From c50c7eeab522102daff9dff98203baa941001698 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 23 Jun 2025 13:12:48 +0800 Subject: [PATCH] . --- apps/blogai/app/[locale]/morphic/action.tsx | 42 +++++++++++---------- apps/blogai/app/[locale]/morphic/layout.tsx | 4 +- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/apps/blogai/app/[locale]/morphic/action.tsx b/apps/blogai/app/[locale]/morphic/action.tsx index 122ad51..3f64f5a 100644 --- a/apps/blogai/app/[locale]/morphic/action.tsx +++ b/apps/blogai/app/[locale]/morphic/action.tsx @@ -1,3 +1,4 @@ +// ai-config.ts import { StreamableValue, createAI, @@ -5,31 +6,13 @@ import { createStreamableValue, getMutableAIState } from 'ai/rsc' + import { ExperimentalMessage } from 'ai' import { Spinner } from '@/components/ui-v2/spinner' import { Section } from '@/components/mpv2/section' import { FollowupPanel } from '@/components/mpv2/followup-panel' import { inquire, researcher, taskManager, querySuggestor } from '@/lib/agents' -// ✅ 初始状态 -const initialAIState: ExperimentalMessage[] = [] - -const initialUIState: { - id: number - isGenerating: StreamableValue - component: React.ReactNode -}[] = [] - -// ✅ 先创建 AI -export const AI = createAI({ - actions: { - submit - }, - initialUIState, - initialAIState -}) - -// ✅ 再定义 submit,才能引用 AI async function submit(formData?: FormData, skip?: boolean) { 'use server' @@ -61,7 +44,6 @@ async function submit(formData?: FormData, skip?: boolean) { if (action.object.next === 'inquire') { const inquiry = await inquire(uiStream, messages) - uiStream.done() isGenerating.done() aiState.done([ @@ -74,6 +56,7 @@ async function submit(formData?: FormData, skip?: boolean) { let answer = '' let errorOccurred = false const streamText = createStreamableValue() + while (answer.length === 0) { const { fullResponse, hasError } = await researcher( uiStream, @@ -107,3 +90,22 @@ async function submit(formData?: FormData, skip?: boolean) { component: uiStream.value } } + +const initialAIState: { + role: 'user' | 'assistant' | 'system' | 'function' | 'tool' + content: string + id?: string + name?: string +}[] = [] + +const initialUIState: { + id: number + isGenerating: StreamableValue + component: React.ReactNode +}[] = [] + +export const AI = createAI({ + actions: { submit }, + initialUIState, + initialAIState +}) diff --git a/apps/blogai/app/[locale]/morphic/layout.tsx b/apps/blogai/app/[locale]/morphic/layout.tsx index af5e47a..6d765b0 100644 --- a/apps/blogai/app/[locale]/morphic/layout.tsx +++ b/apps/blogai/app/[locale]/morphic/layout.tsx @@ -54,7 +54,9 @@ export default function RootLayout({ disableTransitionOnChange > {/*
*/} - {children} + + {children} + {/*