refactor(codemode): namespace public types (#35435)

This commit is contained in:
Aiden Cline 2026-07-05 11:51:50 -05:00 committed by GitHub
commit f9d1d3b259
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 423 additions and 475 deletions

View file

@ -1,14 +1,6 @@
export * as ExecuteTool from "./execute"
import {
CodeMode,
Tool,
toolError,
type DataValue,
type ExecuteResult,
type ToolCallHooks,
type ToolDefinition,
} from "@opencode-ai/codemode"
import { CodeMode, Tool, toolError } from "@opencode-ai/codemode"
import { ToolOutput } from "@opencode-ai/llm"
import { Effect, Ref, Schema } from "effect"
import { definition, make, settle, type AnyTool } from "./tool"
@ -57,9 +49,9 @@ export const create = (options: {
}) => {
const runtime = (
invoke: (name: string, registration: Registration, input: unknown) => Effect.Effect<unknown, unknown>,
hooks?: ToolCallHooks,
hooks?: CodeMode.ToolCallHooks,
) => {
const tools: Record<string, ToolDefinition<never> | Record<string, ToolDefinition<never>>> = {}
const tools: Record<string, Tool.Definition<never> | Record<string, Tool.Definition<never>>> = {}
for (const [name, registration] of options.registrations) {
const child = definition(name, registration.tool)
const value = Tool.make({
@ -83,7 +75,7 @@ export const create = (options: {
group[path] = value
continue
}
const entries: Record<string, ToolDefinition<never>> = {}
const entries: Record<string, Tool.Definition<never>> = {}
entries[path] = value
tools[namespace] = entries
}
@ -178,7 +170,7 @@ function displayInput(input: unknown): Record<string, unknown> | undefined {
return input as Record<string, unknown>
}
function formatResult(result: ExecuteResult) {
function formatResult(result: CodeMode.Result) {
const output = result.ok
? formatValue(result.value)
: [result.error.message, ...(result.error.suggestions ?? []).filter((hint) => !result.error.message.includes(hint))]
@ -189,7 +181,7 @@ function formatResult(result: ExecuteResult) {
return output === "" ? logs : `${output}\n\n${logs}`
}
function formatValue(value: DataValue) {
function formatValue(value: CodeMode.DataValue) {
if (typeof value === "string") return value
return JSON.stringify(value, null, 2) ?? String(value)
}