Skip to content

Commit 18d281e

Browse files
feat(desktop): open UA Control Center in preview pane (#1)
Add View menu affordance that loads the Mac hub /ui in the existing desktop preview BrowserSession (ua_ui cookie auth, configurable URL). Co-authored-by: Cursor <[email protected]>
1 parent fd4c473 commit 18d281e

11 files changed

Lines changed: 213 additions & 0 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,4 @@ Full glossary with file links: `docs/internals/glossary.md`
168168
- MacBook Pro also runs a T3 server; MacBook Air is typically client-only. Prefer `t3 pair --tailscale` for phone/remote pairing once Tailscale **Serve** and **HTTPS Certificates** are enabled on the tailnet (admin DNS + Serve enable link). Until then, use MagicDNS HTTP (`http://desktopubuntu.tailb8459a.ts.net:3773/pair#token=…`) — never paste a `127.0.0.1` pair URL into a phone. Keep `t3code.service` on `T3CODE_HOST=0.0.0.0` (`t3 service update` has stripped that before).
169169
- Local Linux desktop install used here: `~/.local/opt/t3code` with `~/.local/bin/t3code` (clears `ELECTRON_RUN_AS_NODE`); see `scripts/install-local-desktop.sh`.
170170
- Initiative to embed UA web UI surfaces into tcode desktop is filed as task #625.
171+
- UA Control Center (first slice, task #635): desktop **View → Open Unified Agent Control Center** loads the Mac hub `/ui` in the existing preview pane (default `http://100.111.5.64:8765/ui`, override with `T3CODE_UA_CONTROL_CENTER_URL`). Auth is hub `ua_ui` cookie via BrowserSession — not MCP bearer. Origin/CORS follow-ups are task #636 if embed is blocked.

‎apps/desktop/src/app/DesktopConfig.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DEFAULT_UA_CONTROL_CENTER_URL } from "@t3tools/shared/uaControlCenter";
12
import * as Config from "effect/Config";
23
import * as ConfigProvider from "effect/ConfigProvider";
34
import * as Option from "effect/Option";
@@ -54,6 +55,24 @@ export const DesktopConfig = Config.all({
5455
mockUpdateServerPort: Config.port("T3CODE_DESKTOP_MOCK_UPDATE_SERVER_PORT").pipe(
5556
Config.withDefault(3000),
5657
),
58+
/**
59+
* Mac hub Control Center URL loaded in the desktop preview pane.
60+
* Auth is the hub UI cookie session (ua_ui), not an MCP bearer in the renderer.
61+
*/
62+
uaControlCenterUrl: Config.string("T3CODE_UA_CONTROL_CENTER_URL").pipe(
63+
Config.withDefault(DEFAULT_UA_CONTROL_CENTER_URL),
64+
Config.map((value) => {
65+
const trimmed = value.trim();
66+
if (trimmed.length === 0) {
67+
return DEFAULT_UA_CONTROL_CENTER_URL;
68+
}
69+
try {
70+
return new URL(trimmed).href;
71+
} catch {
72+
return DEFAULT_UA_CONTROL_CENTER_URL;
73+
}
74+
}),
75+
),
5776
});
5877

5978
export const layerTest = (env: Readonly<Record<string, string | undefined>>) =>

‎apps/desktop/src/app/DesktopEnvironment.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe("DesktopEnvironment", () => {
7979
assert.deepEqual(environment.commitHashOverride, Option.some("0123456789abcdef"));
8080
assert.deepEqual(environment.otlpTracesUrl, Option.some("http://127.0.0.1:4318/v1/traces"));
8181
assert.equal(environment.otlpExportIntervalMs, 2500);
82+
assert.equal(environment.uaControlCenterUrl, "http://100.111.5.64:8765/ui");
8283
}),
8384
);
8485

@@ -163,4 +164,18 @@ describe("DesktopEnvironment", () => {
163164
);
164165
}),
165166
);
167+
168+
it.effect("honors T3CODE_UA_CONTROL_CENTER_URL", () =>
169+
Effect.gen(function* () {
170+
const environment = yield* makeEnvironment(
171+
{},
172+
{
173+
T3CODE_HOME: "/tmp/t3",
174+
T3CODE_UA_CONTROL_CENTER_URL: " http://127.0.0.1:8765/ui ",
175+
},
176+
);
177+
178+
assert.equal(environment.uaControlCenterUrl, "http://127.0.0.1:8765/ui");
179+
}),
180+
);
166181
});

‎apps/desktop/src/app/DesktopEnvironment.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ export class DesktopEnvironment extends Context.Service<
6969
readonly commitHashOverride: Option.Option<string>;
7070
readonly otlpTracesUrl: Option.Option<string>;
7171
readonly otlpExportIntervalMs: number;
72+
/**
73+
* Mac hub Control Center URL for the desktop preview pane
74+
* (`T3CODE_UA_CONTROL_CENTER_URL`, default Tailscale hub `/ui`).
75+
*/
76+
readonly uaControlCenterUrl: string;
7277
readonly branding: DesktopAppBranding;
7378
readonly displayName: string;
7479
readonly appUserModelId: string;
@@ -221,6 +226,7 @@ const make = Effect.fn("desktop.environment.make")(function* (
221226
commitHashOverride: config.commitHashOverride,
222227
otlpTracesUrl: config.otlpTracesUrl,
223228
otlpExportIntervalMs: config.otlpExportIntervalMs,
229+
uaControlCenterUrl: config.uaControlCenterUrl,
224230
branding,
225231
displayName,
226232
appUserModelId: Option.getOrElse(config.appUserModelIdOverride, () =>

‎apps/desktop/src/window/DesktopApplicationMenu.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,38 @@ describe("DesktopApplicationMenu", () => {
180180
assert.equal(yield* Deferred.await(selectedAction), "zoom-in");
181181
}),
182182
);
183+
184+
it.effect("routes View menu Unified Agent Control Center through DesktopWindow", () =>
185+
Effect.gen(function* () {
186+
const selectedAction = yield* Deferred.make<string>();
187+
const applicationMenuTemplate =
188+
yield* Deferred.make<readonly Electron.MenuItemConstructorOptions[]>();
189+
190+
yield* configureMenu(selectedAction, applicationMenuTemplate);
191+
192+
const template = yield* Deferred.await(applicationMenuTemplate);
193+
const viewMenu = template.find((item) => item.label === "View");
194+
assert.isDefined(viewMenu);
195+
if (!Array.isArray(viewMenu.submenu)) {
196+
throw new Error("Expected View menu submenu to be an array.");
197+
}
198+
199+
const controlCenterItem = viewMenu.submenu.find(
200+
(item) => item.label === "Open Unified Agent Control Center",
201+
);
202+
assert.isDefined(controlCenterItem);
203+
if (typeof controlCenterItem.click !== "function") {
204+
throw new Error("Expected Control Center menu item to have a click handler.");
205+
}
206+
207+
controlCenterItem.click(
208+
{} as Electron.MenuItem,
209+
{} as Electron.BrowserWindow,
210+
{} as KeyboardEvent,
211+
);
212+
const action = yield* Deferred.await(selectedAction);
213+
assert.isTrue(action.startsWith("open-ua-control-center:"));
214+
assert.isTrue(action.includes("100.111.5.64:8765/ui"));
215+
}),
216+
);
183217
});

‎apps/desktop/src/window/DesktopApplicationMenu.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as Effect from "effect/Effect";
33
import * as Layer from "effect/Layer";
44
import * as Option from "effect/Option";
55
import * as Schema from "effect/Schema";
6+
import { encodeUaControlCenterMenuAction } from "@t3tools/shared/uaControlCenter";
67

78
import type * as Electron from "electron";
89

@@ -134,6 +135,12 @@ export const make = Effect.gen(function* () {
134135
const settingsClick = () => {
135136
runMenuEffect("open-settings", dispatchMenuAction("open-settings"));
136137
};
138+
const openUaControlCenterClick = () => {
139+
runMenuEffect(
140+
"open-ua-control-center",
141+
dispatchMenuAction(encodeUaControlCenterMenuAction(environment.uaControlCenterUrl)),
142+
);
143+
};
137144
const zoomClick = (direction: DesktopWindow.MainWindowZoomDirection) => () => {
138145
runMenuEffect(`zoom-${direction}`, zoomMainWindow(direction));
139146
};
@@ -208,6 +215,11 @@ export const make = Effect.gen(function* () {
208215
{ label: "Zoom Out", accelerator: "CmdOrCtrl+-", click: zoomClick("out") },
209216
{ type: "separator" },
210217
{ role: "togglefullscreen" },
218+
{ type: "separator" },
219+
{
220+
label: "Open Unified Agent Control Center",
221+
click: openUaControlCenterClick,
222+
},
211223
],
212224
},
213225
{ role: "windowMenu" },
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2+
import { parseUaControlCenterMenuAction } from "@t3tools/shared/uaControlCenter";
3+
import { useEffect, useMemo } from "react";
4+
5+
import { openUrlInPreview } from "~/browser/openFileInPreview";
6+
import { useHandleNewThread } from "~/hooks/useHandleNewThread";
7+
import { isPreviewSupportedInRuntime } from "~/previewStateStore";
8+
import { previewEnvironment } from "~/state/preview";
9+
import { useAtomCommand } from "~/state/use-atom-command";
10+
import { stackedThreadToast, toastManager } from "~/components/ui/toast";
11+
12+
/**
13+
* Opens the Mac hub Control Center in the existing desktop preview pane when
14+
* the application menu fires `open-ua-control-center:<url>`.
15+
*
16+
* Auth is the hub's `ua_ui` cookie in the shared BrowserSession partition —
17+
* never an MCP bearer in the renderer.
18+
*/
19+
export function UaControlCenterMenuHandler() {
20+
const { activeDraftThread, routeThreadRef } = useHandleNewThread();
21+
const openPreview = useAtomCommand(previewEnvironment.open, { reportFailure: false });
22+
23+
const threadRef = useMemo(() => {
24+
if (routeThreadRef) {
25+
return routeThreadRef;
26+
}
27+
if (activeDraftThread) {
28+
return scopeThreadRef(activeDraftThread.environmentId, activeDraftThread.threadId);
29+
}
30+
return null;
31+
}, [activeDraftThread, routeThreadRef]);
32+
33+
useEffect(() => {
34+
const onMenuAction = window.desktopBridge?.onMenuAction;
35+
if (typeof onMenuAction !== "function") {
36+
return;
37+
}
38+
39+
const unsubscribe = onMenuAction((action) => {
40+
const url = parseUaControlCenterMenuAction(action);
41+
if (url === null) {
42+
return;
43+
}
44+
45+
if (!isPreviewSupportedInRuntime()) {
46+
toastManager.add(
47+
stackedThreadToast({
48+
type: "info",
49+
title: "Control Center needs desktop preview",
50+
description: "Open T3 Code in the desktop app to embed Unified Agent Control Center.",
51+
}),
52+
);
53+
return;
54+
}
55+
56+
if (threadRef === null) {
57+
toastManager.add(
58+
stackedThreadToast({
59+
type: "info",
60+
title: "Open a thread first",
61+
description: "Unified Agent Control Center opens in the active thread's preview pane.",
62+
}),
63+
);
64+
return;
65+
}
66+
67+
void openUrlInPreview({
68+
threadRef,
69+
url,
70+
openPreview,
71+
});
72+
});
73+
74+
return () => {
75+
unsubscribe?.();
76+
};
77+
}, [openPreview, threadRef]);
78+
79+
return null;
80+
}

‎apps/web/src/routes/__root.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ConfirmDialogHost } from "../components/ConfirmDialogHost";
1818
import { ConnectOnboardingDialog } from "../components/cloud/ConnectOnboardingDialog";
1919
import { RelayClientInstallDialog } from "../components/cloud/RelayClientInstallDialog";
2020
import { SshPasswordPromptDialog } from "../components/desktop/SshPasswordPromptDialog";
21+
import { UaControlCenterMenuHandler } from "../components/desktop/UaControlCenterMenuHandler";
2122
import { ProviderUpdateLaunchNotification } from "../components/ProviderUpdateLaunchNotification";
2223
import { SlowRpcRequestToastCoordinator } from "../components/SlowRpcRequestToastCoordinator";
2324
import { ThemeEditorHost } from "../components/settings/ThemeEditorHost";
@@ -123,6 +124,7 @@ function RootRouteView() {
123124
const appShell = (
124125
<CommandPalette>
125126
<AppSidebarLayout>
127+
<UaControlCenterMenuHandler />
126128
<Outlet />
127129
</AppSidebarLayout>
128130
</CommandPalette>

‎packages/shared/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@
191191
"types": "./src/preview.ts",
192192
"import": "./src/preview.ts"
193193
},
194+
"./uaControlCenter": {
195+
"types": "./src/uaControlCenter.ts",
196+
"import": "./src/uaControlCenter.ts"
197+
},
194198
"./previewViewport": {
195199
"types": "./src/previewViewport.ts",
196200
"import": "./src/previewViewport.ts"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import {
4+
DEFAULT_UA_CONTROL_CENTER_URL,
5+
encodeUaControlCenterMenuAction,
6+
OPEN_UA_CONTROL_CENTER_MENU_ACTION,
7+
parseUaControlCenterMenuAction,
8+
} from "./uaControlCenter.ts";
9+
10+
describe("uaControlCenter menu action", () => {
11+
it("encodes and parses the Control Center URL", () => {
12+
const action = encodeUaControlCenterMenuAction(DEFAULT_UA_CONTROL_CENTER_URL);
13+
expect(action.startsWith(`${OPEN_UA_CONTROL_CENTER_MENU_ACTION}:`)).toBe(true);
14+
expect(parseUaControlCenterMenuAction(action)).toBe(DEFAULT_UA_CONTROL_CENTER_URL);
15+
});
16+
17+
it("rejects unrelated or empty payloads", () => {
18+
expect(parseUaControlCenterMenuAction("open-settings")).toBeNull();
19+
expect(parseUaControlCenterMenuAction(`${OPEN_UA_CONTROL_CENTER_MENU_ACTION}:`)).toBeNull();
20+
expect(parseUaControlCenterMenuAction(`${OPEN_UA_CONTROL_CENTER_MENU_ACTION}: `)).toBeNull();
21+
});
22+
});

0 commit comments

Comments
 (0)