Open History to see the last commit
1import { expect, it } from "@effect/vitest";
2import * as Schema from "effect/Schema";
3import { Tool } from "effect/ai";
4
5import { advertisedJsonSchema } from "./advertisedJsonSchema.ts";
6import { ThemeToolkit } from "./toolkits/theme/tools.ts";
7
8it("drops JSON noise, merges tagged unions, and keeps null where it is required", () => {
9 const Every = Schema.Struct({ ms: Schema.Int });
10 const tool = Tool.make("example", {
11 parameters: Schema.Struct({
12 threadId: Schema.optional(Schema.NullOr(Schema.String)),
13 beforeRunId: Schema.NullOr(Schema.String),
14 limit: Schema.optional(Schema.Int),
15 every: Schema.Union([Every, Schema.fromJsonString(Every)]),
16 target: Schema.optional(
17 Schema.NullOr(
18 Schema.Union([
19 Schema.Struct({ kind: Schema.Literal("url"), url: Schema.String }),
20 Schema.Struct({ kind: Schema.Literal("number"), number: Schema.Int }),
21 ]),
22 ),
23 ),
24 }),
25 });
26
27 expect(advertisedJsonSchema(tool)).toEqual({
28 type: "object",
29 properties: {
30 threadId: { type: "string" },
31 beforeRunId: { anyOf: [{ type: "string" }, { type: "null" }] },
32 limit: { type: "integer" },
33 every: { type: "object", properties: { ms: { type: "integer" } }, required: ["ms"] },
34 target: {
35 type: "object",
36 properties: {
37 kind: { type: "string", enum: ["url", "number"] },
38 url: { type: "string" },
39 number: { type: "integer" },
40 },
41 required: ["kind"],
42 },
43 },
44 required: ["beforeRunId", "every"],
45 });
46});
47
48it("advertises only string enum values, which Gemini requires", () => {
49 const enumValues: Array<unknown> = [];
50 const collect = (node: unknown): void => {
51 if (Array.isArray(node)) return node.forEach(collect);
52 if (typeof node !== "object" || node === null) return;
53 for (const [key, value] of Object.entries(node)) {
54 if (key === "enum" && Array.isArray(value)) enumValues.push(...value);
55 else collect(value);
56 }
57 };
58 collect(advertisedJsonSchema(ThemeToolkit.tools.t3_theme_set));
59
60 expect(enumValues.filter((value) => typeof value !== "string")).toEqual([]);
61});