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,206 +0,0 @@
1
- const DEFAULT_SUGGESTED_MAX_PARALLELISM = 50;
2
- const MIN_CONCURRENCY_WAIT_MS = 10;
3
-
4
- type BucketState = {
5
- windowStartedAt: number;
6
- startedInWindow: number;
7
- activeCount: number;
8
- };
9
-
10
- export interface PlayQueueHint {
11
- bucketId: string;
12
- provider: string;
13
- operation: string;
14
- ruleId: string;
15
- requestsPerWindow: number;
16
- windowMs: number;
17
- maxConcurrency: number | null;
18
- }
19
-
20
- type SchedulerOptions = {
21
- now?: () => number;
22
- sleep?: (ms: number) => Promise<void>;
23
- maxSuggestedParallelism?: number;
24
- getQueueHints?: (toolId: string) => Promise<readonly PlayQueueHint[]>;
25
- };
26
-
27
- export async function getSuggestedPlayToolParallelism(
28
- toolId: string,
29
- fallback: number,
30
- maxSuggestedParallelism = DEFAULT_SUGGESTED_MAX_PARALLELISM,
31
- getQueueHints: (toolId: string) => Promise<readonly PlayQueueHint[]> = async () => [],
32
- ): Promise<number> {
33
- const hints = await getQueueHints(toolId);
34
- if (hints.length === 0) {
35
- return fallback;
36
- }
37
-
38
- const limits = hints.flatMap((hint) =>
39
- hint.maxConcurrency != null
40
- ? [hint.requestsPerWindow, hint.maxConcurrency]
41
- : [hint.requestsPerWindow],
42
- );
43
-
44
- return Math.max(1, Math.min(maxSuggestedParallelism, ...limits));
45
- }
46
-
47
- export class PlayRateLimitScheduler {
48
- private readonly bucketStates = new Map<string, BucketState>();
49
- private lock: Promise<void> = Promise.resolve();
50
- private readonly now;
51
- private readonly sleep;
52
- private readonly maxSuggestedParallelism;
53
- private readonly getQueueHints;
54
-
55
- constructor(options: SchedulerOptions = {}) {
56
- this.now = options.now ?? (() => Date.now());
57
- this.sleep = options.sleep ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms)));
58
- this.maxSuggestedParallelism =
59
- options.maxSuggestedParallelism ?? DEFAULT_SUGGESTED_MAX_PARALLELISM;
60
- this.getQueueHints = options.getQueueHints ?? (async () => []);
61
- }
62
-
63
- async getSuggestedParallelism(toolId: string, fallback: number): Promise<number> {
64
- return await getSuggestedPlayToolParallelism(
65
- toolId,
66
- fallback,
67
- this.maxSuggestedParallelism,
68
- this.getQueueHints,
69
- );
70
- }
71
-
72
- async run<T>(toolId: string, task: () => Promise<T>): Promise<T> {
73
- const hints = await this.getQueueHints(toolId);
74
- if (hints.length === 0) {
75
- return await task();
76
- }
77
-
78
- await this.acquire(hints);
79
- try {
80
- return await task();
81
- } finally {
82
- await this.release(hints);
83
- }
84
- }
85
-
86
- private async acquire(hints: readonly PlayQueueHint[]): Promise<void> {
87
- const orderedHints = [...hints].sort((left, right) =>
88
- left.bucketId.localeCompare(right.bucketId),
89
- );
90
-
91
- while (true) {
92
- const decision = await this.withLock(() => {
93
- const now = this.now();
94
- let waitMs = 0;
95
-
96
- for (const hint of orderedHints) {
97
- const state = this.getBucketState(hint.bucketId, now);
98
- this.resetExpiredWindow(state, hint.windowMs, now);
99
-
100
- if (state.startedInWindow >= hint.requestsPerWindow) {
101
- waitMs = Math.max(
102
- waitMs,
103
- state.windowStartedAt + hint.windowMs - now,
104
- );
105
- }
106
-
107
- if (
108
- hint.maxConcurrency != null &&
109
- state.activeCount >= hint.maxConcurrency
110
- ) {
111
- waitMs = Math.max(waitMs, MIN_CONCURRENCY_WAIT_MS);
112
- }
113
- }
114
-
115
- if (waitMs > 0) {
116
- return { acquired: false, waitMs: Math.max(1, waitMs) } as const;
117
- }
118
-
119
- for (const hint of orderedHints) {
120
- const state = this.getBucketState(hint.bucketId, now);
121
- state.startedInWindow += 1;
122
- if (hint.maxConcurrency != null) {
123
- state.activeCount += 1;
124
- }
125
- }
126
-
127
- return { acquired: true, waitMs: 0 } as const;
128
- });
129
-
130
- if (decision.acquired) {
131
- return;
132
- }
133
-
134
- await this.sleep(decision.waitMs);
135
- }
136
- }
137
-
138
- private async release(hints: readonly PlayQueueHint[]): Promise<void> {
139
- await this.withLock(() => {
140
- for (const hint of hints) {
141
- if (hint.maxConcurrency == null) {
142
- continue;
143
- }
144
- const state = this.bucketStates.get(hint.bucketId);
145
- if (!state || state.activeCount <= 0) {
146
- continue;
147
- }
148
- state.activeCount -= 1;
149
- }
150
- });
151
- }
152
-
153
- private getBucketState(bucketId: string, now: number): BucketState {
154
- const existing = this.bucketStates.get(bucketId);
155
- if (existing) {
156
- return existing;
157
- }
158
-
159
- const created: BucketState = {
160
- windowStartedAt: now,
161
- startedInWindow: 0,
162
- activeCount: 0,
163
- };
164
- this.bucketStates.set(bucketId, created);
165
- return created;
166
- }
167
-
168
- private resetExpiredWindow(
169
- state: BucketState,
170
- windowMs: number,
171
- now: number,
172
- ): void {
173
- if (windowMs <= 0) {
174
- state.windowStartedAt = now;
175
- state.startedInWindow = 0;
176
- return;
177
- }
178
-
179
- if (now - state.windowStartedAt < windowMs) {
180
- return;
181
- }
182
-
183
- const windowsElapsed = Math.floor((now - state.windowStartedAt) / windowMs);
184
- state.windowStartedAt += windowsElapsed * windowMs;
185
- state.startedInWindow = 0;
186
-
187
- if (now - state.windowStartedAt >= windowMs) {
188
- state.windowStartedAt = now;
189
- }
190
- }
191
-
192
- private async withLock<T>(fn: () => T | Promise<T>): Promise<T> {
193
- const previous = this.lock;
194
- let releaseLock!: () => void;
195
- this.lock = new Promise<void>((resolve) => {
196
- releaseLock = resolve;
197
- });
198
-
199
- await previous;
200
- try {
201
- return await fn();
202
- } finally {
203
- releaseLock();
204
- }
205
- }
206
- }
@@ -1,164 +0,0 @@
1
- import type {
2
- PlaySheetContract,
3
- PlayStaticPipeline,
4
- PlayStaticSubstep,
5
- } from './static-pipeline';
6
- import { compileSheetContract } from './static-pipeline';
7
-
8
- export type ResolvablePlayStaticShape = {
9
- staticPipeline?: PlayStaticPipeline | null;
10
- };
11
-
12
- export type ResolveStaticPipelineInput = {
13
- rootPlayId: string;
14
- root: ResolvablePlayStaticShape;
15
- resolveReferencedPlay: (playId: string) => Promise<ResolvablePlayStaticShape | null>;
16
- maxDepth?: number;
17
- };
18
-
19
- function clonePipeline(pipeline: PlayStaticPipeline): PlayStaticPipeline {
20
- return {
21
- ...pipeline,
22
- inputFields: pipeline.inputFields ? [...pipeline.inputFields] : undefined,
23
- fields: [...pipeline.fields],
24
- stages: (pipeline.stages ?? []).map((stage) => ({ ...stage })),
25
- substeps: pipeline.substeps.map((substep) => ({ ...substep })),
26
- sheetContract: cloneSheetContract(pipeline.sheetContract),
27
- sheetContractErrors: undefined,
28
- };
29
- }
30
-
31
- function cloneSheetContract(contract: PlaySheetContract | null | undefined) {
32
- if (!contract) return contract;
33
- return {
34
- ...contract,
35
- columns: contract.columns.map((column) => ({ ...column })),
36
- };
37
- }
38
-
39
- function materializePipeline(shape: ResolvablePlayStaticShape | null): PlayStaticPipeline | null {
40
- if (!shape) return null;
41
- if (shape.staticPipeline) {
42
- return clonePipeline(shape.staticPipeline);
43
- }
44
- return null;
45
- }
46
-
47
- function annotateSubstep(
48
- substep: PlayStaticSubstep,
49
- input: { callDepth: number; callPath: string[] },
50
- ): PlayStaticSubstep {
51
- return {
52
- ...substep,
53
- callDepth: input.callDepth,
54
- callPath: input.callPath,
55
- };
56
- }
57
-
58
- async function resolvePipelineSubsteps(input: {
59
- steps: PlayStaticSubstep[];
60
- resolveReferencedPlay: (playId: string) => Promise<ResolvablePlayStaticShape | null>;
61
- stack: string[];
62
- maxDepth: number;
63
- }): Promise<PlayStaticSubstep[]> {
64
- const { steps, resolveReferencedPlay, stack, maxDepth } = input;
65
- const callDepth = Math.max(0, stack.length - 1);
66
-
67
- return await Promise.all(
68
- steps.map(async (substep) => {
69
- const annotated = annotateSubstep(substep, {
70
- callDepth,
71
- callPath: [...stack],
72
- });
73
-
74
- if (annotated.type !== 'play_call') {
75
- return annotated;
76
- }
77
-
78
- if (stack.includes(annotated.playId)) {
79
- return {
80
- ...annotated,
81
- cycleDetected: true,
82
- resolutionError: `Static cycle detected: ${[...stack, annotated.playId].join(' -> ')}`,
83
- pipeline: null,
84
- } satisfies PlayStaticSubstep;
85
- }
86
-
87
- if (stack.length >= maxDepth) {
88
- return {
89
- ...annotated,
90
- resolutionError: `Static nesting limit reached at ${annotated.playId}`,
91
- pipeline: null,
92
- } satisfies PlayStaticSubstep;
93
- }
94
-
95
- const childShape = await resolveReferencedPlay(annotated.playId);
96
- const childPipeline = materializePipeline(childShape);
97
- if (!childPipeline) {
98
- return {
99
- ...annotated,
100
- resolutionError: `Unable to statically resolve play "${annotated.playId}"`,
101
- pipeline: null,
102
- } satisfies PlayStaticSubstep;
103
- }
104
-
105
- const resolvedChildPipeline = {
106
- ...childPipeline,
107
- stages: await resolvePipelineSubsteps({
108
- steps: childPipeline.stages ?? [],
109
- resolveReferencedPlay,
110
- stack: [...stack, annotated.playId],
111
- maxDepth,
112
- }),
113
- substeps: await resolvePipelineSubsteps({
114
- steps: childPipeline.substeps,
115
- resolveReferencedPlay,
116
- stack: [...stack, annotated.playId],
117
- maxDepth,
118
- }),
119
- };
120
- const childContract = compileSheetContract(resolvedChildPipeline);
121
-
122
- return {
123
- ...annotated,
124
- pipeline: {
125
- ...resolvedChildPipeline,
126
- sheetContract: childContract.contract,
127
- sheetContractErrors: childContract.errors,
128
- },
129
- } satisfies PlayStaticSubstep;
130
- }),
131
- );
132
- }
133
-
134
- export async function resolveStaticPipelineTree(
135
- input: ResolveStaticPipelineInput,
136
- ): Promise<PlayStaticPipeline | null> {
137
- const maxDepth = input.maxDepth ?? 6;
138
- const rootPipeline = materializePipeline(input.root);
139
- if (!rootPipeline) {
140
- return null;
141
- }
142
-
143
- const resolvedPipeline = {
144
- ...rootPipeline,
145
- stages: await resolvePipelineSubsteps({
146
- steps: rootPipeline.stages ?? [],
147
- resolveReferencedPlay: input.resolveReferencedPlay,
148
- stack: [input.rootPlayId],
149
- maxDepth,
150
- }),
151
- substeps: await resolvePipelineSubsteps({
152
- steps: rootPipeline.substeps,
153
- resolveReferencedPlay: input.resolveReferencedPlay,
154
- stack: [input.rootPlayId],
155
- maxDepth,
156
- }),
157
- };
158
- const contract = compileSheetContract(resolvedPipeline);
159
- return {
160
- ...resolvedPipeline,
161
- sheetContract: contract.contract,
162
- sheetContractErrors: contract.errors,
163
- };
164
- }