@vinhnt-sdk/trace 0.1.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nguyen Thanh Vinh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module trace
3
+ * Observability — OpenTelemetry-compatible spans, timeline replay, telemetry aggregation.
4
+ *
5
+ * Capability Seam:
6
+ * Tracing (SpanRecorder, createSpan) → Consumer (core kernel, step-executor)
7
+ * Timeline (Timeline, buildTranscript) → Consumer (session, UI)
8
+ * Telemetry (TokenMeter, calculateCost) → Consumer (core kernel, model-caller)
9
+ */
10
+ export { SpanRecorder, createSpan, endSpan, addSpanEvent, generateTraceId, } from "./tracing.js";
11
+ export type { Span, SpanKind, SpanStatus, SpanEvent, SpanNode, TraceContext } from "./tracing.js";
12
+ export { Timeline, buildTranscript } from "./timeline.js";
13
+ export type { TimelineEvent, TimelineEventType, TranscriptEntry } from "./timeline.js";
14
+ export { CostMeter, calculateCost, calculateContextPressure, MODEL_PRICING } from "./telemetry.js";
15
+ export type { UsageStats, ModelPricing, ContextPressure } from "./telemetry.js";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACL,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAC/C,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGlG,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1D,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGvF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACnG,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module trace
3
+ * Observability — OpenTelemetry-compatible spans, timeline replay, telemetry aggregation.
4
+ *
5
+ * Capability Seam:
6
+ * Tracing (SpanRecorder, createSpan) → Consumer (core kernel, step-executor)
7
+ * Timeline (Timeline, buildTranscript) → Consumer (session, UI)
8
+ * Telemetry (TokenMeter, calculateCost) → Consumer (core kernel, model-caller)
9
+ */
10
+ // ── Tracing ──
11
+ export { SpanRecorder, createSpan, endSpan, addSpanEvent, generateTraceId, } from "./tracing.js";
12
+ // ── Timeline ──
13
+ export { Timeline, buildTranscript } from "./timeline.js";
14
+ // ── Telemetry ──
15
+ export { CostMeter, calculateCost, calculateContextPressure, MODEL_PRICING } from "./telemetry.js";
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,gBAAgB;AAChB,OAAO,EACL,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAC/C,eAAe,GAChB,MAAM,cAAc,CAAC;AAGtB,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG1D,kBAAkB;AAClB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Telemetry — usage aggregation, cost tracking, context pressure monitoring.
3
+ *
4
+ * Aggregates usage per session/provider/model and tracks token costs.
5
+ */
6
+ /** Usage statistics for a single operation */
7
+ export interface UsageStats {
8
+ /** Input tokens consumed */
9
+ inputTokens: number;
10
+ /** Output tokens generated */
11
+ outputTokens: number;
12
+ /** Total tokens (input + output) */
13
+ totalTokens: number;
14
+ /** Estimated cost in USD */
15
+ costUsd: number;
16
+ }
17
+ /** Model pricing per 1M tokens (USD) */
18
+ export interface ModelPricing {
19
+ /** Cost per 1M input tokens */
20
+ inputPer1M: number;
21
+ /** Cost per 1M output tokens */
22
+ outputPer1M: number;
23
+ }
24
+ /** Known model pricing (as of 2026) */
25
+ export declare const MODEL_PRICING: Record<string, ModelPricing>;
26
+ /**
27
+ * Calculate cost from token counts.
28
+ */
29
+ export declare function calculateCost(inputTokens: number, outputTokens: number, pricing?: ModelPricing): number;
30
+ /**
31
+ * Cost meter — tracks token usage and cost across operations.
32
+ * Named differently from llm/TokenMeter to clarify purpose:
33
+ * - llm/TokenMeter: heuristic token estimation for request sizing
34
+ * - trace/CostMeter: actual usage tracking and cost aggregation
35
+ */
36
+ export declare class CostMeter {
37
+ private totalInput;
38
+ private totalOutput;
39
+ private readonly operations;
40
+ /** Record a token usage event */
41
+ record(inputTokens: number, outputTokens: number, modelId?: string): UsageStats;
42
+ /** Get total usage */
43
+ getTotal(): UsageStats;
44
+ /** Get operation count */
45
+ getOperationCount(): number;
46
+ /** Get all operation stats */
47
+ getOperations(): readonly UsageStats[];
48
+ /** Reset the meter */
49
+ reset(): void;
50
+ }
51
+ /**
52
+ * Context pressure — monitors context window usage.
53
+ */
54
+ export interface ContextPressure {
55
+ /** Current context tokens */
56
+ currentTokens: number;
57
+ /** Maximum context window */
58
+ maxTokens: number;
59
+ /** Pressure ratio (0.0 = empty, 1.0 = full) */
60
+ pressure: number;
61
+ /** Whether compaction is recommended */
62
+ shouldCompact: boolean;
63
+ readonly metadata?: Record<string, unknown>;
64
+ }
65
+ /**
66
+ * Calculate context pressure.
67
+ */
68
+ export declare function calculateContextPressure(currentTokens: number, maxTokens: number, compactThreshold?: number): ContextPressure;
69
+ //# sourceMappingURL=telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,8CAA8C;AAC9C,MAAM,WAAW,UAAU;IACzB,4BAA4B;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,8BAA8B;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wCAAwC;AACxC,MAAM,WAAW,YAAY;IAC3B,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,WAAW,EAAE,MAAM,CAAC;CACrB;AAQD,uCAAuC;AACvC,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAOtD,CAAC;AAEF;;GAEG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,YAA8B,GACtC,MAAM,CAIR;AAED;;;;;GAKG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAE/C,iCAAiC;IACjC,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU;IAe/E,sBAAsB;IACtB,QAAQ,IAAI,UAAU;IAUtB,0BAA0B;IAC1B,iBAAiB,IAAI,MAAM;IAI3B,8BAA8B;IAC9B,aAAa,IAAI,SAAS,UAAU,EAAE;IAItC,sBAAsB;IACtB,KAAK,IAAI,IAAI;CAKd;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,wCAAwC;IACxC,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,gBAAgB,SAAM,GACrB,eAAe,CAQjB"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Telemetry — usage aggregation, cost tracking, context pressure monitoring.
3
+ *
4
+ * Aggregates usage per session/provider/model and tracks token costs.
5
+ */
6
+ /** Default pricing — zero cost (override with actual pricing) */
7
+ const DEFAULT_PRICING = {
8
+ inputPer1M: 0,
9
+ outputPer1M: 0,
10
+ };
11
+ /** Known model pricing (as of 2026) */
12
+ export const MODEL_PRICING = {
13
+ "deepseek-chat": { inputPer1M: 0.27, outputPer1M: 1.10 },
14
+ "deepseek-reasoner": { inputPer1M: 0.55, outputPer1M: 2.19 },
15
+ "gpt-4o": { inputPer1M: 2.50, outputPer1M: 10.00 },
16
+ "gpt-4o-mini": { inputPer1M: 0.15, outputPer1M: 0.60 },
17
+ "claude-sonnet-4-20250514": { inputPer1M: 3.00, outputPer1M: 15.00 },
18
+ "claude-haiku-4-20250414": { inputPer1M: 0.80, outputPer1M: 4.00 },
19
+ };
20
+ /**
21
+ * Calculate cost from token counts.
22
+ */
23
+ export function calculateCost(inputTokens, outputTokens, pricing = DEFAULT_PRICING) {
24
+ const inputCost = (inputTokens / 1_000_000) * pricing.inputPer1M;
25
+ const outputCost = (outputTokens / 1_000_000) * pricing.outputPer1M;
26
+ return inputCost + outputCost;
27
+ }
28
+ /**
29
+ * Cost meter — tracks token usage and cost across operations.
30
+ * Named differently from llm/TokenMeter to clarify purpose:
31
+ * - llm/TokenMeter: heuristic token estimation for request sizing
32
+ * - trace/CostMeter: actual usage tracking and cost aggregation
33
+ */
34
+ export class CostMeter {
35
+ totalInput = 0;
36
+ totalOutput = 0;
37
+ operations = [];
38
+ /** Record a token usage event */
39
+ record(inputTokens, outputTokens, modelId) {
40
+ const pricing = modelId ? MODEL_PRICING[modelId] : undefined;
41
+ const costUsd = calculateCost(inputTokens, outputTokens, pricing);
42
+ const stats = {
43
+ inputTokens,
44
+ outputTokens,
45
+ totalTokens: inputTokens + outputTokens,
46
+ costUsd,
47
+ };
48
+ this.totalInput += inputTokens;
49
+ this.totalOutput += outputTokens;
50
+ this.operations.push(stats);
51
+ return stats;
52
+ }
53
+ /** Get total usage */
54
+ getTotal() {
55
+ const totalCost = this.operations.reduce((sum, op) => sum + op.costUsd, 0);
56
+ return {
57
+ inputTokens: this.totalInput,
58
+ outputTokens: this.totalOutput,
59
+ totalTokens: this.totalInput + this.totalOutput,
60
+ costUsd: totalCost,
61
+ };
62
+ }
63
+ /** Get operation count */
64
+ getOperationCount() {
65
+ return this.operations.length;
66
+ }
67
+ /** Get all operation stats */
68
+ getOperations() {
69
+ return [...this.operations];
70
+ }
71
+ /** Reset the meter */
72
+ reset() {
73
+ this.totalInput = 0;
74
+ this.totalOutput = 0;
75
+ this.operations.length = 0;
76
+ }
77
+ }
78
+ /**
79
+ * Calculate context pressure.
80
+ */
81
+ export function calculateContextPressure(currentTokens, maxTokens, compactThreshold = 0.8) {
82
+ const pressure = maxTokens > 0 ? currentTokens / maxTokens : 0;
83
+ return {
84
+ currentTokens,
85
+ maxTokens,
86
+ pressure,
87
+ shouldCompact: pressure >= compactThreshold,
88
+ };
89
+ }
90
+ //# sourceMappingURL=telemetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAsBH,iEAAiE;AACjE,MAAM,eAAe,GAAiB;IACpC,UAAU,EAAE,CAAC;IACb,WAAW,EAAE,CAAC;CACf,CAAC;AAEF,uCAAuC;AACvC,MAAM,CAAC,MAAM,aAAa,GAAiC;IACzD,eAAe,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE;IACxD,mBAAmB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE;IAC5D,QAAQ,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE;IAClD,aAAa,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE;IACtD,0BAA0B,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE;IACpE,yBAAyB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE;CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,WAAmB,EACnB,YAAoB,EACpB,UAAwB,eAAe;IAE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ACnB,CAAC;IACJ,CAAC;IAED,0BAA0B;IAC1B,iBAAiB;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IAChC,CAAC;IAED,8BAA8B;IAC9B,aAAa;QACX,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IAED,sBAAsB;IACtB,KAAK;QACH,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;IAC7B,CAAC;CACF;AAiBD;;GAEG;AACH,MAAM,UAAU,wBAAwB,CACtC,aAAqB,EACrB,SAAiB,EACjB,gBAAgB,GAAG,GAAG;IAEtB,MAAM,QAAQ,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,OAAO;QACL,aAAa;QACb,SAAS;QACT,QAAQ;QACR,aAAa,EAAE,QAAQ,IAAI,gBAAgB;KAC5C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Timeline — session log IS the timeline.
3
+ *
4
+ * Full replay from durable events. Token-level replay fidelity
5
+ * via assistant/chunk events.
6
+ *
7
+ * The timeline is a linear sequence of events that can be replayed
8
+ * to reconstruct the full conversation history.
9
+ */
10
+ /** Timeline event types — maps to KnownRunEvent from schema */
11
+ export type TimelineEventType = "run.started" | "run.completed" | "run.failed" | "step.started" | "step.completed" | "step.failed" | "turn.started" | "turn.ended" | "tool.invoked" | "tool.completed" | "tool.failed" | "tool.cancelled" | "approval.asked" | "approval.decided" | "llm.retry" | "llm.retry_started" | "assistant.chunk" | "token.compressed" | "context.compressed" | "permission.asked" | "permission.decided";
12
+ /** A single timeline event */
13
+ export interface TimelineEvent {
14
+ /** Event type */
15
+ readonly type: TimelineEventType;
16
+ /** Timestamp (Unix ms) */
17
+ readonly timestampMs: number;
18
+ /** Event data (type-specific) */
19
+ readonly data: Record<string, unknown>;
20
+ /** Sequence number (monotonic within a session) */
21
+ readonly seq: number;
22
+ }
23
+ /**
24
+ * Timeline — ordered sequence of events for a session.
25
+ */
26
+ export declare class Timeline {
27
+ private readonly events;
28
+ private seq;
29
+ /** Record an event */
30
+ record(type: TimelineEventType, data: Record<string, unknown>): TimelineEvent;
31
+ /** Get all events */
32
+ getEvents(): readonly TimelineEvent[];
33
+ /** Get events filtered by type */
34
+ getEventsByType(type: TimelineEventType): readonly TimelineEvent[];
35
+ /** Get events in a time range */
36
+ getEventsInRange(startMs: number, endMs: number): readonly TimelineEvent[];
37
+ /** Get event count */
38
+ count(): number;
39
+ /** Get duration of the timeline */
40
+ getDurationMs(): number;
41
+ /** Replay events through a handler */
42
+ replay(handler: (event: TimelineEvent) => Promise<void>): Promise<void>;
43
+ /** Export events as JSON */
44
+ export(): TimelineEvent[];
45
+ /** Import events from JSON */
46
+ import(events: TimelineEvent[]): void;
47
+ }
48
+ /**
49
+ * Build a conversation transcript from timeline events.
50
+ * Extracts user messages, assistant responses, and tool calls.
51
+ */
52
+ export declare function buildTranscript(events: readonly TimelineEvent[]): TranscriptEntry[];
53
+ /** A single entry in a conversation transcript */
54
+ export interface TranscriptEntry {
55
+ type: "user" | "assistant" | "tool_call" | "tool_result";
56
+ content?: string;
57
+ toolName?: string;
58
+ input?: unknown;
59
+ output?: unknown;
60
+ timestampMs: number;
61
+ }
62
+ //# sourceMappingURL=timeline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../src/timeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,+DAA+D;AAC/D,MAAM,MAAM,iBAAiB,GACzB,aAAa,GACb,eAAe,GACf,YAAY,GACZ,cAAc,GACd,gBAAgB,GAChB,aAAa,GACb,cAAc,GACd,YAAY,GACZ,cAAc,GACd,gBAAgB,GAChB,aAAa,GACb,gBAAgB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;CAOtC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,GAAG,eAAe,EAAE,CAuCnF;AAED,kDAAkD;AAClD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,WAAW,GAAG,aAAa,CAAC;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Timeline — session log IS the timeline.
3
+ *
4
+ * Full replay from durable events. Token-level replay fidelity
5
+ * via assistant/chunk events.
6
+ *
7
+ * The timeline is a linear sequence of events that can be replayed
8
+ * to reconstruct the full conversation history.
9
+ */
10
+ /**
11
+ * Timeline — ordered sequence of events for a session.
12
+ */
13
+ export class Timeline {
14
+ events = [];
15
+ seq = 0;
16
+ /** Record an event */
17
+ record(type, data) {
18
+ const event = {
19
+ type,
20
+ timestampMs: Date.now(),
21
+ data,
22
+ seq: this.seq++,
23
+ };
24
+ this.events.push(event);
25
+ return event;
26
+ }
27
+ /** Get all events */
28
+ getEvents() {
29
+ return [...this.events];
30
+ }
31
+ /** Get events filtered by type */
32
+ getEventsByType(type) {
33
+ return this.events.filter((e) => e.type === type);
34
+ }
35
+ /** Get events in a time range */
36
+ getEventsInRange(startMs, endMs) {
37
+ return this.events.filter((e) => e.timestampMs >= startMs && e.timestampMs <= endMs);
38
+ }
39
+ /** Get event count */
40
+ count() {
41
+ return this.events.length;
42
+ }
43
+ /** Get duration of the timeline */
44
+ getDurationMs() {
45
+ if (this.events.length === 0)
46
+ return 0;
47
+ return this.events[this.events.length - 1].timestampMs - this.events[0].timestampMs;
48
+ }
49
+ /** Replay events through a handler */
50
+ async replay(handler) {
51
+ for (const event of this.events) {
52
+ await handler(event);
53
+ }
54
+ }
55
+ /** Export events as JSON */
56
+ export() {
57
+ return [...this.events];
58
+ }
59
+ /** Import events from JSON */
60
+ import(events) {
61
+ this.events.length = 0;
62
+ for (const event of events) {
63
+ this.events.push(event);
64
+ }
65
+ this.seq = Math.max(0, ...events.map((e) => e.seq)) + 1;
66
+ }
67
+ }
68
+ /**
69
+ * Build a conversation transcript from timeline events.
70
+ * Extracts user messages, assistant responses, and tool calls.
71
+ */
72
+ export function buildTranscript(events) {
73
+ const entries = [];
74
+ for (const event of events) {
75
+ switch (event.type) {
76
+ case "run.started":
77
+ entries.push({
78
+ type: "user",
79
+ content: event.data.prompt,
80
+ timestampMs: event.timestampMs,
81
+ });
82
+ break;
83
+ case "assistant.chunk":
84
+ entries.push({
85
+ type: "assistant",
86
+ content: event.data.content,
87
+ timestampMs: event.timestampMs,
88
+ });
89
+ break;
90
+ case "tool.invoked":
91
+ entries.push({
92
+ type: "tool_call",
93
+ toolName: event.data.toolName,
94
+ input: event.data.input,
95
+ timestampMs: event.timestampMs,
96
+ });
97
+ break;
98
+ case "tool.completed":
99
+ entries.push({
100
+ type: "tool_result",
101
+ toolName: event.data.toolName,
102
+ output: event.data.output,
103
+ timestampMs: event.timestampMs,
104
+ });
105
+ break;
106
+ }
107
+ }
108
+ return entries;
109
+ }
110
+ //# sourceMappingURL=timeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeline.js","sourceRoot":"","sources":["../src/timeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsCH;;GAEG;AACH,MAAM,OAAO,QAAQ;IACF,MAAM,GAAoB,EAAE,CAAC;IACtC,GAAG,GAAG,CAAC,CAAC;IAEhB,sBAAsB;IACtB,MAAM,CAAC,IAAuB,EAAE,IAA6B;QAC3D,MAAM,KAAK,GAAkB;YAC3B,IAAI;YACJ,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE;YACvB,IAAI;YACJ,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE;SA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AAO,CAAC,IAAI,CAAC;oBACX,IAAI,EAAE,aAAa;oBACnB,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,QAAkB;oBACvC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM;oBACzB,WAAW,EAAE,KAAK,CAAC,WAAW;iBAC/B,CAAC,CAAC;gBACH,MAAM;QACV,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Tracing — OpenTelemetry-compatible span model.
3
+ *
4
+ * Spans represent units of work (model call, tool execution, step, turn).
5
+ * They form a tree: parent span → child spans.
6
+ *
7
+ * This is a lightweight, zero-dependency implementation compatible with
8
+ * the OpenTelemetry span model but without requiring the OTel SDK.
9
+ */
10
+ /** Span status */
11
+ export type SpanStatus = "ok" | "error" | "cancelled";
12
+ /** A single trace span */
13
+ export interface Span {
14
+ /** Unique span ID */
15
+ readonly id: string;
16
+ /** Parent span ID (undefined for root spans) */
17
+ readonly parentId: string | undefined;
18
+ /** Span name (e.g., "llm.call", "tool.execute", "step") */
19
+ readonly name: string;
20
+ /** Span kind */
21
+ readonly kind: SpanKind;
22
+ /** Start time (Unix ms) */
23
+ readonly startTimeMs: number;
24
+ /** End time (Unix ms, 0 if still active) */
25
+ endTimeMs: number;
26
+ /** Span status */
27
+ status: SpanStatus;
28
+ /** Span attributes (key-value pairs) */
29
+ attributes: Record<string, unknown>;
30
+ /** Span events (timestamped annotations) */
31
+ events: SpanEvent[];
32
+ readonly metadata?: Record<string, unknown>;
33
+ }
34
+ /** Span kind */
35
+ export type SpanKind = "internal" | "client" | "server" | "producer" | "consumer";
36
+ /** A timestamped event within a span */
37
+ export interface SpanEvent {
38
+ name: string;
39
+ timestampMs: number;
40
+ attributes: Record<string, unknown>;
41
+ }
42
+ /** Trace context — passed through the call chain */
43
+ export interface TraceContext {
44
+ /** Root trace ID */
45
+ readonly traceId: string;
46
+ /** Current span */
47
+ readonly span: Span;
48
+ }
49
+ /** Generate a unique trace ID */
50
+ export declare function generateTraceId(): string;
51
+ /**
52
+ * Create a new span.
53
+ */
54
+ export declare function createSpan(name: string, kind: SpanKind, parentId?: string, traceId?: string): Span;
55
+ /**
56
+ * End a span with a status.
57
+ */
58
+ export declare function endSpan(span: Span, status?: SpanStatus): void;
59
+ /**
60
+ * Add an event to a span.
61
+ */
62
+ export declare function addSpanEvent(span: Span, name: string, attributes?: Record<string, unknown>): void;
63
+ /**
64
+ * A span recorder — collects spans and provides trace context.
65
+ */
66
+ export declare class SpanRecorder {
67
+ private readonly spans;
68
+ private readonly traceId;
69
+ constructor(traceId?: string);
70
+ /** Start a new span */
71
+ startSpan(name: string, kind: SpanKind, parentId?: string): Span;
72
+ /** End a span */
73
+ endSpan(span: Span, status?: SpanStatus): void;
74
+ /** Get all recorded spans */
75
+ getSpans(): readonly Span[];
76
+ /** Get span tree (root → children) */
77
+ getSpanTree(): SpanNode[];
78
+ /** Get total duration of the trace */
79
+ getTotalDurationMs(): number;
80
+ }
81
+ /** A node in the span tree */
82
+ export interface SpanNode {
83
+ span: Span;
84
+ children: SpanNode[];
85
+ }
86
+ //# sourceMappingURL=tracing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,kBAAkB;AAClB,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,OAAO,GAAG,WAAW,CAAC;AAEtD,0BAA0B;AAC1B,MAAM,WAAW,IAAI;IACnB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gBAAgB;IAChB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,2BAA2B;IAC3B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AI,CAMjG;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,CAAC,EAAE,MAAM;IAI5B,uBAAuB;IACvB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IAMhE,iBAAiB;IACjB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,UAAiB,GAAG,IAAI;IAIpD,6BAA6B;IAC7B,QAAQ,IAAI,SAAS,IAAI,EAAE;IAI3B,sCAAsC;IACtC,WAAW,IAAI,QAAQ,EAAE;IA0BzB,sCAAsC;IACtC,kBAAkB,IAAI,MAAM;CAM7B;AAED,8BAA8B;AAC9B,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Tracing — OpenTelemetry-compatible span model.
3
+ *
4
+ * Spans represent units of work (model call, tool execution, step, turn).
5
+ * They form a tree: parent span → child spans.
6
+ *
7
+ * This is a lightweight, zero-dependency implementation compatible with
8
+ * the OpenTelemetry span model but without requiring the OTel SDK.
9
+ */
10
+ let spanCounter = 0;
11
+ /** Generate a unique span ID */
12
+ function generateSpanId() {
13
+ return `span_${Date.now().toString(36)}_${(spanCounter++).toString(36)}`;
14
+ }
15
+ /** Generate a unique trace ID */
16
+ export function generateTraceId() {
17
+ return `trace_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
18
+ }
19
+ /**
20
+ * Create a new span.
21
+ */
22
+ export function createSpan(name, kind, parentId, traceId) {
23
+ return {
24
+ id: generateSpanId(),
25
+ parentId,
26
+ name,
27
+ kind,
28
+ startTimeMs: Date.now(),
29
+ endTimeMs: 0,
30
+ status: "ok",
31
+ attributes: {},
32
+ events: [],
33
+ };
34
+ }
35
+ /**
36
+ * End a span with a status.
37
+ */
38
+ export function endSpan(span, status = "ok") {
39
+ span.endTimeMs = Date.now();
40
+ span.status = status;
41
+ }
42
+ /**
43
+ * Add an event to a span.
44
+ */
45
+ export function addSpanEvent(span, name, attributes) {
46
+ span.events.push({
47
+ name,
48
+ timestampMs: Date.now(),
49
+ attributes: attributes ?? {},
50
+ });
51
+ }
52
+ /**
53
+ * A span recorder — collects spans and provides trace context.
54
+ */
55
+ export class SpanRecorder {
56
+ spans = [];
57
+ traceId;
58
+ constructor(traceId) {
59
+ this.traceId = traceId ?? generateTraceId();
60
+ }
61
+ /** Start a new span */
62
+ startSpan(name, kind, parentId) {
63
+ const span = createSpan(name, kind, parentId ?? this.spans[this.spans.length - 1]?.id, this.traceId);
64
+ this.spans.push(span);
65
+ return span;
66
+ }
67
+ /** End a span */
68
+ endSpan(span, status = "ok") {
69
+ endSpan(span, status);
70
+ }
71
+ /** Get all recorded spans */
72
+ getSpans() {
73
+ return [...this.spans];
74
+ }
75
+ /** Get span tree (root → children) */
76
+ getSpanTree() {
77
+ const spanMap = new Map();
78
+ const roots = [];
79
+ // Create nodes
80
+ for (const span of this.spans) {
81
+ spanMap.set(span.id, { span, children: [] });
82
+ }
83
+ // Build tree
84
+ for (const node of spanMap.values()) {
85
+ if (node.span.parentId) {
86
+ const parent = spanMap.get(node.span.parentId);
87
+ if (parent) {
88
+ parent.children.push(node);
89
+ }
90
+ else {
91
+ roots.push(node);
92
+ }
93
+ }
94
+ else {
95
+ roots.push(node);
96
+ }
97
+ }
98
+ return roots;
99
+ }
100
+ /** Get total duration of the trace */
101
+ getTotalDurationMs() {
102
+ if (this.spans.length === 0)
103
+ return 0;
104
+ const start = Math.min(...this.spans.map((s) => s.startTimeMs));
105
+ const end = Math.max(...this.spans.map((s) => s.endTimeMs || Date.now()));
106
+ return end - start;
107
+ }
108
+ }
109
+ //# sourceMappingURL=tracing.js.map
@@ -0,0 +1 @@
1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E,CAAC;gBACvB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC/C,IAAI,MAAM,EAAE,CAAC;oBACX,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC7B,CAAC;qBAAM,CAAC;oBACN,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACnB,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,sCAAsC;IACtC,kBAAkB;QAChB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,CAAC,CAAC;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;QAChE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAC1E,OAAO,GAAG,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@vinhnt-sdk/trace",
3
+ "version": "0.1.3",
4
+ "description": "Observability — OpenTelemetry spans, timeline replay, telemetry aggregation",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "LICENSE",
20
+ "README.md"
21
+ ],
22
+ "sideEffects": false,
23
+ "engines": {
24
+ "node": ">=20"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/vinhnt-develop/vinhnt-sdk.git",
29
+ "directory": "packages/trace"
30
+ },
31
+ "homepage": "https://github.com/vinhnt-develop/vinhnt-sdk/tree/main/packages/trace",
32
+ "bugs": {
33
+ "url": "https://github.com/vinhnt-develop/vinhnt-sdk/issues"
34
+ },
35
+ "keywords": [
36
+ "vnt",
37
+ "trace",
38
+ "opentelemetry",
39
+ "timeline",
40
+ "telemetry"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "dependencies": {
46
+ "@vinhnt-sdk/schema": "0.1.3"
47
+ },
48
+ "devDependencies": {
49
+ "vitest": "^3.2.7"
50
+ },
51
+ "scripts": {
52
+ "build": "tsc -b",
53
+ "typecheck": "tsc --noEmit",
54
+ "clean": "node -e \"try{require('fs').rmSync('dist',{recursive:true,force:true})}catch(e){}\" && node -e \"try{require('fs').rmSync('tsconfig.tsbuildinfo',{force:true})}catch(e){}\"",
55
+ "test": "vitest run",
56
+ "lint": "eslint ."
57
+ }
58
+ }