Files
oh-my-opencode/src/plugin-handlers/agent-key-remapper.ts
T
ZeyuFu 7bc92bcd25 feat(agents): support per-agent displayName for i18n (#4004)
Add optional `displayName` field to AgentOverrideConfigSchema (next to
the existing `color` field) so users can specify localized agent names
in oh-my-openagent.json:

  { "agents": { "sisyphus": { "displayName": "总指挥" } } }

When set, the override takes precedence everywhere
AGENT_DISPLAY_NAMES[agentName] is used — TUI agent selector, the
agent list key, and the internal `name` field. When not set, behavior
is identical to before (hardcoded English names from AGENT_DISPLAY_NAMES).

Implementation touches:
- AgentOverrideConfigSchema: adds displayName?: z.string().optional()
- getAgentDisplayName / getAgentListDisplayName: accept optional overrides
  map and check displayName before the hardcoded table
- remapAgentKeysToDisplayNames: forwards overrides map to name resolution
- agent-config-handler: passes pluginConfig.agents as the overrides map

Backward compatible — existing configs without displayName continue to
work unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 06:52:14 -04:00

43 lines
1.4 KiB
TypeScript

import { getAgentListDisplayName } from "../shared/agent-display-names"
type AgentOverridesMap = Record<string, { displayName?: string } | undefined>
function rewriteAgentNameForListDisplay(
key: string,
value: unknown,
overrides?: AgentOverridesMap,
): unknown {
if (typeof value !== "object" || value === null) {
return value
}
const agent = value as Record<string, unknown>
return {
...agent,
name: getAgentListDisplayName(key, overrides),
}
}
export function remapAgentKeysToDisplayNames(
agents: Record<string, unknown>,
overrides?: AgentOverridesMap,
): Record<string, unknown> {
const result: Record<string, unknown> = {}
for (const [key, value] of Object.entries(agents)) {
const displayName = getAgentListDisplayName(key, overrides)
if (displayName && displayName !== key) {
result[displayName] = rewriteAgentNameForListDisplay(key, value, overrides)
// Regression guard: do not also assign result[key].
// This line was repeatedly re-added and caused duplicate agent rows in the UI.
// Runtime callers that previously depended on config-key aliases were fixed in:
// - hooks/atlas/boulder-continuation-injector.ts (prompt agent normalization)
// - features/claude-code-session-state/state.ts (dual registration for display + config forms)
} else {
result[key] = value
}
}
return result
}