Repository navigation
feat(extension): shared tool definitions keep literal names, declared errors reach the typed client - #251
Conversation
Tools declared through a shared def const widened `name` to `string`, so `ToolNameOf` mapped them to `never`: they vanished from the typed client and from the prefix/duplicate/empty-segment/forbidden-segment diagnostics. `toolDefinition()` is an identity helper whose generic `Name extends string` parameter keeps the literal, and every shared def across the tanstack, whiteboard, test-runner and recorder extensions now goes through it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…lient The derived router gave every procedure an empty oRPC error map, so isDefinedError narrowed to never on the typed client and a tool's declared errors were invisible at the call site. defineTool's builder now carries the declared error shape and its binding as generics; the registry projects them into the procedure's error-map slot, merging the transport errors for client-bound tools exactly where compileTool merges them at runtime. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The changeset violates the repository’s prohibition on em dashes.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
Preserves shared tool-name literals and projects declared tool errors onto typed clients.
Changes:
- Adds
toolDefinition()and migrates 38 shared definitions. - Carries tool bindings and error maps through registry types.
- Adds type-level coverage for names, collisions, and error narrowing.
File summaries
| File | Description |
|---|---|
.changeset/eager-tools-narrow.md |
Documents the extension API improvements. |
packages/extension/src/define-extension.ts |
Expands builder generics. |
packages/extension/src/define-tool.ts |
Adds the helper and error propagation. |
packages/extension/src/index.ts |
Exports toolDefinition. |
packages/extension/src/tool-registry.ts |
Projects runtime error maps into client types. |
packages/extension/test/extension-registry.test-d.ts |
Tests literal names and error narrowing. |
packages/extensions/recorder/src/tool/def.ts |
Preserves recorder tool names. |
packages/extensions/tanstack/src/tool/def.ts |
Preserves TanStack tool names. |
packages/extensions/test-runner/src/tool/def.ts |
Preserves test-runner tool names. |
packages/extensions/whiteboard/src/tool/anchor/def.ts |
Preserves anchor tool names. |
packages/extensions/whiteboard/src/tool/canvas/def.ts |
Preserves canvas tool names. |
packages/extensions/whiteboard/src/tool/comment/def.ts |
Preserves comment tool names. |
packages/extensions/whiteboard/src/tool/element/def.ts |
Preserves element tool names. |
Review details
- Files reviewed: 13/13 changed files
- Comments generated: 1
- Review effort level: Balanced
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Ready to approve
The type propagation matches runtime error behavior and is covered by focused, non-vacuous type assertions.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
- Files reviewed: 13/13 changed files
- Comments generated: 0 new
- Review effort level: Balanced
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
A renderer-only builder carries no binding, and its separately compiled runtime twin may be client-bound, so guessing 'server' hid the transport codes the forwarding layer can really raise. The projected binding gains an explicit 'unknown' case and the registry merges the transport errors for anything that is not provably server-bound, leaving a .server()-bound tool with its declared errors alone. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The collision test does not exercise the required shared-definition versus inline-definition case.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (1)
packages/extension/test/extension-registry.test-d.ts:123
- Both
treblerandtreblerTwinusetoolDefinition, so the collision assertions only cover shared-definition versus shared-definition collisions. The linked acceptance criterion specifically requires a shared-definition tool to collide with an inline declaration; make this twin inline so that regression is exercised.
const treblerTwinDef = toolDefinition({
- Files reviewed: 13/13 changed files
- Comments generated: 0 new
- Review effort level: Balanced
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Closes #248, closes #249. Both split out of #238 (PR #247).
#248 —
toolDefinition()inference siteTools declared through a shared def const (
export const fooDef = {name: 'foo', ...}— the pattern tanstack, whiteboard, recorder and test-runner use so client and server share one definition) widenednametostring, soToolNameOfmapped them tonever: absent from the typed registry client and invisible to #247's collision diagnostics.toolDefinition()is an 8-line identity helper whoseconst Namegeneric keeps the literal; all 38 shared defs now go through it (ios already used inline literals). Excess-property checking on the contextual type made threeas constsuffixes redundant.#249 — declared errors projected onto the typed client
The derived router's procedure leaves carried an empty oRPC error map, so
isDefinedErrornarrowed tonever(pinned honestly by a type test).defineTool's builder now carriesErrorsandBindinggenerics; the registry fills the procedure's 5th slot withRegistryErrorMap<Errors, Binding>— oRPC's ownMergedErrorMapwithTOOL_TRANSPORT_ERRORSfor client-bound tools, at the same decision site ascompileTool's runtime merge. Runtime untouched. The narrows-to-never pin is replaced by six positive assertions (code +datanarrowing, exact transport union for client-bound, none for server-bound, undeclared errors stay outside), vacuity-checked (a widened union fails the assertion) and revert-checked (restoringRecord<never, never>reproduces all five original errors).Zero casts, zero comments;
ToolBuildergrew to six generic slots (AnyToolBuilderabsorbs it — onlydefine-extension.tsnames them). Verified against oRPC 1.14.7 resolved sources.Gates: extension-dependents typecheck 67/67 (re-run post-rebase on the new base, 52 cache misses = real run), extension+tanstack+recorder+test-runner+core+tools tests green, lint/format green, fallow zero INTRODUCED. Whiteboard suite is CI-only by standing rule — covered here.
🤖 Generated with Claude Code