diff --git a/desktop/cli/commands/prefs.mjs b/desktop/cli/commands/prefs.mjs index 1c30be0f..4f6d5ef1 100644 --- a/desktop/cli/commands/prefs.mjs +++ b/desktop/cli/commands/prefs.mjs @@ -35,6 +35,8 @@ const KEYS = [ ["appearance.textSize", "small | default | large | larger", "The size of the text"], ["appearance.font", list(THEMES.fonts.map((font) => font.id)), "The font"], ["appearance.bubble", "theme | #rrggbb", "The color of your messages"], + ["appearance.agentMessages", "canvas | bubbles", "How agent messages are shown"], + ["appearance.agentBubble", "theme | #rrggbb", "The default color of agent message bubbles"], ["appearance.avatarAnimations", "on | off", "Animate bot avatars while they work"], ["foldTools", "on | off", "Fold the steps of a finished reply into one line"], ["showThinking", "on | off", "Show the bot's thinking"], diff --git a/desktop/cli/commands/workspace.mjs b/desktop/cli/commands/workspace.mjs index 3940c868..89c2a7ea 100644 --- a/desktop/cli/commands/workspace.mjs +++ b/desktop/cli/commands/workspace.mjs @@ -42,12 +42,18 @@ function voiceOf(options) { function botFields(options) { if (options.instructions !== undefined && options["instructions-file"] !== undefined) throw usage("Give --instructions or --instructions-file, not both."); const voice = voiceOf(options); + let bubbleColor; + if (options["bubble-color"] !== undefined) { + const raw = String(options["bubble-color"]).trim(); + bubbleColor = raw === "" || raw.toLowerCase() === "default" ? "" : raw; + } return { ...(options.name !== undefined && { name: options.name }), ...(options.role !== undefined && { role: options.role }), ...(options.instructions !== undefined && { instructions: options.instructions }), ...(options["instructions-file"] !== undefined && { instructions: fileText(options["instructions-file"]) }), ...(options.model !== undefined && { model: options.model }), + ...(bubbleColor !== undefined && { bubbleColor }), ...(voice !== undefined && { voice }), }; } @@ -56,6 +62,7 @@ const BOT_OPTIONS = { instructions: { type: "string", value: "text", about: "How the bot should work" }, "instructions-file": { type: "string", value: "path", about: "The same, from a file" }, model: { type: "string", value: "provider/model", about: "Its model, as `botkins models` names it (\"\" for the default)" }, + "bubble-color": { type: "string", value: "hex|default", about: "Message bubble color for this bot (#rrggbb, or \"default\" to reset)" }, }; /** The options that give a bot a voice of its own. Only `bots edit` has them. */ const VOICE_OPTIONS = { @@ -308,7 +315,7 @@ export const workspace = { }, add: { summary: "Add a bot", - usage: "botkins bots add [--role ] [--instructions | --instructions-file ] [--model ]", + usage: "botkins bots add [--role ] [--instructions | --instructions-file ] [--model ] [--bubble-color ]", options: BOT_OPTIONS, async run(context) { if (context.args.length !== 1) throw usage("Give the bot a name."); @@ -317,7 +324,7 @@ export const workspace = { }, edit: { summary: "Change a bot", - usage: "botkins bots edit [--name ] [--role ] [--instructions | --instructions-file ] [--model ] [--reading-provider ] [--reading-model ] [--reading-voice ] [--reading-speed <0.5-2>] [--live-provider ] [--live-model ] [--live-voice ] [--same-voice]", + usage: "botkins bots edit [--name ] [--role ] [--instructions | --instructions-file ] [--model ] [--bubble-color ] [--reading-provider ] [--reading-model ] [--reading-voice ] [--reading-speed <0.5-2>] [--live-provider ] [--live-model ] [--live-voice ] [--same-voice]", options: { name: { type: "string", value: "text", about: "A new name" }, ...BOT_OPTIONS, ...VOICE_OPTIONS }, details: "With no option, the bot opens in your editor ($VISUAL, $EDITOR, else vi) as JSON: change its name, role, instructions or model and save. The voice options give the bot a voice of its own, over Settings › Voice: only what you name changes, and an empty value goes back to Settings. The keys stay in Settings › Voice.", async run(context) { diff --git a/desktop/desktop/agents.mjs b/desktop/desktop/agents.mjs index 563fdd0f..2175e0d0 100644 --- a/desktop/desktop/agents.mjs +++ b/desktop/desktop/agents.mjs @@ -38,6 +38,16 @@ export function summaryField(value) { return value.trim(); } +export function bubbleColorField(value) { + if (value === null || value === "") return null; + if (typeof value === "string") { + const trimmed = value.trim(); + if (!trimmed) return null; + if (/^#[0-9a-f]{6}$/i.test(trimmed)) return trimmed.toLowerCase(); + } + throw new Error("Choose a bubble color as #rrggbb, or leave it empty for default."); +} + /** Brings older workspace files up to the agent-management model. Runs on every load. */ export function migrateAgents(state) { state.sections ??= []; diff --git a/desktop/desktop/link/methods.mjs b/desktop/desktop/link/methods.mjs index 15b47d00..ac5a6221 100644 --- a/desktop/desktop/link/methods.mjs +++ b/desktop/desktop/link/methods.mjs @@ -672,14 +672,29 @@ export function remoteArgs(method, args, { deviceId, uploads } = {}) { args = [{ ...args[0], bundle: templateBundle(args[0].bundle) }]; } if (method === "updateBot" && args[1]?.bundle !== undefined) throw new Error("A template bundle is installed when a bot is created."); - // A bot's own voice ("bot-voice-v1"): only the shape the computer keeps; null clears it. Anything else is refused with a sentence. - if ((method === "updateBot" || method === "addBot") && args[method === "addBot" ? 0 : 1]?.voice !== undefined) { + // A bot's own voice ("bot-voice-v1") and bubble color: only the shapes the computer keeps; null/"" clears them. + if (method === "updateBot" || method === "addBot") { const at = method === "addBot" ? 0 : 1; const data = args[at]; - if (data === null || typeof data !== "object" || Array.isArray(data)) return args; - const next = [...args]; - next[at] = { ...data, voice: botVoiceField(data.voice) }; - return next; + if (data && typeof data === "object" && !Array.isArray(data) && (data.voice !== undefined || data.bubbleColor !== undefined)) { + const next = [...args]; + const patched = { ...data }; + if (data.voice !== undefined) patched.voice = botVoiceField(data.voice); + if (data.bubbleColor !== undefined) { + if (data.bubbleColor === null || data.bubbleColor === "") { + patched.bubbleColor = null; + } else if (typeof data.bubbleColor === "string") { + const trimmed = data.bubbleColor.trim(); + if (!trimmed) patched.bubbleColor = null; + else if (/^#[0-9a-f]{6}$/i.test(trimmed)) patched.bubbleColor = trimmed.toLowerCase(); + else throw new Error("Choose a bubble color as #rrggbb, or leave it empty for default."); + } else { + throw new Error("Choose a bubble color as #rrggbb, or leave it empty for default."); + } + } + next[at] = patched; + return next; + } } return fileArgs(method, args) ?? pluginArgs(method, args) ?? marketArgs(method, args) ?? marketV2Args(method, args) ?? catalogArgs(method, args) ?? mcpAppArgs(method, args) ?? claudeArtifactArgs(method, args) ?? providerArgs(method, args) ?? appUpdateArgs(method, args) ?? projectArtifactArgs(method, args) ?? jobArgs(method, args) ?? spaceArgs(method, args) ?? args; } diff --git a/desktop/desktop/preferences.mjs b/desktop/desktop/preferences.mjs index 9f05cdbb..fb8a8b34 100644 --- a/desktop/desktop/preferences.mjs +++ b/desktop/desktop/preferences.mjs @@ -18,6 +18,8 @@ export const DEFAULT_FONT = THEMES.defaultFont; export const TEXT_SIZES = ["small", "default", "large", "larger"]; export const BACKDROPS = ["clean", "mesh", "botkins", "grid"]; export const DEFAULT_BACKDROP = "clean"; +export const AGENT_MESSAGE_MODES = ["canvas", "bubbles"]; +export const DEFAULT_AGENT_MESSAGES = "canvas"; // The theme everyone had before Ink became the usual one. It was saved for everyone, picked or // not, so by itself it doesn't show that a person chose it. const OLD_DEFAULT = "botkins"; @@ -62,6 +64,8 @@ export function appearanceField(saved) { appearance.font = fontPick ?? DEFAULT_FONT; appearance.fontPicked = fontPick != null; if (!(appearance.bubble === "theme" || /^#[0-9a-f]{6}$/i.test(appearance.bubble))) appearance.bubble = "theme"; + if (!AGENT_MESSAGE_MODES.includes(appearance.agentMessages)) appearance.agentMessages = DEFAULT_AGENT_MESSAGES; + if (!(appearance.agentBubble === "theme" || /^#[0-9a-f]{6}$/i.test(appearance.agentBubble))) appearance.agentBubble = "theme"; if (typeof appearance.avatarAnimations !== "boolean") appearance.avatarAnimations = true; return appearance; } @@ -178,6 +182,10 @@ export const defaultSettings = { font: "system", fontPicked: false, bubble: "theme", + // How agent messages are displayed in chats: "canvas" (default) or "bubbles". + agentMessages: DEFAULT_AGENT_MESSAGES, + // Default color for agent message bubbles: "theme" or a #rrggbb hex color. + agentBubble: "theme", // Large avatars draw a still pose while idle; active and outcome states can move. avatarAnimations: true, // Background presets from before themes. Kept as saved, for an earlier version to read. @@ -284,6 +292,11 @@ export function changeSettings(settings, patch) { !( appearance.bubble === "theme" || /^#[0-9a-f]{6}$/i.test(appearance.bubble) + ) || + !AGENT_MESSAGE_MODES.includes(appearance.agentMessages) || + !( + appearance.agentBubble === "theme" || + /^#[0-9a-f]{6}$/i.test(appearance.agentBubble) ) ) throw new Error("Invalid appearance choice"); diff --git a/desktop/desktop/terminal/control-prefs.mjs b/desktop/desktop/terminal/control-prefs.mjs index 093b9256..ef40cea5 100644 --- a/desktop/desktop/terminal/control-prefs.mjs +++ b/desktop/desktop/terminal/control-prefs.mjs @@ -10,7 +10,7 @@ // and got a yes. The command line does that (`--yes`, or the question at a terminal). A caller that is the // person gives the mark itself. import { backgroundField } from "../startup.mjs"; -import { appearanceField, BACKDROPS, clarificationPrompts, defaultSettings, FONT_IDS, sidebarField, SIDEBAR, TEXT_SIZES, THEME_IDS, TOOL_CALL_TIMEOUT_MAX } from "../preferences.mjs"; +import { AGENT_MESSAGE_MODES, appearanceField, BACKDROPS, clarificationPrompts, defaultSettings, FONT_IDS, sidebarField, SIDEBAR, TEXT_SIZES, THEME_IDS, TOOL_CALL_TIMEOUT_MAX } from "../preferences.mjs"; import { HARNESSES } from "../harness/index.mjs"; import { AUTO_SUMMARIZE_MAX, AUTO_SUMMARIZE_MIN } from "../summaries.mjs"; import { MAC_LEVELS, MAC_TOOLS } from "../mactools.mjs"; @@ -45,6 +45,8 @@ export const PREFERENCES = { "appearance.textSize": choice(TEXT_SIZES, "The size of the text"), "appearance.font": choice(FONT_IDS, "The font"), "appearance.bubble": { type: "color", about: "The color of your messages: theme, or a color such as #3366cc" }, + "appearance.agentMessages": choice(AGENT_MESSAGE_MODES, "How agent messages are shown: canvas or bubbles"), + "appearance.agentBubble": { type: "color", about: "The default color of agent message bubbles: theme, or a color such as #3366cc" }, "appearance.avatarAnimations": switches("Animate bot avatars while they work"), foldTools: switches("For older apps: fold the steps of a finished reply into one line (each window's Steps setting is in Settings › Chat)"), showThinking: switches("Show the bot's thinking; off hides it in each window where nobody picked Thinking in Settings › Chat"), diff --git a/desktop/desktop/terminal/control.mjs b/desktop/desktop/terminal/control.mjs index 7dcd937b..68744490 100644 --- a/desktop/desktop/terminal/control.mjs +++ b/desktop/desktop/terminal/control.mjs @@ -121,6 +121,7 @@ export function controlApi(service) { instructions: entry.instructions, ...(entry.model && { model: entry.model }), ...(entry.voice && { voice: entry.voice }), + ...(entry.bubbleColor && { bubbleColor: entry.bubbleColor }), ...(entry.primary && { primary: true }), chats: state().chats.filter((chat) => chat.botId === entry.id && !chat.temporary).length, working: state().chats.some((chat) => chat.botId === entry.id && workspace.active.has(chat.id)), @@ -456,6 +457,7 @@ export function controlApi(service) { role: entry.role ?? "", ...(entry.model && { model: entry.model }), ...(entry.voice && { voice: entry.voice }), + ...(entry.bubbleColor && { bubbleColor: entry.bubbleColor }), ...(entry.primary && { primary: true }), chats: (snapshot.chats ?? []).filter((chat) => chat.botId === entry.id && !chat.temporary).length, working: (snapshot.chats ?? []).some((chat) => chat.botId === entry.id && Boolean(snapshot.active?.[chat.id])), @@ -475,6 +477,7 @@ export function controlApi(service) { name, role: typeof data.role === "string" && data.role.trim() ? data.role : "Assistant", instructions: typeof data.instructions === "string" && data.instructions.trim() ? data.instructions : "Help with what you are asked, clearly and briefly.", + ...(data.bubbleColor !== undefined && { bubbleColor: data.bubbleColor }), }); if (model) await workspace.setModel("bot", id, model); return botView(bot(id)); @@ -482,7 +485,7 @@ export function controlApi(service) { async "bots.edit"([ref, patch = {}]) { const found = bot(ref); const fields = {}; - for (const key of ["name", "role", "instructions"]) if (patch[key] !== undefined) fields[key] = patch[key]; + for (const key of ["name", "role", "instructions", "bubbleColor"]) if (patch[key] !== undefined) fields[key] = patch[key]; // A voice of its own: what is named changes and the rest stays; "" goes back to Settings › Voice; null clears it all. if (patch.voice !== undefined) fields.voice = patch.voice === null ? null : mergeVoice(found.voice, patch.voice); if (Object.keys(fields).length) handlers.updateBot(found.id, fields); diff --git a/desktop/desktop/workspace.mjs b/desktop/desktop/workspace.mjs index 73f122f8..35c067cf 100644 --- a/desktop/desktop/workspace.mjs +++ b/desktop/desktop/workspace.mjs @@ -85,7 +85,7 @@ import { validateAttachments, } from "./canvas.mjs"; import { holderSessions, migrateChatSessions, migrateSessionHolder } from "./providers/sessions.mjs"; -import { Agents, instructionsField, migrateAgents, summaryField } from "./agents.mjs"; +import { Agents, bubbleColorField, instructionsField, migrateAgents, summaryField } from "./agents.mjs"; import { linkLooks, lookField, migrateLooks, nextLook } from "./looks.mjs"; import { starterById } from "./starters.mjs"; import { botVoiceField } from "./link/voice.mjs"; @@ -954,6 +954,10 @@ export class Workspace { // A voice of the bot's own (desktop/link/voice.mjs, botVoiceField): checked here, and kept only when something is set. const voice = data.voice === undefined ? null : botVoiceField(data.voice); if (voice) bot.voice = voice; + if (data.bubbleColor !== undefined) { + const bubbleColor = bubbleColorField(data.bubbleColor); + if (bubbleColor) bot.bubbleColor = bubbleColor; + } if (person !== "owner") bot.createdBy = person; return this.installBot(bot, data.bundle, undefined, opts); } @@ -1010,6 +1014,11 @@ export class Workspace { if (voice) bot.voice = voice; else delete bot.voice; } + if (data.bubbleColor !== undefined) { + const bubbleColor = bubbleColorField(data.bubbleColor); + if (bubbleColor) bot.bubbleColor = bubbleColor; + else delete bot.bubbleColor; + } this.save(); } mainChat(botId, person = "owner") { diff --git a/desktop/src/BotProfile.tsx b/desktop/src/BotProfile.tsx index 0ad770eb..76a623bb 100644 --- a/desktop/src/BotProfile.tsx +++ b/desktop/src/BotProfile.tsx @@ -22,6 +22,7 @@ import { import { BotAvatar, activityLabel, botActivity } from "./Avatar"; import { BotStudio } from "./BotStudio"; import { availableHeads, lookOf, sameLook } from "./botkins"; +import { AGENT_BUBBLE_SWATCHES, inkOn } from "./themes"; import ModelPicker from "./ModelPicker"; import { openProviderSettings } from "./providers"; import { ChatRow, deleteBot, keepsMainChats, useAsk, type PageActions } from "./Pages"; @@ -123,8 +124,10 @@ export default function BotProfile({ role: bot.role, summary: bot.summary ?? "", instructions: bot.instructions, + bubbleColor: bot.bubbleColor ?? "", }; const [draft, setDraft] = useState(initial); + const [customBubbleHex, setCustomBubbleHex] = useState(bot.bubbleColor || AGENT_BUBBLE_SWATCHES[1].hex); const [look, setLook] = useState(() => lookOf(bot)); const [editAvatar, setEditAvatar] = useState(false); const [avatarSaving, setAvatarSaving] = useState(false); @@ -142,9 +145,11 @@ export default function BotProfile({ const panels = state.panels.filter((p) => p.botId === bot.id && !p.hidden).length; const own = lookOf(bot); const lookChanged = !sameLook(look, own); + const bubbleColorChanged = draft.bubbleColor.trim().toLowerCase() !== initial.bubbleColor.trim().toLowerCase(); const dirty = lookChanged || - (Object.keys(initial) as (keyof typeof initial)[]).some((k) => draft[k].trim() !== initial[k].trim()); + bubbleColorChanged || + (["name", "role", "summary", "instructions"] as const).some((k) => draft[k].trim() !== initial[k].trim()); const valid = draft.name.trim() && draft.role.trim() && draft.instructions.trim(); const field = (k: keyof typeof draft) => ({ value: draft[k], @@ -163,6 +168,7 @@ export default function BotProfile({ summary: draft.summary.trim(), instructions: draft.instructions.trim(), ...(lookChanged ? { look } : {}), + ...(bubbleColorChanged ? { bubbleColor: draft.bubbleColor.trim() || null } : {}), }); setSaved(true); setEditAvatar(false); @@ -296,6 +302,63 @@ export default function BotProfile({ Instructions