Remove legacy local backend and telemetry RPC

- drop browser-only local backend stubs in favor of desktop bridge
- route resource telemetry through the subscription path
This commit is contained in:
Julius Marminge committed 2026-06-18 22:00:25 -07:00
1 parent 4a875dbe51
commit 7addf7c6d6
8 files changed
+26 -325

No files matched your search

+17
View File
@@ -4272,6 +4272,23 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);
it.effect("routes websocket resource telemetry through the subscription", () =>
Effect.gen(function* () {
yield* buildAppUnderTest();
const wsUrl = yield* getWsServerUrl("/ws");
const snapshot = yield* Effect.scoped(
withWsRpcClient(wsUrl, (client) =>
client[WS_METHODS.subscribeResourceTelemetry]({}).pipe(Stream.runHead),
),
);
assertTrue(Option.isSome(snapshot));
assert.equal(snapshot.value.processes.length, 0);
assert.equal(snapshot.value.groups.backend.processCount, 0);
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);
it.effect("routes websocket rpc subscribeServerConfig emits provider status updates", () =>
Effect.gen(function* () {
const nextProviders = [
-5
View File
@@ -160,7 +160,6 @@ const RPC_REQUIRED_SCOPE = new Map<string, AuthEnvironmentScope>([
[WS_METHODS.serverGetTraceDiagnostics, AuthOrchestrationReadScope],
[WS_METHODS.serverGetProcessDiagnostics, AuthOrchestrationReadScope],
[WS_METHODS.serverGetProcessResourceHistory, AuthOrchestrationReadScope],
[WS_METHODS.serverGetResourceTelemetry, AuthOrchestrationReadScope],
[WS_METHODS.serverGetResourceTelemetryHistory, AuthOrchestrationReadScope],
[WS_METHODS.serverRetryResourceTelemetry, AuthOrchestrationOperateScope],
[WS_METHODS.serverSignalProcess, AuthOrchestrationOperateScope],
@@ -1124,10 +1123,6 @@ const makeWsRpcLayer = (currentSession: AuthenticatedSession) =>
"rpc.aggregate": "server",
},
),
[WS_METHODS.serverGetResourceTelemetry]: (_input) =>
observeRpcEffect(WS_METHODS.serverGetResourceTelemetry, resourceTelemetry.latest, {
"rpc.aggregate": "server",
}),
[WS_METHODS.serverGetResourceTelemetryHistory]: (input) =>
observeRpcEffect(
WS_METHODS.serverGetResourceTelemetryHistory,
+2 -4
View File
@@ -1,8 +1,6 @@
/**
* True when running inside the Electron preload bridge, false in a regular browser.
* The preload script sets window.nativeApi via contextBridge before any web-app
* The preload script sets window.desktopBridge via contextBridge before any web-app
* code executes, so this is reliable at module load time.
*/
export const isElectron =
typeof window !== "undefined" &&
(window.desktopBridge !== undefined || window.nativeApi !== undefined);
export const isElectron = typeof window !== "undefined" && window.desktopBridge !== undefined;
+3 -16
View File
@@ -49,7 +49,6 @@ beforeEach(() => {
});
}
Reflect.deleteProperty(testWindow(), "desktopBridge");
Reflect.deleteProperty(testWindow(), "nativeApi");
Object.defineProperty(testWindow(), "localStorage", {
configurable: true,
value: createLocalStorageStub(),
@@ -61,16 +60,12 @@ afterEach(() => {
});
describe("LocalApi", () => {
it("keeps backend operations unavailable in the browser facade", async () => {
it("keeps backend operations out of the local host facade", async () => {
const { createLocalApi } = await import("./localApi");
const api = createLocalApi();
await expect(api.server.getConfig()).rejects.toThrow(
"Local backend API is unavailable before a backend is paired.",
);
await expect(api.shell.openInEditor("/tmp", "cursor")).rejects.toThrow(
"Local backend API is unavailable before a backend is paired.",
);
expect(api).not.toHaveProperty("server");
expect(api.shell).not.toHaveProperty("openInEditor");
});
it("uses the browser context-menu fallback without a desktop bridge", async () => {
@@ -120,12 +115,4 @@ describe("LocalApi", () => {
await api.persistence.setClientSettings(settings);
await expect(api.persistence.getClientSettings()).resolves.toEqual(settings);
});
it("prefers the native LocalApi when one is injected", async () => {
const nativeApi = { dialogs: {} };
testWindow().nativeApi = nativeApi as never;
const { readLocalApi } = await import("./localApi");
expect(readLocalApi()).toBe(nativeApi);
});
});
+1 -28
View File
@@ -6,10 +6,6 @@ import { readBrowserClientSettings, writeBrowserClientSettings } from "./clientP
let cachedApi: LocalApi | undefined;
function unavailableLocalBackendError(): Error {
return new Error("Local backend API is unavailable before a backend is paired.");
}
function createBrowserLocalApi(): LocalApi {
return {
dialogs: {
@@ -25,7 +21,6 @@ function createBrowserLocalApi(): LocalApi {
},
},
shell: {
openInEditor: () => Promise.reject(unavailableLocalBackendError()),
openExternal: async (url) => {
if (window.desktopBridge) {
const opened = await window.desktopBridge.openExternal(url);
@@ -63,23 +58,6 @@ function createBrowserLocalApi(): LocalApi {
writeBrowserClientSettings(settings);
},
},
server: {
getConfig: () => Promise.reject(unavailableLocalBackendError()),
refreshProviders: () => Promise.reject(unavailableLocalBackendError()),
updateProvider: () => Promise.reject(unavailableLocalBackendError()),
upsertKeybinding: () => Promise.reject(unavailableLocalBackendError()),
removeKeybinding: () => Promise.reject(unavailableLocalBackendError()),
getSettings: () => Promise.reject(unavailableLocalBackendError()),
updateSettings: () => Promise.reject(unavailableLocalBackendError()),
discoverSourceControl: () => Promise.reject(unavailableLocalBackendError()),
getTraceDiagnostics: () => Promise.reject(unavailableLocalBackendError()),
getProcessDiagnostics: () => Promise.reject(unavailableLocalBackendError()),
getProcessResourceHistory: () => Promise.reject(unavailableLocalBackendError()),
getResourceTelemetry: () => Promise.reject(unavailableLocalBackendError()),
getResourceTelemetryHistory: () => Promise.reject(unavailableLocalBackendError()),
retryResourceTelemetry: () => Promise.reject(unavailableLocalBackendError()),
signalProcess: () => Promise.reject(unavailableLocalBackendError()),
},
};
}
@@ -91,12 +69,7 @@ export function readLocalApi(): LocalApi | undefined {
if (typeof window === "undefined") return undefined;
if (cachedApi) return cachedApi;
if (window.nativeApi) {
cachedApi = window.nativeApi;
return cachedApi;
}
cachedApi = createBrowserLocalApi();
cachedApi = createLocalApi();
return cachedApi;
}
+1 -2
View File
@@ -1,6 +1,6 @@
/// <reference types="vite-plus/client" />
import type { DesktopBridge, LocalApi } from "@t3tools/contracts";
import type { DesktopBridge } from "@t3tools/contracts";
interface ImportMetaEnv {
readonly VITE_HTTP_URL: string;
@@ -21,7 +21,6 @@ interface ImportMeta {
declare global {
interface Window {
nativeApi?: LocalApi;
desktopBridge?: DesktopBridge;
}
}
+2 -262
View File
@@ -1,121 +1,19 @@
import type {
VcsCreateRefInput,
VcsCreateRefResult,
VcsCreateWorktreeInput,
VcsCreateWorktreeResult,
VcsInitInput,
VcsListRefsInput,
VcsListRefsResult,
VcsPullInput,
VcsPullResult,
VcsRemoveWorktreeInput,
VcsSwitchRefInput,
VcsSwitchRefResult,
GitPreparePullRequestThreadInput,
GitPreparePullRequestThreadResult,
GitPullRequestRefInput,
GitResolvePullRequestResult,
VcsStatusInput,
VcsStatusResult,
} from "./git.ts";
import type { ReviewDiffPreviewInput, ReviewDiffPreviewResult } from "./review.ts";
import type { FilesystemBrowseInput, FilesystemBrowseResult } from "./filesystem.ts";
import type { AssetCreateUrlInput, AssetCreateUrlResult } from "./assets.ts";
import type {
ProjectListEntriesInput,
ProjectListEntriesResult,
ProjectReadFileInput,
ProjectReadFileResult,
ProjectSearchEntriesInput,
ProjectSearchEntriesResult,
ProjectWriteFileInput,
ProjectWriteFileResult,
} from "./project.ts";
import type { ProviderInstanceId } from "./providerInstance.ts";
import type {
ResourceTelemetryHistory,
ResourceTelemetryHistoryInput,
ResourceTelemetryRetryResult,
ResourceTelemetrySnapshot,
} from "./resourceTelemetry.ts";
import type {
ServerConfig,
ServerProcessDiagnosticsResult,
ServerProcessResourceHistoryInput,
ServerProcessResourceHistoryResult,
ServerProviderUpdateInput,
ServerProviderUpdatedPayload,
ServerRemoveKeybindingResult,
ServerSignalProcessInput,
ServerSignalProcessResult,
ServerTraceDiagnosticsResult,
ServerUpsertKeybindingResult,
} from "./server.ts";
import type {
TerminalAttachInput,
TerminalAttachStreamEvent,
TerminalClearInput,
TerminalCloseInput,
TerminalMetadataStreamEvent,
TerminalOpenInput,
TerminalResizeInput,
TerminalRestartInput,
TerminalSessionSnapshot,
TerminalWriteInput,
} from "./terminal.ts";
import type { ServerRemoveKeybindingInput, ServerUpsertKeybindingInput } from "./server.ts";
import * as Schema from "effect/Schema";
import type {
DiscoveredLocalServerList,
PreviewCloseInput,
PreviewEvent,
PreviewListInput,
PreviewListResult,
PreviewNavigateInput,
PreviewOpenInput,
PreviewRefreshInput,
PreviewReportStatusInput,
PreviewSessionSnapshot,
} from "./preview.ts";
import {
PreviewAutomationClickInput,
PreviewAutomationEvaluateInput,
PreviewAutomationOwner,
PreviewAutomationPressInput,
PreviewAutomationRequest,
PreviewAutomationResponse,
PreviewAutomationScrollInput,
PreviewAutomationSnapshot,
PreviewAutomationStatus,
PreviewAutomationTypeInput,
PreviewAutomationWaitForInput,
} from "./previewAutomation.ts";
import type {
ClientOrchestrationCommand,
OrchestrationGetFullThreadDiffInput,
OrchestrationGetFullThreadDiffResult,
OrchestrationGetTurnDiffInput,
OrchestrationGetTurnDiffResult,
OrchestrationShellSnapshot,
OrchestrationShellStreamItem,
OrchestrationSubscribeThreadInput,
OrchestrationThreadStreamItem,
} from "./orchestration.ts";
import { EnvironmentId } from "./baseSchemas.ts";
import { AuthAccessTokenResult, AuthSessionState, AuthWebSocketTicketResult } from "./auth.ts";
import { AdvertisedEndpoint } from "./remoteAccess.ts";
import { EditorId } from "./editor.ts";
import { ExecutionEnvironmentDescriptor } from "./environment.ts";
import type { ClientSettings, ServerSettings, ServerSettingsPatch } from "./settings.ts";
import type {
SourceControlCloneRepositoryInput,
SourceControlCloneRepositoryResult,
SourceControlDiscoveryResult,
SourceControlPublishRepositoryInput,
SourceControlPublishRepositoryResult,
SourceControlRepositoryInfo,
SourceControlRepositoryLookupInput,
} from "./sourceControl.ts";
import type { ClientSettings } from "./settings.ts";
export interface ContextMenuItem<T extends string = string> {
id: T;
@@ -1027,7 +925,7 @@ export interface DesktopPreviewBridge {
* APIs bound to the local app shell, not to any particular backend environment.
*
* These capabilities describe the desktop/browser host that the user is
* currently running: dialogs, editor/external-link opening, context menus, and
* currently running: dialogs, external-link opening, context menus, and
* app-level settings/config access. They must not be used as a proxy for
* "whatever environment the user is targeting", because in a multi-environment
* world the local shell and a selected backend environment are distinct
@@ -1039,7 +937,6 @@ export interface LocalApi {
confirm: (message: string) => Promise<boolean>;
};
shell: {
openInEditor: (cwd: string, editor: EditorId) => Promise<void>;
openExternal: (url: string) => Promise<void>;
};
contextMenu: {
@@ -1052,161 +949,4 @@ export interface LocalApi {
getClientSettings: () => Promise<ClientSettings | null>;
setClientSettings: (settings: ClientSettings) => Promise<void>;
};
server: {
getConfig: () => Promise<ServerConfig>;
/**
* Refresh provider snapshots. When `input.instanceId` is supplied only that
* configured instance is probed; otherwise every configured instance is
* refreshed (legacy untargeted refresh).
*/
refreshProviders: (input?: {
readonly instanceId?: ProviderInstanceId;
}) => Promise<ServerProviderUpdatedPayload>;
updateProvider: (input: ServerProviderUpdateInput) => Promise<ServerProviderUpdatedPayload>;
upsertKeybinding: (input: ServerUpsertKeybindingInput) => Promise<ServerUpsertKeybindingResult>;
removeKeybinding: (input: ServerRemoveKeybindingInput) => Promise<ServerRemoveKeybindingResult>;
getSettings: () => Promise<ServerSettings>;
updateSettings: (patch: ServerSettingsPatch) => Promise<ServerSettings>;
discoverSourceControl: () => Promise<SourceControlDiscoveryResult>;
getTraceDiagnostics: () => Promise<ServerTraceDiagnosticsResult>;
getProcessDiagnostics: () => Promise<ServerProcessDiagnosticsResult>;
getProcessResourceHistory: (
input: ServerProcessResourceHistoryInput,
) => Promise<ServerProcessResourceHistoryResult>;
getResourceTelemetry: () => Promise<ResourceTelemetrySnapshot>;
getResourceTelemetryHistory: (
input: ResourceTelemetryHistoryInput,
) => Promise<ResourceTelemetryHistory>;
retryResourceTelemetry: () => Promise<ResourceTelemetryRetryResult>;
signalProcess: (input: ServerSignalProcessInput) => Promise<ServerSignalProcessResult>;
};
}
/**
* APIs bound to a specific backend environment connection.
*
* These operations must always be routed with explicit environment context.
* They represent remote stateful capabilities such as orchestration, terminal,
* project, VCS, and provider operations. In multi-environment mode, each environment gets
* its own instance of this surface, and callers should resolve it by
* `environmentId` rather than reaching through the local desktop bridge.
*/
export interface EnvironmentApi {
terminal: {
open: (input: typeof TerminalOpenInput.Encoded) => Promise<TerminalSessionSnapshot>;
attach: (
input: typeof TerminalAttachInput.Encoded,
callback: (event: TerminalAttachStreamEvent) => void,
options?: {
onResubscribe?: () => void;
},
) => () => void;
write: (input: typeof TerminalWriteInput.Encoded) => Promise<void>;
resize: (input: typeof TerminalResizeInput.Encoded) => Promise<void>;
clear: (input: typeof TerminalClearInput.Encoded) => Promise<void>;
restart: (input: typeof TerminalRestartInput.Encoded) => Promise<TerminalSessionSnapshot>;
close: (input: typeof TerminalCloseInput.Encoded) => Promise<void>;
onMetadata: (
callback: (event: TerminalMetadataStreamEvent) => void,
options?: {
onResubscribe?: () => void;
},
) => () => void;
};
projects: {
listEntries: (input: ProjectListEntriesInput) => Promise<ProjectListEntriesResult>;
readFile: (input: ProjectReadFileInput) => Promise<ProjectReadFileResult>;
searchEntries: (input: ProjectSearchEntriesInput) => Promise<ProjectSearchEntriesResult>;
writeFile: (input: ProjectWriteFileInput) => Promise<ProjectWriteFileResult>;
};
filesystem: {
browse: (input: FilesystemBrowseInput) => Promise<FilesystemBrowseResult>;
};
assets: {
createUrl: (input: AssetCreateUrlInput) => Promise<AssetCreateUrlResult>;
};
sourceControl: {
lookupRepository: (
input: SourceControlRepositoryLookupInput,
) => Promise<SourceControlRepositoryInfo>;
cloneRepository: (
input: SourceControlCloneRepositoryInput,
) => Promise<SourceControlCloneRepositoryResult>;
publishRepository: (
input: SourceControlPublishRepositoryInput,
) => Promise<SourceControlPublishRepositoryResult>;
};
vcs: {
listRefs: (input: VcsListRefsInput) => Promise<VcsListRefsResult>;
createWorktree: (input: VcsCreateWorktreeInput) => Promise<VcsCreateWorktreeResult>;
removeWorktree: (input: VcsRemoveWorktreeInput) => Promise<void>;
createRef: (input: VcsCreateRefInput) => Promise<VcsCreateRefResult>;
switchRef: (input: VcsSwitchRefInput) => Promise<VcsSwitchRefResult>;
init: (input: VcsInitInput) => Promise<void>;
pull: (input: VcsPullInput) => Promise<VcsPullResult>;
refreshStatus: (input: VcsStatusInput) => Promise<VcsStatusResult>;
onStatus: (
input: VcsStatusInput,
callback: (status: VcsStatusResult) => void,
options?: {
onResubscribe?: () => void;
},
) => () => void;
};
git: {
resolvePullRequest: (input: GitPullRequestRefInput) => Promise<GitResolvePullRequestResult>;
preparePullRequestThread: (
input: GitPreparePullRequestThreadInput,
) => Promise<GitPreparePullRequestThreadResult>;
};
review: {
getDiffPreview: (input: ReviewDiffPreviewInput) => Promise<ReviewDiffPreviewResult>;
};
orchestration: {
dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>;
getTurnDiff: (input: OrchestrationGetTurnDiffInput) => Promise<OrchestrationGetTurnDiffResult>;
getFullThreadDiff: (
input: OrchestrationGetFullThreadDiffInput,
) => Promise<OrchestrationGetFullThreadDiffResult>;
getArchivedShellSnapshot: () => Promise<OrchestrationShellSnapshot>;
subscribeShell: (
callback: (event: OrchestrationShellStreamItem) => void,
options?: {
onResubscribe?: () => void;
},
) => () => void;
subscribeThread: (
input: OrchestrationSubscribeThreadInput,
callback: (event: OrchestrationThreadStreamItem) => void,
options?: {
onResubscribe?: () => void;
},
) => () => void;
};
preview: {
open: (input: typeof PreviewOpenInput.Encoded) => Promise<PreviewSessionSnapshot>;
navigate: (input: typeof PreviewNavigateInput.Encoded) => Promise<PreviewSessionSnapshot>;
refresh: (input: typeof PreviewRefreshInput.Encoded) => Promise<void>;
close: (input: typeof PreviewCloseInput.Encoded) => Promise<void>;
list: (input: typeof PreviewListInput.Encoded) => Promise<PreviewListResult>;
reportStatus: (input: typeof PreviewReportStatusInput.Encoded) => Promise<void>;
automation: {
connect: (
input: { clientId: string },
callback: (request: PreviewAutomationRequest) => void,
options?: { onResubscribe?: () => void },
) => () => void;
respond: (response: PreviewAutomationResponse) => Promise<void>;
reportOwner: (owner: PreviewAutomationOwner) => Promise<void>;
clearOwner: (input: { clientId: string }) => Promise<void>;
};
onEvent: (
callback: (event: PreviewEvent) => void,
options?: { onResubscribe?: () => void },
) => () => void;
subscribePorts: (
callback: (servers: DiscoveredLocalServerList) => void,
options?: { onResubscribe?: () => void },
) => () => void;
};
}
-8
View File
@@ -221,7 +221,6 @@ export const WS_METHODS = {
serverGetTraceDiagnostics: "server.getTraceDiagnostics",
serverGetProcessDiagnostics: "server.getProcessDiagnostics",
serverGetProcessResourceHistory: "server.getProcessResourceHistory",
serverGetResourceTelemetry: "server.getResourceTelemetry",
serverGetResourceTelemetryHistory: "server.getResourceTelemetryHistory",
serverRetryResourceTelemetry: "server.retryResourceTelemetry",
serverSignalProcess: "server.signalProcess",
@@ -328,12 +327,6 @@ export const WsServerGetProcessResourceHistoryRpc = Rpc.make(
},
);
export const WsServerGetResourceTelemetryRpc = Rpc.make(WS_METHODS.serverGetResourceTelemetry, {
payload: Schema.Struct({}),
success: ResourceTelemetrySnapshot,
error: EnvironmentAuthorizationError,
});
export const WsServerGetResourceTelemetryHistoryRpc = Rpc.make(
WS_METHODS.serverGetResourceTelemetryHistory,
{
@@ -760,7 +753,6 @@ export const WsRpcGroup = RpcGroup.make(
WsServerGetTraceDiagnosticsRpc,
WsServerGetProcessDiagnosticsRpc,
WsServerGetProcessResourceHistoryRpc,
WsServerGetResourceTelemetryRpc,
WsServerGetResourceTelemetryHistoryRpc,
WsServerRetryResourceTelemetryRpc,
WsServerSignalProcessRpc,