Skip to content

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

feat(attachments): add attachment support to thread API and store

Steven Enamakel5087612412f4
diff --git a/app/src/lib/attachments.ts b/app/src/lib/attachments.ts
index d97024145c..8ab5f80f02 100644
--- a/app/src/lib/attachments.ts
+++ b/app/src/lib/attachments.ts
@@ -1,13 +1,16 @@
/**
* Utilities for multimodal chat attachments.
*
- * Images are embedded as `[IMAGE:<data-uri>]` markers. Other files
- * are embedded as `[FILE:<data-uri>]` markers. The Rust agent harness
- * (`agent/multimodal.rs`) parses, validates, and expands both shapes before
- * the provider call.
+ * Originals travel as typed `ContentPart`s ({@link attachmentsToParts}) next to
+ * the message text; the core stages them and returns durable
+ * `[ATTACHMENT:…]` references, which {@link parseAttachmentReferences} reads
+ * back for display. The `[IMAGE:]`/`[FILE:]` marker grammar is an internal
+ * staging format of the core and is no longer built here.
*/
import debugFactory from 'debug';
+import type { ContentPart } from '../services/chatWire';
+
const debug = debugFactory('chat:attachments');
const ALLOWED_IMAGE_MIME_TYPES = [
diff --git a/app/src/services/api/threadApi.ts b/app/src/services/api/threadApi.ts
index c797c32d0c..6a139b01b4 100644
--- a/app/src/services/api/threadApi.ts
+++ b/app/src/services/api/threadApi.ts
@@ -94,10 +94,18 @@ export const threadApi = {
return unwrapEnvelope(response)?.hits ?? [];
},
- appendMessage: async (threadId: string, message: ThreadMessage): Promise<ThreadMessage> => {
+ appendMessage: async (
+ threadId: string,
+ message: ThreadMessage,
+ attachments?: ContentPart[]
+ ): Promise<ThreadMessage> => {
const response = await callCoreRpc<Envelope<ThreadMessage>>({
method: 'openhuman.threads_message_append',
- params: { thread_id: threadId, message },
+ params: {
+ thread_id: threadId,
+ message,
+ ...(attachments && attachments.length > 0 ? { attachments } : {}),
+ },
});
return normalizeThreadMessage(unwrapEnvelope(response));
},
diff --git a/app/src/store/threadSlice.ts b/app/src/store/threadSlice.ts
index 990fbfe741..678948b5e1 100644
--- a/app/src/store/threadSlice.ts
+++ b/app/src/store/threadSlice.ts
@@ -252,9 +252,16 @@ async function evictStaleThread(threadId: string, dispatch: (action: any) => any
export const addMessageLocal = createAsyncThunk(
'thread/addMessageLocal',
- async (payload: { threadId: string; message: ThreadMessage }, { dispatch, rejectWithValue }) => {
+ async (
+ payload: { threadId: string; message: ThreadMessage; attachments?: ContentPart[] },
+ { dispatch, rejectWithValue }
+ ) => {
try {
- const persisted = await threadApi.appendMessage(payload.threadId, payload.message);
+ const persisted = await threadApi.appendMessage(
+ payload.threadId,
+ payload.message,
+ payload.attachments
+ );
if (payload.message.sender === 'user' && payload.message.content.trim()) {
void dispatch(generateThreadTitleIfNeeded({ threadId: payload.threadId }))
.unwrap()