Skip to content

feat(extension): shared tool definitions keep literal names, declared errors reach the typed client - #251

Merged
omridevk merged 6 commits into
mainfrom
tool-definition-248
Aug 5, 2026
Merged

omridevk merged 6 commits into
mainfrom
tool-definition-248

Conversation

@omridevk

@omridevk omridevk commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Closes #248, closes #249. Both split out of #238 (PR #247).

#248 — toolDefinition() inference site

Tools 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) widened name to string, so ToolNameOf mapped them to never: absent from the typed registry client and invisible to #247's collision diagnostics. toolDefinition() is an 8-line identity helper whose const Name generic keeps the literal; all 38 shared defs now go through it (ios already used inline literals). Excess-property checking on the contextual type made three as const suffixes redundant.

#249 — declared errors projected onto the typed client

The derived router's procedure leaves carried an empty oRPC error map, so isDefinedError narrowed to never (pinned honestly by a type test). defineTool's builder now carries Errors and Binding generics; the registry fills the procedure's 5th slot with RegistryErrorMap<Errors, Binding> — oRPC's own MergedErrorMap with TOOL_TRANSPORT_ERRORS for client-bound tools, at the same decision site as compileTool's runtime merge. Runtime untouched. The narrows-to-never pin is replaced by six positive assertions (code + data narrowing, 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 (restoring Record<never, never> reproduces all five original errors).

Zero casts, zero comments; ToolBuilder grew to six generic slots (AnyToolBuilder absorbs it — only define-extension.ts names 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

omridevk and others added 3 commits August 5, 2026 22:18
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>
Copilot AI balanced review requested due to automatic review settings August 5, 2026 19:23

Copilot AI left a comment

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.

🟡 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.

Comment thread .changeset/eager-tools-narrow.md Resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 5, 2026 19:32

Copilot AI left a comment

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.

🟢 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.

omridevk and others added 2 commits August 5, 2026 22:52
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>
Copilot AI review requested due to automatic review settings August 5, 2026 19:53

Copilot AI left a comment

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.

🟡 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 trebler and treblerTwin use toolDefinition, 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.

@omridevk
omridevk merged commit 1e1b01b into main Aug 5, 2026
24 checks passed
@omridevk
omridevk deleted the tool-definition-248 branch August 5, 2026 20:04
@github-actions github-actions Bot mentioned this pull request Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants