chore: enable anon ai writer

This commit is contained in:
Nathan 2025-04-17 16:53:52 +08:00
parent 57e4d269eb
commit 3a4d17f054
3 changed files with 50 additions and 10 deletions

View file

@ -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(

View file

@ -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(),
],
),
);
}
}

View file

@ -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())
}
}
}