Open History to see the last commit
1export interface ClientAssistantPlaceholderInput {
2 role: string
3 source: 'client' | 'server'
4 content?: string
5 toolCalls?: Array<unknown>
6 parts?: Array<unknown>
7}
8
9export interface ClientToolCallMessageInput {
10 messageId: string
11 toolCallId: string
12 toolName: string
13 arguments: string
14 state: string
15 timestamp: number
16 source: 'client' | 'server'
17 requestId?: string
18 approvalRequired?: boolean
19 approvalId?: string
20 approvalApproved?: boolean
21}
22
23export function createClientToolCallMessage(input: ClientToolCallMessageInput) {
24 return {
25 id: input.messageId,
26 role: 'assistant' as const,
27 content: '',
28 timestamp: input.timestamp,
29 parts: [],
30 toolCalls: [
31 {
32 id: input.toolCallId,
33 name: input.toolName,
34 arguments: input.arguments,
35 state: input.state,
36 ...(input.approvalRequired !== undefined
37 ? { approvalRequired: input.approvalRequired }
38 : {}),
39 ...(input.approvalId ? { approvalId: input.approvalId } : {}),
40 ...(input.approvalApproved !== undefined
41 ? { approvalApproved: input.approvalApproved }
42 : {}),
43 },
44 ],
45 source: input.source,
46 ...(input.requestId ? { requestId: input.requestId } : {}),
47 }
48}
49
50export function shouldSkipClientAssistantPlaceholder(
51 message: ClientAssistantPlaceholderInput,
52): boolean {
53 return (
54 message.role === 'assistant' &&
55 message.source === 'client' &&
56 !message.content &&
57 (!message.toolCalls || message.toolCalls.length === 0) &&
58 (!message.parts || message.parts.length === 0)
59 )
60}