@rulvar/core 1.38.0 → 1.40.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
@@ -4303,6 +4303,14 @@ type CoreEvents = {
4303
4303
  type: "run:end";
4304
4304
  status: "ok" | "error" | "cancelled" | "exhausted" | "suspended";
4305
4305
  totalUsd: number;
4306
+ /**
4307
+ * Present and true when any priced usage folded into totalUsd is
4308
+ * approximate (a transport cut, a stream the ceiling severed, or an
4309
+ * abort left a turn's usage estimated rather than reported by the
4310
+ * provider), so totalUsd is a lower bound estimate, never an exact
4311
+ * charge. Absent means every contributing turn reported exact usage.
4312
+ */
4313
+ usageApprox?: boolean;
4306
4314
  } | {
4307
4315
  type: "phase:start";
4308
4316
  phase: string;
@@ -4356,6 +4364,14 @@ type AgentEvents = {
4356
4364
  usage: Usage;
4357
4365
  costUsd: number;
4358
4366
  entryRef: number;
4367
+ /**
4368
+ * Present and true when this agent's usage is approximate rather
4369
+ * than reported by the provider (the turn was cut by a transport
4370
+ * failure, a ceiling that severed the stream, or an abort). Absent
4371
+ * means the provider reported the usage exactly. Mirrors the
4372
+ * terminal journal entry's usageApprox.
4373
+ */
4374
+ usageApprox?: boolean;
4359
4375
  } | {
4360
4376
  type: "agent:error";
4361
4377
  agentType: string;
@@ -4612,6 +4628,16 @@ interface CostReport {
4612
4628
  model: string;
4613
4629
  usage: Usage;
4614
4630
  }>;
4631
+ /**
4632
+ * Present and true when any terminal entry folded into totalUsd carried
4633
+ * approximate usage (a transport cut, a stream the ceiling severed, or
4634
+ * an abort estimated the turn instead of the provider reporting it), so
4635
+ * totalUsd is a lower bound estimate, never an exact charge. Absent
4636
+ * means every contributing entry reported exact usage. The field the
4637
+ * v1.39.0 review asked the report to raise so approximate cost is never
4638
+ * shown as though it were the provider invoice.
4639
+ */
4640
+ usageApprox?: boolean;
4615
4641
  }
4616
4642
  type RunOutcome<R> = {
4617
4643
  status: "ok" | "error" | "cancelled" | "exhausted" | "suspended";
package/dist/index.js CHANGED
@@ -6799,6 +6799,7 @@ function costReportFromJournal(entries, priceUsd) {
6799
6799
  const byRole = emptyByRole();
6800
6800
  const unpriced = [];
6801
6801
  let totalUsd = 0;
6802
+ let usageApprox = false;
6802
6803
  let orchestratorSpentUsd = 0;
6803
6804
  let reserveUsedUsd = 0;
6804
6805
  let wakes = 0;
@@ -6815,6 +6816,7 @@ function costReportFromJournal(entries, priceUsd) {
6815
6816
  });
6816
6817
  for (const slice of priced.priced) byModel[slice.servedBy] = (byModel[slice.servedBy] ?? 0) + slice.usd;
6817
6818
  totalUsd += priced.usd;
6819
+ if (entry.usageApprox === true) usageApprox = true;
6818
6820
  const facts = entry.costAttribution;
6819
6821
  const phase = facts?.phase ?? "";
6820
6822
  byPhase[phase] = (byPhase[phase] ?? 0) + priced.usd;
@@ -6840,7 +6842,8 @@ function costReportFromJournal(entries, priceUsd) {
6840
6842
  forcedFinish,
6841
6843
  reserveUsedUsd
6842
6844
  },
6843
- unpriced
6845
+ unpriced,
6846
+ ...usageApprox ? { usageApprox: true } : {}
6844
6847
  };
6845
6848
  }
6846
6849
  //#endregion
@@ -11411,7 +11414,8 @@ function createCtx(internals, rootWorkflow) {
11411
11414
  status: result.status,
11412
11415
  usage,
11413
11416
  costUsd,
11414
- entryRef: terminal?.seq ?? matched.running.seq
11417
+ entryRef: terminal?.seq ?? matched.running.seq,
11418
+ ...terminal?.usageApprox === true ? { usageApprox: true } : {}
11415
11419
  }, spanId, true);
11416
11420
  for (const slice of replayPriced?.priced ?? []) bump(internals.cost.byModel, slice.servedBy, slice.usd);
11417
11421
  for (const slice of replayPriced?.unpriced ?? []) internals.cost.unpriced.push({
@@ -11866,7 +11870,8 @@ function createCtx(internals, rootWorkflow) {
11866
11870
  if (result.status === "escalated" && result.escalation !== void 0) terminalPatch.escalation = result.escalation;
11867
11871
  if (result.output !== null && result.status === "ok") terminalPatch.value = result.output;
11868
11872
  if (result.error !== void 0) terminalPatch.error = agentErrorToWire(result.error, result.errorMessage ?? `agent terminated with status ${result.status}`);
11869
- if (result.usageApprox === true) terminalPatch.usageApprox = true;
11873
+ const resultUsageApprox = result.usageApprox === true;
11874
+ if (resultUsageApprox) terminalPatch.usageApprox = true;
11870
11875
  if (result.artifacts !== void 0) terminalPatch.artifacts = result.artifacts;
11871
11876
  if (result.abortClass !== void 0) {
11872
11877
  terminalPatch.memoizeOutcome = true;
@@ -11891,7 +11896,8 @@ function createCtx(internals, rootWorkflow) {
11891
11896
  status: result.status,
11892
11897
  usage: result.usage,
11893
11898
  costUsd: result.costUsd,
11894
- entryRef: terminal.seq
11899
+ entryRef: terminal.seq,
11900
+ ...resultUsageApprox ? { usageApprox: true } : {}
11895
11901
  }, spanId);
11896
11902
  if (result.status === "escalated" && result.escalation !== void 0) {
11897
11903
  let decision = flavorBDecision;
@@ -14110,7 +14116,8 @@ function createEngine(options) {
14110
14116
  bus.emit({
14111
14117
  type: "run:end",
14112
14118
  status,
14113
- totalUsd: ledger.usd
14119
+ totalUsd: ledger.usd,
14120
+ ...outcome.cost.usageApprox === true ? { usageApprox: true } : {}
14114
14121
  }, rootSpanId);
14115
14122
  bus.end();
14116
14123
  resumeCtx?.previewResolve({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulvar/core",
3
- "version": "1.38.0",
3
+ "version": "1.40.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",