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.
Files changed (100) hide show
  1. package/README.md +324 -0
  2. package/dist/cli/index.js +6750 -503
  3. package/dist/cli/index.js.map +1 -1
  4. package/dist/cli/index.mjs +6735 -512
  5. package/dist/cli/index.mjs.map +1 -1
  6. package/dist/index.d.mts +2349 -32
  7. package/dist/index.d.ts +2349 -32
  8. package/dist/index.js +1631 -82
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +1617 -83
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/repo/apps/play-runner-workers/src/coordinator-entry.ts +3256 -0
  13. package/dist/repo/apps/play-runner-workers/src/dedup-do.ts +710 -0
  14. package/dist/repo/apps/play-runner-workers/src/entry.ts +5070 -0
  15. package/dist/repo/apps/play-runner-workers/src/runtime/README.md +21 -0
  16. package/dist/repo/apps/play-runner-workers/src/runtime/batching.ts +177 -0
  17. package/dist/repo/apps/play-runner-workers/src/runtime/execution-plan.ts +52 -0
  18. package/dist/repo/apps/play-runner-workers/src/runtime/tool-batch.ts +100 -0
  19. package/dist/repo/apps/play-runner-workers/src/runtime/tool-result.ts +184 -0
  20. package/dist/repo/sdk/src/cli/commands/auth.ts +482 -0
  21. package/dist/repo/sdk/src/cli/commands/billing.ts +188 -0
  22. package/dist/repo/sdk/src/cli/commands/csv.ts +123 -0
  23. package/dist/repo/sdk/src/cli/commands/db.ts +119 -0
  24. package/dist/repo/sdk/src/cli/commands/feedback.ts +40 -0
  25. package/dist/repo/sdk/src/cli/commands/org.ts +117 -0
  26. package/dist/repo/sdk/src/cli/commands/play.ts +3200 -0
  27. package/dist/repo/sdk/src/cli/commands/tools.ts +687 -0
  28. package/dist/repo/sdk/src/cli/dataset-stats.ts +341 -0
  29. package/dist/repo/sdk/src/cli/index.ts +138 -0
  30. package/dist/repo/sdk/src/cli/progress.ts +135 -0
  31. package/dist/repo/sdk/src/cli/trace.ts +61 -0
  32. package/dist/repo/sdk/src/cli/utils.ts +145 -0
  33. package/dist/repo/sdk/src/client.ts +1188 -0
  34. package/dist/repo/sdk/src/compat.ts +77 -0
  35. package/dist/repo/sdk/src/config.ts +285 -0
  36. package/dist/repo/sdk/src/errors.ts +125 -0
  37. package/dist/repo/sdk/src/http.ts +391 -0
  38. package/dist/repo/sdk/src/index.ts +139 -0
  39. package/dist/repo/sdk/src/play.ts +1330 -0
  40. package/dist/repo/sdk/src/plays/bundle-play-file.ts +133 -0
  41. package/dist/repo/sdk/src/plays/harness-stub.ts +210 -0
  42. package/dist/repo/sdk/src/plays/local-file-discovery.ts +326 -0
  43. package/dist/repo/sdk/src/tool-output.ts +489 -0
  44. package/dist/repo/sdk/src/types.ts +669 -0
  45. package/dist/repo/sdk/src/version.ts +2 -0
  46. package/dist/repo/sdk/src/worker-play-entry.ts +286 -0
  47. package/dist/repo/shared_libs/observability/node-tracing.ts +129 -0
  48. package/dist/repo/shared_libs/observability/tracing.ts +98 -0
  49. package/dist/repo/shared_libs/play-runtime/backend.ts +139 -0
  50. package/dist/repo/shared_libs/play-runtime/batch-runtime.ts +182 -0
  51. package/dist/repo/shared_libs/play-runtime/batching-types.ts +91 -0
  52. package/dist/repo/shared_libs/play-runtime/context.ts +3999 -0
  53. package/dist/repo/shared_libs/play-runtime/coordinator-headers.ts +78 -0
  54. package/dist/repo/shared_libs/play-runtime/ctx-contract.ts +250 -0
  55. package/dist/repo/shared_libs/play-runtime/ctx-types.ts +713 -0
  56. package/dist/repo/shared_libs/play-runtime/dataset-id.ts +10 -0
  57. package/dist/repo/shared_libs/play-runtime/db-session-crypto.ts +304 -0
  58. package/dist/repo/shared_libs/play-runtime/db-session.ts +462 -0
  59. package/dist/repo/shared_libs/play-runtime/dedup-backend.ts +0 -0
  60. package/dist/repo/shared_libs/play-runtime/default-batch-strategies.ts +124 -0
  61. package/dist/repo/shared_libs/play-runtime/execution-plan.ts +262 -0
  62. package/dist/repo/shared_libs/play-runtime/live-events.ts +214 -0
  63. package/dist/repo/shared_libs/play-runtime/live-state-contract.ts +50 -0
  64. package/dist/repo/shared_libs/play-runtime/map-execution-frame.ts +114 -0
  65. package/dist/repo/shared_libs/play-runtime/map-row-identity.ts +158 -0
  66. package/dist/repo/shared_libs/play-runtime/profiles.ts +90 -0
  67. package/dist/repo/shared_libs/play-runtime/progress-emitter.ts +172 -0
  68. package/dist/repo/shared_libs/play-runtime/protocol.ts +121 -0
  69. package/dist/repo/shared_libs/play-runtime/public-play-contract.ts +42 -0
  70. package/dist/repo/shared_libs/play-runtime/result-normalization.ts +33 -0
  71. package/dist/repo/shared_libs/play-runtime/runtime-actions.ts +208 -0
  72. package/dist/repo/shared_libs/play-runtime/runtime-api.ts +1873 -0
  73. package/dist/repo/shared_libs/play-runtime/runtime-constraints.ts +2 -0
  74. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-neon-serverless.ts +201 -0
  75. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-pg.ts +48 -0
  76. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver.ts +84 -0
  77. package/dist/repo/shared_libs/play-runtime/scheduler-backend.ts +174 -0
  78. package/dist/repo/shared_libs/play-runtime/static-pipeline-types.ts +147 -0
  79. package/dist/repo/shared_libs/play-runtime/suspension.ts +68 -0
  80. package/dist/repo/shared_libs/play-runtime/tool-batch-executor.ts +146 -0
  81. package/dist/repo/shared_libs/play-runtime/tool-result.ts +387 -0
  82. package/dist/repo/shared_libs/play-runtime/tracing.ts +31 -0
  83. package/dist/repo/shared_libs/play-runtime/waterfall-replay.ts +75 -0
  84. package/dist/repo/shared_libs/play-runtime/worker-api-types.ts +140 -0
  85. package/dist/repo/shared_libs/plays/artifact-transport.ts +14 -0
  86. package/dist/repo/shared_libs/plays/artifact-types.ts +49 -0
  87. package/dist/repo/shared_libs/plays/bundling/index.ts +1346 -0
  88. package/dist/repo/shared_libs/plays/compiler-manifest.ts +186 -0
  89. package/dist/repo/shared_libs/plays/contracts.ts +51 -0
  90. package/dist/repo/shared_libs/plays/dataset.ts +308 -0
  91. package/dist/repo/shared_libs/plays/definition.ts +264 -0
  92. package/dist/repo/shared_libs/plays/file-refs.ts +11 -0
  93. package/dist/repo/shared_libs/plays/rate-limit-scheduler.ts +206 -0
  94. package/dist/repo/shared_libs/plays/resolve-static-pipeline.ts +164 -0
  95. package/dist/repo/shared_libs/plays/row-identity.ts +302 -0
  96. package/dist/repo/shared_libs/plays/runtime-validation.ts +415 -0
  97. package/dist/repo/shared_libs/plays/static-pipeline.ts +560 -0
  98. package/dist/repo/shared_libs/temporal/constants.ts +39 -0
  99. package/dist/repo/shared_libs/temporal/preview-config.ts +153 -0
  100. package/package.json +14 -12
@@ -0,0 +1,182 @@
1
+ import type { AnyBatchOperationStrategy } from './batching-types';
2
+
3
+ export interface ChunkExecutionResult<TRequest, TResult> {
4
+ request: TRequest;
5
+ result: TResult | null;
6
+ }
7
+
8
+ function formatChunkExecutionError(error: unknown): string {
9
+ if (error instanceof Error) {
10
+ return error.message;
11
+ }
12
+ return String(error);
13
+ }
14
+
15
+ export interface CompiledRequestBatch<TRequest> {
16
+ batchOperation: string;
17
+ memberRequests: TRequest[];
18
+ batchPayload: Record<string, unknown>;
19
+ splitResults: (value: unknown) => Array<unknown | null>;
20
+ }
21
+
22
+ export async function executeChunkedRequests<TRequest, TResult>(input: {
23
+ requests: TRequest[];
24
+ batchSize: number;
25
+ execute: (request: TRequest) => Promise<TResult>;
26
+ onChunkComplete?: (
27
+ results: Array<ChunkExecutionResult<TRequest, TResult>>,
28
+ ) => void | Promise<void>;
29
+ }): Promise<Array<ChunkExecutionResult<TRequest, TResult>>> {
30
+ const results: Array<ChunkExecutionResult<TRequest, TResult>> = [];
31
+
32
+ for (let start = 0; start < input.requests.length; start += input.batchSize) {
33
+ const chunk = input.requests.slice(start, start + input.batchSize);
34
+ const settled = await Promise.allSettled(
35
+ chunk.map((request) => input.execute(request)),
36
+ );
37
+
38
+ const rejected = settled.find(
39
+ (outcome): outcome is PromiseRejectedResult =>
40
+ outcome.status === 'rejected',
41
+ );
42
+ if (rejected) {
43
+ throw new Error(
44
+ `Play batch request failed: ${formatChunkExecutionError(rejected.reason)}`,
45
+ { cause: rejected.reason },
46
+ );
47
+ }
48
+
49
+ for (let index = 0; index < chunk.length; index += 1) {
50
+ const outcome = settled[index] as PromiseFulfilledResult<TResult>;
51
+ results.push({
52
+ request: chunk[index]!,
53
+ result: outcome.value,
54
+ });
55
+ }
56
+
57
+ const completedChunk = results.slice(results.length - chunk.length);
58
+ await input.onChunkComplete?.(completedChunk);
59
+ }
60
+
61
+ return results;
62
+ }
63
+
64
+ export function compileRequestsWithStrategy<TRequest>(input: {
65
+ requests: TRequest[];
66
+ strategy: AnyBatchOperationStrategy;
67
+ getPayload: (request: TRequest) => Record<string, unknown>;
68
+ }): Array<CompiledRequestBatch<TRequest>> {
69
+ const compiledBatches: Array<CompiledRequestBatch<TRequest>> = [];
70
+ const bucketedRequests = new Map<string, TRequest[]>();
71
+
72
+ for (const request of input.requests) {
73
+ const payload = input.getPayload(request);
74
+ const bucketKey = String(input.strategy.toBucketKey(payload));
75
+ if (!bucketedRequests.has(bucketKey)) {
76
+ bucketedRequests.set(bucketKey, []);
77
+ }
78
+ bucketedRequests.get(bucketKey)!.push(request);
79
+ }
80
+
81
+ for (const bucketRequests of bucketedRequests.values()) {
82
+ let currentBatch: TRequest[] = [];
83
+
84
+ const flushBatch = () => {
85
+ if (currentBatch.length === 0) {
86
+ return;
87
+ }
88
+
89
+ const memberRequests = [...currentBatch];
90
+ const compiled = input.strategy.compile(
91
+ memberRequests.map((request) => input.getPayload(request)),
92
+ );
93
+ compiledBatches.push({
94
+ batchOperation: compiled.batchOperation,
95
+ memberRequests,
96
+ batchPayload: compiled.batchPayload as Record<string, unknown>,
97
+ splitResults: (value: unknown) => {
98
+ const splitResults = input.strategy.splitResult(
99
+ value as never,
100
+ compiled as never,
101
+ );
102
+ return memberRequests.map(
103
+ (_, index) => splitResults[index]?.result ?? null,
104
+ );
105
+ },
106
+ });
107
+ currentBatch = [];
108
+ };
109
+
110
+ for (const request of bucketRequests) {
111
+ const payload = input.getPayload(request);
112
+ const canAppend =
113
+ currentBatch.length > 0 &&
114
+ currentBatch.length < input.strategy.maxBatchSize &&
115
+ currentBatch.every((existing) =>
116
+ input.strategy.canBatchWith(input.getPayload(existing), payload),
117
+ );
118
+
119
+ if (!canAppend && currentBatch.length > 0) {
120
+ flushBatch();
121
+ }
122
+
123
+ currentBatch.push(request);
124
+ }
125
+
126
+ flushBatch();
127
+ }
128
+
129
+ return compiledBatches;
130
+ }
131
+
132
+ export async function executeWaterfallProviders<TRequest, TResult>(input: {
133
+ providers: string[];
134
+ getPendingRequests: () => TRequest[];
135
+ getCachedResults: (provider: string) => Array<ChunkExecutionResult<TRequest, TResult>> | null;
136
+ storeCachedResults: (
137
+ provider: string,
138
+ results: Array<ChunkExecutionResult<TRequest, TResult>>,
139
+ ) => void;
140
+ executeProviderRequests: (
141
+ provider: string,
142
+ requests: TRequest[],
143
+ ) => Promise<Array<ChunkExecutionResult<TRequest, TResult>>>;
144
+ onHit: (provider: string, request: TRequest, result: TResult) => void;
145
+ onMiss: (provider: string, request: TRequest) => void;
146
+ onProviderComplete?: (provider: string) => void;
147
+ }): Promise<void> {
148
+ for (const provider of input.providers) {
149
+ const cached = input.getCachedResults(provider);
150
+ if (cached) {
151
+ for (const entry of cached) {
152
+ if (entry.result != null) {
153
+ input.onHit(provider, entry.request, entry.result);
154
+ }
155
+ }
156
+ input.onProviderComplete?.(provider);
157
+ continue;
158
+ }
159
+
160
+ const pending = input.getPendingRequests();
161
+ if (pending.length === 0) {
162
+ return;
163
+ }
164
+
165
+ const results = await input.executeProviderRequests(provider, pending);
166
+ input.storeCachedResults(provider, results);
167
+
168
+ for (const entry of results) {
169
+ if (entry.result != null) {
170
+ input.onHit(provider, entry.request, entry.result);
171
+ } else {
172
+ input.onMiss(provider, entry.request);
173
+ }
174
+ }
175
+
176
+ input.onProviderComplete?.(provider);
177
+ }
178
+ }
179
+
180
+ export function resolveWaterfallToolId(provider: string, toolName: string): string {
181
+ return toolName.startsWith(`${provider}_`) ? toolName : `${provider}_${toolName}`;
182
+ }
@@ -0,0 +1,91 @@
1
+ export type BatchStrategyKind =
2
+ | 'identifier_batch'
3
+ | 'query_share'
4
+ | 'async_dataset_job';
5
+
6
+ export type BatchCompileItem<TSingle extends object> = {
7
+ // Preserved for diagnostics and job bookkeeping only.
8
+ // Batch fanout is positional: compiled.items[index] maps to splitResult[index].
9
+ itemKey: string;
10
+ payload: TSingle;
11
+ };
12
+
13
+ export type BatchCompileResult<TBatch extends object, TSingle extends object> = {
14
+ batchOperation: string;
15
+ batchPayload: TBatch;
16
+ items: Array<BatchCompileItem<TSingle>>;
17
+ };
18
+
19
+ export type BatchExecutionDataEnvelope<TBatchResult> = {
20
+ data: TBatchResult;
21
+ };
22
+
23
+ export type BatchExecutionResultPayload<TBatchResult> =
24
+ | TBatchResult
25
+ | BatchExecutionDataEnvelope<TBatchResult>;
26
+
27
+ export type BatchSplitItemResult<TResult = unknown, TRawResult = unknown> = {
28
+ // Preserved as metadata only. The runtime does not use itemKey to match rows.
29
+ itemKey: string;
30
+ result: TResult;
31
+ rawResult?: TRawResult;
32
+ };
33
+
34
+ export type BatchOperationStrategy<
35
+ TSingle extends Record<string, unknown> = Record<string, unknown>,
36
+ TBatch extends Record<string, unknown> = Record<string, unknown>,
37
+ TBatchResult extends object = Record<string, unknown>,
38
+ TResult = unknown,
39
+ TRawResult = unknown,
40
+ > = {
41
+ sourceOperation: string;
42
+ batchOperation: string;
43
+ kind: BatchStrategyKind;
44
+ maxBatchSize: number;
45
+ canBatchWith(left: TSingle, right: TSingle): boolean;
46
+ toBucketKey(payload: TSingle): string;
47
+ toItemKey(payload: TSingle): string;
48
+ compile(payloads: TSingle[]): BatchCompileResult<TBatch, TSingle>;
49
+ splitResult(
50
+ fullResult: TBatchResult,
51
+ compiled: BatchCompileResult<TBatch, TSingle>,
52
+ // Implementations must return results in the same order as compiled.items.
53
+ ): BatchSplitItemResult<TResult, TRawResult>[];
54
+ };
55
+
56
+ export type AnyBatchOperationStrategy = {
57
+ sourceOperation: string;
58
+ batchOperation: string;
59
+ kind: BatchStrategyKind;
60
+ maxBatchSize: number;
61
+ canBatchWith(left: Record<string, unknown>, right: Record<string, unknown>): boolean;
62
+ toBucketKey(payload: Record<string, unknown>): string;
63
+ toItemKey(payload: Record<string, unknown>): string;
64
+ compile(payloads: Record<string, unknown>[]): {
65
+ batchOperation: string;
66
+ batchPayload: Record<string, unknown>;
67
+ items: Array<{
68
+ itemKey: string;
69
+ payload: Record<string, unknown>;
70
+ }>;
71
+ };
72
+ splitResult(
73
+ fullResult: unknown,
74
+ compiled: {
75
+ batchOperation: string;
76
+ batchPayload: Record<string, unknown>;
77
+ items: Array<{ itemKey: string; payload: Record<string, unknown> }>;
78
+ },
79
+ ): BatchSplitItemResult<unknown, unknown>[];
80
+ };
81
+
82
+ export type BatchStrategyMap = Record<string, AnyBatchOperationStrategy>;
83
+
84
+ type StrictBatchOperationStrategy =
85
+ BatchOperationStrategy<Record<string, unknown>, Record<string, unknown>, object, unknown, unknown>;
86
+
87
+ export function defineBatchStrategyMap<
88
+ TStrategies extends Record<string, StrictBatchOperationStrategy>,
89
+ >(strategies: TStrategies): BatchStrategyMap {
90
+ return strategies as BatchStrategyMap;
91
+ }