A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
improvement: update WebSocket URL generation for agents to work on remote deployments (#8065)
Myles Scolnick8d1c36db0f00
diff --git a/frontend/src/components/chat/acp/__tests__/state.test.ts b/frontend/src/components/chat/acp/__tests__/state.test.tsindex b7d0d4b73c..948c103f36 100644--- a/frontend/src/components/chat/acp/__tests__/state.test.ts+++ b/frontend/src/components/chat/acp/__tests__/state.test.ts@@ -9,6 +9,7 @@ import {type ExternalAgentId,getAgentConnectionCommand,getAgentDisplayName,+ getAgentWebSocketUrl,getSessionsByAgent,removeSession,type TabId,@@ -697,4 +698,72 @@ describe("state utility functions", () => {`);});});++ describe("getAgentWebSocketUrl", () => {+ const originalLocation = window.location;++ afterEach(() => {+ // Restore original window.location+ Object.defineProperty(window, "location", {+ value: originalLocation,+ writable: true,+ });+ });++ it("should return ws:// URL with localhost for http protocol", () => {+ Object.defineProperty(window, "location", {+ value: {+ hostname: "localhost",+ protocol: "http:",+ },+ writable: true,+ });++ expect(getAgentWebSocketUrl("claude")).toMatchInlineSnapshot(+ `"ws://localhost:3017/message"`,+ );+ });++ it("should return wss:// URL for https protocol", () => {+ Object.defineProperty(window, "location", {+ value: {+ hostname: "example.com",+ protocol: "https:",+ },+ writable: true,+ });++ expect(getAgentWebSocketUrl("claude")).toMatchInlineSnapshot(+ `"wss://example.com:3017/message"`,+ );+ });++ it("should work with IP addresses", () => {+ Object.defineProperty(window, "location", {+ value: {+ hostname: "192.168.1.100",+ protocol: "http:",+ },+ writable: true,+ });++ expect(getAgentWebSocketUrl("claude")).toMatchInlineSnapshot(+ `"ws://192.168.1.100:3017/message"`,+ );+ });++ it("should work with remote hostnames", () => {+ Object.defineProperty(window, "location", {+ value: {+ hostname: "marimo.example.com",+ protocol: "https:",+ },+ writable: true,+ });++ expect(getAgentWebSocketUrl("gemini")).toMatchInlineSnapshot(+ `"wss://marimo.example.com:3019/message"`,+ );+ });+ });});diff --git a/frontend/src/components/chat/acp/state.ts b/frontend/src/components/chat/acp/state.tsindex 7d0b337cbd..6afe86ff52 100644--- a/frontend/src/components/chat/acp/state.ts+++ b/frontend/src/components/chat/acp/state.ts@@ -233,13 +233,17 @@ export function getAgentDisplayName(agentId: ExternalAgentId): string {}export function getAgentWebSocketUrl(agentId: ExternalAgentId): string {- return AGENT_CONFIG[agentId].webSocketUrl;+ const port = AGENT_CONFIG[agentId].port;+ // Use the current page's hostname so the agent is reachable when+ // marimo is accessed remotely (e.g. via direct IP or reverse proxy).+ const hostname = window.location.hostname;+ const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";+ return `${protocol}//${hostname}:${port}/message` as const;}interface AgentConfig {port: number;command: string;- webSocketUrl: string;sessionSupport: SessionSupportType;}@@ -247,25 +251,21 @@ const AGENT_CONFIG: Record<ExternalAgentId, AgentConfig> = {claude: {port: 3017,command: "npx @zed-industries/claude-code-acp",- webSocketUrl: "ws://localhost:3017/message",sessionSupport: "single",},gemini: {port: 3019,command: "npx @google/gemini-cli --experimental-acp",- webSocketUrl: "ws://localhost:3019/message",sessionSupport: "single",},codex: {port: 3021,command: "npx @zed-industries/codex-acp",- webSocketUrl: "ws://localhost:3021/message",sessionSupport: "single",},opencode: {port: 3023,command: "npx opencode-ai acp",- webSocketUrl: "ws://localhost:3023/message",sessionSupport: "single",},};