feat(ai): structured-output middleware coverage (closes #390) #600
main fromrefs/pull/600/head·merged by AlemTuzlak View on GitHubSummary#
- Routes the final structured-output adapter call in
chat({ outputSchema })(bothPromise<T>and streaming variants) through the same middleware pipeline as the agent loop. Closes #390. - New public surface:
'structuredOutput'value onChatMiddlewarePhase, optionalonStructuredOutputConfighook onChatMiddleware, new exportedStructuredOutputMiddlewareConfigtype. - Standard Schema validation moved into the engine's finalization step (Promise path); validation failures now route through
onErrorinstead of throwing post-engine. Streaming path intentionally defers validation to the consumer (documented). - Internal cleanup: the
RUN_STARTED/RUN_FINISHEDsuppression hack inrunStreamingStructuredOutputis relocated into the engine (streamModelResponse) and gated onfinalStructuredOutput.yieldChunks; consumer still sees exactly one outer pair.
Behavior change for existing middleware#
onChunknow observes chunks from the final structured-output call (attributed toctx.phase === 'structuredOutput'). Phase-aware middleware can branch onctx.phaseto opt out:if (ctx.phase === 'structuredOutput') return.onFinishfires once at the end of the wholechat()invocation, after finalization (not after the agent loop).info.usage/info.finishReason/info.contentreflect the agent-loop's terminal state only — useonUsageto capture finalization tokens.
Files#
- New public surface + engine wiring in
packages/typescript/ai/src/activities/chat/**. - 11 unit tests in
packages/typescript/ai/tests/structured-output-middleware.test.ts(Promise + streaming paths, hook transforms, schema-validation routing, fallback, backward-compat). - 2 E2E specs + harness extensions (
phase-recordermode +structured-output(-stream)scenarios) intesting/e2e/. - Agent skills and public docs updated (
packages/typescript/ai/skills/ai-core/middleware/SKILL.md,packages/typescript/ai/skills/ai-core/structured-outputs/SKILL.md,docs/structured-outputs/overview.md,docs/advanced/middleware.md).
Test plan#
-
pnpm --filter @tanstack/ai test:lib— 857 unit tests pass (39 files) -
pnpm --filter @tanstack/ai test:types— clean -
pnpm --filter @tanstack/ai test:eslint— clean -
pnpm --filter @tanstack/ai-e2e test:e2e— 181 tests pass (incl. 2 new structured-output × middleware specs) -
pnpm test:docs— 297 markdown files, no broken links -
pnpm test:build— 29 Nx projects clean
Review history#
10 commits on this branch. The cr-loop ran 6 rounds + Procedure 3 bucket-(c) audit; load-bearing findings folded back into the diff:
- Round 1: 14 items (types, error preservation, abort handling, doc claims)
- Round 2: 3 items (mid-finalization abort routing, finalization-state pollution, synth start-before-error)
- Round 3: 1 item (
info.usagedoc claim alignment) - Round 4: 1 item (
toolsfield documented as transformable but not forwarded) - Round 5: 1 item (
runStreamingStructuredOutputJSDoc validation claim) - Round 6: 1 item (
docs/structured-outputs/overview.mdserver-side-validation claim) - Procedure 3: 1 PROMOTE_TO_A (schema-conversion asymmetry between Promise and streaming) + 3 PROMOTE_TO_B (fallback
mock-prefix, RUN_ERRORthreadId, JSDoc typo)
Summary by CodeRabbit#
New Features
- Added middleware support for structured output with a new
structuredOutputphase andonStructuredOutputConfighook for customizing output schemas. - Middleware now observes the entire structured-output finalization process, including chunks and token usage.
- Added middleware support for structured output with a new
Bug Fixes
- Fixed middleware lifecycle timing—
onFinishnow fires once after all operations complete.
- Fixed middleware lifecycle timing—
Documentation
- Updated middleware guides with structured-output lifecycle details and examples.
- 1
Actionable comments posted: 1
🧹 Nitpick comments (1)
testing/e2e/tests/structured-output-middleware.spec.ts (1)
82-83: ⚡ Quick winReplace fixed 2s sleeps with explicit readiness waits.
Lines 82 and 113 use
page.waitForTimeout(2000)which can cause flaky or unnecessarily slow E2E runs. Use Playwright's explicit wait mechanisms instead (e.g.,waitForSelector(),waitForLoadState(), orwaitForFunction()) to wait for deterministic UI/server-ready signals.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@testing/e2e/tests/structured-output-middleware.spec.ts` around lines 82 - 83, The test uses brittle fixed sleeps via page.waitForTimeout(2000); replace those calls with deterministic Playwright waits: identify the UI/state the test expects (e.g., a rendered element or network idle) and swap page.waitForTimeout(2000) with an explicit wait such as page.waitForSelector('<selector>') or page.waitForLoadState('networkidle') or page.waitForFunction(() => /* readiness predicate */) in the tests inside structured-output-middleware.spec.ts so the code paths around the existing page.waitForTimeout invocations wait for a concrete selector or readiness condition instead of a fixed 2s sleep.🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Inline comments: In `@packages/typescript/ai/src/activities/chat/index.ts`: - Around line 600-606: The current finalization condition allows structured finalization to run even after the agent-loop set earlyTermination for RUN_ERROR; update the guard where finalStructuredOutput is checked (the block that calls this.runStructuredFinalization()) to also check that earlyTermination is false (e.g., include !this.earlyTermination) so structured finalization is skipped when the loop ended with RUN_ERROR; apply the same additional check to the other occurrence referenced (the block around lines 909-913) so no structured-output provider call runs after an earlyTermination. --- Nitpick comments: In `@testing/e2e/tests/structured-output-middleware.spec.ts`: - Around line 82-83: The test uses brittle fixed sleeps via page.waitForTimeout(2000); replace those calls with deterministic Playwright waits: identify the UI/state the test expects (e.g., a rendered element or network idle) and swap page.waitForTimeout(2000) with an explicit wait such as page.waitForSelector('<selector>') or page.waitForLoadState('networkidle') or page.waitForFunction(() => /* readiness predicate */) in the tests inside structured-output-middleware.spec.ts so the code paths around the existing page.waitForTimeout invocations wait for a concrete selector or readiness condition instead of a fixed 2s sleep.🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
762a55c1-2fc0-416c-9b10-4ea662967eef📥 Commits
Reviewing files that changed from the base of the PR and between 1e4df183553a34ea6a4e9010b692314b48e66e67 and c988bbb941dfca276b908943f8a7521a49b489e5.
📒 Files selected for processing (35)
.changeset/structured-output-middleware-coverage.mddocs/advanced/middleware.mddocs/reference/functions/chat.mddocs/reference/functions/createChatOptions.mddocs/reference/index.mddocs/reference/interfaces/AbortInfo.mddocs/reference/interfaces/AfterToolCallInfo.mddocs/reference/interfaces/ChatMiddleware.mddocs/reference/interfaces/ChatMiddlewareConfig.mddocs/reference/interfaces/ChatMiddlewareContext.mddocs/reference/interfaces/ErrorInfo.mddocs/reference/interfaces/FinishInfo.mddocs/reference/interfaces/IterationInfo.mddocs/reference/interfaces/StructuredOutputMiddlewareConfig.mddocs/reference/interfaces/ToolCallHookContext.mddocs/reference/interfaces/ToolPhaseCompleteInfo.mddocs/reference/interfaces/UsageInfo.mddocs/reference/type-aliases/BeforeToolCallDecision.mddocs/reference/type-aliases/ChatMiddlewarePhase.mddocs/structured-outputs/overview.mdpackages/typescript/ai/skills/ai-core/middleware/SKILL.mdpackages/typescript/ai/skills/ai-core/structured-outputs/SKILL.mdpackages/typescript/ai/src/activities/chat/index.tspackages/typescript/ai/src/activities/chat/middleware/compose.tspackages/typescript/ai/src/activities/chat/middleware/index.tspackages/typescript/ai/src/activities/chat/middleware/types.tspackages/typescript/ai/src/index.tspackages/typescript/ai/tests/chat-structured-output-stream.test.tspackages/typescript/ai/tests/structured-output-middleware.test.tspackages/typescript/ai/tests/test-utils.tstesting/e2e/fixtures/middleware-test/structured-output.jsontesting/e2e/src/lib/phase-capture.tstesting/e2e/src/routes/api.middleware-test.tstesting/e2e/src/routes/middleware-test.tsxtesting/e2e/tests/structured-output-middleware.spec.ts
packages/typescript/ai/src/activities/chat/index.ts lines 610 to 616@@ -523,7 +593,14 @@523- this.terminalHookCalled = true524- await this.middlewareRunner.runOnFinish(this.middlewareCtx, {525- finishReason: this.lastFinishReason,526- duration: Date.now() - this.streamStartTime,527- content: this.accumulatedContent,528- usage: this.finishedEvent?.usage,529- })593+ // ============================================================594+ // Structured-output finalization (new — closes issue #390)595+ // ============================================================596+ // After the agent loop ends, if a structured-output finalization was597+ // requested AND the run hasn't already errored/aborted, run it through598+ // the middleware pipeline. The terminal hook fires once at the very599+ // end (after finalization), not after the agent loop.600+ if (601+ this.finalStructuredOutput &&602+ !this.isCancelled() &&603+ !this.finalizationError604+ ) {605+ yield* this.runStructuredFinalization()606+ }⚠️ Potential issue | 🟠 Major | ⚡ Quick win
Skip structured-output finalization after agent-loop RUN_ERROR.
Line 909setsearlyTermination = trueonRUN_ERROR, butLine 600still allows finalization to run. That can issue an extra structured-output provider call after a failed loop and can mis-route terminal behavior.💡 Proposed fix
if ( this.finalStructuredOutput && + !this.earlyTermination && !this.isCancelled() && !this.finalizationError ) { yield* this.runStructuredFinalization() }Also applies to: 909-913
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/typescript/ai/src/activities/chat/index.ts` around lines 600 - 606, The current finalization condition allows structured finalization to run even after the agent-loop set earlyTermination for RUN_ERROR; update the guard where finalStructuredOutput is checked (the block that calls this.runStructuredFinalization()) to also check that earlyTermination is false (e.g., include !this.earlyTermination) so structured finalization is skipped when the loop ended with RUN_ERROR; apply the same additional check to the other occurrence referenced (the block around lines 909-913) so no structured-output provider call runs after an earlyTermination.🚀 Changeset Version Preview#
10 package(s) bumped directly, 20 bumped as dependents.
🟥 Major bumps#
Package Version Reason @tanstack/ai-code-mode0.1.16 → 1.0.0 Changeset @tanstack/ai-code-mode-skills0.1.16 → 1.0.0 Changeset @tanstack/ai-elevenlabs0.2.8 → 1.0.0 Changeset @tanstack/ai-fal0.7.9 → 1.0.0 Changeset @tanstack/ai-gemini0.10.8 → 1.0.0 Changeset @tanstack/ai-grok0.8.5 → 1.0.0 Changeset @tanstack/ai-openai0.9.5 → 1.0.0 Changeset @tanstack/ai-openrouter0.9.5 → 1.0.0 Changeset @tanstack/ai-react-ui0.7.2 → 1.0.0 Changeset @tanstack/ai-anthropic0.10.1 → 1.0.0 Dependent @tanstack/ai-event-client0.3.6 → 1.0.0 Dependent @tanstack/ai-groq0.2.4 → 1.0.0 Dependent @tanstack/ai-isolate-node0.1.16 → 1.0.0 Dependent @tanstack/ai-isolate-quickjs0.1.16 → 1.0.0 Dependent @tanstack/ai-ollama0.6.19 → 1.0.0 Dependent @tanstack/ai-preact0.6.28 → 1.0.0 Dependent @tanstack/ai-react0.11.3 → 1.0.0 Dependent @tanstack/ai-solid0.10.3 → 1.0.0 Dependent @tanstack/ai-solid-ui0.6.7 → 1.0.0 Dependent @tanstack/ai-svelte0.10.3 → 1.0.0 Dependent @tanstack/ai-vue0.10.4 → 1.0.0 Dependent @tanstack/openai-base0.3.4 → 1.0.0 Dependent 🟨 Minor bumps#
Package Version Reason @tanstack/ai0.20.1 → 0.21.0 Changeset 🟩 Patch bumps#
Package Version Reason @tanstack/ai-client0.11.3 → 0.11.4 Dependent @tanstack/ai-devtools-core0.3.33 → 0.3.34 Dependent @tanstack/ai-isolate-cloudflare0.2.7 → 0.2.8 Dependent @tanstack/ai-vue-ui0.1.40 → 0.1.41 Dependent @tanstack/preact-ai-devtools0.1.37 → 0.1.38 Dependent @tanstack/react-ai-devtools0.2.37 → 0.2.38 Dependent @tanstack/solid-ai-devtools0.2.37 → 0.2.38 Dependent View your CI Pipeline Execution ↗ for commit 010c810cf4102b2743727fadeba158800f8770f8
Command Status Duration Result nx run-many --targets=build --exclude=examples/...✅ Succeeded 1m 5s View ↗
☁️ Nx Cloud last updated this comment at
2026-05-21 04:58:27UTC@tanstack/ai
npm i https://pkg.pr.new/@tanstack/ai@600@tanstack/ai-anthropic
npm i https://pkg.pr.new/@tanstack/ai-anthropic@600@tanstack/ai-client
npm i https://pkg.pr.new/@tanstack/ai-client@600@tanstack/ai-code-mode
npm i https://pkg.pr.new/@tanstack/ai-code-mode@600@tanstack/ai-code-mode-skills
npm i https://pkg.pr.new/@tanstack/ai-code-mode-skills@600@tanstack/ai-devtools-core
npm i https://pkg.pr.new/@tanstack/ai-devtools-core@600@tanstack/ai-elevenlabs
npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@600@tanstack/ai-event-client
npm i https://pkg.pr.new/@tanstack/ai-event-client@600@tanstack/ai-fal
npm i https://pkg.pr.new/@tanstack/ai-fal@600@tanstack/ai-gemini
npm i https://pkg.pr.new/@tanstack/ai-gemini@600@tanstack/ai-grok
npm i https://pkg.pr.new/@tanstack/ai-grok@600@tanstack/ai-groq
npm i https://pkg.pr.new/@tanstack/ai-groq@600@tanstack/ai-isolate-cloudflare
npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@600@tanstack/ai-isolate-node
npm i https://pkg.pr.new/@tanstack/ai-isolate-node@600@tanstack/ai-isolate-quickjs
npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@600@tanstack/ai-ollama
npm i https://pkg.pr.new/@tanstack/ai-ollama@600@tanstack/ai-openai
npm i https://pkg.pr.new/@tanstack/ai-openai@600@tanstack/ai-openrouter
npm i https://pkg.pr.new/@tanstack/ai-openrouter@600@tanstack/ai-preact
npm i https://pkg.pr.new/@tanstack/ai-preact@600@tanstack/ai-react
npm i https://pkg.pr.new/@tanstack/ai-react@600@tanstack/ai-react-ui
npm i https://pkg.pr.new/@tanstack/ai-react-ui@600@tanstack/ai-solid
npm i https://pkg.pr.new/@tanstack/ai-solid@600@tanstack/ai-solid-ui
npm i https://pkg.pr.new/@tanstack/ai-solid-ui@600@tanstack/ai-svelte
npm i https://pkg.pr.new/@tanstack/ai-svelte@600@tanstack/ai-utils
npm i https://pkg.pr.new/@tanstack/ai-utils@600@tanstack/ai-vue
npm i https://pkg.pr.new/@tanstack/ai-vue@600@tanstack/ai-vue-ui
npm i https://pkg.pr.new/@tanstack/ai-vue-ui@600@tanstack/openai-base
npm i https://pkg.pr.new/@tanstack/openai-base@600@tanstack/preact-ai-devtools
npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@600@tanstack/react-ai-devtools
npm i https://pkg.pr.new/@tanstack/react-ai-devtools@600@tanstack/solid-ai-devtools
npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@600commit:
27ae70fActionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Inline comments: In `@docs/reference/interfaces/ChatMiddleware.md`: - Around line 179-183: Update the prose for the Chat middleware config hooks (specifically the onConfig and onStructuredOutputConfig descriptions) to explicitly document that returning null indicates a pass-through/no-op (i.e., leave the current config unchanged and do not perform a merge), in contrast to returning void or a Partial<ChatMiddlewareConfig> which performs no change or a partial merge respectively; apply the same clarifying sentence to all other occurrences of these hook signatures (the other comment blocks referencing onConfig/onStructuredOutputConfig) so the null semantics are consistently documented.🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
92543861-2971-402b-81fc-cf03fb9d0254📥 Commits
Reviewing files that changed from the base of the PR and between c988bbb941dfca276b908943f8a7521a49b489e5 and d6c1200f29718c3115d08087173b9411c3b47723.
📒 Files selected for processing (14)
docs/reference/functions/chat.mddocs/reference/functions/createChatOptions.mddocs/reference/index.mddocs/reference/interfaces/AbortInfo.mddocs/reference/interfaces/AfterToolCallInfo.mddocs/reference/interfaces/ChatMiddleware.mddocs/reference/interfaces/ErrorInfo.mddocs/reference/interfaces/FinishInfo.mddocs/reference/interfaces/IterationInfo.mddocs/reference/interfaces/StructuredOutputMiddlewareConfig.mddocs/reference/interfaces/ToolCallHookContext.mddocs/reference/interfaces/ToolPhaseCompleteInfo.mddocs/reference/interfaces/UsageInfo.mddocs/reference/type-aliases/BeforeToolCallDecision.md
✅ Files skipped from review due to trivial changes (12)
- docs/reference/functions/createChatOptions.md
- docs/reference/interfaces/AfterToolCallInfo.md
- docs/reference/interfaces/ToolCallHookContext.md
- docs/reference/type-aliases/BeforeToolCallDecision.md
- docs/reference/interfaces/ErrorInfo.md
- docs/reference/interfaces/AbortInfo.md
- docs/reference/index.md
- docs/reference/interfaces/StructuredOutputMiddlewareConfig.md
- docs/reference/interfaces/FinishInfo.md
- docs/reference/interfaces/UsageInfo.md
- docs/reference/interfaces/IterationInfo.md
- docs/reference/interfaces/ToolPhaseCompleteInfo.md
docs/reference/interfaces/ChatMiddleware.md lines 179 to 183@@ -176,5 +176,8 @@176176 optional onConfig: (ctx, config) =>177177 | void178178 | Partial<ChatMiddlewareConfig>179- | Promise<void | Partial<ChatMiddlewareConfig>>179+ | Promise<180+ | void181+ | Partial<ChatMiddlewareConfig>182+ | null>180183 | null;⚠️ Potential issue | 🟡 Minor | ⚡ Quick win
Document
nullsemantics for config hooks explicitly.Both
onConfigandonStructuredOutputConfignow allow returningnull, but the prose only explainsvoidand partial merges. Please add one sentence clarifying whatnulldoes (e.g., pass-through/no-op) to avoid middleware ambiguity.Also applies to: 191-193, 327-329, 338-340, 364-366
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/reference/interfaces/ChatMiddleware.md` around lines 179 - 183, Update the prose for the Chat middleware config hooks (specifically the onConfig and onStructuredOutputConfig descriptions) to explicitly document that returning null indicates a pass-through/no-op (i.e., leave the current config unchanged and do not perform a merge), in contrast to returning void or a Partial<ChatMiddlewareConfig> which performs no change or a partial merge respectively; apply the same clarifying sentence to all other occurrences of these hook signatures (the other comment blocks referencing onConfig/onStructuredOutputConfig) so the null semantics are consistently documented.AlemTuzlak merged this188fe11
AlemTuzlak closed this
Sign in to join this conversation.
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
📝 Walkthrough
Walkthrough#
This PR integrates the final structured-output provider call into the middleware pipeline. It introduces a new
'structuredOutput'middleware phase, a dedicatedonStructuredOutputConfighook for transforming the output schema before the provider call, routes structured-output finalization throughTextEngine, refactors public APIs to use engine-driven finalization, adds comprehensive test and E2E coverage, and updates documentation.Changes#
Structured-output middleware integration
packages/typescript/ai/src/activities/chat/middleware/types.ts,packages/typescript/ai/src/activities/chat/middleware/index.ts,packages/typescript/ai/src/index.tsStructuredOutputMiddlewareConfigtype extendingChatMiddlewareConfigwithoutputSchema: JSONSchema, extendedChatMiddlewarePhaseto include'structuredOutput', new optionalonStructuredOutputConfighook onChatMiddleware, and public re-exports updated.packages/typescript/ai/src/activities/chat/middleware/compose.tsMiddlewareRunner.runOnStructuredOutputConfig()sequentially invokes each middleware'sonStructuredOutputConfighook, shallow-merges partial config returns, and emits instrumentation events.packages/typescript/ai/src/activities/chat/index.ts(lines 38, 58, 298–320, 379–404, 512–538, 563–652, 811–824, 1592–1950)finalStructuredOutputconfig/state toTextEngine, implementrunStructuredFinalization()to run adapter structured-output stream through middleware, synthesize missingstructured-output.startevents, route terminal hooks by finalization error, and suppress agent-loop lifecycle events whenyieldChunksis enabled.packages/typescript/ai/src/activities/chat/index.ts(lines 2078, 2227–2245, 2255–2348, 2364–2369, 2420–2434, 2495–2519),packages/typescript/ai/src/activities/chat/tools/schema-converter.ts(lines 342–360, 369–370, 391)runAgenticStructuredOutputuses engine finalization with optional Standard Schemavalidatecallback;runStreamingStructuredOutputsimplified to drive entire flow through engine withyieldChunks: true; newStandardSchemaValidationErrorclass captures Standard Schema validation issues; fallback error handling improved.packages/typescript/ai/tests/structured-output-middleware.test.ts,packages/typescript/ai/tests/chat-structured-output-stream.test.ts,packages/typescript/ai/tests/test-utils.tsonStructuredOutputConfigtransforms, terminal hook routing, failure paths, validation, and backward compatibility; existing streaming tests updated to reflect consumer-side validation responsibility; mock adapter enhanced withstructuredOutputStreamoption.testing/e2e/src/lib/phase-capture.ts,testing/e2e/src/routes/api.middleware-test.ts,testing/e2e/src/routes/middleware-test.tsx,testing/e2e/tests/structured-output-middleware.spec.ts,testing/e2e/fixtures/middleware-test/structured-output.jsonexamples/ts-react-chat/src/routes/api.structured-output.ts,examples/ts-react-chat/src/routes/generations.structured-output.tsxdocs/,packages/typescript/ai/skills/ai-core/StructuredOutputMiddlewareConfigreference page, updatedChatMiddlewareandChatMiddlewarePhasedocs,onStructuredOutputConfighook and phase semantics documented in advanced middleware guide,ai-core/middlewareandai-core/structured-outputsSKILL.md updated with middleware coverage patterns, numerous "Defined in" reference links updated.Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~75 minutes
Possibly related issues#
#390: The primary motivation—middleware now wraps the final structured-output provider call via the newstructuredOutputphase andonStructuredOutputConfighook, addressing the missing middleware coverage for structured-output finalization.#570: Changes tostructuredOutputStreamfallback handling and new structured-output lifecycle event routing inpackages/typescript/ai/src/activities/chat/index.tsmay affect native adapter implementations.#605: Both PRs introduce thestructuredOutputphase andStructuredOutputMiddlewareConfigsurface.Possibly related PRs#
structured-output.start/structured-output.complete), messageId handling, and chunk routing; this PR adds middleware phase/hook semantics on top of those event flows.Suggested reviewers#
Poem#
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#390.#390: the final structured-output call is routed through middleware pipeline, a dedicated 'structuredOutput' phase and 'onStructuredOutputConfig' hook are provided, behavior is consistent across adapters, and limitations are documented.#390objectives.✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share