mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-05 04:06:45 +00:00
feat: add model reconciliation hook
This commit is contained in:
@@ -110,9 +110,9 @@ export namespace Plugin {
|
|||||||
})
|
})
|
||||||
|
|
||||||
export async function trigger<
|
export async function trigger<
|
||||||
Name extends Exclude<keyof Required<Hooks>, "auth" | "event" | "tool">,
|
Name extends Exclude<keyof Required<Hooks>, "auth" | "event" | "tool" | "provider">,
|
||||||
Input = Parameters<Required<Hooks>[Name]>[0],
|
Input = Parameters<Extract<Required<Hooks>[Name], (...args: any) => any>>[0],
|
||||||
Output = Parameters<Required<Hooks>[Name]>[1],
|
Output = Parameters<Extract<Required<Hooks>[Name], (...args: any) => any>>[1],
|
||||||
>(name: Name, input: Input, output: Output): Promise<Output> {
|
>(name: Name, input: Input, output: Output): Promise<Output> {
|
||||||
if (!name) return output
|
if (!name) return output
|
||||||
for (const hook of await state().then((x) => x.hooks)) {
|
for (const hook of await state().then((x) => x.hooks)) {
|
||||||
|
|||||||
@@ -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 {
|
export interface Hooks {
|
||||||
event?: (input: { event: Event }) => Promise<void>
|
event?: (input: { event: Event }) => Promise<void>
|
||||||
config?: (input: Config) => Promise<void>
|
config?: (input: Config) => Promise<void>
|
||||||
@@ -166,6 +176,7 @@ export interface Hooks {
|
|||||||
[key: string]: ToolDefinition
|
[key: string]: ToolDefinition
|
||||||
}
|
}
|
||||||
auth?: AuthHook
|
auth?: AuthHook
|
||||||
|
provider?: ProviderHook
|
||||||
/**
|
/**
|
||||||
* Called when a new message is received
|
* Called when a new message is received
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user