Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Show Teach a task and Library in Advanced mode (#4258)
Aditya Umale3ca2e152a768
diff --git a/src/components/BotSettingsDialog.library.test.ts b/src/components/BotSettingsDialog.library.test.tsnew file mode 100644index 0000000000..292bd37248--- /dev/null+++ b/src/components/BotSettingsDialog.library.test.ts@@ -0,0 +1,50 @@+// @vitest-environment happy-dom+import { createElement } from "react";+import { renderToStaticMarkup } from "react-dom/server";+import { describe, expect, it, vi } from "vitest";++import type { Bot } from "@/state/store";++// Advanced mode's fold-out settings list Library too, with what the bot made, as Simple mode's panel does.+vi.mock("@/lib/interface-mode", () => ({ useAdvancedMode: () => true, setAdvancedMode: () => {} }));+vi.mock("@/lib/use-owner-or-admin", () => ({ useOwnerOrAdmin: () => false }));+vi.mock("./bot-settings/useSlackManagement", () => ({ useSlackManagementUrl: () => null }));+vi.mock("./bot-settings/useBotSettingsDerived", () => ({ useBotSettingsDerived: () => ({}) }));+const fixture = vi.hoisted(() => ({ dispatch: vi.fn(), onOpen: undefined as undefined | ((page: string) => void) }));+vi.mock("@/state/store", async (importOriginal) => {+ const store = await importOriginal<typeof import("@/state/store")>();+ const state = { ...store.initialState, botSettingsSection: "library", botSettingsExpandAccordion: true };+ return { ...store, useStore: () => ({ state, dispatch: fixture.dispatch, flushBotPatches: vi.fn() }) };+});+vi.mock("./bot-panel/LibraryTab", async (importOriginal) => {+ const original = await importOriginal<typeof import("./bot-panel/LibraryTab")>();+ return {+ ...original,+ LibraryTab: (props: Parameters<typeof original.LibraryTab>[0]) => {+ fixture.onOpen = props.onOpen as (page: string) => void;+ return original.LibraryTab(props);+ },+ };+});+import { BotSettingsDialog } from "./BotSettingsDialog";+import { DesktopCapabilitiesProvider } from "./DesktopCapabilities";++const bot = { id: "bot-1", name: "Maily", threadId: "bot-1-main", messages: [], tasks: [] } as never as Bot;+const html = () => renderToStaticMarkup(createElement(DesktopCapabilitiesProvider, null, createElement(BotSettingsDialog, { bot })));++describe("Advanced bot settings", () => {+ it("has a Library section that shows the bot's library when open", () => {+ const markup = html();+ expect(markup).toContain('data-bot-settings-section="library"');+ expect(markup).toContain('data-panel-tabpanel="library"');+ });++ it("opens the matching settings section from each Library row", () => {+ html();+ for (const [page, section] of [["memory", "memory"], ["skills", "skills"], ["folder", "access"], ["apps", "overview"]]) {+ fixture.dispatch.mockClear();+ fixture.onOpen!(page);+ expect(fixture.dispatch).toHaveBeenCalledWith({ type: "toggleSettings", open: true, section });+ }+ });+});diff --git a/src/components/BotSettingsDialog.tsx b/src/components/BotSettingsDialog.tsxindex 01723f2b07..d99079c7a5 100644--- a/src/components/BotSettingsDialog.tsx+++ b/src/components/BotSettingsDialog.tsx@@ -1,7 +1,7 @@import { useEffect, useRef, useState } from "react";import { ChevronDown, Search, X } from "lucide-react";-import { useStore, type Bot } from "@/state/store";+import { useStore, type Bot, type BotSettingsSection } from "@/state/store";import { cn } from "@/lib/cn";import { useCaptionChrome } from "./DesktopCapabilities";import { BOT_SECTIONS } from "./bot-settings/sections";@@ -24,11 +24,16 @@ import { VisibilitySection } from "./bot-settings/VisibilitySection";import { t } from "@/lib/i18n";import { useAdvancedMode } from "@/lib/interface-mode";import { BotPanel } from "./bot-panel/PanelShell";+import { LibraryTab } from "./bot-panel/LibraryTab";+import type { SimplePageId } from "./bot-panel/page-registry";import { BOT_PANEL_ID, sidePanelCls } from "./bot-panel/side-panel";import { HistoryRollbackDialog, useBotHistory, useBotOverview } from "./bot-settings/useBotOverview";import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";import { ShareBotButton, useTeamName } from "./bot-access/ShareBotButton";+/** Where the Library's memory, skills and folder rows lead in Advanced settings. */+const LIBRARY_LINKS: Partial<Record<SimplePageId, BotSettingsSection>> = { memory: "memory", skills: "skills", folder: "access" };+const sectionLabel = (entry: (typeof BOT_SECTIONS)[number]) => (entry.labelKey ? t(entry.labelKey) : entry.label);function sectionMatches(entry: (typeof BOT_SECTIONS)[number], query: string): boolean {@@ -131,6 +136,8 @@ export function BotSettingsDialog({ bot, overlay = false }: {return <SkillsSection bot={bot} />;case "memory":return <MemorySection bot={bot} active={!collapsed && section === "memory"} onToggle={(enabled) => derived.patch({ memoryEnabled: enabled })} />;+ case "library":+ return <LibraryTab bot={bot} onOpen={(page) => dispatch({ type: "toggleSettings", open: true, section: LIBRARY_LINKS[page] ?? "overview" })} />;case "routines":return <RoutinesSection bot={bot} routines={derived.botRoutines} runs={state.routineRuns} />;case "access":diff --git a/src/components/Composer.phone.test.ts b/src/components/Composer.phone.test.tsindex dff1897ac3..ec8a761441 100644--- a/src/components/Composer.phone.test.ts+++ b/src/components/Composer.phone.test.ts@@ -107,7 +107,7 @@ describe("the phone composer", () => {expect(fixture.call).toMatchObject({ inverse: true });openPlus();const keys = [...menu()!.querySelectorAll("[data-menu-key]")].map((row) => row.getAttribute("data-menu-key"));- expect(keys).toEqual(expect.arrayContaining(["attach", "place", "approval", "call:turns", "call:live"]));+ expect(keys).toEqual(expect.arrayContaining(["attach", "teach", "place", "approval", "call:turns", "call:live"]));expect(item("place")?.textContent).toContain("Works on");});diff --git a/src/components/Composer.simple.test.ts b/src/components/Composer.simple.test.tsindex 1c526995af..93c25ed6cf 100644--- a/src/components/Composer.simple.test.ts+++ b/src/components/Composer.simple.test.ts@@ -14,6 +14,7 @@ import { BOT_BUTTON, botButtonTone } from "@/lib/bot-button";const fixture = vi.hoisted(() => ({advanced: false,+ agentsMcp: true,dispatch: vi.fn(),call: null as Record<string, unknown> | null,groupCall: null as Record<string, unknown> | null,@@ -25,7 +26,7 @@ vi.mock("@/state/store", async (importOriginal) => {const original = await importOriginal<typeof import("@/state/store")>();return { ...original, useStore: () => ({state: { ...original.initialState, config: fixture.config ?? original.initialState.config, bots: [bot, peer], liveCall: fixture.liveCall, instances: [{- instanceId: ENGINE, driverKind: "claudeAgent", displayName: "Claude", capabilities: { agentsMcp: true },+ instanceId: ENGINE, driverKind: "claudeAgent", displayName: "Claude", capabilities: { agentsMcp: fixture.agentsMcp },}] },dispatch: fixture.dispatch,}) };@@ -86,6 +87,7 @@ function openPlus() {beforeEach(() => {fixture.advanced = false;+ fixture.agentsMcp = true;fixture.liveCall = null;fixture.config = undefined;setCallMode("turns");@@ -298,6 +300,30 @@ describe("the Advanced composer", () => {expect(container.querySelector("[data-composer-backdrop]")!.className.split(" ")).toContain("top-1/2");});+ it("offers Teach a task as its own button, which starts a /learn draft ahead of anything typed", () => {+ fixture.advanced = true;+ restoreComposerDraft(`bot:${bot.id}:${bot.threadId}`, { text: "how I file expenses", attachments: [] });+ render({ bot });+ const teach = container.querySelector<HTMLButtonElement>('button[aria-label="Teach a task"]');+ expect(teach).not.toBeNull();+ click(teach);+ expect(container.querySelector("textarea")!.value).toBe("/learn how I file expenses");+ });++ it("leaves Teach a task out when skill authoring is off", () => {+ fixture.advanced = true;+ fixture.config = { features: { skillAuthoring: false } };+ render({ bot });+ expect(container.querySelector('button[aria-label="Teach a task"]')).toBeNull();+ });++ it("leaves Teach a task out when the bot's engine can't run agents", () => {+ fixture.advanced = true;+ fixture.agentsMcp = false;+ render({ bot });+ expect(container.querySelector('button[aria-label="Teach a task"]')).toBeNull();+ });+it("sends with the bot's own button too, and keeps the accent in a room", () => {fixture.advanced = true;restoreComposerDraft(`bot:${bot.id}:${bot.threadId}`, { text: "hello", attachments: [] });diff --git a/src/components/Composer.tsx b/src/components/Composer.tsxindex a5005074b2..d0408f8930 100644--- a/src/components/Composer.tsx+++ b/src/components/Composer.tsx@@ -1,7 +1,7 @@import { directMessageSent, roomMessageSent } from "@/lib/product-events";import { useComposerDictation } from "@/lib/use-composer-dictation";import { useCallback, useEffect, useMemo, useRef, useState, type SetStateAction } from "react";-import { Mic, Paperclip, Square, X } from "lucide-react";+import { GraduationCap, Mic, Paperclip, Square, X } from "lucide-react";import { useStore, visibleMessages, currentTaskBot, type Bot, type Group, type InstanceInfo, type Message } from "@/state/store";import { cn } from "@/lib/cn";import { PHONE_LAYOUT, useMediaQuery } from "@/lib/use-media-query";@@ -792,7 +792,7 @@ export function Composer({<PhonePlusonAttach={() => fileInput.current?.click()}goal={goal}- teach={!advanced && canLearn ? teachTask : undefined}+ teach={canLearn ? teachTask : undefined}approval={approvalChoice && modeBot && { name: modeBot.name, choice: approvalChoice }}callBotId={bot && !group ? bot.id : undefined}place={modeBot && !remoteClient && advanced ? {@@ -830,6 +830,15 @@ export function Composer({><Paperclip size={16} strokeWidth={1.75} absoluteStrokeWidth /></button>}+ {advanced && canLearn && <button+ type="button"+ onClick={teachTask}+ aria-label={t("composer.teachTask")}+ title={t("composer.teachTask")}+ className="flex size-8 shrink-0 items-center justify-center rounded-full text-ink-secondary hover:bg-control hover:text-ink"+ >+ <GraduationCap size={16} strokeWidth={1.75} absoluteStrokeWidth />+ </button>}{/* Simple mode shows a mode's chip only while it is on, so a choice made in the + menu or the bot panel stays in view. */}{goal && (advanced || goal.on) && <GoalToggle {...goal} compact={simpleDock} />}{advanced && approvalChoice && <ApprovalModeSelector {...approvalChoice} />}diff --git a/src/components/bot-panel/page-registry.ts b/src/components/bot-panel/page-registry.tsindex 4198322860..390d25e8a1 100644--- a/src/components/bot-panel/page-registry.ts+++ b/src/components/bot-panel/page-registry.ts@@ -78,6 +78,7 @@ const SECTION_TARGET: Record<BotSettingsSection, PanelTarget> = {soul: { tab: "details", page: "settings", anchor: "instructions", editInstructions: true },skills: { tab: "library", page: "skills" },memory: { tab: "library", page: "memory" },+ library: { tab: "library" },routines: { tab: "details", page: "routines" },access: { tab: "computer" },model: { tab: "details", anchor: "model" },diff --git a/src/components/bot-settings/sections.ts b/src/components/bot-settings/sections.tsindex 5645702132..e96355e36a 100644--- a/src/components/bot-settings/sections.ts+++ b/src/components/bot-settings/sections.ts@@ -7,6 +7,7 @@ import {Eye,History,LayoutDashboard,+ Library,type LucideIcon,Mic,Network,@@ -32,6 +33,7 @@ export const BOT_SECTIONS: Array<{{ id: "soul", label: "Soul", labelKey: "botSettings.sections.soul", icon: Sparkles, keywords: ["standing instructions", "instructions", "persona", "rules", "soul.md"] },{ id: "skills", label: "Skills", labelKey: "botSettings.sections.skills", icon: BookOpen, keywords: ["skills", "learned", "procedures", "teach"] },{ id: "memory", label: "Memory", labelKey: "botSettings.sections.memory", icon: Brain, keywords: ["memory", "notes", "remember", "topics"] },+ { id: "library", label: "Library", labelKey: "botPanel.tab.library", icon: Library, keywords: ["library", "made", "pages", "apps", "files", "published"] },{ id: "routines", label: "Routines", labelKey: "botSettings.sections.routines", icon: CalendarClock, keywords: ["schedule", "routines", "cron", "tasks"] },{ id: "access", label: "Access", labelKey: "botSettings.sections.access", icon: Network, keywords: ["works on", "computer", "vm", "cloud", "vps", "folder", "workspace", "browser", "connected apps", "composio", "webhooks", "always allow", "grants", "tool selection", "tools", "mcp", "allow", "exclude"] },{ id: "model", label: "Model", labelKey: "botSettings.sections.model", icon: Cpu, keywords: ["engine", "model", "provider", "cli", "effort"] },diff --git a/src/lib/last-bot-section.ts b/src/lib/last-bot-section.tsindex d05d2c7e8f..481da75093 100644--- a/src/lib/last-bot-section.ts+++ b/src/lib/last-bot-section.ts@@ -9,6 +9,7 @@ export const BOT_SETTINGS_SECTION_IDS: readonly BotSettingsSection[] = ["soul","skills","memory",+ "library","routines","access","model",diff --git a/src/state/store.tsx b/src/state/store.tsxindex f3dfd54cf8..7b552bdc5d 100644--- a/src/state/store.tsx+++ b/src/state/store.tsx@@ -535,6 +535,7 @@ export type BotSettingsSection =| "soul"| "skills"| "memory"+ | "library"| "routines"| "access"| "model"