@dexto/agent-management 1.5.2 → 1.5.4
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/config-enrichment.d.ts +4 -3
- package/dist/config/config-enrichment.d.ts.map +1 -1
- package/dist/config/discover-prompts.cjs +24 -19
- package/dist/config/discover-prompts.d.ts +13 -5
- package/dist/config/discover-prompts.d.ts.map +1 -1
- package/dist/config/discover-prompts.js +24 -19
- 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/preferences/index.cjs +2 -0
- package/dist/preferences/index.d.ts +2 -2
- package/dist/preferences/index.d.ts.map +1 -1
- package/dist/preferences/index.js +3 -1
- package/dist/preferences/loader.cjs +39 -41
- package/dist/preferences/loader.d.ts +7 -5
- package/dist/preferences/loader.d.ts.map +1 -1
- package/dist/preferences/loader.js +39 -41
- package/dist/preferences/schemas.cjs +14 -2
- package/dist/preferences/schemas.d.ts +37 -0
- package/dist/preferences/schemas.d.ts.map +1 -1
- package/dist/preferences/schemas.js +12 -1
- 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 +390 -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 +366 -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
|
@@ -53,6 +53,19 @@ export declare const PreferenceSetupSchema: z.ZodObject<{
|
|
|
53
53
|
apiKeyPending?: boolean | undefined;
|
|
54
54
|
baseURLPending?: boolean | undefined;
|
|
55
55
|
}>;
|
|
56
|
+
export declare const PreferenceSoundsSchema: z.ZodObject<{
|
|
57
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
58
|
+
onApprovalRequired: z.ZodDefault<z.ZodBoolean>;
|
|
59
|
+
onTaskComplete: z.ZodDefault<z.ZodBoolean>;
|
|
60
|
+
}, "strict", z.ZodTypeAny, {
|
|
61
|
+
enabled: boolean;
|
|
62
|
+
onApprovalRequired: boolean;
|
|
63
|
+
onTaskComplete: boolean;
|
|
64
|
+
}, {
|
|
65
|
+
enabled?: boolean | undefined;
|
|
66
|
+
onApprovalRequired?: boolean | undefined;
|
|
67
|
+
onTaskComplete?: boolean | undefined;
|
|
68
|
+
}>;
|
|
56
69
|
export declare const GlobalPreferencesSchema: z.ZodObject<{
|
|
57
70
|
llm: z.ZodEffects<z.ZodObject<{
|
|
58
71
|
provider: z.ZodEnum<["openai", "openai-compatible", "anthropic", "google", "groq", "xai", "cohere", "openrouter", "litellm", "glama", "vertex", "bedrock", "local", "ollama"]>;
|
|
@@ -108,6 +121,19 @@ export declare const GlobalPreferencesSchema: z.ZodObject<{
|
|
|
108
121
|
apiKeyPending?: boolean | undefined;
|
|
109
122
|
baseURLPending?: boolean | undefined;
|
|
110
123
|
}>>;
|
|
124
|
+
sounds: z.ZodDefault<z.ZodObject<{
|
|
125
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
126
|
+
onApprovalRequired: z.ZodDefault<z.ZodBoolean>;
|
|
127
|
+
onTaskComplete: z.ZodDefault<z.ZodBoolean>;
|
|
128
|
+
}, "strict", z.ZodTypeAny, {
|
|
129
|
+
enabled: boolean;
|
|
130
|
+
onApprovalRequired: boolean;
|
|
131
|
+
onTaskComplete: boolean;
|
|
132
|
+
}, {
|
|
133
|
+
enabled?: boolean | undefined;
|
|
134
|
+
onApprovalRequired?: boolean | undefined;
|
|
135
|
+
onTaskComplete?: boolean | undefined;
|
|
136
|
+
}>>;
|
|
111
137
|
}, "strict", z.ZodTypeAny, {
|
|
112
138
|
llm: {
|
|
113
139
|
provider: "openai" | "openai-compatible" | "anthropic" | "google" | "groq" | "xai" | "cohere" | "openrouter" | "litellm" | "glama" | "vertex" | "bedrock" | "local" | "ollama";
|
|
@@ -125,6 +151,11 @@ export declare const GlobalPreferencesSchema: z.ZodObject<{
|
|
|
125
151
|
apiKeyPending: boolean;
|
|
126
152
|
baseURLPending: boolean;
|
|
127
153
|
};
|
|
154
|
+
sounds: {
|
|
155
|
+
enabled: boolean;
|
|
156
|
+
onApprovalRequired: boolean;
|
|
157
|
+
onTaskComplete: boolean;
|
|
158
|
+
};
|
|
128
159
|
}, {
|
|
129
160
|
llm: {
|
|
130
161
|
provider: "openai" | "openai-compatible" | "anthropic" | "google" | "groq" | "xai" | "cohere" | "openrouter" | "litellm" | "glama" | "vertex" | "bedrock" | "local" | "ollama";
|
|
@@ -142,9 +173,15 @@ export declare const GlobalPreferencesSchema: z.ZodObject<{
|
|
|
142
173
|
apiKeyPending?: boolean | undefined;
|
|
143
174
|
baseURLPending?: boolean | undefined;
|
|
144
175
|
} | undefined;
|
|
176
|
+
sounds?: {
|
|
177
|
+
enabled?: boolean | undefined;
|
|
178
|
+
onApprovalRequired?: boolean | undefined;
|
|
179
|
+
onTaskComplete?: boolean | undefined;
|
|
180
|
+
} | undefined;
|
|
145
181
|
}>;
|
|
146
182
|
export type PreferenceLLM = z.output<typeof PreferenceLLMSchema>;
|
|
147
183
|
export type PreferenceDefaults = z.output<typeof PreferenceDefaultsSchema>;
|
|
148
184
|
export type PreferenceSetup = z.output<typeof PreferenceSetupSchema>;
|
|
185
|
+
export type PreferenceSounds = z.output<typeof PreferenceSoundsSchema>;
|
|
149
186
|
export type GlobalPreferences = z.output<typeof GlobalPreferencesSchema>;
|
|
150
187
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/preferences/schemas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsE1B,CAAC;AAEP,eAAO,MAAM,wBAAwB;;;;;;;;;EAYxB,CAAC;AAEd,eAAO,MAAM,qBAAqB;;;;;;;;;;;;EAYrB,CAAC;AAEd,eAAO,MAAM,uBAAuB
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/preferences/schemas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsE1B,CAAC;AAEP,eAAO,MAAM,wBAAwB;;;;;;;;;EAYxB,CAAC;AAEd,eAAO,MAAM,qBAAqB;;;;;;;;;;;;EAYrB,CAAC;AAEd,eAAO,MAAM,sBAAsB;;;;;;;;;;;;EActB,CAAC;AAEd,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcvB,CAAC;AAGd,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACjE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC3E,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACrE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACvE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
|
|
@@ -60,16 +60,27 @@ const PreferenceSetupSchema = z.object({
|
|
|
60
60
|
apiKeyPending: z.boolean().default(false).describe("Whether API key setup was skipped and needs to be configured later"),
|
|
61
61
|
baseURLPending: z.boolean().default(false).describe("Whether baseURL setup was skipped and needs to be configured later")
|
|
62
62
|
}).strict();
|
|
63
|
+
const PreferenceSoundsSchema = z.object({
|
|
64
|
+
enabled: z.boolean().default(true).describe("Enable sound notifications (default: true)"),
|
|
65
|
+
onApprovalRequired: z.boolean().default(true).describe(
|
|
66
|
+
"Play sound when tool approval is required (default: true when sounds enabled)"
|
|
67
|
+
),
|
|
68
|
+
onTaskComplete: z.boolean().default(true).describe("Play sound when agent task completes (default: true when sounds enabled)")
|
|
69
|
+
}).strict();
|
|
63
70
|
const GlobalPreferencesSchema = z.object({
|
|
64
71
|
llm: PreferenceLLMSchema.describe("LLM configuration preferences"),
|
|
65
72
|
defaults: PreferenceDefaultsSchema.describe("Default behavior preferences (required)"),
|
|
66
73
|
setup: PreferenceSetupSchema.default({ completed: false }).describe(
|
|
67
74
|
"Setup completion tracking"
|
|
75
|
+
),
|
|
76
|
+
sounds: PreferenceSoundsSchema.default({}).describe(
|
|
77
|
+
"Sound notification preferences (defaults applied for legacy preferences)"
|
|
68
78
|
)
|
|
69
79
|
}).strict();
|
|
70
80
|
export {
|
|
71
81
|
GlobalPreferencesSchema,
|
|
72
82
|
PreferenceDefaultsSchema,
|
|
73
83
|
PreferenceLLMSchema,
|
|
74
|
-
PreferenceSetupSchema
|
|
84
|
+
PreferenceSetupSchema,
|
|
85
|
+
PreferenceSoundsSchema
|
|
75
86
|
};
|
|
@@ -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,SAAS;IAClB,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,MAAM,CAAe;gBAEjB,MAAM,EAAE,OAAO,CAAC,2BAA2B,CAAC,EAAE,MAAM,EAAE,YAAY;IAQ9E;;;OAGG;IACH,GAAG,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAe9B;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAShD;;OAEG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAI7C;;OAEG;IACH,QAAQ,IAAI,OAAO;IAInB;;OAEG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,WAAW,EAAE;IAczC;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE;IAIxC;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIpC;;;OAGG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;IAmBxE;;OAEG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI7B;;OAEG;IACH,MAAM,IAAI,WAAW,EAAE;IAIvB;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,SAAS,IAAI,2BAA2B;IAIxC;;;OAGG;IACH,KAAK,IAAI,IAAI;IAQb;;OAEG;IACH,OAAO,CAAC,aAAa;CAqBxB"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_MAX_AGENTS,
|
|
3
|
+
DEFAULT_TASK_TIMEOUT
|
|
4
|
+
} from "./schemas.js";
|
|
5
|
+
import { RuntimeError } from "./errors.js";
|
|
6
|
+
class AgentPool {
|
|
7
|
+
agents = /* @__PURE__ */ 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
|
+
};
|