Skip to content
Source
Sign inSign up
Open History to see the last commit

TimelineUserMessageRow.logic.ts

29 lines1.3 KB

1import { type ChatFileAttachment, type ChatImageAttachment } from "../../types";
2import type { ComposerContextRecord, KnownComposerContextRecord } from "@t3tools/contracts";
3import { asKnownContextRecord } from "~/lib/composerContextRecords";
4​
5export function userMessageFileLabel(file: Pick<ChatFileAttachment, "name" | "source">) {
6 return file.source?._tag === "pasted-text" ? "Pasted text" : file.name;
7}
8​
9export function resolvePreviewAnnotationImage(input: {
10 record: Extract<KnownComposerContextRecord, { kind: "preview-annotation" }>;
11 recordsById: ReadonlyMap<string, ComposerContextRecord>;
12 userImages: ReadonlyArray<ChatImageAttachment>;
13 previewImages: ReadonlyArray<ChatImageAttachment>;
14 annotationRecordIds: ReadonlyArray<string>;
15}): ChatImageAttachment | null {
16 const screenshotRecord = input.record.screenshotContextId
17 ? asKnownContextRecord(input.recordsById.get(input.record.screenshotContextId))
18 : undefined;
19 return (
20 (screenshotRecord?.kind === "image"
21 ? input.userImages.find((image) => image.id === screenshotRecord.attachmentId)
22 : undefined) ??
23 input.previewImages.find(
24 (image) => image.name === `preview-annotation-${input.record.annotationId}.png`,
25 ) ??
26 input.previewImages[input.annotationRecordIds.indexOf(input.record.contextId)] ??
27 null
28 );