Repository navigation
[EPIC-D][LOU-D23] ToolExecutionContext replaces ai's ToolExecutionOptions in the public types - #103
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ToolExecutionContextinsrc/types/tool.ts:{ toolCallId: string; messages: readonly Message[]; abortSignal?: AbortSignal; sessionId?: string; onDelegatedUsage?: (usage: RunUsage) => void }. It merges the oldToolRunContextextras into one public type.defineTool(execute),DefinedTool.execute,ToolDescriptor.execute,sandboxExecute(third argument) andbuildToolRunContext()(return type, no moreas unknown ascast) use it.ToolRunContextstays as a deprecated alias (Partial<Omit<ToolExecutionContext, 'messages'>>, so existing imports andaitool()execute options inDelegationToolstill fit).src/types/agent.ts:AgentExecutionOptions.messagesisMessage[]instead ofCoreMessage[](noCoreMessageis exported, so no alias; the field is unused inside the SDK).src/tools/defineTool.tsno longer imports anything fromai(the legacy.toolis typed viaToolDescriptor['tool']['execute'], with a// legacy (.tool), removed in D26cast).src/types/tool.tskeeps its oneimport type { Tool as AITool } from 'ai'for the legacy.toolfield, marked// legacy (.tool), removed in D26.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:toolsrc/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
aiv4 -> v6/v7 upgrade chain (D22-D29): the public tool types must not leakai'sToolExecutionOptions, whosemessagesshape (CoreMessage[]) changes betweenaimajors. We already pass our ownMessages at runtime (U15).Acceptance criteria
ToolExecutionContextexported fromsrc/types/tool.ts(viasrc/typesand the root), merged with theToolRunContextextras;ToolRunContextkept as a deprecated aliasdefineTool,ToolDescriptor.execute,sandboxExecute,DefinedTool,buildToolRunContext()use it (workspace tools infer ctx fromdefineTool; no workspace/built-in source needed changes)src/types/*,src/tools/defineTool.tsorsrc/execution/*type import fromaiexcept the legacyAIToolinsrc/types/tool.ts(the ticket's one allowed legacy import; defineTool.ts needs none)src/types/agent.ts:CoreMessagereplaced byMessagedefineToolctx isToolExecutionContextand args still infer; a legacyaitool()descriptor still registers inToolRegistry.registerNotes:
sessionIdis declared and passed throughbuildToolRunContext()but the executor does not set it yet (wiring it needssrc/execution/toolCallExecution.ts, out of scope here; docs say so).How verified
npx tsc --noEmit: cleannpm run lint: 0 errors, 404 warnings (noanyadded; the change removes a cast)npm run test:types: 6 files, 28 tests passed, no type errorsnpx vitest run(afternpm run build): 2223 passed, 3 skipped, 1 failed:src/deploy/adapters/cloudflare.test.ts"wrangler devserves the worker on the local workerd runtime" (needs the real wrangler/workerd; fails in isolation too, unrelated to this change).src/execution/guardrails.test.tsfailed once under coverage and passed in the other runs (flaky).npm run build && npm run build --workspace=packages/create-loushy-agent: successnpm run docs:verify-snippets -- --skip-build: all 115 snippets type-check, 6 also runnpm run docs:llms:check: passesvitest run --coverage --coverage.reportOnFailure --config vitest.coverage.config.tsthennpm run fallow: exit 0, 0 above threshold (the plaintest:coveragedoes 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