Skip to content

Commit ee91f31

Browse files
committed
fix issue with tool schemas and google
1 parent 57b3051 commit ee91f31

File tree

15 files changed

+82
-19
lines changed

15 files changed

+82
-19
lines changed

bun.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
"esbuild",
3838
"protobufjs",
3939
"sharp"
40-
]
40+
],
41+
"patchedDependencies": {
42+
43+
}
4144
}

packages/opencode/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ const cli = yargs(hideBin(process.argv))
9393
if (Installation.VERSION === latest) return
9494
const method = await Installation.method()
9595
if (method === "unknown") return
96-
await Installation.upgrade(method, latest).catch(() => {})
97-
Bus.publish(Installation.Event.Updated, { version: latest })
96+
await Installation.upgrade(method, latest)
97+
.then(() => {
98+
Bus.publish(Installation.Event.Updated, { version: latest })
99+
})
100+
.catch(() => {})
98101
})()
99102

100103
await proc.exited

packages/opencode/src/installation/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,6 @@ export namespace Installation {
117117
export async function latest() {
118118
return fetch("https://api.github.com/repos/sst/opencode/releases/latest")
119119
.then((res) => res.json())
120-
.then((data) => data.tag_name.slice(1))
120+
.then((data) => data.tag_name.slice(1) as string)
121121
}
122122
}

packages/opencode/src/provider/provider.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ModelsDev } from "./models"
2323
import { NamedError } from "../util/error"
2424
import { Auth } from "../auth"
2525
import { TaskTool } from "../tool/task"
26+
import { GlobalConfig } from "../global/config"
2627

2728
export namespace Provider {
2829
const log = Log.create({ service: "provider" })
@@ -257,7 +258,10 @@ export namespace Provider {
257258
}
258259

259260
export async function defaultModel() {
260-
const [provider] = await list().then((val) => Object.values(val))
261+
const cfg = await GlobalConfig.get()
262+
const provider = await list()
263+
.then((val) => Object.values(val))
264+
.then((x) => x.find((p) => !cfg.provider || cfg.provider === p.info.id))
261265
if (!provider) throw new Error("no providers found")
262266
const [model] = sort(Object.values(provider.info.models))
263267
if (!model) throw new Error("no models found")
@@ -285,11 +289,16 @@ export namespace Provider {
285289
TaskTool,
286290
TodoReadTool,
287291
]
292+
288293
const TOOL_MAPPING: Record<string, Tool.Info[]> = {
289294
anthropic: TOOLS.filter((t) => t.id !== "opencode.patch"),
290-
openai: TOOLS,
295+
openai: TOOLS.map((t) => ({
296+
...t,
297+
parameters: optionalToNullable(t.parameters),
298+
})),
291299
google: TOOLS,
292300
}
301+
293302
export async function tools(providerID: string) {
294303
/*
295304
const cfg = await Config.get()
@@ -301,6 +310,38 @@ export namespace Provider {
301310
return TOOL_MAPPING[providerID] ?? TOOLS
302311
}
303312

313+
function optionalToNullable(schema: z.ZodTypeAny): z.ZodTypeAny {
314+
if (schema instanceof z.ZodObject) {
315+
const shape = schema.shape
316+
const newShape: Record<string, z.ZodTypeAny> = {}
317+
318+
for (const [key, value] of Object.entries(shape)) {
319+
const zodValue = value as z.ZodTypeAny
320+
if (zodValue instanceof z.ZodOptional) {
321+
newShape[key] = zodValue.unwrap().nullable()
322+
} else {
323+
newShape[key] = optionalToNullable(zodValue)
324+
}
325+
}
326+
327+
return z.object(newShape)
328+
}
329+
330+
if (schema instanceof z.ZodArray) {
331+
return z.array(optionalToNullable(schema.element))
332+
}
333+
334+
if (schema instanceof z.ZodUnion) {
335+
return z.union(
336+
schema.options.map((option: z.ZodTypeAny) =>
337+
optionalToNullable(option),
338+
) as [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]],
339+
)
340+
}
341+
342+
return schema
343+
}
344+
304345
export const ModelNotFoundError = NamedError.create(
305346
"ProviderModelNotFoundError",
306347
z.object({

packages/opencode/src/session/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ export namespace Session {
497497
msgs.map(toUIMessage).filter((x) => x.parts.length > 0),
498498
),
499499
],
500-
temperature: model.info.id === "codex-mini-latest" ? undefined : 0,
500+
temperature: model.info.temperature ? 0 : undefined,
501501
tools: {
502502
...tools,
503503
},

packages/opencode/src/tool/bash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const BashTool = Tool.define({
3535
.min(0)
3636
.max(MAX_TIMEOUT)
3737
.describe("Optional timeout in milliseconds")
38-
.nullable(),
38+
.optional(),
3939
description: z
4040
.string()
4141
.describe(

packages/opencode/src/tool/edit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const EditTool = Tool.define({
2121
),
2222
replaceAll: z
2323
.boolean()
24-
.nullable()
24+
.optional()
2525
.describe("Replace all occurences of old_string (default false)"),
2626
}),
2727
async execute(params, ctx) {

packages/opencode/src/tool/glob.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const GlobTool = Tool.define({
1111
pattern: z.string().describe("The glob pattern to match files against"),
1212
path: z
1313
.string()
14-
.nullable()
14+
.optional()
1515
.describe(
1616
`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.`,
1717
),

packages/opencode/src/tool/grep.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export const GrepTool = Tool.define({
1414
.describe("The regex pattern to search for in file contents"),
1515
path: z
1616
.string()
17-
.nullable()
17+
.optional()
1818
.describe(
1919
"The directory to search in. Defaults to the current working directory.",
2020
),
2121
include: z
2222
.string()
23-
.nullable()
23+
.optional()
2424
.describe(
2525
'File pattern to include in the search (e.g. "*.js", "*.{ts,tsx}")',
2626
),

0 commit comments

Comments
 (0)