fix(gateway): resolve local avatars to URL in HTML injection and RPC

The frontend fix alone wasn't enough because:
1. serveIndexHtml() was injecting the raw avatar filename into HTML
2. agent.identity.get RPC was returning raw filename, overwriting the
   HTML-injected value

Now both paths resolve local file avatars (*.png, *.jpg, etc.) to the
/avatar/{agentId} endpoint URL.
This commit is contained in:
Dave Lauer
2026-01-22 15:16:31 -05:00
parent 9d09a7879c
commit ffca65d15f
2 changed files with 24 additions and 2 deletions

View File

@@ -407,7 +407,18 @@ export const agentHandlers: GatewayRequestHandlers = {
}
const cfg = loadConfig();
const identity = resolveAssistantIdentity({ cfg, agentId });
respond(true, identity, undefined);
// Resolve local file avatars to /avatar/{agentId} URL
let avatarValue = identity.avatar;
if (
avatarValue &&
!/^https?:\/\//i.test(avatarValue) &&
!/^data:image\//i.test(avatarValue) &&
/\.(png|jpe?g|gif|webp|svg|ico)$/i.test(avatarValue) &&
identity.agentId
) {
avatarValue = `/avatar/${identity.agentId}`;
}
respond(true, { ...identity, avatar: avatarValue }, undefined);
},
"agent.wait": async ({ params, respond }) => {
if (!validateAgentWaitParams(params)) {