mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 21:24:32 +00:00
refactor(outbound): centralize outbound identity
This commit is contained in:
37
src/infra/outbound/identity.ts
Normal file
37
src/infra/outbound/identity.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { resolveAgentAvatar } from "../../agents/identity-avatar.js";
|
||||
import { resolveAgentIdentity } from "../../agents/identity.js";
|
||||
|
||||
export type OutboundIdentity = {
|
||||
name?: string;
|
||||
avatarUrl?: string;
|
||||
emoji?: string;
|
||||
};
|
||||
|
||||
export function normalizeOutboundIdentity(
|
||||
identity?: OutboundIdentity | null,
|
||||
): OutboundIdentity | undefined {
|
||||
if (!identity) {
|
||||
return undefined;
|
||||
}
|
||||
const name = identity.name?.trim() || undefined;
|
||||
const avatarUrl = identity.avatarUrl?.trim() || undefined;
|
||||
const emoji = identity.emoji?.trim() || undefined;
|
||||
if (!name && !avatarUrl && !emoji) {
|
||||
return undefined;
|
||||
}
|
||||
return { name, avatarUrl, emoji };
|
||||
}
|
||||
|
||||
export function resolveAgentOutboundIdentity(
|
||||
cfg: OpenClawConfig,
|
||||
agentId: string,
|
||||
): OutboundIdentity | undefined {
|
||||
const agentIdentity = resolveAgentIdentity(cfg, agentId);
|
||||
const avatar = resolveAgentAvatar(cfg, agentId);
|
||||
return normalizeOutboundIdentity({
|
||||
name: agentIdentity?.name,
|
||||
emoji: agentIdentity?.emoji,
|
||||
avatarUrl: avatar.kind === "remote" ? avatar.url : undefined,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user