Skip to content

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

feat(chat): add guardrail error UI and fix test mock patterns

Steven Enamakelca0ea331716a
diff --git a/app/src/features/conversations/aui/PlanReviewPart.test.tsx b/app/src/features/conversations/aui/PlanReviewPart.test.tsx
index 639a9bb823..87bd4daa3b 100644
--- a/app/src/features/conversations/aui/PlanReviewPart.test.tsx
+++ b/app/src/features/conversations/aui/PlanReviewPart.test.tsx
@@ -86,7 +86,7 @@ describe('PlanReviewCardCore', () => {
});
it('shows an error and does not clear the review when the RPC fails', async () => {
- vi.mocked(callCoreRpc).mockRejectedValue(new Error('boom'));
+ vi.mocked(callCoreRpc).mockImplementation(() => Promise.reject(new Error('boom')));
const store = renderCard();
await userEvent.click(screen.getByText('Approve & run'));
diff --git a/app/src/features/conversations/aui/useThreadGoal.test.tsx b/app/src/features/conversations/aui/useThreadGoal.test.tsx
index 8910ac9d2e..b8682b27f9 100644
--- a/app/src/features/conversations/aui/useThreadGoal.test.tsx
+++ b/app/src/features/conversations/aui/useThreadGoal.test.tsx
@@ -58,7 +58,7 @@ describe('useLoadThreadGoal', () => {
});
it('leaves the slice untouched when the RPC fails', async () => {
- vi.mocked(threadApi.getGoal).mockRejectedValue(new Error('no such method'));
+ vi.mocked(threadApi.getGoal).mockImplementation(() => Promise.reject(new Error('no such method')));
const { store, wrapper } = setup();
renderHook(() => useLoadThreadGoal('t1'), { wrapper });
diff --git a/app/src/features/conversations/aui/useThreadTodos.test.tsx b/app/src/features/conversations/aui/useThreadTodos.test.tsx
index 7241724aeb..55670f61c3 100644
--- a/app/src/features/conversations/aui/useThreadTodos.test.tsx
+++ b/app/src/features/conversations/aui/useThreadTodos.test.tsx
@@ -51,7 +51,7 @@ describe('useLoadThreadTodos', () => {
});
it('leaves the slice untouched when the RPC fails (older core)', async () => {
- vi.mocked(threadApi.getTodos).mockRejectedValue(new Error('no such method'));
+ vi.mocked(threadApi.getTodos).mockImplementation(() => Promise.reject(new Error('no such method')));
const { store, wrapper } = setup();
renderHook(() => useLoadThreadTodos('t1'), { wrapper });
diff --git a/app/src/lib/i18n/ar.ts b/app/src/lib/i18n/ar.ts
index 6b9fb27d53..73a2f7165a 100644
--- a/app/src/lib/i18n/ar.ts
+++ b/app/src/lib/i18n/ar.ts
@@ -165,6 +165,11 @@ const messages: TranslationMap = {
'crossHostVault.title': 'الخزنة موجودة على مضيف النواة.',
'crossHostVault.message':
'يتم تخزين خزنة الذاكرة هذه على مضيف openhuman-core ({os}). لا يمكن فتحها أو عرضها إلا على ذلك الجهاز، وليس من هذا الجهاز.',
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': 'لم يمر هذا الطلب بفحص أمان',
+ 'conversations.chatError.guardrail.explanationFallback':
+ 'منعت السياسة هذا الرد قبل إرساله.',
+ 'conversations.chatError.guardrail.tryInstead': 'جرّب بدلاً من ذلك',
'conversations.toolFailure.whyLabel': 'لماذا',
'conversations.toolFailure.nextLabel': 'ما الذي يجب فعله بعد ذلك',
'conversations.toolFailure.missingPermission.cause': 'لا يملك OpenHuman الإذن للقيام بهذا بعد.',
diff --git a/app/src/lib/i18n/bn.ts b/app/src/lib/i18n/bn.ts
index 58b1731e08..62a7445c77 100644
--- a/app/src/lib/i18n/bn.ts
+++ b/app/src/lib/i18n/bn.ts
@@ -172,6 +172,11 @@ const messages: TranslationMap = {
'crossHostVault.title': 'ভল্টটি কোর হোস্টে রয়েছে।',
'crossHostVault.message':
'এই মেমরি ভল্টটি openhuman-core হোস্টে ({os}) সংরক্ষিত আছে। এটি কেবল সেই মেশিনেই খোলা বা দেখানো যায়, এই ডিভাইস থেকে নয়।',
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': 'এই অনুরোধটি সুরক্ষা পরীক্ষায় উত্তীর্ণ হয়নি',
+ 'conversations.chatError.guardrail.explanationFallback':
+ 'প্রতিক্রিয়াটি পাঠানোর আগে একটি নীতি এটি ব্লক করেছে।',
+ 'conversations.chatError.guardrail.tryInstead': 'পরিবর্তে চেষ্টা করুন',
'conversations.toolFailure.whyLabel': 'কেন',
'conversations.toolFailure.nextLabel': 'এরপর কী করবেন',
'conversations.toolFailure.missingPermission.cause': 'OpenHuman-এর এখনও এটি করার অনুমতি নেই।',
diff --git a/app/src/lib/i18n/de.ts b/app/src/lib/i18n/de.ts
index 5f7ebb6919..dff73a576d 100644
--- a/app/src/lib/i18n/de.ts
+++ b/app/src/lib/i18n/de.ts
@@ -186,6 +186,11 @@ const messages: TranslationMap = {
'crossHostVault.title': 'Der Vault liegt auf dem Core-Host.',
'crossHostVault.message':
'Dieser Memory-Vault wird auf dem openhuman-core-Host ({os}) gespeichert. Er kann nur auf diesem Rechner geöffnet oder angezeigt werden, nicht von diesem Gerät.',
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': 'Diese Anfrage hat eine Sicherheitsprüfung nicht bestanden',
+ 'conversations.chatError.guardrail.explanationFallback':
+ 'Eine Richtlinie hat diese Antwort blockiert, bevor sie gesendet wurde.',
+ 'conversations.chatError.guardrail.tryInstead': 'stattdessen versuchen',
'conversations.toolFailure.whyLabel': 'Warum',
'conversations.toolFailure.nextLabel': 'Nächste Schritte',
'conversations.toolFailure.missingPermission.cause':
diff --git a/app/src/lib/i18n/es.ts b/app/src/lib/i18n/es.ts
index c8efdf6143..bc91df7183 100644
--- a/app/src/lib/i18n/es.ts
+++ b/app/src/lib/i18n/es.ts
@@ -178,6 +178,11 @@ const messages: TranslationMap = {
'crossHostVault.title': 'El vault está en el host del core.',
'crossHostVault.message':
'Este vault de memoria se almacena en el host de openhuman-core ({os}). Solo se puede abrir o mostrar en esa máquina, no desde este dispositivo.',
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': 'Esta solicitud no pasó una verificación de seguridad',
+ 'conversations.chatError.guardrail.explanationFallback':
+ 'Una política bloqueó esta respuesta antes de que se enviara.',
+ 'conversations.chatError.guardrail.tryInstead': 'probar en su lugar',
'conversations.toolFailure.whyLabel': 'Por qué',
'conversations.toolFailure.nextLabel': 'Qué hacer a continuación',
'conversations.toolFailure.missingPermission.cause':
diff --git a/app/src/lib/i18n/fr.ts b/app/src/lib/i18n/fr.ts
index 1b4b889c84..f2de77bc41 100644
--- a/app/src/lib/i18n/fr.ts
+++ b/app/src/lib/i18n/fr.ts
@@ -186,6 +186,11 @@ const messages: TranslationMap = {
'crossHostVault.title': "Le coffre se trouve sur l'hôte du cœur.",
'crossHostVault.message':
"Ce coffre de mémoire est stocké sur l'hôte openhuman-core ({os}). Il ne peut être ouvert ou affiché que sur cette machine, pas depuis cet appareil.",
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': "Cette demande n'a pas passé un contrôle de sécurité",
+ 'conversations.chatError.guardrail.explanationFallback':
+ 'Une politique a bloqué cette réponse avant son envoi.',
+ 'conversations.chatError.guardrail.tryInstead': 'essayer plutôt',
'conversations.toolFailure.whyLabel': 'Pourquoi',
'conversations.toolFailure.nextLabel': 'Que faire ensuite',
'conversations.toolFailure.missingPermission.cause':
diff --git a/app/src/lib/i18n/hi.ts b/app/src/lib/i18n/hi.ts
index d3f944262c..053c80c792 100644
--- a/app/src/lib/i18n/hi.ts
+++ b/app/src/lib/i18n/hi.ts
@@ -174,6 +174,11 @@ const messages: TranslationMap = {
'crossHostVault.title': 'वॉल्ट कोर होस्ट पर है।',
'crossHostVault.message':
'यह मेमोरी वॉल्ट openhuman-core होस्ट ({os}) पर संग्रहीत है। इसे केवल उसी मशीन पर खोला या दिखाया जा सकता है, इस डिवाइस से नहीं।',
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': 'यह अनुरोध सुरक्षा जांच में पास नहीं हुआ',
+ 'conversations.chatError.guardrail.explanationFallback':
+ 'यह प्रतिक्रिया भेजे जाने से पहले एक नीति द्वारा रोक दी गई।',
+ 'conversations.chatError.guardrail.tryInstead': 'इसके बजाय आज़माएं',
'conversations.toolFailure.whyLabel': 'क्यों',
'conversations.toolFailure.nextLabel': 'आगे क्या करें',
'conversations.toolFailure.missingPermission.cause':
diff --git a/app/src/lib/i18n/id.ts b/app/src/lib/i18n/id.ts
index 92d7f38037..25718c0509 100644
--- a/app/src/lib/i18n/id.ts
+++ b/app/src/lib/i18n/id.ts
@@ -178,6 +178,11 @@ const messages: TranslationMap = {
'crossHostVault.title': 'Vault berada di host core.',
'crossHostVault.message':
'Vault memori ini disimpan di host openhuman-core ({os}). Hanya dapat dibuka atau ditampilkan di mesin tersebut, bukan dari perangkat ini.',
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': 'Permintaan ini tidak lolos pemeriksaan keamanan',
+ 'conversations.chatError.guardrail.explanationFallback':
+ 'Kebijakan memblokir respons ini sebelum dikirim.',
+ 'conversations.chatError.guardrail.tryInstead': 'coba sebagai gantinya',
'conversations.toolFailure.whyLabel': 'Mengapa',
'conversations.toolFailure.nextLabel': 'Yang harus dilakukan',
'conversations.toolFailure.missingPermission.cause':
diff --git a/app/src/lib/i18n/it.ts b/app/src/lib/i18n/it.ts
index d1a92da054..be983cb9c9 100644
--- a/app/src/lib/i18n/it.ts
+++ b/app/src/lib/i18n/it.ts
@@ -179,6 +179,11 @@ const messages: TranslationMap = {
'crossHostVault.title': "Il vault è sull'host del core.",
'crossHostVault.message':
"Questo vault di memoria è archiviato sull'host openhuman-core ({os}). Può essere aperto o mostrato solo su quella macchina, non da questo dispositivo.",
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': 'Questa richiesta non ha superato un controllo di sicurezza',
+ 'conversations.chatError.guardrail.explanationFallback':
+ 'Una norma ha bloccato questa risposta prima che venisse inviata.',
+ 'conversations.chatError.guardrail.tryInstead': 'prova invece',
'conversations.toolFailure.whyLabel': 'Perché',
'conversations.toolFailure.nextLabel': 'Cosa fare ora',
'conversations.toolFailure.missingPermission.cause':
diff --git a/app/src/lib/i18n/ko.ts b/app/src/lib/i18n/ko.ts
index 3038033e13..e81eb6626f 100644
--- a/app/src/lib/i18n/ko.ts
+++ b/app/src/lib/i18n/ko.ts
@@ -169,6 +169,11 @@ const messages: TranslationMap = {
'crossHostVault.title': '보관소가 코어 호스트에 있습니다.',
'crossHostVault.message':
'이 메모리 보관소는 openhuman-core 호스트({os})에 저장되어 있습니다. 해당 컴퓨터에서만 열거나 표시할 수 있으며 이 기기에서는 불가능합니다.',
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': '이 요청은 안전성 검사를 통과하지 못했습니다',
+ 'conversations.chatError.guardrail.explanationFallback':
+ '정책에 따라 이 응답이 전송되기 전에 차단되었습니다.',
+ 'conversations.chatError.guardrail.tryInstead': '대신 시도',
'conversations.toolFailure.whyLabel': '이유',
'conversations.toolFailure.nextLabel': '다음 할 일',
'conversations.toolFailure.missingPermission.cause':
diff --git a/app/src/lib/i18n/pl.ts b/app/src/lib/i18n/pl.ts
index 4d6f892aa5..2e9bfc5a1b 100644
--- a/app/src/lib/i18n/pl.ts
+++ b/app/src/lib/i18n/pl.ts
@@ -179,6 +179,11 @@ const messages: TranslationMap = {
'crossHostVault.title': 'Skarbiec znajduje się na hoście rdzenia.',
'crossHostVault.message':
'Ten skarbiec pamięci jest przechowywany na hoście openhuman-core ({os}). Można go otworzyć lub pokazać tylko na tym komputerze, a nie z tego urządzenia.',
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': 'Ta prośba nie przeszła kontroli bezpieczeństwa',
+ 'conversations.chatError.guardrail.explanationFallback':
+ 'Zasada zablokowała tę odpowiedź przed jej wysłaniem.',
+ 'conversations.chatError.guardrail.tryInstead': 'wypróbuj zamiast tego',
'conversations.toolFailure.whyLabel': 'Dlaczego',
'conversations.toolFailure.nextLabel': 'Co dalej',
'conversations.toolFailure.missingPermission.cause':
diff --git a/app/src/lib/i18n/pt.ts b/app/src/lib/i18n/pt.ts
index ac9029f11f..1d99f8f391 100644
--- a/app/src/lib/i18n/pt.ts
+++ b/app/src/lib/i18n/pt.ts
@@ -174,6 +174,11 @@ const messages: TranslationMap = {
'crossHostVault.title': 'O vault está no host do core.',
'crossHostVault.message':
'Este vault de memória fica armazenado no host openhuman-core ({os}). Só pode ser aberto ou exibido nessa máquina, não a partir deste dispositivo.',
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': 'Esta solicitação não passou por uma verificação de segurança',
+ 'conversations.chatError.guardrail.explanationFallback':
+ 'Uma política bloqueou esta resposta antes que fosse enviada.',
+ 'conversations.chatError.guardrail.tryInstead': 'tentar em vez disso',
'conversations.toolFailure.whyLabel': 'Por quê',
'conversations.toolFailure.nextLabel': 'O que fazer a seguir',
'conversations.toolFailure.missingPermission.cause':
diff --git a/app/src/lib/i18n/ru.ts b/app/src/lib/i18n/ru.ts
index 3f4a4e2f74..06aeef3fd7 100644
--- a/app/src/lib/i18n/ru.ts
+++ b/app/src/lib/i18n/ru.ts
@@ -174,6 +174,11 @@ const messages: TranslationMap = {
'crossHostVault.title': 'Хранилище находится на хосте ядра.',
'crossHostVault.message':
'Это хранилище памяти размещено на хосте openhuman-core ({os}). Его можно открыть или показать только на той машине, но не с этого устройства.',
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': 'Этот запрос не прошёл проверку безопасности',
+ 'conversations.chatError.guardrail.explanationFallback':
+ 'Правило блокировало этот ответ до того, как он был отправлен.',
+ 'conversations.chatError.guardrail.tryInstead': 'попробовать вместо этого',
'conversations.toolFailure.whyLabel': 'Почему',
'conversations.toolFailure.nextLabel': 'Что делать дальше',
'conversations.toolFailure.missingPermission.cause':
diff --git a/app/src/lib/i18n/zh-CN.ts b/app/src/lib/i18n/zh-CN.ts
index 6562d887e5..f06f9fe4ae 100644
--- a/app/src/lib/i18n/zh-CN.ts
+++ b/app/src/lib/i18n/zh-CN.ts
@@ -161,6 +161,11 @@ const messages: TranslationMap = {
'crossHostVault.title': '记忆库位于核心主机上。',
'crossHostVault.message':
'此记忆库存储在 openhuman-core 主机({os})上。只能在该机器上打开或显示,无法从本设备访问。',
+ // Guardrail notice for a `chat_error{error_type:"guardrail"}` turn (wire-contract.md).
+ 'conversations.chatError.guardrail.title': '此请求未通过安全检查',
+ 'conversations.chatError.guardrail.explanationFallback':
+ '策略在此回复发送前将其拦截。',
+ 'conversations.chatError.guardrail.tryInstead': '改为尝试',
'conversations.toolFailure.whyLabel': '原因',
'conversations.toolFailure.nextLabel': '接下来该怎么做',
'conversations.toolFailure.missingPermission.cause': 'OpenHuman 目前还没有执行此操作的权限。',
diff --git a/crates/openhuman-core/src/web_chat/presentation.rs b/crates/openhuman-core/src/web_chat/presentation.rs
index 1a5b14e828..7ac3f98da3 100644
--- a/crates/openhuman-core/src/web_chat/presentation.rs
+++ b/crates/openhuman-core/src/web_chat/presentation.rs
@@ -66,6 +66,7 @@ pub(crate) async fn deliver_response(
usage: Option<&LastTurnUsage>,
workspace_dir: Option<&std::path::Path>,
timing: Option<super::turn_timing::TurnTimingSnapshot>,
+ suggest_follow_ups: bool,
) {
let usage_payload = usage_payload(usage);
let timing_payload =