@tangle-network/sdk-telemetry 0.60.78-develop.20261026103900.8d71e95 → 0.60.78-develop.20261026111948.bd9ddcb

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/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  Usage tracking, credit management, execution-trace collection, and telemetry
4
4
  export for the Agent Dev Container SDK.
5
5
 
6
+ The existing `server-timing` entry exports `partitionLifecycleWalls` for per-input accounting; `stage-span` exports parent, leaf and stage-tree projections. [Lifecycle accounting](src/lifecycle-wall.ts) preserves unavailable timings and signed overlap residuals. Consumers own population grouping, statistics and display labels.
7
+
6
8
  ## LLM call capture
7
9
 
8
10
  Capture LLM calls (model, tokens, latency, prompt/completion) with
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { f as parseServerTiming, l as ServerTimingEntry } from "./server-timing-BScGLvfx.mjs";
1
+ import { f as parseServerTiming, l as ServerTimingEntry } from "./server-timing-CE4vurML.mjs";
2
2
  import { LifecycleOp, ORCHESTRATOR_HOP_ID_HEADER, PROVISION_TRACE_ID_HEADER, PTID_PREFIX, RecordOptions, SpanComponent, SpanRecorder, SpanStatus, StageSpan, StageSpanInput, isAdoptablePtid, mintPtid, monotonicNs, readOrMintPtid, spanDurationMs } from "./stage-span.mjs";
3
3
  import { AgentEvent, ErrorEvent as AgentErrorEvent, FilePart, GEN_AI_CONVERSATION_ID, GEN_AI_INPUT_TOKEN_KEYS, GEN_AI_MODEL_KEYS, GEN_AI_OPERATION_NAME, GEN_AI_OUTPUT_TOKEN_KEYS, GEN_AI_REQUEST_MODEL, GEN_AI_RESPONSE_MODEL, GEN_AI_USAGE_INPUT_TOKENS, GEN_AI_USAGE_OUTPUT_TOKENS, GenAiUsage, MessagePartUpdatedEvent, MessagePartUpdatedEvent as MessagePartUpdatedEvent$1, ParsedSSEEvent, Part, ReasoningPart, ResultEvent, SSEChunkParser, SSEEventData, SSEEventData as SSEEventData$1, SSEParserOptions, StatusEvent, StreamTokenUsage, StreamUsageAccumulator, StreamUsageExtractor, TOKEN_USAGE_COST_KEYS, TOKEN_USAGE_INPUT_KEYS, TOKEN_USAGE_OUTPUT_KEYS, TextPart, TokenUsageCounts, ToolPart, ToolState, addTokenUsage, consumeSSEStream, createStreamUsageExtractor, createUsageCallback, firstTokenCount, firstUsageCostUsd, genAiUsageAttributes, isFilePart, isReasoningPart, isTextPart, isToolPart, parseSSEData as parseSSEData$1, parseSSEStream, readTokenCostUsd, readTokenUsage, tokenCount, tokenUsageSource } from "@tangle-network/agent-core";
4
4
 
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as parseServerTiming } from "./server-timing-CTGu_pos.mjs";
1
+ import { c as parseServerTiming } from "./server-timing-HI-hXI39.mjs";
2
2
  import { ORCHESTRATOR_HOP_ID_HEADER, PROVISION_TRACE_ID_HEADER, PTID_PREFIX, SpanRecorder, isAdoptablePtid, mintPtid, monotonicNs, readOrMintPtid, spanDurationMs } from "./stage-span.mjs";
3
3
  import { GEN_AI_CONVERSATION_ID, GEN_AI_CONVERSATION_ID as GEN_AI_CONVERSATION_ID$1, GEN_AI_INPUT_TOKEN_KEYS, GEN_AI_MODEL_KEYS, GEN_AI_OPERATION_NAME, GEN_AI_OPERATION_NAME as GEN_AI_OPERATION_NAME$1, GEN_AI_OUTPUT_TOKEN_KEYS, GEN_AI_REQUEST_MODEL, GEN_AI_REQUEST_MODEL as GEN_AI_REQUEST_MODEL$1, GEN_AI_RESPONSE_MODEL, GEN_AI_RESPONSE_MODEL as GEN_AI_RESPONSE_MODEL$1, GEN_AI_USAGE_INPUT_TOKENS, GEN_AI_USAGE_INPUT_TOKENS as GEN_AI_USAGE_INPUT_TOKENS$1, GEN_AI_USAGE_OUTPUT_TOKENS, GEN_AI_USAGE_OUTPUT_TOKENS as GEN_AI_USAGE_OUTPUT_TOKENS$1, SSEChunkParser, StreamUsageExtractor, TOKEN_USAGE_COST_KEYS, TOKEN_USAGE_INPUT_KEYS, TOKEN_USAGE_OUTPUT_KEYS, addTokenUsage, consumeSSEStream, createStreamUsageExtractor, createUsageCallback, firstTokenCount, firstUsageCostUsd, genAiUsageAttributes, isFilePart, isReasoningPart, isTextPart, isToolPart, parseSSEData as parseSSEData$1, parseSSEStream, readTokenCostUsd, readTokenUsage, tokenCount, tokenUsageSource } from "@tangle-network/agent-core";
4
4
  //#region src/enrichment/parse.ts
@@ -0,0 +1,235 @@
1
+ //#region src/lifecycle-wall.d.ts
2
+ /**
3
+ * Per-flow shape of the accounting window. `totalOperation` is the span whose
4
+ * wall the named leaves must tile; `postReadyOperations` run AFTER it is
5
+ * stamped (excluded from the leaf sum); `prepUmbrella` is the optional
6
+ * create-style split of an entry umbrella minus its measured leaf children. Absent
7
+ * `prepUmbrella` ⇒ `prepUnaccountedMs` is always 0 and the whole dark falls
8
+ * into `unaccountedMs` (the shape every non-create flow uses).
9
+ */
10
+ type FlowAccountingSpec = {
11
+ totalOperation: string;
12
+ postReadyOperations?: ReadonlySet<string>;
13
+ prepUmbrella?: {
14
+ operation: string;
15
+ };
16
+ };
17
+ declare const CREATE_ACCOUNTING_SPEC: FlowAccountingSpec;
18
+ declare const RESUME_ACCOUNTING_SPEC: FlowAccountingSpec;
19
+ declare const STOP_ACCOUNTING_SPEC: FlowAccountingSpec;
20
+ declare const DELETE_ACCOUNTING_SPEC: FlowAccountingSpec;
21
+ interface LifecycleStageTiming {
22
+ operation: string;
23
+ durationMs?: number;
24
+ parent?: string | null;
25
+ }
26
+ type Values = Readonly<Record<string, number>>;
27
+ interface LifecycleWallSample {
28
+ wallMs: number;
29
+ httpMs: number;
30
+ hops?: Values;
31
+ spanOps?: readonly LifecycleStageTiming[];
32
+ spanLeaves?: Values;
33
+ spanTotalMs?: number | null;
34
+ orchStages?: Values | null;
35
+ jobPhases?: Values | null;
36
+ jobMs?: number | null;
37
+ settleMs?: number | null;
38
+ spanAccountedMs?: number;
39
+ }
40
+ interface LifecycleWallFlow extends Partial<FlowAccountingSpec> {
41
+ workerTotalHop: string;
42
+ addPreHandler: boolean;
43
+ settleHop?: string;
44
+ workerNamedHops?: readonly string[];
45
+ }
46
+ /**
47
+ * A flat `{name: ms}` ledger read as the tree its names describe.
48
+ *
49
+ * Every producer in this repo emits nested stages FLAT, with the containment
50
+ * in the name: `capture.<hostPhase>` and `capture.restic_<phase>` inside
51
+ * `capture` (snapshot-helpers.ts), `materialize.parentRead|precreate|
52
+ * branchComplete|host.*|child.*|residual` inside `materialize` (branch.ts),
53
+ * `delete.<hostPhase>` inside `delete` and `restore_workspace.<phase>` inside
54
+ * `restore_workspace` (snapshots.ts). Summing every entry as a sibling counts
55
+ * the children inside their parent a second time and reports a wall the
56
+ * orchestrator never spent.
57
+ *
58
+ * So a dotted name is NEVER top-level. It attaches to the longest prefix that
59
+ * exists as a stage; when no prefix exists — the restore job's `host.<phase>`,
60
+ * which the queue records inside `restore_workspace` without naming it
61
+ * (snapshot-job-queue.ts:394) — it is still excluded from the top-level sum
62
+ * and reported as a child of the ledger at large. Excluding it can only leave
63
+ * MORE time unnamed, never fabricate a reconciliation.
64
+ */
65
+ declare function stageTree(stages: Readonly<Record<string, number>>): {
66
+ nodes: {
67
+ name: string;
68
+ ms: number;
69
+ parent: string | null;
70
+ }[];
71
+ topLevel: {
72
+ name: string;
73
+ ms: number;
74
+ parent: string | null;
75
+ }[]; /** Children whose declared parent is not in the ledger; never summed. */
76
+ orphans: {
77
+ name: string;
78
+ ms: number;
79
+ parent: string | null;
80
+ }[];
81
+ topLevelMs: number;
82
+ };
83
+ /** Parent operations contain their descendants and are never counted as leaves. */
84
+ declare function parentOperations(operations: readonly LifecycleStageTiming[]): ReadonlySet<string>;
85
+ /**
86
+ * The measured leaves of one response's span tree, per the flow's own spec.
87
+ *
88
+ * Identical rule to the orchestrator's `computeFlowAccountingResiduals`: drop
89
+ * the total span (it is the window), drop the spans stamped after it closes,
90
+ * and drop any span another span names as its parent (a parent re-measures its
91
+ * children). What is left sums to the window minus its named residual.
92
+ */
93
+ declare function leafOperations<T extends LifecycleStageTiming>(operations: readonly T[], excluded?: ReadonlySet<string>, parents?: ReadonlySet<string>): (T & {
94
+ durationMs: number;
95
+ })[];
96
+ declare function operationLeafDurations(operations: readonly LifecycleStageTiming[], excluded?: ReadonlySet<string>): Map<string, number>;
97
+ /**
98
+ * Partition one input before aggregation: null is unavailable; a negative
99
+ * residual is overlapping evidence, never an instruction to publish zero.
100
+ * Callers retain their population grouping, medians and display labels.
101
+ */
102
+ declare function partitionLifecycleWalls(sample: LifecycleWallSample, flow: LifecycleWallFlow): {
103
+ wallMs: number;
104
+ httpMs: number;
105
+ workerWallMs: number | null;
106
+ roundTripMs: number | null;
107
+ orchServerMs: number | null;
108
+ orchIncludesTransport: boolean;
109
+ workerIncludesTransport: boolean;
110
+ terms: {
111
+ edge: number | null;
112
+ worker: number | null;
113
+ transport: number | null;
114
+ orch: number | null;
115
+ job: number | null;
116
+ settle: number | null;
117
+ dark: number;
118
+ };
119
+ workerUnattributedMs: number | null;
120
+ orchUnattributedMs: number | null;
121
+ jobUnattributedMs: number | null;
122
+ unnamedMs: number;
123
+ unnamedShare: number;
124
+ overcountMs: number;
125
+ spanLeaves: {
126
+ [k: string]: number;
127
+ };
128
+ workerStages: {
129
+ [k: string]: number;
130
+ };
131
+ orchTree: {
132
+ nodes: {
133
+ name: string;
134
+ ms: number;
135
+ parent: string | null;
136
+ }[];
137
+ topLevel: {
138
+ name: string;
139
+ ms: number;
140
+ parent: string | null;
141
+ }[]; /** Children whose declared parent is not in the ledger; never summed. */
142
+ orphans: {
143
+ name: string;
144
+ ms: number;
145
+ parent: string | null;
146
+ }[];
147
+ topLevelMs: number;
148
+ };
149
+ jobTree: {
150
+ nodes: {
151
+ name: string;
152
+ ms: number;
153
+ parent: string | null;
154
+ }[];
155
+ topLevel: {
156
+ name: string;
157
+ ms: number;
158
+ parent: string | null;
159
+ }[]; /** Children whose declared parent is not in the ledger; never summed. */
160
+ orphans: {
161
+ name: string;
162
+ ms: number;
163
+ parent: string | null;
164
+ }[];
165
+ topLevelMs: number;
166
+ };
167
+ spanTotalMs: number | null;
168
+ window: {
169
+ transportMs: number | null;
170
+ afterSpanMs: number | null;
171
+ outerMs: number | null;
172
+ workerUnattributedMs: number | null;
173
+ workerOwnMs: number | null;
174
+ gaps: {
175
+ overlapMs: number;
176
+ underTileMs: number;
177
+ workerOverlapMs: number;
178
+ unrowedMs: number;
179
+ clampedMs: number;
180
+ };
181
+ };
182
+ };
183
+ //#endregion
184
+ //#region src/create-wall.d.ts
185
+ /** Exclusive create-request wall phases; nested service spans are a separate view. */
186
+ declare const CREATE_WALL_PHASES: readonly ["middleware", "identity", "preflight", "tenantCoordination", "configuration", "leaseSelection", "credentialJournal", "quotaReservation", "orchestrator", "provisionResponse", "responseBody", "credentialAllocation", "postCreate", "response"];
187
+ type CreateWallPhase = (typeof CREATE_WALL_PHASES)[number];
188
+ type CreateWallPhases = Record<CreateWallPhase, number>;
189
+ interface CreateWallMeasurement {
190
+ phases: CreateWallPhases;
191
+ totalMs: number;
192
+ /** Includes middleware/auth, preserving the original bookkeeping + post budget. */
193
+ bookkeepingPostCreateMs: number;
194
+ }
195
+ /** The original other-Worker + post-create budget, including auth/middleware. */
196
+ declare function createBookkeepingPostWall(phases: CreateWallPhases): number;
197
+ /**
198
+ * One cursor owned by the sequential request path. Parallel operations keep
199
+ * their own spans and never transition this cursor from their callbacks.
200
+ * Invalid clocks or missing caller hooks withhold a complete measurement.
201
+ */
202
+ declare function createWallTiming(startedAt: number): {
203
+ phase(name: CreateWallPhase, at: number): void;
204
+ finish(receivedAt: number, respondedAt: number): CreateWallMeasurement | null;
205
+ };
206
+ /** Read the already-parsed header. Historical/incomplete/overlapping rows stay unknown. */
207
+ declare function readCreateWallTiming(stages: Readonly<Record<string, number>>): CreateWallMeasurement | null;
208
+ //#endregion
209
+ //#region src/server-timing-parser.d.mts
210
+ interface ServerTimingEntry {
211
+ name: string;
212
+ dur?: number;
213
+ desc?: string;
214
+ }
215
+ declare function parseServerTiming(header: string | null | undefined): ServerTimingEntry[];
216
+ declare function parseServerTimingDurations(header: string | null | undefined): Record<string, number>;
217
+ declare const PLATFORM_VERDICT_REUSE_REASONS: readonly ["entry_changed", "refusal_observed", "current_compliance", "negative_age", "retention_elapsed", "key_expired", "feed_missing", "feed_stale", "feed_generation", "dependencies_empty", "dependency_revision", "dependency_floor", "grant_missing", "grant_unreadable", "grant_shape", "grant_negative_age", "grant_retention_elapsed", "shared_refusal_observed", "shared_refusal_unreadable", "shared_read_unavailable", "grant_invalid", "grant_validation", "verification_inflight", "feed_contradiction", "current_required", "lkg_retention_elapsed"];
218
+ type PlatformVerdictReuseRejection = (typeof PLATFORM_VERDICT_REUSE_REASONS)[number];
219
+ declare const HTTP_REQUEST_PHASE_NAMES: readonly ["external.provision", "benchmarks.records.load", "benchmarks.records.build", "benchmarks.records.page", "benchmarks.records.json", "admission.host.list", "host.records.ready", "host.records.scan", "host.records.read", "host.records.metadata", "host.records.project", "host.records.retry", "admission.metadata", "admission.json", "observability.refresh.wait", "fleet.sidecars", "native-export.snapshot.wait", "native-export.prepare.wait", "native-export.collect.wait", "scorecard.fleet.wait", "scorecard.capacity.wait", "scorecard.coverage.wait", "scorecard.compose", "scorecard.json", "proxy.model_refresh", "proxy.hub.lock_wait", "proxy.hub.refresh", "proxy.hub.state", "proxy.hub.proof", "proxy.hub.delivery", "proxy.runtime_token", "snapshot.delete.lock", "snapshot.delete.credentials", "snapshot.delete.list", "snapshot.delete.generation"];
220
+ type HttpRequestPhaseName = (typeof HTTP_REQUEST_PHASE_NAMES)[number];
221
+ declare function httpRequestPhaseFromTimingName(name: string): HttpRequestPhaseName | undefined;
222
+ declare const PLATFORM_VERDICT_SCOPE_CLASSES: readonly ["key", "identity", "owner_user", "owner_team", "lineage", "other"];
223
+ declare const PLATFORM_VERDICT_EVIDENCE_ORDERS: readonly ["feed_before_observation", "feed_at_observation", "feed_after_observation", "unknown"];
224
+ type PlatformVerdictDependencyMismatch = {
225
+ scopeClass: (typeof PLATFORM_VERDICT_SCOPE_CLASSES)[number];
226
+ evidenceOrder: (typeof PLATFORM_VERDICT_EVIDENCE_ORDERS)[number];
227
+ };
228
+ declare function createUpstreamHttpPhaseProjection(): {
229
+ absorb(header: unknown): void;
230
+ entries(): string[];
231
+ };
232
+ declare const HTTP_PHASE_COVERAGE_FIELDS: readonly ["stored", "emitted", "omitted", "invalid", "collisions", "headerDropped"];
233
+ //#endregion
234
+ export { parentOperations as A, FlowAccountingSpec as C, STOP_ACCOUNTING_SPEC as D, RESUME_ACCOUNTING_SPEC as E, stageTree as M, leafOperations as O, DELETE_ACCOUNTING_SPEC as S, LifecycleWallSample as T, CreateWallPhases as _, PLATFORM_VERDICT_REUSE_REASONS as a, readCreateWallTiming as b, PlatformVerdictReuseRejection as c, httpRequestPhaseFromTimingName as d, parseServerTiming as f, CreateWallPhase as g, CreateWallMeasurement as h, PLATFORM_VERDICT_EVIDENCE_ORDERS as i, partitionLifecycleWalls as j, operationLeafDurations as k, ServerTimingEntry as l, CREATE_WALL_PHASES as m, HTTP_REQUEST_PHASE_NAMES as n, PLATFORM_VERDICT_SCOPE_CLASSES as o, parseServerTimingDurations as p, HttpRequestPhaseName as r, PlatformVerdictDependencyMismatch as s, HTTP_PHASE_COVERAGE_FIELDS as t, createUpstreamHttpPhaseProjection as u, createBookkeepingPostWall as v, LifecycleWallFlow as w, CREATE_ACCOUNTING_SPEC as x, createWallTiming as y };
235
+ //# sourceMappingURL=server-timing-CE4vurML.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-timing-CE4vurML.d.mts","names":["ServerTimingEntry","name","dur","desc","parseServerTiming","header","parseServerTimingDurations","Record","PLATFORM_VERDICT_REUSE_REASONS","PlatformVerdictReuseRejection","HTTP_REQUEST_PHASE_NAMES","HttpRequestPhaseName","httpRequestPhaseFromTimingName","PLATFORM_VERDICT_SCOPE_CLASSES","PLATFORM_VERDICT_EVIDENCE_ORDERS","PlatformVerdictDependencyMismatch","scopeClass","evidenceOrder","createUpstreamHttpPhaseProjection","absorb","entries","HTTP_PHASE_COVERAGE_FIELDS"],"sources":["../src/lifecycle-wall.ts","../src/create-wall.ts","../src/server-timing-parser.d.mts"],"mappings":";;AAoBA;;;;;;;KAAY,kBAAA;EACV,cAAA;EACA,mBAAA,GAAsB,WAAA;EACtB,YAAA;IAAiB,SAAA;EAAA;AAAA;AAAA,cAGN,sBAAA,EAAwB,kBAAA;AAAA,cAQxB,sBAAA,EAAwB,kBAAA;AAAA,cAcxB,oBAAA,EAAsB,kBAAA;AAAA,cAItB,sBAAA,EAAwB,kBAAA;AAAA,UAIpB,oBAAA;EACf,SAAA;EACA,UAAA;EACA,MAAA;AAAA;AAAA,KAEG,MAAA,GAAS,QAAA,CAAS,MAAA;AAAA,UACN,mBAAA;EACf,MAAA;EACA,MAAA;EACA,IAAA,GAAO,MAAA;EACP,OAAA,YAAmB,oBAAA;EACnB,UAAA,GAAa,MAAA;EACb,WAAA;EACA,UAAA,GAAa,MAAA;EACb,SAAA,GAAY,MAAA;EACZ,KAAA;EACA,QAAA;EACA,eAAA;AAAA;AAAA,UAEe,iBAAA,SAA0B,OAAA,CAAQ,kBAAA;EACjD,cAAA;EACA,aAAA;EACA,SAAA;EACA,eAAA;AAAA;;;AAjBF;;;;;;;;;;;;;;;;;iBAuCgB,SAAA,CAAU,MAAA,EAAQ,QAAA,CAAS,MAAA;;;;;;;;;;OA1B1B;;;;;;;;;iBAuED,gBAAA,CACd,UAAA,WAAqB,oBAAA,KACpB,WAAA;;;AA/CH;;;;;;iBA+DgB,cAAA,WAAyB,oBAAA,CAAA,CACvC,UAAA,WAAqB,CAAA,IACrB,QAAA,GAAU,WAAA,UACV,OAAA,GAAO,WAAA,YAA+B,CAAA;;;iBAWxB,sBAAA,CACd,UAAA,WAAqB,oBAAA,IACrB,QAAA,GAAU,WAAA,WAA+B,GAAA;;;;;;iBAoB3B,uBAAA,CACd,MAAA,EAAQ,mBAAA,EACR,IAAA,EAAM,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAxB8B;;;;;;;;;;;;;;;;;;SAwB9B;;;;;;;;;;;;;;;;;;;;;;;;;;;cCzMK,kBAAA;AAAA,KAiBD,eAAA,WAA0B,kBAAA;AAAA,KAC1B,gBAAA,GAAmB,MAAA,CAAO,eAAA;AAAA,UACrB,qBAAA;EACf,MAAA,EAAQ,gBAAA;EACR,OAAA;EDAsB;ECEtB,uBAAA;AAAA;;iBAWc,yBAAA,CAA0B,MAAA,EAAQ,gBAAA;ADTlD;;;;;AAAA,iBCuBgB,gBAAA,CAAiB,SAAA;cAUjB,eAAA,EAAe,EAAA;6BAWP,WAAA,WAEjB,qBAAA;AAAA;;iBA6BS,oBAAA,CACd,MAAA,EAAQ,QAAA,CAAS,MAAA,oBAChB,qBAAA;;;UCvGcA,iBAAAA;EACfC,IAAAA;EACAC,GAAAA;EACAC,IAAAA;AAAAA;AAAAA,iBAGcC,iBAAAA,CACdC,MAAAA,8BACCL,iBAAAA;AAAAA,iBAEaM,0BAAAA,CACdD,MAAAA,8BACCE,MAAAA;AAAAA,cAEUC,8BAAAA;AAAAA,KA4BDC,6BAAAA,WACFD,8BAAAA;AAAAA,cAEGE,wBAAAA;AAAAA,KAqCDC,oBAAAA,WAA+BD,wBAAAA;AAAAA,iBAC3BE,8BAAAA,CACdX,IAAAA,WACCU,oBAAAA;AAAAA,cACUE,8BAAAA;AAAAA,cAQAC,gCAAAA;AAAAA,KAMDC,iCAAAA;EACVC,UAAAA,UAAoBH,8BAAAA;EACpBI,aAAAA,UAAuBH,gCAAAA;AAAAA;AAAAA,iBAGTI,iCAAAA,CAAAA;EACdC,MAAAA,CAAOd,MAAAA;EACPe,OAAAA;AAAAA;AAAAA,cAGWC,0BAAAA"}