@dexto/agent-management 1.3.0 → 1.5.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 (94) hide show
  1. package/dist/AgentFactory.cjs +152 -0
  2. package/dist/AgentFactory.d.ts +121 -0
  3. package/dist/AgentFactory.d.ts.map +1 -0
  4. package/dist/AgentFactory.js +132 -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 +23 -3
  10. package/dist/config/config-enrichment.d.ts +20 -5
  11. package/dist/config/config-enrichment.d.ts.map +1 -1
  12. package/dist/config/config-enrichment.js +22 -3
  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/errors.cjs +2 -2
  22. package/dist/config/errors.js +2 -2
  23. package/dist/config/index.cjs +14 -2
  24. package/dist/config/index.d.ts +2 -2
  25. package/dist/config/index.d.ts.map +1 -1
  26. package/dist/config/index.js +21 -3
  27. package/dist/index.cjs +109 -6
  28. package/dist/index.d.ts +9 -6
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +111 -6
  31. package/dist/installation.cjs +239 -0
  32. package/dist/installation.d.ts +72 -0
  33. package/dist/installation.d.ts.map +1 -0
  34. package/dist/installation.js +202 -0
  35. package/dist/models/custom-models.cjs +157 -0
  36. package/dist/models/custom-models.d.ts +94 -0
  37. package/dist/models/custom-models.d.ts.map +1 -0
  38. package/dist/models/custom-models.js +117 -0
  39. package/dist/models/index.cjs +89 -0
  40. package/dist/models/index.d.ts +11 -0
  41. package/dist/models/index.d.ts.map +1 -0
  42. package/dist/models/index.js +68 -0
  43. package/dist/models/path-resolver.cjs +154 -0
  44. package/dist/models/path-resolver.d.ts +77 -0
  45. package/dist/models/path-resolver.d.ts.map +1 -0
  46. package/dist/models/path-resolver.js +108 -0
  47. package/dist/models/state-manager.cjs +220 -0
  48. package/dist/models/state-manager.d.ts +138 -0
  49. package/dist/models/state-manager.d.ts.map +1 -0
  50. package/dist/models/state-manager.js +184 -0
  51. package/dist/preferences/error-codes.cjs +2 -0
  52. package/dist/preferences/error-codes.d.ts +3 -1
  53. package/dist/preferences/error-codes.d.ts.map +1 -1
  54. package/dist/preferences/error-codes.js +2 -0
  55. package/dist/preferences/index.d.ts +1 -1
  56. package/dist/preferences/index.d.ts.map +1 -1
  57. package/dist/preferences/loader.cjs +32 -6
  58. package/dist/preferences/loader.d.ts +23 -4
  59. package/dist/preferences/loader.d.ts.map +1 -1
  60. package/dist/preferences/loader.js +32 -6
  61. package/dist/preferences/schemas.cjs +21 -3
  62. package/dist/preferences/schemas.d.ts +52 -24
  63. package/dist/preferences/schemas.d.ts.map +1 -1
  64. package/dist/preferences/schemas.js +28 -4
  65. package/dist/registry/registry.cjs +28 -45
  66. package/dist/registry/registry.d.ts +8 -6
  67. package/dist/registry/registry.d.ts.map +1 -1
  68. package/dist/registry/registry.js +26 -44
  69. package/dist/registry/types.d.ts +11 -13
  70. package/dist/registry/types.d.ts.map +1 -1
  71. package/dist/resolver.cjs +82 -43
  72. package/dist/resolver.d.ts +7 -5
  73. package/dist/resolver.d.ts.map +1 -1
  74. package/dist/resolver.js +83 -44
  75. package/dist/utils/api-key-resolver.cjs +19 -1
  76. package/dist/utils/api-key-resolver.d.ts.map +1 -1
  77. package/dist/utils/api-key-resolver.js +19 -1
  78. package/dist/utils/api-key-store.cjs +46 -0
  79. package/dist/utils/api-key-store.d.ts +27 -0
  80. package/dist/utils/api-key-store.d.ts.map +1 -1
  81. package/dist/utils/api-key-store.js +44 -0
  82. package/dist/utils/env-file.cjs +20 -68
  83. package/dist/utils/env-file.d.ts +2 -1
  84. package/dist/utils/env-file.d.ts.map +1 -1
  85. package/dist/utils/env-file.js +20 -68
  86. package/dist/writer.cjs +20 -2
  87. package/dist/writer.d.ts +1 -0
  88. package/dist/writer.d.ts.map +1 -1
  89. package/dist/writer.js +20 -2
  90. package/package.json +2 -2
  91. package/dist/AgentOrchestrator.cjs +0 -263
  92. package/dist/AgentOrchestrator.d.ts +0 -191
  93. package/dist/AgentOrchestrator.d.ts.map +0 -1
  94. package/dist/AgentOrchestrator.js +0 -239
@@ -1,239 +0,0 @@
1
- import { logger, AgentError, DextoAgent, DextoValidationError } from "@dexto/core";
2
- import { loadAgentConfig, enrichAgentConfig } from "./config/index.js";
3
- import { getAgentRegistry } from "./registry/registry.js";
4
- import { deriveDisplayName } from "./registry/types.js";
5
- import { ZodError } from "zod";
6
- import { zodToIssues } from "@dexto/core";
7
- class AgentOrchestrator {
8
- /**
9
- * Lists available and installed agents from the registry.
10
- * Returns a structured object containing both installed and available agents,
11
- * along with metadata like descriptions, authors, and tags.
12
- *
13
- * @returns Promise resolving to object with installed and available agent lists
14
- *
15
- * @example
16
- * ```typescript
17
- * const agents = await AgentOrchestrator.listAgents();
18
- * console.log(agents.installed); // ['default', 'my-custom-agent']
19
- * console.log(agents.available); // [{ name: 'productivity', description: '...', ... }]
20
- * console.log(agents.current?.name); // 'default'
21
- * ```
22
- */
23
- static async listAgents() {
24
- const agentRegistry = getAgentRegistry();
25
- const availableMap = agentRegistry.getAvailableAgents();
26
- const installedNames = await agentRegistry.getInstalledAgents();
27
- const installed = await Promise.all(
28
- installedNames.map(async (agentId) => {
29
- const registryEntry = availableMap[agentId];
30
- if (registryEntry) {
31
- return {
32
- id: agentId,
33
- name: registryEntry.name,
34
- description: registryEntry.description,
35
- author: registryEntry.author,
36
- tags: registryEntry.tags,
37
- type: registryEntry.type
38
- };
39
- } else {
40
- try {
41
- const config = await loadAgentConfig(agentId);
42
- const author = config.agentCard?.provider?.organization;
43
- const result = {
44
- id: agentId,
45
- name: typeof config.agentCard?.name === "string" ? config.agentCard.name : deriveDisplayName(agentId),
46
- description: config.agentCard?.description || "Local agent",
47
- tags: [],
48
- type: "custom"
49
- // Assume custom if not in registry
50
- };
51
- if (author) {
52
- result.author = author;
53
- }
54
- return result;
55
- } catch {
56
- const result = {
57
- id: agentId,
58
- name: deriveDisplayName(agentId),
59
- description: "Local agent (config unavailable)",
60
- tags: [],
61
- type: "custom"
62
- // Assume custom if not in registry
63
- };
64
- return result;
65
- }
66
- }
67
- })
68
- );
69
- const available = Object.entries(availableMap).filter(([agentId]) => !installedNames.includes(agentId)).map(([agentId, entry]) => ({
70
- id: agentId,
71
- name: entry.name,
72
- description: entry.description,
73
- author: entry.author,
74
- tags: entry.tags,
75
- type: entry.type
76
- }));
77
- return {
78
- installed,
79
- available,
80
- current: { id: null, name: null }
81
- // TODO: Track current agent name
82
- };
83
- }
84
- /**
85
- * Installs an agent from the registry.
86
- * Downloads and sets up the specified agent, making it available for use.
87
- *
88
- * @param agentName The name of the agent to install from the registry
89
- * @returns Promise that resolves when installation is complete
90
- *
91
- * @throws {AgentError} When agent is not found in registry or installation fails
92
- *
93
- * @example
94
- * ```typescript
95
- * await AgentOrchestrator.installAgent('productivity');
96
- * console.log('Productivity agent installed successfully');
97
- * ```
98
- */
99
- static async installAgent(agentName) {
100
- const agentRegistry = getAgentRegistry();
101
- if (!agentRegistry.hasAgent(agentName)) {
102
- throw AgentError.apiValidationError(`Agent '${agentName}' not found in registry`);
103
- }
104
- try {
105
- await agentRegistry.installAgent(agentName, true);
106
- logger.info(`Successfully installed agent: ${agentName}`);
107
- } catch (error) {
108
- const errorMessage = error instanceof Error ? error.message : String(error);
109
- logger.error(`Failed to install agent ${agentName}: ${errorMessage}`);
110
- throw AgentError.apiValidationError(
111
- `Installation failed for agent '${agentName}'`,
112
- error
113
- );
114
- }
115
- }
116
- /**
117
- * Installs a custom agent from a local file or directory path.
118
- * Creates a new custom agent entry in the user registry with provided metadata.
119
- *
120
- * @param agentName The name to use for the custom agent (must be unique)
121
- * @param sourcePath Absolute path to the agent YAML file or directory
122
- * @param metadata Agent metadata (description, author, tags, main config file)
123
- * @param injectPreferences Whether to inject global preferences into agent config (default: true)
124
- * @returns Promise resolving to the path of the installed main config file
125
- *
126
- * @throws {AgentError} When name conflicts with existing agent or installation fails
127
- *
128
- * @example
129
- * ```typescript
130
- * await AgentOrchestrator.installCustomAgent('my-coding-agent', '/path/to/agent.yml', {
131
- * description: 'Custom coding assistant',
132
- * author: 'John Doe',
133
- * tags: ['coding', 'custom']
134
- * });
135
- * console.log('Custom agent installed successfully');
136
- * ```
137
- */
138
- static async installCustomAgent(agentName, sourcePath, metadata, injectPreferences = true) {
139
- const agentRegistry = getAgentRegistry();
140
- try {
141
- const mainConfigPath = await agentRegistry.installCustomAgentFromPath(
142
- agentName,
143
- sourcePath,
144
- metadata,
145
- injectPreferences
146
- );
147
- logger.info(`Successfully installed custom agent: ${agentName}`);
148
- return mainConfigPath;
149
- } catch (error) {
150
- const errorMessage = error instanceof Error ? error.message : String(error);
151
- logger.error(`Failed to install custom agent ${agentName}: ${errorMessage}`);
152
- throw AgentError.apiValidationError(
153
- `Installation failed for custom agent '${agentName}'`,
154
- error
155
- );
156
- }
157
- }
158
- /**
159
- * Uninstalls an agent by removing its directory from disk.
160
- * For custom agents: also removes from user registry.
161
- * For builtin agents: only removes from disk (can be reinstalled).
162
- *
163
- * @param agentName The name of the agent to uninstall
164
- * @param force Whether to force uninstall even if agent is protected (default: false)
165
- * @returns Promise that resolves when uninstallation is complete
166
- *
167
- * @throws {AgentError} When agent is not installed or uninstallation fails
168
- *
169
- * @example
170
- * ```typescript
171
- * await AgentOrchestrator.uninstallAgent('my-custom-agent');
172
- * console.log('Agent uninstalled successfully');
173
- * ```
174
- */
175
- static async uninstallAgent(agentName, force = false) {
176
- const agentRegistry = getAgentRegistry();
177
- try {
178
- await agentRegistry.uninstallAgent(agentName, force);
179
- logger.info(`Successfully uninstalled agent: ${agentName}`);
180
- } catch (error) {
181
- const errorMessage = error instanceof Error ? error.message : String(error);
182
- logger.error(`Failed to uninstall agent ${agentName}: ${errorMessage}`);
183
- throw AgentError.apiValidationError(
184
- `Uninstallation failed for agent '${agentName}'`,
185
- error
186
- );
187
- }
188
- }
189
- /**
190
- * Creates a new agent instance for the specified agent name.
191
- * This method resolves the agent (installing if needed), loads its configuration,
192
- * and returns a new DextoAgent instance ready to be started.
193
- *
194
- * This is a factory method that doesn't affect any existing agent instances.
195
- * The caller is responsible for managing the lifecycle of the returned agent.
196
- *
197
- * @param agentName The name of the agent to create
198
- * @returns Promise resolving to a new DextoAgent instance (not started)
199
- *
200
- * @throws {AgentError} When agent is not found or creation fails
201
- *
202
- * @example
203
- * ```typescript
204
- * const newAgent = await AgentOrchestrator.createAgent('productivity');
205
- * await newAgent.start();
206
- * ```
207
- */
208
- static async createAgent(agentName) {
209
- const agentRegistry = getAgentRegistry();
210
- try {
211
- const agentPath = await agentRegistry.resolveAgent(agentName, true, true);
212
- const config = await loadAgentConfig(agentPath);
213
- const enrichedConfig = enrichAgentConfig(config, agentPath);
214
- logger.info(`Creating agent: ${agentName}`);
215
- const newAgent = new DextoAgent(enrichedConfig, agentPath);
216
- logger.info(`Successfully created agent: ${agentName}`);
217
- return newAgent;
218
- } catch (error) {
219
- if (error instanceof ZodError) {
220
- const issues = zodToIssues(error, "error");
221
- const formatted = issues.map((issue) => {
222
- const path = Array.isArray(issue.path) ? issue.path.join(".") : String(issue.path);
223
- return `${path}: ${issue.message}`;
224
- });
225
- const message = `Configuration validation failed for agent '${agentName}':
226
- ${formatted.join("\n")}`;
227
- logger.error(message);
228
- throw new DextoValidationError(issues);
229
- }
230
- logger.error(
231
- `Failed to create agent '${agentName}': ${error instanceof Error ? error.message : String(error)}`
232
- );
233
- throw AgentError.apiValidationError(`Failed to create agent '${agentName}'`, error);
234
- }
235
- }
236
- }
237
- export {
238
- AgentOrchestrator
239
- };