Skip to content
Source
Sign inSign up
Open History to see the last commit

advertisedJsonSchema.test.ts

45 lines1.5 KB

1import { expect, it } from "@effect/vitest";
2import * as Schema from "effect/Schema";
3import { Tool } from "effect/ai";
4​
5import { advertisedJsonSchema } from "./advertisedJsonSchema.ts";
6​
7it("drops JSON noise, merges tagged unions, and keeps null where it is required", () => {
8 const Every = Schema.Struct({ ms: Schema.Int });
9 const tool = Tool.make("example", {
10 parameters: Schema.Struct({
11 threadId: Schema.optional(Schema.NullOr(Schema.String)),
12 beforeRunId: Schema.NullOr(Schema.String),
13 limit: Schema.optional(Schema.Int),
14 every: Schema.Union([Every, Schema.fromJsonString(Every)]),
15 target: Schema.optional(
16 Schema.NullOr(
17 Schema.Union([
18 Schema.Struct({ kind: Schema.Literal("url"), url: Schema.String }),
19 Schema.Struct({ kind: Schema.Literal("number"), number: Schema.Int }),
20 ]),
21 ),
22 ),
23 }),
24 });
25​
26 expect(advertisedJsonSchema(tool)).toEqual({
27 type: "object",
28 properties: {
29 threadId: { type: "string" },
30 beforeRunId: { anyOf: [{ type: "string" }, { type: "null" }] },
31 limit: { type: "integer" },
32 every: { type: "object", properties: { ms: { type: "integer" } }, required: ["ms"] },
33 target: {
34 type: "object",
35 properties: {
36 kind: { type: "string", enum: ["url", "number"] },
37 url: { type: "string" },
38 number: { type: "integer" },
39 },
40 required: ["kind"],
41 },
42 },
43 required: ["beforeRunId", "every"],
44 });
45});