(part: ExtendedStreamPart)
| 194 | * @yields ApiStreamChunk objects corresponding to the stream part |
| 195 | */ |
| 196 | export function* processAiSdkStreamPart(part: ExtendedStreamPart): Generator<ApiStreamChunk> { |
| 197 | switch (part.type) { |
| 198 | case "text": |
| 199 | case "text-delta": |
| 200 | yield { type: "text", text: (part as { text: string }).text } |
| 201 | break |
| 202 | |
| 203 | case "reasoning": |
| 204 | case "reasoning-delta": |
| 205 | yield { type: "reasoning", text: (part as { text: string }).text } |
| 206 | break |
| 207 | |
| 208 | case "tool-input-start": |
| 209 | yield { |
| 210 | type: "tool_call_start", |
| 211 | id: part.id, |
| 212 | name: part.toolName, |
| 213 | } |
| 214 | break |
| 215 | |
| 216 | case "tool-input-delta": |
| 217 | yield { |
| 218 | type: "tool_call_delta", |
| 219 | id: part.id, |
| 220 | delta: part.delta, |
| 221 | } |
| 222 | break |
| 223 | |
| 224 | case "tool-input-end": |
| 225 | yield { |
| 226 | type: "tool_call_end", |
| 227 | id: part.id, |
| 228 | } |
| 229 | break |
| 230 | |
| 231 | case "tool-call": |
| 232 | // Complete tool call - emit for compatibility |
| 233 | yield { |
| 234 | type: "tool_call", |
| 235 | id: part.toolCallId, |
| 236 | name: part.toolName, |
| 237 | arguments: typeof part.input === "string" ? part.input : JSON.stringify(part.input), |
| 238 | } |
| 239 | break |
| 240 | |
| 241 | case "source": |
| 242 | // Handle both URL and document source types |
| 243 | if ("url" in part) { |
| 244 | yield { |
| 245 | type: "grounding", |
| 246 | sources: [ |
| 247 | { |
| 248 | title: part.title || "Source", |
| 249 | url: part.url, |
| 250 | snippet: undefined, |
| 251 | }, |
| 252 | ], |
| 253 | } |
no test coverage detected