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.
- package/LICENSE +21 -0
- package/README.md +134 -0
- package/bin/runwork.js +2 -0
- package/bundled-types/agents.d.ts +3 -0
- package/bundled-types/ai.d.ts +2 -0
- package/bundled-types/app-registry.d.ts +74 -0
- package/bundled-types/channels.d.ts +2 -0
- package/bundled-types/components.d.ts +1 -0
- package/bundled-types/core-agent.d.ts +265 -0
- package/bundled-types/core-ai.d.ts +170 -0
- package/bundled-types/core-base-agent.d.ts +89 -0
- package/bundled-types/core-channels.d.ts +42 -0
- package/bundled-types/core-components.d.ts +21 -0
- package/bundled-types/core-endpoints.d.ts +198 -0
- package/bundled-types/core-entities.d.ts +276 -0
- package/bundled-types/core-entity-do.d.ts +119 -0
- package/bundled-types/core-events.d.ts +52 -0
- package/bundled-types/core-file-storage.d.ts +216 -0
- package/bundled-types/core-integration-entities.d.ts +147 -0
- package/bundled-types/core-integrations.d.ts +143 -0
- package/bundled-types/core-routes.d.ts +33 -0
- package/bundled-types/core-scheduler.d.ts +180 -0
- package/bundled-types/core-utils.d.ts +85 -0
- package/bundled-types/core-workflow-cloudflare.d.ts +85 -0
- package/bundled-types/core-workflow-config.d.ts +18 -0
- package/bundled-types/core-workflow-coordinator.d.ts +78 -0
- package/bundled-types/core-workflow-instance.d.ts +82 -0
- package/bundled-types/core-workflow-types.d.ts +251 -0
- package/bundled-types/core-workflows.d.ts +75 -0
- package/bundled-types/core-workspace.d.ts +454 -0
- package/bundled-types/create-app.d.ts +57 -0
- package/bundled-types/endpoints.d.ts +2 -0
- package/bundled-types/entities.d.ts +5 -0
- package/bundled-types/events.d.ts +2 -0
- package/bundled-types/index.d.ts +19 -0
- package/bundled-types/integrations.d.ts +2 -0
- package/bundled-types/routes.d.ts +2 -0
- package/bundled-types/scheduler.d.ts +2 -0
- package/bundled-types/storage.d.ts +2 -0
- package/bundled-types/test-entry.d.ts +21 -0
- package/bundled-types/types.d.ts +1 -0
- package/bundled-types/vite.d.ts +23 -0
- package/bundled-types/workflows.d.ts +14 -0
- package/bundled-types/workspace.d.ts +2 -0
- package/dist/__tests__/types-manager.test.d.ts +1 -0
- package/dist/__tests__/types-manager.test.js +85 -0
- package/dist/api/__tests__/client.test.d.ts +1 -0
- package/dist/api/__tests__/client.test.js +264 -0
- package/dist/api/client.d.ts +72 -0
- package/dist/api/client.js +144 -0
- package/dist/auth/__tests__/store.test.d.ts +1 -0
- package/dist/auth/__tests__/store.test.js +103 -0
- package/dist/auth/browser.d.ts +2 -0
- package/dist/auth/browser.js +7 -0
- package/dist/auth/store.d.ts +5 -0
- package/dist/auth/store.js +33 -0
- package/dist/commands/clone.d.ts +2 -0
- package/dist/commands/clone.js +90 -0
- package/dist/commands/deploy.d.ts +2 -0
- package/dist/commands/deploy.js +43 -0
- package/dist/commands/dev.d.ts +2 -0
- package/dist/commands/dev.js +188 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +87 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.js +32 -0
- package/dist/commands/logout.d.ts +2 -0
- package/dist/commands/logout.js +13 -0
- package/dist/commands/logs.d.ts +2 -0
- package/dist/commands/logs.js +166 -0
- package/dist/generated/bundled-types.d.ts +1 -0
- package/dist/generated/bundled-types.js +44 -0
- package/dist/generated/version.d.ts +1 -0
- package/dist/generated/version.js +2 -0
- package/dist/git/__tests__/credentials.test.d.ts +1 -0
- package/dist/git/__tests__/credentials.test.js +128 -0
- package/dist/git/auto-commit.d.ts +3 -0
- package/dist/git/auto-commit.js +209 -0
- package/dist/git/credentials.d.ts +15 -0
- package/dist/git/credentials.js +65 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +31 -0
- package/dist/logs/tailer.d.ts +13 -0
- package/dist/logs/tailer.js +135 -0
- package/dist/template/manifest.d.ts +17 -0
- package/dist/template/manifest.js +102 -0
- package/dist/types-manager.d.ts +1 -0
- package/dist/types-manager.js +35 -0
- package/dist/types.d.ts +27 -0
- package/dist/types.js +1 -0
- package/dist/utils/__tests__/prompt.test.d.ts +1 -0
- package/dist/utils/__tests__/prompt.test.js +103 -0
- package/dist/utils/fs.d.ts +5 -0
- package/dist/utils/fs.js +23 -0
- package/dist/utils/prompt.d.ts +4 -0
- package/dist/utils/prompt.js +34 -0
- package/dist/utils/zip.d.ts +1 -0
- package/dist/utils/zip.js +17 -0
- package/package.json +66 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Platform Routes
|
|
3
|
+
* DO NOT MODIFY THIS FILE - You may break the project functionality
|
|
4
|
+
*
|
|
5
|
+
* This module orchestrates core API routes for platform features.
|
|
6
|
+
* Each feature exposes its own routes in its respective core-* file.
|
|
7
|
+
* These routes are mounted before user-defined routes in index.ts.
|
|
8
|
+
*/
|
|
9
|
+
import { type Env } from './core-utils';
|
|
10
|
+
import { Hono } from 'hono';
|
|
11
|
+
export interface ClientErrorReport {
|
|
12
|
+
message: string;
|
|
13
|
+
url: string;
|
|
14
|
+
userAgent?: string;
|
|
15
|
+
timestamp: string;
|
|
16
|
+
stack?: string;
|
|
17
|
+
componentStack?: string;
|
|
18
|
+
errorBoundary?: boolean;
|
|
19
|
+
errorBoundaryProps?: Record<string, unknown>;
|
|
20
|
+
source?: string;
|
|
21
|
+
lineno?: number;
|
|
22
|
+
colno?: number;
|
|
23
|
+
error?: unknown;
|
|
24
|
+
level?: 'error' | 'warning' | 'info';
|
|
25
|
+
category?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Mount all core platform routes on the Hono app
|
|
29
|
+
* Called from index.ts before user-defined routes
|
|
30
|
+
*/
|
|
31
|
+
export declare function setupRoutes(): Hono<{
|
|
32
|
+
Bindings: Env;
|
|
33
|
+
}, import("hono/types").BlankSchema, "/">;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Scheduled Jobs Framework
|
|
3
|
+
* DO NOT MODIFY THIS FILE - You may break the project functionality
|
|
4
|
+
*
|
|
5
|
+
* This module provides the infrastructure for scheduled background jobs
|
|
6
|
+
* using a dedicated Cloudflare Durable Object (SchedulerDO).
|
|
7
|
+
*
|
|
8
|
+
* SchedulerDO is a standalone Durable Object that:
|
|
9
|
+
* - Owns its own storage for job metadata and history
|
|
10
|
+
* - Handles alarm-based job scheduling
|
|
11
|
+
* - Provides job management (pause, resume, trigger)
|
|
12
|
+
*
|
|
13
|
+
* Job handlers receive JobContext which includes env for entity access.
|
|
14
|
+
*/
|
|
15
|
+
import { DurableObject } from 'cloudflare:workers';
|
|
16
|
+
import { type Env } from './core-utils';
|
|
17
|
+
export interface ScheduledJob {
|
|
18
|
+
/** Unique name for this job (kebab-case, e.g., "daily-cleanup") */
|
|
19
|
+
name: string;
|
|
20
|
+
/** Cron expression (e.g., "0 0 * * *" for daily at midnight UTC) */
|
|
21
|
+
schedule: string;
|
|
22
|
+
/** Human-readable description of what this job does */
|
|
23
|
+
description?: string;
|
|
24
|
+
/** The handler function to execute */
|
|
25
|
+
handler: (ctx: JobContext) => Promise<JobResult>;
|
|
26
|
+
/** Whether the job is enabled (default: true) */
|
|
27
|
+
enabled?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface JobContext {
|
|
30
|
+
/** Environment bindings */
|
|
31
|
+
env: Env;
|
|
32
|
+
/** Name of the job being executed */
|
|
33
|
+
jobName: string;
|
|
34
|
+
/** Unique ID for this execution run */
|
|
35
|
+
runId: string;
|
|
36
|
+
/** When this job was scheduled to run */
|
|
37
|
+
scheduledAt: Date;
|
|
38
|
+
/** Logger for structured job logging */
|
|
39
|
+
logger: JobLogger;
|
|
40
|
+
}
|
|
41
|
+
export interface JobResult {
|
|
42
|
+
/** Whether the job completed successfully */
|
|
43
|
+
success: boolean;
|
|
44
|
+
/** Additional result data (varies by job) */
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
export interface JobLogger {
|
|
48
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
49
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
50
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
51
|
+
}
|
|
52
|
+
export interface JobRunRecord {
|
|
53
|
+
id: string;
|
|
54
|
+
jobName: string;
|
|
55
|
+
status: 'running' | 'completed' | 'failed';
|
|
56
|
+
scheduledAt: number;
|
|
57
|
+
startedAt: number;
|
|
58
|
+
completedAt?: number;
|
|
59
|
+
result?: JobResult;
|
|
60
|
+
error?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ScheduleState {
|
|
63
|
+
name: string;
|
|
64
|
+
schedule: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
enabled: boolean;
|
|
67
|
+
lastRun: number | null;
|
|
68
|
+
nextRun: number;
|
|
69
|
+
lastError?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface SchedulerRegistry {
|
|
72
|
+
schedules: Record<string, ScheduleState>;
|
|
73
|
+
initialized: boolean;
|
|
74
|
+
}
|
|
75
|
+
export interface ScheduleStatusResponse {
|
|
76
|
+
schedules: Array<{
|
|
77
|
+
name: string;
|
|
78
|
+
schedule: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
enabled: boolean;
|
|
81
|
+
lastRun: number | null;
|
|
82
|
+
nextRun: number;
|
|
83
|
+
status: 'active' | 'paused' | 'error';
|
|
84
|
+
lastError?: string;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
interface CronParts {
|
|
88
|
+
minute: number[];
|
|
89
|
+
hour: number[];
|
|
90
|
+
dayOfMonth: number[];
|
|
91
|
+
month: number[];
|
|
92
|
+
dayOfWeek: number[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Parse a cron expression into its component parts
|
|
96
|
+
* Supports standard 5-field cron: minute hour day-of-month month day-of-week
|
|
97
|
+
*/
|
|
98
|
+
export declare function parseCronExpression(expr: string): CronParts;
|
|
99
|
+
/**
|
|
100
|
+
* Calculate the next run time for a cron expression after the given date
|
|
101
|
+
*/
|
|
102
|
+
export declare function calculateNextRun(cronExpression: string, after?: Date): Date;
|
|
103
|
+
/**
|
|
104
|
+
* SchedulerDO - Standalone Durable Object for job scheduling
|
|
105
|
+
*
|
|
106
|
+
* This is the actual Durable Object class that handles all scheduling.
|
|
107
|
+
* It owns its own storage for job metadata and execution history.
|
|
108
|
+
*
|
|
109
|
+
* Job handlers receive env so they can access entities and other services.
|
|
110
|
+
*/
|
|
111
|
+
export declare class SchedulerDO extends DurableObject<Env> {
|
|
112
|
+
private jobs;
|
|
113
|
+
private initialized;
|
|
114
|
+
constructor(ctx: DurableObjectState, env: Env);
|
|
115
|
+
/**
|
|
116
|
+
* Ensure the scheduler is initialized (lazy initialization for DO recovery)
|
|
117
|
+
* This is needed because DOs can be evicted and recreated, losing in-memory state.
|
|
118
|
+
* Also handles HMR: if getRegisteredSchedules() has changed since last init, re-sync.
|
|
119
|
+
*/
|
|
120
|
+
private ensureInitialized;
|
|
121
|
+
/**
|
|
122
|
+
* Alarm handler - processes scheduled jobs
|
|
123
|
+
* Called by Cloudflare when an alarm fires
|
|
124
|
+
*/
|
|
125
|
+
alarm(): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Initialize the job scheduler with job definitions.
|
|
128
|
+
* Can be called again after HMR to sync new/changed job definitions.
|
|
129
|
+
*/
|
|
130
|
+
initializeJobScheduler(jobs: ScheduledJob[]): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Handle alarm - execute due jobs
|
|
133
|
+
*/
|
|
134
|
+
private handleAlarm;
|
|
135
|
+
/**
|
|
136
|
+
* Execute a single job
|
|
137
|
+
*/
|
|
138
|
+
private executeJob;
|
|
139
|
+
/**
|
|
140
|
+
* Store a job execution record in history
|
|
141
|
+
*/
|
|
142
|
+
private storeHistoryRecord;
|
|
143
|
+
/**
|
|
144
|
+
* Schedule the next alarm for the earliest due job
|
|
145
|
+
*/
|
|
146
|
+
private scheduleNextAlarm;
|
|
147
|
+
/**
|
|
148
|
+
* Get status of all schedules
|
|
149
|
+
*/
|
|
150
|
+
getScheduleStatus(): Promise<ScheduleStatusResponse>;
|
|
151
|
+
/**
|
|
152
|
+
* Get job execution history
|
|
153
|
+
*/
|
|
154
|
+
getJobHistory(jobName?: string, limit?: number): Promise<JobRunRecord[]>;
|
|
155
|
+
/**
|
|
156
|
+
* Manually trigger a job (for testing/debugging)
|
|
157
|
+
*/
|
|
158
|
+
triggerJob(jobName: string): Promise<JobResult>;
|
|
159
|
+
/**
|
|
160
|
+
* Pause a scheduled job
|
|
161
|
+
*/
|
|
162
|
+
pauseJob(jobName: string): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Resume a paused job
|
|
165
|
+
*/
|
|
166
|
+
resumeJob(jobName: string): Promise<void>;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Initialize the job scheduler with the given jobs.
|
|
170
|
+
*/
|
|
171
|
+
export declare function initializeScheduler(env: Env, jobs: ScheduledJob[]): Promise<void>;
|
|
172
|
+
import type { Hono } from 'hono';
|
|
173
|
+
/**
|
|
174
|
+
* Mount scheduler routes on the Hono app
|
|
175
|
+
* Provides internal API for schedule management
|
|
176
|
+
*/
|
|
177
|
+
export declare function schedulerRoutes(app: Hono<{
|
|
178
|
+
Bindings: Env;
|
|
179
|
+
}>): void;
|
|
180
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Utilities
|
|
3
|
+
* DO NOT MODIFY THIS FILE - You may break the project functionality
|
|
4
|
+
*
|
|
5
|
+
* This module provides:
|
|
6
|
+
* - Env type: Environment bindings for Cloudflare Workers
|
|
7
|
+
* - API helpers: Response utilities for Hono routes
|
|
8
|
+
*
|
|
9
|
+
* Entity System: See core-entities.ts
|
|
10
|
+
* Workspace Context: See core-workspace.ts
|
|
11
|
+
* Scheduler: See core-scheduler.ts
|
|
12
|
+
*/
|
|
13
|
+
import type { Context } from 'hono';
|
|
14
|
+
import type { EntityDO } from './core-entity-do';
|
|
15
|
+
import type { SchedulerDO } from './core-scheduler';
|
|
16
|
+
import type { BaseAgent } from './core-base-agent';
|
|
17
|
+
/**
|
|
18
|
+
* Environment bindings for Cloudflare Workers
|
|
19
|
+
*/
|
|
20
|
+
export interface Env {
|
|
21
|
+
EntityDO: DurableObjectNamespace<EntityDO>;
|
|
22
|
+
SchedulerDO: DurableObjectNamespace<SchedulerDO>;
|
|
23
|
+
BaseAgent?: DurableObjectNamespace<BaseAgent>;
|
|
24
|
+
WorkspaceObject?: DurableObjectNamespace;
|
|
25
|
+
WorkflowInstance: DurableObjectNamespace;
|
|
26
|
+
WorkflowCoordinator: DurableObjectNamespace;
|
|
27
|
+
BUCKET?: R2Bucket;
|
|
28
|
+
WORKSPACE_ID?: string;
|
|
29
|
+
APP_ID?: string;
|
|
30
|
+
APP_NAME?: string;
|
|
31
|
+
WORKSPACE_API_URL?: string;
|
|
32
|
+
WORKSPACE_API_BASE_URL?: string;
|
|
33
|
+
WORKSPACE_API_KEY?: string;
|
|
34
|
+
DEPLOYMENT_MODE?: 'preview' | 'production';
|
|
35
|
+
VITE_DEPLOYMENT_MODE?: 'preview' | 'production';
|
|
36
|
+
RUNWORK_AI_PROXY_URL?: string;
|
|
37
|
+
RUNWORK_PROXY_TOKEN?: string;
|
|
38
|
+
INTEGRATIONS_PROXY_URL?: string;
|
|
39
|
+
ALLOWED_ORIGINS?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Return a successful JSON response.
|
|
43
|
+
* Returns the data directly as the response body with 200 status.
|
|
44
|
+
*/
|
|
45
|
+
export declare const ok: <T>(c: Context, data: T) => Response & import("hono").TypedResponse<{
|
|
46
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
47
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">;
|
|
48
|
+
/**
|
|
49
|
+
* Return a 400 Bad Request response
|
|
50
|
+
* Automatically logs the error for debugging in production logs
|
|
51
|
+
*/
|
|
52
|
+
export declare const bad: (c: Context, error: string) => Response & import("hono").TypedResponse<{
|
|
53
|
+
error: string;
|
|
54
|
+
}, 400, "json">;
|
|
55
|
+
/**
|
|
56
|
+
* Return a 404 Not Found response
|
|
57
|
+
* Automatically logs the error for debugging in production logs
|
|
58
|
+
*/
|
|
59
|
+
export declare const notFound: (c: Context, error?: string) => Response & import("hono").TypedResponse<{
|
|
60
|
+
error: string;
|
|
61
|
+
}, 404, "json">;
|
|
62
|
+
/**
|
|
63
|
+
* Type guard for non-empty strings
|
|
64
|
+
*/
|
|
65
|
+
export declare const isStr: (s: unknown) => s is string;
|
|
66
|
+
/**
|
|
67
|
+
* Safely clone a value for Durable Object storage.
|
|
68
|
+
* Strips non-serializable references (R2Bucket, D1Database, DO stubs, etc.)
|
|
69
|
+
* that would cause structured clone to fail in ctx.storage.put().
|
|
70
|
+
*/
|
|
71
|
+
export declare function safeClone<T>(value: T, fallback?: T): T;
|
|
72
|
+
export declare function platformFetch(env: Env, url: string | URL, init?: RequestInit): Promise<Response>;
|
|
73
|
+
/**
|
|
74
|
+
* Workspace API fetch - routes workspace service requests through WorkspaceObject DO
|
|
75
|
+
* for production WfP workers, avoiding 522 recursive invocation errors.
|
|
76
|
+
*
|
|
77
|
+
* Workers for Platforms workers cannot HTTP-fetch back to their dispatcher domain.
|
|
78
|
+
* This routes through the WorkspaceObject DO binding in production, and falls back
|
|
79
|
+
* to standard HTTP with x-workspace-key auth header in preview/sandbox.
|
|
80
|
+
*
|
|
81
|
+
* @param env - Environment with workspace bindings
|
|
82
|
+
* @param path - Workspace API sub-path (e.g., '/ingest-event')
|
|
83
|
+
* @param init - Standard fetch options
|
|
84
|
+
*/
|
|
85
|
+
export declare function workspaceApiFetch(env: Pick<Env, 'WORKSPACE_API_URL' | 'WORKSPACE_API_KEY' | 'WORKSPACE_ID' | 'DEPLOYMENT_MODE' | 'WorkspaceObject'>, path: string, init?: RequestInit): Promise<Response>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Workflows Implementation
|
|
3
|
+
* DO NOT MODIFY THIS FILE - You may break the project functionality
|
|
4
|
+
*
|
|
5
|
+
* @deprecated This module is DEPRECATED and kept for reference only.
|
|
6
|
+
* Cloudflare Workflows do not support Workers for Platforms, so this code path
|
|
7
|
+
* is no longer used. The native DO-based workflow engine is used instead.
|
|
8
|
+
*
|
|
9
|
+
* For active workflow implementation, see:
|
|
10
|
+
* - core-workflow-instance.ts (WorkflowInstance DO)
|
|
11
|
+
* - core-workflow-coordinator.ts (WorkflowCoordinator DO)
|
|
12
|
+
* - core-workflows.ts (public API)
|
|
13
|
+
*/
|
|
14
|
+
import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent } from 'cloudflare:workers';
|
|
15
|
+
import type { Env } from './core-utils';
|
|
16
|
+
import type { WorkflowResult, WorkflowStatus, WorkflowInstanceInfo, WorkflowDefinition, WorkflowLogger, WorkflowStatusResponse } from './core-workflow-types';
|
|
17
|
+
type WorkflowParams = {
|
|
18
|
+
workflowName: string;
|
|
19
|
+
params: Record<string, unknown>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* WorkflowRunner - Single entrypoint for all user-defined workflows
|
|
23
|
+
*
|
|
24
|
+
* This class extends Cloudflare's WorkflowEntrypoint and dispatches to
|
|
25
|
+
* the appropriate workflow handler based on the workflowName parameter.
|
|
26
|
+
*/
|
|
27
|
+
export declare class WorkflowRunner extends WorkflowEntrypoint<Env, WorkflowParams> {
|
|
28
|
+
run(event: WorkflowEvent<WorkflowParams>, step: WorkflowStep): Promise<WorkflowResult>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* WorkflowManager - Manages workflow state within a Durable Object
|
|
32
|
+
*
|
|
33
|
+
* Note: Actual workflow execution is handled by Cloudflare Workflows.
|
|
34
|
+
* This manager tracks metadata and provides status APIs.
|
|
35
|
+
*/
|
|
36
|
+
export declare class WorkflowManager {
|
|
37
|
+
private ctx;
|
|
38
|
+
private env;
|
|
39
|
+
private initialized;
|
|
40
|
+
constructor(ctx: DurableObjectState, env: Env);
|
|
41
|
+
/**
|
|
42
|
+
* Initialize the workflow manager with workflow definitions
|
|
43
|
+
*/
|
|
44
|
+
initialize(workflows: WorkflowDefinition[]): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Record a workflow instance creation
|
|
47
|
+
*/
|
|
48
|
+
recordInstanceCreated(instanceId: string, workflowName: string, params: Record<string, unknown>): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Update instance status
|
|
51
|
+
*/
|
|
52
|
+
updateInstanceStatus(instanceId: string, status: WorkflowStatus, result?: WorkflowResult, error?: string): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Get instance info
|
|
55
|
+
*/
|
|
56
|
+
getInstance(instanceId: string): Promise<WorkflowInstanceInfo | null>;
|
|
57
|
+
/**
|
|
58
|
+
* List instances with optional filters
|
|
59
|
+
*/
|
|
60
|
+
listInstances(options?: {
|
|
61
|
+
workflowName?: string;
|
|
62
|
+
status?: WorkflowStatus;
|
|
63
|
+
limit?: number;
|
|
64
|
+
}): Promise<WorkflowInstanceInfo[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Get status of all workflows
|
|
67
|
+
*/
|
|
68
|
+
getStatus(): Promise<WorkflowStatusResponse>;
|
|
69
|
+
/**
|
|
70
|
+
* Send an event to a workflow instance.
|
|
71
|
+
* Note: This stores the event for the workflow to pick up. The actual
|
|
72
|
+
* event delivery depends on how the workflow binding is configured.
|
|
73
|
+
*/
|
|
74
|
+
sendEvent(instanceId: string, eventType: string, payload: Record<string, unknown>): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the workflow manager instance for a DO
|
|
78
|
+
* Used internally by workflow Durable Objects
|
|
79
|
+
*/
|
|
80
|
+
export declare function getWorkflowManager(ctx: DurableObjectState, env: Env): WorkflowManager;
|
|
81
|
+
/**
|
|
82
|
+
* Create a workflow logger instance
|
|
83
|
+
*/
|
|
84
|
+
export declare function createWorkflowLogger(workflowName: string, instanceId: string): WorkflowLogger;
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Configuration
|
|
3
|
+
* DO NOT MODIFY THIS FILE - You may break the project functionality
|
|
4
|
+
*
|
|
5
|
+
* This platform uses native DO-based workflows exclusively.
|
|
6
|
+
* Cloudflare Workflows mode was removed because CF Workflows
|
|
7
|
+
* do not support Workers for Platforms.
|
|
8
|
+
*
|
|
9
|
+
* For workflow implementation, see:
|
|
10
|
+
* - core-workflow-instance.ts (WorkflowInstance DO)
|
|
11
|
+
* - core-workflow-coordinator.ts (WorkflowCoordinator DO)
|
|
12
|
+
* - core-workflows.ts (public API)
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Workflow infrastructure mode - always 'native'.
|
|
16
|
+
* Kept for backward compatibility.
|
|
17
|
+
*/
|
|
18
|
+
export declare const WORKFLOW_INFRA_MODE: "native";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WorkflowCoordinator Durable Object - Native Workflow Engine
|
|
3
|
+
* DO NOT MODIFY THIS FILE - You may break the project functionality
|
|
4
|
+
*
|
|
5
|
+
* Singleton coordinator that manages workflow instances.
|
|
6
|
+
* - Creates WorkflowInstance DOs
|
|
7
|
+
* - Maintains an index for querying workflows
|
|
8
|
+
* - Routes signals to correct instances
|
|
9
|
+
*/
|
|
10
|
+
import { DurableObject } from 'cloudflare:workers';
|
|
11
|
+
import type { NativeWorkflowStatus, NativeWorkflowConfig, ListWorkflowsOptions, WorkflowInstanceInfo, WorkflowInstanceStub } from './core-workflow-types';
|
|
12
|
+
import { type Env } from './core-utils';
|
|
13
|
+
/**
|
|
14
|
+
* WorkflowCoordinator Durable Object
|
|
15
|
+
*
|
|
16
|
+
* Acts as the central point for workflow management in native mode.
|
|
17
|
+
* Similar to WorkflowManager but creates actual DO instances instead
|
|
18
|
+
* of relying on Cloudflare Workflows.
|
|
19
|
+
*/
|
|
20
|
+
export declare class WorkflowCoordinator extends DurableObject<Env> {
|
|
21
|
+
private index;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new workflow instance
|
|
24
|
+
*/
|
|
25
|
+
create(workflowName: string, params: Record<string, unknown>, config?: Partial<NativeWorkflowConfig>, metadata?: Record<string, unknown>): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Get a workflow instance stub
|
|
28
|
+
*/
|
|
29
|
+
getInstance(instanceId: string): WorkflowInstanceStub;
|
|
30
|
+
/**
|
|
31
|
+
* Get workflow instance info (combines index with instance state)
|
|
32
|
+
*/
|
|
33
|
+
getInstanceInfo(instanceId: string): Promise<WorkflowInstanceInfo | null>;
|
|
34
|
+
/**
|
|
35
|
+
* List workflow instances with optional filters
|
|
36
|
+
*/
|
|
37
|
+
listInstances(options?: ListWorkflowsOptions): Promise<WorkflowInstanceInfo[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Send a signal/event to a workflow instance
|
|
40
|
+
*/
|
|
41
|
+
signal(instanceId: string, eventType: string, payload: unknown): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Pause a workflow instance
|
|
44
|
+
*/
|
|
45
|
+
pause(instanceId: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Resume a paused workflow instance
|
|
48
|
+
*/
|
|
49
|
+
resume(instanceId: string): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Cancel a workflow instance
|
|
52
|
+
*/
|
|
53
|
+
cancel(instanceId: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Update the index when a workflow instance changes status
|
|
56
|
+
* Called by WorkflowInstance DOs
|
|
57
|
+
*/
|
|
58
|
+
updateIndex(instanceId: string, workflowName: string, status: NativeWorkflowStatus): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Get workflow statistics
|
|
61
|
+
*/
|
|
62
|
+
getStats(): Promise<{
|
|
63
|
+
total: number;
|
|
64
|
+
byStatus: Record<string, number>;
|
|
65
|
+
byWorkflow: Record<string, number>;
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Clean up completed/old workflow entries
|
|
69
|
+
* Should be called periodically to prevent index bloat
|
|
70
|
+
*/
|
|
71
|
+
cleanup(options?: {
|
|
72
|
+
olderThanMs?: number;
|
|
73
|
+
keepCompleted?: boolean;
|
|
74
|
+
maxEntries?: number;
|
|
75
|
+
}): Promise<number>;
|
|
76
|
+
private ensureIndexLoaded;
|
|
77
|
+
private persistIndex;
|
|
78
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WorkflowInstance Durable Object - Native Workflow Engine
|
|
3
|
+
* DO NOT MODIFY THIS FILE - You may break the project functionality
|
|
4
|
+
*
|
|
5
|
+
* One instance per workflow execution. Uses alarm-based execution
|
|
6
|
+
* to bypass the 30-second CPU limit and provide durability.
|
|
7
|
+
*/
|
|
8
|
+
import { DurableObject } from 'cloudflare:workers';
|
|
9
|
+
import type { NativeWorkflowInstance, NativeWorkflowConfig } from './core-workflow-types';
|
|
10
|
+
import type { StepOptions, WaitEventOptions } from './core-workflows';
|
|
11
|
+
import { type Env } from './core-utils';
|
|
12
|
+
/**
|
|
13
|
+
* WorkflowInstance Durable Object
|
|
14
|
+
*
|
|
15
|
+
* Manages the execution of a single workflow instance.
|
|
16
|
+
* Uses alarm chaining for step execution to bypass CPU limits.
|
|
17
|
+
*/
|
|
18
|
+
export declare class WorkflowInstanceDO extends DurableObject<Env> {
|
|
19
|
+
private instance;
|
|
20
|
+
private definition;
|
|
21
|
+
private stepCounter;
|
|
22
|
+
/**
|
|
23
|
+
* Create and start a new workflow instance
|
|
24
|
+
*/
|
|
25
|
+
create(workflowName: string, input: unknown, instanceId: string, config?: Partial<NativeWorkflowConfig>, metadata?: Record<string, unknown>): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Get current workflow status
|
|
28
|
+
*/
|
|
29
|
+
getStatus(): Promise<NativeWorkflowInstance | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Signal the workflow with an event (for waitForEvent steps)
|
|
32
|
+
*/
|
|
33
|
+
signal(eventType: string, payload: unknown): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Pause the workflow
|
|
36
|
+
*/
|
|
37
|
+
pause(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Resume a paused workflow
|
|
40
|
+
*/
|
|
41
|
+
resume(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Cancel the workflow
|
|
44
|
+
*/
|
|
45
|
+
cancel(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Alarm handler - main execution loop
|
|
48
|
+
*/
|
|
49
|
+
alarm(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Execute the workflow handler
|
|
52
|
+
*/
|
|
53
|
+
private executeWorkflow;
|
|
54
|
+
/**
|
|
55
|
+
* Execute or retrieve cached result for a step
|
|
56
|
+
*/
|
|
57
|
+
executeStep<T>(name: string, options: StepOptions | undefined, fn: () => Promise<T>): Promise<T>;
|
|
58
|
+
/**
|
|
59
|
+
* Sleep for a duration
|
|
60
|
+
*/
|
|
61
|
+
executeSleep(name: string, duration: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Sleep until a specific timestamp
|
|
64
|
+
*/
|
|
65
|
+
executeSleepUntil(name: string, timestamp: Date): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Wait for an external event
|
|
68
|
+
*/
|
|
69
|
+
executeWaitForEvent<T>(name: string, options?: WaitEventOptions): Promise<T>;
|
|
70
|
+
private ensureLoaded;
|
|
71
|
+
private persist;
|
|
72
|
+
private isTerminal;
|
|
73
|
+
private isTimedOut;
|
|
74
|
+
private getCurrentStep;
|
|
75
|
+
private transitionTo;
|
|
76
|
+
private notifyCoordinator;
|
|
77
|
+
private generateStepId;
|
|
78
|
+
private parseDuration;
|
|
79
|
+
private calculateBackoff;
|
|
80
|
+
private executeWithTimeout;
|
|
81
|
+
private normalizeError;
|
|
82
|
+
}
|