agents 0.11.0 → 0.11.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/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as Agent } from "./index-CrOzHA2T.js";
1
+ import { r as Agent } from "./index-C_XD19E3.js";
2
2
  import {
3
3
  i as SerializableValue,
4
4
  n as RPCMethod,
@@ -232,6 +232,14 @@ type AgentObservabilityEvent =
232
232
  subject?: string;
233
233
  }
234
234
  >
235
+ | BaseEvent<
236
+ "email:send",
237
+ {
238
+ from: string;
239
+ to: string | string[];
240
+ subject: string;
241
+ }
242
+ >
235
243
  | BaseEvent<
236
244
  "workflow:start",
237
245
  {
@@ -413,4 +421,4 @@ export {
413
421
  MCPObservabilityEvent as s,
414
422
  ChannelEventMap as t
415
423
  };
416
- //# sourceMappingURL=index-Cubsi2Qv.d.ts.map
424
+ //# sourceMappingURL=index-Biv6K70p.d.ts.map
@@ -4,7 +4,7 @@ import {
4
4
  n as Observability,
5
5
  r as ObservabilityEvent,
6
6
  s as MCPObservabilityEvent
7
- } from "./index-Cubsi2Qv.js";
7
+ } from "./index-Biv6K70p.js";
8
8
  import { t as AgentMcpOAuthProvider } from "./do-oauth-client-provider-C38aWbFV.js";
9
9
  import {
10
10
  _ as WorkflowPage,
@@ -729,7 +729,7 @@ declare class MCPClientConnection {
729
729
  */
730
730
  getTransport(
731
731
  transportType: BaseTransportType
732
- ): StreamableHTTPClientTransport | SSEClientTransport | RPCClientTransport;
732
+ ): RPCClientTransport | SSEClientTransport | StreamableHTTPClientTransport;
733
733
  private tryConnect;
734
734
  private _capabilityErrorHandler;
735
735
  }
@@ -1420,6 +1420,64 @@ declare function getNamespacedData<T extends keyof NamespacedData>(
1420
1420
  ): NamespacedData[T];
1421
1421
  //#endregion
1422
1422
  //#region src/index.d.ts
1423
+ /**
1424
+ * Structural type for Cloudflare's `send_email` binding.
1425
+ * Accepts both raw MIME messages and structured builder objects.
1426
+ */
1427
+ type EmailSendBinding = {
1428
+ send(
1429
+ message:
1430
+ | EmailMessage
1431
+ | {
1432
+ from:
1433
+ | string
1434
+ | {
1435
+ email: string;
1436
+ name?: string;
1437
+ };
1438
+ to: string | string[];
1439
+ subject: string;
1440
+ replyTo?:
1441
+ | string
1442
+ | {
1443
+ email: string;
1444
+ name?: string;
1445
+ };
1446
+ cc?: string | string[];
1447
+ bcc?: string | string[];
1448
+ headers?: Record<string, string>;
1449
+ text?: string;
1450
+ html?: string;
1451
+ }
1452
+ ): Promise<EmailSendResult>;
1453
+ };
1454
+ /**
1455
+ * Options for Agent.sendEmail()
1456
+ */
1457
+ type SendEmailOptions = {
1458
+ binding: EmailSendBinding;
1459
+ to: string | string[];
1460
+ from:
1461
+ | string
1462
+ | {
1463
+ email: string;
1464
+ name?: string;
1465
+ };
1466
+ subject: string;
1467
+ text?: string;
1468
+ html?: string;
1469
+ replyTo?:
1470
+ | string
1471
+ | {
1472
+ email: string;
1473
+ name?: string;
1474
+ };
1475
+ cc?: string | string[];
1476
+ bcc?: string | string[];
1477
+ inReplyTo?: string;
1478
+ headers?: Record<string, string>;
1479
+ secret?: string;
1480
+ };
1423
1481
  /**
1424
1482
  * RPC request message from client
1425
1483
  */
@@ -2015,6 +2073,28 @@ declare class Agent<
2015
2073
  secret?: string | null;
2016
2074
  }
2017
2075
  ): Promise<void>;
2076
+ /**
2077
+ * Send an outbound email via an Email Service binding.
2078
+ *
2079
+ * Automatically injects agent routing headers (X-Agent-Name, X-Agent-ID).
2080
+ * When `secret` is provided, signs headers with HMAC-SHA256 so that replies
2081
+ * can be routed back to this agent instance via createSecureReplyEmailResolver.
2082
+ *
2083
+ * @param options.binding The send_email binding (e.g. this.env.EMAIL)
2084
+ * @param options.to Recipient address(es)
2085
+ * @param options.from Sender address or {email, name} object
2086
+ * @param options.subject Email subject line
2087
+ * @param options.text Plain text body (at least one of text/html required)
2088
+ * @param options.html HTML body (at least one of text/html required)
2089
+ * @param options.replyTo Reply-to address
2090
+ * @param options.cc CC recipient(s)
2091
+ * @param options.bcc BCC recipient(s)
2092
+ * @param options.inReplyTo Message-ID of the email this is replying to (for threading)
2093
+ * @param options.headers Additional custom headers
2094
+ * @param options.secret Secret for signing agent routing headers
2095
+ * @returns The messageId from Email Service
2096
+ */
2097
+ sendEmail(options: SendEmailOptions): Promise<EmailSendResult>;
2018
2098
  private _tryCatch;
2019
2099
  /**
2020
2100
  * Automatically wrap custom methods with agent context
@@ -2932,70 +3012,72 @@ declare class StreamingResponse {
2932
3012
  }
2933
3013
  //#endregion
2934
3014
  export {
2935
- McpAgent as $,
2936
- getCurrentAgent as A,
2937
- MCPOAuthCallbackResult as B,
2938
- StateUpdateMessage as C,
2939
- WSMessage as D,
2940
- SubAgentStub as E,
2941
- MCPClientManagerOptions as F,
2942
- RPCClientTransport as G,
2943
- MCPServerOptions as H,
2944
- MCPClientOAuthCallbackConfig as I,
2945
- RPCServerTransportOptions as J,
2946
- RPCClientTransportOptions as K,
2947
- MCPClientOAuthResult as L,
2948
- routeAgentRequest as M,
2949
- unstable_callable as N,
2950
- callable as O,
2951
- MCPClientManager as P,
2952
- ElicitResult$1 as Q,
2953
- MCPConnectionResult as R,
2954
- SqlError as S,
2955
- SubAgentClass as T,
2956
- RegisterServerOptions as U,
2957
- MCPServerFilter as V,
2958
- getNamespacedData as W,
2959
- ElicitRequest$1 as X,
2960
- RPC_DO_PREFIX as Y,
2961
- ElicitRequestSchema$1 as Z,
2962
- MCPServersState as _,
3015
+ ElicitRequestSchema$1 as $,
3016
+ callable as A,
3017
+ MCPConnectionResult as B,
3018
+ SendEmailOptions as C,
3019
+ SubAgentClass as D,
3020
+ StreamingResponse as E,
3021
+ unstable_callable as F,
3022
+ RegisterServerOptions as G,
3023
+ MCPOAuthCallbackResult as H,
3024
+ MCPClientManager as I,
3025
+ RPCClientTransportOptions as J,
3026
+ getNamespacedData as K,
3027
+ MCPClientManagerOptions as L,
3028
+ getCurrentAgent as M,
3029
+ routeAgentEmail as N,
3030
+ SubAgentStub as O,
3031
+ routeAgentRequest as P,
3032
+ ElicitRequest$1 as Q,
3033
+ MCPClientOAuthCallbackConfig as R,
3034
+ Schedule as S,
3035
+ StateUpdateMessage as T,
3036
+ MCPServerFilter as U,
3037
+ MCPDiscoverResult as V,
3038
+ MCPServerOptions as W,
3039
+ RPCServerTransportOptions as X,
3040
+ RPCServerTransport as Y,
3041
+ RPC_DO_PREFIX as Z,
3042
+ MCPServerMessage as _,
2963
3043
  AgentNamespace as a,
2964
- TransportState as at,
2965
- RPCResponse as b,
3044
+ McpAuthContext as at,
3045
+ RPCRequest as b,
2966
3046
  CallableMetadata as c,
2967
- SSEEdgeClientTransport as ct,
3047
+ WorkerTransport as ct,
2968
3048
  DEFAULT_AGENT_STATIC_OPTIONS as d,
2969
- TransportType as dt,
2970
- CreateMcpHandlerOptions as et,
3049
+ StreamableHTTPEdgeClientTransport as dt,
3050
+ ElicitResult$1 as et,
2971
3051
  EmailRoutingOptions as f,
2972
- MCPServerMessage as g,
2973
- MCPServer as h,
3052
+ McpClientOptions as ft,
3053
+ MCPServer as g,
3054
+ FiberRecoveryContext as h,
2974
3055
  AgentContext as i,
2975
- getMcpAuthContext as it,
2976
- routeAgentEmail as j,
2977
- getAgentByName as k,
3056
+ experimental_createMcpHandler as it,
3057
+ getAgentByName as j,
3058
+ WSMessage as k,
2978
3059
  Connection$1 as l,
2979
- StreamableHTTPEdgeClientTransport as lt,
2980
- FiberRecoveryContext as m,
3060
+ WorkerTransportOptions as lt,
3061
+ FiberContext as m,
2981
3062
  AddRpcMcpServerOptions as n,
2982
- experimental_createMcpHandler as nt,
3063
+ CreateMcpHandlerOptions as nt,
2983
3064
  AgentOptions as o,
2984
- WorkerTransport as ot,
2985
- FiberContext as p,
2986
- RPCServerTransport as q,
3065
+ getMcpAuthContext as ot,
3066
+ EmailSendBinding as p,
3067
+ TransportType as pt,
3068
+ RPCClientTransport as q,
2987
3069
  Agent as r,
2988
- McpAuthContext as rt,
3070
+ createMcpHandler as rt,
2989
3071
  AgentStaticOptions as s,
2990
- WorkerTransportOptions as st,
3072
+ TransportState as st,
2991
3073
  AddMcpServerOptions as t,
2992
- createMcpHandler as tt,
3074
+ McpAgent as tt,
2993
3075
  ConnectionContext$1 as u,
2994
- McpClientOptions as ut,
2995
- QueueItem as v,
2996
- StreamingResponse as w,
2997
- Schedule as x,
2998
- RPCRequest as y,
2999
- MCPDiscoverResult as z
3076
+ SSEEdgeClientTransport as ut,
3077
+ MCPServersState as v,
3078
+ SqlError as w,
3079
+ RPCResponse as x,
3080
+ QueueItem as y,
3081
+ MCPClientOAuthResult as z
3000
3082
  };
3001
- //# sourceMappingURL=index-CrOzHA2T.d.ts.map
3083
+ //# sourceMappingURL=index-C_XD19E3.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,41 +1,43 @@
1
1
  import { r as __DO_NOT_USE_WILL_BREAK__agentContext } from "./internal_context-BvuGZieY.js";
2
2
  import { t as RetryOptions } from "./retries-JlwH9mnV.js";
3
3
  import {
4
- A as getCurrentAgent,
5
- C as StateUpdateMessage,
6
- D as WSMessage,
7
- E as SubAgentStub,
8
- M as routeAgentRequest,
9
- N as unstable_callable,
10
- O as callable,
11
- S as SqlError,
12
- T as SubAgentClass,
13
- _ as MCPServersState,
4
+ A as callable,
5
+ C as SendEmailOptions,
6
+ D as SubAgentClass,
7
+ E as StreamingResponse,
8
+ F as unstable_callable,
9
+ M as getCurrentAgent,
10
+ N as routeAgentEmail,
11
+ O as SubAgentStub,
12
+ P as routeAgentRequest,
13
+ S as Schedule,
14
+ T as StateUpdateMessage,
15
+ _ as MCPServerMessage,
14
16
  a as AgentNamespace,
15
- b as RPCResponse,
17
+ b as RPCRequest,
16
18
  c as CallableMetadata,
17
19
  d as DEFAULT_AGENT_STATIC_OPTIONS,
18
- dt as TransportType,
19
20
  f as EmailRoutingOptions,
20
- g as MCPServerMessage,
21
- h as MCPServer,
21
+ g as MCPServer,
22
+ h as FiberRecoveryContext,
22
23
  i as AgentContext,
23
- j as routeAgentEmail,
24
- k as getAgentByName,
24
+ j as getAgentByName,
25
+ k as WSMessage,
25
26
  l as Connection,
26
- m as FiberRecoveryContext,
27
+ m as FiberContext,
27
28
  n as AddRpcMcpServerOptions,
28
29
  o as AgentOptions,
29
- p as FiberContext,
30
+ p as EmailSendBinding,
31
+ pt as TransportType,
30
32
  r as Agent,
31
33
  s as AgentStaticOptions,
32
34
  t as AddMcpServerOptions,
33
35
  u as ConnectionContext,
34
- v as QueueItem,
35
- w as StreamingResponse,
36
- x as Schedule,
37
- y as RPCRequest
38
- } from "./index-CrOzHA2T.js";
36
+ v as MCPServersState,
37
+ w as SqlError,
38
+ x as RPCResponse,
39
+ y as QueueItem
40
+ } from "./index-C_XD19E3.js";
39
41
  import {
40
42
  n as AgentsOAuthProvider,
41
43
  r as DurableObjectOAuthClientProvider,
@@ -59,6 +61,7 @@ export {
59
61
  DEFAULT_AGENT_STATIC_OPTIONS,
60
62
  DurableObjectOAuthClientProvider,
61
63
  EmailRoutingOptions,
64
+ EmailSendBinding,
62
65
  FiberContext,
63
66
  FiberRecoveryContext,
64
67
  MCPServer,
@@ -70,6 +73,7 @@ export {
70
73
  RPCResponse,
71
74
  RetryOptions,
72
75
  Schedule,
76
+ SendEmailOptions,
73
77
  SqlError,
74
78
  StateUpdateMessage,
75
79
  StreamingResponse,
package/dist/index.js CHANGED
@@ -1075,6 +1075,63 @@ var Agent = class Agent extends Server {
1075
1075
  });
1076
1076
  });
1077
1077
  }
1078
+ /**
1079
+ * Send an outbound email via an Email Service binding.
1080
+ *
1081
+ * Automatically injects agent routing headers (X-Agent-Name, X-Agent-ID).
1082
+ * When `secret` is provided, signs headers with HMAC-SHA256 so that replies
1083
+ * can be routed back to this agent instance via createSecureReplyEmailResolver.
1084
+ *
1085
+ * @param options.binding The send_email binding (e.g. this.env.EMAIL)
1086
+ * @param options.to Recipient address(es)
1087
+ * @param options.from Sender address or {email, name} object
1088
+ * @param options.subject Email subject line
1089
+ * @param options.text Plain text body (at least one of text/html required)
1090
+ * @param options.html HTML body (at least one of text/html required)
1091
+ * @param options.replyTo Reply-to address
1092
+ * @param options.cc CC recipient(s)
1093
+ * @param options.bcc BCC recipient(s)
1094
+ * @param options.inReplyTo Message-ID of the email this is replying to (for threading)
1095
+ * @param options.headers Additional custom headers
1096
+ * @param options.secret Secret for signing agent routing headers
1097
+ * @returns The messageId from Email Service
1098
+ */
1099
+ async sendEmail(options) {
1100
+ return this._tryCatch(async () => {
1101
+ if (!options.binding) throw new Error("binding is required. Pass your send_email binding, e.g. this.sendEmail({ binding: this.env.EMAIL, ... }).");
1102
+ const agentName = camelCaseToKebabCase(this._ParentClass.name);
1103
+ const agentId = this.name;
1104
+ const headers = {
1105
+ ...options.headers,
1106
+ "X-Agent-Name": agentName,
1107
+ "X-Agent-ID": agentId
1108
+ };
1109
+ if (options.inReplyTo) headers["In-Reply-To"] = options.inReplyTo;
1110
+ if (typeof options.secret === "string") {
1111
+ const signedHeaders = await signAgentHeaders(options.secret, agentName, agentId);
1112
+ headers["X-Agent-Sig"] = signedHeaders["X-Agent-Sig"];
1113
+ headers["X-Agent-Sig-Ts"] = signedHeaders["X-Agent-Sig-Ts"];
1114
+ }
1115
+ const result = await options.binding.send({
1116
+ from: options.from,
1117
+ to: options.to,
1118
+ subject: options.subject,
1119
+ text: options.text,
1120
+ html: options.html,
1121
+ replyTo: options.replyTo,
1122
+ cc: options.cc,
1123
+ bcc: options.bcc,
1124
+ headers
1125
+ });
1126
+ const fromAddr = typeof options.from === "string" ? options.from : options.from.email;
1127
+ this._emit("email:send", {
1128
+ from: fromAddr,
1129
+ to: options.to,
1130
+ subject: options.subject
1131
+ });
1132
+ return result;
1133
+ });
1134
+ }
1078
1135
  async _tryCatch(fn) {
1079
1136
  try {
1080
1137
  return await fn();