Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(calls): keep English answers as before in Take turns and room calls

yofizanedf93aa5c2cb1
diff --git a/shared/call-consent.test.ts b/shared/call-consent.test.ts
index d45a3d7820..aed0767fff 100644
--- a/shared/call-consent.test.ts
+++ b/shared/call-consent.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
-import { spokenConsent } from "./call-consent.ts";
+import { chineseConsent, spokenConsent } from "./call-consent.ts";
describe("spokenConsent", () => {
it("reads a clear yes or no at the start of the answer", () => {
@@ -86,3 +86,26 @@ describe("spokenConsent", () => {
});
}
});
+
+describe("chineseConsent", () => {
+ it("accepts a whole Chinese approval or refusal", () => {
+ for (const said of ["同意", "好的,同意。", "可以执行", "允許"]) {
+ expect.soft(chineseConsent(said), said).toBe("allow");
+ }
+ for (const said of ["拒绝", "不行", "嗯,取消", "拒絕"]) {
+ expect.soft(chineseConsent(said), said).toBe("deny");
+ }
+ });
+
+ it("ignores Chinese filler, questions and conditions", () => {
+ for (const said of ["好的", "可以", "同意吗?", "同意,但是先备份"]) {
+ expect(chineseConsent(said), said).toBeNull();
+ }
+ });
+
+ it("ignores English answers and empty input", () => {
+ for (const said of ["yes", "no", "okay", "uh, yes", "uh, yes, but only after a backup", ""]) {
+ expect(chineseConsent(said), said).toBeNull();
+ }
+ });
+});
diff --git a/shared/call-consent.ts b/shared/call-consent.ts
index 9ea6100576..b812e3e339 100644
--- a/shared/call-consent.ts
+++ b/shared/call-consent.ts
@@ -26,6 +26,14 @@ const ZH_YES = /^(?:我?(?:同意|允[许許]|批准)|是的|(?:[确確][认認]
// 不 no, 不行 no way, 不可以 you may not, 不要 don't, 不用 no need.
const ZH_NO = /^(?:我?拒[绝絕]|不同意|不允[许許]|不批准|(?:不要|不|取消|停止)[执執]行|取消|不(?:行|可以|要|用)?)[\s。.!!]*$/;
+/** A Chinese answer on its own: "allow", "deny", or null. Never decides an English answer. */
+export function chineseConsent(text: string): "allow" | "deny" | null {
+ const said = text.trim().replace(ZH_HEDGES, "");
+ if (ZH_YES.test(said)) return "allow";
+ if (ZH_NO.test(said)) return "deny";
+ return null;
+}
+
/** "allow", "deny", or null when the words are not a clear decision. The
* answer must open the utterance; filler before it ("uh, yes") is dropped.
* `live`: a Live call, whose microphone stays open while the voice speaks
@@ -33,9 +41,8 @@ const ZH_NO = /^(?:我?拒[绝絕]|不同意|不允[许許]|不批准|(?:不要|
* `turns` (take turns) keeps its own rule: its microphone is closed while
* the bot talks. */
export function spokenConsent(text: string, mode: "turns" | "live" = "turns"): "allow" | "deny" | null {
- const chinese = text.trim().replace(ZH_HEDGES, "");
- if (ZH_YES.test(chinese)) return "allow";
- if (ZH_NO.test(chinese)) return "deny";
+ const chinese = chineseConsent(text);
+ if (chinese) return chinese;
const said = text.trim().replace(mode === "live" ? LIVE_HEDGES : FILLER, "");
if ((mode === "live" ? LIVE_YES : YES).test(said)) return "allow";
if (NO.test(said)) return "deny";
diff --git a/src/components/CallView.tsx b/src/components/CallView.tsx
index 59f4b2f4ce..df5cb91b6e 100644
--- a/src/components/CallView.tsx
+++ b/src/components/CallView.tsx
@@ -10,7 +10,7 @@ import { cn } from "@/lib/cn";
import { useMenuMotion } from "./MenuMotion";
import { currentCall, deferCallCleanup, endCall, startCall, useOnCall } from "@/lib/call";
import { CALL_MODES, callModeHint, effectiveCallMode, setCallMode, useCallMode, type CallMode } from "@/lib/call-mode";
-import { spokenConsent } from "../../shared/call-consent";
+import { chineseConsent, NO, YES } from "../../shared/call-consent";
import { dismissStartPrompt, hangUpLiveCall, isLiveCallRunning, startLiveCall, useLiveMedia } from "@/lib/live-call-media";
import { t } from "@/lib/i18n";
import { speaker } from "@/lib/tts";
@@ -588,7 +588,8 @@ function Call({ bot }: { bot: Bot }) {
hush();
return;
}
- const decision = spokenConsent(said, "turns");
+ // English is read exactly as before; chineseConsent only adds the Chinese answers.
+ const decision = YES.test(said) ? "allow" : NO.test(said) ? "deny" : chineseConsent(said);
if (decision) {
const allow = decision === "allow";
if (allow && open.skill) {
diff --git a/src/components/GroupCallView.tsx b/src/components/GroupCallView.tsx
index b706d4fcca..b8914c6668 100644
--- a/src/components/GroupCallView.tsx
+++ b/src/components/GroupCallView.tsx
@@ -20,7 +20,7 @@ import { CALL_ENDPOINT_MS, speechBridge } from "@/lib/speech";
import { useDesktopCapabilities } from "./DesktopCapabilities";
import { isRoutineApproval, isSkillApproval, pendingApprovals, spokenApprovalPrompt } from "./PendingApproval";
import { titledCard } from "./ApprovalCard";
-import { spokenConsent } from "../../shared/call-consent";
+import { chineseConsent, NO, YES } from "../../shared/call-consent";
type Phase = "listening" | "sending" | "working" | "speaking";
@@ -235,7 +235,8 @@ function GroupCall({ group, members }: { group: Group; members: Bot[] }) {
hush();
return;
}
- const decision = spokenConsent(said, "turns");
+ // English is read exactly as before; chineseConsent only adds the Chinese answers.
+ const decision = YES.test(said) ? "allow" : NO.test(said) ? "deny" : chineseConsent(said);
if (decision) {
const allow = decision === "allow";
if (allow && openApproval.skill) {