Skip to content

Commit

Permalink
feat: convert to x bot
Browse files Browse the repository at this point in the history
  • Loading branch information
shanexi committed Jan 14, 2025
1 parent 21232c6 commit 6a51a7c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
22 changes: 19 additions & 3 deletions web/apps/web/src/components/chat/app-builder-chat.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -48,6 +50,8 @@ export class AppBuilderChatModel {
constructor(
@inject(ToastModel) private emitter: ToastModel,
@inject(ChatNewModel) public chatNew: ChatNewModel,
@inject('Factory<AppBuilderModel>')
public appBuilderModelFactory: () => AppBuilderModel,
) {
this.chatNew.handlers.sendTextMessagePost = async (
text: string,
Expand Down Expand Up @@ -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`,
Expand Down
9 changes: 9 additions & 0 deletions web/apps/web/src/services/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ export const initBot: Fetcher<InitBotResponse, InitBotRequest> = params => {
});
};

export const convertXBotSvc: Fetcher<
InitBotRequest,
InitBotRequest
> = params => {
return APIFetch.post<InitBotRequest>('/api/app/convert_x_bot', {
body: params,
});
};

export const runApp = (
params: RunAppRequest,
cb: {
Expand Down

0 comments on commit 6a51a7c

Please sign in to comment.