@mapomodule/mcp 0.0.0-stage → 1.0.0-beta.1
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 +479 -2
- package/bin/mapo-mcp.mjs +3 -0
- package/dist/build.d.mts +18 -0
- package/dist/build.d.ts +18 -0
- package/dist/build.mjs +351 -0
- package/dist/cli.d.mts +7 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.mjs +263 -0
- package/dist/index.d.mts +68 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.mjs +1 -0
- package/dist/knowledge/api.json +1 -0
- package/dist/knowledge/docs.json +1 -0
- package/dist/module.d.mts +16 -0
- package/dist/module.d.ts +16 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +121 -0
- package/dist/runtime/core/doctor.d.ts +0 -0
- package/dist/runtime/core/doctor.js +128 -0
- package/dist/runtime/core/indexer.d.ts +0 -0
- package/dist/runtime/core/indexer.js +193 -0
- package/dist/runtime/core/knowledge.d.ts +0 -0
- package/dist/runtime/core/knowledge.js +76 -0
- package/dist/runtime/core/openapi.d.ts +0 -0
- package/dist/runtime/core/openapi.js +229 -0
- package/dist/runtime/core/prompts.d.ts +0 -0
- package/dist/runtime/core/prompts.js +108 -0
- package/dist/runtime/core/recipes.d.ts +0 -0
- package/dist/runtime/core/recipes.js +297 -0
- package/dist/runtime/core/resources.d.ts +0 -0
- package/dist/runtime/core/resources.js +88 -0
- package/dist/runtime/core/scaffold/fields.d.ts +0 -0
- package/dist/runtime/core/scaffold/fields.js +64 -0
- package/dist/runtime/core/scaffold/index.d.ts +0 -0
- package/dist/runtime/core/scaffold/index.js +74 -0
- package/dist/runtime/core/scaffold/templates.d.ts +0 -0
- package/dist/runtime/core/scaffold/templates.js +349 -0
- package/dist/runtime/core/schema-source.d.ts +0 -0
- package/dist/runtime/core/schema-source.js +70 -0
- package/dist/runtime/core/search.d.ts +0 -0
- package/dist/runtime/core/search.js +173 -0
- package/dist/runtime/core/tokenize.d.ts +0 -0
- package/dist/runtime/core/tokenize.js +96 -0
- package/dist/runtime/core/tool-spec.d.ts +0 -0
- package/dist/runtime/core/tool-spec.js +3 -0
- package/dist/runtime/core/tools/api.d.ts +0 -0
- package/dist/runtime/core/tools/api.js +192 -0
- package/dist/runtime/core/tools/app.d.ts +0 -0
- package/dist/runtime/core/tools/app.js +141 -0
- package/dist/runtime/core/tools/backend.d.ts +0 -0
- package/dist/runtime/core/tools/backend.js +143 -0
- package/dist/runtime/core/tools/docs.d.ts +0 -0
- package/dist/runtime/core/tools/docs.js +150 -0
- package/dist/runtime/core/tools/scaffold.d.ts +0 -0
- package/dist/runtime/core/tools/scaffold.js +127 -0
- package/dist/runtime/core/types.d.ts +0 -0
- package/dist/runtime/core/types.js +0 -0
- package/dist/runtime/core/write.d.ts +0 -0
- package/dist/runtime/core/write.js +53 -0
- package/dist/runtime/mcp/handlers/mapo/index.js +13 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/crud-page.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/custom-field.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/debug-form.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/migrate-v1.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/theme.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/resources/app-manifest.js +19 -0
- package/dist/runtime/mcp/handlers/mapo/resources/docs.js +34 -0
- package/dist/runtime/mcp/handlers/mapo/resources/fields.js +34 -0
- package/dist/runtime/mcp/handlers/mapo/resources/knowledge-index.js +22 -0
- package/dist/runtime/mcp/handlers/mapo/tools/backend-schema.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/component-api.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/composable-api.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/doctor.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/get-doc.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/inspect-app.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/list-field-types.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/list-recipes.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/scaffold.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/search-docs.js +3 -0
- package/dist/runtime/nitro/context.d.ts +0 -0
- package/dist/runtime/nitro/context.js +21 -0
- package/dist/runtime/nitro/to-mcp-prompt.d.ts +0 -0
- package/dist/runtime/nitro/to-mcp-prompt.js +23 -0
- package/dist/runtime/nitro/to-mcp-tool.d.ts +0 -0
- package/dist/runtime/nitro/to-mcp-tool.js +28 -0
- package/dist/runtime/types/virtual-modules.d.ts +6 -0
- package/dist/types.d.mts +9 -0
- package/package.json +73 -4
- package/src/__tests__/cli.test.ts +121 -0
- package/src/__tests__/doctor.test.ts +145 -0
- package/src/__tests__/fixtures/drf-schema.json +142 -0
- package/src/__tests__/fixtures.ts +198 -0
- package/src/__tests__/indexer.test.ts +114 -0
- package/src/__tests__/knowledge.test.ts +209 -0
- package/src/__tests__/openapi.test.ts +256 -0
- package/src/__tests__/recipes.test.ts +44 -0
- package/src/__tests__/resources.test.ts +69 -0
- package/src/__tests__/scaffold.test.ts +153 -0
- package/src/__tests__/search.test.ts +105 -0
- package/src/__tests__/tools.test.ts +226 -0
- package/src/__tests__/write.test.ts +134 -0
- package/src/build/extract-components.ts +135 -0
- package/src/build/extract-composables.ts +125 -0
- package/src/build/extract-fields.ts +250 -0
- package/src/build/index.ts +103 -0
- package/src/cli.ts +364 -0
- package/src/index.ts +65 -0
- package/src/module.ts +214 -0
- package/src/runtime/core/doctor.ts +204 -0
- package/src/runtime/core/indexer.ts +279 -0
- package/src/runtime/core/knowledge.ts +121 -0
- package/src/runtime/core/openapi.ts +417 -0
- package/src/runtime/core/prompts.ts +150 -0
- package/src/runtime/core/recipes.ts +361 -0
- package/src/runtime/core/resources.ts +144 -0
- package/src/runtime/core/scaffold/fields.ts +127 -0
- package/src/runtime/core/scaffold/index.ts +120 -0
- package/src/runtime/core/scaffold/templates.ts +394 -0
- package/src/runtime/core/schema-source.ts +123 -0
- package/src/runtime/core/search.ts +282 -0
- package/src/runtime/core/tokenize.ts +146 -0
- package/src/runtime/core/tool-spec.ts +74 -0
- package/src/runtime/core/tools/api.ts +300 -0
- package/src/runtime/core/tools/app.ts +200 -0
- package/src/runtime/core/tools/backend.ts +197 -0
- package/src/runtime/core/tools/docs.ts +215 -0
- package/src/runtime/core/tools/scaffold.ts +176 -0
- package/src/runtime/core/types.ts +133 -0
- package/src/runtime/core/write.ts +119 -0
- package/src/runtime/mcp/handlers/mapo/index.ts +22 -0
- package/src/runtime/mcp/handlers/mapo/prompts/crud-page.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/custom-field.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/debug-form.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/migrate-v1.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/theme.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/resources/app-manifest.ts +28 -0
- package/src/runtime/mcp/handlers/mapo/resources/docs.ts +41 -0
- package/src/runtime/mcp/handlers/mapo/resources/fields.ts +37 -0
- package/src/runtime/mcp/handlers/mapo/resources/knowledge-index.ts +24 -0
- package/src/runtime/mcp/handlers/mapo/tools/backend-schema.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/component-api.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/composable-api.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/doctor.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/get-doc.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/inspect-app.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/list-field-types.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/list-recipes.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/scaffold.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/search-docs.ts +4 -0
- package/src/runtime/nitro/context.ts +41 -0
- package/src/runtime/nitro/to-mcp-prompt.ts +30 -0
- package/src/runtime/nitro/to-mcp-tool.ts +35 -0
- package/src/runtime/types/virtual-modules.d.ts +6 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curated task → documentation map.
|
|
3
|
+
*
|
|
4
|
+
* BM25 answers "which section mentions these words"; it cannot answer "which
|
|
5
|
+
* page is the canonical recipe for this task" — API reference tables often win
|
|
6
|
+
* on raw term frequency. This table encodes that intent, and is the file to
|
|
7
|
+
* update when a new feature ships.
|
|
8
|
+
*/
|
|
9
|
+
import { tokenize } from "./tokenize.js";
|
|
10
|
+
|
|
11
|
+
export interface Recipe {
|
|
12
|
+
id: string;
|
|
13
|
+
/** Task phrased the way a developer would ask for it. */
|
|
14
|
+
task: string;
|
|
15
|
+
/** Extra vocabulary that should match this recipe. */
|
|
16
|
+
keywords: string[];
|
|
17
|
+
/** Canonical doc path, relative to the docs root. */
|
|
18
|
+
doc: string;
|
|
19
|
+
/** Optional section inside `doc`. */
|
|
20
|
+
heading?: string;
|
|
21
|
+
/** Related docs worth reading next. */
|
|
22
|
+
seeAlso?: string[];
|
|
23
|
+
summary: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const RECIPES: Recipe[] = [
|
|
27
|
+
{
|
|
28
|
+
id: "first-admin-page",
|
|
29
|
+
task: "Create the first admin page",
|
|
30
|
+
keywords: [
|
|
31
|
+
"scaffold",
|
|
32
|
+
"start",
|
|
33
|
+
"setup",
|
|
34
|
+
"layout",
|
|
35
|
+
"definePageMeta",
|
|
36
|
+
"dashboard",
|
|
37
|
+
"sidebar entry",
|
|
38
|
+
],
|
|
39
|
+
doc: "howto/first-admin-page.md",
|
|
40
|
+
seeAlso: ["guide/getting-started.md"],
|
|
41
|
+
summary:
|
|
42
|
+
"Page meta, mapo-default layout, auth middleware and sidebar registration.",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "crud-list",
|
|
46
|
+
task: "Build a CRUD list page",
|
|
47
|
+
keywords: [
|
|
48
|
+
"MapoList",
|
|
49
|
+
"table",
|
|
50
|
+
"columns",
|
|
51
|
+
"pagination",
|
|
52
|
+
"filters",
|
|
53
|
+
"tabs",
|
|
54
|
+
"bulk",
|
|
55
|
+
"quick edit",
|
|
56
|
+
"search",
|
|
57
|
+
"sorting",
|
|
58
|
+
],
|
|
59
|
+
doc: "howto/crud-list.md",
|
|
60
|
+
seeAlso: ["uikit/list.md"],
|
|
61
|
+
summary:
|
|
62
|
+
"MapoList with server-side pagination, filters, tabs, bulk actions and quick edit.",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: "crud-detail",
|
|
66
|
+
task: "Build a CRUD detail or edit page",
|
|
67
|
+
keywords: [
|
|
68
|
+
"MapoDetail",
|
|
69
|
+
"form",
|
|
70
|
+
"save",
|
|
71
|
+
"delete",
|
|
72
|
+
"translations",
|
|
73
|
+
"sidebar fields",
|
|
74
|
+
"patch",
|
|
75
|
+
],
|
|
76
|
+
doc: "howto/crud-detail.md",
|
|
77
|
+
seeAlso: ["uikit/detail.md", "uikit/form/index.md"],
|
|
78
|
+
summary:
|
|
79
|
+
"MapoDetail wired to useCrud, with body/sidebar field descriptors and save flow.",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: "standalone-form",
|
|
83
|
+
task: "Use the form engine outside a detail page",
|
|
84
|
+
keywords: [
|
|
85
|
+
"MapoForm",
|
|
86
|
+
"useMapoForm",
|
|
87
|
+
"standalone",
|
|
88
|
+
"modal",
|
|
89
|
+
"wizard",
|
|
90
|
+
"custom submit",
|
|
91
|
+
],
|
|
92
|
+
doc: "howto/form-standalone.md",
|
|
93
|
+
seeAlso: ["uikit/form/composable.md"],
|
|
94
|
+
summary:
|
|
95
|
+
"MapoForm / useMapoForm driven by your own state and submit handler.",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: "field-types",
|
|
99
|
+
task: "Pick a form field type",
|
|
100
|
+
keywords: [
|
|
101
|
+
"descriptor",
|
|
102
|
+
"field type",
|
|
103
|
+
"text",
|
|
104
|
+
"select",
|
|
105
|
+
"editor",
|
|
106
|
+
"repeater",
|
|
107
|
+
"seo",
|
|
108
|
+
"map",
|
|
109
|
+
"fks",
|
|
110
|
+
"m2m",
|
|
111
|
+
"datetime",
|
|
112
|
+
],
|
|
113
|
+
doc: "uikit/form/add-fields.md",
|
|
114
|
+
seeAlso: ["uikit/form/index.md"],
|
|
115
|
+
summary:
|
|
116
|
+
"Every built-in field type, the component behind it and its attrs.",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "custom-field",
|
|
120
|
+
task: "Create and register a custom field type",
|
|
121
|
+
keywords: [
|
|
122
|
+
"defineFormField",
|
|
123
|
+
"registry",
|
|
124
|
+
"custom component",
|
|
125
|
+
"mapping",
|
|
126
|
+
"own field",
|
|
127
|
+
"extend fields",
|
|
128
|
+
],
|
|
129
|
+
doc: "uikit/form/registry.md",
|
|
130
|
+
heading: "Add types globally — `defineFormField()` (recommended)",
|
|
131
|
+
seeAlso: ["uikit/form/custom-fields.md", "uikit/form/reusable-fields.md"],
|
|
132
|
+
summary:
|
|
133
|
+
"Register a component in the field registry, then use it through descriptor.type.",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
id: "form-validation",
|
|
137
|
+
task: "Validate form fields",
|
|
138
|
+
keywords: [
|
|
139
|
+
"validate",
|
|
140
|
+
"validateAsync",
|
|
141
|
+
"required",
|
|
142
|
+
"errors",
|
|
143
|
+
"rules",
|
|
144
|
+
"async validation",
|
|
145
|
+
],
|
|
146
|
+
doc: "uikit/form/validation.md",
|
|
147
|
+
summary:
|
|
148
|
+
"Sync and debounced async validation on descriptors, plus error display.",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: "form-i18n",
|
|
152
|
+
task: "Make form fields translatable",
|
|
153
|
+
keywords: [
|
|
154
|
+
"translatable",
|
|
155
|
+
"synci18n",
|
|
156
|
+
"translations",
|
|
157
|
+
"languages",
|
|
158
|
+
"lang switch",
|
|
159
|
+
],
|
|
160
|
+
doc: "uikit/form/i18n.md",
|
|
161
|
+
seeAlso: ["howto/i18n.md"],
|
|
162
|
+
summary:
|
|
163
|
+
"translatable descriptors, per-language models and the detail language switcher.",
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
id: "media-manager",
|
|
167
|
+
task: "Use the media manager and media fields",
|
|
168
|
+
keywords: [
|
|
169
|
+
"upload",
|
|
170
|
+
"image",
|
|
171
|
+
"gallery",
|
|
172
|
+
"folders",
|
|
173
|
+
"MapoMediaManager",
|
|
174
|
+
"enhanced-media",
|
|
175
|
+
"MapoDropArea",
|
|
176
|
+
],
|
|
177
|
+
doc: "howto/media-manager.md",
|
|
178
|
+
seeAlso: ["uikit/media.md"],
|
|
179
|
+
summary:
|
|
180
|
+
"Media endpoints configuration, media fields and the picker dialog.",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
id: "menu-manager",
|
|
184
|
+
task: "Build a navigation menu editor",
|
|
185
|
+
keywords: [
|
|
186
|
+
"MapoMenuManager",
|
|
187
|
+
"tree",
|
|
188
|
+
"drag and drop",
|
|
189
|
+
"nodes",
|
|
190
|
+
"navigation",
|
|
191
|
+
],
|
|
192
|
+
doc: "howto/menu-manager.md",
|
|
193
|
+
seeAlso: ["uikit/menu-manager.md"],
|
|
194
|
+
summary:
|
|
195
|
+
"Tree editor for menus with drag-and-drop nodes and per-node forms.",
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
id: "i18n",
|
|
199
|
+
task: "Translate the admin UI",
|
|
200
|
+
keywords: [
|
|
201
|
+
"locale",
|
|
202
|
+
"language",
|
|
203
|
+
"vue-i18n",
|
|
204
|
+
"catalog",
|
|
205
|
+
"useMapoT",
|
|
206
|
+
"messages",
|
|
207
|
+
],
|
|
208
|
+
doc: "howto/i18n.md",
|
|
209
|
+
seeAlso: ["modules/i18n.md"],
|
|
210
|
+
summary:
|
|
211
|
+
"Locale setup, overriding Mapo strings and adding your own catalogs.",
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
id: "auth-permissions",
|
|
215
|
+
task: "Protect routes with auth and permissions",
|
|
216
|
+
keywords: [
|
|
217
|
+
"login",
|
|
218
|
+
"middleware",
|
|
219
|
+
"roles",
|
|
220
|
+
"useCanAccessRoute",
|
|
221
|
+
"session",
|
|
222
|
+
"logout",
|
|
223
|
+
"django permissions",
|
|
224
|
+
],
|
|
225
|
+
doc: "howto/auth-permissions.md",
|
|
226
|
+
seeAlso: ["uikit/login.md"],
|
|
227
|
+
summary:
|
|
228
|
+
"Auth middleware, permission route meta and the Django-backed permission model.",
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
id: "feedback",
|
|
232
|
+
task: "Show toasts and confirm dialogs",
|
|
233
|
+
keywords: [
|
|
234
|
+
"snackbar",
|
|
235
|
+
"toast",
|
|
236
|
+
"notification",
|
|
237
|
+
"confirm",
|
|
238
|
+
"dialog",
|
|
239
|
+
"alert",
|
|
240
|
+
],
|
|
241
|
+
doc: "howto/feedback.md",
|
|
242
|
+
seeAlso: ["uikit/feedback.md"],
|
|
243
|
+
summary: "Snackbar and confirm stores, plus their root components.",
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
id: "theming",
|
|
247
|
+
task: "Theme and restyle the admin",
|
|
248
|
+
keywords: [
|
|
249
|
+
"css variables",
|
|
250
|
+
"tailwind",
|
|
251
|
+
"nuxt ui",
|
|
252
|
+
"colors",
|
|
253
|
+
"dark mode",
|
|
254
|
+
"tokens",
|
|
255
|
+
"design",
|
|
256
|
+
],
|
|
257
|
+
doc: "howto/theming.md",
|
|
258
|
+
seeAlso: ["uikit/theming.md"],
|
|
259
|
+
summary:
|
|
260
|
+
"CSS tokens, Nuxt UI defaults and where to put the override stylesheet.",
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: "override-components",
|
|
264
|
+
task: "Replace or extend a Mapo component",
|
|
265
|
+
keywords: [
|
|
266
|
+
"MapoOverride",
|
|
267
|
+
"slots",
|
|
268
|
+
"swap component",
|
|
269
|
+
"customize layout",
|
|
270
|
+
"topbar",
|
|
271
|
+
"sidebar",
|
|
272
|
+
],
|
|
273
|
+
doc: "uikit/mapoverride.md",
|
|
274
|
+
seeAlso: ["uikit/layout.md"],
|
|
275
|
+
summary:
|
|
276
|
+
"The MapoOverride system and the layout slots that avoid full replacements.",
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
id: "backend-integration",
|
|
280
|
+
task: "Connect a custom or Django backend",
|
|
281
|
+
keywords: [
|
|
282
|
+
"api",
|
|
283
|
+
"endpoints",
|
|
284
|
+
"csrf",
|
|
285
|
+
"camomilla",
|
|
286
|
+
"drf",
|
|
287
|
+
"proxy",
|
|
288
|
+
"useCrud",
|
|
289
|
+
"rest",
|
|
290
|
+
],
|
|
291
|
+
doc: "howto/backend-integration.md",
|
|
292
|
+
seeAlso: ["modules/camomilla.md", "modules/api.md"],
|
|
293
|
+
summary:
|
|
294
|
+
"Endpoint conventions, CSRF/session handling and the camomilla integration.",
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
id: "migration",
|
|
298
|
+
task: "Migrate a v1 project to v2",
|
|
299
|
+
keywords: ["v1", "upgrade", "legacy", "vuex", "axios", "breaking changes"],
|
|
300
|
+
doc: "migration/v1-to-v2.md",
|
|
301
|
+
summary: "What changed between Mapo v1 and v2 and how to port each piece.",
|
|
302
|
+
},
|
|
303
|
+
];
|
|
304
|
+
|
|
305
|
+
export interface RecipeMatch extends Recipe {
|
|
306
|
+
score: number;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const TASK_WEIGHT = 1.5;
|
|
310
|
+
const KEYWORD_WEIGHT = 1;
|
|
311
|
+
/** Roughly "two distinctive words, or one distinctive word in the task". */
|
|
312
|
+
const MATCH_THRESHOLD = 3;
|
|
313
|
+
|
|
314
|
+
interface RecipeTerms {
|
|
315
|
+
recipe: Recipe;
|
|
316
|
+
task: Set<string>;
|
|
317
|
+
keywords: Set<string>;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const RECIPE_TERMS: RecipeTerms[] = RECIPES.map((recipe) => ({
|
|
321
|
+
recipe,
|
|
322
|
+
task: new Set(tokenize(recipe.task)),
|
|
323
|
+
keywords: new Set(tokenize(recipe.keywords.join(" "))),
|
|
324
|
+
}));
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* How many recipes mention each term. Words shared by most recipes ("field",
|
|
328
|
+
* "page", "custom") carry little signal; "upload" or "permission" carry a lot.
|
|
329
|
+
*/
|
|
330
|
+
const DOCUMENT_FREQUENCY = new Map<string, number>();
|
|
331
|
+
for (const entry of RECIPE_TERMS) {
|
|
332
|
+
for (const term of new Set([...entry.task, ...entry.keywords])) {
|
|
333
|
+
DOCUMENT_FREQUENCY.set(term, (DOCUMENT_FREQUENCY.get(term) ?? 0) + 1);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function idf(term: string): number {
|
|
338
|
+
const frequency = DOCUMENT_FREQUENCY.get(term);
|
|
339
|
+
return frequency ? Math.log(1 + RECIPES.length / frequency) : 0;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Weighted term overlap over task + keywords; returns only confident hits. */
|
|
343
|
+
export function matchRecipes(query: string, limit = 2): RecipeMatch[] {
|
|
344
|
+
const queryTerms = new Set(tokenize(query));
|
|
345
|
+
if (!queryTerms.size) return [];
|
|
346
|
+
|
|
347
|
+
const matches: RecipeMatch[] = [];
|
|
348
|
+
|
|
349
|
+
for (const { recipe, task, keywords } of RECIPE_TERMS) {
|
|
350
|
+
let score = 0;
|
|
351
|
+
for (const term of queryTerms) {
|
|
352
|
+
if (task.has(term)) score += TASK_WEIGHT * idf(term);
|
|
353
|
+
else if (keywords.has(term)) score += KEYWORD_WEIGHT * idf(term);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (score >= MATCH_THRESHOLD)
|
|
357
|
+
matches.push({ ...recipe, score: Number(score.toFixed(2)) });
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return matches.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
361
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource payloads, shared by both transports.
|
|
3
|
+
*
|
|
4
|
+
* Resources are what a client can attach to the conversation without calling a
|
|
5
|
+
* tool, so they carry whole documents: a doc page, the contract of a field
|
|
6
|
+
* type, or the index of everything available.
|
|
7
|
+
*/
|
|
8
|
+
import { RECIPES } from "./recipes.js";
|
|
9
|
+
import { getDoc, listDocs } from "./search.js";
|
|
10
|
+
import type { ApiKnowledge, DocsKnowledge } from "./types.js";
|
|
11
|
+
|
|
12
|
+
export const DOCS_URI_PREFIX = "mapo://docs/";
|
|
13
|
+
export const FIELD_URI_PREFIX = "mapo://fields/";
|
|
14
|
+
export const INDEX_URI = "mapo://knowledge/index";
|
|
15
|
+
export const MANIFEST_URI = "mapo://app/manifest";
|
|
16
|
+
|
|
17
|
+
/** Everything the knowledge base contains, as a compact browsable map. */
|
|
18
|
+
export function renderKnowledgeIndex(
|
|
19
|
+
knowledge: DocsKnowledge,
|
|
20
|
+
api: ApiKnowledge,
|
|
21
|
+
): string {
|
|
22
|
+
const pages = listDocs(knowledge)
|
|
23
|
+
.map(
|
|
24
|
+
(doc) =>
|
|
25
|
+
`- \`${doc.path}\` — ${doc.title} (${doc.headings.length} sections)`,
|
|
26
|
+
)
|
|
27
|
+
.join("\n");
|
|
28
|
+
|
|
29
|
+
const recipes = RECIPES.map(
|
|
30
|
+
(recipe) => `- ${recipe.task} → \`${recipe.doc}\``,
|
|
31
|
+
).join("\n");
|
|
32
|
+
|
|
33
|
+
const components = api.components
|
|
34
|
+
.map((component) => component.name)
|
|
35
|
+
.join(", ");
|
|
36
|
+
const fields = api.fieldTypes.map((field) => field.type).join(", ");
|
|
37
|
+
const composables = api.composables
|
|
38
|
+
.map((composable) => composable.name)
|
|
39
|
+
.join(", ");
|
|
40
|
+
|
|
41
|
+
return [
|
|
42
|
+
"# Mapo knowledge base",
|
|
43
|
+
"",
|
|
44
|
+
`Generated ${knowledge.generatedAt}.`,
|
|
45
|
+
"",
|
|
46
|
+
"## Recipes",
|
|
47
|
+
recipes,
|
|
48
|
+
"",
|
|
49
|
+
"## Documentation pages",
|
|
50
|
+
pages,
|
|
51
|
+
"",
|
|
52
|
+
"## Components",
|
|
53
|
+
components,
|
|
54
|
+
"",
|
|
55
|
+
"## Field types",
|
|
56
|
+
fields,
|
|
57
|
+
"",
|
|
58
|
+
"## Auto-imported composables",
|
|
59
|
+
composables,
|
|
60
|
+
].join("\n");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One documentation page, whole. */
|
|
64
|
+
export function renderDocResource(
|
|
65
|
+
knowledge: DocsKnowledge,
|
|
66
|
+
path: string,
|
|
67
|
+
): string | null {
|
|
68
|
+
const doc = getDoc(knowledge, path, { maxChars: 100_000 });
|
|
69
|
+
if (!doc) return null;
|
|
70
|
+
return `# ${doc.title}\n\nsource: \`${doc.path}\`\n\n${doc.content}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The full contract of a field type: attrs, defaults, component, docs. */
|
|
74
|
+
export function renderFieldResource(
|
|
75
|
+
api: ApiKnowledge,
|
|
76
|
+
type: string,
|
|
77
|
+
): string | null {
|
|
78
|
+
const field = api.fieldTypes.find((entry) => entry.type === type);
|
|
79
|
+
if (!field) return null;
|
|
80
|
+
|
|
81
|
+
const attrs = field.attrs.length
|
|
82
|
+
? field.attrs
|
|
83
|
+
.map(
|
|
84
|
+
(attr) =>
|
|
85
|
+
`- \`${attr.name}\`${attr.type ? `: ${attr.type}` : ""}${attr.required ? " (required)" : ""}` +
|
|
86
|
+
`${attr.description ? ` — ${attr.description}` : ""}`,
|
|
87
|
+
)
|
|
88
|
+
.join("\n")
|
|
89
|
+
: "_none_";
|
|
90
|
+
|
|
91
|
+
const common = api.fieldCommon
|
|
92
|
+
.map((member) => `\`${member.name}\``)
|
|
93
|
+
.join(", ");
|
|
94
|
+
|
|
95
|
+
return [
|
|
96
|
+
`# Field type \`${field.type}\``,
|
|
97
|
+
"",
|
|
98
|
+
field.description ?? "",
|
|
99
|
+
"",
|
|
100
|
+
`- component: ${field.component ?? "(unmapped)"}`,
|
|
101
|
+
`- descriptor: ${field.descriptor ?? "(none)"}`,
|
|
102
|
+
field.defaultAttrs
|
|
103
|
+
? `- registry default attrs: \`${JSON.stringify(field.defaultAttrs)}\``
|
|
104
|
+
: "",
|
|
105
|
+
"",
|
|
106
|
+
"## attrs",
|
|
107
|
+
attrs,
|
|
108
|
+
"",
|
|
109
|
+
"## Shared descriptor properties",
|
|
110
|
+
common,
|
|
111
|
+
"",
|
|
112
|
+
field.docs.length
|
|
113
|
+
? `## Docs\n${field.docs.map((doc) => `- \`${doc}\``).join("\n")}`
|
|
114
|
+
: "",
|
|
115
|
+
]
|
|
116
|
+
.filter(Boolean)
|
|
117
|
+
.join("\n");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Doc pages as resource entries, for clients that list what is attachable. */
|
|
121
|
+
export function docResourceList(
|
|
122
|
+
knowledge: DocsKnowledge,
|
|
123
|
+
): Array<{ uri: string; name: string; description: string; mimeType: string }> {
|
|
124
|
+
return listDocs(knowledge).map((doc) => ({
|
|
125
|
+
uri: `${DOCS_URI_PREFIX}${doc.path}`,
|
|
126
|
+
name: doc.title,
|
|
127
|
+
description: `${doc.section} · ${doc.headings.slice(0, 5).join(", ")}`,
|
|
128
|
+
mimeType: "text/markdown",
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Field types as resource entries. */
|
|
133
|
+
export function fieldResourceList(
|
|
134
|
+
api: ApiKnowledge,
|
|
135
|
+
): Array<{ uri: string; name: string; description: string; mimeType: string }> {
|
|
136
|
+
return api.fieldTypes.map((field) => ({
|
|
137
|
+
uri: `${FIELD_URI_PREFIX}${field.type}`,
|
|
138
|
+
name: `Field type: ${field.type}`,
|
|
139
|
+
description:
|
|
140
|
+
field.description ??
|
|
141
|
+
`Rendered by ${field.component ?? "a custom component"}`,
|
|
142
|
+
mimeType: "text/markdown",
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field specs: the compact syntax the scaffold tool accepts for descriptors.
|
|
3
|
+
*
|
|
4
|
+
* `"title:text:Title"` → `{ key: "title", type: "text", label: "Title" }`.
|
|
5
|
+
* Types are validated against the registry extracted from source, so the
|
|
6
|
+
* scaffold can never emit a field type that does not exist.
|
|
7
|
+
*/
|
|
8
|
+
import type { ApiKnowledge } from "../types.js";
|
|
9
|
+
|
|
10
|
+
export interface ParsedField {
|
|
11
|
+
key: string;
|
|
12
|
+
type: string;
|
|
13
|
+
label: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class UnknownFieldTypeError extends Error {
|
|
17
|
+
constructor(
|
|
18
|
+
readonly type: string,
|
|
19
|
+
readonly available: string[],
|
|
20
|
+
) {
|
|
21
|
+
super(
|
|
22
|
+
`Unknown field type "${type}". Registered types: ${available.join(", ")}. ` +
|
|
23
|
+
`Custom types are added with defineFormField() — see uikit/form/registry.md.`,
|
|
24
|
+
);
|
|
25
|
+
this.name = "UnknownFieldTypeError";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* `published_at` / `coverImage` → `Published at` / `Cover image`.
|
|
31
|
+
* Sentence case, not Title Case: it is what the rest of the admin uses, and an
|
|
32
|
+
* explicit label is one `:` away when the guess is wrong.
|
|
33
|
+
*/
|
|
34
|
+
export function humanise(key: string): string {
|
|
35
|
+
return key
|
|
36
|
+
.replace(/[_-]+/g, " ")
|
|
37
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
38
|
+
.replace(/\s+/g, " ")
|
|
39
|
+
.trim()
|
|
40
|
+
.toLowerCase()
|
|
41
|
+
.replace(/^./, (char) => char.toUpperCase());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param specs `key[:type[:label]]`, type defaults to `text`
|
|
46
|
+
* @param api when given, unknown types are rejected instead of generated
|
|
47
|
+
*/
|
|
48
|
+
export function parseFields(
|
|
49
|
+
specs: string[],
|
|
50
|
+
api?: ApiKnowledge,
|
|
51
|
+
): ParsedField[] {
|
|
52
|
+
const known = api ? new Set(api.fieldTypes.map((field) => field.type)) : null;
|
|
53
|
+
|
|
54
|
+
return specs.map((spec) => {
|
|
55
|
+
const [key = "", type = "text", ...rest] = spec.split(":");
|
|
56
|
+
if (!key.trim()) throw new Error(`Empty field key in "${spec}".`);
|
|
57
|
+
|
|
58
|
+
if (known && !known.has(type)) {
|
|
59
|
+
throw new UnknownFieldTypeError(type, [...known].sort());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
key: key.trim(),
|
|
64
|
+
type: type.trim(),
|
|
65
|
+
label: rest.join(":").trim() || humanise(key.trim()),
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Attrs a field type cannot work without, so the skeleton is honest about them. */
|
|
71
|
+
function requiredAttrs(type: string, api?: ApiKnowledge): string[] {
|
|
72
|
+
const field = api?.fieldTypes.find((entry) => entry.type === type);
|
|
73
|
+
return (field?.attrs ?? [])
|
|
74
|
+
.filter((attr) => attr.required)
|
|
75
|
+
.map((attr) => attr.name);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Renders a descriptor array literal, indented to sit inside a `const`. */
|
|
79
|
+
export function renderDescriptors(
|
|
80
|
+
fields: ParsedField[],
|
|
81
|
+
api: ApiKnowledge | undefined,
|
|
82
|
+
indent = " ",
|
|
83
|
+
): string {
|
|
84
|
+
return fields
|
|
85
|
+
.map((field) => {
|
|
86
|
+
const attrs = requiredAttrs(field.type, api);
|
|
87
|
+
const attrsLine = attrs.length
|
|
88
|
+
? `\n${indent} attrs: { ${attrs.map((name) => `${name}: undefined /* TODO */`).join(", ")} },`
|
|
89
|
+
: "";
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
`${indent}{\n` +
|
|
93
|
+
`${indent} key: "${field.key}",\n` +
|
|
94
|
+
`${indent} type: "${field.type}",\n` +
|
|
95
|
+
`${indent} label: "${field.label}",${attrsLine}\n` +
|
|
96
|
+
`${indent}},`
|
|
97
|
+
);
|
|
98
|
+
})
|
|
99
|
+
.join("\n");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Interface members for the model type, inferred from the field types. */
|
|
103
|
+
export function renderModel(fields: ParsedField[]): string {
|
|
104
|
+
const tsType = (type: string): string => {
|
|
105
|
+
if (["number", "slider"].includes(type)) return "number";
|
|
106
|
+
if (["boolean", "switch"].includes(type)) return "boolean";
|
|
107
|
+
if (
|
|
108
|
+
[
|
|
109
|
+
"fks",
|
|
110
|
+
"m2m",
|
|
111
|
+
"media",
|
|
112
|
+
"media-m2m",
|
|
113
|
+
"enhanced-media",
|
|
114
|
+
"repeater",
|
|
115
|
+
"seo",
|
|
116
|
+
"map",
|
|
117
|
+
].includes(type)
|
|
118
|
+
) {
|
|
119
|
+
return "unknown";
|
|
120
|
+
}
|
|
121
|
+
return "string";
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return fields
|
|
125
|
+
.map((field) => ` ${field.key}: ${tsType(field.type)};`)
|
|
126
|
+
.join("\n");
|
|
127
|
+
}
|