-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
executable file
·41 lines (34 loc) · 1.24 KB
/
index.ts
File metadata and controls
executable file
·41 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/// <reference types="node" />
import type { Hooks, Plugin, PluginInput } from "@opencode-ai/plugin"
import { ContextMemoryHook } from "./lib/hooks/context-memory"
import { HistoryRecallRouterHook } from "./lib/hooks/history-recall-router"
import { ToolCallGuardHook } from "./lib/hooks/tool-call-guard"
function mergeHooks(hooksList: Hooks[]): Hooks {
const merged: Record<string, unknown> = {}
for (const hooks of hooksList) {
for (const [name, fn] of Object.entries(hooks)) {
if (typeof fn !== "function") continue
const existing = merged[name]
if (typeof existing === "function") {
const current = existing as (...args: unknown[]) => Promise<void>
const next = fn
merged[name] = async (...args: unknown[]) => {
await current(...args)
await (next as (...innerArgs: unknown[]) => Promise<void>)(...args)
}
} else {
merged[name] = fn
}
}
}
return merged as Hooks
}
export const OpenCodePlugins: Plugin = async (ctx: PluginInput): Promise<Hooks> => {
const hooksList: Hooks[] = [
await ContextMemoryHook(ctx),
await HistoryRecallRouterHook(ctx),
await ToolCallGuardHook(ctx),
]
return mergeHooks(hooksList)
}
export default OpenCodePlugins