@truefoundry/trueforge-core 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +27 -0
  2. package/dist/agent-session/ITurnResourceResolver.d.ts +8 -7
  3. package/dist/agent-session/ITurnResourceResolver.d.ts.map +1 -1
  4. package/dist/agent-session/ITurnResourceResolver.js.map +1 -1
  5. package/dist/agent-session/SessionHandle.d.ts +12 -0
  6. package/dist/agent-session/SessionHandle.d.ts.map +1 -1
  7. package/dist/agent-session/SessionHandle.js +74 -33
  8. package/dist/agent-session/SessionHandle.js.map +1 -1
  9. package/dist/agent-session/SessionHandle.mjs +74 -33
  10. package/dist/agent-session/SessionHandle.mjs.map +1 -1
  11. package/dist/agent-session/TurnResourceResolver.d.ts +3 -8
  12. package/dist/agent-session/TurnResourceResolver.d.ts.map +1 -1
  13. package/dist/agent-session/TurnResourceResolver.js +6 -2
  14. package/dist/agent-session/TurnResourceResolver.js.map +1 -1
  15. package/dist/agent-session/TurnResourceResolver.mjs +6 -2
  16. package/dist/agent-session/TurnResourceResolver.mjs.map +1 -1
  17. package/dist/agent-session/schemas/turn.d.ts.map +1 -1
  18. package/dist/agent-session/schemas/turn.js +3 -1
  19. package/dist/agent-session/schemas/turn.js.map +1 -1
  20. package/dist/agent-session/schemas/turn.mjs +3 -1
  21. package/dist/agent-session/schemas/turn.mjs.map +1 -1
  22. package/dist/agent-session/store/ISessionStore.d.ts +7 -6
  23. package/dist/agent-session/store/ISessionStore.d.ts.map +1 -1
  24. package/dist/agent-session/store/ISessionStore.js.map +1 -1
  25. package/dist/agent-session/store/InMemorySessionStore.d.ts.map +1 -1
  26. package/dist/agent-session/store/InMemorySessionStore.js +25 -10
  27. package/dist/agent-session/store/InMemorySessionStore.js.map +1 -1
  28. package/dist/agent-session/store/InMemorySessionStore.mjs +25 -10
  29. package/dist/agent-session/store/InMemorySessionStore.mjs.map +1 -1
  30. package/dist/agent-session/store/OffsetPageToken.d.ts.map +1 -1
  31. package/dist/agent-session/store/OffsetPageToken.js +3 -1
  32. package/dist/agent-session/store/OffsetPageToken.js.map +1 -1
  33. package/dist/agent-session/store/OffsetPageToken.mjs +3 -1
  34. package/dist/agent-session/store/OffsetPageToken.mjs.map +1 -1
  35. package/dist/agent-session/store/SessionListPageToken.d.ts.map +1 -1
  36. package/dist/agent-session/store/SessionListPageToken.js +3 -1
  37. package/dist/agent-session/store/SessionListPageToken.js.map +1 -1
  38. package/dist/agent-session/store/SessionListPageToken.mjs +3 -1
  39. package/dist/agent-session/store/SessionListPageToken.mjs.map +1 -1
  40. package/dist/core/InstructionBuilder.d.ts.map +1 -1
  41. package/dist/core/InstructionBuilder.js +12 -4
  42. package/dist/core/InstructionBuilder.js.map +1 -1
  43. package/dist/core/InstructionBuilder.mjs +12 -4
  44. package/dist/core/InstructionBuilder.mjs.map +1 -1
  45. package/dist/core/capabilities/builtins/AskUserQuestion.d.ts.map +1 -1
  46. package/dist/core/capabilities/builtins/AskUserQuestion.js +5 -0
  47. package/dist/core/capabilities/builtins/AskUserQuestion.js.map +1 -1
  48. package/dist/core/capabilities/builtins/AskUserQuestion.mjs +5 -0
  49. package/dist/core/capabilities/builtins/AskUserQuestion.mjs.map +1 -1
  50. package/dist/core/capabilities/builtins/LargeToolResponse.d.ts.map +1 -1
  51. package/dist/core/capabilities/builtins/LargeToolResponse.js +6 -2
  52. package/dist/core/capabilities/builtins/LargeToolResponse.js.map +1 -1
  53. package/dist/core/capabilities/builtins/LargeToolResponse.mjs +6 -2
  54. package/dist/core/capabilities/builtins/LargeToolResponse.mjs.map +1 -1
  55. package/dist/core/llm/VercelAILLM.d.ts.map +1 -1
  56. package/dist/core/llm/VercelAILLM.js +6 -2
  57. package/dist/core/llm/VercelAILLM.js.map +1 -1
  58. package/dist/core/llm/VercelAILLM.mjs +6 -2
  59. package/dist/core/llm/VercelAILLM.mjs.map +1 -1
  60. package/dist/core/mcp/RemoteMCP.d.ts.map +1 -1
  61. package/dist/core/mcp/RemoteMCP.js +15 -5
  62. package/dist/core/mcp/RemoteMCP.js.map +1 -1
  63. package/dist/core/mcp/RemoteMCP.mjs +15 -5
  64. package/dist/core/mcp/RemoteMCP.mjs.map +1 -1
  65. package/dist/core/mcp/ToolSelectorPolicy.d.ts.map +1 -1
  66. package/dist/core/mcp/ToolSelectorPolicy.js +3 -1
  67. package/dist/core/mcp/ToolSelectorPolicy.js.map +1 -1
  68. package/dist/core/mcp/ToolSelectorPolicy.mjs +3 -1
  69. package/dist/core/mcp/ToolSelectorPolicy.mjs.map +1 -1
  70. package/dist/core/mcp/ToolSet.d.ts.map +1 -1
  71. package/dist/core/mcp/ToolSet.js +9 -3
  72. package/dist/core/mcp/ToolSet.js.map +1 -1
  73. package/dist/core/mcp/ToolSet.mjs +9 -3
  74. package/dist/core/mcp/ToolSet.mjs.map +1 -1
  75. package/dist/core/mcp/convertMCPServers.d.ts.map +1 -1
  76. package/dist/core/mcp/convertMCPServers.js +6 -2
  77. package/dist/core/mcp/convertMCPServers.js.map +1 -1
  78. package/dist/core/mcp/convertMCPServers.mjs +6 -2
  79. package/dist/core/mcp/convertMCPServers.mjs.map +1 -1
  80. package/dist/core/mcp/remoteMcpClient.d.ts.map +1 -1
  81. package/dist/core/mcp/remoteMcpClient.js +21 -7
  82. package/dist/core/mcp/remoteMcpClient.js.map +1 -1
  83. package/dist/core/mcp/remoteMcpClient.mjs +21 -7
  84. package/dist/core/mcp/remoteMcpClient.mjs.map +1 -1
  85. package/dist/core/mcp/toolSelectors.d.ts.map +1 -1
  86. package/dist/core/mcp/toolSelectors.js +18 -6
  87. package/dist/core/mcp/toolSelectors.js.map +1 -1
  88. package/dist/core/mcp/toolSelectors.mjs +18 -6
  89. package/dist/core/mcp/toolSelectors.mjs.map +1 -1
  90. package/dist/core/runtime/AgentThread.d.ts.map +1 -1
  91. package/dist/core/runtime/AgentThread.js +42 -17
  92. package/dist/core/runtime/AgentThread.js.map +1 -1
  93. package/dist/core/runtime/AgentThread.mjs +42 -17
  94. package/dist/core/runtime/AgentThread.mjs.map +1 -1
  95. package/dist/core/runtime/AgentThreadOrchestrator.d.ts.map +1 -1
  96. package/dist/core/runtime/AgentThreadOrchestrator.js +27 -9
  97. package/dist/core/runtime/AgentThreadOrchestrator.js.map +1 -1
  98. package/dist/core/runtime/AgentThreadOrchestrator.mjs +27 -9
  99. package/dist/core/runtime/AgentThreadOrchestrator.mjs.map +1 -1
  100. package/dist/core/runtime/DeferredTool.d.ts.map +1 -1
  101. package/dist/core/runtime/DeferredTool.js +15 -5
  102. package/dist/core/runtime/DeferredTool.js.map +1 -1
  103. package/dist/core/runtime/DeferredTool.mjs +15 -5
  104. package/dist/core/runtime/DeferredTool.mjs.map +1 -1
  105. package/dist/core/runtime/contextUtils.d.ts.map +1 -1
  106. package/dist/core/runtime/contextUtils.js +3 -1
  107. package/dist/core/runtime/contextUtils.js.map +1 -1
  108. package/dist/core/runtime/contextUtils.mjs +3 -1
  109. package/dist/core/runtime/contextUtils.mjs.map +1 -1
  110. package/dist/core/sandbox/Sandbox.d.ts.map +1 -1
  111. package/dist/core/sandbox/Sandbox.js +12 -4
  112. package/dist/core/sandbox/Sandbox.js.map +1 -1
  113. package/dist/core/sandbox/Sandbox.mjs +12 -4
  114. package/dist/core/sandbox/Sandbox.mjs.map +1 -1
  115. package/dist/core/sandbox/codeMode/CodeModeDispatcher.d.ts.map +1 -1
  116. package/dist/core/sandbox/codeMode/CodeModeDispatcher.js +9 -3
  117. package/dist/core/sandbox/codeMode/CodeModeDispatcher.js.map +1 -1
  118. package/dist/core/sandbox/codeMode/CodeModeDispatcher.mjs +9 -3
  119. package/dist/core/sandbox/codeMode/CodeModeDispatcher.mjs.map +1 -1
  120. package/dist/core/sandbox/codeMode/nats/CodeModeNatsTransport.d.ts.map +1 -1
  121. package/dist/core/sandbox/codeMode/nats/CodeModeNatsTransport.js +9 -3
  122. package/dist/core/sandbox/codeMode/nats/CodeModeNatsTransport.js.map +1 -1
  123. package/dist/core/sandbox/codeMode/nats/CodeModeNatsTransport.mjs +9 -3
  124. package/dist/core/sandbox/codeMode/nats/CodeModeNatsTransport.mjs.map +1 -1
  125. package/dist/core/sandbox/provider/DaytonaProvider.d.ts +17 -0
  126. package/dist/core/sandbox/provider/DaytonaProvider.d.ts.map +1 -1
  127. package/dist/core/sandbox/provider/DaytonaProvider.js +83 -17
  128. package/dist/core/sandbox/provider/DaytonaProvider.js.map +1 -1
  129. package/dist/core/sandbox/provider/DaytonaProvider.mjs +83 -17
  130. package/dist/core/sandbox/provider/DaytonaProvider.mjs.map +1 -1
  131. package/dist/core/sandbox/provider/TFYSandboxProvider.d.ts.map +1 -1
  132. package/dist/core/sandbox/provider/TFYSandboxProvider.js +12 -4
  133. package/dist/core/sandbox/provider/TFYSandboxProvider.js.map +1 -1
  134. package/dist/core/sandbox/provider/TFYSandboxProvider.mjs +12 -4
  135. package/dist/core/sandbox/provider/TFYSandboxProvider.mjs.map +1 -1
  136. package/dist/core/sandbox/skills/SkillMounter.d.ts.map +1 -1
  137. package/dist/core/sandbox/skills/SkillMounter.js +3 -1
  138. package/dist/core/sandbox/skills/SkillMounter.js.map +1 -1
  139. package/dist/core/sandbox/skills/SkillMounter.mjs +3 -1
  140. package/dist/core/sandbox/skills/SkillMounter.mjs.map +1 -1
  141. package/dist/core/util/abort.d.ts.map +1 -1
  142. package/dist/core/util/abort.js +3 -1
  143. package/dist/core/util/abort.js.map +1 -1
  144. package/dist/core/util/abort.mjs +3 -1
  145. package/dist/core/util/abort.mjs.map +1 -1
  146. package/package.json +10 -6
@@ -27,13 +27,21 @@ function createTransport(type, url, headers, sessionId) {
27
27
  return new SSEClientTransport(url, { requestInit });
28
28
  }
29
29
  function isSessionExpiredError(error) {
30
- if (!(error instanceof Error)) return false;
31
- if ("code" in error && error.code === 404) return true;
30
+ if (!(error instanceof Error)) {
31
+ return false;
32
+ }
33
+ if ("code" in error && error.code === 404) {
34
+ return true;
35
+ }
32
36
  return error.message.includes("HTTP 404") || error.message.toLowerCase().includes("session");
33
37
  }
34
38
  function isAuthError(error) {
35
- if (!(error instanceof Error)) return false;
36
- if ("code" in error && error.code === 401) return true;
39
+ if (!(error instanceof Error)) {
40
+ return false;
41
+ }
42
+ if ("code" in error && error.code === 401) {
43
+ return true;
44
+ }
37
45
  return error.message.includes("HTTP 401");
38
46
  }
39
47
  function stampTraceHeaders(headers) {
@@ -43,7 +51,9 @@ function getTransportSessionId(transport) {
43
51
  return transport instanceof StreamableHTTPClientTransport ? transport.sessionId ?? null : null;
44
52
  }
45
53
  function toConnectError(error) {
46
- if (error instanceof McpConnectionError) return error;
54
+ if (error instanceof McpConnectionError) {
55
+ return error;
56
+ }
47
57
  if (isAuthError(error)) {
48
58
  return new McpConnectionError("upstream returned 401 Unauthorized (check x-tfy-mcp-headers credentials)", 401, {
49
59
  cause: error
@@ -94,8 +104,12 @@ async function connectRemoteMcp(params) {
94
104
  } catch (error) {
95
105
  await client.close().catch(() => {
96
106
  });
97
- if (isAuthError(error)) throw toConnectError(error);
98
- if (params.sessionId && isSessionExpiredError(error)) throw toConnectError(error);
107
+ if (isAuthError(error)) {
108
+ throw toConnectError(error);
109
+ }
110
+ if (params.sessionId && isSessionExpiredError(error)) {
111
+ throw toConnectError(error);
112
+ }
99
113
  failures.push({ transport: transportType, error: error instanceof Error ? error.message.trim() : String(error) });
100
114
  continue;
101
115
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/mcp/remoteMcpClient.ts"],"sourcesContent":["import { Client } from '@modelcontextprotocol/sdk/client/index.js';\n// SSE remains required during the Streamable HTTP migration (some servers still speak SSE only).\n\nimport { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport type { CallToolRequest, CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { context, propagation } from '@opentelemetry/api';\nimport { McpConnectionError } from '../errors';\nimport { withTimeout } from '../util/promiseUtils';\nimport type { ToolSchema } from './IMCPServer';\n\n/** Networking for remote (url-based) MCP servers, kept separate so it can be mocked in tests. */\n\nexport type RemoteMcpTransportType = 'streamable-http' | 'sse';\n\nexport interface RemoteMcpConnection {\n readonly transportType: RemoteMcpTransportType;\n /** Session id for a stateful server, or null for a stateless one. */\n readonly sessionId: string | null;\n listTools(cursor?: string): Promise<{ tools: ToolSchema[]; nextCursor?: string | undefined }>;\n callTool(params: CallToolRequest['params']): Promise<CallToolResult>;\n close(): Promise<void>;\n}\n\n// SSE transport type kept for dual-probe support during migration.\n// eslint-disable-next-line @typescript-eslint/no-deprecated -- see TRANSPORT_PROBE_ORDER\ntype McpTransport = StreamableHTTPClientTransport | SSEClientTransport;\n\nconst CLIENT_INFO = { name: 'tfy-agent-mcp-client', version: '1.0.0' } as const;\nconst TRANSPORT_PROBE_ORDER: RemoteMcpTransportType[] = ['streamable-http', 'sse'];\n\nclass McpClientWithTimeout extends Client {\n constructor(private readonly requestTimeoutMs: number) {\n super(CLIENT_INFO, { capabilities: {} });\n }\n\n // SDK Client.request is loosely typed; forward with an explicit timeout.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- MCP SDK request typing\n override request(req: any, schema: any, options?: any): Promise<any> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- MCP SDK request typing\n return super.request(req, schema, { ...options, timeout: this.requestTimeoutMs });\n }\n}\n\nfunction createTransport(\n type: RemoteMcpTransportType,\n url: URL,\n headers: Record<string, string>,\n sessionId?: string,\n): McpTransport {\n const requestInit = { headers };\n if (type === 'streamable-http') {\n return new StreamableHTTPClientTransport(url, { requestInit, ...(sessionId !== undefined ? { sessionId } : {}) });\n }\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- dual-transport probe; see TRANSPORT_PROBE_ORDER\n return new SSEClientTransport(url, { requestInit });\n}\n\nexport function isSessionExpiredError(error: unknown): boolean {\n if (!(error instanceof Error)) return false;\n if ('code' in error && error.code === 404) return true;\n return error.message.includes('HTTP 404') || error.message.toLowerCase().includes('session');\n}\n\nfunction isAuthError(error: unknown): boolean {\n if (!(error instanceof Error)) return false;\n if ('code' in error && error.code === 401) return true;\n return error.message.includes('HTTP 401');\n}\n\n/** Inject the active otel trace context so each request propagates its span. */\nfunction stampTraceHeaders(headers: Record<string, string>): void {\n propagation.inject(context.active(), headers);\n}\n\nfunction getTransportSessionId(transport: McpTransport): string | null {\n return transport instanceof StreamableHTTPClientTransport ? (transport.sessionId ?? null) : null;\n}\n\nfunction toConnectError(error: unknown): McpConnectionError {\n if (error instanceof McpConnectionError) return error;\n if (isAuthError(error)) {\n return new McpConnectionError('upstream returned 401 Unauthorized (check x-tfy-mcp-headers credentials)', 401, {\n cause: error,\n });\n }\n const message = error instanceof Error ? error.message : String(error);\n return new McpConnectionError(message, 502, { cause: error });\n}\n\nfunction buildConnection(\n client: McpClientWithTimeout,\n transport: McpTransport,\n transportType: RemoteMcpTransportType,\n headers: Record<string, string>,\n requestOptions: { signal: AbortSignal },\n): RemoteMcpConnection {\n return {\n transportType,\n sessionId: getTransportSessionId(transport),\n listTools: async (cursor?: string) => {\n stampTraceHeaders(headers);\n const response = await client.listTools(cursor ? { cursor } : undefined, requestOptions);\n return {\n tools: response.tools,\n nextCursor: response.nextCursor,\n };\n },\n callTool: async (callParams: CallToolRequest['params']): Promise<CallToolResult> => {\n stampTraceHeaders(headers);\n return (await client.callTool(callParams, undefined, requestOptions)) as CallToolResult;\n },\n close: async (): Promise<void> => {\n await client.close().catch(() => {\n /* no-op */\n });\n },\n };\n}\n\n/**\n * Connect to a remote MCP server, keeping the first transport that connects. `sessionId` is passed to\n * every attempt so a stateful session resumes in place instead of opening a throwaway one.\n *\n * `knownTransportType` is a hint (from a prior connect / persisted state): it's tried first for a fast\n * path, but on failure we still fall back to probing the remaining transports, so a stale or wrong\n * hint (server switched transports, bad resume data) self-heals instead of failing every turn.\n */\nexport async function connectRemoteMcp(params: {\n url: string;\n headers: Record<string, string>;\n sessionId?: string | undefined;\n knownTransportType?: RemoteMcpTransportType | undefined;\n requestTimeoutMs: number;\n connectTimeoutMs: number;\n signal: AbortSignal;\n onClose?: (() => void) | undefined;\n onError?: ((error: Error) => void) | undefined;\n}): Promise<RemoteMcpConnection> {\n const url = new URL(params.url);\n const requestOptions = { signal: params.signal };\n const candidates = params.knownTransportType\n ? [params.knownTransportType, ...TRANSPORT_PROBE_ORDER.filter(t => t !== params.knownTransportType)]\n : TRANSPORT_PROBE_ORDER;\n const failures: { transport: RemoteMcpTransportType; error: string }[] = [];\n\n for (const transportType of candidates) {\n const transport = createTransport(transportType, url, params.headers, params.sessionId);\n const client = new McpClientWithTimeout(params.requestTimeoutMs);\n try {\n stampTraceHeaders(params.headers);\n await withTimeout(\n // Concrete transports use sessionId: string|undefined; Transport uses an optional\n // property — exactOptionalPropertyTypes rejects assignability without this cast.\n client.connect(transport as Parameters<Client['connect']>[0], requestOptions),\n params.connectTimeoutMs,\n transportType,\n );\n } catch (error) {\n await client.close().catch(() => {\n /* no-op */\n });\n if (isAuthError(error)) throw toConnectError(error);\n // A session-expired error means the transport is right but the session is stale: surface it so\n // the caller reconnects fresh instead of falling through to a different transport.\n if (params.sessionId && isSessionExpiredError(error)) throw toConnectError(error);\n failures.push({ transport: transportType, error: error instanceof Error ? error.message.trim() : String(error) });\n continue;\n }\n\n // Set on the client (not the transport) so the SDK's own onclose/onerror cleanup still runs; the\n // SDK invokes these from inside it. Only wired on the kept connection, so failed attempts stay quiet.\n client.onclose = () => params.onClose?.();\n client.onerror = error => params.onError?.(error);\n return buildConnection(client, transport, transportType, params.headers, requestOptions);\n }\n\n throw new McpConnectionError(`failed to connect (tried ${candidates.join(', ')}): ${JSON.stringify(failures)}`, 502);\n}\n"],"mappings":";AAAA,SAAS,cAAc;AAGvB,SAAS,0BAA0B;AACnC,SAAS,qCAAqC;AAE9C,SAAS,SAAS,mBAAmB;AACrC,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAoB5B,IAAM,cAAc,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O,QAAQ,WAA+C,cAAc;AAAA,QAC5E,OAAO;AAAA,QACP;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,YAAM,OAAO,MAAM,EAAE,MAAM,MAAM;AAAA,MAEjC,CAAC;AACD,UAAI,YAAY,KAAK,EAAG,OAAM,eAAe,KAAK;AAGlD,UAAI,OAAO,aAAa,sBAAsB,KAAK,EAAG,OAAM,eAAe,KAAK;AAChF,eAAS,KAAK,EAAE,WAAW,eAAe,OAAO,iBAAiB,QAAQ,MAAM,QAAQ,KAAK,IAAI,OAAO,KAAK,EAAE,CAAC;AAChH;AAAA,IACF;AAIA,WAAO,UAAU,MAAM,OAAO,UAAU;AACxC,WAAO,UAAU,WAAS,OAAO,UAAU,KAAK;AAChD,WAAO,gBAAgB,QAAQ,WAAW,eAAe,OAAO,SAAS,cAAc;AAAA,EACzF;AAEA,QAAM,IAAI,mBAAmB,4BAA4B,WAAW,KAAK,IAAI,CAAC,MAAM,KAAK,UAAU,QAAQ,CAAC,IAAI,GAAG;AACrH;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/mcp/remoteMcpClient.ts"],"sourcesContent":["import { Client } from '@modelcontextprotocol/sdk/client/index.js';\n// SSE remains required during the Streamable HTTP migration (some servers still speak SSE only).\n\nimport { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport type { CallToolRequest, CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { context, propagation } from '@opentelemetry/api';\nimport { McpConnectionError } from '../errors';\nimport { withTimeout } from '../util/promiseUtils';\nimport type { ToolSchema } from './IMCPServer';\n\n/** Networking for remote (url-based) MCP servers, kept separate so it can be mocked in tests. */\n\nexport type RemoteMcpTransportType = 'streamable-http' | 'sse';\n\nexport interface RemoteMcpConnection {\n readonly transportType: RemoteMcpTransportType;\n /** Session id for a stateful server, or null for a stateless one. */\n readonly sessionId: string | null;\n listTools(cursor?: string): Promise<{ tools: ToolSchema[]; nextCursor?: string | undefined }>;\n callTool(params: CallToolRequest['params']): Promise<CallToolResult>;\n close(): Promise<void>;\n}\n\n// SSE transport type kept for dual-probe support during migration.\n// eslint-disable-next-line @typescript-eslint/no-deprecated -- see TRANSPORT_PROBE_ORDER\ntype McpTransport = StreamableHTTPClientTransport | SSEClientTransport;\n\nconst CLIENT_INFO = { name: 'tfy-agent-mcp-client', version: '1.0.0' } as const;\nconst TRANSPORT_PROBE_ORDER: RemoteMcpTransportType[] = ['streamable-http', 'sse'];\n\nclass McpClientWithTimeout extends Client {\n constructor(private readonly requestTimeoutMs: number) {\n super(CLIENT_INFO, { capabilities: {} });\n }\n\n // SDK Client.request is loosely typed; forward with an explicit timeout.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- MCP SDK request typing\n override request(req: any, schema: any, options?: any): Promise<any> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- MCP SDK request typing\n return super.request(req, schema, { ...options, timeout: this.requestTimeoutMs });\n }\n}\n\nfunction createTransport(\n type: RemoteMcpTransportType,\n url: URL,\n headers: Record<string, string>,\n sessionId?: string,\n): McpTransport {\n const requestInit = { headers };\n if (type === 'streamable-http') {\n return new StreamableHTTPClientTransport(url, { requestInit, ...(sessionId !== undefined ? { sessionId } : {}) });\n }\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- dual-transport probe; see TRANSPORT_PROBE_ORDER\n return new SSEClientTransport(url, { requestInit });\n}\n\nexport function isSessionExpiredError(error: unknown): boolean {\n if (!(error instanceof Error)) {\n return false;\n }\n if ('code' in error && error.code === 404) {\n return true;\n }\n return error.message.includes('HTTP 404') || error.message.toLowerCase().includes('session');\n}\n\nfunction isAuthError(error: unknown): boolean {\n if (!(error instanceof Error)) {\n return false;\n }\n if ('code' in error && error.code === 401) {\n return true;\n }\n return error.message.includes('HTTP 401');\n}\n\n/** Inject the active otel trace context so each request propagates its span. */\nfunction stampTraceHeaders(headers: Record<string, string>): void {\n propagation.inject(context.active(), headers);\n}\n\nfunction getTransportSessionId(transport: McpTransport): string | null {\n return transport instanceof StreamableHTTPClientTransport ? (transport.sessionId ?? null) : null;\n}\n\nfunction toConnectError(error: unknown): McpConnectionError {\n if (error instanceof McpConnectionError) {\n return error;\n }\n if (isAuthError(error)) {\n return new McpConnectionError('upstream returned 401 Unauthorized (check x-tfy-mcp-headers credentials)', 401, {\n cause: error,\n });\n }\n const message = error instanceof Error ? error.message : String(error);\n return new McpConnectionError(message, 502, { cause: error });\n}\n\nfunction buildConnection(\n client: McpClientWithTimeout,\n transport: McpTransport,\n transportType: RemoteMcpTransportType,\n headers: Record<string, string>,\n requestOptions: { signal: AbortSignal },\n): RemoteMcpConnection {\n return {\n transportType,\n sessionId: getTransportSessionId(transport),\n listTools: async (cursor?: string) => {\n stampTraceHeaders(headers);\n const response = await client.listTools(cursor ? { cursor } : undefined, requestOptions);\n return {\n tools: response.tools,\n nextCursor: response.nextCursor,\n };\n },\n callTool: async (callParams: CallToolRequest['params']): Promise<CallToolResult> => {\n stampTraceHeaders(headers);\n return (await client.callTool(callParams, undefined, requestOptions)) as CallToolResult;\n },\n close: async (): Promise<void> => {\n await client.close().catch(() => {\n /* no-op */\n });\n },\n };\n}\n\n/**\n * Connect to a remote MCP server, keeping the first transport that connects. `sessionId` is passed to\n * every attempt so a stateful session resumes in place instead of opening a throwaway one.\n *\n * `knownTransportType` is a hint (from a prior connect / persisted state): it's tried first for a fast\n * path, but on failure we still fall back to probing the remaining transports, so a stale or wrong\n * hint (server switched transports, bad resume data) self-heals instead of failing every turn.\n */\nexport async function connectRemoteMcp(params: {\n url: string;\n headers: Record<string, string>;\n sessionId?: string | undefined;\n knownTransportType?: RemoteMcpTransportType | undefined;\n requestTimeoutMs: number;\n connectTimeoutMs: number;\n signal: AbortSignal;\n onClose?: (() => void) | undefined;\n onError?: ((error: Error) => void) | undefined;\n}): Promise<RemoteMcpConnection> {\n const url = new URL(params.url);\n const requestOptions = { signal: params.signal };\n const candidates = params.knownTransportType\n ? [params.knownTransportType, ...TRANSPORT_PROBE_ORDER.filter(t => t !== params.knownTransportType)]\n : TRANSPORT_PROBE_ORDER;\n const failures: { transport: RemoteMcpTransportType; error: string }[] = [];\n\n for (const transportType of candidates) {\n const transport = createTransport(transportType, url, params.headers, params.sessionId);\n const client = new McpClientWithTimeout(params.requestTimeoutMs);\n try {\n stampTraceHeaders(params.headers);\n await withTimeout(\n // Concrete transports use sessionId: string|undefined; Transport uses an optional\n // property — exactOptionalPropertyTypes rejects assignability without this cast.\n client.connect(transport as Parameters<Client['connect']>[0], requestOptions),\n params.connectTimeoutMs,\n transportType,\n );\n } catch (error) {\n await client.close().catch(() => {\n /* no-op */\n });\n if (isAuthError(error)) {\n throw toConnectError(error);\n }\n // A session-expired error means the transport is right but the session is stale: surface it so\n // the caller reconnects fresh instead of falling through to a different transport.\n if (params.sessionId && isSessionExpiredError(error)) {\n throw toConnectError(error);\n }\n failures.push({ transport: transportType, error: error instanceof Error ? error.message.trim() : String(error) });\n continue;\n }\n\n // Set on the client (not the transport) so the SDK's own onclose/onerror cleanup still runs; the\n // SDK invokes these from inside it. Only wired on the kept connection, so failed attempts stay quiet.\n client.onclose = () => params.onClose?.();\n client.onerror = error => params.onError?.(error);\n return buildConnection(client, transport, transportType, params.headers, requestOptions);\n }\n\n throw new McpConnectionError(`failed to connect (tried ${candidates.join(', ')}): ${JSON.stringify(failures)}`, 502);\n}\n"],"mappings":";AAAA,SAAS,cAAc;AAGvB,SAAS,0BAA0B;AACnC,SAAS,qCAAqC;AAE9C,SAAS,SAAS,mBAAmB;AACrC,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAoB5B,IAAM,cAAc,EAAE,MAAM,wBAAwB,SAAS,QAAQ;AACrE,IAAM,wBAAkD,CAAC,mBAAmB,KAAK;AAEjF,IAAM,uBAAN,cAAmC,OAAO;AAAA,EACxC,YAA6B,kBAA0B;AACrD,UAAM,aAAa,EAAE,cAAc,CAAC,EAAE,CAAC;AADZ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AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,eAAe,GAAG,SAAS,EACxC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GACvC,OAAO,CAKT;AAED,oDAAoD;AACpD,wBAAgB,aAAa,CAAC,MAAM,EAAE;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,eAAe,GAAG,SAAS,CAAC;IACzC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC,GAAG,OAAO,CASV;AAED,yFAAyF;AACzF,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,CAKnF;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,OAAO,CAErF"}
@@ -69,10 +69,14 @@ function toolMatchesTag(tag, annotations) {
69
69
  }
70
70
  }
71
71
  function toolMatchesAnySelector(toolName, annotations, selectors) {
72
- if (!selectors?.length) return false;
72
+ if (!selectors?.length) {
73
+ return false;
74
+ }
73
75
  for (const selector of selectors) {
74
76
  if (isToolTag(selector)) {
75
- if (toolMatchesTag(selector, annotations)) return true;
77
+ if (toolMatchesTag(selector, annotations)) {
78
+ return true;
79
+ }
76
80
  } else if (selector === toolName) {
77
81
  return true;
78
82
  }
@@ -80,17 +84,25 @@ function toolMatchesAnySelector(toolName, annotations, selectors) {
80
84
  return false;
81
85
  }
82
86
  function toolRequiresApproval(toolName, annotations, selectors) {
83
- if (!selectors?.length) return false;
87
+ if (!selectors?.length) {
88
+ return false;
89
+ }
84
90
  return toolMatchesAnySelector(toolName, annotations, selectors);
85
91
  }
86
92
  function isToolAllowed(params) {
87
93
  const { toolName, annotations, enableSelectors, disableSelectors } = params;
88
- if (!toolMatchesAnySelector(toolName, annotations, enableSelectors)) return false;
89
- if (toolMatchesAnySelector(toolName, annotations, disableSelectors)) return false;
94
+ if (!toolMatchesAnySelector(toolName, annotations, enableSelectors)) {
95
+ return false;
96
+ }
97
+ if (toolMatchesAnySelector(toolName, annotations, disableSelectors)) {
98
+ return false;
99
+ }
90
100
  return true;
91
101
  }
92
102
  function literalToolNames(selectors) {
93
- if (!selectors) return [];
103
+ if (!selectors) {
104
+ return [];
105
+ }
94
106
  return selectors.filter((s) => !isToolTag(s));
95
107
  }
96
108
  function selectorsIncludeAll(selectors) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/mcp/toolSelectors.ts"],"sourcesContent":["import type { ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * MCP server tool selectors are either a special tag or a literal tool name.\n *\n * @all — every tool on the server\n * @read-only — readOnlyHint === true\n * @write — readOnlyHint === false and not destructive\n * @destructive — destructiveHint === true\n */\nconst TOOL_TAG_ALL = '@all';\nconst TOOL_TAG_READ_ONLY = '@read-only';\nconst TOOL_TAG_WRITE = '@write';\nconst TOOL_TAG_DESTRUCTIVE = '@destructive';\n\nconst TOOL_TAGS = [TOOL_TAG_ALL, TOOL_TAG_READ_ONLY, TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE] as const;\ntype ToolTag = (typeof TOOL_TAGS)[number];\n\n/** Tags allowed on `enable_tools`, `disable_tools`, and `preload_tools`. */\nexport const TOOLS_SELECTOR_TAGS = [TOOL_TAG_ALL, TOOL_TAG_READ_ONLY] as const;\n\n/** Tags allowed on `require_approval_for_tools`. */\nexport const REQUIRE_APPROVAL_TOOLS_SELECTOR_TAGS = [TOOL_TAG_ALL, TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE] as const;\n\nexport const DEFAULT_ENABLE_TOOLS: string[] = [TOOL_TAG_ALL];\nexport const DEFAULT_DISABLE_TOOLS: string[] = [];\nexport const DEFAULT_PRELOAD_TOOLS: string[] = [];\nexport const DEFAULT_REQUIRE_APPROVAL_FOR_TOOLS: string[] = [TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE];\n\nfunction isToolTag(selector: string): selector is ToolTag {\n return TOOL_TAGS.includes(selector as ToolTag);\n}\n\nfunction isReadOnly(annotations?: ToolAnnotations): boolean {\n return annotations?.readOnlyHint === true;\n}\n\nfunction isWrite(annotations?: ToolAnnotations): boolean {\n return annotations?.readOnlyHint === false && annotations.destructiveHint !== true;\n}\n\nfunction isDestructive(annotations?: ToolAnnotations): boolean {\n return annotations?.destructiveHint === true;\n}\n\nfunction toolMatchesTag(tag: ToolTag, annotations: ToolAnnotations | undefined): boolean {\n switch (tag) {\n case TOOL_TAG_ALL:\n return true;\n case TOOL_TAG_READ_ONLY:\n return isReadOnly(annotations);\n case TOOL_TAG_WRITE:\n return isWrite(annotations);\n case TOOL_TAG_DESTRUCTIVE:\n return isDestructive(annotations);\n }\n}\n\n/** True if the tool matches any selector (tag or literal name). */\nexport function toolMatchesAnySelector(\n toolName: string,\n annotations: ToolAnnotations | undefined,\n selectors: readonly string[] | undefined,\n): boolean {\n if (!selectors?.length) return false;\n\n for (const selector of selectors) {\n if (isToolTag(selector)) {\n if (toolMatchesTag(selector, annotations)) return true;\n } else if (selector === toolName) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Whether the tool requires human approval before execution.\n * Matches `@write`, `@destructive`, `@all`, or explicit tool names against annotations.\n * Unannotated tools are exempt unless named in `require_approval_for_tools` or covered by `@all`.\n */\nexport function toolRequiresApproval(\n toolName: string,\n annotations: ToolAnnotations | undefined,\n selectors: readonly string[] | undefined,\n): boolean {\n if (!selectors?.length) return false;\n return toolMatchesAnySelector(toolName, annotations, selectors);\n}\n\n/** True if the tool is enabled and not disabled. */\nexport function isToolAllowed(params: {\n toolName: string;\n annotations: ToolAnnotations | undefined;\n enableSelectors: readonly string[];\n disableSelectors: readonly string[];\n}): boolean {\n const { toolName, annotations, enableSelectors, disableSelectors } = params;\n if (!toolMatchesAnySelector(toolName, annotations, enableSelectors)) return false;\n if (toolMatchesAnySelector(toolName, annotations, disableSelectors)) return false;\n return true;\n}\n\n/** Non-tag names from a selector list (for upfront validation / sandbox allow-lists). */\nexport function literalToolNames(selectors: readonly string[] | undefined): string[] {\n if (!selectors) return [];\n return selectors.filter(s => !isToolTag(s));\n}\n\nexport function selectorsIncludeAll(selectors: readonly string[] | undefined): boolean {\n return !!selectors?.includes(TOOL_TAG_ALL);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,IAAM,eAAe;AACrB,IAAM,qBAAqB;AAC3B,IAAM,iBAAiB;AACvB,IAAM,uBAAuB;AAE7B,IAAM,YAAY,CAAC,cAAc,oBAAoB,gBAAgB,oBAAoB;AAIlF,IAAM,sBAAsB,CAAC,cAAc,kBAAkB;AAG7D,IAAM,uCAAuC,CAAC,cAAc,gBAAgB,oBAAoB;AAEhG,IAAM,uBAAiC,CAAC,YAAY;AACpD,IAAM,wBAAkC,CAAC;AACzC,IAAM,wBAAkC,CAAC;AACzC,IAAM,qCAA+C,CAAC,gBAAgB,oBAAoB;AAEjG,SAAS,UAAU,UAAuC;AACxD,SAAO,UAAU,SAAS,QAAmB;AAC/C;AAEA,SAAS,WAAW,aAAwC;AAC1D,SAAO,aAAa,iBAAiB;AACvC;AAEA,SAAS,QAAQ,aAAwC;AACvD,SAAO,aAAa,iBAAiB,SAAS,YAAY,oBAAoB;AAChF;AAEA,SAAS,cAAc,aAAwC;AAC7D,SAAO,aAAa,oBAAoB;AAC1C;AAEA,SAAS,eAAe,KAAc,aAAmD;AACvF,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,WAAW,WAAW;AAAA,IAC/B,KAAK;AACH,aAAO,QAAQ,WAAW;AAAA,IAC5B,KAAK;AACH,aAAO,cAAc,WAAW;AAAA,EACpC;AACF;AAGO,SAAS,uBACd,UACA,aACA,WACS;AACT,MAAI,CAAC,WAAW,OAAQ,QAAO;AAE/B,aAAW,YAAY,WAAW;AAChC,QAAI,UAAU,QAAQ,GAAG;AACvB,UAAI,eAAe,UAAU,WAAW,EAAG,QAAO;AAAA,IACpD,WAAW,aAAa,UAAU;AAChC,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAOO,SAAS,qBACd,UACA,aACA,WACS;AACT,MAAI,CAAC,WAAW,OAAQ,QAAO;AAC/B,SAAO,uBAAuB,UAAU,aAAa,SAAS;AAChE;AAGO,SAAS,cAAc,QAKlB;AACV,QAAM,EAAE,UAAU,aAAa,iBAAiB,iBAAiB,IAAI;AACrE,MAAI,CAAC,uBAAuB,UAAU,aAAa,eAAe,EAAG,QAAO;AAC5E,MAAI,uBAAuB,UAAU,aAAa,gBAAgB,EAAG,QAAO;AAC5E,SAAO;AACT;AAGO,SAAS,iBAAiB,WAAoD;AACnF,MAAI,CAAC,UAAW,QAAO,CAAC;AACxB,SAAO,UAAU,OAAO,OAAK,CAAC,UAAU,CAAC,CAAC;AAC5C;AAEO,SAAS,oBAAoB,WAAmD;AACrF,SAAO,CAAC,CAAC,WAAW,SAAS,YAAY;AAC3C;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/mcp/toolSelectors.ts"],"sourcesContent":["import type { ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * MCP server tool selectors are either a special tag or a literal tool name.\n *\n * @all — every tool on the server\n * @read-only — readOnlyHint === true\n * @write — readOnlyHint === false and not destructive\n * @destructive — destructiveHint === true\n */\nconst TOOL_TAG_ALL = '@all';\nconst TOOL_TAG_READ_ONLY = '@read-only';\nconst TOOL_TAG_WRITE = '@write';\nconst TOOL_TAG_DESTRUCTIVE = '@destructive';\n\nconst TOOL_TAGS = [TOOL_TAG_ALL, TOOL_TAG_READ_ONLY, TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE] as const;\ntype ToolTag = (typeof TOOL_TAGS)[number];\n\n/** Tags allowed on `enable_tools`, `disable_tools`, and `preload_tools`. */\nexport const TOOLS_SELECTOR_TAGS = [TOOL_TAG_ALL, TOOL_TAG_READ_ONLY] as const;\n\n/** Tags allowed on `require_approval_for_tools`. */\nexport const REQUIRE_APPROVAL_TOOLS_SELECTOR_TAGS = [TOOL_TAG_ALL, TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE] as const;\n\nexport const DEFAULT_ENABLE_TOOLS: string[] = [TOOL_TAG_ALL];\nexport const DEFAULT_DISABLE_TOOLS: string[] = [];\nexport const DEFAULT_PRELOAD_TOOLS: string[] = [];\nexport const DEFAULT_REQUIRE_APPROVAL_FOR_TOOLS: string[] = [TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE];\n\nfunction isToolTag(selector: string): selector is ToolTag {\n return TOOL_TAGS.includes(selector as ToolTag);\n}\n\nfunction isReadOnly(annotations?: ToolAnnotations): boolean {\n return annotations?.readOnlyHint === true;\n}\n\nfunction isWrite(annotations?: ToolAnnotations): boolean {\n return annotations?.readOnlyHint === false && annotations.destructiveHint !== true;\n}\n\nfunction isDestructive(annotations?: ToolAnnotations): boolean {\n return annotations?.destructiveHint === true;\n}\n\nfunction toolMatchesTag(tag: ToolTag, annotations: ToolAnnotations | undefined): boolean {\n switch (tag) {\n case TOOL_TAG_ALL:\n return true;\n case TOOL_TAG_READ_ONLY:\n return isReadOnly(annotations);\n case TOOL_TAG_WRITE:\n return isWrite(annotations);\n case TOOL_TAG_DESTRUCTIVE:\n return isDestructive(annotations);\n }\n}\n\n/** True if the tool matches any selector (tag or literal name). */\nexport function toolMatchesAnySelector(\n toolName: string,\n annotations: ToolAnnotations | undefined,\n selectors: readonly string[] | undefined,\n): boolean {\n if (!selectors?.length) {\n return false;\n }\n\n for (const selector of selectors) {\n if (isToolTag(selector)) {\n if (toolMatchesTag(selector, annotations)) {\n return true;\n }\n } else if (selector === toolName) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Whether the tool requires human approval before execution.\n * Matches `@write`, `@destructive`, `@all`, or explicit tool names against annotations.\n * Unannotated tools are exempt unless named in `require_approval_for_tools` or covered by `@all`.\n */\nexport function toolRequiresApproval(\n toolName: string,\n annotations: ToolAnnotations | undefined,\n selectors: readonly string[] | undefined,\n): boolean {\n if (!selectors?.length) {\n return false;\n }\n return toolMatchesAnySelector(toolName, annotations, selectors);\n}\n\n/** True if the tool is enabled and not disabled. */\nexport function isToolAllowed(params: {\n toolName: string;\n annotations: ToolAnnotations | undefined;\n enableSelectors: readonly string[];\n disableSelectors: readonly string[];\n}): boolean {\n const { toolName, annotations, enableSelectors, disableSelectors } = params;\n if (!toolMatchesAnySelector(toolName, annotations, enableSelectors)) {\n return false;\n }\n if (toolMatchesAnySelector(toolName, annotations, disableSelectors)) {\n return false;\n }\n return true;\n}\n\n/** Non-tag names from a selector list (for upfront validation / sandbox allow-lists). */\nexport function literalToolNames(selectors: readonly string[] | undefined): string[] {\n if (!selectors) {\n return [];\n }\n return selectors.filter(s => !isToolTag(s));\n}\n\nexport function selectorsIncludeAll(selectors: readonly string[] | undefined): boolean {\n return !!selectors?.includes(TOOL_TAG_ALL);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,IAAM,eAAe;AACrB,IAAM,qBAAqB;AAC3B,IAAM,iBAAiB;AACvB,IAAM,uBAAuB;AAE7B,IAAM,YAAY,CAAC,cAAc,oBAAoB,gBAAgB,oBAAoB;AAIlF,IAAM,sBAAsB,CAAC,cAAc,kBAAkB;AAG7D,IAAM,uCAAuC,CAAC,cAAc,gBAAgB,oBAAoB;AAEhG,IAAM,uBAAiC,CAAC,YAAY;AACpD,IAAM,wBAAkC,CAAC;AACzC,IAAM,wBAAkC,CAAC;AACzC,IAAM,qCAA+C,CAAC,gBAAgB,oBAAoB;AAEjG,SAAS,UAAU,UAAuC;AACxD,SAAO,UAAU,S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BAAoB,WAAmD;AACrF,SAAO,CAAC,CAAC,WAAW,SAAS,YAAY;AAC3C;","names":[]}
@@ -35,10 +35,14 @@ function toolMatchesTag(tag, annotations) {
35
35
  }
36
36
  }
37
37
  function toolMatchesAnySelector(toolName, annotations, selectors) {
38
- if (!selectors?.length) return false;
38
+ if (!selectors?.length) {
39
+ return false;
40
+ }
39
41
  for (const selector of selectors) {
40
42
  if (isToolTag(selector)) {
41
- if (toolMatchesTag(selector, annotations)) return true;
43
+ if (toolMatchesTag(selector, annotations)) {
44
+ return true;
45
+ }
42
46
  } else if (selector === toolName) {
43
47
  return true;
44
48
  }
@@ -46,17 +50,25 @@ function toolMatchesAnySelector(toolName, annotations, selectors) {
46
50
  return false;
47
51
  }
48
52
  function toolRequiresApproval(toolName, annotations, selectors) {
49
- if (!selectors?.length) return false;
53
+ if (!selectors?.length) {
54
+ return false;
55
+ }
50
56
  return toolMatchesAnySelector(toolName, annotations, selectors);
51
57
  }
52
58
  function isToolAllowed(params) {
53
59
  const { toolName, annotations, enableSelectors, disableSelectors } = params;
54
- if (!toolMatchesAnySelector(toolName, annotations, enableSelectors)) return false;
55
- if (toolMatchesAnySelector(toolName, annotations, disableSelectors)) return false;
60
+ if (!toolMatchesAnySelector(toolName, annotations, enableSelectors)) {
61
+ return false;
62
+ }
63
+ if (toolMatchesAnySelector(toolName, annotations, disableSelectors)) {
64
+ return false;
65
+ }
56
66
  return true;
57
67
  }
58
68
  function literalToolNames(selectors) {
59
- if (!selectors) return [];
69
+ if (!selectors) {
70
+ return [];
71
+ }
60
72
  return selectors.filter((s) => !isToolTag(s));
61
73
  }
62
74
  function selectorsIncludeAll(selectors) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/mcp/toolSelectors.ts"],"sourcesContent":["import type { ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * MCP server tool selectors are either a special tag or a literal tool name.\n *\n * @all — every tool on the server\n * @read-only — readOnlyHint === true\n * @write — readOnlyHint === false and not destructive\n * @destructive — destructiveHint === true\n */\nconst TOOL_TAG_ALL = '@all';\nconst TOOL_TAG_READ_ONLY = '@read-only';\nconst TOOL_TAG_WRITE = '@write';\nconst TOOL_TAG_DESTRUCTIVE = '@destructive';\n\nconst TOOL_TAGS = [TOOL_TAG_ALL, TOOL_TAG_READ_ONLY, TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE] as const;\ntype ToolTag = (typeof TOOL_TAGS)[number];\n\n/** Tags allowed on `enable_tools`, `disable_tools`, and `preload_tools`. */\nexport const TOOLS_SELECTOR_TAGS = [TOOL_TAG_ALL, TOOL_TAG_READ_ONLY] as const;\n\n/** Tags allowed on `require_approval_for_tools`. */\nexport const REQUIRE_APPROVAL_TOOLS_SELECTOR_TAGS = [TOOL_TAG_ALL, TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE] as const;\n\nexport const DEFAULT_ENABLE_TOOLS: string[] = [TOOL_TAG_ALL];\nexport const DEFAULT_DISABLE_TOOLS: string[] = [];\nexport const DEFAULT_PRELOAD_TOOLS: string[] = [];\nexport const DEFAULT_REQUIRE_APPROVAL_FOR_TOOLS: string[] = [TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE];\n\nfunction isToolTag(selector: string): selector is ToolTag {\n return TOOL_TAGS.includes(selector as ToolTag);\n}\n\nfunction isReadOnly(annotations?: ToolAnnotations): boolean {\n return annotations?.readOnlyHint === true;\n}\n\nfunction isWrite(annotations?: ToolAnnotations): boolean {\n return annotations?.readOnlyHint === false && annotations.destructiveHint !== true;\n}\n\nfunction isDestructive(annotations?: ToolAnnotations): boolean {\n return annotations?.destructiveHint === true;\n}\n\nfunction toolMatchesTag(tag: ToolTag, annotations: ToolAnnotations | undefined): boolean {\n switch (tag) {\n case TOOL_TAG_ALL:\n return true;\n case TOOL_TAG_READ_ONLY:\n return isReadOnly(annotations);\n case TOOL_TAG_WRITE:\n return isWrite(annotations);\n case TOOL_TAG_DESTRUCTIVE:\n return isDestructive(annotations);\n }\n}\n\n/** True if the tool matches any selector (tag or literal name). */\nexport function toolMatchesAnySelector(\n toolName: string,\n annotations: ToolAnnotations | undefined,\n selectors: readonly string[] | undefined,\n): boolean {\n if (!selectors?.length) return false;\n\n for (const selector of selectors) {\n if (isToolTag(selector)) {\n if (toolMatchesTag(selector, annotations)) return true;\n } else if (selector === toolName) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Whether the tool requires human approval before execution.\n * Matches `@write`, `@destructive`, `@all`, or explicit tool names against annotations.\n * Unannotated tools are exempt unless named in `require_approval_for_tools` or covered by `@all`.\n */\nexport function toolRequiresApproval(\n toolName: string,\n annotations: ToolAnnotations | undefined,\n selectors: readonly string[] | undefined,\n): boolean {\n if (!selectors?.length) return false;\n return toolMatchesAnySelector(toolName, annotations, selectors);\n}\n\n/** True if the tool is enabled and not disabled. */\nexport function isToolAllowed(params: {\n toolName: string;\n annotations: ToolAnnotations | undefined;\n enableSelectors: readonly string[];\n disableSelectors: readonly string[];\n}): boolean {\n const { toolName, annotations, enableSelectors, disableSelectors } = params;\n if (!toolMatchesAnySelector(toolName, annotations, enableSelectors)) return false;\n if (toolMatchesAnySelector(toolName, annotations, disableSelectors)) return false;\n return true;\n}\n\n/** Non-tag names from a selector list (for upfront validation / sandbox allow-lists). */\nexport function literalToolNames(selectors: readonly string[] | undefined): string[] {\n if (!selectors) return [];\n return selectors.filter(s => !isToolTag(s));\n}\n\nexport function selectorsIncludeAll(selectors: readonly string[] | undefined): boolean {\n return !!selectors?.includes(TOOL_TAG_ALL);\n}\n"],"mappings":";AAUA,IAAM,eAAe;AACrB,IAAM,qBAAqB;AAC3B,IAAM,iBAAiB;AACvB,IAAM,uBAAuB;AAE7B,IAAM,YAAY,CAAC,cAAc,oBAAoB,gBAAgB,oBAAoB;AAIlF,IAAM,sBAAsB,CAAC,cAAc,kBAAkB;AAG7D,IAAM,uCAAuC,CAAC,cAAc,gBAAgB,oBAAoB;AAEhG,IAAM,uBAAiC,CAAC,YAAY;AAC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OAAK,CAAC,UAAU,CAAC,CAAC;AAC5C;AAEO,SAAS,oBAAoB,WAAmD;AACrF,SAAO,CAAC,CAAC,WAAW,SAAS,YAAY;AAC3C;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/mcp/toolSelectors.ts"],"sourcesContent":["import type { ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * MCP server tool selectors are either a special tag or a literal tool name.\n *\n * @all — every tool on the server\n * @read-only — readOnlyHint === true\n * @write — readOnlyHint === false and not destructive\n * @destructive — destructiveHint === true\n */\nconst TOOL_TAG_ALL = '@all';\nconst TOOL_TAG_READ_ONLY = '@read-only';\nconst TOOL_TAG_WRITE = '@write';\nconst TOOL_TAG_DESTRUCTIVE = '@destructive';\n\nconst TOOL_TAGS = [TOOL_TAG_ALL, TOOL_TAG_READ_ONLY, TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE] as const;\ntype ToolTag = (typeof TOOL_TAGS)[number];\n\n/** Tags allowed on `enable_tools`, `disable_tools`, and `preload_tools`. */\nexport const TOOLS_SELECTOR_TAGS = [TOOL_TAG_ALL, TOOL_TAG_READ_ONLY] as const;\n\n/** Tags allowed on `require_approval_for_tools`. */\nexport const REQUIRE_APPROVAL_TOOLS_SELECTOR_TAGS = [TOOL_TAG_ALL, TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE] as const;\n\nexport const DEFAULT_ENABLE_TOOLS: string[] = [TOOL_TAG_ALL];\nexport const DEFAULT_DISABLE_TOOLS: string[] = [];\nexport const DEFAULT_PRELOAD_TOOLS: string[] = [];\nexport const DEFAULT_REQUIRE_APPROVAL_FOR_TOOLS: string[] = [TOOL_TAG_WRITE, TOOL_TAG_DESTRUCTIVE];\n\nfunction isToolTag(selector: string): selector is ToolTag {\n return TOOL_TAGS.includes(selector as ToolTag);\n}\n\nfunction isReadOnly(annotations?: ToolAnnotations): boolean {\n return annotations?.readOnlyHint === true;\n}\n\nfunction isWrite(annotations?: ToolAnnotations): boolean {\n return annotations?.readOnlyHint === false && annotations.destructiveHint !== true;\n}\n\nfunction isDestructive(annotations?: ToolAnnotations): boolean {\n return annotations?.destructiveHint === true;\n}\n\nfunction toolMatchesTag(tag: ToolTag, annotations: ToolAnnotations | undefined): boolean {\n switch (tag) {\n case TOOL_TAG_ALL:\n return true;\n case TOOL_TAG_READ_ONLY:\n return isReadOnly(annotations);\n case TOOL_TAG_WRITE:\n return isWrite(annotations);\n case TOOL_TAG_DESTRUCTIVE:\n return isDestructive(annotations);\n }\n}\n\n/** True if the tool matches any selector (tag or literal name). */\nexport function toolMatchesAnySelector(\n toolName: string,\n annotations: ToolAnnotations | undefined,\n selectors: readonly string[] | undefined,\n): boolean {\n if (!selectors?.length) {\n return false;\n }\n\n for (const selector of selectors) {\n if (isToolTag(selector)) {\n if (toolMatchesTag(selector, annotations)) {\n return true;\n }\n } else if (selector === toolName) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Whether the tool requires human approval before execution.\n * Matches `@write`, `@destructive`, `@all`, or explicit tool names against annotations.\n * Unannotated tools are exempt unless named in `require_approval_for_tools` or covered by `@all`.\n */\nexport function toolRequiresApproval(\n toolName: string,\n annotations: ToolAnnotations | undefined,\n selectors: readonly string[] | undefined,\n): boolean {\n if (!selectors?.length) {\n return false;\n }\n return toolMatchesAnySelector(toolName, annotations, selectors);\n}\n\n/** True if the tool is enabled and not disabled. */\nexport function isToolAllowed(params: {\n toolName: string;\n annotations: ToolAnnotations | undefined;\n enableSelectors: readonly string[];\n disableSelectors: readonly string[];\n}): boolean {\n const { toolName, annotations, enableSelectors, disableSelectors } = params;\n if (!toolMatchesAnySelector(toolName, annotations, enableSelectors)) {\n return false;\n }\n if (toolMatchesAnySelector(toolName, annotations, disableSelectors)) {\n return false;\n }\n return true;\n}\n\n/** Non-tag names from a selector list (for upfront validation / sandbox allow-lists). */\nexport function literalToolNames(selectors: readonly string[] | undefined): string[] {\n if (!selectors) {\n return [];\n }\n return selectors.filter(s => !isToolTag(s));\n}\n\nexport function selectorsIncludeAll(selectors: readonly string[] | undefined): boolean {\n return !!selectors?.includes(TOOL_TAG_ALL);\n}\n"],"mappings":";AAUA,IAAM,eAAe;AACrB,IAAM,qBAAqB;AAC3B,IAAM,iBAAiB;AACvB,IAAM,uBAAuB;AAE7B,IAAM,YAAY,CAAC,cAAc,oBAAoB,gBAAgB,oBAAoB;AAIlF,IAAM,sBAAsB,CAAC,cAAc,kBAAkB;AAG7D,IAAM,uCAAuC,CAAC,cAAc,gBAAgB,oBAAoB;AAEhG,IAAM,uBAAiC,CAAC,YAAY;AACpD,IAAM,wBAAkC,CAAC;AACzC,IAAM,wBAAkC,CAAC;AACzC,IAAM,qCAA+C,CAAC,gBAAgB,oBAAoB;AAEjG,SAAS,UAAU,UAAuC;AACxD,SAAO,UAAU,SAAS,QAAmB;AAC/C;AAEA,SAAS,WAAW,aAAwC;AAC1D,SAAO,aAAa,iBAAiB;AACvC;AAEA,SAAS,QAAQ,aAAwC;AACvD,SAAO,aAAa,iBAAiB,SAAS,YAAY,oBAAoB;AAChF;AAEA,SAAS,cAAc,aAAwC;AAC7D,SAAO,aAAa,oBAAoB;AAC1C;AAEA,SAAS,eAAe,KAAc,aAAmD;AACvF,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,WAAW,WAAW;AAAA,IAC/B,KAAK;AACH,aAAO,QAAQ,WAAW;AAAA,IAC5B,KAAK;AACH,aAAO,cAAc,WAAW;AAAA,EACpC;AACF;AAGO,SAAS,uBACd,UACA,aACA,WACS;AACT,MAAI,CAAC,WAAW,QAAQ;AACtB,WAAO;AAAA,EACT;AAEA,aAAW,YAAY,WAAW;AAChC,QAAI,UAAU,QAAQ,GAAG;AACvB,UAAI,eAAe,UAAU,WAAW,GAAG;AACzC,eAAO;AAAA,MACT;AAAA,IACF,WAAW,aAAa,UAAU;AAChC,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAOO,SAAS,qBACd,UACA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,OAAO,CAAE,eAAe;IAiCxB,OAAO,CAAE,gBAAgB;IAgBzB,OAAO,CAAC,kBAAkB;IAmBnB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEpD;IAIM,mBAAmB,IAAI,OAAO,CAIpC;IAIM,iBAAiB,CAAC,QAAQ,EAAE,2BAA2B,GAAG,IAAI,CAEpE;IAEM,UAAU,IAAI,mBAAmB,CAWvC;IAEM,qBAAqB,IAAI,kBAAkB,CAEjD;IAED,OAAO,CAAC,qBAAqB;IAiD7B,OAAO,CAAC,4BAA4B;IAiDpC,OAAO,CAAC,wBAAwB;YAsFlB,IAAI;YAUJ,SAAS;IAsBvB,OAAO,CAAC,iBAAiB;YAOV,WAAW;YAuIX,gBAAgB;IAmH/B,OAAO,CAAE,qBAAqB;IA2B9B,OAAO,CAAC,gBAAgB;IAaV,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9B,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;KAClC,GAAG,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,OAAO,CAAC,CAoGlD;CACF"}
@@ -57,7 +57,9 @@ function assertValidTransition(from, to) {
57
57
  }
58
58
  function deriveAgentThreadState(context) {
59
59
  const openToolCallIds = getOpenToolCallIds(context);
60
- if (openToolCallIds.size === 0) return "llm-call-required";
60
+ if (openToolCallIds.size === 0) {
61
+ return "llm-call-required";
62
+ }
61
63
  const assistant = lastAssistantInContext(context);
62
64
  const decisions = (0, import_contextUtils.scanApprovalDecisions)(context);
63
65
  const hasPendingApproval = assistant?.tool_calls?.some(
@@ -76,15 +78,23 @@ function getOpenToolCallIds(context) {
76
78
  const openToolCallIds = /* @__PURE__ */ new Set();
77
79
  for (let i = context.length - 1; i >= 0; i--) {
78
80
  const msg = context[i];
79
- if (msg === void 0) continue;
80
- if (!(0, import_contextUtils.isLLMContextMessage)(msg)) continue;
81
+ if (msg === void 0) {
82
+ continue;
83
+ }
84
+ if (!(0, import_contextUtils.isLLMContextMessage)(msg)) {
85
+ continue;
86
+ }
81
87
  if (msg.role === "tool") {
82
88
  resolvedToolCallIds.add(msg.tool_call_id);
83
89
  continue;
84
90
  }
85
91
  if (msg.role === "assistant") {
86
- for (const tc of msg.tool_calls ?? []) openToolCallIds.add(tc.id);
87
- for (const id of resolvedToolCallIds) openToolCallIds.delete(id);
92
+ for (const tc of msg.tool_calls ?? []) {
93
+ openToolCallIds.add(tc.id);
94
+ }
95
+ for (const id of resolvedToolCallIds) {
96
+ openToolCallIds.delete(id);
97
+ }
88
98
  break;
89
99
  }
90
100
  }
@@ -196,7 +206,9 @@ function validateInputMessageTypesGivenContext(context, messages) {
196
206
  const pendingClientSideIds = new Set(getPendingClientSideToolCalls(context).map((tc) => tc.id));
197
207
  for (let i = 0; i < messages.length; i++) {
198
208
  const m = messages[i];
199
- if (m === void 0) continue;
209
+ if (m === void 0) {
210
+ continue;
211
+ }
200
212
  if ((0, import_contextUtils.isApprovalDecisionMessage)(m)) {
201
213
  validateApprovalMessage(m, pendingApprovalIds, i);
202
214
  pendingApprovalIds.delete(m.tool_call_id);
@@ -299,7 +311,9 @@ function isJsonObject(value) {
299
311
  return typeof value === "object" && value !== null && !Array.isArray(value);
300
312
  }
301
313
  function tryParseToolArgs(args) {
302
- if (!args) return {};
314
+ if (!args) {
315
+ return {};
316
+ }
303
317
  try {
304
318
  const parsed = JSON.parse(args);
305
319
  return isJsonObject(parsed) ? parsed : {};
@@ -366,7 +380,9 @@ var AgentThread = class {
366
380
  capabilities.map((c) => c.state?.key).filter((k) => typeof k === "string")
367
381
  );
368
382
  for (const capability of capabilities) {
369
- if (!capability.state) continue;
383
+ if (!capability.state) {
384
+ continue;
385
+ }
370
386
  const value = claimed[capability.state.key];
371
387
  if (value !== void 0) {
372
388
  capability.state.load(value);
@@ -378,9 +394,6 @@ var AgentThread = class {
378
394
  logger: input.logger
379
395
  });
380
396
  }
381
- if (this.sandbox) {
382
- this.sandbox.configureCodeMode(this.definition.toolSets ?? []);
383
- }
384
397
  this.instruction = this.buildInstruction(this.definition.instruction);
385
398
  }
386
399
  buildInstruction(userInstruction) {
@@ -990,14 +1003,18 @@ var AgentThread = class {
990
1003
  for (; ; ) {
991
1004
  for (; ; ) {
992
1005
  const sandboxCreatedEvent = this.pendingSandboxCreatedEvents.shift();
993
- if (sandboxCreatedEvent === void 0) break;
1006
+ if (sandboxCreatedEvent === void 0) {
1007
+ break;
1008
+ }
994
1009
  yield sandboxCreatedEvent;
995
1010
  }
996
1011
  const state = this.deriveState();
997
1012
  let outcome;
998
1013
  switch (state) {
999
1014
  case "llm-call-required": {
1000
- if (signal?.aborted) return;
1015
+ if (signal?.aborted) {
1016
+ return;
1017
+ }
1001
1018
  if (this.metrics.iterations >= iterationLimit) {
1002
1019
  yield this.generateErrorEvent(
1003
1020
  `You have reached iteration limit of ${String(iterationLimit)}, please request again`
@@ -1011,7 +1028,9 @@ var AgentThread = class {
1011
1028
  break;
1012
1029
  }
1013
1030
  case "tool-response-required": {
1014
- if (signal?.aborted) return;
1031
+ if (signal?.aborted) {
1032
+ return;
1033
+ }
1015
1034
  outcome = yield* this.stepToolResponse(toolMapping);
1016
1035
  break;
1017
1036
  }
@@ -1023,7 +1042,9 @@ var AgentThread = class {
1023
1042
  throw new Error("unreachable");
1024
1043
  }
1025
1044
  }
1026
- if (outcome === "exit") return;
1045
+ if (outcome === "exit") {
1046
+ return;
1047
+ }
1027
1048
  }
1028
1049
  } catch (error) {
1029
1050
  this.logger.error("Agent thread execution failed", (0, import_errorLogFields.extractErrorLogFields)(error));
@@ -1037,7 +1058,9 @@ function assertUniqueStateKeys(capabilities) {
1037
1058
  const seen = /* @__PURE__ */ new Set();
1038
1059
  for (const capability of capabilities) {
1039
1060
  const key = capability.state?.key;
1040
- if (!key) continue;
1061
+ if (!key) {
1062
+ continue;
1063
+ }
1041
1064
  if (seen.has(key)) {
1042
1065
  throw new import_errors.AgentHarnessError(
1043
1066
  "capability_state_error",
@@ -1048,7 +1071,9 @@ function assertUniqueStateKeys(capabilities) {
1048
1071
  }
1049
1072
  }
1050
1073
  function claimCapabilityState(capabilities, input, logger) {
1051
- if (!input) return {};
1074
+ if (!input) {
1075
+ return {};
1076
+ }
1052
1077
  const claimedKeys = new Set(capabilities.map((c) => c.state?.key).filter((k) => typeof k === "string"));
1053
1078
  const claimed = {};
1054
1079
  for (const [key, value] of Object.entries(input)) {