Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Accounts: name an account's places and keep its rows before its sign-in goes quiet
milind-soniab00447a714b
diff --git a/electron/accounts-main.mjs b/electron/accounts-main.mjsindex f80590e8da..c5960020b9 100644--- a/electron/accounts-main.mjs+++ b/electron/accounts-main.mjs@@ -47,7 +47,8 @@ export function createDesktopRing(deps) {const ring = () => {if (!deps.allowed()) return null;return made ??= createCloudAccounts({ active: deps.active(), saved: deps.savedStore(), client: deps.client, makeClient: deps.makeClient, origin: deps.origin, holding: deps.holding, settled: deps.settled, changed: deps.tell, log: deps.log,- leaving: async (id) => { deps.letGo(id); leavingNow = { left: leave.places(), rows: accountRows(deps.rows()) }; },+ naming: async () => { leavingNow = { left: leave.places(), rows: accountRows(deps.rows()) }; },+ leaving: async (id) => { deps.letGo(id); },left: async (id) => {const { left, rows } = leavingNow ?? { left: [], rows: [] };leavingNow = null;diff --git a/electron/accounts-main.node-test.mjs b/electron/accounts-main.node-test.mjsindex 0a2de741a6..aa47b92427 100644--- a/electron/accounts-main.node-test.mjs+++ b/electron/accounts-main.node-test.mjs@@ -164,11 +164,13 @@ function desktopRing({ environments = places.environments, order = [], activeIdconst tokens = (id) => ({ origin: "https://admin.test", token: `omc_${id.repeat(43)}`, account: { id, email: `${id}@example.test` }, device: { id: `d-${id}` }, expiresAt: Date.now() + 86_400_000 });const files = { active: tokens(activeId), saved: { v: 1, accounts: [tokens("b")] } };const store = (key) => ({ read: async () => files[key], write: async (value) => { files[key] = value; } });- const client = { state: () => state, quiesce() {}, async reload() { const id = files.active.account.id; state = { status: "connected", account: { id, email: `${id}@example.test` } }; order.push(`reload:${id}`); }, async refresh() {}, async revokeSaved() { order.push("revoke"); },+ let quiet = false;+ const client = { state: () => state, quiesce() { quiet = true; }, async reload() { quiet = false; const id = files.active.account.id; state = { status: "connected", account: { id, email: `${id}@example.test` } }; order.push(`reload:${id}`); }, async refresh() {}, async revokeSaved() { order.push("revoke"); },async signOut() { order.push("client-sign-out"); files.active = null; state = { status: "signed-out" }; return state; } };const ring = createDesktopRing({ allowed: () => true, active: () => store("active"), savedStore: () => store("saved"), stash: () => stash, client: () => client, origin: "https://admin.test", makeClient: () => { throw new Error("not here"); },- saved: () => saved, persist: (next) => { saved = next; order.push("persist"); }, session: () => ({ clearStorageData: async ({ origin }) => { order.push(`clear:${origin}`); } }), mine: () => mine, leaveWindow: async () => order.push("window"),- rows: () => [{ id: "home-a", name: "My Cloud", color: "green", kind: "cloud", opens: true, active: true, progress: 0.5, attention: true, paint: { swatch: "green" } }, { id: "by-hand", name: "By hand", kind: "server", opens: true, forget: true }, { id: "local", name: "This computer", kind: "computer", opens: true }],+ saved: () => saved, persist: (next) => { saved = next; order.push("persist"); }, session: () => ({ clearStorageData: async ({ origin }) => { order.push(`clear:${origin}`); } }), mine: () => (quiet ? null : mine), leaveWindow: async () => order.push("window"),+ // A quiet sign-in says nothing of its Clouds: what the rail keeps is read before that.+ rows: () => (quiet ? [] : [{ id: "home-a", name: "My Cloud", color: "green", kind: "cloud", opens: true, active: true, progress: 0.5, attention: true, paint: { swatch: "green" } }, { id: "by-hand", name: "By hand", kind: "server", opens: true, forget: true }, { id: "local", name: "This computer", kind: "computer", opens: true }]),holding: () => null, letGo: (id) => order.push(`let-go:${id}`), lendingDone: async () => { order.push("lending-done"); }, settled: async () => order.push("settled"), forgetLending: (place) => lent.push(place.id), tell: () => order.push("tell"), log: () => {} });return { ring, order, lent, saved: () => saved, files };}diff --git a/electron/cloud-accounts.mjs b/electron/cloud-accounts.mjsindex 0f5455d186..3d635579c2 100644--- a/electron/cloud-accounts.mjs+++ b/electron/cloud-accounts.mjs@@ -24,6 +24,7 @@ const memoryStore = () => { let held = null; return { read: async () => held, wr* makeClient(options: { store: any, onState(state: any): void }): any,* origin: string,* holding?(): string | null,+ * naming?(accountId: string | null): Promise<unknown>,* leaving?(accountId: string | null): Promise<unknown>,* left?(accountId: string | null): Promise<unknown>,* arriving?(accountId: string): Promise<unknown>,@@ -33,14 +34,14 @@ const memoryStore = () => { let held = null; return { read: async () => held, wr* now?(): number,* log?(line: string): void,* }} deps `holding()`: why the active account can't be left now ("moving"), else null. `leaving(id)`: everything that was- * running for that account stops, and its places are named while its sign-in can still say which they are. `left(id)`: those+ * running for that account stops. `naming(id)`, before anything else: its places are named and kept as the rail shows them, while its sign-in can still say which they are and how they look, which it can't once it is quiet. `left(id)`: those* places leave the list and the window, and their sessions go; a sign-out's comes after its sign-in ended, whose last answers can* re-issue a session. `arriving(id)`: what this device kept for that* account comes back, before its sign-in is read. `settled()`: the window goes where it belongs. `removed(id)`: that account* is off this device: what was kept for it goes. `makeClient`: a sign-in of its own for Add another account, which leaves the* active account running until it succeeds.*/-export function createCloudAccounts({ active, saved, client, makeClient, origin, holding = () => null, leaving = async () => {}, left = async () => {}, arriving = async () => {}, settled = async () => {}, removed = async () => {}, changed = () => {}, now = Date.now, log = () => {} }) {+export function createCloudAccounts({ active, saved, client, makeClient, origin, holding = () => null, naming = async () => {}, leaving = async () => {}, left = async () => {}, arriving = async () => {}, settled = async () => {}, removed = async () => {}, changed = () => {}, now = Date.now, log = () => {} }) {let rows = [], known = false, queue = Promise.resolve(), adder = null, browserResult = null;const serial = (work) => { const run = queue.then(work, work); queue = run.catch(() => {}); return run; };@@ -71,6 +72,7 @@ export function createCloudAccounts({ active, saved, client, makeClient, origin,/** The account `next` becomes active; `keep`: the one active now stays signed in, waiting. */async function become(next, { list, keep = true }) {const leavingId = activeId();+ await naming(leavingId);const current = await active.read().catch(() => null);const waiting = keep && usable(current, origin) ? current : null;await saved.write({ v: VERSION, accounts: [...list.filter((record) => record.account.id !== waiting?.account.id), ...(waiting ? [waiting] : [])] });@@ -123,6 +125,7 @@ export function createCloudAccounts({ active, saved, client, makeClient, origin,await become(next, { list: list.filter((record) => record.account.id !== id), keep: false });if (usable(current, origin)) await client().revokeSaved(current).catch((error) => log(`accounts: signed out here only (${error?.message ?? error})`));} else {+ await naming(id);await leaving(id);await client().signOut();await left(id);diff --git a/src/components/PlacesRail.tsx b/src/components/PlacesRail.tsxindex 0769878e69..d630c3d596 100644--- a/src/components/PlacesRail.tsx+++ b/src/components/PlacesRail.tsx@@ -248,7 +248,7 @@ function MorePlaces({ places, canPair, onOpen, onMenu, onClose }: { places: Rail<button type="button" disabled={!placeActs(place, canPair)} aria-current={place.active ? "page" : undefined} onClick={() => { onOpen(place); onClose(); }}onContextMenu={menuOpener(place, (menu) => { onClose(); onMenu(menu); })} className={cn(MENU_ROW, "h-9")}><PlaceMark place={place} size={22} />- <span className="min-w-0 flex-1 truncate">{placeLabel(place)}</span>+ <span className="min-w-0 flex-1 truncate">{[placeStatus(place, Date.now()), place.signIn && t("accounts.needsSignIn")].filter(Boolean).join(" · ")}</span></button></li>)}</ul>