@dexto/agent-management 1.15.0-beta.2 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.cjs +0 -25
- package/dist/auth/index.d.ts +0 -6
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +0 -10
- package/dist/auth/model-auth-handlers.cjs +1 -3
- package/dist/auth/model-auth-handlers.d.ts +1 -6
- package/dist/auth/model-auth-handlers.d.ts.map +1 -1
- package/dist/auth/model-auth-handlers.js +1 -6
- package/dist/config/errors.cjs +6 -6
- package/dist/config/errors.js +6 -6
- package/dist/images/image-store.cjs +4 -2
- package/dist/images/image-store.d.ts.map +1 -1
- package/dist/images/image-store.js +4 -2
- package/dist/index.cjs +29 -40
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -9
- package/dist/installation.cjs +2 -2
- package/dist/installation.js +2 -2
- package/dist/plugins/discover-skills.cjs +2 -5
- package/dist/plugins/discover-skills.d.ts +2 -6
- package/dist/plugins/discover-skills.d.ts.map +1 -1
- package/dist/plugins/discover-skills.js +2 -5
- package/dist/plugins/errors.cjs +2 -2
- package/dist/plugins/errors.js +2 -2
- package/dist/plugins/marketplace/errors.cjs +4 -4
- package/dist/plugins/marketplace/errors.js +4 -4
- package/dist/preferences/errors.cjs +1 -1
- package/dist/preferences/errors.js +1 -1
- package/dist/registry/registry.cjs +3 -3
- package/dist/registry/registry.js +3 -3
- package/dist/resolver.cjs +1 -1
- package/dist/resolver.js +1 -1
- package/dist/tool-factories/agent-spawner/factory.cjs +218 -1
- package/dist/tool-factories/agent-spawner/factory.d.ts.map +1 -1
- package/dist/tool-factories/agent-spawner/factory.js +228 -1
- package/dist/utils/dexto-auth.cjs +58 -3
- package/dist/utils/dexto-auth.d.ts +18 -4
- package/dist/utils/dexto-auth.d.ts.map +1 -1
- package/dist/utils/dexto-auth.js +57 -3
- package/package.json +6 -5
- package/dist/auth/dexto-accounts.cjs +0 -277
- package/dist/auth/dexto-accounts.d.ts +0 -144
- package/dist/auth/dexto-accounts.d.ts.map +0 -1
- package/dist/auth/dexto-accounts.js +0 -230
- package/dist/auth/dexto-cloud.cjs +0 -51
- package/dist/auth/dexto-cloud.d.ts +0 -9
- package/dist/auth/dexto-cloud.d.ts.map +0 -1
- package/dist/auth/dexto-cloud.js +0 -27
- package/dist/auth/dexto-gateway.cjs +0 -162
- package/dist/auth/dexto-gateway.d.ts +0 -55
- package/dist/auth/dexto-gateway.d.ts.map +0 -1
- package/dist/auth/dexto-gateway.js +0 -133
- package/dist/auth/dexto-mcp.cjs +0 -77
- package/dist/auth/dexto-mcp.d.ts +0 -23
- package/dist/auth/dexto-mcp.d.ts.map +0 -1
- package/dist/auth/dexto-mcp.js +0 -49
- package/dist/auth/dexto-sign-in.cjs +0 -345
- package/dist/auth/dexto-sign-in.d.ts +0 -86
- package/dist/auth/dexto-sign-in.d.ts.map +0 -1
- package/dist/auth/dexto-sign-in.js +0 -314
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { TOOL_ACTIVITY, createLocalToolCallHeader, truncateForHeader } from "@dexto/core";
|
|
2
2
|
import { ToolError } from "@dexto/core";
|
|
3
|
+
import {
|
|
4
|
+
ConditionEngine,
|
|
5
|
+
SignalBus,
|
|
6
|
+
TaskRegistry,
|
|
7
|
+
createCheckTaskTool,
|
|
8
|
+
createListTasksTool,
|
|
9
|
+
createWaitForTool,
|
|
10
|
+
WaitForInputSchema,
|
|
11
|
+
CheckTaskInputSchema,
|
|
12
|
+
ListTasksInputSchema
|
|
13
|
+
} from "@dexto/orchestration";
|
|
3
14
|
import {
|
|
4
15
|
AgentSpawnerConfigSchema,
|
|
5
16
|
SpawnAgentInputSchema
|
|
@@ -48,10 +59,152 @@ const agentSpawnerToolsFactory = {
|
|
|
48
59
|
state.runtime.cleanup().catch(() => void 0);
|
|
49
60
|
}
|
|
50
61
|
state = void 0;
|
|
62
|
+
const signalBus = new SignalBus();
|
|
63
|
+
const taskRegistry = new TaskRegistry(signalBus);
|
|
64
|
+
const conditionEngine = new ConditionEngine(taskRegistry, signalBus, logger);
|
|
51
65
|
const spawnerRuntime = new AgentSpawnerRuntime(agent, config, logger);
|
|
52
66
|
updateWorkspaceRootHint(spawnerRuntime, context);
|
|
53
67
|
attachTaskForker({ toolServices, taskForker: spawnerRuntime, logger });
|
|
68
|
+
const taskSessions = /* @__PURE__ */ new Map();
|
|
69
|
+
const taskHostRuntimeContexts = /* @__PURE__ */ new Map();
|
|
70
|
+
const emitTasksUpdate = (sessionId) => {
|
|
71
|
+
const tasks = taskRegistry.list({
|
|
72
|
+
status: ["running", "completed", "failed", "cancelled"]
|
|
73
|
+
});
|
|
74
|
+
const scopedTasks = sessionId ? tasks.filter((task) => taskSessions.get(task.taskId) === sessionId) : tasks;
|
|
75
|
+
const runningCount = scopedTasks.filter((task) => task.status === "running").length;
|
|
76
|
+
agent.emit("service:event", {
|
|
77
|
+
service: "orchestration",
|
|
78
|
+
event: "tasks-updated",
|
|
79
|
+
sessionId: sessionId ?? "",
|
|
80
|
+
data: {
|
|
81
|
+
runningCount,
|
|
82
|
+
tasks: scopedTasks.map((task) => ({
|
|
83
|
+
taskId: task.taskId,
|
|
84
|
+
status: task.status,
|
|
85
|
+
...task.description !== void 0 && {
|
|
86
|
+
description: task.description
|
|
87
|
+
}
|
|
88
|
+
}))
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const triggerBackgroundCompletion = (taskId, sessionId, hostRuntime) => {
|
|
93
|
+
if (!sessionId) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
agent.emit("tool:background-completed", {
|
|
97
|
+
toolCallId: taskId,
|
|
98
|
+
sessionId,
|
|
99
|
+
...hostRuntime !== void 0 && { hostRuntime }
|
|
100
|
+
});
|
|
101
|
+
const taskInfo = taskRegistry.getInfo(taskId);
|
|
102
|
+
const resultText = (() => {
|
|
103
|
+
if (taskInfo?.status === "failed") {
|
|
104
|
+
return taskInfo.error ?? "Unknown error.";
|
|
105
|
+
}
|
|
106
|
+
if (taskInfo?.result !== void 0) {
|
|
107
|
+
if (typeof taskInfo.result === "string") {
|
|
108
|
+
return taskInfo.result;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
return JSON.stringify(taskInfo.result, null, 2);
|
|
112
|
+
} catch {
|
|
113
|
+
return String(taskInfo.result ?? "<unserializable result>");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return "No result available.";
|
|
117
|
+
})();
|
|
118
|
+
const sanitizeCdata = (value) => value.replace(/\]\]>/g, "]]]]><![CDATA[>");
|
|
119
|
+
const safeDescription = taskInfo?.description ? sanitizeCdata(taskInfo.description) : null;
|
|
120
|
+
const safeResultText = sanitizeCdata(resultText);
|
|
121
|
+
const descriptionTag = safeDescription ? ` <description><![CDATA[${safeDescription}]]></description>
|
|
122
|
+
` : "";
|
|
123
|
+
const statusTag = taskInfo?.status ? ` <status>${taskInfo.status}</status>
|
|
124
|
+
` : "";
|
|
125
|
+
const content = [
|
|
126
|
+
{
|
|
127
|
+
type: "text",
|
|
128
|
+
text: `<background-task-completion>
|
|
129
|
+
<origin>task</origin>
|
|
130
|
+
<note>The following response was reported by the background task (not user input).</note>
|
|
131
|
+
<taskId>${taskId}</taskId>
|
|
132
|
+
` + statusTag + descriptionTag + ` <result><![CDATA[${safeResultText}]]></result>
|
|
133
|
+
</background-task-completion>`
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
agent.isSessionBusy(sessionId).then((isBusy) => {
|
|
137
|
+
if (isBusy) {
|
|
138
|
+
agent.steer(sessionId, {
|
|
139
|
+
content,
|
|
140
|
+
kind: "background"
|
|
141
|
+
}).catch(() => void 0);
|
|
142
|
+
} else {
|
|
143
|
+
agent.emit("run:invoke", {
|
|
144
|
+
sessionId,
|
|
145
|
+
content,
|
|
146
|
+
source: "external",
|
|
147
|
+
metadata: { taskId },
|
|
148
|
+
...hostRuntime !== void 0 && { hostRuntime }
|
|
149
|
+
});
|
|
150
|
+
agent.generate(content, sessionId, {
|
|
151
|
+
...hostRuntime !== void 0 && {
|
|
152
|
+
executionContext: hostRuntime
|
|
153
|
+
}
|
|
154
|
+
}).catch(() => void 0);
|
|
155
|
+
}
|
|
156
|
+
}).catch(() => {
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
const handleBackground = (event) => {
|
|
160
|
+
const taskId = event.toolCallId;
|
|
161
|
+
if (taskRegistry.has(taskId)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (event.sessionId) {
|
|
165
|
+
taskSessions.set(taskId, event.sessionId);
|
|
166
|
+
}
|
|
167
|
+
if (event.hostRuntime !== void 0) {
|
|
168
|
+
taskHostRuntimeContexts.set(taskId, event.hostRuntime);
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
taskRegistry.register(
|
|
172
|
+
{
|
|
173
|
+
type: "generic",
|
|
174
|
+
taskId,
|
|
175
|
+
description: event.description ?? `Tool ${event.toolName}`,
|
|
176
|
+
promise: event.promise
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
...event.timeoutMs !== void 0 && { timeout: event.timeoutMs },
|
|
180
|
+
...event.notifyOnComplete !== void 0 && {
|
|
181
|
+
notify: event.notifyOnComplete
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
taskSessions.delete(taskId);
|
|
187
|
+
taskHostRuntimeContexts.delete(taskId);
|
|
188
|
+
event.promise.catch(() => void 0);
|
|
189
|
+
logger.warn(
|
|
190
|
+
`Failed to register background task ${taskId}: ${error instanceof Error ? error.message : String(error)}`,
|
|
191
|
+
{ color: "yellow" }
|
|
192
|
+
);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
emitTasksUpdate(event.sessionId);
|
|
196
|
+
event.promise.finally(() => {
|
|
197
|
+
taskSessions.delete(taskId);
|
|
198
|
+
const hostRuntime = taskHostRuntimeContexts.get(taskId);
|
|
199
|
+
taskHostRuntimeContexts.delete(taskId);
|
|
200
|
+
emitTasksUpdate(event.sessionId);
|
|
201
|
+
triggerBackgroundCompletion(taskId, event.sessionId, hostRuntime);
|
|
202
|
+
});
|
|
203
|
+
};
|
|
54
204
|
const abortController = new AbortController();
|
|
205
|
+
agent.on("tool:background", handleBackground, {
|
|
206
|
+
signal: abortController.signal
|
|
207
|
+
});
|
|
55
208
|
agent.on(
|
|
56
209
|
"agent:stopped",
|
|
57
210
|
() => {
|
|
@@ -61,8 +214,14 @@ const agentSpawnerToolsFactory = {
|
|
|
61
214
|
{ signal: abortController.signal }
|
|
62
215
|
);
|
|
63
216
|
const spawnAgentTool = createSpawnAgentTool(spawnerRuntime);
|
|
217
|
+
const waitForTool = createWaitForTool(conditionEngine);
|
|
218
|
+
const checkTaskTool = createCheckTaskTool(taskRegistry);
|
|
219
|
+
const listTasksTool = createListTasksTool(taskRegistry);
|
|
64
220
|
const tools = {
|
|
65
|
-
spawnAgent: spawnAgentTool
|
|
221
|
+
spawnAgent: spawnAgentTool,
|
|
222
|
+
waitFor: waitForTool,
|
|
223
|
+
checkTask: checkTaskTool,
|
|
224
|
+
listTasks: listTasksTool
|
|
66
225
|
};
|
|
67
226
|
state = {
|
|
68
227
|
agent,
|
|
@@ -107,6 +266,74 @@ const agentSpawnerToolsFactory = {
|
|
|
107
266
|
return await previewFn(input, context);
|
|
108
267
|
}
|
|
109
268
|
}
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
id: "wait_for",
|
|
272
|
+
description: "Wait for background task(s) to complete.",
|
|
273
|
+
inputSchema: WaitForInputSchema,
|
|
274
|
+
execute: (input, context) => ensureToolsInitialized(context).waitFor.execute(input, context),
|
|
275
|
+
presentation: {
|
|
276
|
+
activity: TOOL_ACTIVITY.wait,
|
|
277
|
+
describeHeader: (input) => {
|
|
278
|
+
const argsText = input.taskId ? truncateForHeader(input.taskId, 80) : input.taskIds && input.taskIds.length > 0 ? truncateForHeader(`${input.taskIds.length} tasks`, 80) : void 0;
|
|
279
|
+
return createLocalToolCallHeader({
|
|
280
|
+
title: "Wait",
|
|
281
|
+
...argsText ? { argsText } : {}
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
preview: async (input, context) => {
|
|
285
|
+
const tool = ensureToolsInitialized(context).waitFor;
|
|
286
|
+
const previewFn = tool.presentation?.preview;
|
|
287
|
+
if (!previewFn) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
return await previewFn(input, context);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: "check_task",
|
|
296
|
+
description: "Check the status of a background task.",
|
|
297
|
+
inputSchema: CheckTaskInputSchema,
|
|
298
|
+
execute: (input, context) => ensureToolsInitialized(context).checkTask.execute(input, context),
|
|
299
|
+
presentation: {
|
|
300
|
+
activity: TOOL_ACTIVITY.checkTask,
|
|
301
|
+
describeHeader: (input) => {
|
|
302
|
+
const argsText = truncateForHeader(input.taskId, 80);
|
|
303
|
+
return createLocalToolCallHeader({
|
|
304
|
+
title: "Check Task",
|
|
305
|
+
...argsText ? { argsText } : {}
|
|
306
|
+
});
|
|
307
|
+
},
|
|
308
|
+
preview: async (input, context) => {
|
|
309
|
+
const tool = ensureToolsInitialized(context).checkTask;
|
|
310
|
+
const previewFn = tool.presentation?.preview;
|
|
311
|
+
if (!previewFn) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
return await previewFn(input, context);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
id: "list_tasks",
|
|
320
|
+
description: "List background tasks and their statuses.",
|
|
321
|
+
inputSchema: ListTasksInputSchema,
|
|
322
|
+
execute: (input, context) => ensureToolsInitialized(context).listTasks.execute(input, context),
|
|
323
|
+
presentation: {
|
|
324
|
+
activity: TOOL_ACTIVITY.listTasks,
|
|
325
|
+
describeHeader: () => createLocalToolCallHeader({
|
|
326
|
+
title: "List Tasks"
|
|
327
|
+
}),
|
|
328
|
+
preview: async (input, context) => {
|
|
329
|
+
const tool = ensureToolsInitialized(context).listTasks;
|
|
330
|
+
const previewFn = tool.presentation?.preview;
|
|
331
|
+
if (!previewFn) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
return await previewFn(input, context);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
110
337
|
}
|
|
111
338
|
];
|
|
112
339
|
}
|
|
@@ -19,18 +19,73 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var dexto_auth_exports = {};
|
|
20
20
|
__export(dexto_auth_exports, {
|
|
21
21
|
canUseDextoProvider: () => canUseDextoProvider,
|
|
22
|
+
getDextoApiKeyFromAuth: () => getDextoApiKeyFromAuth,
|
|
22
23
|
isDextoAuthenticated: () => isDextoAuthenticated
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(dexto_auth_exports);
|
|
25
|
-
var
|
|
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).optional(),
|
|
32
|
+
refreshToken: import_zod.z.string().optional(),
|
|
33
|
+
expiresAt: import_zod.z.number().optional(),
|
|
34
|
+
createdAt: import_zod.z.number().optional(),
|
|
35
|
+
dextoApiKey: import_zod.z.string().optional(),
|
|
36
|
+
dextoKeyId: import_zod.z.string().optional(),
|
|
37
|
+
dextoApiKeySource: import_zod.z.enum(["provisioned", "user-supplied"]).optional()
|
|
38
|
+
}).refine((data) => data.token || data.dextoApiKey, {
|
|
39
|
+
message: "Either token or dextoApiKey is required"
|
|
40
|
+
});
|
|
41
|
+
async function loadAuthConfig() {
|
|
42
|
+
const authPath = (0, import_core.getDextoGlobalPath)("", AUTH_CONFIG_FILE);
|
|
43
|
+
if (!(0, import_fs.existsSync)(authPath)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const content = await import_fs.promises.readFile(authPath, "utf-8");
|
|
48
|
+
const config = JSON.parse(content);
|
|
49
|
+
const validated = AuthConfigSchema.safeParse(config);
|
|
50
|
+
if (!validated.success) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const auth = validated.data;
|
|
54
|
+
if (auth.expiresAt && auth.expiresAt < Date.now()) {
|
|
55
|
+
if (!auth.refreshToken && !auth.dextoApiKey) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return auth;
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
26
64
|
async function isDextoAuthenticated() {
|
|
27
|
-
return
|
|
65
|
+
return await loadAuthConfig() !== null;
|
|
66
|
+
}
|
|
67
|
+
async function getDextoApiKeyFromAuth() {
|
|
68
|
+
const auth = await loadAuthConfig();
|
|
69
|
+
if (auth?.dextoApiKey?.trim()) {
|
|
70
|
+
const apiKey = auth.dextoApiKey.trim();
|
|
71
|
+
process.env.DEXTO_API_KEY = apiKey;
|
|
72
|
+
return apiKey;
|
|
73
|
+
}
|
|
74
|
+
if (process.env.DEXTO_API_KEY?.trim()) {
|
|
75
|
+
return process.env.DEXTO_API_KEY;
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
28
78
|
}
|
|
29
79
|
async function canUseDextoProvider() {
|
|
30
|
-
|
|
80
|
+
const authenticated = await isDextoAuthenticated();
|
|
81
|
+
if (!authenticated) return false;
|
|
82
|
+
const apiKey = await getDextoApiKeyFromAuth();
|
|
83
|
+
if (!apiKey) return false;
|
|
84
|
+
return true;
|
|
31
85
|
}
|
|
32
86
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33
87
|
0 && (module.exports = {
|
|
34
88
|
canUseDextoProvider,
|
|
89
|
+
getDextoApiKeyFromAuth,
|
|
35
90
|
isDextoAuthenticated
|
|
36
91
|
});
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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 when auth.json contains usable Dexto auth state.
|
|
4
10
|
*/
|
|
5
|
-
/** Signed in to Dexto, or DEXTO_API_KEY is set. */
|
|
6
11
|
export declare function isDextoAuthenticated(): Promise<boolean>;
|
|
7
|
-
/**
|
|
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 has usable Dexto auth state (token, refresh-backed login, or stored API key)
|
|
20
|
+
* 2. Has DEXTO_API_KEY (from auth config or environment)
|
|
21
|
+
*/
|
|
8
22
|
export declare function canUseDextoProvider(): Promise<boolean>;
|
|
9
23
|
//# sourceMappingURL=dexto-auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dexto-auth.d.ts","sourceRoot":"","sources":["../../src/utils/dexto-auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"dexto-auth.d.ts","sourceRoot":"","sources":["../../src/utils/dexto-auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA4DH;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC,CAE7D;AAED;;GAEG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAarE;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAQ5D"}
|
package/dist/utils/dexto-auth.js
CHANGED
|
@@ -1,11 +1,65 @@
|
|
|
1
|
-
import {
|
|
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).optional(),
|
|
7
|
+
refreshToken: z.string().optional(),
|
|
8
|
+
expiresAt: z.number().optional(),
|
|
9
|
+
createdAt: z.number().optional(),
|
|
10
|
+
dextoApiKey: z.string().optional(),
|
|
11
|
+
dextoKeyId: z.string().optional(),
|
|
12
|
+
dextoApiKeySource: z.enum(["provisioned", "user-supplied"]).optional()
|
|
13
|
+
}).refine((data) => data.token || data.dextoApiKey, {
|
|
14
|
+
message: "Either token or dextoApiKey is required"
|
|
15
|
+
});
|
|
16
|
+
async function loadAuthConfig() {
|
|
17
|
+
const authPath = getDextoGlobalPath("", AUTH_CONFIG_FILE);
|
|
18
|
+
if (!existsSync(authPath)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const content = await fs.readFile(authPath, "utf-8");
|
|
23
|
+
const config = JSON.parse(content);
|
|
24
|
+
const validated = AuthConfigSchema.safeParse(config);
|
|
25
|
+
if (!validated.success) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const auth = validated.data;
|
|
29
|
+
if (auth.expiresAt && auth.expiresAt < Date.now()) {
|
|
30
|
+
if (!auth.refreshToken && !auth.dextoApiKey) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return auth;
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
2
39
|
async function isDextoAuthenticated() {
|
|
3
|
-
return
|
|
40
|
+
return await loadAuthConfig() !== null;
|
|
41
|
+
}
|
|
42
|
+
async function getDextoApiKeyFromAuth() {
|
|
43
|
+
const auth = await loadAuthConfig();
|
|
44
|
+
if (auth?.dextoApiKey?.trim()) {
|
|
45
|
+
const apiKey = auth.dextoApiKey.trim();
|
|
46
|
+
process.env.DEXTO_API_KEY = apiKey;
|
|
47
|
+
return apiKey;
|
|
48
|
+
}
|
|
49
|
+
if (process.env.DEXTO_API_KEY?.trim()) {
|
|
50
|
+
return process.env.DEXTO_API_KEY;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
4
53
|
}
|
|
5
54
|
async function canUseDextoProvider() {
|
|
6
|
-
|
|
55
|
+
const authenticated = await isDextoAuthenticated();
|
|
56
|
+
if (!authenticated) return false;
|
|
57
|
+
const apiKey = await getDextoApiKeyFromAuth();
|
|
58
|
+
if (!apiKey) return false;
|
|
59
|
+
return true;
|
|
7
60
|
}
|
|
8
61
|
export {
|
|
9
62
|
canUseDextoProvider,
|
|
63
|
+
getDextoApiKeyFromAuth,
|
|
10
64
|
isDextoAuthenticated
|
|
11
65
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexto/agent-management",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,10 +22,11 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"yaml": "^2.8.3",
|
|
24
24
|
"zod": "^4.3.6",
|
|
25
|
-
"@dexto/agent-config": "1.
|
|
26
|
-
"@dexto/
|
|
27
|
-
"@dexto/
|
|
28
|
-
"@dexto/
|
|
25
|
+
"@dexto/agent-config": "1.16.0",
|
|
26
|
+
"@dexto/core": "1.16.0",
|
|
27
|
+
"@dexto/llm": "1.16.0",
|
|
28
|
+
"@dexto/orchestration": "1.16.0",
|
|
29
|
+
"@dexto/tools-builtins": "1.16.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/node": "^22.13.5"
|