@kubb/cli 5.0.0-alpha.9 → 5.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/README.md +4 -2
  2. package/bin/kubb.js +6 -0
  3. package/dist/{agent-BKphjOIF.cjs → agent-0Nk--lcr.cjs} +5 -5
  4. package/dist/agent-0Nk--lcr.cjs.map +1 -0
  5. package/dist/agent-B_pirbeB.cjs +116 -0
  6. package/dist/agent-B_pirbeB.cjs.map +1 -0
  7. package/dist/{agent-5mmp7QzF.js → agent-DKeVuiUC.js} +5 -5
  8. package/dist/agent-DKeVuiUC.js.map +1 -0
  9. package/dist/agent-Ev5hU5hH.js +112 -0
  10. package/dist/agent-Ev5hU5hH.js.map +1 -0
  11. package/dist/{constants-D0XHAHeZ.cjs → constants-CnDXa1R6.cjs} +30 -60
  12. package/dist/constants-CnDXa1R6.cjs.map +1 -0
  13. package/dist/{constants-DJM9zCXm.js → constants-aL3CP_Wq.js} +23 -59
  14. package/dist/constants-aL3CP_Wq.js.map +1 -0
  15. package/dist/define-Bdn8j5VM.cjs +54 -0
  16. package/dist/define-Bdn8j5VM.cjs.map +1 -0
  17. package/dist/define-Ctii4bel.js +43 -0
  18. package/dist/define-Ctii4bel.js.map +1 -0
  19. package/dist/{errors-DBW0N9w4.cjs → errors-CLCjoSg0.cjs} +22 -6
  20. package/dist/errors-CLCjoSg0.cjs.map +1 -0
  21. package/dist/errors-CjPmyZHy.js +43 -0
  22. package/dist/errors-CjPmyZHy.js.map +1 -0
  23. package/dist/{generate-Rly1EXBN.js → generate-B3PZ6Dp-.js} +3 -3
  24. package/dist/generate-B3PZ6Dp-.js.map +1 -0
  25. package/dist/{generate-Cq5RDTBL.cjs → generate-B3jl4ukb.cjs} +559 -265
  26. package/dist/generate-B3jl4ukb.cjs.map +1 -0
  27. package/dist/{generate-DU5zzc54.cjs → generate-DL_7a7Wd.cjs} +3 -3
  28. package/dist/generate-DL_7a7Wd.cjs.map +1 -0
  29. package/dist/{generate-BHNyeQXl.js → generate-Dt_r0ELY.js} +552 -258
  30. package/dist/generate-Dt_r0ELY.js.map +1 -0
  31. package/dist/index.cjs +40 -18
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.js +40 -18
  34. package/dist/index.js.map +1 -1
  35. package/dist/{init-iN7e1XwI.js → init-Bj94Nvt8.js} +4 -4
  36. package/dist/init-Bj94Nvt8.js.map +1 -0
  37. package/dist/{init-BK6inBTR.cjs → init-CZ5Xq2Hd.cjs} +45 -58
  38. package/dist/init-CZ5Xq2Hd.cjs.map +1 -0
  39. package/dist/{init-CN1JFyGX.cjs → init-CyN1oyTF.cjs} +4 -4
  40. package/dist/init-CyN1oyTF.cjs.map +1 -0
  41. package/dist/{init-BQ6zfsnw.js → init-eNRlotJK.js} +41 -54
  42. package/dist/init-eNRlotJK.js.map +1 -0
  43. package/dist/{mcp-eP1S40LZ.js → mcp-BzW703d7.js} +4 -4
  44. package/dist/{mcp-eP1S40LZ.js.map → mcp-BzW703d7.js.map} +1 -1
  45. package/dist/{mcp-CONmm_xT.cjs → mcp-CLcDV4Jm.cjs} +5 -6
  46. package/dist/mcp-CLcDV4Jm.cjs.map +1 -0
  47. package/dist/{mcp-BiGUvbWP.js → mcp-D7EIR9fR.js} +4 -5
  48. package/dist/mcp-D7EIR9fR.js.map +1 -0
  49. package/dist/{mcp-T7Q4nWbT.cjs → mcp-ZY-ONTOp.cjs} +4 -4
  50. package/dist/{mcp-T7Q4nWbT.cjs.map → mcp-ZY-ONTOp.cjs.map} +1 -1
  51. package/dist/{package-BJ6ionm6.cjs → package-D8wlStAg.cjs} +2 -2
  52. package/dist/package-D8wlStAg.cjs.map +1 -0
  53. package/dist/package-Yo-9_m5C.js +6 -0
  54. package/dist/package-Yo-9_m5C.js.map +1 -0
  55. package/dist/{shell-7HPrTCJ5.cjs → shell-475fQKaX.cjs} +8 -3
  56. package/dist/shell-475fQKaX.cjs.map +1 -0
  57. package/dist/{shell-DqqWsHCD.js → shell-DLzN4fRo.js} +8 -3
  58. package/dist/shell-DLzN4fRo.js.map +1 -0
  59. package/dist/{telemetry-DZ7IrLAU.cjs → telemetry-DN95_2pF.cjs} +50 -8
  60. package/dist/telemetry-DN95_2pF.cjs.map +1 -0
  61. package/dist/{telemetry-BF3SMlH6.js → telemetry-LgT_sdPe.js} +48 -6
  62. package/dist/telemetry-LgT_sdPe.js.map +1 -0
  63. package/dist/{validate-DAZdX_0i.js → validate-Dplr99xO.js} +4 -4
  64. package/dist/validate-Dplr99xO.js.map +1 -0
  65. package/dist/{validate-DucFMytl.cjs → validate-_8mBa63G.cjs} +4 -4
  66. package/dist/validate-_8mBa63G.cjs.map +1 -0
  67. package/dist/{validate-BImbbx1t.js → validate-kLJoT_hi.js} +5 -13
  68. package/dist/validate-kLJoT_hi.js.map +1 -0
  69. package/dist/{validate-ujLCYSWU.cjs → validate-yKKzqEZ5.cjs} +6 -14
  70. package/dist/validate-yKKzqEZ5.cjs.map +1 -0
  71. package/package.json +47 -46
  72. package/src/commands/agent/start.ts +20 -4
  73. package/src/commands/generate.ts +35 -6
  74. package/src/commands/init.ts +6 -1
  75. package/src/commands/validate.ts +6 -1
  76. package/src/constants.ts +19 -38
  77. package/src/index.ts +7 -10
  78. package/src/loggers/clackLogger.ts +54 -46
  79. package/src/loggers/fileSystemLogger.ts +15 -16
  80. package/src/loggers/githubActionsLogger.ts +23 -24
  81. package/src/loggers/plainLogger.ts +22 -23
  82. package/src/runners/agent.ts +81 -34
  83. package/src/runners/generate.ts +90 -100
  84. package/src/runners/init.ts +24 -51
  85. package/src/runners/mcp.ts +17 -4
  86. package/src/runners/validate.ts +19 -15
  87. package/src/utils/executeHooks.ts +15 -15
  88. package/src/utils/flags.ts +1 -2
  89. package/src/utils/getConfig.ts +10 -0
  90. package/src/utils/getCosmiConfig.ts +21 -12
  91. package/src/utils/getSummary.ts +1 -1
  92. package/src/utils/runHook.ts +29 -13
  93. package/src/utils/telemetry.ts +16 -3
  94. package/bin/kubb.cjs +0 -18
  95. package/dist/agent-5mmp7QzF.js.map +0 -1
  96. package/dist/agent-BKphjOIF.cjs.map +0 -1
  97. package/dist/agent-BapvKB4r.cjs +0 -92
  98. package/dist/agent-BapvKB4r.cjs.map +0 -1
  99. package/dist/agent-CBrpIMMU.js +0 -88
  100. package/dist/agent-CBrpIMMU.js.map +0 -1
  101. package/dist/constants-D0XHAHeZ.cjs.map +0 -1
  102. package/dist/constants-DJM9zCXm.js.map +0 -1
  103. package/dist/define--M_JMcDC.js +0 -25
  104. package/dist/define--M_JMcDC.js.map +0 -1
  105. package/dist/define-D6Kfm7-Z.cjs +0 -36
  106. package/dist/define-D6Kfm7-Z.cjs.map +0 -1
  107. package/dist/errors-6mF_WKxg.js +0 -27
  108. package/dist/errors-6mF_WKxg.js.map +0 -1
  109. package/dist/errors-DBW0N9w4.cjs.map +0 -1
  110. package/dist/generate-BHNyeQXl.js.map +0 -1
  111. package/dist/generate-Cq5RDTBL.cjs.map +0 -1
  112. package/dist/generate-DU5zzc54.cjs.map +0 -1
  113. package/dist/generate-Rly1EXBN.js.map +0 -1
  114. package/dist/init-BK6inBTR.cjs.map +0 -1
  115. package/dist/init-BQ6zfsnw.js.map +0 -1
  116. package/dist/init-CN1JFyGX.cjs.map +0 -1
  117. package/dist/init-iN7e1XwI.js.map +0 -1
  118. package/dist/jiti-Cd3S0xwr.cjs +0 -16
  119. package/dist/jiti-Cd3S0xwr.cjs.map +0 -1
  120. package/dist/jiti-e08mD2Ph.js +0 -11
  121. package/dist/jiti-e08mD2Ph.js.map +0 -1
  122. package/dist/mcp-BiGUvbWP.js.map +0 -1
  123. package/dist/mcp-CONmm_xT.cjs.map +0 -1
  124. package/dist/package-BJ6ionm6.cjs.map +0 -1
  125. package/dist/package-BKZ0H3Zf.js +0 -6
  126. package/dist/package-BKZ0H3Zf.js.map +0 -1
  127. package/dist/shell-7HPrTCJ5.cjs.map +0 -1
  128. package/dist/shell-DqqWsHCD.js.map +0 -1
  129. package/dist/telemetry-BF3SMlH6.js.map +0 -1
  130. package/dist/telemetry-DZ7IrLAU.cjs.map +0 -1
  131. package/dist/validate-BImbbx1t.js.map +0 -1
  132. package/dist/validate-DAZdX_0i.js.map +0 -1
  133. package/dist/validate-DucFMytl.cjs.map +0 -1
  134. package/dist/validate-ujLCYSWU.cjs.map +0 -1
  135. package/src/utils/jiti.ts +0 -9
package/README.md CHANGED
@@ -4,12 +4,12 @@
4
4
  <img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
5
5
  </a>
6
6
 
7
-
8
7
  [![npm version][npm-version-src]][npm-version-href]
9
8
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
10
9
  [![Coverage][coverage-src]][coverage-href]
11
10
  [![License][license-src]][license-href]
12
11
  [![Sponsors][sponsors-src]][sponsors-href]
12
+
13
13
  <h4>
14
14
  <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
15
15
  <span> · </span>
@@ -38,11 +38,13 @@ npx kubb init -y
38
38
  ```
39
39
 
40
40
  Defaults when using `-y`:
41
+
41
42
  - Input path: `./openapi.yaml`
42
43
  - Output path: `./src/gen`
43
44
  - Plugins: OpenAPI Parser + TypeScript
44
45
 
45
46
  This command will:
47
+
46
48
  1. Detect or create a `package.json` if it doesn't exist
47
49
  2. Prompt you for your OpenAPI specification path (default: `./openapi.yaml`)
48
50
  3. Ask for the output directory for generated files (default: `./src/gen`)
@@ -59,6 +61,7 @@ npx kubb generate
59
61
  ```
60
62
 
61
63
  Options:
64
+
62
65
  - `-c, --config <path>` - Path to the Kubb config file
63
66
  - `-l, --logLevel <level>` - Set log level (silent, info, verbose, debug)
64
67
  - `-w, --watch` - Watch mode based on the input file
@@ -94,7 +97,6 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
94
97
  </a>
95
98
  </p>
96
99
 
97
-
98
100
  <!-- Badges -->
99
101
 
100
102
  [npm-version-src]: https://img.shields.io/npm/v/@kubb/cli?flat&colorA=18181B&colorB=f58517
package/bin/kubb.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ process.setSourceMapsEnabled?.(true)
3
+
4
+ const { run } = await import('../dist/index.js')
5
+ process.title = 'Kubb'
6
+ run(process.argv)
@@ -1,7 +1,7 @@
1
1
  require("./chunk-ByKO4r7w.cjs");
2
- const require_define = require("./define-D6Kfm7-Z.cjs");
3
- const require_package = require("./package-BJ6ionm6.cjs");
4
- const require_constants = require("./constants-D0XHAHeZ.cjs");
2
+ const require_define = require("./define-Bdn8j5VM.cjs");
3
+ const require_package = require("./package-D8wlStAg.cjs");
4
+ const require_constants = require("./constants-CnDXa1R6.cjs");
5
5
  //#region src/commands/agent/start.ts
6
6
  const command$1 = require_define.defineCommand({
7
7
  name: "start",
@@ -34,7 +34,7 @@ const command$1 = require_define.defineCommand({
34
34
  }
35
35
  },
36
36
  async run({ values }) {
37
- const { runAgentStart } = await Promise.resolve().then(() => require("./agent-BapvKB4r.cjs"));
37
+ const { runAgentStart } = await Promise.resolve().then(() => require("./agent-B_pirbeB.cjs"));
38
38
  await runAgentStart({
39
39
  port: values.port !== void 0 ? values.port : void 0,
40
40
  host: values.host,
@@ -55,4 +55,4 @@ const command = require_define.defineCommand({
55
55
  //#endregion
56
56
  exports.command = command;
57
57
 
58
- //# sourceMappingURL=agent-BKphjOIF.cjs.map
58
+ //# sourceMappingURL=agent-0Nk--lcr.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-0Nk--lcr.cjs","names":["command","defineCommand","agentDefaults","defineCommand","startCommand"],"sources":["../src/commands/agent/start.ts","../src/commands/agent.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport { version } from '../../../package.json'\nimport { agentDefaults } from '../../constants.ts'\n\nexport const command = defineCommand({\n name: 'start',\n description: 'Start the Agent server',\n options: {\n config: {\n type: 'string',\n description: 'Path to the Kubb config',\n short: 'c',\n },\n port: {\n type: 'string',\n description: `Port for the server (default: ${agentDefaults.port})`,\n short: 'p',\n },\n host: {\n type: 'string',\n description: 'Host for the server',\n default: agentDefaults.host,\n },\n 'allow-write': {\n type: 'boolean',\n description: 'Allow writing generated files to the filesystem. When not set, no files are written and the config patch is not persisted.',\n default: false,\n },\n 'allow-all': {\n type: 'boolean',\n description: 'Grant all permissions (implies --allow-write).',\n default: false,\n },\n },\n async run({ values }) {\n const { runAgentStart } = await import('../../runners/agent.ts')\n\n await runAgentStart({\n port: values.port !== undefined ? values.port : undefined,\n host: values.host,\n configPath: values.config,\n allowWrite: values['allow-write'],\n allowAll: values['allow-all'],\n version,\n })\n },\n})\n","import { defineCommand } from '@internals/utils'\nimport { command as startCommand } from './agent/start.ts'\n\nexport const command = defineCommand({\n name: 'agent',\n description: 'Manage the Kubb Agent server',\n subCommands: [startCommand],\n})\n"],"mappings":";;;;;AAIA,MAAaA,YAAUC,eAAAA,cAAc;CACnC,MAAM;CACN,aAAa;CACb,SAAS;EACP,QAAQ;GACN,MAAM;GACN,aAAa;GACb,OAAO;GACR;EACD,MAAM;GACJ,MAAM;GACN,aAAa,iCAAiCC,kBAAAA,cAAc,KAAK;GACjE,OAAO;GACR;EACD,MAAM;GACJ,MAAM;GACN,aAAa;GACb,SAASA,kBAAAA,cAAc;GACxB;EACD,eAAe;GACb,MAAM;GACN,aAAa;GACb,SAAS;GACV;EACD,aAAa;GACX,MAAM;GACN,aAAa;GACb,SAAS;GACV;EACF;CACD,MAAM,IAAI,EAAE,UAAU;EACpB,MAAM,EAAE,kBAAkB,MAAA,QAAA,SAAA,CAAA,WAAA,QAAM,uBAAA,CAAA;AAEhC,QAAM,cAAc;GAClB,MAAM,OAAO,SAAS,KAAA,IAAY,OAAO,OAAO,KAAA;GAChD,MAAM,OAAO;GACb,YAAY,OAAO;GACnB,YAAY,OAAO;GACnB,UAAU,OAAO;GACjB,SAAA,gBAAA;GACD,CAAC;;CAEL,CAAC;;;AC3CF,MAAa,UAAUC,eAAAA,cAAc;CACnC,MAAM;CACN,aAAa;CACb,aAAa,CAACC,UAAa;CAC5B,CAAC"}
@@ -0,0 +1,116 @@
1
+ const require_chunk = require("./chunk-ByKO4r7w.cjs");
2
+ const require_telemetry = require("./telemetry-DN95_2pF.cjs");
3
+ const require_shell = require("./shell-475fQKaX.cjs");
4
+ const require_constants = require("./constants-CnDXa1R6.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 node_process = require("node:process");
9
+ node_process = require_chunk.__toESM(node_process, 1);
10
+ let node_net = require("node:net");
11
+ node_net = require_chunk.__toESM(node_net, 1);
12
+ let node_url = require("node:url");
13
+ let _clack_prompts = require("@clack/prompts");
14
+ _clack_prompts = require_chunk.__toESM(_clack_prompts, 1);
15
+ //#region src/runners/agent.ts
16
+ /**
17
+ * Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.
18
+ */
19
+ function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }) {
20
+ const resolvedPort = port ?? node_process.env.PORT ?? require_constants.agentDefaults.port;
21
+ const resolvedHost = host !== require_constants.agentDefaults.host ? host : node_process.env.HOST ?? require_constants.agentDefaults.host;
22
+ const resolvedAllowAll = allowAll || node_process.env.KUBB_AGENT_ALLOW_ALL === "true";
23
+ const resolvedAllowWrite = resolvedAllowAll || allowWrite || node_process.env.KUBB_AGENT_ALLOW_WRITE === "true";
24
+ const agentRoot = node_process.env.KUBB_AGENT_ROOT ?? node_process.cwd();
25
+ const agentConfigPath = node_path.default.resolve(node_process.cwd(), configPath || node_process.env.KUBB_AGENT_CONFIG || require_constants.agentDefaults.configFile);
26
+ return {
27
+ port: resolvedPort,
28
+ host: resolvedHost,
29
+ allowWrite: resolvedAllowWrite,
30
+ allowAll: resolvedAllowAll,
31
+ agentConfigPath,
32
+ env: {
33
+ ...node_process.env,
34
+ PORT: resolvedPort,
35
+ HOST: resolvedHost,
36
+ KUBB_AGENT_ROOT: agentRoot,
37
+ KUBB_AGENT_CONFIG: agentConfigPath,
38
+ KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),
39
+ KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),
40
+ KUBB_AGENT_TOKEN: node_process.env.KUBB_AGENT_TOKEN,
41
+ KUBB_AGENT_RETRY_TIMEOUT: node_process.env.KUBB_AGENT_RETRY_TIMEOUT ?? require_constants.agentDefaults.retryTimeout,
42
+ KUBB_STUDIO_URL: node_process.env.KUBB_STUDIO_URL ?? require_constants.agentDefaults.studioUrl
43
+ }
44
+ };
45
+ }
46
+ function isPortAvailable(port, host) {
47
+ return new Promise((resolve) => {
48
+ const server = node_net.default.createServer();
49
+ server.once("error", () => resolve(false));
50
+ server.once("listening", () => {
51
+ server.close();
52
+ resolve(true);
53
+ });
54
+ server.listen(port, host);
55
+ });
56
+ }
57
+ async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }) {
58
+ const hrStart = node_process.hrtime();
59
+ try {
60
+ try {
61
+ node_process.loadEnvFile();
62
+ } catch {}
63
+ let agentPkgUrl;
64
+ try {
65
+ agentPkgUrl = {}.resolve("@kubb/agent/package.json");
66
+ } catch (_e) {
67
+ console.error(`Import of '@kubb/agent' is required to start the Agent server`);
68
+ node_process.exit(1);
69
+ }
70
+ const agentPkgPath = (0, node_url.fileURLToPath)(agentPkgUrl);
71
+ const agentDir = node_path.default.dirname(agentPkgPath);
72
+ const serverPath = node_path.default.join(agentDir, require_constants.agentDefaults.serverEntryPath);
73
+ const resolvedEnv = resolveAgentStartEnvironment({
74
+ port,
75
+ host,
76
+ configPath,
77
+ allowWrite,
78
+ allowAll
79
+ });
80
+ const numericPort = Number(resolvedEnv.port);
81
+ if (!Number.isInteger(numericPort) || numericPort <= 0) throw new Error(`Invalid port "${resolvedEnv.port}". Provide a positive integer with --port or PORT.`);
82
+ _clack_prompts.log.step((0, node_util.styleText)("cyan", "Starting agent server..."));
83
+ _clack_prompts.log.info((0, node_util.styleText)("dim", `Config: ${resolvedEnv.agentConfigPath}`));
84
+ _clack_prompts.log.info((0, node_util.styleText)("dim", `Host: ${resolvedEnv.host}`));
85
+ _clack_prompts.log.info((0, node_util.styleText)("dim", `Port: ${resolvedEnv.port}`));
86
+ 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."));
87
+ if (!await isPortAvailable(numericPort, resolvedEnv.host)) {
88
+ _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.`));
89
+ node_process.exit(1);
90
+ }
91
+ await require_shell.spawnAsync("node", [serverPath], {
92
+ env: resolvedEnv.env,
93
+ cwd: node_process.cwd()
94
+ });
95
+ await require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
96
+ command: "agent",
97
+ kubbVersion: version,
98
+ hrStart,
99
+ status: "success"
100
+ }));
101
+ } catch (error) {
102
+ await require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
103
+ command: "agent",
104
+ kubbVersion: version,
105
+ hrStart,
106
+ status: "failed"
107
+ }));
108
+ _clack_prompts.log.error((0, node_util.styleText)("red", "Failed to start agent server"));
109
+ console.error(error);
110
+ node_process.exit(1);
111
+ }
112
+ }
113
+ //#endregion
114
+ exports.runAgentStart = runAgentStart;
115
+
116
+ //# sourceMappingURL=agent-B_pirbeB.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-B_pirbeB.cjs","names":["process","agentDefaults","path","net","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\ntype ResolvedAgentStartEnvironment = {\n port: string\n host: string\n allowWrite: boolean\n allowAll: boolean\n agentConfigPath: string\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 */\nfunction resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: Omit<AgentStartOptions, 'version'>): 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\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 let agentPkgUrl: string\n try {\n agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')\n } catch (_e) {\n console.error(`Import of '@kubb/agent' is required to start the Agent server`)\n process.exit(1)\n }\n const agentPkgPath = fileURLToPath(agentPkgUrl)\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 await spawnAsync('node', [serverPath], {\n env: resolvedEnv.env,\n cwd: process.cwd(),\n })\n\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'agent',\n kubbVersion: version,\n hrStart,\n status: 'success',\n }),\n )\n } catch (error) {\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'agent',\n kubbVersion: version,\n hrStart,\n status: 'failed',\n }),\n )\n clack.log.error(styleText('red', 'Failed to start agent server'))\n console.error(error)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,SAAS,6BAA6B,EAAE,MAAM,MAAM,YAAY,YAAY,YAA+E;CACzJ,MAAM,eAAe,QAAQA,aAAQ,IAAI,QAAQC,kBAAAA,cAAc;CAC/D,MAAM,eAAe,SAASA,kBAAAA,cAAc,OAAO,OAAQD,aAAQ,IAAI,QAAQC,kBAAAA,cAAc;CAC7F,MAAM,mBAAmB,YAAYD,aAAQ,IAAI,yBAAyB;CAC1E,MAAM,qBAAqB,oBAAoB,cAAcA,aAAQ,IAAI,2BAA2B;CACpG,MAAM,YAAYA,aAAQ,IAAI,mBAAmBA,aAAQ,KAAK;CAC9D,MAAM,kBAAkBE,UAAAA,QAAK,QAAQF,aAAQ,KAAK,EAAE,cAAcA,aAAQ,IAAI,qBAAqBC,kBAAAA,cAAc,WAAW;AAE5H,QAAO;EACL,MAAM;EACN,MAAM;EACN,YAAY;EACZ,UAAU;EACV;EACA,KAAK;GACH,GAAGD,aAAQ;GACX,MAAM;GACN,MAAM;GACN,iBAAiB;GACjB,mBAAmB;GACnB,wBAAwB,OAAO,mBAAmB;GAClD,sBAAsB,OAAO,iBAAiB;GAC9C,kBAAkBA,aAAQ,IAAI;GAC9B,0BAA0BA,aAAQ,IAAI,4BAA4BC,kBAAAA,cAAc;GAChF,iBAAiBD,aAAQ,IAAI,mBAAmBC,kBAAAA,cAAc;GAC/D;EACF;;AAGH,SAAS,gBAAgB,MAAc,MAAgC;AACrE,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,SAASE,SAAAA,QAAI,cAAc;AACjC,SAAO,KAAK,eAAe,QAAQ,MAAM,CAAC;AAC1C,SAAO,KAAK,mBAAmB;AAC7B,UAAO,OAAO;AAC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AAuF,CAAC;AAClJ,gBAAQ,KAAK,EAAE;;AAIjB,QAAMG,cAAAA,WAAW,QAAQ,CAAC,WAAW,EAAE;GACrC,KAAK,YAAY;GACjB,KAAKJ,aAAQ,KAAK;GACnB,CAAC;AAEF,QAAMK,kBAAAA,cACJC,kBAAAA,oBAAoB;GAClB,SAAS;GACT,aAAa;GACb;GACA,QAAQ;GACT,CAAC,CACH;UACM,OAAO;AACd,QAAMD,kBAAAA,cACJC,kBAAAA,oBAAoB;GAClB,SAAS;GACT,aAAa;GACb;GACA,QAAQ;GACT,CAAC,CACH;AACD,iBAAM,IAAI,OAAA,GAAA,UAAA,WAAgB,OAAO,+BAA+B,CAAC;AACjE,UAAQ,MAAM,MAAM;AACpB,eAAQ,KAAK,EAAE"}
@@ -1,7 +1,7 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { n as defineCommand } from "./define--M_JMcDC.js";
3
- import { t as version } from "./package-BKZ0H3Zf.js";
4
- import { o as agentDefaults } from "./constants-DJM9zCXm.js";
2
+ import { n as defineCommand } from "./define-Ctii4bel.js";
3
+ import { t as version } from "./package-Yo-9_m5C.js";
4
+ import { s as agentDefaults } from "./constants-aL3CP_Wq.js";
5
5
  //#endregion
6
6
  //#region src/commands/agent.ts
7
7
  const command = defineCommand({
@@ -38,7 +38,7 @@ const command = defineCommand({
38
38
  }
39
39
  },
40
40
  async run({ values }) {
41
- const { runAgentStart } = await import("./agent-CBrpIMMU.js");
41
+ const { runAgentStart } = await import("./agent-Ev5hU5hH.js");
42
42
  await runAgentStart({
43
43
  port: values.port !== void 0 ? values.port : void 0,
44
44
  host: values.host,
@@ -53,4 +53,4 @@ const command = defineCommand({
53
53
  //#endregion
54
54
  export { command };
55
55
 
56
- //# sourceMappingURL=agent-5mmp7QzF.js.map
56
+ //# sourceMappingURL=agent-DKeVuiUC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-DKeVuiUC.js","names":["command","startCommand"],"sources":["../src/commands/agent/start.ts","../src/commands/agent.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport { version } from '../../../package.json'\nimport { agentDefaults } from '../../constants.ts'\n\nexport const command = defineCommand({\n name: 'start',\n description: 'Start the Agent server',\n options: {\n config: {\n type: 'string',\n description: 'Path to the Kubb config',\n short: 'c',\n },\n port: {\n type: 'string',\n description: `Port for the server (default: ${agentDefaults.port})`,\n short: 'p',\n },\n host: {\n type: 'string',\n description: 'Host for the server',\n default: agentDefaults.host,\n },\n 'allow-write': {\n type: 'boolean',\n description: 'Allow writing generated files to the filesystem. When not set, no files are written and the config patch is not persisted.',\n default: false,\n },\n 'allow-all': {\n type: 'boolean',\n description: 'Grant all permissions (implies --allow-write).',\n default: false,\n },\n },\n async run({ values }) {\n const { runAgentStart } = await import('../../runners/agent.ts')\n\n await runAgentStart({\n port: values.port !== undefined ? values.port : undefined,\n host: values.host,\n configPath: values.config,\n allowWrite: values['allow-write'],\n allowAll: values['allow-all'],\n version,\n })\n },\n})\n","import { defineCommand } from '@internals/utils'\nimport { command as startCommand } from './agent/start.ts'\n\nexport const command = defineCommand({\n name: 'agent',\n description: 'Manage the Kubb Agent server',\n subCommands: [startCommand],\n})\n"],"mappings":";;;;;;ACGA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,aAAa;CACb,aAAa,CDFQ,cAAc;EACnC,MAAM;EACN,aAAa;EACb,SAAS;GACP,QAAQ;IACN,MAAM;IACN,aAAa;IACb,OAAO;IACR;GACD,MAAM;IACJ,MAAM;IACN,aAAa,iCAAiC,cAAc,KAAK;IACjE,OAAO;IACR;GACD,MAAM;IACJ,MAAM;IACN,aAAa;IACb,SAAS,cAAc;IACxB;GACD,eAAe;IACb,MAAM;IACN,aAAa;IACb,SAAS;IACV;GACD,aAAa;IACX,MAAM;IACN,aAAa;IACb,SAAS;IACV;GACF;EACD,MAAM,IAAI,EAAE,UAAU;GACpB,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,SAAM,cAAc;IAClB,MAAM,OAAO,SAAS,KAAA,IAAY,OAAO,OAAO,KAAA;IAChD,MAAM,OAAO;IACb,YAAY,OAAO;IACnB,YAAY,OAAO;IACnB,UAAU,OAAO;IACjB;IACD,CAAC;;EAEL,CCxCeC,CAAa;CAC5B,CAAC"}
@@ -0,0 +1,112 @@
1
+ import "./chunk--u3MIqq1.js";
2
+ import { r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-LgT_sdPe.js";
3
+ import { t as spawnAsync } from "./shell-DLzN4fRo.js";
4
+ import { s as agentDefaults } from "./constants-aL3CP_Wq.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
+ /**
13
+ * Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.
14
+ */
15
+ function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }) {
16
+ const resolvedPort = port ?? process$1.env.PORT ?? agentDefaults.port;
17
+ const resolvedHost = host !== agentDefaults.host ? host : process$1.env.HOST ?? agentDefaults.host;
18
+ const resolvedAllowAll = allowAll || process$1.env.KUBB_AGENT_ALLOW_ALL === "true";
19
+ const resolvedAllowWrite = resolvedAllowAll || allowWrite || process$1.env.KUBB_AGENT_ALLOW_WRITE === "true";
20
+ const agentRoot = process$1.env.KUBB_AGENT_ROOT ?? process$1.cwd();
21
+ const agentConfigPath = path.resolve(process$1.cwd(), configPath || process$1.env.KUBB_AGENT_CONFIG || agentDefaults.configFile);
22
+ return {
23
+ port: resolvedPort,
24
+ host: resolvedHost,
25
+ allowWrite: resolvedAllowWrite,
26
+ allowAll: resolvedAllowAll,
27
+ agentConfigPath,
28
+ env: {
29
+ ...process$1.env,
30
+ PORT: resolvedPort,
31
+ HOST: resolvedHost,
32
+ KUBB_AGENT_ROOT: agentRoot,
33
+ KUBB_AGENT_CONFIG: agentConfigPath,
34
+ KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),
35
+ KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),
36
+ KUBB_AGENT_TOKEN: process$1.env.KUBB_AGENT_TOKEN,
37
+ KUBB_AGENT_RETRY_TIMEOUT: process$1.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,
38
+ KUBB_STUDIO_URL: process$1.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl
39
+ }
40
+ };
41
+ }
42
+ function isPortAvailable(port, host) {
43
+ return new Promise((resolve) => {
44
+ const server = net.createServer();
45
+ server.once("error", () => resolve(false));
46
+ server.once("listening", () => {
47
+ server.close();
48
+ resolve(true);
49
+ });
50
+ server.listen(port, host);
51
+ });
52
+ }
53
+ async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }) {
54
+ const hrStart = process$1.hrtime();
55
+ try {
56
+ try {
57
+ process$1.loadEnvFile();
58
+ } catch {}
59
+ let agentPkgUrl;
60
+ try {
61
+ agentPkgUrl = import.meta.resolve("@kubb/agent/package.json");
62
+ } catch (_e) {
63
+ console.error(`Import of '@kubb/agent' is required to start the Agent server`);
64
+ process$1.exit(1);
65
+ }
66
+ const agentPkgPath = fileURLToPath(agentPkgUrl);
67
+ const agentDir = path.dirname(agentPkgPath);
68
+ const serverPath = path.join(agentDir, agentDefaults.serverEntryPath);
69
+ const resolvedEnv = resolveAgentStartEnvironment({
70
+ port,
71
+ host,
72
+ configPath,
73
+ allowWrite,
74
+ allowAll
75
+ });
76
+ const numericPort = Number(resolvedEnv.port);
77
+ if (!Number.isInteger(numericPort) || numericPort <= 0) throw new Error(`Invalid port "${resolvedEnv.port}". Provide a positive integer with --port or PORT.`);
78
+ clack.log.step(styleText("cyan", "Starting agent server..."));
79
+ clack.log.info(styleText("dim", `Config: ${resolvedEnv.agentConfigPath}`));
80
+ clack.log.info(styleText("dim", `Host: ${resolvedEnv.host}`));
81
+ clack.log.info(styleText("dim", `Port: ${resolvedEnv.port}`));
82
+ if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) clack.log.warn(styleText("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
83
+ if (!await isPortAvailable(numericPort, resolvedEnv.host)) {
84
+ clack.log.error(styleText("red", `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`));
85
+ process$1.exit(1);
86
+ }
87
+ await spawnAsync("node", [serverPath], {
88
+ env: resolvedEnv.env,
89
+ cwd: process$1.cwd()
90
+ });
91
+ await sendTelemetry(buildTelemetryEvent({
92
+ command: "agent",
93
+ kubbVersion: version,
94
+ hrStart,
95
+ status: "success"
96
+ }));
97
+ } catch (error) {
98
+ await sendTelemetry(buildTelemetryEvent({
99
+ command: "agent",
100
+ kubbVersion: version,
101
+ hrStart,
102
+ status: "failed"
103
+ }));
104
+ clack.log.error(styleText("red", "Failed to start agent server"));
105
+ console.error(error);
106
+ process$1.exit(1);
107
+ }
108
+ }
109
+ //#endregion
110
+ export { runAgentStart };
111
+
112
+ //# sourceMappingURL=agent-Ev5hU5hH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-Ev5hU5hH.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\ntype ResolvedAgentStartEnvironment = {\n port: string\n host: string\n allowWrite: boolean\n allowAll: boolean\n agentConfigPath: string\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 */\nfunction resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: Omit<AgentStartOptions, 'version'>): 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\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 let agentPkgUrl: string\n try {\n agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')\n } catch (_e) {\n console.error(`Import of '@kubb/agent' is required to start the Agent server`)\n process.exit(1)\n }\n const agentPkgPath = fileURLToPath(agentPkgUrl)\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 await spawnAsync('node', [serverPath], {\n env: resolvedEnv.env,\n cwd: process.cwd(),\n })\n\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'agent',\n kubbVersion: version,\n hrStart,\n status: 'success',\n }),\n )\n } catch (error) {\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'agent',\n kubbVersion: version,\n hrStart,\n status: 'failed',\n }),\n )\n clack.log.error(styleText('red', 'Failed to start agent server'))\n console.error(error)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAS,6BAA6B,EAAE,MAAM,MAAM,YAAY,YAAY,YAA+E;CACzJ,MAAM,eAAe,QAAQA,UAAQ,IAAI,QAA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
+ * Used by the `init` command when scaffolding new projects and by the `agent` default config.
6
+ */
7
+ const KUBB_CONFIG_FILENAME = "kubb.config.ts";
8
+ /**
3
9
  * NPM registry endpoint used to check for @kubb/cli updates.
4
10
  */
5
11
  const KUBB_NPM_PACKAGE_URL = "https://registry.npmjs.org/@kubb/cli/latest";
@@ -18,62 +24,21 @@ const WATCHER_IGNORED_PATHS = "**/{.git,node_modules}/**";
18
24
  /**
19
25
  * Flags that short-circuit execution (help/version) — no telemetry notice is shown.
20
26
  */
21
- const QUITE_FLAGS = new Set([
27
+ const QUIET_FLAGS = new Set([
22
28
  "--help",
23
29
  "-h",
24
30
  "--version",
25
31
  "-v"
26
32
  ]);
27
- /**
28
- * Flags accepted by the `generate` command.
29
- */
30
- const GENERATE_FLAGS = new Set([
31
- "--config",
32
- "-c",
33
- "--log-level",
34
- "-l",
35
- "--watch",
36
- "-w",
37
- "--debug",
38
- "-d",
39
- "--verbose",
40
- "-v",
41
- "--silent",
42
- "-s"
43
- ]);
44
- /**
45
- * Flags accepted by the `validate` command.
46
- */
47
- const VALIDATE_FLAGS = new Set(["--input", "-i"]);
48
- /**
49
- * Flags accepted by the `init` command.
50
- */
51
- const INIT_FLAGS = new Set(["--yes", "-y"]);
52
- /**
53
- * Flags accepted by the `agent start` command.
54
- */
55
- const AGENT_START_FLAGS = new Set([
56
- "--config",
57
- "-c",
58
- "--port",
59
- "-p",
60
- "--host",
61
- "--allow-write",
62
- "--allow-all"
63
- ]);
64
- new Set([
65
- ...QUITE_FLAGS,
66
- ...GENERATE_FLAGS,
67
- ...VALIDATE_FLAGS,
68
- ...INIT_FLAGS,
69
- ...AGENT_START_FLAGS
70
- ]);
71
33
  const agentDefaults = {
72
34
  port: "3000",
73
35
  host: "localhost",
74
- configFile: "kubb.config.ts",
36
+ configFile: KUBB_CONFIG_FILENAME,
75
37
  retryTimeout: "30000",
76
38
  studioUrl: "https://studio.kubb.dev",
39
+ /**
40
+ * Relative path from the @kubb/agent package root to the server entry.
41
+ */
77
42
  serverEntryPath: ".output/server/index.mjs"
78
43
  };
79
44
  /**
@@ -82,7 +47,7 @@ const agentDefaults = {
82
47
  const initDefaults = {
83
48
  inputPath: "./openapi.yaml",
84
49
  outputPath: "./src/gen",
85
- plugins: ["plugin-oas", "plugin-ts"]
50
+ plugins: ["plugin-ts"]
86
51
  };
87
52
  /**
88
53
  * Maps each plugin value to the default config snippet inserted by `init`.
@@ -90,7 +55,6 @@ const initDefaults = {
90
55
  * `as const` keeps the object deeply immutable.
91
56
  */
92
57
  const pluginDefaultConfigs = {
93
- "plugin-oas": "pluginOas()",
94
58
  "plugin-ts": `pluginTs({
95
59
  output: { path: 'models' },
96
60
  })`,
@@ -99,18 +63,9 @@ const pluginDefaultConfigs = {
99
63
  })`,
100
64
  "plugin-react-query": `pluginReactQuery({
101
65
  output: { path: 'hooks' },
102
- })`,
103
- "plugin-solid-query": `pluginSolidQuery({
104
- output: { path: 'hooks' },
105
- })`,
106
- "plugin-svelte-query": `pluginSvelteQuery({
107
- output: { path: 'hooks' },
108
66
  })`,
109
67
  "plugin-vue-query": `pluginVueQuery({
110
68
  output: { path: 'hooks' },
111
- })`,
112
- "plugin-swr": `pluginSwr({
113
- output: { path: 'hooks' },
114
69
  })`,
115
70
  "plugin-zod": `pluginZod({
116
71
  output: { path: 'zod' },
@@ -120,12 +75,27 @@ const pluginDefaultConfigs = {
120
75
  })`,
121
76
  "plugin-msw": `pluginMsw({
122
77
  output: { path: 'msw' },
78
+ })`,
79
+ "plugin-cypress": `pluginCypress({
80
+ output: { path: 'cypress' },
81
+ })`,
82
+ "plugin-mcp": `pluginMcp({
83
+ output: { path: 'mcp' },
84
+ })`,
85
+ "plugin-redoc": `pluginRedoc({
86
+ output: { path: 'redoc' },
123
87
  })`
124
88
  };
125
89
  /**
126
90
  * Color palette used by randomCliColor() for deterministic plugin name coloring.
127
91
  */
128
92
  //#endregion
93
+ Object.defineProperty(exports, "KUBB_CONFIG_FILENAME", {
94
+ enumerable: true,
95
+ get: function() {
96
+ return KUBB_CONFIG_FILENAME;
97
+ }
98
+ });
129
99
  Object.defineProperty(exports, "KUBB_NPM_PACKAGE_URL", {
130
100
  enumerable: true,
131
101
  get: function() {
@@ -138,10 +108,10 @@ Object.defineProperty(exports, "OTLP_ENDPOINT", {
138
108
  return OTLP_ENDPOINT;
139
109
  }
140
110
  });
141
- Object.defineProperty(exports, "QUITE_FLAGS", {
111
+ Object.defineProperty(exports, "QUIET_FLAGS", {
142
112
  enumerable: true,
143
113
  get: function() {
144
- return QUITE_FLAGS;
114
+ return QUIET_FLAGS;
145
115
  }
146
116
  });
147
117
  Object.defineProperty(exports, "SUMMARY_SEPARATOR", {
@@ -175,4 +145,4 @@ Object.defineProperty(exports, "pluginDefaultConfigs", {
175
145
  }
176
146
  });
177
147
 
178
- //# sourceMappingURL=constants-D0XHAHeZ.cjs.map
148
+ //# sourceMappingURL=constants-CnDXa1R6.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants-CnDXa1R6.cjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Default filename for the Kubb configuration file.\n *\n * Used by the `init` command when scaffolding new projects and by the `agent` default config.\n */\nexport const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const\n\n/**\n * NPM registry endpoint used to check for @kubb/cli updates.\n */\nexport const KUBB_NPM_PACKAGE_URL = 'https://registry.npmjs.org/@kubb/cli/latest' as const\n\n/**\n * OpenTelemetry ingestion endpoint for anonymous usage telemetry.\n */\nexport const OTLP_ENDPOINT = 'https://otlp.kubb.dev' as const\n\n/**\n * Horizontal rule rendered above/below the plain-logger generation summary.\n */\nexport const SUMMARY_SEPARATOR = '─'.repeat(27)\n\n/**\n * Maximum number of █ characters in a plugin timing bar.\n */\nexport const SUMMARY_MAX_BAR_LENGTH = 10 as const\n\n/**\n * Divides elapsed milliseconds into bar-length units (1 block per 100 ms).\n */\nexport const SUMMARY_TIME_SCALE_DIVISOR = 100 as const\n\n/**\n * Glob pattern for paths the file watcher ignores.\n */\nexport const WATCHER_IGNORED_PATHS = '**/{.git,node_modules}/**' as const\n\n/**\n * Flags that short-circuit execution (help/version) — no telemetry notice is shown.\n */\nexport const QUIET_FLAGS = new Set(['--help', '-h', '--version', '-v'] as const)\n\nexport const agentDefaults = {\n port: '3000',\n host: 'localhost',\n configFile: KUBB_CONFIG_FILENAME,\n retryTimeout: '30000',\n studioUrl: 'https://studio.kubb.dev',\n /**\n * Relative path from the @kubb/agent package root to the server entry.\n */\n serverEntryPath: '.output/server/index.mjs',\n} as const\n\n/**\n * Default values used during interactive `init` scaffolding.\n */\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['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-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-vue-query': `pluginVueQuery({\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 'plugin-cypress': `pluginCypress({\n output: { path: 'cypress' },\n })`,\n 'plugin-mcp': `pluginMcp({\n output: { path: 'mcp' },\n })`,\n 'plugin-redoc': `pluginRedoc({\n output: { path: 'redoc' },\n })`,\n} as const satisfies Record<string, string>\n\n/**\n * Color palette used by randomCliColor() for deterministic plugin name coloring.\n */\n"],"mappings":";;;;;;AAKA,MAAa,uBAAuB;;;;AAKpC,MAAa,uBAAuB;;;;AAKpC,MAAa,gBAAgB;;;;AAK7B,MAAa,oBAAoB,IAAI,OAAO,GAAG;;;;AAe/C,MAAa,wBAAwB;;;;AAKrC,MAAa,cAAc,IAAI,IAAI;CAAC;CAAU;CAAM;CAAa;CAAK,CAAU;AAEhF,MAAa,gBAAgB;CAC3B,MAAM;CACN,MAAM;CACN,YAAY;CACZ,cAAc;CACd,WAAW;;;;CAIX,iBAAiB;CAClB;;;;AAKD,MAAa,eAAe;CAC1B,WAAW;CACX,YAAY;CACZ,SAAS,CAAC,YAAY;CACvB;;;;;;AAOD,MAAa,uBAAuB;CAClC,aAAa;;;CAGb,iBAAiB;;;CAGjB,sBAAsB;;;CAGtB,oBAAoB;;;CAGpB,cAAc;;;CAGd,gBAAgB;;;CAGhB,cAAc;;;CAGd,kBAAkB;;;CAGlB,cAAc;;;CAGd,gBAAgB;;;CAGjB"}