@tangle-network/agent-runtime 0.246.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.
- package/dist/{activation-Df-ae5Uq.d.ts → activation-CZz7kkgd.d.ts} +2 -2
- package/dist/{activation-C6d-NTWk.js → activation-ygjQvYwG.js} +33 -3
- package/dist/activation-ygjQvYwG.js.map +1 -0
- package/dist/agent.d.ts +2 -2
- package/dist/agent.js +2 -2
- package/dist/{coordination-driver-De8pyM57.js → coordination-driver-B61Hh6B1.js} +161 -16
- package/dist/coordination-driver-B61Hh6B1.js.map +1 -0
- package/dist/{delegate-DE6hNhbD.js → delegate-A6EYmMxy.js} +2 -2
- package/dist/{delegate-DE6hNhbD.js.map → delegate-A6EYmMxy.js.map} +1 -1
- package/dist/durable.d.ts +2 -2
- package/dist/durable.js +2 -2
- package/dist/{graph-s57f-VCR.js → graph-CXwmMtTx.js} +3 -3
- package/dist/{graph-s57f-VCR.js.map → graph-CXwmMtTx.js.map} +1 -1
- package/dist/{improvement-cycle-BE3gIJwL.js → improvement-cycle-B049YmQ8.js} +3 -3
- package/dist/{improvement-cycle-BE3gIJwL.js.map → improvement-cycle-B049YmQ8.js.map} +1 -1
- package/dist/{index-CAG31NtK.d.ts → index-BV5EmjCL.d.ts} +15 -7
- package/dist/index.d.ts +8 -6
- package/dist/index.js +30 -47
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +22 -13
- package/dist/intelligence.js +96 -40
- package/dist/intelligence.js.map +1 -1
- package/dist/kernel.d.ts +3 -3
- package/dist/kernel.js +9 -9
- package/dist/{loop-runner-bin-Bp8Mih20.js → loop-runner-bin-C1O16oIq.js} +3 -3
- package/dist/{loop-runner-bin-Bp8Mih20.js.map → loop-runner-bin-C1O16oIq.js.map} +1 -1
- package/dist/{loop-runner-bin-B_oSVrE7.d.ts → loop-runner-bin-q0akFXYX.d.ts} +3 -3
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +5 -5
- package/dist/mcp/index.js +4 -4
- package/dist/{openai-tools-B1GMKDjW.d.ts → openai-tools-zrajPyXe.d.ts} +2 -2
- package/dist/profiles.d.ts +2 -2
- package/dist/{provision-supervisor-D0X9KUv-.js → provision-supervisor-D7gC-Veu.js} +4 -4
- package/dist/{provision-supervisor-D0X9KUv-.js.map → provision-supervisor-D7gC-Veu.js.map} +1 -1
- package/dist/{run-layout-B8-Gqhpg.js → run-layout-hKAJGF4g.js} +6 -1
- package/dist/run-layout-hKAJGF4g.js.map +1 -0
- package/dist/{runtime-CHbVv5UI.js → runtime-BVZIbtyL.js} +9 -9
- package/dist/{runtime-CHbVv5UI.js.map → runtime-BVZIbtyL.js.map} +1 -1
- package/dist/{server-DwsC_FyV.js → server-DHS1Gxt2.js} +3 -3
- package/dist/{server-DwsC_FyV.js.map → server-DHS1Gxt2.js.map} +1 -1
- package/dist/{stream-agent-turn-DQ-W8mHf.d.ts → stream-agent-turn-D9IbZMys.d.ts} +2 -2
- package/dist/{structural-rollout-DasmuuUp.js → structural-rollout-z1A0okaB.js} +2 -2
- package/dist/{structural-rollout-DasmuuUp.js.map → structural-rollout-z1A0okaB.js.map} +1 -1
- package/dist/{substrate-DJOnuoa_.d.ts → substrate-Ctmos75o.d.ts} +2 -2
- package/dist/{supervise-o6CzD2Rt.js → supervise-CnFk7_wb.js} +25 -5
- package/dist/supervise-CnFk7_wb.js.map +1 -0
- package/dist/{supervisor-tGq-TPIv.js → supervisor-BIBWUFUr.js} +165 -48
- package/dist/supervisor-BIBWUFUr.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +12 -12
- package/dist/{top-app-DL-sjv7K.js → top-app-d-bmwO7O.js} +2 -2
- package/dist/{top-app-DL-sjv7K.js.map → top-app-d-bmwO7O.js.map} +1 -1
- package/dist/tui/bin.js +1 -1
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +2 -2
- package/dist/{types-BoEzH8V6.d.ts → types-BmxS-W-f.d.ts} +44 -20
- package/package.json +4 -4
- package/dist/activation-C6d-NTWk.js.map +0 -1
- package/dist/coordination-driver-De8pyM57.js.map +0 -1
- package/dist/run-layout-B8-Gqhpg.js.map +0 -1
- package/dist/supervise-o6CzD2Rt.js.map +0 -1
- package/dist/supervisor-tGq-TPIv.js.map +0 -1
package/dist/intelligence.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Gi as RuntimeStreamEvent, nn as RuntimeTelemetryOptions, oi as LoopTraceEvent } from "./types-
|
|
1
|
+
import { Gi as RuntimeStreamEvent, nn as RuntimeTelemetryOptions, oi as LoopTraceEvent } from "./types-BmxS-W-f.js";
|
|
2
2
|
import { d as RunAnalystLoopOpts, f as RunAnalystLoopResult } from "./types-zWfqDjeL.js";
|
|
3
|
-
import { Tn as ToolSpec, er as Redactor, nr as resolveRedactor, tr as defaultRedactor, vt as AgentEnvironmentProviderRef, yt as AgentEnvironmentProviderRegistry } from "./stream-agent-turn-
|
|
3
|
+
import { Tn as ToolSpec, er as Redactor, nr as resolveRedactor, tr as defaultRedactor, vt as AgentEnvironmentProviderRef, yt as AgentEnvironmentProviderRegistry } from "./stream-agent-turn-D9IbZMys.js";
|
|
4
4
|
import { D as AgentCandidateRunFinalization, O as AgentCandidateTaskExecution, a as AgentCandidateExecutionPorts, c as AgentCandidateExecutorPort, r as AgentCandidateBenchmarkGraderPort, y as AgentCandidateOutputArtifactPort } from "./types-CuXu5zuS.js";
|
|
5
5
|
import { T as AgentCandidateExecutionClaimStore, _ as PrepareAgentCandidateExecutionOptions, o as CreateProtectedAgentCandidateModelPortOptions, p as parseAgentCandidateProfileActivation, y as ExecutePreparedAgentCandidateOptions } from "./protected-model-port-BlLP8ja6.js";
|
|
6
|
-
import { H as ImproveOptions, J as ImproveScenarioPartitions, K as ImproveResult, R as ImproveMethodOptions, a as AgentImprovementActivationTransitionInput, c as CreateAgentImprovementActivationResultOptions, d as ProfileImprovementActivationTransitionInput, f as SealedCandidateActivationTransitionInput, h as verifyAgentImprovementActivationResult, i as AgentImprovementActivationTransition, l as ExecuteAgentImprovementActivationInput, m as executeAgentImprovementActivation, n as AgentImprovementActivationResultStore, o as AgentProfileImprovementActivationOperation, p as createAgentImprovementActivationResult, r as AgentImprovementActivationTargetPlan, s as AgentProfileImprovementActivationTargetPlan, t as AgentImprovementActivationReconciliation, u as ExecuteAgentImprovementActivationOptions, z as ImproveMethodResult } from "./activation-
|
|
6
|
+
import { H as ImproveOptions, J as ImproveScenarioPartitions, K as ImproveResult, R as ImproveMethodOptions, a as AgentImprovementActivationTransitionInput, c as CreateAgentImprovementActivationResultOptions, d as ProfileImprovementActivationTransitionInput, f as SealedCandidateActivationTransitionInput, h as verifyAgentImprovementActivationResult, i as AgentImprovementActivationTransition, l as ExecuteAgentImprovementActivationInput, m as executeAgentImprovementActivation, n as AgentImprovementActivationResultStore, o as AgentProfileImprovementActivationOperation, p as createAgentImprovementActivationResult, r as AgentImprovementActivationTargetPlan, s as AgentProfileImprovementActivationTargetPlan, t as AgentImprovementActivationReconciliation, u as ExecuteAgentImprovementActivationOptions, z as ImproveMethodResult } from "./activation-CZz7kkgd.js";
|
|
7
7
|
import { AgentCandidateBenchmarkCellRef, AgentCandidateBundle, AgentCandidateEvaluationPolicy, AgentCandidateExperiment, AgentCandidateExperimentMaterial, AgentCandidateExperimentMeasurement, AgentCandidateLineage, AgentCandidateProfileActivation as CandidateProfileMaterialization, AgentImprovementActivation, AgentImprovementActivation as AgentImprovementActivation$1, AgentImprovementActivationIntent, AgentImprovementActivationIntent as AgentImprovementActivationIntent$1, AgentImprovementActivationOutcome, AgentImprovementActivationResult, AgentImprovementActivationTarget, AgentImprovementActivationTargetState, AgentImprovementActivationTargetTransition, AgentImprovementEvaluation, AgentImprovementEvaluation as AgentImprovementEvaluation$1, AgentImprovementMeasuredComparison, AgentImprovementMeasuredComparison as AgentImprovementMeasuredComparison$1, AgentImprovementProposal, AgentImprovementProposal as AgentImprovementProposal$1, AgentImprovementReview, AgentImprovementReview as AgentImprovementReview$1, AgentImprovementReviewDecision, AgentImprovementReviewDecision as AgentImprovementReviewDecision$1, AgentImprovementSource, AgentImprovementSurface, AgentProfile, AgentProfileDiff, AgentProfileImprovementChange, AgentProfileImprovementExecutionRef, AgentProfileImprovementExperiment, AgentProfileImprovementMeasuredComparison, AgentProfileImprovementMeasurement, AgentProfileImprovementRunReceipt, AgentProfileImprovementTaskMaterial, AgentProfileMcpServer, CandidateExecutionEvidence, CandidateExecutionEvidence as CandidateExecutionEvidence$1, Sha256Digest } from "@tangle-network/agent-interface";
|
|
8
8
|
import { CostLedgerHandle, TraceStore } from "@tangle-network/agent-eval";
|
|
9
9
|
import { ProposalFinding as ProposalFinding$1 } from "@tangle-network/agent-eval/analyst";
|
|
@@ -639,8 +639,10 @@ interface CertifiedPromptSource {
|
|
|
639
639
|
compose(base: string): Promise<string>;
|
|
640
640
|
/** The certified profile currently in effect (`null` = none pulled yet). */
|
|
641
641
|
current(): CertifiedProfile | null;
|
|
642
|
-
/** Pull
|
|
643
|
-
refresh(
|
|
642
|
+
/** Pull after the refresh window, or force a pull now. Both join an in-flight pull. */
|
|
643
|
+
refresh(options?: {
|
|
644
|
+
force?: boolean;
|
|
645
|
+
}): Promise<void>;
|
|
644
646
|
}
|
|
645
647
|
/** Options for {@link createCertifiedPromptSource} — the pull coordinates plus
|
|
646
648
|
* the refresh cadence. */
|
|
@@ -1048,7 +1050,7 @@ interface AppliedIntelligence {
|
|
|
1048
1050
|
applyProfile(base: AgentProfile): AgentProfile;
|
|
1049
1051
|
/** Enrich the {@link RunRecord} sent for this call — outcome, usage split,
|
|
1050
1052
|
* model/provider, and the loop event stream. Optional; an un-recorded run
|
|
1051
|
-
* still sends input/output with
|
|
1053
|
+
* still sends input/output with unknown usage, except for the OFF billing guarantee. */
|
|
1052
1054
|
record(report: RunReport): void;
|
|
1053
1055
|
}
|
|
1054
1056
|
/** An agent wrapped by {@link withIntelligence}: receives the input plus the
|
|
@@ -1096,10 +1098,16 @@ declare function withIntelligence<I, O>(agent: IntelligenceAgent<I, O>, config:
|
|
|
1096
1098
|
* bill. This is a classification on the trace, NOT a budget-pool split.
|
|
1097
1099
|
*/
|
|
1098
1100
|
interface UsageSplit {
|
|
1099
|
-
/**
|
|
1101
|
+
/** Observed base-stream spend in USD; a subtotal when `inferenceUsdKnown` is false. */
|
|
1100
1102
|
inferenceUsd: number;
|
|
1101
1103
|
/** Intelligence-spawn spend in USD. Provably `0` at the OFF tier. */
|
|
1102
1104
|
intelligenceUsd: number;
|
|
1105
|
+
/** False when inference cost is incomplete or unreported. */
|
|
1106
|
+
inferenceUsdKnown?: false;
|
|
1107
|
+
/** False when Intelligence cost is incomplete or unreported. */
|
|
1108
|
+
intelligenceUsdKnown?: false;
|
|
1109
|
+
/** Reported inference estimate, separate from observed spend and completeness. */
|
|
1110
|
+
estimatedInferenceUsd?: number;
|
|
1103
1111
|
}
|
|
1104
1112
|
/**
|
|
1105
1113
|
* The typed record `withIntelligence` sends per call — serialized through the
|
|
@@ -1139,6 +1147,8 @@ interface RunRecord {
|
|
|
1139
1147
|
output: number;
|
|
1140
1148
|
cachedInput?: number;
|
|
1141
1149
|
reasoning?: number;
|
|
1150
|
+
/** False when the numeric token subtotals are incomplete. */
|
|
1151
|
+
tokensKnown?: false;
|
|
1142
1152
|
};
|
|
1143
1153
|
error?: {
|
|
1144
1154
|
name: string;
|
|
@@ -1151,8 +1161,8 @@ interface RunRecord {
|
|
|
1151
1161
|
/**
|
|
1152
1162
|
* What an agent reports (via `applied.record`) to enrich the {@link RunRecord}
|
|
1153
1163
|
* sent for its call. All optional — an un-recorded run still sends input/output
|
|
1154
|
-
* with
|
|
1155
|
-
*
|
|
1164
|
+
* with unknown usage, except for the OFF billing guarantee.
|
|
1165
|
+
* `costUsd` supplies inference spend when the split omits it.
|
|
1156
1166
|
*/
|
|
1157
1167
|
interface RunReport {
|
|
1158
1168
|
success?: boolean;
|
|
@@ -1251,10 +1261,9 @@ interface TraceHandle {
|
|
|
1251
1261
|
/** Capture the run's output. Exported through the redactor. */
|
|
1252
1262
|
recordOutput(output: unknown): void;
|
|
1253
1263
|
/**
|
|
1254
|
-
* Capture the run's outcome.
|
|
1255
|
-
*
|
|
1256
|
-
*
|
|
1257
|
-
* treated as pure inference.
|
|
1264
|
+
* Capture the run's outcome. Unreported spend is unknown, except for Intelligence at OFF.
|
|
1265
|
+
* `costUsd` supplies inference spend when the split omits it.
|
|
1266
|
+
* Numeric usage updates replace subtotals; explicit incomplete flags remain sticky.
|
|
1258
1267
|
*/
|
|
1259
1268
|
recordOutcome(outcome: {
|
|
1260
1269
|
success?: boolean;
|
package/dist/intelligence.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Yn as resolveRedactor, ar as buildLoopOtelSpans, dr as flatOtelSpan, jn as resolveAgentEnvironmentProvider, lr as createOtelExporter, qn as defaultRedactor, sr as buildRuntimeEventOtelSpans } from "./supervisor-
|
|
2
|
-
import {
|
|
1
|
+
import { Yn as resolveRedactor, ar as buildLoopOtelSpans, dr as flatOtelSpan, jn as resolveAgentEnvironmentProvider, lr as createOtelExporter, qn as defaultRedactor, sr as buildRuntimeEventOtelSpans } from "./supervisor-BIBWUFUr.js";
|
|
2
|
+
import { a as createRuntimeUsageTotals, i as addRuntimeUsage, n as executeAgentImprovementActivation, o as isUsageAmount, r as verifyAgentImprovementActivationResult, t as createAgentImprovementActivationResult } from "./activation-ygjQvYwG.js";
|
|
3
|
+
import { C as optimizationActivationReceiptFromMetadata, D as agentImprovementProfileSurfaceDigest, E as agentImprovementProfileDiffs, F as isAgentImprovementProfileSurface, I as isAgentProfileMeasuredSurface, N as assertProfileImprovementTargetsShareIdentity, O as agentImprovementProfileSurfaceInput, P as buildAgentImprovementActivationTargets, S as createOptimizationActivationReceipt, T as AGENT_PROFILE_MEASURED_SURFACES, V as assertProfileTrainingIsHeldOut, _ as profilePolicyWithBudget, a as executeAgentCandidateExperimentCell, b as profileTaskScenarioIdentity, d as verifyAgentImprovementActivation, f as verifyAgentImprovementProposal, g as profileImprovementMetadata, h as createProfileImprovementCostLedger, i as createAgentImprovementProposal, j as agentImprovementTargetProfileDiffs, l as reviewAgentImprovementProposal, m as verifyCandidateExecutionEvidence, n as createAgentImprovementActivation, o as proposeAgentImprovement, p as verifyAgentImprovementReview, r as createAgentImprovementMeasuredComparison, s as proposeAgentProfileImprovement, t as AgentCandidateExperimentCellExecutionError, u as runAgentCandidateExperiment, v as profilePreparationAccounting, w as AGENT_IMPROVEMENT_PROFILE_SURFACES, x as sealProfileImprovementBenchmark, y as profileStateDigest$1 } from "./improvement-cycle-B049YmQ8.js";
|
|
3
4
|
import { o as canonicalCandidateDigest$1, u as immutableCandidateValue } from "./protected-redaction-Fn1ETfJ-.js";
|
|
4
5
|
import { A as omitUndefinedObjectFields, M as parseExactAgentProfile, a as AGENT_CANDIDATE_EXECUTION_SUPPORT, j as parseAgentCandidateProfileActivation, w as applyExactAgentProfileDiff } from "./prepare-CibQrhfi.js";
|
|
5
|
-
import { n as executeAgentImprovementActivation, r as verifyAgentImprovementActivationResult, t as createAgentImprovementActivationResult } from "./activation-C6d-NTWk.js";
|
|
6
6
|
import { n as exactProcessProviderAsCandidateExecutor, t as createProtectedAgentCandidateModelPort } from "./protected-model-port-Dhdi5mDl.js";
|
|
7
7
|
import { agentImprovementSourceSchema, agentProfileImprovementArmSchema, applyAgentProfileDiff } from "@tangle-network/agent-interface";
|
|
8
8
|
import { contentHash } from "@tangle-network/agent-eval";
|
|
@@ -251,15 +251,16 @@ function composeCertifiedPrompt(base, certified) {
|
|
|
251
251
|
* `withIntelligence` hook rides this same source for its prompt delivery.
|
|
252
252
|
*/
|
|
253
253
|
function createCertifiedPromptSource(opts) {
|
|
254
|
-
const
|
|
254
|
+
const pullOptions = { ...opts };
|
|
255
|
+
const refreshMs = pullOptions.refreshMs ?? defaultRefreshMs;
|
|
255
256
|
let certified = null;
|
|
256
|
-
let lastPullAt
|
|
257
|
+
let lastPullAt;
|
|
257
258
|
let inflight = null;
|
|
258
|
-
async function refresh() {
|
|
259
|
-
if (Date.now() - lastPullAt < refreshMs) return;
|
|
259
|
+
async function refresh(options) {
|
|
260
260
|
if (inflight) return inflight;
|
|
261
|
+
if (!options?.force && lastPullAt !== void 0 && Date.now() - lastPullAt < refreshMs) return;
|
|
261
262
|
inflight = (async () => {
|
|
262
|
-
const outcome = await pullCertified(
|
|
263
|
+
const outcome = await pullCertified(pullOptions);
|
|
263
264
|
lastPullAt = Date.now();
|
|
264
265
|
if (outcome.succeeded) certified = outcome.value;
|
|
265
266
|
})();
|
|
@@ -370,6 +371,37 @@ function compileEffort(settings) {
|
|
|
370
371
|
};
|
|
371
372
|
}
|
|
372
373
|
//#endregion
|
|
374
|
+
//#region src/intelligence/usage.ts
|
|
375
|
+
/** Numeric reports replace subtotals; explicit or malformed missingness is irreversible. */
|
|
376
|
+
function mergeReportedUsage(target, report) {
|
|
377
|
+
const update = {
|
|
378
|
+
...report.usage,
|
|
379
|
+
inferenceUsd: report.usage?.inferenceUsd ?? report.costUsd
|
|
380
|
+
};
|
|
381
|
+
for (const [amount, known] of [
|
|
382
|
+
["inferenceUsd", "inferenceUsdKnown"],
|
|
383
|
+
["intelligenceUsd", "intelligenceUsdKnown"],
|
|
384
|
+
["estimatedInferenceUsd", void 0]
|
|
385
|
+
]) {
|
|
386
|
+
const value = update[amount];
|
|
387
|
+
if (isUsageAmount(value)) target[amount] = value;
|
|
388
|
+
else if (value !== void 0 && known !== void 0) target[known] = false;
|
|
389
|
+
if (known !== void 0 && update[known] === false) target[known] = false;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/** Absence is unknown; OFF alone proves zero Intelligence spend without a receipt. */
|
|
393
|
+
function normalizeReportedUsage(usage, intelligenceOff = false) {
|
|
394
|
+
const inferenceKnown = isUsageAmount(usage.inferenceUsd) && usage.inferenceUsdKnown !== false;
|
|
395
|
+
const intelligenceKnown = intelligenceOff || isUsageAmount(usage.intelligenceUsd) && usage.intelligenceUsdKnown !== false;
|
|
396
|
+
return {
|
|
397
|
+
inferenceUsd: isUsageAmount(usage.inferenceUsd) ? usage.inferenceUsd : 0,
|
|
398
|
+
intelligenceUsd: intelligenceOff || !isUsageAmount(usage.intelligenceUsd) ? 0 : usage.intelligenceUsd,
|
|
399
|
+
...!inferenceKnown ? { inferenceUsdKnown: false } : {},
|
|
400
|
+
...!intelligenceKnown ? { intelligenceUsdKnown: false } : {},
|
|
401
|
+
...isUsageAmount(usage.estimatedInferenceUsd) ? { estimatedInferenceUsd: usage.estimatedInferenceUsd } : {}
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
//#endregion
|
|
373
405
|
//#region src/intelligence/authored-profile-improvement.ts
|
|
374
406
|
/**
|
|
375
407
|
* Put a complete authored/imported profile through the canonical profile
|
|
@@ -888,18 +920,12 @@ function assertUniqueProfileTargets(targets) {
|
|
|
888
920
|
//#endregion
|
|
889
921
|
//#region src/intelligence/with-intelligence.ts
|
|
890
922
|
function summarizeRuntimeEvents(events) {
|
|
891
|
-
const summary =
|
|
892
|
-
inferenceUsd: 0,
|
|
893
|
-
inputTokens: 0,
|
|
894
|
-
outputTokens: 0
|
|
895
|
-
};
|
|
923
|
+
const summary = createRuntimeUsageTotals();
|
|
896
924
|
for (const event of events) {
|
|
897
925
|
if ("session" in event && event.session) summary.sessionId = event.session.id;
|
|
898
926
|
if (event.type === "llm_call") {
|
|
899
927
|
summary.model = event.model;
|
|
900
|
-
summary
|
|
901
|
-
summary.inputTokens += event.tokensIn ?? 0;
|
|
902
|
-
summary.outputTokens += event.tokensOut ?? 0;
|
|
928
|
+
addRuntimeUsage(summary, event);
|
|
903
929
|
} else if (event.type === "backend_error") {
|
|
904
930
|
summary.success = false;
|
|
905
931
|
summary.error = {
|
|
@@ -974,6 +1000,7 @@ function withIntelligence(agent, config) {
|
|
|
974
1000
|
const certified = source.current();
|
|
975
1001
|
const proposals = currentProposals();
|
|
976
1002
|
const report = {};
|
|
1003
|
+
const usage = {};
|
|
977
1004
|
const applied = {
|
|
978
1005
|
runId,
|
|
979
1006
|
traceId,
|
|
@@ -981,16 +1008,41 @@ function withIntelligence(agent, config) {
|
|
|
981
1008
|
composePrompt: (base) => composeCertifiedPrompt(base, certified),
|
|
982
1009
|
proposals,
|
|
983
1010
|
applyProfile: (base) => proposals.reduce((profile, p) => applyAgentProfileDiff(profile, p.diff), base),
|
|
984
|
-
record: (r) =>
|
|
1011
|
+
record: (r) => {
|
|
1012
|
+
const tokens = r.tokens ?? report.tokens;
|
|
1013
|
+
const tokensIncomplete = report.tokens?.tokensKnown === false || tokens?.tokensKnown === false;
|
|
1014
|
+
mergeReportedUsage(usage, r);
|
|
1015
|
+
Object.assign(report, r, {
|
|
1016
|
+
usage,
|
|
1017
|
+
...tokens ? { tokens: {
|
|
1018
|
+
...tokens,
|
|
1019
|
+
...tokensIncomplete ? { tokensKnown: false } : {}
|
|
1020
|
+
} } : {}
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
985
1023
|
};
|
|
986
1024
|
function exportCompleted(output, caught) {
|
|
987
1025
|
const completedAt = Date.now();
|
|
988
1026
|
const eventSummary = summarizeRuntimeEvents(report.runtimeEvents ?? []);
|
|
989
1027
|
const error = report.error ?? (caught !== void 0 ? runError(caught) : eventSummary.error);
|
|
990
|
-
const tokens = report.tokens
|
|
991
|
-
input: eventSummary.
|
|
992
|
-
output: eventSummary.
|
|
993
|
-
|
|
1028
|
+
const tokens = report.tokens !== void 0 || eventSummary.llmCalls > 0 ? {
|
|
1029
|
+
input: eventSummary.tokensIn,
|
|
1030
|
+
output: eventSummary.tokensOut,
|
|
1031
|
+
...eventSummary.tokensKnown === false || report.tokens?.tokensKnown === false ? { tokensKnown: false } : {}
|
|
1032
|
+
} : void 0;
|
|
1033
|
+
if (tokens && report.tokens) for (const key of [
|
|
1034
|
+
"input",
|
|
1035
|
+
"output",
|
|
1036
|
+
"cachedInput",
|
|
1037
|
+
"reasoning"
|
|
1038
|
+
]) {
|
|
1039
|
+
const value = report.tokens[key];
|
|
1040
|
+
if (isUsageAmount(value) && Number.isSafeInteger(value)) tokens[key] = value;
|
|
1041
|
+
else if (value !== void 0 || key === "input" || key === "output") tokens.tokensKnown = false;
|
|
1042
|
+
}
|
|
1043
|
+
const reportedCost = report.usage?.inferenceUsd ?? report.costUsd;
|
|
1044
|
+
const inferenceKnown = eventSummary.usdKnown !== false && report.usage?.inferenceUsdKnown !== false && (reportedCost !== void 0 ? isUsageAmount(reportedCost) : eventSummary.llmCalls > 0);
|
|
1045
|
+
const estimatedInferenceUsd = isUsageAmount(report.usage?.estimatedInferenceUsd) ? report.usage.estimatedInferenceUsd : eventSummary.estimatedCostUsd;
|
|
994
1046
|
const profile = report.profile ?? config.profile;
|
|
995
1047
|
const record = {
|
|
996
1048
|
runId,
|
|
@@ -1002,10 +1054,13 @@ function withIntelligence(agent, config) {
|
|
|
1002
1054
|
outcome: {
|
|
1003
1055
|
success: report.success ?? (caught !== void 0 ? false : eventSummary.success ?? error === void 0),
|
|
1004
1056
|
...report.score !== void 0 ? { score: report.score } : {},
|
|
1005
|
-
usage: {
|
|
1006
|
-
inferenceUsd:
|
|
1007
|
-
|
|
1008
|
-
|
|
1057
|
+
usage: normalizeReportedUsage({
|
|
1058
|
+
inferenceUsd: isUsageAmount(reportedCost) ? reportedCost : eventSummary.costUsd,
|
|
1059
|
+
...inferenceKnown ? {} : { inferenceUsdKnown: false },
|
|
1060
|
+
...isUsageAmount(estimatedInferenceUsd) ? { estimatedInferenceUsd } : {},
|
|
1061
|
+
intelligenceUsd: report.usage?.intelligenceUsd,
|
|
1062
|
+
...report.usage?.intelligenceUsdKnown === false ? { intelligenceUsdKnown: false } : {}
|
|
1063
|
+
})
|
|
1009
1064
|
},
|
|
1010
1065
|
timing: {
|
|
1011
1066
|
startedAt,
|
|
@@ -1063,6 +1118,16 @@ function withIntelligence(agent, config) {
|
|
|
1063
1118
|
* @module
|
|
1064
1119
|
* @stable
|
|
1065
1120
|
*/
|
|
1121
|
+
function usageAttributes(usage, intelligenceOff) {
|
|
1122
|
+
const normalized = normalizeReportedUsage(usage, intelligenceOff);
|
|
1123
|
+
return {
|
|
1124
|
+
"tangle.usage.inference_usd": normalized.inferenceUsd,
|
|
1125
|
+
"tangle.usage.intelligence_usd": normalized.intelligenceUsd,
|
|
1126
|
+
...normalized.inferenceUsdKnown === false ? { "tangle.usage.inference_usd_known": false } : {},
|
|
1127
|
+
...normalized.intelligenceUsdKnown === false ? { "tangle.usage.intelligence_usd_known": false } : {},
|
|
1128
|
+
...normalized.estimatedInferenceUsd !== void 0 ? { "tangle.usage.inference_usd_estimated": normalized.estimatedInferenceUsd } : {}
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1066
1131
|
function resolveEffortConfig(effort) {
|
|
1067
1132
|
if (effort === void 0) return resolveEffort(defaultEffortTier);
|
|
1068
1133
|
if (typeof effort === "string") return resolveEffort(effort);
|
|
@@ -1132,8 +1197,7 @@ function createIntelligenceClient(config) {
|
|
|
1132
1197
|
const labels = {
|
|
1133
1198
|
project: config.project,
|
|
1134
1199
|
"tangle.effort.intelligence_off": outcome.intelligenceOff,
|
|
1135
|
-
|
|
1136
|
-
"tangle.usage.intelligence_usd": outcome.usage.intelligenceUsd,
|
|
1200
|
+
...usageAttributes(outcome.usage, intelligenceOff),
|
|
1137
1201
|
...meta.model ? { "gen_ai.request.model": meta.model } : {},
|
|
1138
1202
|
...meta.provider ? { "provider.name": meta.provider } : {},
|
|
1139
1203
|
...typeof outcome.success === "boolean" ? { "tangle.outcome.success": outcome.success } : {},
|
|
@@ -1154,14 +1218,12 @@ function createIntelligenceClient(config) {
|
|
|
1154
1218
|
const ex = getExporter();
|
|
1155
1219
|
if (!ex) return record.traceId;
|
|
1156
1220
|
try {
|
|
1157
|
-
const intelligenceUsd = intelligenceOff ? 0 : record.outcome.usage.intelligenceUsd;
|
|
1158
1221
|
const repository = record.repository ?? (config.repo ? `${config.repo.owner}/${config.repo.name}` : void 0);
|
|
1159
1222
|
const labels = {
|
|
1160
1223
|
project: record.project,
|
|
1161
1224
|
"tangle.target": record.target,
|
|
1162
1225
|
"tangle.effort.intelligence_off": intelligenceOff,
|
|
1163
|
-
|
|
1164
|
-
"tangle.usage.intelligence_usd": intelligenceUsd,
|
|
1226
|
+
...usageAttributes(record.outcome.usage, intelligenceOff),
|
|
1165
1227
|
...record.model ? { "gen_ai.request.model": record.model } : {},
|
|
1166
1228
|
...record.provider ? { "provider.name": record.provider } : {},
|
|
1167
1229
|
...record.sessionId ? {
|
|
@@ -1179,6 +1241,7 @@ function createIntelligenceClient(config) {
|
|
|
1179
1241
|
...record.tokens ? {
|
|
1180
1242
|
"gen_ai.usage.input_tokens": record.tokens.input,
|
|
1181
1243
|
"gen_ai.usage.output_tokens": record.tokens.output,
|
|
1244
|
+
...record.tokens.tokensKnown === false ? { "tangle.usage.tokens_known": false } : {},
|
|
1182
1245
|
...record.tokens.cachedInput !== void 0 ? { "gen_ai.usage.cache_read_input_tokens": record.tokens.cachedInput } : {},
|
|
1183
1246
|
...record.tokens.reasoning !== void 0 ? { "gen_ai.usage.reasoning_tokens": record.tokens.reasoning } : {}
|
|
1184
1247
|
} : {},
|
|
@@ -1237,10 +1300,7 @@ function createIntelligenceClient(config) {
|
|
|
1237
1300
|
const runId = meta.runId ?? freshRunId();
|
|
1238
1301
|
const traceId = meta.traceId ?? freshTraceId();
|
|
1239
1302
|
let recordedOutput;
|
|
1240
|
-
const usage = {
|
|
1241
|
-
inferenceUsd: 0,
|
|
1242
|
-
intelligenceUsd: 0
|
|
1243
|
-
};
|
|
1303
|
+
const usage = {};
|
|
1244
1304
|
let success;
|
|
1245
1305
|
let score;
|
|
1246
1306
|
const result = await fn({
|
|
@@ -1250,13 +1310,9 @@ function createIntelligenceClient(config) {
|
|
|
1250
1310
|
recordOutcome(outcome) {
|
|
1251
1311
|
if (typeof outcome.success === "boolean") success = outcome.success;
|
|
1252
1312
|
if (typeof outcome.score === "number") score = outcome.score;
|
|
1253
|
-
|
|
1254
|
-
if (typeof outcome.usage.inferenceUsd === "number") usage.inferenceUsd = outcome.usage.inferenceUsd;
|
|
1255
|
-
if (typeof outcome.usage.intelligenceUsd === "number") usage.intelligenceUsd = outcome.usage.intelligenceUsd;
|
|
1256
|
-
} else if (typeof outcome.costUsd === "number") usage.inferenceUsd = outcome.costUsd;
|
|
1313
|
+
mergeReportedUsage(usage, outcome);
|
|
1257
1314
|
}
|
|
1258
1315
|
});
|
|
1259
|
-
if (intelligenceOff) usage.intelligenceUsd = 0;
|
|
1260
1316
|
exportTrace(meta, {
|
|
1261
1317
|
runId,
|
|
1262
1318
|
traceId,
|
|
@@ -1265,7 +1321,7 @@ function createIntelligenceClient(config) {
|
|
|
1265
1321
|
intelligenceOff,
|
|
1266
1322
|
...success !== void 0 ? { success } : {},
|
|
1267
1323
|
...score !== void 0 ? { score } : {},
|
|
1268
|
-
usage
|
|
1324
|
+
usage: normalizeReportedUsage(usage, intelligenceOff)
|
|
1269
1325
|
}, recordedOutput);
|
|
1270
1326
|
return result;
|
|
1271
1327
|
},
|