deepline 0.1.12 → 0.1.20

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 (82) hide show
  1. package/README.md +14 -6
  2. package/dist/cli/index.js +1346 -717
  3. package/dist/cli/index.mjs +1342 -713
  4. package/dist/index.d.mts +199 -23
  5. package/dist/index.d.ts +199 -23
  6. package/dist/index.js +221 -14
  7. package/dist/index.mjs +221 -14
  8. package/dist/repo/apps/play-runner-workers/src/coordinator-entry.ts +214 -77
  9. package/dist/repo/apps/play-runner-workers/src/dedup-do.ts +85 -60
  10. package/dist/repo/apps/play-runner-workers/src/entry.ts +385 -66
  11. package/dist/repo/sdk/src/client.ts +237 -0
  12. package/dist/repo/sdk/src/config.ts +125 -8
  13. package/dist/repo/sdk/src/http.ts +29 -5
  14. package/dist/repo/sdk/src/play.ts +19 -36
  15. package/dist/repo/sdk/src/plays/bundle-play-file.ts +22 -8
  16. package/dist/repo/sdk/src/plays/local-file-discovery.ts +207 -160
  17. package/dist/repo/sdk/src/types.ts +25 -0
  18. package/dist/repo/sdk/src/version.ts +2 -2
  19. package/dist/repo/shared_libs/play-runtime/tool-result.ts +237 -145
  20. package/dist/repo/shared_libs/plays/bundling/index.ts +206 -229
  21. package/dist/repo/shared_libs/plays/dataset.ts +28 -0
  22. package/dist/repo/shared_libs/plays/row-identity.ts +59 -4
  23. package/package.json +5 -4
  24. package/dist/cli/index.js.map +0 -1
  25. package/dist/cli/index.mjs.map +0 -1
  26. package/dist/index.js.map +0 -1
  27. package/dist/index.mjs.map +0 -1
  28. package/dist/repo/apps/play-runner-workers/src/runtime/README.md +0 -21
  29. package/dist/repo/apps/play-runner-workers/src/runtime/batching.ts +0 -177
  30. package/dist/repo/apps/play-runner-workers/src/runtime/execution-plan.ts +0 -52
  31. package/dist/repo/apps/play-runner-workers/src/runtime/tool-batch.ts +0 -100
  32. package/dist/repo/sdk/src/cli/commands/auth.ts +0 -500
  33. package/dist/repo/sdk/src/cli/commands/billing.ts +0 -188
  34. package/dist/repo/sdk/src/cli/commands/csv.ts +0 -123
  35. package/dist/repo/sdk/src/cli/commands/db.ts +0 -119
  36. package/dist/repo/sdk/src/cli/commands/feedback.ts +0 -40
  37. package/dist/repo/sdk/src/cli/commands/org.ts +0 -117
  38. package/dist/repo/sdk/src/cli/commands/play.ts +0 -3441
  39. package/dist/repo/sdk/src/cli/commands/tools.ts +0 -687
  40. package/dist/repo/sdk/src/cli/dataset-stats.ts +0 -415
  41. package/dist/repo/sdk/src/cli/index.ts +0 -148
  42. package/dist/repo/sdk/src/cli/progress.ts +0 -149
  43. package/dist/repo/sdk/src/cli/skills-sync.ts +0 -141
  44. package/dist/repo/sdk/src/cli/trace.ts +0 -61
  45. package/dist/repo/sdk/src/cli/utils.ts +0 -145
  46. package/dist/repo/sdk/src/compat.ts +0 -77
  47. package/dist/repo/shared_libs/observability/node-tracing.ts +0 -129
  48. package/dist/repo/shared_libs/observability/tracing.ts +0 -98
  49. package/dist/repo/shared_libs/play-runtime/context.ts +0 -4242
  50. package/dist/repo/shared_libs/play-runtime/ctx-contract.ts +0 -250
  51. package/dist/repo/shared_libs/play-runtime/ctx-types.ts +0 -725
  52. package/dist/repo/shared_libs/play-runtime/dataset-id.ts +0 -10
  53. package/dist/repo/shared_libs/play-runtime/db-session-crypto.ts +0 -304
  54. package/dist/repo/shared_libs/play-runtime/db-session.ts +0 -462
  55. package/dist/repo/shared_libs/play-runtime/live-events.ts +0 -214
  56. package/dist/repo/shared_libs/play-runtime/live-state-contract.ts +0 -50
  57. package/dist/repo/shared_libs/play-runtime/map-execution-frame.ts +0 -114
  58. package/dist/repo/shared_libs/play-runtime/map-row-identity.ts +0 -158
  59. package/dist/repo/shared_libs/play-runtime/progress-emitter.ts +0 -172
  60. package/dist/repo/shared_libs/play-runtime/protocol.ts +0 -121
  61. package/dist/repo/shared_libs/play-runtime/public-play-contract.ts +0 -42
  62. package/dist/repo/shared_libs/play-runtime/result-normalization.ts +0 -33
  63. package/dist/repo/shared_libs/play-runtime/runtime-api.ts +0 -1873
  64. package/dist/repo/shared_libs/play-runtime/runtime-constraints.ts +0 -2
  65. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-neon-serverless.ts +0 -201
  66. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-pg.ts +0 -48
  67. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver.ts +0 -84
  68. package/dist/repo/shared_libs/play-runtime/static-pipeline-types.ts +0 -147
  69. package/dist/repo/shared_libs/play-runtime/suspension.ts +0 -68
  70. package/dist/repo/shared_libs/play-runtime/tracing.ts +0 -31
  71. package/dist/repo/shared_libs/play-runtime/waterfall-replay.ts +0 -75
  72. package/dist/repo/shared_libs/play-runtime/worker-api-types.ts +0 -140
  73. package/dist/repo/shared_libs/plays/artifact-transport.ts +0 -14
  74. package/dist/repo/shared_libs/plays/artifact-types.ts +0 -49
  75. package/dist/repo/shared_libs/plays/compiler-manifest.ts +0 -186
  76. package/dist/repo/shared_libs/plays/definition.ts +0 -264
  77. package/dist/repo/shared_libs/plays/file-refs.ts +0 -11
  78. package/dist/repo/shared_libs/plays/rate-limit-scheduler.ts +0 -206
  79. package/dist/repo/shared_libs/plays/resolve-static-pipeline.ts +0 -164
  80. package/dist/repo/shared_libs/plays/runtime-validation.ts +0 -395
  81. package/dist/repo/shared_libs/temporal/constants.ts +0 -39
  82. package/dist/repo/shared_libs/temporal/preview-config.ts +0 -153
@@ -1,140 +0,0 @@
1
- export type PlayStagedFileRef = {
2
- storageKind: 'r2';
3
- storageKey: string;
4
- logicalPath: string;
5
- fileName: string;
6
- contentHash: string;
7
- contentType: string;
8
- bytes: number;
9
- };
10
-
11
- export type PlayVisualNodeProgress = {
12
- completed?: number;
13
- total?: number;
14
- failed?: number;
15
- message?: string;
16
- updatedAt?: number;
17
- startedAt?: number;
18
- completedAt?: number;
19
- artifactTableNamespace?: string | null;
20
- };
21
-
22
- export type PlayVisualNodeProgressMap = Record<string, PlayVisualNodeProgress>;
23
-
24
- export type ComputeBillingItem = {
25
- itemId: string;
26
- source: string;
27
- unit: string;
28
- units: number;
29
- providerCostUsd: number;
30
- metadata?: unknown;
31
- };
32
-
33
- const DAYTONA_COMPUTE_PRICING_USD = {
34
- vcpuSecond: 0.000014,
35
- memoryGiBSecond: 0.0000045,
36
- storageGiBSecond: 0.00000003,
37
- includedStorageGiB: 5,
38
- } as const;
39
-
40
- const TEMPORAL_COMPUTE_PRICING_USD = {
41
- action: 50 / 1_000_000,
42
- } as const;
43
-
44
- const NEON_COMPUTE_PRICING_USD = {
45
- cuHour: 0.106,
46
- defaultCu: 1,
47
- } as const;
48
-
49
- function roundUsd(amount: number): number {
50
- return Number(Math.max(0, amount).toFixed(12));
51
- }
52
-
53
- export function resolveDaytonaSandboxComputeItem(input: {
54
- itemId: string;
55
- source?: string;
56
- wallTimeSeconds: number;
57
- cpu: number;
58
- memoryGiB: number;
59
- diskGiB: number;
60
- sandboxId?: string | null;
61
- startedAt?: number;
62
- endedAt?: number;
63
- }): ComputeBillingItem {
64
- const billableSeconds = Math.max(1, Math.ceil(input.wallTimeSeconds));
65
- const cpu = Math.max(0, input.cpu);
66
- const memoryGiB = Math.max(0, input.memoryGiB);
67
- const billableDiskGiB = Math.max(
68
- 0,
69
- input.diskGiB - DAYTONA_COMPUTE_PRICING_USD.includedStorageGiB,
70
- );
71
- const providerCostUsd = roundUsd(
72
- billableSeconds *
73
- (cpu * DAYTONA_COMPUTE_PRICING_USD.vcpuSecond +
74
- memoryGiB * DAYTONA_COMPUTE_PRICING_USD.memoryGiBSecond +
75
- billableDiskGiB *
76
- DAYTONA_COMPUTE_PRICING_USD.storageGiBSecond),
77
- );
78
-
79
- return {
80
- itemId: input.itemId,
81
- source: input.source ?? 'daytona',
82
- unit: 'sandbox_second',
83
- units: billableSeconds,
84
- providerCostUsd,
85
- metadata: {
86
- sandboxId: input.sandboxId ?? null,
87
- cpu,
88
- memoryGiB,
89
- diskGiB: Math.max(0, input.diskGiB),
90
- billableDiskGiB,
91
- startedAt: input.startedAt,
92
- endedAt: input.endedAt,
93
- },
94
- };
95
- }
96
-
97
- export function resolveTemporalComputeItem(input: {
98
- itemId: string;
99
- actions: number;
100
- metadata?: unknown;
101
- }): ComputeBillingItem {
102
- const actions = Math.max(0, Math.ceil(input.actions));
103
- return {
104
- itemId: input.itemId,
105
- source: 'temporal',
106
- unit: 'action',
107
- units: actions,
108
- providerCostUsd: roundUsd(actions * TEMPORAL_COMPUTE_PRICING_USD.action),
109
- metadata: input.metadata,
110
- };
111
- }
112
-
113
- export function resolveNeonComputeItem(input: {
114
- itemId: string;
115
- activeSeconds: number;
116
- cu?: number;
117
- metadata?: unknown;
118
- }): ComputeBillingItem {
119
- const billableSeconds = Math.max(0, Math.ceil(input.activeSeconds));
120
- const cu = Math.max(0, input.cu ?? NEON_COMPUTE_PRICING_USD.defaultCu);
121
- return {
122
- itemId: input.itemId,
123
- source: 'neon',
124
- unit: 'cu_second',
125
- units: billableSeconds * cu,
126
- providerCostUsd: roundUsd(
127
- billableSeconds * cu * (NEON_COMPUTE_PRICING_USD.cuHour / 3600),
128
- ),
129
- metadata: {
130
- activeSeconds: billableSeconds,
131
- cu,
132
- cuHourUsd: NEON_COMPUTE_PRICING_USD.cuHour,
133
- ...(input.metadata && typeof input.metadata === 'object'
134
- ? (input.metadata as Record<string, unknown>)
135
- : input.metadata !== undefined
136
- ? { inputMetadata: input.metadata }
137
- : {}),
138
- },
139
- };
140
- }
@@ -1,14 +0,0 @@
1
- import type { PlayBundleArtifact } from './artifact-types';
2
-
3
- const INLINE_SOURCE_MAP_PATTERN =
4
- /\r?\n?\/\/# sourceMappingURL=data:application\/json;base64,[A-Za-z0-9+/=]+\s*$/;
5
-
6
- export function compactPlayArtifactForRuntimeTransport(
7
- artifact: PlayBundleArtifact,
8
- ): PlayBundleArtifact {
9
- return {
10
- ...artifact,
11
- bundledCode: artifact.bundledCode.replace(INLINE_SOURCE_MAP_PATTERN, ''),
12
- sourceMap: '',
13
- };
14
- }
@@ -1,49 +0,0 @@
1
- export type PlayPackageImport = {
2
- name: string;
3
- version: string | null;
4
- };
5
-
6
- export type PlayImportPolicy = {
7
- localFiles: string[];
8
- nodeBuiltins: string[];
9
- packages: PlayPackageImport[];
10
- };
11
-
12
- export type PlayRuntimeFeature =
13
- | 'artifact_storage'
14
- | 'checkpoint_resume'
15
- | 'durable_sleep'
16
- | 'packaged_files';
17
-
18
- export type PlayArtifactCompatibility = {
19
- apiVersion: number;
20
- artifactVersion: number;
21
- minRunnerVersion: number;
22
- runtimeFeatures: PlayRuntimeFeature[];
23
- runtimeBackend?: string | null;
24
- };
25
-
26
- /**
27
- * Identifies which runtime can consume this artifact:
28
- * - cjs_node20: Daytona / local-process (Node.js)
29
- * - esm_workers: Cloudflare Workers (V8 isolate)
30
- */
31
- export type PlayArtifactKind = 'cjs_node20' | 'esm_workers';
32
-
33
- export type PlayBundleArtifact = {
34
- codeFormat: 'cjs_module' | 'esm_module';
35
- /** Defaults to cjs_node20 when not present (legacy artifacts). */
36
- artifactKind?: PlayArtifactKind;
37
- entryFile: string;
38
- virtualFilename: string;
39
- sourceHash: string;
40
- graphHash: string;
41
- artifactHash: string;
42
- sourceMapHash: string;
43
- bundledCode: string;
44
- sourceMap: string;
45
- importPolicy: PlayImportPolicy;
46
- compatibility: PlayArtifactCompatibility;
47
- generatedAt: number;
48
- cacheHit: boolean;
49
- };
@@ -1,186 +0,0 @@
1
- import type { PlayArtifactKind } from '../play-runtime/backend';
2
-
3
- export interface PlayStaticPipelineSnapshot {
4
- tableNamespace?: string;
5
- inputFields?: string[];
6
- csvArg?: string;
7
- hasInlineData?: boolean;
8
- csvDescription?: string;
9
- mapDescription?: string;
10
- fields: string[];
11
- stages?: PlayStaticSubstepSnapshot[];
12
- substeps: PlayStaticSubstepSnapshot[];
13
- sheetContract?: PlaySheetContractSnapshot | null;
14
- sheetContractErrors?: string[];
15
- }
16
-
17
- export type PlaySheetColumnSourceSnapshot =
18
- | 'input'
19
- | 'mapField'
20
- | 'waterfallStep'
21
- | 'childPlayColumn';
22
-
23
- export interface PlaySheetColumnContractSnapshot {
24
- id: string;
25
- sqlName: string;
26
- source: PlaySheetColumnSourceSnapshot;
27
- field?: string;
28
- parentField?: string;
29
- playId?: string;
30
- waterfallId?: string;
31
- outputField?: string;
32
- outputSqlName?: string;
33
- stepId?: string;
34
- toolId?: string;
35
- }
36
-
37
- export interface PlaySheetContractSnapshot {
38
- tableNamespace: string;
39
- columns: PlaySheetColumnContractSnapshot[];
40
- }
41
-
42
- export interface PlayStaticSourceRangeSnapshot {
43
- sourcePath?: string;
44
- startLine: number;
45
- endLine: number;
46
- startColumn: number;
47
- endColumn: number;
48
- }
49
-
50
- type PlayStaticSubstepMetadataSnapshot = {
51
- conditional?: boolean;
52
- };
53
-
54
- export type PlayStaticSubstepSnapshot = PlayStaticSubstepMetadataSnapshot &
55
- (
56
- | {
57
- type: 'csv';
58
- field: string;
59
- path?: string;
60
- description?: string;
61
- sourceRange?: PlayStaticSourceRangeSnapshot;
62
- callDepth?: number;
63
- callPath?: string[];
64
- }
65
- | {
66
- type: 'map';
67
- field: string;
68
- name?: string;
69
- tableNamespace?: string;
70
- inputFields?: string[];
71
- outputFields?: string[];
72
- waterfallIds?: string[];
73
- sheetContract?: PlaySheetContractSnapshot | null;
74
- description?: string;
75
- sourceRange?: PlayStaticSourceRangeSnapshot;
76
- callDepth?: number;
77
- callPath?: string[];
78
- }
79
- | {
80
- type: 'tool';
81
- toolId: string;
82
- field: string;
83
- description?: string;
84
- inLoop?: boolean;
85
- isEventWait?: boolean;
86
- sourceRange?: PlayStaticSourceRangeSnapshot;
87
- callDepth?: number;
88
- callPath?: string[];
89
- }
90
- | {
91
- type: 'waterfall';
92
- tool?: string;
93
- field: string;
94
- inLoop?: boolean;
95
- id?: string;
96
- output?: string;
97
- minResults?: number;
98
- sourceText?: string;
99
- steps?: Array<{
100
- id: string;
101
- kind?: 'tool' | 'code';
102
- toolId?: string;
103
- paramsSource?: string;
104
- }>;
105
- description?: string;
106
- sourceRange?: PlayStaticSourceRangeSnapshot;
107
- callDepth?: number;
108
- callPath?: string[];
109
- }
110
- | {
111
- type: 'step_suite';
112
- field: string;
113
- steps: PlayStaticSubstepSnapshot[];
114
- returnSource?: string;
115
- description?: string;
116
- sourceRange?: PlayStaticSourceRangeSnapshot;
117
- callDepth?: number;
118
- callPath?: string[];
119
- }
120
- | {
121
- type: 'play_call';
122
- playId: string;
123
- field: string;
124
- inLoop?: boolean;
125
- pipeline?: PlayStaticPipelineSnapshot | null;
126
- cycleDetected?: boolean;
127
- resolutionError?: string;
128
- description?: string;
129
- sourceRange?: PlayStaticSourceRangeSnapshot;
130
- callDepth?: number;
131
- callPath?: string[];
132
- }
133
- | {
134
- type: 'run_javascript';
135
- alias: string;
136
- description?: string;
137
- sourceRange?: PlayStaticSourceRangeSnapshot;
138
- callDepth?: number;
139
- callPath?: string[];
140
- }
141
- | {
142
- type: 'code';
143
- field: string;
144
- description?: string;
145
- sourceRange?: PlayStaticSourceRangeSnapshot;
146
- callDepth?: number;
147
- callPath?: string[];
148
- }
149
- );
150
-
151
- export const PLAY_COMPILER_MANIFEST_VERSION = 1;
152
-
153
- export type PlayCompilerDependencyManifest = {
154
- playName: string;
155
- sourceHash: string;
156
- graphHash: string;
157
- artifactHash: string;
158
- staticPipeline: PlayStaticPipelineSnapshot;
159
- };
160
-
161
- export type PlayCompilerManifest = {
162
- compilerVersion: number;
163
- playName: string;
164
- sourceHash: string;
165
- graphHash: string;
166
- artifactHash: string;
167
- artifactKind?: PlayArtifactKind;
168
- staticPipeline: PlayStaticPipelineSnapshot;
169
- importedPlayDependencies: PlayCompilerDependencyManifest[];
170
- };
171
-
172
- export type PlayRuntimeManifest = {
173
- playName?: string;
174
- graphHash: string;
175
- artifactHash: string;
176
- artifactStorageKey: string;
177
- staticPipelineHash: string;
178
- staticPipeline: PlayStaticPipelineSnapshot;
179
- compiledAt: number;
180
- compilerVersion: string;
181
- sourceCode?: string | null;
182
- bundledCode?: string | null;
183
- maxCreditsPerRun?: number | null;
184
- };
185
-
186
- export type PlayRuntimeManifestMap = Record<string, PlayRuntimeManifest>;
@@ -1,264 +0,0 @@
1
- export type PlayPrimitive = string | number | boolean | null;
2
-
3
- export type PlayValueTemplate =
4
- | PlayPrimitive
5
- | { $ref: string }
6
- | { [key: string]: PlayValueTemplate }
7
- | PlayValueTemplate[];
8
-
9
- export type SerializedPlayJavascript = {
10
- kind: 'serialized_javascript';
11
- source: string;
12
- displayName?: string;
13
- };
14
-
15
- export type PlayJavascriptExecutorContext = {
16
- row: Record<string, unknown>;
17
- steps: Record<string, unknown>;
18
- input: Record<string, unknown>;
19
- index: number;
20
- };
21
-
22
- export type PlayJavascriptExecutor<TResult = unknown> = (
23
- context: PlayJavascriptExecutorContext,
24
- ) => TResult | Promise<TResult>;
25
-
26
- export type PlayStructuredStep =
27
- | {
28
- type: 'tool';
29
- alias: string;
30
- toolId: string;
31
- input: Record<string, PlayValueTemplate>;
32
- description?: string;
33
- }
34
- | {
35
- type: 'waterfall';
36
- alias: string;
37
- tool: string;
38
- input: Record<string, PlayValueTemplate>;
39
- providers?: string[];
40
- description?: string;
41
- }
42
- | {
43
- type: 'run_javascript';
44
- alias: string;
45
- execute: SerializedPlayJavascript;
46
- input?: Record<string, PlayValueTemplate>;
47
- description?: string;
48
- displayAs?: 'run_javascript';
49
- };
50
-
51
- export type PlayStructuredDefinition = {
52
- version: 1;
53
- map: {
54
- key: string;
55
- steps: PlayStructuredStep[];
56
- };
57
- result?: {
58
- mode?: 'rows';
59
- };
60
- };
61
-
62
- export function serializeExecutableJs<TResult = unknown>(
63
- execute: PlayJavascriptExecutor<TResult>,
64
- displayName?: string,
65
- ): SerializedPlayJavascript {
66
- const source = execute.toString().trim();
67
- if (!source) {
68
- throw new Error('Executable JavaScript function source must be non-empty.');
69
- }
70
- return {
71
- kind: 'serialized_javascript',
72
- source,
73
- displayName,
74
- };
75
- }
76
-
77
- export function runJavascriptStep<TResult = unknown>(input: {
78
- alias: string;
79
- execute: PlayJavascriptExecutor<TResult>;
80
- description?: string;
81
- input?: Record<string, PlayValueTemplate>;
82
- }): Extract<PlayStructuredStep, { type: 'run_javascript' }> {
83
- return {
84
- type: 'run_javascript',
85
- alias: input.alias,
86
- execute: serializeExecutableJs(input.execute, input.alias),
87
- ...(input.description ? { description: input.description } : {}),
88
- ...(input.input ? { input: input.input } : {}),
89
- displayAs: 'run_javascript',
90
- };
91
- }
92
-
93
- export function definePlayDefinition(
94
- definition: PlayStructuredDefinition,
95
- ): PlayStructuredDefinition {
96
- return definition;
97
- }
98
-
99
- function formatTemplate(template: PlayValueTemplate): string {
100
- if (
101
- template === null ||
102
- typeof template === 'string' ||
103
- typeof template === 'number' ||
104
- typeof template === 'boolean'
105
- ) {
106
- return JSON.stringify(template);
107
- }
108
- if (Array.isArray(template)) {
109
- return `[${template.map((value) => formatTemplate(value)).join(', ')}]`;
110
- }
111
- if ('$ref' in template && typeof template.$ref === 'string') {
112
- return `ref(${JSON.stringify(template.$ref)})`;
113
- }
114
- return `{ ${Object.entries(template)
115
- .map(([key, value]) => `${JSON.stringify(key)}: ${formatTemplate(value)}`)
116
- .join(', ')} }`;
117
- }
118
-
119
- export function renderPlayDefinitionSource(
120
- definition: PlayStructuredDefinition,
121
- ): string {
122
- const lines: string[] = [];
123
- lines.push('definePlayDefinition({');
124
- lines.push(' version: 1,');
125
- lines.push(' map: {');
126
- lines.push(` key: ${JSON.stringify(definition.map.key)},`);
127
- lines.push(' steps: [');
128
- for (const step of definition.map.steps) {
129
- if (step.type === 'tool') {
130
- lines.push(' {');
131
- lines.push(' type: "tool",');
132
- lines.push(` alias: ${JSON.stringify(step.alias)},`);
133
- lines.push(` toolId: ${JSON.stringify(step.toolId)},`);
134
- lines.push(` input: ${formatTemplate(step.input)},`);
135
- if (step.description) {
136
- lines.push(` description: ${JSON.stringify(step.description)},`);
137
- }
138
- lines.push(' },');
139
- continue;
140
- }
141
- if (step.type === 'waterfall') {
142
- lines.push(' {');
143
- lines.push(' type: "waterfall",');
144
- lines.push(` alias: ${JSON.stringify(step.alias)},`);
145
- lines.push(` tool: ${JSON.stringify(step.tool)},`);
146
- lines.push(` input: ${formatTemplate(step.input)},`);
147
- if (step.providers?.length) {
148
- lines.push(` providers: ${JSON.stringify(step.providers)},`);
149
- }
150
- if (step.description) {
151
- lines.push(` description: ${JSON.stringify(step.description)},`);
152
- }
153
- lines.push(' },');
154
- continue;
155
- }
156
- lines.push(` runJavascriptStep({
157
- alias: ${JSON.stringify(step.alias)},
158
- execute: ${step.execute.source},
159
- ${step.input ? `input: ${formatTemplate(step.input)},` : ''}
160
- }),`);
161
- }
162
- lines.push(' ],');
163
- lines.push(' },');
164
- lines.push('});');
165
- return lines.join('\n');
166
- }
167
-
168
- export function validatePlayStructuredDefinition(
169
- definition: unknown,
170
- ): { valid: boolean; errors: string[] } {
171
- const errors: string[] = [];
172
- if (!definition || typeof definition !== 'object') {
173
- return { valid: false, errors: ['Definition must be an object.'] };
174
- }
175
- const candidate = definition as Partial<PlayStructuredDefinition>;
176
- if (candidate.version !== 1) {
177
- errors.push('Definition version must be 1.');
178
- }
179
- if (typeof candidate.map?.key !== 'string' || !candidate.map.key.trim()) {
180
- errors.push('Definition map.key must be a non-empty string.');
181
- }
182
- if (!Array.isArray(candidate.map?.steps) || candidate.map.steps.length === 0) {
183
- errors.push('Definition must contain at least one step.');
184
- }
185
- for (const [index, step] of (candidate.map?.steps ?? []).entries()) {
186
- if (!step || typeof step !== 'object') {
187
- errors.push(`Step ${index} must be an object.`);
188
- continue;
189
- }
190
- const typedStep = step as PlayStructuredStep;
191
- if (!typedStep.alias?.trim()) {
192
- errors.push(`Step ${index} requires a non-empty alias.`);
193
- }
194
- if (typedStep.type === 'tool' && !typedStep.toolId?.trim()) {
195
- errors.push(`Tool step ${typedStep.alias || index} requires toolId.`);
196
- }
197
- if (typedStep.type === 'waterfall' && !typedStep.tool?.trim()) {
198
- errors.push(`Waterfall step ${typedStep.alias || index} requires tool.`);
199
- }
200
- if (typedStep.type === 'run_javascript') {
201
- if (!typedStep.execute?.source?.trim()) {
202
- errors.push(`run_javascript step ${typedStep.alias || index} requires executable source.`);
203
- continue;
204
- }
205
- try {
206
- new Function(`return (${typedStep.execute.source});`);
207
- } catch (error) {
208
- errors.push(
209
- `run_javascript step ${typedStep.alias || index} parse error: ${
210
- error instanceof Error ? error.message : String(error)
211
- }`,
212
- );
213
- }
214
- }
215
- }
216
- return { valid: errors.length === 0, errors };
217
- }
218
-
219
- function getPathValue(
220
- value: unknown,
221
- path: string,
222
- ): unknown {
223
- if (!path) return value;
224
- const normalized = path.replace(/^\$?/, '');
225
- const parts = normalized.split('.').filter(Boolean);
226
- let current = value;
227
- for (const part of parts) {
228
- if (current == null || typeof current !== 'object') return undefined;
229
- current = (current as Record<string, unknown>)[part];
230
- }
231
- return current;
232
- }
233
-
234
- export function resolvePlayValueTemplate(
235
- template: PlayValueTemplate,
236
- context: PlayJavascriptExecutorContext,
237
- ): unknown {
238
- if (
239
- template === null ||
240
- typeof template === 'string' ||
241
- typeof template === 'number' ||
242
- typeof template === 'boolean'
243
- ) {
244
- return template;
245
- }
246
- if (Array.isArray(template)) {
247
- return template.map((item) => resolvePlayValueTemplate(item, context));
248
- }
249
- if ('$ref' in template && typeof template.$ref === 'string') {
250
- const [root, ...rest] = template.$ref.split('.');
251
- const path = rest.join('.');
252
- if (root === 'row') return getPathValue(context.row, path);
253
- if (root === 'steps') return getPathValue(context.steps, path);
254
- if (root === 'input') return getPathValue(context.input, path);
255
- if (root === 'index') return context.index;
256
- return undefined;
257
- }
258
- return Object.fromEntries(
259
- Object.entries(template).map(([key, value]) => [
260
- key,
261
- resolvePlayValueTemplate(value, context),
262
- ]),
263
- );
264
- }
@@ -1,11 +0,0 @@
1
- export interface PlayR2FileRef {
2
- storageKind: 'r2';
3
- storageKey: string;
4
- logicalPath: string;
5
- fileName: string;
6
- contentHash: string;
7
- contentType: string;
8
- bytes: number;
9
- }
10
-
11
- export type PlayExecutionFileRef = PlayR2FileRef;