fix: remove 10 more unnecessary as any casts in opencode core (#22882)
This commit is contained in:
@@ -44,6 +44,8 @@ import type { GrepTool } from "@/tool/grep"
|
|||||||
import type { EditTool } from "@/tool/edit"
|
import type { EditTool } from "@/tool/edit"
|
||||||
import type { ApplyPatchTool } from "@/tool/apply_patch"
|
import type { ApplyPatchTool } from "@/tool/apply_patch"
|
||||||
import type { WebFetchTool } from "@/tool/webfetch"
|
import type { WebFetchTool } from "@/tool/webfetch"
|
||||||
|
import type { CodeSearchTool } from "@/tool/codesearch"
|
||||||
|
import type { WebSearchTool } from "@/tool/websearch"
|
||||||
import type { TaskTool } from "@/tool/task"
|
import type { TaskTool } from "@/tool/task"
|
||||||
import type { QuestionTool } from "@/tool/question"
|
import type { QuestionTool } from "@/tool/question"
|
||||||
import type { SkillTool } from "@/tool/skill"
|
import type { SkillTool } from "@/tool/skill"
|
||||||
@@ -1934,28 +1936,26 @@ function Grep(props: ToolProps<typeof GrepTool>) {
|
|||||||
|
|
||||||
function WebFetch(props: ToolProps<typeof WebFetchTool>) {
|
function WebFetch(props: ToolProps<typeof WebFetchTool>) {
|
||||||
return (
|
return (
|
||||||
<InlineTool icon="%" pending="Fetching from the web..." complete={(props.input as any).url} part={props.part}>
|
<InlineTool icon="%" pending="Fetching from the web..." complete={props.input.url} part={props.part}>
|
||||||
WebFetch {(props.input as any).url}
|
WebFetch {props.input.url}
|
||||||
</InlineTool>
|
</InlineTool>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function CodeSearch(props: ToolProps<any>) {
|
function CodeSearch(props: ToolProps<typeof CodeSearchTool>) {
|
||||||
const input = props.input as any
|
const metadata = props.metadata as { results?: number }
|
||||||
const metadata = props.metadata as any
|
|
||||||
return (
|
return (
|
||||||
<InlineTool icon="◇" pending="Searching code..." complete={input.query} part={props.part}>
|
<InlineTool icon="◇" pending="Searching code..." complete={props.input.query} part={props.part}>
|
||||||
Exa Code Search "{input.query}" <Show when={metadata.results}>({metadata.results} results)</Show>
|
Exa Code Search "{props.input.query}" <Show when={metadata.results}>({metadata.results} results)</Show>
|
||||||
</InlineTool>
|
</InlineTool>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function WebSearch(props: ToolProps<any>) {
|
function WebSearch(props: ToolProps<typeof WebSearchTool>) {
|
||||||
const input = props.input as any
|
const metadata = props.metadata as { numResults?: number }
|
||||||
const metadata = props.metadata as any
|
|
||||||
return (
|
return (
|
||||||
<InlineTool icon="◈" pending="Searching web..." complete={input.query} part={props.part}>
|
<InlineTool icon="◈" pending="Searching web..." complete={props.input.query} part={props.part}>
|
||||||
Exa Web Search "{input.query}" <Show when={metadata.numResults}>({metadata.numResults} results)</Show>
|
Exa Web Search "{props.input.query}" <Show when={metadata.numResults}>({metadata.numResults} results)</Show>
|
||||||
</InlineTool>
|
</InlineTool>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1979,7 +1979,9 @@ function Task(props: ToolProps<typeof TaskTool>) {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const current = createMemo(() => tools().findLast((x) => (x.state as any).title))
|
const current = createMemo(() =>
|
||||||
|
tools().findLast((x) => (x.state.status === "running" || x.state.status === "completed") && x.state.title),
|
||||||
|
)
|
||||||
|
|
||||||
const isRunning = createMemo(() => props.part.state.status === "running")
|
const isRunning = createMemo(() => props.part.state.status === "running")
|
||||||
|
|
||||||
@@ -1996,8 +1998,11 @@ function Task(props: ToolProps<typeof TaskTool>) {
|
|||||||
|
|
||||||
if (isRunning() && tools().length > 0) {
|
if (isRunning() && tools().length > 0) {
|
||||||
// content[0] += ` · ${tools().length} toolcalls`
|
// content[0] += ` · ${tools().length} toolcalls`
|
||||||
if (current()) content.push(`↳ ${Locale.titlecase(current()!.tool)} ${(current()!.state as any).title}`)
|
if (current()) {
|
||||||
else content.push(`↳ ${tools().length} toolcalls`)
|
const state = current()!.state
|
||||||
|
const title = state.status === "running" || state.status === "completed" ? state.title : undefined
|
||||||
|
content.push(`↳ ${Locale.titlecase(current()!.tool)} ${title}`)
|
||||||
|
} else content.push(`↳ ${tools().length} toolcalls`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.part.state.status === "completed") {
|
if (props.part.state.status === "completed") {
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ export const layer = Layer.effect(
|
|||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`failed to fetch remote config from ${url}: ${response.status}`)
|
throw new Error(`failed to fetch remote config from ${url}: ${response.status}`)
|
||||||
}
|
}
|
||||||
const wellknown = (yield* Effect.promise(() => response.json())) as any
|
const wellknown = (yield* Effect.promise(() => response.json())) as { config?: Record<string, unknown> }
|
||||||
const remoteConfig = wellknown.config ?? {}
|
const remoteConfig = wellknown.config ?? {}
|
||||||
if (!remoteConfig.$schema) remoteConfig.$schema = "https://opencode.ai/config.json"
|
if (!remoteConfig.$schema) remoteConfig.$schema = "https://opencode.ai/config.json"
|
||||||
const source = `${url}/.well-known/opencode`
|
const source = `${url}/.well-known/opencode`
|
||||||
|
|||||||
@@ -611,7 +611,9 @@ export const Zls: Info = {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const release = (await releaseResponse.json()) as any
|
const release = (await releaseResponse.json()) as {
|
||||||
|
assets?: { name?: string; browser_download_url?: string }[]
|
||||||
|
}
|
||||||
|
|
||||||
const platform = process.platform
|
const platform = process.platform
|
||||||
const arch = process.arch
|
const arch = process.arch
|
||||||
@@ -646,8 +648,8 @@ export const Zls: Info = {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const asset = release.assets.find((a: any) => a.name === assetName)
|
const asset = release.assets?.find((a) => a.name === assetName)
|
||||||
if (!asset) {
|
if (!asset?.browser_download_url) {
|
||||||
log.error(`Could not find asset ${assetName} in latest zls release`)
|
log.error(`Could not find asset ${assetName} in latest zls release`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import { Config } from "../../config"
|
|||||||
import { ConsoleState } from "../../config/console-state"
|
import { ConsoleState } from "../../config/console-state"
|
||||||
import { Account, AccountID, OrgID } from "../../account"
|
import { Account, AccountID, OrgID } from "../../account"
|
||||||
import { AppRuntime } from "../../effect/app-runtime"
|
import { AppRuntime } from "../../effect/app-runtime"
|
||||||
import { zodToJsonSchema } from "zod-to-json-schema"
|
|
||||||
import { errors } from "../error"
|
import { errors } from "../error"
|
||||||
import { lazy } from "../../util/lazy"
|
import { lazy } from "../../util/lazy"
|
||||||
import { Effect, Option } from "effect"
|
import { Effect, Option } from "effect"
|
||||||
@@ -226,8 +225,7 @@ export const ExperimentalRoutes = lazy(() =>
|
|||||||
tools.map((t) => ({
|
tools.map((t) => ({
|
||||||
id: t.id,
|
id: t.id,
|
||||||
description: t.description,
|
description: t.description,
|
||||||
// Handle both Zod schemas and plain JSON schemas
|
parameters: z.toJSONSchema(t.parameters),
|
||||||
parameters: (t.parameters as any)?._def ? zodToJsonSchema(t.parameters as any) : t.parameters,
|
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { Agent } from "../agent/agent"
|
|||||||
import { Provider } from "../provider"
|
import { Provider } from "../provider"
|
||||||
import { ModelID, ProviderID } from "../provider/schema"
|
import { ModelID, ProviderID } from "../provider/schema"
|
||||||
import { type Tool as AITool, tool, jsonSchema, type ToolExecutionOptions, asSchema } from "ai"
|
import { type Tool as AITool, tool, jsonSchema, type ToolExecutionOptions, asSchema } from "ai"
|
||||||
|
import type { JSONSchema7 } from "@ai-sdk/provider"
|
||||||
import { SessionCompaction } from "./compaction"
|
import { SessionCompaction } from "./compaction"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { ProviderTransform } from "../provider"
|
import { ProviderTransform } from "../provider"
|
||||||
@@ -407,9 +408,8 @@ NOTE: At any point in time through this workflow you should feel free to ask the
|
|||||||
})) {
|
})) {
|
||||||
const schema = ProviderTransform.schema(input.model, z.toJSONSchema(item.parameters))
|
const schema = ProviderTransform.schema(input.model, z.toJSONSchema(item.parameters))
|
||||||
tools[item.id] = tool({
|
tools[item.id] = tool({
|
||||||
id: item.id as any,
|
|
||||||
description: item.description,
|
description: item.description,
|
||||||
inputSchema: jsonSchema(schema as any),
|
inputSchema: jsonSchema(schema),
|
||||||
execute(args, options) {
|
execute(args, options) {
|
||||||
return run.promise(
|
return run.promise(
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
@@ -1827,9 +1827,8 @@ NOTE: At any point in time through this workflow you should feel free to ask the
|
|||||||
const { $schema: _, ...toolSchema } = input.schema
|
const { $schema: _, ...toolSchema } = input.schema
|
||||||
|
|
||||||
return tool({
|
return tool({
|
||||||
id: "StructuredOutput" as any,
|
|
||||||
description: STRUCTURED_OUTPUT_DESCRIPTION,
|
description: STRUCTURED_OUTPUT_DESCRIPTION,
|
||||||
inputSchema: jsonSchema(toolSchema as any),
|
inputSchema: jsonSchema(toolSchema as JSONSchema7),
|
||||||
async execute(args) {
|
async execute(args) {
|
||||||
// AI SDK validates args against inputSchema before calling execute()
|
// AI SDK validates args against inputSchema before calling execute()
|
||||||
input.onSuccess(args)
|
input.onSuccess(args)
|
||||||
|
|||||||
@@ -157,16 +157,6 @@ describe("structured-output.AssistantMessage", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("structured-output.createStructuredOutputTool", () => {
|
describe("structured-output.createStructuredOutputTool", () => {
|
||||||
test("creates tool with correct id", () => {
|
|
||||||
const tool = SessionPrompt.createStructuredOutputTool({
|
|
||||||
schema: { type: "object", properties: { name: { type: "string" } } },
|
|
||||||
onSuccess: () => {},
|
|
||||||
})
|
|
||||||
|
|
||||||
// AI SDK tool type doesn't expose id, but we set it internally
|
|
||||||
expect((tool as any).id).toBe("StructuredOutput")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("creates tool with description", () => {
|
test("creates tool with description", () => {
|
||||||
const tool = SessionPrompt.createStructuredOutputTool({
|
const tool = SessionPrompt.createStructuredOutputTool({
|
||||||
schema: { type: "object" },
|
schema: { type: "object" },
|
||||||
|
|||||||
Reference in New Issue
Block a user