43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
const AGENT_MODE_SCOPED_CHAT_SUFFIX = "a93e17a60001";
|
|
const CHAT_UUID_REGEX =
|
|
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
const EMPTY_HISTORY_SCOPES = new Set(["canvas", "agent"]);
|
|
|
|
export function normalizeMessagesChatId(chatId: string) {
|
|
const normalized = String(chatId || "").trim();
|
|
const canvasPrefix = "canvas-";
|
|
if (normalized.toLowerCase().startsWith(canvasPrefix)) {
|
|
const rawCanvasId = normalized.slice(canvasPrefix.length);
|
|
return CHAT_UUID_REGEX.test(rawCanvasId) ? rawCanvasId : normalized;
|
|
}
|
|
return normalized;
|
|
}
|
|
|
|
export function isValidMessagesChatId(chatId: string) {
|
|
return CHAT_UUID_REGEX.test(String(chatId || "").trim());
|
|
}
|
|
|
|
export function isAgentModeScopedChatId(chatId: string) {
|
|
const normalized = String(chatId || "")
|
|
.trim()
|
|
.toLowerCase()
|
|
.replace(/-/g, "");
|
|
|
|
return (
|
|
/^[0-9a-f]{32}$/.test(normalized) &&
|
|
normalized.endsWith(AGENT_MODE_SCOPED_CHAT_SUFFIX)
|
|
);
|
|
}
|
|
|
|
export function isScopedEmptyHistoryRequest(params: {
|
|
chatId: string;
|
|
scope?: string | null;
|
|
}) {
|
|
const scope = String(params.scope || "")
|
|
.trim()
|
|
.toLowerCase();
|
|
return (
|
|
EMPTY_HISTORY_SCOPES.has(scope) && isValidMessagesChatId(params.chatId)
|
|
);
|
|
}
|