agents 0.3.6 → 0.3.7

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.
Files changed (69) hide show
  1. package/README.md +303 -314
  2. package/dist/ai-types.js +1 -1
  3. package/dist/{client-0lfEZpSQ.js → client-6CeOh-EV.js} +7 -3
  4. package/dist/client-6CeOh-EV.js.map +1 -0
  5. package/dist/{client-Cxno-5sH.d.ts → client-DGpERepg.d.ts} +8 -14
  6. package/dist/client.d.ts +80 -24
  7. package/dist/client.js +184 -2
  8. package/dist/client.js.map +1 -0
  9. package/dist/{do-oauth-client-provider-BH9zFtSy.d.ts → do-oauth-client-provider-BqnOQzjy.d.ts} +1 -1
  10. package/dist/{do-oauth-client-provider-BfPFgQU0.js → do-oauth-client-provider-DDg8QrEA.js} +1 -1
  11. package/dist/{do-oauth-client-provider-BfPFgQU0.js.map → do-oauth-client-provider-DDg8QrEA.js.map} +1 -1
  12. package/dist/email-8ljcpvwV.d.ts +157 -0
  13. package/dist/email-XHsSYsTO.js +223 -0
  14. package/dist/email-XHsSYsTO.js.map +1 -0
  15. package/dist/email.d.ts +30 -0
  16. package/dist/email.js +3 -0
  17. package/dist/{index-B7Ny-XfU.d.ts → index-N6791tVt.d.ts} +18 -3
  18. package/dist/index.d.ts +543 -87
  19. package/dist/index.js +6 -6
  20. package/dist/{internal_context-neg89p5n.d.ts → internal_context-CEu5ji80.d.ts} +8 -3
  21. package/dist/{internal_context-oN047Id3.js → internal_context-D9eKFth1.js} +1 -1
  22. package/dist/internal_context-D9eKFth1.js.map +1 -0
  23. package/dist/internal_context.d.ts +1 -1
  24. package/dist/internal_context.js +1 -1
  25. package/dist/mcp/client.d.ts +1 -1
  26. package/dist/mcp/client.js +2 -2
  27. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  28. package/dist/mcp/do-oauth-client-provider.js +1 -1
  29. package/dist/mcp/index.d.ts +4 -2
  30. package/dist/mcp/index.js +35 -35
  31. package/dist/mcp/index.js.map +1 -1
  32. package/dist/mcp/x402.d.ts +0 -1
  33. package/dist/mcp/x402.js.map +1 -1
  34. package/dist/{mcp-AK39tq6H.d.ts → mcp-BwPscEiF.d.ts} +1 -1
  35. package/dist/observability/index.d.ts +1 -1
  36. package/dist/observability/index.js +5 -5
  37. package/dist/react.d.ts +70 -26
  38. package/dist/react.js +83 -21
  39. package/dist/react.js.map +1 -1
  40. package/dist/schedule.d.ts +23 -2
  41. package/dist/schedule.js +23 -1
  42. package/dist/schedule.js.map +1 -1
  43. package/dist/serializable.d.ts +68 -3
  44. package/dist/src-BFP4sOQ4.js +2146 -0
  45. package/dist/src-BFP4sOQ4.js.map +1 -0
  46. package/dist/types-BITaDFf-.js +16 -0
  47. package/dist/{types-4b5tlB0u.js.map → types-BITaDFf-.js.map} +1 -1
  48. package/dist/{types-C5vR2Gzv.d.ts → types-DSSHBW6w.d.ts} +2 -1
  49. package/dist/types.d.ts +1 -1
  50. package/dist/types.js +1 -1
  51. package/dist/utils-B49TmLCI.js +16 -0
  52. package/dist/utils-B49TmLCI.js.map +1 -0
  53. package/dist/utils.d.ts +10 -0
  54. package/dist/utils.js +3 -0
  55. package/dist/workflow-types-Z_Oem1FJ.d.ts +260 -0
  56. package/dist/workflow-types.d.ts +48 -0
  57. package/dist/workflow-types.js +16 -0
  58. package/dist/workflow-types.js.map +1 -0
  59. package/dist/workflows.d.ts +163 -0
  60. package/dist/workflows.js +240 -0
  61. package/dist/workflows.js.map +1 -0
  62. package/package.json +22 -12
  63. package/dist/client-0lfEZpSQ.js.map +0 -1
  64. package/dist/client-CEO0P7vN.js +0 -117
  65. package/dist/client-CEO0P7vN.js.map +0 -1
  66. package/dist/internal_context-oN047Id3.js.map +0 -1
  67. package/dist/src-C_iKczoR.js +0 -1191
  68. package/dist/src-C_iKczoR.js.map +0 -1
  69. package/dist/types-4b5tlB0u.js +0 -15
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import "./client-CEO0P7vN.js";
2
- import "./internal_context-oN047Id3.js";
3
- import "./client-0lfEZpSQ.js";
4
- import "./do-oauth-client-provider-BfPFgQU0.js";
5
- import { a as createAddressBasedEmailResolver, c as getAgentByName, d as routeAgentRequest, f as unstable_callable, i as callable, l as getCurrentAgent, n as SqlError, o as createCatchAllEmailResolver, r as StreamingResponse, s as createHeaderBasedEmailResolver, t as Agent, u as routeAgentEmail } from "./src-C_iKczoR.js";
1
+ import { i as createHeaderBasedEmailResolver } from "./email-XHsSYsTO.js";
2
+ import "./internal_context-D9eKFth1.js";
3
+ import "./client-6CeOh-EV.js";
4
+ import "./do-oauth-client-provider-DDg8QrEA.js";
5
+ import { a as callable, c as routeAgentEmail, i as StreamingResponse, l as routeAgentRequest, n as DEFAULT_AGENT_STATIC_OPTIONS, o as getAgentByName, r as SqlError, s as getCurrentAgent, t as Agent, u as unstable_callable } from "./src-BFP4sOQ4.js";
6
6
 
7
- export { Agent, SqlError, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };
7
+ export { Agent, DEFAULT_AGENT_STATIC_OPTIONS, SqlError, StreamingResponse, callable, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };
@@ -9,8 +9,13 @@ type AgentEmail = {
9
9
  headers: Headers;
10
10
  rawSize: number;
11
11
  setReject: (reason: string) => void;
12
- forward: (rcptTo: string, headers?: Headers) => Promise<void>;
13
- reply: (options: { from: string; to: string; raw: string }) => Promise<void>;
12
+ forward: (rcptTo: string, headers?: Headers) => Promise<EmailSendResult>;
13
+ reply: (options: {
14
+ from: string;
15
+ to: string;
16
+ raw: string;
17
+ }) => Promise<EmailSendResult>; /** @internal Indicates email was routed via createSecureReplyEmailResolver */
18
+ _secureRouted?: boolean;
14
19
  };
15
20
  type AgentContextStore = {
16
21
  agent: unknown;
@@ -21,4 +26,4 @@ type AgentContextStore = {
21
26
  declare const agentContext: AsyncLocalStorage<AgentContextStore>;
22
27
  //#endregion
23
28
  export { AgentEmail as n, agentContext as r, AgentContextStore as t };
24
- //# sourceMappingURL=internal_context-neg89p5n.d.ts.map
29
+ //# sourceMappingURL=internal_context-CEu5ji80.d.ts.map
@@ -5,4 +5,4 @@ const agentContext = new AsyncLocalStorage();
5
5
 
6
6
  //#endregion
7
7
  export { agentContext as t };
8
- //# sourceMappingURL=internal_context-oN047Id3.js.map
8
+ //# sourceMappingURL=internal_context-D9eKFth1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal_context-D9eKFth1.js","names":[],"sources":["../src/internal_context.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { Connection } from \"partyserver\";\n\nexport type AgentEmail = {\n from: string;\n to: string;\n getRaw: () => Promise<Uint8Array>;\n headers: Headers;\n rawSize: number;\n setReject: (reason: string) => void;\n forward: (rcptTo: string, headers?: Headers) => Promise<EmailSendResult>;\n reply: (options: {\n from: string;\n to: string;\n raw: string;\n }) => Promise<EmailSendResult>;\n /** @internal Indicates email was routed via createSecureReplyEmailResolver */\n _secureRouted?: boolean;\n};\n\nexport type AgentContextStore = {\n // Using unknown to avoid circular dependency with Agent\n agent: unknown;\n connection: Connection | undefined;\n request: Request | undefined;\n email: AgentEmail | undefined;\n};\n\nexport const agentContext = new AsyncLocalStorage<AgentContextStore>();\n"],"mappings":";;;AA4BA,MAAa,eAAe,IAAI,mBAAsC"}
@@ -2,5 +2,5 @@ import {
2
2
  n as AgentEmail,
3
3
  r as agentContext,
4
4
  t as AgentContextStore
5
- } from "./internal_context-neg89p5n.js";
5
+ } from "./internal_context-CEu5ji80.js";
6
6
  export { AgentContextStore, AgentEmail, agentContext };
@@ -1,3 +1,3 @@
1
- import { t as agentContext } from "./internal_context-oN047Id3.js";
1
+ import { t as agentContext } from "./internal_context-D9eKFth1.js";
2
2
 
3
3
  export { agentContext };
@@ -1,2 +1,2 @@
1
- import { a as MCPConnectionResult, c as RegisterServerOptions, i as MCPClientOAuthResult, l as getNamespacedData, n as MCPClientManagerOptions, o as MCPDiscoverResult, r as MCPClientOAuthCallbackConfig, s as MCPServerOptions, t as MCPClientManager } from "../client-Cxno-5sH.js";
1
+ import { a as MCPConnectionResult, c as RegisterServerOptions, i as MCPClientOAuthResult, l as getNamespacedData, n as MCPClientManagerOptions, o as MCPDiscoverResult, r as MCPClientOAuthCallbackConfig, s as MCPServerOptions, t as MCPClientManager } from "../client-DGpERepg.js";
2
2
  export { MCPClientManager, MCPClientManagerOptions, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, MCPConnectionResult, MCPDiscoverResult, MCPServerOptions, RegisterServerOptions, getNamespacedData };
@@ -1,4 +1,4 @@
1
- import { n as getNamespacedData, t as MCPClientManager } from "../client-0lfEZpSQ.js";
2
- import "../do-oauth-client-provider-BfPFgQU0.js";
1
+ import { n as getNamespacedData, t as MCPClientManager } from "../client-6CeOh-EV.js";
2
+ import "../do-oauth-client-provider-DDg8QrEA.js";
3
3
 
4
4
  export { MCPClientManager, getNamespacedData };
@@ -1,2 +1,2 @@
1
- import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider-BH9zFtSy.js";
1
+ import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider-BqnOQzjy.js";
2
2
  export { AgentsOAuthProvider, DurableObjectOAuthClientProvider };
@@ -1,3 +1,3 @@
1
- import { t as DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-BfPFgQU0.js";
1
+ import { t as DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-DDg8QrEA.js";
2
2
 
3
3
  export { DurableObjectOAuthClientProvider };
@@ -1,5 +1,7 @@
1
- import "../internal_context-neg89p5n.js";
2
- import { a as MCPConnectionResult, d as BaseTransportType, f as CORSOptions, i as MCPClientOAuthResult, m as ServeOptions, o as MCPDiscoverResult, p as MaybePromise, r as MCPClientOAuthCallbackConfig, s as MCPServerOptions } from "../client-Cxno-5sH.js";
1
+ import "../internal_context-CEu5ji80.js";
2
+ import "../email-8ljcpvwV.js";
3
+ import { a as MCPConnectionResult, d as BaseTransportType, f as CORSOptions, i as MCPClientOAuthResult, m as ServeOptions, o as MCPDiscoverResult, p as MaybePromise, r as MCPClientOAuthCallbackConfig, s as MCPServerOptions } from "../client-DGpERepg.js";
4
+ import "../workflow-types-Z_Oem1FJ.js";
3
5
  import { Agent, Connection, ConnectionContext } from "../index.js";
4
6
  import { SSEClientTransport, SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
5
7
  import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
package/dist/mcp/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { t as MessageType } from "../types-4b5tlB0u.js";
2
- import "../client-CEO0P7vN.js";
3
- import "../internal_context-oN047Id3.js";
4
- import "../client-0lfEZpSQ.js";
5
- import "../do-oauth-client-provider-BfPFgQU0.js";
6
- import { c as getAgentByName, l as getCurrentAgent, t as Agent } from "../src-C_iKczoR.js";
1
+ import { t as MessageType } from "../types-BITaDFf-.js";
2
+ import "../email-XHsSYsTO.js";
3
+ import "../internal_context-D9eKFth1.js";
4
+ import "../client-6CeOh-EV.js";
5
+ import "../do-oauth-client-provider-DDg8QrEA.js";
6
+ import { o as getAgentByName, s as getCurrentAgent, t as Agent } from "../src-BFP4sOQ4.js";
7
7
  import { AsyncLocalStorage } from "node:async_hooks";
8
8
  import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
9
9
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
@@ -34,7 +34,7 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
34
34
  if (request.method === "POST") {
35
35
  const acceptHeader = request.headers.get("accept");
36
36
  if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
37
- const body$1 = JSON.stringify({
37
+ const body = JSON.stringify({
38
38
  error: {
39
39
  code: -32e3,
40
40
  message: "Not Acceptable: Client must accept both application/json and text/event-stream"
@@ -42,11 +42,11 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
42
42
  id: null,
43
43
  jsonrpc: "2.0"
44
44
  });
45
- return new Response(body$1, { status: 406 });
45
+ return new Response(body, { status: 406 });
46
46
  }
47
47
  const ct = request.headers.get("content-type");
48
48
  if (!ct || !ct.includes("application/json")) {
49
- const body$1 = JSON.stringify({
49
+ const body = JSON.stringify({
50
50
  error: {
51
51
  code: -32e3,
52
52
  message: "Unsupported Media Type: Content-Type must be application/json"
@@ -54,10 +54,10 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
54
54
  id: null,
55
55
  jsonrpc: "2.0"
56
56
  });
57
- return new Response(body$1, { status: 415 });
57
+ return new Response(body, { status: 415 });
58
58
  }
59
59
  if (Number.parseInt(request.headers.get("content-length") ?? "0", 10) > MAXIMUM_MESSAGE_SIZE_BYTES) {
60
- const body$1 = JSON.stringify({
60
+ const body = JSON.stringify({
61
61
  error: {
62
62
  code: -32e3,
63
63
  message: `Request body too large. Maximum size is ${MAXIMUM_MESSAGE_SIZE_BYTES} bytes`
@@ -65,14 +65,14 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
65
65
  id: null,
66
66
  jsonrpc: "2.0"
67
67
  });
68
- return new Response(body$1, { status: 413 });
68
+ return new Response(body, { status: 413 });
69
69
  }
70
70
  let sessionId = request.headers.get("mcp-session-id");
71
71
  let rawMessage;
72
72
  try {
73
73
  rawMessage = await request.json();
74
74
  } catch (_error) {
75
- const body$1 = JSON.stringify({
75
+ const body = JSON.stringify({
76
76
  error: {
77
77
  code: -32700,
78
78
  message: "Parse error: Invalid JSON"
@@ -80,14 +80,14 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
80
80
  id: null,
81
81
  jsonrpc: "2.0"
82
82
  });
83
- return new Response(body$1, { status: 400 });
83
+ return new Response(body, { status: 400 });
84
84
  }
85
85
  let arrayMessage;
86
86
  if (Array.isArray(rawMessage)) arrayMessage = rawMessage;
87
87
  else arrayMessage = [rawMessage];
88
88
  let messages = [];
89
89
  for (const msg of arrayMessage) if (!JSONRPCMessageSchema.safeParse(msg).success) {
90
- const body$1 = JSON.stringify({
90
+ const body = JSON.stringify({
91
91
  error: {
92
92
  code: -32700,
93
93
  message: "Parse error: Invalid JSON-RPC message"
@@ -95,12 +95,12 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
95
95
  id: null,
96
96
  jsonrpc: "2.0"
97
97
  });
98
- return new Response(body$1, { status: 400 });
98
+ return new Response(body, { status: 400 });
99
99
  }
100
100
  messages = arrayMessage.map((msg) => JSONRPCMessageSchema.parse(msg));
101
101
  const maybeInitializeRequest = messages.find((msg) => InitializeRequestSchema.safeParse(msg).success);
102
102
  if (!!maybeInitializeRequest && sessionId) {
103
- const body$1 = JSON.stringify({
103
+ const body = JSON.stringify({
104
104
  error: {
105
105
  code: -32600,
106
106
  message: "Invalid Request: Initialization requests must not include a sessionId"
@@ -108,10 +108,10 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
108
108
  id: null,
109
109
  jsonrpc: "2.0"
110
110
  });
111
- return new Response(body$1, { status: 400 });
111
+ return new Response(body, { status: 400 });
112
112
  }
113
113
  if (!!maybeInitializeRequest && messages.length > 1) {
114
- const body$1 = JSON.stringify({
114
+ const body = JSON.stringify({
115
115
  error: {
116
116
  code: -32600,
117
117
  message: "Invalid Request: Only one initialization request is allowed"
@@ -119,10 +119,10 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
119
119
  id: null,
120
120
  jsonrpc: "2.0"
121
121
  });
122
- return new Response(body$1, { status: 400 });
122
+ return new Response(body, { status: 400 });
123
123
  }
124
124
  if (!maybeInitializeRequest && !sessionId) {
125
- const body$1 = JSON.stringify({
125
+ const body = JSON.stringify({
126
126
  error: {
127
127
  code: -32e3,
128
128
  message: "Bad Request: Mcp-Session-Id header is required"
@@ -130,7 +130,7 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
130
130
  id: null,
131
131
  jsonrpc: "2.0"
132
132
  });
133
- return new Response(body$1, { status: 400 });
133
+ return new Response(body, { status: 400 });
134
134
  }
135
135
  sessionId = sessionId ?? namespace.newUniqueId().toString();
136
136
  const agent = await getAgentByName(namespace, `streamable-http:${sessionId}`, {
@@ -140,7 +140,7 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
140
140
  const isInitialized = await agent.getInitializeRequest();
141
141
  if (maybeInitializeRequest) await agent.setInitializeRequest(maybeInitializeRequest);
142
142
  else if (!isInitialized) {
143
- const body$1 = JSON.stringify({
143
+ const body = JSON.stringify({
144
144
  error: {
145
145
  code: -32001,
146
146
  message: "Session not found"
@@ -148,7 +148,7 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
148
148
  id: null,
149
149
  jsonrpc: "2.0"
150
150
  });
151
- return new Response(body$1, { status: 404 });
151
+ return new Response(body, { status: 404 });
152
152
  }
153
153
  const { readable, writable } = new TransformStream();
154
154
  const writer = writable.getWriter();
@@ -168,7 +168,7 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
168
168
  if (!ws) {
169
169
  console.error("Failed to establish WebSocket connection");
170
170
  await writer.close();
171
- const body$1 = JSON.stringify({
171
+ const body = JSON.stringify({
172
172
  error: {
173
173
  code: -32001,
174
174
  message: "Failed to establish WebSocket connection"
@@ -176,13 +176,13 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
176
176
  id: null,
177
177
  jsonrpc: "2.0"
178
178
  });
179
- return new Response(body$1, { status: 500 });
179
+ return new Response(body, { status: 500 });
180
180
  }
181
181
  ws.accept();
182
182
  ws.addEventListener("message", (event) => {
183
- async function onMessage(event$1) {
183
+ async function onMessage(event) {
184
184
  try {
185
- const data = typeof event$1.data === "string" ? event$1.data : new TextDecoder().decode(event$1.data);
185
+ const data = typeof event.data === "string" ? event.data : new TextDecoder().decode(event.data);
186
186
  const message = JSON.parse(data);
187
187
  if (message.type !== MessageType.CF_MCP_AGENT_EVENT) return;
188
188
  await writer.write(encoder.encode(message.event));
@@ -227,7 +227,7 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
227
227
  });
228
228
  } else if (request.method === "GET") {
229
229
  if (!request.headers.get("accept")?.includes("text/event-stream")) {
230
- const body$1 = JSON.stringify({
230
+ const body = JSON.stringify({
231
231
  jsonrpc: "2.0",
232
232
  error: {
233
233
  code: -32e3,
@@ -235,7 +235,7 @@ const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
235
235
  },
236
236
  id: null
237
237
  });
238
- return new Response(body$1, { status: 406 });
238
+ return new Response(body, { status: 406 });
239
239
  }
240
240
  const sessionId = request.headers.get("mcp-session-id");
241
241
  if (!sessionId) return new Response(JSON.stringify({
@@ -385,9 +385,9 @@ const createLegacySseHandler = (basePath, namespace, options = {}) => {
385
385
  }
386
386
  ws.accept();
387
387
  ws.addEventListener("message", (event) => {
388
- async function onMessage(event$1) {
388
+ async function onMessage(event) {
389
389
  try {
390
- const message = JSON.parse(event$1.data);
390
+ const message = JSON.parse(event.data);
391
391
  const result = JSONRPCMessageSchema.safeParse(message);
392
392
  if (!result.success) return;
393
393
  const messageText = `event: message\ndata: ${JSON.stringify(result.data)}\n\n`;
@@ -640,9 +640,9 @@ var StreamableHTTPServerTransport = class {
640
640
  let standaloneConnection;
641
641
  for (const conn of agent.getConnections()) if (conn.state?._standaloneSse) standaloneConnection = conn;
642
642
  if (standaloneConnection === void 0) return;
643
- let eventId$1;
644
- if (this._eventStore) eventId$1 = await this._eventStore.storeEvent(standaloneConnection.id, message);
645
- this.writeSSEEvent(standaloneConnection, message, eventId$1);
643
+ let eventId;
644
+ if (this._eventStore) eventId = await this._eventStore.storeEvent(standaloneConnection.id, message);
645
+ this.writeSSEEvent(standaloneConnection, message, eventId);
646
646
  return;
647
647
  }
648
648
  const connection = Array.from(agent.getConnections()).find((conn) => conn.state?.requestIds?.includes(requestId));