Skip to content

Commit 35fac8d

Browse files
committed
fix(opencode): clean up low severity review notes
1 parent 1e174f7 commit 35fac8d

File tree

6 files changed

+33
-30
lines changed

6 files changed

+33
-30
lines changed

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
shouldRetryWithFreshOpenCodeSession,
1515
storeOpenCodeSession,
1616
} from '@/lib/opencode/service'
17+
import { coerceOpenCodeBoolean } from '@/lib/opencode/utils'
1718

1819
const logger = createLogger('OpenCodePromptToolAPI')
1920

@@ -44,18 +45,6 @@ const OpenCodePromptSchema = z.object({
4445
export const dynamic = 'force-dynamic'
4546
export const runtime = 'nodejs'
4647

47-
function coerceBoolean(value: boolean | string | undefined): boolean {
48-
if (typeof value === 'boolean') {
49-
return value
50-
}
51-
52-
if (typeof value === 'string') {
53-
return value.toLowerCase() === 'true'
54-
}
55-
56-
return false
57-
}
58-
5948
function getSessionOwnerKey(params: z.infer<typeof OpenCodePromptSchema>): string {
6049
if (params._context?.userId) {
6150
return `user:${params._context.userId}`
@@ -145,7 +134,7 @@ export async function POST(request: NextRequest) {
145134
const modelId = body.modelId.trim()
146135
const sessionOwnerKey = getSessionOwnerKey(body)
147136
const memoryKey = buildOpenCodeSessionMemoryKey(workflowId, sessionOwnerKey)
148-
const newThread = coerceBoolean(body.newThread)
137+
const newThread = coerceOpenCodeBoolean(body.newThread)
149138
const storedThread = newThread ? null : await getStoredOpenCodeSession(workspaceId, memoryKey)
150139
let threadId =
151140
storedThread && storedThread.repository === repositoryId

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/combobox/combobox.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export const ComboBox = memo(function ComboBox({
136136
!fetchOptions ||
137137
isPreview ||
138138
disabled ||
139-
isLoadingOptions ||
140139
(!force && hasAttemptedOptionsFetch) ||
141140
isOptionsFetchInFlightRef.current
142141
) {
@@ -164,7 +163,6 @@ export const ComboBox = memo(function ComboBox({
164163
subBlockId,
165164
isPreview,
166165
disabled,
167-
isLoadingOptions,
168166
hasAttemptedOptionsFetch,
169167
])
170168

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/dropdown/dropdown.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ export const Dropdown = memo(function Dropdown({
161161
!fetchOptions ||
162162
isPreview ||
163163
disabled ||
164-
isLoadingOptions ||
165164
(!force && hasAttemptedOptionsFetch) ||
166165
isOptionsFetchInFlightRef.current
167166
) {
@@ -189,7 +188,6 @@ export const Dropdown = memo(function Dropdown({
189188
subBlockId,
190189
isPreview,
191190
disabled,
192-
isLoadingOptions,
193191
hasAttemptedOptionsFetch,
194192
])
195193

apps/sim/blocks/blocks/opencode.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
import type { BlockConfig } from '@/blocks/types'
22
import { OpenCodeIcon } from '@/components/icons'
33
import { getEnv, isTruthy } from '@/lib/core/config/env'
4+
import { coerceOpenCodeBoolean } from '@/lib/opencode/utils'
45
import type { OpenCodePromptResponse } from '@/tools/opencode/types'
56

67
const isOpenCodeEnabled = isTruthy(getEnv('NEXT_PUBLIC_OPENCODE_ENABLED'))
78

8-
function coerceBoolean(value: unknown): boolean {
9-
if (typeof value === 'boolean') {
10-
return value
11-
}
12-
13-
if (typeof value === 'string') {
14-
return value.toLowerCase() === 'true'
15-
}
16-
17-
return false
18-
}
19-
209
function getOptionalString(value: unknown): string | undefined {
2110
if (typeof value !== 'string') {
2211
return undefined
@@ -230,7 +219,7 @@ export const OpenCodeBlock: BlockConfig<OpenCodePromptResponse> = {
230219
modelId: params.modelId,
231220
...(getOptionalString(params.agent) ? { agent: getOptionalString(params.agent) } : {}),
232221
prompt: params.prompt,
233-
newThread: coerceBoolean(params.newThread),
222+
newThread: coerceOpenCodeBoolean(params.newThread),
234223
}),
235224
},
236225
},
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
5+
import { describe, expect, it } from 'vitest'
6+
import { coerceOpenCodeBoolean } from '@/lib/opencode/utils'
7+
8+
describe('coerceOpenCodeBoolean', () => {
9+
it('coerces booleans and string booleans consistently', () => {
10+
expect(coerceOpenCodeBoolean(true)).toBe(true)
11+
expect(coerceOpenCodeBoolean(false)).toBe(false)
12+
expect(coerceOpenCodeBoolean('true')).toBe(true)
13+
expect(coerceOpenCodeBoolean('TRUE')).toBe(true)
14+
expect(coerceOpenCodeBoolean('false')).toBe(false)
15+
expect(coerceOpenCodeBoolean(undefined)).toBe(false)
16+
expect(coerceOpenCodeBoolean(null)).toBe(false)
17+
})
18+
})

apps/sim/lib/opencode/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function coerceOpenCodeBoolean(value: unknown): boolean {
2+
if (typeof value === 'boolean') {
3+
return value
4+
}
5+
6+
if (typeof value === 'string') {
7+
return value.toLowerCase() === 'true'
8+
}
9+
10+
return false
11+
}

0 commit comments

Comments
 (0)