Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: enable anon ai writer

Nathan3a4d17f05468
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_toolbar_item.dart
index 467a847c53..a8071e9286 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_toolbar_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_toolbar_item.dart
@@ -142,7 +142,7 @@ class _AiWriterToolbarActionListState extends State<AiWriterToolbarActionList> {
],
),
onPressed: () {
- if (_isAIEnabled(widget.editorState)) {
+ if (_isAIWriterEnabled(widget.editorState)) {
keepEditorFocusNotifier.increase();
popoverController.show();
setState(() {
@@ -159,7 +159,7 @@ class _AiWriterToolbarActionListState extends State<AiWriterToolbarActionList> {
return widget.tooltipBuilder?.call(
context,
_aiWriterToolbarItemId,
- _isAIEnabled(widget.editorState)
+ _isAIWriterEnabled(widget.editorState)
? LocaleKeys.document_plugins_aiWriter_userQuestion.tr()
: LocaleKeys.document_plugins_appflowyAIEditDisabled.tr(),
child,
@@ -191,7 +191,7 @@ class ImproveWritingButton extends StatelessWidget {
color: theme.iconColorTheme.primary,
),
onPressed: () {
- if (_isAIEnabled(editorState)) {
+ if (_isAIWriterEnabled(editorState)) {
keepEditorFocusNotifier.increase();
_insertAiNode(editorState, AiWriterCommand.improveWriting);
} else {
@@ -205,7 +205,7 @@ class ImproveWritingButton extends StatelessWidget {
return tooltipBuilder?.call(
context,
_aiWriterToolbarItemId,
- _isAIEnabled(editorState)
+ _isAIWriterEnabled(editorState)
? LocaleKeys.document_plugins_aiWriter_improveWriting.tr()
: LocaleKeys.document_plugins_appflowyAIEditDisabled.tr(),
child,
@@ -240,10 +240,8 @@ void _insertAiNode(EditorState editorState, AiWriterCommand command) async {
);
}
-bool _isAIEnabled(EditorState editorState) {
- final documentContext = editorState.document.root.context;
- return documentContext == null ||
- !documentContext.read<DocumentBloc>().isLocalMode;
+bool _isAIWriterEnabled(EditorState editorState) {
+ return true;
}
bool onlyShowInTextTypeAndExcludeTable(
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/local_settings_ai_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/local_settings_ai_view.dart
new file mode 100644
index 0000000000..e90c42444f
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/local_settings_ai_view.dart
@@ -0,0 +1,34 @@
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/workspace/application/settings/ai/settings_ai_bloc.dart';
+import 'package:appflowy/workspace/presentation/settings/pages/setting_ai_view/local_ai_setting.dart';
+import 'package:appflowy/workspace/presentation/settings/shared/settings_body.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+
+class LocalSettingsAIView extends StatelessWidget {
+ const LocalSettingsAIView({
+ super.key,
+ required this.userProfile,
+ required this.workspaceId,
+ });
+
+ final UserProfilePB userProfile;
+ final String workspaceId;
+
+ @override
+ Widget build(BuildContext context) {
+ return BlocProvider<SettingsAIBloc>(
+ create: (_) => SettingsAIBloc(userProfile, workspaceId)
+ ..add(const SettingsAIEvent.started()),
+ child: SettingsBody(
+ title: LocaleKeys.settings_aiPage_title.tr(),
+ description: "",
+ children: [
+ const LocalAISetting(),
+ ],
+ ),
+ );
+ }
+}
diff --git a/frontend/rust-lib/flowy-server/src/local_server/impls/chat.rs b/frontend/rust-lib/flowy-server/src/local_server/impls/chat.rs
index 09ef644bfc..9057288f88 100644
--- a/frontend/rust-lib/flowy-server/src/local_server/impls/chat.rs
+++ b/frontend/rust-lib/flowy-server/src/local_server/impls/chat.rs
@@ -132,7 +132,11 @@ impl ChatCloudService for LocalServerChatServiceImpl {
),
}
} else {
- Err(FlowyError::local_ai_not_ready())
+ if self.local_ai.is_enabled() {
+ Err(FlowyError::local_ai_not_ready())
+ } else {
+ Err(FlowyError::local_ai_disabled())
+ }
}
}
@@ -244,7 +248,11 @@ impl ChatCloudService for LocalServerChatServiceImpl {
Err(_) => Ok(stream::once(async { Err(FlowyError::local_ai_unavailable()) }).boxed()),
}
} else {
- Err(FlowyError::local_ai_not_ready())
+ if self.local_ai.is_enabled() {
+ Err(FlowyError::local_ai_not_ready())
+ } else {
+ Err(FlowyError::local_ai_disabled())
+ }
}
}