runwork 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +134 -0
  3. package/bin/runwork.js +2 -0
  4. package/bundled-types/agents.d.ts +3 -0
  5. package/bundled-types/ai.d.ts +2 -0
  6. package/bundled-types/app-registry.d.ts +74 -0
  7. package/bundled-types/channels.d.ts +2 -0
  8. package/bundled-types/components.d.ts +1 -0
  9. package/bundled-types/core-agent.d.ts +265 -0
  10. package/bundled-types/core-ai.d.ts +170 -0
  11. package/bundled-types/core-base-agent.d.ts +89 -0
  12. package/bundled-types/core-channels.d.ts +42 -0
  13. package/bundled-types/core-components.d.ts +21 -0
  14. package/bundled-types/core-endpoints.d.ts +198 -0
  15. package/bundled-types/core-entities.d.ts +276 -0
  16. package/bundled-types/core-entity-do.d.ts +119 -0
  17. package/bundled-types/core-events.d.ts +52 -0
  18. package/bundled-types/core-file-storage.d.ts +216 -0
  19. package/bundled-types/core-integration-entities.d.ts +147 -0
  20. package/bundled-types/core-integrations.d.ts +143 -0
  21. package/bundled-types/core-routes.d.ts +33 -0
  22. package/bundled-types/core-scheduler.d.ts +180 -0
  23. package/bundled-types/core-utils.d.ts +85 -0
  24. package/bundled-types/core-workflow-cloudflare.d.ts +85 -0
  25. package/bundled-types/core-workflow-config.d.ts +18 -0
  26. package/bundled-types/core-workflow-coordinator.d.ts +78 -0
  27. package/bundled-types/core-workflow-instance.d.ts +82 -0
  28. package/bundled-types/core-workflow-types.d.ts +251 -0
  29. package/bundled-types/core-workflows.d.ts +75 -0
  30. package/bundled-types/core-workspace.d.ts +454 -0
  31. package/bundled-types/create-app.d.ts +57 -0
  32. package/bundled-types/endpoints.d.ts +2 -0
  33. package/bundled-types/entities.d.ts +5 -0
  34. package/bundled-types/events.d.ts +2 -0
  35. package/bundled-types/index.d.ts +19 -0
  36. package/bundled-types/integrations.d.ts +2 -0
  37. package/bundled-types/routes.d.ts +2 -0
  38. package/bundled-types/scheduler.d.ts +2 -0
  39. package/bundled-types/storage.d.ts +2 -0
  40. package/bundled-types/test-entry.d.ts +21 -0
  41. package/bundled-types/types.d.ts +1 -0
  42. package/bundled-types/vite.d.ts +23 -0
  43. package/bundled-types/workflows.d.ts +14 -0
  44. package/bundled-types/workspace.d.ts +2 -0
  45. package/dist/__tests__/types-manager.test.d.ts +1 -0
  46. package/dist/__tests__/types-manager.test.js +85 -0
  47. package/dist/api/__tests__/client.test.d.ts +1 -0
  48. package/dist/api/__tests__/client.test.js +264 -0
  49. package/dist/api/client.d.ts +72 -0
  50. package/dist/api/client.js +144 -0
  51. package/dist/auth/__tests__/store.test.d.ts +1 -0
  52. package/dist/auth/__tests__/store.test.js +103 -0
  53. package/dist/auth/browser.d.ts +2 -0
  54. package/dist/auth/browser.js +7 -0
  55. package/dist/auth/store.d.ts +5 -0
  56. package/dist/auth/store.js +33 -0
  57. package/dist/commands/clone.d.ts +2 -0
  58. package/dist/commands/clone.js +90 -0
  59. package/dist/commands/deploy.d.ts +2 -0
  60. package/dist/commands/deploy.js +43 -0
  61. package/dist/commands/dev.d.ts +2 -0
  62. package/dist/commands/dev.js +188 -0
  63. package/dist/commands/init.d.ts +2 -0
  64. package/dist/commands/init.js +87 -0
  65. package/dist/commands/login.d.ts +2 -0
  66. package/dist/commands/login.js +32 -0
  67. package/dist/commands/logout.d.ts +2 -0
  68. package/dist/commands/logout.js +13 -0
  69. package/dist/commands/logs.d.ts +2 -0
  70. package/dist/commands/logs.js +166 -0
  71. package/dist/generated/bundled-types.d.ts +1 -0
  72. package/dist/generated/bundled-types.js +44 -0
  73. package/dist/generated/version.d.ts +1 -0
  74. package/dist/generated/version.js +2 -0
  75. package/dist/git/__tests__/credentials.test.d.ts +1 -0
  76. package/dist/git/__tests__/credentials.test.js +128 -0
  77. package/dist/git/auto-commit.d.ts +3 -0
  78. package/dist/git/auto-commit.js +209 -0
  79. package/dist/git/credentials.d.ts +15 -0
  80. package/dist/git/credentials.js +65 -0
  81. package/dist/index.d.ts +1 -0
  82. package/dist/index.js +31 -0
  83. package/dist/logs/tailer.d.ts +13 -0
  84. package/dist/logs/tailer.js +135 -0
  85. package/dist/template/manifest.d.ts +17 -0
  86. package/dist/template/manifest.js +102 -0
  87. package/dist/types-manager.d.ts +1 -0
  88. package/dist/types-manager.js +35 -0
  89. package/dist/types.d.ts +27 -0
  90. package/dist/types.js +1 -0
  91. package/dist/utils/__tests__/prompt.test.d.ts +1 -0
  92. package/dist/utils/__tests__/prompt.test.js +103 -0
  93. package/dist/utils/fs.d.ts +5 -0
  94. package/dist/utils/fs.js +23 -0
  95. package/dist/utils/prompt.d.ts +4 -0
  96. package/dist/utils/prompt.js +34 -0
  97. package/dist/utils/zip.d.ts +1 -0
  98. package/dist/utils/zip.js +17 -0
  99. package/package.json +66 -0
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Workflow Types - Shared types for native workflow engine
3
+ * DO NOT MODIFY THIS FILE - You may break the project functionality
4
+ */
5
+ import type { Env } from './core-utils';
6
+ import type { IntegrationClient } from './core-integrations';
7
+ export type NativeWorkflowStatus = 'pending' | 'running' | 'sleeping' | 'waiting' | 'paused' | 'completed' | 'failed' | 'cancelled' | 'timedOut';
8
+ export type NativeStepStatus = 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
9
+ export type NativeStepType = 'do' | 'sleep' | 'sleepUntil' | 'waitEvent';
10
+ export interface NativeWorkflowError {
11
+ code: string;
12
+ message: string;
13
+ stack?: string;
14
+ retryable: boolean;
15
+ }
16
+ export interface NativeStepAttempt {
17
+ attemptNumber: number;
18
+ startedAt: number;
19
+ completedAt?: number;
20
+ error?: NativeWorkflowError;
21
+ }
22
+ export interface NativeStepExecution {
23
+ id: string;
24
+ name: string;
25
+ type: NativeStepType;
26
+ status: NativeStepStatus;
27
+ input?: unknown;
28
+ output?: unknown;
29
+ error?: NativeWorkflowError;
30
+ attempts: NativeStepAttempt[];
31
+ maxRetries: number;
32
+ startedAt?: number;
33
+ completedAt?: number;
34
+ timeoutMs?: number;
35
+ sleepUntil?: number;
36
+ eventType?: string;
37
+ eventTimeoutAt?: number;
38
+ }
39
+ export interface NativeWorkflowInstance {
40
+ id: string;
41
+ workflowName: string;
42
+ status: NativeWorkflowStatus;
43
+ input: unknown;
44
+ output?: unknown;
45
+ error?: NativeWorkflowError;
46
+ createdAt: number;
47
+ startedAt?: number;
48
+ completedAt?: number;
49
+ steps: NativeStepExecution[];
50
+ currentStepId?: string;
51
+ config: NativeWorkflowConfig;
52
+ metadata?: Record<string, unknown>;
53
+ }
54
+ export interface NativeWorkflowConfig {
55
+ maxRetries: number;
56
+ retryBackoffMs: number;
57
+ stepTimeoutMs: number;
58
+ workflowTimeoutMs: number;
59
+ }
60
+ export declare const DEFAULT_WORKFLOW_CONFIG: NativeWorkflowConfig;
61
+ export interface NativeStepContext {
62
+ /** Unique instance ID for this workflow execution */
63
+ instanceId: string;
64
+ /** Input passed when workflow was started */
65
+ workflowInput: unknown;
66
+ /** Results from previous steps */
67
+ previousSteps: Record<string, {
68
+ output: unknown;
69
+ status: NativeStepStatus;
70
+ }>;
71
+ }
72
+ export interface WorkflowIndexEntry {
73
+ instanceId: string;
74
+ workflowName: string;
75
+ status: NativeWorkflowStatus;
76
+ createdAt: number;
77
+ completedAt?: number;
78
+ }
79
+ export interface ListWorkflowsOptions {
80
+ workflowName?: string;
81
+ status?: NativeWorkflowStatus;
82
+ limit?: number;
83
+ offset?: number;
84
+ }
85
+ export interface ExecuteStepRequest {
86
+ instanceId: string;
87
+ stepId: string;
88
+ stepName: string;
89
+ workflowName: string;
90
+ workflowInput: unknown;
91
+ previousSteps: Record<string, {
92
+ output: unknown;
93
+ status: NativeStepStatus;
94
+ }>;
95
+ }
96
+ export interface ExecuteStepResponse {
97
+ success: boolean;
98
+ output?: unknown;
99
+ error?: NativeWorkflowError;
100
+ }
101
+ export interface PendingEvent {
102
+ instanceId: string;
103
+ stepId: string;
104
+ eventType: string;
105
+ waitingSince: number;
106
+ timeoutAt?: number;
107
+ }
108
+ export interface ReceivedEvent {
109
+ type: string;
110
+ payload: unknown;
111
+ timestamp: number;
112
+ }
113
+ /**
114
+ * Result returned by a workflow execution
115
+ */
116
+ export interface WorkflowResult {
117
+ success: boolean;
118
+ [key: string]: unknown;
119
+ }
120
+ /**
121
+ * Possible states of a workflow instance
122
+ */
123
+ export type WorkflowStatus = 'queued' | 'running' | 'paused' | 'errored' | 'terminated' | 'complete' | 'waiting';
124
+ /**
125
+ * Information about a workflow instance
126
+ */
127
+ export interface WorkflowInstanceInfo {
128
+ id: string;
129
+ workflowName: string;
130
+ status: WorkflowStatus;
131
+ params?: Record<string, unknown>;
132
+ createdAt: number;
133
+ startedAt?: number;
134
+ completedAt?: number;
135
+ error?: string;
136
+ result?: WorkflowResult;
137
+ }
138
+ /**
139
+ * Interface for WorkflowInstance DO stub methods
140
+ * Used to type the DurableObjectStub without importing the class
141
+ */
142
+ export interface WorkflowInstanceStub {
143
+ create(workflowName: string, params: Record<string, unknown>, instanceId: string, config?: Partial<NativeWorkflowConfig>, metadata?: Record<string, unknown>): Promise<void>;
144
+ getStatus(): Promise<NativeWorkflowInstance | null>;
145
+ signal(eventType: string, payload: unknown): Promise<void>;
146
+ pause(): Promise<void>;
147
+ resume(): Promise<void>;
148
+ cancel(): Promise<void>;
149
+ }
150
+ /**
151
+ * Interface for WorkflowCoordinator DO stub methods
152
+ * Used to type the DurableObjectStub without importing the class
153
+ */
154
+ export interface WorkflowCoordinatorStub {
155
+ create(workflowName: string, params: Record<string, unknown>, config?: Partial<NativeWorkflowConfig>, metadata?: Record<string, unknown>): Promise<string>;
156
+ signal(instanceId: string, eventType: string, payload: unknown): Promise<void>;
157
+ getInstanceInfo(instanceId: string): Promise<WorkflowInstanceInfo | null>;
158
+ listInstances(options?: ListWorkflowsOptions): Promise<WorkflowInstanceInfo[]>;
159
+ updateIndex(instanceId: string, workflowName: string, status: NativeWorkflowStatus): Promise<void>;
160
+ pause(instanceId: string): Promise<void>;
161
+ resume(instanceId: string): Promise<void>;
162
+ cancel(instanceId: string): Promise<void>;
163
+ }
164
+ /**
165
+ * Definition for a workflow handler
166
+ */
167
+ export interface WorkflowDefinition<TParams = unknown, TResult = unknown> {
168
+ /** Unique name for this workflow (kebab-case, e.g., "order-fulfillment") */
169
+ name: string;
170
+ /** Human-readable description of what this workflow does */
171
+ description?: string;
172
+ /** The workflow handler function */
173
+ handler: (ctx: WorkflowContext<TParams>) => Promise<TResult>;
174
+ /** Whether the workflow is enabled (default: true) */
175
+ enabled?: boolean;
176
+ }
177
+ /**
178
+ * Context passed to workflow handlers
179
+ */
180
+ export interface WorkflowContext<TParams = unknown> {
181
+ /** Environment bindings */
182
+ env: Env;
183
+ /** Unique instance ID for this workflow execution */
184
+ instanceId: string;
185
+ /** Parameters passed when workflow was started */
186
+ params: TParams;
187
+ /** Step utilities for durable execution */
188
+ step: WorkflowStepUtilities;
189
+ /** Integration client for external service calls */
190
+ integrations: IntegrationClient;
191
+ /** Logger for structured workflow logging */
192
+ logger: WorkflowLogger;
193
+ }
194
+ /**
195
+ * Step utilities for durable workflow execution
196
+ */
197
+ export interface WorkflowStepUtilities {
198
+ /** Execute a step with automatic retry and persistence */
199
+ do<T>(name: string, fn: () => Promise<T>): Promise<T>;
200
+ do<T>(name: string, options: StepOptions, fn: () => Promise<T>): Promise<T>;
201
+ /** Sleep for a duration (e.g., '5 minutes', '1 hour', '24 hours') */
202
+ sleep(name: string, duration: string): Promise<void>;
203
+ /** Sleep until a specific timestamp */
204
+ sleepUntil(name: string, timestamp: Date): Promise<void>;
205
+ /** Wait for an external event */
206
+ waitForEvent<T = unknown>(name: string, options?: WaitEventOptions): Promise<T>;
207
+ }
208
+ /**
209
+ * Options for step execution
210
+ */
211
+ export interface StepOptions {
212
+ retries?: {
213
+ limit: number;
214
+ delay: string;
215
+ backoff?: 'constant' | 'linear' | 'exponential';
216
+ };
217
+ timeout?: string;
218
+ }
219
+ /**
220
+ * Options for waitForEvent
221
+ */
222
+ export interface WaitEventOptions {
223
+ type?: string;
224
+ timeout?: string;
225
+ }
226
+ /**
227
+ * Logger interface for workflow execution
228
+ */
229
+ export interface WorkflowLogger {
230
+ info(message: string, data?: Record<string, unknown>): void;
231
+ warn(message: string, data?: Record<string, unknown>): void;
232
+ error(message: string, data?: Record<string, unknown>): void;
233
+ }
234
+ /**
235
+ * State of a registered workflow
236
+ */
237
+ export interface WorkflowState {
238
+ name: string;
239
+ description?: string;
240
+ enabled: boolean;
241
+ activeInstances: number;
242
+ totalRuns: number;
243
+ lastRun: number | null;
244
+ lastError?: string;
245
+ }
246
+ /**
247
+ * Response from workflow status API
248
+ */
249
+ export interface WorkflowStatusResponse {
250
+ workflows: WorkflowState[];
251
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Core Workflow Framework - Public API
3
+ * DO NOT MODIFY THIS FILE - You may break the project functionality
4
+ *
5
+ * This module provides the public API for workflow operations.
6
+ * Uses native DO-based engine (WorkflowCoordinator/WorkflowInstance).
7
+ *
8
+ * Implementation details:
9
+ * - Types are defined in core-workflow-types.ts
10
+ * - Native DO-based implementation is in core-workflow-instance.ts and core-workflow-coordinator.ts
11
+ */
12
+ import type { Env } from './core-utils';
13
+ export type { WorkflowResult, WorkflowStatus, WorkflowInstanceInfo, WorkflowDefinition, WorkflowContext, WorkflowStepUtilities, StepOptions, WaitEventOptions, WorkflowLogger, WorkflowState, WorkflowStatusResponse, } from './core-workflow-types';
14
+ import type { WorkflowInstanceInfo } from './core-workflow-types';
15
+ /**
16
+ * Trigger a workflow by name with the given parameters.
17
+ * This is a convenience function that creates a new workflow instance.
18
+ *
19
+ * @param env - The environment bindings
20
+ * @param workflowName - The name of the workflow to trigger (must be defined in workflows.ts)
21
+ * @param params - Parameters to pass to the workflow
22
+ * @returns The instance ID of the created workflow
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const instanceId = await triggerWorkflow(ctx.env, 'order-fulfillment', {
27
+ * orderId: '12345',
28
+ * customerId: 'cust-001',
29
+ * });
30
+ * ```
31
+ */
32
+ export declare function triggerWorkflow(env: Env, workflowName: string, params?: Record<string, unknown>): Promise<string>;
33
+ /**
34
+ * Send an event to a running workflow instance.
35
+ * Use this to trigger workflows waiting on `step.waitForEvent()`.
36
+ *
37
+ * @param env - The environment bindings
38
+ * @param instanceId - The workflow instance ID to send event to
39
+ * @param eventType - The event type name (must match the name in waitForEvent)
40
+ * @param payload - Data to send with the event
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * // In an API endpoint handler
45
+ * await sendWorkflowEvent(c.env, instanceId, 'approval-response', {
46
+ * approved: true,
47
+ * approvedBy: 'user123',
48
+ * });
49
+ * ```
50
+ */
51
+ export declare function sendWorkflowEvent(env: Env, instanceId: string, eventType: string, payload?: Record<string, unknown>): Promise<void>;
52
+ /**
53
+ * Get the current status of a workflow instance.
54
+ *
55
+ * @param env - The environment bindings
56
+ * @param instanceId - The workflow instance ID
57
+ * @returns The workflow instance info or null if not found
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const status = await getWorkflowStatus(c.env, instanceId);
62
+ * if (status?.status === 'completed') {
63
+ * console.log('Workflow completed:', status.result);
64
+ * }
65
+ * ```
66
+ */
67
+ export declare function getWorkflowStatus(env: Env, instanceId: string): Promise<WorkflowInstanceInfo | null>;
68
+ import type { Hono } from 'hono';
69
+ /**
70
+ * Mount workflow routes on the Hono app
71
+ * Provides internal API for workflow management
72
+ */
73
+ export declare function workflowRoutes(app: Hono<{
74
+ Bindings: Env;
75
+ }>): void;