summaryrefslogtreecommitdiff
path: root/packages/core/src/background/backgroundManager.ts
diff options
context:
space:
mode:
authorTommaso Sciortino <[email protected]>2025-07-18 15:38:04 -0700
committerGitHub <[email protected]>2025-07-18 22:38:04 +0000
commit003609239fe81c8a2920ed0c63b7f5142bb4f7e5 (patch)
tree9dcce05e79a6f1bbe58d8074232212e2495130c5 /packages/core/src/background/backgroundManager.ts
parent04bbc60b97809b4200c5dd09ba849e4d097d1d1f (diff)
Add /background commands (when background agent is configured) (#4407)
Co-authored-by: Bryan Morgan <[email protected]>
Diffstat (limited to 'packages/core/src/background/backgroundManager.ts')
-rw-r--r--packages/core/src/background/backgroundManager.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/packages/core/src/background/backgroundManager.ts b/packages/core/src/background/backgroundManager.ts
new file mode 100644
index 00000000..a3ec526c
--- /dev/null
+++ b/packages/core/src/background/backgroundManager.ts
@@ -0,0 +1,40 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { MCPServerConfig } from '../config/config.js';
+import { BackgroundAgent, loadBackgroundAgent } from './backgroundAgent.js';
+
+export async function loadBackgroundAgentManager(
+ backgroundAgentConfigs: Record<string, MCPServerConfig> | undefined,
+ debugMode: boolean,
+): Promise<BackgroundAgentManager> {
+ const agents = await Promise.all(
+ Object.entries(backgroundAgentConfigs ?? {}).map(([name, config]) =>
+ loadBackgroundAgent(name, config, debugMode).catch((error) => {
+ console.error(`Error loading background agent '${name}': ${error}`);
+ return null;
+ }),
+ ),
+ ).then((agents) => agents.filter((agent) => agent !== null));
+ return new BackgroundAgentManager(agents);
+}
+
+export class BackgroundAgentManager {
+ // The active agent. May be empty if none are confgured.
+ activeAgent?: BackgroundAgent;
+
+ constructor(readonly backgroundAgents: BackgroundAgent[]) {
+ if (backgroundAgents.length !== 0) {
+ this.activeAgent = backgroundAgents[0];
+ }
+ }
+
+ setActiveAgentByName(name: string) {
+ this.activeAgent = this.backgroundAgents.find(
+ (agent) => agent.serverName === name,
+ );
+ }
+}