@orkestrel/agent 0.0.22 → 0.0.23

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.
@@ -368,8 +368,8 @@ function isProviderError(value) {
368
368
  *
369
369
  * @remarks
370
370
  * The wire is strictly narrower than the domain: non-JSON arguments are refused.
371
- * ToolCall.caller is not in this shape and never crosses a wire. The guard refuses
372
- * that extra member; the contract parser drops it.
371
+ * Calls carry only id, name, and arguments; execution context stays local.
372
+ * The guard refuses every extra member; the contract parser drops extra members.
373
373
  */
374
374
  var toolCallShape = (0, _orkestrel_contract.objectShape)({
375
375
  id: (0, _orkestrel_contract.stringShape)(),
@@ -381,7 +381,7 @@ var toolCallShape = (0, _orkestrel_contract.objectShape)({
381
381
  *
382
382
  * @remarks
383
383
  * The wire is strictly narrower than Message: non-JSON call arguments are refused,
384
- * and caller context is refused by the guard or dropped by the parser.
384
+ * and execution context stays local. The guard refuses extra members; the parser drops them.
385
385
  */
386
386
  var messageShape = (0, _orkestrel_contract.objectShape)({
387
387
  id: (0, _orkestrel_contract.stringShape)(),
@@ -400,7 +400,8 @@ var messageShape = (0, _orkestrel_contract.objectShape)({
400
400
  *
401
401
  * @remarks
402
402
  * The wire is strictly narrower than ProviderRequest: non-JSON arguments, parameters,
403
- * or schema members are refused, and caller context is refused or dropped.
403
+ * or schema members are refused. Execution context stays local; the guard refuses
404
+ * extra members, and the parser drops them.
404
405
  */
405
406
  var providerRequestShape = (0, _orkestrel_contract.objectShape)({
406
407
  messages: (0, _orkestrel_contract.arrayShape)(messageShape),
@@ -419,7 +420,7 @@ var providerRequestShape = (0, _orkestrel_contract.objectShape)({
419
420
  *
420
421
  * @remarks
421
422
  * The wire is strictly narrower than ProviderResult: non-JSON call arguments are
422
- * refused, and caller context is refused or dropped.
423
+ * refused. Execution context stays local; the guard refuses extra members, and the parser drops them.
423
424
  */
424
425
  var providerResultShape = (0, _orkestrel_contract.objectShape)({
425
426
  content: (0, _orkestrel_contract.stringShape)(),
@@ -436,7 +437,8 @@ var providerResultShape = (0, _orkestrel_contract.objectShape)({
436
437
  *
437
438
  * @remarks
438
439
  * The wire is strictly narrower than RelayFrame through its result and partial
439
- * fields: non-JSON arguments are refused, and caller context is refused or dropped.
440
+ * fields: non-JSON arguments are refused. Execution context stays local; the guard
441
+ * refuses extra members, and the parser drops them.
440
442
  */
441
443
  var relayFrameShape = (0, _orkestrel_contract.unionShape)((0, _orkestrel_contract.objectShape)({
442
444
  channel: (0, _orkestrel_contract.literalShape)(["content", "thinking"]),
@@ -2163,13 +2165,19 @@ var Agent = class {
2163
2165
  };
2164
2166
  }
2165
2167
  if (result.tools !== void 0 && result.tools.length > 0) {
2168
+ const authorization = this.#authorize(result.tools);
2169
+ if (abort.signal.aborted) {
2170
+ partial = true;
2171
+ broke = true;
2172
+ break;
2173
+ }
2166
2174
  const assistant = this.#context.messages.add({
2167
2175
  role: "assistant",
2168
2176
  content: result.content,
2169
2177
  calls: result.tools
2170
2178
  });
2171
2179
  messages.push(assistant);
2172
- const results = await this.#authorize(tools, result.tools);
2180
+ const results = await this.#dispatch(tools, result.tools, abort.signal, authorization);
2173
2181
  for (let index = 0; index < result.tools.length; index += 1) {
2174
2182
  const call = result.tools[index];
2175
2183
  const outcomeResult = results[index];
@@ -2229,8 +2237,8 @@ var Agent = class {
2229
2237
  messages.splice(0, messages.length, ...this.#context.build(this.#provider.format));
2230
2238
  return false;
2231
2239
  }
2232
- async #authorize(tools, calls) {
2233
- if (this.#authority === void 0) return tools.execute(calls);
2240
+ #authorize(calls) {
2241
+ if (this.#authority === void 0) return void 0;
2234
2242
  const authority = this.#authority;
2235
2243
  const allowed = [];
2236
2244
  const denials = /* @__PURE__ */ new Map();
@@ -2250,7 +2258,15 @@ var Agent = class {
2250
2258
  this.#emitter.emit("deny", call, decision.reason);
2251
2259
  }
2252
2260
  }
2253
- const executed = allowed.length > 0 ? await tools.execute(allowed) : [];
2261
+ return {
2262
+ allowed,
2263
+ denials
2264
+ };
2265
+ }
2266
+ async #dispatch(tools, calls, signal, authorization) {
2267
+ if (authorization === void 0) return tools.execute(calls, { signal });
2268
+ const { allowed, denials } = authorization;
2269
+ const executed = allowed.length > 0 ? await tools.execute(allowed, { signal }) : [];
2254
2270
  const byId = new Map(denials);
2255
2271
  for (const result of executed) byId.set(result.id, result);
2256
2272
  return calls.map((call) => byId.get(call.id) ?? denyCall(call, void 0));
@@ -2934,7 +2950,8 @@ var AgentProvider = class {
2934
2950
  * Carries provider calls over an authenticated NDJSON relay endpoint.
2935
2951
  *
2936
2952
  * @remarks
2937
- * The `ToolCall.caller` member never crosses the hop. The wire body is an owned snapshot of
2953
+ * Tool execution context stays local; calls carry only `id`, `name`, and `arguments`.
2954
+ * The wire body is an owned snapshot of
2938
2955
  * the projection read through property descriptors, so a serializer reachable only through a
2939
2956
  * `get` trap or a prototype is never consulted; an own function-valued property such as a
2940
2957
  * `toJSON` method is a value outside JSON and is refused before fetching, with the clone's
@@ -2993,7 +3010,7 @@ var RelayProvider = class extends AgentProvider {
2993
3010
  * value carries is ignored rather than consulted and cannot reach the wire.
2994
3011
  *
2995
3012
  * @param request - The domain conversation and call configuration
2996
- * @returns The validated wire request with caller context omitted
3013
+ * @returns The validated wire request
2997
3014
  * @throws {ProviderError} Thrown when the snapshot cannot be taken — a hostile read or a
2998
3015
  * value outside JSON — carrying that failure as its `cause`, and when the snapshot the
2999
3016
  * projection produced is not a valid wire request