deepline 0.1.180 → 0.1.182
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/apps/play-runner-workers/src/entry.ts +241 -4
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/output-datasets.ts +124 -12
- package/dist/bundling-sources/sdk/src/client.ts +7 -5
- package/dist/bundling-sources/sdk/src/play.ts +200 -26
- package/dist/bundling-sources/sdk/src/release.ts +2 -2
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +263 -44
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/query-result-dataset.ts +120 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +139 -17
- package/dist/cli/index.js +12 -9
- package/dist/cli/index.mjs +12 -9
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +213 -28
- package/dist/index.mjs +213 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -422,10 +422,10 @@ var SDK_RELEASE = {
|
|
|
422
422
|
// 0.1.154 removes the short-lived generated enrich StepOptions recompute
|
|
423
423
|
// fields shipped in 0.1.153.
|
|
424
424
|
// 0.1.175 ships loud `deepline enrich` empty-waterfall reporting.
|
|
425
|
-
version: "0.1.
|
|
425
|
+
version: "0.1.182",
|
|
426
426
|
apiContract: "2026-06-dataset-handle-results-hard-cutover",
|
|
427
427
|
supportPolicy: {
|
|
428
|
-
latest: "0.1.
|
|
428
|
+
latest: "0.1.182",
|
|
429
429
|
minimumSupported: "0.1.53",
|
|
430
430
|
deprecatedBelow: "0.1.53",
|
|
431
431
|
commandMinimumSupported: [
|
|
@@ -2541,11 +2541,14 @@ var DeeplineClient = class {
|
|
|
2541
2541
|
const headers = {
|
|
2542
2542
|
[EXECUTE_RESPONSE_CONTRACT_HEADER]: V2_EXECUTE_RESPONSE_CONTRACT,
|
|
2543
2543
|
...options?.includeToolMetadata ? { [INCLUDE_TOOL_METADATA_HEADER]: "true" } : {},
|
|
2544
|
-
|
|
2544
|
+
[EXECUTE_RESPONSE_INTENT_HEADER]: options?.responseIntent ?? "raw"
|
|
2545
2545
|
};
|
|
2546
2546
|
return this.http.post(
|
|
2547
2547
|
`/api/v2/integrations/${encodeURIComponent(toolId)}/execute`,
|
|
2548
|
-
{
|
|
2548
|
+
{
|
|
2549
|
+
payload: input,
|
|
2550
|
+
...options?.metadata ? { metadata: options.metadata } : {}
|
|
2551
|
+
},
|
|
2549
2552
|
headers,
|
|
2550
2553
|
{
|
|
2551
2554
|
forbiddenAsApiError: true,
|
|
@@ -5350,6 +5353,73 @@ function createToolExecuteResult(input) {
|
|
|
5350
5353
|
});
|
|
5351
5354
|
return wrapper;
|
|
5352
5355
|
}
|
|
5356
|
+
function attachToolResultListDataset(result, input) {
|
|
5357
|
+
const existing = result._metadata.lists[input.name];
|
|
5358
|
+
result._metadata.lists[input.name] = {
|
|
5359
|
+
path: input.path,
|
|
5360
|
+
count: input.count,
|
|
5361
|
+
keys: input.keys ?? existing?.keys ?? {}
|
|
5362
|
+
};
|
|
5363
|
+
const accessor = {
|
|
5364
|
+
path: input.path,
|
|
5365
|
+
count: input.count,
|
|
5366
|
+
keys: result._metadata.lists[input.name].keys
|
|
5367
|
+
};
|
|
5368
|
+
Object.defineProperty(accessor, "get", {
|
|
5369
|
+
value() {
|
|
5370
|
+
return input.dataset;
|
|
5371
|
+
},
|
|
5372
|
+
enumerable: false
|
|
5373
|
+
});
|
|
5374
|
+
result.extractedLists[input.name] = accessor;
|
|
5375
|
+
const serialized = input.dataset.toJSON();
|
|
5376
|
+
let root = { toolResponse: { raw: result.toolResponse.raw } };
|
|
5377
|
+
const candidates = [...candidateResultPaths(input.path)].filter(
|
|
5378
|
+
(candidate, index, all) => all.indexOf(candidate) === index
|
|
5379
|
+
);
|
|
5380
|
+
for (const candidate of candidates) {
|
|
5381
|
+
if (!Array.isArray(getAtPath(root, candidate))) continue;
|
|
5382
|
+
root = replaceAtPath(root, candidate, serialized.preview);
|
|
5383
|
+
break;
|
|
5384
|
+
}
|
|
5385
|
+
if (isRecord4(root) && isRecord4(root.toolResponse) && Object.prototype.hasOwnProperty.call(root.toolResponse, "raw")) {
|
|
5386
|
+
result.toolResponse.raw = root.toolResponse.raw;
|
|
5387
|
+
result.toolOutput.raw = root.toolResponse.raw;
|
|
5388
|
+
}
|
|
5389
|
+
return result;
|
|
5390
|
+
}
|
|
5391
|
+
function replaceAtPath(root, path, replacement) {
|
|
5392
|
+
const segments = parsePath(path);
|
|
5393
|
+
if (segments.length === 0 || segments.includes("*")) return root;
|
|
5394
|
+
const replace = (current, index) => {
|
|
5395
|
+
if (index >= segments.length) return replacement;
|
|
5396
|
+
const segment = segments[index];
|
|
5397
|
+
if (typeof segment === "number") {
|
|
5398
|
+
if (!Array.isArray(current)) return current;
|
|
5399
|
+
const copy = [...current];
|
|
5400
|
+
copy[segment] = replace(copy[segment], index + 1);
|
|
5401
|
+
return copy;
|
|
5402
|
+
}
|
|
5403
|
+
if (!isRecord4(current)) return current;
|
|
5404
|
+
return {
|
|
5405
|
+
...current,
|
|
5406
|
+
[segment]: replace(current[segment], index + 1)
|
|
5407
|
+
};
|
|
5408
|
+
};
|
|
5409
|
+
return replace(root, 0);
|
|
5410
|
+
}
|
|
5411
|
+
|
|
5412
|
+
// ../shared_libs/play-runtime/query-result-dataset.ts
|
|
5413
|
+
var QUERY_RESULT_DATASET_PAGE_SIZE = 1e3;
|
|
5414
|
+
function isCustomerDbDatasetTool(toolId) {
|
|
5415
|
+
return /^(?:customer_db_)?query_customer_db$/.test(toolId);
|
|
5416
|
+
}
|
|
5417
|
+
function isSnowflakeQueryDatasetTool(toolId) {
|
|
5418
|
+
return /^snowflake_(?:snowflake_)?run_(?:semantic_)?query$/.test(toolId);
|
|
5419
|
+
}
|
|
5420
|
+
function isQueryResultDatasetTool(toolId) {
|
|
5421
|
+
return isCustomerDbDatasetTool(toolId) || isSnowflakeQueryDatasetTool(toolId);
|
|
5422
|
+
}
|
|
5353
5423
|
|
|
5354
5424
|
// src/play.ts
|
|
5355
5425
|
var DeeplineConditionalStepResolver = class _DeeplineConditionalStepResolver {
|
|
@@ -5525,9 +5595,13 @@ var DeeplineContext = class {
|
|
|
5525
5595
|
/** Execute a tool and return the standard execution envelope. */
|
|
5526
5596
|
execute: async (toolId, input) => {
|
|
5527
5597
|
const response = await this.client.executeTool(toolId, input, {
|
|
5528
|
-
includeToolMetadata: true
|
|
5598
|
+
includeToolMetadata: true,
|
|
5599
|
+
responseIntent: "dataset"
|
|
5600
|
+
});
|
|
5601
|
+
return toolExecutionEnvelopeToResult(toolId, response, {
|
|
5602
|
+
client: this.client,
|
|
5603
|
+
input
|
|
5529
5604
|
});
|
|
5530
|
-
return toolExecutionEnvelopeToResult(toolId, response);
|
|
5531
5605
|
}
|
|
5532
5606
|
};
|
|
5533
5607
|
}
|
|
@@ -5722,32 +5796,143 @@ function extractorDescriptorRecord(value) {
|
|
|
5722
5796
|
})
|
|
5723
5797
|
);
|
|
5724
5798
|
}
|
|
5725
|
-
function
|
|
5799
|
+
function rowsFromUnknown(value) {
|
|
5800
|
+
if (!Array.isArray(value)) return [];
|
|
5801
|
+
return value.map((row) => isRecord5(row) ? row : { value: row });
|
|
5802
|
+
}
|
|
5803
|
+
function finiteNonNegativeInteger(value) {
|
|
5804
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
5805
|
+
return null;
|
|
5806
|
+
}
|
|
5807
|
+
return Math.floor(value);
|
|
5808
|
+
}
|
|
5809
|
+
function finitePositiveInteger(value) {
|
|
5810
|
+
const integer = finiteNonNegativeInteger(value);
|
|
5811
|
+
return integer !== null && integer > 0 ? integer : null;
|
|
5812
|
+
}
|
|
5813
|
+
function stableHash(value) {
|
|
5814
|
+
let hash = 0;
|
|
5815
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
5816
|
+
hash = Math.imul(31, hash) + value.charCodeAt(index);
|
|
5817
|
+
hash |= 0;
|
|
5818
|
+
}
|
|
5819
|
+
return Math.abs(hash).toString(36);
|
|
5820
|
+
}
|
|
5821
|
+
function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
5822
|
+
if (!options || !isQueryResultDatasetTool(toolId)) return result;
|
|
5823
|
+
const raw = isRecord5(result.toolResponse.raw) ? result.toolResponse.raw : null;
|
|
5824
|
+
const dataset = isRecord5(raw?.dataset) ? raw.dataset : null;
|
|
5825
|
+
const totalRows = finiteNonNegativeInteger(dataset?.total_rows);
|
|
5826
|
+
const sql = typeof options.input.sql === "string" ? options.input.sql : typeof options.input.query === "string" ? options.input.query : typeof raw?.sql === "string" ? raw.sql : null;
|
|
5827
|
+
if (!dataset || totalRows === null || !sql) {
|
|
5828
|
+
return result;
|
|
5829
|
+
}
|
|
5830
|
+
const datasetLimit = finitePositiveInteger(dataset.returned_limit) ?? totalRows;
|
|
5831
|
+
const previewRows = rowsFromUnknown(raw?.rows).slice(0, 25);
|
|
5832
|
+
const fetchPage = async (offset, limit) => {
|
|
5833
|
+
if (limit <= 0 || offset >= totalRows) return [];
|
|
5834
|
+
const response = await options.client.executeTool(toolId, options.input, {
|
|
5835
|
+
includeToolMetadata: true,
|
|
5836
|
+
responseIntent: "dataset",
|
|
5837
|
+
metadata: {
|
|
5838
|
+
query_result_dataset: {
|
|
5839
|
+
limit: datasetLimit,
|
|
5840
|
+
offset,
|
|
5841
|
+
page_size: Math.min(limit, QUERY_RESULT_DATASET_PAGE_SIZE),
|
|
5842
|
+
total_rows: totalRows
|
|
5843
|
+
},
|
|
5844
|
+
...isCustomerDbDatasetTool(toolId) ? {
|
|
5845
|
+
customer_db_dataset: {
|
|
5846
|
+
limit: datasetLimit,
|
|
5847
|
+
offset,
|
|
5848
|
+
page_size: Math.min(limit, QUERY_RESULT_DATASET_PAGE_SIZE),
|
|
5849
|
+
total_rows: totalRows
|
|
5850
|
+
}
|
|
5851
|
+
} : {}
|
|
5852
|
+
}
|
|
5853
|
+
});
|
|
5854
|
+
const pageRaw = isRecord5(response.toolResponse?.raw) ? response.toolResponse.raw : null;
|
|
5855
|
+
return rowsFromUnknown(pageRaw?.rows);
|
|
5856
|
+
};
|
|
5857
|
+
const collectRows = async (limit) => {
|
|
5858
|
+
const target = Math.min(limit ?? totalRows, totalRows, datasetLimit);
|
|
5859
|
+
const collected = [];
|
|
5860
|
+
for (let offset = 0; offset < target; offset += QUERY_RESULT_DATASET_PAGE_SIZE) {
|
|
5861
|
+
collected.push(
|
|
5862
|
+
...await fetchPage(
|
|
5863
|
+
offset,
|
|
5864
|
+
Math.min(QUERY_RESULT_DATASET_PAGE_SIZE, target - offset)
|
|
5865
|
+
)
|
|
5866
|
+
);
|
|
5867
|
+
}
|
|
5868
|
+
return collected.slice(0, target);
|
|
5869
|
+
};
|
|
5870
|
+
const executionNonce = typeof result.job_id === "string" && result.job_id.trim() ? result.job_id.trim() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
5871
|
+
const safeNonce = executionNonce.replace(/[^A-Za-z0-9_.:-]/g, "_").slice(0, 64);
|
|
5872
|
+
const datasetScope = `${options.client.baseUrl}:${toolId}:${sql}:${datasetLimit}`;
|
|
5873
|
+
const playDataset = createDeferredPlayDataset({
|
|
5874
|
+
datasetKind: "csv",
|
|
5875
|
+
datasetId: `sdk-tool-list:${toolId}:${stableHash(datasetScope)}:${datasetLimit}:${safeNonce}`,
|
|
5876
|
+
count: Math.min(totalRows, datasetLimit),
|
|
5877
|
+
previewRows,
|
|
5878
|
+
sourceLabel: "query result rows",
|
|
5879
|
+
tableNamespace: null,
|
|
5880
|
+
resolvers: {
|
|
5881
|
+
count: async () => Math.min(totalRows, datasetLimit),
|
|
5882
|
+
peek: async (limit) => collectRows(limit),
|
|
5883
|
+
materialize: async (limit) => collectRows(limit),
|
|
5884
|
+
iterate: () => ({
|
|
5885
|
+
async *[Symbol.asyncIterator]() {
|
|
5886
|
+
const count = Math.min(totalRows, datasetLimit);
|
|
5887
|
+
for (let offset = 0; offset < count; offset += QUERY_RESULT_DATASET_PAGE_SIZE) {
|
|
5888
|
+
yield* await fetchPage(
|
|
5889
|
+
offset,
|
|
5890
|
+
Math.min(QUERY_RESULT_DATASET_PAGE_SIZE, count - offset)
|
|
5891
|
+
);
|
|
5892
|
+
}
|
|
5893
|
+
}
|
|
5894
|
+
})
|
|
5895
|
+
}
|
|
5896
|
+
});
|
|
5897
|
+
return attachToolResultListDataset(result, {
|
|
5898
|
+
name: "rows",
|
|
5899
|
+
path: "toolResponse.raw.rows",
|
|
5900
|
+
dataset: playDataset,
|
|
5901
|
+
count: Math.min(totalRows, datasetLimit)
|
|
5902
|
+
});
|
|
5903
|
+
}
|
|
5904
|
+
function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
5726
5905
|
const raw = response.toolResponse?.raw ?? null;
|
|
5727
5906
|
const meta = response.toolResponse?.meta;
|
|
5728
5907
|
const metadata = isRecord5(response._metadata) ? response._metadata.tool : null;
|
|
5729
5908
|
const toolMetadata = isRecord5(metadata) ? metadata : {};
|
|
5730
|
-
return
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5909
|
+
return attachSdkQueryResultDatasetResult(
|
|
5910
|
+
fallbackToolId,
|
|
5911
|
+
createToolExecuteResult({
|
|
5912
|
+
status: typeof response.status === "string" ? response.status : "completed",
|
|
5913
|
+
jobId: typeof response.job_id === "string" ? response.job_id : void 0,
|
|
5914
|
+
result: {
|
|
5915
|
+
data: raw,
|
|
5916
|
+
...isRecord5(meta) ? { meta } : {}
|
|
5917
|
+
},
|
|
5918
|
+
metadata: {
|
|
5919
|
+
toolId: typeof toolMetadata.toolId === "string" ? toolMetadata.toolId : fallbackToolId,
|
|
5920
|
+
extractors: extractorDescriptorRecord(toolMetadata.extractors),
|
|
5921
|
+
targetGetters: stringArrayRecord(toolMetadata.targetGetters),
|
|
5922
|
+
listExtractorPaths: stringArray(toolMetadata.listExtractorPaths),
|
|
5923
|
+
listIdentityGetters: stringArrayRecord(
|
|
5924
|
+
toolMetadata.listIdentityGetters
|
|
5925
|
+
)
|
|
5926
|
+
},
|
|
5927
|
+
execution: {
|
|
5928
|
+
idempotent: true,
|
|
5929
|
+
cached: false,
|
|
5930
|
+
source: "live"
|
|
5931
|
+
},
|
|
5932
|
+
meta: isRecord5(response.meta) ? response.meta : void 0
|
|
5933
|
+
}),
|
|
5934
|
+
options
|
|
5935
|
+
);
|
|
5751
5936
|
}
|
|
5752
5937
|
function defineInput(schema) {
|
|
5753
5938
|
if (!schema || typeof schema !== "object" || Array.isArray(schema)) {
|
package/dist/index.mjs
CHANGED
|
@@ -352,10 +352,10 @@ var SDK_RELEASE = {
|
|
|
352
352
|
// 0.1.154 removes the short-lived generated enrich StepOptions recompute
|
|
353
353
|
// fields shipped in 0.1.153.
|
|
354
354
|
// 0.1.175 ships loud `deepline enrich` empty-waterfall reporting.
|
|
355
|
-
version: "0.1.
|
|
355
|
+
version: "0.1.182",
|
|
356
356
|
apiContract: "2026-06-dataset-handle-results-hard-cutover",
|
|
357
357
|
supportPolicy: {
|
|
358
|
-
latest: "0.1.
|
|
358
|
+
latest: "0.1.182",
|
|
359
359
|
minimumSupported: "0.1.53",
|
|
360
360
|
deprecatedBelow: "0.1.53",
|
|
361
361
|
commandMinimumSupported: [
|
|
@@ -2471,11 +2471,14 @@ var DeeplineClient = class {
|
|
|
2471
2471
|
const headers = {
|
|
2472
2472
|
[EXECUTE_RESPONSE_CONTRACT_HEADER]: V2_EXECUTE_RESPONSE_CONTRACT,
|
|
2473
2473
|
...options?.includeToolMetadata ? { [INCLUDE_TOOL_METADATA_HEADER]: "true" } : {},
|
|
2474
|
-
|
|
2474
|
+
[EXECUTE_RESPONSE_INTENT_HEADER]: options?.responseIntent ?? "raw"
|
|
2475
2475
|
};
|
|
2476
2476
|
return this.http.post(
|
|
2477
2477
|
`/api/v2/integrations/${encodeURIComponent(toolId)}/execute`,
|
|
2478
|
-
{
|
|
2478
|
+
{
|
|
2479
|
+
payload: input,
|
|
2480
|
+
...options?.metadata ? { metadata: options.metadata } : {}
|
|
2481
|
+
},
|
|
2479
2482
|
headers,
|
|
2480
2483
|
{
|
|
2481
2484
|
forbiddenAsApiError: true,
|
|
@@ -5280,6 +5283,73 @@ function createToolExecuteResult(input) {
|
|
|
5280
5283
|
});
|
|
5281
5284
|
return wrapper;
|
|
5282
5285
|
}
|
|
5286
|
+
function attachToolResultListDataset(result, input) {
|
|
5287
|
+
const existing = result._metadata.lists[input.name];
|
|
5288
|
+
result._metadata.lists[input.name] = {
|
|
5289
|
+
path: input.path,
|
|
5290
|
+
count: input.count,
|
|
5291
|
+
keys: input.keys ?? existing?.keys ?? {}
|
|
5292
|
+
};
|
|
5293
|
+
const accessor = {
|
|
5294
|
+
path: input.path,
|
|
5295
|
+
count: input.count,
|
|
5296
|
+
keys: result._metadata.lists[input.name].keys
|
|
5297
|
+
};
|
|
5298
|
+
Object.defineProperty(accessor, "get", {
|
|
5299
|
+
value() {
|
|
5300
|
+
return input.dataset;
|
|
5301
|
+
},
|
|
5302
|
+
enumerable: false
|
|
5303
|
+
});
|
|
5304
|
+
result.extractedLists[input.name] = accessor;
|
|
5305
|
+
const serialized = input.dataset.toJSON();
|
|
5306
|
+
let root = { toolResponse: { raw: result.toolResponse.raw } };
|
|
5307
|
+
const candidates = [...candidateResultPaths(input.path)].filter(
|
|
5308
|
+
(candidate, index, all) => all.indexOf(candidate) === index
|
|
5309
|
+
);
|
|
5310
|
+
for (const candidate of candidates) {
|
|
5311
|
+
if (!Array.isArray(getAtPath(root, candidate))) continue;
|
|
5312
|
+
root = replaceAtPath(root, candidate, serialized.preview);
|
|
5313
|
+
break;
|
|
5314
|
+
}
|
|
5315
|
+
if (isRecord4(root) && isRecord4(root.toolResponse) && Object.prototype.hasOwnProperty.call(root.toolResponse, "raw")) {
|
|
5316
|
+
result.toolResponse.raw = root.toolResponse.raw;
|
|
5317
|
+
result.toolOutput.raw = root.toolResponse.raw;
|
|
5318
|
+
}
|
|
5319
|
+
return result;
|
|
5320
|
+
}
|
|
5321
|
+
function replaceAtPath(root, path, replacement) {
|
|
5322
|
+
const segments = parsePath(path);
|
|
5323
|
+
if (segments.length === 0 || segments.includes("*")) return root;
|
|
5324
|
+
const replace = (current, index) => {
|
|
5325
|
+
if (index >= segments.length) return replacement;
|
|
5326
|
+
const segment = segments[index];
|
|
5327
|
+
if (typeof segment === "number") {
|
|
5328
|
+
if (!Array.isArray(current)) return current;
|
|
5329
|
+
const copy = [...current];
|
|
5330
|
+
copy[segment] = replace(copy[segment], index + 1);
|
|
5331
|
+
return copy;
|
|
5332
|
+
}
|
|
5333
|
+
if (!isRecord4(current)) return current;
|
|
5334
|
+
return {
|
|
5335
|
+
...current,
|
|
5336
|
+
[segment]: replace(current[segment], index + 1)
|
|
5337
|
+
};
|
|
5338
|
+
};
|
|
5339
|
+
return replace(root, 0);
|
|
5340
|
+
}
|
|
5341
|
+
|
|
5342
|
+
// ../shared_libs/play-runtime/query-result-dataset.ts
|
|
5343
|
+
var QUERY_RESULT_DATASET_PAGE_SIZE = 1e3;
|
|
5344
|
+
function isCustomerDbDatasetTool(toolId) {
|
|
5345
|
+
return /^(?:customer_db_)?query_customer_db$/.test(toolId);
|
|
5346
|
+
}
|
|
5347
|
+
function isSnowflakeQueryDatasetTool(toolId) {
|
|
5348
|
+
return /^snowflake_(?:snowflake_)?run_(?:semantic_)?query$/.test(toolId);
|
|
5349
|
+
}
|
|
5350
|
+
function isQueryResultDatasetTool(toolId) {
|
|
5351
|
+
return isCustomerDbDatasetTool(toolId) || isSnowflakeQueryDatasetTool(toolId);
|
|
5352
|
+
}
|
|
5283
5353
|
|
|
5284
5354
|
// src/play.ts
|
|
5285
5355
|
var DeeplineConditionalStepResolver = class _DeeplineConditionalStepResolver {
|
|
@@ -5455,9 +5525,13 @@ var DeeplineContext = class {
|
|
|
5455
5525
|
/** Execute a tool and return the standard execution envelope. */
|
|
5456
5526
|
execute: async (toolId, input) => {
|
|
5457
5527
|
const response = await this.client.executeTool(toolId, input, {
|
|
5458
|
-
includeToolMetadata: true
|
|
5528
|
+
includeToolMetadata: true,
|
|
5529
|
+
responseIntent: "dataset"
|
|
5530
|
+
});
|
|
5531
|
+
return toolExecutionEnvelopeToResult(toolId, response, {
|
|
5532
|
+
client: this.client,
|
|
5533
|
+
input
|
|
5459
5534
|
});
|
|
5460
|
-
return toolExecutionEnvelopeToResult(toolId, response);
|
|
5461
5535
|
}
|
|
5462
5536
|
};
|
|
5463
5537
|
}
|
|
@@ -5652,32 +5726,143 @@ function extractorDescriptorRecord(value) {
|
|
|
5652
5726
|
})
|
|
5653
5727
|
);
|
|
5654
5728
|
}
|
|
5655
|
-
function
|
|
5729
|
+
function rowsFromUnknown(value) {
|
|
5730
|
+
if (!Array.isArray(value)) return [];
|
|
5731
|
+
return value.map((row) => isRecord5(row) ? row : { value: row });
|
|
5732
|
+
}
|
|
5733
|
+
function finiteNonNegativeInteger(value) {
|
|
5734
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
5735
|
+
return null;
|
|
5736
|
+
}
|
|
5737
|
+
return Math.floor(value);
|
|
5738
|
+
}
|
|
5739
|
+
function finitePositiveInteger(value) {
|
|
5740
|
+
const integer = finiteNonNegativeInteger(value);
|
|
5741
|
+
return integer !== null && integer > 0 ? integer : null;
|
|
5742
|
+
}
|
|
5743
|
+
function stableHash(value) {
|
|
5744
|
+
let hash = 0;
|
|
5745
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
5746
|
+
hash = Math.imul(31, hash) + value.charCodeAt(index);
|
|
5747
|
+
hash |= 0;
|
|
5748
|
+
}
|
|
5749
|
+
return Math.abs(hash).toString(36);
|
|
5750
|
+
}
|
|
5751
|
+
function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
5752
|
+
if (!options || !isQueryResultDatasetTool(toolId)) return result;
|
|
5753
|
+
const raw = isRecord5(result.toolResponse.raw) ? result.toolResponse.raw : null;
|
|
5754
|
+
const dataset = isRecord5(raw?.dataset) ? raw.dataset : null;
|
|
5755
|
+
const totalRows = finiteNonNegativeInteger(dataset?.total_rows);
|
|
5756
|
+
const sql = typeof options.input.sql === "string" ? options.input.sql : typeof options.input.query === "string" ? options.input.query : typeof raw?.sql === "string" ? raw.sql : null;
|
|
5757
|
+
if (!dataset || totalRows === null || !sql) {
|
|
5758
|
+
return result;
|
|
5759
|
+
}
|
|
5760
|
+
const datasetLimit = finitePositiveInteger(dataset.returned_limit) ?? totalRows;
|
|
5761
|
+
const previewRows = rowsFromUnknown(raw?.rows).slice(0, 25);
|
|
5762
|
+
const fetchPage = async (offset, limit) => {
|
|
5763
|
+
if (limit <= 0 || offset >= totalRows) return [];
|
|
5764
|
+
const response = await options.client.executeTool(toolId, options.input, {
|
|
5765
|
+
includeToolMetadata: true,
|
|
5766
|
+
responseIntent: "dataset",
|
|
5767
|
+
metadata: {
|
|
5768
|
+
query_result_dataset: {
|
|
5769
|
+
limit: datasetLimit,
|
|
5770
|
+
offset,
|
|
5771
|
+
page_size: Math.min(limit, QUERY_RESULT_DATASET_PAGE_SIZE),
|
|
5772
|
+
total_rows: totalRows
|
|
5773
|
+
},
|
|
5774
|
+
...isCustomerDbDatasetTool(toolId) ? {
|
|
5775
|
+
customer_db_dataset: {
|
|
5776
|
+
limit: datasetLimit,
|
|
5777
|
+
offset,
|
|
5778
|
+
page_size: Math.min(limit, QUERY_RESULT_DATASET_PAGE_SIZE),
|
|
5779
|
+
total_rows: totalRows
|
|
5780
|
+
}
|
|
5781
|
+
} : {}
|
|
5782
|
+
}
|
|
5783
|
+
});
|
|
5784
|
+
const pageRaw = isRecord5(response.toolResponse?.raw) ? response.toolResponse.raw : null;
|
|
5785
|
+
return rowsFromUnknown(pageRaw?.rows);
|
|
5786
|
+
};
|
|
5787
|
+
const collectRows = async (limit) => {
|
|
5788
|
+
const target = Math.min(limit ?? totalRows, totalRows, datasetLimit);
|
|
5789
|
+
const collected = [];
|
|
5790
|
+
for (let offset = 0; offset < target; offset += QUERY_RESULT_DATASET_PAGE_SIZE) {
|
|
5791
|
+
collected.push(
|
|
5792
|
+
...await fetchPage(
|
|
5793
|
+
offset,
|
|
5794
|
+
Math.min(QUERY_RESULT_DATASET_PAGE_SIZE, target - offset)
|
|
5795
|
+
)
|
|
5796
|
+
);
|
|
5797
|
+
}
|
|
5798
|
+
return collected.slice(0, target);
|
|
5799
|
+
};
|
|
5800
|
+
const executionNonce = typeof result.job_id === "string" && result.job_id.trim() ? result.job_id.trim() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
5801
|
+
const safeNonce = executionNonce.replace(/[^A-Za-z0-9_.:-]/g, "_").slice(0, 64);
|
|
5802
|
+
const datasetScope = `${options.client.baseUrl}:${toolId}:${sql}:${datasetLimit}`;
|
|
5803
|
+
const playDataset = createDeferredPlayDataset({
|
|
5804
|
+
datasetKind: "csv",
|
|
5805
|
+
datasetId: `sdk-tool-list:${toolId}:${stableHash(datasetScope)}:${datasetLimit}:${safeNonce}`,
|
|
5806
|
+
count: Math.min(totalRows, datasetLimit),
|
|
5807
|
+
previewRows,
|
|
5808
|
+
sourceLabel: "query result rows",
|
|
5809
|
+
tableNamespace: null,
|
|
5810
|
+
resolvers: {
|
|
5811
|
+
count: async () => Math.min(totalRows, datasetLimit),
|
|
5812
|
+
peek: async (limit) => collectRows(limit),
|
|
5813
|
+
materialize: async (limit) => collectRows(limit),
|
|
5814
|
+
iterate: () => ({
|
|
5815
|
+
async *[Symbol.asyncIterator]() {
|
|
5816
|
+
const count = Math.min(totalRows, datasetLimit);
|
|
5817
|
+
for (let offset = 0; offset < count; offset += QUERY_RESULT_DATASET_PAGE_SIZE) {
|
|
5818
|
+
yield* await fetchPage(
|
|
5819
|
+
offset,
|
|
5820
|
+
Math.min(QUERY_RESULT_DATASET_PAGE_SIZE, count - offset)
|
|
5821
|
+
);
|
|
5822
|
+
}
|
|
5823
|
+
}
|
|
5824
|
+
})
|
|
5825
|
+
}
|
|
5826
|
+
});
|
|
5827
|
+
return attachToolResultListDataset(result, {
|
|
5828
|
+
name: "rows",
|
|
5829
|
+
path: "toolResponse.raw.rows",
|
|
5830
|
+
dataset: playDataset,
|
|
5831
|
+
count: Math.min(totalRows, datasetLimit)
|
|
5832
|
+
});
|
|
5833
|
+
}
|
|
5834
|
+
function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
5656
5835
|
const raw = response.toolResponse?.raw ?? null;
|
|
5657
5836
|
const meta = response.toolResponse?.meta;
|
|
5658
5837
|
const metadata = isRecord5(response._metadata) ? response._metadata.tool : null;
|
|
5659
5838
|
const toolMetadata = isRecord5(metadata) ? metadata : {};
|
|
5660
|
-
return
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5839
|
+
return attachSdkQueryResultDatasetResult(
|
|
5840
|
+
fallbackToolId,
|
|
5841
|
+
createToolExecuteResult({
|
|
5842
|
+
status: typeof response.status === "string" ? response.status : "completed",
|
|
5843
|
+
jobId: typeof response.job_id === "string" ? response.job_id : void 0,
|
|
5844
|
+
result: {
|
|
5845
|
+
data: raw,
|
|
5846
|
+
...isRecord5(meta) ? { meta } : {}
|
|
5847
|
+
},
|
|
5848
|
+
metadata: {
|
|
5849
|
+
toolId: typeof toolMetadata.toolId === "string" ? toolMetadata.toolId : fallbackToolId,
|
|
5850
|
+
extractors: extractorDescriptorRecord(toolMetadata.extractors),
|
|
5851
|
+
targetGetters: stringArrayRecord(toolMetadata.targetGetters),
|
|
5852
|
+
listExtractorPaths: stringArray(toolMetadata.listExtractorPaths),
|
|
5853
|
+
listIdentityGetters: stringArrayRecord(
|
|
5854
|
+
toolMetadata.listIdentityGetters
|
|
5855
|
+
)
|
|
5856
|
+
},
|
|
5857
|
+
execution: {
|
|
5858
|
+
idempotent: true,
|
|
5859
|
+
cached: false,
|
|
5860
|
+
source: "live"
|
|
5861
|
+
},
|
|
5862
|
+
meta: isRecord5(response.meta) ? response.meta : void 0
|
|
5863
|
+
}),
|
|
5864
|
+
options
|
|
5865
|
+
);
|
|
5681
5866
|
}
|
|
5682
5867
|
function defineInput(schema) {
|
|
5683
5868
|
if (!schema || typeof schema !== "object" || Array.isArray(schema)) {
|