agents 0.27.0 → 0.28.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/dist/abortable-C1SpfVoi.js +21 -0
- package/dist/abortable-C1SpfVoi.js.map +1 -0
- package/dist/{agent-routing-Bhdbvf7s.d.ts → agent-routing-BMvWTFEp.d.ts} +21 -15
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-bJZwBMfq.d.ts → agent-tools-ohoewW-B.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/ai-ahruGw7e.d.ts +239 -0
- package/dist/{ai-sdk-OoGkFy3s.js → ai-sdk-C2iTAwUd.js} +44 -18
- package/dist/ai-sdk-C2iTAwUd.js.map +1 -0
- package/dist/browser/ai.d.ts +8 -227
- package/dist/browser/ai.js +259 -1
- package/dist/browser/ai.js.map +1 -0
- package/dist/browser/index.d.ts +56 -46
- package/dist/browser/index.js +4 -361
- package/dist/browser/{ai-sdk.d.ts → tools/ai-sdk.d.ts} +7 -7
- package/dist/browser/{ai-sdk.js → tools/ai-sdk.js} +5 -4
- package/dist/browser/tools/ai-sdk.js.map +1 -0
- package/dist/browser/tools/pi.d.ts +111 -0
- package/dist/browser/tools/pi.js +119 -0
- package/dist/browser/tools/pi.js.map +1 -0
- package/dist/browser/{tanstack-ai.d.ts → tools/tanstack-ai.d.ts} +39 -37
- package/dist/browser/{tanstack-ai.js → tools/tanstack-ai.js} +73 -59
- package/dist/browser/tools/tanstack-ai.js.map +1 -0
- package/dist/browser-CEdNlsaD.js +481 -0
- package/dist/browser-CEdNlsaD.js.map +1 -0
- package/dist/{browser-tmkcAAI3.d.ts → browser-D30VlpcA.d.ts} +63 -37
- package/dist/{browser-tool-CBqs6hqa.js → browser-tool-4iomavs_.js} +145 -49
- package/dist/browser-tool-4iomavs_.js.map +1 -0
- package/dist/{browser-tool-Bn-nzJQI.d.ts → browser-tool-vtrPOV8e.d.ts} +24 -5
- package/dist/{capability-B4WbF81e.js → capability-DBAKc6UZ.js} +1 -3
- package/dist/capability-DBAKc6UZ.js.map +1 -0
- package/dist/{capability-runner-O5VbQzqg.d.ts → capability-runner-BiVUtjqC.d.ts} +1 -7
- package/dist/chat/index.d.ts +4 -4
- package/dist/chat/index.js +1 -1
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/chat-sdk/index.js +1 -1
- package/dist/{client-1tEQ1Oqz.js → client-BnYbNT3z.js} +3 -4
- package/dist/client-BnYbNT3z.js.map +1 -0
- package/dist/{client-DS3Dz9l0.d.ts → client-Bp-JwL3p.d.ts} +2 -2
- package/dist/client.d.ts +1 -1
- package/dist/{connector-58XDGvc3.js → connector-CtZylXdk.js} +3 -603
- package/dist/connector-CtZylXdk.js.map +1 -0
- package/dist/{connector-Cl-VqPmA.d.ts → connector-DEXzVoaY.d.ts} +9 -374
- package/dist/{conversations-DH0ut_8n.d.ts → conversations-FjHDRZyD.d.ts} +4 -4
- package/dist/{current-agent-C07C5o5Y.d.ts → current-agent-CKgT5d1O.d.ts} +3 -5
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{durable-object-lifecycle-DRqp475_.d.ts → durable-object-lifecycle-DOI_bzCH.d.ts} +2 -2
- package/dist/experimental/channels/index.d.ts +2 -2
- package/dist/experimental/channels/index.js +2 -2
- package/dist/experimental/channels/web/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.js +1 -1
- package/dist/{gateway-BDC07gYO.d.ts → gateway-BFO6vRDn.d.ts} +2 -2
- package/dist/{handler-stateless-VvrWSAVA.js → handler-stateless-Bly_nSH3.js} +12 -3
- package/dist/handler-stateless-Bly_nSH3.js.map +1 -0
- package/dist/harness/ai-sdk/index.d.ts +2 -2
- package/dist/harness/ai-sdk/index.js +1 -1
- package/dist/harness/container/index.d.ts +2 -2
- package/dist/harness/container/index.js +3 -3
- package/dist/harness/opencode/index.d.ts +183 -7
- package/dist/harness/opencode/index.js +355 -24
- package/dist/harness/opencode/index.js.map +1 -1
- package/dist/harness/pi/index.d.ts +2 -2
- package/dist/harness/pi/index.js +3 -3
- package/dist/harness/store/index.d.ts +1 -1
- package/dist/harness/store/index.js +1 -1
- package/dist/harness/think/index.d.ts +2 -2
- package/dist/harness/think/index.js +363 -171
- package/dist/harness/think/index.js.map +1 -1
- package/dist/{images-Ce9SCu3X.js → images-C4hiIexM.js} +46 -4
- package/dist/images-C4hiIexM.js.map +1 -0
- package/dist/{index-D0A5tbWu.d.ts → index-BEL3ZV-s.d.ts} +2 -6
- package/dist/{index-Ib_4dwOo.d.ts → index-CBt8oRJt.d.ts} +3 -5
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/input-schema-BQykTEp_.js +20 -0
- package/dist/input-schema-BQykTEp_.js.map +1 -0
- package/dist/{input-schema-DNrpTu49.js → input-schema-xBofjBKC.js} +3 -3
- package/dist/input-schema-xBofjBKC.js.map +1 -0
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +3 -3
- package/dist/lifecycle/index.js +2 -2
- package/dist/{lifecycle-CFu6OV03.js → lifecycle-DGorpAmA.js} +2 -4
- package/dist/lifecycle-DGorpAmA.js.map +1 -0
- package/dist/mcp/client/index.d.ts +1 -1
- package/dist/mcp/client/index.js +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +18 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/server/index.js +1 -1
- package/dist/models/ai-sdk/index.d.ts +45 -17
- package/dist/models/ai-sdk/index.js +1 -1
- package/dist/models/opencode/index.d.ts +2 -2
- package/dist/models/opencode/index.js +1 -1
- package/dist/models/pi-ai/index.d.ts +8 -3
- package/dist/models/pi-ai/index.js +6 -6
- package/dist/models/pi-ai/index.js.map +1 -1
- package/dist/{options-pwTNq9z6.d.ts → options-CiIsJHXR.d.ts} +2 -6
- package/dist/queue/index.d.ts +1 -1
- package/dist/queue/index.js +1 -1
- package/dist/{queue-BB-zfIYF.js → queue-CcIjVYTE.js} +2 -2
- package/dist/{queue-BB-zfIYF.js.map → queue-CcIjVYTE.js.map} +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/routing/index.d.ts +2 -2
- package/dist/routing/index.js +1 -1
- package/dist/{scheduler-CrFCnv_J.d.ts → scheduler-BCLESHSC.d.ts} +2 -12
- package/dist/{scheduler-DZ3xQfeK.js → scheduler-FIHv2-kJ.js} +2 -4
- package/dist/scheduler-FIHv2-kJ.js.map +1 -0
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/session-store-Do4xkDcf.js +606 -0
- package/dist/session-store-Do4xkDcf.js.map +1 -0
- package/dist/session-store-DoPY12xM.d.ts +383 -0
- package/dist/sessions/index.d.ts +1 -1
- package/dist/sessions/index.js +1 -1
- package/dist/{sessions-B9pNuxdT.js → sessions-_vN5BEZX.js} +2 -2
- package/dist/{sessions-B9pNuxdT.js.map → sessions-_vN5BEZX.js.map} +1 -1
- package/dist/{settings-C45hDliX.js → settings-BjAiPd6Z.js} +7 -4
- package/dist/settings-BjAiPd6Z.js.map +1 -0
- package/dist/{settings-NgGwF7Qt.d.ts → settings-DnD__xuE.d.ts} +22 -4
- package/dist/{src-DgCbZtIR.js → src-CQxJFv4l.js} +8 -8
- package/dist/src-CQxJFv4l.js.map +1 -0
- package/dist/state/index.d.ts +1 -1
- package/dist/state/index.js +1 -3
- package/dist/state/index.js.map +1 -1
- package/dist/{store-DLeqKuj3.d.ts → store-BKM4Xm9M.d.ts} +23 -1
- package/dist/{store-vgcPYo8K.js → store-CslVzfN7.js} +28 -2
- package/dist/store-CslVzfN7.js.map +1 -0
- package/dist/streams/index.d.ts +1 -1
- package/dist/streams/index.js +1 -1
- package/dist/{streams-CITClVer.js → streams-lsHMJhRW.js} +2 -2
- package/dist/{streams-CITClVer.js.map → streams-lsHMJhRW.js.map} +1 -1
- package/dist/{streams-fbG61qM8.d.ts → streams-vrCtbUIn.d.ts} +2 -2
- package/dist/sub-routing.d.ts +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +1 -1
- package/dist/{tasks-CkTZNaV1.js → tasks-BN_5AWqI.js} +2 -2
- package/dist/{tasks-CkTZNaV1.js.map → tasks-BN_5AWqI.js.map} +1 -1
- package/dist/{tasks-PtlB4Uyn.d.ts → tasks-E89KdwkS.d.ts} +2 -2
- package/dist/{tool-BPJEbwaX.d.ts → tool-CTp72Jb_.d.ts} +4 -4
- package/dist/tool-CxKsvxjm.js +1126 -0
- package/dist/tool-CxKsvxjm.js.map +1 -0
- package/dist/tool-DoVberpN.d.ts +301 -0
- package/dist/{tool-3PA8xjB_.js → tool-VF0qiO7q.js} +7 -18
- package/dist/tool-VF0qiO7q.js.map +1 -0
- package/dist/tool-helpers-O5BDVEAY.js +58 -0
- package/dist/tool-helpers-O5BDVEAY.js.map +1 -0
- package/dist/{transport-k2mFrtL8.d.ts → transport-DCyarnwm.d.ts} +2 -2
- package/dist/voice/index.d.ts +2 -2
- package/dist/web/fetch/index.d.ts +89 -0
- package/dist/web/fetch/index.js +20 -0
- package/dist/web/fetch/index.js.map +1 -0
- package/dist/web/fetch/tools/ai-sdk.d.ts +80 -0
- package/dist/web/fetch/tools/ai-sdk.js +47 -0
- package/dist/web/fetch/tools/ai-sdk.js.map +1 -0
- package/dist/web/fetch/tools/pi.d.ts +84 -0
- package/dist/web/fetch/tools/pi.js +88 -0
- package/dist/web/fetch/tools/pi.js.map +1 -0
- package/dist/web/fetch/tools/tanstack-ai.d.ts +78 -0
- package/dist/web/fetch/tools/tanstack-ai.js +45 -0
- package/dist/web/fetch/tools/tanstack-ai.js.map +1 -0
- package/dist/{websearch → web/search}/index.d.ts +1 -1
- package/dist/{websearch → web/search}/index.js +1 -1
- package/dist/{websearch → web/search}/tools/ai-sdk.d.ts +2 -2
- package/dist/{websearch → web/search}/tools/ai-sdk.js +3 -3
- package/dist/web/search/tools/ai-sdk.js.map +1 -0
- package/dist/{websearch → web/search}/tools/pi.d.ts +3 -3
- package/dist/{websearch → web/search}/tools/pi.js +2 -2
- package/dist/web/search/tools/pi.js.map +1 -0
- package/dist/{websearch → web/search}/tools/tanstack-ai.d.ts +2 -2
- package/dist/{websearch → web/search}/tools/tanstack-ai.js +3 -3
- package/dist/web/search/tools/tanstack-ai.js.map +1 -0
- package/dist/websockets/index.d.ts +2 -2
- package/dist/websockets/index.js +1 -1
- package/dist/{websockets-CmENGb-Z.js → websockets-C3zy8YR0.js} +3 -5
- package/dist/websockets-C3zy8YR0.js.map +1 -0
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/dist/workflows.js +1 -1
- package/docs/browse-the-web.md +26 -1
- package/docs/fetch-the-web.md +276 -0
- package/docs/harnesses/pi.md +25 -0
- package/docs/index.md +99 -76
- package/docs/lifecycle.md +2 -3
- package/docs/mcp-client.md +1 -1
- package/docs/mcp-servers.md +1 -1
- package/docs/models-pi-ai.md +11 -0
- package/docs/models.md +45 -3
- package/docs/queue.md +2 -3
- package/docs/scheduling.md +2 -6
- package/docs/search-the-web.md +2 -0
- package/package.json +52 -27
- package/dist/ai-fm7xx1BK.js +0 -312
- package/dist/ai-fm7xx1BK.js.map +0 -1
- package/dist/ai-sdk-OoGkFy3s.js.map +0 -1
- package/dist/browser/ai-sdk.js.map +0 -1
- package/dist/browser/index.js.map +0 -1
- package/dist/browser/tanstack-ai.js.map +0 -1
- package/dist/browser-tool-CBqs6hqa.js.map +0 -1
- package/dist/capability-B4WbF81e.js.map +0 -1
- package/dist/client-1tEQ1Oqz.js.map +0 -1
- package/dist/connector-58XDGvc3.js.map +0 -1
- package/dist/handler-stateless-VvrWSAVA.js.map +0 -1
- package/dist/images-Ce9SCu3X.js.map +0 -1
- package/dist/input-schema-DNrpTu49.js.map +0 -1
- package/dist/lifecycle-CFu6OV03.js.map +0 -1
- package/dist/scheduler-DZ3xQfeK.js.map +0 -1
- package/dist/settings-C45hDliX.js.map +0 -1
- package/dist/src-DgCbZtIR.js.map +0 -1
- package/dist/store-vgcPYo8K.js.map +0 -1
- package/dist/tool-3PA8xjB_.js.map +0 -1
- package/dist/websearch/tools/ai-sdk.js.map +0 -1
- package/dist/websearch/tools/pi.js.map +0 -1
- package/dist/websearch/tools/tanstack-ai.js.map +0 -1
- package/dist/websockets-CmENGb-Z.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"current-agent-DhoDkSnH.js","names":[],"sources":["../src/lifecycle/current-agent.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { DurableObject } from \"cloudflare:workers\";\n\nimport type { MemoryLimitContext } from \"./capability-runner\";\nimport type { Lifecycle } from \"./durable-object-lifecycle\";\nimport type { Connection } from \"./types\";\nimport type { LifecycleJobContext, LifecycleJobOutcome } from \"./job-queue\";\n\n/**\n * A Durable Object that has installed the Agents SDK Lifecycle.\n *\n * Pass a more specific Lifecycle Object type to {@link getCurrentAgent} when\n * shared host code needs APIs implemented by a particular object.\n
|
|
1
|
+
{"version":3,"file":"current-agent-DhoDkSnH.js","names":[],"sources":["../src/lifecycle/current-agent.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { DurableObject } from \"cloudflare:workers\";\n\nimport type { MemoryLimitContext } from \"./capability-runner\";\nimport type { Lifecycle } from \"./durable-object-lifecycle\";\nimport type { Connection } from \"./types\";\nimport type { LifecycleJobContext, LifecycleJobOutcome } from \"./job-queue\";\n\n/**\n * A Durable Object that has installed the Agents SDK Lifecycle.\n *\n * Pass a more specific Lifecycle Object type to {@link getCurrentAgent} when\n * shared host code needs APIs implemented by a particular object.\n */\nexport interface LifecycleObject<\n Env extends object = Cloudflare.Env,\n Props extends object = object\n> extends DurableObject<Env> {\n readonly lifecycle: Lifecycle<Env, Props>;\n onStart?(props?: Props): void | Promise<void>;\n onRequest?(request: Request): Response | Promise<Response>;\n onAlarm?(): void | Promise<void>;\n onJob?(\n context: LifecycleJobContext\n ): LifecycleJobOutcome | void | Promise<LifecycleJobOutcome | void>;\n /**\n * Host domain policy applied when the alarm memory-limit circuit breaker\n * records a strike (#1825), after every capability's `onMemoryLimit` hook.\n *\n * Lifecycle dispatches host hooks structurally through its internal host\n * cast, so TS visibility is the host's to choose: a framework host whose\n * implementation is internal machinery declares the hook `protected` (the\n * pattern — see `AIChatAgent`/`Think`) and keeps the real work in a\n * `private _cf_`-prefixed method, without falling out of this contract at\n * runtime.\n */\n onAlarmMemoryLimit?(context: MemoryLimitContext): void | Promise<void>;\n}\n\n/** Values associated with the currently executing Lifecycle host. */\nexport type AgentContextStore = {\n /** Lifecycle host selected for this invocation. */\n agent: unknown;\n /** WebSocket connection selected for this invocation, when applicable. */\n connection: Connection | undefined;\n /** HTTP request selected for this invocation, when applicable. */\n request: Request | undefined;\n /** Extension-owned value selected for this invocation, when applicable. */\n email: unknown;\n};\n\n/** Values returned by {@link getCurrentAgent}. */\nexport type CurrentAgentContext<\n Host extends DurableObject = LifecycleObject,\n Email = unknown\n> = {\n agent: Host | undefined;\n connection: Connection | undefined;\n request: Request | undefined;\n email: Email | undefined;\n};\n\n/**\n * Shared invocation context for Lifecycle, Agent, AIChatAgent, and Think.\n *\n * @internal Importing or relying on this symbol will break your code in a\n * future release. Use {@link getCurrentAgent} to read the public context.\n */\nexport const __DO_NOT_USE_WILL_BREAK__agentContext =\n new AsyncLocalStorage<AgentContextStore>();\n\n/**\n * Return the current Agent or Lifecycle Object and invocation-specific values.\n *\n * Lifecycle host startup and alarm hooks receive the current object with no\n * request. Request hooks additionally receive the request being handled.\n * Lifecycle-managed WebSocket hooks receive their connection and, during\n * connect, its upgrade request. Agent extensions may also establish context\n * for email, chat turns, callable methods, and detached work. Capability hooks\n * do not run in this ambient context.\n */\nexport function getCurrentAgent<\n Host extends DurableObject = LifecycleObject\n>(): CurrentAgentContext<Host> {\n const store = __DO_NOT_USE_WILL_BREAK__agentContext.getStore();\n if (!store) {\n return {\n agent: undefined,\n connection: undefined,\n request: undefined,\n email: undefined\n };\n }\n\n return {\n agent: store.agent as Host,\n connection: store.connection,\n request: store.request,\n email: store.email\n };\n}\n\ntype LifecycleHostContext<Env extends object, Props extends object> = {\n readonly host: LifecycleObject<Env, Props>;\n readonly connection?: Connection;\n readonly request?: Request;\n};\n\n/** Run one host hook in the context of its Lifecycle Object. */\nexport function runInLifecycleHostContext<\n Env extends object,\n Props extends object,\n T\n>(context: LifecycleHostContext<Env, Props>, operation: () => T): T {\n return __DO_NOT_USE_WILL_BREAK__agentContext.run(\n {\n agent: context.host,\n connection: context.connection,\n request: context.request,\n email: undefined\n },\n operation\n );\n}\n\n/** Run a capability hook without inheriting a current Agent or host context. */\nexport function runWithoutCurrentAgent<T>(operation: () => T): T {\n return __DO_NOT_USE_WILL_BREAK__agentContext.exit(operation);\n}\n"],"mappings":";;;;;;;;AAoEA,MAAa,wCACX,IAAI,kBAAqC;;;;;;;;;;;AAY3C,SAAgB,kBAEe;CAC7B,MAAM,QAAQ,sCAAsC,SAAS;CAC7D,IAAI,CAAC,OACH,OAAO;EACL,OAAO,KAAA;EACP,YAAY,KAAA;EACZ,SAAS,KAAA;EACT,OAAO,KAAA;CACT;CAGF,OAAO;EACL,OAAO,MAAM;EACb,YAAY,MAAM;EAClB,SAAS,MAAM;EACf,OAAO,MAAM;CACf;AACF;;AASA,SAAgB,0BAId,SAA2C,WAAuB;CAClE,OAAO,sCAAsC,IAC3C;EACE,OAAO,QAAQ;EACf,YAAY,QAAQ;EACpB,SAAS,QAAQ;EACjB,OAAO,KAAA;CACT,GACA,SACF;AACF;;AAGA,SAAgB,uBAA0B,WAAuB;CAC/D,OAAO,sCAAsC,KAAK,SAAS;AAC7D"}
|
package/dist/{durable-object-lifecycle-DRqp475_.d.ts → durable-object-lifecycle-DOI_bzCH.d.ts}
RENAMED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
b as LifecycleJobs,
|
|
4
4
|
i as DurableObjectCapability,
|
|
5
5
|
u as LifecycleRouteAddress
|
|
6
|
-
} from "./capability-runner-
|
|
6
|
+
} from "./capability-runner-BiVUtjqC.js";
|
|
7
7
|
import { DurableObject } from "cloudflare:workers";
|
|
8
8
|
|
|
9
9
|
//#region src/lifecycle/durable-object-lifecycle.d.ts
|
|
@@ -162,4 +162,4 @@ declare class Lifecycle<
|
|
|
162
162
|
}
|
|
163
163
|
//#endregion
|
|
164
164
|
export { LifecycleOptions as n, LifecycleRouteEnvelope as r, Lifecycle as t };
|
|
165
|
-
//# sourceMappingURL=durable-object-lifecycle-
|
|
165
|
+
//# sourceMappingURL=durable-object-lifecycle-DOI_bzCH.d.ts.map
|
|
@@ -91,13 +91,13 @@ import {
|
|
|
91
91
|
s as ForHarnessOptions,
|
|
92
92
|
t as ChannelState,
|
|
93
93
|
u as ResponseReadOptions
|
|
94
|
-
} from "../../conversations-
|
|
94
|
+
} from "../../conversations-FjHDRZyD.js";
|
|
95
95
|
import {
|
|
96
96
|
i as GatewayAgent,
|
|
97
97
|
n as ChannelGatewayOptions,
|
|
98
98
|
r as ChannelRouteEvent,
|
|
99
99
|
t as ChannelGateway
|
|
100
|
-
} from "../../gateway-
|
|
100
|
+
} from "../../gateway-BFO6vRDn.js";
|
|
101
101
|
|
|
102
102
|
//#region src/experimental/channels/apply-chunks.d.ts
|
|
103
103
|
/** Apply a response's chunks to the message it builds or extends. */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "../../classPrivateFieldGet2-DZBYAB34.js";
|
|
2
2
|
import { t as _classPrivateMethodInitSpec } from "../../classPrivateMethodInitSpec-qMjJ6sHQ.js";
|
|
3
|
-
import { t as LifecycleCapability } from "../../capability-
|
|
3
|
+
import { t as LifecycleCapability } from "../../capability-DBAKc6UZ.js";
|
|
4
4
|
import { t as TextSegmentJoiner } from "../../text-segment-joiner-BtAFQSA_.js";
|
|
5
|
-
import { n as Streams } from "../../streams-
|
|
5
|
+
import { n as Streams } from "../../streams-lsHMJhRW.js";
|
|
6
6
|
import { t as applyChunks } from "../../apply-chunks-1FheRb9W.js";
|
|
7
7
|
import { a as toParticipant, i as participantRoute, o as unsupported } from "../../internal-kmw70xwR.js";
|
|
8
8
|
import { t as WEB_IDENTITY_HEADER } from "../../protocol-y2sSY584.js";
|
|
@@ -14,12 +14,12 @@ import {
|
|
|
14
14
|
r as ConversationOperation,
|
|
15
15
|
y as TurnStatus
|
|
16
16
|
} from "../../../protocol-CukuI73M.js";
|
|
17
|
-
import { i as WebSockets } from "../../../index-
|
|
17
|
+
import { i as WebSockets } from "../../../index-CBt8oRJt.js";
|
|
18
18
|
import {
|
|
19
19
|
a as ConversationChannel,
|
|
20
20
|
o as ConversationUpdate,
|
|
21
21
|
r as ChannelsHost
|
|
22
|
-
} from "../../../conversations-
|
|
22
|
+
} from "../../../conversations-FjHDRZyD.js";
|
|
23
23
|
|
|
24
24
|
//#region src/experimental/channels/web/channel.d.ts
|
|
25
25
|
type WebChannelOptions = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "../../../classPrivateFieldGet2-DZBYAB34.js";
|
|
2
2
|
import { t as _classPrivateMethodInitSpec } from "../../../classPrivateMethodInitSpec-qMjJ6sHQ.js";
|
|
3
|
-
import { a as getConnectionFlag, l as registerInternalConnectionKeys, t as WebSockets, u as setConnectionFlag } from "../../../websockets-
|
|
3
|
+
import { a as getConnectionFlag, l as registerInternalConnectionKeys, t as WebSockets, u as setConnectionFlag } from "../../../websockets-C3zy8YR0.js";
|
|
4
4
|
import { i as participantRoute } from "../../../internal-kmw70xwR.js";
|
|
5
5
|
import { n as parseClientFrame, t as WEB_IDENTITY_HEADER } from "../../../protocol-y2sSY584.js";
|
|
6
6
|
//#region src/experimental/channels/web/channel.ts
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
p as Participant,
|
|
15
15
|
s as GatewayOrigin
|
|
16
16
|
} from "./protocol-CukuI73M.js";
|
|
17
|
-
import { c as GatewayEvent } from "./conversations-
|
|
17
|
+
import { c as GatewayEvent } from "./conversations-FjHDRZyD.js";
|
|
18
18
|
|
|
19
19
|
//#region src/experimental/channels/gateway.d.ts
|
|
20
20
|
type ChannelRouteEvent = {
|
|
@@ -97,4 +97,4 @@ export {
|
|
|
97
97
|
ChannelRouteEvent as r,
|
|
98
98
|
ChannelGateway as t
|
|
99
99
|
};
|
|
100
|
-
//# sourceMappingURL=gateway-
|
|
100
|
+
//# sourceMappingURL=gateway-BFO6vRDn.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import { WebStandardStreamableHTTPServerTransport, createMcpHandler, hostHeaderValidationResponse, isJSONRPCRequest, isLegacyRequest, localhostAllowedHostnames, localhostAllowedOrigins, originValidationResponse } from "@modelcontextprotocol/server";
|
|
2
|
+
import { McpServer, WebStandardStreamableHTTPServerTransport, createMcpHandler, hostHeaderValidationResponse, isJSONRPCRequest, isLegacyRequest, localhostAllowedHostnames, localhostAllowedOrigins, originValidationResponse } from "@modelcontextprotocol/server";
|
|
3
3
|
//#region src/mcp/server/auth-context.ts
|
|
4
4
|
const VERIFIED_OAUTH_CONTEXT = Symbol.for("cloudflare.workers-oauth-provider.verified-context.v1");
|
|
5
5
|
const authContextStorage = new AsyncLocalStorage();
|
|
@@ -78,6 +78,10 @@ function reportHandlerError(onerror, error) {
|
|
|
78
78
|
*
|
|
79
79
|
* - impossible stateless server-to-client requests fail immediately rather
|
|
80
80
|
* than leaving the tool handler waiting for a session response.
|
|
81
|
+
* - a factory that returns an instance still serving another request is
|
|
82
|
+
* rejected before this request takes ownership of it, so the error path
|
|
83
|
+
* never closes the other request's instance (mirrors upstream's
|
|
84
|
+
* `assertNotServing` on the modern path).
|
|
81
85
|
*
|
|
82
86
|
* Streaming and keepalive behavior remain delegated to the SDK transport.
|
|
83
87
|
* Remove this adapter once the SDK exposes the reverse-request policy directly.
|
|
@@ -102,11 +106,13 @@ function createLegacyCompatibilityRequestHandler(factory, handlerOptions = {}) {
|
|
|
102
106
|
})();
|
|
103
107
|
const onAbort = () => void teardown();
|
|
104
108
|
try {
|
|
105
|
-
|
|
109
|
+
const candidate = await factory({
|
|
106
110
|
era: "legacy",
|
|
107
111
|
...requestOptions?.authInfo !== void 0 && { authInfo: requestOptions.authInfo },
|
|
108
112
|
requestInfo: request
|
|
109
113
|
});
|
|
114
|
+
assertNotServing(candidate);
|
|
115
|
+
product = candidate;
|
|
110
116
|
transport = new WebStandardStreamableHTTPServerTransport({
|
|
111
117
|
keepAliveMs,
|
|
112
118
|
sessionIdGenerator: void 0
|
|
@@ -177,6 +183,9 @@ function createLegacyCompatibilityRequestHandler(factory, handlerOptions = {}) {
|
|
|
177
183
|
};
|
|
178
184
|
return { fetch };
|
|
179
185
|
}
|
|
186
|
+
function assertNotServing(product) {
|
|
187
|
+
if ((product instanceof McpServer ? product.server : product).transport !== void 0) throw new Error("The factory returned an instance that is still serving another request. Return a new instance for each request.");
|
|
188
|
+
}
|
|
180
189
|
//#endregion
|
|
181
190
|
//#region src/mcp/server/handler-stateless.ts
|
|
182
191
|
const DEFAULT_CORS_OPTIONS = {
|
|
@@ -315,4 +324,4 @@ function createStatelessMcpHandler(factory, options = {}) {
|
|
|
315
324
|
//#endregion
|
|
316
325
|
export { getMcpAuthContext as n, runWithAuthContext as r, createStatelessMcpHandler as t };
|
|
317
326
|
|
|
318
|
-
//# sourceMappingURL=handler-stateless-
|
|
327
|
+
//# sourceMappingURL=handler-stateless-Bly_nSH3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-stateless-Bly_nSH3.js","names":["candidate","createSdkMcpHandler"],"sources":["../src/mcp/server/auth-context.ts","../src/mcp/server/handler-errors.ts","../src/mcp/server/handler-legacy-compat.ts","../src/mcp/server/handler-stateless.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { AuthInfo } from \"@modelcontextprotocol/server\";\n\nconst VERIFIED_OAUTH_CONTEXT = Symbol.for(\n \"cloudflare.workers-oauth-provider.verified-context.v1\"\n);\n\ninterface VerifiedWorkersOAuthContext {\n version: 1;\n token: string;\n clientId: string;\n scopes: string[];\n expiresAt?: number;\n resource?: string;\n props: Record<string, unknown>;\n}\n\nexport interface McpAuthContext {\n props: Record<string, unknown>;\n}\n\nconst authContextStorage = new AsyncLocalStorage<McpAuthContext>();\n\nexport function getMcpAuthContext(): McpAuthContext | undefined {\n return authContextStorage.getStore();\n}\n\nexport function runWithAuthContext<T>(context: McpAuthContext, fn: () => T): T {\n return authContextStorage.run(context, fn);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction invalidVerifiedContext(): never {\n throw new TypeError(\"Invalid verified OAuth request context\");\n}\n\nexport function getVerifiedOAuthAuthInfo(\n ctx: ExecutionContext\n): { authInfo: AuthInfo; props: Record<string, unknown> } | undefined {\n const symbolContext = ctx as ExecutionContext & Record<symbol, unknown>;\n if (!(VERIFIED_OAUTH_CONTEXT in symbolContext)) return undefined;\n\n const value = symbolContext[VERIFIED_OAUTH_CONTEXT];\n if (!isPlainRecord(value) || value.version !== 1) invalidVerifiedContext();\n\n const candidate = value as Partial<VerifiedWorkersOAuthContext>;\n const { token, clientId, scopes, expiresAt, resource, props } = candidate;\n if (\n typeof token !== \"string\" ||\n token.length === 0 ||\n typeof clientId !== \"string\" ||\n clientId.length === 0 ||\n !Array.isArray(scopes) ||\n !scopes.every((scope) => typeof scope === \"string\") ||\n !isPlainRecord(props)\n ) {\n invalidVerifiedContext();\n }\n\n if (\n expiresAt !== undefined &&\n (typeof expiresAt !== \"number\" ||\n !Number.isFinite(expiresAt) ||\n expiresAt <= 0)\n ) {\n invalidVerifiedContext();\n }\n\n let resourceUrl: URL | undefined;\n if (resource !== undefined) {\n if (typeof resource !== \"string\") invalidVerifiedContext();\n try {\n resourceUrl = new URL(resource);\n } catch {\n invalidVerifiedContext();\n }\n if (resourceUrl.protocol !== \"http:\" && resourceUrl.protocol !== \"https:\") {\n invalidVerifiedContext();\n }\n }\n\n if (ctx.props !== props) invalidVerifiedContext();\n\n return {\n props,\n authInfo: {\n token,\n clientId,\n scopes: [...scopes],\n ...(expiresAt !== undefined && { expiresAt }),\n ...(resourceUrl !== undefined && { resource: resourceUrl }),\n extra: { props }\n }\n };\n}\n","export function internalErrorResponse(\n id: string | number | null = null\n): Response {\n return Response.json(\n {\n jsonrpc: \"2.0\",\n error: { code: -32603, message: \"Internal server error\" },\n id\n },\n { status: 500 }\n );\n}\n\nexport function requestIdFromParsedBody(body: unknown): string | number | null {\n if (\n typeof body !== \"object\" ||\n body === null ||\n Array.isArray(body) ||\n !(\"method\" in body) ||\n typeof body.method !== \"string\" ||\n !(\"id\" in body)\n ) {\n return null;\n }\n return typeof body.id === \"string\" || typeof body.id === \"number\"\n ? body.id\n : null;\n}\n\nexport function reportHandlerError(\n onerror: ((error: Error) => void) | undefined,\n error: unknown\n): void {\n try {\n onerror?.(error instanceof Error ? error : new Error(String(error)));\n } catch {\n // Error reporting must not change the response.\n }\n}\n","import {\n WebStandardStreamableHTTPServerTransport,\n isJSONRPCRequest,\n type CreateMcpHandlerOptions,\n type McpHandlerRequestOptions,\n McpServer,\n type McpServerFactory,\n type Server\n} from \"@modelcontextprotocol/server\";\nimport {\n internalErrorResponse,\n reportHandlerError,\n requestIdFromParsedBody\n} from \"./handler-errors\";\n/**\n * Temporary adapter for Legacy compatibility on the SDK v2 transport.\n *\n * Local deltas from the upstream stateless fallback:\n *\n * - impossible stateless server-to-client requests fail immediately rather\n * than leaving the tool handler waiting for a session response.\n * - a factory that returns an instance still serving another request is\n * rejected before this request takes ownership of it, so the error path\n * never closes the other request's instance (mirrors upstream's\n * `assertNotServing` on the modern path).\n *\n * Streaming and keepalive behavior remain delegated to the SDK transport.\n * Remove this adapter once the SDK exposes the reverse-request policy directly.\n */\nexport function createLegacyCompatibilityRequestHandler(\n factory: McpServerFactory,\n handlerOptions: Pick<CreateMcpHandlerOptions, \"keepAliveMs\" | \"onerror\"> = {}\n) {\n const { keepAliveMs, onerror } = handlerOptions;\n const fetch = async (\n request: Request,\n requestOptions: McpHandlerRequestOptions | undefined\n ): Promise<Response> => {\n // Match the upstream Legacy fallback: GET and DELETE are session operations\n // and cannot be served by a fresh per-request transport. Reject\n // them before running a factory with application-visible side effects.\n if (request.method.toUpperCase() !== \"POST\") {\n return Response.json(\n {\n jsonrpc: \"2.0\",\n error: { code: -32000, message: \"Method not allowed.\" },\n id: null\n },\n { status: 405 }\n );\n }\n\n if (request.signal.aborted) {\n return new Response(null, { status: 499 });\n }\n\n let product: McpServer | Server | undefined;\n let transport: WebStandardStreamableHTTPServerTransport | undefined;\n let teardownPromise: Promise<void> | undefined;\n const teardown = () =>\n (teardownPromise ??= (async () => {\n await Promise.all([\n transport?.close().catch(() => {}),\n product?.close().catch(() => {})\n ]);\n })());\n const onAbort = () => void teardown();\n\n try {\n const candidate = await factory({\n era: \"legacy\",\n ...(requestOptions?.authInfo !== undefined && {\n authInfo: requestOptions.authInfo\n }),\n requestInfo: request\n });\n assertNotServing(candidate);\n product = candidate;\n transport = new WebStandardStreamableHTTPServerTransport({\n keepAliveMs,\n sessionIdGenerator: undefined\n });\n\n const send = transport.send.bind(transport);\n transport.send = async (message, sendOptions) => {\n if (isJSONRPCRequest(message)) {\n transport?.onmessage?.({\n jsonrpc: \"2.0\",\n id: message.id,\n error: {\n code: -32603,\n message:\n \"Server-to-client requests are unavailable in the Legacy compatibility lane. \" +\n \"Use inputRequired(...) for Stateless clients, or route \" +\n \"Legacy traffic to a sessionful transport.\"\n }\n });\n return;\n }\n await send(message, sendOptions);\n };\n\n await product.connect(transport);\n if (request.signal.aborted) {\n await teardown();\n return new Response(null, { status: 499 });\n }\n request.signal.addEventListener(\"abort\", onAbort, { once: true });\n const response = await transport.handleRequest(request, {\n ...(requestOptions?.authInfo !== undefined && {\n authInfo: requestOptions.authInfo\n }),\n ...(requestOptions?.parsedBody !== undefined && {\n parsedBody: requestOptions.parsedBody\n })\n });\n\n if (\n response.body === null ||\n !response.headers.get(\"content-type\")?.includes(\"text/event-stream\")\n ) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n return response;\n }\n\n const reader = response.body.getReader();\n const body = new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n const { done, value } = await reader.read();\n if (done) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n controller.close();\n } else if (value !== undefined) {\n controller.enqueue(value);\n }\n } catch (error) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n controller.error(error);\n }\n },\n async cancel(reason) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await reader.cancel(reason).catch(() => {});\n await teardown();\n }\n });\n return new Response(body, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers\n });\n } catch (error) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n reportHandlerError(onerror, error);\n return internalErrorResponse(\n requestIdFromParsedBody(requestOptions?.parsedBody)\n );\n }\n };\n\n return { fetch };\n}\n\nfunction assertNotServing(product: McpServer | Server): void {\n const server = product instanceof McpServer ? product.server : product;\n if (server.transport !== undefined) {\n throw new Error(\n \"The factory returned an instance that is still serving another \" +\n \"request. Return a new instance for each request.\"\n );\n }\n}\n","import {\n createMcpHandler as createSdkMcpHandler,\n hostHeaderValidationResponse,\n isLegacyRequest,\n localhostAllowedHostnames,\n localhostAllowedOrigins,\n originValidationResponse,\n type AuthInfo,\n type CreateMcpHandlerOptions as SdkCreateMcpHandlerOptions,\n type McpHandlerRequestOptions,\n type McpServerFactory,\n type ServerNotifier\n} from \"@modelcontextprotocol/server\";\nimport {\n getVerifiedOAuthAuthInfo,\n runWithAuthContext,\n type McpAuthContext\n} from \"./auth-context\";\nimport { internalErrorResponse, reportHandlerError } from \"./handler-errors\";\nimport { createLegacyCompatibilityRequestHandler } from \"./handler-legacy-compat\";\nimport type { CORSOptions } from \"../types\";\n\nexport interface CreateStatelessMcpHandlerOptions extends Omit<\n SdkCreateMcpHandlerOptions,\n \"bus\"\n> {\n /** Exact pathname handled by this Worker wrapper. @default \"/mcp\" */\n route?: string;\n /** CORS headers applied by the Worker wrapper. Pass `false` to disable. */\n corsOptions?: CORSOptions | false;\n /**\n * Restrict `Host` headers to these hostnames. Localhost and `workers.dev`\n * endpoints receive matching defaults; custom domains rely on Cloudflare\n * routing unless this option is set.\n */\n allowedHostnames?: string[];\n /**\n * Restrict present browser `Origin` headers to these hostnames. Requests\n * without an Origin (including non-browser MCP clients) remain valid. The\n * default includes localhost-class Origins, the endpoint's `workers.dev`\n * hostname, and a concrete `corsOptions.origin` hostname. Pass `\"*\"` only\n * when equivalent Origin validation runs in trusted middleware upstream.\n */\n allowedOriginHostnames?: string[] | \"*\";\n /** Application props exposed through {@link getMcpAuthContext}. */\n authContext?: McpAuthContext;\n}\n\nexport type StatelessMcpHandler = {\n (request: Request, env: unknown, ctx: ExecutionContext): Promise<Response>;\n fetch(\n request: Request,\n options?: McpHandlerRequestOptions\n ): Promise<Response>;\n notify: ServerNotifier;\n};\n\nexport type StatelessMcpServerInput = McpServerFactory;\n\nconst DEFAULT_CORS_OPTIONS: Required<CORSOptions> = {\n origin: \"*\",\n headers:\n \"Content-Type, Accept, Authorization, mcp-session-id, MCP-Protocol-Version, Mcp-Method, Mcp-Name\",\n methods: \"GET, POST, DELETE, OPTIONS\",\n exposeHeaders: \"mcp-session-id\",\n maxAge: 86400\n};\n\nfunction corsHeaders(options: CORSOptions = {}): Headers {\n const merged = { ...DEFAULT_CORS_OPTIONS, ...options };\n return new Headers({\n \"Access-Control-Allow-Headers\": merged.headers,\n \"Access-Control-Allow-Methods\": merged.methods,\n \"Access-Control-Allow-Origin\": merged.origin,\n \"Access-Control-Expose-Headers\": merged.exposeHeaders,\n \"Access-Control-Max-Age\": String(merged.maxAge)\n });\n}\n\nfunction withCors(response: Response, options: CORSOptions | false): Response {\n const headers = new Headers(response.headers);\n if (options === false) {\n for (const name of Array.from(headers.keys())) {\n if (name.toLowerCase().startsWith(\"access-control-\")) {\n headers.delete(name);\n }\n }\n } else {\n for (const [name, value] of corsHeaders(options)) {\n headers.set(name, value);\n }\n }\n return new Response(response.body, {\n status: response.status,\n statusText: response.statusText,\n headers\n });\n}\n\nfunction wrapResponseBodyWithAuthContext(\n response: Response,\n authContext: McpAuthContext | undefined\n): Response {\n if (!authContext || !response.body) return response;\n\n const reader = response.body.getReader();\n const body = new ReadableStream<Uint8Array>({\n pull(controller) {\n return runWithAuthContext(authContext, async () => {\n try {\n const { done, value } = await reader.read();\n if (done) {\n controller.close();\n } else {\n controller.enqueue(value);\n }\n } catch (error) {\n controller.error(error);\n }\n });\n },\n cancel(reason) {\n return runWithAuthContext(authContext, () => reader.cancel(reason));\n }\n });\n\n return new Response(body, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers\n });\n}\n\nexport function createStatelessMcpHandler(\n factory: StatelessMcpServerInput,\n options: CreateStatelessMcpHandlerOptions = {}\n): StatelessMcpHandler {\n const optionRecord = options as Record<string, unknown>;\n if (optionRecord.bus !== undefined) {\n throw new TypeError(\n 'createMcpHandler option \"bus\" is not exposed by the Agents SDK.'\n );\n }\n const legacyOnlyOption = [\n \"transport\",\n \"storage\",\n \"sessionIdGenerator\",\n \"onsessioninitialized\",\n \"onsessionclosed\",\n \"enableJsonResponse\",\n \"eventStore\",\n \"allowedHosts\",\n \"allowedOrigins\",\n \"enableDnsRebindingProtection\",\n \"retryInterval\"\n ].find((key) => optionRecord[key] !== undefined);\n if (legacyOnlyOption) {\n throw new TypeError(\n `createMcpHandler option \"${legacyOnlyOption}\" is only supported with an MCP SDK v1 server. The managed SDK v2 handler is stateless; remove this option or keep the v1 server during migration.`\n );\n }\n\n const {\n route = \"/mcp\",\n corsOptions = {},\n allowedHostnames,\n allowedOriginHostnames,\n authContext,\n legacy = \"stateless\",\n ...sdkOptions\n } = options;\n\n const sdkHandler = createSdkMcpHandler(factory, {\n ...sdkOptions,\n legacy: \"reject\"\n });\n const legacyCompatibilityHandler =\n legacy === \"stateless\"\n ? createLegacyCompatibilityRequestHandler(factory, {\n keepAliveMs: sdkOptions.keepAliveMs,\n onerror: sdkOptions.onerror\n })\n : undefined;\n\n const serve = async (\n request: Request,\n requestOptions?: McpHandlerRequestOptions,\n workerCtx?: ExecutionContext\n ): Promise<Response> => {\n const requestUrl = new URL(request.url);\n if (requestUrl.pathname !== route) {\n return withCors(new Response(\"Not Found\", { status: 404 }), corsOptions);\n }\n\n // The SDK app factories can distinguish their bind address from an\n // attacker-controlled Host header. A bare Worker cannot. Use defaults we\n // can establish independently: localhost-class names, a standard\n // workers.dev route, and any concrete CORS Origin the application chose.\n // Custom-domain deployments can provide explicit Host and Origin lists.\n const localEndpoint = localhostAllowedHostnames().includes(\n requestUrl.hostname\n );\n const workersDevEndpoint = requestUrl.hostname.endsWith(\".workers.dev\");\n const acceptedHostnames =\n allowedHostnames ??\n (localEndpoint\n ? localhostAllowedHostnames()\n : workersDevEndpoint\n ? [requestUrl.hostname]\n : undefined);\n const hostRejection = acceptedHostnames\n ? hostHeaderValidationResponse(request, acceptedHostnames)\n : undefined;\n if (hostRejection) {\n return withCors(hostRejection, corsOptions);\n }\n if (allowedOriginHostnames !== \"*\") {\n let acceptedOriginHostnames = allowedOriginHostnames;\n if (acceptedOriginHostnames === undefined) {\n const defaults = new Set(localhostAllowedOrigins());\n if (workersDevEndpoint) defaults.add(requestUrl.hostname);\n if (corsOptions !== false && corsOptions.origin !== undefined) {\n try {\n const configuredOrigin = new URL(corsOptions.origin);\n if (\n (configuredOrigin.protocol === \"http:\" ||\n configuredOrigin.protocol === \"https:\") &&\n configuredOrigin.hostname\n ) {\n defaults.add(configuredOrigin.hostname);\n }\n } catch {\n // A wildcard or malformed CORS value does not expand the allowlist.\n }\n }\n acceptedOriginHostnames = [...defaults];\n }\n const originRejection = originValidationResponse(\n request,\n acceptedOriginHostnames ?? []\n );\n if (originRejection) {\n return withCors(originRejection, corsOptions);\n }\n }\n\n if (request.method === \"OPTIONS\" && corsOptions !== false) {\n return new Response(null, { headers: corsHeaders(corsOptions) });\n }\n\n const legacyRequest =\n legacyCompatibilityHandler !== undefined &&\n (await isLegacyRequest(request, requestOptions?.parsedBody));\n\n try {\n const verified = workerCtx\n ? getVerifiedOAuthAuthInfo(workerCtx)\n : undefined;\n const explicitAuthInfo = requestOptions?.authInfo;\n if (\n verified &&\n explicitAuthInfo &&\n explicitAuthInfo.clientId !== verified.authInfo.clientId\n ) {\n throw new TypeError(\"Conflicting verified OAuth client identity\");\n }\n\n const authInfo: AuthInfo | undefined =\n explicitAuthInfo ?? verified?.authInfo;\n const resolvedAuthContext =\n authContext ??\n (verified\n ? { props: verified.props }\n : workerCtx?.props && Object.keys(workerCtx.props).length > 0\n ? { props: workerCtx.props as Record<string, unknown> }\n : undefined);\n const upstreamOptions: McpHandlerRequestOptions | undefined =\n requestOptions || authInfo\n ? { ...requestOptions, ...(authInfo && { authInfo }) }\n : undefined;\n const invoke = async () => {\n if (legacyRequest && legacyCompatibilityHandler) {\n return legacyCompatibilityHandler.fetch(request, upstreamOptions);\n }\n return sdkHandler.fetch(request, upstreamOptions);\n };\n const response = resolvedAuthContext\n ? await runWithAuthContext(resolvedAuthContext, invoke)\n : await invoke();\n return withCors(\n wrapResponseBodyWithAuthContext(response, resolvedAuthContext),\n corsOptions\n );\n } catch (error) {\n reportHandlerError(sdkOptions.onerror, error);\n return withCors(internalErrorResponse(), corsOptions);\n }\n };\n\n const callable = (request: Request, _env: unknown, ctx: ExecutionContext) =>\n serve(request, undefined, ctx);\n const fetch = (request: Request, requestOptions?: McpHandlerRequestOptions) =>\n serve(request, requestOptions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,MAAM,SAAS,SAAkB,mBAC/B,MAAM,SAAS,cAAc;CAE/B,OAAO,OAAO,OAAO,UAAU;EAC7B;EACA,QAAQ,WAAW;CACrB,CAAC;AACH"}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
_ as LifecycleJobContext,
|
|
3
3
|
s as LifecycleCapability,
|
|
4
4
|
v as LifecycleJobOutcome
|
|
5
|
-
} from "../../capability-runner-
|
|
5
|
+
} from "../../capability-runner-BiVUtjqC.js";
|
|
6
6
|
import {
|
|
7
7
|
o as ChannelMessage,
|
|
8
8
|
p as DeliveryResult
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
i as HarnessSession,
|
|
20
20
|
t as AgentHarness
|
|
21
21
|
} from "../../harness-B6B9S3rb.js";
|
|
22
|
-
import { t as ChannelGateway } from "../../gateway-
|
|
22
|
+
import { t as ChannelGateway } from "../../gateway-BFO6vRDn.js";
|
|
23
23
|
import {
|
|
24
24
|
LanguageModel,
|
|
25
25
|
StopCondition,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "../../classPrivateFieldGet2-DZBYAB34.js";
|
|
2
2
|
import { t as _classPrivateMethodInitSpec } from "../../classPrivateMethodInitSpec-qMjJ6sHQ.js";
|
|
3
|
-
import { t as LifecycleCapability } from "../../capability-
|
|
3
|
+
import { t as LifecycleCapability } from "../../capability-DBAKc6UZ.js";
|
|
4
4
|
import { a as toTranscriptMessage, i as toResponseChunks, n as awaitsInput, o as toUIMessage, r as toResponseChunk, s as toUIMessageChunk, t as answerToolCall } from "../../turns-DCV3ycDl.js";
|
|
5
5
|
import { convertToModelMessages, jsonSchema, stepCountIs, streamText, toUIMessageStream, tool } from "ai";
|
|
6
6
|
//#region src/harness/ai-sdk/harness.ts
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
n as CapabilityStartContext,
|
|
4
4
|
s as LifecycleCapability,
|
|
5
5
|
v as LifecycleJobOutcome
|
|
6
|
-
} from "../../capability-runner-
|
|
6
|
+
} from "../../capability-runner-BiVUtjqC.js";
|
|
7
7
|
import {
|
|
8
8
|
d as ContainerInputPart,
|
|
9
9
|
f as ContainerMessage,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
u as ContainerInput,
|
|
15
15
|
x as JsonValue
|
|
16
16
|
} from "../../protocol-BEgrJYC5.js";
|
|
17
|
-
import { r as JsonValue$1, t as HarnessStore } from "../../store-
|
|
17
|
+
import { r as JsonValue$1, t as HarnessStore } from "../../store-BKM4Xm9M.js";
|
|
18
18
|
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
19
19
|
|
|
20
20
|
//#region src/harness/container/egress.d.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "../../classPrivateFieldGet2-DZBYAB34.js";
|
|
2
2
|
import { t as _classPrivateMethodInitSpec } from "../../classPrivateMethodInitSpec-qMjJ6sHQ.js";
|
|
3
|
-
import { t as LifecycleCapability } from "../../capability-
|
|
4
|
-
import "../../lifecycle-
|
|
5
|
-
import { n as openHarnessStore } from "../../store-
|
|
3
|
+
import { t as LifecycleCapability } from "../../capability-DBAKc6UZ.js";
|
|
4
|
+
import "../../lifecycle-DGorpAmA.js";
|
|
5
|
+
import { n as openHarnessStore } from "../../store-CslVzfN7.js";
|
|
6
6
|
import { d as parseDaemonMessage, i as CONTAINER_HEALTH_PATH, l as chunkEntries, o as CONTAINER_SESSION_PATH, r as CONTAINER_ENV, s as CONTAINER_TOKEN_HEADER } from "../../protocol-cOklVBBD.js";
|
|
7
7
|
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
8
8
|
//#region src/harness/container/link.ts
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
n as CapabilityStartContext,
|
|
4
4
|
s as LifecycleCapability,
|
|
5
5
|
v as LifecycleJobOutcome
|
|
6
|
-
} from "../../capability-runner-
|
|
6
|
+
} from "../../capability-runner-BiVUtjqC.js";
|
|
7
7
|
import { OpenCodeWorkerd } from "@opencode/sdk/workerd";
|
|
8
8
|
|
|
9
9
|
//#region src/harness/opencode/types.d.ts
|
|
@@ -30,7 +30,10 @@ type OpenCodeInput =
|
|
|
30
30
|
type OpenCodeMessage = Awaited<
|
|
31
31
|
ReturnType<OpenCode["sessions"]["context"]>
|
|
32
32
|
>[number];
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* One of OpenCode's own events: durable transcript events and live deltas.
|
|
35
|
+
* `session.events()` translates these into `OpenCodeSessionEvent`s.
|
|
36
|
+
*/
|
|
34
37
|
type OpenCodeEvent =
|
|
35
38
|
ReturnType<OpenCode["events"]["subscribe"]> extends AsyncIterable<infer E>
|
|
36
39
|
? E
|
|
@@ -101,6 +104,173 @@ type OpenCodeSessionInfo = {
|
|
|
101
104
|
readonly title?: string /** Running, input waiting, or a turn a restart cut off, about to resume. */;
|
|
102
105
|
readonly busy: boolean;
|
|
103
106
|
};
|
|
107
|
+
/** A permission OpenCode asked for, waiting on a reply. */
|
|
108
|
+
type OpenCodePermission = {
|
|
109
|
+
readonly id: string;
|
|
110
|
+
readonly session: OpenCodeSessionId /** What OpenCode wants to do, such as `edit` or `webfetch`. */;
|
|
111
|
+
readonly action: string /** What the action applies to, such as paths or URLs. */;
|
|
112
|
+
readonly resources: readonly string[];
|
|
113
|
+
readonly message?: string;
|
|
114
|
+
};
|
|
115
|
+
/** How an assistant message's step ended, as OpenCode reports it. */
|
|
116
|
+
type OpenCodeFinish =
|
|
117
|
+
| "stop"
|
|
118
|
+
| "length"
|
|
119
|
+
| "tool-calls"
|
|
120
|
+
| "content-filter"
|
|
121
|
+
| "error"
|
|
122
|
+
| "unknown";
|
|
123
|
+
/**
|
|
124
|
+
* One event on a session's stream, translated from OpenCode's events into
|
|
125
|
+
* the same kinds of event `PiHarness` and `ContainerHarness` report.
|
|
126
|
+
* `messageId` is OpenCode's assistant message id. Text and reasoning are
|
|
127
|
+
* addressed by `ordinal`, their position among the message's parts of the
|
|
128
|
+
* same kind.
|
|
129
|
+
*/
|
|
130
|
+
type OpenCodeSessionEvent =
|
|
131
|
+
/**
|
|
132
|
+
* An input is in OpenCode's inbox. Every input goes through it, so this
|
|
133
|
+
* comes before `operation_start` even when the session is idle.
|
|
134
|
+
*/
|
|
135
|
+
| {
|
|
136
|
+
readonly type: "operation_queued";
|
|
137
|
+
readonly operationId: string;
|
|
138
|
+
} /** A queued input was withdrawn before it ran. */
|
|
139
|
+
| {
|
|
140
|
+
readonly type: "operation_withdrawn";
|
|
141
|
+
readonly operationId: string;
|
|
142
|
+
} /** An input joined the transcript; the next assistant message answers it. */
|
|
143
|
+
| {
|
|
144
|
+
readonly type: "operation_start";
|
|
145
|
+
readonly operationId: string;
|
|
146
|
+
} /** An input has its answer: the same result `wait()` returns. */
|
|
147
|
+
| {
|
|
148
|
+
readonly type: "operation_end";
|
|
149
|
+
readonly result: OpenCodeOperationResult;
|
|
150
|
+
} /** OpenCode started a run. One run answers every input it drains. */
|
|
151
|
+
| {
|
|
152
|
+
readonly type: "run_start";
|
|
153
|
+
}
|
|
154
|
+
| {
|
|
155
|
+
readonly type: "run_end";
|
|
156
|
+
readonly outcome: "succeeded" | "failed" | "interrupted";
|
|
157
|
+
readonly error?: string;
|
|
158
|
+
}
|
|
159
|
+
| {
|
|
160
|
+
readonly type: "message_start";
|
|
161
|
+
readonly messageId: string;
|
|
162
|
+
readonly agent: string;
|
|
163
|
+
readonly model: {
|
|
164
|
+
readonly providerID: string;
|
|
165
|
+
readonly id: string;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
| {
|
|
169
|
+
readonly type: "text_delta";
|
|
170
|
+
readonly messageId: string;
|
|
171
|
+
readonly ordinal: number;
|
|
172
|
+
readonly delta: string;
|
|
173
|
+
} /** A text part is complete; `text` is the whole part. */
|
|
174
|
+
| {
|
|
175
|
+
readonly type: "text_end";
|
|
176
|
+
readonly messageId: string;
|
|
177
|
+
readonly ordinal: number;
|
|
178
|
+
readonly text: string;
|
|
179
|
+
}
|
|
180
|
+
| {
|
|
181
|
+
readonly type: "reasoning_delta";
|
|
182
|
+
readonly messageId: string;
|
|
183
|
+
readonly ordinal: number;
|
|
184
|
+
readonly delta: string;
|
|
185
|
+
}
|
|
186
|
+
| {
|
|
187
|
+
readonly type: "reasoning_end";
|
|
188
|
+
readonly messageId: string;
|
|
189
|
+
readonly ordinal: number;
|
|
190
|
+
readonly text: string;
|
|
191
|
+
} /** The model called a tool and OpenCode has its whole input. */
|
|
192
|
+
| {
|
|
193
|
+
readonly type: "tool_start";
|
|
194
|
+
readonly messageId: string;
|
|
195
|
+
readonly toolCallId: string;
|
|
196
|
+
readonly name: string;
|
|
197
|
+
readonly input: Readonly<Record<string, unknown>>;
|
|
198
|
+
}
|
|
199
|
+
| {
|
|
200
|
+
readonly type: "tool_end";
|
|
201
|
+
readonly messageId: string;
|
|
202
|
+
readonly toolCallId: string;
|
|
203
|
+
readonly name: string;
|
|
204
|
+
readonly error: boolean /** The tool's text output, or its error message. */;
|
|
205
|
+
readonly output: string;
|
|
206
|
+
}
|
|
207
|
+
| {
|
|
208
|
+
readonly type: "message_end";
|
|
209
|
+
readonly messageId: string;
|
|
210
|
+
readonly finish: OpenCodeFinish;
|
|
211
|
+
readonly error?: string;
|
|
212
|
+
} /** A model call failed and OpenCode will try again at `at`. */
|
|
213
|
+
| {
|
|
214
|
+
readonly type: "retry_scheduled";
|
|
215
|
+
readonly messageId: string;
|
|
216
|
+
readonly attempt: number;
|
|
217
|
+
readonly at: number;
|
|
218
|
+
readonly error: string;
|
|
219
|
+
}
|
|
220
|
+
| {
|
|
221
|
+
readonly type: "compaction_start";
|
|
222
|
+
readonly reason: "auto" | "manual";
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* OpenCode compacted the session: `messages()` is now shorter, and
|
|
226
|
+
* `history()` has a compaction message. Read the transcript again.
|
|
227
|
+
*/
|
|
228
|
+
| {
|
|
229
|
+
readonly type: "transcript_reset";
|
|
230
|
+
readonly reason: "compaction";
|
|
231
|
+
}
|
|
232
|
+
| {
|
|
233
|
+
readonly type: "permission_asked";
|
|
234
|
+
readonly permission: OpenCodePermission;
|
|
235
|
+
}
|
|
236
|
+
| {
|
|
237
|
+
readonly type: "permission_replied";
|
|
238
|
+
readonly permissionId: string;
|
|
239
|
+
readonly reply: "once" | "always" | "reject";
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Something went wrong outside a model step: `compaction_failed`, or
|
|
243
|
+
* `events_failed` when OpenCode's event stream ended with an error. No
|
|
244
|
+
* more events follow `events_failed`; open a new stream.
|
|
245
|
+
*/
|
|
246
|
+
| {
|
|
247
|
+
readonly type: "fault";
|
|
248
|
+
readonly code: "compaction_failed" | "events_failed";
|
|
249
|
+
readonly message: string;
|
|
250
|
+
};
|
|
251
|
+
/** A session's state when its event stream opens. */
|
|
252
|
+
type OpenCodeSessionSnapshot = {
|
|
253
|
+
readonly session: OpenCodeSessionId /** The whole transcript, compacted messages included: `history()`. */;
|
|
254
|
+
readonly messages: readonly OpenCodeMessage[];
|
|
255
|
+
readonly pending: readonly OpenCodePendingOperation[];
|
|
256
|
+
readonly busy: boolean /** Permissions OpenCode is waiting on. */;
|
|
257
|
+
readonly permissions: readonly OpenCodePermission[];
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* A session's events: the snapshot taken when the stream opened, then every
|
|
261
|
+
* event after it, in batches, including any that arrived before `start()`.
|
|
262
|
+
* An event may repeat what the snapshot already shows; messages are keyed
|
|
263
|
+
* by id. Live: events reach listeners in the isolate that runs the harness,
|
|
264
|
+
* and the stream holds OpenCode open until `stop()`. Call `stop()` when
|
|
265
|
+
* done, started or not.
|
|
266
|
+
*/
|
|
267
|
+
type OpenCodeEventStream = {
|
|
268
|
+
readonly snapshot: OpenCodeSessionSnapshot /** Start delivering events. Call once. */;
|
|
269
|
+
start(
|
|
270
|
+
listener: (events: readonly OpenCodeSessionEvent[]) => void
|
|
271
|
+
): void /** Stop delivering events and release OpenCode. */;
|
|
272
|
+
stop(): Promise<void>;
|
|
273
|
+
};
|
|
104
274
|
//#endregion
|
|
105
275
|
//#region src/harness/opencode/harness.d.ts
|
|
106
276
|
/** The root session's id. OpenCode session ids start with `ses`. */
|
|
@@ -304,12 +474,13 @@ declare class OpenCodeSession {
|
|
|
304
474
|
*/
|
|
305
475
|
history(): Promise<OpenCodeMessage[]>;
|
|
306
476
|
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* durable
|
|
477
|
+
* The session's state now, then everything that happens to it after, as
|
|
478
|
+
* `OpenCodeSessionEvent`s: the same kinds of event `PiHarness` reports,
|
|
479
|
+
* live text deltas included. The stream holds OpenCode open until
|
|
480
|
+
* `stop()`. For OpenCode's own events, durable and resumable by sequence
|
|
481
|
+
* number, use `log()`.
|
|
311
482
|
*/
|
|
312
|
-
events(
|
|
483
|
+
events(): Promise<OpenCodeEventStream>;
|
|
313
484
|
/**
|
|
314
485
|
* The session's durable events after sequence number `after` (from the
|
|
315
486
|
* start by default), then, with `follow`, new ones as they are committed,
|
|
@@ -344,6 +515,8 @@ declare class OpenCodeSessions {
|
|
|
344
515
|
export {
|
|
345
516
|
type OpenCode,
|
|
346
517
|
type OpenCodeEvent,
|
|
518
|
+
type OpenCodeEventStream,
|
|
519
|
+
type OpenCodeFinish,
|
|
347
520
|
OpenCodeHarness,
|
|
348
521
|
type OpenCodeHarnessContext,
|
|
349
522
|
type OpenCodeHarnessFactory,
|
|
@@ -354,13 +527,16 @@ export {
|
|
|
354
527
|
type OpenCodeModel,
|
|
355
528
|
type OpenCodeOperationResult,
|
|
356
529
|
type OpenCodePendingOperation,
|
|
530
|
+
type OpenCodePermission,
|
|
357
531
|
type OpenCodePromptResponse,
|
|
358
532
|
type OpenCodeReceipt,
|
|
359
533
|
OpenCodeSession,
|
|
360
534
|
type OpenCodeSessionDefaults,
|
|
535
|
+
type OpenCodeSessionEvent,
|
|
361
536
|
type OpenCodeSessionId,
|
|
362
537
|
type OpenCodeSessionInfo,
|
|
363
538
|
type OpenCodeSessionOptions,
|
|
539
|
+
type OpenCodeSessionSnapshot,
|
|
364
540
|
OpenCodeSessions,
|
|
365
541
|
type OpenCodeSubmitOptions,
|
|
366
542
|
type OpenCodeWhenBusy,
|