This commit is contained in:
parent
d22a1fbb6b
commit
c50c7eeab5
|
|
@ -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<boolean>
|
||||
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<string>()
|
||||
|
||||
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<boolean>
|
||||
component: React.ReactNode
|
||||
}[] = []
|
||||
|
||||
export const AI = createAI({
|
||||
actions: { submit },
|
||||
initialUIState,
|
||||
initialAIState
|
||||
})
|
||||
|
|
|
|||
|
|
@ -54,7 +54,9 @@ export default function RootLayout({
|
|||
disableTransitionOnChange
|
||||
>
|
||||
{/* <Header /> */}
|
||||
<AIProvider>{children}</AIProvider>
|
||||
<AI>
|
||||
{children}
|
||||
</AI>
|
||||
{/* <Footer /> */}
|
||||
</ThemeProvider>
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue