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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: implement custom prompt usage metrics (#7923)
Richard Shiuec634e906eada
diff --git a/frontend/appflowy_flutter/integration_test/shared/mock/mock_ai.dart b/frontend/appflowy_flutter/integration_test/shared/mock/mock_ai.dartindex cd4ecb931f..b7131996c6 100644--- a/frontend/appflowy_flutter/integration_test/shared/mock/mock_ai.dart+++ b/frontend/appflowy_flutter/integration_test/shared/mock/mock_ai.dart@@ -84,6 +84,7 @@ class MockAIRepository extends Mock implements AppFlowyAIService {String? objectId,required String text,PredefinedFormat? format,+ String? promptId,List<String> sourceIds = const [],List<AiWriterRecord> history = const [],required CompletionTypePB completionType,diff --git a/frontend/appflowy_flutter/lib/ai/service/ai_prompt_input_bloc.dart b/frontend/appflowy_flutter/lib/ai/service/ai_prompt_input_bloc.dartindex 3c9c82b594..c09c0fefe1 100644--- a/frontend/appflowy_flutter/lib/ai/service/ai_prompt_input_bloc.dart+++ b/frontend/appflowy_flutter/lib/ai/service/ai_prompt_input_bloc.dart@@ -23,6 +23,8 @@ class AIPromptInputBloc extends Bloc<AIPromptInputEvent, AIPromptInputState> {final AIModelStateNotifier aiModelStateNotifier;+ String? promptId;+@overrideFuture<void> close() async {await aiModelStateNotifier.dispose();@@ -88,7 +90,11 @@ class AIPromptInputBloc extends Bloc<AIPromptInputEvent, AIPromptInputState> {),);},+ updatePromptId: (promptId) {+ this.promptId = promptId;+ },clearMetadata: () {+ promptId = null;emit(state.copyWith(attachedFiles: [],@@ -151,6 +157,8 @@ class AIPromptInputEvent with _$AIPromptInputEvent {const factory AIPromptInputEvent.updateMentionedViews(List<ViewPB> views) =_UpdateMentionedViews;const factory AIPromptInputEvent.clearMetadata() = _ClearMetadata;+ const factory AIPromptInputEvent.updatePromptId(String promptId) =+ _UpdatePromptId;}@freezeddiff --git a/frontend/appflowy_flutter/lib/ai/service/appflowy_ai_service.dart b/frontend/appflowy_flutter/lib/ai/service/appflowy_ai_service.dartindex 8d56b9d32c..09a3a30614 100644--- a/frontend/appflowy_flutter/lib/ai/service/appflowy_ai_service.dart+++ b/frontend/appflowy_flutter/lib/ai/service/appflowy_ai_service.dart@@ -29,6 +29,7 @@ abstract class AIRepository {String? objectId,required String text,PredefinedFormat? format,+ String? promptId,List<String> sourceIds = const [],List<AiWriterRecord> history = const [],required CompletionTypePB completionType,@@ -56,6 +57,7 @@ class AppFlowyAIService implements AIRepository {String? objectId,required String text,PredefinedFormat? format,+ String? promptId,List<String> sourceIds = const [],List<AiWriterRecord> history = const [],required CompletionTypePB completionType,@@ -82,6 +84,7 @@ class AppFlowyAIService implements AIRepository {text: text,completionType: completionType,format: format?.toPB(),+ promptId: promptId,streamPort: fixnum.Int64(stream.nativePort),objectId: objectId ?? '',ragIds: [diff --git a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dart b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dartindex 692cbeb899..1b1631af97 100644--- a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dart+++ b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dart@@ -15,6 +15,13 @@ import 'package:flutter_bloc/flutter_bloc.dart';import 'browse_prompts_button.dart';+typedef OnPromptInputSubmitted = void Function(+ String input,+ PredefinedFormat? predefinedFormat,+ Map<String, dynamic> metadata,+ String? promptId,+);+class DesktopPromptInput extends StatefulWidget {const DesktopPromptInput({super.key,@@ -32,8 +39,7 @@ class DesktopPromptInput extends StatefulWidget {final bool isStreaming;final AiPromptInputTextEditingController textController;final void Function() onStopStreaming;- final void Function(String, PredefinedFormat?, Map<String, dynamic>)- onSubmitted;+ final OnPromptInputSubmitted onSubmitted;final ValueNotifier<List<String>> selectedSourcesNotifier;final void Function(List<String>) onUpdateSelectedSources;final bool hideDecoration;@@ -241,12 +247,14 @@ class _DesktopPromptInputState extends State<DesktopPromptInput> {final sources = (paletteState.askAISources ?? []).map((e) => e.id).toList();final metadata =context.read<AIPromptInputBloc?>()?.consumeMetadata() ?? {};- final promptState = context.read<AIPromptInputBloc?>()?.state;+ final promptBloc = context.read<AIPromptInputBloc?>();+ final promptId = promptBloc?.promptId;+ final promptState = promptBloc?.state;final predefinedFormat = promptState?.predefinedFormat;if (sources.isNotEmpty) {widget.onUpdateSelectedSources(sources);}- widget.onSubmitted.call(query, predefinedFormat, metadata);+ widget.onSubmitted.call(query, predefinedFormat, metadata, promptId ?? '');}void startMentionPageFromButton() {@@ -308,6 +316,7 @@ class _DesktopPromptInputState extends State<DesktopPromptInput> {userInput,showPredefinedFormats ? predefinedFormat : null,metadata,+ bloc.promptId,);}@@ -526,9 +535,9 @@ class _DesktopPromptInputState extends State<DesktopPromptInput> {void handleOnSelectPrompt(AiPrompt prompt) {final bloc = context.read<AIPromptInputBloc>();- bloc.add(- AIPromptInputEvent.updateMentionedViews([]),- );+ bloc+ ..add(AIPromptInputEvent.updateMentionedViews([]))+ ..add(AIPromptInputEvent.updatePromptId(prompt.id));final content = AiPromptInputTextEditingController.replace(prompt.content);diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_bloc.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_bloc.dartindex 7c1e3aafd0..f33dbfb88a 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_bloc.dart@@ -106,8 +106,8 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {receiveMessage: (message) async => _handleReceiveMessage(message),// Sending messages- sendMessage: (message, format, metadata) async =>- _handleSendMessage(message, format, metadata, emit),+ sendMessage: (message, format, metadata, promptId) async =>+ _handleSendMessage(message, format, metadata, promptId, emit),finishSending: () async => emit(state.copyWith(promptResponseState: PromptResponseState.streamingAnswer,@@ -204,13 +204,14 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {String message,PredefinedFormat? format,Map<String, dynamic>? metadata,+ String? promptId,Emitter<ChatState> emit,) {_messageHandler.clearErrorMessages();emit(state.copyWith(clearErrorMessages: !state.clearErrorMessages));_messageHandler.clearRelatedQuestions();- _startStreamingMessage(message, format, metadata);+ _startStreamingMessage(message, format, metadata, promptId);lastSentMessage = null;isFetchingRelatedQuestions = false;@@ -436,6 +437,7 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {String message,PredefinedFormat? format,Map<String, dynamic>? metadata,+ String? promptId,) async {// Prepare streamsawait _streamManager.prepareStreams();@@ -448,7 +450,7 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {add(ChatEvent.receiveMessage(questionStreamMessage));// Send stream request- await _streamManager.sendStreamRequest(message, format).fold(+ await _streamManager.sendStreamRequest(message, format, promptId).fold((question) {if (!isClosed) {// Create and add answer stream message@@ -540,6 +542,7 @@ class ChatEvent with _$ChatEvent {required String message,PredefinedFormat? format,Map<String, dynamic>? metadata,+ String? promptId,}) = _SendMessage;const factory ChatEvent.finishSending() = _FinishSendMessage;const factory ChatEvent.failedSending() = _FailSendMessage;diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_stream_manager.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_stream_manager.dartindex c2ec09a41f..9f859c2ade 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_stream_manager.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_stream_manager.dart@@ -37,6 +37,7 @@ class ChatStreamManager {StreamChatPayloadPB buildStreamPayload(String message,PredefinedFormat? format,+ String? promptId,) {final payload = StreamChatPayloadPB(chatId: chatId,@@ -50,6 +51,10 @@ class ChatStreamManager {payload.format = format.toPB();}+ if (promptId != null) {+ payload.promptId = promptId;+ }+return payload;}@@ -57,8 +62,9 @@ class ChatStreamManager {Future<FlowyResult<ChatMessagePB, FlowyError>> sendStreamRequest(String message,PredefinedFormat? format,+ String? promptId,) async {- final payload = buildStreamPayload(message, format);+ final payload = buildStreamPayload(message, format, promptId);return AIEventStreamMessage(payload).send();}diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_page/chat_footer.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_page/chat_footer.dartindex 7035006fc0..41765ebf80 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_page/chat_footer.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_page/chat_footer.dart@@ -85,12 +85,13 @@ class _ChatFooterState extends State<ChatFooter> {onStopStreaming: () {chatBloc.add(const ChatEvent.stopStream());},- onSubmitted: (text, format, metadata) {+ onSubmitted: (text, format, metadata, promptId) {chatBloc.add(ChatEvent.sendMessage(message: text,format: format,metadata: metadata,+ promptId: promptId,),);},diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_block_component.dartindex 2e7596b9f0..2b88f57d2f 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_block_component.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_block_component.dart@@ -314,7 +314,9 @@ class _OverlayContentState extends State<OverlayContent> {hasSelection: hasSelection,editorState: widget.editorState,onSelectCommand: (command) {- final state = context.read<AIPromptInputBloc>().state;+ final bloc = context.read<AIPromptInputBloc>();+ final promptId = bloc.promptId;+ final state = bloc.state;final showPredefinedFormats = state.showPredefinedFormats;final predefinedFormat = state.predefinedFormat;final text = widget.textController.text;@@ -323,6 +325,7 @@ class _OverlayContentState extends State<OverlayContent> {command,text,showPredefinedFormats ? predefinedFormat : null,+ promptId,);},),@@ -497,8 +500,8 @@ class MainContentArea extends StatelessWidget {AiWriterCommand.makeShorter,].contains(state.command),textController: textController,- onSubmitted: (message, format, _) {- cubit.runCommand(state.command, message, format);+ onSubmitted: (message, format, _, promptId) {+ cubit.runCommand(state.command, message, format, promptId);},onStopStreaming: () => cubit.stopStream(),selectedSourcesNotifier: cubit.selectedSourcesNotifier,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/operations/ai_writer_cubit.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/operations/ai_writer_cubit.dartindex a5dbb69f23..c7e6d2c424 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/operations/ai_writer_cubit.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/operations/ai_writer_cubit.dart@@ -115,13 +115,14 @@ class AiWriterCubit extends Cubit<AiWriterState> {return;}- runCommand(command, prompt, null);+ runCommand(command, prompt, null, null);}void runCommand(AiWriterCommand command,String prompt,PredefinedFormat? predefinedFormat,+ String? promptId,) async {if (aiWriterNode == null) {return;@@ -135,19 +136,29 @@ class AiWriterCubit extends Cubit<AiWriterState> {await _startContinueWriting(command,predefinedFormat,+ promptId,);break;case AiWriterCommand.fixSpellingAndGrammar:case AiWriterCommand.improveWriting:case AiWriterCommand.makeLonger:case AiWriterCommand.makeShorter:- await _startSuggestingEdits(command, prompt, predefinedFormat);+ await _startSuggestingEdits(+ command,+ prompt,+ predefinedFormat,+ promptId,+ );break;case AiWriterCommand.explain:- await _startInforming(command, prompt, predefinedFormat);+ await _startInforming(command, prompt, predefinedFormat, promptId);break;case AiWriterCommand.userQuestion when prompt.isNotEmpty:- _startAskingQuestion(prompt, predefinedFormat);+ _startAskingQuestion(+ prompt,+ predefinedFormat,+ promptId,+ );break;case AiWriterCommand.userQuestion:emit(@@ -168,6 +179,7 @@ class AiWriterCubit extends Cubit<AiWriterState> {(state as RegisteredAiWriter).command,lastQuestion.content,lastQuestion.format,+ null,);}}@@ -359,6 +371,7 @@ class AiWriterCubit extends Cubit<AiWriterState> {void _startAskingQuestion(String prompt,PredefinedFormat? format,+ String? promptId,) async {if (aiWriterNode == null) {return;@@ -369,6 +382,7 @@ class AiWriterCubit extends Cubit<AiWriterState> {objectId: documentId,text: prompt,format: format,+ promptId: promptId,history: records,sourceIds: selectedSourcesNotifier.value,completionType: command.toCompletionType(),@@ -445,6 +459,7 @@ class AiWriterCubit extends Cubit<AiWriterState> {Future<void> _startContinueWriting(AiWriterCommand command,PredefinedFormat? predefinedFormat,+ String? promptId,) async {final position = aiWriterNode?.aiWriterSelection?.start;if (position == null) {@@ -466,6 +481,7 @@ class AiWriterCubit extends Cubit<AiWriterState> {history: records,sourceIds: selectedSourcesNotifier.value,format: predefinedFormat,+ promptId: promptId,onStart: () async {final position = await ensurePreviousNodeIsEmptyParagraph(editorState,@@ -536,6 +552,7 @@ class AiWriterCubit extends Cubit<AiWriterState> {AiWriterCommand command,String prompt,PredefinedFormat? predefinedFormat,+ String? promptId,) async {final selection = aiWriterNode?.aiWriterSelection;if (selection == null) {@@ -549,6 +566,7 @@ class AiWriterCubit extends Cubit<AiWriterState> {objectId: documentId,text: prompt,format: predefinedFormat,+ promptId: promptId,completionType: command.toCompletionType(),history: records,sourceIds: selectedSourcesNotifier.value,@@ -639,6 +657,7 @@ class AiWriterCubit extends Cubit<AiWriterState> {AiWriterCommand command,String prompt,PredefinedFormat? predefinedFormat,+ String? promptId,) async {final selection = aiWriterNode?.aiWriterSelection;if (selection == null) {@@ -655,6 +674,7 @@ class AiWriterCubit extends Cubit<AiWriterState> {history: records,sourceIds: selectedSourcesNotifier.value,format: predefinedFormat,+ promptId: promptId,onStart: () async {records.add(AiWriterRecord.user(diff --git a/frontend/appflowy_flutter/test/bloc_test/ai_writer_test/ai_writer_bloc_test.dart b/frontend/appflowy_flutter/test/bloc_test/ai_writer_test/ai_writer_bloc_test.dartindex 10e88dc71a..128924af9d 100644--- a/frontend/appflowy_flutter/test/bloc_test/ai_writer_test/ai_writer_bloc_test.dart+++ b/frontend/appflowy_flutter/test/bloc_test/ai_writer_test/ai_writer_bloc_test.dart@@ -23,6 +23,7 @@ class _MockAIRepository extends Mock implements AppFlowyAIService {String? objectId,required String text,PredefinedFormat? format,+ String? promptId,List<String> sourceIds = const [],List<AiWriterRecord> history = const [],required CompletionTypePB completionType,@@ -57,6 +58,7 @@ class _MockAIRepositoryLess extends Mock implements AppFlowyAIService {String? objectId,required String text,PredefinedFormat? format,+ String? promptId,List<String> sourceIds = const [],List<AiWriterRecord> history = const [],required CompletionTypePB completionType,@@ -87,6 +89,7 @@ class _MockAIRepositoryMore extends Mock implements AppFlowyAIService {String? objectId,required String text,PredefinedFormat? format,+ String? promptId,List<String> sourceIds = const [],List<AiWriterRecord> history = const [],required CompletionTypePB completionType,@@ -119,6 +122,7 @@ class _MockErrorRepository extends Mock implements AppFlowyAIService {String? objectId,required String text,PredefinedFormat? format,+ String? promptId,List<String> sourceIds = const [],List<AiWriterRecord> history = const [],required CompletionTypePB completionType,diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lockindex 646fbd3658..bd787e392a 100644--- a/frontend/rust-lib/Cargo.lock+++ b/frontend/rust-lib/Cargo.lock@@ -163,7 +163,7 @@ checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"[[package]]name = "app-error"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["anyhow","bincode",@@ -183,7 +183,7 @@ dependencies = [[[package]]name = "appflowy-ai-client"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["anyhow","bytes",@@ -860,7 +860,7 @@ dependencies = [[[package]]name = "client-api"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["again","anyhow",@@ -915,7 +915,7 @@ dependencies = [[[package]]name = "client-api-entity"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["collab-entity","collab-rt-entity",@@ -928,7 +928,7 @@ dependencies = [[[package]]name = "client-websocket"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["futures-channel","futures-util",@@ -1199,7 +1199,7 @@ dependencies = [[[package]]name = "collab-rt-entity"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["anyhow","bincode",@@ -1221,7 +1221,7 @@ dependencies = [[[package]]name = "collab-rt-protocol"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["anyhow","async-trait",@@ -1648,7 +1648,7 @@ checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"[[package]]name = "database-entity"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["bincode","bytes",@@ -3186,7 +3186,7 @@ dependencies = [[[package]]name = "gotrue"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["anyhow","getrandom 0.2.10",@@ -3201,7 +3201,7 @@ dependencies = [[[package]]name = "gotrue-entity"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["app-error","jsonwebtoken",@@ -3894,7 +3894,7 @@ dependencies = [[[package]]name = "infra"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["anyhow","bytes",@@ -6865,7 +6865,7 @@ dependencies = [[[package]]name = "shared-entity"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["anyhow","app-error",@@ -8920,7 +8920,7 @@ dependencies = [[[package]]name = "workspace-template"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=e75450c#e75450c050c60c29ad32bb579a5f0a9aef6e69ea"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=ae3c4fa#ae3c4fa03f182b05d29794df3bbd540322987067"dependencies = ["anyhow","async-trait",diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.tomlindex 0775e92b77..718bc2ba69 100644--- a/frontend/rust-lib/Cargo.toml+++ b/frontend/rust-lib/Cargo.toml@@ -29,7 +29,8 @@ members = ["flowy-search-pub","flowy-ai","flowy-ai-pub",- "flowy-storage-pub", "flowy-sqlite-vec",+ "flowy-storage-pub",+ "flowy-sqlite-vec",]resolver = "2"@@ -109,9 +110,9 @@ flowy-sqlite-vec = { path = "flowy-sqlite-vec" }# Run the script.add_workspace_members:# scripts/tool/update_client_api_rev.sh new_rev_id# ⚠️⚠️⚠️️-client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "e75450c" }-client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "e75450c" }-workspace-template = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "e75450c" }+client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "ae3c4fa" }+client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "ae3c4fa" }+workspace-template = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "ae3c4fa" }[profile.dev]opt-level = 0@@ -155,4 +156,4 @@ collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlocollab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "33f6844954f9b631693cac11aef573cf376d04f8" }collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "33f6844954f9b631693cac11aef573cf376d04f8" }-langchain-rust = { version = "4.6.0", git = "https://github.com/appflowy/langchain-rust", branch = "af" }\ No newline at end of file+langchain-rust = { version = "4.6.0", git = "https://github.com/appflowy/langchain-rust", branch = "af" }diff --git a/frontend/rust-lib/event-integration-test/src/chat_event.rs b/frontend/rust-lib/event-integration-test/src/chat_event.rsindex c08e899a71..524d72e6a4 100644--- a/frontend/rust-lib/event-integration-test/src/chat_event.rs+++ b/frontend/rust-lib/event-integration-test/src/chat_event.rs@@ -58,6 +58,7 @@ impl EventIntegrationTest {answer_stream_port: 0,question_stream_port: 0,format: None,+ prompt_id: None,};EventBuilder::new(self.clone())diff --git a/frontend/rust-lib/event-integration-test/tests/chat/chat_message_test.rs b/frontend/rust-lib/event-integration-test/tests/chat/chat_message_test.rsindex aacba827c4..10edc0b294 100644--- a/frontend/rust-lib/event-integration-test/tests/chat/chat_message_test.rs+++ b/frontend/rust-lib/event-integration-test/tests/chat/chat_message_test.rs@@ -32,6 +32,7 @@ async fn af_cloud_create_chat_message_test() {&Uuid::from_str(&chat_id).unwrap(),&format!("hello world {}", i),ChatMessageType::System,+ None,).await.unwrap();@@ -92,6 +93,7 @@ async fn af_cloud_load_remote_system_message_test() {&Uuid::from_str(&chat_id).unwrap(),&format!("hello server {}", i),ChatMessageType::System,+ None,).await.unwrap();diff --git a/frontend/rust-lib/flowy-ai-pub/src/cloud.rs b/frontend/rust-lib/flowy-ai-pub/src/cloud.rsindex 69360cf5be..c90ffa4c6c 100644--- a/frontend/rust-lib/flowy-ai-pub/src/cloud.rs+++ b/frontend/rust-lib/flowy-ai-pub/src/cloud.rs@@ -106,6 +106,7 @@ pub trait ChatCloudService: Send + Sync + 'static {chat_id: &Uuid,message: &str,message_type: ChatMessageType,+ prompt_id: Option<String>,) -> Result<ChatMessage, FlowyError>;async fn create_answer(diff --git a/frontend/rust-lib/flowy-ai/src/chat.rs b/frontend/rust-lib/flowy-ai/src/chat.rsindex b7ad1c6b77..db9add2368 100644--- a/frontend/rust-lib/flowy-ai/src/chat.rs+++ b/frontend/rust-lib/flowy-ai/src/chat.rs@@ -98,6 +98,7 @@ impl Chat {&self.chat_id,¶ms.message,params.message_type.clone(),+ params.prompt_id.clone(),).await.map_err(|err| {diff --git a/frontend/rust-lib/flowy-ai/src/completion.rs b/frontend/rust-lib/flowy-ai/src/completion.rsindex 6585561c4f..24ba265a55 100644--- a/frontend/rust-lib/flowy-ai/src/completion.rs+++ b/frontend/rust-lib/flowy-ai/src/completion.rs@@ -137,6 +137,7 @@ impl CompletionTask {.context.custom_prompt.map(|v| CustomPrompt { system: v }),+ prompt_id: self.context.prompt_id.clone(),}),format,};diff --git a/frontend/rust-lib/flowy-ai/src/entities.rs b/frontend/rust-lib/flowy-ai/src/entities.rsindex af26f400d9..f63f4bc22d 100644--- a/frontend/rust-lib/flowy-ai/src/entities.rs+++ b/frontend/rust-lib/flowy-ai/src/entities.rs@@ -70,6 +70,9 @@ pub struct StreamChatPayloadPB {#[pb(index = 6, one_of)]pub format: Option<PredefinedFormatPB>,++ #[pb(index = 7, one_of)]+ pub prompt_id: Option<String>,}#[derive(Default, Debug)]@@ -80,6 +83,7 @@ pub struct StreamMessageParams {pub answer_stream_port: i64,pub question_stream_port: i64,pub format: Option<PredefinedFormatPB>,+ pub prompt_id: Option<String>,}#[derive(Default, ProtoBuf, Validate, Clone, Debug)]@@ -441,6 +445,9 @@ pub struct CompleteTextPB {#[pb(index = 8, one_of)]pub custom_prompt: Option<String>,++ #[pb(index = 9, one_of)]+ pub prompt_id: Option<String>,}#[derive(Default, ProtoBuf, Clone, Debug)]diff --git a/frontend/rust-lib/flowy-ai/src/event_handler.rs b/frontend/rust-lib/flowy-ai/src/event_handler.rsindex 258d23d31c..41039832d1 100644--- a/frontend/rust-lib/flowy-ai/src/event_handler.rs+++ b/frontend/rust-lib/flowy-ai/src/event_handler.rs@@ -33,6 +33,7 @@ pub(crate) async fn stream_chat_message_handler(answer_stream_port,question_stream_port,format,+ prompt_id,} = data;let message_type = match message_type {@@ -48,6 +49,7 @@ pub(crate) async fn stream_chat_message_handler(answer_stream_port,question_stream_port,format,+ prompt_id,};let ai_manager = upgrade_ai_manager(ai_manager)?;diff --git a/frontend/rust-lib/flowy-ai/src/middleware/chat_service_mw.rs b/frontend/rust-lib/flowy-ai/src/middleware/chat_service_mw.rsindex af15e74446..d21e242762 100644--- a/frontend/rust-lib/flowy-ai/src/middleware/chat_service_mw.rs+++ b/frontend/rust-lib/flowy-ai/src/middleware/chat_service_mw.rs@@ -74,10 +74,11 @@ impl ChatCloudService for ChatServiceMiddleware {chat_id: &Uuid,message: &str,message_type: ChatMessageType,+ prompt_id: Option<String>,) -> Result<ChatMessage, FlowyError> {self.cloud_service- .create_question(workspace_id, chat_id, message, message_type)+ .create_question(workspace_id, chat_id, message, message_type, prompt_id).await}diff --git a/frontend/rust-lib/flowy-ai/src/offline/offline_message_sync.rs b/frontend/rust-lib/flowy-ai/src/offline/offline_message_sync.rsindex d92fd14532..d2e9809031 100644--- a/frontend/rust-lib/flowy-ai/src/offline/offline_message_sync.rs+++ b/frontend/rust-lib/flowy-ai/src/offline/offline_message_sync.rs@@ -96,10 +96,11 @@ impl ChatCloudService for AutoSyncChatService {chat_id: &Uuid,message: &str,message_type: ChatMessageType,+ prompt_id: Option<String>,) -> Result<ChatMessage, FlowyError> {let message = self.cloud_service- .create_question(workspace_id, chat_id, message, message_type)+ .create_question(workspace_id, chat_id, message, message_type, prompt_id).await?;self.upsert_message(chat_id, message.clone(), true).await?;// TODO: implement background syncdiff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/cloud_service_impl.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/cloud_service_impl.rsindex 006486287a..ab1f4f1027 100644--- a/frontend/rust-lib/flowy-core/src/deps_resolve/cloud_service_impl.rs+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/cloud_service_impl.rs@@ -698,12 +698,13 @@ impl ChatCloudService for ServerProvider {chat_id: &Uuid,message: &str,message_type: ChatMessageType,+ prompt_id: Option<String>,) -> Result<ChatMessage, FlowyError> {let message = message.to_string();self.get_server()?.chat_service()- .create_question(workspace_id, chat_id, &message, message_type)+ .create_question(workspace_id, chat_id, &message, message_type, prompt_id).await}diff --git a/frontend/rust-lib/flowy-server/src/af_cloud/impls/chat.rs b/frontend/rust-lib/flowy-server/src/af_cloud/impls/chat.rsindex f3ae70a085..2039b12566 100644--- a/frontend/rust-lib/flowy-server/src/af_cloud/impls/chat.rs+++ b/frontend/rust-lib/flowy-server/src/af_cloud/impls/chat.rs@@ -59,12 +59,14 @@ wherechat_id: &Uuid,message: &str,message_type: ChatMessageType,+ prompt_id: Option<String>,) -> Result<ChatMessage, FlowyError> {let chat_id = chat_id.to_string();let try_get_client = self.inner.try_get_client();let params = CreateChatMessageParams {content: message.to_string(),message_type,+ prompt_id,};let message = try_get_client?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.rsindex c4993a91e7..3ac42f5fa0 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@@ -78,6 +78,7 @@ impl ChatCloudService for LocalChatServiceImpl {chat_id: &Uuid,message: &str,message_type: ChatMessageType,+ _prompt_id: Option<String>,) -> Result<ChatMessage, FlowyError> {let message_id = ID_GEN.lock().await.next_id();let message = match message_type {