Skip to content

Personal AI, On Personal Devices

Python

fix(desktop): complete remote server support

Elliot Slusky4b7bb936ff35
diff --git a/frontend/src-tauri/Info.plist b/frontend/src-tauri/Info.plist
new file mode 100644
index 00000000..794e7a46
--- /dev/null
+++ b/frontend/src-tauri/Info.plist
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>NSAppTransportSecurity</key>
+ <dict>
+ <!-- The desktop API URL is user-configurable, so it cannot be represented
+ by Tauri's single, build-time exceptionDomain setting. Keep this
+ exception scoped to WKWebView; native URLSession traffic retains ATS. -->
+ <key>NSAllowsArbitraryLoadsInWebContent</key>
+ <true/>
+ </dict>
+</dict>
+</plist>
diff --git a/frontend/src-tauri/tauri.conf.json b/frontend/src-tauri/tauri.conf.json
index 3cf35457..824204b5 100644
--- a/frontend/src-tauri/tauri.conf.json
+++ b/frontend/src-tauri/tauri.conf.json
@@ -45,7 +45,6 @@
"macOS": {
"entitlements": "Entitlements.plist",
"minimumSystemVersion": "10.15",
- "exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": "-"
diff --git a/frontend/src/lib/useAgentEvents.test.ts b/frontend/src/lib/useAgentEvents.test.ts
new file mode 100644
index 00000000..a9761d29
--- /dev/null
+++ b/frontend/src/lib/useAgentEvents.test.ts
@@ -0,0 +1,66 @@
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import { buildWsUrl } from './useAgentEvents';
+
+const SETTINGS_KEY = 'openjarvis-settings';
+
+class MemoryStorage {
+ private store = new Map<string, string>();
+
+ getItem(key: string): string | null {
+ return this.store.get(key) ?? null;
+ }
+
+ setItem(key: string, value: string): void {
+ this.store.set(key, String(value));
+ }
+}
+
+beforeEach(() => {
+ (globalThis as unknown as { localStorage: MemoryStorage }).localStorage =
+ new MemoryStorage();
+});
+
+afterEach(() => {
+ (globalThis as unknown as { localStorage?: MemoryStorage }).localStorage =
+ undefined;
+});
+
+describe('buildWsUrl', () => {
+ it('authenticates agent events with the configured API key', () => {
+ localStorage.setItem(
+ SETTINGS_KEY,
+ JSON.stringify({
+ apiUrl: 'https://jarvis.example.com:8443',
+ apiKey: 'secret+/=',
+ }),
+ );
+
+ const url = new URL(buildWsUrl('agent/one'));
+
+ expect(url.origin).toBe('wss://jarvis.example.com:8443');
+ expect(url.pathname).toBe('/v1/agents/events');
+ expect(url.searchParams.get('agent_id')).toBe('agent/one');
+ expect(url.searchParams.get('token')).toBe('secret+/=');
+ });
+
+ it('normalizes a versioned API base without duplicating /v1', () => {
+ localStorage.setItem(
+ SETTINGS_KEY,
+ JSON.stringify({ apiUrl: 'http://192.0.2.10:8000/v1/' }),
+ );
+
+ expect(buildWsUrl()).toBe('ws://192.0.2.10:8000/v1/agents/events');
+ });
+
+ it('omits the token for a keyless server', () => {
+ localStorage.setItem(
+ SETTINGS_KEY,
+ JSON.stringify({ apiUrl: 'http://localhost:8000' }),
+ );
+
+ const url = new URL(buildWsUrl('agent-one'));
+
+ expect(url.searchParams.has('token')).toBe(false);
+ });
+});
diff --git a/frontend/src/lib/useAgentEvents.ts b/frontend/src/lib/useAgentEvents.ts
index 5232239f..786f3b94 100644
--- a/frontend/src/lib/useAgentEvents.ts
+++ b/frontend/src/lib/useAgentEvents.ts
@@ -1,5 +1,5 @@
import { useEffect, useRef } from 'react';
-import { getBase } from './api';
+import { getApiKey, getBase } from './api';
export interface AgentEvent {
type: string;
@@ -7,19 +7,16 @@ export interface AgentEvent {
data: Record<string, unknown>;
}
-function buildWsUrl(agentId?: string): string {
+export function buildWsUrl(agentId?: string): string {
const base = getBase();
- let origin: string;
- if (base) {
- origin = base.replace(/^http/, 'ws');
- } else {
- const loc = window.location;
- origin = `${loc.protocol === 'https:' ? 'wss:' : 'ws:'}//${loc.host}`;
- }
- const path = '/v1/agents/events';
- return agentId
- ? `${origin}${path}?agent_id=${encodeURIComponent(agentId)}`
- : `${origin}${path}`;
+ const url = new URL('/v1/agents/events', base || window.location.origin);
+ url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
+
+ if (agentId) url.searchParams.set('agent_id', agentId);
+ const apiKey = getApiKey();
+ if (apiKey) url.searchParams.set('token', apiKey);
+
+ return url.toString();
}
/**
diff --git a/tests/deployment/test_desktop_network_policy.py b/tests/deployment/test_desktop_network_policy.py
index 4ded5e02..e68b1de3 100644
--- a/tests/deployment/test_desktop_network_policy.py
+++ b/tests/deployment/test_desktop_network_policy.py
@@ -3,10 +3,12 @@
from __future__ import annotations
import json
+import plistlib
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent.parent
TAURI_CONFIG = ROOT / "frontend" / "src-tauri" / "tauri.conf.json"
+MACOS_INFO_PLIST = ROOT / "frontend" / "src-tauri" / "Info.plist"
def _csp_sources(directive: str) -> set[str]:
@@ -23,3 +25,10 @@ def test_desktop_csp_allows_remote_api_servers() -> None:
connect_sources = _csp_sources("connect-src")
assert {"http:", "https:", "ws:", "wss:"} <= connect_sources
+
+
+def test_macos_webview_allows_user_configured_http_servers() -> None:
+ """CSP alone cannot override App Transport Security for public hosts."""
+ info = plistlib.loads(MACOS_INFO_PLIST.read_bytes())
+
+ assert info["NSAppTransportSecurity"]["NSAllowsArbitraryLoadsInWebContent"] is True