deepline 0.1.175 → 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.
- package/dist/bundling-sources/sdk/src/client.ts +20 -1
- package/dist/bundling-sources/sdk/src/http.ts +19 -7
- package/dist/bundling-sources/sdk/src/release.ts +2 -2
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +29 -9
- package/dist/cli/index.js +240 -30
- package/dist/cli/index.mjs +240 -30
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +20 -9
- package/dist/index.mjs +20 -9
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -622,10 +622,10 @@ var SDK_RELEASE = {
|
|
|
622
622
|
// 0.1.111 ships dataset-native tool list getters and result row datasets.
|
|
623
623
|
// 0.1.154 removes the short-lived generated enrich StepOptions recompute
|
|
624
624
|
// fields shipped in 0.1.153.
|
|
625
|
-
version: "0.1.
|
|
625
|
+
version: "0.1.176",
|
|
626
626
|
apiContract: "2026-06-dataset-handle-results-hard-cutover",
|
|
627
627
|
supportPolicy: {
|
|
628
|
-
latest: "0.1.
|
|
628
|
+
latest: "0.1.176",
|
|
629
629
|
minimumSupported: "0.1.53",
|
|
630
630
|
deprecatedBelow: "0.1.53",
|
|
631
631
|
commandMinimumSupported: [
|
|
@@ -886,9 +886,10 @@ var HttpClient = class {
|
|
|
886
886
|
headers["Content-Type"] = "application/json";
|
|
887
887
|
}
|
|
888
888
|
let lastError = null;
|
|
889
|
-
const candidateUrls = buildCandidateUrls(url);
|
|
889
|
+
const candidateUrls = options?.exactUrlOnly ? [url] : buildCandidateUrls(url);
|
|
890
890
|
let retryAfterDelayMs = null;
|
|
891
|
-
|
|
891
|
+
const maxRetries = options?.maxRetries ?? this.config.maxRetries;
|
|
892
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
892
893
|
if (attempt > 0) {
|
|
893
894
|
const backoffMs = Math.min(1e3 * Math.pow(2, attempt - 1), 3e4);
|
|
894
895
|
const delayMs = retryAfterDelayMs === null ? backoffMs : Math.max(backoffMs, retryAfterDelayMs);
|
|
@@ -915,7 +916,7 @@ var HttpClient = class {
|
|
|
915
916
|
if (response.status === 429) {
|
|
916
917
|
const retryAfter = parseRetryAfter(response);
|
|
917
918
|
lastError = new RateLimitError(retryAfter);
|
|
918
|
-
if (attempt <
|
|
919
|
+
if (attempt < maxRetries) {
|
|
919
920
|
retryAfterDelayMs = retryAfter;
|
|
920
921
|
break;
|
|
921
922
|
}
|
|
@@ -945,7 +946,7 @@ var HttpClient = class {
|
|
|
945
946
|
...htmlError.workerThrewException ? { workerThrewException: true } : {}
|
|
946
947
|
}
|
|
947
948
|
);
|
|
948
|
-
if (retryableApiError && attempt <
|
|
949
|
+
if (retryableApiError && attempt < maxRetries) {
|
|
949
950
|
retryAfterDelayMs = parseOptionalRetryAfter(response);
|
|
950
951
|
break;
|
|
951
952
|
}
|
|
@@ -957,7 +958,7 @@ var HttpClient = class {
|
|
|
957
958
|
lastError = new DeeplineError(msg, response.status, apiErrorCode, {
|
|
958
959
|
response: parsed
|
|
959
960
|
});
|
|
960
|
-
if (retryableApiError && attempt <
|
|
961
|
+
if (retryableApiError && attempt < maxRetries) {
|
|
961
962
|
retryAfterDelayMs = parseOptionalRetryAfter(response);
|
|
962
963
|
break;
|
|
963
964
|
}
|
|
@@ -976,7 +977,7 @@ var HttpClient = class {
|
|
|
976
977
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
977
978
|
}
|
|
978
979
|
}
|
|
979
|
-
if (attempt <
|
|
980
|
+
if (attempt < maxRetries) continue;
|
|
980
981
|
}
|
|
981
982
|
if (lastError instanceof DeeplineError) {
|
|
982
983
|
throw lastError;
|
|
@@ -2111,6 +2112,7 @@ var COMPILE_MANIFEST_RETRY_DELAYS_MS = [250, 1e3];
|
|
|
2111
2112
|
var REGISTER_PLAY_ARTIFACTS_COMPILE_CONCURRENCY = 3;
|
|
2112
2113
|
var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_COUNT = 3;
|
|
2113
2114
|
var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_BYTES = 25e5;
|
|
2115
|
+
var DEEPLINEAGENT_EXECUTE_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
2114
2116
|
function normalizePlayRunIntegrationMode(value) {
|
|
2115
2117
|
if (value === "live" || value === "eval_stub" || value === "fixture") {
|
|
2116
2118
|
return value;
|
|
@@ -2185,6 +2187,10 @@ function chunkRegisterPlayArtifacts(artifacts) {
|
|
|
2185
2187
|
}
|
|
2186
2188
|
return chunks;
|
|
2187
2189
|
}
|
|
2190
|
+
function resolveToolExecuteTimeoutMs(toolId) {
|
|
2191
|
+
const normalized = toolId.trim().toLowerCase();
|
|
2192
|
+
return normalized === "deeplineagent" || normalized === "deeplineagent_deeplineagent" || normalized === "ai_inference" || normalized === "deeplineagent_ai_inference" || normalized === "aiinference" ? DEEPLINEAGENT_EXECUTE_TIMEOUT_MS : void 0;
|
|
2193
|
+
}
|
|
2188
2194
|
var RUN_LOGS_PAGE_LIMIT = 1e3;
|
|
2189
2195
|
function isRecord3(value) {
|
|
2190
2196
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
@@ -2624,7 +2630,12 @@ var DeeplineClient = class {
|
|
|
2624
2630
|
`/api/v2/integrations/${encodeURIComponent(toolId)}/execute`,
|
|
2625
2631
|
{ payload: input2 },
|
|
2626
2632
|
headers,
|
|
2627
|
-
{
|
|
2633
|
+
{
|
|
2634
|
+
forbiddenAsApiError: true,
|
|
2635
|
+
timeout: options?.timeout ?? resolveToolExecuteTimeoutMs(toolId),
|
|
2636
|
+
maxRetries: options?.maxRetries ?? 0,
|
|
2637
|
+
exactUrlOnly: true
|
|
2638
|
+
}
|
|
2628
2639
|
);
|
|
2629
2640
|
}
|
|
2630
2641
|
/**
|
|
@@ -4572,10 +4583,21 @@ function failureMessageFromRecord(value) {
|
|
|
4572
4583
|
}
|
|
4573
4584
|
return directError || resultError || `Column status: ${status}`;
|
|
4574
4585
|
}
|
|
4575
|
-
function
|
|
4586
|
+
function shouldPreserveJsonStringColumn(columns, key) {
|
|
4587
|
+
if (!columns) {
|
|
4588
|
+
return false;
|
|
4589
|
+
}
|
|
4590
|
+
if (columns.has(key)) {
|
|
4591
|
+
return true;
|
|
4592
|
+
}
|
|
4593
|
+
const normalizedKey = key.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
4594
|
+
return normalizedKey ? columns.has(normalizedKey) : false;
|
|
4595
|
+
}
|
|
4596
|
+
function flattenObjectColumns(row, options = {}) {
|
|
4576
4597
|
const flattened = {};
|
|
4577
4598
|
for (const [key, rawValue] of Object.entries(row)) {
|
|
4578
4599
|
const value = parseMaybeJsonObject(rawValue);
|
|
4600
|
+
const parsedFromString = typeof rawValue === "string" && value !== rawValue;
|
|
4579
4601
|
if (key === "_metadata") {
|
|
4580
4602
|
flattened[key] = value && typeof value === "object" ? JSON.stringify(value) : value;
|
|
4581
4603
|
continue;
|
|
@@ -4586,6 +4608,10 @@ function flattenObjectColumns(row) {
|
|
|
4586
4608
|
if (hasMatchedEnvelope) {
|
|
4587
4609
|
flattened[key] = JSON.stringify(record);
|
|
4588
4610
|
continue;
|
|
4611
|
+
}
|
|
4612
|
+
if (parsedFromString && shouldPreserveJsonStringColumn(options.preserveJsonStringColumns, key)) {
|
|
4613
|
+
flattened[key] = rawValue;
|
|
4614
|
+
continue;
|
|
4589
4615
|
} else {
|
|
4590
4616
|
const failureMessage = failureMessageFromRecord(record);
|
|
4591
4617
|
if (failureMessage) {
|
|
@@ -4610,8 +4636,8 @@ function recordRows(value) {
|
|
|
4610
4636
|
(row) => Boolean(row) && typeof row === "object" && !Array.isArray(row)
|
|
4611
4637
|
);
|
|
4612
4638
|
}
|
|
4613
|
-
function dataExportRows(rows) {
|
|
4614
|
-
return rows.map((row) => flattenObjectColumns(row));
|
|
4639
|
+
function dataExportRows(rows, options = {}) {
|
|
4640
|
+
return rows.map((row) => flattenObjectColumns(row, options));
|
|
4615
4641
|
}
|
|
4616
4642
|
function dataExportColumns(rows, preferredColumns = []) {
|
|
4617
4643
|
const discoveredColumns = [
|
|
@@ -16883,7 +16909,8 @@ function helperSource() {
|
|
|
16883
16909
|
// src/cli/commands/enrich.ts
|
|
16884
16910
|
var ENRICH_EXPORT_PAGE_SIZE = 5e3;
|
|
16885
16911
|
var ENRICH_AUTO_BATCH_ROWS = 250;
|
|
16886
|
-
var ENRICH_HEAVY_PLAY_AUTO_BATCH_ROWS =
|
|
16912
|
+
var ENRICH_HEAVY_PLAY_AUTO_BATCH_ROWS = 25;
|
|
16913
|
+
var ENRICH_NESTED_PROVIDER_AUTO_BATCH_ROWS = 50;
|
|
16887
16914
|
var ENRICH_EXPORT_BACKING_ROWS_WAIT_MS = 6e4;
|
|
16888
16915
|
var ENRICH_EXPORT_BACKING_ROWS_POLL_MS = 1e3;
|
|
16889
16916
|
var ENRICH_SOURCE_ROW_INDEX_COLUMN = "__deeplineSourceRowIndex";
|
|
@@ -16898,6 +16925,12 @@ var HEAVY_ENRICH_AUTO_BATCH_PLAYS = /* @__PURE__ */ new Set([
|
|
|
16898
16925
|
"company-to-contact-by-role-waterfall",
|
|
16899
16926
|
"company_to_contact_by_role_waterfall"
|
|
16900
16927
|
]);
|
|
16928
|
+
var HEAVY_ENRICH_AUTO_BATCH_TOOLS = /* @__PURE__ */ new Set([
|
|
16929
|
+
"ai_inference",
|
|
16930
|
+
"aiinference",
|
|
16931
|
+
"deeplineagent"
|
|
16932
|
+
]);
|
|
16933
|
+
var ENRICH_TEST_AI_INFERENCE_PAYLOAD_MARKER = "__deeplineTestAiInference";
|
|
16901
16934
|
var PLAN_SHAPING_OPTION_NAMES = [
|
|
16902
16935
|
"with",
|
|
16903
16936
|
"withWaterfall",
|
|
@@ -16915,6 +16948,15 @@ function normalizeAlias2(value) {
|
|
|
16915
16948
|
function hasPlanShapingArgs(args) {
|
|
16916
16949
|
return optionWasProvided(args, "--with") || optionWasProvided(args, "--with-waterfall") || optionWasProvided(args, "--min-results") || optionWasProvided(args, "--end-waterfall");
|
|
16917
16950
|
}
|
|
16951
|
+
function isMarkedTestAiInferenceCommand(command) {
|
|
16952
|
+
if ("with_waterfall" in command) {
|
|
16953
|
+
return false;
|
|
16954
|
+
}
|
|
16955
|
+
if (normalizeEnrichPlayRef(command.tool) !== "run_javascript") {
|
|
16956
|
+
return false;
|
|
16957
|
+
}
|
|
16958
|
+
return isRecord7(command.payload) && command.payload[ENRICH_TEST_AI_INFERENCE_PAYLOAD_MARKER] === true;
|
|
16959
|
+
}
|
|
16918
16960
|
function enrichDebugEnabled(env = process.env) {
|
|
16919
16961
|
const raw = String(env.DEEPLINE_DEBUG_ENRICH ?? "").trim().toLowerCase();
|
|
16920
16962
|
if (["1", "true", "yes", "on"].includes(raw)) {
|
|
@@ -17682,8 +17724,6 @@ function normalizeEnrichPlayRef(value) {
|
|
|
17682
17724
|
return normalized || null;
|
|
17683
17725
|
}
|
|
17684
17726
|
function configContainsHeavyEnrichPlay(config) {
|
|
17685
|
-
let hasNestedPlayStep = false;
|
|
17686
|
-
let hasSubrequestProviderStep = false;
|
|
17687
17727
|
const visit = (commands) => {
|
|
17688
17728
|
for (const command of commands) {
|
|
17689
17729
|
if ("with_waterfall" in command) {
|
|
@@ -17707,18 +17747,67 @@ function configContainsHeavyEnrichPlay(config) {
|
|
|
17707
17747
|
return true;
|
|
17708
17748
|
}
|
|
17709
17749
|
const normalizedTool = normalizeEnrichPlayRef(command.tool);
|
|
17750
|
+
const normalizedOperation = normalizeEnrichPlayRef(command.operation);
|
|
17751
|
+
if (isMarkedTestAiInferenceCommand(command) || normalizedTool && HEAVY_ENRICH_AUTO_BATCH_TOOLS.has(normalizedTool) || normalizedOperation && HEAVY_ENRICH_AUTO_BATCH_TOOLS.has(normalizedOperation)) {
|
|
17752
|
+
return true;
|
|
17753
|
+
}
|
|
17754
|
+
}
|
|
17755
|
+
return false;
|
|
17756
|
+
};
|
|
17757
|
+
return visit(config.commands);
|
|
17758
|
+
}
|
|
17759
|
+
function configContainsNestedProviderEnrichWorkload(config) {
|
|
17760
|
+
let hasNestedPlayStep = false;
|
|
17761
|
+
let hasSubrequestProviderStep = false;
|
|
17762
|
+
const visit = (commands) => {
|
|
17763
|
+
for (const command of commands) {
|
|
17764
|
+
if ("with_waterfall" in command) {
|
|
17765
|
+
visit(command.commands);
|
|
17766
|
+
continue;
|
|
17767
|
+
}
|
|
17768
|
+
if (command.disabled) {
|
|
17769
|
+
continue;
|
|
17770
|
+
}
|
|
17771
|
+
const normalizedTool = normalizeEnrichPlayRef(command.tool);
|
|
17710
17772
|
if (command.play || normalizedTool === "test-play") {
|
|
17711
17773
|
hasNestedPlayStep = true;
|
|
17712
17774
|
} else if (normalizedTool !== null && normalizedTool !== "run_javascript") {
|
|
17713
17775
|
hasSubrequestProviderStep = true;
|
|
17714
17776
|
}
|
|
17715
17777
|
}
|
|
17716
|
-
return false;
|
|
17717
17778
|
};
|
|
17718
|
-
|
|
17779
|
+
visit(config.commands);
|
|
17780
|
+
return hasNestedPlayStep && hasSubrequestProviderStep;
|
|
17719
17781
|
}
|
|
17720
17782
|
function enrichAutoBatchRowsForConfig(config) {
|
|
17721
|
-
|
|
17783
|
+
if (configContainsHeavyEnrichPlay(config)) {
|
|
17784
|
+
return ENRICH_HEAVY_PLAY_AUTO_BATCH_ROWS;
|
|
17785
|
+
}
|
|
17786
|
+
if (configContainsNestedProviderEnrichWorkload(config)) {
|
|
17787
|
+
return ENRICH_NESTED_PROVIDER_AUTO_BATCH_ROWS;
|
|
17788
|
+
}
|
|
17789
|
+
return ENRICH_AUTO_BATCH_ROWS;
|
|
17790
|
+
}
|
|
17791
|
+
function enrichAiRuntimeCompactAliases(config) {
|
|
17792
|
+
const aliases = /* @__PURE__ */ new Set();
|
|
17793
|
+
const visit = (commands) => {
|
|
17794
|
+
for (const command of commands) {
|
|
17795
|
+
if ("with_waterfall" in command) {
|
|
17796
|
+
visit(command.commands);
|
|
17797
|
+
continue;
|
|
17798
|
+
}
|
|
17799
|
+
if (command.disabled) {
|
|
17800
|
+
continue;
|
|
17801
|
+
}
|
|
17802
|
+
const normalizedTool = normalizeEnrichPlayRef(command.tool);
|
|
17803
|
+
const normalizedOperation = normalizeEnrichPlayRef(command.operation);
|
|
17804
|
+
if (isMarkedTestAiInferenceCommand(command) || normalizedTool && HEAVY_ENRICH_AUTO_BATCH_TOOLS.has(normalizedTool) || normalizedOperation && HEAVY_ENRICH_AUTO_BATCH_TOOLS.has(normalizedOperation)) {
|
|
17805
|
+
aliases.add(normalizeAlias2(command.alias));
|
|
17806
|
+
}
|
|
17807
|
+
}
|
|
17808
|
+
};
|
|
17809
|
+
visit(config.commands);
|
|
17810
|
+
return aliases;
|
|
17722
17811
|
}
|
|
17723
17812
|
async function maybeWriteOutputCsv(input2) {
|
|
17724
17813
|
if (!input2.outputPath) return null;
|
|
@@ -17814,6 +17903,52 @@ function selectedSourceCsvRange(sourceCsvPath, rows) {
|
|
|
17814
17903
|
sourceRows
|
|
17815
17904
|
};
|
|
17816
17905
|
}
|
|
17906
|
+
function compactRuntimeCsvCell(value) {
|
|
17907
|
+
const parsed = parseMaybeJsonObject(value);
|
|
17908
|
+
const compacted = compactAiInferenceCellForCsv(parsed);
|
|
17909
|
+
return materializeCsvCellValue(compacted);
|
|
17910
|
+
}
|
|
17911
|
+
async function writeSlimBatchedRuntimeCsv(input2) {
|
|
17912
|
+
const cleanRows = readCsvRows(input2.cleanSourceCsvPath).map(
|
|
17913
|
+
(row) => ({ ...row })
|
|
17914
|
+
);
|
|
17915
|
+
const mergeRows = readCsvRows(input2.mergeSourceCsvPath);
|
|
17916
|
+
const preserveJsonStringColumns = /* @__PURE__ */ new Set([
|
|
17917
|
+
...cleanRows.flatMap((row) => Object.keys(row)),
|
|
17918
|
+
...mergeRows.flatMap((row) => Object.keys(row))
|
|
17919
|
+
]);
|
|
17920
|
+
const selectedRange = selectedSourceCsvRange(
|
|
17921
|
+
input2.mergeSourceCsvPath,
|
|
17922
|
+
input2.rows
|
|
17923
|
+
);
|
|
17924
|
+
for (let rowIndex = selectedRange.start; rowIndex <= selectedRange.end; rowIndex += 1) {
|
|
17925
|
+
const mergeRow = mergeRows[rowIndex];
|
|
17926
|
+
if (!mergeRow) {
|
|
17927
|
+
continue;
|
|
17928
|
+
}
|
|
17929
|
+
const baseRow = cleanRows[rowIndex] ?? {};
|
|
17930
|
+
const compactOverlayCell = ([key, value]) => {
|
|
17931
|
+
return [
|
|
17932
|
+
key,
|
|
17933
|
+
input2.compactAliases.has(normalizeAlias2(key)) ? compactRuntimeCsvCell(value) : value
|
|
17934
|
+
];
|
|
17935
|
+
};
|
|
17936
|
+
cleanRows[rowIndex] = {
|
|
17937
|
+
...baseRow,
|
|
17938
|
+
...Object.fromEntries(
|
|
17939
|
+
Object.entries(mergeRow).map(compactOverlayCell)
|
|
17940
|
+
)
|
|
17941
|
+
};
|
|
17942
|
+
}
|
|
17943
|
+
const columns = dataExportColumns(
|
|
17944
|
+
dataExportRows(cleanRows, { preserveJsonStringColumns })
|
|
17945
|
+
);
|
|
17946
|
+
await (0, import_promises3.writeFile)(
|
|
17947
|
+
input2.outputPath,
|
|
17948
|
+
csvStringFromRows(cleanRows, columns),
|
|
17949
|
+
"utf8"
|
|
17950
|
+
);
|
|
17951
|
+
}
|
|
17817
17952
|
function selectedSourceCsvRowCount(options) {
|
|
17818
17953
|
if (!options?.sourceCsvPath) {
|
|
17819
17954
|
return null;
|
|
@@ -18120,6 +18255,22 @@ function mergeExportedSheetRow(target, next) {
|
|
|
18120
18255
|
target._metadata = metadata;
|
|
18121
18256
|
}
|
|
18122
18257
|
}
|
|
18258
|
+
function countEnrichedRowsInSourceRange(exportResult, rows) {
|
|
18259
|
+
const start = Math.max(0, rows.rowStart ?? 0);
|
|
18260
|
+
const end = rows.rowEnd === null || rows.rowEnd === void 0 ? Number.MAX_SAFE_INTEGER : Math.max(start, rows.rowEnd);
|
|
18261
|
+
const rowIndexes = /* @__PURE__ */ new Set();
|
|
18262
|
+
for (const row of exportResult.enrichedDataRows) {
|
|
18263
|
+
const rowIndex = sourceRowIndexFromEnrichRow(row, start, end);
|
|
18264
|
+
if (rowIndex !== null) {
|
|
18265
|
+
rowIndexes.add(rowIndex);
|
|
18266
|
+
}
|
|
18267
|
+
}
|
|
18268
|
+
if (rowIndexes.size > 0) {
|
|
18269
|
+
return rowIndexes.size;
|
|
18270
|
+
}
|
|
18271
|
+
const selectedRows = end === Number.MAX_SAFE_INTEGER ? exportResult.enrichedRows : end - start + 1;
|
|
18272
|
+
return Math.min(exportResult.enrichedRows, Math.max(0, selectedRows));
|
|
18273
|
+
}
|
|
18123
18274
|
function coalesceExportableSheetRows(rows, sourceRowStart = 0) {
|
|
18124
18275
|
const mergedRows = [];
|
|
18125
18276
|
const bySourceRowIndex = /* @__PURE__ */ new Map();
|
|
@@ -18751,10 +18902,12 @@ async function fetchBackingRowsForCsvExport(input2) {
|
|
|
18751
18902
|
};
|
|
18752
18903
|
}
|
|
18753
18904
|
function mergeRowsForCsvExport(enrichedRows, options) {
|
|
18905
|
+
const compactAliases = options?.config ? enrichAiRuntimeCompactAliases(options.config) : /* @__PURE__ */ new Set();
|
|
18754
18906
|
const rows = dataExportRows(
|
|
18755
18907
|
normalizeEnrichRowsForCsvExport(enrichedRows, options?.config, {
|
|
18756
18908
|
statusFailureMessages: options?.statusFailureMessages
|
|
18757
|
-
})
|
|
18909
|
+
}),
|
|
18910
|
+
{ preserveJsonStringColumns: compactAliases }
|
|
18758
18911
|
);
|
|
18759
18912
|
const range = options?.rows;
|
|
18760
18913
|
if (!options?.sourceCsvPath) {
|
|
@@ -18774,16 +18927,16 @@ function mergeRowsForCsvExport(enrichedRows, options) {
|
|
|
18774
18927
|
const maxEnd = Math.max(start, baseRows.length - 1);
|
|
18775
18928
|
const inclusiveEnd = range?.rowEnd === null || range?.rowEnd === void 0 ? maxEnd : Math.min(maxEnd, range.rowEnd);
|
|
18776
18929
|
const expectedSelectedRows = baseRows.length === 0 ? 0 : Math.max(0, inclusiveEnd - start + 1);
|
|
18777
|
-
const
|
|
18930
|
+
const hasRowsInSelectedRange = rows.some(
|
|
18778
18931
|
(row) => sourceRowIndexFromEnrichRow(row, start, inclusiveEnd) !== null
|
|
18779
18932
|
);
|
|
18780
|
-
if (options.inPlace && rows.length < expectedSelectedRows && !options.allowPartial && !
|
|
18933
|
+
if (options.inPlace && rows.length < expectedSelectedRows && !options.allowPartial && !hasRowsInSelectedRange) {
|
|
18781
18934
|
throw new Error(
|
|
18782
18935
|
`Refusing to write a partial in-place CSV export: the run returned ${rows.length} row(s) for ${expectedSelectedRows} selected source row(s).`
|
|
18783
18936
|
);
|
|
18784
18937
|
}
|
|
18785
18938
|
const merged = [...baseRows];
|
|
18786
|
-
if (
|
|
18939
|
+
if (hasRowsInSelectedRange) {
|
|
18787
18940
|
for (const rawEnriched of rows) {
|
|
18788
18941
|
const rowIndex = sourceRowIndexFromEnrichRow(
|
|
18789
18942
|
rawEnriched,
|
|
@@ -18918,9 +19071,45 @@ function materializeCsvCellValue(value) {
|
|
|
18918
19071
|
}
|
|
18919
19072
|
return value;
|
|
18920
19073
|
}
|
|
18921
|
-
function
|
|
19074
|
+
function disambiguateCompactAiInferencePayload(value) {
|
|
19075
|
+
const parsed = parseMaybeJsonObject(value);
|
|
19076
|
+
if (!isRecord7(parsed) || !cellFailureError(parsed)) {
|
|
19077
|
+
return value;
|
|
19078
|
+
}
|
|
19079
|
+
return {
|
|
19080
|
+
status: "completed",
|
|
19081
|
+
extracted_json: parsed
|
|
19082
|
+
};
|
|
19083
|
+
}
|
|
19084
|
+
function compactAiInferenceCellForCsv(value) {
|
|
19085
|
+
if (!isRecord7(value)) {
|
|
19086
|
+
return value;
|
|
19087
|
+
}
|
|
19088
|
+
const extractedJson = value.extracted_json;
|
|
19089
|
+
if (extractedJson !== null && extractedJson !== void 0) {
|
|
19090
|
+
return disambiguateCompactAiInferencePayload(extractedJson);
|
|
19091
|
+
}
|
|
19092
|
+
const result = isRecord7(value.result) ? value.result : null;
|
|
19093
|
+
const object = result?.object;
|
|
19094
|
+
if (object !== null && object !== void 0) {
|
|
19095
|
+
return disambiguateCompactAiInferencePayload(object);
|
|
19096
|
+
}
|
|
19097
|
+
const text = result?.text;
|
|
19098
|
+
if (typeof text === "string" && text.trim()) {
|
|
19099
|
+
return disambiguateCompactAiInferencePayload(text);
|
|
19100
|
+
}
|
|
19101
|
+
const output2 = value.output;
|
|
19102
|
+
if (typeof output2 === "string" && output2.trim()) {
|
|
19103
|
+
return disambiguateCompactAiInferencePayload(output2);
|
|
19104
|
+
}
|
|
19105
|
+
return value;
|
|
19106
|
+
}
|
|
19107
|
+
function materializeEnrichAliasCellForCsv(row, alias, options) {
|
|
18922
19108
|
const direct = row[alias];
|
|
18923
19109
|
if (isRecord7(direct)) {
|
|
19110
|
+
if (options?.compactAiCell && direct.status === "completed" && (isRecord7(direct.result) || Object.prototype.hasOwnProperty.call(direct, "extracted_json") || typeof direct.output === "string")) {
|
|
19111
|
+
return materializeCsvCellValue(compactAiInferenceCellForCsv(direct));
|
|
19112
|
+
}
|
|
18924
19113
|
if (Object.prototype.hasOwnProperty.call(direct, "matched_result") || Object.prototype.hasOwnProperty.call(direct, "matchedResult") || Object.prototype.hasOwnProperty.call(direct, "result")) {
|
|
18925
19114
|
return materializeCsvCellValue(direct);
|
|
18926
19115
|
}
|
|
@@ -18979,6 +19168,7 @@ function materializeAliasSuccessCell(row, alias) {
|
|
|
18979
19168
|
}
|
|
18980
19169
|
function normalizeEnrichRowsForCsvExport(rows, config, options) {
|
|
18981
19170
|
const aliases = config ? collectConfigScalarAliasOrder(config) : [];
|
|
19171
|
+
const aiCompactAliases = config ? enrichAiRuntimeCompactAliases(config) : null;
|
|
18982
19172
|
const failureOperationByAlias = hardFailureOperationByAlias(config);
|
|
18983
19173
|
return rows.map((row) => {
|
|
18984
19174
|
const metadata = legacyMetadataFromRow(row);
|
|
@@ -19021,7 +19211,9 @@ function normalizeEnrichRowsForCsvExport(rows, config, options) {
|
|
|
19021
19211
|
}
|
|
19022
19212
|
}
|
|
19023
19213
|
for (const alias of aliases) {
|
|
19024
|
-
const value =
|
|
19214
|
+
const value = materializeEnrichAliasCellForCsv(normalized, alias, {
|
|
19215
|
+
compactAiCell: aiCompactAliases?.has(normalizeAlias2(alias)) ?? false
|
|
19216
|
+
});
|
|
19025
19217
|
if (value !== void 0) {
|
|
19026
19218
|
normalized[alias] = value;
|
|
19027
19219
|
continue;
|
|
@@ -19346,7 +19538,7 @@ function registerEnrichCommand(program) {
|
|
|
19346
19538
|
capturedResult: captured2.result,
|
|
19347
19539
|
client: client2,
|
|
19348
19540
|
config,
|
|
19349
|
-
sourceCsvPath: input2.sourceCsvPath,
|
|
19541
|
+
sourceCsvPath: input2.mergeSourceCsvPath ?? input2.sourceCsvPath,
|
|
19350
19542
|
rows: input2.rows,
|
|
19351
19543
|
inPlace: Boolean(options.inPlace)
|
|
19352
19544
|
});
|
|
@@ -19362,11 +19554,12 @@ function registerEnrichCommand(program) {
|
|
|
19362
19554
|
`
|
|
19363
19555
|
);
|
|
19364
19556
|
}
|
|
19365
|
-
let
|
|
19557
|
+
let workingMergeSourceCsvPath = sourceCsvPath;
|
|
19366
19558
|
let lastStatus = null;
|
|
19367
19559
|
let finalExportResult = null;
|
|
19368
19560
|
let totalEnrichedRows = 0;
|
|
19369
19561
|
const batchFailureRows = [];
|
|
19562
|
+
const runtimeCompactAliases = enrichAiRuntimeCompactAliases(config);
|
|
19370
19563
|
for (let chunkStart = selectedRange.start, chunkIndex = 0; chunkStart <= selectedRange.end; chunkStart += autoBatchRows, chunkIndex += 1) {
|
|
19371
19564
|
const chunkRows = {
|
|
19372
19565
|
rowStart: chunkStart,
|
|
@@ -19381,8 +19574,19 @@ function registerEnrichCommand(program) {
|
|
|
19381
19574
|
`
|
|
19382
19575
|
);
|
|
19383
19576
|
}
|
|
19577
|
+
const runtimeSourceCsvPath = options.inPlace ? sourceCsvPath : workingMergeSourceCsvPath === inputCsv ? inputCsv : (0, import_node_path12.join)(tempDir, `runtime-batch-${chunkIndex}.csv`);
|
|
19578
|
+
if (!options.inPlace && runtimeSourceCsvPath !== inputCsv) {
|
|
19579
|
+
await writeSlimBatchedRuntimeCsv({
|
|
19580
|
+
cleanSourceCsvPath: inputCsv,
|
|
19581
|
+
mergeSourceCsvPath: workingMergeSourceCsvPath,
|
|
19582
|
+
rows: chunkRows,
|
|
19583
|
+
compactAliases: runtimeCompactAliases,
|
|
19584
|
+
outputPath: runtimeSourceCsvPath
|
|
19585
|
+
});
|
|
19586
|
+
}
|
|
19384
19587
|
const chunk = await runOne({
|
|
19385
|
-
sourceCsvPath:
|
|
19588
|
+
sourceCsvPath: runtimeSourceCsvPath,
|
|
19589
|
+
mergeSourceCsvPath: workingMergeSourceCsvPath,
|
|
19386
19590
|
rows: chunkRows,
|
|
19387
19591
|
json: true,
|
|
19388
19592
|
passthroughStdout: false,
|
|
@@ -19392,7 +19596,10 @@ function registerEnrichCommand(program) {
|
|
|
19392
19596
|
if (chunk.captured.result !== 0) {
|
|
19393
19597
|
if (chunk.exportResult) {
|
|
19394
19598
|
finalExportResult = chunk.exportResult;
|
|
19395
|
-
totalEnrichedRows +=
|
|
19599
|
+
totalEnrichedRows += countEnrichedRowsInSourceRange(
|
|
19600
|
+
chunk.exportResult,
|
|
19601
|
+
chunkRows
|
|
19602
|
+
);
|
|
19396
19603
|
batchFailureRows.push(...chunk.exportResult.enrichedDataRows);
|
|
19397
19604
|
}
|
|
19398
19605
|
const failureReport3 = await maybeEmitEnrichFailureReport({
|
|
@@ -19453,9 +19660,12 @@ function registerEnrichCommand(program) {
|
|
|
19453
19660
|
}
|
|
19454
19661
|
if (chunk.exportResult) {
|
|
19455
19662
|
finalExportResult = chunk.exportResult;
|
|
19456
|
-
totalEnrichedRows +=
|
|
19663
|
+
totalEnrichedRows += countEnrichedRowsInSourceRange(
|
|
19664
|
+
chunk.exportResult,
|
|
19665
|
+
chunkRows
|
|
19666
|
+
);
|
|
19457
19667
|
batchFailureRows.push(...chunk.exportResult.enrichedDataRows);
|
|
19458
|
-
|
|
19668
|
+
workingMergeSourceCsvPath = outputPath;
|
|
19459
19669
|
}
|
|
19460
19670
|
}
|
|
19461
19671
|
const outputRows = readCsvRows(outputPath);
|