fix(core): simplify tool schemas (#39184)

This commit is contained in:
Aiden Cline 2026-07-27 16:04:48 -05:00 committed by GitHub
commit 31124312f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 174 additions and 33 deletions

View file

@ -32,6 +32,67 @@ test("tools are structural values", async () => {
})
})
test("Effect tool schemas use exact optional keys and flatten compatible constraints", () => {
const tool: Info = {
name: "constraints",
description: "Constraints",
input: Schema.Struct({
offset: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
code: Schema.String.check(Schema.isPattern(/^a/), Schema.isPattern(/z$/)),
}),
execute: () => Effect.succeed({ content: "unused" }),
}
expect(definition(tool).inputSchema).toEqual({
type: "object",
properties: {
offset: { type: "integer", minimum: 0 },
code: { type: "string", allOf: [{ pattern: "^a" }, { pattern: "z$" }] },
},
required: ["code"],
additionalProperties: false,
})
})
test("Effect tool schemas inline named child schemas", () => {
const Child = Schema.Struct({ value: Schema.String }).annotate({ identifier: "Child" })
const tool: Info = {
name: "references",
description: "References",
input: Schema.Struct({ child: Child.annotate({ description: "Child value" }) }),
execute: () => Effect.succeed({ content: "unused" }),
}
expect(definition(tool).inputSchema).toEqual({
type: "object",
properties: {
child: {
type: "object",
properties: { value: { type: "string" } },
required: ["value"],
additionalProperties: false,
description: "Child value",
},
},
required: ["child"],
additionalProperties: false,
})
})
test("Effect tool schemas resolve escaped definition names", () => {
const Slash = Schema.Struct({ slash: Schema.String }).annotate({ identifier: "A/B" })
const Tilde = Schema.Struct({ tilde: Schema.String }).annotate({ identifier: "A~B" })
const tool: Info = {
name: "escaped-references",
description: "Escaped references",
input: Schema.Struct({ slash: Slash, tilde: Tilde }),
execute: () => Effect.succeed({ content: "unused" }),
}
expect(JSON.stringify(definition(tool).inputSchema)).not.toContain("$ref")
expect(JSON.stringify(definition(tool).inputSchema)).not.toContain("$defs")
})
test("portable schemas validate and describe typed tools", async () => {
const input = {
"~standard": {