@kubb/cli 5.0.0-beta.49 → 5.0.0-beta.50
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/README.md +1 -40
- package/dist/{chunk-CRm0XQPb.js → chunk-C0LytTxp.js} +0 -1
- package/dist/constants-BQ8LZB1P.js +23 -0
- package/dist/constants-BQ8LZB1P.js.map +1 -0
- package/dist/{constants-BtmponZ3.cjs → constants-MzEjK668.cjs} +1 -19
- package/dist/constants-MzEjK668.cjs.map +1 -0
- package/dist/{define-DNG1U8ha.js → define-C63T4jp6.js} +2 -2
- package/dist/{define-DNG1U8ha.js.map → define-C63T4jp6.js.map} +1 -1
- package/dist/{errors-CoxrNXaA.js → errors-BsemQCMn.js} +2 -2
- package/dist/{errors-CoxrNXaA.js.map → errors-BsemQCMn.js.map} +1 -1
- package/dist/{generate-Ua2_bX6F.js → generate-CKnn3tQa.js} +4 -4
- package/dist/{generate-Ua2_bX6F.js.map → generate-CKnn3tQa.js.map} +1 -1
- package/dist/{generate-CNqETcDC.cjs → generate-Q6GMu4L8.cjs} +2 -2
- package/dist/{generate-CNqETcDC.cjs.map → generate-Q6GMu4L8.cjs.map} +1 -1
- package/dist/index.cjs +6 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -10
- package/dist/index.js.map +1 -1
- package/dist/{init-Ga1vvbKs.cjs → init-C5iCqBwA.cjs} +3 -3
- package/dist/{init-Ga1vvbKs.cjs.map → init-C5iCqBwA.cjs.map} +1 -1
- package/dist/{init-o5XBcC-j.js → init-DyOF6CiQ.js} +5 -5
- package/dist/{init-o5XBcC-j.js.map → init-DyOF6CiQ.js.map} +1 -1
- package/dist/{mcp-B203R5_F.js → mcp-09FvxYWS.js} +5 -5
- package/dist/{mcp-B203R5_F.js.map → mcp-09FvxYWS.js.map} +1 -1
- package/dist/{mcp-HfHC9cPg.cjs → mcp-BN5HQYdK.cjs} +2 -2
- package/dist/{mcp-HfHC9cPg.cjs.map → mcp-BN5HQYdK.cjs.map} +1 -1
- package/dist/package-Bm6VUbtL.js +6 -0
- package/dist/package-Bm6VUbtL.js.map +1 -0
- package/dist/{package-BWUO2ZW7.cjs → package-DOVOGEEY.cjs} +2 -2
- package/dist/package-DOVOGEEY.cjs.map +1 -0
- package/dist/{run-CGf0KEts.js → run-BO7phoNN.js} +3 -3
- package/dist/{run-CGf0KEts.js.map → run-BO7phoNN.js.map} +1 -1
- package/dist/{run-B1Bc6OVr.cjs → run-BtjzfTz3.cjs} +133 -21
- package/dist/run-BtjzfTz3.cjs.map +1 -0
- package/dist/{run-BQzoaxjR.js → run-BzaKz_nl.js} +3 -3
- package/dist/{run-BQzoaxjR.js.map → run-BzaKz_nl.js.map} +1 -1
- package/dist/{run-CvEVkbIx.js → run-C-omuksC.js} +117 -5
- package/dist/run-C-omuksC.js.map +1 -0
- package/dist/{run--SXpHhbu.cjs → run-CrvmI4G2.cjs} +3 -3
- package/dist/{run--SXpHhbu.cjs.map → run-CrvmI4G2.cjs.map} +1 -1
- package/dist/{run-CCXgjDTA.js → run-DvZ5i2lT.js} +6 -6
- package/dist/{run-CCXgjDTA.js.map → run-DvZ5i2lT.js.map} +1 -1
- package/dist/{shell-BrqyJdB7.js → shell-DsgkfUSW.js} +2 -2
- package/dist/{shell-BrqyJdB7.js.map → shell-DsgkfUSW.js.map} +1 -1
- package/dist/{validate-DM2F50zr.js → validate-5atkOC73.js} +5 -5
- package/dist/{validate-DM2F50zr.js.map → validate-5atkOC73.js.map} +1 -1
- package/dist/{validate-D6ReW7QT.cjs → validate-C6KPFEex.cjs} +2 -2
- package/dist/{validate-D6ReW7QT.cjs.map → validate-C6KPFEex.cjs.map} +1 -1
- package/package.json +6 -10
- package/src/constants.ts +0 -14
- package/src/index.ts +1 -2
- package/src/runners/init/run.ts +0 -2
- package/dist/agent-BKMdKAIJ.cjs +0 -70
- package/dist/agent-BKMdKAIJ.cjs.map +0 -1
- package/dist/agent-yMycIvOI.js +0 -68
- package/dist/agent-yMycIvOI.js.map +0 -1
- package/dist/constants-84a47qA-.js +0 -35
- package/dist/constants-84a47qA-.js.map +0 -1
- package/dist/constants-AHhyFH15.cjs +0 -139
- package/dist/constants-AHhyFH15.cjs.map +0 -1
- package/dist/constants-BtmponZ3.cjs.map +0 -1
- package/dist/constants-C94RKp3A.js +0 -116
- package/dist/constants-C94RKp3A.js.map +0 -1
- package/dist/package-BWUO2ZW7.cjs.map +0 -1
- package/dist/package-BxAq00xt.js +0 -6
- package/dist/package-BxAq00xt.js.map +0 -1
- package/dist/run-B1Bc6OVr.cjs.map +0 -1
- package/dist/run-Bm3WebIl.js +0 -121
- package/dist/run-Bm3WebIl.js.map +0 -1
- package/dist/run-CZC17tSi.cjs +0 -125
- package/dist/run-CZC17tSi.cjs.map +0 -1
- package/dist/run-CvEVkbIx.js.map +0 -1
- package/src/commands/agent/start.ts +0 -50
- package/src/commands/agent.ts +0 -10
- package/src/runners/agent/run.ts +0 -115
- package/src/runners/agent/utils.ts +0 -98
package/dist/run-Bm3WebIl.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import "./chunk-CRm0XQPb.js";
|
|
2
|
-
import { t as getErrorMessage } from "./errors-CoxrNXaA.js";
|
|
3
|
-
import { t as spawnAsync } from "./shell-BrqyJdB7.js";
|
|
4
|
-
import { i as agentDefaults } from "./constants-84a47qA-.js";
|
|
5
|
-
import { createRequire } from "node:module";
|
|
6
|
-
import { styleText } from "node:util";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
import { Telemetry } from "@kubb/core";
|
|
9
|
-
import process from "node:process";
|
|
10
|
-
import * as clack from "@clack/prompts";
|
|
11
|
-
import net from "node:net";
|
|
12
|
-
//#region src/runners/agent/utils.ts
|
|
13
|
-
/**
|
|
14
|
-
* Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.
|
|
15
|
-
*/
|
|
16
|
-
function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }) {
|
|
17
|
-
const resolvedPort = port ?? process.env.PORT ?? agentDefaults.port;
|
|
18
|
-
const resolvedHost = host !== agentDefaults.host ? host : process.env.HOST ?? agentDefaults.host;
|
|
19
|
-
const resolvedAllowAll = allowAll || process.env.KUBB_AGENT_ALLOW_ALL === "true";
|
|
20
|
-
const resolvedAllowWrite = resolvedAllowAll || allowWrite || process.env.KUBB_AGENT_ALLOW_WRITE === "true";
|
|
21
|
-
const agentRoot = process.env.KUBB_AGENT_ROOT ?? process.cwd();
|
|
22
|
-
const agentConfigPath = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile);
|
|
23
|
-
return {
|
|
24
|
-
port: resolvedPort,
|
|
25
|
-
host: resolvedHost,
|
|
26
|
-
allowWrite: resolvedAllowWrite,
|
|
27
|
-
allowAll: resolvedAllowAll,
|
|
28
|
-
agentConfigPath,
|
|
29
|
-
env: {
|
|
30
|
-
...process.env,
|
|
31
|
-
PORT: resolvedPort,
|
|
32
|
-
HOST: resolvedHost,
|
|
33
|
-
KUBB_AGENT_ROOT: agentRoot,
|
|
34
|
-
KUBB_AGENT_CONFIG: agentConfigPath,
|
|
35
|
-
KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),
|
|
36
|
-
KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),
|
|
37
|
-
KUBB_AGENT_TOKEN: process.env.KUBB_AGENT_TOKEN,
|
|
38
|
-
KUBB_AGENT_RETRY_TIMEOUT: process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,
|
|
39
|
-
KUBB_STUDIO_URL: process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function isPortAvailable(port, host) {
|
|
44
|
-
return new Promise((resolve) => {
|
|
45
|
-
const server = net.createServer();
|
|
46
|
-
server.once("error", () => resolve(false));
|
|
47
|
-
server.once("listening", () => {
|
|
48
|
-
server.close();
|
|
49
|
-
resolve(true);
|
|
50
|
-
});
|
|
51
|
-
server.listen(port, host);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region src/runners/agent/run.ts
|
|
56
|
-
/**
|
|
57
|
-
* Spawns the Kubb Agent HTTP server as a Node.js subprocess.
|
|
58
|
-
* Resolves config from CLI flags and environment variables, validates the port, and exits with code 1 on failure.
|
|
59
|
-
*/
|
|
60
|
-
async function run({ port, host, configPath, allowWrite, allowAll, version }) {
|
|
61
|
-
const hrStart = process.hrtime();
|
|
62
|
-
const report = (status) => Telemetry.send(Telemetry.build({
|
|
63
|
-
command: "agent",
|
|
64
|
-
kubbVersion: version,
|
|
65
|
-
hrStart,
|
|
66
|
-
status
|
|
67
|
-
}));
|
|
68
|
-
try {
|
|
69
|
-
try {
|
|
70
|
-
process.loadEnvFile();
|
|
71
|
-
} catch {}
|
|
72
|
-
const require = createRequire(import.meta.url);
|
|
73
|
-
let agentPkgPath;
|
|
74
|
-
try {
|
|
75
|
-
agentPkgPath = require.resolve("@kubb/agent/package.json");
|
|
76
|
-
} catch (_e) {
|
|
77
|
-
console.error(styleText("red", "The @kubb/agent package is not installed."));
|
|
78
|
-
console.error("");
|
|
79
|
-
console.error("Install it with:");
|
|
80
|
-
console.error(styleText("cyan", " npm install @kubb/agent"));
|
|
81
|
-
console.error(styleText("cyan", " # or"));
|
|
82
|
-
console.error(styleText("cyan", " pnpm install @kubb/agent"));
|
|
83
|
-
console.error("");
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
const agentDir = path.dirname(agentPkgPath);
|
|
87
|
-
const serverPath = path.join(agentDir, agentDefaults.serverEntryPath);
|
|
88
|
-
const resolvedEnv = resolveAgentStartEnvironment({
|
|
89
|
-
port,
|
|
90
|
-
host,
|
|
91
|
-
configPath,
|
|
92
|
-
allowWrite,
|
|
93
|
-
allowAll
|
|
94
|
-
});
|
|
95
|
-
const numericPort = Number(resolvedEnv.port);
|
|
96
|
-
if (!Number.isInteger(numericPort) || numericPort <= 0) throw new Error(`Invalid port "${resolvedEnv.port}". Provide a positive integer with --port or PORT.`);
|
|
97
|
-
clack.log.step(styleText("cyan", "Starting agent server..."));
|
|
98
|
-
clack.log.info(styleText("dim", `Config: ${resolvedEnv.agentConfigPath}`));
|
|
99
|
-
clack.log.info(styleText("dim", `Host: ${resolvedEnv.host}`));
|
|
100
|
-
clack.log.info(styleText("dim", `Port: ${resolvedEnv.port}`));
|
|
101
|
-
if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) clack.log.warn(styleText("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
|
|
102
|
-
if (!await isPortAvailable(numericPort, resolvedEnv.host)) {
|
|
103
|
-
clack.log.error(styleText("red", `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`));
|
|
104
|
-
process.exit(1);
|
|
105
|
-
}
|
|
106
|
-
await spawnAsync(process.execPath, [serverPath], {
|
|
107
|
-
env: resolvedEnv.env,
|
|
108
|
-
cwd: process.cwd()
|
|
109
|
-
});
|
|
110
|
-
await report("success");
|
|
111
|
-
} catch (error) {
|
|
112
|
-
await report("failed");
|
|
113
|
-
clack.log.error(styleText("red", "Failed to start agent server"));
|
|
114
|
-
clack.log.error(getErrorMessage(error));
|
|
115
|
-
process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
//#endregion
|
|
119
|
-
export { run };
|
|
120
|
-
|
|
121
|
-
//# sourceMappingURL=run-Bm3WebIl.js.map
|
package/dist/run-Bm3WebIl.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run-Bm3WebIl.js","names":[],"sources":["../src/runners/agent/utils.ts","../src/runners/agent/run.ts"],"sourcesContent":["import net from 'node:net'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { agentDefaults } from '../../constants.ts'\n\ntype AgentStartEnvironmentInput = {\n /**\n * TCP port for the HTTP server. When `undefined`, falls back to `PORT` env var or the default (`3000`).\n */\n port: string | undefined\n /**\n * Hostname the HTTP server binds to.\n */\n host: string\n /**\n * Explicit path to the Kubb config file. When `undefined`, falls back to `KUBB_AGENT_CONFIG` or the default filename.\n */\n configPath: string | undefined\n /**\n * Grants the agent permission to write generated files to the filesystem.\n */\n allowWrite: boolean\n /**\n * Grants all agent permissions, including filesystem writes. Implies `allowWrite`.\n */\n allowAll: boolean\n}\n\ntype ResolvedAgentStartEnvironment = {\n /**\n * Final port string after merging CLI flag, `PORT` env var, and the default.\n */\n port: string\n /**\n * Final hostname after merging CLI flag, `HOST` env var, and the default.\n */\n host: string\n /**\n * Effective write-permission flag, accounting for `allowAll` and `KUBB_AGENT_ALLOW_WRITE`.\n */\n allowWrite: boolean\n /**\n * Effective all-permissions flag, accounting for `KUBB_AGENT_ALLOW_ALL`.\n */\n allowAll: boolean\n /**\n * Absolute path to the Kubb config file passed to the agent subprocess.\n */\n agentConfigPath: string\n /**\n * Merged `process.env` object with all resolved agent environment variables applied.\n */\n env: NodeJS.ProcessEnv\n}\n\n/**\n * Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.\n */\nexport function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: AgentStartEnvironmentInput): ResolvedAgentStartEnvironment {\n const resolvedPort = port ?? process.env.PORT ?? agentDefaults.port\n const resolvedHost = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)\n const resolvedAllowAll = allowAll || process.env.KUBB_AGENT_ALLOW_ALL === 'true'\n const resolvedAllowWrite = resolvedAllowAll || allowWrite || process.env.KUBB_AGENT_ALLOW_WRITE === 'true'\n const agentRoot = process.env.KUBB_AGENT_ROOT ?? process.cwd()\n const agentConfigPath = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)\n\n return {\n port: resolvedPort,\n host: resolvedHost,\n allowWrite: resolvedAllowWrite,\n allowAll: resolvedAllowAll,\n agentConfigPath,\n env: {\n ...process.env,\n PORT: resolvedPort,\n HOST: resolvedHost,\n KUBB_AGENT_ROOT: agentRoot,\n KUBB_AGENT_CONFIG: agentConfigPath,\n KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),\n KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),\n KUBB_AGENT_TOKEN: process.env.KUBB_AGENT_TOKEN,\n KUBB_AGENT_RETRY_TIMEOUT: process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,\n KUBB_STUDIO_URL: process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl,\n },\n }\n}\n\nexport function 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","import { createRequire } from 'node:module'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { spawnAsync, getErrorMessage } from '@internals/utils'\nimport { Telemetry } from '@kubb/core'\nimport { agentDefaults } from '../../constants.ts'\nimport { isPortAvailable, resolveAgentStartEnvironment } from './utils.ts'\n\ntype AgentStartOptions = {\n /**\n * TCP port for the HTTP server. When `undefined`, falls back to `PORT` env var or the default (`3000`).\n */\n port: string | undefined\n /**\n * Hostname the HTTP server binds to.\n *\n * @default 'localhost'\n */\n host: string\n /**\n * Explicit path to the Kubb config file. When `undefined`, falls back to `KUBB_AGENT_CONFIG` or the default filename.\n */\n configPath: string | undefined\n /**\n * Grants the agent permission to write generated files to the filesystem.\n */\n allowWrite: boolean\n /**\n * Grants all agent permissions, including filesystem writes. Implies `allowWrite`.\n */\n allowAll: boolean\n /**\n * Current `@kubb/cli` version string, used for the telemetry payload.\n */\n version: string\n}\n\n/**\n * Spawns the Kubb Agent HTTP server as a Node.js subprocess.\n * Resolves config from CLI flags and environment variables, validates the port, and exits with code 1 on failure.\n */\nexport async function run({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {\n const hrStart = process.hrtime()\n const report = (status: 'success' | 'failed') => Telemetry.send(Telemetry.build({ command: 'agent', kubbVersion: version, hrStart, status }))\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, createRequire is CJS/ESM compatible (import.meta.resolve is ESM-only)\n const require = createRequire(import.meta.url)\n let agentPkgPath: string\n try {\n agentPkgPath = require.resolve('@kubb/agent/package.json')\n } catch (_e) {\n console.error(styleText('red', 'The @kubb/agent package is not installed.'))\n console.error('')\n console.error('Install it with:')\n console.error(styleText('cyan', ' npm install @kubb/agent'))\n console.error(styleText('cyan', ' # or'))\n console.error(styleText('cyan', ' pnpm install @kubb/agent'))\n console.error('')\n process.exit(1)\n }\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n const resolvedEnv = resolveAgentStartEnvironment({\n port,\n host,\n configPath,\n allowWrite,\n allowAll,\n })\n const numericPort = Number(resolvedEnv.port)\n\n if (!Number.isInteger(numericPort) || numericPort <= 0) {\n throw new Error(`Invalid port \"${resolvedEnv.port}\". Provide a positive integer with --port or PORT.`)\n }\n\n clack.log.step(styleText('cyan', 'Starting agent server...'))\n clack.log.info(styleText('dim', `Config: ${resolvedEnv.agentConfigPath}`))\n clack.log.info(styleText('dim', `Host: ${resolvedEnv.host}`))\n clack.log.info(styleText('dim', `Port: ${resolvedEnv.port}`))\n if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) {\n clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))\n }\n\n if (!(await isPortAvailable(numericPort, resolvedEnv.host))) {\n clack.log.error(styleText('red', `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`))\n process.exit(1)\n }\n\n // Spawns the server as a detached background process so the CLI can exit independently.\n // Reuse the runtime that launched the CLI (Bun or Node) via process.execPath so the\n // agent stays on the same runtime instead of forcing a `node` binary that may be absent.\n await spawnAsync(process.execPath, [serverPath], {\n env: resolvedEnv.env,\n cwd: process.cwd(),\n })\n\n await report('success')\n } catch (error) {\n await report('failed')\n clack.log.error(styleText('red', 'Failed to start agent server'))\n clack.log.error(getErrorMessage(error))\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0DA,SAAgB,6BAA6B,EAAE,MAAM,MAAM,YAAY,YAAY,YAAuE;CACxJ,MAAM,eAAe,QAAQ,QAAQ,IAAI,QAAQ,cAAc;CAC/D,MAAM,eAAe,SAAS,cAAc,OAAO,OAAQ,QAAQ,IAAI,QAAQ,cAAc;CAC7F,MAAM,mBAAmB,YAAY,QAAQ,IAAI,yBAAyB;CAC1E,MAAM,qBAAqB,oBAAoB,cAAc,QAAQ,IAAI,2BAA2B;CACpG,MAAM,YAAY,QAAQ,IAAI,mBAAmB,QAAQ,IAAI;CAC7D,MAAM,kBAAkB,KAAK,QAAQ,QAAQ,IAAI,GAAG,cAAc,QAAQ,IAAI,qBAAqB,cAAc,UAAU;CAE3H,OAAO;EACL,MAAM;EACN,MAAM;EACN,YAAY;EACZ,UAAU;EACV;EACA,KAAK;GACH,GAAG,QAAQ;GACX,MAAM;GACN,MAAM;GACN,iBAAiB;GACjB,mBAAmB;GACnB,wBAAwB,OAAO,kBAAkB;GACjD,sBAAsB,OAAO,gBAAgB;GAC7C,kBAAkB,QAAQ,IAAI;GAC9B,0BAA0B,QAAQ,IAAI,4BAA4B,cAAc;GAChF,iBAAiB,QAAQ,IAAI,mBAAmB,cAAc;EAChE;CACF;AACF;AAEA,SAAgB,gBAAgB,MAAc,MAAgC;CAC5E,OAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,SAAS,IAAI,aAAa;EAChC,OAAO,KAAK,eAAe,QAAQ,KAAK,CAAC;EACzC,OAAO,KAAK,mBAAmB;GAC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AM,CAAC;EAC5D,MAAM,IAAI,KAAK,UAAU,OAAO,SAAS,YAAY,MAAM,CAAC;EAC5D,IAAI,CAAC,YAAY,cAAc,CAAC,YAAY,UAC1C,MAAM,IAAI,KAAK,UAAU,UAAU,yEAAyE,CAAC;EAG/G,IAAI,CAAE,MAAM,gBAAgB,aAAa,YAAY,IAAI,GAAI;GAC3D,MAAM,IAAI,MAAM,UAAU,OAAO,QAAQ,YAAY,KAAK,sFAAsF,CAAC;GACjJ,QAAQ,KAAK,CAAC;EAChB;EAKA,MAAM,WAAW,QAAQ,UAAU,CAAC,UAAU,GAAG;GAC/C,KAAK,YAAY;GACjB,KAAK,QAAQ,IAAI;EACnB,CAAC;EAED,MAAM,OAAO,SAAS;CACxB,SAAS,OAAO;EACd,MAAM,OAAO,QAAQ;EACrB,MAAM,IAAI,MAAM,UAAU,OAAO,8BAA8B,CAAC;EAChE,MAAM,IAAI,MAAM,gBAAgB,KAAK,CAAC;EACtC,QAAQ,KAAK,CAAC;CAChB;AACF"}
|
package/dist/run-CZC17tSi.cjs
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-Bx3C2hgW.cjs");
|
|
2
|
-
const require_errors = require("./errors-DykI11xo.cjs");
|
|
3
|
-
const require_shell = require("./shell-Lh-vLWwH.cjs");
|
|
4
|
-
const require_constants = require("./constants-BtmponZ3.cjs");
|
|
5
|
-
let node_util = require("node:util");
|
|
6
|
-
let node_path = require("node:path");
|
|
7
|
-
node_path = require_chunk.__toESM(node_path, 1);
|
|
8
|
-
let _kubb_core = require("@kubb/core");
|
|
9
|
-
let node_module = require("node:module");
|
|
10
|
-
let node_process = require("node:process");
|
|
11
|
-
node_process = require_chunk.__toESM(node_process, 1);
|
|
12
|
-
let _clack_prompts = require("@clack/prompts");
|
|
13
|
-
_clack_prompts = require_chunk.__toESM(_clack_prompts, 1);
|
|
14
|
-
let node_net = require("node:net");
|
|
15
|
-
node_net = require_chunk.__toESM(node_net, 1);
|
|
16
|
-
//#region src/runners/agent/utils.ts
|
|
17
|
-
/**
|
|
18
|
-
* Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.
|
|
19
|
-
*/
|
|
20
|
-
function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }) {
|
|
21
|
-
const resolvedPort = port ?? node_process.default.env.PORT ?? require_constants.agentDefaults.port;
|
|
22
|
-
const resolvedHost = host !== require_constants.agentDefaults.host ? host : node_process.default.env.HOST ?? require_constants.agentDefaults.host;
|
|
23
|
-
const resolvedAllowAll = allowAll || node_process.default.env.KUBB_AGENT_ALLOW_ALL === "true";
|
|
24
|
-
const resolvedAllowWrite = resolvedAllowAll || allowWrite || node_process.default.env.KUBB_AGENT_ALLOW_WRITE === "true";
|
|
25
|
-
const agentRoot = node_process.default.env.KUBB_AGENT_ROOT ?? node_process.default.cwd();
|
|
26
|
-
const agentConfigPath = node_path.default.resolve(node_process.default.cwd(), configPath || node_process.default.env.KUBB_AGENT_CONFIG || require_constants.agentDefaults.configFile);
|
|
27
|
-
return {
|
|
28
|
-
port: resolvedPort,
|
|
29
|
-
host: resolvedHost,
|
|
30
|
-
allowWrite: resolvedAllowWrite,
|
|
31
|
-
allowAll: resolvedAllowAll,
|
|
32
|
-
agentConfigPath,
|
|
33
|
-
env: {
|
|
34
|
-
...node_process.default.env,
|
|
35
|
-
PORT: resolvedPort,
|
|
36
|
-
HOST: resolvedHost,
|
|
37
|
-
KUBB_AGENT_ROOT: agentRoot,
|
|
38
|
-
KUBB_AGENT_CONFIG: agentConfigPath,
|
|
39
|
-
KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),
|
|
40
|
-
KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),
|
|
41
|
-
KUBB_AGENT_TOKEN: node_process.default.env.KUBB_AGENT_TOKEN,
|
|
42
|
-
KUBB_AGENT_RETRY_TIMEOUT: node_process.default.env.KUBB_AGENT_RETRY_TIMEOUT ?? require_constants.agentDefaults.retryTimeout,
|
|
43
|
-
KUBB_STUDIO_URL: node_process.default.env.KUBB_STUDIO_URL ?? require_constants.agentDefaults.studioUrl
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function isPortAvailable(port, host) {
|
|
48
|
-
return new Promise((resolve) => {
|
|
49
|
-
const server = node_net.default.createServer();
|
|
50
|
-
server.once("error", () => resolve(false));
|
|
51
|
-
server.once("listening", () => {
|
|
52
|
-
server.close();
|
|
53
|
-
resolve(true);
|
|
54
|
-
});
|
|
55
|
-
server.listen(port, host);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/runners/agent/run.ts
|
|
60
|
-
/**
|
|
61
|
-
* Spawns the Kubb Agent HTTP server as a Node.js subprocess.
|
|
62
|
-
* Resolves config from CLI flags and environment variables, validates the port, and exits with code 1 on failure.
|
|
63
|
-
*/
|
|
64
|
-
async function run({ port, host, configPath, allowWrite, allowAll, version }) {
|
|
65
|
-
const hrStart = node_process.default.hrtime();
|
|
66
|
-
const report = (status) => _kubb_core.Telemetry.send(_kubb_core.Telemetry.build({
|
|
67
|
-
command: "agent",
|
|
68
|
-
kubbVersion: version,
|
|
69
|
-
hrStart,
|
|
70
|
-
status
|
|
71
|
-
}));
|
|
72
|
-
try {
|
|
73
|
-
try {
|
|
74
|
-
node_process.default.loadEnvFile();
|
|
75
|
-
} catch {}
|
|
76
|
-
const require = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
77
|
-
let agentPkgPath;
|
|
78
|
-
try {
|
|
79
|
-
agentPkgPath = require.resolve("@kubb/agent/package.json");
|
|
80
|
-
} catch (_e) {
|
|
81
|
-
console.error((0, node_util.styleText)("red", "The @kubb/agent package is not installed."));
|
|
82
|
-
console.error("");
|
|
83
|
-
console.error("Install it with:");
|
|
84
|
-
console.error((0, node_util.styleText)("cyan", " npm install @kubb/agent"));
|
|
85
|
-
console.error((0, node_util.styleText)("cyan", " # or"));
|
|
86
|
-
console.error((0, node_util.styleText)("cyan", " pnpm install @kubb/agent"));
|
|
87
|
-
console.error("");
|
|
88
|
-
node_process.default.exit(1);
|
|
89
|
-
}
|
|
90
|
-
const agentDir = node_path.default.dirname(agentPkgPath);
|
|
91
|
-
const serverPath = node_path.default.join(agentDir, require_constants.agentDefaults.serverEntryPath);
|
|
92
|
-
const resolvedEnv = resolveAgentStartEnvironment({
|
|
93
|
-
port,
|
|
94
|
-
host,
|
|
95
|
-
configPath,
|
|
96
|
-
allowWrite,
|
|
97
|
-
allowAll
|
|
98
|
-
});
|
|
99
|
-
const numericPort = Number(resolvedEnv.port);
|
|
100
|
-
if (!Number.isInteger(numericPort) || numericPort <= 0) throw new Error(`Invalid port "${resolvedEnv.port}". Provide a positive integer with --port or PORT.`);
|
|
101
|
-
_clack_prompts.log.step((0, node_util.styleText)("cyan", "Starting agent server..."));
|
|
102
|
-
_clack_prompts.log.info((0, node_util.styleText)("dim", `Config: ${resolvedEnv.agentConfigPath}`));
|
|
103
|
-
_clack_prompts.log.info((0, node_util.styleText)("dim", `Host: ${resolvedEnv.host}`));
|
|
104
|
-
_clack_prompts.log.info((0, node_util.styleText)("dim", `Port: ${resolvedEnv.port}`));
|
|
105
|
-
if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) _clack_prompts.log.warn((0, node_util.styleText)("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
|
|
106
|
-
if (!await isPortAvailable(numericPort, resolvedEnv.host)) {
|
|
107
|
-
_clack_prompts.log.error((0, node_util.styleText)("red", `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`));
|
|
108
|
-
node_process.default.exit(1);
|
|
109
|
-
}
|
|
110
|
-
await require_shell.spawnAsync(node_process.default.execPath, [serverPath], {
|
|
111
|
-
env: resolvedEnv.env,
|
|
112
|
-
cwd: node_process.default.cwd()
|
|
113
|
-
});
|
|
114
|
-
await report("success");
|
|
115
|
-
} catch (error) {
|
|
116
|
-
await report("failed");
|
|
117
|
-
_clack_prompts.log.error((0, node_util.styleText)("red", "Failed to start agent server"));
|
|
118
|
-
_clack_prompts.log.error(require_errors.getErrorMessage(error));
|
|
119
|
-
node_process.default.exit(1);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
//#endregion
|
|
123
|
-
exports.run = run;
|
|
124
|
-
|
|
125
|
-
//# sourceMappingURL=run-CZC17tSi.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run-CZC17tSi.cjs","names":["process","agentDefaults","path","net","process","Telemetry","path","agentDefaults","spawnAsync","getErrorMessage"],"sources":["../src/runners/agent/utils.ts","../src/runners/agent/run.ts"],"sourcesContent":["import net from 'node:net'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { agentDefaults } from '../../constants.ts'\n\ntype AgentStartEnvironmentInput = {\n /**\n * TCP port for the HTTP server. When `undefined`, falls back to `PORT` env var or the default (`3000`).\n */\n port: string | undefined\n /**\n * Hostname the HTTP server binds to.\n */\n host: string\n /**\n * Explicit path to the Kubb config file. When `undefined`, falls back to `KUBB_AGENT_CONFIG` or the default filename.\n */\n configPath: string | undefined\n /**\n * Grants the agent permission to write generated files to the filesystem.\n */\n allowWrite: boolean\n /**\n * Grants all agent permissions, including filesystem writes. Implies `allowWrite`.\n */\n allowAll: boolean\n}\n\ntype ResolvedAgentStartEnvironment = {\n /**\n * Final port string after merging CLI flag, `PORT` env var, and the default.\n */\n port: string\n /**\n * Final hostname after merging CLI flag, `HOST` env var, and the default.\n */\n host: string\n /**\n * Effective write-permission flag, accounting for `allowAll` and `KUBB_AGENT_ALLOW_WRITE`.\n */\n allowWrite: boolean\n /**\n * Effective all-permissions flag, accounting for `KUBB_AGENT_ALLOW_ALL`.\n */\n allowAll: boolean\n /**\n * Absolute path to the Kubb config file passed to the agent subprocess.\n */\n agentConfigPath: string\n /**\n * Merged `process.env` object with all resolved agent environment variables applied.\n */\n env: NodeJS.ProcessEnv\n}\n\n/**\n * Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.\n */\nexport function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: AgentStartEnvironmentInput): ResolvedAgentStartEnvironment {\n const resolvedPort = port ?? process.env.PORT ?? agentDefaults.port\n const resolvedHost = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)\n const resolvedAllowAll = allowAll || process.env.KUBB_AGENT_ALLOW_ALL === 'true'\n const resolvedAllowWrite = resolvedAllowAll || allowWrite || process.env.KUBB_AGENT_ALLOW_WRITE === 'true'\n const agentRoot = process.env.KUBB_AGENT_ROOT ?? process.cwd()\n const agentConfigPath = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)\n\n return {\n port: resolvedPort,\n host: resolvedHost,\n allowWrite: resolvedAllowWrite,\n allowAll: resolvedAllowAll,\n agentConfigPath,\n env: {\n ...process.env,\n PORT: resolvedPort,\n HOST: resolvedHost,\n KUBB_AGENT_ROOT: agentRoot,\n KUBB_AGENT_CONFIG: agentConfigPath,\n KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),\n KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),\n KUBB_AGENT_TOKEN: process.env.KUBB_AGENT_TOKEN,\n KUBB_AGENT_RETRY_TIMEOUT: process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,\n KUBB_STUDIO_URL: process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl,\n },\n }\n}\n\nexport function 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","import { createRequire } from 'node:module'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { spawnAsync, getErrorMessage } from '@internals/utils'\nimport { Telemetry } from '@kubb/core'\nimport { agentDefaults } from '../../constants.ts'\nimport { isPortAvailable, resolveAgentStartEnvironment } from './utils.ts'\n\ntype AgentStartOptions = {\n /**\n * TCP port for the HTTP server. When `undefined`, falls back to `PORT` env var or the default (`3000`).\n */\n port: string | undefined\n /**\n * Hostname the HTTP server binds to.\n *\n * @default 'localhost'\n */\n host: string\n /**\n * Explicit path to the Kubb config file. When `undefined`, falls back to `KUBB_AGENT_CONFIG` or the default filename.\n */\n configPath: string | undefined\n /**\n * Grants the agent permission to write generated files to the filesystem.\n */\n allowWrite: boolean\n /**\n * Grants all agent permissions, including filesystem writes. Implies `allowWrite`.\n */\n allowAll: boolean\n /**\n * Current `@kubb/cli` version string, used for the telemetry payload.\n */\n version: string\n}\n\n/**\n * Spawns the Kubb Agent HTTP server as a Node.js subprocess.\n * Resolves config from CLI flags and environment variables, validates the port, and exits with code 1 on failure.\n */\nexport async function run({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {\n const hrStart = process.hrtime()\n const report = (status: 'success' | 'failed') => Telemetry.send(Telemetry.build({ command: 'agent', kubbVersion: version, hrStart, status }))\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, createRequire is CJS/ESM compatible (import.meta.resolve is ESM-only)\n const require = createRequire(import.meta.url)\n let agentPkgPath: string\n try {\n agentPkgPath = require.resolve('@kubb/agent/package.json')\n } catch (_e) {\n console.error(styleText('red', 'The @kubb/agent package is not installed.'))\n console.error('')\n console.error('Install it with:')\n console.error(styleText('cyan', ' npm install @kubb/agent'))\n console.error(styleText('cyan', ' # or'))\n console.error(styleText('cyan', ' pnpm install @kubb/agent'))\n console.error('')\n process.exit(1)\n }\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n const resolvedEnv = resolveAgentStartEnvironment({\n port,\n host,\n configPath,\n allowWrite,\n allowAll,\n })\n const numericPort = Number(resolvedEnv.port)\n\n if (!Number.isInteger(numericPort) || numericPort <= 0) {\n throw new Error(`Invalid port \"${resolvedEnv.port}\". Provide a positive integer with --port or PORT.`)\n }\n\n clack.log.step(styleText('cyan', 'Starting agent server...'))\n clack.log.info(styleText('dim', `Config: ${resolvedEnv.agentConfigPath}`))\n clack.log.info(styleText('dim', `Host: ${resolvedEnv.host}`))\n clack.log.info(styleText('dim', `Port: ${resolvedEnv.port}`))\n if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) {\n clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))\n }\n\n if (!(await isPortAvailable(numericPort, resolvedEnv.host))) {\n clack.log.error(styleText('red', `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`))\n process.exit(1)\n }\n\n // Spawns the server as a detached background process so the CLI can exit independently.\n // Reuse the runtime that launched the CLI (Bun or Node) via process.execPath so the\n // agent stays on the same runtime instead of forcing a `node` binary that may be absent.\n await spawnAsync(process.execPath, [serverPath], {\n env: resolvedEnv.env,\n cwd: process.cwd(),\n })\n\n await report('success')\n } catch (error) {\n await report('failed')\n clack.log.error(styleText('red', 'Failed to start agent server'))\n clack.log.error(getErrorMessage(error))\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,6BAA6B,EAAE,MAAM,MAAM,YAAY,YAAY,YAAuE;CACxJ,MAAM,eAAe,QAAQA,aAAAA,QAAQ,IAAI,QAAQC,kBAAAA,cAAc;CAC/D,MAAM,eAAe,SAASA,kBAAAA,cAAc,OAAO,OAAQD,aAAAA,QAAQ,IAAI,QAAQC,kBAAAA,cAAc;CAC7F,MAAM,mBAAmB,YAAYD,aAAAA,QAAQ,IAAI,yBAAyB;CAC1E,MAAM,qBAAqB,oBAAoB,cAAcA,aAAAA,QAAQ,IAAI,2BAA2B;CACpG,MAAM,YAAYA,aAAAA,QAAQ,IAAI,mBAAmBA,aAAA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OAAA,GAAA,UAAA,UAAA,CAAgB,OAAO,QAAQ,YAAY,KAAK,sFAAsF,CAAC;GACjJ,aAAA,QAAQ,KAAK,CAAC;EAChB;EAKA,MAAMC,cAAAA,WAAWJ,aAAAA,QAAQ,UAAU,CAAC,UAAU,GAAG;GAC/C,KAAK,YAAY;GACjB,KAAKA,aAAAA,QAAQ,IAAI;EACnB,CAAC;EAED,MAAM,OAAO,SAAS;CACxB,SAAS,OAAO;EACd,MAAM,OAAO,QAAQ;EACrB,eAAM,IAAI,OAAA,GAAA,UAAA,UAAA,CAAgB,OAAO,8BAA8B,CAAC;EAChE,eAAM,IAAI,MAAMK,eAAAA,gBAAgB,KAAK,CAAC;EACtC,aAAA,QAAQ,KAAK,CAAC;CAChB;AACF"}
|
package/dist/run-CvEVkbIx.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run-CvEVkbIx.js","names":["process","process"],"sources":["../../../internals/utils/src/packageManager.ts","../../../internals/shared/src/init.ts","../src/runners/init/utils.ts","../src/runners/init/run.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { join } from 'node:path'\n\n/**\n * Supported package manager identifiers.\n *\n * @example\n * ```ts\n * const pm: PackageManagerName = 'pnpm'\n * ```\n */\nexport type PackageManagerName = 'npm' | 'pnpm' | 'yarn' | 'bun'\n\n/**\n * Metadata describing a package manager's lock file and install command.\n */\nexport interface PackageManagerInfo {\n /**\n * Identifier used in CLI commands, e.g. `pnpm`, `yarn`.\n */\n name: PackageManagerName\n /**\n * Lock file name that uniquely identifies this package manager in a project root.\n */\n lockFile: string\n /**\n * Subcommands passed to the package manager binary to install a dev dependency.\n */\n installCommand: ReadonlyArray<string>\n}\n/**\n * Metadata for each supported package manager, keyed by its short name.\n *\n * @example\n * ```ts\n * packageManagers.pnpm.installCommand // ['add', '-D']\n * packageManagers.npm.lockFile // 'package-lock.json'\n * ```\n */\nconst packageManagers: Record<PackageManagerName, PackageManagerInfo> = {\n pnpm: {\n name: 'pnpm',\n lockFile: 'pnpm-lock.yaml',\n installCommand: ['add', '-D'],\n },\n yarn: {\n name: 'yarn',\n lockFile: 'yarn.lock',\n installCommand: ['add', '-D'],\n },\n bun: {\n name: 'bun',\n lockFile: 'bun.lockb',\n installCommand: ['add', '-d'],\n },\n npm: {\n name: 'npm',\n lockFile: 'package-lock.json',\n installCommand: ['install', '--save-dev'],\n },\n}\n\n/**\n * Minimal shape of `package.json` fields read during detection.\n */\ntype PackageJson = {\n /**\n * The `packageManager` field from `package.json` (e.g. `\"pnpm@9.0.0\"`).\n */\n packageManager?: string\n}\n\n/**\n * Detects the active package manager for the given directory.\n * Resolution order: `packageManager` field in `package.json`, then presence of a lock file.\n * Falls back to `npm` when no signal is found.\n *\n * @example\n * ```ts\n * detectPackageManager('/my/project') // { name: 'pnpm', lockFile: 'pnpm-lock.yaml', ... }\n * detectPackageManager() // falls back to npm when no lock file is found\n * ```\n */\nexport function detectPackageManager(cwd: string = process.cwd()): PackageManagerInfo {\n const packageJsonPath = join(cwd, 'package.json')\n if (existsSync(packageJsonPath)) {\n try {\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as PackageJson\n const pmField = packageJson.packageManager\n if (typeof pmField === 'string') {\n const name = pmField.split('@')[0]\n if (name && name in packageManagers) {\n return packageManagers[name as PackageManagerName]\n }\n }\n } catch {\n // Continue to lock file detection\n }\n }\n\n for (const pm of Object.values(packageManagers)) {\n if (existsSync(join(cwd, pm.lockFile))) {\n return pm\n }\n }\n\n return packageManagers.npm\n}\n","import { pluginDefaultConfigs } from './constants.ts'\nimport type { PluginOption } from './types.ts'\n\nexport function generateConfigFile({\n selectedPlugins,\n inputPath,\n outputPath,\n}: {\n selectedPlugins: PluginOption[]\n inputPath: string\n outputPath: string\n}): string {\n const imports = selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`).join('\\n')\n\n const pluginConfigs = selectedPlugins\n .map((plugin) => {\n const config = (pluginDefaultConfigs as Record<string, string>)[plugin.value] ?? `${plugin.importName}()`\n return ` ${config},`\n })\n .join('\\n')\n\n return `import { defineConfig } from 'kubb'\n${imports}\n\nexport default defineConfig({\n root: '.',\n input: {\n path: '${inputPath}',\n },\n output: {\n path: '${outputPath}',\n clean: true,\n },\n plugins: [\n${pluginConfigs}\n ],\n})\n`\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport type { PackageManagerInfo, PackageManagerName } from '@internals/utils'\nimport { spawnAsync } from '@internals/utils'\n\n/**\n * Returns `true` when a `package.json` exists at `cwd`.\n */\nexport function hasPackageJson(cwd: string = process.cwd()): boolean {\n return fs.existsSync(path.join(cwd, 'package.json'))\n}\n\n/**\n * Initializes a new `package.json` at `cwd` using the detected package manager.\n */\nexport async function initPackageJson(cwd: string, packageManager: PackageManagerInfo): Promise<void> {\n const commands: Record<PackageManagerName, Array<string>> = {\n npm: ['init', '-y'],\n pnpm: ['init'],\n yarn: ['init', '-y'],\n bun: ['init', '-y'],\n }\n\n await spawnAsync(packageManager.name, commands[packageManager.name], { cwd })\n}\n\n/**\n * Installs the given packages at `cwd` using the detected package manager.\n */\nexport async function installPackages(packages: Array<string>, packageManager: PackageManagerInfo, cwd: string = process.cwd()): Promise<void> {\n await spawnAsync(packageManager.name, [...packageManager.installCommand, ...packages], { cwd })\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { detectPackageManager } from '@internals/utils'\nimport { availablePlugins, generateConfigFile, initDefaults, KUBB_CONFIG_FILENAME, type PluginOption } from '@internals/shared'\nimport { hasPackageJson, initPackageJson, installPackages } from './utils.ts'\n\nfunction cancelAndExit(message = 'Operation canceled.'): never {\n clack.cancel(message)\n process.exit(0)\n}\n\ntype InitOptions = {\n /**\n * When `true`, skips all interactive prompts and uses default values.\n */\n yes: boolean\n /**\n * Current `@kubb/cli` version string, shown in the outro and used for package installation.\n */\n version: string\n /**\n * Input path flag value from `--input`. When provided, skips the input prompt.\n */\n input?: string\n /**\n * Output directory flag value from `--output`. When provided, skips the output prompt.\n */\n output?: string\n /**\n * Comma-separated plugin list from `--plugins`, e.g. `'plugin-ts,plugin-zod'`. When provided, skips the plugin selection prompt.\n */\n plugins?: string\n}\n\n/**\n * Runs the interactive Kubb scaffolding wizard.\n * Detects the package manager, prompts for input/output paths and plugins, installs packages, and writes `kubb.config.ts`.\n * Pass `yes: true` to skip all prompts and use defaults.\n */\nexport async function run({ yes, version, input: inputFlag, output: outputFlag, plugins: pluginsFlag }: InitOptions): Promise<void> {\n const cwd = process.cwd()\n\n clack.intro(styleText('bgCyan', styleText('black', ' Kubb Init ')))\n\n /**\n * Returns `flag` when provided, the `defaultValue` when `yes` is set,\n * or calls `prompt()` for interactive input. Exits on cancellation.\n */\n async function resolveOrPrompt<T>(flag: T | undefined, defaultValue: T, logLabel: string, prompt: () => Promise<T | symbol>): Promise<T> {\n if (flag !== undefined) {\n clack.log.info(`${logLabel}: ${styleText('cyan', String(flag))}`)\n return flag\n }\n if (yes) {\n clack.log.info(`${logLabel}: ${styleText('cyan', String(defaultValue))}`)\n return defaultValue\n }\n const result = await prompt()\n if (clack.isCancel(result)) cancelAndExit()\n return result as T\n }\n\n try {\n // Check/create package.json, detect package manager once after the block\n if (!hasPackageJson(cwd)) {\n if (!yes) {\n const shouldInit = await clack.confirm({\n message: 'No package.json found. Would you like to create one?',\n initialValue: true,\n })\n\n if (clack.isCancel(shouldInit) || !shouldInit) {\n cancelAndExit()\n }\n }\n\n const packageManager = detectPackageManager(cwd)\n const spinner = clack.spinner()\n spinner.start(`Initializing package.json with ${packageManager.name}`)\n await initPackageJson(cwd, packageManager)\n spinner.stop(`Created package.json with ${packageManager.name}`)\n }\n\n const packageManager = detectPackageManager(cwd)\n if (hasPackageJson(cwd)) {\n clack.log.info(`Detected package manager: ${styleText('cyan', packageManager.name)}`)\n }\n\n // Prompt for OpenAPI spec path\n const inputPath = await resolveOrPrompt(inputFlag, initDefaults.inputPath, 'Using input path', () =>\n clack.text({\n message: 'Where is your OpenAPI specification located?',\n placeholder: initDefaults.inputPath,\n defaultValue: initDefaults.inputPath,\n validate: (value) => {\n if (!value) return 'Input path is required'\n },\n }),\n )\n\n // Prompt for output directory\n const outputPath = await resolveOrPrompt(outputFlag, initDefaults.outputPath, 'Using output path', () =>\n clack.text({\n message: 'Where should the generated files be output?',\n placeholder: initDefaults.outputPath,\n defaultValue: initDefaults.outputPath,\n validate: (value) => {\n if (!value) return 'Output path is required'\n },\n }),\n )\n\n // Plugin selection\n const defaultPlugins = availablePlugins.filter((p) => (initDefaults.plugins as ReadonlyArray<string>).includes(p.value))\n const pluginLabel = (plugins: Array<PluginOption>) => styleText('cyan', plugins.map((p) => p.label).join(', '))\n\n const selectedPlugins: Array<PluginOption> = await (async () => {\n if (pluginsFlag) {\n const requested = pluginsFlag\n .split(',')\n .map((v) => v.trim())\n .filter(Boolean)\n const plugins = availablePlugins.filter((p) => requested.includes(p.value))\n if (plugins.length === 0) {\n clack.log.warn(`No valid plugins found in --plugins value; falling back to default: ${pluginLabel(defaultPlugins)}`)\n return defaultPlugins\n }\n clack.log.info(`Using plugins: ${pluginLabel(plugins)}`)\n return plugins\n }\n if (yes) {\n clack.log.info(`Using plugins: ${pluginLabel(defaultPlugins)}`)\n return defaultPlugins\n }\n const values = await clack.multiselect({\n message: 'Select plugins to use:',\n options: availablePlugins.map(({ value, label, hint }) => ({ value, label, hint })),\n initialValues: [...initDefaults.plugins],\n required: true,\n })\n if (clack.isCancel(values)) cancelAndExit()\n return availablePlugins.filter((p) => (values as Array<string>).includes(p.value))\n })()\n\n // Install packages\n const packagesToInstall = ['kubb', ...selectedPlugins.map((p) => p.packageName)]\n\n const spinner = clack.spinner()\n spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`)\n\n try {\n await installPackages(packagesToInstall, packageManager, cwd)\n spinner.stop(`Installed ${packagesToInstall.length} packages`)\n } catch (error) {\n spinner.stop('Installation failed')\n throw error\n }\n\n // Generate config file\n const configSpinner = clack.spinner()\n configSpinner.start(`Creating ${KUBB_CONFIG_FILENAME}`)\n\n const configContent = generateConfigFile({ selectedPlugins, inputPath, outputPath })\n const configPath = path.join(cwd, KUBB_CONFIG_FILENAME)\n\n if (fs.existsSync(configPath)) {\n configSpinner.stop(`${KUBB_CONFIG_FILENAME} already exists`)\n\n if (!yes) {\n const shouldOverwrite = await clack.confirm({\n message: `${KUBB_CONFIG_FILENAME} already exists. Overwrite?`,\n initialValue: false,\n })\n\n if (clack.isCancel(shouldOverwrite) || !shouldOverwrite) {\n cancelAndExit('Keeping existing configuration. Packages have been installed.')\n }\n }\n\n configSpinner.start(`Overwriting ${KUBB_CONFIG_FILENAME}`)\n }\n\n await fs.promises.writeFile(configPath, configContent, 'utf-8')\n\n configSpinner.stop(`Created ${KUBB_CONFIG_FILENAME}`)\n\n clack.outro(\n styleText('green', '✓ All set!') +\n '\\n\\n' +\n styleText('dim', 'Next steps:') +\n '\\n' +\n styleText('cyan', ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) +\n '\\n' +\n styleText('cyan', ' 2. Generate code with: npx kubb generate') +\n '\\n' +\n styleText('cyan', ' Or start a stream server with: npx kubb agent start') +\n '\\n' +\n styleText('cyan', ` 3. Find generated files in: ${outputPath}`) +\n '\\n\\n' +\n styleText('dim', `Using ${packageManager.name} • Kubb v${version}`),\n )\n } catch (error) {\n clack.log.error(styleText('red', 'An error occurred during initialization'))\n if (error instanceof Error) {\n clack.log.error(error.message)\n }\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuCA,MAAM,kBAAkE;CACtE,MAAM;EACJ,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,OAAO,IAAI;CAC9B;CACA,MAAM;EACJ,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,OAAO,IAAI;CAC9B;CACA,KAAK;EACH,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,OA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,2CAA2C,WAAW,IACxE,OACA,UAAU,QAAQ,4CAA4C,IAC9D,OACA,UAAU,QAAQ,0DAA0D,IAC5E,OACA,UAAU,QAAQ,iCAAiC,YAAY,IAC/D,SACA,UAAU,OAAO,SAAS,eAAe,KAAK,WAAW,SAAS,CACtE;CACF,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,UAAU,OAAO,yCAAyC,CAAC;EAC3E,IAAI,iBAAiB,OACnB,MAAM,IAAI,MAAM,MAAM,OAAO;EAE/B,UAAQ,KAAK,CAAC;CAChB;AACF"}
|
|
@@ -1,50 +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:
|
|
8
|
-
'Start the Kubb Agent HTTP server. Exposes a REST API that accepts a kubb.config.ts patch and returns generated code as a stream. Use --allow-write to also write files to disk.',
|
|
9
|
-
examples: ['kubb agent start', 'kubb agent start --port 4000', 'kubb agent start --allow-write', 'kubb agent start --config ./kubb.config.ts --allow-all'],
|
|
10
|
-
options: {
|
|
11
|
-
config: {
|
|
12
|
-
type: 'string',
|
|
13
|
-
description: 'Path to the Kubb config file',
|
|
14
|
-
short: 'c',
|
|
15
|
-
},
|
|
16
|
-
port: {
|
|
17
|
-
type: 'string',
|
|
18
|
-
description: 'Port the HTTP server listens on',
|
|
19
|
-
short: 'p',
|
|
20
|
-
default: agentDefaults.port,
|
|
21
|
-
},
|
|
22
|
-
host: {
|
|
23
|
-
type: 'string',
|
|
24
|
-
description: 'Hostname the HTTP server binds to',
|
|
25
|
-
default: agentDefaults.host,
|
|
26
|
-
},
|
|
27
|
-
'allow-write': {
|
|
28
|
-
type: 'boolean',
|
|
29
|
-
description: 'Write generated files to the filesystem. When omitted, output is streamed only and no files are written.',
|
|
30
|
-
default: false,
|
|
31
|
-
},
|
|
32
|
-
'allow-all': {
|
|
33
|
-
type: 'boolean',
|
|
34
|
-
description: 'Grant all permissions (implies --allow-write).',
|
|
35
|
-
default: false,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
async run({ values }) {
|
|
39
|
-
const { run } = await import('../../runners/agent/run.ts')
|
|
40
|
-
|
|
41
|
-
await run({
|
|
42
|
-
port: values.port !== undefined ? values.port : undefined,
|
|
43
|
-
host: values.host,
|
|
44
|
-
configPath: values.config,
|
|
45
|
-
allowWrite: values['allow-write'],
|
|
46
|
-
allowAll: values['allow-all'],
|
|
47
|
-
version,
|
|
48
|
-
})
|
|
49
|
-
},
|
|
50
|
-
})
|
package/src/commands/agent.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from '@internals/utils'
|
|
2
|
-
import { command as startCommand } from './agent/start.ts'
|
|
3
|
-
|
|
4
|
-
export const command = defineCommand({
|
|
5
|
-
name: 'agent',
|
|
6
|
-
description:
|
|
7
|
-
'Manage the Kubb Agent — an HTTP server that lets AI agents trigger code generation programmatically via a REST API. Useful when an AI workflow needs to generate code without direct CLI access.',
|
|
8
|
-
examples: ['kubb agent start', 'kubb agent start --port 4000 --allow-write', 'kubb agent start --config ./kubb.config.ts --allow-all'],
|
|
9
|
-
subCommands: [startCommand],
|
|
10
|
-
})
|
package/src/runners/agent/run.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import process from 'node:process'
|
|
4
|
-
import { styleText } from 'node:util'
|
|
5
|
-
import * as clack from '@clack/prompts'
|
|
6
|
-
import { spawnAsync, getErrorMessage } from '@internals/utils'
|
|
7
|
-
import { Telemetry } from '@kubb/core'
|
|
8
|
-
import { agentDefaults } from '../../constants.ts'
|
|
9
|
-
import { isPortAvailable, resolveAgentStartEnvironment } from './utils.ts'
|
|
10
|
-
|
|
11
|
-
type AgentStartOptions = {
|
|
12
|
-
/**
|
|
13
|
-
* TCP port for the HTTP server. When `undefined`, falls back to `PORT` env var or the default (`3000`).
|
|
14
|
-
*/
|
|
15
|
-
port: string | undefined
|
|
16
|
-
/**
|
|
17
|
-
* Hostname the HTTP server binds to.
|
|
18
|
-
*
|
|
19
|
-
* @default 'localhost'
|
|
20
|
-
*/
|
|
21
|
-
host: string
|
|
22
|
-
/**
|
|
23
|
-
* Explicit path to the Kubb config file. When `undefined`, falls back to `KUBB_AGENT_CONFIG` or the default filename.
|
|
24
|
-
*/
|
|
25
|
-
configPath: string | undefined
|
|
26
|
-
/**
|
|
27
|
-
* Grants the agent permission to write generated files to the filesystem.
|
|
28
|
-
*/
|
|
29
|
-
allowWrite: boolean
|
|
30
|
-
/**
|
|
31
|
-
* Grants all agent permissions, including filesystem writes. Implies `allowWrite`.
|
|
32
|
-
*/
|
|
33
|
-
allowAll: boolean
|
|
34
|
-
/**
|
|
35
|
-
* Current `@kubb/cli` version string, used for the telemetry payload.
|
|
36
|
-
*/
|
|
37
|
-
version: string
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Spawns the Kubb Agent HTTP server as a Node.js subprocess.
|
|
42
|
-
* Resolves config from CLI flags and environment variables, validates the port, and exits with code 1 on failure.
|
|
43
|
-
*/
|
|
44
|
-
export async function run({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {
|
|
45
|
-
const hrStart = process.hrtime()
|
|
46
|
-
const report = (status: 'success' | 'failed') => Telemetry.send(Telemetry.build({ command: 'agent', kubbVersion: version, hrStart, status }))
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
// Load .env file into process.env using Node.js built-in (v20.12.0+)
|
|
50
|
-
try {
|
|
51
|
-
process.loadEnvFile()
|
|
52
|
-
} catch {
|
|
53
|
-
// .env file may not exist. Ignore
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Resolve the @kubb/agent package path, createRequire is CJS/ESM compatible (import.meta.resolve is ESM-only)
|
|
57
|
-
const require = createRequire(import.meta.url)
|
|
58
|
-
let agentPkgPath: string
|
|
59
|
-
try {
|
|
60
|
-
agentPkgPath = require.resolve('@kubb/agent/package.json')
|
|
61
|
-
} catch (_e) {
|
|
62
|
-
console.error(styleText('red', 'The @kubb/agent package is not installed.'))
|
|
63
|
-
console.error('')
|
|
64
|
-
console.error('Install it with:')
|
|
65
|
-
console.error(styleText('cyan', ' npm install @kubb/agent'))
|
|
66
|
-
console.error(styleText('cyan', ' # or'))
|
|
67
|
-
console.error(styleText('cyan', ' pnpm install @kubb/agent'))
|
|
68
|
-
console.error('')
|
|
69
|
-
process.exit(1)
|
|
70
|
-
}
|
|
71
|
-
const agentDir = path.dirname(agentPkgPath)
|
|
72
|
-
const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)
|
|
73
|
-
|
|
74
|
-
const resolvedEnv = resolveAgentStartEnvironment({
|
|
75
|
-
port,
|
|
76
|
-
host,
|
|
77
|
-
configPath,
|
|
78
|
-
allowWrite,
|
|
79
|
-
allowAll,
|
|
80
|
-
})
|
|
81
|
-
const numericPort = Number(resolvedEnv.port)
|
|
82
|
-
|
|
83
|
-
if (!Number.isInteger(numericPort) || numericPort <= 0) {
|
|
84
|
-
throw new Error(`Invalid port "${resolvedEnv.port}". Provide a positive integer with --port or PORT.`)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
clack.log.step(styleText('cyan', 'Starting agent server...'))
|
|
88
|
-
clack.log.info(styleText('dim', `Config: ${resolvedEnv.agentConfigPath}`))
|
|
89
|
-
clack.log.info(styleText('dim', `Host: ${resolvedEnv.host}`))
|
|
90
|
-
clack.log.info(styleText('dim', `Port: ${resolvedEnv.port}`))
|
|
91
|
-
if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) {
|
|
92
|
-
clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (!(await isPortAvailable(numericPort, resolvedEnv.host))) {
|
|
96
|
-
clack.log.error(styleText('red', `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`))
|
|
97
|
-
process.exit(1)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Spawns the server as a detached background process so the CLI can exit independently.
|
|
101
|
-
// Reuse the runtime that launched the CLI (Bun or Node) via process.execPath so the
|
|
102
|
-
// agent stays on the same runtime instead of forcing a `node` binary that may be absent.
|
|
103
|
-
await spawnAsync(process.execPath, [serverPath], {
|
|
104
|
-
env: resolvedEnv.env,
|
|
105
|
-
cwd: process.cwd(),
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
await report('success')
|
|
109
|
-
} catch (error) {
|
|
110
|
-
await report('failed')
|
|
111
|
-
clack.log.error(styleText('red', 'Failed to start agent server'))
|
|
112
|
-
clack.log.error(getErrorMessage(error))
|
|
113
|
-
process.exit(1)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import net from 'node:net'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import process from 'node:process'
|
|
4
|
-
import { agentDefaults } from '../../constants.ts'
|
|
5
|
-
|
|
6
|
-
type AgentStartEnvironmentInput = {
|
|
7
|
-
/**
|
|
8
|
-
* TCP port for the HTTP server. When `undefined`, falls back to `PORT` env var or the default (`3000`).
|
|
9
|
-
*/
|
|
10
|
-
port: string | undefined
|
|
11
|
-
/**
|
|
12
|
-
* Hostname the HTTP server binds to.
|
|
13
|
-
*/
|
|
14
|
-
host: string
|
|
15
|
-
/**
|
|
16
|
-
* Explicit path to the Kubb config file. When `undefined`, falls back to `KUBB_AGENT_CONFIG` or the default filename.
|
|
17
|
-
*/
|
|
18
|
-
configPath: string | undefined
|
|
19
|
-
/**
|
|
20
|
-
* Grants the agent permission to write generated files to the filesystem.
|
|
21
|
-
*/
|
|
22
|
-
allowWrite: boolean
|
|
23
|
-
/**
|
|
24
|
-
* Grants all agent permissions, including filesystem writes. Implies `allowWrite`.
|
|
25
|
-
*/
|
|
26
|
-
allowAll: boolean
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
type ResolvedAgentStartEnvironment = {
|
|
30
|
-
/**
|
|
31
|
-
* Final port string after merging CLI flag, `PORT` env var, and the default.
|
|
32
|
-
*/
|
|
33
|
-
port: string
|
|
34
|
-
/**
|
|
35
|
-
* Final hostname after merging CLI flag, `HOST` env var, and the default.
|
|
36
|
-
*/
|
|
37
|
-
host: string
|
|
38
|
-
/**
|
|
39
|
-
* Effective write-permission flag, accounting for `allowAll` and `KUBB_AGENT_ALLOW_WRITE`.
|
|
40
|
-
*/
|
|
41
|
-
allowWrite: boolean
|
|
42
|
-
/**
|
|
43
|
-
* Effective all-permissions flag, accounting for `KUBB_AGENT_ALLOW_ALL`.
|
|
44
|
-
*/
|
|
45
|
-
allowAll: boolean
|
|
46
|
-
/**
|
|
47
|
-
* Absolute path to the Kubb config file passed to the agent subprocess.
|
|
48
|
-
*/
|
|
49
|
-
agentConfigPath: string
|
|
50
|
-
/**
|
|
51
|
-
* Merged `process.env` object with all resolved agent environment variables applied.
|
|
52
|
-
*/
|
|
53
|
-
env: NodeJS.ProcessEnv
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.
|
|
58
|
-
*/
|
|
59
|
-
export function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: AgentStartEnvironmentInput): ResolvedAgentStartEnvironment {
|
|
60
|
-
const resolvedPort = port ?? process.env.PORT ?? agentDefaults.port
|
|
61
|
-
const resolvedHost = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)
|
|
62
|
-
const resolvedAllowAll = allowAll || process.env.KUBB_AGENT_ALLOW_ALL === 'true'
|
|
63
|
-
const resolvedAllowWrite = resolvedAllowAll || allowWrite || process.env.KUBB_AGENT_ALLOW_WRITE === 'true'
|
|
64
|
-
const agentRoot = process.env.KUBB_AGENT_ROOT ?? process.cwd()
|
|
65
|
-
const agentConfigPath = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
port: resolvedPort,
|
|
69
|
-
host: resolvedHost,
|
|
70
|
-
allowWrite: resolvedAllowWrite,
|
|
71
|
-
allowAll: resolvedAllowAll,
|
|
72
|
-
agentConfigPath,
|
|
73
|
-
env: {
|
|
74
|
-
...process.env,
|
|
75
|
-
PORT: resolvedPort,
|
|
76
|
-
HOST: resolvedHost,
|
|
77
|
-
KUBB_AGENT_ROOT: agentRoot,
|
|
78
|
-
KUBB_AGENT_CONFIG: agentConfigPath,
|
|
79
|
-
KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),
|
|
80
|
-
KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),
|
|
81
|
-
KUBB_AGENT_TOKEN: process.env.KUBB_AGENT_TOKEN,
|
|
82
|
-
KUBB_AGENT_RETRY_TIMEOUT: process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,
|
|
83
|
-
KUBB_STUDIO_URL: process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl,
|
|
84
|
-
},
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function isPortAvailable(port: number, host: string): Promise<boolean> {
|
|
89
|
-
return new Promise((resolve) => {
|
|
90
|
-
const server = net.createServer()
|
|
91
|
-
server.once('error', () => resolve(false))
|
|
92
|
-
server.once('listening', () => {
|
|
93
|
-
server.close()
|
|
94
|
-
resolve(true)
|
|
95
|
-
})
|
|
96
|
-
server.listen(port, host)
|
|
97
|
-
})
|
|
98
|
-
}
|