@bitbybit-dev/mcp 1.3.2-rc.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/LICENSE +21 -0
- package/README.md +143 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +28 -0
- package/dist/context.js.map +1 -0
- package/dist/descriptions.d.ts +10 -0
- package/dist/descriptions.d.ts.map +1 -0
- package/dist/descriptions.js +48 -0
- package/dist/descriptions.js.map +1 -0
- package/dist/guides-split.d.ts +9 -0
- package/dist/guides-split.d.ts.map +1 -0
- package/dist/guides-split.js +41 -0
- package/dist/guides-split.js.map +1 -0
- package/dist/guides.generated.d.ts +9 -0
- package/dist/guides.generated.d.ts.map +1 -0
- package/dist/guides.generated.js +93 -0
- package/dist/guides.generated.js.map +1 -0
- package/dist/index-loader.d.ts +11 -0
- package/dist/index-loader.d.ts.map +1 -0
- package/dist/index-loader.js +53 -0
- package/dist/index-loader.js.map +1 -0
- package/dist/index-reader.d.ts +27 -0
- package/dist/index-reader.d.ts.map +1 -0
- package/dist/index-reader.js +171 -0
- package/dist/index-reader.js.map +1 -0
- package/dist/index-shape.d.ts +3 -0
- package/dist/index-shape.d.ts.map +1 -0
- package/dist/index-shape.js +17 -0
- package/dist/index-shape.js.map +1 -0
- package/dist/index-types.d.ts +72 -0
- package/dist/index-types.d.ts.map +1 -0
- package/dist/index-types.js +2 -0
- package/dist/index-types.js.map +1 -0
- package/dist/index-url.d.ts +11 -0
- package/dist/index-url.d.ts.map +1 -0
- package/dist/index-url.js +30 -0
- package/dist/index-url.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/installed-version.d.ts +18 -0
- package/dist/installed-version.d.ts.map +1 -0
- package/dist/installed-version.js +67 -0
- package/dist/installed-version.js.map +1 -0
- package/dist/json-schema.d.ts +2 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +46 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/registry.d.ts +56 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +78 -0
- package/dist/registry.js.map +1 -0
- package/dist/render.d.ts +4 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +76 -0
- package/dist/render.js.map +1 -0
- package/dist/results.d.ts +5 -0
- package/dist/results.d.ts.map +1 -0
- package/dist/results.js +18 -0
- package/dist/results.js.map +1 -0
- package/dist/server.d.ts +22 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +69 -0
- package/dist/server.js.map +1 -0
- package/dist/stdio.d.ts +3 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +64 -0
- package/dist/stdio.js.map +1 -0
- package/dist/tools/describe.d.ts +10 -0
- package/dist/tools/describe.d.ts.map +1 -0
- package/dist/tools/describe.js +39 -0
- package/dist/tools/describe.js.map +1 -0
- package/dist/tools/fetch.d.ts +9 -0
- package/dist/tools/fetch.d.ts.map +1 -0
- package/dist/tools/fetch.js +37 -0
- package/dist/tools/fetch.js.map +1 -0
- package/dist/tools/get-examples.d.ts +17 -0
- package/dist/tools/get-examples.d.ts.map +1 -0
- package/dist/tools/get-examples.js +60 -0
- package/dist/tools/get-examples.js.map +1 -0
- package/dist/tools/get-guide.d.ts +10 -0
- package/dist/tools/get-guide.d.ts.map +1 -0
- package/dist/tools/get-guide.js +64 -0
- package/dist/tools/get-guide.js.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +19 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/list-namespace.d.ts +10 -0
- package/dist/tools/list-namespace.d.ts.map +1 -0
- package/dist/tools/list-namespace.js +41 -0
- package/dist/tools/list-namespace.js.map +1 -0
- package/dist/tools/search-api.d.ts +16 -0
- package/dist/tools/search-api.d.ts.map +1 -0
- package/dist/tools/search-api.js +44 -0
- package/dist/tools/search-api.js.map +1 -0
- package/dist/tools/search.d.ts +9 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +31 -0
- package/dist/tools/search.js.map +1 -0
- package/package.json +102 -0
- package/server.json +30 -0
- package/src/__fixtures__/index.sample.json +1916 -0
- package/src/__fixtures__/load.ts +29 -0
- package/src/context.ts +40 -0
- package/src/dependencies.test.ts +72 -0
- package/src/descriptions.ts +62 -0
- package/src/guides-split.ts +46 -0
- package/src/guides.generated.ts +95 -0
- package/src/guides.test.ts +57 -0
- package/src/index-loader.test.ts +160 -0
- package/src/index-loader.ts +61 -0
- package/src/index-reader.ts +179 -0
- package/src/index-shape.ts +17 -0
- package/src/index-types.ts +74 -0
- package/src/index-url.ts +29 -0
- package/src/index.ts +20 -0
- package/src/installed-version.test.ts +79 -0
- package/src/installed-version.ts +80 -0
- package/src/json-schema.test.ts +65 -0
- package/src/json-schema.ts +40 -0
- package/src/network.test.ts +37 -0
- package/src/registry.test.ts +177 -0
- package/src/registry.ts +139 -0
- package/src/render.ts +62 -0
- package/src/results.ts +21 -0
- package/src/server.test.ts +233 -0
- package/src/server.ts +117 -0
- package/src/stdio.test.ts +100 -0
- package/src/stdio.ts +67 -0
- package/src/tools/describe.ts +42 -0
- package/src/tools/docs-tools.test.ts +375 -0
- package/src/tools/fetch.ts +39 -0
- package/src/tools/get-examples.ts +59 -0
- package/src/tools/get-guide.ts +69 -0
- package/src/tools/index.ts +20 -0
- package/src/tools/list-namespace.ts +50 -0
- package/src/tools/search-api.ts +47 -0
- package/src/tools/search.ts +34 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createDocsRegistry } from "./index.js";
|
|
3
|
+
import { TOOL_CEILING, toHttp } from "../registry.js";
|
|
4
|
+
import type { HttpTool, ToolResult } from "../registry.js";
|
|
5
|
+
import { DESCRIPTIONS, TOOL_NAMES } from "../descriptions.js";
|
|
6
|
+
import { FIXTURE_VERSION, GUIDE_URL, fixtureContext } from "../__fixtures__/load.js";
|
|
7
|
+
|
|
8
|
+
function tool(name: string): HttpTool {
|
|
9
|
+
const found = toHttp(createDocsRegistry(), fixtureContext()).find((candidate) => candidate.name === name);
|
|
10
|
+
if (!found) throw new Error(`no tool ${name}`);
|
|
11
|
+
return found;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const call = (name: string, args: unknown): Promise<ToolResult> => tool(name).call(args);
|
|
15
|
+
const structured = (result: ToolResult): Record<string, unknown> => result.structured ?? {};
|
|
16
|
+
const paths = (rows: unknown): string[] => (rows as { path: string }[]).map((row) => row.path);
|
|
17
|
+
|
|
18
|
+
describe("the docs registry", () => {
|
|
19
|
+
it("exposes the seven tools within the ceiling, every one read-only, each described once", () => {
|
|
20
|
+
// Act
|
|
21
|
+
const definitions = createDocsRegistry().list();
|
|
22
|
+
|
|
23
|
+
// Assert
|
|
24
|
+
expect(definitions.map((definition) => definition.name)).toEqual([...TOOL_NAMES]);
|
|
25
|
+
expect(definitions.length).toBeLessThanOrEqual(TOOL_CEILING);
|
|
26
|
+
expect(definitions.every((definition) => definition.annotations.readOnlyHint && !definition.annotations.destructiveHint)).toBe(true);
|
|
27
|
+
expect(Object.keys(DESCRIPTIONS).sort()).toEqual([...TOOL_NAMES].sort());
|
|
28
|
+
expect(definitions.every((definition) => definition.description === DESCRIPTIONS[definition.name as keyof typeof DESCRIPTIONS].description)).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("search_api", () => {
|
|
33
|
+
it("ranks the member whose name and summary match first", async () => {
|
|
34
|
+
// Act
|
|
35
|
+
const result = await call("search_api", { query: "box solid" });
|
|
36
|
+
|
|
37
|
+
// Assert
|
|
38
|
+
expect(paths(structured(result)["results"])[0]).toBe("occt.shapes.solid.createBox");
|
|
39
|
+
expect(structured(result)["version"]).toBe(FIXTURE_VERSION);
|
|
40
|
+
expect(result.text).toContain("occt.shapes.solid.createBox");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("keeps only members published for the requested engine", async () => {
|
|
44
|
+
// Act
|
|
45
|
+
const forThree = await call("search_api", { query: "create box", engine: "threejs" });
|
|
46
|
+
const forBabylon = await call("search_api", { query: "create box", engine: "babylonjs" });
|
|
47
|
+
|
|
48
|
+
// Assert
|
|
49
|
+
expect(paths(structured(forThree)["results"])).not.toContain("babylon.meshBuilder.createBox");
|
|
50
|
+
expect(paths(structured(forBabylon)["results"])).toContain("babylon.meshBuilder.createBox");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("reports the tier of every result", async () => {
|
|
54
|
+
// Act
|
|
55
|
+
const result = await call("search_api", { query: "text 3d", limit: 5 });
|
|
56
|
+
|
|
57
|
+
// Assert
|
|
58
|
+
const rows = structured(result)["results"] as { path: string; tier: string }[];
|
|
59
|
+
expect(rows.find((row) => row.path === "advanced.text3d.create")?.tier).toBe("platform-pro");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("ranks the exact path first whether or not the query carries the bitbybit prefix", async () => {
|
|
63
|
+
// Act
|
|
64
|
+
const plain = await call("search_api", { query: "occt.shapes.solid.createBox" });
|
|
65
|
+
const prefixed = await call("search_api", { query: "bitbybit.occt.shapes.solid.createBox" });
|
|
66
|
+
|
|
67
|
+
// Assert
|
|
68
|
+
expect(paths(structured(plain)["results"])[0]).toBe("occt.shapes.solid.createBox");
|
|
69
|
+
expect(paths(structured(prefixed)["results"])[0]).toBe("occt.shapes.solid.createBox");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("refuses a query longer than a sentence, before any scoring", async () => {
|
|
73
|
+
// Arrange
|
|
74
|
+
const overlong = "box ".repeat(100);
|
|
75
|
+
|
|
76
|
+
// Act
|
|
77
|
+
const result = await call("search_api", { query: overlong });
|
|
78
|
+
|
|
79
|
+
// Assert
|
|
80
|
+
expect(result.isError).toBe(true);
|
|
81
|
+
expect(result.text).toContain("Invalid arguments for search_api");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("says so when nothing matches", async () => {
|
|
85
|
+
// Act
|
|
86
|
+
const result = await call("search_api", { query: "zzzz" });
|
|
87
|
+
|
|
88
|
+
// Assert
|
|
89
|
+
expect(structured(result)["results"]).toEqual([]);
|
|
90
|
+
expect(result.text).toContain("No member");
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("describe", () => {
|
|
95
|
+
it("returns the full record, the version and the examples of a known path", async () => {
|
|
96
|
+
// Act
|
|
97
|
+
const result = await call("describe", { path: "occt.shapes.solid.createBox" });
|
|
98
|
+
|
|
99
|
+
// Assert
|
|
100
|
+
const member = structured(result)["member"] as { path: string; signature: string };
|
|
101
|
+
expect(member.path).toBe("occt.shapes.solid.createBox");
|
|
102
|
+
expect(structured(result)["version"]).toBe(FIXTURE_VERSION);
|
|
103
|
+
expect(result.text).toContain(member.signature);
|
|
104
|
+
expect(result.text).toContain("version: 9.9.9");
|
|
105
|
+
expect(result.text).toContain("## Examples");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("accepts the bitbybit. prefix", async () => {
|
|
109
|
+
// Act
|
|
110
|
+
const result = await call("describe", { path: "bitbybit.occt.shapes.solid.createBox" });
|
|
111
|
+
|
|
112
|
+
// Assert
|
|
113
|
+
expect((structured(result)["member"] as { path: string }).path).toBe("occt.shapes.solid.createBox");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("reports an unknown path with the nearest existing ones instead of guessing", async () => {
|
|
117
|
+
// Act
|
|
118
|
+
const result = await call("describe", { path: "occt.shapes.solid.createbox" });
|
|
119
|
+
|
|
120
|
+
// Assert
|
|
121
|
+
expect(structured(result)["notFound"]).toBe("occt.shapes.solid.createbox");
|
|
122
|
+
expect((structured(result)["nearest"] as string[])[0]).toBe("occt.shapes.solid.createBox");
|
|
123
|
+
expect(result.isError).toBeUndefined();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("offers the sibling a misspelling meant before anything that merely shares a word", async () => {
|
|
127
|
+
// Act
|
|
128
|
+
const result = await call("describe", { path: "occt.shapes.solid.createboxx" });
|
|
129
|
+
|
|
130
|
+
// Assert
|
|
131
|
+
expect((structured(result)["nearest"] as string[])[0]).toBe("occt.shapes.solid.createBox");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("offers the path with a misspelt middle segment before a same-named member elsewhere", async () => {
|
|
135
|
+
// Act
|
|
136
|
+
const result = await call("describe", { path: "occt.shape.solid.createBox" });
|
|
137
|
+
|
|
138
|
+
// Assert
|
|
139
|
+
expect((structured(result)["nearest"] as string[])[0]).toBe("occt.shapes.solid.createBox");
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("refuses a path longer than a dotted API path can be, before any lookup", async () => {
|
|
143
|
+
// Arrange
|
|
144
|
+
const overlong = "a".repeat(300);
|
|
145
|
+
|
|
146
|
+
// Act
|
|
147
|
+
const result = await call("describe", { path: overlong });
|
|
148
|
+
|
|
149
|
+
// Assert
|
|
150
|
+
expect(result.isError).toBe(true);
|
|
151
|
+
expect(result.text).toContain("Invalid arguments for describe");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("shows a deprecation", async () => {
|
|
155
|
+
// Act
|
|
156
|
+
const result = await call("describe", { path: "verb" });
|
|
157
|
+
|
|
158
|
+
// Assert
|
|
159
|
+
expect(result.text).toContain("deprecated:");
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("shows a bare deprecation without a reason", async () => {
|
|
163
|
+
// Act
|
|
164
|
+
const result = await call("describe", { path: "verb.curve" });
|
|
165
|
+
|
|
166
|
+
// Assert
|
|
167
|
+
expect(result.text).toContain("- deprecated\n");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("documents the CAD Cloud inputs beside the browser signature when they differ", async () => {
|
|
171
|
+
// Act
|
|
172
|
+
const result = await call("describe", { path: "occt.shapes.solid.createBoxFromCorner" });
|
|
173
|
+
|
|
174
|
+
// Assert
|
|
175
|
+
expect(result.text).toContain("## Parameters on CAD Cloud");
|
|
176
|
+
expect(result.text).toContain("On CAD Cloud the corner is given as three numbers.");
|
|
177
|
+
expect(result.text).toContain("- corner: number[]; default [0,0,0] - The corner as [x, y, z]");
|
|
178
|
+
expect((await call("describe", { path: "occt.shapes.solid.createBox" })).text).not.toContain("Parameters on CAD Cloud");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("refuses another version than the one it holds, naming both", async () => {
|
|
182
|
+
// Act
|
|
183
|
+
const result = await call("describe", { path: "occt", version: "1.0.0" });
|
|
184
|
+
|
|
185
|
+
// Assert
|
|
186
|
+
expect(result.isError).toBe(true);
|
|
187
|
+
expect(structured(result)).toEqual({ code: "VERSION_NOT_LOADED", requested: "1.0.0", loaded: FIXTURE_VERSION });
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe("list_namespace", () => {
|
|
192
|
+
it("lists the roots without a path", async () => {
|
|
193
|
+
// Act
|
|
194
|
+
const result = await call("list_namespace", {});
|
|
195
|
+
|
|
196
|
+
// Assert
|
|
197
|
+
const listed = paths(structured(result)["members"]);
|
|
198
|
+
expect(listed).toContain("occt");
|
|
199
|
+
expect(listed).toContain("math");
|
|
200
|
+
expect(listed).toContain("occtPro");
|
|
201
|
+
expect(listed).not.toContain("cloud.unfold.solidToFlat");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("lists a namespace the index carries only through its members", async () => {
|
|
205
|
+
// Act
|
|
206
|
+
const result = await call("list_namespace", { path: "cloud.unfold" });
|
|
207
|
+
|
|
208
|
+
// Assert
|
|
209
|
+
expect(paths(structured(result)["members"])).toEqual(["cloud.unfold.solidToFlat"]);
|
|
210
|
+
expect(structured(result)["notFound"]).toBeUndefined();
|
|
211
|
+
expect(paths(structured(await call("list_namespace", { path: "occtPro" }))["members"])).toEqual(["occtPro.sheetMetal"]);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("lists the children of a namespace", async () => {
|
|
215
|
+
// Act
|
|
216
|
+
const result = await call("list_namespace", { path: "occt.shapes" });
|
|
217
|
+
|
|
218
|
+
// Assert
|
|
219
|
+
expect(paths(structured(result)["members"])).toEqual(["occt.shapes.solid"]);
|
|
220
|
+
expect(result.text).toContain("occt.shapes");
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("says when the path is a member rather than a namespace", async () => {
|
|
224
|
+
// Act
|
|
225
|
+
const result = await call("list_namespace", { path: "occt.shapes.solid.createBox" });
|
|
226
|
+
|
|
227
|
+
// Assert
|
|
228
|
+
expect(structured(result)["notNamespace"]).toBe("occt.shapes.solid.createBox");
|
|
229
|
+
expect(structured(result)["kind"]).toBe("method");
|
|
230
|
+
expect(result.text).toContain("not a namespace");
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("reports an unknown namespace with the nearest paths", async () => {
|
|
234
|
+
// Act
|
|
235
|
+
const result = await call("list_namespace", { path: "occt.shape" });
|
|
236
|
+
|
|
237
|
+
// Assert
|
|
238
|
+
expect(structured(result)["notFound"]).toBe("occt.shape");
|
|
239
|
+
expect(structured(result)["nearest"]).toContain("occt.shapes");
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe("get_examples", () => {
|
|
244
|
+
it("returns a member's examples with its reference url", async () => {
|
|
245
|
+
// Act
|
|
246
|
+
const result = await call("get_examples", { path: "occt.shapes.solid.createBox" });
|
|
247
|
+
|
|
248
|
+
// Assert
|
|
249
|
+
const rows = structured(result)["examples"] as { path: string; url: string; code: string }[];
|
|
250
|
+
expect(rows[0]?.path).toBe("occt.shapes.solid.createBox");
|
|
251
|
+
expect(rows[0]?.url).toContain("docs.bitbybit.dev");
|
|
252
|
+
expect(result.text).toContain(rows[0]?.code ?? "missing");
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("collects examples under a namespace", async () => {
|
|
256
|
+
// Act
|
|
257
|
+
const result = await call("get_examples", { path: "occt.shapes.solid", limit: 3 });
|
|
258
|
+
|
|
259
|
+
// Assert
|
|
260
|
+
const rows = structured(result)["examples"] as { path: string }[];
|
|
261
|
+
expect(rows.length).toBeGreaterThan(0);
|
|
262
|
+
expect(rows.every((row) => row.path.startsWith("occt.shapes.solid."))).toBe(true);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("collects examples under a namespace the index carries only through its members", async () => {
|
|
266
|
+
// Act
|
|
267
|
+
const result = await call("get_examples", { path: "cloud.unfold" });
|
|
268
|
+
|
|
269
|
+
// Assert
|
|
270
|
+
expect(result.isError).toBeUndefined();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("finds examples by topic", async () => {
|
|
274
|
+
// Act
|
|
275
|
+
const result = await call("get_examples", { topic: "box" });
|
|
276
|
+
|
|
277
|
+
// Assert
|
|
278
|
+
expect((structured(result)["examples"] as unknown[]).length).toBeGreaterThan(0);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("needs a path or a topic", async () => {
|
|
282
|
+
// Act
|
|
283
|
+
const result = await call("get_examples", {});
|
|
284
|
+
|
|
285
|
+
// Assert
|
|
286
|
+
expect(result.isError).toBe(true);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("reports an unknown path as an error", async () => {
|
|
290
|
+
// Act
|
|
291
|
+
const result = await call("get_examples", { path: "occt.nothing" });
|
|
292
|
+
|
|
293
|
+
// Assert
|
|
294
|
+
expect(result.isError).toBe(true);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe("get_guide", () => {
|
|
299
|
+
it("lists the sections without a topic", async () => {
|
|
300
|
+
// Act
|
|
301
|
+
const result = await call("get_guide", {});
|
|
302
|
+
|
|
303
|
+
// Assert
|
|
304
|
+
expect((structured(result)["sections"] as { id: string }[]).map((section) => section.id)).toContain("browser-apps");
|
|
305
|
+
expect(structured(result)["url"]).toBe(GUIDE_URL);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("resolves a short name to its section and links the anchor", async () => {
|
|
309
|
+
// Act
|
|
310
|
+
const result = await call("get_guide", { topic: "deploy" });
|
|
311
|
+
|
|
312
|
+
// Assert
|
|
313
|
+
expect(structured(result)["id"]).toBe("how-an-agent-should-integrate-bitbybit");
|
|
314
|
+
expect(structured(result)["url"]).toBe(`${GUIDE_URL}#how-an-agent-should-integrate-bitbybit`);
|
|
315
|
+
expect(result.text).toContain("The packages are the whole answer.");
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("matches a title by its words", async () => {
|
|
319
|
+
// Act
|
|
320
|
+
const result = await call("get_guide", { topic: "browser" });
|
|
321
|
+
|
|
322
|
+
// Assert
|
|
323
|
+
expect(structured(result)["id"]).toBe("browser-apps");
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it("names the sections when nothing matches", async () => {
|
|
327
|
+
// Act
|
|
328
|
+
const result = await call("get_guide", { topic: "kitchen" });
|
|
329
|
+
|
|
330
|
+
// Assert
|
|
331
|
+
expect(structured(result)["notFound"]).toBe("kitchen");
|
|
332
|
+
expect(result.text).toContain("get-started");
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
describe("search and fetch, the connector shape", () => {
|
|
337
|
+
it("search returns results of id, title and url", async () => {
|
|
338
|
+
// Act
|
|
339
|
+
const result = await call("search", { query: "box" });
|
|
340
|
+
|
|
341
|
+
// Assert
|
|
342
|
+
const rows = structured(result)["results"] as { id: string; title: string; url: string }[];
|
|
343
|
+
expect(rows[0]).toMatchObject({ id: "occt.shapes.solid.createBox" });
|
|
344
|
+
expect(rows[0]?.title).toContain("occt.shapes.solid.createBox");
|
|
345
|
+
expect(rows[0]?.url).toContain("docs.bitbybit.dev");
|
|
346
|
+
expect(JSON.parse(result.text)).toEqual({ results: rows });
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it("fetch returns one document by id with text, url and metadata", async () => {
|
|
350
|
+
// Act
|
|
351
|
+
const result = await call("fetch", { id: "occt.shapes.solid.createBox" });
|
|
352
|
+
|
|
353
|
+
// Assert
|
|
354
|
+
expect(structured(result)).toMatchObject({ id: "occt.shapes.solid.createBox", title: "occt.shapes.solid.createBox", metadata: { tier: "oss", version: FIXTURE_VERSION } });
|
|
355
|
+
expect(structured(result)["text"]).toContain("# occt.shapes.solid.createBox");
|
|
356
|
+
expect(JSON.parse(result.text)).toEqual(structured(result));
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("fetch accepts the bitbybit. prefix like every other tool", async () => {
|
|
360
|
+
// Act
|
|
361
|
+
const result = await call("fetch", { id: "bitbybit.occt.shapes.solid.createBox" });
|
|
362
|
+
|
|
363
|
+
// Assert
|
|
364
|
+
expect(result.isError).toBeUndefined();
|
|
365
|
+
expect(structured(result)["id"]).toBe("occt.shapes.solid.createBox");
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("fetch reports an unknown id as an error", async () => {
|
|
369
|
+
// Act
|
|
370
|
+
const result = await call("fetch", { id: "nope" });
|
|
371
|
+
|
|
372
|
+
// Assert
|
|
373
|
+
expect(result.isError).toBe(true);
|
|
374
|
+
});
|
|
375
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ToolDefinition } from "../registry.js";
|
|
3
|
+
import type { DocsContext } from "../context.js";
|
|
4
|
+
import { DESCRIPTIONS } from "../descriptions.js";
|
|
5
|
+
import { ok, fail, failFor } from "../results.js";
|
|
6
|
+
import { renderMember } from "../render.js";
|
|
7
|
+
|
|
8
|
+
const MAX_ID_LENGTH = 256;
|
|
9
|
+
|
|
10
|
+
const input = z.object({
|
|
11
|
+
id: z.string().min(1).max(MAX_ID_LENGTH).describe("A dotted API path returned by search"),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const fetchTool: ToolDefinition<typeof input, DocsContext> = {
|
|
15
|
+
name: "fetch",
|
|
16
|
+
description: DESCRIPTIONS.fetch.description,
|
|
17
|
+
annotations: { title: DESCRIPTIONS.fetch.title, readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
18
|
+
input,
|
|
19
|
+
where: "server",
|
|
20
|
+
handler: async (args, context) => {
|
|
21
|
+
let resolved;
|
|
22
|
+
try {
|
|
23
|
+
resolved = await context.resolve();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return failFor(error);
|
|
26
|
+
}
|
|
27
|
+
const id = args.id.replace(/^bitbybit\./, "");
|
|
28
|
+
const member = resolved.reader.get(id);
|
|
29
|
+
if (!member) return fail(`No document has the id ${id}; ids are dotted API paths returned by search.`);
|
|
30
|
+
const document = {
|
|
31
|
+
id: member.path,
|
|
32
|
+
title: member.path,
|
|
33
|
+
text: renderMember(member, resolved.version, resolved.reader.examplesOf(member.path)),
|
|
34
|
+
url: member.docUrl ?? context.guideUrl,
|
|
35
|
+
metadata: { tier: member.tier, kind: member.kind, version: resolved.version, engines: member.engines.join(",") },
|
|
36
|
+
};
|
|
37
|
+
return ok(JSON.stringify(document), document);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ToolDefinition } from "../registry.js";
|
|
3
|
+
import type { DocsContext } from "../context.js";
|
|
4
|
+
import type { IndexExample } from "../index-types.js";
|
|
5
|
+
import { DESCRIPTIONS } from "../descriptions.js";
|
|
6
|
+
import { ok, fail, failFor } from "../results.js";
|
|
7
|
+
|
|
8
|
+
const ENGINES = ["babylonjs", "threejs", "playcanvas"] as const;
|
|
9
|
+
const DEFAULT_LIMIT = 5;
|
|
10
|
+
const MAX_LIMIT = 20;
|
|
11
|
+
const MAX_PATH_LENGTH = 256;
|
|
12
|
+
const MAX_TOPIC_LENGTH = 200;
|
|
13
|
+
|
|
14
|
+
const input = z
|
|
15
|
+
.object({
|
|
16
|
+
path: z.string().max(MAX_PATH_LENGTH).optional().describe("A member or namespace path, for example occt.shapes.solid.createBox or occt.fillets"),
|
|
17
|
+
topic: z.string().max(MAX_TOPIC_LENGTH).optional().describe("Keywords to find examples by, when no path is known"),
|
|
18
|
+
engine: z.enum(ENGINES).optional().describe("Prefer members published for this engine when searching by topic"),
|
|
19
|
+
limit: z.number().int().min(1).max(MAX_LIMIT).optional().describe("How many examples, 5 by default"),
|
|
20
|
+
version: z.string().optional().describe("The API version; omit for the version the server holds"),
|
|
21
|
+
})
|
|
22
|
+
.refine((value) => value.path !== undefined || value.topic !== undefined, { message: "Give a path or a topic" });
|
|
23
|
+
|
|
24
|
+
export const getExamples: ToolDefinition<typeof input, DocsContext> = {
|
|
25
|
+
name: "get_examples",
|
|
26
|
+
description: DESCRIPTIONS.get_examples.description,
|
|
27
|
+
annotations: { title: DESCRIPTIONS.get_examples.title, readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
28
|
+
input,
|
|
29
|
+
where: "server",
|
|
30
|
+
handler: async (args, context) => {
|
|
31
|
+
let resolved;
|
|
32
|
+
try {
|
|
33
|
+
resolved = await context.resolve(args.version);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return failFor(error);
|
|
36
|
+
}
|
|
37
|
+
const limit = args.limit ?? DEFAULT_LIMIT;
|
|
38
|
+
const { reader } = resolved;
|
|
39
|
+
let examples: IndexExample[] = [];
|
|
40
|
+
if (args.path !== undefined) {
|
|
41
|
+
const path = args.path.replace(/^bitbybit\./, "");
|
|
42
|
+
if (!reader.get(path) && reader.children(path).length === 0) return fail(`${path} is not a member of the Bitbybit API ${resolved.version}; call describe to see the nearest paths.`);
|
|
43
|
+
examples = reader.examplesOf(path);
|
|
44
|
+
if (examples.length < limit) examples = [...examples, ...reader.examplesUnder(path, limit - examples.length)];
|
|
45
|
+
} else if (args.topic !== undefined) {
|
|
46
|
+
for (const hit of reader.search(args.topic, { engine: args.engine, limit: MAX_LIMIT })) {
|
|
47
|
+
for (const example of reader.examplesOf(hit.member.path)) {
|
|
48
|
+
if (examples.length >= limit) break;
|
|
49
|
+
examples.push(example);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
examples = examples.slice(0, limit);
|
|
54
|
+
const rows = examples.map((example) => ({ path: example.path, code: example.code, url: reader.get(example.path)?.docUrl ?? null }));
|
|
55
|
+
if (rows.length === 0) return ok(`No example matches in the Bitbybit API ${resolved.version}. Try describe on a path: its parameters and defaults are enough to write a call.`, { version: resolved.version, examples: [] });
|
|
56
|
+
const text = rows.map((row) => `// ${row.path}${row.url ? ` (${row.url})` : ""}\n${row.code}`).join("\n\n");
|
|
57
|
+
return ok(text, { version: resolved.version, examples: rows });
|
|
58
|
+
},
|
|
59
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ToolDefinition } from "../registry.js";
|
|
3
|
+
import type { DocsContext } from "../context.js";
|
|
4
|
+
import type { GuideSection } from "../guides-split.js";
|
|
5
|
+
import { DESCRIPTIONS } from "../descriptions.js";
|
|
6
|
+
import { ok } from "../results.js";
|
|
7
|
+
import { tokenize } from "../index-reader.js";
|
|
8
|
+
|
|
9
|
+
export const GUIDE_ALIASES: Readonly<Record<string, string>> = {
|
|
10
|
+
integrate: "how-an-agent-should-integrate-bitbybit",
|
|
11
|
+
deploy: "how-an-agent-should-integrate-bitbybit",
|
|
12
|
+
deployment: "how-an-agent-should-integrate-bitbybit",
|
|
13
|
+
"server-side": "node-servers-with-headroom",
|
|
14
|
+
server: "node-servers-with-headroom",
|
|
15
|
+
backend: "lightweight-backends",
|
|
16
|
+
serverless: "lightweight-backends",
|
|
17
|
+
edge: "lightweight-backends",
|
|
18
|
+
browser: "browser-apps",
|
|
19
|
+
"large-models": "node-servers-with-headroom",
|
|
20
|
+
editors: "inside-the-bitbybit-editors",
|
|
21
|
+
pro: "pro-algorithms",
|
|
22
|
+
cloud: "pro-algorithms",
|
|
23
|
+
start: "get-started",
|
|
24
|
+
"getting-started": "get-started",
|
|
25
|
+
layers: "three-layers-you-can-use",
|
|
26
|
+
trust: "trust",
|
|
27
|
+
companies: "for-companies",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const MAX_TOPIC_LENGTH = 128;
|
|
31
|
+
|
|
32
|
+
const input = z.object({
|
|
33
|
+
topic: z.string().max(MAX_TOPIC_LENGTH).optional().describe("A section id or a short name such as integrate, browser, backend, server-side, pro, start; omit to list the sections"),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
function findSection(guides: readonly GuideSection[], topic: string): GuideSection | undefined {
|
|
37
|
+
const wanted = topic.trim().toLowerCase();
|
|
38
|
+
const alias = Object.hasOwn(GUIDE_ALIASES, wanted) ? GUIDE_ALIASES[wanted] : undefined;
|
|
39
|
+
const byId = guides.find((section) => section.id === (alias ?? wanted));
|
|
40
|
+
if (byId) return byId;
|
|
41
|
+
const words = new Set(tokenize(wanted));
|
|
42
|
+
let best: { section: GuideSection; overlap: number } | undefined;
|
|
43
|
+
for (const section of guides) {
|
|
44
|
+
const overlap = tokenize(section.title).filter((word) => words.has(word)).length;
|
|
45
|
+
if (overlap > 0 && (!best || overlap > best.overlap)) best = { section, overlap };
|
|
46
|
+
}
|
|
47
|
+
return best?.section;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const getGuide: ToolDefinition<typeof input, DocsContext> = {
|
|
51
|
+
name: "get_guide",
|
|
52
|
+
description: DESCRIPTIONS.get_guide.description,
|
|
53
|
+
annotations: { title: DESCRIPTIONS.get_guide.title, readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
54
|
+
input,
|
|
55
|
+
where: "server",
|
|
56
|
+
handler: (args, context) => {
|
|
57
|
+
const sections = context.guides.map((section) => ({ id: section.id, title: section.title, level: section.level }));
|
|
58
|
+
if (args.topic === undefined) {
|
|
59
|
+
const text = [`Sections of the guide (${context.guideUrl}):`, ...context.guides.map((section) => `- ${section.id}: ${section.title}`)].join("\n");
|
|
60
|
+
return ok(text, { url: context.guideUrl, sections });
|
|
61
|
+
}
|
|
62
|
+
const section = findSection(context.guides, args.topic);
|
|
63
|
+
if (!section) {
|
|
64
|
+
return ok(`No guide section matches "${args.topic}". Sections: ${context.guides.map((candidate) => candidate.id).join(", ")}.`, { url: context.guideUrl, notFound: args.topic, sections });
|
|
65
|
+
}
|
|
66
|
+
const url = `${context.guideUrl}#${section.id}`;
|
|
67
|
+
return ok(`${"#".repeat(section.level)} ${section.title}\n\n${section.body}\n\nSource: ${url}`, { url, id: section.id, title: section.title, body: section.body });
|
|
68
|
+
},
|
|
69
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Registry } from "../registry.js";
|
|
2
|
+
import type { DocsContext } from "../context.js";
|
|
3
|
+
import { searchApi } from "./search-api.js";
|
|
4
|
+
import { describe } from "./describe.js";
|
|
5
|
+
import { listNamespace } from "./list-namespace.js";
|
|
6
|
+
import { getExamples } from "./get-examples.js";
|
|
7
|
+
import { getGuide } from "./get-guide.js";
|
|
8
|
+
import { search } from "./search.js";
|
|
9
|
+
import { fetchTool } from "./fetch.js";
|
|
10
|
+
|
|
11
|
+
export function createDocsRegistry(): Registry<DocsContext> {
|
|
12
|
+
return new Registry<DocsContext>()
|
|
13
|
+
.register(searchApi)
|
|
14
|
+
.register(describe)
|
|
15
|
+
.register(listNamespace)
|
|
16
|
+
.register(getExamples)
|
|
17
|
+
.register(getGuide)
|
|
18
|
+
.register(search)
|
|
19
|
+
.register(fetchTool);
|
|
20
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ToolDefinition } from "../registry.js";
|
|
3
|
+
import type { DocsContext } from "../context.js";
|
|
4
|
+
import { DESCRIPTIONS } from "../descriptions.js";
|
|
5
|
+
import { ok, failFor } from "../results.js";
|
|
6
|
+
import { renderLine } from "../render.js";
|
|
7
|
+
|
|
8
|
+
const MAX_PATH_LENGTH = 256;
|
|
9
|
+
|
|
10
|
+
const input = z.object({
|
|
11
|
+
path: z.string().max(MAX_PATH_LENGTH).optional().describe("A namespace path such as occt or occt.shapes; omit for the top level"),
|
|
12
|
+
version: z.string().optional().describe("The API version to list; omit for the version the server holds"),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const listNamespace: ToolDefinition<typeof input, DocsContext> = {
|
|
16
|
+
name: "list_namespace",
|
|
17
|
+
description: DESCRIPTIONS.list_namespace.description,
|
|
18
|
+
annotations: { title: DESCRIPTIONS.list_namespace.title, readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
19
|
+
input,
|
|
20
|
+
where: "server",
|
|
21
|
+
handler: async (args, context) => {
|
|
22
|
+
let resolved;
|
|
23
|
+
try {
|
|
24
|
+
resolved = await context.resolve(args.version);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return failFor(error);
|
|
27
|
+
}
|
|
28
|
+
const path = args.path?.replace(/^bitbybit\./, "");
|
|
29
|
+
const parent = path ? resolved.reader.get(path) : undefined;
|
|
30
|
+
if (path && !parent && resolved.reader.children(path).length === 0) {
|
|
31
|
+
const nearest = resolved.reader.nearest(path);
|
|
32
|
+
return ok(
|
|
33
|
+
[`${path} is not a namespace of the Bitbybit API ${resolved.version}.`, ...nearest.map(renderLine)].join("\n"),
|
|
34
|
+
{ version: resolved.version, notFound: path, nearest: nearest.map((candidate) => candidate.path) },
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (path && parent && parent.kind !== "namespace") {
|
|
38
|
+
const siblings = path.split(".").slice(0, -1).join(".");
|
|
39
|
+
return ok(
|
|
40
|
+
`${path} is a ${parent.kind} of the Bitbybit API ${resolved.version}, not a namespace; describe it with describe, or list ${siblings} for its siblings.`,
|
|
41
|
+
{ version: resolved.version, notNamespace: path, kind: parent.kind },
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const children = resolved.reader.children(path);
|
|
45
|
+
const members = children.map((member) => ({ path: member.path, kind: member.kind, tier: member.tier, summary: member.summary, engines: member.engines }));
|
|
46
|
+
const heading = path ? `${path}${parent?.summary ? `: ${parent.summary}` : ""}` : `Top-level namespaces of the Bitbybit API ${resolved.version}`;
|
|
47
|
+
const text = [heading, ...children.map(renderLine)].join("\n");
|
|
48
|
+
return ok(text, { version: resolved.version, path: path ?? null, members });
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ToolDefinition } from "../registry.js";
|
|
3
|
+
import type { DocsContext } from "../context.js";
|
|
4
|
+
import { DESCRIPTIONS } from "../descriptions.js";
|
|
5
|
+
import { ok, failFor } from "../results.js";
|
|
6
|
+
import { renderLine } from "../render.js";
|
|
7
|
+
|
|
8
|
+
const ENGINES = ["babylonjs", "threejs", "playcanvas"] as const;
|
|
9
|
+
const MAX_LIMIT = 50;
|
|
10
|
+
const MAX_QUERY_LENGTH = 200;
|
|
11
|
+
|
|
12
|
+
const input = z.object({
|
|
13
|
+
query: z.string().min(1).max(MAX_QUERY_LENGTH).describe("Keywords, a phrase, or a partial dotted path"),
|
|
14
|
+
engine: z.enum(ENGINES).optional().describe("Only members published for this engine, plus the cloud operations, which run on CAD Cloud rather than in an engine; omit for every engine"),
|
|
15
|
+
limit: z.number().int().min(1).max(MAX_LIMIT).optional().describe("How many results, 10 by default"),
|
|
16
|
+
version: z.string().optional().describe("The API version to search; omit for the version the server holds"),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const searchApi: ToolDefinition<typeof input, DocsContext> = {
|
|
20
|
+
name: "search_api",
|
|
21
|
+
description: DESCRIPTIONS.search_api.description,
|
|
22
|
+
annotations: { title: DESCRIPTIONS.search_api.title, readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
23
|
+
input,
|
|
24
|
+
where: "server",
|
|
25
|
+
handler: async (args, context) => {
|
|
26
|
+
let resolved;
|
|
27
|
+
try {
|
|
28
|
+
resolved = await context.resolve(args.version);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return failFor(error);
|
|
31
|
+
}
|
|
32
|
+
const query = args.query.replace(/^bitbybit\./, "");
|
|
33
|
+
const hits = resolved.reader.search(query, { engine: args.engine, limit: args.limit });
|
|
34
|
+
const results = hits.map((hit) => ({
|
|
35
|
+
path: hit.member.path,
|
|
36
|
+
kind: hit.member.kind,
|
|
37
|
+
tier: hit.member.tier,
|
|
38
|
+
summary: hit.member.summary,
|
|
39
|
+
engines: hit.member.engines,
|
|
40
|
+
onApi3d: hit.member.onApi3d,
|
|
41
|
+
}));
|
|
42
|
+
const text = hits.length === 0
|
|
43
|
+
? `No member of the Bitbybit API ${resolved.version} matches "${args.query}". Try other words, or list_namespace to browse.`
|
|
44
|
+
: [`${hits.length} result(s) for "${args.query}" in Bitbybit API ${resolved.version}:`, ...hits.map((hit) => renderLine(hit.member))].join("\n");
|
|
45
|
+
return ok(text, { version: resolved.version, query: args.query, results });
|
|
46
|
+
},
|
|
47
|
+
};
|