Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion apps/mobile/src/lib/composerImages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,37 @@ vi.mock("./uuid", () => ({
uuidv4: () => "attachment-id",
}));

import { convertPastedImagesToAttachments, isOwnedPastedImageUri } from "./composerImages";
import {
convertPastedImagesToAttachments,
isOwnedPastedImageUri,
toUploadChatImageAttachments,
} from "./composerImages";

describe("toUploadChatImageAttachments", () => {
it("strips client draft id and previewUri for the startTurn wire shape", () => {
expect(
toUploadChatImageAttachments([
{
id: "client-draft-id",
type: "image",
name: "pasted-image.png",
mimeType: "image/png",
sizeBytes: 12,
dataUrl: "data:image/png;base64,AA==",
previewUri: "file:///tmp/preview.png",
},
]),
).toEqual([
{
type: "image",
name: "pasted-image.png",
mimeType: "image/png",
sizeBytes: 12,
dataUrl: "data:image/png;base64,AA==",
},
]);
});
});

describe("native pasted image cleanup", () => {
beforeEach(() => {
Expand Down
13 changes: 13 additions & 0 deletions apps/mobile/src/lib/composerImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ export interface DraftComposerImageAttachment extends UploadChatImageAttachment
readonly previewUri: string;
}

/** Wire shape for startTurn: pure uploads without client draft id / previewUri. */
export function toUploadChatImageAttachments(
attachments: ReadonlyArray<DraftComposerImageAttachment>,
): ReadonlyArray<UploadChatImageAttachment> {
return attachments.map((attachment) => ({
type: attachment.type,
name: attachment.name,
mimeType: attachment.mimeType,
sizeBytes: attachment.sizeBytes,
dataUrl: attachment.dataUrl,
}));
}

const OWNED_PASTED_IMAGE_DIRECTORY = "t3-composer-paste";

function estimateBase64ByteSize(base64: string): number {
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/lib/projectThreadStartTurn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type RuntimeMode,
} from "@t3tools/contracts";

import type { DraftComposerImageAttachment } from "./composerImages";
import { toUploadChatImageAttachments, type DraftComposerImageAttachment } from "./composerImages";

export function deriveThreadTitleFromPrompt(value: string): string {
const trimmed = value.trim();
Expand Down Expand Up @@ -55,7 +55,7 @@ export function buildProjectThreadStartTurnInput(spec: ProjectThreadStartTurnSpe
messageId: MessageId.make(spec.messageId),
role: "user" as const,
text: spec.text,
attachments: spec.attachments,
attachments: toUploadChatImageAttachments(spec.attachments),
Comment thread
juliusmarminge marked this conversation as resolved.
},
modelSelection: spec.modelSelection,
titleSeed: title,
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/src/state/use-thread-outbox-drain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useCallback, useEffect, useRef, useState } from "react";

import { scopedThreadKey } from "../lib/scopedEntities";
import { buildProjectThreadStartTurnInput } from "../lib/projectThreadStartTurn";
import { toUploadChatImageAttachments } from "../lib/composerImages";
import { randomHex } from "../lib/uuid";
import { appAtomRegistry } from "./atom-registry";
import { useProjects, useThreadShells } from "./entities";
Expand Down Expand Up @@ -221,7 +222,7 @@ export function useThreadOutboxDrain(): void {
messageId: queuedMessage.messageId,
role: "user",
text: queuedMessage.text,
attachments: queuedMessage.attachments,
attachments: toUploadChatImageAttachments(queuedMessage.attachments),
},
modelSelection: settings.modelSelection,
runtimeMode: settings.runtimeMode,
Expand Down
Loading