@bitbybit-dev/mcp 1.4.0 → 1.5.0-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/README.md +3 -3
- package/dist/descriptions.d.ts.map +1 -1
- package/dist/descriptions.js +10 -5
- package/dist/descriptions.js.map +1 -1
- package/dist/guides-split.d.ts +6 -0
- package/dist/guides-split.d.ts.map +1 -1
- package/dist/guides-split.js +17 -3
- package/dist/guides-split.js.map +1 -1
- package/dist/guides.generated.d.ts +4 -3
- package/dist/guides.generated.d.ts.map +1 -1
- package/dist/guides.generated.js +249 -17
- package/dist/guides.generated.js.map +1 -1
- package/dist/index-loader.d.ts.map +1 -1
- package/dist/index-loader.js +10 -5
- package/dist/index-loader.js.map +1 -1
- package/dist/index-reader.d.ts +11 -1
- package/dist/index-reader.d.ts.map +1 -1
- package/dist/index-reader.js +87 -22
- package/dist/index-reader.js.map +1 -1
- package/dist/index-shape.d.ts.map +1 -1
- package/dist/index-shape.js +4 -2
- package/dist/index-shape.js.map +1 -1
- package/dist/index-types.d.ts +7 -0
- package/dist/index-types.d.ts.map +1 -1
- package/dist/index-url.d.ts.map +1 -1
- package/dist/index-url.js +2 -1
- package/dist/index-url.js.map +1 -1
- package/dist/installed-version.d.ts.map +1 -1
- package/dist/installed-version.js +14 -7
- package/dist/installed-version.js.map +1 -1
- package/dist/json-schema.d.ts.map +1 -1
- package/dist/json-schema.js +16 -8
- package/dist/json-schema.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +6 -3
- package/dist/registry.js.map +1 -1
- package/dist/render.d.ts +3 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +55 -21
- package/dist/render.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +4 -2
- package/dist/server.js.map +1 -1
- package/dist/stdio.js +4 -2
- package/dist/stdio.js.map +1 -1
- package/dist/tools/describe.d.ts.map +1 -1
- package/dist/tools/describe.js +13 -3
- package/dist/tools/describe.js.map +1 -1
- package/dist/tools/fetch.d.ts.map +1 -1
- package/dist/tools/fetch.js +3 -2
- package/dist/tools/fetch.js.map +1 -1
- package/dist/tools/get-examples.d.ts.map +1 -1
- package/dist/tools/get-examples.js +8 -4
- package/dist/tools/get-examples.js.map +1 -1
- package/dist/tools/get-guide.d.ts.map +1 -1
- package/dist/tools/get-guide.js +52 -7
- package/dist/tools/get-guide.js.map +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/src/__fixtures__/index.sample.json +261 -0
- package/src/__fixtures__/load.ts +1 -0
- package/src/descriptions.ts +10 -5
- package/src/guides-split.ts +27 -3
- package/src/guides.generated.ts +249 -17
- package/src/guides.test.ts +41 -7
- package/src/index-loader.test.ts +3 -1
- package/src/index-loader.ts +15 -5
- package/src/index-reader.ts +116 -21
- package/src/index-shape.ts +6 -2
- package/src/index-types.ts +8 -0
- package/src/index-url.ts +3 -1
- package/src/installed-version.test.ts +3 -1
- package/src/installed-version.ts +21 -7
- package/src/json-schema.ts +21 -7
- package/src/registry.ts +9 -3
- package/src/render.test.ts +153 -1
- package/src/render.ts +78 -20
- package/src/server.ts +6 -2
- package/src/stdio.test.ts +15 -5
- package/src/stdio.ts +6 -2
- package/src/tools/describe.ts +13 -3
- package/src/tools/docs-tools.test.ts +57 -1
- package/src/tools/fetch.ts +4 -2
- package/src/tools/get-examples.ts +12 -4
- package/src/tools/get-guide.ts +54 -7
package/src/render.ts
CHANGED
|
@@ -1,19 +1,36 @@
|
|
|
1
1
|
import type { IndexExample, IndexField, IndexMember, IndexParam } from "./index-types.js";
|
|
2
|
+
import type { NamedType } from "./index-reader.js";
|
|
2
3
|
import { TIER_MEANING } from "./descriptions.js";
|
|
3
4
|
|
|
5
|
+
type IndexOption = NonNullable<IndexField["options"]>[number];
|
|
6
|
+
|
|
7
|
+
function renderOption(option: IndexOption): string {
|
|
8
|
+
return option.label === option.value ? option.value : `${option.label} = ${JSON.stringify(option.value)}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
function renderField(field: IndexField): string {
|
|
5
12
|
const parts = [`${field.name}${field.optional ? "?" : ""}: ${field.type}`];
|
|
6
|
-
if (field.default !== undefined)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (field.
|
|
13
|
+
if (field.default !== undefined) {
|
|
14
|
+
parts.push(`default ${JSON.stringify(field.default)}`);
|
|
15
|
+
}
|
|
16
|
+
if (field.min !== undefined || field.max !== undefined) {
|
|
17
|
+
parts.push(`range ${field.min ?? "..."} to ${field.max ?? "..."}`);
|
|
18
|
+
}
|
|
19
|
+
if (field.step !== undefined) {
|
|
20
|
+
parts.push(`step ${field.step}`);
|
|
21
|
+
}
|
|
22
|
+
if (field.options) {
|
|
23
|
+
parts.push(`one of ${field.options.map(renderOption).join(", ")}`);
|
|
24
|
+
}
|
|
10
25
|
const doc = field.doc ? ` - ${field.doc.replace(/\s+/g, " ")}` : "";
|
|
11
26
|
return `- ${parts.join("; ")}${doc}`;
|
|
12
27
|
}
|
|
13
28
|
|
|
14
29
|
function renderParam(param: IndexParam): string[] {
|
|
15
30
|
const head = `**${param.name}${param.optional ? "?" : ""}**: \`${param.type}\``;
|
|
16
|
-
if (!param.fields || param.fields.length === 0)
|
|
31
|
+
if (!param.fields || param.fields.length === 0) {
|
|
32
|
+
return [head];
|
|
33
|
+
}
|
|
17
34
|
return [head, ...param.fields.map(renderField)];
|
|
18
35
|
}
|
|
19
36
|
|
|
@@ -21,38 +38,79 @@ function renderExample(example: IndexExample): string {
|
|
|
21
38
|
return ["```typescript", example.code, "```"].join("\n");
|
|
22
39
|
}
|
|
23
40
|
|
|
24
|
-
|
|
41
|
+
function renderTypes(types: readonly NamedType[]): string[] {
|
|
42
|
+
return types.length === 0 ? [] : ["## Types", "", "Describe one by its name for its fields:", ...types.map(({ key, type }) => `- \`${key}\`${type.summary ? `: ${type.summary}` : ""}`), ""];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function renderType(named: NamedType, version: string, used: readonly NamedType[]): string {
|
|
46
|
+
const lines = [`# ${named.key}`, "", "- kind: type", `- version: ${version}`, ""];
|
|
47
|
+
if (named.type.doc) {
|
|
48
|
+
lines.push(named.type.doc, "");
|
|
49
|
+
}
|
|
50
|
+
lines.push("## Fields", "", ...named.type.fields.map(renderField), "", ...renderTypes(used));
|
|
51
|
+
return lines.join("\n").trimEnd() + "\n";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function renderMember(member: IndexMember, version: string, examples: IndexExample[], types: readonly NamedType[] = []): string {
|
|
25
55
|
const lines: string[] = [`# ${member.path}`, ""];
|
|
26
56
|
const facts = [`kind: ${member.kind}`, `tier: ${member.tier} (${TIER_MEANING[member.tier]})`, `version: ${version}`];
|
|
27
|
-
if (member.engines.length > 0)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (member.
|
|
31
|
-
|
|
32
|
-
|
|
57
|
+
if (member.engines.length > 0) {
|
|
58
|
+
facts.push(`engines: ${member.engines.join(", ")}`);
|
|
59
|
+
}
|
|
60
|
+
if (member.onApi3d) {
|
|
61
|
+
facts.push("runs on CAD Cloud: yes");
|
|
62
|
+
}
|
|
63
|
+
if (member.endpoint) {
|
|
64
|
+
facts.push(`endpoint: ${member.httpMethod ?? "POST"} ${member.endpoint}`);
|
|
65
|
+
}
|
|
66
|
+
if (member.scope) {
|
|
67
|
+
facts.push(`API key scope: ${member.scope}`);
|
|
68
|
+
}
|
|
69
|
+
if (member.deprecated !== undefined) {
|
|
70
|
+
facts.push(member.deprecated ? `deprecated: ${member.deprecated}` : "deprecated");
|
|
71
|
+
}
|
|
72
|
+
if (member.drawable) {
|
|
73
|
+
facts.push("drawable: the result can be drawn directly");
|
|
74
|
+
}
|
|
33
75
|
lines.push(...facts.map((fact) => `- ${fact}`), "");
|
|
34
|
-
if (member.signature)
|
|
76
|
+
if (member.signature) {
|
|
77
|
+
lines.push("```typescript", member.signature, "```", "");
|
|
78
|
+
}
|
|
35
79
|
if (member.engineSignatures) {
|
|
36
80
|
lines.push("Signature by engine:", ...Object.entries(member.engineSignatures).map(([engine, signature]) => `- ${engine}: \`${signature ?? "none"}\``), "");
|
|
37
81
|
}
|
|
38
|
-
if (member.doc)
|
|
39
|
-
|
|
82
|
+
if (member.doc) {
|
|
83
|
+
lines.push(member.doc, "");
|
|
84
|
+
} else if (member.summary) {
|
|
85
|
+
lines.push(member.summary, "");
|
|
86
|
+
}
|
|
40
87
|
if (member.params.length > 0) {
|
|
41
88
|
lines.push("## Parameters", "");
|
|
42
|
-
for (const param of member.params)
|
|
89
|
+
for (const param of member.params) {
|
|
90
|
+
lines.push(...renderParam(param));
|
|
91
|
+
}
|
|
43
92
|
lines.push("");
|
|
44
93
|
}
|
|
45
94
|
if (member.cloudParams) {
|
|
46
95
|
lines.push("## Parameters on CAD Cloud", "", "The signature above is the browser one; a cad_execute or pipeline step takes these inputs instead.", "");
|
|
47
|
-
if (member.cloudSummary)
|
|
48
|
-
|
|
96
|
+
if (member.cloudSummary) {
|
|
97
|
+
lines.push(member.cloudSummary, "");
|
|
98
|
+
}
|
|
99
|
+
for (const param of member.cloudParams) {
|
|
100
|
+
lines.push(...renderParam(param));
|
|
101
|
+
}
|
|
49
102
|
lines.push("");
|
|
50
103
|
}
|
|
51
|
-
if (member.returns)
|
|
104
|
+
if (member.returns) {
|
|
105
|
+
lines.push(`## Returns`, "", `\`${member.returns}\`${member.async ? " (async)" : ""}`, "");
|
|
106
|
+
}
|
|
107
|
+
lines.push(...renderTypes(types));
|
|
52
108
|
if (examples.length > 0) {
|
|
53
109
|
lines.push("## Examples", "", ...examples.map(renderExample), "");
|
|
54
110
|
}
|
|
55
|
-
if (member.docUrl)
|
|
111
|
+
if (member.docUrl) {
|
|
112
|
+
lines.push(`Reference: ${member.docUrl}`);
|
|
113
|
+
}
|
|
56
114
|
return lines.join("\n").trimEnd() + "\n";
|
|
57
115
|
}
|
|
58
116
|
|
package/src/server.ts
CHANGED
|
@@ -69,7 +69,9 @@ export function bindRegistry<TContext>(
|
|
|
69
69
|
const bound: string[] = [];
|
|
70
70
|
for (const definition of registry.list()) {
|
|
71
71
|
const { handler } = definition;
|
|
72
|
-
if (!handler || (filter && !filter(definition)))
|
|
72
|
+
if (!handler || (filter && !filter(definition))) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
73
75
|
const { annotations } = definition;
|
|
74
76
|
server.registerTool(
|
|
75
77
|
definition.name,
|
|
@@ -104,7 +106,9 @@ function carrying<TContext>(context: TContext): AuthInfo {
|
|
|
104
106
|
|
|
105
107
|
function carried<TContext>(authInfo: AuthInfo | undefined): TContext {
|
|
106
108
|
const context = authInfo?.extra?.[REQUEST_CONTEXT];
|
|
107
|
-
if (context === undefined)
|
|
109
|
+
if (context === undefined) {
|
|
110
|
+
throw new Error("The request carries no context; serve it through the request handler's own fetch");
|
|
111
|
+
}
|
|
108
112
|
return context as TContext;
|
|
109
113
|
}
|
|
110
114
|
|
package/src/stdio.test.ts
CHANGED
|
@@ -31,14 +31,18 @@ function buildIsStale(): boolean {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
beforeAll(() => {
|
|
34
|
-
if (buildIsStale())
|
|
34
|
+
if (buildIsStale()) {
|
|
35
|
+
execFileSync("npx", ["tsc", "-p", "tsconfig.build.json"], { cwd: PACKAGE_DIRECTORY, stdio: "ignore", timeout: BUILD_TIMEOUT_MS });
|
|
36
|
+
}
|
|
35
37
|
cacheHome = mkdtempSync(join(tmpdir(), "bitbybit-mcp-stdio-"));
|
|
36
38
|
mkdirSync(join(cacheHome, "bitbybit-mcp"), { recursive: true });
|
|
37
39
|
writeFileSync(join(cacheHome, "bitbybit-mcp", `index-v${FIXTURE_VERSION}.json`), JSON.stringify(fixtureIndex()), "utf8");
|
|
38
40
|
}, BUILD_TIMEOUT_MS);
|
|
39
41
|
|
|
40
42
|
afterAll(() => {
|
|
41
|
-
if (cacheHome)
|
|
43
|
+
if (cacheHome) {
|
|
44
|
+
rmSync(cacheHome, { recursive: true, force: true });
|
|
45
|
+
}
|
|
42
46
|
});
|
|
43
47
|
|
|
44
48
|
function run(args: string[], messages: object[]): Promise<Session> {
|
|
@@ -55,10 +59,16 @@ function run(args: string[], messages: object[]): Promise<Session> {
|
|
|
55
59
|
let answered = 0;
|
|
56
60
|
child.stdout.on("data", () => {
|
|
57
61
|
answered = out.split("\n").filter((line) => line.includes("\"result\"")).length;
|
|
58
|
-
if (answered >= expected)
|
|
62
|
+
if (answered >= expected) {
|
|
63
|
+
child.stdin.end();
|
|
64
|
+
}
|
|
59
65
|
});
|
|
60
|
-
for (const message of messages)
|
|
61
|
-
|
|
66
|
+
for (const message of messages) {
|
|
67
|
+
child.stdin.write(`${JSON.stringify(message)}\n`);
|
|
68
|
+
}
|
|
69
|
+
if (expected === 0) {
|
|
70
|
+
child.stdin.end();
|
|
71
|
+
}
|
|
62
72
|
});
|
|
63
73
|
}
|
|
64
74
|
|
package/src/stdio.ts
CHANGED
|
@@ -26,7 +26,9 @@ instead and a note says so. Everything this program prints goes to stderr; stdou
|
|
|
26
26
|
|
|
27
27
|
function ownVersion(): string {
|
|
28
28
|
const manifest: unknown = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
29
|
-
if (typeof manifest === "object" && manifest !== null && "version" in manifest && typeof manifest.version === "string")
|
|
29
|
+
if (typeof manifest === "object" && manifest !== null && "version" in manifest && typeof manifest.version === "string") {
|
|
30
|
+
return manifest.version;
|
|
31
|
+
}
|
|
30
32
|
throw new Error("The package manifest carries no version");
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -34,7 +36,9 @@ async function loadServed(detected: DetectedVersion, own: string, cacheDir: stri
|
|
|
34
36
|
try {
|
|
35
37
|
return { index: await loadIndex({ version: detected.version, cacheDir }), served: detected };
|
|
36
38
|
} catch (error) {
|
|
37
|
-
if (!(error instanceof IndexNotPublishedError) || detected.source !== "installed" || detected.version === own)
|
|
39
|
+
if (!(error instanceof IndexNotPublishedError) || detected.source !== "installed" || detected.version === own) {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
38
42
|
console.error(`bitbybit-mcp: ${error.message}`);
|
|
39
43
|
console.error(`bitbybit-mcp: serving this package's version ${own} instead; answers describe ${own}, not the installed ${detected.version}`);
|
|
40
44
|
const served: DetectedVersion = { version: own, source: "own" };
|
package/src/tools/describe.ts
CHANGED
|
@@ -3,12 +3,12 @@ import type { ToolDefinition } from "../registry.js";
|
|
|
3
3
|
import type { DocsContext } from "../context.js";
|
|
4
4
|
import { DESCRIPTIONS } from "../descriptions.js";
|
|
5
5
|
import { ok, failFor } from "../results.js";
|
|
6
|
-
import { renderLine, renderMember } from "../render.js";
|
|
6
|
+
import { renderLine, renderMember, renderType } from "../render.js";
|
|
7
7
|
|
|
8
8
|
const MAX_PATH_LENGTH = 256;
|
|
9
9
|
|
|
10
10
|
const input = z.object({
|
|
11
|
-
path: z.string().min(1).max(MAX_PATH_LENGTH).describe("The dotted path of the member, for example occt.shapes.solid.createBox"),
|
|
11
|
+
path: z.string().min(1).max(MAX_PATH_LENGTH).describe("The dotted path of the member, for example occt.shapes.solid.createBox, or the name of a type a member returns or takes, for example Inputs.IFC.SpaceInfoDto"),
|
|
12
12
|
version: z.string().optional().describe("The API version to describe; omit for the version the server holds"),
|
|
13
13
|
});
|
|
14
14
|
|
|
@@ -27,6 +27,15 @@ export const describe: ToolDefinition<typeof input, DocsContext> = {
|
|
|
27
27
|
}
|
|
28
28
|
const path = args.path.replace(/^bitbybit\./, "");
|
|
29
29
|
const member = resolved.reader.get(path);
|
|
30
|
+
const named = member ? undefined : resolved.reader.type(path);
|
|
31
|
+
if (named) {
|
|
32
|
+
return ok(renderType(named, resolved.version, resolved.reader.typesUsedByType(named)), { version: resolved.version, type: { key: named.key, ...named.type } });
|
|
33
|
+
}
|
|
34
|
+
const sharing = member ? [] : resolved.reader.typeKeysNamed(path);
|
|
35
|
+
if (sharing.length > 1) {
|
|
36
|
+
const text = [`${path} names ${sharing.length} types in the Bitbybit API ${resolved.version}; describe one by its full name:`, ...sharing.map((key) => `- ${key}`)].join("\n");
|
|
37
|
+
return ok(text, { version: resolved.version, notFound: path, types: sharing });
|
|
38
|
+
}
|
|
30
39
|
if (!member) {
|
|
31
40
|
const nearest = resolved.reader.nearest(path);
|
|
32
41
|
const text = [
|
|
@@ -37,6 +46,7 @@ export const describe: ToolDefinition<typeof input, DocsContext> = {
|
|
|
37
46
|
return ok(text, { version: resolved.version, notFound: path, nearest: nearest.map((candidate) => candidate.path) });
|
|
38
47
|
}
|
|
39
48
|
const examples = resolved.reader.examplesOf(path);
|
|
40
|
-
|
|
49
|
+
const types = resolved.reader.typesUsedBy(member);
|
|
50
|
+
return ok(renderMember(member, resolved.version, examples, types), { version: resolved.version, member, examples, types: types.map((used) => used.key) });
|
|
41
51
|
},
|
|
42
52
|
};
|
|
@@ -7,7 +7,9 @@ import { FIXTURE_VERSION, GUIDE_URL, fixtureContext } from "../__fixtures__/load
|
|
|
7
7
|
|
|
8
8
|
function tool(name: string): HttpTool {
|
|
9
9
|
const found = toHttp(createDocsRegistry(), fixtureContext()).find((candidate) => candidate.name === name);
|
|
10
|
-
if (!found)
|
|
10
|
+
if (!found) {
|
|
11
|
+
throw new Error(`no tool ${name}`);
|
|
12
|
+
}
|
|
11
13
|
return found;
|
|
12
14
|
}
|
|
13
15
|
|
|
@@ -105,6 +107,41 @@ describe("describe", () => {
|
|
|
105
107
|
expect(result.text).toContain("## Examples");
|
|
106
108
|
});
|
|
107
109
|
|
|
110
|
+
it("lists the types a member returns in its answer, by full name", async () => {
|
|
111
|
+
// Act
|
|
112
|
+
const result = await call("describe", { path: "ifc.model.summary" });
|
|
113
|
+
|
|
114
|
+
// Assert
|
|
115
|
+
expect(structured(result)["types"]).toEqual(["Inputs.IFC.ModelSummaryDto"]);
|
|
116
|
+
expect(result.text).toContain("## Types");
|
|
117
|
+
expect(result.text).toContain("- `Inputs.IFC.ModelSummaryDto`: What a model holds");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("describes a type a member returns, field by field, by its full or its short name", async () => {
|
|
121
|
+
// Act
|
|
122
|
+
const full = await call("describe", { path: "Inputs.IFC.ModelSummaryDto" });
|
|
123
|
+
const short = await call("describe", { path: "ModelSummaryDto" });
|
|
124
|
+
|
|
125
|
+
// Assert
|
|
126
|
+
const type = structured(full)["type"] as { key: string; fields: { name: string }[] };
|
|
127
|
+
expect(type.key).toBe("Inputs.IFC.ModelSummaryDto");
|
|
128
|
+
expect(type.fields.map((field) => field.name)).toEqual(["schema", "editable", "project", "millimetresPerUnit", "entities", "storeys", "elementCounts"]);
|
|
129
|
+
expect(structured(full)["version"]).toBe(FIXTURE_VERSION);
|
|
130
|
+
expect(full.text).toContain("- millimetresPerUnit: number; default 1 - How many millimetres one length unit of the model is.");
|
|
131
|
+
expect(full.text).toContain("- `Inputs.IFC.StoreyInfoDto`");
|
|
132
|
+
expect(short.text).toBe(full.text);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("names every type a short name could mean instead of choosing one", async () => {
|
|
136
|
+
// Act
|
|
137
|
+
const result = await call("describe", { path: "DecomposedManifoldMeshDto" });
|
|
138
|
+
|
|
139
|
+
// Assert
|
|
140
|
+
expect(structured(result)["notFound"]).toBe("DecomposedManifoldMeshDto");
|
|
141
|
+
expect(structured(result)["types"]).toEqual(["Inputs.OCCT.DecomposedManifoldMeshDto", "Inputs.Manifold.DecomposedManifoldMeshDto"]);
|
|
142
|
+
expect(result.text).toContain("- Inputs.Manifold.DecomposedManifoldMeshDto");
|
|
143
|
+
});
|
|
144
|
+
|
|
108
145
|
it("accepts the bitbybit. prefix", async () => {
|
|
109
146
|
// Act
|
|
110
147
|
const result = await call("describe", { path: "bitbybit.occt.shapes.solid.createBox" });
|
|
@@ -323,6 +360,17 @@ describe("get_guide", () => {
|
|
|
323
360
|
expect(structured(result)["id"]).toBe("browser-apps");
|
|
324
361
|
});
|
|
325
362
|
|
|
363
|
+
it("links a section of another page to that page, and lists the sections page by page", async () => {
|
|
364
|
+
// Act
|
|
365
|
+
const design = await call("get_guide", { topic: "design" });
|
|
366
|
+
const listing = await call("get_guide", {});
|
|
367
|
+
|
|
368
|
+
// Assert
|
|
369
|
+
expect(structured(design)["url"]).toBe("https://example.test/design#what-a-design-document-is");
|
|
370
|
+
expect(structured(listing)["pages"]).toEqual([GUIDE_URL, "https://example.test/design"]);
|
|
371
|
+
expect(listing.text).toContain("Sections of https://example.test/design:\n- what-a-design-document-is: What a design document is");
|
|
372
|
+
});
|
|
373
|
+
|
|
326
374
|
it("names the sections when nothing matches", async () => {
|
|
327
375
|
// Act
|
|
328
376
|
const result = await call("get_guide", { topic: "kitchen" });
|
|
@@ -356,6 +404,14 @@ describe("search and fetch, the connector shape", () => {
|
|
|
356
404
|
expect(JSON.parse(result.text)).toEqual(structured(result));
|
|
357
405
|
});
|
|
358
406
|
|
|
407
|
+
it("fetch lists the types a member returns, as describe does", async () => {
|
|
408
|
+
// Act
|
|
409
|
+
const result = await call("fetch", { id: "ifc.model.summary" });
|
|
410
|
+
|
|
411
|
+
// Assert
|
|
412
|
+
expect(structured(result)["text"]).toContain("- `Inputs.IFC.ModelSummaryDto`: What a model holds");
|
|
413
|
+
});
|
|
414
|
+
|
|
359
415
|
it("fetch accepts the bitbybit. prefix like every other tool", async () => {
|
|
360
416
|
// Act
|
|
361
417
|
const result = await call("fetch", { id: "bitbybit.occt.shapes.solid.createBox" });
|
package/src/tools/fetch.ts
CHANGED
|
@@ -26,11 +26,13 @@ export const fetchTool: ToolDefinition<typeof input, DocsContext> = {
|
|
|
26
26
|
}
|
|
27
27
|
const id = args.id.replace(/^bitbybit\./, "");
|
|
28
28
|
const member = resolved.reader.get(id);
|
|
29
|
-
if (!member)
|
|
29
|
+
if (!member) {
|
|
30
|
+
return fail(`No document has the id ${id}; ids are dotted API paths returned by search.`);
|
|
31
|
+
}
|
|
30
32
|
const document = {
|
|
31
33
|
id: member.path,
|
|
32
34
|
title: member.path,
|
|
33
|
-
text: renderMember(member, resolved.version, resolved.reader.examplesOf(member.path)),
|
|
35
|
+
text: renderMember(member, resolved.version, resolved.reader.examplesOf(member.path), resolved.reader.typesUsedBy(member)),
|
|
34
36
|
url: member.docUrl ?? context.guideUrl,
|
|
35
37
|
metadata: { tier: member.tier, kind: member.kind, version: resolved.version, engines: member.engines.join(",") },
|
|
36
38
|
};
|
|
@@ -39,20 +39,28 @@ export const getExamples: ToolDefinition<typeof input, DocsContext> = {
|
|
|
39
39
|
let examples: IndexExample[] = [];
|
|
40
40
|
if (args.path !== undefined) {
|
|
41
41
|
const path = args.path.replace(/^bitbybit\./, "");
|
|
42
|
-
if (!reader.get(path) && reader.children(path).length === 0)
|
|
42
|
+
if (!reader.get(path) && reader.children(path).length === 0) {
|
|
43
|
+
return fail(`${path} is not a member of the Bitbybit API ${resolved.version}; call describe to see the nearest paths.`);
|
|
44
|
+
}
|
|
43
45
|
examples = reader.examplesOf(path);
|
|
44
|
-
if (examples.length < limit)
|
|
46
|
+
if (examples.length < limit) {
|
|
47
|
+
examples = [...examples, ...reader.examplesUnder(path, limit - examples.length)];
|
|
48
|
+
}
|
|
45
49
|
} else if (args.topic !== undefined) {
|
|
46
50
|
for (const hit of reader.search(args.topic, { engine: args.engine, limit: MAX_LIMIT })) {
|
|
47
51
|
for (const example of reader.examplesOf(hit.member.path)) {
|
|
48
|
-
if (examples.length >= limit)
|
|
52
|
+
if (examples.length >= limit) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
49
55
|
examples.push(example);
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
59
|
examples = examples.slice(0, limit);
|
|
54
60
|
const rows = examples.map((example) => ({ path: example.path, code: example.code, url: reader.get(example.path)?.docUrl ?? null }));
|
|
55
|
-
if (rows.length === 0)
|
|
61
|
+
if (rows.length === 0) {
|
|
62
|
+
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: [] });
|
|
63
|
+
}
|
|
56
64
|
const text = rows.map((row) => `// ${row.path}${row.url ? ` (${row.url})` : ""}\n${row.code}`).join("\n\n");
|
|
57
65
|
return ok(text, { version: resolved.version, examples: rows });
|
|
58
66
|
},
|
package/src/tools/get-guide.ts
CHANGED
|
@@ -25,24 +25,69 @@ export const GUIDE_ALIASES: Readonly<Record<string, string>> = {
|
|
|
25
25
|
layers: "three-layers-you-can-use",
|
|
26
26
|
trust: "trust",
|
|
27
27
|
companies: "for-companies",
|
|
28
|
+
design: "what-a-design-document-is",
|
|
29
|
+
"design-document": "what-a-design-document-is",
|
|
30
|
+
"design-documents": "what-a-design-document-is",
|
|
31
|
+
documents: "what-a-design-document-is",
|
|
32
|
+
"build-loop": "the-loop-an-agent-should-follow",
|
|
33
|
+
validate: "the-loop-an-agent-should-follow",
|
|
34
|
+
references: "references-naming-faces-and-edges",
|
|
35
|
+
sketch: "sketches",
|
|
36
|
+
assembly: "assemblies",
|
|
37
|
+
"design-mistakes": "mistakes-to-avoid",
|
|
38
|
+
geometry: "geometry-in-bitbybit",
|
|
39
|
+
cad: "geometry-in-bitbybit",
|
|
40
|
+
occt: "how-the-occt-kernel-thinks",
|
|
41
|
+
kernels: "which-kernel-to-use",
|
|
42
|
+
manifold: "manifold-and-jscad",
|
|
43
|
+
jscad: "manifold-and-jscad",
|
|
44
|
+
"part-order": "the-order-to-build-a-part-in",
|
|
45
|
+
part: "a-part-to-start-from",
|
|
46
|
+
edges: "choosing-edges-and-faces",
|
|
47
|
+
fillets: "choosing-edges-and-faces",
|
|
48
|
+
check: "checking-a-shape",
|
|
49
|
+
export: "drawing-and-exporting-a-part",
|
|
50
|
+
step: "drawing-and-exporting-a-part",
|
|
51
|
+
mistakes: "mistakes-to-avoid-in-geometry-code",
|
|
52
|
+
"geometry-mistakes": "mistakes-to-avoid-in-geometry-code",
|
|
53
|
+
ifc: "ifc-models-in-bitbybit",
|
|
54
|
+
bim: "ifc-models-in-bitbybit",
|
|
55
|
+
building: "ifc-models-in-bitbybit",
|
|
56
|
+
buildings: "ifc-models-in-bitbybit",
|
|
57
|
+
"ifc-node": "two-ways-to-call-the-ifc-api",
|
|
58
|
+
"ifc-worker": "two-ways-to-call-the-ifc-api",
|
|
59
|
+
"ifc-order": "the-order-to-write-a-building-in",
|
|
60
|
+
"ifc-house": "a-house-to-start-from",
|
|
61
|
+
"ifc-example": "a-house-to-start-from",
|
|
62
|
+
"ifc-check": "checking-an-ifc-model",
|
|
63
|
+
"ifc-validate": "checking-an-ifc-model",
|
|
64
|
+
"ifc-read": "reading-and-changing-ifc-files",
|
|
65
|
+
"ifc-edit": "reading-and-changing-ifc-files",
|
|
66
|
+
"ifc-draw": "drawing-an-ifc-model-and-exporting-step",
|
|
67
|
+
"ifc-step": "drawing-an-ifc-model-and-exporting-step",
|
|
68
|
+
"ifc-mistakes": "mistakes-to-avoid-in-ifc-models",
|
|
28
69
|
};
|
|
29
70
|
|
|
30
71
|
const MAX_TOPIC_LENGTH = 128;
|
|
31
72
|
|
|
32
73
|
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"),
|
|
74
|
+
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, geometry, part-order, geometry-mistakes, design, references, assembly, ifc, ifc-order, ifc-mistakes; omit to list the sections"),
|
|
34
75
|
});
|
|
35
76
|
|
|
36
77
|
function findSection(guides: readonly GuideSection[], topic: string): GuideSection | undefined {
|
|
37
78
|
const wanted = topic.trim().toLowerCase();
|
|
38
79
|
const alias = Object.hasOwn(GUIDE_ALIASES, wanted) ? GUIDE_ALIASES[wanted] : undefined;
|
|
39
80
|
const byId = guides.find((section) => section.id === (alias ?? wanted));
|
|
40
|
-
if (byId)
|
|
81
|
+
if (byId) {
|
|
82
|
+
return byId;
|
|
83
|
+
}
|
|
41
84
|
const words = new Set(tokenize(wanted));
|
|
42
85
|
let best: { section: GuideSection; overlap: number } | undefined;
|
|
43
86
|
for (const section of guides) {
|
|
44
87
|
const overlap = tokenize(section.title).filter((word) => words.has(word)).length;
|
|
45
|
-
if (overlap > 0 && (!best || overlap > best.overlap))
|
|
88
|
+
if (overlap > 0 && (!best || overlap > best.overlap)) {
|
|
89
|
+
best = { section, overlap };
|
|
90
|
+
}
|
|
46
91
|
}
|
|
47
92
|
return best?.section;
|
|
48
93
|
}
|
|
@@ -54,16 +99,18 @@ export const getGuide: ToolDefinition<typeof input, DocsContext> = {
|
|
|
54
99
|
input,
|
|
55
100
|
where: "server",
|
|
56
101
|
handler: (args, context) => {
|
|
57
|
-
const
|
|
102
|
+
const pageOf = (section: GuideSection): string => section.page ?? context.guideUrl;
|
|
103
|
+
const sections = context.guides.map((section) => ({ id: section.id, title: section.title, level: section.level, page: pageOf(section) }));
|
|
58
104
|
if (args.topic === undefined) {
|
|
59
|
-
const
|
|
60
|
-
|
|
105
|
+
const pages = [...new Set(context.guides.map(pageOf))];
|
|
106
|
+
const text = pages.flatMap((page) => [`Sections of ${page}:`, ...context.guides.filter((section) => pageOf(section) === page).map((section) => `- ${section.id}: ${section.title}`)]).join("\n");
|
|
107
|
+
return ok(text, { url: context.guideUrl, pages, sections });
|
|
61
108
|
}
|
|
62
109
|
const section = findSection(context.guides, args.topic);
|
|
63
110
|
if (!section) {
|
|
64
111
|
return ok(`No guide section matches "${args.topic}". Sections: ${context.guides.map((candidate) => candidate.id).join(", ")}.`, { url: context.guideUrl, notFound: args.topic, sections });
|
|
65
112
|
}
|
|
66
|
-
const url = `${
|
|
113
|
+
const url = `${pageOf(section)}#${section.id}`;
|
|
67
114
|
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
115
|
},
|
|
69
116
|
};
|