import { useChat } from '@ai-sdk/react';
import { DefaultChatTransport } from 'ai';
const AGENT_NAME = 'my-namespace/my-agent';
// Configure transport with task context
const transport = useMemo(
() => new DefaultChatTransport({
api: '/api/chat',
body: { agentName: AGENT_NAME, taskId },
}),
[taskId]
);
const { messages, sendMessage, status } = useChat({
id: 'chat-session', // Client-generated session ID
transport,
});
// Send message with task context
await sendMessage(
{ text: inputValue },
{ body: { agentName: AGENT_NAME, taskId } }
);