deepline 0.3.257 → 0.3.259

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 (68) hide show
  1. package/dist/bundling-sources/sdk/src/api-error.ts +45 -0
  2. package/dist/bundling-sources/sdk/src/client.ts +98 -459
  3. package/dist/bundling-sources/sdk/src/http.ts +1 -34
  4. package/dist/bundling-sources/sdk/src/index.ts +8 -0
  5. package/dist/bundling-sources/sdk/src/plays/csv-data-input.ts +139 -0
  6. package/dist/bundling-sources/sdk/src/plays/run-request.ts +855 -0
  7. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  8. package/dist/bundling-sources/sdk/src/runs/overview.ts +45 -2
  9. package/dist/bundling-sources/sdk/src/types.ts +5 -0
  10. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +8 -0
  11. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +42 -10
  12. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +3 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/launch-source-policy.ts +23 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/live-state-contract.ts +3 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/play-admission-outcome.ts +23 -5
  16. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/gateway-adapter.ts +1 -1
  17. package/dist/bundling-sources/shared_libs/play-runtime/run-execution-state.ts +845 -0
  18. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +106 -6
  19. package/dist/bundling-sources/shared_libs/play-runtime/run-observation.ts +440 -0
  20. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +35 -2
  21. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +66 -7
  22. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +0 -29
  23. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-row-transition.ts +47 -2
  24. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +6 -0
  25. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +475 -36
  26. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +78 -11
  27. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +550 -42
  28. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +181 -8
  29. package/dist/bundling-sources/shared_libs/play-runtime/step-lifecycle-tracker.ts +0 -18
  30. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +80 -7
  31. package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +37 -2
  32. package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +148 -18
  33. package/dist/bundling-sources/shared_libs/plays/cascade-falloff.ts +86 -0
  34. package/dist/bundling-sources/shared_libs/plays/docflow-unreached-reason.ts +611 -0
  35. package/dist/bundling-sources/shared_libs/plays/docflow.ts +21 -0
  36. package/dist/bundling-sources/shared_libs/plays/play-exports.ts +28 -5
  37. package/dist/bundling-sources/shared_libs/plays/play-grep-search.ts +40 -2
  38. package/dist/bundling-sources/shared_libs/plays/settings-contract.ts +92 -10
  39. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +5 -0
  40. package/dist/bundling-sources/shared_libs/plays/trigger-config-contract.ts +222 -0
  41. package/dist/bundling-sources/shared_libs/plays/trigger-config-route.ts +15 -0
  42. package/dist/cli/index.js +4957 -771
  43. package/dist/cli/index.mjs +4957 -771
  44. package/dist/client-B5XbKrrs.d.mts +6564 -0
  45. package/dist/client-C9Y49yya.d.ts +6564 -0
  46. package/dist/{compiler-manifest-C4mdRJOP.d.mts → compiler-manifest-CUuh8C3b.d.mts} +14 -1
  47. package/dist/{compiler-manifest-C4mdRJOP.d.ts → compiler-manifest-CUuh8C3b.d.ts} +14 -1
  48. package/dist/index.d.mts +7 -6275
  49. package/dist/index.d.ts +7 -6275
  50. package/dist/index.js +360 -326
  51. package/dist/index.mjs +360 -326
  52. package/dist/install-integrity.json +21 -2
  53. package/dist/plays/bundle-play-file.d.mts +2 -2
  54. package/dist/plays/bundle-play-file.d.ts +2 -2
  55. package/dist/plays/bundle-play-file.mjs +117 -18
  56. package/dist/plays/csv-data-input.d.mts +37 -0
  57. package/dist/plays/csv-data-input.d.ts +37 -0
  58. package/dist/plays/csv-data-input.js +3135 -0
  59. package/dist/plays/csv-data-input.mjs +3108 -0
  60. package/dist/plays/run-request.d.mts +6 -0
  61. package/dist/plays/run-request.d.ts +6 -0
  62. package/dist/plays/run-request.js +664 -0
  63. package/dist/plays/run-request.mjs +614 -0
  64. package/dist/release.d.mts +1 -1
  65. package/dist/release.d.ts +1 -1
  66. package/dist/release.js +1 -1
  67. package/dist/release.mjs +1 -1
  68. package/package.json +12 -1
@@ -10,12 +10,14 @@ import {
10
10
  type PlayRunRowOutcomeSummary,
11
11
  } from './run-ledger';
12
12
  import {
13
+ decodePlayRunPublicStatus,
13
14
  isActivePlayRunLifecycleStatus,
14
15
  isTerminalPlayRunLifecycleStatus,
15
16
  normalizePlayRunLifecycleStatus,
16
17
  type PlayRunLifecycleStatus,
17
18
  } from './run-lifecycle-policy';
18
19
  import type { PlayDocflowNodeIoState } from './docflow-node-io';
20
+ import type { RunStopCause } from './run-execution-state';
19
21
  import type { PlayVisualNodeUsageSnapshot } from './live-state-contract';
20
22
  import {
21
23
  projectPlayRunActivity,
@@ -57,6 +59,8 @@ export type PlayRunStreamNodeState = {
57
59
  nodeId: string;
58
60
  status: 'idle' | 'running' | 'completed' | 'failed' | 'skipped';
59
61
  error?: string | null;
62
+ /** The run's terminal event settled this step in flight (ledger fact). */
63
+ stoppedBy?: RunStopCause;
60
64
  artifactTableNamespace?: string | null;
61
65
  progress?: PlayRunStreamNodeProgress | null;
62
66
  startedAt?: number | null;
@@ -193,6 +197,28 @@ function extractTerminalRunLogTail(result: unknown): {
193
197
  };
194
198
  }
195
199
 
200
+ /**
201
+ * Whether the run stopped under this step rather than the step failing. The
202
+ * ledger records it (`stoppedBy`) since run-execution-state; a snapshot written
203
+ * before that settled every in-flight step `failed` on the run's terminal
204
+ * event WITHOUT an error of its own, while a step that failed itself carries
205
+ * one (`step.failed` with its error). Projected here, once, so every reader —
206
+ * the run read, the observation, the CLI — gets the same fact.
207
+ */
208
+ function stepStopCause(
209
+ step: PlayRunLedgerStepSnapshot,
210
+ runStatus: PlayRunLedgerSnapshot['status'],
211
+ ): { stoppedBy?: RunStopCause } {
212
+ if (step.status !== 'failed') return {};
213
+ if (step.stoppedBy) return { stoppedBy: step.stoppedBy };
214
+ const run = decodePlayRunPublicStatus(runStatus);
215
+ if (run === 'cancelled') return { stoppedBy: 'run_cancelled' };
216
+ if (run === 'failed' && !step.error?.trim()) {
217
+ return { stoppedBy: 'run_failed' };
218
+ }
219
+ return {};
220
+ }
221
+
196
222
  function buildSnapshotFromLedger(
197
223
  snapshot: PlayRunLedgerSnapshot,
198
224
  ): PlayRunLiveSnapshot {
@@ -203,6 +229,7 @@ function buildSnapshotFromLedger(
203
229
  nodeId: step.stepId,
204
230
  status: step.status,
205
231
  error: step.error ?? null,
232
+ ...stepStopCause(step, snapshot.status),
206
233
  artifactTableNamespace: step.artifactTableNamespace ?? null,
207
234
  progress: step.progress
208
235
  ? {
@@ -327,9 +354,15 @@ export function buildPlayRunStatusSnapshot(input: {
327
354
  playName: input.run.name,
328
355
  status: projectedSnapshot.status,
329
356
  updatedAt: projectedSnapshot.updatedAt,
330
- waitKind: input.run.waitKind ?? input.run.wait?.kind ?? null,
357
+ // The typed wait is recorded on the durable `run.waiting` ledger event;
358
+ // run-record fields are an older projection that may not carry it.
359
+ waitKind:
360
+ input.run.waitKind ??
361
+ input.run.wait?.kind ??
362
+ ledgerSnapshot.waitKind ??
363
+ null,
331
364
  waitBoundaryId: input.run.wait?.boundaryId ?? input.run.activeBoundaryId,
332
- waitUntil: input.run.waitUntil,
365
+ waitUntil: input.run.waitUntil ?? ledgerSnapshot.waitUntil ?? null,
333
366
  eventKey: input.run.wait?.eventKey ?? null,
334
367
  runtimeBackend: input.run.runtimeBackend,
335
368
  activeNodeId: input.run.activeBoundaryId ?? projectedSnapshot.activeNodeId,
@@ -43,6 +43,10 @@ import {
43
43
  runtimeLimitExceededFailure,
44
44
  } from '../run-failure';
45
45
  import { createPlayContext } from '../context';
46
+ import {
47
+ isHtmlErrorBody,
48
+ summarizeHtmlErrorBody,
49
+ } from '../tool-http-errors';
46
50
  import { augmentSheetContractWithDatasetFields } from '../../play-data-plane/sheet-contract';
47
51
  import { nextWorkCounterInvocationSeq } from '../runtime-work-counters';
48
52
  import type { RuntimeApiResponseMeta } from '../app-runtime-api';
@@ -688,9 +692,11 @@ function createRuntimeToolMetadataResolver(config: PlayRunnerExecutionConfig) {
688
692
  },
689
693
  });
690
694
  if (!response.ok) {
691
- throw new Error(
692
- `Runtime metadata lookup for tool ${normalizedToolId} failed (${response.status}): ${await response.text()}`,
693
- );
695
+ throw await runtimeControlHttpError({
696
+ description: `Runtime metadata lookup for tool ${normalizedToolId}`,
697
+ toolId: normalizedToolId,
698
+ response,
699
+ });
694
700
  }
695
701
  return (await response.json()) as RuntimeToolMetadata;
696
702
  })();
@@ -730,9 +736,11 @@ function createAppRuntimeToolAuthScopeDigestResolver(
730
736
  },
731
737
  });
732
738
  if (!response.ok) {
733
- throw new Error(
734
- `Runtime auth scope lookup for tool ${normalizedToolId} failed (${response.status}): ${await response.text()}`,
735
- );
739
+ throw await runtimeControlHttpError({
740
+ description: `Runtime auth scope lookup for tool ${normalizedToolId}`,
741
+ toolId: normalizedToolId,
742
+ response,
743
+ });
736
744
  }
737
745
  const body = (await response.json()) as RuntimeToolAuthScope;
738
746
  const digest = typeof body.digest === 'string' ? body.digest.trim() : '';
@@ -952,11 +960,62 @@ export function formatRuntimeControlFailure(input: {
952
960
  message = [code, error, operatorHint].filter(Boolean).join(': ');
953
961
  }
954
962
  } catch {
955
- // Preserve the original runtime-control response for unstructured errors.
963
+ // Not JSON. An edge proxy's HTML error page (a tunnel or gateway that
964
+ // never reached the app) is kilobytes of markup with nothing in it but a
965
+ // title and a Ray ID: name the failure and keep those, never the page —
966
+ // it was stored verbatim as every failed row's error (6.7 KB a row).
967
+ message = isHtmlErrorBody(input.bodyText)
968
+ ? `${runtimeControlStatusLabel(input.status)} — ${summarizeHtmlErrorBody(input.bodyText)}`
969
+ : input.bodyText.replace(/\s+/g, ' ').trim().slice(0, 500);
956
970
  }
957
971
  return `${input.description} failed (${input.status}): ${message}`;
958
972
  }
959
973
 
974
+ /** What a gateway status means, for a reader who sees only the message. */
975
+ function runtimeControlStatusLabel(status: number): string {
976
+ switch (status) {
977
+ case 502:
978
+ return 'Bad gateway';
979
+ case 503:
980
+ return 'Service unavailable';
981
+ case 504:
982
+ return 'Gateway timeout';
983
+ case 520:
984
+ case 521:
985
+ case 522:
986
+ case 523:
987
+ case 524:
988
+ case 525:
989
+ case 526:
990
+ case 530:
991
+ return 'Origin unreachable';
992
+ default:
993
+ return `HTTP ${status}`;
994
+ }
995
+ }
996
+
997
+ /**
998
+ * A failed runtime-control call as an Error that says WHICH call, HOW it
999
+ * failed (`status`) and for WHICH tool — never the raw response body.
1000
+ */
1001
+ async function runtimeControlHttpError(input: {
1002
+ description: string;
1003
+ toolId: string;
1004
+ response: Response;
1005
+ }): Promise<Error> {
1006
+ const bodyText = await input.response.text().catch(() => '');
1007
+ return Object.assign(
1008
+ new Error(
1009
+ formatRuntimeControlFailure({
1010
+ description: input.description,
1011
+ status: input.response.status,
1012
+ bodyText,
1013
+ }),
1014
+ ),
1015
+ { status: input.response.status, toolId: input.toolId },
1016
+ );
1017
+ }
1018
+
960
1019
  function runtimeControlSlackHitlTimeoutError(input: {
961
1020
  toolId: string;
962
1021
  phase: 'prepare' | 'arm' | 'timeout';
@@ -3118,35 +3118,6 @@ function mapRuntimePostgresRow(input: {
3118
3118
  };
3119
3119
  }
3120
3120
 
3121
- function completedRuntimeCellMetaPatch(input: {
3122
- runId: string;
3123
- outputFields: readonly string[];
3124
- rowPatch?: Record<string, unknown>;
3125
- }): Record<string, unknown> {
3126
- const patch: Record<string, unknown> = {};
3127
- const completedAt = Date.now();
3128
- for (const field of input.outputFields) {
3129
- const existing =
3130
- input.rowPatch?.[field] &&
3131
- typeof input.rowPatch[field] === 'object' &&
3132
- !Array.isArray(input.rowPatch[field])
3133
- ? (input.rowPatch[field] as Record<string, unknown>)
3134
- : {};
3135
- patch[field] = {
3136
- status: 'completed',
3137
- runId: input.runId,
3138
- completedAt,
3139
- ...existing,
3140
- };
3141
- }
3142
- for (const [field, meta] of Object.entries(input.rowPatch ?? {})) {
3143
- if (!Object.hasOwn(patch, field)) {
3144
- patch[field] = meta;
3145
- }
3146
- }
3147
- return patch;
3148
- }
3149
-
3150
3121
  function mergeRuntimeCellMetaPatchSql(
3151
3122
  targetExpression: string,
3152
3123
  patchExpression: string,
@@ -49,9 +49,15 @@ export function completedRuntimeCellMetaPatch(input: {
49
49
  : {};
50
50
  patch[field] = {
51
51
  status: 'completed',
52
- runId: input.runId,
53
52
  completedAt,
54
53
  ...existing,
54
+ // This run wrote the row, so this run is the cell's run — including a
55
+ // cell it REUSED (from a receipt or an earlier run's row), whose meta
56
+ // can still carry the run that first produced it. Spread last so a
57
+ // carried stamp never wins: a reused row kept the first run's stamp,
58
+ // the reusing run's column counts held none of its cells, and the
59
+ // canvas lent the step its table's count instead.
60
+ runId: input.runId,
55
61
  };
56
62
  }
57
63
  for (const [field, meta] of Object.entries(input.rowPatch ?? {})) {
@@ -62,6 +68,41 @@ export function completedRuntimeCellMetaPatch(input: {
62
68
  return patch;
63
69
  }
64
70
 
71
+ /**
72
+ * Cell meta for a failed row's terminal write.
73
+ *
74
+ * The durable merge is per cell and shallow (`existing || patch`), so a cell
75
+ * patch that omits `runId` keeps whatever run stamped the cell before. A failed
76
+ * row re-executed by a later run therefore kept the earlier run's stamp on the
77
+ * very cell that failed now, and every per-run column count (which keys on the
78
+ * cell's `runId`) dropped this run's failure.
79
+ *
80
+ * Every output cell this run touched — the ones it carries meta for — is
81
+ * stamped with the current run, exactly as a completed row stamps its cells; the
82
+ * cell's own status (`failed` for the column that threw, `completed` for the
83
+ * ones that resolved before it) is kept. An output cell this run never reached
84
+ * keeps its earlier meta and value: that is still the earlier run's fact, and
85
+ * the row's failure is attributed through the cell that failed.
86
+ */
87
+ export function failedRuntimeCellMetaPatch(input: {
88
+ runId: string;
89
+ outputFields: readonly string[];
90
+ rowPatch?: Record<string, unknown>;
91
+ }): Record<string, unknown> {
92
+ const patch: Record<string, unknown> = { ...(input.rowPatch ?? {}) };
93
+ for (const field of input.outputFields) {
94
+ const existing = patch[field];
95
+ if (!existing || typeof existing !== 'object' || Array.isArray(existing)) {
96
+ continue;
97
+ }
98
+ patch[field] = {
99
+ ...(existing as Record<string, unknown>),
100
+ runId: input.runId,
101
+ };
102
+ }
103
+ return patch;
104
+ }
105
+
65
106
  function serializeRuntimeRowPatch(value: Record<string, unknown>): string {
66
107
  const serialized = stringifyPostgresJson(value);
67
108
  if (serialized === undefined) {
@@ -126,7 +167,11 @@ export function prepareRuntimeSheetRowTransitions(input: {
126
167
  try {
127
168
  cellMetaPatch =
128
169
  row.status === 'failed'
129
- ? (row.cellMetaPatch ?? {})
170
+ ? failedRuntimeCellMetaPatch({
171
+ runId: input.runId,
172
+ outputFields: input.outputFields,
173
+ rowPatch: row.cellMetaPatch,
174
+ })
130
175
  : completedRuntimeCellMetaPatch({
131
176
  runId: input.runId,
132
177
  outputFields: input.outputFields,
@@ -170,6 +170,12 @@ export type PlaySchedulerSubmitInput = RetainedPipelineCarrier & {
170
170
  source?: 'published' | 'ad_hoc' | 'draft';
171
171
  /** Invocation origin, distinct from the artifact source above. */
172
172
  triggerSource?: 'api' | 'webhook' | 'cron' | 'sql_listener' | 'async_child';
173
+ /**
174
+ * Display-only client surface of a person-started run (`ui` | `cli` |
175
+ * `api`). Optional: older launchers and automated triggers omit it, and
176
+ * readers show nothing rather than guess.
177
+ */
178
+ launchSurface?: 'ui' | 'cli' | 'api' | null;
173
179
  /** Null lets a durable trigger wait for capacity; a number bounds queue delay. */
174
180
  queueMaxDelaySeconds?: number | null;
175
181
  /**