mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): support SSH remote windows with per-endpoint isolation and context window overrides
- Add per-endpoint registry and isolated caches (endpoint-registry.mjs, multi-path trajectory-cache-file.mjs) so local and SSH remote windows maintain independent conversations, telemetry, quotas, and consumption analytics (Antigravity SSH) without remote plugin installation - Classify local vs. SSH Desktop targets via two-pass hub port and metadata probing in window-bridge.mjs and ls-discovery.mjs, routing HTTP/CDP requests with authoritative X-Usage-Monitor-Endpoint headers and preventing local data leaks or 503-triggered CDP downgrades - Implement two-tier read-only remote LS RPC transport in ls-rpc.mjs (loopback HTTP/HTTPS with size/wall-clock limits and 60s circuit breaker falling back to stateless same-origin window.fetch / connect-websocket via CDP) - Enable per-endpoint verified context window overrides in SSH Desktop windows (context-windows.mjs, window-bridge.mjs, api-actions.mjs) without double-wrapping window.fetch - Surface an SSH badge in TopSessionHeader, cleanly flush stale requests/queues on endpoint rebind, rebuild app.js/styles.css, and add 13 unit/E2E tests in test/ssh-remote-endpoints.test.mjs (157/157 passing)
This commit is contained in:
@@ -76,6 +76,12 @@ export const TopSessionHeader = defineComponent({
|
||||
[updateBtnIcon, updateBtnText]
|
||||
);
|
||||
|
||||
const sshBadge = h('span', {
|
||||
className: 'endpoint-ssh-badge',
|
||||
hidden: true,
|
||||
text: 'SSH',
|
||||
});
|
||||
|
||||
const statusIcon = createSvgIcon('pulse', { size: 12 });
|
||||
const statusText = h('span', { text: t('header.statusLive') });
|
||||
const statusTag = h('span', { className: 'status-tag' }, [statusIcon, statusText]);
|
||||
@@ -93,7 +99,7 @@ export const TopSessionHeader = defineComponent({
|
||||
|
||||
const headerRowEl = h('div', { className: 'session-header' }, [
|
||||
h('div', { className: 'session-left' }, [convSelect.el]),
|
||||
h('div', { className: 'session-right' }, [updateBtn, statusTag, refreshBtn]),
|
||||
h('div', { className: 'session-right' }, [sshBadge, updateBtn, statusTag, refreshBtn]),
|
||||
]);
|
||||
|
||||
const headerEl = h('header', { className: 'top-session-stack' }, [headerRowEl]);
|
||||
@@ -162,6 +168,14 @@ export const TopSessionHeader = defineComponent({
|
||||
patchAttr(updateBtn, 'aria-label', t('header.ariaUpdate'));
|
||||
patchAttr(refreshBtn, 'aria-label', t('header.ariaRefresh'));
|
||||
|
||||
const ep = telemetry?.endpoint;
|
||||
const isRemoteEndpoint = Boolean(ep?.isRemote);
|
||||
patchAttr(sshBadge, 'hidden', !isRemoteEndpoint);
|
||||
if (isRemoteEndpoint) {
|
||||
const epLabel = String(ep?.label || 'SSH').trim();
|
||||
patchAttr(sshBadge, 'title', epLabel && epLabel !== 'SSH' ? `SSH · ${epLabel}` : 'SSH');
|
||||
}
|
||||
|
||||
const actConv = telemetry?.activeConversation;
|
||||
const convs = telemetry?.conversations || [];
|
||||
const hostRouteId = telSt.hostRouteConversationId || '';
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
LOCAL_ENDPOINT_ID,
|
||||
WINDOW_BRIDGE_ENDPOINT_KEY,
|
||||
WINDOW_BRIDGE_KEY,
|
||||
WINDOW_OVERLAY_KEY,
|
||||
WINDOW_OVERLAY_METHODS,
|
||||
@@ -51,6 +53,7 @@ import {
|
||||
normalizeClientTopbarSlots,
|
||||
normalizeClientUpdateMode,
|
||||
normalizeClientWindowMountMode,
|
||||
resetTelemetryForEndpointSwitch,
|
||||
resolveScopedConversation,
|
||||
selectConversation,
|
||||
startAsyncTelemetryLoop,
|
||||
@@ -958,10 +961,18 @@ export function mountWindowOverlay() {
|
||||
const bridgeConfig = getWindowBridgeConfig();
|
||||
const bundleVersion = String(bridgeConfig?.bundleVersion || '');
|
||||
const stylesCss = String(bridgeConfig?.stylesCss || '');
|
||||
const activeBridgeEndpointId = String(
|
||||
bridgeConfig?.[WINDOW_BRIDGE_ENDPOINT_KEY] || LOCAL_ENDPOINT_ID
|
||||
);
|
||||
const reusableCarryOver =
|
||||
carryOverTelemetry &&
|
||||
String(carryOverTelemetry?.endpoint?.id || LOCAL_ENDPOINT_ID) === activeBridgeEndpointId
|
||||
? carryOverTelemetry
|
||||
: null;
|
||||
const seedTelemetry =
|
||||
(bridgeConfig?.initialTelemetry && typeof bridgeConfig.initialTelemetry === 'object'
|
||||
? bridgeConfig.initialTelemetry
|
||||
: null) || carryOverTelemetry;
|
||||
: null) || reusableCarryOver;
|
||||
if (bridgeConfig?.initialTelemetry) {
|
||||
delete bridgeConfig.initialTelemetry;
|
||||
}
|
||||
@@ -2741,14 +2752,49 @@ export function mountWindowOverlay() {
|
||||
const token = String(nextBridge.token || '');
|
||||
if (!Number.isInteger(port) || port <= 0 || !token) return false;
|
||||
const cur = readInjectedWindowBridge() || {};
|
||||
const prevEndpointId = String(cur[WINDOW_BRIDGE_ENDPOINT_KEY] || LOCAL_ENDPOINT_ID);
|
||||
const nextEndpointId =
|
||||
nextBridge[WINDOW_BRIDGE_ENDPOINT_KEY] !== undefined
|
||||
? String(nextBridge[WINDOW_BRIDGE_ENDPOINT_KEY] || LOCAL_ENDPOINT_ID)
|
||||
: prevEndpointId;
|
||||
const portChanged = Number(cur.port || 0) !== port || String(cur.token || '') !== token;
|
||||
const endpointChanged = prevEndpointId !== nextEndpointId;
|
||||
cur.port = port;
|
||||
cur.token = token;
|
||||
if (portChanged) {
|
||||
cur[WINDOW_BRIDGE_ENDPOINT_KEY] = nextEndpointId;
|
||||
if (nextBridge.isRemoteEndpoint !== undefined) {
|
||||
cur.isRemoteEndpoint = Boolean(nextBridge.isRemoteEndpoint);
|
||||
}
|
||||
if (nextBridge.endpointLabel !== undefined) {
|
||||
cur.endpointLabel = String(nextBridge.endpointLabel || '');
|
||||
}
|
||||
if (portChanged || endpointChanged) {
|
||||
cur.transportMode = 'http';
|
||||
}
|
||||
if (endpointChanged) {
|
||||
if (Array.isArray(cur.rpcQueue)) {
|
||||
cur.rpcQueue.length = 0;
|
||||
}
|
||||
if (cur.rpcPending instanceof Map) {
|
||||
for (const pending of cur.rpcPending.values()) {
|
||||
try {
|
||||
const switchErr = new Error('Bridge endpoint switched');
|
||||
switchErr.name = 'AbortError';
|
||||
pending?.reject?.(switchErr);
|
||||
} catch {
|
||||
// 忽略旧端点回调异常
|
||||
}
|
||||
}
|
||||
cur.rpcPending.clear();
|
||||
}
|
||||
}
|
||||
window[WINDOW_BRIDGE_KEY] = cur;
|
||||
void fetchTelemetry({ force: false });
|
||||
if (endpointChanged) {
|
||||
resetTelemetryForEndpointSwitch();
|
||||
void fetchTelemetry({ force: true });
|
||||
} else {
|
||||
void fetchTelemetry({ force: false });
|
||||
}
|
||||
return true;
|
||||
},
|
||||
getTelemetrySnapshot() {
|
||||
|
||||
Reference in New Issue
Block a user