List GET no longer ships transcripts; consult appends questions after reserve and ignores client history so dual-tab last-write-wins cannot erase messages. Co-authored-by: Cursor <cursoragent@cursor.com>
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
export const CONSULTATION_HISTORY_LIMIT = 12;
|
|
export const CONSULTATION_HISTORY_MESSAGE_CHARS = 4_000;
|
|
|
|
export type ConsultationHistoryMessage = Readonly<{
|
|
role: "user" | "assistant";
|
|
text: string;
|
|
}>;
|
|
|
|
export function consultationHistoryFromStoredMessages(
|
|
messages: unknown,
|
|
options: { excludeRequestId?: string } = {},
|
|
): ConsultationHistoryMessage[] {
|
|
if (!Array.isArray(messages)) return [];
|
|
const rows: ConsultationHistoryMessage[] = [];
|
|
for (const message of messages) {
|
|
if (!message || typeof message !== "object") continue;
|
|
const stored = message as { role?: unknown; text?: unknown; requestId?: unknown };
|
|
if (options.excludeRequestId && stored.requestId === options.excludeRequestId) continue;
|
|
if (stored.role !== "user" && stored.role !== "assistant") continue;
|
|
if (typeof stored.text !== "string" || !stored.text) continue;
|
|
rows.push({
|
|
role: stored.role,
|
|
text: stored.text.slice(0, CONSULTATION_HISTORY_MESSAGE_CHARS),
|
|
});
|
|
}
|
|
return rows.slice(-CONSULTATION_HISTORY_LIMIT);
|
|
}
|