@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.
- package/README.md +26 -24
- package/dist/build.mjs +66 -4
- package/dist/cli.mjs +8 -1
- package/dist/knowledge/api.json +1 -1
- package/dist/knowledge/docs.json +1 -1
- package/dist/module.json +1 -1
- package/dist/runtime/core/ai-setup/catalog.d.ts +0 -0
- package/dist/runtime/core/ai-setup/catalog.js +428 -0
- package/dist/runtime/core/ai-setup/index.d.ts +0 -0
- package/dist/runtime/core/ai-setup/index.js +20 -0
- package/dist/runtime/core/ai-setup/plan.d.ts +0 -0
- package/dist/runtime/core/ai-setup/plan.js +642 -0
- package/dist/runtime/core/ai-setup/questions.d.ts +0 -0
- package/dist/runtime/core/ai-setup/questions.js +237 -0
- package/dist/runtime/core/indexer.js +10 -3
- package/dist/runtime/core/instructions.js +3 -2
- package/dist/runtime/core/prompts.js +25 -1
- package/dist/runtime/core/recipes.js +407 -3
- package/dist/runtime/core/search.js +2 -1
- package/dist/runtime/core/tools/ai.d.ts +0 -0
- package/dist/runtime/core/tools/ai.js +125 -0
- package/dist/runtime/core/tools/api.js +7 -1
- package/dist/runtime/mcp/handlers/mapo/prompts/ai-setup.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/ai-setup.js +3 -0
- package/package.json +1 -1
- package/src/__tests__/aiSetup.test.ts +330 -0
- package/src/__tests__/cli.test.ts +1 -0
- package/src/__tests__/composables.test.ts +95 -0
- package/src/__tests__/indexer.test.ts +19 -0
- package/src/__tests__/knowledge.test.ts +48 -0
- package/src/__tests__/overview.test.ts +11 -0
- package/src/__tests__/recipes.test.ts +83 -0
- package/src/__tests__/search.test.ts +16 -0
- package/src/__tests__/tools.test.ts +27 -1
- package/src/build/extract-components.ts +33 -5
- package/src/build/extract-composables.ts +65 -2
- package/src/cli.ts +8 -1
- package/src/runtime/core/ai-setup/catalog.ts +492 -0
- package/src/runtime/core/ai-setup/index.ts +29 -0
- package/src/runtime/core/ai-setup/plan.ts +710 -0
- package/src/runtime/core/ai-setup/questions.ts +290 -0
- package/src/runtime/core/indexer.ts +16 -4
- package/src/runtime/core/instructions.ts +3 -2
- package/src/runtime/core/prompts.ts +28 -0
- package/src/runtime/core/recipes.ts +428 -3
- package/src/runtime/core/search.ts +4 -1
- package/src/runtime/core/tools/ai.ts +209 -0
- package/src/runtime/core/tools/api.ts +8 -0
- package/src/runtime/mcp/handlers/mapo/prompts/ai-setup.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/ai-setup.ts +4 -0
|
@@ -13,6 +13,22 @@ const knowledge = makeKnowledge({
|
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
describe("searchDocs", () => {
|
|
16
|
+
it("finds nothing for constructor in docs that never write it, without throwing", () => {
|
|
17
|
+
expect(searchDocs(knowledge, "constructor")).toEqual([]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("finds the section that writes constructor, from a knowledge base read back from JSON", () => {
|
|
21
|
+
const withWord = makeKnowledge({
|
|
22
|
+
"modules/utils.md":
|
|
23
|
+
"# Utils\n\n## Flags\n\nA model named constructor gets flags of its own.\n",
|
|
24
|
+
});
|
|
25
|
+
const loaded = JSON.parse(JSON.stringify(withWord)) as typeof withWord;
|
|
26
|
+
|
|
27
|
+
const [top] = searchDocs(loaded, "constructor");
|
|
28
|
+
|
|
29
|
+
expect(top?.heading).toBe("Flags");
|
|
30
|
+
});
|
|
31
|
+
|
|
16
32
|
it("ranks the section that actually answers the question first", () => {
|
|
17
33
|
const [top] = searchDocs(
|
|
18
34
|
knowledge,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
getDocTool,
|
|
16
16
|
searchDocsTool,
|
|
17
17
|
} from "../runtime/core/tools/docs.js";
|
|
18
|
-
import { makeContext, makeManifest } from "./fixtures.js";
|
|
18
|
+
import { makeApi, makeContext, makeManifest } from "./fixtures.js";
|
|
19
19
|
|
|
20
20
|
const context = makeContext();
|
|
21
21
|
const allTools = [...docsTools, ...apiTools, ...appTools];
|
|
@@ -104,6 +104,32 @@ describe("mapo_component_api", () => {
|
|
|
104
104
|
expect(output).toContain("No Mapo component matches");
|
|
105
105
|
expect(output).toContain("MapoList");
|
|
106
106
|
});
|
|
107
|
+
|
|
108
|
+
it("says that a component of an opt-in package needs it turned on", async () => {
|
|
109
|
+
const api = makeApi();
|
|
110
|
+
api.components.push({
|
|
111
|
+
name: "MapoAiMagicFillBanner",
|
|
112
|
+
pkg: "@mapomodule/ai",
|
|
113
|
+
file: "packages/@mapomodule/ai/src/runtime/components/MapoAiMagicFillBanner.vue",
|
|
114
|
+
props: [
|
|
115
|
+
{ name: "detail", type: "MapoAiMagicFillDetail", required: true },
|
|
116
|
+
],
|
|
117
|
+
events: [],
|
|
118
|
+
slots: [],
|
|
119
|
+
exposed: [],
|
|
120
|
+
docs: [],
|
|
121
|
+
});
|
|
122
|
+
const withAi = makeContext(undefined, undefined, { api: () => api });
|
|
123
|
+
|
|
124
|
+
const banner = await componentApiTool.run(
|
|
125
|
+
{ name: "MapoAiMagicFillBanner" },
|
|
126
|
+
withAi,
|
|
127
|
+
);
|
|
128
|
+
const list = await componentApiTool.run({ name: "MapoList" }, withAi);
|
|
129
|
+
|
|
130
|
+
expect(banner).toContain("it exists only in an app that sets `mapo.ai`");
|
|
131
|
+
expect(list).not.toContain("mapo.ai");
|
|
132
|
+
});
|
|
107
133
|
});
|
|
108
134
|
|
|
109
135
|
describe("mapo_list_field_types", () => {
|
|
@@ -11,10 +11,30 @@ import { join, relative } from "node:path";
|
|
|
11
11
|
import { createChecker } from "vue-component-meta";
|
|
12
12
|
import type { ApiMember, ComponentApi } from "../runtime/core/types.js";
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Packages whose `runtime/components` tree is scanned. `only` lists the
|
|
16
|
+
* components a package registers for apps, when it has internal ones too:
|
|
17
|
+
* `@mapomodule/ai` registers the settings page and Magic Fill's four parts
|
|
18
|
+
* (its `module.ts`), the parts of the settings page stay inside it.
|
|
19
|
+
*/
|
|
20
|
+
const COMPONENT_PACKAGES: {
|
|
21
|
+
pkg: string;
|
|
22
|
+
dir: string;
|
|
23
|
+
only?: readonly string[];
|
|
24
|
+
}[] = [
|
|
16
25
|
{ pkg: "@mapomodule/uikit", dir: "packages/@mapomodule/uikit" },
|
|
17
26
|
{ pkg: "@mapomodule/form", dir: "packages/@mapomodule/form" },
|
|
27
|
+
{
|
|
28
|
+
pkg: "@mapomodule/ai",
|
|
29
|
+
dir: "packages/@mapomodule/ai",
|
|
30
|
+
only: [
|
|
31
|
+
"MapoAiSettings",
|
|
32
|
+
"MapoAiMagicFillAction",
|
|
33
|
+
"MapoAiMagicFillBanner",
|
|
34
|
+
"MapoAiMagicFillPanel",
|
|
35
|
+
"MapoAiMagicFillPreview",
|
|
36
|
+
],
|
|
37
|
+
},
|
|
18
38
|
];
|
|
19
39
|
|
|
20
40
|
/** Union types can be enormous; keep them readable in a tool response. */
|
|
@@ -85,12 +105,20 @@ export function extractComponents(
|
|
|
85
105
|
): ComponentApi[] {
|
|
86
106
|
const components: ComponentApi[] = [];
|
|
87
107
|
|
|
88
|
-
for (const { pkg, dir } of COMPONENT_PACKAGES) {
|
|
108
|
+
for (const { pkg, dir, only } of COMPONENT_PACKAGES) {
|
|
89
109
|
const packageRoot = join(repoRoot, dir);
|
|
90
110
|
const tsconfig = join(packageRoot, "tsconfig.json");
|
|
91
111
|
const componentsRoot = join(packageRoot, "src", "runtime", "components");
|
|
92
|
-
const
|
|
93
|
-
|
|
112
|
+
const isListed = (file: string) =>
|
|
113
|
+
!only ||
|
|
114
|
+
only.includes(
|
|
115
|
+
file
|
|
116
|
+
.split("/")
|
|
117
|
+
.pop()!
|
|
118
|
+
.replace(/\.vue$/, ""),
|
|
119
|
+
);
|
|
120
|
+
const files = collectVueFiles(componentsRoot).filter(
|
|
121
|
+
(file) => /\/Mapo[A-Z][^/]*\.vue$/.test(file) && isListed(file),
|
|
94
122
|
);
|
|
95
123
|
if (!files.length || !existsSync(tsconfig)) continue;
|
|
96
124
|
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The module's `addImports([...])` calls are the authoritative list of what an
|
|
5
5
|
* app can call without importing anything — exactly what an assistant needs to
|
|
6
|
-
* know, and what it cannot infer from `node_modules`.
|
|
6
|
+
* know, and what it cannot infer from `node_modules`. Only those calls are
|
|
7
|
+
* read: `addServerImports([...])` names what the app's server code imports,
|
|
8
|
+
* which is no composable of the app.
|
|
7
9
|
*/
|
|
8
10
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
9
11
|
import { join, relative } from "node:path";
|
|
@@ -30,6 +32,64 @@ interface Candidate {
|
|
|
30
32
|
file: string;
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The text between the parentheses of each `addImports(...)` call of a
|
|
37
|
+
* module, so the entries of other calls, such as `addServerImports`, are
|
|
38
|
+
* never read as the app's composables.
|
|
39
|
+
*/
|
|
40
|
+
function addImportsArguments(source: string): string[] {
|
|
41
|
+
const calls: string[] = [];
|
|
42
|
+
for (const match of source.matchAll(/\baddImports\s*\(/g)) {
|
|
43
|
+
const start = (match.index ?? 0) + match[0].length;
|
|
44
|
+
calls.push(source.slice(start, closingParenthesis(source, start)));
|
|
45
|
+
}
|
|
46
|
+
return calls;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Where the parenthesis opened just before `from` closes. Strings and
|
|
51
|
+
* comments are skipped: a parenthesis in them counts for nothing.
|
|
52
|
+
*/
|
|
53
|
+
function closingParenthesis(source: string, from: number): number {
|
|
54
|
+
let depth = 1;
|
|
55
|
+
let at = from;
|
|
56
|
+
while (at < source.length) {
|
|
57
|
+
const char = source[at];
|
|
58
|
+
const next = source[at + 1];
|
|
59
|
+
if (char === '"' || char === "'" || char === "`") {
|
|
60
|
+
at = afterString(source, at, char);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (char === "/" && next === "/") {
|
|
64
|
+
const end = source.indexOf("\n", at);
|
|
65
|
+
at = end === -1 ? source.length : end;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (char === "/" && next === "*") {
|
|
69
|
+
const end = source.indexOf("*/", at + 2);
|
|
70
|
+
at = end === -1 ? source.length : end + 2;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (char === "(") depth++;
|
|
74
|
+
if (char === ")") depth--;
|
|
75
|
+
if (depth === 0) return at;
|
|
76
|
+
at++;
|
|
77
|
+
}
|
|
78
|
+
return source.length;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Where the string that opens at `at` with `quote` ends. */
|
|
82
|
+
function afterString(source: string, at: number, quote: string): number {
|
|
83
|
+
let index = at + 1;
|
|
84
|
+
while (index < source.length) {
|
|
85
|
+
const char = source[index];
|
|
86
|
+
if (char === "\\") index += 2;
|
|
87
|
+
else if (char === quote) return index + 1;
|
|
88
|
+
else index++;
|
|
89
|
+
}
|
|
90
|
+
return source.length;
|
|
91
|
+
}
|
|
92
|
+
|
|
33
93
|
/** Reads every `addImports` entry declared by the Mapo modules. */
|
|
34
94
|
function collectCandidates(repoRoot: string): Candidate[] {
|
|
35
95
|
const packagesDir = join(repoRoot, PACKAGES_ROOT);
|
|
@@ -46,7 +106,10 @@ function collectCandidates(repoRoot: string): Candidate[] {
|
|
|
46
106
|
const source = readFileSync(moduleFile, "utf-8");
|
|
47
107
|
const packageRoot = join(packagesDir, entry.name);
|
|
48
108
|
|
|
49
|
-
|
|
109
|
+
const entries = addImportsArguments(source).flatMap((call) => [
|
|
110
|
+
...call.matchAll(ADD_IMPORT_ENTRY),
|
|
111
|
+
]);
|
|
112
|
+
for (const match of entries) {
|
|
50
113
|
const [, name, from] = match;
|
|
51
114
|
if (!name || !from) continue;
|
|
52
115
|
|
package/src/cli.ts
CHANGED
|
@@ -35,6 +35,7 @@ import { appTools } from "./runtime/core/tools/app.js";
|
|
|
35
35
|
import { docsTools } from "./runtime/core/tools/docs.js";
|
|
36
36
|
import { scaffoldTools } from "./runtime/core/tools/scaffold.js";
|
|
37
37
|
import { backendTools } from "./runtime/core/tools/backend.js";
|
|
38
|
+
import { aiTools } from "./runtime/core/tools/ai.js";
|
|
38
39
|
import { PROMPTS } from "./runtime/core/prompts.js";
|
|
39
40
|
import {
|
|
40
41
|
loadApiKnowledge,
|
|
@@ -63,7 +64,13 @@ export const DEFAULT_APP_URL = mcpEndpointUrl("http://localhost:3000");
|
|
|
63
64
|
|
|
64
65
|
/** All tools that run without the Nuxt dev server. */
|
|
65
66
|
function staticTools(): AnyMapoToolSpec[] {
|
|
66
|
-
return [
|
|
67
|
+
return [
|
|
68
|
+
...docsTools,
|
|
69
|
+
...apiTools,
|
|
70
|
+
...scaffoldTools,
|
|
71
|
+
...backendTools,
|
|
72
|
+
...aiTools,
|
|
73
|
+
];
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
function createToolContext(
|