Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Apps: short sample app names, and samples on Team Clouds (#8161)
Milind Soni66687f49ff02
diff --git a/server/local-apps/starters.test.ts b/server/local-apps/starters.test.tsindex 207444663c..e24324ae8d 100644--- a/server/local-apps/starters.test.ts+++ b/server/local-apps/starters.test.ts@@ -35,6 +35,17 @@ describe("starter apps", () => {}});+ it("have short names, each page titled with its name, and remember the long names they came with", () => {+ expect(STARTER_APPS.map(({ id, name, was }) => ({ id, name, was }))).toEqual([+ { id: "la_starter_ledger__", name: "Ledger", was: ["Ledger · household & studio accounts"] },+ { id: "la_starter_cohorts_", name: "Cohorts", was: ["Cohorts · Q3 activation review"] },+ { id: "la_starter_fleet___", name: "Fleet control", was: ["Corridor · Fleet control"] },+ { id: "la_starter_bigtable", name: "Rowfall", was: ["Rowfall · orders"] },+ ]);+ const source = bundledStarterApps();+ for (const app of STARTER_APPS) expect(source.html(app), app.file).toContain(`<title>${app.name}</title>`);+ });+it("make no outside request, keep nothing in the browser, and say they are sample data", () => {const source = bundledStarterApps();for (const app of STARTER_APPS) {@@ -84,6 +95,40 @@ describe("starter apps", () => {expect(open(dir, pages({ "one.html": "<h1>One, newer</h1>" })).get(TWO[0]!.id)?.versions).toHaveLength(2);});+ it("take the new name only while the stored one is still the old default, in the manifest too", () => {+ const dir = fresh();+ const OLD: StarterApp[] = [+ { id: TWO[0]!.id, name: "One · the long name", file: "one.html" },+ { id: TWO[1]!.id, name: "Two · the long name", file: "two.html" },+ { id: "la_starter_three___", name: "Three · the long name", file: "three.html" },+ ];+ const html = { "one.html": "<h1>One</h1>", "two.html": "<h1>Two</h1>", "three.html": "<h1>Three</h1>" };+ const before = open(dir, { apps: OLD, html: (app) => html[app.file as keyof typeof html] ?? null });+ before.rename(TWO[1]!.id, "Our two");+ expect(before.remove("la_starter_three___")).toBe(true);++ const NEW: StarterApp[] = OLD.map((app) => ({ ...app, name: app.name.split(" · ")[0]!, was: [app.name] }));+ // The page of One is gone from this release: its name still moves on.+ const after = open(dir, { apps: NEW, html: (app) => (app.file === "one.html" ? null : html[app.file as keyof typeof html] ?? null) });+ expect(after.list().map((app) => [app.id, app.name, app.manifest.name])).toEqual([+ [TWO[0]!.id, "One", "One"],+ [TWO[1]!.id, "Our two", "Our two"],+ ]);+ expect(after.get(TWO[0]!.id)?.versions).toHaveLength(1);++ const written = readFileSync(localAppsFile(dir), "utf8");+ open(dir, { apps: NEW, html: (app) => html[app.file as keyof typeof html] ?? null });+ expect(readFileSync(localAppsFile(dir), "utf8")).toBe(written);+ });++ it("leave an app of the person's own alone even when it has a starter's old name", () => {+ const dir = fresh();+ const own = new LocalAppsStore(dir).add({ name: "One · the long name", botId: "b1", threadId: "t1", messageId: "m1", versions: [{ rev: 0, doc: "a".repeat(64), at: 0 }], manifest: { name: "One · the long name" } });+ const apps = open(dir, { apps: [{ ...TWO[0]!, was: ["One · the long name"] }], html: () => "<h1>One</h1>" });+ expect(apps.get(own.id)?.name).toBe("One · the long name");+ expect(apps.get(TWO[0]!.id)?.name).toBe("One");+ });+it("add nothing when the saved apps or the removals can't be read", () => {const unreadable = fresh();writeFileSync(localAppsFile(unreadable), JSON.stringify({ version: 2, apps: [{ id: "la_from_a_newer_bu" }] }));diff --git a/server/local-apps/starters.ts b/server/local-apps/starters.tsindex 5f66014f88..aafda68574 100644--- a/server/local-apps/starters.ts+++ b/server/local-apps/starters.ts@@ -13,13 +13,16 @@ export interface StarterApp {name: string;/** The page, a file in the starters folder. */file: string;+ /** Names it came with in earlier releases: one still kept exactly as it came takes `name` at the next start, while a+ * name the person gave it stays. */+ was?: readonly string[];}export const STARTER_APPS: readonly StarterApp[] = [- { id: "la_starter_ledger__", name: "Ledger · household & studio accounts", file: "ledger.html" },- { id: "la_starter_cohorts_", name: "Cohorts · Q3 activation review", file: "cohorts.html" },- { id: "la_starter_fleet___", name: "Corridor · Fleet control", file: "fleet.html" },- { id: "la_starter_bigtable", name: "Rowfall · orders", file: "bigtable.html" },+ { id: "la_starter_ledger__", name: "Ledger", file: "ledger.html", was: ["Ledger · household & studio accounts"] },+ { id: "la_starter_cohorts_", name: "Cohorts", file: "cohorts.html", was: ["Cohorts · Q3 activation review"] },+ { id: "la_starter_fleet___", name: "Fleet control", file: "fleet.html", was: ["Corridor · Fleet control"] },+ { id: "la_starter_bigtable", name: "Rowfall", file: "bigtable.html", was: ["Rowfall · orders"] },];export interface StarterSource {@@ -72,8 +75,9 @@ export function rememberRemovedStarter(dataDir: string, id: string): void {/*** Adds each starter app the store lacks and the person never removed, after their own apps; a starter still kept whose- * page changed in this release gets the new page as its newest version. Nothing at all when either file can't be read:- * the person's saved apps are never written over, and a removed starter never comes back.+ * page changed in this release gets the new page as its newest version, and one still named as it came in an earlier+ * release takes this release's name. Nothing at all when either file can't be read: the person's saved apps are never+ * written over, and a removed starter never comes back.*/export function seedStarterApps(args: { store: LocalAppsStore; docs: AppDocs; dataDir: string; source: StarterSource; now: number }): void {const { store, docs, source, now } = args;@@ -84,17 +88,21 @@ export function seedStarterApps(args: { store: LocalAppsStore; docs: AppDocs; dafor (const app of source.apps) {if (removed.has(app.id) || !LOCAL_APP_ID.test(app.id)) continue;const html = source.html(app);- if (html === null) continue;- const put = docs.put({ source: "html", html });- if (!put.ok) continue;+ const put = html === null ? null : docs.put({ source: "html", html });+ const doc = put?.ok ? put.doc : null;const kept = store.get(app.id);if (!kept) {- added.push({ id: app.id, name: app.name, botId: "", threadId: "", messageId: app.id, sample: true, versions: [{ rev: 0, doc: put.doc, at: now }],+ if (doc) added.push({ id: app.id, name: app.name, botId: "", threadId: "", messageId: app.id, sample: true, versions: [{ rev: 0, doc, at: now }],createdAt: now, updatedAt: now, manifest: { name: app.name } });continue;}const newest = kept.versions.at(-1)!;- if (newest.doc !== put.doc) store.update(app.id, (record) => ({ ...record, versions: [...record.versions, { rev: newest.rev + 1, doc: put.doc, at: now }] }), now);+ const newPage = doc !== null && newest.doc !== doc;+ const newName = kept.sample === true && kept.name !== app.name && (app.was ?? []).includes(kept.name);+ if (!newPage && !newName) continue;+ store.update(app.id, (record) => ({ ...record,+ ...(newName ? { name: app.name, manifest: { ...record.manifest, name: app.name } } : {}),+ ...(newPage ? { versions: [...record.versions, { rev: newest.rev + 1, doc, at: now }] } : {}) }), now);}store.append(added);}diff --git a/server/local-apps/starters/bigtable.html b/server/local-apps/starters/bigtable.htmlindex b0cd476778..6c9a1f17b8 100644--- a/server/local-apps/starters/bigtable.html+++ b/server/local-apps/starters/bigtable.html@@ -3,7 +3,7 @@<head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">-<title>Rowfall · orders</title>+<title>Rowfall</title><style>:root{--ui:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif; --mono:ui-monospace,"SF Mono",Menlo,Consolas,monospace;diff --git a/server/local-apps/starters/cohorts.html b/server/local-apps/starters/cohorts.htmlindex b0dec889d8..e4ea1444b8 100644--- a/server/local-apps/starters/cohorts.html+++ b/server/local-apps/starters/cohorts.html@@ -3,7 +3,7 @@<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">-<title>Cohorts · Q3 activation review</title>+<title>Cohorts</title><style>:root{--bg:#fff;--rail:#fafafb;--ink:#111318;--ink2:#4b5160;--ink3:#8a90a0;--line:#eceef2;--line2:#e2e5eb;--acc:#5b5bd6;--acc2:#e9e9fb;--cmp:#b4b0a6;--ui:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;--mono:ui-monospace,"SF Mono",Menlo,Consolas,monospace}diff --git a/server/local-apps/starters/fleet.html b/server/local-apps/starters/fleet.htmlindex 9cb016da4b..6c8dd468c7 100644--- a/server/local-apps/starters/fleet.html+++ b/server/local-apps/starters/fleet.html@@ -3,7 +3,7 @@<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">-<title>Corridor · Fleet control</title>+<title>Fleet control</title><style>:root{--bg:#070b10;--panel:rgba(9,13,19,.88);--line:#1c2733;--line2:#26323f;--ink:#d8e2eb;--ink2:#8b9bab;--ink3:#566676;--cyan:#3fd0ff;--amber:#ffb020;--red:#ff4d5e;--green:#4fd39a;--mono:ui-monospace,"SF Mono",Menlo,Consolas,monospace;--ui:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;diff --git a/server/local-apps/starters/ledger.html b/server/local-apps/starters/ledger.htmlindex 689b909f99..249f2a0dbd 100644--- a/server/local-apps/starters/ledger.html+++ b/server/local-apps/starters/ledger.html@@ -3,7 +3,7 @@<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">-<title>Ledger · household & studio accounts</title>+<title>Ledger</title><style>:root{--paper:#f5efe4;--paper2:#efe7d8;--ink:#2b2118;--ink2:#5d4f41;--ink3:#8a7b68;--rule:#d9ccb8;--rule2:#e6dccb;--terra:#c4572e;--over:#b23a1f;--serif:ui-serif,"Iowan Old Style","Palatino Linotype",Palatino,Georgia,serif;--text:ui-serif,"Iowan Old Style","Palatino Linotype",Palatino,Georgia,serif;--gx:clamp(36px,2.9vw,56px)}diff --git a/server/request-auth.ts b/server/request-auth.tsindex 772e8b5964..fe6ff43763 100644--- a/server/request-auth.ts+++ b/server/request-auth.ts@@ -520,7 +520,8 @@ export const CLIENT_ALLOW: ReadonlyArray<{ methods: readonly string[]; path: Reg// what the viewer's own bots put online, from conversations they can read; the handler deletes only what is theirs{ methods: ["GET"], path: /^\/api\/published-apps(?:\/framing)?$/ },{ methods: ["POST"], path: /^\/api\/published-apps\/delete$/ },- // the apps a person saved from bots' pages: the handler shows and changes only their own, from conversations they read+ // the apps a person saved from bots' pages: the handler shows and changes only their own, from conversations they read;+ // everyone sees the sample apps, which only an admin removes or renames{ methods: ["GET", "POST"], path: /^\/api\/local-apps$/ },{ methods: ["GET", "PATCH", "DELETE"], path: /^\/api\/local-apps\/la_[A-Za-z0-9_-]{16}$/ },{ methods: ["GET"], path: /^\/api\/local-apps\/la_[A-Za-z0-9_-]{16}\/app$/ },diff --git a/server/routes/local-apps-page-rpc.test.ts b/server/routes/local-apps-page-rpc.test.tsindex c77b009a36..1f42748fe6 100644--- a/server/routes/local-apps-page-rpc.test.ts+++ b/server/routes/local-apps-page-rpc.test.ts@@ -13,6 +13,7 @@ import type { ModelSelection } from "../contracts.ts";import { createDataEngine } from "../data/engine.ts";import { json, readBody } from "../harness/http.ts";import { createLocalApps, type LocalApps } from "../local-apps/service.ts";+import type { StarterSource } from "../local-apps/starters.ts";import { withLocalAppDocs } from "../local-apps/store.ts";import type { RequestAuth } from "../request-auth.ts";import { Store } from "../store.ts";@@ -33,11 +34,11 @@ afterEach(async () => {});afterAll(async () => { await engine.closeAll(); });-async function fixture() {+async function fixture(starters?: StarterSource) {const store = new Store(() => sonnet);const bot = store.createBot({ name: "Scout" });const chatApps: ChatApps = createChatApps({ store, dataDir: DATA_DIR, sweeps: false, references: withLocalAppDocs(DATA_DIR) });- const localApps: LocalApps = createLocalApps({ chat: store, docs: chatApps.docs, dataDir: DATA_DIR });+ const localApps: LocalApps = createLocalApps({ chat: store, docs: chatApps.docs, dataDir: DATA_DIR, ...(starters ? { starters } : {}) });closers.push(chatApps, localApps);const everything = { everything: true, thread: () => true };const routes = [@@ -119,6 +120,17 @@ describe("a saved app that reads its bot's data and keeps state", () => {expect((await rpc(app, messageId, "mausbot/state/keys")).status).toBe(404);});+ it("a sample app reaches no conversation's data or state, from its own bridge or a real bot's", async () => {+ const starters: StarterSource = { apps: [{ id: "la_starter_sample__", name: "Sample", file: "sample.html" }], html: () => "<p>Sample</p>" };+ const { call, rpc, bot, thread } = await fixture(starters);+ const sample = (await call("GET", "/api/local-apps/la_starter_sample__")).body.app as { botId: string; threadId: string; messageId: string };+ expect(sample).toMatchObject({ botId: "", threadId: "", chat: false });+ expect((await call("GET", "/api/local-apps/la_starter_sample__/app")).body.can.data ?? false).toBe(false);+ expect((await rpc(sample, sample.messageId, "mausbot/data/query", { sql: "SELECT 1 AS one" })).status).toBe(404);+ expect((await rpc({ botId: bot.id, threadId: thread }, sample.messageId, "mausbot/data/query", { sql: "SELECT 1 AS one" })).status).toBe(404);+ expect((await rpc({ botId: bot.id, threadId: thread }, sample.messageId, "mausbot/state/keys")).status).toBe(404);+ });+it("carries the connector tools a page declared into its document and manifest", async () => {const { call, show, save } = await fixture();const messageId = show({ uses: ["data", "gmail:GMAIL_FETCH_EMAILS", "gmail:GMAIL_TRASH_MESSAGE"] });diff --git a/server/routes/local-apps.test.ts b/server/routes/local-apps.test.tsindex db74daa8a0..a0e2f2bfa6 100644--- a/server/routes/local-apps.test.ts+++ b/server/routes/local-apps.test.ts@@ -51,7 +51,7 @@ async function fixture(seen: (person: string, threadId: string) => boolean = ()if (localApps.serveFile(req, res, url.pathname, req.method ?? "GET")) return;const person = req.headers["x-session"];const auth = (typeof person === "string"- ? { kind: "session", session: { id: person, email: `${person}@example.com` }, via: "bearer", scopes: ["client"] }+ ? { kind: "session", session: { id: person, email: `${person}@example.com` }, via: "bearer", scopes: person.startsWith("admin") ? ["admin", "client"] : ["client"] }: { kind: "loopback", scopes: ["admin", "client"] }) as RequestAuth;if (!await dispatchRoutes(routes, { req, res, url, path: url.pathname, method: req.method ?? "GET", auth, json, readBody })) json(res, 404, { from: "inline routes" });} catch (error) {@@ -243,12 +243,14 @@ describe("local apps", () => {expect((await call("DELETE", `/api/local-apps/${bobs}`, undefined, "bob")).body).toEqual({ ok: true });});- it("shows a starter app to whoever sees everything; only this computer or an admin removes it, and for good", async () => {+ it("shows a starter app to everyone and opens it for them; only this computer or an admin changes it", async () => {const starters: StarterSource = { apps: [{ id: "la_starter_sample__", name: "Sample", file: "sample.html" }], html: () => "<p>Sample data</p>" };const narrow = await fixture(() => true, { starters });- expect((await narrow.call("GET", "/api/local-apps")).body.apps.map((app: any) => [app.id, app.sample])).toEqual([["la_starter_sample__", true]]);- expect((await narrow.call("GET", "/api/local-apps", undefined, "ann")).body.apps).toEqual([]);- expect((await narrow.call("GET", "/api/local-apps/la_starter_sample__/app", undefined, "ann")).status).toBe(404);+ expect((await narrow.call("GET", "/api/local-apps")).body.apps.map((app: any) => [app.id, app.sample, app.canChange])).toEqual([["la_starter_sample__", true, true]]);+ expect((await narrow.call("GET", "/api/local-apps", undefined, "ann")).body.apps.map((app: any) => [app.id, app.canChange])).toEqual([["la_starter_sample__", false]]);+ expect((await narrow.call("GET", "/api/local-apps/la_starter_sample__", undefined, "ann")).body.app).toMatchObject({ sample: true, canChange: false, botId: "", threadId: "" });+ expect((await narrow.call("GET", "/api/local-apps/la_starter_sample__/app", undefined, "ann")).body.srcdoc).toContain("Sample data");+ expect((await narrow.call("GET", "/api/local-apps", undefined, "admin-zoe")).body.apps.map((app: any) => app.canChange)).toEqual([true]);const wide = await fixture(() => true, { everything: true, starters });expect((await wide.call("GET", "/api/local-apps", undefined, "bob")).body.apps.map((app: any) => app.id)).toEqual(["la_starter_sample__"]);@@ -259,6 +261,32 @@ describe("local apps", () => {expect((await (await fixture(() => true, { starters })).call("GET", "/api/local-apps")).body.apps).toEqual([]);});+ it("on a Team Cloud a member sees the samples but not a teammate's app, may not change a sample, and an admin's removal holds for everyone", async () => {+ const starters: StarterSource = { apps: [{ id: "la_starter_sample__", name: "Sample", file: "sample.html" }], html: () => "<p>Sample data</p>" };+ const { page, save, call, bot } = await fixture((person, threadId) => person === "ann" && threadId === bot.threadId, { starters });+ const anns = (await save(page(), "ann")).body.app.id;+ expect((await call("GET", "/api/local-apps", undefined, "bob")).body.apps.map((app: any) => app.id)).toEqual(["la_starter_sample__"]);+ expect((await call("GET", `/api/local-apps/${anns}`, undefined, "bob")).status).toBe(404);+ expect((await call("GET", `/api/local-apps/${anns}/app`, undefined, "bob")).status).toBe(404);+ expect((await call("GET", "/api/local-apps", undefined, "ann")).body.apps.map((app: any) => [app.id, app.canChange])).toEqual([[anns, true], ["la_starter_sample__", false]]);++ expect((await call("PATCH", "/api/local-apps/la_starter_sample__", { name: "Bob's" }, "bob")).status).toBe(403);+ expect((await call("PATCH", "/api/local-apps/la_starter_sample__", { pinnedRev: 0 }, "bob")).status).toBe(403);+ expect((await call("DELETE", "/api/local-apps/la_starter_sample__", undefined, "bob")).status).toBe(403);+ expect((await call("GET", "/api/local-apps/la_starter_sample__", undefined, "bob")).body.app.name).toBe("Sample");+ expect(readRemovedStarters(DATA_DIR)).toEqual(new Set());++ expect((await call("PATCH", "/api/local-apps/la_starter_sample__", { name: "Team sample" }, "admin-zoe")).body.app).toMatchObject({ name: "Team sample", canChange: true });+ expect((await call("GET", "/api/local-apps/la_starter_sample__", undefined, "bob")).body.app).toMatchObject({ name: "Team sample", canChange: false });+ expect((await call("DELETE", "/api/local-apps/la_starter_sample__", undefined, "admin-zoe")).body).toEqual({ ok: true });+ expect((await call("GET", "/api/local-apps", undefined, "bob")).body.apps).toEqual([]);+ expect((await call("GET", "/api/local-apps/la_starter_sample__", undefined, "ann")).status).toBe(404);++ const restarted = await fixture(() => true, { starters });+ expect((await restarted.call("GET", "/api/local-apps", undefined, "bob")).body.apps).toEqual([]);+ expect((await restarted.call("GET", "/api/local-apps")).body.apps.map((app: any) => app.id)).toEqual([anns]);+ });+it("stops serving a folder app's files once the session that opened it has ended", async () => {let live = true;const { folderPage, save, call, base } = await fixture(() => true, { live: () => live });diff --git a/server/routes/local-apps.ts b/server/routes/local-apps.tsindex 55fa9cb881..69ac9baced 100644--- a/server/routes/local-apps.ts+++ b/server/routes/local-apps.ts@@ -1,6 +1,6 @@import { z } from "zod";-import { LOCAL_APP_NAME_MAX, type LocalAppsList } from "../../shared/local-apps.ts";+import { LOCAL_APP_NAME_MAX, type LocalApp, type LocalAppsList } from "../../shared/local-apps.ts";import { webOrigin } from "../../shared/app-frame/csp.ts";import type { LocalApps } from "../local-apps/service.ts";import { nameOf } from "../local-apps/service.ts";@@ -38,13 +38,14 @@ const ownerOf = (auth: RequestAuth) => (auth.kind === "session" ? personKey(auth* saved again answers with its app). GET, PATCH `{ name?, pinnedRev? }` and DELETE /api/local-apps/:id; GET* /api/local-apps/:id/app?rev=&origin= is the app's document, built as the chat builds it.* Security: a viewer who does not see every conversation is shown only the apps they saved, and of those only the ones- * whose conversation, while it exists, they can still read. Saving asks the same of the page's conversation, so another- * bot's or another conversation's page reads as one that is not there. */+ * whose conversation, while it exists, they can still read, plus the sample apps, which come from no bot or conversation.+ * Saving asks the same of the page's conversation, so another bot's or another conversation's page reads as one that is+ * not there. Each app listed says whether this viewer may change it (`canChange`). */export function createLocalAppsRoutes(deps: LocalAppsRouteDeps): RouteHandler {const { apps, store } = deps;const chatHas = (threadId: string) => Boolean(store.botByThread(threadId) || store.groupByThread(threadId));const sees = (auth: RequestAuth, record: LocalAppRecord, visible = deps.visibleFor(auth)) => {- if (visible.everything) return true;+ if (visible.everything || record.sample) return true;if (!record.owner || record.owner !== ownerOf(auth)) return false;return !chatHas(record.threadId) || visible.thread(record.threadId);};@@ -54,13 +55,14 @@ export function createLocalAppsRoutes(deps: LocalAppsRouteDeps): RouteHandler {if (!auth.scopes.includes("admin") && record.owner !== ownerOf(auth)) return "Only whoever saved this app can change it.";return chatHas(record.threadId) ? deps.threadRefusal?.(auth, record.threadId) ?? null : null;};+ const shown = (auth: RequestAuth, record: LocalAppRecord): LocalApp => ({ ...apps.view(record), canChange: mayChange(auth, record) === null });return async ({ req, res, url, path, method, auth, json, readBody }) => {if (path === LIST) {if (method === "GET") {const visible = deps.visibleFor(auth);res.setHeader("cache-control", "private, no-store");- return json(res, 200, { apps: apps.list().filter((record) => sees(auth, record, visible)).map(apps.view) } satisfies LocalAppsList);+ return json(res, 200, { apps: apps.list().filter((record) => sees(auth, record, visible)).map((record) => shown(auth, record)) } satisfies LocalAppsList);}if (method !== "POST") return PASS;const body = saveBody.safeParse(await readBody(req, 4_096));@@ -72,7 +74,7 @@ export function createLocalAppsRoutes(deps: LocalAppsRouteDeps): RouteHandler {if (refused) return json(res, 403, { error: refused });const saved = apps.save({ botId, threadId, messageId, owner: ownerOf(auth) });if (!saved.ok) return json(res, saved.status, { error: saved.error });- return json(res, saved.created ? 201 : 200, { app: apps.view(saved.app) });+ return json(res, saved.created ? 201 : 200, { app: shown(auth, saved.app) });}const m = ONE.exec(path);@@ -93,7 +95,7 @@ export function createLocalAppsRoutes(deps: LocalAppsRouteDeps): RouteHandler {return json(res, 200, doc);}- if (method === "GET") return json(res, 200, { app: apps.view(record) });+ if (method === "GET") return json(res, 200, { app: shown(auth, record) });if (method !== "DELETE" && method !== "PATCH") return PASS;const refused = mayChange(auth, record);if (refused) return json(res, 403, { error: refused });@@ -113,6 +115,6 @@ export function createLocalAppsRoutes(deps: LocalAppsRouteDeps): RouteHandler {changed = apps.pin(record.id, body.data.pinnedRev);if (!changed) return json(res, 404, { error: "That version of the app is no longer kept." });}- return changed ? json(res, 200, { app: apps.view(changed) }) : json(res, 404, { error: "No such app." });+ return changed ? json(res, 200, { app: shown(auth, changed) }) : json(res, 404, { error: "No such app." });};}diff --git a/shared/local-apps.ts b/shared/local-apps.tsindex 2971395e1e..576d9dd9fa 100644--- a/shared/local-apps.ts+++ b/shared/local-apps.ts@@ -40,6 +40,8 @@ export interface LocalApp {chat: boolean;/** A sample app that came with MausBot: no bot made it and it has no chat (`botId`, `threadId` are empty). */sample?: true;+ /** Whether the person asking may rename it, keep a version of it or remove it. Absent from a server that doesn't say. */+ canChange?: boolean;}export interface LocalAppsList {diff --git a/src/components/published-apps/LocalAppCard.tsx b/src/components/published-apps/LocalAppCard.tsxindex d1335ad155..9190709bf7 100644--- a/src/components/published-apps/LocalAppCard.tsx+++ b/src/components/published-apps/LocalAppCard.tsx@@ -78,11 +78,12 @@ export function LocalAppCard({ app, bot, onOpen, onOpenWindow, onRename, onGoToCconst [renaming, setRenaming] = useState(false);const maker = bot?.name ?? app.bot?.name;const facts = [maker ?? t(app.sample ? "localApps.card.sample" : "localApps.card.botGone"), relativeTime(app.updatedAt)].join(" · ");+ const fixed = app.sample && app.canChange === false;const items: SidebarMenuItem[] = [- { key: "rename", label: t("localApps.card.rename"), icon: <Pencil size={16} />, onSelect: () => setRenaming(true) },+ ...(fixed ? [] : [{ key: "rename", label: t("localApps.card.rename"), icon: <Pencil size={16} />, onSelect: () => setRenaming(true) }]),...(onGoToChat ? [{ key: "chat", label: t("localApps.card.goToChat"), icon: <MessageSquare size={16} />, onSelect: onGoToChat }] : []),...installItems(install),- { key: "remove", label: t("localApps.card.remove"), icon: <Trash2 size={16} />, separatorBefore: true, onSelect: onRemove },+ ...(fixed ? [] : [{ key: "remove", label: t("localApps.card.remove"), icon: <Trash2 size={16} />, separatorBefore: true, onSelect: onRemove }]),];return (<li data-local-app={app.id} className="group relative flex min-w-0 flex-col rounded-2xl border border-hairline/40 bg-card transition-colors duration-[120ms] hover:border-hairline motion-reduce:transition-none">@@ -103,9 +104,11 @@ export function LocalAppCard({ app, bot, onOpen, onOpenWindow, onRename, onGoToC<button type="button" className="ui-icon-button hover:bg-ink/[0.06] hover:text-ink" onClick={onOpenWindow}aria-label={t("localApps.card.openWindow")} title={t("localApps.card.openWindow")}><AppWindowMac size={16} /></button>)}- <SidebarPopoverMenu items={items} ariaLabel={t("localApps.card.more", { name: app.name })} placement="below" align="end"- triggerTitle={t("localApps.card.more", { name: app.name })} triggerClassName="ui-icon-button hover:bg-ink/[0.06] hover:text-ink aria-expanded:bg-ink/[0.06]"- renderTrigger={() => <MoreHorizontal size={16} aria-hidden="true" />} />+ {items.length > 0 && (+ <SidebarPopoverMenu items={items} ariaLabel={t("localApps.card.more", { name: app.name })} placement="below" align="end"+ triggerTitle={t("localApps.card.more", { name: app.name })} triggerClassName="ui-icon-button hover:bg-ink/[0.06] hover:text-ink aria-expanded:bg-ink/[0.06]"+ renderTrigger={() => <MoreHorizontal size={16} aria-hidden="true" />} />+ )}</span></div><span className="flex min-w-0 items-center gap-1.5 pe-1.5">diff --git a/src/components/published-apps/LocalApps.test.ts b/src/components/published-apps/LocalApps.test.tsindex 54a969f9bb..8fc439cce3 100644--- a/src/components/published-apps/LocalApps.test.ts+++ b/src/components/published-apps/LocalApps.test.ts@@ -143,6 +143,28 @@ describe("saved apps on the apps page", () => {expect(host.querySelector(`[data-local-app-view="${SAMPLE.id}"]`)?.getAttribute("data-local-app-state")).toBe("live");});+ it("offers no Rename or Remove on a sample this person may not change, and still opens it", async () => {+ const theirs = app("la_theirs00000000000", "Their board", { canChange: false });+ saved = [{ ...SAMPLE, canChange: false }, theirs];+ await show();+ expect(button(card(SAMPLE.id), "More for Ledger")).toBeUndefined();+ act(() => button(card(theirs.id), "More for Their board").click());+ expect(menuItem("Rename")).toBeDefined();+ expect(menuItem("Remove")).toBeDefined();+ act(() => button(card(SAMPLE.id), "Open Ledger").click());+ await settle();+ expect(host.querySelector(`[data-local-app-view="${SAMPLE.id}"]`)?.getAttribute("data-local-app-state")).toBe("live");+ expect(calls.some((call) => call.method !== "GET")).toBe(false);+ });++ it("offers Rename and Remove on a sample this person may change", async () => {+ saved = [{ ...SAMPLE, canChange: true }];+ await show();+ act(() => button(card(SAMPLE.id), "More for Ledger").click());+ expect(menuItem("Rename")).toBeDefined();+ expect(menuItem("Remove")).toBeDefined();+ });+it("opens an app in its own window on the desktop", async () => {const openWindow = vi.fn(async () => true);vi.stubGlobal("ogb", { localApps: { openWindow, openChat: vi.fn() } });@@ -289,6 +311,15 @@ describe("installing a saved app on this computer", () => {expect(card(SAMPLE.id).querySelector("[data-local-app-installed]")).not.toBeNull();});+ it("keeps Install on a sample this person may not change, without Rename or Remove", async () => {+ saved = [{ ...SAMPLE, canChange: false }];+ await show();+ act(() => button(card(SAMPLE.id), "More for Ledger").click());+ expect(menuItem("Install on this computer")).toBeDefined();+ expect(menuItem("Rename")).toBeUndefined();+ expect(menuItem("Remove")).toBeUndefined();+ });+it("says so in one line when a launcher couldn't be written", async () => {bridge.install.mockResolvedValueOnce({ ok: false, reason: "failed" });await show();