@fabraix/nyx 0.1.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.
- package/LICENSE +190 -0
- package/README.md +166 -0
- package/dist/api/client.d.ts +3 -0
- package/dist/api/client.js +67 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/stream.d.ts +9 -0
- package/dist/api/stream.js +86 -0
- package/dist/api/stream.js.map +1 -0
- package/dist/api/types.d.ts +64 -0
- package/dist/api/types.js +3 -0
- package/dist/api/types.js.map +1 -0
- package/dist/commands/cancel.d.ts +2 -0
- package/dist/commands/cancel.js +25 -0
- package/dist/commands/cancel.js.map +1 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.js +40 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.js +105 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +2 -0
- package/dist/commands/logout.js +23 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/report.d.ts +2 -0
- package/dist/commands/report.js +22 -0
- package/dist/commands/report.js.map +1 -0
- package/dist/commands/run.d.ts +2 -0
- package/dist/commands/run.js +50 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +61 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/config/auth.d.ts +8 -0
- package/dist/config/auth.js +30 -0
- package/dist/config/auth.js.map +1 -0
- package/dist/config/loader.d.ts +5 -0
- package/dist/config/loader.js +36 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/schema.d.ts +150 -0
- package/dist/config/schema.js +23 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/ui/renderer.d.ts +8 -0
- package/dist/ui/renderer.js +98 -0
- package/dist/ui/renderer.js.map +1 -0
- package/dist/ui/report-writer.d.ts +1 -0
- package/dist/ui/report-writer.js +20 -0
- package/dist/ui/report-writer.js.map +1 -0
- package/dist/utils/config-name.d.ts +1 -0
- package/dist/utils/config-name.js +4 -0
- package/dist/utils/config-name.js.map +1 -0
- package/dist/utils/errors.d.ts +7 -0
- package/dist/utils/errors.js +29 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +7 -0
- package/dist/version.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { apiRequest } from "../api/client.js";
|
|
3
|
+
import { handleError } from "../utils/errors.js";
|
|
4
|
+
export function registerList(program) {
|
|
5
|
+
program
|
|
6
|
+
.command("list")
|
|
7
|
+
.description("List recent runs")
|
|
8
|
+
.option("--status <status>", "Filter by status")
|
|
9
|
+
.option("--limit <n>", "Number of runs", "10")
|
|
10
|
+
.action(async (opts) => {
|
|
11
|
+
try {
|
|
12
|
+
const params = new URLSearchParams();
|
|
13
|
+
if (opts.status)
|
|
14
|
+
params.set("status", opts.status);
|
|
15
|
+
params.set("limit", opts.limit);
|
|
16
|
+
const data = await apiRequest("GET", `/v1/nyx/runs?${params.toString()}`);
|
|
17
|
+
if (data.runs.length === 0) {
|
|
18
|
+
console.log(chalk.dim("\n No runs found.\n"));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
console.log("");
|
|
22
|
+
for (const run of data.runs) {
|
|
23
|
+
const status = run.status === "running"
|
|
24
|
+
? chalk.cyan("running")
|
|
25
|
+
: run.result === "success"
|
|
26
|
+
? chalk.green("success")
|
|
27
|
+
: run.result === "exhausted"
|
|
28
|
+
? chalk.yellow("exhausted")
|
|
29
|
+
: chalk.dim(run.status);
|
|
30
|
+
console.log(` ${chalk.bold(run.config_name.padEnd(20))} ${status.padEnd(20)} ` +
|
|
31
|
+
`$${run.spent_usd.toFixed(2)}/$${run.budget_usd.toFixed(2)} ${run.run_id}`);
|
|
32
|
+
}
|
|
33
|
+
console.log(chalk.dim(`\n Showing ${data.runs.length} of ${data.total}\n`));
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
handleError(err);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,OAAO;SACJ,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,kBAAkB,CAAC;SAC/B,MAAM,CAAC,mBAAmB,EAAE,kBAAkB,CAAC;SAC/C,MAAM,CAAC,aAAa,EAAE,gBAAgB,EAAE,IAAI,CAAC;SAC7C,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACrB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;YACrC,IAAI,IAAI,CAAC,MAAM;gBAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YACnD,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;YAEhC,MAAM,IAAI,GAAG,MAAM,UAAU,CAC3B,KAAK,EACL,gBAAgB,MAAM,CAAC,QAAQ,EAAE,EAAE,CACpC,CAAC;YAEF,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC3B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,CAAC;gBAC/C,OAAO;YACT,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBAC5B,MAAM,MAAM,GACV,GAAG,CAAC,MAAM,KAAK,SAAS;oBACtB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;oBACvB,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS;wBACxB,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC;wBACxB,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,WAAW;4BAC1B,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC;4BAC3B,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBAEhC,OAAO,CAAC,GAAG,CACT,KAAK,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG;oBACjE,IAAI,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,MAAM,EAAE,CAC9E,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,GAAG,CAAC,eAAe,IAAI,CAAC,IAAI,CAAC,MAAM,OAAO,IAAI,CAAC,KAAK,IAAI,CAAC,CAChE,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import open from "open";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { saveCredentials } from "../config/auth.js";
|
|
5
|
+
import { apiRequest, getBaseUrl } from "../api/client.js";
|
|
6
|
+
import { NyxError, handleError } from "../utils/errors.js";
|
|
7
|
+
export function registerLogin(program) {
|
|
8
|
+
program
|
|
9
|
+
.command("login")
|
|
10
|
+
.description("Authenticate with Fabraix")
|
|
11
|
+
.option("--check", "Verify current authentication")
|
|
12
|
+
.action(async (opts) => {
|
|
13
|
+
try {
|
|
14
|
+
if (opts.check) {
|
|
15
|
+
await checkAuth();
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
await interactiveLogin();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
handleError(err);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async function checkAuth() {
|
|
27
|
+
const resp = await apiRequest("POST", "/v1/auth");
|
|
28
|
+
console.log(chalk.green("\n Authenticated"));
|
|
29
|
+
console.log(` Email: ${resp.account.email}`);
|
|
30
|
+
console.log(` Plan: ${resp.account.plan}`);
|
|
31
|
+
console.log(` Balance: $${resp.account.balance_usd.toFixed(2)}\n`);
|
|
32
|
+
}
|
|
33
|
+
async function interactiveLogin() {
|
|
34
|
+
const { port, codePromise, server } = startCallbackServer();
|
|
35
|
+
const loginUrl = `https://app.fabraix.com/auth/cli?port=${port}`;
|
|
36
|
+
console.log(chalk.dim(`\n Opening browser to: ${loginUrl}`));
|
|
37
|
+
console.log(chalk.dim(" Waiting for authentication...\n"));
|
|
38
|
+
await open(loginUrl);
|
|
39
|
+
let code;
|
|
40
|
+
try {
|
|
41
|
+
code = await codePromise;
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
server.close();
|
|
45
|
+
}
|
|
46
|
+
const baseUrl = getBaseUrl();
|
|
47
|
+
let res;
|
|
48
|
+
try {
|
|
49
|
+
res = await fetch(`${baseUrl}/v1/auth`, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
headers: { "Content-Type": "application/json" },
|
|
52
|
+
body: JSON.stringify({ code }),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
throw new NyxError(`Network error: could not reach ${baseUrl}. Check your internet connection.`, "network");
|
|
57
|
+
}
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
throw new NyxError("Login failed. Please try again.", "auth");
|
|
60
|
+
}
|
|
61
|
+
const data = (await res.json());
|
|
62
|
+
if (!data.token) {
|
|
63
|
+
throw new NyxError("Login failed: no token received.", "auth");
|
|
64
|
+
}
|
|
65
|
+
saveCredentials({
|
|
66
|
+
token: data.token,
|
|
67
|
+
email: data.account.email,
|
|
68
|
+
expires_at: data.expires_at,
|
|
69
|
+
});
|
|
70
|
+
console.log(chalk.green(" Logged in successfully!"));
|
|
71
|
+
console.log(` Email: ${data.account.email}\n`);
|
|
72
|
+
}
|
|
73
|
+
function startCallbackServer() {
|
|
74
|
+
let resolveCode;
|
|
75
|
+
let rejectCode;
|
|
76
|
+
const codePromise = new Promise((resolve, reject) => {
|
|
77
|
+
resolveCode = resolve;
|
|
78
|
+
rejectCode = reject;
|
|
79
|
+
});
|
|
80
|
+
const server = createServer((req, res) => {
|
|
81
|
+
const url = new URL(req.url, `http://localhost`);
|
|
82
|
+
const code = url.searchParams.get("code");
|
|
83
|
+
if (code) {
|
|
84
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
85
|
+
res.end("<html><body><h2>Authenticated! You can close this tab.</h2></body></html>");
|
|
86
|
+
resolveCode(code);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
res.writeHead(400, { "Content-Type": "text/plain" });
|
|
90
|
+
res.end("Missing code parameter");
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
server.on("error", (err) => {
|
|
94
|
+
rejectCode(new NyxError(`Failed to start login server: ${err.message}`, "network"));
|
|
95
|
+
});
|
|
96
|
+
server.listen(0);
|
|
97
|
+
const port = server.address().port;
|
|
98
|
+
const timeout = setTimeout(() => {
|
|
99
|
+
rejectCode(new NyxError("Login timed out. Please try again.", "auth"));
|
|
100
|
+
server.close();
|
|
101
|
+
}, 120_000);
|
|
102
|
+
codePromise.finally(() => clearTimeout(timeout));
|
|
103
|
+
return { port, codePromise, server };
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAG3D,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,2BAA2B,CAAC;SACxC,MAAM,CAAC,SAAS,EAAE,+BAA+B,CAAC;SAClD,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACrB,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,MAAM,SAAS,EAAE,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACN,MAAM,gBAAgB,EAAE,CAAC;YAC3B,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC;AAED,KAAK,UAAU,SAAS;IACtB,MAAM,IAAI,GAAG,MAAM,UAAU,CAAe,MAAM,EAAE,UAAU,CAAC,CAAC;IAChE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC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AC;YACpD,GAAG,CAAC,GAAG,CACL,2EAA2E,CAC5E,CAAC;YACF,WAAW,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAC;YACrD,GAAG,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACpC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACzB,UAAU,CACR,IAAI,QAAQ,CAAC,iCAAiC,GAAG,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CACxE,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACjB,MAAM,IAAI,GAAI,MAAM,CAAC,OAAO,EAAuB,CAAC,IAAI,CAAC;IAEzD,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;QAC9B,UAAU,CAAC,IAAI,QAAQ,CAAC,oCAAoC,EAAE,MAAM,CAAC,CAAC,CAAC;QACvE,MAAM,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC,EAAE,OAAO,CAAC,CAAC;IAEZ,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IAEjD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { removeCredentials } from "../config/auth.js";
|
|
3
|
+
import { handleError } from "../utils/errors.js";
|
|
4
|
+
export function registerLogout(program) {
|
|
5
|
+
program
|
|
6
|
+
.command("logout")
|
|
7
|
+
.description("Remove stored credentials")
|
|
8
|
+
.action(async () => {
|
|
9
|
+
try {
|
|
10
|
+
const removed = removeCredentials();
|
|
11
|
+
if (removed) {
|
|
12
|
+
console.log(chalk.green("\n Logged out. Credentials removed.\n"));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
console.log(chalk.dim("\n No stored credentials found.\n"));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
handleError(err);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=logout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout.js","sourceRoot":"","sources":["../../src/commands/logout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,2BAA2B,CAAC;SACxC,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;YACpC,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC,CAAC;YACrE,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { apiRequest } from "../api/client.js";
|
|
2
|
+
import { writeReport } from "../ui/report-writer.js";
|
|
3
|
+
import { handleError } from "../utils/errors.js";
|
|
4
|
+
import { resolveConfigName } from "../utils/config-name.js";
|
|
5
|
+
export function registerReport(program) {
|
|
6
|
+
program
|
|
7
|
+
.command("report <config>")
|
|
8
|
+
.description("Download audit report")
|
|
9
|
+
.option("--output <dir>", "Output directory", ".")
|
|
10
|
+
.action(async (configArg, opts) => {
|
|
11
|
+
try {
|
|
12
|
+
const configName = resolveConfigName(configArg);
|
|
13
|
+
const run = await apiRequest("GET", `/v1/nyx/runs/by-config/${encodeURIComponent(configName)}`);
|
|
14
|
+
const path = await writeReport(run.run_id, configName, opts.output);
|
|
15
|
+
console.log(`\n Report written to: ${path}\n`);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
handleError(err);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/commands/report.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,OAAO;SACJ,OAAO,CAAC,iBAAiB,CAAC;SAC1B,WAAW,CAAC,uBAAuB,CAAC;SACpC,MAAM,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,GAAG,CAAC;SACjD,MAAM,CAAC,KAAK,EAAE,SAAiB,EAAE,IAAI,EAAE,EAAE;QACxC,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAChD,MAAM,GAAG,GAAG,MAAM,UAAU,CAC1B,KAAK,EACL,0BAA0B,kBAAkB,CAAC,UAAU,CAAC,EAAE,CAC3D,CAAC;YAEF,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YACpE,OAAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,IAAI,CAAC,CAAC;QAClD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { loadConfig } from "../config/loader.js";
|
|
2
|
+
import { apiRequest } from "../api/client.js";
|
|
3
|
+
import { connectStream } from "../api/stream.js";
|
|
4
|
+
import { renderHeader, createStreamRenderer } from "../ui/renderer.js";
|
|
5
|
+
import { writeReport } from "../ui/report-writer.js";
|
|
6
|
+
import { handleError } from "../utils/errors.js";
|
|
7
|
+
export function registerRun(program) {
|
|
8
|
+
program
|
|
9
|
+
.command("run <config>")
|
|
10
|
+
.description("Run a security audit")
|
|
11
|
+
.option("--budget <n>", "Max spend in USD", parseFloat)
|
|
12
|
+
.option("--goal <level>", "AIVSS goal: low|medium|high|critical")
|
|
13
|
+
.option("--output <dir>", "Report output directory", ".")
|
|
14
|
+
.option("--no-stream", "Submit and exit without streaming")
|
|
15
|
+
.option("--verbose", "Show full transcripts")
|
|
16
|
+
.action(async (configArg, opts) => {
|
|
17
|
+
try {
|
|
18
|
+
const { config, configName } = loadConfig(configArg);
|
|
19
|
+
const budget = opts.budget ?? config.budget;
|
|
20
|
+
const goal = opts.goal ?? config.goal;
|
|
21
|
+
const submission = {
|
|
22
|
+
config_name: configName,
|
|
23
|
+
name: config.name,
|
|
24
|
+
target: config.target,
|
|
25
|
+
objective: config.objective,
|
|
26
|
+
budget_usd: budget,
|
|
27
|
+
severity_target: goal,
|
|
28
|
+
hints: config.hints,
|
|
29
|
+
};
|
|
30
|
+
const run = await apiRequest("POST", "/v1/nyx/runs", submission);
|
|
31
|
+
if (!opts.stream) {
|
|
32
|
+
console.log(`\n Run submitted: ${run.run_id}`);
|
|
33
|
+
console.log(` Check status: nyx status ${configName}\n`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
renderHeader(config, run, budget);
|
|
37
|
+
const result = await connectStream(run.stream_url, createStreamRenderer({
|
|
38
|
+
verbose: opts.verbose,
|
|
39
|
+
runId: run.run_id,
|
|
40
|
+
}));
|
|
41
|
+
if (result.reportUrl) {
|
|
42
|
+
await writeReport(run.run_id, configName, opts.output);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
handleError(err);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,OAAO;SACJ,OAAO,CAAC,cAAc,CAAC;SACvB,WAAW,CAAC,sBAAsB,CAAC;SACnC,MAAM,CAAC,cAAc,EAAE,kBAAkB,EAAE,UAAU,CAAC;SACtD,MAAM,CAAC,gBAAgB,EAAE,sCAAsC,CAAC;SAChE,MAAM,CAAC,gBAAgB,EAAE,yBAAyB,EAAE,GAAG,CAAC;SACxD,MAAM,CAAC,aAAa,EAAE,mCAAmC,CAAC;SAC1D,MAAM,CAAC,WAAW,EAAE,uBAAuB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,CAAC;YACzD,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { apiRequest } from "../api/client.js";
|
|
3
|
+
import { handleError } from "../utils/errors.js";
|
|
4
|
+
import { resolveConfigName } from "../utils/config-name.js";
|
|
5
|
+
export function registerStatus(program) {
|
|
6
|
+
program
|
|
7
|
+
.command("status <config>")
|
|
8
|
+
.description("Check status of a run")
|
|
9
|
+
.action(async (configArg) => {
|
|
10
|
+
try {
|
|
11
|
+
const name = resolveConfigName(configArg);
|
|
12
|
+
const run = await apiRequest("GET", `/v1/nyx/runs/by-config/${encodeURIComponent(name)}`);
|
|
13
|
+
console.log("");
|
|
14
|
+
console.log(` Config: ${run.config_name}`);
|
|
15
|
+
console.log(` Run ID: ${run.run_id}`);
|
|
16
|
+
console.log(` Target: ${run.name}`);
|
|
17
|
+
console.log(` Status: ${formatStatus(run)}`);
|
|
18
|
+
console.log(` Started: ${timeAgo(run.created_at)}`);
|
|
19
|
+
console.log(` Findings: ${run.findings_count} saved`);
|
|
20
|
+
console.log("");
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
handleError(err);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function formatStatus(run) {
|
|
28
|
+
if (run.status === "running") {
|
|
29
|
+
return `Running (attempt ${run.attempts_completed + 1}, $${run.spent_usd.toFixed(2)} / $${run.budget_usd.toFixed(2)} spent)`;
|
|
30
|
+
}
|
|
31
|
+
if (run.status === "queued") {
|
|
32
|
+
return chalk.dim("Queued");
|
|
33
|
+
}
|
|
34
|
+
if (run.status === "completed" && run.result === "success") {
|
|
35
|
+
return chalk.green("Completed — vulnerability found");
|
|
36
|
+
}
|
|
37
|
+
if (run.status === "completed" && run.result === "exhausted") {
|
|
38
|
+
return chalk.yellow("Completed — budget exhausted");
|
|
39
|
+
}
|
|
40
|
+
if (run.status === "failed") {
|
|
41
|
+
return chalk.red("Failed");
|
|
42
|
+
}
|
|
43
|
+
if (run.status === "cancelled") {
|
|
44
|
+
return chalk.dim("Cancelled");
|
|
45
|
+
}
|
|
46
|
+
return run.status;
|
|
47
|
+
}
|
|
48
|
+
function timeAgo(iso) {
|
|
49
|
+
const diff = Date.now() - new Date(iso).getTime();
|
|
50
|
+
const mins = Math.floor(diff / 60_000);
|
|
51
|
+
if (mins < 1)
|
|
52
|
+
return "just now";
|
|
53
|
+
if (mins < 60)
|
|
54
|
+
return `${mins} minute${mins === 1 ? "" : "s"} ago`;
|
|
55
|
+
const hours = Math.floor(mins / 60);
|
|
56
|
+
if (hours < 24)
|
|
57
|
+
return `${hours} hour${hours === 1 ? "" : "s"} ago`;
|
|
58
|
+
const days = Math.floor(hours / 24);
|
|
59
|
+
return `${days} day${days === 1 ? "" : "s"} ago`;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,OAAO;SACJ,OAAO,CAAC,iBAAiB,CAAC;SAC1B,WAAW,CAAC,uBAAuB,CAAC;SACpC,MAAM,CAAC,KAAK,EAAE,SAAiB,EAAE,EAAE;QAClC,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAC1C,MAAM,GAAG,GAAG,MAA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EAAE,CAAC,CAAC;IACpC,OAAO,GAAG,IAAI,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface StoredCredentials {
|
|
2
|
+
token: string;
|
|
3
|
+
email?: string;
|
|
4
|
+
expires_at?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function getToken(): string | null;
|
|
7
|
+
export declare function saveCredentials(creds: StoredCredentials): void;
|
|
8
|
+
export declare function removeCredentials(): boolean;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, mkdirSync, unlinkSync, existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
const NYX_DIR = join(homedir(), ".nyx");
|
|
5
|
+
const CRED_FILE = join(NYX_DIR, "credentials.json");
|
|
6
|
+
export function getToken() {
|
|
7
|
+
const envToken = process.env.NYX_TOKEN;
|
|
8
|
+
if (envToken)
|
|
9
|
+
return envToken;
|
|
10
|
+
if (!existsSync(CRED_FILE))
|
|
11
|
+
return null;
|
|
12
|
+
try {
|
|
13
|
+
const data = JSON.parse(readFileSync(CRED_FILE, "utf-8"));
|
|
14
|
+
return data.token || null;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function saveCredentials(creds) {
|
|
21
|
+
mkdirSync(NYX_DIR, { recursive: true });
|
|
22
|
+
writeFileSync(CRED_FILE, JSON.stringify(creds, null, 2) + "\n", { mode: 0o600 });
|
|
23
|
+
}
|
|
24
|
+
export function removeCredentials() {
|
|
25
|
+
if (!existsSync(CRED_FILE))
|
|
26
|
+
return false;
|
|
27
|
+
unlinkSync(CRED_FILE);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=auth.js.map
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C;IACzC,UAAU,CAAC,SAAS,CAAC,CAAC;IACtB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { parse as parseYaml } from "yaml";
|
|
4
|
+
import { configSchema } from "./schema.js";
|
|
5
|
+
import { resolveConfigName } from "../utils/config-name.js";
|
|
6
|
+
import { NyxError } from "../utils/errors.js";
|
|
7
|
+
export function loadConfig(name) {
|
|
8
|
+
const configName = resolveConfigName(name);
|
|
9
|
+
const candidates = [
|
|
10
|
+
resolve(`${configName}.yaml`),
|
|
11
|
+
resolve(`${configName}.yml`),
|
|
12
|
+
resolve(name),
|
|
13
|
+
];
|
|
14
|
+
const filePath = candidates.find(existsSync);
|
|
15
|
+
if (!filePath) {
|
|
16
|
+
throw new NyxError(`Config file not found: ${configName}.yaml\n` +
|
|
17
|
+
` Create a YAML config file. See: https://docs.fabraix.com/nyx/config`, "config");
|
|
18
|
+
}
|
|
19
|
+
let raw;
|
|
20
|
+
try {
|
|
21
|
+
const content = readFileSync(filePath, "utf-8");
|
|
22
|
+
raw = parseYaml(content);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
throw new NyxError(`Failed to parse ${filePath}: ${err.message}`, "config");
|
|
26
|
+
}
|
|
27
|
+
const result = configSchema.safeParse(raw);
|
|
28
|
+
if (!result.success) {
|
|
29
|
+
const issues = result.error.issues
|
|
30
|
+
.map((i) => ` - ${i.path.join(".")}: ${i.message}`)
|
|
31
|
+
.join("\n");
|
|
32
|
+
throw new NyxError(`Invalid config in ${filePath}:\n${issues}`, "config");
|
|
33
|
+
}
|
|
34
|
+
return { config: result.data, configName };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],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AAG,MAAM,CAAC,KAAK,CAAC,MAAM;aAC/B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;aACnD,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,IAAI,QAAQ,CAAC,qBAAqB,QAAQ,MAAM,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const configSchema: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
target: z.ZodObject<{
|
|
5
|
+
base_url: z.ZodString;
|
|
6
|
+
protocol: z.ZodObject<{
|
|
7
|
+
create_session: z.ZodObject<{
|
|
8
|
+
method: z.ZodEnum<["GET", "POST", "PUT", "PATCH", "DELETE"]>;
|
|
9
|
+
path: z.ZodString;
|
|
10
|
+
body: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
11
|
+
response: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
14
|
+
path: string;
|
|
15
|
+
body?: Record<string, unknown> | undefined;
|
|
16
|
+
response?: Record<string, string> | undefined;
|
|
17
|
+
}, {
|
|
18
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
19
|
+
path: string;
|
|
20
|
+
body?: Record<string, unknown> | undefined;
|
|
21
|
+
response?: Record<string, string> | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
send_message: z.ZodObject<{
|
|
24
|
+
method: z.ZodEnum<["GET", "POST", "PUT", "PATCH", "DELETE"]>;
|
|
25
|
+
path: z.ZodString;
|
|
26
|
+
body: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
27
|
+
response: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
30
|
+
path: string;
|
|
31
|
+
body?: Record<string, unknown> | undefined;
|
|
32
|
+
response?: Record<string, string> | undefined;
|
|
33
|
+
}, {
|
|
34
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
35
|
+
path: string;
|
|
36
|
+
body?: Record<string, unknown> | undefined;
|
|
37
|
+
response?: Record<string, string> | undefined;
|
|
38
|
+
}>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
create_session: {
|
|
41
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
42
|
+
path: string;
|
|
43
|
+
body?: Record<string, unknown> | undefined;
|
|
44
|
+
response?: Record<string, string> | undefined;
|
|
45
|
+
};
|
|
46
|
+
send_message: {
|
|
47
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
48
|
+
path: string;
|
|
49
|
+
body?: Record<string, unknown> | undefined;
|
|
50
|
+
response?: Record<string, string> | undefined;
|
|
51
|
+
};
|
|
52
|
+
}, {
|
|
53
|
+
create_session: {
|
|
54
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
55
|
+
path: string;
|
|
56
|
+
body?: Record<string, unknown> | undefined;
|
|
57
|
+
response?: Record<string, string> | undefined;
|
|
58
|
+
};
|
|
59
|
+
send_message: {
|
|
60
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
61
|
+
path: string;
|
|
62
|
+
body?: Record<string, unknown> | undefined;
|
|
63
|
+
response?: Record<string, string> | undefined;
|
|
64
|
+
};
|
|
65
|
+
}>;
|
|
66
|
+
}, "strip", z.ZodTypeAny, {
|
|
67
|
+
base_url: string;
|
|
68
|
+
protocol: {
|
|
69
|
+
create_session: {
|
|
70
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
71
|
+
path: string;
|
|
72
|
+
body?: Record<string, unknown> | undefined;
|
|
73
|
+
response?: Record<string, string> | undefined;
|
|
74
|
+
};
|
|
75
|
+
send_message: {
|
|
76
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
77
|
+
path: string;
|
|
78
|
+
body?: Record<string, unknown> | undefined;
|
|
79
|
+
response?: Record<string, string> | undefined;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
}, {
|
|
83
|
+
base_url: string;
|
|
84
|
+
protocol: {
|
|
85
|
+
create_session: {
|
|
86
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
87
|
+
path: string;
|
|
88
|
+
body?: Record<string, unknown> | undefined;
|
|
89
|
+
response?: Record<string, string> | undefined;
|
|
90
|
+
};
|
|
91
|
+
send_message: {
|
|
92
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
93
|
+
path: string;
|
|
94
|
+
body?: Record<string, unknown> | undefined;
|
|
95
|
+
response?: Record<string, string> | undefined;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
}>;
|
|
99
|
+
objective: z.ZodString;
|
|
100
|
+
budget: z.ZodDefault<z.ZodNumber>;
|
|
101
|
+
goal: z.ZodDefault<z.ZodEnum<["low", "medium", "high", "critical"]>>;
|
|
102
|
+
hints: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
103
|
+
}, "strip", z.ZodTypeAny, {
|
|
104
|
+
name: string;
|
|
105
|
+
target: {
|
|
106
|
+
base_url: string;
|
|
107
|
+
protocol: {
|
|
108
|
+
create_session: {
|
|
109
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
110
|
+
path: string;
|
|
111
|
+
body?: Record<string, unknown> | undefined;
|
|
112
|
+
response?: Record<string, string> | undefined;
|
|
113
|
+
};
|
|
114
|
+
send_message: {
|
|
115
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
116
|
+
path: string;
|
|
117
|
+
body?: Record<string, unknown> | undefined;
|
|
118
|
+
response?: Record<string, string> | undefined;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
objective: string;
|
|
123
|
+
budget: number;
|
|
124
|
+
goal: "low" | "medium" | "high" | "critical";
|
|
125
|
+
hints?: string[] | undefined;
|
|
126
|
+
}, {
|
|
127
|
+
name: string;
|
|
128
|
+
target: {
|
|
129
|
+
base_url: string;
|
|
130
|
+
protocol: {
|
|
131
|
+
create_session: {
|
|
132
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
133
|
+
path: string;
|
|
134
|
+
body?: Record<string, unknown> | undefined;
|
|
135
|
+
response?: Record<string, string> | undefined;
|
|
136
|
+
};
|
|
137
|
+
send_message: {
|
|
138
|
+
method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
139
|
+
path: string;
|
|
140
|
+
body?: Record<string, unknown> | undefined;
|
|
141
|
+
response?: Record<string, string> | undefined;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
objective: string;
|
|
146
|
+
budget?: number | undefined;
|
|
147
|
+
goal?: "low" | "medium" | "high" | "critical" | undefined;
|
|
148
|
+
hints?: string[] | undefined;
|
|
149
|
+
}>;
|
|
150
|
+
export type NyxConfig = z.infer<typeof configSchema>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const protocolEndpoint = z.object({
|
|
3
|
+
method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]),
|
|
4
|
+
path: z.string(),
|
|
5
|
+
body: z.record(z.unknown()).optional(),
|
|
6
|
+
response: z.record(z.string()).optional(),
|
|
7
|
+
});
|
|
8
|
+
const target = z.object({
|
|
9
|
+
base_url: z.string().url("target.base_url must be a valid URL"),
|
|
10
|
+
protocol: z.object({
|
|
11
|
+
create_session: protocolEndpoint,
|
|
12
|
+
send_message: protocolEndpoint,
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
15
|
+
export const configSchema = z.object({
|
|
16
|
+
name: z.string().min(1, "name is required"),
|
|
17
|
+
target,
|
|
18
|
+
objective: z.string().min(1, "objective is required"),
|
|
19
|
+
budget: z.number().positive().default(5),
|
|
20
|
+
goal: z.enum(["low", "medium", "high", "critical"]).default("medium"),
|
|
21
|
+
hints: z.array(z.string()).optional(),
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/config/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;IACtC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;CAC1C,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,qCAAqC,CAAC;IAC/D,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;QACjB,cAAc,EAAE,gBAAgB;QAChC,YAAY,EAAE,gBAAgB;KAC/B,CAAC;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