This commit is contained in:
parent
d22a1fbb6b
commit
c50c7eeab5
|
|
@ -1,3 +1,4 @@
|
||||||
|
// ai-config.ts
|
||||||
import {
|
import {
|
||||||
StreamableValue,
|
StreamableValue,
|
||||||
createAI,
|
createAI,
|
||||||
|
|
@ -5,31 +6,13 @@ import {
|
||||||
createStreamableValue,
|
createStreamableValue,
|
||||||
getMutableAIState
|
getMutableAIState
|
||||||
} from 'ai/rsc'
|
} from 'ai/rsc'
|
||||||
|
|
||||||
import { ExperimentalMessage } from 'ai'
|
import { ExperimentalMessage } from 'ai'
|
||||||
import { Spinner } from '@/components/ui-v2/spinner'
|
import { Spinner } from '@/components/ui-v2/spinner'
|
||||||
import { Section } from '@/components/mpv2/section'
|
import { Section } from '@/components/mpv2/section'
|
||||||
import { FollowupPanel } from '@/components/mpv2/followup-panel'
|
import { FollowupPanel } from '@/components/mpv2/followup-panel'
|
||||||
import { inquire, researcher, taskManager, querySuggestor } from '@/lib/agents'
|
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) {
|
async function submit(formData?: FormData, skip?: boolean) {
|
||||||
'use server'
|
'use server'
|
||||||
|
|
||||||
|
|
@ -61,7 +44,6 @@ async function submit(formData?: FormData, skip?: boolean) {
|
||||||
|
|
||||||
if (action.object.next === 'inquire') {
|
if (action.object.next === 'inquire') {
|
||||||
const inquiry = await inquire(uiStream, messages)
|
const inquiry = await inquire(uiStream, messages)
|
||||||
|
|
||||||
uiStream.done()
|
uiStream.done()
|
||||||
isGenerating.done()
|
isGenerating.done()
|
||||||
aiState.done([
|
aiState.done([
|
||||||
|
|
@ -74,6 +56,7 @@ async function submit(formData?: FormData, skip?: boolean) {
|
||||||
let answer = ''
|
let answer = ''
|
||||||
let errorOccurred = false
|
let errorOccurred = false
|
||||||
const streamText = createStreamableValue<string>()
|
const streamText = createStreamableValue<string>()
|
||||||
|
|
||||||
while (answer.length === 0) {
|
while (answer.length === 0) {
|
||||||
const { fullResponse, hasError } = await researcher(
|
const { fullResponse, hasError } = await researcher(
|
||||||
uiStream,
|
uiStream,
|
||||||
|
|
@ -107,3 +90,22 @@ async function submit(formData?: FormData, skip?: boolean) {
|
||||||
component: uiStream.value
|
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
|
disableTransitionOnChange
|
||||||
>
|
>
|
||||||
{/* <Header /> */}
|
{/* <Header /> */}
|
||||||
<AIProvider>{children}</AIProvider>
|
<AI>
|
||||||
|
{children}
|
||||||
|
</AI>
|
||||||
{/* <Footer /> */}
|
{/* <Footer /> */}
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue