import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts"; import { resolveLivePluginConfigObject } from "openclaw/plugin-sdk/plugin-config-runtime"; import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry"; import { createCodexAppServerAgentHarness } from "./harness.js"; import { buildCodexMediaUnderstandingProvider } from "./media-understanding-provider.js"; import { buildCodexProvider } from "./provider.js"; import { createCodexCommand } from "./src/commands.js"; import { handleCodexConversationBindingResolved, handleCodexConversationInboundClaim, } from "./src/conversation-binding.js"; import { buildCodexMigrationProvider } from "./src/migration/provider.js"; import { createCodexCliSessionNodeHostCommands, createCodexCliSessionNodeInvokePolicies, listCodexCliSessionsOnNode, resumeCodexCliSessionOnNode, resolveCodexCliSessionForBindingOnNode, } from "./src/node-cli-sessions.js"; export default definePluginEntry({ id: "codex", name: "Codex", description: "Codex app-server harness and Codex-managed GPT model catalog.", register(api) { const resolveCurrentPluginConfig = () => resolveLivePluginConfigObject( api.runtime.config?.current ? () => api.runtime.config.current() as OpenClawConfig : undefined, "codex", api.pluginConfig as Record, ) ?? api.pluginConfig; api.registerAgentHarness(createCodexAppServerAgentHarness({ pluginConfig: api.pluginConfig })); api.registerProvider(buildCodexProvider({ pluginConfig: api.pluginConfig })); api.registerMediaUnderstandingProvider( buildCodexMediaUnderstandingProvider({ pluginConfig: api.pluginConfig }), ); api.registerMigrationProvider(buildCodexMigrationProvider({ runtime: api.runtime })); for (const command of createCodexCliSessionNodeHostCommands()) { api.registerNodeHostCommand(command); } for (const policy of createCodexCliSessionNodeInvokePolicies()) { api.registerNodeInvokePolicy(policy); } api.registerCommand( createCodexCommand({ pluginConfig: api.pluginConfig, deps: { listCodexCliSessionsOnNode: (params) => listCodexCliSessionsOnNode({ runtime: api.runtime, ...params }), resolveCodexCliSessionForBindingOnNode: (params) => resolveCodexCliSessionForBindingOnNode({ runtime: api.runtime, ...params }), }, }), ); api.on("inbound_claim", (event, ctx) => handleCodexConversationInboundClaim(event, ctx, { pluginConfig: resolveCurrentPluginConfig(), resumeCodexCliSessionOnNode: (params) => resumeCodexCliSessionOnNode({ runtime: api.runtime, ...params }), }), ); api.onConversationBindingResolved?.(handleCodexConversationBindingResolved); }, });