deepline 0.1.301 → 0.1.302

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 (35) hide show
  1. package/dist/bundling-sources/sdk/src/client.ts +8 -0
  2. package/dist/bundling-sources/sdk/src/errors.ts +57 -15
  3. package/dist/bundling-sources/sdk/src/http.ts +82 -5
  4. package/dist/bundling-sources/sdk/src/index.ts +4 -0
  5. package/dist/bundling-sources/sdk/src/play.ts +29 -1
  6. package/dist/bundling-sources/sdk/src/release.ts +5 -3
  7. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +120 -14
  8. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +10 -0
  9. package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +59 -11
  10. package/dist/bundling-sources/shared_libs/play-runtime/execution-ledger-store.ts +3 -3
  11. package/dist/bundling-sources/shared_libs/play-runtime/execution-plan.ts +0 -15
  12. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +3 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/runtime-actions.ts +3 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +136 -36
  15. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +17 -12
  16. package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +210 -5
  17. package/dist/bundling-sources/shared_libs/play-runtime/work-receipts.ts +4 -0
  18. package/dist/bundling-sources/shared_libs/plays/artifact-contract-version.ts +6 -0
  19. package/dist/bundling-sources/shared_libs/plays/artifact-types.ts +4 -0
  20. package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +159 -12
  21. package/dist/bundling-sources/shared_libs/plays/contracts.ts +69 -1
  22. package/dist/bundling-sources/shared_libs/tool-execution-error.ts +428 -0
  23. package/dist/cli/index.js +501 -179
  24. package/dist/cli/index.mjs +501 -179
  25. package/dist/index.d.mts +39 -18
  26. package/dist/index.d.ts +39 -18
  27. package/dist/index.js +394 -59
  28. package/dist/index.mjs +391 -59
  29. package/dist/plays/bundle-play-file.d.mts +4 -2
  30. package/dist/plays/bundle-play-file.d.ts +4 -2
  31. package/dist/plays/bundle-play-file.mjs +116 -19
  32. package/dist/{compiler-manifest-BjopNIqx.d.mts → tool-execution-error-9mH4i-mJ.d.mts} +79 -1
  33. package/dist/{compiler-manifest-BjopNIqx.d.ts → tool-execution-error-9mH4i-mJ.d.ts} +79 -1
  34. package/package.json +1 -1
  35. package/dist/bundling-sources/shared_libs/play-runtime/completed-receipt-cache.ts +0 -166
package/dist/index.mjs CHANGED
@@ -11,19 +11,252 @@ import {
11
11
  import { homedir } from "os";
12
12
  import { dirname, isAbsolute, join, resolve } from "path";
13
13
 
14
- // src/errors.ts
15
- var DeeplineError = class extends Error {
14
+ // ../shared_libs/tool-execution-error.ts
15
+ var DEEPLINE_ERROR_BRAND = /* @__PURE__ */ Symbol.for("deepline.error.v1");
16
+ var TOOL_EXECUTION_ERROR_BRAND = /* @__PURE__ */ Symbol.for(
17
+ "deepline.tool-execution-error.v1"
18
+ );
19
+ var PROVIDER_TRANSIENT_ERROR_BRAND = /* @__PURE__ */ Symbol.for(
20
+ "deepline.provider-transient-error.v1"
21
+ );
22
+ var LEGACY_TOOL_EXECUTION_ERROR_SCHEMA_VERSION = 0;
23
+ var TOOL_EXECUTION_ERROR_SCHEMA_VERSION = 1;
24
+ var TOOL_EXECUTION_ERROR_SCHEMA_HEADER = "x-deepline-tool-error-schema";
25
+ var MAX_IDENTIFIER_LENGTH = 200;
26
+ var MAX_CODE_LENGTH = 160;
27
+ function nativeInstanceOf(constructor, value) {
28
+ return Reflect.apply(Function.prototype[Symbol.hasInstance], constructor, [
29
+ value
30
+ ]);
31
+ }
32
+ function hasBrand(value, brand) {
33
+ return typeof value === "object" && value !== null && value[brand] === true;
34
+ }
35
+ function applyBrand(value, brand) {
36
+ if (hasBrand(value, brand)) return;
37
+ Object.defineProperty(value, brand, {
38
+ configurable: false,
39
+ enumerable: false,
40
+ writable: false,
41
+ value: true
42
+ });
43
+ }
44
+ var DeeplineError = class _DeeplineError extends Error {
16
45
  constructor(message, statusCode, code, details) {
17
46
  super(message);
18
47
  this.statusCode = statusCode;
19
48
  this.code = code;
20
49
  this.details = details;
21
50
  this.name = "DeeplineError";
51
+ applyBrand(this, DEEPLINE_ERROR_BRAND);
22
52
  }
23
53
  statusCode;
24
54
  code;
25
55
  details;
56
+ static [Symbol.hasInstance](value) {
57
+ if (this !== _DeeplineError) return nativeInstanceOf(this, value);
58
+ return hasBrand(value, DEEPLINE_ERROR_BRAND);
59
+ }
26
60
  };
61
+ var ToolExecutionError = class _ToolExecutionError extends DeeplineError {
62
+ toolId;
63
+ provider;
64
+ operation;
65
+ origin;
66
+ category;
67
+ retryable;
68
+ requestId;
69
+ retryAfterMs;
70
+ networkKind;
71
+ networkScope;
72
+ constructor(message, options) {
73
+ super(
74
+ message,
75
+ options.statusCode ?? void 0,
76
+ options.code ?? void 0,
77
+ options.details
78
+ );
79
+ this.name = "ToolExecutionError";
80
+ this.toolId = options.toolId;
81
+ this.provider = options.provider;
82
+ this.operation = options.operation;
83
+ this.origin = options.origin;
84
+ this.category = options.category;
85
+ this.retryable = options.retryable;
86
+ this.requestId = options.requestId;
87
+ this.retryAfterMs = options.retryAfterMs;
88
+ this.networkKind = options.networkKind;
89
+ this.networkScope = options.networkScope;
90
+ applyBrand(this, TOOL_EXECUTION_ERROR_BRAND);
91
+ if (isProviderTransientFailure(options)) {
92
+ applyBrand(this, PROVIDER_TRANSIENT_ERROR_BRAND);
93
+ }
94
+ }
95
+ static [Symbol.hasInstance](value) {
96
+ if (this !== _ToolExecutionError) return nativeInstanceOf(this, value);
97
+ return hasBrand(value, TOOL_EXECUTION_ERROR_BRAND);
98
+ }
99
+ };
100
+ function brandAsToolExecutionError(value) {
101
+ applyBrand(value, TOOL_EXECUTION_ERROR_BRAND);
102
+ }
103
+ function isProviderTransientFailure(input) {
104
+ return input.origin === "provider" && (input.category === "rate_limit" || input.category === "network" || input.category === "upstream");
105
+ }
106
+ var ProviderTransientError = class _ProviderTransientError extends ToolExecutionError {
107
+ origin = "provider";
108
+ constructor(message, options) {
109
+ super(message, {
110
+ ...options,
111
+ origin: "provider",
112
+ category: options.category
113
+ });
114
+ this.name = "ProviderTransientError";
115
+ this.category = options.category;
116
+ applyBrand(this, PROVIDER_TRANSIENT_ERROR_BRAND);
117
+ }
118
+ static [Symbol.hasInstance](value) {
119
+ if (this !== _ProviderTransientError) return nativeInstanceOf(this, value);
120
+ return hasBrand(value, PROVIDER_TRANSIENT_ERROR_BRAND);
121
+ }
122
+ };
123
+ function brandAsProviderTransientError(value) {
124
+ applyBrand(value, PROVIDER_TRANSIENT_ERROR_BRAND);
125
+ }
126
+ function boundedString(value, maxLength = MAX_IDENTIFIER_LENGTH) {
127
+ if (typeof value !== "string") return null;
128
+ const normalized = value.trim();
129
+ return normalized ? normalized.slice(0, maxLength) : null;
130
+ }
131
+ function finiteNonNegativeInteger(value) {
132
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 && Number.isInteger(value) ? value : null;
133
+ }
134
+ function normalizeToolExecutionOrigin(value, input) {
135
+ const normalized = boundedString(value)?.toLowerCase();
136
+ if (normalized === "caller") return "caller";
137
+ if (normalized === "provider" || normalized === "provider_network") {
138
+ return "provider";
139
+ }
140
+ if (normalized === "upstream" && boundedString(input?.provider) && boundedString(input?.operation)) {
141
+ return "provider";
142
+ }
143
+ if (normalized === "deepline" || normalized === "deepline_billing" || normalized === "deepline_rate_limit" || normalized === "internal" || normalized === "server") {
144
+ return "deepline";
145
+ }
146
+ if (normalized === "provider_account") return "provider";
147
+ return "unknown";
148
+ }
149
+ function normalizeToolExecutionCategory(value) {
150
+ switch (boundedString(value)?.toLowerCase()) {
151
+ case "validation":
152
+ case "authorization":
153
+ case "rate_limit":
154
+ case "network":
155
+ case "upstream":
156
+ case "billing":
157
+ case "conflict":
158
+ case "internal":
159
+ return boundedString(value).toLowerCase();
160
+ case "authentication":
161
+ case "provider_auth":
162
+ case "provider_account":
163
+ return "authentication";
164
+ case "execution":
165
+ case "parse":
166
+ case "stub":
167
+ case "internal_native_search_performance":
168
+ return "internal";
169
+ default:
170
+ return "unknown";
171
+ }
172
+ }
173
+ function normalizeNetworkKind(value) {
174
+ switch (boundedString(value)?.toLowerCase()) {
175
+ case "timeout":
176
+ case "dns":
177
+ case "connect":
178
+ case "reset":
179
+ case "unavailable":
180
+ case "unknown":
181
+ return boundedString(value).toLowerCase();
182
+ default:
183
+ return null;
184
+ }
185
+ }
186
+ function normalizeNetworkScope(value) {
187
+ switch (boundedString(value)?.toLowerCase()) {
188
+ case "client_to_deepline":
189
+ case "runtime_to_deepline":
190
+ case "deepline_to_provider":
191
+ return boundedString(value).toLowerCase();
192
+ default:
193
+ return null;
194
+ }
195
+ }
196
+ function isRecord(value) {
197
+ return value !== null && typeof value === "object" && !Array.isArray(value);
198
+ }
199
+ function normalizeToolExecutionFailure(value) {
200
+ if (!isRecord(value) || value.schemaVersion !== TOOL_EXECUTION_ERROR_SCHEMA_VERSION) {
201
+ return null;
202
+ }
203
+ const toolId = boundedString(value.toolId);
204
+ if (!toolId) return null;
205
+ const provider = boundedString(value.provider);
206
+ const operation = boundedString(value.operation);
207
+ const origin = normalizeToolExecutionOrigin(value.origin, {
208
+ provider,
209
+ operation
210
+ });
211
+ const category = normalizeToolExecutionCategory(value.category);
212
+ const trustworthy = origin !== "unknown" && category !== "unknown" && typeof value.retryable === "boolean";
213
+ return {
214
+ schemaVersion: TOOL_EXECUTION_ERROR_SCHEMA_VERSION,
215
+ toolId,
216
+ provider,
217
+ operation,
218
+ code: boundedString(value.code, MAX_CODE_LENGTH),
219
+ origin,
220
+ category,
221
+ retryable: trustworthy ? value.retryable === true : false,
222
+ statusCode: finiteNonNegativeInteger(value.statusCode),
223
+ requestId: boundedString(value.requestId),
224
+ retryAfterMs: finiteNonNegativeInteger(value.retryAfterMs),
225
+ networkKind: normalizeNetworkKind(value.networkKind),
226
+ networkScope: normalizeNetworkScope(value.networkScope)
227
+ };
228
+ }
229
+ function serializeToolExecutionFailure(error) {
230
+ if (!(error instanceof ToolExecutionError)) return null;
231
+ return normalizeToolExecutionFailure({
232
+ schemaVersion: TOOL_EXECUTION_ERROR_SCHEMA_VERSION,
233
+ toolId: error.toolId,
234
+ provider: error.provider,
235
+ operation: error.operation,
236
+ code: error.code ?? null,
237
+ origin: error.origin,
238
+ category: error.category,
239
+ retryable: error.retryable,
240
+ statusCode: error.statusCode ?? null,
241
+ requestId: error.requestId,
242
+ retryAfterMs: error.retryAfterMs,
243
+ networkKind: error.networkKind,
244
+ networkScope: error.networkScope
245
+ });
246
+ }
247
+ function deserializeToolExecutionFailure(message, value, acceptedSchemaVersion) {
248
+ if (acceptedSchemaVersion === LEGACY_TOOL_EXECUTION_ERROR_SCHEMA_VERSION) {
249
+ return null;
250
+ }
251
+ const failure = normalizeToolExecutionFailure(value);
252
+ if (!failure) return null;
253
+ if (isProviderTransientFailure(failure)) {
254
+ return new ProviderTransientError(message, failure);
255
+ }
256
+ return new ToolExecutionError(message, failure);
257
+ }
258
+
259
+ // src/errors.ts
27
260
  var AuthError = class extends DeeplineError {
28
261
  constructor(message = "Authentication failed. Check your DEEPLINE_API_KEY.") {
29
262
  super(message, 401, "AUTH_ERROR");
@@ -43,6 +276,38 @@ var RateLimitError = class extends DeeplineError {
43
276
  this.retryAfterMs = retryAfterMs;
44
277
  }
45
278
  };
279
+ var ToolRateLimitError = class extends RateLimitError {
280
+ toolId;
281
+ provider;
282
+ operation;
283
+ code;
284
+ origin;
285
+ category;
286
+ retryable;
287
+ requestId;
288
+ networkKind;
289
+ networkScope;
290
+ constructor(message, options) {
291
+ super(options.retryAfterMs ?? 5e3, message);
292
+ this.name = "ToolRateLimitError";
293
+ this.statusCode = options.statusCode ?? 429;
294
+ this.code = options.code ?? void 0;
295
+ this.toolId = options.toolId;
296
+ this.provider = options.provider;
297
+ this.operation = options.operation;
298
+ this.origin = options.origin;
299
+ this.category = options.category;
300
+ this.retryable = options.retryable;
301
+ this.requestId = options.requestId;
302
+ this.networkKind = options.networkKind;
303
+ this.networkScope = options.networkScope;
304
+ this.details = options.details;
305
+ brandAsToolExecutionError(this);
306
+ if (isProviderTransientFailure(this)) {
307
+ brandAsProviderTransientError(this);
308
+ }
309
+ }
310
+ };
46
311
  var ConfigError = class extends DeeplineError {
47
312
  constructor(message) {
48
313
  super(message, void 0, "CONFIG_ERROR");
@@ -328,6 +593,9 @@ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
328
593
  import { homedir as homedir3 } from "os";
329
594
  import { join as join2 } from "path";
330
595
 
596
+ // ../shared_libs/plays/artifact-contract-version.ts
597
+ var CURRENT_PLAY_ARTIFACT_CONTRACT_VERSION = 2;
598
+
331
599
  // src/release.ts
332
600
  var SDK_RELEASE = {
333
601
  // 0.1.94 is claimed by PR #1527 — this watch-render fix ships as 0.1.95.
@@ -367,7 +635,7 @@ var SDK_RELEASE = {
367
635
  // 0.1.253 makes play-page browser opening opt-in and retires --no-open.
368
636
  // 0.1.254 removes the internal operations tree from the published SDK CLI.
369
637
  // Operators use the checkout-local deepline-admin binary instead.
370
- version: "0.1.301",
638
+ version: "0.1.302",
371
639
  contracts: {
372
640
  api: {
373
641
  name: "sdk-http-api",
@@ -383,8 +651,8 @@ var SDK_RELEASE = {
383
651
  },
384
652
  playArtifact: {
385
653
  name: "play-artifact-runtime",
386
- currentVersion: 2,
387
- supportedVersions: [1, 2]
654
+ currentVersion: CURRENT_PLAY_ARTIFACT_CONTRACT_VERSION,
655
+ supportedVersions: [1, CURRENT_PLAY_ARTIFACT_CONTRACT_VERSION]
388
656
  },
389
657
  release: {
390
658
  name: "production-sdk-release",
@@ -616,6 +884,9 @@ function providerLabelFromToolId(toolId) {
616
884
  const provider = normalized.split(/[_:./-]+/)[0];
617
885
  return provider || normalized || "provider";
618
886
  }
887
+ function isRecord2(value) {
888
+ return value !== null && typeof value === "object" && !Array.isArray(value);
889
+ }
619
890
  var HttpClient = class {
620
891
  constructor(config) {
621
892
  this.config = config;
@@ -751,6 +1022,29 @@ var HttpClient = class {
751
1022
  signal: controller.signal
752
1023
  });
753
1024
  clearTimeout(timeoutId);
1025
+ const body = await response.text();
1026
+ const parsed = parseResponseBody(body);
1027
+ const structuredToolError = options?.toolId && !response.ok ? deserializeToolExecutionFailure(
1028
+ apiErrorMessage(parsed, response.status),
1029
+ isRecord2(parsed) ? parsed.tool_error : null,
1030
+ TOOL_EXECUTION_ERROR_SCHEMA_VERSION
1031
+ ) : null;
1032
+ if (structuredToolError) {
1033
+ if (response.status === 429) {
1034
+ const retryAfter = parseRetryAfter(response);
1035
+ const failure = serializeToolExecutionFailure(structuredToolError);
1036
+ lastError = failure === null ? structuredToolError : new ToolRateLimitError(structuredToolError.message, {
1037
+ ...failure,
1038
+ retryAfterMs: failure.retryAfterMs ?? Math.max(0, retryAfter)
1039
+ });
1040
+ if (attempt < maxRetries) {
1041
+ retryAfterDelayMs = retryAfter;
1042
+ break;
1043
+ }
1044
+ throw lastError;
1045
+ }
1046
+ throw structuredToolError;
1047
+ }
754
1048
  if (response.status === 429) {
755
1049
  const retryAfter = parseRetryAfter(response);
756
1050
  lastError = new RateLimitError(retryAfter);
@@ -760,8 +1054,6 @@ var HttpClient = class {
760
1054
  }
761
1055
  throw lastError;
762
1056
  }
763
- const body = await response.text();
764
- const parsed = parseResponseBody(body);
765
1057
  if (response.status === 401 && !isProviderOriginatedHttpError(parsed) || response.status === 403 && !options?.forbiddenAsApiError) {
766
1058
  throw new AuthError();
767
1059
  }
@@ -826,6 +1118,29 @@ var HttpClient = class {
826
1118
  lastError,
827
1119
  describeRequestTarget(path)
828
1120
  );
1121
+ if (options?.toolId) {
1122
+ const code = mappedNetworkError.code;
1123
+ throw new ToolExecutionError(
1124
+ withCoworkNetworkHint(mappedNetworkError.message),
1125
+ {
1126
+ toolId: options.toolId,
1127
+ provider: providerLabelFromToolId(options.toolId),
1128
+ operation: options.toolId,
1129
+ code,
1130
+ origin: "deepline",
1131
+ category: "network",
1132
+ // A direct client timeout has ambiguous delivery. Fail closed unless
1133
+ // the server returns the authoritative action delivery contract.
1134
+ retryable: false,
1135
+ statusCode: null,
1136
+ requestId: null,
1137
+ retryAfterMs: null,
1138
+ networkKind: code === "NETWORK_TIMEOUT" ? "timeout" : code === "NETWORK_ABORTED" ? "unknown" : "unavailable",
1139
+ networkScope: "client_to_deepline",
1140
+ details: mappedNetworkError.details
1141
+ }
1142
+ );
1143
+ }
829
1144
  throw new DeeplineError(
830
1145
  withCoworkNetworkHint(mappedNetworkError.message),
831
1146
  void 0,
@@ -1267,11 +1582,11 @@ var RUNNER_POST_TERMINAL_DIAGNOSTIC_MAX_BYTES = 64 * 1024;
1267
1582
  var ledgerIngressRedactor = createSecretRedactionContext();
1268
1583
 
1269
1584
  // ../shared_libs/play-runtime/activity-observation.ts
1270
- function isRecord(value) {
1585
+ function isRecord3(value) {
1271
1586
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
1272
1587
  }
1273
1588
  function isPlayActivityObservation(value) {
1274
- if (!isRecord(value) || value.schemaVersion !== 1 || typeof value.activityId !== "string" || !value.activityId.trim() || typeof value.observedAt !== "number" || !Number.isFinite(value.observedAt) || !isRecord(value.target) || !isRecord(value.state)) {
1589
+ if (!isRecord3(value) || value.schemaVersion !== 1 || typeof value.activityId !== "string" || !value.activityId.trim() || typeof value.observedAt !== "number" || !Number.isFinite(value.observedAt) || !isRecord3(value.target) || !isRecord3(value.state)) {
1275
1590
  return false;
1276
1591
  }
1277
1592
  const targetKinds = /* @__PURE__ */ new Set([
@@ -1536,7 +1851,7 @@ function projectPlayRunActivity(input) {
1536
1851
 
1537
1852
  // ../shared_libs/play-runtime/run-ledger.ts
1538
1853
  var LOG_TAIL_LIMIT = 100;
1539
- function isRecord2(value) {
1854
+ function isRecord4(value) {
1540
1855
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
1541
1856
  }
1542
1857
  function finiteNumber(value) {
@@ -1632,21 +1947,21 @@ function createEmptyPlayRunLedgerSnapshot(input) {
1632
1947
  };
1633
1948
  }
1634
1949
  function normalizePlayRunLedgerSnapshot(value, fallback) {
1635
- if (!isRecord2(value)) {
1950
+ if (!isRecord4(value)) {
1636
1951
  return createEmptyPlayRunLedgerSnapshot(fallback);
1637
1952
  }
1638
1953
  const orderedStepIds = Array.isArray(value.orderedStepIds) ? value.orderedStepIds.filter(
1639
1954
  (entry) => typeof entry === "string" && Boolean(entry.trim())
1640
1955
  ) : [];
1641
- const rawSteps = isRecord2(value.stepsById) ? value.stepsById : {};
1956
+ const rawSteps = isRecord4(value.stepsById) ? value.stepsById : {};
1642
1957
  const stepsById = {};
1643
1958
  for (const [stepId, rawStep] of Object.entries(rawSteps)) {
1644
- if (!stepId.trim() || !isRecord2(rawStep)) continue;
1959
+ if (!stepId.trim() || !isRecord4(rawStep)) continue;
1645
1960
  const rawStatus = normalizeStepStatus(rawStep.status);
1646
1961
  if (!rawStatus) continue;
1647
1962
  const completedAt = finiteNumber(rawStep.completedAt);
1648
1963
  const status = rawStatus === "running" && completedAt !== null ? "completed" : rawStatus;
1649
- const rawProgress = isRecord2(rawStep.progress) ? rawStep.progress : null;
1964
+ const rawProgress = isRecord4(rawStep.progress) ? rawStep.progress : null;
1650
1965
  stepsById[stepId] = {
1651
1966
  stepId,
1652
1967
  label: optionalString(rawStep.label),
@@ -1662,10 +1977,10 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
1662
1977
  progress: rawProgress ? normalizeStepProgress(rawProgress) : null
1663
1978
  };
1664
1979
  }
1665
- const rawDatasets = isRecord2(value.datasetsById) ? value.datasetsById : {};
1980
+ const rawDatasets = isRecord4(value.datasetsById) ? value.datasetsById : {};
1666
1981
  const datasetsById = {};
1667
1982
  for (const [datasetId, rawDataset] of Object.entries(rawDatasets)) {
1668
- if (!datasetId.trim() || !isRecord2(rawDataset)) continue;
1983
+ if (!datasetId.trim() || !isRecord4(rawDataset)) continue;
1669
1984
  const phase = rawDataset.phase === "available" || rawDataset.phase === "failed" ? rawDataset.phase : "registered";
1670
1985
  datasetsById[datasetId] = {
1671
1986
  datasetId,
@@ -1679,7 +1994,7 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
1679
1994
  updatedAt: finiteNumber(rawDataset.updatedAt) ?? 0
1680
1995
  };
1681
1996
  }
1682
- const rawActivities = isRecord2(value.activitiesById) ? value.activitiesById : {};
1997
+ const rawActivities = isRecord4(value.activitiesById) ? value.activitiesById : {};
1683
1998
  const activitiesById = {};
1684
1999
  for (const [activityId, rawActivity] of Object.entries(rawActivities)) {
1685
2000
  if (activityId.trim() && isPlayActivityObservation(rawActivity) && rawActivity.activityId === activityId) {
@@ -1828,18 +2143,18 @@ function normalizePlayRunLiveStatus(value) {
1828
2143
  function isTerminalPlayRunLiveStatus(status) {
1829
2144
  return isTerminalPlayRunLifecycleStatus(status);
1830
2145
  }
1831
- function isRecord3(value) {
2146
+ function isRecord5(value) {
1832
2147
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
1833
2148
  }
1834
2149
  function finiteNumber2(value) {
1835
2150
  return typeof value === "number" && Number.isFinite(value) ? value : null;
1836
2151
  }
1837
2152
  function extractTerminalRunLogTail(result) {
1838
- if (!isRecord3(result) || !isRecord3(result._metadata)) {
2153
+ if (!isRecord5(result) || !isRecord5(result._metadata)) {
1839
2154
  return null;
1840
2155
  }
1841
2156
  const runLogTail = result._metadata.runLogTail;
1842
- if (!isRecord3(runLogTail) || !Array.isArray(runLogTail.tail)) {
2157
+ if (!isRecord5(runLogTail) || !Array.isArray(runLogTail.tail)) {
1843
2158
  return null;
1844
2159
  }
1845
2160
  const logTail = runLogTail.tail.filter(
@@ -2733,7 +3048,7 @@ function resolveToolExecuteTimeoutMs(toolId, input) {
2733
3048
  }
2734
3049
  var RUNS_FAILED_LOG_LIMIT = 20;
2735
3050
  var RUN_LOGS_PAGE_LIMIT = 1e3;
2736
- function isRecord4(value) {
3051
+ function isRecord6(value) {
2737
3052
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
2738
3053
  }
2739
3054
  function isPrebuiltPlayDescription(play) {
@@ -2896,7 +3211,7 @@ function updatePlayLiveStatusState(state, event) {
2896
3211
  }
2897
3212
  const runId = typeof payload.runId === "string" && payload.runId ? payload.runId : isPlayRunPackage(payload) ? payload.run.id : state.runId;
2898
3213
  const status = normalizeLiveStatus(payload.status) ?? (isPlayRunPackage(payload) ? normalizeLiveStatus(payload.run.status) : null) ?? state.status;
2899
- const progressPayload = isRecord4(payload.progress) ? payload.progress : {};
3214
+ const progressPayload = isRecord6(payload.progress) ? payload.progress : {};
2900
3215
  if (event.type === "play.run.final_status" && state.logs.length === 0 && state.lastLogSeq === 0) {
2901
3216
  const payloadLogs = readStringArray(payload.logs);
2902
3217
  const progressLogs = readStringArray(progressPayload.logs);
@@ -3030,9 +3345,9 @@ var DeeplineClient = class {
3030
3345
  return fields.length > 0 ? { fields } : schema;
3031
3346
  }
3032
3347
  schemaMetadata(schema, key) {
3033
- if (!isRecord4(schema)) return null;
3348
+ if (!isRecord6(schema)) return null;
3034
3349
  const value = schema[key];
3035
- return isRecord4(value) ? value : null;
3350
+ return isRecord6(value) ? value : null;
3036
3351
  }
3037
3352
  playRunCommand(play, options) {
3038
3353
  const target = play.reference || play.name;
@@ -3081,7 +3396,7 @@ var DeeplineClient = class {
3081
3396
  aliases,
3082
3397
  inputSchema: options?.compact ? this.compactSchema(play.inputSchema) : play.inputSchema ?? null,
3083
3398
  outputSchema: options?.compact ? this.compactSchema(play.outputSchema) : play.outputSchema ?? null,
3084
- staticPipeline: isRecord4(play.staticPipeline) ? play.staticPipeline : isRecord4(play.currentRevision?.staticPipeline) ? play.currentRevision.staticPipeline : isRecord4(play.liveRevision?.staticPipeline) ? play.liveRevision.staticPipeline : null,
3399
+ staticPipeline: isRecord6(play.staticPipeline) ? play.staticPipeline : isRecord6(play.currentRevision?.staticPipeline) ? play.currentRevision.staticPipeline : isRecord6(play.liveRevision?.staticPipeline) ? play.liveRevision.staticPipeline : null,
3085
3400
  ...csvInput ? { csvInput } : {},
3086
3401
  ...rowOutputSchema ? { rowOutputSchema } : {},
3087
3402
  runCommand,
@@ -3252,6 +3567,9 @@ var DeeplineClient = class {
3252
3567
  async executeTool(toolId, input, options) {
3253
3568
  const headers = {
3254
3569
  [EXECUTE_RESPONSE_CONTRACT_HEADER]: V2_EXECUTE_RESPONSE_CONTRACT,
3570
+ [TOOL_EXECUTION_ERROR_SCHEMA_HEADER]: String(
3571
+ TOOL_EXECUTION_ERROR_SCHEMA_VERSION
3572
+ ),
3255
3573
  ...options?.includeToolMetadata ? { [INCLUDE_TOOL_METADATA_HEADER]: "true" } : {},
3256
3574
  [EXECUTE_RESPONSE_INTENT_HEADER]: options?.responseIntent ?? "raw"
3257
3575
  };
@@ -3266,7 +3584,8 @@ var DeeplineClient = class {
3266
3584
  forbiddenAsApiError: true,
3267
3585
  timeout: options?.timeout ?? resolveToolExecuteTimeoutMs(toolId, input),
3268
3586
  maxRetries: options?.maxRetries ?? 0,
3269
- exactUrlOnly: true
3587
+ exactUrlOnly: true,
3588
+ toolId
3270
3589
  }
3271
3590
  );
3272
3591
  }
@@ -5773,7 +6092,7 @@ var TARGET_FALLBACK_KEYS = {
5773
6092
  status: [/^email_status$/i, /^status$/i],
5774
6093
  email_status: [/^email_status$/i, /^status$/i]
5775
6094
  };
5776
- function isRecord5(value) {
6095
+ function isRecord7(value) {
5777
6096
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5778
6097
  }
5779
6098
  function toV2RawToolOutputPath(path) {
@@ -5833,7 +6152,7 @@ function valuesAtSegments(current, segments, path = []) {
5833
6152
  if (!Array.isArray(current)) return [];
5834
6153
  return valuesAtSegments(current[segment], rest, [...path, segment]);
5835
6154
  }
5836
- if (!isRecord5(current)) return [];
6155
+ if (!isRecord7(current)) return [];
5837
6156
  const directMatches = valuesAtSegments(current[segment], rest, [
5838
6157
  ...path,
5839
6158
  segment
@@ -5863,7 +6182,7 @@ function getValuesAtPath(root, path) {
5863
6182
  return valuesAtSegments(root, parsePath(path)).map((entry) => entry.value);
5864
6183
  }
5865
6184
  function toResultEnvelope(value) {
5866
- if (isRecord5(value) && "data" in value) {
6185
+ if (isRecord7(value) && "data" in value) {
5867
6186
  const envelope = { data: value.data };
5868
6187
  if ("meta" in value) envelope.meta = value.meta;
5869
6188
  return envelope;
@@ -5916,7 +6235,7 @@ function getAtPath(root, path) {
5916
6235
  current = current[segment];
5917
6236
  continue;
5918
6237
  }
5919
- if (!isRecord5(current)) return void 0;
6238
+ if (!isRecord7(current)) return void 0;
5920
6239
  current = current[segment];
5921
6240
  }
5922
6241
  return current;
@@ -5933,7 +6252,7 @@ function normalizeString(value) {
5933
6252
  }
5934
6253
  function normalizeRows(value) {
5935
6254
  if (!Array.isArray(value)) return null;
5936
- return value.map((entry) => isRecord5(entry) ? entry : { value: entry });
6255
+ return value.map((entry) => isRecord7(entry) ? entry : { value: entry });
5937
6256
  }
5938
6257
  function findFirstTargetByPath(result, paths) {
5939
6258
  for (const path of paths ?? []) {
@@ -5992,7 +6311,7 @@ function findFirstTargetByKey(result, target, depth = 0, path = []) {
5992
6311
  }
5993
6312
  return null;
5994
6313
  }
5995
- if (!isRecord5(result)) return null;
6314
+ if (!isRecord7(result)) return null;
5996
6315
  const patterns = TARGET_FALLBACK_KEYS[target] ?? [
5997
6316
  new RegExp(`^${target}$`, "i")
5998
6317
  ];
@@ -6052,7 +6371,7 @@ function normalizeJobChangeStatus(value) {
6052
6371
  function firstExperienceDate(value) {
6053
6372
  if (!Array.isArray(value)) return null;
6054
6373
  for (const entry of value) {
6055
- if (!isRecord5(entry)) continue;
6374
+ if (!isRecord7(entry)) continue;
6056
6375
  const date = normalizeString(
6057
6376
  entry.start_date ?? entry.started_at ?? entry.startDate
6058
6377
  );
@@ -6061,10 +6380,10 @@ function firstExperienceDate(value) {
6061
6380
  return null;
6062
6381
  }
6063
6382
  function normalizeJobChange(value) {
6064
- const record = isRecord5(value) ? value : {};
6065
- const nested = isRecord5(record.job_change) ? record.job_change : record;
6066
- const output = isRecord5(nested.output) ? nested.output : nested;
6067
- const person = isRecord5(output.person) ? output.person : {};
6383
+ const record = isRecord7(value) ? value : {};
6384
+ const nested = isRecord7(record.job_change) ? record.job_change : record;
6385
+ const output = isRecord7(nested.output) ? nested.output : nested;
6386
+ const person = isRecord7(output.person) ? output.person : {};
6068
6387
  const status = normalizeJobChangeStatus(
6069
6388
  output.status ?? output.job_change_status ?? output.job_changed ?? output.changed
6070
6389
  );
@@ -6429,7 +6748,7 @@ function attachToolResultListDataset(result, input) {
6429
6748
  root = replaceAtPath(root, candidate, serialized.preview);
6430
6749
  break;
6431
6750
  }
6432
- if (isRecord5(root) && isRecord5(root.toolResponse) && Object.prototype.hasOwnProperty.call(root.toolResponse, "raw")) {
6751
+ if (isRecord7(root) && isRecord7(root.toolResponse) && Object.prototype.hasOwnProperty.call(root.toolResponse, "raw")) {
6433
6752
  result.toolResponse.raw = root.toolResponse.raw;
6434
6753
  result.toolOutput.raw = root.toolResponse.raw;
6435
6754
  }
@@ -6447,7 +6766,7 @@ function replaceAtPath(root, path, replacement) {
6447
6766
  copy[segment] = replace(copy[segment], index + 1);
6448
6767
  return copy;
6449
6768
  }
6450
- if (!isRecord5(current)) return current;
6769
+ if (!isRecord7(current)) return current;
6451
6770
  return {
6452
6771
  ...current,
6453
6772
  [segment]: replace(current[segment], index + 1)
@@ -6768,11 +7087,11 @@ var Deepline = class {
6768
7087
  return new DeeplineContext(options);
6769
7088
  }
6770
7089
  };
6771
- function isRecord6(value) {
7090
+ function isRecord8(value) {
6772
7091
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6773
7092
  }
6774
7093
  function stringArrayRecord(value) {
6775
- if (!isRecord6(value)) return {};
7094
+ if (!isRecord8(value)) return {};
6776
7095
  return Object.fromEntries(
6777
7096
  Object.entries(value).map(([key, paths]) => [
6778
7097
  key,
@@ -6784,7 +7103,7 @@ function stringArray(value) {
6784
7103
  return Array.isArray(value) ? value.map(String) : [];
6785
7104
  }
6786
7105
  function emailStatusExtractorConfig(value) {
6787
- if (!isRecord6(value)) return void 0;
7106
+ if (!isRecord8(value)) return void 0;
6788
7107
  const readPaths = (key) => {
6789
7108
  const paths = stringArray(value[key]).map((path) => path.trim()).filter(Boolean);
6790
7109
  return paths.length > 0 ? paths : void 0;
@@ -6811,7 +7130,7 @@ function emailStatusExtractorConfig(value) {
6811
7130
  const paths = readPaths(key);
6812
7131
  if (paths) config[key] = paths;
6813
7132
  }
6814
- if (isRecord6(value.statusMap)) {
7133
+ if (isRecord8(value.statusMap)) {
6815
7134
  config.statusMap = value.statusMap;
6816
7135
  }
6817
7136
  if (Array.isArray(value.rules)) {
@@ -6820,10 +7139,10 @@ function emailStatusExtractorConfig(value) {
6820
7139
  return config;
6821
7140
  }
6822
7141
  function extractorDescriptorRecord(value) {
6823
- if (!isRecord6(value)) return {};
7142
+ if (!isRecord8(value)) return {};
6824
7143
  return Object.fromEntries(
6825
7144
  Object.entries(value).flatMap(([key, descriptor]) => {
6826
- if (!isRecord6(descriptor)) return [];
7145
+ if (!isRecord8(descriptor)) return [];
6827
7146
  const paths = stringArray(descriptor.paths).map((path) => path.trim()).filter(Boolean);
6828
7147
  if (paths.length === 0) return [];
6829
7148
  const transforms = stringArray(descriptor.transforms).map((transform) => transform.trim()).filter(Boolean);
@@ -6845,16 +7164,16 @@ function extractorDescriptorRecord(value) {
6845
7164
  }
6846
7165
  function rowsFromUnknown(value) {
6847
7166
  if (!Array.isArray(value)) return [];
6848
- return value.map((row) => isRecord6(row) ? row : { value: row });
7167
+ return value.map((row) => isRecord8(row) ? row : { value: row });
6849
7168
  }
6850
- function finiteNonNegativeInteger(value) {
7169
+ function finiteNonNegativeInteger2(value) {
6851
7170
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
6852
7171
  return null;
6853
7172
  }
6854
7173
  return Math.floor(value);
6855
7174
  }
6856
7175
  function finitePositiveInteger(value) {
6857
- const integer = finiteNonNegativeInteger(value);
7176
+ const integer = finiteNonNegativeInteger2(value);
6858
7177
  return integer !== null && integer > 0 ? integer : null;
6859
7178
  }
6860
7179
  function stableHash(value) {
@@ -6867,9 +7186,9 @@ function stableHash(value) {
6867
7186
  }
6868
7187
  function attachSdkQueryResultDatasetResult(toolId, result, options) {
6869
7188
  if (!options || !isQueryResultDatasetTool(toolId)) return result;
6870
- const raw = isRecord6(result.toolResponse.raw) ? result.toolResponse.raw : null;
6871
- const dataset = isRecord6(raw?.dataset) ? raw.dataset : null;
6872
- const totalRows = finiteNonNegativeInteger(dataset?.total_rows);
7189
+ const raw = isRecord8(result.toolResponse.raw) ? result.toolResponse.raw : null;
7190
+ const dataset = isRecord8(raw?.dataset) ? raw.dataset : null;
7191
+ const totalRows = finiteNonNegativeInteger2(dataset?.total_rows);
6873
7192
  const sql = typeof options.input.sql === "string" ? options.input.sql : typeof options.input.query === "string" ? options.input.query : typeof raw?.sql === "string" ? raw.sql : null;
6874
7193
  if (!dataset || totalRows === null || !sql) {
6875
7194
  return result;
@@ -6898,7 +7217,7 @@ function attachSdkQueryResultDatasetResult(toolId, result, options) {
6898
7217
  } : {}
6899
7218
  }
6900
7219
  });
6901
- const pageRaw = isRecord6(response.toolResponse?.raw) ? response.toolResponse.raw : null;
7220
+ const pageRaw = isRecord8(response.toolResponse?.raw) ? response.toolResponse.raw : null;
6902
7221
  return rowsFromUnknown(pageRaw?.rows);
6903
7222
  };
6904
7223
  const collectRows = async (limit) => {
@@ -6951,8 +7270,8 @@ function attachSdkQueryResultDatasetResult(toolId, result, options) {
6951
7270
  function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
6952
7271
  const raw = response.toolResponse?.raw ?? null;
6953
7272
  const meta = response.toolResponse?.meta;
6954
- const metadata = isRecord6(response._metadata) ? response._metadata.tool : null;
6955
- const toolMetadata = isRecord6(metadata) ? metadata : {};
7273
+ const metadata = isRecord8(response._metadata) ? response._metadata.tool : null;
7274
+ const toolMetadata = isRecord8(metadata) ? metadata : {};
6956
7275
  return attachSdkQueryResultDatasetResult(
6957
7276
  fallbackToolId,
6958
7277
  createToolExecuteResult({
@@ -6960,7 +7279,7 @@ function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
6960
7279
  jobId: typeof response.job_id === "string" ? response.job_id : void 0,
6961
7280
  result: {
6962
7281
  data: raw,
6963
- ...isRecord6(meta) ? { meta } : {}
7282
+ ...isRecord8(meta) ? { meta } : {}
6964
7283
  },
6965
7284
  metadata: {
6966
7285
  toolId: typeof toolMetadata.toolId === "string" ? toolMetadata.toolId : fallbackToolId,
@@ -6976,7 +7295,7 @@ function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
6976
7295
  cached: false,
6977
7296
  source: "live"
6978
7297
  },
6979
- meta: isRecord6(response.meta) ? response.meta : void 0
7298
+ meta: isRecord8(response.meta) ? response.meta : void 0
6980
7299
  }),
6981
7300
  options
6982
7301
  );
@@ -6996,14 +7315,16 @@ function definePlay(nameOrConfig, maybeFn, maybeBindings) {
6996
7315
  bindings: maybeBindings,
6997
7316
  description: maybeBindings?.description,
6998
7317
  inputSchema: void 0,
6999
- billing: maybeBindings?.billing
7318
+ billing: maybeBindings?.billing,
7319
+ compatibility: maybeBindings?.compatibility
7000
7320
  } : {
7001
7321
  name: nameOrConfig.id,
7002
7322
  fn: nameOrConfig.run,
7003
7323
  bindings: nameOrConfig.bindings,
7004
7324
  description: nameOrConfig.description,
7005
7325
  inputSchema: nameOrConfig.input.schema,
7006
- billing: nameOrConfig.billing
7326
+ billing: nameOrConfig.billing,
7327
+ compatibility: nameOrConfig.compatibility ?? nameOrConfig.bindings?.compatibility
7007
7328
  };
7008
7329
  const name = config.name;
7009
7330
  const fn = config.fn;
@@ -7011,6 +7332,7 @@ function definePlay(nameOrConfig, maybeFn, maybeBindings) {
7011
7332
  const description = config.description?.trim();
7012
7333
  const billing = config.billing;
7013
7334
  const inputSchema = config.inputSchema;
7335
+ const compatibility = config.compatibility;
7014
7336
  if (typeof fn !== "function") {
7015
7337
  throw new Error("definePlay(...) requires an async run function.");
7016
7338
  }
@@ -7035,7 +7357,8 @@ function definePlay(nameOrConfig, maybeFn, maybeBindings) {
7035
7357
  ...description ? { description } : {},
7036
7358
  ...bindings ? { bindings } : {},
7037
7359
  ...inputSchema ? { inputSchema } : {},
7038
- ...billing ? { billing } : {}
7360
+ ...billing ? { billing } : {},
7361
+ ...compatibility ? { compatibility } : {}
7039
7362
  };
7040
7363
  const play = fn;
7041
7364
  Object.defineProperty(play, PLAY_METADATA_SYMBOL, {
@@ -7056,6 +7379,12 @@ function definePlay(nameOrConfig, maybeFn, maybeBindings) {
7056
7379
  configurable: false,
7057
7380
  writable: false
7058
7381
  });
7382
+ Object.defineProperty(play, "compatibility", {
7383
+ value: compatibility,
7384
+ enumerable: true,
7385
+ configurable: false,
7386
+ writable: false
7387
+ });
7059
7388
  const handle = createNamedPlayHandle(
7060
7389
  () => new DeeplineClient(),
7061
7390
  name
@@ -7307,10 +7636,13 @@ export {
7307
7636
  PLAY_BOOTSTRAP_STAGE_KINDS,
7308
7637
  PLAY_BOOTSTRAP_TEMPLATES,
7309
7638
  PROD_URL,
7639
+ ProviderTransientError,
7310
7640
  RateLimitError,
7311
7641
  RunObserveTransportUnavailableError,
7312
7642
  SDK_API_CONTRACT,
7313
7643
  SDK_VERSION,
7644
+ ToolExecutionError,
7645
+ ToolRateLimitError,
7314
7646
  defineInput,
7315
7647
  defineMonitor,
7316
7648
  definePlay,