Skip to content

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

feat(store): allow attachments when editing a message

Steven Enamakel415047b0579e
diff --git a/app/src/providers/useOpenHumanExternalStore.ts b/app/src/providers/useOpenHumanExternalStore.ts
index 934f5f86cc..3a70b7e38f 100644
--- a/app/src/providers/useOpenHumanExternalStore.ts
+++ b/app/src/providers/useOpenHumanExternalStore.ts
@@ -655,15 +655,24 @@ export function useOpenHumanExternalStore(
if (!messageId) {
throw new Error('Edit is missing the source message id');
}
+ const sourceRow = messages.find(row => row.id === messageId);
const text = `${appendMessageQuote(message)}${appendMessageText(message)}`;
// Truncate the local cache FIRST: the edit RPC returns no message list,
// and the socket events that follow (`inference_start` … `chat_done`)
// only carry the new turn, so a reader would still see the discarded
// replies until the next full refetch if this waited on the RPC.
dispatch(truncateMessagesFrom({ threadId, messageId, inclusive: true }));
- await editMessage({ threadId, messageId, content: text });
+ await editMessage({
+ threadId,
+ messageId,
+ content: text,
+ // Keep the source row's media when editing its text. The core accepts
+ // only these opaque refs, validates them against this exact row, and
+ // stages fresh ownership before truncating history.
+ attachments: sourceRow?.attachments?.length ? sourceRow.attachments : undefined,
+ });
},
- [dispatch, threadId]
+ [dispatch, messages, threadId]
);
/**
diff --git a/crates/openhuman-core/src/threads/attachments.rs b/crates/openhuman-core/src/threads/attachments.rs
index cd7d3280fb..b220bc3fd6 100644
--- a/crates/openhuman-core/src/threads/attachments.rs
+++ b/crates/openhuman-core/src/threads/attachments.rs
@@ -23,6 +23,10 @@ pub(crate) use staged::{
validate_opaque_parts,
};
+pub(crate) fn has_opaque_ref(part: &ContentPart) -> bool {
+ opaque_media(part).is_some_and(|media| media.opaque_id.is_some())
+}
+
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct StoredAttachment {
diff --git a/crates/openhuman-core/src/threads/ops/edit.rs b/crates/openhuman-core/src/threads/ops/edit.rs
index b63aef9ddb..9b73d42a4e 100644
--- a/crates/openhuman-core/src/threads/ops/edit.rs
+++ b/crates/openhuman-core/src/threads/ops/edit.rs
@@ -117,8 +117,7 @@ pub async fn edit_message(
.await
.map_err(ThreadsError::Message)?;
let has_existing_refs = request.attachments.iter().any(|part| {
- crate::threads::attachments::opaque_media(part)
- .is_some_and(|media| media.opaque_id.is_some())
+ crate::threads::attachments::has_opaque_ref(part)
});
let staged_parts = if request.attachments.is_empty() {
Vec::new()