farseer-cli 1.13.0 → 1.14.2
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/README.md +23 -8
- package/dist/commands/config.js +4 -3
- package/dist/commands/config.js.map +2 -2
- package/dist/commands/install.js +5 -0
- package/dist/commands/install.js.map +2 -2
- package/dist/commands/login.js +2 -2
- package/dist/commands/login.js.map +2 -2
- package/dist/commands/pipeline.js +158 -0
- package/dist/commands/pipeline.js.map +7 -0
- package/dist/commands/pull.js +2 -1
- package/dist/commands/pull.js.map +2 -2
- package/dist/commands/run.js +9 -0
- package/dist/commands/run.js.map +2 -2
- package/dist/commands/variables.js +17 -8
- package/dist/commands/variables.js.map +2 -2
- package/dist/index.js +45 -46
- package/dist/index.js.map +2 -2
- package/dist/mcp/prompts/workflows.js +13 -68
- package/dist/mcp/prompts/workflows.js.map +2 -2
- package/dist/mcp/resources/documentation.js +14 -0
- package/dist/mcp/resources/documentation.js.map +2 -2
- package/dist/mcp/server.js +14 -2
- package/dist/mcp/server.js.map +2 -2
- package/dist/mcp/skills.js +59 -0
- package/dist/mcp/skills.js.map +7 -0
- package/dist/mcp/tools/appTools.js +4 -0
- package/dist/mcp/tools/appTools.js.map +2 -2
- package/dist/mcp/tools/authTools.js +5 -3
- package/dist/mcp/tools/authTools.js.map +2 -2
- package/dist/mcp/tools/cellTools.js +3 -2
- package/dist/mcp/tools/cellTools.js.map +2 -2
- package/dist/mcp/tools/dashboardTools.js +23 -18
- package/dist/mcp/tools/dashboardTools.js.map +2 -2
- package/dist/mcp/tools/dataTools.js +16 -12
- package/dist/mcp/tools/dataTools.js.map +2 -2
- package/dist/mcp/tools/folderTools.js +5 -4
- package/dist/mcp/tools/folderTools.js.map +2 -2
- package/dist/mcp/tools/modelTools.js +33 -58
- package/dist/mcp/tools/modelTools.js.map +2 -2
- package/dist/mcp/tools/pipelineContract.js +320 -0
- package/dist/mcp/tools/pipelineContract.js.map +7 -0
- package/dist/mcp/tools/pipelineTools.js +111 -0
- package/dist/mcp/tools/pipelineTools.js.map +7 -0
- package/dist/mcp/tools/runTools.js +10 -3
- package/dist/mcp/tools/runTools.js.map +2 -2
- package/dist/mcp/tools/sheetTools.js +21 -17
- package/dist/mcp/tools/sheetTools.js.map +2 -2
- package/dist/mcp/tools/syncTools.js +15 -5
- package/dist/mcp/tools/syncTools.js.map +2 -2
- package/dist/mcp/utils/registerTool.js +32 -0
- package/dist/mcp/utils/registerTool.js.map +7 -0
- package/dist/pipeline/compatibility.js +53 -0
- package/dist/pipeline/compatibility.js.map +7 -0
- package/dist/pipeline/connect.js +139 -0
- package/dist/pipeline/connect.js.map +7 -0
- package/dist/pipeline/create.js +158 -0
- package/dist/pipeline/create.js.map +7 -0
- package/dist/pipeline/errors.js +45 -0
- package/dist/pipeline/errors.js.map +7 -0
- package/dist/pipeline/generated-reference.json +115 -0
- package/dist/pipeline/guide.js +33 -0
- package/dist/pipeline/guide.js.map +7 -0
- package/dist/pipeline/init.js +204 -0
- package/dist/pipeline/init.js.map +7 -0
- package/dist/pipeline/operations.js +106 -0
- package/dist/pipeline/operations.js.map +7 -0
- package/dist/pipeline/query.js +121 -0
- package/dist/pipeline/query.js.map +7 -0
- package/dist/pipeline/queryDownloads.js +72 -0
- package/dist/pipeline/queryDownloads.js.map +7 -0
- package/dist/pipeline/queryWorker.js +96 -0
- package/dist/pipeline/queryWorker.js.map +7 -0
- package/dist/pipeline/readiness.js +62 -0
- package/dist/pipeline/readiness.js.map +7 -0
- package/dist/pipeline/reference.js +73 -0
- package/dist/pipeline/reference.js.map +7 -0
- package/dist/pipeline/requests.js +122 -0
- package/dist/pipeline/requests.js.map +7 -0
- package/dist/pipeline/runArguments.js +68 -0
- package/dist/pipeline/runArguments.js.map +7 -0
- package/dist/pipeline/runtime.js +106 -0
- package/dist/pipeline/runtime.js.map +7 -0
- package/dist/pipeline/service.js +1027 -0
- package/dist/pipeline/service.js.map +7 -0
- package/dist/services/agentApprovalFetch.js +86 -0
- package/dist/services/agentApprovalFetch.js.map +7 -0
- package/dist/services/appSyncService.js.map +1 -1
- package/dist/services/configService.js +40 -4
- package/dist/services/configService.js.map +2 -2
- package/dist/services/credentials.js +2 -0
- package/dist/services/credentials.js.map +2 -2
- package/dist/services/farseerService.js +33 -3
- package/dist/services/farseerService.js.map +2 -2
- package/dist/services/modelExport.js.map +1 -1
- package/dist/services/preflight.js +4 -0
- package/dist/services/preflight.js.map +2 -2
- package/dist/services/syncService.js +6 -0
- package/dist/services/syncService.js.map +2 -2
- package/dist/skills/pipeline.js +71 -0
- package/dist/skills/pipeline.js.map +7 -0
- package/dist/utils/agentSandbox.js +35 -0
- package/dist/utils/agentSandbox.js.map +7 -0
- package/dist/utils/helpers.js +2 -1
- package/dist/utils/helpers.js.map +2 -2
- package/dist/utils/variableValues.js +78 -0
- package/dist/utils/variableValues.js.map +7 -0
- package/docs/pipeline-client-guide.md +67 -0
- package/docs/pipeline-reference.md +2064 -0
- package/package.json +5 -1
- package/skills/pipeline-authoring/SKILL.md +95 -0
- package/skills/pipeline-authoring/practices.md +325 -0
|
@@ -0,0 +1,204 @@
|
|
|
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 init_exports = {};
|
|
30
|
+
__export(init_exports, {
|
|
31
|
+
initPipelineProfile: () => initPipelineProfile
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(init_exports);
|
|
34
|
+
var fs = __toESM(require("fs"));
|
|
35
|
+
var path = __toESM(require("path"));
|
|
36
|
+
var import_crypto = require("crypto");
|
|
37
|
+
var import_connect = require("./connect");
|
|
38
|
+
var import_reference = require("./reference");
|
|
39
|
+
var import_runtime = require("./runtime");
|
|
40
|
+
var import_service = require("./service");
|
|
41
|
+
const { load: loadYaml } = require("js-yaml");
|
|
42
|
+
const CONVENTIONAL_ENTRYPOINT = "main.py";
|
|
43
|
+
const DATASET_NAME = /^[A-Za-z0-9_-]+$/;
|
|
44
|
+
async function initPipelineProfile(options, client, paths) {
|
|
45
|
+
const warnings = [];
|
|
46
|
+
const job = await readJob(client, options.jobId);
|
|
47
|
+
const workspace = options.workspace ?? await locateWorkspace(client, job);
|
|
48
|
+
const folder = await resolveFolder(client, job, workspace);
|
|
49
|
+
const file = targetFile(paths.profileDir, workspace, options.force ?? false);
|
|
50
|
+
const identity = {
|
|
51
|
+
organisation: options.organisation,
|
|
52
|
+
tenant: options.tenant,
|
|
53
|
+
jobId: job.id,
|
|
54
|
+
sourceFolderId: job.sourceFolderId,
|
|
55
|
+
workspace
|
|
56
|
+
};
|
|
57
|
+
const kept = writtenByPeople(file, identity, warnings);
|
|
58
|
+
const draft = import_service.profileSchema.parse({
|
|
59
|
+
...identity,
|
|
60
|
+
author: kept?.author,
|
|
61
|
+
configFiles: kept?.configFiles,
|
|
62
|
+
entrypoint: entrypointFor(job, folder, warnings),
|
|
63
|
+
engine: import_reference.PIPELINE_ENGINE_PROFILE,
|
|
64
|
+
schedule: job.schedule ?? null
|
|
65
|
+
});
|
|
66
|
+
const runtime = (0, import_runtime.compareRuntime)(job.runnerImage);
|
|
67
|
+
if (runtime.status !== "match") warnings.push(runtime.nextAction);
|
|
68
|
+
if (job.schedule)
|
|
69
|
+
warnings.push(`Job runs on schedule "${job.schedule}" (recorded in the profile). ${import_service.SCHEDULE_NOTE}`);
|
|
70
|
+
const service = new import_service.PipelineService(draft, client, paths.filesDir, paths.stateRoot);
|
|
71
|
+
const { definitions, skipped } = await scanDefinitions(service, paths.filesDir, warnings);
|
|
72
|
+
const resolved = await resolveDatasets(client, definitions);
|
|
73
|
+
const profile = import_service.profileSchema.parse({
|
|
74
|
+
...draft,
|
|
75
|
+
datasetIds: [...new Set(resolved.datasets.map((d) => d.id))],
|
|
76
|
+
setup: kept?.setup ?? import_service.BLANK_SETUP
|
|
77
|
+
});
|
|
78
|
+
writeProfile(file, profile);
|
|
79
|
+
return {
|
|
80
|
+
file,
|
|
81
|
+
profile,
|
|
82
|
+
...resolved,
|
|
83
|
+
skippedDefinitions: skipped,
|
|
84
|
+
warnings,
|
|
85
|
+
nextSteps: [
|
|
86
|
+
"Fill the setup record: owner, checkedAt (ISO datetime), evidence, retentionDays, otherWritersExcluded=true and runtimeVerified=true. These are owner statements; check reports the record as pending until all are filled.",
|
|
87
|
+
...resolved.pendingDatasets.length ? [
|
|
88
|
+
`Pending datasets (${resolved.pendingDatasets.map((d) => d.name).join(", ")}) are created on the first run; rerun init jobId=${job.id} force=true after it to record their IDs.`
|
|
89
|
+
] : [],
|
|
90
|
+
"Run check to see what is verified and what is still pending."
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async function readJob(client, jobId) {
|
|
95
|
+
const job = await client.getApp(String(jobId));
|
|
96
|
+
if (!job) throw new Error(`Job ${jobId} was not found on this tenant`);
|
|
97
|
+
const runnerImage = job.runnerImage ?? "";
|
|
98
|
+
(0, import_runtime.assertPipelineRuntime)(runnerImage);
|
|
99
|
+
if (!job.sourceFolderId) throw new Error(`Job ${jobId} has no source folder; set one in the web app first`);
|
|
100
|
+
return { ...job, sourceFolderId: job.sourceFolderId, runnerImage };
|
|
101
|
+
}
|
|
102
|
+
async function locateWorkspace(client, job) {
|
|
103
|
+
const advice = "give the workspace folder (workspace=<dir>, the tenant-relative source folder path)";
|
|
104
|
+
if (!job.mainScriptFileId) throw new Error(`Job ${job.id} has no main script; ${advice}`);
|
|
105
|
+
const script = (await client.listFiles(["Files"])).find((f) => f.reference === job.mainScriptFileId);
|
|
106
|
+
if (!script) throw new Error(`Main script of job ${job.id} was not found under Files; ${advice}`);
|
|
107
|
+
const workspace = path.posix.dirname(script.path);
|
|
108
|
+
if (workspace === ".") throw new Error(`Main script of job ${job.id} sits at the Files root; ${advice}`);
|
|
109
|
+
return workspace;
|
|
110
|
+
}
|
|
111
|
+
async function resolveFolder(client, job, workspace) {
|
|
112
|
+
const folder = await client.resolveSourceFolder(workspace);
|
|
113
|
+
if (!folder) throw new Error(`Workspace folder "${workspace}" does not exist under Files`);
|
|
114
|
+
if (folder.id !== job.sourceFolderId)
|
|
115
|
+
throw new Error(
|
|
116
|
+
`Workspace folder "${workspace}" (id ${folder.id}) is not the source folder of job ${job.id} (id ${job.sourceFolderId})`
|
|
117
|
+
);
|
|
118
|
+
return folder;
|
|
119
|
+
}
|
|
120
|
+
function entrypointFor(job, folder, warnings) {
|
|
121
|
+
const script = folder.scripts.find((s) => s.id === job.mainScriptFileId);
|
|
122
|
+
if (script) return script.name;
|
|
123
|
+
warnings.push(
|
|
124
|
+
`Job ${job.id} names no main script inside its source folder; wrote the conventional entrypoint ${CONVENTIONAL_ENTRYPOINT}. Until the job's main script is set to it, check reports prepared-job as failed and run refuses.`
|
|
125
|
+
);
|
|
126
|
+
return CONVENTIONAL_ENTRYPOINT;
|
|
127
|
+
}
|
|
128
|
+
function writtenByPeople(file, identity, warnings) {
|
|
129
|
+
if (!fs.existsSync(file)) return void 0;
|
|
130
|
+
let existing;
|
|
131
|
+
try {
|
|
132
|
+
existing = (0, import_service.readPipelineProfileFile)(file);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
warnings.push(
|
|
135
|
+
`The existing profile could not be read, so its setup record, config files and author were not kept: ${(0, import_service.redact)(error instanceof Error ? error.message : String(error))}`
|
|
136
|
+
);
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
139
|
+
const same = Object.keys(identity).every((key) => existing[key] === identity[key]);
|
|
140
|
+
return same ? { author: existing.author, configFiles: existing.configFiles, setup: existing.setup } : void 0;
|
|
141
|
+
}
|
|
142
|
+
function targetFile(profileDir, workspace, force) {
|
|
143
|
+
const file = (0, import_connect.profileFile)(profileDir, path.posix.basename(workspace));
|
|
144
|
+
if (fs.existsSync(file) && !force)
|
|
145
|
+
throw new Error(`Profile ${file} already exists for workspace ${workspace}; set force=true to overwrite it`);
|
|
146
|
+
return file;
|
|
147
|
+
}
|
|
148
|
+
async function scanDefinitions(service, filesDir, warnings) {
|
|
149
|
+
if (!service.localSources().length) {
|
|
150
|
+
try {
|
|
151
|
+
await service.syncSources("pull");
|
|
152
|
+
} catch (error) {
|
|
153
|
+
warnings.push(
|
|
154
|
+
`No local source and the pull failed, so no datasets were derived: ${(0, import_service.redact)(String(error))}. Fix the job, pull, then rerun init jobId=${service.profile.jobId} force=true.`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const prefix = `${service.profile.workspace}/Models/`;
|
|
159
|
+
const definitions = [];
|
|
160
|
+
const skipped = [];
|
|
161
|
+
for (const file of service.localSources().filter((f) => f.startsWith(prefix) && /\.ya?ml$/.test(f)).sort()) {
|
|
162
|
+
const parsed = readDefinition(path.join(filesDir, file), file.slice(prefix.length));
|
|
163
|
+
if ("reason" in parsed) skipped.push({ file, reason: parsed.reason });
|
|
164
|
+
else definitions.push({ file, qualifiedName: parsed.qualifiedName });
|
|
165
|
+
}
|
|
166
|
+
return { definitions, skipped };
|
|
167
|
+
}
|
|
168
|
+
function readDefinition(absolute, relativeToModels) {
|
|
169
|
+
let data;
|
|
170
|
+
try {
|
|
171
|
+
data = loadYaml(fs.readFileSync(absolute, "utf8"));
|
|
172
|
+
} catch {
|
|
173
|
+
return { reason: "invalid YAML syntax" };
|
|
174
|
+
}
|
|
175
|
+
const name = data?.name;
|
|
176
|
+
if (typeof name !== "string") return { reason: "no string name field" };
|
|
177
|
+
if (!DATASET_NAME.test(name)) return { reason: `name "${name}" is templated or not a plain dataset name` };
|
|
178
|
+
const namespace = path.posix.dirname(relativeToModels).split("/").filter((p) => p !== ".");
|
|
179
|
+
return { qualifiedName: [...namespace, name].join(".") };
|
|
180
|
+
}
|
|
181
|
+
async function resolveDatasets(client, definitions) {
|
|
182
|
+
if (definitions.length === 0) return { datasets: [], pendingDatasets: [] };
|
|
183
|
+
const remote = await client.pipelineRequest("GET", "/labs/datasets");
|
|
184
|
+
const byName = new Map(remote.map((d) => [d.name, d.id]));
|
|
185
|
+
const datasets = [];
|
|
186
|
+
const pendingDatasets = [];
|
|
187
|
+
for (const { file, qualifiedName: name } of definitions) {
|
|
188
|
+
const id = byName.get(name);
|
|
189
|
+
if (id) datasets.push({ name, id, file });
|
|
190
|
+
else pendingDatasets.push({ name, file });
|
|
191
|
+
}
|
|
192
|
+
return { datasets, pendingDatasets };
|
|
193
|
+
}
|
|
194
|
+
function writeProfile(file, profile) {
|
|
195
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
196
|
+
const tmp = `${file}.${(0, import_crypto.randomUUID)()}`;
|
|
197
|
+
fs.writeFileSync(tmp, JSON.stringify(profile, null, 2) + "\n", { mode: 384 });
|
|
198
|
+
fs.renameSync(tmp, file);
|
|
199
|
+
}
|
|
200
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
201
|
+
0 && (module.exports = {
|
|
202
|
+
initPipelineProfile
|
|
203
|
+
});
|
|
204
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/pipeline/init.ts"],
|
|
4
|
+
"sourcesContent": ["import * as fs from 'fs';\nimport * as path from 'path';\nimport { randomUUID } from 'crypto';\nimport type { RemoteApp, SourceFolderResolution } from '../services/apps';\nimport { profileFile, type PipelinePaths } from './connect';\nimport { PIPELINE_ENGINE_PROFILE } from './reference';\nimport { assertPipelineRuntime, compareRuntime } from './runtime';\nimport {\n BLANK_SETUP,\n PipelineClient,\n PipelineProfile,\n PipelineService,\n profileSchema,\n readPipelineProfileFile,\n redact,\n SCHEDULE_NOTE,\n} from './service';\n\nconst { load: loadYaml }: { load: (source: string) => unknown } = require('js-yaml');\n\n/** What the skill's starter layout uses and what check expects when the job names no script. */\nconst CONVENTIONAL_ENTRYPOINT = 'main.py';\n// Mirrors the engine's charset for a rendered dataset name; anything else is templated or invalid.\nconst DATASET_NAME = /^[A-Za-z0-9_-]+$/;\n\nexport interface InitOptions {\n organisation: string;\n tenant: string;\n jobId: number;\n workspace?: string;\n force?: boolean;\n}\ninterface Definition {\n file: string;\n qualifiedName: string;\n}\ninterface SkippedDefinition {\n file: string;\n reason: string;\n}\nexport interface InitResult {\n file: string;\n profile: PipelineProfile;\n datasets: { name: string; id: string; file: string }[];\n /** Declared under Models/ but not created yet; the engine creates a dataset on its first write. */\n pendingDatasets: { name: string; file: string }[];\n skippedDefinitions: SkippedDefinition[];\n warnings: string[];\n nextSteps: string[];\n}\ntype Job = RemoteApp & { sourceFolderId: number; runnerImage: string };\n\n/** Derive a profile from the prepared job and write it. Reads only; never changes remote state. */\nexport async function initPipelineProfile(\n options: InitOptions,\n client: PipelineClient,\n paths: PipelinePaths,\n): Promise<InitResult> {\n const warnings: string[] = [];\n const job = await readJob(client, options.jobId);\n const workspace = options.workspace ?? (await locateWorkspace(client, job));\n const folder = await resolveFolder(client, job, workspace);\n const file = targetFile(paths.profileDir, workspace, options.force ?? false);\n const identity = {\n organisation: options.organisation,\n tenant: options.tenant,\n jobId: job.id,\n sourceFolderId: job.sourceFolderId,\n workspace,\n };\n const kept = writtenByPeople(file, identity, warnings);\n const draft = profileSchema.parse({\n ...identity,\n author: kept?.author,\n configFiles: kept?.configFiles,\n entrypoint: entrypointFor(job, folder, warnings),\n engine: PIPELINE_ENGINE_PROFILE,\n schedule: job.schedule ?? null,\n });\n const runtime = compareRuntime(job.runnerImage);\n if (runtime.status !== 'match') warnings.push(runtime.nextAction);\n if (job.schedule)\n warnings.push(`Job runs on schedule \"${job.schedule}\" (recorded in the profile). ${SCHEDULE_NOTE}`);\n const service = new PipelineService(draft, client, paths.filesDir, paths.stateRoot);\n const { definitions, skipped } = await scanDefinitions(service, paths.filesDir, warnings);\n const resolved = await resolveDatasets(client, definitions);\n const profile = profileSchema.parse({\n ...draft,\n datasetIds: [...new Set(resolved.datasets.map((d) => d.id))],\n setup: kept?.setup ?? BLANK_SETUP,\n });\n writeProfile(file, profile);\n return {\n file,\n profile,\n ...resolved,\n skippedDefinitions: skipped,\n warnings,\n nextSteps: [\n 'Fill the setup record: owner, checkedAt (ISO datetime), evidence, retentionDays, otherWritersExcluded=true and runtimeVerified=true. These are owner statements; check reports the record as pending until all are filled.',\n ...(resolved.pendingDatasets.length\n ? [\n `Pending datasets (${resolved.pendingDatasets.map((d) => d.name).join(', ')}) are created on the first run; rerun init jobId=${job.id} force=true after it to record their IDs.`,\n ]\n : []),\n 'Run check to see what is verified and what is still pending.',\n ],\n };\n}\n\nasync function readJob(client: PipelineClient, jobId: number): Promise<Job> {\n const job = await client.getApp(String(jobId));\n if (!job) throw new Error(`Job ${jobId} was not found on this tenant`);\n const runnerImage = job.runnerImage ?? '';\n assertPipelineRuntime(runnerImage);\n if (!job.sourceFolderId) throw new Error(`Job ${jobId} has no source folder; set one in the web app first`);\n return { ...job, sourceFolderId: job.sourceFolderId, runnerImage };\n}\n\n/** The job stores a folder ID, not a path; the path comes from where its main script lives. */\nasync function locateWorkspace(client: PipelineClient, job: Job): Promise<string> {\n const advice = 'give the workspace folder (workspace=<dir>, the tenant-relative source folder path)';\n if (!job.mainScriptFileId) throw new Error(`Job ${job.id} has no main script; ${advice}`);\n const script = (await client.listFiles(['Files'])).find((f) => f.reference === job.mainScriptFileId);\n if (!script) throw new Error(`Main script of job ${job.id} was not found under Files; ${advice}`);\n const workspace = path.posix.dirname(script.path);\n if (workspace === '.') throw new Error(`Main script of job ${job.id} sits at the Files root; ${advice}`);\n return workspace;\n}\n\nasync function resolveFolder(client: PipelineClient, job: Job, workspace: string): Promise<SourceFolderResolution> {\n const folder = await client.resolveSourceFolder(workspace);\n if (!folder) throw new Error(`Workspace folder \"${workspace}\" does not exist under Files`);\n if (folder.id !== job.sourceFolderId)\n throw new Error(\n `Workspace folder \"${workspace}\" (id ${folder.id}) is not the source folder of job ${job.id} (id ${job.sourceFolderId})`,\n );\n return folder;\n}\n\nfunction entrypointFor(job: Job, folder: SourceFolderResolution, warnings: string[]): string {\n const script = folder.scripts.find((s) => s.id === job.mainScriptFileId);\n if (script) return script.name;\n warnings.push(\n `Job ${job.id} names no main script inside its source folder; wrote the conventional entrypoint ${CONVENTIONAL_ENTRYPOINT}. Until the job's main script is set to it, check reports prepared-job as failed and run refuses.`,\n );\n return CONVENTIONAL_ENTRYPOINT;\n}\n\n/**\n * What people wrote into the existing profile, kept when it belongs to the same job and folder: a\n * rerun with force refreshes only what init reads from the job. A profile for anything else, or one\n * that cannot be read, is replaced by a fresh one.\n */\nfunction writtenByPeople(\n file: string,\n identity: Pick<PipelineProfile, 'organisation' | 'tenant' | 'jobId' | 'sourceFolderId' | 'workspace'>,\n warnings: string[],\n): Pick<PipelineProfile, 'author' | 'configFiles' | 'setup'> | undefined {\n if (!fs.existsSync(file)) return undefined;\n let existing: PipelineProfile;\n try {\n existing = readPipelineProfileFile(file);\n } catch (error) {\n warnings.push(\n `The existing profile could not be read, so its setup record, config files and author were not kept: ${redact(error instanceof Error ? error.message : String(error))}`,\n );\n return undefined;\n }\n const same = (Object.keys(identity) as (keyof typeof identity)[]).every((key) => existing[key] === identity[key]);\n return same ? { author: existing.author, configFiles: existing.configFiles, setup: existing.setup } : undefined;\n}\n\n/** Named after the pipeline folder, so one tenant can hold a profile per pipeline. */\nfunction targetFile(profileDir: string, workspace: string, force: boolean): string {\n const file = profileFile(profileDir, path.posix.basename(workspace));\n if (fs.existsSync(file) && !force)\n throw new Error(`Profile ${file} already exists for workspace ${workspace}; set force=true to overwrite it`);\n return file;\n}\n\n/** Dataset YAML in the local Models/ tree, pulled first when the workspace has no local source. */\nasync function scanDefinitions(\n service: PipelineService,\n filesDir: string,\n warnings: string[],\n): Promise<{ definitions: Definition[]; skipped: SkippedDefinition[] }> {\n if (!service.localSources().length) {\n try {\n await service.syncSources('pull');\n } catch (error) {\n warnings.push(\n `No local source and the pull failed, so no datasets were derived: ${redact(String(error))}. Fix the job, pull, then rerun init jobId=${service.profile.jobId} force=true.`,\n );\n }\n }\n const prefix = `${service.profile.workspace}/Models/`;\n const definitions: Definition[] = [];\n const skipped: SkippedDefinition[] = [];\n for (const file of service\n .localSources()\n .filter((f) => f.startsWith(prefix) && /\\.ya?ml$/.test(f))\n .sort()) {\n const parsed = readDefinition(path.join(filesDir, file), file.slice(prefix.length));\n if ('reason' in parsed) skipped.push({ file, reason: parsed.reason });\n else definitions.push({ file, qualifiedName: parsed.qualifiedName });\n }\n return { definitions, skipped };\n}\n\n/** Same rule as the engine: folders under Models/ form the namespace, the YAML name is the last segment. */\nfunction readDefinition(absolute: string, relativeToModels: string): { qualifiedName: string } | { reason: string } {\n let data: unknown;\n try {\n data = loadYaml(fs.readFileSync(absolute, 'utf8'));\n } catch {\n return { reason: 'invalid YAML syntax' };\n }\n const name = (data as { name?: unknown } | null)?.name;\n if (typeof name !== 'string') return { reason: 'no string name field' };\n if (!DATASET_NAME.test(name)) return { reason: `name \"${name}\" is templated or not a plain dataset name` };\n const namespace = path.posix\n .dirname(relativeToModels)\n .split('/')\n .filter((p) => p !== '.');\n return { qualifiedName: [...namespace, name].join('.') };\n}\n\nasync function resolveDatasets(client: PipelineClient, definitions: Definition[]) {\n // A newly scaffolded pipeline (or a plain script job) has no dataset names\n // to resolve. It must be initializable before dataset storage is configured.\n if (definitions.length === 0) return { datasets: [], pendingDatasets: [] };\n const remote = await client.pipelineRequest<{ id: string; name: string }[]>('GET', '/labs/datasets');\n const byName = new Map(remote.map((d) => [d.name, d.id]));\n const datasets: InitResult['datasets'] = [];\n const pendingDatasets: InitResult['pendingDatasets'] = [];\n for (const { file, qualifiedName: name } of definitions) {\n const id = byName.get(name);\n if (id) datasets.push({ name, id, file });\n else pendingDatasets.push({ name, file });\n }\n return { datasets, pendingDatasets };\n}\n\nfunction writeProfile(file: string, profile: PipelineProfile) {\n fs.mkdirSync(path.dirname(file), { recursive: true });\n const tmp = `${file}.${randomUUID()}`;\n fs.writeFileSync(tmp, JSON.stringify(profile, null, 2) + '\\n', { mode: 0o600 });\n fs.renameSync(tmp, file);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;AACtB,oBAA2B;AAE3B,qBAAgD;AAChD,uBAAwC;AACxC,qBAAsD;AACtD,qBASO;AAEP,MAAM,EAAE,MAAM,SAAS,IAA2C,QAAQ,SAAS;AAGnF,MAAM,0BAA0B;AAEhC,MAAM,eAAe;AA8BrB,eAAsB,oBAClB,SACA,QACA,OAC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AAI,YAAY,WAAW,EAAG,QAAO,EAAE,UAAU,CAAC,GAAG,iBAAiB,CAAC,EAAE;AACzE,QAAM,SAAS,MAAM,OAAO,gBAAgD,OAAO,gBAAgB;AACnG,QAAM,SAAS,IAAI,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;AACxD,QAAM,WAAmC,CAAC;AAC1C,QAAM,kBAAiD,CAAC;AACxD,aAAW,EAAE,MAAM,eAAe,KAAK,KAAK,aAAa;AACrD,UAAM,KAAK,OAAO,IAAI,IAAI;AAC1B,QAAI,GAAI,UAAS,KAAK,EAAE,MAAM,IAAI,KAAK,CAAC;AAAA,QACnC,iBAAgB,KAAK,EAAE,MAAM,KAAK,CAAC;AAAA,EAC5C;AACA,SAAO,EAAE,UAAU,gBAAgB;AACvC;AAEA,SAAS,aAAa,MAAc,SAA0B;AAC1D,KAAG,UAAU,KAAK,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AACpD,QAAM,MAAM,GAAG,IAAI,QAAI,0BAAW,CAAC;AACnC,KAAG,cAAc,KAAK,KAAK,UAAU,SAAS,MAAM,CAAC,IAAI,MAAM,EAAE,MAAM,IAAM,CAAC;AAC9E,KAAG,WAAW,KAAK,IAAI;AAC3B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var operations_exports = {};
|
|
20
|
+
__export(operations_exports, {
|
|
21
|
+
PIPELINE_OPERATIONS: () => PIPELINE_OPERATIONS,
|
|
22
|
+
runPipelineInit: () => runPipelineInit,
|
|
23
|
+
runPipelineOperation: () => runPipelineOperation
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(operations_exports);
|
|
26
|
+
var import_create = require("./create");
|
|
27
|
+
var import_init = require("./init");
|
|
28
|
+
const PIPELINE_OPERATIONS = [
|
|
29
|
+
"check",
|
|
30
|
+
"pull",
|
|
31
|
+
"push",
|
|
32
|
+
"run",
|
|
33
|
+
"runs",
|
|
34
|
+
"inspect",
|
|
35
|
+
"inspect-import",
|
|
36
|
+
"query",
|
|
37
|
+
"versions",
|
|
38
|
+
"restore",
|
|
39
|
+
"terminate",
|
|
40
|
+
"upgrade-runtime"
|
|
41
|
+
];
|
|
42
|
+
function required(name, value) {
|
|
43
|
+
if (value === void 0) throw new Error(`${name} is required`);
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
async function runPipelineOperation(service, operation, args, signal) {
|
|
47
|
+
switch (operation) {
|
|
48
|
+
case "check":
|
|
49
|
+
return service.check(signal);
|
|
50
|
+
case "pull":
|
|
51
|
+
case "push":
|
|
52
|
+
return service.syncSources(operation);
|
|
53
|
+
case "run":
|
|
54
|
+
return service.submit(args.args ?? []);
|
|
55
|
+
case "runs":
|
|
56
|
+
return service.runs(args.limit);
|
|
57
|
+
case "inspect":
|
|
58
|
+
return service.inspect(args.uuid, args.offset ?? 0);
|
|
59
|
+
case "inspect-import":
|
|
60
|
+
return service.inspectImport(required("importId", args.importId));
|
|
61
|
+
case "versions":
|
|
62
|
+
return service.versions(required("datasetId", args.datasetId));
|
|
63
|
+
case "restore":
|
|
64
|
+
return service.restore(
|
|
65
|
+
required("datasetId", args.datasetId),
|
|
66
|
+
required("versionId", args.versionId),
|
|
67
|
+
required("expectedCurrent", args.expectedCurrent)
|
|
68
|
+
);
|
|
69
|
+
case "terminate":
|
|
70
|
+
return service.terminate(required("uuid", args.uuid));
|
|
71
|
+
case "upgrade-runtime":
|
|
72
|
+
return service.upgradeRuntime();
|
|
73
|
+
case "query": {
|
|
74
|
+
const bindings = required("bindings", args.bindings);
|
|
75
|
+
const sql = required("sql", args.sql);
|
|
76
|
+
const versioned = bindings[0]?.datasetId !== void 0;
|
|
77
|
+
return versioned ? service.queryVersions(bindings, sql, signal) : service.query(bindings, sql, signal);
|
|
78
|
+
}
|
|
79
|
+
default:
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Unknown operation "${String(operation)}". Supported operations: ${PIPELINE_OPERATIONS.join(", ")}`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function runPipelineInit(selection, openClient, paths) {
|
|
86
|
+
const { organisation, tenant, jobId, name, workspace, force } = selection;
|
|
87
|
+
if (jobId === void 0 === (name === void 0))
|
|
88
|
+
throw new Error("Pass either a prepared jobId or a new name, not both and not neither");
|
|
89
|
+
if (name !== void 0) {
|
|
90
|
+
if (workspace !== void 0 || force !== void 0)
|
|
91
|
+
throw new Error("workspace and force only apply when attaching to a prepared jobId");
|
|
92
|
+
return (0, import_create.createPipeline)({ organisation, tenant, name }, await openClient(), paths);
|
|
93
|
+
}
|
|
94
|
+
return (0, import_init.initPipelineProfile)(
|
|
95
|
+
{ organisation, tenant, jobId, workspace, force },
|
|
96
|
+
await openClient(),
|
|
97
|
+
paths
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
101
|
+
0 && (module.exports = {
|
|
102
|
+
PIPELINE_OPERATIONS,
|
|
103
|
+
runPipelineInit,
|
|
104
|
+
runPipelineOperation
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/pipeline/operations.ts"],
|
|
4
|
+
"sourcesContent": ["import type { PipelinePaths } from './connect';\nimport { createPipeline } from './create';\nimport { initPipelineProfile } from './init';\nimport type { PipelineClient, PipelineService } from './service';\n\n/**\n * The operations every surface (CLI command, MCP tool) exposes on a connected pipeline.\n * recover and unlock stay CLI-only: they resolve local state after a crash and are not\n * offered to a model.\n */\nexport const PIPELINE_OPERATIONS = [\n 'check',\n 'pull',\n 'push',\n 'run',\n 'runs',\n 'inspect',\n 'inspect-import',\n 'query',\n 'versions',\n 'restore',\n 'terminate',\n 'upgrade-runtime',\n] as const;\nexport type PipelineOperation = (typeof PIPELINE_OPERATIONS)[number];\n\nexport interface PipelineOperationArgs {\n /** Exact run UUID: for inspect (the local receipt's run when absent) and terminate (required). */\n uuid?: string;\n datasetId?: string;\n versionId?: string;\n /** The current version observed before restore; a stale value is refused by the backend. */\n expectedCurrent?: string;\n importId?: number;\n /** Log offset for inspect, from a previous page's nextOffset. */\n offset?: number;\n /** Ordered job arguments for run. */\n args?: string[];\n /** Version bindings {name, datasetId, versionId} or file bindings {name, file} for query. */\n bindings?: unknown[];\n sql?: string;\n /** Runs to list, newest first. */\n limit?: number;\n}\n\nexport interface PipelineInitSelection {\n organisation: string;\n tenant: string;\n /** Attach to a job somebody prepared; reads only. */\n jobId?: number;\n /** Create folder, job and profile for a new pipeline named after its folder. */\n name?: string;\n workspace?: string;\n force?: boolean;\n}\n\nfunction required<T>(name: keyof PipelineOperationArgs, value: T | undefined): T {\n if (value === undefined) throw new Error(`${name} is required`);\n return value;\n}\n\n/** One dispatcher for every surface, so an operation means the same call everywhere. */\nexport async function runPipelineOperation(\n service: PipelineService,\n operation: PipelineOperation,\n args: PipelineOperationArgs,\n signal?: AbortSignal,\n): Promise<unknown> {\n switch (operation) {\n case 'check':\n return service.check(signal);\n case 'pull':\n case 'push':\n return service.syncSources(operation);\n case 'run':\n return service.submit(args.args ?? []);\n case 'runs':\n return service.runs(args.limit);\n case 'inspect':\n return service.inspect(args.uuid, args.offset ?? 0);\n case 'inspect-import':\n return service.inspectImport(required('importId', args.importId));\n case 'versions':\n return service.versions(required('datasetId', args.datasetId));\n case 'restore':\n return service.restore(\n required('datasetId', args.datasetId),\n required('versionId', args.versionId),\n required('expectedCurrent', args.expectedCurrent),\n );\n case 'terminate':\n return service.terminate(required('uuid', args.uuid));\n case 'upgrade-runtime':\n return service.upgradeRuntime();\n case 'query': {\n const bindings = required('bindings', args.bindings);\n const sql = required('sql', args.sql);\n // A binding naming a dataset version reads immutable history; a file binding\n // reads the current mutable Farseer File. The first binding decides the mode.\n const versioned = (bindings[0] as { datasetId?: unknown } | undefined)?.datasetId !== undefined;\n return versioned\n ? service.queryVersions(bindings as Parameters<PipelineService['queryVersions']>[0], sql, signal)\n : service.query(bindings as Parameters<PipelineService['query']>[0], sql, signal);\n }\n default:\n throw new Error(\n `Unknown operation \"${String(operation)}\". Supported operations: ${PIPELINE_OPERATIONS.join(', ')}`,\n );\n }\n}\n\n/**\n * Attach to a prepared job or create a pipeline from nothing; exactly one of the two.\n * The selection is validated before the client is opened, so a bad call never touches the tenant.\n */\nexport async function runPipelineInit(\n selection: PipelineInitSelection,\n openClient: () => Promise<PipelineClient>,\n paths: PipelinePaths,\n) {\n const { organisation, tenant, jobId, name, workspace, force } = selection;\n if ((jobId === undefined) === (name === undefined))\n throw new Error('Pass either a prepared jobId or a new name, not both and not neither');\n if (name !== undefined) {\n if (workspace !== undefined || force !== undefined)\n throw new Error('workspace and force only apply when attaching to a prepared jobId');\n return createPipeline({ organisation, tenant, name }, await openClient(), paths);\n }\n return initPipelineProfile(\n { organisation, ten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ClC,KAAK,SAAS;AACV,YAAM,WAAW,SAAS,YAAY,KAAK,QAAQ;AACnD,YAAM,MAAM,SAAS,OAAO,KAAK,GAAG;AAGpC,YAAM,YAAa,SAAS,CAAC,GAA2C,cAAc;AACtF,aAAO,YACD,QAAQ,cAAc,UAA6D,KAAK,MAAM,IAC9F,QAAQ,MAAM,UAAqD,KAAK,MAAM;AAAA,IACxF;AAAA,IACA;AACI,YAAM,IAAI;AAAA,QACN,sBAAsB,OAAO,SAAS,CAAC,4BAA4B,oBAAoB,KAAK,IAAI,CAAC;AAAA,MACrG;AAAA,EACR;AACJ;AAMA,eAAsB,gBAClB,WACA,YACA,OACF;AACE,QAAM,EAAE,cAAc,QAAQ,OAAO,MAAM,WAAW,MAAM,IAAI;AAChE,MAAK,UAAU,YAAgB,SAAS;AACpC,UAAM,IAAI,MAAM,sEAAsE;AAC1F,MAAI,SAAS,QAAW;AACpB,QAAI,cAAc,UAAa,UAAU;AACrC,YAAM,IAAI,MAAM,mEAAmE;AACvF,eAAO,8BAAe,EAAE,cAAc,QAAQ,KAAK,GAAG,MAAM,WAAW,GAAG,KAAK;AAAA,EACnF;AACA,aAAO;AAAA,IACH,EAAE,cAAc,QAAQ,OAAwB,WAAW,MAAM;AAAA,IACjE,MAAM,WAAW;AAAA,IACjB;AAAA,EACJ;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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 query_exports = {};
|
|
30
|
+
__export(query_exports, {
|
|
31
|
+
DEFAULT_LIMITS: () => DEFAULT_LIMITS,
|
|
32
|
+
queryFiles: () => queryFiles
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(query_exports);
|
|
35
|
+
var import_child_process = require("child_process");
|
|
36
|
+
var fs = __toESM(require("fs"));
|
|
37
|
+
var os = __toESM(require("os"));
|
|
38
|
+
var path = __toESM(require("path"));
|
|
39
|
+
var import_queryDownloads = require("./queryDownloads");
|
|
40
|
+
const DEFAULT_LIMITS = Object.freeze({
|
|
41
|
+
memoryMb: 256,
|
|
42
|
+
spillMb: 256,
|
|
43
|
+
threads: 2,
|
|
44
|
+
timeMs: 3e4,
|
|
45
|
+
inputBytes: 256 * 1024 * 1024,
|
|
46
|
+
rows: 1e3,
|
|
47
|
+
resultBytes: 256 * 1024
|
|
48
|
+
});
|
|
49
|
+
async function queryFiles(request, signal, download) {
|
|
50
|
+
if (signal?.aborted) throw new Error("Query cancelled");
|
|
51
|
+
for (const value of Object.values(request.limits))
|
|
52
|
+
if (!Number.isSafeInteger(value) || value <= 0) throw new Error("Invalid query limits");
|
|
53
|
+
if (!request.bindings.length || request.bindings.length > 16 || request.sql.length > 1e5)
|
|
54
|
+
throw new Error("Invalid query size or bindings");
|
|
55
|
+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "farseer-pipeline-query-"));
|
|
56
|
+
fs.chmodSync(directory, 448);
|
|
57
|
+
const timeout = new AbortController();
|
|
58
|
+
const querySignal = signal ? AbortSignal.any([signal, timeout.signal]) : timeout.signal;
|
|
59
|
+
const cancelled = () => new Error(timeout.signal.aborted ? "Query time limit exceeded" : "Query cancelled");
|
|
60
|
+
const timer = setTimeout(() => timeout.abort(), request.limits.timeMs);
|
|
61
|
+
try {
|
|
62
|
+
const prepared = download ? await (0, import_queryDownloads.downloadQueryFiles)(
|
|
63
|
+
request,
|
|
64
|
+
directory,
|
|
65
|
+
(_address, binding, file) => download(binding, file, querySignal)
|
|
66
|
+
) : void 0;
|
|
67
|
+
if (querySignal.aborted) throw cancelled();
|
|
68
|
+
const worker = path.join(__dirname, "queryWorker.js");
|
|
69
|
+
const child = (0, import_child_process.fork)(worker, [], {
|
|
70
|
+
stdio: ["ignore", "ignore", "ignore", "ipc"],
|
|
71
|
+
execArgv: [],
|
|
72
|
+
// A laptop behind a TLS-inspecting proxy needs its extra CA for signed storage reads.
|
|
73
|
+
env: {
|
|
74
|
+
HOME: directory,
|
|
75
|
+
TMPDIR: directory,
|
|
76
|
+
LANG: "en_US.UTF-8",
|
|
77
|
+
...process.env.NODE_EXTRA_CA_CERTS ? { NODE_EXTRA_CA_CERTS: process.env.NODE_EXTRA_CA_CERTS } : {}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return await new Promise((resolve, reject) => {
|
|
81
|
+
let outcome;
|
|
82
|
+
const finish = (next) => {
|
|
83
|
+
if (!outcome) {
|
|
84
|
+
outcome = next;
|
|
85
|
+
child.kill("SIGKILL");
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const cancel = () => finish({ error: cancelled() });
|
|
89
|
+
querySignal.addEventListener("abort", cancel, { once: true });
|
|
90
|
+
child.once(
|
|
91
|
+
"message",
|
|
92
|
+
(message) => finish(message.ok ? { value: message.result } : { error: new Error(message.error) })
|
|
93
|
+
);
|
|
94
|
+
child.once("error", (error) => finish({ error }));
|
|
95
|
+
child.once("exit", () => {
|
|
96
|
+
querySignal.removeEventListener("abort", cancel);
|
|
97
|
+
if (outcome?.value) resolve(outcome.value);
|
|
98
|
+
else reject(outcome?.error ?? new Error("Query worker exited without a result"));
|
|
99
|
+
});
|
|
100
|
+
child.send({
|
|
101
|
+
...request,
|
|
102
|
+
...prepared ? { bindings: request.bindings.map(({ name }) => ({ name })) } : {},
|
|
103
|
+
directory,
|
|
104
|
+
prepared
|
|
105
|
+
});
|
|
106
|
+
if (querySignal.aborted) cancel();
|
|
107
|
+
});
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (querySignal.aborted) throw cancelled();
|
|
110
|
+
throw error;
|
|
111
|
+
} finally {
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
fs.rmSync(directory, { recursive: true, force: true });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
117
|
+
0 && (module.exports = {
|
|
118
|
+
DEFAULT_LIMITS,
|
|
119
|
+
queryFiles
|
|
120
|
+
});
|
|
121
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/pipeline/query.ts"],
|
|
4
|
+
"sourcesContent": ["import { fork } from 'child_process';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { downloadQueryFiles } from './queryDownloads';\n\nexport interface QueryLimits {\n memoryMb: number;\n spillMb: number;\n threads: number;\n timeMs: number;\n inputBytes: number;\n rows: number;\n resultBytes: number;\n}\nexport const DEFAULT_LIMITS: Readonly<QueryLimits> = Object.freeze({\n memoryMb: 256,\n spillMb: 256,\n threads: 2,\n timeMs: 30_000,\n inputBytes: 256 * 1024 * 1024,\n rows: 1000,\n resultBytes: 256 * 1024,\n});\nexport interface QueryRequest {\n bindings: { name: string; url?: string; urls?: string[] }[];\n sql: string;\n limits: QueryLimits;\n /** Local test harness only; not an MCP/CLI argument. */\n loopbackTest?: boolean;\n}\nexport interface QueryResult {\n columns: string[];\n rows: unknown[][];\n truncated: boolean;\n complete: boolean;\n downloadedBytes: number;\n resultBytes: number;\n}\n\nexport async function queryFiles(\n request: QueryRequest,\n signal?: AbortSignal,\n download?: (binding: number, file: number, signal: AbortSignal) => Promise<Response>,\n): Promise<QueryResult> {\n if (signal?.aborted) throw new Error('Query cancelled');\n for (const value of Object.values(request.limits))\n if (!Number.isSafeInteger(value) || value <= 0) throw new Error('Invalid query limits');\n if (!request.bindings.length || request.bindings.length > 16 || request.sql.length > 100_000)\n throw new Error('Invalid query size or bindings');\n const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'farseer-pipeline-query-'));\n fs.chmodSync(directory, 0o700);\n const timeout = new AbortController();\n const querySignal = signal ? AbortSignal.any([signal, timeout.signal]) : timeout.signal;\n const cancelled = () => new Error(timeout.signal.aborted ? 'Query time limit exceeded' : 'Query cancelled');\n const timer = setTimeout(() => timeout.abort(), request.limits.timeMs);\n try {\n // The sandbox parent downloads through its authenticated backend connection. Only local\n // files reach the disposable SQL worker; it receives no credential or authenticated URL.\n const prepared = download\n ? await downloadQueryFiles(request, directory, (_address, binding, file) =>\n download(binding, file, querySignal),\n )\n : undefined;\n if (querySignal.aborted) throw cancelled();\n const worker = path.join(__dirname, 'queryWorker.js');\n const child = fork(worker, [], {\n stdio: ['ignore', 'ignore', 'ignore', 'ipc'],\n execArgv: [],\n // A laptop behind a TLS-inspecting proxy needs its extra CA for signed storage reads.\n env: {\n HOME: directory,\n TMPDIR: directory,\n LANG: 'en_US.UTF-8',\n ...(process.env.NODE_EXTRA_CA_CERTS ? { NODE_EXTRA_CA_CERTS: process.env.NODE_EXTRA_CA_CERTS } : {}),\n },\n });\n return await new Promise((resolve, reject) => {\n let outcome: { value?: QueryResult; error?: Error } | undefined;\n const finish = (next: typeof outcome) => {\n if (!outcome) {\n outcome = next;\n child.kill('SIGKILL');\n }\n };\n const cancel = () => finish({ error: cancelled() });\n querySignal.addEventListener('abort', cancel, { once: true });\n child.once('message', (message: any) =>\n finish(message.ok ? { value: message.result } : { error: new Error(message.error) }),\n );\n child.once('error', (error) => finish({ error }));\n child.once('exit', () => {\n querySignal.removeEventListener('abort', cancel);\n if (outcome?.value) resolve(outcome.value);\n else reject(outcome?.error ?? new Error('Query worker exited without a result'));\n });\n child.send({\n ...request,\n ...(prepared ? { bindings: request.bindings.map(({ name }) => ({ name })) } : {}),\n directory,\n prepared,\n });\n if (querySignal.aborted) cancel();\n });\n } catch (error) {\n if (querySignal.aborted) throw cancelled();\n throw error;\n } finally {\n clearTimeout(timer);\n fs.rmSync(directory, { recursive: true, force: true });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAqB;AACrB,SAAoB;AACpB,SAAoB;AACpB,WAAsB;AACtB,4BAAmC;AAW5B,MAAM,iBAAwC,OAAO,OAAO;AAAA,EAC/D,UAAU;AAAA,EACV,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,YAAY,MAAM,OAAO;AAAA,EACzB,MAAM;AAAA,EACN,aAAa,MAAM;AACvB,CAAC;AAiBD,eAAsB,WAClB,SACA,QACA,UACoB;AACpB,MAAI,QAAQ,QAAS,OAAM,IAAI,MAAM,iBAAiB;AACtD,aAAW,SAAS,OAAO,OAAO,QAA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AU;AACV,gBAAM,KAAK,SAAS;AAAA,QACxB;AAAA,MACJ;AACA,YAAM,SAAS,MAAM,OAAO,EAAE,OAAO,UAAU,EAAE,CAAC;AAClD,kBAAY,iBAAiB,SAAS,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC5D,YAAM;AAAA,QAAK;AAAA,QAAW,CAAC,YACnB,OAAO,QAAQ,KAAK,EAAE,OAAO,QAAQ,OAAO,IAAI,EAAE,OAAO,IAAI,MAAM,QAAQ,KAAK,EAAE,CAAC;AAAA,MACvF;AACA,YAAM,KAAK,SAAS,CAAC,UAAU,OAAO,EAAE,MAAM,CAAC,CAAC;AAChD,YAAM,KAAK,QAAQ,MAAM;AACrB,oBAAY,oBAAoB,SAAS,MAAM;AAC/C,YAAI,SAAS,MAAO,SAAQ,QAAQ,KAAK;AAAA,YACpC,QAAO,SAAS,SAAS,IAAI,MAAM,sCAAsC,CAAC;AAAA,MACnF,CAAC;AACD,YAAM,KAAK;AAAA,QACP,GAAG;AAAA,QACH,GAAI,WAAW,EAAE,UAAU,QAAQ,SAAS,IAAI,CAAC,EAAE,KAAK,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC;AAAA,QAC/E;AAAA,QACA;AAAA,MACJ,CAAC;AACD,UAAI,YAAY,QAAS,QAAO;AAAA,IACpC,CAAC;AAAA,EACL,SAAS,OAAO;AACZ,QAAI,YAAY,QAAS,OAAM,UAAU;AACzC,UAAM;AAAA,EACV,UAAE;AACE,iBAAa,KAAK;AAClB,OAAG,OAAO,WAAW,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EACzD;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -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,wB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