farseer-cli 1.14.1 → 1.15.0

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.
Files changed (69) hide show
  1. package/dist/commands/config.js +4 -3
  2. package/dist/commands/config.js.map +2 -2
  3. package/dist/commands/install.js +5 -0
  4. package/dist/commands/install.js.map +2 -2
  5. package/dist/commands/login.js +2 -2
  6. package/dist/commands/login.js.map +2 -2
  7. package/dist/commands/pull.js +9 -3
  8. package/dist/commands/pull.js.map +2 -2
  9. package/dist/commands/run.js +9 -0
  10. package/dist/commands/run.js.map +2 -2
  11. package/dist/index.js +7 -2
  12. package/dist/index.js.map +2 -2
  13. package/dist/mcp/tools/appTools.js.map +2 -2
  14. package/dist/mcp/tools/authTools.js +5 -3
  15. package/dist/mcp/tools/authTools.js.map +2 -2
  16. package/dist/mcp/tools/cellTools.js +3 -2
  17. package/dist/mcp/tools/cellTools.js.map +2 -2
  18. package/dist/mcp/tools/dashboardTools.js +23 -18
  19. package/dist/mcp/tools/dashboardTools.js.map +2 -2
  20. package/dist/mcp/tools/dataTools.js +13 -11
  21. package/dist/mcp/tools/dataTools.js.map +2 -2
  22. package/dist/mcp/tools/folderTools.js +5 -4
  23. package/dist/mcp/tools/folderTools.js.map +2 -2
  24. package/dist/mcp/tools/modelTools.js +27 -17
  25. package/dist/mcp/tools/modelTools.js.map +2 -2
  26. package/dist/mcp/tools/pipelineContract.js +5 -2
  27. package/dist/mcp/tools/pipelineContract.js.map +2 -2
  28. package/dist/mcp/tools/runTools.js +8 -3
  29. package/dist/mcp/tools/runTools.js.map +2 -2
  30. package/dist/mcp/tools/sheetTools.js +21 -17
  31. package/dist/mcp/tools/sheetTools.js.map +2 -2
  32. package/dist/mcp/tools/syncTools.js +11 -5
  33. package/dist/mcp/tools/syncTools.js.map +2 -2
  34. package/dist/mcp/utils/registerTool.js +32 -0
  35. package/dist/mcp/utils/registerTool.js.map +7 -0
  36. package/dist/pipeline/generated-reference.json +3 -3
  37. package/dist/pipeline/operations.js +4 -1
  38. package/dist/pipeline/operations.js.map +2 -2
  39. package/dist/pipeline/query.js +58 -40
  40. package/dist/pipeline/query.js.map +2 -2
  41. package/dist/pipeline/queryDownloads.js +72 -0
  42. package/dist/pipeline/queryDownloads.js.map +7 -0
  43. package/dist/pipeline/queryWorker.js +8 -31
  44. package/dist/pipeline/queryWorker.js.map +2 -2
  45. package/dist/pipeline/readiness.js +15 -8
  46. package/dist/pipeline/readiness.js.map +2 -2
  47. package/dist/pipeline/reference.js +2 -1
  48. package/dist/pipeline/reference.js.map +2 -2
  49. package/dist/pipeline/runtime.js +4 -3
  50. package/dist/pipeline/runtime.js.map +2 -2
  51. package/dist/pipeline/service.js +110 -50
  52. package/dist/pipeline/service.js.map +2 -2
  53. package/dist/services/appSyncService.js.map +1 -1
  54. package/dist/services/configService.js +11 -4
  55. package/dist/services/configService.js.map +2 -2
  56. package/dist/services/farseerService.js +23 -0
  57. package/dist/services/farseerService.js.map +2 -2
  58. package/dist/services/modelExport.js.map +1 -1
  59. package/dist/utils/agentSandbox.js +35 -0
  60. package/dist/utils/agentSandbox.js.map +7 -0
  61. package/dist/utils/constants.js +4 -7
  62. package/dist/utils/constants.js.map +2 -2
  63. package/dist/utils/packageManager.js +40 -11
  64. package/dist/utils/packageManager.js.map +2 -2
  65. package/dist/utils/updateCheck.js +4 -2
  66. package/dist/utils/updateCheck.js.map +2 -2
  67. package/docs/pipeline-client-guide.md +4 -4
  68. package/package.json +2 -2
  69. package/skills/pipeline-authoring/SKILL.md +5 -5
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var queryDownloads_exports = {};
30
+ __export(queryDownloads_exports, {
31
+ downloadQueryFiles: () => downloadQueryFiles
32
+ });
33
+ module.exports = __toCommonJS(queryDownloads_exports);
34
+ var fs = __toESM(require("fs"));
35
+ var path = __toESM(require("path"));
36
+ async function downloadQueryFiles(request, directory, download) {
37
+ let downloadedBytes = 0;
38
+ let fileCount = 0;
39
+ const groups = [];
40
+ for (const [index, binding] of request.bindings.entries()) {
41
+ const group = [];
42
+ groups.push(group);
43
+ const urls = binding.urls ?? (binding.url ? [binding.url] : []);
44
+ if (!urls.length || urls.length > 512) throw new Error("Unsupported version file count");
45
+ for (const [fileIndex, address] of urls.entries()) {
46
+ const response = await download(address, index, fileIndex);
47
+ if (!response.ok || !response.body) {
48
+ await response.body?.cancel();
49
+ throw new Error(`Dataset read failed (${response.status}); retry as a new query`);
50
+ }
51
+ const file = path.join(directory, `${fileCount++}.parquet`);
52
+ const handle = await fs.promises.open(file, "wx", 384);
53
+ try {
54
+ for await (const chunk of response.body) {
55
+ downloadedBytes += chunk.byteLength;
56
+ if (downloadedBytes > request.limits.inputBytes)
57
+ throw new Error("Input download byte limit exceeded");
58
+ await handle.write(chunk);
59
+ }
60
+ } finally {
61
+ await handle.close();
62
+ }
63
+ group.push(file);
64
+ }
65
+ }
66
+ return { groups, downloadedBytes };
67
+ }
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ downloadQueryFiles
71
+ });
72
+ //# sourceMappingURL=queryDownloads.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/pipeline/queryDownloads.ts"],
4
+ "sourcesContent": ["import * as fs from 'fs';\nimport * as path from 'path';\nimport type { QueryRequest } from './query';\n\nexport interface QueryFiles {\n groups: string[][];\n downloadedBytes: number;\n}\n\n/** Shared byte limits for direct signed downloads and authenticated backend downloads. */\nexport async function downloadQueryFiles(\n request: QueryRequest,\n directory: string,\n download: (address: string, binding: number, file: number) => Promise<Response>,\n): Promise<QueryFiles> {\n let downloadedBytes = 0;\n let fileCount = 0;\n const groups: string[][] = [];\n for (const [index, binding] of request.bindings.entries()) {\n const group: string[] = [];\n groups.push(group);\n const urls = binding.urls ?? (binding.url ? [binding.url] : []);\n if (!urls.length || urls.length > 512) throw new Error('Unsupported version file count');\n for (const [fileIndex, address] of urls.entries()) {\n const response = await download(address, index, fileIndex);\n if (!response.ok || !response.body) {\n await response.body?.cancel();\n throw new Error(`Dataset read failed (${response.status}); retry as a new query`);\n }\n const file = path.join(directory, `${fileCount++}.parquet`);\n const handle = await fs.promises.open(file, 'wx', 0o600);\n try {\n for await (const chunk of response.body as any) {\n downloadedBytes += chunk.byteLength;\n if (downloadedBytes > request.limits.inputBytes)\n throw new Error('Input download byte limit exceeded');\n await handle.write(chunk);\n }\n } finally {\n await handle.close();\n }\n group.push(file);\n }\n }\n return { groups, downloadedBytes };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;AAStB,eAAsB,mBAClB,SACA,WACA,UACmB;AACnB,MAAI,kBAAkB;AACtB,MAAI,YAAY;AAChB,QAAM,SAAqB,CAAC;AAC5B,aAAW,CAAC,OAAO,OAAO,KAAK,QAAQ,SAAS,QAAQ,GAAG;AACvD,UAAM,QAAkB,CAAC;AACzB,WAAO,KAAK,KAAK;AACjB,UAAM,OAAO,QAAQ,SAAS,QAAQ,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;AAC7D,QAAI,CAAC,KAAK,UAAU,KAAK,SAAS,IAAK,OAAM,IAAI,MAAM,gCAAgC;AACvF,eAAW,CAAC,WAAW,OAAO,KAAK,KAAK,QAAQ,GAAG;AAC/C,YAAM,WAAW,MAAM,SAAS,SAAS,OAAO,SAAS;AACzD,UAAI,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM;AAChC,cAAM,SAAS,MAAM,OAAO;AAC5B,cAAM,IAAI,MAAM,wBAAwB,SAAS,MAAM,yBAAyB;AAAA,MACpF;AACA,YAAM,OAAO,KAAK,KAAK,WAAW,GAAG,WAAW,UAAU;AAC1D,YAAM,SAAS,MAAM,GAAG,SAAS,KAAK,MAAM,MAAM,GAAK;AACvD,UAAI;AACA,yBAAiB,SAAS,SAAS,MAAa;AAC5C,6BAAmB,MAAM;AACzB,cAAI,kBAAkB,QAAQ,OAAO;AACjC,kBAAM,IAAI,MAAM,oCAAoC;AACxD,gBAAM,OAAO,MAAM,KAAK;AAAA,QAC5B;AAAA,MACJ,UAAE;AACE,cAAM,OAAO,MAAM;AAAA,MACvB;AACA,YAAM,KAAK,IAAI;AAAA,IACnB;AAAA,EACJ;AACA,SAAO,EAAE,QAAQ,gBAAgB;AACrC;",
6
+ "names": []
7
+ }
@@ -22,43 +22,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  mod
23
23
  ));
24
24
  var import_node_api = require("@duckdb/node-api");
25
- var fs = __toESM(require("fs"));
26
25
  var path = __toESM(require("path"));
26
+ var import_queryDownloads = require("./queryDownloads");
27
27
  const literal = (s) => `'${s.replace(/'/g, "''")}'`;
28
28
  process.once("message", async (request) => {
29
29
  const { directory, limits } = request;
30
30
  try {
31
- let downloadedBytes = 0;
32
- const files = [];
33
- const groups = [];
34
- for (const binding of request.bindings) {
35
- const group = [];
36
- groups.push(group);
37
- const urls = binding.urls ?? (binding.url ? [binding.url] : []);
38
- if (!urls.length || urls.length > 512) throw new Error("Unsupported version file count");
39
- for (const address of urls) {
40
- const url = new URL(address);
41
- if (url.protocol !== "https:" && !(request.loopbackTest && url.protocol === "http:" && url.hostname === "127.0.0.1")) {
42
- throw new Error("Signed access must use HTTPS");
43
- }
44
- const response = await fetch(url, { redirect: "error" });
45
- if (!response.ok || !response.body)
46
- throw new Error(`Signed read failed (${response.status}); retry as a new query`);
47
- const file = path.join(directory, `${files.length}.parquet`);
48
- const handle = await fs.promises.open(file, "wx", 384);
49
- try {
50
- for await (const chunk of response.body) {
51
- downloadedBytes += chunk.byteLength;
52
- if (downloadedBytes > limits.inputBytes) throw new Error("Input download byte limit exceeded");
53
- await handle.write(chunk);
54
- }
55
- } finally {
56
- await handle.close();
57
- }
58
- files.push(file);
59
- group.push(file);
31
+ const { groups, downloadedBytes } = request.prepared ?? await (0, import_queryDownloads.downloadQueryFiles)(request, directory, async (address) => {
32
+ const url = new URL(address);
33
+ if (url.protocol !== "https:" && !(request.loopbackTest && url.protocol === "http:" && url.hostname === "127.0.0.1")) {
34
+ throw new Error("Signed access must use HTTPS");
60
35
  }
61
- }
36
+ return fetch(url, { redirect: "error" });
37
+ });
38
+ const files = groups.flat();
62
39
  const db = await import_node_api.DuckDBInstance.create(":memory:", {
63
40
  memory_limit: `${limits.memoryMb}MB`,
64
41
  threads: String(limits.threads),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/pipeline/queryWorker.ts"],
4
- "sourcesContent": ["// Runs in a disposable child process. No tenant token or user environment is inherited.\nimport { DuckDBInstance, StatementType } from '@duckdb/node-api';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport type { QueryRequest } from './query';\n\nconst literal = (s: string) => `'${s.replace(/'/g, \"''\")}'`;\nprocess.once('message', async (request: QueryRequest & { directory: string }) => {\n const { directory, limits } = request;\n try {\n let downloadedBytes = 0;\n const files: string[] = [];\n const groups: string[][] = [];\n for (const binding of request.bindings) {\n const group: string[] = [];\n groups.push(group);\n const urls = binding.urls ?? (binding.url ? [binding.url] : []);\n if (!urls.length || urls.length > 512) throw new Error('Unsupported version file count');\n for (const address of urls) {\n const url = new URL(address);\n if (\n url.protocol !== 'https:' &&\n !(request.loopbackTest && url.protocol === 'http:' && url.hostname === '127.0.0.1')\n ) {\n throw new Error('Signed access must use HTTPS');\n }\n // One fixed grant, no credential forwarding, redirects or automatic rebinding.\n const response = await fetch(url, { redirect: 'error' });\n if (!response.ok || !response.body)\n throw new Error(`Signed read failed (${response.status}); retry as a new query`);\n const file = path.join(directory, `${files.length}.parquet`);\n const handle = await fs.promises.open(file, 'wx', 0o600);\n try {\n for await (const chunk of response.body as any) {\n downloadedBytes += chunk.byteLength;\n if (downloadedBytes > limits.inputBytes) throw new Error('Input download byte limit exceeded');\n await handle.write(chunk);\n }\n } finally {\n await handle.close();\n }\n files.push(file);\n group.push(file);\n }\n }\n const db = await DuckDBInstance.create(':memory:', {\n memory_limit: `${limits.memoryMb}MB`,\n threads: String(limits.threads),\n temp_directory: path.join(directory, 'spill'),\n max_temp_directory_size: `${limits.spillMb}MB`,\n autoinstall_known_extensions: 'false',\n autoload_known_extensions: 'false',\n allow_unsigned_extensions: 'false',\n });\n const connection = await db.connect();\n await connection.run(`SET allowed_paths = [${files.map(literal).join(',')}]`);\n await connection.run('SET enable_external_access = false');\n for (const [i, binding] of request.bindings.entries()) {\n if (!/^[a-zA-Z_][a-zA-Z0-9_]{0,62}$/.test(binding.name)) throw new Error('Invalid SQL binding name');\n await connection.run(\n `CREATE VIEW \"${binding.name}\" AS SELECT * FROM read_parquet([${groups[i].map(literal).join(',')}])`,\n );\n }\n await connection.run('SET lock_configuration = true');\n const statements = await connection.extractStatements(request.sql);\n if (statements.count !== 1) throw new Error('Exactly one SELECT query is supported');\n const prepared = await statements.prepare(0);\n if (prepared.statementType !== StatementType.SELECT) throw new Error('Only SELECT queries are supported');\n prepared.destroySync();\n // Streaming avoids materializing an unbounded result in JS. Timeout includes downloads.\n const result = await connection.stream(request.sql);\n const rows: unknown[][] = [];\n let bytes = 0;\n let truncated = false;\n outer: for await (const chunk of result.yieldRowsJson()) {\n for (const row of chunk) {\n const size = Buffer.byteLength(JSON.stringify(row));\n if (rows.length >= limits.rows || bytes + size > limits.resultBytes) {\n truncated = true;\n break outer;\n }\n rows.push(row);\n bytes += size;\n }\n }\n process.send?.({\n ok: true,\n result: {\n columns: result.columnNames(),\n rows,\n truncated,\n complete: !truncated,\n downloadedBytes,\n resultBytes: bytes,\n },\n });\n } catch (error) {\n const message = String(error instanceof Error ? error.message : error)\n .replace(/https?:\\/\\/[^\\s'\"<>]+/g, '[signed URL redacted]')\n .split(directory)\n .join('[query temp]');\n process.send?.({ ok: false, error: message.slice(0, 2000) });\n } finally {\n process.disconnect();\n }\n});\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AACA,sBAA8C;AAC9C,SAAoB;AACpB,WAAsB;AAGtB,MAAM,UAAU,CAAC,MAAc,IAAI,EAAE,QAAQ,MAAM,IAAI,CAAC;AACxD,QAAQ,KAAK,WAAW,OAAO,YAAkD;AAC7E,QAAM,EAAE,WAAW,OAAO,IAAI;AAC9B,MAAI;AACA,QAAI,kBAAkB;AACtB,UAAM,QAAkB,CAAC;AACzB,UAAM,SAAqB,CAAC;AAC5B,eAAW,WAAW,QAAQ,UAAU;AACpC,YAAM,QAAkB,CAAC;AACzB,aAAO,KAAK,KAAK;AACjB,YAAM,OAAO,QAAQ,SAAS,QAAQ,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;AAC7D,UAAI,CAAC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AAU,KAAK,EAChE,QAAQ,0BAA0B,uBAAuB,EACzD,MAAM,SAAS,EACf,KAAK,cAAc;AACxB,YAAQ,OAAO,EAAE,IAAI,OAAO,OAAO,QAAQ,MAAM,GAAG,GAAI,EAAE,CAAC;AAAA,EAC/D,UAAE;AACE,YAAQ,WAAW;AAAA,EACvB;AACJ,CAAC;",
4
+ "sourcesContent": ["// Runs in a disposable child process. No tenant token or user environment is inherited.\nimport { DuckDBInstance, StatementType } from '@duckdb/node-api';\nimport * as path from 'path';\nimport type { QueryRequest } from './query';\nimport { downloadQueryFiles, type QueryFiles } from './queryDownloads';\n\nconst literal = (s: string) => `'${s.replace(/'/g, \"''\")}'`;\nprocess.once('message', async (request: QueryRequest & { directory: string; prepared?: QueryFiles }) => {\n const { directory, limits } = request;\n try {\n const { groups, downloadedBytes } =\n request.prepared ??\n (await downloadQueryFiles(request, directory, async (address) => {\n const url = new URL(address);\n if (\n url.protocol !== 'https:' &&\n !(request.loopbackTest && url.protocol === 'http:' && url.hostname === '127.0.0.1')\n ) {\n throw new Error('Signed access must use HTTPS');\n }\n // One fixed grant, no credential forwarding, redirects or automatic rebinding.\n return fetch(url, { redirect: 'error' });\n }));\n const files = groups.flat();\n const db = await DuckDBInstance.create(':memory:', {\n memory_limit: `${limits.memoryMb}MB`,\n threads: String(limits.threads),\n temp_directory: path.join(directory, 'spill'),\n max_temp_directory_size: `${limits.spillMb}MB`,\n autoinstall_known_extensions: 'false',\n autoload_known_extensions: 'false',\n allow_unsigned_extensions: 'false',\n });\n const connection = await db.connect();\n await connection.run(`SET allowed_paths = [${files.map(literal).join(',')}]`);\n await connection.run('SET enable_external_access = false');\n for (const [i, binding] of request.bindings.entries()) {\n if (!/^[a-zA-Z_][a-zA-Z0-9_]{0,62}$/.test(binding.name)) throw new Error('Invalid SQL binding name');\n await connection.run(\n `CREATE VIEW \"${binding.name}\" AS SELECT * FROM read_parquet([${groups[i].map(literal).join(',')}])`,\n );\n }\n await connection.run('SET lock_configuration = true');\n const statements = await connection.extractStatements(request.sql);\n if (statements.count !== 1) throw new Error('Exactly one SELECT query is supported');\n const prepared = await statements.prepare(0);\n if (prepared.statementType !== StatementType.SELECT) throw new Error('Only SELECT queries are supported');\n prepared.destroySync();\n // Streaming avoids materializing an unbounded result in JS. Timeout includes downloads.\n const result = await connection.stream(request.sql);\n const rows: unknown[][] = [];\n let bytes = 0;\n let truncated = false;\n outer: for await (const chunk of result.yieldRowsJson()) {\n for (const row of chunk) {\n const size = Buffer.byteLength(JSON.stringify(row));\n if (rows.length >= limits.rows || bytes + size > limits.resultBytes) {\n truncated = true;\n break outer;\n }\n rows.push(row);\n bytes += size;\n }\n }\n process.send?.({\n ok: true,\n result: {\n columns: result.columnNames(),\n rows,\n truncated,\n complete: !truncated,\n downloadedBytes,\n resultBytes: bytes,\n },\n });\n } catch (error) {\n const message = String(error instanceof Error ? error.message : error)\n .replace(/https?:\\/\\/[^\\s'\"<>]+/g, '[signed URL redacted]')\n .split(directory)\n .join('[query temp]');\n process.send?.({ ok: false, error: message.slice(0, 2000) });\n } finally {\n process.disconnect();\n }\n});\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AACA,sBAA8C;AAC9C,WAAsB;AAEtB,4BAAoD;AAEpD,MAAM,UAAU,CAAC,MAAc,IAAI,EAAE,QAAQ,MAAM,IAAI,CAAC;AACxD,QAAQ,KAAK,WAAW,OAAO,YAAyE;AACpG,QAAM,EAAE,WAAW,OAAO,IAAI;AAC9B,MAAI;AACA,UAAM,EAAE,QAAQ,gBAAgB,IAC5B,QAAQ,YACP,UAAM,0CAAmB,SAAS,WAAW,OAAO,YAAY;AAC7D,YAAM,MAAM,IAAI,IAAI,OAAO;AAC3B,UACI,IAAI,aAAa,YACjB,EAAE,QAAQ,gBAAgB,IAAI,aAAa,WAAW,IAAI,aAAa,cACzE;AACE,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAClD;AAEA,aAAO,MAAM,KAAK,EAAE,UAAU,QAAQ,CAA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,OAAO,OAAO,WAAW,KAAK,UAAU,GAAG,CAAC;AAClD,YAAI,KAAK,UAAU,OAAO,QAAQ,QAAQ,OAAO,OAAO,aAAa;AACjE,sBAAY;AACZ,gBAAM;AAAA,QACV;AACA,aAAK,KAAK,GAAG;AACb,iBAAS;AAAA,MACb;AAAA,IACJ;AACA,YAAQ,OAAO;AAAA,MACX,IAAI;AAAA,MACJ,QAAQ;AAAA,QACJ,SAAS,OAAO,YAAY;AAAA,QAC5B;AAAA,QACA;AAAA,QACA,UAAU,CAAC;AAAA,QACX;AAAA,QACA,aAAa;AAAA,MACjB;AAAA,IACJ,CAAC;AAAA,EACL,SAAS,OAAO;AACZ,UAAM,UAAU,OAAO,iBAAiB,QAAQ,MAAM,UAAU,KAAK,EAChE,QAAQ,0BAA0B,uBAAuB,EACzD,MAAM,SAAS,EACf,KAAK,cAAc;AACxB,YAAQ,OAAO,EAAE,IAAI,OAAO,OAAO,QAAQ,MAAM,GAAG,GAAI,EAAE,CAAC;AAAA,EAC/D,UAAE;AACE,YAAQ,WAAW;AAAA,EACvB;AACJ,CAAC;",
6
6
  "names": []
7
7
  }
@@ -18,21 +18,27 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var readiness_exports = {};
20
20
  __export(readiness_exports, {
21
- probeParquetAccess: () => probeParquetAccess
21
+ probeParquetAccess: () => probeParquetAccess,
22
+ probeParquetPrefix: () => probeParquetPrefix
22
23
  });
23
24
  module.exports = __toCommonJS(readiness_exports);
24
25
  var import_requests = require("./requests");
25
26
  async function probeParquetAccess(address) {
26
27
  if (new URL(address).protocol !== "https:") throw new Error("Signed read access must use HTTPS");
27
- await (0, import_requests.boundedPipelineCall)(async () => {
28
- const response = await fetch(address, {
28
+ await probeParquetPrefix(
29
+ (signal) => fetch(address, {
29
30
  headers: { Range: "bytes=0-3" },
30
31
  redirect: "error",
31
- signal: (0, import_requests.pipelineRequestSignal)()
32
- });
32
+ signal
33
+ })
34
+ );
35
+ }
36
+ async function probeParquetPrefix(open) {
37
+ await (0, import_requests.boundedPipelineCall)(async () => {
38
+ const response = await open((0, import_requests.pipelineRequestSignal)());
33
39
  if (!response.ok || !response.body) {
34
40
  await response.body?.cancel();
35
- throw new Error(`Signed read probe failed (${response.status})`);
41
+ throw new Error(`Read probe failed (${response.status})`);
36
42
  }
37
43
  const reader = response.body.getReader();
38
44
  const prefix = [];
@@ -42,7 +48,7 @@ async function probeParquetAccess(address) {
42
48
  if (next.done) break;
43
49
  prefix.push(...next.value.subarray(0, 4 - prefix.length));
44
50
  }
45
- if (Buffer.from(prefix).toString("ascii") !== "PAR1") throw new Error("Signed object is not Parquet");
51
+ if (Buffer.from(prefix).toString("ascii") !== "PAR1") throw new Error("Probed file is not Parquet");
46
52
  } finally {
47
53
  await reader.cancel();
48
54
  }
@@ -50,6 +56,7 @@ async function probeParquetAccess(address) {
50
56
  }
51
57
  // Annotate the CommonJS export names for ESM import in node:
52
58
  0 && (module.exports = {
53
- probeParquetAccess
59
+ probeParquetAccess,
60
+ probeParquetPrefix
54
61
  });
55
62
  //# sourceMappingURL=readiness.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/pipeline/readiness.ts"],
4
- "sourcesContent": ["import { boundedPipelineCall, pipelineRequestSignal } from './requests';\n\n/** Probe one fixed grant without tenant credentials, redirects, or a full download. */\nexport async function probeParquetAccess(address: string): Promise<void> {\n if (new URL(address).protocol !== 'https:') throw new Error('Signed read access must use HTTPS');\n await boundedPipelineCall(async () => {\n const response = await fetch(address, {\n headers: { Range: 'bytes=0-3' },\n redirect: 'error',\n signal: pipelineRequestSignal(),\n });\n if (!response.ok || !response.body) {\n await response.body?.cancel();\n throw new Error(`Signed read probe failed (${response.status})`);\n }\n const reader = response.body.getReader();\n const prefix: number[] = [];\n try {\n while (prefix.length < 4) {\n const next = await reader.read();\n if (next.done) break;\n prefix.push(...next.value.subarray(0, 4 - prefix.length));\n }\n if (Buffer.from(prefix).toString('ascii') !== 'PAR1') throw new Error('Signed object is not Parquet');\n } finally {\n await reader.cancel(); // Also stops servers that ignored the Range header.\n }\n });\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA2D;AAG3D,eAAsB,mBAAmB,SAAgC;AACrE,MAAI,IAAI,IAAI,OAAO,EAAE,aAAa,SAAU,OAAM,IAAI,MAAM,mCAAmC;AAC/F,YAAM,qCAAoB,YAAY;AAClC,UAAM,WAAW,MAAM,MAAM,SAAS;AAAA,MAClC,SAAS,EAAE,OAAO,YAAY;AAAA,MAC9B,UAAU;AAAA,MACV,YAAQ,uCAAsB;AAAA,IAClC,CAAC;AACD,QAAI,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM;AAChC,YAAM,SAAS,MAAM,OAAO;AAC5B,YAAM,IAAI,MAAM,6BAA6B,SAAS,MAAM,GAAG;AAAA,IACnE;AACA,UAAM,SAAS,SAAS,KAAK,UAAU;AACvC,UAAM,SAAmB,CAAC;AAC1B,QAAI;AACA,aAAO,OAAO,SAAS,GAAG;AACtB,cAAM,OAAO,MAAM,OAAO,KAAK;AAC/B,YAAI,KAAK,KAAM;AACf,eAAO,KAAK,GAAG,KAAK,MAAM,SAAS,GAAG,IAAI,OAAO,MAAM,CAAC;AAAA,MAC5D;AACA,UAAI,OAAO,KAAK,MAAM,EAAE,SAAS,OAAO,MAAM,OAAQ,OAAM,IAAI,MAAM,8BAA8B;AAAA,IACxG,UAAE;AACE,YAAM,OAAO,OAAO;AAAA,IACxB;AAAA,EACJ,CAAC;AACL;",
4
+ "sourcesContent": ["import { boundedPipelineCall, pipelineRequestSignal } from './requests';\n\n/** Probe one fixed grant without tenant credentials, redirects, or a full download. */\nexport async function probeParquetAccess(address: string): Promise<void> {\n if (new URL(address).protocol !== 'https:') throw new Error('Signed read access must use HTTPS');\n await probeParquetPrefix((signal) =>\n fetch(address, {\n headers: { Range: 'bytes=0-3' },\n redirect: 'error',\n signal,\n }),\n );\n}\n\n/** Read a file's first four bytes, confirm the Parquet magic number, and stop the download there. */\nexport async function probeParquetPrefix(open: (signal: AbortSignal) => Promise<Response>): Promise<void> {\n await boundedPipelineCall(async () => {\n // boundedPipelineCall always sets the request signal.\n const response = await open(pipelineRequestSignal()!);\n if (!response.ok || !response.body) {\n await response.body?.cancel();\n throw new Error(`Read probe failed (${response.status})`);\n }\n const reader = response.body.getReader();\n const prefix: number[] = [];\n try {\n while (prefix.length < 4) {\n const next = await reader.read();\n if (next.done) break;\n prefix.push(...next.value.subarray(0, 4 - prefix.length));\n }\n if (Buffer.from(prefix).toString('ascii') !== 'PAR1') throw new Error('Probed file is not Parquet');\n } finally {\n await reader.cancel(); // Also stops servers that ignore Range, as the API's file route does.\n }\n });\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA2D;AAG3D,eAAsB,mBAAmB,SAAgC;AACrE,MAAI,IAAI,IAAI,OAAO,EAAE,aAAa,SAAU,OAAM,IAAI,MAAM,mCAAmC;AAC/F,QAAM;AAAA,IAAmB,CAAC,WACtB,MAAM,SAAS;AAAA,MACX,SAAS,EAAE,OAAO,YAAY;AAAA,MAC9B,UAAU;AAAA,MACV;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;AAGA,eAAsB,mBAAmB,MAAiE;AACtG,YAAM,qCAAoB,YAAY;AAElC,UAAM,WAAW,MAAM,SAAK,uCAAsB,CAAE;AACpD,QAAI,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM;AAChC,YAAM,SAAS,MAAM,OAAO;AAC5B,YAAM,IAAI,MAAM,sBAAsB,SAAS,MAAM,GAAG;AAAA,IAC5D;AACA,UAAM,SAAS,SAAS,KAAK,UAAU;AACvC,UAAM,SAAmB,CAAC;AAC1B,QAAI;AACA,aAAO,OAAO,SAAS,GAAG;AACtB,cAAM,OAAO,MAAM,OAAO,KAAK;AAC/B,YAAI,KAAK,KAAM;AACf,eAAO,KAAK,GAAG,KAAK,MAAM,SAAS,GAAG,IAAI,OAAO,MAAM,CAAC;AAAA,MAC5D;AACA,UAAI,OAAO,KAAK,MAAM,EAAE,SAAS,OAAO,MAAM,OAAQ,OAAM,IAAI,MAAM,4BAA4B;AAAA,IACtG,UAAE;AACE,YAAM,OAAO,OAAO;AAAA,IACxB;AAAA,EACJ,CAAC;AACL;",
6
6
  "names": []
7
7
  }
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(reference_exports);
37
37
  var import_generated_reference = __toESM(require("./generated-reference.json"));
38
38
  var import_guide = require("./guide");
39
39
  var import_constants = require("../utils/constants");
40
+ var import_agentSandbox = require("../utils/agentSandbox");
40
41
  const PIPELINE_ENGINE_PROFILE = import_generated_reference.default.engineProfile;
41
42
  function engineReport(observations) {
42
43
  const expected = PIPELINE_ENGINE_PROFILE;
@@ -46,7 +47,7 @@ function engineReport(observations) {
46
47
  const line = ran.split(".").slice(0, 2).join(".");
47
48
  return { ran, expected, status: line === expected ? "match" : "mismatch" };
48
49
  }
49
- const CLI_UPDATE_INSTRUCTION = "Update to the latest compatible CLI: npm install -g farseer-cli@latest. Restart the MCP connection in your AI client after updating. Until the matching CLI is published, install the build supplied by the setup owner.";
50
+ const CLI_UPDATE_INSTRUCTION = (0, import_agentSandbox.inAgentSandbox)() ? "This chat's CLI comes with its sandbox and cannot be updated here; do not try to install one. Tell the user that a new chat starts with the newest CLI this deployment provides, and that if it is still too old, a Labs admin must update the sandbox image." : "Update to the latest compatible CLI: npm install -g farseer-cli@latest. Restart the MCP connection in your AI client after updating. Until the matching CLI is published, install the build supplied by the setup owner.";
50
51
  function pipelineGuide(topic = "method") {
51
52
  const header = `Pipeline authoring reference: engine ${import_generated_reference.default.engineVersion}; CLI ${import_constants.CLI_VERSION}.
52
53
  This is the bundled reference for the prepared pipeline runtime; the engine was not detected from a job.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/pipeline/reference.ts"],
4
- "sourcesContent": ["import reference from './generated-reference.json';\nimport { PIPELINE_GUIDE, PIPELINE_PRACTICES } from './guide';\nimport { CLI_VERSION } from '../utils/constants';\n\n/** The engine line (major.minor) this CLI's grammar describes. Patch releases keep the grammar. */\nexport const PIPELINE_ENGINE_PROFILE = reference.engineProfile;\n\nexport interface EngineReport {\n /** Engine version the run reported at startup, or null when no start marker was inspected. */\n ran: string | null;\n /** Engine line (major.minor) this CLI's bundled grammar describes. */\n expected: string;\n status: 'match' | 'mismatch' | 'unobserved';\n}\n\n/** Compare the engine line a run actually started on against the one this CLI's grammar describes. */\nexport function engineReport(observations: Record<string, unknown>[]): EngineReport {\n const expected = PIPELINE_ENGINE_PROFILE;\n const started = observations.find((o) => o.event === 'pipeline_started');\n const ran = typeof started?.version === 'string' ? started.version : null;\n if (ran === null) return { ran, expected, status: 'unobserved' };\n const line = ran.split('.').slice(0, 2).join('.');\n return { ran, expected, status: line === expected ? 'match' : 'mismatch' };\n}\nexport const CLI_UPDATE_INSTRUCTION =\n 'Update to the latest compatible CLI: npm install -g farseer-cli@latest. Restart the MCP connection in your AI client after updating. Until the matching CLI is published, install the build supplied by the setup owner.';\n\nexport function pipelineGuide(topic = 'method'): string {\n const header =\n `Pipeline authoring reference: engine ${reference.engineVersion}; CLI ${CLI_VERSION}.\\n` +\n 'This is the bundled reference for the prepared pipeline runtime; the engine was not detected from a job.\\n\\n';\n if (topic === 'method')\n return (\n header +\n PIPELINE_GUIDE +\n '\\nRead topic=\"grammar\" for the generated YAML reference, then request the model names it links to.\\n' +\n CLI_UPDATE_INSTRUCTION\n );\n if (topic === 'practices') return header + PIPELINE_PRACTICES;\n const topics: Record<string, string> = reference.topics;\n if (topic === 'grammar')\n return (\n header +\n reference.notice +\n '\\n\\n' +\n topics.DatasetDefinition +\n '\\nAvailable topics (use their exact names as topic):\\n' +\n Object.keys(topics).join(', ')\n );\n if (!Object.prototype.hasOwnProperty.call(topics, topic))\n throw new Error(`Unknown guide topic \"${topic}\". Read topic=\"grammar\" to list supported model names.`);\n return header + reference.notice + '\\n\\n' + topics[topic];\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAAsB;AACtB,mBAAmD;AACnD,uBAA4B;AAGrB,MAAM,0BAA0B,2BAAAA,QAAU;AAW1C,SAAS,aAAa,cAAuD;AAChF,QAAM,WAAW;AACjB,QAAM,UAAU,aAAa,KAAK,CAAC,MAAM,EAAE,UAAU,kBAAkB;AACvE,QAAM,MAAM,OAAO,SAAS,YAAY,WAAW,QAAQ,UAAU;AACrE,MAAI,QAAQ,KAAM,QAAO,EAAE,KAAK,UAAU,QAAQ,aAAa;AAC/D,QAAM,OAAO,IAAI,MAAM,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG;AAChD,SAAO,EAAE,KAAK,UAAU,QAAQ,SAAS,WAAW,UAAU,WAAW;AAC7E;AACO,MAAM,yBACT;AAEG,SAAS,cAAc,QAAQ,UAAkB;AACpD,QAAM,SACF,wCAAwC,2BAAAA,QAAU,aAAa,SAAS,4BAAW;AAAA;AAAA;AAAA;AAEvF,MAAI,UAAU;AACV,WACI,SACA,8BACA,yGACA;AAER,MAAI,UAAU,YAAa,QAAO,SAAS;AAC3C,QAAM,SAAiC,2BAAAA,QAAU;AACjD,MAAI,UAAU;AACV,WACI,SACA,2BAAAA,QAAU,SACV,SACA,OAAO,oBACP,2DACA,OAAO,KAAK,MAAM,EAAE,KAAK,IAAI;AAErC,MAAI,CAAC,OAAO,UAAU,eAAe,KAAK,QAAQ,KAAK;AACnD,UAAM,IAAI,MAAM,wBAAwB,KAAK,wDAAwD;AACzG,SAAO,SAAS,2BAAAA,QAAU,SAAS,SAAS,OAAO,KAAK;AAC5D;",
4
+ "sourcesContent": ["import reference from './generated-reference.json';\nimport { PIPELINE_GUIDE, PIPELINE_PRACTICES } from './guide';\nimport { CLI_VERSION } from '../utils/constants';\nimport { inAgentSandbox } from '../utils/agentSandbox';\n\n/** The engine line (major.minor) this CLI's grammar describes. Patch releases keep the grammar. */\nexport const PIPELINE_ENGINE_PROFILE = reference.engineProfile;\n\nexport interface EngineReport {\n /** Engine version the run reported at startup, or null when no start marker was inspected. */\n ran: string | null;\n /** Engine line (major.minor) this CLI's bundled grammar describes. */\n expected: string;\n status: 'match' | 'mismatch' | 'unobserved';\n}\n\n/** Compare the engine line a run actually started on against the one this CLI's grammar describes. */\nexport function engineReport(observations: Record<string, unknown>[]): EngineReport {\n const expected = PIPELINE_ENGINE_PROFILE;\n const started = observations.find((o) => o.event === 'pipeline_started');\n const ran = typeof started?.version === 'string' ? started.version : null;\n if (ran === null) return { ran, expected, status: 'unobserved' };\n const line = ran.split('.').slice(0, 2).join('.');\n return { ran, expected, status: line === expected ? 'match' : 'mismatch' };\n}\n// An agent sandbox's CLI is part of its image and the sandbox cannot reach npm; a conversation keeps\n// its image, so only a new chat (on the deployment's current image) can bring a newer CLI.\nexport const CLI_UPDATE_INSTRUCTION = inAgentSandbox()\n ? \"This chat's CLI comes with its sandbox and cannot be updated here; do not try to install one. Tell the user that a new chat starts with the newest CLI this deployment provides, and that if it is still too old, a Labs admin must update the sandbox image.\"\n : 'Update to the latest compatible CLI: npm install -g farseer-cli@latest. Restart the MCP connection in your AI client after updating. Until the matching CLI is published, install the build supplied by the setup owner.';\n\nexport function pipelineGuide(topic = 'method'): string {\n const header =\n `Pipeline authoring reference: engine ${reference.engineVersion}; CLI ${CLI_VERSION}.\\n` +\n 'This is the bundled reference for the prepared pipeline runtime; the engine was not detected from a job.\\n\\n';\n if (topic === 'method')\n return (\n header +\n PIPELINE_GUIDE +\n '\\nRead topic=\"grammar\" for the generated YAML reference, then request the model names it links to.\\n' +\n CLI_UPDATE_INSTRUCTION\n );\n if (topic === 'practices') return header + PIPELINE_PRACTICES;\n const topics: Record<string, string> = reference.topics;\n if (topic === 'grammar')\n return (\n header +\n reference.notice +\n '\\n\\n' +\n topics.DatasetDefinition +\n '\\nAvailable topics (use their exact names as topic):\\n' +\n Object.keys(topics).join(', ')\n );\n if (!Object.prototype.hasOwnProperty.call(topics, topic))\n throw new Error(`Unknown guide topic \"${topic}\". Read topic=\"grammar\" to list supported model names.`);\n return header + reference.notice + '\\n\\n' + topics[topic];\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAAsB;AACtB,mBAAmD;AACnD,uBAA4B;AAC5B,0BAA+B;AAGxB,MAAM,0BAA0B,2BAAAA,QAAU;AAW1C,SAAS,aAAa,cAAuD;AAChF,QAAM,WAAW;AACjB,QAAM,UAAU,aAAa,KAAK,CAAC,MAAM,EAAE,UAAU,kBAAkB;AACvE,QAAM,MAAM,OAAO,SAAS,YAAY,WAAW,QAAQ,UAAU;AACrE,MAAI,QAAQ,KAAM,QAAO,EAAE,KAAK,UAAU,QAAQ,aAAa;AAC/D,QAAM,OAAO,IAAI,MAAM,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG;AAChD,SAAO,EAAE,KAAK,UAAU,QAAQ,SAAS,WAAW,UAAU,WAAW;AAC7E;AAGO,MAAM,6BAAyB,oCAAe,IAC/C,kQACA;AAEC,SAAS,cAAc,QAAQ,UAAkB;AACpD,QAAM,SACF,wCAAwC,2BAAAA,QAAU,aAAa,SAAS,4BAAW;AAAA;AAAA;AAAA;AAEvF,MAAI,UAAU;AACV,WACI,SACA,8BACA,yGACA;AAER,MAAI,UAAU,YAAa,QAAO,SAAS;AAC3C,QAAM,SAAiC,2BAAAA,QAAU;AACjD,MAAI,UAAU;AACV,WACI,SACA,2BAAAA,QAAU,SACV,SACA,OAAO,oBACP,2DACA,OAAO,KAAK,MAAM,EAAE,KAAK,IAAI;AAErC,MAAI,CAAC,OAAO,UAAU,eAAe,KAAK,QAAQ,KAAK;AACnD,UAAM,IAAI,MAAM,wBAAwB,KAAK,wDAAwD;AACzG,SAAO,SAAS,2BAAAA,QAAU,SAAS,SAAS,OAAO,KAAK;AAC5D;",
6
6
  "names": ["reference"]
7
7
  }
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(runtime_exports);
37
37
  var import_generated_reference = __toESM(require("./generated-reference.json"));
38
38
  var import_reference = require("./reference");
39
39
  var import_errors = require("./errors");
40
+ var import_agentSandbox = require("../utils/agentSandbox");
40
41
  const PIPELINE_RUNNER_IMAGE = import_generated_reference.default.runnerImage;
41
42
  const RELEASE_VERSION = /^\d+\.\d+\.\d+$/;
42
43
  function split(image) {
@@ -66,7 +67,7 @@ function compareRuntime(jobImage) {
66
67
  status: "unversioned",
67
68
  jobVersion: null,
68
69
  expected,
69
- nextAction: `The job's image "${jobImage}" is not a released ${bundled.repository} version. The next run pins it to ${PIPELINE_RUNNER_IMAGE} before submitting.`
70
+ nextAction: `The job's image "${jobImage}" is a moving tag or digest, not a released ${bundled.repository} version, so this CLI leaves the image as it is. Each run reports the engine it started on: read engine in inspect.`
70
71
  };
71
72
  const order = compareVersions(job.tag, expected);
72
73
  if (order === 0) return { status: "match", jobVersion: job.tag, expected, nextAction: "" };
@@ -75,13 +76,13 @@ function compareRuntime(jobImage) {
75
76
  status: "behind",
76
77
  jobVersion: job.tag,
77
78
  expected,
78
- nextAction: `The job runs ${bundled.repository}:${job.tag}; this CLI authors for ${expected}. The next run moves the job to ${PIPELINE_RUNNER_IMAGE} before submitting; fix what the newer engine's preflight rejects.`
79
+ nextAction: `The job runs ${bundled.repository}:${job.tag}; this CLI authors for ${expected}. Run, pull and reads work on the job's image, but push is refused until the job is upgraded: ask the user, then run upgrade-runtime, which moves the job to ${PIPELINE_RUNNER_IMAGE} for everyone on the tenant and for its next scheduled run.${(0, import_agentSandbox.inAgentSandbox)() ? "" : " Or keep the job on its image and author with the CLI release that targets it."}`
79
80
  };
80
81
  return {
81
82
  status: "ahead",
82
83
  jobVersion: job.tag,
83
84
  expected,
84
- nextAction: `The job runs ${bundled.repository}:${job.tag}; this CLI authors for ${expected}. ${import_reference.CLI_UPDATE_INSTRUCTION}`
85
+ nextAction: `The job runs ${bundled.repository}:${job.tag}; this CLI authors for ${expected}. Run and push work on the job's image, but this CLI does not describe what the newer engine added. ${import_reference.CLI_UPDATE_INSTRUCTION}`
85
86
  };
86
87
  }
87
88
  function assertPipelineRuntime(jobImage) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/pipeline/runtime.ts"],
4
- "sourcesContent": ["import reference from './generated-reference.json';\nimport { CLI_UPDATE_INSTRUCTION } from './reference';\nimport { PipelineError } from './errors';\n\n/** The runner image tag this CLI was released in tandem with, as `<repository>:<version>`. */\nexport const PIPELINE_RUNNER_IMAGE: string = reference.runnerImage;\n\nexport interface RuntimeComparison {\n status: 'match' | 'behind' | 'ahead' | 'unversioned' | 'incompatible';\n /** Version parsed from the job's image tag, or null when the tag is not a release version. */\n jobVersion: string | null;\n /** Version this CLI authors for. */\n expected: string;\n nextAction: string;\n}\n\nconst RELEASE_VERSION = /^\\d+\\.\\d+\\.\\d+$/;\n\nfunction split(image: string): { repository: string; tag: string | null } {\n const name = image.slice(image.lastIndexOf('/') + 1);\n if (name.includes('@')) return { repository: name.slice(0, name.indexOf('@')).split(':')[0], tag: null };\n const colon = name.indexOf(':');\n return colon < 0\n ? { repository: name, tag: null }\n : { repository: name.slice(0, colon), tag: name.slice(colon + 1) };\n}\n\n/** Numeric three-part comparison; negative when `a` is older than `b`. */\nexport function compareVersions(a: string, b: string): number {\n const [pa, pb] = [a, b].map((v) => v.split('.').map(Number));\n for (let i = 0; i < 3; i++) if (pa[i] !== pb[i]) return pa[i] < pb[i] ? -1 : 1;\n return 0;\n}\n\n/**\n * The CLI authors for exactly one engine: the one inside the runner image it was\n * released with. A job behind it is moved up on the next run; a CLI behind a job is\n * updated. Nothing moves down.\n */\nexport function compareRuntime(jobImage: string): RuntimeComparison {\n const bundled = split(PIPELINE_RUNNER_IMAGE);\n const expected = bundled.tag ?? '';\n const job = split(jobImage);\n if (job.repository !== bundled.repository)\n return {\n status: 'incompatible',\n jobVersion: null,\n expected,\n nextAction:\n 'Use the existing app tools to inspect, run or maintain this app in its current implementation. Do not change its runner or entrypoint to satisfy pipeline setup. Migration to Simple Pipelines requires an explicit migration request.',\n };\n if (!job.tag || !RELEASE_VERSION.test(job.tag))\n return {\n status: 'unversioned',\n jobVersion: null,\n expected,\n nextAction: `The job's image \"${jobImage}\" is not a released ${bundled.repository} version. The next run pins it to ${PIPELINE_RUNNER_IMAGE} before submitting.`,\n };\n const order = compareVersions(job.tag, expected);\n if (order === 0) return { status: 'match', jobVersion: job.tag, expected, nextAction: '' };\n if (order < 0)\n return {\n status: 'behind',\n jobVersion: job.tag,\n expected,\n nextAction: `The job runs ${bundled.repository}:${job.tag}; this CLI authors for ${expected}. The next run moves the job to ${PIPELINE_RUNNER_IMAGE} before submitting; fix what the newer engine's preflight rejects.`,\n };\n return {\n status: 'ahead',\n jobVersion: job.tag,\n expected,\n nextAction: `The job runs ${bundled.repository}:${job.tag}; this CLI authors for ${expected}. ${CLI_UPDATE_INSTRUCTION}`,\n };\n}\n\n/** Version pinning may upgrade Simple Pipelines, but must never convert another kind of app. */\nexport function assertPipelineRuntime(jobImage: string): RuntimeComparison {\n const runtime = compareRuntime(jobImage);\n if (runtime.status === 'incompatible')\n throw new PipelineError(\n 'refused',\n 'PIPELINE_RUNTIME_UNSUPPORTED',\n `Runner image \"${jobImage || '(tenant default or unknown)'}\" is not a Simple Pipelines runner. The existing app must be preserved.`,\n runtime.nextAction,\n );\n return runtime;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAAsB;AACtB,uBAAuC;AACvC,oBAA8B;AAGvB,MAAM,wBAAgC,2BAAAA,QAAU;AAWvD,MA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C/C,MAAI,UAAU,EAAG,QAAO,EAAE,QAAQ,SAAS,YAAY,IAAI,KAAK,UAAU,YAAY,GAAG;AACzF,MAAI,QAAQ;AACR,WAAO;AAAA,MACH,QAAQ;AAAA,MACR,YAAY,IAAI;AAAA,MAChB;AAAA,MACA,YAAY,gBAAgB,QAAQ,UAAU,IAAI,IAAI,GAAG,0BAA0B,QAAQ,mCAAmC,qBAAqB;AAAA,IACvJ;AACJ,SAAO;AAAA,IACH,QAAQ;AAAA,IACR,YAAY,IAAI;AAAA,IAChB;AAAA,IACA,YAAY,gBAAgB,QAAQ,UAAU,IAAI,IAAI,GAAG,0BAA0B,QAAQ,KAAK,uCAAsB;AAAA,EAC1H;AACJ;AAGO,SAAS,sBAAsB,UAAqC;AACvE,QAAM,UAAU,eAAe,QAAQ;AACvC,MAAI,QAAQ,WAAW;AACnB,UAAM,IAAI;AAAA,MACN;AAAA,MACA;AAAA,MACA,iBAAiB,YAAY,6BAA6B;AAAA,MAC1D,QAAQ;AAAA,IACZ;AACJ,SAAO;AACX;",
4
+ "sourcesContent": ["import reference from './generated-reference.json';\nimport { CLI_UPDATE_INSTRUCTION } from './reference';\nimport { PipelineError } from './errors';\nimport { inAgentSandbox } from '../utils/agentSandbox';\n\n/** The runner image tag this CLI was released in tandem with, as `<repository>:<version>`. */\nexport const PIPELINE_RUNNER_IMAGE: string = reference.runnerImage;\n\nexport interface RuntimeComparison {\n status: 'match' | 'behind' | 'ahead' | 'unversioned' | 'incompatible';\n /** Version parsed from the job's image tag, or null when the tag is not a release version. */\n jobVersion: string | null;\n /** Version this CLI authors for. */\n expected: string;\n nextAction: string;\n}\n\nconst RELEASE_VERSION = /^\\d+\\.\\d+\\.\\d+$/;\n\nfunction split(image: string): { repository: string; tag: string | null } {\n const name = image.slice(image.lastIndexOf('/') + 1);\n if (name.includes('@')) return { repository: name.slice(0, name.indexOf('@')).split(':')[0], tag: null };\n const colon = name.indexOf(':');\n return colon < 0\n ? { repository: name, tag: null }\n : { repository: name.slice(0, colon), tag: name.slice(colon + 1) };\n}\n\n/** Numeric three-part comparison; negative when `a` is older than `b`. */\nexport function compareVersions(a: string, b: string): number {\n const [pa, pb] = [a, b].map((v) => v.split('.').map(Number));\n for (let i = 0; i < 3; i++) if (pa[i] !== pb[i]) return pa[i] < pb[i] ? -1 : 1;\n return 0;\n}\n\n/**\n * The CLI authors for exactly one engine: the one inside the runner image it was\n * released with. It never changes a job's image on its own: a job behind it is moved\n * up only by upgrade-runtime, a CLI behind a job is updated, and nothing moves down.\n */\nexport function compareRuntime(jobImage: string): RuntimeComparison {\n const bundled = split(PIPELINE_RUNNER_IMAGE);\n const expected = bundled.tag ?? '';\n const job = split(jobImage);\n if (job.repository !== bundled.repository)\n return {\n status: 'incompatible',\n jobVersion: null,\n expected,\n nextAction:\n 'Use the existing app tools to inspect, run or maintain this app in its current implementation. Do not change its runner or entrypoint to satisfy pipeline setup. Migration to Simple Pipelines requires an explicit migration request.',\n };\n if (!job.tag || !RELEASE_VERSION.test(job.tag))\n return {\n status: 'unversioned',\n jobVersion: null,\n expected,\n nextAction: `The job's image \"${jobImage}\" is a moving tag or digest, not a released ${bundled.repository} version, so this CLI leaves the image as it is. Each run reports the engine it started on: read engine in inspect.`,\n };\n const order = compareVersions(job.tag, expected);\n if (order === 0) return { status: 'match', jobVersion: job.tag, expected, nextAction: '' };\n if (order < 0)\n return {\n status: 'behind',\n jobVersion: job.tag,\n expected,\n nextAction: `The job runs ${bundled.repository}:${job.tag}; this CLI authors for ${expected}. Run, pull and reads work on the job's image, but push is refused until the job is upgraded: ask the user, then run upgrade-runtime, which moves the job to ${PIPELINE_RUNNER_IMAGE} for everyone on the tenant and for its next scheduled run.${inAgentSandbox() ? '' : ' Or keep the job on its image and author with the CLI release that targets it.'}`,\n };\n return {\n status: 'ahead',\n jobVersion: job.tag,\n expected,\n nextAction: `The job runs ${bundled.repository}:${job.tag}; this CLI authors for ${expected}. Run and push work on the job's image, but this CLI does not describe what the newer engine added. ${CLI_UPDATE_INSTRUCTION}`,\n };\n}\n\n/** Version pinning may upgrade Simple Pipelines, but must never convert another kind of app. */\nexport function assertPipelineRuntime(jobImage: string): RuntimeComparison {\n const runtime = compareRuntime(jobImage);\n if (runtime.status === 'incompatible')\n throw new PipelineError(\n 'refused',\n 'PIPELINE_RUNTIME_UNSUPPORTED',\n `Runner image \"${jobImage || '(tenant default or unknown)'}\" is not a Simple Pipelines runner. The existing app must be preserved.`,\n runtime.nextAction,\n );\n return runtime;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAAsB;AACtB,uBAAuC;AACvC,oBAA8B;AAC9B,0BAA+B;AAGxB,MAAM,wBAAgC,2BAAAA,QAAU;AAWvD,MAAM,kBAAkB;AAExB,SAAS,MAAM,OAA2D;AACtE,QAAM,OAAO,MAAM,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC;AACnD,MAAI,KAAK,SAAS,GAAG,EAAG,QAAO,EAAE,YAAY,KAAK,MAAM,GAAG,KAAK,QAAQ,GAAG,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC,GAAG,KAAK,KAAK;AACvG,QAAM,QAAQ,KAAK,QAAQ,GAAG;AAC9B,SAAO,QAAQ,IACT,EAAE,YAAY,MAAM,KAAK,KAAK,IAC9B,EAAE,YAAY,KAAK,MAAM,GAAG,KAAK,GAAG,KAAK,KAAK,MAAM,QAAQ,CAAC,EAAE;AACzE;AAGO,SAAS,gBAAgB,GAAW,GAAmB;AAC1D,QAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM,CAAC;AAC3D,WAAS,IAAI,GAAG,IAAI,GAAG,IAAK,KAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAG,QAAO,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK;AAC7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= require("../services/apps");
56
56
  var import_requests = require("./requests");
57
57
  var import_readiness = require("./readiness");
58
58
  var import_errors = require("./errors");
59
+ var import_agentSandbox = require("../utils/agentSandbox");
59
60
  const relative = import_zod.z.string().min(1).refine(
60
61
  (s) => !s.includes("\\") && !s.startsWith("/") && s.split("/").every((p) => p && p !== "." && p !== ".." && !p.startsWith(".")),
61
62
  "Expected a non-hidden relative path"
@@ -222,9 +223,15 @@ class PipelineService {
222
223
  this.filesDir = filesDir;
223
224
  this.client = (0, import_requests.boundedPipelineClient)(client);
224
225
  this.profile = profileSchema.parse(profile);
225
- if (this.profile.engine !== import_reference.PIPELINE_ENGINE_PROFILE)
226
+ const grammar = /^(\d+)\.(\d+)(?:\.\d+)?$/.exec(this.profile.engine)?.slice(1).map(Number);
227
+ const [major, minor] = import_reference.PIPELINE_ENGINE_PROFILE.split(".").map(Number);
228
+ if (grammar && (grammar[0] > major || grammar[0] === major && grammar[1] > minor))
226
229
  throw new Error(
227
- `This CLI's bundled grammar supports ${import_reference.PIPELINE_ENGINE_PROFILE}; the profile requires ${this.profile.engine}. ${import_reference.CLI_UPDATE_INSTRUCTION} Keep the prepared runtime and profile consistent.`
230
+ `This CLI's bundled grammar is ${import_reference.PIPELINE_ENGINE_PROFILE}; the profile was set up for ${this.profile.engine}. ${import_reference.CLI_UPDATE_INSTRUCTION}`
231
+ );
232
+ if (!grammar || grammar[0] < major)
233
+ throw new Error(
234
+ `The profile was set up for grammar ${this.profile.engine}, which this CLI (${import_reference.PIPELINE_ENGINE_PROFILE}) does not continue. Set the profile up again with init jobId=${this.profile.jobId} force=true${(0, import_agentSandbox.inAgentSandbox)() ? "" : `, or keep using the CLI release that targets ${this.profile.engine}`}.`
228
235
  );
229
236
  if (!profile.entrypoint.endsWith(".py"))
230
237
  throw new import_errors.PipelineError(
@@ -273,7 +280,7 @@ class PipelineService {
273
280
  const runtime = (0, import_runtime.compareRuntime)(job?.runnerImage ?? "");
274
281
  checks.push({
275
282
  name: "runner-image",
276
- status: runtime.status === "match" ? "pass" : runtime.status === "ahead" || runtime.status === "incompatible" ? "fail" : "pending",
283
+ status: runtime.status === "match" ? "pass" : runtime.status === "behind" || runtime.status === "incompatible" ? "fail" : "pending",
277
284
  detail: runtime.status === "match" ? `Job runs ${import_runtime.PIPELINE_RUNNER_IMAGE}, the image this CLI authors for` : runtime.nextAction
278
285
  });
279
286
  } catch (error) {
@@ -359,8 +366,15 @@ class PipelineService {
359
366
  throw new Error(
360
367
  "This version exceeds the 256 MiB query download limit; prepare a smaller pipeline output"
361
368
  );
362
- await (0, import_readiness.probeParquetAccess)(manifest.files[0].signedUrl);
363
- return `Version ${dataset.currentVersionId}: ${manifest.files.length} Parquet file(s), ${bytes} bytes. Signed GET verified on the first file; full-query performance is not established by this probe.`;
369
+ const versionId = dataset.currentVersionId;
370
+ const first = manifest.files[0];
371
+ if (this.client.agentSession)
372
+ await (0, import_readiness.probeParquetPrefix)(
373
+ (probeSignal) => this.client.downloadDatasetVersionFile(datasetId, versionId, first.filename, probeSignal)
374
+ );
375
+ else await (0, import_readiness.probeParquetAccess)(first.signedUrl);
376
+ const access = this.client.agentSession ? "Read through the API" : "Signed GET";
377
+ return `Version ${versionId}: ${manifest.files.length} Parquet file(s), ${bytes} bytes. ${access} verified on the first file; full-query performance is not established by this probe.`;
364
378
  });
365
379
  }
366
380
  const automatedReady = checks.every((c) => c.status === "pass");
@@ -411,7 +425,16 @@ class PipelineService {
411
425
  sql,
412
426
  limits: import_query.DEFAULT_LIMITS
413
427
  },
414
- signal
428
+ signal,
429
+ this.client.agentSession ? (binding, file, downloadSignal) => {
430
+ const input = inputs[binding];
431
+ return this.client.downloadDatasetVersionFile(
432
+ input.datasetId,
433
+ input.versionId,
434
+ input.files[file].filename,
435
+ downloadSignal
436
+ );
437
+ } : void 0
415
438
  );
416
439
  return {
417
440
  ...result,
@@ -599,40 +622,6 @@ class PipelineService {
599
622
  }
600
623
  return job;
601
624
  }
602
- /**
603
- * A job never runs an older image than the one this CLI authors for: a job that is
604
- * behind, or on a moving tag or digest, is moved to the tandem image here, and the
605
- * run that follows shows what the newer engine rejects. A job that is ahead refuses,
606
- * because the fix is a newer CLI.
607
- */
608
- async ensureRuntime(job) {
609
- const runtime = (0, import_runtime.assertPipelineRuntime)(job.runnerImage ?? "");
610
- if (runtime.status === "match") return void 0;
611
- if (runtime.status === "ahead")
612
- throw new import_errors.PipelineError(
613
- "refused",
614
- "CLI_UPDATE_REQUIRED",
615
- `The job runs ${job.runnerImage}; this CLI authors for ${import_runtime.PIPELINE_RUNNER_IMAGE}.`,
616
- import_reference.CLI_UPDATE_INSTRUCTION
617
- );
618
- const image = (0, import_apps.resolveRunnerImage)(import_runtime.PIPELINE_RUNNER_IMAGE, await this.client.getRunnerImageRepositories());
619
- if ("error" in image) throw new Error(image.error);
620
- await this.client.updateApp(String(job.id), { runnerImage: image.image }, job);
621
- return { from: job.runnerImage ?? "", to: image.image };
622
- }
623
- /**
624
- * A refused submission started no run, so the job goes back to the image it had: the new
625
- * engine stays paired only with source that has run on it. Returns what to add to the refusal.
626
- */
627
- async moveBack(job, moved) {
628
- if (!moved) return "";
629
- try {
630
- await this.client.updateApp(String(job.id), { runnerImage: moved.from }, job);
631
- return "";
632
- } catch (error) {
633
- return ` The job could not be moved back to ${moved.from} and is left on ${moved.to}: ${redact(String(error))}`;
634
- }
635
- }
636
625
  /** Workspace source files in the pull/push scope, as tenant-relative paths. */
637
626
  localSources() {
638
627
  return localSourceFiles(this.profile, this.filesDir);
@@ -672,6 +661,14 @@ class PipelineService {
672
661
  return this.exclusive(async () => {
673
662
  await this.idle();
674
663
  const job = await this.verifyJob();
664
+ const runtime = (0, import_runtime.compareRuntime)(job.runnerImage ?? "");
665
+ if (direction === "push" && runtime.status === "behind")
666
+ throw new import_errors.PipelineError(
667
+ "refused",
668
+ "RUNTIME_UPGRADE_REQUIRED",
669
+ `The job runs ${job.runnerImage}, older than ${import_runtime.PIPELINE_RUNNER_IMAGE} this CLI authors for. Nothing was pushed.`,
670
+ runtime.nextAction
671
+ );
675
672
  const { onlyFiles } = await this.sources();
676
673
  let result;
677
674
  try {
@@ -687,6 +684,61 @@ class PipelineService {
687
684
  return direction === "push" && job.schedule ? { ...result, schedule: { cron: job.schedule, note: SCHEDULE_NOTE } } : result;
688
685
  });
689
686
  }
687
+ /**
688
+ * Move the job to the image this CLI authors for. Only a job behind it moves: a job on a
689
+ * moving tag or digest may already run a newer engine, and a job ahead needs a newer CLI.
690
+ */
691
+ async upgradeRuntime() {
692
+ return this.exclusive(async () => {
693
+ await this.idle();
694
+ const job = await this.verifyJob();
695
+ const from = job.runnerImage ?? "";
696
+ const runtime = (0, import_runtime.compareRuntime)(from);
697
+ if (runtime.status === "match") return { jobId: job.id, from, to: from, changed: false };
698
+ if (runtime.status === "ahead")
699
+ throw new import_errors.PipelineError(
700
+ "refused",
701
+ "CLI_UPDATE_REQUIRED",
702
+ `The job runs ${from}, newer than ${import_runtime.PIPELINE_RUNNER_IMAGE} this CLI authors for.`,
703
+ import_reference.CLI_UPDATE_INSTRUCTION
704
+ );
705
+ if (runtime.status !== "behind")
706
+ throw new import_errors.PipelineError(
707
+ "refused",
708
+ "RUNTIME_UNVERSIONED",
709
+ `The job runs ${from}, a moving tag or digest, so this CLI cannot tell whether ${import_runtime.PIPELINE_RUNNER_IMAGE} is older or newer.`,
710
+ "Leave the job on its image, or pin an exact image deliberately in the web app."
711
+ );
712
+ const image = (0, import_apps.resolveRunnerImage)(import_runtime.PIPELINE_RUNNER_IMAGE, await this.client.getRunnerImageRepositories());
713
+ if ("error" in image) throw new Error(image.error);
714
+ try {
715
+ await this.client.updateApp(String(job.id), { runnerImage: image.image }, job);
716
+ } catch (error) {
717
+ const status = (0, import_errors.httpStatus)(error) ?? 0;
718
+ if (status >= 400 && status < 500)
719
+ throw new import_errors.PipelineError(
720
+ "refused",
721
+ "RUNTIME_UPGRADE_REFUSED",
722
+ `The backend refused the image change; the job stays on ${from}. ${redact(String(error))}`,
723
+ "Read the reason, fix the setup it names or ask the setup owner, then try again."
724
+ );
725
+ throw new import_errors.PipelineError(
726
+ "unknown",
727
+ "RUNTIME_UPGRADE_UNCONFIRMED",
728
+ `The image change may have been saved: the job is on ${from} or ${image.image}. ${redact(String(error))}`,
729
+ "Run check to read the job's image before anything else. Do not retry blindly."
730
+ );
731
+ }
732
+ const moved = { jobId: job.id, from, to: image.image, changed: true };
733
+ return job.schedule ? {
734
+ ...moved,
735
+ schedule: {
736
+ cron: job.schedule,
737
+ note: "The next scheduled run uses the new engine with the source already on the tenant. Run it once now to see what the new engine refuses."
738
+ }
739
+ } : moved;
740
+ });
741
+ }
690
742
  async submit(args = []) {
691
743
  import_zod.z.array(import_zod.z.string()).parse(args);
692
744
  return this.exclusive(async () => {
@@ -718,7 +770,6 @@ class PipelineService {
718
770
  `Unsynced source files: ${differences.join(", ")}`,
719
771
  "Pull and reconcile the listed source files, then push the intended changes before running."
720
772
  );
721
- const runtimeMoved = await this.ensureRuntime(job);
722
773
  const { organisation, tenant, jobId, workspace, author } = this.profile;
723
774
  const receipt = {
724
775
  organisation,
@@ -745,7 +796,7 @@ class PipelineService {
745
796
  throw new import_errors.PipelineError(
746
797
  "refused",
747
798
  "REQUEST_REFUSED",
748
- `Submission refused by the backend (HTTP ${status}). No new run was accepted. ${redact(String(reason))}${await this.moveBack(job, runtimeMoved)}`,
799
+ `Submission refused by the backend (HTTP ${status}). No new run was accepted. ${redact(String(reason))}`,
749
800
  "Read the reason, fix the setup it names or ask the setup owner, then run again."
750
801
  );
751
802
  }
@@ -779,7 +830,6 @@ class PipelineService {
779
830
  ...result,
780
831
  phase: "accepted",
781
832
  observation: "pending",
782
- runtimeMoved,
783
833
  arguments: runArguments.given
784
834
  };
785
835
  });
@@ -842,19 +892,29 @@ class PipelineService {
842
892
  const file = await this.client.getFileByPath(`${this.profile.workspace}/${binding.file}`);
843
893
  if (!file || file.path !== `${this.profile.workspace}/${binding.file}`)
844
894
  throw new Error("Workspace output not found");
845
- const access = await this.client.pipelineRequest(
846
- "GET",
847
- `/farseerFiles/${encodeURIComponent(file.reference)}/downloadUrl`
848
- );
849
- if (!access?.url?.startsWith("https://")) throw new Error("Signed object read access unavailable");
895
+ let url = `farseer-file:${file.reference}`;
896
+ if (!this.client.agentSession) {
897
+ const access = await this.client.pipelineRequest(
898
+ "GET",
899
+ `/farseerFiles/${encodeURIComponent(file.reference)}/downloadUrl`
900
+ );
901
+ if (!access?.url?.startsWith("https://")) throw new Error("Signed object read access unavailable");
902
+ url = access.url;
903
+ }
850
904
  inputs.push({
851
905
  ...file,
852
906
  metadata: await this.client.getFileMetadata(file.reference) ?? void 0,
853
907
  name: binding.name,
854
- url: access.url
908
+ url
855
909
  });
856
910
  }
857
- const result = await (0, import_query.queryFiles)({ bindings: inputs, sql, limits: import_query.DEFAULT_LIMITS }, signal);
911
+ const total = inputs.reduce((sum, input) => sum + (input.metadata?.size ?? 0), 0);
912
+ if (total > import_query.DEFAULT_LIMITS.inputBytes) throw new Error("Input download byte limit exceeded");
913
+ const result = await (0, import_query.queryFiles)(
914
+ { bindings: inputs, sql, limits: import_query.DEFAULT_LIMITS },
915
+ signal,
916
+ this.client.agentSession ? (binding, _file, downloadSignal) => this.client.downloadFarseerFile(inputs[binding].reference, downloadSignal) : void 0
917
+ );
858
918
  return {
859
919
  ...result,
860
920
  tenant: this.profile.tenant,