@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 34 lines 1.44 KB
Raw
1 import { type ChatFileAttachment, type ChatImageAttachment } from "../../types";
2 import type { ComposerContextRecord, KnownComposerContextRecord } from "@t3tools/contracts";
3 import { msg } from "gt-react";
4 import { m, type MessageResolver } from "~/i18n/messages";
5 import { asKnownContextRecord } from "~/lib/composerContextRecords";
6
7 export 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 export function resolvePreviewAnnotationImage(input: {
15 record: Extract<KnownComposerContextRecord, { kind: "preview-annotation" }>;
16 recordsById: ReadonlyMap<string, ComposerContextRecord>;
17 userImages: ReadonlyArray<ChatImageAttachment>;
18 previewImages: ReadonlyArray<ChatImageAttachment>;
19 annotationRecordIds: ReadonlyArray<string>;
20 }): ChatImageAttachment | null {
21 const screenshotRecord = input.record.screenshotContextId
22 ? asKnownContextRecord(input.recordsById.get(input.record.screenshotContextId))
23 : undefined;
24 return (
25 (screenshotRecord?.kind === "image"
26 ? input.userImages.find((image) => image.id === screenshotRecord.attachmentId)
27 : undefined) ??
28 input.previewImages.find(
29 (image) => image.name === `preview-annotation-${input.record.annotationId}.png`,
30 ) ??
31 input.previewImages[input.annotationRecordIds.indexOf(input.record.contextId)] ??
32 null
33 );
34 }