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 25, 19:45 UTC
Allow attachments field in ChatView
Julius Marminge committed
Feb 12, 2026 at 15:37 UTC
1cad53dae43aa9d719e190f88f2a3e1ce549942a
7 files changed
+42
-29
apps/web/src/components/ChatView.tsx
+5
-3
@@ -548,6 +548,7 @@ export default function ChatView() {
548
549
const previewUrl = URL.createObjectURL(file);
550
nextImages.push({
551
+ type: "image",
552
id: crypto.randomUUID(),
553
name: file.name || "image",
554
mimeType: file.type,
@@ -749,7 +750,8 @@ export default function ChatView() {
750
}
751
752
setThreadError(activeThread.id, null);
752
- const messageImages: ChatImageAttachment[] = composerImagesSnapshot.map((image) => ({
753
+ const messageAttachments: ChatImageAttachment[] = composerImagesSnapshot.map((image) => ({
754
+ type: "image",
755
id: image.id,
756
name: image.name,
757
mimeType: image.mimeType,
@@ -761,7 +763,7 @@ export default function ChatView() {
763
threadId: activeThread.id,
764
id: crypto.randomUUID(),
765
text: trimmed,
764
- ...(messageImages.length > 0 ? { images: messageImages } : {}),
766
+ ...(messageAttachments.length > 0 ? { attachments: messageAttachments } : {}),
767
});
768
const previousMessages = activeThread.messages;
769
setPrompt("");
@@ -1106,7 +1108,7 @@ export default function ChatView() {
1108
}
1109
1110
if (timelineEntry.message.role === "user") {
1109
- const userImages = timelineEntry.message.images ?? [];
1111
+ const userImages = timelineEntry.message.attachments ?? [];
1112
return (
1113
<Fragment key={timelineEntry.id}>
1114
<div className="flex justify-end">
apps/web/src/historyBootstrap.test.ts
+2
-1
@@ -99,8 +99,9 @@ describe("buildBootstrapInput", () => {
99
id: "u-image",
100
role: "user",
101
text: "",
102
- images: [
102
+ attachments: [
103
{
104
+ type: "image",
105
id: "img-1",
106
name: "screenshot.png",
107
mimeType: "image/png",
apps/web/src/historyBootstrap.ts
+9
-8
@@ -18,13 +18,14 @@ function messageRoleLabel(message: ChatMessage): "USER" | "ASSISTANT" {
18
return message.role === "assistant" ? "ASSISTANT" : "USER";
19
}
20
21
-function imageSummary(message: ChatMessage): string | null {
22
- const count = message.images?.length ?? 0;
21
+function attachmentSummary(message: ChatMessage): string | null {
22
+ const imageAttachments = message.attachments?.filter((attachment) => attachment.type === "image");
23
+ const count = imageAttachments?.length ?? 0;
24
if (count === 0) {
25
return null;
26
}
27
27
- const names = message.images?.slice(0, 3).map((image) => image.name) ?? [];
28
+ const names = imageAttachments?.slice(0, 3).map((image) => image.name) ?? [];
29
const namesSummary = names.join(", ");
30
const extraCount = count - names.length;
31
const extraSummary = extraCount > 0 ? ` (+${extraCount} more)` : "";
@@ -33,16 +34,16 @@ function imageSummary(message: ChatMessage): string | null {
34
35
function buildMessageBlock(message: ChatMessage): string {
36
const text = message.text;
36
- const images = imageSummary(message);
37
+ const attachments = attachmentSummary(message);
38
38
- if (text && images) {
39
- return `${messageRoleLabel(message)}:\n${text}\n${images}`;
39
+ if (text && attachments) {
40
+ return `${messageRoleLabel(message)}:\n${text}\n${attachments}`;
41
}
42
if (text) {
43
return `${messageRoleLabel(message)}:\n${text}`;
44
}
44
- if (images) {
45
- return `${messageRoleLabel(message)}:\n${images}`;
45
+ if (attachments) {
46
+ return `${messageRoleLabel(message)}:\n${attachments}`;
47
}
48
return `${messageRoleLabel(message)}:\n(empty message)`;
49
}
apps/web/src/persistenceSchema.test.ts
+4
-2
@@ -200,8 +200,9 @@ describe("toPersistedState", () => {
200
id: "m-1",
201
role: "user",
202
text: "Hi",
203
- images: [
203
+ attachments: [
204
{
205
+ type: "image",
206
id: "img-1",
207
name: "diagram.png",
208
mimeType: "image/png",
@@ -250,8 +251,9 @@ describe("toPersistedState", () => {
251
id: "m-1",
252
role: "user",
253
text: "Hi",
253
- images: [
254
+ attachments: [
255
{
256
+ type: "image",
257
id: "img-1",
258
name: "diagram.png",
259
mimeType: "image/png",
apps/web/src/persistenceSchema.ts
+13
-11
@@ -23,9 +23,10 @@ const persistedMessageSchema = z.object({
23
id: z.string().min(1),
24
role: z.enum(["user", "assistant"]),
25
text: z.string(),
26
- images: z
26
+ attachments: z
27
.array(
28
z.object({
29
+ type: z.literal("image"),
30
id: z.string().min(1),
31
name: z.string().min(1),
32
mimeType: z.string().min(1),
@@ -137,14 +138,14 @@ function hydrateThread(
138
terminalHeight: thread.terminalHeight ?? DEFAULT_THREAD_TERMINAL_HEIGHT,
139
session: null,
140
messages: thread.messages.map((message) => {
140
- const hydratedImages = message.images?.map((image) => ({
141
- ...image,
142
- }));
141
+ const hydratedAttachments = message.attachments?.map((attachment) => ({ ...attachment }));
142
return {
143
id: message.id,
144
role: message.role,
145
text: message.text,
147
- ...(hydratedImages && hydratedImages.length > 0 ? { images: hydratedImages } : {}),
146
+ ...(hydratedAttachments && hydratedAttachments.length > 0
147
+ ? { attachments: hydratedAttachments }
148
+ : {}),
149
createdAt: message.createdAt,
150
streaming: false,
151
};
@@ -212,13 +213,14 @@ export function toPersistedState(
213
id: message.id,
214
role: message.role,
215
text: message.text,
215
- ...(message.images && message.images.length > 0
216
+ ...(message.attachments && message.attachments.length > 0
217
? {
217
- images: message.images.map((image) => ({
218
- id: image.id,
219
- name: image.name,
220
- mimeType: image.mimeType,
221
- sizeBytes: image.sizeBytes,
218
+ attachments: message.attachments.map((attachment) => ({
219
+ type: attachment.type,
220
+ id: attachment.id,
221
+ name: attachment.name,
222
+ mimeType: attachment.mimeType,
223
+ sizeBytes: attachment.sizeBytes,
224
})),
225
}
226
: {}),
apps/web/src/store.ts
+5
-3
@@ -13,7 +13,7 @@ import { resolveModelSlug } from "./model-logic";
13
import { hydratePersistedState, toPersistedState } from "./persistenceSchema";
14
import { applyEventToMessages, asObject, asString, evolveSession } from "./session-logic";
15
import {
16
- type ChatImageAttachment,
16
+ type ChatAttachment,
17
DEFAULT_RUNTIME_MODE,
18
type Project,
19
type RuntimeMode,
@@ -43,7 +43,7 @@ type Action =
43
threadId: string;
44
id: string;
45
text: string;
46
- images?: ChatImageAttachment[];
46
+ attachments?: ChatAttachment[];
47
}
48
| { type: "SET_ERROR"; threadId: string; error: string | null }
49
| { type: "SET_THREAD_TITLE"; threadId: string; title: string }
@@ -387,7 +387,9 @@ export function reducer(state: AppState, action: Action): AppState {
387
id: action.id,
388
role: "user" as const,
389
text: action.text,
390
- ...(action.images && action.images.length > 0 ? { images: action.images } : {}),
390
+ ...(action.attachments && action.attachments.length > 0
391
+ ? { attachments: action.attachments }
392
+ : {}),
393
createdAt: new Date().toISOString(),
394
streaming: false,
395
},
apps/web/src/types.ts
+4
-1
@@ -6,6 +6,7 @@ export const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access";
6
export const DEFAULT_THREAD_TERMINAL_HEIGHT = 280;
7
8
export interface ChatImageAttachment {
9
+ type: "image";
10
id: string;
11
name: string;
12
mimeType: string;
@@ -13,11 +14,13 @@ export interface ChatImageAttachment {
14
previewUrl?: string;
15
}
16
17
+export type ChatAttachment = ChatImageAttachment;
18
+
19
export interface ChatMessage {
20
id: string;
21
role: "user" | "assistant";
22
text: string;
20
- images?: ChatImageAttachment[];
23
+ attachments?: ChatAttachment[];
24
createdAt: string;
25
streaming: boolean;
26
}