@dexto/agent-management 1.5.8 → 1.6.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/AgentFactory.cjs +5 -9
- package/dist/AgentFactory.d.ts +6 -5
- package/dist/AgentFactory.d.ts.map +1 -1
- package/dist/AgentFactory.js +5 -9
- package/dist/AgentManager.cjs +2 -2
- package/dist/AgentManager.d.ts +1 -1
- package/dist/AgentManager.d.ts.map +1 -1
- package/dist/AgentManager.js +4 -4
- package/dist/agent-creation.cjs +95 -0
- package/dist/agent-creation.d.ts +15 -0
- package/dist/agent-creation.d.ts.map +1 -0
- package/dist/agent-creation.js +78 -0
- package/dist/config/config-enrichment.cjs +0 -11
- package/dist/config/config-enrichment.d.ts +1 -1
- package/dist/config/config-enrichment.d.ts.map +1 -1
- package/dist/config/config-enrichment.js +0 -11
- package/dist/config/config-manager.cjs +4 -4
- package/dist/config/config-manager.d.ts +1 -1
- package/dist/config/config-manager.d.ts.map +1 -1
- package/dist/config/config-manager.js +3 -1
- package/dist/config/loader.d.ts +3 -3
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/images/image-store.cjs +256 -0
- package/dist/images/image-store.d.ts +70 -0
- package/dist/images/image-store.d.ts.map +1 -0
- package/dist/images/image-store.js +210 -0
- package/dist/index.cjs +32 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -1
- package/dist/plugins/discover-plugins.cjs +15 -31
- package/dist/plugins/discover-plugins.d.ts.map +1 -1
- package/dist/plugins/discover-plugins.js +15 -31
- package/dist/plugins/index.cjs +0 -2
- package/dist/plugins/index.d.ts +5 -6
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +0 -2
- package/dist/plugins/list-plugins.cjs +3 -1
- package/dist/plugins/list-plugins.d.ts.map +1 -1
- package/dist/plugins/list-plugins.js +3 -1
- package/dist/plugins/load-plugin.cjs +0 -13
- package/dist/plugins/load-plugin.d.ts +3 -5
- package/dist/plugins/load-plugin.d.ts.map +1 -1
- package/dist/plugins/load-plugin.js +0 -13
- package/dist/plugins/schemas.cjs +1 -11
- package/dist/plugins/schemas.d.ts +14 -69
- package/dist/plugins/schemas.d.ts.map +1 -1
- package/dist/plugins/schemas.js +1 -10
- package/dist/plugins/types.d.ts +2 -20
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/plugins/validate-plugin.cjs +7 -37
- package/dist/plugins/validate-plugin.d.ts +6 -24
- package/dist/plugins/validate-plugin.d.ts.map +1 -1
- package/dist/plugins/validate-plugin.js +8 -38
- package/dist/registry/registry.d.ts +4 -44
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/runtime/AgentPool.d.ts +2 -2
- package/dist/runtime/AgentPool.d.ts.map +1 -1
- package/dist/runtime/AgentRuntime.cjs +20 -15
- package/dist/runtime/AgentRuntime.d.ts +2 -2
- package/dist/runtime/AgentRuntime.d.ts.map +1 -1
- package/dist/runtime/AgentRuntime.js +20 -15
- package/dist/runtime/approval-delegation.d.ts +2 -2
- package/dist/runtime/approval-delegation.d.ts.map +1 -1
- package/dist/runtime/schemas.d.ts +1 -1
- package/dist/runtime/types.d.ts +2 -1
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/{tool-provider → tool-factories/agent-spawner}/error-codes.d.ts +1 -1
- package/dist/tool-factories/agent-spawner/error-codes.d.ts.map +1 -0
- package/dist/{tool-provider → tool-factories/agent-spawner}/errors.d.ts +1 -1
- package/dist/tool-factories/agent-spawner/errors.d.ts.map +1 -0
- package/dist/tool-factories/agent-spawner/factory.cjs +290 -0
- package/dist/tool-factories/agent-spawner/factory.d.ts +4 -0
- package/dist/tool-factories/agent-spawner/factory.d.ts.map +1 -0
- package/dist/tool-factories/agent-spawner/factory.js +279 -0
- package/dist/{tool-provider → tool-factories/agent-spawner}/index.cjs +9 -9
- package/dist/{tool-provider → tool-factories/agent-spawner}/index.d.ts +3 -3
- package/dist/tool-factories/agent-spawner/index.d.ts.map +1 -0
- package/dist/{tool-provider → tool-factories/agent-spawner}/index.js +4 -4
- package/dist/tool-factories/agent-spawner/llm-resolution.d.ts.map +1 -0
- package/dist/{tool-provider/runtime-service.cjs → tool-factories/agent-spawner/runtime.cjs} +33 -71
- package/dist/{tool-provider/runtime-service.d.ts → tool-factories/agent-spawner/runtime.d.ts} +6 -6
- package/dist/tool-factories/agent-spawner/runtime.d.ts.map +1 -0
- package/dist/{tool-provider/runtime-service.js → tool-factories/agent-spawner/runtime.js} +29 -67
- package/dist/{tool-provider → tool-factories/agent-spawner}/schemas.cjs +2 -2
- package/dist/{tool-provider → tool-factories/agent-spawner}/schemas.d.ts +4 -4
- package/dist/tool-factories/agent-spawner/schemas.d.ts.map +1 -0
- package/dist/{tool-provider → tool-factories/agent-spawner}/schemas.js +2 -2
- package/dist/{tool-provider → tool-factories/agent-spawner}/spawn-agent-tool.cjs +8 -7
- package/dist/tool-factories/agent-spawner/spawn-agent-tool.d.ts +11 -0
- package/dist/tool-factories/agent-spawner/spawn-agent-tool.d.ts.map +1 -0
- package/dist/{tool-provider → tool-factories/agent-spawner}/spawn-agent-tool.js +8 -7
- package/dist/tool-factories/agent-spawner/types.d.ts.map +1 -0
- package/dist/writer.d.ts +2 -1
- package/dist/writer.d.ts.map +1 -1
- package/package.json +6 -4
- package/dist/tool-provider/error-codes.d.ts.map +0 -1
- package/dist/tool-provider/errors.d.ts.map +0 -1
- package/dist/tool-provider/index.d.ts.map +0 -1
- package/dist/tool-provider/llm-resolution.d.ts.map +0 -1
- package/dist/tool-provider/runtime-service.d.ts.map +0 -1
- package/dist/tool-provider/schemas.d.ts.map +0 -1
- package/dist/tool-provider/spawn-agent-tool.d.ts +0 -10
- package/dist/tool-provider/spawn-agent-tool.d.ts.map +0 -1
- package/dist/tool-provider/tool-provider.cjs +0 -197
- package/dist/tool-provider/tool-provider.d.ts +0 -30
- package/dist/tool-provider/tool-provider.d.ts.map +0 -1
- package/dist/tool-provider/tool-provider.js +0 -180
- package/dist/tool-provider/types.d.ts.map +0 -1
- /package/dist/{tool-provider → tool-factories/agent-spawner}/error-codes.cjs +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/error-codes.js +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/errors.cjs +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/errors.js +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/llm-resolution.cjs +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/llm-resolution.d.ts +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/llm-resolution.js +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/types.cjs +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/types.d.ts +0 -0
- /package/dist/{tool-provider → tool-factories/agent-spawner}/types.js +0 -0
|
@@ -22,11 +22,10 @@ __export(AgentRuntime_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(AgentRuntime_exports);
|
|
24
24
|
var import_crypto = require("crypto");
|
|
25
|
-
var import_core = require("@dexto/core");
|
|
26
|
-
var import_config = require("../config/index.js");
|
|
27
25
|
var import_AgentPool = require("./AgentPool.js");
|
|
28
26
|
var import_errors = require("./errors.js");
|
|
29
27
|
var import_schemas = require("./schemas.js");
|
|
28
|
+
var import_agent_creation = require("../agent-creation.js");
|
|
30
29
|
class AgentRuntime {
|
|
31
30
|
pool;
|
|
32
31
|
config;
|
|
@@ -55,14 +54,12 @@ class AgentRuntime {
|
|
|
55
54
|
throw import_errors.RuntimeError.agentAlreadyExists(agentId);
|
|
56
55
|
}
|
|
57
56
|
try {
|
|
58
|
-
const
|
|
59
|
-
config.agentConfig,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
);
|
|
64
|
-
enrichedConfig.agentId = agentId;
|
|
65
|
-
const agent = new import_core.DextoAgent(enrichedConfig);
|
|
57
|
+
const agent = await (0, import_agent_creation.createDextoAgentFromConfig)({
|
|
58
|
+
config: config.agentConfig,
|
|
59
|
+
enrichOptions: { isInteractiveCli: false, skipPluginDiscovery: true },
|
|
60
|
+
agentIdOverride: agentId,
|
|
61
|
+
agentContext: "subagent"
|
|
62
|
+
});
|
|
66
63
|
const sessionId = `session-${(0, import_crypto.randomUUID)().slice(0, 8)}`;
|
|
67
64
|
const handle = {
|
|
68
65
|
agentId,
|
|
@@ -113,16 +110,24 @@ class AgentRuntime {
|
|
|
113
110
|
const taskTimeout = timeout ?? this.config.defaultTaskTimeout;
|
|
114
111
|
this.pool.updateStatus(agentId, "running");
|
|
115
112
|
try {
|
|
113
|
+
let timeoutId;
|
|
116
114
|
const timeoutPromise = new Promise((_, reject) => {
|
|
117
|
-
setTimeout(() => {
|
|
115
|
+
timeoutId = setTimeout(() => {
|
|
118
116
|
reject(import_errors.RuntimeError.taskTimeout(agentId, taskTimeout));
|
|
119
117
|
}, taskTimeout);
|
|
120
118
|
});
|
|
121
119
|
const generatePromise = handle.agent.generate(task, handle.sessionId);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
let response;
|
|
121
|
+
try {
|
|
122
|
+
response = await Promise.race([
|
|
123
|
+
generatePromise,
|
|
124
|
+
timeoutPromise
|
|
125
|
+
]);
|
|
126
|
+
} finally {
|
|
127
|
+
if (timeoutId) {
|
|
128
|
+
clearTimeout(timeoutId);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
126
131
|
this.pool.updateStatus(agentId, "idle");
|
|
127
132
|
const result = {
|
|
128
133
|
success: true,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* - Track agent status and lifecycle
|
|
14
14
|
* - Clean up agents when no longer needed
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import type { Logger } from '@dexto/core';
|
|
17
17
|
import type { AgentRuntimeConfig, SpawnConfig, AgentHandle, TaskResult, AgentFilter } from './types.js';
|
|
18
18
|
import { type ValidatedAgentRuntimeConfig } from './schemas.js';
|
|
19
19
|
/**
|
|
@@ -23,7 +23,7 @@ export interface AgentRuntimeOptions {
|
|
|
23
23
|
/** Runtime configuration */
|
|
24
24
|
config?: AgentRuntimeConfig;
|
|
25
25
|
/** Logger instance */
|
|
26
|
-
logger:
|
|
26
|
+
logger: Logger;
|
|
27
27
|
}
|
|
28
28
|
export declare class AgentRuntime {
|
|
29
29
|
private pool;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentRuntime.d.ts","sourceRoot":"","sources":["../../src/runtime/AgentRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,
|
|
1
|
+
{"version":3,"file":"AgentRuntime.d.ts","sourceRoot":"","sources":["../../src/runtime/AgentRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AAG5D,OAAO,KAAK,EACR,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,UAAU,EACV,WAAW,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAA4B,KAAK,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAG1F;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,4BAA4B;IAC5B,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,YAAY;IACrB,OAAO,CAAC,IAAI,CAAY;IACxB,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,MAAM,CAAS;gBAEX,OAAO,EAAE,mBAAmB;IAYxC;;;;;OAKG;IACG,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAoE3D;;;;;;;OAOG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IA4EvF;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAIlD;;OAEG;IACH,UAAU,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,WAAW,EAAE;IAI/C;;OAEG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsC/C;;OAEG;IACG,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IASlD;;OAEG;IACH,SAAS,IAAI,2BAA2B;IAIxC;;OAEG;IACH,QAAQ,IAAI;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE;CAaxE"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
|
-
import { DextoAgent } from "@dexto/core";
|
|
3
|
-
import { enrichAgentConfig } from "../config/index.js";
|
|
4
2
|
import { AgentPool } from "./AgentPool.js";
|
|
5
3
|
import { RuntimeError } from "./errors.js";
|
|
6
4
|
import { AgentRuntimeConfigSchema } from "./schemas.js";
|
|
5
|
+
import { createDextoAgentFromConfig } from "../agent-creation.js";
|
|
7
6
|
class AgentRuntime {
|
|
8
7
|
pool;
|
|
9
8
|
config;
|
|
@@ -32,14 +31,12 @@ class AgentRuntime {
|
|
|
32
31
|
throw RuntimeError.agentAlreadyExists(agentId);
|
|
33
32
|
}
|
|
34
33
|
try {
|
|
35
|
-
const
|
|
36
|
-
config.agentConfig,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
);
|
|
41
|
-
enrichedConfig.agentId = agentId;
|
|
42
|
-
const agent = new DextoAgent(enrichedConfig);
|
|
34
|
+
const agent = await createDextoAgentFromConfig({
|
|
35
|
+
config: config.agentConfig,
|
|
36
|
+
enrichOptions: { isInteractiveCli: false, skipPluginDiscovery: true },
|
|
37
|
+
agentIdOverride: agentId,
|
|
38
|
+
agentContext: "subagent"
|
|
39
|
+
});
|
|
43
40
|
const sessionId = `session-${randomUUID().slice(0, 8)}`;
|
|
44
41
|
const handle = {
|
|
45
42
|
agentId,
|
|
@@ -90,16 +87,24 @@ class AgentRuntime {
|
|
|
90
87
|
const taskTimeout = timeout ?? this.config.defaultTaskTimeout;
|
|
91
88
|
this.pool.updateStatus(agentId, "running");
|
|
92
89
|
try {
|
|
90
|
+
let timeoutId;
|
|
93
91
|
const timeoutPromise = new Promise((_, reject) => {
|
|
94
|
-
setTimeout(() => {
|
|
92
|
+
timeoutId = setTimeout(() => {
|
|
95
93
|
reject(RuntimeError.taskTimeout(agentId, taskTimeout));
|
|
96
94
|
}, taskTimeout);
|
|
97
95
|
});
|
|
98
96
|
const generatePromise = handle.agent.generate(task, handle.sessionId);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
let response;
|
|
98
|
+
try {
|
|
99
|
+
response = await Promise.race([
|
|
100
|
+
generatePromise,
|
|
101
|
+
timeoutPromise
|
|
102
|
+
]);
|
|
103
|
+
} finally {
|
|
104
|
+
if (timeoutId) {
|
|
105
|
+
clearTimeout(timeoutId);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
103
108
|
this.pool.updateStatus(agentId, "idle");
|
|
104
109
|
const result = {
|
|
105
110
|
success: true,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Creates ApprovalHandler instances that delegate approval requests
|
|
5
5
|
* from sub-agents to the parent agent's approval system.
|
|
6
6
|
*/
|
|
7
|
-
import type { ApprovalHandler, ApprovalManager,
|
|
7
|
+
import type { ApprovalHandler, ApprovalManager, Logger } from '@dexto/core';
|
|
8
8
|
/**
|
|
9
9
|
* Creates an ApprovalHandler that delegates requests to a parent's ApprovalManager.
|
|
10
10
|
*
|
|
@@ -26,5 +26,5 @@ import type { ApprovalHandler, ApprovalManager, IDextoLogger } from '@dexto/core
|
|
|
26
26
|
* subAgent.services.approvalManager.setHandler(delegatingHandler);
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
export declare function createDelegatingApprovalHandler(parentApprovalManager: ApprovalManager, subAgentId: string, logger:
|
|
29
|
+
export declare function createDelegatingApprovalHandler(parentApprovalManager: ApprovalManager, subAgentId: string, logger: Logger): ApprovalHandler;
|
|
30
30
|
//# sourceMappingURL=approval-delegation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-delegation.d.ts","sourceRoot":"","sources":["../../src/runtime/approval-delegation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACR,eAAe,EAIf,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"approval-delegation.d.ts","sourceRoot":"","sources":["../../src/runtime/approval-delegation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACR,eAAe,EAIf,eAAe,EACf,MAAM,EACT,MAAM,aAAa,CAAC;AAYrB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,+BAA+B,CAC3C,qBAAqB,EAAE,eAAe,EACtC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACf,eAAe,CAqFjB"}
|
|
@@ -22,7 +22,7 @@ export declare const AgentRuntimeConfigSchema: z.ZodObject<{
|
|
|
22
22
|
export type ValidatedAgentRuntimeConfig = z.output<typeof AgentRuntimeConfigSchema>;
|
|
23
23
|
/**
|
|
24
24
|
* Schema for SpawnConfig
|
|
25
|
-
* Note: agentConfig is not validated here as it uses the
|
|
25
|
+
* Note: agentConfig is not validated here as it uses the agent-config AgentConfigSchema
|
|
26
26
|
*/
|
|
27
27
|
export declare const SpawnConfigSchema: z.ZodObject<{
|
|
28
28
|
agentConfig: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Type definitions for the general-purpose agent runtime system that manages
|
|
5
5
|
* the lifecycle of multiple agent instances.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
7
|
+
import type { AgentConfig } from '@dexto/agent-config';
|
|
8
|
+
import type { DextoAgent } from '@dexto/core';
|
|
8
9
|
/**
|
|
9
10
|
* Configuration for spawning an agent
|
|
10
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/runtime/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/runtime/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,0DAA0D;IAC1D,WAAW,EAAE,WAAW,CAAC;IAEzB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/D;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC;AAE7F;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAEhB,8BAA8B;IAC9B,KAAK,EAAE,UAAU,CAAC;IAElB,kCAAkC;IAClC,MAAM,EAAE,WAAW,CAAC;IAEpB,mEAAmE;IACnE,SAAS,EAAE,OAAO,CAAC;IAEnB,kCAAkC;IAClC,SAAS,EAAE,IAAI,CAAC;IAEhB,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAC;IAElB,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,wBAAwB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,8CAA8C;IAC9C,OAAO,EAAE,OAAO,CAAC;IAEjB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAEhB,+BAA+B;IAC/B,UAAU,CAAC,EAAE;QACT,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;KACjB,CAAC;CACL;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,qEAAqE;IACrE,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,sBAAsB;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,uBAAuB;IACvB,MAAM,CAAC,EAAE,WAAW,GAAG,WAAW,EAAE,CAAC;IAErC,+BAA+B;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/agent-spawner/error-codes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,qBAAqB;IAE7B,iBAAiB,oCAAoC;IACrD,YAAY,+BAA+B;IAG3C,eAAe,kCAAkC;IAGjD,WAAW,8BAA8B;IAGzC,cAAc,iCAAiC;CAClD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/agent-spawner/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAyB,MAAM,aAAa,CAAC;AAGvE;;GAEG;AACH,qBAAa,iBAAiB;IAC1B,MAAM,CAAC,gBAAgB;IAWvB,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM;;;IAWhC,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM;;;IAWpC,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAWhD,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM;CAUvC"}
|
|
@@ -0,0 +1,290 @@
|
|
|
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 factory_exports = {};
|
|
20
|
+
__export(factory_exports, {
|
|
21
|
+
agentSpawnerToolsFactory: () => agentSpawnerToolsFactory
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(factory_exports);
|
|
24
|
+
var import_core = require("@dexto/core");
|
|
25
|
+
var import_orchestration = require("@dexto/orchestration");
|
|
26
|
+
var import_schemas = require("./schemas.js");
|
|
27
|
+
var import_runtime = require("./runtime.js");
|
|
28
|
+
var import_spawn_agent_tool = require("./spawn-agent-tool.js");
|
|
29
|
+
function requireAgentContext(context) {
|
|
30
|
+
if (!context.agent) {
|
|
31
|
+
throw import_core.ToolError.configInvalid("agent-spawner tools require ToolExecutionContext.agent");
|
|
32
|
+
}
|
|
33
|
+
if (!context.services) {
|
|
34
|
+
throw import_core.ToolError.configInvalid("agent-spawner tools require ToolExecutionContext.services");
|
|
35
|
+
}
|
|
36
|
+
return { agent: context.agent, logger: context.logger, toolServices: context.services };
|
|
37
|
+
}
|
|
38
|
+
const agentSpawnerToolsFactory = {
|
|
39
|
+
configSchema: import_schemas.AgentSpawnerConfigSchema,
|
|
40
|
+
metadata: {
|
|
41
|
+
displayName: "Agent Spawner",
|
|
42
|
+
description: "Spawn sub-agents for task delegation",
|
|
43
|
+
category: "agents"
|
|
44
|
+
},
|
|
45
|
+
create: (config) => {
|
|
46
|
+
let state;
|
|
47
|
+
const attachTaskForker = (options) => {
|
|
48
|
+
const { toolServices, taskForker, logger } = options;
|
|
49
|
+
if (toolServices.taskForker !== taskForker) {
|
|
50
|
+
toolServices.taskForker = taskForker;
|
|
51
|
+
logger.debug(
|
|
52
|
+
"AgentSpawnerRuntime attached as taskForker for context:fork skill support"
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const ensureToolsInitialized = (context) => {
|
|
57
|
+
const { agent, logger, toolServices } = requireAgentContext(context);
|
|
58
|
+
if (state && state.agent === agent && !state.abortController.signal.aborted) {
|
|
59
|
+
attachTaskForker({ toolServices, taskForker: state.runtime, logger });
|
|
60
|
+
return state.tools;
|
|
61
|
+
}
|
|
62
|
+
if (state && !state.abortController.signal.aborted) {
|
|
63
|
+
state.abortController.abort();
|
|
64
|
+
}
|
|
65
|
+
if (state) {
|
|
66
|
+
state.runtime.cleanup().catch(() => void 0);
|
|
67
|
+
}
|
|
68
|
+
state = void 0;
|
|
69
|
+
const signalBus = new import_orchestration.SignalBus();
|
|
70
|
+
const taskRegistry = new import_orchestration.TaskRegistry(signalBus);
|
|
71
|
+
const conditionEngine = new import_orchestration.ConditionEngine(taskRegistry, signalBus, logger);
|
|
72
|
+
const spawnerRuntime = new import_runtime.AgentSpawnerRuntime(agent, config, logger);
|
|
73
|
+
attachTaskForker({ toolServices, taskForker: spawnerRuntime, logger });
|
|
74
|
+
const taskSessions = /* @__PURE__ */ new Map();
|
|
75
|
+
const emitTasksUpdate = (sessionId) => {
|
|
76
|
+
const tasks = taskRegistry.list({
|
|
77
|
+
status: ["running", "completed", "failed", "cancelled"]
|
|
78
|
+
});
|
|
79
|
+
const scopedTasks = sessionId ? tasks.filter((task) => taskSessions.get(task.taskId) === sessionId) : tasks;
|
|
80
|
+
const runningCount = scopedTasks.filter((task) => task.status === "running").length;
|
|
81
|
+
agent.emit("service:event", {
|
|
82
|
+
service: "orchestration",
|
|
83
|
+
event: "tasks-updated",
|
|
84
|
+
sessionId: sessionId ?? "",
|
|
85
|
+
data: {
|
|
86
|
+
runningCount,
|
|
87
|
+
tasks: scopedTasks.map((task) => ({
|
|
88
|
+
taskId: task.taskId,
|
|
89
|
+
status: task.status,
|
|
90
|
+
...task.description !== void 0 && {
|
|
91
|
+
description: task.description
|
|
92
|
+
}
|
|
93
|
+
}))
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
const triggerBackgroundCompletion = (taskId, sessionId) => {
|
|
98
|
+
if (!sessionId) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
agent.emit("tool:background-completed", {
|
|
102
|
+
toolCallId: taskId,
|
|
103
|
+
sessionId
|
|
104
|
+
});
|
|
105
|
+
const taskInfo = taskRegistry.getInfo(taskId);
|
|
106
|
+
const resultText = (() => {
|
|
107
|
+
if (taskInfo?.status === "failed") {
|
|
108
|
+
return taskInfo.error ?? "Unknown error.";
|
|
109
|
+
}
|
|
110
|
+
if (taskInfo?.result !== void 0) {
|
|
111
|
+
if (typeof taskInfo.result === "string") {
|
|
112
|
+
return taskInfo.result;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
return JSON.stringify(taskInfo.result, null, 2);
|
|
116
|
+
} catch {
|
|
117
|
+
return String(taskInfo.result ?? "<unserializable result>");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return "No result available.";
|
|
121
|
+
})();
|
|
122
|
+
const sanitizeCdata = (value) => value.replace(/\]\]>/g, "]]]]><![CDATA[>");
|
|
123
|
+
const safeDescription = taskInfo?.description ? sanitizeCdata(taskInfo.description) : null;
|
|
124
|
+
const safeResultText = sanitizeCdata(resultText);
|
|
125
|
+
const descriptionTag = safeDescription ? ` <description><![CDATA[${safeDescription}]]></description>
|
|
126
|
+
` : "";
|
|
127
|
+
const statusTag = taskInfo?.status ? ` <status>${taskInfo.status}</status>
|
|
128
|
+
` : "";
|
|
129
|
+
const content = [
|
|
130
|
+
{
|
|
131
|
+
type: "text",
|
|
132
|
+
text: `<background-task-completion>
|
|
133
|
+
<origin>task</origin>
|
|
134
|
+
<note>The following response was reported by the background task (not user input).</note>
|
|
135
|
+
<taskId>${taskId}</taskId>
|
|
136
|
+
` + statusTag + descriptionTag + ` <result><![CDATA[${safeResultText}]]></result>
|
|
137
|
+
</background-task-completion>`
|
|
138
|
+
}
|
|
139
|
+
];
|
|
140
|
+
agent.isSessionBusy(sessionId).then((isBusy) => {
|
|
141
|
+
if (isBusy) {
|
|
142
|
+
agent.queueMessage(sessionId, {
|
|
143
|
+
content,
|
|
144
|
+
kind: "background"
|
|
145
|
+
}).catch(() => void 0);
|
|
146
|
+
} else {
|
|
147
|
+
agent.emit("run:invoke", {
|
|
148
|
+
sessionId,
|
|
149
|
+
content,
|
|
150
|
+
source: "external",
|
|
151
|
+
metadata: { taskId }
|
|
152
|
+
});
|
|
153
|
+
agent.generate(content, sessionId).catch(() => void 0);
|
|
154
|
+
}
|
|
155
|
+
}).catch(() => {
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
const handleBackground = (event) => {
|
|
159
|
+
const taskId = event.toolCallId;
|
|
160
|
+
if (taskRegistry.has(taskId)) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (event.sessionId) {
|
|
164
|
+
taskSessions.set(taskId, event.sessionId);
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
taskRegistry.register(
|
|
168
|
+
{
|
|
169
|
+
type: "generic",
|
|
170
|
+
taskId,
|
|
171
|
+
description: event.description ?? `Tool ${event.toolName}`,
|
|
172
|
+
promise: event.promise
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
...event.timeoutMs !== void 0 && { timeout: event.timeoutMs },
|
|
176
|
+
...event.notifyOnComplete !== void 0 && {
|
|
177
|
+
notify: event.notifyOnComplete
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
} catch (error) {
|
|
182
|
+
taskSessions.delete(taskId);
|
|
183
|
+
event.promise.catch(() => void 0);
|
|
184
|
+
logger.warn(
|
|
185
|
+
`Failed to register background task ${taskId}: ${error instanceof Error ? error.message : String(error)}`,
|
|
186
|
+
{ color: "yellow" }
|
|
187
|
+
);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
emitTasksUpdate(event.sessionId);
|
|
191
|
+
event.promise.finally(() => {
|
|
192
|
+
taskSessions.delete(taskId);
|
|
193
|
+
emitTasksUpdate(event.sessionId);
|
|
194
|
+
triggerBackgroundCompletion(taskId, event.sessionId);
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
const abortController = new AbortController();
|
|
198
|
+
agent.on("tool:background", handleBackground, {
|
|
199
|
+
signal: abortController.signal
|
|
200
|
+
});
|
|
201
|
+
agent.on(
|
|
202
|
+
"agent:stopped",
|
|
203
|
+
() => {
|
|
204
|
+
spawnerRuntime.cleanup().catch(() => void 0);
|
|
205
|
+
abortController.abort();
|
|
206
|
+
},
|
|
207
|
+
{ signal: abortController.signal }
|
|
208
|
+
);
|
|
209
|
+
const spawnAgentTool = (0, import_spawn_agent_tool.createSpawnAgentTool)(spawnerRuntime);
|
|
210
|
+
const waitForTool = (0, import_orchestration.createWaitForTool)(conditionEngine);
|
|
211
|
+
const checkTaskTool = (0, import_orchestration.createCheckTaskTool)(taskRegistry);
|
|
212
|
+
const listTasksTool = (0, import_orchestration.createListTasksTool)(taskRegistry);
|
|
213
|
+
const tools = {
|
|
214
|
+
spawnAgent: spawnAgentTool,
|
|
215
|
+
waitFor: waitForTool,
|
|
216
|
+
checkTask: checkTaskTool,
|
|
217
|
+
listTasks: listTasksTool
|
|
218
|
+
};
|
|
219
|
+
state = {
|
|
220
|
+
agent,
|
|
221
|
+
abortController,
|
|
222
|
+
runtime: spawnerRuntime,
|
|
223
|
+
tools
|
|
224
|
+
};
|
|
225
|
+
return tools;
|
|
226
|
+
};
|
|
227
|
+
return [
|
|
228
|
+
{
|
|
229
|
+
id: "spawn_agent",
|
|
230
|
+
displayName: "Agent",
|
|
231
|
+
description: "Spawn a sub-agent to handle a task and return its result.",
|
|
232
|
+
inputSchema: import_schemas.SpawnAgentInputSchema,
|
|
233
|
+
execute: (input, context) => ensureToolsInitialized(context).spawnAgent.execute(input, context),
|
|
234
|
+
generatePreview: async (input, context) => {
|
|
235
|
+
const tool = ensureToolsInitialized(context).spawnAgent;
|
|
236
|
+
if (!tool.generatePreview) {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
return await tool.generatePreview(input, context);
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
id: "wait_for",
|
|
244
|
+
displayName: "Wait",
|
|
245
|
+
description: "Wait for background task(s) to complete.",
|
|
246
|
+
inputSchema: import_orchestration.WaitForInputSchema,
|
|
247
|
+
execute: (input, context) => ensureToolsInitialized(context).waitFor.execute(input, context),
|
|
248
|
+
generatePreview: async (input, context) => {
|
|
249
|
+
const tool = ensureToolsInitialized(context).waitFor;
|
|
250
|
+
if (!tool.generatePreview) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
return await tool.generatePreview(input, context);
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
id: "check_task",
|
|
258
|
+
displayName: "Check Task",
|
|
259
|
+
description: "Check the status of a background task.",
|
|
260
|
+
inputSchema: import_orchestration.CheckTaskInputSchema,
|
|
261
|
+
execute: (input, context) => ensureToolsInitialized(context).checkTask.execute(input, context),
|
|
262
|
+
generatePreview: async (input, context) => {
|
|
263
|
+
const tool = ensureToolsInitialized(context).checkTask;
|
|
264
|
+
if (!tool.generatePreview) {
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
return await tool.generatePreview(input, context);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
id: "list_tasks",
|
|
272
|
+
displayName: "List Tasks",
|
|
273
|
+
description: "List background tasks and their statuses.",
|
|
274
|
+
inputSchema: import_orchestration.ListTasksInputSchema,
|
|
275
|
+
execute: (input, context) => ensureToolsInitialized(context).listTasks.execute(input, context),
|
|
276
|
+
generatePreview: async (input, context) => {
|
|
277
|
+
const tool = ensureToolsInitialized(context).listTasks;
|
|
278
|
+
if (!tool.generatePreview) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
return await tool.generatePreview(input, context);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
];
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
288
|
+
0 && (module.exports = {
|
|
289
|
+
agentSpawnerToolsFactory
|
|
290
|
+
});
|
|
@@ -0,0 +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;AAevD,OAAO,EAGH,KAAK,kBAAkB,EAC1B,MAAM,cAAc,CAAC;AAkCtB,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,kBAAkB,CA8SpE,CAAC"}
|