The open source coding agent.
TypeScript
fix issue with tool schemas and google
Dax Raadee91f3131365
diff --git a/bun.lock b/bun.lockindex 165211228c8..e6da18ca7a2 100644--- a/bun.lock+++ b/bun.lock@@ -86,6 +86,9 @@"sharp","esbuild",],+ "patchedDependencies": {+ "[email protected]": "patches/[email protected]",+ },"overrides": {"zod": "3.24.2",},diff --git a/package.json b/package.jsonindex f454d7d9fee..d3968d5d478 100644--- a/package.json+++ b/package.json@@ -37,5 +37,8 @@"esbuild","protobufjs","sharp"- ]+ ],+ "patchedDependencies": {+ "[email protected]": "patches/[email protected]"+ }}diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.tsindex 287d6270ee8..8bb0055a9ac 100644--- a/packages/opencode/src/index.ts+++ b/packages/opencode/src/index.ts@@ -93,8 +93,11 @@ const cli = yargs(hideBin(process.argv))if (Installation.VERSION === latest) returnconst method = await Installation.method()if (method === "unknown") return- await Installation.upgrade(method, latest).catch(() => {})- Bus.publish(Installation.Event.Updated, { version: latest })+ await Installation.upgrade(method, latest)+ .then(() => {+ Bus.publish(Installation.Event.Updated, { version: latest })+ })+ .catch(() => {})})()await proc.exiteddiff --git a/packages/opencode/src/installation/index.ts b/packages/opencode/src/installation/index.tsindex 54d50cc375e..e7528bcdf81 100644--- a/packages/opencode/src/installation/index.ts+++ b/packages/opencode/src/installation/index.ts@@ -117,6 +117,6 @@ export namespace Installation {export async function latest() {return fetch("https://api.github.com/repos/sst/opencode/releases/latest").then((res) => res.json())- .then((data) => data.tag_name.slice(1))+ .then((data) => data.tag_name.slice(1) as string)}}diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.tsindex 9a08c4e3f05..84d5e31de8b 100644--- a/packages/opencode/src/provider/provider.ts+++ b/packages/opencode/src/provider/provider.ts@@ -23,6 +23,7 @@ import { ModelsDev } from "./models"import { NamedError } from "../util/error"import { Auth } from "../auth"import { TaskTool } from "../tool/task"+import { GlobalConfig } from "../global/config"export namespace Provider {const log = Log.create({ service: "provider" })@@ -257,7 +258,10 @@ export namespace Provider {}export async function defaultModel() {- const [provider] = await list().then((val) => Object.values(val))+ const cfg = await GlobalConfig.get()+ const provider = await list()+ .then((val) => Object.values(val))+ .then((x) => x.find((p) => !cfg.provider || cfg.provider === p.info.id))if (!provider) throw new Error("no providers found")const [model] = sort(Object.values(provider.info.models))if (!model) throw new Error("no models found")@@ -285,11 +289,16 @@ export namespace Provider {TaskTool,TodoReadTool,]+const TOOL_MAPPING: Record<string, Tool.Info[]> = {anthropic: TOOLS.filter((t) => t.id !== "opencode.patch"),- openai: TOOLS,+ openai: TOOLS.map((t) => ({+ ...t,+ parameters: optionalToNullable(t.parameters),+ })),google: TOOLS,}+export async function tools(providerID: string) {/*const cfg = await Config.get()@@ -301,6 +310,38 @@ export namespace Provider {return TOOL_MAPPING[providerID] ?? TOOLS}+ function optionalToNullable(schema: z.ZodTypeAny): z.ZodTypeAny {+ if (schema instanceof z.ZodObject) {+ const shape = schema.shape+ const newShape: Record<string, z.ZodTypeAny> = {}++ for (const [key, value] of Object.entries(shape)) {+ const zodValue = value as z.ZodTypeAny+ if (zodValue instanceof z.ZodOptional) {+ newShape[key] = zodValue.unwrap().nullable()+ } else {+ newShape[key] = optionalToNullable(zodValue)+ }+ }++ return z.object(newShape)+ }++ if (schema instanceof z.ZodArray) {+ return z.array(optionalToNullable(schema.element))+ }++ if (schema instanceof z.ZodUnion) {+ return z.union(+ schema.options.map((option: z.ZodTypeAny) =>+ optionalToNullable(option),+ ) as [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]],+ )+ }++ return schema+ }+export const ModelNotFoundError = NamedError.create("ProviderModelNotFoundError",z.object({diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.tsindex 0dd4e4e626c..fe21b26cd70 100644--- a/packages/opencode/src/session/index.ts+++ b/packages/opencode/src/session/index.ts@@ -497,7 +497,7 @@ export namespace Session {msgs.map(toUIMessage).filter((x) => x.parts.length > 0),),],- temperature: model.info.id === "codex-mini-latest" ? undefined : 0,+ temperature: model.info.temperature ? 0 : undefined,tools: {...tools,},diff --git a/packages/opencode/src/tool/bash.ts b/packages/opencode/src/tool/bash.tsindex e2502fa1327..7bf1c595b3a 100644--- a/packages/opencode/src/tool/bash.ts+++ b/packages/opencode/src/tool/bash.ts@@ -35,7 +35,7 @@ export const BashTool = Tool.define({.min(0).max(MAX_TIMEOUT).describe("Optional timeout in milliseconds")- .nullable(),+ .optional(),description: z.string().describe(diff --git a/packages/opencode/src/tool/edit.ts b/packages/opencode/src/tool/edit.tsindex 78e29e28f5e..26db51fae50 100644--- a/packages/opencode/src/tool/edit.ts+++ b/packages/opencode/src/tool/edit.ts@@ -21,7 +21,7 @@ export const EditTool = Tool.define({),replaceAll: z.boolean()- .nullable()+ .optional().describe("Replace all occurences of old_string (default false)"),}),async execute(params, ctx) {diff --git a/packages/opencode/src/tool/glob.ts b/packages/opencode/src/tool/glob.tsindex 92a01f5e366..aab5603ec31 100644--- a/packages/opencode/src/tool/glob.ts+++ b/packages/opencode/src/tool/glob.ts@@ -11,7 +11,7 @@ export const GlobTool = Tool.define({pattern: z.string().describe("The glob pattern to match files against"),path: z.string()- .nullable()+ .optional().describe(`The directory to search in. If not specified, the current working directory will be used. IMPORTANT: Omit this field to use the default directory. DO NOT enter "undefined" or "null" - simply omit it for the default behavior. Must be a valid directory path if provided.`,),diff --git a/packages/opencode/src/tool/grep.ts b/packages/opencode/src/tool/grep.tsindex 20199a5c6cd..02979b14992 100644--- a/packages/opencode/src/tool/grep.ts+++ b/packages/opencode/src/tool/grep.ts@@ -14,13 +14,13 @@ export const GrepTool = Tool.define({.describe("The regex pattern to search for in file contents"),path: z.string()- .nullable()+ .optional().describe("The directory to search in. Defaults to the current working directory.",),include: z.string()- .nullable()+ .optional().describe('File pattern to include in the search (e.g. "*.js", "*.{ts,tsx}")',),diff --git a/packages/opencode/src/tool/ls.ts b/packages/opencode/src/tool/ls.tsindex 42b78d42507..0a0c4155e95 100644--- a/packages/opencode/src/tool/ls.ts+++ b/packages/opencode/src/tool/ls.ts@@ -29,11 +29,11 @@ export const ListTool = Tool.define({.describe("The absolute path to the directory to list (must be absolute, not relative)",)- .nullable(),+ .optional(),ignore: z.array(z.string()).describe("List of glob patterns to ignore")- .nullable(),+ .optional(),}),async execute(params) {const app = App.info()diff --git a/packages/opencode/src/tool/read.ts b/packages/opencode/src/tool/read.tsindex 38091b7ac41..69d2a0368d8 100644--- a/packages/opencode/src/tool/read.ts+++ b/packages/opencode/src/tool/read.ts@@ -19,11 +19,11 @@ export const ReadTool = Tool.define({offset: z.number().describe("The line number to start reading from (0-based)")- .nullable(),+ .optional(),limit: z.number().describe("The number of lines to read (defaults to 2000)")- .nullable(),+ .optional(),}),async execute(params, ctx) {let filePath = params.filePathdiff --git a/packages/opencode/src/tool/webfetch.ts b/packages/opencode/src/tool/webfetch.tsindex 0c7f2e622ec..77b673a37b3 100644--- a/packages/opencode/src/tool/webfetch.ts+++ b/packages/opencode/src/tool/webfetch.ts@@ -22,7 +22,7 @@ export const WebFetchTool = Tool.define({.min(0).max(MAX_TIMEOUT / 1000).describe("Optional timeout in seconds (max 120)")- .nullable(),+ .optional(),}),async execute(params, ctx) {// Validate URLdiff --git a/packages/opencode/test/tool/tool.test.ts b/packages/opencode/test/tool/tool.test.tsindex 273e725c2a0..2d41405d483 100644--- a/packages/opencode/test/tool/tool.test.ts+++ b/packages/opencode/test/tool/tool.test.ts@@ -9,7 +9,7 @@ describe("tool.glob", () => {let result = await GlobTool.execute({pattern: "./node_modules/**/*",- path: null,+ path: undefined,},{sessionID: "test",@@ -25,7 +25,7 @@ describe("tool.glob", () => {let result = await GlobTool.execute({pattern: "*.json",- path: null,+ path: undefined,},{sessionID: "test",diff --git a/patches/[email protected] b/patches/[email protected]new file mode 100644index 00000000000..7d6df589d7b--- /dev/null+++ b/patches/[email protected]@@ -0,0 +1,13 @@+diff --git a/dist/index.mjs b/dist/index.mjs+index 92a80377692488c4ba8801ce33e7736ad7055e43..add6281bbecaa1c03d3b48eb99aead4a7a7336b2 100644+--- a/dist/index.mjs++++ b/dist/index.mjs+@@ -1593,7 +1593,7 @@ function prepareCallSettings({+ return {+ maxTokens,+ // TODO v5 remove default 0 for temperature+- temperature: temperature != null ? temperature : 0,++ temperature: temperature,+ topP,+ topK,+ presencePenalty,