@tangle-network/agent-runtime 0.247.0 → 0.252.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/{activation-DYqnl8zq.js → activation-BSLatbiJ.js} +34 -4
- package/dist/activation-BSLatbiJ.js.map +1 -0
- package/dist/{activation-DizpINK3.d.ts → activation-BykUtuec.d.ts} +2 -2
- package/dist/agent.d.ts +2 -2
- package/dist/agent.js +2 -2
- package/dist/bundle-DXrBPEFw.js +17 -0
- package/dist/bundle-DXrBPEFw.js.map +1 -0
- package/dist/candidate-execution/index.js +4 -4
- package/dist/{coordination-driver-BV4AAUns.js → coordination-driver-QxitIuva.js} +162 -17
- package/dist/coordination-driver-QxitIuva.js.map +1 -0
- package/dist/{delegate-DQAzB5Xv.js → delegate-BB90iDo7.js} +2 -2
- package/dist/{delegate-DQAzB5Xv.js.map → delegate-BB90iDo7.js.map} +1 -1
- package/dist/durable.d.ts +2 -2
- package/dist/durable.js +2 -2
- package/dist/{graph-DcBmMLIp.js → graph-yC6wqOIt.js} +3 -3
- package/dist/{graph-DcBmMLIp.js.map → graph-yC6wqOIt.js.map} +1 -1
- package/dist/{improvement-cycle-B049YmQ8.js → improvement-cycle-on_u94aK.js} +5 -5
- package/dist/{improvement-cycle-B049YmQ8.js.map → improvement-cycle-on_u94aK.js.map} +1 -1
- package/dist/{index-DLzlXwr6.d.ts → index-DGWG7wSS.d.ts} +20 -9
- package/dist/index.d.ts +8 -6
- package/dist/index.js +32 -50
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +18 -11
- package/dist/intelligence.js +93 -38
- package/dist/intelligence.js.map +1 -1
- package/dist/kernel.d.ts +4 -4
- package/dist/kernel.js +9 -9
- package/dist/{loop-runner-bin-HbMECmxT.d.ts → loop-runner-bin-CsVNUclF.d.ts} +3 -3
- package/dist/{loop-runner-bin-iqq1azfy.js → loop-runner-bin-PL0dItet.js} +3 -3
- package/dist/{loop-runner-bin-iqq1azfy.js.map → loop-runner-bin-PL0dItet.js.map} +1 -1
- 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-DvLk_Ddg.d.ts → openai-tools-zrajPyXe.d.ts} +2 -2
- package/dist/{prepare-CibQrhfi.js → prepare-RuaAclli.js} +8 -598
- package/dist/prepare-RuaAclli.js.map +1 -0
- package/dist/profiles.d.ts +2 -2
- package/dist/{protected-model-port-Dhdi5mDl.js → protected-model-port-BFhSgMAy.js} +3 -3
- package/dist/{protected-model-port-Dhdi5mDl.js.map → protected-model-port-BFhSgMAy.js.map} +1 -1
- package/dist/{protected-redaction-Fn1ETfJ-.js → protected-redaction--F3v1oo8.js} +3 -54
- package/dist/protected-redaction--F3v1oo8.js.map +1 -0
- package/dist/{provision-supervisor-BgQx2Avp.js → provision-supervisor-DsAhgOpn.js} +4 -4
- package/dist/{provision-supervisor-BgQx2Avp.js.map → provision-supervisor-DsAhgOpn.js.map} +1 -1
- package/dist/{run-layout-hKAJGF4g.js → run-layout-vwd4SwX_.js} +15 -9
- package/dist/run-layout-vwd4SwX_.js.map +1 -0
- package/dist/{runtime-HpTXhB3g.js → runtime-CMNTa7Rw.js} +11 -10
- package/dist/{runtime-HpTXhB3g.js.map → runtime-CMNTa7Rw.js.map} +1 -1
- package/dist/{server-OOE7mXrN.js → server-2fL_QElQ.js} +3 -3
- package/dist/{server-OOE7mXrN.js.map → server-2fL_QElQ.js.map} +1 -1
- package/dist/{stream-agent-turn-CcumM0Bu.d.ts → stream-agent-turn-oeWkjxMi.d.ts} +32 -5
- package/dist/{structural-rollout-z1A0okaB.js → structural-rollout-DRD-WnV-.js} +2 -2
- package/dist/{structural-rollout-z1A0okaB.js.map → structural-rollout-DRD-WnV-.js.map} +1 -1
- package/dist/{substrate-CQ0hfewn.d.ts → substrate-Ctmos75o.d.ts} +2 -2
- package/dist/{supervise-DZEOpzRw.js → supervise-BXzkqfTE.js} +25 -8
- package/dist/supervise-BXzkqfTE.js.map +1 -0
- package/dist/{supervisor-BIBWUFUr.js → supervisor-OJwKAnFd.js} +391 -187
- package/dist/supervisor-OJwKAnFd.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +14 -14
- package/dist/{top-app-d-bmwO7O.js → top-app-VAOrBskv.js} +2 -2
- package/dist/{top-app-d-bmwO7O.js.map → top-app-VAOrBskv.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-BUhz284C.d.ts → types-BmxS-W-f.d.ts} +22 -11
- package/dist/workspace-archive-DQGFwvM6.js +1209 -0
- package/dist/workspace-archive-DQGFwvM6.js.map +1 -0
- package/package.json +4 -4
- package/dist/activation-DYqnl8zq.js.map +0 -1
- package/dist/coordination-driver-BV4AAUns.js.map +0 -1
- package/dist/prepare-CibQrhfi.js.map +0 -1
- package/dist/protected-redaction-Fn1ETfJ-.js.map +0 -1
- package/dist/run-layout-hKAJGF4g.js.map +0 -1
- package/dist/supervise-DZEOpzRw.js.map +0 -1
- package/dist/supervisor-BIBWUFUr.js.map +0 -1
- package/dist/workspace-archive-DSRT4Tro.js +0 -572
- package/dist/workspace-archive-DSRT4Tro.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 {
|
|
3
|
+
import { Dn as ToolSpec, ir as resolveRedactor, nr as Redactor, rr as defaultRedactor, vt as AgentEnvironmentProviderRef, yt as AgentEnvironmentProviderRegistry } from "./stream-agent-turn-oeWkjxMi.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-BykUtuec.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";
|
|
@@ -1050,7 +1050,7 @@ interface AppliedIntelligence {
|
|
|
1050
1050
|
applyProfile(base: AgentProfile): AgentProfile;
|
|
1051
1051
|
/** Enrich the {@link RunRecord} sent for this call — outcome, usage split,
|
|
1052
1052
|
* model/provider, and the loop event stream. Optional; an un-recorded run
|
|
1053
|
-
* still sends input/output with
|
|
1053
|
+
* still sends input/output with unknown usage, except for the OFF billing guarantee. */
|
|
1054
1054
|
record(report: RunReport): void;
|
|
1055
1055
|
}
|
|
1056
1056
|
/** An agent wrapped by {@link withIntelligence}: receives the input plus the
|
|
@@ -1098,10 +1098,16 @@ declare function withIntelligence<I, O>(agent: IntelligenceAgent<I, O>, config:
|
|
|
1098
1098
|
* bill. This is a classification on the trace, NOT a budget-pool split.
|
|
1099
1099
|
*/
|
|
1100
1100
|
interface UsageSplit {
|
|
1101
|
-
/**
|
|
1101
|
+
/** Observed base-stream spend in USD; a subtotal when `inferenceUsdKnown` is false. */
|
|
1102
1102
|
inferenceUsd: number;
|
|
1103
1103
|
/** Intelligence-spawn spend in USD. Provably `0` at the OFF tier. */
|
|
1104
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;
|
|
1105
1111
|
}
|
|
1106
1112
|
/**
|
|
1107
1113
|
* The typed record `withIntelligence` sends per call — serialized through the
|
|
@@ -1141,6 +1147,8 @@ interface RunRecord {
|
|
|
1141
1147
|
output: number;
|
|
1142
1148
|
cachedInput?: number;
|
|
1143
1149
|
reasoning?: number;
|
|
1150
|
+
/** False when the numeric token subtotals are incomplete. */
|
|
1151
|
+
tokensKnown?: false;
|
|
1144
1152
|
};
|
|
1145
1153
|
error?: {
|
|
1146
1154
|
name: string;
|
|
@@ -1153,8 +1161,8 @@ interface RunRecord {
|
|
|
1153
1161
|
/**
|
|
1154
1162
|
* What an agent reports (via `applied.record`) to enrich the {@link RunRecord}
|
|
1155
1163
|
* sent for its call. All optional — an un-recorded run still sends input/output
|
|
1156
|
-
* with
|
|
1157
|
-
*
|
|
1164
|
+
* with unknown usage, except for the OFF billing guarantee.
|
|
1165
|
+
* `costUsd` supplies inference spend when the split omits it.
|
|
1158
1166
|
*/
|
|
1159
1167
|
interface RunReport {
|
|
1160
1168
|
success?: boolean;
|
|
@@ -1253,10 +1261,9 @@ interface TraceHandle {
|
|
|
1253
1261
|
/** Capture the run's output. Exported through the redactor. */
|
|
1254
1262
|
recordOutput(output: unknown): void;
|
|
1255
1263
|
/**
|
|
1256
|
-
* Capture the run's outcome.
|
|
1257
|
-
*
|
|
1258
|
-
*
|
|
1259
|
-
* 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.
|
|
1260
1267
|
*/
|
|
1261
1268
|
recordOutcome(outcome: {
|
|
1262
1269
|
success?: boolean;
|
package/dist/intelligence.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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 {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { n as exactProcessProviderAsCandidateExecutor, t as createProtectedAgentCandidateModelPort } from "./protected-model-port-
|
|
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-OJwKAnFd.js";
|
|
2
|
+
import { a as createRuntimeUsageTotals, i as addRuntimeUsage, n as executeAgentImprovementActivation, o as isUsageAmount, r as verifyAgentImprovementActivationResult, t as createAgentImprovementActivationResult } from "./activation-BSLatbiJ.js";
|
|
3
|
+
import { E as immutableCandidateValue, S as canonicalCandidateDigest$1 } from "./workspace-archive-DQGFwvM6.js";
|
|
4
|
+
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-on_u94aK.js";
|
|
5
|
+
import { A as parseAgentCandidateProfileActivation, C as applyExactAgentProfileDiff, a as AGENT_CANDIDATE_EXECUTION_SUPPORT, j as parseExactAgentProfile, k as omitUndefinedObjectFields } from "./prepare-RuaAclli.js";
|
|
6
|
+
import { n as exactProcessProviderAsCandidateExecutor, t as createProtectedAgentCandidateModelPort } from "./protected-model-port-BFhSgMAy.js";
|
|
7
7
|
import { agentImprovementSourceSchema, agentProfileImprovementArmSchema, applyAgentProfileDiff } from "@tangle-network/agent-interface";
|
|
8
8
|
import { contentHash } from "@tangle-network/agent-eval";
|
|
9
9
|
import { assertProposalFindings } from "@tangle-network/agent-eval/analyst";
|
|
@@ -371,6 +371,37 @@ function compileEffort(settings) {
|
|
|
371
371
|
};
|
|
372
372
|
}
|
|
373
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
|
|
374
405
|
//#region src/intelligence/authored-profile-improvement.ts
|
|
375
406
|
/**
|
|
376
407
|
* Put a complete authored/imported profile through the canonical profile
|
|
@@ -889,18 +920,12 @@ function assertUniqueProfileTargets(targets) {
|
|
|
889
920
|
//#endregion
|
|
890
921
|
//#region src/intelligence/with-intelligence.ts
|
|
891
922
|
function summarizeRuntimeEvents(events) {
|
|
892
|
-
const summary =
|
|
893
|
-
inferenceUsd: 0,
|
|
894
|
-
inputTokens: 0,
|
|
895
|
-
outputTokens: 0
|
|
896
|
-
};
|
|
923
|
+
const summary = createRuntimeUsageTotals();
|
|
897
924
|
for (const event of events) {
|
|
898
925
|
if ("session" in event && event.session) summary.sessionId = event.session.id;
|
|
899
926
|
if (event.type === "llm_call") {
|
|
900
927
|
summary.model = event.model;
|
|
901
|
-
summary
|
|
902
|
-
summary.inputTokens += event.tokensIn ?? 0;
|
|
903
|
-
summary.outputTokens += event.tokensOut ?? 0;
|
|
928
|
+
addRuntimeUsage(summary, event);
|
|
904
929
|
} else if (event.type === "backend_error") {
|
|
905
930
|
summary.success = false;
|
|
906
931
|
summary.error = {
|
|
@@ -975,6 +1000,7 @@ function withIntelligence(agent, config) {
|
|
|
975
1000
|
const certified = source.current();
|
|
976
1001
|
const proposals = currentProposals();
|
|
977
1002
|
const report = {};
|
|
1003
|
+
const usage = {};
|
|
978
1004
|
const applied = {
|
|
979
1005
|
runId,
|
|
980
1006
|
traceId,
|
|
@@ -982,16 +1008,41 @@ function withIntelligence(agent, config) {
|
|
|
982
1008
|
composePrompt: (base) => composeCertifiedPrompt(base, certified),
|
|
983
1009
|
proposals,
|
|
984
1010
|
applyProfile: (base) => proposals.reduce((profile, p) => applyAgentProfileDiff(profile, p.diff), base),
|
|
985
|
-
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
|
+
}
|
|
986
1023
|
};
|
|
987
1024
|
function exportCompleted(output, caught) {
|
|
988
1025
|
const completedAt = Date.now();
|
|
989
1026
|
const eventSummary = summarizeRuntimeEvents(report.runtimeEvents ?? []);
|
|
990
1027
|
const error = report.error ?? (caught !== void 0 ? runError(caught) : eventSummary.error);
|
|
991
|
-
const tokens = report.tokens
|
|
992
|
-
input: eventSummary.
|
|
993
|
-
output: eventSummary.
|
|
994
|
-
|
|
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;
|
|
995
1046
|
const profile = report.profile ?? config.profile;
|
|
996
1047
|
const record = {
|
|
997
1048
|
runId,
|
|
@@ -1003,10 +1054,13 @@ function withIntelligence(agent, config) {
|
|
|
1003
1054
|
outcome: {
|
|
1004
1055
|
success: report.success ?? (caught !== void 0 ? false : eventSummary.success ?? error === void 0),
|
|
1005
1056
|
...report.score !== void 0 ? { score: report.score } : {},
|
|
1006
|
-
usage: {
|
|
1007
|
-
inferenceUsd:
|
|
1008
|
-
|
|
1009
|
-
|
|
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
|
+
})
|
|
1010
1064
|
},
|
|
1011
1065
|
timing: {
|
|
1012
1066
|
startedAt,
|
|
@@ -1064,6 +1118,16 @@ function withIntelligence(agent, config) {
|
|
|
1064
1118
|
* @module
|
|
1065
1119
|
* @stable
|
|
1066
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
|
+
}
|
|
1067
1131
|
function resolveEffortConfig(effort) {
|
|
1068
1132
|
if (effort === void 0) return resolveEffort(defaultEffortTier);
|
|
1069
1133
|
if (typeof effort === "string") return resolveEffort(effort);
|
|
@@ -1133,8 +1197,7 @@ function createIntelligenceClient(config) {
|
|
|
1133
1197
|
const labels = {
|
|
1134
1198
|
project: config.project,
|
|
1135
1199
|
"tangle.effort.intelligence_off": outcome.intelligenceOff,
|
|
1136
|
-
|
|
1137
|
-
"tangle.usage.intelligence_usd": outcome.usage.intelligenceUsd,
|
|
1200
|
+
...usageAttributes(outcome.usage, intelligenceOff),
|
|
1138
1201
|
...meta.model ? { "gen_ai.request.model": meta.model } : {},
|
|
1139
1202
|
...meta.provider ? { "provider.name": meta.provider } : {},
|
|
1140
1203
|
...typeof outcome.success === "boolean" ? { "tangle.outcome.success": outcome.success } : {},
|
|
@@ -1155,14 +1218,12 @@ function createIntelligenceClient(config) {
|
|
|
1155
1218
|
const ex = getExporter();
|
|
1156
1219
|
if (!ex) return record.traceId;
|
|
1157
1220
|
try {
|
|
1158
|
-
const intelligenceUsd = intelligenceOff ? 0 : record.outcome.usage.intelligenceUsd;
|
|
1159
1221
|
const repository = record.repository ?? (config.repo ? `${config.repo.owner}/${config.repo.name}` : void 0);
|
|
1160
1222
|
const labels = {
|
|
1161
1223
|
project: record.project,
|
|
1162
1224
|
"tangle.target": record.target,
|
|
1163
1225
|
"tangle.effort.intelligence_off": intelligenceOff,
|
|
1164
|
-
|
|
1165
|
-
"tangle.usage.intelligence_usd": intelligenceUsd,
|
|
1226
|
+
...usageAttributes(record.outcome.usage, intelligenceOff),
|
|
1166
1227
|
...record.model ? { "gen_ai.request.model": record.model } : {},
|
|
1167
1228
|
...record.provider ? { "provider.name": record.provider } : {},
|
|
1168
1229
|
...record.sessionId ? {
|
|
@@ -1180,6 +1241,7 @@ function createIntelligenceClient(config) {
|
|
|
1180
1241
|
...record.tokens ? {
|
|
1181
1242
|
"gen_ai.usage.input_tokens": record.tokens.input,
|
|
1182
1243
|
"gen_ai.usage.output_tokens": record.tokens.output,
|
|
1244
|
+
...record.tokens.tokensKnown === false ? { "tangle.usage.tokens_known": false } : {},
|
|
1183
1245
|
...record.tokens.cachedInput !== void 0 ? { "gen_ai.usage.cache_read_input_tokens": record.tokens.cachedInput } : {},
|
|
1184
1246
|
...record.tokens.reasoning !== void 0 ? { "gen_ai.usage.reasoning_tokens": record.tokens.reasoning } : {}
|
|
1185
1247
|
} : {},
|
|
@@ -1238,10 +1300,7 @@ function createIntelligenceClient(config) {
|
|
|
1238
1300
|
const runId = meta.runId ?? freshRunId();
|
|
1239
1301
|
const traceId = meta.traceId ?? freshTraceId();
|
|
1240
1302
|
let recordedOutput;
|
|
1241
|
-
const usage = {
|
|
1242
|
-
inferenceUsd: 0,
|
|
1243
|
-
intelligenceUsd: 0
|
|
1244
|
-
};
|
|
1303
|
+
const usage = {};
|
|
1245
1304
|
let success;
|
|
1246
1305
|
let score;
|
|
1247
1306
|
const result = await fn({
|
|
@@ -1251,13 +1310,9 @@ function createIntelligenceClient(config) {
|
|
|
1251
1310
|
recordOutcome(outcome) {
|
|
1252
1311
|
if (typeof outcome.success === "boolean") success = outcome.success;
|
|
1253
1312
|
if (typeof outcome.score === "number") score = outcome.score;
|
|
1254
|
-
|
|
1255
|
-
if (typeof outcome.usage.inferenceUsd === "number") usage.inferenceUsd = outcome.usage.inferenceUsd;
|
|
1256
|
-
if (typeof outcome.usage.intelligenceUsd === "number") usage.intelligenceUsd = outcome.usage.intelligenceUsd;
|
|
1257
|
-
} else if (typeof outcome.costUsd === "number") usage.inferenceUsd = outcome.costUsd;
|
|
1313
|
+
mergeReportedUsage(usage, outcome);
|
|
1258
1314
|
}
|
|
1259
1315
|
});
|
|
1260
|
-
if (intelligenceOff) usage.intelligenceUsd = 0;
|
|
1261
1316
|
exportTrace(meta, {
|
|
1262
1317
|
runId,
|
|
1263
1318
|
traceId,
|
|
@@ -1266,7 +1321,7 @@ function createIntelligenceClient(config) {
|
|
|
1266
1321
|
intelligenceOff,
|
|
1267
1322
|
...success !== void 0 ? { success } : {},
|
|
1268
1323
|
...score !== void 0 ? { score } : {},
|
|
1269
|
-
usage
|
|
1324
|
+
usage: normalizeReportedUsage(usage, intelligenceOff)
|
|
1270
1325
|
}, recordedOutput);
|
|
1271
1326
|
return result;
|
|
1272
1327
|
},
|