Skip to content

Commit 2b76ffa

Browse files
committed
fix opencode client cleanup and prompt schema naming
1 parent 7fc5621 commit 2b76ffa

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

apps/sim/app/api/tools/opencode/prompt/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ import { coerceOpenCodeBoolean } from '@/lib/opencode/utils'
1818

1919
const logger = createLogger('OpenCodePromptToolAPI')
2020

21-
const optionalTrimmedStringSchema = z.preprocess(
21+
const optionalNullableStringSchema = z.preprocess(
2222
(value) => (value === null ? undefined : value),
2323
z.string().optional()
2424
)
2525

2626
const OpenCodePromptSchema = z.object({
2727
repository: z.string().min(1, 'repository is required'),
28-
systemPrompt: optionalTrimmedStringSchema,
28+
systemPrompt: optionalNullableStringSchema,
2929
providerId: z.string().min(1, 'providerId is required'),
3030
modelId: z.string().min(1, 'modelId is required'),
31-
agent: optionalTrimmedStringSchema,
31+
agent: optionalNullableStringSchema,
3232
prompt: z.string().min(1, 'prompt is required'),
3333
newThread: z.union([z.boolean(), z.string()]).optional(),
3434
_context: z

apps/sim/lib/opencode/client.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,22 @@ function getOpenCodeBaseUrl(): string {
3232
}
3333

3434
function getOpenCodeClientKey(): string {
35-
return JSON.stringify({
36-
baseUrl: getOpenCodeBaseUrl(),
37-
authorization: getOpenCodeBasicAuthHeader(),
38-
})
35+
const baseUrl = getOpenCodeBaseUrl()
36+
const authorization = getOpenCodeBasicAuthHeader()
37+
38+
return JSON.stringify({ baseUrl, authorization })
3939
}
4040

4141
export function createOpenCodeClient() {
42-
const clientKey = getOpenCodeClientKey()
42+
const baseUrl = getOpenCodeBaseUrl()
43+
const authorization = getOpenCodeBasicAuthHeader()
44+
const clientKey = JSON.stringify({ baseUrl, authorization })
4345

4446
if (!cachedOpenCodeClient || cachedOpenCodeClientKey !== clientKey) {
4547
cachedOpenCodeClient = createOpencodeClient({
46-
baseUrl: JSON.parse(clientKey).baseUrl,
48+
baseUrl,
4749
headers: {
48-
Authorization: JSON.parse(clientKey).authorization,
50+
Authorization: authorization,
4951
},
5052
})
5153
cachedOpenCodeClientKey = clientKey

0 commit comments

Comments
 (0)