agents 0.0.0-ca44ae8 → 0.0.0-ca5cdf0

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 (41) hide show
  1. package/dist/ai-chat-agent.d.ts +31 -5
  2. package/dist/ai-chat-agent.js +119 -115
  3. package/dist/ai-chat-agent.js.map +1 -1
  4. package/dist/ai-react.d.ts +17 -4
  5. package/dist/ai-react.js +27 -29
  6. package/dist/ai-react.js.map +1 -1
  7. package/dist/{chunk-MDL3W36D.js → chunk-4CIGD73X.js} +295 -125
  8. package/dist/chunk-4CIGD73X.js.map +1 -0
  9. package/dist/chunk-767EASBA.js +106 -0
  10. package/dist/chunk-767EASBA.js.map +1 -0
  11. package/dist/{chunk-Q5ZBHY4Z.js → chunk-E3LCYPCB.js} +49 -36
  12. package/dist/chunk-E3LCYPCB.js.map +1 -0
  13. package/dist/chunk-NKZZ66QY.js +116 -0
  14. package/dist/chunk-NKZZ66QY.js.map +1 -0
  15. package/dist/client.d.ts +15 -1
  16. package/dist/client.js +6 -126
  17. package/dist/client.js.map +1 -1
  18. package/dist/index.d.ts +103 -9
  19. package/dist/index.js +4 -3
  20. package/dist/mcp/client.d.ts +301 -23
  21. package/dist/mcp/client.js +1 -2
  22. package/dist/mcp/do-oauth-client-provider.d.ts +3 -3
  23. package/dist/mcp/do-oauth-client-provider.js +3 -103
  24. package/dist/mcp/do-oauth-client-provider.js.map +1 -1
  25. package/dist/mcp/index.d.ts +17 -7
  26. package/dist/mcp/index.js +146 -173
  27. package/dist/mcp/index.js.map +1 -1
  28. package/dist/react.d.ts +85 -5
  29. package/dist/react.js +20 -8
  30. package/dist/react.js.map +1 -1
  31. package/dist/schedule.d.ts +2 -2
  32. package/dist/schedule.js +4 -6
  33. package/dist/schedule.js.map +1 -1
  34. package/dist/serializable.d.ts +32 -0
  35. package/dist/serializable.js +1 -0
  36. package/package.json +70 -69
  37. package/src/index.ts +378 -77
  38. package/dist/chunk-HMLY7DHA.js +0 -16
  39. package/dist/chunk-MDL3W36D.js.map +0 -1
  40. package/dist/chunk-Q5ZBHY4Z.js.map +0 -1
  41. /package/dist/{chunk-HMLY7DHA.js.map → serializable.js.map} +0 -0
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  MCPClientManager
3
- } from "./chunk-Q5ZBHY4Z.js";
3
+ } from "./chunk-E3LCYPCB.js";
4
4
  import {
5
- __privateAdd,
6
- __privateGet,
7
- __privateMethod,
8
- __privateSet
9
- } from "./chunk-HMLY7DHA.js";
5
+ DurableObjectOAuthClientProvider
6
+ } from "./chunk-767EASBA.js";
7
+ import {
8
+ camelCaseToKebabCase
9
+ } from "./chunk-NKZZ66QY.js";
10
10
 
11
11
  // src/index.ts
12
+ import { AsyncLocalStorage } from "async_hooks";
13
+ import { parseCronExpression } from "cron-schedule";
14
+ import { nanoid } from "nanoid";
12
15
  import {
13
- Server,
16
+ getServerByName,
14
17
  routePartykitRequest,
15
- getServerByName
18
+ Server
16
19
  } from "partyserver";
17
- import { parseCronExpression } from "cron-schedule";
18
- import { nanoid } from "nanoid";
19
- import { AsyncLocalStorage } from "node:async_hooks";
20
20
  function isRPCRequest(msg) {
21
21
  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
22
  }
@@ -51,14 +51,12 @@ function getCurrentAgent() {
51
51
  }
52
52
  return store;
53
53
  }
54
- var _state, _ParentClass, _Agent_instances, setStateInternal_fn, tryCatch_fn, scheduleNextAlarm_fn, isCallable_fn;
55
54
  var Agent = class extends Server {
56
55
  constructor(ctx, env) {
57
56
  super(ctx, env);
58
- __privateAdd(this, _Agent_instances);
59
- __privateAdd(this, _state, DEFAULT_STATE);
60
- __privateAdd(this, _ParentClass, Object.getPrototypeOf(this).constructor);
61
- this.mcp = new MCPClientManager(__privateGet(this, _ParentClass).name, "0.0.1");
57
+ this._state = DEFAULT_STATE;
58
+ this._ParentClass = Object.getPrototypeOf(this).constructor;
59
+ this.mcp = new MCPClientManager(this._ParentClass.name, "0.0.1");
62
60
  /**
63
61
  * Initial state for the Agent
64
62
  * Override to provide default state values
@@ -105,7 +103,7 @@ var Agent = class extends Server {
105
103
  `;
106
104
  }
107
105
  }
108
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
106
+ await this._scheduleNextAlarm();
109
107
  };
110
108
  this.sql`
111
109
  CREATE TABLE IF NOT EXISTS cf_agents_state (
@@ -114,7 +112,7 @@ var Agent = class extends Server {
114
112
  )
115
113
  `;
116
114
  void this.ctx.blockConcurrencyWhile(async () => {
117
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, async () => {
115
+ return this._tryCatch(async () => {
118
116
  this.sql`
119
117
  CREATE TABLE IF NOT EXISTS cf_agents_schedules (
120
118
  id TEXT PRIMARY KEY NOT NULL DEFAULT (randomblob(9)),
@@ -130,12 +128,36 @@ var Agent = class extends Server {
130
128
  await this.alarm();
131
129
  });
132
130
  });
131
+ this.sql`
132
+ CREATE TABLE IF NOT EXISTS cf_agents_mcp_servers (
133
+ id TEXT PRIMARY KEY NOT NULL,
134
+ name TEXT NOT NULL,
135
+ server_url TEXT NOT NULL,
136
+ callback_url TEXT NOT NULL,
137
+ client_id TEXT,
138
+ auth_url TEXT,
139
+ server_options TEXT
140
+ )
141
+ `;
133
142
  const _onRequest = this.onRequest.bind(this);
134
143
  this.onRequest = (request) => {
135
144
  return agentContext.run(
136
145
  { agent: this, connection: void 0, request },
137
146
  async () => {
138
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onRequest(request));
147
+ if (this.mcp.isCallbackRequest(request)) {
148
+ await this.mcp.handleCallbackRequest(request);
149
+ this.broadcast(
150
+ JSON.stringify({
151
+ mcp: this.getMcpServers(),
152
+ type: "cf_agent_mcp_servers"
153
+ })
154
+ );
155
+ return new Response("<script>window.close();</script>", {
156
+ headers: { "content-type": "text/html" },
157
+ status: 200
158
+ });
159
+ }
160
+ return this._tryCatch(() => _onRequest(request));
139
161
  }
140
162
  );
141
163
  };
@@ -145,16 +167,16 @@ var Agent = class extends Server {
145
167
  { agent: this, connection, request: void 0 },
146
168
  async () => {
147
169
  if (typeof message !== "string") {
148
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onMessage(connection, message));
170
+ return this._tryCatch(() => _onMessage(connection, message));
149
171
  }
150
172
  let parsed;
151
173
  try {
152
174
  parsed = JSON.parse(message);
153
- } catch (e) {
154
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onMessage(connection, message));
175
+ } catch (_e) {
176
+ return this._tryCatch(() => _onMessage(connection, message));
155
177
  }
156
178
  if (isStateUpdateMessage(parsed)) {
157
- __privateMethod(this, _Agent_instances, setStateInternal_fn).call(this, parsed.state, connection);
179
+ this._setStateInternal(parsed.state, connection);
158
180
  return;
159
181
  }
160
182
  if (isRPCRequest(parsed)) {
@@ -164,7 +186,7 @@ var Agent = class extends Server {
164
186
  if (typeof methodFn !== "function") {
165
187
  throw new Error(`Method ${method} does not exist`);
166
188
  }
167
- if (!__privateMethod(this, _Agent_instances, isCallable_fn).call(this, method)) {
189
+ if (!this._isCallable(method)) {
168
190
  throw new Error(`Method ${method} is not callable`);
169
191
  }
170
192
  const metadata = callableMetadata.get(methodFn);
@@ -175,26 +197,26 @@ var Agent = class extends Server {
175
197
  }
176
198
  const result = await methodFn.apply(this, args);
177
199
  const response = {
178
- type: "rpc",
200
+ done: true,
179
201
  id,
180
- success: true,
181
202
  result,
182
- done: true
203
+ success: true,
204
+ type: "rpc"
183
205
  };
184
206
  connection.send(JSON.stringify(response));
185
207
  } catch (e) {
186
208
  const response = {
187
- type: "rpc",
209
+ error: e instanceof Error ? e.message : "Unknown error occurred",
188
210
  id: parsed.id,
189
211
  success: false,
190
- error: e instanceof Error ? e.message : "Unknown error occurred"
212
+ type: "rpc"
191
213
  };
192
214
  connection.send(JSON.stringify(response));
193
215
  console.error("RPC error:", e);
194
216
  }
195
217
  return;
196
218
  }
197
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onMessage(connection, message));
219
+ return this._tryCatch(() => _onMessage(connection, message));
198
220
  }
199
221
  );
200
222
  };
@@ -207,23 +229,62 @@ var Agent = class extends Server {
207
229
  if (this.state) {
208
230
  connection.send(
209
231
  JSON.stringify({
210
- type: "cf_agent_state",
211
- state: this.state
232
+ state: this.state,
233
+ type: "cf_agent_state"
212
234
  })
213
235
  );
214
236
  }
215
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onConnect(connection, ctx2));
237
+ connection.send(
238
+ JSON.stringify({
239
+ mcp: this.getMcpServers(),
240
+ type: "cf_agent_mcp_servers"
241
+ })
242
+ );
243
+ return this._tryCatch(() => _onConnect(connection, ctx2));
216
244
  }, 20);
217
245
  }
218
246
  );
219
247
  };
248
+ const _onStart = this.onStart.bind(this);
249
+ this.onStart = async () => {
250
+ return agentContext.run(
251
+ { agent: this, connection: void 0, request: void 0 },
252
+ async () => {
253
+ const servers = this.sql`
254
+ SELECT id, name, server_url, client_id, auth_url, callback_url, server_options FROM cf_agents_mcp_servers;
255
+ `;
256
+ Promise.allSettled(
257
+ servers.map((server) => {
258
+ return this._connectToMcpServerInternal(
259
+ server.name,
260
+ server.server_url,
261
+ server.callback_url,
262
+ server.server_options ? JSON.parse(server.server_options) : void 0,
263
+ {
264
+ id: server.id,
265
+ oauthClientId: server.client_id ?? void 0
266
+ }
267
+ );
268
+ })
269
+ ).then((_results) => {
270
+ this.broadcast(
271
+ JSON.stringify({
272
+ mcp: this.getMcpServers(),
273
+ type: "cf_agent_mcp_servers"
274
+ })
275
+ );
276
+ });
277
+ await this._tryCatch(() => _onStart());
278
+ }
279
+ );
280
+ };
220
281
  }
221
282
  /**
222
283
  * Current state of the Agent
223
284
  */
224
285
  get state() {
225
- if (__privateGet(this, _state) !== DEFAULT_STATE) {
226
- return __privateGet(this, _state);
286
+ if (this._state !== DEFAULT_STATE) {
287
+ return this._state;
227
288
  }
228
289
  const wasChanged = this.sql`
229
290
  SELECT state FROM cf_agents_state WHERE id = ${STATE_WAS_CHANGED}
@@ -234,8 +295,8 @@ var Agent = class extends Server {
234
295
  if (wasChanged[0]?.state === "true" || // we do this check for people who updated their code before we shipped wasChanged
235
296
  result[0]?.state) {
236
297
  const state = result[0]?.state;
237
- __privateSet(this, _state, JSON.parse(state));
238
- return __privateGet(this, _state);
298
+ this._state = JSON.parse(state);
299
+ return this._state;
239
300
  }
240
301
  if (this.initialState === DEFAULT_STATE) {
241
302
  return void 0;
@@ -263,24 +324,53 @@ var Agent = class extends Server {
263
324
  throw this.onError(e);
264
325
  }
265
326
  }
327
+ _setStateInternal(state, source = "server") {
328
+ this._state = state;
329
+ this.sql`
330
+ INSERT OR REPLACE INTO cf_agents_state (id, state)
331
+ VALUES (${STATE_ROW_ID}, ${JSON.stringify(state)})
332
+ `;
333
+ this.sql`
334
+ INSERT OR REPLACE INTO cf_agents_state (id, state)
335
+ VALUES (${STATE_WAS_CHANGED}, ${JSON.stringify(true)})
336
+ `;
337
+ this.broadcast(
338
+ JSON.stringify({
339
+ state,
340
+ type: "cf_agent_state"
341
+ }),
342
+ source !== "server" ? [source.id] : []
343
+ );
344
+ return this._tryCatch(() => {
345
+ const { connection, request } = agentContext.getStore() || {};
346
+ return agentContext.run(
347
+ { agent: this, connection, request },
348
+ async () => {
349
+ return this.onStateUpdate(state, source);
350
+ }
351
+ );
352
+ });
353
+ }
266
354
  /**
267
355
  * Update the Agent's state
268
356
  * @param state New state to set
269
357
  */
270
358
  setState(state) {
271
- __privateMethod(this, _Agent_instances, setStateInternal_fn).call(this, state, "server");
359
+ this._setStateInternal(state, "server");
272
360
  }
273
361
  /**
274
362
  * Called when the Agent's state is updated
275
363
  * @param state Updated state
276
364
  * @param source Source of the state update ("server" or a client connection)
277
365
  */
366
+ // biome-ignore lint/correctness/noUnusedFunctionParameters: overridden later
278
367
  onStateUpdate(state, source) {
279
368
  }
280
369
  /**
281
370
  * Called when the Agent receives an email
282
371
  * @param email Email message to process
283
372
  */
373
+ // biome-ignore lint/correctness/noUnusedFunctionParameters: overridden later
284
374
  onEmail(email) {
285
375
  return agentContext.run(
286
376
  { agent: this, connection: void 0, request: void 0 },
@@ -289,6 +379,13 @@ var Agent = class extends Server {
289
379
  }
290
380
  );
291
381
  }
382
+ async _tryCatch(fn) {
383
+ try {
384
+ return await fn();
385
+ } catch (e) {
386
+ throw this.onError(e);
387
+ }
388
+ }
292
389
  onError(connectionOrError, error) {
293
390
  let theError;
294
391
  if (connectionOrError && error) {
@@ -338,10 +435,10 @@ var Agent = class extends Server {
338
435
  payload
339
436
  )}, 'scheduled', ${timestamp})
340
437
  `;
341
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
438
+ await this._scheduleNextAlarm();
342
439
  return {
343
- id,
344
440
  callback,
441
+ id,
345
442
  payload,
346
443
  time: timestamp,
347
444
  type: "scheduled"
@@ -356,12 +453,12 @@ var Agent = class extends Server {
356
453
  payload
357
454
  )}, 'delayed', ${when}, ${timestamp})
358
455
  `;
359
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
456
+ await this._scheduleNextAlarm();
360
457
  return {
361
- id,
362
458
  callback,
363
- payload,
364
459
  delayInSeconds: when,
460
+ id,
461
+ payload,
365
462
  time: timestamp,
366
463
  type: "delayed"
367
464
  };
@@ -375,12 +472,12 @@ var Agent = class extends Server {
375
472
  payload
376
473
  )}, 'cron', ${when}, ${timestamp})
377
474
  `;
378
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
475
+ await this._scheduleNextAlarm();
379
476
  return {
380
- id,
381
477
  callback,
382
- payload,
383
478
  cron: when,
479
+ id,
480
+ payload,
384
481
  time: timestamp,
385
482
  type: "cron"
386
483
  };
@@ -442,76 +539,155 @@ var Agent = class extends Server {
442
539
  */
443
540
  async cancelSchedule(id) {
444
541
  this.sql`DELETE FROM cf_agents_schedules WHERE id = ${id}`;
445
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
542
+ await this._scheduleNextAlarm();
446
543
  return true;
447
544
  }
545
+ async _scheduleNextAlarm() {
546
+ const result = this.sql`
547
+ SELECT time FROM cf_agents_schedules
548
+ WHERE time > ${Math.floor(Date.now() / 1e3)}
549
+ ORDER BY time ASC
550
+ LIMIT 1
551
+ `;
552
+ if (!result) return;
553
+ if (result.length > 0 && "time" in result[0]) {
554
+ const nextTime = result[0].time * 1e3;
555
+ await this.ctx.storage.setAlarm(nextTime);
556
+ }
557
+ }
448
558
  /**
449
559
  * Destroy the Agent, removing all state and scheduled tasks
450
560
  */
451
561
  async destroy() {
452
562
  this.sql`DROP TABLE IF EXISTS cf_agents_state`;
453
563
  this.sql`DROP TABLE IF EXISTS cf_agents_schedules`;
564
+ this.sql`DROP TABLE IF EXISTS cf_agents_mcp_servers`;
454
565
  await this.ctx.storage.deleteAlarm();
455
566
  await this.ctx.storage.deleteAll();
567
+ this.ctx.abort("destroyed");
456
568
  }
457
- };
458
- _state = new WeakMap();
459
- _ParentClass = new WeakMap();
460
- _Agent_instances = new WeakSet();
461
- setStateInternal_fn = function(state, source = "server") {
462
- __privateSet(this, _state, state);
463
- this.sql`
464
- INSERT OR REPLACE INTO cf_agents_state (id, state)
465
- VALUES (${STATE_ROW_ID}, ${JSON.stringify(state)})
466
- `;
467
- this.sql`
468
- INSERT OR REPLACE INTO cf_agents_state (id, state)
469
- VALUES (${STATE_WAS_CHANGED}, ${JSON.stringify(true)})
470
- `;
471
- this.broadcast(
472
- JSON.stringify({
473
- type: "cf_agent_state",
474
- state
475
- }),
476
- source !== "server" ? [source.id] : []
477
- );
478
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => {
479
- const { connection, request } = agentContext.getStore() || {};
480
- return agentContext.run(
481
- { agent: this, connection, request },
482
- async () => {
483
- return this.onStateUpdate(state, source);
569
+ /**
570
+ * Get all methods marked as callable on this Agent
571
+ * @returns A map of method names to their metadata
572
+ */
573
+ _isCallable(method) {
574
+ return callableMetadata.has(this[method]);
575
+ }
576
+ /**
577
+ * Connect to a new MCP Server
578
+ *
579
+ * @param url MCP Server SSE URL
580
+ * @param callbackHost Base host for the agent, used for the redirect URI.
581
+ * @param agentsPrefix agents routing prefix if not using `agents`
582
+ * @param options MCP client and transport (header) options
583
+ * @returns authUrl
584
+ */
585
+ async addMcpServer(serverName, url, callbackHost, agentsPrefix = "agents", options) {
586
+ const callbackUrl = `${callbackHost}/${agentsPrefix}/${camelCaseToKebabCase(this._ParentClass.name)}/${this.name}/callback`;
587
+ const result = await this._connectToMcpServerInternal(
588
+ serverName,
589
+ url,
590
+ callbackUrl,
591
+ options
592
+ );
593
+ this.sql`
594
+ INSERT
595
+ OR REPLACE INTO cf_agents_mcp_servers (id, name, server_url, client_id, auth_url, callback_url, server_options)
596
+ VALUES (
597
+ ${result.id},
598
+ ${serverName},
599
+ ${url},
600
+ ${result.clientId ?? null},
601
+ ${result.authUrl ?? null},
602
+ ${callbackUrl},
603
+ ${options ? JSON.stringify(options) : null}
604
+ );
605
+ `;
606
+ this.broadcast(
607
+ JSON.stringify({
608
+ mcp: this.getMcpServers(),
609
+ type: "cf_agent_mcp_servers"
610
+ })
611
+ );
612
+ return result;
613
+ }
614
+ async _connectToMcpServerInternal(_serverName, url, callbackUrl, options, reconnect) {
615
+ const authProvider = new DurableObjectOAuthClientProvider(
616
+ this.ctx.storage,
617
+ this.name,
618
+ callbackUrl
619
+ );
620
+ if (reconnect) {
621
+ authProvider.serverId = reconnect.id;
622
+ if (reconnect.oauthClientId) {
623
+ authProvider.clientId = reconnect.oauthClientId;
484
624
  }
625
+ }
626
+ let headerTransportOpts = {};
627
+ if (options?.transport?.headers) {
628
+ headerTransportOpts = {
629
+ eventSourceInit: {
630
+ fetch: (url2, init) => fetch(url2, {
631
+ ...init,
632
+ headers: options?.transport?.headers
633
+ })
634
+ },
635
+ requestInit: {
636
+ headers: options?.transport?.headers
637
+ }
638
+ };
639
+ }
640
+ const { id, authUrl, clientId } = await this.mcp.connect(url, {
641
+ client: options?.client,
642
+ reconnect,
643
+ transport: {
644
+ ...headerTransportOpts,
645
+ authProvider
646
+ }
647
+ });
648
+ return {
649
+ authUrl,
650
+ clientId,
651
+ id
652
+ };
653
+ }
654
+ async removeMcpServer(id) {
655
+ this.mcp.closeConnection(id);
656
+ this.sql`
657
+ DELETE FROM cf_agents_mcp_servers WHERE id = ${id};
658
+ `;
659
+ this.broadcast(
660
+ JSON.stringify({
661
+ mcp: this.getMcpServers(),
662
+ type: "cf_agent_mcp_servers"
663
+ })
485
664
  );
486
- });
487
- };
488
- tryCatch_fn = async function(fn) {
489
- try {
490
- return await fn();
491
- } catch (e) {
492
- throw this.onError(e);
493
665
  }
494
- };
495
- scheduleNextAlarm_fn = async function() {
496
- const result = this.sql`
497
- SELECT time FROM cf_agents_schedules
498
- WHERE time > ${Math.floor(Date.now() / 1e3)}
499
- ORDER BY time ASC
500
- LIMIT 1
666
+ getMcpServers() {
667
+ const mcpState = {
668
+ prompts: this.mcp.listPrompts(),
669
+ resources: this.mcp.listResources(),
670
+ servers: {},
671
+ tools: this.mcp.listTools()
672
+ };
673
+ const servers = this.sql`
674
+ SELECT id, name, server_url, client_id, auth_url, callback_url, server_options FROM cf_agents_mcp_servers;
501
675
  `;
502
- if (!result) return;
503
- if (result.length > 0 && "time" in result[0]) {
504
- const nextTime = result[0].time * 1e3;
505
- await this.ctx.storage.setAlarm(nextTime);
676
+ for (const server of servers) {
677
+ const serverConn = this.mcp.mcpConnections[server.id];
678
+ mcpState.servers[server.id] = {
679
+ auth_url: server.auth_url,
680
+ capabilities: serverConn?.serverCapabilities ?? null,
681
+ instructions: serverConn?.instructions ?? null,
682
+ name: server.name,
683
+ server_url: server.server_url,
684
+ // mark as "authenticating" because the server isn't automatically connected, so it's pending authenticating
685
+ state: serverConn?.connectionState ?? "authenticating"
686
+ };
687
+ }
688
+ return mcpState;
506
689
  }
507
690
  };
508
- /**
509
- * Get all methods marked as callable on this Agent
510
- * @returns A map of method names to their metadata
511
- */
512
- isCallable_fn = function(method) {
513
- return callableMetadata.has(this[method]);
514
- };
515
691
  /**
516
692
  * Agent configuration options
517
693
  */
@@ -522,9 +698,9 @@ Agent.options = {
522
698
  };
523
699
  async function routeAgentRequest(request, env, options) {
524
700
  const corsHeaders = options?.cors === true ? {
525
- "Access-Control-Allow-Origin": "*",
526
- "Access-Control-Allow-Methods": "GET, POST, HEAD, OPTIONS",
527
701
  "Access-Control-Allow-Credentials": "true",
702
+ "Access-Control-Allow-Methods": "GET, POST, HEAD, OPTIONS",
703
+ "Access-Control-Allow-Origin": "*",
528
704
  "Access-Control-Max-Age": "86400"
529
705
  } : options?.cors;
530
706
  if (request.method === "OPTIONS") {
@@ -555,59 +731,53 @@ async function routeAgentRequest(request, env, options) {
555
731
  }
556
732
  return response;
557
733
  }
558
- async function routeAgentEmail(email, env, options) {
734
+ async function routeAgentEmail(_email, _env, _options) {
559
735
  }
560
736
  async function getAgentByName(namespace, name, options) {
561
737
  return getServerByName(namespace, name, options);
562
738
  }
563
- var _connection, _id, _closed;
564
739
  var StreamingResponse = class {
565
740
  constructor(connection, id) {
566
- __privateAdd(this, _connection);
567
- __privateAdd(this, _id);
568
- __privateAdd(this, _closed, false);
569
- __privateSet(this, _connection, connection);
570
- __privateSet(this, _id, id);
741
+ this._closed = false;
742
+ this._connection = connection;
743
+ this._id = id;
571
744
  }
572
745
  /**
573
746
  * Send a chunk of data to the client
574
747
  * @param chunk The data to send
575
748
  */
576
749
  send(chunk) {
577
- if (__privateGet(this, _closed)) {
750
+ if (this._closed) {
578
751
  throw new Error("StreamingResponse is already closed");
579
752
  }
580
753
  const response = {
581
- type: "rpc",
582
- id: __privateGet(this, _id),
583
- success: true,
754
+ done: false,
755
+ id: this._id,
584
756
  result: chunk,
585
- done: false
757
+ success: true,
758
+ type: "rpc"
586
759
  };
587
- __privateGet(this, _connection).send(JSON.stringify(response));
760
+ this._connection.send(JSON.stringify(response));
588
761
  }
589
762
  /**
590
763
  * End the stream and send the final chunk (if any)
591
764
  * @param finalChunk Optional final chunk of data to send
592
765
  */
593
766
  end(finalChunk) {
594
- if (__privateGet(this, _closed)) {
767
+ if (this._closed) {
595
768
  throw new Error("StreamingResponse is already closed");
596
769
  }
597
- __privateSet(this, _closed, true);
770
+ this._closed = true;
598
771
  const response = {
599
- type: "rpc",
600
- id: __privateGet(this, _id),
601
- success: true,
772
+ done: true,
773
+ id: this._id,
602
774
  result: finalChunk,
603
- done: true
775
+ success: true,
776
+ type: "rpc"
604
777
  };
605
- __privateGet(this, _connection).send(JSON.stringify(response));
778
+ this._connection.send(JSON.stringify(response));
606
779
  }
607
780
  };
608
- _connection = new WeakMap();
609
- _id = new WeakMap();
610
- _closed = new WeakMap();
611
781
 
612
782
  export {
613
783
  unstable_callable,
@@ -618,4 +788,4 @@ export {
618
788
  getAgentByName,
619
789
  StreamingResponse
620
790
  };
621
- //# sourceMappingURL=chunk-MDL3W36D.js.map
791
+ //# sourceMappingURL=chunk-4CIGD73X.js.map