Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

One list: a short preview line for a bot in the other place

milind-soni44dbdd3c2c55
diff --git a/electron/places-together.d.mts b/electron/places-together.d.mts
index 454312fba4..5d473173a9 100644
--- a/electron/places-together.d.mts
+++ b/electron/places-together.d.mts
@@ -21,6 +21,9 @@ export interface PlaceBotRow {
waiting?: true;
working?: true;
unread?: true;
+ /** The start of its newest message while that is words said (at most PREVIEW_MAX characters, Markdown as written):
+ * its second line in the one list, as this page's own rows show theirs. Absent for a step, a card or a file. */
+ preview?: string;
/** Epoch ms its conversations last moved there (the newest thread's `updatedAt`): Unread's order across places. */
lastAt?: number;
}
@@ -66,4 +69,6 @@ export interface NewBotChoice {
}
export const PLACES_TOGETHER_FILE: string;
+export const PREVIEW_MAX: number;
+export const PREVIEW_LOOK: number;
export function otherHome(asking: "local" | "cloud" | BotHome): BotHome;
diff --git a/electron/places-together.mjs b/electron/places-together.mjs
index edc6c5dea2..4be63bc839 100644
--- a/electron/places-together.mjs
+++ b/electron/places-together.mjs
@@ -4,8 +4,9 @@
// clicked. With the switch off nothing here reads, keeps or sends anything.
//
// Security: the list goes only to this computer's own page and to My Cloud's own page (`asking`, which main works out from
-// the sender), never to a team's Cloud or a server saved by hand. A row is a name, a look and a state: no message, address
-// or token. A page names a bot by an id main listed itself; main opens only such an id, in a place of its own choosing.
+// the sender), never to a team's Cloud or a server saved by hand. A row is a name, a look, a state and, as the person's
+// own two pages show each other, a short preview of the bot's newest line (PREVIEW_MAX characters of plain words; never a
+// step, a card, a file or another bot's note): no whole message, address or token. A page names a bot by an id main listed itself; main opens only such an id, in a place of its own choosing.
// A sleeping Cloud is never asked, since any request would wake it; it keeps the list it gave last.
import { asleepAnswer, BACKGROUND_HEADERS } from "./cloud-power.mjs";
@@ -24,6 +25,10 @@ export const NEW_BOT_WAIT_MS = 45_000;
/** The page that was told to make a new bot says it heard within this long, or is told to forget it. */
export const NEW_BOT_ACK_MS = 10_000;
const TIMEOUT_MS = 10_000;
+/** The most of a bot's newest line a row carries: the sidebar shows one truncated line of it. */
+export const PREVIEW_MAX = 300;
+/** A line another bot sent is stored with this note in front (src/lib/peer-message.ts): never shown as the person's. */
+const PEER_NOTE = /^\[(?:From @|Message from @|Delegated by @|Thread opened by @)/;
const MAX_BOTS = 500;
const ID = /^[\w-]{1,128}$/;
const COLOR = /^[\w#(),.% -]{1,64}$/;
@@ -52,15 +57,34 @@ function rowState(bot) {
return { ...(waiting ? { waiting: true } : {}), ...(working ? { working: true } : {}), ...(unread ? { unread: true } : {}), ...(lastAt !== null ? { lastAt } : {}) };
}
+/** Kinds a row looks past for the newest words said: a turn's work summary, a condensed-history marker and its steps, as
+ * the sidebar's own preview does in Simple. */
+const LOOKED_PAST = new Set(["digest", "compaction", "activity"]);
+/** How many of a bot's newest messages a read carries to find them. */
+export const PREVIEW_LOOK = 3;
+
+/** The start of the newest words the person or the bot said, looking past a turn's steps and summary: what the row's
+ * second line shows, as this page's own rows do in Simple. Nothing when the newest thing is a card, a screen, a file, a
+ * voice note, a setup line or another bot's note, which stay on their own page. */
+export function previewOf(bot) {
+ const messages = Array.isArray(bot.messages) ? bot.messages : [];
+ const last = messages.findLast((message) => !(record(message) && LOOKED_PAST.has(message.kind))) ?? null;
+ if (!record(last) || last.kind !== "text" || (last.role !== "bot" && last.role !== "user") || typeof last.text !== "string") return null;
+ if (last.attachments?.length || last.setupSuggestion || last.helperIntro || last.peerAsk || last.relay || last.comm || last.threadRef || last.roomRequest) return null;
+ if (last.role === "user" && PEER_NOTE.test(last.text)) return null;
+ const line = last.text.trim().slice(0, PREVIEW_MAX);
+ return line || null;
+}
+
/** One bot of the other place as its row: who it is, how it looks and how it is doing. A bot that is archived, hidden
* from the sidebar, or only the pointer a move left behind, has no row. */
export function botRow(bot, home) {
if (!record(bot) || !ID.test(String(bot.id)) || !ID.test(String(bot.threadId)) || bot.hidden || bot.sidebarHidden || bot.movedTo) return null;
const name = text(bot.name, 80);
if (!name) return null;
- const title = text(bot.title, 80), color = look(bot.color), body = look(bot.mascotBody), face = look(bot.mascotFaceColor), tint = look(bot.mascotBodyColor), fur = look(bot.mascotMaterial);
+ const title = text(bot.title, 80), preview = previewOf(bot), color = look(bot.color), body = look(bot.mascotBody), face = look(bot.mascotFaceColor), tint = look(bot.mascotBodyColor), fur = look(bot.mascotMaterial);
return { home, id: bot.id, threadId: bot.threadId, name, ...(title ? { title } : {}), ...(color ? { color } : {}),
- ...(body ? { mascotBody: body } : {}), ...(face ? { mascotFaceColor: face } : {}), ...(tint ? { mascotBodyColor: tint } : {}), ...(fur ? { mascotMaterial: fur } : {}), ...(bot.chiefOfStaff === true ? { chief: true } : {}), ...rowState(bot) };
+ ...(body ? { mascotBody: body } : {}), ...(face ? { mascotFaceColor: face } : {}), ...(tint ? { mascotBodyColor: tint } : {}), ...(fur ? { mascotMaterial: fur } : {}), ...(bot.chiefOfStaff === true ? { chief: true } : {}), ...(preview ? { preview } : {}), ...rowState(bot) };
}
/** The AIs a place's `GET /api/instances` answer says are ready to use: installed and signed in, never one that only
@@ -173,7 +197,8 @@ export function createPlacesTogether({ pref, onlyPair = () => false, switched =
if (had) tell();
}
- async function ask(home, route = "/api/bots?messages=0") {
+ // A bot's newest few messages, for its preview (previewOf); nothing more of them is kept.
+ async function ask(home, route = `/api/bots?messages=${PREVIEW_LOOK}`) {
const signal = AbortSignal.timeout(TIMEOUT_MS);
if (home === "computer") return local(route, { signal, headers: { accept: "application/json" } });
const { origin } = cloud();
diff --git a/electron/places-together.node-test.mjs b/electron/places-together.node-test.mjs
index 6758bd1300..0f965e0b9a 100644
--- a/electron/places-together.node-test.mjs
+++ b/electron/places-together.node-test.mjs
@@ -5,7 +5,7 @@ import test from "node:test";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";
-import { botRow, botRows, CLOUD_EVERY_MS, createPlacesTogether, FRESH_MS, installPlacesTogether, LOOK_EVERY_MS, OPEN_WAIT_MS, makesNewBots, NEW_BOT_ACK_MS, NEW_BOT_WAIT_MS, otherHome, parseTogether, readyAis } from "./places-together.mjs";
+import { botRow, botRows, PREVIEW_MAX, previewOf, CLOUD_EVERY_MS, createPlacesTogether, FRESH_MS, installPlacesTogether, LOOK_EVERY_MS, OPEN_WAIT_MS, makesNewBots, NEW_BOT_ACK_MS, NEW_BOT_WAIT_MS, otherHome, parseTogether, readyAis } from "./places-together.mjs";
const HERE = dirname(fileURLToPath(import.meta.url));
const CLOUD = "https://mine.cloud.test";
@@ -68,7 +68,7 @@ test("on: this computer's page lists My Cloud's bots, asked as background work w
], newBot: true });
assert.deepEqual(f.asked.map(([side]) => side), ["admin", "cloud"], "the Admin is asked whether it sleeps first, then My Cloud, once");
const [, url, init] = f.asked[1];
- assert.deepEqual([url, init.headers["x-omb-background"], init.credentials, init.redirect], [`${CLOUD}/api/bots?messages=0`, "1", "include", "error"]);
+ assert.deepEqual([url, init.headers["x-omb-background"], init.credentials, init.redirect], [`${CLOUD}/api/bots?messages=3`, "1", "include", "error"]);
assert.equal(f.changes, 1);
});
@@ -100,7 +100,7 @@ test("My Cloud's page lists this computer's bots the same way", async () => {
f.together.state("cloud");
await f.together.refresh("computer");
assert.deepEqual(f.together.state("cloud").other.bots.map((row) => [row.home, row.id]), [["computer", "scout"]]);
- assert.deepEqual(f.asked.map(([side, route]) => [side, route]), [["computer", "/api/bots?messages=0"]]);
+ assert.deepEqual(f.asked.map(([side, route]) => [side, route]), [["computer", "/api/bots?messages=3"]]);
assert.equal(otherHome("cloud"), "computer");
assert.equal(otherHome("local"), "cloud");
});
@@ -397,7 +397,7 @@ test("without a My Cloud, or once this computer's bots moved away, there is noth
assert.equal(f.asked.length, 0);
});
-test("a row is a name, a look and a state: no messages, and no row for an archived bot or a move's pointer", () => {
+test("a row is a name, a look and a state: no whole message, and no row for an archived bot or a move's pointer", () => {
const full = bot("scout", " Scout ", { title: "Research", messages: [{ text: "secret" }], soul: "secret", modelSelection: { instanceId: "x" }, chiefOfStaff: true,
tasks: [{ threadId: "t1", unread: true }, { threadId: "t2", activity: "waiting-on-you" }, { threadId: "t3", busy: true, routineRunId: "r" }] });
assert.deepEqual(botRow(full, "cloud"), { home: "cloud", id: "scout", threadId: "t-scout", name: "Scout", title: "Research", color: "blue", mascotBody: "classic", chief: true, waiting: true, unread: true });
@@ -411,6 +411,28 @@ test("a row is a name, a look and a state: no messages, and no row for an archiv
assert.deepEqual(botRows(null, "cloud"), []);
});
+test("a row carries the start of its bot's newest line while that is words said, and nothing of a step, card, file or another bot's note", () => {
+ const said = (message) => botRow(bot("scout", "Scout", { messages: [{ id: "m1", role: "bot", kind: "text", text: "old" }, { id: "m2", ...message }] }), "cloud").preview;
+ assert.equal(said({ role: "bot", kind: "text", text: " Filed the **March** invoices.\n" }), "Filed the **March** invoices.");
+ assert.equal(said({ role: "user", kind: "text", text: "Can you file them?" }), "Can you file them?");
+ assert.equal(said({ role: "bot", kind: "text", text: "x".repeat(PREVIEW_MAX + 50) }).length, PREVIEW_MAX);
+ const afterWork = botRow(bot("w", "Worker", { messages: [{ role: "user", kind: "text", text: "Run it" }, { role: "bot", kind: "text", text: "Done: all green." },
+ { role: "bot", kind: "activity", tool: { name: "bash", output: "secret" } }, { role: "bot", kind: "digest", text: "[digest] · tools: Bash" }] }), "cloud");
+ assert.equal(afterWork.preview, "Done: all green.", "a turn's steps and summary are looked past, as the sidebar's own preview does");
+ for (const message of [
+ { role: "bot", kind: "options", text: "Pick one", card: { title: "Pick" } },
+ { role: "bot", kind: "screen", text: "screenshot" },
+ { role: "user", kind: "text", text: "a photo", attachments: [{ kind: "image", path: "/api/attachments/x", mime: "image/png" }] },
+ { role: "user", kind: "text", text: "[From @Scout (bot) · message · a1] please check" },
+ { role: "user", kind: "text", text: "asked", peerAsk: { name: "Scout" } },
+ { role: "bot", kind: "text", text: "Set up a key", setupSuggestion: { kind: "helperKey" } },
+ { role: "bot", kind: "text", text: " " },
+ { role: "system", kind: "text", text: "internal" },
+ ]) assert.equal(said(message), undefined, JSON.stringify(message));
+ assert.equal(previewOf(bot("none", "None")), null);
+ assert.equal("preview" in botRow(bot("none", "None", { messages: [] }), "cloud"), false);
+});
+
test("a row carries when its conversations last moved there: their own times, never a word of them and never a routine run's", () => {
const row = botRow(bot("scout", "Scout", { tasks: [{ threadId: "t1", updatedAt: 3_000 }, { threadId: "t2", updatedAt: 9_000 }, { threadId: "t3", updatedAt: 99_000, routineRunId: "r" },
{ threadId: "t4", updatedAt: 50_000, archivedAt: 1 }, { threadId: "t5", updatedAt: "soon" }] }), "cloud");
diff --git a/src/components/Sidebar.one-list.dom.test.ts b/src/components/Sidebar.one-list.dom.test.ts
index 2ded6d4e37..c2d8f9b04d 100644
--- a/src/components/Sidebar.one-list.dom.test.ts
+++ b/src/components/Sidebar.one-list.dom.test.ts
@@ -34,7 +34,7 @@ const bot = (id: string, extra: Partial<Bot> = {}): Bot => ({
});
const row = (id: string, over: Partial<PlaceBotRow> = {}): PlaceBotRow => ({ home: "cloud", id, threadId: `t-${id}`, name: id[0]!.toUpperCase() + id.slice(1), color: "blue", ...over });
const said = (over: Partial<PlacesTogetherState> = {}): PlacesTogetherState => ({ v: 1, available: true, on: true, here: "computer",
- other: { home: "cloud", state: "ready", bots: [row("scout", { title: "Open issues" }), row("tech", { unread: true, title: "Deploy check", lastAt: 9_000 })] }, ...over });
+ other: { home: "cloud", state: "ready", bots: [row("scout", { title: "Open issues" }), row("tech", { unread: true, title: "Deploy check", lastAt: 9_000, preview: "Deploy **passed** on staging." })] }, ...over });
const OWN = [bot("mausbot", { chiefOfStaff: true }), bot("git"), bot("ledger")];
const dispatch = vi.fn();
@@ -119,6 +119,7 @@ describe("switch on: one list", () => {
expect([...host.querySelectorAll("[data-section]")].map((header) => header.getAttribute("data-section"))).not.toContain("On My Cloud");
expect(q("[data-other-place]")).toBeNull();
expect(q('[data-sidebar-bot-row="cloud:scout"]')!.textContent).toContain("Open issues");
+ expect(q('[data-sidebar-bot-row="cloud:tech"]')!.textContent).toContain("Deploy passed on staging.");
});
it("unread rows of both places share the one Unread group, newest first", async () => {
diff --git a/src/lib/place-rows.test.ts b/src/lib/place-rows.test.ts
index 0e4e5d3c5c..719036574c 100644
--- a/src/lib/place-rows.test.ts
+++ b/src/lib/place-rows.test.ts
@@ -41,6 +41,12 @@ describe("a row of the other place as a bot of the one list", () => {
expect(placedLine(bot, true)).toBe("");
});
+ it("shows the start of its newest line, in the same plain words as this place's own rows, when the other place sent one", () => {
+ const bot = placedBot(row("cloud", "nova", { title: "Research", preview: "**Filed** the [March invoices](https://drive.example/x) in your Drive." }), "ready");
+ expect(placedLine(bot, false)).toBe("Filed the March invoices in your Drive.");
+ expect(placedLine(bot, true)).toBe("Filed the March invoices in your Drive.");
+ });
+
it("is keyed by a place, not by My Cloud: a third place of the person's own joins with its own key, kind and name", () => {
const studio: Place = { key: "env-7f3a", kind: "home-computer", label: "Studio Mac" };
const rack: Place = { key: "env-91bc", kind: "own-server", label: "Basement server" };
diff --git a/src/lib/place-rows.ts b/src/lib/place-rows.ts
index eb62bc39b9..5c6e74bc33 100644
--- a/src/lib/place-rows.ts
+++ b/src/lib/place-rows.ts
@@ -11,7 +11,9 @@ import type { Dispatch } from "react";
import { BOT_BODY_IDS, type BotBodyId } from "../../shared/bot-body";
import { MASCOT_FACE_COLORS, mascotBodyColorSchema, mascotMaterialSchema, type MascotFaceColor } from "../../shared/bot-avatar";
import type { Action, Bot } from "@/state/store";
+import { citationPreviewText } from "./citations";
import { t } from "./i18n";
+import { plainPreviewText } from "../../shared/plain-preview";
import { MAUS_COLOR_NAMES, type MausColor } from "./mascot";
import { openOtherPlaceBot, usePlacesTogetherPart, type BotHome, type PlaceBotRow, type PlacesTogetherState } from "./places-together";
@@ -36,11 +38,12 @@ export function placeOfHome(home: BotHome): Place {
/** A bot's key in a list that holds several places: ids are unique only within one. */
export const placeKeyed = (place: Pick<Place, "key">, id: string): string => `${place.key}:${id}`;
-/** Where a row of the other place comes from: its place, its own id there, and how that place is doing. */
+/** Where a row of the other place comes from: its place, its own id there, how that place is doing, and its preview. */
export interface PlacedFrom {
place: Place;
id: string;
health: PlaceHealth;
+ preview?: string;
}
export type PlacedBot = Bot & { placedFrom: PlacedFrom; lastAt?: number };
@@ -51,8 +54,8 @@ export function isPlacedBot(bot: object): bot is PlacedBot {
const known = <T extends string>(list: readonly string[], value: string | undefined): T | null => (value !== undefined && list.includes(value) ? value as T : null);
-/** A row of the other place as a bot of this list. It carries only what the row does: a name, a look, a state and a
- * time; never a message, an engine or a setting of the other place. */
+/** A row of the other place as a bot of this list. It carries only what the row does: a name, a look, a state, a time
+ * and its preview line; never a whole message, an engine or a setting of the other place. */
export function placedBot(row: PlaceBotRow, health: PlaceHealth, place: Place = placeOfHome(row.home)): PlacedBot {
return {
id: placeKeyed(place, row.id), threadId: placeKeyed(place, row.threadId),
@@ -67,7 +70,7 @@ export function placedBot(row: PlaceBotRow, health: PlaceHealth, place: Place =
// No engine of this place: no model badge, and nothing here runs it.
modelSelection: { instanceId: "", model: "" },
messages: [],
- placedFrom: { place, id: row.id, health },
+ placedFrom: { place, id: row.id, health, ...(row.preview ? { preview: row.preview } : {}) },
...(row.lastAt !== undefined ? { lastAt: row.lastAt } : {}),
};
}
@@ -148,9 +151,12 @@ export function otherPlaceDispatch(bot: PlacedBot): Dispatch<Action> {
/** A row of the other place opens no menu here. */
export const NO_MENU = (): void => {};
-/** The second line of a row of the other place: its title in the Simple sidebar, where no role is shown, and nothing in
+/** The second line of a row of the other place: the start of its newest line, in the same plain words this page's own
+ * rows use, while the other place sent one; else its title in the Simple sidebar, where no role is shown, and nothing in
* Advanced, whose row shows the title as its role already. */
export function placedLine(bot: PlacedBot, advanced: boolean): string {
+ const preview = bot.placedFrom.preview;
+ if (preview) return plainPreviewText(citationPreviewText(preview));
return advanced ? "" : bot.title;
}