deepline 0.0.1 → 0.1.1
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/README.md +324 -0
- package/dist/cli/index.js +6750 -503
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +6735 -512
- package/dist/cli/index.mjs.map +1 -1
- package/dist/index.d.mts +2349 -32
- package/dist/index.d.ts +2349 -32
- package/dist/index.js +1631 -82
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1617 -83
- package/dist/index.mjs.map +1 -1
- package/dist/repo/apps/play-runner-workers/src/coordinator-entry.ts +3256 -0
- package/dist/repo/apps/play-runner-workers/src/dedup-do.ts +710 -0
- package/dist/repo/apps/play-runner-workers/src/entry.ts +5070 -0
- package/dist/repo/apps/play-runner-workers/src/runtime/README.md +21 -0
- package/dist/repo/apps/play-runner-workers/src/runtime/batching.ts +177 -0
- package/dist/repo/apps/play-runner-workers/src/runtime/execution-plan.ts +52 -0
- package/dist/repo/apps/play-runner-workers/src/runtime/tool-batch.ts +100 -0
- package/dist/repo/apps/play-runner-workers/src/runtime/tool-result.ts +184 -0
- package/dist/repo/sdk/src/cli/commands/auth.ts +482 -0
- package/dist/repo/sdk/src/cli/commands/billing.ts +188 -0
- package/dist/repo/sdk/src/cli/commands/csv.ts +123 -0
- package/dist/repo/sdk/src/cli/commands/db.ts +119 -0
- package/dist/repo/sdk/src/cli/commands/feedback.ts +40 -0
- package/dist/repo/sdk/src/cli/commands/org.ts +117 -0
- package/dist/repo/sdk/src/cli/commands/play.ts +3200 -0
- package/dist/repo/sdk/src/cli/commands/tools.ts +687 -0
- package/dist/repo/sdk/src/cli/dataset-stats.ts +341 -0
- package/dist/repo/sdk/src/cli/index.ts +138 -0
- package/dist/repo/sdk/src/cli/progress.ts +135 -0
- package/dist/repo/sdk/src/cli/trace.ts +61 -0
- package/dist/repo/sdk/src/cli/utils.ts +145 -0
- package/dist/repo/sdk/src/client.ts +1188 -0
- package/dist/repo/sdk/src/compat.ts +77 -0
- package/dist/repo/sdk/src/config.ts +285 -0
- package/dist/repo/sdk/src/errors.ts +125 -0
- package/dist/repo/sdk/src/http.ts +391 -0
- package/dist/repo/sdk/src/index.ts +139 -0
- package/dist/repo/sdk/src/play.ts +1330 -0
- package/dist/repo/sdk/src/plays/bundle-play-file.ts +133 -0
- package/dist/repo/sdk/src/plays/harness-stub.ts +210 -0
- package/dist/repo/sdk/src/plays/local-file-discovery.ts +326 -0
- package/dist/repo/sdk/src/tool-output.ts +489 -0
- package/dist/repo/sdk/src/types.ts +669 -0
- package/dist/repo/sdk/src/version.ts +2 -0
- package/dist/repo/sdk/src/worker-play-entry.ts +286 -0
- package/dist/repo/shared_libs/observability/node-tracing.ts +129 -0
- package/dist/repo/shared_libs/observability/tracing.ts +98 -0
- package/dist/repo/shared_libs/play-runtime/backend.ts +139 -0
- package/dist/repo/shared_libs/play-runtime/batch-runtime.ts +182 -0
- package/dist/repo/shared_libs/play-runtime/batching-types.ts +91 -0
- package/dist/repo/shared_libs/play-runtime/context.ts +3999 -0
- package/dist/repo/shared_libs/play-runtime/coordinator-headers.ts +78 -0
- package/dist/repo/shared_libs/play-runtime/ctx-contract.ts +250 -0
- package/dist/repo/shared_libs/play-runtime/ctx-types.ts +713 -0
- package/dist/repo/shared_libs/play-runtime/dataset-id.ts +10 -0
- package/dist/repo/shared_libs/play-runtime/db-session-crypto.ts +304 -0
- package/dist/repo/shared_libs/play-runtime/db-session.ts +462 -0
- package/dist/repo/shared_libs/play-runtime/dedup-backend.ts +0 -0
- package/dist/repo/shared_libs/play-runtime/default-batch-strategies.ts +124 -0
- package/dist/repo/shared_libs/play-runtime/execution-plan.ts +262 -0
- package/dist/repo/shared_libs/play-runtime/live-events.ts +214 -0
- package/dist/repo/shared_libs/play-runtime/live-state-contract.ts +50 -0
- package/dist/repo/shared_libs/play-runtime/map-execution-frame.ts +114 -0
- package/dist/repo/shared_libs/play-runtime/map-row-identity.ts +158 -0
- package/dist/repo/shared_libs/play-runtime/profiles.ts +90 -0
- package/dist/repo/shared_libs/play-runtime/progress-emitter.ts +172 -0
- package/dist/repo/shared_libs/play-runtime/protocol.ts +121 -0
- package/dist/repo/shared_libs/play-runtime/public-play-contract.ts +42 -0
- package/dist/repo/shared_libs/play-runtime/result-normalization.ts +33 -0
- package/dist/repo/shared_libs/play-runtime/runtime-actions.ts +208 -0
- package/dist/repo/shared_libs/play-runtime/runtime-api.ts +1873 -0
- package/dist/repo/shared_libs/play-runtime/runtime-constraints.ts +2 -0
- package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-neon-serverless.ts +201 -0
- package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-pg.ts +48 -0
- package/dist/repo/shared_libs/play-runtime/runtime-pg-driver.ts +84 -0
- package/dist/repo/shared_libs/play-runtime/scheduler-backend.ts +174 -0
- package/dist/repo/shared_libs/play-runtime/static-pipeline-types.ts +147 -0
- package/dist/repo/shared_libs/play-runtime/suspension.ts +68 -0
- package/dist/repo/shared_libs/play-runtime/tool-batch-executor.ts +146 -0
- package/dist/repo/shared_libs/play-runtime/tool-result.ts +387 -0
- package/dist/repo/shared_libs/play-runtime/tracing.ts +31 -0
- package/dist/repo/shared_libs/play-runtime/waterfall-replay.ts +75 -0
- package/dist/repo/shared_libs/play-runtime/worker-api-types.ts +140 -0
- package/dist/repo/shared_libs/plays/artifact-transport.ts +14 -0
- package/dist/repo/shared_libs/plays/artifact-types.ts +49 -0
- package/dist/repo/shared_libs/plays/bundling/index.ts +1346 -0
- package/dist/repo/shared_libs/plays/compiler-manifest.ts +186 -0
- package/dist/repo/shared_libs/plays/contracts.ts +51 -0
- package/dist/repo/shared_libs/plays/dataset.ts +308 -0
- package/dist/repo/shared_libs/plays/definition.ts +264 -0
- package/dist/repo/shared_libs/plays/file-refs.ts +11 -0
- package/dist/repo/shared_libs/plays/rate-limit-scheduler.ts +206 -0
- package/dist/repo/shared_libs/plays/resolve-static-pipeline.ts +164 -0
- package/dist/repo/shared_libs/plays/row-identity.ts +302 -0
- package/dist/repo/shared_libs/plays/runtime-validation.ts +415 -0
- package/dist/repo/shared_libs/plays/static-pipeline.ts +560 -0
- package/dist/repo/shared_libs/temporal/constants.ts +39 -0
- package/dist/repo/shared_libs/temporal/preview-config.ts +153 -0
- package/package.json +14 -12
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP headers attached to every server-to-coordinator request.
|
|
3
|
+
*
|
|
4
|
+
* The coordinator is a Cloudflare Worker (`deepline-play-coordinator-*`) that
|
|
5
|
+
* we publish through Cloudflare's Versions + Deployments primitives. Whenever
|
|
6
|
+
* a deployment is split across two versions (e.g. 10% canary), Cloudflare
|
|
7
|
+
* uses the `Cloudflare-Workers-Version-Key` header to pick a stable version
|
|
8
|
+
* per request. Sending the runId as the key keeps every request for one play
|
|
9
|
+
* run pinned to whichever version started the run, so a partial rollout
|
|
10
|
+
* cannot strand a Workflow's `/submit` and `/result` calls on different
|
|
11
|
+
* code versions.
|
|
12
|
+
*
|
|
13
|
+
* The header is harmless when there is only one active version (the default).
|
|
14
|
+
*/
|
|
15
|
+
export const COORDINATOR_VERSION_KEY_HEADER = 'Cloudflare-Workers-Version-Key';
|
|
16
|
+
/**
|
|
17
|
+
* Shared secret the coordinator uses to authenticate dispatcher (Vercel app)
|
|
18
|
+
* traffic. The coordinator also sanity-checks `x-deepline-run-scope` matches
|
|
19
|
+
* the run id encoded in the URL path on cancel/signal so a leaked token
|
|
20
|
+
* cannot be retargeted to arbitrary runs.
|
|
21
|
+
*/
|
|
22
|
+
export const COORDINATOR_INTERNAL_TOKEN_HEADER = 'x-deepline-internal-token';
|
|
23
|
+
export const COORDINATOR_RUN_SCOPE_HEADER = 'x-deepline-run-scope';
|
|
24
|
+
export const COORDINATOR_URL_OVERRIDE_HEADER = 'x-deepline-coordinator-url';
|
|
25
|
+
export const WORKER_CALLBACK_URL_OVERRIDE_HEADER =
|
|
26
|
+
'x-deepline-worker-callback-url';
|
|
27
|
+
|
|
28
|
+
let warnedAboutMissingInternalToken = false;
|
|
29
|
+
|
|
30
|
+
function resolveInternalCoordinatorToken(): string | null {
|
|
31
|
+
// Read lazily so the helper is safe to import in environments without
|
|
32
|
+
// env access (e.g. workerd build-time bundling).
|
|
33
|
+
const fromEnv =
|
|
34
|
+
(typeof process !== 'undefined' && process?.env?.DEEPLINE_INTERNAL_TOKEN?.trim()) ||
|
|
35
|
+
null;
|
|
36
|
+
if (fromEnv) return fromEnv;
|
|
37
|
+
if (!warnedAboutMissingInternalToken) {
|
|
38
|
+
warnedAboutMissingInternalToken = true;
|
|
39
|
+
// Dev convenience: log once. The coordinator may be running without the
|
|
40
|
+
// token enforced too, so this is not fatal — let the call proceed and
|
|
41
|
+
// surface any 401/403 from the coordinator instead of failing closed.
|
|
42
|
+
if (typeof console !== 'undefined') {
|
|
43
|
+
console.warn(
|
|
44
|
+
'[plays] DEEPLINE_INTERNAL_TOKEN unset; coordinator calls will fail if the coordinator is enforcing it.',
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function coordinatorRequestHeaders(input: {
|
|
52
|
+
runId: string;
|
|
53
|
+
contentType?: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* When set, the coordinator validates this matches the runId in the URL.
|
|
56
|
+
* Pass the runId on `/cancel` / `/signal` calls so a leaked dispatcher
|
|
57
|
+
* token cannot be retargeted to a different run.
|
|
58
|
+
*/
|
|
59
|
+
runScope?: string | null;
|
|
60
|
+
}): Record<string, string> {
|
|
61
|
+
const headers: Record<string, string> = {};
|
|
62
|
+
if (input.contentType) {
|
|
63
|
+
headers['content-type'] = input.contentType;
|
|
64
|
+
}
|
|
65
|
+
const trimmed = input.runId.trim();
|
|
66
|
+
if (trimmed) {
|
|
67
|
+
headers[COORDINATOR_VERSION_KEY_HEADER] = trimmed;
|
|
68
|
+
}
|
|
69
|
+
const internalToken = resolveInternalCoordinatorToken();
|
|
70
|
+
if (internalToken) {
|
|
71
|
+
headers[COORDINATOR_INTERNAL_TOKEN_HEADER] = internalToken;
|
|
72
|
+
}
|
|
73
|
+
const scope = input.runScope?.trim() || trimmed;
|
|
74
|
+
if (scope) {
|
|
75
|
+
headers[COORDINATOR_RUN_SCOPE_HEADER] = scope;
|
|
76
|
+
}
|
|
77
|
+
return headers;
|
|
78
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
export interface BatchResult {
|
|
2
|
+
rowId: number;
|
|
3
|
+
rowKey?: string | null;
|
|
4
|
+
result: unknown | null;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface MapExecutionFrame {
|
|
8
|
+
mapInvocationId: string;
|
|
9
|
+
mapNodeId?: string | null;
|
|
10
|
+
logicalNamespace: string;
|
|
11
|
+
artifactTableNamespace: string;
|
|
12
|
+
status: 'running' | 'suspended' | 'completed' | 'failed';
|
|
13
|
+
totalRows: number;
|
|
14
|
+
completedRowKeys: string[];
|
|
15
|
+
pendingRowKeys: string[];
|
|
16
|
+
activeBoundaryId?: string | null;
|
|
17
|
+
startedAt: number;
|
|
18
|
+
updatedAt: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PlayRowUpdate {
|
|
22
|
+
key: string;
|
|
23
|
+
rowId: number;
|
|
24
|
+
tableNamespace?: string | null;
|
|
25
|
+
status?: 'running' | 'completed' | 'failed';
|
|
26
|
+
stage?: string | null;
|
|
27
|
+
provider?: string | null;
|
|
28
|
+
error?: string | null;
|
|
29
|
+
dataPatch?: Record<string, unknown>;
|
|
30
|
+
cellMetaPatch?: Record<
|
|
31
|
+
string,
|
|
32
|
+
{
|
|
33
|
+
status:
|
|
34
|
+
| 'queued'
|
|
35
|
+
| 'running'
|
|
36
|
+
| 'completed'
|
|
37
|
+
| 'failed'
|
|
38
|
+
| 'cached'
|
|
39
|
+
| 'missed'
|
|
40
|
+
| 'skipped';
|
|
41
|
+
stage?: string | null;
|
|
42
|
+
provider?: string | null;
|
|
43
|
+
error?: string | null;
|
|
44
|
+
reused?: boolean;
|
|
45
|
+
}
|
|
46
|
+
>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type PlayExecutionEvent =
|
|
50
|
+
| {
|
|
51
|
+
type: 'map.preparing';
|
|
52
|
+
mapInvocationId: string;
|
|
53
|
+
mapNodeId?: string | null;
|
|
54
|
+
logicalNamespace: string;
|
|
55
|
+
artifactTableNamespace: string;
|
|
56
|
+
totalRows: number;
|
|
57
|
+
completedRows: number;
|
|
58
|
+
pendingRows: number;
|
|
59
|
+
at: number;
|
|
60
|
+
}
|
|
61
|
+
| {
|
|
62
|
+
type: 'map.started';
|
|
63
|
+
mapInvocationId: string;
|
|
64
|
+
mapNodeId?: string | null;
|
|
65
|
+
logicalNamespace: string;
|
|
66
|
+
artifactTableNamespace: string;
|
|
67
|
+
totalRows: number;
|
|
68
|
+
completedRows: number;
|
|
69
|
+
pendingRows: number;
|
|
70
|
+
at: number;
|
|
71
|
+
}
|
|
72
|
+
| {
|
|
73
|
+
type: 'map.progress';
|
|
74
|
+
mapInvocationId: string;
|
|
75
|
+
mapNodeId?: string | null;
|
|
76
|
+
logicalNamespace: string;
|
|
77
|
+
artifactTableNamespace: string;
|
|
78
|
+
completedRows: number;
|
|
79
|
+
failedRows: number;
|
|
80
|
+
totalRows?: number;
|
|
81
|
+
at: number;
|
|
82
|
+
}
|
|
83
|
+
| {
|
|
84
|
+
type: 'map.row.updated';
|
|
85
|
+
mapInvocationId: string;
|
|
86
|
+
mapNodeId?: string | null;
|
|
87
|
+
logicalNamespace: string;
|
|
88
|
+
artifactTableNamespace: string;
|
|
89
|
+
rowKey: string;
|
|
90
|
+
rowStatus?: PlayRowUpdate['status'];
|
|
91
|
+
fieldName?: string | null;
|
|
92
|
+
stage?: string | null;
|
|
93
|
+
provider?: string | null;
|
|
94
|
+
at: number;
|
|
95
|
+
}
|
|
96
|
+
| {
|
|
97
|
+
type: 'map.completed' | 'map.suspended' | 'map.resumed' | 'map.failed';
|
|
98
|
+
mapInvocationId: string;
|
|
99
|
+
mapNodeId?: string | null;
|
|
100
|
+
logicalNamespace: string;
|
|
101
|
+
artifactTableNamespace: string;
|
|
102
|
+
completedRows: number;
|
|
103
|
+
failedRows: number;
|
|
104
|
+
totalRows?: number;
|
|
105
|
+
at: number;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export interface PlayCheckpoint {
|
|
109
|
+
completedBatches: Record<string, BatchResult[]>;
|
|
110
|
+
completedToolBatches: Record<
|
|
111
|
+
string,
|
|
112
|
+
Record<string, { done: true; result: unknown | null }>
|
|
113
|
+
>;
|
|
114
|
+
resolvedWaterfalls: Record<string, Record<string, unknown>>;
|
|
115
|
+
resolvedBoundaries?: Record<
|
|
116
|
+
string,
|
|
117
|
+
| {
|
|
118
|
+
kind: 'sleep';
|
|
119
|
+
delayMs: number;
|
|
120
|
+
completedAt?: number;
|
|
121
|
+
scope?: {
|
|
122
|
+
type: 'workflow' | 'map_row';
|
|
123
|
+
tableNamespace?: string;
|
|
124
|
+
rowKey?: string;
|
|
125
|
+
rowIndex?: number;
|
|
126
|
+
fieldName?: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
| {
|
|
130
|
+
kind: 'integration_event';
|
|
131
|
+
eventKey: string;
|
|
132
|
+
timeoutMs: number;
|
|
133
|
+
provider?: string;
|
|
134
|
+
toolId?: string;
|
|
135
|
+
messageRef?: {
|
|
136
|
+
channel: string;
|
|
137
|
+
ts: string;
|
|
138
|
+
};
|
|
139
|
+
output?: unknown;
|
|
140
|
+
completedAt?: number;
|
|
141
|
+
}
|
|
142
|
+
| {
|
|
143
|
+
kind: 'fetch';
|
|
144
|
+
url: string;
|
|
145
|
+
method: string;
|
|
146
|
+
output?: unknown;
|
|
147
|
+
completedAt?: number;
|
|
148
|
+
}
|
|
149
|
+
| {
|
|
150
|
+
kind: 'step';
|
|
151
|
+
stepId: string;
|
|
152
|
+
output?: unknown;
|
|
153
|
+
completedAt?: number;
|
|
154
|
+
}
|
|
155
|
+
>;
|
|
156
|
+
mapFrames?: Record<string, MapExecutionFrame>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface PlayStepRowResult {
|
|
160
|
+
rowId: number;
|
|
161
|
+
status: 'completed' | 'failed' | 'missed' | 'skipped';
|
|
162
|
+
success: boolean;
|
|
163
|
+
provider?: string;
|
|
164
|
+
value?: unknown;
|
|
165
|
+
error?: string | null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export type PlayStep =
|
|
169
|
+
| { type: 'start'; trigger?: string; description?: string }
|
|
170
|
+
| { type: 'csv_load'; arg?: string; rows?: number; description?: string }
|
|
171
|
+
| {
|
|
172
|
+
type: 'map';
|
|
173
|
+
items: number;
|
|
174
|
+
fields?: string[];
|
|
175
|
+
substeps: PlayMapSubstep[];
|
|
176
|
+
description?: string;
|
|
177
|
+
}
|
|
178
|
+
| {
|
|
179
|
+
type: 'waterfall';
|
|
180
|
+
tool?: string;
|
|
181
|
+
providers?: string[];
|
|
182
|
+
id?: string;
|
|
183
|
+
output?: string;
|
|
184
|
+
minResults?: number;
|
|
185
|
+
steps?: Array<{
|
|
186
|
+
id: string;
|
|
187
|
+
kind?: 'tool' | 'code';
|
|
188
|
+
toolId?: string;
|
|
189
|
+
results: PlayStepRowResult[];
|
|
190
|
+
}>;
|
|
191
|
+
results: PlayStepRowResult[];
|
|
192
|
+
description?: string;
|
|
193
|
+
}
|
|
194
|
+
| {
|
|
195
|
+
type: 'tool';
|
|
196
|
+
toolId: string;
|
|
197
|
+
results: PlayStepRowResult[];
|
|
198
|
+
description?: string;
|
|
199
|
+
}
|
|
200
|
+
| {
|
|
201
|
+
type: 'play_call';
|
|
202
|
+
playId: string;
|
|
203
|
+
results?: PlayStepRowResult[];
|
|
204
|
+
nestedSteps: PlayStep[];
|
|
205
|
+
description?: string;
|
|
206
|
+
}
|
|
207
|
+
| {
|
|
208
|
+
type: 'run_javascript';
|
|
209
|
+
alias: string;
|
|
210
|
+
results: PlayStepRowResult[];
|
|
211
|
+
description?: string;
|
|
212
|
+
}
|
|
213
|
+
| { type: 'return'; outputRows: number; description?: string };
|
|
214
|
+
|
|
215
|
+
export type PlayMapSubstep =
|
|
216
|
+
| {
|
|
217
|
+
type: 'waterfall';
|
|
218
|
+
tool?: string;
|
|
219
|
+
providers?: string[];
|
|
220
|
+
id?: string;
|
|
221
|
+
output?: string;
|
|
222
|
+
minResults?: number;
|
|
223
|
+
steps?: Array<{
|
|
224
|
+
id: string;
|
|
225
|
+
kind?: 'tool' | 'code';
|
|
226
|
+
toolId?: string;
|
|
227
|
+
results: PlayStepRowResult[];
|
|
228
|
+
}>;
|
|
229
|
+
results: PlayStepRowResult[];
|
|
230
|
+
description?: string;
|
|
231
|
+
}
|
|
232
|
+
| {
|
|
233
|
+
type: 'tool';
|
|
234
|
+
toolId: string;
|
|
235
|
+
results: PlayStepRowResult[];
|
|
236
|
+
description?: string;
|
|
237
|
+
}
|
|
238
|
+
| {
|
|
239
|
+
type: 'play_call';
|
|
240
|
+
playId: string;
|
|
241
|
+
results?: PlayStepRowResult[];
|
|
242
|
+
nestedSteps: PlayStep[];
|
|
243
|
+
description?: string;
|
|
244
|
+
}
|
|
245
|
+
| {
|
|
246
|
+
type: 'run_javascript';
|
|
247
|
+
alias: string;
|
|
248
|
+
results: PlayStepRowResult[];
|
|
249
|
+
description?: string;
|
|
250
|
+
};
|