deepline 0.1.11 → 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 (85) hide show
  1. package/README.md +18 -10
  2. package/dist/cli/index.js +1795 -1052
  3. package/dist/cli/index.mjs +1795 -1053
  4. package/dist/index.d.mts +427 -308
  5. package/dist/index.d.ts +427 -308
  6. package/dist/index.js +391 -326
  7. package/dist/index.mjs +391 -325
  8. package/dist/repo/apps/play-runner-workers/src/coordinator-entry.ts +88 -22
  9. package/dist/repo/apps/play-runner-workers/src/entry.ts +804 -1253
  10. package/dist/repo/sdk/src/client.ts +287 -47
  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/index.ts +7 -16
  14. package/dist/repo/sdk/src/play.ts +105 -140
  15. package/dist/repo/sdk/src/plays/bundle-play-file.ts +23 -6
  16. package/dist/repo/sdk/src/plays/local-file-discovery.ts +207 -160
  17. package/dist/repo/sdk/src/tool-output.ts +0 -146
  18. package/dist/repo/sdk/src/types.ts +27 -0
  19. package/dist/repo/sdk/src/version.ts +2 -2
  20. package/dist/repo/sdk/src/worker-play-entry.ts +3 -0
  21. package/dist/repo/shared_libs/play-runtime/csv-rename.ts +180 -0
  22. package/dist/repo/shared_libs/play-runtime/tool-result.ts +250 -133
  23. package/dist/repo/shared_libs/plays/bundling/index.ts +274 -234
  24. package/dist/repo/shared_libs/plays/dataset.ts +29 -1
  25. package/package.json +5 -4
  26. package/dist/cli/index.js.map +0 -1
  27. package/dist/cli/index.mjs.map +0 -1
  28. package/dist/index.js.map +0 -1
  29. package/dist/index.mjs.map +0 -1
  30. package/dist/repo/apps/play-runner-workers/src/runtime/README.md +0 -21
  31. package/dist/repo/apps/play-runner-workers/src/runtime/batching.ts +0 -177
  32. package/dist/repo/apps/play-runner-workers/src/runtime/execution-plan.ts +0 -52
  33. package/dist/repo/apps/play-runner-workers/src/runtime/tool-batch.ts +0 -100
  34. package/dist/repo/apps/play-runner-workers/src/runtime/tool-result.ts +0 -184
  35. package/dist/repo/sdk/src/cli/commands/auth.ts +0 -500
  36. package/dist/repo/sdk/src/cli/commands/billing.ts +0 -188
  37. package/dist/repo/sdk/src/cli/commands/csv.ts +0 -123
  38. package/dist/repo/sdk/src/cli/commands/db.ts +0 -119
  39. package/dist/repo/sdk/src/cli/commands/feedback.ts +0 -40
  40. package/dist/repo/sdk/src/cli/commands/org.ts +0 -117
  41. package/dist/repo/sdk/src/cli/commands/play.ts +0 -3307
  42. package/dist/repo/sdk/src/cli/commands/tools.ts +0 -687
  43. package/dist/repo/sdk/src/cli/dataset-stats.ts +0 -341
  44. package/dist/repo/sdk/src/cli/index.ts +0 -148
  45. package/dist/repo/sdk/src/cli/progress.ts +0 -149
  46. package/dist/repo/sdk/src/cli/skills-sync.ts +0 -141
  47. package/dist/repo/sdk/src/cli/trace.ts +0 -61
  48. package/dist/repo/sdk/src/cli/utils.ts +0 -145
  49. package/dist/repo/sdk/src/compat.ts +0 -77
  50. package/dist/repo/shared_libs/observability/node-tracing.ts +0 -129
  51. package/dist/repo/shared_libs/observability/tracing.ts +0 -98
  52. package/dist/repo/shared_libs/play-runtime/context.ts +0 -3999
  53. package/dist/repo/shared_libs/play-runtime/ctx-contract.ts +0 -250
  54. package/dist/repo/shared_libs/play-runtime/ctx-types.ts +0 -713
  55. package/dist/repo/shared_libs/play-runtime/dataset-id.ts +0 -10
  56. package/dist/repo/shared_libs/play-runtime/db-session-crypto.ts +0 -304
  57. package/dist/repo/shared_libs/play-runtime/db-session.ts +0 -462
  58. package/dist/repo/shared_libs/play-runtime/live-events.ts +0 -214
  59. package/dist/repo/shared_libs/play-runtime/live-state-contract.ts +0 -50
  60. package/dist/repo/shared_libs/play-runtime/map-execution-frame.ts +0 -114
  61. package/dist/repo/shared_libs/play-runtime/map-row-identity.ts +0 -158
  62. package/dist/repo/shared_libs/play-runtime/progress-emitter.ts +0 -172
  63. package/dist/repo/shared_libs/play-runtime/protocol.ts +0 -121
  64. package/dist/repo/shared_libs/play-runtime/public-play-contract.ts +0 -42
  65. package/dist/repo/shared_libs/play-runtime/result-normalization.ts +0 -33
  66. package/dist/repo/shared_libs/play-runtime/runtime-api.ts +0 -1873
  67. package/dist/repo/shared_libs/play-runtime/runtime-constraints.ts +0 -2
  68. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-neon-serverless.ts +0 -201
  69. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-pg.ts +0 -48
  70. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver.ts +0 -84
  71. package/dist/repo/shared_libs/play-runtime/static-pipeline-types.ts +0 -147
  72. package/dist/repo/shared_libs/play-runtime/suspension.ts +0 -68
  73. package/dist/repo/shared_libs/play-runtime/tracing.ts +0 -31
  74. package/dist/repo/shared_libs/play-runtime/waterfall-replay.ts +0 -75
  75. package/dist/repo/shared_libs/play-runtime/worker-api-types.ts +0 -140
  76. package/dist/repo/shared_libs/plays/artifact-transport.ts +0 -14
  77. package/dist/repo/shared_libs/plays/artifact-types.ts +0 -49
  78. package/dist/repo/shared_libs/plays/compiler-manifest.ts +0 -186
  79. package/dist/repo/shared_libs/plays/definition.ts +0 -264
  80. package/dist/repo/shared_libs/plays/file-refs.ts +0 -11
  81. package/dist/repo/shared_libs/plays/rate-limit-scheduler.ts +0 -206
  82. package/dist/repo/shared_libs/plays/resolve-static-pipeline.ts +0 -164
  83. package/dist/repo/shared_libs/plays/runtime-validation.ts +0 -415
  84. package/dist/repo/shared_libs/temporal/constants.ts +0 -39
  85. package/dist/repo/shared_libs/temporal/preview-config.ts +0 -153
@@ -359,13 +359,16 @@ type PooledWorkflowBootstrapPayload = {
359
359
  createdAt: number;
360
360
  };
361
361
 
362
- const WORKFLOW_POOL_PROTOCOL_VERSION = 'pooled-workflow-wait-v3-dynamic-binding';
362
+ const WORKFLOW_POOL_PROTOCOL_VERSION =
363
+ 'pooled-workflow-wait-v4-waiting-only';
363
364
  const WORKFLOW_POOL_DO_NAME = 'workflow-pool:v2';
364
365
  const WORKFLOW_POOL_START_EVENT_TYPE = 'play_start';
365
366
  const WORKFLOW_POOL_TTL_MS = 8 * 60 * 1000;
366
367
  const WORKFLOW_POOL_TARGET_SIZE = 2;
367
368
  const WORKFLOW_POOL_READY_TIMEOUT_MS = 1_500;
368
369
  const WORKFLOW_POOL_READY_POLL_MS = 250;
370
+ const WORKFLOW_POOL_REFILL_ON_MISS_TIMEOUT_MS = 2_500;
371
+ const WORKFLOW_POOL_REFILL_ON_MISS_MIN_AVAILABLE = 1;
369
372
 
370
373
  function buildDynamicWorkflowMetadata(
371
374
  params: PlayWorkflowParams,
@@ -675,11 +678,11 @@ function workflowStatusName(status: InstanceStatus | null): string {
675
678
  }
676
679
 
677
680
  function workflowPoolStatusIsReady(statusName: string): boolean {
678
- // Cloudflare Workflows may report a run as "running" even while the body is
679
- // blocked inside step.waitForEvent(). Treat both states as pool-candidates;
680
- // submitViaPooledWorkflow still falls back to a fresh Workflow if sendEvent
681
- // fails.
682
- return statusName === 'waiting' || statusName === 'running';
681
+ // Only a Workflow explicitly blocked on waitForEvent is safe to lease.
682
+ // A generic "running" instance may already be executing a previous play; if
683
+ // we send a new start event to it, the submitted run can stay running forever
684
+ // while callbacks continue updating the previous runId.
685
+ return statusName === 'waiting';
683
686
  }
684
687
 
685
688
  async function waitForWorkflowPoolReady(instance: WorkflowInstance): Promise<{
@@ -900,7 +903,7 @@ async function submitViaPooledWorkflow(input: {
900
903
  return null;
901
904
  }
902
905
  const leaseStartedAt = Date.now();
903
- const pooledInstanceId = await leaseWorkflowPoolId(input.env);
906
+ let pooledInstanceId = await leaseWorkflowPoolId(input.env);
904
907
  const missCounts = pooledInstanceId
905
908
  ? null
906
909
  : await workflowPoolCount(input.env).catch(() => null);
@@ -918,6 +921,47 @@ async function submitViaPooledWorkflow(input: {
918
921
  : {}),
919
922
  },
920
923
  });
924
+
925
+ if (!pooledInstanceId) {
926
+ // A pool miss is often a timing gap rather than a true lack of warm
927
+ // capacity. Wait briefly for refill/promotion, then retry lease once
928
+ // before falling back to a cold workflow create.
929
+ const refillStartedAt = Date.now();
930
+ const refillResult = await refillWorkflowPool(input.env, {
931
+ waitReady: true,
932
+ minAvailable: WORKFLOW_POOL_REFILL_ON_MISS_MIN_AVAILABLE,
933
+ waitTimeoutMs: WORKFLOW_POOL_REFILL_ON_MISS_TIMEOUT_MS,
934
+ }).catch(() => null);
935
+ input.recordSubmitTiming({
936
+ phase: 'coordinator.workflow_pool_refill_on_miss',
937
+ ms: Date.now() - refillStartedAt,
938
+ graphHash: input.params.graphHash ?? null,
939
+ extra:
940
+ refillResult === null
941
+ ? { ok: false }
942
+ : {
943
+ ok: true,
944
+ available: refillResult.available,
945
+ warming: refillResult.warming,
946
+ created: refillResult.created,
947
+ promoted: refillResult.promoted,
948
+ removed: refillResult.removed,
949
+ waitedMs: refillResult.waitedMs,
950
+ waitIterations: refillResult.waitIterations,
951
+ },
952
+ });
953
+ if (refillResult?.available) {
954
+ const retryStartedAt = Date.now();
955
+ pooledInstanceId = await leaseWorkflowPoolId(input.env);
956
+ input.recordSubmitTiming({
957
+ phase: 'coordinator.workflow_pool_lease_retry',
958
+ ms: Date.now() - retryStartedAt,
959
+ graphHash: input.params.graphHash ?? null,
960
+ extra: { pooled: Boolean(pooledInstanceId) },
961
+ });
962
+ }
963
+ }
964
+
921
965
  if (!pooledInstanceId) {
922
966
  return null;
923
967
  }
@@ -1497,8 +1541,8 @@ async function executeChildInline(input: {
1497
1541
  artifactStorageKey: manifest.artifactStorageKey,
1498
1542
  artifactHash: manifest.artifactHash,
1499
1543
  dynamicWorkerCode:
1500
- typeof manifest.dynamicWorkerCode === 'string'
1501
- ? manifest.dynamicWorkerCode
1544
+ typeof manifest.bundledCode === 'string'
1545
+ ? manifest.bundledCode
1502
1546
  : null,
1503
1547
  packagedFiles: null,
1504
1548
  });
@@ -2451,7 +2495,10 @@ async function handleWorkflowRoute(input: {
2451
2495
  ? (body.childPlayManifests as PlayRuntimeManifestMap)
2452
2496
  : null,
2453
2497
  playCallGovernance: governance,
2454
- dynamicWorkerCode: null,
2498
+ dynamicWorkerCode:
2499
+ typeof manifest.bundledCode === 'string'
2500
+ ? manifest.bundledCode
2501
+ : null,
2455
2502
  executorToken: childToken,
2456
2503
  baseUrl: resolveRuntimeBaseUrl(env, body),
2457
2504
  orgId,
@@ -2751,7 +2798,7 @@ function loadDynamicPlayWorkerSync(
2751
2798
  }
2752
2799
  const artifactIdentity =
2753
2800
  metadata.artifactHash?.trim() || stableHash(artifactStorageKey);
2754
- const workerCacheKey = `play:${graphHash}:${artifactIdentity}:harness=h3`;
2801
+ const workerCacheKey = `play:${graphHash}:${artifactIdentity}:harness=h4-runtime-api`;
2755
2802
  const runIdForTrace = metadata.runId ?? graphHash;
2756
2803
  const loaderGetStartedAt = Date.now();
2757
2804
  const stub = env.LOADER.get(workerCacheKey, async () => {
@@ -2777,6 +2824,11 @@ function loadDynamicPlayWorkerSync(
2777
2824
  // which case the per-play stub throws a loud error on first use
2778
2825
  // (no silent fallbacks — see harness-stub.ts → requireBinding).
2779
2826
  HARNESS: env.HARNESS,
2827
+ VERCEL_PROTECTION_BYPASS_TOKEN: env.VERCEL_PROTECTION_BYPASS_TOKEN,
2828
+ // In-process runtime API bridge used by the play harness for status,
2829
+ // tool execution, DB session, and artifact callbacks. This avoids a
2830
+ // public fetch hop when Cloudflare exposes the RuntimeApi export.
2831
+ ...makeRuntimeApiEnvBinding(),
2780
2832
  // NOTE: We intentionally do NOT pass `env.PLAYS_BUCKET` (an R2Bucket
2781
2833
  // binding) through to the per-play Worker's env. Including a raw
2782
2834
  // R2Bucket in the dynamically-loaded Worker's env makes Cloudflare
@@ -2828,7 +2880,7 @@ async function loadDynamicPlayWorker(
2828
2880
  }
2829
2881
  const artifactIdentity =
2830
2882
  metadata.artifactHash?.trim() || stableHash(artifactStorageKey);
2831
- const workerCacheKey = `play:${graphHash}:${artifactIdentity}:harness=h3`;
2883
+ const workerCacheKey = `play:${graphHash}:${artifactIdentity}:harness=h4-runtime-api`;
2832
2884
  const runIdForTrace = metadata.runId ?? graphHash;
2833
2885
  const loaderGetStartedAt = Date.now();
2834
2886
  const stub = env.LOADER.get(workerCacheKey, async () => {
@@ -2849,9 +2901,12 @@ async function loadDynamicPlayWorker(
2849
2901
  env: {
2850
2902
  // Mirror of the sync loader (above) — see that copy for the
2851
2903
  // architectural rationale. The dynamic worker env is intentionally
2852
- // minimal; runtime callbacks and file reads go through HARNESS, and
2853
- // child workflow control uses the coordinator URL in the run request.
2904
+ // minimal; runtime callbacks use RUNTIME_API, file reads go through
2905
+ // HARNESS, and child workflow control uses the coordinator URL in the
2906
+ // run request.
2854
2907
  HARNESS: env.HARNESS,
2908
+ VERCEL_PROTECTION_BYPASS_TOKEN: env.VERCEL_PROTECTION_BYPASS_TOKEN,
2909
+ ...makeRuntimeApiEnvBinding(),
2855
2910
  },
2856
2911
  };
2857
2912
  });
@@ -3159,11 +3214,15 @@ async function handleCoordinatorWarmup(
3159
3214
  * structured-cloneable. WorkerEntrypoint stubs ARE cloneable — same trick
3160
3215
  * `makePlayAssetsBinding` already uses.
3161
3216
  *
3162
- * Falls back transparently in legacy coordinators: if the binding isn't
3163
- * present in `env`, the harness uses its existing `fetch(req.baseUrl + path)`
3164
- * path, which still works (just slower).
3217
+ * Falls back transparently when Cloudflare does not expose module exports in
3218
+ * the current execution path: if the binding is omitted from `env`, the play
3219
+ * worker uses its existing `fetch(req.baseUrl + path)` transport.
3165
3220
  */
3166
- function makeRuntimeApiBinding(): { fetch(req: Request): Promise<Response> } {
3221
+ let loggedMissingRuntimeApiExport = false;
3222
+
3223
+ function makeRuntimeApiEnvBinding():
3224
+ | { RUNTIME_API: { fetch(req: Request): Promise<Response> } }
3225
+ | Record<string, never> {
3167
3226
  const exports = workersExports as unknown as {
3168
3227
  RuntimeApi?: (init: { props: undefined }) => {
3169
3228
  fetch(req: Request): Promise<Response>;
@@ -3171,11 +3230,15 @@ function makeRuntimeApiBinding(): { fetch(req: Request): Promise<Response> } {
3171
3230
  };
3172
3231
  const ctor = exports.RuntimeApi;
3173
3232
  if (typeof ctor !== 'function') {
3174
- throw new Error(
3175
- 'RuntimeApi is not registered on cloudflare:workers exports.',
3176
- );
3233
+ if (!loggedMissingRuntimeApiExport) {
3234
+ loggedMissingRuntimeApiExport = true;
3235
+ console.warn(
3236
+ '[coordinator] RuntimeApi is not registered on cloudflare:workers exports; using public runtime API transport.',
3237
+ );
3238
+ }
3239
+ return {};
3177
3240
  }
3178
- return ctor({ props: undefined });
3241
+ return { RUNTIME_API: ctor({ props: undefined }) };
3179
3242
  }
3180
3243
 
3181
3244
  function makeCoordinatorControlBinding(): {
@@ -3251,6 +3314,9 @@ function mapWorkflowResult(
3251
3314
  : null;
3252
3315
  return {
3253
3316
  runId,
3317
+ ...(typeof output?.playName === 'string' && output.playName.trim()
3318
+ ? { playName: output.playName.trim() }
3319
+ : {}),
3254
3320
  status: mapped,
3255
3321
  result: output?.result ?? status.output ?? null,
3256
3322
  error,