Skip to content

[EPIC-D][LOU-D23] ToolExecutionContext replaces ai's ToolExecutionOptions in the public types - #103

Merged
LinuxDevil merged 2 commits into
mainfrom
lou-d23-own-execute-context
Oct 1, 2026
Merged

LinuxDevil merged 2 commits into
mainfrom
lou-d23-own-execute-context

Conversation

@LinuxDevil

Copy link
Copy Markdown
Owner

What

  • New exported ToolExecutionContext in src/types/tool.ts: { toolCallId: string; messages: readonly Message[]; abortSignal?: AbortSignal; sessionId?: string; onDelegatedUsage?: (usage: RunUsage) => void }. It merges the old ToolRunContext extras into one public type.
  • defineTool (execute), DefinedTool.execute, ToolDescriptor.execute, sandboxExecute (third argument) and buildToolRunContext() (return type, no more as unknown as cast) use it. ToolRunContext stays as a deprecated alias (Partial<Omit<ToolExecutionContext, 'messages'>>, so existing imports and ai tool() execute options in DelegationTool still fit).
  • src/types/agent.ts: AgentExecutionOptions.messages is Message[] instead of CoreMessage[] (no CoreMessage is exported, so no alias; the field is unused inside the SDK).
  • src/tools/defineTool.ts no longer imports anything from ai (the legacy .tool is typed via ToolDescriptor['tool']['execute'], with a // legacy (.tool), removed in D26 cast). src/types/tool.ts keeps its one import type { Tool as AITool } from 'ai' for the legacy .tool field, marked // legacy (.tool), removed in D26.
  • Type tests, docs/tools.md "Execute context", regenerated llms-full.txt, CHANGELOG (Changed, non-breaking).

Remaining from 'ai' imports in src/ (non-test), after this change:

  • src/types/tool.ts: Tool as AITool (legacy .tool, D26)
  • src/execution/DelegationTool.ts: tool (value, builds the legacy delegate tool)
  • src/execution/structuredOutput.ts: zodSchema (value)
  • src/execution/errors.ts: APICallError, LoadAPIKeyError, RetryError (values, used for error classification)
  • src/providers/{OpenRouter,Anthropic,OpenAI,Ollama}Provider.ts: LanguageModel (type); src/providers/aiSdkProvider.ts (excluded by ticket)
  • src/tools/built-in/* (slack, http, currentDate, jira, github, email, dayName): tool (D24/D25); src/tools/mcp/McpToolLoader.ts: tool
  • tests: src/providers/toolCallTurns.contract.test.ts (coreMessageSchema, CoreMessage), src/tools/defineTool.test-d.ts (tool, for the legacy-descriptor type test)

Why

Step 2 of the ai v4 -> v6/v7 upgrade chain (D22-D29): the public tool types must not leak ai's ToolExecutionOptions, whose messages shape (CoreMessage[]) changes between ai majors. We already pass our own Messages at runtime (U15).

Acceptance criteria

  • ToolExecutionContext exported from src/types/tool.ts (via src/types and the root), merged with the ToolRunContext extras; ToolRunContext kept as a deprecated alias
  • defineTool, ToolDescriptor.execute, sandboxExecute, DefinedTool, buildToolRunContext() use it (workspace tools infer ctx from defineTool; no workspace/built-in source needed changes)
  • No src/types/*, src/tools/defineTool.ts or src/execution/* type import from ai except the legacy AITool in src/types/tool.ts (the ticket's one allowed legacy import; defineTool.ts needs none)
  • src/types/agent.ts: CoreMessage replaced by Message
  • Type tests: defineTool ctx is ToolExecutionContext and args still infer; a legacy ai tool() descriptor still registers in ToolRegistry.register
  • Docs (docs/tools.md), llms files regenerated, CHANGELOG entry

Notes: sessionId is declared and passed through buildToolRunContext() but the executor does not set it yet (wiring it needs src/execution/toolCallExecution.ts, out of scope here; docs say so).

How verified

  • npx tsc --noEmit: clean
  • npm run lint: 0 errors, 404 warnings (no any added; the change removes a cast)
  • npm run test:types: 6 files, 28 tests passed, no type errors
  • npx vitest run (after npm run build): 2223 passed, 3 skipped, 1 failed: src/deploy/adapters/cloudflare.test.ts "wrangler dev serves the worker on the local workerd runtime" (needs the real wrangler/workerd; fails in isolation too, unrelated to this change). src/execution/guardrails.test.ts failed once under coverage and passed in the other runs (flaky).
  • npm run build && npm run build --workspace=packages/create-loushy-agent: success
  • npm run docs:verify-snippets -- --skip-build: all 115 snippets type-check, 6 also run
  • npm run docs:llms:check: passes
  • vitest run --coverage --coverage.reportOnFailure --config vitest.coverage.config.ts then npm run fallow: exit 0, 0 above threshold (the plain test:coverage does not write the coverage file because of the cloudflare failure above)

🤖 Generated with Claude Code

https://claude.ai/code/session_016bY29ibQgv3MDdjAbUT4YR


Generated by Claude Code

claude added 2 commits October 1, 2026 16:19
…ions in the public types

Add the exported ToolExecutionContext (toolCallId, messages: readonly Message[],
abortSignal?, sessionId?, onDelegatedUsage?) and use it for defineTool's execute,
ToolDescriptor.execute, DefinedTool.execute, sandboxExecute and
buildToolRunContext(). ToolRunContext stays as a deprecated alias.
AgentExecutionOptions.messages is Message[] instead of ai's CoreMessage[].

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016bY29ibQgv3MDdjAbUT4YR
…ontext

# Conflicts:
#	src/execution/toolRunContext.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.

2 participants