deepline 0.1.301 → 0.1.303
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.
- package/dist/bundling-sources/sdk/src/client.ts +8 -0
- package/dist/bundling-sources/sdk/src/errors.ts +96 -36
- package/dist/bundling-sources/sdk/src/http.ts +82 -5
- package/dist/bundling-sources/sdk/src/index.ts +12 -0
- package/dist/bundling-sources/sdk/src/play.ts +29 -1
- package/dist/bundling-sources/sdk/src/release.ts +5 -3
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +120 -14
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +10 -0
- package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +59 -11
- package/dist/bundling-sources/shared_libs/play-runtime/execution-ledger-store.ts +3 -3
- package/dist/bundling-sources/shared_libs/play-runtime/execution-plan.ts +0 -15
- package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +3 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-actions.ts +3 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +136 -36
- package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +17 -12
- package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +210 -5
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result-paths.ts +15 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result-types.ts +4 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +33 -24
- package/dist/bundling-sources/shared_libs/play-runtime/work-receipts.ts +4 -0
- package/dist/bundling-sources/shared_libs/plays/artifact-contract-version.ts +6 -0
- package/dist/bundling-sources/shared_libs/plays/artifact-types.ts +4 -0
- package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +159 -12
- package/dist/bundling-sources/shared_libs/plays/contracts.ts +69 -1
- package/dist/bundling-sources/shared_libs/tool-execution-error.ts +557 -0
- package/dist/cli/index.js +556 -183
- package/dist/cli/index.mjs +556 -183
- package/dist/index.d.mts +69 -40
- package/dist/index.d.ts +69 -40
- package/dist/index.js +480 -80
- package/dist/index.mjs +477 -80
- package/dist/plays/bundle-play-file.d.mts +4 -2
- package/dist/plays/bundle-play-file.d.ts +4 -2
- package/dist/plays/bundle-play-file.mjs +116 -19
- package/dist/tool-execution-error-YDz7UMl-.d.mts +440 -0
- package/dist/tool-execution-error-YDz7UMl-.d.ts +440 -0
- package/package.json +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/completed-receipt-cache.ts +0 -166
- package/dist/compiler-manifest-BjopNIqx.d.mts +0 -240
- package/dist/compiler-manifest-BjopNIqx.d.ts +0 -240
package/dist/index.js
CHANGED
|
@@ -52,10 +52,13 @@ __export(src_exports, {
|
|
|
52
52
|
PLAY_BOOTSTRAP_STAGE_KINDS: () => PLAY_BOOTSTRAP_STAGE_KINDS,
|
|
53
53
|
PLAY_BOOTSTRAP_TEMPLATES: () => PLAY_BOOTSTRAP_TEMPLATES,
|
|
54
54
|
PROD_URL: () => PROD_URL,
|
|
55
|
+
ProviderTransientError: () => ProviderTransientError,
|
|
55
56
|
RateLimitError: () => RateLimitError,
|
|
56
57
|
RunObserveTransportUnavailableError: () => RunObserveTransportUnavailableError,
|
|
57
58
|
SDK_API_CONTRACT: () => SDK_API_CONTRACT,
|
|
58
59
|
SDK_VERSION: () => SDK_VERSION,
|
|
60
|
+
ToolExecutionError: () => ToolExecutionError,
|
|
61
|
+
ToolRateLimitError: () => ToolRateLimitError,
|
|
59
62
|
defineInput: () => defineInput,
|
|
60
63
|
defineMonitor: () => defineMonitor,
|
|
61
64
|
definePlay: () => definePlay,
|
|
@@ -82,20 +85,291 @@ var import_node_fs = require("fs");
|
|
|
82
85
|
var import_node_os = require("os");
|
|
83
86
|
var import_node_path = require("path");
|
|
84
87
|
|
|
85
|
-
//
|
|
86
|
-
var
|
|
88
|
+
// ../shared_libs/tool-execution-error.ts
|
|
89
|
+
var DEEPLINE_ERROR_BRAND = /* @__PURE__ */ Symbol.for("deepline.error.v1");
|
|
90
|
+
var TOOL_EXECUTION_ERROR_BRAND = /* @__PURE__ */ Symbol.for(
|
|
91
|
+
"deepline.tool-execution-error.v1"
|
|
92
|
+
);
|
|
93
|
+
var PROVIDER_TRANSIENT_ERROR_BRAND = /* @__PURE__ */ Symbol.for(
|
|
94
|
+
"deepline.provider-transient-error.v1"
|
|
95
|
+
);
|
|
96
|
+
var LEGACY_TOOL_EXECUTION_ERROR_SCHEMA_VERSION = 0;
|
|
97
|
+
var TOOL_EXECUTION_ERROR_SCHEMA_VERSION = 1;
|
|
98
|
+
var TOOL_EXECUTION_ERROR_SCHEMA_HEADER = "x-deepline-tool-error-schema";
|
|
99
|
+
var MAX_IDENTIFIER_LENGTH = 200;
|
|
100
|
+
var MAX_CODE_LENGTH = 160;
|
|
101
|
+
function nativeInstanceOf(constructor, value) {
|
|
102
|
+
return Reflect.apply(Function.prototype[Symbol.hasInstance], constructor, [
|
|
103
|
+
value
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
function hasBrand(value, brand) {
|
|
107
|
+
return typeof value === "object" && value !== null && value[brand] === true;
|
|
108
|
+
}
|
|
109
|
+
function applyBrand(value, brand) {
|
|
110
|
+
if (hasBrand(value, brand)) return;
|
|
111
|
+
Object.defineProperty(value, brand, {
|
|
112
|
+
configurable: false,
|
|
113
|
+
enumerable: false,
|
|
114
|
+
writable: false,
|
|
115
|
+
value: true
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
var DeeplineError = class _DeeplineError extends Error {
|
|
119
|
+
/** HTTP status when the failure crossed an HTTP boundary. */
|
|
120
|
+
statusCode;
|
|
121
|
+
/** Stable machine-readable error code when one exists. */
|
|
122
|
+
code;
|
|
123
|
+
/** Local diagnostic context; not a portable error contract. */
|
|
124
|
+
details;
|
|
125
|
+
/**
|
|
126
|
+
* Construct a Deepline error.
|
|
127
|
+
*
|
|
128
|
+
* SDK and runtime code construct these errors. Application and Play code
|
|
129
|
+
* normally catches the public subclasses instead.
|
|
130
|
+
*
|
|
131
|
+
* @param message Human-readable failure summary.
|
|
132
|
+
* @param statusCode HTTP status when one exists.
|
|
133
|
+
* @param code Stable machine-readable code when one exists.
|
|
134
|
+
* @param details Local diagnostic context; never a portable error contract.
|
|
135
|
+
*/
|
|
87
136
|
constructor(message, statusCode, code, details) {
|
|
88
137
|
super(message);
|
|
138
|
+
this.name = "DeeplineError";
|
|
89
139
|
this.statusCode = statusCode;
|
|
90
140
|
this.code = code;
|
|
91
141
|
this.details = details;
|
|
92
|
-
this
|
|
142
|
+
applyBrand(this, DEEPLINE_ERROR_BRAND);
|
|
143
|
+
}
|
|
144
|
+
static [Symbol.hasInstance](value) {
|
|
145
|
+
if (this !== _DeeplineError) return nativeInstanceOf(this, value);
|
|
146
|
+
return hasBrand(value, DEEPLINE_ERROR_BRAND);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
var ToolExecutionError = class _ToolExecutionError extends DeeplineError {
|
|
150
|
+
/** Public tool id passed to `tools.execute`. */
|
|
151
|
+
toolId;
|
|
152
|
+
/** Provider responsible for the operation, or `null` when unattributed. */
|
|
153
|
+
provider;
|
|
154
|
+
/** Provider operation name, or `null` when unavailable. */
|
|
155
|
+
operation;
|
|
156
|
+
/** Boundary responsible for the failure. */
|
|
157
|
+
origin;
|
|
158
|
+
/** Stable reason family for policy and diagnostics. */
|
|
159
|
+
category;
|
|
160
|
+
/**
|
|
161
|
+
* Whether repeating the same semantic call is delivery-safe.
|
|
162
|
+
*
|
|
163
|
+
* This does not mean the error may be ignored. Waterfall fallthrough is
|
|
164
|
+
* represented by `ProviderTransientError`.
|
|
165
|
+
*/
|
|
166
|
+
retryable;
|
|
167
|
+
/** Provider or Deepline request id, or `null` when unavailable. */
|
|
168
|
+
requestId;
|
|
169
|
+
/** Suggested same-call retry delay in milliseconds, or `null`. */
|
|
170
|
+
retryAfterMs;
|
|
171
|
+
/** Network failure kind, or `null` for non-network failures. */
|
|
172
|
+
networkKind;
|
|
173
|
+
/** Network boundary that failed, or `null` for non-network failures. */
|
|
174
|
+
networkScope;
|
|
175
|
+
/**
|
|
176
|
+
* Construct a structured tool error.
|
|
177
|
+
*
|
|
178
|
+
* Deepline constructs this from the versioned `tool_error` payload.
|
|
179
|
+
* Application and Play code should catch it rather than create it.
|
|
180
|
+
*/
|
|
181
|
+
constructor(message, options) {
|
|
182
|
+
super(
|
|
183
|
+
message,
|
|
184
|
+
options.statusCode ?? void 0,
|
|
185
|
+
options.code ?? void 0,
|
|
186
|
+
options.details
|
|
187
|
+
);
|
|
188
|
+
this.name = "ToolExecutionError";
|
|
189
|
+
this.toolId = options.toolId;
|
|
190
|
+
this.provider = options.provider;
|
|
191
|
+
this.operation = options.operation;
|
|
192
|
+
this.origin = options.origin;
|
|
193
|
+
this.category = options.category;
|
|
194
|
+
this.retryable = options.retryable;
|
|
195
|
+
this.requestId = options.requestId;
|
|
196
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
197
|
+
this.networkKind = options.networkKind;
|
|
198
|
+
this.networkScope = options.networkScope;
|
|
199
|
+
applyBrand(this, TOOL_EXECUTION_ERROR_BRAND);
|
|
200
|
+
if (isProviderTransientFailure(options)) {
|
|
201
|
+
applyBrand(this, PROVIDER_TRANSIENT_ERROR_BRAND);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
static [Symbol.hasInstance](value) {
|
|
205
|
+
if (this !== _ToolExecutionError) return nativeInstanceOf(this, value);
|
|
206
|
+
return hasBrand(value, TOOL_EXECUTION_ERROR_BRAND);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
function brandAsToolExecutionError(value) {
|
|
210
|
+
applyBrand(value, TOOL_EXECUTION_ERROR_BRAND);
|
|
211
|
+
}
|
|
212
|
+
function isProviderTransientFailure(input) {
|
|
213
|
+
return input.origin === "provider" && (input.category === "rate_limit" || input.category === "network" || input.category === "upstream");
|
|
214
|
+
}
|
|
215
|
+
var ProviderTransientError = class _ProviderTransientError extends ToolExecutionError {
|
|
216
|
+
/** Provider attribution is guaranteed for this subtype. */
|
|
217
|
+
origin = "provider";
|
|
218
|
+
/** Constructed by Deepline when a provider-owned transient failure arrives. */
|
|
219
|
+
constructor(message, options) {
|
|
220
|
+
super(message, {
|
|
221
|
+
...options,
|
|
222
|
+
origin: "provider",
|
|
223
|
+
category: options.category
|
|
224
|
+
});
|
|
225
|
+
this.name = "ProviderTransientError";
|
|
226
|
+
this.category = options.category;
|
|
227
|
+
applyBrand(this, PROVIDER_TRANSIENT_ERROR_BRAND);
|
|
228
|
+
}
|
|
229
|
+
static [Symbol.hasInstance](value) {
|
|
230
|
+
if (this !== _ProviderTransientError) return nativeInstanceOf(this, value);
|
|
231
|
+
return hasBrand(value, PROVIDER_TRANSIENT_ERROR_BRAND);
|
|
93
232
|
}
|
|
94
|
-
statusCode;
|
|
95
|
-
code;
|
|
96
|
-
details;
|
|
97
233
|
};
|
|
234
|
+
function brandAsProviderTransientError(value) {
|
|
235
|
+
applyBrand(value, PROVIDER_TRANSIENT_ERROR_BRAND);
|
|
236
|
+
}
|
|
237
|
+
function boundedString(value, maxLength = MAX_IDENTIFIER_LENGTH) {
|
|
238
|
+
if (typeof value !== "string") return null;
|
|
239
|
+
const normalized = value.trim();
|
|
240
|
+
return normalized ? normalized.slice(0, maxLength) : null;
|
|
241
|
+
}
|
|
242
|
+
function finiteNonNegativeInteger(value) {
|
|
243
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && Number.isInteger(value) ? value : null;
|
|
244
|
+
}
|
|
245
|
+
function normalizeToolExecutionOrigin(value, input) {
|
|
246
|
+
const normalized = boundedString(value)?.toLowerCase();
|
|
247
|
+
if (normalized === "caller") return "caller";
|
|
248
|
+
if (normalized === "provider" || normalized === "provider_network") {
|
|
249
|
+
return "provider";
|
|
250
|
+
}
|
|
251
|
+
if (normalized === "upstream" && boundedString(input?.provider) && boundedString(input?.operation)) {
|
|
252
|
+
return "provider";
|
|
253
|
+
}
|
|
254
|
+
if (normalized === "deepline" || normalized === "deepline_billing" || normalized === "deepline_rate_limit" || normalized === "internal" || normalized === "server") {
|
|
255
|
+
return "deepline";
|
|
256
|
+
}
|
|
257
|
+
if (normalized === "provider_account") return "provider";
|
|
258
|
+
return "unknown";
|
|
259
|
+
}
|
|
260
|
+
function normalizeToolExecutionCategory(value) {
|
|
261
|
+
switch (boundedString(value)?.toLowerCase()) {
|
|
262
|
+
case "validation":
|
|
263
|
+
case "authorization":
|
|
264
|
+
case "rate_limit":
|
|
265
|
+
case "network":
|
|
266
|
+
case "upstream":
|
|
267
|
+
case "billing":
|
|
268
|
+
case "conflict":
|
|
269
|
+
case "internal":
|
|
270
|
+
return boundedString(value).toLowerCase();
|
|
271
|
+
case "authentication":
|
|
272
|
+
case "provider_auth":
|
|
273
|
+
case "provider_account":
|
|
274
|
+
return "authentication";
|
|
275
|
+
case "execution":
|
|
276
|
+
case "parse":
|
|
277
|
+
case "stub":
|
|
278
|
+
case "internal_native_search_performance":
|
|
279
|
+
return "internal";
|
|
280
|
+
default:
|
|
281
|
+
return "unknown";
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function normalizeNetworkKind(value) {
|
|
285
|
+
switch (boundedString(value)?.toLowerCase()) {
|
|
286
|
+
case "timeout":
|
|
287
|
+
case "dns":
|
|
288
|
+
case "connect":
|
|
289
|
+
case "reset":
|
|
290
|
+
case "unavailable":
|
|
291
|
+
case "unknown":
|
|
292
|
+
return boundedString(value).toLowerCase();
|
|
293
|
+
default:
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function normalizeNetworkScope(value) {
|
|
298
|
+
switch (boundedString(value)?.toLowerCase()) {
|
|
299
|
+
case "client_to_deepline":
|
|
300
|
+
case "runtime_to_deepline":
|
|
301
|
+
case "deepline_to_provider":
|
|
302
|
+
return boundedString(value).toLowerCase();
|
|
303
|
+
default:
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function isRecord(value) {
|
|
308
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
309
|
+
}
|
|
310
|
+
function normalizeToolExecutionFailure(value) {
|
|
311
|
+
if (!isRecord(value) || value.schemaVersion !== TOOL_EXECUTION_ERROR_SCHEMA_VERSION) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
const toolId = boundedString(value.toolId);
|
|
315
|
+
if (!toolId) return null;
|
|
316
|
+
const provider = boundedString(value.provider);
|
|
317
|
+
const operation = boundedString(value.operation);
|
|
318
|
+
const origin = normalizeToolExecutionOrigin(value.origin, {
|
|
319
|
+
provider,
|
|
320
|
+
operation
|
|
321
|
+
});
|
|
322
|
+
const category = normalizeToolExecutionCategory(value.category);
|
|
323
|
+
const trustworthy = origin !== "unknown" && category !== "unknown" && typeof value.retryable === "boolean";
|
|
324
|
+
return {
|
|
325
|
+
schemaVersion: TOOL_EXECUTION_ERROR_SCHEMA_VERSION,
|
|
326
|
+
toolId,
|
|
327
|
+
provider,
|
|
328
|
+
operation,
|
|
329
|
+
code: boundedString(value.code, MAX_CODE_LENGTH),
|
|
330
|
+
origin,
|
|
331
|
+
category,
|
|
332
|
+
retryable: trustworthy ? value.retryable === true : false,
|
|
333
|
+
statusCode: finiteNonNegativeInteger(value.statusCode),
|
|
334
|
+
requestId: boundedString(value.requestId),
|
|
335
|
+
retryAfterMs: finiteNonNegativeInteger(value.retryAfterMs),
|
|
336
|
+
networkKind: normalizeNetworkKind(value.networkKind),
|
|
337
|
+
networkScope: normalizeNetworkScope(value.networkScope)
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function serializeToolExecutionFailure(error) {
|
|
341
|
+
if (!(error instanceof ToolExecutionError)) return null;
|
|
342
|
+
return normalizeToolExecutionFailure({
|
|
343
|
+
schemaVersion: TOOL_EXECUTION_ERROR_SCHEMA_VERSION,
|
|
344
|
+
toolId: error.toolId,
|
|
345
|
+
provider: error.provider,
|
|
346
|
+
operation: error.operation,
|
|
347
|
+
code: error.code ?? null,
|
|
348
|
+
origin: error.origin,
|
|
349
|
+
category: error.category,
|
|
350
|
+
retryable: error.retryable,
|
|
351
|
+
statusCode: error.statusCode ?? null,
|
|
352
|
+
requestId: error.requestId,
|
|
353
|
+
retryAfterMs: error.retryAfterMs,
|
|
354
|
+
networkKind: error.networkKind,
|
|
355
|
+
networkScope: error.networkScope
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
function deserializeToolExecutionFailure(message, value, acceptedSchemaVersion) {
|
|
359
|
+
if (acceptedSchemaVersion === LEGACY_TOOL_EXECUTION_ERROR_SCHEMA_VERSION) {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
const failure = normalizeToolExecutionFailure(value);
|
|
363
|
+
if (!failure) return null;
|
|
364
|
+
if (isProviderTransientFailure(failure)) {
|
|
365
|
+
return new ProviderTransientError(message, failure);
|
|
366
|
+
}
|
|
367
|
+
return new ToolExecutionError(message, failure);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// src/errors.ts
|
|
98
371
|
var AuthError = class extends DeeplineError {
|
|
372
|
+
/** Constructed by the SDK when Deepline rejects the caller's credentials. */
|
|
99
373
|
constructor(message = "Authentication failed. Check your DEEPLINE_API_KEY.") {
|
|
100
374
|
super(message, 401, "AUTH_ERROR");
|
|
101
375
|
this.name = "AuthError";
|
|
@@ -104,6 +378,7 @@ var AuthError = class extends DeeplineError {
|
|
|
104
378
|
var RateLimitError = class extends DeeplineError {
|
|
105
379
|
/** Milliseconds to wait before retrying, from the `Retry-After` response header. Defaults to 5000. */
|
|
106
380
|
retryAfterMs;
|
|
381
|
+
/** Constructed by the SDK after exhausting HTTP-level rate-limit retries. */
|
|
107
382
|
constructor(retryAfterMs = 5e3, message) {
|
|
108
383
|
super(
|
|
109
384
|
message ?? `Rate limited. Retry after ${retryAfterMs}ms.`,
|
|
@@ -114,7 +389,51 @@ var RateLimitError = class extends DeeplineError {
|
|
|
114
389
|
this.retryAfterMs = retryAfterMs;
|
|
115
390
|
}
|
|
116
391
|
};
|
|
392
|
+
var ToolRateLimitError = class extends RateLimitError {
|
|
393
|
+
/** Public tool id passed to `tools.execute`. */
|
|
394
|
+
toolId;
|
|
395
|
+
/** Provider responsible for the operation, or `null`. */
|
|
396
|
+
provider;
|
|
397
|
+
/** Provider operation name, or `null`. */
|
|
398
|
+
operation;
|
|
399
|
+
/** Stable machine-readable failure code when one exists. */
|
|
400
|
+
code;
|
|
401
|
+
/** Boundary responsible for the failure. */
|
|
402
|
+
origin;
|
|
403
|
+
/** Stable reason family for policy and diagnostics. */
|
|
404
|
+
category;
|
|
405
|
+
/** Whether repeating the same semantic call is delivery-safe. */
|
|
406
|
+
retryable;
|
|
407
|
+
/** Provider or Deepline request id, or `null`. */
|
|
408
|
+
requestId;
|
|
409
|
+
/** Network failure kind, or `null` for non-network failures. */
|
|
410
|
+
networkKind;
|
|
411
|
+
/** Network boundary that failed, or `null` for non-network failures. */
|
|
412
|
+
networkScope;
|
|
413
|
+
/** Constructed by the SDK after a structured tool HTTP 429. */
|
|
414
|
+
constructor(message, options) {
|
|
415
|
+
super(options.retryAfterMs ?? 5e3, message);
|
|
416
|
+
this.name = "ToolRateLimitError";
|
|
417
|
+
this.statusCode = options.statusCode ?? 429;
|
|
418
|
+
this.code = options.code ?? void 0;
|
|
419
|
+
this.toolId = options.toolId;
|
|
420
|
+
this.provider = options.provider;
|
|
421
|
+
this.operation = options.operation;
|
|
422
|
+
this.origin = options.origin;
|
|
423
|
+
this.category = options.category;
|
|
424
|
+
this.retryable = options.retryable;
|
|
425
|
+
this.requestId = options.requestId;
|
|
426
|
+
this.networkKind = options.networkKind;
|
|
427
|
+
this.networkScope = options.networkScope;
|
|
428
|
+
this.details = options.details;
|
|
429
|
+
brandAsToolExecutionError(this);
|
|
430
|
+
if (isProviderTransientFailure(this)) {
|
|
431
|
+
brandAsProviderTransientError(this);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
};
|
|
117
435
|
var ConfigError = class extends DeeplineError {
|
|
436
|
+
/** Construct a local SDK configuration failure. */
|
|
118
437
|
constructor(message) {
|
|
119
438
|
super(message, void 0, "CONFIG_ERROR");
|
|
120
439
|
this.name = "ConfigError";
|
|
@@ -399,6 +718,9 @@ var import_node_fs2 = require("fs");
|
|
|
399
718
|
var import_node_os3 = require("os");
|
|
400
719
|
var import_node_path2 = require("path");
|
|
401
720
|
|
|
721
|
+
// ../shared_libs/plays/artifact-contract-version.ts
|
|
722
|
+
var CURRENT_PLAY_ARTIFACT_CONTRACT_VERSION = 2;
|
|
723
|
+
|
|
402
724
|
// src/release.ts
|
|
403
725
|
var SDK_RELEASE = {
|
|
404
726
|
// 0.1.94 is claimed by PR #1527 — this watch-render fix ships as 0.1.95.
|
|
@@ -438,7 +760,7 @@ var SDK_RELEASE = {
|
|
|
438
760
|
// 0.1.253 makes play-page browser opening opt-in and retires --no-open.
|
|
439
761
|
// 0.1.254 removes the internal operations tree from the published SDK CLI.
|
|
440
762
|
// Operators use the checkout-local deepline-admin binary instead.
|
|
441
|
-
version: "0.1.
|
|
763
|
+
version: "0.1.303",
|
|
442
764
|
contracts: {
|
|
443
765
|
api: {
|
|
444
766
|
name: "sdk-http-api",
|
|
@@ -454,8 +776,8 @@ var SDK_RELEASE = {
|
|
|
454
776
|
},
|
|
455
777
|
playArtifact: {
|
|
456
778
|
name: "play-artifact-runtime",
|
|
457
|
-
currentVersion:
|
|
458
|
-
supportedVersions: [1,
|
|
779
|
+
currentVersion: CURRENT_PLAY_ARTIFACT_CONTRACT_VERSION,
|
|
780
|
+
supportedVersions: [1, CURRENT_PLAY_ARTIFACT_CONTRACT_VERSION]
|
|
459
781
|
},
|
|
460
782
|
release: {
|
|
461
783
|
name: "production-sdk-release",
|
|
@@ -687,6 +1009,9 @@ function providerLabelFromToolId(toolId) {
|
|
|
687
1009
|
const provider = normalized.split(/[_:./-]+/)[0];
|
|
688
1010
|
return provider || normalized || "provider";
|
|
689
1011
|
}
|
|
1012
|
+
function isRecord2(value) {
|
|
1013
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1014
|
+
}
|
|
690
1015
|
var HttpClient = class {
|
|
691
1016
|
constructor(config) {
|
|
692
1017
|
this.config = config;
|
|
@@ -822,6 +1147,29 @@ var HttpClient = class {
|
|
|
822
1147
|
signal: controller.signal
|
|
823
1148
|
});
|
|
824
1149
|
clearTimeout(timeoutId);
|
|
1150
|
+
const body = await response.text();
|
|
1151
|
+
const parsed = parseResponseBody(body);
|
|
1152
|
+
const structuredToolError = options?.toolId && !response.ok ? deserializeToolExecutionFailure(
|
|
1153
|
+
apiErrorMessage(parsed, response.status),
|
|
1154
|
+
isRecord2(parsed) ? parsed.tool_error : null,
|
|
1155
|
+
TOOL_EXECUTION_ERROR_SCHEMA_VERSION
|
|
1156
|
+
) : null;
|
|
1157
|
+
if (structuredToolError) {
|
|
1158
|
+
if (response.status === 429) {
|
|
1159
|
+
const retryAfter = parseRetryAfter(response);
|
|
1160
|
+
const failure = serializeToolExecutionFailure(structuredToolError);
|
|
1161
|
+
lastError = failure === null ? structuredToolError : new ToolRateLimitError(structuredToolError.message, {
|
|
1162
|
+
...failure,
|
|
1163
|
+
retryAfterMs: failure.retryAfterMs ?? Math.max(0, retryAfter)
|
|
1164
|
+
});
|
|
1165
|
+
if (attempt < maxRetries) {
|
|
1166
|
+
retryAfterDelayMs = retryAfter;
|
|
1167
|
+
break;
|
|
1168
|
+
}
|
|
1169
|
+
throw lastError;
|
|
1170
|
+
}
|
|
1171
|
+
throw structuredToolError;
|
|
1172
|
+
}
|
|
825
1173
|
if (response.status === 429) {
|
|
826
1174
|
const retryAfter = parseRetryAfter(response);
|
|
827
1175
|
lastError = new RateLimitError(retryAfter);
|
|
@@ -831,8 +1179,6 @@ var HttpClient = class {
|
|
|
831
1179
|
}
|
|
832
1180
|
throw lastError;
|
|
833
1181
|
}
|
|
834
|
-
const body = await response.text();
|
|
835
|
-
const parsed = parseResponseBody(body);
|
|
836
1182
|
if (response.status === 401 && !isProviderOriginatedHttpError(parsed) || response.status === 403 && !options?.forbiddenAsApiError) {
|
|
837
1183
|
throw new AuthError();
|
|
838
1184
|
}
|
|
@@ -897,6 +1243,29 @@ var HttpClient = class {
|
|
|
897
1243
|
lastError,
|
|
898
1244
|
describeRequestTarget(path)
|
|
899
1245
|
);
|
|
1246
|
+
if (options?.toolId) {
|
|
1247
|
+
const code = mappedNetworkError.code;
|
|
1248
|
+
throw new ToolExecutionError(
|
|
1249
|
+
withCoworkNetworkHint(mappedNetworkError.message),
|
|
1250
|
+
{
|
|
1251
|
+
toolId: options.toolId,
|
|
1252
|
+
provider: providerLabelFromToolId(options.toolId),
|
|
1253
|
+
operation: options.toolId,
|
|
1254
|
+
code,
|
|
1255
|
+
origin: "deepline",
|
|
1256
|
+
category: "network",
|
|
1257
|
+
// A direct client timeout has ambiguous delivery. Fail closed unless
|
|
1258
|
+
// the server returns the authoritative action delivery contract.
|
|
1259
|
+
retryable: false,
|
|
1260
|
+
statusCode: null,
|
|
1261
|
+
requestId: null,
|
|
1262
|
+
retryAfterMs: null,
|
|
1263
|
+
networkKind: code === "NETWORK_TIMEOUT" ? "timeout" : code === "NETWORK_ABORTED" ? "unknown" : "unavailable",
|
|
1264
|
+
networkScope: "client_to_deepline",
|
|
1265
|
+
details: mappedNetworkError.details
|
|
1266
|
+
}
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
900
1269
|
throw new DeeplineError(
|
|
901
1270
|
withCoworkNetworkHint(mappedNetworkError.message),
|
|
902
1271
|
void 0,
|
|
@@ -1338,11 +1707,11 @@ var RUNNER_POST_TERMINAL_DIAGNOSTIC_MAX_BYTES = 64 * 1024;
|
|
|
1338
1707
|
var ledgerIngressRedactor = createSecretRedactionContext();
|
|
1339
1708
|
|
|
1340
1709
|
// ../shared_libs/play-runtime/activity-observation.ts
|
|
1341
|
-
function
|
|
1710
|
+
function isRecord3(value) {
|
|
1342
1711
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
1343
1712
|
}
|
|
1344
1713
|
function isPlayActivityObservation(value) {
|
|
1345
|
-
if (!
|
|
1714
|
+
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)) {
|
|
1346
1715
|
return false;
|
|
1347
1716
|
}
|
|
1348
1717
|
const targetKinds = /* @__PURE__ */ new Set([
|
|
@@ -1607,7 +1976,7 @@ function projectPlayRunActivity(input) {
|
|
|
1607
1976
|
|
|
1608
1977
|
// ../shared_libs/play-runtime/run-ledger.ts
|
|
1609
1978
|
var LOG_TAIL_LIMIT = 100;
|
|
1610
|
-
function
|
|
1979
|
+
function isRecord4(value) {
|
|
1611
1980
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
1612
1981
|
}
|
|
1613
1982
|
function finiteNumber(value) {
|
|
@@ -1703,21 +2072,21 @@ function createEmptyPlayRunLedgerSnapshot(input) {
|
|
|
1703
2072
|
};
|
|
1704
2073
|
}
|
|
1705
2074
|
function normalizePlayRunLedgerSnapshot(value, fallback) {
|
|
1706
|
-
if (!
|
|
2075
|
+
if (!isRecord4(value)) {
|
|
1707
2076
|
return createEmptyPlayRunLedgerSnapshot(fallback);
|
|
1708
2077
|
}
|
|
1709
2078
|
const orderedStepIds = Array.isArray(value.orderedStepIds) ? value.orderedStepIds.filter(
|
|
1710
2079
|
(entry) => typeof entry === "string" && Boolean(entry.trim())
|
|
1711
2080
|
) : [];
|
|
1712
|
-
const rawSteps =
|
|
2081
|
+
const rawSteps = isRecord4(value.stepsById) ? value.stepsById : {};
|
|
1713
2082
|
const stepsById = {};
|
|
1714
2083
|
for (const [stepId, rawStep] of Object.entries(rawSteps)) {
|
|
1715
|
-
if (!stepId.trim() || !
|
|
2084
|
+
if (!stepId.trim() || !isRecord4(rawStep)) continue;
|
|
1716
2085
|
const rawStatus = normalizeStepStatus(rawStep.status);
|
|
1717
2086
|
if (!rawStatus) continue;
|
|
1718
2087
|
const completedAt = finiteNumber(rawStep.completedAt);
|
|
1719
2088
|
const status = rawStatus === "running" && completedAt !== null ? "completed" : rawStatus;
|
|
1720
|
-
const rawProgress =
|
|
2089
|
+
const rawProgress = isRecord4(rawStep.progress) ? rawStep.progress : null;
|
|
1721
2090
|
stepsById[stepId] = {
|
|
1722
2091
|
stepId,
|
|
1723
2092
|
label: optionalString(rawStep.label),
|
|
@@ -1733,10 +2102,10 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
|
|
|
1733
2102
|
progress: rawProgress ? normalizeStepProgress(rawProgress) : null
|
|
1734
2103
|
};
|
|
1735
2104
|
}
|
|
1736
|
-
const rawDatasets =
|
|
2105
|
+
const rawDatasets = isRecord4(value.datasetsById) ? value.datasetsById : {};
|
|
1737
2106
|
const datasetsById = {};
|
|
1738
2107
|
for (const [datasetId, rawDataset] of Object.entries(rawDatasets)) {
|
|
1739
|
-
if (!datasetId.trim() || !
|
|
2108
|
+
if (!datasetId.trim() || !isRecord4(rawDataset)) continue;
|
|
1740
2109
|
const phase = rawDataset.phase === "available" || rawDataset.phase === "failed" ? rawDataset.phase : "registered";
|
|
1741
2110
|
datasetsById[datasetId] = {
|
|
1742
2111
|
datasetId,
|
|
@@ -1750,7 +2119,7 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
|
|
|
1750
2119
|
updatedAt: finiteNumber(rawDataset.updatedAt) ?? 0
|
|
1751
2120
|
};
|
|
1752
2121
|
}
|
|
1753
|
-
const rawActivities =
|
|
2122
|
+
const rawActivities = isRecord4(value.activitiesById) ? value.activitiesById : {};
|
|
1754
2123
|
const activitiesById = {};
|
|
1755
2124
|
for (const [activityId, rawActivity] of Object.entries(rawActivities)) {
|
|
1756
2125
|
if (activityId.trim() && isPlayActivityObservation(rawActivity) && rawActivity.activityId === activityId) {
|
|
@@ -1899,18 +2268,18 @@ function normalizePlayRunLiveStatus(value) {
|
|
|
1899
2268
|
function isTerminalPlayRunLiveStatus(status) {
|
|
1900
2269
|
return isTerminalPlayRunLifecycleStatus(status);
|
|
1901
2270
|
}
|
|
1902
|
-
function
|
|
2271
|
+
function isRecord5(value) {
|
|
1903
2272
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
1904
2273
|
}
|
|
1905
2274
|
function finiteNumber2(value) {
|
|
1906
2275
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
1907
2276
|
}
|
|
1908
2277
|
function extractTerminalRunLogTail(result) {
|
|
1909
|
-
if (!
|
|
2278
|
+
if (!isRecord5(result) || !isRecord5(result._metadata)) {
|
|
1910
2279
|
return null;
|
|
1911
2280
|
}
|
|
1912
2281
|
const runLogTail = result._metadata.runLogTail;
|
|
1913
|
-
if (!
|
|
2282
|
+
if (!isRecord5(runLogTail) || !Array.isArray(runLogTail.tail)) {
|
|
1914
2283
|
return null;
|
|
1915
2284
|
}
|
|
1916
2285
|
const logTail = runLogTail.tail.filter(
|
|
@@ -2804,7 +3173,7 @@ function resolveToolExecuteTimeoutMs(toolId, input) {
|
|
|
2804
3173
|
}
|
|
2805
3174
|
var RUNS_FAILED_LOG_LIMIT = 20;
|
|
2806
3175
|
var RUN_LOGS_PAGE_LIMIT = 1e3;
|
|
2807
|
-
function
|
|
3176
|
+
function isRecord6(value) {
|
|
2808
3177
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
2809
3178
|
}
|
|
2810
3179
|
function isPrebuiltPlayDescription(play) {
|
|
@@ -2967,7 +3336,7 @@ function updatePlayLiveStatusState(state, event) {
|
|
|
2967
3336
|
}
|
|
2968
3337
|
const runId = typeof payload.runId === "string" && payload.runId ? payload.runId : isPlayRunPackage(payload) ? payload.run.id : state.runId;
|
|
2969
3338
|
const status = normalizeLiveStatus(payload.status) ?? (isPlayRunPackage(payload) ? normalizeLiveStatus(payload.run.status) : null) ?? state.status;
|
|
2970
|
-
const progressPayload =
|
|
3339
|
+
const progressPayload = isRecord6(payload.progress) ? payload.progress : {};
|
|
2971
3340
|
if (event.type === "play.run.final_status" && state.logs.length === 0 && state.lastLogSeq === 0) {
|
|
2972
3341
|
const payloadLogs = readStringArray(payload.logs);
|
|
2973
3342
|
const progressLogs = readStringArray(progressPayload.logs);
|
|
@@ -3101,9 +3470,9 @@ var DeeplineClient = class {
|
|
|
3101
3470
|
return fields.length > 0 ? { fields } : schema;
|
|
3102
3471
|
}
|
|
3103
3472
|
schemaMetadata(schema, key) {
|
|
3104
|
-
if (!
|
|
3473
|
+
if (!isRecord6(schema)) return null;
|
|
3105
3474
|
const value = schema[key];
|
|
3106
|
-
return
|
|
3475
|
+
return isRecord6(value) ? value : null;
|
|
3107
3476
|
}
|
|
3108
3477
|
playRunCommand(play, options) {
|
|
3109
3478
|
const target = play.reference || play.name;
|
|
@@ -3152,7 +3521,7 @@ var DeeplineClient = class {
|
|
|
3152
3521
|
aliases,
|
|
3153
3522
|
inputSchema: options?.compact ? this.compactSchema(play.inputSchema) : play.inputSchema ?? null,
|
|
3154
3523
|
outputSchema: options?.compact ? this.compactSchema(play.outputSchema) : play.outputSchema ?? null,
|
|
3155
|
-
staticPipeline:
|
|
3524
|
+
staticPipeline: isRecord6(play.staticPipeline) ? play.staticPipeline : isRecord6(play.currentRevision?.staticPipeline) ? play.currentRevision.staticPipeline : isRecord6(play.liveRevision?.staticPipeline) ? play.liveRevision.staticPipeline : null,
|
|
3156
3525
|
...csvInput ? { csvInput } : {},
|
|
3157
3526
|
...rowOutputSchema ? { rowOutputSchema } : {},
|
|
3158
3527
|
runCommand,
|
|
@@ -3323,6 +3692,9 @@ var DeeplineClient = class {
|
|
|
3323
3692
|
async executeTool(toolId, input, options) {
|
|
3324
3693
|
const headers = {
|
|
3325
3694
|
[EXECUTE_RESPONSE_CONTRACT_HEADER]: V2_EXECUTE_RESPONSE_CONTRACT,
|
|
3695
|
+
[TOOL_EXECUTION_ERROR_SCHEMA_HEADER]: String(
|
|
3696
|
+
TOOL_EXECUTION_ERROR_SCHEMA_VERSION
|
|
3697
|
+
),
|
|
3326
3698
|
...options?.includeToolMetadata ? { [INCLUDE_TOOL_METADATA_HEADER]: "true" } : {},
|
|
3327
3699
|
[EXECUTE_RESPONSE_INTENT_HEADER]: options?.responseIntent ?? "raw"
|
|
3328
3700
|
};
|
|
@@ -3337,7 +3709,8 @@ var DeeplineClient = class {
|
|
|
3337
3709
|
forbiddenAsApiError: true,
|
|
3338
3710
|
timeout: options?.timeout ?? resolveToolExecuteTimeoutMs(toolId, input),
|
|
3339
3711
|
maxRetries: options?.maxRetries ?? 0,
|
|
3340
|
-
exactUrlOnly: true
|
|
3712
|
+
exactUrlOnly: true,
|
|
3713
|
+
toolId
|
|
3341
3714
|
}
|
|
3342
3715
|
);
|
|
3343
3716
|
}
|
|
@@ -5832,6 +6205,11 @@ function normalizeTableNamespace(value) {
|
|
|
5832
6205
|
);
|
|
5833
6206
|
}
|
|
5834
6207
|
|
|
6208
|
+
// ../shared_libs/play-runtime/tool-result-paths.ts
|
|
6209
|
+
function listNameFromDeclaredPath(path) {
|
|
6210
|
+
return String(path || "").split(".").filter(Boolean).at(-1)?.replace(/[^A-Za-z0-9_$]/g, "") || null;
|
|
6211
|
+
}
|
|
6212
|
+
|
|
5835
6213
|
// ../shared_libs/play-runtime/tool-result.ts
|
|
5836
6214
|
var TARGET_FALLBACK_KEYS = {
|
|
5837
6215
|
email: [/^email$/i, /^address$/i, /email/i],
|
|
@@ -5844,7 +6222,7 @@ var TARGET_FALLBACK_KEYS = {
|
|
|
5844
6222
|
status: [/^email_status$/i, /^status$/i],
|
|
5845
6223
|
email_status: [/^email_status$/i, /^status$/i]
|
|
5846
6224
|
};
|
|
5847
|
-
function
|
|
6225
|
+
function isRecord7(value) {
|
|
5848
6226
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5849
6227
|
}
|
|
5850
6228
|
function toV2RawToolOutputPath(path) {
|
|
@@ -5904,7 +6282,7 @@ function valuesAtSegments(current, segments, path = []) {
|
|
|
5904
6282
|
if (!Array.isArray(current)) return [];
|
|
5905
6283
|
return valuesAtSegments(current[segment], rest, [...path, segment]);
|
|
5906
6284
|
}
|
|
5907
|
-
if (!
|
|
6285
|
+
if (!isRecord7(current)) return [];
|
|
5908
6286
|
const directMatches = valuesAtSegments(current[segment], rest, [
|
|
5909
6287
|
...path,
|
|
5910
6288
|
segment
|
|
@@ -5934,7 +6312,7 @@ function getValuesAtPath(root, path) {
|
|
|
5934
6312
|
return valuesAtSegments(root, parsePath(path)).map((entry) => entry.value);
|
|
5935
6313
|
}
|
|
5936
6314
|
function toResultEnvelope(value) {
|
|
5937
|
-
if (
|
|
6315
|
+
if (isRecord7(value) && "data" in value) {
|
|
5938
6316
|
const envelope = { data: value.data };
|
|
5939
6317
|
if ("meta" in value) envelope.meta = value.meta;
|
|
5940
6318
|
return envelope;
|
|
@@ -5987,7 +6365,7 @@ function getAtPath(root, path) {
|
|
|
5987
6365
|
current = current[segment];
|
|
5988
6366
|
continue;
|
|
5989
6367
|
}
|
|
5990
|
-
if (!
|
|
6368
|
+
if (!isRecord7(current)) return void 0;
|
|
5991
6369
|
current = current[segment];
|
|
5992
6370
|
}
|
|
5993
6371
|
return current;
|
|
@@ -6004,7 +6382,7 @@ function normalizeString(value) {
|
|
|
6004
6382
|
}
|
|
6005
6383
|
function normalizeRows(value) {
|
|
6006
6384
|
if (!Array.isArray(value)) return null;
|
|
6007
|
-
return value.map((entry) =>
|
|
6385
|
+
return value.map((entry) => isRecord7(entry) ? entry : { value: entry });
|
|
6008
6386
|
}
|
|
6009
6387
|
function findFirstTargetByPath(result, paths) {
|
|
6010
6388
|
for (const path of paths ?? []) {
|
|
@@ -6063,7 +6441,7 @@ function findFirstTargetByKey(result, target, depth = 0, path = []) {
|
|
|
6063
6441
|
}
|
|
6064
6442
|
return null;
|
|
6065
6443
|
}
|
|
6066
|
-
if (!
|
|
6444
|
+
if (!isRecord7(result)) return null;
|
|
6067
6445
|
const patterns = TARGET_FALLBACK_KEYS[target] ?? [
|
|
6068
6446
|
new RegExp(`^${target}$`, "i")
|
|
6069
6447
|
];
|
|
@@ -6123,7 +6501,7 @@ function normalizeJobChangeStatus(value) {
|
|
|
6123
6501
|
function firstExperienceDate(value) {
|
|
6124
6502
|
if (!Array.isArray(value)) return null;
|
|
6125
6503
|
for (const entry of value) {
|
|
6126
|
-
if (!
|
|
6504
|
+
if (!isRecord7(entry)) continue;
|
|
6127
6505
|
const date = normalizeString(
|
|
6128
6506
|
entry.start_date ?? entry.started_at ?? entry.startDate
|
|
6129
6507
|
);
|
|
@@ -6132,10 +6510,10 @@ function firstExperienceDate(value) {
|
|
|
6132
6510
|
return null;
|
|
6133
6511
|
}
|
|
6134
6512
|
function normalizeJobChange(value) {
|
|
6135
|
-
const record =
|
|
6136
|
-
const nested =
|
|
6137
|
-
const output =
|
|
6138
|
-
const person =
|
|
6513
|
+
const record = isRecord7(value) ? value : {};
|
|
6514
|
+
const nested = isRecord7(record.job_change) ? record.job_change : record;
|
|
6515
|
+
const output = isRecord7(nested.output) ? nested.output : nested;
|
|
6516
|
+
const person = isRecord7(output.person) ? output.person : {};
|
|
6139
6517
|
const status = normalizeJobChangeStatus(
|
|
6140
6518
|
output.status ?? output.job_change_status ?? output.job_changed ?? output.changed
|
|
6141
6519
|
);
|
|
@@ -6172,38 +6550,33 @@ function coerceToEnum(value, descriptor) {
|
|
|
6172
6550
|
function resolveListRows(result, listExtractorPaths) {
|
|
6173
6551
|
const lists = {};
|
|
6174
6552
|
for (const rawPath of listExtractorPaths ?? []) {
|
|
6553
|
+
const listName = listNameFromDeclaredPath(rawPath);
|
|
6554
|
+
if (!listName) continue;
|
|
6175
6555
|
const path = normalizeResultPath(rawPath);
|
|
6176
6556
|
if (!path) continue;
|
|
6177
6557
|
const candidates = [...candidateResultPaths(rawPath)].filter(
|
|
6178
6558
|
(candidate, index, all) => candidate && all.indexOf(candidate) === index
|
|
6179
6559
|
);
|
|
6180
|
-
let
|
|
6181
|
-
let rows = null;
|
|
6560
|
+
let resolved = null;
|
|
6182
6561
|
let emptyMatch = null;
|
|
6183
6562
|
for (const candidate of candidates) {
|
|
6184
|
-
|
|
6185
|
-
if (!
|
|
6563
|
+
const candidateRows = normalizeRows(getAtPath(result, candidate));
|
|
6564
|
+
if (!candidateRows) {
|
|
6186
6565
|
continue;
|
|
6187
6566
|
}
|
|
6188
|
-
if (
|
|
6189
|
-
|
|
6567
|
+
if (candidateRows.length > 0) {
|
|
6568
|
+
resolved = { path: candidate, rows: candidateRows };
|
|
6190
6569
|
break;
|
|
6191
6570
|
}
|
|
6192
|
-
emptyMatch ??= { path: candidate, rows };
|
|
6571
|
+
emptyMatch ??= { path: candidate, rows: candidateRows };
|
|
6193
6572
|
}
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
rows = emptyMatch.rows;
|
|
6197
|
-
}
|
|
6198
|
-
if (!rows) continue;
|
|
6199
|
-
const storedPath = resolvedPath ?? path;
|
|
6200
|
-
const name = storedPath.split(".").filter(Boolean).at(-1)?.replace(/\[\d+\]$/, "");
|
|
6201
|
-
const listName = name || storedPath;
|
|
6573
|
+
resolved ??= emptyMatch;
|
|
6574
|
+
if (!resolved) continue;
|
|
6202
6575
|
const existing = lists[listName];
|
|
6203
|
-
if (existing?.rows.length && rows.length === 0) {
|
|
6576
|
+
if (existing?.rows.length && resolved.rows.length === 0) {
|
|
6204
6577
|
continue;
|
|
6205
6578
|
}
|
|
6206
|
-
lists[listName] =
|
|
6579
|
+
lists[listName] = resolved;
|
|
6207
6580
|
}
|
|
6208
6581
|
return lists;
|
|
6209
6582
|
}
|
|
@@ -6437,6 +6810,7 @@ function createToolExecuteResult(input) {
|
|
|
6437
6810
|
toolId: input.metadata.toolId,
|
|
6438
6811
|
execution: input.execution,
|
|
6439
6812
|
targets,
|
|
6813
|
+
listExtractorPaths: [...input.metadata.listExtractorPaths ?? []],
|
|
6440
6814
|
...input.metadata.extractors ? { extractors: input.metadata.extractors } : {},
|
|
6441
6815
|
lists
|
|
6442
6816
|
};
|
|
@@ -6478,6 +6852,19 @@ function attachToolResultListDataset(result, input) {
|
|
|
6478
6852
|
count: input.count,
|
|
6479
6853
|
keys: input.keys ?? existing?.keys ?? {}
|
|
6480
6854
|
};
|
|
6855
|
+
const declaredPaths = result._metadata.listExtractorPaths ?? [];
|
|
6856
|
+
const inputCandidates = new Set(candidateResultPaths(input.path));
|
|
6857
|
+
const equivalentDeclaration = declaredPaths.find(
|
|
6858
|
+
(path) => candidateResultPaths(path).some(
|
|
6859
|
+
(candidate) => inputCandidates.has(candidate)
|
|
6860
|
+
)
|
|
6861
|
+
);
|
|
6862
|
+
result._metadata.listExtractorPaths = equivalentDeclaration ? [...declaredPaths] : [
|
|
6863
|
+
...declaredPaths.filter(
|
|
6864
|
+
(path) => listNameFromDeclaredPath(path) !== input.name
|
|
6865
|
+
),
|
|
6866
|
+
input.path
|
|
6867
|
+
];
|
|
6481
6868
|
const accessor = {
|
|
6482
6869
|
path: input.path,
|
|
6483
6870
|
count: input.count,
|
|
@@ -6500,7 +6887,7 @@ function attachToolResultListDataset(result, input) {
|
|
|
6500
6887
|
root = replaceAtPath(root, candidate, serialized.preview);
|
|
6501
6888
|
break;
|
|
6502
6889
|
}
|
|
6503
|
-
if (
|
|
6890
|
+
if (isRecord7(root) && isRecord7(root.toolResponse) && Object.prototype.hasOwnProperty.call(root.toolResponse, "raw")) {
|
|
6504
6891
|
result.toolResponse.raw = root.toolResponse.raw;
|
|
6505
6892
|
result.toolOutput.raw = root.toolResponse.raw;
|
|
6506
6893
|
}
|
|
@@ -6518,7 +6905,7 @@ function replaceAtPath(root, path, replacement) {
|
|
|
6518
6905
|
copy[segment] = replace(copy[segment], index + 1);
|
|
6519
6906
|
return copy;
|
|
6520
6907
|
}
|
|
6521
|
-
if (!
|
|
6908
|
+
if (!isRecord7(current)) return current;
|
|
6522
6909
|
return {
|
|
6523
6910
|
...current,
|
|
6524
6911
|
[segment]: replace(current[segment], index + 1)
|
|
@@ -6839,11 +7226,11 @@ var Deepline = class {
|
|
|
6839
7226
|
return new DeeplineContext(options);
|
|
6840
7227
|
}
|
|
6841
7228
|
};
|
|
6842
|
-
function
|
|
7229
|
+
function isRecord8(value) {
|
|
6843
7230
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6844
7231
|
}
|
|
6845
7232
|
function stringArrayRecord(value) {
|
|
6846
|
-
if (!
|
|
7233
|
+
if (!isRecord8(value)) return {};
|
|
6847
7234
|
return Object.fromEntries(
|
|
6848
7235
|
Object.entries(value).map(([key, paths]) => [
|
|
6849
7236
|
key,
|
|
@@ -6855,7 +7242,7 @@ function stringArray(value) {
|
|
|
6855
7242
|
return Array.isArray(value) ? value.map(String) : [];
|
|
6856
7243
|
}
|
|
6857
7244
|
function emailStatusExtractorConfig(value) {
|
|
6858
|
-
if (!
|
|
7245
|
+
if (!isRecord8(value)) return void 0;
|
|
6859
7246
|
const readPaths = (key) => {
|
|
6860
7247
|
const paths = stringArray(value[key]).map((path) => path.trim()).filter(Boolean);
|
|
6861
7248
|
return paths.length > 0 ? paths : void 0;
|
|
@@ -6882,7 +7269,7 @@ function emailStatusExtractorConfig(value) {
|
|
|
6882
7269
|
const paths = readPaths(key);
|
|
6883
7270
|
if (paths) config[key] = paths;
|
|
6884
7271
|
}
|
|
6885
|
-
if (
|
|
7272
|
+
if (isRecord8(value.statusMap)) {
|
|
6886
7273
|
config.statusMap = value.statusMap;
|
|
6887
7274
|
}
|
|
6888
7275
|
if (Array.isArray(value.rules)) {
|
|
@@ -6891,10 +7278,10 @@ function emailStatusExtractorConfig(value) {
|
|
|
6891
7278
|
return config;
|
|
6892
7279
|
}
|
|
6893
7280
|
function extractorDescriptorRecord(value) {
|
|
6894
|
-
if (!
|
|
7281
|
+
if (!isRecord8(value)) return {};
|
|
6895
7282
|
return Object.fromEntries(
|
|
6896
7283
|
Object.entries(value).flatMap(([key, descriptor]) => {
|
|
6897
|
-
if (!
|
|
7284
|
+
if (!isRecord8(descriptor)) return [];
|
|
6898
7285
|
const paths = stringArray(descriptor.paths).map((path) => path.trim()).filter(Boolean);
|
|
6899
7286
|
if (paths.length === 0) return [];
|
|
6900
7287
|
const transforms = stringArray(descriptor.transforms).map((transform) => transform.trim()).filter(Boolean);
|
|
@@ -6916,16 +7303,16 @@ function extractorDescriptorRecord(value) {
|
|
|
6916
7303
|
}
|
|
6917
7304
|
function rowsFromUnknown(value) {
|
|
6918
7305
|
if (!Array.isArray(value)) return [];
|
|
6919
|
-
return value.map((row) =>
|
|
7306
|
+
return value.map((row) => isRecord8(row) ? row : { value: row });
|
|
6920
7307
|
}
|
|
6921
|
-
function
|
|
7308
|
+
function finiteNonNegativeInteger2(value) {
|
|
6922
7309
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
6923
7310
|
return null;
|
|
6924
7311
|
}
|
|
6925
7312
|
return Math.floor(value);
|
|
6926
7313
|
}
|
|
6927
7314
|
function finitePositiveInteger(value) {
|
|
6928
|
-
const integer =
|
|
7315
|
+
const integer = finiteNonNegativeInteger2(value);
|
|
6929
7316
|
return integer !== null && integer > 0 ? integer : null;
|
|
6930
7317
|
}
|
|
6931
7318
|
function stableHash(value) {
|
|
@@ -6938,9 +7325,9 @@ function stableHash(value) {
|
|
|
6938
7325
|
}
|
|
6939
7326
|
function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
6940
7327
|
if (!options || !isQueryResultDatasetTool(toolId)) return result;
|
|
6941
|
-
const raw =
|
|
6942
|
-
const dataset =
|
|
6943
|
-
const totalRows =
|
|
7328
|
+
const raw = isRecord8(result.toolResponse.raw) ? result.toolResponse.raw : null;
|
|
7329
|
+
const dataset = isRecord8(raw?.dataset) ? raw.dataset : null;
|
|
7330
|
+
const totalRows = finiteNonNegativeInteger2(dataset?.total_rows);
|
|
6944
7331
|
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;
|
|
6945
7332
|
if (!dataset || totalRows === null || !sql) {
|
|
6946
7333
|
return result;
|
|
@@ -6969,7 +7356,7 @@ function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
|
6969
7356
|
} : {}
|
|
6970
7357
|
}
|
|
6971
7358
|
});
|
|
6972
|
-
const pageRaw =
|
|
7359
|
+
const pageRaw = isRecord8(response.toolResponse?.raw) ? response.toolResponse.raw : null;
|
|
6973
7360
|
return rowsFromUnknown(pageRaw?.rows);
|
|
6974
7361
|
};
|
|
6975
7362
|
const collectRows = async (limit) => {
|
|
@@ -7022,8 +7409,8 @@ function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
|
7022
7409
|
function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
7023
7410
|
const raw = response.toolResponse?.raw ?? null;
|
|
7024
7411
|
const meta = response.toolResponse?.meta;
|
|
7025
|
-
const metadata =
|
|
7026
|
-
const toolMetadata =
|
|
7412
|
+
const metadata = isRecord8(response._metadata) ? response._metadata.tool : null;
|
|
7413
|
+
const toolMetadata = isRecord8(metadata) ? metadata : {};
|
|
7027
7414
|
return attachSdkQueryResultDatasetResult(
|
|
7028
7415
|
fallbackToolId,
|
|
7029
7416
|
createToolExecuteResult({
|
|
@@ -7031,7 +7418,7 @@ function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
|
7031
7418
|
jobId: typeof response.job_id === "string" ? response.job_id : void 0,
|
|
7032
7419
|
result: {
|
|
7033
7420
|
data: raw,
|
|
7034
|
-
...
|
|
7421
|
+
...isRecord8(meta) ? { meta } : {}
|
|
7035
7422
|
},
|
|
7036
7423
|
metadata: {
|
|
7037
7424
|
toolId: typeof toolMetadata.toolId === "string" ? toolMetadata.toolId : fallbackToolId,
|
|
@@ -7047,7 +7434,7 @@ function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
|
7047
7434
|
cached: false,
|
|
7048
7435
|
source: "live"
|
|
7049
7436
|
},
|
|
7050
|
-
meta:
|
|
7437
|
+
meta: isRecord8(response.meta) ? response.meta : void 0
|
|
7051
7438
|
}),
|
|
7052
7439
|
options
|
|
7053
7440
|
);
|
|
@@ -7067,14 +7454,16 @@ function definePlay(nameOrConfig, maybeFn, maybeBindings) {
|
|
|
7067
7454
|
bindings: maybeBindings,
|
|
7068
7455
|
description: maybeBindings?.description,
|
|
7069
7456
|
inputSchema: void 0,
|
|
7070
|
-
billing: maybeBindings?.billing
|
|
7457
|
+
billing: maybeBindings?.billing,
|
|
7458
|
+
compatibility: maybeBindings?.compatibility
|
|
7071
7459
|
} : {
|
|
7072
7460
|
name: nameOrConfig.id,
|
|
7073
7461
|
fn: nameOrConfig.run,
|
|
7074
7462
|
bindings: nameOrConfig.bindings,
|
|
7075
7463
|
description: nameOrConfig.description,
|
|
7076
7464
|
inputSchema: nameOrConfig.input.schema,
|
|
7077
|
-
billing: nameOrConfig.billing
|
|
7465
|
+
billing: nameOrConfig.billing,
|
|
7466
|
+
compatibility: nameOrConfig.compatibility ?? nameOrConfig.bindings?.compatibility
|
|
7078
7467
|
};
|
|
7079
7468
|
const name = config.name;
|
|
7080
7469
|
const fn = config.fn;
|
|
@@ -7082,6 +7471,7 @@ function definePlay(nameOrConfig, maybeFn, maybeBindings) {
|
|
|
7082
7471
|
const description = config.description?.trim();
|
|
7083
7472
|
const billing = config.billing;
|
|
7084
7473
|
const inputSchema = config.inputSchema;
|
|
7474
|
+
const compatibility = config.compatibility;
|
|
7085
7475
|
if (typeof fn !== "function") {
|
|
7086
7476
|
throw new Error("definePlay(...) requires an async run function.");
|
|
7087
7477
|
}
|
|
@@ -7106,7 +7496,8 @@ function definePlay(nameOrConfig, maybeFn, maybeBindings) {
|
|
|
7106
7496
|
...description ? { description } : {},
|
|
7107
7497
|
...bindings ? { bindings } : {},
|
|
7108
7498
|
...inputSchema ? { inputSchema } : {},
|
|
7109
|
-
...billing ? { billing } : {}
|
|
7499
|
+
...billing ? { billing } : {},
|
|
7500
|
+
...compatibility ? { compatibility } : {}
|
|
7110
7501
|
};
|
|
7111
7502
|
const play = fn;
|
|
7112
7503
|
Object.defineProperty(play, PLAY_METADATA_SYMBOL, {
|
|
@@ -7127,6 +7518,12 @@ function definePlay(nameOrConfig, maybeFn, maybeBindings) {
|
|
|
7127
7518
|
configurable: false,
|
|
7128
7519
|
writable: false
|
|
7129
7520
|
});
|
|
7521
|
+
Object.defineProperty(play, "compatibility", {
|
|
7522
|
+
value: compatibility,
|
|
7523
|
+
enumerable: true,
|
|
7524
|
+
configurable: false,
|
|
7525
|
+
writable: false
|
|
7526
|
+
});
|
|
7130
7527
|
const handle = createNamedPlayHandle(
|
|
7131
7528
|
() => new DeeplineClient(),
|
|
7132
7529
|
name
|
|
@@ -7373,10 +7770,13 @@ function extractSummaryFields(payload) {
|
|
|
7373
7770
|
PLAY_BOOTSTRAP_STAGE_KINDS,
|
|
7374
7771
|
PLAY_BOOTSTRAP_TEMPLATES,
|
|
7375
7772
|
PROD_URL,
|
|
7773
|
+
ProviderTransientError,
|
|
7376
7774
|
RateLimitError,
|
|
7377
7775
|
RunObserveTransportUnavailableError,
|
|
7378
7776
|
SDK_API_CONTRACT,
|
|
7379
7777
|
SDK_VERSION,
|
|
7778
|
+
ToolExecutionError,
|
|
7779
|
+
ToolRateLimitError,
|
|
7380
7780
|
defineInput,
|
|
7381
7781
|
defineMonitor,
|
|
7382
7782
|
definePlay,
|