agents 0.14.4 → 0.15.0

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.
@@ -60,6 +60,12 @@ import {
60
60
  Tool as Tool$1
61
61
  } from "@modelcontextprotocol/sdk/types.js";
62
62
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
63
+ import {
64
+ EventStore as EventStore$1,
65
+ StreamId as StreamId$1,
66
+ WebStandardStreamableHTTPServerTransport,
67
+ WebStandardStreamableHTTPServerTransportOptions
68
+ } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
63
69
  import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
64
70
  import {
65
71
  Transport,
@@ -72,10 +78,7 @@ import {
72
78
  EventStore,
73
79
  StreamId
74
80
  } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
75
- import {
76
- EventStore as EventStore$1,
77
- StreamId as StreamId$1
78
- } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
81
+ import { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
79
82
 
80
83
  //#region src/sub-routing.d.ts
81
84
  /**
@@ -240,136 +243,150 @@ declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTran
240
243
  }
241
244
  //#endregion
242
245
  //#region src/mcp/worker-transport.d.ts
246
+ /**
247
+ * Pluggable storage adapter for persisting `WorkerTransport` state across
248
+ * Durable Object hibernation / restart cycles.
249
+ *
250
+ * A typical implementation reads/writes a single key on `this.ctx.storage`
251
+ * inside a Durable Object or Agent.
252
+ */
243
253
  interface MCPStorageApi {
244
254
  get(): Promise<TransportState | undefined> | TransportState | undefined;
245
255
  set(state: TransportState): Promise<void> | void;
246
256
  }
257
+ /** Shape of the persisted transport state. */
247
258
  interface TransportState {
248
259
  sessionId?: string;
249
260
  initialized: boolean;
250
261
  initializeParams?: InitializeRequestParams;
251
262
  }
252
- interface WorkerTransportOptions {
253
- /**
254
- * Function that generates a session ID for the transport.
255
- * The session ID SHOULD be globally unique and cryptographically secure.
256
- * Return undefined to disable session management (stateless mode).
257
- */
258
- sessionIdGenerator?: () => string;
259
- /**
260
- * Enable traditional Request/Response mode, this will disable streaming.
261
- */
262
- enableJsonResponse?: boolean;
263
- /**
264
- * Callback fired when a new session is initialized.
265
- */
266
- onsessioninitialized?: (sessionId: string) => void;
263
+ interface WorkerTransportOptions extends WebStandardStreamableHTTPServerTransportOptions {
267
264
  /**
268
- * Callback fired when a session is closed via DELETE request.
265
+ * CORS options applied to every response and to OPTIONS preflight.
266
+ * Defaults: `origin: *`, expose `mcp-session-id`, allow the standard MCP
267
+ * methods/headers, max-age 86400.
269
268
  */
270
- onsessionclosed?: (sessionId: string) => void;
271
269
  corsOptions?: CORSOptions;
272
270
  /**
273
- * Optional storage api for persisting transport state.
274
- * Use this to store session state in Durable Object/Agent storage
275
- * so it survives hibernation/restart.
271
+ * Optional storage adapter for persisting transport state across DO
272
+ * hibernation / restart. Use this to keep an MCP session alive across
273
+ * Durable Object wake-ups.
276
274
  */
277
275
  storage?: MCPStorageApi;
278
- /**
279
- * Event store for SSE resumability.
280
- *
281
- * When set, the transport assigns a globally-unique `id:` to each SSE
282
- * event and replays missed events when a client reconnects with the
283
- * `Last-Event-ID` header. Both GET (standalone listen stream) and POST
284
- * (tool response stream) events are stored and replayable per the
285
- * MCP 2025-03-26 spec.
286
- *
287
- * Configuring an event store **disables the server-side keepalive**
288
- * on the standalone GET stream — idle drops are recovered by
289
- * reconnect rather than prevented by writing bytes. Without an event
290
- * store, the GET stream still gets the 25s comment-frame keepalive
291
- * so long-lived idle listeners aren't closed by the Cloudflare edge
292
- * ~5min watchdog.
293
- *
294
- * POST response streams always get the keepalive regardless of this
295
- * setting: in-progress tool calls have no way to recover
296
- * mid-execution without staying connected, so we don't let the
297
- * stream drop in the first place.
298
- *
299
- * Bring your own {@link EventStore} implementation — e.g.
300
- * `new DurableObjectEventStore(this.ctx.storage)` when embedding
301
- * `WorkerTransport` inside a Durable Object / Agent. See
302
- * cloudflare/agents#1583.
303
- */
304
- eventStore?: EventStore;
305
- /**
306
- * Retry interval in milliseconds to suggest to clients in SSE retry field.
307
- * Controls client reconnection timing for polling behavior.
308
- */
309
- retryInterval?: number;
310
276
  }
311
- declare class WorkerTransport implements Transport {
312
- started: boolean;
313
- private initialized;
314
- private sessionIdGenerator?;
315
- private enableJsonResponse;
316
- private onsessioninitialized?;
317
- private onsessionclosed?;
318
- private standaloneSseStreamId;
319
- private streamMapping;
320
- private requestToStreamMapping;
321
- private requestResponseMap;
322
- private corsOptions?;
323
- private storage?;
324
- private stateRestored;
325
- private eventStore?;
326
- private retryInterval?;
327
- private initializeParams?;
328
- sessionId?: string;
329
- onclose?: () => void;
330
- onerror?: (error: Error) => void;
331
- onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
277
+ declare class WorkerTransport extends WebStandardStreamableHTTPServerTransport {
278
+ private readonly _corsOptions?;
279
+ private readonly _storage?;
280
+ private _stateRestored;
281
+ private _capturedInitializeParams?;
282
+ private _userOnSessionInitialized?;
283
+ private _bridgeInstalled;
284
+ /**
285
+ * Tracks keepalive interval cleanups so we can fire them eagerly when the
286
+ * SDK closes the underlying SSE stream via `closeSSEStream(requestId)` or
287
+ * `closeStandaloneSSEStream()`. Keyed by the JSON-RPC request id that
288
+ * triggered the stream, or the sentinel for the standalone GET stream.
289
+ */
290
+ private readonly _keepaliveCleanups;
291
+ /**
292
+ * Most recent JSON-RPC request id seen on an incoming POST. Used to key
293
+ * keepalive cleanups when the response is an SSE stream tied to that
294
+ * request (so `closeSSEStream(id)` can find and clear the interval).
295
+ */
296
+ private _pendingRequestId?;
297
+ /**
298
+ * Request ids whose SSE stream was deliberately torn down via
299
+ * `closeSSEStream`. The SDK's `send()` throws "No connection established"
300
+ * when a request id has no stream — a race that surfaces whenever the
301
+ * server's tool handler resolves *after* the caller closed the stream
302
+ * (e.g. polling-style early-close, or test fixtures closing mid-flight).
303
+ * We swallow `send()` for these ids so the rejection doesn't bubble out
304
+ * of the protocol layer as an unhandled rejection. Mirrors the
305
+ * silent-noop behaviour of the pre-refactor `WorkerTransport`.
306
+ */
307
+ private readonly _closedRequestIds;
332
308
  constructor(options?: WorkerTransportOptions);
333
309
  /**
334
- * Restore transport state from persistent storage.
335
- * This is automatically called on start.
310
+ * Backwards-compatible alias for the SDK's internal `_started` flag.
311
+ * Several callers and tests check `transport.started` directly.
336
312
  */
337
- private restoreState;
313
+ get started(): boolean;
338
314
  /**
339
- * Persist current transport state to storage.
315
+ * Top-level request entry point. Handles CORS preflight, restores any
316
+ * persisted state on first invocation, then delegates to the SDK transport
317
+ * and finally appends CORS headers + keepalive to whatever response comes
318
+ * back.
340
319
  */
341
- private saveState;
342
- start(): Promise<void>;
320
+ handleRequest(
321
+ request: Request,
322
+ options?: {
323
+ parsedBody?: unknown;
324
+ authInfo?: AuthInfo;
325
+ }
326
+ ): Promise<Response>;
343
327
  /**
344
- * Validates the MCP-Protocol-Version header on incoming requests.
345
- *
346
- * This performs a simple check: if a version header is present, it must be
347
- * in the SUPPORTED_PROTOCOL_VERSIONS list. We do not track the negotiated
348
- * version or enforce version consistency across requests - the SDK handles
349
- * version negotiation during initialization, and we simply reject any
350
- * explicitly unsupported versions.
351
- *
352
- * - Header present and supported: Accept
353
- * - Header present and unsupported: 400 Bad Request
354
- * - Header missing: Accept (version validation is optional)
355
- */
356
- private validateProtocolVersion;
357
- private getHeaders;
358
- handleRequest(request: Request, parsedBody?: unknown): Promise<Response>;
359
- private handleGetRequest;
360
- private handlePostRequest;
361
- private handleDeleteRequest;
362
- private handleOptionsRequest;
363
- private handleUnsupportedRequest;
364
- private validateSession;
328
+ * The SDK's 405 responses advertise `Allow: GET, POST, DELETE` because
329
+ * OPTIONS is handled outside the SDK. Since our wrapper *does* handle
330
+ * OPTIONS, advertise it in `Allow` so clients can probe accurately.
331
+ */
332
+ private normalizeAllowHeader;
333
+ closeSSEStream(requestId: RequestId): void;
334
+ closeStandaloneSSEStream(): void;
365
335
  close(): Promise<void>;
366
336
  /**
367
- * Close an SSE stream for a specific request, triggering client reconnection.
368
- * Use this to implement polling behavior during long-running operations -
369
- * client will reconnect after the retry interval specified in the priming event.
337
+ * Swallow two classes of message that would otherwise surface as
338
+ * unhandled rejections from the SDK transport's `send()`:
339
+ *
340
+ * 1. Replayed initialize responses (the `RESTORE_REQUEST_ID` sentinel)
341
+ * — we synthesise these in `restoreState()` to rebuild server
342
+ * capabilities; there's no real client waiting for the response.
343
+ * 2. Sends for a request id whose SSE stream has been deliberately
344
+ * closed via `closeSSEStream`. The protocol layer's tool-handler
345
+ * promise may settle after the close, and the SDK's `send()` throws
346
+ * "No connection established" — a race the pre-refactor transport
347
+ * silently swallowed.
348
+ *
349
+ * Everything else is delegated. We use `await super.send(...)` rather
350
+ * than `return super.send(...)` so any rejection is observed inside this
351
+ * async frame; without the await, the test runner's
352
+ * unhandled-rejection tracker can fire before the caller's own `await`
353
+ * observes it.
370
354
  */
371
- closeSSEStream(requestId: RequestId): void;
372
355
  send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
356
+ /**
357
+ * If the response is an SSE stream, tee the body through a TransformStream
358
+ * that injects a `: keepalive\n\n` comment frame every 25s. The interval
359
+ * is cleared when the wrapped stream closes — which happens both when the
360
+ * SDK ends the underlying stream naturally and when `closeSSEStream` is
361
+ * called.
362
+ *
363
+ * Keepalive policy:
364
+ * - POST response streams (`key` is a request id): always keepalive.
365
+ * In-progress tool calls have no recovery path — if the stream drops
366
+ * mid-execution the result is lost — so we keep it under the
367
+ * Cloudflare edge ~5min idle watchdog.
368
+ * - Standalone GET stream (`key === "_standalone"`): keepalive only
369
+ * when no `eventStore` is configured. When resumability is enabled,
370
+ * clients reconnect with `Last-Event-ID` after an idle drop, so we
371
+ * skip the keepalive and let the DO hibernate.
372
+ *
373
+ * Uses the shared `sse-keepalive` constants so both this wrapper and
374
+ * `McpAgent.serve()` write identical frames at the same cadence.
375
+ * See cloudflare/agents#1583.
376
+ */
377
+ private withKeepalive;
378
+ /**
379
+ * Does the SDK transport have an `eventStore`? Reaches into the SDK's
380
+ * private field because the option isn't surfaced on the public API —
381
+ * we only need a yes/no for keepalive policy.
382
+ */
383
+ private eventStoreConfigured;
384
+ private getCorsHeaders;
385
+ private withCorsHeaders;
386
+ private installOnSessionInitializedBridge;
387
+ private captureInitializeParams;
388
+ private restoreState;
389
+ private saveState;
373
390
  }
374
391
  //#endregion
375
392
  //#region src/mcp/auth-context.d.ts
@@ -4777,4 +4794,4 @@ export {
4777
4794
  MCPServer as z,
4778
4795
  WorkerTransport as zt
4779
4796
  };
4780
- //# sourceMappingURL=agent-tool-types-V25Z_HcX.d.ts.map
4797
+ //# sourceMappingURL=agent-tool-types-VPsjVYL0.d.ts.map
@@ -16,7 +16,7 @@ import {
16
16
  s as AgentToolInterruptedReason,
17
17
  t as AgentToolChildAdapter,
18
18
  u as AgentToolRunInspection
19
- } from "./agent-tool-types-V25Z_HcX.js";
19
+ } from "./agent-tool-types-VPsjVYL0.js";
20
20
  export {
21
21
  AgentToolChildAdapter,
22
22
  AgentToolDisplayMetadata,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  a as AgentToolEventState,
3
3
  i as AgentToolEventMessage
4
- } from "./agent-tool-types-V25Z_HcX.js";
4
+ } from "./agent-tool-types-VPsjVYL0.js";
5
5
 
6
6
  //#region src/chat/agent-tools.d.ts
7
7
  declare function createAgentToolEventState(): AgentToolEventState;
@@ -11,4 +11,4 @@ declare function applyAgentToolEvent(
11
11
  ): AgentToolEventState;
12
12
  //#endregion
13
13
  export { createAgentToolEventState as n, applyAgentToolEvent as t };
14
- //# sourceMappingURL=agent-tools-C-9s151X.d.ts.map
14
+ //# sourceMappingURL=agent-tools-BGpgfpJT.d.ts.map
@@ -16,7 +16,7 @@ import {
16
16
  s as AgentToolInterruptedReason,
17
17
  t as AgentToolChildAdapter,
18
18
  u as AgentToolRunInspection
19
- } from "./agent-tool-types-V25Z_HcX.js";
19
+ } from "./agent-tool-types-VPsjVYL0.js";
20
20
  import { Tool } from "ai";
21
21
 
22
22
  //#region src/agent-tools.d.ts
@@ -3,11 +3,11 @@ import {
3
3
  d as AgentToolRunState,
4
4
  i as AgentToolEventMessage,
5
5
  r as AgentToolEvent
6
- } from "../agent-tool-types-V25Z_HcX.js";
6
+ } from "../agent-tool-types-VPsjVYL0.js";
7
7
  import {
8
8
  n as createAgentToolEventState,
9
9
  t as applyAgentToolEvent
10
- } from "../agent-tools-C-9s151X.js";
10
+ } from "../agent-tools-BGpgfpJT.js";
11
11
  import { JSONSchema7, Tool, ToolSet, UIMessage } from "ai";
12
12
  import { Connection } from "agents";
13
13
 
@@ -2,7 +2,7 @@ import {
2
2
  b as Agent,
3
3
  et as SubAgentClass,
4
4
  tt as SubAgentStub
5
- } from "../agent-tool-types-V25Z_HcX.js";
5
+ } from "../agent-tool-types-VPsjVYL0.js";
6
6
  import { Lock, QueueEntry, StateAdapter } from "chat";
7
7
 
8
8
  //#region src/chat-sdk/agent.d.ts
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as Agent } from "./agent-tool-types-V25Z_HcX.js";
1
+ import { b as Agent } from "./agent-tool-types-VPsjVYL0.js";
2
2
  import {
3
3
  ClientParameters,
4
4
  Method,
package/dist/index.d.ts CHANGED
@@ -71,7 +71,8 @@ import {
71
71
  xt as normalizeServerId,
72
72
  y as AddRpcMcpServerOptions,
73
73
  z as MCPServer
74
- } from "./agent-tool-types-V25Z_HcX.js";
74
+ } from "./agent-tool-types-VPsjVYL0.js";
75
+ import { n as camelCaseToKebabCase } from "./utils-CGtGDSgA.js";
75
76
  import { t as RetryOptions } from "./retries-CF_HKSlJ.js";
76
77
  import {
77
78
  n as AgentsOAuthProvider,
@@ -148,6 +149,7 @@ export {
148
149
  type WSMessage,
149
150
  __DO_NOT_USE_WILL_BREAK__agentContext,
150
151
  callable,
152
+ camelCaseToKebabCase,
151
153
  createHeaderBasedEmailResolver,
152
154
  getAgentByName,
153
155
  getCurrentAgent,
package/dist/index.js CHANGED
@@ -6374,6 +6374,6 @@ var StreamingResponse = class {
6374
6374
  }
6375
6375
  };
6376
6376
  //#endregion
6377
- export { Agent, DEFAULT_AGENT_STATIC_OPTIONS, DurableObjectOAuthClientProvider, MCP_SERVER_ID_MAX_LENGTH, MessageType, SUB_PREFIX, SqlError, StreamingResponse, __DO_NOT_USE_WILL_BREAK__agentContext, callable, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, getSubAgentByName, normalizeServerId, parseSubAgentPath, routeAgentEmail, routeAgentRequest, routeSubAgentRequest, unstable_callable };
6377
+ export { Agent, DEFAULT_AGENT_STATIC_OPTIONS, DurableObjectOAuthClientProvider, MCP_SERVER_ID_MAX_LENGTH, MessageType, SUB_PREFIX, SqlError, StreamingResponse, __DO_NOT_USE_WILL_BREAK__agentContext, callable, camelCaseToKebabCase, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, getSubAgentByName, normalizeServerId, parseSubAgentPath, routeAgentEmail, routeAgentRequest, routeSubAgentRequest, unstable_callable };
6378
6378
 
6379
6379
  //# sourceMappingURL=index.js.map