Open History to see the last commit
1import { expect, it } from "@effect/vitest";
2import { Tool } from "effect/unstable/ai";
3
4import { PreviewToolkit } from "./tools.ts";
5
6const schemaHasDescription = (schema: unknown): boolean => {
7 if (!schema || typeof schema !== "object") return false;
8 const record = schema as Record<string, unknown>;
9 if (typeof record.description === "string" && record.description.length > 0) return true;
10 return [record.anyOf, record.oneOf, record.allOf]
11 .filter(Array.isArray)
12 .some((members) => members.some(schemaHasDescription));
13};
14
15it("exports provider-compatible object schemas with described parameters", () => {
16 for (const tool of Object.values(PreviewToolkit.tools)) {
17 const schema = Tool.getJsonSchema(tool) as {
18 readonly type?: unknown;
19 readonly properties?: Readonly<Record<string, unknown>>;
20 readonly anyOf?: unknown;
21 readonly oneOf?: unknown;
22 };
23 expect(
24 tool.description?.length ?? 0,
25 `${tool.name} should have a useful description`,
26 ).toBeGreaterThan(40);
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 expect(
31 schema.properties?.tabId,
32 `${tool.name} must allow an explicit collaborative browser tab target`,
33 ).toBeDefined();
34 for (const [field, fieldSchema] of Object.entries(schema.properties ?? {})) {
35 expect(
36 schemaHasDescription(fieldSchema),
37 `${tool.name}.${field} should explain what data the agent must pass`,
38 ).toBe(true);
39 }
40 }
41});