agents 0.8.0 → 0.8.2

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.
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as Agent } from "./index-BXYKcQZg.js";
1
+ import { r as Agent } from "./index-B6N5URLg.js";
2
2
  import {
3
3
  i as SerializableValue,
4
4
  n as RPCMethod,
@@ -1,4 +1,4 @@
1
- import { r as Agent } from "../index-BXYKcQZg.js";
1
+ import { r as Agent } from "../index-B6N5URLg.js";
2
2
  //#region src/experimental/forever.d.ts
3
3
  type FiberState = {
4
4
  id: string;
@@ -706,7 +706,7 @@ declare class MCPClientConnection {
706
706
  */
707
707
  getTransport(
708
708
  transportType: BaseTransportType
709
- ): StreamableHTTPClientTransport | SSEClientTransport | RPCClientTransport;
709
+ ): SSEClientTransport | StreamableHTTPClientTransport | RPCClientTransport;
710
710
  private tryConnect;
711
711
  private _capabilityErrorHandler;
712
712
  }
@@ -2322,9 +2322,6 @@ declare class Agent<
2322
2322
  * @throws Error if workflow binding not found in environment
2323
2323
  * @throws Error if workflow is already completed/errored/terminated (from Cloudflare)
2324
2324
  *
2325
- * @note `terminate()` is not yet supported in local development (wrangler dev).
2326
- * It will throw an error locally but works when deployed to Cloudflare.
2327
- *
2328
2325
  * @example
2329
2326
  * ```typescript
2330
2327
  * await this.terminateWorkflow(workflowId);
@@ -2340,9 +2337,6 @@ declare class Agent<
2340
2337
  * @throws Error if workflow binding not found in environment
2341
2338
  * @throws Error if workflow is not running (from Cloudflare)
2342
2339
  *
2343
- * @note `pause()` is not yet supported in local development (wrangler dev).
2344
- * It will throw an error locally but works when deployed to Cloudflare.
2345
- *
2346
2340
  * @example
2347
2341
  * ```typescript
2348
2342
  * await this.pauseWorkflow(workflowId);
@@ -2357,9 +2351,6 @@ declare class Agent<
2357
2351
  * @throws Error if workflow binding not found in environment
2358
2352
  * @throws Error if workflow is not paused (from Cloudflare)
2359
2353
  *
2360
- * @note `resume()` is not yet supported in local development (wrangler dev).
2361
- * It will throw an error locally but works when deployed to Cloudflare.
2362
- *
2363
2354
  * @example
2364
2355
  * ```typescript
2365
2356
  * await this.resumeWorkflow(workflowId);
@@ -2377,9 +2368,6 @@ declare class Agent<
2377
2368
  * @throws Error if workflow not found in tracking table
2378
2369
  * @throws Error if workflow binding not found in environment
2379
2370
  *
2380
- * @note `restart()` is not yet supported in local development (wrangler dev).
2381
- * It will throw an error locally but works when deployed to Cloudflare.
2382
- *
2383
2371
  * @example
2384
2372
  * ```typescript
2385
2373
  * // Reset tracking (default)
@@ -2863,4 +2851,4 @@ export {
2863
2851
  Schedule as y,
2864
2852
  MCPServerOptions as z
2865
2853
  };
2866
- //# sourceMappingURL=index-BXYKcQZg.d.ts.map
2854
+ //# sourceMappingURL=index-B6N5URLg.d.ts.map
package/dist/index.d.ts CHANGED
@@ -33,7 +33,7 @@ import {
33
33
  w as SubAgentStub,
34
34
  x as StateUpdateMessage,
35
35
  y as Schedule
36
- } from "./index-BXYKcQZg.js";
36
+ } from "./index-B6N5URLg.js";
37
37
  import {
38
38
  n as AgentsOAuthProvider,
39
39
  r as DurableObjectOAuthClientProvider,
package/dist/index.js CHANGED
@@ -1705,14 +1705,14 @@ var Agent = class Agent extends Server {
1705
1705
  const DUPLICATE_SCHEDULE_THRESHOLD = 10;
1706
1706
  const oneShotCounts = /* @__PURE__ */ new Map();
1707
1707
  for (const row of result) if (row.type === "delayed" || row.type === "scheduled") oneShotCounts.set(row.callback, (oneShotCounts.get(row.callback) ?? 0) + 1);
1708
- for (const [cb, count] of oneShotCounts) if (count >= DUPLICATE_SCHEDULE_THRESHOLD) {
1708
+ for (const [cb, count] of oneShotCounts) if (count >= DUPLICATE_SCHEDULE_THRESHOLD) try {
1709
1709
  console.warn(`Processing ${count} stale "${cb}" schedules in a single alarm cycle. This usually means schedule() is being called repeatedly without the idempotent option. Consider using scheduleEvery() for recurring tasks or passing { idempotent: true } to schedule().`);
1710
1710
  this._emit("schedule:duplicate_warning", {
1711
1711
  callback: cb,
1712
1712
  count,
1713
1713
  type: "one-shot"
1714
1714
  });
1715
- }
1715
+ } catch {}
1716
1716
  for (const row of result) {
1717
1717
  const callback = this[row.callback];
1718
1718
  if (!callback) {
@@ -1737,7 +1737,19 @@ var Agent = class Agent extends Server {
1737
1737
  email: void 0
1738
1738
  }, async () => {
1739
1739
  const { maxAttempts, baseDelayMs, maxDelayMs } = resolveRetryConfig(parseRetryOptions(row), this._resolvedOptions.retry);
1740
- const parsedPayload = JSON.parse(row.payload);
1740
+ let parsedPayload;
1741
+ try {
1742
+ parsedPayload = JSON.parse(row.payload);
1743
+ } catch (e) {
1744
+ console.error(`Failed to parse payload for schedule "${row.id}" (callback "${row.callback}")`, e);
1745
+ this._emit("schedule:error", {
1746
+ callback: row.callback,
1747
+ id: row.id,
1748
+ error: e instanceof Error ? e.message : String(e),
1749
+ attempts: 0
1750
+ });
1751
+ return;
1752
+ }
1741
1753
  try {
1742
1754
  this._emit("schedule:execute", {
1743
1755
  callback: row.callback,
@@ -2067,9 +2079,6 @@ var Agent = class Agent extends Server {
2067
2079
  * @throws Error if workflow binding not found in environment
2068
2080
  * @throws Error if workflow is already completed/errored/terminated (from Cloudflare)
2069
2081
  *
2070
- * @note `terminate()` is not yet supported in local development (wrangler dev).
2071
- * It will throw an error locally but works when deployed to Cloudflare.
2072
- *
2073
2082
  * @example
2074
2083
  * ```typescript
2075
2084
  * await this.terminateWorkflow(workflowId);
@@ -2081,16 +2090,11 @@ var Agent = class Agent extends Server {
2081
2090
  const workflow = this._findWorkflowBindingByName(workflowInfo.workflowName);
2082
2091
  if (!workflow) throw new Error(`Workflow binding '${workflowInfo.workflowName}' not found in environment`);
2083
2092
  const instance = await workflow.get(workflowId);
2084
- try {
2085
- await tryN(3, async () => instance.terminate(), {
2086
- shouldRetry: isErrorRetryable,
2087
- baseDelayMs: 200,
2088
- maxDelayMs: 3e3
2089
- });
2090
- } catch (err) {
2091
- if (err instanceof Error && err.message.includes("Not implemented")) throw new Error("terminateWorkflow() is not supported in local development. Deploy to Cloudflare to use this feature. Follow https://github.com/cloudflare/agents/issues/823 for details and updates.");
2092
- throw err;
2093
- }
2093
+ await tryN(3, async () => instance.terminate(), {
2094
+ shouldRetry: isErrorRetryable,
2095
+ baseDelayMs: 200,
2096
+ maxDelayMs: 3e3
2097
+ });
2094
2098
  const status = await instance.status();
2095
2099
  this._updateWorkflowTracking(workflowId, status);
2096
2100
  this._emit("workflow:terminated", {
@@ -2107,9 +2111,6 @@ var Agent = class Agent extends Server {
2107
2111
  * @throws Error if workflow binding not found in environment
2108
2112
  * @throws Error if workflow is not running (from Cloudflare)
2109
2113
  *
2110
- * @note `pause()` is not yet supported in local development (wrangler dev).
2111
- * It will throw an error locally but works when deployed to Cloudflare.
2112
- *
2113
2114
  * @example
2114
2115
  * ```typescript
2115
2116
  * await this.pauseWorkflow(workflowId);
@@ -2121,16 +2122,11 @@ var Agent = class Agent extends Server {
2121
2122
  const workflow = this._findWorkflowBindingByName(workflowInfo.workflowName);
2122
2123
  if (!workflow) throw new Error(`Workflow binding '${workflowInfo.workflowName}' not found in environment`);
2123
2124
  const instance = await workflow.get(workflowId);
2124
- try {
2125
- await tryN(3, async () => instance.pause(), {
2126
- shouldRetry: isErrorRetryable,
2127
- baseDelayMs: 200,
2128
- maxDelayMs: 3e3
2129
- });
2130
- } catch (err) {
2131
- if (err instanceof Error && err.message.includes("Not implemented")) throw new Error("pauseWorkflow() is not supported in local development. Deploy to Cloudflare to use this feature. Follow https://github.com/cloudflare/agents/issues/823 for details and updates.");
2132
- throw err;
2133
- }
2125
+ await tryN(3, async () => instance.pause(), {
2126
+ shouldRetry: isErrorRetryable,
2127
+ baseDelayMs: 200,
2128
+ maxDelayMs: 3e3
2129
+ });
2134
2130
  const status = await instance.status();
2135
2131
  this._updateWorkflowTracking(workflowId, status);
2136
2132
  this._emit("workflow:paused", {
@@ -2146,9 +2142,6 @@ var Agent = class Agent extends Server {
2146
2142
  * @throws Error if workflow binding not found in environment
2147
2143
  * @throws Error if workflow is not paused (from Cloudflare)
2148
2144
  *
2149
- * @note `resume()` is not yet supported in local development (wrangler dev).
2150
- * It will throw an error locally but works when deployed to Cloudflare.
2151
- *
2152
2145
  * @example
2153
2146
  * ```typescript
2154
2147
  * await this.resumeWorkflow(workflowId);
@@ -2160,16 +2153,11 @@ var Agent = class Agent extends Server {
2160
2153
  const workflow = this._findWorkflowBindingByName(workflowInfo.workflowName);
2161
2154
  if (!workflow) throw new Error(`Workflow binding '${workflowInfo.workflowName}' not found in environment`);
2162
2155
  const instance = await workflow.get(workflowId);
2163
- try {
2164
- await tryN(3, async () => instance.resume(), {
2165
- shouldRetry: isErrorRetryable,
2166
- baseDelayMs: 200,
2167
- maxDelayMs: 3e3
2168
- });
2169
- } catch (err) {
2170
- if (err instanceof Error && err.message.includes("Not implemented")) throw new Error("resumeWorkflow() is not supported in local development. Deploy to Cloudflare to use this feature. Follow https://github.com/cloudflare/agents/issues/823 for details and updates.");
2171
- throw err;
2172
- }
2156
+ await tryN(3, async () => instance.resume(), {
2157
+ shouldRetry: isErrorRetryable,
2158
+ baseDelayMs: 200,
2159
+ maxDelayMs: 3e3
2160
+ });
2173
2161
  const status = await instance.status();
2174
2162
  this._updateWorkflowTracking(workflowId, status);
2175
2163
  this._emit("workflow:resumed", {
@@ -2188,9 +2176,6 @@ var Agent = class Agent extends Server {
2188
2176
  * @throws Error if workflow not found in tracking table
2189
2177
  * @throws Error if workflow binding not found in environment
2190
2178
  *
2191
- * @note `restart()` is not yet supported in local development (wrangler dev).
2192
- * It will throw an error locally but works when deployed to Cloudflare.
2193
- *
2194
2179
  * @example
2195
2180
  * ```typescript
2196
2181
  * // Reset tracking (default)
@@ -2207,16 +2192,11 @@ var Agent = class Agent extends Server {
2207
2192
  const workflow = this._findWorkflowBindingByName(workflowInfo.workflowName);
2208
2193
  if (!workflow) throw new Error(`Workflow binding '${workflowInfo.workflowName}' not found in environment`);
2209
2194
  const instance = await workflow.get(workflowId);
2210
- try {
2211
- await tryN(3, async () => instance.restart(), {
2212
- shouldRetry: isErrorRetryable,
2213
- baseDelayMs: 200,
2214
- maxDelayMs: 3e3
2215
- });
2216
- } catch (err) {
2217
- if (err instanceof Error && err.message.includes("Not implemented")) throw new Error("restartWorkflow() is not supported in local development. Deploy to Cloudflare to use this feature. Follow https://github.com/cloudflare/agents/issues/823 for details and updates.");
2218
- throw err;
2219
- }
2195
+ await tryN(3, async () => instance.restart(), {
2196
+ shouldRetry: isErrorRetryable,
2197
+ baseDelayMs: 200,
2198
+ maxDelayMs: 3e3
2199
+ });
2220
2200
  if (resetTracking) {
2221
2201
  const now = Math.floor(Date.now() / 1e3);
2222
2202
  this.sql`