@diagonal-hq/cli 0.38.2 → 0.38.4
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 +21 -5
- package/dist/check-data.json +1 -0
- package/dist/cli-assets-cli-VQBXYEIZ.mjs +386 -0
- package/dist/cli-check-data-GHZW7MSI.mjs +17893 -0
- package/dist/cli-chunk-A7Q2M4ZU.mjs +1052 -0
- package/dist/cli-chunk-F2J44UIS.mjs +39865 -0
- package/dist/cli-chunk-HWHRAOWD.mjs +24035 -0
- package/dist/cli-chunk-LRS5IEI3.mjs +48 -0
- package/dist/cli-chunk-T6442V5V.mjs +7463 -0
- package/dist/cli-chunk-U2ET6LQJ.mjs +277 -0
- package/dist/cli-chunk-WPC3DBHX.mjs +52 -0
- package/dist/cli-chunk-XMVYLKEB.mjs +359 -0
- package/dist/cli-chunk-YIPLFIKL.mjs +63 -0
- package/dist/cli-files.generated-WAU3U62D.mjs +61 -0
- package/dist/cli-sdk-files.generated-HAH7DJPZ.mjs +1429 -0
- package/dist/cli-skill-file-TEJUXCJB.mjs +262 -0
- package/dist/cli-workflows-CK5ZVNYR.mjs +462 -0
- package/dist/cli.mjs +545 -99388
- package/dist/script-sdk.json +1 -0
- package/package.json +7 -4
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { createRequire as __diagonalCreateRequire } from 'node:module';
|
|
2
|
+
const require = __diagonalCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
stringFacts
|
|
5
|
+
} from "./cli-chunk-WPC3DBHX.mjs";
|
|
6
|
+
|
|
7
|
+
// scripts/lib/npm-package.mjs
|
|
8
|
+
function tarballName(name, version) {
|
|
9
|
+
return `${name.replace(/^@/, "").replace("/", "-")}-${version}.tgz`;
|
|
10
|
+
}
|
|
11
|
+
var VERSION_PATTERN = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
12
|
+
function isVersion(version) {
|
|
13
|
+
return VERSION_PATTERN.test(version);
|
|
14
|
+
}
|
|
15
|
+
function parseVersion(version) {
|
|
16
|
+
const match = VERSION_PATTERN.exec(version);
|
|
17
|
+
if (match === null) {
|
|
18
|
+
throw new Error(`${version} is not a version of the form major.minor.patch[-prerelease]`);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
major: Number(match[1]),
|
|
22
|
+
minor: Number(match[2]),
|
|
23
|
+
patch: Number(match[3]),
|
|
24
|
+
prerelease: match[4] ?? null
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function comparePrereleases(left, right) {
|
|
28
|
+
const a = left.split(".");
|
|
29
|
+
const b = right.split(".");
|
|
30
|
+
for (let index = 0; index < Math.min(a.length, b.length); index++) {
|
|
31
|
+
const aNumeric = /^\d+$/.test(a[index]);
|
|
32
|
+
const bNumeric = /^\d+$/.test(b[index]);
|
|
33
|
+
if (aNumeric && bNumeric) {
|
|
34
|
+
const order = Math.sign(Number(a[index]) - Number(b[index]));
|
|
35
|
+
if (order !== 0) {
|
|
36
|
+
return order;
|
|
37
|
+
}
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (aNumeric !== bNumeric) {
|
|
41
|
+
return aNumeric ? -1 : 1;
|
|
42
|
+
}
|
|
43
|
+
if (a[index] !== b[index]) {
|
|
44
|
+
return a[index] < b[index] ? -1 : 1;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return Math.sign(a.length - b.length);
|
|
48
|
+
}
|
|
49
|
+
function compareVersions(left, right) {
|
|
50
|
+
const a = parseVersion(left);
|
|
51
|
+
const b = parseVersion(right);
|
|
52
|
+
for (const part of ["major", "minor", "patch"]) {
|
|
53
|
+
if (a[part] !== b[part]) {
|
|
54
|
+
return a[part] < b[part] ? -1 : 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (a.prerelease === b.prerelease) {
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
if (a.prerelease === null) {
|
|
61
|
+
return 1;
|
|
62
|
+
}
|
|
63
|
+
if (b.prerelease === null) {
|
|
64
|
+
return -1;
|
|
65
|
+
}
|
|
66
|
+
return comparePrereleases(a.prerelease, b.prerelease);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// scripts/lib/workflow-script/compile.mjs
|
|
70
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
71
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
72
|
+
|
|
73
|
+
// scripts/lib/native-platform-suffix.mjs
|
|
74
|
+
function nativePlatformSuffix({
|
|
75
|
+
platform = process.platform,
|
|
76
|
+
arch = process.arch,
|
|
77
|
+
glibcVersionRuntime = (globalThis[/* @__PURE__ */ Symbol.for("diagonal.nativePlatformSuffix.glibcVersionRuntime")] ??= {
|
|
78
|
+
value: process.report.getReport().header.glibcVersionRuntime
|
|
79
|
+
}).value
|
|
80
|
+
} = {}) {
|
|
81
|
+
const parts = [platform, arch];
|
|
82
|
+
if (platform === "linux") {
|
|
83
|
+
if (glibcVersionRuntime) {
|
|
84
|
+
parts.push(arch === "arm" ? "gnueabihf" : "gnu");
|
|
85
|
+
} else {
|
|
86
|
+
parts.push("musl");
|
|
87
|
+
}
|
|
88
|
+
} else if (platform === "win32") {
|
|
89
|
+
parts.push("msvc");
|
|
90
|
+
}
|
|
91
|
+
return parts.join("-");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// scripts/lib/runtime-build/bundled-binaries.mjs
|
|
95
|
+
import { accessSync, chmodSync, constants, existsSync } from "node:fs";
|
|
96
|
+
var BUN_PACKAGES = {
|
|
97
|
+
"darwin-arm64": "@oven/bun-darwin-aarch64",
|
|
98
|
+
"darwin-x64": "@oven/bun-darwin-x64",
|
|
99
|
+
"linux-arm64-gnu": "@oven/bun-linux-aarch64",
|
|
100
|
+
"linux-arm64-musl": "@oven/bun-linux-aarch64-musl",
|
|
101
|
+
"linux-x64-gnu": "@oven/bun-linux-x64",
|
|
102
|
+
"linux-x64-musl": "@oven/bun-linux-x64-musl"
|
|
103
|
+
};
|
|
104
|
+
function bunPackage(nativePlatform) {
|
|
105
|
+
const name = BUN_PACKAGES[nativePlatform];
|
|
106
|
+
if (name === void 0) {
|
|
107
|
+
throw new Error(`bun has no package for the platform ${nativePlatform}.`);
|
|
108
|
+
}
|
|
109
|
+
return name;
|
|
110
|
+
}
|
|
111
|
+
function ensureExecutable(binary) {
|
|
112
|
+
try {
|
|
113
|
+
accessSync(binary, constants.X_OK);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (error.code !== "EACCES") {
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
chmodSync(binary, 493);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// scripts/lib/workflow-script/compiler-packages.mjs
|
|
123
|
+
import { existsSync as existsSync2, readFileSync } from "node:fs";
|
|
124
|
+
import { createRequire } from "node:module";
|
|
125
|
+
import { fileURLToPath } from "node:url";
|
|
126
|
+
var COMPILER_BINARY = "workflow-script-compiler";
|
|
127
|
+
var checkout = new URL("../../../", import.meta.url);
|
|
128
|
+
var crate = new URL("services/workflow-script-compiler/", checkout);
|
|
129
|
+
function compilerPackage(platform) {
|
|
130
|
+
return `@diagonal-hq/workflow-script-compiler-${platform}`;
|
|
131
|
+
}
|
|
132
|
+
function compilerSourcesHash() {
|
|
133
|
+
const stamp = fileURLToPath(new URL("sources.stamp", crate));
|
|
134
|
+
return existsSync2(stamp) ? readFileSync(stamp, "utf8").trim() : null;
|
|
135
|
+
}
|
|
136
|
+
function hostCompilerPlatform() {
|
|
137
|
+
return `${process.platform}-${process.arch}`;
|
|
138
|
+
}
|
|
139
|
+
function localCompilerBinary(platform) {
|
|
140
|
+
const directory = new URL(`dist/${platform}/`, crate);
|
|
141
|
+
const binary = fileURLToPath(new URL(COMPILER_BINARY, directory));
|
|
142
|
+
const stamp = fileURLToPath(new URL("sources.stamp", directory));
|
|
143
|
+
const hash = compilerSourcesHash();
|
|
144
|
+
return hash !== null && existsSync2(binary) && existsSync2(stamp) && readFileSync(stamp, "utf8").trim() === hash ? binary : null;
|
|
145
|
+
}
|
|
146
|
+
function bundledCompilerBinary(platform) {
|
|
147
|
+
const directory = new URL(`scripts/dist/workflow-script-compiler/${platform}/`, checkout);
|
|
148
|
+
const binary = fileURLToPath(new URL(COMPILER_BINARY, directory));
|
|
149
|
+
const stamp = fileURLToPath(new URL("sources.stamp", directory));
|
|
150
|
+
const hash = compilerSourcesHash();
|
|
151
|
+
return hash !== null && existsSync2(binary) && existsSync2(stamp) && readFileSync(stamp, "utf8").trim() === hash ? binary : null;
|
|
152
|
+
}
|
|
153
|
+
function installedCompilerBinary(platform, from = import.meta.url) {
|
|
154
|
+
try {
|
|
155
|
+
return createRequire(from).resolve(`${compilerPackage(platform)}/bin/${COMPILER_BINARY}`);
|
|
156
|
+
} catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// scripts/lib/workflow-script/compile.mjs
|
|
162
|
+
function compilerBinary() {
|
|
163
|
+
if (process.env.WORKFLOW_SCRIPT_COMPILER_BINARY) {
|
|
164
|
+
return process.env.WORKFLOW_SCRIPT_COMPILER_BINARY;
|
|
165
|
+
}
|
|
166
|
+
const platform = hostCompilerPlatform();
|
|
167
|
+
const binary = localCompilerBinary(platform) ?? bundledCompilerBinary(platform) ?? installedCompilerBinary(platform);
|
|
168
|
+
if (binary === null) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`No workflow script compiler for ${platform} matches services/workflow-script-compiler/sources.stamp. Run npm run build:runtime-workspace-build, or services/workflow-script-compiler/build.sh ${platform}.`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
ensureExecutable(binary);
|
|
174
|
+
return binary;
|
|
175
|
+
}
|
|
176
|
+
var packagedBun = null;
|
|
177
|
+
function bunBinary() {
|
|
178
|
+
if (process.env.RUNTIME_BUN_BINARY) {
|
|
179
|
+
return process.env.RUNTIME_BUN_BINARY;
|
|
180
|
+
}
|
|
181
|
+
packagedBun ??= packagedBunBinary();
|
|
182
|
+
return packagedBun;
|
|
183
|
+
}
|
|
184
|
+
function packagedBunBinary() {
|
|
185
|
+
const require2 = createRequire2(import.meta.url);
|
|
186
|
+
try {
|
|
187
|
+
return require2.resolve(`${bunPackage(nativePlatformSuffix())}/bin/bun`);
|
|
188
|
+
} catch {
|
|
189
|
+
return require2.resolve("bun/bin/bun.exe");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function stripTypes(files) {
|
|
193
|
+
if (files.length === 0) {
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
return runCompiler({ strips: files }).stripResults;
|
|
197
|
+
}
|
|
198
|
+
function runWorkspaceBuild(root, request, sources = {}, needs = workspaceBuildNeeds(root, request, sources)) {
|
|
199
|
+
return workspaceBuildAnswer(runCompiler(workspaceBuildInput(root, request, sources, needs), buildArguments(sources)));
|
|
200
|
+
}
|
|
201
|
+
async function runWorkspaceBuildAsync(root, request, sources, needs) {
|
|
202
|
+
return workspaceBuildAnswer(await runCompilerAsync(workspaceBuildInput(root, request, sources, needs), buildArguments(sources)));
|
|
203
|
+
}
|
|
204
|
+
function workspaceBuildInput(root, request, { data = null, sdk = null, skillFrontMatter = null }, needs) {
|
|
205
|
+
if (needs.skills.length > 0 && skillFrontMatter === null) {
|
|
206
|
+
throw new Error("The build needs the reader of the skill files.");
|
|
207
|
+
}
|
|
208
|
+
const build = data === null ? { root, ...request } : { root, ...request, data };
|
|
209
|
+
const answers = { stringFacts: stringFacts(needs.stringFacts), skillFrontMatter: needs.skills.length > 0 ? skillFrontMatter(root, needs.skills) : {} };
|
|
210
|
+
return { build: { ...build, ...answers }, ...sdk === null ? {} : { sdk } };
|
|
211
|
+
}
|
|
212
|
+
function workspaceBuildAnswer(answer) {
|
|
213
|
+
if (answer.failure !== void 0) {
|
|
214
|
+
throw answer.failure.name === "TypeError" ? new TypeError(answer.failure.message) : new Error(answer.failure.message);
|
|
215
|
+
}
|
|
216
|
+
return answer;
|
|
217
|
+
}
|
|
218
|
+
function workspaceBuildNeeds(root, request, sources = {}) {
|
|
219
|
+
const { data = null } = sources;
|
|
220
|
+
const first = runCompiler({ build: data === null ? { root, ...request } : { root, ...request, data } }, buildArguments(sources), { bun: false });
|
|
221
|
+
if (first.needs === void 0) {
|
|
222
|
+
throw new Error("The workflow script compiler did not name the needs of the build.");
|
|
223
|
+
}
|
|
224
|
+
return first.needs;
|
|
225
|
+
}
|
|
226
|
+
function buildArguments({ dataFile = null, sdkFile = null }) {
|
|
227
|
+
return [...dataFile === null ? [] : ["--data", dataFile], ...sdkFile === null ? [] : ["--sdk", sdkFile]];
|
|
228
|
+
}
|
|
229
|
+
function runCompiler(input, args = [], { timeout, bun = true } = {}) {
|
|
230
|
+
const run = spawnSync(compilerBinary(), args, {
|
|
231
|
+
input: JSON.stringify(input),
|
|
232
|
+
encoding: "utf8",
|
|
233
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
234
|
+
timeout,
|
|
235
|
+
killSignal: "SIGKILL",
|
|
236
|
+
env: bun ? { ...process.env, RUNTIME_BUN_BINARY: bunBinary() } : process.env
|
|
237
|
+
});
|
|
238
|
+
if (run.error !== void 0) {
|
|
239
|
+
throw run.error;
|
|
240
|
+
}
|
|
241
|
+
if (run.status !== 0) {
|
|
242
|
+
throw new Error(`The workflow script compiler failed: ${run.stderr.slice(0, 2e3)}`);
|
|
243
|
+
}
|
|
244
|
+
return JSON.parse(run.stdout);
|
|
245
|
+
}
|
|
246
|
+
function runCompilerAsync(input, args) {
|
|
247
|
+
return new Promise((resolve, reject) => {
|
|
248
|
+
const child = spawn(compilerBinary(), args, { env: { ...process.env, RUNTIME_BUN_BINARY: bunBinary() } });
|
|
249
|
+
const stdout = [];
|
|
250
|
+
const stderr = [];
|
|
251
|
+
child.stdout.on("data", (chunk) => stdout.push(chunk));
|
|
252
|
+
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
253
|
+
child.on("error", reject);
|
|
254
|
+
child.on("close", (status) => {
|
|
255
|
+
if (status !== 0) {
|
|
256
|
+
reject(new Error(`The workflow script compiler failed: ${Buffer.concat(stderr).toString("utf8").slice(0, 2e3)}`));
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
resolve(JSON.parse(Buffer.concat(stdout).toString("utf8")));
|
|
261
|
+
} catch (error) {
|
|
262
|
+
reject(error);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
child.stdin.end(JSON.stringify(input));
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export {
|
|
270
|
+
tarballName,
|
|
271
|
+
isVersion,
|
|
272
|
+
compareVersions,
|
|
273
|
+
stripTypes,
|
|
274
|
+
runWorkspaceBuild,
|
|
275
|
+
runWorkspaceBuildAsync,
|
|
276
|
+
workspaceBuildNeeds
|
|
277
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createRequire as __diagonalCreateRequire } from 'node:module';
|
|
2
|
+
const require = __diagonalCreateRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// scripts/lib/workflow-script/constants.mjs
|
|
5
|
+
var PROFILES = {
|
|
6
|
+
workflow: {
|
|
7
|
+
label: "A workflow script",
|
|
8
|
+
imports: ["@diagonal/workflow", "@diagonal/workflow/workspace"],
|
|
9
|
+
specifier: null,
|
|
10
|
+
entry: null,
|
|
11
|
+
defaultExports: ["defineWorkflow"]
|
|
12
|
+
},
|
|
13
|
+
test: {
|
|
14
|
+
label: "A test script",
|
|
15
|
+
imports: ["@diagonal/workflow", "@diagonal-hq/workflows/test", "@diagonal/workflow/workspace"],
|
|
16
|
+
specifier: "@diagonal-hq/workflows/test",
|
|
17
|
+
entry: "/sdk/profiles/test.ts",
|
|
18
|
+
defaultExports: ["defineWorkflow"]
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var PROFILE_SPECIFIERS = new Set(
|
|
22
|
+
Object.values(PROFILES).flatMap(({ specifier }) => specifier === null ? [] : [specifier])
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// scripts/lib/runtime-build/string-facts.mjs
|
|
26
|
+
var URL_PATTERN = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
27
|
+
function isUrl(value) {
|
|
28
|
+
return URL_PATTERN.test(value) && URL.canParse(value);
|
|
29
|
+
}
|
|
30
|
+
function isTimezone(value) {
|
|
31
|
+
try {
|
|
32
|
+
new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error instanceof RangeError) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
return value.includes("/") || value === "UTC";
|
|
40
|
+
}
|
|
41
|
+
function stringFacts(strings) {
|
|
42
|
+
const facts = /* @__PURE__ */ Object.create(null);
|
|
43
|
+
for (const text of strings) {
|
|
44
|
+
facts[text] = [isTimezone(text), isUrl(text), !Number.isNaN(Date.parse(text))];
|
|
45
|
+
}
|
|
46
|
+
return facts;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
stringFacts,
|
|
51
|
+
PROFILES
|
|
52
|
+
};
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { createRequire as __diagonalCreateRequire } from 'node:module';
|
|
2
|
+
const require = __diagonalCreateRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// scripts/lib/runtime-build/api-cli.mjs
|
|
5
|
+
var WORKFLOWS_USAGE = "Usage: diagonal workflows [--json]";
|
|
6
|
+
var RUN_USAGE = "Usage: diagonal run <path> [--input '<json object>'] [--json]";
|
|
7
|
+
var LOGS_USAGE = "Usage: diagonal logs [path | execution id] [--status <success|error|exception|started|pending>] [--limit <1-100>] [--json]";
|
|
8
|
+
var SUCCESS = "execution.success";
|
|
9
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
10
|
+
var STATUSES = ["success", "error", "exception", "started", "pending"];
|
|
11
|
+
function credentials(env, stderr) {
|
|
12
|
+
const url = env.DIAGONAL_URL?.trim().replace(/\/+$/, "") ?? "";
|
|
13
|
+
const apiKey = env.DIAGONAL_API_KEY?.trim() ?? "";
|
|
14
|
+
if (url === "" || apiKey === "") {
|
|
15
|
+
stderr.write(
|
|
16
|
+
"Set DIAGONAL_URL to the workspace URL and DIAGONAL_API_KEY to an API key of a System Administrator.\n"
|
|
17
|
+
);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return { url, apiKey };
|
|
21
|
+
}
|
|
22
|
+
function errorText(status, body) {
|
|
23
|
+
const lines = [`Request failed with HTTP ${status}${body?.message ? `: ${body.message}` : ""}`];
|
|
24
|
+
for (const messages of Object.values(body?.errors ?? {})) {
|
|
25
|
+
for (const message of messages) {
|
|
26
|
+
if (message !== body.message) {
|
|
27
|
+
lines.push(` ${message}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return `${lines.join("\n")}
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
async function request({ url, apiKey }, method, path, body, stderr, { responseDetails = false } = {}) {
|
|
35
|
+
const headers = { Accept: "application/json", Authorization: `Bearer ${apiKey}` };
|
|
36
|
+
const init = body === void 0 || body instanceof FormData ? { method, headers, body } : {
|
|
37
|
+
method,
|
|
38
|
+
headers: { ...headers, "Content-Type": "application/json" },
|
|
39
|
+
body: JSON.stringify(body)
|
|
40
|
+
};
|
|
41
|
+
let response;
|
|
42
|
+
let text;
|
|
43
|
+
try {
|
|
44
|
+
response = await fetch(`${url}${path}`, init);
|
|
45
|
+
text = await response.text();
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (!(error instanceof TypeError)) {
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
stderr.write(`Could not reach ${url}: ${error.cause?.message ?? error.message}
|
|
51
|
+
`);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
let json;
|
|
55
|
+
try {
|
|
56
|
+
json = JSON.parse(text);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (!(error instanceof SyntaxError)) {
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
stderr.write(`HTTP ${response.status} from ${url}${path} is not JSON.
|
|
62
|
+
`);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (responseDetails) {
|
|
66
|
+
return { ok: response.ok, status: response.status, body: json };
|
|
67
|
+
}
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
stderr.write(errorText(response.status, json));
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return json;
|
|
73
|
+
}
|
|
74
|
+
function parseFlags(args, valueFlags, booleanFlags) {
|
|
75
|
+
const positional = [];
|
|
76
|
+
const values = {};
|
|
77
|
+
const booleans = /* @__PURE__ */ new Set();
|
|
78
|
+
for (let index = 0; index < args.length; index++) {
|
|
79
|
+
const arg = args[index];
|
|
80
|
+
if (!arg.startsWith("--")) {
|
|
81
|
+
positional.push(arg);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (booleanFlags.includes(arg)) {
|
|
85
|
+
booleans.add(arg);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (!valueFlags.includes(arg)) {
|
|
89
|
+
return { error: `Unknown option ${arg}` };
|
|
90
|
+
}
|
|
91
|
+
if (index + 1 >= args.length || args[index + 1].startsWith("--")) {
|
|
92
|
+
return { error: `${arg} needs a value` };
|
|
93
|
+
}
|
|
94
|
+
values[arg] = args[++index];
|
|
95
|
+
}
|
|
96
|
+
return { positional, values, booleans };
|
|
97
|
+
}
|
|
98
|
+
async function listWorkflows(args, { env, stdout, stderr }) {
|
|
99
|
+
const parsed = parseFlags(args, [], ["--json"]);
|
|
100
|
+
if (parsed.error !== void 0 || parsed.positional.length > 0) {
|
|
101
|
+
stderr.write(
|
|
102
|
+
`${parsed.error ?? "diagonal workflows takes no arguments"}
|
|
103
|
+
${WORKFLOWS_USAGE}
|
|
104
|
+
`
|
|
105
|
+
);
|
|
106
|
+
return 2;
|
|
107
|
+
}
|
|
108
|
+
const target = credentials(env, stderr);
|
|
109
|
+
if (target === null) {
|
|
110
|
+
return 2;
|
|
111
|
+
}
|
|
112
|
+
const body = await request(target, "GET", "/api/runtime/workflows", void 0, stderr);
|
|
113
|
+
if (body === null) {
|
|
114
|
+
return 1;
|
|
115
|
+
}
|
|
116
|
+
if (parsed.booleans.has("--json")) {
|
|
117
|
+
stdout.write(`${JSON.stringify(body, null, 2)}
|
|
118
|
+
`);
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
if (body.active_sha === null) {
|
|
122
|
+
stdout.write("The workspace has no active deployment.\n");
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
const rows = body.data.map((workflow) => [workflow.path, workflow.type, workflow.title]);
|
|
126
|
+
const widths = [0, 1].map((column) => Math.max(...rows.map((row) => row[column].length)));
|
|
127
|
+
for (const row of rows) {
|
|
128
|
+
stdout.write(`${row[0].padEnd(widths[0])} ${row[1].padEnd(widths[1])} ${row[2]}
|
|
129
|
+
`);
|
|
130
|
+
}
|
|
131
|
+
stdout.write(
|
|
132
|
+
`${rows.length} workflow${rows.length === 1 ? "" : "s"} at ${body.active_sha.slice(0, 7)}
|
|
133
|
+
`
|
|
134
|
+
);
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
function parseRunArguments(args) {
|
|
138
|
+
const parsed = parseFlags(args, ["--input"], ["--json"]);
|
|
139
|
+
if (parsed.error !== void 0) {
|
|
140
|
+
return parsed;
|
|
141
|
+
}
|
|
142
|
+
if (parsed.positional.length !== 1) {
|
|
143
|
+
return {
|
|
144
|
+
error: "Give one workflow path, for example workflows/seed-catalog.ts"
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const json = parsed.booleans.has("--json");
|
|
148
|
+
const path = parsed.positional[0].replace(/^\.\//, "");
|
|
149
|
+
const rawInput = parsed.values["--input"];
|
|
150
|
+
if (rawInput === void 0) {
|
|
151
|
+
return { path, input: {}, json };
|
|
152
|
+
}
|
|
153
|
+
let input;
|
|
154
|
+
try {
|
|
155
|
+
input = JSON.parse(rawInput);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (!(error instanceof SyntaxError)) {
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
return { error: `--input is not valid JSON: ${error.message}` };
|
|
161
|
+
}
|
|
162
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
163
|
+
return { error: "--input must be a JSON object" };
|
|
164
|
+
}
|
|
165
|
+
return { path, input, json };
|
|
166
|
+
}
|
|
167
|
+
async function runWorkflow(args, { env, stdout, stderr }) {
|
|
168
|
+
const parsed = parseRunArguments(args);
|
|
169
|
+
if (parsed.error !== void 0) {
|
|
170
|
+
stderr.write(`${parsed.error}
|
|
171
|
+
${RUN_USAGE}
|
|
172
|
+
`);
|
|
173
|
+
return 2;
|
|
174
|
+
}
|
|
175
|
+
const target = credentials(env, stderr);
|
|
176
|
+
if (target === null) {
|
|
177
|
+
return 2;
|
|
178
|
+
}
|
|
179
|
+
const body = await request(
|
|
180
|
+
target,
|
|
181
|
+
"POST",
|
|
182
|
+
`/api/runtime/workflows/run?path=${encodeURIComponent(parsed.path)}`,
|
|
183
|
+
{ input: parsed.input },
|
|
184
|
+
stderr
|
|
185
|
+
);
|
|
186
|
+
if (body === null) {
|
|
187
|
+
return 1;
|
|
188
|
+
}
|
|
189
|
+
const succeeded = body.status === SUCCESS;
|
|
190
|
+
if (parsed.json) {
|
|
191
|
+
stdout.write(`${JSON.stringify(body, null, 2)}
|
|
192
|
+
`);
|
|
193
|
+
return succeeded ? 0 : 1;
|
|
194
|
+
}
|
|
195
|
+
stdout.write(`${body.path} ${body.status} (execution ${body.execution_id})
|
|
196
|
+
`);
|
|
197
|
+
if (body.output !== null && body.output !== void 0) {
|
|
198
|
+
stdout.write(`${JSON.stringify(body.output, null, 2)}
|
|
199
|
+
`);
|
|
200
|
+
}
|
|
201
|
+
return succeeded ? 0 : 1;
|
|
202
|
+
}
|
|
203
|
+
function parseLogsArguments(args) {
|
|
204
|
+
const parsed = parseFlags(args, ["--status", "--limit"], ["--json"]);
|
|
205
|
+
if (parsed.error !== void 0) {
|
|
206
|
+
return parsed;
|
|
207
|
+
}
|
|
208
|
+
if (parsed.positional.length > 1) {
|
|
209
|
+
return { error: "Give at most one workflow path or execution id" };
|
|
210
|
+
}
|
|
211
|
+
const target = parsed.positional[0]?.replace(/^\.\//, "") ?? null;
|
|
212
|
+
const status = parsed.values["--status"] ?? null;
|
|
213
|
+
const rawLimit = parsed.values["--limit"];
|
|
214
|
+
const limit = rawLimit === void 0 ? null : Number(rawLimit);
|
|
215
|
+
if (status !== null && !STATUSES.includes(status)) {
|
|
216
|
+
return { error: `--status must be one of ${STATUSES.join(", ")}` };
|
|
217
|
+
}
|
|
218
|
+
if (limit !== null && (!Number.isInteger(limit) || limit < 1 || limit > 100)) {
|
|
219
|
+
return { error: "--limit must be a whole number from 1 to 100" };
|
|
220
|
+
}
|
|
221
|
+
const execution = target !== null && UUID.test(target) ? target : null;
|
|
222
|
+
if (execution !== null && (status !== null || limit !== null)) {
|
|
223
|
+
return {
|
|
224
|
+
error: "--status and --limit apply to a list of runs, not to one execution"
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
execution,
|
|
229
|
+
path: execution === null ? target : null,
|
|
230
|
+
status,
|
|
231
|
+
limit,
|
|
232
|
+
json: parsed.booleans.has("--json")
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function runDuration(run) {
|
|
236
|
+
if (run.duration_ms === null || run.duration_ms === void 0) {
|
|
237
|
+
return "";
|
|
238
|
+
}
|
|
239
|
+
return run.duration_ms < 1e3 ? `${run.duration_ms}ms` : `${(run.duration_ms / 1e3).toFixed(1)}s`;
|
|
240
|
+
}
|
|
241
|
+
function errorLines(error, indent) {
|
|
242
|
+
if (error === null || error === void 0) {
|
|
243
|
+
return [];
|
|
244
|
+
}
|
|
245
|
+
const lines = [`${indent}${error.type ?? "Error"}: ${error.message ?? "(no message)"}`];
|
|
246
|
+
const fieldErrors = Array.isArray(error.errors) ? error.errors : Object.entries(error.errors ?? {});
|
|
247
|
+
for (const [field, messages] of fieldErrors) {
|
|
248
|
+
for (const message of Array.isArray(messages) ? messages : [messages]) {
|
|
249
|
+
lines.push(`${indent} ${field}: ${message}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return lines;
|
|
253
|
+
}
|
|
254
|
+
function runLine(run) {
|
|
255
|
+
const trigger = run.trigger?.request_path ?? run.trigger?.type ?? "";
|
|
256
|
+
const status = run.response_status_code === null ? run.status : `${run.status} ${run.response_status_code}`;
|
|
257
|
+
return [run.started_at, status, run.path, trigger, runDuration(run), run.execution_id].filter((part) => part !== "").join(" ");
|
|
258
|
+
}
|
|
259
|
+
async function showLogs(args, { env, stdout, stderr }) {
|
|
260
|
+
const parsed = parseLogsArguments(args);
|
|
261
|
+
if (parsed.error !== void 0) {
|
|
262
|
+
stderr.write(`${parsed.error}
|
|
263
|
+
${LOGS_USAGE}
|
|
264
|
+
`);
|
|
265
|
+
return 2;
|
|
266
|
+
}
|
|
267
|
+
const target = credentials(env, stderr);
|
|
268
|
+
if (target === null) {
|
|
269
|
+
return 2;
|
|
270
|
+
}
|
|
271
|
+
if (parsed.execution !== null) {
|
|
272
|
+
const run = await request(
|
|
273
|
+
target,
|
|
274
|
+
"GET",
|
|
275
|
+
`/api/runtime/executions/${parsed.execution}`,
|
|
276
|
+
void 0,
|
|
277
|
+
stderr
|
|
278
|
+
);
|
|
279
|
+
if (run === null) {
|
|
280
|
+
return 1;
|
|
281
|
+
}
|
|
282
|
+
if (parsed.json) {
|
|
283
|
+
stdout.write(`${JSON.stringify(run, null, 2)}
|
|
284
|
+
`);
|
|
285
|
+
return 0;
|
|
286
|
+
}
|
|
287
|
+
stdout.write(`${runLine(run)}
|
|
288
|
+
`);
|
|
289
|
+
if (run.error !== null) {
|
|
290
|
+
stdout.write(`${JSON.stringify(run.error, null, 2)}
|
|
291
|
+
`);
|
|
292
|
+
} else if (run.output !== null) {
|
|
293
|
+
stdout.write(`${JSON.stringify(run.output, null, 2)}
|
|
294
|
+
`);
|
|
295
|
+
}
|
|
296
|
+
return 0;
|
|
297
|
+
}
|
|
298
|
+
const query = new URLSearchParams();
|
|
299
|
+
if (parsed.path !== null) {
|
|
300
|
+
query.set("workflow", parsed.path);
|
|
301
|
+
}
|
|
302
|
+
if (parsed.status !== null) {
|
|
303
|
+
query.set("status", parsed.status);
|
|
304
|
+
}
|
|
305
|
+
if (parsed.limit !== null) {
|
|
306
|
+
query.set("limit", String(parsed.limit));
|
|
307
|
+
}
|
|
308
|
+
const suffix = query.size === 0 ? "" : `?${query}`;
|
|
309
|
+
const body = await request(target, "GET", `/api/runtime/executions${suffix}`, void 0, stderr);
|
|
310
|
+
if (body === null) {
|
|
311
|
+
return 1;
|
|
312
|
+
}
|
|
313
|
+
if (parsed.json) {
|
|
314
|
+
stdout.write(`${JSON.stringify(body, null, 2)}
|
|
315
|
+
`);
|
|
316
|
+
return 0;
|
|
317
|
+
}
|
|
318
|
+
if (body.data.length === 0) {
|
|
319
|
+
stdout.write("No runs.\n");
|
|
320
|
+
return 0;
|
|
321
|
+
}
|
|
322
|
+
for (const run of [...body.data].reverse()) {
|
|
323
|
+
stdout.write(`${[runLine(run), ...errorLines(run.error, " ")].join("\n")}
|
|
324
|
+
`);
|
|
325
|
+
}
|
|
326
|
+
return 0;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// scripts/lib/runtime-build/assets-cli-usage.mjs
|
|
330
|
+
var ASSETS_UPLOAD_USAGE = "Usage: diagonal assets upload <file> [--key <key>] [--no-write] [--json]";
|
|
331
|
+
var ASSETS_LIST_USAGE = "Usage: diagonal assets list [--search <text>] [--versions] [--json]";
|
|
332
|
+
|
|
333
|
+
// scripts/lib/runtime-build/format-diagnostic.mjs
|
|
334
|
+
function formatDiagnostic(diagnostic) {
|
|
335
|
+
const [headline, ...details] = diagnostic.message.split("\n");
|
|
336
|
+
const lines = [
|
|
337
|
+
`${diagnostic.path}:${diagnostic.line}:${diagnostic.column} ${diagnostic.severity} ${headline}`
|
|
338
|
+
];
|
|
339
|
+
for (const detail of details) {
|
|
340
|
+
lines.push(` ${detail}`);
|
|
341
|
+
}
|
|
342
|
+
return lines.join("\n");
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export {
|
|
346
|
+
WORKFLOWS_USAGE,
|
|
347
|
+
RUN_USAGE,
|
|
348
|
+
LOGS_USAGE,
|
|
349
|
+
credentials,
|
|
350
|
+
errorText,
|
|
351
|
+
request,
|
|
352
|
+
parseFlags,
|
|
353
|
+
listWorkflows,
|
|
354
|
+
runWorkflow,
|
|
355
|
+
showLogs,
|
|
356
|
+
ASSETS_UPLOAD_USAGE,
|
|
357
|
+
ASSETS_LIST_USAGE,
|
|
358
|
+
formatDiagnostic
|
|
359
|
+
};
|