agents 0.0.0-8ebc079 → 0.0.0-8f03865

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 (80) hide show
  1. package/README.md +257 -27
  2. package/dist/ai-chat-agent.d.ts +131 -20
  3. package/dist/ai-chat-agent.js +812 -226
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration-DguhuLKF.js +155 -0
  6. package/dist/ai-chat-v5-migration-DguhuLKF.js.map +1 -0
  7. package/dist/ai-chat-v5-migration.d.ts +155 -0
  8. package/dist/ai-chat-v5-migration.js +3 -0
  9. package/dist/ai-react.d.ts +79 -72
  10. package/dist/ai-react.js +411 -201
  11. package/dist/ai-react.js.map +1 -1
  12. package/dist/ai-types-CwgHzwUb.js +24 -0
  13. package/dist/ai-types-CwgHzwUb.js.map +1 -0
  14. package/dist/ai-types-D_hTbf25.d.ts +103 -0
  15. package/dist/ai-types.d.ts +6 -74
  16. package/dist/ai-types.js +3 -1
  17. package/dist/cli/index.d.ts +1 -0
  18. package/dist/cli/index.js +28 -0
  19. package/dist/cli/index.js.map +1 -0
  20. package/dist/client-C_M5uPrn.d.ts +834 -0
  21. package/dist/client-CcyhkGfN.js +117 -0
  22. package/dist/client-CcyhkGfN.js.map +1 -0
  23. package/dist/client-ClORm6f0.d.ts +104 -0
  24. package/dist/client-QZa2Rq0l.js +1105 -0
  25. package/dist/client-QZa2Rq0l.js.map +1 -0
  26. package/dist/client.d.ts +12 -79
  27. package/dist/client.js +3 -130
  28. package/dist/codemode/ai.d.ts +27 -0
  29. package/dist/codemode/ai.js +152 -0
  30. package/dist/codemode/ai.js.map +1 -0
  31. package/dist/context-BkKbAa1R.js +8 -0
  32. package/dist/context-BkKbAa1R.js.map +1 -0
  33. package/dist/context-_sPQqJWv.d.ts +24 -0
  34. package/dist/context.d.ts +6 -0
  35. package/dist/context.js +3 -0
  36. package/dist/do-oauth-client-provider-B-ryFIPr.d.ts +70 -0
  37. package/dist/do-oauth-client-provider-B1fVIshX.js +155 -0
  38. package/dist/do-oauth-client-provider-B1fVIshX.js.map +1 -0
  39. package/dist/index-CyDpAVHZ.d.ts +58 -0
  40. package/dist/index-DUnsVDnf.d.ts +577 -0
  41. package/dist/index.d.ts +62 -310
  42. package/dist/index.js +8 -21
  43. package/dist/mcp/client.d.ts +4 -777
  44. package/dist/mcp/client.js +4 -10
  45. package/dist/mcp/do-oauth-client-provider.d.ts +2 -41
  46. package/dist/mcp/do-oauth-client-provider.js +2 -106
  47. package/dist/mcp/index.d.ts +191 -71
  48. package/dist/mcp/index.js +1437 -799
  49. package/dist/mcp/index.js.map +1 -1
  50. package/dist/mcp/x402.d.ts +34 -0
  51. package/dist/mcp/x402.js +198 -0
  52. package/dist/mcp/x402.js.map +1 -0
  53. package/dist/mcp-CzbSsLfc.d.ts +61 -0
  54. package/dist/observability/index.d.ts +3 -0
  55. package/dist/observability/index.js +8 -0
  56. package/dist/react-DIGWa87z.d.ts +137 -0
  57. package/dist/react.d.ts +15 -39
  58. package/dist/react.js +190 -98
  59. package/dist/react.js.map +1 -1
  60. package/dist/schedule.d.ts +89 -12
  61. package/dist/schedule.js +46 -23
  62. package/dist/schedule.js.map +1 -1
  63. package/dist/serializable-C4GLimgv.d.ts +39 -0
  64. package/dist/serializable.d.ts +7 -0
  65. package/dist/serializable.js +1 -0
  66. package/dist/src-BmbDclOA.js +1181 -0
  67. package/dist/src-BmbDclOA.js.map +1 -0
  68. package/package.json +125 -69
  69. package/dist/ai-types.js.map +0 -1
  70. package/dist/chunk-7VFQNJFK.js +0 -462
  71. package/dist/chunk-7VFQNJFK.js.map +0 -1
  72. package/dist/chunk-HMLY7DHA.js +0 -16
  73. package/dist/chunk-HMLY7DHA.js.map +0 -1
  74. package/dist/chunk-JR3NW4A7.js +0 -621
  75. package/dist/chunk-JR3NW4A7.js.map +0 -1
  76. package/dist/client.js.map +0 -1
  77. package/dist/index.js.map +0 -1
  78. package/dist/mcp/client.js.map +0 -1
  79. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  80. package/src/index.ts +0 -956
@@ -1,621 +0,0 @@
1
- import {
2
- MCPClientManager
3
- } from "./chunk-7VFQNJFK.js";
4
- import {
5
- __privateAdd,
6
- __privateGet,
7
- __privateMethod,
8
- __privateSet
9
- } from "./chunk-HMLY7DHA.js";
10
-
11
- // src/index.ts
12
- import {
13
- Server,
14
- routePartykitRequest,
15
- getServerByName
16
- } from "partyserver";
17
- import { parseCronExpression } from "cron-schedule";
18
- import { nanoid } from "nanoid";
19
- import { AsyncLocalStorage } from "node:async_hooks";
20
- function isRPCRequest(msg) {
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
- }
23
- function isStateUpdateMessage(msg) {
24
- return typeof msg === "object" && msg !== null && "type" in msg && msg.type === "cf_agent_state" && "state" in msg;
25
- }
26
- var callableMetadata = /* @__PURE__ */ new Map();
27
- function unstable_callable(metadata = {}) {
28
- return function callableDecorator(target, context) {
29
- if (!callableMetadata.has(target)) {
30
- callableMetadata.set(target, metadata);
31
- }
32
- return target;
33
- };
34
- }
35
- function getNextCronTime(cron) {
36
- const interval = parseCronExpression(cron);
37
- return interval.getNextDate();
38
- }
39
- var STATE_ROW_ID = "cf_state_row_id";
40
- var STATE_WAS_CHANGED = "cf_state_was_changed";
41
- var DEFAULT_STATE = {};
42
- var agentContext = new AsyncLocalStorage();
43
- function getCurrentAgent() {
44
- const store = agentContext.getStore();
45
- if (!store) {
46
- return {
47
- agent: void 0,
48
- connection: void 0,
49
- request: void 0
50
- };
51
- }
52
- return store;
53
- }
54
- var _state, _ParentClass, _Agent_instances, setStateInternal_fn, tryCatch_fn, scheduleNextAlarm_fn, isCallable_fn;
55
- var Agent = class extends Server {
56
- constructor(ctx, env) {
57
- 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");
62
- /**
63
- * Initial state for the Agent
64
- * Override to provide default state values
65
- */
66
- this.initialState = DEFAULT_STATE;
67
- /**
68
- * Method called when an alarm fires.
69
- * Executes any scheduled tasks that are due.
70
- *
71
- * @remarks
72
- * To schedule a task, please use the `this.schedule` method instead.
73
- * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
74
- */
75
- this.alarm = async () => {
76
- const now = Math.floor(Date.now() / 1e3);
77
- const result = this.sql`
78
- SELECT * FROM cf_agents_schedules WHERE time <= ${now}
79
- `;
80
- for (const row of result || []) {
81
- const callback = this[row.callback];
82
- if (!callback) {
83
- console.error(`callback ${row.callback} not found`);
84
- continue;
85
- }
86
- await agentContext.run(
87
- { agent: this, connection: void 0, request: void 0 },
88
- async () => {
89
- try {
90
- await callback.bind(this)(JSON.parse(row.payload), row);
91
- } catch (e) {
92
- console.error(`error executing callback "${row.callback}"`, e);
93
- }
94
- }
95
- );
96
- if (row.type === "cron") {
97
- const nextExecutionTime = getNextCronTime(row.cron);
98
- const nextTimestamp = Math.floor(nextExecutionTime.getTime() / 1e3);
99
- this.sql`
100
- UPDATE cf_agents_schedules SET time = ${nextTimestamp} WHERE id = ${row.id}
101
- `;
102
- } else {
103
- this.sql`
104
- DELETE FROM cf_agents_schedules WHERE id = ${row.id}
105
- `;
106
- }
107
- }
108
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
109
- };
110
- this.sql`
111
- CREATE TABLE IF NOT EXISTS cf_agents_state (
112
- id TEXT PRIMARY KEY NOT NULL,
113
- state TEXT
114
- )
115
- `;
116
- void this.ctx.blockConcurrencyWhile(async () => {
117
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, async () => {
118
- this.sql`
119
- CREATE TABLE IF NOT EXISTS cf_agents_schedules (
120
- id TEXT PRIMARY KEY NOT NULL DEFAULT (randomblob(9)),
121
- callback TEXT,
122
- payload TEXT,
123
- type TEXT NOT NULL CHECK(type IN ('scheduled', 'delayed', 'cron')),
124
- time INTEGER,
125
- delayInSeconds INTEGER,
126
- cron TEXT,
127
- created_at INTEGER DEFAULT (unixepoch())
128
- )
129
- `;
130
- await this.alarm();
131
- });
132
- });
133
- const _onRequest = this.onRequest.bind(this);
134
- this.onRequest = (request) => {
135
- return agentContext.run(
136
- { agent: this, connection: void 0, request },
137
- async () => {
138
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onRequest(request));
139
- }
140
- );
141
- };
142
- const _onMessage = this.onMessage.bind(this);
143
- this.onMessage = async (connection, message) => {
144
- return agentContext.run(
145
- { agent: this, connection, request: void 0 },
146
- async () => {
147
- if (typeof message !== "string") {
148
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onMessage(connection, message));
149
- }
150
- let parsed;
151
- try {
152
- parsed = JSON.parse(message);
153
- } catch (e) {
154
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onMessage(connection, message));
155
- }
156
- if (isStateUpdateMessage(parsed)) {
157
- __privateMethod(this, _Agent_instances, setStateInternal_fn).call(this, parsed.state, connection);
158
- return;
159
- }
160
- if (isRPCRequest(parsed)) {
161
- try {
162
- const { id, method, args } = parsed;
163
- const methodFn = this[method];
164
- if (typeof methodFn !== "function") {
165
- throw new Error(`Method ${method} does not exist`);
166
- }
167
- if (!__privateMethod(this, _Agent_instances, isCallable_fn).call(this, method)) {
168
- throw new Error(`Method ${method} is not callable`);
169
- }
170
- const metadata = callableMetadata.get(methodFn);
171
- if (metadata?.streaming) {
172
- const stream = new StreamingResponse(connection, id);
173
- await methodFn.apply(this, [stream, ...args]);
174
- return;
175
- }
176
- const result = await methodFn.apply(this, args);
177
- const response = {
178
- type: "rpc",
179
- id,
180
- success: true,
181
- result,
182
- done: true
183
- };
184
- connection.send(JSON.stringify(response));
185
- } catch (e) {
186
- const response = {
187
- type: "rpc",
188
- id: parsed.id,
189
- success: false,
190
- error: e instanceof Error ? e.message : "Unknown error occurred"
191
- };
192
- connection.send(JSON.stringify(response));
193
- console.error("RPC error:", e);
194
- }
195
- return;
196
- }
197
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onMessage(connection, message));
198
- }
199
- );
200
- };
201
- const _onConnect = this.onConnect.bind(this);
202
- this.onConnect = (connection, ctx2) => {
203
- return agentContext.run(
204
- { agent: this, connection, request: ctx2.request },
205
- async () => {
206
- setTimeout(() => {
207
- if (this.state) {
208
- connection.send(
209
- JSON.stringify({
210
- type: "cf_agent_state",
211
- state: this.state
212
- })
213
- );
214
- }
215
- return __privateMethod(this, _Agent_instances, tryCatch_fn).call(this, () => _onConnect(connection, ctx2));
216
- }, 20);
217
- }
218
- );
219
- };
220
- }
221
- /**
222
- * Current state of the Agent
223
- */
224
- get state() {
225
- if (__privateGet(this, _state) !== DEFAULT_STATE) {
226
- return __privateGet(this, _state);
227
- }
228
- const wasChanged = this.sql`
229
- SELECT state FROM cf_agents_state WHERE id = ${STATE_WAS_CHANGED}
230
- `;
231
- const result = this.sql`
232
- SELECT state FROM cf_agents_state WHERE id = ${STATE_ROW_ID}
233
- `;
234
- if (wasChanged[0]?.state === "true" || // we do this check for people who updated their code before we shipped wasChanged
235
- result[0]?.state) {
236
- const state = result[0]?.state;
237
- __privateSet(this, _state, JSON.parse(state));
238
- return __privateGet(this, _state);
239
- }
240
- if (this.initialState === DEFAULT_STATE) {
241
- return void 0;
242
- }
243
- this.setState(this.initialState);
244
- return this.initialState;
245
- }
246
- /**
247
- * Execute SQL queries against the Agent's database
248
- * @template T Type of the returned rows
249
- * @param strings SQL query template strings
250
- * @param values Values to be inserted into the query
251
- * @returns Array of query results
252
- */
253
- sql(strings, ...values) {
254
- let query = "";
255
- try {
256
- query = strings.reduce(
257
- (acc, str, i) => acc + str + (i < values.length ? "?" : ""),
258
- ""
259
- );
260
- return [...this.ctx.storage.sql.exec(query, ...values)];
261
- } catch (e) {
262
- console.error(`failed to execute sql query: ${query}`, e);
263
- throw this.onError(e);
264
- }
265
- }
266
- /**
267
- * Update the Agent's state
268
- * @param state New state to set
269
- */
270
- setState(state) {
271
- __privateMethod(this, _Agent_instances, setStateInternal_fn).call(this, state, "server");
272
- }
273
- /**
274
- * Called when the Agent's state is updated
275
- * @param state Updated state
276
- * @param source Source of the state update ("server" or a client connection)
277
- */
278
- onStateUpdate(state, source) {
279
- }
280
- /**
281
- * Called when the Agent receives an email
282
- * @param email Email message to process
283
- */
284
- onEmail(email) {
285
- return agentContext.run(
286
- { agent: this, connection: void 0, request: void 0 },
287
- async () => {
288
- console.error("onEmail not implemented");
289
- }
290
- );
291
- }
292
- onError(connectionOrError, error) {
293
- let theError;
294
- if (connectionOrError && error) {
295
- theError = error;
296
- console.error(
297
- "Error on websocket connection:",
298
- connectionOrError.id,
299
- theError
300
- );
301
- console.error(
302
- "Override onError(connection, error) to handle websocket connection errors"
303
- );
304
- } else {
305
- theError = connectionOrError;
306
- console.error("Error on server:", theError);
307
- console.error("Override onError(error) to handle server errors");
308
- }
309
- throw theError;
310
- }
311
- /**
312
- * Render content (not implemented in base class)
313
- */
314
- render() {
315
- throw new Error("Not implemented");
316
- }
317
- /**
318
- * Schedule a task to be executed in the future
319
- * @template T Type of the payload data
320
- * @param when When to execute the task (Date, seconds delay, or cron expression)
321
- * @param callback Name of the method to call
322
- * @param payload Data to pass to the callback
323
- * @returns Schedule object representing the scheduled task
324
- */
325
- async schedule(when, callback, payload) {
326
- const id = nanoid(9);
327
- if (typeof callback !== "string") {
328
- throw new Error("Callback must be a string");
329
- }
330
- if (typeof this[callback] !== "function") {
331
- throw new Error(`this.${callback} is not a function`);
332
- }
333
- if (when instanceof Date) {
334
- const timestamp = Math.floor(when.getTime() / 1e3);
335
- this.sql`
336
- INSERT OR REPLACE INTO cf_agents_schedules (id, callback, payload, type, time)
337
- VALUES (${id}, ${callback}, ${JSON.stringify(
338
- payload
339
- )}, 'scheduled', ${timestamp})
340
- `;
341
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
342
- return {
343
- id,
344
- callback,
345
- payload,
346
- time: timestamp,
347
- type: "scheduled"
348
- };
349
- }
350
- if (typeof when === "number") {
351
- const time = new Date(Date.now() + when * 1e3);
352
- const timestamp = Math.floor(time.getTime() / 1e3);
353
- this.sql`
354
- INSERT OR REPLACE INTO cf_agents_schedules (id, callback, payload, type, delayInSeconds, time)
355
- VALUES (${id}, ${callback}, ${JSON.stringify(
356
- payload
357
- )}, 'delayed', ${when}, ${timestamp})
358
- `;
359
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
360
- return {
361
- id,
362
- callback,
363
- payload,
364
- delayInSeconds: when,
365
- time: timestamp,
366
- type: "delayed"
367
- };
368
- }
369
- if (typeof when === "string") {
370
- const nextExecutionTime = getNextCronTime(when);
371
- const timestamp = Math.floor(nextExecutionTime.getTime() / 1e3);
372
- this.sql`
373
- INSERT OR REPLACE INTO cf_agents_schedules (id, callback, payload, type, cron, time)
374
- VALUES (${id}, ${callback}, ${JSON.stringify(
375
- payload
376
- )}, 'cron', ${when}, ${timestamp})
377
- `;
378
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
379
- return {
380
- id,
381
- callback,
382
- payload,
383
- cron: when,
384
- time: timestamp,
385
- type: "cron"
386
- };
387
- }
388
- throw new Error("Invalid schedule type");
389
- }
390
- /**
391
- * Get a scheduled task by ID
392
- * @template T Type of the payload data
393
- * @param id ID of the scheduled task
394
- * @returns The Schedule object or undefined if not found
395
- */
396
- async getSchedule(id) {
397
- const result = this.sql`
398
- SELECT * FROM cf_agents_schedules WHERE id = ${id}
399
- `;
400
- if (!result) {
401
- console.error(`schedule ${id} not found`);
402
- return void 0;
403
- }
404
- return { ...result[0], payload: JSON.parse(result[0].payload) };
405
- }
406
- /**
407
- * Get scheduled tasks matching the given criteria
408
- * @template T Type of the payload data
409
- * @param criteria Criteria to filter schedules
410
- * @returns Array of matching Schedule objects
411
- */
412
- getSchedules(criteria = {}) {
413
- let query = "SELECT * FROM cf_agents_schedules WHERE 1=1";
414
- const params = [];
415
- if (criteria.id) {
416
- query += " AND id = ?";
417
- params.push(criteria.id);
418
- }
419
- if (criteria.type) {
420
- query += " AND type = ?";
421
- params.push(criteria.type);
422
- }
423
- if (criteria.timeRange) {
424
- query += " AND time >= ? AND time <= ?";
425
- const start = criteria.timeRange.start || /* @__PURE__ */ new Date(0);
426
- const end = criteria.timeRange.end || /* @__PURE__ */ new Date(999999999999999);
427
- params.push(
428
- Math.floor(start.getTime() / 1e3),
429
- Math.floor(end.getTime() / 1e3)
430
- );
431
- }
432
- const result = this.ctx.storage.sql.exec(query, ...params).toArray().map((row) => ({
433
- ...row,
434
- payload: JSON.parse(row.payload)
435
- }));
436
- return result;
437
- }
438
- /**
439
- * Cancel a scheduled task
440
- * @param id ID of the task to cancel
441
- * @returns true if the task was cancelled, false otherwise
442
- */
443
- async cancelSchedule(id) {
444
- this.sql`DELETE FROM cf_agents_schedules WHERE id = ${id}`;
445
- await __privateMethod(this, _Agent_instances, scheduleNextAlarm_fn).call(this);
446
- return true;
447
- }
448
- /**
449
- * Destroy the Agent, removing all state and scheduled tasks
450
- */
451
- async destroy() {
452
- this.sql`DROP TABLE IF EXISTS cf_agents_state`;
453
- this.sql`DROP TABLE IF EXISTS cf_agents_schedules`;
454
- await this.ctx.storage.deleteAlarm();
455
- await this.ctx.storage.deleteAll();
456
- }
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);
484
- }
485
- );
486
- });
487
- };
488
- tryCatch_fn = async function(fn) {
489
- try {
490
- return await fn();
491
- } catch (e) {
492
- throw this.onError(e);
493
- }
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
501
- `;
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);
506
- }
507
- };
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
- /**
516
- * Agent configuration options
517
- */
518
- Agent.options = {
519
- /** Whether the Agent should hibernate when inactive */
520
- hibernate: true
521
- // default to hibernate
522
- };
523
- async function routeAgentRequest(request, env, options) {
524
- const corsHeaders = options?.cors === true ? {
525
- "Access-Control-Allow-Origin": "*",
526
- "Access-Control-Allow-Methods": "GET, POST, HEAD, OPTIONS",
527
- "Access-Control-Allow-Credentials": "true",
528
- "Access-Control-Max-Age": "86400"
529
- } : options?.cors;
530
- if (request.method === "OPTIONS") {
531
- if (corsHeaders) {
532
- return new Response(null, {
533
- headers: corsHeaders
534
- });
535
- }
536
- console.warn(
537
- "Received an OPTIONS request, but cors was not enabled. Pass `cors: true` or `cors: { ...custom cors headers }` to routeAgentRequest to enable CORS."
538
- );
539
- }
540
- let response = await routePartykitRequest(
541
- request,
542
- env,
543
- {
544
- prefix: "agents",
545
- ...options
546
- }
547
- );
548
- if (response && corsHeaders && request.headers.get("upgrade")?.toLowerCase() !== "websocket" && request.headers.get("Upgrade")?.toLowerCase() !== "websocket") {
549
- response = new Response(response.body, {
550
- headers: {
551
- ...response.headers,
552
- ...corsHeaders
553
- }
554
- });
555
- }
556
- return response;
557
- }
558
- async function routeAgentEmail(email, env, options) {
559
- }
560
- async function getAgentByName(namespace, name, options) {
561
- return getServerByName(namespace, name, options);
562
- }
563
- var _connection, _id, _closed;
564
- var StreamingResponse = class {
565
- 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);
571
- }
572
- /**
573
- * Send a chunk of data to the client
574
- * @param chunk The data to send
575
- */
576
- send(chunk) {
577
- if (__privateGet(this, _closed)) {
578
- throw new Error("StreamingResponse is already closed");
579
- }
580
- const response = {
581
- type: "rpc",
582
- id: __privateGet(this, _id),
583
- success: true,
584
- result: chunk,
585
- done: false
586
- };
587
- __privateGet(this, _connection).send(JSON.stringify(response));
588
- }
589
- /**
590
- * End the stream and send the final chunk (if any)
591
- * @param finalChunk Optional final chunk of data to send
592
- */
593
- end(finalChunk) {
594
- if (__privateGet(this, _closed)) {
595
- throw new Error("StreamingResponse is already closed");
596
- }
597
- __privateSet(this, _closed, true);
598
- const response = {
599
- type: "rpc",
600
- id: __privateGet(this, _id),
601
- success: true,
602
- result: finalChunk,
603
- done: true
604
- };
605
- __privateGet(this, _connection).send(JSON.stringify(response));
606
- }
607
- };
608
- _connection = new WeakMap();
609
- _id = new WeakMap();
610
- _closed = new WeakMap();
611
-
612
- export {
613
- unstable_callable,
614
- getCurrentAgent,
615
- Agent,
616
- routeAgentRequest,
617
- routeAgentEmail,
618
- getAgentByName,
619
- StreamingResponse
620
- };
621
- //# sourceMappingURL=chunk-JR3NW4A7.js.map