deepline 0.3.34 → 0.3.36

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.
@@ -199,7 +199,7 @@ export const SDK_RELEASE = {
199
199
  // available at toolResponse.rawV2 while toolResponse.raw and all declared
200
200
  // getters keep their established compatibility behavior.
201
201
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
202
- version: '0.3.34',
202
+ version: '0.3.36',
203
203
  updateSummary:
204
204
  'Automatic CLI updates are now enabled by default. To opt out, run `deepline settings autoupdate off`; use `deepline settings autoupdate on` to re-enable updates or `deepline settings autoupdate pin <version>` to hold an exact release. This release also adds raw-v2 tool responses at toolResponse.rawV2 while preserving existing toolResponse.raw and declared getters.',
205
205
  packageCapabilities: {
@@ -1,3 +1,8 @@
1
+ import type {
2
+ ToolExecutionErrorCategory,
3
+ ToolExecutionErrorOrigin,
4
+ } from '../tool-execution-error';
5
+
1
6
  /**
2
7
  * The durable terminal envelope carries the complete 5 MiB authored return
3
8
  * plus bounded scheduler-owned metadata (progress, warnings, and a log tail).
@@ -301,6 +306,14 @@ const LEDGER_STRIPPED_TERMINAL_RESULT_KEYS = [
301
306
  'suspension',
302
307
  ] as const;
303
308
 
309
+ export type LedgerTerminalFailureSummary = {
310
+ code: string;
311
+ phase: string;
312
+ retryable: boolean | null;
313
+ origin?: ToolExecutionErrorOrigin;
314
+ category?: ToolExecutionErrorCategory;
315
+ };
316
+
304
317
  /** A tiny reference descriptor left in place of a dropped over-limit result. */
305
318
  export type LedgerTerminalResultRef = {
306
319
  __kind: 'deepline.ledger_terminal_result_ref.v1';
@@ -323,6 +336,8 @@ export type LedgerTerminalResultRef = {
323
336
  * fetching the complete scheduler result.
324
337
  */
325
338
  preview?: BoundedRunListOutputPreview;
339
+ /** Failure ownership retained when the full failed result is out of line. */
340
+ failure?: LedgerTerminalFailureSummary;
326
341
  };
327
342
 
328
343
  export const LEDGER_TERMINAL_RESULT_STORED_WARNING =
@@ -682,6 +697,7 @@ function ledgerTerminalResultRef(
682
697
  content?: 'full';
683
698
  bytes?: number;
684
699
  preview?: BoundedRunListOutputPreview;
700
+ failure?: LedgerTerminalFailureSummary;
685
701
  } = {},
686
702
  ): LedgerTerminalResultRef {
687
703
  return {
@@ -693,12 +709,83 @@ function ledgerTerminalResultRef(
693
709
  projection: 'out_of_line',
694
710
  ...(options.content ? { content: options.content } : {}),
695
711
  ...(options.preview ? { preview: options.preview } : {}),
712
+ ...(options.failure ? { failure: options.failure } : {}),
696
713
  warning: options.content
697
714
  ? LEDGER_TERMINAL_RESULT_STORED_WARNING
698
715
  : LEDGER_TERMINAL_RESULT_OMITTED_WARNING,
699
716
  };
700
717
  }
701
718
 
719
+ const TOOL_ERROR_ORIGINS = new Set<ToolExecutionErrorOrigin>([
720
+ 'caller',
721
+ 'provider',
722
+ 'deepline',
723
+ 'unknown',
724
+ ]);
725
+
726
+ const TOOL_ERROR_CATEGORIES = new Set<ToolExecutionErrorCategory>([
727
+ 'validation',
728
+ 'authentication',
729
+ 'authorization',
730
+ 'rate_limit',
731
+ 'network',
732
+ 'upstream',
733
+ 'billing',
734
+ 'conflict',
735
+ 'internal',
736
+ 'unknown',
737
+ ]);
738
+
739
+ const LEDGER_FAILURE_CODE_MAX_LENGTH = 160;
740
+ const LEDGER_FAILURE_PHASE_MAX_LENGTH = 80;
741
+
742
+ function terminalFailureSummary(
743
+ value: unknown,
744
+ ): LedgerTerminalFailureSummary | undefined {
745
+ if (!isPlainObject(value) || !Array.isArray(value.errors)) return undefined;
746
+ const first = value.errors.find(isPlainObject);
747
+ if (!first) return undefined;
748
+ const rawRetryable = first.retryable;
749
+ let retryable: boolean | null;
750
+ if (typeof rawRetryable === 'boolean') {
751
+ retryable = rawRetryable;
752
+ } else if (rawRetryable === null) {
753
+ retryable = null;
754
+ } else {
755
+ return undefined;
756
+ }
757
+ if (typeof first.code !== 'string' || typeof first.phase !== 'string') {
758
+ return undefined;
759
+ }
760
+ const code = first.code.trim();
761
+ const phase = first.phase.trim();
762
+ if (
763
+ !code ||
764
+ code.length > LEDGER_FAILURE_CODE_MAX_LENGTH ||
765
+ !phase ||
766
+ phase.length > LEDGER_FAILURE_PHASE_MAX_LENGTH
767
+ ) {
768
+ return undefined;
769
+ }
770
+ const origin = TOOL_ERROR_ORIGINS.has(
771
+ first.origin as ToolExecutionErrorOrigin,
772
+ )
773
+ ? (first.origin as ToolExecutionErrorOrigin)
774
+ : undefined;
775
+ const category = TOOL_ERROR_CATEGORIES.has(
776
+ first.category as ToolExecutionErrorCategory,
777
+ )
778
+ ? (first.category as ToolExecutionErrorCategory)
779
+ : undefined;
780
+ return {
781
+ code,
782
+ phase,
783
+ retryable,
784
+ ...(origin ? { origin } : {}),
785
+ ...(category ? { category } : {}),
786
+ };
787
+ }
788
+
702
789
  export function ledgerTerminalResultRefForValue(
703
790
  value: unknown,
704
791
  reason: LedgerTerminalResultRefReason,
@@ -721,7 +808,12 @@ export function ledgerTerminalResultRefForValue(
721
808
  // persistence failure.
722
809
  }
723
810
  }
724
- return ledgerTerminalResultRef(reason, { ...options, bytes, preview });
811
+ return ledgerTerminalResultRef(reason, {
812
+ ...options,
813
+ bytes,
814
+ preview,
815
+ failure: terminalFailureSummary(value),
816
+ });
725
817
  }
726
818
 
727
819
  /** Optional derived summaries must never block the terminal lifecycle event. */
@@ -1,4 +1,8 @@
1
- import { ToolExecutionError } from '../tool-execution-error';
1
+ import {
2
+ ToolExecutionError,
3
+ type ToolExecutionErrorCategory,
4
+ type ToolExecutionErrorOrigin,
5
+ } from '../tool-execution-error';
2
6
 
3
7
  const CLOUDFLARE_DURABLE_OBJECT_RESET_RE =
4
8
  /Durable Object.*(?:code (?:was|has been) updated|storage caused object)/;
@@ -186,6 +190,10 @@ export type PlayRunFailureDetails = {
186
190
  phase: string;
187
191
  message: string;
188
192
  retryable: boolean | null;
193
+ /** Original ownership boundary when the failure came from a typed tool call. */
194
+ origin?: ToolExecutionErrorOrigin;
195
+ /** Original reason family when the failure came from a typed tool call. */
196
+ category?: ToolExecutionErrorCategory;
189
197
  cause?: string;
190
198
  name?: string;
191
199
  stack?: string;
@@ -305,6 +313,8 @@ export function normalizePlayRunFailure(error: unknown): PlayRunFailureDetails {
305
313
  phase: 'billing',
306
314
  message: cause,
307
315
  retryable: false,
316
+ origin: error.origin,
317
+ category: error.category,
308
318
  cause,
309
319
  };
310
320
  }
@@ -534,7 +544,10 @@ export function normalizePlayRunFailure(error: unknown): PlayRunFailureDetails {
534
544
  code: 'RUN_FAILED',
535
545
  phase: 'runtime',
536
546
  message: cause,
537
- retryable: null,
547
+ retryable: error instanceof ToolExecutionError ? error.retryable : null,
548
+ ...(error instanceof ToolExecutionError
549
+ ? { origin: error.origin, category: error.category }
550
+ : {}),
538
551
  ...(diagnostics
539
552
  ? {
540
553
  name: diagnostics.name,
@@ -16,6 +16,12 @@ export type ResolveStaticPipelineInput = {
16
16
  playId: string,
17
17
  ) => Promise<ResolvablePlayStaticShape | null>;
18
18
  maxDepth?: number;
19
+ /**
20
+ * Keep an embedded local-import contract when one is present, while still
21
+ * resolving compact calls nested inside it. Named live calls omit the
22
+ * embedded pipeline and continue through the registry resolver.
23
+ */
24
+ preferEmbeddedPlayCalls?: boolean;
19
25
  };
20
26
 
21
27
  function clonePipeline(pipeline: PlayStaticPipeline): PlayStaticPipeline {
@@ -69,8 +75,17 @@ async function resolvePipelineSubsteps(input: {
69
75
  ) => Promise<ResolvablePlayStaticShape | null>;
70
76
  stack: string[];
71
77
  maxDepth: number;
78
+ preferEmbeddedPlayCalls: boolean;
79
+ resolvedPipelineCache: Map<string, Promise<PlayStaticPipeline | null>>;
72
80
  }): Promise<PlayStaticSubstep[]> {
73
- const { steps, resolveReferencedPlay, stack, maxDepth } = input;
81
+ const {
82
+ steps,
83
+ resolveReferencedPlay,
84
+ stack,
85
+ maxDepth,
86
+ preferEmbeddedPlayCalls,
87
+ resolvedPipelineCache,
88
+ } = input;
74
89
  const callDepth = Math.max(0, stack.length - 1);
75
90
 
76
91
  return await Promise.all(
@@ -81,20 +96,44 @@ async function resolvePipelineSubsteps(input: {
81
96
  });
82
97
 
83
98
  if (
84
- (annotated.type === 'dataset' ||
85
- annotated.type === 'step_suite' ||
86
- annotated.type === 'control_flow') &&
87
- annotated.steps?.length
99
+ annotated.type === 'dataset' ||
100
+ annotated.type === 'step_suite' ||
101
+ annotated.type === 'control_flow'
88
102
  ) {
89
- return {
103
+ const nested = {
90
104
  ...annotated,
91
- steps: await resolvePipelineSubsteps({
92
- steps: annotated.steps,
93
- resolveReferencedPlay,
94
- stack,
95
- maxDepth,
96
- }),
97
- } satisfies PlayStaticSubstep;
105
+ ...(annotated.steps?.length
106
+ ? {
107
+ steps: await resolvePipelineSubsteps({
108
+ steps: annotated.steps,
109
+ resolveReferencedPlay,
110
+ stack,
111
+ maxDepth,
112
+ preferEmbeddedPlayCalls,
113
+ resolvedPipelineCache,
114
+ }),
115
+ }
116
+ : {}),
117
+ };
118
+ if (nested.type === 'control_flow' && nested.branches?.length) {
119
+ return {
120
+ ...nested,
121
+ branches: await Promise.all(
122
+ nested.branches.map(async (branch) => ({
123
+ ...branch,
124
+ steps: await resolvePipelineSubsteps({
125
+ steps: branch.steps,
126
+ resolveReferencedPlay,
127
+ stack,
128
+ maxDepth,
129
+ preferEmbeddedPlayCalls,
130
+ resolvedPipelineCache,
131
+ }),
132
+ })),
133
+ ),
134
+ } satisfies PlayStaticSubstep;
135
+ }
136
+ return nested satisfies PlayStaticSubstep;
98
137
  }
99
138
 
100
139
  if (annotated.type !== 'play_call') {
@@ -118,9 +157,51 @@ async function resolvePipelineSubsteps(input: {
118
157
  } satisfies PlayStaticSubstep;
119
158
  }
120
159
 
121
- const childShape = await resolveReferencedPlay(annotated.playId);
122
- const childPipeline = materializePipeline(childShape);
123
- if (!childPipeline) {
160
+ const cacheKey = JSON.stringify([...stack, annotated.playId]);
161
+ let resolvedChildPipelinePromise = resolvedPipelineCache.get(cacheKey);
162
+ if (!resolvedChildPipelinePromise) {
163
+ resolvedChildPipelinePromise = (async () => {
164
+ const childShape =
165
+ preferEmbeddedPlayCalls && annotated.pipeline
166
+ ? { staticPipeline: annotated.pipeline }
167
+ : await resolveReferencedPlay(annotated.playId);
168
+ const childPipeline = materializePipeline(childShape);
169
+ if (!childPipeline) {
170
+ return null;
171
+ }
172
+
173
+ const resolvedChildPipeline = {
174
+ ...childPipeline,
175
+ stages: await resolvePipelineSubsteps({
176
+ steps: childPipeline.stages ?? [],
177
+ resolveReferencedPlay,
178
+ stack: [...stack, annotated.playId],
179
+ maxDepth,
180
+ preferEmbeddedPlayCalls,
181
+ resolvedPipelineCache,
182
+ }),
183
+ substeps: await resolvePipelineSubsteps({
184
+ steps: childPipeline.substeps,
185
+ resolveReferencedPlay,
186
+ stack: [...stack, annotated.playId],
187
+ maxDepth,
188
+ preferEmbeddedPlayCalls,
189
+ resolvedPipelineCache,
190
+ }),
191
+ };
192
+ const childContract = compileSheetContract(resolvedChildPipeline);
193
+
194
+ return {
195
+ ...resolvedChildPipeline,
196
+ sheetContract: childContract.contract,
197
+ sheetContractErrors: childContract.errors,
198
+ };
199
+ })();
200
+ resolvedPipelineCache.set(cacheKey, resolvedChildPipelinePromise);
201
+ }
202
+
203
+ const resolvedChildPipeline = await resolvedChildPipelinePromise;
204
+ if (!resolvedChildPipeline) {
124
205
  return {
125
206
  ...annotated,
126
207
  resolutionError: `Unable to statically resolve play "${annotated.playId}"`,
@@ -128,30 +209,9 @@ async function resolvePipelineSubsteps(input: {
128
209
  } satisfies PlayStaticSubstep;
129
210
  }
130
211
 
131
- const resolvedChildPipeline = {
132
- ...childPipeline,
133
- stages: await resolvePipelineSubsteps({
134
- steps: childPipeline.stages ?? [],
135
- resolveReferencedPlay,
136
- stack: [...stack, annotated.playId],
137
- maxDepth,
138
- }),
139
- substeps: await resolvePipelineSubsteps({
140
- steps: childPipeline.substeps,
141
- resolveReferencedPlay,
142
- stack: [...stack, annotated.playId],
143
- maxDepth,
144
- }),
145
- };
146
- const childContract = compileSheetContract(resolvedChildPipeline);
147
-
148
212
  return {
149
213
  ...annotated,
150
- pipeline: {
151
- ...resolvedChildPipeline,
152
- sheetContract: childContract.contract,
153
- sheetContractErrors: childContract.errors,
154
- },
214
+ pipeline: resolvedChildPipeline,
155
215
  } satisfies PlayStaticSubstep;
156
216
  }),
157
217
  );
@@ -161,10 +221,15 @@ export async function resolveStaticPipelineTree(
161
221
  input: ResolveStaticPipelineInput,
162
222
  ): Promise<PlayStaticPipeline | null> {
163
223
  const maxDepth = input.maxDepth ?? 6;
224
+ const preferEmbeddedPlayCalls = input.preferEmbeddedPlayCalls ?? false;
164
225
  const rootPipeline = materializePipeline(input.root);
165
226
  if (!rootPipeline) {
166
227
  return null;
167
228
  }
229
+ const resolvedPipelineCache = new Map<
230
+ string,
231
+ Promise<PlayStaticPipeline | null>
232
+ >();
168
233
 
169
234
  const resolvedPipeline = {
170
235
  ...rootPipeline,
@@ -173,12 +238,16 @@ export async function resolveStaticPipelineTree(
173
238
  resolveReferencedPlay: input.resolveReferencedPlay,
174
239
  stack: [input.rootPlayId],
175
240
  maxDepth,
241
+ preferEmbeddedPlayCalls,
242
+ resolvedPipelineCache,
176
243
  }),
177
244
  substeps: await resolvePipelineSubsteps({
178
245
  steps: rootPipeline.substeps,
179
246
  resolveReferencedPlay: input.resolveReferencedPlay,
180
247
  stack: [input.rootPlayId],
181
248
  maxDepth,
249
+ preferEmbeddedPlayCalls,
250
+ resolvedPipelineCache,
182
251
  }),
183
252
  };
184
253
  const contract = compileSheetContract(resolvedPipeline);
@@ -609,6 +609,13 @@ export function truncateStaticPipelineForRuntimeContract(
609
609
  */
610
610
  export function createStaticPipelineReferenceProjection(
611
611
  pipeline: PlayStaticPipeline | null | undefined,
612
+ options?: {
613
+ /**
614
+ * Local imported Plays do not have an independently published registry
615
+ * contract. Keep those embedded while compacting live named Play calls.
616
+ */
617
+ preserveEmbeddedPlayIds?: ReadonlySet<string>;
618
+ },
612
619
  ): PlayStaticPipeline | null | undefined {
613
620
  const stored = truncateStaticPipelineForStorage(pipeline, {
614
621
  maxEmbeddedPlayCallPipelineDepth: Number.POSITIVE_INFINITY,
@@ -629,6 +636,13 @@ export function createStaticPipelineReferenceProjection(
629
636
  }>;
630
637
  };
631
638
  if (projected.type === 'play_call') {
639
+ if (
640
+ projected.pipeline &&
641
+ options?.preserveEmbeddedPlayIds?.has(projected.playId)
642
+ ) {
643
+ projected.pipeline = projectPipeline(projected.pipeline);
644
+ return projected;
645
+ }
632
646
  delete projected.pipeline;
633
647
  if (
634
648
  projected.resolutionError?.startsWith(
@@ -656,11 +670,15 @@ export function createStaticPipelineReferenceProjection(
656
670
  return projected;
657
671
  });
658
672
 
659
- return {
660
- ...stored,
661
- stages: projectSteps(stored.stages),
662
- substeps: projectSteps(stored.substeps),
663
- };
673
+ const projectPipeline = (
674
+ candidate: PlayStaticPipeline,
675
+ ): PlayStaticPipeline => ({
676
+ ...candidate,
677
+ stages: projectSteps(candidate.stages),
678
+ substeps: projectSteps(candidate.substeps),
679
+ });
680
+
681
+ return projectPipeline(stored);
664
682
  }
665
683
 
666
684
  function asStaticRecord(value: unknown): Record<string, unknown> | null {
package/dist/cli/index.js CHANGED
@@ -1043,7 +1043,7 @@ var SDK_RELEASE = {
1043
1043
  // available at toolResponse.rawV2 while toolResponse.raw and all declared
1044
1044
  // getters keep their established compatibility behavior.
1045
1045
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
1046
- version: "0.3.34",
1046
+ version: "0.3.36",
1047
1047
  updateSummary: "Automatic CLI updates are now enabled by default. To opt out, run `deepline settings autoupdate off`; use `deepline settings autoupdate on` to re-enable updates or `deepline settings autoupdate pin <version>` to hold an exact release. This release also adds raw-v2 tool responses at toolResponse.rawV2 while preserving existing toolResponse.raw and declared getters.",
1048
1048
  packageCapabilities: {
1049
1049
  updatePreferences: 1
@@ -1029,7 +1029,7 @@ var SDK_RELEASE = {
1029
1029
  // available at toolResponse.rawV2 while toolResponse.raw and all declared
1030
1030
  // getters keep their established compatibility behavior.
1031
1031
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
1032
- version: "0.3.34",
1032
+ version: "0.3.36",
1033
1033
  updateSummary: "Automatic CLI updates are now enabled by default. To opt out, run `deepline settings autoupdate off`; use `deepline settings autoupdate on` to re-enable updates or `deepline settings autoupdate pin <version>` to hold an exact release. This release also adds raw-v2 tool responses at toolResponse.rawV2 while preserving existing toolResponse.raw and declared getters.",
1034
1034
  packageCapabilities: {
1035
1035
  updatePreferences: 1
package/dist/index.js CHANGED
@@ -779,7 +779,7 @@ var SDK_RELEASE = {
779
779
  // available at toolResponse.rawV2 while toolResponse.raw and all declared
780
780
  // getters keep their established compatibility behavior.
781
781
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
782
- version: "0.3.34",
782
+ version: "0.3.36",
783
783
  updateSummary: "Automatic CLI updates are now enabled by default. To opt out, run `deepline settings autoupdate off`; use `deepline settings autoupdate on` to re-enable updates or `deepline settings autoupdate pin <version>` to hold an exact release. This release also adds raw-v2 tool responses at toolResponse.rawV2 while preserving existing toolResponse.raw and declared getters.",
784
784
  packageCapabilities: {
785
785
  updatePreferences: 1
package/dist/index.mjs CHANGED
@@ -702,7 +702,7 @@ var SDK_RELEASE = {
702
702
  // available at toolResponse.rawV2 while toolResponse.raw and all declared
703
703
  // getters keep their established compatibility behavior.
704
704
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
705
- version: "0.3.34",
705
+ version: "0.3.36",
706
706
  updateSummary: "Automatic CLI updates are now enabled by default. To opt out, run `deepline settings autoupdate off`; use `deepline settings autoupdate on` to re-enable updates or `deepline settings autoupdate pin <version>` to hold an exact release. This release also adds raw-v2 tool responses at toolResponse.rawV2 while preserving existing toolResponse.raw and declared getters.",
707
707
  packageCapabilities: {
708
708
  updatePreferences: 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepline",
3
- "version": "0.3.34",
3
+ "version": "0.3.36",
4
4
  "description": "GTM data CLI and TypeScript SDK for coding agents",
5
5
  "license": "MIT",
6
6
  "homepage": "https://code.deepline.com",