| 1 | import { assert, describe, it } from "@effect/vitest" |
| 2 | import { Schema } from "effect" |
| 3 | import { Tool } from "effect/ai" |
| 4 | |
| 5 | describe("Tool representation v2", () => { |
| 6 | it("projects the encoded side before JSON Schema generation", () => { |
| 7 | assert.strictEqual(Tool.getJsonSchemaFromSchema(Schema.FiniteFromString).type, "string") |
| 8 | }) |
| 9 | |
| 10 | it("uses custom JSON Schema compiler annotations for schema parameters", () => { |
| 11 | const schema = Schema.Struct({ |
| 12 | value: Schema.String.check(Schema.makeFilter<string>((value) => value.length >= 2, { |
| 13 | representation: { |
| 14 | id: "test/ai/tool/minTwoCharacters", |
| 15 | payload: null |
| 16 | }, |
| 17 | toJsonSchema: () => ({ minLength: 2 }) |
| 18 | })) |
| 19 | }) |
| 20 | const tool = Tool.make("CustomCheck", { parameters: schema }) |
| 21 | |
| 22 | assert.deepStrictEqual(Tool.getJsonSchema(tool), Tool.getJsonSchemaFromSchema(schema)) |
| 23 | assert.deepStrictEqual(Tool.getJsonSchema(tool), { |
| 24 | type: "object", |
| 25 | properties: { |
| 26 | value: { |
| 27 | type: "string", |
| 28 | minLength: 2 |
| 29 | } |
| 30 | }, |
| 31 | required: ["value"], |
| 32 | additionalProperties: true |
| 33 | }) |
| 34 | }) |
| 35 | }) |