(
toolKey: string,
toolCall: OpenAIStreamToolCallDelta,
)
| 1242 | } |
| 1243 | |
| 1244 | const ensureToolState = ( |
| 1245 | toolKey: string, |
| 1246 | toolCall: OpenAIStreamToolCallDelta, |
| 1247 | ): OpenAIStreamToolState => { |
| 1248 | const existing = openTools.get(toolKey) |
| 1249 | if (existing) { |
| 1250 | if (!existing.name && toolCall.function?.name) { |
| 1251 | existing.name = toolCall.function.name |
| 1252 | } |
| 1253 | if (toolCall.id && existing.id.startsWith('generated-')) { |
| 1254 | existing.id = toolCall.id |
| 1255 | } |
| 1256 | return existing |
| 1257 | } |
| 1258 | |
| 1259 | const state: OpenAIStreamToolState = { |
| 1260 | contentIndex: nextIndex++, |
| 1261 | id: toolCall.id ?? `generated-${randomUUID()}`, |
| 1262 | name: toolCall.function?.name ?? undefined, |
| 1263 | arguments: '', |
| 1264 | started: false, |
| 1265 | } |
| 1266 | openTools.set(toolKey, state) |
| 1267 | return state |
| 1268 | } |
| 1269 | |
| 1270 | const emitToolStartIfReady = ( |
| 1271 | state: OpenAIStreamToolState, |
no test coverage detected