deepline 0.1.181 → 0.1.183
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/child-play-await.ts +203 -6
- package/dist/bundling-sources/apps/play-runner-workers/src/child-play-submit.ts +8 -1
- package/dist/bundling-sources/apps/play-runner-workers/src/coordinator-entry.ts +633 -107
- package/dist/bundling-sources/apps/play-runner-workers/src/dedup-do.ts +3 -2
- package/dist/bundling-sources/apps/play-runner-workers/src/entry.ts +1932 -1838
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/harness-receipt-store.ts +116 -0
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/map-chunk-plan.ts +542 -78
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/output-datasets.ts +124 -12
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/receipts.ts +292 -11
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/run-work-dispatcher.ts +519 -0
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/tool-dispatch.ts +2381 -0
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/tool-receipts.ts +18 -5
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/work-budget.ts +130 -0
- package/dist/bundling-sources/apps/play-runner-workers/src/runtime/worker-platform-budget.ts +39 -0
- package/dist/bundling-sources/apps/play-runner-workers/src/workflow-retry-state.ts +2 -0
- package/dist/bundling-sources/sdk/src/client.ts +48 -5
- package/dist/bundling-sources/sdk/src/http.ts +23 -8
- package/dist/bundling-sources/sdk/src/play.ts +200 -26
- package/dist/bundling-sources/sdk/src/plays/harness-stub.ts +56 -3
- package/dist/bundling-sources/sdk/src/release.ts +2 -2
- package/dist/bundling-sources/sdk/src/types.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +132 -10
- package/dist/bundling-sources/shared_libs/play-runtime/auth-scope-resolver.ts +92 -0
- package/dist/bundling-sources/shared_libs/play-runtime/batch-runtime.ts +4 -4
- package/dist/bundling-sources/shared_libs/play-runtime/batching-types.ts +8 -0
- package/dist/bundling-sources/shared_libs/play-runtime/child-run-id.ts +101 -0
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +1857 -314
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +106 -6
- package/dist/bundling-sources/shared_libs/play-runtime/dedup-backend.ts +0 -0
- package/dist/bundling-sources/shared_libs/play-runtime/default-batch-strategies.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/durability-store.ts +4 -0
- package/dist/bundling-sources/shared_libs/play-runtime/durable-call-cache.ts +116 -16
- package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +186 -20
- package/dist/bundling-sources/shared_libs/play-runtime/dynamic-worker-version.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/execution-ledger-store.ts +133 -0
- package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +245 -0
- package/dist/bundling-sources/shared_libs/play-runtime/governor/governor.ts +5 -5
- package/dist/bundling-sources/shared_libs/play-runtime/governor/policy.ts +14 -0
- package/dist/bundling-sources/shared_libs/play-runtime/lease-policy.ts +52 -0
- package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +41 -0
- package/dist/bundling-sources/shared_libs/play-runtime/providers.ts +3 -2
- package/dist/bundling-sources/shared_libs/play-runtime/query-result-dataset.ts +120 -0
- package/dist/bundling-sources/shared_libs/play-runtime/receipt-sql.ts +124 -0
- package/dist/bundling-sources/shared_libs/play-runtime/receipt-status.ts +6 -2
- package/dist/bundling-sources/shared_libs/play-runtime/row-isolation.ts +48 -2
- package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +158 -15
- package/dist/bundling-sources/shared_libs/play-runtime/run-terminal-source.ts +45 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-actions.ts +9 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +2037 -262
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-contract.ts +42 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-attempt-state-machine.ts +183 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-errors.ts +88 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +8 -1
- package/dist/bundling-sources/shared_libs/play-runtime/sheet-attempt-sql.ts +103 -0
- package/dist/bundling-sources/shared_libs/play-runtime/suspension.ts +19 -1
- package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +343 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +43 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +11 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +139 -17
- package/dist/bundling-sources/shared_libs/play-runtime/work-receipt-state-machine.ts +437 -0
- package/dist/bundling-sources/shared_libs/play-runtime/work-receipts.ts +83 -6
- package/dist/bundling-sources/shared_libs/security/safe-outbound-fetch.ts +24 -17
- package/dist/cli/index.js +85 -23
- package/dist/cli/index.mjs +85 -23
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +274 -35
- package/dist/index.mjs +274 -35
- package/dist/plays/bundle-play-file.mjs +2 -2
- 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.183",
|
|
426
426
|
apiContract: "2026-06-dataset-handle-results-hard-cutover",
|
|
427
427
|
supportPolicy: {
|
|
428
|
-
latest: "0.1.
|
|
428
|
+
latest: "0.1.183",
|
|
429
429
|
minimumSupported: "0.1.53",
|
|
430
430
|
deprecatedBelow: "0.1.53",
|
|
431
431
|
commandMinimumSupported: [
|
|
@@ -583,6 +583,10 @@ var WORKER_CALLBACK_URL_OVERRIDE_HEADER = "x-deepline-worker-callback-url";
|
|
|
583
583
|
var RUNTIME_SCHEDULER_SCHEMA_OVERRIDE_HEADER = "x-deepline-runtime-scheduler-schema";
|
|
584
584
|
var SYNTHETIC_RUN_HEADER = "x-deepline-synthetic-run";
|
|
585
585
|
|
|
586
|
+
// ../shared_libs/play-runtime/test-runtime-seams.ts
|
|
587
|
+
var PLAY_RUNTIME_TEST_FAULT_HEADER = "x-deepline-test-fault";
|
|
588
|
+
var MAX_RUNTIME_TEST_POLICY_MS = 10 * 6e4;
|
|
589
|
+
|
|
586
590
|
// src/http.ts
|
|
587
591
|
var MAX_DIAGNOSTIC_HEADER_LENGTH = 120;
|
|
588
592
|
var COWORK_NETWORK_HINT = "Claude Cowork appears to be running Deepline in a network-restricted sandbox. In Claude Desktop, open Settings > Capabilities, turn on Allow network egress, and set Domain allowlist to All domains for the Cowork session.";
|
|
@@ -697,12 +701,9 @@ var HttpClient = class {
|
|
|
697
701
|
headers["x-deepline-play-artifact-r2-prefix"] = playArtifactR2Prefix;
|
|
698
702
|
}
|
|
699
703
|
const coordinatorUrl = typeof process !== "undefined" ? process.env?.DEEPLINE_COORDINATOR_URL : void 0;
|
|
704
|
+
const coordinatorInternalToken = typeof process !== "undefined" ? process.env?.DEEPLINE_INTERNAL_TOKEN : void 0;
|
|
700
705
|
if (coordinatorUrl?.trim()) {
|
|
701
706
|
headers[COORDINATOR_URL_OVERRIDE_HEADER] = coordinatorUrl.trim();
|
|
702
|
-
const coordinatorInternalToken = typeof process !== "undefined" ? process.env?.DEEPLINE_INTERNAL_TOKEN : void 0;
|
|
703
|
-
if (coordinatorInternalToken?.trim()) {
|
|
704
|
-
headers[COORDINATOR_INTERNAL_TOKEN_HEADER] = coordinatorInternalToken.trim();
|
|
705
|
-
}
|
|
706
707
|
}
|
|
707
708
|
const workerCallbackUrl = typeof process !== "undefined" ? process.env?.DEEPLINE_WORKER_CALLBACK_URL : void 0;
|
|
708
709
|
if (workerCallbackUrl?.trim()) {
|
|
@@ -716,6 +717,13 @@ var HttpClient = class {
|
|
|
716
717
|
if (syntheticRun && syntheticRun.trim() && syntheticRun.trim() !== "0") {
|
|
717
718
|
headers[SYNTHETIC_RUN_HEADER] = "1";
|
|
718
719
|
}
|
|
720
|
+
const runtimeTestFault = typeof process !== "undefined" ? process.env?.DEEPLINE_TEST_RUNTIME_FAULT : void 0;
|
|
721
|
+
if (runtimeTestFault?.trim()) {
|
|
722
|
+
headers[PLAY_RUNTIME_TEST_FAULT_HEADER] = runtimeTestFault.trim();
|
|
723
|
+
}
|
|
724
|
+
if (coordinatorInternalToken?.trim() && (coordinatorUrl?.trim() || workerCallbackUrl?.trim() || runtimeTestFault?.trim())) {
|
|
725
|
+
headers[COORDINATOR_INTERNAL_TOKEN_HEADER] = coordinatorInternalToken.trim();
|
|
726
|
+
}
|
|
719
727
|
return headers;
|
|
720
728
|
}
|
|
721
729
|
/**
|
|
@@ -1129,6 +1137,20 @@ function resolveTimingWindow(input) {
|
|
|
1129
1137
|
};
|
|
1130
1138
|
}
|
|
1131
1139
|
|
|
1140
|
+
// ../shared_libs/play-runtime/run-terminal-source.ts
|
|
1141
|
+
var PLAY_RUN_LEDGER_EVENT_SOURCES = [
|
|
1142
|
+
"worker",
|
|
1143
|
+
"temporal",
|
|
1144
|
+
"convex",
|
|
1145
|
+
"coordinator",
|
|
1146
|
+
"system"
|
|
1147
|
+
];
|
|
1148
|
+
function normalizePlayRunLedgerTerminalSource(value) {
|
|
1149
|
+
return PLAY_RUN_LEDGER_EVENT_SOURCES.includes(
|
|
1150
|
+
value
|
|
1151
|
+
) ? value : null;
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1132
1154
|
// ../shared_libs/play-runtime/run-ledger.ts
|
|
1133
1155
|
var LOG_TAIL_LIMIT = 100;
|
|
1134
1156
|
function isRecord(value) {
|
|
@@ -1265,7 +1287,8 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
|
|
|
1265
1287
|
),
|
|
1266
1288
|
resultTableNamespace: optionalNullableString(value.resultTableNamespace),
|
|
1267
1289
|
resultSummary: value.resultSummary,
|
|
1268
|
-
result: value.result
|
|
1290
|
+
result: value.result,
|
|
1291
|
+
terminalSource: normalizePlayRunLedgerTerminalSource(value.terminalSource)
|
|
1269
1292
|
};
|
|
1270
1293
|
}
|
|
1271
1294
|
function normalizeStepStatus(value) {
|
|
@@ -1990,6 +2013,33 @@ function resolvePlayRunIntegrationMode(request) {
|
|
|
1990
2013
|
request.integrationMode ?? process.env.DEEPLINE_EVAL_INTEGRATION_MODE
|
|
1991
2014
|
);
|
|
1992
2015
|
}
|
|
2016
|
+
function normalizeTestPolicyOverrides(value, source) {
|
|
2017
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
2018
|
+
return value;
|
|
2019
|
+
}
|
|
2020
|
+
throw new DeeplineError(
|
|
2021
|
+
`${source} must be a JSON object.`,
|
|
2022
|
+
void 0,
|
|
2023
|
+
"INVALID_TEST_POLICY_OVERRIDES"
|
|
2024
|
+
);
|
|
2025
|
+
}
|
|
2026
|
+
function parseEnvTestPolicyOverrides() {
|
|
2027
|
+
const raw = typeof process !== "undefined" ? process.env?.DEEPLINE_TEST_POLICY_OVERRIDES : void 0;
|
|
2028
|
+
const trimmed = raw?.trim();
|
|
2029
|
+
if (!trimmed) return void 0;
|
|
2030
|
+
let parsed;
|
|
2031
|
+
try {
|
|
2032
|
+
parsed = JSON.parse(trimmed);
|
|
2033
|
+
} catch (error) {
|
|
2034
|
+
const detail = error instanceof Error ? ` ${error.message}` : "";
|
|
2035
|
+
throw new DeeplineError(
|
|
2036
|
+
`DEEPLINE_TEST_POLICY_OVERRIDES must be valid JSON.${detail}`,
|
|
2037
|
+
void 0,
|
|
2038
|
+
"INVALID_TEST_POLICY_OVERRIDES"
|
|
2039
|
+
);
|
|
2040
|
+
}
|
|
2041
|
+
return normalizeTestPolicyOverrides(parsed, "DEEPLINE_TEST_POLICY_OVERRIDES");
|
|
2042
|
+
}
|
|
1993
2043
|
function sleep2(ms) {
|
|
1994
2044
|
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
1995
2045
|
}
|
|
@@ -2541,11 +2591,14 @@ var DeeplineClient = class {
|
|
|
2541
2591
|
const headers = {
|
|
2542
2592
|
[EXECUTE_RESPONSE_CONTRACT_HEADER]: V2_EXECUTE_RESPONSE_CONTRACT,
|
|
2543
2593
|
...options?.includeToolMetadata ? { [INCLUDE_TOOL_METADATA_HEADER]: "true" } : {},
|
|
2544
|
-
|
|
2594
|
+
[EXECUTE_RESPONSE_INTENT_HEADER]: options?.responseIntent ?? "raw"
|
|
2545
2595
|
};
|
|
2546
2596
|
return this.http.post(
|
|
2547
2597
|
`/api/v2/integrations/${encodeURIComponent(toolId)}/execute`,
|
|
2548
|
-
{
|
|
2598
|
+
{
|
|
2599
|
+
payload: input,
|
|
2600
|
+
...options?.metadata ? { metadata: options.metadata } : {}
|
|
2601
|
+
},
|
|
2549
2602
|
headers,
|
|
2550
2603
|
{
|
|
2551
2604
|
forbiddenAsApiError: true,
|
|
@@ -2629,6 +2682,7 @@ var DeeplineClient = class {
|
|
|
2629
2682
|
*/
|
|
2630
2683
|
async startPlayRun(request) {
|
|
2631
2684
|
const integrationMode = resolvePlayRunIntegrationMode(request);
|
|
2685
|
+
const testPolicyOverrides = request.testPolicyOverrides ?? parseEnvTestPolicyOverrides();
|
|
2632
2686
|
const forceToolRefresh = request.forceToolRefresh === true;
|
|
2633
2687
|
const response = await this.http.post(
|
|
2634
2688
|
"/api/v2/plays/run",
|
|
@@ -2656,7 +2710,8 @@ var DeeplineClient = class {
|
|
|
2656
2710
|
// defaults to workers_edge; tests and runtime probes that want a
|
|
2657
2711
|
// different profile pass `request.profile` explicitly.
|
|
2658
2712
|
...request.profile ? { profile: request.profile } : {},
|
|
2659
|
-
...integrationMode ? { integrationMode } : {}
|
|
2713
|
+
...integrationMode ? { integrationMode } : {},
|
|
2714
|
+
...testPolicyOverrides ? { testPolicyOverrides } : {}
|
|
2660
2715
|
}
|
|
2661
2716
|
);
|
|
2662
2717
|
return normalizePlayRunStart(response);
|
|
@@ -2674,6 +2729,7 @@ var DeeplineClient = class {
|
|
|
2674
2729
|
*/
|
|
2675
2730
|
async *startPlayRunStream(request, options) {
|
|
2676
2731
|
const integrationMode = resolvePlayRunIntegrationMode(request);
|
|
2732
|
+
const testPolicyOverrides = request.testPolicyOverrides ?? parseEnvTestPolicyOverrides();
|
|
2677
2733
|
const forceToolRefresh = request.forceToolRefresh === true;
|
|
2678
2734
|
const body = {
|
|
2679
2735
|
...request.name ? { name: request.name } : {},
|
|
@@ -2696,7 +2752,8 @@ var DeeplineClient = class {
|
|
|
2696
2752
|
...forceToolRefresh ? { forceToolRefresh: true } : {},
|
|
2697
2753
|
...typeof request.waitForCompletionMs === "number" ? { waitForCompletionMs: request.waitForCompletionMs } : {},
|
|
2698
2754
|
...request.profile ? { profile: request.profile } : {},
|
|
2699
|
-
...integrationMode ? { integrationMode } : {}
|
|
2755
|
+
...integrationMode ? { integrationMode } : {},
|
|
2756
|
+
...testPolicyOverrides ? { testPolicyOverrides } : {}
|
|
2700
2757
|
};
|
|
2701
2758
|
for await (const event of this.http.streamSse(
|
|
2702
2759
|
"/api/v2/plays/run?stream=true",
|
|
@@ -5350,6 +5407,73 @@ function createToolExecuteResult(input) {
|
|
|
5350
5407
|
});
|
|
5351
5408
|
return wrapper;
|
|
5352
5409
|
}
|
|
5410
|
+
function attachToolResultListDataset(result, input) {
|
|
5411
|
+
const existing = result._metadata.lists[input.name];
|
|
5412
|
+
result._metadata.lists[input.name] = {
|
|
5413
|
+
path: input.path,
|
|
5414
|
+
count: input.count,
|
|
5415
|
+
keys: input.keys ?? existing?.keys ?? {}
|
|
5416
|
+
};
|
|
5417
|
+
const accessor = {
|
|
5418
|
+
path: input.path,
|
|
5419
|
+
count: input.count,
|
|
5420
|
+
keys: result._metadata.lists[input.name].keys
|
|
5421
|
+
};
|
|
5422
|
+
Object.defineProperty(accessor, "get", {
|
|
5423
|
+
value() {
|
|
5424
|
+
return input.dataset;
|
|
5425
|
+
},
|
|
5426
|
+
enumerable: false
|
|
5427
|
+
});
|
|
5428
|
+
result.extractedLists[input.name] = accessor;
|
|
5429
|
+
const serialized = input.dataset.toJSON();
|
|
5430
|
+
let root = { toolResponse: { raw: result.toolResponse.raw } };
|
|
5431
|
+
const candidates = [...candidateResultPaths(input.path)].filter(
|
|
5432
|
+
(candidate, index, all) => all.indexOf(candidate) === index
|
|
5433
|
+
);
|
|
5434
|
+
for (const candidate of candidates) {
|
|
5435
|
+
if (!Array.isArray(getAtPath(root, candidate))) continue;
|
|
5436
|
+
root = replaceAtPath(root, candidate, serialized.preview);
|
|
5437
|
+
break;
|
|
5438
|
+
}
|
|
5439
|
+
if (isRecord4(root) && isRecord4(root.toolResponse) && Object.prototype.hasOwnProperty.call(root.toolResponse, "raw")) {
|
|
5440
|
+
result.toolResponse.raw = root.toolResponse.raw;
|
|
5441
|
+
result.toolOutput.raw = root.toolResponse.raw;
|
|
5442
|
+
}
|
|
5443
|
+
return result;
|
|
5444
|
+
}
|
|
5445
|
+
function replaceAtPath(root, path, replacement) {
|
|
5446
|
+
const segments = parsePath(path);
|
|
5447
|
+
if (segments.length === 0 || segments.includes("*")) return root;
|
|
5448
|
+
const replace = (current, index) => {
|
|
5449
|
+
if (index >= segments.length) return replacement;
|
|
5450
|
+
const segment = segments[index];
|
|
5451
|
+
if (typeof segment === "number") {
|
|
5452
|
+
if (!Array.isArray(current)) return current;
|
|
5453
|
+
const copy = [...current];
|
|
5454
|
+
copy[segment] = replace(copy[segment], index + 1);
|
|
5455
|
+
return copy;
|
|
5456
|
+
}
|
|
5457
|
+
if (!isRecord4(current)) return current;
|
|
5458
|
+
return {
|
|
5459
|
+
...current,
|
|
5460
|
+
[segment]: replace(current[segment], index + 1)
|
|
5461
|
+
};
|
|
5462
|
+
};
|
|
5463
|
+
return replace(root, 0);
|
|
5464
|
+
}
|
|
5465
|
+
|
|
5466
|
+
// ../shared_libs/play-runtime/query-result-dataset.ts
|
|
5467
|
+
var QUERY_RESULT_DATASET_PAGE_SIZE = 1e3;
|
|
5468
|
+
function isCustomerDbDatasetTool(toolId) {
|
|
5469
|
+
return /^(?:customer_db_)?query_customer_db$/.test(toolId);
|
|
5470
|
+
}
|
|
5471
|
+
function isSnowflakeQueryDatasetTool(toolId) {
|
|
5472
|
+
return /^snowflake_(?:snowflake_)?run_(?:semantic_)?query$/.test(toolId);
|
|
5473
|
+
}
|
|
5474
|
+
function isQueryResultDatasetTool(toolId) {
|
|
5475
|
+
return isCustomerDbDatasetTool(toolId) || isSnowflakeQueryDatasetTool(toolId);
|
|
5476
|
+
}
|
|
5353
5477
|
|
|
5354
5478
|
// src/play.ts
|
|
5355
5479
|
var DeeplineConditionalStepResolver = class _DeeplineConditionalStepResolver {
|
|
@@ -5525,9 +5649,13 @@ var DeeplineContext = class {
|
|
|
5525
5649
|
/** Execute a tool and return the standard execution envelope. */
|
|
5526
5650
|
execute: async (toolId, input) => {
|
|
5527
5651
|
const response = await this.client.executeTool(toolId, input, {
|
|
5528
|
-
includeToolMetadata: true
|
|
5652
|
+
includeToolMetadata: true,
|
|
5653
|
+
responseIntent: "dataset"
|
|
5654
|
+
});
|
|
5655
|
+
return toolExecutionEnvelopeToResult(toolId, response, {
|
|
5656
|
+
client: this.client,
|
|
5657
|
+
input
|
|
5529
5658
|
});
|
|
5530
|
-
return toolExecutionEnvelopeToResult(toolId, response);
|
|
5531
5659
|
}
|
|
5532
5660
|
};
|
|
5533
5661
|
}
|
|
@@ -5722,32 +5850,143 @@ function extractorDescriptorRecord(value) {
|
|
|
5722
5850
|
})
|
|
5723
5851
|
);
|
|
5724
5852
|
}
|
|
5725
|
-
function
|
|
5853
|
+
function rowsFromUnknown(value) {
|
|
5854
|
+
if (!Array.isArray(value)) return [];
|
|
5855
|
+
return value.map((row) => isRecord5(row) ? row : { value: row });
|
|
5856
|
+
}
|
|
5857
|
+
function finiteNonNegativeInteger(value) {
|
|
5858
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
5859
|
+
return null;
|
|
5860
|
+
}
|
|
5861
|
+
return Math.floor(value);
|
|
5862
|
+
}
|
|
5863
|
+
function finitePositiveInteger(value) {
|
|
5864
|
+
const integer = finiteNonNegativeInteger(value);
|
|
5865
|
+
return integer !== null && integer > 0 ? integer : null;
|
|
5866
|
+
}
|
|
5867
|
+
function stableHash(value) {
|
|
5868
|
+
let hash = 0;
|
|
5869
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
5870
|
+
hash = Math.imul(31, hash) + value.charCodeAt(index);
|
|
5871
|
+
hash |= 0;
|
|
5872
|
+
}
|
|
5873
|
+
return Math.abs(hash).toString(36);
|
|
5874
|
+
}
|
|
5875
|
+
function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
5876
|
+
if (!options || !isQueryResultDatasetTool(toolId)) return result;
|
|
5877
|
+
const raw = isRecord5(result.toolResponse.raw) ? result.toolResponse.raw : null;
|
|
5878
|
+
const dataset = isRecord5(raw?.dataset) ? raw.dataset : null;
|
|
5879
|
+
const totalRows = finiteNonNegativeInteger(dataset?.total_rows);
|
|
5880
|
+
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;
|
|
5881
|
+
if (!dataset || totalRows === null || !sql) {
|
|
5882
|
+
return result;
|
|
5883
|
+
}
|
|
5884
|
+
const datasetLimit = finitePositiveInteger(dataset.returned_limit) ?? totalRows;
|
|
5885
|
+
const previewRows = rowsFromUnknown(raw?.rows).slice(0, 25);
|
|
5886
|
+
const fetchPage = async (offset, limit) => {
|
|
5887
|
+
if (limit <= 0 || offset >= totalRows) return [];
|
|
5888
|
+
const response = await options.client.executeTool(toolId, options.input, {
|
|
5889
|
+
includeToolMetadata: true,
|
|
5890
|
+
responseIntent: "dataset",
|
|
5891
|
+
metadata: {
|
|
5892
|
+
query_result_dataset: {
|
|
5893
|
+
limit: datasetLimit,
|
|
5894
|
+
offset,
|
|
5895
|
+
page_size: Math.min(limit, QUERY_RESULT_DATASET_PAGE_SIZE),
|
|
5896
|
+
total_rows: totalRows
|
|
5897
|
+
},
|
|
5898
|
+
...isCustomerDbDatasetTool(toolId) ? {
|
|
5899
|
+
customer_db_dataset: {
|
|
5900
|
+
limit: datasetLimit,
|
|
5901
|
+
offset,
|
|
5902
|
+
page_size: Math.min(limit, QUERY_RESULT_DATASET_PAGE_SIZE),
|
|
5903
|
+
total_rows: totalRows
|
|
5904
|
+
}
|
|
5905
|
+
} : {}
|
|
5906
|
+
}
|
|
5907
|
+
});
|
|
5908
|
+
const pageRaw = isRecord5(response.toolResponse?.raw) ? response.toolResponse.raw : null;
|
|
5909
|
+
return rowsFromUnknown(pageRaw?.rows);
|
|
5910
|
+
};
|
|
5911
|
+
const collectRows = async (limit) => {
|
|
5912
|
+
const target = Math.min(limit ?? totalRows, totalRows, datasetLimit);
|
|
5913
|
+
const collected = [];
|
|
5914
|
+
for (let offset = 0; offset < target; offset += QUERY_RESULT_DATASET_PAGE_SIZE) {
|
|
5915
|
+
collected.push(
|
|
5916
|
+
...await fetchPage(
|
|
5917
|
+
offset,
|
|
5918
|
+
Math.min(QUERY_RESULT_DATASET_PAGE_SIZE, target - offset)
|
|
5919
|
+
)
|
|
5920
|
+
);
|
|
5921
|
+
}
|
|
5922
|
+
return collected.slice(0, target);
|
|
5923
|
+
};
|
|
5924
|
+
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)}`;
|
|
5925
|
+
const safeNonce = executionNonce.replace(/[^A-Za-z0-9_.:-]/g, "_").slice(0, 64);
|
|
5926
|
+
const datasetScope = `${options.client.baseUrl}:${toolId}:${sql}:${datasetLimit}`;
|
|
5927
|
+
const playDataset = createDeferredPlayDataset({
|
|
5928
|
+
datasetKind: "csv",
|
|
5929
|
+
datasetId: `sdk-tool-list:${toolId}:${stableHash(datasetScope)}:${datasetLimit}:${safeNonce}`,
|
|
5930
|
+
count: Math.min(totalRows, datasetLimit),
|
|
5931
|
+
previewRows,
|
|
5932
|
+
sourceLabel: "query result rows",
|
|
5933
|
+
tableNamespace: null,
|
|
5934
|
+
resolvers: {
|
|
5935
|
+
count: async () => Math.min(totalRows, datasetLimit),
|
|
5936
|
+
peek: async (limit) => collectRows(limit),
|
|
5937
|
+
materialize: async (limit) => collectRows(limit),
|
|
5938
|
+
iterate: () => ({
|
|
5939
|
+
async *[Symbol.asyncIterator]() {
|
|
5940
|
+
const count = Math.min(totalRows, datasetLimit);
|
|
5941
|
+
for (let offset = 0; offset < count; offset += QUERY_RESULT_DATASET_PAGE_SIZE) {
|
|
5942
|
+
yield* await fetchPage(
|
|
5943
|
+
offset,
|
|
5944
|
+
Math.min(QUERY_RESULT_DATASET_PAGE_SIZE, count - offset)
|
|
5945
|
+
);
|
|
5946
|
+
}
|
|
5947
|
+
}
|
|
5948
|
+
})
|
|
5949
|
+
}
|
|
5950
|
+
});
|
|
5951
|
+
return attachToolResultListDataset(result, {
|
|
5952
|
+
name: "rows",
|
|
5953
|
+
path: "toolResponse.raw.rows",
|
|
5954
|
+
dataset: playDataset,
|
|
5955
|
+
count: Math.min(totalRows, datasetLimit)
|
|
5956
|
+
});
|
|
5957
|
+
}
|
|
5958
|
+
function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
5726
5959
|
const raw = response.toolResponse?.raw ?? null;
|
|
5727
5960
|
const meta = response.toolResponse?.meta;
|
|
5728
5961
|
const metadata = isRecord5(response._metadata) ? response._metadata.tool : null;
|
|
5729
5962
|
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
|
-
|
|
5963
|
+
return attachSdkQueryResultDatasetResult(
|
|
5964
|
+
fallbackToolId,
|
|
5965
|
+
createToolExecuteResult({
|
|
5966
|
+
status: typeof response.status === "string" ? response.status : "completed",
|
|
5967
|
+
jobId: typeof response.job_id === "string" ? response.job_id : void 0,
|
|
5968
|
+
result: {
|
|
5969
|
+
data: raw,
|
|
5970
|
+
...isRecord5(meta) ? { meta } : {}
|
|
5971
|
+
},
|
|
5972
|
+
metadata: {
|
|
5973
|
+
toolId: typeof toolMetadata.toolId === "string" ? toolMetadata.toolId : fallbackToolId,
|
|
5974
|
+
extractors: extractorDescriptorRecord(toolMetadata.extractors),
|
|
5975
|
+
targetGetters: stringArrayRecord(toolMetadata.targetGetters),
|
|
5976
|
+
listExtractorPaths: stringArray(toolMetadata.listExtractorPaths),
|
|
5977
|
+
listIdentityGetters: stringArrayRecord(
|
|
5978
|
+
toolMetadata.listIdentityGetters
|
|
5979
|
+
)
|
|
5980
|
+
},
|
|
5981
|
+
execution: {
|
|
5982
|
+
idempotent: true,
|
|
5983
|
+
cached: false,
|
|
5984
|
+
source: "live"
|
|
5985
|
+
},
|
|
5986
|
+
meta: isRecord5(response.meta) ? response.meta : void 0
|
|
5987
|
+
}),
|
|
5988
|
+
options
|
|
5989
|
+
);
|
|
5751
5990
|
}
|
|
5752
5991
|
function defineInput(schema) {
|
|
5753
5992
|
if (!schema || typeof schema !== "object" || Array.isArray(schema)) {
|