@rulvar/core 1.190.0 → 1.192.0

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/index.d.ts CHANGED
@@ -2381,6 +2381,14 @@ type AgentEvents = {
2381
2381
  label?: string;
2382
2382
  error: WireError;
2383
2383
  willRetry: boolean;
2384
+ } | {
2385
+ type: "quota:denied";
2386
+ agentType: string;
2387
+ label?: string; /** The denied model ref. */
2388
+ model?: string; /** The limiter's reason ('tokensPerMinute 1800000 exhausted'). */
2389
+ reason?: string;
2390
+ retryAfterMs?: number;
2391
+ willRetry: true;
2384
2392
  } | {
2385
2393
  type: "agent:schema-retry";
2386
2394
  agentType: string;
@@ -5192,6 +5200,12 @@ interface RunAgentOptions<S extends SchemaSpec = JsonSchema> {
5192
5200
  adapter: ProviderAdapter;
5193
5201
  resolved: ResolvedInvocation;
5194
5202
  /**
5203
+ * The versioned compat flag (RV1810): emit the legacy `agent:error`
5204
+ * twin beside `quota:denied` for recoverable pre-wire quota waits.
5205
+ * Default off: the wait speaks its own type only.
5206
+ */
5207
+ quotaDeniedAgentError?: boolean;
5208
+ /**
5195
5209
  * Transport failover chain for the loop phase (M4-T04):
5196
5210
  * resolved fallback targets tried in order on
5197
5211
  * transport or rate-limit failures after retries exhaust. Failover is
@@ -7070,6 +7084,16 @@ interface CreateEngineOptions {
7070
7084
  modelKnowledge?: ModelKnowledgeStore;
7071
7085
  };
7072
7086
  defaults?: EngineDefaults;
7087
+ /**
7088
+ * Telemetry compat posture (RV1810). `quotaDeniedAgentError: true`
7089
+ * restores the legacy `agent:error` twin beside the primary
7090
+ * `quota:denied` event for recoverable pre-wire quota waits, for
7091
+ * consumers still keyed to the old type. Default off: healthy
7092
+ * throttling speaks its own type and never reads as failure.
7093
+ */
7094
+ telemetry?: {
7095
+ quotaDeniedAgentError?: boolean;
7096
+ };
7073
7097
  budgetDefaults?: BudgetDefaults;
7074
7098
  concurrency?: {
7075
7099
  perRun?: number; /** Per-adapter-id caps; unlimited unless configured (Appendix A; M4-T07). */
@@ -8103,6 +8127,13 @@ interface RunFactPairsFold {
8103
8127
  pairs: ClaimPair[];
8104
8128
  /** True when more sentences matched than `max` allowed to report. */
8105
8129
  truncated: boolean;
8130
+ /**
8131
+ * The UNCAPPED count of matched run-claim sentences (RV1809): with
8132
+ * only `truncated` a consumer knew the bound cut the fold but not by
8133
+ * how much, so no run-fact coverage ratio was computable from the
8134
+ * meta alone.
8135
+ */
8136
+ candidates: number;
8106
8137
  }
8107
8138
  /**
8108
8139
  * Pairs draft sentences that speak about the RUN with the run's own
@@ -9467,6 +9498,32 @@ interface OrchestrateClaimConsistency {
9467
9498
  * `runFacts: true`.
9468
9499
  */
9469
9500
  runFactTerms?: string[];
9501
+ /**
9502
+ * The declared coverage floor (RV1809): the minimum
9503
+ * coveredCitingSentences over draftCitingSentences ratio, in
9504
+ * (0, 1]. The nineteenth benchmark's pass covered 36 of 122 citing
9505
+ * sentences and graded itself 'partial' honestly, but nothing could
9506
+ * ENFORCE a floor: a consumer had to read the counts and decide
9507
+ * externally. Below the floor, `onLowCoverage` decides. A draft
9508
+ * with zero citing sentences is vacuously full and never trips it.
9509
+ */
9510
+ minimumCoverageRatio?: number;
9511
+ /**
9512
+ * The run-fact coverage floor (RV1809): the minimum judged run-fact
9513
+ * pairs over matched run-fact candidates ratio, in (0, 1]. Requires
9514
+ * `runFacts: true`; a draft with zero matched run claims never
9515
+ * trips it.
9516
+ */
9517
+ runFactCoverageRatio?: number;
9518
+ /**
9519
+ * What a below-floor ratio does (RV1809): 'report' (the default)
9520
+ * stamps the machine-readable `lowCoverage` block on the meta;
9521
+ * 'fail' fails the run typed BEFORE the judge dispatch, exactly
9522
+ * like `onUncoveredCritical`, so a run that cannot meet its
9523
+ * declared verification floor never pays for a partial verdict.
9524
+ * Requires at least one declared floor.
9525
+ */
9526
+ onLowCoverage?: "report" | "fail";
9470
9527
  }
9471
9528
  /** One judged contradiction: the pair plus the judge's one-sentence reason. */
9472
9529
  interface ClaimContradictionFinding extends ClaimPair {
@@ -9510,6 +9567,26 @@ interface OrchestrateClaimConsistencyMeta {
9510
9567
  runFactPairs?: number;
9511
9568
  /** Present under `runFacts` when more run claims matched than the bound. */
9512
9569
  runFactPairsTruncated?: true;
9570
+ /**
9571
+ * Present under `runFacts` (RV1809): the UNCAPPED count of matched
9572
+ * run-claim sentences, so the run-fact coverage ratio is computable
9573
+ * from the meta alone, live or from a persisted outcome.
9574
+ */
9575
+ runFactCandidates?: number;
9576
+ /**
9577
+ * Present when a declared coverage floor was not met under
9578
+ * `onLowCoverage: 'report'` (RV1809): each ratio beside its floor,
9579
+ * machine-readable, so "complete but under-verified by the declared
9580
+ * floor" is a field, not an external computation. Under 'fail' the
9581
+ * run fails typed instead and the meta stamps this block on the way
9582
+ * out.
9583
+ */
9584
+ lowCoverage?: {
9585
+ coverageRatio: number;
9586
+ coverageFloor?: number;
9587
+ runFactRatio?: number;
9588
+ runFactFloor?: number;
9589
+ };
9513
9590
  /** True when the judge invocation was dispatched. */
9514
9591
  judgeInvoked: boolean;
9515
9592
  /** Present when the judge invocation did not settle ok. */
@@ -10462,6 +10539,10 @@ interface RunInternals {
10462
10539
  gates?: Record<string, MechanicalGateProfile>; /** Engine-wide admission countTokens policy (RV1804); default 'allow'. */
10463
10540
  countTokens?: "allow" | "deny";
10464
10541
  };
10542
+ /** Telemetry compat posture (RV1810). */
10543
+ telemetry?: {
10544
+ /** Emit the legacy agent:error twin beside quota:denied. */quotaDeniedAgentError?: boolean;
10545
+ };
10465
10546
  /** Engine-scoped per-provider keyed limiter (M4-T07). */
10466
10547
  providerLimiter?: KeyedLimiter;
10467
10548
  /**
package/dist/index.js CHANGED
@@ -12407,7 +12407,25 @@ async function runAgent(options) {
12407
12407
  const retryAfter = (outcome.wireError?.data)?.retryAfterMs;
12408
12408
  if (outcome.wireError !== void 0) {
12409
12409
  if (outcome.quotaDenied !== true) transportRetries += 1;
12410
- events?.emit({
12410
+ if (outcome.quotaDenied === true) {
12411
+ const denialData = outcome.wireError.data;
12412
+ events?.emit({
12413
+ type: "quota:denied",
12414
+ agentType,
12415
+ label: options.label,
12416
+ model: target.resolved.ref,
12417
+ ...typeof denialData?.reason === "string" ? { reason: denialData.reason } : {},
12418
+ ...typeof denialData?.retryAfterMs === "number" ? { retryAfterMs: denialData.retryAfterMs } : {},
12419
+ willRetry: true
12420
+ });
12421
+ if (options.quotaDeniedAgentError === true) events?.emit({
12422
+ type: "agent:error",
12423
+ agentType,
12424
+ label: options.label,
12425
+ error: outcome.wireError,
12426
+ willRetry: true
12427
+ });
12428
+ } else events?.emit({
12411
12429
  type: "agent:error",
12412
12430
  agentType,
12413
12431
  label: options.label,
@@ -17579,6 +17597,7 @@ function createCtx(internals, rootWorkflow) {
17579
17597
  resolved: loopResolved,
17580
17598
  limits,
17581
17599
  events: agentSink,
17600
+ ...internals.telemetry?.quotaDeniedAgentError === true ? { quotaDeniedAgentError: true } : {},
17582
17601
  transcript: {
17583
17602
  mintRef: internals.mintTranscriptRef,
17584
17603
  put: (ref, blob) => internals.transcripts.put(ref, blob, internals.lease)
@@ -20179,7 +20198,8 @@ function pairRunFactClaims(draftText, sheet, options) {
20179
20198
  }
20180
20199
  return {
20181
20200
  pairs: matched,
20182
- truncated: total > matched.length
20201
+ truncated: total > matched.length,
20202
+ candidates: total
20183
20203
  };
20184
20204
  }
20185
20205
  /** Derives the {@link ClaimCoverageGrade} of a claim-consistency meta. */
@@ -20819,6 +20839,10 @@ function validateOrchestrateOptions(opts) {
20819
20839
  if (consistency.runFacts !== true) throw new ConfigError("orchestrate claimConsistency.runFactTerms rides the runFacts pass; set claimConsistency.runFacts true");
20820
20840
  if (!Array.isArray(consistency.runFactTerms) || consistency.runFactTerms.some((term) => typeof term !== "string" || term.length === 0)) throw new ConfigError("orchestrate claimConsistency.runFactTerms must be an array of nonempty strings; got " + JSON.stringify(consistency.runFactTerms));
20821
20841
  }
20842
+ for (const [label, ratio] of [["minimumCoverageRatio", consistency.minimumCoverageRatio], ["runFactCoverageRatio", consistency.runFactCoverageRatio]]) if (ratio !== void 0 && (typeof ratio !== "number" || !Number.isFinite(ratio) || ratio <= 0 || ratio > 1)) throw new ConfigError(`orchestrate claimConsistency.${label} must be a number in (0, 1]; got ` + JSON.stringify(ratio));
20843
+ if (consistency.runFactCoverageRatio !== void 0 && consistency.runFacts !== true) throw new ConfigError("orchestrate claimConsistency.runFactCoverageRatio rides the runFacts pass; set claimConsistency.runFacts true");
20844
+ if (consistency.onLowCoverage !== void 0 && consistency.onLowCoverage !== "report" && consistency.onLowCoverage !== "fail") throw new ConfigError("orchestrate claimConsistency.onLowCoverage must be 'report' or 'fail'; got " + JSON.stringify(consistency.onLowCoverage));
20845
+ if (consistency.onLowCoverage !== void 0 && consistency.minimumCoverageRatio === void 0 && consistency.runFactCoverageRatio === void 0) throw new ConfigError("orchestrate claimConsistency.onLowCoverage needs a declared floor; set minimumCoverageRatio or runFactCoverageRatio");
20822
20846
  if (consistency.judge !== void 0) {
20823
20847
  const judge = consistency.judge;
20824
20848
  if (typeof judge !== "object" || judge === null || Array.isArray(judge)) throw new ConfigError(`orchestrate claimConsistency.judge must be an object; got ${JSON.stringify(consistency.judge)}`);
@@ -22710,8 +22734,22 @@ function makeOrchestratorWorkflow(goal, opts) {
22710
22734
  },
22711
22735
  ...runFold === void 0 ? {} : {
22712
22736
  runFactPairs: runFold.pairs.length,
22713
- ...runFold.truncated ? { runFactPairsTruncated: true } : {}
22714
- }
22737
+ ...runFold.truncated ? { runFactPairsTruncated: true } : {},
22738
+ runFactCandidates: runFold.candidates
22739
+ },
22740
+ ...(() => {
22741
+ const coverageRatio = fold.draftCitingSentences === 0 ? 1 : fold.coveredCitingSentences / fold.draftCitingSentences;
22742
+ const runFactRatio = runFold === void 0 || runFold.candidates === 0 ? void 0 : runFold.pairs.length / runFold.candidates;
22743
+ const belowCoverage = spec.minimumCoverageRatio !== void 0 && fold.draftCitingSentences > 0 && coverageRatio < spec.minimumCoverageRatio;
22744
+ const belowRunFacts = spec.runFactCoverageRatio !== void 0 && runFactRatio !== void 0 && runFactRatio < spec.runFactCoverageRatio;
22745
+ if (!belowCoverage && !belowRunFacts) return {};
22746
+ return { lowCoverage: {
22747
+ coverageRatio,
22748
+ ...spec.minimumCoverageRatio === void 0 ? {} : { coverageFloor: spec.minimumCoverageRatio },
22749
+ ...runFactRatio === void 0 ? {} : { runFactRatio },
22750
+ ...spec.runFactCoverageRatio === void 0 ? {} : { runFactFloor: spec.runFactCoverageRatio }
22751
+ } };
22752
+ })()
22715
22753
  };
22716
22754
  const finishMeta = (flags) => {
22717
22755
  const bare = {
@@ -22723,6 +22761,16 @@ function makeOrchestratorWorkflow(goal, opts) {
22723
22761
  coverage: claimCoverageOf(bare)
22724
22762
  };
22725
22763
  };
22764
+ if (spec.onLowCoverage === "fail" && metaBase.lowCoverage !== void 0) {
22765
+ claimConsistencyMeta = finishMeta({ judgeInvoked: false });
22766
+ const low = metaBase.lowCoverage;
22767
+ throw new FailRunError(`the claim-consistency pass is below a declared coverage floor (coverage ${low.coverageRatio.toFixed(3)}` + (low.coverageFloor === void 0 ? "" : ` under floor ${String(low.coverageFloor)}`) + (low.runFactRatio === void 0 ? "" : `; run facts ${low.runFactRatio.toFixed(3)}` + (low.runFactFloor === void 0 ? "" : ` under floor ${String(low.runFactFloor)}`)) + "), and the armed onLowCoverage posture cannot pass the draft", { data: {
22768
+ source: "orchestrator_claim_consistency",
22769
+ lowCoverage: low,
22770
+ claimConsistencyMeta,
22771
+ ...snapshot ?? {}
22772
+ } });
22773
+ }
22726
22774
  if (spec.onUncoveredCritical === "fail" && fold.criticalUncovered !== void 0 && fold.criticalUncovered.length > 0) {
22727
22775
  claimConsistencyMeta = finishMeta({ judgeInvoked: false });
22728
22776
  throw new FailRunError(`the claim-consistency pass left ${String(fold.criticalUncoveredTotal ?? 0)} critical draft anchor(s) unjudged (${fold.criticalUncovered.join(", ")}), and the armed onUncoveredCritical posture cannot pass the draft`, { data: {
@@ -25155,6 +25203,7 @@ function createEngine(options) {
25155
25203
  if (profile.countTokens !== void 0 && !["allow", "deny"].includes(profile.countTokens)) throw new ConfigError(`createEngine defaults.profiles['${name}'].countTokens must be 'allow' or 'deny'`);
25156
25204
  }
25157
25205
  if (options.defaults?.countTokens !== void 0 && !["allow", "deny"].includes(options.defaults.countTokens)) throw new ConfigError("createEngine defaults.countTokens must be 'allow' or 'deny'");
25206
+ if (options.telemetry?.quotaDeniedAgentError !== void 0 && typeof options.telemetry.quotaDeniedAgentError !== "boolean") throw new ConfigError("createEngine telemetry.quotaDeniedAgentError must be a boolean");
25158
25207
  validateDeterminismConfig(options.determinism);
25159
25208
  validateEngineQuotaConfig(options.quota);
25160
25209
  if (options.security?.argsHashSalt !== void 0 && (typeof options.security.argsHashSalt !== "string" || options.security.argsHashSalt === "")) throw new ConfigError("createEngine security.argsHashSalt must be a nonempty string when given");
@@ -25331,6 +25380,7 @@ function createEngine(options) {
25331
25380
  ...defaults.gates === void 0 ? {} : { gates: defaults.gates },
25332
25381
  ...defaults.countTokens === void 0 ? {} : { countTokens: defaults.countTokens }
25333
25382
  },
25383
+ ...options.telemetry === void 0 ? {} : { telemetry: options.telemetry },
25334
25384
  errorPolicy: wf.errorPolicy,
25335
25385
  dropped: [],
25336
25386
  cost: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulvar/core",
3
- "version": "1.190.0",
3
+ "version": "1.192.0",
4
4
  "description": "Rulvar core: L0 contracts, journal kernel, ctx primitives, agent runtime, model router, tool system, dynamic orchestrator, InMemory and JSONL stores, event stream.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",