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): show branded selections in live agent cards

rubenluetke10-beep19135211319f
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
index a759af10a6..d5a52932b9 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
@@ -27,6 +27,7 @@ import remarkGfm from "remark-gfm";
import { AgentChatStoreProvider, useAgentChat } from "@/components/agentchat/AgentChatStoreContext";
import { ChatAttachmentStrip } from "@/components/agentchat/ChatAttachmentStrip";
+import { ToolChoiceChips } from "@/components/agentchat/ToolChoiceChips";
import { useChatAttachments } from "@/components/agentchat/useChatAttachments";
import { DictationStatus } from "@/components/agentchat/DictationStatus";
import { useComposerDictation } from "@/components/agentchat/useComposerDictation";
@@ -51,6 +52,7 @@ import { AgentSwatch } from "../AgentSwatch";
import { useResolveProposal, useSocietyCapabilities, type SocietyAgent } from "../data";
import { MentionPicker } from "./MentionPicker";
import { AgentModelPicker } from "./AgentModelPicker";
+import { mentionChoice, messageChoices, withoutChoiceTokens } from "./mentionChoices";
import {
buildMentionCatalog,
filterMentions,
@@ -774,11 +776,14 @@ function visibleUserText(text: string): string {
.trimEnd();
}
-function UserBubble({ item }: { item: UserItem }) {
+export function UserBubble({ item }: { item: UserItem }) {
+ const choices = messageChoices(item);
+ const text = withoutChoiceTokens(visibleUserText(item.text), choices);
return (
<div className="flex max-w-[85%] flex-col items-end gap-1 self-end">
<div className="whitespace-pre-wrap rounded-2xl rounded-br-md bg-secondary px-3.5 py-2 text-sm leading-relaxed text-foreground">
- {visibleUserText(item.text)}
+ {text}
+ <ToolChoiceChips items={choices} />
</div>
{item.attachments.length > 0 ? (
<div className="flex flex-wrap justify-end gap-1">
@@ -1057,7 +1062,7 @@ interface ComposerProps {
onCancel: () => Promise<void>;
}
-function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surface = "jarvis", onSend, onCancel }: ComposerProps) {
+export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surface = "jarvis", onSend, onCancel }: ComposerProps) {
const t = useT();
const [modelSaving, setModelSaving] = useState(false);
const [value, setValue] = useState("");
@@ -1065,6 +1070,8 @@ function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surface
const [problem, setProblem] = useState<string | null>(null);
const [mention, setMention] = useState<{ query: string; start: number } | null>(null);
const [activeIndex, setActiveIndex] = useState(0);
+ const [selectedTools, setSelectedTools] = useState<MentionItem[]>([]);
+ useEffect(() => { setSelectedTools([]); }, [sessionId, agent.agentId]);
const textarea = useRef<HTMLTextAreaElement>(null);
const composerRef = useRef<HTMLDivElement>(null);
const fileInput = useRef<HTMLInputElement>(null);
@@ -1108,7 +1115,8 @@ function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surface
if (!mention) return;
const el = textarea.current;
const caret = el?.selectionStart ?? value.length;
- const inserted = `@${item.value} `;
+ const inserted = item.agent ? `@${item.value} ` : "";
+ if (!item.agent) setSelectedTools((items) => items.some((row) => row.key === item.key) ? items : [...items, item]);
const next = `${value.slice(0, mention.start)}${inserted}${value.slice(caret)}`;
setValue(next);
setMention(null);
@@ -1121,7 +1129,9 @@ function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surface
};
const submit = async () => {
- const text = value.trim();
+ const draftText = value.trim();
+ const selected = selectedTools;
+ const text = [draftText, ...selected.map((row) => `@${row.value}`)].filter(Boolean).join(" ");
if (!text || busy || modelSaving) return;
const named = mentionsInText(text, catalog);
const lines = named.agents.map(
@@ -1134,8 +1144,11 @@ function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surface
setProblem(null);
try {
await onSend(hint ? `${text}\n\n${hint}` : text, attachments.attachments);
+ setSelectedTools([]);
attachments.clear();
} catch (err) {
+ setValue(draftText);
+ setSelectedTools(selected);
setProblem(err instanceof Error ? err.message : String(err));
}
};
@@ -1146,6 +1159,10 @@ function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surface
<div className="shrink-0 border-t border-border px-3 pb-3 pt-2">
{problem ? <p className="mb-1 px-1 text-xs text-destructive">{problem}</p> : null}
<div className={CHAT_MEASURE}>
+ <div className="mb-1.5">
+ <ToolChoiceChips items={selectedTools.map(mentionChoice)}
+ onRemove={(id) => setSelectedTools((items) => items.filter((row) => row.key !== id))} />
+ </div>
<ChatAttachmentStrip attachments={attachments.attachments} analyzing={attachments.analyzing} onRemove={attachments.remove} />
</div>
<DictationStatus onStop={dictation.stop} className={cn(CHAT_MEASURE, "mb-1.5")} />
@@ -1182,6 +1199,17 @@ function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surface
</button>
{plusOpen ? (
<div className="absolute bottom-full left-0 z-20 mb-1 w-52 overflow-hidden rounded-lg border border-border bg-popover py-1 shadow-float">
+ <button type="button" onClick={() => {
+ setPlusOpen(false);
+ const caret = textarea.current?.selectionStart ?? value.length;
+ const prefix = value.slice(0, caret);
+ const token = `${prefix && !/\s$/.test(prefix) ? " " : ""}@`;
+ const next = prefix + token + value.slice(caret);
+ onChange(next, caret + token.length);
+ requestAnimationFrame(() => { textarea.current?.focus(); textarea.current?.setSelectionRange(caret + token.length, caret + token.length); });
+ }} className="flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-foreground hover:bg-secondary">
+ <Plus className="h-3.5 w-3.5" aria-hidden />{t("chat_tools.all")}
+ </button>
<button
type="button"
onClick={() => {
@@ -1286,7 +1314,7 @@ function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surface
<button
type="button"
onClick={() => void submit()}
- disabled={modelSaving || !value.trim()}
+ disabled={modelSaving || (!value.trim() && selectedTools.length === 0)}
aria-label={t("society.chat.send")}
className="flex h-8 w-8 items-center justify-center rounded-full bg-primary text-primary-foreground disabled:opacity-40"
>
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/MentionPicker.tsx b/jarvis/ui/web/frontend/src/components/society/chat/MentionPicker.tsx
index bebf057079..955c320727 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/MentionPicker.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/MentionPicker.tsx
@@ -11,7 +11,9 @@ import { useEffect, useId, useLayoutEffect, useRef, useState, type RefObject } f
import { createPortal } from "react-dom";
import { cn } from "@/lib/utils";
-import { resolveToolBrand } from "@/lib/toolBrand";
+import { ToolChoiceIcon } from "@/components/agentchat/ToolChoiceChips";
+import { toolIdentityStyle } from "@/components/agentchat/toolIdentity";
+import { mentionChoice } from "./mentionChoices";
import { useT } from "@/i18n";
import { AgentSwatch } from "../AgentSwatch";
@@ -133,9 +135,11 @@ export function MentionPicker({
data-index={index}
data-kind={item.kind}
data-testid="mention-picker-item"
+ style={item.agent ? undefined : toolIdentityStyle(mentionChoice(item))}
onMouseEnter={() => onHover(index)}
onClick={() => onPick(item)}
className={cn(
+ !item.agent && "tool-identity",
"flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5",
active ? "bg-secondary text-foreground" : "text-foreground",
!item.connected && "opacity-50",
@@ -199,19 +203,5 @@ function Mark({ item }: { item: MentionItem }) {
if (item.agent) {
return <AgentSwatch agent={item.agent} size={20} className="h-5 w-5" />;
}
- const brand = resolveToolBrand(item.toolName || item.value);
- return (
- <span
- aria-hidden
- className="inline-flex h-5 w-5 shrink-0 items-center justify-center overflow-hidden rounded-[5px] bg-secondary"
- >
- {brand.logoUrl ? (
- <img src={brand.logoUrl} alt="" className="h-full w-full object-contain p-[2px]" draggable={false} />
- ) : (
- <span className="font-mono text-[10px] font-semibold uppercase text-muted-foreground">
- {brand.monogram}
- </span>
- )}
- </span>
- );
+ return <ToolChoiceIcon row={mentionChoice(item)} />;
}
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.test.tsx b/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.test.tsx
new file mode 100644
index 0000000000..a4f229ad8d
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.test.tsx
@@ -0,0 +1,93 @@
+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { afterEach, expect, it, vi } from "vitest";
+import { Composer, UserBubble } from "./AgentChatPanel";
+import { pinnedMessageChoices, withoutChoiceTokens } from "./mentionChoices";
+import type { SocietyAgent } from "../data";
+
+vi.mock("@/i18n", () => ({ useT: () => (key: string) => key }));
+// Model controls have their own suite; this exercises selection and pin delivery.
+vi.mock("./AgentModelPicker", () => ({ AgentModelPicker: () => null }));
+vi.mock("../data", async (original) => ({
+ ...(await original<typeof import("../data")>()),
+ useSocietyCapabilities: () => ({
+ isLoading: false,
+ data: [
+ {
+ id: "plugin:gmail",
+ kind: "plugin",
+ label: "gmail",
+ one_liner: "Read email",
+ connected: true,
+ tool_name: "gmail",
+ risk_tier: "ask",
+ },
+ ],
+ }),
+}));
+vi.mock("@/components/agentchat/useComposerDictation", () => ({
+ useComposerDictation: () => ({ dictating: false, stop() {}, toggle() {} }),
+}));
+vi.mock("@/components/agentchat/DictationStatus", () => ({ DictationStatus: () => null }));
+vi.mock("@/components/agentchat/useChatAttachments", () => ({
+ useChatAttachments: () => ({
+ attachments: [],
+ analyzing: 0,
+ dragging: false,
+ dragHandlers: {},
+ clear() {},
+ remove() {},
+ attachFiles() {},
+ }),
+}));
+afterEach(cleanup);
+
+it("uses Add to select a real branded chip and preserves the existing pin protocol", async () => {
+ const send = vi.fn(async (_text: string) => {});
+ render(
+ <Composer
+ agent={{ agentId: "test", name: "Test" } as SocietyAgent}
+ mentionable={[]}
+ busy={false}
+ sessionId="society:test"
+ cwd=""
+ provider="openai"
+ surface="society"
+ onSend={send}
+ onCancel={async () => {}}
+ />,
+ );
+ fireEvent.click(screen.getByRole("button", { name: "society.chat.more" }));
+ fireEvent.click(screen.getByRole("button", { name: "chat_tools.all" }));
+ fireEvent.click(await screen.findByRole("option", { name: /@\s*gmail/ }));
+ const chips = screen.getByTestId("tool-choice-chips");
+ expect(chips.querySelector('[data-brand="gmail"] img')).not.toBeNull();
+ const input = screen.getByRole("textbox");
+ expect((input as HTMLTextAreaElement).value).toBe("");
+ fireEvent.change(input, { target: { value: "Check unread mail" } });
+ fireEvent.click(screen.getByRole("button", { name: "society.chat.send" }));
+ await waitFor(() => expect(send).toHaveBeenCalledOnce());
+ const text = String(send.mock.calls[0][0]);
+ expect(text).toContain("[tools: plugin:gmail]");
+ expect(text).toContain("@gmail");
+ expect(withoutChoiceTokens("Check unread mail @gmail", pinnedMessageChoices(text))).toBe(
+ "Check unread mail",
+ );
+});
+
+it("reconstructs branded tags from an existing saved agent-card message", () => {
+ const text = "Read this @gmail\n\n[tools: plugin:gmail]";
+ render(<UserBubble item={{ type: "user", id: "m1", tsMs: 1, text, attachments: [] }} />);
+ expect(screen.getByText("Read this")).toBeTruthy();
+ expect(screen.queryByText(/@gmail/)).toBeNull();
+ expect(
+ screen.getByTestId("tool-choice-chips").querySelector('[data-brand="gmail"]'),
+ ).not.toBeNull();
+});
+
+it("collapses server pins but keeps specific MCP tool selections distinct", () => {
+ const choices = pinnedMessageChoices("Use @github\n\n[tools: mcp:github/read, mcp:github/list]");
+ expect(choices).toHaveLength(1);
+ expect(choices[0].id).toBe("mcp-server:github");
+ const specific = pinnedMessageChoices("Use @github/read\n\n[tools: mcp:github/read]");
+ expect(specific[0].id).toBe("mcp:github/read");
+});
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.ts b/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.ts
new file mode 100644
index 0000000000..d1d0b3b55d
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.ts
@@ -0,0 +1,72 @@
+/** Presentation adapter for the agent cards' existing capability-pin protocol. */
+import type { ToolChoice, ToolCategory } from "@/components/agentchat/toolChoices";
+import { resolveToolBrand } from "@/lib/toolBrand";
+import type { MentionItem } from "./mentionItems";
+
+function category(id: string): ToolCategory {
+ const [kind, name = ""] = id.split(":");
+ if (kind === "plugin") return "plugins";
+ if (kind === "skill") return "skills";
+ if (kind === "mcp" || kind === "mcp-server") return "mcp";
+ if (kind === "cli") return "cli";
+ if (/wiki|memory|remember|recall|contact/.test(name)) return "memory";
+ if (/search-web|browse/.test(name)) return "web";
+ return "system";
+}
+
+function choice(id: string, name: string, description = ""): ToolChoice {
+ const brand = resolveToolBrand(name);
+ const label = brand.brandId ? brand.label : name;
+ return {
+ id,
+ label,
+ description,
+ category: category(id),
+ group: name.split("/")[0],
+ brand: brand.brandId ?? "",
+ available: true,
+ tool_names: [],
+ skill: id.startsWith("skill:") ? name : "",
+ };
+}
+
+export function mentionChoice(item: MentionItem): ToolChoice {
+ return {
+ ...choice(item.key, item.toolName || item.value, item.hint),
+ available: item.connected,
+ tool_names: [item.toolName].filter(Boolean),
+ };
+}
+
+/** Old conversations already carry validated pin IDs in their saved text. */
+export function pinnedMessageChoices(text: string): ToolChoice[] {
+ const ids = [...text.matchAll(/^\[tools:\s*([^\]\r\n]+)\]\s*$/gm)]
+ .flatMap((match) => match[1].split(",").map((id) => id.trim()))
+ .filter((id) => /^(plugin|mcp|cli|skill|core):[^\s]+$/.test(id));
+ const tags = new Set([...text.matchAll(/(?:^|\s)@([^\s@]+)/g)].map((m) => m[1].toLowerCase()));
+ const picked = new Map<string, ToolChoice>();
+ for (const id of ids) {
+ const name = id.slice(id.indexOf(":") + 1);
+ const server = name.split("/")[0];
+ const collapsed = id.startsWith("mcp:") && tags.has(server.toLowerCase());
+ const key = collapsed ? `mcp-server:${server}` : id;
+ picked.set(key, choice(key, collapsed ? server : name));
+ }
+ return [...picked.values()];
+}
+
+/** Both the structured chat receipt and older agent-card messages are supported. */
+export function messageChoices(item: { text: string; toolChoices?: ToolChoice[] }): ToolChoice[] {
+ return item.toolChoices?.length ? item.toolChoices : pinnedMessageChoices(item.text);
+}
+
+/** Remove only tokens whose selections are displayed separately below the text. */
+export function withoutChoiceTokens(text: string, choices: ToolChoice[]): string {
+ const names = new Set(choices.map((row) => row.id.slice(row.id.indexOf(":") + 1).toLowerCase()));
+ return text
+ .replace(/(^|\s)@([^\s@]+)/g, (whole, space: string, name: string) =>
+ names.has(name.toLowerCase()) ? space : whole,
+ )
+ .replace(/[ \t]+\n/g, "\n")
+ .trim();
+}