@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,62 @@
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 api_key_resolver_exports = {};
20
+ __export(api_key_resolver_exports, {
21
+ PROVIDER_API_KEY_MAP: () => PROVIDER_API_KEY_MAP,
22
+ getPrimaryApiKeyEnvVar: () => getPrimaryApiKeyEnvVar,
23
+ resolveApiKeyForProvider: () => resolveApiKeyForProvider
24
+ });
25
+ module.exports = __toCommonJS(api_key_resolver_exports);
26
+ const PROVIDER_API_KEY_MAP = {
27
+ openai: ["OPENAI_API_KEY", "OPENAI_KEY"],
28
+ "openai-compatible": ["OPENAI_API_KEY", "OPENAI_KEY"],
29
+ // Uses same keys as openai
30
+ anthropic: ["ANTHROPIC_API_KEY", "ANTHROPIC_KEY", "CLAUDE_API_KEY"],
31
+ google: ["GOOGLE_GENERATIVE_AI_API_KEY", "GOOGLE_API_KEY", "GEMINI_API_KEY"],
32
+ groq: ["GROQ_API_KEY"],
33
+ cohere: ["COHERE_API_KEY"],
34
+ xai: ["XAI_API_KEY", "X_AI_API_KEY"]
35
+ // perplexity: ['PERPLEXITY_API_KEY'],
36
+ // together: ['TOGETHER_API_KEY'],
37
+ // fireworks: ['FIREWORKS_API_KEY'],
38
+ // deepseek: ['DEEPSEEK_API_KEY'],
39
+ };
40
+ function resolveApiKeyForProvider(provider) {
41
+ const envVars = PROVIDER_API_KEY_MAP[provider];
42
+ if (!envVars) {
43
+ return void 0;
44
+ }
45
+ for (const envVar of envVars) {
46
+ const value = process.env[envVar];
47
+ if (value && value.trim()) {
48
+ return value.trim();
49
+ }
50
+ }
51
+ return void 0;
52
+ }
53
+ function getPrimaryApiKeyEnvVar(provider) {
54
+ const envVars = PROVIDER_API_KEY_MAP[provider];
55
+ return envVars?.[0] || `${provider.toUpperCase()}_API_KEY`;
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ PROVIDER_API_KEY_MAP,
60
+ getPrimaryApiKeyEnvVar,
61
+ resolveApiKeyForProvider
62
+ });
@@ -0,0 +1,21 @@
1
+ import type { LLMProvider } from '@dexto/core';
2
+ /**
3
+ * Utility for resolving API keys from environment variables.
4
+ * This consolidates the API key resolution logic used across CLI and core components.
5
+ */
6
+ export declare const PROVIDER_API_KEY_MAP: Record<LLMProvider, string[]>;
7
+ /**
8
+ * Resolves API key for a given provider from environment variables.
9
+ *
10
+ * @param provider The LLM provider
11
+ * @returns Resolved API key or undefined if not found
12
+ */
13
+ export declare function resolveApiKeyForProvider(provider: LLMProvider): string | undefined;
14
+ /**
15
+ * Gets the primary environment variable name for a provider (for display/error messages).
16
+ *
17
+ * @param provider The LLM provider
18
+ * @returns Primary environment variable name
19
+ */
20
+ export declare function getPrimaryApiKeyEnvVar(provider: LLMProvider): string;
21
+ //# sourceMappingURL=api-key-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-key-resolver.d.ts","sourceRoot":"","sources":["../../src/utils/api-key-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;GAGG;AAGH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,CAY9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAelF;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,CAGpE"}
@@ -0,0 +1,36 @@
1
+ const PROVIDER_API_KEY_MAP = {
2
+ openai: ["OPENAI_API_KEY", "OPENAI_KEY"],
3
+ "openai-compatible": ["OPENAI_API_KEY", "OPENAI_KEY"],
4
+ // Uses same keys as openai
5
+ anthropic: ["ANTHROPIC_API_KEY", "ANTHROPIC_KEY", "CLAUDE_API_KEY"],
6
+ google: ["GOOGLE_GENERATIVE_AI_API_KEY", "GOOGLE_API_KEY", "GEMINI_API_KEY"],
7
+ groq: ["GROQ_API_KEY"],
8
+ cohere: ["COHERE_API_KEY"],
9
+ xai: ["XAI_API_KEY", "X_AI_API_KEY"]
10
+ // perplexity: ['PERPLEXITY_API_KEY'],
11
+ // together: ['TOGETHER_API_KEY'],
12
+ // fireworks: ['FIREWORKS_API_KEY'],
13
+ // deepseek: ['DEEPSEEK_API_KEY'],
14
+ };
15
+ function resolveApiKeyForProvider(provider) {
16
+ const envVars = PROVIDER_API_KEY_MAP[provider];
17
+ if (!envVars) {
18
+ return void 0;
19
+ }
20
+ for (const envVar of envVars) {
21
+ const value = process.env[envVar];
22
+ if (value && value.trim()) {
23
+ return value.trim();
24
+ }
25
+ }
26
+ return void 0;
27
+ }
28
+ function getPrimaryApiKeyEnvVar(provider) {
29
+ const envVars = PROVIDER_API_KEY_MAP[provider];
30
+ return envVars?.[0] || `${provider.toUpperCase()}_API_KEY`;
31
+ }
32
+ export {
33
+ PROVIDER_API_KEY_MAP,
34
+ getPrimaryApiKeyEnvVar,
35
+ resolveApiKeyForProvider
36
+ };
@@ -0,0 +1,56 @@
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 api_key_store_exports = {};
20
+ __export(api_key_store_exports, {
21
+ getProviderKeyStatus: () => getProviderKeyStatus,
22
+ listProviderKeyStatus: () => listProviderKeyStatus,
23
+ saveProviderApiKey: () => saveProviderApiKey
24
+ });
25
+ module.exports = __toCommonJS(api_key_store_exports);
26
+ var import_api_key_resolver = require("./api-key-resolver.js");
27
+ var import_core = require("@dexto/core");
28
+ var import_path = require("./path.js");
29
+ var import_env_file = require("./env-file.js");
30
+ async function saveProviderApiKey(provider, apiKey, startPath) {
31
+ if (!provider) throw new Error("provider is required");
32
+ if (!apiKey || !apiKey.trim()) throw new Error("apiKey is required");
33
+ const envVar = (0, import_api_key_resolver.getPrimaryApiKeyEnvVar)(provider);
34
+ const targetEnvPath = (0, import_path.getDextoEnvPath)(startPath);
35
+ await (0, import_env_file.updateEnvFile)(targetEnvPath, { [envVar]: apiKey });
36
+ process.env[envVar] = apiKey;
37
+ return { envVar, targetEnvPath };
38
+ }
39
+ function getProviderKeyStatus(provider) {
40
+ const envVar = (0, import_api_key_resolver.getPrimaryApiKeyEnvVar)(provider);
41
+ const key = (0, import_api_key_resolver.resolveApiKeyForProvider)(provider);
42
+ return { hasApiKey: Boolean(key && key.trim()), envVar };
43
+ }
44
+ function listProviderKeyStatus() {
45
+ const result = {};
46
+ for (const provider of import_core.LLM_PROVIDERS) {
47
+ result[provider] = getProviderKeyStatus(provider);
48
+ }
49
+ return result;
50
+ }
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ getProviderKeyStatus,
54
+ listProviderKeyStatus,
55
+ saveProviderApiKey
56
+ });
@@ -0,0 +1,18 @@
1
+ import type { LLMProvider } from '@dexto/core';
2
+ /**
3
+ * Save provider API key to the correct .env and make it immediately available in-process.
4
+ * Never returns the key; only metadata for callers to display.
5
+ */
6
+ export declare function saveProviderApiKey(provider: LLMProvider, apiKey: string, startPath?: string): Promise<{
7
+ envVar: string;
8
+ targetEnvPath: string;
9
+ }>;
10
+ export declare function getProviderKeyStatus(provider: LLMProvider): {
11
+ hasApiKey: boolean;
12
+ envVar: string;
13
+ };
14
+ export declare function listProviderKeyStatus(): Record<string, {
15
+ hasApiKey: boolean;
16
+ envVar: string;
17
+ }>;
18
+ //# sourceMappingURL=api-key-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-key-store.d.ts","sourceRoot":"","sources":["../../src/utils/api-key-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAM/C;;;GAGG;AACH,wBAAsB,kBAAkB,CACpC,QAAQ,EAAE,WAAW,EACrB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CAYpD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,WAAW,GAAG;IACzD,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAClB,CAIA;AAED,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAM9F"}
@@ -0,0 +1,30 @@
1
+ import { getPrimaryApiKeyEnvVar, resolveApiKeyForProvider } from "./api-key-resolver.js";
2
+ import { LLM_PROVIDERS } from "@dexto/core";
3
+ import { getDextoEnvPath } from "./path.js";
4
+ import { updateEnvFile } from "./env-file.js";
5
+ async function saveProviderApiKey(provider, apiKey, startPath) {
6
+ if (!provider) throw new Error("provider is required");
7
+ if (!apiKey || !apiKey.trim()) throw new Error("apiKey is required");
8
+ const envVar = getPrimaryApiKeyEnvVar(provider);
9
+ const targetEnvPath = getDextoEnvPath(startPath);
10
+ await updateEnvFile(targetEnvPath, { [envVar]: apiKey });
11
+ process.env[envVar] = apiKey;
12
+ return { envVar, targetEnvPath };
13
+ }
14
+ function getProviderKeyStatus(provider) {
15
+ const envVar = getPrimaryApiKeyEnvVar(provider);
16
+ const key = resolveApiKeyForProvider(provider);
17
+ return { hasApiKey: Boolean(key && key.trim()), envVar };
18
+ }
19
+ function listProviderKeyStatus() {
20
+ const result = {};
21
+ for (const provider of LLM_PROVIDERS) {
22
+ result[provider] = getProviderKeyStatus(provider);
23
+ }
24
+ return result;
25
+ }
26
+ export {
27
+ getProviderKeyStatus,
28
+ listProviderKeyStatus,
29
+ saveProviderApiKey
30
+ };
@@ -0,0 +1,118 @@
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 env_file_exports = {};
30
+ __export(env_file_exports, {
31
+ updateEnvFile: () => updateEnvFile
32
+ });
33
+ module.exports = __toCommonJS(env_file_exports);
34
+ var path = __toESM(require("node:path"), 1);
35
+ var import_node_fs = require("node:fs");
36
+ const DEXTO_ENV_KEYS = [
37
+ "OPENAI_API_KEY",
38
+ "ANTHROPIC_API_KEY",
39
+ "GOOGLE_GENERATIVE_AI_API_KEY",
40
+ "GROQ_API_KEY",
41
+ "COHERE_API_KEY",
42
+ "XAI_API_KEY",
43
+ "DEXTO_LOG_LEVEL"
44
+ ];
45
+ function isDextoEnvKey(value) {
46
+ return DEXTO_ENV_KEYS.includes(value);
47
+ }
48
+ async function updateEnvFile(envFilePath, updates) {
49
+ await import_node_fs.promises.mkdir(path.dirname(envFilePath), { recursive: true });
50
+ let envLines = [];
51
+ try {
52
+ const existingEnv = await import_node_fs.promises.readFile(envFilePath, "utf8");
53
+ envLines = existingEnv.split("\n");
54
+ } catch {
55
+ }
56
+ const currentValues = {};
57
+ envLines.forEach((line) => {
58
+ const match = line.match(/^([A-Z0-9_]+)=(.*)$/);
59
+ if (match && match[1] && isDextoEnvKey(match[1])) {
60
+ const value = match[2] ?? "";
61
+ currentValues[match[1]] = value;
62
+ }
63
+ });
64
+ const updatedValues = Object.fromEntries(
65
+ DEXTO_ENV_KEYS.map((key) => {
66
+ const update = updates[key];
67
+ const current = currentValues[key];
68
+ const fallback = key === "DEXTO_LOG_LEVEL" ? "info" : "";
69
+ const value = update !== void 0 ? update : current ?? fallback;
70
+ return [key, value];
71
+ })
72
+ );
73
+ const sectionHeader = "## Dexto env variables";
74
+ const headerIndex = envLines.findIndex((line) => line.trim() === sectionHeader);
75
+ let contentLines;
76
+ if (headerIndex !== -1) {
77
+ const beforeSection = envLines.slice(0, headerIndex);
78
+ let sectionEnd = headerIndex + 1;
79
+ while (sectionEnd < envLines.length && envLines[sectionEnd]?.trim() !== "") {
80
+ sectionEnd++;
81
+ }
82
+ if (sectionEnd < envLines.length && envLines[sectionEnd]?.trim() === "") {
83
+ sectionEnd++;
84
+ }
85
+ const afterSection = envLines.slice(sectionEnd);
86
+ contentLines = [...beforeSection, ...afterSection];
87
+ } else {
88
+ contentLines = envLines;
89
+ }
90
+ const existingEnvVars = {};
91
+ contentLines.forEach((line) => {
92
+ const match = line.match(/^([A-Z0-9_]+)=(.*)$/);
93
+ if (match && match[1] && isDextoEnvKey(match[1])) {
94
+ const value = match[2] ?? "";
95
+ existingEnvVars[match[1]] = value;
96
+ }
97
+ });
98
+ if (contentLines.length > 0) {
99
+ if (contentLines[contentLines.length - 1]?.trim() !== "") {
100
+ contentLines.push("");
101
+ }
102
+ } else {
103
+ contentLines.push("");
104
+ }
105
+ contentLines.push(sectionHeader);
106
+ for (const key of DEXTO_ENV_KEYS) {
107
+ if (key in existingEnvVars && !(key in updates)) {
108
+ continue;
109
+ }
110
+ contentLines.push(`${key}=${updatedValues[key]}`);
111
+ }
112
+ contentLines.push("");
113
+ await import_node_fs.promises.writeFile(envFilePath, contentLines.join("\n"), "utf8");
114
+ }
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ updateEnvFile
118
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Update a .env file with Dexto environment variables, ensuring our section stays consistent.
3
+ */
4
+ export declare function updateEnvFile(envFilePath: string, updates: Record<string, string>): Promise<void>;
5
+ //# sourceMappingURL=env-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-file.d.ts","sourceRoot":"","sources":["../../src/utils/env-file.ts"],"names":[],"mappings":"AAsBA;;GAEG;AACH,wBAAsB,aAAa,CAC/B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC,CAgFf"}
@@ -0,0 +1,84 @@
1
+ import * as path from "node:path";
2
+ import { promises as fs } from "node:fs";
3
+ const DEXTO_ENV_KEYS = [
4
+ "OPENAI_API_KEY",
5
+ "ANTHROPIC_API_KEY",
6
+ "GOOGLE_GENERATIVE_AI_API_KEY",
7
+ "GROQ_API_KEY",
8
+ "COHERE_API_KEY",
9
+ "XAI_API_KEY",
10
+ "DEXTO_LOG_LEVEL"
11
+ ];
12
+ function isDextoEnvKey(value) {
13
+ return DEXTO_ENV_KEYS.includes(value);
14
+ }
15
+ async function updateEnvFile(envFilePath, updates) {
16
+ await fs.mkdir(path.dirname(envFilePath), { recursive: true });
17
+ let envLines = [];
18
+ try {
19
+ const existingEnv = await fs.readFile(envFilePath, "utf8");
20
+ envLines = existingEnv.split("\n");
21
+ } catch {
22
+ }
23
+ const currentValues = {};
24
+ envLines.forEach((line) => {
25
+ const match = line.match(/^([A-Z0-9_]+)=(.*)$/);
26
+ if (match && match[1] && isDextoEnvKey(match[1])) {
27
+ const value = match[2] ?? "";
28
+ currentValues[match[1]] = value;
29
+ }
30
+ });
31
+ const updatedValues = Object.fromEntries(
32
+ DEXTO_ENV_KEYS.map((key) => {
33
+ const update = updates[key];
34
+ const current = currentValues[key];
35
+ const fallback = key === "DEXTO_LOG_LEVEL" ? "info" : "";
36
+ const value = update !== void 0 ? update : current ?? fallback;
37
+ return [key, value];
38
+ })
39
+ );
40
+ const sectionHeader = "## Dexto env variables";
41
+ const headerIndex = envLines.findIndex((line) => line.trim() === sectionHeader);
42
+ let contentLines;
43
+ if (headerIndex !== -1) {
44
+ const beforeSection = envLines.slice(0, headerIndex);
45
+ let sectionEnd = headerIndex + 1;
46
+ while (sectionEnd < envLines.length && envLines[sectionEnd]?.trim() !== "") {
47
+ sectionEnd++;
48
+ }
49
+ if (sectionEnd < envLines.length && envLines[sectionEnd]?.trim() === "") {
50
+ sectionEnd++;
51
+ }
52
+ const afterSection = envLines.slice(sectionEnd);
53
+ contentLines = [...beforeSection, ...afterSection];
54
+ } else {
55
+ contentLines = envLines;
56
+ }
57
+ const existingEnvVars = {};
58
+ contentLines.forEach((line) => {
59
+ const match = line.match(/^([A-Z0-9_]+)=(.*)$/);
60
+ if (match && match[1] && isDextoEnvKey(match[1])) {
61
+ const value = match[2] ?? "";
62
+ existingEnvVars[match[1]] = value;
63
+ }
64
+ });
65
+ if (contentLines.length > 0) {
66
+ if (contentLines[contentLines.length - 1]?.trim() !== "") {
67
+ contentLines.push("");
68
+ }
69
+ } else {
70
+ contentLines.push("");
71
+ }
72
+ contentLines.push(sectionHeader);
73
+ for (const key of DEXTO_ENV_KEYS) {
74
+ if (key in existingEnvVars && !(key in updates)) {
75
+ continue;
76
+ }
77
+ contentLines.push(`${key}=${updatedValues[key]}`);
78
+ }
79
+ contentLines.push("");
80
+ await fs.writeFile(envFilePath, contentLines.join("\n"), "utf8");
81
+ }
82
+ export {
83
+ updateEnvFile
84
+ };
@@ -0,0 +1,85 @@
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 execution_context_exports = {};
30
+ __export(execution_context_exports, {
31
+ findDextoProjectRoot: () => findDextoProjectRoot,
32
+ findDextoSourceRoot: () => findDextoSourceRoot,
33
+ getExecutionContext: () => getExecutionContext
34
+ });
35
+ module.exports = __toCommonJS(execution_context_exports);
36
+ var import_fs_walk = require("./fs-walk.js");
37
+ var import_fs = require("fs");
38
+ var path = __toESM(require("path"), 1);
39
+ function isDextoSourceDirectory(dirPath) {
40
+ const packageJsonPath = path.join(dirPath, "package.json");
41
+ try {
42
+ const pkg = JSON.parse((0, import_fs.readFileSync)(packageJsonPath, "utf-8"));
43
+ return pkg.name === "dexto-monorepo";
44
+ } catch {
45
+ return false;
46
+ }
47
+ }
48
+ function isDextoProjectDirectory(dirPath) {
49
+ const packageJsonPath = path.join(dirPath, "package.json");
50
+ try {
51
+ const pkg = JSON.parse((0, import_fs.readFileSync)(packageJsonPath, "utf-8"));
52
+ if (pkg.name === "dexto" || pkg.name === "@dexto/core" || pkg.name === "@dexto/webui") {
53
+ return false;
54
+ }
55
+ const allDeps = {
56
+ ...pkg.dependencies ?? {},
57
+ ...pkg.devDependencies ?? {},
58
+ ...pkg.peerDependencies ?? {}
59
+ };
60
+ return "dexto" in allDeps || "@dexto/core" in allDeps;
61
+ } catch {
62
+ return false;
63
+ }
64
+ }
65
+ function findDextoSourceRoot(startPath = process.cwd()) {
66
+ return (0, import_fs_walk.walkUpDirectories)(startPath, isDextoSourceDirectory);
67
+ }
68
+ function findDextoProjectRoot(startPath = process.cwd()) {
69
+ return (0, import_fs_walk.walkUpDirectories)(startPath, isDextoProjectDirectory);
70
+ }
71
+ function getExecutionContext(startPath = process.cwd()) {
72
+ if (findDextoSourceRoot(startPath)) {
73
+ return "dexto-source";
74
+ }
75
+ if (findDextoProjectRoot(startPath)) {
76
+ return "dexto-project";
77
+ }
78
+ return "global-cli";
79
+ }
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ findDextoProjectRoot,
83
+ findDextoSourceRoot,
84
+ getExecutionContext
85
+ });
@@ -0,0 +1,20 @@
1
+ export type ExecutionContext = 'dexto-source' | 'dexto-project' | 'global-cli';
2
+ /**
3
+ * Find dexto source root directory
4
+ * @param startPath Starting directory path
5
+ * @returns Dexto source root directory or null if not found
6
+ */
7
+ export declare function findDextoSourceRoot(startPath?: string): string | null;
8
+ /**
9
+ * Find dexto project root directory (projects using dexto as dependency)
10
+ * @param startPath Starting directory path
11
+ * @returns Dexto project root directory or null if not found
12
+ */
13
+ export declare function findDextoProjectRoot(startPath?: string): string | null;
14
+ /**
15
+ * Detect current execution context - standardized across codebase
16
+ * @param startPath Starting directory path (defaults to process.cwd())
17
+ * @returns Execution context
18
+ */
19
+ export declare function getExecutionContext(startPath?: string): ExecutionContext;
20
+ //# sourceMappingURL=execution-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-context.d.ts","sourceRoot":"","sources":["../../src/utils/execution-context.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG,eAAe,GAAG,YAAY,CAAC;AAgD/E;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAEpF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAErF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,GAAE,MAAsB,GAAG,gBAAgB,CAavF"}
@@ -0,0 +1,49 @@
1
+ import { walkUpDirectories } from "./fs-walk.js";
2
+ import { readFileSync } from "fs";
3
+ import * as path from "path";
4
+ function isDextoSourceDirectory(dirPath) {
5
+ const packageJsonPath = path.join(dirPath, "package.json");
6
+ try {
7
+ const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
8
+ return pkg.name === "dexto-monorepo";
9
+ } catch {
10
+ return false;
11
+ }
12
+ }
13
+ function isDextoProjectDirectory(dirPath) {
14
+ const packageJsonPath = path.join(dirPath, "package.json");
15
+ try {
16
+ const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
17
+ if (pkg.name === "dexto" || pkg.name === "@dexto/core" || pkg.name === "@dexto/webui") {
18
+ return false;
19
+ }
20
+ const allDeps = {
21
+ ...pkg.dependencies ?? {},
22
+ ...pkg.devDependencies ?? {},
23
+ ...pkg.peerDependencies ?? {}
24
+ };
25
+ return "dexto" in allDeps || "@dexto/core" in allDeps;
26
+ } catch {
27
+ return false;
28
+ }
29
+ }
30
+ function findDextoSourceRoot(startPath = process.cwd()) {
31
+ return walkUpDirectories(startPath, isDextoSourceDirectory);
32
+ }
33
+ function findDextoProjectRoot(startPath = process.cwd()) {
34
+ return walkUpDirectories(startPath, isDextoProjectDirectory);
35
+ }
36
+ function getExecutionContext(startPath = process.cwd()) {
37
+ if (findDextoSourceRoot(startPath)) {
38
+ return "dexto-source";
39
+ }
40
+ if (findDextoProjectRoot(startPath)) {
41
+ return "dexto-project";
42
+ }
43
+ return "global-cli";
44
+ }
45
+ export {
46
+ findDextoProjectRoot,
47
+ findDextoSourceRoot,
48
+ getExecutionContext
49
+ };
@@ -0,0 +1,52 @@
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 fs_walk_exports = {};
30
+ __export(fs_walk_exports, {
31
+ walkUpDirectories: () => walkUpDirectories
32
+ });
33
+ module.exports = __toCommonJS(fs_walk_exports);
34
+ var path = __toESM(require("path"), 1);
35
+ function walkUpDirectories(startPath, predicate) {
36
+ let currentPath = path.resolve(startPath);
37
+ const rootPath = path.parse(currentPath).root;
38
+ while (true) {
39
+ if (predicate(currentPath)) {
40
+ return currentPath;
41
+ }
42
+ if (currentPath === rootPath) break;
43
+ const parent = path.dirname(currentPath);
44
+ if (parent === currentPath) break;
45
+ currentPath = parent;
46
+ }
47
+ return null;
48
+ }
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ walkUpDirectories
52
+ });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generic directory walker that searches up the directory tree
3
+ * @param startPath Starting directory path
4
+ * @param predicate Function that returns true when the desired condition is found
5
+ * @returns The directory path where the condition was met, or null if not found
6
+ */
7
+ export declare function walkUpDirectories(startPath: string, predicate: (dirPath: string) => boolean): string | null;
8
+ //# sourceMappingURL=fs-walk.d.ts.map