feat: implement API key authentication and user session management
Some checks failed
CI / Typecheck & Lint (push) Has been cancelled

This commit is contained in:
nirholas
2026-03-31 12:43:05 +00:00
parent da6c5e1ed7
commit 3a854557e0
145 changed files with 34693 additions and 690 deletions

45
web/lib/export/json.ts Normal file
View File

@@ -0,0 +1,45 @@
import type { Conversation, Message, ExportOptions, ContentBlock } from "../types";
function filterContent(
content: ContentBlock[] | string,
options: ExportOptions
): ContentBlock[] | string {
if (typeof content === "string") return content;
return content.filter((block) => {
if (block.type === "tool_use" || block.type === "tool_result") {
return options.includeToolUse;
}
return true;
});
}
function filterMessage(msg: Message, options: ExportOptions): Message {
return {
...msg,
content: filterContent(msg.content, options),
createdAt: options.includeTimestamps ? msg.createdAt : 0,
};
}
export function toJSON(conv: Conversation, options: ExportOptions): string {
let messages = conv.messages;
if (options.dateRange) {
const { start, end } = options.dateRange;
messages = messages.filter((m) => m.createdAt >= start && m.createdAt <= end);
}
const output = {
id: conv.id,
title: conv.title,
model: conv.model,
createdAt: options.includeTimestamps ? conv.createdAt : undefined,
updatedAt: options.includeTimestamps ? conv.updatedAt : undefined,
messageCount: messages.length,
messages: messages.map((m) => filterMessage(m, options)),
exportedAt: new Date().toISOString(),
};
return JSON.stringify(output, null, 2);
}