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
Delete locations no agent uses at startup
raullopez-sandboxb008e3d1b7c0
diff --git a/console/apps/switch-console-desktop/src/main/core/locations/store.db.test.ts b/console/apps/switch-console-desktop/src/main/core/locations/store.db.test.tsindex 9f53061cf..b51598c41 100644--- a/console/apps/switch-console-desktop/src/main/core/locations/store.db.test.ts+++ b/console/apps/switch-console-desktop/src/main/core/locations/store.db.test.ts@@ -2,7 +2,7 @@ import { openFixture } from '@tooling/utils/db';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import type { AppDb } from '@main/db/client';import { agents, locations } from '@main/db/schema';-import { deleteLocationIfUnused, getLocationById } from './store';+import { deleteLocationIfUnused, deleteUnusedLocations, getLocationById } from './store';const mocks = vi.hoisted(() => ({ db: undefined as AppDb | undefined }));@@ -42,4 +42,10 @@ describe('deleteLocationIfUnused', () => {await deleteLocationIfUnused('shared');expect(await getLocationById('shared')).toBeDefined();});++ it('deletes every agentless location at once and keeps the ones in use', async () => {+ await deleteUnusedLocations();+ expect(await getLocationById('empty')).toBeUndefined();+ expect(await getLocationById('shared')).toBeDefined();+ });});diff --git a/console/apps/switch-console-desktop/src/main/core/locations/store.ts b/console/apps/switch-console-desktop/src/main/core/locations/store.tsindex 02a79e87f..f47667b35 100644--- a/console/apps/switch-console-desktop/src/main/core/locations/store.ts+++ b/console/apps/switch-console-desktop/src/main/core/locations/store.ts@@ -75,3 +75,14 @@ export async function deleteLocationIfUnused(locationId: string): Promise<void>));}++/** Delete every location row no agent uses. Never touches the directories themselves. */+export async function deleteUnusedLocations(): Promise<void> {+ await db+ .delete(locations)+ .where(+ notExists(+ db.select({ id: agents.id }).from(agents).where(eq(agents.locationId, locations.id))+ )+ );+}diff --git a/console/apps/switch-console-desktop/src/main/index.ts b/console/apps/switch-console-desktop/src/main/index.tsindex 1e74f30e6..59cc32e8d 100644--- a/console/apps/switch-console-desktop/src/main/index.ts+++ b/console/apps/switch-console-desktop/src/main/index.ts@@ -25,6 +25,7 @@ import { embeddedControllerService } from './core/embedded-controller/embedded-cimport { featureFlagsService } from './core/feature-flags/feature-flags';import { locationManager } from './core/locations/location-manager';import { locationSettingsService } from './core/locations/settings/location-settings-service';+import { deleteUnusedLocations } from './core/locations/store';import { localServerService } from './core/managed-switch-server/local-server-service';import { remoteServerService } from './core/managed-switch-server/remote-server-service';import { serverVersionChoice } from './core/managed-switch-server/server-version';@@ -133,6 +134,11 @@ void app.whenReady().then(async () => {try {await initializeDatabase();searchService.initialize();+ try {+ await deleteUnusedLocations();+ } catch (e: unknown) {+ log.warn('locations: failed to delete locations no agent uses', { error: e });+ }try {viewStateService.pruneOrphans();} catch (e: unknown) {