@dexto/agent-management 1.2.5
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.
- package/LICENSE +44 -0
- package/dist/AgentOrchestrator.cjs +263 -0
- package/dist/AgentOrchestrator.d.ts +191 -0
- package/dist/AgentOrchestrator.d.ts.map +1 -0
- package/dist/AgentOrchestrator.js +239 -0
- package/dist/config/config-enrichment.cjs +117 -0
- package/dist/config/config-enrichment.d.ts +31 -0
- package/dist/config/config-enrichment.d.ts.map +1 -0
- package/dist/config/config-enrichment.js +82 -0
- package/dist/config/config-manager.cjs +57 -0
- package/dist/config/config-manager.d.ts +51 -0
- package/dist/config/config-manager.d.ts.map +1 -0
- package/dist/config/config-manager.js +32 -0
- package/dist/config/error-codes.cjs +39 -0
- package/dist/config/error-codes.d.ts +16 -0
- package/dist/config/error-codes.d.ts.map +1 -0
- package/dist/config/error-codes.js +15 -0
- package/dist/config/errors.cjs +125 -0
- package/dist/config/errors.d.ts +34 -0
- package/dist/config/errors.d.ts.map +1 -0
- package/dist/config/errors.js +101 -0
- package/dist/config/index.cjs +44 -0
- package/dist/config/index.d.ts +6 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +14 -0
- package/dist/config/loader.cjs +118 -0
- package/dist/config/loader.d.ts +18 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +84 -0
- package/dist/index.cjs +132 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +104 -0
- package/dist/preferences/constants.cjs +28 -0
- package/dist/preferences/constants.d.ts +2 -0
- package/dist/preferences/constants.d.ts.map +1 -0
- package/dist/preferences/constants.js +4 -0
- package/dist/preferences/error-codes.cjs +35 -0
- package/dist/preferences/error-codes.d.ts +8 -0
- package/dist/preferences/error-codes.d.ts.map +1 -0
- package/dist/preferences/error-codes.js +11 -0
- package/dist/preferences/errors.cjs +74 -0
- package/dist/preferences/errors.d.ts +18 -0
- package/dist/preferences/errors.d.ts.map +1 -0
- package/dist/preferences/errors.js +49 -0
- package/dist/preferences/index.cjs +55 -0
- package/dist/preferences/index.d.ts +6 -0
- package/dist/preferences/index.d.ts.map +1 -0
- package/dist/preferences/index.js +31 -0
- package/dist/preferences/loader.cjs +138 -0
- package/dist/preferences/loader.d.ts +50 -0
- package/dist/preferences/loader.d.ts.map +1 -0
- package/dist/preferences/loader.js +109 -0
- package/dist/preferences/schemas.cjs +75 -0
- package/dist/preferences/schemas.d.ts +110 -0
- package/dist/preferences/schemas.d.ts.map +1 -0
- package/dist/preferences/schemas.js +48 -0
- package/dist/registry/error-codes.cjs +44 -0
- package/dist/registry/error-codes.d.ts +21 -0
- package/dist/registry/error-codes.d.ts.map +1 -0
- package/dist/registry/error-codes.js +20 -0
- package/dist/registry/errors.cjs +187 -0
- package/dist/registry/errors.d.ts +63 -0
- package/dist/registry/errors.d.ts.map +1 -0
- package/dist/registry/errors.js +163 -0
- package/dist/registry/registry.cjs +479 -0
- package/dist/registry/registry.d.ts +130 -0
- package/dist/registry/registry.d.ts.map +1 -0
- package/dist/registry/registry.js +452 -0
- package/dist/registry/types.cjs +74 -0
- package/dist/registry/types.d.ts +142 -0
- package/dist/registry/types.d.ts.map +1 -0
- package/dist/registry/types.js +47 -0
- package/dist/registry/user-registry.cjs +140 -0
- package/dist/registry/user-registry.d.ts +34 -0
- package/dist/registry/user-registry.d.ts.map +1 -0
- package/dist/registry/user-registry.js +104 -0
- package/dist/resolver.cjs +182 -0
- package/dist/resolver.d.ts +14 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +151 -0
- package/dist/utils/api-key-resolver.cjs +62 -0
- package/dist/utils/api-key-resolver.d.ts +21 -0
- package/dist/utils/api-key-resolver.d.ts.map +1 -0
- package/dist/utils/api-key-resolver.js +36 -0
- package/dist/utils/api-key-store.cjs +56 -0
- package/dist/utils/api-key-store.d.ts +18 -0
- package/dist/utils/api-key-store.d.ts.map +1 -0
- package/dist/utils/api-key-store.js +30 -0
- package/dist/utils/env-file.cjs +118 -0
- package/dist/utils/env-file.d.ts +5 -0
- package/dist/utils/env-file.d.ts.map +1 -0
- package/dist/utils/env-file.js +84 -0
- package/dist/utils/execution-context.cjs +85 -0
- package/dist/utils/execution-context.d.ts +20 -0
- package/dist/utils/execution-context.d.ts.map +1 -0
- package/dist/utils/execution-context.js +49 -0
- package/dist/utils/fs-walk.cjs +52 -0
- package/dist/utils/fs-walk.d.ts +8 -0
- package/dist/utils/fs-walk.d.ts.map +1 -0
- package/dist/utils/fs-walk.js +18 -0
- package/dist/utils/path.cjs +205 -0
- package/dist/utils/path.d.ts +58 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +167 -0
- package/dist/writer.cjs +182 -0
- package/dist/writer.d.ts +34 -0
- package/dist/writer.d.ts.map +1 -0
- package/dist/writer.js +146 -0
- package/package.json +41 -0
|
@@ -0,0 +1,239 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var config_enrichment_exports = {};
|
|
30
|
+
__export(config_enrichment_exports, {
|
|
31
|
+
deriveAgentId: () => deriveAgentId,
|
|
32
|
+
enrichAgentConfig: () => enrichAgentConfig
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(config_enrichment_exports);
|
|
35
|
+
var import_path = require("../utils/path.js");
|
|
36
|
+
var path = __toESM(require("path"), 1);
|
|
37
|
+
function deriveAgentId(config, configPath) {
|
|
38
|
+
if (config.agentCard?.name) {
|
|
39
|
+
const sanitizedName = config.agentCard.name.toLowerCase().replace(/[^a-z0-9-_]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
40
|
+
if (sanitizedName) {
|
|
41
|
+
return sanitizedName;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (configPath) {
|
|
45
|
+
const basename = path.basename(configPath, path.extname(configPath));
|
|
46
|
+
if (basename && basename !== "agent" && basename !== "config") {
|
|
47
|
+
return basename;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return "default-agent";
|
|
51
|
+
}
|
|
52
|
+
function enrichAgentConfig(config, configPath, isInteractiveCli = false) {
|
|
53
|
+
const agentId = deriveAgentId(config, configPath);
|
|
54
|
+
const logPath = (0, import_path.getDextoPath)("logs", `${agentId}.log`);
|
|
55
|
+
const dbPath = (0, import_path.getDextoPath)("database", `${agentId}.db`);
|
|
56
|
+
const blobPath = (0, import_path.getDextoPath)("blobs", agentId);
|
|
57
|
+
const enriched = {
|
|
58
|
+
...config,
|
|
59
|
+
agentId
|
|
60
|
+
// Set agentId explicitly (single source of truth)
|
|
61
|
+
};
|
|
62
|
+
if (!config.logger) {
|
|
63
|
+
const transports = isInteractiveCli ? [
|
|
64
|
+
{
|
|
65
|
+
type: "file",
|
|
66
|
+
path: logPath,
|
|
67
|
+
maxSize: 10 * 1024 * 1024,
|
|
68
|
+
// 10MB
|
|
69
|
+
maxFiles: 5
|
|
70
|
+
}
|
|
71
|
+
] : [
|
|
72
|
+
{ type: "console", colorize: true },
|
|
73
|
+
{
|
|
74
|
+
type: "file",
|
|
75
|
+
path: logPath,
|
|
76
|
+
maxSize: 10 * 1024 * 1024,
|
|
77
|
+
// 10MB
|
|
78
|
+
maxFiles: 5
|
|
79
|
+
}
|
|
80
|
+
];
|
|
81
|
+
enriched.logger = {
|
|
82
|
+
level: "info",
|
|
83
|
+
transports
|
|
84
|
+
};
|
|
85
|
+
} else {
|
|
86
|
+
enriched.logger = config.logger;
|
|
87
|
+
}
|
|
88
|
+
if (!config.storage) {
|
|
89
|
+
enriched.storage = {
|
|
90
|
+
cache: { type: "in-memory" },
|
|
91
|
+
database: { type: "sqlite", path: dbPath },
|
|
92
|
+
blob: { type: "local", storePath: blobPath }
|
|
93
|
+
};
|
|
94
|
+
} else {
|
|
95
|
+
enriched.storage = {
|
|
96
|
+
...config.storage
|
|
97
|
+
};
|
|
98
|
+
if (config.storage.database?.type === "sqlite") {
|
|
99
|
+
enriched.storage.database = {
|
|
100
|
+
...config.storage.database,
|
|
101
|
+
path: config.storage.database.path || dbPath
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (config.storage.blob?.type === "local") {
|
|
105
|
+
enriched.storage.blob = {
|
|
106
|
+
...config.storage.blob,
|
|
107
|
+
storePath: config.storage.blob.storePath || blobPath
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return enriched;
|
|
112
|
+
}
|
|
113
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
114
|
+
0 && (module.exports = {
|
|
115
|
+
deriveAgentId,
|
|
116
|
+
enrichAgentConfig
|
|
117
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config Enrichment Layer
|
|
3
|
+
*
|
|
4
|
+
* Provides per-agent path defaults for file-based resources (logs, database, blobs, backups).
|
|
5
|
+
* This layer runs before agent initialization and injects explicit paths
|
|
6
|
+
* into the configuration, eliminating the need for core services to resolve paths themselves.
|
|
7
|
+
*
|
|
8
|
+
* Core services now require explicit paths - this enrichment layer provides them.
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentConfig } from '@dexto/core';
|
|
11
|
+
/**
|
|
12
|
+
* Derives an agent ID from config or file path for per-agent isolation.
|
|
13
|
+
* Priority: agentCard.name > filename (without extension) > 'default-agent'
|
|
14
|
+
*/
|
|
15
|
+
export declare function deriveAgentId(config: AgentConfig, configPath?: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Enriches agent configuration with per-agent file paths.
|
|
18
|
+
* This function is called before creating the DextoAgent instance.
|
|
19
|
+
*
|
|
20
|
+
* Enrichment adds:
|
|
21
|
+
* - File transport to logger config (per-agent log file)
|
|
22
|
+
* - Full paths to storage config (SQLite database, blob storage)
|
|
23
|
+
* - Backup path to filesystem config (per-agent backups)
|
|
24
|
+
*
|
|
25
|
+
* @param config Agent configuration from YAML file + CLI overrides
|
|
26
|
+
* @param configPath Path to the agent config file (used for agent ID derivation)
|
|
27
|
+
* @param isInteractiveCli Whether this is interactive CLI mode (affects logger defaults) - defaults to false
|
|
28
|
+
* @returns Enriched configuration with explicit per-agent paths
|
|
29
|
+
*/
|
|
30
|
+
export declare function enrichAgentConfig(config: AgentConfig, configPath?: string, isInteractiveCli?: boolean): AgentConfig;
|
|
31
|
+
//# sourceMappingURL=config-enrichment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-enrichment.d.ts","sourceRoot":"","sources":["../../src/config/config-enrichment.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAyB9E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,WAAW,EACnB,UAAU,CAAC,EAAE,MAAM,EACnB,gBAAgB,GAAE,OAAe,GAClC,WAAW,CAkFb"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { getDextoPath } from "../utils/path.js";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
function deriveAgentId(config, configPath) {
|
|
4
|
+
if (config.agentCard?.name) {
|
|
5
|
+
const sanitizedName = config.agentCard.name.toLowerCase().replace(/[^a-z0-9-_]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
6
|
+
if (sanitizedName) {
|
|
7
|
+
return sanitizedName;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
if (configPath) {
|
|
11
|
+
const basename = path.basename(configPath, path.extname(configPath));
|
|
12
|
+
if (basename && basename !== "agent" && basename !== "config") {
|
|
13
|
+
return basename;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return "default-agent";
|
|
17
|
+
}
|
|
18
|
+
function enrichAgentConfig(config, configPath, isInteractiveCli = false) {
|
|
19
|
+
const agentId = deriveAgentId(config, configPath);
|
|
20
|
+
const logPath = getDextoPath("logs", `${agentId}.log`);
|
|
21
|
+
const dbPath = getDextoPath("database", `${agentId}.db`);
|
|
22
|
+
const blobPath = getDextoPath("blobs", agentId);
|
|
23
|
+
const enriched = {
|
|
24
|
+
...config,
|
|
25
|
+
agentId
|
|
26
|
+
// Set agentId explicitly (single source of truth)
|
|
27
|
+
};
|
|
28
|
+
if (!config.logger) {
|
|
29
|
+
const transports = isInteractiveCli ? [
|
|
30
|
+
{
|
|
31
|
+
type: "file",
|
|
32
|
+
path: logPath,
|
|
33
|
+
maxSize: 10 * 1024 * 1024,
|
|
34
|
+
// 10MB
|
|
35
|
+
maxFiles: 5
|
|
36
|
+
}
|
|
37
|
+
] : [
|
|
38
|
+
{ type: "console", colorize: true },
|
|
39
|
+
{
|
|
40
|
+
type: "file",
|
|
41
|
+
path: logPath,
|
|
42
|
+
maxSize: 10 * 1024 * 1024,
|
|
43
|
+
// 10MB
|
|
44
|
+
maxFiles: 5
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
enriched.logger = {
|
|
48
|
+
level: "info",
|
|
49
|
+
transports
|
|
50
|
+
};
|
|
51
|
+
} else {
|
|
52
|
+
enriched.logger = config.logger;
|
|
53
|
+
}
|
|
54
|
+
if (!config.storage) {
|
|
55
|
+
enriched.storage = {
|
|
56
|
+
cache: { type: "in-memory" },
|
|
57
|
+
database: { type: "sqlite", path: dbPath },
|
|
58
|
+
blob: { type: "local", storePath: blobPath }
|
|
59
|
+
};
|
|
60
|
+
} else {
|
|
61
|
+
enriched.storage = {
|
|
62
|
+
...config.storage
|
|
63
|
+
};
|
|
64
|
+
if (config.storage.database?.type === "sqlite") {
|
|
65
|
+
enriched.storage.database = {
|
|
66
|
+
...config.storage.database,
|
|
67
|
+
path: config.storage.database.path || dbPath
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (config.storage.blob?.type === "local") {
|
|
71
|
+
enriched.storage.blob = {
|
|
72
|
+
...config.storage.blob,
|
|
73
|
+
storePath: config.storage.blob.storePath || blobPath
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return enriched;
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
deriveAgentId,
|
|
81
|
+
enrichAgentConfig
|
|
82
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
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 config_manager_exports = {};
|
|
20
|
+
__export(config_manager_exports, {
|
|
21
|
+
reloadAgentConfigFromFile: () => reloadAgentConfigFromFile,
|
|
22
|
+
updateAgentConfigFile: () => updateAgentConfigFile
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(config_manager_exports);
|
|
25
|
+
var import_fs = require("fs");
|
|
26
|
+
var import_yaml = require("yaml");
|
|
27
|
+
var import_loader = require("./loader.js");
|
|
28
|
+
var import_core = require("@dexto/core");
|
|
29
|
+
var import_core2 = require("@dexto/core");
|
|
30
|
+
var import_core3 = require("@dexto/core");
|
|
31
|
+
async function updateAgentConfigFile(configPath, updates) {
|
|
32
|
+
const rawYaml = await import_fs.promises.readFile(configPath, "utf-8");
|
|
33
|
+
const doc = (0, import_yaml.parseDocument)(rawYaml);
|
|
34
|
+
const rawConfig = doc.toJSON();
|
|
35
|
+
const updatedRawConfig = { ...rawConfig, ...updates };
|
|
36
|
+
const parsed = import_core.AgentConfigSchema.safeParse(updatedRawConfig);
|
|
37
|
+
if (!parsed.success) {
|
|
38
|
+
const result = (0, import_core3.fail)((0, import_core3.zodToIssues)(parsed.error, "error"));
|
|
39
|
+
throw new import_core2.DextoValidationError(result.issues);
|
|
40
|
+
}
|
|
41
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
42
|
+
doc.set(key, value);
|
|
43
|
+
}
|
|
44
|
+
const yamlContent = String(doc);
|
|
45
|
+
const tmpPath = `${configPath}.tmp`;
|
|
46
|
+
await import_fs.promises.writeFile(tmpPath, yamlContent, "utf-8");
|
|
47
|
+
await import_fs.promises.rename(tmpPath, configPath);
|
|
48
|
+
return parsed.data;
|
|
49
|
+
}
|
|
50
|
+
async function reloadAgentConfigFromFile(configPath) {
|
|
51
|
+
return await (0, import_loader.loadAgentConfig)(configPath);
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
reloadAgentConfigFromFile,
|
|
56
|
+
updateAgentConfigFile
|
|
57
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { AgentConfig, ValidatedAgentConfig } from '@dexto/core';
|
|
2
|
+
/**
|
|
3
|
+
* Updates an agent configuration file with partial updates.
|
|
4
|
+
* Reads raw YAML, merges updates, validates, and writes back atomically.
|
|
5
|
+
* Preserves comments, formatting, and environment variable placeholders.
|
|
6
|
+
*
|
|
7
|
+
* This is a CLI/server concern - handles file I/O for config updates.
|
|
8
|
+
* After calling this, you should call agent.reloadConfig() with the returned config.
|
|
9
|
+
*
|
|
10
|
+
* @param configPath Path to the agent configuration file
|
|
11
|
+
* @param updates Partial configuration updates to apply
|
|
12
|
+
* @returns The validated merged configuration
|
|
13
|
+
* @throws DextoValidationError if validation fails
|
|
14
|
+
* @throws Error if file operations fail
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const newConfig = await updateAgentConfigFile('/path/to/agent.yml', {
|
|
19
|
+
* mcpServers: {
|
|
20
|
+
* ...currentConfig.mcpServers,
|
|
21
|
+
* newServer: { command: 'mcp-server', type: 'stdio' }
|
|
22
|
+
* }
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* const reloadResult = await agent.reloadConfig(newConfig);
|
|
26
|
+
* if (reloadResult.restartRequired.length > 0) {
|
|
27
|
+
* await agent.restart();
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function updateAgentConfigFile(configPath: string, updates: Partial<AgentConfig>): Promise<ValidatedAgentConfig>;
|
|
32
|
+
/**
|
|
33
|
+
* Reloads an agent configuration from disk.
|
|
34
|
+
* This is a CLI/server concern - handles file I/O for config loading.
|
|
35
|
+
* After calling this, you should call agent.reloadConfig() with the returned config.
|
|
36
|
+
*
|
|
37
|
+
* @param configPath Path to the agent configuration file
|
|
38
|
+
* @returns The loaded agent configuration
|
|
39
|
+
* @throws ConfigError if file cannot be read or parsed
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const newConfig = await reloadAgentConfigFromFile('/path/to/agent.yml');
|
|
44
|
+
* const reloadResult = await agent.reloadConfig(newConfig);
|
|
45
|
+
* if (reloadResult.restartRequired.length > 0) {
|
|
46
|
+
* await agent.restart();
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function reloadAgentConfigFromFile(configPath: string): Promise<AgentConfig>;
|
|
51
|
+
//# sourceMappingURL=config-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-manager.d.ts","sourceRoot":"","sources":["../../src/config/config-manager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAKrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,qBAAqB,CACvC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAC9B,OAAO,CAAC,oBAAoB,CAAC,CAiC/B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAExF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { promises as fs } from "fs";
|
|
2
|
+
import { parseDocument } from "yaml";
|
|
3
|
+
import { loadAgentConfig } from "./loader.js";
|
|
4
|
+
import { AgentConfigSchema } from "@dexto/core";
|
|
5
|
+
import { DextoValidationError } from "@dexto/core";
|
|
6
|
+
import { fail, zodToIssues } from "@dexto/core";
|
|
7
|
+
async function updateAgentConfigFile(configPath, updates) {
|
|
8
|
+
const rawYaml = await fs.readFile(configPath, "utf-8");
|
|
9
|
+
const doc = parseDocument(rawYaml);
|
|
10
|
+
const rawConfig = doc.toJSON();
|
|
11
|
+
const updatedRawConfig = { ...rawConfig, ...updates };
|
|
12
|
+
const parsed = AgentConfigSchema.safeParse(updatedRawConfig);
|
|
13
|
+
if (!parsed.success) {
|
|
14
|
+
const result = fail(zodToIssues(parsed.error, "error"));
|
|
15
|
+
throw new DextoValidationError(result.issues);
|
|
16
|
+
}
|
|
17
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
18
|
+
doc.set(key, value);
|
|
19
|
+
}
|
|
20
|
+
const yamlContent = String(doc);
|
|
21
|
+
const tmpPath = `${configPath}.tmp`;
|
|
22
|
+
await fs.writeFile(tmpPath, yamlContent, "utf-8");
|
|
23
|
+
await fs.rename(tmpPath, configPath);
|
|
24
|
+
return parsed.data;
|
|
25
|
+
}
|
|
26
|
+
async function reloadAgentConfigFromFile(configPath) {
|
|
27
|
+
return await loadAgentConfig(configPath);
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
reloadAgentConfigFromFile,
|
|
31
|
+
updateAgentConfigFile
|
|
32
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
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 error_codes_exports = {};
|
|
20
|
+
__export(error_codes_exports, {
|
|
21
|
+
ConfigErrorCode: () => ConfigErrorCode
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(error_codes_exports);
|
|
24
|
+
var ConfigErrorCode = /* @__PURE__ */ ((ConfigErrorCode2) => {
|
|
25
|
+
ConfigErrorCode2["FILE_NOT_FOUND"] = "config_file_not_found";
|
|
26
|
+
ConfigErrorCode2["FILE_READ_ERROR"] = "config_file_read_error";
|
|
27
|
+
ConfigErrorCode2["FILE_WRITE_ERROR"] = "config_file_write_error";
|
|
28
|
+
ConfigErrorCode2["PARSE_ERROR"] = "config_parse_error";
|
|
29
|
+
ConfigErrorCode2["NO_PROJECT_DEFAULT"] = "config_no_project_default";
|
|
30
|
+
ConfigErrorCode2["NO_GLOBAL_PREFERENCES"] = "config_no_global_preferences";
|
|
31
|
+
ConfigErrorCode2["SETUP_INCOMPLETE"] = "config_setup_incomplete";
|
|
32
|
+
ConfigErrorCode2["BUNDLED_NOT_FOUND"] = "config_bundled_not_found";
|
|
33
|
+
ConfigErrorCode2["UNKNOWN_CONTEXT"] = "config_unknown_context";
|
|
34
|
+
return ConfigErrorCode2;
|
|
35
|
+
})(ConfigErrorCode || {});
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
ConfigErrorCode
|
|
39
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config-specific error codes
|
|
3
|
+
* Includes file operations, parsing, and validation errors for configuration management
|
|
4
|
+
*/
|
|
5
|
+
export declare enum ConfigErrorCode {
|
|
6
|
+
FILE_NOT_FOUND = "config_file_not_found",
|
|
7
|
+
FILE_READ_ERROR = "config_file_read_error",
|
|
8
|
+
FILE_WRITE_ERROR = "config_file_write_error",
|
|
9
|
+
PARSE_ERROR = "config_parse_error",
|
|
10
|
+
NO_PROJECT_DEFAULT = "config_no_project_default",
|
|
11
|
+
NO_GLOBAL_PREFERENCES = "config_no_global_preferences",
|
|
12
|
+
SETUP_INCOMPLETE = "config_setup_incomplete",
|
|
13
|
+
BUNDLED_NOT_FOUND = "config_bundled_not_found",
|
|
14
|
+
UNKNOWN_CONTEXT = "config_unknown_context"
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=error-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../src/config/error-codes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,eAAe;IAEvB,cAAc,0BAA0B;IACxC,eAAe,2BAA2B;IAC1C,gBAAgB,4BAA4B;IAG5C,WAAW,uBAAuB;IAGlC,kBAAkB,8BAA8B;IAChD,qBAAqB,iCAAiC;IACtD,gBAAgB,4BAA4B;IAC5C,iBAAiB,6BAA6B;IAC9C,eAAe,2BAA2B;CAC7C"}
|