Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix(web): reject a voice turn that mentions an unavailable participant
shoudi zheng20da7c3efe2e
diff --git a/apps/web/src/features/rooms/chat/use-composer-draft.ts b/apps/web/src/features/rooms/chat/use-composer-draft.tsindex 271c27c0..68309cb9 100644--- a/apps/web/src/features/rooms/chat/use-composer-draft.ts+++ b/apps/web/src/features/rooms/chat/use-composer-draft.ts@@ -13,7 +13,7 @@ import {type MessageDocumentOption,type MessageSkillOption,} from "./message-composer-references";-import { activeMessageMentions } from "./message-mentions";+import { activeMessageMentions, formatMentionToken } from "./message-mentions";import type { ComposerVoiceState } from "./use-composer-voice";export const TEAMHUB_MESSAGE_MAX_LENGTH = 50_000;@@ -180,6 +180,17 @@ export function messageLengthError() {return `Message must be ${TEAMHUB_MESSAGE_MAX_LENGTH.toLocaleString()} characters or fewer.`;}+/** Names unavailable mentions; `nextStep` tells the user how to proceed. */+export function unavailableMentionsError(+ mentions: TeamHubActorRef[],+ nextStep: (noun: string) => string,+) {+ const names = mentions.map(formatMentionToken).join(", ");+ const verb = mentions.length === 1 ? "is" : "are";+ const noun = mentions.length === 1 ? "mention" : "mentions";+ return `${names} ${verb} not available in this Room. ${nextStep(noun)}`;+}+export function findDocumentOption(reference: RoomComposerDocumentReference,documentOptions: MessageDocumentOption[],diff --git a/apps/web/src/features/rooms/chat/use-composer-send.ts b/apps/web/src/features/rooms/chat/use-composer-send.tsindex 40fabca4..3c0024ea 100644--- a/apps/web/src/features/rooms/chat/use-composer-send.ts+++ b/apps/web/src/features/rooms/chat/use-composer-send.ts@@ -8,6 +8,7 @@ import type { ComposerAttachments } from "./use-composer-attachments";import {type ComposerDraft,messageLengthError,+ unavailableMentionsError,TEAMHUB_MESSAGE_MAX_LENGTH,} from "./use-composer-draft";import type { ComposerPicker } from "./use-composer-picker";@@ -94,11 +95,11 @@ export function useComposerSend({return;}if (unavailableMentions.length) {- const names = unavailableMentions.map(formatMentionToken).join(", ");- const verb = unavailableMentions.length === 1 ? "is" : "are";- const noun = unavailableMentions.length === 1 ? "mention" : "mentions";setMessageError(- `${names} ${verb} not available in this Room. Remove the ${noun} to send.`,+ unavailableMentionsError(+ unavailableMentions,+ (noun) => `Remove the ${noun} to send.`,+ ),);return;}diff --git a/apps/web/src/features/rooms/chat/use-composer-voice.ts b/apps/web/src/features/rooms/chat/use-composer-voice.tsindex 5cfd216c..e788f9ca 100644--- a/apps/web/src/features/rooms/chat/use-composer-voice.ts+++ b/apps/web/src/features/rooms/chat/use-composer-voice.ts@@ -8,6 +8,7 @@ import {type ComposerDraft,type ComposerReferences,messageLengthError,+ unavailableMentionsError,TEAMHUB_MESSAGE_MAX_LENGTH,} from "./use-composer-draft";import type { ComposerSend } from "./use-composer-send";@@ -135,6 +136,13 @@ export function useComposerVoiceTurn({throw new Error("Message references are still loading. Exit to review the draft.",);+ if (references.unavailableMentions.length)+ throw new Error(+ unavailableMentionsError(+ references.unavailableMentions,+ () => "Exit to review the draft.",+ ),+ );try {snapshot ??= withVoiceMaterials({diff --git a/apps/web/src/features/rooms/chat/voice-mode/voice-materials-composer.test.tsx b/apps/web/src/features/rooms/chat/voice-mode/voice-materials-composer.test.tsxindex 30563ffc..25294ed2 100644--- a/apps/web/src/features/rooms/chat/voice-mode/voice-materials-composer.test.tsx+++ b/apps/web/src/features/rooms/chat/voice-mode/voice-materials-composer.test.tsx@@ -255,6 +255,33 @@ describe("voice material composer", () => {);});+ it("rejects a voice turn whose draft mentions an unavailable Agent", async () => {+ const staleActor = {+ display_name: "Retired Agent",+ id: "actor-retired",+ kind: "agent" as const,+ tenant_id: scope.tenantId,+ };+ const f = mount({+ agentOptionsReady: true,+ initialMentions: [staleActor],+ initialValue: "@Retired Agent",+ });+ act(() =>+ voice.binding!.onChange({+ entered: true,+ text: "Explain this",+ sourceId: "source-1",+ }),+ );+ await expect(+ voice.binding!.prepareSend("Explain this", "turn-retired")(),+ ).rejects.toThrow(+ "@Retired Agent is not available in this Room. Exit to review the draft.",+ );+ expect(f.onSend).not.toHaveBeenCalled();+ });+it("offers only Send once the draft addresses someone", async () => {const codex = {display_name: "Codex",