Skip to content

A personal agent with a browser, terminal, files, and work that keeps going built with CopilotKit and AG-UI.

TypeScript

fix: make the computer button label match its status (#77)

Asem ahmed1ed51c80dd89
diff --git a/apps/mobile/src/computer-status.ts b/apps/mobile/src/computer-status.ts
new file mode 100644
index 0000000..4d39a7e
--- /dev/null
+++ b/apps/mobile/src/computer-status.ts
@@ -0,0 +1,4 @@
+/** The agent computer's status, shown in the header and read out by its button label. */
+export function computerStatus(available: boolean, activeSessions: number) {
+ return !available ? "offline" : activeSessions > 0 ? "take control" : "ready";
+}
diff --git a/apps/mobile/src/computer.tsx b/apps/mobile/src/computer.tsx
index 85aea83..285e051 100644
--- a/apps/mobile/src/computer.tsx
+++ b/apps/mobile/src/computer.tsx
@@ -13,6 +13,7 @@ import type { BrowserSession } from "../../../packages/domain/src";
import type { ComputerSnapshot } from "../../../packages/domain/src/computer";
import { browserAddress } from "./browser-address";
import { useComputerDraft } from "./computer-drafts";
+import { computerStatus } from "./computer-status";
import { LinuxWorkspace } from "./computer-workspace";
import { Button, Card, colors, ErrorNotice, Field, LinkRow, Sheet, s } from "./ui";
import { useWorkspace } from "./workspace";
@@ -23,10 +24,11 @@ export function ComputerEntry() {
(c) => c.id === "browser" && c.status === "connected",
);
const active = workspace.browsers.filter((b) => b.status === "active").length;
+ const status = computerStatus(available, active);
return (
<Pressable
accessibilityRole="button"
- accessibilityLabel="Agent computer — take control"
+ accessibilityLabel={`Agent computer — ${status}`}
onPress={() => open({ type: "computer" })}
style={[
s.row,
@@ -41,10 +43,7 @@ export function ComputerEntry() {
]}
>
<Monitor size={13} color={colors.muted} />
- <Text style={{ fontSize: 12, color: colors.muted }}>
- Computer
- {!available ? " · offline" : active ? " · take control" : " · ready"}
- </Text>
+ <Text style={{ fontSize: 12, color: colors.muted }}>Computer · {status}</Text>
<View
style={{
width: 5,
diff --git a/apps/mobile/test/computer-status.test.ts b/apps/mobile/test/computer-status.test.ts
new file mode 100644
index 0000000..c217c60
--- /dev/null
+++ b/apps/mobile/test/computer-status.test.ts
@@ -0,0 +1,10 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { computerStatus } from "../src/computer-status.ts";
+
+test("the computer status says offline before anything else", () => {
+ assert.equal(computerStatus(false, 0), "offline");
+ assert.equal(computerStatus(false, 2), "offline");
+ assert.equal(computerStatus(true, 0), "ready");
+ assert.equal(computerStatus(true, 1), "take control");
+});