From 6a51a7c5cec5e5e8de4c9d91d7976f213407fcf0 Mon Sep 17 00:00:00 2001 From: shanexi Date: Tue, 14 Jan 2025 16:53:20 +0800 Subject: [PATCH] feat: convert to x bot --- .../components/chat/app-builder-chat.model.ts | 22 ++++++++++++++++--- web/apps/web/src/services/app/index.tsx | 9 ++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/web/apps/web/src/components/chat/app-builder-chat.model.ts b/web/apps/web/src/components/chat/app-builder-chat.model.ts index 428594d6..5d62bba0 100644 --- a/web/apps/web/src/components/chat/app-builder-chat.model.ts +++ b/web/apps/web/src/components/chat/app-builder-chat.model.ts @@ -12,15 +12,17 @@ import { JsonSchema7 } from 'node_modules/@shellagent/form-engine/src/types/json import { upload } from '@/services/common'; +import { convertXBotSvc } from '@/services/app'; +import { type AppBuilderModel } from '@/stores/app/models/app-builder.model'; +import type { ServerMessage } from '../../services/app/message-type'; +import { EventStatusEnum, RunAppRequest } from '../../services/app/type'; +import { ToastModel } from '../../utils/toast.model'; import { patchImageUrl, patchMessageActionPopupForm, serverMessageToMessage, transformEmbedObjs, } from './app-builder-chat-utils'; -import type { ServerMessage } from '../../services/app/message-type'; -import { EventStatusEnum, RunAppRequest } from '../../services/app/type'; -import { ToastModel } from '../../utils/toast.model'; @injectable() export class AppBuilderChatModel { @@ -48,6 +50,8 @@ export class AppBuilderChatModel { constructor( @inject(ToastModel) private emitter: ToastModel, @inject(ChatNewModel) public chatNew: ChatNewModel, + @inject('Factory') + public appBuilderModelFactory: () => AppBuilderModel, ) { this.chatNew.handlers.sendTextMessagePost = async ( text: string, @@ -136,6 +140,18 @@ export class AppBuilderChatModel { runInAction(() => { this.isInitBotLoading = true; }); + if (this.appBuilderModelFactory().metadata.app_type) { + try { + const res = await convertXBotSvc({ automata }); + automata = res.automata; + } catch (e) { + if (e instanceof Error) { + this.emitter.error(e.message); + } else { + this.emitter.error(`convert to x automata error`); + } + } + } try { const res = await axios.post( `/api/app/init_bot`, diff --git a/web/apps/web/src/services/app/index.tsx b/web/apps/web/src/services/app/index.tsx index 5b946873..28fcafa5 100644 --- a/web/apps/web/src/services/app/index.tsx +++ b/web/apps/web/src/services/app/index.tsx @@ -68,6 +68,15 @@ export const initBot: Fetcher = params => { }); }; +export const convertXBotSvc: Fetcher< + InitBotRequest, + InitBotRequest +> = params => { + return APIFetch.post('/api/app/convert_x_bot', { + body: params, + }); +}; + export const runApp = ( params: RunAppRequest, cb: {