(
toolCalls: Array<{ id: string; name: string; arguments: string }>,
messageId: string = 'msg-1',
model: string = 'test',
includeToolInputAvailable: boolean = true,
)
| 207 | * Optionally includes tool-input-available chunks to trigger onToolCall |
| 208 | */ |
| 209 | export function createToolCallChunks( |
| 210 | toolCalls: Array<{ id: string; name: string; arguments: string }>, |
| 211 | messageId: string = 'msg-1', |
| 212 | model: string = 'test', |
| 213 | includeToolInputAvailable: boolean = true, |
| 214 | ): Array<StreamChunk> { |
| 215 | const chunks: Array<StreamChunk> = [] |
| 216 | const runId = `run-${messageId}` |
| 217 | |
| 218 | for (let i = 0; i < toolCalls.length; i++) { |
| 219 | const toolCall = toolCalls[i]! |
| 220 | |
| 221 | // TOOL_CALL_START event |
| 222 | chunks.push({ |
| 223 | type: 'TOOL_CALL_START', |
| 224 | toolCallId: toolCall.id, |
| 225 | toolCallName: toolCall.name, |
| 226 | toolName: toolCall.name, |
| 227 | model, |
| 228 | timestamp: Date.now(), |
| 229 | index: i, |
| 230 | } as StreamChunk) |
| 231 | |
| 232 | // TOOL_CALL_ARGS event |
| 233 | chunks.push({ |
| 234 | type: 'TOOL_CALL_ARGS', |
| 235 | toolCallId: toolCall.id, |
| 236 | model, |
| 237 | timestamp: Date.now(), |
| 238 | delta: toolCall.arguments, |
| 239 | } as StreamChunk) |
| 240 | |
| 241 | // Add tool-input-available CUSTOM chunk if requested |
| 242 | if (includeToolInputAvailable) { |
| 243 | let parsedInput: any |
| 244 | try { |
| 245 | parsedInput = JSON.parse(toolCall.arguments) |
| 246 | } catch { |
| 247 | parsedInput = toolCall.arguments |
| 248 | } |
| 249 | |
| 250 | chunks.push({ |
| 251 | type: 'CUSTOM', |
| 252 | model, |
| 253 | timestamp: Date.now(), |
| 254 | name: 'tool-input-available', |
| 255 | value: { |
| 256 | toolCallId: toolCall.id, |
| 257 | toolName: toolCall.name, |
| 258 | input: parsedInput, |
| 259 | }, |
| 260 | } as StreamChunk) |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | chunks.push({ |
| 265 | type: 'RUN_FINISHED', |
| 266 | runId, |
no test coverage detected