index.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import type { Event, createOpencodeClient, App, Model, Provider, Permission, UserMessage, Part } from "@opencode-ai/sdk"
  2. import type { BunShell } from "./shell"
  3. export type PluginInput = {
  4. client: ReturnType<typeof createOpencodeClient>
  5. app: App
  6. $: BunShell
  7. }
  8. export type Plugin = (input: PluginInput) => Promise<Hooks>
  9. export interface Hooks {
  10. event?: (input: { event: Event }) => Promise<void>
  11. /**
  12. * Called when a new message is received
  13. */
  14. "chat.message"?: (input: {}, output: { message: UserMessage; parts: Part[] }) => Promise<void>
  15. /**
  16. * Modify parameters sent to LLM
  17. */
  18. "chat.params"?: (
  19. input: { model: Model; provider: Provider; message: UserMessage },
  20. output: { temperature: number; topP: number; options: Record<string, any> },
  21. ) => Promise<void>
  22. "permission.ask"?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise<void>
  23. "tool.execute.before"?: (
  24. input: { tool: string; sessionID: string; callID: string },
  25. output: { args: any },
  26. ) => Promise<void>
  27. "tool.execute.after"?: (
  28. input: { tool: string; sessionID: string; callID: string },
  29. output: {
  30. title: string
  31. output: string
  32. metadata: any
  33. },
  34. ) => Promise<void>
  35. }