shitton of the ai changes

This commit is contained in:
2026-05-01 04:54:11 +03:00
parent d95c37a322
commit 8cff086a8e
194 changed files with 29409 additions and 8841 deletions
+66
View File
@@ -0,0 +1,66 @@
import {DatabaseManager} from "../db/database-manager";
import type {AttachmentDbRow} from "../db/db-types";
import type {StoredAttachment} from "../model/stored-attachment";
function toAttachmentRow(input: {
messageChatId: number;
messageId: number;
attachment: StoredAttachment;
direction: string;
createdAt: string;
ordinal: number;
}): AttachmentDbRow {
const attachment = input.attachment;
const idSource = [
input.messageChatId,
input.messageId,
input.direction,
attachment.scope ?? "user_input",
attachment.kind,
attachment.fileUniqueId ?? attachment.fileId,
attachment.fileName,
attachment.cachePath,
attachment.artifactKind ?? "",
input.ordinal,
].join(":");
return {
id: idSource,
messageChatId: input.messageChatId,
messageId: input.messageId,
direction: input.direction,
scope: attachment.scope ?? "user_input",
kind: attachment.kind,
artifactKind: attachment.artifactKind ?? null,
fileId: attachment.fileId,
fileUniqueId: attachment.fileUniqueId ?? null,
fileName: attachment.fileName,
mimeType: attachment.mimeType ?? null,
cachePath: attachment.cachePath,
sizeBytes: attachment.sizeBytes ?? null,
sha256: attachment.sha256 ?? null,
metadata: attachment.metadata ? JSON.stringify(attachment.metadata) : null,
createdAt: input.createdAt,
};
}
export class AttachmentStore {
static async putMessageAttachments(params: {
messageChatId: number;
messageId: number;
attachments: StoredAttachment[];
direction?: string;
createdAt?: string;
}): Promise<void> {
const rows = params.attachments.map((attachment, ordinal) => toAttachmentRow({
messageChatId: params.messageChatId,
messageId: params.messageId,
attachment,
direction: params.direction ?? (attachment.scope === "bot_output" ? "output" : "input"),
createdAt: params.createdAt ?? new Date().toISOString(),
ordinal,
}));
await DatabaseManager.upsertAttachments(rows);
}
}