agents 0.0.0-e48e5f9 → 0.0.0-e777fdd

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 (67) hide show
  1. package/README.md +234 -6
  2. package/dist/_esm-LV5FJ3HK.js +3922 -0
  3. package/dist/_esm-LV5FJ3HK.js.map +1 -0
  4. package/dist/ai-chat-agent.d.ts +12 -9
  5. package/dist/ai-chat-agent.js +151 -59
  6. package/dist/ai-chat-agent.js.map +1 -1
  7. package/dist/ai-chat-v5-migration.d.ts +152 -0
  8. package/dist/ai-chat-v5-migration.js +20 -0
  9. package/dist/ai-chat-v5-migration.js.map +1 -0
  10. package/dist/ai-react.d.ts +68 -71
  11. package/dist/ai-react.js +252 -99
  12. package/dist/ai-react.js.map +1 -1
  13. package/dist/ai-types.d.ts +37 -19
  14. package/dist/ai-types.js +7 -0
  15. package/dist/ccip-CMBYN64O.js +15 -0
  16. package/dist/ccip-CMBYN64O.js.map +1 -0
  17. package/dist/chunk-5Y6BEZDY.js +276 -0
  18. package/dist/chunk-5Y6BEZDY.js.map +1 -0
  19. package/dist/chunk-BER7KXUJ.js +18 -0
  20. package/dist/chunk-BER7KXUJ.js.map +1 -0
  21. package/dist/chunk-JJBFIGUC.js +5202 -0
  22. package/dist/chunk-JJBFIGUC.js.map +1 -0
  23. package/dist/chunk-PR4QN5HX.js +43 -0
  24. package/dist/chunk-PR4QN5HX.js.map +1 -0
  25. package/dist/{chunk-MW5BQ2FW.js → chunk-QEPGNUG6.js} +213 -32
  26. package/dist/chunk-QEPGNUG6.js.map +1 -0
  27. package/dist/{chunk-KUH345EY.js → chunk-QEVM4BVL.js} +5 -5
  28. package/dist/chunk-QEVM4BVL.js.map +1 -0
  29. package/dist/{chunk-5YIRLLUX.js → chunk-RS5OCNEQ.js} +169 -110
  30. package/dist/chunk-RS5OCNEQ.js.map +1 -0
  31. package/dist/chunk-TYAY6AU6.js +159 -0
  32. package/dist/chunk-TYAY6AU6.js.map +1 -0
  33. package/dist/chunk-UJVEAURM.js +150 -0
  34. package/dist/chunk-UJVEAURM.js.map +1 -0
  35. package/dist/{chunk-PVQZBKN7.js → chunk-XFS5ERG3.js} +24 -3
  36. package/dist/chunk-XFS5ERG3.js.map +1 -0
  37. package/dist/client-BohGLma8.d.ts +5041 -0
  38. package/dist/client.js +3 -1
  39. package/dist/index.d.ts +564 -32
  40. package/dist/index.js +8 -4
  41. package/dist/mcp/client.d.ts +9 -1053
  42. package/dist/mcp/client.js +2 -1
  43. package/dist/mcp/do-oauth-client-provider.d.ts +9 -0
  44. package/dist/mcp/do-oauth-client-provider.js +2 -1
  45. package/dist/mcp/index.d.ts +57 -63
  46. package/dist/mcp/index.js +954 -638
  47. package/dist/mcp/index.js.map +1 -1
  48. package/dist/mcp/x402.d.ts +39 -0
  49. package/dist/mcp/x402.js +3195 -0
  50. package/dist/mcp/x402.js.map +1 -0
  51. package/dist/observability/index.d.ts +46 -12
  52. package/dist/observability/index.js +6 -4
  53. package/dist/react.d.ts +7 -3
  54. package/dist/react.js +8 -5
  55. package/dist/react.js.map +1 -1
  56. package/dist/schedule.d.ts +83 -9
  57. package/dist/schedule.js +17 -2
  58. package/dist/schedule.js.map +1 -1
  59. package/dist/secp256k1-M22GZP2U.js +2193 -0
  60. package/dist/secp256k1-M22GZP2U.js.map +1 -0
  61. package/package.json +25 -9
  62. package/src/index.ts +240 -131
  63. package/dist/chunk-5YIRLLUX.js.map +0 -1
  64. package/dist/chunk-KUH345EY.js.map +0 -1
  65. package/dist/chunk-MW5BQ2FW.js.map +0 -1
  66. package/dist/chunk-PVQZBKN7.js.map +0 -1
  67. package/dist/index-BIJvkfYt.d.ts +0 -614
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  MCPClientManager
3
- } from "./chunk-MW5BQ2FW.js";
3
+ } from "./chunk-QEPGNUG6.js";
4
4
  import {
5
5
  DurableObjectOAuthClientProvider
6
- } from "./chunk-PVQZBKN7.js";
6
+ } from "./chunk-XFS5ERG3.js";
7
7
  import {
8
8
  camelCaseToKebabCase
9
- } from "./chunk-KUH345EY.js";
9
+ } from "./chunk-QEVM4BVL.js";
10
10
 
11
11
  // src/index.ts
12
12
  import { AsyncLocalStorage } from "async_hooks";
@@ -19,13 +19,13 @@ import {
19
19
  routePartykitRequest
20
20
  } from "partyserver";
21
21
  function isRPCRequest(msg) {
22
- return typeof msg === "object" && msg !== null && "type" in msg && msg.type === "rpc" && "id" in msg && typeof msg.id === "string" && "method" in msg && typeof msg.method === "string" && "args" in msg && Array.isArray(msg.args);
22
+ return typeof msg === "object" && msg !== null && "type" in msg && msg.type === "rpc" /* RPC */ && "id" in msg && typeof msg.id === "string" && "method" in msg && typeof msg.method === "string" && "args" in msg && Array.isArray(msg.args);
23
23
  }
24
24
  function isStateUpdateMessage(msg) {
25
- return typeof msg === "object" && msg !== null && "type" in msg && msg.type === "cf_agent_state" && "state" in msg;
25
+ return typeof msg === "object" && msg !== null && "type" in msg && msg.type === "cf_agent_state" /* CF_AGENT_STATE */ && "state" in msg;
26
26
  }
27
27
  var callableMetadata = /* @__PURE__ */ new Map();
28
- function unstable_callable(metadata = {}) {
28
+ function callable(metadata = {}) {
29
29
  return function callableDecorator(target, context) {
30
30
  if (!callableMetadata.has(target)) {
31
31
  callableMetadata.set(target, metadata);
@@ -33,6 +33,16 @@ function unstable_callable(metadata = {}) {
33
33
  return target;
34
34
  };
35
35
  }
36
+ var didWarnAboutUnstableCallable = false;
37
+ var unstable_callable = (metadata = {}) => {
38
+ if (!didWarnAboutUnstableCallable) {
39
+ didWarnAboutUnstableCallable = true;
40
+ console.warn(
41
+ "unstable_callable is deprecated, use callable instead. unstable_callable will be removed in the next major version."
42
+ );
43
+ }
44
+ callable(metadata);
45
+ };
36
46
  function getNextCronTime(cron) {
37
47
  const interval = parseCronExpression(cron);
38
48
  return interval.getNextDate();
@@ -55,7 +65,10 @@ function getCurrentAgent() {
55
65
  }
56
66
  function withAgentContext(method) {
57
67
  return function(...args) {
58
- const { connection, request, email } = getCurrentAgent();
68
+ const { connection, request, email, agent } = getCurrentAgent();
69
+ if (agent === this) {
70
+ return method.apply(this, args);
71
+ }
59
72
  return agentContext.run({ agent: this, connection, request, email }, () => {
60
73
  return method.apply(this, args);
61
74
  });
@@ -66,7 +79,10 @@ var _Agent = class _Agent extends Server {
66
79
  super(ctx, env);
67
80
  this._state = DEFAULT_STATE;
68
81
  this._ParentClass = Object.getPrototypeOf(this).constructor;
69
- this.mcp = new MCPClientManager(this._ParentClass.name, "0.0.1");
82
+ this.mcp = new MCPClientManager(
83
+ this._ParentClass.name,
84
+ "0.0.1"
85
+ );
70
86
  /**
71
87
  * Initial state for the Agent
72
88
  * Override to provide default state values
@@ -110,7 +126,10 @@ var _Agent = class _Agent extends Server {
110
126
  {
111
127
  displayMessage: `Schedule ${row.id} executed`,
112
128
  id: nanoid(),
113
- payload: row,
129
+ payload: {
130
+ callback: row.callback,
131
+ id: row.id
132
+ },
114
133
  timestamp: Date.now(),
115
134
  type: "schedule:execute"
116
135
  },
@@ -137,7 +156,10 @@ var _Agent = class _Agent extends Server {
137
156
  }
138
157
  await this._scheduleNextAlarm();
139
158
  };
140
- this._autoWrapCustomMethods();
159
+ if (!wrappedClasses.has(this.constructor)) {
160
+ this._autoWrapCustomMethods();
161
+ wrappedClasses.add(this.constructor);
162
+ }
141
163
  this.sql`
142
164
  CREATE TABLE IF NOT EXISTS cf_agents_state (
143
165
  id TEXT PRIMARY KEY NOT NULL,
@@ -190,7 +212,7 @@ var _Agent = class _Agent extends Server {
190
212
  this.broadcast(
191
213
  JSON.stringify({
192
214
  mcp: this.getMcpServers(),
193
- type: "cf_agent_mcp_servers"
215
+ type: "cf_agent_mcp_servers" /* CF_AGENT_MCP_SERVERS */
194
216
  })
195
217
  );
196
218
  return new Response("<script>window.close();</script>", {
@@ -242,10 +264,8 @@ var _Agent = class _Agent extends Server {
242
264
  displayMessage: `RPC call to ${method}`,
243
265
  id: nanoid(),
244
266
  payload: {
245
- args,
246
267
  method,
247
- streaming: metadata?.streaming,
248
- success: true
268
+ streaming: metadata?.streaming
249
269
  },
250
270
  timestamp: Date.now(),
251
271
  type: "rpc"
@@ -257,7 +277,7 @@ var _Agent = class _Agent extends Server {
257
277
  id,
258
278
  result,
259
279
  success: true,
260
- type: "rpc"
280
+ type: "rpc" /* RPC */
261
281
  };
262
282
  connection.send(JSON.stringify(response));
263
283
  } catch (e) {
@@ -265,7 +285,7 @@ var _Agent = class _Agent extends Server {
265
285
  error: e instanceof Error ? e.message : "Unknown error occurred",
266
286
  id: parsed.id,
267
287
  success: false,
268
- type: "rpc"
288
+ type: "rpc" /* RPC */
269
289
  };
270
290
  connection.send(JSON.stringify(response));
271
291
  console.error("RPC error:", e);
@@ -280,41 +300,39 @@ var _Agent = class _Agent extends Server {
280
300
  this.onConnect = (connection, ctx2) => {
281
301
  return agentContext.run(
282
302
  { agent: this, connection, request: ctx2.request, email: void 0 },
283
- async () => {
284
- setTimeout(() => {
285
- if (this.state) {
286
- connection.send(
287
- JSON.stringify({
288
- state: this.state,
289
- type: "cf_agent_state"
290
- })
291
- );
292
- }
303
+ () => {
304
+ if (this.state) {
293
305
  connection.send(
294
306
  JSON.stringify({
295
- mcp: this.getMcpServers(),
296
- type: "cf_agent_mcp_servers"
307
+ state: this.state,
308
+ type: "cf_agent_state" /* CF_AGENT_STATE */
297
309
  })
298
310
  );
299
- this.observability?.emit(
300
- {
301
- displayMessage: "Connection established",
302
- id: nanoid(),
303
- payload: {
304
- connectionId: connection.id
305
- },
306
- timestamp: Date.now(),
307
- type: "connect"
311
+ }
312
+ connection.send(
313
+ JSON.stringify({
314
+ mcp: this.getMcpServers(),
315
+ type: "cf_agent_mcp_servers" /* CF_AGENT_MCP_SERVERS */
316
+ })
317
+ );
318
+ this.observability?.emit(
319
+ {
320
+ displayMessage: "Connection established",
321
+ id: nanoid(),
322
+ payload: {
323
+ connectionId: connection.id
308
324
  },
309
- this.ctx
310
- );
311
- return this._tryCatch(() => _onConnect(connection, ctx2));
312
- }, 20);
325
+ timestamp: Date.now(),
326
+ type: "connect"
327
+ },
328
+ this.ctx
329
+ );
330
+ return this._tryCatch(() => _onConnect(connection, ctx2));
313
331
  }
314
332
  );
315
333
  };
316
334
  const _onStart = this.onStart.bind(this);
317
- this.onStart = async () => {
335
+ this.onStart = async (props) => {
318
336
  return agentContext.run(
319
337
  {
320
338
  agent: this,
@@ -323,13 +341,24 @@ var _Agent = class _Agent extends Server {
323
341
  email: void 0
324
342
  },
325
343
  async () => {
326
- const servers = this.sql`
344
+ await this._tryCatch(() => {
345
+ const servers = this.sql`
327
346
  SELECT id, name, server_url, client_id, auth_url, callback_url, server_options FROM cf_agents_mcp_servers;
328
347
  `;
329
- if (servers && Array.isArray(servers) && servers.length > 0) {
330
- Promise.allSettled(
331
- servers.map((server) => {
332
- return this._connectToMcpServerInternal(
348
+ this.broadcast(
349
+ JSON.stringify({
350
+ mcp: this.getMcpServers(),
351
+ type: "cf_agent_mcp_servers" /* CF_AGENT_MCP_SERVERS */
352
+ })
353
+ );
354
+ if (servers && Array.isArray(servers) && servers.length > 0) {
355
+ servers.forEach((server) => {
356
+ if (server.callback_url) {
357
+ this.mcp.registerCallbackUrl(server.callback_url);
358
+ }
359
+ });
360
+ servers.forEach((server) => {
361
+ this._connectToMcpServerInternal(
333
362
  server.name,
334
363
  server.server_url,
335
364
  server.callback_url,
@@ -338,18 +367,29 @@ var _Agent = class _Agent extends Server {
338
367
  id: server.id,
339
368
  oauthClientId: server.client_id ?? void 0
340
369
  }
341
- );
342
- })
343
- ).then((_results) => {
344
- this.broadcast(
345
- JSON.stringify({
346
- mcp: this.getMcpServers(),
347
- type: "cf_agent_mcp_servers"
348
- })
349
- );
350
- });
351
- }
352
- await this._tryCatch(() => _onStart());
370
+ ).then(() => {
371
+ this.broadcast(
372
+ JSON.stringify({
373
+ mcp: this.getMcpServers(),
374
+ type: "cf_agent_mcp_servers" /* CF_AGENT_MCP_SERVERS */
375
+ })
376
+ );
377
+ }).catch((error) => {
378
+ console.error(
379
+ `Error connecting to MCP server: ${server.name} (${server.server_url})`,
380
+ error
381
+ );
382
+ this.broadcast(
383
+ JSON.stringify({
384
+ mcp: this.getMcpServers(),
385
+ type: "cf_agent_mcp_servers" /* CF_AGENT_MCP_SERVERS */
386
+ })
387
+ );
388
+ });
389
+ });
390
+ }
391
+ return _onStart(props);
392
+ });
353
393
  }
354
394
  );
355
395
  };
@@ -400,7 +440,6 @@ var _Agent = class _Agent extends Server {
400
440
  }
401
441
  }
402
442
  _setStateInternal(state, source = "server") {
403
- const previousState = this._state;
404
443
  this._state = state;
405
444
  this.sql`
406
445
  INSERT OR REPLACE INTO cf_agents_state (id, state)
@@ -413,7 +452,7 @@ var _Agent = class _Agent extends Server {
413
452
  this.broadcast(
414
453
  JSON.stringify({
415
454
  state,
416
- type: "cf_agent_state"
455
+ type: "cf_agent_state" /* CF_AGENT_STATE */
417
456
  }),
418
457
  source !== "server" ? [source.id] : []
419
458
  );
@@ -426,10 +465,7 @@ var _Agent = class _Agent extends Server {
426
465
  {
427
466
  displayMessage: "State updated",
428
467
  id: nanoid(),
429
- payload: {
430
- previousState,
431
- state
432
- },
468
+ payload: {},
433
469
  timestamp: Date.now(),
434
470
  type: "state:update"
435
471
  },
@@ -546,28 +582,22 @@ var _Agent = class _Agent extends Server {
546
582
  while (proto && proto !== Object.prototype && depth < 10) {
547
583
  const methodNames = Object.getOwnPropertyNames(proto);
548
584
  for (const methodName of methodNames) {
549
- if (baseMethods.has(methodName) || methodName.startsWith("_") || typeof this[methodName] !== "function") {
585
+ const descriptor = Object.getOwnPropertyDescriptor(proto, methodName);
586
+ if (baseMethods.has(methodName) || methodName.startsWith("_") || !descriptor || !!descriptor.get || typeof descriptor.value !== "function") {
550
587
  continue;
551
588
  }
552
- if (!baseMethods.has(methodName)) {
553
- const descriptor = Object.getOwnPropertyDescriptor(proto, methodName);
554
- if (descriptor && typeof descriptor.value === "function") {
555
- const wrappedFunction = withAgentContext(
556
- // biome-ignore lint/suspicious/noExplicitAny: I can't typescript
557
- this[methodName]
558
- // biome-ignore lint/suspicious/noExplicitAny: I can't typescript
559
- );
560
- if (this._isCallable(methodName)) {
561
- callableMetadata.set(
562
- wrappedFunction,
563
- callableMetadata.get(
564
- this[methodName]
565
- )
566
- );
567
- }
568
- this.constructor.prototype[methodName] = wrappedFunction;
569
- }
589
+ const wrappedFunction = withAgentContext(
590
+ // biome-ignore lint/suspicious/noExplicitAny: I can't typescript
591
+ this[methodName]
592
+ // biome-ignore lint/suspicious/noExplicitAny: I can't typescript
593
+ );
594
+ if (this._isCallable(methodName)) {
595
+ callableMetadata.set(
596
+ wrappedFunction,
597
+ callableMetadata.get(this[methodName])
598
+ );
570
599
  }
600
+ this.constructor.prototype[methodName] = wrappedFunction;
571
601
  }
572
602
  proto = Object.getPrototypeOf(proto);
573
603
  depth++;
@@ -627,7 +657,6 @@ var _Agent = class _Agent extends Server {
627
657
  }
628
658
  this._flushingQueue = true;
629
659
  while (true) {
630
- const executed = [];
631
660
  const result = this.sql`
632
661
  SELECT * FROM cf_agents_queues
633
662
  ORDER BY created_at ASC
@@ -651,13 +680,10 @@ var _Agent = class _Agent extends Server {
651
680
  },
652
681
  async () => {
653
682
  await callback.bind(this)(JSON.parse(row.payload), row);
654
- executed.push(row.id);
683
+ await this.dequeue(row.id);
655
684
  }
656
685
  );
657
686
  }
658
- for (const id of executed) {
659
- await this.dequeue(id);
660
- }
661
687
  }
662
688
  this._flushingQueue = false;
663
689
  }
@@ -718,7 +744,10 @@ var _Agent = class _Agent extends Server {
718
744
  {
719
745
  displayMessage: `Schedule ${schedule.id} created`,
720
746
  id: nanoid(),
721
- payload: schedule,
747
+ payload: {
748
+ callback,
749
+ id
750
+ },
722
751
  timestamp: Date.now(),
723
752
  type: "schedule:create"
724
753
  },
@@ -853,7 +882,10 @@ var _Agent = class _Agent extends Server {
853
882
  {
854
883
  displayMessage: `Schedule ${id} cancelled`,
855
884
  id: nanoid(),
856
- payload: schedule,
885
+ payload: {
886
+ callback: schedule.callback,
887
+ id: schedule.id
888
+ },
857
889
  timestamp: Date.now(),
858
890
  type: "schedule:cancel"
859
891
  },
@@ -866,9 +898,9 @@ var _Agent = class _Agent extends Server {
866
898
  }
867
899
  async _scheduleNextAlarm() {
868
900
  const result = this.sql`
869
- SELECT time FROM cf_agents_schedules
901
+ SELECT time FROM cf_agents_schedules
870
902
  WHERE time > ${Math.floor(Date.now() / 1e3)}
871
- ORDER BY time ASC
903
+ ORDER BY time ASC
872
904
  LIMIT 1
873
905
  `;
874
906
  if (!result) return;
@@ -909,14 +941,26 @@ var _Agent = class _Agent extends Server {
909
941
  /**
910
942
  * Connect to a new MCP Server
911
943
  *
944
+ * @param serverName Name of the MCP server
912
945
  * @param url MCP Server SSE URL
913
- * @param callbackHost Base host for the agent, used for the redirect URI.
946
+ * @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
914
947
  * @param agentsPrefix agents routing prefix if not using `agents`
915
948
  * @param options MCP client and transport (header) options
916
949
  * @returns authUrl
917
950
  */
918
951
  async addMcpServer(serverName, url, callbackHost, agentsPrefix = "agents", options) {
919
- const callbackUrl = `${callbackHost}/${agentsPrefix}/${camelCaseToKebabCase(this._ParentClass.name)}/${this.name}/callback`;
952
+ let resolvedCallbackHost = callbackHost;
953
+ if (!resolvedCallbackHost) {
954
+ const { request } = getCurrentAgent();
955
+ if (!request) {
956
+ throw new Error(
957
+ "callbackHost is required when not called within a request context"
958
+ );
959
+ }
960
+ const requestUrl = new URL(request.url);
961
+ resolvedCallbackHost = `${requestUrl.protocol}//${requestUrl.host}`;
962
+ }
963
+ const callbackUrl = `${resolvedCallbackHost}/${agentsPrefix}/${camelCaseToKebabCase(this._ParentClass.name)}/${this.name}/callback`;
920
964
  const result = await this._connectToMcpServerInternal(
921
965
  serverName,
922
966
  url,
@@ -939,7 +983,7 @@ var _Agent = class _Agent extends Server {
939
983
  this.broadcast(
940
984
  JSON.stringify({
941
985
  mcp: this.getMcpServers(),
942
- type: "cf_agent_mcp_servers"
986
+ type: "cf_agent_mcp_servers" /* CF_AGENT_MCP_SERVERS */
943
987
  })
944
988
  );
945
989
  return result;
@@ -970,12 +1014,14 @@ var _Agent = class _Agent extends Server {
970
1014
  }
971
1015
  };
972
1016
  }
1017
+ const transportType = options?.transport?.type || "auto";
973
1018
  const { id, authUrl, clientId } = await this.mcp.connect(url, {
974
1019
  client: options?.client,
975
1020
  reconnect,
976
1021
  transport: {
977
1022
  ...headerTransportOpts,
978
- authProvider
1023
+ authProvider,
1024
+ type: transportType
979
1025
  }
980
1026
  });
981
1027
  return {
@@ -986,13 +1032,14 @@ var _Agent = class _Agent extends Server {
986
1032
  }
987
1033
  async removeMcpServer(id) {
988
1034
  this.mcp.closeConnection(id);
1035
+ this.mcp.unregisterCallbackUrl(id);
989
1036
  this.sql`
990
1037
  DELETE FROM cf_agents_mcp_servers WHERE id = ${id};
991
1038
  `;
992
1039
  this.broadcast(
993
1040
  JSON.stringify({
994
1041
  mcp: this.getMcpServers(),
995
- type: "cf_agent_mcp_servers"
1042
+ type: "cf_agent_mcp_servers" /* CF_AGENT_MCP_SERVERS */
996
1043
  })
997
1044
  );
998
1045
  }
@@ -1032,6 +1079,7 @@ _Agent.options = {
1032
1079
  // default to hibernate
1033
1080
  };
1034
1081
  var Agent = _Agent;
1082
+ var wrappedClasses = /* @__PURE__ */ new Set();
1035
1083
  async function routeAgentRequest(request, env, options) {
1036
1084
  const corsHeaders = options?.cors === true ? {
1037
1085
  "Access-Control-Allow-Credentials": "true",
@@ -1120,25 +1168,35 @@ function createAddressBasedEmailResolver(defaultAgentName) {
1120
1168
  function createCatchAllEmailResolver(agentName, agentId) {
1121
1169
  return async () => ({ agentName, agentId });
1122
1170
  }
1171
+ var agentMapCache = /* @__PURE__ */ new WeakMap();
1123
1172
  async function routeAgentEmail(email, env, options) {
1124
1173
  const routingInfo = await options.resolver(email, env);
1125
1174
  if (!routingInfo) {
1126
1175
  console.warn("No routing information found for email, dropping message");
1127
1176
  return;
1128
1177
  }
1129
- const namespaceBinding = env[routingInfo.agentName];
1130
- if (!namespaceBinding) {
1131
- throw new Error(
1132
- `Agent namespace '${routingInfo.agentName}' not found in environment`
1133
- );
1178
+ if (!agentMapCache.has(env)) {
1179
+ const map = {};
1180
+ for (const [key, value] of Object.entries(env)) {
1181
+ if (value && typeof value === "object" && "idFromName" in value && typeof value.idFromName === "function") {
1182
+ map[key] = value;
1183
+ map[camelCaseToKebabCase(key)] = value;
1184
+ }
1185
+ }
1186
+ agentMapCache.set(env, map);
1134
1187
  }
1135
- if (typeof namespaceBinding !== "object" || !("idFromName" in namespaceBinding) || typeof namespaceBinding.idFromName !== "function") {
1188
+ const agentMap = agentMapCache.get(env);
1189
+ const namespace = agentMap[routingInfo.agentName];
1190
+ if (!namespace) {
1191
+ const availableAgents = Object.keys(agentMap).filter((key) => !key.includes("-")).join(", ");
1136
1192
  throw new Error(
1137
- `Environment binding '${routingInfo.agentName}' is not an AgentNamespace (found: ${typeof namespaceBinding})`
1193
+ `Agent namespace '${routingInfo.agentName}' not found in environment. Available agents: ${availableAgents}`
1138
1194
  );
1139
1195
  }
1140
- const namespace = namespaceBinding;
1141
- const agent = await getAgentByName(namespace, routingInfo.agentId);
1196
+ const agent = await getAgentByName(
1197
+ namespace,
1198
+ routingInfo.agentId
1199
+ );
1142
1200
  const serialisableEmail = {
1143
1201
  getRaw: async () => {
1144
1202
  const reader = email.raw.getReader();
@@ -1200,7 +1258,7 @@ var StreamingResponse = class {
1200
1258
  id: this._id,
1201
1259
  result: chunk,
1202
1260
  success: true,
1203
- type: "rpc"
1261
+ type: "rpc" /* RPC */
1204
1262
  };
1205
1263
  this._connection.send(JSON.stringify(response));
1206
1264
  }
@@ -1218,7 +1276,7 @@ var StreamingResponse = class {
1218
1276
  id: this._id,
1219
1277
  result: finalChunk,
1220
1278
  success: true,
1221
- type: "rpc"
1279
+ type: "rpc" /* RPC */
1222
1280
  };
1223
1281
  this._connection.send(JSON.stringify(response));
1224
1282
  }
@@ -1250,6 +1308,7 @@ function isLocalMode() {
1250
1308
 
1251
1309
  export {
1252
1310
  genericObservability,
1311
+ callable,
1253
1312
  unstable_callable,
1254
1313
  getCurrentAgent,
1255
1314
  Agent,
@@ -1261,4 +1320,4 @@ export {
1261
1320
  getAgentByName,
1262
1321
  StreamingResponse
1263
1322
  };
1264
- //# sourceMappingURL=chunk-5YIRLLUX.js.map
1323
+ //# sourceMappingURL=chunk-RS5OCNEQ.js.map