Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Expand sendTurn attachment handling

Julius Marminge760f15f2f949
diff --git a/apps/server/src/codexAppServerManager.test.ts b/apps/server/src/codexAppServerManager.test.ts
index f408970bd..e9d384594 100644
--- a/apps/server/src/codexAppServerManager.test.ts
+++ b/apps/server/src/codexAppServerManager.test.ts
@@ -114,8 +114,9 @@ describe("sendTurn", () => {
const result = await manager.sendTurn({
sessionId: "sess_1",
input: "Inspect this image",
- images: [
+ attachments: [
{
+ type: "image",
name: "error.png",
mimeType: "image/png",
sizeBytes: 1_024,
@@ -158,8 +159,9 @@ describe("sendTurn", () => {
await manager.sendTurn({
sessionId: "sess_1",
- images: [
+ attachments: [
{
+ type: "image",
name: "diagram.png",
mimeType: "image/png",
sizeBytes: 256,
@@ -186,6 +188,6 @@ describe("sendTurn", () => {
manager.sendTurn({
sessionId: "sess_1",
}),
- ).rejects.toThrow("Turn input must include text or image attachments.");
+ ).rejects.toThrow("Turn input must include text or attachments.");
});
});
diff --git a/apps/server/src/codexAppServerManager.ts b/apps/server/src/codexAppServerManager.ts
index 327484d07..0a1d61c09 100644
--- a/apps/server/src/codexAppServerManager.ts
+++ b/apps/server/src/codexAppServerManager.ts
@@ -268,14 +268,16 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
text_elements: [],
});
}
- for (const image of input.images ?? []) {
- turnInput.push({
- type: "image",
- url: image.dataUrl,
- });
+ for (const attachment of input.attachments ?? []) {
+ if (attachment.type === "image") {
+ turnInput.push({
+ type: "image",
+ url: attachment.dataUrl,
+ });
+ }
}
if (turnInput.length === 0) {
- throw new Error("Turn input must include text or image attachments.");
+ throw new Error("Turn input must include text or attachments.");
}
const turnStartParams: {
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index 11542af1d..86d30208c 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -1,8 +1,8 @@
import {
PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
+ PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
- PROVIDER_SEND_TURN_MAX_IMAGES,
- type ProviderSendTurnImageInput,
+ type ProviderSendTurnAttachmentInput,
type ProviderApprovalDecision,
type ProviderEvent,
} from "@t3tools/contracts";
@@ -541,8 +541,8 @@ export default function ChatView() {
error = `'${file.name}' exceeds the ${IMAGE_SIZE_LIMIT_LABEL} attachment limit.`;
continue;
}
- if (nextImages.length >= PROVIDER_SEND_TURN_MAX_IMAGES) {
- error = `You can attach up to ${PROVIDER_SEND_TURN_MAX_IMAGES} images per message.`;
+ if (nextImages.length >= PROVIDER_SEND_TURN_MAX_ATTACHMENTS) {
+ error = `You can attach up to ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS} images per message.`;
break;
}
@@ -772,8 +772,9 @@ export default function ChatView() {
setIsSending(true);
try {
- const turnImages = await Promise.all(
- composerImagesSnapshot.map(async (image): Promise<ProviderSendTurnImageInput> => ({
+ const turnAttachments = await Promise.all(
+ composerImagesSnapshot.map(async (image): Promise<ProviderSendTurnAttachmentInput> => ({
+ type: "image",
name: image.name,
mimeType: image.mimeType,
sizeBytes: image.sizeBytes,
@@ -794,7 +795,7 @@ export default function ChatView() {
await api.providers.sendTurn({
sessionId: sessionInfo.sessionId,
...(input ? { input } : {}),
- ...(turnImages.length > 0 ? { images: turnImages } : {}),
+ ...(turnAttachments.length > 0 ? { attachments: turnAttachments } : {}),
model: selectedModel || undefined,
effort: selectedEffort || undefined,
});
diff --git a/packages/contracts/src/provider.test.ts b/packages/contracts/src/provider.test.ts
index b9af9633c..e2ccd990b 100644
--- a/packages/contracts/src/provider.test.ts
+++ b/packages/contracts/src/provider.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import {
- PROVIDER_SEND_TURN_MAX_IMAGES,
+ PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
providerEventSchema,
providerRespondToRequestInputSchema,
providerSendTurnInputSchema,
@@ -41,7 +41,7 @@ describe("providerSendTurnInputSchema", () => {
effort: " high ",
});
expect(parsed.input).toBe("summarize this repo");
- expect(parsed.images).toEqual([]);
+ expect(parsed.attachments).toEqual([]);
expect(parsed.model).toBe("gpt-5.2-codex");
expect(parsed.effort).toBe("high");
});
@@ -49,8 +49,9 @@ describe("providerSendTurnInputSchema", () => {
it("accepts image-only turns", () => {
const parsed = providerSendTurnInputSchema.parse({
sessionId: "sess_1",
- images: [
+ attachments: [
{
+ type: "image",
name: "diagram.png",
mimeType: "image/png",
sizeBytes: 1_024,
@@ -59,10 +60,10 @@ describe("providerSendTurnInputSchema", () => {
],
});
expect(parsed.input).toBeUndefined();
- expect(parsed.images).toHaveLength(1);
+ expect(parsed.attachments).toHaveLength(1);
});
- it("rejects turns with neither text nor images", () => {
+ it("rejects turns with neither text nor attachments", () => {
expect(() =>
providerSendTurnInputSchema.parse({
sessionId: "sess_1",
@@ -74,8 +75,9 @@ describe("providerSendTurnInputSchema", () => {
expect(() =>
providerSendTurnInputSchema.parse({
sessionId: "sess_1",
- images: [
+ attachments: [
{
+ type: "image",
name: "not-image.txt",
mimeType: "text/plain",
sizeBytes: 25,
@@ -86,11 +88,12 @@ describe("providerSendTurnInputSchema", () => {
).toThrow();
});
- it("rejects more than the max image count", () => {
+ it("rejects more than the max attachment count", () => {
expect(() =>
providerSendTurnInputSchema.parse({
sessionId: "sess_1",
- images: Array.from({ length: PROVIDER_SEND_TURN_MAX_IMAGES + 1 }, (_, index) => ({
+ attachments: Array.from({ length: PROVIDER_SEND_TURN_MAX_ATTACHMENTS + 1 }, (_, index) => ({
+ type: "image" as const,
name: `image-${index}.png`,
mimeType: "image/png",
sizeBytes: 1_024,
diff --git a/packages/contracts/src/provider.ts b/packages/contracts/src/provider.ts
index 9604b9ddf..66dcaf18c 100644
--- a/packages/contracts/src/provider.ts
+++ b/packages/contracts/src/provider.ts
@@ -55,43 +55,58 @@ export const providerSessionStartInputSchema = z.object({
});
export const PROVIDER_SEND_TURN_MAX_INPUT_CHARS = 120_000;
-export const PROVIDER_SEND_TURN_MAX_IMAGES = 8;
+export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;
export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;
export const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000;
-export const providerSendTurnImageInputSchema = z
- .object({
- name: z.string().trim().min(1).max(255),
- mimeType: z
- .string()
- .trim()
- .min(1)
- .max(100)
- .regex(/^image\//i, "mimeType must be an image/* MIME type"),
- sizeBytes: z.number().int().min(1).max(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES),
- dataUrl: z.string().trim().min(1).max(PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS),
- })
- .superRefine((value, ctx) => {
- if (!value.dataUrl.startsWith("data:image/")) {
- ctx.addIssue({
- code: z.ZodIssueCode.custom,
- message: "Image dataUrl must start with data:image/",
- path: ["dataUrl"],
- });
- }
- });
+function validateImageDataUrl(value: { dataUrl: string }, ctx: z.RefinementCtx): void {
+ if (!value.dataUrl.startsWith("data:image/")) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "Image dataUrl must start with data:image/",
+ path: ["dataUrl"],
+ });
+ }
+}
+
+const providerSendTurnImageAttachmentBaseSchema = z.object({
+ type: z.literal("image"),
+ name: z.string().trim().min(1).max(255),
+ mimeType: z
+ .string()
+ .trim()
+ .min(1)
+ .max(100)
+ .regex(/^image\//i, "mimeType must be an image/* MIME type"),
+ sizeBytes: z.number().int().min(1).max(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES),
+ dataUrl: z.string().trim().min(1).max(PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS),
+});
+
+export const providerSendTurnImageAttachmentInputSchema =
+ providerSendTurnImageAttachmentBaseSchema.superRefine(validateImageDataUrl);
+
+export const providerSendTurnAttachmentInputSchema = z.discriminatedUnion("type", [
+ providerSendTurnImageAttachmentBaseSchema,
+]).superRefine((value, ctx) => {
+ if (value.type === "image") {
+ validateImageDataUrl(value, ctx);
+ }
+});
export const providerSendTurnInputSchema = z.object({
sessionId: z.string().min(1),
input: z.string().trim().min(1).max(PROVIDER_SEND_TURN_MAX_INPUT_CHARS).optional(),
- images: z.array(providerSendTurnImageInputSchema).max(PROVIDER_SEND_TURN_MAX_IMAGES).default([]),
+ attachments: z
+ .array(providerSendTurnAttachmentInputSchema)
+ .max(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)
+ .default([]),
model: z.string().trim().min(1).optional(),
effort: z.string().trim().min(1).optional(),
}).superRefine((value, ctx) => {
- if (!value.input && value.images.length === 0) {
+ if (!value.input && value.attachments.length === 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
- message: "Either input text or at least one image is required",
+ message: "Either input text or at least one attachment is required",
path: ["input"],
});
}
@@ -144,8 +159,10 @@ export type ProviderApprovalDecision = z.infer<typeof providerApprovalDecisionSc
export type ProviderSessionStatus = z.infer<typeof providerSessionStatusSchema>;
export type ProviderSession = z.infer<typeof providerSessionSchema>;
export type ProviderSessionStartInput = z.input<typeof providerSessionStartInputSchema>;
-export type ProviderSendTurnImage = z.infer<typeof providerSendTurnImageInputSchema>;
-export type ProviderSendTurnImageInput = z.input<typeof providerSendTurnImageInputSchema>;
+export type ProviderSendTurnImageAttachment = z.infer<typeof providerSendTurnImageAttachmentInputSchema>;
+export type ProviderSendTurnImageAttachmentInput = z.input<typeof providerSendTurnImageAttachmentInputSchema>;
+export type ProviderSendTurnAttachment = z.infer<typeof providerSendTurnAttachmentInputSchema>;
+export type ProviderSendTurnAttachmentInput = z.input<typeof providerSendTurnAttachmentInputSchema>;
export type ProviderSendTurnInput = z.input<typeof providerSendTurnInputSchema>;
export type ProviderTurnStartResult = z.infer<typeof providerTurnStartResultSchema>;
export type ProviderInterruptTurnInput = z.input<typeof providerInterruptTurnInputSchema>;