@dexto/agent-management 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/AgentFactory.cjs +153 -0
  2. package/dist/AgentFactory.d.ts +121 -0
  3. package/dist/AgentFactory.d.ts.map +1 -0
  4. package/dist/AgentFactory.js +133 -0
  5. package/dist/AgentManager.cjs +226 -0
  6. package/dist/AgentManager.d.ts +191 -0
  7. package/dist/AgentManager.d.ts.map +1 -0
  8. package/dist/AgentManager.js +192 -0
  9. package/dist/config/config-enrichment.cjs +22 -2
  10. package/dist/config/config-enrichment.d.ts +19 -4
  11. package/dist/config/config-enrichment.d.ts.map +1 -1
  12. package/dist/config/config-enrichment.js +21 -2
  13. package/dist/config/config-manager.cjs +340 -3
  14. package/dist/config/config-manager.d.ts +158 -7
  15. package/dist/config/config-manager.d.ts.map +1 -1
  16. package/dist/config/config-manager.js +325 -3
  17. package/dist/config/discover-prompts.cjs +103 -0
  18. package/dist/config/discover-prompts.d.ts +28 -0
  19. package/dist/config/discover-prompts.d.ts.map +1 -0
  20. package/dist/config/discover-prompts.js +73 -0
  21. package/dist/config/index.cjs +14 -2
  22. package/dist/config/index.d.ts +2 -2
  23. package/dist/config/index.d.ts.map +1 -1
  24. package/dist/config/index.js +21 -3
  25. package/dist/index.cjs +40 -6
  26. package/dist/index.d.ts +6 -4
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +40 -5
  29. package/dist/installation.cjs +252 -0
  30. package/dist/installation.d.ts +74 -0
  31. package/dist/installation.d.ts.map +1 -0
  32. package/dist/installation.js +215 -0
  33. package/dist/models/custom-models.cjs +116 -0
  34. package/dist/models/custom-models.d.ts +51 -0
  35. package/dist/models/custom-models.d.ts.map +1 -0
  36. package/dist/models/custom-models.js +77 -0
  37. package/dist/registry/registry.cjs +21 -2
  38. package/dist/registry/registry.d.ts +5 -0
  39. package/dist/registry/registry.d.ts.map +1 -1
  40. package/dist/registry/registry.js +19 -1
  41. package/dist/registry/types.d.ts +9 -9
  42. package/dist/resolver.cjs +68 -29
  43. package/dist/resolver.d.ts +6 -3
  44. package/dist/resolver.d.ts.map +1 -1
  45. package/dist/resolver.js +69 -30
  46. package/package.json +2 -2
  47. package/dist/AgentOrchestrator.cjs +0 -263
  48. package/dist/AgentOrchestrator.d.ts +0 -191
  49. package/dist/AgentOrchestrator.d.ts.map +0 -1
  50. package/dist/AgentOrchestrator.js +0 -239
package/dist/resolver.cjs CHANGED
@@ -39,6 +39,9 @@ var import_execution_context = require("./utils/execution-context.js");
39
39
  var import_core = require("@dexto/core");
40
40
  var import_loader = require("./preferences/loader.js");
41
41
  var import_config = require("./config/index.js");
42
+ var import_errors = require("./registry/errors.js");
43
+ var import_AgentManager = require("./AgentManager.js");
44
+ var import_installation = require("./installation.js");
42
45
  async function resolveAgentPath(nameOrPath, autoInstall = true, injectPreferences = true) {
43
46
  if (nameOrPath && (0, import_path2.isPath)(nameOrPath)) {
44
47
  const resolved = import_path.default.resolve(nameOrPath);
@@ -53,12 +56,47 @@ async function resolveAgentPath(nameOrPath, autoInstall = true, injectPreference
53
56
  }
54
57
  }
55
58
  if (nameOrPath) {
56
- const { getAgentRegistry } = await import("./registry/registry.js");
57
- const registry = getAgentRegistry();
58
- return await registry.resolveAgent(nameOrPath, autoInstall, injectPreferences);
59
+ return await resolveAgentByName(nameOrPath, autoInstall, injectPreferences);
59
60
  }
60
61
  return await resolveDefaultAgentByContext(autoInstall, injectPreferences);
61
62
  }
63
+ async function resolveAgentByName(agentId, autoInstall, injectPreferences) {
64
+ const agentsDir = (0, import_path2.getDextoGlobalPath)("agents");
65
+ const installedRegistryPath = import_path.default.join(agentsDir, "registry.json");
66
+ try {
67
+ const manager = new import_AgentManager.AgentManager(installedRegistryPath);
68
+ await manager.loadRegistry();
69
+ if (manager.hasAgent(agentId)) {
70
+ const agentPath = await getAgentConfigPath(agentId);
71
+ return agentPath;
72
+ }
73
+ } catch (error) {
74
+ import_core.logger.debug(`Agent '${agentId}' not found in installed registry: ${error}`);
75
+ }
76
+ if (autoInstall) {
77
+ try {
78
+ import_core.logger.info(`Auto-installing agent '${agentId}' from bundled registry`);
79
+ const configPath = await (0, import_installation.installBundledAgent)(agentId, { injectPreferences });
80
+ return configPath;
81
+ } catch (error) {
82
+ import_core.logger.debug(`Failed to auto-install agent '${agentId}': ${error}`);
83
+ throw import_errors.RegistryError.agentNotFound(agentId, []);
84
+ }
85
+ }
86
+ throw import_errors.RegistryError.agentNotInstalledAutoInstallDisabled(agentId, []);
87
+ }
88
+ async function getAgentConfigPath(agentId) {
89
+ const agentsDir = (0, import_path2.getDextoGlobalPath)("agents");
90
+ const installedRegistryPath = import_path.default.join(agentsDir, "registry.json");
91
+ const registryContent = await import_fs.promises.readFile(installedRegistryPath, "utf-8");
92
+ const registry = JSON.parse(registryContent);
93
+ const agentEntry = registry.agents.find((a) => a.id === agentId);
94
+ if (!agentEntry) {
95
+ const available = registry.agents.map((a) => a.id);
96
+ throw import_errors.RegistryError.agentNotFound(agentId, available);
97
+ }
98
+ return import_path.default.resolve(import_path.default.dirname(installedRegistryPath), agentEntry.configPath);
99
+ }
62
100
  async function resolveDefaultAgentByContext(autoInstall = true, injectPreferences = true) {
63
101
  const executionContext = (0, import_execution_context.getExecutionContext)();
64
102
  switch (executionContext) {
@@ -95,13 +133,7 @@ async function resolveDefaultAgentForDextoSource(autoInstall = true, injectPrefe
95
133
  if (preferences.setup.completed) {
96
134
  import_core.logger.debug("Using user preferences in dexto-source context");
97
135
  const preferredAgentName = preferences.defaults.defaultAgent;
98
- const { getAgentRegistry } = await import("./registry/registry.js");
99
- const registry = getAgentRegistry();
100
- return await registry.resolveAgent(
101
- preferredAgentName,
102
- autoInstall,
103
- injectPreferences
104
- );
136
+ return await resolveAgentByName(preferredAgentName, autoInstall, injectPreferences);
105
137
  }
106
138
  } catch (error) {
107
139
  import_core.logger.warn(`Failed to load preferences, falling back to repo config: ${error}`);
@@ -142,9 +174,7 @@ async function resolveDefaultAgentForDextoProject(autoInstall = true, injectPref
142
174
  throw import_config.ConfigError.setupIncomplete();
143
175
  }
144
176
  const preferredAgentName = preferences.defaults.defaultAgent;
145
- const { getAgentRegistry } = await import("./registry/registry.js");
146
- const registry = getAgentRegistry();
147
- return await registry.resolveAgent(preferredAgentName, autoInstall, injectPreferences);
177
+ return await resolveAgentByName(preferredAgentName, autoInstall, injectPreferences);
148
178
  }
149
179
  async function resolveDefaultAgentForGlobalCLI(autoInstall = true, injectPreferences = true) {
150
180
  import_core.logger.debug("Resolving default agent for global CLI context");
@@ -156,24 +186,33 @@ async function resolveDefaultAgentForGlobalCLI(autoInstall = true, injectPrefere
156
186
  throw import_config.ConfigError.setupIncomplete();
157
187
  }
158
188
  const preferredAgentName = preferences.defaults.defaultAgent;
159
- const { getAgentRegistry } = await import("./registry/registry.js");
160
- const registry = getAgentRegistry();
161
- return await registry.resolveAgent(preferredAgentName, autoInstall, injectPreferences);
189
+ return await resolveAgentByName(preferredAgentName, autoInstall, injectPreferences);
162
190
  }
163
191
  async function updateDefaultAgentPreference(agentName) {
164
- const { getAgentRegistry } = await import("./registry/registry.js");
165
- const { RegistryError } = await import("./registry/errors.js");
166
- const { isPath: isPath2 } = await import("@dexto/core");
167
- const registry = getAgentRegistry();
168
- if (isPath2(agentName) || !registry.hasAgent(agentName)) {
169
- const available = Object.keys(registry.getAvailableAgents());
170
- throw RegistryError.agentNotFound(agentName, available);
171
- }
172
- const { updateGlobalPreferences } = await import("./preferences/loader.js");
173
- await updateGlobalPreferences({
174
- defaults: { defaultAgent: agentName }
175
- });
176
- import_core.logger.info(`Updated default agent preference to: ${agentName}`);
192
+ const agentsDir = (0, import_path2.getDextoGlobalPath)("agents");
193
+ const installedRegistryPath = import_path.default.join(agentsDir, "registry.json");
194
+ const bundledRegistryPath = (0, import_path2.resolveBundledScript)("agents/agent-registry.json");
195
+ const registriesToCheck = [
196
+ { path: installedRegistryPath, name: "installed" },
197
+ { path: bundledRegistryPath, name: "bundled" }
198
+ ];
199
+ for (const registry of registriesToCheck) {
200
+ try {
201
+ const manager = new import_AgentManager.AgentManager(registry.path);
202
+ await manager.loadRegistry();
203
+ if (manager.hasAgent(agentName)) {
204
+ const { updateGlobalPreferences } = await import("./preferences/loader.js");
205
+ await updateGlobalPreferences({
206
+ defaults: { defaultAgent: agentName }
207
+ });
208
+ import_core.logger.info(`Updated default agent preference to: ${agentName}`);
209
+ return;
210
+ }
211
+ } catch (error) {
212
+ import_core.logger.debug(`Agent '${agentName}' not found in ${registry.name} registry: ${error}`);
213
+ }
214
+ }
215
+ throw import_errors.RegistryError.agentNotFound(agentName, []);
177
216
  }
178
217
  // Annotate the CommonJS export names for ESM import in node:
179
218
  0 && (module.exports = {
@@ -1,14 +1,17 @@
1
1
  /**
2
- * Resolve agent path with preference integration
2
+ * Resolve agent path with automatic installation if needed
3
3
  * @param nameOrPath Optional agent name or explicit path
4
- * @param autoInstall Whether to automatically install missing agents from registry (default: true)
4
+ * @param autoInstall Whether to automatically install missing agents from bundled registry (default: true)
5
5
  * @param injectPreferences Whether to inject preferences during auto-installation (default: true)
6
6
  * @returns Resolved absolute path to agent config
7
- * @throws DextoRuntimeError for any resolution failures
7
+ * @throws {ConfigError} For path/config issues (file not found, unknown context, setup incomplete)
8
+ * @throws {RegistryError} For agent lookup failures (agent not found, not installed)
8
9
  */
9
10
  export declare function resolveAgentPath(nameOrPath?: string, autoInstall?: boolean, injectPreferences?: boolean): Promise<string>;
10
11
  /**
11
12
  * Update default agent preference
13
+ * @param agentName The agent name to set as the new default
14
+ * @throws {RegistryError} If the agent is not found in installed or bundled registry
12
15
  */
13
16
  export declare function updateDefaultAgentPreference(agentName: string): Promise<void>;
14
17
  //# sourceMappingURL=resolver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AAcA;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAClC,UAAU,CAAC,EAAE,MAAM,EACnB,WAAW,GAAE,OAAc,EAC3B,iBAAiB,GAAE,OAAc,GAClC,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAoKD;;GAEG;AACH,wBAAsB,4BAA4B,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBnF"}
1
+ {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AAoCA;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAClC,UAAU,CAAC,EAAE,MAAM,EACnB,WAAW,GAAE,OAAc,EAC3B,iBAAiB,GAAE,OAAc,GAClC,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAiND;;;;GAIG;AACH,wBAAsB,4BAA4B,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BnF"}
package/dist/resolver.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { promises as fs } from "fs";
2
2
  import path from "path";
3
- import { isPath } from "./utils/path.js";
3
+ import { isPath, getDextoGlobalPath, resolveBundledScript } from "./utils/path.js";
4
4
  import {
5
5
  getExecutionContext,
6
6
  findDextoSourceRoot,
@@ -9,6 +9,9 @@ import {
9
9
  import { logger } from "@dexto/core";
10
10
  import { loadGlobalPreferences, globalPreferencesExist } from "./preferences/loader.js";
11
11
  import { ConfigError } from "./config/index.js";
12
+ import { RegistryError } from "./registry/errors.js";
13
+ import { AgentManager } from "./AgentManager.js";
14
+ import { installBundledAgent } from "./installation.js";
12
15
  async function resolveAgentPath(nameOrPath, autoInstall = true, injectPreferences = true) {
13
16
  if (nameOrPath && isPath(nameOrPath)) {
14
17
  const resolved = path.resolve(nameOrPath);
@@ -23,12 +26,47 @@ async function resolveAgentPath(nameOrPath, autoInstall = true, injectPreference
23
26
  }
24
27
  }
25
28
  if (nameOrPath) {
26
- const { getAgentRegistry } = await import("./registry/registry.js");
27
- const registry = getAgentRegistry();
28
- return await registry.resolveAgent(nameOrPath, autoInstall, injectPreferences);
29
+ return await resolveAgentByName(nameOrPath, autoInstall, injectPreferences);
29
30
  }
30
31
  return await resolveDefaultAgentByContext(autoInstall, injectPreferences);
31
32
  }
33
+ async function resolveAgentByName(agentId, autoInstall, injectPreferences) {
34
+ const agentsDir = getDextoGlobalPath("agents");
35
+ const installedRegistryPath = path.join(agentsDir, "registry.json");
36
+ try {
37
+ const manager = new AgentManager(installedRegistryPath);
38
+ await manager.loadRegistry();
39
+ if (manager.hasAgent(agentId)) {
40
+ const agentPath = await getAgentConfigPath(agentId);
41
+ return agentPath;
42
+ }
43
+ } catch (error) {
44
+ logger.debug(`Agent '${agentId}' not found in installed registry: ${error}`);
45
+ }
46
+ if (autoInstall) {
47
+ try {
48
+ logger.info(`Auto-installing agent '${agentId}' from bundled registry`);
49
+ const configPath = await installBundledAgent(agentId, { injectPreferences });
50
+ return configPath;
51
+ } catch (error) {
52
+ logger.debug(`Failed to auto-install agent '${agentId}': ${error}`);
53
+ throw RegistryError.agentNotFound(agentId, []);
54
+ }
55
+ }
56
+ throw RegistryError.agentNotInstalledAutoInstallDisabled(agentId, []);
57
+ }
58
+ async function getAgentConfigPath(agentId) {
59
+ const agentsDir = getDextoGlobalPath("agents");
60
+ const installedRegistryPath = path.join(agentsDir, "registry.json");
61
+ const registryContent = await fs.readFile(installedRegistryPath, "utf-8");
62
+ const registry = JSON.parse(registryContent);
63
+ const agentEntry = registry.agents.find((a) => a.id === agentId);
64
+ if (!agentEntry) {
65
+ const available = registry.agents.map((a) => a.id);
66
+ throw RegistryError.agentNotFound(agentId, available);
67
+ }
68
+ return path.resolve(path.dirname(installedRegistryPath), agentEntry.configPath);
69
+ }
32
70
  async function resolveDefaultAgentByContext(autoInstall = true, injectPreferences = true) {
33
71
  const executionContext = getExecutionContext();
34
72
  switch (executionContext) {
@@ -65,13 +103,7 @@ async function resolveDefaultAgentForDextoSource(autoInstall = true, injectPrefe
65
103
  if (preferences.setup.completed) {
66
104
  logger.debug("Using user preferences in dexto-source context");
67
105
  const preferredAgentName = preferences.defaults.defaultAgent;
68
- const { getAgentRegistry } = await import("./registry/registry.js");
69
- const registry = getAgentRegistry();
70
- return await registry.resolveAgent(
71
- preferredAgentName,
72
- autoInstall,
73
- injectPreferences
74
- );
106
+ return await resolveAgentByName(preferredAgentName, autoInstall, injectPreferences);
75
107
  }
76
108
  } catch (error) {
77
109
  logger.warn(`Failed to load preferences, falling back to repo config: ${error}`);
@@ -112,9 +144,7 @@ async function resolveDefaultAgentForDextoProject(autoInstall = true, injectPref
112
144
  throw ConfigError.setupIncomplete();
113
145
  }
114
146
  const preferredAgentName = preferences.defaults.defaultAgent;
115
- const { getAgentRegistry } = await import("./registry/registry.js");
116
- const registry = getAgentRegistry();
117
- return await registry.resolveAgent(preferredAgentName, autoInstall, injectPreferences);
147
+ return await resolveAgentByName(preferredAgentName, autoInstall, injectPreferences);
118
148
  }
119
149
  async function resolveDefaultAgentForGlobalCLI(autoInstall = true, injectPreferences = true) {
120
150
  logger.debug("Resolving default agent for global CLI context");
@@ -126,24 +156,33 @@ async function resolveDefaultAgentForGlobalCLI(autoInstall = true, injectPrefere
126
156
  throw ConfigError.setupIncomplete();
127
157
  }
128
158
  const preferredAgentName = preferences.defaults.defaultAgent;
129
- const { getAgentRegistry } = await import("./registry/registry.js");
130
- const registry = getAgentRegistry();
131
- return await registry.resolveAgent(preferredAgentName, autoInstall, injectPreferences);
159
+ return await resolveAgentByName(preferredAgentName, autoInstall, injectPreferences);
132
160
  }
133
161
  async function updateDefaultAgentPreference(agentName) {
134
- const { getAgentRegistry } = await import("./registry/registry.js");
135
- const { RegistryError } = await import("./registry/errors.js");
136
- const { isPath: isPath2 } = await import("@dexto/core");
137
- const registry = getAgentRegistry();
138
- if (isPath2(agentName) || !registry.hasAgent(agentName)) {
139
- const available = Object.keys(registry.getAvailableAgents());
140
- throw RegistryError.agentNotFound(agentName, available);
141
- }
142
- const { updateGlobalPreferences } = await import("./preferences/loader.js");
143
- await updateGlobalPreferences({
144
- defaults: { defaultAgent: agentName }
145
- });
146
- logger.info(`Updated default agent preference to: ${agentName}`);
162
+ const agentsDir = getDextoGlobalPath("agents");
163
+ const installedRegistryPath = path.join(agentsDir, "registry.json");
164
+ const bundledRegistryPath = resolveBundledScript("agents/agent-registry.json");
165
+ const registriesToCheck = [
166
+ { path: installedRegistryPath, name: "installed" },
167
+ { path: bundledRegistryPath, name: "bundled" }
168
+ ];
169
+ for (const registry of registriesToCheck) {
170
+ try {
171
+ const manager = new AgentManager(registry.path);
172
+ await manager.loadRegistry();
173
+ if (manager.hasAgent(agentName)) {
174
+ const { updateGlobalPreferences } = await import("./preferences/loader.js");
175
+ await updateGlobalPreferences({
176
+ defaults: { defaultAgent: agentName }
177
+ });
178
+ logger.info(`Updated default agent preference to: ${agentName}`);
179
+ return;
180
+ }
181
+ } catch (error) {
182
+ logger.debug(`Agent '${agentName}' not found in ${registry.name} registry: ${error}`);
183
+ }
184
+ }
185
+ throw RegistryError.agentNotFound(agentName, []);
147
186
  }
148
187
  export {
149
188
  resolveAgentPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexto/agent-management",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "yaml": "^2.7.1",
18
18
  "zod": "^3.25.0",
19
- "@dexto/core": "1.3.0"
19
+ "@dexto/core": "1.4.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.13.5"
@@ -1,263 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var AgentOrchestrator_exports = {};
20
- __export(AgentOrchestrator_exports, {
21
- AgentOrchestrator: () => AgentOrchestrator
22
- });
23
- module.exports = __toCommonJS(AgentOrchestrator_exports);
24
- var import_core = require("@dexto/core");
25
- var import_config = require("./config/index.js");
26
- var import_registry = require("./registry/registry.js");
27
- var import_types = require("./registry/types.js");
28
- var import_zod = require("zod");
29
- var import_core2 = require("@dexto/core");
30
- class AgentOrchestrator {
31
- /**
32
- * Lists available and installed agents from the registry.
33
- * Returns a structured object containing both installed and available agents,
34
- * along with metadata like descriptions, authors, and tags.
35
- *
36
- * @returns Promise resolving to object with installed and available agent lists
37
- *
38
- * @example
39
- * ```typescript
40
- * const agents = await AgentOrchestrator.listAgents();
41
- * console.log(agents.installed); // ['default', 'my-custom-agent']
42
- * console.log(agents.available); // [{ name: 'productivity', description: '...', ... }]
43
- * console.log(agents.current?.name); // 'default'
44
- * ```
45
- */
46
- static async listAgents() {
47
- const agentRegistry = (0, import_registry.getAgentRegistry)();
48
- const availableMap = agentRegistry.getAvailableAgents();
49
- const installedNames = await agentRegistry.getInstalledAgents();
50
- const installed = await Promise.all(
51
- installedNames.map(async (agentId) => {
52
- const registryEntry = availableMap[agentId];
53
- if (registryEntry) {
54
- return {
55
- id: agentId,
56
- name: registryEntry.name,
57
- description: registryEntry.description,
58
- author: registryEntry.author,
59
- tags: registryEntry.tags,
60
- type: registryEntry.type
61
- };
62
- } else {
63
- try {
64
- const config = await (0, import_config.loadAgentConfig)(agentId);
65
- const author = config.agentCard?.provider?.organization;
66
- const result = {
67
- id: agentId,
68
- name: typeof config.agentCard?.name === "string" ? config.agentCard.name : (0, import_types.deriveDisplayName)(agentId),
69
- description: config.agentCard?.description || "Local agent",
70
- tags: [],
71
- type: "custom"
72
- // Assume custom if not in registry
73
- };
74
- if (author) {
75
- result.author = author;
76
- }
77
- return result;
78
- } catch {
79
- const result = {
80
- id: agentId,
81
- name: (0, import_types.deriveDisplayName)(agentId),
82
- description: "Local agent (config unavailable)",
83
- tags: [],
84
- type: "custom"
85
- // Assume custom if not in registry
86
- };
87
- return result;
88
- }
89
- }
90
- })
91
- );
92
- const available = Object.entries(availableMap).filter(([agentId]) => !installedNames.includes(agentId)).map(([agentId, entry]) => ({
93
- id: agentId,
94
- name: entry.name,
95
- description: entry.description,
96
- author: entry.author,
97
- tags: entry.tags,
98
- type: entry.type
99
- }));
100
- return {
101
- installed,
102
- available,
103
- current: { id: null, name: null }
104
- // TODO: Track current agent name
105
- };
106
- }
107
- /**
108
- * Installs an agent from the registry.
109
- * Downloads and sets up the specified agent, making it available for use.
110
- *
111
- * @param agentName The name of the agent to install from the registry
112
- * @returns Promise that resolves when installation is complete
113
- *
114
- * @throws {AgentError} When agent is not found in registry or installation fails
115
- *
116
- * @example
117
- * ```typescript
118
- * await AgentOrchestrator.installAgent('productivity');
119
- * console.log('Productivity agent installed successfully');
120
- * ```
121
- */
122
- static async installAgent(agentName) {
123
- const agentRegistry = (0, import_registry.getAgentRegistry)();
124
- if (!agentRegistry.hasAgent(agentName)) {
125
- throw import_core.AgentError.apiValidationError(`Agent '${agentName}' not found in registry`);
126
- }
127
- try {
128
- await agentRegistry.installAgent(agentName, true);
129
- import_core.logger.info(`Successfully installed agent: ${agentName}`);
130
- } catch (error) {
131
- const errorMessage = error instanceof Error ? error.message : String(error);
132
- import_core.logger.error(`Failed to install agent ${agentName}: ${errorMessage}`);
133
- throw import_core.AgentError.apiValidationError(
134
- `Installation failed for agent '${agentName}'`,
135
- error
136
- );
137
- }
138
- }
139
- /**
140
- * Installs a custom agent from a local file or directory path.
141
- * Creates a new custom agent entry in the user registry with provided metadata.
142
- *
143
- * @param agentName The name to use for the custom agent (must be unique)
144
- * @param sourcePath Absolute path to the agent YAML file or directory
145
- * @param metadata Agent metadata (description, author, tags, main config file)
146
- * @param injectPreferences Whether to inject global preferences into agent config (default: true)
147
- * @returns Promise resolving to the path of the installed main config file
148
- *
149
- * @throws {AgentError} When name conflicts with existing agent or installation fails
150
- *
151
- * @example
152
- * ```typescript
153
- * await AgentOrchestrator.installCustomAgent('my-coding-agent', '/path/to/agent.yml', {
154
- * description: 'Custom coding assistant',
155
- * author: 'John Doe',
156
- * tags: ['coding', 'custom']
157
- * });
158
- * console.log('Custom agent installed successfully');
159
- * ```
160
- */
161
- static async installCustomAgent(agentName, sourcePath, metadata, injectPreferences = true) {
162
- const agentRegistry = (0, import_registry.getAgentRegistry)();
163
- try {
164
- const mainConfigPath = await agentRegistry.installCustomAgentFromPath(
165
- agentName,
166
- sourcePath,
167
- metadata,
168
- injectPreferences
169
- );
170
- import_core.logger.info(`Successfully installed custom agent: ${agentName}`);
171
- return mainConfigPath;
172
- } catch (error) {
173
- const errorMessage = error instanceof Error ? error.message : String(error);
174
- import_core.logger.error(`Failed to install custom agent ${agentName}: ${errorMessage}`);
175
- throw import_core.AgentError.apiValidationError(
176
- `Installation failed for custom agent '${agentName}'`,
177
- error
178
- );
179
- }
180
- }
181
- /**
182
- * Uninstalls an agent by removing its directory from disk.
183
- * For custom agents: also removes from user registry.
184
- * For builtin agents: only removes from disk (can be reinstalled).
185
- *
186
- * @param agentName The name of the agent to uninstall
187
- * @param force Whether to force uninstall even if agent is protected (default: false)
188
- * @returns Promise that resolves when uninstallation is complete
189
- *
190
- * @throws {AgentError} When agent is not installed or uninstallation fails
191
- *
192
- * @example
193
- * ```typescript
194
- * await AgentOrchestrator.uninstallAgent('my-custom-agent');
195
- * console.log('Agent uninstalled successfully');
196
- * ```
197
- */
198
- static async uninstallAgent(agentName, force = false) {
199
- const agentRegistry = (0, import_registry.getAgentRegistry)();
200
- try {
201
- await agentRegistry.uninstallAgent(agentName, force);
202
- import_core.logger.info(`Successfully uninstalled agent: ${agentName}`);
203
- } catch (error) {
204
- const errorMessage = error instanceof Error ? error.message : String(error);
205
- import_core.logger.error(`Failed to uninstall agent ${agentName}: ${errorMessage}`);
206
- throw import_core.AgentError.apiValidationError(
207
- `Uninstallation failed for agent '${agentName}'`,
208
- error
209
- );
210
- }
211
- }
212
- /**
213
- * Creates a new agent instance for the specified agent name.
214
- * This method resolves the agent (installing if needed), loads its configuration,
215
- * and returns a new DextoAgent instance ready to be started.
216
- *
217
- * This is a factory method that doesn't affect any existing agent instances.
218
- * The caller is responsible for managing the lifecycle of the returned agent.
219
- *
220
- * @param agentName The name of the agent to create
221
- * @returns Promise resolving to a new DextoAgent instance (not started)
222
- *
223
- * @throws {AgentError} When agent is not found or creation fails
224
- *
225
- * @example
226
- * ```typescript
227
- * const newAgent = await AgentOrchestrator.createAgent('productivity');
228
- * await newAgent.start();
229
- * ```
230
- */
231
- static async createAgent(agentName) {
232
- const agentRegistry = (0, import_registry.getAgentRegistry)();
233
- try {
234
- const agentPath = await agentRegistry.resolveAgent(agentName, true, true);
235
- const config = await (0, import_config.loadAgentConfig)(agentPath);
236
- const enrichedConfig = (0, import_config.enrichAgentConfig)(config, agentPath);
237
- import_core.logger.info(`Creating agent: ${agentName}`);
238
- const newAgent = new import_core.DextoAgent(enrichedConfig, agentPath);
239
- import_core.logger.info(`Successfully created agent: ${agentName}`);
240
- return newAgent;
241
- } catch (error) {
242
- if (error instanceof import_zod.ZodError) {
243
- const issues = (0, import_core2.zodToIssues)(error, "error");
244
- const formatted = issues.map((issue) => {
245
- const path = Array.isArray(issue.path) ? issue.path.join(".") : String(issue.path);
246
- return `${path}: ${issue.message}`;
247
- });
248
- const message = `Configuration validation failed for agent '${agentName}':
249
- ${formatted.join("\n")}`;
250
- import_core.logger.error(message);
251
- throw new import_core.DextoValidationError(issues);
252
- }
253
- import_core.logger.error(
254
- `Failed to create agent '${agentName}': ${error instanceof Error ? error.message : String(error)}`
255
- );
256
- throw import_core.AgentError.apiValidationError(`Failed to create agent '${agentName}'`, error);
257
- }
258
- }
259
- }
260
- // Annotate the CommonJS export names for ESM import in node:
261
- 0 && (module.exports = {
262
- AgentOrchestrator
263
- });