@orkestrel/agent 0.0.27 → 0.0.29
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/src/core/index.cjs +31 -15
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +30 -7
- package/dist/src/core/index.d.ts +30 -7
- package/dist/src/core/index.js +31 -15
- package/dist/src/core/index.js.map +1 -1
- package/package.json +15 -15
package/dist/src/core/index.cjs
CHANGED
|
@@ -2448,7 +2448,8 @@ var Agent = class {
|
|
|
2448
2448
|
broke = true;
|
|
2449
2449
|
break;
|
|
2450
2450
|
}
|
|
2451
|
-
const
|
|
2451
|
+
const names = this.#context.scope?.tools?.slice();
|
|
2452
|
+
const advertised = filterAllowList(names, tools.definitions(), (definition) => definition.name);
|
|
2452
2453
|
const definitions = advertised.length > 0 ? advertised : void 0;
|
|
2453
2454
|
let charged = 0;
|
|
2454
2455
|
let turnContent = "";
|
|
@@ -2502,8 +2503,10 @@ var Agent = class {
|
|
|
2502
2503
|
usage: resultUsage
|
|
2503
2504
|
};
|
|
2504
2505
|
}
|
|
2505
|
-
if (
|
|
2506
|
-
|
|
2506
|
+
if (definitions === void 0) for (const call of result.tools ?? []) this.#emitter.emit("deny", call, "no tool is advertised in the active scope");
|
|
2507
|
+
else if (result.tools !== void 0 && result.tools.length > 0) {
|
|
2508
|
+
const admitted = filterAllowList(names, result.tools, (call) => call.name);
|
|
2509
|
+
const authorization = this.#authorize(result.tools, admitted);
|
|
2507
2510
|
if (abort.signal.aborted) {
|
|
2508
2511
|
partial = true;
|
|
2509
2512
|
broke = true;
|
|
@@ -2575,24 +2578,33 @@ var Agent = class {
|
|
|
2575
2578
|
messages.splice(0, messages.length, ...this.#context.build(this.#provider.format));
|
|
2576
2579
|
return false;
|
|
2577
2580
|
}
|
|
2578
|
-
#authorize(calls) {
|
|
2579
|
-
if (this.#authority === void 0) return void 0;
|
|
2581
|
+
#authorize(calls, admitted) {
|
|
2580
2582
|
const authority = this.#authority;
|
|
2581
|
-
const allowed =
|
|
2583
|
+
const allowed = /* @__PURE__ */ new Map();
|
|
2582
2584
|
const denials = /* @__PURE__ */ new Map();
|
|
2583
|
-
for (const call of calls) {
|
|
2585
|
+
for (const [index, call] of calls.entries()) {
|
|
2586
|
+
if (!admitted.includes(call)) {
|
|
2587
|
+
const reason = `${call.name} is not in the active scope`;
|
|
2588
|
+
denials.set(index, denyCall(call, reason));
|
|
2589
|
+
this.#emitter.emit("deny", call, reason);
|
|
2590
|
+
continue;
|
|
2591
|
+
}
|
|
2592
|
+
if (authority === void 0) {
|
|
2593
|
+
allowed.set(index, call);
|
|
2594
|
+
continue;
|
|
2595
|
+
}
|
|
2584
2596
|
let decision;
|
|
2585
2597
|
try {
|
|
2586
2598
|
decision = authority.evaluate({ call });
|
|
2587
2599
|
} catch (error) {
|
|
2588
2600
|
const reason = (0, _orkestrel_workflow.errorToMessage)(error);
|
|
2589
|
-
denials.set(
|
|
2601
|
+
denials.set(index, denyCall(call, reason));
|
|
2590
2602
|
this.#emitter.emit("deny", call, reason);
|
|
2591
2603
|
continue;
|
|
2592
2604
|
}
|
|
2593
|
-
if (decision.allowed) allowed.
|
|
2605
|
+
if (decision.allowed) allowed.set(index, call);
|
|
2594
2606
|
else {
|
|
2595
|
-
denials.set(
|
|
2607
|
+
denials.set(index, denyCall(call, decision.reason));
|
|
2596
2608
|
this.#emitter.emit("deny", call, decision.reason);
|
|
2597
2609
|
}
|
|
2598
2610
|
}
|
|
@@ -2602,12 +2614,16 @@ var Agent = class {
|
|
|
2602
2614
|
};
|
|
2603
2615
|
}
|
|
2604
2616
|
async #dispatch(tools, calls, signal, authorization) {
|
|
2605
|
-
if (authorization === void 0) return tools.execute(calls, { signal });
|
|
2606
2617
|
const { allowed, denials } = authorization;
|
|
2607
|
-
const executed = allowed.
|
|
2608
|
-
const
|
|
2609
|
-
|
|
2610
|
-
|
|
2618
|
+
const executed = allowed.size > 0 ? await tools.execute([...allowed.values()], { signal }) : [];
|
|
2619
|
+
const results = new Map(denials);
|
|
2620
|
+
let offset = 0;
|
|
2621
|
+
for (const index of allowed.keys()) {
|
|
2622
|
+
const result = executed[offset];
|
|
2623
|
+
if (result !== void 0) results.set(index, result);
|
|
2624
|
+
offset += 1;
|
|
2625
|
+
}
|
|
2626
|
+
return calls.map((call, index) => results.get(index) ?? denyCall(call, void 0));
|
|
2611
2627
|
}
|
|
2612
2628
|
async *#provide(messages, signal, definitions, think, schema, onDelta) {
|
|
2613
2629
|
const options = {};
|