mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-30 05:33:31 +00:00
fix(core): tolerate missing tool input schemas (#39130)
Co-authored-by: Dax Raad <d@ironbay.co>
This commit is contained in:
parent
1f2c59a1b6
commit
33e3d1ebca
3 changed files with 34 additions and 1 deletions
|
|
@ -58,7 +58,8 @@ const encodeOutput = (schema: Tool.ValueSchema<any>, value: unknown) => {
|
|||
|
||||
const isStandardSchema = (
|
||||
schema: Tool.ValueSchema<any>,
|
||||
): schema is StandardSchemaV1<any, any> & StandardJSONSchemaV1<any, any> => "~standard" in schema
|
||||
): schema is StandardSchemaV1<any, any> & StandardJSONSchemaV1<any, any> =>
|
||||
typeof schema === "object" && schema !== null && "~standard" in schema
|
||||
|
||||
const validateStandard = (
|
||||
schema: StandardSchemaV1<any, any> & StandardJSONSchemaV1<any, any>,
|
||||
|
|
@ -85,6 +86,7 @@ const standardFailure = (prefix: string, error: unknown) =>
|
|||
new Tool.Error({ message: `${prefix}: ${error instanceof Error ? error.message : String(error)}` })
|
||||
|
||||
const inputJsonSchema = (schema: Tool.ValueSchema<any>): JsonSchema.JsonSchema => {
|
||||
if (schema === undefined || schema === null) return {}
|
||||
if (isStandardSchema(schema))
|
||||
return schema["~standard"].jsonSchema.input({ target: "draft-2020-12" }) as JsonSchema.JsonSchema
|
||||
return Schema.isSchema(schema) ? toJsonSchema(schema) : (schema as JsonSchema.JsonSchema)
|
||||
|
|
|
|||
|
|
@ -140,6 +140,22 @@ describe("Tool", () => {
|
|||
}),
|
||||
)
|
||||
|
||||
it.effect("snapshots external tools with missing input schemas", () =>
|
||||
Effect.gen(function* () {
|
||||
const service = yield* Tool.Service
|
||||
yield* service.transform((draft) =>
|
||||
draft.add({
|
||||
...make(),
|
||||
input: undefined,
|
||||
} as unknown as Info),
|
||||
)
|
||||
|
||||
const snapshot = yield* service.snapshot()
|
||||
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["execute"])
|
||||
expect(snapshot.codeModeCatalog?.[0]?.signature).toContain("tools.echo")
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("keeps execute available without Code Mode tools unless explicitly denied", () =>
|
||||
Effect.gen(function* () {
|
||||
const service = yield* Tool.Service
|
||||
|
|
|
|||
|
|
@ -143,3 +143,18 @@ test("raw JSON schemas are render-only and omitted output means model-only", asy
|
|||
content: [{ type: "text", text: '{"value":1}' }],
|
||||
})
|
||||
})
|
||||
|
||||
test("missing external input schemas fall back to an empty schema", () => {
|
||||
const tool = {
|
||||
name: "external",
|
||||
description: "External tool",
|
||||
input: undefined,
|
||||
execute: () => Effect.succeed({ content: "unused" }),
|
||||
} as unknown as Info
|
||||
|
||||
expect(definition(tool)).toEqual({
|
||||
name: "external",
|
||||
description: "External tool",
|
||||
inputSchema: {},
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue