@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.
Files changed (110) hide show
  1. package/LICENSE +44 -0
  2. package/dist/AgentOrchestrator.cjs +263 -0
  3. package/dist/AgentOrchestrator.d.ts +191 -0
  4. package/dist/AgentOrchestrator.d.ts.map +1 -0
  5. package/dist/AgentOrchestrator.js +239 -0
  6. package/dist/config/config-enrichment.cjs +117 -0
  7. package/dist/config/config-enrichment.d.ts +31 -0
  8. package/dist/config/config-enrichment.d.ts.map +1 -0
  9. package/dist/config/config-enrichment.js +82 -0
  10. package/dist/config/config-manager.cjs +57 -0
  11. package/dist/config/config-manager.d.ts +51 -0
  12. package/dist/config/config-manager.d.ts.map +1 -0
  13. package/dist/config/config-manager.js +32 -0
  14. package/dist/config/error-codes.cjs +39 -0
  15. package/dist/config/error-codes.d.ts +16 -0
  16. package/dist/config/error-codes.d.ts.map +1 -0
  17. package/dist/config/error-codes.js +15 -0
  18. package/dist/config/errors.cjs +125 -0
  19. package/dist/config/errors.d.ts +34 -0
  20. package/dist/config/errors.d.ts.map +1 -0
  21. package/dist/config/errors.js +101 -0
  22. package/dist/config/index.cjs +44 -0
  23. package/dist/config/index.d.ts +6 -0
  24. package/dist/config/index.d.ts.map +1 -0
  25. package/dist/config/index.js +14 -0
  26. package/dist/config/loader.cjs +118 -0
  27. package/dist/config/loader.d.ts +18 -0
  28. package/dist/config/loader.d.ts.map +1 -0
  29. package/dist/config/loader.js +84 -0
  30. package/dist/index.cjs +132 -0
  31. package/dist/index.d.ts +20 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +104 -0
  34. package/dist/preferences/constants.cjs +28 -0
  35. package/dist/preferences/constants.d.ts +2 -0
  36. package/dist/preferences/constants.d.ts.map +1 -0
  37. package/dist/preferences/constants.js +4 -0
  38. package/dist/preferences/error-codes.cjs +35 -0
  39. package/dist/preferences/error-codes.d.ts +8 -0
  40. package/dist/preferences/error-codes.d.ts.map +1 -0
  41. package/dist/preferences/error-codes.js +11 -0
  42. package/dist/preferences/errors.cjs +74 -0
  43. package/dist/preferences/errors.d.ts +18 -0
  44. package/dist/preferences/errors.d.ts.map +1 -0
  45. package/dist/preferences/errors.js +49 -0
  46. package/dist/preferences/index.cjs +55 -0
  47. package/dist/preferences/index.d.ts +6 -0
  48. package/dist/preferences/index.d.ts.map +1 -0
  49. package/dist/preferences/index.js +31 -0
  50. package/dist/preferences/loader.cjs +138 -0
  51. package/dist/preferences/loader.d.ts +50 -0
  52. package/dist/preferences/loader.d.ts.map +1 -0
  53. package/dist/preferences/loader.js +109 -0
  54. package/dist/preferences/schemas.cjs +75 -0
  55. package/dist/preferences/schemas.d.ts +110 -0
  56. package/dist/preferences/schemas.d.ts.map +1 -0
  57. package/dist/preferences/schemas.js +48 -0
  58. package/dist/registry/error-codes.cjs +44 -0
  59. package/dist/registry/error-codes.d.ts +21 -0
  60. package/dist/registry/error-codes.d.ts.map +1 -0
  61. package/dist/registry/error-codes.js +20 -0
  62. package/dist/registry/errors.cjs +187 -0
  63. package/dist/registry/errors.d.ts +63 -0
  64. package/dist/registry/errors.d.ts.map +1 -0
  65. package/dist/registry/errors.js +163 -0
  66. package/dist/registry/registry.cjs +479 -0
  67. package/dist/registry/registry.d.ts +130 -0
  68. package/dist/registry/registry.d.ts.map +1 -0
  69. package/dist/registry/registry.js +452 -0
  70. package/dist/registry/types.cjs +74 -0
  71. package/dist/registry/types.d.ts +142 -0
  72. package/dist/registry/types.d.ts.map +1 -0
  73. package/dist/registry/types.js +47 -0
  74. package/dist/registry/user-registry.cjs +140 -0
  75. package/dist/registry/user-registry.d.ts +34 -0
  76. package/dist/registry/user-registry.d.ts.map +1 -0
  77. package/dist/registry/user-registry.js +104 -0
  78. package/dist/resolver.cjs +182 -0
  79. package/dist/resolver.d.ts +14 -0
  80. package/dist/resolver.d.ts.map +1 -0
  81. package/dist/resolver.js +151 -0
  82. package/dist/utils/api-key-resolver.cjs +62 -0
  83. package/dist/utils/api-key-resolver.d.ts +21 -0
  84. package/dist/utils/api-key-resolver.d.ts.map +1 -0
  85. package/dist/utils/api-key-resolver.js +36 -0
  86. package/dist/utils/api-key-store.cjs +56 -0
  87. package/dist/utils/api-key-store.d.ts +18 -0
  88. package/dist/utils/api-key-store.d.ts.map +1 -0
  89. package/dist/utils/api-key-store.js +30 -0
  90. package/dist/utils/env-file.cjs +118 -0
  91. package/dist/utils/env-file.d.ts +5 -0
  92. package/dist/utils/env-file.d.ts.map +1 -0
  93. package/dist/utils/env-file.js +84 -0
  94. package/dist/utils/execution-context.cjs +85 -0
  95. package/dist/utils/execution-context.d.ts +20 -0
  96. package/dist/utils/execution-context.d.ts.map +1 -0
  97. package/dist/utils/execution-context.js +49 -0
  98. package/dist/utils/fs-walk.cjs +52 -0
  99. package/dist/utils/fs-walk.d.ts +8 -0
  100. package/dist/utils/fs-walk.d.ts.map +1 -0
  101. package/dist/utils/fs-walk.js +18 -0
  102. package/dist/utils/path.cjs +205 -0
  103. package/dist/utils/path.d.ts +58 -0
  104. package/dist/utils/path.d.ts.map +1 -0
  105. package/dist/utils/path.js +167 -0
  106. package/dist/writer.cjs +182 -0
  107. package/dist/writer.d.ts +34 -0
  108. package/dist/writer.d.ts.map +1 -0
  109. package/dist/writer.js +146 -0
  110. package/package.json +41 -0
@@ -0,0 +1,47 @@
1
+ import { z } from "zod";
2
+ function deriveDisplayName(slug) {
3
+ return slug.split("-").filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
4
+ }
5
+ const AgentRegistryEntrySchema = z.object({
6
+ id: z.string().describe("Unique identifier for the agent"),
7
+ name: z.string().describe("Display name for the agent"),
8
+ description: z.string(),
9
+ author: z.string(),
10
+ tags: z.array(z.string()),
11
+ source: z.string(),
12
+ main: z.string().optional(),
13
+ type: z.enum(["builtin", "custom"]).default("builtin").describe("Agent type")
14
+ }).strict();
15
+ const RegistrySchema = z.object({
16
+ version: z.string(),
17
+ agents: z.record(z.string(), AgentRegistryEntrySchema)
18
+ }).strict();
19
+ function normalizeRegistryJson(raw) {
20
+ if (!raw || typeof raw !== "object") {
21
+ return { version: "1.0.0", agents: {} };
22
+ }
23
+ const input = raw;
24
+ const normalizedAgents = {};
25
+ const agents = input.agents && typeof input.agents === "object" && input.agents !== null ? input.agents : {};
26
+ for (const [agentId, value] of Object.entries(agents)) {
27
+ if (!value || typeof value !== "object") continue;
28
+ const entry = { ...value };
29
+ if (!entry.id || typeof entry.id !== "string" || entry.id.trim() !== agentId) {
30
+ entry.id = agentId;
31
+ }
32
+ if (!entry.name || typeof entry.name !== "string" || !entry.name.trim()) {
33
+ entry.name = deriveDisplayName(agentId);
34
+ }
35
+ normalizedAgents[agentId] = entry;
36
+ }
37
+ return {
38
+ version: typeof input.version === "string" && input.version.trim().length > 0 ? input.version : "1.0.0",
39
+ agents: normalizedAgents
40
+ };
41
+ }
42
+ export {
43
+ AgentRegistryEntrySchema,
44
+ RegistrySchema,
45
+ deriveDisplayName,
46
+ normalizeRegistryJson
47
+ };
@@ -0,0 +1,140 @@
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 user_registry_exports = {};
30
+ __export(user_registry_exports, {
31
+ addAgentToUserRegistry: () => addAgentToUserRegistry,
32
+ getUserRegistryPath: () => getUserRegistryPath,
33
+ loadUserRegistry: () => loadUserRegistry,
34
+ mergeRegistries: () => mergeRegistries,
35
+ removeAgentFromUserRegistry: () => removeAgentFromUserRegistry,
36
+ saveUserRegistry: () => saveUserRegistry,
37
+ userRegistryHasAgent: () => userRegistryHasAgent
38
+ });
39
+ module.exports = __toCommonJS(user_registry_exports);
40
+ var import_fs = require("fs");
41
+ var import_fs2 = require("fs");
42
+ var import_path = __toESM(require("path"), 1);
43
+ var import_path2 = require("../utils/path.js");
44
+ var import_types = require("./types.js");
45
+ var import_errors = require("./errors.js");
46
+ var import_core = require("@dexto/core");
47
+ const USER_REGISTRY_FILENAME = "user-agent-registry.json";
48
+ function getUserRegistryPath() {
49
+ return (0, import_path2.getDextoGlobalPath)("", USER_REGISTRY_FILENAME);
50
+ }
51
+ function loadUserRegistry() {
52
+ const registryPath = getUserRegistryPath();
53
+ if (!(0, import_fs2.existsSync)(registryPath)) {
54
+ import_core.logger.debug("User registry not found, returning empty registry");
55
+ return { version: "1.0.0", agents: {} };
56
+ }
57
+ try {
58
+ const content = (0, import_fs.readFileSync)(registryPath, "utf-8");
59
+ const data = JSON.parse(content);
60
+ return import_types.RegistrySchema.parse((0, import_types.normalizeRegistryJson)(data));
61
+ } catch (error) {
62
+ throw import_errors.RegistryError.registryParseError(
63
+ registryPath,
64
+ error instanceof Error ? error.message : String(error)
65
+ );
66
+ }
67
+ }
68
+ async function saveUserRegistry(registry) {
69
+ const registryPath = getUserRegistryPath();
70
+ const tempPath = `${registryPath}.tmp.${Date.now()}`;
71
+ const dextoDir = import_path.default.dirname(registryPath);
72
+ try {
73
+ await import_fs.promises.mkdir(dextoDir, { recursive: true });
74
+ await import_fs.promises.writeFile(tempPath, JSON.stringify(registry, null, 2), {
75
+ encoding: "utf-8",
76
+ mode: 384
77
+ });
78
+ await import_fs.promises.rename(tempPath, registryPath);
79
+ import_core.logger.debug(`Saved user registry to ${registryPath}`);
80
+ } catch (error) {
81
+ try {
82
+ if ((0, import_fs2.existsSync)(tempPath)) {
83
+ await import_fs.promises.rm(tempPath, { force: true });
84
+ }
85
+ } catch {
86
+ }
87
+ throw import_errors.RegistryError.registryWriteError(
88
+ registryPath,
89
+ error instanceof Error ? error.message : String(error)
90
+ );
91
+ }
92
+ }
93
+ function mergeRegistries(bundled, user) {
94
+ return {
95
+ version: bundled.version,
96
+ agents: {
97
+ ...bundled.agents,
98
+ ...user.agents
99
+ }
100
+ };
101
+ }
102
+ function userRegistryHasAgent(agentId) {
103
+ const userRegistry = loadUserRegistry();
104
+ return agentId in userRegistry.agents;
105
+ }
106
+ async function addAgentToUserRegistry(agentId, entry) {
107
+ const userRegistry = loadUserRegistry();
108
+ if (agentId in userRegistry.agents) {
109
+ throw import_errors.RegistryError.agentAlreadyExists(agentId);
110
+ }
111
+ userRegistry.agents[agentId] = {
112
+ ...entry,
113
+ id: agentId,
114
+ // Force consistency between key and id field
115
+ name: entry.name && entry.name.trim().length > 0 ? entry.name : (0, import_types.deriveDisplayName)(agentId),
116
+ // Ensure name is never undefined or whitespace-only
117
+ type: "custom"
118
+ };
119
+ await saveUserRegistry(userRegistry);
120
+ import_core.logger.info(`Added custom agent '${agentId}' to user registry`);
121
+ }
122
+ async function removeAgentFromUserRegistry(agentId) {
123
+ const userRegistry = loadUserRegistry();
124
+ if (!(agentId in userRegistry.agents)) {
125
+ throw import_errors.RegistryError.agentNotFound(agentId, Object.keys(userRegistry.agents));
126
+ }
127
+ delete userRegistry.agents[agentId];
128
+ await saveUserRegistry(userRegistry);
129
+ import_core.logger.info(`Removed custom agent '${agentId}' from user registry`);
130
+ }
131
+ // Annotate the CommonJS export names for ESM import in node:
132
+ 0 && (module.exports = {
133
+ addAgentToUserRegistry,
134
+ getUserRegistryPath,
135
+ loadUserRegistry,
136
+ mergeRegistries,
137
+ removeAgentFromUserRegistry,
138
+ saveUserRegistry,
139
+ userRegistryHasAgent
140
+ });
@@ -0,0 +1,34 @@
1
+ import { Registry, AgentRegistryEntry } from './types.js';
2
+ /**
3
+ * Get path to user registry file
4
+ */
5
+ export declare function getUserRegistryPath(): string;
6
+ /**
7
+ * Load user registry from ~/.dexto/user-agent-registry.json
8
+ * Returns empty registry if file doesn't exist
9
+ */
10
+ export declare function loadUserRegistry(): Registry;
11
+ /**
12
+ * Save user registry atomically using temp file + rename
13
+ */
14
+ export declare function saveUserRegistry(registry: Registry): Promise<void>;
15
+ /**
16
+ * Merge bundled and user registries
17
+ * User registry only contains custom agents
18
+ * Name conflicts are not allowed (validated before adding to user registry)
19
+ */
20
+ export declare function mergeRegistries(bundled: Registry, user: Registry): Registry;
21
+ /**
22
+ * Check if agent exists in user registry
23
+ */
24
+ export declare function userRegistryHasAgent(agentId: string): boolean;
25
+ /**
26
+ * Add custom agent to user registry
27
+ * Validates that name doesn't conflict with bundled registry
28
+ */
29
+ export declare function addAgentToUserRegistry(agentId: string, entry: Omit<AgentRegistryEntry, 'type'>): Promise<void>;
30
+ /**
31
+ * Remove custom agent from user registry
32
+ */
33
+ export declare function removeAgentFromUserRegistry(agentId: string): Promise<void>;
34
+ //# sourceMappingURL=user-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-registry.d.ts","sourceRoot":"","sources":["../../src/registry/user-registry.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,QAAQ,EAER,kBAAkB,EAGrB,MAAM,YAAY,CAAC;AAMpB;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,QAAQ,CAkB3C;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAkCxE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAQ3E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAG7D;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CACxC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,GACxC,OAAO,CAAC,IAAI,CAAC,CAkBf;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAWhF"}
@@ -0,0 +1,104 @@
1
+ import { promises as fs, readFileSync } from "fs";
2
+ import { existsSync } from "fs";
3
+ import path from "path";
4
+ import { getDextoGlobalPath } from "../utils/path.js";
5
+ import {
6
+ RegistrySchema,
7
+ normalizeRegistryJson,
8
+ deriveDisplayName
9
+ } from "./types.js";
10
+ import { RegistryError } from "./errors.js";
11
+ import { logger } from "@dexto/core";
12
+ const USER_REGISTRY_FILENAME = "user-agent-registry.json";
13
+ function getUserRegistryPath() {
14
+ return getDextoGlobalPath("", USER_REGISTRY_FILENAME);
15
+ }
16
+ function loadUserRegistry() {
17
+ const registryPath = getUserRegistryPath();
18
+ if (!existsSync(registryPath)) {
19
+ logger.debug("User registry not found, returning empty registry");
20
+ return { version: "1.0.0", agents: {} };
21
+ }
22
+ try {
23
+ const content = readFileSync(registryPath, "utf-8");
24
+ const data = JSON.parse(content);
25
+ return RegistrySchema.parse(normalizeRegistryJson(data));
26
+ } catch (error) {
27
+ throw RegistryError.registryParseError(
28
+ registryPath,
29
+ error instanceof Error ? error.message : String(error)
30
+ );
31
+ }
32
+ }
33
+ async function saveUserRegistry(registry) {
34
+ const registryPath = getUserRegistryPath();
35
+ const tempPath = `${registryPath}.tmp.${Date.now()}`;
36
+ const dextoDir = path.dirname(registryPath);
37
+ try {
38
+ await fs.mkdir(dextoDir, { recursive: true });
39
+ await fs.writeFile(tempPath, JSON.stringify(registry, null, 2), {
40
+ encoding: "utf-8",
41
+ mode: 384
42
+ });
43
+ await fs.rename(tempPath, registryPath);
44
+ logger.debug(`Saved user registry to ${registryPath}`);
45
+ } catch (error) {
46
+ try {
47
+ if (existsSync(tempPath)) {
48
+ await fs.rm(tempPath, { force: true });
49
+ }
50
+ } catch {
51
+ }
52
+ throw RegistryError.registryWriteError(
53
+ registryPath,
54
+ error instanceof Error ? error.message : String(error)
55
+ );
56
+ }
57
+ }
58
+ function mergeRegistries(bundled, user) {
59
+ return {
60
+ version: bundled.version,
61
+ agents: {
62
+ ...bundled.agents,
63
+ ...user.agents
64
+ }
65
+ };
66
+ }
67
+ function userRegistryHasAgent(agentId) {
68
+ const userRegistry = loadUserRegistry();
69
+ return agentId in userRegistry.agents;
70
+ }
71
+ async function addAgentToUserRegistry(agentId, entry) {
72
+ const userRegistry = loadUserRegistry();
73
+ if (agentId in userRegistry.agents) {
74
+ throw RegistryError.agentAlreadyExists(agentId);
75
+ }
76
+ userRegistry.agents[agentId] = {
77
+ ...entry,
78
+ id: agentId,
79
+ // Force consistency between key and id field
80
+ name: entry.name && entry.name.trim().length > 0 ? entry.name : deriveDisplayName(agentId),
81
+ // Ensure name is never undefined or whitespace-only
82
+ type: "custom"
83
+ };
84
+ await saveUserRegistry(userRegistry);
85
+ logger.info(`Added custom agent '${agentId}' to user registry`);
86
+ }
87
+ async function removeAgentFromUserRegistry(agentId) {
88
+ const userRegistry = loadUserRegistry();
89
+ if (!(agentId in userRegistry.agents)) {
90
+ throw RegistryError.agentNotFound(agentId, Object.keys(userRegistry.agents));
91
+ }
92
+ delete userRegistry.agents[agentId];
93
+ await saveUserRegistry(userRegistry);
94
+ logger.info(`Removed custom agent '${agentId}' from user registry`);
95
+ }
96
+ export {
97
+ addAgentToUserRegistry,
98
+ getUserRegistryPath,
99
+ loadUserRegistry,
100
+ mergeRegistries,
101
+ removeAgentFromUserRegistry,
102
+ saveUserRegistry,
103
+ userRegistryHasAgent
104
+ };
@@ -0,0 +1,182 @@
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 resolver_exports = {};
30
+ __export(resolver_exports, {
31
+ resolveAgentPath: () => resolveAgentPath,
32
+ updateDefaultAgentPreference: () => updateDefaultAgentPreference
33
+ });
34
+ module.exports = __toCommonJS(resolver_exports);
35
+ var import_fs = require("fs");
36
+ var import_path = __toESM(require("path"), 1);
37
+ var import_path2 = require("./utils/path.js");
38
+ var import_execution_context = require("./utils/execution-context.js");
39
+ var import_core = require("@dexto/core");
40
+ var import_loader = require("./preferences/loader.js");
41
+ var import_config = require("./config/index.js");
42
+ async function resolveAgentPath(nameOrPath, autoInstall = true, injectPreferences = true) {
43
+ if (nameOrPath && (0, import_path2.isPath)(nameOrPath)) {
44
+ const resolved = import_path.default.resolve(nameOrPath);
45
+ try {
46
+ const stat = await import_fs.promises.stat(resolved);
47
+ if (!stat.isFile()) {
48
+ throw import_config.ConfigError.fileNotFound(resolved);
49
+ }
50
+ return resolved;
51
+ } catch {
52
+ throw import_config.ConfigError.fileNotFound(resolved);
53
+ }
54
+ }
55
+ if (nameOrPath) {
56
+ const { getAgentRegistry } = await import("./registry/registry.js");
57
+ const registry = getAgentRegistry();
58
+ return await registry.resolveAgent(nameOrPath, autoInstall, injectPreferences);
59
+ }
60
+ return await resolveDefaultAgentByContext(autoInstall, injectPreferences);
61
+ }
62
+ async function resolveDefaultAgentByContext(autoInstall = true, injectPreferences = true) {
63
+ const executionContext = (0, import_execution_context.getExecutionContext)();
64
+ switch (executionContext) {
65
+ case "dexto-source":
66
+ return await resolveDefaultAgentForDextoSource(autoInstall, injectPreferences);
67
+ case "dexto-project":
68
+ return await resolveDefaultAgentForDextoProject(autoInstall, injectPreferences);
69
+ case "global-cli":
70
+ return await resolveDefaultAgentForGlobalCLI(autoInstall, injectPreferences);
71
+ default:
72
+ throw import_config.ConfigError.unknownContext(executionContext);
73
+ }
74
+ }
75
+ async function resolveDefaultAgentForDextoSource(autoInstall = true, injectPreferences = true) {
76
+ import_core.logger.debug("Resolving default agent for dexto source context");
77
+ const sourceRoot = (0, import_execution_context.findDextoSourceRoot)();
78
+ if (!sourceRoot) {
79
+ throw import_config.ConfigError.bundledNotFound("dexto source directory not found");
80
+ }
81
+ const repoConfigPath = import_path.default.join(sourceRoot, "agents", "default-agent.yml");
82
+ const isDevMode = process.env.DEXTO_DEV_MODE === "true";
83
+ if (isDevMode) {
84
+ import_core.logger.debug("Dev mode: using repository config file");
85
+ try {
86
+ await import_fs.promises.access(repoConfigPath);
87
+ return repoConfigPath;
88
+ } catch {
89
+ throw import_config.ConfigError.bundledNotFound(repoConfigPath);
90
+ }
91
+ }
92
+ if ((0, import_loader.globalPreferencesExist)()) {
93
+ try {
94
+ const preferences = await (0, import_loader.loadGlobalPreferences)();
95
+ if (preferences.setup.completed) {
96
+ import_core.logger.debug("Using user preferences in dexto-source context");
97
+ 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
+ );
105
+ }
106
+ } catch (error) {
107
+ import_core.logger.warn(`Failed to load preferences, falling back to repo config: ${error}`);
108
+ }
109
+ }
110
+ import_core.logger.debug("Using repository config (no preferences or setup incomplete)");
111
+ try {
112
+ await import_fs.promises.access(repoConfigPath);
113
+ return repoConfigPath;
114
+ } catch {
115
+ throw import_config.ConfigError.bundledNotFound(repoConfigPath);
116
+ }
117
+ }
118
+ async function resolveDefaultAgentForDextoProject(autoInstall = true, injectPreferences = true) {
119
+ import_core.logger.debug("Resolving default agent for dexto project context");
120
+ const projectRoot = (0, import_execution_context.findDextoProjectRoot)();
121
+ if (!projectRoot) {
122
+ throw import_config.ConfigError.unknownContext("dexto-project: project root not found");
123
+ }
124
+ const candidatePaths = [
125
+ import_path.default.join(projectRoot, "default-agent.yml"),
126
+ import_path.default.join(projectRoot, "agents", "default-agent.yml"),
127
+ import_path.default.join(projectRoot, "src", "dexto", "agents", "default-agent.yml")
128
+ ];
129
+ for (const p of candidatePaths) {
130
+ try {
131
+ await import_fs.promises.access(p);
132
+ return p;
133
+ } catch {
134
+ }
135
+ }
136
+ import_core.logger.debug(`No project-local default-agent.yml found in ${projectRoot}`);
137
+ if (!(0, import_loader.globalPreferencesExist)()) {
138
+ throw import_config.ConfigError.noProjectDefault(projectRoot);
139
+ }
140
+ const preferences = await (0, import_loader.loadGlobalPreferences)();
141
+ if (!preferences.setup.completed) {
142
+ throw import_config.ConfigError.setupIncomplete();
143
+ }
144
+ 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);
148
+ }
149
+ async function resolveDefaultAgentForGlobalCLI(autoInstall = true, injectPreferences = true) {
150
+ import_core.logger.debug("Resolving default agent for global CLI context");
151
+ if (!(0, import_loader.globalPreferencesExist)()) {
152
+ throw import_config.ConfigError.noGlobalPreferences();
153
+ }
154
+ const preferences = await (0, import_loader.loadGlobalPreferences)();
155
+ if (!preferences.setup.completed) {
156
+ throw import_config.ConfigError.setupIncomplete();
157
+ }
158
+ 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);
162
+ }
163
+ 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}`);
177
+ }
178
+ // Annotate the CommonJS export names for ESM import in node:
179
+ 0 && (module.exports = {
180
+ resolveAgentPath,
181
+ updateDefaultAgentPreference
182
+ });
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Resolve agent path with preference integration
3
+ * @param nameOrPath Optional agent name or explicit path
4
+ * @param autoInstall Whether to automatically install missing agents from registry (default: true)
5
+ * @param injectPreferences Whether to inject preferences during auto-installation (default: true)
6
+ * @returns Resolved absolute path to agent config
7
+ * @throws DextoRuntimeError for any resolution failures
8
+ */
9
+ export declare function resolveAgentPath(nameOrPath?: string, autoInstall?: boolean, injectPreferences?: boolean): Promise<string>;
10
+ /**
11
+ * Update default agent preference
12
+ */
13
+ export declare function updateDefaultAgentPreference(agentName: string): Promise<void>;
14
+ //# sourceMappingURL=resolver.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,151 @@
1
+ import { promises as fs } from "fs";
2
+ import path from "path";
3
+ import { isPath } from "./utils/path.js";
4
+ import {
5
+ getExecutionContext,
6
+ findDextoSourceRoot,
7
+ findDextoProjectRoot
8
+ } from "./utils/execution-context.js";
9
+ import { logger } from "@dexto/core";
10
+ import { loadGlobalPreferences, globalPreferencesExist } from "./preferences/loader.js";
11
+ import { ConfigError } from "./config/index.js";
12
+ async function resolveAgentPath(nameOrPath, autoInstall = true, injectPreferences = true) {
13
+ if (nameOrPath && isPath(nameOrPath)) {
14
+ const resolved = path.resolve(nameOrPath);
15
+ try {
16
+ const stat = await fs.stat(resolved);
17
+ if (!stat.isFile()) {
18
+ throw ConfigError.fileNotFound(resolved);
19
+ }
20
+ return resolved;
21
+ } catch {
22
+ throw ConfigError.fileNotFound(resolved);
23
+ }
24
+ }
25
+ if (nameOrPath) {
26
+ const { getAgentRegistry } = await import("./registry/registry.js");
27
+ const registry = getAgentRegistry();
28
+ return await registry.resolveAgent(nameOrPath, autoInstall, injectPreferences);
29
+ }
30
+ return await resolveDefaultAgentByContext(autoInstall, injectPreferences);
31
+ }
32
+ async function resolveDefaultAgentByContext(autoInstall = true, injectPreferences = true) {
33
+ const executionContext = getExecutionContext();
34
+ switch (executionContext) {
35
+ case "dexto-source":
36
+ return await resolveDefaultAgentForDextoSource(autoInstall, injectPreferences);
37
+ case "dexto-project":
38
+ return await resolveDefaultAgentForDextoProject(autoInstall, injectPreferences);
39
+ case "global-cli":
40
+ return await resolveDefaultAgentForGlobalCLI(autoInstall, injectPreferences);
41
+ default:
42
+ throw ConfigError.unknownContext(executionContext);
43
+ }
44
+ }
45
+ async function resolveDefaultAgentForDextoSource(autoInstall = true, injectPreferences = true) {
46
+ logger.debug("Resolving default agent for dexto source context");
47
+ const sourceRoot = findDextoSourceRoot();
48
+ if (!sourceRoot) {
49
+ throw ConfigError.bundledNotFound("dexto source directory not found");
50
+ }
51
+ const repoConfigPath = path.join(sourceRoot, "agents", "default-agent.yml");
52
+ const isDevMode = process.env.DEXTO_DEV_MODE === "true";
53
+ if (isDevMode) {
54
+ logger.debug("Dev mode: using repository config file");
55
+ try {
56
+ await fs.access(repoConfigPath);
57
+ return repoConfigPath;
58
+ } catch {
59
+ throw ConfigError.bundledNotFound(repoConfigPath);
60
+ }
61
+ }
62
+ if (globalPreferencesExist()) {
63
+ try {
64
+ const preferences = await loadGlobalPreferences();
65
+ if (preferences.setup.completed) {
66
+ logger.debug("Using user preferences in dexto-source context");
67
+ 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
+ );
75
+ }
76
+ } catch (error) {
77
+ logger.warn(`Failed to load preferences, falling back to repo config: ${error}`);
78
+ }
79
+ }
80
+ logger.debug("Using repository config (no preferences or setup incomplete)");
81
+ try {
82
+ await fs.access(repoConfigPath);
83
+ return repoConfigPath;
84
+ } catch {
85
+ throw ConfigError.bundledNotFound(repoConfigPath);
86
+ }
87
+ }
88
+ async function resolveDefaultAgentForDextoProject(autoInstall = true, injectPreferences = true) {
89
+ logger.debug("Resolving default agent for dexto project context");
90
+ const projectRoot = findDextoProjectRoot();
91
+ if (!projectRoot) {
92
+ throw ConfigError.unknownContext("dexto-project: project root not found");
93
+ }
94
+ const candidatePaths = [
95
+ path.join(projectRoot, "default-agent.yml"),
96
+ path.join(projectRoot, "agents", "default-agent.yml"),
97
+ path.join(projectRoot, "src", "dexto", "agents", "default-agent.yml")
98
+ ];
99
+ for (const p of candidatePaths) {
100
+ try {
101
+ await fs.access(p);
102
+ return p;
103
+ } catch {
104
+ }
105
+ }
106
+ logger.debug(`No project-local default-agent.yml found in ${projectRoot}`);
107
+ if (!globalPreferencesExist()) {
108
+ throw ConfigError.noProjectDefault(projectRoot);
109
+ }
110
+ const preferences = await loadGlobalPreferences();
111
+ if (!preferences.setup.completed) {
112
+ throw ConfigError.setupIncomplete();
113
+ }
114
+ 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);
118
+ }
119
+ async function resolveDefaultAgentForGlobalCLI(autoInstall = true, injectPreferences = true) {
120
+ logger.debug("Resolving default agent for global CLI context");
121
+ if (!globalPreferencesExist()) {
122
+ throw ConfigError.noGlobalPreferences();
123
+ }
124
+ const preferences = await loadGlobalPreferences();
125
+ if (!preferences.setup.completed) {
126
+ throw ConfigError.setupIncomplete();
127
+ }
128
+ 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);
132
+ }
133
+ 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}`);
147
+ }
148
+ export {
149
+ resolveAgentPath,
150
+ updateDefaultAgentPreference
151
+ };