The best way to control Claude Code, Codex and more from any computer or phone
Expand sendTurn attachment handling
Julius Marminge committed
Feb 12, 2026 at 15:33 UTC
760f15f2f94965e2fc653f11225741cd2b6fd870
5 files changed
+76
-51
apps/server/src/codexAppServerManager.test.ts
+5
-3
@@ -114,8 +114,9 @@ describe("sendTurn", () => {
114
const result = await manager.sendTurn({
115
sessionId: "sess_1",
116
input: "Inspect this image",
117
- images: [
117
+ attachments: [
118
{
119
+ type: "image",
120
name: "error.png",
121
mimeType: "image/png",
122
sizeBytes: 1_024,
@@ -158,8 +159,9 @@ describe("sendTurn", () => {
159
160
await manager.sendTurn({
161
sessionId: "sess_1",
161
- images: [
162
+ attachments: [
163
{
164
+ type: "image",
165
name: "diagram.png",
166
mimeType: "image/png",
167
sizeBytes: 256,
@@ -186,6 +188,6 @@ describe("sendTurn", () => {
188
manager.sendTurn({
189
sessionId: "sess_1",
190
}),
189
- ).rejects.toThrow("Turn input must include text or image attachments.");
191
+ ).rejects.toThrow("Turn input must include text or attachments.");
192
});
193
});
apps/server/src/codexAppServerManager.ts
+8
-6
@@ -268,14 +268,16 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
268
text_elements: [],
269
});
270
}
271
- for (const image of input.images ?? []) {
272
- turnInput.push({
273
- type: "image",
274
- url: image.dataUrl,
275
- });
271
+ for (const attachment of input.attachments ?? []) {
272
+ if (attachment.type === "image") {
273
+ turnInput.push({
274
+ type: "image",
275
+ url: attachment.dataUrl,
276
+ });
277
+ }
278
}
279
if (turnInput.length === 0) {
278
- throw new Error("Turn input must include text or image attachments.");
280
+ throw new Error("Turn input must include text or attachments.");
281
}
282
283
const turnStartParams: {
apps/web/src/components/ChatView.tsx
+8
-7
@@ -1,8 +1,8 @@
1
import {
2
PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
3
+ PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
4
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
4
- PROVIDER_SEND_TURN_MAX_IMAGES,
5
- type ProviderSendTurnImageInput,
5
+ type ProviderSendTurnAttachmentInput,
6
type ProviderApprovalDecision,
7
type ProviderEvent,
8
} from "@t3tools/contracts";
@@ -541,8 +541,8 @@ export default function ChatView() {
541
error = `'${file.name}' exceeds the ${IMAGE_SIZE_LIMIT_LABEL} attachment limit.`;
542
continue;
543
}
544
- if (nextImages.length >= PROVIDER_SEND_TURN_MAX_IMAGES) {
545
- error = `You can attach up to ${PROVIDER_SEND_TURN_MAX_IMAGES} images per message.`;
544
+ if (nextImages.length >= PROVIDER_SEND_TURN_MAX_ATTACHMENTS) {
545
+ error = `You can attach up to ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS} images per message.`;
546
break;
547
}
548
@@ -772,8 +772,9 @@ export default function ChatView() {
772
773
setIsSending(true);
774
try {
775
- const turnImages = await Promise.all(
776
- composerImagesSnapshot.map(async (image): Promise<ProviderSendTurnImageInput> => ({
775
+ const turnAttachments = await Promise.all(
776
+ composerImagesSnapshot.map(async (image): Promise<ProviderSendTurnAttachmentInput> => ({
777
+ type: "image",
778
name: image.name,
779
mimeType: image.mimeType,
780
sizeBytes: image.sizeBytes,
@@ -794,7 +795,7 @@ export default function ChatView() {
795
await api.providers.sendTurn({
796
sessionId: sessionInfo.sessionId,
797
...(input ? { input } : {}),
797
- ...(turnImages.length > 0 ? { images: turnImages } : {}),
798
+ ...(turnAttachments.length > 0 ? { attachments: turnAttachments } : {}),
799
model: selectedModel || undefined,
800
effort: selectedEffort || undefined,
801
});
packages/contracts/src/provider.test.ts
+11
-8
@@ -1,7 +1,7 @@
1
import { describe, expect, it } from "vitest";
2
3
import {
4
- PROVIDER_SEND_TURN_MAX_IMAGES,
4
+ PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
5
providerEventSchema,
6
providerRespondToRequestInputSchema,
7
providerSendTurnInputSchema,
@@ -41,7 +41,7 @@ describe("providerSendTurnInputSchema", () => {
41
effort: " high ",
42
});
43
expect(parsed.input).toBe("summarize this repo");
44
- expect(parsed.images).toEqual([]);
44
+ expect(parsed.attachments).toEqual([]);
45
expect(parsed.model).toBe("gpt-5.2-codex");
46
expect(parsed.effort).toBe("high");
47
});
@@ -49,8 +49,9 @@ describe("providerSendTurnInputSchema", () => {
49
it("accepts image-only turns", () => {
50
const parsed = providerSendTurnInputSchema.parse({
51
sessionId: "sess_1",
52
- images: [
52
+ attachments: [
53
{
54
+ type: "image",
55
name: "diagram.png",
56
mimeType: "image/png",
57
sizeBytes: 1_024,
@@ -59,10 +60,10 @@ describe("providerSendTurnInputSchema", () => {
60
],
61
});
62
expect(parsed.input).toBeUndefined();
62
- expect(parsed.images).toHaveLength(1);
63
+ expect(parsed.attachments).toHaveLength(1);
64
});
65
65
- it("rejects turns with neither text nor images", () => {
66
+ it("rejects turns with neither text nor attachments", () => {
67
expect(() =>
68
providerSendTurnInputSchema.parse({
69
sessionId: "sess_1",
@@ -74,8 +75,9 @@ describe("providerSendTurnInputSchema", () => {
75
expect(() =>
76
providerSendTurnInputSchema.parse({
77
sessionId: "sess_1",
77
- images: [
78
+ attachments: [
79
{
80
+ type: "image",
81
name: "not-image.txt",
82
mimeType: "text/plain",
83
sizeBytes: 25,
@@ -86,11 +88,12 @@ describe("providerSendTurnInputSchema", () => {
88
).toThrow();
89
});
90
89
- it("rejects more than the max image count", () => {
91
+ it("rejects more than the max attachment count", () => {
92
expect(() =>
93
providerSendTurnInputSchema.parse({
94
sessionId: "sess_1",
93
- images: Array.from({ length: PROVIDER_SEND_TURN_MAX_IMAGES + 1 }, (_, index) => ({
95
+ attachments: Array.from({ length: PROVIDER_SEND_TURN_MAX_ATTACHMENTS + 1 }, (_, index) => ({
96
+ type: "image" as const,
97
name: `image-${index}.png`,
98
mimeType: "image/png",
99
sizeBytes: 1_024,
packages/contracts/src/provider.ts
+44
-27
@@ -55,43 +55,58 @@ export const providerSessionStartInputSchema = z.object({
55
});
56
57
export const PROVIDER_SEND_TURN_MAX_INPUT_CHARS = 120_000;
58
-export const PROVIDER_SEND_TURN_MAX_IMAGES = 8;
58
+export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;
59
export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;
60
export const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000;
61
62
-export const providerSendTurnImageInputSchema = z
63
- .object({
64
- name: z.string().trim().min(1).max(255),
65
- mimeType: z
66
- .string()
67
- .trim()
68
- .min(1)
69
- .max(100)
70
- .regex(/^image\//i, "mimeType must be an image/* MIME type"),
71
- sizeBytes: z.number().int().min(1).max(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES),
72
- dataUrl: z.string().trim().min(1).max(PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS),
73
- })
74
- .superRefine((value, ctx) => {
75
- if (!value.dataUrl.startsWith("data:image/")) {
76
- ctx.addIssue({
77
- code: z.ZodIssueCode.custom,
78
- message: "Image dataUrl must start with data:image/",
79
- path: ["dataUrl"],
80
- });
81
- }
82
- });
62
+function validateImageDataUrl(value: { dataUrl: string }, ctx: z.RefinementCtx): void {
63
+ if (!value.dataUrl.startsWith("data:image/")) {
64
+ ctx.addIssue({
65
+ code: z.ZodIssueCode.custom,
66
+ message: "Image dataUrl must start with data:image/",
67
+ path: ["dataUrl"],
68
+ });
69
+ }
70
+}
71
+
72
+const providerSendTurnImageAttachmentBaseSchema = z.object({
73
+ type: z.literal("image"),
74
+ name: z.string().trim().min(1).max(255),
75
+ mimeType: z
76
+ .string()
77
+ .trim()
78
+ .min(1)
79
+ .max(100)
80
+ .regex(/^image\//i, "mimeType must be an image/* MIME type"),
81
+ sizeBytes: z.number().int().min(1).max(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES),
82
+ dataUrl: z.string().trim().min(1).max(PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS),
83
+});
84
+
85
+export const providerSendTurnImageAttachmentInputSchema =
86
+ providerSendTurnImageAttachmentBaseSchema.superRefine(validateImageDataUrl);
87
+
88
+export const providerSendTurnAttachmentInputSchema = z.discriminatedUnion("type", [
89
+ providerSendTurnImageAttachmentBaseSchema,
90
+]).superRefine((value, ctx) => {
91
+ if (value.type === "image") {
92
+ validateImageDataUrl(value, ctx);
93
+ }
94
+});
95
96
export const providerSendTurnInputSchema = z.object({
97
sessionId: z.string().min(1),
98
input: z.string().trim().min(1).max(PROVIDER_SEND_TURN_MAX_INPUT_CHARS).optional(),
87
- images: z.array(providerSendTurnImageInputSchema).max(PROVIDER_SEND_TURN_MAX_IMAGES).default([]),
99
+ attachments: z
100
+ .array(providerSendTurnAttachmentInputSchema)
101
+ .max(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)
102
+ .default([]),
103
model: z.string().trim().min(1).optional(),
104
effort: z.string().trim().min(1).optional(),
105
}).superRefine((value, ctx) => {
91
- if (!value.input && value.images.length === 0) {
106
+ if (!value.input && value.attachments.length === 0) {
107
ctx.addIssue({
108
code: z.ZodIssueCode.custom,
94
- message: "Either input text or at least one image is required",
109
+ message: "Either input text or at least one attachment is required",
110
path: ["input"],
111
});
112
}
@@ -144,8 +159,10 @@ export type ProviderApprovalDecision = z.infer<typeof providerApprovalDecisionSc
159
export type ProviderSessionStatus = z.infer<typeof providerSessionStatusSchema>;
160
export type ProviderSession = z.infer<typeof providerSessionSchema>;
161
export type ProviderSessionStartInput = z.input<typeof providerSessionStartInputSchema>;
147
-export type ProviderSendTurnImage = z.infer<typeof providerSendTurnImageInputSchema>;
148
-export type ProviderSendTurnImageInput = z.input<typeof providerSendTurnImageInputSchema>;
162
+export type ProviderSendTurnImageAttachment = z.infer<typeof providerSendTurnImageAttachmentInputSchema>;
163
+export type ProviderSendTurnImageAttachmentInput = z.input<typeof providerSendTurnImageAttachmentInputSchema>;
164
+export type ProviderSendTurnAttachment = z.infer<typeof providerSendTurnAttachmentInputSchema>;
165
+export type ProviderSendTurnAttachmentInput = z.input<typeof providerSendTurnAttachmentInputSchema>;
166
export type ProviderSendTurnInput = z.input<typeof providerSendTurnInputSchema>;
167
export type ProviderTurnStartResult = z.infer<typeof providerTurnStartResultSchema>;
168
export type ProviderInterruptTurnInput = z.input<typeof providerInterruptTurnInputSchema>;