@mapomodule/mcp 1.0.0-beta.3 → 1.0.0-experimental.2

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.
Files changed (50) hide show
  1. package/README.md +26 -24
  2. package/dist/build.mjs +66 -4
  3. package/dist/cli.mjs +8 -1
  4. package/dist/knowledge/api.json +1 -1
  5. package/dist/knowledge/docs.json +1 -1
  6. package/dist/module.json +1 -1
  7. package/dist/runtime/core/ai-setup/catalog.d.ts +0 -0
  8. package/dist/runtime/core/ai-setup/catalog.js +428 -0
  9. package/dist/runtime/core/ai-setup/index.d.ts +0 -0
  10. package/dist/runtime/core/ai-setup/index.js +20 -0
  11. package/dist/runtime/core/ai-setup/plan.d.ts +0 -0
  12. package/dist/runtime/core/ai-setup/plan.js +642 -0
  13. package/dist/runtime/core/ai-setup/questions.d.ts +0 -0
  14. package/dist/runtime/core/ai-setup/questions.js +237 -0
  15. package/dist/runtime/core/indexer.js +10 -3
  16. package/dist/runtime/core/instructions.js +3 -2
  17. package/dist/runtime/core/prompts.js +25 -1
  18. package/dist/runtime/core/recipes.js +407 -3
  19. package/dist/runtime/core/search.js +2 -1
  20. package/dist/runtime/core/tools/ai.d.ts +0 -0
  21. package/dist/runtime/core/tools/ai.js +125 -0
  22. package/dist/runtime/core/tools/api.js +7 -1
  23. package/dist/runtime/mcp/handlers/mapo/prompts/ai-setup.js +3 -0
  24. package/dist/runtime/mcp/handlers/mapo/tools/ai-setup.js +3 -0
  25. package/package.json +1 -1
  26. package/src/__tests__/aiSetup.test.ts +330 -0
  27. package/src/__tests__/cli.test.ts +1 -0
  28. package/src/__tests__/composables.test.ts +95 -0
  29. package/src/__tests__/indexer.test.ts +19 -0
  30. package/src/__tests__/knowledge.test.ts +48 -0
  31. package/src/__tests__/overview.test.ts +11 -0
  32. package/src/__tests__/recipes.test.ts +83 -0
  33. package/src/__tests__/search.test.ts +16 -0
  34. package/src/__tests__/tools.test.ts +27 -1
  35. package/src/build/extract-components.ts +33 -5
  36. package/src/build/extract-composables.ts +65 -2
  37. package/src/cli.ts +8 -1
  38. package/src/runtime/core/ai-setup/catalog.ts +492 -0
  39. package/src/runtime/core/ai-setup/index.ts +29 -0
  40. package/src/runtime/core/ai-setup/plan.ts +710 -0
  41. package/src/runtime/core/ai-setup/questions.ts +290 -0
  42. package/src/runtime/core/indexer.ts +16 -4
  43. package/src/runtime/core/instructions.ts +3 -2
  44. package/src/runtime/core/prompts.ts +28 -0
  45. package/src/runtime/core/recipes.ts +428 -3
  46. package/src/runtime/core/search.ts +4 -1
  47. package/src/runtime/core/tools/ai.ts +209 -0
  48. package/src/runtime/core/tools/api.ts +8 -0
  49. package/src/runtime/mcp/handlers/mapo/prompts/ai-setup.ts +4 -0
  50. package/src/runtime/mcp/handlers/mapo/tools/ai-setup.ts +4 -0
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mapomodule/mcp",
3
3
  "configKey": "mapoMcp",
4
- "version": "1.0.0-beta.3",
4
+ "version": "1.0.0-experimental.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
File without changes
@@ -0,0 +1,428 @@
1
+ import { RECIPES } from "../recipes.js";
2
+ export const AI_AREAS = [
3
+ "Magic Fill",
4
+ "Filling from code",
5
+ "Sources",
6
+ "Providers and models",
7
+ "Keys and tokens",
8
+ "People and rules",
9
+ "Costs and limits",
10
+ "Production"
11
+ ];
12
+ function fromRecipe(id, area) {
13
+ const recipe = RECIPES.find((one) => one.id === id);
14
+ if (!recipe) throw new Error(`No recipe "${id}" for the AI catalog`);
15
+ return {
16
+ id,
17
+ area,
18
+ title: recipe.task,
19
+ doc: recipe.doc,
20
+ ...recipe.heading ? { heading: recipe.heading } : {}
21
+ };
22
+ }
23
+ const AI_DOC = "modules/ai.md";
24
+ const MAGIC_FILL_DOC = "howto/magic-fill.md";
25
+ export const AI_TOPICS = [
26
+ fromRecipe("ai-magic-fill", "Magic Fill"),
27
+ {
28
+ id: "prepare-fields",
29
+ area: "Magic Fill",
30
+ title: "Prepare the fields: a hint for the model, a field kept from the AI, a relation never listed",
31
+ doc: MAGIC_FILL_DOC,
32
+ heading: "3. Prepare the fields"
33
+ },
34
+ {
35
+ id: "turn-off",
36
+ area: "Magic Fill",
37
+ title: "Turn Magic Fill off on a page, or in the whole app",
38
+ doc: MAGIC_FILL_DOC,
39
+ heading: "4. Turn it off"
40
+ },
41
+ {
42
+ id: "no-quotes",
43
+ area: "Magic Fill",
44
+ title: "Ask the AI for no quotes on a page: every value then waits",
45
+ doc: MAGIC_FILL_DOC,
46
+ heading: "Ask for no quotes"
47
+ },
48
+ {
49
+ id: "errors",
50
+ area: "Magic Fill",
51
+ title: "What each error means, and what the operator does about it",
52
+ doc: MAGIC_FILL_DOC,
53
+ heading: "5. When something goes wrong"
54
+ },
55
+ {
56
+ id: "accessibility",
57
+ area: "Magic Fill",
58
+ title: "Keyboard, screen readers and reduced motion",
59
+ doc: MAGIC_FILL_DOC,
60
+ heading: "7. Accessibility"
61
+ },
62
+ {
63
+ id: "customize",
64
+ area: "Magic Fill",
65
+ title: "Replace a part of Magic Fill, or build a panel of your own",
66
+ doc: MAGIC_FILL_DOC,
67
+ heading: "8. Customize it"
68
+ },
69
+ fromRecipe("ai-fill", "Filling from code"),
70
+ fromRecipe("ai-run", "Filling from code"),
71
+ fromRecipe("ai-field-options", "Filling from code"),
72
+ {
73
+ id: "related-records",
74
+ area: "Filling from code",
75
+ title: "Find related records: a few listed for the AI, the others searched by name",
76
+ doc: AI_DOC,
77
+ heading: "Related records"
78
+ },
79
+ fromRecipe("ai-read-files", "Sources"),
80
+ fromRecipe("ai-read-links", "Sources"),
81
+ fromRecipe("ai-readers", "Sources"),
82
+ fromRecipe("ai-providers", "Providers and models"),
83
+ {
84
+ id: "mock",
85
+ area: "Providers and models",
86
+ title: "Develop and test with the mock: no key, no network, no cost",
87
+ doc: AI_DOC,
88
+ heading: "The mock"
89
+ },
90
+ fromRecipe("ai-cloud-models", "Providers and models"),
91
+ fromRecipe("ai-local-models", "Providers and models"),
92
+ {
93
+ id: "own-provider",
94
+ area: "Providers and models",
95
+ title: "Call another AI service, with a provider of the app's own",
96
+ doc: AI_DOC,
97
+ heading: "Your own provider"
98
+ },
99
+ fromRecipe("ai-keys", "Keys and tokens"),
100
+ {
101
+ id: "personal-tokens",
102
+ area: "Keys and tokens",
103
+ title: "Let users save their own token, where an assignment allows it",
104
+ doc: AI_DOC,
105
+ heading: "Personal tokens"
106
+ },
107
+ {
108
+ id: "secret",
109
+ area: "Keys and tokens",
110
+ title: "Seal the keys, tokens and settings with NUXT_MAPO_AI_SECRET",
111
+ doc: AI_DOC,
112
+ heading: "Set the secret"
113
+ },
114
+ {
115
+ id: "restrict-users",
116
+ area: "People and rules",
117
+ title: "Choose who may use the AI: groups, permissions, or a rule of the backend",
118
+ doc: AI_DOC,
119
+ heading: "Restrict who uses the AI"
120
+ },
121
+ {
122
+ id: "admins",
123
+ area: "People and rules",
124
+ title: "Choose who administers the AI",
125
+ doc: AI_DOC,
126
+ heading: "Admins"
127
+ },
128
+ {
129
+ id: "app-rules",
130
+ area: "People and rules",
131
+ title: "Give the AI the app's rules, in every prompt or by entity",
132
+ doc: AI_DOC,
133
+ heading: "Add the app's rules"
134
+ },
135
+ fromRecipe("ai-settings", "People and rules"),
136
+ fromRecipe("ai-admin-settings", "People and rules"),
137
+ {
138
+ id: "verification",
139
+ area: "People and rules",
140
+ title: "Decide what a quote must hold for a value to count as verified",
141
+ doc: AI_DOC,
142
+ heading: "Verification"
143
+ },
144
+ fromRecipe("ai-usage", "Costs and limits"),
145
+ {
146
+ id: "limits",
147
+ area: "Costs and limits",
148
+ title: "Limit the calls per user and minute, the source's length and the files' size",
149
+ doc: AI_DOC,
150
+ heading: "Limits"
151
+ },
152
+ {
153
+ id: "prompt-cache",
154
+ area: "Costs and limits",
155
+ title: "Pay less for the part of the prompt that repeats, with the cache",
156
+ doc: AI_DOC,
157
+ heading: "The prompt cache"
158
+ },
159
+ {
160
+ id: "enable",
161
+ area: "Production",
162
+ title: "Turn the module on with `mapo.ai`",
163
+ doc: AI_DOC,
164
+ heading: "Enable the module"
165
+ },
166
+ {
167
+ id: "storage",
168
+ area: "Production",
169
+ title: "Keep the AI's sealed state: one disk, a shared store for several instances",
170
+ doc: AI_DOC,
171
+ heading: "Where the state is kept"
172
+ },
173
+ {
174
+ id: "audit",
175
+ area: "Production",
176
+ title: "An audit of every call, metadata only, never the source",
177
+ doc: AI_DOC,
178
+ heading: "The audit"
179
+ }
180
+ ];
181
+ export const AI_VERDICTS = {
182
+ ready: "Yes, out of the box",
183
+ "app-code": "Yes, with code of the app",
184
+ "not-yet": "Not yet",
185
+ no: "No"
186
+ };
187
+ export const AI_NEED_IDS = [
188
+ "fill-record",
189
+ "extract-records",
190
+ "files",
191
+ "links",
192
+ "web-search",
193
+ "pdf-images",
194
+ "own-format",
195
+ "related-records",
196
+ "private-relations",
197
+ "exclude-fields",
198
+ "hints",
199
+ "translations",
200
+ "lists",
201
+ "review",
202
+ "save-without-review",
203
+ "generate-content",
204
+ "chat",
205
+ "custom-panel",
206
+ "cloud",
207
+ "local-only",
208
+ "own-provider",
209
+ "team-keys",
210
+ "personal-tokens",
211
+ "costs",
212
+ "limits",
213
+ "restrict-users",
214
+ "app-rules",
215
+ "admin-settings",
216
+ "audit"
217
+ ];
218
+ export const AI_NEEDS = [
219
+ {
220
+ id: "fill-record",
221
+ need: "Fill the record an operator is editing from a text or files",
222
+ verdict: "ready",
223
+ how: "Magic Fill, on every `MapoDetail` of an app with uikit: a button in the sidebar card, a panel for the source, a banner that previews every value. A value goes into an empty field by itself only when a quote of the source proves it; every other value waits for the operator.",
224
+ topics: ["ai-magic-fill", "ai-fill"]
225
+ },
226
+ {
227
+ id: "extract-records",
228
+ need: "Create several records from one source, such as a programme or a sheet",
229
+ verdict: "app-code",
230
+ how: 'A page of the app calls `POST /_mapo/ai/run` with `task: "extract"` and the fields from `mapoAiFieldsSchema(fields)`, shows what came back, and creates the records the operator ticks and confirms. Mapo has no import page of its own yet: Import AI is planned.',
231
+ topics: ["ai-run", "ai-field-options"]
232
+ },
233
+ {
234
+ id: "files",
235
+ need: "Start from web pages, Markdown, CSV, Excel or JSON files",
236
+ verdict: "ready",
237
+ how: "The gateway's `read` turns a file into text with Mapo's readers; Magic Fill's panel takes files, and `useMapoAiRead()` does it in a component of the app.",
238
+ topics: ["ai-read-files"]
239
+ },
240
+ {
241
+ id: "links",
242
+ need: "Start from the link of a web page",
243
+ verdict: "ready",
244
+ how: "The gateway's `read/link` fetches the page from the app's server, without the operator's session, and reads it as a file; links are on by default, and a guard refuses the server's own and private networks. Magic Fill's panel takes links, `useMapoAiRead().readLink()` does it in a component; `mapo.ai.web.allow` opens an intranet's hosts, `mapo.ai.readers.link: false` turns links off.",
245
+ topics: ["ai-read-links"]
246
+ },
247
+ {
248
+ id: "web-search",
249
+ need: "Search the web for the source",
250
+ verdict: "not-yet",
251
+ how: "Mapo does not search the web. The operator can give the link of each page instead (`read/link`), or the app can search in a page of its own and send the pages' links.",
252
+ topics: ["ai-read-links"]
253
+ },
254
+ {
255
+ id: "pdf-images",
256
+ need: "Start from PDFs, scans or images",
257
+ verdict: "not-yet",
258
+ how: "Mapo does not read them yet. Meanwhile a reader of the app (`registerMapoAiReader()`) can turn them into text with a library the app installs: the AI takes text only.",
259
+ topics: ["ai-readers"]
260
+ },
261
+ {
262
+ id: "own-format",
263
+ need: "Start from a format of the app's own, such as a calendar or an export",
264
+ verdict: "app-code",
265
+ how: "`registerMapoAiReader()` in a Nitro plugin adds a format, or replaces one of Mapo's; the `mapo-ai:read` hook touches up what any reader read, and `mapo.ai.readers` turns a format off.",
266
+ topics: ["ai-readers"]
267
+ },
268
+ {
269
+ id: "related-records",
270
+ need: "Pick related records: categories, tags, authors",
271
+ verdict: "ready",
272
+ how: "A relation with up to 50 records is listed for the AI, which picks one; a larger one is searched by the name the AI writes, with the endpoint's `?search=`. Several matches wait on the field's mark, with candidates to pick.",
273
+ topics: ["related-records"]
274
+ },
275
+ {
276
+ id: "private-relations",
277
+ need: "Keep the names of related records, such as people's emails, from the provider",
278
+ verdict: "ready",
279
+ how: "`ai: { list: false }` on the field: its records are never listed for the AI, which writes what it reads; Magic Fill searches it afterwards, in the browser.",
280
+ topics: ["ai-field-options", "prepare-fields"]
281
+ },
282
+ {
283
+ id: "exclude-fields",
284
+ need: "Keep some fields away from the AI",
285
+ verdict: "ready",
286
+ how: "`ai: { exclude: true }` on the field, or `x-mapo-ai` in the backend's schema. Fields named as secrets (Mapo's words, `mapo.ai.secretWords`, the admins' own), read-only fields and media are left out by themselves.",
287
+ topics: ["ai-field-options", "prepare-fields"]
288
+ },
289
+ {
290
+ id: "hints",
291
+ need: "Tell the AI how to fill a field",
292
+ verdict: "ready",
293
+ how: "`ai: { hint }` on the field: the model reads it as the field's description, in the schema of its answer.",
294
+ topics: ["ai-field-options", "prepare-fields"]
295
+ },
296
+ {
297
+ id: "translations",
298
+ need: "Fill the languages of translatable fields",
299
+ verdict: "ready",
300
+ how: "Magic Fill fills the language the form shows; a `synci18n` value goes into every language. Each language is one extraction.",
301
+ topics: ["ai-magic-fill"]
302
+ },
303
+ {
304
+ id: "lists",
305
+ need: "Fill repeaters, blocks and lists of items",
306
+ verdict: "ready",
307
+ how: "The items the AI finds are ticked one by one in the preview, and go after the record's own; an item the record holds is never added twice.",
308
+ topics: ["ai-magic-fill"]
309
+ },
310
+ {
311
+ id: "review",
312
+ need: "Let the operator check every value before saving",
313
+ verdict: "ready",
314
+ how: "By design: each value shows the words of the source that prove it; a value without proof, or one that would replace the record's, waits for the operator's tick. Undo all puts the form back, and nothing is saved until Save.",
315
+ topics: ["ai-magic-fill"]
316
+ },
317
+ {
318
+ id: "save-without-review",
319
+ need: "Save the AI's values without an operator",
320
+ verdict: "no",
321
+ how: "By design: the gateway never writes to the backend, and Magic Fill fills the form, never saves it. An app that creates records from an extraction does it after the operator confirms.",
322
+ topics: ["ai-magic-fill"]
323
+ },
324
+ {
325
+ id: "generate-content",
326
+ need: "Write content the source does not hold, such as copy or SEO texts from nothing",
327
+ verdict: "no",
328
+ how: "Magic Fill takes values from a source: a value no quote proves waits as a proposal without proof, never goes in by itself. Writing new text is not its job.",
329
+ topics: ["verification"]
330
+ },
331
+ {
332
+ id: "chat",
333
+ need: "A conversational assistant, or an agent that acts in the backoffice",
334
+ verdict: "no",
335
+ how: "The module fills forms from sources; it has no chat and no agent.",
336
+ topics: ["ai-magic-fill"]
337
+ },
338
+ {
339
+ id: "custom-panel",
340
+ need: "A panel or a flow of the app's own",
341
+ verdict: "app-code",
342
+ how: "`useMapoAiFill()` and `useMapoAiRead()` in a detail extension do what Magic Fill does, with the app's interface; or one part of Magic Fill is replaced with MapoOverride.",
343
+ topics: ["customize", "ai-fill"]
344
+ },
345
+ {
346
+ id: "cloud",
347
+ need: "Use OpenAI or Anthropic (Claude) models",
348
+ verdict: "ready",
349
+ how: "The `openai` and `anthropic` providers, with a key in the server's environment or assigned by the AI's admins.",
350
+ topics: ["ai-cloud-models"]
351
+ },
352
+ {
353
+ id: "local-only",
354
+ need: "Keep every source on the company's own servers",
355
+ verdict: "ready",
356
+ how: "The `ollama` and `openai-compatible` providers call models on the app's own servers (Ollama, LM Studio, vLLM, llama.cpp), at the address the app sets; no key, no cost per token.",
357
+ topics: ["ai-local-models"]
358
+ },
359
+ {
360
+ id: "own-provider",
361
+ need: "Use another AI service",
362
+ verdict: "app-code",
363
+ how: "`registerMapoAiProvider()` in a Nitro plugin, enabled in `mapo.ai.providers`; its key comes from the environment like Mapo's providers.",
364
+ topics: ["own-provider", "ai-providers"]
365
+ },
366
+ {
367
+ id: "team-keys",
368
+ need: "Give teams their own keys and models",
369
+ verdict: "ready",
370
+ how: "On the AI settings page the AI's admins assign a key and the models to everyone, a group or a user, in an order of the groups; no deploy, and the keys are sealed in the storage.",
371
+ topics: ["ai-keys", "ai-settings"]
372
+ },
373
+ {
374
+ id: "personal-tokens",
375
+ need: "Let operators bring their own key",
376
+ verdict: "ready",
377
+ how: "An assignment of the admins allows personal tokens; each user saves theirs on the AI settings page, and their calls use it first.",
378
+ topics: ["personal-tokens", "ai-keys"]
379
+ },
380
+ {
381
+ id: "costs",
382
+ need: "Know how much the AI is used and what it costs",
383
+ verdict: "ready",
384
+ how: "The usage, read from the audit, by user, model and day, in tokens, and in money where `mapo.ai.prices` prices the models. The admins read everyone's, each user their own.",
385
+ topics: ["ai-usage"]
386
+ },
387
+ {
388
+ id: "limits",
389
+ need: "Cap how much a user can call the AI",
390
+ verdict: "ready",
391
+ how: "`mapo.ai.limits`: calls per user and minute (counted by each server process), the source's characters, the files' bytes. There is no spending cap per month yet.",
392
+ topics: ["limits"]
393
+ },
394
+ {
395
+ id: "restrict-users",
396
+ need: "Choose who may use the AI",
397
+ verdict: "ready",
398
+ how: "`mapo.ai.users` by groups or permissions; the `mapo-ai:user` hook for a rule of the backend, such as internal accounts only.",
399
+ topics: ["restrict-users"]
400
+ },
401
+ {
402
+ id: "app-rules",
403
+ need: "Rules the AI follows in every prompt",
404
+ verdict: "ready",
405
+ how: "`mapo.ai.instructions` (for every task, for fill, for extract), the `mapo-ai:prompt` hook for rules by entity or user, and the admins' instructions on the AI settings page.",
406
+ topics: ["app-rules", "ai-admin-settings"]
407
+ },
408
+ {
409
+ id: "admin-settings",
410
+ need: "Change how the AI works without a deploy",
411
+ verdict: "ready",
412
+ how: "The AI's admins change the instructions, the rules of verification, the secret words, the prompt cache, Anthropic's fallbacks and the models added, within what the app allows.",
413
+ topics: ["ai-admin-settings"]
414
+ },
415
+ {
416
+ id: "audit",
417
+ need: "Know who called the AI, and when",
418
+ verdict: "ready",
419
+ how: "Every call is audited in the sealed storage: who, which model, the tokens, the outcome; never the source, the instructions or the values.",
420
+ topics: ["audit"]
421
+ }
422
+ ];
423
+ export function aiTopic(id) {
424
+ return AI_TOPICS.find((topic) => topic.id === id);
425
+ }
426
+ export function topicLink(topic) {
427
+ return topic.heading ? `\`${topic.doc}\` \u203A ${topic.heading}` : `\`${topic.doc}\``;
428
+ }
File without changes
@@ -0,0 +1,20 @@
1
+ export {
2
+ AI_AREAS,
3
+ AI_NEEDS,
4
+ AI_NEED_IDS,
5
+ AI_TOPICS,
6
+ AI_VERDICTS,
7
+ aiTopic,
8
+ topicLink
9
+ } from "./catalog.js";
10
+ export { AI_QUESTIONS, AI_ROUNDS } from "./questions.js";
11
+ export {
12
+ AI_DEPLOY_CHOICES,
13
+ AI_KEY_CHOICES,
14
+ AI_MAGIC_FILL_CHOICES,
15
+ AI_PROVIDER_CHOICES,
16
+ aiSetupFiles,
17
+ hasAiAnswers,
18
+ renderAiSetupPlan,
19
+ renderAiSetupQuestions
20
+ } from "./plan.js";
File without changes