Files
Khaled Ahmed cff25a625a feat(settings): add Chat Font Size and Interface Scale settings with pre-hydration
- Add useFontSize hook (sm/md/lg/xl) with localStorage persistence and cross-tab sync
- Add useUiScale hook (compact/standard/comfortable/large) with viewport-bounded scaling
- Add pre-hydration inline scripts in app/layout.tsx to prevent layout shifts on load
- Integrate Chat Font Size and Interface Scale dropdowns into Settings -> Interface & Behavior
- Index both settings in SETTING_INDEX for instant search filtering
- Update MessageView, ChatInput, SyntaxHighlightedCode, and MermaidBlock to use font-size tokens
- Optimize MessageView memo comparator and toolCallDurations calculation
- Add complete i18n localization in en, zh-CN, and ja
2026-09-01 19:14:51 +03:00

39 lines
1.8 KiB
TypeScript

import type { AgentMessage, AssistantMessage, ToolCallContent } from "./types";
function isObject(val: unknown): val is Record<string, unknown> {
return typeof val === "object" && val !== null && !Array.isArray(val);
}
function normalizeToolCallBlock(block: unknown): ToolCallContent | null {
if (!isObject(block) || block.type !== "toolCall") return null;
return {
type: "toolCall",
toolCallId: typeof block.toolCallId === "string" ? block.toolCallId : (typeof block.id === "string" ? block.id : ""),
toolName: typeof block.toolName === "string" ? block.toolName : (typeof block.name === "string" ? block.name : ""),
input: typeof block.input === "object" && block.input !== null && !Array.isArray(block.input)
? block.input as Record<string, unknown>
: (typeof block.arguments === "object" && block.arguments !== null && !Array.isArray(block.arguments)
? block.arguments as Record<string, unknown>
: {}),
};
}
export function normalizeToolCalls(msg: AgentMessage): AgentMessage {
// Non-assistant roles (user, toolResult, bashExecution, custom) are returned
// unchanged — only assistant messages go through tool-call field normalization.
if (msg.role !== "assistant") return msg;
const content = (msg as AssistantMessage).content;
if (!Array.isArray(content)) return msg;
let changed = false;
const normalized = content.map((block) => {
const result = normalizeToolCallBlock(block);
if (!result) return block;
const b = block as unknown as Record<string, unknown>;
if (b.toolCallId !== result.toolCallId || b.toolName !== result.toolName || b.input !== result.input) {
changed = true;
return result;
}
return block;
});
return changed ? ({ ...msg, content: normalized } as AgentMessage) : msg;
}