|
| 1 | +import type { CliBackendConfig } from "../config/types.js"; |
| 2 | +import type { OpenClawConfig } from "../config/types.openclaw.js"; |
| 3 | + |
| 4 | +export type PluginTextReplacement = { |
| 5 | + from: string | RegExp; |
| 6 | + to: string; |
| 7 | +}; |
| 8 | + |
| 9 | +export type PluginTextTransforms = { |
| 10 | + /** Rewrites applied to outbound prompt text before provider/CLI transport. */ |
| 11 | + input?: PluginTextReplacement[]; |
| 12 | + /** Rewrites applied to inbound assistant text before OpenClaw consumes it. */ |
| 13 | + output?: PluginTextReplacement[]; |
| 14 | +}; |
| 15 | + |
| 16 | +export type CliBundleMcpMode = |
| 17 | + | "claude-config-file" |
| 18 | + | "codex-config-overrides" |
| 19 | + | "gemini-system-settings"; |
| 20 | + |
| 21 | +/** Plugin-owned CLI backend defaults used by the text-only CLI runner. */ |
| 22 | +export type CliBackendPlugin = { |
| 23 | + /** Provider id used in model refs, for example `claude-cli/opus`. */ |
| 24 | + id: string; |
| 25 | + /** Default backend config before user overrides from `agents.defaults.cliBackends`. */ |
| 26 | + config: CliBackendConfig; |
| 27 | + /** |
| 28 | + * Optional live-smoke metadata owned by the backend plugin. |
| 29 | + * |
| 30 | + * Keep provider-specific test wiring here instead of scattering it across |
| 31 | + * Docker wrappers, docs, and gateway live tests. |
| 32 | + */ |
| 33 | + liveTest?: { |
| 34 | + defaultModelRef?: string; |
| 35 | + defaultImageProbe?: boolean; |
| 36 | + defaultMcpProbe?: boolean; |
| 37 | + docker?: { |
| 38 | + npmPackage?: string; |
| 39 | + binaryName?: string; |
| 40 | + }; |
| 41 | + }; |
| 42 | + /** |
| 43 | + * Whether OpenClaw should inject bundle MCP config for this backend. |
| 44 | + * |
| 45 | + * Keep this opt-in. Only backends that explicitly consume OpenClaw's bundle |
| 46 | + * MCP bridge should enable it. |
| 47 | + */ |
| 48 | + bundleMcp?: boolean; |
| 49 | + /** |
| 50 | + * Provider-owned bundle MCP integration strategy. |
| 51 | + * |
| 52 | + * Different CLIs wire MCP through different surfaces: |
| 53 | + * - Claude: `--strict-mcp-config --mcp-config` |
| 54 | + * - Codex: `-c mcp_servers=...` |
| 55 | + * - Gemini: system-level `settings.json` |
| 56 | + */ |
| 57 | + bundleMcpMode?: CliBundleMcpMode; |
| 58 | + /** |
| 59 | + * Optional config normalizer applied after user overrides merge. |
| 60 | + * |
| 61 | + * Use this for backend-specific compatibility rewrites when old config |
| 62 | + * shapes need to stay working. |
| 63 | + */ |
| 64 | + normalizeConfig?: (config: CliBackendConfig) => CliBackendConfig; |
| 65 | + /** |
| 66 | + * Backend-owned final system-prompt transform. |
| 67 | + * |
| 68 | + * Use this for tiny CLI-specific compatibility rewrites without replacing |
| 69 | + * the generic CLI runner or prompt builder. |
| 70 | + */ |
| 71 | + transformSystemPrompt?: (ctx: { |
| 72 | + config?: OpenClawConfig; |
| 73 | + workspaceDir?: string; |
| 74 | + provider: string; |
| 75 | + modelId: string; |
| 76 | + modelDisplay: string; |
| 77 | + agentId?: string; |
| 78 | + systemPrompt: string; |
| 79 | + }) => string | null | undefined; |
| 80 | + /** |
| 81 | + * Backend-owned bidirectional text replacements. |
| 82 | + * |
| 83 | + * `input` applies to the system prompt and user prompt passed to the CLI. |
| 84 | + * `output` applies to parsed/streamed assistant text from the CLI. |
| 85 | + */ |
| 86 | + textTransforms?: PluginTextTransforms; |
| 87 | +}; |
0 commit comments