agents 0.0.0-c8f53b8 → 0.0.0-cac66b8

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 (40) hide show
  1. package/dist/ai-chat-agent.d.ts +27 -1
  2. package/dist/ai-chat-agent.js +99 -103
  3. package/dist/ai-chat-agent.js.map +1 -1
  4. package/dist/ai-react.d.ts +13 -0
  5. package/dist/ai-react.js +1 -2
  6. package/dist/ai-react.js.map +1 -1
  7. package/dist/chunk-BZXOAZUX.js +106 -0
  8. package/dist/chunk-BZXOAZUX.js.map +1 -0
  9. package/dist/{chunk-HD4VEHBA.js → chunk-DVT5CDUP.js} +306 -131
  10. package/dist/chunk-DVT5CDUP.js.map +1 -0
  11. package/dist/{chunk-Q5ZBHY4Z.js → chunk-IFXSRTKF.js} +33 -24
  12. package/dist/chunk-IFXSRTKF.js.map +1 -0
  13. package/dist/chunk-VCSB47AK.js +116 -0
  14. package/dist/chunk-VCSB47AK.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 +104 -7
  19. package/dist/index.js +4 -3
  20. package/dist/mcp/client.d.ts +21 -15
  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 +11 -1
  26. package/dist/mcp/index.js +110 -137
  27. package/dist/mcp/index.js.map +1 -1
  28. package/dist/react.d.ts +85 -5
  29. package/dist/react.js +14 -2
  30. package/dist/react.js.map +1 -1
  31. package/dist/schedule.js +0 -2
  32. package/dist/schedule.js.map +1 -1
  33. package/dist/serializable.d.ts +32 -0
  34. package/dist/serializable.js +1 -0
  35. package/package.json +10 -7
  36. package/src/index.ts +353 -45
  37. package/dist/chunk-HD4VEHBA.js.map +0 -1
  38. package/dist/chunk-HMLY7DHA.js +0 -16
  39. package/dist/chunk-Q5ZBHY4Z.js.map +0 -1
  40. /package/dist/{chunk-HMLY7DHA.js.map → serializable.js.map} +0 -0
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  MCPClientManager
3
- } from "./chunk-Q5ZBHY4Z.js";
3
+ } from "./chunk-IFXSRTKF.js";
4
4
  import {
5
- __privateAdd,
6
- __privateGet,
7
- __privateMethod,
8
- __privateSet
9
- } from "./chunk-HMLY7DHA.js";
5
+ DurableObjectOAuthClientProvider
6
+ } from "./chunk-BZXOAZUX.js";
7
+ import {
8
+ camelCaseToKebabCase
9
+ } from "./chunk-VCSB47AK.js";
10
10
 
11
11
  // src/index.ts
12
12
  import {
@@ -51,19 +51,60 @@ 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
65
63
  */
66
64
  this.initialState = DEFAULT_STATE;
65
+ /**
66
+ * Method called when an alarm fires.
67
+ * Executes any scheduled tasks that are due.
68
+ *
69
+ * @remarks
70
+ * To schedule a task, please use the `this.schedule` method instead.
71
+ * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
72
+ */
73
+ this.alarm = async () => {
74
+ const now = Math.floor(Date.now() / 1e3);
75
+ const result = this.sql`
76
+ SELECT * FROM cf_agents_schedules WHERE time <= ${now}
77
+ `;
78
+ for (const row of result || []) {
79
+ const callback = this[row.callback];
80
+ if (!callback) {
81
+ console.error(`callback ${row.callback} not found`);
82
+ continue;
83
+ }
84
+ await agentContext.run(
85
+ { agent: this, connection: void 0, request: void 0 },
86
+ async () => {
87
+ try {
88
+ await callback.bind(this)(JSON.parse(row.payload), row);
89
+ } catch (e) {
90
+ console.error(`error executing callback "${row.callback}"`, e);
91
+ }
92
+ }
93
+ );
94
+ if (row.type === "cron") {
95
+ const nextExecutionTime = getNextCronTime(row.cron);
96
+ const nextTimestamp = Math.floor(nextExecutionTime.getTime() / 1e3);
97
+ this.sql`
98
+ UPDATE cf_agents_schedules SET time = ${nextTimestamp} WHERE id = ${row.id}
99
+ `;
100
+ } else {
101
+ this.sql`
102
+ DELETE FROM cf_agents_schedules WHERE id = ${row.id}
103
+ `;
104
+ }
105
+ }
106
+ await this._scheduleNextAlarm();
107
+ };
67
108
  this.sql`
68
109
  CREATE TABLE IF NOT EXISTS cf_agents_state (
69
110
  id TEXT PRIMARY KEY NOT NULL,
@@ -71,7 +112,7 @@ var Agent = class extends Server {
71
112
  )
72
113
  `;
73
114
  void this.ctx.blockConcurrencyWhile(async () => {
74
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, async () => {
115
+ return this._tryCatch(async () => {
75
116
  this.sql`
76
117
  CREATE TABLE IF NOT EXISTS cf_agents_schedules (
77
118
  id TEXT PRIMARY KEY NOT NULL DEFAULT (randomblob(9)),
@@ -87,22 +128,55 @@ var Agent = class extends Server {
87
128
  await this.alarm();
88
129
  });
89
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
+ `;
142
+ const _onRequest = this.onRequest.bind(this);
143
+ this.onRequest = (request) => {
144
+ return agentContext.run(
145
+ { agent: this, connection: void 0, request },
146
+ async () => {
147
+ if (this.mcp.isCallbackRequest(request)) {
148
+ await this.mcp.handleCallbackRequest(request);
149
+ this.broadcast(
150
+ JSON.stringify({
151
+ type: "cf_agent_mcp_servers",
152
+ mcp: this.getMcpServers()
153
+ })
154
+ );
155
+ return new Response("<script>window.close();</script>", {
156
+ status: 200,
157
+ headers: { "content-type": "text/html" }
158
+ });
159
+ }
160
+ return this._tryCatch(() => _onRequest(request));
161
+ }
162
+ );
163
+ };
90
164
  const _onMessage = this.onMessage.bind(this);
91
165
  this.onMessage = async (connection, message) => {
92
166
  return agentContext.run(
93
167
  { agent: this, connection, request: void 0 },
94
168
  async () => {
95
169
  if (typeof message !== "string") {
96
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onMessage(connection, message));
170
+ return this._tryCatch(() => _onMessage(connection, message));
97
171
  }
98
172
  let parsed;
99
173
  try {
100
174
  parsed = JSON.parse(message);
101
175
  } catch (e) {
102
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onMessage(connection, message));
176
+ return this._tryCatch(() => _onMessage(connection, message));
103
177
  }
104
178
  if (isStateUpdateMessage(parsed)) {
105
- __privateMethod(this, _Agent_instances, setStateInternal_fn).call(this, parsed.state, connection);
179
+ this._setStateInternal(parsed.state, connection);
106
180
  return;
107
181
  }
108
182
  if (isRPCRequest(parsed)) {
@@ -112,7 +186,7 @@ var Agent = class extends Server {
112
186
  if (typeof methodFn !== "function") {
113
187
  throw new Error(`Method ${method} does not exist`);
114
188
  }
115
- if (!__privateMethod(this, _Agent_instances, isCallable_fn).call(this, method)) {
189
+ if (!this._isCallable(method)) {
116
190
  throw new Error(`Method ${method} is not callable`);
117
191
  }
118
192
  const metadata = callableMetadata.get(methodFn);
@@ -142,7 +216,7 @@ var Agent = class extends Server {
142
216
  }
143
217
  return;
144
218
  }
145
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onMessage(connection, message));
219
+ return this._tryCatch(() => _onMessage(connection, message));
146
220
  }
147
221
  );
148
222
  };
@@ -160,18 +234,56 @@ var Agent = class extends Server {
160
234
  })
161
235
  );
162
236
  }
163
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onConnect(connection, ctx2));
237
+ connection.send(
238
+ JSON.stringify({
239
+ type: "cf_agent_mcp_servers",
240
+ mcp: this.getMcpServers()
241
+ })
242
+ );
243
+ return this._tryCatch(() => _onConnect(connection, ctx2));
164
244
  }, 20);
165
245
  }
166
246
  );
167
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
+ await 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
+ );
270
+ this.broadcast(
271
+ JSON.stringify({
272
+ type: "cf_agent_mcp_servers",
273
+ mcp: this.getMcpServers()
274
+ })
275
+ );
276
+ await this._tryCatch(() => _onStart());
277
+ }
278
+ );
279
+ };
168
280
  }
169
281
  /**
170
282
  * Current state of the Agent
171
283
  */
172
284
  get state() {
173
- if (__privateGet(this, _state) !== DEFAULT_STATE) {
174
- return __privateGet(this, _state);
285
+ if (this._state !== DEFAULT_STATE) {
286
+ return this._state;
175
287
  }
176
288
  const wasChanged = this.sql`
177
289
  SELECT state FROM cf_agents_state WHERE id = ${STATE_WAS_CHANGED}
@@ -182,8 +294,8 @@ var Agent = class extends Server {
182
294
  if (wasChanged[0]?.state === "true" || // we do this check for people who updated their code before we shipped wasChanged
183
295
  result[0]?.state) {
184
296
  const state = result[0]?.state;
185
- __privateSet(this, _state, JSON.parse(state));
186
- return __privateGet(this, _state);
297
+ this._state = JSON.parse(state);
298
+ return this._state;
187
299
  }
188
300
  if (this.initialState === DEFAULT_STATE) {
189
301
  return void 0;
@@ -211,12 +323,39 @@ var Agent = class extends Server {
211
323
  throw this.onError(e);
212
324
  }
213
325
  }
326
+ _setStateInternal(state, source = "server") {
327
+ this._state = state;
328
+ this.sql`
329
+ INSERT OR REPLACE INTO cf_agents_state (id, state)
330
+ VALUES (${STATE_ROW_ID}, ${JSON.stringify(state)})
331
+ `;
332
+ this.sql`
333
+ INSERT OR REPLACE INTO cf_agents_state (id, state)
334
+ VALUES (${STATE_WAS_CHANGED}, ${JSON.stringify(true)})
335
+ `;
336
+ this.broadcast(
337
+ JSON.stringify({
338
+ type: "cf_agent_state",
339
+ state
340
+ }),
341
+ source !== "server" ? [source.id] : []
342
+ );
343
+ return this._tryCatch(() => {
344
+ const { connection, request } = agentContext.getStore() || {};
345
+ return agentContext.run(
346
+ { agent: this, connection, request },
347
+ async () => {
348
+ return this.onStateUpdate(state, source);
349
+ }
350
+ );
351
+ });
352
+ }
214
353
  /**
215
354
  * Update the Agent's state
216
355
  * @param state New state to set
217
356
  */
218
357
  setState(state) {
219
- __privateMethod(this, _Agent_instances, setStateInternal_fn).call(this, state, "server");
358
+ this._setStateInternal(state, "server");
220
359
  }
221
360
  /**
222
361
  * Called when the Agent's state is updated
@@ -237,6 +376,13 @@ var Agent = class extends Server {
237
376
  }
238
377
  );
239
378
  }
379
+ async _tryCatch(fn) {
380
+ try {
381
+ return await fn();
382
+ } catch (e) {
383
+ throw this.onError(e);
384
+ }
385
+ }
240
386
  onError(connectionOrError, error) {
241
387
  let theError;
242
388
  if (connectionOrError && error) {
@@ -286,7 +432,7 @@ var Agent = class extends Server {
286
432
  payload
287
433
  )}, 'scheduled', ${timestamp})
288
434
  `;
289
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
435
+ await this._scheduleNextAlarm();
290
436
  return {
291
437
  id,
292
438
  callback,
@@ -304,7 +450,7 @@ var Agent = class extends Server {
304
450
  payload
305
451
  )}, 'delayed', ${when}, ${timestamp})
306
452
  `;
307
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
453
+ await this._scheduleNextAlarm();
308
454
  return {
309
455
  id,
310
456
  callback,
@@ -323,7 +469,7 @@ var Agent = class extends Server {
323
469
  payload
324
470
  )}, 'cron', ${when}, ${timestamp})
325
471
  `;
326
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
472
+ await this._scheduleNextAlarm();
327
473
  return {
328
474
  id,
329
475
  callback,
@@ -390,47 +536,21 @@ var Agent = class extends Server {
390
536
  */
391
537
  async cancelSchedule(id) {
392
538
  this.sql`DELETE FROM cf_agents_schedules WHERE id = ${id}`;
393
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
539
+ await this._scheduleNextAlarm();
394
540
  return true;
395
541
  }
396
- /**
397
- * Method called when an alarm fires
398
- * Executes any scheduled tasks that are due
399
- */
400
- async alarm() {
401
- const now = Math.floor(Date.now() / 1e3);
542
+ async _scheduleNextAlarm() {
402
543
  const result = this.sql`
403
- SELECT * FROM cf_agents_schedules WHERE time <= ${now}
544
+ SELECT time FROM cf_agents_schedules
545
+ WHERE time > ${Math.floor(Date.now() / 1e3)}
546
+ ORDER BY time ASC
547
+ LIMIT 1
404
548
  `;
405
- for (const row of result || []) {
406
- const callback = this[row.callback];
407
- if (!callback) {
408
- console.error(`callback ${row.callback} not found`);
409
- continue;
410
- }
411
- await agentContext.run(
412
- { agent: this, connection: void 0, request: void 0 },
413
- async () => {
414
- try {
415
- await callback.bind(this)(JSON.parse(row.payload), row);
416
- } catch (e) {
417
- console.error(`error executing callback "${row.callback}"`, e);
418
- }
419
- }
420
- );
421
- if (row.type === "cron") {
422
- const nextExecutionTime = getNextCronTime(row.cron);
423
- const nextTimestamp = Math.floor(nextExecutionTime.getTime() / 1e3);
424
- this.sql`
425
- UPDATE cf_agents_schedules SET time = ${nextTimestamp} WHERE id = ${row.id}
426
- `;
427
- } else {
428
- this.sql`
429
- DELETE FROM cf_agents_schedules WHERE id = ${row.id}
430
- `;
431
- }
549
+ if (!result) return;
550
+ if (result.length > 0 && "time" in result[0]) {
551
+ const nextTime = result[0].time * 1e3;
552
+ await this.ctx.storage.setAlarm(nextTime);
432
553
  }
433
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
434
554
  }
435
555
  /**
436
556
  * Destroy the Agent, removing all state and scheduled tasks
@@ -438,67 +558,128 @@ var Agent = class extends Server {
438
558
  async destroy() {
439
559
  this.sql`DROP TABLE IF EXISTS cf_agents_state`;
440
560
  this.sql`DROP TABLE IF EXISTS cf_agents_schedules`;
561
+ this.sql`DROP TABLE IF EXISTS cf_agents_mcp_servers`;
441
562
  await this.ctx.storage.deleteAlarm();
442
563
  await this.ctx.storage.deleteAll();
443
564
  }
444
- };
445
- _state = new WeakMap();
446
- _ParentClass = new WeakMap();
447
- _Agent_instances = new WeakSet();
448
- setStateInternal_fn = function(state, source = "server") {
449
- __privateSet(this, _state, state);
450
- this.sql`
451
- INSERT OR REPLACE INTO cf_agents_state (id, state)
452
- VALUES (${STATE_ROW_ID}, ${JSON.stringify(state)})
453
- `;
454
- this.sql`
455
- INSERT OR REPLACE INTO cf_agents_state (id, state)
456
- VALUES (${STATE_WAS_CHANGED}, ${JSON.stringify(true)})
457
- `;
458
- this.broadcast(
459
- JSON.stringify({
460
- type: "cf_agent_state",
461
- state
462
- }),
463
- source !== "server" ? [source.id] : []
464
- );
465
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => {
466
- const { connection, request } = agentContext.getStore() || {};
467
- return agentContext.run(
468
- { agent: this, connection, request },
469
- async () => {
470
- return this.onStateUpdate(state, source);
565
+ /**
566
+ * Get all methods marked as callable on this Agent
567
+ * @returns A map of method names to their metadata
568
+ */
569
+ _isCallable(method) {
570
+ return callableMetadata.has(this[method]);
571
+ }
572
+ /**
573
+ * Connect to a new MCP Server
574
+ *
575
+ * @param url MCP Server SSE URL
576
+ * @param callbackHost Base host for the agent, used for the redirect URI.
577
+ * @param agentsPrefix agents routing prefix if not using `agents`
578
+ * @param options MCP client and transport (header) options
579
+ * @returns authUrl
580
+ */
581
+ async addMcpServer(serverName, url, callbackHost, agentsPrefix = "agents", options) {
582
+ const callbackUrl = `${callbackHost}/${agentsPrefix}/${camelCaseToKebabCase(this._ParentClass.name)}/${this.name}/callback`;
583
+ const result = await this._connectToMcpServerInternal(
584
+ serverName,
585
+ url,
586
+ callbackUrl,
587
+ options
588
+ );
589
+ this.broadcast(
590
+ JSON.stringify({
591
+ type: "cf_agent_mcp_servers",
592
+ mcp: this.getMcpServers()
593
+ })
594
+ );
595
+ return result;
596
+ }
597
+ async _connectToMcpServerInternal(serverName, url, callbackUrl, options, reconnect) {
598
+ const authProvider = new DurableObjectOAuthClientProvider(
599
+ this.ctx.storage,
600
+ this.name,
601
+ callbackUrl
602
+ );
603
+ if (reconnect) {
604
+ authProvider.serverId = reconnect.id;
605
+ if (reconnect.oauthClientId) {
606
+ authProvider.clientId = reconnect.oauthClientId;
471
607
  }
608
+ }
609
+ let headerTransportOpts = {};
610
+ if (options?.transport?.headers) {
611
+ headerTransportOpts = {
612
+ eventSourceInit: {
613
+ fetch: (url2, init) => fetch(url2, {
614
+ ...init,
615
+ headers: options?.transport?.headers
616
+ })
617
+ },
618
+ requestInit: {
619
+ headers: options?.transport?.headers
620
+ }
621
+ };
622
+ }
623
+ const { id, authUrl, clientId } = await this.mcp.connect(url, {
624
+ reconnect,
625
+ transport: {
626
+ ...headerTransportOpts,
627
+ authProvider
628
+ },
629
+ client: options?.client
630
+ });
631
+ this.sql`
632
+ INSERT OR REPLACE INTO cf_agents_mcp_servers (id, name, server_url, client_id, auth_url, callback_url, server_options)
633
+ VALUES (
634
+ ${id},
635
+ ${serverName},
636
+ ${url},
637
+ ${clientId ?? null},
638
+ ${authUrl ?? null},
639
+ ${callbackUrl},
640
+ ${options ? JSON.stringify(options) : null}
641
+ );
642
+ `;
643
+ return {
644
+ id,
645
+ authUrl
646
+ };
647
+ }
648
+ async removeMcpServer(id) {
649
+ this.mcp.closeConnection(id);
650
+ this.sql`
651
+ DELETE FROM cf_agents_mcp_servers WHERE id = ${id};
652
+ `;
653
+ this.broadcast(
654
+ JSON.stringify({
655
+ type: "cf_agent_mcp_servers",
656
+ mcp: this.getMcpServers()
657
+ })
472
658
  );
473
- });
474
- };
475
- tryCatch_fn = async function(fn) {
476
- try {
477
- return await fn();
478
- } catch (e) {
479
- throw this.onError(e);
480
659
  }
481
- };
482
- scheduleNextAlarm_fn = async function() {
483
- const result = this.sql`
484
- SELECT time FROM cf_agents_schedules
485
- WHERE time > ${Math.floor(Date.now() / 1e3)}
486
- ORDER BY time ASC
487
- LIMIT 1
660
+ getMcpServers() {
661
+ const mcpState = {
662
+ servers: {},
663
+ tools: this.mcp.listTools(),
664
+ prompts: this.mcp.listPrompts(),
665
+ resources: this.mcp.listResources()
666
+ };
667
+ const servers = this.sql`
668
+ SELECT id, name, server_url, client_id, auth_url, callback_url, server_options FROM cf_agents_mcp_servers;
488
669
  `;
489
- if (!result) return;
490
- if (result.length > 0 && "time" in result[0]) {
491
- const nextTime = result[0].time * 1e3;
492
- await this.ctx.storage.setAlarm(nextTime);
670
+ for (const server of servers) {
671
+ mcpState.servers[server.id] = {
672
+ name: server.name,
673
+ server_url: server.server_url,
674
+ auth_url: server.auth_url,
675
+ state: this.mcp.mcpConnections[server.id].connectionState,
676
+ instructions: this.mcp.mcpConnections[server.id].instructions ?? null,
677
+ capabilities: this.mcp.mcpConnections[server.id].serverCapabilities ?? null
678
+ };
679
+ }
680
+ return mcpState;
493
681
  }
494
682
  };
495
- /**
496
- * Get all methods marked as callable on this Agent
497
- * @returns A map of method names to their metadata
498
- */
499
- isCallable_fn = function(method) {
500
- return callableMetadata.has(this[method]);
501
- };
502
683
  /**
503
684
  * Agent configuration options
504
685
  */
@@ -547,54 +728,48 @@ async function routeAgentEmail(email, env, options) {
547
728
  async function getAgentByName(namespace, name, options) {
548
729
  return getServerByName(namespace, name, options);
549
730
  }
550
- var _connection, _id, _closed;
551
731
  var StreamingResponse = class {
552
732
  constructor(connection, id) {
553
- __privateAdd(this, _connection);
554
- __privateAdd(this, _id);
555
- __privateAdd(this, _closed, false);
556
- __privateSet(this, _connection, connection);
557
- __privateSet(this, _id, id);
733
+ this._closed = false;
734
+ this._connection = connection;
735
+ this._id = id;
558
736
  }
559
737
  /**
560
738
  * Send a chunk of data to the client
561
739
  * @param chunk The data to send
562
740
  */
563
741
  send(chunk) {
564
- if (__privateGet(this, _closed)) {
742
+ if (this._closed) {
565
743
  throw new Error("StreamingResponse is already closed");
566
744
  }
567
745
  const response = {
568
746
  type: "rpc",
569
- id: __privateGet(this, _id),
747
+ id: this._id,
570
748
  success: true,
571
749
  result: chunk,
572
750
  done: false
573
751
  };
574
- __privateGet(this, _connection).send(JSON.stringify(response));
752
+ this._connection.send(JSON.stringify(response));
575
753
  }
576
754
  /**
577
755
  * End the stream and send the final chunk (if any)
578
756
  * @param finalChunk Optional final chunk of data to send
579
757
  */
580
758
  end(finalChunk) {
581
- if (__privateGet(this, _closed)) {
759
+ if (this._closed) {
582
760
  throw new Error("StreamingResponse is already closed");
583
761
  }
584
- __privateSet(this, _closed, true);
762
+ this._closed = true;
585
763
  const response = {
586
764
  type: "rpc",
587
- id: __privateGet(this, _id),
765
+ id: this._id,
588
766
  success: true,
589
767
  result: finalChunk,
590
768
  done: true
591
769
  };
592
- __privateGet(this, _connection).send(JSON.stringify(response));
770
+ this._connection.send(JSON.stringify(response));
593
771
  }
594
772
  };
595
- _connection = new WeakMap();
596
- _id = new WeakMap();
597
- _closed = new WeakMap();
598
773
 
599
774
  export {
600
775
  unstable_callable,
@@ -605,4 +780,4 @@ export {
605
780
  getAgentByName,
606
781
  StreamingResponse
607
782
  };
608
- //# sourceMappingURL=chunk-HD4VEHBA.js.map
783
+ //# sourceMappingURL=chunk-DVT5CDUP.js.map