agents 0.12.4 → 0.13.1
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.
- package/README.md +8 -8
- package/dist/{agent-tool-types-CM_50fcV.d.ts → agent-tool-types-Dn9n-3SI.d.ts} +234 -85
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-BylX6WXG.d.ts → agent-tools-B1ttU-pq.d.ts} +2 -2
- package/dist/agent-tools-BAdX1vdI.js.map +1 -1
- package/dist/agent-tools.d.ts +1 -1
- package/dist/agent-tools.js.map +1 -1
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration.js.map +1 -1
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.js.map +1 -1
- package/dist/browser/ai.js +1 -1
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/tanstack-ai.js +1 -1
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/chat/index.d.ts +2 -2
- package/dist/chat/index.js.map +1 -1
- package/dist/{classPrivateFieldGet2-CS51BNGR.js → classPrivateFieldGet2-Evpt0SEr.js} +5 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/client-D1kFXo80.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js.map +1 -1
- package/dist/codemode/ai.js.map +1 -1
- package/dist/{compaction-helpers-bYvP1o2S.d.ts → compaction-helpers-DAe-xiVY.d.ts} +33 -15
- package/dist/compaction-helpers-DvcZnvQ1.js.map +1 -1
- package/dist/email.d.ts +1 -1
- package/dist/email.js.map +1 -1
- package/dist/experimental/memory/session/index.d.ts +247 -34
- package/dist/experimental/memory/session/index.js +540 -135
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/experimental/memory/utils/index.d.ts +1 -1
- package/dist/experimental/memory/utils/index.js.map +1 -1
- package/dist/experimental/webmcp.js.map +1 -1
- package/dist/index.d.ts +71 -57
- package/dist/index.js +583 -45
- package/dist/index.js.map +1 -1
- package/dist/internal_context.js.map +1 -1
- package/dist/mcp/client.d.ts +12 -12
- package/dist/mcp/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/index.d.ts +40 -40
- package/dist/mcp/index.js +21 -45
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/x402.js.map +1 -1
- package/dist/observability/index.js.map +1 -1
- package/dist/react.d.ts +3 -3
- package/dist/react.js.map +1 -1
- package/dist/retries.js.map +1 -1
- package/dist/schedule.js.map +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/{shared-DzJYHisH.js → shared-CiKaIK4h.js} +4 -5
- package/dist/{shared-DzJYHisH.js.map → shared-CiKaIK4h.js.map} +1 -1
- package/dist/sub-routing.d.ts +6 -6
- package/dist/sub-routing.js.map +1 -1
- package/dist/tool-output-truncation-CH-khbZ3.js.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.js.map +1 -1
- package/dist/vite.js.map +1 -1
- package/dist/workflow-types.js.map +1 -1
- package/dist/workflows.d.ts +1 -1
- package/dist/workflows.js.map +1 -1
- package/package.json +6 -6
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
s as computeSummaryBudget,
|
|
12
12
|
t as COMPACTION_PREFIX,
|
|
13
13
|
u as isCompactionMessage
|
|
14
|
-
} from "../../../compaction-helpers-
|
|
14
|
+
} from "../../../compaction-helpers-DAe-xiVY.js";
|
|
15
15
|
|
|
16
16
|
//#region src/experimental/memory/utils/tokens.d.ts
|
|
17
17
|
/** Approximate characters per token for English text */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/experimental/memory/utils/compaction.ts"],"sourcesContent":["/**\n * Read-time context truncation.\n *\n * Truncates older tool outputs and long text before sending to the LLM.\n * Structured tool outputs keep their container shape so tool-specific\n * `toModelOutput` handlers can safely replay older results.\n * Does NOT mutate stored messages — operates on a copy.\n */\n\nimport { truncateToolOutput } from \"../../../chat/tool-output-truncation\";\nimport type { SessionMessage } from \"../session/types\";\n\nexport interface TruncateOptions {\n /** Number of recent messages to keep intact (default: 4) */\n keepRecent?: number;\n /** Max chars for tool outputs in older messages (default: 500) */\n maxToolOutputChars?: number;\n /** Max chars for text parts in older messages (default: 10000) */\n maxTextChars?: number;\n}\n\n/**\n * Truncate tool outputs and long text in older messages.\n * Returns a new array — input messages are not mutated.\n *\n * Recent messages (last `keepRecent`) are left intact.\n * Older messages get tool outputs and long text truncated. Structured tool\n * outputs are truncated in place instead of being replaced by raw strings.\n *\n * Use in assembleContext() before sending to the LLM:\n * ```typescript\n * async assembleContext() {\n * const history = this.sessions.getHistory(this._sessionId);\n * const truncated = truncateOlderMessages(history);\n * return convertToModelMessages(truncated);\n * }\n * ```\n */\nexport function truncateOlderMessages(\n messages: SessionMessage[],\n options?: TruncateOptions\n): SessionMessage[] {\n const keepRecent = options?.keepRecent ?? 4;\n const maxToolOutput = options?.maxToolOutputChars ?? 500;\n const maxText = options?.maxTextChars ?? 10000;\n\n if (messages.length <= keepRecent) return messages;\n\n const cutoff = messages.length - keepRecent;\n const result: SessionMessage[] = [];\n\n for (let i = 0; i < messages.length; i++) {\n if (i >= cutoff) {\n result.push(messages[i]);\n continue;\n }\n\n const msg = messages[i];\n let changed = false;\n\n const truncatedParts = msg.parts.map((part) => {\n // Truncate tool outputs\n if (\n (part.type.startsWith(\"tool-\") || part.type === \"dynamic-tool\") &&\n \"output\" in part\n ) {\n const output = (part as { output?: unknown }).output;\n if (output !== undefined) {\n const truncated = truncateToolOutput(output, maxToolOutput);\n if (truncated.truncated) {\n changed = true;\n return {\n ...part,\n output: truncated.output\n };\n }\n }\n }\n\n // Truncate long text\n if (part.type === \"text\" && \"text\" in part) {\n const text = (part as { text: string }).text;\n if (text.length > maxText) {\n changed = true;\n return {\n ...part,\n text: `${text.slice(0, maxText)}... [truncated ${text.length} chars]`\n };\n }\n }\n\n return part;\n });\n\n result.push(\n changed ? ({ ...msg, parts: truncatedParts } as SessionMessage) : msg\n );\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,sBACd,UACA,SACkB;CAClB,MAAM,aAAa,SAAS,cAAc;CAC1C,MAAM,gBAAgB,SAAS,sBAAsB;CACrD,MAAM,UAAU,SAAS,gBAAgB;CAEzC,IAAI,SAAS,UAAU,YAAY,OAAO;CAE1C,MAAM,SAAS,SAAS,SAAS;CACjC,MAAM,SAA2B,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/experimental/memory/utils/compaction.ts"],"sourcesContent":["/**\n * Read-time context truncation.\n *\n * Truncates older tool outputs and long text before sending to the LLM.\n * Structured tool outputs keep their container shape so tool-specific\n * `toModelOutput` handlers can safely replay older results.\n * Does NOT mutate stored messages — operates on a copy.\n */\n\nimport { truncateToolOutput } from \"../../../chat/tool-output-truncation\";\nimport type { SessionMessage } from \"../session/types\";\n\nexport interface TruncateOptions {\n /** Number of recent messages to keep intact (default: 4) */\n keepRecent?: number;\n /** Max chars for tool outputs in older messages (default: 500) */\n maxToolOutputChars?: number;\n /** Max chars for text parts in older messages (default: 10000) */\n maxTextChars?: number;\n}\n\n/**\n * Truncate tool outputs and long text in older messages.\n * Returns a new array — input messages are not mutated.\n *\n * Recent messages (last `keepRecent`) are left intact.\n * Older messages get tool outputs and long text truncated. Structured tool\n * outputs are truncated in place instead of being replaced by raw strings.\n *\n * Use in assembleContext() before sending to the LLM:\n * ```typescript\n * async assembleContext() {\n * const history = this.sessions.getHistory(this._sessionId);\n * const truncated = truncateOlderMessages(history);\n * return convertToModelMessages(truncated);\n * }\n * ```\n */\nexport function truncateOlderMessages(\n messages: SessionMessage[],\n options?: TruncateOptions\n): SessionMessage[] {\n const keepRecent = options?.keepRecent ?? 4;\n const maxToolOutput = options?.maxToolOutputChars ?? 500;\n const maxText = options?.maxTextChars ?? 10000;\n\n if (messages.length <= keepRecent) return messages;\n\n const cutoff = messages.length - keepRecent;\n const result: SessionMessage[] = [];\n\n for (let i = 0; i < messages.length; i++) {\n if (i >= cutoff) {\n result.push(messages[i]);\n continue;\n }\n\n const msg = messages[i];\n let changed = false;\n\n const truncatedParts = msg.parts.map((part) => {\n // Truncate tool outputs\n if (\n (part.type.startsWith(\"tool-\") || part.type === \"dynamic-tool\") &&\n \"output\" in part\n ) {\n const output = (part as { output?: unknown }).output;\n if (output !== undefined) {\n const truncated = truncateToolOutput(output, maxToolOutput);\n if (truncated.truncated) {\n changed = true;\n return {\n ...part,\n output: truncated.output\n };\n }\n }\n }\n\n // Truncate long text\n if (part.type === \"text\" && \"text\" in part) {\n const text = (part as { text: string }).text;\n if (text.length > maxText) {\n changed = true;\n return {\n ...part,\n text: `${text.slice(0, maxText)}... [truncated ${text.length} chars]`\n };\n }\n }\n\n return part;\n });\n\n result.push(\n changed ? ({ ...msg, parts: truncatedParts } as SessionMessage) : msg\n );\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,sBACd,UACA,SACkB;CAClB,MAAM,aAAa,SAAS,cAAc;CAC1C,MAAM,gBAAgB,SAAS,sBAAsB;CACrD,MAAM,UAAU,SAAS,gBAAgB;CAEzC,IAAI,SAAS,UAAU,YAAY,OAAO;CAE1C,MAAM,SAAS,SAAS,SAAS;CACjC,MAAM,SAA2B,CAAC;CAElC,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACxC,IAAI,KAAK,QAAQ;GACf,OAAO,KAAK,SAAS,EAAE;GACvB;EACF;EAEA,MAAM,MAAM,SAAS;EACrB,IAAI,UAAU;EAEd,MAAM,iBAAiB,IAAI,MAAM,KAAK,SAAS;GAE7C,KACG,KAAK,KAAK,WAAW,OAAO,KAAK,KAAK,SAAS,mBAChD,YAAY,MACZ;IACA,MAAM,SAAU,KAA8B;IAC9C,IAAI,WAAW,KAAA,GAAW;KACxB,MAAM,YAAY,mBAAmB,QAAQ,aAAa;KAC1D,IAAI,UAAU,WAAW;MACvB,UAAU;MACV,OAAO;OACL,GAAG;OACH,QAAQ,UAAU;MACpB;KACF;IACF;GACF;GAGA,IAAI,KAAK,SAAS,UAAU,UAAU,MAAM;IAC1C,MAAM,OAAQ,KAA0B;IACxC,IAAI,KAAK,SAAS,SAAS;KACzB,UAAU;KACV,OAAO;MACL,GAAG;MACH,MAAM,GAAG,KAAK,MAAM,GAAG,OAAO,EAAE,iBAAiB,KAAK,OAAO;KAC/D;IACF;GACF;GAEA,OAAO;EACT,CAAC;EAED,OAAO,KACL,UAAW;GAAE,GAAG;GAAK,OAAO;EAAe,IAAuB,GACpE;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webmcp.js","names":[],"sources":["../../src/experimental/webmcp.ts"],"sourcesContent":["/**\n * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n * !! WARNING: EXPERIMENTAL — DO NOT USE IN PRODUCTION !!\n * !! !!\n * !! This API is under active development and WILL break between !!\n * !! releases. Google's WebMCP API (navigator.modelContext) is still !!\n * !! in early preview and subject to change. !!\n * !! !!\n * !! If you use this, pin your agents version and expect to rewrite !!\n * !! your code when upgrading. !!\n * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n *\n * WebMCP adapter for Cloudflare Agents SDK.\n *\n * Bridges tools registered on an McpAgent server to Chrome's native\n * navigator.modelContext API, so browser-native agents can discover\n * and call them without extra infrastructure.\n *\n * @example Bridge a remote McpAgent endpoint into the page\n * ```ts\n * import { registerWebMcp } from \"agents/experimental/webmcp\";\n *\n * const handle = await registerWebMcp({ url: \"/mcp\" });\n *\n * // Later, to clean up:\n * await handle.dispose();\n * ```\n *\n * @example Mix in-page tools with bridged tools (recommended pattern)\n * ```ts\n * import { registerWebMcp } from \"agents/experimental/webmcp\";\n *\n * // 1. Register page-local tools — things only the page can do\n * navigator.modelContext?.registerTool({\n * name: \"scroll_to_section\",\n * description: \"Scroll the page to a named section\",\n * inputSchema: {\n * type: \"object\",\n * properties: { id: { type: \"string\" } },\n * required: [\"id\"]\n * },\n * async execute({ id }) {\n * document.getElementById(String(id))?.scrollIntoView({ behavior: \"smooth\" });\n * return \"ok\";\n * }\n * });\n *\n * // 2. Bridge server tools — things that need durable storage / auth / DB access\n * const handle = await registerWebMcp({\n * url: \"/mcp\",\n * prefix: \"remote.\", // optional namespace to avoid collisions\n * getHeaders: async () => ({ Authorization: `Bearer ${await getToken()}` })\n * });\n *\n * // The browser AI sees both kinds of tools side by side.\n * ```\n *\n * @experimental This API is not yet stable and may change.\n */\n\nimport { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport { ToolListChangedNotificationSchema } from \"@modelcontextprotocol/sdk/types.js\";\n\n// ── WebMCP browser API surface (Chrome's navigator.modelContext) ─────\n\ninterface ModelContextToolAnnotations {\n readOnlyHint?: boolean;\n}\n\ninterface ModelContextClient {\n requestUserInteraction(callback: () => Promise<unknown>): Promise<unknown>;\n}\n\ninterface ModelContextTool {\n name: string;\n description: string;\n inputSchema?: Record<string, unknown>;\n execute: (\n input: Record<string, unknown>,\n client: ModelContextClient\n ) => Promise<unknown>;\n annotations?: ModelContextToolAnnotations;\n}\n\ninterface ModelContextRegisterToolOptions {\n signal?: AbortSignal;\n}\n\ninterface ModelContext {\n registerTool(\n tool: ModelContextTool,\n options?: ModelContextRegisterToolOptions\n ): void;\n}\n\ndeclare global {\n interface Navigator {\n modelContext?: ModelContext;\n }\n}\n\n// ── Internal types ───────────────────────────────────────────────────\n\ninterface McpTool {\n name: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n annotations?: { readOnlyHint?: boolean };\n}\n\ninterface McpToolCallResult {\n content: Array<{\n type: string;\n text?: string;\n data?: string;\n mimeType?: string;\n }>;\n isError?: boolean;\n}\n\n/**\n * Logger interface for adapter diagnostics. Defaults to `console`.\n * Pass a no-op implementation (or `quiet: true`) to silence output.\n */\nexport interface WebMcpLogger {\n info(...args: unknown[]): void;\n warn(...args: unknown[]): void;\n error(...args: unknown[]): void;\n}\n\nconst DEFAULT_LOGGER: WebMcpLogger = {\n info: (...args) => console.info(\"[webmcp-adapter]\", ...args),\n warn: (...args) => console.warn(\"[webmcp-adapter]\", ...args),\n error: (...args) => console.error(\"[webmcp-adapter]\", ...args)\n};\n\nconst SILENT_LOGGER: WebMcpLogger = {\n info: () => {},\n warn: () => {},\n error: () => {}\n};\n\n// ── MCP transport wrapper ────────────────────────────────────────────\n\nclass McpHttpClient {\n private _client: Client;\n private _transport: StreamableHTTPClientTransport;\n private _onToolsChanged?: () => void;\n private _timeoutMs?: number;\n\n constructor(\n url: string,\n headers?: Record<string, string>,\n getHeaders?: () => Promise<Record<string, string>> | Record<string, string>,\n timeoutMs?: number\n ) {\n const resolvedUrl = new URL(url, globalThis.location?.origin);\n this._timeoutMs = timeoutMs;\n\n const transportOptions: ConstructorParameters<\n typeof StreamableHTTPClientTransport\n >[1] = {\n requestInit: { headers: headers ?? {} }\n };\n\n if (getHeaders) {\n transportOptions.fetch = async (input, init) => {\n const dynamic = await getHeaders();\n const merged = new Headers(init?.headers);\n for (const [k, v] of Object.entries(dynamic)) {\n merged.set(k, v);\n }\n return globalThis.fetch(input, {\n ...init,\n headers: merged\n });\n };\n }\n\n this._transport = new StreamableHTTPClientTransport(\n resolvedUrl,\n transportOptions\n );\n\n this._client = new Client(\n { name: \"webmcp-adapter\", version: \"0.1.0\" },\n { capabilities: {} }\n );\n }\n\n async initialize(signal?: AbortSignal): Promise<void> {\n await this._client.connect(this._transport);\n\n this._client.setNotificationHandler(\n ToolListChangedNotificationSchema,\n async () => {\n if (signal?.aborted) return;\n this._onToolsChanged?.();\n }\n );\n }\n\n async listTools(signal?: AbortSignal): Promise<McpTool[]> {\n const allTools: McpTool[] = [];\n let cursor: string | undefined;\n do {\n if (signal?.aborted) throw new DOMException(\"Aborted\", \"AbortError\");\n const result = await this._client.listTools(\n cursor ? { cursor } : undefined,\n { signal, timeout: this._timeoutMs }\n );\n for (const t of result.tools) {\n allTools.push({\n name: t.name,\n description: t.description,\n inputSchema: t.inputSchema as Record<string, unknown> | undefined,\n annotations: t.annotations\n ? { readOnlyHint: t.annotations.readOnlyHint }\n : undefined\n });\n }\n cursor = result.nextCursor;\n } while (cursor);\n return allTools;\n }\n\n async callTool(\n name: string,\n args: Record<string, unknown>,\n signal?: AbortSignal\n ): Promise<McpToolCallResult> {\n const result = await this._client.callTool(\n { name, arguments: args },\n undefined,\n { signal, timeout: this._timeoutMs }\n );\n if (\"content\" in result) {\n return {\n content: (\n result.content as Array<{\n type: string;\n text?: string;\n data?: string;\n }>\n ).map((c) => ({\n type: c.type,\n text: \"text\" in c ? (c.text as string) : undefined,\n data: \"data\" in c ? (c.data as string) : undefined,\n mimeType: \"mimeType\" in c ? (c.mimeType as string) : undefined\n })),\n isError: \"isError\" in result ? (result.isError as boolean) : false\n };\n }\n return { content: [], isError: false };\n }\n\n listenForChanges(onToolsChanged: () => void): void {\n this._onToolsChanged = onToolsChanged;\n }\n\n async close(): Promise<void> {\n try {\n await this._client.close();\n } catch {\n // Closing a never-connected or already-closed client is fine.\n }\n }\n}\n\n// ── Public API ───────────────────────────────────────────────────────\n\nexport interface WebMcpOptions {\n /** URL of the MCP endpoint (absolute or relative, e.g. `\"/mcp\"`). */\n url: string;\n /**\n * Additional headers to include in every request to the MCP server.\n * Useful for static authentication (e.g. `{ Authorization: \"Bearer <token>\" }`).\n */\n headers?: Record<string, string>;\n /**\n * Async function that returns headers for each request.\n * Called before every request, useful for tokens that refresh.\n * If both `headers` and `getHeaders` are provided, they are merged\n * with `getHeaders` values taking precedence.\n */\n getHeaders?: () => Promise<Record<string, string>> | Record<string, string>;\n /**\n * If true, listen for `tools/list_changed` notifications and re-sync\n * tools with `navigator.modelContext`. The adapter opens an SSE GET to\n * the MCP endpoint to receive notifications; servers that don't support\n * server-initiated streams (e.g. respond `405` on GET) gracefully degrade.\n * @default true\n */\n watch?: boolean;\n /**\n * Optional namespace prefix prepended to every tool name registered with\n * `navigator.modelContext`. Useful when bridging multiple MCP servers, or\n * when the page also registers in-page tools and you want to avoid\n * collisions. The original (unprefixed) name is still used on the wire\n * when calling the server.\n *\n * @example `prefix: \"remote.\"` turns `search` into `remote.search`.\n */\n prefix?: string;\n /**\n * Per-request timeout (in milliseconds) applied to `tools/list` and\n * `tools/call`. If the server doesn't respond in time, the request is\n * aborted and the resulting error is surfaced through the normal error\n * paths (`onError` for sync, rejection for tool execution).\n */\n timeoutMs?: number;\n /**\n * Custom logger. Defaults to `console` with a `[webmcp-adapter]` prefix.\n * Pass `{ info: () => {}, warn: () => {}, error: () => {} }` to silence.\n */\n logger?: WebMcpLogger;\n /** Convenience shortcut for `logger: SILENT_LOGGER`. @default false */\n quiet?: boolean;\n /**\n * Called whenever the adapter performs a successful sync (initial load\n * and on `tools/list_changed`). Receives the tools as the server returned\n * them (with their original, unprefixed names).\n */\n onSync?: (tools: McpTool[]) => void;\n /**\n * Called when an error occurs during background work that the caller\n * cannot otherwise observe — specifically: a watch-mode re-sync failure.\n *\n * **Not** called for:\n * - Initialization failures (those reject the `registerWebMcp` promise).\n * - Per-tool execution failures (those reject the `execute` promise the\n * browser host awaits; Chrome surfaces them to the AI).\n */\n onError?: (error: Error) => void;\n}\n\nexport interface WebMcpHandle {\n /**\n * Currently registered tool names (with `prefix` applied). Returns a fresh\n * snapshot on each access — safe to mutate.\n */\n readonly tools: ReadonlyArray<string>;\n /**\n * Re-fetch the tool list from the server and re-register everything.\n * If a sync is already in flight (from a `tools/list_changed` notification\n * or a previous `refresh()` call), returns the in-flight promise rather\n * than starting a second sync.\n */\n refresh(): Promise<void>;\n /**\n * Unregister all tools, signal any in-flight work to abort, and close the\n * MCP connection. Safe to call multiple times.\n */\n dispose(): Promise<void>;\n /** True after `dispose()` has been called at least once. */\n readonly disposed: boolean;\n}\n\n/**\n * Discovers tools from a Cloudflare McpAgent endpoint and registers them\n * with Chrome's native `navigator.modelContext` API.\n *\n * On browsers without `navigator.modelContext` (everything except recent\n * Chrome with the relevant flags), this function is a no-op and returns a\n * handle with an empty tools array. No network request is made.\n *\n * @example\n * ```ts\n * import { registerWebMcp } from \"agents/experimental/webmcp\";\n *\n * const handle = await registerWebMcp({ url: \"/mcp\" });\n * console.log(\"Registered tools:\", handle.tools);\n *\n * // Clean up when done (e.g. in a React effect cleanup)\n * await handle.dispose();\n * ```\n *\n * See the JSDoc on the module itself for the recommended \"in-page tools +\n * remote tools\" composition pattern.\n */\nexport async function registerWebMcp(\n options: WebMcpOptions\n): Promise<WebMcpHandle> {\n const {\n url,\n headers,\n getHeaders,\n watch = true,\n prefix = \"\",\n timeoutMs,\n logger: userLogger,\n quiet = false,\n onSync,\n onError\n } = options;\n\n const logger = quiet ? SILENT_LOGGER : (userLogger ?? DEFAULT_LOGGER);\n\n const registeredTools: string[] = [];\n const toolControllers = new Map<string, AbortController>();\n const lifecycleController = new AbortController();\n let disposed = false;\n let inflightSync: Promise<void> | null = null;\n\n if (!navigator.modelContext) {\n logger.info(\n \"navigator.modelContext not available — skipping registration. \" +\n \"This is expected on non-Chrome browsers.\"\n );\n onSync?.([]);\n return {\n get tools() {\n return [];\n },\n get disposed() {\n return disposed;\n },\n refresh: async () => {},\n dispose: async () => {\n disposed = true;\n }\n };\n }\n\n const modelContext: ModelContext = navigator.modelContext;\n const client = new McpHttpClient(url, headers, getHeaders, timeoutMs);\n\n function unregisterAll(): void {\n for (const controller of toolControllers.values()) {\n controller.abort();\n }\n toolControllers.clear();\n registeredTools.length = 0;\n }\n\n function registerTools(tools: McpTool[]): void {\n for (const tool of tools) {\n const registeredName = `${prefix}${tool.name}`;\n const toolDef: ModelContextTool = {\n name: registeredName,\n description: tool.description ?? tool.name,\n ...(tool.inputSchema ? { inputSchema: tool.inputSchema } : {}),\n ...(tool.annotations\n ? { annotations: { readOnlyHint: tool.annotations.readOnlyHint } }\n : {}),\n execute: async (input: Record<string, unknown>) => {\n if (disposed) {\n throw new Error(\"WebMCP adapter has been disposed\");\n }\n const result = await client.callTool(\n tool.name,\n input,\n lifecycleController.signal\n );\n\n if (result.isError) {\n const errorText = result.content\n .map((c) => c.text ?? \"\")\n .join(\"\\n\");\n throw new Error(errorText || \"Tool execution failed\");\n }\n\n const parts: string[] = [];\n let sawUnsupported = false;\n for (const c of result.content) {\n if (c.type === \"text\" && c.text) {\n parts.push(c.text);\n } else if (c.type === \"image\" && c.data) {\n parts.push(`data:${c.mimeType ?? \"image/png\"};base64,${c.data}`);\n } else if (c.data) {\n parts.push(c.data);\n sawUnsupported = true;\n } else {\n sawUnsupported = true;\n }\n }\n if (sawUnsupported) {\n logger.warn(\n `Tool \"${tool.name}\" returned content type(s) the adapter` +\n \" cannot fully represent as a string.\"\n );\n }\n return parts.join(\"\\n\");\n }\n };\n\n try {\n const controller = new AbortController();\n modelContext.registerTool(toolDef, { signal: controller.signal });\n toolControllers.set(registeredName, controller);\n registeredTools.push(registeredName);\n } catch (err) {\n logger.warn(`Failed to register tool \"${registeredName}\":`, err);\n }\n }\n }\n\n // Serialize syncs: if one is already running, share its promise. This\n // prevents the unregister/listTools/registerTools sequence from\n // interleaving when both `refresh()` and a `tools/list_changed`\n // notification fire concurrently.\n function syncTools(): Promise<void> {\n if (disposed) return Promise.resolve();\n if (inflightSync) return inflightSync;\n inflightSync = (async () => {\n try {\n const tools = await client.listTools(lifecycleController.signal);\n if (disposed) return;\n unregisterAll();\n registerTools(tools);\n onSync?.(tools);\n } finally {\n inflightSync = null;\n }\n })();\n return inflightSync;\n }\n\n try {\n await client.initialize(lifecycleController.signal);\n await syncTools();\n\n if (watch) {\n client.listenForChanges(() => {\n if (disposed) return;\n syncTools().catch((err: unknown) => {\n if (disposed) return;\n const error = err instanceof Error ? err : new Error(String(err));\n logger.warn(\"Watch-mode sync failed:\", error);\n onError?.(error);\n });\n });\n }\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n logger.error(\"Initialization failed:\", error);\n // Best-effort cleanup so a failed init doesn't leak the transport.\n await client.close();\n throw error;\n }\n\n return {\n get tools() {\n return [...registeredTools];\n },\n get disposed() {\n return disposed;\n },\n refresh: syncTools,\n async dispose() {\n if (disposed) return;\n disposed = true;\n lifecycleController.abort();\n unregisterAll();\n // Wait for any in-flight sync to settle so callers can rely on\n // a quiet adapter after `await handle.dispose()`.\n try {\n await inflightSync;\n } catch {\n // Already surfaced via onError or thrown to the original caller.\n }\n await client.close();\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmIA,MAAM,iBAA+B;CACnC,OAAO,GAAG,SAAS,QAAQ,KAAK,oBAAoB,GAAG,KAAK;CAC5D,OAAO,GAAG,SAAS,QAAQ,KAAK,oBAAoB,GAAG,KAAK;CAC5D,QAAQ,GAAG,SAAS,QAAQ,MAAM,oBAAoB,GAAG,KAAK;CAC/D;AAED,MAAM,gBAA8B;CAClC,YAAY;CACZ,YAAY;CACZ,aAAa;CACd;AAID,IAAM,gBAAN,MAAoB;CAMlB,YACE,KACA,SACA,YACA,WACA;EACA,MAAM,cAAc,IAAI,IAAI,KAAK,WAAW,UAAU,OAAO;EAC7D,KAAK,aAAa;EAElB,MAAM,mBAEC,EACL,aAAa,EAAE,SAAS,WAAW,EAAE,EAAE,EACxC;EAED,IAAI,YACF,iBAAiB,QAAQ,OAAO,OAAO,SAAS;GAC9C,MAAM,UAAU,MAAM,YAAY;GAClC,MAAM,SAAS,IAAI,QAAQ,MAAM,QAAQ;GACzC,KAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,QAAQ,EAC1C,OAAO,IAAI,GAAG,EAAE;GAElB,OAAO,WAAW,MAAM,OAAO;IAC7B,GAAG;IACH,SAAS;IACV,CAAC;;EAIN,KAAK,aAAa,IAAI,8BAC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AClC,IAAI,UAAU;IACd,MAAM,QAAQ,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,IAAI,CAAC;IACjE,OAAO,KAAK,2BAA2B,MAAM;IAC7C,UAAU,MAAM;KAChB;IACF;UAEG,KAAK;EACZ,MAAM,QAAQ,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,IAAI,CAAC;EACjE,OAAO,MAAM,0BAA0B,MAAM;EAE7C,MAAM,OAAO,OAAO;EACpB,MAAM;;CAGR,OAAO;EACL,IAAI,QAAQ;GACV,OAAO,CAAC,GAAG,gBAAgB;;EAE7B,IAAI,WAAW;GACb,OAAO;;EAET,SAAS;EACT,MAAM,UAAU;GACd,IAAI,UAAU;GACd,WAAW;GACX,oBAAoB,OAAO;GAC3B,eAAe;GAGf,IAAI;IACF,MAAM;WACA;GAGR,MAAM,OAAO,OAAO;;EAEvB"}
|
|
1
|
+
{"version":3,"file":"webmcp.js","names":[],"sources":["../../src/experimental/webmcp.ts"],"sourcesContent":["/**\n * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n * !! WARNING: EXPERIMENTAL — DO NOT USE IN PRODUCTION !!\n * !! !!\n * !! This API is under active development and WILL break between !!\n * !! releases. Google's WebMCP API (navigator.modelContext) is still !!\n * !! in early preview and subject to change. !!\n * !! !!\n * !! If you use this, pin your agents version and expect to rewrite !!\n * !! your code when upgrading. !!\n * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n *\n * WebMCP adapter for Cloudflare Agents SDK.\n *\n * Bridges tools registered on an McpAgent server to Chrome's native\n * navigator.modelContext API, so browser-native agents can discover\n * and call them without extra infrastructure.\n *\n * @example Bridge a remote McpAgent endpoint into the page\n * ```ts\n * import { registerWebMcp } from \"agents/experimental/webmcp\";\n *\n * const handle = await registerWebMcp({ url: \"/mcp\" });\n *\n * // Later, to clean up:\n * await handle.dispose();\n * ```\n *\n * @example Mix in-page tools with bridged tools (recommended pattern)\n * ```ts\n * import { registerWebMcp } from \"agents/experimental/webmcp\";\n *\n * // 1. Register page-local tools — things only the page can do\n * navigator.modelContext?.registerTool({\n * name: \"scroll_to_section\",\n * description: \"Scroll the page to a named section\",\n * inputSchema: {\n * type: \"object\",\n * properties: { id: { type: \"string\" } },\n * required: [\"id\"]\n * },\n * async execute({ id }) {\n * document.getElementById(String(id))?.scrollIntoView({ behavior: \"smooth\" });\n * return \"ok\";\n * }\n * });\n *\n * // 2. Bridge server tools — things that need durable storage / auth / DB access\n * const handle = await registerWebMcp({\n * url: \"/mcp\",\n * prefix: \"remote.\", // optional namespace to avoid collisions\n * getHeaders: async () => ({ Authorization: `Bearer ${await getToken()}` })\n * });\n *\n * // The browser AI sees both kinds of tools side by side.\n * ```\n *\n * @experimental This API is not yet stable and may change.\n */\n\nimport { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport { ToolListChangedNotificationSchema } from \"@modelcontextprotocol/sdk/types.js\";\n\n// ── WebMCP browser API surface (Chrome's navigator.modelContext) ─────\n\ninterface ModelContextToolAnnotations {\n readOnlyHint?: boolean;\n}\n\ninterface ModelContextClient {\n requestUserInteraction(callback: () => Promise<unknown>): Promise<unknown>;\n}\n\ninterface ModelContextTool {\n name: string;\n description: string;\n inputSchema?: Record<string, unknown>;\n execute: (\n input: Record<string, unknown>,\n client: ModelContextClient\n ) => Promise<unknown>;\n annotations?: ModelContextToolAnnotations;\n}\n\ninterface ModelContextRegisterToolOptions {\n signal?: AbortSignal;\n}\n\ninterface ModelContext {\n registerTool(\n tool: ModelContextTool,\n options?: ModelContextRegisterToolOptions\n ): void;\n}\n\ndeclare global {\n interface Navigator {\n modelContext?: ModelContext;\n }\n}\n\n// ── Internal types ───────────────────────────────────────────────────\n\ninterface McpTool {\n name: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n annotations?: { readOnlyHint?: boolean };\n}\n\ninterface McpToolCallResult {\n content: Array<{\n type: string;\n text?: string;\n data?: string;\n mimeType?: string;\n }>;\n isError?: boolean;\n}\n\n/**\n * Logger interface for adapter diagnostics. Defaults to `console`.\n * Pass a no-op implementation (or `quiet: true`) to silence output.\n */\nexport interface WebMcpLogger {\n info(...args: unknown[]): void;\n warn(...args: unknown[]): void;\n error(...args: unknown[]): void;\n}\n\nconst DEFAULT_LOGGER: WebMcpLogger = {\n info: (...args) => console.info(\"[webmcp-adapter]\", ...args),\n warn: (...args) => console.warn(\"[webmcp-adapter]\", ...args),\n error: (...args) => console.error(\"[webmcp-adapter]\", ...args)\n};\n\nconst SILENT_LOGGER: WebMcpLogger = {\n info: () => {},\n warn: () => {},\n error: () => {}\n};\n\n// ── MCP transport wrapper ────────────────────────────────────────────\n\nclass McpHttpClient {\n private _client: Client;\n private _transport: StreamableHTTPClientTransport;\n private _onToolsChanged?: () => void;\n private _timeoutMs?: number;\n\n constructor(\n url: string,\n headers?: Record<string, string>,\n getHeaders?: () => Promise<Record<string, string>> | Record<string, string>,\n timeoutMs?: number\n ) {\n const resolvedUrl = new URL(url, globalThis.location?.origin);\n this._timeoutMs = timeoutMs;\n\n const transportOptions: ConstructorParameters<\n typeof StreamableHTTPClientTransport\n >[1] = {\n requestInit: { headers: headers ?? {} }\n };\n\n if (getHeaders) {\n transportOptions.fetch = async (input, init) => {\n const dynamic = await getHeaders();\n const merged = new Headers(init?.headers);\n for (const [k, v] of Object.entries(dynamic)) {\n merged.set(k, v);\n }\n return globalThis.fetch(input, {\n ...init,\n headers: merged\n });\n };\n }\n\n this._transport = new StreamableHTTPClientTransport(\n resolvedUrl,\n transportOptions\n );\n\n this._client = new Client(\n { name: \"webmcp-adapter\", version: \"0.1.0\" },\n { capabilities: {} }\n );\n }\n\n async initialize(signal?: AbortSignal): Promise<void> {\n await this._client.connect(this._transport);\n\n this._client.setNotificationHandler(\n ToolListChangedNotificationSchema,\n async () => {\n if (signal?.aborted) return;\n this._onToolsChanged?.();\n }\n );\n }\n\n async listTools(signal?: AbortSignal): Promise<McpTool[]> {\n const allTools: McpTool[] = [];\n let cursor: string | undefined;\n do {\n if (signal?.aborted) throw new DOMException(\"Aborted\", \"AbortError\");\n const result = await this._client.listTools(\n cursor ? { cursor } : undefined,\n { signal, timeout: this._timeoutMs }\n );\n for (const t of result.tools) {\n allTools.push({\n name: t.name,\n description: t.description,\n inputSchema: t.inputSchema as Record<string, unknown> | undefined,\n annotations: t.annotations\n ? { readOnlyHint: t.annotations.readOnlyHint }\n : undefined\n });\n }\n cursor = result.nextCursor;\n } while (cursor);\n return allTools;\n }\n\n async callTool(\n name: string,\n args: Record<string, unknown>,\n signal?: AbortSignal\n ): Promise<McpToolCallResult> {\n const result = await this._client.callTool(\n { name, arguments: args },\n undefined,\n { signal, timeout: this._timeoutMs }\n );\n if (\"content\" in result) {\n return {\n content: (\n result.content as Array<{\n type: string;\n text?: string;\n data?: string;\n }>\n ).map((c) => ({\n type: c.type,\n text: \"text\" in c ? (c.text as string) : undefined,\n data: \"data\" in c ? (c.data as string) : undefined,\n mimeType: \"mimeType\" in c ? (c.mimeType as string) : undefined\n })),\n isError: \"isError\" in result ? (result.isError as boolean) : false\n };\n }\n return { content: [], isError: false };\n }\n\n listenForChanges(onToolsChanged: () => void): void {\n this._onToolsChanged = onToolsChanged;\n }\n\n async close(): Promise<void> {\n try {\n await this._client.close();\n } catch {\n // Closing a never-connected or already-closed client is fine.\n }\n }\n}\n\n// ── Public API ───────────────────────────────────────────────────────\n\nexport interface WebMcpOptions {\n /** URL of the MCP endpoint (absolute or relative, e.g. `\"/mcp\"`). */\n url: string;\n /**\n * Additional headers to include in every request to the MCP server.\n * Useful for static authentication (e.g. `{ Authorization: \"Bearer <token>\" }`).\n */\n headers?: Record<string, string>;\n /**\n * Async function that returns headers for each request.\n * Called before every request, useful for tokens that refresh.\n * If both `headers` and `getHeaders` are provided, they are merged\n * with `getHeaders` values taking precedence.\n */\n getHeaders?: () => Promise<Record<string, string>> | Record<string, string>;\n /**\n * If true, listen for `tools/list_changed` notifications and re-sync\n * tools with `navigator.modelContext`. The adapter opens an SSE GET to\n * the MCP endpoint to receive notifications; servers that don't support\n * server-initiated streams (e.g. respond `405` on GET) gracefully degrade.\n * @default true\n */\n watch?: boolean;\n /**\n * Optional namespace prefix prepended to every tool name registered with\n * `navigator.modelContext`. Useful when bridging multiple MCP servers, or\n * when the page also registers in-page tools and you want to avoid\n * collisions. The original (unprefixed) name is still used on the wire\n * when calling the server.\n *\n * @example `prefix: \"remote.\"` turns `search` into `remote.search`.\n */\n prefix?: string;\n /**\n * Per-request timeout (in milliseconds) applied to `tools/list` and\n * `tools/call`. If the server doesn't respond in time, the request is\n * aborted and the resulting error is surfaced through the normal error\n * paths (`onError` for sync, rejection for tool execution).\n */\n timeoutMs?: number;\n /**\n * Custom logger. Defaults to `console` with a `[webmcp-adapter]` prefix.\n * Pass `{ info: () => {}, warn: () => {}, error: () => {} }` to silence.\n */\n logger?: WebMcpLogger;\n /** Convenience shortcut for `logger: SILENT_LOGGER`. @default false */\n quiet?: boolean;\n /**\n * Called whenever the adapter performs a successful sync (initial load\n * and on `tools/list_changed`). Receives the tools as the server returned\n * them (with their original, unprefixed names).\n */\n onSync?: (tools: McpTool[]) => void;\n /**\n * Called when an error occurs during background work that the caller\n * cannot otherwise observe — specifically: a watch-mode re-sync failure.\n *\n * **Not** called for:\n * - Initialization failures (those reject the `registerWebMcp` promise).\n * - Per-tool execution failures (those reject the `execute` promise the\n * browser host awaits; Chrome surfaces them to the AI).\n */\n onError?: (error: Error) => void;\n}\n\nexport interface WebMcpHandle {\n /**\n * Currently registered tool names (with `prefix` applied). Returns a fresh\n * snapshot on each access — safe to mutate.\n */\n readonly tools: ReadonlyArray<string>;\n /**\n * Re-fetch the tool list from the server and re-register everything.\n * If a sync is already in flight (from a `tools/list_changed` notification\n * or a previous `refresh()` call), returns the in-flight promise rather\n * than starting a second sync.\n */\n refresh(): Promise<void>;\n /**\n * Unregister all tools, signal any in-flight work to abort, and close the\n * MCP connection. Safe to call multiple times.\n */\n dispose(): Promise<void>;\n /** True after `dispose()` has been called at least once. */\n readonly disposed: boolean;\n}\n\n/**\n * Discovers tools from a Cloudflare McpAgent endpoint and registers them\n * with Chrome's native `navigator.modelContext` API.\n *\n * On browsers without `navigator.modelContext` (everything except recent\n * Chrome with the relevant flags), this function is a no-op and returns a\n * handle with an empty tools array. No network request is made.\n *\n * @example\n * ```ts\n * import { registerWebMcp } from \"agents/experimental/webmcp\";\n *\n * const handle = await registerWebMcp({ url: \"/mcp\" });\n * console.log(\"Registered tools:\", handle.tools);\n *\n * // Clean up when done (e.g. in a React effect cleanup)\n * await handle.dispose();\n * ```\n *\n * See the JSDoc on the module itself for the recommended \"in-page tools +\n * remote tools\" composition pattern.\n */\nexport async function registerWebMcp(\n options: WebMcpOptions\n): Promise<WebMcpHandle> {\n const {\n url,\n headers,\n getHeaders,\n watch = true,\n prefix = \"\",\n timeoutMs,\n logger: userLogger,\n quiet = false,\n onSync,\n onError\n } = options;\n\n const logger = quiet ? SILENT_LOGGER : (userLogger ?? DEFAULT_LOGGER);\n\n const registeredTools: string[] = [];\n const toolControllers = new Map<string, AbortController>();\n const lifecycleController = new AbortController();\n let disposed = false;\n let inflightSync: Promise<void> | null = null;\n\n if (!navigator.modelContext) {\n logger.info(\n \"navigator.modelContext not available — skipping registration. \" +\n \"This is expected on non-Chrome browsers.\"\n );\n onSync?.([]);\n return {\n get tools() {\n return [];\n },\n get disposed() {\n return disposed;\n },\n refresh: async () => {},\n dispose: async () => {\n disposed = true;\n }\n };\n }\n\n const modelContext: ModelContext = navigator.modelContext;\n const client = new McpHttpClient(url, headers, getHeaders, timeoutMs);\n\n function unregisterAll(): void {\n for (const controller of toolControllers.values()) {\n controller.abort();\n }\n toolControllers.clear();\n registeredTools.length = 0;\n }\n\n function registerTools(tools: McpTool[]): void {\n for (const tool of tools) {\n const registeredName = `${prefix}${tool.name}`;\n const toolDef: ModelContextTool = {\n name: registeredName,\n description: tool.description ?? tool.name,\n ...(tool.inputSchema ? { inputSchema: tool.inputSchema } : {}),\n ...(tool.annotations\n ? { annotations: { readOnlyHint: tool.annotations.readOnlyHint } }\n : {}),\n execute: async (input: Record<string, unknown>) => {\n if (disposed) {\n throw new Error(\"WebMCP adapter has been disposed\");\n }\n const result = await client.callTool(\n tool.name,\n input,\n lifecycleController.signal\n );\n\n if (result.isError) {\n const errorText = result.content\n .map((c) => c.text ?? \"\")\n .join(\"\\n\");\n throw new Error(errorText || \"Tool execution failed\");\n }\n\n const parts: string[] = [];\n let sawUnsupported = false;\n for (const c of result.content) {\n if (c.type === \"text\" && c.text) {\n parts.push(c.text);\n } else if (c.type === \"image\" && c.data) {\n parts.push(`data:${c.mimeType ?? \"image/png\"};base64,${c.data}`);\n } else if (c.data) {\n parts.push(c.data);\n sawUnsupported = true;\n } else {\n sawUnsupported = true;\n }\n }\n if (sawUnsupported) {\n logger.warn(\n `Tool \"${tool.name}\" returned content type(s) the adapter` +\n \" cannot fully represent as a string.\"\n );\n }\n return parts.join(\"\\n\");\n }\n };\n\n try {\n const controller = new AbortController();\n modelContext.registerTool(toolDef, { signal: controller.signal });\n toolControllers.set(registeredName, controller);\n registeredTools.push(registeredName);\n } catch (err) {\n logger.warn(`Failed to register tool \"${registeredName}\":`, err);\n }\n }\n }\n\n // Serialize syncs: if one is already running, share its promise. This\n // prevents the unregister/listTools/registerTools sequence from\n // interleaving when both `refresh()` and a `tools/list_changed`\n // notification fire concurrently.\n function syncTools(): Promise<void> {\n if (disposed) return Promise.resolve();\n if (inflightSync) return inflightSync;\n inflightSync = (async () => {\n try {\n const tools = await client.listTools(lifecycleController.signal);\n if (disposed) return;\n unregisterAll();\n registerTools(tools);\n onSync?.(tools);\n } finally {\n inflightSync = null;\n }\n })();\n return inflightSync;\n }\n\n try {\n await client.initialize(lifecycleController.signal);\n await syncTools();\n\n if (watch) {\n client.listenForChanges(() => {\n if (disposed) return;\n syncTools().catch((err: unknown) => {\n if (disposed) return;\n const error = err instanceof Error ? err : new Error(String(err));\n logger.warn(\"Watch-mode sync failed:\", error);\n onError?.(error);\n });\n });\n }\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n logger.error(\"Initialization failed:\", error);\n // Best-effort cleanup so a failed init doesn't leak the transport.\n await client.close();\n throw error;\n }\n\n return {\n get tools() {\n return [...registeredTools];\n },\n get disposed() {\n return disposed;\n },\n refresh: syncTools,\n async dispose() {\n if (disposed) return;\n disposed = true;\n lifecycleController.abort();\n unregisterAll();\n // Wait for any in-flight sync to settle so callers can rely on\n // a quiet adapter after `await handle.dispose()`.\n try {\n await inflightSync;\n } catch {\n // Already surfaced via onError or thrown to the original caller.\n }\n await client.close();\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmIA,MAAM,iBAA+B;CACnC,OAAO,GAAG,SAAS,QAAQ,KAAK,oBAAoB,GAAG,IAAI;CAC3D,OAAO,GAAG,SAAS,QAAQ,KAAK,oBAAoB,GAAG,IAAI;CAC3D,QAAQ,GAAG,SAAS,QAAQ,MAAM,oBAAoB,GAAG,IAAI;AAC/D;AAEA,MAAM,gBAA8B;CAClC,YAAY,CAAC;CACb,YAAY,CAAC;CACb,aAAa,CAAC;AAChB;AAIA,IAAM,gBAAN,MAAoB;CAMlB,YACE,KACA,SACA,YACA,WACA;EACA,MAAM,cAAc,IAAI,IAAI,KAAK,WAAW,UAAU,MAAM;EAC5D,KAAK,aAAa;EAElB,MAAM,mBAEC,EACL,aAAa,EAAE,SAAS,WAAW,CAAC,EAAE,EACxC;EAEA,IAAI,YACF,iBAAiB,QAAQ,OAAO,OAAO,SAAS;GAC9C,MAAM,UAAU,MAAM,WAAW;GACjC,MAAM,SAAS,IAAI,QAAQ,MAAM,OAAO;GACxC,KAAK,MAAM,CAAC,GAAG,MAAM,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AC/D,IAAI,UAAU;IACd,cAAc;IACd,cAAc,KAAK;IACnB,SAAS,KAAK;GAChB,UAAU;IACR,eAAe;GACjB;EACF,GAAG;EACH,OAAO;CACT;CAEA,IAAI;EACF,MAAM,OAAO,WAAW,oBAAoB,MAAM;EAClD,MAAM,UAAU;EAEhB,IAAI,OACF,OAAO,uBAAuB;GAC5B,IAAI,UAAU;GACd,UAAU,EAAE,OAAO,QAAiB;IAClC,IAAI,UAAU;IACd,MAAM,QAAQ,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC;IAChE,OAAO,KAAK,2BAA2B,KAAK;IAC5C,UAAU,KAAK;GACjB,CAAC;EACH,CAAC;CAEL,SAAS,KAAK;EACZ,MAAM,QAAQ,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC;EAChE,OAAO,MAAM,0BAA0B,KAAK;EAE5C,MAAM,OAAO,MAAM;EACnB,MAAM;CACR;CAEA,OAAO;EACL,IAAI,QAAQ;GACV,OAAO,CAAC,GAAG,eAAe;EAC5B;EACA,IAAI,WAAW;GACb,OAAO;EACT;EACA,SAAS;EACT,MAAM,UAAU;GACd,IAAI,UAAU;GACd,WAAW;GACX,oBAAoB,MAAM;GAC1B,cAAc;GAGd,IAAI;IACF,MAAM;GACR,QAAQ,CAER;GACA,MAAM,OAAO,MAAM;EACrB;CACF;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,65 +1,72 @@
|
|
|
1
1
|
import { r as __DO_NOT_USE_WILL_BREAK__agentContext } from "./internal_context-BZrMS0B5.js";
|
|
2
2
|
import {
|
|
3
|
-
$ as
|
|
4
|
-
A as
|
|
5
|
-
B as
|
|
3
|
+
$ as SubAgentStub,
|
|
4
|
+
A as EmailSendBinding,
|
|
5
|
+
B as QueueItem,
|
|
6
|
+
Bt as SubAgentPathMatch,
|
|
6
7
|
C as AgentStaticOptions,
|
|
7
8
|
D as DEFAULT_AGENT_STATIC_OPTIONS,
|
|
8
9
|
E as ConnectionContext,
|
|
9
|
-
F as
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
I as
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
Pt as getSubAgentByName,
|
|
25
|
-
Q as routeAgentRequest,
|
|
26
|
-
R as RoutingRetryOptions,
|
|
10
|
+
F as FiberStatus,
|
|
11
|
+
G as ScheduleCriteria,
|
|
12
|
+
H as RPCResponse,
|
|
13
|
+
Ht as parseSubAgentPath,
|
|
14
|
+
I as ListFibersOptions,
|
|
15
|
+
J as StartFiberOptions,
|
|
16
|
+
K as SendEmailOptions,
|
|
17
|
+
L as MCPServer,
|
|
18
|
+
M as FiberInspection,
|
|
19
|
+
N as FiberRecoveryContext,
|
|
20
|
+
O as DeleteFibersOptions,
|
|
21
|
+
P as FiberRecoveryResult,
|
|
22
|
+
Q as SubAgentClass,
|
|
23
|
+
R as MCPServerMessage,
|
|
24
|
+
Rt as TransportType,
|
|
27
25
|
S as AgentOptions,
|
|
28
26
|
T as Connection,
|
|
29
|
-
U as
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
U as RoutingRetryOptions,
|
|
28
|
+
Ut as routeSubAgentRequest,
|
|
29
|
+
V as RPCRequest,
|
|
30
|
+
Vt as getSubAgentByName,
|
|
31
|
+
W as Schedule,
|
|
32
|
+
X as StateUpdateMessage,
|
|
33
|
+
Y as StartFiberResult,
|
|
34
|
+
Z as StreamingResponse,
|
|
35
35
|
_ as AddRpcMcpServerOptions,
|
|
36
36
|
a as AgentToolEventState,
|
|
37
|
+
at as routeAgentRequest,
|
|
37
38
|
b as AgentGetOptions,
|
|
38
39
|
c as AgentToolRunInspection,
|
|
39
40
|
d as AgentToolStoredChunk,
|
|
41
|
+
et as WSMessage,
|
|
40
42
|
f as AgentToolTerminalStatus,
|
|
41
43
|
g as AddMcpServerOptions,
|
|
42
44
|
h as RunAgentToolResult,
|
|
43
45
|
i as AgentToolEventMessage,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
k as
|
|
46
|
+
it as routeAgentEmail,
|
|
47
|
+
j as FiberContext,
|
|
48
|
+
k as EmailRoutingOptions,
|
|
47
49
|
l as AgentToolRunState,
|
|
48
50
|
m as RunAgentToolOptions,
|
|
49
51
|
n as AgentToolDisplayMetadata,
|
|
52
|
+
nt as getAgentByName,
|
|
50
53
|
o as AgentToolLifecycleResult,
|
|
54
|
+
ot as unstable_callable,
|
|
51
55
|
p as ChatCapableAgentClass,
|
|
52
|
-
q as
|
|
56
|
+
q as SqlError,
|
|
53
57
|
r as AgentToolEvent,
|
|
58
|
+
rt as getCurrentAgent,
|
|
54
59
|
s as AgentToolRunInfo,
|
|
55
60
|
t as AgentToolChildAdapter,
|
|
61
|
+
tt as callable,
|
|
56
62
|
u as AgentToolRunStatus,
|
|
57
63
|
v as Agent,
|
|
58
64
|
w as CallableMetadata,
|
|
59
65
|
x as AgentNamespace,
|
|
60
66
|
y as AgentContext,
|
|
61
|
-
z as
|
|
62
|
-
|
|
67
|
+
z as MCPServersState,
|
|
68
|
+
zt as SUB_PREFIX
|
|
69
|
+
} from "./agent-tool-types-Dn9n-3SI.js";
|
|
63
70
|
import { t as RetryOptions } from "./retries-BVdRl5ZE.js";
|
|
64
71
|
import {
|
|
65
72
|
n as AgentsOAuthProvider,
|
|
@@ -74,33 +81,38 @@ export {
|
|
|
74
81
|
Agent,
|
|
75
82
|
AgentContext,
|
|
76
83
|
AgentGetOptions,
|
|
77
|
-
AgentMcpOAuthProvider,
|
|
84
|
+
type AgentMcpOAuthProvider,
|
|
78
85
|
AgentNamespace,
|
|
79
86
|
AgentOptions,
|
|
80
87
|
AgentStaticOptions,
|
|
81
|
-
AgentToolChildAdapter,
|
|
82
|
-
AgentToolDisplayMetadata,
|
|
83
|
-
AgentToolEvent,
|
|
84
|
-
AgentToolEventMessage,
|
|
85
|
-
AgentToolEventState,
|
|
86
|
-
AgentToolLifecycleResult,
|
|
87
|
-
AgentToolRunInfo,
|
|
88
|
-
AgentToolRunInspection,
|
|
89
|
-
AgentToolRunState,
|
|
90
|
-
AgentToolRunStatus,
|
|
91
|
-
AgentToolStoredChunk,
|
|
92
|
-
AgentToolTerminalStatus,
|
|
93
|
-
AgentsOAuthProvider,
|
|
88
|
+
type AgentToolChildAdapter,
|
|
89
|
+
type AgentToolDisplayMetadata,
|
|
90
|
+
type AgentToolEvent,
|
|
91
|
+
type AgentToolEventMessage,
|
|
92
|
+
type AgentToolEventState,
|
|
93
|
+
type AgentToolLifecycleResult,
|
|
94
|
+
type AgentToolRunInfo,
|
|
95
|
+
type AgentToolRunInspection,
|
|
96
|
+
type AgentToolRunState,
|
|
97
|
+
type AgentToolRunStatus,
|
|
98
|
+
type AgentToolStoredChunk,
|
|
99
|
+
type AgentToolTerminalStatus,
|
|
100
|
+
type AgentsOAuthProvider,
|
|
94
101
|
CallableMetadata,
|
|
95
|
-
ChatCapableAgentClass,
|
|
96
|
-
Connection,
|
|
97
|
-
ConnectionContext,
|
|
102
|
+
type ChatCapableAgentClass,
|
|
103
|
+
type Connection,
|
|
104
|
+
type ConnectionContext,
|
|
98
105
|
DEFAULT_AGENT_STATIC_OPTIONS,
|
|
106
|
+
DeleteFibersOptions,
|
|
99
107
|
DurableObjectOAuthClientProvider,
|
|
100
108
|
EmailRoutingOptions,
|
|
101
109
|
EmailSendBinding,
|
|
102
110
|
FiberContext,
|
|
111
|
+
FiberInspection,
|
|
103
112
|
FiberRecoveryContext,
|
|
113
|
+
FiberRecoveryResult,
|
|
114
|
+
FiberStatus,
|
|
115
|
+
ListFibersOptions,
|
|
104
116
|
MCPServer,
|
|
105
117
|
MCPServerMessage,
|
|
106
118
|
MCPServersState,
|
|
@@ -108,22 +120,24 @@ export {
|
|
|
108
120
|
QueueItem,
|
|
109
121
|
RPCRequest,
|
|
110
122
|
RPCResponse,
|
|
111
|
-
RetryOptions,
|
|
112
|
-
RoutingRetryOptions,
|
|
113
|
-
RunAgentToolOptions,
|
|
114
|
-
RunAgentToolResult,
|
|
123
|
+
type RetryOptions,
|
|
124
|
+
type RoutingRetryOptions,
|
|
125
|
+
type RunAgentToolOptions,
|
|
126
|
+
type RunAgentToolResult,
|
|
115
127
|
SUB_PREFIX,
|
|
116
128
|
Schedule,
|
|
117
129
|
ScheduleCriteria,
|
|
118
130
|
SendEmailOptions,
|
|
119
131
|
SqlError,
|
|
132
|
+
StartFiberOptions,
|
|
133
|
+
StartFiberResult,
|
|
120
134
|
StateUpdateMessage,
|
|
121
135
|
StreamingResponse,
|
|
122
136
|
SubAgentClass,
|
|
123
|
-
SubAgentPathMatch,
|
|
137
|
+
type SubAgentPathMatch,
|
|
124
138
|
SubAgentStub,
|
|
125
|
-
TransportType,
|
|
126
|
-
WSMessage,
|
|
139
|
+
type TransportType,
|
|
140
|
+
type WSMessage,
|
|
127
141
|
__DO_NOT_USE_WILL_BREAK__agentContext,
|
|
128
142
|
callable,
|
|
129
143
|
createHeaderBasedEmailResolver,
|