Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix(switchdash): name the owning server in the cannot-import notice (CHOO-2044)
Louis Amaudruzb419ecc08a30
diff --git a/dash/apps/switchdash-desktop/src/main/core/agents/onboard-location-agents.test.ts b/dash/apps/switchdash-desktop/src/main/core/agents/onboard-location-agents.test.tsindex 3dbdfb46a..beb91571f 100644--- a/dash/apps/switchdash-desktop/src/main/core/agents/onboard-location-agents.test.ts+++ b/dash/apps/switchdash-desktop/src/main/core/agents/onboard-location-agents.test.ts@@ -75,6 +75,11 @@ vi.mock('@main/core/switch-servers/servers-store', () => ({name: 'Server B',apiUrl: 'https://b.example.com',})),+ findServerByEndpoint: vi.fn(async (endpoint: string) =>+ endpoint === 'https://a.example.com'+ ? { id: 'srv-a', name: 'Server A', apiUrl: 'https://a.example.com' }+ : null+ ),}));vi.mock('./createAgent', () => ({ createAgent: h.createAgent }));vi.mock('./register-agent-identity', () => ({ registerAgentIdentity: h.registerAgentIdentity }));@@ -134,7 +139,7 @@ describe('onboardLocationAgents identity resolution', () => {expect(h.createAgent).not.toHaveBeenCalled();});- it('names the other server so the refusal can be acted on', async () => {+ it('names the owning server, not its URL, when switchdash has it registered', async () => {h.state.definitions = [definition('test-1', true)];h.state.local = [{ name: 'test-1', switchAgentId: 'sw-on-a', apiEndpoint: 'https://a.example.com' },@@ -146,8 +151,24 @@ describe('onboardLocationAgents identity resolution', () => {if (result.success) return;expect(result.error).toMatchObject({ type: 'error' });const message = 'message' in result.error ? result.error.message : '';- expect(message).toContain('https://a.example.com');+ expect(message).toContain('Server A');expect(message).toContain('Server B');+ expect(message).not.toContain('https://a.example.com');+ });++ it('says "another Switch server" rather than a URL for a server it does not know', async () => {+ h.state.definitions = [definition('test-1', true)];+ h.state.local = [+ { name: 'test-1', switchAgentId: 'sw-elsewhere', apiEndpoint: 'https://unknown.example.com' },+ ];++ const result = await onboard(['test-1']);++ expect(result.success).toBe(false);+ if (result.success) return;+ const message = 'message' in result.error ? result.error.message : '';+ expect(message).toContain('another Switch server');+ expect(message).not.toContain('https://unknown.example.com');});it('imports an identity the target server does have', async () => {diff --git a/dash/apps/switchdash-desktop/src/main/core/agents/onboard-location-agents.ts b/dash/apps/switchdash-desktop/src/main/core/agents/onboard-location-agents.tsindex 266c8fdf1..b6a2801d6 100644--- a/dash/apps/switchdash-desktop/src/main/core/agents/onboard-location-agents.ts+++ b/dash/apps/switchdash-desktop/src/main/core/agents/onboard-location-agents.ts@@ -7,7 +7,7 @@ import { checkIsValidDirectory } from '@main/core/locations/path-utils';import { ensureLocation } from '@main/core/locations/store';import { getPlugin } from '@main/core/providers/plugin-registry';import { agentExistsOnServer, GatewayError } from '@main/core/switch-servers/gateway-client';-import { getServer } from '@main/core/switch-servers/servers-store';+import { findServerByEndpoint, getServer } from '@main/core/switch-servers/servers-store';import { log } from '@main/lib/logger';import type { Agent } from '@shared/core/agents/agents';import type { OnboardAgentError } from '@shared/core/agents/onboarding';@@ -111,11 +111,12 @@ async function resolveIdentity(}throw cause;}+ const owner = await findServerByEndpoint(creds.apiEndpoint);return {ok: false,error: {type: 'error',- message: `"${name}" is already registered with another Switch server (${creds.apiEndpoint}) and cannot be imported into ${ctx.server.name}. Onboard it from that server, or create a new agent here under a different name.`,+ message: `"${name}" is already registered with ${owner ? owner.name : 'another Switch server'} and cannot be imported into ${ctx.server.name}. Onboard it from that server, or create a new agent here under a different name.`,},};}diff --git a/dash/apps/switchdash-desktop/src/main/core/switch-servers/servers-store.ts b/dash/apps/switchdash-desktop/src/main/core/switch-servers/servers-store.tsindex 20d4140dc..20023ce7b 100644--- a/dash/apps/switchdash-desktop/src/main/core/switch-servers/servers-store.ts+++ b/dash/apps/switchdash-desktop/src/main/core/switch-servers/servers-store.ts@@ -3,12 +3,13 @@ import { and, desc, eq, isNull, ne, or, sql } from 'drizzle-orm';import { encryptedAppSecretsStore } from '@main/core/secrets/encrypted-app-secrets-store';import { db } from '@main/db/client';import { agents, kv, type SwitchServerRow, switchServers } from '@main/db/schema';-import type {- AddServerParams,- ManagedServerRef,- RenameServerParams,- SwitchServer,- UpdateServerParams,+import {+ urlOrigin,+ type AddServerParams,+ type ManagedServerRef,+ type RenameServerParams,+ type SwitchServer,+ type UpdateServerParams,} from '@shared/core/switch-servers/switch-servers';const ACTIVE_SERVER_KV_KEY = 'activeSwitchServerId';@@ -43,20 +44,6 @@ function normaliseUrl(url: string): string {return url.trim().replace(/\/+$/, '');}-/**- * Origin (protocol + host + port, lowercased) of a URL, or null if unparseable.- * Agents are matched to servers by origin rather than full URL: an agent's- * `SWITCH_API_ENDPOINT` and a server's API URL share a host but may differ in- * path, so comparing origins is the robust match.- */-export function urlOrigin(url: string): string | null {- try {- return new URL(url.trim()).origin.toLowerCase();- } catch {- return null;- }-}-/*** Find the registered server an agent endpoint belongs to, by matching the* endpoint's origin against each server's API (agent bridge) URL — the endpointdiff --git a/dash/apps/switchdash-desktop/src/renderer/features/locations/components/add-agent-modal/add-agent-modal.tsx b/dash/apps/switchdash-desktop/src/renderer/features/locations/components/add-agent-modal/add-agent-modal.tsxindex 6d54dd5ff..709cd1924 100644--- a/dash/apps/switchdash-desktop/src/renderer/features/locations/components/add-agent-modal/add-agent-modal.tsx+++ b/dash/apps/switchdash-desktop/src/renderer/features/locations/components/add-agent-modal/add-agent-modal.tsx@@ -278,7 +278,11 @@ export const AddAgentModal = observer(function AddAgentModal({ onClose }: AddLocconst foreignCredentialReason = (endpoint: string | null): string | null => {if (endpoint === null || !targetServer) return null;if (sameApiEndpoint(endpoint, targetServer.apiUrl)) return null;- return `Already registered with another Switch server (${endpoint}), so it cannot be imported into ${targetServer.name}. Create a new agent instead.`;+ // Name the server when this switchdash has it registered. The raw endpoint is+ // an implementation detail to the person reading the row, and for a server+ // they have registered it is one they already know by name.+ const owner = switchServersStore.servers.find((s) => sameApiEndpoint(s.apiUrl, endpoint));+ return `Already registered with ${owner ? owner.name : 'another Switch server'}, so it cannot be imported into ${targetServer.name}. Create a new agent instead.`;};const onboardableAgents: OnboardableAgent[] = [diff --git a/dash/apps/switchdash-desktop/src/shared/core/switch-servers/switch-servers.ts b/dash/apps/switchdash-desktop/src/shared/core/switch-servers/switch-servers.tsindex 6f2399b35..71c83fde5 100644--- a/dash/apps/switchdash-desktop/src/shared/core/switch-servers/switch-servers.ts+++ b/dash/apps/switchdash-desktop/src/shared/core/switch-servers/switch-servers.ts@@ -10,14 +10,34 @@*//**- * Whether two Switch API endpoints name the same server, ignoring a trailing- * slash — which is not a difference. This is how an agent's on-disk- * `SWITCH_API_ENDPOINT` is matched to a registered server, so the main process and- * the renderer must agree on it: the renderer decides which discovered agents are- * importable, and the main process enforces it.+ * Origin (protocol + host + port, lowercased) of a URL, or null if unparseable.+ * Agents are matched to servers by origin rather than full URL: an agent's+ * `SWITCH_API_ENDPOINT` and a server's API URL share a host but may differ in+ * path, so comparing origins is the robust match.+ */+export function urlOrigin(url: string): string | null {+ try {+ return new URL(url.trim()).origin.toLowerCase();+ } catch {+ return null;+ }+}++/**+ * Whether two Switch API endpoints name the same server. This is how an agent's+ * on-disk `SWITCH_API_ENDPOINT` is matched to a registered server, so the main+ * process and the renderer must agree on it: the renderer decides which discovered+ * agents are offered as importable, and the main process enforces it.+ *+ * Origins are compared when both parse — path and trailing slash are not+ * differences. Unparseable input falls back to a trimmed string comparison rather+ * than reporting a match it cannot vouch for.*/export function sameApiEndpoint(a: string, b: string): boolean {- return a.replace(/\/+$/, '') === b.replace(/\/+$/, '');+ const originA = urlOrigin(a);+ const originB = urlOrigin(b);+ if (originA && originB) return originA === originB;+ return a.trim().replace(/\/+$/, '') === b.trim().replace(/\/+$/, '');}/** A registered Switch server. Non-secret connection metadata only. */