From 710b6ebdfc283f8e88d7f31af0ad84d52589dd68 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 23 Jun 2025 13:24:46 +0800 Subject: [PATCH] . --- apps/blogai/app/[locale]/morphic/action.tsx | 31 ++++----------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/apps/blogai/app/[locale]/morphic/action.tsx b/apps/blogai/app/[locale]/morphic/action.tsx index 06b419c..7872455 100644 --- a/apps/blogai/app/[locale]/morphic/action.tsx +++ b/apps/blogai/app/[locale]/morphic/action.tsx @@ -11,12 +11,7 @@ import { Section } from '@/components/mpv2/section' import { FollowupPanel } from '@/components/mpv2/followup-panel' import { inquire, researcher, taskManager, querySuggestor } from '@/lib/agents' -const initialAIState: { - role: 'user' | 'assistant' | 'system' | 'function' | 'tool' - content: string - id?: string - name?: string -}[] = [] +const initialAIState: ExperimentalMessage[] = [] const initialUIState: { id: number @@ -24,24 +19,13 @@ const initialUIState: { component: React.ReactNode }[] = [] -// ① 先声明 submit(不引用 AI) -let submit: any - -// ② 先生成 AI,再写 submit -export const { - AIProvider, - useAIState, - useUIState, - useActions -} = createAI({ +const AIProvider = createAI({ actions: { submit: async function(formData?: FormData, skip?: boolean) { 'use server' - - const aiState = getMutableAIState() // 这里用 AIProvider + const aiState = getMutableAIState() const uiStream = createStreamableUI() const isGenerating = createStreamableValue(true) - const messages: ExperimentalMessage[] = aiState.get() as any const userInput = skip ? `{"action": "skip"}` @@ -60,10 +44,8 @@ export const { async function processEvents() { uiStream.update() - let action: any = { object: { next: 'proceed' } } if (!skip) action = await taskManager(messages) - if (action.object.next === 'inquire') { const inquiry = await inquire(uiStream, messages) uiStream.done() @@ -74,7 +56,6 @@ export const { ]) return } - let answer = '' let errorOccurred = false const streamText = createStreamableValue() @@ -88,7 +69,6 @@ export const { errorOccurred = hasError } streamText.done() - if (!errorOccurred) { await querySuggestor(uiStream, messages) uiStream.append( @@ -97,14 +77,11 @@ export const { ) } - isGenerating.done(false) uiStream.done() aiState.done([...aiState.get(), { role: 'assistant', content: answer }]) } - processEvents() - return { id: Date.now(), isGenerating: isGenerating.value, @@ -115,3 +92,5 @@ export const { initialUIState, initialAIState }) + +export default AIProvider