agents 0.5.1 → 0.7.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.
package/dist/index.d.ts CHANGED
@@ -5,14 +5,15 @@ import {
5
5
  import { EmailResolver, createHeaderBasedEmailResolver } from "./email.js";
6
6
  import { RetryOptions } from "./retries.js";
7
7
  import {
8
- l as TransportType,
9
- r as MCPConnectionState
10
- } from "./client-storage-D633wI1S.js";
8
+ r as MCPConnectionState,
9
+ w as TransportType
10
+ } from "./client-storage-tusTuoSF.js";
11
11
  import {
12
12
  AgentMcpOAuthProvider,
13
13
  AgentsOAuthProvider,
14
14
  DurableObjectOAuthClientProvider
15
15
  } from "./mcp/do-oauth-client-provider.js";
16
+ import { McpAgent } from "./mcp/index.js";
16
17
  import { MCPClientManager } from "./mcp/client.js";
17
18
  import {
18
19
  RunWorkflowOptions,
@@ -204,6 +205,12 @@ type AddMcpServerOptions = {
204
205
  } /** Retry options for connection and reconnection attempts */;
205
206
  retry?: RetryOptions;
206
207
  };
208
+ /**
209
+ * Options for adding an MCP server via RPC (Durable Object binding)
210
+ */
211
+ type AddRpcMcpServerOptions = {
212
+ /** Props to pass to the McpAgent instance */ props?: Record<string, unknown>;
213
+ };
207
214
  /**
208
215
  * Default options for Agent configuration.
209
216
  * Child classes can override specific options without spreading.
@@ -314,6 +321,11 @@ declare class Agent<
314
321
  * The observability implementation to use for the Agent
315
322
  */
316
323
  observability?: Observability;
324
+ /**
325
+ * Emit an observability event with auto-generated timestamp.
326
+ * @internal
327
+ */
328
+ private _emit;
317
329
  /**
318
330
  * Execute SQL queries against the Agent's database
319
331
  * @template T Type of the returned rows
@@ -625,6 +637,53 @@ declare class Agent<
625
637
  * @returns true if the task was cancelled, false if the task was not found
626
638
  */
627
639
  cancelSchedule(id: string): Promise<boolean>;
640
+ /**
641
+ * Keep the Durable Object alive via alarm heartbeats.
642
+ * Returns a disposer function that stops the heartbeat when called.
643
+ *
644
+ * Use this when you have long-running work and need to prevent the
645
+ * DO from going idle (eviction after ~70-140s of inactivity).
646
+ * The heartbeat fires every 30 seconds via the scheduling system.
647
+ *
648
+ * @experimental This API may change between releases.
649
+ *
650
+ * @example
651
+ * ```ts
652
+ * const dispose = await this.keepAlive();
653
+ * try {
654
+ * // ... long-running work ...
655
+ * } finally {
656
+ * dispose();
657
+ * }
658
+ * ```
659
+ */
660
+ keepAlive(): Promise<() => void>;
661
+ /**
662
+ * Run an async function while keeping the Durable Object alive.
663
+ * The heartbeat is automatically stopped when the function completes
664
+ * (whether it succeeds or throws).
665
+ *
666
+ * This is the recommended way to use keepAlive — it guarantees cleanup
667
+ * so you cannot forget to dispose the heartbeat.
668
+ *
669
+ * @experimental This API may change between releases.
670
+ *
671
+ * @example
672
+ * ```ts
673
+ * const result = await this.keepAliveWhile(async () => {
674
+ * const data = await longRunningComputation();
675
+ * return data;
676
+ * });
677
+ * ```
678
+ */
679
+ keepAliveWhile<T>(fn: () => Promise<T>): Promise<T>;
680
+ /**
681
+ * Internal no-op callback invoked by the keepAlive heartbeat schedule.
682
+ * Its only purpose is to keep the DO alive — the alarm machinery
683
+ * handles the rest.
684
+ * @internal
685
+ */
686
+ _cf_keepAliveHeartbeat(): Promise<void>;
628
687
  private _scheduleNextAlarm;
629
688
  /**
630
689
  * Method called when an alarm fires.
@@ -944,6 +1003,8 @@ declare class Agent<
944
1003
  * Returns undefined if no match found - use options.agentBinding as fallback.
945
1004
  */
946
1005
  private _findAgentBindingName;
1006
+ private _findBindingNameForNamespace;
1007
+ private _restoreRpcMcpServers;
947
1008
  /**
948
1009
  * Handle a callback from a workflow.
949
1010
  * Called when the Agent receives a callback at /_workflow/callback.
@@ -1023,29 +1084,30 @@ declare class Agent<
1023
1084
  state?: unknown
1024
1085
  ): void;
1025
1086
  /**
1026
- * Connect to a new MCP Server
1087
+ * Connect to a new MCP Server via RPC (Durable Object binding)
1027
1088
  *
1028
- * @example
1029
- * // Simple usage
1030
- * await this.addMcpServer("github", "https://mcp.github.com");
1089
+ * The binding name and props are persisted to storage so the connection
1090
+ * is automatically restored after Durable Object hibernation.
1031
1091
  *
1032
1092
  * @example
1033
- * // With options (preferred for custom headers, transport, etc.)
1034
- * await this.addMcpServer("github", "https://mcp.github.com", {
1035
- * transport: { headers: { "Authorization": "Bearer ..." } }
1036
- * });
1093
+ * await this.addMcpServer("counter", env.MY_MCP);
1094
+ * await this.addMcpServer("counter", env.MY_MCP, { props: { userId: "123" } });
1095
+ */
1096
+ addMcpServer<T extends McpAgent>(
1097
+ serverName: string,
1098
+ binding: DurableObjectNamespace<T>,
1099
+ options?: AddRpcMcpServerOptions
1100
+ ): Promise<{
1101
+ id: string;
1102
+ state: typeof MCPConnectionState.READY;
1103
+ }>;
1104
+ /**
1105
+ * Connect to a new MCP Server via HTTP (SSE or Streamable HTTP)
1037
1106
  *
1038
1107
  * @example
1039
- * // Legacy 5-parameter signature (still supported)
1040
- * await this.addMcpServer("github", url, callbackHost, agentsPrefix, options);
1041
- *
1042
- * @param serverName Name of the MCP server
1043
- * @param url MCP Server URL
1044
- * @param callbackHostOrOptions Options object, or callback host string (legacy)
1045
- * @param agentsPrefix agents routing prefix if not using `agents` (legacy)
1046
- * @param options MCP client and transport options (legacy)
1047
- * @returns Server id and state - either "authenticating" with authUrl, or "ready"
1048
- * @throws If connection or discovery fails
1108
+ * await this.addMcpServer("github", "https://mcp.github.com");
1109
+ * await this.addMcpServer("github", "https://mcp.github.com", { transport: { type: "sse" } });
1110
+ * await this.addMcpServer("github", url, callbackHost, agentsPrefix, options); // legacy
1049
1111
  */
1050
1112
  addMcpServer(
1051
1113
  serverName: string,
@@ -1068,7 +1130,6 @@ declare class Agent<
1068
1130
  | {
1069
1131
  id: string;
1070
1132
  state: typeof MCPConnectionState.READY;
1071
- authUrl?: undefined;
1072
1133
  }
1073
1134
  >;
1074
1135
  removeMcpServer(id: string): Promise<void>;
@@ -1223,6 +1284,7 @@ declare class StreamingResponse {
1223
1284
  //#endregion
1224
1285
  export {
1225
1286
  AddMcpServerOptions,
1287
+ AddRpcMcpServerOptions,
1226
1288
  Agent,
1227
1289
  AgentContext,
1228
1290
  type AgentMcpOAuthProvider,