@arnilo/prism-supervisor 0.0.15 → 0.0.17
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/CHANGELOG.md +10 -0
- package/dist/a2a-card.js +19 -7
- package/dist/a2a-client.js +278 -50
- package/dist/a2a-parts.js +109 -19
- package/dist/a2a-push.js +10 -2
- package/dist/a2a-server.js +218 -84
- package/dist/errors.js +12 -3
- package/dist/limits.js +4 -1
- package/dist/supervisor.js +51 -25
- package/package.json +2 -2
package/dist/supervisor.js
CHANGED
|
@@ -92,7 +92,10 @@ export function createSupervisor(options) {
|
|
|
92
92
|
ownership: options.ownership,
|
|
93
93
|
redactor: options.redactor ?? childAgent.config.redactor,
|
|
94
94
|
});
|
|
95
|
-
const session = agent.createSession({
|
|
95
|
+
const session = agent.createSession({
|
|
96
|
+
id: `${delegationId}-session`,
|
|
97
|
+
metadata: { supervisorId: id, delegationId, resourceId, threadId },
|
|
98
|
+
});
|
|
96
99
|
let result;
|
|
97
100
|
try {
|
|
98
101
|
result = await abortable(session.run(input, {
|
|
@@ -110,15 +113,18 @@ export function createSupervisor(options) {
|
|
|
110
113
|
}
|
|
111
114
|
catch (error) {
|
|
112
115
|
if (error instanceof AgentRunError && error.result.limit) {
|
|
113
|
-
const label = error.result.limit.limit === "maxTotalTokens"
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
const label = error.result.limit.limit === "maxTotalTokens"
|
|
117
|
+
? "token"
|
|
118
|
+
: error.result.limit.limit === "maxToolCalls"
|
|
119
|
+
? "tool-call"
|
|
120
|
+
: error.result.limit.limit === "maxWallTimeMs"
|
|
121
|
+
? "timeout"
|
|
116
122
|
: "run";
|
|
117
123
|
throw new SupervisorLimitError(`Delegation ${label} limit exceeded`);
|
|
118
124
|
}
|
|
119
125
|
throw error;
|
|
120
126
|
}
|
|
121
|
-
const totalTokens = result.usage?.totalTokens ?? (
|
|
127
|
+
const totalTokens = result.usage?.totalTokens ?? (result.usage?.inputTokens ?? 0) + (result.usage?.outputTokens ?? 0);
|
|
122
128
|
events.publish({ type: "delegation_finished", childId: request.childId, delegationId, depth, status: result.status, totalTokens });
|
|
123
129
|
await complete(toCompletion(result, request.childId, delegationId, depth, options));
|
|
124
130
|
completionSent = true;
|
|
@@ -129,14 +135,16 @@ export function createSupervisor(options) {
|
|
|
129
135
|
const result = error instanceof AgentRunError ? error.result : undefined;
|
|
130
136
|
const message = safeError(error, options);
|
|
131
137
|
events.publish({ type: "delegation_error", childId: request.childId, delegationId, depth, error: message });
|
|
132
|
-
await complete(result
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
await complete(result
|
|
139
|
+
? toCompletion(result, request.childId, delegationId, depth, options)
|
|
140
|
+
: {
|
|
141
|
+
childId: request.childId,
|
|
142
|
+
delegationId,
|
|
143
|
+
depth,
|
|
144
|
+
status: controller.signal.aborted ? "aborted" : "rejected",
|
|
145
|
+
text: "",
|
|
146
|
+
error: message,
|
|
147
|
+
});
|
|
140
148
|
}
|
|
141
149
|
if (error instanceof AgentRunError || error instanceof SupervisorError)
|
|
142
150
|
throw error;
|
|
@@ -155,10 +163,22 @@ export function createSupervisor(options) {
|
|
|
155
163
|
await options.hooks.after(Object.freeze(value));
|
|
156
164
|
}
|
|
157
165
|
catch (error) {
|
|
158
|
-
events.publish({
|
|
166
|
+
events.publish({
|
|
167
|
+
type: "delegation_error",
|
|
168
|
+
childId: value.childId,
|
|
169
|
+
delegationId: value.delegationId,
|
|
170
|
+
depth: value.depth,
|
|
171
|
+
error: safeError(error, options),
|
|
172
|
+
});
|
|
159
173
|
}
|
|
160
174
|
}
|
|
161
|
-
return {
|
|
175
|
+
return {
|
|
176
|
+
delegate: (request) => delegate(request),
|
|
177
|
+
subscribe: () => events.subscribe(),
|
|
178
|
+
get activeChildren() {
|
|
179
|
+
return activeChildren;
|
|
180
|
+
},
|
|
181
|
+
};
|
|
162
182
|
}
|
|
163
183
|
function toCompletion(result, childId, delegationId, depth, options) {
|
|
164
184
|
return Object.freeze({
|
|
@@ -173,23 +193,27 @@ function toCompletion(result, childId, delegationId, depth, options) {
|
|
|
173
193
|
}
|
|
174
194
|
function intersectPolicies(...policies) {
|
|
175
195
|
const active = policies.filter((policy) => policy !== undefined);
|
|
176
|
-
return {
|
|
196
|
+
return {
|
|
197
|
+
async check(request) {
|
|
177
198
|
for (const policy of active) {
|
|
178
199
|
const decision = await policy.check(request);
|
|
179
200
|
if (!decision.allowed)
|
|
180
201
|
return decision;
|
|
181
202
|
}
|
|
182
203
|
return { allowed: true };
|
|
183
|
-
}
|
|
204
|
+
},
|
|
205
|
+
};
|
|
184
206
|
}
|
|
185
207
|
function toolBudgetPolicy(max) {
|
|
186
208
|
let count = 0;
|
|
187
|
-
return {
|
|
209
|
+
return {
|
|
210
|
+
check(request) {
|
|
188
211
|
if (request.kind !== "tool" || request.action !== "execute")
|
|
189
212
|
return { allowed: true };
|
|
190
213
|
count += 1;
|
|
191
214
|
return count <= max ? { allowed: true } : { allowed: false, reason: "Delegation tool-call limit exceeded" };
|
|
192
|
-
}
|
|
215
|
+
},
|
|
216
|
+
};
|
|
193
217
|
}
|
|
194
218
|
function linkSignals(controller, ...signals) {
|
|
195
219
|
const removers = [];
|
|
@@ -204,8 +228,10 @@ function linkSignals(controller, ...signals) {
|
|
|
204
228
|
removers.push(() => signal.removeEventListener("abort", abort));
|
|
205
229
|
}
|
|
206
230
|
}
|
|
207
|
-
return () => {
|
|
208
|
-
remove
|
|
231
|
+
return () => {
|
|
232
|
+
for (const remove of removers)
|
|
233
|
+
remove();
|
|
234
|
+
};
|
|
209
235
|
}
|
|
210
236
|
function abortable(promise, signal) {
|
|
211
237
|
if (signal.aborted)
|
|
@@ -221,10 +247,10 @@ function assertBytes(value, max, label) {
|
|
|
221
247
|
throw new SupervisorLimitError(`${label} exceeds max bytes`);
|
|
222
248
|
}
|
|
223
249
|
function requireOwnership(ownership) {
|
|
224
|
-
if (!ownership.tenantId?.trim()
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
250
|
+
if (!ownership.tenantId?.trim() ||
|
|
251
|
+
(ownership.accountId !== undefined && !ownership.accountId.trim()) ||
|
|
252
|
+
(ownership.userId !== undefined && !ownership.userId.trim()) ||
|
|
253
|
+
(!ownership.accountId && !ownership.userId))
|
|
228
254
|
throw new SupervisorValidationError("tenantId and non-empty accountId or userId are required");
|
|
229
255
|
}
|
|
230
256
|
function safeError(error, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arnilo/prism-supervisor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "Bounded supervisor delegation and A2A 1.0 durable task, rich-part, reconnect, and push interoperability.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"pack:dry-run": "npm pack --dry-run"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@arnilo/prism": "0.0.
|
|
28
|
+
"@arnilo/prism": "0.0.17"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@arnilo/prism": "file:../.."
|