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,177 +0,0 @@
1
- /**
2
- * Tiny batching helpers for the per-play Worker runtime.
3
- *
4
- * This mirrors the small subset of shared_libs/play-runtime batching that the
5
- * Workers harness needs without importing the broader shared runtime graph.
6
- */
7
-
8
- import type { AnyBatchOperationStrategy } from '../../../../shared_libs/play-runtime/batching-types';
9
-
10
- export type ChunkExecutionResult<TRequest, TResult> = {
11
- request: TRequest;
12
- result: TResult | null;
13
- };
14
-
15
- export async function executeChunkedRequests<TRequest, TResult>(input: {
16
- requests: TRequest[];
17
- batchSize: number;
18
- execute: (request: TRequest) => Promise<TResult>;
19
- onChunkComplete?: (
20
- results: Array<ChunkExecutionResult<TRequest, TResult>>,
21
- ) => void | Promise<void>;
22
- }): Promise<Array<ChunkExecutionResult<TRequest, TResult>>> {
23
- const results: Array<ChunkExecutionResult<TRequest, TResult>> = [];
24
- for (let start = 0; start < input.requests.length; start += input.batchSize) {
25
- const chunk = input.requests.slice(start, start + input.batchSize);
26
- const settled = await Promise.allSettled(
27
- chunk.map((request) => input.execute(request)),
28
- );
29
- const rejected = settled.find(
30
- (outcome): outcome is PromiseRejectedResult =>
31
- outcome.status === 'rejected',
32
- );
33
- if (rejected) {
34
- throw new Error(
35
- `Play batch request failed: ${
36
- rejected.reason instanceof Error
37
- ? rejected.reason.message
38
- : String(rejected.reason)
39
- }`,
40
- { cause: rejected.reason },
41
- );
42
- }
43
- for (let index = 0; index < chunk.length; index += 1) {
44
- const outcome = settled[index] as PromiseFulfilledResult<TResult>;
45
- results.push({ request: chunk[index]!, result: outcome.value });
46
- }
47
- await input.onChunkComplete?.(results.slice(results.length - chunk.length));
48
- }
49
- return results;
50
- }
51
-
52
- export function compileRequestsWithStrategy<TRequest>(input: {
53
- requests: TRequest[];
54
- strategy: AnyBatchOperationStrategy;
55
- getPayload: (request: TRequest) => Record<string, unknown>;
56
- }): Array<{
57
- batchOperation: string;
58
- memberRequests: TRequest[];
59
- batchPayload: Record<string, unknown>;
60
- splitResults: (value: unknown) => Array<unknown | null>;
61
- }> {
62
- const compiledBatches: Array<{
63
- batchOperation: string;
64
- memberRequests: TRequest[];
65
- batchPayload: Record<string, unknown>;
66
- splitResults: (value: unknown) => Array<unknown | null>;
67
- }> = [];
68
- const bucketedRequests = new Map<string, TRequest[]>();
69
- for (const request of input.requests) {
70
- const payload = input.getPayload(request);
71
- const bucketKey = String(input.strategy.toBucketKey(payload));
72
- const bucket = bucketedRequests.get(bucketKey);
73
- if (bucket) bucket.push(request);
74
- else bucketedRequests.set(bucketKey, [request]);
75
- }
76
- for (const bucketRequests of bucketedRequests.values()) {
77
- let currentBatch: TRequest[] = [];
78
- const flushBatch = () => {
79
- if (currentBatch.length === 0) return;
80
- const memberRequests = [...currentBatch];
81
- const compiled = input.strategy.compile(
82
- memberRequests.map((request) => input.getPayload(request)),
83
- );
84
- compiledBatches.push({
85
- batchOperation: compiled.batchOperation,
86
- memberRequests,
87
- batchPayload: compiled.batchPayload,
88
- splitResults: (value: unknown) => {
89
- const splitResults = input.strategy.splitResult(value, compiled);
90
- return memberRequests.map((_, index) => splitResults[index]?.result ?? null);
91
- },
92
- });
93
- currentBatch = [];
94
- };
95
- for (const request of bucketRequests) {
96
- const payload = input.getPayload(request);
97
- const canAppend =
98
- currentBatch.length > 0 &&
99
- currentBatch.length < input.strategy.maxBatchSize &&
100
- currentBatch.every((existing) =>
101
- input.strategy.canBatchWith(input.getPayload(existing), payload),
102
- );
103
- if (!canAppend && currentBatch.length > 0) flushBatch();
104
- currentBatch.push(request);
105
- }
106
- flushBatch();
107
- }
108
- return compiledBatches;
109
- }
110
-
111
- export function getDefaultPlayRuntimeBatchStrategy(
112
- operation: string | null | undefined,
113
- ): AnyBatchOperationStrategy | null {
114
- if (operation !== 'test_rate_limit') return null;
115
- return {
116
- sourceOperation: 'test_rate_limit',
117
- batchOperation: 'test_batch_rate_limit',
118
- kind: 'identifier_batch',
119
- maxBatchSize: 200,
120
- canBatchWith(left, right) {
121
- return String(left.stage || '') === String(right.stage || '');
122
- },
123
- toBucketKey(payload) {
124
- return `test_batch_rate_limit:${String(payload.stage || '')}`;
125
- },
126
- toItemKey(payload) {
127
- return String(payload.lead_id || payload.row_number || payload.key || '');
128
- },
129
- compile(payloads) {
130
- const stage = String(payloads[0]?.stage || '');
131
- const simulatedDelayMs =
132
- typeof payloads[0]?.simulated_delay_ms === 'number'
133
- ? payloads[0].simulated_delay_ms
134
- : undefined;
135
- const items = payloads.map((payload, index) => ({
136
- itemKey: String(payload.lead_id || payload.row_number || `row_${index}`),
137
- payload,
138
- }));
139
- return {
140
- batchOperation: 'test_batch_rate_limit',
141
- batchPayload: {
142
- key: 'batch',
143
- ...(stage ? { stage } : {}),
144
- ...(simulatedDelayMs !== undefined
145
- ? { simulated_delay_ms: simulatedDelayMs }
146
- : {}),
147
- items,
148
- },
149
- items,
150
- };
151
- },
152
- splitResult(fullResult, compiled) {
153
- const container =
154
- fullResult != null && typeof fullResult === 'object' && !Array.isArray(fullResult)
155
- ? (fullResult as Record<string, unknown>)
156
- : {};
157
- const nestedData =
158
- container.data != null &&
159
- typeof container.data === 'object' &&
160
- !Array.isArray(container.data)
161
- ? (container.data as Record<string, unknown>)
162
- : {};
163
- const resultItems = Array.isArray(container.items)
164
- ? (container.items as Array<{ itemKey?: string; result?: unknown }>)
165
- : Array.isArray(nestedData.items)
166
- ? (nestedData.items as Array<{ itemKey?: string; result?: unknown }>)
167
- : [];
168
- return compiled.items.map((item, index) => ({
169
- itemKey: item.itemKey,
170
- result:
171
- index < resultItems.length ? (resultItems[index]?.result ?? null) : null,
172
- rawResult:
173
- index < resultItems.length ? (resultItems[index]?.result ?? null) : null,
174
- }));
175
- },
176
- };
177
- }
@@ -1,52 +0,0 @@
1
- /**
2
- * Per-play Worker execution-plan helpers.
3
- *
4
- * Keep this file dependency-free. It is bundled into every esm_workers play
5
- * artifact, so shared-runtime imports here directly increase cold compile cost.
6
- */
7
-
8
- const INLINE_ROWS_LIMIT = 1_000;
9
- const LARGE_MAP_CHUNK_SIZE = 5_000;
10
- const SOFT_STEP_BUDGET = 20_000;
11
- const INGEST_STEP_COUNT = 1;
12
- const FINALIZATION_STEP_COUNT = 2;
13
-
14
- export function chooseMapChunkSize(input: {
15
- totalRows: number;
16
- mapCount: number;
17
- stepsPerChunk: number;
18
- preferredChunkSize?: number | null;
19
- softWorkflowStepBudget?: number | null;
20
- }): number {
21
- const totalRows = Math.max(0, Math.floor(input.totalRows));
22
- if (totalRows <= INLINE_ROWS_LIMIT) {
23
- return Math.max(1, totalRows || 1);
24
- }
25
- const mapCount = Math.max(1, Math.floor(input.mapCount));
26
- const stepsPerChunk = Math.max(1, Math.floor(input.stepsPerChunk));
27
- const softBudget = input.softWorkflowStepBudget ?? SOFT_STEP_BUDGET;
28
- const nonChunkSteps = INGEST_STEP_COUNT + FINALIZATION_STEP_COUNT;
29
- const maxChunksAcrossMaps = Math.max(
30
- mapCount,
31
- Math.floor((softBudget - nonChunkSteps) / stepsPerChunk),
32
- );
33
- const maxChunksPerMap = Math.max(1, Math.floor(maxChunksAcrossMaps / mapCount));
34
- const minimumSurvivalChunkSize = Math.max(
35
- 1,
36
- Math.ceil(totalRows / maxChunksPerMap),
37
- );
38
- const preferred = Math.max(
39
- 1,
40
- Math.floor(input.preferredChunkSize ?? LARGE_MAP_CHUNK_SIZE),
41
- );
42
- return Math.max(preferred, minimumSurvivalChunkSize);
43
- }
44
-
45
- export function deterministicMapChunkStepName(input: {
46
- mapName: string;
47
- chunkIndex: number;
48
- phase?: 'prepare' | 'execute' | 'persist' | string;
49
- }): string {
50
- const phase = input.phase?.trim() || 'execute';
51
- return `map:${input.mapName}:chunk:${String(input.chunkIndex).padStart(4, '0')}:${phase}`;
52
- }
@@ -1,100 +0,0 @@
1
- /**
2
- * Per-play Worker tool batch executor.
3
- *
4
- * This is intentionally local to the Worker bundle. Pulling the shared
5
- * executor module back in would widen the bundle graph for a tiny helper.
6
- */
7
-
8
- export type ToolBatchRequest = {
9
- runId: string;
10
- orgId: string;
11
- toolId: string;
12
- operation: string;
13
- provider: string;
14
- items: Array<{
15
- itemKey: string;
16
- payload: Record<string, unknown>;
17
- inputHash?: string | null;
18
- }>;
19
- waterfallId?: string | null;
20
- stageId?: string | null;
21
- fieldName?: string | null;
22
- mapName?: string | null;
23
- chunkIndex?: number | null;
24
- userProvidedRateLimitKey?: string | null;
25
- providerBatchSize: number;
26
- };
27
-
28
- type ToolBatchItemResult = {
29
- itemKey: string;
30
- result: unknown;
31
- cached?: boolean;
32
- };
33
-
34
- export function createToolBatchExecutor(input: {
35
- executeProviderBatch(batch: {
36
- request: ToolBatchRequest;
37
- batchIndex: number;
38
- idempotencyKeys: string[];
39
- rateLimitKey: string;
40
- items: ToolBatchRequest['items'];
41
- }): Promise<ToolBatchItemResult[]>;
42
- }) {
43
- return {
44
- async executeToolBatch(request: ToolBatchRequest) {
45
- const providerBatchSize = Math.max(1, Math.floor(request.providerBatchSize));
46
- const batches: Array<ToolBatchRequest['items']> = [];
47
- for (let index = 0; index < request.items.length; index += providerBatchSize) {
48
- batches.push(request.items.slice(index, index + providerBatchSize));
49
- }
50
- const results: ToolBatchItemResult[] = [];
51
- for (let batchIndex = 0; batchIndex < batches.length; batchIndex += 1) {
52
- const items = batches[batchIndex]!;
53
- results.push(
54
- ...(await input.executeProviderBatch({
55
- request,
56
- batchIndex,
57
- items,
58
- rateLimitKey: [
59
- request.orgId,
60
- request.provider,
61
- request.operation,
62
- request.userProvidedRateLimitKey ?? '',
63
- ].join(':'),
64
- idempotencyKeys: items.map((item) =>
65
- [
66
- request.runId,
67
- request.mapName ?? '',
68
- request.chunkIndex ?? '',
69
- item.itemKey,
70
- request.fieldName ?? '',
71
- request.waterfallId ?? '',
72
- request.stageId ?? '',
73
- item.inputHash ?? stableStringify(item.payload),
74
- ].join(':'),
75
- ),
76
- })),
77
- );
78
- }
79
- return {
80
- runId: request.runId,
81
- toolId: request.toolId,
82
- operation: request.operation,
83
- provider: request.provider,
84
- batchCount: batches.length,
85
- itemCount: request.items.length,
86
- results,
87
- };
88
- },
89
- };
90
- }
91
-
92
- function stableStringify(value: unknown): string {
93
- if (value === null || typeof value !== 'object') return JSON.stringify(value);
94
- if (Array.isArray(value)) return `[${value.map(stableStringify).join(',')}]`;
95
- const record = value as Record<string, unknown>;
96
- return `{${Object.keys(record)
97
- .sort()
98
- .map((key) => `${JSON.stringify(key)}:${stableStringify(record[key])}`)
99
- .join(',')}}`;
100
- }