@kubb/mcp 5.0.0-beta.9 → 5.0.0-beta.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -10
- package/README.md +29 -19
- package/dist/index.cjs +6138 -381
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -9
- package/dist/index.js +6142 -388
- package/dist/index.js.map +1 -1
- package/dist/rolldown-runtime-G2anUtha.js +30 -0
- package/package.json +18 -28
- package/dist/chunk--u3MIqq1.js +0 -8
- package/src/constants.ts +0 -1
- package/src/index.ts +0 -8
- package/src/schemas/generateSchema.ts +0 -13
- package/src/schemas/initSchema.ts +0 -7
- package/src/schemas/validateSchema.ts +0 -5
- package/src/server.ts +0 -41
- package/src/tools/generate.ts +0 -146
- package/src/tools/init.ts +0 -37
- package/src/tools/validate.ts +0 -25
- package/src/types.ts +0 -23
- package/src/utils/loadUserConfig.ts +0 -78
- package/src/utils/resolveCwd.ts +0 -20
- package/src/utils/resolveUserConfig.ts +0 -13
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
6
|
+
value,
|
|
7
|
+
configurable: true
|
|
8
|
+
});
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
16
|
+
key = keys[i];
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: ((k) => from[k]).bind(null, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
29
|
+
//#endregion
|
|
30
|
+
export { __toESM as i, __name as n, __require as r, __commonJSMin as t };
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/mcp",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
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
|
|
3
|
+
"version": "5.0.0-beta.91",
|
|
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.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
7
7
|
"codegen",
|
|
8
8
|
"kubb",
|
|
9
9
|
"llm",
|
|
10
10
|
"mcp",
|
|
11
|
+
"meta-framework",
|
|
11
12
|
"model-context-protocol",
|
|
12
|
-
"openapi",
|
|
13
13
|
"typescript"
|
|
14
14
|
],
|
|
15
15
|
"license": "MIT",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"kubb-mcp": "bin/kubb-mcp.cjs"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
|
-
"src",
|
|
27
26
|
"dist",
|
|
28
27
|
"bin",
|
|
29
28
|
"!/**/**.test.**",
|
|
@@ -47,44 +46,35 @@
|
|
|
47
46
|
"registry": "https://registry.npmjs.org/"
|
|
48
47
|
},
|
|
49
48
|
"dependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"@tmcp/
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"valibot": "^1.4.0",
|
|
57
|
-
"@kubb/adapter-oas": "5.0.0-beta.9",
|
|
58
|
-
"@kubb/core": "5.0.0-beta.9"
|
|
49
|
+
"@tmcp/adapter-valibot": "^0.1.6",
|
|
50
|
+
"@tmcp/transport-stdio": "^0.4.3",
|
|
51
|
+
"tmcp": "^1.19.4",
|
|
52
|
+
"valibot": "^1.4.2",
|
|
53
|
+
"@kubb/adapter-oas": "5.0.0-beta.91",
|
|
54
|
+
"@kubb/core": "5.0.0-beta.91"
|
|
59
55
|
},
|
|
60
56
|
"devDependencies": {
|
|
61
57
|
"@internals/shared": "0.0.0",
|
|
62
|
-
"@
|
|
63
|
-
"@
|
|
58
|
+
"@kubb/renderer-jsx": "5.0.0-beta.91",
|
|
59
|
+
"@internals/utils": "0.0.0"
|
|
64
60
|
},
|
|
65
61
|
"peerDependencies": {
|
|
66
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
62
|
+
"@kubb/renderer-jsx": "5.0.0-beta.91"
|
|
67
63
|
},
|
|
68
|
-
"size-limit": [
|
|
69
|
-
{
|
|
70
|
-
"path": "./dist/*.js",
|
|
71
|
-
"limit": "600 KiB",
|
|
72
|
-
"gzip": true
|
|
73
|
-
}
|
|
74
|
-
],
|
|
75
64
|
"engines": {
|
|
76
65
|
"node": ">=22"
|
|
77
66
|
},
|
|
67
|
+
"inlinedDependencies": {
|
|
68
|
+
"jiti": "2.7.0"
|
|
69
|
+
},
|
|
78
70
|
"scripts": {
|
|
79
|
-
"build": "tsdown
|
|
80
|
-
"
|
|
71
|
+
"build": "tsdown",
|
|
72
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
81
73
|
"debug:mcp": "npx -y @modelcontextprotocol/inspector node ./bin/kubb-mcp.cjs",
|
|
82
|
-
"clean": "npx rimraf ./dist",
|
|
83
74
|
"lint": "oxlint .",
|
|
84
75
|
"lint:fix": "oxlint --fix .",
|
|
85
|
-
"release": "pnpm publish --no-git-check",
|
|
86
|
-
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
87
76
|
"start": "tsdown --watch",
|
|
77
|
+
"start:mcp": "bun --watch ./src/server.ts",
|
|
88
78
|
"test": "vitest --passWithNoTests",
|
|
89
79
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
90
80
|
}
|
package/dist/chunk--u3MIqq1.js
DELETED
package/src/constants.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const ALLOWED_CONFIG_EXTENSIONS = new Set(['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'])
|
package/src/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { startServer } from './server.ts'
|
|
2
|
-
|
|
3
|
-
export { createMcpServer } from './server.ts'
|
|
4
|
-
export type { ServerOptions } from './server.ts'
|
|
5
|
-
|
|
6
|
-
export async function run(_argv?: string[], options?: import('./server.ts').ServerOptions): Promise<void> {
|
|
7
|
-
await startServer(options)
|
|
8
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot'
|
|
2
|
-
|
|
3
|
-
export const generateSchema = v.object({
|
|
4
|
-
config: v.optional(
|
|
5
|
-
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')),
|
|
6
|
-
),
|
|
7
|
-
input: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Path to OpenAPI/Swagger spec file (overrides config)'))),
|
|
8
|
-
output: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Output directory path (overrides config)'))),
|
|
9
|
-
logLevel: v.optional(
|
|
10
|
-
v.pipe(v.picklist(['silent', 'error', 'warn', 'info', 'verbose', 'debug']), v.description('Log level for build output')),
|
|
11
|
-
'info',
|
|
12
|
-
),
|
|
13
|
-
})
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot'
|
|
2
|
-
|
|
3
|
-
export const initSchema = v.object({
|
|
4
|
-
input: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Path to OpenAPI spec (default: ./openapi.yaml)'))),
|
|
5
|
-
output: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Output directory (default: ./src/gen)'))),
|
|
6
|
-
plugins: v.optional(v.pipe(v.string(), v.minLength(1), v.description('Comma-separated list of plugins: plugin-ts,plugin-zod,...'))),
|
|
7
|
-
})
|
package/src/server.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import http from 'node:http'
|
|
2
|
-
import { createRequestListener } from '@remix-run/node-fetch-server'
|
|
3
|
-
import { ValibotJsonSchemaAdapter } from '@tmcp/adapter-valibot'
|
|
4
|
-
import { HttpTransport } from '@tmcp/transport-http'
|
|
5
|
-
import { StdioTransport } from '@tmcp/transport-stdio'
|
|
6
|
-
import { McpServer } from 'tmcp'
|
|
7
|
-
import { version } from '../package.json'
|
|
8
|
-
import { generateTool } from './tools/generate.ts'
|
|
9
|
-
import { initTool } from './tools/init.ts'
|
|
10
|
-
import { validateTool } from './tools/validate.ts'
|
|
11
|
-
|
|
12
|
-
export type ServerOptions = {
|
|
13
|
-
port?: number
|
|
14
|
-
host?: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function createMcpServer() {
|
|
18
|
-
const server = new McpServer({ name: 'Kubb', version }, { adapter: new ValibotJsonSchemaAdapter(), capabilities: { tools: {} } })
|
|
19
|
-
server.tools([generateTool, validateTool, initTool])
|
|
20
|
-
return server
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function startServer({ port, host = 'localhost' }: ServerOptions = {}) {
|
|
24
|
-
const server = createMcpServer()
|
|
25
|
-
|
|
26
|
-
if (port === undefined) {
|
|
27
|
-
new StdioTransport(server).listen()
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const transport = new HttpTransport(server, { path: '/mcp' })
|
|
32
|
-
const httpServer = http.createServer(
|
|
33
|
-
createRequestListener(async (request) => {
|
|
34
|
-
const response = await transport.respond(request)
|
|
35
|
-
return response ?? new Response('Not Found', { status: 404 })
|
|
36
|
-
}),
|
|
37
|
-
)
|
|
38
|
-
httpServer.listen(port, host, () => {
|
|
39
|
-
console.log(`Kubb MCP server on http://${host}:${port}`)
|
|
40
|
-
})
|
|
41
|
-
}
|
package/src/tools/generate.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { AsyncEventEmitter, toError } from '@internals/utils'
|
|
2
|
-
import { type Config, createKubb, type KubbHooks } from '@kubb/core'
|
|
3
|
-
import { defineTool } from 'tmcp/tool'
|
|
4
|
-
import { tool } from 'tmcp/utils'
|
|
5
|
-
import type * as v from 'valibot'
|
|
6
|
-
import { generateSchema } from '../schemas/generateSchema.ts'
|
|
7
|
-
import { NotifyTypes } from '../types.ts'
|
|
8
|
-
import { loadUserConfig } from '../utils/loadUserConfig.ts'
|
|
9
|
-
import { resolveCwd } from '../utils/resolveCwd.ts'
|
|
10
|
-
import { resolveUserConfig } from '../utils/resolveUserConfig.ts'
|
|
11
|
-
|
|
12
|
-
export const generateTool = defineTool(
|
|
13
|
-
{
|
|
14
|
-
name: 'generate',
|
|
15
|
-
description: 'Generate OpenAPI spec helpers using Kubb configuration',
|
|
16
|
-
schema: generateSchema,
|
|
17
|
-
},
|
|
18
|
-
async function generate(schema: v.InferInput<typeof generateSchema>) {
|
|
19
|
-
const { config: configPath, input, output, logLevel } = schema
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
const hooks = new AsyncEventEmitter<KubbHooks>()
|
|
23
|
-
const messages: string[] = []
|
|
24
|
-
|
|
25
|
-
const notify = async (type: string, message: string, _data?: Record<string, unknown>) => {
|
|
26
|
-
messages.push(`${type}: ${message}`)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
hooks.on('kubb:info', async ({ message }: { message: string }) => {
|
|
30
|
-
await notify(NotifyTypes.INFO, message)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
hooks.on('kubb:success', async ({ message }: { message: string }) => {
|
|
34
|
-
await notify(NotifyTypes.SUCCESS, message)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
hooks.on('kubb:error', async ({ error }: { error: Error }) => {
|
|
38
|
-
await notify(NotifyTypes.ERROR, error.message)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
hooks.on('kubb:warn', async ({ message }: { message: string }) => {
|
|
42
|
-
await notify(NotifyTypes.WARN, message)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
hooks.on('kubb:plugin:start', async ({ plugin }) => {
|
|
46
|
-
await notify(NotifyTypes.PLUGIN_START, `Plugin starting: ${plugin.name}`)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
hooks.on('kubb:plugin:end', async ({ plugin, duration }) => {
|
|
50
|
-
await notify(NotifyTypes.PLUGIN_END, `Plugin finished: ${plugin.name}`, { duration })
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
hooks.on('kubb:files:processing:start', async () => {
|
|
54
|
-
await notify(NotifyTypes.FILES_START, 'Starting file processing')
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
hooks.on('kubb:file:processing:update', async ({ file }: { file: { name: string } }) => {
|
|
58
|
-
await notify(NotifyTypes.FILE_UPDATE, `Processing file: ${file.name}`)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
hooks.on('kubb:files:processing:end', async () => {
|
|
62
|
-
await notify(NotifyTypes.FILES_END, 'File processing complete')
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
hooks.on('kubb:generation:start', async () => {
|
|
66
|
-
await notify(NotifyTypes.GENERATION_START, 'Generation started')
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
hooks.on('kubb:generation:end', async () => {
|
|
70
|
-
await notify(NotifyTypes.GENERATION_END, 'Generation ended')
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
let userConfig: Config
|
|
74
|
-
let cwd: string
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const configResult = await loadUserConfig(configPath, { notify })
|
|
78
|
-
userConfig = configResult.userConfig
|
|
79
|
-
cwd = configResult.cwd
|
|
80
|
-
|
|
81
|
-
if (Array.isArray(userConfig)) {
|
|
82
|
-
throw new Error('Array type in kubb.config.ts is not supported in this tool. Please provide a single configuration object.')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
userConfig = await resolveUserConfig(userConfig, {
|
|
86
|
-
configPath,
|
|
87
|
-
logLevel,
|
|
88
|
-
})
|
|
89
|
-
} catch (error) {
|
|
90
|
-
const errorMessage = error instanceof Error ? error.message : String(error)
|
|
91
|
-
await notify(NotifyTypes.CONFIG_ERROR, errorMessage)
|
|
92
|
-
return tool.error(errorMessage)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const inputPath = input ?? (userConfig.input && 'path' in userConfig.input ? userConfig.input.path : undefined)
|
|
96
|
-
|
|
97
|
-
const config: Config = {
|
|
98
|
-
...userConfig,
|
|
99
|
-
root: resolveCwd(userConfig, cwd),
|
|
100
|
-
input: inputPath
|
|
101
|
-
? {
|
|
102
|
-
...userConfig.input,
|
|
103
|
-
path: inputPath,
|
|
104
|
-
}
|
|
105
|
-
: userConfig.input,
|
|
106
|
-
output: output
|
|
107
|
-
? {
|
|
108
|
-
...userConfig.output,
|
|
109
|
-
path: output,
|
|
110
|
-
}
|
|
111
|
-
: userConfig.output,
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
await notify(NotifyTypes.CONFIG_READY, 'Configuration ready')
|
|
115
|
-
await notify(NotifyTypes.SETUP_START, 'Setting up Kubb')
|
|
116
|
-
|
|
117
|
-
const kubb = createKubb(config, { hooks })
|
|
118
|
-
await kubb.setup()
|
|
119
|
-
await notify(NotifyTypes.SETUP_END, 'Kubb setup complete')
|
|
120
|
-
|
|
121
|
-
await notify(NotifyTypes.BUILD_START, 'Starting build')
|
|
122
|
-
const { files, failedPlugins, error } = await kubb.safeBuild()
|
|
123
|
-
await notify(NotifyTypes.BUILD_END, `Build complete - Generated ${files.length} files`)
|
|
124
|
-
|
|
125
|
-
if (error || failedPlugins.size > 0) {
|
|
126
|
-
const allErrors: Error[] = [
|
|
127
|
-
error,
|
|
128
|
-
...Array.from(failedPlugins)
|
|
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)`)
|
|
134
|
-
|
|
135
|
-
return tool.error(`Build failed:\n${allErrors.map((err) => err.message).join('\n')}\n\n${messages.join('\n')}`)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
await notify(NotifyTypes.BUILD_SUCCESS, `Build completed successfully - Generated ${files.length} files`)
|
|
139
|
-
|
|
140
|
-
return tool.text(`Build completed successfully!\n\nGenerated ${files.length} files\n\n${messages.join('\n')}`)
|
|
141
|
-
} catch (caughtError) {
|
|
142
|
-
const error = toError(caughtError)
|
|
143
|
-
return tool.error(`Build error: ${error.message}\n${error.stack ?? ''}`)
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
)
|
package/src/tools/init.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import process from 'node:process'
|
|
4
|
-
import { availablePlugins, generateConfigFile, KUBB_CONFIG_FILENAME, type PluginOption } from '@internals/shared'
|
|
5
|
-
import { defineTool } from 'tmcp/tool'
|
|
6
|
-
import { tool } from 'tmcp/utils'
|
|
7
|
-
import { initSchema } from '../schemas/initSchema.ts'
|
|
8
|
-
|
|
9
|
-
export function resolvePlugins(pluginsFlag: string | undefined): PluginOption[] {
|
|
10
|
-
if (!pluginsFlag) {
|
|
11
|
-
return []
|
|
12
|
-
}
|
|
13
|
-
const requested = pluginsFlag
|
|
14
|
-
.split(',')
|
|
15
|
-
.map((v) => v.trim())
|
|
16
|
-
.filter(Boolean)
|
|
17
|
-
return availablePlugins.filter((p) => requested.includes(p.value))
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const initTool = defineTool(
|
|
21
|
-
{
|
|
22
|
-
name: 'init',
|
|
23
|
-
description: 'Scaffold a kubb.config.ts in the current directory (non-interactive). Does not install packages.',
|
|
24
|
-
schema: initSchema,
|
|
25
|
-
},
|
|
26
|
-
async ({ input = './openapi.yaml', output = './src/gen', plugins }) => {
|
|
27
|
-
const selected = resolvePlugins(plugins)
|
|
28
|
-
const content = generateConfigFile({ selectedPlugins: selected, inputPath: input, outputPath: output })
|
|
29
|
-
const dest = path.join(process.cwd(), KUBB_CONFIG_FILENAME)
|
|
30
|
-
if (fs.existsSync(dest)) {
|
|
31
|
-
return tool.error(`${KUBB_CONFIG_FILENAME} already exists at ${dest}. Delete it first before running init again.`)
|
|
32
|
-
}
|
|
33
|
-
fs.writeFileSync(dest, content, 'utf-8')
|
|
34
|
-
const packageList = ['kubb', ...selected.map((p) => p.packageName)].join(' ')
|
|
35
|
-
return tool.text(`Created kubb.config.ts\n\nInstall packages:\n npm install ${packageList}\n\nThen run:\n npx kubb generate`)
|
|
36
|
-
},
|
|
37
|
-
)
|
package/src/tools/validate.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { defineTool } from 'tmcp/tool'
|
|
2
|
-
import { tool } from 'tmcp/utils'
|
|
3
|
-
import { validateSchema } from '../schemas/validateSchema.ts'
|
|
4
|
-
|
|
5
|
-
export const validateTool = defineTool(
|
|
6
|
-
{
|
|
7
|
-
name: 'validate',
|
|
8
|
-
description: 'Validate an OpenAPI/Swagger specification file or URL',
|
|
9
|
-
schema: validateSchema,
|
|
10
|
-
},
|
|
11
|
-
async ({ input }) => {
|
|
12
|
-
let mod: typeof import('@kubb/adapter-oas')
|
|
13
|
-
try {
|
|
14
|
-
mod = await import('@kubb/adapter-oas')
|
|
15
|
-
} catch {
|
|
16
|
-
return tool.error('The validate tool requires @kubb/adapter-oas.\nInstall: npm install @kubb/adapter-oas')
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
await mod.adapterOas().validate(input, { throwOnError: true })
|
|
20
|
-
return tool.text(`Validation successful: ${input}`)
|
|
21
|
-
} catch (err) {
|
|
22
|
-
return tool.error(`Validation failed:\n${err instanceof Error ? err.message : String(err)}`)
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
)
|
package/src/types.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export const NotifyTypes = {
|
|
2
|
-
INFO: 'INFO',
|
|
3
|
-
SUCCESS: 'SUCCESS',
|
|
4
|
-
ERROR: 'ERROR',
|
|
5
|
-
WARN: 'WARN',
|
|
6
|
-
PLUGIN_START: 'PLUGIN_START',
|
|
7
|
-
PLUGIN_END: 'PLUGIN_END',
|
|
8
|
-
FILES_START: 'FILES_START',
|
|
9
|
-
FILE_UPDATE: 'FILE_UPDATE',
|
|
10
|
-
FILES_END: 'FILES_END',
|
|
11
|
-
GENERATION_START: 'GENERATION_START',
|
|
12
|
-
GENERATION_END: 'GENERATION_END',
|
|
13
|
-
CONFIG_LOADED: 'CONFIG_LOADED',
|
|
14
|
-
CONFIG_ERROR: 'CONFIG_ERROR',
|
|
15
|
-
CONFIG_READY: 'CONFIG_READY',
|
|
16
|
-
SETUP_START: 'SETUP_START',
|
|
17
|
-
SETUP_END: 'SETUP_END',
|
|
18
|
-
BUILD_START: 'BUILD_START',
|
|
19
|
-
BUILD_END: 'BUILD_END',
|
|
20
|
-
BUILD_FAILED: 'BUILD_FAILED',
|
|
21
|
-
BUILD_SUCCESS: 'BUILD_SUCCESS',
|
|
22
|
-
FATAL_ERROR: 'FATAL_ERROR',
|
|
23
|
-
} as const
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import type { Config } from '@kubb/core'
|
|
4
|
-
import { createJiti } from 'jiti'
|
|
5
|
-
import { ALLOWED_CONFIG_EXTENSIONS } from '../constants.ts'
|
|
6
|
-
import { NotifyTypes } from '../types.ts'
|
|
7
|
-
|
|
8
|
-
type NotifyFunction = (type: string, message: string, data?: Record<string, unknown>) => Promise<void>
|
|
9
|
-
|
|
10
|
-
const jiti = createJiti(import.meta.url, {
|
|
11
|
-
jsx: {
|
|
12
|
-
runtime: 'automatic',
|
|
13
|
-
importSource: '@kubb/renderer-jsx',
|
|
14
|
-
},
|
|
15
|
-
moduleCache: false,
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
const loadedModules = new Map<string, unknown>()
|
|
19
|
-
|
|
20
|
-
async function loadModule(filePath: string): Promise<unknown> {
|
|
21
|
-
const ext = path.extname(filePath)
|
|
22
|
-
if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {
|
|
23
|
-
throw new Error(`Invalid config file extension "${ext}". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`)
|
|
24
|
-
}
|
|
25
|
-
if (loadedModules.has(filePath)) {
|
|
26
|
-
return loadedModules.get(filePath)
|
|
27
|
-
}
|
|
28
|
-
const mod = await jiti.import(filePath, { default: true })
|
|
29
|
-
loadedModules.set(filePath, mod)
|
|
30
|
-
return mod
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function loadUserConfig(configPath: string | undefined, { notify }: { notify: NotifyFunction }): Promise<{ userConfig: Config; cwd: string }> {
|
|
34
|
-
if (configPath) {
|
|
35
|
-
const ext = path.extname(configPath)
|
|
36
|
-
if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {
|
|
37
|
-
const msg = `Invalid config file extension "${ext}". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`
|
|
38
|
-
await notify(NotifyTypes.CONFIG_ERROR, msg)
|
|
39
|
-
throw new Error(msg)
|
|
40
|
-
}
|
|
41
|
-
const base = path.resolve(process.cwd())
|
|
42
|
-
const resolvedConfigPath = path.resolve(base, configPath)
|
|
43
|
-
const relative = path.relative(base, resolvedConfigPath)
|
|
44
|
-
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
45
|
-
const msg = 'Invalid config file path: must be within the current working directory'
|
|
46
|
-
await notify(NotifyTypes.CONFIG_ERROR, msg)
|
|
47
|
-
throw new Error(msg)
|
|
48
|
-
}
|
|
49
|
-
const cwd = path.dirname(resolvedConfigPath)
|
|
50
|
-
try {
|
|
51
|
-
const userConfig = (await loadModule(resolvedConfigPath)) as Config
|
|
52
|
-
await notify(NotifyTypes.CONFIG_LOADED, `Loaded config from ${resolvedConfigPath}`)
|
|
53
|
-
return { userConfig, cwd }
|
|
54
|
-
} catch (error) {
|
|
55
|
-
const msg = `Failed to load config: ${error instanceof Error ? error.message : String(error)}`
|
|
56
|
-
await notify(NotifyTypes.CONFIG_ERROR, msg)
|
|
57
|
-
throw new Error(msg)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const cwd = process.cwd()
|
|
62
|
-
const configFileNames = ['kubb.config.ts', 'kubb.config.mts', 'kubb.config.cts', 'kubb.config.js', 'kubb.config.cjs']
|
|
63
|
-
|
|
64
|
-
for (const configFileName of configFileNames) {
|
|
65
|
-
const configFilePath = path.resolve(process.cwd(), configFileName)
|
|
66
|
-
if (!existsSync(configFilePath)) continue
|
|
67
|
-
try {
|
|
68
|
-
const userConfig = (await loadModule(configFilePath)) as Config
|
|
69
|
-
await notify(NotifyTypes.CONFIG_LOADED, `Loaded ${configFileName} from current directory`)
|
|
70
|
-
return { userConfig, cwd }
|
|
71
|
-
} catch (err) {
|
|
72
|
-
await notify(NotifyTypes.CONFIG_ERROR, `Failed to load ${configFileName}: ${err instanceof Error ? err.message : String(err)}`)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
await notify(NotifyTypes.CONFIG_ERROR, 'No config file found')
|
|
77
|
-
throw new Error(`No config file found. Please provide a config path or create one of: ${configFileNames.join(', ')}`)
|
|
78
|
-
}
|
package/src/utils/resolveCwd.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import type { Config } from '@kubb/core'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Determine the root directory based on userConfig.root and resolvedConfigDir
|
|
6
|
-
* 1. If userConfig.root exists and is absolute, use it as-is
|
|
7
|
-
* 2. If userConfig.root exists and is relative, resolve it relative to config directory
|
|
8
|
-
* 3. Otherwise, use the config directory as root
|
|
9
|
-
*/
|
|
10
|
-
export function resolveCwd(userConfig: Config, cwd: string): string {
|
|
11
|
-
if (userConfig.root) {
|
|
12
|
-
if (path.isAbsolute(userConfig.root)) {
|
|
13
|
-
return userConfig.root
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return path.resolve(cwd, userConfig.root)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return cwd
|
|
20
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { isPromise } from '@internals/utils'
|
|
2
|
-
import type { CLIOptions, Config, PossibleConfig } from '@kubb/core'
|
|
3
|
-
|
|
4
|
-
export type ResolveUserConfigOptions = {
|
|
5
|
-
configPath?: string
|
|
6
|
-
logLevel?: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function resolveUserConfig(config: PossibleConfig<CLIOptions>, options: ResolveUserConfigOptions): Promise<Config> {
|
|
10
|
-
const result = typeof config === 'function' ? config({ logLevel: options.logLevel as CLIOptions['logLevel'], config: options.configPath }) : config
|
|
11
|
-
const resolved = isPromise(result) ? await result : result
|
|
12
|
-
return (Array.isArray(resolved) ? resolved[0] : resolved) as Config
|
|
13
|
-
}
|