@kubb/cli 4.37.11 → 4.38.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 +17 -10
- package/dist/{constants-CM3dJzjK.js → constants-CR-BDIf6.js} +2 -11
- package/dist/constants-CR-BDIf6.js.map +1 -0
- package/dist/{constants-BTUap0zs.cjs → constants-DYL5YQqt.cjs} +1 -16
- package/dist/constants-DYL5YQqt.cjs.map +1 -0
- package/dist/{generate-CBD-ZbZu.cjs → generate-BKFQErdj.cjs} +4 -4
- package/dist/{generate-CBD-ZbZu.cjs.map → generate-BKFQErdj.cjs.map} +1 -1
- package/dist/{generate-BjksloS3.js → generate-CzGZWR26.js} +2 -2
- package/dist/{generate-BjksloS3.js.map → generate-CzGZWR26.js.map} +1 -1
- package/dist/{generate-CD19XWmg.js → generate-D9WGRoua.js} +4 -4
- package/dist/{generate-CD19XWmg.js.map → generate-D9WGRoua.js.map} +1 -1
- package/dist/{generate-CxI7VjlX.cjs → generate-Dk-uEljm.cjs} +2 -2
- package/dist/{generate-CxI7VjlX.cjs.map → generate-Dk-uEljm.cjs.map} +1 -1
- package/dist/index.cjs +7 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -9
- package/dist/index.js.map +1 -1
- package/dist/{init-hmolV6B4.cjs → init-BaM_F3d_.cjs} +2 -3
- package/dist/{init-hmolV6B4.cjs.map → init-BaM_F3d_.cjs.map} +1 -1
- package/dist/{init-CwBkr0OO.cjs → init-BppS7lGq.cjs} +3 -3
- package/dist/{init-CwBkr0OO.cjs.map → init-BppS7lGq.cjs.map} +1 -1
- package/dist/{init-C-InrmSY.js → init-Cf6fA41K.js} +2 -3
- package/dist/{init-C-InrmSY.js.map → init-Cf6fA41K.js.map} +1 -1
- package/dist/{init-BhDyPP6M.js → init-DrFtOgvZ.js} +3 -3
- package/dist/{init-BhDyPP6M.js.map → init-DrFtOgvZ.js.map} +1 -1
- package/dist/{jiti-e08mD2Ph.js → jiti-D5qMw1UC.js} +1 -1
- package/dist/{jiti-e08mD2Ph.js.map → jiti-D5qMw1UC.js.map} +1 -1
- package/dist/{jiti-Cd3S0xwr.cjs → jiti-EgzFa-0e.cjs} +1 -1
- package/dist/{jiti-Cd3S0xwr.cjs.map → jiti-EgzFa-0e.cjs.map} +1 -1
- package/dist/{mcp-BKLBwnwB.cjs → mcp-34XslSuW.cjs} +3 -3
- package/dist/{mcp-BKLBwnwB.cjs.map → mcp-34XslSuW.cjs.map} +1 -1
- package/dist/{mcp-X8kKSlov.cjs → mcp-CFaF2OMK.cjs} +3 -3
- package/dist/{mcp-X8kKSlov.cjs.map → mcp-CFaF2OMK.cjs.map} +1 -1
- package/dist/{mcp-Cwbv3dfC.js → mcp-Cc7G7a6r.js} +3 -3
- package/dist/{mcp-Cwbv3dfC.js.map → mcp-Cc7G7a6r.js.map} +1 -1
- package/dist/{mcp-rCGsuaWb.js → mcp-DaK3ey7W.js} +3 -3
- package/dist/{mcp-rCGsuaWb.js.map → mcp-DaK3ey7W.js.map} +1 -1
- package/dist/{package-CXinXKRX.cjs → package-Bri2J9tx.cjs} +2 -2
- package/dist/package-Bri2J9tx.cjs.map +1 -0
- package/dist/package-CKHXivYd.js +6 -0
- package/dist/package-CKHXivYd.js.map +1 -0
- package/dist/{telemetry-CEm85k_X.cjs → telemetry-Cj4VP-SC.cjs} +2 -2
- package/dist/{telemetry-CEm85k_X.cjs.map → telemetry-Cj4VP-SC.cjs.map} +1 -1
- package/dist/{telemetry-CHWsjyeK.js → telemetry-DTy9TjCN.js} +2 -2
- package/dist/{telemetry-CHWsjyeK.js.map → telemetry-DTy9TjCN.js.map} +1 -1
- package/dist/{validate-DYVo8-Fj.cjs → validate-CBVnOSEe.cjs} +3 -3
- package/dist/{validate-DYVo8-Fj.cjs.map → validate-CBVnOSEe.cjs.map} +1 -1
- package/dist/{validate-DDEzYbDZ.js → validate-Cc7mwoms.js} +3 -3
- package/dist/{validate-DDEzYbDZ.js.map → validate-Cc7mwoms.js.map} +1 -1
- package/dist/{validate-BGyxLev8.js → validate-Cn4KXS03.js} +3 -3
- package/dist/{validate-BGyxLev8.js.map → validate-Cn4KXS03.js.map} +1 -1
- package/dist/{validate-CtZ5uwEZ.cjs → validate-VSgcmd7F.cjs} +3 -3
- package/dist/{validate-CtZ5uwEZ.cjs.map → validate-VSgcmd7F.cjs.map} +1 -1
- package/package.json +4 -5
- package/src/constants.ts +0 -11
- package/src/index.ts +7 -9
- package/src/runners/init.ts +1 -1
- package/dist/agent-BaRFyk6N.cjs +0 -58
- package/dist/agent-BaRFyk6N.cjs.map +0 -1
- package/dist/agent-D_JDFk_t.js +0 -56
- package/dist/agent-D_JDFk_t.js.map +0 -1
- package/dist/agent-bJ5FNFnA.cjs +0 -92
- package/dist/agent-bJ5FNFnA.cjs.map +0 -1
- package/dist/agent-fcClds-t.js +0 -88
- package/dist/agent-fcClds-t.js.map +0 -1
- package/dist/constants-BTUap0zs.cjs.map +0 -1
- package/dist/constants-CM3dJzjK.js.map +0 -1
- package/dist/package-CXinXKRX.cjs.map +0 -1
- package/dist/package-DOoCSchC.js +0 -6
- package/dist/package-DOoCSchC.js.map +0 -1
- package/src/commands/agent/start.ts +0 -31
- package/src/commands/agent.ts +0 -8
- package/src/runners/agent.ts +0 -102
package/dist/agent-bJ5FNFnA.cjs
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
2
|
-
const require_telemetry = require("./telemetry-CEm85k_X.cjs");
|
|
3
|
-
const require_shell = require("./shell-7HPrTCJ5.cjs");
|
|
4
|
-
const require_constants = require("./constants-BTUap0zs.cjs");
|
|
5
|
-
let node_util = require("node:util");
|
|
6
|
-
let node_path = require("node:path");
|
|
7
|
-
node_path = require_chunk.__toESM(node_path);
|
|
8
|
-
let node_process = require("node:process");
|
|
9
|
-
node_process = require_chunk.__toESM(node_process);
|
|
10
|
-
let node_net = require("node:net");
|
|
11
|
-
node_net = require_chunk.__toESM(node_net);
|
|
12
|
-
let node_url = require("node:url");
|
|
13
|
-
let _clack_prompts = require("@clack/prompts");
|
|
14
|
-
_clack_prompts = require_chunk.__toESM(_clack_prompts);
|
|
15
|
-
//#region src/runners/agent.ts
|
|
16
|
-
function isPortAvailable(port, host) {
|
|
17
|
-
return new Promise((resolve) => {
|
|
18
|
-
const server = node_net.default.createServer();
|
|
19
|
-
server.once("error", () => resolve(false));
|
|
20
|
-
server.once("listening", () => {
|
|
21
|
-
server.close();
|
|
22
|
-
resolve(true);
|
|
23
|
-
});
|
|
24
|
-
server.listen(port, host);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }) {
|
|
28
|
-
const hrStart = node_process.hrtime();
|
|
29
|
-
try {
|
|
30
|
-
try {
|
|
31
|
-
node_process.loadEnvFile();
|
|
32
|
-
} catch {}
|
|
33
|
-
const agentPkgPath = (0, node_url.fileURLToPath)({}.resolve("@kubb/agent/package.json"));
|
|
34
|
-
const agentDir = node_path.default.dirname(agentPkgPath);
|
|
35
|
-
const serverPath = node_path.default.join(agentDir, require_constants.agentDefaults.serverEntryPath);
|
|
36
|
-
const PORT = port !== void 0 ? port : node_process.env.PORT ?? require_constants.agentDefaults.port;
|
|
37
|
-
const HOST = host !== require_constants.agentDefaults.host ? host : node_process.env.HOST ?? require_constants.agentDefaults.host;
|
|
38
|
-
const KUBB_AGENT_ROOT = node_process.env.KUBB_AGENT_ROOT ?? node_process.cwd();
|
|
39
|
-
const KUBB_AGENT_CONFIG = node_path.default.resolve(node_process.cwd(), configPath || node_process.env.KUBB_AGENT_CONFIG || require_constants.agentDefaults.configFile);
|
|
40
|
-
const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? "true" : node_process.env.KUBB_AGENT_ALLOW_WRITE ?? "false";
|
|
41
|
-
const KUBB_AGENT_ALLOW_ALL = allowAll ? "true" : node_process.env.KUBB_AGENT_ALLOW_ALL ?? "false";
|
|
42
|
-
const KUBB_AGENT_TOKEN = node_process.env.KUBB_AGENT_TOKEN;
|
|
43
|
-
const KUBB_AGENT_RETRY_TIMEOUT = node_process.env.KUBB_AGENT_RETRY_TIMEOUT ?? require_constants.agentDefaults.retryTimeout;
|
|
44
|
-
const KUBB_STUDIO_URL = node_process.env.KUBB_STUDIO_URL ?? require_constants.agentDefaults.studioUrl;
|
|
45
|
-
const env = {
|
|
46
|
-
...node_process.env,
|
|
47
|
-
PORT,
|
|
48
|
-
HOST,
|
|
49
|
-
KUBB_AGENT_ROOT,
|
|
50
|
-
KUBB_AGENT_CONFIG,
|
|
51
|
-
KUBB_AGENT_ALLOW_WRITE,
|
|
52
|
-
KUBB_AGENT_ALLOW_ALL,
|
|
53
|
-
KUBB_AGENT_TOKEN,
|
|
54
|
-
KUBB_AGENT_RETRY_TIMEOUT,
|
|
55
|
-
KUBB_STUDIO_URL
|
|
56
|
-
};
|
|
57
|
-
_clack_prompts.log.step((0, node_util.styleText)("cyan", "Starting agent server..."));
|
|
58
|
-
_clack_prompts.log.info((0, node_util.styleText)("dim", `Config: ${KUBB_AGENT_CONFIG}`));
|
|
59
|
-
_clack_prompts.log.info((0, node_util.styleText)("dim", `Host: ${HOST}`));
|
|
60
|
-
_clack_prompts.log.info((0, node_util.styleText)("dim", `Port: ${PORT}`));
|
|
61
|
-
if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) _clack_prompts.log.warn((0, node_util.styleText)("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
|
|
62
|
-
if (!await isPortAvailable(Number(PORT), HOST)) {
|
|
63
|
-
_clack_prompts.log.error((0, node_util.styleText)("red", `Port ${PORT} is already in use. Stop the existing process or choose a different port with --port.`));
|
|
64
|
-
node_process.exit(1);
|
|
65
|
-
}
|
|
66
|
-
console.log(env);
|
|
67
|
-
await require_shell.spawnAsync("node", [serverPath], {
|
|
68
|
-
env,
|
|
69
|
-
cwd: node_process.cwd()
|
|
70
|
-
});
|
|
71
|
-
await require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
|
|
72
|
-
command: "agent",
|
|
73
|
-
kubbVersion: version,
|
|
74
|
-
hrStart,
|
|
75
|
-
status: "success"
|
|
76
|
-
}));
|
|
77
|
-
} catch (error) {
|
|
78
|
-
await require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
|
|
79
|
-
command: "agent",
|
|
80
|
-
kubbVersion: version,
|
|
81
|
-
hrStart,
|
|
82
|
-
status: "failed"
|
|
83
|
-
}));
|
|
84
|
-
_clack_prompts.log.error((0, node_util.styleText)("red", "Failed to start agent server"));
|
|
85
|
-
console.error(error);
|
|
86
|
-
node_process.exit(1);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
//#endregion
|
|
90
|
-
exports.runAgentStart = runAgentStart;
|
|
91
|
-
|
|
92
|
-
//# sourceMappingURL=agent-bJ5FNFnA.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-bJ5FNFnA.cjs","names":["net","process","path","agentDefaults","spawnAsync","sendTelemetry","buildTelemetryEvent"],"sources":["../src/runners/agent.ts"],"sourcesContent":["import net from 'node:net'\nimport path from 'node:path'\nimport * as process from 'node:process'\nimport { fileURLToPath } from 'node:url'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { spawnAsync } from '@internals/utils'\nimport { agentDefaults } from '../constants.ts'\nimport { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'\n\ntype AgentStartOptions = {\n port: string | undefined\n host: string\n configPath: string | undefined\n allowWrite: boolean\n allowAll: boolean\n version: string\n}\n\nfunction isPortAvailable(port: number, host: string): Promise<boolean> {\n return new Promise((resolve) => {\n const server = net.createServer()\n server.once('error', () => resolve(false))\n server.once('listening', () => {\n server.close()\n resolve(true)\n })\n server.listen(port, host)\n })\n}\n\nexport async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {\n const hrStart = process.hrtime()\n\n try {\n // Load .env file into process.env using Node.js built-in (v20.12.0+)\n try {\n process.loadEnvFile()\n } catch {\n // .env file may not exist; ignore\n }\n\n // Resolve the @kubb/agent package path\n const agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')\n const agentPkgPath = fileURLToPath(agentPkgUrl)\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n // CLI params take priority over process.env; process.env fills in what the CLI didn't specify;\n // agentDefaults are the last resort. Build env as: defaults ← process.env ← CLI.\n const PORT = port !== undefined ? port : (process.env.PORT ?? agentDefaults.port)\n const HOST = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)\n const KUBB_AGENT_ROOT = process.env.KUBB_AGENT_ROOT ?? process.cwd()\n const KUBB_AGENT_CONFIG = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)\n const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? 'true' : (process.env.KUBB_AGENT_ALLOW_WRITE ?? 'false')\n const KUBB_AGENT_ALLOW_ALL = allowAll ? 'true' : (process.env.KUBB_AGENT_ALLOW_ALL ?? 'false')\n const KUBB_AGENT_TOKEN = process.env.KUBB_AGENT_TOKEN\n const KUBB_AGENT_RETRY_TIMEOUT = process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout\n const KUBB_STUDIO_URL = process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl\n\n const env = {\n ...process.env,\n PORT,\n HOST,\n KUBB_AGENT_ROOT,\n KUBB_AGENT_CONFIG,\n KUBB_AGENT_ALLOW_WRITE,\n KUBB_AGENT_ALLOW_ALL,\n KUBB_AGENT_TOKEN,\n KUBB_AGENT_RETRY_TIMEOUT,\n KUBB_STUDIO_URL,\n }\n\n clack.log.step(styleText('cyan', 'Starting agent server...'))\n clack.log.info(styleText('dim', `Config: ${KUBB_AGENT_CONFIG}`))\n clack.log.info(styleText('dim', `Host: ${HOST}`))\n clack.log.info(styleText('dim', `Port: ${PORT}`))\n if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) {\n clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))\n }\n\n if (!(await isPortAvailable(Number(PORT), HOST))) {\n clack.log.error(styleText('red', `Port ${PORT} is already in use. Stop the existing process or choose a different port with --port.`))\n process.exit(1)\n }\n\n console.log(env)\n\n // Spawns the server as a detached background process so the CLI can exit independently.\n await spawnAsync('node', [serverPath], {\n env,\n cwd: process.cwd(),\n })\n\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'success' }))\n } catch (error) {\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'failed' }))\n clack.log.error(styleText('red', 'Failed to start agent server'))\n console.error(error)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAS,gBAAgB,MAAc,MAAgC;AACrE,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,SAASA,SAAAA,QAAI,cAAc;AACjC,SAAO,KAAK,eAAe,QAAQ,MAAM,CAAC;AAC1C,SAAO,KAAK,mBAAmB;AAC7B,UAAO,OAAO;AACd,WAAQ,KAAK;IACb;AACF,SAAO,OAAO,MAAM,KAAK;GACzB;;AAGJ,eAAsB,cAAc,EAAE,MAAM,MAAM,YAAY,YAAY,UAAU,WAA6C;CAC/H,MAAM,UAAUC,aAAQ,QAAQ;AAEhC,KAAI;AAEF,MAAI;AACF,gBAAQ,aAAa;UACf;EAMR,MAAM,gBAAA,GAAA,SAAA,eAAA,EAAA,CAD0B,QAAQ,2BAA2B,CACpB;EAC/C,MAAM,WAAWC,UAAAA,QAAK,QAAQ,aAAa;EAC3C,MAAM,aAAaA,UAAAA,QAAK,KAAK,UAAUC,kBAAAA,cAAc,gBAAgB;EAIrE,MAAM,OAAO,SAAS,KAAA,IAAY,OAAQF,aAAQ,IAAI,QAAQE,kBAAAA,cAAc;EAC5E,MAAM,OAAO,SAASA,kBAAAA,cAAc,OAAO,OAAQF,aAAQ,IAAI,QAAQE,kBAAAA,cAAc;EACrF,MAAM,kBAAkBF,aAAQ,IAAI,mBAAmBA,aAAQ,KAAK;EACpE,MAAM,oBAAoBC,UAAAA,QAAK,QAAQD,aAAQ,KAAK,EAAE,cAAcA,aAAQ,IAAI,qBAAqBE,kBAAAA,cAAc,WAAW;EAC9H,MAAM,yBAAyB,YAAY,aAAa,SAAUF,aAAQ,IAAI,0BAA0B;EACxG,MAAM,uBAAuB,WAAW,SAAUA,aAAQ,IAAI,wBAAwB;EACtF,MAAM,mBAAmBA,aAAQ,IAAI;EACrC,MAAM,2BAA2BA,aAAQ,IAAI,4BAA4BE,kBAAAA,cAAc;EACvF,MAAM,kBAAkBF,aAAQ,IAAI,mBAAmBE,kBAAAA,cAAc;EAErE,MAAM,MAAM;GACV,GAAGF,aAAQ;GACX;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD;AAED,iBAAM,IAAI,MAAA,GAAA,UAAA,WAAe,QAAQ,2BAA2B,CAAC;AAC7D,iBAAM,IAAI,MAAA,GAAA,UAAA,WAAe,OAAO,WAAW,oBAAoB,CAAC;AAChE,iBAAM,IAAI,MAAA,GAAA,UAAA,WAAe,OAAO,SAAS,OAAO,CAAC;AACjD,iBAAM,IAAI,MAAA,GAAA,UAAA,WAAe,OAAO,SAAS,OAAO,CAAC;AACjD,MAAI,CAAC,0BAA0B,CAAC,qBAC9B,gBAAM,IAAI,MAAA,GAAA,UAAA,WAAe,UAAU,0EAA0E,CAAC;AAGhH,MAAI,CAAE,MAAM,gBAAgB,OAAO,KAAK,EAAE,KAAK,EAAG;AAChD,kBAAM,IAAI,OAAA,GAAA,UAAA,WAAgB,OAAO,QAAQ,KAAK,uFAAuF,CAAC;AACtI,gBAAQ,KAAK,EAAE;;AAGjB,UAAQ,IAAI,IAAI;AAGhB,QAAMG,cAAAA,WAAW,QAAQ,CAAC,WAAW,EAAE;GACrC;GACA,KAAKH,aAAQ,KAAK;GACnB,CAAC;AAEF,QAAMI,kBAAAA,cAAcC,kBAAAA,oBAAoB;GAAE,SAAS;GAAS,aAAa;GAAS;GAAS,QAAQ;GAAW,CAAC,CAAC;UACzG,OAAO;AACd,QAAMD,kBAAAA,cAAcC,kBAAAA,oBAAoB;GAAE,SAAS;GAAS,aAAa;GAAS;GAAS,QAAQ;GAAU,CAAC,CAAC;AAC/G,iBAAM,IAAI,OAAA,GAAA,UAAA,WAAgB,OAAO,+BAA+B,CAAC;AACjE,UAAQ,MAAM,MAAM;AACpB,eAAQ,KAAK,EAAE"}
|
package/dist/agent-fcClds-t.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-CHWsjyeK.js";
|
|
3
|
-
import { t as spawnAsync } from "./shell-DqqWsHCD.js";
|
|
4
|
-
import { a as agentDefaults } from "./constants-CM3dJzjK.js";
|
|
5
|
-
import { styleText } from "node:util";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import * as process$1 from "node:process";
|
|
8
|
-
import net from "node:net";
|
|
9
|
-
import { fileURLToPath } from "node:url";
|
|
10
|
-
import * as clack from "@clack/prompts";
|
|
11
|
-
//#region src/runners/agent.ts
|
|
12
|
-
function isPortAvailable(port, host) {
|
|
13
|
-
return new Promise((resolve) => {
|
|
14
|
-
const server = net.createServer();
|
|
15
|
-
server.once("error", () => resolve(false));
|
|
16
|
-
server.once("listening", () => {
|
|
17
|
-
server.close();
|
|
18
|
-
resolve(true);
|
|
19
|
-
});
|
|
20
|
-
server.listen(port, host);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }) {
|
|
24
|
-
const hrStart = process$1.hrtime();
|
|
25
|
-
try {
|
|
26
|
-
try {
|
|
27
|
-
process$1.loadEnvFile();
|
|
28
|
-
} catch {}
|
|
29
|
-
const agentPkgPath = fileURLToPath(import.meta.resolve("@kubb/agent/package.json"));
|
|
30
|
-
const agentDir = path.dirname(agentPkgPath);
|
|
31
|
-
const serverPath = path.join(agentDir, agentDefaults.serverEntryPath);
|
|
32
|
-
const PORT = port !== void 0 ? port : process$1.env.PORT ?? agentDefaults.port;
|
|
33
|
-
const HOST = host !== agentDefaults.host ? host : process$1.env.HOST ?? agentDefaults.host;
|
|
34
|
-
const KUBB_AGENT_ROOT = process$1.env.KUBB_AGENT_ROOT ?? process$1.cwd();
|
|
35
|
-
const KUBB_AGENT_CONFIG = path.resolve(process$1.cwd(), configPath || process$1.env.KUBB_AGENT_CONFIG || agentDefaults.configFile);
|
|
36
|
-
const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? "true" : process$1.env.KUBB_AGENT_ALLOW_WRITE ?? "false";
|
|
37
|
-
const KUBB_AGENT_ALLOW_ALL = allowAll ? "true" : process$1.env.KUBB_AGENT_ALLOW_ALL ?? "false";
|
|
38
|
-
const KUBB_AGENT_TOKEN = process$1.env.KUBB_AGENT_TOKEN;
|
|
39
|
-
const KUBB_AGENT_RETRY_TIMEOUT = process$1.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout;
|
|
40
|
-
const KUBB_STUDIO_URL = process$1.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl;
|
|
41
|
-
const env = {
|
|
42
|
-
...process$1.env,
|
|
43
|
-
PORT,
|
|
44
|
-
HOST,
|
|
45
|
-
KUBB_AGENT_ROOT,
|
|
46
|
-
KUBB_AGENT_CONFIG,
|
|
47
|
-
KUBB_AGENT_ALLOW_WRITE,
|
|
48
|
-
KUBB_AGENT_ALLOW_ALL,
|
|
49
|
-
KUBB_AGENT_TOKEN,
|
|
50
|
-
KUBB_AGENT_RETRY_TIMEOUT,
|
|
51
|
-
KUBB_STUDIO_URL
|
|
52
|
-
};
|
|
53
|
-
clack.log.step(styleText("cyan", "Starting agent server..."));
|
|
54
|
-
clack.log.info(styleText("dim", `Config: ${KUBB_AGENT_CONFIG}`));
|
|
55
|
-
clack.log.info(styleText("dim", `Host: ${HOST}`));
|
|
56
|
-
clack.log.info(styleText("dim", `Port: ${PORT}`));
|
|
57
|
-
if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) clack.log.warn(styleText("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
|
|
58
|
-
if (!await isPortAvailable(Number(PORT), HOST)) {
|
|
59
|
-
clack.log.error(styleText("red", `Port ${PORT} is already in use. Stop the existing process or choose a different port with --port.`));
|
|
60
|
-
process$1.exit(1);
|
|
61
|
-
}
|
|
62
|
-
console.log(env);
|
|
63
|
-
await spawnAsync("node", [serverPath], {
|
|
64
|
-
env,
|
|
65
|
-
cwd: process$1.cwd()
|
|
66
|
-
});
|
|
67
|
-
await sendTelemetry(buildTelemetryEvent({
|
|
68
|
-
command: "agent",
|
|
69
|
-
kubbVersion: version,
|
|
70
|
-
hrStart,
|
|
71
|
-
status: "success"
|
|
72
|
-
}));
|
|
73
|
-
} catch (error) {
|
|
74
|
-
await sendTelemetry(buildTelemetryEvent({
|
|
75
|
-
command: "agent",
|
|
76
|
-
kubbVersion: version,
|
|
77
|
-
hrStart,
|
|
78
|
-
status: "failed"
|
|
79
|
-
}));
|
|
80
|
-
clack.log.error(styleText("red", "Failed to start agent server"));
|
|
81
|
-
console.error(error);
|
|
82
|
-
process$1.exit(1);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
//#endregion
|
|
86
|
-
export { runAgentStart };
|
|
87
|
-
|
|
88
|
-
//# sourceMappingURL=agent-fcClds-t.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-fcClds-t.js","names":["process"],"sources":["../src/runners/agent.ts"],"sourcesContent":["import net from 'node:net'\nimport path from 'node:path'\nimport * as process from 'node:process'\nimport { fileURLToPath } from 'node:url'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { spawnAsync } from '@internals/utils'\nimport { agentDefaults } from '../constants.ts'\nimport { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'\n\ntype AgentStartOptions = {\n port: string | undefined\n host: string\n configPath: string | undefined\n allowWrite: boolean\n allowAll: boolean\n version: string\n}\n\nfunction isPortAvailable(port: number, host: string): Promise<boolean> {\n return new Promise((resolve) => {\n const server = net.createServer()\n server.once('error', () => resolve(false))\n server.once('listening', () => {\n server.close()\n resolve(true)\n })\n server.listen(port, host)\n })\n}\n\nexport async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {\n const hrStart = process.hrtime()\n\n try {\n // Load .env file into process.env using Node.js built-in (v20.12.0+)\n try {\n process.loadEnvFile()\n } catch {\n // .env file may not exist; ignore\n }\n\n // Resolve the @kubb/agent package path\n const agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')\n const agentPkgPath = fileURLToPath(agentPkgUrl)\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n // CLI params take priority over process.env; process.env fills in what the CLI didn't specify;\n // agentDefaults are the last resort. Build env as: defaults ← process.env ← CLI.\n const PORT = port !== undefined ? port : (process.env.PORT ?? agentDefaults.port)\n const HOST = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)\n const KUBB_AGENT_ROOT = process.env.KUBB_AGENT_ROOT ?? process.cwd()\n const KUBB_AGENT_CONFIG = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)\n const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? 'true' : (process.env.KUBB_AGENT_ALLOW_WRITE ?? 'false')\n const KUBB_AGENT_ALLOW_ALL = allowAll ? 'true' : (process.env.KUBB_AGENT_ALLOW_ALL ?? 'false')\n const KUBB_AGENT_TOKEN = process.env.KUBB_AGENT_TOKEN\n const KUBB_AGENT_RETRY_TIMEOUT = process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout\n const KUBB_STUDIO_URL = process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl\n\n const env = {\n ...process.env,\n PORT,\n HOST,\n KUBB_AGENT_ROOT,\n KUBB_AGENT_CONFIG,\n KUBB_AGENT_ALLOW_WRITE,\n KUBB_AGENT_ALLOW_ALL,\n KUBB_AGENT_TOKEN,\n KUBB_AGENT_RETRY_TIMEOUT,\n KUBB_STUDIO_URL,\n }\n\n clack.log.step(styleText('cyan', 'Starting agent server...'))\n clack.log.info(styleText('dim', `Config: ${KUBB_AGENT_CONFIG}`))\n clack.log.info(styleText('dim', `Host: ${HOST}`))\n clack.log.info(styleText('dim', `Port: ${PORT}`))\n if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) {\n clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))\n }\n\n if (!(await isPortAvailable(Number(PORT), HOST))) {\n clack.log.error(styleText('red', `Port ${PORT} is already in use. Stop the existing process or choose a different port with --port.`))\n process.exit(1)\n }\n\n console.log(env)\n\n // Spawns the server as a detached background process so the CLI can exit independently.\n await spawnAsync('node', [serverPath], {\n env,\n cwd: process.cwd(),\n })\n\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'success' }))\n } catch (error) {\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'failed' }))\n clack.log.error(styleText('red', 'Failed to start agent server'))\n console.error(error)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;AAmBA,SAAS,gBAAgB,MAAc,MAAgC;AACrE,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,SAAS,IAAI,cAAc;AACjC,SAAO,KAAK,eAAe,QAAQ,MAAM,CAAC;AAC1C,SAAO,KAAK,mBAAmB;AAC7B,UAAO,OAAO;AACd,WAAQ,KAAK;IACb;AACF,SAAO,OAAO,MAAM,KAAK;GACzB;;AAGJ,eAAsB,cAAc,EAAE,MAAM,MAAM,YAAY,YAAY,UAAU,WAA6C;CAC/H,MAAM,UAAUA,UAAQ,QAAQ;AAEhC,KAAI;AAEF,MAAI;AACF,aAAQ,aAAa;UACf;EAMR,MAAM,eAAe,cADD,OAAO,KAAK,QAAQ,2BAA2B,CACpB;EAC/C,MAAM,WAAW,KAAK,QAAQ,aAAa;EAC3C,MAAM,aAAa,KAAK,KAAK,UAAU,cAAc,gBAAgB;EAIrE,MAAM,OAAO,SAAS,KAAA,IAAY,OAAQA,UAAQ,IAAI,QAAQ,cAAc;EAC5E,MAAM,OAAO,SAAS,cAAc,OAAO,OAAQA,UAAQ,IAAI,QAAQ,cAAc;EACrF,MAAM,kBAAkBA,UAAQ,IAAI,mBAAmBA,UAAQ,KAAK;EACpE,MAAM,oBAAoB,KAAK,QAAQA,UAAQ,KAAK,EAAE,cAAcA,UAAQ,IAAI,qBAAqB,cAAc,WAAW;EAC9H,MAAM,yBAAyB,YAAY,aAAa,SAAUA,UAAQ,IAAI,0BAA0B;EACxG,MAAM,uBAAuB,WAAW,SAAUA,UAAQ,IAAI,wBAAwB;EACtF,MAAM,mBAAmBA,UAAQ,IAAI;EACrC,MAAM,2BAA2BA,UAAQ,IAAI,4BAA4B,cAAc;EACvF,MAAM,kBAAkBA,UAAQ,IAAI,mBAAmB,cAAc;EAErE,MAAM,MAAM;GACV,GAAGA,UAAQ;GACX;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD;AAED,QAAM,IAAI,KAAK,UAAU,QAAQ,2BAA2B,CAAC;AAC7D,QAAM,IAAI,KAAK,UAAU,OAAO,WAAW,oBAAoB,CAAC;AAChE,QAAM,IAAI,KAAK,UAAU,OAAO,SAAS,OAAO,CAAC;AACjD,QAAM,IAAI,KAAK,UAAU,OAAO,SAAS,OAAO,CAAC;AACjD,MAAI,CAAC,0BAA0B,CAAC,qBAC9B,OAAM,IAAI,KAAK,UAAU,UAAU,0EAA0E,CAAC;AAGhH,MAAI,CAAE,MAAM,gBAAgB,OAAO,KAAK,EAAE,KAAK,EAAG;AAChD,SAAM,IAAI,MAAM,UAAU,OAAO,QAAQ,KAAK,uFAAuF,CAAC;AACtI,aAAQ,KAAK,EAAE;;AAGjB,UAAQ,IAAI,IAAI;AAGhB,QAAM,WAAW,QAAQ,CAAC,WAAW,EAAE;GACrC;GACA,KAAKA,UAAQ,KAAK;GACnB,CAAC;AAEF,QAAM,cAAc,oBAAoB;GAAE,SAAS;GAAS,aAAa;GAAS;GAAS,QAAQ;GAAW,CAAC,CAAC;UACzG,OAAO;AACd,QAAM,cAAc,oBAAoB;GAAE,SAAS;GAAS,aAAa;GAAS;GAAS,QAAQ;GAAU,CAAC,CAAC;AAC/G,QAAM,IAAI,MAAM,UAAU,OAAO,+BAA+B,CAAC;AACjE,UAAQ,MAAM,MAAM;AACpB,YAAQ,KAAK,EAAE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants-BTUap0zs.cjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/** NPM registry endpoint used to check for @kubb/cli updates. */\nexport const KUBB_NPM_PACKAGE_URL = 'https://registry.npmjs.org/@kubb/cli/latest' as const\n\n/** OpenTelemetry ingestion endpoint for anonymous usage telemetry. */\nexport const OTLP_ENDPOINT = 'https://otlp.kubb.dev' as const\n\n/** Horizontal rule rendered above/below the plain-logger generation summary. */\nexport const SUMMARY_SEPARATOR = '─'.repeat(27)\n\n/** Maximum number of █ characters in a plugin timing bar. */\nexport const SUMMARY_MAX_BAR_LENGTH = 10 as const\n\n/** Divides elapsed milliseconds into bar-length units (1 block per 100 ms). */\nexport const SUMMARY_TIME_SCALE_DIVISOR = 100 as const\n\n/** Glob pattern for paths the file watcher ignores. */\nexport const WATCHER_IGNORED_PATHS = '**/{.git,node_modules}/**' as const\n\n/** Default runtime values for the `agent start` command. */\nexport const agentDefaults = {\n port: '3000',\n host: 'localhost',\n configFile: 'kubb.config.ts',\n retryTimeout: '30000',\n studioUrl: 'https://studio.kubb.dev',\n /** Relative path from the @kubb/agent package root to the server entry. */\n serverEntryPath: '.output/server/index.mjs',\n} as const\n\n/** Default values used during interactive `init` scaffolding. */\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['plugin-oas', 'plugin-ts'],\n} as const\n\n/**\n * Maps each plugin value to the default config snippet inserted by `init`.\n * The `satisfies` constraint ensures all values remain plain strings while\n * `as const` keeps the object deeply immutable.\n */\nexport const pluginDefaultConfigs = {\n 'plugin-oas': 'pluginOas()',\n 'plugin-ts': `pluginTs({\n output: { path: 'models' },\n })`,\n 'plugin-client': `pluginClient({\n output: { path: 'clients' },\n })`,\n 'plugin-react-query': `pluginReactQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-solid-query': `pluginSolidQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-svelte-query': `pluginSvelteQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-vue-query': `pluginVueQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-swr': `pluginSwr({\n output: { path: 'hooks' },\n })`,\n 'plugin-zod': `pluginZod({\n output: { path: 'zod' },\n })`,\n 'plugin-faker': `pluginFaker({\n output: { path: 'mocks' },\n })`,\n 'plugin-msw': `pluginMsw({\n output: { path: 'msw' },\n })`,\n} as const satisfies Record<string, string>\n\n/** Color palette used by randomCliColor() for deterministic plugin name coloring. */\n"],"mappings":";;AACA,MAAa,uBAAuB;;AAGpC,MAAa,gBAAgB;;AAG7B,MAAa,oBAAoB,IAAI,OAAO,GAAG;;AAS/C,MAAa,wBAAwB;;AAGrC,MAAa,gBAAgB;CAC3B,MAAM;CACN,MAAM;CACN,YAAY;CACZ,cAAc;CACd,WAAW;CAEX,iBAAiB;CAClB;;AAGD,MAAa,eAAe;CAC1B,WAAW;CACX,YAAY;CACZ,SAAS,CAAC,cAAc,YAAY;CACrC;;;;;;AAOD,MAAa,uBAAuB;CAClC,cAAc;CACd,aAAa;;;CAGb,iBAAiB;;;CAGjB,sBAAsB;;;CAGtB,sBAAsB;;;CAGtB,uBAAuB;;;CAGvB,oBAAoB;;;CAGpB,cAAc;;;CAGd,cAAc;;;CAGd,gBAAgB;;;CAGhB,cAAc;;;CAGf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants-CM3dJzjK.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/** NPM registry endpoint used to check for @kubb/cli updates. */\nexport const KUBB_NPM_PACKAGE_URL = 'https://registry.npmjs.org/@kubb/cli/latest' as const\n\n/** OpenTelemetry ingestion endpoint for anonymous usage telemetry. */\nexport const OTLP_ENDPOINT = 'https://otlp.kubb.dev' as const\n\n/** Horizontal rule rendered above/below the plain-logger generation summary. */\nexport const SUMMARY_SEPARATOR = '─'.repeat(27)\n\n/** Maximum number of █ characters in a plugin timing bar. */\nexport const SUMMARY_MAX_BAR_LENGTH = 10 as const\n\n/** Divides elapsed milliseconds into bar-length units (1 block per 100 ms). */\nexport const SUMMARY_TIME_SCALE_DIVISOR = 100 as const\n\n/** Glob pattern for paths the file watcher ignores. */\nexport const WATCHER_IGNORED_PATHS = '**/{.git,node_modules}/**' as const\n\n/** Default runtime values for the `agent start` command. */\nexport const agentDefaults = {\n port: '3000',\n host: 'localhost',\n configFile: 'kubb.config.ts',\n retryTimeout: '30000',\n studioUrl: 'https://studio.kubb.dev',\n /** Relative path from the @kubb/agent package root to the server entry. */\n serverEntryPath: '.output/server/index.mjs',\n} as const\n\n/** Default values used during interactive `init` scaffolding. */\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['plugin-oas', 'plugin-ts'],\n} as const\n\n/**\n * Maps each plugin value to the default config snippet inserted by `init`.\n * The `satisfies` constraint ensures all values remain plain strings while\n * `as const` keeps the object deeply immutable.\n */\nexport const pluginDefaultConfigs = {\n 'plugin-oas': 'pluginOas()',\n 'plugin-ts': `pluginTs({\n output: { path: 'models' },\n })`,\n 'plugin-client': `pluginClient({\n output: { path: 'clients' },\n })`,\n 'plugin-react-query': `pluginReactQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-solid-query': `pluginSolidQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-svelte-query': `pluginSvelteQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-vue-query': `pluginVueQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-swr': `pluginSwr({\n output: { path: 'hooks' },\n })`,\n 'plugin-zod': `pluginZod({\n output: { path: 'zod' },\n })`,\n 'plugin-faker': `pluginFaker({\n output: { path: 'mocks' },\n })`,\n 'plugin-msw': `pluginMsw({\n output: { path: 'msw' },\n })`,\n} as const satisfies Record<string, string>\n\n/** Color palette used by randomCliColor() for deterministic plugin name coloring. */\n"],"mappings":";;AACA,MAAa,uBAAuB;;AAGpC,MAAa,gBAAgB;;AAG7B,MAAa,oBAAoB,IAAI,OAAO,GAAG;;AAS/C,MAAa,wBAAwB;;AAGrC,MAAa,gBAAgB;CAC3B,MAAM;CACN,MAAM;CACN,YAAY;CACZ,cAAc;CACd,WAAW;CAEX,iBAAiB;CAClB;;AAGD,MAAa,eAAe;CAC1B,WAAW;CACX,YAAY;CACZ,SAAS,CAAC,cAAc,YAAY;CACrC;;;;;;AAOD,MAAa,uBAAuB;CAClC,cAAc;CACd,aAAa;;;CAGb,iBAAiB;;;CAGjB,sBAAsB;;;CAGtB,sBAAsB;;;CAGtB,uBAAuB;;;CAGvB,oBAAoB;;;CAGpB,cAAc;;;CAGd,cAAc;;;CAGd,gBAAgB;;;CAGhB,cAAc;;;CAGf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package-CXinXKRX.cjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
package/dist/package-DOoCSchC.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package-DOoCSchC.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from '@internals/utils'
|
|
2
|
-
import { version } from '../../../package.json'
|
|
3
|
-
import { agentDefaults } from '../../constants.ts'
|
|
4
|
-
|
|
5
|
-
export const command = defineCommand({
|
|
6
|
-
name: 'start',
|
|
7
|
-
description: 'Start the Agent server',
|
|
8
|
-
options: {
|
|
9
|
-
config: { type: 'string', description: 'Path to the Kubb config', short: 'c' },
|
|
10
|
-
port: { type: 'string', description: `Port for the server (default: ${agentDefaults.port})`, short: 'p' },
|
|
11
|
-
host: { type: 'string', description: 'Host for the server', default: agentDefaults.host },
|
|
12
|
-
'allow-write': {
|
|
13
|
-
type: 'boolean',
|
|
14
|
-
description: 'Allow writing generated files to the filesystem. When not set, no files are written and the config patch is not persisted.',
|
|
15
|
-
default: false,
|
|
16
|
-
},
|
|
17
|
-
'allow-all': { type: 'boolean', description: 'Grant all permissions (implies --allow-write).', default: false },
|
|
18
|
-
},
|
|
19
|
-
async run({ values }) {
|
|
20
|
-
const { runAgentStart } = await import('../../runners/agent.ts')
|
|
21
|
-
|
|
22
|
-
await runAgentStart({
|
|
23
|
-
port: values.port !== undefined ? values.port : undefined,
|
|
24
|
-
host: values.host,
|
|
25
|
-
configPath: values.config,
|
|
26
|
-
allowWrite: values['allow-write'],
|
|
27
|
-
allowAll: values['allow-all'],
|
|
28
|
-
version,
|
|
29
|
-
})
|
|
30
|
-
},
|
|
31
|
-
})
|
package/src/commands/agent.ts
DELETED
package/src/runners/agent.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import net from 'node:net'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import * as process from 'node:process'
|
|
4
|
-
import { fileURLToPath } from 'node:url'
|
|
5
|
-
import { styleText } from 'node:util'
|
|
6
|
-
import * as clack from '@clack/prompts'
|
|
7
|
-
import { spawnAsync } from '@internals/utils'
|
|
8
|
-
import { agentDefaults } from '../constants.ts'
|
|
9
|
-
import { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'
|
|
10
|
-
|
|
11
|
-
type AgentStartOptions = {
|
|
12
|
-
port: string | undefined
|
|
13
|
-
host: string
|
|
14
|
-
configPath: string | undefined
|
|
15
|
-
allowWrite: boolean
|
|
16
|
-
allowAll: boolean
|
|
17
|
-
version: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function isPortAvailable(port: number, host: string): Promise<boolean> {
|
|
21
|
-
return new Promise((resolve) => {
|
|
22
|
-
const server = net.createServer()
|
|
23
|
-
server.once('error', () => resolve(false))
|
|
24
|
-
server.once('listening', () => {
|
|
25
|
-
server.close()
|
|
26
|
-
resolve(true)
|
|
27
|
-
})
|
|
28
|
-
server.listen(port, host)
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {
|
|
33
|
-
const hrStart = process.hrtime()
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
// Load .env file into process.env using Node.js built-in (v20.12.0+)
|
|
37
|
-
try {
|
|
38
|
-
process.loadEnvFile()
|
|
39
|
-
} catch {
|
|
40
|
-
// .env file may not exist; ignore
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Resolve the @kubb/agent package path
|
|
44
|
-
const agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')
|
|
45
|
-
const agentPkgPath = fileURLToPath(agentPkgUrl)
|
|
46
|
-
const agentDir = path.dirname(agentPkgPath)
|
|
47
|
-
const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)
|
|
48
|
-
|
|
49
|
-
// CLI params take priority over process.env; process.env fills in what the CLI didn't specify;
|
|
50
|
-
// agentDefaults are the last resort. Build env as: defaults ← process.env ← CLI.
|
|
51
|
-
const PORT = port !== undefined ? port : (process.env.PORT ?? agentDefaults.port)
|
|
52
|
-
const HOST = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)
|
|
53
|
-
const KUBB_AGENT_ROOT = process.env.KUBB_AGENT_ROOT ?? process.cwd()
|
|
54
|
-
const KUBB_AGENT_CONFIG = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)
|
|
55
|
-
const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? 'true' : (process.env.KUBB_AGENT_ALLOW_WRITE ?? 'false')
|
|
56
|
-
const KUBB_AGENT_ALLOW_ALL = allowAll ? 'true' : (process.env.KUBB_AGENT_ALLOW_ALL ?? 'false')
|
|
57
|
-
const KUBB_AGENT_TOKEN = process.env.KUBB_AGENT_TOKEN
|
|
58
|
-
const KUBB_AGENT_RETRY_TIMEOUT = process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout
|
|
59
|
-
const KUBB_STUDIO_URL = process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl
|
|
60
|
-
|
|
61
|
-
const env = {
|
|
62
|
-
...process.env,
|
|
63
|
-
PORT,
|
|
64
|
-
HOST,
|
|
65
|
-
KUBB_AGENT_ROOT,
|
|
66
|
-
KUBB_AGENT_CONFIG,
|
|
67
|
-
KUBB_AGENT_ALLOW_WRITE,
|
|
68
|
-
KUBB_AGENT_ALLOW_ALL,
|
|
69
|
-
KUBB_AGENT_TOKEN,
|
|
70
|
-
KUBB_AGENT_RETRY_TIMEOUT,
|
|
71
|
-
KUBB_STUDIO_URL,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
clack.log.step(styleText('cyan', 'Starting agent server...'))
|
|
75
|
-
clack.log.info(styleText('dim', `Config: ${KUBB_AGENT_CONFIG}`))
|
|
76
|
-
clack.log.info(styleText('dim', `Host: ${HOST}`))
|
|
77
|
-
clack.log.info(styleText('dim', `Port: ${PORT}`))
|
|
78
|
-
if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) {
|
|
79
|
-
clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!(await isPortAvailable(Number(PORT), HOST))) {
|
|
83
|
-
clack.log.error(styleText('red', `Port ${PORT} is already in use. Stop the existing process or choose a different port with --port.`))
|
|
84
|
-
process.exit(1)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
console.log(env)
|
|
88
|
-
|
|
89
|
-
// Spawns the server as a detached background process so the CLI can exit independently.
|
|
90
|
-
await spawnAsync('node', [serverPath], {
|
|
91
|
-
env,
|
|
92
|
-
cwd: process.cwd(),
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'success' }))
|
|
96
|
-
} catch (error) {
|
|
97
|
-
await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'failed' }))
|
|
98
|
-
clack.log.error(styleText('red', 'Failed to start agent server'))
|
|
99
|
-
console.error(error)
|
|
100
|
-
process.exit(1)
|
|
101
|
-
}
|
|
102
|
-
}
|