@dexto/agent-management 1.5.1 → 1.5.3
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/discover-prompts.cjs +14 -4
- package/dist/config/discover-prompts.d.ts +4 -4
- package/dist/config/discover-prompts.d.ts.map +1 -1
- package/dist/config/discover-prompts.js +14 -4
- package/dist/index.cjs +6 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/runtime/AgentPool.cjs +181 -0
- package/dist/runtime/AgentPool.d.ts +76 -0
- package/dist/runtime/AgentPool.d.ts.map +1 -0
- package/dist/runtime/AgentPool.js +160 -0
- package/dist/runtime/AgentRuntime.cjs +225 -0
- package/dist/runtime/AgentRuntime.d.ts +77 -0
- package/dist/runtime/AgentRuntime.d.ts.map +1 -0
- package/dist/runtime/AgentRuntime.js +201 -0
- package/dist/runtime/approval-delegation.cjs +97 -0
- package/dist/runtime/approval-delegation.d.ts +30 -0
- package/dist/runtime/approval-delegation.d.ts.map +1 -0
- package/dist/runtime/approval-delegation.js +73 -0
- package/dist/runtime/error-codes.cjs +40 -0
- package/dist/runtime/error-codes.d.ts +17 -0
- package/dist/runtime/error-codes.d.ts.map +1 -0
- package/dist/runtime/error-codes.js +16 -0
- package/dist/runtime/errors.cjs +135 -0
- package/dist/runtime/errors.d.ts +40 -0
- package/dist/runtime/errors.d.ts.map +1 -0
- package/dist/runtime/errors.js +111 -0
- package/dist/runtime/index.cjs +53 -0
- package/dist/runtime/index.d.ts +19 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +26 -0
- package/dist/runtime/schemas.cjs +64 -0
- package/dist/runtime/schemas.d.ts +69 -0
- package/dist/runtime/schemas.d.ts.map +1 -0
- package/dist/runtime/schemas.js +35 -0
- package/dist/runtime/types.cjs +16 -0
- package/dist/runtime/types.d.ts +94 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +0 -0
- package/dist/tool-provider/error-codes.cjs +35 -0
- package/dist/tool-provider/error-codes.d.ts +11 -0
- package/dist/tool-provider/error-codes.d.ts.map +1 -0
- package/dist/tool-provider/error-codes.js +11 -0
- package/dist/tool-provider/errors.cjs +81 -0
- package/dist/tool-provider/errors.d.ts +19 -0
- package/dist/tool-provider/errors.d.ts.map +1 -0
- package/dist/tool-provider/errors.js +57 -0
- package/dist/tool-provider/index.cjs +46 -0
- package/dist/tool-provider/index.d.ts +16 -0
- package/dist/tool-provider/index.d.ts.map +1 -0
- package/dist/tool-provider/index.js +16 -0
- package/dist/tool-provider/runtime-service.cjs +370 -0
- package/dist/tool-provider/runtime-service.d.ts +83 -0
- package/dist/tool-provider/runtime-service.d.ts.map +1 -0
- package/dist/tool-provider/runtime-service.js +346 -0
- package/dist/tool-provider/schemas.cjs +73 -0
- package/dist/tool-provider/schemas.d.ts +83 -0
- package/dist/tool-provider/schemas.d.ts.map +1 -0
- package/dist/tool-provider/schemas.js +48 -0
- package/dist/tool-provider/spawn-agent-tool.cjs +89 -0
- package/dist/tool-provider/spawn-agent-tool.d.ts +10 -0
- package/dist/tool-provider/spawn-agent-tool.d.ts.map +1 -0
- package/dist/tool-provider/spawn-agent-tool.js +65 -0
- package/dist/tool-provider/tool-provider.cjs +44 -0
- package/dist/tool-provider/tool-provider.d.ts +24 -0
- package/dist/tool-provider/tool-provider.d.ts.map +1 -0
- package/dist/tool-provider/tool-provider.js +20 -0
- package/dist/tool-provider/types.cjs +16 -0
- package/dist/tool-provider/types.d.ts +17 -0
- package/dist/tool-provider/types.d.ts.map +1 -0
- package/dist/tool-provider/types.js +0 -0
- package/package.json +2 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
function createDelegatingApprovalHandler(parentApprovalManager, subAgentId, logger) {
|
|
2
|
+
const pendingApprovalIds = /* @__PURE__ */ new Set();
|
|
3
|
+
const handler = Object.assign(
|
|
4
|
+
async (request) => {
|
|
5
|
+
logger.debug(
|
|
6
|
+
`Delegating approval '${request.approvalId}' (type: ${request.type}) from sub-agent '${subAgentId}'`
|
|
7
|
+
);
|
|
8
|
+
pendingApprovalIds.add(request.approvalId);
|
|
9
|
+
try {
|
|
10
|
+
const delegatedDetails = {
|
|
11
|
+
type: request.type,
|
|
12
|
+
timeout: request.timeout,
|
|
13
|
+
sessionId: request.sessionId,
|
|
14
|
+
metadata: {
|
|
15
|
+
...request.metadata,
|
|
16
|
+
delegatedFromAgent: subAgentId
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const response = await parentApprovalManager.requestApproval(delegatedDetails);
|
|
20
|
+
logger.debug(
|
|
21
|
+
`Approval '${request.approvalId}' delegated response: ${response.status}`
|
|
22
|
+
);
|
|
23
|
+
return response;
|
|
24
|
+
} finally {
|
|
25
|
+
pendingApprovalIds.delete(request.approvalId);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
/**
|
|
30
|
+
* Cancel a specific pending approval request
|
|
31
|
+
*/
|
|
32
|
+
cancel: (approvalId) => {
|
|
33
|
+
if (pendingApprovalIds.has(approvalId)) {
|
|
34
|
+
logger.debug(
|
|
35
|
+
`Cancelling delegated approval '${approvalId}' for sub-agent '${subAgentId}'`
|
|
36
|
+
);
|
|
37
|
+
parentApprovalManager.cancelApproval(approvalId);
|
|
38
|
+
pendingApprovalIds.delete(approvalId);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
/**
|
|
42
|
+
* Cancel all pending approval requests for this sub-agent
|
|
43
|
+
*/
|
|
44
|
+
cancelAll: () => {
|
|
45
|
+
if (pendingApprovalIds.size > 0) {
|
|
46
|
+
logger.debug(
|
|
47
|
+
`Cancelling all ${pendingApprovalIds.size} delegated approvals for sub-agent '${subAgentId}'`
|
|
48
|
+
);
|
|
49
|
+
for (const approvalId of pendingApprovalIds) {
|
|
50
|
+
parentApprovalManager.cancelApproval(approvalId);
|
|
51
|
+
}
|
|
52
|
+
pendingApprovalIds.clear();
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Get list of pending approval IDs for this sub-agent
|
|
57
|
+
*/
|
|
58
|
+
getPending: () => {
|
|
59
|
+
return Array.from(pendingApprovalIds);
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Get pending approval requests (not available for delegated handlers)
|
|
63
|
+
*/
|
|
64
|
+
getPendingRequests: () => {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
return handler;
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
createDelegatingApprovalHandler
|
|
73
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
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 error_codes_exports = {};
|
|
20
|
+
__export(error_codes_exports, {
|
|
21
|
+
RuntimeErrorCode: () => RuntimeErrorCode
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(error_codes_exports);
|
|
24
|
+
var RuntimeErrorCode = /* @__PURE__ */ ((RuntimeErrorCode2) => {
|
|
25
|
+
RuntimeErrorCode2["MAX_AGENTS_EXCEEDED"] = "runtime_max_agents_exceeded";
|
|
26
|
+
RuntimeErrorCode2["AGENT_NOT_FOUND"] = "runtime_agent_not_found";
|
|
27
|
+
RuntimeErrorCode2["AGENT_ALREADY_EXISTS"] = "runtime_agent_already_exists";
|
|
28
|
+
RuntimeErrorCode2["AGENT_NOT_STARTED"] = "runtime_agent_not_started";
|
|
29
|
+
RuntimeErrorCode2["AGENT_ALREADY_STOPPED"] = "runtime_agent_already_stopped";
|
|
30
|
+
RuntimeErrorCode2["SPAWN_FAILED"] = "runtime_spawn_failed";
|
|
31
|
+
RuntimeErrorCode2["INVALID_CONFIG"] = "runtime_invalid_config";
|
|
32
|
+
RuntimeErrorCode2["TASK_TIMEOUT"] = "runtime_task_timeout";
|
|
33
|
+
RuntimeErrorCode2["TASK_FAILED"] = "runtime_task_failed";
|
|
34
|
+
RuntimeErrorCode2["TASK_CANCELLED"] = "runtime_task_cancelled";
|
|
35
|
+
return RuntimeErrorCode2;
|
|
36
|
+
})(RuntimeErrorCode || {});
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
RuntimeErrorCode
|
|
40
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime-specific error codes
|
|
3
|
+
* Includes errors for agent spawning, lifecycle management, and task execution
|
|
4
|
+
*/
|
|
5
|
+
export declare enum RuntimeErrorCode {
|
|
6
|
+
MAX_AGENTS_EXCEEDED = "runtime_max_agents_exceeded",
|
|
7
|
+
AGENT_NOT_FOUND = "runtime_agent_not_found",
|
|
8
|
+
AGENT_ALREADY_EXISTS = "runtime_agent_already_exists",
|
|
9
|
+
AGENT_NOT_STARTED = "runtime_agent_not_started",
|
|
10
|
+
AGENT_ALREADY_STOPPED = "runtime_agent_already_stopped",
|
|
11
|
+
SPAWN_FAILED = "runtime_spawn_failed",
|
|
12
|
+
INVALID_CONFIG = "runtime_invalid_config",
|
|
13
|
+
TASK_TIMEOUT = "runtime_task_timeout",
|
|
14
|
+
TASK_FAILED = "runtime_task_failed",
|
|
15
|
+
TASK_CANCELLED = "runtime_task_cancelled"
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=error-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../src/runtime/error-codes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,gBAAgB;IAExB,mBAAmB,gCAAgC;IAGnD,eAAe,4BAA4B;IAC3C,oBAAoB,iCAAiC;IACrD,iBAAiB,8BAA8B;IAC/C,qBAAqB,kCAAkC;IAGvD,YAAY,yBAAyB;IACrC,cAAc,2BAA2B;IAGzC,YAAY,yBAAyB;IACrC,WAAW,wBAAwB;IACnC,cAAc,2BAA2B;CAC5C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var RuntimeErrorCode = /* @__PURE__ */ ((RuntimeErrorCode2) => {
|
|
2
|
+
RuntimeErrorCode2["MAX_AGENTS_EXCEEDED"] = "runtime_max_agents_exceeded";
|
|
3
|
+
RuntimeErrorCode2["AGENT_NOT_FOUND"] = "runtime_agent_not_found";
|
|
4
|
+
RuntimeErrorCode2["AGENT_ALREADY_EXISTS"] = "runtime_agent_already_exists";
|
|
5
|
+
RuntimeErrorCode2["AGENT_NOT_STARTED"] = "runtime_agent_not_started";
|
|
6
|
+
RuntimeErrorCode2["AGENT_ALREADY_STOPPED"] = "runtime_agent_already_stopped";
|
|
7
|
+
RuntimeErrorCode2["SPAWN_FAILED"] = "runtime_spawn_failed";
|
|
8
|
+
RuntimeErrorCode2["INVALID_CONFIG"] = "runtime_invalid_config";
|
|
9
|
+
RuntimeErrorCode2["TASK_TIMEOUT"] = "runtime_task_timeout";
|
|
10
|
+
RuntimeErrorCode2["TASK_FAILED"] = "runtime_task_failed";
|
|
11
|
+
RuntimeErrorCode2["TASK_CANCELLED"] = "runtime_task_cancelled";
|
|
12
|
+
return RuntimeErrorCode2;
|
|
13
|
+
})(RuntimeErrorCode || {});
|
|
14
|
+
export {
|
|
15
|
+
RuntimeErrorCode
|
|
16
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
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 errors_exports = {};
|
|
20
|
+
__export(errors_exports, {
|
|
21
|
+
RuntimeError: () => RuntimeError
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(errors_exports);
|
|
24
|
+
var import_core = require("@dexto/core");
|
|
25
|
+
var import_error_codes = require("./error-codes.js");
|
|
26
|
+
class RuntimeError {
|
|
27
|
+
// Limit errors
|
|
28
|
+
static maxAgentsExceeded(currentCount, maxAllowed) {
|
|
29
|
+
return new import_core.DextoRuntimeError(
|
|
30
|
+
import_error_codes.RuntimeErrorCode.MAX_AGENTS_EXCEEDED,
|
|
31
|
+
import_core.ErrorScope.AGENT,
|
|
32
|
+
import_core.ErrorType.USER,
|
|
33
|
+
`Maximum agents limit exceeded. Current: ${currentCount}, Max: ${maxAllowed}`,
|
|
34
|
+
{ currentCount, maxAllowed },
|
|
35
|
+
"Stop some existing agents before spawning new ones"
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
// Agent lifecycle errors
|
|
39
|
+
static agentNotFound(agentId) {
|
|
40
|
+
return new import_core.DextoRuntimeError(
|
|
41
|
+
import_error_codes.RuntimeErrorCode.AGENT_NOT_FOUND,
|
|
42
|
+
import_core.ErrorScope.AGENT,
|
|
43
|
+
import_core.ErrorType.NOT_FOUND,
|
|
44
|
+
`Agent '${agentId}' not found`,
|
|
45
|
+
{ agentId },
|
|
46
|
+
"Ensure the agent ID is correct and the agent has been spawned"
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
static agentAlreadyExists(agentId) {
|
|
50
|
+
return new import_core.DextoRuntimeError(
|
|
51
|
+
import_error_codes.RuntimeErrorCode.AGENT_ALREADY_EXISTS,
|
|
52
|
+
import_core.ErrorScope.AGENT,
|
|
53
|
+
import_core.ErrorType.USER,
|
|
54
|
+
`Agent with ID '${agentId}' already exists`,
|
|
55
|
+
{ agentId },
|
|
56
|
+
"Use a different agent ID or stop the existing agent first"
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
static agentNotStarted(agentId) {
|
|
60
|
+
return new import_core.DextoRuntimeError(
|
|
61
|
+
import_error_codes.RuntimeErrorCode.AGENT_NOT_STARTED,
|
|
62
|
+
import_core.ErrorScope.AGENT,
|
|
63
|
+
import_core.ErrorType.USER,
|
|
64
|
+
`Agent '${agentId}' has not been started`,
|
|
65
|
+
{ agentId },
|
|
66
|
+
"Start the agent before executing tasks"
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
static agentAlreadyStopped(agentId) {
|
|
70
|
+
return new import_core.DextoRuntimeError(
|
|
71
|
+
import_error_codes.RuntimeErrorCode.AGENT_ALREADY_STOPPED,
|
|
72
|
+
import_core.ErrorScope.AGENT,
|
|
73
|
+
import_core.ErrorType.USER,
|
|
74
|
+
`Agent '${agentId}' has already been stopped`,
|
|
75
|
+
{ agentId },
|
|
76
|
+
"Spawn a new agent if you need to continue"
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
// Spawn errors
|
|
80
|
+
static spawnFailed(cause, agentId) {
|
|
81
|
+
return new import_core.DextoRuntimeError(
|
|
82
|
+
import_error_codes.RuntimeErrorCode.SPAWN_FAILED,
|
|
83
|
+
import_core.ErrorScope.AGENT,
|
|
84
|
+
import_core.ErrorType.SYSTEM,
|
|
85
|
+
agentId ? `Failed to spawn agent '${agentId}': ${cause}` : `Failed to spawn agent: ${cause}`,
|
|
86
|
+
{ agentId, cause },
|
|
87
|
+
"Check the agent configuration and try again"
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
static invalidConfig(message, details) {
|
|
91
|
+
return new import_core.DextoRuntimeError(
|
|
92
|
+
import_error_codes.RuntimeErrorCode.INVALID_CONFIG,
|
|
93
|
+
import_core.ErrorScope.AGENT,
|
|
94
|
+
import_core.ErrorType.USER,
|
|
95
|
+
`Invalid agent configuration: ${message}`,
|
|
96
|
+
details ?? {},
|
|
97
|
+
"Check the configuration and ensure all required fields are provided"
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
// Task execution errors
|
|
101
|
+
static taskTimeout(agentId, timeoutMs) {
|
|
102
|
+
return new import_core.DextoRuntimeError(
|
|
103
|
+
import_error_codes.RuntimeErrorCode.TASK_TIMEOUT,
|
|
104
|
+
import_core.ErrorScope.AGENT,
|
|
105
|
+
import_core.ErrorType.TIMEOUT,
|
|
106
|
+
`Task execution timed out for agent '${agentId}' after ${timeoutMs}ms`,
|
|
107
|
+
{ agentId, timeoutMs },
|
|
108
|
+
"Increase the timeout or simplify the task"
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
static taskFailed(agentId, cause) {
|
|
112
|
+
return new import_core.DextoRuntimeError(
|
|
113
|
+
import_error_codes.RuntimeErrorCode.TASK_FAILED,
|
|
114
|
+
import_core.ErrorScope.AGENT,
|
|
115
|
+
import_core.ErrorType.SYSTEM,
|
|
116
|
+
`Task execution failed for agent '${agentId}': ${cause}`,
|
|
117
|
+
{ agentId, cause },
|
|
118
|
+
"Check the task requirements and agent configuration"
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
static taskCancelled(agentId) {
|
|
122
|
+
return new import_core.DextoRuntimeError(
|
|
123
|
+
import_error_codes.RuntimeErrorCode.TASK_CANCELLED,
|
|
124
|
+
import_core.ErrorScope.AGENT,
|
|
125
|
+
import_core.ErrorType.USER,
|
|
126
|
+
`Task execution was cancelled for agent '${agentId}'`,
|
|
127
|
+
{ agentId },
|
|
128
|
+
"The task was cancelled by user or system request"
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
RuntimeError
|
|
135
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DextoRuntimeError } from '@dexto/core';
|
|
2
|
+
/**
|
|
3
|
+
* Runtime error factory methods
|
|
4
|
+
* Creates properly typed errors for agent runtime operations
|
|
5
|
+
*/
|
|
6
|
+
export declare class RuntimeError {
|
|
7
|
+
static maxAgentsExceeded(currentCount: number, maxAllowed: number): DextoRuntimeError<{
|
|
8
|
+
currentCount: number;
|
|
9
|
+
maxAllowed: number;
|
|
10
|
+
}>;
|
|
11
|
+
static agentNotFound(agentId: string): DextoRuntimeError<{
|
|
12
|
+
agentId: string;
|
|
13
|
+
}>;
|
|
14
|
+
static agentAlreadyExists(agentId: string): DextoRuntimeError<{
|
|
15
|
+
agentId: string;
|
|
16
|
+
}>;
|
|
17
|
+
static agentNotStarted(agentId: string): DextoRuntimeError<{
|
|
18
|
+
agentId: string;
|
|
19
|
+
}>;
|
|
20
|
+
static agentAlreadyStopped(agentId: string): DextoRuntimeError<{
|
|
21
|
+
agentId: string;
|
|
22
|
+
}>;
|
|
23
|
+
static spawnFailed(cause: string, agentId?: string): DextoRuntimeError<{
|
|
24
|
+
agentId: string | undefined;
|
|
25
|
+
cause: string;
|
|
26
|
+
}>;
|
|
27
|
+
static invalidConfig(message: string, details?: Record<string, unknown>): DextoRuntimeError<Record<string, unknown>>;
|
|
28
|
+
static taskTimeout(agentId: string, timeoutMs: number): DextoRuntimeError<{
|
|
29
|
+
agentId: string;
|
|
30
|
+
timeoutMs: number;
|
|
31
|
+
}>;
|
|
32
|
+
static taskFailed(agentId: string, cause: string): DextoRuntimeError<{
|
|
33
|
+
agentId: string;
|
|
34
|
+
cause: string;
|
|
35
|
+
}>;
|
|
36
|
+
static taskCancelled(agentId: string): DextoRuntimeError<{
|
|
37
|
+
agentId: string;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/runtime/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAyB,MAAM,aAAa,CAAC;AAGvE;;;GAGG;AACH,qBAAa,YAAY;IAErB,MAAM,CAAC,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;;;;IAYjE,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM;;;IAWpC,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM;;;IAWzC,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM;;;IAWtC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM;;;IAY1C,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;;;;IAalD,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAYvE,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;;;IAWrD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAWhD,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM;;;CAUvC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { DextoRuntimeError, ErrorScope, ErrorType } from "@dexto/core";
|
|
2
|
+
import { RuntimeErrorCode } from "./error-codes.js";
|
|
3
|
+
class RuntimeError {
|
|
4
|
+
// Limit errors
|
|
5
|
+
static maxAgentsExceeded(currentCount, maxAllowed) {
|
|
6
|
+
return new DextoRuntimeError(
|
|
7
|
+
RuntimeErrorCode.MAX_AGENTS_EXCEEDED,
|
|
8
|
+
ErrorScope.AGENT,
|
|
9
|
+
ErrorType.USER,
|
|
10
|
+
`Maximum agents limit exceeded. Current: ${currentCount}, Max: ${maxAllowed}`,
|
|
11
|
+
{ currentCount, maxAllowed },
|
|
12
|
+
"Stop some existing agents before spawning new ones"
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
// Agent lifecycle errors
|
|
16
|
+
static agentNotFound(agentId) {
|
|
17
|
+
return new DextoRuntimeError(
|
|
18
|
+
RuntimeErrorCode.AGENT_NOT_FOUND,
|
|
19
|
+
ErrorScope.AGENT,
|
|
20
|
+
ErrorType.NOT_FOUND,
|
|
21
|
+
`Agent '${agentId}' not found`,
|
|
22
|
+
{ agentId },
|
|
23
|
+
"Ensure the agent ID is correct and the agent has been spawned"
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
static agentAlreadyExists(agentId) {
|
|
27
|
+
return new DextoRuntimeError(
|
|
28
|
+
RuntimeErrorCode.AGENT_ALREADY_EXISTS,
|
|
29
|
+
ErrorScope.AGENT,
|
|
30
|
+
ErrorType.USER,
|
|
31
|
+
`Agent with ID '${agentId}' already exists`,
|
|
32
|
+
{ agentId },
|
|
33
|
+
"Use a different agent ID or stop the existing agent first"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
static agentNotStarted(agentId) {
|
|
37
|
+
return new DextoRuntimeError(
|
|
38
|
+
RuntimeErrorCode.AGENT_NOT_STARTED,
|
|
39
|
+
ErrorScope.AGENT,
|
|
40
|
+
ErrorType.USER,
|
|
41
|
+
`Agent '${agentId}' has not been started`,
|
|
42
|
+
{ agentId },
|
|
43
|
+
"Start the agent before executing tasks"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
static agentAlreadyStopped(agentId) {
|
|
47
|
+
return new DextoRuntimeError(
|
|
48
|
+
RuntimeErrorCode.AGENT_ALREADY_STOPPED,
|
|
49
|
+
ErrorScope.AGENT,
|
|
50
|
+
ErrorType.USER,
|
|
51
|
+
`Agent '${agentId}' has already been stopped`,
|
|
52
|
+
{ agentId },
|
|
53
|
+
"Spawn a new agent if you need to continue"
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
// Spawn errors
|
|
57
|
+
static spawnFailed(cause, agentId) {
|
|
58
|
+
return new DextoRuntimeError(
|
|
59
|
+
RuntimeErrorCode.SPAWN_FAILED,
|
|
60
|
+
ErrorScope.AGENT,
|
|
61
|
+
ErrorType.SYSTEM,
|
|
62
|
+
agentId ? `Failed to spawn agent '${agentId}': ${cause}` : `Failed to spawn agent: ${cause}`,
|
|
63
|
+
{ agentId, cause },
|
|
64
|
+
"Check the agent configuration and try again"
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
static invalidConfig(message, details) {
|
|
68
|
+
return new DextoRuntimeError(
|
|
69
|
+
RuntimeErrorCode.INVALID_CONFIG,
|
|
70
|
+
ErrorScope.AGENT,
|
|
71
|
+
ErrorType.USER,
|
|
72
|
+
`Invalid agent configuration: ${message}`,
|
|
73
|
+
details ?? {},
|
|
74
|
+
"Check the configuration and ensure all required fields are provided"
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
// Task execution errors
|
|
78
|
+
static taskTimeout(agentId, timeoutMs) {
|
|
79
|
+
return new DextoRuntimeError(
|
|
80
|
+
RuntimeErrorCode.TASK_TIMEOUT,
|
|
81
|
+
ErrorScope.AGENT,
|
|
82
|
+
ErrorType.TIMEOUT,
|
|
83
|
+
`Task execution timed out for agent '${agentId}' after ${timeoutMs}ms`,
|
|
84
|
+
{ agentId, timeoutMs },
|
|
85
|
+
"Increase the timeout or simplify the task"
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
static taskFailed(agentId, cause) {
|
|
89
|
+
return new DextoRuntimeError(
|
|
90
|
+
RuntimeErrorCode.TASK_FAILED,
|
|
91
|
+
ErrorScope.AGENT,
|
|
92
|
+
ErrorType.SYSTEM,
|
|
93
|
+
`Task execution failed for agent '${agentId}': ${cause}`,
|
|
94
|
+
{ agentId, cause },
|
|
95
|
+
"Check the task requirements and agent configuration"
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
static taskCancelled(agentId) {
|
|
99
|
+
return new DextoRuntimeError(
|
|
100
|
+
RuntimeErrorCode.TASK_CANCELLED,
|
|
101
|
+
ErrorScope.AGENT,
|
|
102
|
+
ErrorType.USER,
|
|
103
|
+
`Task execution was cancelled for agent '${agentId}'`,
|
|
104
|
+
{ agentId },
|
|
105
|
+
"The task was cancelled by user or system request"
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export {
|
|
110
|
+
RuntimeError
|
|
111
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
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 runtime_exports = {};
|
|
20
|
+
__export(runtime_exports, {
|
|
21
|
+
AgentFilterSchema: () => import_schemas.AgentFilterSchema,
|
|
22
|
+
AgentPool: () => import_AgentPool.AgentPool,
|
|
23
|
+
AgentRuntime: () => import_AgentRuntime.AgentRuntime,
|
|
24
|
+
AgentRuntimeConfigSchema: () => import_schemas.AgentRuntimeConfigSchema,
|
|
25
|
+
AgentStatusSchema: () => import_schemas.AgentStatusSchema,
|
|
26
|
+
DEFAULT_MAX_AGENTS: () => import_schemas.DEFAULT_MAX_AGENTS,
|
|
27
|
+
DEFAULT_TASK_TIMEOUT: () => import_schemas.DEFAULT_TASK_TIMEOUT,
|
|
28
|
+
RuntimeError: () => import_errors.RuntimeError,
|
|
29
|
+
RuntimeErrorCode: () => import_error_codes.RuntimeErrorCode,
|
|
30
|
+
SpawnConfigSchema: () => import_schemas.SpawnConfigSchema,
|
|
31
|
+
createDelegatingApprovalHandler: () => import_approval_delegation.createDelegatingApprovalHandler
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
34
|
+
var import_AgentRuntime = require("./AgentRuntime.js");
|
|
35
|
+
var import_AgentPool = require("./AgentPool.js");
|
|
36
|
+
var import_approval_delegation = require("./approval-delegation.js");
|
|
37
|
+
var import_schemas = require("./schemas.js");
|
|
38
|
+
var import_errors = require("./errors.js");
|
|
39
|
+
var import_error_codes = require("./error-codes.js");
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
AgentFilterSchema,
|
|
43
|
+
AgentPool,
|
|
44
|
+
AgentRuntime,
|
|
45
|
+
AgentRuntimeConfigSchema,
|
|
46
|
+
AgentStatusSchema,
|
|
47
|
+
DEFAULT_MAX_AGENTS,
|
|
48
|
+
DEFAULT_TASK_TIMEOUT,
|
|
49
|
+
RuntimeError,
|
|
50
|
+
RuntimeErrorCode,
|
|
51
|
+
SpawnConfigSchema,
|
|
52
|
+
createDelegatingApprovalHandler
|
|
53
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Runtime Module
|
|
3
|
+
*
|
|
4
|
+
* Provides infrastructure for spawning and managing agents.
|
|
5
|
+
* General-purpose runtime that can be used for:
|
|
6
|
+
* - Dashboard managing multiple independent agents
|
|
7
|
+
* - Agent task delegation (parent spawns sub-agents)
|
|
8
|
+
* - Test harnesses managing multiple agents
|
|
9
|
+
*/
|
|
10
|
+
export { AgentRuntime } from './AgentRuntime.js';
|
|
11
|
+
export type { AgentRuntimeOptions } from './AgentRuntime.js';
|
|
12
|
+
export { AgentPool } from './AgentPool.js';
|
|
13
|
+
export { createDelegatingApprovalHandler } from './approval-delegation.js';
|
|
14
|
+
export type { SpawnConfig, AgentStatus, AgentHandle, TaskResult, AgentRuntimeConfig, AgentFilter, } from './types.js';
|
|
15
|
+
export { AgentRuntimeConfigSchema, SpawnConfigSchema, AgentStatusSchema, AgentFilterSchema, DEFAULT_MAX_AGENTS, DEFAULT_TASK_TIMEOUT, } from './schemas.js';
|
|
16
|
+
export type { ValidatedAgentRuntimeConfig, ValidatedSpawnConfig, ValidatedAgentFilter, } from './schemas.js';
|
|
17
|
+
export { RuntimeError } from './errors.js';
|
|
18
|
+
export { RuntimeErrorCode } from './error-codes.js';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAG7D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,EAAE,+BAA+B,EAAE,MAAM,0BAA0B,CAAC;AAG3E,YAAY,EACR,WAAW,EACX,WAAW,EACX,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,WAAW,GACd,MAAM,YAAY,CAAC;AAGpB,OAAO,EACH,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,GACvB,MAAM,cAAc,CAAC;AACtB,YAAY,EACR,2BAA2B,EAC3B,oBAAoB,EACpB,oBAAoB,GACvB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AgentRuntime } from "./AgentRuntime.js";
|
|
2
|
+
import { AgentPool } from "./AgentPool.js";
|
|
3
|
+
import { createDelegatingApprovalHandler } from "./approval-delegation.js";
|
|
4
|
+
import {
|
|
5
|
+
AgentRuntimeConfigSchema,
|
|
6
|
+
SpawnConfigSchema,
|
|
7
|
+
AgentStatusSchema,
|
|
8
|
+
AgentFilterSchema,
|
|
9
|
+
DEFAULT_MAX_AGENTS,
|
|
10
|
+
DEFAULT_TASK_TIMEOUT
|
|
11
|
+
} from "./schemas.js";
|
|
12
|
+
import { RuntimeError } from "./errors.js";
|
|
13
|
+
import { RuntimeErrorCode } from "./error-codes.js";
|
|
14
|
+
export {
|
|
15
|
+
AgentFilterSchema,
|
|
16
|
+
AgentPool,
|
|
17
|
+
AgentRuntime,
|
|
18
|
+
AgentRuntimeConfigSchema,
|
|
19
|
+
AgentStatusSchema,
|
|
20
|
+
DEFAULT_MAX_AGENTS,
|
|
21
|
+
DEFAULT_TASK_TIMEOUT,
|
|
22
|
+
RuntimeError,
|
|
23
|
+
RuntimeErrorCode,
|
|
24
|
+
SpawnConfigSchema,
|
|
25
|
+
createDelegatingApprovalHandler
|
|
26
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
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 schemas_exports = {};
|
|
20
|
+
__export(schemas_exports, {
|
|
21
|
+
AgentFilterSchema: () => AgentFilterSchema,
|
|
22
|
+
AgentRuntimeConfigSchema: () => AgentRuntimeConfigSchema,
|
|
23
|
+
AgentStatusSchema: () => AgentStatusSchema,
|
|
24
|
+
DEFAULT_MAX_AGENTS: () => DEFAULT_MAX_AGENTS,
|
|
25
|
+
DEFAULT_TASK_TIMEOUT: () => DEFAULT_TASK_TIMEOUT,
|
|
26
|
+
SpawnConfigSchema: () => SpawnConfigSchema
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(schemas_exports);
|
|
29
|
+
var import_zod = require("zod");
|
|
30
|
+
const DEFAULT_MAX_AGENTS = 20;
|
|
31
|
+
const DEFAULT_TASK_TIMEOUT = 3e5;
|
|
32
|
+
const AgentRuntimeConfigSchema = import_zod.z.object({
|
|
33
|
+
maxAgents: import_zod.z.number().int().positive().default(DEFAULT_MAX_AGENTS).describe("Maximum total agents managed by this runtime"),
|
|
34
|
+
defaultTaskTimeout: import_zod.z.number().int().positive().default(DEFAULT_TASK_TIMEOUT).describe("Default task timeout in milliseconds")
|
|
35
|
+
}).strict().describe("Configuration for the AgentRuntime");
|
|
36
|
+
const SpawnConfigSchema = import_zod.z.object({
|
|
37
|
+
agentConfig: import_zod.z.record(import_zod.z.unknown()).describe("Base agent configuration"),
|
|
38
|
+
ephemeral: import_zod.z.boolean().default(true).describe("Whether agent should be destroyed after task completion"),
|
|
39
|
+
agentId: import_zod.z.string().min(1).optional().describe("Optional custom agent ID (auto-generated if not provided)"),
|
|
40
|
+
group: import_zod.z.string().min(1).optional().describe("Optional group identifier for logical grouping"),
|
|
41
|
+
metadata: import_zod.z.record(import_zod.z.unknown()).optional().describe("Optional metadata for tracking relationships or context")
|
|
42
|
+
}).strict().describe("Configuration for spawning an agent");
|
|
43
|
+
const AgentStatusSchema = import_zod.z.enum([
|
|
44
|
+
"starting",
|
|
45
|
+
"idle",
|
|
46
|
+
"running",
|
|
47
|
+
"stopping",
|
|
48
|
+
"stopped",
|
|
49
|
+
"error"
|
|
50
|
+
]);
|
|
51
|
+
const AgentFilterSchema = import_zod.z.object({
|
|
52
|
+
group: import_zod.z.string().optional().describe("Filter by group"),
|
|
53
|
+
status: import_zod.z.union([AgentStatusSchema, import_zod.z.array(AgentStatusSchema)]).optional().describe("Filter by status"),
|
|
54
|
+
ephemeral: import_zod.z.boolean().optional().describe("Filter by ephemeral flag")
|
|
55
|
+
}).strict().describe("Filter options for listing agents");
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
AgentFilterSchema,
|
|
59
|
+
AgentRuntimeConfigSchema,
|
|
60
|
+
AgentStatusSchema,
|
|
61
|
+
DEFAULT_MAX_AGENTS,
|
|
62
|
+
DEFAULT_TASK_TIMEOUT,
|
|
63
|
+
SpawnConfigSchema
|
|
64
|
+
});
|