Skip to content

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

feat(chat): support started chat acknowledgements

Steven Enamakele8ce974b64a5
diff --git a/app/src/services/__tests__/chatService.test.ts b/app/src/services/__tests__/chatService.test.ts
index c30b0c8fb3..5fb237ab7b 100644
--- a/app/src/services/__tests__/chatService.test.ts
+++ b/app/src/services/__tests__/chatService.test.ts
@@ -420,7 +420,23 @@ describe('chatService.subscribeChatEvents', () => {
).resolves.toEqual({ requestId: 'request-1', queuedAttachments: attachments });
});
- it('maps the scalar request identity returned for a started turn', async () => {
+ it('maps the started-turn acknowledgement returned by the core', async () => {
+ const socket = createMockSocket();
+ bindMockSocket(socket);
+ mockCallCoreRpc.mockResolvedValue({
+ accepted: true,
+ client_id: 'socket-1',
+ thread_id: 'thread-1',
+ request_id: 'request-started',
+ });
+
+ await expect(chatSendWithAck({ threadId: 'thread-1', message: 'hello' })).resolves.toEqual({
+ requestId: 'request-started',
+ queuedAttachments: [],
+ });
+ });
+
+ it('preserves compatibility with the legacy scalar request identity', async () => {
const socket = createMockSocket();
bindMockSocket(socket);
mockCallCoreRpc.mockResolvedValue('request-started');
diff --git a/app/src/services/chatService.ts b/app/src/services/chatService.ts
index 4bd452d7b4..abfa1c01c0 100644
--- a/app/src/services/chatService.ts
+++ b/app/src/services/chatService.ts
@@ -8,7 +8,7 @@
*/
import debug from 'debug';
-import type { QueuedChatAck } from '../types/threadWire.generated';
+import type { QueuedChatAck, StartedChatAck } from '../types/threadWire.generated';
import {
type ArtifactFailedEvent,
ArtifactKind,
@@ -994,6 +994,16 @@ function isQueuedChatAck(value: unknown): value is QueuedChatAck {
);
}
+function isStartedChatAck(value: unknown): value is StartedChatAck {
+ return (
+ isRecord(value) &&
+ value.accepted === true &&
+ typeof value.client_id === 'string' &&
+ typeof value.thread_id === 'string' &&
+ typeof value.request_id === 'string'
+ );
+}
+
export async function chatSendWithAck(params: ChatSendParams): Promise<ChatSendAck> {
const socket = socketService.getSocket();
const clientId = socket?.id;
@@ -1024,6 +1034,9 @@ export async function chatSendWithAck(params: ChatSendParams): Promise<ChatSendA
if (typeof result === 'string') {
return { requestId: result, queuedAttachments: [] };
}
+ if (isStartedChatAck(result)) {
+ return { requestId: result.request_id, queuedAttachments: [] };
+ }
if (result == null) {
return { queuedAttachments: [] };
}
diff --git a/crates/openhuman-core/src/threads/rpc_models.rs b/crates/openhuman-core/src/threads/rpc_models.rs
index c321d8a66d..af5adc2c76 100644
--- a/crates/openhuman-core/src/threads/rpc_models.rs
+++ b/crates/openhuman-core/src/threads/rpc_models.rs
@@ -10,6 +10,18 @@ use serde::{Deserialize, Serialize};
pub use crate::core::envelope::{ApiEnvelope, ApiError, ApiMeta, EmptyRequest, PaginationMeta};
+/// Typed acknowledgement returned when a web chat message enters the run queue.
+/// Attachment values are sanitized opaque references minted by the core.
+/// Typed acknowledgement returned when a web chat message starts immediately.
+#[derive(Debug, Clone, Serialize, JsonSchema)]
+#[serde(rename_all = "snake_case")]
+pub struct StartedChatAck {
+ pub accepted: bool,
+ pub client_id: String,
+ pub thread_id: String,
+ pub request_id: String,
+}
+
/// Typed acknowledgement returned when a web chat message enters the run queue.
/// Attachment values are sanitized opaque references minted by the core.
#[derive(Debug, Clone, Serialize, JsonSchema)]
diff --git a/crates/openhuman-core/src/threads/wire_schema.rs b/crates/openhuman-core/src/threads/wire_schema.rs
index 4a48149ef3..95f10b3026 100644
--- a/crates/openhuman-core/src/threads/wire_schema.rs
+++ b/crates/openhuman-core/src/threads/wire_schema.rs
@@ -21,6 +21,7 @@ pub struct ThreadWireTypes {
pub thread: ConversationThreadSummary,
pub message: ConversationMessageRecord,
pub queued_chat_ack: super::rpc_models::QueuedChatAck,
+ pub started_chat_ack: super::rpc_models::StartedChatAck,
pub threads_list: ConversationThreadsListResponse,
pub thread_messages: ConversationMessagesResponse,
pub thread_delete: DeleteConversationThreadResponse,
diff --git a/crates/openhuman-core/src/threads/wire_schema_tests.rs b/crates/openhuman-core/src/threads/wire_schema_tests.rs
index 9d439387fc..703c250ca1 100644
--- a/crates/openhuman-core/src/threads/wire_schema_tests.rs
+++ b/crates/openhuman-core/src/threads/wire_schema_tests.rs
@@ -10,6 +10,7 @@ fn thread_wire_schema_exports_the_core_and_session_records() {
"thread",
"message",
"queuedChatAck",
+ "startedChatAck",
"threadsList",
"threadMessages",
"threadDelete",
@@ -44,3 +45,17 @@ fn thread_wire_schema_exports_the_core_and_session_records() {
);
}
}
+
+#[test]
+fn started_chat_ack_schema_requires_every_serialized_field() {
+ let schema: serde_json::Value =
+ serde_json::from_str(&thread_wire_schema_json().expect("schema serializes"))
+ .expect("schema is JSON");
+ let ack = &schema["$defs"]["StartedChatAck"];
+ for field in ["accepted", "client_id", "thread_id", "request_id"] {
+ assert!(
+ ack["required"].as_array().unwrap().contains(&field.into()),
+ "started ack schema must require serialized field {field}"
+ );
+ }
+}
diff --git a/crates/openhuman-core/src/web_chat/ops/channel_ops.rs b/crates/openhuman-core/src/web_chat/ops/channel_ops.rs
index 6c6721d50d..ccea2f355c 100644
--- a/crates/openhuman-core/src/web_chat/ops/channel_ops.rs
+++ b/crates/openhuman-core/src/web_chat/ops/channel_ops.rs
@@ -307,12 +307,12 @@ pub async fn channel_web_chat_with_attachments(
}
Ok(Outcome::single_log(
- json!({
- "accepted": true,
- "client_id": client_id.trim(),
- "thread_id": thread_id.trim(),
- "request_id": result,
- }),
+ crate::threads::rpc_models::StartedChatAck {
+ accepted: true,
+ client_id: client_id.trim().to_owned(),
+ thread_id: thread_id.trim().to_owned(),
+ request_id: result,
+ },
"web channel request accepted",
))
}