diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx index c83f4445..8a69dbad 100644 --- a/components/chat-panel.tsx +++ b/components/chat-panel.tsx @@ -50,13 +50,6 @@ export function ChatPanel({ messages, input, setInput }: ChatPanelProps) { handleClear() setIsButtonPressed(false) } - setMessages(currentMessages => [ - ...currentMessages, - { - id: nanoid(), - component: - } - ]) const formData = new FormData(e.currentTarget) // Removed mcp argument from submit call const responseMessage = await submit(formData) diff --git a/components/copilot.tsx b/components/copilot.tsx index af110a89..04408ee0 100644 --- a/components/copilot.tsx +++ b/components/copilot.tsx @@ -16,16 +16,17 @@ import { } from './ui/icons' import { cn } from '@/lib/utils' +import { StreamableValue } from 'ai/rsc' + export type CopilotProps = { - inquiry: { value: PartialInquiry }; + inquiry: StreamableValue } -export const Copilot: React.FC = ({ inquiry }: CopilotProps) => { - const { value } = inquiry; +export const Copilot: React.FC = ({ inquiry }) => { + const [data, error, pending] = useStreamableValue(inquiry) const [completed, setCompleted] = useState(false) const [query, setQuery] = useState('') const [skipped, setSkipped] = useState(false) - const [data, error, pending] = useStreamableValue() const [checkedOptions, setCheckedOptions] = useState<{ [key: string]: boolean }>({}) @@ -121,14 +122,12 @@ export const Copilot: React.FC = ({ inquiry }: CopilotProps) => {

- {data?.question || value.question} - - + {data?.question}

- {value.options?.map((option, index) => ( + {data?.options?.map((option, index) => (
= ({ inquiry }: CopilotProps) => { {data?.allowsInput && (
diff --git a/components/followup-panel.tsx b/components/followup-panel.tsx index 336e9a42..c1a0f362 100644 --- a/components/followup-panel.tsx +++ b/components/followup-panel.tsx @@ -19,19 +19,9 @@ export function FollowupPanel() { event.preventDefault() const formData = new FormData(event.currentTarget as HTMLFormElement) - const userMessage = { - id: Date.now(), - isGenerating: false, - component: - } - // Removed mcp argument from submit call const responseMessage = await submit(formData) - setMessages(currentMessages => [ - ...currentMessages, - userMessage, - responseMessage - ]) + setMessages(currentMessages => [...currentMessages, responseMessage]) setInput('') } diff --git a/components/search-related.tsx b/components/search-related.tsx index b65a7be3..2bb49a79 100644 --- a/components/search-related.tsx +++ b/components/search-related.tsx @@ -41,18 +41,9 @@ export const SearchRelated: React.FC = ({ query = submitter.value } - const userMessage = { - id: Date.now(), - component: - } - // Removed mcp argument from submit call const responseMessage = await submit(formData) - setMessages(currentMessages => [ - ...currentMessages, - userMessage, - responseMessage - ]) + setMessages(currentMessages => [...currentMessages, responseMessage]) } return ( diff --git a/lib/agents/inquire.tsx b/lib/agents/inquire.tsx index ee1f9e04..852f9232 100644 --- a/lib/agents/inquire.tsx +++ b/lib/agents/inquire.tsx @@ -4,51 +4,36 @@ import { CoreMessage, LanguageModel, streamObject } from 'ai'; import { PartialInquiry, inquirySchema } from '@/lib/schema/inquiry'; import { getModel } from '../utils'; -// Define a plain object type for the inquiry prop -interface InquiryProp { - value: PartialInquiry; -} - export async function inquire( uiStream: ReturnType, messages: CoreMessage[] -) { - const objectStream = createStreamableValue(); - let currentInquiry: PartialInquiry = {}; - - // Update the UI stream with the Copilot component, passing only the serializable value - uiStream.update( - - ); - - let finalInquiry: PartialInquiry = {}; - const result = await streamObject({ - model: getModel() as LanguageModel, - system: `...`, // Your system prompt remains unchanged - messages, - schema: inquirySchema, - }); - - for await (const obj of result.partialObjectStream) { - if (obj) { - // Update the local state - currentInquiry = obj; - // Update the stream with the new serializable value - objectStream.update(obj); - finalInquiry = obj; - - // Update the UI stream with the new inquiry value - uiStream.update( - - ); +): Promise { + const objectStream = createStreamableValue() + uiStream.update() + + let finalInquiry: PartialInquiry = {} + try { + const result = await streamObject({ + model: getModel() as LanguageModel, + system: `As a professional writer, your job is to generate a comprehensive and informative, yet concise answer of 400 words or less for the given question based solely on the provided search results (URL and content). You must only use information from the provided search results. Use an unbiased and journalistic tone. Combine search results together into a coherent answer. Do not repeat text. If there are any images relevant to your answer, be sure to include them as well. Aim to directly address the user's question, augmenting your response with insights gleaned from the search results. + Whenever quoting or referencing information from a specific URL, always cite the source URL explicitly. Please match the language of the response to the user's language. + Always answer in Markdown format. Links and images must follow the correct format. + Link format: [link text](url) + Image format: ![alt text](url) + `, + messages, + schema: inquirySchema + }) + + for await (const obj of result.partialObjectStream) { + if (obj) { + objectStream.update(obj) + finalInquiry = obj + } } + } finally { + objectStream.done() } - objectStream.done(); - // Final UI update - uiStream.update( - - ); - - return finalInquiry; + return finalInquiry } \ No newline at end of file diff --git a/lib/agents/researcher.tsx b/lib/agents/researcher.tsx index 6ef6d53b..6394ffe5 100644 --- a/lib/agents/researcher.tsx +++ b/lib/agents/researcher.tsx @@ -71,7 +71,11 @@ Match the language of your response to the user's language.`; case 'text-delta': if (delta.textDelta) { // If the first text delta is available, add a UI section - if (fullResponse.length === 0 && delta.textDelta.length > 0) { + if ( + fullResponse.length === 0 && + delta.textDelta.length > 0 && + !useSpecificModel + ) { // Update the UI uiStream.update(answerSection) }