deepline 0.1.174 → 0.1.176

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.
@@ -607,10 +607,10 @@ var SDK_RELEASE = {
607
607
  // 0.1.111 ships dataset-native tool list getters and result row datasets.
608
608
  // 0.1.154 removes the short-lived generated enrich StepOptions recompute
609
609
  // fields shipped in 0.1.153.
610
- version: "0.1.174",
610
+ version: "0.1.176",
611
611
  apiContract: "2026-06-dataset-handle-results-hard-cutover",
612
612
  supportPolicy: {
613
- latest: "0.1.174",
613
+ latest: "0.1.176",
614
614
  minimumSupported: "0.1.53",
615
615
  deprecatedBelow: "0.1.53",
616
616
  commandMinimumSupported: [
@@ -871,9 +871,10 @@ var HttpClient = class {
871
871
  headers["Content-Type"] = "application/json";
872
872
  }
873
873
  let lastError = null;
874
- const candidateUrls = buildCandidateUrls(url);
874
+ const candidateUrls = options?.exactUrlOnly ? [url] : buildCandidateUrls(url);
875
875
  let retryAfterDelayMs = null;
876
- for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
876
+ const maxRetries = options?.maxRetries ?? this.config.maxRetries;
877
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
877
878
  if (attempt > 0) {
878
879
  const backoffMs = Math.min(1e3 * Math.pow(2, attempt - 1), 3e4);
879
880
  const delayMs = retryAfterDelayMs === null ? backoffMs : Math.max(backoffMs, retryAfterDelayMs);
@@ -900,7 +901,7 @@ var HttpClient = class {
900
901
  if (response.status === 429) {
901
902
  const retryAfter = parseRetryAfter(response);
902
903
  lastError = new RateLimitError(retryAfter);
903
- if (attempt < this.config.maxRetries) {
904
+ if (attempt < maxRetries) {
904
905
  retryAfterDelayMs = retryAfter;
905
906
  break;
906
907
  }
@@ -930,7 +931,7 @@ var HttpClient = class {
930
931
  ...htmlError.workerThrewException ? { workerThrewException: true } : {}
931
932
  }
932
933
  );
933
- if (retryableApiError && attempt < this.config.maxRetries) {
934
+ if (retryableApiError && attempt < maxRetries) {
934
935
  retryAfterDelayMs = parseOptionalRetryAfter(response);
935
936
  break;
936
937
  }
@@ -942,7 +943,7 @@ var HttpClient = class {
942
943
  lastError = new DeeplineError(msg, response.status, apiErrorCode, {
943
944
  response: parsed
944
945
  });
945
- if (retryableApiError && attempt < this.config.maxRetries) {
946
+ if (retryableApiError && attempt < maxRetries) {
946
947
  retryAfterDelayMs = parseOptionalRetryAfter(response);
947
948
  break;
948
949
  }
@@ -961,7 +962,7 @@ var HttpClient = class {
961
962
  lastError = error instanceof Error ? error : new Error(String(error));
962
963
  }
963
964
  }
964
- if (attempt < this.config.maxRetries) continue;
965
+ if (attempt < maxRetries) continue;
965
966
  }
966
967
  if (lastError instanceof DeeplineError) {
967
968
  throw lastError;
@@ -2096,6 +2097,7 @@ var COMPILE_MANIFEST_RETRY_DELAYS_MS = [250, 1e3];
2096
2097
  var REGISTER_PLAY_ARTIFACTS_COMPILE_CONCURRENCY = 3;
2097
2098
  var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_COUNT = 3;
2098
2099
  var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_BYTES = 25e5;
2100
+ var DEEPLINEAGENT_EXECUTE_TIMEOUT_MS = 15 * 60 * 1e3;
2099
2101
  function normalizePlayRunIntegrationMode(value) {
2100
2102
  if (value === "live" || value === "eval_stub" || value === "fixture") {
2101
2103
  return value;
@@ -2170,6 +2172,10 @@ function chunkRegisterPlayArtifacts(artifacts) {
2170
2172
  }
2171
2173
  return chunks;
2172
2174
  }
2175
+ function resolveToolExecuteTimeoutMs(toolId) {
2176
+ const normalized = toolId.trim().toLowerCase();
2177
+ return normalized === "deeplineagent" || normalized === "deeplineagent_deeplineagent" || normalized === "ai_inference" || normalized === "deeplineagent_ai_inference" || normalized === "aiinference" ? DEEPLINEAGENT_EXECUTE_TIMEOUT_MS : void 0;
2178
+ }
2173
2179
  var RUN_LOGS_PAGE_LIMIT = 1e3;
2174
2180
  function isRecord3(value) {
2175
2181
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
@@ -2609,7 +2615,12 @@ var DeeplineClient = class {
2609
2615
  `/api/v2/integrations/${encodeURIComponent(toolId)}/execute`,
2610
2616
  { payload: input2 },
2611
2617
  headers,
2612
- { forbiddenAsApiError: true }
2618
+ {
2619
+ forbiddenAsApiError: true,
2620
+ timeout: options?.timeout ?? resolveToolExecuteTimeoutMs(toolId),
2621
+ maxRetries: options?.maxRetries ?? 0,
2622
+ exactUrlOnly: true
2623
+ }
2613
2624
  );
2614
2625
  }
2615
2626
  /**
@@ -2671,6 +2682,7 @@ var DeeplineClient = class {
2671
2682
  */
2672
2683
  async startPlayRun(request) {
2673
2684
  const integrationMode = resolvePlayRunIntegrationMode(request);
2685
+ const forceToolRefresh = request.forceToolRefresh === true;
2674
2686
  const response = await this.http.post(
2675
2687
  "/api/v2/plays/run",
2676
2688
  {
@@ -2691,6 +2703,7 @@ var DeeplineClient = class {
2691
2703
  ...request.inputFile ? { inputFile: request.inputFile } : {},
2692
2704
  ...request.packagedFiles?.length ? { packagedFiles: request.packagedFiles } : {},
2693
2705
  ...request.force ? { force: true } : {},
2706
+ ...forceToolRefresh ? { forceToolRefresh: true } : {},
2694
2707
  ...typeof request.waitForCompletionMs === "number" ? { waitForCompletionMs: request.waitForCompletionMs } : {},
2695
2708
  // Profile selection is the API's job, not the CLI's. The server
2696
2709
  // defaults to workers_edge; tests and runtime probes that want a
@@ -2714,6 +2727,7 @@ var DeeplineClient = class {
2714
2727
  */
2715
2728
  async *startPlayRunStream(request, options) {
2716
2729
  const integrationMode = resolvePlayRunIntegrationMode(request);
2730
+ const forceToolRefresh = request.forceToolRefresh === true;
2717
2731
  const body = {
2718
2732
  ...request.name ? { name: request.name } : {},
2719
2733
  ...request.revisionId ? { revisionId: request.revisionId } : {},
@@ -2732,6 +2746,7 @@ var DeeplineClient = class {
2732
2746
  ...request.inputFile ? { inputFile: request.inputFile } : {},
2733
2747
  ...request.packagedFiles?.length ? { packagedFiles: request.packagedFiles } : {},
2734
2748
  ...request.force ? { force: true } : {},
2749
+ ...forceToolRefresh ? { forceToolRefresh: true } : {},
2735
2750
  ...typeof request.waitForCompletionMs === "number" ? { waitForCompletionMs: request.waitForCompletionMs } : {},
2736
2751
  ...request.profile ? { profile: request.profile } : {},
2737
2752
  ...integrationMode ? { integrationMode } : {}
@@ -2903,7 +2918,8 @@ var DeeplineClient = class {
2903
2918
  ...input2.input ? { input: input2.input } : {},
2904
2919
  ...input2.inputFile ? { inputFile: input2.inputFile } : {},
2905
2920
  ...input2.packagedFiles?.length ? { packagedFiles: input2.packagedFiles } : {},
2906
- ...input2.force ? { force: true } : {}
2921
+ ...input2.force ? { force: true } : {},
2922
+ ...input2.forceToolRefresh ? { forceToolRefresh: true } : {}
2907
2923
  });
2908
2924
  }
2909
2925
  /**
@@ -2976,7 +2992,8 @@ var DeeplineClient = class {
2976
2992
  ...Object.keys(runtimeInput).length > 0 ? { input: runtimeInput } : {},
2977
2993
  ...options?.inputFile ? { inputFile: options.inputFile } : {},
2978
2994
  ...options?.packagedFiles?.length ? { packagedFiles: options.packagedFiles } : {},
2979
- ...options?.force ? { force: true } : {}
2995
+ ...options?.force ? { force: true } : {},
2996
+ ...options?.forceToolRefresh ? { forceToolRefresh: true } : {}
2980
2997
  });
2981
2998
  }
2982
2999
  /**
@@ -3858,7 +3875,8 @@ var DeeplineClient = class {
3858
3875
  compilerManifest: options?.compilerManifest,
3859
3876
  inputFile: options?.inputFile,
3860
3877
  packagedFiles: options?.packagedFiles,
3861
- force: options?.force
3878
+ force: options?.force,
3879
+ forceToolRefresh: options?.forceToolRefresh
3862
3880
  });
3863
3881
  const start = Date.now();
3864
3882
  const state = {
@@ -4562,10 +4580,21 @@ function failureMessageFromRecord(value) {
4562
4580
  }
4563
4581
  return directError || resultError || `Column status: ${status}`;
4564
4582
  }
4565
- function flattenObjectColumns(row) {
4583
+ function shouldPreserveJsonStringColumn(columns, key) {
4584
+ if (!columns) {
4585
+ return false;
4586
+ }
4587
+ if (columns.has(key)) {
4588
+ return true;
4589
+ }
4590
+ const normalizedKey = key.toLowerCase().replace(/[^a-z0-9]/g, "");
4591
+ return normalizedKey ? columns.has(normalizedKey) : false;
4592
+ }
4593
+ function flattenObjectColumns(row, options = {}) {
4566
4594
  const flattened = {};
4567
4595
  for (const [key, rawValue] of Object.entries(row)) {
4568
4596
  const value = parseMaybeJsonObject(rawValue);
4597
+ const parsedFromString = typeof rawValue === "string" && value !== rawValue;
4569
4598
  if (key === "_metadata") {
4570
4599
  flattened[key] = value && typeof value === "object" ? JSON.stringify(value) : value;
4571
4600
  continue;
@@ -4576,6 +4605,10 @@ function flattenObjectColumns(row) {
4576
4605
  if (hasMatchedEnvelope) {
4577
4606
  flattened[key] = JSON.stringify(record);
4578
4607
  continue;
4608
+ }
4609
+ if (parsedFromString && shouldPreserveJsonStringColumn(options.preserveJsonStringColumns, key)) {
4610
+ flattened[key] = rawValue;
4611
+ continue;
4579
4612
  } else {
4580
4613
  const failureMessage = failureMessageFromRecord(record);
4581
4614
  if (failureMessage) {
@@ -4600,8 +4633,8 @@ function recordRows(value) {
4600
4633
  (row) => Boolean(row) && typeof row === "object" && !Array.isArray(row)
4601
4634
  );
4602
4635
  }
4603
- function dataExportRows(rows) {
4604
- return rows.map((row) => flattenObjectColumns(row));
4636
+ function dataExportRows(rows, options = {}) {
4637
+ return rows.map((row) => flattenObjectColumns(row, options));
4605
4638
  }
4606
4639
  function dataExportColumns(rows, preferredColumns = []) {
4607
4640
  const discoveredColumns = [
@@ -13384,7 +13417,7 @@ async function handleFileBackedRun(options) {
13384
13417
  ...Object.keys(runtimeInput).length > 0 ? { input: runtimeInput } : {},
13385
13418
  ...stagedFileInputs.inputFile ? { inputFile: stagedFileInputs.inputFile } : {},
13386
13419
  ...stagedFileInputs.packagedFiles.length ? { packagedFiles: stagedFileInputs.packagedFiles } : {},
13387
- ...options.force ? { force: true } : {},
13420
+ ...options.force ? { force: true, forceToolRefresh: true } : {},
13388
13421
  ...options.profile ? { profile: options.profile } : {},
13389
13422
  ...integrationMode ? { integrationMode } : {}
13390
13423
  };
@@ -13543,7 +13576,7 @@ async function handleNamedRun(options) {
13543
13576
  ...Object.keys(runtimeInput).length > 0 ? { input: runtimeInput } : {},
13544
13577
  ...stagedFileInputs.inputFile ? { inputFile: stagedFileInputs.inputFile } : {},
13545
13578
  ...stagedFileInputs.packagedFiles.length ? { packagedFiles: stagedFileInputs.packagedFiles } : {},
13546
- ...options.force ? { force: true } : {},
13579
+ ...options.force ? { force: true, forceToolRefresh: true } : {},
13547
13580
  ...options.profile ? { profile: options.profile } : {},
13548
13581
  ...integrationMode ? { integrationMode } : {}
13549
13582
  };
@@ -14729,9 +14762,9 @@ Notes:
14729
14762
  a fire-and-forget run id.
14730
14763
  The play page opens in your browser as soon as the run starts; use --no-open
14731
14764
  to only print the URL.
14732
- Concurrent runs for the same play are allowed. --force is accepted for
14733
- compatibility, but it does not cancel active sibling runs or bypass completed
14734
- reuse.
14765
+ Concurrent runs for the same play are allowed.
14766
+ --force bypasses durable dataset/tool cache reuse for this run.
14767
+ It does not cancel active sibling runs.
14735
14768
  This command starts cloud work and may spend Deepline credits through tool calls.
14736
14769
 
14737
14770
  Idempotent execution:
@@ -14782,7 +14815,7 @@ Examples:
14782
14815
  ).option("--watch", "Compatibility alias; run waits by default").option("--wait", "Compatibility alias; run waits by default").option("--no-wait", "Start the run and return immediately").option(
14783
14816
  "--logs",
14784
14817
  "When output is non-interactive, stream play logs to stderr while waiting"
14785
- ).option("--tail-timeout-ms <ms>", "Timeout while watching the run stream").option("--force", "Compatibility flag; active sibling runs are allowed").option("--no-open", "Print the play page URL without opening a browser").option("--json", "Emit JSON output").option("--full", "Debug only: with --json, emit the raw status payload").addHelpText(
14818
+ ).option("--tail-timeout-ms <ms>", "Timeout while watching the run stream").option("--force", "Bypass durable dataset/tool cache reuse").option("--no-open", "Print the play page URL without opening a browser").option("--json", "Emit JSON output").option("--full", "Debug only: with --json, emit the raw status payload").addHelpText(
14786
14819
  "afterAll",
14787
14820
  `
14788
14821
  Pass-through input flags:
@@ -16903,7 +16936,8 @@ function helperSource() {
16903
16936
  // src/cli/commands/enrich.ts
16904
16937
  var ENRICH_EXPORT_PAGE_SIZE = 5e3;
16905
16938
  var ENRICH_AUTO_BATCH_ROWS = 250;
16906
- var ENRICH_HEAVY_PLAY_AUTO_BATCH_ROWS = 40;
16939
+ var ENRICH_HEAVY_PLAY_AUTO_BATCH_ROWS = 25;
16940
+ var ENRICH_NESTED_PROVIDER_AUTO_BATCH_ROWS = 50;
16907
16941
  var ENRICH_EXPORT_BACKING_ROWS_WAIT_MS = 6e4;
16908
16942
  var ENRICH_EXPORT_BACKING_ROWS_POLL_MS = 1e3;
16909
16943
  var ENRICH_SOURCE_ROW_INDEX_COLUMN = "__deeplineSourceRowIndex";
@@ -16918,6 +16952,12 @@ var HEAVY_ENRICH_AUTO_BATCH_PLAYS = /* @__PURE__ */ new Set([
16918
16952
  "company-to-contact-by-role-waterfall",
16919
16953
  "company_to_contact_by_role_waterfall"
16920
16954
  ]);
16955
+ var HEAVY_ENRICH_AUTO_BATCH_TOOLS = /* @__PURE__ */ new Set([
16956
+ "ai_inference",
16957
+ "aiinference",
16958
+ "deeplineagent"
16959
+ ]);
16960
+ var ENRICH_TEST_AI_INFERENCE_PAYLOAD_MARKER = "__deeplineTestAiInference";
16921
16961
  var PLAN_SHAPING_OPTION_NAMES = [
16922
16962
  "with",
16923
16963
  "withWaterfall",
@@ -16935,6 +16975,15 @@ function normalizeAlias2(value) {
16935
16975
  function hasPlanShapingArgs(args) {
16936
16976
  return optionWasProvided(args, "--with") || optionWasProvided(args, "--with-waterfall") || optionWasProvided(args, "--min-results") || optionWasProvided(args, "--end-waterfall");
16937
16977
  }
16978
+ function isMarkedTestAiInferenceCommand(command) {
16979
+ if ("with_waterfall" in command) {
16980
+ return false;
16981
+ }
16982
+ if (normalizeEnrichPlayRef(command.tool) !== "run_javascript") {
16983
+ return false;
16984
+ }
16985
+ return isRecord7(command.payload) && command.payload[ENRICH_TEST_AI_INFERENCE_PAYLOAD_MARKER] === true;
16986
+ }
16938
16987
  function enrichDebugEnabled(env = process.env) {
16939
16988
  const raw = String(env.DEEPLINE_DEBUG_ENRICH ?? "").trim().toLowerCase();
16940
16989
  if (["1", "true", "yes", "on"].includes(raw)) {
@@ -17702,8 +17751,6 @@ function normalizeEnrichPlayRef(value) {
17702
17751
  return normalized || null;
17703
17752
  }
17704
17753
  function configContainsHeavyEnrichPlay(config) {
17705
- let hasNestedPlayStep = false;
17706
- let hasSubrequestProviderStep = false;
17707
17754
  const visit = (commands) => {
17708
17755
  for (const command of commands) {
17709
17756
  if ("with_waterfall" in command) {
@@ -17727,18 +17774,67 @@ function configContainsHeavyEnrichPlay(config) {
17727
17774
  return true;
17728
17775
  }
17729
17776
  const normalizedTool = normalizeEnrichPlayRef(command.tool);
17777
+ const normalizedOperation = normalizeEnrichPlayRef(command.operation);
17778
+ if (isMarkedTestAiInferenceCommand(command) || normalizedTool && HEAVY_ENRICH_AUTO_BATCH_TOOLS.has(normalizedTool) || normalizedOperation && HEAVY_ENRICH_AUTO_BATCH_TOOLS.has(normalizedOperation)) {
17779
+ return true;
17780
+ }
17781
+ }
17782
+ return false;
17783
+ };
17784
+ return visit(config.commands);
17785
+ }
17786
+ function configContainsNestedProviderEnrichWorkload(config) {
17787
+ let hasNestedPlayStep = false;
17788
+ let hasSubrequestProviderStep = false;
17789
+ const visit = (commands) => {
17790
+ for (const command of commands) {
17791
+ if ("with_waterfall" in command) {
17792
+ visit(command.commands);
17793
+ continue;
17794
+ }
17795
+ if (command.disabled) {
17796
+ continue;
17797
+ }
17798
+ const normalizedTool = normalizeEnrichPlayRef(command.tool);
17730
17799
  if (command.play || normalizedTool === "test-play") {
17731
17800
  hasNestedPlayStep = true;
17732
17801
  } else if (normalizedTool !== null && normalizedTool !== "run_javascript") {
17733
17802
  hasSubrequestProviderStep = true;
17734
17803
  }
17735
17804
  }
17736
- return false;
17737
17805
  };
17738
- return visit(config.commands) || hasNestedPlayStep && hasSubrequestProviderStep;
17806
+ visit(config.commands);
17807
+ return hasNestedPlayStep && hasSubrequestProviderStep;
17739
17808
  }
17740
17809
  function enrichAutoBatchRowsForConfig(config) {
17741
- return configContainsHeavyEnrichPlay(config) ? ENRICH_HEAVY_PLAY_AUTO_BATCH_ROWS : ENRICH_AUTO_BATCH_ROWS;
17810
+ if (configContainsHeavyEnrichPlay(config)) {
17811
+ return ENRICH_HEAVY_PLAY_AUTO_BATCH_ROWS;
17812
+ }
17813
+ if (configContainsNestedProviderEnrichWorkload(config)) {
17814
+ return ENRICH_NESTED_PROVIDER_AUTO_BATCH_ROWS;
17815
+ }
17816
+ return ENRICH_AUTO_BATCH_ROWS;
17817
+ }
17818
+ function enrichAiRuntimeCompactAliases(config) {
17819
+ const aliases = /* @__PURE__ */ new Set();
17820
+ const visit = (commands) => {
17821
+ for (const command of commands) {
17822
+ if ("with_waterfall" in command) {
17823
+ visit(command.commands);
17824
+ continue;
17825
+ }
17826
+ if (command.disabled) {
17827
+ continue;
17828
+ }
17829
+ const normalizedTool = normalizeEnrichPlayRef(command.tool);
17830
+ const normalizedOperation = normalizeEnrichPlayRef(command.operation);
17831
+ if (isMarkedTestAiInferenceCommand(command) || normalizedTool && HEAVY_ENRICH_AUTO_BATCH_TOOLS.has(normalizedTool) || normalizedOperation && HEAVY_ENRICH_AUTO_BATCH_TOOLS.has(normalizedOperation)) {
17832
+ aliases.add(normalizeAlias2(command.alias));
17833
+ }
17834
+ }
17835
+ };
17836
+ visit(config.commands);
17837
+ return aliases;
17742
17838
  }
17743
17839
  async function maybeWriteOutputCsv(input2) {
17744
17840
  if (!input2.outputPath) return null;
@@ -17834,6 +17930,52 @@ function selectedSourceCsvRange(sourceCsvPath, rows) {
17834
17930
  sourceRows
17835
17931
  };
17836
17932
  }
17933
+ function compactRuntimeCsvCell(value) {
17934
+ const parsed = parseMaybeJsonObject(value);
17935
+ const compacted = compactAiInferenceCellForCsv(parsed);
17936
+ return materializeCsvCellValue(compacted);
17937
+ }
17938
+ async function writeSlimBatchedRuntimeCsv(input2) {
17939
+ const cleanRows = readCsvRows(input2.cleanSourceCsvPath).map(
17940
+ (row) => ({ ...row })
17941
+ );
17942
+ const mergeRows = readCsvRows(input2.mergeSourceCsvPath);
17943
+ const preserveJsonStringColumns = /* @__PURE__ */ new Set([
17944
+ ...cleanRows.flatMap((row) => Object.keys(row)),
17945
+ ...mergeRows.flatMap((row) => Object.keys(row))
17946
+ ]);
17947
+ const selectedRange = selectedSourceCsvRange(
17948
+ input2.mergeSourceCsvPath,
17949
+ input2.rows
17950
+ );
17951
+ for (let rowIndex = selectedRange.start; rowIndex <= selectedRange.end; rowIndex += 1) {
17952
+ const mergeRow = mergeRows[rowIndex];
17953
+ if (!mergeRow) {
17954
+ continue;
17955
+ }
17956
+ const baseRow = cleanRows[rowIndex] ?? {};
17957
+ const compactOverlayCell = ([key, value]) => {
17958
+ return [
17959
+ key,
17960
+ input2.compactAliases.has(normalizeAlias2(key)) ? compactRuntimeCsvCell(value) : value
17961
+ ];
17962
+ };
17963
+ cleanRows[rowIndex] = {
17964
+ ...baseRow,
17965
+ ...Object.fromEntries(
17966
+ Object.entries(mergeRow).map(compactOverlayCell)
17967
+ )
17968
+ };
17969
+ }
17970
+ const columns = dataExportColumns(
17971
+ dataExportRows(cleanRows, { preserveJsonStringColumns })
17972
+ );
17973
+ await writeFile3(
17974
+ input2.outputPath,
17975
+ csvStringFromRows(cleanRows, columns),
17976
+ "utf8"
17977
+ );
17978
+ }
17837
17979
  function selectedSourceCsvRowCount(options) {
17838
17980
  if (!options?.sourceCsvPath) {
17839
17981
  return null;
@@ -18140,6 +18282,22 @@ function mergeExportedSheetRow(target, next) {
18140
18282
  target._metadata = metadata;
18141
18283
  }
18142
18284
  }
18285
+ function countEnrichedRowsInSourceRange(exportResult, rows) {
18286
+ const start = Math.max(0, rows.rowStart ?? 0);
18287
+ const end = rows.rowEnd === null || rows.rowEnd === void 0 ? Number.MAX_SAFE_INTEGER : Math.max(start, rows.rowEnd);
18288
+ const rowIndexes = /* @__PURE__ */ new Set();
18289
+ for (const row of exportResult.enrichedDataRows) {
18290
+ const rowIndex = sourceRowIndexFromEnrichRow(row, start, end);
18291
+ if (rowIndex !== null) {
18292
+ rowIndexes.add(rowIndex);
18293
+ }
18294
+ }
18295
+ if (rowIndexes.size > 0) {
18296
+ return rowIndexes.size;
18297
+ }
18298
+ const selectedRows = end === Number.MAX_SAFE_INTEGER ? exportResult.enrichedRows : end - start + 1;
18299
+ return Math.min(exportResult.enrichedRows, Math.max(0, selectedRows));
18300
+ }
18143
18301
  function coalesceExportableSheetRows(rows, sourceRowStart = 0) {
18144
18302
  const mergedRows = [];
18145
18303
  const bySourceRowIndex = /* @__PURE__ */ new Map();
@@ -18771,10 +18929,12 @@ async function fetchBackingRowsForCsvExport(input2) {
18771
18929
  };
18772
18930
  }
18773
18931
  function mergeRowsForCsvExport(enrichedRows, options) {
18932
+ const compactAliases = options?.config ? enrichAiRuntimeCompactAliases(options.config) : /* @__PURE__ */ new Set();
18774
18933
  const rows = dataExportRows(
18775
18934
  normalizeEnrichRowsForCsvExport(enrichedRows, options?.config, {
18776
18935
  statusFailureMessages: options?.statusFailureMessages
18777
- })
18936
+ }),
18937
+ { preserveJsonStringColumns: compactAliases }
18778
18938
  );
18779
18939
  const range = options?.rows;
18780
18940
  if (!options?.sourceCsvPath) {
@@ -18794,16 +18954,16 @@ function mergeRowsForCsvExport(enrichedRows, options) {
18794
18954
  const maxEnd = Math.max(start, baseRows.length - 1);
18795
18955
  const inclusiveEnd = range?.rowEnd === null || range?.rowEnd === void 0 ? maxEnd : Math.min(maxEnd, range.rowEnd);
18796
18956
  const expectedSelectedRows = baseRows.length === 0 ? 0 : Math.max(0, inclusiveEnd - start + 1);
18797
- const canMergeSparseBySourceIndex = rows.length > 0 && rows.every(
18957
+ const hasRowsInSelectedRange = rows.some(
18798
18958
  (row) => sourceRowIndexFromEnrichRow(row, start, inclusiveEnd) !== null
18799
18959
  );
18800
- if (options.inPlace && rows.length < expectedSelectedRows && !options.allowPartial && !canMergeSparseBySourceIndex) {
18960
+ if (options.inPlace && rows.length < expectedSelectedRows && !options.allowPartial && !hasRowsInSelectedRange) {
18801
18961
  throw new Error(
18802
18962
  `Refusing to write a partial in-place CSV export: the run returned ${rows.length} row(s) for ${expectedSelectedRows} selected source row(s).`
18803
18963
  );
18804
18964
  }
18805
18965
  const merged = [...baseRows];
18806
- if (canMergeSparseBySourceIndex) {
18966
+ if (hasRowsInSelectedRange) {
18807
18967
  for (const rawEnriched of rows) {
18808
18968
  const rowIndex = sourceRowIndexFromEnrichRow(
18809
18969
  rawEnriched,
@@ -18938,9 +19098,45 @@ function materializeCsvCellValue(value) {
18938
19098
  }
18939
19099
  return value;
18940
19100
  }
18941
- function materializeAliasSuccessCell(row, alias) {
19101
+ function disambiguateCompactAiInferencePayload(value) {
19102
+ const parsed = parseMaybeJsonObject(value);
19103
+ if (!isRecord7(parsed) || !cellFailureError(parsed)) {
19104
+ return value;
19105
+ }
19106
+ return {
19107
+ status: "completed",
19108
+ extracted_json: parsed
19109
+ };
19110
+ }
19111
+ function compactAiInferenceCellForCsv(value) {
19112
+ if (!isRecord7(value)) {
19113
+ return value;
19114
+ }
19115
+ const extractedJson = value.extracted_json;
19116
+ if (extractedJson !== null && extractedJson !== void 0) {
19117
+ return disambiguateCompactAiInferencePayload(extractedJson);
19118
+ }
19119
+ const result = isRecord7(value.result) ? value.result : null;
19120
+ const object = result?.object;
19121
+ if (object !== null && object !== void 0) {
19122
+ return disambiguateCompactAiInferencePayload(object);
19123
+ }
19124
+ const text = result?.text;
19125
+ if (typeof text === "string" && text.trim()) {
19126
+ return disambiguateCompactAiInferencePayload(text);
19127
+ }
19128
+ const output2 = value.output;
19129
+ if (typeof output2 === "string" && output2.trim()) {
19130
+ return disambiguateCompactAiInferencePayload(output2);
19131
+ }
19132
+ return value;
19133
+ }
19134
+ function materializeEnrichAliasCellForCsv(row, alias, options) {
18942
19135
  const direct = row[alias];
18943
19136
  if (isRecord7(direct)) {
19137
+ if (options?.compactAiCell && direct.status === "completed" && (isRecord7(direct.result) || Object.prototype.hasOwnProperty.call(direct, "extracted_json") || typeof direct.output === "string")) {
19138
+ return materializeCsvCellValue(compactAiInferenceCellForCsv(direct));
19139
+ }
18944
19140
  if (Object.prototype.hasOwnProperty.call(direct, "matched_result") || Object.prototype.hasOwnProperty.call(direct, "matchedResult") || Object.prototype.hasOwnProperty.call(direct, "result")) {
18945
19141
  return materializeCsvCellValue(direct);
18946
19142
  }
@@ -18999,6 +19195,7 @@ function materializeAliasSuccessCell(row, alias) {
18999
19195
  }
19000
19196
  function normalizeEnrichRowsForCsvExport(rows, config, options) {
19001
19197
  const aliases = config ? collectConfigScalarAliasOrder(config) : [];
19198
+ const aiCompactAliases = config ? enrichAiRuntimeCompactAliases(config) : null;
19002
19199
  const failureOperationByAlias = hardFailureOperationByAlias(config);
19003
19200
  return rows.map((row) => {
19004
19201
  const metadata = legacyMetadataFromRow(row);
@@ -19041,7 +19238,9 @@ function normalizeEnrichRowsForCsvExport(rows, config, options) {
19041
19238
  }
19042
19239
  }
19043
19240
  for (const alias of aliases) {
19044
- const value = materializeAliasSuccessCell(normalized, alias);
19241
+ const value = materializeEnrichAliasCellForCsv(normalized, alias, {
19242
+ compactAiCell: aiCompactAliases?.has(normalizeAlias2(alias)) ?? false
19243
+ });
19045
19244
  if (value !== void 0) {
19046
19245
  normalized[alias] = value;
19047
19246
  continue;
@@ -19366,7 +19565,7 @@ function registerEnrichCommand(program) {
19366
19565
  capturedResult: captured2.result,
19367
19566
  client: client2,
19368
19567
  config,
19369
- sourceCsvPath: input2.sourceCsvPath,
19568
+ sourceCsvPath: input2.mergeSourceCsvPath ?? input2.sourceCsvPath,
19370
19569
  rows: input2.rows,
19371
19570
  inPlace: Boolean(options.inPlace)
19372
19571
  });
@@ -19382,11 +19581,12 @@ function registerEnrichCommand(program) {
19382
19581
  `
19383
19582
  );
19384
19583
  }
19385
- let workingSourceCsvPath = sourceCsvPath;
19584
+ let workingMergeSourceCsvPath = sourceCsvPath;
19386
19585
  let lastStatus = null;
19387
19586
  let finalExportResult = null;
19388
19587
  let totalEnrichedRows = 0;
19389
19588
  const batchFailureRows = [];
19589
+ const runtimeCompactAliases = enrichAiRuntimeCompactAliases(config);
19390
19590
  for (let chunkStart = selectedRange.start, chunkIndex = 0; chunkStart <= selectedRange.end; chunkStart += autoBatchRows, chunkIndex += 1) {
19391
19591
  const chunkRows = {
19392
19592
  rowStart: chunkStart,
@@ -19401,8 +19601,19 @@ function registerEnrichCommand(program) {
19401
19601
  `
19402
19602
  );
19403
19603
  }
19604
+ const runtimeSourceCsvPath = options.inPlace ? sourceCsvPath : workingMergeSourceCsvPath === inputCsv ? inputCsv : join7(tempDir, `runtime-batch-${chunkIndex}.csv`);
19605
+ if (!options.inPlace && runtimeSourceCsvPath !== inputCsv) {
19606
+ await writeSlimBatchedRuntimeCsv({
19607
+ cleanSourceCsvPath: inputCsv,
19608
+ mergeSourceCsvPath: workingMergeSourceCsvPath,
19609
+ rows: chunkRows,
19610
+ compactAliases: runtimeCompactAliases,
19611
+ outputPath: runtimeSourceCsvPath
19612
+ });
19613
+ }
19404
19614
  const chunk = await runOne({
19405
- sourceCsvPath: workingSourceCsvPath,
19615
+ sourceCsvPath: runtimeSourceCsvPath,
19616
+ mergeSourceCsvPath: workingMergeSourceCsvPath,
19406
19617
  rows: chunkRows,
19407
19618
  json: true,
19408
19619
  passthroughStdout: false,
@@ -19412,7 +19623,10 @@ function registerEnrichCommand(program) {
19412
19623
  if (chunk.captured.result !== 0) {
19413
19624
  if (chunk.exportResult) {
19414
19625
  finalExportResult = chunk.exportResult;
19415
- totalEnrichedRows += chunk.exportResult.enrichedRows;
19626
+ totalEnrichedRows += countEnrichedRowsInSourceRange(
19627
+ chunk.exportResult,
19628
+ chunkRows
19629
+ );
19416
19630
  batchFailureRows.push(...chunk.exportResult.enrichedDataRows);
19417
19631
  }
19418
19632
  const failureReport3 = await maybeEmitEnrichFailureReport({
@@ -19473,9 +19687,12 @@ function registerEnrichCommand(program) {
19473
19687
  }
19474
19688
  if (chunk.exportResult) {
19475
19689
  finalExportResult = chunk.exportResult;
19476
- totalEnrichedRows += chunk.exportResult.enrichedRows;
19690
+ totalEnrichedRows += countEnrichedRowsInSourceRange(
19691
+ chunk.exportResult,
19692
+ chunkRows
19693
+ );
19477
19694
  batchFailureRows.push(...chunk.exportResult.enrichedDataRows);
19478
- workingSourceCsvPath = outputPath;
19695
+ workingMergeSourceCsvPath = outputPath;
19479
19696
  }
19480
19697
  }
19481
19698
  const outputRows = readCsvRows(outputPath);
package/dist/index.d.mts CHANGED
@@ -940,6 +940,8 @@ interface StartPlayRunRequest {
940
940
  packagedFiles?: unknown[];
941
941
  /** Compatibility flag; active sibling runs are allowed. */
942
942
  force?: boolean;
943
+ /** Explicit cache-bypass flag for durable dataset and tool-call reuse. */
944
+ forceToolRefresh?: boolean;
943
945
  /** Optionally let the start request wait briefly and return a terminal result. */
944
946
  waitForCompletionMs?: number;
945
947
  /**
@@ -1087,6 +1089,8 @@ type EnrichCompiledConfig = {
1087
1089
  type ExecuteToolRawOptions = {
1088
1090
  includeToolMetadata?: boolean;
1089
1091
  responseIntent?: 'raw' | 'row_artifact';
1092
+ timeout?: number;
1093
+ maxRetries?: number;
1090
1094
  };
1091
1095
  /**
1092
1096
  * Standard provider/tool execution envelope returned by low-level SDK calls.
@@ -1690,6 +1694,7 @@ declare class DeeplineClient {
1690
1694
  inputFile?: PlayStagedFileRef | null;
1691
1695
  packagedFiles?: PlayStagedFileRef[];
1692
1696
  force?: boolean;
1697
+ forceToolRefresh?: boolean;
1693
1698
  }): Promise<PlayRunStart>;
1694
1699
  /**
1695
1700
  * Register a bundled play artifact and start a run from the live revision.
@@ -1725,6 +1730,7 @@ declare class DeeplineClient {
1725
1730
  inputFile?: PlayStagedFileRef | null;
1726
1731
  packagedFiles?: PlayStagedFileRef[];
1727
1732
  force?: boolean;
1733
+ forceToolRefresh?: boolean;
1728
1734
  }): Promise<PlayRunStart>;
1729
1735
  /**
1730
1736
  * Upload files to the staging area for use in play runs.
@@ -2176,6 +2182,8 @@ declare class DeeplineClient {
2176
2182
  packagedFiles?: PlayStagedFileRef[];
2177
2183
  /** Compatibility flag; active sibling runs are allowed. */
2178
2184
  force?: boolean;
2185
+ /** Explicit cache-bypass flag for durable dataset and tool-call reuse. */
2186
+ forceToolRefresh?: boolean;
2179
2187
  }): Promise<PlayRunResult>;
2180
2188
  /**
2181
2189
  * Published plans plus the caller's active plan: prices, monthly grant
package/dist/index.d.ts CHANGED
@@ -940,6 +940,8 @@ interface StartPlayRunRequest {
940
940
  packagedFiles?: unknown[];
941
941
  /** Compatibility flag; active sibling runs are allowed. */
942
942
  force?: boolean;
943
+ /** Explicit cache-bypass flag for durable dataset and tool-call reuse. */
944
+ forceToolRefresh?: boolean;
943
945
  /** Optionally let the start request wait briefly and return a terminal result. */
944
946
  waitForCompletionMs?: number;
945
947
  /**
@@ -1087,6 +1089,8 @@ type EnrichCompiledConfig = {
1087
1089
  type ExecuteToolRawOptions = {
1088
1090
  includeToolMetadata?: boolean;
1089
1091
  responseIntent?: 'raw' | 'row_artifact';
1092
+ timeout?: number;
1093
+ maxRetries?: number;
1090
1094
  };
1091
1095
  /**
1092
1096
  * Standard provider/tool execution envelope returned by low-level SDK calls.
@@ -1690,6 +1694,7 @@ declare class DeeplineClient {
1690
1694
  inputFile?: PlayStagedFileRef | null;
1691
1695
  packagedFiles?: PlayStagedFileRef[];
1692
1696
  force?: boolean;
1697
+ forceToolRefresh?: boolean;
1693
1698
  }): Promise<PlayRunStart>;
1694
1699
  /**
1695
1700
  * Register a bundled play artifact and start a run from the live revision.
@@ -1725,6 +1730,7 @@ declare class DeeplineClient {
1725
1730
  inputFile?: PlayStagedFileRef | null;
1726
1731
  packagedFiles?: PlayStagedFileRef[];
1727
1732
  force?: boolean;
1733
+ forceToolRefresh?: boolean;
1728
1734
  }): Promise<PlayRunStart>;
1729
1735
  /**
1730
1736
  * Upload files to the staging area for use in play runs.
@@ -2176,6 +2182,8 @@ declare class DeeplineClient {
2176
2182
  packagedFiles?: PlayStagedFileRef[];
2177
2183
  /** Compatibility flag; active sibling runs are allowed. */
2178
2184
  force?: boolean;
2185
+ /** Explicit cache-bypass flag for durable dataset and tool-call reuse. */
2186
+ forceToolRefresh?: boolean;
2179
2187
  }): Promise<PlayRunResult>;
2180
2188
  /**
2181
2189
  * Published plans plus the caller's active plan: prices, monthly grant