fix(cli): normalise les timestamps chat secondes/ms pour l'heure des messages — #221
This commit is contained in:
@ -75,6 +75,14 @@ const chatConversationViewCache = new Map<string, CachedChatView>();
|
||||
const EMPTY_MODEL_RESPONSE_MESSAGE = "Le modèle n'a renvoyé aucune réponse.";
|
||||
const COMPOSER_RESIZE_STEP = 12;
|
||||
const FALLBACK_COMPOSER_HEIGHT = 64;
|
||||
const MIN_REASONABLE_CHAT_TIMESTAMP_MS = Date.UTC(2020, 0, 1);
|
||||
const MAX_REASONABLE_CHAT_TIMESTAMP_MS = Date.UTC(2100, 0, 1);
|
||||
const MIN_REASONABLE_CHAT_TIMESTAMP_SECONDS = Math.floor(
|
||||
MIN_REASONABLE_CHAT_TIMESTAMP_MS / 1000,
|
||||
);
|
||||
const MAX_REASONABLE_CHAT_TIMESTAMP_SECONDS = Math.floor(
|
||||
MAX_REASONABLE_CHAT_TIMESTAMP_MS / 1000,
|
||||
);
|
||||
|
||||
export function __clearCustomAgentChatViewCacheForTests() {
|
||||
chatSessionViewCache.clear();
|
||||
@ -1120,7 +1128,10 @@ export function CustomAgentChatView({
|
||||
setCurrentSession(reattached.sessionId);
|
||||
if (options.applyScrollback) {
|
||||
scrollbackChunkCountRef.current = reattached.scrollback.length;
|
||||
const replayed = reattached.scrollback.reduce(foldChunk, emptyChatViewState());
|
||||
const replayed = reattached.scrollback.reduce(
|
||||
(state, chunk) => foldChunk(state, chunk),
|
||||
emptyChatViewState(),
|
||||
);
|
||||
applyChatViewState(replayed);
|
||||
setBusy(turnsIndicateBusy(replayed));
|
||||
}
|
||||
@ -2175,14 +2186,34 @@ function ChatBubble({
|
||||
);
|
||||
}
|
||||
|
||||
function normalizeChatReceivedAtMs(receivedAtMs: number | undefined): number | undefined {
|
||||
if (!Number.isFinite(receivedAtMs) || receivedAtMs === undefined || receivedAtMs <= 0) {
|
||||
return undefined;
|
||||
}
|
||||
if (
|
||||
receivedAtMs >= MIN_REASONABLE_CHAT_TIMESTAMP_SECONDS &&
|
||||
receivedAtMs < MAX_REASONABLE_CHAT_TIMESTAMP_SECONDS
|
||||
) {
|
||||
return receivedAtMs * 1000;
|
||||
}
|
||||
if (
|
||||
receivedAtMs < MIN_REASONABLE_CHAT_TIMESTAMP_MS ||
|
||||
receivedAtMs >= MAX_REASONABLE_CHAT_TIMESTAMP_MS
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
return receivedAtMs;
|
||||
}
|
||||
|
||||
function formatChatReceivedTime(receivedAtMs: number | undefined): string {
|
||||
if (!Number.isFinite(receivedAtMs) || !receivedAtMs) return "";
|
||||
const normalizedAtMs = normalizeChatReceivedAtMs(receivedAtMs);
|
||||
if (!normalizedAtMs) return "";
|
||||
try {
|
||||
const parts = new Intl.DateTimeFormat(undefined, {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
hourCycle: "h23",
|
||||
}).formatToParts(new Date(receivedAtMs));
|
||||
}).formatToParts(new Date(normalizedAtMs));
|
||||
const hour = parts.find((part) => part.type === "hour")?.value;
|
||||
const minute = parts.find((part) => part.type === "minute")?.value;
|
||||
return hour && minute ? `${hour}:${minute}` : "";
|
||||
@ -2201,7 +2232,8 @@ function ChatMessageMeta({
|
||||
labelClassName?: string;
|
||||
}) {
|
||||
const time = formatChatReceivedTime(receivedAtMs);
|
||||
const dateTime = time && receivedAtMs ? new Date(receivedAtMs).toISOString() : undefined;
|
||||
const normalizedAtMs = normalizeChatReceivedAtMs(receivedAtMs);
|
||||
const dateTime = time && normalizedAtMs ? new Date(normalizedAtMs).toISOString() : undefined;
|
||||
return (
|
||||
<div className="mb-1 flex min-w-0 flex-col gap-0.5 text-xs sm:flex-row sm:items-baseline sm:justify-between sm:gap-3">
|
||||
<span className={cn("min-w-0 truncate font-medium text-muted", labelClassName)}>
|
||||
|
||||
Reference in New Issue
Block a user