fix: remove 10 more unnecessary as any casts in opencode core#22882
Merged
kitlangton merged 2 commits intodevfrom Apr 16, 2026
Merged
fix: remove 10 more unnecessary as any casts in opencode core#22882kitlangton merged 2 commits intodevfrom
as any casts in opencode core#22882kitlangton merged 2 commits intodevfrom
Conversation
- session/prompt.ts: drop the bogus `id: ... as any` from tool() calls (id is only for type: 'provider' tools); use jsonSchema(schema) and jsonSchema(toolSchema as JSONSchema7) directly
- server/instance/experimental.ts: replace zodToJsonSchema (zod v3) with z.toJSONSchema from the existing zod v4 import; drop the dead zod-detection branch
- config/config.ts: inline { config?: Record<string, unknown> } shape for well-known response
- lsp/server.ts: inline { assets?: {...}[] } shape for GitHub release API; tighten the find callback to remove a stray `a: any` and check browser_download_url before use
- cli/cmd/tui/routes/session/index.tsx: type CodeSearch/WebSearch with their proper tool types; type WebFetch input.url directly; narrow Task's state.title access via status discriminant
The test was asserting `tool.id === "StructuredOutput"` on an internal implementation detail. The AI SDK's user-defined tool type has no `id` field (that field only exists on `type: 'provider'` tools). Tools are registered under their key on the outer `tools` object, not via an inner `id`, so the field was ornamental and unread. The previous `id: ... as any` cast was papering over this \u2014 dropping both the cast and the assertion aligns the test with the AI SDK's actual contract.
xywsxp
pushed a commit
to xywsxp/opencode
that referenced
this pull request
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #22877. Removes 10 more
as anycasts frompackages/opencode/src/.Changes
session/prompt.ts— theid: ... as anyinsidetool({...})was bogus. Theidfield on the AI SDKTooltype only exists fortype: 'provider'tools (with a${string}.${string}template literal format); for user-defined tools you register them under anidkey on the outertoolsobject, not inside the tool itself. Dropping those fields removes 2 casts. TheinputSchema: jsonSchema(... as any)casts were unnecessary: theProviderTransform.schema(...)call already returnsJSONSchema7(removing 1 cast), and the other site now importsJSONSchema7from@ai-sdk/providerinstead of widening toany.server/instance/experimental.ts— replacezodToJsonSchema(fromzod-to-json-schema, which expects the zod v3ZodSchema<any>) withz.toJSONSchemafrom the existing zod v4 import. This kills the(t.parameters as any)?._def ? zodToJsonSchema(t.parameters as any) : t.parametersdead fallback — everyTool.Def.parametersis az.ZodTypeby construction, so the "is this a Zod schema?" branch was unreachable.config/config.ts— inline{ config?: Record<string, unknown> }for the.well-known/opencodeJSON response.lsp/server.ts— inline{ assets?: { name?: string; browser_download_url?: string }[] }for the GitHub releases response (matching the existing shape used further down in the same file at line 1580). Tightens therelease.assets.find((a: any) => ...)callback to drop its owna: anyand adds abrowser_download_urlpresence check before use.cli/cmd/tui/routes/session/index.tsx:WebFetch— remove 2 casts by accessingprops.input.urldirectly (ToolProps<typeof WebFetchTool>already gives us the shape).CodeSearch/WebSearch— changeToolProps<any>toToolProps<typeof CodeSearchTool>/ToolProps<typeof WebSearchTool>soprops.input.queryis typed. Themetadatacasts are retained but narrowed fromanyto{ results?: number }/{ numResults?: number }(true type would require touching the tool metadata schemas — deferred).Task— narrowx.state.titleaccess via thestatus === "running" || status === "completed"discriminant (Pending/Error states don't havetitle).Remaining
~15
as anycasts still inpackages/opencode/src/, all at genuine type boundaries or dynamic dispatch sites:plugin/plugin.ts(3) — dynamic hook dispatch (internal bus payload ↔ SDK Event, plugin config type mismatch)lsp/client.ts(2) — Node child process stream ↔ vscode-languageserver-protocol streamutil/filesystem.ts(1) — DOM ↔ NodeReadableStreambridgeutil/effect-zod.ts(1) — symbol key on interface with only string index signatureprovider/provider.ts(1) — internalAuth.Info↔ plugin SDKAuthtool/registry.ts(1) — plugin args boundary (runtime-validated unknown ↔ user-defined Zod shape)cli/cmd/tui/routes/session/index.tsx(1) — SolidJS<Dynamic>component/props inferenceVerification
bun turbo typecheckpasses (all 13 tasks).bun run lintpasses (oxlint warnings only, no errors).bun test test/session/structured-output-integration.test.tspasses (checks thecreateStructuredOutputToolpath).