@dexto/agent-management 1.5.5 → 1.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/config-enrichment.cjs +70 -20
- package/dist/config/config-enrichment.d.ts +10 -2
- package/dist/config/config-enrichment.d.ts.map +1 -1
- package/dist/config/config-enrichment.js +74 -20
- package/dist/config/discover-prompts.cjs +1 -1
- package/dist/config/discover-prompts.d.ts +11 -11
- package/dist/config/discover-prompts.d.ts.map +1 -1
- package/dist/config/discover-prompts.js +1 -1
- package/dist/config/loader.cjs +31 -13
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +31 -13
- package/dist/index.cjs +65 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +66 -0
- package/dist/models/custom-models.cjs +2 -1
- package/dist/models/custom-models.d.ts +7 -6
- package/dist/models/custom-models.d.ts.map +1 -1
- package/dist/models/custom-models.js +2 -1
- package/dist/plugins/discover-plugins.cjs +176 -0
- package/dist/plugins/discover-plugins.d.ts +39 -0
- package/dist/plugins/discover-plugins.d.ts.map +1 -0
- package/dist/plugins/discover-plugins.js +140 -0
- package/dist/plugins/discover-skills.cjs +89 -0
- package/dist/plugins/discover-skills.d.ts +46 -0
- package/dist/plugins/discover-skills.d.ts.map +1 -0
- package/dist/plugins/discover-skills.js +54 -0
- package/dist/plugins/error-codes.cjs +47 -0
- package/dist/plugins/error-codes.d.ts +24 -0
- package/dist/plugins/error-codes.d.ts.map +1 -0
- package/dist/plugins/error-codes.js +23 -0
- package/dist/plugins/errors.cjs +197 -0
- package/dist/plugins/errors.d.ts +68 -0
- package/dist/plugins/errors.d.ts.map +1 -0
- package/dist/plugins/errors.js +173 -0
- package/dist/plugins/index.cjs +144 -0
- package/dist/plugins/index.d.ts +23 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +115 -0
- package/dist/plugins/install-plugin.cjs +211 -0
- package/dist/plugins/install-plugin.d.ts +47 -0
- package/dist/plugins/install-plugin.d.ts.map +1 -0
- package/dist/plugins/install-plugin.js +173 -0
- package/dist/plugins/list-plugins.cjs +134 -0
- package/dist/plugins/list-plugins.d.ts +26 -0
- package/dist/plugins/list-plugins.d.ts.map +1 -0
- package/dist/plugins/list-plugins.js +99 -0
- package/dist/plugins/load-plugin.cjs +197 -0
- package/dist/plugins/load-plugin.d.ts +20 -0
- package/dist/plugins/load-plugin.d.ts.map +1 -0
- package/dist/plugins/load-plugin.js +163 -0
- package/dist/plugins/marketplace/error-codes.cjs +45 -0
- package/dist/plugins/marketplace/error-codes.d.ts +21 -0
- package/dist/plugins/marketplace/error-codes.d.ts.map +1 -0
- package/dist/plugins/marketplace/error-codes.js +21 -0
- package/dist/plugins/marketplace/errors.cjs +188 -0
- package/dist/plugins/marketplace/errors.d.ts +64 -0
- package/dist/plugins/marketplace/errors.d.ts.map +1 -0
- package/dist/plugins/marketplace/errors.js +164 -0
- package/dist/plugins/marketplace/index.cjs +95 -0
- package/dist/plugins/marketplace/index.d.ts +14 -0
- package/dist/plugins/marketplace/index.d.ts.map +1 -0
- package/dist/plugins/marketplace/index.js +74 -0
- package/dist/plugins/marketplace/install-from-marketplace.cjs +152 -0
- package/dist/plugins/marketplace/install-from-marketplace.d.ts +25 -0
- package/dist/plugins/marketplace/install-from-marketplace.d.ts.map +1 -0
- package/dist/plugins/marketplace/install-from-marketplace.js +120 -0
- package/dist/plugins/marketplace/operations.cjs +374 -0
- package/dist/plugins/marketplace/operations.d.ts +43 -0
- package/dist/plugins/marketplace/operations.d.ts.map +1 -0
- package/dist/plugins/marketplace/operations.js +339 -0
- package/dist/plugins/marketplace/registry.cjs +166 -0
- package/dist/plugins/marketplace/registry.d.ts +72 -0
- package/dist/plugins/marketplace/registry.d.ts.map +1 -0
- package/dist/plugins/marketplace/registry.js +119 -0
- package/dist/plugins/marketplace/schemas.cjs +79 -0
- package/dist/plugins/marketplace/schemas.d.ts +260 -0
- package/dist/plugins/marketplace/schemas.d.ts.map +1 -0
- package/dist/plugins/marketplace/schemas.js +49 -0
- package/dist/plugins/marketplace/types.cjs +16 -0
- package/dist/plugins/marketplace/types.d.ts +156 -0
- package/dist/plugins/marketplace/types.d.ts.map +1 -0
- package/dist/plugins/marketplace/types.js +0 -0
- package/dist/plugins/schemas.cjs +74 -0
- package/dist/plugins/schemas.d.ts +262 -0
- package/dist/plugins/schemas.d.ts.map +1 -0
- package/dist/plugins/schemas.js +46 -0
- package/dist/plugins/types.cjs +16 -0
- package/dist/plugins/types.d.ts +186 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +0 -0
- package/dist/plugins/uninstall-plugin.cjs +133 -0
- package/dist/plugins/uninstall-plugin.d.ts +24 -0
- package/dist/plugins/uninstall-plugin.d.ts.map +1 -0
- package/dist/plugins/uninstall-plugin.js +99 -0
- package/dist/plugins/validate-plugin.cjs +180 -0
- package/dist/plugins/validate-plugin.d.ts +53 -0
- package/dist/plugins/validate-plugin.d.ts.map +1 -0
- package/dist/plugins/validate-plugin.js +145 -0
- package/dist/preferences/schemas.d.ts +12 -12
- package/dist/runtime/AgentRuntime.cjs +1 -2
- package/dist/runtime/AgentRuntime.d.ts.map +1 -1
- package/dist/runtime/AgentRuntime.js +1 -2
- package/dist/tool-provider/llm-resolution.cjs +74 -0
- package/dist/tool-provider/llm-resolution.d.ts +51 -0
- package/dist/tool-provider/llm-resolution.d.ts.map +1 -0
- package/dist/tool-provider/llm-resolution.js +50 -0
- package/dist/tool-provider/runtime-service.cjs +158 -23
- package/dist/tool-provider/runtime-service.d.ts +32 -2
- package/dist/tool-provider/runtime-service.d.ts.map +1 -1
- package/dist/tool-provider/runtime-service.js +158 -23
- package/dist/tool-provider/tool-provider.cjs +2 -0
- package/dist/tool-provider/tool-provider.d.ts.map +1 -1
- package/dist/tool-provider/tool-provider.js +2 -0
- package/dist/tool-provider/types.d.ts +2 -0
- package/dist/tool-provider/types.d.ts.map +1 -1
- package/dist/utils/api-key-resolver.cjs +5 -2
- package/dist/utils/api-key-resolver.d.ts.map +1 -1
- package/dist/utils/api-key-resolver.js +5 -2
- package/dist/utils/dexto-auth.cjs +83 -0
- package/dist/utils/dexto-auth.d.ts +23 -0
- package/dist/utils/dexto-auth.d.ts.map +1 -0
- package/dist/utils/dexto-auth.js +57 -0
- package/dist/utils/feature-flags.cjs +30 -0
- package/dist/utils/feature-flags.d.ts +21 -0
- package/dist/utils/feature-flags.d.ts.map +1 -0
- package/dist/utils/feature-flags.js +6 -0
- package/package.json +2 -2
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
* - Enforces per-parent agent limits
|
|
11
11
|
* - Always cleans up agents after task completion (synchronous model)
|
|
12
12
|
*/
|
|
13
|
-
import type { DextoAgent, IDextoLogger } from '@dexto/core';
|
|
13
|
+
import type { DextoAgent, IDextoLogger, TaskForker } from '@dexto/core';
|
|
14
14
|
import type { AgentRegistryEntry } from '../registry/types.js';
|
|
15
15
|
import type { AgentSpawnerConfig } from './schemas.js';
|
|
16
16
|
import type { SpawnAgentOutput } from './types.js';
|
|
17
|
-
export declare class RuntimeService {
|
|
17
|
+
export declare class RuntimeService implements TaskForker {
|
|
18
18
|
private runtime;
|
|
19
19
|
private parentId;
|
|
20
20
|
private parentAgent;
|
|
@@ -39,6 +39,7 @@ export declare class RuntimeService {
|
|
|
39
39
|
* @param input.task - Short task description (for logging/UI)
|
|
40
40
|
* @param input.instructions - Full prompt sent to sub-agent
|
|
41
41
|
* @param input.agentId - Optional agent ID from registry
|
|
42
|
+
* @param input.autoApprove - Optional override for auto-approve (used by fork skills)
|
|
42
43
|
* @param input.timeout - Optional task timeout in milliseconds
|
|
43
44
|
* @param input.toolCallId - Optional tool call ID for progress events
|
|
44
45
|
* @param input.sessionId - Optional session ID for progress events
|
|
@@ -47,10 +48,34 @@ export declare class RuntimeService {
|
|
|
47
48
|
task: string;
|
|
48
49
|
instructions: string;
|
|
49
50
|
agentId?: string;
|
|
51
|
+
autoApprove?: boolean;
|
|
50
52
|
timeout?: number;
|
|
51
53
|
toolCallId?: string;
|
|
52
54
|
sessionId?: string;
|
|
53
55
|
}): Promise<SpawnAgentOutput>;
|
|
56
|
+
/**
|
|
57
|
+
* Fork execution to an isolated subagent.
|
|
58
|
+
* Implements TaskForker interface for use by invoke_skill when context: fork is set.
|
|
59
|
+
*
|
|
60
|
+
* @param options.task - Short description for UI/logs
|
|
61
|
+
* @param options.instructions - Full instructions for the subagent
|
|
62
|
+
* @param options.agentId - Optional agent ID from registry to use for execution
|
|
63
|
+
* @param options.autoApprove - Auto-approve tool calls (default: true for fork skills)
|
|
64
|
+
* @param options.toolCallId - Optional tool call ID for progress events
|
|
65
|
+
* @param options.sessionId - Optional session ID for progress events
|
|
66
|
+
*/
|
|
67
|
+
fork(options: {
|
|
68
|
+
task: string;
|
|
69
|
+
instructions: string;
|
|
70
|
+
agentId?: string;
|
|
71
|
+
autoApprove?: boolean;
|
|
72
|
+
toolCallId?: string;
|
|
73
|
+
sessionId?: string;
|
|
74
|
+
}): Promise<{
|
|
75
|
+
success: boolean;
|
|
76
|
+
response?: string;
|
|
77
|
+
error?: string;
|
|
78
|
+
}>;
|
|
54
79
|
/**
|
|
55
80
|
* Set up progress event emission for a sub-agent.
|
|
56
81
|
* Subscribes to llm:tool-call and llm:response events and emits service:event with progress data.
|
|
@@ -58,6 +83,10 @@ export declare class RuntimeService {
|
|
|
58
83
|
* @returns Cleanup function to unsubscribe from events
|
|
59
84
|
*/
|
|
60
85
|
private setupProgressTracking;
|
|
86
|
+
/**
|
|
87
|
+
* Check if an error is LLM-related (API errors, credit issues, model not found, etc.)
|
|
88
|
+
*/
|
|
89
|
+
private isLLMError;
|
|
61
90
|
/**
|
|
62
91
|
* Try to spawn agent, falling back to parent's LLM config if the sub-agent's config fails
|
|
63
92
|
*/
|
|
@@ -68,6 +97,7 @@ export declare class RuntimeService {
|
|
|
68
97
|
* @param options.agentId - Agent ID from registry
|
|
69
98
|
* @param options.inheritLlm - Use parent's LLM config instead of sub-agent's
|
|
70
99
|
* @param options.autoApprove - Auto-approve all tool calls
|
|
100
|
+
* @param sessionId - Optional session ID to get session-specific LLM config
|
|
71
101
|
*/
|
|
72
102
|
private buildSubAgentConfig;
|
|
73
103
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-service.d.ts","sourceRoot":"","sources":["../../src/tool-provider/runtime-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAe,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime-service.d.ts","sourceRoot":"","sources":["../../src/tool-provider/runtime-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAe,UAAU,EAAE,MAAM,aAAa,CAAC;AAMrF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,qBAAa,cAAe,YAAW,UAAU;IAC7C,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,MAAM,CAAe;gBAEjB,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,YAAY;IAuBrF;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAIhB;;;;;;;;;;;;;;OAcG;IACG,eAAe,CAAC,KAAK,EAAE;QACzB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA8C7B;;;;;;;;;;OAUG;IACG,IAAI,CAAC,OAAO,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IA6BpE;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IAiH7B;;OAEG;IACH,OAAO,CAAC,UAAU;IAsBlB;;OAEG;YACW,oBAAoB;IAyPlC;;;;;;;OAOG;YACW,mBAAmB;IA2GjC;;;OAGG;IACH,kBAAkB,IAAI,kBAAkB,EAAE;IAoB1C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAIjC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { DextoRuntimeError, ErrorType } from "@dexto/core";
|
|
1
2
|
import { AgentRuntime } from "../runtime/AgentRuntime.js";
|
|
2
3
|
import { createDelegatingApprovalHandler } from "../runtime/approval-delegation.js";
|
|
3
4
|
import { loadAgentConfig } from "../config/loader.js";
|
|
4
5
|
import { getAgentRegistry } from "../registry/registry.js";
|
|
6
|
+
import { resolveSubAgentLLM } from "./llm-resolution.js";
|
|
5
7
|
class RuntimeService {
|
|
6
8
|
runtime;
|
|
7
9
|
parentId;
|
|
@@ -46,6 +48,7 @@ class RuntimeService {
|
|
|
46
48
|
* @param input.task - Short task description (for logging/UI)
|
|
47
49
|
* @param input.instructions - Full prompt sent to sub-agent
|
|
48
50
|
* @param input.agentId - Optional agent ID from registry
|
|
51
|
+
* @param input.autoApprove - Optional override for auto-approve (used by fork skills)
|
|
49
52
|
* @param input.timeout - Optional task timeout in milliseconds
|
|
50
53
|
* @param input.toolCallId - Optional tool call ID for progress events
|
|
51
54
|
* @param input.sessionId - Optional session ID for progress events
|
|
@@ -72,10 +75,7 @@ class RuntimeService {
|
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
const timeout = input.timeout ?? this.config.defaultTimeout;
|
|
75
|
-
|
|
76
|
-
if (input.agentId && this.config.autoApproveAgents) {
|
|
77
|
-
autoApprove = this.config.autoApproveAgents.includes(input.agentId);
|
|
78
|
-
}
|
|
78
|
+
const autoApprove = input.autoApprove !== void 0 ? input.autoApprove : !!(input.agentId && this.config.autoApproveAgents?.includes(input.agentId));
|
|
79
79
|
const result = await this.trySpawnWithFallback(
|
|
80
80
|
input,
|
|
81
81
|
timeout,
|
|
@@ -85,6 +85,36 @@ class RuntimeService {
|
|
|
85
85
|
);
|
|
86
86
|
return result;
|
|
87
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Fork execution to an isolated subagent.
|
|
90
|
+
* Implements TaskForker interface for use by invoke_skill when context: fork is set.
|
|
91
|
+
*
|
|
92
|
+
* @param options.task - Short description for UI/logs
|
|
93
|
+
* @param options.instructions - Full instructions for the subagent
|
|
94
|
+
* @param options.agentId - Optional agent ID from registry to use for execution
|
|
95
|
+
* @param options.autoApprove - Auto-approve tool calls (default: true for fork skills)
|
|
96
|
+
* @param options.toolCallId - Optional tool call ID for progress events
|
|
97
|
+
* @param options.sessionId - Optional session ID for progress events
|
|
98
|
+
*/
|
|
99
|
+
async fork(options) {
|
|
100
|
+
const spawnOptions = {
|
|
101
|
+
task: options.task,
|
|
102
|
+
instructions: options.instructions
|
|
103
|
+
};
|
|
104
|
+
if (options.agentId) {
|
|
105
|
+
spawnOptions.agentId = options.agentId;
|
|
106
|
+
}
|
|
107
|
+
if (options.autoApprove !== void 0) {
|
|
108
|
+
spawnOptions.autoApprove = options.autoApprove;
|
|
109
|
+
}
|
|
110
|
+
if (options.toolCallId) {
|
|
111
|
+
spawnOptions.toolCallId = options.toolCallId;
|
|
112
|
+
}
|
|
113
|
+
if (options.sessionId) {
|
|
114
|
+
spawnOptions.sessionId = options.sessionId;
|
|
115
|
+
}
|
|
116
|
+
return this.spawnAndExecute(spawnOptions);
|
|
117
|
+
}
|
|
88
118
|
/**
|
|
89
119
|
* Set up progress event emission for a sub-agent.
|
|
90
120
|
* Subscribes to llm:tool-call and llm:response events and emits service:event with progress data.
|
|
@@ -160,12 +190,25 @@ class RuntimeService {
|
|
|
160
190
|
subAgentBus.off("llm:response", responseHandler);
|
|
161
191
|
};
|
|
162
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Check if an error is LLM-related (API errors, credit issues, model not found, etc.)
|
|
195
|
+
*/
|
|
196
|
+
isLLMError(error) {
|
|
197
|
+
if (error instanceof DextoRuntimeError) {
|
|
198
|
+
if (error.scope === "llm") return true;
|
|
199
|
+
if (error.type === ErrorType.PAYMENT_REQUIRED || error.type === ErrorType.FORBIDDEN) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
204
|
+
return msg.includes("model") || msg.includes("provider") || msg.includes("rate limit") || msg.includes("quota");
|
|
205
|
+
}
|
|
163
206
|
/**
|
|
164
207
|
* Try to spawn agent, falling back to parent's LLM config if the sub-agent's config fails
|
|
165
208
|
*/
|
|
166
209
|
async trySpawnWithFallback(input, timeout, autoApprove, toolCallId, sessionId) {
|
|
167
210
|
let spawnedAgentId;
|
|
168
|
-
let
|
|
211
|
+
let llmMode = "subagent";
|
|
169
212
|
let cleanupProgressTracking;
|
|
170
213
|
try {
|
|
171
214
|
const buildOptions = {};
|
|
@@ -175,7 +218,7 @@ class RuntimeService {
|
|
|
175
218
|
if (autoApprove) {
|
|
176
219
|
buildOptions.autoApprove = autoApprove;
|
|
177
220
|
}
|
|
178
|
-
let subAgentConfig = await this.buildSubAgentConfig(buildOptions);
|
|
221
|
+
let subAgentConfig = await this.buildSubAgentConfig(buildOptions, sessionId);
|
|
179
222
|
let handle;
|
|
180
223
|
try {
|
|
181
224
|
handle = await this.runtime.spawnAgent({
|
|
@@ -201,15 +244,15 @@ class RuntimeService {
|
|
|
201
244
|
});
|
|
202
245
|
spawnedAgentId = handle.agentId;
|
|
203
246
|
} catch (spawnError) {
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
247
|
+
const isLlmError = this.isLLMError(spawnError);
|
|
248
|
+
if (isLlmError && input.agentId && llmMode === "subagent") {
|
|
249
|
+
const errorMsg = spawnError instanceof Error ? spawnError.message : String(spawnError);
|
|
207
250
|
this.logger.warn(
|
|
208
|
-
`Sub-agent LLM config failed: ${errorMsg}. Falling back to parent's LLM config.`
|
|
251
|
+
`Sub-agent '${input.agentId}' LLM config failed: ${errorMsg}. Falling back to parent's full LLM config.`
|
|
209
252
|
);
|
|
210
|
-
|
|
253
|
+
llmMode = "parent";
|
|
211
254
|
buildOptions.inheritLlm = true;
|
|
212
|
-
subAgentConfig = await this.buildSubAgentConfig(buildOptions);
|
|
255
|
+
subAgentConfig = await this.buildSubAgentConfig(buildOptions, sessionId);
|
|
213
256
|
handle = await this.runtime.spawnAgent({
|
|
214
257
|
agentConfig: subAgentConfig,
|
|
215
258
|
ephemeral: true,
|
|
@@ -218,7 +261,8 @@ class RuntimeService {
|
|
|
218
261
|
parentId: this.parentId,
|
|
219
262
|
task: input.task,
|
|
220
263
|
autoApprove,
|
|
221
|
-
|
|
264
|
+
llmMode: "parent",
|
|
265
|
+
fallbackStage: "spawn",
|
|
222
266
|
spawnedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
223
267
|
},
|
|
224
268
|
onBeforeStart: (agent) => {
|
|
@@ -238,7 +282,7 @@ class RuntimeService {
|
|
|
238
282
|
}
|
|
239
283
|
}
|
|
240
284
|
this.logger.info(
|
|
241
|
-
`Spawned sub-agent '${spawnedAgentId}' for task: ${input.task}${autoApprove ? " (auto-approve)" : ""}${
|
|
285
|
+
`Spawned sub-agent '${spawnedAgentId}' for task: ${input.task}${autoApprove ? " (auto-approve)" : ""}${llmMode === "parent" ? " (using parent LLM)" : ""}`
|
|
242
286
|
);
|
|
243
287
|
cleanupProgressTracking = this.setupProgressTracking(
|
|
244
288
|
handle,
|
|
@@ -246,11 +290,74 @@ class RuntimeService {
|
|
|
246
290
|
toolCallId,
|
|
247
291
|
sessionId
|
|
248
292
|
);
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
293
|
+
let result;
|
|
294
|
+
try {
|
|
295
|
+
result = await this.runtime.executeTask(
|
|
296
|
+
spawnedAgentId,
|
|
297
|
+
input.instructions,
|
|
298
|
+
timeout
|
|
299
|
+
);
|
|
300
|
+
} catch (execError) {
|
|
301
|
+
const isLlmExecError = this.isLLMError(execError);
|
|
302
|
+
if (llmMode === "parent") {
|
|
303
|
+
throw execError;
|
|
304
|
+
}
|
|
305
|
+
if (isLlmExecError && input.agentId && llmMode === "subagent") {
|
|
306
|
+
this.logger.warn(
|
|
307
|
+
`Sub-agent '${input.agentId}' LLM error during execution: ${execError instanceof Error ? execError.message : String(execError)}. Retrying with parent's full LLM config.`
|
|
308
|
+
);
|
|
309
|
+
try {
|
|
310
|
+
await this.runtime.stopAgent(spawnedAgentId);
|
|
311
|
+
} catch {
|
|
312
|
+
}
|
|
313
|
+
if (cleanupProgressTracking) {
|
|
314
|
+
cleanupProgressTracking();
|
|
315
|
+
}
|
|
316
|
+
llmMode = "parent";
|
|
317
|
+
buildOptions.inheritLlm = true;
|
|
318
|
+
subAgentConfig = await this.buildSubAgentConfig(buildOptions, sessionId);
|
|
319
|
+
handle = await this.runtime.spawnAgent({
|
|
320
|
+
agentConfig: subAgentConfig,
|
|
321
|
+
ephemeral: true,
|
|
322
|
+
group: this.parentId,
|
|
323
|
+
metadata: {
|
|
324
|
+
parentId: this.parentId,
|
|
325
|
+
task: input.task,
|
|
326
|
+
autoApprove,
|
|
327
|
+
llmMode: "parent",
|
|
328
|
+
fallbackStage: "execution",
|
|
329
|
+
spawnedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
330
|
+
},
|
|
331
|
+
onBeforeStart: (agent) => {
|
|
332
|
+
if (!autoApprove) {
|
|
333
|
+
const delegatingHandler = createDelegatingApprovalHandler(
|
|
334
|
+
this.parentAgent.services.approvalManager,
|
|
335
|
+
agent.config.agentId ?? "unknown",
|
|
336
|
+
this.logger
|
|
337
|
+
);
|
|
338
|
+
agent.setApprovalHandler(delegatingHandler);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
spawnedAgentId = handle.agentId;
|
|
343
|
+
this.logger.info(
|
|
344
|
+
`Re-spawned sub-agent '${spawnedAgentId}' for task: ${input.task} (using parent LLM)`
|
|
345
|
+
);
|
|
346
|
+
cleanupProgressTracking = this.setupProgressTracking(
|
|
347
|
+
handle,
|
|
348
|
+
input,
|
|
349
|
+
toolCallId,
|
|
350
|
+
sessionId
|
|
351
|
+
);
|
|
352
|
+
result = await this.runtime.executeTask(
|
|
353
|
+
spawnedAgentId,
|
|
354
|
+
input.instructions,
|
|
355
|
+
timeout
|
|
356
|
+
);
|
|
357
|
+
} else {
|
|
358
|
+
throw execError;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
254
361
|
const output = {
|
|
255
362
|
success: result.success
|
|
256
363
|
};
|
|
@@ -260,6 +367,9 @@ class RuntimeService {
|
|
|
260
367
|
if (result.error !== void 0) {
|
|
261
368
|
output.error = result.error;
|
|
262
369
|
}
|
|
370
|
+
if (llmMode === "parent") {
|
|
371
|
+
output.warning = `Sub-agent '${input.agentId}' used fallback LLM (parent's full config) due to an error with its configured model.`;
|
|
372
|
+
}
|
|
263
373
|
return output;
|
|
264
374
|
} catch (error) {
|
|
265
375
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -286,10 +396,15 @@ class RuntimeService {
|
|
|
286
396
|
* @param options.agentId - Agent ID from registry
|
|
287
397
|
* @param options.inheritLlm - Use parent's LLM config instead of sub-agent's
|
|
288
398
|
* @param options.autoApprove - Auto-approve all tool calls
|
|
399
|
+
* @param sessionId - Optional session ID to get session-specific LLM config
|
|
289
400
|
*/
|
|
290
|
-
async buildSubAgentConfig(options) {
|
|
401
|
+
async buildSubAgentConfig(options, sessionId) {
|
|
291
402
|
const { agentId, inheritLlm, autoApprove } = options;
|
|
292
403
|
const parentConfig = this.parentAgent.config;
|
|
404
|
+
const currentParentLLM = this.parentAgent.getCurrentLLMConfig(sessionId);
|
|
405
|
+
this.logger.debug(
|
|
406
|
+
`[RuntimeService] Building sub-agent config with LLM: ${currentParentLLM.provider}/${currentParentLLM.model}` + (sessionId ? ` (sessionId: ${sessionId})` : " (no sessionId)")
|
|
407
|
+
);
|
|
293
408
|
const toolConfirmationMode = autoApprove ? "auto-approve" : "manual";
|
|
294
409
|
if (agentId) {
|
|
295
410
|
const registry = getAgentRegistry();
|
|
@@ -301,8 +416,18 @@ class RuntimeService {
|
|
|
301
416
|
const loadedConfig = await loadAgentConfig(configPath, this.logger);
|
|
302
417
|
let llmConfig = loadedConfig.llm;
|
|
303
418
|
if (inheritLlm) {
|
|
304
|
-
this.logger.debug(
|
|
305
|
-
|
|
419
|
+
this.logger.debug(
|
|
420
|
+
`Sub-agent '${agentId}' using parent LLM config (inheritLlm=true)`
|
|
421
|
+
);
|
|
422
|
+
llmConfig = { ...currentParentLLM };
|
|
423
|
+
} else {
|
|
424
|
+
const resolution = resolveSubAgentLLM({
|
|
425
|
+
subAgentLLM: loadedConfig.llm,
|
|
426
|
+
parentLLM: currentParentLLM,
|
|
427
|
+
subAgentId: agentId
|
|
428
|
+
});
|
|
429
|
+
this.logger.debug(`Sub-agent LLM resolution: ${resolution.reason}`);
|
|
430
|
+
llmConfig = resolution.llm;
|
|
306
431
|
}
|
|
307
432
|
return {
|
|
308
433
|
...loadedConfig,
|
|
@@ -320,12 +445,22 @@ class RuntimeService {
|
|
|
320
445
|
}
|
|
321
446
|
}
|
|
322
447
|
const config = {
|
|
323
|
-
llm: { ...
|
|
448
|
+
llm: { ...currentParentLLM },
|
|
324
449
|
// Default system prompt for sub-agents
|
|
325
450
|
systemPrompt: "You are a helpful sub-agent. Complete the task given to you efficiently and concisely.",
|
|
326
451
|
toolConfirmation: {
|
|
327
452
|
mode: toolConfirmationMode
|
|
328
453
|
},
|
|
454
|
+
// Inherit MCP servers from parent so subagent has tool access
|
|
455
|
+
mcpServers: parentConfig.mcpServers ? { ...parentConfig.mcpServers } : {},
|
|
456
|
+
// Inherit internal tools from parent, excluding tools that don't work in subagent context
|
|
457
|
+
// - ask_user: Subagents can't interact with the user directly
|
|
458
|
+
// - invoke_skill: Avoid nested skill invocations for simplicity
|
|
459
|
+
internalTools: parentConfig.internalTools ? parentConfig.internalTools.filter(
|
|
460
|
+
(tool) => tool !== "ask_user" && tool !== "invoke_skill"
|
|
461
|
+
) : [],
|
|
462
|
+
// Inherit custom tools from parent
|
|
463
|
+
customTools: parentConfig.customTools ? [...parentConfig.customTools] : [],
|
|
329
464
|
// Suppress sub-agent console logs entirely using silent transport
|
|
330
465
|
logger: {
|
|
331
466
|
level: "error",
|
|
@@ -30,6 +30,8 @@ const agentSpawnerToolsProvider = {
|
|
|
30
30
|
create: (config, context) => {
|
|
31
31
|
const { logger, agent } = context;
|
|
32
32
|
const service = new import_runtime_service.RuntimeService(agent, config, logger);
|
|
33
|
+
agent.toolManager.setTaskForker(service);
|
|
34
|
+
logger.debug("RuntimeService wired as taskForker for context:fork skill support");
|
|
33
35
|
return [(0, import_spawn_agent_tool.createSpawnAgentTool)(service)];
|
|
34
36
|
},
|
|
35
37
|
metadata: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-provider.d.ts","sourceRoot":"","sources":["../../src/tool-provider/tool-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAgB,MAAM,aAAa,CAAC;AACpE,OAAO,EAA4B,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAIjF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,yBAAyB,EAAE,kBAAkB,CAAC,eAAe,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"tool-provider.d.ts","sourceRoot":"","sources":["../../src/tool-provider/tool-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAgB,MAAM,aAAa,CAAC;AACpE,OAAO,EAA4B,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAIjF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,yBAAyB,EAAE,kBAAkB,CAAC,eAAe,EAAE,kBAAkB,CAwB7F,CAAC"}
|
|
@@ -7,6 +7,8 @@ const agentSpawnerToolsProvider = {
|
|
|
7
7
|
create: (config, context) => {
|
|
8
8
|
const { logger, agent } = context;
|
|
9
9
|
const service = new RuntimeService(agent, config, logger);
|
|
10
|
+
agent.toolManager.setTaskForker(service);
|
|
11
|
+
logger.debug("RuntimeService wired as taskForker for context:fork skill support");
|
|
10
12
|
return [createSpawnAgentTool(service)];
|
|
11
13
|
},
|
|
12
14
|
metadata: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tool-provider/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,8CAA8C;IAC9C,OAAO,EAAE,OAAO,CAAC;IAEjB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tool-provider/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,8CAA8C;IAC9C,OAAO,EAAE,OAAO,CAAC;IAEjB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -32,6 +32,8 @@ const PROVIDER_API_KEY_MAP = {
|
|
|
32
32
|
groq: ["GROQ_API_KEY"],
|
|
33
33
|
cohere: ["COHERE_API_KEY"],
|
|
34
34
|
xai: ["XAI_API_KEY", "X_AI_API_KEY"],
|
|
35
|
+
minimax: ["MINIMAX_API_KEY"],
|
|
36
|
+
glm: ["ZHIPU_API_KEY", "ZHIPUAI_API_KEY"],
|
|
35
37
|
openrouter: ["OPENROUTER_API_KEY"],
|
|
36
38
|
litellm: ["LITELLM_API_KEY", "LITELLM_KEY"],
|
|
37
39
|
glama: ["GLAMA_API_KEY"],
|
|
@@ -47,9 +49,10 @@ const PROVIDER_API_KEY_MAP = {
|
|
|
47
49
|
// Local providers don't require API keys
|
|
48
50
|
local: [],
|
|
49
51
|
// Native node-llama-cpp execution
|
|
50
|
-
ollama: []
|
|
52
|
+
ollama: [],
|
|
51
53
|
// Ollama server (may optionally use OLLAMA_API_KEY for remote servers)
|
|
52
|
-
//
|
|
54
|
+
// Dexto gateway - requires key from `dexto login`
|
|
55
|
+
dexto: ["DEXTO_API_KEY"]
|
|
53
56
|
// perplexity: ['PERPLEXITY_API_KEY'],
|
|
54
57
|
// together: ['TOGETHER_API_KEY'],
|
|
55
58
|
// fireworks: ['FIREWORKS_API_KEY'],
|
|
@@ -1 +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,
|
|
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,CA+B9D,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"}
|
|
@@ -7,6 +7,8 @@ const PROVIDER_API_KEY_MAP = {
|
|
|
7
7
|
groq: ["GROQ_API_KEY"],
|
|
8
8
|
cohere: ["COHERE_API_KEY"],
|
|
9
9
|
xai: ["XAI_API_KEY", "X_AI_API_KEY"],
|
|
10
|
+
minimax: ["MINIMAX_API_KEY"],
|
|
11
|
+
glm: ["ZHIPU_API_KEY", "ZHIPUAI_API_KEY"],
|
|
10
12
|
openrouter: ["OPENROUTER_API_KEY"],
|
|
11
13
|
litellm: ["LITELLM_API_KEY", "LITELLM_KEY"],
|
|
12
14
|
glama: ["GLAMA_API_KEY"],
|
|
@@ -22,9 +24,10 @@ const PROVIDER_API_KEY_MAP = {
|
|
|
22
24
|
// Local providers don't require API keys
|
|
23
25
|
local: [],
|
|
24
26
|
// Native node-llama-cpp execution
|
|
25
|
-
ollama: []
|
|
27
|
+
ollama: [],
|
|
26
28
|
// Ollama server (may optionally use OLLAMA_API_KEY for remote servers)
|
|
27
|
-
//
|
|
29
|
+
// Dexto gateway - requires key from `dexto login`
|
|
30
|
+
dexto: ["DEXTO_API_KEY"]
|
|
28
31
|
// perplexity: ['PERPLEXITY_API_KEY'],
|
|
29
32
|
// together: ['TOGETHER_API_KEY'],
|
|
30
33
|
// fireworks: ['FIREWORKS_API_KEY'],
|
|
@@ -0,0 +1,83 @@
|
|
|
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 dexto_auth_exports = {};
|
|
20
|
+
__export(dexto_auth_exports, {
|
|
21
|
+
canUseDextoProvider: () => canUseDextoProvider,
|
|
22
|
+
getDextoApiKeyFromAuth: () => getDextoApiKeyFromAuth,
|
|
23
|
+
isDextoAuthenticated: () => isDextoAuthenticated
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(dexto_auth_exports);
|
|
26
|
+
var import_fs = require("fs");
|
|
27
|
+
var import_zod = require("zod");
|
|
28
|
+
var import_core = require("@dexto/core");
|
|
29
|
+
const AUTH_CONFIG_FILE = "auth.json";
|
|
30
|
+
const AuthConfigSchema = import_zod.z.object({
|
|
31
|
+
token: import_zod.z.string().min(1),
|
|
32
|
+
expiresAt: import_zod.z.number().optional(),
|
|
33
|
+
dextoApiKey: import_zod.z.string().optional()
|
|
34
|
+
});
|
|
35
|
+
async function isDextoAuthenticated() {
|
|
36
|
+
const authPath = (0, import_core.getDextoGlobalPath)("", AUTH_CONFIG_FILE);
|
|
37
|
+
if (!(0, import_fs.existsSync)(authPath)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const content = await import_fs.promises.readFile(authPath, "utf-8");
|
|
42
|
+
const config = JSON.parse(content);
|
|
43
|
+
const validated = AuthConfigSchema.safeParse(config);
|
|
44
|
+
if (!validated.success) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (validated.data.expiresAt && validated.data.expiresAt < Date.now()) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
} catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function getDextoApiKeyFromAuth() {
|
|
56
|
+
if (process.env.DEXTO_API_KEY) {
|
|
57
|
+
return process.env.DEXTO_API_KEY;
|
|
58
|
+
}
|
|
59
|
+
const authPath = (0, import_core.getDextoGlobalPath)("", AUTH_CONFIG_FILE);
|
|
60
|
+
if (!(0, import_fs.existsSync)(authPath)) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const content = await import_fs.promises.readFile(authPath, "utf-8");
|
|
65
|
+
const config = JSON.parse(content);
|
|
66
|
+
return config.dextoApiKey || null;
|
|
67
|
+
} catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function canUseDextoProvider() {
|
|
72
|
+
const authenticated = await isDextoAuthenticated();
|
|
73
|
+
if (!authenticated) return false;
|
|
74
|
+
const apiKey = await getDextoApiKeyFromAuth();
|
|
75
|
+
if (!apiKey) return false;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
canUseDextoProvider,
|
|
81
|
+
getDextoApiKeyFromAuth,
|
|
82
|
+
isDextoAuthenticated
|
|
83
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dexto Authentication Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides functions to check dexto authentication status.
|
|
5
|
+
* Used by both CLI and server to determine if user can use dexto features.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Check if user is authenticated with Dexto.
|
|
9
|
+
* Returns true if auth.json exists with valid (non-expired) token.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isDextoAuthenticated(): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Get the dexto API key from auth config or environment.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getDextoApiKeyFromAuth(): Promise<string | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Check if user can use Dexto provider.
|
|
18
|
+
* Requires BOTH:
|
|
19
|
+
* 1. User is authenticated (valid auth token)
|
|
20
|
+
* 2. Has DEXTO_API_KEY (from auth config or environment)
|
|
21
|
+
*/
|
|
22
|
+
export declare function canUseDextoProvider(): Promise<boolean>;
|
|
23
|
+
//# sourceMappingURL=dexto-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dexto-auth.d.ts","sourceRoot":"","sources":["../../src/utils/dexto-auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkBH;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC,CAyB7D;AAED;;GAEG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoBrE;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAQ5D"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { existsSync, promises as fs } from "fs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { getDextoGlobalPath } from "@dexto/core";
|
|
4
|
+
const AUTH_CONFIG_FILE = "auth.json";
|
|
5
|
+
const AuthConfigSchema = z.object({
|
|
6
|
+
token: z.string().min(1),
|
|
7
|
+
expiresAt: z.number().optional(),
|
|
8
|
+
dextoApiKey: z.string().optional()
|
|
9
|
+
});
|
|
10
|
+
async function isDextoAuthenticated() {
|
|
11
|
+
const authPath = getDextoGlobalPath("", AUTH_CONFIG_FILE);
|
|
12
|
+
if (!existsSync(authPath)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const content = await fs.readFile(authPath, "utf-8");
|
|
17
|
+
const config = JSON.parse(content);
|
|
18
|
+
const validated = AuthConfigSchema.safeParse(config);
|
|
19
|
+
if (!validated.success) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (validated.data.expiresAt && validated.data.expiresAt < Date.now()) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function getDextoApiKeyFromAuth() {
|
|
31
|
+
if (process.env.DEXTO_API_KEY) {
|
|
32
|
+
return process.env.DEXTO_API_KEY;
|
|
33
|
+
}
|
|
34
|
+
const authPath = getDextoGlobalPath("", AUTH_CONFIG_FILE);
|
|
35
|
+
if (!existsSync(authPath)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const content = await fs.readFile(authPath, "utf-8");
|
|
40
|
+
const config = JSON.parse(content);
|
|
41
|
+
return config.dextoApiKey || null;
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function canUseDextoProvider() {
|
|
47
|
+
const authenticated = await isDextoAuthenticated();
|
|
48
|
+
if (!authenticated) return false;
|
|
49
|
+
const apiKey = await getDextoApiKeyFromAuth();
|
|
50
|
+
if (!apiKey) return false;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
canUseDextoProvider,
|
|
55
|
+
getDextoApiKeyFromAuth,
|
|
56
|
+
isDextoAuthenticated
|
|
57
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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 feature_flags_exports = {};
|
|
20
|
+
__export(feature_flags_exports, {
|
|
21
|
+
isDextoAuthEnabled: () => isDextoAuthEnabled
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(feature_flags_exports);
|
|
24
|
+
function isDextoAuthEnabled() {
|
|
25
|
+
return process.env.DEXTO_FEATURE_AUTH === "true";
|
|
26
|
+
}
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
isDextoAuthEnabled
|
|
30
|
+
});
|