tool rework

This commit is contained in:
Dax Raad
2025-05-31 17:12:16 -04:00
parent 33109bac4d
commit b4f809559e
19 changed files with 142 additions and 110 deletions

View File

@@ -7,6 +7,17 @@ import { Log } from "../util/log"
import path from "path"
import { Global } from "../global"
import { BunProc } from "../bun"
import { BashTool } from "../tool/bash"
import { EditTool } from "../tool/edit"
import { FetchTool } from "../tool/fetch"
import { GlobTool } from "../tool/glob"
import { GrepTool } from "../tool/grep"
import { ListTool } from "../tool/ls"
import { LspDiagnosticTool } from "../tool/lsp-diagnostics"
import { LspHoverTool } from "../tool/lsp-hover"
import { PatchTool } from "../tool/patch"
import { ViewTool } from "../tool/view"
import type { Tool } from "../tool/tool"
export namespace Provider {
const log = Log.create({ service: "provider" })
@@ -130,6 +141,33 @@ export namespace Provider {
}
}
const TOOLS = [
BashTool,
EditTool,
FetchTool,
GlobTool,
GrepTool,
ListTool,
LspDiagnosticTool,
LspHoverTool,
PatchTool,
ViewTool,
EditTool,
]
const TOOL_MAPPING: Record<string, Tool.Info[]> = {
anthropic: TOOLS,
openai: TOOLS,
google: TOOLS,
}
export async function tools(providerID: string) {
const cfg = await Config.get()
if (cfg.tool?.provider?.[providerID])
return cfg.tool.provider[providerID].map(
(id) => TOOLS.find((t) => t.id === id)!,
)
return TOOL_MAPPING[providerID] ?? TOOLS
}
class ModelNotFoundError extends Error {
constructor(public readonly model: string) {
super()