@@ -5,7 +5,6 @@ import { Bus } from "../bus"
55import { Log } from "../util/log"
66import { createOpencodeClient } from "@opencode-ai/sdk"
77import { Server } from "../server/server"
8- import { pathOr } from "remeda"
98import { BunProc } from "../bun"
109
1110export namespace Plugin {
@@ -40,38 +39,14 @@ export namespace Plugin {
4039 }
4140 } )
4241
43- type Path < T , Prefix extends string = "" > = T extends object
44- ? {
45- [ K in keyof T ] : K extends string
46- ? T [ K ] extends Function | undefined
47- ? `${Prefix } ${K } `
48- : Path < T [ K ] , `${Prefix } ${K } .`>
49- : never
50- } [ keyof T ]
51- : never
52-
53- export type FunctionFromKey < T , P extends Path < T > > = P extends `${infer K } .${infer R } `
54- ? K extends keyof T
55- ? R extends Path < T [ K ] >
56- ? FunctionFromKey < T [ K ] , R >
57- : never
58- : never
59- : P extends keyof T
60- ? T [ P ]
61- : never
62-
6342 export async function trigger <
64- Name extends Path < Required < Hooks > > ,
65- Input = Parameters < FunctionFromKey < Required < Hooks > , Name > > [ 0 ] ,
66- Output = Parameters < FunctionFromKey < Required < Hooks > , Name > > [ 1 ] ,
67- > ( fn : Name , input : Input , output : Output ) : Promise < Output > {
68- if ( ! fn ) return output
69- const path = fn . split ( "." )
43+ Name extends keyof Required < Hooks > ,
44+ Input = Parameters < Required < Hooks > [ Name ] > [ 0 ] ,
45+ Output = Parameters < Required < Hooks > [ Name ] > [ 1 ] ,
46+ > ( name : Name , input : Input , output : Output ) : Promise < Output > {
47+ if ( ! name ) return output
7048 for ( const hook of await state ( ) . then ( ( x ) => x . hooks ) ) {
71- // @ts -expect-error if you feel adventurous, please fix the typing, make sure to bump the try-counter if you
72- // give up.
73- // try-counter: 2
74- const fn = pathOr ( hook , path , undefined )
49+ const fn = hook [ name ]
7550 if ( ! fn ) continue
7651 // @ts -expect-error if you feel adventurous, please fix the typing, make sure to bump the try-counter if you
7752 // give up.
0 commit comments