feat(code-mode): lazy tool support (progressive disclosure) #726
main fromrefs/pull/726/head·merged by AlemTuzlak View on GitHubSummary#
Adds lazy tool support (progressive disclosure) to Code Mode, plus a shared, optional lazyToolsConfig that also tunes chat()'s existing lazy-tool discovery. The goal is context savings: with a large tool catalog, you no longer pay for every tool's type stub + description in the execute_typescript system prompt on every turn.
Lazy behavior is triggered purely by marking a tool lazy: true — lazyToolsConfig is optional everywhere and only tunes how much of each lazy tool's description shows in the pre-discovery catalog.
How it works#
- Shared config:
LazyToolsConfig { includeDescription: 'none' | 'first-sentence' | 'full' }(default'none'), accepted by bothchat()andcreateCodeMode().'none'is byte-identical to today's chat catalog. - Code Mode: tools marked
lazy: trueare kept out of the system prompt's full documentation (type stubs omitted) and listed in a lightweight "Discoverable APIs" catalog. A newdiscover_toolscompanion tool returns each lazy tool's TypeScript signature on demand; the model then callsexternal_<name>(...)insideexecute_typescript. Lookups tolerate the optionalexternal_prefix so the model can pass the catalog name verbatim. - Documentation-only lazy: all tool bindings are always injected into the sandbox —
lazydefers only prompt documentation, not callability. This is stateless/serverless-safe.
API#
createCodeMode(config) now returns { tool, discoveryTool, tools, systemPrompt }:
tool(=execute_typescript) andsystemPromptare unchanged — fully backward compatible.toolsis the array to spread intochat({ tools });discoveryToolisnullwhen there are no lazy tools.
Testing#
- Unit tests across both packages (helpers,
LazyToolManagercatalog rendering, eager/lazy partition,discover_toolsincl. prefix tolerance +includeDescription, return shape).pnpm test:prgreen. - E2E: a wire-journal spec asserts the chat lazy discovery catalog renders per
includeDescription(none/first-sentence/full). - Docs (
docs/code-mode/lazy-tools.md), both agent skills, and a changeset updated in the same PR.
Follow-up#
There is currently no code-mode E2E harness in testing/e2e/ (no route/fixture exercising createCodeMode). A code-mode-specific lazy E2E (sequencing discover_tools → execute_typescript against a sandbox driver) would need net-new harness wiring disproportionate to this change; the partition/discovery logic is comprehensively unit-covered. Recommend tracking code-mode E2E harness wiring as a separate issue.
🤖 Generated with Claude Code
Summary by CodeRabbit#
New Features
- Lazy tool discovery: mark tools as
lazyto reduce initial prompts and surface them through a discoverable catalog, with on-demand signature/type retrieval - Shared
lazyToolsConfig(includeDescription:none,first-sentence,full) controls how much is shown before discovery in bothchat()and Code Mode - Code Mode: when lazy tools are present, it can provide a discovery companion and includes it in the returned tool set while keeping existing behavior intact
- Lazy tool discovery: mark tools as
Documentation
- Added guides and examples for configuring lazy tools and discovery catalog verbosity
Tests
- Added unit tests plus end-to-end/wire-format coverage for discovery, verbosity, and expected payloads
- 1
🚀 Changeset Version Preview#
3 package(s) bumped directly, 29 bumped as dependents.
🟥 Major bumps#
Package Version Reason @tanstack/ai-code-mode0.2.13 → 1.0.0 Changeset @tanstack/ai-angular0.1.9 → 1.0.0 Dependent @tanstack/ai-anthropic0.15.8 → 1.0.0 Dependent @tanstack/ai-code-mode-skills0.3.2 → 1.0.0 Dependent @tanstack/ai-elevenlabs0.2.27 → 1.0.0 Dependent @tanstack/ai-fal0.9.4 → 1.0.0 Dependent @tanstack/ai-gemini0.18.0 → 1.0.0 Dependent @tanstack/ai-grok0.14.2 → 1.0.0 Dependent @tanstack/ai-groq0.4.12 → 1.0.0 Dependent @tanstack/ai-isolate-node0.1.38 → 1.0.0 Dependent @tanstack/ai-isolate-quickjs0.1.38 → 1.0.0 Dependent @tanstack/ai-ollama0.8.8 → 1.0.0 Dependent @tanstack/ai-openai0.15.6 → 1.0.0 Dependent @tanstack/ai-openrouter0.15.1 → 1.0.0 Dependent @tanstack/ai-preact0.9.13 → 1.0.0 Dependent @tanstack/ai-react0.15.13 → 1.0.0 Dependent @tanstack/ai-react-ui0.8.10 → 1.0.0 Dependent @tanstack/ai-solid0.13.13 → 1.0.0 Dependent @tanstack/ai-solid-ui0.7.9 → 1.0.0 Dependent @tanstack/ai-svelte0.13.13 → 1.0.0 Dependent @tanstack/ai-vue0.13.13 → 1.0.0 Dependent @tanstack/openai-base0.9.2 → 1.0.0 Dependent 🟨 Minor bumps#
Package Version Reason @tanstack/ai0.35.0 → 0.36.0 Changeset 🟩 Patch bumps#
Package Version Reason @tanstack/ai-event-client0.6.6 → 0.6.7 Changeset @tanstack/ai-client0.18.4 → 0.18.5 Dependent @tanstack/ai-devtools-core0.4.16 → 0.4.17 Dependent @tanstack/ai-isolate-cloudflare0.2.29 → 0.2.30 Dependent @tanstack/ai-mcp0.1.8 → 0.1.9 Dependent @tanstack/ai-vue-ui0.2.25 → 0.2.26 Dependent @tanstack/preact-ai-devtools0.1.59 → 0.1.60 Dependent @tanstack/react-ai-devtools0.2.59 → 0.2.60 Dependent @tanstack/solid-ai-devtools0.2.59 → 0.2.60 Dependent View your CI Pipeline Execution ↗ for commit cab200308c620e2d5060c47ef131a43f0f0a3011
Command Status Duration Result nx run-many --targets=build --exclude=examples/...✅ Succeeded 1m 23s View ↗
☁️ Nx Cloud last updated this comment at
2026-06-25 10:16:07UTC@tanstack/ai
npm i https://pkg.pr.new/@tanstack/ai@726@tanstack/ai-angular
npm i https://pkg.pr.new/@tanstack/ai-angular@726@tanstack/ai-anthropic
npm i https://pkg.pr.new/@tanstack/ai-anthropic@726@tanstack/ai-client
npm i https://pkg.pr.new/@tanstack/ai-client@726@tanstack/ai-code-mode
npm i https://pkg.pr.new/@tanstack/ai-code-mode@726@tanstack/ai-code-mode-skills
npm i https://pkg.pr.new/@tanstack/ai-code-mode-skills@726@tanstack/ai-devtools-core
npm i https://pkg.pr.new/@tanstack/ai-devtools-core@726@tanstack/ai-elevenlabs
npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@726@tanstack/ai-event-client
npm i https://pkg.pr.new/@tanstack/ai-event-client@726@tanstack/ai-fal
npm i https://pkg.pr.new/@tanstack/ai-fal@726@tanstack/ai-gemini
npm i https://pkg.pr.new/@tanstack/ai-gemini@726@tanstack/ai-grok
npm i https://pkg.pr.new/@tanstack/ai-grok@726@tanstack/ai-groq
npm i https://pkg.pr.new/@tanstack/ai-groq@726@tanstack/ai-isolate-cloudflare
npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@726@tanstack/ai-isolate-node
npm i https://pkg.pr.new/@tanstack/ai-isolate-node@726@tanstack/ai-isolate-quickjs
npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@726@tanstack/ai-mcp
npm i https://pkg.pr.new/@tanstack/ai-mcp@726@tanstack/ai-ollama
npm i https://pkg.pr.new/@tanstack/ai-ollama@726@tanstack/ai-openai
npm i https://pkg.pr.new/@tanstack/ai-openai@726@tanstack/ai-openrouter
npm i https://pkg.pr.new/@tanstack/ai-openrouter@726@tanstack/ai-preact
npm i https://pkg.pr.new/@tanstack/ai-preact@726@tanstack/ai-react
npm i https://pkg.pr.new/@tanstack/ai-react@726@tanstack/ai-react-ui
npm i https://pkg.pr.new/@tanstack/ai-react-ui@726@tanstack/ai-solid
npm i https://pkg.pr.new/@tanstack/ai-solid@726@tanstack/ai-solid-ui
npm i https://pkg.pr.new/@tanstack/ai-solid-ui@726@tanstack/ai-svelte
npm i https://pkg.pr.new/@tanstack/ai-svelte@726@tanstack/ai-utils
npm i https://pkg.pr.new/@tanstack/ai-utils@726@tanstack/ai-vue
npm i https://pkg.pr.new/@tanstack/ai-vue@726@tanstack/ai-vue-ui
npm i https://pkg.pr.new/@tanstack/ai-vue-ui@726@tanstack/openai-base
npm i https://pkg.pr.new/@tanstack/openai-base@726@tanstack/preact-ai-devtools
npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@726@tanstack/react-ai-devtools
npm i https://pkg.pr.new/@tanstack/react-ai-devtools@726@tanstack/solid-ai-devtools
npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@726commit:
cab2003Actionable comments posted: 4
🧹 Nitpick comments (4)
packages/ai/tests/lazy-tools.test.ts (1)
1-61: ⚡ Quick winCo-locate this unit test with the source module.
This test should live next to the lazy-tools implementation per repo guideline (for example under
packages/ai/src/activities/chat/tools/).As per coding guidelines,
**/*.test.ts: Place unit tests alongside source code in*.test.tsfiles.🤖 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/ai/tests/lazy-tools.test.ts` around lines 1 - 61, The tests for firstSentence and renderLazyCatalogEntry are currently in the shared tests folder and must be co-located with the lazy-tools source module; move the lazy-tools.test.ts file that contains tests referencing firstSentence and renderLazyCatalogEntry into the same directory as the lazy-tools implementation (next to the module that exports those functions), keep the filename ending in .test.ts, and update the import paths in the test to use the local module import so the tests run alongside the source per repo guidelines.Source: Coding guidelines
packages/ai-code-mode/skills/ai-code-mode/SKILL.md (1)
383-388: 💤 Low valueAdd language identifier to fenced code block.
Markdown linters require language identifiers on fenced code blocks. Since this is a flow/sequence diagram rather than executable code, consider using
textor remove the fence and use indentation.📝 Proposed fix
-``` +```text Model sees: "Discoverable APIs: external_fetchStocks" Model calls: discover_tools({ toolNames: ["fetchStocks"] }) Response: { tools: [{ name: "external_fetchStocks", description: "...", typeStub: "declare function external_fetchStocks(...)" }] } Model writes inside execute_typescript: const result = await external_fetchStocks({ ticker: "AAPL" })</details> <details> <summary>🤖 Prompt for AI Agents</summary>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/ai-code-mode/skills/ai-code-mode/SKILL.mdaround lines 383 - 388, The fenced code block containing the flow lines starting with "Model sees: "Discoverable APIs: external_fetchStocks"" in SKILL.md is missing a language identifier; update that triple-backtick fence to use a language tag (e.g.,linters accept it, ensuring the block that shows the discover_tools/execute_typescript sequence remains unchanged.Source: Linters/SAST tools
docs/code-mode/lazy-tools.md (2)
119-125: 💤 Low valueAdd language identifier to fenced code block.
The fenced code block showing example catalog output should specify a language identifier (e.g.,
text) to satisfy markdownlint.📝 Suggested fix
-``` +```text ### Discoverable APIs - external_fetchArchive - external_runReport - external_exportData</details> <details> <summary>🤖 Prompt for AI Agents</summary>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/code-mode/lazy-tools.mdaround lines 119 - 125, Add a language identifier to the fenced code block containing the "### Discoverable APIs" sample output so markdownlint passes; update the opening backticks to include a language liketext(e.g., change the block that lists "external_fetchArchive", "external_runReport", and "external_exportData" to start with ```text).</details> <!-- cr-comment:v1:8c8fdffc4537652ad3f97ae4 --> _Source: Linters/SAST tools_ --- `141-147`: _💤 Low value_ **Add language identifier to fenced code block.** The fenced code block showing example catalog output with descriptions should specify a language identifier (e.g., `text`) to satisfy markdownlint. <details> <summary>📝 Suggested fix</summary> ```diff -``` +```text ### Discoverable APIs - external_fetchArchive — Retrieve historical weather archive data for a date range. - external_runReport — Generate a summary report for a given time period. - external_exportData — Export query results to CSV or JSON format. ``` ``` </details> <details> <summary>🤖 Prompt for AI Agents</summary>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/code-mode/lazy-tools.mdaround lines 141 - 147, The fenced code block containing the "Discoverable APIs" section is missing a language identifier. Add the language identifiertextto the opening backticks of this code block (changetotext) to satisfy markdownlint requirements. This applies to the code block that lists the external functions like external_fetchArchive, external_runReport, and external_exportData.</details> <!-- cr-comment:v1:661e2d957bbb1a6bad28ead9 --> _Source: Linters/SAST tools_ </blockquote></details> </blockquote></details> <details> <summary>🤖 Prompt for all review comments with AI agents</summary>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/code-mode/lazy-tools.md:- Line 71: Update the docs examples to use the newer OpenAI model name: in the createCodeMode examples (identify the createCodeMode invocation and any openaiText(...) calls), replace openaiText("gpt-5.2") with openaiText("gpt-5.5"); ensure all occurrences in this file (including the instances around the createCodeMode block and the examples at the other noted locations) are changed so the documentation matches the NEWEST model names defined in OPENAI_CHAT_MODELS.
In
@packages/ai-code-mode/tests/create-discovery-tool.test.ts:- Line 1: Reorder the named imports from vitest so they are alphabetized to satisfy ESLint sort-imports: change the import list in the test file (the import statement that currently lists describe, it, expect) to list expect first, then describe, then it (i.e., import { expect, describe, it } from 'vitest'), preserving the same module and spacing.
In
@packages/ai/tests/lazy-tools.test.ts:- Line 1: The named imports from 'vitest' are out of alphabetical order and trigger sort-imports linting; update the import specifier in packages/ai/tests/lazy-tools.test.ts to list the members alphabetically (use describe, expect, it) so the import becomes alphabetically ordered and satisfies the linter.
In
@testing/e2e/tests/lazy-tools-wire.spec.ts:- Around line 63-67: Remove the global journal reset in the test.beforeEach hook
to avoid mutating shared state; specifically delete the await
request.delete(
http://127.0.0.1:${aimockPort}/v1/_requests) call inside test.beforeEach and rely on the existing per-test isolation header (X-Test-Id) instead, ensuring tests continue to set and use X-Test-Id when calling the aimock server; no other changes to request setup are required.
Nitpick comments: In
@docs/code-mode/lazy-tools.md:- Around line 119-125: Add a language identifier to the fenced code block
containing the "### Discoverable APIs" sample output so markdownlint passes;
update the opening backticks to include a language like
text(e.g., change the block that lists "external_fetchArchive", "external_runReport", and "external_exportData" to start with ```text). - Around line 141-147: The fenced code block containing the "Discoverable APIs"
section is missing a language identifier. Add the language identifier
textto the opening backticks of this code block (changetotext) to satisfy markdownlint requirements. This applies to the code block that lists the external functions like external_fetchArchive, external_runReport, and external_exportData.
In
@packages/ai-code-mode/skills/ai-code-mode/SKILL.md:- Around line 383-388: The fenced code block containing the flow lines starting with "Model sees: "Discoverable APIs: external_fetchStocks"" in SKILL.md is missing a language identifier; update that triple-backtick fence to use a language tag (e.g., ```text) or replace the fenced block with an indented code block so markdown linters accept it, ensuring the block that shows the discover_tools/execute_typescript sequence remains unchanged.
In
@packages/ai/tests/lazy-tools.test.ts:- Around line 1-61: The tests for firstSentence and renderLazyCatalogEntry are currently in the shared tests folder and must be co-located with the lazy-tools source module; move the lazy-tools.test.ts file that contains tests referencing firstSentence and renderLazyCatalogEntry into the same directory as the lazy-tools implementation (next to the module that exports those functions), keep the filename ending in .test.ts, and update the import paths in the test to use the local module import so the tests run alongside the source per repo guidelines.
</details> <details> <summary>🪄 Autofix (Beta)</summary> Fix all unresolved CodeRabbit comments on this PR: - [ ] <!-- {"checkboxId": "4b0d0e0a-96d7-4f10-b296-3a18ea78f0b9"} --> Push a commit to this branch (recommended) - [ ] <!-- {"checkboxId": "ff5b1114-7d8c-49e6-8ac1-43f82af23a33"} --> Create a new PR with the fixes </details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: defaults **Review profile**: CHILL **Plan**: Pro **Run ID**: `f340d8aa-df1b-43c4-a30b-4d8305872f91` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 22c9b42baec74914b720e440f29bd02be04eb164 and 20b8d2ab63e333a5cb7ac9f8ecfd65343be77630. </details> <details> <summary>📒 Files selected for processing (25)</summary> * `.changeset/code-mode-lazy-tools.md` * `docs/code-mode/lazy-tools.md` * `docs/config.json` * `packages/ai-code-mode/skills/ai-code-mode/SKILL.md` * `packages/ai-code-mode/src/create-code-mode-tool.ts` * `packages/ai-code-mode/src/create-code-mode.ts` * `packages/ai-code-mode/src/create-discovery-tool.ts` * `packages/ai-code-mode/src/create-system-prompt.ts` * `packages/ai-code-mode/src/index.ts` * `packages/ai-code-mode/src/types.ts` * `packages/ai-code-mode/tests/create-code-mode.test.ts` * `packages/ai-code-mode/tests/create-discovery-tool.test.ts` * `packages/ai-code-mode/tests/create-system-prompt.test.ts` * `packages/ai/skills/ai-core/tool-calling/SKILL.md` * `packages/ai/src/activities/chat/index.ts` * `packages/ai/src/activities/chat/tools/lazy-tool-manager.ts` * `packages/ai/src/activities/chat/tools/lazy-tools.ts` * `packages/ai/src/index.ts` * `packages/ai/src/types.ts` * `packages/ai/tests/lazy-tool-manager.test.ts` * `packages/ai/tests/lazy-tools.test.ts` * `testing/e2e/fixtures/lazy-tools-wire/basic.json` * `testing/e2e/src/routeTree.gen.ts` * `testing/e2e/src/routes/api.lazy-tools-wire.ts` * `testing/e2e/tests/lazy-tools-wire.spec.ts` </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->docs/code-mode/lazy-tools.md line 71Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +51,21 @@51+ const res = await fetch(52+ `https://api.weather.example/v1/archive?city=${location}&from=${from}&to=${to}`53+ );54+ return res.json();55+});56+```57+58+Eager tools continue to receive full type stubs in the system prompt. Lazy tools appear only by name.59+60+## Server Setup61+62+Pass both eager and lazy tools to `createCodeMode`. When at least one tool is lazy, `createCodeMode` also returns a `discover_tools` sibling tool — include it in the `tools` array you pass to `chat()`:63+64+```typescript65+// server/route.ts66+import { chat, maxIterations, toServerSentEventsStream } from "@tanstack/ai";67+import { createCodeMode } from "@tanstack/ai-code-mode";68+import { createNodeIsolateDriver } from "@tanstack/ai-isolate-node";69+import { openaiText } from "@tanstack/ai-openai";70+71+const { tools, systemPrompt } = createCodeMode({⚠️ Potential issue | 🟡 Minor
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash # Verify the latest OpenAI text model in model-meta.ts # Find and display OpenAI model metadata fd -t f 'model-meta.ts' packages | rg -i openai | xargs cat | rg -A 10 -B 2 'export.*openaiText|text.*models'Repository: TanStack/ai
Length of output: 393
🏁 Script executed:
#!/bin/bash set -euo pipefail # Locate OpenAI adapter model-meta.ts files="$(fd -t f 'model-meta.ts' packages | rg -i 'openai')" echo "OpenAI model-meta.ts files:" echo "$files" # Show the openaiText export section(s) echo "---- openaiText export contexts ----" printf "%s\n" "$files" | while read -r f; do echo "== $f ==" rg -n "openaiText" "$f" || true # show a bit of surrounding text for each match rg -n "openaiText" "$f" | cut -d: -f1 | sort -u | while read -r line; do sed -n "$((line-10)),$((line+20))p" "$f" done done # List all GPT_* constants with names in the OpenAI model-meta.ts (likely text models too) echo "---- GPT_* name constants ----" printf "%s\n" "$files" | while read -r f; do echo "== $f ==" rg -n "name: 'gpt-" "$f" || true done # Specifically check whether gpt-5.2 is present echo "---- presence of gpt-5.2 ----" printf "%s\n" "$files" | while read -r f; do echo "== $f ==" rg -n "gpt-5\.2" "$f" || true doneRepository: TanStack/ai
Length of output: 200
🏁 Script executed:
#!/bin/bash set -u f="packages/ai-openai/src/model-meta.ts" echo "== File: $f ==" wc -l "$f" echo echo "---- Matching: openaiText / text helpers ----" rg -n "openaiText|Text\\(" "$f" || true echo echo "---- Matching: exported text model(s) ----" rg -n "export (const|type|function).*(openai|text)" "$f" || true echo echo "---- Matching: gpt-* model name constants ----" rg -n "name: 'gpt-" "$f" || true echo echo "---- Matching: gpt-* references (non-name) ----" rg -n "gpt-[0-9]" "$f" || true echo echo "---- Tail exports section ----" tail -n 120 "$f"Repository: TanStack/ai
Length of output: 8754
🏁 Script executed:
#!/bin/bash set -euo pipefail # 1) Inspect the doc lines referenced in the review comment sed -n '1,240p' docs/code-mode/lazy-tools.md | nl -ba | sed -n '50,220p' # 2) Find where `openaiText` is defined and what it expects echo "---- Searching for openaiText definition/usages ----" rg -n "openaiText" packages docs || true # 3) Inspect ai-openai adapter for openaiText mapping to model names # (limit output by narrowing to model-meta and adapter entrypoints) echo "---- Searching model-meta for text completion models ----" rg -n "text completion|text-only models|endpoints: \\[\"chat\\\"|chat-completions|completions|openaiText" packages/ai-openai/src/model-meta.ts || true echo "---- Show around GPT_5_4_MINI definition ----" rg -n "GPT_5_4_MINI" packages/ai-openai/src/model-meta.tsRepository: TanStack/ai
Length of output: 98
🏁 Script executed:
#!/bin/bash set -euo pipefail # 1) Inspect docs/code-mode/lazy-tools.md around the referenced lines echo "---- lazy-tools.md (lines 60-110) ----" sed -n '60,110p' docs/code-mode/lazy-tools.md | cat -n echo "---- lazy-tools.md (lines 150-200) ----" sed -n '150,200p' docs/code-mode/lazy-tools.md | cat -n # 2) Search for openaiText usages/definition echo "---- rg: openaiText in packages+docs ----" rg -n "openaiText" packages docs || true # 3) Inspect ai-openai model-meta.ts around GPT_* text-only / chat models echo "---- rg: text-only / completion hints in model-meta.ts ----" rg -n "Text\\b|text-only|text completion|endpoints: \\['chat'|chat-completions|chat-completions|chat\\b" packages/ai-openai/src/model-meta.ts | head -n 80 # 4) Show exact block(s) for GPT_5_2 and GPT_5_4_* to compare endpoints/supports echo "---- GPT_5_2 block context ----" rg -n "GPT_5_2\\b" packages/ai-openai/src/model-meta.ts echo "---- GPT_5_4_MINI block context ----" rg -n "GPT_5_4_MINI\\b" packages/ai-openai/src/model-meta.ts echo "---- GPT_5_5 block context ----" rg -n "GPT_5_5\\b" packages/ai-openai/src/model-meta.ts # Print around those constants for sym in GPT_5_2 GPT_5_4_MINI GPT_5_5 GPT_CHAT_LATEST GPT_5_4_NANO; do line="$(rg -n "${sym}\\b" packages/ai-openai/src/model-meta.ts | head -n1 | cut -d: -f1 || true)" if [ -n "${line:-}" ]; then echo "---- $sym around line $line ----" start=$((line-20)); end=$((line+40)) sed -n "${start},${end}p" packages/ai-openai/src/model-meta.ts fi doneRepository: TanStack/ai
Length of output: 50369
🏁 Script executed:
#!/bin/bash set -euo pipefail f="packages/ai-openai/src/model-meta.ts" echo "== openai model-meta.ts key model blocks ==" # show around gpt-5.2, gpt-5.4-mini, gpt-5.5, gpt-5.5-pro, and gpt-chat-latest for pat in "GPT_5_2" "GPT_5_4_MINI" "GPT_5_5" "GPT_5_5_PRO" "GPT_CHAT_LATEST"; do line="$(rg -n "${pat}\b" "$f" | head -n1 | cut -d: -f1 || true)" echo echo "---- $pat ----" if [ -n "$line" ]; then start=$((line-25)); end=$((line+80)) sed -n "${start},${end}p" "$f" else echo "not found: $pat" fi done echo echo "== show openaiText adapter model type list ==" tf="packages/ai-openai/src/adapters/text.ts" wc -l "$tf" rg -n "OPENAI_CHAT_MODELS|OPENAI_TEXT_MODELS|gpt-5\.5|gpt-5\.2" "$tf" || true # print the definition area for the model list rg -n "OPENAI_CHAT_MODELS|OPENAI.*MODELS" "$tf" | head -n 20 # show around the first match first_line="$(rg -n "OPENAI_CHAT_MODELS|OPENAI.*MODELS" "$tf" | head -n1 | cut -d: -f1 || true)" if [ -n "$first_line" ]; then start=$((first_line-40)); end=$((first_line+120)) sed -n "${start},${end}p" "$tf" fiRepository: TanStack/ai
Length of output: 10648
🏁 Script executed:
#!/bin/bash set -euo pipefail # Show exact constant block for GPT5_2 and GPT5_5[_PRO] f="packages/ai-openai/src/model-meta.ts" for sym in GPT5_2 GPT5_2_PRO GPT5_2_CHAT GPT5_4_MINI GPT5_5 GPT5_5_PRO GPT_CHAT_LATEST; do echo echo "==== $sym ====" line="$(rg -n "${sym}\b" "$f" | head -n1 | cut -d: -f1 || true)" if [ -z "${line:-}" ]; then echo "not found" continue fi start=$((line-25)); end=$((line+70)) sed -n "${start},${end}p" "$f" | head -n 120 done # Find any default / "latest" model exports in model-meta.ts echo echo "==== potential default/latest exports (model-meta.ts) ====" rg -n "DEFAULT|LATEST|latest model|defaultModel" "$f" || true # Inspect openaiText adapter default model selection in adapters/text.ts tf="packages/ai-openai/src/adapters/text.ts" echo echo "==== openaiText default model selection (adapters/text.ts) ====" rg -n "default|DEFAULT|latest|GPT5_|gpt-5\.5|gpt-5\.2" "$tf" | head -n 200 # Specifically locate openaiText signature (to see param defaults) echo echo "==== openaiText() signature section (adapters/text.ts) ====" sed -n '150,270p' "$tf" | cat -nRepository: TanStack/ai
Length of output: 8437
🏁 Script executed:
#!/bin/bash set -euo pipefail f="packages/ai-openai/src/model-meta.ts" echo "---- Check OPENAI_CHAT_MODELS includes gpt-5.5 / gpt-5.4-mini ----" rg -n "OPENAI_CHAT_MODELS|gpt-5\.5|gpt-5\.4-mini|gpt-5\.5-pro|gpt-chat-latest" "$f" || true echo echo "---- Show OPENAI_CHAT_MODELS array (full) ----" # Extract the array block only to avoid huge output python3 - <<'PY' import re, pathlib p=pathlib.Path("packages/ai-openai/src/model-meta.ts") s=p.read_text(encoding="utf-8") m=re.search(r"export const OPENAI_CHAT_MODELS\s*=\s*\[\s*(.*?)\s*\]\s*as const", s, flags=re.S) if not m: # fallback without as const m=re.search(r"export const OPENAI_CHAT_MODELS\s*=\s*\[\s*(.*?)\s*\]", s, flags=re.S) print(m.group(0)[:5000] if m else "OPENAI_CHAT_MODELS block not found") PY echo echo "---- Check gpt-5.2 in OPENAI_CHAT_MODELS ----" rg -n "gpt-5\.2" "$f" | head -n 20Repository: TanStack/ai
Length of output: 1639
Update OpenAI model in docs to newest option from
model-meta.ts(usegpt-5.5)The examples in
docs/code-mode/lazy-tools.mduseopenaiText("gpt-5.2"), butpackages/ai-openai/src/model-meta.tsincludes newer GPT models such asgpt-5.5(andgpt-5.5-pro) inOPENAI_CHAT_MODELS. Update the documentation examples to use the latest (e.g.,openaiText("gpt-5.5")).const { tools, systemPrompt } = createCodeMode({Also applies to: 83-83, 167-167
🤖 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/code-mode/lazy-tools.md` at line 71, Update the docs examples to use the newer OpenAI model name: in the createCodeMode examples (identify the createCodeMode invocation and any openaiText(...) calls), replace openaiText("gpt-5.2") with openaiText("gpt-5.5"); ensure all occurrences in this file (including the instances around the createCodeMode block and the examples at the other noted locations) are changed so the documentation matches the NEWEST model names defined in OPENAI_CHAT_MODELS.Source: Coding guidelines
✅ Addressed in commit bab6ada
packages/ai-code-mode/tests/create-discovery-tool.test.ts line 1OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1 @@1+import { describe, it, expect } from 'vitest'⚠️ Potential issue | 🟡 Minor | ⚡ Quick win
Fix import ordering to comply with ESLint sort-imports.
The
expectimport should be sorted beforedescribeanditalphabetically.📝 Proposed fix
-import { describe, it, expect } from 'vitest' +import { describe, expect, it } from 'vitest'📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change1-import { describe, it, expect } from 'vitest'1+import { describe, expect, it } from 'vitest'🧰 Tools
🪛 ESLint
[error] 1-1: Member 'expect' of the import declaration should be sorted alphabetically.
(sort-imports)
🤖 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/ai-code-mode/tests/create-discovery-tool.test.ts` at line 1, Reorder the named imports from vitest so they are alphabetized to satisfy ESLint sort-imports: change the import list in the test file (the import statement that currently lists describe, it, expect) to list expect first, then describe, then it (i.e., import { expect, describe, it } from 'vitest'), preserving the same module and spacing.Source: Linters/SAST tools
✅ Addressed in commit bab6ada
packages/ai/tests/lazy-tools.test.ts line 1OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1 @@1+import { describe, it, expect } from 'vitest'⚠️ Potential issue | 🟠 Major | ⚡ Quick win
Fix the named import order to clear lint.
sort-importsflags the member order in the Vitest import and can fail CI.Suggested fix
-import { describe, it, expect } from 'vitest' +import { describe, expect, it } from 'vitest'📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change1-import { describe, it, expect } from 'vitest'1+import { describe, expect, it } from 'vitest'🧰 Tools
🪛 ESLint
[error] 1-1: Member 'expect' of the import declaration should be sorted alphabetically.
(sort-imports)
🤖 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/ai/tests/lazy-tools.test.ts` at line 1, The named imports from 'vitest' are out of alphabetical order and trigger sort-imports linting; update the import specifier in packages/ai/tests/lazy-tools.test.ts to list the members alphabetically (use describe, expect, it) so the import becomes alphabetically ordered and satisfies the linter.Source: Linters/SAST tools
✅ Addressed in commit bab6ada
testing/e2e/tests/lazy-tools-wire.spec.ts lines 63 to 67OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +47,21 @@47+ `http://127.0.0.1:${aimockPort}/v1/_requests`,48+ )49+ const entries = (await journalRes.json()) as Array<JournalEntry>50+ for (const entry of entries) {51+ if (entry.headers?.['x-test-id'] !== testId) continue52+ const discovery = entry.body?.tools?.find(53+ (t) => t.function?.name === DISCOVERY_TOOL_NAME,54+ )55+ if (discovery?.function?.description) {56+ return discovery.function.description57+ }58+ }59+ return undefined60+}61+62+test.describe('lazy tools — discovery catalog wire format', () => {63+ test.beforeEach(async ({ request, aimockPort }) => {64+ // Clear the aimock journal so we only assert against this test's requests —65+ // adjacent specs share the same aimock instance.66+ await request.delete(`http://127.0.0.1:${aimockPort}/v1/_requests`)67+ })⚠️ Potential issue | 🟠 Major | ⚡ Quick win
Avoid deleting the shared aimock journal in
beforeEach.DELETE /v1/_requestsmutates global shared state and can race with other parallel specs using the same aimock instance. You already isolate byX-Test-Id, so this reset is unnecessary and can cause flaky failures.Suggested change
test.describe('lazy tools — discovery catalog wire format', () => { - test.beforeEach(async ({ request, aimockPort }) => { - // Clear the aimock journal so we only assert against this test's requests — - // adjacent specs share the same aimock instance. - await request.delete(`http://127.0.0.1:${aimockPort}/v1/_requests`) - }) - test("includeDescription: 'none' sends bare lazy tool names (legacy default)", async ({📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change63- test.beforeEach(async ({ request, aimockPort }) => {64- // Clear the aimock journal so we only assert against this test's requests —65- // adjacent specs share the same aimock instance.66- await request.delete(`http://127.0.0.1:${aimockPort}/v1/_requests`)67- })63+🤖 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/lazy-tools-wire.spec.ts` around lines 63 - 67, Remove the global journal reset in the test.beforeEach hook to avoid mutating shared state; specifically delete the await request.delete(`http://127.0.0.1:${aimockPort}/v1/_requests`) call inside test.beforeEach and rely on the existing per-test isolation header (X-Test-Id) instead, ensuring tests continue to set and use X-Test-Id when calling the aimock server; no other changes to request setup are required.✅ Addressed in commit bab6ada
tombeckenham assignedtombeckenham
tombeckenham approved these changes
This is good to go after rebasing
AlemTuzlak merged thisfbd3762
AlemTuzlak closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
231a1c82-3311-4902-82a6-b724c8a4ebfa📥 Commits
Reviewing files that changed from the base of the PR and between bab6ada9c4332c9670ecbae92ba87f9a3ccb29ed and cab200308c620e2d5060c47ef131a43f0f0a3011.
📒 Files selected for processing (3)
docs/code-mode/lazy-tools.mddocs/config.jsondocs/tools/lazy-tool-discovery.md✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 Walkthrough
Walkthrough#
Adds lazy-tool progressive disclosure for Code Mode and chat: lazy tools are omitted from initial eager stubs, exposed through a discoverable catalog with configurable description detail, and fetched on demand through
discover_tools. Tests, e2e coverage, docs, and skill guides were updated.Changes#
Lazy Tools Progressive Disclosure
packages/ai/src/types.ts,packages/ai/src/activities/chat/tools/lazy-tools.ts,packages/ai/src/index.ts,packages/ai/tests/lazy-tools.test.tsLazyToolsConfig, addsfirstSentenceandrenderLazyCatalogEntry, re-exports the helpers, and verifies catalog formatting behavior.packages/ai/src/activities/chat/index.ts,packages/ai/src/activities/chat/tools/lazy-tool-manager.ts,packages/ai/tests/lazy-tool-manager.test.tslazyToolsConfigto chat activity options, passes it intoLazyToolManager, and changes discovery-tool description rendering to use the configurable lazy catalog format.packages/ai-code-mode/src/types.ts,packages/ai-code-mode/src/create-discovery-tool.ts,packages/ai-code-mode/src/index.ts,packages/ai-code-mode/tests/create-discovery-tool.test.tscreateDiscoveryToolwith schemas and name normalization, re-exports it, and validates discovery and error handling.packages/ai-code-mode/src/create-code-mode.ts,packages/ai-code-mode/src/create-code-mode-tool.ts,packages/ai-code-mode/src/create-system-prompt.ts,packages/ai-code-mode/tests/create-code-mode.test.ts,packages/ai-code-mode/tests/create-system-prompt.test.ts,.changeset/code-mode-lazy-tools.mdcreateCodeModeto return discovery metadata, filters lazy tools out of eager prompt stubs, adds a discoverable section to the system prompt, and covers the new return shape in tests.testing/e2e/src/routes/api.lazy-tools-wire.ts,testing/e2e/src/routeTree.gen.ts,testing/e2e/src/routes/api.lazy-tools-wire.ts,testing/e2e/fixtures/lazy-tools-wire/basic.json,testing/e2e/tests/lazy-tools-wire.spec.tsnone,first-sentence, andfulldiscovery-catalog descriptions.docs/code-mode/lazy-tools.md,docs/tools/lazy-tool-discovery.md,docs/config.json,packages/ai-code-mode/skills/ai-code-mode/SKILL.md,packages/ai/skills/ai-core/tool-calling/SKILL.mdSequence Diagram(s)#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs#
packages/ai/src/activities/chat/tools/lazy-tool-manager.ts.Suggested reviewers#
Poem#
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
✨ 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