agents 0.7.3 → 0.7.5
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-CgXIwdcc.js +1442 -0
- package/dist/client-CgXIwdcc.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 +1 -2
- 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/sub-agent.js +1 -2
- package/dist/experimental/sub-agent.js.map +1 -1
- package/dist/experimental/workspace.d.ts +273 -0
- package/dist/experimental/workspace.js +1263 -0
- package/dist/experimental/workspace.js.map +1 -0
- package/dist/index-BS_jL8MI.d.ts +492 -0
- package/dist/index-p1XLNvwQ.d.ts +2719 -0
- package/dist/index.d.ts +45 -1320
- package/dist/index.js +40 -6
- 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 +2 -9
- 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 +15 -5
- 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-yDVwzgfF.d.ts +0 -604
- package/dist/mcp/client.js.map +0 -1
package/dist/workflow-types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-types.js","names":[],"sources":["../src/workflow-types.ts"],"sourcesContent":["/**\n * Workflow integration types for Agents\n *\n * These types provide seamless integration between Cloudflare Agents\n * and Cloudflare Workflows for durable, multi-step background processing.\n *\n * Note: This file is kept separate from workflows.ts to avoid circular dependencies.\n * Both index.ts (Agent class) and workflows.ts (AgentWorkflow class) import from here.\n */\n\nimport type {\n WorkflowEvent,\n WorkflowStep,\n WorkflowSleepDuration\n} from \"cloudflare:workers\";\n\n/**\n * Type alias for WorkflowEvent in AgentWorkflow context.\n * Identical to WorkflowEvent - provided for naming consistency with AgentWorkflowStep.\n */\nexport type AgentWorkflowEvent<Params = unknown> = WorkflowEvent<Params>;\n\n/**\n * Extended WorkflowStep with durable Agent communication methods.\n * All added methods on this interface are durable - they're idempotent and won't\n * repeat on workflow retry.\n */\nexport interface AgentWorkflowStep extends WorkflowStep {\n /**\n * Report successful completion to the Agent (durable).\n * Triggers onWorkflowComplete() on the Agent.\n * @param result - Optional result data\n */\n reportComplete<T = unknown>(result?: T): Promise<void>;\n\n /**\n * Report an error to the Agent (durable).\n * Triggers onWorkflowError() on the Agent.\n * @param error - Error or error message\n */\n reportError(error: Error | string): Promise<void>;\n\n /**\n * Send a custom event to the Agent (durable).\n * Triggers onWorkflowEvent() on the Agent.\n * @param event - Custom event payload\n */\n sendEvent<T = unknown>(event: T): Promise<void>;\n\n /**\n * Update the Agent's state entirely (durable).\n * This will replace the Agent's state and broadcast to all connected clients.\n * @param state - New state to set\n */\n updateAgentState(state: unknown): Promise<void>;\n\n /**\n * Merge partial state into the Agent's existing state (durable).\n * Performs a shallow merge and broadcasts to all connected clients.\n * @param partialState - Partial state to merge\n */\n mergeAgentState(partialState: Record<string, unknown>): Promise<void>;\n\n /**\n * Reset the Agent's state to its initialState (durable).\n * Broadcasts the reset state to all connected clients.\n */\n resetAgentState(): Promise<void>;\n}\n\n/**\n * Internal parameters injected by runWorkflow() to identify the originating Agent\n */\nexport type AgentWorkflowInternalParams = {\n /** Name/ID of the Agent that started this workflow */\n __agentName: string;\n /** Environment binding name for the Agent's namespace */\n __agentBinding: string;\n /** Workflow binding name (for callbacks) */\n __workflowName: string;\n};\n\n/**\n * Combined workflow params: user params + internal agent params\n */\nexport type AgentWorkflowParams<T = unknown> = T & AgentWorkflowInternalParams;\n\n/**\n * Workflow callback types for Agent-Workflow communication\n */\nexport type WorkflowCallbackType = \"progress\" | \"complete\" | \"error\" | \"event\";\n\n/**\n * Base callback structure sent from Workflow to Agent\n */\nexport type WorkflowCallbackBase = {\n /** Workflow binding name */\n workflowName: string;\n /** ID of the workflow instance */\n workflowId: string;\n /** Type of callback */\n type: WorkflowCallbackType;\n /** Timestamp when callback was sent */\n timestamp: number;\n};\n\n/**\n * Default progress type - covers common use cases.\n * Developers can define their own progress type for domain-specific needs.\n */\nexport type DefaultProgress = {\n /** Current step name */\n step?: string;\n /** Step/overall status */\n status?: \"pending\" | \"running\" | \"complete\" | \"error\";\n /** Human-readable message */\n message?: string;\n /** Progress percentage (0-1) */\n percent?: number;\n /** Allow additional custom fields */\n [key: string]: unknown;\n};\n\n/**\n * Progress callback - reports workflow progress with typed payload\n */\nexport type WorkflowProgressCallback<P = DefaultProgress> =\n WorkflowCallbackBase & {\n type: \"progress\";\n /** Typed progress data */\n progress: P;\n };\n\n/**\n * Complete callback - workflow finished successfully\n */\nexport type WorkflowCompleteCallback = WorkflowCallbackBase & {\n type: \"complete\";\n /** Result of the workflow */\n result?: unknown;\n};\n\n/**\n * Error callback - workflow encountered an error\n */\nexport type WorkflowErrorCallback = WorkflowCallbackBase & {\n type: \"error\";\n /** Error message */\n error: string;\n};\n\n/**\n * Event callback - custom event from workflow\n */\nexport type WorkflowEventCallback = WorkflowCallbackBase & {\n type: \"event\";\n /** Custom event payload */\n event: unknown;\n};\n\n/**\n * Union of all callback types\n */\nexport type WorkflowCallback<P = DefaultProgress> =\n | WorkflowProgressCallback<P>\n | WorkflowCompleteCallback\n | WorkflowErrorCallback\n | WorkflowEventCallback;\n\n/**\n * Workflow status values - derived from Cloudflare's InstanceStatus\n */\nexport type WorkflowStatus = InstanceStatus[\"status\"];\n\n/**\n * Row structure for cf_agents_workflows tracking table\n */\nexport type WorkflowTrackingRow = {\n /** Internal row ID (UUID) */\n id: string;\n /** Cloudflare Workflow instance ID */\n workflow_id: string;\n /** Workflow binding name */\n workflow_name: string;\n /** Current workflow status */\n status: WorkflowStatus;\n /** JSON-serialized metadata for querying */\n metadata: string | null;\n /** Error name if workflow failed */\n error_name: string | null;\n /** Error message if workflow failed */\n error_message: string | null;\n /** Unix timestamp when workflow was created */\n created_at: number;\n /** Unix timestamp when workflow was last updated */\n updated_at: number;\n /** Unix timestamp when workflow completed (null if not complete) */\n completed_at: number | null;\n};\n\n/**\n * Options for runWorkflow()\n */\nexport type RunWorkflowOptions = {\n /** Custom workflow instance ID (auto-generated if not provided) */\n id?: string;\n /** Optional metadata for querying (stored as JSON) */\n metadata?: Record<string, unknown>;\n /** Agent binding name (auto-detected from class name if not provided) */\n agentBinding?: string;\n};\n\n/**\n * Event payload for sendWorkflowEvent()\n */\nexport type WorkflowEventPayload = {\n /** Event type name */\n type: string;\n /** Event payload data */\n payload: unknown;\n};\n\n/**\n * Parsed workflow tracking info returned by getWorkflow()\n */\nexport type WorkflowInfo = {\n /** Internal row ID */\n id: string;\n /** Cloudflare Workflow instance ID */\n workflowId: string;\n /** Workflow binding name */\n workflowName: string;\n /** Current workflow status */\n status: WorkflowStatus;\n /** Metadata (parsed from JSON) */\n metadata: Record<string, unknown> | null;\n /** Error info if workflow failed */\n error: { name: string; message: string } | null;\n /** When workflow was created */\n createdAt: Date;\n /** When workflow was last updated */\n updatedAt: Date;\n /** When workflow completed (null if not complete) */\n completedAt: Date | null;\n};\n\n/**\n * Criteria for querying tracked workflows\n */\nexport type WorkflowQueryCriteria = {\n /** Filter by status */\n status?: WorkflowStatus | WorkflowStatus[];\n /** Filter by workflow binding name */\n workflowName?: string;\n /** Filter by metadata key-value pairs (exact match) */\n metadata?: Record<string, string | number | boolean>;\n /** Limit number of results (default 50, max 100) */\n limit?: number;\n /** Order by created_at */\n orderBy?: \"asc\" | \"desc\";\n /** Cursor for pagination (from previous WorkflowPage.nextCursor) */\n cursor?: string;\n};\n\n/**\n * Paginated result from getWorkflows()\n */\nexport type WorkflowPage = {\n /** Workflows for this page */\n workflows: WorkflowInfo[];\n /** Total count of workflows matching the criteria (ignoring pagination) */\n total: number;\n /** Cursor for next page, or null if no more pages */\n nextCursor: string | null;\n};\n\n/**\n * Standard approval event payload used by approveWorkflow/rejectWorkflow\n */\nexport type ApprovalEventPayload = {\n /** Whether the workflow was approved */\n approved: boolean;\n /** Optional reason for approval/rejection */\n reason?: string;\n /** Optional additional metadata */\n metadata?: Record<string, unknown>;\n};\n\n/**\n * Options for waitForApproval()\n */\nexport type WaitForApprovalOptions = {\n /** Step name for waitForEvent (default: \"wait-for-approval\") */\n stepName?: string;\n /** Timeout duration (e.g., \"7 days\") */\n timeout?: WorkflowSleepDuration;\n /** Event type to wait for (default: \"approval\") */\n eventType?: string;\n};\n\n/**\n * Error thrown when a workflow is rejected via rejectWorkflow()\n */\nexport class WorkflowRejectedError extends Error {\n constructor(\n public readonly reason?: string,\n public readonly workflowId?: string\n ) {\n super(reason ? `Workflow rejected: ${reason}` : \"Workflow rejected\");\n this.name = \"WorkflowRejectedError\";\n }\n}\n"],"mappings":";;;;AA+SA,IAAa,wBAAb,cAA2C,MAAM;CAC/C,YACE,
|
|
1
|
+
{"version":3,"file":"workflow-types.js","names":[],"sources":["../src/workflow-types.ts"],"sourcesContent":["/**\n * Workflow integration types for Agents\n *\n * These types provide seamless integration between Cloudflare Agents\n * and Cloudflare Workflows for durable, multi-step background processing.\n *\n * Note: This file is kept separate from workflows.ts to avoid circular dependencies.\n * Both index.ts (Agent class) and workflows.ts (AgentWorkflow class) import from here.\n */\n\nimport type {\n WorkflowEvent,\n WorkflowStep,\n WorkflowSleepDuration\n} from \"cloudflare:workers\";\n\n/**\n * Type alias for WorkflowEvent in AgentWorkflow context.\n * Identical to WorkflowEvent - provided for naming consistency with AgentWorkflowStep.\n */\nexport type AgentWorkflowEvent<Params = unknown> = WorkflowEvent<Params>;\n\n/**\n * Extended WorkflowStep with durable Agent communication methods.\n * All added methods on this interface are durable - they're idempotent and won't\n * repeat on workflow retry.\n */\nexport interface AgentWorkflowStep extends WorkflowStep {\n /**\n * Report successful completion to the Agent (durable).\n * Triggers onWorkflowComplete() on the Agent.\n * @param result - Optional result data\n */\n reportComplete<T = unknown>(result?: T): Promise<void>;\n\n /**\n * Report an error to the Agent (durable).\n * Triggers onWorkflowError() on the Agent.\n * @param error - Error or error message\n */\n reportError(error: Error | string): Promise<void>;\n\n /**\n * Send a custom event to the Agent (durable).\n * Triggers onWorkflowEvent() on the Agent.\n * @param event - Custom event payload\n */\n sendEvent<T = unknown>(event: T): Promise<void>;\n\n /**\n * Update the Agent's state entirely (durable).\n * This will replace the Agent's state and broadcast to all connected clients.\n * @param state - New state to set\n */\n updateAgentState(state: unknown): Promise<void>;\n\n /**\n * Merge partial state into the Agent's existing state (durable).\n * Performs a shallow merge and broadcasts to all connected clients.\n * @param partialState - Partial state to merge\n */\n mergeAgentState(partialState: Record<string, unknown>): Promise<void>;\n\n /**\n * Reset the Agent's state to its initialState (durable).\n * Broadcasts the reset state to all connected clients.\n */\n resetAgentState(): Promise<void>;\n}\n\n/**\n * Internal parameters injected by runWorkflow() to identify the originating Agent\n */\nexport type AgentWorkflowInternalParams = {\n /** Name/ID of the Agent that started this workflow */\n __agentName: string;\n /** Environment binding name for the Agent's namespace */\n __agentBinding: string;\n /** Workflow binding name (for callbacks) */\n __workflowName: string;\n};\n\n/**\n * Combined workflow params: user params + internal agent params\n */\nexport type AgentWorkflowParams<T = unknown> = T & AgentWorkflowInternalParams;\n\n/**\n * Workflow callback types for Agent-Workflow communication\n */\nexport type WorkflowCallbackType = \"progress\" | \"complete\" | \"error\" | \"event\";\n\n/**\n * Base callback structure sent from Workflow to Agent\n */\nexport type WorkflowCallbackBase = {\n /** Workflow binding name */\n workflowName: string;\n /** ID of the workflow instance */\n workflowId: string;\n /** Type of callback */\n type: WorkflowCallbackType;\n /** Timestamp when callback was sent */\n timestamp: number;\n};\n\n/**\n * Default progress type - covers common use cases.\n * Developers can define their own progress type for domain-specific needs.\n */\nexport type DefaultProgress = {\n /** Current step name */\n step?: string;\n /** Step/overall status */\n status?: \"pending\" | \"running\" | \"complete\" | \"error\";\n /** Human-readable message */\n message?: string;\n /** Progress percentage (0-1) */\n percent?: number;\n /** Allow additional custom fields */\n [key: string]: unknown;\n};\n\n/**\n * Progress callback - reports workflow progress with typed payload\n */\nexport type WorkflowProgressCallback<P = DefaultProgress> =\n WorkflowCallbackBase & {\n type: \"progress\";\n /** Typed progress data */\n progress: P;\n };\n\n/**\n * Complete callback - workflow finished successfully\n */\nexport type WorkflowCompleteCallback = WorkflowCallbackBase & {\n type: \"complete\";\n /** Result of the workflow */\n result?: unknown;\n};\n\n/**\n * Error callback - workflow encountered an error\n */\nexport type WorkflowErrorCallback = WorkflowCallbackBase & {\n type: \"error\";\n /** Error message */\n error: string;\n};\n\n/**\n * Event callback - custom event from workflow\n */\nexport type WorkflowEventCallback = WorkflowCallbackBase & {\n type: \"event\";\n /** Custom event payload */\n event: unknown;\n};\n\n/**\n * Union of all callback types\n */\nexport type WorkflowCallback<P = DefaultProgress> =\n | WorkflowProgressCallback<P>\n | WorkflowCompleteCallback\n | WorkflowErrorCallback\n | WorkflowEventCallback;\n\n/**\n * Workflow status values - derived from Cloudflare's InstanceStatus\n */\nexport type WorkflowStatus = InstanceStatus[\"status\"];\n\n/**\n * Row structure for cf_agents_workflows tracking table\n */\nexport type WorkflowTrackingRow = {\n /** Internal row ID (UUID) */\n id: string;\n /** Cloudflare Workflow instance ID */\n workflow_id: string;\n /** Workflow binding name */\n workflow_name: string;\n /** Current workflow status */\n status: WorkflowStatus;\n /** JSON-serialized metadata for querying */\n metadata: string | null;\n /** Error name if workflow failed */\n error_name: string | null;\n /** Error message if workflow failed */\n error_message: string | null;\n /** Unix timestamp when workflow was created */\n created_at: number;\n /** Unix timestamp when workflow was last updated */\n updated_at: number;\n /** Unix timestamp when workflow completed (null if not complete) */\n completed_at: number | null;\n};\n\n/**\n * Options for runWorkflow()\n */\nexport type RunWorkflowOptions = {\n /** Custom workflow instance ID (auto-generated if not provided) */\n id?: string;\n /** Optional metadata for querying (stored as JSON) */\n metadata?: Record<string, unknown>;\n /** Agent binding name (auto-detected from class name if not provided) */\n agentBinding?: string;\n};\n\n/**\n * Event payload for sendWorkflowEvent()\n */\nexport type WorkflowEventPayload = {\n /** Event type name */\n type: string;\n /** Event payload data */\n payload: unknown;\n};\n\n/**\n * Parsed workflow tracking info returned by getWorkflow()\n */\nexport type WorkflowInfo = {\n /** Internal row ID */\n id: string;\n /** Cloudflare Workflow instance ID */\n workflowId: string;\n /** Workflow binding name */\n workflowName: string;\n /** Current workflow status */\n status: WorkflowStatus;\n /** Metadata (parsed from JSON) */\n metadata: Record<string, unknown> | null;\n /** Error info if workflow failed */\n error: { name: string; message: string } | null;\n /** When workflow was created */\n createdAt: Date;\n /** When workflow was last updated */\n updatedAt: Date;\n /** When workflow completed (null if not complete) */\n completedAt: Date | null;\n};\n\n/**\n * Criteria for querying tracked workflows\n */\nexport type WorkflowQueryCriteria = {\n /** Filter by status */\n status?: WorkflowStatus | WorkflowStatus[];\n /** Filter by workflow binding name */\n workflowName?: string;\n /** Filter by metadata key-value pairs (exact match) */\n metadata?: Record<string, string | number | boolean>;\n /** Limit number of results (default 50, max 100) */\n limit?: number;\n /** Order by created_at */\n orderBy?: \"asc\" | \"desc\";\n /** Cursor for pagination (from previous WorkflowPage.nextCursor) */\n cursor?: string;\n};\n\n/**\n * Paginated result from getWorkflows()\n */\nexport type WorkflowPage = {\n /** Workflows for this page */\n workflows: WorkflowInfo[];\n /** Total count of workflows matching the criteria (ignoring pagination) */\n total: number;\n /** Cursor for next page, or null if no more pages */\n nextCursor: string | null;\n};\n\n/**\n * Standard approval event payload used by approveWorkflow/rejectWorkflow\n */\nexport type ApprovalEventPayload = {\n /** Whether the workflow was approved */\n approved: boolean;\n /** Optional reason for approval/rejection */\n reason?: string;\n /** Optional additional metadata */\n metadata?: Record<string, unknown>;\n};\n\n/**\n * Options for waitForApproval()\n */\nexport type WaitForApprovalOptions = {\n /** Step name for waitForEvent (default: \"wait-for-approval\") */\n stepName?: string;\n /** Timeout duration (e.g., \"7 days\") */\n timeout?: WorkflowSleepDuration;\n /** Event type to wait for (default: \"approval\") */\n eventType?: string;\n};\n\n/**\n * Error thrown when a workflow is rejected via rejectWorkflow()\n */\nexport class WorkflowRejectedError extends Error {\n constructor(\n public readonly reason?: string,\n public readonly workflowId?: string\n ) {\n super(reason ? `Workflow rejected: ${reason}` : \"Workflow rejected\");\n this.name = \"WorkflowRejectedError\";\n }\n}\n"],"mappings":";;;;AA+SA,IAAa,wBAAb,cAA2C,MAAM;CAC/C,YACE,QACA,YACA;AACA,QAAM,SAAS,sBAAsB,WAAW,oBAAoB;AAHpD,OAAA,SAAA;AACA,OAAA,aAAA;AAGhB,OAAK,OAAO"}
|
package/dist/workflows.d.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import "./
|
|
1
|
+
import { r as Agent } from "./index-p1XLNvwQ.js";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
WorkflowEventCallback,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
WorkflowStatus,
|
|
22
|
-
|
|
23
|
-
} from "./workflow-types.js";
|
|
24
|
-
import { Agent } from "./index.js";
|
|
3
|
+
S as WorkflowTrackingRow,
|
|
4
|
+
_ as WorkflowPage,
|
|
5
|
+
a as ApprovalEventPayload,
|
|
6
|
+
b as WorkflowRejectedError,
|
|
7
|
+
c as WaitForApprovalOptions,
|
|
8
|
+
d as WorkflowCallbackType,
|
|
9
|
+
f as WorkflowCompleteCallback,
|
|
10
|
+
g as WorkflowInfo,
|
|
11
|
+
h as WorkflowEventPayload,
|
|
12
|
+
i as AgentWorkflowStep,
|
|
13
|
+
l as WorkflowCallback,
|
|
14
|
+
m as WorkflowEventCallback,
|
|
15
|
+
o as DefaultProgress,
|
|
16
|
+
p as WorkflowErrorCallback,
|
|
17
|
+
r as AgentWorkflowParams,
|
|
18
|
+
s as RunWorkflowOptions,
|
|
19
|
+
t as AgentWorkflowEvent,
|
|
20
|
+
v as WorkflowProgressCallback,
|
|
21
|
+
x as WorkflowStatus,
|
|
22
|
+
y as WorkflowQueryCriteria
|
|
23
|
+
} from "./workflow-types-CZNXKj_D.js";
|
|
25
24
|
import { WorkflowEntrypoint } from "cloudflare:workers";
|
|
26
25
|
|
|
27
26
|
//#region src/workflows.d.ts
|
package/dist/workflows.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import "./client-
|
|
1
|
+
import "./client-CgXIwdcc.js";
|
|
2
2
|
import { getAgentByName } from "./index.js";
|
|
3
3
|
import { WorkflowRejectedError } from "./workflow-types.js";
|
|
4
4
|
import { WorkflowEntrypoint } from "cloudflare:workers";
|
|
5
|
-
|
|
6
5
|
//#region src/workflows.ts
|
|
7
6
|
/**
|
|
8
7
|
* AgentWorkflow - Base class for Workflows that integrate with Agents
|
|
@@ -145,17 +144,17 @@ var AgentWorkflow = class extends WorkflowEntrypoint {
|
|
|
145
144
|
};
|
|
146
145
|
wrappedStep.updateAgentState = async (state) => {
|
|
147
146
|
await step.do(`__agent_updateState_${stepCounter++}`, async () => {
|
|
148
|
-
this.agent._workflow_updateState("set", state);
|
|
147
|
+
await this.agent._workflow_updateState("set", state);
|
|
149
148
|
});
|
|
150
149
|
};
|
|
151
150
|
wrappedStep.mergeAgentState = async (partialState) => {
|
|
152
151
|
await step.do(`__agent_mergeState_${stepCounter++}`, async () => {
|
|
153
|
-
this.agent._workflow_updateState("merge", partialState);
|
|
152
|
+
await this.agent._workflow_updateState("merge", partialState);
|
|
154
153
|
});
|
|
155
154
|
};
|
|
156
155
|
wrappedStep.resetAgentState = async () => {
|
|
157
156
|
await step.do(`__agent_resetState_${stepCounter++}`, async () => {
|
|
158
|
-
this.agent._workflow_updateState("reset");
|
|
157
|
+
await this.agent._workflow_updateState("reset");
|
|
159
158
|
});
|
|
160
159
|
};
|
|
161
160
|
return wrappedStep;
|
|
@@ -280,7 +279,7 @@ var AgentWorkflow = class extends WorkflowEntrypoint {
|
|
|
280
279
|
return payload.metadata;
|
|
281
280
|
}
|
|
282
281
|
};
|
|
283
|
-
|
|
284
282
|
//#endregion
|
|
285
283
|
export { AgentWorkflow, WorkflowRejectedError };
|
|
284
|
+
|
|
286
285
|
//# sourceMappingURL=workflows.js.map
|
package/dist/workflows.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflows.js","names":[],"sources":["../src/workflows.ts"],"sourcesContent":["/**\n * AgentWorkflow - Base class for Workflows that integrate with Agents\n *\n * Extends Cloudflare's WorkflowEntrypoint to provide seamless access to\n * the Agent that started the workflow, enabling bidirectional communication.\n *\n * @example\n * ```typescript\n * import { AgentWorkflow } from 'agents/workflows';\n * import type { MyAgent } from './agent';\n *\n * type TaskParams = { taskId: string; data: string };\n *\n * export class ProcessingWorkflow extends AgentWorkflow<MyAgent, TaskParams> {\n * async run(event: AgentWorkflowEvent<TaskParams>, step: WorkflowStep) {\n * // Access the originating Agent via typed RPC\n * await this.agent.updateTaskStatus(event.payload.taskId, 'processing');\n *\n * const result = await step.do('process', async () => {\n * // ... processing logic\n * return { processed: true };\n * });\n *\n * // Report progress to Agent (typed)\n * await this.reportProgress({ step: 'process', status: 'complete', percent: 0.5 });\n *\n * // Broadcast to connected clients\n * await this.broadcastToClients({ type: 'progress', data: result });\n *\n * return result;\n * }\n * }\n * ```\n */\n\nimport { WorkflowEntrypoint } from \"cloudflare:workers\";\nimport type { WorkflowEvent, WorkflowStep } from \"cloudflare:workers\";\nimport { getAgentByName, type Agent } from \"./index\";\nimport type {\n AgentWorkflowParams,\n AgentWorkflowStep,\n WorkflowCallback,\n DefaultProgress,\n WaitForApprovalOptions\n} from \"./workflow-types\";\nimport { WorkflowRejectedError } from \"./workflow-types\";\n\n/**\n * WeakSet to track which prototypes have been wrapped.\n * This prevents re-wrapping on subsequent instantiations of the same class.\n */\nconst wrappedPrototypes = new WeakSet<object>();\n\n/**\n * Base class for Workflows that need access to their originating Agent.\n *\n * @template AgentType - The Agent class type (for typed RPC access)\n * @template Params - User-defined params passed to the workflow (optional)\n * @template ProgressType - Type for progress reporting (defaults to DefaultProgress)\n * @template Env - Environment type (defaults to Cloudflare.Env)\n */\nexport class AgentWorkflow<\n AgentType extends Agent = Agent,\n Params = unknown,\n ProgressType = DefaultProgress,\n Env extends Cloudflare.Env = Cloudflare.Env\n> extends WorkflowEntrypoint<Env, AgentWorkflowParams<Params>> {\n /**\n * The Agent stub - initialized before run() is called.\n * Use this.agent to access the Agent's RPC methods.\n */\n private _agent!: DurableObjectStub<AgentType>;\n\n /**\n * Workflow instance ID\n */\n private _workflowId!: string;\n\n /**\n * Workflow binding name (for callbacks)\n */\n private _workflowName!: string;\n\n /**\n * Instance-level guard to prevent double initialization.\n * Used when a subclass calls super.run() after its own run() was wrapped.\n */\n private __agentInitCalled = false;\n\n /**\n * Guard to prevent double error notification.\n * Set to true when reportError() is called explicitly, so the automatic\n * error catch in the run() wrapper doesn't send a duplicate notification.\n */\n private _errorReported = false;\n\n constructor(ctx: ExecutionContext, env: Env) {\n super(ctx, env);\n\n const proto = Object.getPrototypeOf(this);\n\n // Only wrap if:\n // 1. This prototype defines its own run method (hasOwnProperty)\n // 2. It hasn't been wrapped yet (WeakSet check)\n // This prevents double-wrapping inherited methods and ensures each subclass\n // that defines run() gets wrapped exactly once.\n if (Object.hasOwn(proto, \"run\") && !wrappedPrototypes.has(proto)) {\n const originalRun = proto.run as (\n event: WorkflowEvent<Params>,\n step: AgentWorkflowStep\n ) => Promise<unknown>;\n\n // Replace the prototype's run method with a wrapper that initializes\n // the agent before calling the user's implementation\n proto.run = async function (\n this: AgentWorkflow<AgentType, Params, ProgressType, Env>,\n event: WorkflowEvent<AgentWorkflowParams<Params>>,\n step: WorkflowStep\n ) {\n // Instance-level guard: only init once per instance\n // (prevents double init if super.run() is called from a subclass)\n if (!this.__agentInitCalled) {\n const { __agentName, __agentBinding, __workflowName, ...userParams } =\n event.payload;\n\n // Initialize agent connection\n await this._initAgent(\n __agentName,\n __agentBinding,\n __workflowName,\n event.instanceId\n );\n this.__agentInitCalled = true;\n\n // Pass cleaned event and wrapped step to user's implementation\n const cleanedEvent = {\n ...event,\n payload: userParams as Params\n } as WorkflowEvent<Params>;\n\n const wrappedStep = this._wrapStep(step);\n\n try {\n return await originalRun.call(this, cleanedEvent, wrappedStep);\n } catch (err) {\n await this._autoReportError(err);\n throw err;\n }\n }\n\n // If already initialized (e.g., called via super.run()),\n // just call the original with the event as-is\n try {\n return await originalRun.call(\n this,\n event as WorkflowEvent<Params>,\n step as AgentWorkflowStep\n );\n } catch (err) {\n await this._autoReportError(err);\n throw err;\n }\n };\n\n wrappedPrototypes.add(proto);\n }\n }\n\n /**\n * Initialize the Agent stub from workflow params.\n * Called automatically before run() executes.\n */\n private async _initAgent(\n agentName: string | undefined,\n agentBinding: string | undefined,\n workflowName: string | undefined,\n instanceId: string\n ): Promise<void> {\n if (!agentName || !agentBinding || !workflowName) {\n throw new Error(\n \"AgentWorkflow requires __agentName, __agentBinding, and __workflowName in params. \" +\n \"Use agent.runWorkflow() to start workflows with proper agent context.\"\n );\n }\n\n this._workflowId = instanceId;\n this._workflowName = workflowName;\n\n // Get the Agent namespace from env\n const namespace = (this.env as Record<string, unknown>)[\n agentBinding\n ] as DurableObjectNamespace<AgentType>;\n\n if (!namespace) {\n throw new Error(\n `Agent binding '${agentBinding}' not found in environment`\n );\n }\n\n // Get the Agent stub by name\n this._agent = await getAgentByName<Cloudflare.Env, AgentType>(\n namespace,\n agentName\n );\n }\n\n /**\n * Wrap WorkflowStep with durable Agent communication methods.\n * Methods added to the wrapped step are idempotent and won't repeat on retry.\n *\n * Note: We add methods directly to the step object to preserve instanceof checks\n * that Cloudflare's runtime may perform on the WorkflowStep class.\n */\n private _wrapStep(step: WorkflowStep): AgentWorkflowStep {\n let stepCounter = 0;\n\n // Cast step to our extended type and add methods directly\n // This preserves the original object identity and instanceof relationship\n const wrappedStep = step as AgentWorkflowStep;\n\n // Add durable Agent methods directly to the step object\n wrappedStep.reportComplete = async <T>(result?: T): Promise<void> => {\n await step.do(`__agent_reportComplete_${stepCounter++}`, async () => {\n await this.notifyAgent({\n workflowName: this._workflowName,\n workflowId: this._workflowId,\n type: \"complete\",\n result,\n timestamp: Date.now()\n });\n });\n };\n\n wrappedStep.reportError = async (error: Error | string): Promise<void> => {\n const errorMessage = error instanceof Error ? error.message : error;\n this._errorReported = true;\n await step.do(`__agent_reportError_${stepCounter++}`, async () => {\n await this.notifyAgent({\n workflowName: this._workflowName,\n workflowId: this._workflowId,\n type: \"error\",\n error: errorMessage,\n timestamp: Date.now()\n });\n });\n };\n\n wrappedStep.sendEvent = async <T>(event: T): Promise<void> => {\n await step.do(`__agent_sendEvent_${stepCounter++}`, async () => {\n await this.notifyAgent({\n workflowName: this._workflowName,\n workflowId: this._workflowId,\n type: \"event\",\n event,\n timestamp: Date.now()\n });\n });\n };\n\n wrappedStep.updateAgentState = async (state: unknown): Promise<void> => {\n await step.do(`__agent_updateState_${stepCounter++}`, async () => {\n this.agent._workflow_updateState(\"set\", state);\n });\n };\n\n wrappedStep.mergeAgentState = async (\n partialState: Record<string, unknown>\n ): Promise<void> => {\n await step.do(`__agent_mergeState_${stepCounter++}`, async () => {\n this.agent._workflow_updateState(\"merge\", partialState);\n });\n };\n\n wrappedStep.resetAgentState = async (): Promise<void> => {\n await step.do(`__agent_resetState_${stepCounter++}`, async () => {\n this.agent._workflow_updateState(\"reset\");\n });\n };\n\n return wrappedStep;\n }\n\n /**\n * Get the Agent stub for RPC calls.\n * Provides typed access to the Agent's methods.\n *\n * @example\n * ```typescript\n * // Call any public method on the Agent\n * await this.agent.updateStatus('processing');\n * const data = await this.agent.getData();\n * ```\n */\n get agent(): DurableObjectStub<AgentType> {\n if (!this._agent) {\n throw new Error(\n \"Agent not initialized. Ensure you're accessing this.agent inside run().\"\n );\n }\n return this._agent;\n }\n\n /**\n * Get the workflow instance ID\n */\n get workflowId(): string {\n return this._workflowId;\n }\n\n /**\n * Get the workflow binding name\n */\n get workflowName(): string {\n return this._workflowName;\n }\n\n /**\n * Automatically report an unhandled error to the Agent.\n * Skipped if reportError() was already called (prevents double notification).\n * Best-effort: notification failures are swallowed so the original error propagates.\n *\n * @param err - The caught error\n */\n private async _autoReportError(err: unknown): Promise<void> {\n if (this._errorReported) {\n return;\n }\n this._errorReported = true;\n const errorMessage = err instanceof Error ? err.message : String(err);\n try {\n await this.notifyAgent({\n workflowName: this._workflowName,\n workflowId: this._workflowId,\n type: \"error\",\n error: errorMessage,\n timestamp: Date.now()\n });\n } catch (_notifyErr) {\n // Best-effort: don't mask the original error\n }\n }\n\n /**\n * Send a notification to the Agent via RPC.\n *\n * @param callback - Callback payload to send\n */\n protected async notifyAgent(callback: WorkflowCallback): Promise<void> {\n await this.agent._workflow_handleCallback(callback);\n }\n\n /**\n * Report progress to the Agent with typed progress data.\n * Triggers onWorkflowProgress() on the Agent.\n *\n * @param progress - Typed progress data\n *\n * @example\n * ```typescript\n * // Using default progress type\n * await this.reportProgress({ step: 'fetch', status: 'running' });\n * await this.reportProgress({ step: 'fetch', status: 'complete', percent: 0.5 });\n *\n * // With custom progress type\n * await this.reportProgress({ stage: 'extract', recordsProcessed: 100 });\n * ```\n */\n protected async reportProgress(progress: ProgressType): Promise<void> {\n await this.notifyAgent({\n workflowName: this._workflowName,\n workflowId: this._workflowId,\n type: \"progress\",\n progress: progress as DefaultProgress,\n timestamp: Date.now()\n });\n }\n\n /**\n * Broadcast a message to all connected WebSocket clients via the Agent.\n * This is non-durable and may repeat on workflow retry.\n *\n * @param message - Message to broadcast (will be JSON-stringified)\n */\n protected broadcastToClients(message: unknown): void {\n this.agent._workflow_broadcast(message);\n }\n\n /**\n * Wait for approval from the Agent.\n * Handles rejection by reporting error (durably) and throwing WorkflowRejectedError.\n *\n * @param step - AgentWorkflowStep object\n * @param options - Wait options (timeout, eventType, stepName)\n * @returns Approval payload (throws WorkflowRejectedError if rejected)\n *\n * @example\n * ```typescript\n * const approval = await this.waitForApproval(step, { timeout: '7 days' });\n * // approval contains the payload from approveWorkflow()\n * ```\n */\n protected async waitForApproval<T = unknown>(\n step: AgentWorkflowStep,\n options?: WaitForApprovalOptions\n ): Promise<T> {\n const stepName = options?.stepName ?? \"wait-for-approval\";\n const eventType = options?.eventType ?? \"approval\";\n const timeout = options?.timeout;\n\n // Wait for the approval event\n // Note: Call reportProgress() before this method if you want to update progress\n const event = await step.waitForEvent(stepName, {\n type: eventType,\n timeout\n });\n\n // Cast the payload to our expected type\n const payload = event.payload as {\n approved: boolean;\n reason?: string;\n metadata?: T;\n };\n\n // Check if rejected\n if (!payload.approved) {\n const reason = payload.reason;\n await step.reportError(reason ?? \"Workflow rejected\");\n throw new WorkflowRejectedError(reason, this._workflowId);\n }\n\n // Return the approval metadata as the result\n return payload.metadata as T;\n }\n}\n\n// Re-export types for convenience\nexport type {\n AgentWorkflowEvent,\n AgentWorkflowStep,\n WorkflowCallback,\n WorkflowCallbackType,\n WorkflowProgressCallback,\n WorkflowCompleteCallback,\n WorkflowErrorCallback,\n WorkflowEventCallback,\n DefaultProgress,\n WaitForApprovalOptions,\n ApprovalEventPayload,\n WorkflowStatus,\n WorkflowTrackingRow,\n RunWorkflowOptions,\n WorkflowEventPayload,\n WorkflowInfo,\n WorkflowQueryCriteria,\n WorkflowPage\n} from \"./workflow-types\";\n\nexport { WorkflowRejectedError } from \"./workflow-types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,MAAM,oCAAoB,IAAI,SAAiB;;;;;;;;;AAU/C,IAAa,gBAAb,cAKU,mBAAqD;CA8B7D,YAAY,KAAuB,KAAU;AAC3C,QAAM,KAAK,IAAI;2BAVW;wBAOH;EAKv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KAAK;IACnB,YAAY,KAAK;IACjB,MAAM;IACN,OAAO;IACP,WAAW,KAAK,KAAK;IACtB,CAAC;WACK,YAAY;;;;;;;CAUvB,MAAgB,YAAY,UAA2C;AACrE,QAAM,KAAK,MAAM,yBAAyB,SAAS;;;;;;;;;;;;;;;;;;CAmBrD,MAAgB,eAAe,UAAuC;AACpE,QAAM,KAAK,YAAY;GACrB,cAAc,KAAK;GACnB,YAAY,KAAK;GACjB,MAAM;GACI;GACV,WAAW,KAAK,KAAK;GACtB,CAAC;;;;;;;;CASJ,AAAU,mBAAmB,SAAwB;AACnD,OAAK,MAAM,oBAAoB,QAAQ;;;;;;;;;;;;;;;;CAiBzC,MAAgB,gBACd,MACA,SACY;EACZ,MAAM,WAAW,SAAS,YAAY;EACtC,MAAM,YAAY,SAAS,aAAa;EACxC,MAAM,UAAU,SAAS;EAUzB,MAAM,WANQ,MAAM,KAAK,aAAa,UAAU;GAC9C,MAAM;GACN;GACD,CAAC,EAGoB;AAOtB,MAAI,CAAC,QAAQ,UAAU;GACrB,MAAM,SAAS,QAAQ;AACvB,SAAM,KAAK,YAAY,UAAU,oBAAoB;AACrD,SAAM,IAAI,sBAAsB,QAAQ,KAAK,YAAY;;AAI3D,SAAO,QAAQ"}
|
|
1
|
+
{"version":3,"file":"workflows.js","names":[],"sources":["../src/workflows.ts"],"sourcesContent":["/**\n * AgentWorkflow - Base class for Workflows that integrate with Agents\n *\n * Extends Cloudflare's WorkflowEntrypoint to provide seamless access to\n * the Agent that started the workflow, enabling bidirectional communication.\n *\n * @example\n * ```typescript\n * import { AgentWorkflow } from 'agents/workflows';\n * import type { MyAgent } from './agent';\n *\n * type TaskParams = { taskId: string; data: string };\n *\n * export class ProcessingWorkflow extends AgentWorkflow<MyAgent, TaskParams> {\n * async run(event: AgentWorkflowEvent<TaskParams>, step: WorkflowStep) {\n * // Access the originating Agent via typed RPC\n * await this.agent.updateTaskStatus(event.payload.taskId, 'processing');\n *\n * const result = await step.do('process', async () => {\n * // ... processing logic\n * return { processed: true };\n * });\n *\n * // Report progress to Agent (typed)\n * await this.reportProgress({ step: 'process', status: 'complete', percent: 0.5 });\n *\n * // Broadcast to connected clients\n * await this.broadcastToClients({ type: 'progress', data: result });\n *\n * return result;\n * }\n * }\n * ```\n */\n\nimport { WorkflowEntrypoint } from \"cloudflare:workers\";\nimport type { WorkflowEvent, WorkflowStep } from \"cloudflare:workers\";\nimport { getAgentByName, type Agent } from \"./index\";\nimport type {\n AgentWorkflowParams,\n AgentWorkflowStep,\n WorkflowCallback,\n DefaultProgress,\n WaitForApprovalOptions\n} from \"./workflow-types\";\nimport { WorkflowRejectedError } from \"./workflow-types\";\n\n/**\n * WeakSet to track which prototypes have been wrapped.\n * This prevents re-wrapping on subsequent instantiations of the same class.\n */\nconst wrappedPrototypes = new WeakSet<object>();\n\n/**\n * Base class for Workflows that need access to their originating Agent.\n *\n * @template AgentType - The Agent class type (for typed RPC access)\n * @template Params - User-defined params passed to the workflow (optional)\n * @template ProgressType - Type for progress reporting (defaults to DefaultProgress)\n * @template Env - Environment type (defaults to Cloudflare.Env)\n */\nexport class AgentWorkflow<\n AgentType extends Agent = Agent,\n Params = unknown,\n ProgressType = DefaultProgress,\n Env extends Cloudflare.Env = Cloudflare.Env\n> extends WorkflowEntrypoint<Env, AgentWorkflowParams<Params>> {\n /**\n * The Agent stub - initialized before run() is called.\n * Use this.agent to access the Agent's RPC methods.\n */\n private _agent!: DurableObjectStub<AgentType>;\n\n /**\n * Workflow instance ID\n */\n private _workflowId!: string;\n\n /**\n * Workflow binding name (for callbacks)\n */\n private _workflowName!: string;\n\n /**\n * Instance-level guard to prevent double initialization.\n * Used when a subclass calls super.run() after its own run() was wrapped.\n */\n private __agentInitCalled = false;\n\n /**\n * Guard to prevent double error notification.\n * Set to true when reportError() is called explicitly, so the automatic\n * error catch in the run() wrapper doesn't send a duplicate notification.\n */\n private _errorReported = false;\n\n constructor(ctx: ExecutionContext, env: Env) {\n super(ctx, env);\n\n const proto = Object.getPrototypeOf(this);\n\n // Only wrap if:\n // 1. This prototype defines its own run method (hasOwnProperty)\n // 2. It hasn't been wrapped yet (WeakSet check)\n // This prevents double-wrapping inherited methods and ensures each subclass\n // that defines run() gets wrapped exactly once.\n if (Object.hasOwn(proto, \"run\") && !wrappedPrototypes.has(proto)) {\n const originalRun = proto.run as (\n event: WorkflowEvent<Params>,\n step: AgentWorkflowStep\n ) => Promise<unknown>;\n\n // Replace the prototype's run method with a wrapper that initializes\n // the agent before calling the user's implementation\n proto.run = async function (\n this: AgentWorkflow<AgentType, Params, ProgressType, Env>,\n event: WorkflowEvent<AgentWorkflowParams<Params>>,\n step: WorkflowStep\n ) {\n // Instance-level guard: only init once per instance\n // (prevents double init if super.run() is called from a subclass)\n if (!this.__agentInitCalled) {\n const { __agentName, __agentBinding, __workflowName, ...userParams } =\n event.payload;\n\n // Initialize agent connection\n await this._initAgent(\n __agentName,\n __agentBinding,\n __workflowName,\n event.instanceId\n );\n this.__agentInitCalled = true;\n\n // Pass cleaned event and wrapped step to user's implementation\n const cleanedEvent = {\n ...event,\n payload: userParams as Params\n } as WorkflowEvent<Params>;\n\n const wrappedStep = this._wrapStep(step);\n\n try {\n return await originalRun.call(this, cleanedEvent, wrappedStep);\n } catch (err) {\n await this._autoReportError(err);\n throw err;\n }\n }\n\n // If already initialized (e.g., called via super.run()),\n // just call the original with the event as-is\n try {\n return await originalRun.call(\n this,\n event as WorkflowEvent<Params>,\n step as AgentWorkflowStep\n );\n } catch (err) {\n await this._autoReportError(err);\n throw err;\n }\n };\n\n wrappedPrototypes.add(proto);\n }\n }\n\n /**\n * Initialize the Agent stub from workflow params.\n * Called automatically before run() executes.\n */\n private async _initAgent(\n agentName: string | undefined,\n agentBinding: string | undefined,\n workflowName: string | undefined,\n instanceId: string\n ): Promise<void> {\n if (!agentName || !agentBinding || !workflowName) {\n throw new Error(\n \"AgentWorkflow requires __agentName, __agentBinding, and __workflowName in params. \" +\n \"Use agent.runWorkflow() to start workflows with proper agent context.\"\n );\n }\n\n this._workflowId = instanceId;\n this._workflowName = workflowName;\n\n // Get the Agent namespace from env\n const namespace = (this.env as Record<string, unknown>)[\n agentBinding\n ] as DurableObjectNamespace<AgentType>;\n\n if (!namespace) {\n throw new Error(\n `Agent binding '${agentBinding}' not found in environment`\n );\n }\n\n // Get the Agent stub by name\n this._agent = await getAgentByName<Cloudflare.Env, AgentType>(\n namespace,\n agentName\n );\n }\n\n /**\n * Wrap WorkflowStep with durable Agent communication methods.\n * Methods added to the wrapped step are idempotent and won't repeat on retry.\n *\n * Note: We add methods directly to the step object to preserve instanceof checks\n * that Cloudflare's runtime may perform on the WorkflowStep class.\n */\n private _wrapStep(step: WorkflowStep): AgentWorkflowStep {\n let stepCounter = 0;\n\n // Cast step to our extended type and add methods directly\n // This preserves the original object identity and instanceof relationship\n const wrappedStep = step as AgentWorkflowStep;\n\n // Add durable Agent methods directly to the step object\n wrappedStep.reportComplete = async <T>(result?: T): Promise<void> => {\n await step.do(`__agent_reportComplete_${stepCounter++}`, async () => {\n await this.notifyAgent({\n workflowName: this._workflowName,\n workflowId: this._workflowId,\n type: \"complete\",\n result,\n timestamp: Date.now()\n });\n });\n };\n\n wrappedStep.reportError = async (error: Error | string): Promise<void> => {\n const errorMessage = error instanceof Error ? error.message : error;\n this._errorReported = true;\n await step.do(`__agent_reportError_${stepCounter++}`, async () => {\n await this.notifyAgent({\n workflowName: this._workflowName,\n workflowId: this._workflowId,\n type: \"error\",\n error: errorMessage,\n timestamp: Date.now()\n });\n });\n };\n\n wrappedStep.sendEvent = async <T>(event: T): Promise<void> => {\n await step.do(`__agent_sendEvent_${stepCounter++}`, async () => {\n await this.notifyAgent({\n workflowName: this._workflowName,\n workflowId: this._workflowId,\n type: \"event\",\n event,\n timestamp: Date.now()\n });\n });\n };\n\n wrappedStep.updateAgentState = async (state: unknown): Promise<void> => {\n await step.do(`__agent_updateState_${stepCounter++}`, async () => {\n await this.agent._workflow_updateState(\"set\", state);\n });\n };\n\n wrappedStep.mergeAgentState = async (\n partialState: Record<string, unknown>\n ): Promise<void> => {\n await step.do(`__agent_mergeState_${stepCounter++}`, async () => {\n await this.agent._workflow_updateState(\"merge\", partialState);\n });\n };\n\n wrappedStep.resetAgentState = async (): Promise<void> => {\n await step.do(`__agent_resetState_${stepCounter++}`, async () => {\n await this.agent._workflow_updateState(\"reset\");\n });\n };\n\n return wrappedStep;\n }\n\n /**\n * Get the Agent stub for RPC calls.\n * Provides typed access to the Agent's methods.\n *\n * @example\n * ```typescript\n * // Call any public method on the Agent\n * await this.agent.updateStatus('processing');\n * const data = await this.agent.getData();\n * ```\n */\n get agent(): DurableObjectStub<AgentType> {\n if (!this._agent) {\n throw new Error(\n \"Agent not initialized. Ensure you're accessing this.agent inside run().\"\n );\n }\n return this._agent;\n }\n\n /**\n * Get the workflow instance ID\n */\n get workflowId(): string {\n return this._workflowId;\n }\n\n /**\n * Get the workflow binding name\n */\n get workflowName(): string {\n return this._workflowName;\n }\n\n /**\n * Automatically report an unhandled error to the Agent.\n * Skipped if reportError() was already called (prevents double notification).\n * Best-effort: notification failures are swallowed so the original error propagates.\n *\n * @param err - The caught error\n */\n private async _autoReportError(err: unknown): Promise<void> {\n if (this._errorReported) {\n return;\n }\n this._errorReported = true;\n const errorMessage = err instanceof Error ? err.message : String(err);\n try {\n await this.notifyAgent({\n workflowName: this._workflowName,\n workflowId: this._workflowId,\n type: \"error\",\n error: errorMessage,\n timestamp: Date.now()\n });\n } catch (_notifyErr) {\n // Best-effort: don't mask the original error\n }\n }\n\n /**\n * Send a notification to the Agent via RPC.\n *\n * @param callback - Callback payload to send\n */\n protected async notifyAgent(callback: WorkflowCallback): Promise<void> {\n await this.agent._workflow_handleCallback(callback);\n }\n\n /**\n * Report progress to the Agent with typed progress data.\n * Triggers onWorkflowProgress() on the Agent.\n *\n * @param progress - Typed progress data\n *\n * @example\n * ```typescript\n * // Using default progress type\n * await this.reportProgress({ step: 'fetch', status: 'running' });\n * await this.reportProgress({ step: 'fetch', status: 'complete', percent: 0.5 });\n *\n * // With custom progress type\n * await this.reportProgress({ stage: 'extract', recordsProcessed: 100 });\n * ```\n */\n protected async reportProgress(progress: ProgressType): Promise<void> {\n await this.notifyAgent({\n workflowName: this._workflowName,\n workflowId: this._workflowId,\n type: \"progress\",\n progress: progress as DefaultProgress,\n timestamp: Date.now()\n });\n }\n\n /**\n * Broadcast a message to all connected WebSocket clients via the Agent.\n * This is non-durable and may repeat on workflow retry.\n *\n * @param message - Message to broadcast (will be JSON-stringified)\n */\n protected broadcastToClients(message: unknown): void {\n this.agent._workflow_broadcast(message);\n }\n\n /**\n * Wait for approval from the Agent.\n * Handles rejection by reporting error (durably) and throwing WorkflowRejectedError.\n *\n * @param step - AgentWorkflowStep object\n * @param options - Wait options (timeout, eventType, stepName)\n * @returns Approval payload (throws WorkflowRejectedError if rejected)\n *\n * @example\n * ```typescript\n * const approval = await this.waitForApproval(step, { timeout: '7 days' });\n * // approval contains the payload from approveWorkflow()\n * ```\n */\n protected async waitForApproval<T = unknown>(\n step: AgentWorkflowStep,\n options?: WaitForApprovalOptions\n ): Promise<T> {\n const stepName = options?.stepName ?? \"wait-for-approval\";\n const eventType = options?.eventType ?? \"approval\";\n const timeout = options?.timeout;\n\n // Wait for the approval event\n // Note: Call reportProgress() before this method if you want to update progress\n const event = await step.waitForEvent(stepName, {\n type: eventType,\n timeout\n });\n\n // Cast the payload to our expected type\n const payload = event.payload as {\n approved: boolean;\n reason?: string;\n metadata?: T;\n };\n\n // Check if rejected\n if (!payload.approved) {\n const reason = payload.reason;\n await step.reportError(reason ?? \"Workflow rejected\");\n throw new WorkflowRejectedError(reason, this._workflowId);\n }\n\n // Return the approval metadata as the result\n return payload.metadata as T;\n }\n}\n\n// Re-export types for convenience\nexport type {\n AgentWorkflowEvent,\n AgentWorkflowStep,\n WorkflowCallback,\n WorkflowCallbackType,\n WorkflowProgressCallback,\n WorkflowCompleteCallback,\n WorkflowErrorCallback,\n WorkflowEventCallback,\n DefaultProgress,\n WaitForApprovalOptions,\n ApprovalEventPayload,\n WorkflowStatus,\n WorkflowTrackingRow,\n RunWorkflowOptions,\n WorkflowEventPayload,\n WorkflowInfo,\n WorkflowQueryCriteria,\n WorkflowPage\n} from \"./workflow-types\";\n\nexport { WorkflowRejectedError } from \"./workflow-types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,MAAM,oCAAoB,IAAI,SAAiB;;;;;;;;;AAU/C,IAAa,gBAAb,cAKU,mBAAqD;CA8B7D,YAAY,KAAuB,KAAU;AAC3C,QAAM,KAAK,IAAI;2BAVW;wBAOH;EAKvB,MAAM,QAAQ,OAAO,eAAe,KAAK;AAOzC,MAAI,OAAO,OAAO,OAAO,MAAM,IAAI,CAAC,kBAAkB,IAAI,MAAM,EAAE;GAChE,MAAM,cAAc,MAAM;AAO1B,SAAM,MAAM,eAEV,OACA,MACA;AAGA,QAAI,CAAC,KAAK,mBAAmB;KAC3B,MAAM,EAAE,aAAa,gBAAgB,gBAAgB,GAAG,eACtD,MAAM;AAGR,WAAM,KAAK,WACT,aACA,gBACA,gBACA,MAAM,WACP;AACD,UAAK,oBAAoB;KAGzB,MAAM,eAAe;MACnB,GAAG;MACH,SAAS;MACV;KAED,MAAM,cAAc,KAAK,UAAU,KAAK;AAExC,SAAI;AACF,aAAO,MAAM,YAAY,KAAK,MAAM,cAAc,YAAY;cACvD,KAAK;AACZ,YAAM,KAAK,iBAAiB,IAAI;AAChC,YAAM;;;AAMV,QAAI;AACF,YAAO,MAAM,YAAY,KACvB,MACA,OACA,KACD;aACM,KAAK;AACZ,WAAM,KAAK,iBAAiB,IAAI;AAChC,WAAM;;;AAIV,qBAAkB,IAAI,MAAM;;;;;;;CAQhC,MAAc,WACZ,WACA,cACA,cACA,YACe;AACf,MAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,aAClC,OAAM,IAAI,MACR,0JAED;AAGH,OAAK,cAAc;AACnB,OAAK,gBAAgB;EAGr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9
|
"durable objects"
|
|
10
10
|
],
|
|
11
11
|
"type": "module",
|
|
12
|
-
"version": "0.7.
|
|
12
|
+
"version": "0.7.5",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"repository": {
|
|
15
15
|
"directory": "packages/agents",
|
|
@@ -36,14 +36,15 @@
|
|
|
36
36
|
"yargs": "^18.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@ai-sdk/openai": "^3.0.
|
|
40
|
-
"@ai-sdk/react": "^3.0.
|
|
41
|
-
"@cloudflare/workers-oauth-provider": "^0.
|
|
39
|
+
"@ai-sdk/openai": "^3.0.41",
|
|
40
|
+
"@ai-sdk/react": "^3.0.118",
|
|
41
|
+
"@cloudflare/workers-oauth-provider": "^0.3.0",
|
|
42
42
|
"@types/react": "^19.2.14",
|
|
43
43
|
"@types/yargs": "^17.0.35",
|
|
44
44
|
"@x402/core": "^2.5.0",
|
|
45
45
|
"@x402/evm": "^2.5.0",
|
|
46
|
-
"ai": "^6.0.
|
|
46
|
+
"ai": "^6.0.116",
|
|
47
|
+
"just-bash": "^2.11.8",
|
|
47
48
|
"react": "^19.2.4",
|
|
48
49
|
"vitest-browser-react": "^1.0.1",
|
|
49
50
|
"zod": "^4.3.6"
|
|
@@ -56,6 +57,7 @@
|
|
|
56
57
|
"@x402/core": "^2.0.0",
|
|
57
58
|
"@x402/evm": "^2.0.0",
|
|
58
59
|
"ai": "^6.0.0",
|
|
60
|
+
"just-bash": "^2.11.0",
|
|
59
61
|
"react": "^19.0.0",
|
|
60
62
|
"viem": ">=2.0.0",
|
|
61
63
|
"zod": "^3.25.0 || ^4.0.0"
|
|
@@ -79,6 +81,9 @@
|
|
|
79
81
|
"@x402/evm": {
|
|
80
82
|
"optional": true
|
|
81
83
|
},
|
|
84
|
+
"just-bash": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
82
87
|
"viem": {
|
|
83
88
|
"optional": true
|
|
84
89
|
}
|
|
@@ -184,6 +189,11 @@
|
|
|
184
189
|
"types": "./dist/email.d.ts",
|
|
185
190
|
"import": "./dist/email.js",
|
|
186
191
|
"require": "./dist/email.js"
|
|
192
|
+
},
|
|
193
|
+
"./experimental/workspace": {
|
|
194
|
+
"types": "./dist/experimental/workspace.d.ts",
|
|
195
|
+
"import": "./dist/experimental/workspace.js",
|
|
196
|
+
"require": "./dist/experimental/workspace.js"
|
|
187
197
|
}
|
|
188
198
|
},
|
|
189
199
|
"publishConfig": {
|
package/dist/agent-eZnMHidZ.d.ts
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
//#region src/observability/base.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Base event structure for all observability events
|
|
4
|
-
*/
|
|
5
|
-
type BaseEvent<
|
|
6
|
-
T extends string,
|
|
7
|
-
Payload extends Record<string, unknown> = Record<string, never>
|
|
8
|
-
> = {
|
|
9
|
-
type: T;
|
|
10
|
-
/**
|
|
11
|
-
* The class name of the agent that emitted this event
|
|
12
|
-
* (e.g. "MyChatAgent").
|
|
13
|
-
* Always present on events emitted by an Agent instance.
|
|
14
|
-
*/
|
|
15
|
-
agent?: string;
|
|
16
|
-
/**
|
|
17
|
-
* The instance name (Durable Object ID name) of the agent.
|
|
18
|
-
* Always present on events emitted by an Agent instance.
|
|
19
|
-
*/
|
|
20
|
-
name?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The payload of the event
|
|
23
|
-
*/
|
|
24
|
-
payload: Payload;
|
|
25
|
-
/**
|
|
26
|
-
* The timestamp of the event in milliseconds since epoch
|
|
27
|
-
*/
|
|
28
|
-
timestamp: number;
|
|
29
|
-
};
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/observability/mcp.d.ts
|
|
32
|
-
/**
|
|
33
|
-
* MCP-specific observability events
|
|
34
|
-
* These track the lifecycle of MCP connections and operations
|
|
35
|
-
*/
|
|
36
|
-
type MCPObservabilityEvent =
|
|
37
|
-
| BaseEvent<
|
|
38
|
-
"mcp:client:preconnect",
|
|
39
|
-
{
|
|
40
|
-
serverId: string;
|
|
41
|
-
}
|
|
42
|
-
>
|
|
43
|
-
| BaseEvent<
|
|
44
|
-
"mcp:client:connect",
|
|
45
|
-
{
|
|
46
|
-
url: string;
|
|
47
|
-
transport: string;
|
|
48
|
-
state: string;
|
|
49
|
-
error?: string;
|
|
50
|
-
}
|
|
51
|
-
>
|
|
52
|
-
| BaseEvent<
|
|
53
|
-
"mcp:client:authorize",
|
|
54
|
-
{
|
|
55
|
-
serverId: string;
|
|
56
|
-
authUrl: string;
|
|
57
|
-
clientId?: string;
|
|
58
|
-
}
|
|
59
|
-
>
|
|
60
|
-
| BaseEvent<
|
|
61
|
-
"mcp:client:discover",
|
|
62
|
-
{
|
|
63
|
-
url?: string;
|
|
64
|
-
state?: string;
|
|
65
|
-
error?: string;
|
|
66
|
-
capability?: string;
|
|
67
|
-
}
|
|
68
|
-
>;
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/observability/agent.d.ts
|
|
71
|
-
/**
|
|
72
|
-
* Agent-specific observability events
|
|
73
|
-
* These track the lifecycle and operations of an Agent
|
|
74
|
-
*/
|
|
75
|
-
type AgentObservabilityEvent =
|
|
76
|
-
| BaseEvent<"state:update">
|
|
77
|
-
| BaseEvent<
|
|
78
|
-
"rpc",
|
|
79
|
-
{
|
|
80
|
-
method: string;
|
|
81
|
-
streaming?: boolean;
|
|
82
|
-
}
|
|
83
|
-
>
|
|
84
|
-
| BaseEvent<
|
|
85
|
-
"rpc:error",
|
|
86
|
-
{
|
|
87
|
-
method: string;
|
|
88
|
-
error: string;
|
|
89
|
-
}
|
|
90
|
-
>
|
|
91
|
-
| BaseEvent<"message:request">
|
|
92
|
-
| BaseEvent<"message:response">
|
|
93
|
-
| BaseEvent<"message:clear">
|
|
94
|
-
| BaseEvent<
|
|
95
|
-
"message:cancel",
|
|
96
|
-
{
|
|
97
|
-
requestId: string;
|
|
98
|
-
}
|
|
99
|
-
>
|
|
100
|
-
| BaseEvent<
|
|
101
|
-
"message:error",
|
|
102
|
-
{
|
|
103
|
-
error: string;
|
|
104
|
-
}
|
|
105
|
-
>
|
|
106
|
-
| BaseEvent<
|
|
107
|
-
"tool:result",
|
|
108
|
-
{
|
|
109
|
-
toolCallId: string;
|
|
110
|
-
toolName: string;
|
|
111
|
-
}
|
|
112
|
-
>
|
|
113
|
-
| BaseEvent<
|
|
114
|
-
"tool:approval",
|
|
115
|
-
{
|
|
116
|
-
toolCallId: string;
|
|
117
|
-
approved: boolean;
|
|
118
|
-
}
|
|
119
|
-
>
|
|
120
|
-
| BaseEvent<
|
|
121
|
-
"schedule:create",
|
|
122
|
-
{
|
|
123
|
-
callback: string;
|
|
124
|
-
id: string;
|
|
125
|
-
}
|
|
126
|
-
>
|
|
127
|
-
| BaseEvent<
|
|
128
|
-
"schedule:execute",
|
|
129
|
-
{
|
|
130
|
-
callback: string;
|
|
131
|
-
id: string;
|
|
132
|
-
}
|
|
133
|
-
>
|
|
134
|
-
| BaseEvent<
|
|
135
|
-
"schedule:cancel",
|
|
136
|
-
{
|
|
137
|
-
callback: string;
|
|
138
|
-
id: string;
|
|
139
|
-
}
|
|
140
|
-
>
|
|
141
|
-
| BaseEvent<
|
|
142
|
-
"schedule:retry",
|
|
143
|
-
{
|
|
144
|
-
callback: string;
|
|
145
|
-
id: string;
|
|
146
|
-
attempt: number;
|
|
147
|
-
maxAttempts: number;
|
|
148
|
-
}
|
|
149
|
-
>
|
|
150
|
-
| BaseEvent<
|
|
151
|
-
"schedule:error",
|
|
152
|
-
{
|
|
153
|
-
callback: string;
|
|
154
|
-
id: string;
|
|
155
|
-
error: string;
|
|
156
|
-
attempts: number;
|
|
157
|
-
}
|
|
158
|
-
>
|
|
159
|
-
| BaseEvent<
|
|
160
|
-
"queue:create",
|
|
161
|
-
{
|
|
162
|
-
callback: string;
|
|
163
|
-
id: string;
|
|
164
|
-
}
|
|
165
|
-
>
|
|
166
|
-
| BaseEvent<
|
|
167
|
-
"queue:retry",
|
|
168
|
-
{
|
|
169
|
-
callback: string;
|
|
170
|
-
id: string;
|
|
171
|
-
attempt: number;
|
|
172
|
-
maxAttempts: number;
|
|
173
|
-
}
|
|
174
|
-
>
|
|
175
|
-
| BaseEvent<
|
|
176
|
-
"queue:error",
|
|
177
|
-
{
|
|
178
|
-
callback: string;
|
|
179
|
-
id: string;
|
|
180
|
-
error: string;
|
|
181
|
-
attempts: number;
|
|
182
|
-
}
|
|
183
|
-
>
|
|
184
|
-
| BaseEvent<"destroy">
|
|
185
|
-
| BaseEvent<
|
|
186
|
-
"connect",
|
|
187
|
-
{
|
|
188
|
-
connectionId: string;
|
|
189
|
-
}
|
|
190
|
-
>
|
|
191
|
-
| BaseEvent<
|
|
192
|
-
"disconnect",
|
|
193
|
-
{
|
|
194
|
-
connectionId: string;
|
|
195
|
-
code: number;
|
|
196
|
-
reason: string;
|
|
197
|
-
}
|
|
198
|
-
>
|
|
199
|
-
| BaseEvent<
|
|
200
|
-
"email:receive",
|
|
201
|
-
{
|
|
202
|
-
from: string;
|
|
203
|
-
to: string;
|
|
204
|
-
subject?: string;
|
|
205
|
-
}
|
|
206
|
-
>
|
|
207
|
-
| BaseEvent<
|
|
208
|
-
"email:reply",
|
|
209
|
-
{
|
|
210
|
-
from: string;
|
|
211
|
-
to: string;
|
|
212
|
-
subject?: string;
|
|
213
|
-
}
|
|
214
|
-
>
|
|
215
|
-
| BaseEvent<
|
|
216
|
-
"workflow:start",
|
|
217
|
-
{
|
|
218
|
-
workflowId: string;
|
|
219
|
-
workflowName?: string;
|
|
220
|
-
}
|
|
221
|
-
>
|
|
222
|
-
| BaseEvent<
|
|
223
|
-
"workflow:event",
|
|
224
|
-
{
|
|
225
|
-
workflowId: string;
|
|
226
|
-
eventType?: string;
|
|
227
|
-
}
|
|
228
|
-
>
|
|
229
|
-
| BaseEvent<
|
|
230
|
-
"workflow:approved",
|
|
231
|
-
{
|
|
232
|
-
workflowId: string;
|
|
233
|
-
reason?: string;
|
|
234
|
-
}
|
|
235
|
-
>
|
|
236
|
-
| BaseEvent<
|
|
237
|
-
"workflow:rejected",
|
|
238
|
-
{
|
|
239
|
-
workflowId: string;
|
|
240
|
-
reason?: string;
|
|
241
|
-
}
|
|
242
|
-
>
|
|
243
|
-
| BaseEvent<
|
|
244
|
-
"workflow:terminated",
|
|
245
|
-
{
|
|
246
|
-
workflowId: string;
|
|
247
|
-
workflowName?: string;
|
|
248
|
-
}
|
|
249
|
-
>
|
|
250
|
-
| BaseEvent<
|
|
251
|
-
"workflow:paused",
|
|
252
|
-
{
|
|
253
|
-
workflowId: string;
|
|
254
|
-
workflowName?: string;
|
|
255
|
-
}
|
|
256
|
-
>
|
|
257
|
-
| BaseEvent<
|
|
258
|
-
"workflow:resumed",
|
|
259
|
-
{
|
|
260
|
-
workflowId: string;
|
|
261
|
-
workflowName?: string;
|
|
262
|
-
}
|
|
263
|
-
>
|
|
264
|
-
| BaseEvent<
|
|
265
|
-
"workflow:restarted",
|
|
266
|
-
{
|
|
267
|
-
workflowId: string;
|
|
268
|
-
workflowName?: string;
|
|
269
|
-
}
|
|
270
|
-
>;
|
|
271
|
-
//#endregion
|
|
272
|
-
export { MCPObservabilityEvent as n, AgentObservabilityEvent as t };
|
|
273
|
-
//# sourceMappingURL=agent-eZnMHidZ.d.ts.map
|