Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(chat): deduplicate connector mentions

rubenluetke10-beepe18e1185f99f
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
index d5ba3cde79..3cd682f12c 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
@@ -208,7 +208,7 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
await send(
content,
attached,
- selected.map((row) => row.id),
+ [...new Set(selected.map((row) => row.id))],
);
else await send(content, attached);
if (sessionAtSend && store.getState().activeSessionId !== sessionAtSend) return;
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/ComposerChipField.test.tsx b/jarvis/ui/web/frontend/src/components/agentchat/ComposerChipField.test.tsx
index a017d24733..3d18008a00 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/ComposerChipField.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/ComposerChipField.test.tsx
@@ -66,4 +66,12 @@ describe("ComposerChipField", () => {
expect(draft.text).toContain("@gmail");
expect(draft.caret).toBeGreaterThan(draft.text.indexOf("@gmail"));
});
+
+ it("keeps an already selected connector to one chip", () => {
+ const handle = createRef<ComposerChipFieldHandle>();
+ render(<ComposerChipField ref={handle} placeholder="Message" onSubmit={() => {}} onDraftChange={() => {}} />);
+ handle.current?.insertChip(gmail);
+ handle.current?.insertChip(gmail);
+ expect(handle.current?.getDraft().choices.map((row) => row.id)).toEqual(["plugin:gmail"]);
+ });
});
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/ComposerChipField.tsx b/jarvis/ui/web/frontend/src/components/agentchat/ComposerChipField.tsx
index 217f4f07d6..3f9f714459 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/ComposerChipField.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/ComposerChipField.tsx
@@ -223,6 +223,14 @@ export const ComposerChipField = forwardRef<
useImperativeHandle(ref, () => ({
insertChip(row) {
+ // A connector is a per-message selection, not a repeatable word. The
+ // Add menu may be reopened after the field has emitted its draft, so
+ // reject the second insertion at the source rather than serializing two
+ // identical connector IDs to the turn.
+ if (elRef.current && serialize(elRef.current).choices.some((choice) => choice.id === row.id)) {
+ elRef.current.focus();
+ return;
+ }
insertNode(createChipEl(row));
},
insertText(text) {
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/composerChips.test.ts b/jarvis/ui/web/frontend/src/components/agentchat/composerChips.test.ts
index 71c5428b33..da52e90885 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/composerChips.test.ts
+++ b/jarvis/ui/web/frontend/src/components/agentchat/composerChips.test.ts
@@ -35,4 +35,12 @@ describe("composer chips", () => {
expect(parts[0]).toEqual({ type: "text", text: "Find that email" });
expect(parts[1]).toEqual({ type: "chip", row: gmail });
});
+
+ it("renders each selected connector once when an old receipt duplicates it", () => {
+ const duplicate = { ...gmail };
+ const parts = splitMessageChips("Use @gmail", [gmail, duplicate]);
+ expect(parts.filter((part) => part.type === "chip")).toEqual([
+ { type: "chip", row: duplicate },
+ ]);
+ });
});
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/composerChips.ts b/jarvis/ui/web/frontend/src/components/agentchat/composerChips.ts
index a865e3f49f..0d4fbd45ba 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/composerChips.ts
+++ b/jarvis/ui/web/frontend/src/components/agentchat/composerChips.ts
@@ -37,7 +37,10 @@ export function splitMessageChips(
return choices.length ? choices.map((row) => ({ type: "chip" as const, row })) : [];
}
const tags = choiceLookup(choices);
- const used = new Set<ToolChoice>();
+ // Event receipts can be replayed from an older client which wrote the same
+ // choice twice. Identity is the tool id, not the object instance: JSON
+ // hydration creates a fresh object for every copy.
+ const used = new Set<string>();
const parts: Array<{ type: "text"; text: string } | { type: "chip"; row: ToolChoice }> = [];
const chunks = text.split(CHIP_RE);
for (const chunk of chunks) {
@@ -45,14 +48,15 @@ export function splitMessageChips(
const name = chunk.startsWith("@") ? chunk.slice(1).toLowerCase() : "";
const row = name ? tags.get(name) : undefined;
if (row) {
- parts.push({ type: "chip", row });
- used.add(row);
+ if (!used.has(row.id)) parts.push({ type: "chip", row });
+ used.add(row.id);
} else {
parts.push({ type: "text", text: chunk });
}
}
for (const row of choices) {
- if (!used.has(row)) parts.push({ type: "chip", row });
+ if (!used.has(row.id)) parts.push({ type: "chip", row });
+ used.add(row.id);
}
return parts;
}