@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,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,16 +17,31 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var config_manager_exports = {};
20
30
  __export(config_manager_exports, {
31
+ addPromptToAgentConfig: () => addPromptToAgentConfig,
32
+ deletePromptByMetadata: () => deletePromptByMetadata,
21
33
  reloadAgentConfigFromFile: () => reloadAgentConfigFromFile,
22
- updateAgentConfigFile: () => updateAgentConfigFile
34
+ removeMcpServerFromConfig: () => removeMcpServerFromConfig,
35
+ removePromptFromAgentConfig: () => removePromptFromAgentConfig,
36
+ updateAgentConfigFile: () => updateAgentConfigFile,
37
+ updateMcpServerField: () => updateMcpServerField
23
38
  });
24
39
  module.exports = __toCommonJS(config_manager_exports);
25
40
  var import_fs = require("fs");
41
+ var path = __toESM(require("path"), 1);
26
42
  var import_yaml = require("yaml");
27
43
  var import_loader = require("./loader.js");
44
+ var import_config_enrichment = require("./config-enrichment.js");
28
45
  var import_core = require("@dexto/core");
29
46
  var import_core2 = require("@dexto/core");
30
47
  var import_core3 = require("@dexto/core");
@@ -33,7 +50,8 @@ async function updateAgentConfigFile(configPath, updates) {
33
50
  const doc = (0, import_yaml.parseDocument)(rawYaml);
34
51
  const rawConfig = doc.toJSON();
35
52
  const updatedRawConfig = { ...rawConfig, ...updates };
36
- const parsed = import_core.AgentConfigSchema.safeParse(updatedRawConfig);
53
+ const enrichedConfig = (0, import_config_enrichment.enrichAgentConfig)(updatedRawConfig, configPath);
54
+ const parsed = import_core.AgentConfigSchema.safeParse(enrichedConfig);
37
55
  if (!parsed.success) {
38
56
  const result = (0, import_core3.fail)((0, import_core3.zodToIssues)(parsed.error, "error"));
39
57
  throw new import_core2.DextoValidationError(result.issues);
@@ -50,8 +68,327 @@ async function updateAgentConfigFile(configPath, updates) {
50
68
  async function reloadAgentConfigFromFile(configPath) {
51
69
  return await (0, import_loader.loadAgentConfig)(configPath);
52
70
  }
71
+ async function writeFileAtomic(configPath, content) {
72
+ const tmpPath = `${configPath}.tmp`;
73
+ await import_fs.promises.writeFile(tmpPath, content, "utf-8");
74
+ await import_fs.promises.rename(tmpPath, configPath);
75
+ }
76
+ function findMcpServerRange(lines, serverName) {
77
+ let inMcpServersSection = false;
78
+ let mcpServersIndent = "";
79
+ let serverLevelIndent = -1;
80
+ let serverIndent = "";
81
+ let inTargetServer = false;
82
+ let serverStartLine = -1;
83
+ let serverEndLine = -1;
84
+ for (let i = 0; i < lines.length; i++) {
85
+ const line = lines[i] ?? "";
86
+ const trimmed = line.trimStart();
87
+ if (!trimmed || trimmed.startsWith("#")) {
88
+ if (inTargetServer && serverStartLine >= 0) {
89
+ }
90
+ continue;
91
+ }
92
+ const currentIndent = line.slice(0, line.length - trimmed.length);
93
+ const currentIndentLen = currentIndent.length;
94
+ if (!inMcpServersSection && trimmed.startsWith("mcpServers:")) {
95
+ inMcpServersSection = true;
96
+ mcpServersIndent = currentIndent;
97
+ continue;
98
+ }
99
+ if (inMcpServersSection) {
100
+ if (currentIndentLen <= mcpServersIndent.length && trimmed.includes(":")) {
101
+ if (inTargetServer && serverStartLine >= 0) {
102
+ return {
103
+ startLine: serverStartLine,
104
+ endLine: serverEndLine >= 0 ? serverEndLine : serverStartLine,
105
+ indent: serverIndent
106
+ };
107
+ }
108
+ return null;
109
+ }
110
+ if (serverLevelIndent < 0 && currentIndentLen > mcpServersIndent.length) {
111
+ serverLevelIndent = currentIndentLen;
112
+ }
113
+ if (serverLevelIndent >= 0 && currentIndentLen === serverLevelIndent) {
114
+ const serverMatch = trimmed.match(/^([a-zA-Z0-9_-]+):(\s|$)/);
115
+ if (serverMatch) {
116
+ const foundServerName = serverMatch[1];
117
+ if (inTargetServer && serverStartLine >= 0) {
118
+ return {
119
+ startLine: serverStartLine,
120
+ endLine: serverEndLine >= 0 ? serverEndLine : serverStartLine,
121
+ indent: serverIndent
122
+ };
123
+ }
124
+ if (foundServerName === serverName) {
125
+ inTargetServer = true;
126
+ serverStartLine = i;
127
+ serverEndLine = i;
128
+ serverIndent = currentIndent;
129
+ } else {
130
+ inTargetServer = false;
131
+ }
132
+ }
133
+ } else if (inTargetServer && currentIndentLen > serverLevelIndent) {
134
+ serverEndLine = i;
135
+ }
136
+ }
137
+ }
138
+ if (inTargetServer && serverStartLine >= 0) {
139
+ return {
140
+ startLine: serverStartLine,
141
+ endLine: serverEndLine >= 0 ? serverEndLine : serverStartLine,
142
+ indent: serverIndent
143
+ };
144
+ }
145
+ return null;
146
+ }
147
+ async function updateMcpServerField(configPath, serverName, field, value) {
148
+ const rawYaml = await import_fs.promises.readFile(configPath, "utf-8");
149
+ const lines = rawYaml.split("\n");
150
+ const serverRange = findMcpServerRange(lines, serverName);
151
+ if (!serverRange) {
152
+ return false;
153
+ }
154
+ const formattedValue = typeof value === "string" ? value.includes(":") ? `"${value}"` : value : String(value);
155
+ const fieldIndent = serverRange.indent + " ";
156
+ const fieldPrefix = `${fieldIndent}${field}:`;
157
+ let fieldLineIndex = -1;
158
+ for (let i = serverRange.startLine + 1; i <= serverRange.endLine; i++) {
159
+ const line = lines[i] ?? "";
160
+ if (line.startsWith(fieldPrefix)) {
161
+ fieldLineIndex = i;
162
+ break;
163
+ }
164
+ }
165
+ if (fieldLineIndex >= 0) {
166
+ lines[fieldLineIndex] = `${fieldIndent}${field}: ${formattedValue}`;
167
+ } else {
168
+ const newFieldLine = `${fieldIndent}${field}: ${formattedValue}`;
169
+ lines.splice(serverRange.startLine + 1, 0, newFieldLine);
170
+ }
171
+ await writeFileAtomic(configPath, lines.join("\n"));
172
+ return true;
173
+ }
174
+ async function removeMcpServerFromConfig(configPath, serverName) {
175
+ const rawYaml = await import_fs.promises.readFile(configPath, "utf-8");
176
+ const lines = rawYaml.split("\n");
177
+ const serverRange = findMcpServerRange(lines, serverName);
178
+ if (!serverRange) {
179
+ return false;
180
+ }
181
+ lines.splice(serverRange.startLine, serverRange.endLine - serverRange.startLine + 1);
182
+ await writeFileAtomic(configPath, lines.join("\n"));
183
+ return true;
184
+ }
185
+ function findPromptsArrayEndPosition(lines) {
186
+ let inPromptsSection = false;
187
+ let promptsIndent = "";
188
+ let lastPromptEntryEnd = -1;
189
+ let itemIndent = "";
190
+ for (let i = 0; i < lines.length; i++) {
191
+ const line = lines[i] ?? "";
192
+ const trimmed = line.trimStart();
193
+ if (trimmed.startsWith("prompts:")) {
194
+ inPromptsSection = true;
195
+ const idx = line.indexOf("prompts:");
196
+ promptsIndent = idx >= 0 ? line.slice(0, idx) : "";
197
+ continue;
198
+ }
199
+ if (inPromptsSection) {
200
+ if (trimmed && !trimmed.startsWith("#") && !trimmed.startsWith("-")) {
201
+ const currentIndent = line.slice(0, line.length - trimmed.length);
202
+ if (currentIndent.length <= promptsIndent.length && trimmed.includes(":")) {
203
+ return { insertIndex: lastPromptEntryEnd + 1, indent: itemIndent };
204
+ }
205
+ }
206
+ if (trimmed.startsWith("- ")) {
207
+ const dashIdx = line.indexOf("-");
208
+ itemIndent = dashIdx >= 0 ? line.slice(0, dashIdx) : "";
209
+ lastPromptEntryEnd = i;
210
+ } else if (lastPromptEntryEnd >= 0 && trimmed && !trimmed.startsWith("#")) {
211
+ lastPromptEntryEnd = i;
212
+ }
213
+ }
214
+ }
215
+ if (inPromptsSection && lastPromptEntryEnd >= 0) {
216
+ return { insertIndex: lastPromptEntryEnd + 1, indent: itemIndent };
217
+ }
218
+ return null;
219
+ }
220
+ async function addPromptToAgentConfig(configPath, prompt) {
221
+ const rawYaml = await import_fs.promises.readFile(configPath, "utf-8");
222
+ const lines = rawYaml.split("\n");
223
+ const position = findPromptsArrayEndPosition(lines);
224
+ if (position) {
225
+ const promptYaml = (0, import_yaml.stringify)([prompt], { indent: 2, lineWidth: 0 }).trim();
226
+ const indentedPrompt = promptYaml.split("\n").map((line) => position.indent + line).join("\n");
227
+ lines.splice(position.insertIndex, 0, indentedPrompt);
228
+ } else {
229
+ const promptYaml = (0, import_yaml.stringify)({ prompts: [prompt] }, { indent: 2, lineWidth: 0 }).trim();
230
+ lines.push("", promptYaml);
231
+ }
232
+ await writeFileAtomic(configPath, lines.join("\n"));
233
+ }
234
+ function findPromptEntryRanges(lines) {
235
+ const entries = [];
236
+ let inPromptsSection = false;
237
+ let promptsIndent = "";
238
+ let currentEntryStart = -1;
239
+ let currentEntryEnd = -1;
240
+ let itemIndent = "";
241
+ for (let i = 0; i < lines.length; i++) {
242
+ const line = lines[i] ?? "";
243
+ const trimmed = line.trimStart();
244
+ if (!inPromptsSection && trimmed.startsWith("prompts:")) {
245
+ inPromptsSection = true;
246
+ const idx = line.indexOf("prompts:");
247
+ promptsIndent = idx >= 0 ? line.slice(0, idx) : "";
248
+ continue;
249
+ }
250
+ if (inPromptsSection) {
251
+ if (trimmed && !trimmed.startsWith("-")) {
252
+ const currentIndent = line.slice(0, line.length - trimmed.length);
253
+ if (currentIndent.length <= promptsIndent.length && trimmed.includes(":")) {
254
+ if (currentEntryStart >= 0) {
255
+ entries.push({
256
+ startLine: currentEntryStart,
257
+ endLine: currentEntryEnd >= 0 ? currentEntryEnd : currentEntryStart,
258
+ content: lines.slice(
259
+ currentEntryStart,
260
+ (currentEntryEnd >= 0 ? currentEntryEnd : currentEntryStart) + 1
261
+ ).join("\n")
262
+ });
263
+ }
264
+ inPromptsSection = false;
265
+ break;
266
+ }
267
+ if (trimmed.startsWith("#") && currentIndent.length <= promptsIndent.length) {
268
+ if (currentEntryStart >= 0) {
269
+ entries.push({
270
+ startLine: currentEntryStart,
271
+ endLine: currentEntryEnd >= 0 ? currentEntryEnd : currentEntryStart,
272
+ content: lines.slice(
273
+ currentEntryStart,
274
+ (currentEntryEnd >= 0 ? currentEntryEnd : currentEntryStart) + 1
275
+ ).join("\n")
276
+ });
277
+ }
278
+ inPromptsSection = false;
279
+ break;
280
+ }
281
+ }
282
+ if (trimmed.startsWith("- ")) {
283
+ if (currentEntryStart >= 0) {
284
+ entries.push({
285
+ startLine: currentEntryStart,
286
+ endLine: currentEntryEnd >= 0 ? currentEntryEnd : currentEntryStart,
287
+ content: lines.slice(
288
+ currentEntryStart,
289
+ (currentEntryEnd >= 0 ? currentEntryEnd : currentEntryStart) + 1
290
+ ).join("\n")
291
+ });
292
+ }
293
+ currentEntryStart = i;
294
+ currentEntryEnd = i;
295
+ const dashIdx = line.indexOf("-");
296
+ itemIndent = dashIdx >= 0 ? line.slice(0, dashIdx) : "";
297
+ } else if (currentEntryStart >= 0 && trimmed) {
298
+ const lineIndent = line.slice(0, line.length - trimmed.length);
299
+ if (lineIndent.length > itemIndent.length) {
300
+ currentEntryEnd = i;
301
+ }
302
+ }
303
+ }
304
+ }
305
+ if (inPromptsSection && currentEntryStart >= 0) {
306
+ entries.push({
307
+ startLine: currentEntryStart,
308
+ endLine: currentEntryEnd >= 0 ? currentEntryEnd : currentEntryStart,
309
+ content: lines.slice(
310
+ currentEntryStart,
311
+ (currentEntryEnd >= 0 ? currentEntryEnd : currentEntryStart) + 1
312
+ ).join("\n")
313
+ });
314
+ }
315
+ return entries;
316
+ }
317
+ async function removePromptFromAgentConfig(configPath, matcher) {
318
+ const rawYaml = await import_fs.promises.readFile(configPath, "utf-8");
319
+ const lines = rawYaml.split("\n");
320
+ const entries = findPromptEntryRanges(lines);
321
+ if (entries.length === 0) {
322
+ return;
323
+ }
324
+ const entriesToRemove = [];
325
+ for (const entry of entries) {
326
+ if (matcher.type === "file") {
327
+ if (entry.content.includes("type: file") && entry.content.includes(matcher.filePattern)) {
328
+ entriesToRemove.push(entry);
329
+ }
330
+ } else if (matcher.type === "inline") {
331
+ if (entry.content.includes("type: inline") && entry.content.includes(`id: ${matcher.id}`)) {
332
+ entriesToRemove.push(entry);
333
+ }
334
+ }
335
+ }
336
+ if (entriesToRemove.length === 0) {
337
+ return;
338
+ }
339
+ const sortedEntries = [...entriesToRemove].sort((a, b) => b.startLine - a.startLine);
340
+ for (const entry of sortedEntries) {
341
+ lines.splice(entry.startLine, entry.endLine - entry.startLine + 1);
342
+ }
343
+ await writeFileAtomic(configPath, lines.join("\n"));
344
+ }
345
+ async function deletePromptByMetadata(configPath, prompt, options = { deleteFile: true }) {
346
+ const result = {
347
+ success: false,
348
+ deletedFile: false,
349
+ removedFromConfig: false
350
+ };
351
+ const filePath = prompt.metadata?.filePath;
352
+ try {
353
+ if (filePath) {
354
+ const fileName = path.basename(filePath);
355
+ const isSharedPrompt = filePath.includes("/commands/") || filePath.includes("/.dexto/commands/");
356
+ if (!isSharedPrompt) {
357
+ await removePromptFromAgentConfig(configPath, {
358
+ type: "file",
359
+ filePattern: `/prompts/${fileName}`
360
+ });
361
+ result.removedFromConfig = true;
362
+ }
363
+ if (options.deleteFile) {
364
+ try {
365
+ await import_fs.promises.unlink(filePath);
366
+ result.deletedFile = true;
367
+ } catch {
368
+ }
369
+ }
370
+ result.success = true;
371
+ } else {
372
+ const promptId = prompt.metadata?.originalId || prompt.name;
373
+ await removePromptFromAgentConfig(configPath, {
374
+ type: "inline",
375
+ id: promptId
376
+ });
377
+ result.removedFromConfig = true;
378
+ result.success = true;
379
+ }
380
+ } catch (err) {
381
+ result.error = err instanceof Error ? err.message : String(err);
382
+ }
383
+ return result;
384
+ }
53
385
  // Annotate the CommonJS export names for ESM import in node:
54
386
  0 && (module.exports = {
387
+ addPromptToAgentConfig,
388
+ deletePromptByMetadata,
55
389
  reloadAgentConfigFromFile,
56
- updateAgentConfigFile
390
+ removeMcpServerFromConfig,
391
+ removePromptFromAgentConfig,
392
+ updateAgentConfigFile,
393
+ updateMcpServerField
57
394
  });
@@ -1,15 +1,40 @@
1
1
  import type { AgentConfig, ValidatedAgentConfig } from '@dexto/core';
2
+ /**
3
+ * Input type for adding a file-based prompt
4
+ */
5
+ export interface FilePromptInput {
6
+ type: 'file';
7
+ file: string;
8
+ showInStarters?: boolean;
9
+ }
10
+ /**
11
+ * Input type for adding an inline prompt
12
+ */
13
+ export interface InlinePromptInput {
14
+ type: 'inline';
15
+ id: string;
16
+ prompt: string;
17
+ title?: string;
18
+ description?: string;
19
+ category?: string;
20
+ priority?: number;
21
+ showInStarters?: boolean;
22
+ }
23
+ export type PromptInput = FilePromptInput | InlinePromptInput;
2
24
  /**
3
25
  * Updates an agent configuration file with partial updates.
4
- * Reads raw YAML, merges updates, validates, and writes back atomically.
26
+ * Reads raw YAML, merges updates, enriches for validation, and writes back atomically.
5
27
  * Preserves comments, formatting, and environment variable placeholders.
6
28
  *
29
+ * Note: The file is kept "raw" (no enriched paths written), but the returned config
30
+ * is enriched and validated so it can be passed directly to agent.reload().
31
+ *
7
32
  * 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.
33
+ * After calling this, you should call agent.reload() with the returned config.
9
34
  *
10
35
  * @param configPath Path to the agent configuration file
11
36
  * @param updates Partial configuration updates to apply
12
- * @returns The validated merged configuration
37
+ * @returns The validated, enriched merged configuration (ready for agent.reload())
13
38
  * @throws DextoValidationError if validation fails
14
39
  * @throws Error if file operations fail
15
40
  *
@@ -22,10 +47,7 @@ import type { AgentConfig, ValidatedAgentConfig } from '@dexto/core';
22
47
  * }
23
48
  * });
24
49
  *
25
- * const reloadResult = await agent.reloadConfig(newConfig);
26
- * if (reloadResult.restartRequired.length > 0) {
27
- * await agent.restart();
28
- * }
50
+ * const reloadResult = await agent.reload(newConfig);
29
51
  * ```
30
52
  */
31
53
  export declare function updateAgentConfigFile(configPath: string, updates: Partial<AgentConfig>): Promise<ValidatedAgentConfig>;
@@ -48,4 +70,133 @@ export declare function updateAgentConfigFile(configPath: string, updates: Parti
48
70
  * ```
49
71
  */
50
72
  export declare function reloadAgentConfigFromFile(configPath: string): Promise<AgentConfig>;
73
+ /**
74
+ * Updates a specific field within an MCP server configuration.
75
+ * Uses string manipulation to preserve all formatting, comments, and structure.
76
+ *
77
+ * @param configPath Path to the agent configuration file
78
+ * @param serverName Name of the MCP server to update
79
+ * @param field Field name to update (e.g., 'enabled')
80
+ * @param value New value for the field
81
+ * @returns true if the field was updated, false if server not found
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * // Toggle enabled state
86
+ * await updateMcpServerField('/path/to/agent.yml', 'filesystem', 'enabled', true);
87
+ * ```
88
+ */
89
+ export declare function updateMcpServerField(configPath: string, serverName: string, field: string, value: boolean | string | number): Promise<boolean>;
90
+ /**
91
+ * Removes an MCP server from the agent configuration file.
92
+ * Uses string manipulation to preserve all formatting, comments, and structure.
93
+ *
94
+ * @param configPath Path to the agent configuration file
95
+ * @param serverName Name of the MCP server to remove
96
+ * @returns true if the server was removed, false if not found
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * await removeMcpServerFromConfig('/path/to/agent.yml', 'filesystem');
101
+ * ```
102
+ */
103
+ export declare function removeMcpServerFromConfig(configPath: string, serverName: string): Promise<boolean>;
104
+ /**
105
+ * Adds a prompt to the agent configuration file.
106
+ * Uses string manipulation to preserve all formatting, comments, and structure.
107
+ * Only modifies the prompts array by appending a new entry.
108
+ *
109
+ * @param configPath Path to the agent configuration file
110
+ * @param prompt The prompt to add (file or inline)
111
+ * @throws Error if file operations fail
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * // Add a file-based prompt
116
+ * await addPromptToAgentConfig('/path/to/agent.yml', {
117
+ * type: 'file',
118
+ * file: '${{dexto.agent_dir}}/prompts/my-prompt.md'
119
+ * });
120
+ * ```
121
+ */
122
+ export declare function addPromptToAgentConfig(configPath: string, prompt: PromptInput): Promise<void>;
123
+ /**
124
+ * Removes a prompt from the agent configuration file.
125
+ * Uses string manipulation to preserve all formatting, comments, and structure.
126
+ * Only removes the matching prompt entry lines.
127
+ *
128
+ * For file prompts: matches by file path pattern
129
+ * For inline prompts: matches by id
130
+ *
131
+ * @param configPath Path to the agent configuration file
132
+ * @param matcher Criteria to match prompts to remove
133
+ * @throws Error if file operations fail
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * // Remove by file path pattern
138
+ * await removePromptFromAgentConfig('/path/to/agent.yml', {
139
+ * type: 'file',
140
+ * filePattern: '/prompts/my-prompt.md'
141
+ * });
142
+ *
143
+ * // Remove by inline prompt id
144
+ * await removePromptFromAgentConfig('/path/to/agent.yml', {
145
+ * type: 'inline',
146
+ * id: 'quick-help'
147
+ * });
148
+ * ```
149
+ */
150
+ export declare function removePromptFromAgentConfig(configPath: string, matcher: {
151
+ type: 'file';
152
+ filePattern: string;
153
+ } | {
154
+ type: 'inline';
155
+ id: string;
156
+ }): Promise<void>;
157
+ /**
158
+ * Prompt metadata expected from core's PromptInfo
159
+ */
160
+ export interface PromptMetadataForDeletion {
161
+ name: string;
162
+ metadata?: {
163
+ filePath?: string | undefined;
164
+ originalId?: string | undefined;
165
+ };
166
+ }
167
+ /**
168
+ * Result of prompt deletion operation
169
+ */
170
+ export interface PromptDeletionResult {
171
+ success: boolean;
172
+ deletedFile: boolean;
173
+ removedFromConfig: boolean;
174
+ error?: string;
175
+ }
176
+ /**
177
+ * Higher-level function to delete a prompt using its metadata.
178
+ * Handles both file-based and inline prompts, including file deletion.
179
+ *
180
+ * @param configPath - Path to the agent config file
181
+ * @param prompt - Prompt metadata (name and optional filePath in metadata)
182
+ * @param options - Options for deletion behavior
183
+ * @returns Result indicating what was deleted
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // Delete a file-based prompt (deletes file and removes from config)
188
+ * await deletePromptByMetadata('/path/to/agent.yml', {
189
+ * name: 'test-prompt',
190
+ * metadata: { filePath: '/path/to/prompts/test-prompt.md' }
191
+ * });
192
+ *
193
+ * // Delete an inline prompt (only removes from config)
194
+ * await deletePromptByMetadata('/path/to/agent.yml', {
195
+ * name: 'quick-help'
196
+ * });
197
+ * ```
198
+ */
199
+ export declare function deletePromptByMetadata(configPath: string, prompt: PromptMetadataForDeletion, options?: {
200
+ deleteFile?: boolean;
201
+ }): Promise<PromptDeletionResult>;
51
202
  //# sourceMappingURL=config-manager.d.ts.map
@@ -1 +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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