forked from code-yeongyu/oh-my-openagent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin-interface.ts
More file actions
105 lines (90 loc) · 3.21 KB
/
Copy pathplugin-interface.ts
File metadata and controls
105 lines (90 loc) · 3.21 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import type { PluginContext, PluginInterface, ToolsRecord } from "./plugin/types"
import type { OhMyOpenCodeConfig } from "./config"
import { applyAgentVariant } from "./shared/agent-variant"
import { createChatParamsHandler } from "./plugin/chat-params"
import { createChatHeadersHandler } from "./plugin/chat-headers"
import { createChatMessageHandler } from "./plugin/chat-message"
import { createCommandExecuteBeforeHandler } from "./plugin/command-execute-before"
import { createMessagesTransformHandler } from "./plugin/messages-transform"
import { createSystemTransformHandler } from "./plugin/system-transform"
import { getUltraworkMessage } from "./hooks/keyword-detector/ultrawork"
import { createEventHandler } from "./plugin/event"
import { createToolDefinitionHandler } from "./plugin/tool-definition"
import { createToolExecuteAfterHandler } from "./plugin/tool-execute-after"
import { createToolExecuteBeforeHandler } from "./plugin/tool-execute-before"
import type { CreatedHooks } from "./create-hooks"
import type { Managers } from "./create-managers"
export function createPluginInterface(args: {
ctx: PluginContext
pluginConfig: OhMyOpenCodeConfig
firstMessageVariantGate: {
shouldOverride: (sessionID: string) => boolean
markApplied: (sessionID: string) => void
markSessionCreated: (sessionInfo: { id?: string; title?: string; parentID?: string } | undefined) => void
clear: (sessionID: string) => void
}
managers: Managers
hooks: CreatedHooks
tools: ToolsRecord
}): PluginInterface {
const { ctx, pluginConfig, firstMessageVariantGate, managers, hooks, tools } =
args
return {
tool: tools,
"chat.params": async (input: unknown, output: unknown) => {
const chatParamsInput = input as {
agent?: string | { name?: string }
message?: { variant?: string }
}
const agentName =
typeof chatParamsInput.agent === "string"
? chatParamsInput.agent
: chatParamsInput.agent?.name
if (chatParamsInput.message) {
applyAgentVariant(pluginConfig, agentName, chatParamsInput.message)
}
const handler = createChatParamsHandler({
client: ctx.client,
})
await handler(input, output)
},
"chat.headers": createChatHeadersHandler({ ctx }),
"command.execute.before": createCommandExecuteBeforeHandler({
directory: ctx.directory,
hooks,
}),
"chat.message": createChatMessageHandler({
ctx,
pluginConfig,
firstMessageVariantGate,
hooks,
}),
"experimental.chat.messages.transform": createMessagesTransformHandler({
hooks,
}),
"experimental.chat.system.transform": createSystemTransformHandler(
pluginConfig.default_mode,
getUltraworkMessage,
),
config: managers.configHandler,
event: createEventHandler({
ctx,
pluginConfig,
firstMessageVariantGate,
managers,
hooks,
}),
"tool.definition": createToolDefinitionHandler({
hooks,
}),
"tool.execute.before": createToolExecuteBeforeHandler({
ctx,
hooks,
backgroundManager: managers.backgroundManager,
}),
"tool.execute.after": createToolExecuteAfterHandler({
ctx,
hooks,
}),
}
}