@keystoneui/mcp 0.2.0-beta.4 → 0.2.0-beta.6
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 +21 -19
- package/dist/chunk-LC22ZWZH.js +1372 -0
- package/dist/index.js +143 -90
- package/dist/{server-TNVOIXZW.js → server-HWF3HIOR.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-JVJEQ7VV.js +0 -560
|
@@ -0,0 +1,1372 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/config.ts
|
|
4
|
+
import { existsSync, readFileSync } from "fs";
|
|
5
|
+
import { resolve } from "path";
|
|
6
|
+
|
|
7
|
+
// src/registry-url.ts
|
|
8
|
+
var NAME = "{name}";
|
|
9
|
+
var ITEM_FILE = `/${NAME}.json`;
|
|
10
|
+
var PLACEHOLDER = /\{(?:name|style)\}/;
|
|
11
|
+
var HEAD = /^([^:/?#]*:[/\\]{2}[^/\\]*)(.*)$/s;
|
|
12
|
+
var TRAILING_SLASHES = /\/+$/;
|
|
13
|
+
var IGNORED_BY_PARSER = /[\t\n\r]|^[\0- ]|[\0- ]$/;
|
|
14
|
+
function sameAuthority(head, url) {
|
|
15
|
+
let own;
|
|
16
|
+
try {
|
|
17
|
+
own = new URL(head);
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return own.protocol === url.protocol && own.username === url.username && own.password === url.password && own.host === url.host;
|
|
22
|
+
}
|
|
23
|
+
function split(raw) {
|
|
24
|
+
let url;
|
|
25
|
+
try {
|
|
26
|
+
url = new URL(raw);
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (IGNORED_BY_PARSER.test(raw)) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const hashAt = raw.indexOf("#");
|
|
37
|
+
const beforeHash = hashAt === -1 ? raw : raw.slice(0, hashAt);
|
|
38
|
+
const queryAt = beforeHash.indexOf("?");
|
|
39
|
+
const beforeQuery = queryAt === -1 ? beforeHash : beforeHash.slice(0, queryAt);
|
|
40
|
+
const match = HEAD.exec(beforeQuery);
|
|
41
|
+
if (!(match && sameAuthority(match[1], url))) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
head: match[1],
|
|
46
|
+
path: match[2],
|
|
47
|
+
query: queryAt === -1 ? "" : beforeHash.slice(queryAt + 1)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function count(text, part) {
|
|
51
|
+
return text.split(part).length - 1;
|
|
52
|
+
}
|
|
53
|
+
function withQuery(query, params) {
|
|
54
|
+
const extra = params ? new URLSearchParams(params).toString() : "";
|
|
55
|
+
const joined = [query, extra].filter(Boolean).join("&");
|
|
56
|
+
return joined ? `?${joined}` : "";
|
|
57
|
+
}
|
|
58
|
+
function templateParts(source) {
|
|
59
|
+
if (!(source.template && source.url.includes(NAME))) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const parts = split(source.url);
|
|
63
|
+
if (!parts || source.url.includes("{style}")) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
if (count(parts.path, NAME) === 0 || count(parts.path, NAME) !== count(source.url, NAME)) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return parts;
|
|
70
|
+
}
|
|
71
|
+
function joinBase(raw, path) {
|
|
72
|
+
const parts = PLACEHOLDER.test(raw) ? null : split(raw);
|
|
73
|
+
if (!parts) {
|
|
74
|
+
return `${raw}/${path}`;
|
|
75
|
+
}
|
|
76
|
+
const dir = parts.path.replace(TRAILING_SLASHES, "");
|
|
77
|
+
return `${parts.head}${dir}/${path}${withQuery(parts.query)}`;
|
|
78
|
+
}
|
|
79
|
+
function docsResourceUrl(docsUrl, path) {
|
|
80
|
+
return joinBase(docsUrl, path);
|
|
81
|
+
}
|
|
82
|
+
function docsRegistryUrl(docsUrl) {
|
|
83
|
+
return joinBase(docsUrl, "r");
|
|
84
|
+
}
|
|
85
|
+
function normalise(source) {
|
|
86
|
+
return typeof source === "string" ? { url: source } : source;
|
|
87
|
+
}
|
|
88
|
+
function joinSource(source, path) {
|
|
89
|
+
return source.docsUrl === void 0 ? joinBase(source.url, path) : joinBase(source.docsUrl, `r/${path}`);
|
|
90
|
+
}
|
|
91
|
+
function templateDir(parts) {
|
|
92
|
+
const { path } = parts;
|
|
93
|
+
if (!path.endsWith(ITEM_FILE) || count(path, NAME) !== 1) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return path.slice(0, -ITEM_FILE.length);
|
|
97
|
+
}
|
|
98
|
+
function registryItemUrl(registry, name) {
|
|
99
|
+
const source = normalise(registry);
|
|
100
|
+
const parts = templateParts(source);
|
|
101
|
+
if (!parts) {
|
|
102
|
+
return joinSource(source, `${name}.json`);
|
|
103
|
+
}
|
|
104
|
+
return `${parts.head}${parts.path.replaceAll(NAME, () => name)}${withQuery(
|
|
105
|
+
parts.query,
|
|
106
|
+
source.params
|
|
107
|
+
)}`;
|
|
108
|
+
}
|
|
109
|
+
function templateSibling(source, path) {
|
|
110
|
+
const parts = templateParts(source);
|
|
111
|
+
const dir = parts && templateDir(parts);
|
|
112
|
+
if (!(parts && dir !== null)) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return `${parts.head}${dir}/${path}${withQuery(parts.query, source.params)}`;
|
|
116
|
+
}
|
|
117
|
+
function registryCatalogueUrl(registry) {
|
|
118
|
+
const source = normalise(registry);
|
|
119
|
+
return templateSibling(source, "registry.json") ?? joinSource(source, "registry.json");
|
|
120
|
+
}
|
|
121
|
+
function registryDemosUrl(registry, name) {
|
|
122
|
+
const source = normalise(registry);
|
|
123
|
+
return templateSibling(source, `demos/${name}`) ?? joinSource(source, `demos/${name}`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/config.ts
|
|
127
|
+
var DEFAULT_DOCS_URL = "https://keystoneui.io";
|
|
128
|
+
var DEFAULT_REGISTRY_URL = `${DEFAULT_DOCS_URL}/r`;
|
|
129
|
+
function templateSource(entry) {
|
|
130
|
+
const params = entry.params && typeof entry.params === "object" ? Object.fromEntries(
|
|
131
|
+
Object.entries(entry.params).filter(
|
|
132
|
+
(pair) => typeof pair[1] === "string"
|
|
133
|
+
)
|
|
134
|
+
) : {};
|
|
135
|
+
return { url: entry.url, template: true, params };
|
|
136
|
+
}
|
|
137
|
+
function resolveDocsUrl() {
|
|
138
|
+
return process.env.KEYSTONEUI_URL ?? DEFAULT_DOCS_URL;
|
|
139
|
+
}
|
|
140
|
+
function loadProjectConfig() {
|
|
141
|
+
const docsUrl = resolveDocsUrl();
|
|
142
|
+
const derivedRegistry = docsUrl === DEFAULT_DOCS_URL ? { url: DEFAULT_REGISTRY_URL } : { url: docsRegistryUrl(docsUrl), docsUrl };
|
|
143
|
+
const registryUrlEnv = process.env.KEYSTONEUI_REGISTRY_URL;
|
|
144
|
+
if (registryUrlEnv) {
|
|
145
|
+
return { docsUrl, registry: { url: registryUrlEnv } };
|
|
146
|
+
}
|
|
147
|
+
const cwd = process.cwd();
|
|
148
|
+
const configPath = resolve(cwd, "components.json");
|
|
149
|
+
if (existsSync(configPath)) {
|
|
150
|
+
try {
|
|
151
|
+
const raw = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
152
|
+
const entry = raw?.registries?.["@keystoneui"];
|
|
153
|
+
if (typeof entry?.url === "string" && entry.url.includes("{name}")) {
|
|
154
|
+
return { docsUrl, registry: templateSource(entry) };
|
|
155
|
+
}
|
|
156
|
+
const registry = entry?.url === void 0 || entry?.url === null ? derivedRegistry : { url: entry.url };
|
|
157
|
+
return { docsUrl, registry };
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return { docsUrl, registry: derivedRegistry };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/package-version.ts
|
|
165
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
166
|
+
import { fileURLToPath } from "url";
|
|
167
|
+
function readPackageVersion() {
|
|
168
|
+
try {
|
|
169
|
+
const pkgPath = fileURLToPath(new URL("../package.json", import.meta.url));
|
|
170
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf-8"));
|
|
171
|
+
return pkg.version ?? "unknown";
|
|
172
|
+
} catch {
|
|
173
|
+
return "unknown";
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/tools.ts
|
|
178
|
+
import { z } from "zod";
|
|
179
|
+
|
|
180
|
+
// src/display-url.ts
|
|
181
|
+
import { inspect } from "util";
|
|
182
|
+
var DISPLAYED_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "file:"]);
|
|
183
|
+
var PATH_AFTER_AUTHORITY = /^[\0- ]*[a-z][a-z\d+.-]*:[/\\]{2}[^/\\?#]*[/\\]/i;
|
|
184
|
+
function displayUrl(raw) {
|
|
185
|
+
let url;
|
|
186
|
+
try {
|
|
187
|
+
url = new URL(raw);
|
|
188
|
+
} catch {
|
|
189
|
+
return "<unparseable URL>";
|
|
190
|
+
}
|
|
191
|
+
if (!DISPLAYED_PROTOCOLS.has(url.protocol)) {
|
|
192
|
+
return "<unsupported URL>";
|
|
193
|
+
}
|
|
194
|
+
if (!(url.username || url.password || url.search || url.hash)) {
|
|
195
|
+
return raw;
|
|
196
|
+
}
|
|
197
|
+
url.username = "";
|
|
198
|
+
url.password = "";
|
|
199
|
+
url.hash = "";
|
|
200
|
+
const keys = [...url.searchParams.keys()];
|
|
201
|
+
url.search = keys.map((key) => `${encodeURIComponent(key)}=REDACTED`).join("&");
|
|
202
|
+
if (url.host && url.pathname === "/" && !PATH_AFTER_AUTHORITY.test(raw)) {
|
|
203
|
+
return `${url.protocol}//${url.host}${url.search}`;
|
|
204
|
+
}
|
|
205
|
+
return url.href;
|
|
206
|
+
}
|
|
207
|
+
var LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
208
|
+
function wellFormed(text) {
|
|
209
|
+
return text.replace(LONE_SURROGATE, "\uFFFD");
|
|
210
|
+
}
|
|
211
|
+
function redactUrlInError(error, url) {
|
|
212
|
+
const forms = [.../* @__PURE__ */ new Set([url, wellFormed(url)])];
|
|
213
|
+
const full = inspect(error, { depth: 10 });
|
|
214
|
+
if (!forms.some((form) => full.includes(form))) {
|
|
215
|
+
return error;
|
|
216
|
+
}
|
|
217
|
+
const shown2 = displayUrl(url);
|
|
218
|
+
let message = error instanceof Error ? error.message : String(error ?? "Unknown error");
|
|
219
|
+
for (const form of forms) {
|
|
220
|
+
message = message.replaceAll(form, () => shown2);
|
|
221
|
+
}
|
|
222
|
+
return error instanceof TypeError ? new TypeError(message) : new Error(message);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/render.ts
|
|
226
|
+
var BREAK_OR_CONTROL = (
|
|
227
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: the characters escaped
|
|
228
|
+
/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g
|
|
229
|
+
);
|
|
230
|
+
var BREAK_OR_CONTROL_TEST = (
|
|
231
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: the characters tested
|
|
232
|
+
/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/
|
|
233
|
+
);
|
|
234
|
+
var LEADING_FENCE = /^( {0,3})([`~])(?=\2\2)/;
|
|
235
|
+
var BACKTICK_RUN = /`+/g;
|
|
236
|
+
var SHELL_SAFE = /^[A-Za-z0-9@%+=:,._/-]+$/;
|
|
237
|
+
function escapeChar(c) {
|
|
238
|
+
return `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`;
|
|
239
|
+
}
|
|
240
|
+
function shown(text) {
|
|
241
|
+
return String(text).replace(BREAK_OR_CONTROL, escapeChar).replace(
|
|
242
|
+
LEADING_FENCE,
|
|
243
|
+
(_, indent, mark) => `${indent}${escapeChar(mark)}`
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
function inlineCode(text) {
|
|
247
|
+
const safe = String(text).replace(BREAK_OR_CONTROL, escapeChar);
|
|
248
|
+
const fence = "`".repeat(longestBacktickRun(safe) + 1);
|
|
249
|
+
const pad = safe.startsWith("`") || safe.endsWith("`") ? " " : "";
|
|
250
|
+
return `${fence}${pad}${safe}${pad}${fence}`;
|
|
251
|
+
}
|
|
252
|
+
function isCommandSafe(text) {
|
|
253
|
+
return !BREAK_OR_CONTROL_TEST.test(text);
|
|
254
|
+
}
|
|
255
|
+
function shellWord(value) {
|
|
256
|
+
return SHELL_SAFE.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`;
|
|
257
|
+
}
|
|
258
|
+
function longestBacktickRun(text) {
|
|
259
|
+
return Math.max(
|
|
260
|
+
0,
|
|
261
|
+
...[...text.matchAll(BACKTICK_RUN)].map((run) => run[0].length)
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
function codeBlock(info, body, separator = "\n") {
|
|
265
|
+
const text = String(body);
|
|
266
|
+
const fence = "`".repeat(Math.max(3, longestBacktickRun(text) + 1));
|
|
267
|
+
const label = String(info).replace(BREAK_OR_CONTROL, escapeChar).replaceAll("`", "\\u0060");
|
|
268
|
+
return `${fence}${label}
|
|
269
|
+
${text}${separator}${fence}`;
|
|
270
|
+
}
|
|
271
|
+
var PIPE_AFTER_BACKSLASHES = /(\\*)\|/g;
|
|
272
|
+
function tableCell(rendered) {
|
|
273
|
+
return rendered.replace(
|
|
274
|
+
PIPE_AFTER_BACKSLASHES,
|
|
275
|
+
(match, slashes) => slashes.length % 2 === 0 ? `${slashes}\\|` : match
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
function needsEscape(error, seen) {
|
|
279
|
+
if (typeof error === "string") {
|
|
280
|
+
return shown(error) !== error;
|
|
281
|
+
}
|
|
282
|
+
if (!(error instanceof Error) || seen.has(error)) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
seen.add(error);
|
|
286
|
+
return shown(error.message) !== error.message || "cause" in error && needsEscape(error.cause, seen);
|
|
287
|
+
}
|
|
288
|
+
function escapedCopy(error, copies) {
|
|
289
|
+
if (typeof error === "string") {
|
|
290
|
+
return shown(error);
|
|
291
|
+
}
|
|
292
|
+
if (!(error instanceof Error)) {
|
|
293
|
+
return error;
|
|
294
|
+
}
|
|
295
|
+
const done = copies.get(error);
|
|
296
|
+
if (done) {
|
|
297
|
+
return done;
|
|
298
|
+
}
|
|
299
|
+
const copy = Object.create(Object.getPrototypeOf(error));
|
|
300
|
+
copies.set(error, copy);
|
|
301
|
+
for (const key of Reflect.ownKeys(error)) {
|
|
302
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, key);
|
|
303
|
+
if (descriptor) {
|
|
304
|
+
Object.defineProperty(copy, key, descriptor);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const message = shown(error.message);
|
|
308
|
+
Object.defineProperty(copy, "message", {
|
|
309
|
+
configurable: true,
|
|
310
|
+
value: message,
|
|
311
|
+
writable: true
|
|
312
|
+
});
|
|
313
|
+
if (typeof error.stack === "string") {
|
|
314
|
+
const head = `${error.name}: ${error.message}`;
|
|
315
|
+
Object.defineProperty(copy, "stack", {
|
|
316
|
+
configurable: true,
|
|
317
|
+
value: error.stack.startsWith(head) ? `${error.name}: ${message}${error.stack.slice(head.length)}` : shown(error.stack),
|
|
318
|
+
writable: true
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
if ("cause" in error) {
|
|
322
|
+
Object.defineProperty(copy, "cause", {
|
|
323
|
+
configurable: true,
|
|
324
|
+
value: escapedCopy(error.cause, copies),
|
|
325
|
+
writable: true
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return copy;
|
|
329
|
+
}
|
|
330
|
+
function escapedError(error) {
|
|
331
|
+
return needsEscape(error, /* @__PURE__ */ new Set()) ? escapedCopy(error, /* @__PURE__ */ new Map()) : error;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/fetcher.ts
|
|
335
|
+
var cache = /* @__PURE__ */ new Map();
|
|
336
|
+
var CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
337
|
+
var failedStatus = /* @__PURE__ */ new WeakMap();
|
|
338
|
+
function isNotFound(error) {
|
|
339
|
+
return typeof error === "object" && error !== null && failedStatus.get(error) === 404;
|
|
340
|
+
}
|
|
341
|
+
async function fetchJson(url, init) {
|
|
342
|
+
const cached = cache.get(url);
|
|
343
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
|
|
344
|
+
return cached.data;
|
|
345
|
+
}
|
|
346
|
+
let response;
|
|
347
|
+
try {
|
|
348
|
+
response = await (init ? fetch(url, init) : fetch(url));
|
|
349
|
+
} catch (error) {
|
|
350
|
+
throw escapedError(redactUrlInError(error, url));
|
|
351
|
+
}
|
|
352
|
+
if (!response.ok) {
|
|
353
|
+
const error = new Error(
|
|
354
|
+
`Failed to fetch ${shown(displayUrl(url))}: ${response.status}`
|
|
355
|
+
);
|
|
356
|
+
failedStatus.set(error, response.status);
|
|
357
|
+
throw error;
|
|
358
|
+
}
|
|
359
|
+
let data;
|
|
360
|
+
try {
|
|
361
|
+
data = await response.json();
|
|
362
|
+
} catch (error) {
|
|
363
|
+
throw escapedError(error);
|
|
364
|
+
}
|
|
365
|
+
cache.set(url, { data, timestamp: Date.now() });
|
|
366
|
+
return data;
|
|
367
|
+
}
|
|
368
|
+
function fetchManifest(registry) {
|
|
369
|
+
return fetchJson(registryCatalogueUrl(registry));
|
|
370
|
+
}
|
|
371
|
+
var LOOKUP_TIMEOUT_MS = 1e4;
|
|
372
|
+
async function lookupManifest(registry, ms = LOOKUP_TIMEOUT_MS) {
|
|
373
|
+
const url = registryCatalogueUrl(registry);
|
|
374
|
+
const controller = new AbortController();
|
|
375
|
+
let timer;
|
|
376
|
+
const timeout = new Promise((_, reject) => {
|
|
377
|
+
timer = setTimeout(() => {
|
|
378
|
+
controller.abort();
|
|
379
|
+
reject(new Error(`Timed out after ${ms} ms: ${shown(displayUrl(url))}`));
|
|
380
|
+
}, ms);
|
|
381
|
+
});
|
|
382
|
+
try {
|
|
383
|
+
const manifest = await Promise.race([
|
|
384
|
+
fetchJson(url, { signal: controller.signal }),
|
|
385
|
+
timeout
|
|
386
|
+
]);
|
|
387
|
+
if (!Array.isArray(manifest?.items)) {
|
|
388
|
+
throw new Error(`Not a registry index: ${shown(displayUrl(url))}`);
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
...manifest,
|
|
392
|
+
items: manifest.items.filter(
|
|
393
|
+
(item) => typeof item === "object" && item !== null && typeof item.name === "string"
|
|
394
|
+
)
|
|
395
|
+
};
|
|
396
|
+
} finally {
|
|
397
|
+
clearTimeout(timer);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function fetchItem(registry, name) {
|
|
401
|
+
return fetchJson(registryItemUrl(registry, name));
|
|
402
|
+
}
|
|
403
|
+
function fetchExamples(registry, name) {
|
|
404
|
+
return fetchJson(registryDemosUrl(registry, name));
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// src/item-meta.ts
|
|
408
|
+
var DOCS_POINTER = /^(\/docs\/[a-z0-9/-]+)(?:#([a-z0-9-]+))?$/;
|
|
409
|
+
function parseDocsPointer(value) {
|
|
410
|
+
if (typeof value !== "string") {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const match = DOCS_POINTER.exec(value);
|
|
414
|
+
if (!match) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
return match[2] ? { path: match[1], anchor: match[2] } : { path: match[1] };
|
|
418
|
+
}
|
|
419
|
+
function isRecord(value) {
|
|
420
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
421
|
+
}
|
|
422
|
+
function readMeta(item) {
|
|
423
|
+
const raw = isRecord(item) && isRecord(item.meta) ? item.meta.keystoneui : void 0;
|
|
424
|
+
if (!isRecord(raw)) {
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
const meta = {};
|
|
428
|
+
const docs = parseDocsPointer(raw.docs);
|
|
429
|
+
if (docs) {
|
|
430
|
+
meta.docs = docs;
|
|
431
|
+
}
|
|
432
|
+
if (typeof raw.flavourOf === "string" && raw.flavourOf !== "" && raw.flavourOf !== item.name) {
|
|
433
|
+
meta.flavourOf = raw.flavourOf;
|
|
434
|
+
}
|
|
435
|
+
if (typeof raw.minPackageVersion === "string" && raw.minPackageVersion) {
|
|
436
|
+
meta.minPackageVersion = raw.minPackageVersion;
|
|
437
|
+
}
|
|
438
|
+
if (Array.isArray(raw.partOf) && raw.partOf.length > 0 && raw.partOf.every((name) => typeof name === "string" && name !== "")) {
|
|
439
|
+
meta.partOf = raw.partOf;
|
|
440
|
+
}
|
|
441
|
+
return Object.keys(meta).length > 0 ? meta : null;
|
|
442
|
+
}
|
|
443
|
+
function packageFlavours(entries) {
|
|
444
|
+
const items = entries.filter((entry) => isRecord(entry));
|
|
445
|
+
const names = new Set(items.map((item) => item.name));
|
|
446
|
+
const flavours = /* @__PURE__ */ new Map();
|
|
447
|
+
for (const item of items) {
|
|
448
|
+
const parent = readMeta(item)?.flavourOf;
|
|
449
|
+
if (parent && names.has(parent) && !flavours.has(parent)) {
|
|
450
|
+
flavours.set(parent, item.name);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return flavours;
|
|
454
|
+
}
|
|
455
|
+
function pointerUrl(docsUrl, pointer) {
|
|
456
|
+
const page = displayUrl(docsResourceUrl(docsUrl, pointer.path.slice(1)));
|
|
457
|
+
return pointer.anchor ? `${page}#${pointer.anchor}` : page;
|
|
458
|
+
}
|
|
459
|
+
function metaLines(item, docsUrl, flavours) {
|
|
460
|
+
const meta = readMeta(item);
|
|
461
|
+
const lines = [];
|
|
462
|
+
if (meta && item.type === "registry:component") {
|
|
463
|
+
lines.push("Kind: kit");
|
|
464
|
+
}
|
|
465
|
+
if (meta?.partOf) {
|
|
466
|
+
lines.push(`Part of: ${meta.partOf.map(shown).join(", ")}`);
|
|
467
|
+
}
|
|
468
|
+
if (meta?.flavourOf) {
|
|
469
|
+
lines.push(
|
|
470
|
+
`Flavour of: ${shown(meta.flavourOf)} \u2014 for apps that use the @keystoneui/react package`
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
if (meta?.minPackageVersion) {
|
|
474
|
+
lines.push(
|
|
475
|
+
`Needs @keystoneui/react ${shown(meta.minPackageVersion)} or later`
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
const flavour = flavours?.get(item.name);
|
|
479
|
+
if (flavour) {
|
|
480
|
+
lines.push(`Package flavour: ${shown(flavour)}`);
|
|
481
|
+
}
|
|
482
|
+
if (meta?.docs) {
|
|
483
|
+
lines.push(`Docs: ${shown(pointerUrl(docsUrl, meta.docs))}`);
|
|
484
|
+
}
|
|
485
|
+
return lines;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// src/theme.ts
|
|
489
|
+
var THEME_CODE_RE = /^k1_([a-z]+)_(\d+(?:\.\d+)?)_(\d+(?:\.\d+)?)_(\d+(?:\.\d+)?)_([a-z]+)_([a-z-]+)$/;
|
|
490
|
+
function parseThemeCode(code) {
|
|
491
|
+
const match = THEME_CODE_RE.exec(code);
|
|
492
|
+
if (!match) {
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
const [, base, l, c, h, radius, font] = match;
|
|
496
|
+
return { base, font, primary: `oklch(${l} ${c} ${h})`, radius };
|
|
497
|
+
}
|
|
498
|
+
function themeInstallUrl(code, siteUrl, only = []) {
|
|
499
|
+
const query = only.length > 0 ? `?only=${only.join(",")}` : "";
|
|
500
|
+
return `${siteUrl}/r/theme/${code}.json${query}`;
|
|
501
|
+
}
|
|
502
|
+
function themeInstallCommand(code, siteUrl, only = []) {
|
|
503
|
+
return `npx shadcn@latest add ${shellWord(themeInstallUrl(code, siteUrl, only))}`;
|
|
504
|
+
}
|
|
505
|
+
function themeBuilderUrl(code, siteUrl) {
|
|
506
|
+
const match = THEME_CODE_RE.exec(code);
|
|
507
|
+
if (!match) {
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
510
|
+
const [, base, primaryL, primaryC, primaryH, radius, font] = match;
|
|
511
|
+
const params = new URLSearchParams({
|
|
512
|
+
base,
|
|
513
|
+
primaryL,
|
|
514
|
+
primaryC,
|
|
515
|
+
primaryH,
|
|
516
|
+
radius,
|
|
517
|
+
font
|
|
518
|
+
});
|
|
519
|
+
return `${siteUrl}/theme-builder?${params}`;
|
|
520
|
+
}
|
|
521
|
+
function parseThemeParts(value) {
|
|
522
|
+
if (!value) {
|
|
523
|
+
return [];
|
|
524
|
+
}
|
|
525
|
+
return value.split(",").map((part) => part.trim()).filter((part) => part === "theme" || part === "font");
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// src/item-name.ts
|
|
529
|
+
var CONTROL = /[\u0000-\u001f\u007f]/;
|
|
530
|
+
var ENCODED_DOT = /%2e/gi;
|
|
531
|
+
var TRAILING_SPACES = / +$/;
|
|
532
|
+
var ONLY_PARAM = /^(.*?)\?only=([^&#]*)/s;
|
|
533
|
+
var THEME_CODE = /^theme\/(.+)$/s;
|
|
534
|
+
var THEME_PARTS = /* @__PURE__ */ new Set(["theme", "font", "theme,font", "font,theme"]);
|
|
535
|
+
function shownName(name) {
|
|
536
|
+
return shown(name);
|
|
537
|
+
}
|
|
538
|
+
function isDotSegment(segment) {
|
|
539
|
+
const decoded = segment.replace(ENCODED_DOT, ".");
|
|
540
|
+
return decoded === "." || decoded === "..";
|
|
541
|
+
}
|
|
542
|
+
function invalidReason(name) {
|
|
543
|
+
if (name === "") {
|
|
544
|
+
return "empty name";
|
|
545
|
+
}
|
|
546
|
+
if (CONTROL.test(name)) {
|
|
547
|
+
return "control character";
|
|
548
|
+
}
|
|
549
|
+
if (name.includes("?")) {
|
|
550
|
+
return "query delimiter `?`";
|
|
551
|
+
}
|
|
552
|
+
if (name.includes("#")) {
|
|
553
|
+
return "fragment delimiter `#`";
|
|
554
|
+
}
|
|
555
|
+
if (name.includes("\\")) {
|
|
556
|
+
return "backslash, read as a path separator";
|
|
557
|
+
}
|
|
558
|
+
const segments = name.split("/");
|
|
559
|
+
if (segments.some((segment) => segment === "")) {
|
|
560
|
+
return "empty path segment";
|
|
561
|
+
}
|
|
562
|
+
if (segments.some(isDotSegment)) {
|
|
563
|
+
return "dot segment";
|
|
564
|
+
}
|
|
565
|
+
const last = (segments.at(-1) ?? "").replace(TRAILING_SPACES, "");
|
|
566
|
+
if (last === "") {
|
|
567
|
+
return "empty path segment";
|
|
568
|
+
}
|
|
569
|
+
if (isDotSegment(last)) {
|
|
570
|
+
return "dot segment";
|
|
571
|
+
}
|
|
572
|
+
return null;
|
|
573
|
+
}
|
|
574
|
+
function onlyMessage(name) {
|
|
575
|
+
const match = ONLY_PARAM.exec(name);
|
|
576
|
+
if (!match || CONTROL.test(name)) {
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
const [, base, only] = match;
|
|
580
|
+
const code = THEME_CODE.exec(base)?.[1];
|
|
581
|
+
const cli = code && parseThemeCode(code) && THEME_PARTS.has(only) ? ` (CLI: keystoneui theme ${shellWord(code)} --only ${shellWord(only)})` : "";
|
|
582
|
+
return `**${shown(name)}**: ?only is not part of a name: get the command for ${shown(base)}, then append ?only=${shown(only)} to the printed URL${cli}.`;
|
|
583
|
+
}
|
|
584
|
+
function nameRefusal(name, label = "") {
|
|
585
|
+
const reason = invalidReason(name);
|
|
586
|
+
if (reason === null) {
|
|
587
|
+
return null;
|
|
588
|
+
}
|
|
589
|
+
return (label ? null : onlyMessage(name)) ?? `**${shownName(name)}**${label}: not a valid registry item name (${reason}).`;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// src/docs.ts
|
|
593
|
+
var PARENT_SECTION = {
|
|
594
|
+
"registry:block": "blocks",
|
|
595
|
+
"registry:ui": "components"
|
|
596
|
+
};
|
|
597
|
+
function docsPageUrl(docsUrl, path) {
|
|
598
|
+
return `${docsUrl}/llms.mdx${path}`;
|
|
599
|
+
}
|
|
600
|
+
async function pointerFor(config, name) {
|
|
601
|
+
let items;
|
|
602
|
+
try {
|
|
603
|
+
items = (await lookupManifest(config.registry)).items;
|
|
604
|
+
} catch {
|
|
605
|
+
return null;
|
|
606
|
+
}
|
|
607
|
+
const item = items.find((candidate) => candidate.name === name);
|
|
608
|
+
const meta = item && readMeta(item);
|
|
609
|
+
if (!meta) {
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
if (meta.docs) {
|
|
613
|
+
return meta.docs;
|
|
614
|
+
}
|
|
615
|
+
const parent = meta.flavourOf && items.find((candidate) => candidate.name === meta.flavourOf);
|
|
616
|
+
if (!parent) {
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
619
|
+
const parentMeta = readMeta(parent);
|
|
620
|
+
if (parentMeta?.docs) {
|
|
621
|
+
return parentMeta.docs;
|
|
622
|
+
}
|
|
623
|
+
const section = Object.hasOwn(PARENT_SECTION, parent.type) ? PARENT_SECTION[parent.type] : void 0;
|
|
624
|
+
return section && nameRefusal(parent.name) === null ? { path: `/docs/${section}/${parent.name}` } : null;
|
|
625
|
+
}
|
|
626
|
+
async function resolveDocs(config, name, section, init) {
|
|
627
|
+
const url = docsPageUrl(config.docsUrl, `/docs/${section}/${name}`);
|
|
628
|
+
let response;
|
|
629
|
+
let text;
|
|
630
|
+
try {
|
|
631
|
+
response = await fetch(url, init());
|
|
632
|
+
if (response.ok) {
|
|
633
|
+
text = await response.text();
|
|
634
|
+
return { kind: "page", text };
|
|
635
|
+
}
|
|
636
|
+
} catch (error) {
|
|
637
|
+
return { kind: "unreachable", error, url };
|
|
638
|
+
}
|
|
639
|
+
const notFound = {
|
|
640
|
+
kind: "status",
|
|
641
|
+
status: response.status,
|
|
642
|
+
statusText: response.statusText,
|
|
643
|
+
url
|
|
644
|
+
};
|
|
645
|
+
if (response.status !== 404) {
|
|
646
|
+
return notFound;
|
|
647
|
+
}
|
|
648
|
+
const pointer = await pointerFor(config, name);
|
|
649
|
+
if (!pointer) {
|
|
650
|
+
return notFound;
|
|
651
|
+
}
|
|
652
|
+
try {
|
|
653
|
+
const pointed = await fetch(
|
|
654
|
+
// A new request: composed into the docs URL (registry-url.ts).
|
|
655
|
+
docsResourceUrl(config.docsUrl, `llms.mdx${pointer.path}`),
|
|
656
|
+
init()
|
|
657
|
+
);
|
|
658
|
+
if (!pointed.ok) {
|
|
659
|
+
return notFound;
|
|
660
|
+
}
|
|
661
|
+
const where = pointer.anchor ? `section #${shown(pointer.anchor)} of ${shown(pointer.path)}` : shown(pointer.path);
|
|
662
|
+
return {
|
|
663
|
+
kind: "page",
|
|
664
|
+
text: `Documented in ${where}.
|
|
665
|
+
|
|
666
|
+
${await pointed.text()}`
|
|
667
|
+
};
|
|
668
|
+
} catch {
|
|
669
|
+
return notFound;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// src/project-context.ts
|
|
674
|
+
import { existsSync as existsSync2, readFileSync as readFileSync3 } from "fs";
|
|
675
|
+
import { resolve as resolve2 } from "path";
|
|
676
|
+
function readJson(path) {
|
|
677
|
+
if (!existsSync2(path)) {
|
|
678
|
+
return null;
|
|
679
|
+
}
|
|
680
|
+
try {
|
|
681
|
+
return JSON.parse(readFileSync3(path, "utf-8"));
|
|
682
|
+
} catch {
|
|
683
|
+
return null;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
function detectPackageManager(cwd, manifest) {
|
|
687
|
+
const declared = manifest?.packageManager;
|
|
688
|
+
if (typeof declared === "string" && declared.length > 0) {
|
|
689
|
+
return declared.split("@")[0];
|
|
690
|
+
}
|
|
691
|
+
const lockfiles = [
|
|
692
|
+
["pnpm-lock.yaml", "pnpm"],
|
|
693
|
+
["bun.lock", "bun"],
|
|
694
|
+
["bun.lockb", "bun"],
|
|
695
|
+
["yarn.lock", "yarn"],
|
|
696
|
+
["package-lock.json", "npm"]
|
|
697
|
+
];
|
|
698
|
+
for (const [file, name] of lockfiles) {
|
|
699
|
+
if (existsSync2(resolve2(cwd, file))) {
|
|
700
|
+
return name;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return null;
|
|
704
|
+
}
|
|
705
|
+
function detectProjectContext(cwd = process.cwd()) {
|
|
706
|
+
const manifest = readJson(resolve2(cwd, "package.json"));
|
|
707
|
+
const components = readJson(resolve2(cwd, "components.json"));
|
|
708
|
+
const deps = {
|
|
709
|
+
...manifest?.dependencies,
|
|
710
|
+
...manifest?.devDependencies
|
|
711
|
+
};
|
|
712
|
+
const keystoneVersion = deps["@keystoneui/react"] ?? null;
|
|
713
|
+
let installMode = "unknown";
|
|
714
|
+
if (keystoneVersion) {
|
|
715
|
+
installMode = "package";
|
|
716
|
+
} else if (components) {
|
|
717
|
+
installMode = "registry";
|
|
718
|
+
}
|
|
719
|
+
const tailwind = components?.tailwind;
|
|
720
|
+
const css = tailwind?.css;
|
|
721
|
+
return {
|
|
722
|
+
installMode,
|
|
723
|
+
aliases: components?.aliases ?? null,
|
|
724
|
+
tailwindCssFile: typeof css === "string" && css.length > 0 ? css : null,
|
|
725
|
+
iconLibrary: typeof components?.iconLibrary === "string" ? components.iconLibrary : null,
|
|
726
|
+
isRSC: typeof components?.rsc === "boolean" ? components.rsc : null,
|
|
727
|
+
packageManager: detectPackageManager(cwd, manifest),
|
|
728
|
+
keystoneVersion
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
function importLineFor(name, ctx) {
|
|
732
|
+
if (ctx.installMode === "registry") {
|
|
733
|
+
const ui = ctx.aliases?.ui ?? "@/components/ui";
|
|
734
|
+
return `import { \u2026 } from "${ui}/${name}";`;
|
|
735
|
+
}
|
|
736
|
+
return `import { \u2026 } from "@keystoneui/react/${name}";`;
|
|
737
|
+
}
|
|
738
|
+
function describeInstallMode(ctx) {
|
|
739
|
+
if (ctx.installMode === "package") {
|
|
740
|
+
const version = ctx.keystoneVersion ? ` (${shown(String(ctx.keystoneVersion))})` : "";
|
|
741
|
+
return `**package** -- \`@keystoneui/react\`${version} is a dependency. Import from subpaths.`;
|
|
742
|
+
}
|
|
743
|
+
if (ctx.installMode === "registry") {
|
|
744
|
+
const ui = ctx.aliases?.ui ?? "@/components/ui";
|
|
745
|
+
return `**registry** -- source is vendored via shadcn. Import from ${inlineCode(String(ui))}.`;
|
|
746
|
+
}
|
|
747
|
+
return "**unknown** -- neither `@keystoneui/react` in dependencies nor a `components.json`. Ask before writing imports.";
|
|
748
|
+
}
|
|
749
|
+
function describeRsc(isRSC) {
|
|
750
|
+
if (isRSC === null) {
|
|
751
|
+
return "_unknown_";
|
|
752
|
+
}
|
|
753
|
+
return isRSC ? 'yes -- interactive files need `"use client"`' : "no";
|
|
754
|
+
}
|
|
755
|
+
function valueOr(value, fallback) {
|
|
756
|
+
return value === null || value === void 0 ? fallback : shown(String(value));
|
|
757
|
+
}
|
|
758
|
+
function formatProjectContext(ctx) {
|
|
759
|
+
const rows = [
|
|
760
|
+
`| install mode | ${tableCell(describeInstallMode(ctx))} |`,
|
|
761
|
+
`| ui alias | ${tableCell(valueOr(ctx.aliases?.ui, "_unknown_"))} |`,
|
|
762
|
+
`| theme CSS file | ${tableCell(valueOr(ctx.tailwindCssFile, "_unknown_ -- ask which file owns the tokens"))} |`,
|
|
763
|
+
`| icon library | ${tableCell(valueOr(ctx.iconLibrary, "_unknown_ -- ask before importing icons"))} |`,
|
|
764
|
+
`| RSC | ${tableCell(describeRsc(ctx.isRSC))} |`,
|
|
765
|
+
`| package manager | ${tableCell(valueOr(ctx.packageManager, "_unknown_"))} |`
|
|
766
|
+
];
|
|
767
|
+
const lines = [
|
|
768
|
+
"# Project context",
|
|
769
|
+
"",
|
|
770
|
+
"| field | value |",
|
|
771
|
+
"|---|---|",
|
|
772
|
+
...rows,
|
|
773
|
+
"",
|
|
774
|
+
`Example import: ${inlineCode(importLineFor("button", ctx))}`
|
|
775
|
+
];
|
|
776
|
+
if (ctx.installMode === "package") {
|
|
777
|
+
lines.push(PACKAGE_INSTALL_ADVICE);
|
|
778
|
+
}
|
|
779
|
+
return lines.join("\n");
|
|
780
|
+
}
|
|
781
|
+
var PACKAGE_INSTALL_ADVICE = `Installing a block or kit: pass flavour: "package" to get_add_command; it uses the registry's package flavour where one exists, and vendors source where none does.`;
|
|
782
|
+
|
|
783
|
+
// src/search.ts
|
|
784
|
+
import fuzzysort from "fuzzysort";
|
|
785
|
+
function applyFilters(items, type, category) {
|
|
786
|
+
let filtered = items;
|
|
787
|
+
if (type) {
|
|
788
|
+
filtered = filtered.filter((i) => i.type === `registry:${type}`);
|
|
789
|
+
}
|
|
790
|
+
if (category) {
|
|
791
|
+
filtered = filtered.filter((i) => i.categories?.includes(category));
|
|
792
|
+
}
|
|
793
|
+
return filtered;
|
|
794
|
+
}
|
|
795
|
+
function searchItems(manifest, query, opts = {}) {
|
|
796
|
+
const { limit = 20, offset = 0, type, category } = opts;
|
|
797
|
+
const items = applyFilters(manifest.items, type, category);
|
|
798
|
+
const targets = items.map((item) => ({
|
|
799
|
+
item,
|
|
800
|
+
searchable: `${item.name} ${item.title ?? ""} ${item.description ?? ""} ${(item.categories ?? []).join(" ")}`
|
|
801
|
+
}));
|
|
802
|
+
const results = fuzzysort.go(query, targets, {
|
|
803
|
+
key: "searchable",
|
|
804
|
+
threshold: -1e4
|
|
805
|
+
}).map((r) => ({ item: r.obj.item, score: r.score }));
|
|
806
|
+
return {
|
|
807
|
+
results: results.slice(offset, offset + limit),
|
|
808
|
+
total: results.length
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
function listItems(manifest, opts = {}) {
|
|
812
|
+
const { limit = 20, offset = 0, type, category } = opts;
|
|
813
|
+
const items = applyFilters(manifest.items, type, category);
|
|
814
|
+
return {
|
|
815
|
+
items: items.slice(offset, offset + limit),
|
|
816
|
+
total: items.length
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// src/tools.ts
|
|
821
|
+
function formatItemSummary(item, extra = []) {
|
|
822
|
+
const parts = [
|
|
823
|
+
`**${shown(item.title ?? item.name)}** (${inlineCode(item.name)})`
|
|
824
|
+
];
|
|
825
|
+
if (item.description) {
|
|
826
|
+
parts.push(shown(item.description));
|
|
827
|
+
}
|
|
828
|
+
if (item.categories?.length) {
|
|
829
|
+
parts.push(`Categories: ${item.categories.map(shown).join(", ")}`);
|
|
830
|
+
}
|
|
831
|
+
if (item.dependencies?.length) {
|
|
832
|
+
parts.push(`Dependencies: ${item.dependencies.map(shown).join(", ")}`);
|
|
833
|
+
}
|
|
834
|
+
if (item.registryDependencies?.length) {
|
|
835
|
+
parts.push(
|
|
836
|
+
`Registry dependencies: ${item.registryDependencies.map(shown).join(", ")}`
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
parts.push(...extra);
|
|
840
|
+
return parts.join("\n");
|
|
841
|
+
}
|
|
842
|
+
function formatItemDetail(item, docsUrl) {
|
|
843
|
+
const sections = [formatItemSummary(item, metaLines(item, docsUrl))];
|
|
844
|
+
if (item.files?.length) {
|
|
845
|
+
for (const file of item.files) {
|
|
846
|
+
if (file.content) {
|
|
847
|
+
const body = String(file.content);
|
|
848
|
+
const separator = body.endsWith("\n") || body.endsWith("\r") ? "" : "\n";
|
|
849
|
+
sections.push(
|
|
850
|
+
`### ${shown(file.path)}
|
|
851
|
+
${codeBlock("tsx", body, separator)}`
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
return sections.join("\n\n");
|
|
857
|
+
}
|
|
858
|
+
var ITEM_TYPES = [
|
|
859
|
+
"ui",
|
|
860
|
+
"block",
|
|
861
|
+
"example",
|
|
862
|
+
"kit",
|
|
863
|
+
"style",
|
|
864
|
+
"theme",
|
|
865
|
+
"item"
|
|
866
|
+
];
|
|
867
|
+
function registryType(type) {
|
|
868
|
+
return type === "kit" ? "component" : type;
|
|
869
|
+
}
|
|
870
|
+
function formatEntries(items, allItems, docsUrl) {
|
|
871
|
+
const flavours = packageFlavours(allItems);
|
|
872
|
+
return items.map(
|
|
873
|
+
(item) => formatItemSummary(item, metaLines(item, docsUrl, flavours))
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
var listComponentsSchema = z.object({
|
|
877
|
+
limit: z.number().min(1).max(100).default(20).describe("Maximum number of items to return"),
|
|
878
|
+
offset: z.number().min(0).default(0).describe("Number of items to skip"),
|
|
879
|
+
type: z.enum(ITEM_TYPES).optional().describe(
|
|
880
|
+
"Filter by item type: 'ui' for components, 'block' for full-page blocks, 'example' for named demo variants like 'table-with-pagination', 'kit' for pieces taken from a block and installable on their own (such as 'sidebar' or 'filter-pills'), and 'style' | 'theme' | 'item' for those registry types"
|
|
881
|
+
),
|
|
882
|
+
category: z.string().optional().describe(
|
|
883
|
+
"Filter by category (e.g. 'authentication', 'login', 'signup', 'navigation', 'data', 'dashboard', 'admin', 'betting'). Blocks and kits carry categories; components and examples do not."
|
|
884
|
+
)
|
|
885
|
+
});
|
|
886
|
+
async function listComponentsTool(config, input) {
|
|
887
|
+
const manifest = await fetchManifest(config.registry);
|
|
888
|
+
const { items, total } = listItems(manifest, {
|
|
889
|
+
...input,
|
|
890
|
+
type: registryType(input.type)
|
|
891
|
+
});
|
|
892
|
+
const lines = formatEntries(items, manifest.items, config.docsUrl);
|
|
893
|
+
lines.push(`
|
|
894
|
+
---
|
|
895
|
+
Showing ${items.length} of ${total} items.`);
|
|
896
|
+
if (input.offset + items.length < total) {
|
|
897
|
+
lines.push(`Use offset: ${input.offset + items.length} to see more.`);
|
|
898
|
+
}
|
|
899
|
+
return lines.join("\n\n");
|
|
900
|
+
}
|
|
901
|
+
var searchComponentsSchema = z.object({
|
|
902
|
+
query: z.string().describe("Search query (name, description, or keywords)"),
|
|
903
|
+
limit: z.number().min(1).max(50).default(10).describe("Maximum number of results"),
|
|
904
|
+
type: z.enum(ITEM_TYPES).optional().describe(
|
|
905
|
+
"Filter by item type: 'ui' for components, 'block' for full-page blocks, 'example' for named demo variants, 'kit' for pieces taken from a block and installable on their own, and 'style' | 'theme' | 'item' for those registry types"
|
|
906
|
+
),
|
|
907
|
+
category: z.string().optional().describe(
|
|
908
|
+
"Filter by category (e.g. 'authentication', 'login'). Blocks and kits carry categories; components and examples do not."
|
|
909
|
+
)
|
|
910
|
+
});
|
|
911
|
+
async function searchComponentsTool(config, input) {
|
|
912
|
+
const manifest = await fetchManifest(config.registry);
|
|
913
|
+
const { results, total } = searchItems(manifest, input.query, {
|
|
914
|
+
limit: input.limit,
|
|
915
|
+
type: registryType(input.type),
|
|
916
|
+
category: input.category
|
|
917
|
+
});
|
|
918
|
+
if (results.length === 0) {
|
|
919
|
+
return `No results found for "${shown(input.query)}".`;
|
|
920
|
+
}
|
|
921
|
+
const lines = formatEntries(
|
|
922
|
+
results.map((r) => r.item),
|
|
923
|
+
manifest.items,
|
|
924
|
+
config.docsUrl
|
|
925
|
+
);
|
|
926
|
+
lines.push(`
|
|
927
|
+
---
|
|
928
|
+
${total} result${total === 1 ? "" : "s"} found.`);
|
|
929
|
+
return lines.join("\n\n");
|
|
930
|
+
}
|
|
931
|
+
var viewComponentSchema = z.object({
|
|
932
|
+
names: z.array(z.string()).min(1).max(5).describe(
|
|
933
|
+
'Names of components, blocks, kits, or package flavours to view (e.g. ["button", "users-01", "sidebar", "npm/users-01"]). Returns full source code.'
|
|
934
|
+
)
|
|
935
|
+
});
|
|
936
|
+
async function viewComponentTool(config, input) {
|
|
937
|
+
const results = await Promise.all(
|
|
938
|
+
input.names.map(async (name) => {
|
|
939
|
+
const refusal = nameRefusal(name);
|
|
940
|
+
if (refusal) {
|
|
941
|
+
return refusal;
|
|
942
|
+
}
|
|
943
|
+
try {
|
|
944
|
+
const item = await fetchItem(config.registry, name);
|
|
945
|
+
return formatItemDetail(item, config.docsUrl);
|
|
946
|
+
} catch {
|
|
947
|
+
return `**${shown(name)}**: Not found in registry.`;
|
|
948
|
+
}
|
|
949
|
+
})
|
|
950
|
+
);
|
|
951
|
+
return results.join("\n\n---\n\n");
|
|
952
|
+
}
|
|
953
|
+
var getAddCommandSchema = z.object({
|
|
954
|
+
names: z.array(z.string()).min(1).max(20).describe(
|
|
955
|
+
"Names of components, blocks, or kits to generate install commands for (a package flavour such as `npm/users-01` may be named directly)"
|
|
956
|
+
),
|
|
957
|
+
flavour: z.enum(["vendored", "package"]).optional().describe(
|
|
958
|
+
"'package' for a project that uses the @keystoneui/react package (get_project_context install mode `package`): installs a block's or kit's package flavour where the registry has one, and names the components to import from the package instead. Omitted or 'vendored': the commands for the names as given, with no lookup. Spelled `flavour`."
|
|
959
|
+
)
|
|
960
|
+
});
|
|
961
|
+
function installText(urls) {
|
|
962
|
+
const unsafe = urls.filter((url) => !isCommandSafe(url));
|
|
963
|
+
if (unsafe.length > 0) {
|
|
964
|
+
return `No install command: ${unsafe.map((url) => shown(displayUrl(url))).join(
|
|
965
|
+
", "
|
|
966
|
+
)} holds a line break or control character, so it cannot be printed as a command.`;
|
|
967
|
+
}
|
|
968
|
+
const words = urls.map(shellWord);
|
|
969
|
+
return [
|
|
970
|
+
"Install these components with the shadcn CLI:",
|
|
971
|
+
"",
|
|
972
|
+
codeBlock("bash", `npx shadcn@latest add ${words.join(" ")}`),
|
|
973
|
+
"",
|
|
974
|
+
"Or install individually:",
|
|
975
|
+
"",
|
|
976
|
+
...words.map((word) => codeBlock("bash", `npx shadcn@latest add ${word}`))
|
|
977
|
+
].join("\n");
|
|
978
|
+
}
|
|
979
|
+
var REFUSED_HEADER = "No install command: every name must be a registry item name.";
|
|
980
|
+
function getAddCommandTool(config, input) {
|
|
981
|
+
const refusals = input.names.map((name) => nameRefusal(name)).filter((refusal) => refusal !== null);
|
|
982
|
+
if (refusals.length > 0) {
|
|
983
|
+
return [REFUSED_HEADER, ...refusals.map((r) => `- ${r}`)].join("\n");
|
|
984
|
+
}
|
|
985
|
+
if (input.flavour === "package") {
|
|
986
|
+
return packageAddCommand(config, input.names);
|
|
987
|
+
}
|
|
988
|
+
return installText(
|
|
989
|
+
input.names.map((name) => registryItemUrl(config.registry, name))
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
var VENDORS_SOURCE = "No package flavour: this vendors source that imports from your ui alias, beside the package.";
|
|
993
|
+
var VENDORED_TYPES = /* @__PURE__ */ new Set([
|
|
994
|
+
"registry:block",
|
|
995
|
+
"registry:component",
|
|
996
|
+
"registry:example"
|
|
997
|
+
]);
|
|
998
|
+
function versionNote(minVersion, declared) {
|
|
999
|
+
return minVersion ? ` Needs @keystoneui/react ${shown(minVersion)} or later; ${declared}.` : "";
|
|
1000
|
+
}
|
|
1001
|
+
function pickTarget(name, items, flavours, declared) {
|
|
1002
|
+
const item = items.get(name);
|
|
1003
|
+
if (!item) {
|
|
1004
|
+
return {
|
|
1005
|
+
line: `${inlineCode(name)}: Not in the registry index; command composed from the name.`,
|
|
1006
|
+
target: name
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
const meta = readMeta(item);
|
|
1010
|
+
if (meta?.flavourOf) {
|
|
1011
|
+
return {
|
|
1012
|
+
line: `${inlineCode(name)}: package flavour of ${inlineCode(meta.flavourOf)}.${versionNote(meta.minPackageVersion, declared)}`,
|
|
1013
|
+
target: name
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
const flavour = flavours.get(name);
|
|
1017
|
+
if (flavour) {
|
|
1018
|
+
const refusal = nameRefusal(
|
|
1019
|
+
flavour,
|
|
1020
|
+
` (the package flavour of ${shown(name)})`
|
|
1021
|
+
);
|
|
1022
|
+
const flavourMeta = readMeta(items.get(flavour));
|
|
1023
|
+
return {
|
|
1024
|
+
line: `${inlineCode(name)} \u2192 ${inlineCode(flavour)} (package flavour).${versionNote(flavourMeta?.minPackageVersion, declared)}`,
|
|
1025
|
+
target: flavour,
|
|
1026
|
+
...refusal ? { refusal } : {}
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
if (item.type === "registry:ui") {
|
|
1030
|
+
return {
|
|
1031
|
+
line: `${shown(name)} is a component. If @keystoneui/react provides it, import it from "@keystoneui/react/${shown(name)}" instead of installing it.`
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
if (VENDORED_TYPES.has(item.type)) {
|
|
1035
|
+
return { line: `${inlineCode(name)}: ${VENDORS_SOURCE}`, target: name };
|
|
1036
|
+
}
|
|
1037
|
+
return {
|
|
1038
|
+
line: `${inlineCode(name)}: a ${shown(String(item.type))} item, installed as named.`,
|
|
1039
|
+
target: name
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
async function packageAddCommand(config, names) {
|
|
1043
|
+
let allItems;
|
|
1044
|
+
try {
|
|
1045
|
+
allItems = (await lookupManifest(config.registry)).items;
|
|
1046
|
+
} catch {
|
|
1047
|
+
const index = shown(displayUrl(registryCatalogueUrl(config.registry)));
|
|
1048
|
+
return `Could not read the registry index (${index}); names kept as supplied; package-flavour selection could not be checked.
|
|
1049
|
+
|
|
1050
|
+
${installText(
|
|
1051
|
+
names.map((name) => registryItemUrl(config.registry, name))
|
|
1052
|
+
)}`;
|
|
1053
|
+
}
|
|
1054
|
+
const { keystoneVersion } = detectProjectContext();
|
|
1055
|
+
const declared = keystoneVersion ? `package.json declares ${shown(keystoneVersion)}` : "package.json declares no @keystoneui/react dependency";
|
|
1056
|
+
const items = /* @__PURE__ */ new Map();
|
|
1057
|
+
for (const item of allItems) {
|
|
1058
|
+
if (!items.has(item.name)) {
|
|
1059
|
+
items.set(item.name, item);
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
const flavours = packageFlavours(allItems);
|
|
1063
|
+
const picks = names.map(
|
|
1064
|
+
(name) => pickTarget(name, items, flavours, declared)
|
|
1065
|
+
);
|
|
1066
|
+
const refusals = picks.flatMap(
|
|
1067
|
+
(pick) => pick.refusal ? [`- ${pick.refusal}`] : []
|
|
1068
|
+
);
|
|
1069
|
+
if (refusals.length > 0) {
|
|
1070
|
+
return [REFUSED_HEADER, ...refusals].join("\n");
|
|
1071
|
+
}
|
|
1072
|
+
const targets = [
|
|
1073
|
+
...new Set(picks.flatMap((pick) => pick.target ? [pick.target] : []))
|
|
1074
|
+
];
|
|
1075
|
+
const perName = picks.map((pick) => `- ${pick.line}`).join("\n");
|
|
1076
|
+
if (targets.length === 0) {
|
|
1077
|
+
return `${perName}
|
|
1078
|
+
|
|
1079
|
+
No install command: none of these names is installed with flavour: "package".`;
|
|
1080
|
+
}
|
|
1081
|
+
return `${perName}
|
|
1082
|
+
|
|
1083
|
+
${installText(
|
|
1084
|
+
targets.map((target) => registryItemUrl(config.registry, target))
|
|
1085
|
+
)}`;
|
|
1086
|
+
}
|
|
1087
|
+
var getExamplesSchema = z.object({
|
|
1088
|
+
name: z.string().describe(
|
|
1089
|
+
'Component, block, kit, or package flavour name (e.g. "button", "signin-01", "tickets-01", "sidebar")'
|
|
1090
|
+
)
|
|
1091
|
+
});
|
|
1092
|
+
async function getExamplesTool(config, input) {
|
|
1093
|
+
const refusal = nameRefusal(input.name);
|
|
1094
|
+
if (refusal) {
|
|
1095
|
+
return refusal;
|
|
1096
|
+
}
|
|
1097
|
+
try {
|
|
1098
|
+
const bundle = await fetchExamples(config.registry, input.name);
|
|
1099
|
+
if (!bundle.files.length) {
|
|
1100
|
+
return `**${shown(input.name)}**: no example files found.`;
|
|
1101
|
+
}
|
|
1102
|
+
const sections = [
|
|
1103
|
+
`# ${shown(input.name)} examples`,
|
|
1104
|
+
`${bundle.files.length} file${bundle.files.length === 1 ? "" : "s"}:`,
|
|
1105
|
+
""
|
|
1106
|
+
];
|
|
1107
|
+
for (const file of bundle.files) {
|
|
1108
|
+
const ext = file.path.includes(".") ? file.path.split(".").pop() : "tsx";
|
|
1109
|
+
sections.push(`### ${shown(file.path)}`);
|
|
1110
|
+
sections.push(codeBlock(ext, file.content));
|
|
1111
|
+
}
|
|
1112
|
+
return sections.join("\n\n");
|
|
1113
|
+
} catch (error) {
|
|
1114
|
+
const notFound = `**${shown(input.name)}**: examples not found in registry.`;
|
|
1115
|
+
if (!isNotFound(error)) {
|
|
1116
|
+
return notFound;
|
|
1117
|
+
}
|
|
1118
|
+
const hint = await examplesHint(config, input.name);
|
|
1119
|
+
return hint ? `${notFound}
|
|
1120
|
+
${hint}` : notFound;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
async function examplesHint(config, name) {
|
|
1124
|
+
let items;
|
|
1125
|
+
try {
|
|
1126
|
+
items = (await lookupManifest(config.registry)).items;
|
|
1127
|
+
} catch {
|
|
1128
|
+
return null;
|
|
1129
|
+
}
|
|
1130
|
+
const find = (wanted) => items.find((candidate) => candidate.name === wanted);
|
|
1131
|
+
const item = find(name);
|
|
1132
|
+
const meta = item && readMeta(item);
|
|
1133
|
+
let used = meta?.partOf;
|
|
1134
|
+
if (!used && meta?.flavourOf) {
|
|
1135
|
+
const parent = find(meta.flavourOf);
|
|
1136
|
+
if (parent) {
|
|
1137
|
+
used = readMeta(parent)?.partOf ?? [parent.name];
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
if (!used) {
|
|
1141
|
+
return null;
|
|
1142
|
+
}
|
|
1143
|
+
return `No demos of its own; it is used in ${used.map(shown).join(", ")}: get_examples(${shown(JSON.stringify(used[0]))})`;
|
|
1144
|
+
}
|
|
1145
|
+
function commandBlock(url, probe = url) {
|
|
1146
|
+
if (!isCommandSafe(url)) {
|
|
1147
|
+
return `(No command: ${shown(displayUrl(url))} holds a line break or control character.)`;
|
|
1148
|
+
}
|
|
1149
|
+
const word = shellWord(probe) === probe ? url : shellWord(url);
|
|
1150
|
+
return codeBlock("bash", `npx shadcn@latest add ${word}`);
|
|
1151
|
+
}
|
|
1152
|
+
function getThemeInfoTool(config) {
|
|
1153
|
+
const defaultStyleUrl = registryItemUrl(config.registry, "default");
|
|
1154
|
+
const themeUrl = registryItemUrl(config.registry, "theme/<code>");
|
|
1155
|
+
const themeProbeUrl = registryItemUrl(config.registry, "theme/code");
|
|
1156
|
+
const themeCtx = detectProjectContext();
|
|
1157
|
+
return `# Keystone UI Theme
|
|
1158
|
+
|
|
1159
|
+
## CSS Setup
|
|
1160
|
+
|
|
1161
|
+
Add these to ${inlineCode(themeCtx.tailwindCssFile ?? "your global CSS file")} -- edit that
|
|
1162
|
+
file rather than creating a new one, or the tokens will not reach the components.
|
|
1163
|
+
|
|
1164
|
+
\`\`\`css
|
|
1165
|
+
@import "tailwindcss";
|
|
1166
|
+
@import "@keystoneui/react/base.css";
|
|
1167
|
+
\`\`\`
|
|
1168
|
+
|
|
1169
|
+
## Semantic Color Tokens (OKLCH)
|
|
1170
|
+
|
|
1171
|
+
| Token | Light | Dark | Usage |
|
|
1172
|
+
|---|---|---|---|
|
|
1173
|
+
| \`--primary\` | \`oklch(0.21 0.006 285)\` | \`oklch(0.92 0.004 286)\` | Main actions, CTAs |
|
|
1174
|
+
| \`--secondary\` | \`oklch(0.967 0.001 286)\` | \`oklch(0.274 0.006 286)\` | Alternative actions |
|
|
1175
|
+
| \`--destructive\` | \`oklch(0.577 0.245 27)\` | \`oklch(0.704 0.191 22)\` | Destructive actions, a metric that got worse |
|
|
1176
|
+
| \`--success\` | \`oklch(0.627 0.194 149)\` | \`oklch(0.723 0.19 150)\` | Positive status, a metric that improved |
|
|
1177
|
+
| \`--warning\` | \`oklch(0.769 0.188 70)\` | \`oklch(0.828 0.189 84)\` | Caution and threshold states only |
|
|
1178
|
+
| \`--info\` | \`oklch(0.546 0.245 263)\` | \`oklch(0.707 0.165 255)\` | Neutral notices (info Alert, info Toast) |
|
|
1179
|
+
| \`--muted\` | \`oklch(0.967 0.001 286)\` | \`oklch(0.274 0.006 286)\` | Subdued elements |
|
|
1180
|
+
| \`--accent\` | \`oklch(0.967 0.001 286)\` | \`oklch(0.274 0.006 286)\` | Highlights |
|
|
1181
|
+
| \`--background\` | \`oklch(1 0 0)\` | \`oklch(0.141 0.005 286)\` | Page background |
|
|
1182
|
+
| \`--border\` | \`oklch(0.92 0.004 286)\` | \`oklch(1 0 0 / 10%)\` | Border color |
|
|
1183
|
+
| \`--ring\` | \`oklch(0.21 0.006 286)\` | \`oklch(0.92 0.004 286)\` | Focus ring |
|
|
1184
|
+
|
|
1185
|
+
## Radius Scale
|
|
1186
|
+
|
|
1187
|
+
Base: \`--radius: 0.625rem\` (10px). Derived values:
|
|
1188
|
+
- \`rounded-sm\`: \`--radius * 0.6\` (6px)
|
|
1189
|
+
- \`rounded-md\`: \`--radius * 0.8\` (8px)
|
|
1190
|
+
- \`rounded-lg\`: \`--radius\` (10px, base)
|
|
1191
|
+
- \`rounded-xl\`: \`--radius * 1.4\` (14px)
|
|
1192
|
+
|
|
1193
|
+
Ratios, not pixel offsets \u2014 the scale stays proportional at any base.
|
|
1194
|
+
|
|
1195
|
+
## Custom Tokens
|
|
1196
|
+
|
|
1197
|
+
- \`--input-bg\`: Form control background (transparent light, 5% white dark)
|
|
1198
|
+
- \`--popup-ring\`: Subtle popup container ring
|
|
1199
|
+
- \`--border-muted\`: Lower-contrast separator inside popups, and Card's filled ring
|
|
1200
|
+
- \`--success-foreground\` / \`--warning-foreground\`: Text on a success/warning fill. \`--warning-foreground\` is dark, not near-white \u2014 near-white on amber-500 is ~1.9:1 and fails WCAG
|
|
1201
|
+
- \`--sidebar\` + 7 \`--sidebar-*\`: Read by the sidebar item (\`sidebar\`) and by an imported shadcn sidebar. Declared as aliases, so the sidebar follows the active keystone theme
|
|
1202
|
+
|
|
1203
|
+
Use \`text-success\` / \`bg-warning\` rather than raw \`emerald\`/\`amber\` classes, and never add a \`dark:\` override to a status token.
|
|
1204
|
+
|
|
1205
|
+
## Dark Mode
|
|
1206
|
+
|
|
1207
|
+
Add the \`dark\` class to a parent element.
|
|
1208
|
+
|
|
1209
|
+
## Registry
|
|
1210
|
+
|
|
1211
|
+
Get the full style definition:
|
|
1212
|
+
${commandBlock(defaultStyleUrl)}
|
|
1213
|
+
|
|
1214
|
+
## Custom themes
|
|
1215
|
+
|
|
1216
|
+
The theme builder (${shown(config.docsUrl)}/theme-builder) encodes a theme as a code,
|
|
1217
|
+
\`k1_<base>_<L>_<C>_<H>_<radius>_<font>\`, served as a \`registry:theme\` item.
|
|
1218
|
+
Install one, or only its colours (\`?only=theme\`) or font (\`?only=font\`):
|
|
1219
|
+
${commandBlock(themeUrl, themeProbeUrl)}
|
|
1220
|
+
\`keystoneui theme <code>\` prints the decoded settings and this command.`;
|
|
1221
|
+
}
|
|
1222
|
+
function auditChecklistTool() {
|
|
1223
|
+
const ctx = detectProjectContext();
|
|
1224
|
+
const registryMode = ctx.installMode === "registry";
|
|
1225
|
+
const uiAlias = ctx.aliases?.ui ?? "@/components/ui";
|
|
1226
|
+
const cssFile = ctx.tailwindCssFile ?? "your CSS entry point";
|
|
1227
|
+
const iconPkg = iconPackageFor(ctx.iconLibrary);
|
|
1228
|
+
return `# Post-Install Audit Checklist
|
|
1229
|
+
|
|
1230
|
+
## 1. CSS Setup (${inlineCode(cssFile)})
|
|
1231
|
+
- [ ] \`@import "tailwindcss"\` is present in ${inlineCode(cssFile)}
|
|
1232
|
+
- [ ] \`@import "@keystoneui/react/base.css"\` is imported AFTER tailwindcss
|
|
1233
|
+
- [ ] Dark mode variant is configured: \`@custom-variant dark (&:is(.dark *))\`
|
|
1234
|
+
|
|
1235
|
+
## 2. Tailwind Configuration
|
|
1236
|
+
- [ ] Using Tailwind CSS v4.1+
|
|
1237
|
+
- [ ] Content paths include your component files
|
|
1238
|
+
|
|
1239
|
+
## 3. Dependencies
|
|
1240
|
+
- [ ] \`@keystoneui/react\` is installed
|
|
1241
|
+
- [ ] Component-specific peer dependencies are installed (check each component's \`dependencies\` field)
|
|
1242
|
+
- [ ] Using React 19+
|
|
1243
|
+
|
|
1244
|
+
## 4. Import Pattern (install mode: ${ctx.installMode})
|
|
1245
|
+
${registryMode ? `- [ ] Importing from the project alias: ${inlineCode(`import { Button } from "${uiAlias}/button"`)}
|
|
1246
|
+
- [ ] NOT importing from \`@keystoneui/react\` -- it is not a dependency in this project` : `- [ ] Using subpath imports: \`import { Button } from "@keystoneui/react/button"\`
|
|
1247
|
+
- [ ] NOT using barrel imports from \`@keystoneui/react\``}
|
|
1248
|
+
|
|
1249
|
+
## 5. Theme Variables
|
|
1250
|
+
- [ ] CSS custom properties are defined in \`:root\` (see \`get_theme_info\` for the full list)
|
|
1251
|
+
- [ ] Dark mode variables are defined in \`.dark\` selector
|
|
1252
|
+
|
|
1253
|
+
## 6. Icon Library
|
|
1254
|
+
- [ ] Using ${inlineCode(iconPkg)} for icons, matching this project's configured icon library
|
|
1255
|
+
|
|
1256
|
+
## 7. Common Issues
|
|
1257
|
+
- [ ] If hover styles feel "sticky" on mobile: ensure \`base.css\` is imported (it gates \`hover:\` with \`@media (hover: hover)\`)
|
|
1258
|
+
- [ ] If buttons don't show pointer cursor: Tailwind v4 changed the default \u2014 Keystone UI handles this internally
|
|
1259
|
+
- [ ] If focus rings look wrong: don't mix outline-based and ring-based focus patterns`;
|
|
1260
|
+
}
|
|
1261
|
+
var ICON_PACKAGES = {
|
|
1262
|
+
lucide: "lucide-react",
|
|
1263
|
+
tabler: "@tabler/icons-react",
|
|
1264
|
+
hugeicons: "@hugeicons/react",
|
|
1265
|
+
remix: "@remixicon/react"
|
|
1266
|
+
};
|
|
1267
|
+
function iconPackageFor(library) {
|
|
1268
|
+
if (library === null) {
|
|
1269
|
+
return "lucide-react";
|
|
1270
|
+
}
|
|
1271
|
+
return ICON_PACKAGES[library] ?? library;
|
|
1272
|
+
}
|
|
1273
|
+
var getDocsSchema = z.object({
|
|
1274
|
+
name: z.string().describe(
|
|
1275
|
+
'Component, block, kit, or package flavour name (e.g. "select", "signin-01", "sidebar", "npm/users-01")'
|
|
1276
|
+
),
|
|
1277
|
+
type: z.enum(["component", "block"]).default("component").describe("Which docs section to read from")
|
|
1278
|
+
});
|
|
1279
|
+
async function getDocsTool(config, input) {
|
|
1280
|
+
const refusal = nameRefusal(input.name);
|
|
1281
|
+
if (refusal) {
|
|
1282
|
+
return refusal;
|
|
1283
|
+
}
|
|
1284
|
+
const result = await resolveDocs(
|
|
1285
|
+
config,
|
|
1286
|
+
input.name,
|
|
1287
|
+
input.type === "block" ? "blocks" : "components",
|
|
1288
|
+
() => ({
|
|
1289
|
+
headers: { "User-Agent": "keystoneui-mcp" },
|
|
1290
|
+
signal: AbortSignal.timeout(3e4)
|
|
1291
|
+
})
|
|
1292
|
+
);
|
|
1293
|
+
if (result.kind === "page") {
|
|
1294
|
+
return result.text;
|
|
1295
|
+
}
|
|
1296
|
+
if (result.kind === "status") {
|
|
1297
|
+
return `**${shown(input.name)}**: no ${input.type} docs found (${result.status}). Try search_components to find the right name.`;
|
|
1298
|
+
}
|
|
1299
|
+
return `**${shown(input.name)}**: could not reach ${shown(displayUrl(result.url))}.`;
|
|
1300
|
+
}
|
|
1301
|
+
var emptySchema = z.object({});
|
|
1302
|
+
var TOOL_SPECS = {
|
|
1303
|
+
list_components: {
|
|
1304
|
+
description: "List all available Keystone UI components, blocks, kits, and named examples with pagination. Returns name, description, categories, and dependency info for each item. A package flavour is listed as its own entry, with a `Flavour of:` line.",
|
|
1305
|
+
schema: listComponentsSchema
|
|
1306
|
+
},
|
|
1307
|
+
search_components: {
|
|
1308
|
+
description: "Fuzzy search components, blocks, kits, and named examples (e.g., `table-with-pagination`, `card-with-image`). Categories (e.g. 'authentication', 'login') participate in fuzzy matching. Use when the exact name isn't known; pair with `view_component` or `get_examples` to see code.",
|
|
1309
|
+
schema: searchComponentsSchema
|
|
1310
|
+
},
|
|
1311
|
+
view_component: {
|
|
1312
|
+
description: "Get full details for one or more Keystone UI components, blocks, kits, or a package flavour such as `npm/users-01`, including complete source code, dependencies, and registry dependencies. Use this to understand how a component works before using or customizing it.",
|
|
1313
|
+
schema: viewComponentSchema
|
|
1314
|
+
},
|
|
1315
|
+
get_add_command: {
|
|
1316
|
+
description: 'Generate the shadcn CLI command to install one or more Keystone UI components, blocks, or kits into a project. In a project that uses the @keystoneui/react package (see get_project_context), pass flavour: "package" to install the package flavour of a block or kit where the registry has one.',
|
|
1317
|
+
schema: getAddCommandSchema
|
|
1318
|
+
},
|
|
1319
|
+
get_examples: {
|
|
1320
|
+
description: "Fetch live demo files for a Keystone UI component or block. Returns the TSX source for every example/demo associated with the name (e.g. button, signin-01, tickets-01). A kit or package flavour with no demos of its own names the block whose demos show it. Use after view_component to see real-world usage patterns.",
|
|
1321
|
+
schema: getExamplesSchema
|
|
1322
|
+
},
|
|
1323
|
+
get_docs: {
|
|
1324
|
+
description: "Fetch the full documentation page for a component, block, kit, or package flavour; kits and flavours resolve to the page section that documents them. Includes its Composition tree (the parts hierarchy, and nestings Base UI rejects) and its API Reference table. Read it before composing any compound component. Props are documented ONLY here -- not in the registry -- so view_component alone will not give you a prop's type or default. Previews arrive resolved to inline TSX, so one call returns prose and working code.",
|
|
1325
|
+
schema: getDocsSchema
|
|
1326
|
+
},
|
|
1327
|
+
get_project_context: {
|
|
1328
|
+
description: "Read this project's Keystone UI setup: install mode (npm package vs vendored registry source), path aliases, which CSS file owns the theme tokens, icon library, whether React Server Components are in use, and the package manager. Call this FIRST -- import style and which file to edit both depend on it, and guessing wrong is the most common source of broken output.",
|
|
1329
|
+
schema: emptySchema
|
|
1330
|
+
},
|
|
1331
|
+
get_theme_info: {
|
|
1332
|
+
description: "Get Keystone UI theme configuration: CSS setup, semantic color tokens (OKLCH), radius scale, dark mode setup, and custom tokens.",
|
|
1333
|
+
schema: emptySchema
|
|
1334
|
+
},
|
|
1335
|
+
audit_checklist: {
|
|
1336
|
+
description: "Get a post-install audit checklist to verify Keystone UI is correctly configured in your project. Covers CSS setup, Tailwind config, dependencies, imports, and common issues.",
|
|
1337
|
+
schema: emptySchema
|
|
1338
|
+
}
|
|
1339
|
+
};
|
|
1340
|
+
function getProjectContextTool() {
|
|
1341
|
+
return formatProjectContext(detectProjectContext());
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
export {
|
|
1345
|
+
registryCatalogueUrl,
|
|
1346
|
+
loadProjectConfig,
|
|
1347
|
+
displayUrl,
|
|
1348
|
+
redactUrlInError,
|
|
1349
|
+
shown,
|
|
1350
|
+
isCommandSafe,
|
|
1351
|
+
escapedError,
|
|
1352
|
+
lookupManifest,
|
|
1353
|
+
parseThemeCode,
|
|
1354
|
+
themeInstallUrl,
|
|
1355
|
+
themeInstallCommand,
|
|
1356
|
+
themeBuilderUrl,
|
|
1357
|
+
parseThemeParts,
|
|
1358
|
+
nameRefusal,
|
|
1359
|
+
resolveDocs,
|
|
1360
|
+
readPackageVersion,
|
|
1361
|
+
detectProjectContext,
|
|
1362
|
+
listComponentsTool,
|
|
1363
|
+
searchComponentsTool,
|
|
1364
|
+
viewComponentTool,
|
|
1365
|
+
getAddCommandTool,
|
|
1366
|
+
getExamplesTool,
|
|
1367
|
+
getThemeInfoTool,
|
|
1368
|
+
auditChecklistTool,
|
|
1369
|
+
getDocsTool,
|
|
1370
|
+
TOOL_SPECS,
|
|
1371
|
+
getProjectContextTool
|
|
1372
|
+
};
|