@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.
@@ -486,6 +486,14 @@ export declare type AgentEventMap = {
486
486
  * - **Bounded.** Each turn arms a single cancel folded from the external `signal`, the
487
487
  * `timeout` deadline, and the `budget` signal (through `AbortSignal.any`); any of them —
488
488
  * or `abort()` — stops the loop and settles the result `partial: true`.
489
+ * Tool handlers receive that run's signal through their `ToolContext`. An agent abort,
490
+ * stream abort, external signal, or deadline can reach a running handler. The budget is
491
+ * charged during provider streaming and between turns, before tool dispatch; exhaustion
492
+ * ends the run without dispatching, never inside a handler. An abort before dispatch
493
+ * appends neither the assistant call turn nor tool messages and emits no tool chunk;
494
+ * streamed content remains in the partial result. Cancellation after entry is cooperative:
495
+ * the loop awaits a running handler even when it ignores the signal.
496
+ * The agent supplies no caller identity.
489
497
  * - **Paced + capped.** The `scheduler` (when given) yields between turns; tool
490
498
  * iteration is capped at `limit` so the loop always terminates.
491
499
  * - **Two observation surfaces.** Pull: the {@link AgentChunk} stream (`stream().events`)
@@ -3826,7 +3834,7 @@ export declare type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
3826
3834
  *
3827
3835
  * @remarks
3828
3836
  * The wire is strictly narrower than Message: non-JSON call arguments are refused,
3829
- * and caller context is refused by the guard or dropped by the parser.
3837
+ * and execution context stays local. The guard refuses extra members; the parser drops them.
3830
3838
  */
3831
3839
  export declare const messageShape: ObjectShape< {
3832
3840
  id: StringShape;
@@ -4056,7 +4064,8 @@ readonly [k: string]: JSONValue;
4056
4064
  *
4057
4065
  * @remarks
4058
4066
  * The wire is strictly narrower than ProviderRequest: non-JSON arguments, parameters,
4059
- * or schema members are refused, and caller context is refused or dropped.
4067
+ * or schema members are refused. Execution context stays local; the guard refuses
4068
+ * extra members, and the parser drops them.
4060
4069
  */
4061
4070
  export declare const providerRequestShape: ObjectShape< {
4062
4071
  messages: ArrayShape<ObjectShape< {
@@ -4130,7 +4139,7 @@ total: number;
4130
4139
  *
4131
4140
  * @remarks
4132
4141
  * The wire is strictly narrower than ProviderResult: non-JSON call arguments are
4133
- * refused, and caller context is refused or dropped.
4142
+ * refused. Execution context stays local; the guard refuses extra members, and the parser drops them.
4134
4143
  */
4135
4144
  export declare const providerResultShape: ObjectShape< {
4136
4145
  content: StringShape;
@@ -4284,7 +4293,8 @@ message: string;
4284
4293
  *
4285
4294
  * @remarks
4286
4295
  * The wire is strictly narrower than RelayFrame through its result and partial
4287
- * fields: non-JSON arguments are refused, and caller context is refused or dropped.
4296
+ * fields: non-JSON arguments are refused. Execution context stays local; the guard
4297
+ * refuses extra members, and the parser drops them.
4288
4298
  */
4289
4299
  export declare const relayFrameShape: UnionShape<readonly [ObjectShape< {
4290
4300
  channel: LiteralShape<readonly ["content", "thinking"]>;
@@ -4353,7 +4363,8 @@ export declare interface RelayOptions {
4353
4363
  * Carries provider calls over an authenticated NDJSON relay endpoint.
4354
4364
  *
4355
4365
  * @remarks
4356
- * The `ToolCall.caller` member never crosses the hop. The wire body is an owned snapshot of
4366
+ * Tool execution context stays local; calls carry only `id`, `name`, and `arguments`.
4367
+ * The wire body is an owned snapshot of
4357
4368
  * the projection read through property descriptors, so a serializer reachable only through a
4358
4369
  * `get` trap or a prototype is never consulted; an own function-valued property such as a
4359
4370
  * `toJSON` method is a value outside JSON and is refused before fetching, with the clone's
@@ -4398,7 +4409,7 @@ export declare class RelayProvider extends AgentProvider {
4398
4409
  * value carries is ignored rather than consulted and cannot reach the wire.
4399
4410
  *
4400
4411
  * @param request - The domain conversation and call configuration
4401
- * @returns The validated wire request with caller context omitted
4412
+ * @returns The validated wire request
4402
4413
  * @throws {ProviderError} Thrown when the snapshot cannot be taken — a hostile read or a
4403
4414
  * value outside JSON — carrying that failure as its `cause`, and when the snapshot the
4404
4415
  * projection produced is not a valid wire request
@@ -5065,8 +5076,8 @@ export declare interface ThinkSplitterInterface {
5065
5076
  *
5066
5077
  * @remarks
5067
5078
  * The wire is strictly narrower than the domain: non-JSON arguments are refused.
5068
- * ToolCall.caller is not in this shape and never crosses a wire. The guard refuses
5069
- * that extra member; the contract parser drops it.
5079
+ * Calls carry only id, name, and arguments; execution context stays local.
5080
+ * The guard refuses every extra member; the contract parser drops extra members.
5070
5081
  */
5071
5082
  export declare const toolCallShape: ObjectShape< {
5072
5083
  id: StringShape;
@@ -486,6 +486,14 @@ export declare type AgentEventMap = {
486
486
  * - **Bounded.** Each turn arms a single cancel folded from the external `signal`, the
487
487
  * `timeout` deadline, and the `budget` signal (through `AbortSignal.any`); any of them —
488
488
  * or `abort()` — stops the loop and settles the result `partial: true`.
489
+ * Tool handlers receive that run's signal through their `ToolContext`. An agent abort,
490
+ * stream abort, external signal, or deadline can reach a running handler. The budget is
491
+ * charged during provider streaming and between turns, before tool dispatch; exhaustion
492
+ * ends the run without dispatching, never inside a handler. An abort before dispatch
493
+ * appends neither the assistant call turn nor tool messages and emits no tool chunk;
494
+ * streamed content remains in the partial result. Cancellation after entry is cooperative:
495
+ * the loop awaits a running handler even when it ignores the signal.
496
+ * The agent supplies no caller identity.
489
497
  * - **Paced + capped.** The `scheduler` (when given) yields between turns; tool
490
498
  * iteration is capped at `limit` so the loop always terminates.
491
499
  * - **Two observation surfaces.** Pull: the {@link AgentChunk} stream (`stream().events`)
@@ -3826,7 +3834,7 @@ export declare type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
3826
3834
  *
3827
3835
  * @remarks
3828
3836
  * The wire is strictly narrower than Message: non-JSON call arguments are refused,
3829
- * and caller context is refused by the guard or dropped by the parser.
3837
+ * and execution context stays local. The guard refuses extra members; the parser drops them.
3830
3838
  */
3831
3839
  export declare const messageShape: ObjectShape< {
3832
3840
  id: StringShape;
@@ -4056,7 +4064,8 @@ readonly [k: string]: JSONValue;
4056
4064
  *
4057
4065
  * @remarks
4058
4066
  * The wire is strictly narrower than ProviderRequest: non-JSON arguments, parameters,
4059
- * or schema members are refused, and caller context is refused or dropped.
4067
+ * or schema members are refused. Execution context stays local; the guard refuses
4068
+ * extra members, and the parser drops them.
4060
4069
  */
4061
4070
  export declare const providerRequestShape: ObjectShape< {
4062
4071
  messages: ArrayShape<ObjectShape< {
@@ -4130,7 +4139,7 @@ total: number;
4130
4139
  *
4131
4140
  * @remarks
4132
4141
  * The wire is strictly narrower than ProviderResult: non-JSON call arguments are
4133
- * refused, and caller context is refused or dropped.
4142
+ * refused. Execution context stays local; the guard refuses extra members, and the parser drops them.
4134
4143
  */
4135
4144
  export declare const providerResultShape: ObjectShape< {
4136
4145
  content: StringShape;
@@ -4284,7 +4293,8 @@ message: string;
4284
4293
  *
4285
4294
  * @remarks
4286
4295
  * The wire is strictly narrower than RelayFrame through its result and partial
4287
- * fields: non-JSON arguments are refused, and caller context is refused or dropped.
4296
+ * fields: non-JSON arguments are refused. Execution context stays local; the guard
4297
+ * refuses extra members, and the parser drops them.
4288
4298
  */
4289
4299
  export declare const relayFrameShape: UnionShape<readonly [ObjectShape< {
4290
4300
  channel: LiteralShape<readonly ["content", "thinking"]>;
@@ -4353,7 +4363,8 @@ export declare interface RelayOptions {
4353
4363
  * Carries provider calls over an authenticated NDJSON relay endpoint.
4354
4364
  *
4355
4365
  * @remarks
4356
- * The `ToolCall.caller` member never crosses the hop. The wire body is an owned snapshot of
4366
+ * Tool execution context stays local; calls carry only `id`, `name`, and `arguments`.
4367
+ * The wire body is an owned snapshot of
4357
4368
  * the projection read through property descriptors, so a serializer reachable only through a
4358
4369
  * `get` trap or a prototype is never consulted; an own function-valued property such as a
4359
4370
  * `toJSON` method is a value outside JSON and is refused before fetching, with the clone's
@@ -4398,7 +4409,7 @@ export declare class RelayProvider extends AgentProvider {
4398
4409
  * value carries is ignored rather than consulted and cannot reach the wire.
4399
4410
  *
4400
4411
  * @param request - The domain conversation and call configuration
4401
- * @returns The validated wire request with caller context omitted
4412
+ * @returns The validated wire request
4402
4413
  * @throws {ProviderError} Thrown when the snapshot cannot be taken — a hostile read or a
4403
4414
  * value outside JSON — carrying that failure as its `cause`, and when the snapshot the
4404
4415
  * projection produced is not a valid wire request
@@ -5065,8 +5076,8 @@ export declare interface ThinkSplitterInterface {
5065
5076
  *
5066
5077
  * @remarks
5067
5078
  * The wire is strictly narrower than the domain: non-JSON arguments are refused.
5068
- * ToolCall.caller is not in this shape and never crosses a wire. The guard refuses
5069
- * that extra member; the contract parser drops it.
5079
+ * Calls carry only id, name, and arguments; execution context stays local.
5080
+ * The guard refuses every extra member; the contract parser drops extra members.
5070
5081
  */
5071
5082
  export declare const toolCallShape: ObjectShape< {
5072
5083
  id: StringShape;
@@ -367,8 +367,8 @@ function isProviderError(value) {
367
367
  *
368
368
  * @remarks
369
369
  * The wire is strictly narrower than the domain: non-JSON arguments are refused.
370
- * ToolCall.caller is not in this shape and never crosses a wire. The guard refuses
371
- * that extra member; the contract parser drops it.
370
+ * Calls carry only id, name, and arguments; execution context stays local.
371
+ * The guard refuses every extra member; the contract parser drops extra members.
372
372
  */
373
373
  var toolCallShape = objectShape({
374
374
  id: stringShape(),
@@ -380,7 +380,7 @@ var toolCallShape = objectShape({
380
380
  *
381
381
  * @remarks
382
382
  * The wire is strictly narrower than Message: non-JSON call arguments are refused,
383
- * and caller context is refused by the guard or dropped by the parser.
383
+ * and execution context stays local. The guard refuses extra members; the parser drops them.
384
384
  */
385
385
  var messageShape = objectShape({
386
386
  id: stringShape(),
@@ -399,7 +399,8 @@ var messageShape = objectShape({
399
399
  *
400
400
  * @remarks
401
401
  * The wire is strictly narrower than ProviderRequest: non-JSON arguments, parameters,
402
- * or schema members are refused, and caller context is refused or dropped.
402
+ * or schema members are refused. Execution context stays local; the guard refuses
403
+ * extra members, and the parser drops them.
403
404
  */
404
405
  var providerRequestShape = objectShape({
405
406
  messages: arrayShape(messageShape),
@@ -418,7 +419,7 @@ var providerRequestShape = objectShape({
418
419
  *
419
420
  * @remarks
420
421
  * The wire is strictly narrower than ProviderResult: non-JSON call arguments are
421
- * refused, and caller context is refused or dropped.
422
+ * refused. Execution context stays local; the guard refuses extra members, and the parser drops them.
422
423
  */
423
424
  var providerResultShape = objectShape({
424
425
  content: stringShape(),
@@ -435,7 +436,8 @@ var providerResultShape = objectShape({
435
436
  *
436
437
  * @remarks
437
438
  * The wire is strictly narrower than RelayFrame through its result and partial
438
- * fields: non-JSON arguments are refused, and caller context is refused or dropped.
439
+ * fields: non-JSON arguments are refused. Execution context stays local; the guard
440
+ * refuses extra members, and the parser drops them.
439
441
  */
440
442
  var relayFrameShape = unionShape(objectShape({
441
443
  channel: literalShape(["content", "thinking"]),
@@ -2162,13 +2164,19 @@ var Agent = class {
2162
2164
  };
2163
2165
  }
2164
2166
  if (result.tools !== void 0 && result.tools.length > 0) {
2167
+ const authorization = this.#authorize(result.tools);
2168
+ if (abort.signal.aborted) {
2169
+ partial = true;
2170
+ broke = true;
2171
+ break;
2172
+ }
2165
2173
  const assistant = this.#context.messages.add({
2166
2174
  role: "assistant",
2167
2175
  content: result.content,
2168
2176
  calls: result.tools
2169
2177
  });
2170
2178
  messages.push(assistant);
2171
- const results = await this.#authorize(tools, result.tools);
2179
+ const results = await this.#dispatch(tools, result.tools, abort.signal, authorization);
2172
2180
  for (let index = 0; index < result.tools.length; index += 1) {
2173
2181
  const call = result.tools[index];
2174
2182
  const outcomeResult = results[index];
@@ -2228,8 +2236,8 @@ var Agent = class {
2228
2236
  messages.splice(0, messages.length, ...this.#context.build(this.#provider.format));
2229
2237
  return false;
2230
2238
  }
2231
- async #authorize(tools, calls) {
2232
- if (this.#authority === void 0) return tools.execute(calls);
2239
+ #authorize(calls) {
2240
+ if (this.#authority === void 0) return void 0;
2233
2241
  const authority = this.#authority;
2234
2242
  const allowed = [];
2235
2243
  const denials = /* @__PURE__ */ new Map();
@@ -2249,7 +2257,15 @@ var Agent = class {
2249
2257
  this.#emitter.emit("deny", call, decision.reason);
2250
2258
  }
2251
2259
  }
2252
- const executed = allowed.length > 0 ? await tools.execute(allowed) : [];
2260
+ return {
2261
+ allowed,
2262
+ denials
2263
+ };
2264
+ }
2265
+ async #dispatch(tools, calls, signal, authorization) {
2266
+ if (authorization === void 0) return tools.execute(calls, { signal });
2267
+ const { allowed, denials } = authorization;
2268
+ const executed = allowed.length > 0 ? await tools.execute(allowed, { signal }) : [];
2253
2269
  const byId = new Map(denials);
2254
2270
  for (const result of executed) byId.set(result.id, result);
2255
2271
  return calls.map((call) => byId.get(call.id) ?? denyCall(call, void 0));
@@ -2933,7 +2949,8 @@ var AgentProvider = class {
2933
2949
  * Carries provider calls over an authenticated NDJSON relay endpoint.
2934
2950
  *
2935
2951
  * @remarks
2936
- * The `ToolCall.caller` member never crosses the hop. The wire body is an owned snapshot of
2952
+ * Tool execution context stays local; calls carry only `id`, `name`, and `arguments`.
2953
+ * The wire body is an owned snapshot of
2937
2954
  * the projection read through property descriptors, so a serializer reachable only through a
2938
2955
  * `get` trap or a prototype is never consulted; an own function-valued property such as a
2939
2956
  * `toJSON` method is a value outside JSON and is refused before fetching, with the clone's
@@ -2992,7 +3009,7 @@ var RelayProvider = class extends AgentProvider {
2992
3009
  * value carries is ignored rather than consulted and cannot reach the wire.
2993
3010
  *
2994
3011
  * @param request - The domain conversation and call configuration
2995
- * @returns The validated wire request with caller context omitted
3012
+ * @returns The validated wire request
2996
3013
  * @throws {ProviderError} Thrown when the snapshot cannot be taken — a hostile read or a
2997
3014
  * value outside JSON — carrying that failure as its `cause`, and when the snapshot the
2998
3015
  * projection produced is not a valid wire request