Skip to content

Commit 197a676

Browse files
author
sangyinghao
committed
fix(opencode): preserve custom tool arg descriptions in LLM prompts
Use zodToJsonSchema() instead of z.toJSONSchema() for converting custom tool parameter schemas. The built-in z.toJSONSchema() drops .describe() metadata from dynamically imported Zod schemas, so LLMs never see the argument descriptions users define on their custom tools. Closes anomalyco#4357
1 parent b06afd6 commit 197a676

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎packages/opencode/src/session/prompt.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import path from "path"
22
import os from "os"
33
import fs from "fs/promises"
44
import z from "zod"
5+
import { zodToJsonSchema } from "zod-to-json-schema"
6+
import type { JSONSchema7 } from "@ai-sdk/provider"
57
import { Identifier } from "../id/id"
68
import { MessageV2 } from "./message-v2"
79
import { Log } from "../util/log"
@@ -781,7 +783,7 @@ export namespace SessionPrompt {
781783
{ modelID: input.model.api.id, providerID: input.model.providerID },
782784
input.agent,
783785
)) {
784-
const schema = ProviderTransform.schema(input.model, z.toJSONSchema(item.parameters))
786+
const schema = ProviderTransform.schema(input.model, zodToJsonSchema(item.parameters) as JSONSchema7)
785787
tools[item.id] = tool({
786788
id: item.id as any,
787789
description: item.description,

0 commit comments

Comments
 (0)