Skip to content

Commit 2d2f587

Browse files
authored
fix(opencode): avoid nullable webfetch format schema (#30215)
1 parent bba7600 commit 2d2f587

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

packages/opencode/src/tool/webfetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const Parameters = Schema.Struct({
1717
description: "The format to return the content in (text, markdown, or html). Defaults to markdown.",
1818
default: "markdown",
1919
})
20-
.pipe(Schema.optional, Schema.withDecodingDefault(Effect.succeed("markdown" as const))),
20+
.pipe(Schema.withDecodingDefault(Effect.succeed("markdown" as const))),
2121
timeout: Schema.optional(Schema.Number).annotate({ description: "Optional timeout in seconds (max 120)" }),
2222
})
2323

packages/opencode/test/tool/__snapshots__/parameters.test.ts.snap

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -396,21 +396,14 @@ exports[`tool parameters JSON Schema (wire shape) webfetch 1`] = `
396396
"$schema": "https://json-schema.org/draft/2020-12/schema",
397397
"properties": {
398398
"format": {
399-
"anyOf": [
400-
{
401-
"default": "markdown",
402-
"description": "The format to return the content in (text, markdown, or html). Defaults to markdown.",
403-
"enum": [
404-
"text",
405-
"markdown",
406-
"html",
407-
],
408-
"type": "string",
409-
},
410-
{
411-
"type": "null",
412-
},
399+
"default": "markdown",
400+
"description": "The format to return the content in (text, markdown, or html). Defaults to markdown.",
401+
"enum": [
402+
"text",
403+
"markdown",
404+
"html",
413405
],
406+
"type": "string",
414407
},
415408
"timeout": {
416409
"description": "Optional timeout in seconds (max 120)",

packages/opencode/test/tool/parameters.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ describe("tool parameters", () => {
8282
properties: { value: { minimum: Number.MIN_SAFE_INTEGER, maximum: Number.MAX_SAFE_INTEGER } },
8383
})
8484
})
85+
86+
test("does not expose defaulted optional keys as nullable", () => {
87+
expect(toJsonSchema(WebFetch)).toMatchObject({
88+
properties: { format: { type: "string", enum: ["text", "markdown", "html"], default: "markdown" } },
89+
})
90+
expect(toJsonSchema(WebFetch).properties?.format).not.toHaveProperty("anyOf")
91+
})
8592
})
8693

8794
describe("apply_patch", () => {
@@ -257,8 +264,15 @@ describe("tool parameters", () => {
257264
})
258265

259266
describe("webfetch", () => {
260-
test("accepts url-only", () => {
261-
expect(parse(WebFetch, { url: "https://example.com" }).url).toBe("https://example.com")
267+
test("defaults omitted format to markdown", () => {
268+
expect(parse(WebFetch, { url: "https://example.com" })).toEqual({
269+
url: "https://example.com",
270+
format: "markdown",
271+
})
272+
expect(parse(WebFetch, { url: "https://example.com", format: undefined })).toEqual({
273+
url: "https://example.com",
274+
format: "markdown",
275+
})
262276
})
263277
})
264278

0 commit comments

Comments
 (0)