Jelajahi Sumber

feat: add model reconciliation hook

Aiden Cline 4 minggu lalu
induk
melakukan
c32c2e8a8f
2 mengubah file dengan 14 tambahan dan 3 penghapusan
  1. 3 3
      packages/opencode/src/plugin/index.ts
  2. 11 0
      packages/plugin/src/index.ts

+ 3 - 3
packages/opencode/src/plugin/index.ts

@@ -110,9 +110,9 @@ export namespace Plugin {
   })
 
   export async function trigger<
-    Name extends Exclude<keyof Required<Hooks>, "auth" | "event" | "tool">,
-    Input = Parameters<Required<Hooks>[Name]>[0],
-    Output = Parameters<Required<Hooks>[Name]>[1],
+    Name extends Exclude<keyof Required<Hooks>, "auth" | "event" | "tool" | "provider">,
+    Input = Parameters<Extract<Required<Hooks>[Name], (...args: any) => any>>[0],
+    Output = Parameters<Extract<Required<Hooks>[Name], (...args: any) => any>>[1],
   >(name: Name, input: Input, output: Output): Promise<Output> {
     if (!name) return output
     for (const hook of await state().then((x) => x.hooks)) {

+ 11 - 0
packages/plugin/src/index.ts

@@ -159,6 +159,16 @@ export type AuthOuathResult = { url: string; instructions: string } & (
     }
 )
 
+export type ProviderHook = {
+  id: string
+  models?: {
+    reconcile?: (input: {
+      provider: Provider
+      models: Record<string, Model>
+    }) => Promise<Record<string, Model> | undefined>
+  }
+}
+
 export interface Hooks {
   event?: (input: { event: Event }) => Promise<void>
   config?: (input: Config) => Promise<void>
@@ -166,6 +176,7 @@ export interface Hooks {
     [key: string]: ToolDefinition
   }
   auth?: AuthHook
+  provider?: ProviderHook
   /**
    * Called when a new message is received
    */