2026-02-08 16:25:25 +09:00
|
|
|
import type { PluginContext, PluginInterface, ToolsRecord } from "./plugin/types"
|
|
|
|
|
import type { OhMyOpenCodeConfig } from "./config"
|
|
|
|
|
|
|
|
|
|
import { createChatParamsHandler } from "./plugin/chat-params"
|
2026-02-18 19:55:36 +02:00
|
|
|
import { createChatHeadersHandler } from "./plugin/chat-headers"
|
2026-02-08 16:25:25 +09:00
|
|
|
import { createChatMessageHandler } from "./plugin/chat-message"
|
2026-03-31 20:02:00 -07:00
|
|
|
import { createCommandExecuteBeforeHandler } from "./plugin/command-execute-before"
|
2026-02-08 16:25:25 +09:00
|
|
|
import { createMessagesTransformHandler } from "./plugin/messages-transform"
|
2026-02-19 04:41:00 +02:00
|
|
|
import { createSystemTransformHandler } from "./plugin/system-transform"
|
2026-02-08 16:25:25 +09:00
|
|
|
import { createEventHandler } from "./plugin/event"
|
|
|
|
|
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,
|
|
|
|
|
|
2026-03-18 20:37:42 +01:00
|
|
|
"chat.params": async (input: unknown, output: unknown) => {
|
|
|
|
|
const handler = createChatParamsHandler({
|
|
|
|
|
anthropicEffort: hooks.anthropicEffort,
|
|
|
|
|
client: ctx.client,
|
|
|
|
|
})
|
|
|
|
|
await handler(input, output)
|
|
|
|
|
},
|
2026-02-08 16:25:25 +09:00
|
|
|
|
2026-02-18 20:15:23 +02:00
|
|
|
"chat.headers": createChatHeadersHandler({ ctx }),
|
2026-02-18 19:55:36 +02:00
|
|
|
|
2026-03-31 20:02:00 -07:00
|
|
|
"command.execute.before": createCommandExecuteBeforeHandler({
|
|
|
|
|
hooks,
|
|
|
|
|
}),
|
|
|
|
|
|
2026-02-08 16:25:25 +09:00
|
|
|
"chat.message": createChatMessageHandler({
|
|
|
|
|
ctx,
|
|
|
|
|
pluginConfig,
|
|
|
|
|
firstMessageVariantGate,
|
|
|
|
|
hooks,
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
"experimental.chat.messages.transform": createMessagesTransformHandler({
|
|
|
|
|
hooks,
|
|
|
|
|
}),
|
|
|
|
|
|
2026-02-22 01:57:22 +09:00
|
|
|
"experimental.chat.system.transform": createSystemTransformHandler(),
|
2026-02-19 04:41:00 +02:00
|
|
|
|
2026-02-08 16:25:25 +09:00
|
|
|
config: managers.configHandler,
|
|
|
|
|
|
|
|
|
|
event: createEventHandler({
|
|
|
|
|
ctx,
|
|
|
|
|
pluginConfig,
|
|
|
|
|
firstMessageVariantGate,
|
|
|
|
|
managers,
|
|
|
|
|
hooks,
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
"tool.execute.before": createToolExecuteBeforeHandler({
|
|
|
|
|
ctx,
|
|
|
|
|
hooks,
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
"tool.execute.after": createToolExecuteAfterHandler({
|
2026-03-06 22:37:41 +09:00
|
|
|
ctx,
|
2026-02-08 16:25:25 +09:00
|
|
|
hooks,
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
}
|