From ca031278ca9ca30277620e344f7a95c597a8a0de Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Sat, 2 Aug 2025 18:50:19 -0400 Subject: wip: plugins --- packages/plugin/src/example.ts | 7 ++++++ packages/plugin/src/index.ts | 56 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 packages/plugin/src/example.ts create mode 100644 packages/plugin/src/index.ts (limited to 'packages/plugin/src') diff --git a/packages/plugin/src/example.ts b/packages/plugin/src/example.ts new file mode 100644 index 000000000..ac8c0e344 --- /dev/null +++ b/packages/plugin/src/example.ts @@ -0,0 +1,7 @@ +import { Plugin } from "./index" + +export const ExamplePlugin: Plugin = async ({ app, client }) => { + return { + permission: {}, + } +} diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts new file mode 100644 index 000000000..9040fb517 --- /dev/null +++ b/packages/plugin/src/index.ts @@ -0,0 +1,56 @@ +import type { Event, createOpencodeClient, App, Model, Provider, Permission, UserMessage, Part } from "@opencode-ai/sdk" +import { $ } from "bun" + +export type PluginInput = { + client: ReturnType + app: App + $: $ +} +export type Plugin = (input: PluginInput) => Promise + +export interface Hooks { + event?: (input: { event: Event }) => Promise + chat?: { + /** + * Called when a new message is received + */ + message?: (input: {}, output: { message: UserMessage; parts: Part[] }) => Promise + /** + * Modify parameters sent to LLM + */ + params?: ( + input: { model: Model; provider: Provider; message: UserMessage }, + output: { temperature: number; topP: number }, + ) => Promise + } + permission?: { + /** + * Called when a permission is asked + */ + ask?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise + } + tool?: { + execute?: { + /** + * Called before a tool is executed + */ + before?: ( + input: { tool: string; sessionID: string; callID: string }, + output: { + args: any + }, + ) => Promise + /** + * Called after a tool is executed + */ + after?: ( + input: { tool: string; sessionID: string; callID: string }, + output: { + title: string + output: string + metadata: any + }, + ) => Promise + } + } +} -- cgit v1.2.3