From 81223e1a4e35223df2befb79809525fb21d70992 Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Sun, 8 Nov 2026 22:00:46 -0800 Subject: [PATCH 01/79] feat(desktop): routes, contracts and preview seams for clusters, sandboxes, waitlists, chat and local serving The app's sidebar gains Chat, Clusters, Sandboxes and Early access. Each feature gets its own shared types (shared/cluster.ts, sandbox.ts, waitlists.ts, chat.ts, localServing.ts), its own preview module (renderer/preview/*) and its own main-process relay (main/chat.ts, main/clusterSession.ts), so the pages can be built side by side. The native resources `cluster`, `sandbox`, `sandbox-logs` and `waitlists` are allowed through the main process; `useResource` reads a resource while its page is shown. Sandbox approval links open only on Darkbloom hosts over https. Co-Authored-By: Claude Opus 5.5 --- desktop-app/src/main/backend.ts | 4 + desktop-app/src/main/chat.ts | 29 +++++ desktop-app/src/main/clusterSession.ts | 33 +++++ desktop-app/src/main/ipc.ts | 45 ++++++- desktop-app/src/main/security.ts | 19 +++ desktop-app/src/preload/index.ts | 16 +++ desktop-app/src/renderer/App.tsx | 26 +++- .../renderer/components/operations/labels.ts | 11 ++ .../src/renderer/data/pageResources.ts | 6 + desktop-app/src/renderer/data/useResource.ts | 50 ++++++++ .../src/renderer/features/chat/Chat.tsx | 16 +++ .../src/renderer/features/cluster/Cluster.tsx | 16 +++ .../renderer/features/sandboxes/Sandboxes.tsx | 16 +++ .../features/waitlists/WaitlistCard.tsx | 30 +++++ .../renderer/features/waitlists/Waitlists.tsx | 25 ++++ .../features/waitlists/useWaitlist.ts | 54 ++++++++ desktop-app/src/renderer/preview.ts | 21 +++- desktop-app/src/renderer/preview/chat.ts | 18 +++ desktop-app/src/renderer/preview/cluster.ts | 4 + .../src/renderer/preview/clusterSession.ts | 21 ++++ desktop-app/src/renderer/preview/features.ts | 35 ++++++ .../src/renderer/preview/localServing.ts | 4 + desktop-app/src/renderer/preview/sandbox.ts | 4 + desktop-app/src/renderer/preview/types.ts | 47 +++++++ desktop-app/src/renderer/preview/waitlists.ts | 69 +++++++++++ desktop-app/src/shared/chat.ts | 57 +++++++++ desktop-app/src/shared/cluster.ts | 115 ++++++++++++++++++ desktop-app/src/shared/contracts.ts | 56 ++++++++- desktop-app/src/shared/localServing.ts | 35 ++++++ desktop-app/src/shared/sandbox.ts | 99 +++++++++++++++ desktop-app/src/shared/waitlists.ts | 34 ++++++ desktop-app/tests/app.test.tsx | 11 +- desktop-app/tests/pageTitle.test.tsx | 13 ++ docs/developer/desktop-app.md | 23 +++- 34 files changed, 1047 insertions(+), 15 deletions(-) create mode 100644 desktop-app/src/main/chat.ts create mode 100644 desktop-app/src/main/clusterSession.ts create mode 100644 desktop-app/src/renderer/data/useResource.ts create mode 100644 desktop-app/src/renderer/features/chat/Chat.tsx create mode 100644 desktop-app/src/renderer/features/cluster/Cluster.tsx create mode 100644 desktop-app/src/renderer/features/sandboxes/Sandboxes.tsx create mode 100644 desktop-app/src/renderer/features/waitlists/WaitlistCard.tsx create mode 100644 desktop-app/src/renderer/features/waitlists/Waitlists.tsx create mode 100644 desktop-app/src/renderer/features/waitlists/useWaitlist.ts create mode 100644 desktop-app/src/renderer/preview/chat.ts create mode 100644 desktop-app/src/renderer/preview/cluster.ts create mode 100644 desktop-app/src/renderer/preview/clusterSession.ts create mode 100644 desktop-app/src/renderer/preview/features.ts create mode 100644 desktop-app/src/renderer/preview/localServing.ts create mode 100644 desktop-app/src/renderer/preview/sandbox.ts create mode 100644 desktop-app/src/renderer/preview/types.ts create mode 100644 desktop-app/src/renderer/preview/waitlists.ts create mode 100644 desktop-app/src/shared/chat.ts create mode 100644 desktop-app/src/shared/cluster.ts create mode 100644 desktop-app/src/shared/localServing.ts create mode 100644 desktop-app/src/shared/sandbox.ts create mode 100644 desktop-app/src/shared/waitlists.ts diff --git a/desktop-app/src/main/backend.ts b/desktop-app/src/main/backend.ts index 7b9a3af161..addbabd7ab 100644 --- a/desktop-app/src/main/backend.ts +++ b/desktop-app/src/main/backend.ts @@ -35,6 +35,10 @@ const resources = new Set([ 'insights-month', 'request-history', 'hardware', + 'cluster', + 'sandbox', + 'sandbox-logs', + 'waitlists', ]); export function validateDiscovery(value: unknown): { port: number; diff --git a/desktop-app/src/main/chat.ts b/desktop-app/src/main/chat.ts new file mode 100644 index 0000000000..d228e1e50f --- /dev/null +++ b/desktop-app/src/main/chat.ts @@ -0,0 +1,29 @@ +import type { ChatEvent, ChatModels, ChatRequest } from '../shared/chat'; +import type { Backend } from './backend'; + +// Chat with this Mac's local API. The main process holds the local API key and makes every +// request, so the renderer never sees it; only a loopback base URL from the native snapshot is +// ever called. Each streamed answer is published as ChatEvents tagged with its stream ID. +export class ChatRelay { + constructor( + private backend: Backend, + private publish: (event: ChatEvent) => void, + ) {} + + async models(): Promise { + return { models: [], error: 'Chat is not available in this build.', code: 'unavailable' }; + } + + async send(_request: unknown): Promise<{ stream: string }> { + void this.backend; + void this.publish; + throw new Error('Chat is not available in this build.'); + } + + async cancel(_stream: unknown) {} + + // Ends every stream, such as when the window navigates or closes. + reset() {} +} + +export type { ChatRequest }; diff --git a/desktop-app/src/main/clusterSession.ts b/desktop-app/src/main/clusterSession.ts new file mode 100644 index 0000000000..fd073561c1 --- /dev/null +++ b/desktop-app/src/main/clusterSession.ts @@ -0,0 +1,33 @@ +import type { ClusterSession } from '../shared/cluster'; +import type { Backend } from './backend'; + +// The guided cluster setup session, run by the native API (`/control/v1/cluster/session`). This +// relays the session's routes and holds one event stream while the renderer watches it, +// publishing the whole session on every change. +export class ClusterSessionRelay { + constructor( + private backend: Backend, + private publish: (session: ClusterSession) => void, + ) {} + + async current(): Promise { + return null; + } + + async start(_start: unknown): Promise { + void this.backend; + void this.publish; + throw new Error('Cluster setup from the app needs a newer Darkbloom CLI.'); + } + + async answer(_answer: unknown): Promise { + throw new Error('Cluster setup from the app needs a newer Darkbloom CLI.'); + } + + acquire() {} + + release() {} + + // Drops every subscription, such as when the renderer navigates or crashes. + reset() {} +} diff --git a/desktop-app/src/main/ipc.ts b/desktop-app/src/main/ipc.ts index 02f41db44a..8e93a81466 100644 --- a/desktop-app/src/main/ipc.ts +++ b/desktop-app/src/main/ipc.ts @@ -2,10 +2,18 @@ import { app, clipboard, ipcMain, shell } from 'electron'; import path from 'node:path'; import type { Backend } from './backend'; import { HardwareWatch } from './hardware'; +import { ChatRelay } from './chat'; +import { ClusterSessionRelay } from './clusterSession'; import type { desktopUpdates } from './updates'; import type { MainWindow } from './window'; import type { SystemInfo } from '../shared/macos'; -import { clipboardText, externalURL, isTrustedSender, softwareUpdateURL } from './security'; +import { + approvalURL, + clipboardText, + externalURL, + isTrustedSender, + softwareUpdateURL, +} from './security'; function installScript() { return path.join( @@ -61,14 +69,45 @@ export function registerIPC(options: { (signal) => backend.openHardwareEvents(signal), (sample) => window.send('hardware:sample', sample), ); + const chat = new ChatRelay(backend, (event) => window.send('chat:event', event)); + const clusterSession = new ClusterSessionRelay(backend, (session) => + window.send('cluster:session', session), + ); window.webContents?.on('did-start-navigation', (details) => { - if (details.isMainFrame && !details.isSameDocument) hardware.reset(); + if (details.isMainFrame && !details.isSameDocument) { + hardware.reset(); + chat.reset(); + clusterSession.reset(); + } + }); + window.webContents?.on('render-process-gone', () => { + hardware.reset(); + chat.reset(); + clusterSession.reset(); }); - window.webContents?.on('render-process-gone', () => hardware.reset()); handle('hardware:watch', () => { if (!smokeTest) hardware.acquire(); }); handle('hardware:unwatch', () => hardware.release()); + handle('chat:models', () => chat.models()); + handle('chat:send', (request) => { + if (smokeTest) throw new Error('Chat is disabled in UI smoke tests'); + return chat.send(request); + }); + handle('chat:cancel', (stream) => chat.cancel(stream)); + handle('cluster:session', () => clusterSession.current()); + handle('cluster:session-start', (start) => { + if (smokeTest) throw new Error('Native actions are disabled in UI smoke tests'); + return clusterSession.start(start); + }); + handle('cluster:session-answer', (answer) => clusterSession.answer(answer)); + handle('cluster:session-watch', () => { + if (!smokeTest) clusterSession.acquire(); + }); + handle('cluster:session-unwatch', () => clusterSession.release()); + handle('app:approval', async (url) => { + await shell.openExternal(approvalURL(url)); + }); handle('app:update-status', () => updates.status()); handle('app:update', () => updates.check()); handle('app:apply-update', () => updates.apply()); diff --git a/desktop-app/src/main/security.ts b/desktop-app/src/main/security.ts index 9e701f5bc5..05ac3ef980 100644 --- a/desktop-app/src/main/security.ts +++ b/desktop-app/src/main/security.ts @@ -70,6 +70,25 @@ export function externalURL(target: unknown, deviceLinkURL: string | undefined) return url; } +// A sandbox setup's browser approval page, from the installer's own event: https on a +// Darkbloom host only (darkbloom.dev, darkbloom.ai and their subdomains), without credentials. +export function approvalURL(value: unknown) { + if (typeof value !== 'string' || value.length > 2048) throw new Error('Unsupported link'); + let url: URL; + try { + url = new URL(value); + } catch { + throw new Error('Unsupported link'); + } + const host = url.hostname; + const darkbloom = ['darkbloom.dev', 'darkbloom.ai'].some( + (domain) => host === domain || host.endsWith('.' + domain), + ); + if (url.protocol !== 'https:' || !darkbloom || url.username || url.password) + throw new Error('Unsupported link'); + return url.toString(); +} + export function clipboardText(text: unknown) { if (typeof text !== 'string' || text.length > 65536) throw new Error('Invalid clipboard value'); return text; diff --git a/desktop-app/src/preload/index.ts b/desktop-app/src/preload/index.ts index 18547870d4..d84b2eec32 100644 --- a/desktop-app/src/preload/index.ts +++ b/desktop-app/src/preload/index.ts @@ -29,5 +29,21 @@ const api: DesktopAPI = { void ipcRenderer.invoke('hardware:unwatch'); }; }, + chatModels: () => ipcRenderer.invoke('chat:models'), + chatSend: (request) => ipcRenderer.invoke('chat:send', request), + chatCancel: (stream) => ipcRenderer.invoke('chat:cancel', stream), + onChat: (callback) => subscribe('chat:event', callback), + clusterSession: () => ipcRenderer.invoke('cluster:session'), + startClusterSession: (start) => ipcRenderer.invoke('cluster:session-start', start), + answerClusterSession: (answer) => ipcRenderer.invoke('cluster:session-answer', answer), + onClusterSession: (callback) => { + const unsubscribe = subscribe('cluster:session', callback); + void ipcRenderer.invoke('cluster:session-watch'); + return () => { + unsubscribe(); + void ipcRenderer.invoke('cluster:session-unwatch'); + }; + }, + openApproval: (url) => ipcRenderer.invoke('app:approval', url), }; contextBridge.exposeInMainWorld('darkbloom', api); diff --git a/desktop-app/src/renderer/App.tsx b/desktop-app/src/renderer/App.tsx index a1c84f7edc..fc087f6678 100644 --- a/desktop-app/src/renderer/App.tsx +++ b/desktop-app/src/renderer/App.tsx @@ -1,5 +1,15 @@ import { useCallback, useEffect, useLayoutEffect, useState } from 'react'; -import { Box, Home as HomeIcon, Monitor, Trophy, Zap } from 'lucide-react'; +import { + Box, + Boxes, + Home as HomeIcon, + MessageCircle, + Monitor, + Network, + Ticket, + Trophy, + Zap, +} from 'lucide-react'; import type { Route } from '../shared/contracts'; import { api, isPreview, useBackend } from './useBackend'; import { Home } from './features/Home'; @@ -17,11 +27,19 @@ import { GetHelp, HelpControl } from './components/Help'; import { AccountControl } from './components/AccountControl'; import { SocialLinks } from './components/SocialLinks'; import { useFocusRecovery } from './useFocusRecovery'; +import { Chat } from './features/chat/Chat'; +import { Cluster } from './features/cluster/Cluster'; +import { Sandboxes } from './features/sandboxes/Sandboxes'; +import { Waitlists } from './features/waitlists/Waitlists'; const navigation = [ { id: 'home', label: 'Home', icon: HomeIcon }, + { id: 'chat', label: 'Chat', icon: MessageCircle }, { id: 'machines', label: 'My Macs', icon: Monitor }, + { id: 'cluster', label: 'Clusters', icon: Network }, + { id: 'sandboxes', label: 'Sandboxes', icon: Boxes }, { id: 'leaderboard', label: 'Leaderboard', icon: Trophy }, { id: 'updates', label: 'Updates', icon: Box }, + { id: 'waitlists', label: 'Early access', icon: Ticket }, ] as const; export default function App() { const [{ route, machine }, setView] = useState<{ route: Route; machine: MachineSelection }>({ @@ -109,7 +127,7 @@ export default function App() {
{backend.status.state !== 'ready' && ( @@ -135,6 +153,10 @@ export default function App() { {route === 'earnings' && } {route === 'updates' && } {route === 'leaderboard' && } + {route === 'chat' && } + {route === 'cluster' && } + {route === 'sandboxes' && } + {route === 'waitlists' && }