opencode/packages/plugin/src/index.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-08-03 06:50:19 +08:00
import type { Event, createOpencodeClient, App, Model, Provider, Permission, UserMessage, Part } from "@opencode-ai/sdk"
2025-08-05 11:06:49 +08:00
import type { BunShell } from "./shell"
2025-08-03 06:50:19 +08:00
export type PluginInput = {
client: ReturnType<typeof createOpencodeClient>
app: App
2025-08-05 11:06:49 +08:00
$: BunShell
2025-08-03 06:50:19 +08:00
}
export type Plugin = (input: PluginInput) => Promise<Hooks>
export interface Hooks {
event?: (input: { event: Event }) => Promise<void>
2025-08-04 09:42:45 +08:00
/**
* Called when a new message is received
*/
"chat.message"?: (input: {}, output: { message: UserMessage; parts: Part[] }) => Promise<void>
/**
* Modify parameters sent to LLM
*/
"chat.params"?: (
input: { model: Model; provider: Provider; message: UserMessage },
2025-08-11 08:30:25 +08:00
output: { temperature: number; topP: number; options: Record<string, any> },
2025-08-04 09:42:45 +08:00
) => Promise<void>
"permission.ask"?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise<void>
"tool.execute.before"?: (
input: { tool: string; sessionID: string; callID: string },
output: { args: any },
) => Promise<void>
"tool.execute.after"?: (
input: { tool: string; sessionID: string; callID: string },
output: {
title: string
output: string
metadata: any
},
) => Promise<void>
2025-08-03 06:50:19 +08:00
}