@dexto/agent-management 1.5.2 → 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/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
package/dist/index.cjs
CHANGED
|
@@ -15,6 +15,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
20
|
var index_exports = {};
|
|
20
21
|
__export(index_exports, {
|
|
@@ -135,6 +136,8 @@ var import_api_key_store = require("./utils/api-key-store.js");
|
|
|
135
136
|
var import_api_key_resolver = require("./utils/api-key-resolver.js");
|
|
136
137
|
var import_custom_models = require("./models/custom-models.js");
|
|
137
138
|
var import_models = require("./models/index.js");
|
|
139
|
+
__reExport(index_exports, require("./runtime/index.js"), module.exports);
|
|
140
|
+
__reExport(index_exports, require("./tool-provider/index.js"), module.exports);
|
|
138
141
|
// Annotate the CommonJS export names for ESM import in node:
|
|
139
142
|
0 && (module.exports = {
|
|
140
143
|
AgentFactory,
|
|
@@ -231,5 +234,7 @@ var import_models = require("./models/index.js");
|
|
|
231
234
|
walkUpDirectories,
|
|
232
235
|
writeConfigFile,
|
|
233
236
|
writeLLMPreferences,
|
|
234
|
-
writePreferencesToAgent
|
|
237
|
+
writePreferencesToAgent,
|
|
238
|
+
...require("./runtime/index.js"),
|
|
239
|
+
...require("./tool-provider/index.js")
|
|
235
240
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -20,4 +20,6 @@ export { saveProviderApiKey, getProviderKeyStatus, listProviderKeyStatus, determ
|
|
|
20
20
|
export { resolveApiKeyForProvider, getPrimaryApiKeyEnvVar, PROVIDER_API_KEY_MAP, } from './utils/api-key-resolver.js';
|
|
21
21
|
export { loadCustomModels, saveCustomModel, deleteCustomModel, getCustomModel, getCustomModelsPath, CustomModelSchema, CUSTOM_MODEL_PROVIDERS, type CustomModel, type CustomModelProvider, } from './models/custom-models.js';
|
|
22
22
|
export { getModelsDirectory, getModelFilePath, getModelDirectory, getModelStatePath, getModelTempDirectory, ensureModelsDirectory, ensureModelDirectory, modelFileExists, getModelFileSize, deleteModelDirectory, listModelDirectories, getModelsDiskUsage, formatSize, type ModelSource, type InstalledModel, type ModelState, loadModelState, saveModelState, addInstalledModel, removeInstalledModel, getInstalledModel, getAllInstalledModels, isModelInstalled, updateModelLastUsed, setActiveModel, getActiveModelId, getActiveModel, addToDownloadQueue, removeFromDownloadQueue, getDownloadQueue, syncStateWithFilesystem, getTotalInstalledSize, getInstalledModelCount, registerManualModel, } from './models/index.js';
|
|
23
|
+
export * from './runtime/index.js';
|
|
24
|
+
export * from './tool-provider/index.js';
|
|
23
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACrF,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,EACH,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,GAChC,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG/E,OAAO,EAAE,gBAAgB,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAG/E,OAAO,EACH,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,KAAK,YAAY,GACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGrE,OAAO,EACH,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,KAAK,cAAc,GACtB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,YAAY,EAAE,KAAK,kBAA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BAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EAEV,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,GACtB,MAAM,mBAAmB,CAAC;AAG3B,cAAc,oBAAoB,CAAC;AAGnC,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,181 @@
|
|
|
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 AgentPool_exports = {};
|
|
20
|
+
__export(AgentPool_exports, {
|
|
21
|
+
AgentPool: () => AgentPool
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(AgentPool_exports);
|
|
24
|
+
var import_schemas = require("./schemas.js");
|
|
25
|
+
var import_errors = require("./errors.js");
|
|
26
|
+
class AgentPool {
|
|
27
|
+
agents = /* @__PURE__ */ new Map();
|
|
28
|
+
config;
|
|
29
|
+
logger;
|
|
30
|
+
constructor(config, logger) {
|
|
31
|
+
this.config = {
|
|
32
|
+
maxAgents: config.maxAgents ?? import_schemas.DEFAULT_MAX_AGENTS,
|
|
33
|
+
defaultTaskTimeout: config.defaultTaskTimeout ?? import_schemas.DEFAULT_TASK_TIMEOUT
|
|
34
|
+
};
|
|
35
|
+
this.logger = logger;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Add an agent handle to the pool
|
|
39
|
+
* @throws RuntimeError if agent with same ID already exists or limit exceeded
|
|
40
|
+
*/
|
|
41
|
+
add(handle) {
|
|
42
|
+
if (this.agents.has(handle.agentId)) {
|
|
43
|
+
throw import_errors.RuntimeError.agentAlreadyExists(handle.agentId);
|
|
44
|
+
}
|
|
45
|
+
if (this.agents.size >= this.config.maxAgents) {
|
|
46
|
+
throw import_errors.RuntimeError.maxAgentsExceeded(this.agents.size, this.config.maxAgents);
|
|
47
|
+
}
|
|
48
|
+
this.agents.set(handle.agentId, handle);
|
|
49
|
+
this.logger.debug(
|
|
50
|
+
`Added agent '${handle.agentId}' to pool${handle.group ? ` (group: ${handle.group})` : ""}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Remove an agent from the pool
|
|
55
|
+
* @returns The removed handle, or undefined if not found
|
|
56
|
+
*/
|
|
57
|
+
remove(agentId) {
|
|
58
|
+
const handle = this.agents.get(agentId);
|
|
59
|
+
if (handle) {
|
|
60
|
+
this.agents.delete(agentId);
|
|
61
|
+
this.logger.debug(`Removed agent '${agentId}' from pool`);
|
|
62
|
+
}
|
|
63
|
+
return handle;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get an agent handle by ID
|
|
67
|
+
*/
|
|
68
|
+
get(agentId) {
|
|
69
|
+
return this.agents.get(agentId);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Check if another agent can be spawned
|
|
73
|
+
*/
|
|
74
|
+
canSpawn() {
|
|
75
|
+
return this.agents.size < this.config.maxAgents;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* List agents matching the given filter
|
|
79
|
+
*/
|
|
80
|
+
list(filter) {
|
|
81
|
+
if (!filter) {
|
|
82
|
+
return Array.from(this.agents.values());
|
|
83
|
+
}
|
|
84
|
+
const results = [];
|
|
85
|
+
for (const handle of this.agents.values()) {
|
|
86
|
+
if (this.matchesFilter(handle, filter)) {
|
|
87
|
+
results.push(handle);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return results;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get all agents in a specific group
|
|
94
|
+
*/
|
|
95
|
+
getByGroup(group) {
|
|
96
|
+
return this.list({ group });
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the count of agents in a specific group
|
|
100
|
+
*/
|
|
101
|
+
getGroupCount(group) {
|
|
102
|
+
return this.getByGroup(group).length;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Update the status of an agent
|
|
106
|
+
* @throws RuntimeError if agent not found
|
|
107
|
+
*/
|
|
108
|
+
updateStatus(agentId, status, error) {
|
|
109
|
+
const handle = this.agents.get(agentId);
|
|
110
|
+
if (!handle) {
|
|
111
|
+
throw import_errors.RuntimeError.agentNotFound(agentId);
|
|
112
|
+
}
|
|
113
|
+
const previousStatus = handle.status;
|
|
114
|
+
handle.status = status;
|
|
115
|
+
if (status !== "error") {
|
|
116
|
+
delete handle.error;
|
|
117
|
+
} else if (error !== void 0) {
|
|
118
|
+
handle.error = error;
|
|
119
|
+
}
|
|
120
|
+
this.logger.debug(
|
|
121
|
+
`Agent '${agentId}' status changed: ${previousStatus} -> ${status}${error ? ` (error: ${error})` : ""}`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Check if an agent exists in the pool
|
|
126
|
+
*/
|
|
127
|
+
has(agentId) {
|
|
128
|
+
return this.agents.has(agentId);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get all agent handles in the pool
|
|
132
|
+
*/
|
|
133
|
+
getAll() {
|
|
134
|
+
return Array.from(this.agents.values());
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get the total count of agents in the pool
|
|
138
|
+
*/
|
|
139
|
+
get size() {
|
|
140
|
+
return this.agents.size;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get the configuration
|
|
144
|
+
*/
|
|
145
|
+
getConfig() {
|
|
146
|
+
return { ...this.config };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Clear all agents from the pool
|
|
150
|
+
* Note: This does NOT stop the agents - use AgentRuntime.stopAll instead
|
|
151
|
+
*/
|
|
152
|
+
clear() {
|
|
153
|
+
const count = this.agents.size;
|
|
154
|
+
this.agents.clear();
|
|
155
|
+
if (count > 0) {
|
|
156
|
+
this.logger.debug(`Cleared ${count} agents from pool`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Check if an agent handle matches a filter
|
|
161
|
+
*/
|
|
162
|
+
matchesFilter(handle, filter) {
|
|
163
|
+
if (filter.group !== void 0 && handle.group !== filter.group) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
if (filter.status !== void 0) {
|
|
167
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
168
|
+
if (!statuses.includes(handle.status)) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (filter.ephemeral !== void 0 && handle.ephemeral !== filter.ephemeral) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
179
|
+
0 && (module.exports = {
|
|
180
|
+
AgentPool
|
|
181
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentPool - Manages a pool of agent instances
|
|
3
|
+
*
|
|
4
|
+
* Tracks active agents, enforces resource limits, and provides
|
|
5
|
+
* lookup and lifecycle management capabilities.
|
|
6
|
+
*/
|
|
7
|
+
import type { IDextoLogger } from '@dexto/core';
|
|
8
|
+
import type { AgentHandle, AgentStatus, AgentFilter } from './types.js';
|
|
9
|
+
import { type ValidatedAgentRuntimeConfig } from './schemas.js';
|
|
10
|
+
export declare class AgentPool {
|
|
11
|
+
private agents;
|
|
12
|
+
private config;
|
|
13
|
+
private logger;
|
|
14
|
+
constructor(config: Partial<ValidatedAgentRuntimeConfig>, logger: IDextoLogger);
|
|
15
|
+
/**
|
|
16
|
+
* Add an agent handle to the pool
|
|
17
|
+
* @throws RuntimeError if agent with same ID already exists or limit exceeded
|
|
18
|
+
*/
|
|
19
|
+
add(handle: AgentHandle): void;
|
|
20
|
+
/**
|
|
21
|
+
* Remove an agent from the pool
|
|
22
|
+
* @returns The removed handle, or undefined if not found
|
|
23
|
+
*/
|
|
24
|
+
remove(agentId: string): AgentHandle | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Get an agent handle by ID
|
|
27
|
+
*/
|
|
28
|
+
get(agentId: string): AgentHandle | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Check if another agent can be spawned
|
|
31
|
+
*/
|
|
32
|
+
canSpawn(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* List agents matching the given filter
|
|
35
|
+
*/
|
|
36
|
+
list(filter?: AgentFilter): AgentHandle[];
|
|
37
|
+
/**
|
|
38
|
+
* Get all agents in a specific group
|
|
39
|
+
*/
|
|
40
|
+
getByGroup(group: string): AgentHandle[];
|
|
41
|
+
/**
|
|
42
|
+
* Get the count of agents in a specific group
|
|
43
|
+
*/
|
|
44
|
+
getGroupCount(group: string): number;
|
|
45
|
+
/**
|
|
46
|
+
* Update the status of an agent
|
|
47
|
+
* @throws RuntimeError if agent not found
|
|
48
|
+
*/
|
|
49
|
+
updateStatus(agentId: string, status: AgentStatus, error?: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Check if an agent exists in the pool
|
|
52
|
+
*/
|
|
53
|
+
has(agentId: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Get all agent handles in the pool
|
|
56
|
+
*/
|
|
57
|
+
getAll(): AgentHandle[];
|
|
58
|
+
/**
|
|
59
|
+
* Get the total count of agents in the pool
|
|
60
|
+
*/
|
|
61
|
+
get size(): number;
|
|
62
|
+
/**
|
|
63
|
+
* Get the configuration
|
|
64
|
+
*/
|
|
65
|
+
getConfig(): ValidatedAgentRuntimeConfig;
|
|
66
|
+
/**
|
|
67
|
+
* Clear all agents from the pool
|
|
68
|
+
* Note: This does NOT stop the agents - use AgentRuntime.stopAll instead
|
|
69
|
+
*/
|
|
70
|
+
clear(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Check if an agent handle matches a filter
|
|
73
|
+
*/
|
|
74
|
+
private matchesFilter;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=AgentPool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentPool.d.ts","sourceRoot":"","sources":["../../src/runtime/AgentPool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAGH,KAAK,2BAA2B,EACnC,MAAM,cAAc,CAAC;AAGtB,qBAAa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__ */ new Map();
|
|
8
|
+
config;
|
|
9
|
+
logger;
|
|
10
|
+
constructor(config, logger) {
|
|
11
|
+
this.config = {
|
|
12
|
+
maxAgents: config.maxAgents ?? DEFAULT_MAX_AGENTS,
|
|
13
|
+
defaultTaskTimeout: config.defaultTaskTimeout ?? DEFAULT_TASK_TIMEOUT
|
|
14
|
+
};
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Add an agent handle to the pool
|
|
19
|
+
* @throws RuntimeError if agent with same ID already exists or limit exceeded
|
|
20
|
+
*/
|
|
21
|
+
add(handle) {
|
|
22
|
+
if (this.agents.has(handle.agentId)) {
|
|
23
|
+
throw RuntimeError.agentAlreadyExists(handle.agentId);
|
|
24
|
+
}
|
|
25
|
+
if (this.agents.size >= this.config.maxAgents) {
|
|
26
|
+
throw RuntimeError.maxAgentsExceeded(this.agents.size, this.config.maxAgents);
|
|
27
|
+
}
|
|
28
|
+
this.agents.set(handle.agentId, handle);
|
|
29
|
+
this.logger.debug(
|
|
30
|
+
`Added agent '${handle.agentId}' to pool${handle.group ? ` (group: ${handle.group})` : ""}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Remove an agent from the pool
|
|
35
|
+
* @returns The removed handle, or undefined if not found
|
|
36
|
+
*/
|
|
37
|
+
remove(agentId) {
|
|
38
|
+
const handle = this.agents.get(agentId);
|
|
39
|
+
if (handle) {
|
|
40
|
+
this.agents.delete(agentId);
|
|
41
|
+
this.logger.debug(`Removed agent '${agentId}' from pool`);
|
|
42
|
+
}
|
|
43
|
+
return handle;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get an agent handle by ID
|
|
47
|
+
*/
|
|
48
|
+
get(agentId) {
|
|
49
|
+
return this.agents.get(agentId);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Check if another agent can be spawned
|
|
53
|
+
*/
|
|
54
|
+
canSpawn() {
|
|
55
|
+
return this.agents.size < this.config.maxAgents;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* List agents matching the given filter
|
|
59
|
+
*/
|
|
60
|
+
list(filter) {
|
|
61
|
+
if (!filter) {
|
|
62
|
+
return Array.from(this.agents.values());
|
|
63
|
+
}
|
|
64
|
+
const results = [];
|
|
65
|
+
for (const handle of this.agents.values()) {
|
|
66
|
+
if (this.matchesFilter(handle, filter)) {
|
|
67
|
+
results.push(handle);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return results;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get all agents in a specific group
|
|
74
|
+
*/
|
|
75
|
+
getByGroup(group) {
|
|
76
|
+
return this.list({ group });
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the count of agents in a specific group
|
|
80
|
+
*/
|
|
81
|
+
getGroupCount(group) {
|
|
82
|
+
return this.getByGroup(group).length;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Update the status of an agent
|
|
86
|
+
* @throws RuntimeError if agent not found
|
|
87
|
+
*/
|
|
88
|
+
updateStatus(agentId, status, error) {
|
|
89
|
+
const handle = this.agents.get(agentId);
|
|
90
|
+
if (!handle) {
|
|
91
|
+
throw RuntimeError.agentNotFound(agentId);
|
|
92
|
+
}
|
|
93
|
+
const previousStatus = handle.status;
|
|
94
|
+
handle.status = status;
|
|
95
|
+
if (status !== "error") {
|
|
96
|
+
delete handle.error;
|
|
97
|
+
} else if (error !== void 0) {
|
|
98
|
+
handle.error = error;
|
|
99
|
+
}
|
|
100
|
+
this.logger.debug(
|
|
101
|
+
`Agent '${agentId}' status changed: ${previousStatus} -> ${status}${error ? ` (error: ${error})` : ""}`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check if an agent exists in the pool
|
|
106
|
+
*/
|
|
107
|
+
has(agentId) {
|
|
108
|
+
return this.agents.has(agentId);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get all agent handles in the pool
|
|
112
|
+
*/
|
|
113
|
+
getAll() {
|
|
114
|
+
return Array.from(this.agents.values());
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get the total count of agents in the pool
|
|
118
|
+
*/
|
|
119
|
+
get size() {
|
|
120
|
+
return this.agents.size;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get the configuration
|
|
124
|
+
*/
|
|
125
|
+
getConfig() {
|
|
126
|
+
return { ...this.config };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Clear all agents from the pool
|
|
130
|
+
* Note: This does NOT stop the agents - use AgentRuntime.stopAll instead
|
|
131
|
+
*/
|
|
132
|
+
clear() {
|
|
133
|
+
const count = this.agents.size;
|
|
134
|
+
this.agents.clear();
|
|
135
|
+
if (count > 0) {
|
|
136
|
+
this.logger.debug(`Cleared ${count} agents from pool`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Check if an agent handle matches a filter
|
|
141
|
+
*/
|
|
142
|
+
matchesFilter(handle, filter) {
|
|
143
|
+
if (filter.group !== void 0 && handle.group !== filter.group) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (filter.status !== void 0) {
|
|
147
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
148
|
+
if (!statuses.includes(handle.status)) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (filter.ephemeral !== void 0 && handle.ephemeral !== filter.ephemeral) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
AgentPool
|
|
160
|
+
};
|