@dowel-ui/registry 0.5.0 → 0.7.0
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/dist/build.d.ts +32 -4
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +398 -88
- package/dist/build.js.map +1 -1
- package/dist/generate.d.ts +71 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +324 -0
- package/dist/generate.js.map +1 -0
- package/dist/index.d.ts +184 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +648 -2
- package/dist/index.js.map +1 -0
- package/dist/{schema-ByqIpT47.js → schema-BbyNjH6Q.js} +25 -5
- package/dist/schema-BbyNjH6Q.js.map +1 -0
- package/dist/{schema-Cc32v3R-.d.ts → schema-BmYeKe9e.d.ts} +36 -2
- package/dist/schema-BmYeKe9e.d.ts.map +1 -0
- package/package.json +12 -4
- package/src/agent-docs.ts +544 -0
- package/src/build.ts +66 -4
- package/src/custom.ts +312 -0
- package/src/generate.ts +500 -0
- package/src/index.ts +41 -0
- package/src/schema.ts +23 -0
- package/dist/schema-ByqIpT47.js.map +0 -1
- package/dist/schema-Cc32v3R-.d.ts.map +0 -1
package/src/generate.ts
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import type { RegistryIndex, RegistryIndexEntry } from "./schema";
|
|
2
|
+
|
|
3
|
+
export type { RegistryIndex, RegistryIndexEntry } from "./schema";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Turning a description of a screen into a plan made of components that exist.
|
|
7
|
+
*
|
|
8
|
+
* The hard part of generating UI is not writing JSX. It is not inventing: a
|
|
9
|
+
* model asked for a billing page will cheerfully produce `<PricingTable>` and
|
|
10
|
+
* `<InvoiceList>` and a `variant="subtle"` that was never implemented, and the
|
|
11
|
+
* result reads perfectly and compiles nowhere.
|
|
12
|
+
*
|
|
13
|
+
* So this resolves a prompt against the registry first, and everything it
|
|
14
|
+
* emits afterwards is drawn from what came back. It cannot name a component
|
|
15
|
+
* that is not installable, because it only ever repeats names the registry
|
|
16
|
+
* gave it.
|
|
17
|
+
*
|
|
18
|
+
* It does not guess at props. The registry publishes what a component *is* and
|
|
19
|
+
* what it depends on, not the shape of its arguments, so the output stops at
|
|
20
|
+
* the composition and points at the page where the props are documented.
|
|
21
|
+
* Emitting a plausible prop is worse than emitting none — one is a gap, the
|
|
22
|
+
* other is a bug that looks like working code.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** Words that carry no signal about which component is wanted. */
|
|
26
|
+
const STOPWORDS = new Set([
|
|
27
|
+
"a",
|
|
28
|
+
"an",
|
|
29
|
+
"the",
|
|
30
|
+
"and",
|
|
31
|
+
"or",
|
|
32
|
+
"of",
|
|
33
|
+
"for",
|
|
34
|
+
"with",
|
|
35
|
+
"to",
|
|
36
|
+
"in",
|
|
37
|
+
"on",
|
|
38
|
+
"at",
|
|
39
|
+
"by",
|
|
40
|
+
"is",
|
|
41
|
+
"are",
|
|
42
|
+
"be",
|
|
43
|
+
"make",
|
|
44
|
+
"build",
|
|
45
|
+
"create",
|
|
46
|
+
"want",
|
|
47
|
+
"need",
|
|
48
|
+
"add",
|
|
49
|
+
"show",
|
|
50
|
+
"page",
|
|
51
|
+
"screen",
|
|
52
|
+
"app",
|
|
53
|
+
"application",
|
|
54
|
+
"ui",
|
|
55
|
+
"interface",
|
|
56
|
+
"component",
|
|
57
|
+
"components",
|
|
58
|
+
"me",
|
|
59
|
+
"my",
|
|
60
|
+
"our",
|
|
61
|
+
"i",
|
|
62
|
+
"it",
|
|
63
|
+
"that",
|
|
64
|
+
"this",
|
|
65
|
+
"some",
|
|
66
|
+
"using",
|
|
67
|
+
"use",
|
|
68
|
+
"like",
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Words a reader would use that are not the words the registry uses.
|
|
73
|
+
*
|
|
74
|
+
* Hand-written, and deliberately so. "Sign in" is what someone types and
|
|
75
|
+
* `login` is what the item is called; no amount of string similarity bridges
|
|
76
|
+
* that, and pretending otherwise produces a matcher that works on the examples
|
|
77
|
+
* it was tuned against and nothing else.
|
|
78
|
+
*/
|
|
79
|
+
const SYNONYMS: Record<string, string[]> = {
|
|
80
|
+
"sign in": ["login"],
|
|
81
|
+
signin: ["login"],
|
|
82
|
+
"log in": ["login"],
|
|
83
|
+
"sign up": ["signup"],
|
|
84
|
+
register: ["signup"],
|
|
85
|
+
registration: ["signup"],
|
|
86
|
+
"forgot password": ["forgot-password"],
|
|
87
|
+
"reset password": ["forgot-password"],
|
|
88
|
+
chat: ["ai-chat", "ai-conversation", "ai-prompt-input"],
|
|
89
|
+
conversation: ["ai-chat"],
|
|
90
|
+
assistant: ["ai-chat"],
|
|
91
|
+
copilot: ["ai-chat"],
|
|
92
|
+
agent: ["agent-console", "ai-agent-status", "ai-agent-plan"],
|
|
93
|
+
agents: ["agent-console"],
|
|
94
|
+
tool: ["ai-tool"],
|
|
95
|
+
approval: ["ai-approval-request"],
|
|
96
|
+
approve: ["ai-approval-request"],
|
|
97
|
+
undo: ["ai-action-ledger"],
|
|
98
|
+
audit: ["ai-action-ledger", "activity-feed"],
|
|
99
|
+
tokens: ["ai-token-usage"],
|
|
100
|
+
spend: ["ai-dashboard", "billing"],
|
|
101
|
+
cost: ["ai-dashboard", "billing"],
|
|
102
|
+
usage: ["ai-dashboard", "billing"],
|
|
103
|
+
subscription: ["billing", "pricing"],
|
|
104
|
+
invoice: ["billing"],
|
|
105
|
+
invoices: ["billing"],
|
|
106
|
+
payment: ["billing"],
|
|
107
|
+
plan: ["pricing", "billing"],
|
|
108
|
+
plans: ["pricing"],
|
|
109
|
+
metrics: ["analytics", "dashboard", "metric-delta"],
|
|
110
|
+
chart: ["analytics"],
|
|
111
|
+
charts: ["analytics"],
|
|
112
|
+
graph: ["analytics"],
|
|
113
|
+
stats: ["dashboard", "analytics"],
|
|
114
|
+
overview: ["dashboard"],
|
|
115
|
+
grid: ["data-table", "table"],
|
|
116
|
+
spreadsheet: ["data-table"],
|
|
117
|
+
list: ["table", "data-table"],
|
|
118
|
+
search: ["command", "combobox"],
|
|
119
|
+
palette: ["command"],
|
|
120
|
+
shortcut: ["command", "shortcut-recorder"],
|
|
121
|
+
modal: ["dialog"],
|
|
122
|
+
popup: ["dialog", "popover"],
|
|
123
|
+
dropdown: ["dropdown-menu", "select"],
|
|
124
|
+
toast: ["toast"],
|
|
125
|
+
notification: ["toast", "activity-feed"],
|
|
126
|
+
notifications: ["toast", "settings"],
|
|
127
|
+
upload: ["file-upload"],
|
|
128
|
+
file: ["file-upload"],
|
|
129
|
+
date: ["date-picker", "calendar"],
|
|
130
|
+
time: ["time-range-picker"],
|
|
131
|
+
schedule: ["cron-editor"],
|
|
132
|
+
cron: ["cron-editor"],
|
|
133
|
+
team: ["admin-users", "settings"],
|
|
134
|
+
members: ["admin-users"],
|
|
135
|
+
users: ["admin-users"],
|
|
136
|
+
admin: ["admin-users"],
|
|
137
|
+
permissions: ["permission-matrix"],
|
|
138
|
+
roles: ["permission-matrix"],
|
|
139
|
+
profile: ["settings"],
|
|
140
|
+
preferences: ["settings"],
|
|
141
|
+
account: ["settings", "billing"],
|
|
142
|
+
setup: ["onboarding"],
|
|
143
|
+
checklist: ["onboarding"],
|
|
144
|
+
wizard: ["onboarding"],
|
|
145
|
+
logs: ["log-viewer"],
|
|
146
|
+
log: ["log-viewer"],
|
|
147
|
+
diff: ["diff-viewer", "record-diff"],
|
|
148
|
+
secret: ["secret-field"],
|
|
149
|
+
"api key": ["secret-field"],
|
|
150
|
+
key: ["secret-field"],
|
|
151
|
+
dns: ["dns-record"],
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export interface PlanEntry {
|
|
155
|
+
entry: RegistryIndexEntry;
|
|
156
|
+
/** Why this was chosen, in words, so a wrong pick is arguable. */
|
|
157
|
+
because: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface UiPlan {
|
|
161
|
+
/** The prompt, as given. */
|
|
162
|
+
prompt: string;
|
|
163
|
+
/** Whole sections, which bring their own components. */
|
|
164
|
+
blocks: PlanEntry[];
|
|
165
|
+
/** Individual components, none of which a chosen block already installs. */
|
|
166
|
+
components: PlanEntry[];
|
|
167
|
+
/** Everything to install, in one list. */
|
|
168
|
+
install: string[];
|
|
169
|
+
/** True when nothing matched, so callers can say so rather than emit nothing. */
|
|
170
|
+
empty: boolean;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function normalise(prompt: string): string {
|
|
174
|
+
return prompt.toLowerCase().replace(/[^a-z0-9\s-]/g, " ");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function words(prompt: string): string[] {
|
|
178
|
+
return normalise(prompt)
|
|
179
|
+
.split(/\s+/)
|
|
180
|
+
.filter((word) => word.length > 2 && !STOPWORDS.has(word));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
interface SynonymMatch {
|
|
184
|
+
/** Item name to the phrase that selected it. */
|
|
185
|
+
hits: Map<string, string>;
|
|
186
|
+
/**
|
|
187
|
+
* Words the table has already spoken for.
|
|
188
|
+
*
|
|
189
|
+
* Excluded from generic term matching afterwards. The table exists to say
|
|
190
|
+
* that "plan" means pricing or billing; letting the generic matcher also
|
|
191
|
+
* score every item with "plan" in its name puts `ai-agent-plan` on a billing
|
|
192
|
+
* page and re-introduces exactly the ambiguity the table resolves.
|
|
193
|
+
*/
|
|
194
|
+
consumed: Set<string>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function synonymHits(prompt: string): SynonymMatch {
|
|
198
|
+
const text = normalise(prompt);
|
|
199
|
+
const hits = new Map<string, string>();
|
|
200
|
+
const consumed = new Set<string>();
|
|
201
|
+
|
|
202
|
+
for (const [phrase, names] of Object.entries(SYNONYMS)) {
|
|
203
|
+
// Word-boundary matched, so "keyboard" does not trigger "key".
|
|
204
|
+
const pattern = new RegExp(`(^|\\s)${phrase.replace(/\s+/g, "\\s+")}(\\s|$)`);
|
|
205
|
+
if (!pattern.test(text)) continue;
|
|
206
|
+
|
|
207
|
+
for (const word of phrase.split(/\s+/)) consumed.add(word);
|
|
208
|
+
for (const name of names) {
|
|
209
|
+
if (!hits.has(name)) hits.set(name, phrase);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return { hits, consumed };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Below this a match is coincidence rather than intent. */
|
|
217
|
+
const MINIMUM_SCORE = 20;
|
|
218
|
+
|
|
219
|
+
interface Scored {
|
|
220
|
+
entry: RegistryIndexEntry;
|
|
221
|
+
/** What the prompt actually matched. Decides whether it qualifies at all. */
|
|
222
|
+
score: number;
|
|
223
|
+
/** Score plus the block preference. Decides order only. */
|
|
224
|
+
rank: number;
|
|
225
|
+
because: string;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function scoreEntry(
|
|
229
|
+
entry: RegistryIndexEntry,
|
|
230
|
+
terms: string[],
|
|
231
|
+
synonyms: Map<string, string>,
|
|
232
|
+
): Scored | undefined {
|
|
233
|
+
const name = entry.name.toLowerCase();
|
|
234
|
+
const title = entry.title.toLowerCase();
|
|
235
|
+
const description = entry.description.toLowerCase();
|
|
236
|
+
|
|
237
|
+
let score = 0;
|
|
238
|
+
const reasons: string[] = [];
|
|
239
|
+
|
|
240
|
+
const synonym = synonyms.get(entry.name);
|
|
241
|
+
if (synonym) {
|
|
242
|
+
score += 60;
|
|
243
|
+
reasons.push(`"${synonym}"`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
for (const term of terms) {
|
|
247
|
+
if (name === term) {
|
|
248
|
+
score += 50;
|
|
249
|
+
reasons.push(`named "${term}"`);
|
|
250
|
+
} else if (name.split("-").includes(term)) {
|
|
251
|
+
score += 30;
|
|
252
|
+
reasons.push(`"${term}" in its name`);
|
|
253
|
+
} else if (title.includes(term)) {
|
|
254
|
+
score += 20;
|
|
255
|
+
reasons.push(`"${term}" in its title`);
|
|
256
|
+
} else if (entry.category === term) {
|
|
257
|
+
score += 12;
|
|
258
|
+
reasons.push(`the ${term} category`);
|
|
259
|
+
} else if (description.includes(term)) {
|
|
260
|
+
score += 8;
|
|
261
|
+
reasons.push(`"${term}" in its description`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (score === 0) return undefined;
|
|
266
|
+
|
|
267
|
+
// A block covers more of an intent than a component does, and installing one
|
|
268
|
+
// brings the components anyway — so where both match, the block is the better
|
|
269
|
+
// answer rather than merely an equal one.
|
|
270
|
+
//
|
|
271
|
+
// Kept out of `score` on purpose. Added there it would lift a block over the
|
|
272
|
+
// qualifying floor on a description-only brush, which is how `ai-dashboard`
|
|
273
|
+
// ended up recommended for an agent console because its prose contains the
|
|
274
|
+
// word "run". A preference should order real matches, not manufacture one.
|
|
275
|
+
const rank = score + (entry.type === "registry:block" ? 25 : 0);
|
|
276
|
+
|
|
277
|
+
return { entry, score, rank, because: [...new Set(reasons)].slice(0, 3).join(", ") };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export interface PlanOptions {
|
|
281
|
+
/** How many components to suggest beyond the blocks. */
|
|
282
|
+
maxComponents?: number;
|
|
283
|
+
/** How many blocks to suggest. */
|
|
284
|
+
maxBlocks?: number;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export function planUi(
|
|
288
|
+
prompt: string,
|
|
289
|
+
index: RegistryIndex,
|
|
290
|
+
options: PlanOptions = {},
|
|
291
|
+
): UiPlan {
|
|
292
|
+
const { maxBlocks = 3, maxComponents = 6 } = options;
|
|
293
|
+
|
|
294
|
+
const { hits: synonyms, consumed } = synonymHits(prompt);
|
|
295
|
+
const terms = words(prompt).filter((term) => !consumed.has(term));
|
|
296
|
+
|
|
297
|
+
const scored = index.items
|
|
298
|
+
.filter((entry) => entry.type === "registry:ui" || entry.type === "registry:block")
|
|
299
|
+
.map((entry) => scoreEntry(entry, terms, synonyms))
|
|
300
|
+
.filter((candidate): candidate is Scored => candidate !== undefined)
|
|
301
|
+
// A description-only brush (8) or a bare category hit (12) is not enough on
|
|
302
|
+
// its own. Suggesting six components because the prompt shares a common
|
|
303
|
+
// word with their prose makes the plan look like more work than it is, and
|
|
304
|
+
// buries the ones that actually matched.
|
|
305
|
+
.filter((candidate) => candidate.score >= MINIMUM_SCORE)
|
|
306
|
+
.sort((a, b) => b.rank - a.rank || a.entry.name.localeCompare(b.entry.name));
|
|
307
|
+
|
|
308
|
+
const blocks = scored
|
|
309
|
+
.filter((candidate) => candidate.entry.type === "registry:block")
|
|
310
|
+
.slice(0, maxBlocks);
|
|
311
|
+
|
|
312
|
+
// Anything a chosen block already installs is not a separate suggestion:
|
|
313
|
+
// listing Button beside a Dashboard that brings it is noise that makes the
|
|
314
|
+
// plan look longer than the work.
|
|
315
|
+
const covered = new Set(
|
|
316
|
+
blocks.flatMap((candidate) => [
|
|
317
|
+
candidate.entry.name,
|
|
318
|
+
...candidate.entry.registryDependencies,
|
|
319
|
+
]),
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
const components = scored
|
|
323
|
+
.filter(
|
|
324
|
+
(candidate) =>
|
|
325
|
+
candidate.entry.type === "registry:ui" && !covered.has(candidate.entry.name),
|
|
326
|
+
)
|
|
327
|
+
.slice(0, maxComponents);
|
|
328
|
+
|
|
329
|
+
const toEntry = (candidate: Scored): PlanEntry => ({
|
|
330
|
+
entry: candidate.entry,
|
|
331
|
+
because: candidate.because,
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
return {
|
|
335
|
+
prompt,
|
|
336
|
+
blocks: blocks.map(toEntry),
|
|
337
|
+
components: components.map(toEntry),
|
|
338
|
+
install: [...blocks, ...components].map((candidate) => candidate.entry.name),
|
|
339
|
+
empty: blocks.length === 0 && components.length === 0,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** PascalCase export name for a registry name, e.g. "ai-tool" -> "AiTool". */
|
|
344
|
+
function tag(name: string): string {
|
|
345
|
+
return name
|
|
346
|
+
.split("-")
|
|
347
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
348
|
+
.join("");
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Blocks export a `…Block` component; components export their own name. */
|
|
352
|
+
function componentName(entry: RegistryIndexEntry): string {
|
|
353
|
+
const base = tag(entry.name);
|
|
354
|
+
return entry.type === "registry:block" ? `${base}Block` : base;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export interface RenderOptions {
|
|
358
|
+
/** Where components are imported from in the target project. */
|
|
359
|
+
importFrom?: string;
|
|
360
|
+
/**
|
|
361
|
+
* Where blocks are imported from.
|
|
362
|
+
*
|
|
363
|
+
* Separate because blocks are not exported from the component package at
|
|
364
|
+
* all — they are only ever installed as source — so deriving their path from
|
|
365
|
+
* a package specifier produces an import that does not exist. Derived from
|
|
366
|
+
* `importFrom` when it is a project alias, and otherwise the conventional
|
|
367
|
+
* install location.
|
|
368
|
+
*/
|
|
369
|
+
blocksImportFrom?: string;
|
|
370
|
+
cliPackage?: string;
|
|
371
|
+
docsUrl?: string;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Where an installed block lives.
|
|
376
|
+
*
|
|
377
|
+
* A project alias like `@/components/ui` has a sibling `@/components/blocks`. A
|
|
378
|
+
* bare package specifier has no block path at all, so the conventional install
|
|
379
|
+
* location is used instead of inventing one under the package.
|
|
380
|
+
*/
|
|
381
|
+
export function blocksPathFor(importFrom: string): string {
|
|
382
|
+
if (importFrom.endsWith("/ui")) return `${importFrom.slice(0, -3)}/blocks`;
|
|
383
|
+
if (importFrom.startsWith("@/") || importFrom.startsWith("~/")) {
|
|
384
|
+
return `${importFrom}/blocks`;
|
|
385
|
+
}
|
|
386
|
+
return "@/components/blocks";
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* The plan as a starting file.
|
|
391
|
+
*
|
|
392
|
+
* Imports and composition only. Every element carries the page its props are
|
|
393
|
+
* documented on, because the registry does not publish prop shapes and a
|
|
394
|
+
* plausible invented prop is worse than an obvious gap — one is a TODO, the
|
|
395
|
+
* other is a bug wearing the costume of working code.
|
|
396
|
+
*/
|
|
397
|
+
export function renderPlan(plan: UiPlan, options: RenderOptions = {}): string {
|
|
398
|
+
const {
|
|
399
|
+
importFrom = "@/components/ui",
|
|
400
|
+
docsUrl = "https://dowel-eight.vercel.app",
|
|
401
|
+
blocksImportFrom = blocksPathFor(importFrom),
|
|
402
|
+
} = options;
|
|
403
|
+
|
|
404
|
+
if (plan.empty) {
|
|
405
|
+
return `// Nothing in the registry matched "${plan.prompt}".\n`;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const chosen = [...plan.blocks, ...plan.components];
|
|
409
|
+
|
|
410
|
+
const imports = chosen
|
|
411
|
+
.map((item) => {
|
|
412
|
+
const from =
|
|
413
|
+
item.entry.type === "registry:block"
|
|
414
|
+
? `${blocksImportFrom}/${item.entry.name}`
|
|
415
|
+
: `${importFrom}/${item.entry.name}`;
|
|
416
|
+
return `import { ${componentName(item.entry)} } from "${from}";`;
|
|
417
|
+
})
|
|
418
|
+
.sort();
|
|
419
|
+
|
|
420
|
+
const body = chosen
|
|
421
|
+
.map((item) => {
|
|
422
|
+
const name = componentName(item.entry);
|
|
423
|
+
return [
|
|
424
|
+
` {/* ${item.entry.title} — props: ${docsUrl}/docs/${
|
|
425
|
+
item.entry.type === "registry:block" ? "blocks" : "components"
|
|
426
|
+
}/${item.entry.name} */}`,
|
|
427
|
+
` <${name} />`,
|
|
428
|
+
].join("\n");
|
|
429
|
+
})
|
|
430
|
+
.join("\n\n");
|
|
431
|
+
|
|
432
|
+
return `${imports.join("\n")}
|
|
433
|
+
|
|
434
|
+
export default function Page() {
|
|
435
|
+
return (
|
|
436
|
+
<div className="flex flex-col gap-6">
|
|
437
|
+
${body}
|
|
438
|
+
</div>
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
`;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* The plan as a brief for a coding agent.
|
|
446
|
+
*
|
|
447
|
+
* The most useful thing this can produce. The agent has the project, the
|
|
448
|
+
* editor and the ability to write the props; what it lacks is the knowledge
|
|
449
|
+
* that these components exist and that it must not invent others. That is
|
|
450
|
+
* exactly what a grounded plan supplies.
|
|
451
|
+
*/
|
|
452
|
+
export function renderBrief(plan: UiPlan, options: RenderOptions = {}): string {
|
|
453
|
+
const {
|
|
454
|
+
cliPackage = "@dowel-ui/cli",
|
|
455
|
+
docsUrl = "https://dowel-eight.vercel.app",
|
|
456
|
+
importFrom = "@/components/ui",
|
|
457
|
+
} = options;
|
|
458
|
+
|
|
459
|
+
if (plan.empty) {
|
|
460
|
+
return `Nothing in the registry matched "${plan.prompt}". Search the catalogue at ${docsUrl}/docs/components before building anything by hand.`;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const lines = [
|
|
464
|
+
`Build: ${plan.prompt}`,
|
|
465
|
+
"",
|
|
466
|
+
"Use these, which are already in the registry. Do not write your own versions,",
|
|
467
|
+
"and do not use any component not listed here without checking the catalogue first.",
|
|
468
|
+
"",
|
|
469
|
+
];
|
|
470
|
+
|
|
471
|
+
if (plan.blocks.length > 0) {
|
|
472
|
+
lines.push("Blocks (whole sections — each installs its own components):");
|
|
473
|
+
for (const item of plan.blocks) {
|
|
474
|
+
lines.push(`- ${item.entry.name} — ${item.entry.description}`);
|
|
475
|
+
}
|
|
476
|
+
lines.push("");
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (plan.components.length > 0) {
|
|
480
|
+
lines.push("Components:");
|
|
481
|
+
for (const item of plan.components) {
|
|
482
|
+
lines.push(`- ${item.entry.name} — ${item.entry.description}`);
|
|
483
|
+
}
|
|
484
|
+
lines.push("");
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
lines.push(
|
|
488
|
+
"Install first:",
|
|
489
|
+
"",
|
|
490
|
+
` npx ${cliPackage} add ${plan.install.join(" ")}`,
|
|
491
|
+
"",
|
|
492
|
+
`Import from \`${importFrom}\`. Each component's props are on its page under`,
|
|
493
|
+
`${docsUrl}/docs/components — read the page rather than guessing a prop name.`,
|
|
494
|
+
"",
|
|
495
|
+
"Style with semantic tokens only (bg-background, text-muted-foreground). Never raw",
|
|
496
|
+
"hex, never Tailwind's own palette — those do not follow the theme.",
|
|
497
|
+
);
|
|
498
|
+
|
|
499
|
+
return lines.join("\n");
|
|
500
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,53 @@
|
|
|
1
|
+
export {
|
|
2
|
+
blocksPathFor,
|
|
3
|
+
planUi,
|
|
4
|
+
renderBrief,
|
|
5
|
+
renderPlan,
|
|
6
|
+
type PlanEntry,
|
|
7
|
+
type PlanOptions,
|
|
8
|
+
type RenderOptions,
|
|
9
|
+
type UiPlan,
|
|
10
|
+
} from "./generate";
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
assertResolvable,
|
|
14
|
+
buildCustomRegistry,
|
|
15
|
+
defineRegistryConfig,
|
|
16
|
+
itemGroupSchema,
|
|
17
|
+
itemSourceSchema,
|
|
18
|
+
registryConfigSchema,
|
|
19
|
+
type BuildResult,
|
|
20
|
+
type ItemGroup,
|
|
21
|
+
type ItemSource,
|
|
22
|
+
type RegistryConfig,
|
|
23
|
+
} from "./custom";
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
AGENTS_MARKER_END,
|
|
27
|
+
AGENTS_MARKER_START,
|
|
28
|
+
agentsSection,
|
|
29
|
+
aiDoc,
|
|
30
|
+
componentsDoc,
|
|
31
|
+
conventionsDoc,
|
|
32
|
+
cursorRule,
|
|
33
|
+
llmsFullTxt,
|
|
34
|
+
llmsTxt,
|
|
35
|
+
skillDoc,
|
|
36
|
+
themesDoc,
|
|
37
|
+
upsertAgentsSection,
|
|
38
|
+
type AgentDocsContext,
|
|
39
|
+
} from "./agent-docs";
|
|
1
40
|
export { hashContent } from "./hash";
|
|
2
41
|
export {
|
|
3
42
|
REGISTRY_VERSION,
|
|
43
|
+
registryAccessSchema,
|
|
4
44
|
registryFileSchema,
|
|
5
45
|
registryFileTypeSchema,
|
|
6
46
|
registryIndexEntrySchema,
|
|
7
47
|
registryIndexSchema,
|
|
8
48
|
registryItemSchema,
|
|
9
49
|
registryItemTypeSchema,
|
|
50
|
+
type RegistryAccess,
|
|
10
51
|
type RegistryFile,
|
|
11
52
|
type RegistryFileType,
|
|
12
53
|
type RegistryIndex,
|
package/src/schema.ts
CHANGED
|
@@ -38,6 +38,18 @@ export const registryItemTypeSchema = z.enum([
|
|
|
38
38
|
|
|
39
39
|
export type RegistryItemType = z.infer<typeof registryItemTypeSchema>;
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Whether an item's source is public.
|
|
43
|
+
*
|
|
44
|
+
* `free` is the default and stays the default: an item that has ever been
|
|
45
|
+
* installable without a licence must never quietly become one that is not.
|
|
46
|
+
* Existing registries carry no `access` field at all, which parses as `free` —
|
|
47
|
+
* so an older registry read by a newer CLI behaves exactly as it did.
|
|
48
|
+
*/
|
|
49
|
+
export const registryAccessSchema = z.enum(["free", "pro"]).default("free");
|
|
50
|
+
|
|
51
|
+
export type RegistryAccess = z.infer<typeof registryAccessSchema>;
|
|
52
|
+
|
|
41
53
|
export const registryFileSchema = z.object({
|
|
42
54
|
/**
|
|
43
55
|
* Logical path within the registry, e.g. `ui/button.tsx`, `lib/utils.ts`.
|
|
@@ -76,10 +88,20 @@ export const registryItemSchema = z.object({
|
|
|
76
88
|
registryDependencies: z.array(z.string()),
|
|
77
89
|
files: z.array(registryFileSchema).min(1),
|
|
78
90
|
a11y: z.string().optional(),
|
|
91
|
+
access: registryAccessSchema,
|
|
79
92
|
});
|
|
80
93
|
|
|
81
94
|
export type RegistryItem = z.infer<typeof registryItemSchema>;
|
|
82
95
|
|
|
96
|
+
/**
|
|
97
|
+
* The index entry.
|
|
98
|
+
*
|
|
99
|
+
* Carries `access` so a licensed item is *listed* — with its title, what it
|
|
100
|
+
* depends on and how many files it has — while its source is not. Hiding paid
|
|
101
|
+
* items entirely would mean nobody could discover them; including their source
|
|
102
|
+
* would mean nobody needed to buy them. The index is the catalogue; the item
|
|
103
|
+
* body is the goods.
|
|
104
|
+
*/
|
|
83
105
|
export const registryIndexEntrySchema = registryItemSchema
|
|
84
106
|
.pick({
|
|
85
107
|
name: true,
|
|
@@ -90,6 +112,7 @@ export const registryIndexEntrySchema = registryItemSchema
|
|
|
90
112
|
status: true,
|
|
91
113
|
dependencies: true,
|
|
92
114
|
registryDependencies: true,
|
|
115
|
+
access: true,
|
|
93
116
|
})
|
|
94
117
|
.extend({ fileCount: z.number().int().positive() });
|
|
95
118
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-ByqIpT47.js","names":[],"sources":["../src/hash.ts","../src/schema.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\n\n/**\n * Content hash used to detect local edits to an installed file.\n *\n * Line endings are normalised before hashing so a Windows checkout does not\n * read as \"every file modified\", which would make `update` useless there.\n */\nexport function hashContent(content: string): string {\n const normalised = content.replace(/\\r\\n/g, \"\\n\");\n return `sha256:${createHash(\"sha256\").update(normalised, \"utf8\").digest(\"hex\")}`;\n}\n","import { z } from \"zod\";\n\n/**\n * The public registry contract.\n *\n * This is the boundary between the library and every consumer's project, so it\n * is validated on both sides: the build refuses to emit anything that does not\n * satisfy it, and the CLI refuses to install anything that does not parse. A\n * registry that serves malformed data breaks builds in someone else's\n * repository, where it is hardest to diagnose.\n */\n\n/** Bumped only for a breaking change to the shape below. */\nexport const REGISTRY_VERSION = 1;\n\nexport const registryFileTypeSchema = z.enum([\n /** A component. Installed under the `ui` alias. */\n \"registry:ui\",\n /** A shared utility. Installed under the `lib` alias. */\n \"registry:lib\",\n /** A hook. Installed under the `hooks` alias. */\n \"registry:hook\",\n /** A whole page section. Installed under the `blocks` alias. */\n \"registry:block\",\n /** CSS appended to the project stylesheet rather than written as a file. */\n \"registry:style\",\n]);\n\nexport type RegistryFileType = z.infer<typeof registryFileTypeSchema>;\n\nexport const registryItemTypeSchema = z.enum([\n \"registry:ui\",\n \"registry:lib\",\n \"registry:hook\",\n \"registry:theme\",\n \"registry:block\",\n]);\n\nexport type RegistryItemType = z.infer<typeof registryItemTypeSchema>;\n\nexport const registryFileSchema = z.object({\n /**\n * Logical path within the registry, e.g. `ui/button.tsx`, `lib/utils.ts`.\n *\n * The leading segment selects which of the consumer's aliases the file is\n * written under. The registry deliberately does not know the destination —\n * that depends on a project layout it has never seen.\n */\n path: z.string().min(1),\n type: registryFileTypeSchema,\n content: z.string(),\n /**\n * `sha256:<hex>` of `content` as published.\n *\n * Recorded at install time so `update` can tell an untouched file from one\n * the user has edited. This cannot be added later: an install that did not\n * record a hash leaves no way to know what it originally wrote.\n */\n hash: z.string().regex(/^sha256:[0-9a-f]{64}$/),\n});\n\nexport type RegistryFile = z.infer<typeof registryFileSchema>;\n\nexport const registryItemSchema = z.object({\n $schema: z.string().optional(),\n registryVersion: z.literal(REGISTRY_VERSION),\n name: z.string().regex(/^[a-z][a-z0-9-]*$/),\n type: registryItemTypeSchema,\n title: z.string().min(1),\n description: z.string().min(10),\n category: z.string().min(1),\n status: z.enum([\"stable\", \"beta\", \"experimental\"]),\n /** npm packages to install alongside the files. */\n dependencies: z.array(z.string()),\n /** Other registry items to install first. */\n registryDependencies: z.array(z.string()),\n files: z.array(registryFileSchema).min(1),\n a11y: z.string().optional(),\n});\n\nexport type RegistryItem = z.infer<typeof registryItemSchema>;\n\nexport const registryIndexEntrySchema = registryItemSchema\n .pick({\n name: true,\n type: true,\n title: true,\n description: true,\n category: true,\n status: true,\n dependencies: true,\n registryDependencies: true,\n })\n .extend({ fileCount: z.number().int().positive() });\n\nexport type RegistryIndexEntry = z.infer<typeof registryIndexEntrySchema>;\n\nexport const registryIndexSchema = z.object({\n $schema: z.string().optional(),\n registryVersion: z.literal(REGISTRY_VERSION),\n /** Version of the package the registry was generated from. */\n generatedFrom: z.string().min(1),\n items: z.array(regist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