Skip to content

feat(ai): add typed runtime context#628

Open
AlemTuzlak wants to merge 7 commits into
mainfrom
feat/typed-runtime-context-pr
Open

feat(ai): add typed runtime context#628
AlemTuzlak wants to merge 7 commits into
mainfrom
feat/typed-runtime-context-pr

Conversation

@AlemTuzlak
Copy link
Copy Markdown
Contributor

@AlemTuzlak AlemTuzlak commented May 22, 2026

Summary

  • Adds typed runtime context generics for chat, server/client tools, middleware, ChatClient, and framework useChat wrappers without breaking untyped middleware/tools.
  • Threads server context through chat() and client-local context through ChatClient so tool and middleware implementations can access typed runtime data.
  • Adds docs, e2e coverage for server/client/client-forwarded context, and a playable ts-react-chat runtime context route.

Test Plan

  • git diff --cached --check
  • pnpm --filter @tanstack/ai-event-client build
  • pnpm --filter @tanstack/ai test:types
  • pnpm --filter @tanstack/ai build
  • pnpm --filter @tanstack/ai-client test:types
  • pnpm --filter @tanstack/ai test:lib -- run tests/tool-context.test.ts tests/tool-calls-context.test.ts tests/tool-call-manager-context.test.ts tests/middleware-context.test.ts tests/type-check.test.ts
  • pnpm --filter @tanstack/ai-client test:lib -- run tests/chat-client-context.test.ts tests/tool-types.test.ts
  • pnpm --filter @tanstack/ai-client build
  • pnpm --filter @tanstack/ai-react test:types
  • pnpm --filter @tanstack/ai-solid test:types
  • pnpm --filter @tanstack/ai-vue test:types
  • pnpm --filter @tanstack/ai-svelte test:types
  • pnpm --filter @tanstack/ai-preact test:types
  • pnpm --filter @tanstack/ai-code-mode test:types
  • pnpm --filter @tanstack/ai-react test:lib -- run tests/use-chat-types.test.ts
  • pnpm --filter @tanstack/ai-svelte test:lib -- run tests/create-chat-types.test.ts
  • pnpm --filter @tanstack/ai-utils build
  • pnpm --filter @tanstack/openai-base build
  • Provider adapter builds required by the e2e dev server: @tanstack/ai-openai, @tanstack/ai-anthropic, @tanstack/ai-gemini, @tanstack/ai-grok, @tanstack/ai-groq, @tanstack/ai-elevenlabs, @tanstack/ai-ollama, @tanstack/ai-openrouter
  • pnpm --filter @tanstack/ai-e2e test:e2e -- tests/tools-test/runtime-context.spec.ts

Notes: Vite/svelte-check emitted the existing missing .svelte-kit/tsconfig.json warning for examples/ts-svelte-chat; the commands above exited successfully where listed.

Summary by CodeRabbit

  • New Features
    • Typed runtime context across chat, tools, and middleware (client-local context option; server-side context passed into runs).
  • Documentation
    • Extensive guides, API docs, and migration notes covering runtime context, middleware helpers (abort/defer), client-to-server handoff, and usage examples across frameworks.
  • Tests
    • New E2E tests and example pages demonstrating client/server runtime-context propagation and tooling.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

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_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds typed runtime context support (TContext) across TanStack AI's core APIs, framework integrations, tools, middleware, documentation, examples, and end-to-end tests. Runtime context is request-scoped typed application state passed to tool implementations and middleware via chat({ context }), framework hooks, or ChatClient constructors—distinct from prompt context and AG-UI context, and never sent to the model.

Changes

Typed Runtime Context Feature

Layer / File(s) Summary
Core API type documentation and chat() context option
docs/api/ai.md, docs/reference/functions/*
chat(options) adds typed context?: TContext parameter; Tool<TContext>, ChatMiddleware<TContext>, and ToolExecutionContext<TContext> become generic; chatParamsFromRequest return includes aguiContext field and marks context as deprecated alias.
Middleware and runtime context architecture
docs/advanced/middleware.md, docs/advanced/runtime-context.md, docs/config.json
New comprehensive "Runtime Context" guide covering type-safety merging, server/client patterns, and client-to-server handoff; middleware documentation updated to show typed ChatMiddleware<TContext> with ctx.context and defer() support; navigation config adds Runtime Context entry.
Framework hook context support
docs/api/ai-preact.md, docs/api/ai-react.md, docs/api/ai-solid.md, docs/api/ai-svelte.md, docs/api/ai-vue.md
useChat(options?) and framework-specific chat creators accept typed context?: TContext option; ChatClientOptions<TTools, TContext> generic signature added; Svelte's CreateChatReturn<TContext> includes new updateContext(context: TContext) method.
ChatClient constructor and documentation
docs/api/ai-client.md
ChatClient documentation removes onToolCall option, adds typed context? for client-local runtime context; examples updated to use clientTools(...) registration; createChatClientOptions clarifies typed context preservation and forwardedProps for server handoff.
Server and client tool documentation
docs/tools/server-tools.md, docs/tools/client-tools.md
Server tools show typed .server<AppContext>() pattern with ctx.context usage in example; client tools add "Client Runtime Context" section with forwardedProps vs local context guidance; lifecycle states updated with approval flow and complete state.
Migration and AG-UI compliance
docs/migration/migration-from-vercel-ai.md, docs/migration/ag-ui-compliance.md
Clarify mapping from Vercel experimental_context to TanStack chat({ context }); distinguish AG-UI RunAgentInput.context (now aguiContext) from runtime context; document explicit validation/mapping for client-to-server handoff.
Example app tool definitions and setup
examples/ts-react-chat/src/lib/guitar-tools.ts, examples/ts-react-chat/src/components/Header.tsx, examples/ts-react-chat/src/routeTree.gen.ts
Add runtimeLoyaltyTiers, runtimePreferredStyles enums and ClientRuntimeContext/ServerRuntimeContext types; define inspectClientRuntimeContextToolDef and inspectServerRuntimeContextToolDef tools; register new /example/runtime-context route in navigation and route tree.
Example API route and interactive page
examples/ts-react-chat/src/routes/api.tanchat.ts, examples/ts-react-chat/src/routes/example.runtime-context.tsx
API route constructs typed runtimeContext from forwardedProps with allowlisting and passes into chat(); runtimeContextMiddleware logs context on request start; interactive page renders runtime profile selection, Client/Server/Both prompts, tool results, and streamed messages with auto-scroll.
Code-mode and tool type refactors
examples/ts-code-mode-web/src/lib/execute-prompt.ts, examples/ts-code-mode-web/src/lib/structured-output.ts
Wrap tool execution result with Promise.resolve(); switch StructuredOutputOptions from Tool<any, any, any> to AnyTool type alias.
Issue-176 example tool updates
examples/ts-react-chat/src/routes/issue-176-tool-result.tsx
Add getGuitarsToolDef to live-tool registration via clientTools(...).
E2E test fixtures and tool definitions
testing/e2e/fixtures/tools-test/*, testing/e2e/src/lib/tools-test-tools.ts
Add fixture files for server-context, client-context, and client-server-context scenarios; define TestRuntimeContext type, read_server_context server tool, and read_client_context client tool; extend SCENARIO_LIST and getToolsForScenario().
E2E test routes and adapters
testing/e2e/src/routes/api.tools-test.ts, testing/e2e/src/routes/tools-test.tsx
Add runtimeContextAdapter() for deterministic synthetic tool-call generation; construct runtimeContext from forwardedProps with scenario-based defaults; test UI initializes scenario from route param and passes context to useChat().
E2E test helpers and Playwright suite
testing/e2e/tests/tools-test/helpers.ts, testing/e2e/tests/tools-test/runtime-context.spec.ts
Harden selectScenario() with early-return detection on metadata; strengthen runTest() with 5-attempt retry loop; add Playwright tests validating server context, client context, and forwarded-props-to-server scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • tombeckenham

Poem

🐰 I hopped through docs and tests so neat,

Typed context now travels where tools meet.
Client, server, middleware sing in tune,
Forwarded props land safe as the moon.
🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 49.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly summarizes the main feature being added: typed runtime context. It accurately reflects the primary change across the codebase.
Description check ✅ Passed The pull request description includes a comprehensive Summary section detailing the changes, a detailed Test Plan with specific commands, and notes about testing. It follows the expected structure and provides sufficient context.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/typed-runtime-context-pr

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: lockfile failed supply-chain policy check. Run pnpm install locally to update the lockfile.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@AlemTuzlak AlemTuzlak force-pushed the feat/typed-runtime-context-pr branch from 5b10d74 to fd36fac Compare May 22, 2026 16:46
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/typescript/ai/src/activities/chat/middleware/types.ts (1)

384-387: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Propagate TContext into onStructuredOutputConfig (and its runner)

packages/typescript/ai/src/activities/chat/middleware/types.ts still types onStructuredOutputConfig as ctx: ChatMiddlewareContext (non-generic), and packages/typescript/ai/src/activities/chat/middleware/compose.ts still types runOnStructuredOutputConfig as ctx: ChatMiddlewareContext, dropping the TContext parameter from ChatMiddleware<TContext> for this hook.

Update both signatures to use ChatMiddlewareContext<TContext> so the hook receives the correctly typed context.

🤖 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/middleware/types.ts` around lines
384 - 387, Update the generic context propagation for the structured-output
hook: change the type of onStructuredOutputConfig in the
ChatMiddleware<TContext> interface to accept ctx:
ChatMiddlewareContext<TContext> (not the non-generic ChatMiddlewareContext), and
likewise update the runner function runOnStructuredOutputConfig in compose (and
any helper/runner types it uses) to accept ctx: ChatMiddlewareContext<TContext>
so the TContext parameter is preserved and the hook receives the correctly typed
context.
🤖 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 `@examples/ts-react-chat/src/routes/api.tanchat.ts`:
- Around line 164-166: The console.log in the onStart middleware is emitting raw
PII (ctx.context.userId and ctx.context.tenantId); change the log to avoid raw
identifiers by applying a deterministic mask or hash instead (e.g., introduce a
helper like hashIdentifier(id: string) or redactIdentifier(id: string) and call
it for ctx.context.userId and ctx.context.tenantId before logging), or drop
those fields entirely and only log non-PII such as ctx.context.loyaltyTier;
update the console.log invocation in the onStart handler to use the new helper
or redacted values.

In `@examples/ts-react-chat/src/routes/example.runtime-context.tsx`:
- Around line 198-203: The ReactMarkdown instance in example.runtime-context.tsx
incorrectly places the remark plugin remarkGfm in the rehypePlugins list; move
remarkGfm into the remarkPlugins prop so it's applied by remark instead of
rehype (locate the ReactMarkdown component where rehypePlugins is defined and
change the plugin arrays accordingly, keeping rehypeRaw, rehypeSanitize,
rehypeHighlight in rehypePlugins and adding remarkGfm to remarkPlugins).

---

Outside diff comments:
In `@packages/typescript/ai/src/activities/chat/middleware/types.ts`:
- Around line 384-387: Update the generic context propagation for the
structured-output hook: change the type of onStructuredOutputConfig in the
ChatMiddleware<TContext> interface to accept ctx:
ChatMiddlewareContext<TContext> (not the non-generic ChatMiddlewareContext), and
likewise update the runner function runOnStructuredOutputConfig in compose (and
any helper/runner types it uses) to accept ctx: ChatMiddlewareContext<TContext>
so the TContext parameter is preserved and the hook receives the correctly typed
context.
🪄 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: 601a7093-ba6a-4a21-874d-32f0d2abde34

📥 Commits

Reviewing files that changed from the base of the PR and between e144a53 and 5b10d74.

📒 Files selected for processing (60)
  • docs/advanced/middleware.md
  • docs/advanced/runtime-context.md
  • docs/api/ai-client.md
  • docs/api/ai-preact.md
  • docs/api/ai-react.md
  • docs/api/ai-solid.md
  • docs/api/ai-svelte.md
  • docs/api/ai-vue.md
  • docs/api/ai.md
  • docs/config.json
  • docs/migration/ag-ui-compliance.md
  • docs/migration/migration-from-vercel-ai.md
  • docs/tools/client-tools.md
  • docs/tools/server-tools.md
  • examples/ts-code-mode-web/src/lib/execute-prompt.ts
  • examples/ts-code-mode-web/src/lib/structured-output.ts
  • examples/ts-react-chat/src/components/Header.tsx
  • examples/ts-react-chat/src/lib/guitar-tools.ts
  • examples/ts-react-chat/src/routeTree.gen.ts
  • examples/ts-react-chat/src/routes/api.tanchat.ts
  • examples/ts-react-chat/src/routes/example.runtime-context.tsx
  • packages/typescript/ai-client/src/chat-client.ts
  • packages/typescript/ai-client/src/index.ts
  • packages/typescript/ai-client/src/types.ts
  • packages/typescript/ai-client/tests/chat-client-context.test.ts
  • packages/typescript/ai-client/tests/tool-types.test.ts
  • packages/typescript/ai-code-mode/src/types.ts
  • packages/typescript/ai-code-mode/tests/create-code-mode-tool.test.ts
  • packages/typescript/ai-preact/src/types.ts
  • packages/typescript/ai-preact/src/use-chat.ts
  • packages/typescript/ai-react/src/types.ts
  • packages/typescript/ai-react/src/use-chat.ts
  • packages/typescript/ai-react/tests/use-chat-types.test.ts
  • packages/typescript/ai-solid/src/types.ts
  • packages/typescript/ai-solid/src/use-chat.ts
  • packages/typescript/ai-svelte/src/create-chat.svelte.ts
  • packages/typescript/ai-svelte/src/types.ts
  • packages/typescript/ai-svelte/tests/create-chat-types.test.ts
  • packages/typescript/ai-vue/src/types.ts
  • packages/typescript/ai-vue/src/use-chat.ts
  • packages/typescript/ai/src/activities/chat/index.ts
  • packages/typescript/ai/src/activities/chat/middleware/compose.ts
  • packages/typescript/ai/src/activities/chat/middleware/types.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-calls.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-definition.ts
  • packages/typescript/ai/src/types.ts
  • packages/typescript/ai/src/utilities/chat-params.ts
  • packages/typescript/ai/tests/middleware-context.test.ts
  • packages/typescript/ai/tests/tool-call-manager-context.test.ts
  • packages/typescript/ai/tests/tool-calls-context.test.ts
  • packages/typescript/ai/tests/tool-context.test.ts
  • packages/typescript/ai/tests/type-check.test.ts
  • testing/e2e/fixtures/tools-test/client-context.json
  • testing/e2e/fixtures/tools-test/client-server-context.json
  • testing/e2e/fixtures/tools-test/server-context.json
  • testing/e2e/src/lib/tools-test-tools.ts
  • testing/e2e/src/routes/api.tools-test.ts
  • testing/e2e/src/routes/tools-test.tsx
  • testing/e2e/tests/tools-test/helpers.ts
  • testing/e2e/tests/tools-test/runtime-context.spec.ts

Comment thread examples/ts-react-chat/src/routes/api.tanchat.ts
Comment thread examples/ts-react-chat/src/routes/example.runtime-context.tsx
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 22, 2026

View your CI Pipeline Execution ↗ for commit c182c9a

Command Status Duration Result
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-26 14:51:24 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 22, 2026

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/@tanstack/ai@628

@tanstack/ai-anthropic

npm i https://pkg.pr.new/@tanstack/ai-anthropic@628

@tanstack/ai-client

npm i https://pkg.pr.new/@tanstack/ai-client@628

@tanstack/ai-code-mode

npm i https://pkg.pr.new/@tanstack/ai-code-mode@628

@tanstack/ai-code-mode-skills

npm i https://pkg.pr.new/@tanstack/ai-code-mode-skills@628

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/@tanstack/ai-devtools-core@628

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@628

@tanstack/ai-event-client

npm i https://pkg.pr.new/@tanstack/ai-event-client@628

@tanstack/ai-fal

npm i https://pkg.pr.new/@tanstack/ai-fal@628

@tanstack/ai-gemini

npm i https://pkg.pr.new/@tanstack/ai-gemini@628

@tanstack/ai-grok

npm i https://pkg.pr.new/@tanstack/ai-grok@628

@tanstack/ai-groq

npm i https://pkg.pr.new/@tanstack/ai-groq@628

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@628

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/@tanstack/ai-isolate-node@628

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@628

@tanstack/ai-ollama

npm i https://pkg.pr.new/@tanstack/ai-ollama@628

@tanstack/ai-openai

npm i https://pkg.pr.new/@tanstack/ai-openai@628

@tanstack/ai-openrouter

npm i https://pkg.pr.new/@tanstack/ai-openrouter@628

@tanstack/ai-preact

npm i https://pkg.pr.new/@tanstack/ai-preact@628

@tanstack/ai-react

npm i https://pkg.pr.new/@tanstack/ai-react@628

@tanstack/ai-react-ui

npm i https://pkg.pr.new/@tanstack/ai-react-ui@628

@tanstack/ai-solid

npm i https://pkg.pr.new/@tanstack/ai-solid@628

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/@tanstack/ai-solid-ui@628

@tanstack/ai-svelte

npm i https://pkg.pr.new/@tanstack/ai-svelte@628

@tanstack/ai-utils

npm i https://pkg.pr.new/@tanstack/ai-utils@628

@tanstack/ai-vue

npm i https://pkg.pr.new/@tanstack/ai-vue@628

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/@tanstack/ai-vue-ui@628

@tanstack/openai-base

npm i https://pkg.pr.new/@tanstack/openai-base@628

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@628

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/@tanstack/react-ai-devtools@628

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@628

commit: c182c9a

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/typescript/ai/src/activities/chat/middleware/types.ts (1)

349-387: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

onStructuredOutputConfig still drops typed runtime context

ChatMiddleware<TContext> threads TContext through other hooks, but onStructuredOutputConfig keeps ctx: ChatMiddlewareContext (unknown context), so typed context is lost exactly in this phase.

Proposed fix
   onStructuredOutputConfig?: (
-    ctx: ChatMiddlewareContext,
+    ctx: ChatMiddlewareContext<TContext>,
     config: StructuredOutputMiddlewareConfig,
   ) =>
🤖 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/middleware/types.ts` around lines
349 - 387, The onStructuredOutputConfig hook currently types its context as
ChatMiddlewareContext (losing the generic TContext); update the signature on
ChatMiddleware<TContext> so onStructuredOutputConfig receives ctx:
ChatMiddlewareContext<TContext> (and keep the existing
StructuredOutputMiddlewareConfig type for the second parameter) so the generic
runtime context is preserved through this hook; locate the ChatMiddleware
interface and change the onStructuredOutputConfig parameter type accordingly
(referencing ChatMiddleware, onStructuredOutputConfig, ChatMiddlewareContext,
and StructuredOutputMiddlewareConfig).
🧹 Nitpick comments (1)
packages/typescript/ai/tests/middleware-context.test.ts (1)

47-47: ⚡ Quick win

Assert reference identity instead of deep equality.

Line 47 currently checks structural equality, so it won’t fail if middleware/tool receive cloned context objects. If the contract is “same runtime context instance,” assert identity with toBe.

Proposed change
-    expect(seen).toEqual([context, context])
+    expect(seen).toHaveLength(2)
+    expect(seen[0]).toBe(context)
+    expect(seen[1]).toBe(context)
🤖 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/tests/middleware-context.test.ts` at line 47, The test
currently uses structural equality (expect(seen).toEqual([context, context]))
which allows cloned objects to pass; change it to assert reference identity by
replacing that assertion with identity checks such as
expect(seen[0]).toBe(context) and expect(seen[1]).toBe(context) so both captured
entries are the exact same runtime context instance.
🤖 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 `@testing/e2e/tests/tools-test/helpers.ts`:
- Around line 94-107: The current page.evaluate in helpers.ts treats any
non-empty `#messages-json-content` as a started run and causes false positives
when fixtures are preloaded; update the check to compare the current messages
array length against the prior message count captured before clicking so we only
return true when a new run actually produced additional messages. Concretely: in
runTest() capture the preClickCount by parsing
document.getElementById('messages-json-content')?.textContent (default []), then
call page.evaluate with that preClickCount and inside the evaluated function
parse the messages once, return true if metadata.getAttribute('data-is-loading')
=== 'true' OR (Array.isArray(messages) && messages.length > preClickCount);
reference page.evaluate, '`#messages-json-content`', and the runTest() caller to
locate and implement this change.

---

Outside diff comments:
In `@packages/typescript/ai/src/activities/chat/middleware/types.ts`:
- Around line 349-387: The onStructuredOutputConfig hook currently types its
context as ChatMiddlewareContext (losing the generic TContext); update the
signature on ChatMiddleware<TContext> so onStructuredOutputConfig receives ctx:
ChatMiddlewareContext<TContext> (and keep the existing
StructuredOutputMiddlewareConfig type for the second parameter) so the generic
runtime context is preserved through this hook; locate the ChatMiddleware
interface and change the onStructuredOutputConfig parameter type accordingly
(referencing ChatMiddleware, onStructuredOutputConfig, ChatMiddlewareContext,
and StructuredOutputMiddlewareConfig).

---

Nitpick comments:
In `@packages/typescript/ai/tests/middleware-context.test.ts`:
- Line 47: The test currently uses structural equality
(expect(seen).toEqual([context, context])) which allows cloned objects to pass;
change it to assert reference identity by replacing that assertion with identity
checks such as expect(seen[0]).toBe(context) and expect(seen[1]).toBe(context)
so both captured entries are the exact same runtime context instance.
🪄 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: 6bb95160-469b-4912-9470-f4089a8b533b

📥 Commits

Reviewing files that changed from the base of the PR and between 5b10d74 and fd36fac.

📒 Files selected for processing (60)
  • docs/advanced/middleware.md
  • docs/advanced/runtime-context.md
  • docs/api/ai-client.md
  • docs/api/ai-preact.md
  • docs/api/ai-react.md
  • docs/api/ai-solid.md
  • docs/api/ai-svelte.md
  • docs/api/ai-vue.md
  • docs/api/ai.md
  • docs/config.json
  • docs/migration/ag-ui-compliance.md
  • docs/migration/migration-from-vercel-ai.md
  • docs/tools/client-tools.md
  • docs/tools/server-tools.md
  • examples/ts-code-mode-web/src/lib/execute-prompt.ts
  • examples/ts-code-mode-web/src/lib/structured-output.ts
  • examples/ts-react-chat/src/components/Header.tsx
  • examples/ts-react-chat/src/lib/guitar-tools.ts
  • examples/ts-react-chat/src/routeTree.gen.ts
  • examples/ts-react-chat/src/routes/api.tanchat.ts
  • examples/ts-react-chat/src/routes/example.runtime-context.tsx
  • packages/typescript/ai-client/src/chat-client.ts
  • packages/typescript/ai-client/src/index.ts
  • packages/typescript/ai-client/src/types.ts
  • packages/typescript/ai-client/tests/chat-client-context.test.ts
  • packages/typescript/ai-client/tests/tool-types.test.ts
  • packages/typescript/ai-code-mode/src/types.ts
  • packages/typescript/ai-code-mode/tests/create-code-mode-tool.test.ts
  • packages/typescript/ai-preact/src/types.ts
  • packages/typescript/ai-preact/src/use-chat.ts
  • packages/typescript/ai-react/src/types.ts
  • packages/typescript/ai-react/src/use-chat.ts
  • packages/typescript/ai-react/tests/use-chat-types.test.ts
  • packages/typescript/ai-solid/src/types.ts
  • packages/typescript/ai-solid/src/use-chat.ts
  • packages/typescript/ai-svelte/src/create-chat.svelte.ts
  • packages/typescript/ai-svelte/src/types.ts
  • packages/typescript/ai-svelte/tests/create-chat-types.test.ts
  • packages/typescript/ai-vue/src/types.ts
  • packages/typescript/ai-vue/src/use-chat.ts
  • packages/typescript/ai/src/activities/chat/index.ts
  • packages/typescript/ai/src/activities/chat/middleware/compose.ts
  • packages/typescript/ai/src/activities/chat/middleware/types.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-calls.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-definition.ts
  • packages/typescript/ai/src/types.ts
  • packages/typescript/ai/src/utilities/chat-params.ts
  • packages/typescript/ai/tests/middleware-context.test.ts
  • packages/typescript/ai/tests/tool-call-manager-context.test.ts
  • packages/typescript/ai/tests/tool-calls-context.test.ts
  • packages/typescript/ai/tests/tool-context.test.ts
  • packages/typescript/ai/tests/type-check.test.ts
  • testing/e2e/fixtures/tools-test/client-context.json
  • testing/e2e/fixtures/tools-test/client-server-context.json
  • testing/e2e/fixtures/tools-test/server-context.json
  • testing/e2e/src/lib/tools-test-tools.ts
  • testing/e2e/src/routes/api.tools-test.ts
  • testing/e2e/src/routes/tools-test.tsx
  • testing/e2e/tests/tools-test/helpers.ts
  • testing/e2e/tests/tools-test/runtime-context.spec.ts
✅ Files skipped from review due to trivial changes (14)
  • testing/e2e/fixtures/tools-test/client-server-context.json
  • docs/tools/server-tools.md
  • testing/e2e/tests/tools-test/runtime-context.spec.ts
  • docs/migration/ag-ui-compliance.md
  • packages/typescript/ai-code-mode/tests/create-code-mode-tool.test.ts
  • docs/api/ai-vue.md
  • docs/api/ai-react.md
  • docs/api/ai-solid.md
  • examples/ts-code-mode-web/src/lib/structured-output.ts
  • docs/migration/migration-from-vercel-ai.md
  • docs/advanced/middleware.md
  • docs/api/ai-preact.md
  • docs/tools/client-tools.md
  • examples/ts-react-chat/src/routeTree.gen.ts

Comment thread testing/e2e/tests/tools-test/helpers.ts Outdated
AlemTuzlak and others added 3 commits May 25, 2026 11:25
- propagate ChatMiddlewareContext<TContext> through compose, structured output, and stream processor
- thread TContext through tool registry, tool-call manager, code-mode bindings, and ai-client
- add type-level tests for typed client context in ai-solid, ai-svelte, ai-vue, ai-preact, and ai-code-mode
- mask user/tenant identifiers in ts-react-chat runtime-context middleware logging
- fix runTest helper false-positive when fixtures are pre-populated by baselining the message count
- update docs and runtime-context example for context typing changes
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/typescript/ai/src/activities/chat/tools/tool-calls.ts (2)

441-463: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Validate middleware skip results with the tool's outputSchema.

The skip branch pushes decision.result straight into results, so middleware short-circuits bypass the output validation/normalization that executeServerTool() and buildClientToolResult() now apply. A skipped tool can therefore return an invalid “successful” result.

🤖 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/tools/tool-calls.ts` around lines
441 - 463, The skip branch currently pushes decision.result directly and calls
middlewareHooks.onAfterToolCall, bypassing the tool output
validation/normalization; update the handling for decision.type === 'skip' to
run the skipResult through the same normalization/validation used by
executeServerTool()/buildClientToolResult() (apply the tool's outputSchema and
safeJsonParse as needed) and use that normalized value when pushing into results
and when invoking middlewareHooks.onAfterToolCall (keep
toolCallId/toolName/duration:0 and ok:true), so skipped results are validated
before being recorded or reported.

604-615: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix executeToolCalls typing/runtime contract for tool context + middleware skip validation

  • executeToolCalls<TContext> keeps userContext?: TContext and then casts it to ToolExecutionContext<TContext>, so executeToolCalls<MyContext>(...) can omit userContext even though ToolExecuteFunction requires context when undefined isn’t part of TContext (tool implementations will see context as required).
    🔧 Proposed fix
 export async function* executeToolCalls<TContext = unknown>(
   toolCalls: Array<ToolCall>,
   tools: ReadonlyArray<AnyTool>,
   approvals: Map<string, boolean> = new Map(),
   clientResults: Map<string, any> = new Map(),
   createCustomEventChunk?: (
     eventName: string,
     value: Record<string, any>,
   ) => CustomEvent,
   middlewareHooks?: ToolExecutionMiddlewareHooks,
-  userContext?: TContext,
+  ...contextArgs: undefined extends TContext
+    ? [userContext?: TContext]
+    : [userContext: TContext]
 ): AsyncGenerator<CustomEvent, ExecuteToolCallsResult, void> {
+  const userContext = contextArgs[0]
   const results: Array<ToolResult> = []
   const needsApproval: Array<ApprovalRequest> = []
   const needsClientExecution: Array<ClientToolRequest> = []
- `onBeforeToolCall` decisions of type `skip` push `skipResult` directly and call `onAfterToolCall` with `ok: true` without applying the tool’s `outputSchema` validation (server execution path validates `tool.outputSchema`), so middleware can cause invalid output to be treated as success.
🤖 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/api/ai-client.md`:
- Around line 362-364: The docs are inconsistent: the state union is documented
as "streaming" | "complete" | "error" but the addToolResult example still uses
"output-available"; update the addToolResult example to use one of the
documented states (e.g., replace "output-available" with "complete" or
"streaming" as appropriate) so the addToolResult example aligns with the state
union, and ensure any descriptive text around addToolResult references the same
state names.

---

Outside diff comments:
In `@packages/typescript/ai/src/activities/chat/tools/tool-calls.ts`:
- Around line 441-463: The skip branch currently pushes decision.result directly
and calls middlewareHooks.onAfterToolCall, bypassing the tool output
validation/normalization; update the handling for decision.type === 'skip' to
run the skipResult through the same normalization/validation used by
executeServerTool()/buildClientToolResult() (apply the tool's outputSchema and
safeJsonParse as needed) and use that normalized value when pushing into results
and when invoking middlewareHooks.onAfterToolCall (keep
toolCallId/toolName/duration:0 and ok:true), so skipped results are validated
before being recorded or reported.
🪄 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: 26354e21-c8ef-42ca-867c-021e7e823e0c

📥 Commits

Reviewing files that changed from the base of the PR and between fd36fac and a768b6a.

📒 Files selected for processing (45)
  • docs/advanced/runtime-context.md
  • docs/api/ai-client.md
  • docs/api/ai.md
  • docs/migration/ag-ui-compliance.md
  • docs/reference/functions/chatParamsFromRequest.md
  • docs/reference/functions/chatParamsFromRequestBody.md
  • docs/tools/client-tools.md
  • examples/ts-react-chat/src/routes/api.tanchat.ts
  • examples/ts-react-chat/src/routes/example.runtime-context.tsx
  • examples/ts-react-chat/src/routes/issue-176-tool-result.tsx
  • packages/typescript/ai-client/src/chat-client.ts
  • packages/typescript/ai-client/src/types.ts
  • packages/typescript/ai-client/tests/chat-client-context.test.ts
  • packages/typescript/ai-client/tests/tool-types.test.ts
  • packages/typescript/ai-code-mode-skills/src/code-mode-with-skills.ts
  • packages/typescript/ai-code-mode-skills/src/create-skill-management-tools.ts
  • packages/typescript/ai-code-mode-skills/src/skills-to-tools.ts
  • packages/typescript/ai-code-mode-skills/src/storage/file-storage.ts
  • packages/typescript/ai-code-mode-skills/src/storage/memory-storage.ts
  • packages/typescript/ai-code-mode/src/bindings/tool-to-binding.ts
  • packages/typescript/ai-code-mode/src/types.ts
  • packages/typescript/ai-code-mode/tests/code-mode-types.test.ts
  • packages/typescript/ai-code-mode/tests/create-code-mode-tool.test.ts
  • packages/typescript/ai-code-mode/tests/tool-to-binding.test.ts
  • packages/typescript/ai-preact/tests/use-chat-types.test.ts
  • packages/typescript/ai-solid/tests/use-chat-types.test.ts
  • packages/typescript/ai-svelte/tests/create-chat-types.test.ts
  • packages/typescript/ai-vue/tests/use-chat-types.test.ts
  • packages/typescript/ai/src/activities/chat/index.ts
  • packages/typescript/ai/src/activities/chat/middleware/compose.ts
  • packages/typescript/ai/src/activities/chat/middleware/types.ts
  • packages/typescript/ai/src/activities/chat/stream/processor.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-calls.ts
  • packages/typescript/ai/src/activities/chat/tools/tool-definition.ts
  • packages/typescript/ai/src/index.ts
  • packages/typescript/ai/src/tool-registry.ts
  • packages/typescript/ai/src/types.ts
  • packages/typescript/ai/src/utilities/chat-params.ts
  • packages/typescript/ai/tests/chat-params.test.ts
  • packages/typescript/ai/tests/chat.test.ts
  • packages/typescript/ai/tests/middleware-context.test.ts
  • packages/typescript/ai/tests/stream-processor.test.ts
  • packages/typescript/ai/tests/tool-call-manager.test.ts
  • packages/typescript/ai/tests/type-check.test.ts
  • testing/e2e/tests/tools-test/helpers.ts
✅ Files skipped from review due to trivial changes (6)
  • packages/typescript/ai-code-mode-skills/src/storage/memory-storage.ts
  • packages/typescript/ai-code-mode-skills/src/storage/file-storage.ts
  • docs/tools/client-tools.md
  • docs/migration/ag-ui-compliance.md
  • docs/reference/functions/chatParamsFromRequest.md
  • docs/advanced/runtime-context.md

Comment thread docs/api/ai-client.md
Comment on lines +362 to +364
| "streaming"
| "complete"
| "error";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Align tool-result state docs with the addToolResult example.

Line 362 introduces "streaming" | "complete" | "error", but this page still demonstrates "output-available" in the addToolResult section, which is contradictory for readers. Please update one side so the documented state model is consistent end-to-end.

🤖 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/api/ai-client.md` around lines 362 - 364, The docs are inconsistent: the
state union is documented as "streaming" | "complete" | "error" but the
addToolResult example still uses "output-available"; update the addToolResult
example to use one of the documented states (e.g., replace "output-available"
with "complete" or "streaming" as appropriate) so the addToolResult example
aligns with the state union, and ensure any descriptive text around
addToolResult references the same state names.

…ntext-pr

# Conflicts:
#	docs/migration/ag-ui-compliance.md
#	docs/tools/client-tools.md
#	examples/ts-react-chat/src/routes/api.tanchat.ts
#	packages/ai-client/src/chat-client.ts
#	packages/ai-client/src/types.ts
#	packages/ai-client/tests/chat-client-context.test.ts
#	packages/ai-code-mode/tests/code-mode-types.test.ts
#	packages/ai-preact/src/types.ts
#	packages/ai-preact/src/use-chat.ts
#	packages/ai-preact/tests/use-chat-types.test.ts
#	packages/ai-react/src/types.ts
#	packages/ai-react/src/use-chat.ts
#	packages/ai-solid/src/types.ts
#	packages/ai-solid/src/use-chat.ts
#	packages/ai-svelte/src/create-chat.svelte.ts
#	packages/ai-svelte/src/types.ts
#	packages/ai-vue/src/types.ts
#	packages/ai-vue/src/use-chat.ts
#	packages/ai/tests/middleware-context.test.ts
#	packages/ai/tests/tool-call-manager-context.test.ts
#	packages/ai/tests/tool-calls-context.test.ts
#	packages/ai/tests/tool-context.test.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
examples/ts-react-chat/src/routes/api.tanchat.ts (1)

258-313: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Provider-specific model defaults are currently unreachable.

model is pre-filled before adapter selection, so each (model || '...') always resolves to model. This makes per-provider defaults ineffective and can send an incompatible default to non-OpenAI adapters.

🔧 Suggested fix
-        const model: string =
-          typeof params.forwardedProps.model === 'string'
-            ? params.forwardedProps.model
-            : 'gpt-4o'
+        const forwardedModel =
+          typeof params.forwardedProps.model === 'string' &&
+          params.forwardedProps.model.trim() !== ''
+            ? params.forwardedProps.model
+            : undefined
...
-              adapter: anthropicText(
-                (model || 'claude-sonnet-4-6') as 'claude-sonnet-4-6',
-              ),
+              adapter: anthropicText(
+                (forwardedModel ?? 'claude-sonnet-4-6') as 'claude-sonnet-4-6',
+              ),
...
-              adapter: geminiText(
-                (model || 'gemini-3.1-pro-preview') as 'gemini-3.1-pro-preview',
-              ),
+              adapter: geminiText(
+                (forwardedModel ??
+                  'gemini-3.1-pro-preview') as 'gemini-3.1-pro-preview',
+              ),
...
-              adapter: geminiTextInteractions(
-                (model || 'gemini-3.1-pro-preview') as 'gemini-3.1-pro-preview',
-              ),
+              adapter: geminiTextInteractions(
+                (forwardedModel ??
+                  'gemini-3.1-pro-preview') as 'gemini-3.1-pro-preview',
+              ),
...
-              adapter: grokText((model || 'grok-4.20') as 'grok-4.20'),
+              adapter: grokText((forwardedModel ?? 'grok-4.20') as 'grok-4.20'),
...
-              adapter: groqText(
-                (model || 'openai/gpt-oss-120b') as 'openai/gpt-oss-120b',
-              ),
+              adapter: groqText(
+                (forwardedModel ??
+                  'openai/gpt-oss-120b') as 'openai/gpt-oss-120b',
+              ),
...
-              adapter: ollamaText((model || 'gpt-oss:20b') as 'gpt-oss:20b'),
+              adapter: ollamaText(
+                (forwardedModel ?? 'gpt-oss:20b') as 'gpt-oss:20b',
+              ),
...
-              adapter: openaiText((model || 'gpt-5.2') as 'gpt-5.2'),
+              adapter: openaiText((forwardedModel ?? 'gpt-5.2') as 'gpt-5.2'),
🤖 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 `@examples/ts-react-chat/src/routes/api.tanchat.ts` around lines 258 - 313, The
per-provider default model strings are never used because the code checks (model
|| '...') where model is pre-filled; change the logic so each branch computes a
providerDefault and uses (model ?? providerDefault) (or equivalent) when calling
adapters in createChatOptions; update branches that call openRouterText,
geminiText, geminiTextInteractions, grokText, groqText, ollamaText, openaiText,
etc., to pass model ?? '<provider-default>' instead of (model ||
'<provider-default>') so provider-specific defaults are applied only when model
is undefined/null.
🤖 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.

Outside diff comments:
In `@examples/ts-react-chat/src/routes/api.tanchat.ts`:
- Around line 258-313: The per-provider default model strings are never used
because the code checks (model || '...') where model is pre-filled; change the
logic so each branch computes a providerDefault and uses (model ??
providerDefault) (or equivalent) when calling adapters in createChatOptions;
update branches that call openRouterText, geminiText, geminiTextInteractions,
grokText, groqText, ollamaText, openaiText, etc., to pass model ??
'<provider-default>' instead of (model || '<provider-default>') so
provider-specific defaults are applied only when model is undefined/null.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 13247677-3167-41a2-b998-f2e027007d3a

📥 Commits

Reviewing files that changed from the base of the PR and between a768b6a and 36ff4a0.

📒 Files selected for processing (10)
  • docs/advanced/middleware.md
  • docs/api/ai-vue.md
  • docs/config.json
  • docs/migration/ag-ui-compliance.md
  • docs/reference/functions/chatParamsFromRequest.md
  • docs/reference/functions/chatParamsFromRequestBody.md
  • docs/tools/client-tools.md
  • examples/ts-react-chat/src/components/Header.tsx
  • examples/ts-react-chat/src/routeTree.gen.ts
  • examples/ts-react-chat/src/routes/api.tanchat.ts
💤 Files with no reviewable changes (1)
  • docs/migration/ag-ui-compliance.md
✅ Files skipped from review due to trivial changes (4)
  • docs/reference/functions/chatParamsFromRequestBody.md
  • docs/reference/functions/chatParamsFromRequest.md
  • docs/tools/client-tools.md
  • examples/ts-react-chat/src/routeTree.gen.ts

Merge auto-resolution left duplicate EventType (value) and StreamChunk
(type) imports, causing Vite pre-transform to fail with "Crawling result
not available" and timing out the entire E2E suite.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
testing/e2e/src/routes/api.tools-test.ts (1)

174-175: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Validate aimockPort before passing it to the adapter.

On Line 175, Number(fp.aimockPort) can become NaN for invalid input and then flows into createTextAdapter(...). Please reject non-finite values with a 400 (or coerce to undefined) to avoid turning bad input into internal failures.

Suggested patch
-        const aimockPort: number | undefined =
-          fp.aimockPort != null ? Number(fp.aimockPort) : undefined
+        const parsedAimockPort =
+          fp.aimockPort != null ? Number(fp.aimockPort) : undefined
+        if (parsedAimockPort != null && !Number.isFinite(parsedAimockPort)) {
+          return new Response('Invalid aimockPort', { status: 400 })
+        }
+        const aimockPort: number | undefined = parsedAimockPort
🤖 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/src/routes/api.tools-test.ts` around lines 174 - 175, The
computed aimockPort variable can become NaN and then be passed into
createTextAdapter; validate it after parsing by using Number(fp.aimockPort) and
checking Number.isFinite(value) (or Number.isInteger/within port range) and if
invalid either set aimockPort = undefined before calling createTextAdapter or
immediately return a 400 response; update the code around the aimockPort
assignment and the call site to use the validated value (referencing the
aimockPort variable and the createTextAdapter(...) invocation) so bad input does
not flow into the adapter.
🤖 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.

Outside diff comments:
In `@testing/e2e/src/routes/api.tools-test.ts`:
- Around line 174-175: The computed aimockPort variable can become NaN and then
be passed into createTextAdapter; validate it after parsing by using
Number(fp.aimockPort) and checking Number.isFinite(value) (or
Number.isInteger/within port range) and if invalid either set aimockPort =
undefined before calling createTextAdapter or immediately return a 400 response;
update the code around the aimockPort assignment and the call site to use the
validated value (referencing the aimockPort variable and the
createTextAdapter(...) invocation) so bad input does not flow into the adapter.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2e55c43e-44ae-442a-9d3c-34aa986b2690

📥 Commits

Reviewing files that changed from the base of the PR and between 36ff4a0 and c182c9a.

📒 Files selected for processing (1)
  • testing/e2e/src/routes/api.tools-test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant