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

main
ts 36 lines 1.29 KB
Raw
1 export interface SentImageHandoff {
2 readonly uri: string;
3 readonly aspectRatio: number;
4 }
5
6 // A sent image's local pixels and shape, so the pending bubble and then the delivered copy open at
7 // their final size over pixels already on screen instead of a placeholder that later resizes.
8 // The server re-ids attachments into the thread, so delivered images match by message and position.
9 const MAX_ENTRIES = 64;
10 const images = new Map<string, SentImageHandoff>();
11
12 function remember(key: string, image: SentImageHandoff) {
13 if (!Number.isFinite(image.aspectRatio) || image.aspectRatio <= 0) return;
14 images.delete(key);
15 images.set(key, image);
16 if (images.size > MAX_ENTRIES) images.delete(images.keys().next().value!);
17 }
18
19 export function rememberDraftImage(attachmentId: string, image: SentImageHandoff): void {
20 remember(`draft:${attachmentId}`, image);
21 }
22
23 export function rememberSentImage(messageId: string, index: number, image: SentImageHandoff): void {
24 remember(`message:${messageId}:${index}`, image);
25 }
26
27 export function sentImageHandoff(
28 messageId: string,
29 index: number,
30 draftAttachmentId?: string,
31 ): SentImageHandoff | undefined {
32 return (
33 images.get(`message:${messageId}:${index}`) ??
34 (draftAttachmentId === undefined ? undefined : images.get(`draft:${draftAttachmentId}`))
35 );
36 }