@dexto/agent-management 1.2.6 → 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 (53) 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/dist/writer.cjs +15 -13
  47. package/dist/writer.d.ts.map +1 -1
  48. package/dist/writer.js +16 -14
  49. package/package.json +2 -2
  50. package/dist/AgentOrchestrator.cjs +0 -263
  51. package/dist/AgentOrchestrator.d.ts +0 -191
  52. package/dist/AgentOrchestrator.d.ts.map +0 -1
  53. 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/dist/writer.cjs CHANGED
@@ -70,9 +70,13 @@ async function writeLLMPreferences(configPath, preferences, overrides) {
70
70
  error instanceof Error ? error.message : String(error)
71
71
  );
72
72
  }
73
- let config;
73
+ let doc;
74
74
  try {
75
- config = (0, import_yaml.parse)(fileContent);
75
+ doc = (0, import_yaml.parseDocument)(fileContent);
76
+ if (doc.errors && doc.errors.length > 0) {
77
+ throw new Error(doc.errors.map((e) => e.message).join("; "));
78
+ }
79
+ const config = doc.toJS();
76
80
  import_core.logger.debug(`Successfully parsed YAML config`, {
77
81
  hasLlmSection: Boolean(config.llm),
78
82
  existingProvider: config.llm?.provider,
@@ -94,17 +98,15 @@ async function writeLLMPreferences(configPath, preferences, overrides) {
94
98
  hasApiKey: Boolean(apiKey),
95
99
  source: overrides ? "CLI overrides + preferences" : "preferences only"
96
100
  });
97
- config.llm = {
98
- ...config.llm,
99
- // Preserve temperature, router, maxTokens, etc.
100
- provider,
101
- // Write user preference
102
- model,
103
- // Write user preference
104
- apiKey
105
- // Write user preference
106
- };
107
- await writeConfigFile(configPath, config);
101
+ let llmNode = doc.get("llm");
102
+ if (!llmNode || typeof llmNode !== "object") {
103
+ doc.set("llm", { provider, model, apiKey });
104
+ } else {
105
+ doc.setIn(["llm", "provider"], provider);
106
+ doc.setIn(["llm", "model"], model);
107
+ doc.setIn(["llm", "apiKey"], apiKey);
108
+ }
109
+ await import_fs.promises.writeFile(configPath, doc.toString(), "utf-8");
108
110
  import_core.logger.info(`\u2713 Applied preferences to: ${path.basename(configPath)} (${provider}/${model})`);
109
111
  }
110
112
  async function writePreferencesToAgent(installedPath, preferences, overrides) {
@@ -1 +1 @@
1
- {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAIlE,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB5F;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACrC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,CAAC,EAAE,YAAY,GACzB,OAAO,CAAC,IAAI,CAAC,CAiEf;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CACzC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,CAAC,EAAE,YAAY,GACzB,OAAO,CAAC,IAAI,CAAC,CAyBf"}
1
+ {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAIlE,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB5F;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACrC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,CAAC,EAAE,YAAY,GACzB,OAAO,CAAC,IAAI,CAAC,CAwEf;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CACzC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,CAAC,EAAE,YAAY,GACzB,OAAO,CAAC,IAAI,CAAC,CAyBf"}
package/dist/writer.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { promises as fs } from "fs";
2
- import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
2
+ import { parseDocument, stringify as stringifyYaml } from "yaml";
3
3
  import * as path from "path";
4
4
  import { logger } from "@dexto/core";
5
5
  import { ConfigError } from "./config/index.js";
@@ -35,9 +35,13 @@ async function writeLLMPreferences(configPath, preferences, overrides) {
35
35
  error instanceof Error ? error.message : String(error)
36
36
  );
37
37
  }
38
- let config;
38
+ let doc;
39
39
  try {
40
- config = parseYaml(fileContent);
40
+ doc = parseDocument(fileContent);
41
+ if (doc.errors && doc.errors.length > 0) {
42
+ throw new Error(doc.errors.map((e) => e.message).join("; "));
43
+ }
44
+ const config = doc.toJS();
41
45
  logger.debug(`Successfully parsed YAML config`, {
42
46
  hasLlmSection: Boolean(config.llm),
43
47
  existingProvider: config.llm?.provider,
@@ -59,17 +63,15 @@ async function writeLLMPreferences(configPath, preferences, overrides) {
59
63
  hasApiKey: Boolean(apiKey),
60
64
  source: overrides ? "CLI overrides + preferences" : "preferences only"
61
65
  });
62
- config.llm = {
63
- ...config.llm,
64
- // Preserve temperature, router, maxTokens, etc.
65
- provider,
66
- // Write user preference
67
- model,
68
- // Write user preference
69
- apiKey
70
- // Write user preference
71
- };
72
- await writeConfigFile(configPath, config);
66
+ let llmNode = doc.get("llm");
67
+ if (!llmNode || typeof llmNode !== "object") {
68
+ doc.set("llm", { provider, model, apiKey });
69
+ } else {
70
+ doc.setIn(["llm", "provider"], provider);
71
+ doc.setIn(["llm", "model"], model);
72
+ doc.setIn(["llm", "apiKey"], apiKey);
73
+ }
74
+ await fs.writeFile(configPath, doc.toString(), "utf-8");
73
75
  logger.info(`\u2713 Applied preferences to: ${path.basename(configPath)} (${provider}/${model})`);
74
76
  }
75
77
  async function writePreferencesToAgent(installedPath, preferences, overrides) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexto/agent-management",
3
- "version": "1.2.6",
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.2.6"
19
+ "@dexto/core": "1.4.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.13.5"