deepline 0.3.231 → 0.3.233

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/cli/index.js CHANGED
@@ -1964,7 +1964,7 @@ configureProxyFromEnv();
1964
1964
 
1965
1965
  // src/cli/index.ts
1966
1966
  var import_promises15 = require("fs/promises");
1967
- var import_node_path33 = require("path");
1967
+ var import_node_path34 = require("path");
1968
1968
  var import_node_os20 = require("os");
1969
1969
  var import_commander5 = require("commander");
1970
1970
 
@@ -3001,6 +3001,409 @@ function resolveCliCommandContext(inputConfig, requestedScope) {
3001
3001
  };
3002
3002
  }
3003
3003
 
3004
+ // ../integration-contracts/theirstack/execution-policy.ts
3005
+ var THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS = 135e3;
3006
+ var THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS = 6e4 + THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS + 15e3;
3007
+ var THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS = 21e4;
3008
+ var LONG_JOB_SEARCH_WINDOW_MS = 365 * 24 * 60 * 60 * 1e3;
3009
+ var DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
3010
+ function parseDateOnly(value) {
3011
+ if (typeof value !== "string" || !DATE_ONLY_PATTERN.test(value)) {
3012
+ return null;
3013
+ }
3014
+ const timestamp = Date.parse(`${value}T00:00:00.000Z`);
3015
+ if (!Number.isFinite(timestamp)) {
3016
+ return null;
3017
+ }
3018
+ return new Date(timestamp).toISOString().slice(0, 10) === value ? timestamp : null;
3019
+ }
3020
+ function usesLongExplicitDateWindow(payload) {
3021
+ const postedAtGte = parseDateOnly(payload.posted_at_gte);
3022
+ const postedAtLte = parseDateOnly(payload.posted_at_lte);
3023
+ if (postedAtGte !== null && postedAtLte !== null) {
3024
+ return postedAtLte - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
3025
+ }
3026
+ if (postedAtGte !== null) {
3027
+ return Date.now() - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
3028
+ }
3029
+ return postedAtLte !== null && payload.posted_at_gte == null;
3030
+ }
3031
+ function parseMaxAgeDays(value) {
3032
+ if (typeof value === "number") {
3033
+ return Number.isFinite(value) ? value : null;
3034
+ }
3035
+ if (typeof value !== "string" || !/^-?\d+$/.test(value.trim())) {
3036
+ return null;
3037
+ }
3038
+ const parsed = Number(value.trim());
3039
+ return Number.isSafeInteger(parsed) ? parsed : null;
3040
+ }
3041
+ function usesExtendedTheirstackJobSearchBudget(endpointId, payload) {
3042
+ if (endpointId !== "theirstack_job_search") {
3043
+ return false;
3044
+ }
3045
+ if (payload.include_total_results === true) {
3046
+ return true;
3047
+ }
3048
+ const maxAgeDays = parseMaxAgeDays(payload.posted_at_max_age_days);
3049
+ return maxAgeDays !== null && maxAgeDays >= 365 ? true : usesLongExplicitDateWindow(payload);
3050
+ }
3051
+ function resolveTheirstackClientTimeoutMs(endpointId, payload) {
3052
+ if (endpointId === "theirstack_company_search") {
3053
+ return THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS;
3054
+ }
3055
+ return usesExtendedTheirstackJobSearchBudget(endpointId, payload) ? THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS : null;
3056
+ }
3057
+
3058
+ // ../integration-contracts/waterfall/execution-policy.ts
3059
+ var WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS = 18e4;
3060
+ var WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
3061
+ "prospector",
3062
+ "deepline_native_prospector"
3063
+ ]);
3064
+ function resolveWaterfallClientTimeoutMs(toolId) {
3065
+ return WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase()) ? WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS : null;
3066
+ }
3067
+
3068
+ // ../integration-contracts/bettercontact/execution-policy.ts
3069
+ var BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS = 12e4;
3070
+ var BETTERCONTACT_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
3071
+ "bettercontact_enrich",
3072
+ "bettercontact_bulk_enrich"
3073
+ ]);
3074
+ function usesExtendedBetterContactLauncherBudget(toolId) {
3075
+ return BETTERCONTACT_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase());
3076
+ }
3077
+
3078
+ // ../plays/tool-response-contract.ts
3079
+ var RAW_V2_TOOL_RESPONSE_CONTRACT = "raw-v2";
3080
+ function legacyRawFromToolResponseRawV2(rawV2, view, responseMeta) {
3081
+ const legacyRaw = view === "data" && rawV2 && typeof rawV2 === "object" && !Array.isArray(rawV2) ? rawV2.data : rawV2;
3082
+ const deeplineBilling = responseMeta?.deepline_billing;
3083
+ if (view === "rawV2" && deeplineBilling !== void 0 && legacyRaw && typeof legacyRaw === "object" && !Array.isArray(legacyRaw)) {
3084
+ return {
3085
+ ...legacyRaw,
3086
+ deepline_billing: deeplineBilling
3087
+ };
3088
+ }
3089
+ return legacyRaw;
3090
+ }
3091
+ function providerMetaFromToolResponseRawV2(rawV2, view) {
3092
+ if (view !== "data" || !rawV2 || typeof rawV2 !== "object" || Array.isArray(rawV2)) {
3093
+ return void 0;
3094
+ }
3095
+ const meta = rawV2.meta;
3096
+ return meta && typeof meta === "object" && !Array.isArray(meta) ? meta : void 0;
3097
+ }
3098
+
3099
+ // src/tool-calls.ts
3100
+ var INCLUDE_TOOL_METADATA_HEADER = "x-deepline-include-tool-metadata";
3101
+ var EXECUTE_RESPONSE_CONTRACT_HEADER = "x-deepline-execute-response-contract";
3102
+ var EXECUTE_RESPONSE_INTENT_HEADER = "x-deepline-execute-response-intent";
3103
+ var RAW_V2_EXECUTE_RESPONSE_CONTRACT = RAW_V2_TOOL_RESPONSE_CONTRACT;
3104
+ var DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS = 15 * 60 * 1e3;
3105
+ function validateExecutionIdempotencyKey(key) {
3106
+ if (typeof key !== "string" || key.length < 1 || key.length > 200 || !/^[A-Za-z0-9._:-]+$/.test(key)) {
3107
+ throw new DeeplineError(
3108
+ "Execution idempotency keys must be 1\u2013200 ASCII letters, digits, dots, underscores, colons, or hyphens.",
3109
+ void 0,
3110
+ "IDEMPOTENCY_KEY_INVALID"
3111
+ );
3112
+ }
3113
+ }
3114
+ function getExecutionRecoveryState(value) {
3115
+ if (!isRecord2(value) || !isRecord2(value.executionRecovery)) return null;
3116
+ const state = value.executionRecovery.state;
3117
+ return state === "running" || state === "completed" || state === "outcome_unknown" ? state : null;
3118
+ }
3119
+ function isRecoverableExecutionAttemptError(error) {
3120
+ if (error instanceof ToolExecutionError) {
3121
+ return error.code === "EXECUTION_IN_PROGRESS" || error.origin === "deepline" && error.category === "network" && error.networkScope === "client_to_deepline";
3122
+ }
3123
+ return error instanceof DeeplineError && (error.code === "EXECUTION_IN_PROGRESS" || error.code?.startsWith("NETWORK_") === true && error.statusCode === void 0);
3124
+ }
3125
+ function isRecoverableExecutionLookupError(error) {
3126
+ if (isRecoverableExecutionAttemptError(error)) return true;
3127
+ return error instanceof DeeplineError && (error.statusCode === 429 || error.statusCode !== void 0 && error.statusCode >= 500);
3128
+ }
3129
+ function timeoutWithinRecoveryBudget(requestTimeoutMs, defaultRequestTimeoutMs, remainingMs) {
3130
+ return Math.min(requestTimeoutMs ?? defaultRequestTimeoutMs, remainingMs);
3131
+ }
3132
+ function executionRecoveryError(input2) {
3133
+ return new ToolExecutionError(input2.message, {
3134
+ toolId: input2.toolId,
3135
+ provider: null,
3136
+ operation: input2.toolId,
3137
+ code: input2.code,
3138
+ origin: "deepline",
3139
+ category: input2.code === "EXECUTION_OUTCOME_UNKNOWN" ? "unknown" : "conflict",
3140
+ retryable: input2.code !== "EXECUTION_OUTCOME_UNKNOWN",
3141
+ statusCode: null,
3142
+ requestId: null,
3143
+ retryAfterMs: null,
3144
+ networkKind: null,
3145
+ networkScope: null,
3146
+ publicDetails: { idempotencyKey: input2.idempotencyKey }
3147
+ });
3148
+ }
3149
+ var DEEPLINEAGENT_EXECUTE_TIMEOUT_MS = 15 * 60 * 1e3;
3150
+ var APIFY_SYNC_DEFAULT_TIMEOUT_MS = 3e5;
3151
+ var APIFY_SYNC_RESPONSE_GRACE_MS = 9e4;
3152
+ function resolveToolExecuteTimeoutMs(toolId, input2) {
3153
+ const normalized = toolId.trim().toLowerCase();
3154
+ if (normalized === "apify_run_actor_sync") {
3155
+ const requestedTimeoutMs = input2.timeoutMs ?? APIFY_SYNC_DEFAULT_TIMEOUT_MS;
3156
+ if (typeof requestedTimeoutMs === "number" && Number.isFinite(requestedTimeoutMs) && requestedTimeoutMs > 0) {
3157
+ return Math.floor(requestedTimeoutMs) + APIFY_SYNC_RESPONSE_GRACE_MS;
3158
+ }
3159
+ }
3160
+ const theirstackTimeoutMs = resolveTheirstackClientTimeoutMs(
3161
+ normalized,
3162
+ input2
3163
+ );
3164
+ if (theirstackTimeoutMs !== null) return theirstackTimeoutMs;
3165
+ const waterfallTimeoutMs = resolveWaterfallClientTimeoutMs(normalized);
3166
+ if (waterfallTimeoutMs !== null) return waterfallTimeoutMs;
3167
+ if (usesExtendedBetterContactLauncherBudget(normalized)) {
3168
+ return BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS;
3169
+ }
3170
+ return normalized === "deeplineagent" || normalized === "deeplineagent_deeplineagent" || normalized === "ai_inference" || normalized === "deeplineagent_ai_inference" || normalized === "ai_evaluate" || normalized === "deeplineagent_ai_evaluate" || normalized === "aiinference" ? DEEPLINEAGENT_EXECUTE_TIMEOUT_MS : void 0;
3171
+ }
3172
+ function isRecord2(value) {
3173
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
3174
+ }
3175
+ function materializeToolExecutionResponse(response) {
3176
+ const toolResponse = response.toolResponse;
3177
+ if (!toolResponse && isRecord2(response.result)) {
3178
+ const legacyResult = response.result;
3179
+ if (Object.prototype.hasOwnProperty.call(legacyResult, "data")) {
3180
+ const legacyMeta = isRecord2(legacyResult.meta) ? legacyResult.meta : void 0;
3181
+ return {
3182
+ ...response,
3183
+ toolResponse: {
3184
+ raw: legacyResult.data,
3185
+ ...legacyMeta ? { meta: legacyMeta } : {}
3186
+ }
3187
+ };
3188
+ }
3189
+ }
3190
+ if (!toolResponse || Object.prototype.hasOwnProperty.call(toolResponse, "raw")) {
3191
+ return response;
3192
+ }
3193
+ const rawV2 = toolResponse.rawV2;
3194
+ const view = toolResponse.view;
3195
+ const providerMeta = providerMetaFromToolResponseRawV2(
3196
+ rawV2,
3197
+ view ?? "rawV2"
3198
+ );
3199
+ const responseMeta = isRecord2(toolResponse.responseMeta) ? toolResponse.responseMeta : void 0;
3200
+ return {
3201
+ ...response,
3202
+ toolResponse: {
3203
+ ...toolResponse,
3204
+ raw: legacyRawFromToolResponseRawV2(
3205
+ rawV2,
3206
+ view ?? "rawV2",
3207
+ responseMeta
3208
+ ),
3209
+ ...toolResponse.meta || providerMeta || responseMeta ? {
3210
+ meta: {
3211
+ ...toolResponse.meta ?? {},
3212
+ ...providerMeta ?? {},
3213
+ ...responseMeta ?? {}
3214
+ }
3215
+ } : {}
3216
+ }
3217
+ };
3218
+ }
3219
+ var ToolCalls = class {
3220
+ constructor(http, defaultRequestTimeoutMs) {
3221
+ this.http = http;
3222
+ this.defaultRequestTimeoutMs = defaultRequestTimeoutMs;
3223
+ }
3224
+ async call(toolId, input2, options) {
3225
+ const inputSnapshot = JSON.parse(JSON.stringify(input2));
3226
+ const metadataSnapshot = options?.metadata ? JSON.parse(JSON.stringify(options.metadata)) : void 0;
3227
+ const idempotencyKey = options?.idempotencyKey ?? (options?.recover ? crypto.randomUUID() : void 0);
3228
+ if (idempotencyKey !== void 0) {
3229
+ validateExecutionIdempotencyKey(idempotencyKey);
3230
+ if (options?.recoveryTimeoutMs !== void 0 && (!Number.isFinite(options.recoveryTimeoutMs) || options.recoveryTimeoutMs < 0)) {
3231
+ throw new DeeplineError(
3232
+ "recoveryTimeoutMs must be a finite, non-negative number.",
3233
+ void 0,
3234
+ "IDEMPOTENCY_KEY_INVALID"
3235
+ );
3236
+ }
3237
+ await options?.onExecution?.({ idempotencyKey });
3238
+ }
3239
+ const timeoutMs = options?.timeout ?? resolveToolExecuteTimeoutMs(toolId, inputSnapshot);
3240
+ if (idempotencyKey !== void 0) {
3241
+ await this.lookupExecutionByKey(idempotencyKey, timeoutMs);
3242
+ }
3243
+ const isApifySync = toolId.trim().toLowerCase() === "apify_run_actor_sync";
3244
+ const headers = {
3245
+ [EXECUTE_RESPONSE_CONTRACT_HEADER]: RAW_V2_EXECUTE_RESPONSE_CONTRACT,
3246
+ ...isApifySync ? { "X-Deepline-Apify-Sync-Response-Budget": "extended-v1" } : {},
3247
+ [TOOL_EXECUTION_ERROR_SCHEMA_HEADER]: String(
3248
+ TOOL_EXECUTION_ERROR_SCHEMA_VERSION
3249
+ ),
3250
+ ...options?.includeToolMetadata ? { [INCLUDE_TOOL_METADATA_HEADER]: "true" } : {},
3251
+ [EXECUTE_RESPONSE_INTENT_HEADER]: options?.responseIntent ?? "raw",
3252
+ ...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {},
3253
+ ...options?.searchRef ? { "x-deepline-search-ref": options.searchRef } : {}
3254
+ };
3255
+ const request = (requestTimeoutMs) => this.http.post(
3256
+ `/api/v2/integrations/${encodeURIComponent(toolId)}/execute`,
3257
+ {
3258
+ payload: inputSnapshot,
3259
+ ...metadataSnapshot ? { metadata: metadataSnapshot } : {}
3260
+ },
3261
+ headers,
3262
+ {
3263
+ timeout: requestTimeoutMs,
3264
+ maxRetries: idempotencyKey ? 0 : options?.maxRetries ?? 0,
3265
+ retryApiErrors: options?.retryApiErrors === true,
3266
+ exactUrlOnly: true,
3267
+ toolId,
3268
+ idempotencyKey
3269
+ }
3270
+ );
3271
+ let response;
3272
+ let recoveryDeadline = null;
3273
+ const recoveryTimeoutMs = options?.recoveryTimeoutMs ?? DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS;
3274
+ let retryDelayMs = 1e3;
3275
+ const recoveryTimeoutError = () => executionRecoveryError({
3276
+ toolId,
3277
+ idempotencyKey,
3278
+ code: "EXECUTION_RECOVERY_TIMEOUT",
3279
+ message: `Execution recovery for ${idempotencyKey} did not finish before the recovery timeout. Inspect client.executions.getByKey() and resume with the same idempotency key.`
3280
+ });
3281
+ const waitForRecoveryRetry = async (deadline) => {
3282
+ const remainingMs = deadline - Date.now();
3283
+ if (remainingMs <= 0) throw recoveryTimeoutError();
3284
+ await new Promise(
3285
+ (resolve22) => setTimeout(resolve22, Math.min(retryDelayMs, remainingMs))
3286
+ );
3287
+ retryDelayMs = Math.min(retryDelayMs * 2, 5e3);
3288
+ };
3289
+ const lookupDuringRecovery = async () => {
3290
+ while (true) {
3291
+ const remainingMs = recoveryDeadline - Date.now();
3292
+ if (remainingMs <= 0) throw recoveryTimeoutError();
3293
+ try {
3294
+ return await this.lookupExecutionByKey(
3295
+ idempotencyKey,
3296
+ timeoutWithinRecoveryBudget(
3297
+ timeoutMs,
3298
+ this.defaultRequestTimeoutMs,
3299
+ remainingMs
3300
+ )
3301
+ );
3302
+ } catch (error) {
3303
+ if (!isRecoverableExecutionLookupError(error)) throw error;
3304
+ await waitForRecoveryRetry(recoveryDeadline);
3305
+ }
3306
+ }
3307
+ };
3308
+ while (true) {
3309
+ const remainingMs = recoveryDeadline === null ? null : recoveryDeadline - Date.now();
3310
+ if (remainingMs !== null && remainingMs <= 0) {
3311
+ throw recoveryTimeoutError();
3312
+ }
3313
+ try {
3314
+ response = await request(
3315
+ remainingMs === null ? timeoutMs : timeoutWithinRecoveryBudget(
3316
+ timeoutMs,
3317
+ this.defaultRequestTimeoutMs,
3318
+ remainingMs
3319
+ )
3320
+ );
3321
+ const recoveryState = getExecutionRecoveryState(response);
3322
+ if (recoveryState === "outcome_unknown") {
3323
+ if (!idempotencyKey) break;
3324
+ throw executionRecoveryError({
3325
+ toolId,
3326
+ idempotencyKey,
3327
+ code: "EXECUTION_OUTCOME_UNKNOWN",
3328
+ message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
3329
+ });
3330
+ }
3331
+ if (!idempotencyKey || recoveryState !== "running") {
3332
+ break;
3333
+ }
3334
+ if (recoveryDeadline === null) {
3335
+ recoveryDeadline = Date.now() + recoveryTimeoutMs;
3336
+ }
3337
+ } catch (error) {
3338
+ if (idempotencyKey && error instanceof DeeplineError && error.code === "EXECUTION_OUTCOME_UNKNOWN") {
3339
+ throw executionRecoveryError({
3340
+ toolId,
3341
+ idempotencyKey,
3342
+ code: "EXECUTION_OUTCOME_UNKNOWN",
3343
+ message: error.message
3344
+ });
3345
+ }
3346
+ if (!idempotencyKey || !isRecoverableExecutionAttemptError(error)) {
3347
+ throw error;
3348
+ }
3349
+ if (recoveryDeadline === null) {
3350
+ recoveryDeadline = Date.now() + recoveryTimeoutMs;
3351
+ }
3352
+ }
3353
+ await waitForRecoveryRetry(recoveryDeadline);
3354
+ const recovered = await lookupDuringRecovery();
3355
+ if (getExecutionRecoveryState(recovered) === "outcome_unknown") {
3356
+ throw executionRecoveryError({
3357
+ toolId,
3358
+ idempotencyKey,
3359
+ code: "EXECUTION_OUTCOME_UNKNOWN",
3360
+ message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
3361
+ });
3362
+ }
3363
+ }
3364
+ const materialized = materializeToolExecutionResponse(response);
3365
+ return idempotencyKey ? { ...materialized, idempotencyKey } : materialized;
3366
+ }
3367
+ /** Read the durable state of a keyed tool execution. */
3368
+ async getByKey(idempotencyKey) {
3369
+ validateExecutionIdempotencyKey(idempotencyKey);
3370
+ const result = await this.lookupExecutionByKey(idempotencyKey);
3371
+ if (!result) {
3372
+ throw new DeeplineError(
3373
+ `No execution exists for idempotency key ${idempotencyKey}.`,
3374
+ 404,
3375
+ "EXECUTION_NOT_FOUND"
3376
+ );
3377
+ }
3378
+ return result;
3379
+ }
3380
+ async lookupExecutionByKey(idempotencyKey, timeoutMs) {
3381
+ validateExecutionIdempotencyKey(idempotencyKey);
3382
+ let supported = false;
3383
+ const result = await this.http.get(
3384
+ `/api/v2/executions/by-key/${encodeURIComponent(idempotencyKey)}`,
3385
+ {
3386
+ exactUrlOnly: true,
3387
+ maxRetries: 0,
3388
+ timeout: timeoutMs,
3389
+ idempotencyKey,
3390
+ allowNotFound: true,
3391
+ onResponse: (response) => {
3392
+ supported = response.headers.get("X-Deepline-Idempotency-Supported") === "true";
3393
+ }
3394
+ }
3395
+ );
3396
+ if (!supported) {
3397
+ throw new DeeplineError(
3398
+ "This Deepline server does not support recoverable tool executions; no tool was dispatched.",
3399
+ 422,
3400
+ "IDEMPOTENCY_NOT_SUPPORTED"
3401
+ );
3402
+ }
3403
+ return result;
3404
+ }
3405
+ };
3406
+
3004
3407
  // ../plays/artifact-contract-version.ts
3005
3408
  var CURRENT_PLAY_ARTIFACT_CONTRACT_VERSION = 2;
3006
3409
 
@@ -3051,7 +3454,7 @@ var SDK_RELEASE = {
3051
3454
  // getters keep their established compatibility behavior.
3052
3455
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
3053
3456
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
3054
- version: "0.3.231",
3457
+ version: "0.3.233",
3055
3458
  updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.",
3056
3459
  packageCapabilities: {
3057
3460
  updatePreferences: 1
@@ -3735,7 +4138,7 @@ function providerLabelFromToolId(toolId) {
3735
4138
  const provider = normalized.split(/[_:./-]+/)[0];
3736
4139
  return provider || normalized || "provider";
3737
4140
  }
3738
- function isRecord2(value) {
4141
+ function isRecord3(value) {
3739
4142
  return value !== null && typeof value === "object" && !Array.isArray(value);
3740
4143
  }
3741
4144
  var HttpClient = class {
@@ -3887,7 +4290,7 @@ var HttpClient = class {
3887
4290
  const parsed = parseResponseBody(body);
3888
4291
  const structuredToolError = options?.toolId && !response.ok ? deserializeToolExecutionFailure(
3889
4292
  apiErrorMessage(parsed, response.status),
3890
- isRecord2(parsed) ? parsed.tool_error : null,
4293
+ isRecord3(parsed) ? parsed.tool_error : null,
3891
4294
  TOOL_EXECUTION_ERROR_SCHEMA_VERSION
3892
4295
  ) : null;
3893
4296
  if (structuredToolError) {
@@ -4958,11 +5361,11 @@ function buildPlayDocflowNodeErrorPreview(error, redactor = createSecretRedactio
4958
5361
  return "Non-Error value thrown (message unavailable)";
4959
5362
  }
4960
5363
  }
4961
- function isRecord3(value) {
5364
+ function isRecord4(value) {
4962
5365
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
4963
5366
  }
4964
5367
  function normalizePreview(value, depth) {
4965
- if (!isRecord3(value) || typeof value.kind !== "string") return null;
5368
+ if (!isRecord4(value) || typeof value.kind !== "string") return null;
4966
5369
  if (value.kind === "null") return { kind: "null" };
4967
5370
  if (value.kind === "scalar") {
4968
5371
  if (typeof value.value === "string" || typeof value.value === "boolean" || typeof value.value === "number" && Number.isFinite(value.value)) {
@@ -5027,7 +5430,7 @@ function normalizePreview(value, depth) {
5027
5430
  ...value.truncated === true || totalItems > items.length ? { truncated: true } : {}
5028
5431
  };
5029
5432
  }
5030
- if (value.kind === "object" && isRecord3(value.fields)) {
5433
+ if (value.kind === "object" && isRecord4(value.fields)) {
5031
5434
  const fields2 = {};
5032
5435
  for (const [key, field] of Object.entries(value.fields).slice(
5033
5436
  0,
@@ -5047,10 +5450,10 @@ function normalizePreview(value, depth) {
5047
5450
  return null;
5048
5451
  }
5049
5452
  function normalizePlayDocflowNodeIoState(value) {
5050
- if (!isRecord3(value)) return void 0;
5453
+ if (!isRecord4(value)) return void 0;
5051
5454
  const attempt = typeof value.attempt === "number" && Number.isFinite(value.attempt) ? Math.max(0, Math.floor(value.attempt)) : 0;
5052
5455
  const normalizeMap = (raw) => {
5053
- if (!isRecord3(raw)) return void 0;
5456
+ if (!isRecord4(raw)) return void 0;
5054
5457
  const output2 = {};
5055
5458
  for (const [path, preview] of Object.entries(raw).slice(
5056
5459
  0,
@@ -5087,11 +5490,11 @@ function normalizePlayDocflowNodeIoState(value) {
5087
5490
  }
5088
5491
 
5089
5492
  // ../play-runtime/activity-observation.ts
5090
- function isRecord4(value) {
5493
+ function isRecord5(value) {
5091
5494
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
5092
5495
  }
5093
5496
  function isPlayActivityObservation(value) {
5094
- if (!isRecord4(value) || value.schemaVersion !== void 0 && value.schemaVersion !== 1 || typeof value.activityId !== "string" || !value.activityId.trim() || typeof value.observedAt !== "number" || !Number.isFinite(value.observedAt) || !isRecord4(value.target) || !isRecord4(value.state)) {
5497
+ if (!isRecord5(value) || value.schemaVersion !== void 0 && value.schemaVersion !== 1 || typeof value.activityId !== "string" || !value.activityId.trim() || typeof value.observedAt !== "number" || !Number.isFinite(value.observedAt) || !isRecord5(value.target) || !isRecord5(value.state)) {
5095
5498
  return false;
5096
5499
  }
5097
5500
  const targetKinds = /* @__PURE__ */ new Set([
@@ -5391,7 +5794,7 @@ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
5391
5794
  "terminated",
5392
5795
  "timed_out"
5393
5796
  ]);
5394
- function isRecord5(value) {
5797
+ function isRecord6(value) {
5395
5798
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
5396
5799
  }
5397
5800
  function finiteNumber(value) {
@@ -5406,7 +5809,7 @@ function isWorkCounterSegmentId(value) {
5406
5809
  );
5407
5810
  }
5408
5811
  function normalizePlayRunLedgerTerminalWorkCounterSegment(value) {
5409
- if (!isRecord5(value)) return void 0;
5812
+ if (!isRecord6(value)) return void 0;
5410
5813
  if (!nonnegativeSafeInteger(value.attempt) || !nonnegativeSafeInteger(value.invocationSeq) || value.invocationSeq === 0 || !isWorkCounterSegmentId(value.segmentId)) {
5411
5814
  return void 0;
5412
5815
  }
@@ -5430,7 +5833,7 @@ function hasConfirmedPlayRunLedgerWorkCounters(snapshot) {
5430
5833
  );
5431
5834
  }
5432
5835
  function normalizeWorkCounters(value) {
5433
- if (!isRecord5(value)) return void 0;
5836
+ if (!isRecord6(value)) return void 0;
5434
5837
  for (const field of [
5435
5838
  "attempt",
5436
5839
  "invocationSeq",
@@ -5520,8 +5923,8 @@ function summarizeRunRowOutcomes(snapshot) {
5520
5923
  const stepTotal = finiteNumber(progress.total);
5521
5924
  totalRows += stepTotal !== null && stepTotal >= 0 ? stepTotal : Math.max(0, finiteNumber(progress.completed) ?? 0) + Math.max(0, finiteNumber(progress.failed) ?? 0) + Math.max(0, finiteNumber(progress.supersededRows) ?? 0);
5522
5925
  }
5523
- const resultSummary = isRecord5(snapshot.resultSummary) ? snapshot.resultSummary : null;
5524
- const resultRowOutcomes = isRecord5(resultSummary?.rowOutcomes) ? resultSummary.rowOutcomes : null;
5926
+ const resultSummary = isRecord6(snapshot.resultSummary) ? snapshot.resultSummary : null;
5927
+ const resultRowOutcomes = isRecord6(resultSummary?.rowOutcomes) ? resultSummary.rowOutcomes : null;
5525
5928
  const terminalCompletedRows = finiteNumber(resultRowOutcomes?.completedRows);
5526
5929
  const terminalFailedRows = finiteNumber(resultRowOutcomes?.failedRows);
5527
5930
  const terminalTotalRows = finiteNumber(resultRowOutcomes?.totalRows);
@@ -5570,21 +5973,21 @@ function createEmptyPlayRunLedgerSnapshot(input2) {
5570
5973
  };
5571
5974
  }
5572
5975
  function normalizePlayRunLedgerSnapshot(value, fallback) {
5573
- if (!isRecord5(value)) {
5976
+ if (!isRecord6(value)) {
5574
5977
  return createEmptyPlayRunLedgerSnapshot(fallback);
5575
5978
  }
5576
5979
  const orderedStepIds = Array.isArray(value.orderedStepIds) ? value.orderedStepIds.filter(
5577
5980
  (entry) => typeof entry === "string" && Boolean(entry.trim())
5578
5981
  ) : [];
5579
- const rawSteps = isRecord5(value.stepsById) ? value.stepsById : {};
5982
+ const rawSteps = isRecord6(value.stepsById) ? value.stepsById : {};
5580
5983
  const stepsById = {};
5581
5984
  for (const [stepId, rawStep] of Object.entries(rawSteps)) {
5582
- if (!stepId.trim() || !isRecord5(rawStep)) continue;
5985
+ if (!stepId.trim() || !isRecord6(rawStep)) continue;
5583
5986
  const rawStatus = normalizeStepStatus(rawStep.status);
5584
5987
  if (!rawStatus) continue;
5585
5988
  const completedAt = finiteNumber(rawStep.completedAt);
5586
5989
  const status = rawStatus === "running" && completedAt !== null ? "completed" : rawStatus;
5587
- const rawProgress = isRecord5(rawStep.progress) ? rawStep.progress : null;
5990
+ const rawProgress = isRecord6(rawStep.progress) ? rawStep.progress : null;
5588
5991
  stepsById[stepId] = {
5589
5992
  stepId,
5590
5993
  label: optionalString(rawStep.label),
@@ -5600,10 +6003,10 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
5600
6003
  progress: rawProgress ? normalizeStepProgress(rawProgress) : null
5601
6004
  };
5602
6005
  }
5603
- const rawDatasets = isRecord5(value.datasetsById) ? value.datasetsById : {};
6006
+ const rawDatasets = isRecord6(value.datasetsById) ? value.datasetsById : {};
5604
6007
  const datasetsById = {};
5605
6008
  for (const [datasetId, rawDataset] of Object.entries(rawDatasets)) {
5606
- if (!datasetId.trim() || !isRecord5(rawDataset)) continue;
6009
+ if (!datasetId.trim() || !isRecord6(rawDataset)) continue;
5607
6010
  const phase = rawDataset.phase === "available" || rawDataset.phase === "failed" ? rawDataset.phase : "registered";
5608
6011
  const datasetBornFrom = normalizeDatasetBornFrom(rawDataset.bornFrom);
5609
6012
  datasetsById[datasetId] = {
@@ -5626,7 +6029,7 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
5626
6029
  updatedAt: finiteNumber(rawDataset.updatedAt) ?? 0
5627
6030
  };
5628
6031
  }
5629
- const rawActivities = isRecord5(value.activitiesById) ? value.activitiesById : {};
6032
+ const rawActivities = isRecord6(value.activitiesById) ? value.activitiesById : {};
5630
6033
  const activitiesById = {};
5631
6034
  for (const [activityId, rawActivity] of Object.entries(rawActivities)) {
5632
6035
  if (activityId.trim() && isPlayActivityObservation(rawActivity) && rawActivity.activityId === activityId) {
@@ -5916,18 +6319,18 @@ function normalizePlayRunLiveStatus(value) {
5916
6319
  function isTerminalPlayRunLiveStatus(status) {
5917
6320
  return isTerminalPlayRunLifecycleStatus(status);
5918
6321
  }
5919
- function isRecord6(value) {
6322
+ function isRecord7(value) {
5920
6323
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
5921
6324
  }
5922
6325
  function finiteNumber2(value) {
5923
6326
  return typeof value === "number" && Number.isFinite(value) ? value : null;
5924
6327
  }
5925
6328
  function extractTerminalRunLogTail(result) {
5926
- if (!isRecord6(result) || !isRecord6(result._metadata)) {
6329
+ if (!isRecord7(result) || !isRecord7(result._metadata)) {
5927
6330
  return null;
5928
6331
  }
5929
6332
  const runLogTail = result._metadata.runLogTail;
5930
- if (!isRecord6(runLogTail) || !Array.isArray(runLogTail.tail)) {
6333
+ if (!isRecord7(runLogTail) || !Array.isArray(runLogTail.tail)) {
5931
6334
  return null;
5932
6335
  }
5933
6336
  const logTail = runLogTail.tail.filter(
@@ -6587,80 +6990,6 @@ function isStopAllPlayRunsDryRunResult(result) {
6587
6990
  return "dryRun" in result && result.dryRun === true;
6588
6991
  }
6589
6992
 
6590
- // ../integration-contracts/theirstack/execution-policy.ts
6591
- var THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS = 135e3;
6592
- var THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS = 6e4 + THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS + 15e3;
6593
- var THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS = 21e4;
6594
- var LONG_JOB_SEARCH_WINDOW_MS = 365 * 24 * 60 * 60 * 1e3;
6595
- var DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
6596
- function parseDateOnly(value) {
6597
- if (typeof value !== "string" || !DATE_ONLY_PATTERN.test(value)) {
6598
- return null;
6599
- }
6600
- const timestamp = Date.parse(`${value}T00:00:00.000Z`);
6601
- if (!Number.isFinite(timestamp)) {
6602
- return null;
6603
- }
6604
- return new Date(timestamp).toISOString().slice(0, 10) === value ? timestamp : null;
6605
- }
6606
- function usesLongExplicitDateWindow(payload) {
6607
- const postedAtGte = parseDateOnly(payload.posted_at_gte);
6608
- const postedAtLte = parseDateOnly(payload.posted_at_lte);
6609
- if (postedAtGte !== null && postedAtLte !== null) {
6610
- return postedAtLte - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
6611
- }
6612
- if (postedAtGte !== null) {
6613
- return Date.now() - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
6614
- }
6615
- return postedAtLte !== null && payload.posted_at_gte == null;
6616
- }
6617
- function parseMaxAgeDays(value) {
6618
- if (typeof value === "number") {
6619
- return Number.isFinite(value) ? value : null;
6620
- }
6621
- if (typeof value !== "string" || !/^-?\d+$/.test(value.trim())) {
6622
- return null;
6623
- }
6624
- const parsed = Number(value.trim());
6625
- return Number.isSafeInteger(parsed) ? parsed : null;
6626
- }
6627
- function usesExtendedTheirstackJobSearchBudget(endpointId, payload) {
6628
- if (endpointId !== "theirstack_job_search") {
6629
- return false;
6630
- }
6631
- if (payload.include_total_results === true) {
6632
- return true;
6633
- }
6634
- const maxAgeDays = parseMaxAgeDays(payload.posted_at_max_age_days);
6635
- return maxAgeDays !== null && maxAgeDays >= 365 ? true : usesLongExplicitDateWindow(payload);
6636
- }
6637
- function resolveTheirstackClientTimeoutMs(endpointId, payload) {
6638
- if (endpointId === "theirstack_company_search") {
6639
- return THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS;
6640
- }
6641
- return usesExtendedTheirstackJobSearchBudget(endpointId, payload) ? THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS : null;
6642
- }
6643
-
6644
- // ../integration-contracts/waterfall/execution-policy.ts
6645
- var WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS = 18e4;
6646
- var WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
6647
- "prospector",
6648
- "deepline_native_prospector"
6649
- ]);
6650
- function resolveWaterfallClientTimeoutMs(toolId) {
6651
- return WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase()) ? WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS : null;
6652
- }
6653
-
6654
- // ../integration-contracts/bettercontact/execution-policy.ts
6655
- var BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS = 12e4;
6656
- var BETTERCONTACT_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
6657
- "bettercontact_enrich",
6658
- "bettercontact_bulk_enrich"
6659
- ]);
6660
- function usesExtendedBetterContactLauncherBudget(toolId) {
6661
- return BETTERCONTACT_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase());
6662
- }
6663
-
6664
6993
  // ../plays/artifact-types.ts
6665
6994
  var PLAY_ARTIFACT_KINDS = {
6666
6995
  cjsNode20: "cjs_node20"
@@ -6734,27 +7063,6 @@ function normalizePlayRuntimeEnvironment(value) {
6734
7063
  return typeof value === "string" && PLAY_RUNTIME_ENVIRONMENTS.includes(value) ? value : null;
6735
7064
  }
6736
7065
 
6737
- // ../plays/tool-response-contract.ts
6738
- var RAW_V2_TOOL_RESPONSE_CONTRACT = "raw-v2";
6739
- function legacyRawFromToolResponseRawV2(rawV2, view, responseMeta) {
6740
- const legacyRaw = view === "data" && rawV2 && typeof rawV2 === "object" && !Array.isArray(rawV2) ? rawV2.data : rawV2;
6741
- const deeplineBilling = responseMeta?.deepline_billing;
6742
- if (view === "rawV2" && deeplineBilling !== void 0 && legacyRaw && typeof legacyRaw === "object" && !Array.isArray(legacyRaw)) {
6743
- return {
6744
- ...legacyRaw,
6745
- deepline_billing: deeplineBilling
6746
- };
6747
- }
6748
- return legacyRaw;
6749
- }
6750
- function providerMetaFromToolResponseRawV2(rawV2, view) {
6751
- if (view !== "data" || !rawV2 || typeof rawV2 !== "object" || Array.isArray(rawV2)) {
6752
- return void 0;
6753
- }
6754
- const meta = rawV2.meta;
6755
- return meta && typeof meta === "object" && !Array.isArray(meta) ? meta : void 0;
6756
- }
6757
-
6758
7066
  // src/client.ts
6759
7067
  var MAX_NOTIFICATION_GROUP_CREATE_TARGETS = 50;
6760
7068
  function parseNotificationGroupTarget(value) {
@@ -6793,69 +7101,14 @@ function notificationObjectKey(kind) {
6793
7101
  return `${kind}.${globalThis.crypto.randomUUID()}`;
6794
7102
  }
6795
7103
  var TERMINAL_PLAY_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
6796
- var INCLUDE_TOOL_METADATA_HEADER = "x-deepline-include-tool-metadata";
6797
- var EXECUTE_RESPONSE_CONTRACT_HEADER = "x-deepline-execute-response-contract";
6798
- var EXECUTE_RESPONSE_INTENT_HEADER = "x-deepline-execute-response-intent";
6799
7104
  var MONITOR_NON_RETRYABLE_MUTATION_OPTIONS = {
6800
7105
  maxRetries: 0,
6801
7106
  exactUrlOnly: true
6802
7107
  };
6803
- var RAW_V2_EXECUTE_RESPONSE_CONTRACT = RAW_V2_TOOL_RESPONSE_CONTRACT;
6804
- var DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS = 15 * 60 * 1e3;
6805
- function validateExecutionIdempotencyKey(key) {
6806
- if (typeof key !== "string" || key.length < 1 || key.length > 200 || !/^[A-Za-z0-9._:-]+$/.test(key)) {
6807
- throw new DeeplineError(
6808
- "Execution idempotency keys must be 1\u2013200 ASCII letters, digits, dots, underscores, colons, or hyphens.",
6809
- void 0,
6810
- "IDEMPOTENCY_KEY_INVALID"
6811
- );
6812
- }
6813
- }
6814
- function isExecutionInProgressResponse(value) {
6815
- return typeof value === "object" && value !== null && typeof value.executionRecovery === "object" && value.executionRecovery.state === "running";
6816
- }
6817
- function getExecutionRecoveryState(value) {
6818
- if (typeof value !== "object" || value === null || typeof value.executionRecovery !== "object") {
6819
- return null;
6820
- }
6821
- const state = value.executionRecovery.state;
6822
- return state === "running" || state === "completed" || state === "outcome_unknown" ? state : null;
6823
- }
6824
- function isRecoverableExecutionAttemptError(error) {
6825
- if (error instanceof ToolExecutionError) {
6826
- return error.code === "EXECUTION_IN_PROGRESS" || error.origin === "deepline" && error.category === "network" && error.networkScope === "client_to_deepline";
6827
- }
6828
- return error instanceof DeeplineError && (error.code === "EXECUTION_IN_PROGRESS" || error.code?.startsWith("NETWORK_") === true && error.statusCode === void 0);
6829
- }
6830
- function isRecoverableExecutionLookupError(error) {
6831
- if (isRecoverableExecutionAttemptError(error)) return true;
6832
- return error instanceof DeeplineError && (error.statusCode === 429 || error.statusCode !== void 0 && error.statusCode >= 500);
6833
- }
6834
- function timeoutWithinRecoveryBudget(requestTimeoutMs, defaultRequestTimeoutMs, remainingMs) {
6835
- return Math.min(requestTimeoutMs ?? defaultRequestTimeoutMs, remainingMs);
6836
- }
6837
- function executionRecoveryError(input2) {
6838
- return new ToolExecutionError(input2.message, {
6839
- toolId: input2.toolId,
6840
- provider: null,
6841
- operation: input2.toolId,
6842
- code: input2.code,
6843
- origin: "deepline",
6844
- category: input2.code === "EXECUTION_OUTCOME_UNKNOWN" ? "unknown" : "conflict",
6845
- retryable: input2.code !== "EXECUTION_OUTCOME_UNKNOWN",
6846
- statusCode: null,
6847
- requestId: null,
6848
- retryAfterMs: null,
6849
- networkKind: null,
6850
- networkScope: null,
6851
- publicDetails: { idempotencyKey: input2.idempotencyKey }
6852
- });
6853
- }
6854
7108
  var COMPILE_MANIFEST_RETRY_DELAYS_MS = [250, 1e3];
6855
7109
  var REGISTER_PLAY_ARTIFACTS_COMPILE_CONCURRENCY = 3;
6856
7110
  var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_COUNT = 3;
6857
7111
  var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_BYTES = 25e5;
6858
- var DEEPLINEAGENT_EXECUTE_TIMEOUT_MS = 15 * 60 * 1e3;
6859
7112
  function normalizePlayRunIntegrationMode(value) {
6860
7113
  if (value === "live" || value === "eval_stub" || value === "fixture") {
6861
7114
  return value;
@@ -7046,28 +7299,6 @@ function chunkRegisterPlayArtifacts(artifacts) {
7046
7299
  }
7047
7300
  return chunks;
7048
7301
  }
7049
- var APIFY_SYNC_DEFAULT_TIMEOUT_MS = 3e5;
7050
- var APIFY_SYNC_RESPONSE_GRACE_MS = 9e4;
7051
- function resolveToolExecuteTimeoutMs(toolId, input2) {
7052
- const normalized = toolId.trim().toLowerCase();
7053
- if (normalized === "apify_run_actor_sync") {
7054
- const requestedTimeoutMs = input2.timeoutMs ?? APIFY_SYNC_DEFAULT_TIMEOUT_MS;
7055
- if (typeof requestedTimeoutMs === "number" && Number.isFinite(requestedTimeoutMs) && requestedTimeoutMs > 0) {
7056
- return Math.floor(requestedTimeoutMs) + APIFY_SYNC_RESPONSE_GRACE_MS;
7057
- }
7058
- }
7059
- const theirstackTimeoutMs = resolveTheirstackClientTimeoutMs(
7060
- normalized,
7061
- input2
7062
- );
7063
- if (theirstackTimeoutMs !== null) return theirstackTimeoutMs;
7064
- const waterfallTimeoutMs = resolveWaterfallClientTimeoutMs(normalized);
7065
- if (waterfallTimeoutMs !== null) return waterfallTimeoutMs;
7066
- if (usesExtendedBetterContactLauncherBudget(normalized)) {
7067
- return BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS;
7068
- }
7069
- return normalized === "deeplineagent" || normalized === "deeplineagent_deeplineagent" || normalized === "ai_inference" || normalized === "deeplineagent_ai_inference" || normalized === "ai_evaluate" || normalized === "deeplineagent_ai_evaluate" || normalized === "aiinference" ? DEEPLINEAGENT_EXECUTE_TIMEOUT_MS : void 0;
7070
- }
7071
7302
  var RUNS_FAILED_LOG_LIMIT = 20;
7072
7303
  var RUN_LOGS_PAGE_LIMIT = 1e3;
7073
7304
  function requireTargetBillingIdempotencyKey(value) {
@@ -7081,53 +7312,9 @@ function requireTargetBillingIdempotencyKey(value) {
7081
7312
  }
7082
7313
  return normalized;
7083
7314
  }
7084
- function isRecord7(value) {
7315
+ function isRecord8(value) {
7085
7316
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
7086
7317
  }
7087
- function materializeToolExecutionResponse(response) {
7088
- const toolResponse = response.toolResponse;
7089
- if (!toolResponse && isRecord7(response.result)) {
7090
- const legacyResult = response.result;
7091
- if (Object.prototype.hasOwnProperty.call(legacyResult, "data")) {
7092
- const legacyMeta = isRecord7(legacyResult.meta) ? legacyResult.meta : void 0;
7093
- return {
7094
- ...response,
7095
- toolResponse: {
7096
- raw: legacyResult.data,
7097
- ...legacyMeta ? { meta: legacyMeta } : {}
7098
- }
7099
- };
7100
- }
7101
- }
7102
- if (!toolResponse || Object.prototype.hasOwnProperty.call(toolResponse, "raw")) {
7103
- return response;
7104
- }
7105
- const rawV2 = toolResponse.rawV2;
7106
- const view = toolResponse.view;
7107
- const providerMeta = providerMetaFromToolResponseRawV2(
7108
- rawV2,
7109
- view ?? "rawV2"
7110
- );
7111
- const responseMeta = isRecord7(toolResponse.responseMeta) ? toolResponse.responseMeta : void 0;
7112
- return {
7113
- ...response,
7114
- toolResponse: {
7115
- ...toolResponse,
7116
- raw: legacyRawFromToolResponseRawV2(
7117
- rawV2,
7118
- view ?? "rawV2",
7119
- responseMeta
7120
- ),
7121
- ...toolResponse.meta || providerMeta || responseMeta ? {
7122
- meta: {
7123
- ...toolResponse.meta ?? {},
7124
- ...providerMeta ?? {},
7125
- ...responseMeta ?? {}
7126
- }
7127
- } : {}
7128
- }
7129
- };
7130
- }
7131
7318
  function isPrebuiltPlayDescription(play) {
7132
7319
  return play.origin === "prebuilt" || play.ownerType === "deepline";
7133
7320
  }
@@ -7157,10 +7344,10 @@ function normalizePlayStatus(raw) {
7157
7344
  return {
7158
7345
  ...raw,
7159
7346
  runId,
7160
- ...isRecord7(legacyOverview) ? {
7347
+ ...isRecord8(legacyOverview) ? {
7161
7348
  overview: legacyOverview
7162
7349
  } : {},
7163
- ...isRecord7(runStatus) ? { runStatus } : {},
7350
+ ...isRecord8(runStatus) ? { runStatus } : {},
7164
7351
  ...runPackage ? {
7165
7352
  package: runPackage,
7166
7353
  outputs: runPackage.outputs
@@ -7299,7 +7486,7 @@ function updatePlayLiveStatusState(state, event) {
7299
7486
  }
7300
7487
  const runId = typeof payload.runId === "string" && payload.runId ? payload.runId : isPlayRunPackage(payload) ? payload.run.id : state.runId;
7301
7488
  const status = normalizeLiveStatus(payload.status) ?? (isPlayRunPackage(payload) ? normalizeLiveStatus(payload.run.status) : null) ?? state.status;
7302
- const progressPayload = isRecord7(payload.progress) ? payload.progress : {};
7489
+ const progressPayload = isRecord8(payload.progress) ? payload.progress : {};
7303
7490
  if (event.type === "play.run.final_status" && state.logs.length === 0 && state.lastLogSeq === 0) {
7304
7491
  const payloadLogs = readStringArray(payload.logs);
7305
7492
  const progressLogs = readStringArray(progressPayload.logs);
@@ -7348,6 +7535,7 @@ function playRunResultFromStatus(status, startedAt, fallbackRunId) {
7348
7535
  }
7349
7536
  var DeeplineClient = class _DeeplineClient {
7350
7537
  http;
7538
+ toolCalls;
7351
7539
  config;
7352
7540
  /** Canonical run lifecycle namespace backed by `/api/v2/runs`. */
7353
7541
  runs;
@@ -7371,6 +7559,7 @@ var DeeplineClient = class _DeeplineClient {
7371
7559
  constructor(options) {
7372
7560
  this.config = resolveConfig(options);
7373
7561
  this.http = new HttpClient(this.config);
7562
+ this.toolCalls = new ToolCalls(this.http, this.config.timeout);
7374
7563
  this.runs = {
7375
7564
  get: (runId, options2) => this.getRunStatus(runId, options2),
7376
7565
  status: (runId) => this.getRunLifecycleStatus(runId),
@@ -7498,9 +7687,9 @@ var DeeplineClient = class _DeeplineClient {
7498
7687
  return fields2.length > 0 ? { fields: fields2 } : schema;
7499
7688
  }
7500
7689
  schemaMetadata(schema, key) {
7501
- if (!isRecord7(schema)) return null;
7690
+ if (!isRecord8(schema)) return null;
7502
7691
  const value = schema[key];
7503
- return isRecord7(value) ? value : null;
7692
+ return isRecord8(value) ? value : null;
7504
7693
  }
7505
7694
  playRunCommand(play, options) {
7506
7695
  const target = play.reference || play.name;
@@ -7555,7 +7744,7 @@ var DeeplineClient = class _DeeplineClient {
7555
7744
  aliases,
7556
7745
  inputSchema: options?.compact ? this.compactSchema(play.inputSchema) : play.inputSchema ?? null,
7557
7746
  outputSchema: options?.compact ? this.compactSchema(play.outputSchema) : play.outputSchema ?? null,
7558
- staticPipeline: isRecord7(play.staticPipeline) ? play.staticPipeline : isRecord7(play.currentRevision?.staticPipeline) ? play.currentRevision.staticPipeline : isRecord7(play.liveRevision?.staticPipeline) ? play.liveRevision.staticPipeline : null,
7747
+ staticPipeline: isRecord8(play.staticPipeline) ? play.staticPipeline : isRecord8(play.currentRevision?.staticPipeline) ? play.currentRevision.staticPipeline : isRecord8(play.liveRevision?.staticPipeline) ? play.liveRevision.staticPipeline : null,
7559
7748
  ...csvInput ? { csvInput } : {},
7560
7749
  ...rowOutputSchema ? { rowOutputSchema } : {},
7561
7750
  runCommand: runCommand2,
@@ -7775,183 +7964,11 @@ var DeeplineClient = class _DeeplineClient {
7775
7964
  * Deepline execution envelope.
7776
7965
  */
7777
7966
  async executeTool(toolId, input2, options) {
7778
- const inputSnapshot = JSON.parse(JSON.stringify(input2));
7779
- const metadataSnapshot = options?.metadata ? JSON.parse(JSON.stringify(options.metadata)) : void 0;
7780
- const idempotencyKey = options?.idempotencyKey ?? (options?.recover ? crypto.randomUUID() : void 0);
7781
- if (idempotencyKey !== void 0) {
7782
- validateExecutionIdempotencyKey(idempotencyKey);
7783
- if (options?.recoveryTimeoutMs !== void 0 && (!Number.isFinite(options.recoveryTimeoutMs) || options.recoveryTimeoutMs < 0)) {
7784
- throw new DeeplineError(
7785
- "recoveryTimeoutMs must be a finite, non-negative number.",
7786
- void 0,
7787
- "IDEMPOTENCY_KEY_INVALID"
7788
- );
7789
- }
7790
- await options?.onExecution?.({ idempotencyKey });
7791
- const timeoutMs2 = options?.timeout ?? resolveToolExecuteTimeoutMs(toolId, inputSnapshot);
7792
- await this.lookupExecutionByKey(idempotencyKey, timeoutMs2);
7793
- }
7794
- const timeoutMs = options?.timeout ?? resolveToolExecuteTimeoutMs(toolId, inputSnapshot);
7795
- const isApifySync = toolId.trim().toLowerCase() === "apify_run_actor_sync";
7796
- const headers = {
7797
- [EXECUTE_RESPONSE_CONTRACT_HEADER]: RAW_V2_EXECUTE_RESPONSE_CONTRACT,
7798
- ...isApifySync ? { "X-Deepline-Apify-Sync-Response-Budget": "extended-v1" } : {},
7799
- [TOOL_EXECUTION_ERROR_SCHEMA_HEADER]: String(
7800
- TOOL_EXECUTION_ERROR_SCHEMA_VERSION
7801
- ),
7802
- ...options?.includeToolMetadata ? { [INCLUDE_TOOL_METADATA_HEADER]: "true" } : {},
7803
- [EXECUTE_RESPONSE_INTENT_HEADER]: options?.responseIntent ?? "raw",
7804
- ...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {},
7805
- ...options?.searchRef ? { "x-deepline-search-ref": options.searchRef } : {}
7806
- };
7807
- const request = (requestTimeoutMs) => this.http.post(
7808
- `/api/v2/integrations/${encodeURIComponent(toolId)}/execute`,
7809
- {
7810
- payload: inputSnapshot,
7811
- ...metadataSnapshot ? { metadata: metadataSnapshot } : {}
7812
- },
7813
- headers,
7814
- {
7815
- timeout: requestTimeoutMs,
7816
- maxRetries: idempotencyKey ? 0 : options?.maxRetries ?? 0,
7817
- retryApiErrors: options?.retryApiErrors === true,
7818
- exactUrlOnly: true,
7819
- toolId,
7820
- idempotencyKey
7821
- }
7822
- );
7823
- let response;
7824
- let recoveryDeadline = null;
7825
- const recoveryTimeoutMs = options?.recoveryTimeoutMs ?? DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS;
7826
- let retryDelayMs = 1e3;
7827
- const recoveryTimeoutError = () => executionRecoveryError({
7828
- toolId,
7829
- idempotencyKey,
7830
- code: "EXECUTION_RECOVERY_TIMEOUT",
7831
- message: `Execution recovery for ${idempotencyKey} did not finish before the recovery timeout. Inspect client.executions.getByKey() and resume with the same idempotency key.`
7832
- });
7833
- const waitForRecoveryRetry = async (deadline) => {
7834
- const remainingMs = deadline - Date.now();
7835
- if (remainingMs <= 0) throw recoveryTimeoutError();
7836
- await new Promise(
7837
- (resolve22) => setTimeout(resolve22, Math.min(retryDelayMs, remainingMs))
7838
- );
7839
- retryDelayMs = Math.min(retryDelayMs * 2, 5e3);
7840
- };
7841
- const lookupDuringRecovery = async () => {
7842
- while (true) {
7843
- const remainingMs = recoveryDeadline - Date.now();
7844
- if (remainingMs <= 0) throw recoveryTimeoutError();
7845
- try {
7846
- return await this.lookupExecutionByKey(
7847
- idempotencyKey,
7848
- timeoutWithinRecoveryBudget(
7849
- timeoutMs,
7850
- this.config.timeout,
7851
- remainingMs
7852
- )
7853
- );
7854
- } catch (error) {
7855
- if (!isRecoverableExecutionLookupError(error)) throw error;
7856
- await waitForRecoveryRetry(recoveryDeadline);
7857
- }
7858
- }
7859
- };
7860
- while (true) {
7861
- const remainingMs = recoveryDeadline === null ? null : recoveryDeadline - Date.now();
7862
- if (remainingMs !== null && remainingMs <= 0) {
7863
- throw recoveryTimeoutError();
7864
- }
7865
- try {
7866
- response = await request(
7867
- remainingMs === null ? timeoutMs : timeoutWithinRecoveryBudget(
7868
- timeoutMs,
7869
- this.config.timeout,
7870
- remainingMs
7871
- )
7872
- );
7873
- if (getExecutionRecoveryState(response) === "outcome_unknown") {
7874
- if (!idempotencyKey) break;
7875
- throw executionRecoveryError({
7876
- toolId,
7877
- idempotencyKey,
7878
- code: "EXECUTION_OUTCOME_UNKNOWN",
7879
- message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
7880
- });
7881
- }
7882
- if (!idempotencyKey || !isExecutionInProgressResponse(response)) {
7883
- break;
7884
- }
7885
- if (recoveryDeadline === null) {
7886
- recoveryDeadline = Date.now() + recoveryTimeoutMs;
7887
- }
7888
- } catch (error) {
7889
- if (idempotencyKey && error instanceof DeeplineError && error.code === "EXECUTION_OUTCOME_UNKNOWN") {
7890
- throw executionRecoveryError({
7891
- toolId,
7892
- idempotencyKey,
7893
- code: "EXECUTION_OUTCOME_UNKNOWN",
7894
- message: error.message
7895
- });
7896
- }
7897
- if (!idempotencyKey || !isRecoverableExecutionAttemptError(error)) {
7898
- throw error;
7899
- }
7900
- if (recoveryDeadline === null) {
7901
- recoveryDeadline = Date.now() + recoveryTimeoutMs;
7902
- }
7903
- }
7904
- await waitForRecoveryRetry(recoveryDeadline);
7905
- const recovered = await lookupDuringRecovery();
7906
- if (getExecutionRecoveryState(recovered) === "outcome_unknown") {
7907
- throw executionRecoveryError({
7908
- toolId,
7909
- idempotencyKey,
7910
- code: "EXECUTION_OUTCOME_UNKNOWN",
7911
- message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
7912
- });
7913
- }
7914
- }
7915
- const materialized = materializeToolExecutionResponse(response);
7916
- return idempotencyKey ? { ...materialized, idempotencyKey } : materialized;
7967
+ return this.toolCalls.call(toolId, input2, options);
7917
7968
  }
7918
7969
  /** Read the durable state of a keyed tool execution. */
7919
7970
  async getExecutionByKey(idempotencyKey) {
7920
- validateExecutionIdempotencyKey(idempotencyKey);
7921
- const result = await this.lookupExecutionByKey(idempotencyKey);
7922
- if (!result) {
7923
- throw new DeeplineError(
7924
- `No execution exists for idempotency key ${idempotencyKey}.`,
7925
- 404,
7926
- "EXECUTION_NOT_FOUND"
7927
- );
7928
- }
7929
- return result;
7930
- }
7931
- async lookupExecutionByKey(idempotencyKey, timeoutMs) {
7932
- validateExecutionIdempotencyKey(idempotencyKey);
7933
- let supported = false;
7934
- const result = await this.http.get(
7935
- `/api/v2/executions/by-key/${encodeURIComponent(idempotencyKey)}`,
7936
- {
7937
- exactUrlOnly: true,
7938
- maxRetries: 0,
7939
- timeout: timeoutMs,
7940
- idempotencyKey,
7941
- allowNotFound: true,
7942
- onResponse: (response) => {
7943
- supported = response.headers.get("X-Deepline-Idempotency-Supported") === "true";
7944
- }
7945
- }
7946
- );
7947
- if (!supported) {
7948
- throw new DeeplineError(
7949
- "This Deepline server does not support recoverable tool executions; no tool was dispatched.",
7950
- 422,
7951
- "IDEMPOTENCY_NOT_SUPPORTED"
7952
- );
7953
- }
7954
- return result;
7971
+ return this.toolCalls.getByKey(idempotencyKey);
7955
7972
  }
7956
7973
  /** Public recovery namespace. */
7957
7974
  get executions() {
@@ -8759,10 +8776,10 @@ var DeeplineClient = class _DeeplineClient {
8759
8776
  const responseRunStatus = isPlayRunPackage(response) ? response.runStatus : isPlayRunPackage(response.package) ? response.package.runStatus : response.runStatus;
8760
8777
  const responseOverview = isPlayRunPackage(response) ? response.overview : isPlayRunPackage(response.package) ? response.package.overview : response.overview;
8761
8778
  const status = normalizePlayStatus(response);
8762
- if (isRecord7(responseRunStatus)) {
8779
+ if (isRecord8(responseRunStatus)) {
8763
8780
  status.runStatus = responseRunStatus;
8764
8781
  }
8765
- if (isRecord7(responseOverview)) {
8782
+ if (isRecord8(responseOverview)) {
8766
8783
  status.overview = responseOverview;
8767
8784
  }
8768
8785
  if (options?.failedLogs !== true || status.status !== "failed") {
@@ -14567,24 +14584,24 @@ function sanitizeCsvProjectionInfo(input2) {
14567
14584
  const rows = input2.rows.map(stripCsvProjectionFields);
14568
14585
  return { rows, columns };
14569
14586
  }
14570
- function isRecord8(value) {
14587
+ function isRecord9(value) {
14571
14588
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
14572
14589
  }
14573
14590
  function isSerializedDataset(value) {
14574
- return isRecord8(value) && value.kind === "dataset" && typeof value.count === "number" && (Array.isArray(value.preview) || typeof value.tableNamespace === "string");
14591
+ return isRecord9(value) && value.kind === "dataset" && typeof value.count === "number" && (Array.isArray(value.preview) || typeof value.tableNamespace === "string");
14575
14592
  }
14576
14593
  function isPackagedDatasetOutput(value) {
14577
- return isRecord8(value) && value.kind === "dataset" && isRecord8(value.preview) && Array.isArray(value.preview.rows);
14594
+ return isRecord9(value) && value.kind === "dataset" && isRecord9(value.preview) && Array.isArray(value.preview.rows);
14578
14595
  }
14579
14596
  function hasCurrentTableExport(value) {
14580
- if (!isRecord8(value) || !isRecord8(value.actions)) return false;
14597
+ if (!isRecord9(value) || !isRecord9(value.actions)) return false;
14581
14598
  const exportCsv = value.actions.exportCsv;
14582
- return isRecord8(exportCsv) && isRecord8(exportCsv.scope) && exportCsv.scope.kind === "database" && exportCsv.scope.mutability === "current";
14599
+ return isRecord9(exportCsv) && isRecord9(exportCsv.scope) && exportCsv.scope.kind === "database" && exportCsv.scope.mutability === "current";
14583
14600
  }
14584
14601
  function currentTableQueryCommand(value) {
14585
- if (!isRecord8(value) || !isRecord8(value.actions)) return void 0;
14602
+ if (!isRecord9(value) || !isRecord9(value.actions)) return void 0;
14586
14603
  const query = value.actions.queryCurrentTable;
14587
- const command = isRecord8(query) ? query.command : void 0;
14604
+ const command = isRecord9(query) ? query.command : void 0;
14588
14605
  return typeof command === "string" && command.trim() ? command.trim() : void 0;
14589
14606
  }
14590
14607
  function recoveredReturnPaths(value) {
@@ -14603,7 +14620,7 @@ function pathParts(path) {
14603
14620
  function valueAtPath(root, path) {
14604
14621
  let cursor = root;
14605
14622
  for (const part of pathParts(path)) {
14606
- if (!isRecord8(cursor)) {
14623
+ if (!isRecord9(cursor)) {
14607
14624
  return void 0;
14608
14625
  }
14609
14626
  cursor = cursor[part];
@@ -14611,17 +14628,17 @@ function valueAtPath(root, path) {
14611
14628
  return cursor;
14612
14629
  }
14613
14630
  function totalRowsForDataset(result, datasetPath) {
14614
- const metadata = isRecord8(result._metadata) ? result._metadata : null;
14631
+ const metadata = isRecord9(result._metadata) ? result._metadata : null;
14615
14632
  const parentPath = datasetPath.split(".").slice(0, -1).join(".");
14616
14633
  const parent = parentPath ? valueAtPath({ result }, parentPath) : result;
14617
- return metadata?.totalRows ?? metadata?.rowCount ?? metadata?.count ?? (isRecord8(parent) ? parent.totalRows ?? parent.rowCount ?? parent.count : void 0) ?? result.totalRows ?? result.rowCount ?? result.count;
14634
+ return metadata?.totalRows ?? metadata?.rowCount ?? metadata?.count ?? (isRecord9(parent) ? parent.totalRows ?? parent.rowCount ?? parent.count : void 0) ?? result.totalRows ?? result.rowCount ?? result.count;
14618
14635
  }
14619
14636
  function rowArray(value) {
14620
14637
  if (!Array.isArray(value)) {
14621
14638
  return null;
14622
14639
  }
14623
14640
  const rows = value.filter(
14624
- (row) => isRecord8(row)
14641
+ (row) => isRecord9(row)
14625
14642
  );
14626
14643
  return rows.length === value.length ? rows : null;
14627
14644
  }
@@ -14645,7 +14662,7 @@ function inferColumns(rows) {
14645
14662
  return columns;
14646
14663
  }
14647
14664
  function columnsFromDatasetSummary(summary) {
14648
- if (!isRecord8(summary) || !isRecord8(summary.columnStats)) {
14665
+ if (!isRecord9(summary) || !isRecord9(summary.columnStats)) {
14649
14666
  return [];
14650
14667
  }
14651
14668
  return Object.keys(summary.columnStats).filter((column) => column);
@@ -14702,7 +14719,7 @@ function canonicalRowsInfoFromCandidate(input2) {
14702
14719
  candidate.value.recoveredReturnPaths
14703
14720
  )
14704
14721
  } : {},
14705
- ...isRecord8(candidate.value.exportUnavailable) && (candidate.value.exportUnavailable.reason === "empty_dataset" || candidate.value.exportUnavailable.reason === "shared_table_namespace" || candidate.value.exportUnavailable.reason === "returned_dataset_not_persisted") ? {
14722
+ ...isRecord9(candidate.value.exportUnavailable) && (candidate.value.exportUnavailable.reason === "empty_dataset" || candidate.value.exportUnavailable.reason === "shared_table_namespace" || candidate.value.exportUnavailable.reason === "returned_dataset_not_persisted") ? {
14706
14723
  exportUnavailableReason: candidate.value.exportUnavailable.reason,
14707
14724
  ...typeof candidate.value.exportUnavailable.message === "string" ? {
14708
14725
  exportUnavailableMessage: candidate.value.exportUnavailable.message
@@ -14750,7 +14767,7 @@ function collectDatasetCandidates(input2) {
14750
14767
  });
14751
14768
  return;
14752
14769
  }
14753
- if (!isRecord8(input2.value)) {
14770
+ if (!isRecord9(input2.value)) {
14754
14771
  return;
14755
14772
  }
14756
14773
  for (const [key, child] of Object.entries(input2.value)) {
@@ -14767,12 +14784,12 @@ function collectDatasetCandidates(input2) {
14767
14784
  }
14768
14785
  }
14769
14786
  function collectCanonicalRowsInfos(statusOrResult) {
14770
- const root = isRecord8(statusOrResult) ? statusOrResult : null;
14771
- const result = isRecord8(root?.result) ? root.result : root;
14787
+ const root = isRecord9(statusOrResult) ? statusOrResult : null;
14788
+ const result = isRecord9(root?.result) ? root.result : root;
14772
14789
  if (!result) {
14773
14790
  return [];
14774
14791
  }
14775
- const metadata = isRecord8(result._metadata) ? result._metadata : null;
14792
+ const metadata = isRecord9(result._metadata) ? result._metadata : null;
14776
14793
  const totalFromMetadata = metadata?.totalRows ?? metadata?.rowCount ?? metadata?.count;
14777
14794
  const candidates = [
14778
14795
  {
@@ -14796,8 +14813,8 @@ function collectCanonicalRowsInfos(statusOrResult) {
14796
14813
  total: totalFromMetadata ?? result.totalRows ?? result.rowCount ?? result.count
14797
14814
  }
14798
14815
  ];
14799
- if (isRecord8(result.output)) {
14800
- const outputMetadata = isRecord8(result.output._metadata) ? result.output._metadata : null;
14816
+ if (isRecord9(result.output)) {
14817
+ const outputMetadata = isRecord9(result.output._metadata) ? result.output._metadata : null;
14801
14818
  const outputTotalFromMetadata = outputMetadata?.totalRows ?? outputMetadata?.rowCount ?? outputMetadata?.count;
14802
14819
  candidates.push(
14803
14820
  {
@@ -14824,14 +14841,14 @@ function collectCanonicalRowsInfos(statusOrResult) {
14824
14841
  }
14825
14842
  if (Array.isArray(result.steps)) {
14826
14843
  result.steps.forEach((step, index) => {
14827
- if (!isRecord8(step) || !isRecord8(step.output)) {
14844
+ if (!isRecord9(step) || !isRecord9(step.output)) {
14828
14845
  return;
14829
14846
  }
14830
14847
  const source = typeof step.output.path === "string" ? step.output.path : typeof step.id === "string" ? `steps.${step.id}.output` : `steps.${index}.output`;
14831
14848
  candidates.push({
14832
14849
  source,
14833
14850
  value: step.output,
14834
- total: step.output.rowCount ?? (isRecord8(step.output.preview) ? step.output.preview.totalRows : void 0) ?? (isRecord8(step.progress) ? step.progress.total : void 0)
14851
+ total: step.output.rowCount ?? (isRecord9(step.output.preview) ? step.output.preview.totalRows : void 0) ?? (isRecord9(step.progress) ? step.progress.total : void 0)
14835
14852
  });
14836
14853
  });
14837
14854
  }
@@ -14859,15 +14876,15 @@ function collectCanonicalRowsInfos(statusOrResult) {
14859
14876
  return infos;
14860
14877
  }
14861
14878
  function collectPackagedDatasetCandidates(statusOrResult) {
14862
- const root = isRecord8(statusOrResult) ? statusOrResult : null;
14879
+ const root = isRecord9(statusOrResult) ? statusOrResult : null;
14863
14880
  if (!root) {
14864
14881
  return [];
14865
14882
  }
14866
- const pkg = isRecord8(root.package) ? root.package : root;
14883
+ const pkg = isRecord9(root.package) ? root.package : root;
14867
14884
  const datasets = Array.isArray(pkg.datasets) ? pkg.datasets : [];
14868
14885
  const candidates = [];
14869
14886
  for (const output2 of datasets) {
14870
- if (!isRecord8(output2) || !isPackagedDatasetOutput(output2)) {
14887
+ if (!isRecord9(output2) || !isPackagedDatasetOutput(output2)) {
14871
14888
  continue;
14872
14889
  }
14873
14890
  const source = typeof output2.path === "string" && output2.path.trim() ? output2.path.trim() : null;
@@ -14877,18 +14894,18 @@ function collectPackagedDatasetCandidates(statusOrResult) {
14877
14894
  candidates.push({
14878
14895
  source,
14879
14896
  value: output2,
14880
- total: output2.rowCount ?? (isRecord8(output2.preview) ? output2.preview.totalRows : void 0)
14897
+ total: output2.rowCount ?? (isRecord9(output2.preview) ? output2.preview.totalRows : void 0)
14881
14898
  });
14882
14899
  }
14883
14900
  return candidates;
14884
14901
  }
14885
14902
  function collectPackagedStepDatasetCandidates(statusOrResult) {
14886
- const root = isRecord8(statusOrResult) ? statusOrResult : null;
14903
+ const root = isRecord9(statusOrResult) ? statusOrResult : null;
14887
14904
  if (!root) return [];
14888
- const pkg = isRecord8(root.package) ? root.package : root;
14905
+ const pkg = isRecord9(root.package) ? root.package : root;
14889
14906
  const steps = Array.isArray(pkg.steps) ? pkg.steps : [];
14890
14907
  return steps.flatMap((step) => {
14891
- if (!isRecord8(step) || !isPackagedDatasetOutput(step.output)) return [];
14908
+ if (!isRecord9(step) || !isPackagedDatasetOutput(step.output)) return [];
14892
14909
  const source = typeof step.output.path === "string" && step.output.path.trim() ? step.output.path.trim() : null;
14893
14910
  return source ? [
14894
14911
  {
@@ -14900,8 +14917,8 @@ function collectPackagedStepDatasetCandidates(statusOrResult) {
14900
14917
  });
14901
14918
  }
14902
14919
  function collectSerializedDatasetRowsInfos(statusOrResult) {
14903
- const root = isRecord8(statusOrResult) ? statusOrResult : null;
14904
- const result = isRecord8(root?.result) ? root.result : root;
14920
+ const root = isRecord9(statusOrResult) ? statusOrResult : null;
14921
+ const result = isRecord9(root?.result) ? root.result : root;
14905
14922
  const candidates = [];
14906
14923
  if (result) {
14907
14924
  collectDatasetCandidates({
@@ -14909,7 +14926,7 @@ function collectSerializedDatasetRowsInfos(statusOrResult) {
14909
14926
  path: "result",
14910
14927
  output: candidates
14911
14928
  });
14912
- if (isRecord8(result.output)) {
14929
+ if (isRecord9(result.output)) {
14913
14930
  collectDatasetCandidates({
14914
14931
  value: result.output,
14915
14932
  path: "result",
@@ -14992,13 +15009,13 @@ function summarizeSampleValue(value, depth = 0) {
14992
15009
  if (typeof parsed === "number" || typeof parsed === "boolean") return parsed;
14993
15010
  if (depth >= 3) {
14994
15011
  if (Array.isArray(parsed)) return [];
14995
- if (isRecord8(parsed)) return {};
15012
+ if (isRecord9(parsed)) return {};
14996
15013
  return compactScalar(parsed);
14997
15014
  }
14998
15015
  if (Array.isArray(parsed)) {
14999
15016
  return parsed.slice(0, 3).map((item) => summarizeSampleValue(item, depth + 1));
15000
15017
  }
15001
- if (isRecord8(parsed)) {
15018
+ if (isRecord9(parsed)) {
15002
15019
  const out = {};
15003
15020
  for (const [key, nested] of Object.entries(parsed)) {
15004
15021
  if (["__dl", "meta", "metadata"].includes(key)) {
@@ -15029,7 +15046,7 @@ function compactCell(value) {
15029
15046
  }
15030
15047
  return `[${parsed.length} items]`;
15031
15048
  }
15032
- if (isRecord8(parsed)) {
15049
+ if (isRecord9(parsed)) {
15033
15050
  for (const key of ["matched_result", "output"]) {
15034
15051
  if (parsed[key] !== null && parsed[key] !== void 0 && parsed[key] !== "") {
15035
15052
  return compactCell(parsed[key]);
@@ -16424,17 +16441,17 @@ function parsePositiveInteger2(value, flagName) {
16424
16441
  }
16425
16442
  return parsed;
16426
16443
  }
16427
- function isRecord9(value) {
16444
+ function isRecord10(value) {
16428
16445
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
16429
16446
  }
16430
16447
  function stringValue(value) {
16431
16448
  return typeof value === "string" ? value.trim() : "";
16432
16449
  }
16433
16450
  function extractionEntries(value) {
16434
- if (Array.isArray(value)) return value.filter(isRecord9);
16435
- if (!isRecord9(value)) return [];
16451
+ if (Array.isArray(value)) return value.filter(isRecord10);
16452
+ if (!isRecord10(value)) return [];
16436
16453
  return Object.entries(value).map(
16437
- ([name, entry]) => isRecord9(entry) ? { name, ...entry } : { name }
16454
+ ([name, entry]) => isRecord10(entry) ? { name, ...entry } : { name }
16438
16455
  );
16439
16456
  }
16440
16457
  var PlayBootstrapError = class extends Error {
@@ -16995,7 +17012,7 @@ function readCsvSampleRows(sample) {
16995
17012
  relax_column_count: true,
16996
17013
  trim: true
16997
17014
  });
16998
- return Array.isArray(parsedRows) ? parsedRows.filter(isRecord9) : [];
17015
+ return Array.isArray(parsedRows) ? parsedRows.filter(isRecord10) : [];
16999
17016
  }
17000
17017
  function readSourceCsvColumnSpecs(csvPath) {
17001
17018
  const sample = readCsvSample(csvPath);
@@ -17028,16 +17045,16 @@ function packagedCsvPathForPlay(csvPath) {
17028
17045
  return portablePath.startsWith(".") ? portablePath : `./${portablePath}`;
17029
17046
  }
17030
17047
  function getterNamesFromTool(tool, kind) {
17031
- const usageGuidance = isRecord9(tool?.usageGuidance) ? tool.usageGuidance : {};
17032
- const resultGuidance = isRecord9(usageGuidance.toolExecutionResult) ? usageGuidance.toolExecutionResult : isRecord9(usageGuidance.tool_execution_result) ? usageGuidance.tool_execution_result : {};
17048
+ const usageGuidance = isRecord10(tool?.usageGuidance) ? tool.usageGuidance : {};
17049
+ const resultGuidance = isRecord10(usageGuidance.toolExecutionResult) ? usageGuidance.toolExecutionResult : isRecord10(usageGuidance.tool_execution_result) ? usageGuidance.tool_execution_result : {};
17033
17050
  const key = kind === "list" ? "extractedLists" : "extractedValues";
17034
17051
  const snakeKey = kind === "list" ? "extracted_lists" : "extracted_values";
17035
17052
  return extractionEntries(resultGuidance[key] ?? resultGuidance[snakeKey]).map((entry) => stringValue(entry.name)).filter(Boolean);
17036
17053
  }
17037
17054
  function targetGettersFromTool(tool) {
17038
- const record3 = isRecord9(tool) ? tool : {};
17055
+ const record3 = isRecord10(tool) ? tool : {};
17039
17056
  const raw = record3.targetGetters ?? record3.target_getters;
17040
- if (!isRecord9(raw)) return {};
17057
+ if (!isRecord10(raw)) return {};
17041
17058
  const entries = [];
17042
17059
  for (const [target, value] of Object.entries(raw)) {
17043
17060
  const paths = Array.isArray(value) ? value.map((path) => typeof path === "string" ? path.trim() : "").filter(Boolean) : [];
@@ -17058,10 +17075,10 @@ function listRowCandidateKeysFromTool(tool) {
17058
17075
  return [...keys].sort();
17059
17076
  }
17060
17077
  function inputPropertyNames(schema) {
17061
- if (!isRecord9(schema)) return [];
17062
- if (isRecord9(schema.properties)) return Object.keys(schema.properties);
17078
+ if (!isRecord10(schema)) return [];
17079
+ if (isRecord10(schema.properties)) return Object.keys(schema.properties);
17063
17080
  if (Array.isArray(schema.fields)) {
17064
- return schema.fields.filter(isRecord9).map((field) => stringValue(field.name)).filter(Boolean);
17081
+ return schema.fields.filter(isRecord10).map((field) => stringValue(field.name)).filter(Boolean);
17065
17082
  }
17066
17083
  return [];
17067
17084
  }
@@ -17075,7 +17092,7 @@ function schemaFieldDetails(schema) {
17075
17092
  return { required, optional };
17076
17093
  }
17077
17094
  function jsonSchemaTypeExpression(schema) {
17078
- if (!isRecord9(schema)) return "unknown";
17095
+ if (!isRecord10(schema)) return "unknown";
17079
17096
  const type = schema.type;
17080
17097
  if (Array.isArray(type)) {
17081
17098
  return type.map((entry) => jsonSchemaTypeExpression({ ...schema, type: entry })).join(" | ");
@@ -17105,7 +17122,7 @@ function jsonSchemaTypeExpression(schema) {
17105
17122
  }
17106
17123
  }
17107
17124
  function objectPropertySchema(schema, property) {
17108
- return isRecord9(schema) && isRecord9(schema.properties) ? schema.properties[property] : null;
17125
+ return isRecord10(schema) && isRecord10(schema.properties) ? schema.properties[property] : null;
17109
17126
  }
17110
17127
  function playOutputHasField(schema, field) {
17111
17128
  return objectPropertySchema(schema, field) != null;
@@ -17281,14 +17298,14 @@ ${indent2.slice(2)}}`;
17281
17298
  }
17282
17299
  function requiredPlayInputFields(play) {
17283
17300
  const schema = play?.inputSchema;
17284
- if (!isRecord9(schema)) return [];
17301
+ if (!isRecord10(schema)) return [];
17285
17302
  if (Array.isArray(schema.required)) {
17286
17303
  return schema.required.filter(
17287
17304
  (value) => typeof value === "string"
17288
17305
  );
17289
17306
  }
17290
17307
  if (Array.isArray(schema.fields)) {
17291
- return schema.fields.filter(isRecord9).filter(
17308
+ return schema.fields.filter(isRecord10).filter(
17292
17309
  (field) => field.required === true && typeof field.name === "string"
17293
17310
  ).map((field) => String(field.name));
17294
17311
  }
@@ -17469,7 +17486,7 @@ function validateBootstrapRoutes(input2) {
17469
17486
  }
17470
17487
  }
17471
17488
  function staticPipelineSubsteps(pipeline) {
17472
- if (!isRecord9(pipeline)) return [];
17489
+ if (!isRecord10(pipeline)) return [];
17473
17490
  return [
17474
17491
  ...extractionEntries(pipeline.stages),
17475
17492
  ...extractionEntries(pipeline.substeps)
@@ -17477,7 +17494,7 @@ function staticPipelineSubsteps(pipeline) {
17477
17494
  }
17478
17495
  function playUsesMapBackedRuntime(play) {
17479
17496
  const pipeline = play?.staticPipeline;
17480
- if (!isRecord9(pipeline)) return false;
17497
+ if (!isRecord10(pipeline)) return false;
17481
17498
  if (stringValue(pipeline.tableNamespace)) return true;
17482
17499
  return staticPipelineSubsteps(pipeline).some((substep) => {
17483
17500
  if (stringValue(substep.type) === "map") return true;
@@ -17486,7 +17503,7 @@ function playUsesMapBackedRuntime(play) {
17486
17503
  aliases: [],
17487
17504
  runCommand: "",
17488
17505
  examples: [],
17489
- staticPipeline: isRecord9(substep.pipeline) ? substep.pipeline : null
17506
+ staticPipeline: isRecord10(substep.pipeline) ? substep.pipeline : null
17490
17507
  });
17491
17508
  });
17492
17509
  }
@@ -28003,7 +28020,7 @@ function extractPlayValidationErrors(value) {
28003
28020
  if (value instanceof DeeplineError) {
28004
28021
  return extractPlayValidationErrors(value.details);
28005
28022
  }
28006
- if (!isRecord10(value)) {
28023
+ if (!isRecord11(value)) {
28007
28024
  return [];
28008
28025
  }
28009
28026
  const directErrors = stringArrayField(value, "errors");
@@ -28667,7 +28684,7 @@ function formatPlayRuntimeLimit(runtimeLimit) {
28667
28684
  if (seconds % 60 === 0) return `${seconds / 60} min`;
28668
28685
  return `${seconds} sec`;
28669
28686
  }
28670
- function isRecord10(value) {
28687
+ function isRecord11(value) {
28671
28688
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
28672
28689
  }
28673
28690
  function stringValue3(value) {
@@ -28677,14 +28694,14 @@ function asArray(value) {
28677
28694
  return Array.isArray(value) ? value : [];
28678
28695
  }
28679
28696
  function extractionEntries2(value) {
28680
- if (Array.isArray(value)) return value.filter(isRecord10);
28681
- if (!isRecord10(value)) return [];
28697
+ if (Array.isArray(value)) return value.filter(isRecord11);
28698
+ if (!isRecord11(value)) return [];
28682
28699
  return Object.entries(value).map(
28683
- ([name, entry]) => isRecord10(entry) ? { name, ...entry } : { name }
28700
+ ([name, entry]) => isRecord11(entry) ? { name, ...entry } : { name }
28684
28701
  );
28685
28702
  }
28686
28703
  function firstRawPath(entry) {
28687
- const details = isRecord10(entry.details) ? entry.details : {};
28704
+ const details = isRecord11(entry.details) ? entry.details : {};
28688
28705
  const paths = [
28689
28706
  ...asArray(details.rawToolOutputPaths),
28690
28707
  ...asArray(details.raw_tool_output_paths),
@@ -28702,12 +28719,12 @@ function checkHintRawPath(value) {
28702
28719
  function collectStaticPipelineToolIds(staticPipeline) {
28703
28720
  const seen = /* @__PURE__ */ new Set();
28704
28721
  const visitPipeline = (pipeline) => {
28705
- if (!isRecord10(pipeline)) return;
28722
+ if (!isRecord11(pipeline)) return;
28706
28723
  for (const step of [
28707
28724
  ...asArray(pipeline.stages),
28708
28725
  ...asArray(pipeline.substeps)
28709
28726
  ]) {
28710
- if (!isRecord10(step)) continue;
28727
+ if (!isRecord11(step)) continue;
28711
28728
  if (step.type === "tool") {
28712
28729
  const toolId = stringValue3(step.toolId) || stringValue3(step.tool);
28713
28730
  if (toolId) seen.add(toolId);
@@ -28721,9 +28738,9 @@ function collectStaticPipelineToolIds(staticPipeline) {
28721
28738
  return [...seen].sort();
28722
28739
  }
28723
28740
  function toolGetterHintFromMetadata(toolId, tool) {
28724
- const usageGuidance = isRecord10(tool.usageGuidance) ? tool.usageGuidance : {};
28725
- const resultGuidance = isRecord10(usageGuidance.toolExecutionResult) ? usageGuidance.toolExecutionResult : isRecord10(usageGuidance.tool_execution_result) ? usageGuidance.tool_execution_result : {};
28726
- const toolResponse = isRecord10(resultGuidance.toolResponse) ? resultGuidance.toolResponse : isRecord10(resultGuidance.tool_response) ? resultGuidance.tool_response : {};
28741
+ const usageGuidance = isRecord11(tool.usageGuidance) ? tool.usageGuidance : {};
28742
+ const resultGuidance = isRecord11(usageGuidance.toolExecutionResult) ? usageGuidance.toolExecutionResult : isRecord11(usageGuidance.tool_execution_result) ? usageGuidance.tool_execution_result : {};
28743
+ const toolResponse = isRecord11(resultGuidance.toolResponse) ? resultGuidance.toolResponse : isRecord11(resultGuidance.tool_response) ? resultGuidance.tool_response : {};
28727
28744
  const lists = extractionEntries2(
28728
28745
  resultGuidance.extractedLists ?? resultGuidance.extracted_lists
28729
28746
  ).map((entry) => ({
@@ -29086,7 +29103,7 @@ function artifactForProductionCompatibilityCheck(artifact) {
29086
29103
  "DEEPLINE_PROD_CHECK_AUTHORING_CONTRACT_EDITION must be a positive integer."
29087
29104
  );
29088
29105
  }
29089
- const compatibility = isRecord10(artifact.compatibility) ? artifact.compatibility : {};
29106
+ const compatibility = isRecord11(artifact.compatibility) ? artifact.compatibility : {};
29090
29107
  return {
29091
29108
  ...artifact,
29092
29109
  compatibility: {
@@ -34308,7 +34325,7 @@ function isMarkedTestAiInferenceCommand(command) {
34308
34325
  if (normalizeEnrichPlayRef(command.tool) !== "run_javascript") {
34309
34326
  return false;
34310
34327
  }
34311
- return isRecord11(command.payload) && command.payload[ENRICH_TEST_AI_INFERENCE_PAYLOAD_MARKER] === true;
34328
+ return isRecord12(command.payload) && command.payload[ENRICH_TEST_AI_INFERENCE_PAYLOAD_MARKER] === true;
34312
34329
  }
34313
34330
  function enrichDebugEnabled(env = process.env) {
34314
34331
  const raw = String(env.DEEPLINE_DEBUG_ENRICH ?? "").trim().toLowerCase();
@@ -34572,7 +34589,7 @@ function rewriteGeneratedPlayRerunForEnrich(status, enrichCommand) {
34572
34589
  if (Array.isArray(value)) {
34573
34590
  return value.map(rewrite);
34574
34591
  }
34575
- if (!isRecord11(value)) {
34592
+ if (!isRecord12(value)) {
34576
34593
  return value;
34577
34594
  }
34578
34595
  const next = Object.fromEntries(
@@ -34581,7 +34598,7 @@ function rewriteGeneratedPlayRerunForEnrich(status, enrichCommand) {
34581
34598
  key === "rerunCommand" && typeof entry === "string" ? enrichCommand : rewrite(entry)
34582
34599
  ])
34583
34600
  );
34584
- if (isRecord11(next.next) && typeof next.next.run === "string") {
34601
+ if (isRecord12(next.next) && typeof next.next.run === "string") {
34585
34602
  next.next = { ...next.next, run: enrichCommand };
34586
34603
  }
34587
34604
  return next;
@@ -35063,7 +35080,7 @@ async function resolveWatchedGeneratedPlayStatus(input2) {
35063
35080
  }
35064
35081
  return input2.client.runs.get(runId, { full: true });
35065
35082
  }
35066
- function isRecord11(value) {
35083
+ function isRecord12(value) {
35067
35084
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
35068
35085
  }
35069
35086
  async function captureStdout(run, options = {}) {
@@ -35315,15 +35332,15 @@ function readFirstEnrichDatasetActions(value) {
35315
35332
  return null;
35316
35333
  }
35317
35334
  const record3 = candidate;
35318
- const actions = isRecord11(record3.actions) ? record3.actions : null;
35319
- const currentQuery = isRecord11(actions?.queryCurrentTable) ? actions.queryCurrentTable : null;
35320
- const legacyQuery = isRecord11(actions?.query) ? actions.query : null;
35335
+ const actions = isRecord12(record3.actions) ? record3.actions : null;
35336
+ const currentQuery = isRecord12(actions?.queryCurrentTable) ? actions.queryCurrentTable : null;
35337
+ const legacyQuery = isRecord12(actions?.query) ? actions.query : null;
35321
35338
  const query = currentQuery?.kind === "deepline_db_query" ? currentQuery : legacyQuery?.kind === "deepline_db_query" ? legacyQuery : null;
35322
35339
  if (query?.kind === "deepline_db_query") {
35323
35340
  return {
35324
35341
  dataset: record3,
35325
35342
  query,
35326
- ...isRecord11(actions?.exportCsv) ? { exportCsv: actions.exportCsv } : {}
35343
+ ...isRecord12(actions?.exportCsv) ? { exportCsv: actions.exportCsv } : {}
35327
35344
  };
35328
35345
  }
35329
35346
  if (options.allowLegacy && record3.kind === "dataset" && typeof record3.queryDatasetCommand === "string" && record3.queryDatasetCommand.trim()) {
@@ -35376,7 +35393,7 @@ function enrichCustomerDbJson(input2) {
35376
35393
  const dataset = actions.dataset;
35377
35394
  const sql = actionStringField(query, "sql") ?? parseSqlFromDbQueryCommand(actions.queryDatasetCommand);
35378
35395
  const datasetPath = actionStringField(query, "datasetPath") ?? actionStringField(dataset, "path") ?? actionStringField(dataset, "tableNamespace");
35379
- const api = isRecord11(query.api) ? query.api : null;
35396
+ const api = isRecord12(query.api) ? query.api : null;
35380
35397
  const apiPath = actionStringField(api ?? {}, "path") ?? "/api/v2/db/query";
35381
35398
  const apiMethod = actionStringField(api ?? {}, "method") ?? "POST";
35382
35399
  if (!datasetPath) {
@@ -35445,11 +35462,11 @@ function sqlStringLiteral(value) {
35445
35462
  return `'${value.replace(/'/g, "''")}'`;
35446
35463
  }
35447
35464
  function failureAliasFromCellMeta(cellMeta) {
35448
- if (!isRecord11(cellMeta)) {
35465
+ if (!isRecord12(cellMeta)) {
35449
35466
  return null;
35450
35467
  }
35451
35468
  for (const [alias, meta] of Object.entries(cellMeta)) {
35452
- if (!isRecord11(meta)) {
35469
+ if (!isRecord12(meta)) {
35453
35470
  continue;
35454
35471
  }
35455
35472
  const failure = failureCellFromMeta(meta, {});
@@ -35943,7 +35960,7 @@ function exportableSheetRow2(row, sourceRowStart = 0) {
35943
35960
  return fallback;
35944
35961
  }
35945
35962
  function failureCellFromMeta(meta, fallback) {
35946
- if (!isRecord11(meta)) {
35963
+ if (!isRecord12(meta)) {
35947
35964
  return null;
35948
35965
  }
35949
35966
  const status = typeof meta.status === "string" ? meta.status.trim().toLowerCase() : "";
@@ -35963,7 +35980,7 @@ function failureCellFromMeta(meta, fallback) {
35963
35980
  };
35964
35981
  }
35965
35982
  function applyFailureCellMeta(row, cellMeta, fallback) {
35966
- if (!isRecord11(cellMeta)) {
35983
+ if (!isRecord12(cellMeta)) {
35967
35984
  return;
35968
35985
  }
35969
35986
  for (const [field, meta] of Object.entries(cellMeta)) {
@@ -36191,7 +36208,7 @@ function stableRowSnapshot(value) {
36191
36208
  }
36192
36209
  function cellFailureError(value) {
36193
36210
  const parsed = parseMaybeJsonObject(value);
36194
- if (!isRecord11(parsed)) {
36211
+ if (!isRecord12(parsed)) {
36195
36212
  const text = typeof parsed === "string" ? parsed.trim() : "";
36196
36213
  if (/^(?:[A-Za-z0-9_:-]+:\s*)?(?:Error|TypeError|ReferenceError|SyntaxError|RangeError):\s+/.test(
36197
36214
  text
@@ -36199,12 +36216,12 @@ function cellFailureError(value) {
36199
36216
  return { message: text };
36200
36217
  }
36201
36218
  }
36202
- if (!isRecord11(parsed)) {
36219
+ if (!isRecord12(parsed)) {
36203
36220
  return null;
36204
36221
  }
36205
36222
  const status = typeof parsed.status === "string" ? parsed.status.trim().toLowerCase() : "";
36206
36223
  const directError = typeof parsed.error === "string" ? parsed.error.trim() : typeof parsed.last_error === "string" ? parsed.last_error.trim() : "";
36207
- const result = isRecord11(parsed.result) ? parsed.result : null;
36224
+ const result = isRecord12(parsed.result) ? parsed.result : null;
36208
36225
  const resultError = typeof result?.error === "string" ? result.error.trim() : typeof result?.message === "string" ? result.message.trim() : "";
36209
36226
  if (!directError && !resultError && status !== "error" && status !== "failed") {
36210
36227
  return null;
@@ -36274,7 +36291,7 @@ function assignFlattenedFailurePath(target, field, value) {
36274
36291
  let cursor = target;
36275
36292
  for (const part of normalized.slice(0, -1)) {
36276
36293
  const existing = cursor[part];
36277
- if (!isRecord11(existing)) {
36294
+ if (!isRecord12(existing)) {
36278
36295
  const next = {};
36279
36296
  cursor[part] = next;
36280
36297
  cursor = next;
@@ -36438,10 +36455,10 @@ function waterfallExecutionSignal(status, spec) {
36438
36455
  let everyChildStatOnlyConditionSkipped = true;
36439
36456
  const childAliasesWithStats = /* @__PURE__ */ new Set();
36440
36457
  for (const childAlias of childAliases) {
36441
- for (const stat5 of summaries.map((summary) => summary[childAlias]).filter(isRecord11)) {
36458
+ for (const stat5 of summaries.map((summary) => summary[childAlias]).filter(isRecord12)) {
36442
36459
  sawChildStats = true;
36443
36460
  childAliasesWithStats.add(childAlias);
36444
- const execution = isRecord11(stat5.execution) ? stat5.execution : null;
36461
+ const execution = isRecord12(stat5.execution) ? stat5.execution : null;
36445
36462
  const executedSummary = parseExecutionSummary(
36446
36463
  execution?.["completed:executed"]
36447
36464
  );
@@ -36471,7 +36488,7 @@ function waterfallExecutionSignal(status, spec) {
36471
36488
  }
36472
36489
  function emptyWaterfallStatsEvidence(status, spec) {
36473
36490
  const summaries = collectColumnStats(status);
36474
- const parentStats = summaries.map((summary) => summary[spec.alias]).filter(isRecord11);
36491
+ const parentStats = summaries.map((summary) => summary[spec.alias]).filter(isRecord12);
36475
36492
  for (const stat5 of parentStats) {
36476
36493
  const nonEmpty = parseExecutionSummary(stat5.non_empty);
36477
36494
  if (nonEmpty?.total && nonEmpty.count === 0) {
@@ -36485,7 +36502,7 @@ function emptyWaterfallStatsEvidence(status, spec) {
36485
36502
  let selectedRows = 0;
36486
36503
  let sawStatsForEveryChild = true;
36487
36504
  for (const childAlias of childAliases) {
36488
- const stat5 = summaries.map((summary) => summary[childAlias]).find(isRecord11);
36505
+ const stat5 = summaries.map((summary) => summary[childAlias]).find(isRecord12);
36489
36506
  if (!stat5) {
36490
36507
  sawStatsForEveryChild = false;
36491
36508
  break;
@@ -36494,7 +36511,7 @@ function emptyWaterfallStatsEvidence(status, spec) {
36494
36511
  if ((nonEmpty?.count ?? 0) > 0) {
36495
36512
  return null;
36496
36513
  }
36497
- const execution = isRecord11(stat5.execution) ? stat5.execution : null;
36514
+ const execution = isRecord12(stat5.execution) ? stat5.execution : null;
36498
36515
  const executed = parseExecutionSummary(execution?.["completed:executed"]);
36499
36516
  const reused = parseExecutionSummary(execution?.["completed:reused"]);
36500
36517
  const skipped = parseExecutionSummary(execution?.["skipped:condition"]);
@@ -36536,11 +36553,11 @@ function collectStatusFailureJobs(input2) {
36536
36553
  const jobs = [];
36537
36554
  aliases.forEach((spec, aliasIndex) => {
36538
36555
  const { alias } = spec;
36539
- const stat5 = summaries.map((summary) => summary[alias]).find(isRecord11);
36556
+ const stat5 = summaries.map((summary) => summary[alias]).find(isRecord12);
36540
36557
  if (!stat5) {
36541
36558
  return;
36542
36559
  }
36543
- const execution = isRecord11(stat5.execution) ? stat5.execution : null;
36560
+ const execution = isRecord12(stat5.execution) ? stat5.execution : null;
36544
36561
  const failedCount = Math.min(
36545
36562
  selectedRows,
36546
36563
  Math.max(
@@ -36647,10 +36664,10 @@ function collectColumnStats(status) {
36647
36664
  value.forEach(visit);
36648
36665
  return;
36649
36666
  }
36650
- if (!isRecord11(value)) {
36667
+ if (!isRecord12(value)) {
36651
36668
  return;
36652
36669
  }
36653
- if (isRecord11(value.columnStats)) {
36670
+ if (isRecord12(value.columnStats)) {
36654
36671
  summaries.push(value.columnStats);
36655
36672
  }
36656
36673
  Object.values(value).forEach(visit);
@@ -36662,12 +36679,12 @@ function firstAliasExecutionCounts(input2) {
36662
36679
  const aliases = collectConfigScalarAliasOrder(input2.config);
36663
36680
  const summaries = collectColumnStats(input2.status);
36664
36681
  for (const alias of aliases) {
36665
- const stat5 = summaries.map((summary) => summary[alias]).find(isRecord11);
36682
+ const stat5 = summaries.map((summary) => summary[alias]).find(isRecord12);
36666
36683
  if (!stat5) continue;
36667
36684
  if (input2.forceAliases.has(normalizeAlias2(alias))) {
36668
36685
  return { executed: input2.selectedRows, reused: 0 };
36669
36686
  }
36670
- const execution = isRecord11(stat5.execution) ? stat5.execution : null;
36687
+ const execution = isRecord12(stat5.execution) ? stat5.execution : null;
36671
36688
  if (!execution) continue;
36672
36689
  return {
36673
36690
  executed: parseExecutionCount(execution["completed:executed"]),
@@ -36694,14 +36711,14 @@ function rewriteEnrichJsonStatus(input2) {
36694
36711
  if (Array.isArray(value)) {
36695
36712
  return value.map(rewrite);
36696
36713
  }
36697
- if (!isRecord11(value)) {
36714
+ if (!isRecord12(value)) {
36698
36715
  return value;
36699
36716
  }
36700
36717
  const next = {};
36701
36718
  for (const [key, entry] of Object.entries(value)) {
36702
36719
  next[key] = rewrite(entry);
36703
36720
  }
36704
- if (isRecord11(next.progress)) {
36721
+ if (isRecord12(next.progress)) {
36705
36722
  next.progress = {
36706
36723
  ...next.progress,
36707
36724
  ...selectedRows > 0 ? { total: selectedRows } : {},
@@ -36710,8 +36727,8 @@ function rewriteEnrichJsonStatus(input2) {
36710
36727
  ...failedRows > 0 ? { failed: failedRows, pending: 0 } : {}
36711
36728
  };
36712
36729
  }
36713
- if (isRecord11(next.summary)) {
36714
- const rowCounts = isRecord11(next.summary.rowCounts) ? next.summary.rowCounts : null;
36730
+ if (isRecord12(next.summary)) {
36731
+ const rowCounts = isRecord12(next.summary.rowCounts) ? next.summary.rowCounts : null;
36715
36732
  if (failedRows > 0) {
36716
36733
  next.summary = {
36717
36734
  ...next.summary,
@@ -36724,11 +36741,11 @@ function rewriteEnrichJsonStatus(input2) {
36724
36741
  };
36725
36742
  }
36726
36743
  }
36727
- if (isRecord11(next.columnStats) && selectedRows > 0) {
36744
+ if (isRecord12(next.columnStats) && selectedRows > 0) {
36728
36745
  const columnStats = { ...next.columnStats };
36729
36746
  for (const alias of forcedAliases) {
36730
- const stat5 = isRecord11(columnStats[alias]) ? columnStats[alias] : null;
36731
- const execution = isRecord11(stat5?.execution) ? stat5.execution : null;
36747
+ const stat5 = isRecord12(columnStats[alias]) ? columnStats[alias] : null;
36748
+ const execution = isRecord12(stat5?.execution) ? stat5.execution : null;
36732
36749
  if (!stat5 || !execution) continue;
36733
36750
  columnStats[alias] = {
36734
36751
  ...stat5,
@@ -36747,14 +36764,14 @@ function rewriteEnrichJsonStatus(input2) {
36747
36764
  return next;
36748
36765
  };
36749
36766
  const rewritten = rewrite(input2.status);
36750
- if (failedRows === 0 || !isRecord11(rewritten)) {
36767
+ if (failedRows === 0 || !isRecord12(rewritten)) {
36751
36768
  return rewritten;
36752
36769
  }
36753
36770
  const partialStatus = selectedRows > 0 && failedRows < selectedRows ? "partial_success" : "failed";
36754
36771
  return {
36755
36772
  ...rewritten,
36756
36773
  ...rewritten.status === "completed" || rewritten.status === "failed" ? { status: partialStatus } : {},
36757
- ...isRecord11(rewritten.run) && (rewritten.run.status === "completed" || rewritten.run.status === "failed") ? { run: { ...rewritten.run, status: partialStatus } } : {}
36774
+ ...isRecord12(rewritten.run) && (rewritten.run.status === "completed" || rewritten.run.status === "failed") ? { run: { ...rewritten.run, status: partialStatus } } : {}
36758
36775
  };
36759
36776
  }
36760
36777
  function summarizeFailedJobError(value) {
@@ -37378,7 +37395,7 @@ function materializeCsvCellValue(value) {
37378
37395
  return value;
37379
37396
  }
37380
37397
  function compactArrayEnvelopeCompleteValue(value) {
37381
- if (!isRecord11(value) || value.kind !== "array") {
37398
+ if (!isRecord12(value) || value.kind !== "array") {
37382
37399
  return null;
37383
37400
  }
37384
37401
  if (!Array.isArray(value.preview)) {
@@ -37392,7 +37409,7 @@ function compactArrayEnvelopeCompleteValue(value) {
37392
37409
  }
37393
37410
  function disambiguateCompactAiInferencePayload(value) {
37394
37411
  const parsed = parseMaybeJsonObject(value);
37395
- if (!isRecord11(parsed) || !cellFailureError(parsed)) {
37412
+ if (!isRecord12(parsed) || !cellFailureError(parsed)) {
37396
37413
  return value;
37397
37414
  }
37398
37415
  return {
@@ -37401,14 +37418,14 @@ function disambiguateCompactAiInferencePayload(value) {
37401
37418
  };
37402
37419
  }
37403
37420
  function compactAiInferenceCellForCsv(value) {
37404
- if (!isRecord11(value)) {
37421
+ if (!isRecord12(value)) {
37405
37422
  return value;
37406
37423
  }
37407
37424
  const extractedJson = value.extracted_json;
37408
37425
  if (extractedJson !== null && extractedJson !== void 0) {
37409
37426
  return disambiguateCompactAiInferencePayload(extractedJson);
37410
37427
  }
37411
- const result = isRecord11(value.result) ? value.result : null;
37428
+ const result = isRecord12(value.result) ? value.result : null;
37412
37429
  const object = result?.object;
37413
37430
  if (object !== null && object !== void 0) {
37414
37431
  return disambiguateCompactAiInferencePayload(object);
@@ -37425,12 +37442,12 @@ function compactAiInferenceCellForCsv(value) {
37425
37442
  }
37426
37443
  function materializeEnrichAliasCellForCsv(row, alias, options) {
37427
37444
  const direct = row[alias];
37428
- if (isRecord11(direct)) {
37445
+ if (isRecord12(direct)) {
37429
37446
  const completeArray = compactArrayEnvelopeCompleteValue(direct);
37430
37447
  if (completeArray) {
37431
37448
  return materializeCsvCellValue(completeArray);
37432
37449
  }
37433
- if (options?.compactAiCell && direct.status === "completed" && (isRecord11(direct.result) || Object.prototype.hasOwnProperty.call(direct, "extracted_json") || typeof direct.output === "string")) {
37450
+ if (options?.compactAiCell && direct.status === "completed" && (isRecord12(direct.result) || Object.prototype.hasOwnProperty.call(direct, "extracted_json") || typeof direct.output === "string")) {
37434
37451
  return materializeCsvCellValue(compactAiInferenceCellForCsv(direct));
37435
37452
  }
37436
37453
  if (Object.prototype.hasOwnProperty.call(direct, "matched_result") || Object.prototype.hasOwnProperty.call(direct, "matchedResult") || Object.prototype.hasOwnProperty.call(direct, "result")) {
@@ -37571,11 +37588,11 @@ function normalizeEnrichRowsForCsvExport(rows, config, options) {
37571
37588
  }
37572
37589
  function legacyMetadataFromRow(row) {
37573
37590
  const direct = parseLegacyMetadataCell(row._metadata);
37574
- if (direct && isRecord11(direct.columns)) {
37591
+ if (direct && isRecord12(direct.columns)) {
37575
37592
  return direct;
37576
37593
  }
37577
37594
  const relocated = parseLegacyMetadataCell(row.metadata);
37578
- if (relocated && isRecord11(relocated.columns)) {
37595
+ if (relocated && isRecord12(relocated.columns)) {
37579
37596
  return relocated;
37580
37597
  }
37581
37598
  const flattenedColumns = parseLegacyMetadataCell(row["metadata.columns"]);
@@ -37592,7 +37609,7 @@ function legacyMetadataFromRow(row) {
37592
37609
  }
37593
37610
  function parseLegacyMetadataCell(value) {
37594
37611
  const parsed = parseMaybeJsonObject(value);
37595
- if (isRecord11(parsed)) {
37612
+ if (isRecord12(parsed)) {
37596
37613
  return parsed;
37597
37614
  }
37598
37615
  if (typeof value !== "string") {
@@ -37609,12 +37626,12 @@ function parseLegacyMetadataCell(value) {
37609
37626
  for (const candidate of candidates) {
37610
37627
  try {
37611
37628
  const decoded = JSON.parse(candidate);
37612
- if (isRecord11(decoded)) {
37629
+ if (isRecord12(decoded)) {
37613
37630
  return decoded;
37614
37631
  }
37615
37632
  if (typeof decoded === "string") {
37616
37633
  const nested = JSON.parse(decoded);
37617
- if (isRecord11(nested)) {
37634
+ if (isRecord12(nested)) {
37618
37635
  return nested;
37619
37636
  }
37620
37637
  }
@@ -37624,8 +37641,8 @@ function parseLegacyMetadataCell(value) {
37624
37641
  return null;
37625
37642
  }
37626
37643
  function mergeLegacyMetadataRecords(base, enriched) {
37627
- const baseColumns = isRecord11(base.columns) ? base.columns : null;
37628
- const enrichedColumns = isRecord11(enriched.columns) ? enriched.columns : null;
37644
+ const baseColumns = isRecord12(base.columns) ? base.columns : null;
37645
+ const enrichedColumns = isRecord12(enriched.columns) ? enriched.columns : null;
37629
37646
  const merged = {
37630
37647
  ...base,
37631
37648
  ...enriched
@@ -49381,6 +49398,11 @@ Examples:
49381
49398
 
49382
49399
  // src/cli/commands/tools.ts
49383
49400
  var import_commander4 = require("commander");
49401
+ var import_node_fs27 = require("fs");
49402
+ var import_node_os19 = require("os");
49403
+ var import_node_path32 = require("path");
49404
+
49405
+ // src/cli/tool-call-recovery.ts
49384
49406
  var import_node_crypto12 = require("crypto");
49385
49407
 
49386
49408
  // ../plays/row-identity.ts
@@ -49399,15 +49421,94 @@ function stableStringify(value) {
49399
49421
  return JSON.stringify(stableValue(value));
49400
49422
  }
49401
49423
 
49402
- // src/cli/commands/tools.ts
49403
- var import_node_fs26 = require("fs");
49404
- var import_node_os19 = require("os");
49405
- var import_node_path31 = require("path");
49424
+ // src/cli/tool-call-recovery.ts
49425
+ var import_node_fs25 = require("fs");
49426
+ var import_node_path30 = require("path");
49427
+ var ToolCallRecovery = class _ToolCallRecovery {
49428
+ constructor(idempotencyKey, path) {
49429
+ this.idempotencyKey = idempotencyKey;
49430
+ this.path = path;
49431
+ }
49432
+ static open(input2) {
49433
+ if (!input2.recover || input2.idempotencyKey) {
49434
+ return new _ToolCallRecovery(input2.idempotencyKey, null);
49435
+ }
49436
+ const path = pendingToolExecutionPath(input2);
49437
+ return new _ToolCallRecovery(loadOrCreatePendingToolExecution(path), path);
49438
+ }
49439
+ async acknowledgeDelivery() {
49440
+ await completePendingToolExecution(this.path, this.idempotencyKey);
49441
+ }
49442
+ };
49443
+ function pendingToolExecutionPath(input2) {
49444
+ const config = resolveConfig();
49445
+ const fingerprint = (0, import_node_crypto12.createHash)("sha256").update(config.baseUrl).update("\0").update((0, import_node_crypto12.createHash)("sha256").update(config.apiKey).digest("hex")).update("\0").update(input2.toolId).update("\0").update(stableStringify(input2.params)).update("\0").update(input2.responseIntent).digest("hex");
49446
+ return (0, import_node_path30.join)(
49447
+ sdkCliStateDirPath(config.baseUrl),
49448
+ `pending-tool-execution-${fingerprint}.json`
49449
+ );
49450
+ }
49451
+ function loadOrCreatePendingToolExecution(path) {
49452
+ (0, import_node_fs25.mkdirSync)((0, import_node_path30.dirname)(path), { recursive: true });
49453
+ if ((0, import_node_fs25.existsSync)(path)) {
49454
+ return readPendingToolExecution(path);
49455
+ }
49456
+ const idempotencyKey = (0, import_node_crypto12.randomUUID)();
49457
+ const temporaryPath = `${path}.${process.pid}.${(0, import_node_crypto12.randomUUID)()}.tmp`;
49458
+ try {
49459
+ (0, import_node_fs25.writeFileSync)(temporaryPath, `${JSON.stringify({ idempotencyKey })}
49460
+ `, {
49461
+ encoding: "utf8",
49462
+ flag: "wx",
49463
+ mode: 384
49464
+ });
49465
+ (0, import_node_fs25.linkSync)(temporaryPath, path);
49466
+ return idempotencyKey;
49467
+ } catch (error) {
49468
+ if (error.code !== "EEXIST") throw error;
49469
+ return readPendingToolExecution(path);
49470
+ } finally {
49471
+ if ((0, import_node_fs25.existsSync)(temporaryPath)) (0, import_node_fs25.unlinkSync)(temporaryPath);
49472
+ }
49473
+ }
49474
+ function readPendingToolExecution(path) {
49475
+ const saved = JSON.parse((0, import_node_fs25.readFileSync)(path, "utf8"));
49476
+ if (typeof saved.idempotencyKey !== "string") {
49477
+ throw new Error(
49478
+ `Cannot resume the saved tool execution at ${path}: invalid recovery key.`
49479
+ );
49480
+ }
49481
+ return saved.idempotencyKey;
49482
+ }
49483
+ async function completePendingToolExecution(path, idempotencyKey) {
49484
+ if (!path || !idempotencyKey || !(0, import_node_fs25.existsSync)(path)) return;
49485
+ await new Promise((resolve22, reject) => {
49486
+ const onError = (error) => {
49487
+ process.stdout.off("error", onError);
49488
+ reject(error);
49489
+ };
49490
+ process.stdout.once("error", onError);
49491
+ process.stdout.write("", (error) => {
49492
+ process.stdout.off("error", onError);
49493
+ if (error) {
49494
+ reject(error);
49495
+ } else {
49496
+ resolve22();
49497
+ }
49498
+ });
49499
+ });
49500
+ try {
49501
+ if (readPendingToolExecution(path) !== idempotencyKey) return;
49502
+ (0, import_node_fs25.unlinkSync)(path);
49503
+ } catch (error) {
49504
+ if (error.code !== "ENOENT") throw error;
49505
+ }
49506
+ }
49406
49507
 
49407
49508
  // src/tool-output.ts
49408
- var import_node_fs25 = require("fs");
49509
+ var import_node_fs26 = require("fs");
49409
49510
  var import_node_os18 = require("os");
49410
- var import_node_path30 = require("path");
49511
+ var import_node_path31 = require("path");
49411
49512
  function isPlainObject(value) {
49412
49513
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
49413
49514
  }
@@ -49534,19 +49635,19 @@ function projectRowOutput(conversion) {
49534
49635
  };
49535
49636
  }
49536
49637
  function ensureOutputDir() {
49537
- const outputDir = (0, import_node_path30.join)((0, import_node_os18.homedir)(), ".local", "share", "deepline", "data");
49538
- (0, import_node_fs25.mkdirSync)(outputDir, { recursive: true });
49638
+ const outputDir = (0, import_node_path31.join)((0, import_node_os18.homedir)(), ".local", "share", "deepline", "data");
49639
+ (0, import_node_fs26.mkdirSync)(outputDir, { recursive: true });
49539
49640
  return outputDir;
49540
49641
  }
49541
49642
  function writeJsonOutputFile(payload, stem) {
49542
49643
  const outputDir = ensureOutputDir();
49543
- const outputPath = (0, import_node_path30.join)(outputDir, `${stem}_${Date.now()}.json`);
49544
- (0, import_node_fs25.writeFileSync)(outputPath, JSON.stringify(payload, null, 2), "utf-8");
49644
+ const outputPath = (0, import_node_path31.join)(outputDir, `${stem}_${Date.now()}.json`);
49645
+ (0, import_node_fs26.writeFileSync)(outputPath, JSON.stringify(payload, null, 2), "utf-8");
49545
49646
  return outputPath;
49546
49647
  }
49547
49648
  function writeCsvOutputFile(rows, stem, options) {
49548
- const outputPath = options?.outPath ? options.outPath : (0, import_node_path30.join)(ensureOutputDir(), `${stem}_${Date.now()}.csv`);
49549
- (0, import_node_fs25.mkdirSync)((0, import_node_path30.dirname)(outputPath), { recursive: true });
49649
+ const outputPath = options?.outPath ? options.outPath : (0, import_node_path31.join)(ensureOutputDir(), `${stem}_${Date.now()}.csv`);
49650
+ (0, import_node_fs26.mkdirSync)((0, import_node_path31.dirname)(outputPath), { recursive: true });
49550
49651
  const columns = columnsForRows(rows);
49551
49652
  const escapeCell = (value) => {
49552
49653
  const normalized = value == null ? "" : typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : JSON.stringify(value);
@@ -49555,19 +49656,19 @@ function writeCsvOutputFile(rows, stem, options) {
49555
49656
  }
49556
49657
  return normalized;
49557
49658
  };
49558
- const fd = (0, import_node_fs25.openSync)(outputPath, "w");
49659
+ const fd = (0, import_node_fs26.openSync)(outputPath, "w");
49559
49660
  try {
49560
- (0, import_node_fs25.writeSync)(fd, `${columns.map(escapeCell).join(",")}
49661
+ (0, import_node_fs26.writeSync)(fd, `${columns.map(escapeCell).join(",")}
49561
49662
  `);
49562
49663
  for (const row of rows) {
49563
- (0, import_node_fs25.writeSync)(
49664
+ (0, import_node_fs26.writeSync)(
49564
49665
  fd,
49565
49666
  `${columns.map((column) => escapeCell(row[column])).join(",")}
49566
49667
  `
49567
49668
  );
49568
49669
  }
49569
49670
  } finally {
49570
- (0, import_node_fs25.closeSync)(fd);
49671
+ (0, import_node_fs26.closeSync)(fd);
49571
49672
  }
49572
49673
  const previewRows = rows.slice(0, 5);
49573
49674
  const previewColumns = columns.slice(0, 5);
@@ -50134,12 +50235,12 @@ async function listTools(category, options = {}) {
50134
50235
  }
50135
50236
  var SEARCH_REF_TTL_MS = 15 * 6e4;
50136
50237
  function lastSearchPath() {
50137
- return (0, import_node_path31.join)(sdkCliStateDirPath(resolveConfig().baseUrl), "last-search.json");
50238
+ return (0, import_node_path32.join)(sdkCliStateDirPath(resolveConfig().baseUrl), "last-search.json");
50138
50239
  }
50139
50240
  function rememberSearchRef(searchRef) {
50140
50241
  try {
50141
- (0, import_node_fs26.mkdirSync)((0, import_node_path31.dirname)(lastSearchPath()), { recursive: true });
50142
- (0, import_node_fs26.writeFileSync)(
50242
+ (0, import_node_fs27.mkdirSync)((0, import_node_path32.dirname)(lastSearchPath()), { recursive: true });
50243
+ (0, import_node_fs27.writeFileSync)(
50143
50244
  lastSearchPath(),
50144
50245
  JSON.stringify({ searchRef, at: Date.now() }),
50145
50246
  { mode: 384 }
@@ -50149,7 +50250,7 @@ function rememberSearchRef(searchRef) {
50149
50250
  }
50150
50251
  function recentSearchRef() {
50151
50252
  try {
50152
- const saved = JSON.parse((0, import_node_fs26.readFileSync)(lastSearchPath(), "utf8"));
50253
+ const saved = JSON.parse((0, import_node_fs27.readFileSync)(lastSearchPath(), "utf8"));
50153
50254
  return typeof saved.searchRef === "string" && typeof saved.at === "number" && Date.now() - saved.at < SEARCH_REF_TTL_MS ? saved.searchRef : void 0;
50154
50255
  } catch {
50155
50256
  return void 0;
@@ -50809,7 +50910,7 @@ function toolContractJsonForDescribe(tool, requestedToolId) {
50809
50910
  }
50810
50911
  function extractionContractEntries(entries) {
50811
50912
  return entries.flatMap((entry) => {
50812
- if (!isRecord12(entry)) return [];
50913
+ if (!isRecord13(entry)) return [];
50813
50914
  const name = stringField2(entry, "name");
50814
50915
  const expression = stringField2(entry, "expression");
50815
50916
  return name && expression ? [{ name, expression }] : [];
@@ -50830,7 +50931,7 @@ function printMonitorTypeFilters(tool) {
50830
50931
  }
50831
50932
  console.log("Deploy filters (set in the monitor payload):");
50832
50933
  for (const name of names) {
50833
- const field = isRecord12(properties[name]) ? properties[name] : {};
50934
+ const field = isRecord13(properties[name]) ? properties[name] : {};
50834
50935
  const star = required.has(name) ? "*" : "";
50835
50936
  const enumVals = arrayField2(field, "enum").filter(
50836
50937
  (v) => typeof v === "string"
@@ -50844,7 +50945,7 @@ function printMonitorTypeFilterExamples(tool) {
50844
50945
  const documentation = recordField2(tool, "documentation");
50845
50946
  const fields2 = recordField2(documentation, "fields");
50846
50947
  const examples = Object.entries(fields2).flatMap(([name, rawField]) => {
50847
- const grammar = recordField2(isRecord12(rawField) ? rawField : {}, "grammar");
50948
+ const grammar = recordField2(isRecord13(rawField) ? rawField : {}, "grammar");
50848
50949
  const example = stringField2(grammar, "example");
50849
50950
  const values = [
50850
50951
  ...arrayField2(grammar, "examples").filter(
@@ -50863,14 +50964,14 @@ function printMonitorTypeFilterExamples(tool) {
50863
50964
  }
50864
50965
  function printMonitorTypeStreams(tool) {
50865
50966
  const streams = arrayField2(tool, "streams", "output_streams").filter(
50866
- isRecord12
50967
+ isRecord13
50867
50968
  );
50868
50969
  if (!streams.length) return;
50869
50970
  console.log("");
50870
50971
  console.log("Filter columns (a play's sqlListeners.where, per stream):");
50871
50972
  for (const stream of streams) {
50872
50973
  const name = stringField2(stream, "stream");
50873
- const cols = arrayField2(stream, "columns").filter(isRecord12).map((col) => stringField2(col, "name")).filter(Boolean);
50974
+ const cols = arrayField2(stream, "columns").filter(isRecord13).map((col) => stringField2(col, "name")).filter(Boolean);
50874
50975
  console.log(`- ${name}: ${cols.join(", ")}`);
50875
50976
  }
50876
50977
  }
@@ -50888,7 +50989,7 @@ function printMonitorTypePricing(tool) {
50888
50989
  }
50889
50990
  console.log("Pricing (Deepline credits per accepted event):");
50890
50991
  for (const key of keys) {
50891
- const entry = isRecord12(byType[key]) ? byType[key] : {};
50992
+ const entry = isRecord13(byType[key]) ? byType[key] : {};
50892
50993
  const credits = numberField2(entry, "deepline_credits", "deeplineCredits");
50893
50994
  const display = stringField2(entry, "display");
50894
50995
  const shown = display || (credits !== null ? `${formatDecimal(credits)} credits/event` : "see --json");
@@ -50934,8 +51035,8 @@ function printCompactToolContract(tool, requestedToolId) {
50934
51035
  return;
50935
51036
  }
50936
51037
  const contract = toolContractJsonForDescribe(tool, requestedToolId);
50937
- const cost = isRecord12(contract.cost) ? contract.cost : {};
50938
- const getters = isRecord12(contract.getters) ? contract.getters : {};
51038
+ const cost = isRecord13(contract.cost) ? contract.cost : {};
51039
+ const getters = isRecord13(contract.getters) ? contract.getters : {};
50939
51040
  const listGetters = Array.isArray(getters.extractedLists) ? getters.extractedLists : [];
50940
51041
  const valueGetters = Array.isArray(getters.extractedValues) ? getters.extractedValues : [];
50941
51042
  const inputFields = recursiveToolInputFieldsForDisplay(
@@ -50952,7 +51053,7 @@ function printCompactToolContract(tool, requestedToolId) {
50952
51053
  printToolOutputArrayShape(contract);
50953
51054
  printToolExecutionHints(contract);
50954
51055
  if (contract.deprecated === true) {
50955
- const deprecation = isRecord12(contract.deprecation) ? contract.deprecation : {};
51056
+ const deprecation = isRecord13(contract.deprecation) ? contract.deprecation : {};
50956
51057
  const message = stringField2(deprecation, "message");
50957
51058
  const replacementToolId = stringField2(
50958
51059
  deprecation,
@@ -50979,7 +51080,7 @@ function printCompactToolContract(tool, requestedToolId) {
50979
51080
  console.log("");
50980
51081
  console.log("Inputs:");
50981
51082
  for (const field of inputFields) {
50982
- if (!isRecord12(field)) continue;
51083
+ if (!isRecord13(field)) continue;
50983
51084
  const name = stringField2(field, "name");
50984
51085
  if (!name) continue;
50985
51086
  const required = field.required ? "*" : "";
@@ -50999,7 +51100,7 @@ function printCompactToolContract(tool, requestedToolId) {
50999
51100
  }
51000
51101
  console.log("");
51001
51102
  printToolExamplesOnly(tool, requestedToolId, { includeSamples: false });
51002
- const starterScript = isRecord12(contract.starterScript) ? contract.starterScript : {};
51103
+ const starterScript = isRecord13(contract.starterScript) ? contract.starterScript : {};
51003
51104
  const starterPath = stringField2(starterScript, "path");
51004
51105
  if (starterPath) {
51005
51106
  console.log("");
@@ -51013,14 +51114,14 @@ function printCompactToolContract(tool, requestedToolId) {
51013
51114
  console.log("Getters:");
51014
51115
  if (listGetters.length) console.log("Lists:");
51015
51116
  for (const entry of listGetters) {
51016
- if (isRecord12(entry))
51117
+ if (isRecord13(entry))
51017
51118
  console.log(
51018
51119
  `- ${stringField2(entry, "name")}: ${playResultExpression(entry)}`
51019
51120
  );
51020
51121
  }
51021
51122
  if (valueGetters.length) console.log("Values:");
51022
51123
  for (const entry of valueGetters) {
51023
- if (isRecord12(entry))
51124
+ if (isRecord13(entry))
51024
51125
  console.log(
51025
51126
  `- ${stringField2(entry, "name")}: ${playResultExpression(entry)}`
51026
51127
  );
@@ -51037,7 +51138,7 @@ function printToolPricingOnly(tool, requestedToolId, options = {}) {
51037
51138
  return;
51038
51139
  }
51039
51140
  const contract = toolContractJsonForDescribe(tool, requestedToolId);
51040
- const cost = isRecord12(contract.cost) ? contract.cost : {};
51141
+ const cost = isRecord13(contract.cost) ? contract.cost : {};
51041
51142
  const pricingModel = stringField2(cost, "pricingModel") || "unknown";
51042
51143
  const billing = stringField2(cost, "billingSourceLabel") || stringField2(cost, "billingSource") || stringField2(cost, "billingMode") || "unknown";
51043
51144
  const explicitUnit = stringField2(cost, "unit");
@@ -51114,10 +51215,10 @@ function printToolExamplesOnly(tool, requestedToolId, options = {}) {
51114
51215
  ` input: ${JSON.stringify(sampleInput || {}, null, 2).replace(/\n/g, "\n ")},`
51115
51216
  );
51116
51217
  console.log("});");
51117
- const getters = isRecord12(contract.getters) ? contract.getters : {};
51218
+ const getters = isRecord13(contract.getters) ? contract.getters : {};
51118
51219
  const valueGetters = Array.isArray(getters.extractedValues) ? getters.extractedValues : [];
51119
51220
  const listGetters = Array.isArray(getters.extractedLists) ? getters.extractedLists : [];
51120
- const firstGetter = [...valueGetters, ...listGetters].find(isRecord12);
51221
+ const firstGetter = [...valueGetters, ...listGetters].find(isRecord13);
51121
51222
  if (firstGetter) {
51122
51223
  const name = stringField2(firstGetter, "name") || "value";
51123
51224
  const expression = stringField2(firstGetter, "expression");
@@ -51153,7 +51254,7 @@ function printPlayLikeToolUsage(tool, requestedToolId) {
51153
51254
  }
51154
51255
  function printToolGettersOnly(tool, requestedToolId) {
51155
51256
  const contract = toolContractJsonForDescribe(tool, requestedToolId);
51156
- const getters = isRecord12(contract.getters) ? contract.getters : {};
51257
+ const getters = isRecord13(contract.getters) ? contract.getters : {};
51157
51258
  const listGetters = Array.isArray(getters.extractedLists) ? getters.extractedLists : [];
51158
51259
  const valueGetters = Array.isArray(getters.extractedValues) ? getters.extractedValues : [];
51159
51260
  console.log(`Getters: ${contract.toolId}`);
@@ -51166,7 +51267,7 @@ function printToolGettersOnly(tool, requestedToolId) {
51166
51267
  if (listGetters.length) {
51167
51268
  console.log("Lists:");
51168
51269
  for (const entry of listGetters) {
51169
- if (isRecord12(entry))
51270
+ if (isRecord13(entry))
51170
51271
  console.log(
51171
51272
  `- ${stringField2(entry, "name")}: ${playResultExpression(entry)}`
51172
51273
  );
@@ -51175,7 +51276,7 @@ function printToolGettersOnly(tool, requestedToolId) {
51175
51276
  if (valueGetters.length) {
51176
51277
  console.log("Values:");
51177
51278
  for (const entry of valueGetters) {
51178
- if (isRecord12(entry))
51279
+ if (isRecord13(entry))
51179
51280
  console.log(
51180
51281
  `- ${stringField2(entry, "name")}: ${playResultExpression(entry)}`
51181
51282
  );
@@ -51201,7 +51302,7 @@ function sampleValueForField(field) {
51201
51302
  function samplePayloadForInputFields(fields2) {
51202
51303
  return Object.fromEntries(
51203
51304
  fields2.slice(0, 4).flatMap((field) => {
51204
- if (!isRecord12(field)) return [];
51305
+ if (!isRecord13(field)) return [];
51205
51306
  const name = stringField2(field, "name");
51206
51307
  if (!name) return [];
51207
51308
  return [[name, sampleValueForField(field)]];
@@ -51331,8 +51432,8 @@ function formatListedToolCost(tool) {
51331
51432
  }
51332
51433
  function toolInputFieldsForDisplay(inputSchema) {
51333
51434
  if (Array.isArray(inputSchema.fields)) {
51334
- const fields2 = inputSchema.fields.filter(isRecord12);
51335
- if (!isRecord12(inputSchema.jsonSchema)) return fields2;
51435
+ const fields2 = inputSchema.fields.filter(isRecord13);
51436
+ if (!isRecord13(inputSchema.jsonSchema)) return fields2;
51336
51437
  const jsonSchemaFields = new Map(
51337
51438
  recursiveToolInputFieldsForDisplay({
51338
51439
  jsonSchema: inputSchema.jsonSchema
@@ -51344,26 +51445,26 @@ function toolInputFieldsForDisplay(inputSchema) {
51344
51445
  const jsonSchemaField = typeof field.name === "string" ? jsonSchemaFields.get(field.name) : void 0;
51345
51446
  const minItems = typeof field.minItems === "number" ? field.minItems : jsonSchemaField?.minItems;
51346
51447
  const maxItems = typeof field.maxItems === "number" ? field.maxItems : jsonSchemaField?.maxItems;
51347
- const items = isRecord12(field.items) ? field.items : jsonSchemaField?.items;
51448
+ const items = isRecord13(field.items) ? field.items : jsonSchemaField?.items;
51348
51449
  return {
51349
51450
  ...field,
51350
- ...isRecord12(items) ? { items } : {},
51451
+ ...isRecord13(items) ? { items } : {},
51351
51452
  ...typeof minItems === "number" ? { minItems } : {},
51352
51453
  ...typeof maxItems === "number" ? { maxItems } : {}
51353
51454
  };
51354
51455
  });
51355
51456
  }
51356
- const jsonSchema = isRecord12(inputSchema.jsonSchema) ? inputSchema.jsonSchema : inputSchema;
51357
- const properties = isRecord12(jsonSchema.properties) ? jsonSchema.properties : {};
51457
+ const jsonSchema = isRecord13(inputSchema.jsonSchema) ? inputSchema.jsonSchema : inputSchema;
51458
+ const properties = isRecord13(jsonSchema.properties) ? jsonSchema.properties : {};
51358
51459
  const required = Array.isArray(jsonSchema.required) ? new Set(jsonSchema.required.map(String)) : /* @__PURE__ */ new Set();
51359
51460
  return Object.entries(properties).map(([name, value]) => {
51360
- const property = isRecord12(value) ? value : {};
51461
+ const property = isRecord13(value) ? value : {};
51361
51462
  return {
51362
51463
  name,
51363
51464
  type: typeof property.type === "string" ? property.type : "unknown",
51364
51465
  required: required.has(name),
51365
51466
  description: property.description,
51366
- ...isRecord12(property.items) ? { items: property.items } : {},
51467
+ ...isRecord13(property.items) ? { items: property.items } : {},
51367
51468
  ...typeof property.minItems === "number" ? { minItems: property.minItems } : {},
51368
51469
  ...typeof property.maxItems === "number" ? { maxItems: property.maxItems } : {},
51369
51470
  ...Object.prototype.hasOwnProperty.call(property, "default") ? { default: property.default } : {}
@@ -51380,7 +51481,7 @@ function toolOutputFieldsForDisplay(outputSchema) {
51380
51481
  }
51381
51482
  function printToolOutputArrayShape(tool) {
51382
51483
  const outputFields = toolOutputFieldsForDisplay(
51383
- recordField2(isRecord12(tool) ? tool : {}, "outputSchema", "output_schema")
51484
+ recordField2(isRecord13(tool) ? tool : {}, "outputSchema", "output_schema")
51384
51485
  );
51385
51486
  if (outputFields.length === 0) return;
51386
51487
  console.log(" Output array shape (declared schema):");
@@ -51395,10 +51496,10 @@ function printToolOutputArrayShape(tool) {
51395
51496
  }
51396
51497
  }
51397
51498
  function canonicalToolJsonSchema(inputSchema) {
51398
- return isRecord12(inputSchema.jsonSchema) ? inputSchema.jsonSchema : inputSchema;
51499
+ return isRecord13(inputSchema.jsonSchema) ? inputSchema.jsonSchema : inputSchema;
51399
51500
  }
51400
51501
  function declaredToolJsonSchema(inputSchema) {
51401
- if (isRecord12(inputSchema.jsonSchema)) {
51502
+ if (isRecord13(inputSchema.jsonSchema)) {
51402
51503
  return inputSchema.jsonSchema;
51403
51504
  }
51404
51505
  return Array.isArray(inputSchema.fields) ? null : inputSchema;
@@ -51423,7 +51524,7 @@ function publicToolInputSchemaForDescribe(inputSchema) {
51423
51524
  };
51424
51525
  const stripDescriptions = (value) => {
51425
51526
  if (Array.isArray(value)) return value.map(stripDescriptions);
51426
- if (!isRecord12(value)) return value;
51527
+ if (!isRecord13(value)) return value;
51427
51528
  return Object.fromEntries(
51428
51529
  Object.entries(value).flatMap(([key, nested]) => {
51429
51530
  if (key === "description" && typeof nested === "string" && exposesProviderSpend(nested)) {
@@ -51444,7 +51545,7 @@ function recursiveToolInputFieldsForDisplay(inputSchema) {
51444
51545
  for (const item of value) collectSchemaIds(item);
51445
51546
  return;
51446
51547
  }
51447
- if (!isRecord12(value)) return;
51548
+ if (!isRecord13(value)) return;
51448
51549
  if (typeof value.$id === "string" && value.$id.trim()) {
51449
51550
  schemasById.set(value.$id.trim(), value);
51450
51551
  }
@@ -51457,10 +51558,10 @@ function recursiveToolInputFieldsForDisplay(inputSchema) {
51457
51558
  let current = root;
51458
51559
  for (const rawSegment of ref.slice(2).split("/")) {
51459
51560
  const segment = rawSegment.replace(/~1/g, "/").replace(/~0/g, "~");
51460
- if (!isRecord12(current)) return schema;
51561
+ if (!isRecord13(current)) return schema;
51461
51562
  current = current[segment];
51462
51563
  }
51463
- return isRecord12(current) ? current : schema;
51564
+ return isRecord13(current) ? current : schema;
51464
51565
  };
51465
51566
  const addField = (field) => {
51466
51567
  const name = typeof field.name === "string" ? field.name : "";
@@ -51475,7 +51576,7 @@ function recursiveToolInputFieldsForDisplay(inputSchema) {
51475
51576
  if (ref && activeRefs.has(ref)) return;
51476
51577
  const schema = resolveRef(unresolvedSchema);
51477
51578
  const nextActiveRefs = ref ? /* @__PURE__ */ new Set([...activeRefs, ref]) : activeRefs;
51478
- const type = Array.isArray(schema.type) ? schema.type.map(String).join("|") : typeof schema.type === "string" ? schema.type : isRecord12(schema.properties) ? "object" : schema.items ? "array" : "unknown";
51579
+ const type = Array.isArray(schema.type) ? schema.type.map(String).join("|") : typeof schema.type === "string" ? schema.type : isRecord13(schema.properties) ? "object" : schema.items ? "array" : "unknown";
51479
51580
  if (path) {
51480
51581
  addField({
51481
51582
  name: path,
@@ -51483,18 +51584,18 @@ function recursiveToolInputFieldsForDisplay(inputSchema) {
51483
51584
  required,
51484
51585
  description: schema.description,
51485
51586
  ...Array.isArray(schema.enum) ? { enum: schema.enum } : {},
51486
- ...isRecord12(schema.items) ? { items: schema.items } : {},
51587
+ ...isRecord13(schema.items) ? { items: schema.items } : {},
51487
51588
  ...typeof schema.minItems === "number" ? { minItems: schema.minItems } : {},
51488
51589
  ...typeof schema.maxItems === "number" ? { maxItems: schema.maxItems } : {},
51489
51590
  ...Object.prototype.hasOwnProperty.call(schema, "default") ? { default: schema.default } : {}
51490
51591
  });
51491
51592
  }
51492
- const properties = isRecord12(schema.properties) ? schema.properties : {};
51593
+ const properties = isRecord13(schema.properties) ? schema.properties : {};
51493
51594
  const requiredNames = new Set(
51494
51595
  Array.isArray(schema.required) ? schema.required.map(String) : []
51495
51596
  );
51496
51597
  for (const [name, value] of Object.entries(properties)) {
51497
- if (!isRecord12(value)) continue;
51598
+ if (!isRecord13(value)) continue;
51498
51599
  visit(
51499
51600
  value,
51500
51601
  path ? `${path}.${name}` : name,
@@ -51502,13 +51603,13 @@ function recursiveToolInputFieldsForDisplay(inputSchema) {
51502
51603
  nextActiveRefs
51503
51604
  );
51504
51605
  }
51505
- if (isRecord12(schema.items)) {
51606
+ if (isRecord13(schema.items)) {
51506
51607
  visit(schema.items, `${path}[]`, false, nextActiveRefs);
51507
51608
  }
51508
51609
  for (const keyword of ["anyOf", "oneOf", "allOf"]) {
51509
51610
  const branches = Array.isArray(schema[keyword]) ? schema[keyword] : [];
51510
51611
  for (const branch of branches) {
51511
- if (isRecord12(branch)) {
51612
+ if (isRecord13(branch)) {
51512
51613
  visit(branch, path, required, nextActiveRefs);
51513
51614
  }
51514
51615
  }
@@ -51518,21 +51619,21 @@ function recursiveToolInputFieldsForDisplay(inputSchema) {
51518
51619
  return fields2.size ? [...fields2.values()] : toolInputFieldsForDisplay(inputSchema);
51519
51620
  }
51520
51621
  function inputFieldJsonForDescribe(field) {
51521
- const publicItems = isRecord12(field.items) ? publicToolInputSchemaForDescribe({ items: field.items }).items : void 0;
51622
+ const publicItems = isRecord13(field.items) ? publicToolInputSchemaForDescribe({ items: field.items }).items : void 0;
51522
51623
  return {
51523
51624
  name: field.name,
51524
51625
  type: field.type ?? "unknown",
51525
51626
  required: Boolean(field.required),
51526
51627
  ...field.description ? { description: field.description } : {},
51527
- ...isRecord12(publicItems) ? { items: publicItems } : {},
51628
+ ...isRecord13(publicItems) ? { items: publicItems } : {},
51528
51629
  ...typeof field.minItems === "number" ? { minItems: field.minItems } : {},
51529
51630
  ...typeof field.maxItems === "number" ? { maxItems: field.maxItems } : {},
51530
51631
  ...Object.prototype.hasOwnProperty.call(field, "default") ? { default: field.default } : {}
51531
51632
  };
51532
51633
  }
51533
51634
  function arrayItemBoundsSuffix(field) {
51534
- const itemSchema = isRecord12(field.items) ? field.items : null;
51535
- const itemType = itemSchema ? typeof itemSchema.type === "string" ? itemSchema.type : isRecord12(itemSchema.properties) ? "object" : "unknown" : null;
51635
+ const itemSchema = isRecord13(field.items) ? field.items : null;
51636
+ const itemType = itemSchema ? typeof itemSchema.type === "string" ? itemSchema.type : isRecord13(itemSchema.properties) ? "object" : "unknown" : null;
51536
51637
  const itemEnum = Array.isArray(itemSchema?.enum) ? ` enum=${itemSchema.enum.map(String).join("|")}` : "";
51537
51638
  const itemTypeSuffix = itemType && itemType !== "unknown" ? ` items=${itemType}${itemEnum}` : "";
51538
51639
  const minItems = typeof field.minItems === "number" && Number.isFinite(field.minItems) ? field.minItems : null;
@@ -51546,13 +51647,13 @@ function arrayItemBoundsSuffix(field) {
51546
51647
  }
51547
51648
  function printToolExecutionHints(value) {
51548
51649
  const batchCapabilityRecord = recordField2(
51549
- isRecord12(value) ? value : {},
51650
+ isRecord13(value) ? value : {},
51550
51651
  "batchCapability",
51551
51652
  "batch_capability"
51552
51653
  );
51553
51654
  const batchCapability = Object.keys(batchCapabilityRecord).length > 0 ? batchCapabilityRecord : null;
51554
51655
  const executionMetadata = recordField2(
51555
- isRecord12(value) ? value : {},
51656
+ isRecord13(value) ? value : {},
51556
51657
  "executionMetadata",
51557
51658
  "execution_metadata"
51558
51659
  );
@@ -51592,7 +51693,7 @@ function printToolExecutionHints(value) {
51592
51693
  executionMetadata,
51593
51694
  "configuredRateLimits",
51594
51695
  "configured_rate_limits"
51595
- ).filter(isRecord12);
51696
+ ).filter(isRecord13);
51596
51697
  if (configuredRateLimits.length > 0) {
51597
51698
  console.log("");
51598
51699
  console.log(
@@ -51657,17 +51758,17 @@ function printJsonPreview(label, payload) {
51657
51758
  }
51658
51759
  function samplePayload(samples, key) {
51659
51760
  const entry = samples[key];
51660
- if (!isRecord12(entry)) return void 0;
51761
+ if (!isRecord13(entry)) return void 0;
51661
51762
  return Object.prototype.hasOwnProperty.call(entry, "payload") ? entry.payload : entry;
51662
51763
  }
51663
51764
  function commandEnvelopeFromRawResponse(rawResponse) {
51664
- return isRecord12(rawResponse) ? { ...rawResponse } : { status: "completed", result: rawResponse };
51765
+ return isRecord13(rawResponse) ? { ...rawResponse } : { status: "completed", result: rawResponse };
51665
51766
  }
51666
51767
  function toolExecuteExitCode(envelope) {
51667
51768
  return envelope.status === "failed" || envelope.ok === false ? 1 : 0;
51668
51769
  }
51669
51770
  function extractToolExecutionWarningMessages(rawResponse) {
51670
- if (!isRecord12(rawResponse)) return [];
51771
+ if (!isRecord13(rawResponse)) return [];
51671
51772
  const candidates = [
51672
51773
  recordField2(recordField2(rawResponse, "toolResponse"), "meta"),
51673
51774
  recordField2(
@@ -51684,7 +51785,7 @@ function extractToolExecutionWarningMessages(rawResponse) {
51684
51785
  for (const warning of warnings) {
51685
51786
  if (typeof warning === "string" && warning.trim()) {
51686
51787
  messages.push(warning.trim());
51687
- } else if (isRecord12(warning)) {
51788
+ } else if (isRecord13(warning)) {
51688
51789
  const message = stringField2(warning, "message");
51689
51790
  if (message) messages.push(message);
51690
51791
  }
@@ -51693,7 +51794,7 @@ function extractToolExecutionWarningMessages(rawResponse) {
51693
51794
  return [...new Set(messages)];
51694
51795
  }
51695
51796
  function apifySyncRecoveryNext(rawResponse) {
51696
- if (!isRecord12(rawResponse) || rawResponse.status !== "running") return null;
51797
+ if (!isRecord13(rawResponse) || rawResponse.status !== "running") return null;
51697
51798
  const toolResponse = recordField2(rawResponse, "toolResponse");
51698
51799
  const raw = recordField2(toolResponse, "raw");
51699
51800
  if (raw.state !== "awaiting_apify") return null;
@@ -51716,7 +51817,7 @@ function apifySyncRecoveryNext(rawResponse) {
51716
51817
  }
51717
51818
  function listExtractorPathsFromUsageGuidance(tool) {
51718
51819
  const toolExecutionResult = tool.usageGuidance?.toolExecutionResult;
51719
- const extractedLists = Array.isArray(toolExecutionResult?.extractedLists) ? toolExecutionResult.extractedLists : isRecord12(toolExecutionResult?.extractedLists) ? Object.values(toolExecutionResult.extractedLists) : [];
51820
+ const extractedLists = Array.isArray(toolExecutionResult?.extractedLists) ? toolExecutionResult.extractedLists : isRecord13(toolExecutionResult?.extractedLists) ? Object.values(toolExecutionResult.extractedLists) : [];
51720
51821
  return extractedLists.flatMap((entry) => {
51721
51822
  const paths = entry.details?.candidatePaths ?? entry.details?.rawToolOutputPaths;
51722
51823
  if (!Array.isArray(paths)) return [];
@@ -51732,7 +51833,7 @@ function formatDecimal(value) {
51732
51833
  function formatUsd(value) {
51733
51834
  return `$${formatDecimal(value)}`;
51734
51835
  }
51735
- function isRecord12(value) {
51836
+ function isRecord13(value) {
51736
51837
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
51737
51838
  }
51738
51839
  function stringField2(source, ...keys) {
@@ -51759,7 +51860,7 @@ function arrayField2(source, ...keys) {
51759
51860
  function recordField2(source, ...keys) {
51760
51861
  for (const key of keys) {
51761
51862
  const value = source[key];
51762
- if (isRecord12(value)) return value;
51863
+ if (isRecord13(value)) return value;
51763
51864
  }
51764
51865
  return {};
51765
51866
  }
@@ -51781,11 +51882,11 @@ function normalizeOutputFormat(raw) {
51781
51882
  }
51782
51883
  function resolveAtFilePath(rawPath) {
51783
51884
  const trimmed = rawPath.trim();
51784
- const resolved = (0, import_node_path31.resolve)(trimmed);
51785
- if ((0, import_node_fs26.existsSync)(resolved)) return resolved;
51885
+ const resolved = (0, import_node_path32.resolve)(trimmed);
51886
+ if ((0, import_node_fs27.existsSync)(resolved)) return resolved;
51786
51887
  if (process.platform !== "win32" && trimmed.includes("\\")) {
51787
- const normalized = (0, import_node_path31.resolve)(trimmed.replace(/\\/g, "/"));
51788
- if ((0, import_node_fs26.existsSync)(normalized)) return normalized;
51888
+ const normalized = (0, import_node_path32.resolve)(trimmed.replace(/\\/g, "/"));
51889
+ if ((0, import_node_fs27.existsSync)(normalized)) return normalized;
51789
51890
  }
51790
51891
  return resolved;
51791
51892
  }
@@ -51796,7 +51897,7 @@ function readJsonArgument(raw, flagName) {
51796
51897
  throw new Error(`Invalid ${flagName} value: empty @file path.`);
51797
51898
  }
51798
51899
  try {
51799
- return (0, import_node_fs26.readFileSync)(resolveAtFilePath(filePath), "utf8").replace(
51900
+ return (0, import_node_fs27.readFileSync)(resolveAtFilePath(filePath), "utf8").replace(
51800
51901
  /^\uFEFF/,
51801
51902
  ""
51802
51903
  );
@@ -51825,7 +51926,7 @@ function parseJsonObjectArgument(raw, flagName) {
51825
51926
  }
51826
51927
  throw invalidJsonError(flagName, message);
51827
51928
  }
51828
- if (!isRecord12(parsed)) {
51929
+ if (!isRecord13(parsed)) {
51829
51930
  throw invalidJsonError(flagName, "expected an object.");
51830
51931
  }
51831
51932
  return parsed;
@@ -51897,7 +51998,7 @@ function parseExecuteOptions(args) {
51897
51998
  continue;
51898
51999
  }
51899
52000
  if ((arg === "--out" || arg === "-o") && args[index + 1]) {
51900
- outPath = (0, import_node_path31.resolve)(args[++index]);
52001
+ outPath = (0, import_node_path32.resolve)(args[++index]);
51901
52002
  continue;
51902
52003
  }
51903
52004
  throw new Error(`Unknown option: ${arg}`);
@@ -51932,70 +52033,6 @@ function parseToolExecuteTimeout(raw) {
51932
52033
  }
51933
52034
  return timeoutMs;
51934
52035
  }
51935
- function pendingToolExecutionPath(input2) {
51936
- const config = resolveConfig();
51937
- const fingerprint = (0, import_node_crypto12.createHash)("sha256").update(config.baseUrl).update("\0").update((0, import_node_crypto12.createHash)("sha256").update(config.apiKey).digest("hex")).update("\0").update(input2.toolId).update("\0").update(stableStringify(input2.params)).update("\0").update(input2.responseIntent).digest("hex");
51938
- return (0, import_node_path31.join)(
51939
- sdkCliStateDirPath(resolveConfig().baseUrl),
51940
- `pending-tool-execution-${fingerprint}.json`
51941
- );
51942
- }
51943
- function loadOrCreatePendingToolExecution(path) {
51944
- (0, import_node_fs26.mkdirSync)((0, import_node_path31.dirname)(path), { recursive: true });
51945
- if ((0, import_node_fs26.existsSync)(path)) {
51946
- return readPendingToolExecution(path);
51947
- }
51948
- const idempotencyKey = (0, import_node_crypto12.randomUUID)();
51949
- const temporaryPath = `${path}.${process.pid}.${(0, import_node_crypto12.randomUUID)()}.tmp`;
51950
- try {
51951
- (0, import_node_fs26.writeFileSync)(temporaryPath, `${JSON.stringify({ idempotencyKey })}
51952
- `, {
51953
- encoding: "utf8",
51954
- flag: "wx",
51955
- mode: 384
51956
- });
51957
- (0, import_node_fs26.linkSync)(temporaryPath, path);
51958
- return idempotencyKey;
51959
- } catch (error) {
51960
- if (error.code !== "EEXIST") throw error;
51961
- return readPendingToolExecution(path);
51962
- } finally {
51963
- if ((0, import_node_fs26.existsSync)(temporaryPath)) (0, import_node_fs26.unlinkSync)(temporaryPath);
51964
- }
51965
- }
51966
- function readPendingToolExecution(path) {
51967
- const saved = JSON.parse((0, import_node_fs26.readFileSync)(path, "utf8"));
51968
- if (typeof saved.idempotencyKey !== "string") {
51969
- throw new Error(
51970
- `Cannot resume the saved tool execution at ${path}: invalid recovery key.`
51971
- );
51972
- }
51973
- return saved.idempotencyKey;
51974
- }
51975
- async function completePendingToolExecution(path, idempotencyKey) {
51976
- if (!path || !idempotencyKey || !(0, import_node_fs26.existsSync)(path)) return;
51977
- await new Promise((resolve22, reject) => {
51978
- const onError = (error) => {
51979
- process.stdout.off("error", onError);
51980
- reject(error);
51981
- };
51982
- process.stdout.once("error", onError);
51983
- process.stdout.write("", (error) => {
51984
- process.stdout.off("error", onError);
51985
- if (error) {
51986
- reject(error);
51987
- } else {
51988
- resolve22();
51989
- }
51990
- });
51991
- });
51992
- try {
51993
- if (readPendingToolExecution(path) !== idempotencyKey) return;
51994
- (0, import_node_fs26.unlinkSync)(path);
51995
- } catch (error) {
51996
- if (error.code !== "ENOENT") throw error;
51997
- }
51998
- }
51999
52036
  function safeFileStem(value) {
52000
52037
  return value.trim().replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64) || "tool";
52001
52038
  }
@@ -52019,9 +52056,9 @@ function starterScriptJson(script) {
52019
52056
  function seedToolListScript(input2) {
52020
52057
  const stem = safeFileStem(input2.toolId);
52021
52058
  const fileName = `${stem}-workflow-seed-${Date.now()}.play.ts`;
52022
- const scriptDir = (0, import_node_fs26.mkdtempSync)((0, import_node_path31.join)((0, import_node_os19.tmpdir)(), "deepline-workflow-seed-"));
52023
- (0, import_node_fs26.chmodSync)(scriptDir, 448);
52024
- const scriptPath = (0, import_node_path31.join)(scriptDir, fileName);
52059
+ const scriptDir = (0, import_node_fs27.mkdtempSync)((0, import_node_path32.join)((0, import_node_os19.tmpdir)(), "deepline-workflow-seed-"));
52060
+ (0, import_node_fs27.chmodSync)(scriptDir, 448);
52061
+ const scriptPath = (0, import_node_path32.join)(scriptDir, fileName);
52025
52062
  const projectDir = `deepline/projects/${stem}-workflow`;
52026
52063
  const playName = `${stem}-workflow`;
52027
52064
  const sampleRows = input2.rows.length > 0 ? `${JSON.stringify(input2.rows.slice(0, 2)).replace(/\]$/, "")}, ...]` : "[]";
@@ -52064,7 +52101,7 @@ export default definePlay(${JSON.stringify(playName)}, async (ctx) => {
52064
52101
  description: ${JSON.stringify(`Seed ${input2.toolId} rows into a Deepline workflow-ready dataset.`)},
52065
52102
  });
52066
52103
  `;
52067
- (0, import_node_fs26.writeFileSync)(scriptPath, script, { encoding: "utf-8", mode: 384 });
52104
+ (0, import_node_fs27.writeFileSync)(scriptPath, script, { encoding: "utf-8", mode: 384 });
52068
52105
  return {
52069
52106
  path: scriptPath,
52070
52107
  sourceCode: script,
@@ -52091,7 +52128,7 @@ function buildToolExecuteBaseEnvelope(input2) {
52091
52128
  kind: summaryEntries.length > 0 ? "object" : "raw",
52092
52129
  summary: input2.summary
52093
52130
  };
52094
- const envelopeHasCanonicalOutput = isRecord12(envelope.toolResponse) && Object.prototype.hasOwnProperty.call(envelope.toolResponse, "raw");
52131
+ const envelopeHasCanonicalOutput = isRecord13(envelope.toolResponse) && Object.prototype.hasOwnProperty.call(envelope.toolResponse, "raw");
52095
52132
  const envelopeHasDeclaredOutput = Object.prototype.hasOwnProperty.call(
52096
52133
  envelope,
52097
52134
  "output"
@@ -52118,7 +52155,7 @@ function buildToolExecuteBaseEnvelope(input2) {
52118
52155
  return {
52119
52156
  ...envelope,
52120
52157
  ...input2.idempotencyKey ? { idempotency_key: input2.idempotencyKey } : {},
52121
- ...isRecord12(input2.rawResponse) && isRecord12(input2.rawResponse.executionRecovery) ? { execution_recovery: input2.rawResponse.executionRecovery } : {},
52158
+ ...isRecord13(input2.rawResponse) && isRecord13(input2.rawResponse.executionRecovery) ? { execution_recovery: input2.rawResponse.executionRecovery } : {},
52122
52159
  ...envelopeHasCanonicalOutput || envelopeHasDeclaredOutput ? { output_preview: outputPreview } : { output: outputPreview },
52123
52160
  ...summaryEntries.length > 0 ? { summary: input2.summary } : {},
52124
52161
  ...warningMessages.length > 0 ? { warnings: warningMessages } : {},
@@ -52177,7 +52214,7 @@ function buildToolExecuteRowArtifactEnvelope(input2) {
52177
52214
  void _render;
52178
52215
  void _next;
52179
52216
  void _local;
52180
- const billingLookup = isRecord12(input2.baseEnvelope.next) && typeof input2.baseEnvelope.next.billing === "string" ? input2.baseEnvelope.next.billing : null;
52217
+ const billingLookup = isRecord13(input2.baseEnvelope.next) && typeof input2.baseEnvelope.next.billing === "string" ? input2.baseEnvelope.next.billing : null;
52181
52218
  return {
52182
52219
  ...base,
52183
52220
  status: typeof base.status === "string" ? base.status : "completed",
@@ -52306,17 +52343,15 @@ async function executeTool(args) {
52306
52343
  }
52307
52344
  return 2;
52308
52345
  }
52309
- let idempotencyKey = parsed.idempotencyKey;
52310
- let pendingRecoveryPath = null;
52311
52346
  const responseIntent = parsed.outPath || parsed.outputFormat === "csv" || parsed.outputFormat === "csv_file" ? "row_artifact" : "raw";
52312
- if (parsed.recover && !idempotencyKey) {
52313
- pendingRecoveryPath = pendingToolExecutionPath({
52314
- toolId: parsed.toolId,
52315
- params: parsed.params,
52316
- responseIntent
52317
- });
52318
- idempotencyKey = loadOrCreatePendingToolExecution(pendingRecoveryPath);
52319
- }
52347
+ const recovery = ToolCallRecovery.open({
52348
+ toolId: parsed.toolId,
52349
+ params: parsed.params,
52350
+ responseIntent,
52351
+ recover: parsed.recover,
52352
+ idempotencyKey: parsed.idempotencyKey
52353
+ });
52354
+ const { idempotencyKey } = recovery;
52320
52355
  if (idempotencyKey) {
52321
52356
  console.error(`Tool execution recovery key: ${idempotencyKey}`);
52322
52357
  }
@@ -52341,42 +52376,12 @@ async function executeTool(args) {
52341
52376
  summary
52342
52377
  });
52343
52378
  const executeExitCode = toolExecuteExitCode(baseEnvelope);
52344
- if (!parsed.outPath && (parsed.outputFormat === "json" || parsed.outputFormat === "auto" && shouldEmitJson())) {
52345
- printCommandEnvelope(baseEnvelope, { json: true });
52346
- await completePendingToolExecution(pendingRecoveryPath, idempotencyKey);
52347
- return executeExitCode;
52348
- }
52349
- if (parsed.outputFormat === "json_file") {
52350
- const jsonPath = writeJsonOutputFile(
52351
- rawResponse,
52352
- `payload_${parsed.toolId}`
52353
- );
52354
- printCommandEnvelope(
52355
- {
52356
- ...baseEnvelope,
52357
- local: {
52358
- ...isRecord12(baseEnvelope.local) ? baseEnvelope.local : {},
52359
- payload_file: jsonPath
52360
- }
52361
- },
52362
- { json: true }
52363
- );
52364
- await completePendingToolExecution(pendingRecoveryPath, idempotencyKey);
52365
- return executeExitCode;
52366
- }
52367
- if (!listConversion) {
52368
- if (parsed.outPath) {
52369
- const error = new Error(
52370
- `${parsed.toolId} did not expose row-shaped output to write as CSV. Re-run with --json to inspect the raw tool response.`
52371
- );
52372
- if (argsWantJson(args)) {
52373
- printJsonError(error);
52374
- } else {
52375
- console.error(error.message);
52376
- }
52377
- return 1;
52379
+ const delivered = (() => {
52380
+ if (!parsed.outPath && (parsed.outputFormat === "json" || parsed.outputFormat === "auto" && shouldEmitJson())) {
52381
+ printCommandEnvelope(baseEnvelope, { json: true });
52382
+ return true;
52378
52383
  }
52379
- if (parsed.outputFormat === "csv" || parsed.outputFormat === "csv_file") {
52384
+ if (parsed.outputFormat === "json_file") {
52380
52385
  const jsonPath = writeJsonOutputFile(
52381
52386
  rawResponse,
52382
52387
  `payload_${parsed.toolId}`
@@ -52385,68 +52390,94 @@ async function executeTool(args) {
52385
52390
  {
52386
52391
  ...baseEnvelope,
52387
52392
  local: {
52393
+ ...isRecord13(baseEnvelope.local) ? baseEnvelope.local : {},
52388
52394
  payload_file: jsonPath
52389
52395
  }
52390
52396
  },
52391
- { json: parsed.outputFormat === "csv_file" || shouldEmitJson() }
52397
+ { json: true }
52392
52398
  );
52393
- await completePendingToolExecution(pendingRecoveryPath, idempotencyKey);
52394
- return executeExitCode;
52399
+ return true;
52395
52400
  }
52396
- printCommandEnvelope(baseEnvelope, { json: false });
52397
- await completePendingToolExecution(pendingRecoveryPath, idempotencyKey);
52398
- return executeExitCode;
52399
- }
52400
- const rowOutput = projectRowOutput(listConversion);
52401
- const csv = writeCsvOutputFile(
52402
- listConversion.rows,
52403
- `${parsed.toolId}_output`,
52404
- parsed.outPath ? { outPath: parsed.outPath } : void 0
52405
- );
52406
- const seededScript = seedToolListScript({
52407
- toolId: parsed.toolId,
52408
- payload: parsed.params,
52409
- rows: listConversion.rows
52410
- });
52411
- const materializedEnvelope = buildToolExecuteRowArtifactEnvelope({
52412
- baseEnvelope,
52413
- csv,
52414
- rowOutput,
52415
- summary,
52416
- seededScript
52417
- });
52418
- if (parsed.outputFormat === "csv_file") {
52419
- printCommandEnvelope(materializedEnvelope, { json: true });
52420
- await completePendingToolExecution(pendingRecoveryPath, idempotencyKey);
52421
- return executeExitCode;
52422
- }
52423
- if (parsed.outPath) {
52424
- printCommandEnvelope(materializedEnvelope, {
52425
- json: argsWantJson(args) || shouldEmitJson(),
52426
- text: `Wrote ${csv.rowCount} row(s) to ${csv.path}
52427
- `
52428
- });
52429
- await completePendingToolExecution(pendingRecoveryPath, idempotencyKey);
52430
- return executeExitCode;
52431
- }
52432
- if (parsed.noPreview) {
52433
- printCommandEnvelope(
52434
- {
52435
- ...materializedEnvelope,
52436
- local: {
52437
- ...materializedEnvelope.local ?? {},
52438
- output_path: csv.path
52401
+ if (!listConversion) {
52402
+ if (parsed.outPath) {
52403
+ const error = new Error(
52404
+ `${parsed.toolId} did not expose row-shaped output to write as CSV. Re-run with --json to inspect the raw tool response.`
52405
+ );
52406
+ if (argsWantJson(args)) {
52407
+ printJsonError(error);
52408
+ } else {
52409
+ console.error(error.message);
52439
52410
  }
52440
- },
52441
- { json: shouldEmitJson(), text: `${csv.path}
52442
- ` }
52411
+ return false;
52412
+ }
52413
+ if (parsed.outputFormat === "csv" || parsed.outputFormat === "csv_file") {
52414
+ const jsonPath = writeJsonOutputFile(
52415
+ rawResponse,
52416
+ `payload_${parsed.toolId}`
52417
+ );
52418
+ printCommandEnvelope(
52419
+ {
52420
+ ...baseEnvelope,
52421
+ local: {
52422
+ payload_file: jsonPath
52423
+ }
52424
+ },
52425
+ { json: parsed.outputFormat === "csv_file" || shouldEmitJson() }
52426
+ );
52427
+ return true;
52428
+ }
52429
+ printCommandEnvelope(baseEnvelope, { json: false });
52430
+ return true;
52431
+ }
52432
+ const rowOutput = projectRowOutput(listConversion);
52433
+ const csv = writeCsvOutputFile(
52434
+ listConversion.rows,
52435
+ `${parsed.toolId}_output`,
52436
+ parsed.outPath ? { outPath: parsed.outPath } : void 0
52443
52437
  );
52444
- await completePendingToolExecution(pendingRecoveryPath, idempotencyKey);
52445
- return executeExitCode;
52446
- }
52447
- printCommandEnvelope(materializedEnvelope, { json: false });
52448
- await completePendingToolExecution(pendingRecoveryPath, idempotencyKey);
52449
- return executeExitCode;
52438
+ const seededScript = seedToolListScript({
52439
+ toolId: parsed.toolId,
52440
+ payload: parsed.params,
52441
+ rows: listConversion.rows
52442
+ });
52443
+ const materializedEnvelope = buildToolExecuteRowArtifactEnvelope({
52444
+ baseEnvelope,
52445
+ csv,
52446
+ rowOutput,
52447
+ summary,
52448
+ seededScript
52449
+ });
52450
+ if (parsed.outputFormat === "csv_file") {
52451
+ printCommandEnvelope(materializedEnvelope, { json: true });
52452
+ return true;
52453
+ }
52454
+ if (parsed.outPath) {
52455
+ printCommandEnvelope(materializedEnvelope, {
52456
+ json: argsWantJson(args) || shouldEmitJson(),
52457
+ text: `Wrote ${csv.rowCount} row(s) to ${csv.path}
52458
+ `
52459
+ });
52460
+ return true;
52461
+ }
52462
+ if (parsed.noPreview) {
52463
+ printCommandEnvelope(
52464
+ {
52465
+ ...materializedEnvelope,
52466
+ local: {
52467
+ ...materializedEnvelope.local ?? {},
52468
+ output_path: csv.path
52469
+ }
52470
+ },
52471
+ { json: shouldEmitJson(), text: `${csv.path}
52472
+ ` }
52473
+ );
52474
+ return true;
52475
+ }
52476
+ printCommandEnvelope(materializedEnvelope, { json: false });
52477
+ return true;
52478
+ })();
52479
+ if (delivered) await recovery.acknowledgeDelivery();
52480
+ return delivered ? executeExitCode : 1;
52450
52481
  }
52451
52482
 
52452
52483
  // src/cli/commands/providers.ts
@@ -52528,7 +52559,7 @@ Examples:
52528
52559
 
52529
52560
  // src/cli/commands/workflow.ts
52530
52561
  var import_promises14 = require("fs/promises");
52531
- var import_node_path32 = require("path");
52562
+ var import_node_path33 = require("path");
52532
52563
 
52533
52564
  // src/cli/workflow-to-play.ts
52534
52565
  var import_node_crypto13 = require("crypto");
@@ -52745,7 +52776,7 @@ function readStatus(payload) {
52745
52776
  }
52746
52777
  async function readJsonOption(payload, file) {
52747
52778
  if (file) {
52748
- const raw = await (0, import_promises14.readFile)((0, import_node_path32.resolve)(file), "utf8");
52779
+ const raw = await (0, import_promises14.readFile)((0, import_node_path33.resolve)(file), "utf8");
52749
52780
  return JSON.parse(raw);
52750
52781
  }
52751
52782
  if (payload) {
@@ -52779,8 +52810,8 @@ async function transformOne(api, workflowId, outDir, publish) {
52779
52810
  revision.config,
52780
52811
  { workflowName: workflow.name, version: revision.version }
52781
52812
  );
52782
- const file = (0, import_node_path32.join)((0, import_node_path32.resolve)(outDir), `${compiled.playName}.play.ts`);
52783
- await (0, import_promises14.mkdir)((0, import_node_path32.dirname)(file), { recursive: true });
52813
+ const file = (0, import_node_path33.join)((0, import_node_path33.resolve)(outDir), `${compiled.playName}.play.ts`);
52814
+ await (0, import_promises14.mkdir)((0, import_node_path33.dirname)(file), { recursive: true });
52784
52815
  await (0, import_promises14.writeFile)(file, compiled.sourceCode, "utf8");
52785
52816
  let published = false;
52786
52817
  if (publish) {
@@ -53326,8 +53357,8 @@ function topLevelCommandKnown(program, commandName) {
53326
53357
  );
53327
53358
  }
53328
53359
  async function runPlayRunnerHealthCheck() {
53329
- const dir = await (0, import_promises15.mkdtemp)((0, import_node_path33.join)((0, import_node_os20.tmpdir)(), "deepline-health-play-"));
53330
- const file = (0, import_node_path33.join)(dir, "health-check.play.ts");
53360
+ const dir = await (0, import_promises15.mkdtemp)((0, import_node_path34.join)((0, import_node_os20.tmpdir)(), "deepline-health-play-"));
53361
+ const file = (0, import_node_path34.join)(dir, "health-check.play.ts");
53331
53362
  try {
53332
53363
  await (0, import_promises15.writeFile)(
53333
53364
  file,