@kubb/mcp 5.0.0-beta.36 → 5.0.0-beta.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +56 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +57 -16
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/schemas/generateSchema.ts +1 -1
- package/src/tools/generate.ts +18 -17
- package/src/tools/validate.ts +4 -1
- package/src/types.ts +1 -0
- package/src/utils/formatDiagnostics.ts +29 -0
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ Generate code from OpenAPI/Swagger specifications using Kubb configuration.
|
|
|
116
116
|
- `config` (string, optional): Path to kubb.config.ts file. If not provided, looks for kubb.config.ts in current directory
|
|
117
117
|
- `input` (string, optional): Path to OpenAPI/Swagger spec file (overrides config file setting)
|
|
118
118
|
- `output` (string, optional): Output directory path (overrides config file setting)
|
|
119
|
-
- `logLevel` (enum, optional): Control logging verbosity
|
|
119
|
+
- `logLevel` (enum, optional): Control logging verbosity, one of `'silent'`, `'info'`, `'verbose'` (default: 'info')
|
|
120
120
|
|
|
121
121
|
**Examples:**
|
|
122
122
|
|
package/dist/index.cjs
CHANGED
|
@@ -42,7 +42,7 @@ let jiti = require("jiti");
|
|
|
42
42
|
let node_process = require("node:process");
|
|
43
43
|
node_process = __toESM(node_process, 1);
|
|
44
44
|
//#region package.json
|
|
45
|
-
var version = "5.0.0-beta.
|
|
45
|
+
var version = "5.0.0-beta.37";
|
|
46
46
|
//#endregion
|
|
47
47
|
//#region ../../internals/utils/src/errors.ts
|
|
48
48
|
/**
|
|
@@ -158,6 +158,24 @@ var AsyncEventEmitter = class {
|
|
|
158
158
|
return this.#emitter.listenerCount(eventName);
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
|
+
* Raises or lowers the per-event listener ceiling before Node warns about a memory leak.
|
|
162
|
+
* Set this above the expected listener count when many listeners attach by design.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* emitter.setMaxListeners(40)
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
setMaxListeners(max) {
|
|
170
|
+
this.#emitter.setMaxListeners(max);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Returns the current per-event listener ceiling.
|
|
174
|
+
*/
|
|
175
|
+
getMaxListeners() {
|
|
176
|
+
return this.#emitter.getMaxListeners();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
161
179
|
* Removes all listeners from every event channel.
|
|
162
180
|
*
|
|
163
181
|
* @example
|
|
@@ -190,20 +208,37 @@ const generateSchema = valibot.object({
|
|
|
190
208
|
output: valibot.optional(valibot.pipe(valibot.string(), valibot.minLength(1), valibot.description("Output directory path (overrides config)"))),
|
|
191
209
|
logLevel: valibot.optional(valibot.pipe(valibot.picklist([
|
|
192
210
|
"silent",
|
|
193
|
-
"error",
|
|
194
|
-
"warn",
|
|
195
211
|
"info",
|
|
196
|
-
"verbose"
|
|
197
|
-
"debug"
|
|
212
|
+
"verbose"
|
|
198
213
|
]), valibot.description("Log level for build output")), "info")
|
|
199
214
|
});
|
|
200
215
|
//#endregion
|
|
216
|
+
//#region src/utils/formatDiagnostics.ts
|
|
217
|
+
/**
|
|
218
|
+
* Renders serialized diagnostics as a plain-text block for an AI assistant. Each entry
|
|
219
|
+
* keeps the stable `code`, the source pointer, the suggested fix, and the docs link, so
|
|
220
|
+
* the agent can act on the problem rather than parsing a bare message. No ANSI styling,
|
|
221
|
+
* unlike the CLI renderer.
|
|
222
|
+
*/
|
|
223
|
+
function formatDiagnostics(diagnostics) {
|
|
224
|
+
return diagnostics.map((diagnostic) => formatDiagnostic(diagnostic)).join("\n\n");
|
|
225
|
+
}
|
|
226
|
+
function formatDiagnostic(diagnostic) {
|
|
227
|
+
const { code, severity, message, location, help, plugin, docsUrl } = diagnostic;
|
|
228
|
+
const lines = [`${severity} ${plugin ? `${plugin}(${code})` : code}: ${message}`];
|
|
229
|
+
if (location && "pointer" in location) lines.push(` at ${location.pointer}`);
|
|
230
|
+
if (help) lines.push(` help: ${help}`);
|
|
231
|
+
if (docsUrl) lines.push(` docs: ${docsUrl}`);
|
|
232
|
+
return lines.join("\n");
|
|
233
|
+
}
|
|
234
|
+
//#endregion
|
|
201
235
|
//#region src/types.ts
|
|
202
236
|
const NotifyTypes = {
|
|
203
237
|
INFO: "INFO",
|
|
204
238
|
SUCCESS: "SUCCESS",
|
|
205
239
|
ERROR: "ERROR",
|
|
206
240
|
WARN: "WARN",
|
|
241
|
+
DIAGNOSTIC: "DIAGNOSTIC",
|
|
207
242
|
PLUGIN_START: "PLUGIN_START",
|
|
208
243
|
PLUGIN_END: "PLUGIN_END",
|
|
209
244
|
FILES_START: "FILES_START",
|
|
@@ -341,8 +376,8 @@ const generateTool = (0, tmcp_tool.defineTool)({
|
|
|
341
376
|
try {
|
|
342
377
|
const hooks = new AsyncEventEmitter();
|
|
343
378
|
const messages = [];
|
|
344
|
-
const notify = async (type, message,
|
|
345
|
-
messages.push(`${type}: ${message}`);
|
|
379
|
+
const notify = async (type, message, data) => {
|
|
380
|
+
messages.push(data ? `${type}: ${message} ${JSON.stringify(data)}` : `${type}: ${message}`);
|
|
346
381
|
};
|
|
347
382
|
hooks.on("kubb:info", async ({ message }) => {
|
|
348
383
|
await notify(NotifyTypes.INFO, message);
|
|
@@ -356,6 +391,9 @@ const generateTool = (0, tmcp_tool.defineTool)({
|
|
|
356
391
|
hooks.on("kubb:warn", async ({ message }) => {
|
|
357
392
|
await notify(NotifyTypes.WARN, message);
|
|
358
393
|
});
|
|
394
|
+
hooks.on("kubb:diagnostic", async ({ diagnostic }) => {
|
|
395
|
+
await notify(NotifyTypes.DIAGNOSTIC, diagnostic.message, _kubb_core.Diagnostics.serialize(diagnostic));
|
|
396
|
+
});
|
|
359
397
|
hooks.on("kubb:plugin:start", async ({ plugin }) => {
|
|
360
398
|
await notify(NotifyTypes.PLUGIN_START, `Plugin starting: ${plugin.name}`);
|
|
361
399
|
});
|
|
@@ -412,18 +450,20 @@ const generateTool = (0, tmcp_tool.defineTool)({
|
|
|
412
450
|
await kubb.setup();
|
|
413
451
|
await notify(NotifyTypes.SETUP_END, "Kubb setup complete");
|
|
414
452
|
await notify(NotifyTypes.BUILD_START, "Starting build");
|
|
415
|
-
const { files,
|
|
453
|
+
const { files, diagnostics } = await kubb.safeBuild();
|
|
416
454
|
await notify(NotifyTypes.BUILD_END, `Build complete - Generated ${files.length} files`);
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
455
|
+
const problems = diagnostics.filter(_kubb_core.isProblemDiagnostic);
|
|
456
|
+
const errors = problems.filter((diagnostic) => diagnostic.severity === "error");
|
|
457
|
+
if (errors.length > 0) {
|
|
458
|
+
await notify(NotifyTypes.BUILD_FAILED, `Build failed with ${errors.length} diagnostic(s)`);
|
|
459
|
+
const serialized = problems.map((diagnostic) => _kubb_core.Diagnostics.serialize(diagnostic));
|
|
460
|
+
return tmcp_utils.tool.error(`Build failed:\n${formatDiagnostics(serialized)}\n\n\`\`\`json\n${JSON.stringify(serialized, null, 2)}\n\`\`\``);
|
|
421
461
|
}
|
|
422
462
|
await notify(NotifyTypes.BUILD_SUCCESS, `Build completed successfully - Generated ${files.length} files`);
|
|
423
463
|
return tmcp_utils.tool.text(`Build completed successfully!\n\nGenerated ${files.length} files\n\n${messages.join("\n")}`);
|
|
424
464
|
} catch (caughtError) {
|
|
425
|
-
const
|
|
426
|
-
return tmcp_utils.tool.error(`Build error
|
|
465
|
+
const serialized = _kubb_core.Diagnostics.serialize(_kubb_core.Diagnostics.from(caughtError));
|
|
466
|
+
return tmcp_utils.tool.error(`Build error:\n${formatDiagnostics([serialized])}\n\n\`\`\`json\n${JSON.stringify(serialized, null, 2)}\n\`\`\``);
|
|
427
467
|
}
|
|
428
468
|
});
|
|
429
469
|
//#endregion
|
|
@@ -608,7 +648,8 @@ const validateTool = (0, tmcp_tool.defineTool)({
|
|
|
608
648
|
await mod.adapterOas().validate(input, { throwOnError: true });
|
|
609
649
|
return tmcp_utils.tool.text(`Validation successful: ${input}`);
|
|
610
650
|
} catch (err) {
|
|
611
|
-
|
|
651
|
+
const serialized = _kubb_core.Diagnostics.serialize(_kubb_core.Diagnostics.from(err));
|
|
652
|
+
return tmcp_utils.tool.error(`Validation failed:\n${formatDiagnostics([serialized])}\n\n\`\`\`json\n${JSON.stringify(serialized, null, 2)}\n\`\`\``);
|
|
612
653
|
}
|
|
613
654
|
});
|
|
614
655
|
//#endregion
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["#emitter","NodeEventEmitter","#emitAll","v","jiti","path","path","tool","v","path","process","fs","tool","v","tool","McpServer","ValibotJsonSchemaAdapter","StdioTransport","HttpTransport","http"],"sources":["../package.json","../../../internals/utils/src/errors.ts","../../../internals/utils/src/asyncEventEmitter.ts","../../../internals/utils/src/promise.ts","../src/schemas/generateSchema.ts","../src/types.ts","../src/constants.ts","../src/utils/loadUserConfig.ts","../src/utils/resolveCwd.ts","../src/utils/resolveUserConfig.ts","../src/tools/generate.ts","../../../internals/shared/src/constants.ts","../../../internals/shared/src/init.ts","../src/schemas/initSchema.ts","../src/tools/init.ts","../src/schemas/validateSchema.ts","../src/tools/validate.ts","../src/server.ts","../src/index.ts"],"sourcesContent":["","/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n *\n * @example\n * ```ts\n * throw new BuildError('Build failed', { errors: [err1, err2] })\n * ```\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new BuildError('Build failed', { cause: toError(err), errors: [] })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.\n *\n * @example\n * ```ts\n * const cause = toCause(buildError) // Error | undefined\n * ```\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport { toError } from './errors.ts'\n\n/**\n * A function that can be registered as an event listener, synchronous or async.\n */\ntype AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>\n\n/**\n * Typed `EventEmitter` that awaits all async listeners before resolving.\n * Wraps Node's `EventEmitter` with full TypeScript event-map inference.\n *\n * @example\n * ```ts\n * const emitter = new AsyncEventEmitter<{ build: [name: string] }>()\n * emitter.on('build', async (name) => { console.log(name) })\n * await emitter.emit('build', 'petstore') // all listeners awaited\n * ```\n */\nexport class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {\n /**\n * Maximum number of listeners per event before Node emits a memory-leak warning.\n * @default 10\n */\n constructor(maxListener = 10) {\n this.#emitter.setMaxListeners(maxListener)\n }\n\n #emitter = new NodeEventEmitter()\n\n /**\n * Emits `eventName` and awaits all registered listeners sequentially.\n * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.\n *\n * @example\n * ```ts\n * await emitter.emit('build', 'petstore')\n * ```\n */\n emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> | void {\n const listeners = this.#emitter.listeners(eventName) as Array<AsyncListener<TEvents[TEventName]>>\n\n if (listeners.length === 0) {\n return\n }\n\n return this.#emitAll(eventName, listeners, eventArgs)\n }\n\n async #emitAll<TEventName extends keyof TEvents & string>(\n eventName: TEventName,\n listeners: Array<AsyncListener<TEvents[TEventName]>>,\n eventArgs: TEvents[TEventName],\n ): Promise<void> {\n for (const listener of listeners) {\n try {\n await listener(...eventArgs)\n } catch (err) {\n let serializedArgs: string\n try {\n serializedArgs = JSON.stringify(eventArgs)\n } catch {\n serializedArgs = String(eventArgs)\n }\n throw new Error(`Error in async listener for \"${eventName}\" with eventArgs ${serializedArgs}`, { cause: toError(err) })\n }\n }\n }\n\n /**\n * Registers a persistent listener for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', async (name) => { console.log(name) })\n * ```\n */\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.on(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Registers a one-shot listener that removes itself after the first invocation.\n *\n * @example\n * ```ts\n * emitter.onOnce('build', async (name) => { console.log(name) })\n * ```\n */\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n const wrapper: AsyncListener<TEvents[TEventName]> = (...args) => {\n this.off(eventName, wrapper)\n return handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n /**\n * Removes a previously registered listener.\n *\n * @example\n * ```ts\n * emitter.off('build', handler)\n * ```\n */\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.off(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Returns the number of listeners registered for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', handler)\n * emitter.listenerCount('build') // 1\n * ```\n */\n listenerCount<TEventName extends keyof TEvents & string>(eventName: TEventName): number {\n return this.#emitter.listenerCount(eventName)\n }\n\n /**\n * Removes all listeners from every event channel.\n *\n * @example\n * ```ts\n * emitter.removeAll()\n * ```\n */\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","function* chunks<T>(arr: readonly T[], size: number): Generator<T[]> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: readonly T[] | AsyncIterable<T>,\n process: (batch: T[]) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: T[] = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/**\n * Runs `work`, passing `flush` as its periodic-flush callback, then calls\n * `flush` once more to drain any items that did not cross a flush boundary.\n *\n * @example\n * ```ts\n * await withDrain(\n * (flush) => processItems(items, { flush }),\n * () => writeRemainingFiles(),\n * )\n * ```\n */\nexport async function withDrain(work: (flush: () => Promise<void>) => Promise<void>, flush: () => Promise<void>): Promise<void> {\n await work(flush)\n await flush()\n}\n\n/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n\n/**\n * Returns a wrapper that caches the result of the first invocation and replays\n * it for every subsequent call, ignoring later arguments.\n *\n * Works for sync and async factories — for async, the cached value is the\n * promise itself, so concurrent callers share one in-flight execution and\n * cannot race each other.\n *\n * @example\n * ```ts\n * const loadDocument = once(async (path: string) => parse(await readFile(path)))\n * const a = loadDocument('./a.yaml') // parses\n * const b = loadDocument('./b.yaml') // returns the cached promise from the first call\n * ```\n */\nexport function once<TArgs extends unknown[], TReturn>(factory: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn {\n let cache: { value: TReturn } | undefined\n return (...args: TArgs): TReturn => {\n if (!cache) cache = { value: factory(...args) }\n return cache.value\n }\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: readonly T[]): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import * as v from 'valibot'\n\nexport const generateSchema = v.object({\n config: v.optional(\n v.pipe(v.string(), v.minLength(1), v.description('Path to kubb.config file (supports .ts, .js, .cjs). If not provided, will look for kubb.config.{ts,js,cjs} in current directory')),\n ),\n input: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Path to OpenAPI/Swagger spec file (overrides config)'))),\n output: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Output directory path (overrides config)'))),\n logLevel: v.optional(\n v.pipe(v.picklist(['silent', 'error', 'warn', 'info', 'verbose', 'debug']), v.description('Log level for build output')),\n 'info',\n ),\n})\n","export const NotifyTypes = {\n INFO: 'INFO',\n SUCCESS: 'SUCCESS',\n ERROR: 'ERROR',\n WARN: 'WARN',\n PLUGIN_START: 'PLUGIN_START',\n PLUGIN_END: 'PLUGIN_END',\n FILES_START: 'FILES_START',\n FILES_UPDATE: 'FILES_UPDATE',\n FILES_END: 'FILES_END',\n GENERATION_START: 'GENERATION_START',\n GENERATION_END: 'GENERATION_END',\n CONFIG_LOADED: 'CONFIG_LOADED',\n CONFIG_ERROR: 'CONFIG_ERROR',\n CONFIG_READY: 'CONFIG_READY',\n SETUP_START: 'SETUP_START',\n SETUP_END: 'SETUP_END',\n BUILD_START: 'BUILD_START',\n BUILD_END: 'BUILD_END',\n BUILD_FAILED: 'BUILD_FAILED',\n BUILD_SUCCESS: 'BUILD_SUCCESS',\n FATAL_ERROR: 'FATAL_ERROR',\n} as const\n","export const ALLOWED_CONFIG_EXTENSIONS = new Set(['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'])\n","import { existsSync } from 'node:fs'\nimport path from 'node:path'\nimport type { Config } from '@kubb/core'\nimport { createJiti } from 'jiti'\nimport { ALLOWED_CONFIG_EXTENSIONS } from '../constants.ts'\nimport { NotifyTypes } from '../types.ts'\n\ntype NotifyFunction = (type: string, message: string, data?: Record<string, unknown>) => Promise<void>\n\nconst jiti = createJiti(import.meta.url, {\n jsx: {\n runtime: 'automatic',\n importSource: '@kubb/renderer-jsx',\n },\n moduleCache: false,\n})\n\nconst loadedModules = new Map<string, unknown>()\n\nasync function loadModule(filePath: string): Promise<unknown> {\n const ext = path.extname(filePath)\n if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {\n throw new Error(`Invalid config file extension \"${ext}\". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`)\n }\n if (loadedModules.has(filePath)) {\n return loadedModules.get(filePath)\n }\n const mod = await jiti.import(filePath, { default: true })\n loadedModules.set(filePath, mod)\n return mod\n}\n\nexport async function loadUserConfig(configPath: string | undefined, { notify }: { notify: NotifyFunction }): Promise<{ userConfig: Config; cwd: string }> {\n if (configPath) {\n const ext = path.extname(configPath)\n if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {\n const msg = `Invalid config file extension \"${ext}\". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n const base = path.resolve(process.cwd())\n const resolvedConfigPath = path.resolve(base, configPath)\n const relative = path.relative(base, resolvedConfigPath)\n if (relative.startsWith('..') || path.isAbsolute(relative)) {\n const msg = 'Invalid config file path: must be within the current working directory'\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n const cwd = path.dirname(resolvedConfigPath)\n try {\n const userConfig = (await loadModule(resolvedConfigPath)) as Config\n await notify(NotifyTypes.CONFIG_LOADED, `Loaded config from ${resolvedConfigPath}`)\n return { userConfig, cwd }\n } catch (error) {\n const msg = `Failed to load config: ${error instanceof Error ? error.message : String(error)}`\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n }\n\n const cwd = process.cwd()\n const configFileNames = ['kubb.config.ts', 'kubb.config.mts', 'kubb.config.cts', 'kubb.config.js', 'kubb.config.cjs']\n\n for (const configFileName of configFileNames) {\n const configFilePath = path.resolve(process.cwd(), configFileName)\n if (!existsSync(configFilePath)) continue\n try {\n const userConfig = (await loadModule(configFilePath)) as Config\n await notify(NotifyTypes.CONFIG_LOADED, `Loaded ${configFileName} from current directory`)\n return { userConfig, cwd }\n } catch (err) {\n await notify(NotifyTypes.CONFIG_ERROR, `Failed to load ${configFileName}: ${err instanceof Error ? err.message : String(err)}`)\n }\n }\n\n await notify(NotifyTypes.CONFIG_ERROR, 'No config file found')\n throw new Error(`No config file found. Please provide a config path or create one of: ${configFileNames.join(', ')}`)\n}\n","import path from 'node:path'\nimport type { Config } from '@kubb/core'\n\n/**\n * Determine the root directory based on userConfig.root and resolvedConfigDir\n * 1. If userConfig.root exists and is absolute, use it as-is\n * 2. If userConfig.root exists and is relative, resolve it relative to config directory\n * 3. Otherwise, use the config directory as root\n */\nexport function resolveCwd(userConfig: Config, cwd: string): string {\n if (userConfig.root) {\n if (path.isAbsolute(userConfig.root)) {\n return userConfig.root\n }\n\n return path.resolve(cwd, userConfig.root)\n }\n\n return cwd\n}\n","import { isPromise } from '@internals/utils'\nimport type { CLIOptions, Config, PossibleConfig } from '@kubb/core'\n\nexport type ResolveUserConfigOptions = {\n configPath?: string\n logLevel?: string\n}\n\nexport async function resolveUserConfig(config: PossibleConfig<CLIOptions>, options: ResolveUserConfigOptions): Promise<Config> {\n const result = typeof config === 'function' ? config({ logLevel: options.logLevel as CLIOptions['logLevel'], config: options.configPath }) : config\n const resolved = isPromise(result) ? await result : result\n return (Array.isArray(resolved) ? resolved[0] : resolved) as Config\n}\n","import { AsyncEventEmitter, toError } from '@internals/utils'\nimport { type Config, createKubb, type KubbHooks } from '@kubb/core'\nimport { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport type * as v from 'valibot'\nimport { generateSchema } from '../schemas/generateSchema.ts'\nimport { NotifyTypes } from '../types.ts'\nimport { loadUserConfig } from '../utils/loadUserConfig.ts'\nimport { resolveCwd } from '../utils/resolveCwd.ts'\nimport { resolveUserConfig } from '../utils/resolveUserConfig.ts'\n\nexport const generateTool = defineTool(\n {\n name: 'generate',\n description: 'Generate OpenAPI spec helpers using Kubb configuration',\n schema: generateSchema,\n },\n async function generate(schema: v.InferInput<typeof generateSchema>) {\n const { config: configPath, input, output, logLevel } = schema\n\n try {\n const hooks = new AsyncEventEmitter<KubbHooks>()\n const messages: Array<string> = []\n\n const notify = async (type: string, message: string, _data?: Record<string, unknown>) => {\n messages.push(`${type}: ${message}`)\n }\n\n hooks.on('kubb:info', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.INFO, message)\n })\n\n hooks.on('kubb:success', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.SUCCESS, message)\n })\n\n hooks.on('kubb:error', async ({ error }: { error: Error }) => {\n await notify(NotifyTypes.ERROR, error.message)\n })\n\n hooks.on('kubb:warn', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.WARN, message)\n })\n\n hooks.on('kubb:plugin:start', async ({ plugin }) => {\n await notify(NotifyTypes.PLUGIN_START, `Plugin starting: ${plugin.name}`)\n })\n\n hooks.on('kubb:plugin:end', async ({ plugin, duration }) => {\n await notify(NotifyTypes.PLUGIN_END, `Plugin finished: ${plugin.name}`, { duration })\n })\n\n hooks.on('kubb:files:processing:start', async () => {\n await notify(NotifyTypes.FILES_START, 'Starting file processing')\n })\n\n hooks.on('kubb:files:processing:update', async ({ files }: { files: Array<{ file: { name: string } }> }) => {\n await notify(NotifyTypes.FILES_UPDATE, `Processing ${files.length} files`)\n })\n\n hooks.on('kubb:files:processing:end', async () => {\n await notify(NotifyTypes.FILES_END, 'File processing complete')\n })\n\n hooks.on('kubb:generation:start', async () => {\n await notify(NotifyTypes.GENERATION_START, 'Generation started')\n })\n\n hooks.on('kubb:generation:end', async () => {\n await notify(NotifyTypes.GENERATION_END, 'Generation ended')\n })\n\n let userConfig: Config\n let cwd: string\n\n try {\n const configResult = await loadUserConfig(configPath, { notify })\n userConfig = configResult.userConfig\n cwd = configResult.cwd\n\n if (Array.isArray(userConfig)) {\n throw new Error('Array type in kubb.config.ts is not supported in this tool. Please provide a single configuration object.')\n }\n\n userConfig = await resolveUserConfig(userConfig, {\n configPath,\n logLevel,\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error)\n await notify(NotifyTypes.CONFIG_ERROR, errorMessage)\n return tool.error(errorMessage)\n }\n\n const inputPath = input ?? (userConfig.input && 'path' in userConfig.input ? userConfig.input.path : undefined)\n\n const config: Config = {\n ...userConfig,\n root: resolveCwd(userConfig, cwd),\n input: inputPath\n ? {\n ...userConfig.input,\n path: inputPath,\n }\n : userConfig.input,\n output: output\n ? {\n ...userConfig.output,\n path: output,\n }\n : userConfig.output,\n }\n\n await notify(NotifyTypes.CONFIG_READY, 'Configuration ready')\n await notify(NotifyTypes.SETUP_START, 'Setting up Kubb')\n\n const kubb = createKubb(config, { hooks })\n await kubb.setup()\n await notify(NotifyTypes.SETUP_END, 'Kubb setup complete')\n\n await notify(NotifyTypes.BUILD_START, 'Starting build')\n const { files, failedPlugins, error } = await kubb.safeBuild()\n await notify(NotifyTypes.BUILD_END, `Build complete - Generated ${files.length} files`)\n\n if (error || failedPlugins.size > 0) {\n const allErrors: Array<Error> = [\n error,\n ...Array.from(failedPlugins)\n .filter((it) => it.error)\n .map((it) => it.error),\n ].filter(Boolean)\n\n await notify(NotifyTypes.BUILD_FAILED, `Build failed with ${allErrors.length} error(s)`)\n\n return tool.error(`Build failed:\\n${allErrors.map((err) => err.message).join('\\n')}\\n\\n${messages.join('\\n')}`)\n }\n\n await notify(NotifyTypes.BUILD_SUCCESS, `Build completed successfully - Generated ${files.length} files`)\n\n return tool.text(`Build completed successfully!\\n\\nGenerated ${files.length} files\\n\\n${messages.join('\\n')}`)\n } catch (caughtError) {\n const error = toError(caughtError)\n return tool.error(`Build error: ${error.message}\\n${error.stack ?? ''}`)\n }\n },\n)\n","import type { PluginOption } from './types.ts'\n\nexport const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const\n\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['plugin-ts'],\n} as const\n\nexport const availablePlugins: PluginOption[] = [\n {\n value: 'plugin-ts',\n label: 'TypeScript',\n hint: 'Recommended',\n packageName: '@kubb/plugin-ts',\n importName: 'pluginTs',\n category: 'types',\n },\n {\n value: 'plugin-client',\n label: 'Client (Fetch/Axios)',\n packageName: '@kubb/plugin-client',\n importName: 'pluginClient',\n category: 'client',\n },\n {\n value: 'plugin-react-query',\n label: 'React Query / TanStack Query',\n packageName: '@kubb/plugin-react-query',\n importName: 'pluginReactQuery',\n category: 'framework',\n },\n {\n value: 'plugin-vue-query',\n label: 'Vue Query',\n packageName: '@kubb/plugin-vue-query',\n importName: 'pluginVueQuery',\n category: 'framework',\n },\n {\n value: 'plugin-zod',\n label: 'Zod Schemas',\n packageName: '@kubb/plugin-zod',\n importName: 'pluginZod',\n category: 'validation',\n },\n {\n value: 'plugin-faker',\n label: 'Faker.js Mocks',\n packageName: '@kubb/plugin-faker',\n importName: 'pluginFaker',\n category: 'mocks',\n },\n {\n value: 'plugin-msw',\n label: 'MSW Handlers',\n packageName: '@kubb/plugin-msw',\n importName: 'pluginMsw',\n category: 'mocks',\n },\n {\n value: 'plugin-cypress',\n label: 'Cypress Tests',\n packageName: '@kubb/plugin-cypress',\n importName: 'pluginCypress',\n category: 'testing',\n },\n {\n value: 'plugin-mcp',\n label: 'MCP Server (AI / Model Context Protocol)',\n packageName: '@kubb/plugin-mcp',\n importName: 'pluginMcp',\n category: 'ai',\n },\n {\n value: 'plugin-redoc',\n label: 'ReDoc Documentation',\n packageName: '@kubb/plugin-redoc',\n importName: 'pluginRedoc',\n category: 'documentation',\n },\n]\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","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 * as v from 'valibot'\n\nexport const initSchema = v.object({\n input: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Path to OpenAPI spec (default: ./openapi.yaml)'))),\n output: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Output directory (default: ./src/gen)'))),\n plugins: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Comma-separated list of plugins: plugin-ts,plugin-zod,...'))),\n})\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { availablePlugins, generateConfigFile, KUBB_CONFIG_FILENAME, type PluginOption } from '@internals/shared'\nimport { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport { initSchema } from '../schemas/initSchema.ts'\n\nexport function resolvePlugins(pluginsFlag: string | undefined): Array<PluginOption> {\n if (!pluginsFlag) {\n return []\n }\n const requested = pluginsFlag\n .split(',')\n .map((v) => v.trim())\n .filter(Boolean)\n return availablePlugins.filter((p) => requested.includes(p.value))\n}\n\nexport const initTool = defineTool(\n {\n name: 'init',\n description: 'Scaffold a kubb.config.ts in the current directory (non-interactive). Does not install packages.',\n schema: initSchema,\n },\n async ({ input = './openapi.yaml', output = './src/gen', plugins }) => {\n const selected = resolvePlugins(plugins)\n const content = generateConfigFile({ selectedPlugins: selected, inputPath: input, outputPath: output })\n const dest = path.join(process.cwd(), KUBB_CONFIG_FILENAME)\n if (fs.existsSync(dest)) {\n return tool.error(`${KUBB_CONFIG_FILENAME} already exists at ${dest}. Delete it first before running init again.`)\n }\n fs.writeFileSync(dest, content, 'utf-8')\n const packageList = ['kubb', ...selected.map((p) => p.packageName)].join(' ')\n return tool.text(`Created kubb.config.ts\\n\\nInstall packages:\\n npm install ${packageList}\\n\\nThen run:\\n npx kubb generate`)\n },\n)\n","import * as v from 'valibot'\n\nexport const validateSchema = v.object({\n input: v.pipe(v.string(), v.minLength(1), v.description('Path or URL to the OpenAPI/Swagger specification')),\n})\n","import { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport { validateSchema } from '../schemas/validateSchema.ts'\n\nexport const validateTool = defineTool(\n {\n name: 'validate',\n description: 'Validate an OpenAPI/Swagger specification file or URL',\n schema: validateSchema,\n },\n async ({ input }) => {\n let mod: typeof import('@kubb/adapter-oas')\n try {\n mod = await import('@kubb/adapter-oas')\n } catch {\n return tool.error('The validate tool requires @kubb/adapter-oas.\\nInstall: npm install @kubb/adapter-oas')\n }\n try {\n await mod.adapterOas().validate(input, { throwOnError: true })\n return tool.text(`Validation successful: ${input}`)\n } catch (err) {\n return tool.error(`Validation failed:\\n${err instanceof Error ? err.message : String(err)}`)\n }\n },\n)\n","import http from 'node:http'\nimport { createRequestListener } from '@remix-run/node-fetch-server'\nimport { ValibotJsonSchemaAdapter } from '@tmcp/adapter-valibot'\nimport { HttpTransport } from '@tmcp/transport-http'\nimport { StdioTransport } from '@tmcp/transport-stdio'\nimport { McpServer } from 'tmcp'\nimport { version } from '../package.json'\nimport { generateTool } from './tools/generate.ts'\nimport { initTool } from './tools/init.ts'\nimport { validateTool } from './tools/validate.ts'\n\nexport type ServerOptions = {\n port?: number\n host?: string\n}\n\nexport function createMcpServer() {\n const server = new McpServer({ name: 'Kubb', version }, { adapter: new ValibotJsonSchemaAdapter(), capabilities: { tools: {} } })\n server.tools([generateTool, validateTool, initTool])\n return server\n}\n\nexport async function startServer({ port, host = 'localhost' }: ServerOptions = {}) {\n const server = createMcpServer()\n\n if (port === undefined) {\n new StdioTransport(server).listen()\n return\n }\n\n const transport = new HttpTransport(server, { path: '/mcp' })\n const httpServer = http.createServer(\n createRequestListener(async (request) => {\n const response = await transport.respond(request)\n return response ?? new Response('Not Found', { status: 404 })\n }),\n )\n httpServer.listen(port, host, () => {\n console.log(`Kubb MCP server on http://${host}:${port}`)\n })\n\n const closeServer = () => httpServer.close()\n process.once('SIGINT', closeServer)\n process.once('SIGTERM', closeServer)\n httpServer.once('close', () => {\n process.off('SIGINT', closeServer)\n process.off('SIGTERM', closeServer)\n })\n}\n","import { startServer } from './server.ts'\n\nexport { createMcpServer } from './server.ts'\nexport type { ServerOptions } from './server.ts'\n\nexport async function run(_argv?: Array<string>, options?: import('./server.ts').ServerOptions): Promise<void> {\n await startServer(options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC8BA,SAAgB,QAAQ,OAAuB;CAC7C,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACjE;;;;;;;;;;;;;;ACbA,IAAa,oBAAb,MAAoF;;;;;CAKlF,YAAY,cAAc,IAAI;EAC5B,KAAKA,SAAS,gBAAgB,WAAW;CAC3C;CAEA,WAAW,IAAIC,YAAAA,aAAiB;;;;;;;;;;CAWhC,KAAgD,WAAuB,GAAG,WAAsD;EAC9H,MAAM,YAAY,KAAKD,SAAS,UAAU,SAAS;EAEnD,IAAI,UAAU,WAAW,GACvB;EAGF,OAAO,KAAKE,SAAS,WAAW,WAAW,SAAS;CACtD;CAEA,MAAMA,SACJ,WACA,WACA,WACe;EACf,KAAK,MAAM,YAAY,WACrB,IAAI;GACF,MAAM,SAAS,GAAG,SAAS;EAC7B,SAAS,KAAK;GACZ,IAAI;GACJ,IAAI;IACF,iBAAiB,KAAK,UAAU,SAAS;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MAAM;CACzD,CAAC;CAED,MAAM,oBAAoB,WAAW,MAAM;CAC3C,QAAQ,KAAK,UAAU,WAAW;CAClC,QAAQ,KAAK,WAAW,WAAW;CACnC,WAAW,KAAK,eAAe;EAC7B,QAAQ,IAAI,UAAU,WAAW;EACjC,QAAQ,IAAI,WAAW,WAAW;CACpC,CAAC;AACH;;;AC3CA,eAAsB,IAAI,OAAuB,SAA8D;CAC7G,MAAM,YAAY,OAAO;AAC3B"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["#emitter","NodeEventEmitter","#emitAll","v","jiti","path","path","Diagnostics","tool","isProblemDiagnostic","v","path","process","fs","tool","v","tool","Diagnostics","McpServer","ValibotJsonSchemaAdapter","StdioTransport","HttpTransport","http"],"sources":["../package.json","../../../internals/utils/src/errors.ts","../../../internals/utils/src/asyncEventEmitter.ts","../../../internals/utils/src/promise.ts","../src/schemas/generateSchema.ts","../src/utils/formatDiagnostics.ts","../src/types.ts","../src/constants.ts","../src/utils/loadUserConfig.ts","../src/utils/resolveCwd.ts","../src/utils/resolveUserConfig.ts","../src/tools/generate.ts","../../../internals/shared/src/constants.ts","../../../internals/shared/src/init.ts","../src/schemas/initSchema.ts","../src/tools/init.ts","../src/schemas/validateSchema.ts","../src/tools/validate.ts","../src/server.ts","../src/index.ts"],"sourcesContent":["","/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n *\n * @example\n * ```ts\n * throw new BuildError('Build failed', { errors: [err1, err2] })\n * ```\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new BuildError('Build failed', { cause: toError(err), errors: [] })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.\n *\n * @example\n * ```ts\n * const cause = toCause(buildError) // Error | undefined\n * ```\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport { toError } from './errors.ts'\n\n/**\n * A function that can be registered as an event listener, synchronous or async.\n */\ntype AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>\n\n/**\n * Typed `EventEmitter` that awaits all async listeners before resolving.\n * Wraps Node's `EventEmitter` with full TypeScript event-map inference.\n *\n * @example\n * ```ts\n * const emitter = new AsyncEventEmitter<{ build: [name: string] }>()\n * emitter.on('build', async (name) => { console.log(name) })\n * await emitter.emit('build', 'petstore') // all listeners awaited\n * ```\n */\nexport class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {\n /**\n * Maximum number of listeners per event before Node emits a memory-leak warning.\n * @default 10\n */\n constructor(maxListener = 10) {\n this.#emitter.setMaxListeners(maxListener)\n }\n\n #emitter = new NodeEventEmitter()\n\n /**\n * Emits `eventName` and awaits all registered listeners sequentially.\n * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.\n *\n * @example\n * ```ts\n * await emitter.emit('build', 'petstore')\n * ```\n */\n emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> | void {\n const listeners = this.#emitter.listeners(eventName) as Array<AsyncListener<TEvents[TEventName]>>\n\n if (listeners.length === 0) {\n return\n }\n\n return this.#emitAll(eventName, listeners, eventArgs)\n }\n\n async #emitAll<TEventName extends keyof TEvents & string>(\n eventName: TEventName,\n listeners: Array<AsyncListener<TEvents[TEventName]>>,\n eventArgs: TEvents[TEventName],\n ): Promise<void> {\n for (const listener of listeners) {\n try {\n await listener(...eventArgs)\n } catch (err) {\n let serializedArgs: string\n try {\n serializedArgs = JSON.stringify(eventArgs)\n } catch {\n serializedArgs = String(eventArgs)\n }\n throw new Error(`Error in async listener for \"${eventName}\" with eventArgs ${serializedArgs}`, { cause: toError(err) })\n }\n }\n }\n\n /**\n * Registers a persistent listener for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', async (name) => { console.log(name) })\n * ```\n */\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.on(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Registers a one-shot listener that removes itself after the first invocation.\n *\n * @example\n * ```ts\n * emitter.onOnce('build', async (name) => { console.log(name) })\n * ```\n */\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n const wrapper: AsyncListener<TEvents[TEventName]> = (...args) => {\n this.off(eventName, wrapper)\n return handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n /**\n * Removes a previously registered listener.\n *\n * @example\n * ```ts\n * emitter.off('build', handler)\n * ```\n */\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.off(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Returns the number of listeners registered for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', handler)\n * emitter.listenerCount('build') // 1\n * ```\n */\n listenerCount<TEventName extends keyof TEvents & string>(eventName: TEventName): number {\n return this.#emitter.listenerCount(eventName)\n }\n\n /**\n * Raises or lowers the per-event listener ceiling before Node warns about a memory leak.\n * Set this above the expected listener count when many listeners attach by design.\n *\n * @example\n * ```ts\n * emitter.setMaxListeners(40)\n * ```\n */\n setMaxListeners(max: number): void {\n this.#emitter.setMaxListeners(max)\n }\n\n /**\n * Returns the current per-event listener ceiling.\n */\n getMaxListeners(): number {\n return this.#emitter.getMaxListeners()\n }\n\n /**\n * Removes all listeners from every event channel.\n *\n * @example\n * ```ts\n * emitter.removeAll()\n * ```\n */\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","function* chunks<T>(arr: readonly T[], size: number): Generator<T[]> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: readonly T[] | AsyncIterable<T>,\n process: (batch: T[]) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: T[] = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/**\n * Runs `work`, passing `flush` as its periodic-flush callback, then calls\n * `flush` once more to drain any items that did not cross a flush boundary.\n *\n * @example\n * ```ts\n * await withDrain(\n * (flush) => processItems(items, { flush }),\n * () => writeRemainingFiles(),\n * )\n * ```\n */\nexport async function withDrain(work: (flush: () => Promise<void>) => Promise<void>, flush: () => Promise<void>): Promise<void> {\n await work(flush)\n await flush()\n}\n\n/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n\n/**\n * Returns a wrapper that caches the result of the first invocation and replays\n * it for every subsequent call, ignoring later arguments.\n *\n * Works for sync and async factories — for async, the cached value is the\n * promise itself, so concurrent callers share one in-flight execution and\n * cannot race each other.\n *\n * @example\n * ```ts\n * const loadDocument = once(async (path: string) => parse(await readFile(path)))\n * const a = loadDocument('./a.yaml') // parses\n * const b = loadDocument('./b.yaml') // returns the cached promise from the first call\n * ```\n */\nexport function once<TArgs extends unknown[], TReturn>(factory: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn {\n let cache: { value: TReturn } | undefined\n return (...args: TArgs): TReturn => {\n if (!cache) cache = { value: factory(...args) }\n return cache.value\n }\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: readonly T[]): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import * as v from 'valibot'\n\nexport const generateSchema = v.object({\n config: v.optional(\n v.pipe(v.string(), v.minLength(1), v.description('Path to kubb.config file (supports .ts, .js, .cjs). If not provided, will look for kubb.config.{ts,js,cjs} in current directory')),\n ),\n input: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Path to OpenAPI/Swagger spec file (overrides config)'))),\n output: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Output directory path (overrides config)'))),\n logLevel: v.optional(\n v.pipe(v.picklist(['silent', 'info', 'verbose']), v.description('Log level for build output')),\n 'info',\n ),\n})\n","import type { SerializedDiagnostic } from '@kubb/core'\n\n/**\n * Renders serialized diagnostics as a plain-text block for an AI assistant. Each entry\n * keeps the stable `code`, the source pointer, the suggested fix, and the docs link, so\n * the agent can act on the problem rather than parsing a bare message. No ANSI styling,\n * unlike the CLI renderer.\n */\nexport function formatDiagnostics(diagnostics: ReadonlyArray<SerializedDiagnostic>): string {\n return diagnostics.map((diagnostic) => formatDiagnostic(diagnostic)).join('\\n\\n')\n}\n\nfunction formatDiagnostic(diagnostic: SerializedDiagnostic): string {\n const { code, severity, message, location, help, plugin, docsUrl } = diagnostic\n const rule = plugin ? `${plugin}(${code})` : code\n const lines = [`${severity} ${rule}: ${message}`]\n\n if (location && 'pointer' in location) {\n lines.push(` at ${location.pointer}`)\n }\n if (help) {\n lines.push(` help: ${help}`)\n }\n if (docsUrl) {\n lines.push(` docs: ${docsUrl}`)\n }\n\n return lines.join('\\n')\n}\n","export const NotifyTypes = {\n INFO: 'INFO',\n SUCCESS: 'SUCCESS',\n ERROR: 'ERROR',\n WARN: 'WARN',\n DIAGNOSTIC: 'DIAGNOSTIC',\n PLUGIN_START: 'PLUGIN_START',\n PLUGIN_END: 'PLUGIN_END',\n FILES_START: 'FILES_START',\n FILES_UPDATE: 'FILES_UPDATE',\n FILES_END: 'FILES_END',\n GENERATION_START: 'GENERATION_START',\n GENERATION_END: 'GENERATION_END',\n CONFIG_LOADED: 'CONFIG_LOADED',\n CONFIG_ERROR: 'CONFIG_ERROR',\n CONFIG_READY: 'CONFIG_READY',\n SETUP_START: 'SETUP_START',\n SETUP_END: 'SETUP_END',\n BUILD_START: 'BUILD_START',\n BUILD_END: 'BUILD_END',\n BUILD_FAILED: 'BUILD_FAILED',\n BUILD_SUCCESS: 'BUILD_SUCCESS',\n FATAL_ERROR: 'FATAL_ERROR',\n} as const\n","export const ALLOWED_CONFIG_EXTENSIONS = new Set(['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'])\n","import { existsSync } from 'node:fs'\nimport path from 'node:path'\nimport type { Config } from '@kubb/core'\nimport { createJiti } from 'jiti'\nimport { ALLOWED_CONFIG_EXTENSIONS } from '../constants.ts'\nimport { NotifyTypes } from '../types.ts'\n\ntype NotifyFunction = (type: string, message: string, data?: Record<string, unknown>) => Promise<void>\n\nconst jiti = createJiti(import.meta.url, {\n jsx: {\n runtime: 'automatic',\n importSource: '@kubb/renderer-jsx',\n },\n moduleCache: false,\n})\n\nconst loadedModules = new Map<string, unknown>()\n\nasync function loadModule(filePath: string): Promise<unknown> {\n const ext = path.extname(filePath)\n if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {\n throw new Error(`Invalid config file extension \"${ext}\". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`)\n }\n if (loadedModules.has(filePath)) {\n return loadedModules.get(filePath)\n }\n const mod = await jiti.import(filePath, { default: true })\n loadedModules.set(filePath, mod)\n return mod\n}\n\nexport async function loadUserConfig(configPath: string | undefined, { notify }: { notify: NotifyFunction }): Promise<{ userConfig: Config; cwd: string }> {\n if (configPath) {\n const ext = path.extname(configPath)\n if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {\n const msg = `Invalid config file extension \"${ext}\". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n const base = path.resolve(process.cwd())\n const resolvedConfigPath = path.resolve(base, configPath)\n const relative = path.relative(base, resolvedConfigPath)\n if (relative.startsWith('..') || path.isAbsolute(relative)) {\n const msg = 'Invalid config file path: must be within the current working directory'\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n const cwd = path.dirname(resolvedConfigPath)\n try {\n const userConfig = (await loadModule(resolvedConfigPath)) as Config\n await notify(NotifyTypes.CONFIG_LOADED, `Loaded config from ${resolvedConfigPath}`)\n return { userConfig, cwd }\n } catch (error) {\n const msg = `Failed to load config: ${error instanceof Error ? error.message : String(error)}`\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n }\n\n const cwd = process.cwd()\n const configFileNames = ['kubb.config.ts', 'kubb.config.mts', 'kubb.config.cts', 'kubb.config.js', 'kubb.config.cjs']\n\n for (const configFileName of configFileNames) {\n const configFilePath = path.resolve(process.cwd(), configFileName)\n if (!existsSync(configFilePath)) continue\n try {\n const userConfig = (await loadModule(configFilePath)) as Config\n await notify(NotifyTypes.CONFIG_LOADED, `Loaded ${configFileName} from current directory`)\n return { userConfig, cwd }\n } catch (err) {\n await notify(NotifyTypes.CONFIG_ERROR, `Failed to load ${configFileName}: ${err instanceof Error ? err.message : String(err)}`)\n }\n }\n\n await notify(NotifyTypes.CONFIG_ERROR, 'No config file found')\n throw new Error(`No config file found. Please provide a config path or create one of: ${configFileNames.join(', ')}`)\n}\n","import path from 'node:path'\nimport type { Config } from '@kubb/core'\n\n/**\n * Determine the root directory based on userConfig.root and resolvedConfigDir\n * 1. If userConfig.root exists and is absolute, use it as-is\n * 2. If userConfig.root exists and is relative, resolve it relative to config directory\n * 3. Otherwise, use the config directory as root\n */\nexport function resolveCwd(userConfig: Config, cwd: string): string {\n if (userConfig.root) {\n if (path.isAbsolute(userConfig.root)) {\n return userConfig.root\n }\n\n return path.resolve(cwd, userConfig.root)\n }\n\n return cwd\n}\n","import { isPromise } from '@internals/utils'\nimport type { CLIOptions, Config, PossibleConfig } from '@kubb/core'\n\nexport type ResolveUserConfigOptions = {\n configPath?: string\n logLevel?: string\n}\n\nexport async function resolveUserConfig(config: PossibleConfig<CLIOptions>, options: ResolveUserConfigOptions): Promise<Config> {\n const result = typeof config === 'function' ? config({ logLevel: options.logLevel as CLIOptions['logLevel'], config: options.configPath }) : config\n const resolved = isPromise(result) ? await result : result\n return (Array.isArray(resolved) ? resolved[0] : resolved) as Config\n}\n","import { AsyncEventEmitter } from '@internals/utils'\nimport { type Config, createKubb, type Diagnostic, Diagnostics, isProblemDiagnostic, type KubbHooks } from '@kubb/core'\nimport { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport type * as v from 'valibot'\nimport { generateSchema } from '../schemas/generateSchema.ts'\nimport { formatDiagnostics } from '../utils/formatDiagnostics.ts'\nimport { NotifyTypes } from '../types.ts'\nimport { loadUserConfig } from '../utils/loadUserConfig.ts'\nimport { resolveCwd } from '../utils/resolveCwd.ts'\nimport { resolveUserConfig } from '../utils/resolveUserConfig.ts'\n\nexport const generateTool = defineTool(\n {\n name: 'generate',\n description: 'Generate OpenAPI spec helpers using Kubb configuration',\n schema: generateSchema,\n },\n async function generate(schema: v.InferInput<typeof generateSchema>) {\n const { config: configPath, input, output, logLevel } = schema\n\n try {\n const hooks = new AsyncEventEmitter<KubbHooks>()\n const messages: Array<string> = []\n\n const notify = async (type: string, message: string, data?: Record<string, unknown>) => {\n messages.push(data ? `${type}: ${message} ${JSON.stringify(data)}` : `${type}: ${message}`)\n }\n\n hooks.on('kubb:info', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.INFO, message)\n })\n\n hooks.on('kubb:success', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.SUCCESS, message)\n })\n\n hooks.on('kubb:error', async ({ error }: { error: Error }) => {\n await notify(NotifyTypes.ERROR, error.message)\n })\n\n hooks.on('kubb:warn', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.WARN, message)\n })\n\n hooks.on('kubb:diagnostic', async ({ diagnostic }: { diagnostic: Diagnostic }) => {\n await notify(NotifyTypes.DIAGNOSTIC, diagnostic.message, Diagnostics.serialize(diagnostic))\n })\n\n hooks.on('kubb:plugin:start', async ({ plugin }) => {\n await notify(NotifyTypes.PLUGIN_START, `Plugin starting: ${plugin.name}`)\n })\n\n hooks.on('kubb:plugin:end', async ({ plugin, duration }) => {\n await notify(NotifyTypes.PLUGIN_END, `Plugin finished: ${plugin.name}`, { duration })\n })\n\n hooks.on('kubb:files:processing:start', async () => {\n await notify(NotifyTypes.FILES_START, 'Starting file processing')\n })\n\n hooks.on('kubb:files:processing:update', async ({ files }: { files: Array<{ file: { name: string } }> }) => {\n await notify(NotifyTypes.FILES_UPDATE, `Processing ${files.length} files`)\n })\n\n hooks.on('kubb:files:processing:end', async () => {\n await notify(NotifyTypes.FILES_END, 'File processing complete')\n })\n\n hooks.on('kubb:generation:start', async () => {\n await notify(NotifyTypes.GENERATION_START, 'Generation started')\n })\n\n hooks.on('kubb:generation:end', async () => {\n await notify(NotifyTypes.GENERATION_END, 'Generation ended')\n })\n\n let userConfig: Config\n let cwd: string\n\n try {\n const configResult = await loadUserConfig(configPath, { notify })\n userConfig = configResult.userConfig\n cwd = configResult.cwd\n\n if (Array.isArray(userConfig)) {\n throw new Error('Array type in kubb.config.ts is not supported in this tool. Please provide a single configuration object.')\n }\n\n userConfig = await resolveUserConfig(userConfig, {\n configPath,\n logLevel,\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error)\n await notify(NotifyTypes.CONFIG_ERROR, errorMessage)\n return tool.error(errorMessage)\n }\n\n const inputPath = input ?? (userConfig.input && 'path' in userConfig.input ? userConfig.input.path : undefined)\n\n const config: Config = {\n ...userConfig,\n root: resolveCwd(userConfig, cwd),\n input: inputPath\n ? {\n ...userConfig.input,\n path: inputPath,\n }\n : userConfig.input,\n output: output\n ? {\n ...userConfig.output,\n path: output,\n }\n : userConfig.output,\n }\n\n await notify(NotifyTypes.CONFIG_READY, 'Configuration ready')\n await notify(NotifyTypes.SETUP_START, 'Setting up Kubb')\n\n const kubb = createKubb(config, { hooks })\n await kubb.setup()\n await notify(NotifyTypes.SETUP_END, 'Kubb setup complete')\n\n await notify(NotifyTypes.BUILD_START, 'Starting build')\n const { files, diagnostics } = await kubb.safeBuild()\n await notify(NotifyTypes.BUILD_END, `Build complete - Generated ${files.length} files`)\n\n const problems = diagnostics.filter(isProblemDiagnostic)\n const errors = problems.filter((diagnostic) => diagnostic.severity === 'error')\n if (errors.length > 0) {\n await notify(NotifyTypes.BUILD_FAILED, `Build failed with ${errors.length} diagnostic(s)`)\n\n const serialized = problems.map((diagnostic) => Diagnostics.serialize(diagnostic))\n return tool.error(`Build failed:\\n${formatDiagnostics(serialized)}\\n\\n\\`\\`\\`json\\n${JSON.stringify(serialized, null, 2)}\\n\\`\\`\\``)\n }\n\n await notify(NotifyTypes.BUILD_SUCCESS, `Build completed successfully - Generated ${files.length} files`)\n\n return tool.text(`Build completed successfully!\\n\\nGenerated ${files.length} files\\n\\n${messages.join('\\n')}`)\n } catch (caughtError) {\n const serialized = Diagnostics.serialize(Diagnostics.from(caughtError))\n return tool.error(`Build error:\\n${formatDiagnostics([serialized])}\\n\\n\\`\\`\\`json\\n${JSON.stringify(serialized, null, 2)}\\n\\`\\`\\``)\n }\n },\n)\n","import type { PluginOption } from './types.ts'\n\nexport const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const\n\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['plugin-ts'],\n} as const\n\nexport const availablePlugins: PluginOption[] = [\n {\n value: 'plugin-ts',\n label: 'TypeScript',\n hint: 'Recommended',\n packageName: '@kubb/plugin-ts',\n importName: 'pluginTs',\n category: 'types',\n },\n {\n value: 'plugin-client',\n label: 'Client (Fetch/Axios)',\n packageName: '@kubb/plugin-client',\n importName: 'pluginClient',\n category: 'client',\n },\n {\n value: 'plugin-react-query',\n label: 'React Query / TanStack Query',\n packageName: '@kubb/plugin-react-query',\n importName: 'pluginReactQuery',\n category: 'framework',\n },\n {\n value: 'plugin-vue-query',\n label: 'Vue Query',\n packageName: '@kubb/plugin-vue-query',\n importName: 'pluginVueQuery',\n category: 'framework',\n },\n {\n value: 'plugin-zod',\n label: 'Zod Schemas',\n packageName: '@kubb/plugin-zod',\n importName: 'pluginZod',\n category: 'validation',\n },\n {\n value: 'plugin-faker',\n label: 'Faker.js Mocks',\n packageName: '@kubb/plugin-faker',\n importName: 'pluginFaker',\n category: 'mocks',\n },\n {\n value: 'plugin-msw',\n label: 'MSW Handlers',\n packageName: '@kubb/plugin-msw',\n importName: 'pluginMsw',\n category: 'mocks',\n },\n {\n value: 'plugin-cypress',\n label: 'Cypress Tests',\n packageName: '@kubb/plugin-cypress',\n importName: 'pluginCypress',\n category: 'testing',\n },\n {\n value: 'plugin-mcp',\n label: 'MCP Server (AI / Model Context Protocol)',\n packageName: '@kubb/plugin-mcp',\n importName: 'pluginMcp',\n category: 'ai',\n },\n {\n value: 'plugin-redoc',\n label: 'ReDoc Documentation',\n packageName: '@kubb/plugin-redoc',\n importName: 'pluginRedoc',\n category: 'documentation',\n },\n]\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","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 * as v from 'valibot'\n\nexport const initSchema = v.object({\n input: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Path to OpenAPI spec (default: ./openapi.yaml)'))),\n output: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Output directory (default: ./src/gen)'))),\n plugins: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Comma-separated list of plugins: plugin-ts,plugin-zod,...'))),\n})\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { availablePlugins, generateConfigFile, KUBB_CONFIG_FILENAME, type PluginOption } from '@internals/shared'\nimport { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport { initSchema } from '../schemas/initSchema.ts'\n\nexport function resolvePlugins(pluginsFlag: string | undefined): Array<PluginOption> {\n if (!pluginsFlag) {\n return []\n }\n const requested = pluginsFlag\n .split(',')\n .map((v) => v.trim())\n .filter(Boolean)\n return availablePlugins.filter((p) => requested.includes(p.value))\n}\n\nexport const initTool = defineTool(\n {\n name: 'init',\n description: 'Scaffold a kubb.config.ts in the current directory (non-interactive). Does not install packages.',\n schema: initSchema,\n },\n async ({ input = './openapi.yaml', output = './src/gen', plugins }) => {\n const selected = resolvePlugins(plugins)\n const content = generateConfigFile({ selectedPlugins: selected, inputPath: input, outputPath: output })\n const dest = path.join(process.cwd(), KUBB_CONFIG_FILENAME)\n if (fs.existsSync(dest)) {\n return tool.error(`${KUBB_CONFIG_FILENAME} already exists at ${dest}. Delete it first before running init again.`)\n }\n fs.writeFileSync(dest, content, 'utf-8')\n const packageList = ['kubb', ...selected.map((p) => p.packageName)].join(' ')\n return tool.text(`Created kubb.config.ts\\n\\nInstall packages:\\n npm install ${packageList}\\n\\nThen run:\\n npx kubb generate`)\n },\n)\n","import * as v from 'valibot'\n\nexport const validateSchema = v.object({\n input: v.pipe(v.string(), v.minLength(1), v.description('Path or URL to the OpenAPI/Swagger specification')),\n})\n","import { Diagnostics } from '@kubb/core'\nimport { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport { validateSchema } from '../schemas/validateSchema.ts'\nimport { formatDiagnostics } from '../utils/formatDiagnostics.ts'\n\nexport const validateTool = defineTool(\n {\n name: 'validate',\n description: 'Validate an OpenAPI/Swagger specification file or URL',\n schema: validateSchema,\n },\n async ({ input }) => {\n let mod: typeof import('@kubb/adapter-oas')\n try {\n mod = await import('@kubb/adapter-oas')\n } catch {\n return tool.error('The validate tool requires @kubb/adapter-oas.\\nInstall: npm install @kubb/adapter-oas')\n }\n try {\n await mod.adapterOas().validate(input, { throwOnError: true })\n return tool.text(`Validation successful: ${input}`)\n } catch (err) {\n const serialized = Diagnostics.serialize(Diagnostics.from(err))\n return tool.error(`Validation failed:\\n${formatDiagnostics([serialized])}\\n\\n\\`\\`\\`json\\n${JSON.stringify(serialized, null, 2)}\\n\\`\\`\\``)\n }\n },\n)\n","import http from 'node:http'\nimport { createRequestListener } from '@remix-run/node-fetch-server'\nimport { ValibotJsonSchemaAdapter } from '@tmcp/adapter-valibot'\nimport { HttpTransport } from '@tmcp/transport-http'\nimport { StdioTransport } from '@tmcp/transport-stdio'\nimport { McpServer } from 'tmcp'\nimport { version } from '../package.json'\nimport { generateTool } from './tools/generate.ts'\nimport { initTool } from './tools/init.ts'\nimport { validateTool } from './tools/validate.ts'\n\nexport type ServerOptions = {\n port?: number\n host?: string\n}\n\nexport function createMcpServer() {\n const server = new McpServer({ name: 'Kubb', version }, { adapter: new ValibotJsonSchemaAdapter(), capabilities: { tools: {} } })\n server.tools([generateTool, validateTool, initTool])\n return server\n}\n\nexport async function startServer({ port, host = 'localhost' }: ServerOptions = {}) {\n const server = createMcpServer()\n\n if (port === undefined) {\n new StdioTransport(server).listen()\n return\n }\n\n const transport = new HttpTransport(server, { path: '/mcp' })\n const httpServer = http.createServer(\n createRequestListener(async (request) => {\n const response = await transport.respond(request)\n return response ?? new Response('Not Found', { status: 404 })\n }),\n )\n httpServer.listen(port, host, () => {\n console.log(`Kubb MCP server on http://${host}:${port}`)\n })\n\n const closeServer = () => httpServer.close()\n process.once('SIGINT', closeServer)\n process.once('SIGTERM', closeServer)\n httpServer.once('close', () => {\n process.off('SIGINT', closeServer)\n process.off('SIGTERM', closeServer)\n })\n}\n","import { startServer } from './server.ts'\n\nexport { createMcpServer } from './server.ts'\nexport type { ServerOptions } from './server.ts'\n\nexport async function run(_argv?: Array<string>, options?: import('./server.ts').ServerOptions): Promise<void> {\n await startServer(options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC8BA,SAAgB,QAAQ,OAAuB;CAC7C,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACjE;;;;;;;;;;;;;;ACbA,IAAa,oBAAb,MAAoF;;;;;CAKlF,YAAY,cAAc,IAAI;EAC5B,KAAKA,SAAS,gBAAgB,WAAW;CAC3C;CAEA,WAAW,IAAIC,YAAAA,aAAiB;;;;;;;;;;CAWhC,KAAgD,WAAuB,GAAG,WAAsD;EAC9H,MAAM,YAAY,KAAKD,SAAS,UAAU,SAAS;EAEnD,IAAI,UAAU,WAAW,GACvB;EAGF,OAAO,KAAKE,SAAS,WAAW,WAAW,SAAS;CACtD;CAEA,MAAMA,SACJ,WACA,WACA,WACe;EACf,KAAK,MAAM,YAAY,WACrB,IAAI;GACF,MAAM,SAAS,GAAG,SAAS;EAC7B,SAAS,KAAK;GACZ,IAAI;GACJ,IAAI;IACF,iBA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CAAC;AACH;;;AC3CA,eAAsB,IAAI,OAAuB,SAA8D;CAC7G,MAAM,YAAY,OAAO;AAC3B"}
|
package/dist/index.js
CHANGED
|
@@ -8,14 +8,14 @@ import { McpServer } from "tmcp";
|
|
|
8
8
|
import { EventEmitter } from "node:events";
|
|
9
9
|
import fs, { existsSync } from "node:fs";
|
|
10
10
|
import path from "node:path";
|
|
11
|
-
import { createKubb } from "@kubb/core";
|
|
11
|
+
import { Diagnostics, createKubb, isProblemDiagnostic } from "@kubb/core";
|
|
12
12
|
import { defineTool } from "tmcp/tool";
|
|
13
13
|
import { tool } from "tmcp/utils";
|
|
14
14
|
import * as v from "valibot";
|
|
15
15
|
import { createJiti } from "jiti";
|
|
16
16
|
import process$1 from "node:process";
|
|
17
17
|
//#region package.json
|
|
18
|
-
var version = "5.0.0-beta.
|
|
18
|
+
var version = "5.0.0-beta.37";
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region ../../internals/utils/src/errors.ts
|
|
21
21
|
/**
|
|
@@ -131,6 +131,24 @@ var AsyncEventEmitter = class {
|
|
|
131
131
|
return this.#emitter.listenerCount(eventName);
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
|
+
* Raises or lowers the per-event listener ceiling before Node warns about a memory leak.
|
|
135
|
+
* Set this above the expected listener count when many listeners attach by design.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* emitter.setMaxListeners(40)
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
setMaxListeners(max) {
|
|
143
|
+
this.#emitter.setMaxListeners(max);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Returns the current per-event listener ceiling.
|
|
147
|
+
*/
|
|
148
|
+
getMaxListeners() {
|
|
149
|
+
return this.#emitter.getMaxListeners();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
134
152
|
* Removes all listeners from every event channel.
|
|
135
153
|
*
|
|
136
154
|
* @example
|
|
@@ -163,20 +181,37 @@ const generateSchema = v.object({
|
|
|
163
181
|
output: v.optional(v.pipe(v.string(), v.minLength(1), v.description("Output directory path (overrides config)"))),
|
|
164
182
|
logLevel: v.optional(v.pipe(v.picklist([
|
|
165
183
|
"silent",
|
|
166
|
-
"error",
|
|
167
|
-
"warn",
|
|
168
184
|
"info",
|
|
169
|
-
"verbose"
|
|
170
|
-
"debug"
|
|
185
|
+
"verbose"
|
|
171
186
|
]), v.description("Log level for build output")), "info")
|
|
172
187
|
});
|
|
173
188
|
//#endregion
|
|
189
|
+
//#region src/utils/formatDiagnostics.ts
|
|
190
|
+
/**
|
|
191
|
+
* Renders serialized diagnostics as a plain-text block for an AI assistant. Each entry
|
|
192
|
+
* keeps the stable `code`, the source pointer, the suggested fix, and the docs link, so
|
|
193
|
+
* the agent can act on the problem rather than parsing a bare message. No ANSI styling,
|
|
194
|
+
* unlike the CLI renderer.
|
|
195
|
+
*/
|
|
196
|
+
function formatDiagnostics(diagnostics) {
|
|
197
|
+
return diagnostics.map((diagnostic) => formatDiagnostic(diagnostic)).join("\n\n");
|
|
198
|
+
}
|
|
199
|
+
function formatDiagnostic(diagnostic) {
|
|
200
|
+
const { code, severity, message, location, help, plugin, docsUrl } = diagnostic;
|
|
201
|
+
const lines = [`${severity} ${plugin ? `${plugin}(${code})` : code}: ${message}`];
|
|
202
|
+
if (location && "pointer" in location) lines.push(` at ${location.pointer}`);
|
|
203
|
+
if (help) lines.push(` help: ${help}`);
|
|
204
|
+
if (docsUrl) lines.push(` docs: ${docsUrl}`);
|
|
205
|
+
return lines.join("\n");
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
174
208
|
//#region src/types.ts
|
|
175
209
|
const NotifyTypes = {
|
|
176
210
|
INFO: "INFO",
|
|
177
211
|
SUCCESS: "SUCCESS",
|
|
178
212
|
ERROR: "ERROR",
|
|
179
213
|
WARN: "WARN",
|
|
214
|
+
DIAGNOSTIC: "DIAGNOSTIC",
|
|
180
215
|
PLUGIN_START: "PLUGIN_START",
|
|
181
216
|
PLUGIN_END: "PLUGIN_END",
|
|
182
217
|
FILES_START: "FILES_START",
|
|
@@ -314,8 +349,8 @@ const generateTool = defineTool({
|
|
|
314
349
|
try {
|
|
315
350
|
const hooks = new AsyncEventEmitter();
|
|
316
351
|
const messages = [];
|
|
317
|
-
const notify = async (type, message,
|
|
318
|
-
messages.push(`${type}: ${message}`);
|
|
352
|
+
const notify = async (type, message, data) => {
|
|
353
|
+
messages.push(data ? `${type}: ${message} ${JSON.stringify(data)}` : `${type}: ${message}`);
|
|
319
354
|
};
|
|
320
355
|
hooks.on("kubb:info", async ({ message }) => {
|
|
321
356
|
await notify(NotifyTypes.INFO, message);
|
|
@@ -329,6 +364,9 @@ const generateTool = defineTool({
|
|
|
329
364
|
hooks.on("kubb:warn", async ({ message }) => {
|
|
330
365
|
await notify(NotifyTypes.WARN, message);
|
|
331
366
|
});
|
|
367
|
+
hooks.on("kubb:diagnostic", async ({ diagnostic }) => {
|
|
368
|
+
await notify(NotifyTypes.DIAGNOSTIC, diagnostic.message, Diagnostics.serialize(diagnostic));
|
|
369
|
+
});
|
|
332
370
|
hooks.on("kubb:plugin:start", async ({ plugin }) => {
|
|
333
371
|
await notify(NotifyTypes.PLUGIN_START, `Plugin starting: ${plugin.name}`);
|
|
334
372
|
});
|
|
@@ -385,18 +423,20 @@ const generateTool = defineTool({
|
|
|
385
423
|
await kubb.setup();
|
|
386
424
|
await notify(NotifyTypes.SETUP_END, "Kubb setup complete");
|
|
387
425
|
await notify(NotifyTypes.BUILD_START, "Starting build");
|
|
388
|
-
const { files,
|
|
426
|
+
const { files, diagnostics } = await kubb.safeBuild();
|
|
389
427
|
await notify(NotifyTypes.BUILD_END, `Build complete - Generated ${files.length} files`);
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
428
|
+
const problems = diagnostics.filter(isProblemDiagnostic);
|
|
429
|
+
const errors = problems.filter((diagnostic) => diagnostic.severity === "error");
|
|
430
|
+
if (errors.length > 0) {
|
|
431
|
+
await notify(NotifyTypes.BUILD_FAILED, `Build failed with ${errors.length} diagnostic(s)`);
|
|
432
|
+
const serialized = problems.map((diagnostic) => Diagnostics.serialize(diagnostic));
|
|
433
|
+
return tool.error(`Build failed:\n${formatDiagnostics(serialized)}\n\n\`\`\`json\n${JSON.stringify(serialized, null, 2)}\n\`\`\``);
|
|
394
434
|
}
|
|
395
435
|
await notify(NotifyTypes.BUILD_SUCCESS, `Build completed successfully - Generated ${files.length} files`);
|
|
396
436
|
return tool.text(`Build completed successfully!\n\nGenerated ${files.length} files\n\n${messages.join("\n")}`);
|
|
397
437
|
} catch (caughtError) {
|
|
398
|
-
const
|
|
399
|
-
return tool.error(`Build error
|
|
438
|
+
const serialized = Diagnostics.serialize(Diagnostics.from(caughtError));
|
|
439
|
+
return tool.error(`Build error:\n${formatDiagnostics([serialized])}\n\n\`\`\`json\n${JSON.stringify(serialized, null, 2)}\n\`\`\``);
|
|
400
440
|
}
|
|
401
441
|
});
|
|
402
442
|
//#endregion
|
|
@@ -578,7 +618,8 @@ const validateTool = defineTool({
|
|
|
578
618
|
await mod.adapterOas().validate(input, { throwOnError: true });
|
|
579
619
|
return tool.text(`Validation successful: ${input}`);
|
|
580
620
|
} catch (err) {
|
|
581
|
-
|
|
621
|
+
const serialized = Diagnostics.serialize(Diagnostics.from(err));
|
|
622
|
+
return tool.error(`Validation failed:\n${formatDiagnostics([serialized])}\n\n\`\`\`json\n${JSON.stringify(serialized, null, 2)}\n\`\`\``);
|
|
582
623
|
}
|
|
583
624
|
});
|
|
584
625
|
//#endregion
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["#emitter","NodeEventEmitter","#emitAll","process"],"sources":["../package.json","../../../internals/utils/src/errors.ts","../../../internals/utils/src/asyncEventEmitter.ts","../../../internals/utils/src/promise.ts","../src/schemas/generateSchema.ts","../src/types.ts","../src/constants.ts","../src/utils/loadUserConfig.ts","../src/utils/resolveCwd.ts","../src/utils/resolveUserConfig.ts","../src/tools/generate.ts","../../../internals/shared/src/constants.ts","../../../internals/shared/src/init.ts","../src/schemas/initSchema.ts","../src/tools/init.ts","../src/schemas/validateSchema.ts","../src/tools/validate.ts","../src/server.ts","../src/index.ts"],"sourcesContent":["","/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n *\n * @example\n * ```ts\n * throw new BuildError('Build failed', { errors: [err1, err2] })\n * ```\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new BuildError('Build failed', { cause: toError(err), errors: [] })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.\n *\n * @example\n * ```ts\n * const cause = toCause(buildError) // Error | undefined\n * ```\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport { toError } from './errors.ts'\n\n/**\n * A function that can be registered as an event listener, synchronous or async.\n */\ntype AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>\n\n/**\n * Typed `EventEmitter` that awaits all async listeners before resolving.\n * Wraps Node's `EventEmitter` with full TypeScript event-map inference.\n *\n * @example\n * ```ts\n * const emitter = new AsyncEventEmitter<{ build: [name: string] }>()\n * emitter.on('build', async (name) => { console.log(name) })\n * await emitter.emit('build', 'petstore') // all listeners awaited\n * ```\n */\nexport class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {\n /**\n * Maximum number of listeners per event before Node emits a memory-leak warning.\n * @default 10\n */\n constructor(maxListener = 10) {\n this.#emitter.setMaxListeners(maxListener)\n }\n\n #emitter = new NodeEventEmitter()\n\n /**\n * Emits `eventName` and awaits all registered listeners sequentially.\n * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.\n *\n * @example\n * ```ts\n * await emitter.emit('build', 'petstore')\n * ```\n */\n emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> | void {\n const listeners = this.#emitter.listeners(eventName) as Array<AsyncListener<TEvents[TEventName]>>\n\n if (listeners.length === 0) {\n return\n }\n\n return this.#emitAll(eventName, listeners, eventArgs)\n }\n\n async #emitAll<TEventName extends keyof TEvents & string>(\n eventName: TEventName,\n listeners: Array<AsyncListener<TEvents[TEventName]>>,\n eventArgs: TEvents[TEventName],\n ): Promise<void> {\n for (const listener of listeners) {\n try {\n await listener(...eventArgs)\n } catch (err) {\n let serializedArgs: string\n try {\n serializedArgs = JSON.stringify(eventArgs)\n } catch {\n serializedArgs = String(eventArgs)\n }\n throw new Error(`Error in async listener for \"${eventName}\" with eventArgs ${serializedArgs}`, { cause: toError(err) })\n }\n }\n }\n\n /**\n * Registers a persistent listener for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', async (name) => { console.log(name) })\n * ```\n */\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.on(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Registers a one-shot listener that removes itself after the first invocation.\n *\n * @example\n * ```ts\n * emitter.onOnce('build', async (name) => { console.log(name) })\n * ```\n */\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n const wrapper: AsyncListener<TEvents[TEventName]> = (...args) => {\n this.off(eventName, wrapper)\n return handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n /**\n * Removes a previously registered listener.\n *\n * @example\n * ```ts\n * emitter.off('build', handler)\n * ```\n */\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.off(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Returns the number of listeners registered for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', handler)\n * emitter.listenerCount('build') // 1\n * ```\n */\n listenerCount<TEventName extends keyof TEvents & string>(eventName: TEventName): number {\n return this.#emitter.listenerCount(eventName)\n }\n\n /**\n * Removes all listeners from every event channel.\n *\n * @example\n * ```ts\n * emitter.removeAll()\n * ```\n */\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","function* chunks<T>(arr: readonly T[], size: number): Generator<T[]> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: readonly T[] | AsyncIterable<T>,\n process: (batch: T[]) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: T[] = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/**\n * Runs `work`, passing `flush` as its periodic-flush callback, then calls\n * `flush` once more to drain any items that did not cross a flush boundary.\n *\n * @example\n * ```ts\n * await withDrain(\n * (flush) => processItems(items, { flush }),\n * () => writeRemainingFiles(),\n * )\n * ```\n */\nexport async function withDrain(work: (flush: () => Promise<void>) => Promise<void>, flush: () => Promise<void>): Promise<void> {\n await work(flush)\n await flush()\n}\n\n/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n\n/**\n * Returns a wrapper that caches the result of the first invocation and replays\n * it for every subsequent call, ignoring later arguments.\n *\n * Works for sync and async factories — for async, the cached value is the\n * promise itself, so concurrent callers share one in-flight execution and\n * cannot race each other.\n *\n * @example\n * ```ts\n * const loadDocument = once(async (path: string) => parse(await readFile(path)))\n * const a = loadDocument('./a.yaml') // parses\n * const b = loadDocument('./b.yaml') // returns the cached promise from the first call\n * ```\n */\nexport function once<TArgs extends unknown[], TReturn>(factory: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn {\n let cache: { value: TReturn } | undefined\n return (...args: TArgs): TReturn => {\n if (!cache) cache = { value: factory(...args) }\n return cache.value\n }\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: readonly T[]): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import * as v from 'valibot'\n\nexport const generateSchema = v.object({\n config: v.optional(\n v.pipe(v.string(), v.minLength(1), v.description('Path to kubb.config file (supports .ts, .js, .cjs). If not provided, will look for kubb.config.{ts,js,cjs} in current directory')),\n ),\n input: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Path to OpenAPI/Swagger spec file (overrides config)'))),\n output: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Output directory path (overrides config)'))),\n logLevel: v.optional(\n v.pipe(v.picklist(['silent', 'error', 'warn', 'info', 'verbose', 'debug']), v.description('Log level for build output')),\n 'info',\n ),\n})\n","export const NotifyTypes = {\n INFO: 'INFO',\n SUCCESS: 'SUCCESS',\n ERROR: 'ERROR',\n WARN: 'WARN',\n PLUGIN_START: 'PLUGIN_START',\n PLUGIN_END: 'PLUGIN_END',\n FILES_START: 'FILES_START',\n FILES_UPDATE: 'FILES_UPDATE',\n FILES_END: 'FILES_END',\n GENERATION_START: 'GENERATION_START',\n GENERATION_END: 'GENERATION_END',\n CONFIG_LOADED: 'CONFIG_LOADED',\n CONFIG_ERROR: 'CONFIG_ERROR',\n CONFIG_READY: 'CONFIG_READY',\n SETUP_START: 'SETUP_START',\n SETUP_END: 'SETUP_END',\n BUILD_START: 'BUILD_START',\n BUILD_END: 'BUILD_END',\n BUILD_FAILED: 'BUILD_FAILED',\n BUILD_SUCCESS: 'BUILD_SUCCESS',\n FATAL_ERROR: 'FATAL_ERROR',\n} as const\n","export const ALLOWED_CONFIG_EXTENSIONS = new Set(['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'])\n","import { existsSync } from 'node:fs'\nimport path from 'node:path'\nimport type { Config } from '@kubb/core'\nimport { createJiti } from 'jiti'\nimport { ALLOWED_CONFIG_EXTENSIONS } from '../constants.ts'\nimport { NotifyTypes } from '../types.ts'\n\ntype NotifyFunction = (type: string, message: string, data?: Record<string, unknown>) => Promise<void>\n\nconst jiti = createJiti(import.meta.url, {\n jsx: {\n runtime: 'automatic',\n importSource: '@kubb/renderer-jsx',\n },\n moduleCache: false,\n})\n\nconst loadedModules = new Map<string, unknown>()\n\nasync function loadModule(filePath: string): Promise<unknown> {\n const ext = path.extname(filePath)\n if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {\n throw new Error(`Invalid config file extension \"${ext}\". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`)\n }\n if (loadedModules.has(filePath)) {\n return loadedModules.get(filePath)\n }\n const mod = await jiti.import(filePath, { default: true })\n loadedModules.set(filePath, mod)\n return mod\n}\n\nexport async function loadUserConfig(configPath: string | undefined, { notify }: { notify: NotifyFunction }): Promise<{ userConfig: Config; cwd: string }> {\n if (configPath) {\n const ext = path.extname(configPath)\n if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {\n const msg = `Invalid config file extension \"${ext}\". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n const base = path.resolve(process.cwd())\n const resolvedConfigPath = path.resolve(base, configPath)\n const relative = path.relative(base, resolvedConfigPath)\n if (relative.startsWith('..') || path.isAbsolute(relative)) {\n const msg = 'Invalid config file path: must be within the current working directory'\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n const cwd = path.dirname(resolvedConfigPath)\n try {\n const userConfig = (await loadModule(resolvedConfigPath)) as Config\n await notify(NotifyTypes.CONFIG_LOADED, `Loaded config from ${resolvedConfigPath}`)\n return { userConfig, cwd }\n } catch (error) {\n const msg = `Failed to load config: ${error instanceof Error ? error.message : String(error)}`\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n }\n\n const cwd = process.cwd()\n const configFileNames = ['kubb.config.ts', 'kubb.config.mts', 'kubb.config.cts', 'kubb.config.js', 'kubb.config.cjs']\n\n for (const configFileName of configFileNames) {\n const configFilePath = path.resolve(process.cwd(), configFileName)\n if (!existsSync(configFilePath)) continue\n try {\n const userConfig = (await loadModule(configFilePath)) as Config\n await notify(NotifyTypes.CONFIG_LOADED, `Loaded ${configFileName} from current directory`)\n return { userConfig, cwd }\n } catch (err) {\n await notify(NotifyTypes.CONFIG_ERROR, `Failed to load ${configFileName}: ${err instanceof Error ? err.message : String(err)}`)\n }\n }\n\n await notify(NotifyTypes.CONFIG_ERROR, 'No config file found')\n throw new Error(`No config file found. Please provide a config path or create one of: ${configFileNames.join(', ')}`)\n}\n","import path from 'node:path'\nimport type { Config } from '@kubb/core'\n\n/**\n * Determine the root directory based on userConfig.root and resolvedConfigDir\n * 1. If userConfig.root exists and is absolute, use it as-is\n * 2. If userConfig.root exists and is relative, resolve it relative to config directory\n * 3. Otherwise, use the config directory as root\n */\nexport function resolveCwd(userConfig: Config, cwd: string): string {\n if (userConfig.root) {\n if (path.isAbsolute(userConfig.root)) {\n return userConfig.root\n }\n\n return path.resolve(cwd, userConfig.root)\n }\n\n return cwd\n}\n","import { isPromise } from '@internals/utils'\nimport type { CLIOptions, Config, PossibleConfig } from '@kubb/core'\n\nexport type ResolveUserConfigOptions = {\n configPath?: string\n logLevel?: string\n}\n\nexport async function resolveUserConfig(config: PossibleConfig<CLIOptions>, options: ResolveUserConfigOptions): Promise<Config> {\n const result = typeof config === 'function' ? config({ logLevel: options.logLevel as CLIOptions['logLevel'], config: options.configPath }) : config\n const resolved = isPromise(result) ? await result : result\n return (Array.isArray(resolved) ? resolved[0] : resolved) as Config\n}\n","import { AsyncEventEmitter, toError } from '@internals/utils'\nimport { type Config, createKubb, type KubbHooks } from '@kubb/core'\nimport { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport type * as v from 'valibot'\nimport { generateSchema } from '../schemas/generateSchema.ts'\nimport { NotifyTypes } from '../types.ts'\nimport { loadUserConfig } from '../utils/loadUserConfig.ts'\nimport { resolveCwd } from '../utils/resolveCwd.ts'\nimport { resolveUserConfig } from '../utils/resolveUserConfig.ts'\n\nexport const generateTool = defineTool(\n {\n name: 'generate',\n description: 'Generate OpenAPI spec helpers using Kubb configuration',\n schema: generateSchema,\n },\n async function generate(schema: v.InferInput<typeof generateSchema>) {\n const { config: configPath, input, output, logLevel } = schema\n\n try {\n const hooks = new AsyncEventEmitter<KubbHooks>()\n const messages: Array<string> = []\n\n const notify = async (type: string, message: string, _data?: Record<string, unknown>) => {\n messages.push(`${type}: ${message}`)\n }\n\n hooks.on('kubb:info', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.INFO, message)\n })\n\n hooks.on('kubb:success', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.SUCCESS, message)\n })\n\n hooks.on('kubb:error', async ({ error }: { error: Error }) => {\n await notify(NotifyTypes.ERROR, error.message)\n })\n\n hooks.on('kubb:warn', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.WARN, message)\n })\n\n hooks.on('kubb:plugin:start', async ({ plugin }) => {\n await notify(NotifyTypes.PLUGIN_START, `Plugin starting: ${plugin.name}`)\n })\n\n hooks.on('kubb:plugin:end', async ({ plugin, duration }) => {\n await notify(NotifyTypes.PLUGIN_END, `Plugin finished: ${plugin.name}`, { duration })\n })\n\n hooks.on('kubb:files:processing:start', async () => {\n await notify(NotifyTypes.FILES_START, 'Starting file processing')\n })\n\n hooks.on('kubb:files:processing:update', async ({ files }: { files: Array<{ file: { name: string } }> }) => {\n await notify(NotifyTypes.FILES_UPDATE, `Processing ${files.length} files`)\n })\n\n hooks.on('kubb:files:processing:end', async () => {\n await notify(NotifyTypes.FILES_END, 'File processing complete')\n })\n\n hooks.on('kubb:generation:start', async () => {\n await notify(NotifyTypes.GENERATION_START, 'Generation started')\n })\n\n hooks.on('kubb:generation:end', async () => {\n await notify(NotifyTypes.GENERATION_END, 'Generation ended')\n })\n\n let userConfig: Config\n let cwd: string\n\n try {\n const configResult = await loadUserConfig(configPath, { notify })\n userConfig = configResult.userConfig\n cwd = configResult.cwd\n\n if (Array.isArray(userConfig)) {\n throw new Error('Array type in kubb.config.ts is not supported in this tool. Please provide a single configuration object.')\n }\n\n userConfig = await resolveUserConfig(userConfig, {\n configPath,\n logLevel,\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error)\n await notify(NotifyTypes.CONFIG_ERROR, errorMessage)\n return tool.error(errorMessage)\n }\n\n const inputPath = input ?? (userConfig.input && 'path' in userConfig.input ? userConfig.input.path : undefined)\n\n const config: Config = {\n ...userConfig,\n root: resolveCwd(userConfig, cwd),\n input: inputPath\n ? {\n ...userConfig.input,\n path: inputPath,\n }\n : userConfig.input,\n output: output\n ? {\n ...userConfig.output,\n path: output,\n }\n : userConfig.output,\n }\n\n await notify(NotifyTypes.CONFIG_READY, 'Configuration ready')\n await notify(NotifyTypes.SETUP_START, 'Setting up Kubb')\n\n const kubb = createKubb(config, { hooks })\n await kubb.setup()\n await notify(NotifyTypes.SETUP_END, 'Kubb setup complete')\n\n await notify(NotifyTypes.BUILD_START, 'Starting build')\n const { files, failedPlugins, error } = await kubb.safeBuild()\n await notify(NotifyTypes.BUILD_END, `Build complete - Generated ${files.length} files`)\n\n if (error || failedPlugins.size > 0) {\n const allErrors: Array<Error> = [\n error,\n ...Array.from(failedPlugins)\n .filter((it) => it.error)\n .map((it) => it.error),\n ].filter(Boolean)\n\n await notify(NotifyTypes.BUILD_FAILED, `Build failed with ${allErrors.length} error(s)`)\n\n return tool.error(`Build failed:\\n${allErrors.map((err) => err.message).join('\\n')}\\n\\n${messages.join('\\n')}`)\n }\n\n await notify(NotifyTypes.BUILD_SUCCESS, `Build completed successfully - Generated ${files.length} files`)\n\n return tool.text(`Build completed successfully!\\n\\nGenerated ${files.length} files\\n\\n${messages.join('\\n')}`)\n } catch (caughtError) {\n const error = toError(caughtError)\n return tool.error(`Build error: ${error.message}\\n${error.stack ?? ''}`)\n }\n },\n)\n","import type { PluginOption } from './types.ts'\n\nexport const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const\n\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['plugin-ts'],\n} as const\n\nexport const availablePlugins: PluginOption[] = [\n {\n value: 'plugin-ts',\n label: 'TypeScript',\n hint: 'Recommended',\n packageName: '@kubb/plugin-ts',\n importName: 'pluginTs',\n category: 'types',\n },\n {\n value: 'plugin-client',\n label: 'Client (Fetch/Axios)',\n packageName: '@kubb/plugin-client',\n importName: 'pluginClient',\n category: 'client',\n },\n {\n value: 'plugin-react-query',\n label: 'React Query / TanStack Query',\n packageName: '@kubb/plugin-react-query',\n importName: 'pluginReactQuery',\n category: 'framework',\n },\n {\n value: 'plugin-vue-query',\n label: 'Vue Query',\n packageName: '@kubb/plugin-vue-query',\n importName: 'pluginVueQuery',\n category: 'framework',\n },\n {\n value: 'plugin-zod',\n label: 'Zod Schemas',\n packageName: '@kubb/plugin-zod',\n importName: 'pluginZod',\n category: 'validation',\n },\n {\n value: 'plugin-faker',\n label: 'Faker.js Mocks',\n packageName: '@kubb/plugin-faker',\n importName: 'pluginFaker',\n category: 'mocks',\n },\n {\n value: 'plugin-msw',\n label: 'MSW Handlers',\n packageName: '@kubb/plugin-msw',\n importName: 'pluginMsw',\n category: 'mocks',\n },\n {\n value: 'plugin-cypress',\n label: 'Cypress Tests',\n packageName: '@kubb/plugin-cypress',\n importName: 'pluginCypress',\n category: 'testing',\n },\n {\n value: 'plugin-mcp',\n label: 'MCP Server (AI / Model Context Protocol)',\n packageName: '@kubb/plugin-mcp',\n importName: 'pluginMcp',\n category: 'ai',\n },\n {\n value: 'plugin-redoc',\n label: 'ReDoc Documentation',\n packageName: '@kubb/plugin-redoc',\n importName: 'pluginRedoc',\n category: 'documentation',\n },\n]\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","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 * as v from 'valibot'\n\nexport const initSchema = v.object({\n input: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Path to OpenAPI spec (default: ./openapi.yaml)'))),\n output: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Output directory (default: ./src/gen)'))),\n plugins: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Comma-separated list of plugins: plugin-ts,plugin-zod,...'))),\n})\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { availablePlugins, generateConfigFile, KUBB_CONFIG_FILENAME, type PluginOption } from '@internals/shared'\nimport { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport { initSchema } from '../schemas/initSchema.ts'\n\nexport function resolvePlugins(pluginsFlag: string | undefined): Array<PluginOption> {\n if (!pluginsFlag) {\n return []\n }\n const requested = pluginsFlag\n .split(',')\n .map((v) => v.trim())\n .filter(Boolean)\n return availablePlugins.filter((p) => requested.includes(p.value))\n}\n\nexport const initTool = defineTool(\n {\n name: 'init',\n description: 'Scaffold a kubb.config.ts in the current directory (non-interactive). Does not install packages.',\n schema: initSchema,\n },\n async ({ input = './openapi.yaml', output = './src/gen', plugins }) => {\n const selected = resolvePlugins(plugins)\n const content = generateConfigFile({ selectedPlugins: selected, inputPath: input, outputPath: output })\n const dest = path.join(process.cwd(), KUBB_CONFIG_FILENAME)\n if (fs.existsSync(dest)) {\n return tool.error(`${KUBB_CONFIG_FILENAME} already exists at ${dest}. Delete it first before running init again.`)\n }\n fs.writeFileSync(dest, content, 'utf-8')\n const packageList = ['kubb', ...selected.map((p) => p.packageName)].join(' ')\n return tool.text(`Created kubb.config.ts\\n\\nInstall packages:\\n npm install ${packageList}\\n\\nThen run:\\n npx kubb generate`)\n },\n)\n","import * as v from 'valibot'\n\nexport const validateSchema = v.object({\n input: v.pipe(v.string(), v.minLength(1), v.description('Path or URL to the OpenAPI/Swagger specification')),\n})\n","import { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport { validateSchema } from '../schemas/validateSchema.ts'\n\nexport const validateTool = defineTool(\n {\n name: 'validate',\n description: 'Validate an OpenAPI/Swagger specification file or URL',\n schema: validateSchema,\n },\n async ({ input }) => {\n let mod: typeof import('@kubb/adapter-oas')\n try {\n mod = await import('@kubb/adapter-oas')\n } catch {\n return tool.error('The validate tool requires @kubb/adapter-oas.\\nInstall: npm install @kubb/adapter-oas')\n }\n try {\n await mod.adapterOas().validate(input, { throwOnError: true })\n return tool.text(`Validation successful: ${input}`)\n } catch (err) {\n return tool.error(`Validation failed:\\n${err instanceof Error ? err.message : String(err)}`)\n }\n },\n)\n","import http from 'node:http'\nimport { createRequestListener } from '@remix-run/node-fetch-server'\nimport { ValibotJsonSchemaAdapter } from '@tmcp/adapter-valibot'\nimport { HttpTransport } from '@tmcp/transport-http'\nimport { StdioTransport } from '@tmcp/transport-stdio'\nimport { McpServer } from 'tmcp'\nimport { version } from '../package.json'\nimport { generateTool } from './tools/generate.ts'\nimport { initTool } from './tools/init.ts'\nimport { validateTool } from './tools/validate.ts'\n\nexport type ServerOptions = {\n port?: number\n host?: string\n}\n\nexport function createMcpServer() {\n const server = new McpServer({ name: 'Kubb', version }, { adapter: new ValibotJsonSchemaAdapter(), capabilities: { tools: {} } })\n server.tools([generateTool, validateTool, initTool])\n return server\n}\n\nexport async function startServer({ port, host = 'localhost' }: ServerOptions = {}) {\n const server = createMcpServer()\n\n if (port === undefined) {\n new StdioTransport(server).listen()\n return\n }\n\n const transport = new HttpTransport(server, { path: '/mcp' })\n const httpServer = http.createServer(\n createRequestListener(async (request) => {\n const response = await transport.respond(request)\n return response ?? new Response('Not Found', { status: 404 })\n }),\n )\n httpServer.listen(port, host, () => {\n console.log(`Kubb MCP server on http://${host}:${port}`)\n })\n\n const closeServer = () => httpServer.close()\n process.once('SIGINT', closeServer)\n process.once('SIGTERM', closeServer)\n httpServer.once('close', () => {\n process.off('SIGINT', closeServer)\n process.off('SIGTERM', closeServer)\n })\n}\n","import { startServer } from './server.ts'\n\nexport { createMcpServer } from './server.ts'\nexport type { ServerOptions } from './server.ts'\n\nexport async function run(_argv?: Array<string>, options?: import('./server.ts').ServerOptions): Promise<void> {\n await startServer(options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC8BA,SAAgB,QAAQ,OAAuB;CAC7C,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAA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;CAC9D,CAAC,CACH;CACA,WAAW,OAAO,MAAM,YAAY;EAClC,QAAQ,IAAI,6BAA6B,KAAK,GAAG,MAAM;CACzD,CAAC;CAED,MAAM,oBAAoB,WAAW,MAAM;CAC3C,QAAQ,KAAK,UAAU,WAAW;CAClC,QAAQ,KAAK,WAAW,WAAW;CACnC,WAAW,KAAK,eAAe;EAC7B,QAAQ,IAAI,UAAU,WAAW;EACjC,QAAQ,IAAI,WAAW,WAAW;CACpC,CAAC;AACH;;;AC3CA,eAAsB,IAAI,OAAuB,SAA8D;CAC7G,MAAM,YAAY,OAAO;AAC3B"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["#emitter","NodeEventEmitter","#emitAll","process"],"sources":["../package.json","../../../internals/utils/src/errors.ts","../../../internals/utils/src/asyncEventEmitter.ts","../../../internals/utils/src/promise.ts","../src/schemas/generateSchema.ts","../src/utils/formatDiagnostics.ts","../src/types.ts","../src/constants.ts","../src/utils/loadUserConfig.ts","../src/utils/resolveCwd.ts","../src/utils/resolveUserConfig.ts","../src/tools/generate.ts","../../../internals/shared/src/constants.ts","../../../internals/shared/src/init.ts","../src/schemas/initSchema.ts","../src/tools/init.ts","../src/schemas/validateSchema.ts","../src/tools/validate.ts","../src/server.ts","../src/index.ts"],"sourcesContent":["","/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n *\n * @example\n * ```ts\n * throw new BuildError('Build failed', { errors: [err1, err2] })\n * ```\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new BuildError('Build failed', { cause: toError(err), errors: [] })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.\n *\n * @example\n * ```ts\n * const cause = toCause(buildError) // Error | undefined\n * ```\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport { toError } from './errors.ts'\n\n/**\n * A function that can be registered as an event listener, synchronous or async.\n */\ntype AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>\n\n/**\n * Typed `EventEmitter` that awaits all async listeners before resolving.\n * Wraps Node's `EventEmitter` with full TypeScript event-map inference.\n *\n * @example\n * ```ts\n * const emitter = new AsyncEventEmitter<{ build: [name: string] }>()\n * emitter.on('build', async (name) => { console.log(name) })\n * await emitter.emit('build', 'petstore') // all listeners awaited\n * ```\n */\nexport class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {\n /**\n * Maximum number of listeners per event before Node emits a memory-leak warning.\n * @default 10\n */\n constructor(maxListener = 10) {\n this.#emitter.setMaxListeners(maxListener)\n }\n\n #emitter = new NodeEventEmitter()\n\n /**\n * Emits `eventName` and awaits all registered listeners sequentially.\n * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.\n *\n * @example\n * ```ts\n * await emitter.emit('build', 'petstore')\n * ```\n */\n emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> | void {\n const listeners = this.#emitter.listeners(eventName) as Array<AsyncListener<TEvents[TEventName]>>\n\n if (listeners.length === 0) {\n return\n }\n\n return this.#emitAll(eventName, listeners, eventArgs)\n }\n\n async #emitAll<TEventName extends keyof TEvents & string>(\n eventName: TEventName,\n listeners: Array<AsyncListener<TEvents[TEventName]>>,\n eventArgs: TEvents[TEventName],\n ): Promise<void> {\n for (const listener of listeners) {\n try {\n await listener(...eventArgs)\n } catch (err) {\n let serializedArgs: string\n try {\n serializedArgs = JSON.stringify(eventArgs)\n } catch {\n serializedArgs = String(eventArgs)\n }\n throw new Error(`Error in async listener for \"${eventName}\" with eventArgs ${serializedArgs}`, { cause: toError(err) })\n }\n }\n }\n\n /**\n * Registers a persistent listener for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', async (name) => { console.log(name) })\n * ```\n */\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.on(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Registers a one-shot listener that removes itself after the first invocation.\n *\n * @example\n * ```ts\n * emitter.onOnce('build', async (name) => { console.log(name) })\n * ```\n */\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n const wrapper: AsyncListener<TEvents[TEventName]> = (...args) => {\n this.off(eventName, wrapper)\n return handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n /**\n * Removes a previously registered listener.\n *\n * @example\n * ```ts\n * emitter.off('build', handler)\n * ```\n */\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.off(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Returns the number of listeners registered for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', handler)\n * emitter.listenerCount('build') // 1\n * ```\n */\n listenerCount<TEventName extends keyof TEvents & string>(eventName: TEventName): number {\n return this.#emitter.listenerCount(eventName)\n }\n\n /**\n * Raises or lowers the per-event listener ceiling before Node warns about a memory leak.\n * Set this above the expected listener count when many listeners attach by design.\n *\n * @example\n * ```ts\n * emitter.setMaxListeners(40)\n * ```\n */\n setMaxListeners(max: number): void {\n this.#emitter.setMaxListeners(max)\n }\n\n /**\n * Returns the current per-event listener ceiling.\n */\n getMaxListeners(): number {\n return this.#emitter.getMaxListeners()\n }\n\n /**\n * Removes all listeners from every event channel.\n *\n * @example\n * ```ts\n * emitter.removeAll()\n * ```\n */\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","function* chunks<T>(arr: readonly T[], size: number): Generator<T[]> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: readonly T[] | AsyncIterable<T>,\n process: (batch: T[]) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: T[] = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/**\n * Runs `work`, passing `flush` as its periodic-flush callback, then calls\n * `flush` once more to drain any items that did not cross a flush boundary.\n *\n * @example\n * ```ts\n * await withDrain(\n * (flush) => processItems(items, { flush }),\n * () => writeRemainingFiles(),\n * )\n * ```\n */\nexport async function withDrain(work: (flush: () => Promise<void>) => Promise<void>, flush: () => Promise<void>): Promise<void> {\n await work(flush)\n await flush()\n}\n\n/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n\n/**\n * Returns a wrapper that caches the result of the first invocation and replays\n * it for every subsequent call, ignoring later arguments.\n *\n * Works for sync and async factories — for async, the cached value is the\n * promise itself, so concurrent callers share one in-flight execution and\n * cannot race each other.\n *\n * @example\n * ```ts\n * const loadDocument = once(async (path: string) => parse(await readFile(path)))\n * const a = loadDocument('./a.yaml') // parses\n * const b = loadDocument('./b.yaml') // returns the cached promise from the first call\n * ```\n */\nexport function once<TArgs extends unknown[], TReturn>(factory: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn {\n let cache: { value: TReturn } | undefined\n return (...args: TArgs): TReturn => {\n if (!cache) cache = { value: factory(...args) }\n return cache.value\n }\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: readonly T[]): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import * as v from 'valibot'\n\nexport const generateSchema = v.object({\n config: v.optional(\n v.pipe(v.string(), v.minLength(1), v.description('Path to kubb.config file (supports .ts, .js, .cjs). If not provided, will look for kubb.config.{ts,js,cjs} in current directory')),\n ),\n input: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Path to OpenAPI/Swagger spec file (overrides config)'))),\n output: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Output directory path (overrides config)'))),\n logLevel: v.optional(\n v.pipe(v.picklist(['silent', 'info', 'verbose']), v.description('Log level for build output')),\n 'info',\n ),\n})\n","import type { SerializedDiagnostic } from '@kubb/core'\n\n/**\n * Renders serialized diagnostics as a plain-text block for an AI assistant. Each entry\n * keeps the stable `code`, the source pointer, the suggested fix, and the docs link, so\n * the agent can act on the problem rather than parsing a bare message. No ANSI styling,\n * unlike the CLI renderer.\n */\nexport function formatDiagnostics(diagnostics: ReadonlyArray<SerializedDiagnostic>): string {\n return diagnostics.map((diagnostic) => formatDiagnostic(diagnostic)).join('\\n\\n')\n}\n\nfunction formatDiagnostic(diagnostic: SerializedDiagnostic): string {\n const { code, severity, message, location, help, plugin, docsUrl } = diagnostic\n const rule = plugin ? `${plugin}(${code})` : code\n const lines = [`${severity} ${rule}: ${message}`]\n\n if (location && 'pointer' in location) {\n lines.push(` at ${location.pointer}`)\n }\n if (help) {\n lines.push(` help: ${help}`)\n }\n if (docsUrl) {\n lines.push(` docs: ${docsUrl}`)\n }\n\n return lines.join('\\n')\n}\n","export const NotifyTypes = {\n INFO: 'INFO',\n SUCCESS: 'SUCCESS',\n ERROR: 'ERROR',\n WARN: 'WARN',\n DIAGNOSTIC: 'DIAGNOSTIC',\n PLUGIN_START: 'PLUGIN_START',\n PLUGIN_END: 'PLUGIN_END',\n FILES_START: 'FILES_START',\n FILES_UPDATE: 'FILES_UPDATE',\n FILES_END: 'FILES_END',\n GENERATION_START: 'GENERATION_START',\n GENERATION_END: 'GENERATION_END',\n CONFIG_LOADED: 'CONFIG_LOADED',\n CONFIG_ERROR: 'CONFIG_ERROR',\n CONFIG_READY: 'CONFIG_READY',\n SETUP_START: 'SETUP_START',\n SETUP_END: 'SETUP_END',\n BUILD_START: 'BUILD_START',\n BUILD_END: 'BUILD_END',\n BUILD_FAILED: 'BUILD_FAILED',\n BUILD_SUCCESS: 'BUILD_SUCCESS',\n FATAL_ERROR: 'FATAL_ERROR',\n} as const\n","export const ALLOWED_CONFIG_EXTENSIONS = new Set(['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'])\n","import { existsSync } from 'node:fs'\nimport path from 'node:path'\nimport type { Config } from '@kubb/core'\nimport { createJiti } from 'jiti'\nimport { ALLOWED_CONFIG_EXTENSIONS } from '../constants.ts'\nimport { NotifyTypes } from '../types.ts'\n\ntype NotifyFunction = (type: string, message: string, data?: Record<string, unknown>) => Promise<void>\n\nconst jiti = createJiti(import.meta.url, {\n jsx: {\n runtime: 'automatic',\n importSource: '@kubb/renderer-jsx',\n },\n moduleCache: false,\n})\n\nconst loadedModules = new Map<string, unknown>()\n\nasync function loadModule(filePath: string): Promise<unknown> {\n const ext = path.extname(filePath)\n if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {\n throw new Error(`Invalid config file extension \"${ext}\". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`)\n }\n if (loadedModules.has(filePath)) {\n return loadedModules.get(filePath)\n }\n const mod = await jiti.import(filePath, { default: true })\n loadedModules.set(filePath, mod)\n return mod\n}\n\nexport async function loadUserConfig(configPath: string | undefined, { notify }: { notify: NotifyFunction }): Promise<{ userConfig: Config; cwd: string }> {\n if (configPath) {\n const ext = path.extname(configPath)\n if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {\n const msg = `Invalid config file extension \"${ext}\". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n const base = path.resolve(process.cwd())\n const resolvedConfigPath = path.resolve(base, configPath)\n const relative = path.relative(base, resolvedConfigPath)\n if (relative.startsWith('..') || path.isAbsolute(relative)) {\n const msg = 'Invalid config file path: must be within the current working directory'\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n const cwd = path.dirname(resolvedConfigPath)\n try {\n const userConfig = (await loadModule(resolvedConfigPath)) as Config\n await notify(NotifyTypes.CONFIG_LOADED, `Loaded config from ${resolvedConfigPath}`)\n return { userConfig, cwd }\n } catch (error) {\n const msg = `Failed to load config: ${error instanceof Error ? error.message : String(error)}`\n await notify(NotifyTypes.CONFIG_ERROR, msg)\n throw new Error(msg)\n }\n }\n\n const cwd = process.cwd()\n const configFileNames = ['kubb.config.ts', 'kubb.config.mts', 'kubb.config.cts', 'kubb.config.js', 'kubb.config.cjs']\n\n for (const configFileName of configFileNames) {\n const configFilePath = path.resolve(process.cwd(), configFileName)\n if (!existsSync(configFilePath)) continue\n try {\n const userConfig = (await loadModule(configFilePath)) as Config\n await notify(NotifyTypes.CONFIG_LOADED, `Loaded ${configFileName} from current directory`)\n return { userConfig, cwd }\n } catch (err) {\n await notify(NotifyTypes.CONFIG_ERROR, `Failed to load ${configFileName}: ${err instanceof Error ? err.message : String(err)}`)\n }\n }\n\n await notify(NotifyTypes.CONFIG_ERROR, 'No config file found')\n throw new Error(`No config file found. Please provide a config path or create one of: ${configFileNames.join(', ')}`)\n}\n","import path from 'node:path'\nimport type { Config } from '@kubb/core'\n\n/**\n * Determine the root directory based on userConfig.root and resolvedConfigDir\n * 1. If userConfig.root exists and is absolute, use it as-is\n * 2. If userConfig.root exists and is relative, resolve it relative to config directory\n * 3. Otherwise, use the config directory as root\n */\nexport function resolveCwd(userConfig: Config, cwd: string): string {\n if (userConfig.root) {\n if (path.isAbsolute(userConfig.root)) {\n return userConfig.root\n }\n\n return path.resolve(cwd, userConfig.root)\n }\n\n return cwd\n}\n","import { isPromise } from '@internals/utils'\nimport type { CLIOptions, Config, PossibleConfig } from '@kubb/core'\n\nexport type ResolveUserConfigOptions = {\n configPath?: string\n logLevel?: string\n}\n\nexport async function resolveUserConfig(config: PossibleConfig<CLIOptions>, options: ResolveUserConfigOptions): Promise<Config> {\n const result = typeof config === 'function' ? config({ logLevel: options.logLevel as CLIOptions['logLevel'], config: options.configPath }) : config\n const resolved = isPromise(result) ? await result : result\n return (Array.isArray(resolved) ? resolved[0] : resolved) as Config\n}\n","import { AsyncEventEmitter } from '@internals/utils'\nimport { type Config, createKubb, type Diagnostic, Diagnostics, isProblemDiagnostic, type KubbHooks } from '@kubb/core'\nimport { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport type * as v from 'valibot'\nimport { generateSchema } from '../schemas/generateSchema.ts'\nimport { formatDiagnostics } from '../utils/formatDiagnostics.ts'\nimport { NotifyTypes } from '../types.ts'\nimport { loadUserConfig } from '../utils/loadUserConfig.ts'\nimport { resolveCwd } from '../utils/resolveCwd.ts'\nimport { resolveUserConfig } from '../utils/resolveUserConfig.ts'\n\nexport const generateTool = defineTool(\n {\n name: 'generate',\n description: 'Generate OpenAPI spec helpers using Kubb configuration',\n schema: generateSchema,\n },\n async function generate(schema: v.InferInput<typeof generateSchema>) {\n const { config: configPath, input, output, logLevel } = schema\n\n try {\n const hooks = new AsyncEventEmitter<KubbHooks>()\n const messages: Array<string> = []\n\n const notify = async (type: string, message: string, data?: Record<string, unknown>) => {\n messages.push(data ? `${type}: ${message} ${JSON.stringify(data)}` : `${type}: ${message}`)\n }\n\n hooks.on('kubb:info', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.INFO, message)\n })\n\n hooks.on('kubb:success', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.SUCCESS, message)\n })\n\n hooks.on('kubb:error', async ({ error }: { error: Error }) => {\n await notify(NotifyTypes.ERROR, error.message)\n })\n\n hooks.on('kubb:warn', async ({ message }: { message: string }) => {\n await notify(NotifyTypes.WARN, message)\n })\n\n hooks.on('kubb:diagnostic', async ({ diagnostic }: { diagnostic: Diagnostic }) => {\n await notify(NotifyTypes.DIAGNOSTIC, diagnostic.message, Diagnostics.serialize(diagnostic))\n })\n\n hooks.on('kubb:plugin:start', async ({ plugin }) => {\n await notify(NotifyTypes.PLUGIN_START, `Plugin starting: ${plugin.name}`)\n })\n\n hooks.on('kubb:plugin:end', async ({ plugin, duration }) => {\n await notify(NotifyTypes.PLUGIN_END, `Plugin finished: ${plugin.name}`, { duration })\n })\n\n hooks.on('kubb:files:processing:start', async () => {\n await notify(NotifyTypes.FILES_START, 'Starting file processing')\n })\n\n hooks.on('kubb:files:processing:update', async ({ files }: { files: Array<{ file: { name: string } }> }) => {\n await notify(NotifyTypes.FILES_UPDATE, `Processing ${files.length} files`)\n })\n\n hooks.on('kubb:files:processing:end', async () => {\n await notify(NotifyTypes.FILES_END, 'File processing complete')\n })\n\n hooks.on('kubb:generation:start', async () => {\n await notify(NotifyTypes.GENERATION_START, 'Generation started')\n })\n\n hooks.on('kubb:generation:end', async () => {\n await notify(NotifyTypes.GENERATION_END, 'Generation ended')\n })\n\n let userConfig: Config\n let cwd: string\n\n try {\n const configResult = await loadUserConfig(configPath, { notify })\n userConfig = configResult.userConfig\n cwd = configResult.cwd\n\n if (Array.isArray(userConfig)) {\n throw new Error('Array type in kubb.config.ts is not supported in this tool. Please provide a single configuration object.')\n }\n\n userConfig = await resolveUserConfig(userConfig, {\n configPath,\n logLevel,\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error)\n await notify(NotifyTypes.CONFIG_ERROR, errorMessage)\n return tool.error(errorMessage)\n }\n\n const inputPath = input ?? (userConfig.input && 'path' in userConfig.input ? userConfig.input.path : undefined)\n\n const config: Config = {\n ...userConfig,\n root: resolveCwd(userConfig, cwd),\n input: inputPath\n ? {\n ...userConfig.input,\n path: inputPath,\n }\n : userConfig.input,\n output: output\n ? {\n ...userConfig.output,\n path: output,\n }\n : userConfig.output,\n }\n\n await notify(NotifyTypes.CONFIG_READY, 'Configuration ready')\n await notify(NotifyTypes.SETUP_START, 'Setting up Kubb')\n\n const kubb = createKubb(config, { hooks })\n await kubb.setup()\n await notify(NotifyTypes.SETUP_END, 'Kubb setup complete')\n\n await notify(NotifyTypes.BUILD_START, 'Starting build')\n const { files, diagnostics } = await kubb.safeBuild()\n await notify(NotifyTypes.BUILD_END, `Build complete - Generated ${files.length} files`)\n\n const problems = diagnostics.filter(isProblemDiagnostic)\n const errors = problems.filter((diagnostic) => diagnostic.severity === 'error')\n if (errors.length > 0) {\n await notify(NotifyTypes.BUILD_FAILED, `Build failed with ${errors.length} diagnostic(s)`)\n\n const serialized = problems.map((diagnostic) => Diagnostics.serialize(diagnostic))\n return tool.error(`Build failed:\\n${formatDiagnostics(serialized)}\\n\\n\\`\\`\\`json\\n${JSON.stringify(serialized, null, 2)}\\n\\`\\`\\``)\n }\n\n await notify(NotifyTypes.BUILD_SUCCESS, `Build completed successfully - Generated ${files.length} files`)\n\n return tool.text(`Build completed successfully!\\n\\nGenerated ${files.length} files\\n\\n${messages.join('\\n')}`)\n } catch (caughtError) {\n const serialized = Diagnostics.serialize(Diagnostics.from(caughtError))\n return tool.error(`Build error:\\n${formatDiagnostics([serialized])}\\n\\n\\`\\`\\`json\\n${JSON.stringify(serialized, null, 2)}\\n\\`\\`\\``)\n }\n },\n)\n","import type { PluginOption } from './types.ts'\n\nexport const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const\n\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['plugin-ts'],\n} as const\n\nexport const availablePlugins: PluginOption[] = [\n {\n value: 'plugin-ts',\n label: 'TypeScript',\n hint: 'Recommended',\n packageName: '@kubb/plugin-ts',\n importName: 'pluginTs',\n category: 'types',\n },\n {\n value: 'plugin-client',\n label: 'Client (Fetch/Axios)',\n packageName: '@kubb/plugin-client',\n importName: 'pluginClient',\n category: 'client',\n },\n {\n value: 'plugin-react-query',\n label: 'React Query / TanStack Query',\n packageName: '@kubb/plugin-react-query',\n importName: 'pluginReactQuery',\n category: 'framework',\n },\n {\n value: 'plugin-vue-query',\n label: 'Vue Query',\n packageName: '@kubb/plugin-vue-query',\n importName: 'pluginVueQuery',\n category: 'framework',\n },\n {\n value: 'plugin-zod',\n label: 'Zod Schemas',\n packageName: '@kubb/plugin-zod',\n importName: 'pluginZod',\n category: 'validation',\n },\n {\n value: 'plugin-faker',\n label: 'Faker.js Mocks',\n packageName: '@kubb/plugin-faker',\n importName: 'pluginFaker',\n category: 'mocks',\n },\n {\n value: 'plugin-msw',\n label: 'MSW Handlers',\n packageName: '@kubb/plugin-msw',\n importName: 'pluginMsw',\n category: 'mocks',\n },\n {\n value: 'plugin-cypress',\n label: 'Cypress Tests',\n packageName: '@kubb/plugin-cypress',\n importName: 'pluginCypress',\n category: 'testing',\n },\n {\n value: 'plugin-mcp',\n label: 'MCP Server (AI / Model Context Protocol)',\n packageName: '@kubb/plugin-mcp',\n importName: 'pluginMcp',\n category: 'ai',\n },\n {\n value: 'plugin-redoc',\n label: 'ReDoc Documentation',\n packageName: '@kubb/plugin-redoc',\n importName: 'pluginRedoc',\n category: 'documentation',\n },\n]\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","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 * as v from 'valibot'\n\nexport const initSchema = v.object({\n input: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Path to OpenAPI spec (default: ./openapi.yaml)'))),\n output: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Output directory (default: ./src/gen)'))),\n plugins: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Comma-separated list of plugins: plugin-ts,plugin-zod,...'))),\n})\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { availablePlugins, generateConfigFile, KUBB_CONFIG_FILENAME, type PluginOption } from '@internals/shared'\nimport { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport { initSchema } from '../schemas/initSchema.ts'\n\nexport function resolvePlugins(pluginsFlag: string | undefined): Array<PluginOption> {\n if (!pluginsFlag) {\n return []\n }\n const requested = pluginsFlag\n .split(',')\n .map((v) => v.trim())\n .filter(Boolean)\n return availablePlugins.filter((p) => requested.includes(p.value))\n}\n\nexport const initTool = defineTool(\n {\n name: 'init',\n description: 'Scaffold a kubb.config.ts in the current directory (non-interactive). Does not install packages.',\n schema: initSchema,\n },\n async ({ input = './openapi.yaml', output = './src/gen', plugins }) => {\n const selected = resolvePlugins(plugins)\n const content = generateConfigFile({ selectedPlugins: selected, inputPath: input, outputPath: output })\n const dest = path.join(process.cwd(), KUBB_CONFIG_FILENAME)\n if (fs.existsSync(dest)) {\n return tool.error(`${KUBB_CONFIG_FILENAME} already exists at ${dest}. Delete it first before running init again.`)\n }\n fs.writeFileSync(dest, content, 'utf-8')\n const packageList = ['kubb', ...selected.map((p) => p.packageName)].join(' ')\n return tool.text(`Created kubb.config.ts\\n\\nInstall packages:\\n npm install ${packageList}\\n\\nThen run:\\n npx kubb generate`)\n },\n)\n","import * as v from 'valibot'\n\nexport const validateSchema = v.object({\n input: v.pipe(v.string(), v.minLength(1), v.description('Path or URL to the OpenAPI/Swagger specification')),\n})\n","import { Diagnostics } from '@kubb/core'\nimport { defineTool } from 'tmcp/tool'\nimport { tool } from 'tmcp/utils'\nimport { validateSchema } from '../schemas/validateSchema.ts'\nimport { formatDiagnostics } from '../utils/formatDiagnostics.ts'\n\nexport const validateTool = defineTool(\n {\n name: 'validate',\n description: 'Validate an OpenAPI/Swagger specification file or URL',\n schema: validateSchema,\n },\n async ({ input }) => {\n let mod: typeof import('@kubb/adapter-oas')\n try {\n mod = await import('@kubb/adapter-oas')\n } catch {\n return tool.error('The validate tool requires @kubb/adapter-oas.\\nInstall: npm install @kubb/adapter-oas')\n }\n try {\n await mod.adapterOas().validate(input, { throwOnError: true })\n return tool.text(`Validation successful: ${input}`)\n } catch (err) {\n const serialized = Diagnostics.serialize(Diagnostics.from(err))\n return tool.error(`Validation failed:\\n${formatDiagnostics([serialized])}\\n\\n\\`\\`\\`json\\n${JSON.stringify(serialized, null, 2)}\\n\\`\\`\\``)\n }\n },\n)\n","import http from 'node:http'\nimport { createRequestListener } from '@remix-run/node-fetch-server'\nimport { ValibotJsonSchemaAdapter } from '@tmcp/adapter-valibot'\nimport { HttpTransport } from '@tmcp/transport-http'\nimport { StdioTransport } from '@tmcp/transport-stdio'\nimport { McpServer } from 'tmcp'\nimport { version } from '../package.json'\nimport { generateTool } from './tools/generate.ts'\nimport { initTool } from './tools/init.ts'\nimport { validateTool } from './tools/validate.ts'\n\nexport type ServerOptions = {\n port?: number\n host?: string\n}\n\nexport function createMcpServer() {\n const server = new McpServer({ name: 'Kubb', version }, { adapter: new ValibotJsonSchemaAdapter(), capabilities: { tools: {} } })\n server.tools([generateTool, validateTool, initTool])\n return server\n}\n\nexport async function startServer({ port, host = 'localhost' }: ServerOptions = {}) {\n const server = createMcpServer()\n\n if (port === undefined) {\n new StdioTransport(server).listen()\n return\n }\n\n const transport = new HttpTransport(server, { path: '/mcp' })\n const httpServer = http.createServer(\n createRequestListener(async (request) => {\n const response = await transport.respond(request)\n return response ?? new Response('Not Found', { status: 404 })\n }),\n )\n httpServer.listen(port, host, () => {\n console.log(`Kubb MCP server on http://${host}:${port}`)\n })\n\n const closeServer = () => httpServer.close()\n process.once('SIGINT', closeServer)\n process.once('SIGTERM', closeServer)\n httpServer.once('close', () => {\n process.off('SIGINT', closeServer)\n process.off('SIGTERM', closeServer)\n })\n}\n","import { startServer } from './server.ts'\n\nexport { createMcpServer } from './server.ts'\nexport type { ServerOptions } from './server.ts'\n\nexport async function run(_argv?: Array<string>, options?: import('./server.ts').ServerOptions): Promise<void> {\n await startServer(options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC8BA,SAAgB,QAAQ,OAAuB;CAC7C,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACjE;;;;;;;;;;;;;;ACbA,IAAa,oBAAb,MAAoF;;;;;CAKlF,YAAY,cAAc,IAAI;EAC5B,KAAKA,SAAS,gBAAgB,WAAW;CAC3C;CAEA,WAAW,IAAIC,aAAiB;;;;;;;;;;CAWhC,KAAgD,WAAuB,GAAG,WAAsD;EAC9H,MAAM,YAAY,KAAKD,SAAS,UAAU,SAAS;EAEnD,IAAI,UAAU,WAAW,GACvB;EAGF,OAAO,KAAKE,SAAS,WAAW,WAAW,SAAS;CACtD;CAEA,MAAMA,SACJ,WACA,WACA,WACe;EACf,KAAK,MAAM,YAAY,WACrB,IAAI;GACF,MAAM,SAAS,GAAG,SAAS;EAC7B,SAAS,KAAK;GACZ,IAAI;GACJ,IAAI;IACF,iBAAiB,KAAK,UAAU,SAAS;GAC3C,QAAQ;IACN,iBAAiB,OAAO,SAAS;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c;EAAc;CAAQ,CAAC;CACnD,OAAO;AACT;AAEA,eAAsB,YAAY,EAAE,MAAM,OAAO,gBAA+B,CAAC,GAAG;CAClF,MAAM,SAAS,gBAAgB;CAE/B,IAAI,SAAS,KAAA,GAAW;EACtB,IAAI,eAAe,MAAM,EAAE,OAAO;EAClC;CACF;CAEA,MAAM,YAAY,IAAI,cAAc,QAAQ,EAAE,MAAM,OAAO,CAAC;CAC5D,MAAM,aAAa,KAAK,aACtB,sBAAsB,OAAO,YAAY;EAEvC,OAAO,MADgB,UAAU,QAAQ,OAAO,KAC7B,IAAI,SAAS,aAAa,EAAE,QAAQ,IAAI,CAAC;CAC9D,CAAC,CACH;CACA,WAAW,OAAO,MAAM,YAAY;EAClC,QAAQ,IAAI,6BAA6B,KAAK,GAAG,MAAM;CACzD,CAAC;CAED,MAAM,oBAAoB,WAAW,MAAM;CAC3C,QAAQ,KAAK,UAAU,WAAW;CAClC,QAAQ,KAAK,WAAW,WAAW;CACnC,WAAW,KAAK,eAAe;EAC7B,QAAQ,IAAI,UAAU,WAAW;EACjC,QAAQ,IAAI,WAAW,WAAW;CACpC,CAAC;AACH;;;AC3CA,eAAsB,IAAI,OAAuB,SAA8D;CAC7G,MAAM,YAAY,OAAO;AAC3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/mcp",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.37",
|
|
4
4
|
"description": "MCP server for Kubb. Exposes code generation as a tool over the Model Context Protocol so AI assistants like Claude, Cursor, and other MCP-compatible clients can generate TypeScript types, clients, and more from OpenAPI specs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -54,16 +54,16 @@
|
|
|
54
54
|
"jiti": "^2.7.0",
|
|
55
55
|
"tmcp": "^1.19.4",
|
|
56
56
|
"valibot": "^1.4.1",
|
|
57
|
-
"@kubb/adapter-oas": "5.0.0-beta.
|
|
58
|
-
"@kubb/core": "5.0.0-beta.
|
|
57
|
+
"@kubb/adapter-oas": "5.0.0-beta.37",
|
|
58
|
+
"@kubb/core": "5.0.0-beta.37"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@internals/shared": "0.0.0",
|
|
62
62
|
"@internals/utils": "0.0.0",
|
|
63
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
63
|
+
"@kubb/renderer-jsx": "5.0.0-beta.37"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
66
|
+
"@kubb/renderer-jsx": "5.0.0-beta.37"
|
|
67
67
|
},
|
|
68
68
|
"size-limit": [
|
|
69
69
|
{
|
|
@@ -7,7 +7,7 @@ export const generateSchema = v.object({
|
|
|
7
7
|
input: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Path to OpenAPI/Swagger spec file (overrides config)'))),
|
|
8
8
|
output: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Output directory path (overrides config)'))),
|
|
9
9
|
logLevel: v.optional(
|
|
10
|
-
v.pipe(v.picklist(['silent', '
|
|
10
|
+
v.pipe(v.picklist(['silent', 'info', 'verbose']), v.description('Log level for build output')),
|
|
11
11
|
'info',
|
|
12
12
|
),
|
|
13
13
|
})
|
package/src/tools/generate.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AsyncEventEmitter
|
|
2
|
-
import { type Config, createKubb, type KubbHooks } from '@kubb/core'
|
|
1
|
+
import { AsyncEventEmitter } from '@internals/utils'
|
|
2
|
+
import { type Config, createKubb, type Diagnostic, Diagnostics, isProblemDiagnostic, type KubbHooks } from '@kubb/core'
|
|
3
3
|
import { defineTool } from 'tmcp/tool'
|
|
4
4
|
import { tool } from 'tmcp/utils'
|
|
5
5
|
import type * as v from 'valibot'
|
|
6
6
|
import { generateSchema } from '../schemas/generateSchema.ts'
|
|
7
|
+
import { formatDiagnostics } from '../utils/formatDiagnostics.ts'
|
|
7
8
|
import { NotifyTypes } from '../types.ts'
|
|
8
9
|
import { loadUserConfig } from '../utils/loadUserConfig.ts'
|
|
9
10
|
import { resolveCwd } from '../utils/resolveCwd.ts'
|
|
@@ -22,8 +23,8 @@ export const generateTool = defineTool(
|
|
|
22
23
|
const hooks = new AsyncEventEmitter<KubbHooks>()
|
|
23
24
|
const messages: Array<string> = []
|
|
24
25
|
|
|
25
|
-
const notify = async (type: string, message: string,
|
|
26
|
-
messages.push(`${type}: ${message}`)
|
|
26
|
+
const notify = async (type: string, message: string, data?: Record<string, unknown>) => {
|
|
27
|
+
messages.push(data ? `${type}: ${message} ${JSON.stringify(data)}` : `${type}: ${message}`)
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
hooks.on('kubb:info', async ({ message }: { message: string }) => {
|
|
@@ -42,6 +43,10 @@ export const generateTool = defineTool(
|
|
|
42
43
|
await notify(NotifyTypes.WARN, message)
|
|
43
44
|
})
|
|
44
45
|
|
|
46
|
+
hooks.on('kubb:diagnostic', async ({ diagnostic }: { diagnostic: Diagnostic }) => {
|
|
47
|
+
await notify(NotifyTypes.DIAGNOSTIC, diagnostic.message, Diagnostics.serialize(diagnostic))
|
|
48
|
+
})
|
|
49
|
+
|
|
45
50
|
hooks.on('kubb:plugin:start', async ({ plugin }) => {
|
|
46
51
|
await notify(NotifyTypes.PLUGIN_START, `Plugin starting: ${plugin.name}`)
|
|
47
52
|
})
|
|
@@ -119,28 +124,24 @@ export const generateTool = defineTool(
|
|
|
119
124
|
await notify(NotifyTypes.SETUP_END, 'Kubb setup complete')
|
|
120
125
|
|
|
121
126
|
await notify(NotifyTypes.BUILD_START, 'Starting build')
|
|
122
|
-
const { files,
|
|
127
|
+
const { files, diagnostics } = await kubb.safeBuild()
|
|
123
128
|
await notify(NotifyTypes.BUILD_END, `Build complete - Generated ${files.length} files`)
|
|
124
129
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
.filter((it) => it.error)
|
|
130
|
-
.map((it) => it.error),
|
|
131
|
-
].filter(Boolean)
|
|
132
|
-
|
|
133
|
-
await notify(NotifyTypes.BUILD_FAILED, `Build failed with ${allErrors.length} error(s)`)
|
|
130
|
+
const problems = diagnostics.filter(isProblemDiagnostic)
|
|
131
|
+
const errors = problems.filter((diagnostic) => diagnostic.severity === 'error')
|
|
132
|
+
if (errors.length > 0) {
|
|
133
|
+
await notify(NotifyTypes.BUILD_FAILED, `Build failed with ${errors.length} diagnostic(s)`)
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
const serialized = problems.map((diagnostic) => Diagnostics.serialize(diagnostic))
|
|
136
|
+
return tool.error(`Build failed:\n${formatDiagnostics(serialized)}\n\n\`\`\`json\n${JSON.stringify(serialized, null, 2)}\n\`\`\``)
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
await notify(NotifyTypes.BUILD_SUCCESS, `Build completed successfully - Generated ${files.length} files`)
|
|
139
140
|
|
|
140
141
|
return tool.text(`Build completed successfully!\n\nGenerated ${files.length} files\n\n${messages.join('\n')}`)
|
|
141
142
|
} catch (caughtError) {
|
|
142
|
-
const
|
|
143
|
-
return tool.error(`Build error
|
|
143
|
+
const serialized = Diagnostics.serialize(Diagnostics.from(caughtError))
|
|
144
|
+
return tool.error(`Build error:\n${formatDiagnostics([serialized])}\n\n\`\`\`json\n${JSON.stringify(serialized, null, 2)}\n\`\`\``)
|
|
144
145
|
}
|
|
145
146
|
},
|
|
146
147
|
)
|
package/src/tools/validate.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { Diagnostics } from '@kubb/core'
|
|
1
2
|
import { defineTool } from 'tmcp/tool'
|
|
2
3
|
import { tool } from 'tmcp/utils'
|
|
3
4
|
import { validateSchema } from '../schemas/validateSchema.ts'
|
|
5
|
+
import { formatDiagnostics } from '../utils/formatDiagnostics.ts'
|
|
4
6
|
|
|
5
7
|
export const validateTool = defineTool(
|
|
6
8
|
{
|
|
@@ -19,7 +21,8 @@ export const validateTool = defineTool(
|
|
|
19
21
|
await mod.adapterOas().validate(input, { throwOnError: true })
|
|
20
22
|
return tool.text(`Validation successful: ${input}`)
|
|
21
23
|
} catch (err) {
|
|
22
|
-
|
|
24
|
+
const serialized = Diagnostics.serialize(Diagnostics.from(err))
|
|
25
|
+
return tool.error(`Validation failed:\n${formatDiagnostics([serialized])}\n\n\`\`\`json\n${JSON.stringify(serialized, null, 2)}\n\`\`\``)
|
|
23
26
|
}
|
|
24
27
|
},
|
|
25
28
|
)
|
package/src/types.ts
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SerializedDiagnostic } from '@kubb/core'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Renders serialized diagnostics as a plain-text block for an AI assistant. Each entry
|
|
5
|
+
* keeps the stable `code`, the source pointer, the suggested fix, and the docs link, so
|
|
6
|
+
* the agent can act on the problem rather than parsing a bare message. No ANSI styling,
|
|
7
|
+
* unlike the CLI renderer.
|
|
8
|
+
*/
|
|
9
|
+
export function formatDiagnostics(diagnostics: ReadonlyArray<SerializedDiagnostic>): string {
|
|
10
|
+
return diagnostics.map((diagnostic) => formatDiagnostic(diagnostic)).join('\n\n')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function formatDiagnostic(diagnostic: SerializedDiagnostic): string {
|
|
14
|
+
const { code, severity, message, location, help, plugin, docsUrl } = diagnostic
|
|
15
|
+
const rule = plugin ? `${plugin}(${code})` : code
|
|
16
|
+
const lines = [`${severity} ${rule}: ${message}`]
|
|
17
|
+
|
|
18
|
+
if (location && 'pointer' in location) {
|
|
19
|
+
lines.push(` at ${location.pointer}`)
|
|
20
|
+
}
|
|
21
|
+
if (help) {
|
|
22
|
+
lines.push(` help: ${help}`)
|
|
23
|
+
}
|
|
24
|
+
if (docsUrl) {
|
|
25
|
+
lines.push(` docs: ${docsUrl}`)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return lines.join('\n')
|
|
29
|
+
}
|