Skip to content

Commit 1c33b86

Browse files
authored
fix: remove 10 more unnecessary as any casts in opencode core (#22882)
1 parent 5e650fd commit 1c33b86

6 files changed

Lines changed: 30 additions & 36 deletions

File tree

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import type { GrepTool } from "@/tool/grep"
4444
import type { EditTool } from "@/tool/edit"
4545
import type { ApplyPatchTool } from "@/tool/apply_patch"
4646
import type { WebFetchTool } from "@/tool/webfetch"
47+
import type { CodeSearchTool } from "@/tool/codesearch"
48+
import type { WebSearchTool } from "@/tool/websearch"
4749
import type { TaskTool } from "@/tool/task"
4850
import type { QuestionTool } from "@/tool/question"
4951
import type { SkillTool } from "@/tool/skill"
@@ -1934,28 +1936,26 @@ function Grep(props: ToolProps<typeof GrepTool>) {
19341936

19351937
function WebFetch(props: ToolProps<typeof WebFetchTool>) {
19361938
return (
1937-
<InlineTool icon="%" pending="Fetching from the web..." complete={(props.input as any).url} part={props.part}>
1938-
WebFetch {(props.input as any).url}
1939+
<InlineTool icon="%" pending="Fetching from the web..." complete={props.input.url} part={props.part}>
1940+
WebFetch {props.input.url}
19391941
</InlineTool>
19401942
)
19411943
}
19421944

1943-
function CodeSearch(props: ToolProps<any>) {
1944-
const input = props.input as any
1945-
const metadata = props.metadata as any
1945+
function CodeSearch(props: ToolProps<typeof CodeSearchTool>) {
1946+
const metadata = props.metadata as { results?: number }
19461947
return (
1947-
<InlineTool icon="◇" pending="Searching code..." complete={input.query} part={props.part}>
1948-
Exa Code Search "{input.query}" <Show when={metadata.results}>({metadata.results} results)</Show>
1948+
<InlineTool icon="◇" pending="Searching code..." complete={props.input.query} part={props.part}>
1949+
Exa Code Search "{props.input.query}" <Show when={metadata.results}>({metadata.results} results)</Show>
19491950
</InlineTool>
19501951
)
19511952
}
19521953

1953-
function WebSearch(props: ToolProps<any>) {
1954-
const input = props.input as any
1955-
const metadata = props.metadata as any
1954+
function WebSearch(props: ToolProps<typeof WebSearchTool>) {
1955+
const metadata = props.metadata as { numResults?: number }
19561956
return (
1957-
<InlineTool icon="◈" pending="Searching web..." complete={input.query} part={props.part}>
1958-
Exa Web Search "{input.query}" <Show when={metadata.numResults}>({metadata.numResults} results)</Show>
1957+
<InlineTool icon="◈" pending="Searching web..." complete={props.input.query} part={props.part}>
1958+
Exa Web Search "{props.input.query}" <Show when={metadata.numResults}>({metadata.numResults} results)</Show>
19591959
</InlineTool>
19601960
)
19611961
}
@@ -1979,7 +1979,9 @@ function Task(props: ToolProps<typeof TaskTool>) {
19791979
)
19801980
})
19811981

1982-
const current = createMemo(() => tools().findLast((x) => (x.state as any).title))
1982+
const current = createMemo(() =>
1983+
tools().findLast((x) => (x.state.status === "running" || x.state.status === "completed") && x.state.title),
1984+
)
19831985

19841986
const isRunning = createMemo(() => props.part.state.status === "running")
19851987

@@ -1996,8 +1998,11 @@ function Task(props: ToolProps<typeof TaskTool>) {
19961998

19971999
if (isRunning() && tools().length > 0) {
19982000
// content[0] += ` · ${tools().length} toolcalls`
1999-
if (current()) content.push(`↳ ${Locale.titlecase(current()!.tool)} ${(current()!.state as any).title}`)
2000-
else content.push(`↳ ${tools().length} toolcalls`)
2001+
if (current()) {
2002+
const state = current()!.state
2003+
const title = state.status === "running" || state.status === "completed" ? state.title : undefined
2004+
content.push(`↳ ${Locale.titlecase(current()!.tool)} ${title}`)
2005+
} else content.push(`↳ ${tools().length} toolcalls`)
20012006
}
20022007

20032008
if (props.part.state.status === "completed") {

packages/opencode/src/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ export const layer = Layer.effect(
517517
if (!response.ok) {
518518
throw new Error(`failed to fetch remote config from ${url}: ${response.status}`)
519519
}
520-
const wellknown = (yield* Effect.promise(() => response.json())) as any
520+
const wellknown = (yield* Effect.promise(() => response.json())) as { config?: Record<string, unknown> }
521521
const remoteConfig = wellknown.config ?? {}
522522
if (!remoteConfig.$schema) remoteConfig.$schema = "https://opencode.ai/config.json"
523523
const source = `${url}/.well-known/opencode`

packages/opencode/src/lsp/server.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,9 @@ export const Zls: Info = {
611611
return
612612
}
613613

614-
const release = (await releaseResponse.json()) as any
614+
const release = (await releaseResponse.json()) as {
615+
assets?: { name?: string; browser_download_url?: string }[]
616+
}
615617

616618
const platform = process.platform
617619
const arch = process.arch
@@ -646,8 +648,8 @@ export const Zls: Info = {
646648
return
647649
}
648650

649-
const asset = release.assets.find((a: any) => a.name === assetName)
650-
if (!asset) {
651+
const asset = release.assets?.find((a) => a.name === assetName)
652+
if (!asset?.browser_download_url) {
651653
log.error(`Could not find asset ${assetName} in latest zls release`)
652654
return
653655
}

packages/opencode/src/server/instance/experimental.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { Config } from "../../config"
1212
import { ConsoleState } from "../../config/console-state"
1313
import { Account, AccountID, OrgID } from "../../account"
1414
import { AppRuntime } from "../../effect/app-runtime"
15-
import { zodToJsonSchema } from "zod-to-json-schema"
1615
import { errors } from "../error"
1716
import { lazy } from "../../util/lazy"
1817
import { Effect, Option } from "effect"
@@ -226,8 +225,7 @@ export const ExperimentalRoutes = lazy(() =>
226225
tools.map((t) => ({
227226
id: t.id,
228227
description: t.description,
229-
// Handle both Zod schemas and plain JSON schemas
230-
parameters: (t.parameters as any)?._def ? zodToJsonSchema(t.parameters as any) : t.parameters,
228+
parameters: z.toJSONSchema(t.parameters),
231229
})),
232230
)
233231
},

packages/opencode/src/session/prompt.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Agent } from "../agent/agent"
1010
import { Provider } from "../provider"
1111
import { ModelID, ProviderID } from "../provider/schema"
1212
import { type Tool as AITool, tool, jsonSchema, type ToolExecutionOptions, asSchema } from "ai"
13+
import type { JSONSchema7 } from "@ai-sdk/provider"
1314
import { SessionCompaction } from "./compaction"
1415
import { Bus } from "../bus"
1516
import { ProviderTransform } from "../provider"
@@ -407,9 +408,8 @@ NOTE: At any point in time through this workflow you should feel free to ask the
407408
})) {
408409
const schema = ProviderTransform.schema(input.model, z.toJSONSchema(item.parameters))
409410
tools[item.id] = tool({
410-
id: item.id as any,
411411
description: item.description,
412-
inputSchema: jsonSchema(schema as any),
412+
inputSchema: jsonSchema(schema),
413413
execute(args, options) {
414414
return run.promise(
415415
Effect.gen(function* () {
@@ -1827,9 +1827,8 @@ NOTE: At any point in time through this workflow you should feel free to ask the
18271827
const { $schema: _, ...toolSchema } = input.schema
18281828

18291829
return tool({
1830-
id: "StructuredOutput" as any,
18311830
description: STRUCTURED_OUTPUT_DESCRIPTION,
1832-
inputSchema: jsonSchema(toolSchema as any),
1831+
inputSchema: jsonSchema(toolSchema as JSONSchema7),
18331832
async execute(args) {
18341833
// AI SDK validates args against inputSchema before calling execute()
18351834
input.onSuccess(args)

packages/opencode/test/session/structured-output.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,6 @@ describe("structured-output.AssistantMessage", () => {
157157
})
158158

159159
describe("structured-output.createStructuredOutputTool", () => {
160-
test("creates tool with correct id", () => {
161-
const tool = SessionPrompt.createStructuredOutputTool({
162-
schema: { type: "object", properties: { name: { type: "string" } } },
163-
onSuccess: () => {},
164-
})
165-
166-
// AI SDK tool type doesn't expose id, but we set it internally
167-
expect((tool as any).id).toBe("StructuredOutput")
168-
})
169-
170160
test("creates tool with description", () => {
171161
const tool = SessionPrompt.createStructuredOutputTool({
172162
schema: { type: "object" },

0 commit comments

Comments
 (0)