deepline 0.1.12 → 0.1.19

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 (80) hide show
  1. package/README.md +14 -6
  2. package/dist/cli/index.js +1298 -711
  3. package/dist/cli/index.mjs +1294 -707
  4. package/dist/index.d.mts +199 -23
  5. package/dist/index.d.ts +199 -23
  6. package/dist/index.js +219 -13
  7. package/dist/index.mjs +219 -13
  8. package/dist/repo/apps/play-runner-workers/src/coordinator-entry.ts +68 -12
  9. package/dist/repo/apps/play-runner-workers/src/entry.ts +241 -51
  10. package/dist/repo/sdk/src/client.ts +237 -0
  11. package/dist/repo/sdk/src/config.ts +125 -8
  12. package/dist/repo/sdk/src/http.ts +10 -2
  13. package/dist/repo/sdk/src/play.ts +19 -36
  14. package/dist/repo/sdk/src/plays/bundle-play-file.ts +22 -8
  15. package/dist/repo/sdk/src/plays/local-file-discovery.ts +207 -160
  16. package/dist/repo/sdk/src/types.ts +25 -0
  17. package/dist/repo/sdk/src/version.ts +2 -2
  18. package/dist/repo/shared_libs/play-runtime/tool-result.ts +237 -145
  19. package/dist/repo/shared_libs/plays/bundling/index.ts +206 -229
  20. package/dist/repo/shared_libs/plays/dataset.ts +28 -0
  21. package/package.json +5 -4
  22. package/dist/cli/index.js.map +0 -1
  23. package/dist/cli/index.mjs.map +0 -1
  24. package/dist/index.js.map +0 -1
  25. package/dist/index.mjs.map +0 -1
  26. package/dist/repo/apps/play-runner-workers/src/runtime/README.md +0 -21
  27. package/dist/repo/apps/play-runner-workers/src/runtime/batching.ts +0 -177
  28. package/dist/repo/apps/play-runner-workers/src/runtime/execution-plan.ts +0 -52
  29. package/dist/repo/apps/play-runner-workers/src/runtime/tool-batch.ts +0 -100
  30. package/dist/repo/sdk/src/cli/commands/auth.ts +0 -500
  31. package/dist/repo/sdk/src/cli/commands/billing.ts +0 -188
  32. package/dist/repo/sdk/src/cli/commands/csv.ts +0 -123
  33. package/dist/repo/sdk/src/cli/commands/db.ts +0 -119
  34. package/dist/repo/sdk/src/cli/commands/feedback.ts +0 -40
  35. package/dist/repo/sdk/src/cli/commands/org.ts +0 -117
  36. package/dist/repo/sdk/src/cli/commands/play.ts +0 -3441
  37. package/dist/repo/sdk/src/cli/commands/tools.ts +0 -687
  38. package/dist/repo/sdk/src/cli/dataset-stats.ts +0 -415
  39. package/dist/repo/sdk/src/cli/index.ts +0 -148
  40. package/dist/repo/sdk/src/cli/progress.ts +0 -149
  41. package/dist/repo/sdk/src/cli/skills-sync.ts +0 -141
  42. package/dist/repo/sdk/src/cli/trace.ts +0 -61
  43. package/dist/repo/sdk/src/cli/utils.ts +0 -145
  44. package/dist/repo/sdk/src/compat.ts +0 -77
  45. package/dist/repo/shared_libs/observability/node-tracing.ts +0 -129
  46. package/dist/repo/shared_libs/observability/tracing.ts +0 -98
  47. package/dist/repo/shared_libs/play-runtime/context.ts +0 -4242
  48. package/dist/repo/shared_libs/play-runtime/ctx-contract.ts +0 -250
  49. package/dist/repo/shared_libs/play-runtime/ctx-types.ts +0 -725
  50. package/dist/repo/shared_libs/play-runtime/dataset-id.ts +0 -10
  51. package/dist/repo/shared_libs/play-runtime/db-session-crypto.ts +0 -304
  52. package/dist/repo/shared_libs/play-runtime/db-session.ts +0 -462
  53. package/dist/repo/shared_libs/play-runtime/live-events.ts +0 -214
  54. package/dist/repo/shared_libs/play-runtime/live-state-contract.ts +0 -50
  55. package/dist/repo/shared_libs/play-runtime/map-execution-frame.ts +0 -114
  56. package/dist/repo/shared_libs/play-runtime/map-row-identity.ts +0 -158
  57. package/dist/repo/shared_libs/play-runtime/progress-emitter.ts +0 -172
  58. package/dist/repo/shared_libs/play-runtime/protocol.ts +0 -121
  59. package/dist/repo/shared_libs/play-runtime/public-play-contract.ts +0 -42
  60. package/dist/repo/shared_libs/play-runtime/result-normalization.ts +0 -33
  61. package/dist/repo/shared_libs/play-runtime/runtime-api.ts +0 -1873
  62. package/dist/repo/shared_libs/play-runtime/runtime-constraints.ts +0 -2
  63. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-neon-serverless.ts +0 -201
  64. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-pg.ts +0 -48
  65. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver.ts +0 -84
  66. package/dist/repo/shared_libs/play-runtime/static-pipeline-types.ts +0 -147
  67. package/dist/repo/shared_libs/play-runtime/suspension.ts +0 -68
  68. package/dist/repo/shared_libs/play-runtime/tracing.ts +0 -31
  69. package/dist/repo/shared_libs/play-runtime/waterfall-replay.ts +0 -75
  70. package/dist/repo/shared_libs/play-runtime/worker-api-types.ts +0 -140
  71. package/dist/repo/shared_libs/plays/artifact-transport.ts +0 -14
  72. package/dist/repo/shared_libs/plays/artifact-types.ts +0 -49
  73. package/dist/repo/shared_libs/plays/compiler-manifest.ts +0 -186
  74. package/dist/repo/shared_libs/plays/definition.ts +0 -264
  75. package/dist/repo/shared_libs/plays/file-refs.ts +0 -11
  76. package/dist/repo/shared_libs/plays/rate-limit-scheduler.ts +0 -206
  77. package/dist/repo/shared_libs/plays/resolve-static-pipeline.ts +0 -164
  78. package/dist/repo/shared_libs/plays/runtime-validation.ts +0 -395
  79. package/dist/repo/shared_libs/temporal/constants.ts +0 -39
  80. package/dist/repo/shared_libs/temporal/preview-config.ts +0 -153
@@ -1,725 +0,0 @@
1
- // Core types for PlayContext — cloud-only execution via Temporal
2
- import type { PlayBundleArtifact } from '../plays/artifact-types';
3
- import type { PlayRunContractSnapshot } from '../plays/contracts';
4
- import type { PlayStructuredDefinition } from '../plays/definition';
5
- import type { PlayStaticPipeline } from '../plays/static-pipeline';
6
- import type { PlayDataset, PlayDatasetInput } from '../plays/dataset';
7
- import type { PlayQueueHint } from '../plays/rate-limit-scheduler';
8
- import type { AnyBatchOperationStrategy } from './batching-types';
9
- import type { ToolResultMetadataInput } from './tool-result';
10
-
11
- export interface RowState {
12
- id: number;
13
- input: unknown;
14
- status: 'pending' | 'waiting' | 'complete' | 'failed';
15
- waterfalls: Map<string, WaterfallState>;
16
- toolCalls: Map<string, ToolCallState>;
17
- results: Map<string, unknown>;
18
- }
19
-
20
- export interface WaterfallState {
21
- status: 'pending' | 'complete' | 'failed';
22
- providerIndex: number;
23
- result?: unknown;
24
- error?: string;
25
- }
26
-
27
- export interface ToolCallState {
28
- status: 'pending' | 'complete' | 'failed';
29
- result?: unknown;
30
- error?: string;
31
- }
32
-
33
- export interface WaterfallRequest {
34
- rowId: number;
35
- fieldName?: string;
36
- tableNamespace?: string;
37
- rowKey?: string | null;
38
- key: string;
39
- toolName: string;
40
- input: Record<string, unknown>;
41
- providerIndex: number;
42
- opts?: WaterfallOptions;
43
- spec?: InlineWaterfallSpec;
44
- description?: string;
45
- }
46
-
47
- export interface ToolCallRequest {
48
- callId: string;
49
- rowId: number;
50
- fieldName?: string;
51
- toolId: string;
52
- input: Record<string, unknown>;
53
- tableNamespace?: string;
54
- rowKey?: string | null;
55
- description?: string;
56
- }
57
-
58
- export interface ToolBatchResult {
59
- done: true;
60
- result: unknown | null;
61
- }
62
-
63
- export interface RuntimeStepReceipt {
64
- key: string;
65
- status: 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
66
- output?: unknown;
67
- error?: string;
68
- runId?: string | null;
69
- }
70
-
71
- export interface GetRuntimeStepReceiptInput {
72
- key: string;
73
- }
74
-
75
- export interface ClaimRuntimeStepReceiptInput {
76
- key: string;
77
- runId: string;
78
- }
79
-
80
- export interface CompleteRuntimeStepReceiptInput {
81
- key: string;
82
- runId: string;
83
- output: unknown | null;
84
- }
85
-
86
- export interface FailRuntimeStepReceiptInput {
87
- key: string;
88
- runId: string;
89
- error: string;
90
- }
91
-
92
- export interface SkipRuntimeStepReceiptInput {
93
- key: string;
94
- runId: string;
95
- output?: unknown | null;
96
- }
97
-
98
- export interface WaterfallOptions {
99
- providers?: string[];
100
- timeout?: number;
101
- description?: string;
102
- }
103
-
104
- export interface CsvOptions {
105
- description?: string;
106
- columns?: Record<string, string | readonly string[]>;
107
- rename?: Record<string, string | readonly string[]>;
108
- required?: readonly string[];
109
- }
110
-
111
- export interface MapOptions<TItem = Record<string, unknown>> {
112
- description?: string;
113
- /**
114
- * Optional relative cache window for intentional reruns.
115
- *
116
- * By default, ctx.map is durable by play + map key + row identity forever.
117
- * Set staleAfterSeconds to rerun after that many seconds while retries/replays
118
- * inside the same window still hit the cache. Daily refreshes use 86400.
119
- */
120
- staleAfterSeconds?: number;
121
- /**
122
- * Maximum row resolvers to execute concurrently. Use 1 when a map calls a
123
- * map-backed child play via ctx.runPlay, because those child tables share
124
- * durable row identity.
125
- */
126
- concurrency?: number;
127
- /**
128
- * Optional stable key per row. When provided, row identity is derived from
129
- * the selected input field(s) or returned value instead of hashing the full
130
- * row. Use this to pin identity to primary columns (e.g. `{ key: "email" }`
131
- * or `{ key: ["first_name", "last_name", "domain"] }`) so harmless
132
- * mutations to other columns don't invalidate the cache.
133
- *
134
- * Must return a non-empty string (numbers are coerced) and must be unique
135
- * across rows in this ctx.map() call. Empty or duplicate keys throw loudly
136
- * before any provider work runs. The key function should reference *input*
137
- * columns only — values produced by this map's field resolvers are stripped
138
- * before identity is computed.
139
- */
140
- key?:
141
- | (keyof TItem & string)
142
- | readonly (keyof TItem & string)[]
143
- | ((row: TItem, index: number) => string | number | readonly unknown[]);
144
- }
145
-
146
- export type MapDefinitionOptions<TItem = Record<string, unknown>> = Omit<
147
- MapOptions<TItem>,
148
- 'description'
149
- >;
150
-
151
- export type MapRunOptions<TItem = Record<string, unknown>> = Pick<
152
- MapOptions<TItem>,
153
- 'description' | 'staleAfterSeconds' | 'concurrency' | 'key'
154
- >;
155
-
156
- export interface ToolCallOptions {
157
- description?: string;
158
- }
159
-
160
- export interface ToolExecutionRequest {
161
- id: string;
162
- tool: string;
163
- input: Record<string, unknown>;
164
- description?: string;
165
- }
166
-
167
- export interface PlayCallOptions {
168
- description?: string;
169
- }
170
-
171
- export interface InlineWaterfallToolStep {
172
- id: string;
173
- kind?: 'tool';
174
- toolId: string;
175
- mapInput: (input: Record<string, unknown>) => Record<string, unknown>;
176
- }
177
-
178
- export interface InlineWaterfallCodeStepContext {
179
- tools: {
180
- execute(request: ToolExecutionRequest): Promise<unknown>;
181
- };
182
- }
183
-
184
- export interface InlineWaterfallCodeStep {
185
- id: string;
186
- kind: 'code';
187
- run: (
188
- input: Record<string, unknown>,
189
- ctx: InlineWaterfallCodeStepContext,
190
- ) => unknown | Promise<unknown>;
191
- }
192
-
193
- export type InlineWaterfallStep =
194
- | InlineWaterfallToolStep
195
- | InlineWaterfallCodeStep;
196
-
197
- export interface InlineWaterfallSpec {
198
- id: string;
199
- output: string;
200
- minResults: number;
201
- steps: InlineWaterfallStep[];
202
- }
203
-
204
- export interface ResolvedPlayExecution {
205
- playId: string;
206
- code?: string | null;
207
- sourceCode?: string | null;
208
- codeFormat?: 'function' | 'cjs_module' | 'esm_module';
209
- artifact?: PlayBundleArtifact | null;
210
- compressedArtifact?: string | null;
211
- definition?: PlayStructuredDefinition | null;
212
- staticPipeline?: PlayStaticPipeline | null;
213
- contractSnapshot?: PlayRunContractSnapshot | null;
214
- }
215
-
216
- export interface PlayExecutionGovernanceLimits {
217
- maxPlayCallDepth: number;
218
- maxPlayCallCount: number;
219
- maxToolCallCount: number;
220
- maxWaterfallStepExecutions: number | null;
221
- maxRetryCount: number;
222
- maxDescendants: number;
223
- maxChildPlayCallsPerParent: number;
224
- maxConcurrentPlayCalls: number;
225
- maxConcurrentToolCalls: number;
226
- }
227
-
228
- export interface PlayExecutionGovernanceState {
229
- rootPlayId: string;
230
- rootRunId: string;
231
- currentPlayId: string;
232
- currentRunId: string;
233
- ancestryPlayIds: string[];
234
- ancestryRunIds: string[];
235
- callDepth: number;
236
- playCallCount: number;
237
- toolCallCount: number;
238
- waterfallStepExecutions: number;
239
- retryCount: number;
240
- descendantCount: number;
241
- parentChildCalls: Record<string, number>;
242
- inFlightPlayCalls: number;
243
- inFlightPlayCallsByPlayId?: Record<string, number>;
244
- inFlightToolCalls: number;
245
- limits: PlayExecutionGovernanceLimits;
246
- }
247
-
248
- export interface BatchRequest {
249
- provider: string;
250
- toolName: string;
251
- inputs: Record<string, unknown>[];
252
- rowIds: number[];
253
- }
254
-
255
- export interface MapStartResult {
256
- /** Rows that need processing (not yet completed in a prior run). */
257
- pendingRows: Record<string, unknown>[];
258
- /** Rows already completed in a prior run (cached results). */
259
- completedRows: Record<string, unknown>[];
260
- /** Resolved table namespace. */
261
- tableNamespace: string;
262
- }
263
-
264
- export interface MapExecutionFrame {
265
- mapInvocationId: string;
266
- mapNodeId?: string | null;
267
- logicalNamespace: string;
268
- artifactTableNamespace: string;
269
- status: 'running' | 'suspended' | 'completed' | 'failed';
270
- totalRows: number;
271
- completedRowKeys: string[];
272
- pendingRowKeys: string[];
273
- activeBoundaryId?: string | null;
274
- startedAt: number;
275
- updatedAt: number;
276
- }
277
-
278
- export interface MapExecutionScope {
279
- mapInvocationId: string;
280
- mapNodeId?: string | null;
281
- logicalNamespace: string;
282
- artifactTableNamespace: string;
283
- rowIdentity: (row: Record<string, unknown>, index?: number) => string;
284
- }
285
-
286
- export type PlayExecutionEvent =
287
- | {
288
- type: 'map.preparing';
289
- mapInvocationId: string;
290
- mapNodeId?: string | null;
291
- logicalNamespace: string;
292
- artifactTableNamespace: string;
293
- totalRows: number;
294
- completedRows: number;
295
- pendingRows: number;
296
- at: number;
297
- }
298
- | {
299
- type: 'map.started';
300
- mapInvocationId: string;
301
- mapNodeId?: string | null;
302
- logicalNamespace: string;
303
- artifactTableNamespace: string;
304
- totalRows: number;
305
- completedRows: number;
306
- pendingRows: number;
307
- at: number;
308
- }
309
- | {
310
- type: 'map.progress';
311
- mapInvocationId: string;
312
- mapNodeId?: string | null;
313
- logicalNamespace: string;
314
- artifactTableNamespace: string;
315
- completedRows: number;
316
- failedRows: number;
317
- totalRows?: number;
318
- at: number;
319
- }
320
- | {
321
- type: 'map.row.updated';
322
- mapInvocationId: string;
323
- mapNodeId?: string | null;
324
- logicalNamespace: string;
325
- artifactTableNamespace: string;
326
- rowKey: string;
327
- rowStatus?: PlayRowUpdate['status'];
328
- fieldName?: string | null;
329
- stage?: string | null;
330
- provider?: string | null;
331
- at: number;
332
- }
333
- | {
334
- type: 'map.completed' | 'map.suspended' | 'map.resumed' | 'map.failed';
335
- mapInvocationId: string;
336
- mapNodeId?: string | null;
337
- logicalNamespace: string;
338
- artifactTableNamespace: string;
339
- completedRows: number;
340
- failedRows: number;
341
- totalRows?: number;
342
- at: number;
343
- };
344
-
345
- export type IntegrationEventWaitRuntimeContext = {
346
- playId?: string;
347
- runId?: string;
348
- workflowId?: string;
349
- orgId?: string;
350
- executorToken?: string;
351
- };
352
-
353
- export type IntegrationEventWaitBoundary = {
354
- boundaryId: string;
355
- eventKey: string;
356
- timeoutMs: number;
357
- provider: string;
358
- toolId: string;
359
- messageRef?: {
360
- channel: string;
361
- ts: string;
362
- };
363
- };
364
-
365
- export type IntegrationEventWaitHandler = {
366
- provider: string;
367
- toolId: string;
368
- prepare: (input: {
369
- payload: Record<string, unknown>;
370
- context: IntegrationEventWaitRuntimeContext;
371
- }) => IntegrationEventWaitBoundary | Promise<IntegrationEventWaitBoundary>;
372
- arm: (input: {
373
- payload: Record<string, unknown>;
374
- context: IntegrationEventWaitRuntimeContext;
375
- boundary: IntegrationEventWaitBoundary;
376
- }) => Promise<IntegrationEventWaitBoundary>;
377
- };
378
-
379
- export interface ContextOptions {
380
- /** Short-lived HMAC-signed internal token for tool callbacks. Required for cloud execution. */
381
- executorToken?: string;
382
- baseUrl?: string;
383
- orgId?: string;
384
- userEmail?: string;
385
- playName?: string;
386
- convexUrl?: string;
387
- staticPipeline?: PlayStaticPipeline | null;
388
- workflowId?: string;
389
- sessionId?: string;
390
- verbose?: boolean;
391
- /** Heartbeat checkpoint from a previous Temporal activity attempt. */
392
- checkpoint?: PlayCheckpoint;
393
- /** Enables durable boundary replay such as ctx.sleep() resumptions. */
394
- durableBoundaries?: boolean;
395
- /** Called after each durable batch completes — for Temporal heartbeating. */
396
- onBatchComplete?: (checkpoint: PlayCheckpoint) => void;
397
- /** Called when the runtime emits a new execution log line. */
398
- onLog?: (line: string) => void;
399
- /** Called when a row gains new partial data or stage info. */
400
- onRowUpdate?: (update: PlayRowUpdate) => void | Promise<void>;
401
- /** Structured execution events emitted from explicit map scopes. */
402
- onExecutionEvent?: (event: PlayExecutionEvent) => void | Promise<void>;
403
- /**
404
- * Called when ctx.map() starts — inserts items into the sheet and returns
405
- * the pending/completed split. If not provided, all items are processed.
406
- */
407
- onMapStart?: (
408
- items: Record<string, unknown>[],
409
- tableNamespace: string,
410
- context: {
411
- playName?: string;
412
- playId?: string;
413
- runId?: string;
414
- staticPipeline?: PlayStaticPipeline | null;
415
- },
416
- ) => Promise<MapStartResult>;
417
- playId?: string;
418
- runId?: string;
419
- resolvePlay?: (playRef: string) => Promise<ResolvedPlayExecution | null>;
420
- getToolQueueHints?: (toolId: string) => Promise<readonly PlayQueueHint[]>;
421
- getToolResultIdentityGetters?: (
422
- toolId: string,
423
- output: string,
424
- ) => Promise<readonly string[]>;
425
- getToolResultMetadata?: (
426
- toolId: string,
427
- ) => Promise<ToolResultMetadataInput | null> | ToolResultMetadataInput | null;
428
- getIntegrationEventWaitHandler?: (
429
- toolId: string,
430
- ) =>
431
- | IntegrationEventWaitHandler
432
- | null
433
- | Promise<IntegrationEventWaitHandler | null>;
434
- getBatchOperationStrategy?: (
435
- operation: string,
436
- ) => AnyBatchOperationStrategy | null;
437
- executeStructuredPlayDefinition?: (input: {
438
- definition: PlayStructuredDefinition;
439
- ctx: unknown;
440
- rows: Record<string, unknown>[];
441
- playInput: Record<string, unknown>;
442
- }) => Promise<unknown>;
443
- getRuntimeStepReceipt?: (
444
- input: GetRuntimeStepReceiptInput,
445
- ) => Promise<RuntimeStepReceipt | null> | RuntimeStepReceipt | null;
446
- claimRuntimeStepReceipt?: (
447
- input: ClaimRuntimeStepReceiptInput,
448
- ) => Promise<RuntimeStepReceipt | null> | RuntimeStepReceipt | null;
449
- completeRuntimeStepReceipt?: (
450
- input: CompleteRuntimeStepReceiptInput,
451
- ) => Promise<RuntimeStepReceipt | null> | RuntimeStepReceipt | null;
452
- failRuntimeStepReceipt?: (
453
- input: FailRuntimeStepReceiptInput,
454
- ) => Promise<RuntimeStepReceipt | null> | RuntimeStepReceipt | null;
455
- skipRuntimeStepReceipt?: (
456
- input: SkipRuntimeStepReceiptInput,
457
- ) => Promise<RuntimeStepReceipt | null> | RuntimeStepReceipt | null;
458
- governance?: PlayExecutionGovernanceState;
459
- }
460
-
461
- export interface PlayCheckpoint {
462
- /** Waterfall batches that have completed: key = `${toolName}:${provider}`, value = results array. */
463
- completedBatches: Record<string, BatchResult[]>;
464
- /** Tool call batches that have completed: key = toolId, value = sparse row-cache-key -> result map. */
465
- completedToolBatches: Record<string, Record<string, ToolBatchResult>>;
466
- /** Row states resolved from completed batches. */
467
- resolvedWaterfalls: Record<string, Record<string, unknown>>;
468
- /** Durable boundary completions keyed by boundary id. */
469
- resolvedBoundaries?: Record<
470
- string,
471
- | {
472
- kind: 'sleep';
473
- delayMs: number;
474
- completedAt?: number;
475
- scope?: {
476
- type: 'workflow' | 'map_row';
477
- tableNamespace?: string;
478
- rowKey?: string;
479
- rowIndex?: number;
480
- fieldName?: string;
481
- };
482
- }
483
- | {
484
- kind: 'integration_event';
485
- eventKey: string;
486
- timeoutMs: number;
487
- provider?: string;
488
- toolId?: string;
489
- messageRef?: {
490
- channel: string;
491
- ts: string;
492
- };
493
- output?: unknown;
494
- completedAt?: number;
495
- }
496
- | {
497
- kind: 'fetch';
498
- url: string;
499
- method: string;
500
- output?: unknown;
501
- completedAt?: number;
502
- }
503
- | {
504
- kind: 'step';
505
- stepId: string;
506
- output?: unknown;
507
- completedAt?: number;
508
- }
509
- >;
510
- /** Per-map execution frames keyed by invocation id. */
511
- mapFrames?: Record<string, MapExecutionFrame>;
512
- }
513
-
514
- export type PlayFetchResponse = {
515
- ok: boolean;
516
- status: number;
517
- statusText: string;
518
- url: string;
519
- headers: Record<string, string>;
520
- bodyText: string;
521
- json: unknown | null;
522
- };
523
-
524
- export interface BatchResult {
525
- rowId: number;
526
- rowKey?: string | null;
527
- result: unknown | null;
528
- }
529
-
530
- export interface ToolDefinition {
531
- toolId: string;
532
- provider: string;
533
- providers?: string[]; // For waterfalls
534
- supportsBatch?: boolean;
535
- }
536
-
537
- type AwaitedMapValue<T> = T extends Promise<infer U> ? AwaitedMapValue<U> : T;
538
-
539
- export type MapResolvedFields<TColumns extends Record<string, unknown>> = {
540
- [K in keyof TColumns]: AwaitedMapValue<TColumns[K]>;
541
- };
542
-
543
- export type MapAvailableFields<
544
- TItem,
545
- TColumns extends Record<string, unknown>,
546
- > = TItem & Partial<MapResolvedFields<NoInfer<TColumns>>>;
547
-
548
- export type MapFieldResolver<
549
- TItem,
550
- TFields = Record<string, unknown>,
551
- TValue = unknown,
552
- > =
553
- | TValue
554
- | ((
555
- row: TItem,
556
- ctx: unknown,
557
- fields: TFields,
558
- index: number,
559
- ) => TValue | Promise<TValue>);
560
-
561
- export type MapFieldDefinition<
562
- TItem,
563
- TColumns extends Record<string, unknown> = Record<string, unknown>,
564
- > = {
565
- [K in keyof TColumns]: MapFieldResolver<
566
- TItem,
567
- MapAvailableFields<TItem, TColumns>,
568
- TColumns[K]
569
- >;
570
- };
571
-
572
- export type RuntimeStepResolver<
573
- Row = Record<string, unknown>,
574
- Value = unknown,
575
- > = (row: Row, ctx: unknown, index: number) => Value | Promise<Value>;
576
-
577
- export type RuntimeConditionalStepResolver<
578
- Row = Record<string, unknown>,
579
- Value = unknown,
580
- > = {
581
- kind: 'conditional';
582
- when: (row: Row, index: number) => boolean | Promise<boolean>;
583
- run: RuntimeStepResolver<Row, Value>;
584
- elseValue?: unknown;
585
- };
586
-
587
- export type RuntimeStepProgramStep = {
588
- name: string;
589
- resolver:
590
- | RuntimeStepResolver
591
- | RuntimeConditionalStepResolver
592
- | RuntimeStepProgram;
593
- };
594
-
595
- export type RuntimeStepProgram = {
596
- kind: 'steps';
597
- steps: readonly RuntimeStepProgramStep[];
598
- returnResolver?: RuntimeStepResolver;
599
- };
600
-
601
- export type { PlayDataset, PlayDatasetInput };
602
-
603
- // Structured step data for UI visualization
604
- // csv_load is NOT a step — it's part of the run metadata, not the pipeline
605
- export type PlayStep =
606
- | { type: 'start'; trigger?: string; description?: string }
607
- | { type: 'csv_load'; arg?: string; rows?: number; description?: string }
608
- | {
609
- type: 'map';
610
- items: number;
611
- fields?: string[];
612
- substeps: PlayMapSubstep[];
613
- description?: string;
614
- }
615
- | {
616
- type: 'waterfall';
617
- tool?: string;
618
- providers?: string[];
619
- id?: string;
620
- output?: string;
621
- minResults?: number;
622
- steps?: Array<{
623
- id: string;
624
- kind?: 'tool' | 'code';
625
- toolId?: string;
626
- results: PlayStepRowResult[];
627
- }>;
628
- results: PlayStepRowResult[];
629
- description?: string;
630
- }
631
- | {
632
- type: 'tool';
633
- toolId: string;
634
- results: PlayStepRowResult[];
635
- description?: string;
636
- }
637
- | {
638
- type: 'play_call';
639
- playId: string;
640
- results?: PlayStepRowResult[];
641
- nestedSteps: PlayStep[];
642
- description?: string;
643
- }
644
- | {
645
- type: 'run_javascript';
646
- alias: string;
647
- results: PlayStepRowResult[];
648
- description?: string;
649
- }
650
- | { type: 'return'; outputRows: number; description?: string };
651
-
652
- /** Steps that happen INSIDE a ctx.map() — tool/waterfall calls from field resolvers. */
653
- export type PlayMapSubstep =
654
- | {
655
- type: 'waterfall';
656
- tool?: string;
657
- providers?: string[];
658
- id?: string;
659
- output?: string;
660
- minResults?: number;
661
- steps?: Array<{
662
- id: string;
663
- kind?: 'tool' | 'code';
664
- toolId?: string;
665
- results: PlayStepRowResult[];
666
- }>;
667
- results: PlayStepRowResult[];
668
- description?: string;
669
- }
670
- | {
671
- type: 'tool';
672
- toolId: string;
673
- results: PlayStepRowResult[];
674
- description?: string;
675
- }
676
- | {
677
- type: 'play_call';
678
- playId: string;
679
- results?: PlayStepRowResult[];
680
- nestedSteps: PlayStep[];
681
- description?: string;
682
- }
683
- | {
684
- type: 'run_javascript';
685
- alias: string;
686
- results: PlayStepRowResult[];
687
- description?: string;
688
- };
689
-
690
- export interface PlayStepRowResult {
691
- rowId: number;
692
- status: 'completed' | 'failed' | 'missed' | 'skipped';
693
- success: boolean;
694
- provider?: string;
695
- value?: unknown;
696
- error?: string | null;
697
- }
698
-
699
- export interface PlayRowUpdate {
700
- key: string;
701
- rowId: number;
702
- tableNamespace?: string | null;
703
- status?: 'running' | 'completed' | 'failed';
704
- stage?: string | null;
705
- provider?: string | null;
706
- error?: string | null;
707
- dataPatch?: Record<string, unknown>;
708
- cellMetaPatch?: Record<
709
- string,
710
- {
711
- status:
712
- | 'queued'
713
- | 'running'
714
- | 'completed'
715
- | 'failed'
716
- | 'cached'
717
- | 'missed'
718
- | 'skipped';
719
- stage?: string | null;
720
- provider?: string | null;
721
- error?: string | null;
722
- reused?: boolean;
723
- }
724
- >;
725
- }