oh-my-opencode/src/plugin/chat-params.ts
YeonGyu-Kim af7b1ee620 refactor(hashline): override native edit tool instead of separate tool + disabler hook
Replace 3-component hashline system (separate hashline_edit tool + edit
disabler hook + OpenAI-exempted read enhancer) with 2-component system
that directly overrides the native edit tool key, matching the
delegate_task pattern.

- Register hashline tool as 'edit' key to override native edit
- Delete hashline-edit-disabler hook (no longer needed)
- Delete hashline-provider-state module (no remaining consumers)
- Remove OpenAI exemption from read enhancer (explicit opt-in means all providers)
- Remove setProvider wiring from chat-params
2026-02-17 00:03:10 +09:00

72 lines
2.0 KiB
TypeScript

type ChatParamsInput = {
sessionID: string
agent: { name?: string }
model: { providerID: string; modelID: string }
provider: { id: string }
message: { variant?: string }
}
type ChatParamsOutput = {
temperature?: number
topP?: number
topK?: number
options: Record<string, unknown>
}
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null
}
function buildChatParamsInput(raw: unknown): ChatParamsInput | null {
if (!isRecord(raw)) return null
const sessionID = raw.sessionID
const agent = raw.agent
const model = raw.model
const provider = raw.provider
const message = raw.message
if (typeof sessionID !== "string") return null
if (typeof agent !== "string") return null
if (!isRecord(model)) return null
if (!isRecord(provider)) return null
if (!isRecord(message)) return null
const providerID = model.providerID
const modelID = model.modelID
const providerId = provider.id
const variant = message.variant
if (typeof providerID !== "string") return null
if (typeof modelID !== "string") return null
if (typeof providerId !== "string") return null
return {
sessionID,
agent: { name: agent },
model: { providerID, modelID },
provider: { id: providerId },
message: typeof variant === "string" ? { variant } : {},
}
}
function isChatParamsOutput(raw: unknown): raw is ChatParamsOutput {
if (!isRecord(raw)) return false
if (!isRecord(raw.options)) {
raw.options = {}
}
return isRecord(raw.options)
}
export function createChatParamsHandler(args: {
anthropicEffort: { "chat.params"?: (input: ChatParamsInput, output: ChatParamsOutput) => Promise<void> } | null
}): (input: unknown, output: unknown) => Promise<void> {
return async (input, output): Promise<void> => {
const normalizedInput = buildChatParamsInput(input)
if (!normalizedInput) return
if (!isChatParamsOutput(output)) return
await args.anthropicEffort?.["chat.params"]?.(normalizedInput, output)
}
}