index.ts 1.4 KB

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