@dexto/agent-management 1.15.0-beta.0 → 1.15.0-beta.1
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/dexto-sign-in.cjs +11 -4
- package/dist/auth/dexto-sign-in.d.ts.map +1 -1
- package/dist/auth/dexto-sign-in.js +11 -4
- package/dist/tool-factories/agent-spawner/factory.cjs +1 -218
- package/dist/tool-factories/agent-spawner/factory.d.ts.map +1 -1
- package/dist/tool-factories/agent-spawner/factory.js +1 -228
- package/package.json +3 -4
|
@@ -171,8 +171,9 @@ ${device.verification_uri_complete}`,
|
|
|
171
171
|
tokenEndpoint: server.token_endpoint
|
|
172
172
|
});
|
|
173
173
|
} catch (error) {
|
|
174
|
+
if (error instanceof TypeError) continue;
|
|
174
175
|
if (!(error instanceof OAuthHttpError)) throw error;
|
|
175
|
-
if (error.code === "authorization_pending") continue;
|
|
176
|
+
if (error.status >= 500 || error.code === "authorization_pending") continue;
|
|
176
177
|
if (error.code === "slow_down") {
|
|
177
178
|
intervalSeconds += 5;
|
|
178
179
|
continue;
|
|
@@ -279,13 +280,19 @@ const OAuthErrorSchema = import_zod.z.object({
|
|
|
279
280
|
});
|
|
280
281
|
async function readJson(response, url) {
|
|
281
282
|
const text = await response.text();
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const reply = OAuthErrorSchema.safeParse(body);
|
|
283
|
+
if (response.ok) return text.length === 0 ? null : JSON.parse(text);
|
|
284
|
+
const reply = OAuthErrorSchema.safeParse(parseOrNull(text));
|
|
285
285
|
const code = reply.success ? reply.data.error ?? null : null;
|
|
286
286
|
const description = (reply.success ? reply.data.error_description : void 0) ?? code ?? `HTTP ${response.status}`;
|
|
287
287
|
throw new OAuthHttpError(response.status, code, `${new URL(url).pathname}: ${description}`);
|
|
288
288
|
}
|
|
289
|
+
function parseOrNull(text) {
|
|
290
|
+
try {
|
|
291
|
+
return JSON.parse(text);
|
|
292
|
+
} catch {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
289
296
|
async function withTimeout(promise, ms, signal) {
|
|
290
297
|
let timer;
|
|
291
298
|
const stop = new Promise((_, reject) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dexto-sign-in.d.ts","sourceRoot":"","sources":["../../src/auth/dexto-sign-in.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,UAAU,EAAoB,MAAM,qBAAqB,CAAC;AAExE,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAU/C,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAC7B,0CAA0C;IAC1C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,uCAAuC;IACvC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED,8FAA8F;AAC9F,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,CAAC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAChC;AAED,8EAA8E;AAC9E,MAAM,WAAW,aAAc,SAAQ,kBAAkB;IACrD,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,WAAW;IACxB,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6CAA6C;IAC7C,Q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AS,CAC3B,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,UAAU,GAClB,OAAO,CAAC,WAAW,CAAC,CAgBtB;AAED,qBAAa,cAAe,SAAQ,KAAK;IACrC,6FAA6F;IAC7F,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM;CAMnE"}
|
|
@@ -143,8 +143,9 @@ ${device.verification_uri_complete}`,
|
|
|
143
143
|
tokenEndpoint: server.token_endpoint
|
|
144
144
|
});
|
|
145
145
|
} catch (error) {
|
|
146
|
+
if (error instanceof TypeError) continue;
|
|
146
147
|
if (!(error instanceof OAuthHttpError)) throw error;
|
|
147
|
-
if (error.code === "authorization_pending") continue;
|
|
148
|
+
if (error.status >= 500 || error.code === "authorization_pending") continue;
|
|
148
149
|
if (error.code === "slow_down") {
|
|
149
150
|
intervalSeconds += 5;
|
|
150
151
|
continue;
|
|
@@ -251,13 +252,19 @@ const OAuthErrorSchema = z.object({
|
|
|
251
252
|
});
|
|
252
253
|
async function readJson(response, url) {
|
|
253
254
|
const text = await response.text();
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const reply = OAuthErrorSchema.safeParse(body);
|
|
255
|
+
if (response.ok) return text.length === 0 ? null : JSON.parse(text);
|
|
256
|
+
const reply = OAuthErrorSchema.safeParse(parseOrNull(text));
|
|
257
257
|
const code = reply.success ? reply.data.error ?? null : null;
|
|
258
258
|
const description = (reply.success ? reply.data.error_description : void 0) ?? code ?? `HTTP ${response.status}`;
|
|
259
259
|
throw new OAuthHttpError(response.status, code, `${new URL(url).pathname}: ${description}`);
|
|
260
260
|
}
|
|
261
|
+
function parseOrNull(text) {
|
|
262
|
+
try {
|
|
263
|
+
return JSON.parse(text);
|
|
264
|
+
} catch {
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
261
268
|
async function withTimeout(promise, ms, signal) {
|
|
262
269
|
let timer;
|
|
263
270
|
const stop = new Promise((_, reject) => {
|
|
@@ -23,7 +23,6 @@ __export(factory_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(factory_exports);
|
|
24
24
|
var import_core = require("@dexto/core");
|
|
25
25
|
var import_core2 = require("@dexto/core");
|
|
26
|
-
var import_orchestration = require("@dexto/orchestration");
|
|
27
26
|
var import_schemas = require("./schemas.js");
|
|
28
27
|
var import_runtime = require("./runtime.js");
|
|
29
28
|
var import_spawn_agent_tool = require("./spawn-agent-tool.js");
|
|
@@ -69,152 +68,10 @@ const agentSpawnerToolsFactory = {
|
|
|
69
68
|
state.runtime.cleanup().catch(() => void 0);
|
|
70
69
|
}
|
|
71
70
|
state = void 0;
|
|
72
|
-
const signalBus = new import_orchestration.SignalBus();
|
|
73
|
-
const taskRegistry = new import_orchestration.TaskRegistry(signalBus);
|
|
74
|
-
const conditionEngine = new import_orchestration.ConditionEngine(taskRegistry, signalBus, logger);
|
|
75
71
|
const spawnerRuntime = new import_runtime.AgentSpawnerRuntime(agent, config, logger);
|
|
76
72
|
updateWorkspaceRootHint(spawnerRuntime, context);
|
|
77
73
|
attachTaskForker({ toolServices, taskForker: spawnerRuntime, logger });
|
|
78
|
-
const taskSessions = /* @__PURE__ */ new Map();
|
|
79
|
-
const taskHostRuntimeContexts = /* @__PURE__ */ new Map();
|
|
80
|
-
const emitTasksUpdate = (sessionId) => {
|
|
81
|
-
const tasks = taskRegistry.list({
|
|
82
|
-
status: ["running", "completed", "failed", "cancelled"]
|
|
83
|
-
});
|
|
84
|
-
const scopedTasks = sessionId ? tasks.filter((task) => taskSessions.get(task.taskId) === sessionId) : tasks;
|
|
85
|
-
const runningCount = scopedTasks.filter((task) => task.status === "running").length;
|
|
86
|
-
agent.emit("service:event", {
|
|
87
|
-
service: "orchestration",
|
|
88
|
-
event: "tasks-updated",
|
|
89
|
-
sessionId: sessionId ?? "",
|
|
90
|
-
data: {
|
|
91
|
-
runningCount,
|
|
92
|
-
tasks: scopedTasks.map((task) => ({
|
|
93
|
-
taskId: task.taskId,
|
|
94
|
-
status: task.status,
|
|
95
|
-
...task.description !== void 0 && {
|
|
96
|
-
description: task.description
|
|
97
|
-
}
|
|
98
|
-
}))
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
const triggerBackgroundCompletion = (taskId, sessionId, hostRuntime) => {
|
|
103
|
-
if (!sessionId) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
agent.emit("tool:background-completed", {
|
|
107
|
-
toolCallId: taskId,
|
|
108
|
-
sessionId,
|
|
109
|
-
...hostRuntime !== void 0 && { hostRuntime }
|
|
110
|
-
});
|
|
111
|
-
const taskInfo = taskRegistry.getInfo(taskId);
|
|
112
|
-
const resultText = (() => {
|
|
113
|
-
if (taskInfo?.status === "failed") {
|
|
114
|
-
return taskInfo.error ?? "Unknown error.";
|
|
115
|
-
}
|
|
116
|
-
if (taskInfo?.result !== void 0) {
|
|
117
|
-
if (typeof taskInfo.result === "string") {
|
|
118
|
-
return taskInfo.result;
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
return JSON.stringify(taskInfo.result, null, 2);
|
|
122
|
-
} catch {
|
|
123
|
-
return String(taskInfo.result ?? "<unserializable result>");
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return "No result available.";
|
|
127
|
-
})();
|
|
128
|
-
const sanitizeCdata = (value) => value.replace(/\]\]>/g, "]]]]><![CDATA[>");
|
|
129
|
-
const safeDescription = taskInfo?.description ? sanitizeCdata(taskInfo.description) : null;
|
|
130
|
-
const safeResultText = sanitizeCdata(resultText);
|
|
131
|
-
const descriptionTag = safeDescription ? ` <description><![CDATA[${safeDescription}]]></description>
|
|
132
|
-
` : "";
|
|
133
|
-
const statusTag = taskInfo?.status ? ` <status>${taskInfo.status}</status>
|
|
134
|
-
` : "";
|
|
135
|
-
const content = [
|
|
136
|
-
{
|
|
137
|
-
type: "text",
|
|
138
|
-
text: `<background-task-completion>
|
|
139
|
-
<origin>task</origin>
|
|
140
|
-
<note>The following response was reported by the background task (not user input).</note>
|
|
141
|
-
<taskId>${taskId}</taskId>
|
|
142
|
-
` + statusTag + descriptionTag + ` <result><![CDATA[${safeResultText}]]></result>
|
|
143
|
-
</background-task-completion>`
|
|
144
|
-
}
|
|
145
|
-
];
|
|
146
|
-
agent.isSessionBusy(sessionId).then((isBusy) => {
|
|
147
|
-
if (isBusy) {
|
|
148
|
-
agent.steer(sessionId, {
|
|
149
|
-
content,
|
|
150
|
-
kind: "background"
|
|
151
|
-
}).catch(() => void 0);
|
|
152
|
-
} else {
|
|
153
|
-
agent.emit("run:invoke", {
|
|
154
|
-
sessionId,
|
|
155
|
-
content,
|
|
156
|
-
source: "external",
|
|
157
|
-
metadata: { taskId },
|
|
158
|
-
...hostRuntime !== void 0 && { hostRuntime }
|
|
159
|
-
});
|
|
160
|
-
agent.generate(content, sessionId, {
|
|
161
|
-
...hostRuntime !== void 0 && {
|
|
162
|
-
executionContext: hostRuntime
|
|
163
|
-
}
|
|
164
|
-
}).catch(() => void 0);
|
|
165
|
-
}
|
|
166
|
-
}).catch(() => {
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
const handleBackground = (event) => {
|
|
170
|
-
const taskId = event.toolCallId;
|
|
171
|
-
if (taskRegistry.has(taskId)) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
if (event.sessionId) {
|
|
175
|
-
taskSessions.set(taskId, event.sessionId);
|
|
176
|
-
}
|
|
177
|
-
if (event.hostRuntime !== void 0) {
|
|
178
|
-
taskHostRuntimeContexts.set(taskId, event.hostRuntime);
|
|
179
|
-
}
|
|
180
|
-
try {
|
|
181
|
-
taskRegistry.register(
|
|
182
|
-
{
|
|
183
|
-
type: "generic",
|
|
184
|
-
taskId,
|
|
185
|
-
description: event.description ?? `Tool ${event.toolName}`,
|
|
186
|
-
promise: event.promise
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
...event.timeoutMs !== void 0 && { timeout: event.timeoutMs },
|
|
190
|
-
...event.notifyOnComplete !== void 0 && {
|
|
191
|
-
notify: event.notifyOnComplete
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
);
|
|
195
|
-
} catch (error) {
|
|
196
|
-
taskSessions.delete(taskId);
|
|
197
|
-
taskHostRuntimeContexts.delete(taskId);
|
|
198
|
-
event.promise.catch(() => void 0);
|
|
199
|
-
logger.warn(
|
|
200
|
-
`Failed to register background task ${taskId}: ${error instanceof Error ? error.message : String(error)}`,
|
|
201
|
-
{ color: "yellow" }
|
|
202
|
-
);
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
emitTasksUpdate(event.sessionId);
|
|
206
|
-
event.promise.finally(() => {
|
|
207
|
-
taskSessions.delete(taskId);
|
|
208
|
-
const hostRuntime = taskHostRuntimeContexts.get(taskId);
|
|
209
|
-
taskHostRuntimeContexts.delete(taskId);
|
|
210
|
-
emitTasksUpdate(event.sessionId);
|
|
211
|
-
triggerBackgroundCompletion(taskId, event.sessionId, hostRuntime);
|
|
212
|
-
});
|
|
213
|
-
};
|
|
214
74
|
const abortController = new AbortController();
|
|
215
|
-
agent.on("tool:background", handleBackground, {
|
|
216
|
-
signal: abortController.signal
|
|
217
|
-
});
|
|
218
75
|
agent.on(
|
|
219
76
|
"agent:stopped",
|
|
220
77
|
() => {
|
|
@@ -224,14 +81,8 @@ const agentSpawnerToolsFactory = {
|
|
|
224
81
|
{ signal: abortController.signal }
|
|
225
82
|
);
|
|
226
83
|
const spawnAgentTool = (0, import_spawn_agent_tool.createSpawnAgentTool)(spawnerRuntime);
|
|
227
|
-
const waitForTool = (0, import_orchestration.createWaitForTool)(conditionEngine);
|
|
228
|
-
const checkTaskTool = (0, import_orchestration.createCheckTaskTool)(taskRegistry);
|
|
229
|
-
const listTasksTool = (0, import_orchestration.createListTasksTool)(taskRegistry);
|
|
230
84
|
const tools = {
|
|
231
|
-
spawnAgent: spawnAgentTool
|
|
232
|
-
waitFor: waitForTool,
|
|
233
|
-
checkTask: checkTaskTool,
|
|
234
|
-
listTasks: listTasksTool
|
|
85
|
+
spawnAgent: spawnAgentTool
|
|
235
86
|
};
|
|
236
87
|
state = {
|
|
237
88
|
agent,
|
|
@@ -276,74 +127,6 @@ const agentSpawnerToolsFactory = {
|
|
|
276
127
|
return await previewFn(input, context);
|
|
277
128
|
}
|
|
278
129
|
}
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
id: "wait_for",
|
|
282
|
-
description: "Wait for background task(s) to complete.",
|
|
283
|
-
inputSchema: import_orchestration.WaitForInputSchema,
|
|
284
|
-
execute: (input, context) => ensureToolsInitialized(context).waitFor.execute(input, context),
|
|
285
|
-
presentation: {
|
|
286
|
-
activity: import_core.TOOL_ACTIVITY.wait,
|
|
287
|
-
describeHeader: (input) => {
|
|
288
|
-
const argsText = input.taskId ? (0, import_core.truncateForHeader)(input.taskId, 80) : input.taskIds && input.taskIds.length > 0 ? (0, import_core.truncateForHeader)(`${input.taskIds.length} tasks`, 80) : void 0;
|
|
289
|
-
return (0, import_core.createLocalToolCallHeader)({
|
|
290
|
-
title: "Wait",
|
|
291
|
-
...argsText ? { argsText } : {}
|
|
292
|
-
});
|
|
293
|
-
},
|
|
294
|
-
preview: async (input, context) => {
|
|
295
|
-
const tool = ensureToolsInitialized(context).waitFor;
|
|
296
|
-
const previewFn = tool.presentation?.preview;
|
|
297
|
-
if (!previewFn) {
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
return await previewFn(input, context);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
{
|
|
305
|
-
id: "check_task",
|
|
306
|
-
description: "Check the status of a background task.",
|
|
307
|
-
inputSchema: import_orchestration.CheckTaskInputSchema,
|
|
308
|
-
execute: (input, context) => ensureToolsInitialized(context).checkTask.execute(input, context),
|
|
309
|
-
presentation: {
|
|
310
|
-
activity: import_core.TOOL_ACTIVITY.checkTask,
|
|
311
|
-
describeHeader: (input) => {
|
|
312
|
-
const argsText = (0, import_core.truncateForHeader)(input.taskId, 80);
|
|
313
|
-
return (0, import_core.createLocalToolCallHeader)({
|
|
314
|
-
title: "Check Task",
|
|
315
|
-
...argsText ? { argsText } : {}
|
|
316
|
-
});
|
|
317
|
-
},
|
|
318
|
-
preview: async (input, context) => {
|
|
319
|
-
const tool = ensureToolsInitialized(context).checkTask;
|
|
320
|
-
const previewFn = tool.presentation?.preview;
|
|
321
|
-
if (!previewFn) {
|
|
322
|
-
return null;
|
|
323
|
-
}
|
|
324
|
-
return await previewFn(input, context);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
id: "list_tasks",
|
|
330
|
-
description: "List background tasks and their statuses.",
|
|
331
|
-
inputSchema: import_orchestration.ListTasksInputSchema,
|
|
332
|
-
execute: (input, context) => ensureToolsInitialized(context).listTasks.execute(input, context),
|
|
333
|
-
presentation: {
|
|
334
|
-
activity: import_core.TOOL_ACTIVITY.listTasks,
|
|
335
|
-
describeHeader: () => (0, import_core.createLocalToolCallHeader)({
|
|
336
|
-
title: "List Tasks"
|
|
337
|
-
}),
|
|
338
|
-
preview: async (input, context) => {
|
|
339
|
-
const tool = ensureToolsInitialized(context).listTasks;
|
|
340
|
-
const previewFn = tool.presentation?.preview;
|
|
341
|
-
if (!previewFn) {
|
|
342
|
-
return null;
|
|
343
|
-
}
|
|
344
|
-
return await previewFn(input, context);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
130
|
}
|
|
348
131
|
];
|
|
349
132
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/agent-spawner/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/agent-spawner/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD,OAAO,EAGH,KAAK,kBAAkB,EAE1B,MAAM,cAAc,CAAC;AA+BtB,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,kBAAkB,CA4HpE,CAAC"}
|
|
@@ -1,16 +1,5 @@
|
|
|
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";
|
|
14
3
|
import {
|
|
15
4
|
AgentSpawnerConfigSchema,
|
|
16
5
|
SpawnAgentInputSchema
|
|
@@ -59,152 +48,10 @@ const agentSpawnerToolsFactory = {
|
|
|
59
48
|
state.runtime.cleanup().catch(() => void 0);
|
|
60
49
|
}
|
|
61
50
|
state = void 0;
|
|
62
|
-
const signalBus = new SignalBus();
|
|
63
|
-
const taskRegistry = new TaskRegistry(signalBus);
|
|
64
|
-
const conditionEngine = new ConditionEngine(taskRegistry, signalBus, logger);
|
|
65
51
|
const spawnerRuntime = new AgentSpawnerRuntime(agent, config, logger);
|
|
66
52
|
updateWorkspaceRootHint(spawnerRuntime, context);
|
|
67
53
|
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
|
-
};
|
|
204
54
|
const abortController = new AbortController();
|
|
205
|
-
agent.on("tool:background", handleBackground, {
|
|
206
|
-
signal: abortController.signal
|
|
207
|
-
});
|
|
208
55
|
agent.on(
|
|
209
56
|
"agent:stopped",
|
|
210
57
|
() => {
|
|
@@ -214,14 +61,8 @@ const agentSpawnerToolsFactory = {
|
|
|
214
61
|
{ signal: abortController.signal }
|
|
215
62
|
);
|
|
216
63
|
const spawnAgentTool = createSpawnAgentTool(spawnerRuntime);
|
|
217
|
-
const waitForTool = createWaitForTool(conditionEngine);
|
|
218
|
-
const checkTaskTool = createCheckTaskTool(taskRegistry);
|
|
219
|
-
const listTasksTool = createListTasksTool(taskRegistry);
|
|
220
64
|
const tools = {
|
|
221
|
-
spawnAgent: spawnAgentTool
|
|
222
|
-
waitFor: waitForTool,
|
|
223
|
-
checkTask: checkTaskTool,
|
|
224
|
-
listTasks: listTasksTool
|
|
65
|
+
spawnAgent: spawnAgentTool
|
|
225
66
|
};
|
|
226
67
|
state = {
|
|
227
68
|
agent,
|
|
@@ -266,74 +107,6 @@ const agentSpawnerToolsFactory = {
|
|
|
266
107
|
return await previewFn(input, context);
|
|
267
108
|
}
|
|
268
109
|
}
|
|
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
|
-
}
|
|
337
110
|
}
|
|
338
111
|
];
|
|
339
112
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexto/agent-management",
|
|
3
|
-
"version": "1.15.0-beta.
|
|
3
|
+
"version": "1.15.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,9 +24,8 @@
|
|
|
24
24
|
"zod": "^4.3.6",
|
|
25
25
|
"@dexto/agent-config": "1.14.4",
|
|
26
26
|
"@dexto/core": "1.14.4",
|
|
27
|
-
"@dexto/
|
|
28
|
-
"@dexto/tools-builtins": "1.14.4"
|
|
29
|
-
"@dexto/llm": "1.14.4"
|
|
27
|
+
"@dexto/llm": "1.14.4",
|
|
28
|
+
"@dexto/tools-builtins": "1.14.4"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
31
|
"@types/node": "^22.13.5"
|