UNPKG

@tanstack/ai

Version:

Type-safe TypeScript AI SDK for streaming chat, tool calling, agents, structured outputs, and multimodal generation.

34 lines (33 loc) 1.06 kB
//#region src/strip-to-spec-middleware.ts /** * Strip only the deprecated nested `error` object from RUN_ERROR events. * The flat `message`/`code` fields are the spec-compliant form. * * All other fields pass through unchanged. @ag-ui/core's BaseEventSchema * uses `.passthrough()`, so extra fields (model, content, usage, * finishReason, toolName, stepId, etc.) are allowed and won't break * spec validation or verifyEvents. */ function stripToSpec(chunk) { if (chunk.type === "RUN_ERROR" && "error" in chunk) { const { error: _deprecated, ...rest } = chunk; return rest; } return chunk; } /** * Middleware that ensures events are AG-UI spec compliant. * Currently only strips the deprecated nested `error` object from RUN_ERROR. * All other fields pass through unchanged (passthrough allowed by spec). */ function stripToSpecMiddleware() { return { name: "strip-to-spec", onChunk(_ctx, chunk) { return stripToSpec(chunk); } }; } //#endregion export { stripToSpec, stripToSpecMiddleware }; //# sourceMappingURL=strip-to-spec-middleware.js.map