Open History to see the last commit
1import { type ChatFileAttachment, type ChatImageAttachment } from "../../types";
2import type { ComposerContextRecord, KnownComposerContextRecord } from "@t3tools/contracts";
3import { msg } from "gt-react";
4import { m, type MessageResolver } from "~/i18n/messages";
5import { asKnownContextRecord } from "~/lib/composerContextRecords";
6
7export function userMessageFileLabel(
8 file: Pick<ChatFileAttachment, "name" | "source">,
9 resolve: MessageResolver = m,
10) {
11 return file.source?._tag === "pasted-text" ? resolve(msg("Pasted text")) : file.name;
12}
13
14/** An annotation owns only the screenshot its record names; messages from before structured context matched by file name. */
15export function resolvePreviewAnnotationImage(input: {
16 record: Extract<KnownComposerContextRecord, { kind: "preview-annotation" }>;
17 recordsById: ReadonlyMap<string, ComposerContextRecord>;
18 userImages: ReadonlyArray<ChatImageAttachment>;
19 legacy: boolean;
20}): ChatImageAttachment | null {
21 if (input.record.screenshotContextId) {
22 const screenshotRecord = asKnownContextRecord(
23 input.recordsById.get(input.record.screenshotContextId),
24 );
25 return screenshotRecord?.kind === "image"
26 ? (input.userImages.find((image) => image.id === screenshotRecord.attachmentId) ?? null)
27 : null;
28 }
29 if (!input.legacy) return null;
30 return (
31 input.userImages.find(
32 (image) => image.name === `preview-annotation-${input.record.annotationId}.png`,
33 ) ?? null
34 );
35}