{"record":{"id":"666fc0c9b8d21311","repo":"vercel/ai","slug":"expected-parsed-tool-call-stream-part-got-inp","errorCode":null,"errorMessage":"`Expected parsed tool-call stream part, got '${input.part.type}'.`","messagePattern":"`Expected parsed tool-call stream part, got '(.+?)'\\.`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/harness/src/agent/internal/run-prompt.ts","lineNumber":1159,"sourceCode":"  // rejection.\n  done.catch(() => {});\n\n  return { result, done };\n}\n\ntype HostToolOutcome =\n  | { ok: true; output: unknown }\n  | { ok: false; error: unknown };\n\ntype HostToolExecution =\n  | { executed: false }\n  | { executed: true; outcome: HostToolOutcome };\n\nfunction asToolCallTextStreamPart<TOOLS extends ToolSet>(input: {\n  part: TextStreamPart<TOOLS>;\n}): ToolCallTextStreamPart {\n  if (input.part.type !== 'tool-call') {\n    throw new Error(\n      `Expected parsed tool-call stream part, got '${input.part.type}'.`,\n    );\n  }\n  return input.part as ToolCallTextStreamPart;\n}\n\ntype ToolCallTextStreamPart = {\n  readonly type: 'tool-call';\n  readonly toolCallId: string;\n  readonly toolName: string;\n  readonly input: unknown;\n  readonly providerExecuted?: boolean;\n  readonly providerMetadata?: unknown;\n  readonly dynamic?: boolean;\n  readonly invalid?: boolean;\n  readonly error?: unknown;\n  readonly title?: string;\n};","sourceCodeStart":1141,"sourceCodeEnd":1177,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness/src/agent/internal/run-prompt.ts#L1141-L1177","documentation":"Internal invariant check in `asToolCallTextStreamPart`: the function was handed a stream part whose `type` is not 'tool-call' when a parsed tool-call part was required. This is an SDK-internal type-narrowing assertion, so hitting it means an internal code path or a badly patched/extended stream pipeline passed the wrong part type.","triggerScenarios":"Any code path calling `asToolCallTextStreamPart` with a TextStreamPart whose `type` is something other than 'tool-call' (e.g. 'text', 'tool-result', 'error').","commonSituations":"Bugs in the SDK's own stream transformation pipeline; custom middleware or monkey-patches that reorder/relabel stream parts; version-mismatched @ai-sdk packages producing unexpected part types.","solutions":["Pin all @ai-sdk/* packages to matching versions so stream part types are consistent.","Remove or fix custom stream middleware/transformations that alter part types before this helper runs.","If it reproduces on unmodified SDK code, file a bug with the harness and stream trace."],"exampleFix":"// before\nasToolCallTextStreamPart({ type: 'tool-result', ... }); // wrong part\n\n// after\nif (part.type === 'tool-call') {\n  asToolCallTextStreamPart(part);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isToolCallPart<TOOLS extends ToolSet>(part: TextStreamPart<TOOLS>): part is Extract<TextStreamPart<TOOLS>, { type: 'tool-call' }> {\n  return part.type === 'tool-call';\n}","tryCatchPattern":"try {\n  asToolCallTextStreamPart(part);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Expected parsed tool-call stream part')) {\n    // inspect upstream stream transformation for part-type corruption\n  }\n  throw e;\n}","preventionTips":["Keep all @ai-sdk packages on identical versions.","Do not add stream middleware that changes part `type` fields.","Report reproducible hits on stock SDK code as a bug with a stream trace."],"tags":["internal","invariant","stream","type-narrowing"],"backgroundTag":"invariant-violation","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}