@tangle-network/agent-runtime 0.247.0 → 0.249.1

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.
Files changed (52) hide show
  1. package/dist/{activation-DizpINK3.d.ts → activation-CZz7kkgd.d.ts} +2 -2
  2. package/dist/{activation-DYqnl8zq.js → activation-ygjQvYwG.js} +32 -2
  3. package/dist/activation-ygjQvYwG.js.map +1 -0
  4. package/dist/agent.d.ts +2 -2
  5. package/dist/agent.js +1 -1
  6. package/dist/{coordination-driver-BV4AAUns.js → coordination-driver-B61Hh6B1.js} +142 -10
  7. package/dist/coordination-driver-B61Hh6B1.js.map +1 -0
  8. package/dist/{delegate-DQAzB5Xv.js → delegate-A6EYmMxy.js} +2 -2
  9. package/dist/{delegate-DQAzB5Xv.js.map → delegate-A6EYmMxy.js.map} +1 -1
  10. package/dist/durable.d.ts +2 -2
  11. package/dist/durable.js +1 -1
  12. package/dist/{graph-DcBmMLIp.js → graph-CXwmMtTx.js} +2 -2
  13. package/dist/{graph-DcBmMLIp.js.map → graph-CXwmMtTx.js.map} +1 -1
  14. package/dist/{index-DLzlXwr6.d.ts → index-BV5EmjCL.d.ts} +8 -5
  15. package/dist/index.d.ts +8 -6
  16. package/dist/index.js +27 -44
  17. package/dist/index.js.map +1 -1
  18. package/dist/intelligence.d.ts +18 -11
  19. package/dist/intelligence.js +88 -33
  20. package/dist/intelligence.js.map +1 -1
  21. package/dist/kernel.d.ts +3 -3
  22. package/dist/kernel.js +6 -6
  23. package/dist/{loop-runner-bin-iqq1azfy.js → loop-runner-bin-C1O16oIq.js} +2 -2
  24. package/dist/{loop-runner-bin-iqq1azfy.js.map → loop-runner-bin-C1O16oIq.js.map} +1 -1
  25. package/dist/{loop-runner-bin-HbMECmxT.d.ts → loop-runner-bin-q0akFXYX.d.ts} +3 -3
  26. package/dist/loop-runner-bin.d.ts +1 -1
  27. package/dist/loop-runner-bin.js +1 -1
  28. package/dist/mcp/bin.js +2 -2
  29. package/dist/mcp/index.d.ts +5 -5
  30. package/dist/mcp/index.js +3 -3
  31. package/dist/{openai-tools-DvLk_Ddg.d.ts → openai-tools-zrajPyXe.d.ts} +2 -2
  32. package/dist/profiles.d.ts +2 -2
  33. package/dist/{provision-supervisor-BgQx2Avp.js → provision-supervisor-D7gC-Veu.js} +2 -2
  34. package/dist/{provision-supervisor-BgQx2Avp.js.map → provision-supervisor-D7gC-Veu.js.map} +1 -1
  35. package/dist/run-layout-hKAJGF4g.js.map +1 -1
  36. package/dist/{runtime-HpTXhB3g.js → runtime-BVZIbtyL.js} +6 -6
  37. package/dist/{runtime-HpTXhB3g.js.map → runtime-BVZIbtyL.js.map} +1 -1
  38. package/dist/{server-OOE7mXrN.js → server-DHS1Gxt2.js} +2 -2
  39. package/dist/{server-OOE7mXrN.js.map → server-DHS1Gxt2.js.map} +1 -1
  40. package/dist/{stream-agent-turn-CcumM0Bu.d.ts → stream-agent-turn-D9IbZMys.d.ts} +2 -2
  41. package/dist/{substrate-CQ0hfewn.d.ts → substrate-Ctmos75o.d.ts} +2 -2
  42. package/dist/{supervise-DZEOpzRw.js → supervise-CnFk7_wb.js} +18 -4
  43. package/dist/supervise-CnFk7_wb.js.map +1 -0
  44. package/dist/testing.d.ts +2 -2
  45. package/dist/testing.js +11 -11
  46. package/dist/tui/index.d.ts +1 -1
  47. package/dist/tui/index.js +1 -1
  48. package/dist/{types-BUhz284C.d.ts → types-BmxS-W-f.d.ts} +22 -11
  49. package/package.json +4 -4
  50. package/dist/activation-DYqnl8zq.js.map +0 -1
  51. package/dist/coordination-driver-BV4AAUns.js.map +0 -1
  52. package/dist/supervise-DZEOpzRw.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { $t as RuntimeStreamEventCollector, Ai as AgentRuntimeEventSink, At as EvalRunEvent, Bi as RunAgentTaskOptions, Bt as RuntimeEventOtelOptions, Ci as startRuntimeRun, Di as AgentExecutionBackend, Ei as AgentBackendInput, Fi as BackendErrorDetail, Ft as LoopSpanNode, Gi as RuntimeStreamEvent, Gt as createOtelExporter, Hi as RuntimeCanonicalStreamEvent, Ht as buildLoopSpanNodes, Ii as KnowledgeReadinessDecision, It as OtelAttribute, Jt as loopEventToOtelSpan, Kt as exportEvalRuns, Li as OpenAIChatResponseFormat, Lt as OtelExportConfig, Mi as AgentTaskRunResult, Mt as EvalRunsExportConfig, Ni as AgentTaskSpec, Nt as EvalRunsExportResult, Oi as AgentKnowledgeProvider, Pi as AgentTaskStatus, Pt as INTELLIGENCE_WIRE_VERSION, Qt as RuntimeEventCollector, Ri as OpenAIChatTool, Rt as OtelExporter, Si as RuntimeRunStatus, Ti as AgentBackendContext, Ui as RuntimeSession, Ut as buildRuntimeEventOtelSpans, Vi as RunAgentTaskStreamOptions, Vt as buildLoopOtelSpans, Wi as RuntimeSessionStore, Wt as createOpenInferenceFileExporter, Xt as padTraceId, Yt as padSpanId, Zt as toOtelAttributes, _i as RuntimeRunCost, an as createRuntimeEventCollector, at as SupervisedResult, bi as RuntimeRunPersistenceAdapter, cn as sanitizeKnowledgeReadinessReport, en as RuntimeStreamEventSink, g as ExecutorFactory, gi as RuntimeRunCompleteInput, i as Budget, in as SanitizedKnowledgeRequirement, ji as AgentTaskContext, jt as EvalRunGeneration, ki as AgentRuntimeEvent, ln as sanitizeRuntimeStreamEvent, nn as RuntimeTelemetryOptions, on as createRuntimeStreamEventCollector, qt as generateSpanId, rn as SanitizedKnowledgeReadinessReport, sn as sanitizeAgentRuntimeEvent, tn as RuntimeStreamEventSummary, vi as RuntimeRunHandle, wi as AgentAdapter, xi as RuntimeRunRow, yi as RuntimeRunOptions, zi as OpenAIChatToolChoice, zt as OtelSpan } from "./types-BUhz284C.js";
1
+ import { $t as RuntimeStreamEventCollector, Ai as AgentRuntimeEventSink, At as EvalRunEvent, Bi as RunAgentTaskOptions, Bt as RuntimeEventOtelOptions, Ci as startRuntimeRun, Di as AgentExecutionBackend, Ei as AgentBackendInput, Fi as BackendErrorDetail, Ft as LoopSpanNode, Gi as RuntimeStreamEvent, Gt as createOtelExporter, Hi as RuntimeCanonicalStreamEvent, Ht as buildLoopSpanNodes, Ii as KnowledgeReadinessDecision, It as OtelAttribute, Jt as loopEventToOtelSpan, Kt as exportEvalRuns, Li as OpenAIChatResponseFormat, Lt as OtelExportConfig, Mi as AgentTaskRunResult, Mt as EvalRunsExportConfig, Ni as AgentTaskSpec, Nt as EvalRunsExportResult, Oi as AgentKnowledgeProvider, Pi as AgentTaskStatus, Pt as INTELLIGENCE_WIRE_VERSION, Qt as RuntimeEventCollector, Ri as OpenAIChatTool, Rt as OtelExporter, Si as RuntimeRunStatus, Ti as AgentBackendContext, Ui as RuntimeSession, Ut as buildRuntimeEventOtelSpans, Vi as RunAgentTaskStreamOptions, Vt as buildLoopOtelSpans, Wi as RuntimeSessionStore, Wt as createOpenInferenceFileExporter, Xt as padTraceId, Yt as padSpanId, Zt as toOtelAttributes, _i as RuntimeRunCost, an as createRuntimeEventCollector, at as SupervisedResult, bi as RuntimeRunPersistenceAdapter, cn as sanitizeKnowledgeReadinessReport, en as RuntimeStreamEventSink, g as ExecutorFactory, gi as RuntimeRunCompleteInput, i as Budget, in as SanitizedKnowledgeRequirement, ji as AgentTaskContext, jt as EvalRunGeneration, ki as AgentRuntimeEvent, ln as sanitizeRuntimeStreamEvent, nn as RuntimeTelemetryOptions, on as createRuntimeStreamEventCollector, qt as generateSpanId, rn as SanitizedKnowledgeReadinessReport, sn as sanitizeAgentRuntimeEvent, tn as RuntimeStreamEventSummary, vi as RuntimeRunHandle, wi as AgentAdapter, xi as RuntimeRunRow, yi as RuntimeRunOptions, zi as OpenAIChatToolChoice, zt as OtelSpan } from "./types-BmxS-W-f.js";
2
2
  import { i as SurfaceImprovementEdit } from "./improvement-adapter-D5gwwoXQ.js";
3
3
  import { o as ImprovementProposalSource } from "./types-zWfqDjeL.js";
4
- import { Bp as BackendTransportError, Gp as RetainedInteractiveAdmissionError, Hp as JudgeError, Jp as RetainedRunDispatchBindingError, Kp as RetainedInteractiveBindingError, Rp as AgentEvalError, Up as NotFoundError, Vp as ConfigError, Wp as PlannerError, Xa as SuperviseOptions, Xp as ValidationError, Yp as RuntimeRunStateError, nr as StructuralRolloutPolicy, qp as RetainedRunAdmissionError, sm as DeliverableSpec, wo as SupervisorProfile, zp as AgentEvalErrorCode } from "./index-DLzlXwr6.js";
4
+ import { Bp as BackendTransportError, Gp as RetainedInteractiveAdmissionError, Hp as JudgeError, Jp as RetainedRunDispatchBindingError, Kp as RetainedInteractiveBindingError, Rp as AgentEvalError, Up as NotFoundError, Vp as ConfigError, Wp as PlannerError, Xa as SuperviseOptions, Xp as ValidationError, Yp as RuntimeRunStateError, nr as StructuralRolloutPolicy, qp as RetainedRunAdmissionError, sm as DeliverableSpec, wo as SupervisorProfile, zp as AgentEvalErrorCode } from "./index-BV5EmjCL.js";
5
5
  import { a as RuntimeHookErrorContext, c as RuntimeHookTarget, d as defineRuntimeHooks, f as notifyRuntimeDecisionPoint, i as RuntimeHookContext, l as RuntimeHooks, n as RuntimeDecisionKind, o as RuntimeHookEvent, p as notifyRuntimeHookEvent, r as RuntimeDecisionPoint, s as RuntimeHookPhase, t as RuntimeDecisionEvidenceRef, u as composeRuntimeHooks } from "./runtime-hooks-Bj6wJHlH.js";
6
- import { $t as WorktreeCheckRunner, er as Redactor, f as ExecutorConfig } from "./stream-agent-turn-CcumM0Bu.js";
6
+ import { $t as WorktreeCheckRunner, er as Redactor, f as ExecutorConfig } from "./stream-agent-turn-D9IbZMys.js";
7
7
  import { y as AgentCandidateOutputArtifactPort } from "./types-CuXu5zuS.js";
8
- import { $ as ImprovementMaterializedProfilePopulationCandidate, A as ImproveCodeResult, B as ImproveMethodSource, C as TrainingBoundaryResult, Ct as CandidateGenerator, D as ImproveCandidateValidator, E as ImproveCandidateValidationInput, F as ImproveMethodContext, G as ImproveProfileSurface, H as ImproveOptions, I as ImproveMethodFactory, J as ImproveScenarioPartitions, K as ImproveResult, L as ImproveMethodLineage, M as ImproveCost, N as ImproveCustomCodeGeneratorOptions, O as ImproveCodeBaseOptions, P as ImproveLineage, Q as ImprovementCodeCandidate, R as ImproveMethodOptions, S as ProfileTrainerRequest, St as defaultBuildPrompt, T as createCommandProfileTrainer, U as ImproveProfileAgent, V as ImproveOptimizationRunOptions, W as ImproveProfileComponents, X as ImproveSurface, Y as ImproveSkillsOptions, Z as ImprovementCandidate, _ as CheckpointServingPort, _t as AgenticGeneratorShotReceipt, at as ImprovementProfilePopulationCandidate, b as ImproveTrainingResult, bt as agenticGenerator, ct as ImprovementProfilePopulationLineageNode, dt as DeepReadonly, et as ImprovementProfileCandidate, ft as ReadonlyAgentProfile, g as improve, gt as AgenticGeneratorShotExecution, ht as AgenticGeneratorShotDisposition, i as AgentImprovementActivationTransition, it as ImprovementProfilePopulationArtifactSource, j as ImproveCodeRunOptions, k as ImproveCodeOptions, lt as ImprovementProfilePopulationObservationSource, mt as AgenticGeneratorOptions, n as AgentImprovementActivationResultStore, nt as ImprovementProfileCandidatePopulationAvailable, ot as ImprovementProfilePopulationCandidateSource, pt as AgenticGeneratorExecutorForWorktree, q as ImproveRuntimeCodeGeneratorOptions, rt as ImprovementProfileCandidatePopulationUnavailable, st as ImprovementProfilePopulationLineage, t as AgentImprovementActivationReconciliation, tt as ImprovementProfileCandidatePopulation, ut as ImprovementRefusedProfilePopulationCandidate, v as ControlledTrainingCommand, vt as Verifier, w as TrainingDatasetDocument, x as ProfileTrainer, xt as commandVerifier, y as ImproveTrainingOptions, yt as VerifyResult, z as ImproveMethodResult } from "./activation-DizpINK3.js";
9
- import { _ as researchLoopRunner, a as DELEGATED_LOOP_MODES, c as DelegatedLoopResult, d as ResearchLoopRunnerOptions, f as RunDelegatedLoopOptions, g as isDelegatedLoopMode, h as auditLoopRunner, i as runLoopRunnerCli, l as DelegatedLoopRunner, m as WorktreeLoopRunnerOptions, n as LoopRunnerCliResult, o as DelegatedLoopMode, p as VetoedFact, r as parseLoopRunnerArgv, s as DelegatedLoopRegistry, t as LoopRunnerCliArgs, u as ResearchLoopResult, v as runDelegatedLoop, y as worktreeLoopRunner } from "./loop-runner-bin-HbMECmxT.js";
10
- import { n as mcpToolsForRuntimeMcpSubset, t as mcpToolsForRuntimeMcp } from "./openai-tools-DvLk_Ddg.js";
8
+ import { $ as ImprovementMaterializedProfilePopulationCandidate, A as ImproveCodeResult, B as ImproveMethodSource, C as TrainingBoundaryResult, Ct as CandidateGenerator, D as ImproveCandidateValidator, E as ImproveCandidateValidationInput, F as ImproveMethodContext, G as ImproveProfileSurface, H as ImproveOptions, I as ImproveMethodFactory, J as ImproveScenarioPartitions, K as ImproveResult, L as ImproveMethodLineage, M as ImproveCost, N as ImproveCustomCodeGeneratorOptions, O as ImproveCodeBaseOptions, P as ImproveLineage, Q as ImprovementCodeCandidate, R as ImproveMethodOptions, S as ProfileTrainerRequest, St as defaultBuildPrompt, T as createCommandProfileTrainer, U as ImproveProfileAgent, V as ImproveOptimizationRunOptions, W as ImproveProfileComponents, X as ImproveSurface, Y as ImproveSkillsOptions, Z as ImprovementCandidate, _ as CheckpointServingPort, _t as AgenticGeneratorShotReceipt, at as ImprovementProfilePopulationCandidate, b as ImproveTrainingResult, bt as agenticGenerator, ct as ImprovementProfilePopulationLineageNode, dt as DeepReadonly, et as ImprovementProfileCandidate, ft as ReadonlyAgentProfile, g as improve, gt as AgenticGeneratorShotExecution, ht as AgenticGeneratorShotDisposition, i as AgentImprovementActivationTransition, it as ImprovementProfilePopulationArtifactSource, j as ImproveCodeRunOptions, k as ImproveCodeOptions, lt as ImprovementProfilePopulationObservationSource, mt as AgenticGeneratorOptions, n as AgentImprovementActivationResultStore, nt as ImprovementProfileCandidatePopulationAvailable, ot as ImprovementProfilePopulationCandidateSource, pt as AgenticGeneratorExecutorForWorktree, q as ImproveRuntimeCodeGeneratorOptions, rt as ImprovementProfileCandidatePopulationUnavailable, st as ImprovementProfilePopulationLineage, t as AgentImprovementActivationReconciliation, tt as ImprovementProfileCandidatePopulation, ut as ImprovementRefusedProfilePopulationCandidate, v as ControlledTrainingCommand, vt as Verifier, w as TrainingDatasetDocument, x as ProfileTrainer, xt as commandVerifier, y as ImproveTrainingOptions, yt as VerifyResult, z as ImproveMethodResult } from "./activation-CZz7kkgd.js";
9
+ import { _ as researchLoopRunner, a as DELEGATED_LOOP_MODES, c as DelegatedLoopResult, d as ResearchLoopRunnerOptions, f as RunDelegatedLoopOptions, g as isDelegatedLoopMode, h as auditLoopRunner, i as runLoopRunnerCli, l as DelegatedLoopRunner, m as WorktreeLoopRunnerOptions, n as LoopRunnerCliResult, o as DelegatedLoopMode, p as VetoedFact, r as parseLoopRunnerArgv, s as DelegatedLoopRegistry, t as LoopRunnerCliArgs, u as ResearchLoopResult, v as runDelegatedLoop, y as worktreeLoopRunner } from "./loop-runner-bin-q0akFXYX.js";
10
+ import { n as mcpToolsForRuntimeMcpSubset, t as mcpToolsForRuntimeMcp } from "./openai-tools-zrajPyXe.js";
11
11
  import { AgentCandidateBundle, AgentCandidateCapturedArtifact, AgentCandidateKnowledge, AgentProfile, Sha256Digest } from "@tangle-network/agent-interface";
12
12
  import { AgentProfile as AgentProfile$1, ControlBudget, ControlDecision, ControlEvalResult, ControlEvalResult as ControlEvalResult$1, ControlRunResult, ControlStep, DataAcquisitionPlan, KnowledgeReadinessReport, KnowledgeReadinessReport as KnowledgeReadinessReport$1, KnowledgeRequirement, MaximumCharge, ProposalFinding, RunRecord, RunRecord as RunRecord$1 } from "@tangle-network/agent-eval";
13
13
  import { GepaOptimizationMethodConfig, ProfileDispatchFn, Scenario, SkillOptOptimizationMethodConfig } from "@tangle-network/agent-eval/campaign";
@@ -555,6 +555,8 @@ interface PersonaConversationResult {
555
555
  tokensKnown?: false;
556
556
  /** Absent means every worker call reported provider-billed cost, including a known zero. */
557
557
  costUsdKnown?: false;
558
+ /** Worker-only external estimate, kept separate from observed provider-billed spend. */
559
+ estimatedCostUsd?: number;
558
560
  }
559
561
  /**
560
562
  * Run one worker profile against one persona as a multi-round conversation.
package/dist/index.js CHANGED
@@ -2,15 +2,15 @@ import { $r as writeAllBytes, Jn as defaultRedactorIdentityMaterial, Qr as readC
2
2
  import { a as JudgeError, c as RetainedInteractiveAdmissionError, d as RetainedRunDispatchBindingError, f as RuntimeRunStateError, i as ConfigError, l as RetainedInteractiveBindingError, m as ValidationError, o as NotFoundError, r as BackendTransportError, s as PlannerError, t as AgentEvalError, u as RetainedRunAdmissionError } from "./errors-DodWX-cb.js";
3
3
  import { F as InMemoryRuntimeSessionStore, I as newRuntimeSession, L as nowIso, M as createIterableBackend, N as createSandboxPromptBackend, O as optimizerMethod, P as normalizeBackendStreamEvent, R as startOrResumeRuntimeSession, j as streamAgentTurn, k as strategyAuthorMethod, z as touchSession } from "./structural-rollout-z1A0okaB.js";
4
4
  import { t as assertExecutableAgentProfile } from "./model-policy-BbSCSak0.js";
5
- import { Lt as McpSpawnFault, Rt as connectStdioMcp } from "./runtime-HpTXhB3g.js";
5
+ import { a as createRuntimeUsageTotals, i as addRuntimeUsage, o as isUsageAmount, t as createAgentImprovementActivationResult } from "./activation-ygjQvYwG.js";
6
+ import { Lt as McpSpawnFault, Rt as connectStdioMcp } from "./runtime-BVZIbtyL.js";
6
7
  import { i as notifyRuntimeHookEvent, n as defineRuntimeHooks, r as notifyRuntimeDecisionPoint, t as composeRuntimeHooks } from "./runtime-hooks-tXpAarhW.js";
7
8
  import { B as assertCandidateValidator, G as applyRolloutPolicyToProfile, H as parseExecutionRef, J as serializeRolloutPolicy, K as normalizeRolloutPolicy, L as improve, Q as defaultBuildPrompt, R as createCommandProfileTrainer, U as rawTraceDistiller, W as ROLLOUT_POLICY_EXTENSION, X as agenticGenerator, Y as structuralRolloutPolicyFromProfile, Z as commandVerifier, q as parseRolloutPolicy, z as withMethodRuntimeControls } from "./improvement-cycle-B049YmQ8.js";
8
9
  import { a as canonicalCandidateBytes$1, d as omitTopLevelDigest, l as embeddedCandidateArtifact, o as canonicalCandidateDigest$1, u as immutableCandidateValue } from "./protected-redaction-Fn1ETfJ-.js";
9
10
  import { d as persistCandidateOutputArtifact } from "./prepare-CibQrhfi.js";
10
- import { t as createAgentImprovementActivationResult } from "./activation-DYqnl8zq.js";
11
11
  import { i as sealAgentCandidateBundle, t as captureAgentCandidateWorkspace } from "./workspace-archive-DSRT4Tro.js";
12
- import { n as supervise } from "./supervise-DZEOpzRw.js";
13
- import { a as isDelegatedLoopMode, c as worktreeLoopRunner, i as auditLoopRunner, n as runLoopRunnerCli, o as researchLoopRunner, r as DELEGATED_LOOP_MODES, s as runDelegatedLoop, t as parseLoopRunnerArgv } from "./loop-runner-bin-iqq1azfy.js";
12
+ import { n as supervise } from "./supervise-CnFk7_wb.js";
13
+ import { a as isDelegatedLoopMode, c as worktreeLoopRunner, i as auditLoopRunner, n as runLoopRunnerCli, o as researchLoopRunner, r as DELEGATED_LOOP_MODES, s as runDelegatedLoop, t as parseLoopRunnerArgv } from "./loop-runner-bin-C1O16oIq.js";
14
14
  import { n as mcpToolsForRuntimeMcpSubset, t as mcpToolsForRuntimeMcp } from "./openai-tools-DoQ32vpe.js";
15
15
  import { agentCandidateKnowledgeSchema, agentProfileSchema, canonicalAgentProfileDigest, sha256DigestSchema } from "@tangle-network/agent-interface";
16
16
  import { FAILURE_CLASSES, acquisitionPlansForKnowledgeGaps, blockingKnowledgeEval, canonicalJson, runAgentControlLoop, scoreKnowledgeReadiness, userQuestionsForKnowledgeGaps } from "@tangle-network/agent-eval";
@@ -1231,14 +1231,7 @@ function profileRuntimeBackend(profile, factory, counter) {
1231
1231
  ...backend,
1232
1232
  async *stream(input, context) {
1233
1233
  for await (const event of backend.stream(input, context)) {
1234
- if (event.type === "llm_call") {
1235
- counter.sawLlmCall = true;
1236
- counter.tokensIn += event.tokensIn ?? 0;
1237
- counter.tokensOut += event.tokensOut ?? 0;
1238
- counter.costUsd += event.costUsd ?? 0;
1239
- if (event.tokensKnown === false || event.tokensIn === void 0 || event.tokensOut === void 0) counter.tokensKnown = false;
1240
- if (event.usdKnown === false || event.costUsd === void 0) counter.usdKnown = false;
1241
- }
1234
+ if (event.type === "llm_call") addRuntimeUsage(counter, event);
1242
1235
  yield event;
1243
1236
  }
1244
1237
  }
@@ -1269,14 +1262,7 @@ function scriptedPersonaBackend(turns) {
1269
1262
  * until `maxTurns`. Returns the persistent transcript + worker-only usage.
1270
1263
  */
1271
1264
  async function runPersonaConversation(opts) {
1272
- const counter = {
1273
- tokensIn: 0,
1274
- tokensOut: 0,
1275
- costUsd: 0,
1276
- sawLlmCall: false,
1277
- tokensKnown: true,
1278
- usdKnown: true
1279
- };
1265
+ const counter = createRuntimeUsageTotals();
1280
1266
  const workerName = opts.workerName ?? "agent";
1281
1267
  const worker = profileRuntimeBackend(opts.worker, opts.executorFor(opts.worker, "worker"), counter);
1282
1268
  let persona;
@@ -1307,10 +1293,10 @@ async function runPersonaConversation(opts) {
1307
1293
  seed: opts.seed ?? "Begin.",
1308
1294
  signal: opts.signal
1309
1295
  });
1310
- const fallbackCostKnown = !counter.sawLlmCall && opts.persona.kind === "scripted" && result.spentCreditsCents > 0;
1296
+ const fallbackCostKnown = counter.llmCalls === 0 && opts.persona.kind === "scripted" && result.spentCreditsCents > 0;
1311
1297
  const costUsd = fallbackCostKnown ? result.spentCreditsCents / 100 : counter.costUsd;
1312
- const tokensKnown = counter.sawLlmCall && counter.tokensKnown;
1313
- const costUsdKnown = counter.sawLlmCall ? counter.usdKnown : fallbackCostKnown;
1298
+ const tokensKnown = counter.llmCalls > 0 && counter.tokensKnown !== false;
1299
+ const costUsdKnown = counter.llmCalls > 0 ? counter.usdKnown !== false : fallbackCostKnown;
1314
1300
  return {
1315
1301
  transcript: result.transcript,
1316
1302
  turns: result.turns,
@@ -1319,7 +1305,8 @@ async function runPersonaConversation(opts) {
1319
1305
  tokensIn: counter.tokensIn,
1320
1306
  tokensOut: counter.tokensOut,
1321
1307
  ...tokensKnown ? {} : { tokensKnown: false },
1322
- ...costUsdKnown ? {} : { costUsdKnown: false }
1308
+ ...costUsdKnown ? {} : { costUsdKnown: false },
1309
+ ...counter.estimatedCostUsd !== void 0 ? { estimatedCostUsd: counter.estimatedCostUsd } : {}
1323
1310
  };
1324
1311
  }
1325
1312
  /**
@@ -2994,19 +2981,10 @@ function startRuntimeRun(options) {
2994
2981
  let resultSummary;
2995
2982
  let error;
2996
2983
  let completionMetadata;
2997
- const ledger = {
2998
- tokensIn: 0,
2999
- tokensOut: 0,
3000
- costUsd: 0,
3001
- wallMs: 0,
3002
- llmCalls: 0
3003
- };
2984
+ const ledger = createRuntimeUsageTotals();
3004
2985
  const snapshotCost = () => ({
3005
- tokensIn: ledger.tokensIn,
3006
- tokensOut: ledger.tokensOut,
3007
- costUsd: ledger.costUsd,
3008
- wallMs: (completedAtMs ?? now()) - startedAtMs,
3009
- llmCalls: ledger.llmCalls
2986
+ ...ledger,
2987
+ wallMs: (completedAtMs ?? now()) - startedAtMs
3010
2988
  });
3011
2989
  const buildRow = (extraMetadata) => ({
3012
2990
  id,
@@ -3034,10 +3012,7 @@ function startRuntimeRun(options) {
3034
3012
  },
3035
3013
  observe(event) {
3036
3014
  if (event.type !== "llm_call") return;
3037
- ledger.llmCalls += 1;
3038
- if (typeof event.tokensIn === "number" && Number.isFinite(event.tokensIn)) ledger.tokensIn += event.tokensIn;
3039
- if (typeof event.tokensOut === "number" && Number.isFinite(event.tokensOut)) ledger.tokensOut += event.tokensOut;
3040
- if (typeof event.costUsd === "number" && Number.isFinite(event.costUsd)) ledger.costUsd += event.costUsd;
3015
+ addRuntimeUsage(ledger, event);
3041
3016
  },
3042
3017
  cost: snapshotCost,
3043
3018
  complete(input) {
@@ -3052,10 +3027,18 @@ function startRuntimeRun(options) {
3052
3027
  error = input.error;
3053
3028
  completionMetadata = input.metadata;
3054
3029
  if (input.cost) {
3055
- if (typeof input.cost.tokensIn === "number" && Number.isFinite(input.cost.tokensIn)) ledger.tokensIn = input.cost.tokensIn;
3056
- if (typeof input.cost.tokensOut === "number" && Number.isFinite(input.cost.tokensOut)) ledger.tokensOut = input.cost.tokensOut;
3057
- if (typeof input.cost.costUsd === "number" && Number.isFinite(input.cost.costUsd)) ledger.costUsd = input.cost.costUsd;
3058
- if (typeof input.cost.llmCalls === "number" && Number.isFinite(input.cost.llmCalls)) ledger.llmCalls = input.cost.llmCalls;
3030
+ for (const key of [
3031
+ "tokensIn",
3032
+ "tokensOut",
3033
+ "costUsd",
3034
+ "llmCalls",
3035
+ "estimatedCostUsd"
3036
+ ]) {
3037
+ const value = input.cost[key];
3038
+ if (isUsageAmount(value)) ledger[key] = value;
3039
+ }
3040
+ if (input.cost.tokensKnown === false) ledger.tokensKnown = false;
3041
+ if (input.cost.usdKnown === false) ledger.usdKnown = false;
3059
3042
  }
3060
3043
  },
3061
3044
  toRow(metadata) {