@orkestrel/agent 0.0.32 → 0.0.33

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.
@@ -40,11 +40,12 @@ var JudgeAbortError = class extends Error {
40
40
  constructor(partial, options) {
41
41
  super("judge call aborted", options);
42
42
  this.name = "JudgeAbortError";
43
+ _orkestrel_contract.INTRINSICS.define(this, Symbol.for("@orkestrel/agent.JudgeAbortError"), { value: this });
43
44
  this.partial = partial;
44
45
  }
45
46
  };
46
47
  /**
47
- * Narrows a caught value to a {@link JudgeAbortError} through `instanceof`, so a `catch` can
48
+ * Narrows a caught value to a {@link JudgeAbortError} through its identity brand and declared members, so a `catch` can
48
49
  * recover its `partial` result.
49
50
  *
50
51
  * @param value - The caught value
@@ -55,7 +56,27 @@ var JudgeAbortError = class extends Error {
55
56
  * ```
56
57
  */
57
58
  function isJudgeAbortError(value) {
58
- return (0, _orkestrel_contract.isInstance)(value, JudgeAbortError);
59
+ return (0, _orkestrel_contract.holds)(() => {
60
+ if (!(value instanceof Error && _orkestrel_contract.INTRINSICS.prototype(value) !== Error.prototype && _orkestrel_contract.INTRINSICS.describe(value, Symbol.for("@orkestrel/agent.JudgeAbortError"))?.value === value)) return false;
61
+ if (!(_orkestrel_contract.INTRINSICS.reflect.read(value, "code") === "ABORT")) return false;
62
+ const partial = _orkestrel_contract.INTRINSICS.reflect.read(value, "partial");
63
+ if (!((0, _orkestrel_contract.isObject)(partial) || (0, _orkestrel_contract.isFunction)(partial))) return false;
64
+ const answers = _orkestrel_contract.INTRINSICS.reflect.read(partial, "answers");
65
+ const refusals = _orkestrel_contract.INTRINSICS.reflect.read(partial, "refusals");
66
+ const usage = _orkestrel_contract.INTRINSICS.reflect.read(partial, "usage");
67
+ return (0, _orkestrel_contract.isString)(_orkestrel_contract.INTRINSICS.reflect.read(partial, "model")) && (usage === void 0 || ((0, _orkestrel_contract.isObject)(usage) || (0, _orkestrel_contract.isFunction)(usage)) && [
68
+ "prompt",
69
+ "completion",
70
+ "total"
71
+ ].every((key) => (0, _orkestrel_contract.isNumber)(_orkestrel_contract.INTRINSICS.reflect.read(usage, key)))) && ((0, _orkestrel_contract.isObject)(answers) || (0, _orkestrel_contract.isFunction)(answers)) && _orkestrel_contract.INTRINSICS.values(answers).every((answer) => {
72
+ if (!((0, _orkestrel_contract.isObject)(answer) || (0, _orkestrel_contract.isFunction)(answer))) return false;
73
+ const form = _orkestrel_contract.INTRINSICS.reflect.read(answer, "form");
74
+ if (form === "noul") return (0, _orkestrel_contract.isNumber)(_orkestrel_contract.INTRINSICS.reflect.read(answer, "noul"));
75
+ const probabilities = _orkestrel_contract.INTRINSICS.reflect.read(answer, "probabilities");
76
+ if (form === "score") return (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isNumber)(probabilities);
77
+ return form === "choice" && ((0, _orkestrel_contract.isObject)(probabilities) || (0, _orkestrel_contract.isFunction)(probabilities)) && _orkestrel_contract.INTRINSICS.values(probabilities).every(_orkestrel_contract.isNumber);
78
+ }) && (refusals === void 0 || ((0, _orkestrel_contract.isObject)(refusals) || (0, _orkestrel_contract.isFunction)(refusals)) && _orkestrel_contract.INTRINSICS.values(refusals).every((refusal) => ((0, _orkestrel_contract.isObject)(refusal) || (0, _orkestrel_contract.isFunction)(refusal)) && (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isString)(_orkestrel_contract.INTRINSICS.reflect.read(refusal, "missing"))));
79
+ });
59
80
  }
60
81
  // src/core/shapers.ts
61
82
  /**
@@ -615,11 +636,12 @@ var ProviderAbortError = class extends Error {
615
636
  constructor(partial, options) {
616
637
  super("provider stream aborted", options);
617
638
  this.name = "ProviderAbortError";
639
+ _orkestrel_contract.INTRINSICS.define(this, Symbol.for("@orkestrel/agent.ProviderAbortError"), { value: this });
618
640
  this.partial = partial;
619
641
  }
620
642
  };
621
643
  /**
622
- * Narrows an unknown caught value to a {@link ProviderAbortError} through `instanceof`, so a
644
+ * Narrows an unknown caught value to a {@link ProviderAbortError} through its identity brand and declared members, so a
623
645
  * `catch` can recover its `partial` result.
624
646
  *
625
647
  * @param value - The value to test (typically a `catch` binding)
@@ -635,7 +657,19 @@ var ProviderAbortError = class extends Error {
635
657
  * ```
636
658
  */
637
659
  function isProviderAbortError(value) {
638
- return (0, _orkestrel_contract.isInstance)(value, ProviderAbortError);
660
+ return (0, _orkestrel_contract.holds)(() => {
661
+ if (!(value instanceof Error && _orkestrel_contract.INTRINSICS.prototype(value) !== Error.prototype && _orkestrel_contract.INTRINSICS.describe(value, Symbol.for("@orkestrel/agent.ProviderAbortError"))?.value === value)) return false;
662
+ if (!(_orkestrel_contract.INTRINSICS.reflect.read(value, "code") === "ABORT")) return false;
663
+ const partial = _orkestrel_contract.INTRINSICS.reflect.read(value, "partial");
664
+ if (!((0, _orkestrel_contract.isObject)(partial) || (0, _orkestrel_contract.isFunction)(partial))) return false;
665
+ const usage = _orkestrel_contract.INTRINSICS.reflect.read(partial, "usage");
666
+ const tools = _orkestrel_contract.INTRINSICS.reflect.read(partial, "tools");
667
+ return (0, _orkestrel_contract.isString)(_orkestrel_contract.INTRINSICS.reflect.read(partial, "content")) && (_orkestrel_contract.INTRINSICS.reflect.read(partial, "thinking") === void 0 || (0, _orkestrel_contract.isString)(_orkestrel_contract.INTRINSICS.reflect.read(partial, "thinking"))) && (_orkestrel_contract.INTRINSICS.reflect.read(partial, "truncated") === void 0 || (0, _orkestrel_contract.isBoolean)(_orkestrel_contract.INTRINSICS.reflect.read(partial, "truncated"))) && (usage === void 0 || ((0, _orkestrel_contract.isObject)(usage) || (0, _orkestrel_contract.isFunction)(usage)) && [
668
+ "prompt",
669
+ "completion",
670
+ "total"
671
+ ].every((key) => (0, _orkestrel_contract.isNumber)(_orkestrel_contract.INTRINSICS.reflect.read(usage, key)))) && (tools === void 0 || (0, _orkestrel_contract.arrayOf)((tool) => ((0, _orkestrel_contract.isObject)(tool) || (0, _orkestrel_contract.isFunction)(tool)) && (0, _orkestrel_contract.isString)(_orkestrel_contract.INTRINSICS.reflect.read(tool, "id")) && (0, _orkestrel_contract.isString)(_orkestrel_contract.INTRINSICS.reflect.read(tool, "name")) && ((0, _orkestrel_contract.isObject)(_orkestrel_contract.INTRINSICS.reflect.read(tool, "arguments")) || (0, _orkestrel_contract.isFunction)(_orkestrel_contract.INTRINSICS.reflect.read(tool, "arguments"))))(tools));
672
+ });
639
673
  }
640
674
  /**
641
675
  * Reports a coded provider failure with its HTTP status and underlying cause when available.
@@ -654,12 +688,13 @@ var ProviderError = class extends Error {
654
688
  constructor(code, message, options) {
655
689
  super(message, options);
656
690
  this.name = "ProviderError";
691
+ _orkestrel_contract.INTRINSICS.define(this, Symbol.for("@orkestrel/agent.ProviderError"), { value: this });
657
692
  this.code = code;
658
693
  this.status = options?.status;
659
694
  }
660
695
  };
661
696
  /**
662
- * Narrows a caught value to the provider failure class through `instanceof`.
697
+ * Narrows a caught value to the provider failure class through its identity brand and declared members.
663
698
  *
664
699
  * @param value - The caught value
665
700
  * @returns True if the value is a provider failure; false otherwise
@@ -669,7 +704,13 @@ var ProviderError = class extends Error {
669
704
  * ```
670
705
  */
671
706
  function isProviderError(value) {
672
- return (0, _orkestrel_contract.isInstance)(value, ProviderError);
707
+ return (0, _orkestrel_contract.holds)(() => {
708
+ if (!(value instanceof Error && _orkestrel_contract.INTRINSICS.prototype(value) !== Error.prototype && _orkestrel_contract.INTRINSICS.describe(value, Symbol.for("@orkestrel/agent.ProviderError"))?.value === value)) return false;
709
+ const code = _orkestrel_contract.INTRINSICS.reflect.read(value, "code");
710
+ if (!(code === "HTTP" || code === "PROTOCOL" || code === "PROVIDER")) return false;
711
+ const status = _orkestrel_contract.INTRINSICS.reflect.read(value, "status");
712
+ return status === void 0 || (0, _orkestrel_contract.isNumber)(status);
713
+ });
673
714
  }
674
715
  /**
675
716
  * Reports a coded judge failure with its HTTP status and underlying cause when available.
@@ -688,12 +729,13 @@ var JudgeError = class extends Error {
688
729
  constructor(code, message, options) {
689
730
  super(message, options);
690
731
  this.name = "JudgeError";
732
+ _orkestrel_contract.INTRINSICS.define(this, Symbol.for("@orkestrel/agent.JudgeError"), { value: this });
691
733
  this.code = code;
692
734
  this.status = options?.status;
693
735
  }
694
736
  };
695
737
  /**
696
- * Narrows a caught value to the judge failure class through `instanceof`.
738
+ * Narrows a caught value to the judge failure class through its identity brand and declared members.
697
739
  *
698
740
  * @param value - The caught value
699
741
  * @returns True if the value is a {@link JudgeError}; false otherwise
@@ -703,7 +745,13 @@ var JudgeError = class extends Error {
703
745
  * ```
704
746
  */
705
747
  function isJudgeError(value) {
706
- return (0, _orkestrel_contract.isInstance)(value, JudgeError);
748
+ return (0, _orkestrel_contract.holds)(() => {
749
+ if (!(value instanceof Error && _orkestrel_contract.INTRINSICS.prototype(value) !== Error.prototype && _orkestrel_contract.INTRINSICS.describe(value, Symbol.for("@orkestrel/agent.JudgeError"))?.value === value)) return false;
750
+ const code = _orkestrel_contract.INTRINSICS.reflect.read(value, "code");
751
+ if (!(code === "HTTP" || code === "PROTOCOL" || code === "QUESTION")) return false;
752
+ const status = _orkestrel_contract.INTRINSICS.reflect.read(value, "status");
753
+ return status === void 0 || (0, _orkestrel_contract.isNumber)(status);
754
+ });
707
755
  }
708
756
  // src/core/providers/shapers.ts
709
757
  /**
@@ -2329,12 +2377,13 @@ var ConversationError = class extends Error {
2329
2377
  constructor(code, message, options) {
2330
2378
  super(message, options?.cause === void 0 ? void 0 : { cause: options.cause });
2331
2379
  this.name = "ConversationError";
2380
+ _orkestrel_contract.INTRINSICS.define(this, Symbol.for("@orkestrel/agent.ConversationError"), { value: this });
2332
2381
  this.code = code;
2333
2382
  this.context = options?.context;
2334
2383
  }
2335
2384
  };
2336
2385
  /**
2337
- * Narrows an unknown caught value to a {@link ConversationError} through `instanceof`, so a
2386
+ * Narrows an unknown caught value to a {@link ConversationError} through its identity brand and declared members, so a
2338
2387
  * `catch` can branch on its `code`.
2339
2388
  *
2340
2389
  * @param value - The value to test (typically a `catch` binding)
@@ -2350,7 +2399,13 @@ var ConversationError = class extends Error {
2350
2399
  * ```
2351
2400
  */
2352
2401
  function isConversationError(value) {
2353
- return (0, _orkestrel_contract.isInstance)(value, ConversationError);
2402
+ return (0, _orkestrel_contract.holds)(() => {
2403
+ if (!(value instanceof Error && _orkestrel_contract.INTRINSICS.prototype(value) !== Error.prototype && _orkestrel_contract.INTRINSICS.describe(value, Symbol.for("@orkestrel/agent.ConversationError"))?.value === value)) return false;
2404
+ const code = _orkestrel_contract.INTRINSICS.reflect.read(value, "code");
2405
+ if (!(code === "SUMMARIZER" || code === "SECTIONS" || code === "JUDGMENT" || code === "KEEP")) return false;
2406
+ const context = _orkestrel_contract.INTRINSICS.reflect.read(value, "context");
2407
+ return context === void 0 || (0, _orkestrel_contract.isObject)(context) || (0, _orkestrel_contract.isFunction)(context);
2408
+ });
2354
2409
  }
2355
2410
  // src/core/conversations/validators.ts
2356
2411
  /**
@@ -4285,11 +4340,12 @@ var AgentJobError = class extends Error {
4285
4340
  constructor(message, partial) {
4286
4341
  super(message);
4287
4342
  this.name = "AgentJobError";
4343
+ _orkestrel_contract.INTRINSICS.define(this, Symbol.for("@orkestrel/agent.AgentJobError"), { value: this });
4288
4344
  this.partial = partial;
4289
4345
  }
4290
4346
  };
4291
4347
  /**
4292
- * Narrows an unknown caught value to an {@link AgentJobError} through `instanceof`, so a
4348
+ * Narrows an unknown caught value to an {@link AgentJobError} through its identity brand and declared members, so a
4293
4349
  * `catch` can recover its `partial` result.
4294
4350
  *
4295
4351
  * @param value - The value to test (typically a `catch` binding or a rejected enqueue)
@@ -4305,7 +4361,30 @@ var AgentJobError = class extends Error {
4305
4361
  * ```
4306
4362
  */
4307
4363
  function isAgentJobError(value) {
4308
- return (0, _orkestrel_contract.isInstance)(value, AgentJobError);
4364
+ return (0, _orkestrel_contract.holds)(() => {
4365
+ if (!(value instanceof Error && _orkestrel_contract.INTRINSICS.prototype(value) !== Error.prototype && _orkestrel_contract.INTRINSICS.describe(value, Symbol.for("@orkestrel/agent.AgentJobError"))?.value === value)) return false;
4366
+ if (!(_orkestrel_contract.INTRINSICS.reflect.read(value, "code") === "PARTIAL")) return false;
4367
+ const partial = _orkestrel_contract.INTRINSICS.reflect.read(value, "partial");
4368
+ if (!((0, _orkestrel_contract.isObject)(partial) || (0, _orkestrel_contract.isFunction)(partial))) return false;
4369
+ const usage = _orkestrel_contract.INTRINSICS.reflect.read(partial, "usage");
4370
+ const stop = _orkestrel_contract.INTRINSICS.reflect.read(partial, "stop");
4371
+ if (stop !== void 0) {
4372
+ if (!((0, _orkestrel_contract.isObject)(stop) || (0, _orkestrel_contract.isFunction)(stop))) return false;
4373
+ const layer = _orkestrel_contract.INTRINSICS.reflect.read(stop, "layer");
4374
+ const spent = _orkestrel_contract.INTRINSICS.reflect.read(stop, "usage");
4375
+ if (!(0, _orkestrel_contract.isString)(_orkestrel_contract.INTRINSICS.reflect.read(stop, "id")) || !(_orkestrel_contract.INTRINSICS.reflect.read(stop, "estimate") === void 0 || (0, _orkestrel_contract.isNumber)(_orkestrel_contract.INTRINSICS.reflect.read(stop, "estimate"))) || !(spent === void 0 || ((0, _orkestrel_contract.isObject)(spent) || (0, _orkestrel_contract.isFunction)(spent)) && [
4376
+ "prompt",
4377
+ "completion",
4378
+ "total"
4379
+ ].every((key) => (0, _orkestrel_contract.isNumber)(_orkestrel_contract.INTRINSICS.reflect.read(spent, key))))) return false;
4380
+ if (layer !== "model" && !((layer === "meter" || layer === "budget") && (0, _orkestrel_contract.isNumber)(_orkestrel_contract.INTRINSICS.reflect.read(stop, "max")) && (0, _orkestrel_contract.isNumber)(_orkestrel_contract.INTRINSICS.reflect.read(stop, "consumed")))) return false;
4381
+ }
4382
+ return (0, _orkestrel_contract.isString)(_orkestrel_contract.INTRINSICS.reflect.read(partial, "content")) && (_orkestrel_contract.INTRINSICS.reflect.read(partial, "thinking") === void 0 || (0, _orkestrel_contract.isString)(_orkestrel_contract.INTRINSICS.reflect.read(partial, "thinking"))) && (0, _orkestrel_contract.isBoolean)(_orkestrel_contract.INTRINSICS.reflect.read(partial, "partial")) && (usage === void 0 || ((0, _orkestrel_contract.isObject)(usage) || (0, _orkestrel_contract.isFunction)(usage)) && [
4383
+ "prompt",
4384
+ "completion",
4385
+ "total"
4386
+ ].every((key) => (0, _orkestrel_contract.isNumber)(_orkestrel_contract.INTRINSICS.reflect.read(usage, key))));
4387
+ });
4309
4388
  }
4310
4389
  /**
4311
4390
  * Reports a run sharing accounting with a live run, a `limit` that is not a nonnegative safe integer, a name absent from a registry pool, or a strict run whose request exceeds its window. Agent construction, the `stream` and `generate` methods, and registry accessors throw synchronously, before returning a handle or promise; a `'WINDOW'` refusal rejects the run's `result` instead. Await the call inside `try`/`catch` to catch it.
@@ -4341,12 +4420,13 @@ var AgentError = class extends Error {
4341
4420
  constructor(code, message, options) {
4342
4421
  super(message, options?.cause === void 0 ? void 0 : { cause: options.cause });
4343
4422
  this.name = "AgentError";
4423
+ _orkestrel_contract.INTRINSICS.define(this, Symbol.for("@orkestrel/agent.AgentError"), { value: this });
4344
4424
  this.code = code;
4345
4425
  this.context = options?.context;
4346
4426
  }
4347
4427
  };
4348
4428
  /**
4349
- * Narrows an unknown caught value to an {@link AgentError} through `instanceof`, so a `catch`
4429
+ * Narrows an unknown caught value to an {@link AgentError} through its identity brand and declared members, so a `catch`
4350
4430
  * can branch on its `code`.
4351
4431
  *
4352
4432
  * @param value - The value to test (typically a `catch` binding)
@@ -4362,7 +4442,13 @@ var AgentError = class extends Error {
4362
4442
  * ```
4363
4443
  */
4364
4444
  function isAgentError(value) {
4365
- return (0, _orkestrel_contract.isInstance)(value, AgentError);
4445
+ return (0, _orkestrel_contract.holds)(() => {
4446
+ if (!(value instanceof Error && _orkestrel_contract.INTRINSICS.prototype(value) !== Error.prototype && _orkestrel_contract.INTRINSICS.describe(value, Symbol.for("@orkestrel/agent.AgentError"))?.value === value)) return false;
4447
+ const code = _orkestrel_contract.INTRINSICS.reflect.read(value, "code");
4448
+ if (!(code === "CONCURRENCY" || code === "LIMIT" || code === "REGISTRY" || code === "WINDOW")) return false;
4449
+ const context = _orkestrel_contract.INTRINSICS.reflect.read(value, "context");
4450
+ return context === void 0 || (0, _orkestrel_contract.isObject)(context) || (0, _orkestrel_contract.isFunction)(context);
4451
+ });
4366
4452
  }
4367
4453
  // src/core/agents/Channel.ts
4368
4454
  /**
@@ -4661,7 +4747,7 @@ function estimateTokens(text) {
4661
4747
  function estimateMessages(messages) {
4662
4748
  return messages.reduce((sum, message) => {
4663
4749
  const measure = measureMessage(message);
4664
- return sum + measure.content + measure.framing + measure.calls + measure.thinking + measure.images;
4750
+ return sum + measure.content + measure.uniform + measure.calls + measure.thinking + measure.images;
4665
4751
  }, 0);
4666
4752
  }
4667
4753
  /**
@@ -4671,7 +4757,7 @@ function estimateMessages(messages) {
4671
4757
  * @remarks
4672
4758
  * The result is a structural estimate, not a tokenizer allocation. `id` and `role` are joins back to
4673
4759
  * the message, not token components, and a provider's template effects and the estimation error are
4674
- * not individually attributed. `content` is `ceil(length / 4)`, `framing` is
4760
+ * not individually attributed. `content` is `ceil(length / 4)`, `uniform` is
4675
4761
  * {@link import('./constants.js').MESSAGE_TOKEN_OVERHEAD}, `calls` is the estimate of the JSON-rendered
4676
4762
  * calls (`0` when the message carries none, the framing overhead when they cannot be rendered),
4677
4763
  * `thinking` is the estimate of the thinking (`0` when absent), and `images` is the attached image
@@ -4683,7 +4769,7 @@ function estimateMessages(messages) {
4683
4769
  * @example
4684
4770
  * ```ts
4685
4771
  * measureMessage({ id: '1', role: 'user', content: 'hello' })
4686
- * // { id: '1', role: 'user', content: 2, framing: 4, calls: 0, thinking: 0, images: 0 }
4772
+ * // { id: '1', role: 'user', content: 2, uniform: 4, calls: 0, thinking: 0, images: 0 }
4687
4773
  * ```
4688
4774
  */
4689
4775
  function measureMessage(message) {
@@ -4693,7 +4779,7 @@ function measureMessage(message) {
4693
4779
  id: message.id,
4694
4780
  role: message.role,
4695
4781
  content: estimateTokens(message.content),
4696
- framing: 4,
4782
+ uniform: 4,
4697
4783
  calls,
4698
4784
  thinking: message.thinking === void 0 ? 0 : estimateTokens(message.thinking),
4699
4785
  images: (message.images?.length ?? 0) * 512
@@ -4725,7 +4811,7 @@ function measureMessage(message) {
4725
4811
  */
4726
4812
  function estimateRequest(request) {
4727
4813
  const measure = measureRequest(request);
4728
- return measure.messages.reduce((sum, message) => sum + message.content + message.framing + message.calls + message.thinking + message.images, measure.tools + measure.schema);
4814
+ return measure.messages.reduce((sum, message) => sum + message.content + message.uniform + message.calls + message.thinking + message.images, measure.tools + measure.schema);
4729
4815
  }
4730
4816
  /**
4731
4817
  * Measures the disjoint estimate components of a complete provider request — each message through
@@ -4746,7 +4832,7 @@ function estimateRequest(request) {
4746
4832
  * @example
4747
4833
  * ```ts
4748
4834
  * measureRequest({ messages: [{ id: '1', role: 'user', content: 'hello' }] })
4749
- * // { messages: [{ id: '1', role: 'user', content: 2, framing: 4, calls: 0, thinking: 0, images: 0 }], tools: 0, schema: 0 }
4835
+ * // { messages: [{ id: '1', role: 'user', content: 2, uniform: 4, calls: 0, thinking: 0, images: 0 }], tools: 0, schema: 0 }
4750
4836
  * ```
4751
4837
  */
4752
4838
  function measureRequest(request) {
@@ -5197,7 +5283,7 @@ var Agent = class {
5197
5283
  this.#window?.clear();
5198
5284
  const cancelled = abort.signal.aborted;
5199
5285
  const turns = [];
5200
- while (turns.length < limit && (turns.at(-1)?.ending ?? "tools") === "tools") {
5286
+ while (turns.length < limit && (turns.at(-1)?.outcome ?? "tools") === "tools") {
5201
5287
  const index = turns.length;
5202
5288
  const base = turns.at(-1)?.messages ?? entry.messages;
5203
5289
  const futile = turns.at(-1)?.futile ?? false;
@@ -5207,7 +5293,7 @@ var Agent = class {
5207
5293
  usage: void 0,
5208
5294
  spent: void 0,
5209
5295
  messages: base,
5210
- ending: "cancel",
5296
+ outcome: "cancel",
5211
5297
  partial: true,
5212
5298
  futile,
5213
5299
  estimate: void 0,
@@ -5253,7 +5339,7 @@ var Agent = class {
5253
5339
  if (!provided.success) {
5254
5340
  turns.push({
5255
5341
  ...settled,
5256
- ending: "cancel",
5342
+ outcome: "cancel",
5257
5343
  partial: true
5258
5344
  });
5259
5345
  continue;
@@ -5275,7 +5361,7 @@ var Agent = class {
5275
5361
  if (abort.signal.aborted) {
5276
5362
  turns.push({
5277
5363
  ...settled,
5278
- ending: "cancel",
5364
+ outcome: "cancel",
5279
5365
  partial: true
5280
5366
  });
5281
5367
  continue;
@@ -5310,7 +5396,7 @@ var Agent = class {
5310
5396
  assistant,
5311
5397
  ...replies
5312
5398
  ],
5313
- ending: "tools",
5399
+ outcome: "tools",
5314
5400
  partial: true
5315
5401
  });
5316
5402
  continue;
@@ -5323,7 +5409,7 @@ var Agent = class {
5323
5409
  turns.push({
5324
5410
  ...settled,
5325
5411
  content: result.content,
5326
- ending: "answer",
5412
+ outcome: "answer",
5327
5413
  partial: abort.signal.aborted,
5328
5414
  truncated: result.truncated === true
5329
5415
  });
@@ -5331,7 +5417,7 @@ var Agent = class {
5331
5417
  const final = turns.at(-1);
5332
5418
  const thinkings = turns.flatMap((turn) => turn.thinking === void 0 ? [] : [turn.thinking]);
5333
5419
  return {
5334
- content: final?.ending === "answer" ? final.content : turns.map((turn) => turn.content).join(""),
5420
+ content: final?.outcome === "answer" ? final.content : turns.map((turn) => turn.content).join(""),
5335
5421
  thinking: thinkings.length === 0 ? void 0 : thinkings.join("\n\n"),
5336
5422
  usage: [
5337
5423
  ...turns.map((turn) => turn.usage),
@@ -5339,7 +5425,7 @@ var Agent = class {
5339
5425
  ...turns.map((turn) => turn.spent)
5340
5426
  ].reduce((total, one) => one === void 0 ? total : sumUsage(total, one), void 0),
5341
5427
  partial: final?.partial ?? cancelled,
5342
- exhausted: final?.ending === "tools" && !abort.signal.aborted,
5428
+ exhausted: final?.outcome === "tools" && !abort.signal.aborted,
5343
5429
  stop: inferStop(abort.signal.reason, allowance, budget, this.#provider.id, final)
5344
5430
  };
5345
5431
  }
@@ -6140,11 +6226,12 @@ var LedgerError = class extends Error {
6140
6226
  constructor(code, message) {
6141
6227
  super(message);
6142
6228
  this.name = "LedgerError";
6229
+ _orkestrel_contract.INTRINSICS.define(this, Symbol.for("@orkestrel/agent.LedgerError"), { value: this });
6143
6230
  this.code = code;
6144
6231
  }
6145
6232
  };
6146
6233
  /**
6147
- * Narrows an unknown caught value to a {@link LedgerError} through `instanceof`, so a `catch` can
6234
+ * Narrows an unknown caught value to a {@link LedgerError} through its identity brand and declared members, so a `catch` can
6148
6235
  * branch on its `code`.
6149
6236
  *
6150
6237
  * @param value - The value to test (typically a `catch` binding)
@@ -6156,7 +6243,12 @@ var LedgerError = class extends Error {
6156
6243
  * ```
6157
6244
  */
6158
6245
  function isLedgerError(value) {
6159
- return (0, _orkestrel_contract.isInstance)(value, LedgerError);
6246
+ return (0, _orkestrel_contract.holds)(() => {
6247
+ if (!(value instanceof Error && _orkestrel_contract.INTRINSICS.prototype(value) !== Error.prototype && _orkestrel_contract.INTRINSICS.describe(value, Symbol.for("@orkestrel/agent.LedgerError"))?.value === value)) return false;
6248
+ const code = _orkestrel_contract.INTRINSICS.reflect.read(value, "code");
6249
+ if (!(code === "REQUEST" || code === "THRESHOLD" || code === "SHARE" || code === "CAPACITY" || code === "LIMIT" || code === "TOPIC" || code === "LOOKUP" || code === "GAUGE" || code === "REFERENCE")) return false;
6250
+ return true;
6251
+ });
6160
6252
  }
6161
6253
  // src/core/ledgers/helpers.ts
6162
6254
  /**