agents 0.0.0-dfa677f → 0.0.0-e19fea6

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