Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(attachments): add helper to resolve attachment URLs

Steven Enamakeldc3ed2bf0a18
diff --git a/app/src/lib/attachments.ts b/app/src/lib/attachments.ts
index ff7890485f..d97024145c 100644
--- a/app/src/lib/attachments.ts
+++ b/app/src/lib/attachments.ts
@@ -306,18 +306,25 @@ export async function validateAndReadFile(
}
/**
- * Compose the final message string by appending `[IMAGE:<data-uri>]` markers
- * for image attachments and `[FILE:<data-uri>]` markers for other supported
- * files after the user's text. The Rust agent harness parses and strips these
- * markers before forwarding clean text and attachment payloads to the provider.
+ * The typed wire form of composer attachments (`ContentPart[]`): an `image`,
+ * `video` or `file` part whose media carries the original as a `data:` URI
+ * plus its name, type and size. Sent next to the message text through the
+ * `attachments` param of `channel.web_chat`, `threads.message_append` and
+ * `threads.edit_message`; the core stages the originals. The text is never
+ * touched, so no `[IMAGE:]`/`[FILE:]` marker is built here.
*/
-export function buildMessageWithAttachments(text: string, attachments: Attachment[]): string {
- if (attachments.length === 0) return text;
- const markers = attachments
- .map(a => `[${a.kind === 'image' ? 'IMAGE' : 'FILE'}:${a.dataUri}]`)
- .filter(marker => marker.length > 0)
- .join(' ');
- return text.trim() ? `${text.trim()} ${markers}` : markers;
+export function attachmentsToParts(attachments: Attachment[]): ContentPart[] {
+ return attachments.map((a): ContentPart => {
+ const media = {
+ url: a.dataUri,
+ contentType: a.mimeType,
+ fileName: a.file.name,
+ sizeBytes: a.originalSizeBytes,
+ };
+ if (a.kind === 'image') return { kind: 'image', media: { ...media, kind: 'image' } };
+ if (a.kind === 'video') return { kind: 'video', media: { ...media, kind: 'video' } };
+ return { kind: 'file', fileName: a.file.name, media: { ...media, kind: 'document' } };
+ });
}
/** Workspace references returned by the core after it has saved originals. */