agents 0.7.4 → 0.7.6
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/ai-chat-agent.js +3 -4
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration.js +3 -4
- package/dist/ai-chat-v5-migration.js.map +1 -1
- package/dist/ai-react.js +3 -4
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.js +1 -2
- package/dist/ai-types.js.map +1 -1
- package/dist/cli/index.js +2 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/client-K8Z-u76l.js +1468 -0
- package/dist/client-K8Z-u76l.js.map +1 -0
- package/dist/client.js +1 -2
- package/dist/client.js.map +1 -1
- package/dist/codemode/ai.js +2 -2
- package/dist/do-oauth-client-provider-C2jurFjW.d.ts +78 -0
- package/dist/email-U_MG7UET.d.ts +157 -0
- package/dist/email.d.ts +16 -146
- package/dist/email.js +2 -2
- package/dist/email.js.map +1 -1
- package/dist/experimental/forever.d.ts +26 -71
- package/dist/experimental/forever.js +2 -3
- package/dist/experimental/forever.js.map +1 -1
- package/dist/experimental/memory/session/index.js +3 -12
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/experimental/workspace.d.ts +273 -0
- package/dist/experimental/workspace.js +1265 -0
- package/dist/experimental/workspace.js.map +1 -0
- package/dist/index-BS_jL8MI.d.ts +492 -0
- package/dist/index-WBy5hmm3.d.ts +2840 -0
- package/dist/index.d.ts +49 -1320
- package/dist/index.js +281 -138
- package/dist/index.js.map +1 -1
- package/dist/internal_context-DgcmHqS1.d.ts +37 -0
- package/dist/internal_context.d.ts +5 -32
- package/dist/internal_context.js +1 -2
- package/dist/internal_context.js.map +1 -1
- package/dist/mcp/client.d.ts +2 -575
- package/dist/mcp/client.js +1 -847
- package/dist/mcp/do-oauth-client-provider.d.ts +2 -61
- package/dist/mcp/do-oauth-client-provider.js +1 -2
- package/dist/mcp/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -95
- package/dist/mcp/index.js +60 -57
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/x402.js +1 -2
- package/dist/mcp/x402.js.map +1 -1
- package/dist/observability/index.d.ts +2 -93
- package/dist/observability/index.js +4 -3
- package/dist/observability/index.js.map +1 -1
- package/dist/react.d.ts +1 -2
- package/dist/react.js +1 -2
- package/dist/react.js.map +1 -1
- package/dist/retries-DXMQGhG3.d.ts +79 -0
- package/dist/retries.d.ts +7 -72
- package/dist/retries.js +1 -1
- package/dist/retries.js.map +1 -1
- package/dist/schedule.js +1 -2
- package/dist/schedule.js.map +1 -1
- package/dist/serializable.js +1 -1
- package/dist/types-BB1plA51.d.ts +15 -0
- package/dist/types.d.ts +1 -14
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/workflow-types-CZNXKj_D.d.ts +260 -0
- package/dist/workflow-types.d.ts +23 -235
- package/dist/workflow-types.js +1 -1
- package/dist/workflow-types.js.map +1 -1
- package/dist/workflows.d.ts +22 -23
- package/dist/workflows.js +5 -6
- package/dist/workflows.js.map +1 -1
- package/package.json +25 -13
- package/dist/agent-eZnMHidZ.d.ts +0 -273
- package/dist/client-connection-D3Wcd6Q6.js +0 -603
- package/dist/client-connection-D3Wcd6Q6.js.map +0 -1
- package/dist/client-storage-BPjfP_is.d.ts +0 -604
- package/dist/experimental/sub-agent.d.ts +0 -205
- package/dist/experimental/sub-agent.js +0 -191
- package/dist/experimental/sub-agent.js.map +0 -1
- package/dist/mcp/client.js.map +0 -1
package/dist/retries.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retries.js","names":[],"sources":["../src/retries.ts"],"sourcesContent":["/**\n * Retry options for schedule(), scheduleEvery(), queue(), and this.retry().\n */\nexport interface RetryOptions {\n /** Max number of attempts (including the first). Default: 3 */\n maxAttempts?: number;\n /** Base delay in ms for exponential backoff. Default: 100 */\n baseDelayMs?: number;\n /** Max delay cap in ms. Default: 3000 */\n maxDelayMs?: number;\n}\n\n/**\n * Internal options for tryN -- extends RetryOptions with a shouldRetry predicate.\n */\ninterface TryNOptions extends RetryOptions {\n /**\n * Predicate to determine if an error should be retried.\n * Receives the error and the next attempt number (so callers can\n * make attempt-aware decisions).\n * If not provided, all errors are retried.\n */\n shouldRetry?: (err: unknown, nextAttempt: number) => boolean;\n}\n\n/**\n * Validate retry options eagerly so invalid config fails at enqueue/schedule time\n * rather than at execution time. Checks individual field ranges, enforces integer\n * maxAttempts, and validates cross-field constraints after resolving against\n * defaults when provided.\n */\nexport function validateRetryOptions(\n options: RetryOptions,\n defaults?: Required<RetryOptions>\n): void {\n if (options.maxAttempts !== undefined) {\n if (!Number.isFinite(options.maxAttempts) || options.maxAttempts < 1) {\n throw new Error(\"retry.maxAttempts must be >= 1\");\n }\n if (!Number.isInteger(options.maxAttempts)) {\n throw new Error(\"retry.maxAttempts must be an integer\");\n }\n }\n if (options.baseDelayMs !== undefined) {\n if (!Number.isFinite(options.baseDelayMs) || options.baseDelayMs <= 0) {\n throw new Error(\"retry.baseDelayMs must be > 0\");\n }\n }\n if (options.maxDelayMs !== undefined) {\n if (!Number.isFinite(options.maxDelayMs) || options.maxDelayMs <= 0) {\n throw new Error(\"retry.maxDelayMs must be > 0\");\n }\n }\n\n // Resolve against defaults (when provided) so that cross-field checks\n // catch e.g. { baseDelayMs: 5000 } against default maxDelayMs: 3000.\n const resolvedBase = options.baseDelayMs ?? defaults?.baseDelayMs;\n const resolvedMax = options.maxDelayMs ?? defaults?.maxDelayMs;\n if (\n resolvedBase !== undefined &&\n resolvedMax !== undefined &&\n resolvedBase > resolvedMax\n ) {\n throw new Error(\"retry.baseDelayMs must be <= retry.maxDelayMs\");\n }\n}\n\n/**\n * Returns the number of milliseconds to wait before retrying a request.\n * Uses the \"Full Jitter\" approach from\n * https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/\n *\n * @param attempt The current attempt number (1-indexed).\n * @param baseDelayMs Base delay multiplier in ms.\n * @param maxDelayMs Maximum delay cap in ms.\n * @returns Milliseconds to wait before retrying.\n */\nexport function jitterBackoff(\n attempt: number,\n baseDelayMs: number,\n maxDelayMs: number\n): number {\n const upperBoundMs = Math.min(2 ** attempt * baseDelayMs, maxDelayMs);\n return Math.floor(Math.random() * upperBoundMs);\n}\n\n/**\n * Retry an async function up to `n` total attempts with jittered exponential backoff.\n *\n * @param n Total number of attempts (must be a finite integer >= 1).\n * @param fn The async function to retry. Receives the current attempt number (1-indexed).\n * @param options Retry configuration.\n * @returns The result of `fn` on success.\n * @throws The last error if all attempts fail or `shouldRetry` returns false.\n */\nexport async function tryN<T>(\n n: number,\n fn: (attempt: number) => Promise<T>,\n options?: TryNOptions\n): Promise<T> {\n if (!Number.isFinite(n) || n < 1) {\n throw new Error(\"retry.maxAttempts must be >= 1\");\n }\n n = Math.floor(n);\n\n const rawBase = options?.baseDelayMs ?? 100;\n const rawMax = options?.maxDelayMs ?? 3000;\n\n if (!Number.isFinite(rawBase) || rawBase <= 0) {\n throw new Error(\"retry.baseDelayMs must be > 0\");\n }\n if (!Number.isFinite(rawMax) || rawMax <= 0) {\n throw new Error(\"retry.maxDelayMs must be > 0\");\n }\n\n const baseDelayMs = Math.floor(rawBase);\n const maxDelayMs = Math.floor(rawMax);\n\n if (baseDelayMs > maxDelayMs) {\n throw new Error(\"retry.baseDelayMs must be <= retry.maxDelayMs\");\n }\n\n let attempt = 1;\n while (true) {\n try {\n return await fn(attempt);\n } catch (err) {\n const nextAttempt = attempt + 1;\n if (\n nextAttempt > n ||\n (options?.shouldRetry && !options.shouldRetry(err, nextAttempt))\n ) {\n throw err;\n }\n const delay = jitterBackoff(attempt, baseDelayMs, maxDelayMs);\n await new Promise((resolve) => setTimeout(resolve, delay));\n attempt = nextAttempt;\n }\n }\n}\n\n/**\n * Returns true if the given error is retryable according to Durable Object error handling.\n * See https://developers.cloudflare.com/durable-objects/best-practices/error-handling/\n *\n * An error is retryable if it has `retryable: true` but is NOT an overloaded error.\n */\nexport function isErrorRetryable(err: unknown): boolean {\n if (typeof err !== \"object\" || err === null) {\n return false;\n }\n const msg = String(err);\n const typed = err as { retryable?: boolean; overloaded?: boolean };\n return (\n Boolean(typed.retryable) &&\n !typed.overloaded &&\n !msg.includes(\"Durable Object is overloaded\")\n );\n}\n"],"mappings":";;;;;;;AA+BA,SAAgB,qBACd,SACA,UACM;AACN,KAAI,QAAQ,gBAAgB,
|
|
1
|
+
{"version":3,"file":"retries.js","names":[],"sources":["../src/retries.ts"],"sourcesContent":["/**\n * Retry options for schedule(), scheduleEvery(), queue(), and this.retry().\n */\nexport interface RetryOptions {\n /** Max number of attempts (including the first). Default: 3 */\n maxAttempts?: number;\n /** Base delay in ms for exponential backoff. Default: 100 */\n baseDelayMs?: number;\n /** Max delay cap in ms. Default: 3000 */\n maxDelayMs?: number;\n}\n\n/**\n * Internal options for tryN -- extends RetryOptions with a shouldRetry predicate.\n */\ninterface TryNOptions extends RetryOptions {\n /**\n * Predicate to determine if an error should be retried.\n * Receives the error and the next attempt number (so callers can\n * make attempt-aware decisions).\n * If not provided, all errors are retried.\n */\n shouldRetry?: (err: unknown, nextAttempt: number) => boolean;\n}\n\n/**\n * Validate retry options eagerly so invalid config fails at enqueue/schedule time\n * rather than at execution time. Checks individual field ranges, enforces integer\n * maxAttempts, and validates cross-field constraints after resolving against\n * defaults when provided.\n */\nexport function validateRetryOptions(\n options: RetryOptions,\n defaults?: Required<RetryOptions>\n): void {\n if (options.maxAttempts !== undefined) {\n if (!Number.isFinite(options.maxAttempts) || options.maxAttempts < 1) {\n throw new Error(\"retry.maxAttempts must be >= 1\");\n }\n if (!Number.isInteger(options.maxAttempts)) {\n throw new Error(\"retry.maxAttempts must be an integer\");\n }\n }\n if (options.baseDelayMs !== undefined) {\n if (!Number.isFinite(options.baseDelayMs) || options.baseDelayMs <= 0) {\n throw new Error(\"retry.baseDelayMs must be > 0\");\n }\n }\n if (options.maxDelayMs !== undefined) {\n if (!Number.isFinite(options.maxDelayMs) || options.maxDelayMs <= 0) {\n throw new Error(\"retry.maxDelayMs must be > 0\");\n }\n }\n\n // Resolve against defaults (when provided) so that cross-field checks\n // catch e.g. { baseDelayMs: 5000 } against default maxDelayMs: 3000.\n const resolvedBase = options.baseDelayMs ?? defaults?.baseDelayMs;\n const resolvedMax = options.maxDelayMs ?? defaults?.maxDelayMs;\n if (\n resolvedBase !== undefined &&\n resolvedMax !== undefined &&\n resolvedBase > resolvedMax\n ) {\n throw new Error(\"retry.baseDelayMs must be <= retry.maxDelayMs\");\n }\n}\n\n/**\n * Returns the number of milliseconds to wait before retrying a request.\n * Uses the \"Full Jitter\" approach from\n * https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/\n *\n * @param attempt The current attempt number (1-indexed).\n * @param baseDelayMs Base delay multiplier in ms.\n * @param maxDelayMs Maximum delay cap in ms.\n * @returns Milliseconds to wait before retrying.\n */\nexport function jitterBackoff(\n attempt: number,\n baseDelayMs: number,\n maxDelayMs: number\n): number {\n const upperBoundMs = Math.min(2 ** attempt * baseDelayMs, maxDelayMs);\n return Math.floor(Math.random() * upperBoundMs);\n}\n\n/**\n * Retry an async function up to `n` total attempts with jittered exponential backoff.\n *\n * @param n Total number of attempts (must be a finite integer >= 1).\n * @param fn The async function to retry. Receives the current attempt number (1-indexed).\n * @param options Retry configuration.\n * @returns The result of `fn` on success.\n * @throws The last error if all attempts fail or `shouldRetry` returns false.\n */\nexport async function tryN<T>(\n n: number,\n fn: (attempt: number) => Promise<T>,\n options?: TryNOptions\n): Promise<T> {\n if (!Number.isFinite(n) || n < 1) {\n throw new Error(\"retry.maxAttempts must be >= 1\");\n }\n n = Math.floor(n);\n\n const rawBase = options?.baseDelayMs ?? 100;\n const rawMax = options?.maxDelayMs ?? 3000;\n\n if (!Number.isFinite(rawBase) || rawBase <= 0) {\n throw new Error(\"retry.baseDelayMs must be > 0\");\n }\n if (!Number.isFinite(rawMax) || rawMax <= 0) {\n throw new Error(\"retry.maxDelayMs must be > 0\");\n }\n\n const baseDelayMs = Math.floor(rawBase);\n const maxDelayMs = Math.floor(rawMax);\n\n if (baseDelayMs > maxDelayMs) {\n throw new Error(\"retry.baseDelayMs must be <= retry.maxDelayMs\");\n }\n\n let attempt = 1;\n while (true) {\n try {\n return await fn(attempt);\n } catch (err) {\n const nextAttempt = attempt + 1;\n if (\n nextAttempt > n ||\n (options?.shouldRetry && !options.shouldRetry(err, nextAttempt))\n ) {\n throw err;\n }\n const delay = jitterBackoff(attempt, baseDelayMs, maxDelayMs);\n await new Promise((resolve) => setTimeout(resolve, delay));\n attempt = nextAttempt;\n }\n }\n}\n\n/**\n * Returns true if the given error is retryable according to Durable Object error handling.\n * See https://developers.cloudflare.com/durable-objects/best-practices/error-handling/\n *\n * An error is retryable if it has `retryable: true` but is NOT an overloaded error.\n */\nexport function isErrorRetryable(err: unknown): boolean {\n if (typeof err !== \"object\" || err === null) {\n return false;\n }\n const msg = String(err);\n const typed = err as { retryable?: boolean; overloaded?: boolean };\n return (\n Boolean(typed.retryable) &&\n !typed.overloaded &&\n !msg.includes(\"Durable Object is overloaded\")\n );\n}\n"],"mappings":";;;;;;;AA+BA,SAAgB,qBACd,SACA,UACM;AACN,KAAI,QAAQ,gBAAgB,KAAA,GAAW;AACrC,MAAI,CAAC,OAAO,SAAS,QAAQ,YAAY,IAAI,QAAQ,cAAc,EACjE,OAAM,IAAI,MAAM,iCAAiC;AAEnD,MAAI,CAAC,OAAO,UAAU,QAAQ,YAAY,CACxC,OAAM,IAAI,MAAM,uCAAuC;;AAG3D,KAAI,QAAQ,gBAAgB,KAAA;MACtB,CAAC,OAAO,SAAS,QAAQ,YAAY,IAAI,QAAQ,eAAe,EAClE,OAAM,IAAI,MAAM,gCAAgC;;AAGpD,KAAI,QAAQ,eAAe,KAAA;MACrB,CAAC,OAAO,SAAS,QAAQ,WAAW,IAAI,QAAQ,cAAc,EAChE,OAAM,IAAI,MAAM,+BAA+B;;CAMnD,MAAM,eAAe,QAAQ,eAAe,UAAU;CACtD,MAAM,cAAc,QAAQ,cAAc,UAAU;AACpD,KACE,iBAAiB,KAAA,KACjB,gBAAgB,KAAA,KAChB,eAAe,YAEf,OAAM,IAAI,MAAM,gDAAgD;;;;;;;;;;;;AAcpE,SAAgB,cACd,SACA,aACA,YACQ;CACR,MAAM,eAAe,KAAK,IAAI,KAAK,UAAU,aAAa,WAAW;AACrE,QAAO,KAAK,MAAM,KAAK,QAAQ,GAAG,aAAa;;;;;;;;;;;AAYjD,eAAsB,KACpB,GACA,IACA,SACY;AACZ,KAAI,CAAC,OAAO,SAAS,EAAE,IAAI,IAAI,EAC7B,OAAM,IAAI,MAAM,iCAAiC;AAEnD,KAAI,KAAK,MAAM,EAAE;CAEjB,MAAM,UAAU,SAAS,eAAe;CACxC,MAAM,SAAS,SAAS,cAAc;AAEtC,KAAI,CAAC,OAAO,SAAS,QAAQ,IAAI,WAAW,EAC1C,OAAM,IAAI,MAAM,gCAAgC;AAElD,KAAI,CAAC,OAAO,SAAS,OAAO,IAAI,UAAU,EACxC,OAAM,IAAI,MAAM,+BAA+B;CAGjD,MAAM,cAAc,KAAK,MAAM,QAAQ;CACvC,MAAM,aAAa,KAAK,MAAM,OAAO;AAErC,KAAI,cAAc,WAChB,OAAM,IAAI,MAAM,gDAAgD;CAGlE,IAAI,UAAU;AACd,QAAO,KACL,KAAI;AACF,SAAO,MAAM,GAAG,QAAQ;UACjB,KAAK;EACZ,MAAM,cAAc,UAAU;AAC9B,MACE,cAAc,KACb,SAAS,eAAe,CAAC,QAAQ,YAAY,KAAK,YAAY,CAE/D,OAAM;EAER,MAAM,QAAQ,cAAc,SAAS,aAAa,WAAW;AAC7D,QAAM,IAAI,SAAS,YAAY,WAAW,SAAS,MAAM,CAAC;AAC1D,YAAU;;;;;;;;;AAWhB,SAAgB,iBAAiB,KAAuB;AACtD,KAAI,OAAO,QAAQ,YAAY,QAAQ,KACrC,QAAO;CAET,MAAM,MAAM,OAAO,IAAI;CACvB,MAAM,QAAQ;AACd,QACE,QAAQ,MAAM,UAAU,IACxB,CAAC,MAAM,cACP,CAAC,IAAI,SAAS,+BAA+B"}
|
package/dist/schedule.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
2
|
//#region src/schedule.ts
|
|
4
3
|
/**
|
|
5
4
|
* Get the schedule prompt for a given event
|
|
@@ -116,7 +115,7 @@ const scheduleSchema = z.object({
|
|
|
116
115
|
* @returns The schedule schema
|
|
117
116
|
*/
|
|
118
117
|
const unstable_scheduleSchema = scheduleSchema;
|
|
119
|
-
|
|
120
118
|
//#endregion
|
|
121
119
|
export { getSchedulePrompt, scheduleSchema, unstable_getSchedulePrompt, unstable_scheduleSchema };
|
|
120
|
+
|
|
122
121
|
//# sourceMappingURL=schedule.js.map
|
package/dist/schedule.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.js","names":[],"sources":["../src/schedule.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/**\n * Get the schedule prompt for a given event\n * @param event - The event to get the schedule prompt for\n * @returns The schedule prompt\n */\nexport function getSchedulePrompt(event: { date: Date }) {\n return `\n[Schedule Parser Component]\n\nCurrent time: ${event.date.toUTCString()}\n\nThis component parses natural language scheduling requests into a structured format. It extracts:\n1. A clean task description (without timing information)\n2. Scheduling details in one of these formats:\n - scheduled: Specific date/time events\n - delayed: Relative time delays (in seconds)\n - cron: Recurring patterns\n - no-schedule: Tasks without timing\n\nRules:\n- Task descriptions should be clean and focused on the action\n- Use numbers (0-6) for days in cron patterns (0=Sunday)\n- For recurring tasks, use standard cron syntax\n- For relative times, convert to seconds\n- For specific dates, use the current time as reference\n\nExample outputs:\n{\n \"description\": \"meeting with team\",\n \"when\": {\n \"type\": \"scheduled\",\n \"date\": \"tomorrow at 14:00\"\n }\n}\n\n{\n \"description\": \"backup database\",\n \"when\": {\n \"type\": \"cron\",\n \"cron\": \"0 0 * * *\"\n }\n}\n\n{\n \"description\": \"send report\",\n \"when\": {\n \"type\": \"delayed\",\n \"delayInSeconds\": 1800\n }\n}\n\n[End Schedule Parser Component]\n`;\n}\n\nlet didWarnAboutUnstableGetSchedulePrompt = false;\n\n/**\n * @deprecated this has been renamed to getSchedulePrompt, and unstable_getSchedulePrompt will be removed in the next major version\n * @param event - The event to get the schedule prompt for\n * @returns The schedule prompt\n */\nexport function unstable_getSchedulePrompt(event: { date: Date }) {\n if (!didWarnAboutUnstableGetSchedulePrompt) {\n didWarnAboutUnstableGetSchedulePrompt = true;\n console.warn(\n \"unstable_getSchedulePrompt is deprecated, use getSchedulePrompt instead. unstable_getSchedulePrompt will be removed in the next major version.\"\n );\n }\n return getSchedulePrompt(event);\n}\n\n/**\n * The schema for parsing natural language scheduling requests.\n *\n * @example\n * ```typescript\n * import { generateObject } from \"ai\";\n * import { scheduleSchema, getSchedulePrompt } from \"agents/schedule\";\n *\n * const result = await generateObject({\n * model,\n * prompt: `${getSchedulePrompt({ date: new Date() })} Input: \"${userInput}\"`,\n * schema: scheduleSchema,\n * // Required for OpenAI to avoid strict JSON schema validation errors\n * providerOptions: {\n * openai: { strictJsonSchema: false }\n * }\n * });\n * ```\n *\n * @remarks\n * When using this schema with OpenAI models via the AI SDK, you must pass\n * `providerOptions: { openai: { strictJsonSchema: false } }` to `generateObject`.\n * This is because the schema uses a discriminated union which is not compatible\n * with OpenAI's strict structured outputs mode.\n */\nexport const scheduleSchema = z.object({\n description: z.string().describe(\"A description of the task\"),\n when: z.discriminatedUnion(\"type\", [\n z.object({\n type: z.literal(\"scheduled\"),\n date: z\n .string()\n .describe(\n \"Execute task at the specified date and time in ISO 8601 format\"\n )\n }),\n z.object({\n type: z.literal(\"delayed\"),\n delayInSeconds: z\n .number()\n .describe(\"Execute task after a delay in seconds\")\n }),\n z.object({\n type: z.literal(\"cron\"),\n cron: z\n .string()\n .describe(\n \"Execute task on a recurring interval specified as cron syntax\"\n )\n }),\n z.object({\n type: z.literal(\"no-schedule\")\n })\n ])\n});\n\n/**\n * The type for the schedule prompt\n */\nexport type Schedule = z.infer<typeof scheduleSchema>;\n\n/**\n * @deprecated this has been renamed to scheduleSchema, and unstable_scheduleSchema will be removed in the next major version\n * @returns The schedule schema\n */\nexport const unstable_scheduleSchema = scheduleSchema;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"schedule.js","names":[],"sources":["../src/schedule.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/**\n * Get the schedule prompt for a given event\n * @param event - The event to get the schedule prompt for\n * @returns The schedule prompt\n */\nexport function getSchedulePrompt(event: { date: Date }) {\n return `\n[Schedule Parser Component]\n\nCurrent time: ${event.date.toUTCString()}\n\nThis component parses natural language scheduling requests into a structured format. It extracts:\n1. A clean task description (without timing information)\n2. Scheduling details in one of these formats:\n - scheduled: Specific date/time events\n - delayed: Relative time delays (in seconds)\n - cron: Recurring patterns\n - no-schedule: Tasks without timing\n\nRules:\n- Task descriptions should be clean and focused on the action\n- Use numbers (0-6) for days in cron patterns (0=Sunday)\n- For recurring tasks, use standard cron syntax\n- For relative times, convert to seconds\n- For specific dates, use the current time as reference\n\nExample outputs:\n{\n \"description\": \"meeting with team\",\n \"when\": {\n \"type\": \"scheduled\",\n \"date\": \"tomorrow at 14:00\"\n }\n}\n\n{\n \"description\": \"backup database\",\n \"when\": {\n \"type\": \"cron\",\n \"cron\": \"0 0 * * *\"\n }\n}\n\n{\n \"description\": \"send report\",\n \"when\": {\n \"type\": \"delayed\",\n \"delayInSeconds\": 1800\n }\n}\n\n[End Schedule Parser Component]\n`;\n}\n\nlet didWarnAboutUnstableGetSchedulePrompt = false;\n\n/**\n * @deprecated this has been renamed to getSchedulePrompt, and unstable_getSchedulePrompt will be removed in the next major version\n * @param event - The event to get the schedule prompt for\n * @returns The schedule prompt\n */\nexport function unstable_getSchedulePrompt(event: { date: Date }) {\n if (!didWarnAboutUnstableGetSchedulePrompt) {\n didWarnAboutUnstableGetSchedulePrompt = true;\n console.warn(\n \"unstable_getSchedulePrompt is deprecated, use getSchedulePrompt instead. unstable_getSchedulePrompt will be removed in the next major version.\"\n );\n }\n return getSchedulePrompt(event);\n}\n\n/**\n * The schema for parsing natural language scheduling requests.\n *\n * @example\n * ```typescript\n * import { generateObject } from \"ai\";\n * import { scheduleSchema, getSchedulePrompt } from \"agents/schedule\";\n *\n * const result = await generateObject({\n * model,\n * prompt: `${getSchedulePrompt({ date: new Date() })} Input: \"${userInput}\"`,\n * schema: scheduleSchema,\n * // Required for OpenAI to avoid strict JSON schema validation errors\n * providerOptions: {\n * openai: { strictJsonSchema: false }\n * }\n * });\n * ```\n *\n * @remarks\n * When using this schema with OpenAI models via the AI SDK, you must pass\n * `providerOptions: { openai: { strictJsonSchema: false } }` to `generateObject`.\n * This is because the schema uses a discriminated union which is not compatible\n * with OpenAI's strict structured outputs mode.\n */\nexport const scheduleSchema = z.object({\n description: z.string().describe(\"A description of the task\"),\n when: z.discriminatedUnion(\"type\", [\n z.object({\n type: z.literal(\"scheduled\"),\n date: z\n .string()\n .describe(\n \"Execute task at the specified date and time in ISO 8601 format\"\n )\n }),\n z.object({\n type: z.literal(\"delayed\"),\n delayInSeconds: z\n .number()\n .describe(\"Execute task after a delay in seconds\")\n }),\n z.object({\n type: z.literal(\"cron\"),\n cron: z\n .string()\n .describe(\n \"Execute task on a recurring interval specified as cron syntax\"\n )\n }),\n z.object({\n type: z.literal(\"no-schedule\")\n })\n ])\n});\n\n/**\n * The type for the schedule prompt\n */\nexport type Schedule = z.infer<typeof scheduleSchema>;\n\n/**\n * @deprecated this has been renamed to scheduleSchema, and unstable_scheduleSchema will be removed in the next major version\n * @returns The schedule schema\n */\nexport const unstable_scheduleSchema = scheduleSchema;\n"],"mappings":";;;;;;;AAOA,SAAgB,kBAAkB,OAAuB;AACvD,QAAO;;;gBAGO,MAAM,KAAK,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CzC,IAAI,wCAAwC;;;;;;AAO5C,SAAgB,2BAA2B,OAAuB;AAChE,KAAI,CAAC,uCAAuC;AAC1C,0CAAwC;AACxC,UAAQ,KACN,iJACD;;AAEH,QAAO,kBAAkB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BjC,MAAa,iBAAiB,EAAE,OAAO;CACrC,aAAa,EAAE,QAAQ,CAAC,SAAS,4BAA4B;CAC7D,MAAM,EAAE,mBAAmB,QAAQ;EACjC,EAAE,OAAO;GACP,MAAM,EAAE,QAAQ,YAAY;GAC5B,MAAM,EACH,QAAQ,CACR,SACC,iEACD;GACJ,CAAC;EACF,EAAE,OAAO;GACP,MAAM,EAAE,QAAQ,UAAU;GAC1B,gBAAgB,EACb,QAAQ,CACR,SAAS,wCAAwC;GACrD,CAAC;EACF,EAAE,OAAO;GACP,MAAM,EAAE,QAAQ,OAAO;GACvB,MAAM,EACH,QAAQ,CACR,SACC,gEACD;GACJ,CAAC;EACF,EAAE,OAAO,EACP,MAAM,EAAE,QAAQ,cAAc,EAC/B,CAAC;EACH,CAAC;CACH,CAAC;;;;;AAWF,MAAa,0BAA0B"}
|
package/dist/serializable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Enum for message types to improve type safety and maintainability
|
|
4
|
+
*/
|
|
5
|
+
declare enum MessageType {
|
|
6
|
+
CF_AGENT_MCP_SERVERS = "cf_agent_mcp_servers",
|
|
7
|
+
CF_MCP_AGENT_EVENT = "cf_mcp_agent_event",
|
|
8
|
+
CF_AGENT_STATE = "cf_agent_state",
|
|
9
|
+
CF_AGENT_STATE_ERROR = "cf_agent_state_error",
|
|
10
|
+
CF_AGENT_IDENTITY = "cf_agent_identity",
|
|
11
|
+
RPC = "rpc"
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { MessageType as t };
|
|
15
|
+
//# sourceMappingURL=types-BB1plA51.d.ts.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Enum for message types to improve type safety and maintainability
|
|
4
|
-
*/
|
|
5
|
-
declare enum MessageType {
|
|
6
|
-
CF_AGENT_MCP_SERVERS = "cf_agent_mcp_servers",
|
|
7
|
-
CF_MCP_AGENT_EVENT = "cf_mcp_agent_event",
|
|
8
|
-
CF_AGENT_STATE = "cf_agent_state",
|
|
9
|
-
CF_AGENT_STATE_ERROR = "cf_agent_state_error",
|
|
10
|
-
CF_AGENT_IDENTITY = "cf_agent_identity",
|
|
11
|
-
RPC = "rpc"
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
1
|
+
import { t as MessageType } from "./types-BB1plA51.js";
|
|
14
2
|
export { MessageType };
|
|
15
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
CHANGED
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Enum for message types to improve type safety and maintainability\n */\nexport enum MessageType {\n CF_AGENT_MCP_SERVERS = \"cf_agent_mcp_servers\",\n CF_MCP_AGENT_EVENT = \"cf_mcp_agent_event\",\n CF_AGENT_STATE = \"cf_agent_state\",\n CF_AGENT_STATE_ERROR = \"cf_agent_state_error\",\n CF_AGENT_IDENTITY = \"cf_agent_identity\",\n RPC = \"rpc\"\n}\n"],"mappings":";;;;AAGA,IAAY,
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Enum for message types to improve type safety and maintainability\n */\nexport enum MessageType {\n CF_AGENT_MCP_SERVERS = \"cf_agent_mcp_servers\",\n CF_MCP_AGENT_EVENT = \"cf_mcp_agent_event\",\n CF_AGENT_STATE = \"cf_agent_state\",\n CF_AGENT_STATE_ERROR = \"cf_agent_state_error\",\n CF_AGENT_IDENTITY = \"cf_agent_identity\",\n RPC = \"rpc\"\n}\n"],"mappings":";;;;AAGA,IAAY,cAAL,yBAAA,aAAA;AACL,aAAA,0BAAA;AACA,aAAA,wBAAA;AACA,aAAA,oBAAA;AACA,aAAA,0BAAA;AACA,aAAA,uBAAA;AACA,aAAA,SAAA;;KACD"}
|
package/dist/utils.js
CHANGED
|
@@ -10,7 +10,7 @@ function camelCaseToKebabCase(str) {
|
|
|
10
10
|
kebabified = kebabified.startsWith("-") ? kebabified.slice(1) : kebabified;
|
|
11
11
|
return kebabified.replace(/_/g, "-").replace(/-$/, "");
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
//#endregion
|
|
15
14
|
export { camelCaseToKebabCase };
|
|
15
|
+
|
|
16
16
|
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WorkflowEvent,
|
|
3
|
+
WorkflowSleepDuration,
|
|
4
|
+
WorkflowStep
|
|
5
|
+
} from "cloudflare:workers";
|
|
6
|
+
|
|
7
|
+
//#region src/workflow-types.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Type alias for WorkflowEvent in AgentWorkflow context.
|
|
10
|
+
* Identical to WorkflowEvent - provided for naming consistency with AgentWorkflowStep.
|
|
11
|
+
*/
|
|
12
|
+
type AgentWorkflowEvent<Params = unknown> = WorkflowEvent<Params>;
|
|
13
|
+
/**
|
|
14
|
+
* Extended WorkflowStep with durable Agent communication methods.
|
|
15
|
+
* All added methods on this interface are durable - they're idempotent and won't
|
|
16
|
+
* repeat on workflow retry.
|
|
17
|
+
*/
|
|
18
|
+
interface AgentWorkflowStep extends WorkflowStep {
|
|
19
|
+
/**
|
|
20
|
+
* Report successful completion to the Agent (durable).
|
|
21
|
+
* Triggers onWorkflowComplete() on the Agent.
|
|
22
|
+
* @param result - Optional result data
|
|
23
|
+
*/
|
|
24
|
+
reportComplete<T = unknown>(result?: T): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Report an error to the Agent (durable).
|
|
27
|
+
* Triggers onWorkflowError() on the Agent.
|
|
28
|
+
* @param error - Error or error message
|
|
29
|
+
*/
|
|
30
|
+
reportError(error: Error | string): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Send a custom event to the Agent (durable).
|
|
33
|
+
* Triggers onWorkflowEvent() on the Agent.
|
|
34
|
+
* @param event - Custom event payload
|
|
35
|
+
*/
|
|
36
|
+
sendEvent<T = unknown>(event: T): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Update the Agent's state entirely (durable).
|
|
39
|
+
* This will replace the Agent's state and broadcast to all connected clients.
|
|
40
|
+
* @param state - New state to set
|
|
41
|
+
*/
|
|
42
|
+
updateAgentState(state: unknown): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Merge partial state into the Agent's existing state (durable).
|
|
45
|
+
* Performs a shallow merge and broadcasts to all connected clients.
|
|
46
|
+
* @param partialState - Partial state to merge
|
|
47
|
+
*/
|
|
48
|
+
mergeAgentState(partialState: Record<string, unknown>): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Reset the Agent's state to its initialState (durable).
|
|
51
|
+
* Broadcasts the reset state to all connected clients.
|
|
52
|
+
*/
|
|
53
|
+
resetAgentState(): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Internal parameters injected by runWorkflow() to identify the originating Agent
|
|
57
|
+
*/
|
|
58
|
+
type AgentWorkflowInternalParams = {
|
|
59
|
+
/** Name/ID of the Agent that started this workflow */ __agentName: string /** Environment binding name for the Agent's namespace */;
|
|
60
|
+
__agentBinding: string /** Workflow binding name (for callbacks) */;
|
|
61
|
+
__workflowName: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Combined workflow params: user params + internal agent params
|
|
65
|
+
*/
|
|
66
|
+
type AgentWorkflowParams<T = unknown> = T & AgentWorkflowInternalParams;
|
|
67
|
+
/**
|
|
68
|
+
* Workflow callback types for Agent-Workflow communication
|
|
69
|
+
*/
|
|
70
|
+
type WorkflowCallbackType = "progress" | "complete" | "error" | "event";
|
|
71
|
+
/**
|
|
72
|
+
* Base callback structure sent from Workflow to Agent
|
|
73
|
+
*/
|
|
74
|
+
type WorkflowCallbackBase = {
|
|
75
|
+
/** Workflow binding name */ workflowName: string /** ID of the workflow instance */;
|
|
76
|
+
workflowId: string /** Type of callback */;
|
|
77
|
+
type: WorkflowCallbackType /** Timestamp when callback was sent */;
|
|
78
|
+
timestamp: number;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Default progress type - covers common use cases.
|
|
82
|
+
* Developers can define their own progress type for domain-specific needs.
|
|
83
|
+
*/
|
|
84
|
+
type DefaultProgress = {
|
|
85
|
+
/** Current step name */ step?: string /** Step/overall status */;
|
|
86
|
+
status?:
|
|
87
|
+
| "pending"
|
|
88
|
+
| "running"
|
|
89
|
+
| "complete"
|
|
90
|
+
| "error" /** Human-readable message */;
|
|
91
|
+
message?: string /** Progress percentage (0-1) */;
|
|
92
|
+
percent?: number /** Allow additional custom fields */;
|
|
93
|
+
[key: string]: unknown;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Progress callback - reports workflow progress with typed payload
|
|
97
|
+
*/
|
|
98
|
+
type WorkflowProgressCallback<P = DefaultProgress> = WorkflowCallbackBase & {
|
|
99
|
+
type: "progress" /** Typed progress data */;
|
|
100
|
+
progress: P;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Complete callback - workflow finished successfully
|
|
104
|
+
*/
|
|
105
|
+
type WorkflowCompleteCallback = WorkflowCallbackBase & {
|
|
106
|
+
type: "complete" /** Result of the workflow */;
|
|
107
|
+
result?: unknown;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Error callback - workflow encountered an error
|
|
111
|
+
*/
|
|
112
|
+
type WorkflowErrorCallback = WorkflowCallbackBase & {
|
|
113
|
+
type: "error" /** Error message */;
|
|
114
|
+
error: string;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Event callback - custom event from workflow
|
|
118
|
+
*/
|
|
119
|
+
type WorkflowEventCallback = WorkflowCallbackBase & {
|
|
120
|
+
type: "event" /** Custom event payload */;
|
|
121
|
+
event: unknown;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Union of all callback types
|
|
125
|
+
*/
|
|
126
|
+
type WorkflowCallback<P = DefaultProgress> =
|
|
127
|
+
| WorkflowProgressCallback<P>
|
|
128
|
+
| WorkflowCompleteCallback
|
|
129
|
+
| WorkflowErrorCallback
|
|
130
|
+
| WorkflowEventCallback;
|
|
131
|
+
/**
|
|
132
|
+
* Workflow status values - derived from Cloudflare's InstanceStatus
|
|
133
|
+
*/
|
|
134
|
+
type WorkflowStatus = InstanceStatus["status"];
|
|
135
|
+
/**
|
|
136
|
+
* Row structure for cf_agents_workflows tracking table
|
|
137
|
+
*/
|
|
138
|
+
type WorkflowTrackingRow = {
|
|
139
|
+
/** Internal row ID (UUID) */ id: string /** Cloudflare Workflow instance ID */;
|
|
140
|
+
workflow_id: string /** Workflow binding name */;
|
|
141
|
+
workflow_name: string /** Current workflow status */;
|
|
142
|
+
status: WorkflowStatus /** JSON-serialized metadata for querying */;
|
|
143
|
+
metadata: string | null /** Error name if workflow failed */;
|
|
144
|
+
error_name: string | null /** Error message if workflow failed */;
|
|
145
|
+
error_message: string | null /** Unix timestamp when workflow was created */;
|
|
146
|
+
created_at: number /** Unix timestamp when workflow was last updated */;
|
|
147
|
+
updated_at: number /** Unix timestamp when workflow completed (null if not complete) */;
|
|
148
|
+
completed_at: number | null;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Options for runWorkflow()
|
|
152
|
+
*/
|
|
153
|
+
type RunWorkflowOptions = {
|
|
154
|
+
/** Custom workflow instance ID (auto-generated if not provided) */ id?: string /** Optional metadata for querying (stored as JSON) */;
|
|
155
|
+
metadata?: Record<
|
|
156
|
+
string,
|
|
157
|
+
unknown
|
|
158
|
+
> /** Agent binding name (auto-detected from class name if not provided) */;
|
|
159
|
+
agentBinding?: string;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Event payload for sendWorkflowEvent()
|
|
163
|
+
*/
|
|
164
|
+
type WorkflowEventPayload = {
|
|
165
|
+
/** Event type name */ type: string /** Event payload data */;
|
|
166
|
+
payload: unknown;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Parsed workflow tracking info returned by getWorkflow()
|
|
170
|
+
*/
|
|
171
|
+
type WorkflowInfo = {
|
|
172
|
+
/** Internal row ID */ id: string /** Cloudflare Workflow instance ID */;
|
|
173
|
+
workflowId: string /** Workflow binding name */;
|
|
174
|
+
workflowName: string /** Current workflow status */;
|
|
175
|
+
status: WorkflowStatus /** Metadata (parsed from JSON) */;
|
|
176
|
+
metadata: Record<string, unknown> | null /** Error info if workflow failed */;
|
|
177
|
+
error: {
|
|
178
|
+
name: string;
|
|
179
|
+
message: string;
|
|
180
|
+
} | null /** When workflow was created */;
|
|
181
|
+
createdAt: Date /** When workflow was last updated */;
|
|
182
|
+
updatedAt: Date /** When workflow completed (null if not complete) */;
|
|
183
|
+
completedAt: Date | null;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Criteria for querying tracked workflows
|
|
187
|
+
*/
|
|
188
|
+
type WorkflowQueryCriteria = {
|
|
189
|
+
/** Filter by status */ status?:
|
|
190
|
+
| WorkflowStatus
|
|
191
|
+
| WorkflowStatus[] /** Filter by workflow binding name */;
|
|
192
|
+
workflowName?: string /** Filter by metadata key-value pairs (exact match) */;
|
|
193
|
+
metadata?: Record<
|
|
194
|
+
string,
|
|
195
|
+
string | number | boolean
|
|
196
|
+
> /** Limit number of results (default 50, max 100) */;
|
|
197
|
+
limit?: number /** Order by created_at */;
|
|
198
|
+
orderBy?:
|
|
199
|
+
| "asc"
|
|
200
|
+
| "desc" /** Cursor for pagination (from previous WorkflowPage.nextCursor) */;
|
|
201
|
+
cursor?: string;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Paginated result from getWorkflows()
|
|
205
|
+
*/
|
|
206
|
+
type WorkflowPage = {
|
|
207
|
+
/** Workflows for this page */ workflows: WorkflowInfo[] /** Total count of workflows matching the criteria (ignoring pagination) */;
|
|
208
|
+
total: number /** Cursor for next page, or null if no more pages */;
|
|
209
|
+
nextCursor: string | null;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Standard approval event payload used by approveWorkflow/rejectWorkflow
|
|
213
|
+
*/
|
|
214
|
+
type ApprovalEventPayload = {
|
|
215
|
+
/** Whether the workflow was approved */ approved: boolean /** Optional reason for approval/rejection */;
|
|
216
|
+
reason?: string /** Optional additional metadata */;
|
|
217
|
+
metadata?: Record<string, unknown>;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Options for waitForApproval()
|
|
221
|
+
*/
|
|
222
|
+
type WaitForApprovalOptions = {
|
|
223
|
+
/** Step name for waitForEvent (default: "wait-for-approval") */ stepName?: string /** Timeout duration (e.g., "7 days") */;
|
|
224
|
+
timeout?: WorkflowSleepDuration /** Event type to wait for (default: "approval") */;
|
|
225
|
+
eventType?: string;
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Error thrown when a workflow is rejected via rejectWorkflow()
|
|
229
|
+
*/
|
|
230
|
+
declare class WorkflowRejectedError extends Error {
|
|
231
|
+
readonly reason?: string | undefined;
|
|
232
|
+
readonly workflowId?: string | undefined;
|
|
233
|
+
constructor(reason?: string | undefined, workflowId?: string | undefined);
|
|
234
|
+
}
|
|
235
|
+
//#endregion
|
|
236
|
+
export {
|
|
237
|
+
WorkflowTrackingRow as S,
|
|
238
|
+
WorkflowPage as _,
|
|
239
|
+
ApprovalEventPayload as a,
|
|
240
|
+
WorkflowRejectedError as b,
|
|
241
|
+
WaitForApprovalOptions as c,
|
|
242
|
+
WorkflowCallbackType as d,
|
|
243
|
+
WorkflowCompleteCallback as f,
|
|
244
|
+
WorkflowInfo as g,
|
|
245
|
+
WorkflowEventPayload as h,
|
|
246
|
+
AgentWorkflowStep as i,
|
|
247
|
+
WorkflowCallback as l,
|
|
248
|
+
WorkflowEventCallback as m,
|
|
249
|
+
AgentWorkflowInternalParams as n,
|
|
250
|
+
DefaultProgress as o,
|
|
251
|
+
WorkflowErrorCallback as p,
|
|
252
|
+
AgentWorkflowParams as r,
|
|
253
|
+
RunWorkflowOptions as s,
|
|
254
|
+
AgentWorkflowEvent as t,
|
|
255
|
+
WorkflowCallbackBase as u,
|
|
256
|
+
WorkflowProgressCallback as v,
|
|
257
|
+
WorkflowStatus as x,
|
|
258
|
+
WorkflowQueryCriteria as y
|
|
259
|
+
};
|
|
260
|
+
//# sourceMappingURL=workflow-types-CZNXKj_D.d.ts.map
|
package/dist/workflow-types.d.ts
CHANGED
|
@@ -1,238 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Report an error to the Agent (durable).
|
|
27
|
-
* Triggers onWorkflowError() on the Agent.
|
|
28
|
-
* @param error - Error or error message
|
|
29
|
-
*/
|
|
30
|
-
reportError(error: Error | string): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* Send a custom event to the Agent (durable).
|
|
33
|
-
* Triggers onWorkflowEvent() on the Agent.
|
|
34
|
-
* @param event - Custom event payload
|
|
35
|
-
*/
|
|
36
|
-
sendEvent<T = unknown>(event: T): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Update the Agent's state entirely (durable).
|
|
39
|
-
* This will replace the Agent's state and broadcast to all connected clients.
|
|
40
|
-
* @param state - New state to set
|
|
41
|
-
*/
|
|
42
|
-
updateAgentState(state: unknown): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Merge partial state into the Agent's existing state (durable).
|
|
45
|
-
* Performs a shallow merge and broadcasts to all connected clients.
|
|
46
|
-
* @param partialState - Partial state to merge
|
|
47
|
-
*/
|
|
48
|
-
mergeAgentState(partialState: Record<string, unknown>): Promise<void>;
|
|
49
|
-
/**
|
|
50
|
-
* Reset the Agent's state to its initialState (durable).
|
|
51
|
-
* Broadcasts the reset state to all connected clients.
|
|
52
|
-
*/
|
|
53
|
-
resetAgentState(): Promise<void>;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Internal parameters injected by runWorkflow() to identify the originating Agent
|
|
57
|
-
*/
|
|
58
|
-
type AgentWorkflowInternalParams = {
|
|
59
|
-
/** Name/ID of the Agent that started this workflow */ __agentName: string /** Environment binding name for the Agent's namespace */;
|
|
60
|
-
__agentBinding: string /** Workflow binding name (for callbacks) */;
|
|
61
|
-
__workflowName: string;
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Combined workflow params: user params + internal agent params
|
|
65
|
-
*/
|
|
66
|
-
type AgentWorkflowParams<T = unknown> = T & AgentWorkflowInternalParams;
|
|
67
|
-
/**
|
|
68
|
-
* Workflow callback types for Agent-Workflow communication
|
|
69
|
-
*/
|
|
70
|
-
type WorkflowCallbackType = "progress" | "complete" | "error" | "event";
|
|
71
|
-
/**
|
|
72
|
-
* Base callback structure sent from Workflow to Agent
|
|
73
|
-
*/
|
|
74
|
-
type WorkflowCallbackBase = {
|
|
75
|
-
/** Workflow binding name */ workflowName: string /** ID of the workflow instance */;
|
|
76
|
-
workflowId: string /** Type of callback */;
|
|
77
|
-
type: WorkflowCallbackType /** Timestamp when callback was sent */;
|
|
78
|
-
timestamp: number;
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Default progress type - covers common use cases.
|
|
82
|
-
* Developers can define their own progress type for domain-specific needs.
|
|
83
|
-
*/
|
|
84
|
-
type DefaultProgress = {
|
|
85
|
-
/** Current step name */ step?: string /** Step/overall status */;
|
|
86
|
-
status?:
|
|
87
|
-
| "pending"
|
|
88
|
-
| "running"
|
|
89
|
-
| "complete"
|
|
90
|
-
| "error" /** Human-readable message */;
|
|
91
|
-
message?: string /** Progress percentage (0-1) */;
|
|
92
|
-
percent?: number /** Allow additional custom fields */;
|
|
93
|
-
[key: string]: unknown;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Progress callback - reports workflow progress with typed payload
|
|
97
|
-
*/
|
|
98
|
-
type WorkflowProgressCallback<P = DefaultProgress> = WorkflowCallbackBase & {
|
|
99
|
-
type: "progress" /** Typed progress data */;
|
|
100
|
-
progress: P;
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Complete callback - workflow finished successfully
|
|
104
|
-
*/
|
|
105
|
-
type WorkflowCompleteCallback = WorkflowCallbackBase & {
|
|
106
|
-
type: "complete" /** Result of the workflow */;
|
|
107
|
-
result?: unknown;
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Error callback - workflow encountered an error
|
|
111
|
-
*/
|
|
112
|
-
type WorkflowErrorCallback = WorkflowCallbackBase & {
|
|
113
|
-
type: "error" /** Error message */;
|
|
114
|
-
error: string;
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* Event callback - custom event from workflow
|
|
118
|
-
*/
|
|
119
|
-
type WorkflowEventCallback = WorkflowCallbackBase & {
|
|
120
|
-
type: "event" /** Custom event payload */;
|
|
121
|
-
event: unknown;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Union of all callback types
|
|
125
|
-
*/
|
|
126
|
-
type WorkflowCallback<P = DefaultProgress> =
|
|
127
|
-
| WorkflowProgressCallback<P>
|
|
128
|
-
| WorkflowCompleteCallback
|
|
129
|
-
| WorkflowErrorCallback
|
|
130
|
-
| WorkflowEventCallback;
|
|
131
|
-
/**
|
|
132
|
-
* Workflow status values - derived from Cloudflare's InstanceStatus
|
|
133
|
-
*/
|
|
134
|
-
type WorkflowStatus = InstanceStatus["status"];
|
|
135
|
-
/**
|
|
136
|
-
* Row structure for cf_agents_workflows tracking table
|
|
137
|
-
*/
|
|
138
|
-
type WorkflowTrackingRow = {
|
|
139
|
-
/** Internal row ID (UUID) */ id: string /** Cloudflare Workflow instance ID */;
|
|
140
|
-
workflow_id: string /** Workflow binding name */;
|
|
141
|
-
workflow_name: string /** Current workflow status */;
|
|
142
|
-
status: WorkflowStatus /** JSON-serialized metadata for querying */;
|
|
143
|
-
metadata: string | null /** Error name if workflow failed */;
|
|
144
|
-
error_name: string | null /** Error message if workflow failed */;
|
|
145
|
-
error_message: string | null /** Unix timestamp when workflow was created */;
|
|
146
|
-
created_at: number /** Unix timestamp when workflow was last updated */;
|
|
147
|
-
updated_at: number /** Unix timestamp when workflow completed (null if not complete) */;
|
|
148
|
-
completed_at: number | null;
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* Options for runWorkflow()
|
|
152
|
-
*/
|
|
153
|
-
type RunWorkflowOptions = {
|
|
154
|
-
/** Custom workflow instance ID (auto-generated if not provided) */ id?: string /** Optional metadata for querying (stored as JSON) */;
|
|
155
|
-
metadata?: Record<
|
|
156
|
-
string,
|
|
157
|
-
unknown
|
|
158
|
-
> /** Agent binding name (auto-detected from class name if not provided) */;
|
|
159
|
-
agentBinding?: string;
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Event payload for sendWorkflowEvent()
|
|
163
|
-
*/
|
|
164
|
-
type WorkflowEventPayload = {
|
|
165
|
-
/** Event type name */ type: string /** Event payload data */;
|
|
166
|
-
payload: unknown;
|
|
167
|
-
};
|
|
168
|
-
/**
|
|
169
|
-
* Parsed workflow tracking info returned by getWorkflow()
|
|
170
|
-
*/
|
|
171
|
-
type WorkflowInfo = {
|
|
172
|
-
/** Internal row ID */ id: string /** Cloudflare Workflow instance ID */;
|
|
173
|
-
workflowId: string /** Workflow binding name */;
|
|
174
|
-
workflowName: string /** Current workflow status */;
|
|
175
|
-
status: WorkflowStatus /** Metadata (parsed from JSON) */;
|
|
176
|
-
metadata: Record<string, unknown> | null /** Error info if workflow failed */;
|
|
177
|
-
error: {
|
|
178
|
-
name: string;
|
|
179
|
-
message: string;
|
|
180
|
-
} | null /** When workflow was created */;
|
|
181
|
-
createdAt: Date /** When workflow was last updated */;
|
|
182
|
-
updatedAt: Date /** When workflow completed (null if not complete) */;
|
|
183
|
-
completedAt: Date | null;
|
|
184
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* Criteria for querying tracked workflows
|
|
187
|
-
*/
|
|
188
|
-
type WorkflowQueryCriteria = {
|
|
189
|
-
/** Filter by status */ status?:
|
|
190
|
-
| WorkflowStatus
|
|
191
|
-
| WorkflowStatus[] /** Filter by workflow binding name */;
|
|
192
|
-
workflowName?: string /** Filter by metadata key-value pairs (exact match) */;
|
|
193
|
-
metadata?: Record<
|
|
194
|
-
string,
|
|
195
|
-
string | number | boolean
|
|
196
|
-
> /** Limit number of results (default 50, max 100) */;
|
|
197
|
-
limit?: number /** Order by created_at */;
|
|
198
|
-
orderBy?:
|
|
199
|
-
| "asc"
|
|
200
|
-
| "desc" /** Cursor for pagination (from previous WorkflowPage.nextCursor) */;
|
|
201
|
-
cursor?: string;
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* Paginated result from getWorkflows()
|
|
205
|
-
*/
|
|
206
|
-
type WorkflowPage = {
|
|
207
|
-
/** Workflows for this page */ workflows: WorkflowInfo[] /** Total count of workflows matching the criteria (ignoring pagination) */;
|
|
208
|
-
total: number /** Cursor for next page, or null if no more pages */;
|
|
209
|
-
nextCursor: string | null;
|
|
210
|
-
};
|
|
211
|
-
/**
|
|
212
|
-
* Standard approval event payload used by approveWorkflow/rejectWorkflow
|
|
213
|
-
*/
|
|
214
|
-
type ApprovalEventPayload = {
|
|
215
|
-
/** Whether the workflow was approved */ approved: boolean /** Optional reason for approval/rejection */;
|
|
216
|
-
reason?: string /** Optional additional metadata */;
|
|
217
|
-
metadata?: Record<string, unknown>;
|
|
218
|
-
};
|
|
219
|
-
/**
|
|
220
|
-
* Options for waitForApproval()
|
|
221
|
-
*/
|
|
222
|
-
type WaitForApprovalOptions = {
|
|
223
|
-
/** Step name for waitForEvent (default: "wait-for-approval") */ stepName?: string /** Timeout duration (e.g., "7 days") */;
|
|
224
|
-
timeout?: WorkflowSleepDuration /** Event type to wait for (default: "approval") */;
|
|
225
|
-
eventType?: string;
|
|
226
|
-
};
|
|
227
|
-
/**
|
|
228
|
-
* Error thrown when a workflow is rejected via rejectWorkflow()
|
|
229
|
-
*/
|
|
230
|
-
declare class WorkflowRejectedError extends Error {
|
|
231
|
-
readonly reason?: string | undefined;
|
|
232
|
-
readonly workflowId?: string | undefined;
|
|
233
|
-
constructor(reason?: string | undefined, workflowId?: string | undefined);
|
|
234
|
-
}
|
|
235
|
-
//#endregion
|
|
2
|
+
S as WorkflowTrackingRow,
|
|
3
|
+
_ as WorkflowPage,
|
|
4
|
+
a as ApprovalEventPayload,
|
|
5
|
+
b as WorkflowRejectedError,
|
|
6
|
+
c as WaitForApprovalOptions,
|
|
7
|
+
d as WorkflowCallbackType,
|
|
8
|
+
f as WorkflowCompleteCallback,
|
|
9
|
+
g as WorkflowInfo,
|
|
10
|
+
h as WorkflowEventPayload,
|
|
11
|
+
i as AgentWorkflowStep,
|
|
12
|
+
l as WorkflowCallback,
|
|
13
|
+
m as WorkflowEventCallback,
|
|
14
|
+
n as AgentWorkflowInternalParams,
|
|
15
|
+
o as DefaultProgress,
|
|
16
|
+
p as WorkflowErrorCallback,
|
|
17
|
+
r as AgentWorkflowParams,
|
|
18
|
+
s as RunWorkflowOptions,
|
|
19
|
+
t as AgentWorkflowEvent,
|
|
20
|
+
u as WorkflowCallbackBase,
|
|
21
|
+
v as WorkflowProgressCallback,
|
|
22
|
+
x as WorkflowStatus,
|
|
23
|
+
y as WorkflowQueryCriteria
|
|
24
|
+
} from "./workflow-types-CZNXKj_D.js";
|
|
236
25
|
export {
|
|
237
26
|
AgentWorkflowEvent,
|
|
238
27
|
AgentWorkflowInternalParams,
|
|
@@ -257,4 +46,3 @@ export {
|
|
|
257
46
|
WorkflowStatus,
|
|
258
47
|
WorkflowTrackingRow
|
|
259
48
|
};
|
|
260
|
-
//# sourceMappingURL=workflow-types.d.ts.map
|