Open History to see the last commit
1import { expect, it } from "@effect/vitest";
2import { Tool } from "effect/ai";
3
4import { PreviewToolkit } from "./tools.ts";
5
6const schemaHasMultipleAllOfDescriptions = (schema: unknown): boolean => {
7 if (!schema || typeof schema !== "object") return false;
8 const record = schema as Record<string, unknown>;
9 const allOf = Array.isArray(record.allOf) ? record.allOf : [];
10 const descriptionCount = allOf.filter(
11 (member) =>
12 member !== null &&
13 typeof member === "object" &&
14 typeof (member as Record<string, unknown>).description === "string",
15 ).length;
16 return descriptionCount > 1 || Object.values(record).some(schemaHasMultipleAllOfDescriptions);
17};
18
19it("exports provider-compatible object schemas", () => {
20 for (const tool of Object.values(PreviewToolkit.tools)) {
21 const schema = Tool.getJsonSchema(tool) as {
22 readonly type?: unknown;
23 readonly properties?: Readonly<Record<string, unknown>>;
24 readonly anyOf?: unknown;
25 readonly oneOf?: unknown;
26 };
27 expect(schema.type, `${tool.name} must export a top-level object schema`).toBe("object");
28 expect(schema.anyOf, `${tool.name} must not export a root anyOf`).toBeUndefined();
29 expect(schema.oneOf, `${tool.name} must not export a root oneOf`).toBeUndefined();
30 if (tool.name === "preview_navigate") {
31 expect(schemaHasMultipleAllOfDescriptions(schema)).toBe(false);
32 }
33 expect(
34 schema.properties?.tabId,
35 `${tool.name} must allow an explicit collaborative browser tab target`,
36 ).toBeDefined();
37 }
38});