@tangle-network/sdk-telemetry 0.1.8
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 +11 -0
- package/README.md +24 -0
- package/dist/index.d.mts +968 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2170 -0
- package/dist/index.mjs.map +1 -0
- package/dist/stage-span.d.mts +139 -0
- package/dist/stage-span.d.mts.map +1 -0
- package/dist/stage-span.mjs +218 -0
- package/dist/stage-span.mjs.map +1 -0
- package/package.json +69 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,968 @@
|
|
|
1
|
+
import { LifecycleOp, PROVISION_TRACE_ID_HEADER, PTID_PREFIX, RecordOptions, ServerTimingEntry, SpanComponent, SpanRecorder, SpanStatus, StageSpan, StageSpanInput, isAdoptablePtid, mintPtid, monotonicNs, parseServerTiming, readOrMintPtid, spanDurationMs } from "./stage-span.mjs";
|
|
2
|
+
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, Storage, 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";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Telemetry Types
|
|
7
|
+
*
|
|
8
|
+
* Type definitions for usage tracking, credit management,
|
|
9
|
+
* and telemetry data collection.
|
|
10
|
+
*/
|
|
11
|
+
interface CreditBalance {
|
|
12
|
+
available: number;
|
|
13
|
+
used: number;
|
|
14
|
+
limit: number;
|
|
15
|
+
resetAt?: Date;
|
|
16
|
+
currency: "credits" | "usd" | "tokens";
|
|
17
|
+
}
|
|
18
|
+
interface CreditTransaction {
|
|
19
|
+
id: string;
|
|
20
|
+
type: "charge" | "refund" | "grant" | "adjustment";
|
|
21
|
+
amount: number;
|
|
22
|
+
balance: number;
|
|
23
|
+
description: string;
|
|
24
|
+
metadata?: Record<string, unknown>;
|
|
25
|
+
timestamp: Date;
|
|
26
|
+
}
|
|
27
|
+
interface UsageRecord {
|
|
28
|
+
id: string;
|
|
29
|
+
projectRef: string;
|
|
30
|
+
userId?: string;
|
|
31
|
+
operation: string;
|
|
32
|
+
credits: number;
|
|
33
|
+
durationMs?: number;
|
|
34
|
+
inputTokens?: number;
|
|
35
|
+
outputTokens?: number;
|
|
36
|
+
metadata?: Record<string, unknown>;
|
|
37
|
+
timestamp: Date;
|
|
38
|
+
}
|
|
39
|
+
interface UsageSummary {
|
|
40
|
+
projectRef: string;
|
|
41
|
+
period: "hour" | "day" | "week" | "month";
|
|
42
|
+
periodStart: Date;
|
|
43
|
+
periodEnd: Date;
|
|
44
|
+
totalCredits: number;
|
|
45
|
+
totalOperations: number;
|
|
46
|
+
totalDurationMs: number;
|
|
47
|
+
totalInputTokens: number;
|
|
48
|
+
totalOutputTokens: number;
|
|
49
|
+
operationBreakdown: Record<string, number>;
|
|
50
|
+
}
|
|
51
|
+
type TelemetryEventType = "session_start" | "session_end" | "api_request" | "api_response" | "agent_execution" | "error" | "performance" | "custom";
|
|
52
|
+
interface TelemetryEvent {
|
|
53
|
+
id: string;
|
|
54
|
+
type: TelemetryEventType;
|
|
55
|
+
name: string;
|
|
56
|
+
projectRef?: string;
|
|
57
|
+
sessionId?: string;
|
|
58
|
+
userId?: string;
|
|
59
|
+
data: Record<string, unknown>;
|
|
60
|
+
timestamp: Date;
|
|
61
|
+
sequence: number;
|
|
62
|
+
}
|
|
63
|
+
interface PerformanceMetric {
|
|
64
|
+
name: string;
|
|
65
|
+
value: number;
|
|
66
|
+
unit: "ms" | "bytes" | "count" | "percent";
|
|
67
|
+
tags?: Record<string, string>;
|
|
68
|
+
timestamp: Date;
|
|
69
|
+
}
|
|
70
|
+
interface TelemetryConfig {
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
projectRef?: string;
|
|
73
|
+
userId?: string;
|
|
74
|
+
sessionId?: string;
|
|
75
|
+
flushIntervalMs?: number;
|
|
76
|
+
maxBatchSize?: number;
|
|
77
|
+
maxQueueSize?: number;
|
|
78
|
+
endpoint?: string;
|
|
79
|
+
sampleRate?: number;
|
|
80
|
+
excludePatterns?: string[];
|
|
81
|
+
includeMetadata?: boolean;
|
|
82
|
+
persistOffline?: boolean;
|
|
83
|
+
}
|
|
84
|
+
interface CreditTrackerConfig {
|
|
85
|
+
projectRef: string;
|
|
86
|
+
userId?: string;
|
|
87
|
+
endpoint?: string;
|
|
88
|
+
refreshIntervalMs?: number;
|
|
89
|
+
warningThreshold?: number;
|
|
90
|
+
criticalThreshold?: number;
|
|
91
|
+
onLowBalance?: (balance: CreditBalance) => void;
|
|
92
|
+
onCriticalBalance?: (balance: CreditBalance) => void;
|
|
93
|
+
onBalanceUpdate?: (balance: CreditBalance) => void;
|
|
94
|
+
}
|
|
95
|
+
interface UsageTrackerConfig {
|
|
96
|
+
projectRef: string;
|
|
97
|
+
userId?: string;
|
|
98
|
+
autoTrack?: boolean;
|
|
99
|
+
trackApiCalls?: boolean;
|
|
100
|
+
trackAgentExecutions?: boolean;
|
|
101
|
+
trackErrors?: boolean;
|
|
102
|
+
batchSize?: number;
|
|
103
|
+
flushIntervalMs?: number;
|
|
104
|
+
}
|
|
105
|
+
interface TelemetrySink {
|
|
106
|
+
name: string;
|
|
107
|
+
send(events: TelemetryEvent[]): Promise<void>;
|
|
108
|
+
flush(): Promise<void>;
|
|
109
|
+
close(): Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
interface CreditProvider {
|
|
112
|
+
getBalance(): Promise<CreditBalance>;
|
|
113
|
+
getTransactions(options?: {
|
|
114
|
+
limit?: number;
|
|
115
|
+
offset?: number;
|
|
116
|
+
since?: Date;
|
|
117
|
+
}): Promise<CreditTransaction[]>;
|
|
118
|
+
checkCredit(amount: number): Promise<boolean>;
|
|
119
|
+
reserveCredit(amount: number): Promise<string | null>;
|
|
120
|
+
releaseReservation(reservationId: string): Promise<void>;
|
|
121
|
+
chargeReservation(reservationId: string, actualAmount?: number): Promise<CreditTransaction>;
|
|
122
|
+
}
|
|
123
|
+
interface UsageProvider {
|
|
124
|
+
recordUsage(record: Omit<UsageRecord, "id" | "timestamp">): Promise<string>;
|
|
125
|
+
getUsage(options?: {
|
|
126
|
+
projectRef?: string;
|
|
127
|
+
since?: Date;
|
|
128
|
+
until?: Date;
|
|
129
|
+
limit?: number;
|
|
130
|
+
}): Promise<UsageRecord[]>;
|
|
131
|
+
getSummary(projectRef: string, period: UsageSummary["period"]): Promise<UsageSummary>;
|
|
132
|
+
}
|
|
133
|
+
interface ApiMetric {
|
|
134
|
+
path: string;
|
|
135
|
+
method: string;
|
|
136
|
+
status: number;
|
|
137
|
+
durationMs: number;
|
|
138
|
+
requestSize?: number;
|
|
139
|
+
responseSize?: number;
|
|
140
|
+
error?: string;
|
|
141
|
+
timestamp: Date;
|
|
142
|
+
}
|
|
143
|
+
interface AgentMetric {
|
|
144
|
+
identifier: string;
|
|
145
|
+
projectRef: string;
|
|
146
|
+
executionId: string;
|
|
147
|
+
durationMs: number;
|
|
148
|
+
inputTokens?: number;
|
|
149
|
+
outputTokens?: number;
|
|
150
|
+
toolCalls?: number;
|
|
151
|
+
success: boolean;
|
|
152
|
+
error?: string;
|
|
153
|
+
timestamp: Date;
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/credits.d.ts
|
|
157
|
+
declare class CreditTracker {
|
|
158
|
+
private readonly config;
|
|
159
|
+
private readonly provider;
|
|
160
|
+
private readonly storage?;
|
|
161
|
+
private cachedBalance?;
|
|
162
|
+
private lastRefresh?;
|
|
163
|
+
private refreshTimer?;
|
|
164
|
+
private reservations;
|
|
165
|
+
constructor(config: CreditTrackerConfig, provider: CreditProvider, storage?: Storage);
|
|
166
|
+
getBalance(forceRefresh?: boolean): Promise<CreditBalance>;
|
|
167
|
+
getTransactions(options?: {
|
|
168
|
+
limit?: number;
|
|
169
|
+
offset?: number;
|
|
170
|
+
since?: Date;
|
|
171
|
+
}): Promise<CreditTransaction[]>;
|
|
172
|
+
hasCredits(amount: number): Promise<boolean>;
|
|
173
|
+
reserve(amount: number, options?: {
|
|
174
|
+
ttlMs?: number;
|
|
175
|
+
}): Promise<string | null>;
|
|
176
|
+
release(reservationId: string): Promise<void>;
|
|
177
|
+
charge(reservationId: string, actualAmount?: number): Promise<CreditTransaction>;
|
|
178
|
+
chargeImmediate(amount: number, _description: string): Promise<CreditTransaction | null>;
|
|
179
|
+
getReservedTotal(): number;
|
|
180
|
+
getEffectiveBalance(): number;
|
|
181
|
+
getUsagePercent(): number;
|
|
182
|
+
getRemainingPercent(): number;
|
|
183
|
+
isLow(): boolean;
|
|
184
|
+
isCritical(): boolean;
|
|
185
|
+
close(): Promise<void>;
|
|
186
|
+
private isStale;
|
|
187
|
+
private checkThresholds;
|
|
188
|
+
private cleanupExpiredReservations;
|
|
189
|
+
private startRefreshTimer;
|
|
190
|
+
private stopRefreshTimer;
|
|
191
|
+
}
|
|
192
|
+
declare class MemoryCreditProvider implements CreditProvider {
|
|
193
|
+
private balance;
|
|
194
|
+
private transactions;
|
|
195
|
+
private reservations;
|
|
196
|
+
constructor(initialBalance?: Partial<CreditBalance>);
|
|
197
|
+
getBalance(): Promise<CreditBalance>;
|
|
198
|
+
getTransactions(options?: {
|
|
199
|
+
limit?: number;
|
|
200
|
+
offset?: number;
|
|
201
|
+
since?: Date;
|
|
202
|
+
}): Promise<CreditTransaction[]>;
|
|
203
|
+
checkCredit(amount: number): Promise<boolean>;
|
|
204
|
+
reserveCredit(amount: number): Promise<string | null>;
|
|
205
|
+
releaseReservation(reservationId: string): Promise<void>;
|
|
206
|
+
chargeReservation(reservationId: string, actualAmount?: number): Promise<CreditTransaction>;
|
|
207
|
+
addCredits(amount: number, description: string): CreditTransaction;
|
|
208
|
+
}
|
|
209
|
+
declare function createCreditTracker(config: CreditTrackerConfig, provider: CreditProvider, storage?: Storage): CreditTracker;
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/enrichment/types.d.ts
|
|
212
|
+
/**
|
|
213
|
+
* Enrichment Types
|
|
214
|
+
*
|
|
215
|
+
* Types for client-forwarded metadata blobs and parsed enrichment context.
|
|
216
|
+
* Partners can send arbitrary metadata that gets parsed by registered adapters
|
|
217
|
+
* and attached to traces for analytics and tenant isolation.
|
|
218
|
+
*/
|
|
219
|
+
/** Supported blob formats for metadata transmission */
|
|
220
|
+
type MetadataBlobFormat = "json" | "msgpack" | "protobuf";
|
|
221
|
+
/** Client-forwarded metadata blob */
|
|
222
|
+
interface MetadataBlob {
|
|
223
|
+
/** Serialization format of the data */
|
|
224
|
+
format: MetadataBlobFormat;
|
|
225
|
+
/** Serialized data (base64 for binary formats) */
|
|
226
|
+
data: string | Buffer;
|
|
227
|
+
/** Optional schema identifier for validation */
|
|
228
|
+
schema?: string;
|
|
229
|
+
}
|
|
230
|
+
/** Product context for trace classification */
|
|
231
|
+
type ProductType = "vibe_coding" | "simulation" | "background_agent";
|
|
232
|
+
/** Environment context */
|
|
233
|
+
type EnvironmentType = "development" | "staging" | "production";
|
|
234
|
+
/** Subscription tier for rate limiting and feature gating */
|
|
235
|
+
type SubscriptionTier = "free" | "pro" | "enterprise";
|
|
236
|
+
/**
|
|
237
|
+
* Parsed enrichment context attached to traces.
|
|
238
|
+
* Built from partner metadata blobs via adapters.
|
|
239
|
+
*/
|
|
240
|
+
interface EnrichmentContext {
|
|
241
|
+
/** Partner identifier for tenant isolation */
|
|
242
|
+
partnerId?: string;
|
|
243
|
+
/** Subscription tier for rate limiting */
|
|
244
|
+
subscriptionTier?: SubscriptionTier;
|
|
245
|
+
/** End user identifier within partner's system */
|
|
246
|
+
endUserId?: string;
|
|
247
|
+
/** Product context */
|
|
248
|
+
product?: ProductType;
|
|
249
|
+
/** Deployment environment */
|
|
250
|
+
environment?: EnvironmentType;
|
|
251
|
+
/** Custom key-value labels for filtering */
|
|
252
|
+
customLabels: Record<string, string>;
|
|
253
|
+
/** Original blob for audit/replay */
|
|
254
|
+
rawBlob?: MetadataBlob;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Adapter interface for parsing metadata blobs.
|
|
258
|
+
* Register adapters to handle different blob formats or schemas.
|
|
259
|
+
*/
|
|
260
|
+
interface MetadataBlobAdapter {
|
|
261
|
+
/** Unique adapter name */
|
|
262
|
+
name: string;
|
|
263
|
+
/** Check if this adapter can parse the given blob */
|
|
264
|
+
canParse(blob: MetadataBlob): boolean;
|
|
265
|
+
/** Parse blob into enrichment context fields */
|
|
266
|
+
parse(blob: MetadataBlob): Partial<EnrichmentContext>;
|
|
267
|
+
}
|
|
268
|
+
/** Create an empty enrichment context with defaults */
|
|
269
|
+
declare function createEmptyContext(): EnrichmentContext;
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/enrichment/adapter-registry.d.ts
|
|
272
|
+
/** Registry for metadata blob adapters */
|
|
273
|
+
declare class AdapterRegistry {
|
|
274
|
+
private adapters;
|
|
275
|
+
/** Register an adapter (added to end of chain) */
|
|
276
|
+
register(adapter: MetadataBlobAdapter): void;
|
|
277
|
+
/** Unregister an adapter by name */
|
|
278
|
+
unregister(name: string): boolean;
|
|
279
|
+
/** Get all registered adapter names */
|
|
280
|
+
getAdapterNames(): string[];
|
|
281
|
+
/**
|
|
282
|
+
* Parse a metadata blob using registered adapters.
|
|
283
|
+
* Returns enrichment context with parsed fields.
|
|
284
|
+
* Stores original blob in rawBlob for audit.
|
|
285
|
+
*/
|
|
286
|
+
parse(blob: MetadataBlob): EnrichmentContext;
|
|
287
|
+
/** Check if any adapter can parse the given blob */
|
|
288
|
+
canParse(blob: MetadataBlob): boolean;
|
|
289
|
+
}
|
|
290
|
+
/** Get or create the default adapter registry */
|
|
291
|
+
declare function getDefaultRegistry(): AdapterRegistry;
|
|
292
|
+
/** Reset the default registry (for testing) */
|
|
293
|
+
declare function resetDefaultRegistry(): void;
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region src/enrichment/json-adapter.d.ts
|
|
296
|
+
/** JSON adapter for parsing metadata blobs */
|
|
297
|
+
declare const jsonAdapter: MetadataBlobAdapter;
|
|
298
|
+
/** Create a JSON adapter instance */
|
|
299
|
+
declare function createJsonAdapter(): MetadataBlobAdapter;
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/enrichment/index.d.ts
|
|
302
|
+
/**
|
|
303
|
+
* Initialize the default registry with built-in adapters.
|
|
304
|
+
* Call this at startup to ensure JSON adapter is available.
|
|
305
|
+
*/
|
|
306
|
+
declare function initializeDefaultAdapters(): void;
|
|
307
|
+
/**
|
|
308
|
+
* Parse a metadata blob using the default registry.
|
|
309
|
+
* Convenience function for common use case.
|
|
310
|
+
*/
|
|
311
|
+
declare function parseMetadataBlob(blob: MetadataBlob): EnrichmentContext;
|
|
312
|
+
//#endregion
|
|
313
|
+
//#region src/trace-types.d.ts
|
|
314
|
+
/**
|
|
315
|
+
* MessagePartUpdatedEvent with timestamp for trace collection.
|
|
316
|
+
* This is the canonical event type from OpenCode - pass through without transformation.
|
|
317
|
+
*/
|
|
318
|
+
interface MessagePartUpdatedEventWithTimestamp extends MessagePartUpdatedEvent$1 {
|
|
319
|
+
/** Timestamp when event was recorded */
|
|
320
|
+
timestamp: Date;
|
|
321
|
+
}
|
|
322
|
+
/** Type guard for MessagePartUpdatedEvent */
|
|
323
|
+
declare function isMessagePartUpdatedEvent(event: TraceEvent): event is MessagePartUpdatedEventWithTimestamp;
|
|
324
|
+
/** Execution scope for trace association */
|
|
325
|
+
interface TraceScope {
|
|
326
|
+
projectRef?: string;
|
|
327
|
+
sessionId?: string;
|
|
328
|
+
/** Links sub-agent sessions to their parent session */
|
|
329
|
+
parentSessionId?: string;
|
|
330
|
+
userId?: string;
|
|
331
|
+
/**
|
|
332
|
+
* Tangle Intelligence resource attributes for this scope — the `tangle.*`
|
|
333
|
+
* dimensions a partner filters on (partner / project / domain / pseudonymous
|
|
334
|
+
* end-user). Built host-side and threaded per session; stamped onto every
|
|
335
|
+
* exported span by the OTEL sink. Kept as an open bag so new dimensions flow
|
|
336
|
+
* through without a schema change.
|
|
337
|
+
*/
|
|
338
|
+
resourceAttributes?: Record<string, string>;
|
|
339
|
+
}
|
|
340
|
+
/** Success/failure signals captured during execution */
|
|
341
|
+
type Signal = "build_passed" | "build_failed" | "tests_passed" | "tests_failed" | "lint_passed" | "lint_failed" | "user_approved" | "user_rejected" | "task_completed" | "task_abandoned" | "runtime_error" | "timeout";
|
|
342
|
+
interface SignalEvent {
|
|
343
|
+
signal: Signal;
|
|
344
|
+
timestamp: Date;
|
|
345
|
+
metadata?: Record<string, unknown>;
|
|
346
|
+
}
|
|
347
|
+
/** Base fields shared by all trace events */
|
|
348
|
+
interface TraceEventBase {
|
|
349
|
+
timestamp: Date;
|
|
350
|
+
}
|
|
351
|
+
/** Message updated event (final model text and result metadata) */
|
|
352
|
+
interface MessageUpdatedEvent extends TraceEventBase {
|
|
353
|
+
type: "message.updated";
|
|
354
|
+
/** Final text content */
|
|
355
|
+
text?: string;
|
|
356
|
+
/** Legacy alias for text */
|
|
357
|
+
finalText?: string;
|
|
358
|
+
/** Token usage details */
|
|
359
|
+
tokenUsage?: Record<string, unknown>;
|
|
360
|
+
/** Timing details */
|
|
361
|
+
timing?: Record<string, unknown>;
|
|
362
|
+
/** Tool invocations captured during execution */
|
|
363
|
+
toolInvocations?: unknown[];
|
|
364
|
+
/** Additional metadata */
|
|
365
|
+
metadata?: Record<string, unknown>;
|
|
366
|
+
}
|
|
367
|
+
/** Error event */
|
|
368
|
+
interface ErrorEvent extends TraceEventBase {
|
|
369
|
+
type: "error";
|
|
370
|
+
/** Error category */
|
|
371
|
+
category: "runtime" | "syntax" | "type" | "network" | "timeout" | "unknown";
|
|
372
|
+
/** Error message */
|
|
373
|
+
message: string;
|
|
374
|
+
/** Stack trace if available */
|
|
375
|
+
stack?: string;
|
|
376
|
+
/** Error code if available */
|
|
377
|
+
code?: string;
|
|
378
|
+
/** Source of error (tool name, file, etc.) */
|
|
379
|
+
source?: string;
|
|
380
|
+
}
|
|
381
|
+
/** Diagnostic severity levels */
|
|
382
|
+
type DiagnosticSeverity = "error" | "warning" | "info" | "hint";
|
|
383
|
+
/** Individual diagnostic message */
|
|
384
|
+
interface Diagnostic {
|
|
385
|
+
/** Severity level */
|
|
386
|
+
severity: DiagnosticSeverity;
|
|
387
|
+
/** Diagnostic message */
|
|
388
|
+
message: string;
|
|
389
|
+
/** Diagnostic code (e.g., "TS2304", "E0001") */
|
|
390
|
+
code?: string | number;
|
|
391
|
+
/** Source (e.g., "typescript", "eslint") */
|
|
392
|
+
source?: string;
|
|
393
|
+
/** Start line (0-indexed) */
|
|
394
|
+
startLine: number;
|
|
395
|
+
/** Start column (0-indexed) */
|
|
396
|
+
startColumn: number;
|
|
397
|
+
/** End line (0-indexed) */
|
|
398
|
+
endLine: number;
|
|
399
|
+
/** End column (0-indexed) */
|
|
400
|
+
endColumn: number;
|
|
401
|
+
}
|
|
402
|
+
/** Summary of diagnostics for a file */
|
|
403
|
+
interface DiagnosticSummary {
|
|
404
|
+
errors: number;
|
|
405
|
+
warnings: number;
|
|
406
|
+
infos: number;
|
|
407
|
+
hints: number;
|
|
408
|
+
}
|
|
409
|
+
/** Diagnostic change event - captured after file edits */
|
|
410
|
+
interface DiagnosticEvent extends TraceEventBase {
|
|
411
|
+
type: "diagnostic";
|
|
412
|
+
/** File path */
|
|
413
|
+
file: string;
|
|
414
|
+
/** Language server ID */
|
|
415
|
+
serverId?: string;
|
|
416
|
+
/** Language (e.g., "typescript", "python") */
|
|
417
|
+
language?: string;
|
|
418
|
+
/** Diagnostics before the change */
|
|
419
|
+
before?: Diagnostic[];
|
|
420
|
+
/** Diagnostics after the change */
|
|
421
|
+
after: Diagnostic[];
|
|
422
|
+
/** Summary counts before */
|
|
423
|
+
beforeSummary?: DiagnosticSummary;
|
|
424
|
+
/** Summary counts after */
|
|
425
|
+
afterSummary: DiagnosticSummary;
|
|
426
|
+
/** Net change in error count (negative = improvement) */
|
|
427
|
+
errorDelta: number;
|
|
428
|
+
/** Diagnostics that were resolved */
|
|
429
|
+
resolved?: Diagnostic[];
|
|
430
|
+
/** Diagnostics that were introduced */
|
|
431
|
+
introduced?: Diagnostic[];
|
|
432
|
+
}
|
|
433
|
+
/** File change event */
|
|
434
|
+
interface FileChangeEvent extends TraceEventBase {
|
|
435
|
+
type: "file_change";
|
|
436
|
+
/** File path */
|
|
437
|
+
file: string;
|
|
438
|
+
/** Change type */
|
|
439
|
+
changeType: "created" | "modified" | "deleted";
|
|
440
|
+
/** Lines added */
|
|
441
|
+
linesAdded?: number;
|
|
442
|
+
/** Lines removed */
|
|
443
|
+
linesRemoved?: number;
|
|
444
|
+
}
|
|
445
|
+
/** Build result event */
|
|
446
|
+
interface BuildResultEvent extends TraceEventBase {
|
|
447
|
+
type: "build_result";
|
|
448
|
+
/** Build command */
|
|
449
|
+
command?: string;
|
|
450
|
+
/** Whether build succeeded */
|
|
451
|
+
success: boolean;
|
|
452
|
+
/** Duration in milliseconds */
|
|
453
|
+
durationMs?: number;
|
|
454
|
+
/** Error count */
|
|
455
|
+
errorCount?: number;
|
|
456
|
+
/** Warning count */
|
|
457
|
+
warningCount?: number;
|
|
458
|
+
}
|
|
459
|
+
/** Test result event */
|
|
460
|
+
interface TestResultEvent extends TraceEventBase {
|
|
461
|
+
type: "test_result";
|
|
462
|
+
/** Test command */
|
|
463
|
+
command?: string;
|
|
464
|
+
/** Whether all tests passed */
|
|
465
|
+
success: boolean;
|
|
466
|
+
/** Duration in milliseconds */
|
|
467
|
+
durationMs?: number;
|
|
468
|
+
/** Number of tests passed */
|
|
469
|
+
passed?: number;
|
|
470
|
+
/** Number of tests failed */
|
|
471
|
+
failed?: number;
|
|
472
|
+
/** Number of tests skipped */
|
|
473
|
+
skipped?: number;
|
|
474
|
+
}
|
|
475
|
+
/** Environment snapshot at trace start */
|
|
476
|
+
interface EnvironmentEvent extends TraceEventBase {
|
|
477
|
+
type: "environment";
|
|
478
|
+
/** Runtime versions */
|
|
479
|
+
versions?: Record<string, string>;
|
|
480
|
+
/** Working directory */
|
|
481
|
+
workingDir?: string;
|
|
482
|
+
/** Platform info */
|
|
483
|
+
platform?: string;
|
|
484
|
+
}
|
|
485
|
+
/** Generic event for extensibility (use sparingly) */
|
|
486
|
+
interface CustomEvent extends TraceEventBase {
|
|
487
|
+
type: "custom";
|
|
488
|
+
/** Custom event name */
|
|
489
|
+
name: string;
|
|
490
|
+
/** Custom event data */
|
|
491
|
+
data: Record<string, unknown>;
|
|
492
|
+
}
|
|
493
|
+
/** Batch execution started event */
|
|
494
|
+
interface BatchStartedEvent extends TraceEventBase {
|
|
495
|
+
type: "batch_started";
|
|
496
|
+
/** Unique batch execution ID */
|
|
497
|
+
batchId: string;
|
|
498
|
+
/** Number of tasks in the batch */
|
|
499
|
+
taskCount: number;
|
|
500
|
+
/** Number of backends being tested */
|
|
501
|
+
backendCount: number;
|
|
502
|
+
/** Total executions (tasks × backends) */
|
|
503
|
+
totalExecutions: number;
|
|
504
|
+
/** Scaling mode used */
|
|
505
|
+
scalingMode?: "fastest" | "balanced" | "cheapest";
|
|
506
|
+
}
|
|
507
|
+
/** Batch execution completed event */
|
|
508
|
+
interface BatchCompletedEvent extends TraceEventBase {
|
|
509
|
+
type: "batch_completed";
|
|
510
|
+
/** Unique batch execution ID */
|
|
511
|
+
batchId: string;
|
|
512
|
+
/** Number of successful task executions */
|
|
513
|
+
successCount: number;
|
|
514
|
+
/** Number of failed task executions */
|
|
515
|
+
failureCount: number;
|
|
516
|
+
/** Success rate as percentage (0-100) */
|
|
517
|
+
successRate: number;
|
|
518
|
+
/** Total duration in milliseconds */
|
|
519
|
+
durationMs: number;
|
|
520
|
+
/** Total tokens used across all executions */
|
|
521
|
+
totalTokensUsed?: number;
|
|
522
|
+
}
|
|
523
|
+
/** Individual task within a batch completed */
|
|
524
|
+
interface BatchTaskCompletedEvent extends TraceEventBase {
|
|
525
|
+
type: "batch_task_completed";
|
|
526
|
+
/** Parent batch ID */
|
|
527
|
+
batchId: string;
|
|
528
|
+
/** Task ID within the batch */
|
|
529
|
+
taskId: string;
|
|
530
|
+
/** Backend used for this execution */
|
|
531
|
+
backend: string;
|
|
532
|
+
/** Whether the task succeeded */
|
|
533
|
+
success: boolean;
|
|
534
|
+
/** Duration in milliseconds */
|
|
535
|
+
durationMs: number;
|
|
536
|
+
/** Attempt number (1 = first try) */
|
|
537
|
+
attempt: number;
|
|
538
|
+
/** Number of retries before success/failure */
|
|
539
|
+
retries: number;
|
|
540
|
+
/** Tokens used for this task */
|
|
541
|
+
tokensUsed?: number;
|
|
542
|
+
/** Error message if failed */
|
|
543
|
+
error?: string;
|
|
544
|
+
}
|
|
545
|
+
/** Union of all trace event types */
|
|
546
|
+
type TraceEvent = MessagePartUpdatedEventWithTimestamp | MessageUpdatedEvent | ErrorEvent | DiagnosticEvent | FileChangeEvent | BuildResultEvent | TestResultEvent | EnvironmentEvent | CustomEvent | BatchStartedEvent | BatchCompletedEvent | BatchTaskCompletedEvent;
|
|
547
|
+
/** Event type discriminator */
|
|
548
|
+
type TraceEventType = TraceEvent["type"];
|
|
549
|
+
declare function isMessageUpdatedEvent(event: TraceEvent): event is MessageUpdatedEvent;
|
|
550
|
+
declare function isErrorEvent(event: TraceEvent): event is ErrorEvent;
|
|
551
|
+
declare function isDiagnosticEvent(event: TraceEvent): event is DiagnosticEvent;
|
|
552
|
+
declare function isFileChangeEvent(event: TraceEvent): event is FileChangeEvent;
|
|
553
|
+
declare function isBuildResultEvent(event: TraceEvent): event is BuildResultEvent;
|
|
554
|
+
declare function isTestResultEvent(event: TraceEvent): event is TestResultEvent;
|
|
555
|
+
declare function isEnvironmentEvent(event: TraceEvent): event is EnvironmentEvent;
|
|
556
|
+
declare function isCustomEvent(event: TraceEvent): event is CustomEvent;
|
|
557
|
+
/** Execution outcome derived from signals */
|
|
558
|
+
type Outcome = "success" | "partial" | "failure" | "unknown";
|
|
559
|
+
/** Execution trace - complete record of an agent task */
|
|
560
|
+
interface ExecutionTrace {
|
|
561
|
+
id: string;
|
|
562
|
+
scope: TraceScope;
|
|
563
|
+
task: string;
|
|
564
|
+
events: TraceEvent[];
|
|
565
|
+
signals: SignalEvent[];
|
|
566
|
+
outcome: Outcome;
|
|
567
|
+
startedAt: Date;
|
|
568
|
+
completedAt?: Date;
|
|
569
|
+
metadata?: Record<string, unknown>;
|
|
570
|
+
}
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region src/langfuse-sink.d.ts
|
|
573
|
+
/** Langfuse sink configuration */
|
|
574
|
+
interface LangfuseSinkConfig {
|
|
575
|
+
/** Langfuse public key */
|
|
576
|
+
publicKey: string;
|
|
577
|
+
/** Langfuse secret key */
|
|
578
|
+
secretKey: string;
|
|
579
|
+
/** Langfuse host (default: https://cloud.langfuse.com) */
|
|
580
|
+
baseUrl?: string;
|
|
581
|
+
/** Enable debug logging */
|
|
582
|
+
debug?: boolean;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Langfuse trace exporter using the native SDK.
|
|
586
|
+
*
|
|
587
|
+
* Creates proper Langfuse traces with spans and generations
|
|
588
|
+
* for rich observability in the Langfuse dashboard.
|
|
589
|
+
*
|
|
590
|
+
* Note: This is a trace-level exporter (ExecutionTrace), not a
|
|
591
|
+
* TelemetrySink (TelemetryEvent). Use for exporting complete traces.
|
|
592
|
+
*/
|
|
593
|
+
declare class LangfuseSink {
|
|
594
|
+
readonly name = "langfuse";
|
|
595
|
+
private readonly config;
|
|
596
|
+
constructor(config: LangfuseSinkConfig);
|
|
597
|
+
/**
|
|
598
|
+
* Export an execution trace to Langfuse.
|
|
599
|
+
*/
|
|
600
|
+
exportTrace(trace: ExecutionTrace): Promise<void>;
|
|
601
|
+
/**
|
|
602
|
+
* Export a trace event as a Langfuse span or generation.
|
|
603
|
+
*/
|
|
604
|
+
private exportTraceEvent;
|
|
605
|
+
/**
|
|
606
|
+
* Export a tool part from message.part.updated event.
|
|
607
|
+
* Tool parts have state progression: pending → running → completed/error
|
|
608
|
+
*/
|
|
609
|
+
private exportToolPart;
|
|
610
|
+
flush(): Promise<void>;
|
|
611
|
+
close(): Promise<void>;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Create a Langfuse sink from environment variables.
|
|
615
|
+
*/
|
|
616
|
+
declare function createLangfuseSinkFromEnv(): LangfuseSink | null;
|
|
617
|
+
//#endregion
|
|
618
|
+
//#region src/otel-provider.d.ts
|
|
619
|
+
/**
|
|
620
|
+
* Global OpenTelemetry tracer provider for the in-container agent loop.
|
|
621
|
+
*
|
|
622
|
+
* Registers a Node TracerProvider + batching OTLP/HTTP exporter so the GLOBAL
|
|
623
|
+
* tracer (`@opentelemetry/api` `trace.getTracer`, used by the OTel sink) ships
|
|
624
|
+
* spans to the configured collector (Tangle Intelligence) instead of being a
|
|
625
|
+
* no-op. Endpoint + headers come from the standard OTEL env the host threads in
|
|
626
|
+
* (`OTEL_EXPORTER_OTLP_ENDPOINT` / `OTEL_EXPORTER_OTLP_HEADERS`); per-session
|
|
627
|
+
* partner/project/user resource attributes are stamped on spans by the sink,
|
|
628
|
+
* not here.
|
|
629
|
+
*
|
|
630
|
+
* Opt-in + best-effort:
|
|
631
|
+
* - a no-op unless `TELEMETRY_ENABLED=true` AND an endpoint is set;
|
|
632
|
+
* - any SDK import / construction failure degrades to disabled, never crashes
|
|
633
|
+
* the sidecar (telemetry must never take down the agent);
|
|
634
|
+
* - idempotent — a second `initOtelProvider` returns the already-active result.
|
|
635
|
+
*/
|
|
636
|
+
interface InitOtelProviderResult {
|
|
637
|
+
active: boolean;
|
|
638
|
+
reason?: string;
|
|
639
|
+
}
|
|
640
|
+
declare function initOtelProvider(serviceName: string): Promise<InitOtelProviderResult>;
|
|
641
|
+
declare function shutdownOtelProvider(): Promise<void>;
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/otel-sink.d.ts
|
|
644
|
+
/** Configuration for the OTEL sink */
|
|
645
|
+
interface OtelSinkConfig {
|
|
646
|
+
/** Service name for the tracer */
|
|
647
|
+
serviceName?: string;
|
|
648
|
+
/** Include raw input/output in span attributes (may contain sensitive data) */
|
|
649
|
+
includePayloads?: boolean;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* OpenTelemetry sink — exports via whatever OTEL SDK config was set at
|
|
653
|
+
* application startup (Langfuse, Jaeger, any OTLP backend).
|
|
654
|
+
*/
|
|
655
|
+
declare class OtelTelemetrySink implements TelemetrySink {
|
|
656
|
+
readonly name = "otel";
|
|
657
|
+
private readonly config;
|
|
658
|
+
constructor(config?: OtelSinkConfig);
|
|
659
|
+
send(events: TelemetryEvent[]): Promise<void>;
|
|
660
|
+
/**
|
|
661
|
+
* Export an execution trace as OTEL spans.
|
|
662
|
+
*
|
|
663
|
+
* Creates a parent span for the trace and child spans for each event.
|
|
664
|
+
* Uses the global tracer, so spans flow through the configured processor.
|
|
665
|
+
*/
|
|
666
|
+
exportTrace(trace: ExecutionTrace): Promise<void>;
|
|
667
|
+
/**
|
|
668
|
+
* Export a single trace event as an OTEL span.
|
|
669
|
+
*/
|
|
670
|
+
private exportTraceEvent;
|
|
671
|
+
private getEventStartTime;
|
|
672
|
+
private getEventEndTime;
|
|
673
|
+
private getStartupPhaseDurationMs;
|
|
674
|
+
/**
|
|
675
|
+
* Get span name for a trace event.
|
|
676
|
+
*/
|
|
677
|
+
private getSpanName;
|
|
678
|
+
/**
|
|
679
|
+
* Get OTEL attributes for a trace event.
|
|
680
|
+
*/
|
|
681
|
+
private getEventAttributes;
|
|
682
|
+
/**
|
|
683
|
+
* Flatten metadata object into span attributes
|
|
684
|
+
*/
|
|
685
|
+
private flattenMetadata;
|
|
686
|
+
/** Narrow an opaque telemetry `data.trace` to an ExecutionTrace. */
|
|
687
|
+
private isExecutionTrace;
|
|
688
|
+
flush(): Promise<void>;
|
|
689
|
+
close(): Promise<void>;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Create an OTEL sink that uses the global tracer.
|
|
693
|
+
*
|
|
694
|
+
* The OTEL SDK must be initialized separately before using this sink.
|
|
695
|
+
*/
|
|
696
|
+
declare function createOtelSink(config?: OtelSinkConfig): OtelTelemetrySink;
|
|
697
|
+
/**
|
|
698
|
+
* Create an OTEL sink from environment variables.
|
|
699
|
+
*
|
|
700
|
+
* Returns a sink that uses the global tracer (which should be initialized
|
|
701
|
+
* separately via NodeSDK with LangfuseSpanProcessor or OTLPTraceExporter).
|
|
702
|
+
*/
|
|
703
|
+
declare function createOtelSinkFromEnv(): OtelTelemetrySink | null;
|
|
704
|
+
//#endregion
|
|
705
|
+
//#region src/sinks.d.ts
|
|
706
|
+
declare class HttpTelemetrySink implements TelemetrySink {
|
|
707
|
+
readonly name = "http";
|
|
708
|
+
private readonly endpoint;
|
|
709
|
+
private readonly headers;
|
|
710
|
+
private readonly fetchFn;
|
|
711
|
+
private readonly timeout;
|
|
712
|
+
private pendingRequests;
|
|
713
|
+
constructor(config: {
|
|
714
|
+
endpoint: string;
|
|
715
|
+
headers?: Record<string, string>;
|
|
716
|
+
fetch?: typeof fetch;
|
|
717
|
+
timeout?: number;
|
|
718
|
+
});
|
|
719
|
+
send(events: TelemetryEvent[]): Promise<void>;
|
|
720
|
+
flush(): Promise<void>;
|
|
721
|
+
close(): Promise<void>;
|
|
722
|
+
}
|
|
723
|
+
declare class ConsoleTelemetrySink implements TelemetrySink {
|
|
724
|
+
readonly name = "console";
|
|
725
|
+
private readonly prefix;
|
|
726
|
+
private readonly logLevel;
|
|
727
|
+
private readonly formatJson;
|
|
728
|
+
constructor(config?: {
|
|
729
|
+
prefix?: string;
|
|
730
|
+
logLevel?: "log" | "debug" | "info";
|
|
731
|
+
formatJson?: boolean;
|
|
732
|
+
});
|
|
733
|
+
send(events: TelemetryEvent[]): Promise<void>;
|
|
734
|
+
flush(): Promise<void>;
|
|
735
|
+
close(): Promise<void>;
|
|
736
|
+
}
|
|
737
|
+
declare class TestTelemetrySink implements TelemetrySink {
|
|
738
|
+
readonly name = "test";
|
|
739
|
+
readonly events: TelemetryEvent[];
|
|
740
|
+
send(events: TelemetryEvent[]): Promise<void>;
|
|
741
|
+
flush(): Promise<void>;
|
|
742
|
+
close(): Promise<void>;
|
|
743
|
+
clear(): void;
|
|
744
|
+
getEvents(): TelemetryEvent[];
|
|
745
|
+
getEventsByType(type: string): TelemetryEvent[];
|
|
746
|
+
getEventsByName(name: string): TelemetryEvent[];
|
|
747
|
+
}
|
|
748
|
+
declare class MultiTelemetrySink implements TelemetrySink {
|
|
749
|
+
readonly name = "multi";
|
|
750
|
+
private readonly sinks;
|
|
751
|
+
constructor(sinks: TelemetrySink[]);
|
|
752
|
+
send(events: TelemetryEvent[]): Promise<void>;
|
|
753
|
+
flush(): Promise<void>;
|
|
754
|
+
close(): Promise<void>;
|
|
755
|
+
}
|
|
756
|
+
declare function createHttpSink(config: {
|
|
757
|
+
endpoint: string;
|
|
758
|
+
headers?: Record<string, string>;
|
|
759
|
+
fetch?: typeof fetch;
|
|
760
|
+
timeout?: number;
|
|
761
|
+
}): HttpTelemetrySink;
|
|
762
|
+
declare function createConsoleSink(config?: {
|
|
763
|
+
prefix?: string;
|
|
764
|
+
logLevel?: "log" | "debug" | "info";
|
|
765
|
+
}): ConsoleTelemetrySink;
|
|
766
|
+
declare function createTestSink(): TestTelemetrySink;
|
|
767
|
+
//#endregion
|
|
768
|
+
//#region src/sse-parser.d.ts
|
|
769
|
+
declare const parseSSEData: typeof parseSSEData$1;
|
|
770
|
+
/**
|
|
771
|
+
* Convert SSE event data to a typed TraceEvent.
|
|
772
|
+
* Returns null for events that should be skipped (heartbeats, status-only, etc.)
|
|
773
|
+
*
|
|
774
|
+
* message.part.updated events are passed through directly - no transformation.
|
|
775
|
+
* This preserves full fidelity to what OpenCode outputs.
|
|
776
|
+
*
|
|
777
|
+
* `raw` events that carry a recognized tool-invocation payload are
|
|
778
|
+
* normalized into the same `message.part.updated` shape (with a
|
|
779
|
+
* `ToolPart`) so consumers don't need to reach into provider-specific
|
|
780
|
+
* raw shapes to render tool calls. Unrecognized raw events fall
|
|
781
|
+
* through to a `custom` trace event.
|
|
782
|
+
*/
|
|
783
|
+
declare function sseToTraceEvent(event: SSEEventData$1): TraceEvent | null;
|
|
784
|
+
/**
|
|
785
|
+
* Extract a signal from an SSE event if present.
|
|
786
|
+
*/
|
|
787
|
+
declare function sseToSignal(event: SSEEventData$1): SignalEvent | null;
|
|
788
|
+
/**
|
|
789
|
+
* Check if an SSE event indicates completion (success or failure).
|
|
790
|
+
*/
|
|
791
|
+
declare function isCompletionEvent(event: SSEEventData$1): {
|
|
792
|
+
complete: boolean;
|
|
793
|
+
success: boolean;
|
|
794
|
+
};
|
|
795
|
+
//#endregion
|
|
796
|
+
//#region src/trace-collector.d.ts
|
|
797
|
+
interface TraceCollectorConfig {
|
|
798
|
+
/** Sink to export traces to */
|
|
799
|
+
sink: TelemetrySink;
|
|
800
|
+
/** Max traces to buffer before auto-flush */
|
|
801
|
+
maxBufferSize?: number;
|
|
802
|
+
/** Auto-flush interval in ms (0 = manual only) */
|
|
803
|
+
flushIntervalMs?: number;
|
|
804
|
+
/** Default scope for new traces */
|
|
805
|
+
defaultScope?: TraceScope;
|
|
806
|
+
}
|
|
807
|
+
/** Active trace context for tracking a single execution */
|
|
808
|
+
interface TraceContext {
|
|
809
|
+
traceId: string;
|
|
810
|
+
startedAt: Date;
|
|
811
|
+
/** Add a typed event to the trace */
|
|
812
|
+
addEvent<T extends TraceEvent>(event: Omit<T, "timestamp">): void;
|
|
813
|
+
/** Add a signal (success/failure indicator) */
|
|
814
|
+
addSignal(signal: Signal, metadata?: Record<string, unknown>): void;
|
|
815
|
+
/** Complete the trace successfully */
|
|
816
|
+
complete(metadata?: Record<string, unknown>): ExecutionTrace;
|
|
817
|
+
/** Complete the trace with failure */
|
|
818
|
+
fail(error: string | Error, metadata?: Record<string, unknown>): ExecutionTrace;
|
|
819
|
+
/** Abandon the trace */
|
|
820
|
+
abandon(): ExecutionTrace;
|
|
821
|
+
}
|
|
822
|
+
declare class TraceCollector {
|
|
823
|
+
private sink;
|
|
824
|
+
private config;
|
|
825
|
+
private activeTraces;
|
|
826
|
+
private completedTraces;
|
|
827
|
+
private flushTimer?;
|
|
828
|
+
private sequence;
|
|
829
|
+
constructor(config: TraceCollectorConfig);
|
|
830
|
+
/** Start tracking a new execution */
|
|
831
|
+
startTrace(task: string, scope?: TraceScope, metadata?: Record<string, unknown>): TraceContext;
|
|
832
|
+
/** Convenience: track a complete execution with a wrapper function */
|
|
833
|
+
track<T>(task: string, fn: (ctx: TraceContext) => Promise<T>, options?: {
|
|
834
|
+
scope?: TraceScope;
|
|
835
|
+
metadata?: Record<string, unknown>;
|
|
836
|
+
}): Promise<{
|
|
837
|
+
result: T;
|
|
838
|
+
trace: ExecutionTrace;
|
|
839
|
+
}>;
|
|
840
|
+
/** Flush completed traces to sink */
|
|
841
|
+
flush(): Promise<void>;
|
|
842
|
+
/** Get count of pending traces */
|
|
843
|
+
getPendingCount(): number;
|
|
844
|
+
/** Get active trace count */
|
|
845
|
+
getActiveCount(): number;
|
|
846
|
+
/** Shutdown collector */
|
|
847
|
+
shutdown(): Promise<void>;
|
|
848
|
+
private completeTrace;
|
|
849
|
+
private classifyOutcome;
|
|
850
|
+
}
|
|
851
|
+
declare function createTraceCollector(config: TraceCollectorConfig): TraceCollector;
|
|
852
|
+
//#endregion
|
|
853
|
+
//#region src/tracker.d.ts
|
|
854
|
+
declare class TelemetryTracker {
|
|
855
|
+
private readonly config;
|
|
856
|
+
private readonly sinks;
|
|
857
|
+
private readonly queue;
|
|
858
|
+
private readonly storage?;
|
|
859
|
+
private sequence;
|
|
860
|
+
private flushTimer?;
|
|
861
|
+
private sessionStartTime?;
|
|
862
|
+
private isFlushing;
|
|
863
|
+
constructor(config: TelemetryConfig, storage?: Storage);
|
|
864
|
+
addSink(sink: TelemetrySink): this;
|
|
865
|
+
removeSink(name: string): this;
|
|
866
|
+
startSession(metadata?: Record<string, unknown>): string;
|
|
867
|
+
endSession(metadata?: Record<string, unknown>): void;
|
|
868
|
+
track(type: TelemetryEventType, name: string, data?: Record<string, unknown>): void;
|
|
869
|
+
trackPerformance(metric: Omit<PerformanceMetric, "timestamp">): void;
|
|
870
|
+
trackError(error: Error | string, context?: Record<string, unknown>): void;
|
|
871
|
+
trackApiRequest(method: string, path: string, status: number, durationMs: number, metadata?: Record<string, unknown>): void;
|
|
872
|
+
trackAgentExecution(identifier: string, executionId: string, durationMs: number, success: boolean, metadata?: Record<string, unknown>): void;
|
|
873
|
+
flush(): Promise<void>;
|
|
874
|
+
close(): Promise<void>;
|
|
875
|
+
getQueueSize(): number;
|
|
876
|
+
isEnabled(): boolean;
|
|
877
|
+
enable(): void;
|
|
878
|
+
disable(): void;
|
|
879
|
+
private enqueue;
|
|
880
|
+
private shouldSample;
|
|
881
|
+
private isExcluded;
|
|
882
|
+
private enrichData;
|
|
883
|
+
private startFlushTimer;
|
|
884
|
+
private stopFlushTimer;
|
|
885
|
+
private persistEvent;
|
|
886
|
+
private persistEvents;
|
|
887
|
+
private clearPersistedEvents;
|
|
888
|
+
loadPersistedEvents(): Promise<TelemetryEvent[]>;
|
|
889
|
+
}
|
|
890
|
+
declare function createTelemetryTracker(config: TelemetryConfig, storage?: Storage): TelemetryTracker;
|
|
891
|
+
//#endregion
|
|
892
|
+
//#region src/usage.d.ts
|
|
893
|
+
declare class UsageTracker {
|
|
894
|
+
private readonly config;
|
|
895
|
+
private readonly provider?;
|
|
896
|
+
private readonly storage?;
|
|
897
|
+
private readonly queue;
|
|
898
|
+
private flushTimer?;
|
|
899
|
+
private isFlushing;
|
|
900
|
+
private sessionMetrics;
|
|
901
|
+
constructor(config: UsageTrackerConfig, provider?: UsageProvider, storage?: Storage);
|
|
902
|
+
recordApiCall(metric: ApiMetric): void;
|
|
903
|
+
recordAgentExecution(metric: AgentMetric): void;
|
|
904
|
+
recordError(error: Error | string, operation: string): void;
|
|
905
|
+
record(usage: Omit<UsageRecord, "id" | "timestamp">): void;
|
|
906
|
+
flush(): Promise<void>;
|
|
907
|
+
getUsage(options?: {
|
|
908
|
+
since?: Date;
|
|
909
|
+
until?: Date;
|
|
910
|
+
limit?: number;
|
|
911
|
+
}): Promise<UsageRecord[]>;
|
|
912
|
+
getSummary(period?: UsageSummary["period"]): Promise<UsageSummary>;
|
|
913
|
+
getSessionMetrics(): {
|
|
914
|
+
totalCredits: number;
|
|
915
|
+
totalOperations: number;
|
|
916
|
+
totalDurationMs: number;
|
|
917
|
+
totalInputTokens: number;
|
|
918
|
+
totalOutputTokens: number;
|
|
919
|
+
operationBreakdown: Record<string, number>;
|
|
920
|
+
sessionDurationMs: number;
|
|
921
|
+
};
|
|
922
|
+
resetSessionMetrics(): void;
|
|
923
|
+
close(): Promise<void>;
|
|
924
|
+
private calculateCost;
|
|
925
|
+
private persistRecords;
|
|
926
|
+
private loadPersistedRecords;
|
|
927
|
+
private generateLocalSummary;
|
|
928
|
+
private getPeriodStart;
|
|
929
|
+
private startFlushTimer;
|
|
930
|
+
private stopFlushTimer;
|
|
931
|
+
}
|
|
932
|
+
declare function createUsageInterceptor(tracker: UsageTracker): {
|
|
933
|
+
onRequest(ctx: {
|
|
934
|
+
request: {
|
|
935
|
+
method: string;
|
|
936
|
+
url: string;
|
|
937
|
+
};
|
|
938
|
+
startedAt: number;
|
|
939
|
+
}): {
|
|
940
|
+
request: {
|
|
941
|
+
method: string;
|
|
942
|
+
url: string;
|
|
943
|
+
};
|
|
944
|
+
startedAt: number;
|
|
945
|
+
};
|
|
946
|
+
onResponse<T>(ctx: {
|
|
947
|
+
request: {
|
|
948
|
+
method: string;
|
|
949
|
+
url: string;
|
|
950
|
+
};
|
|
951
|
+
response: {
|
|
952
|
+
status: number;
|
|
953
|
+
};
|
|
954
|
+
startedAt: number;
|
|
955
|
+
}): T;
|
|
956
|
+
onError(ctx: {
|
|
957
|
+
request: {
|
|
958
|
+
method: string;
|
|
959
|
+
url: string;
|
|
960
|
+
};
|
|
961
|
+
error: Error;
|
|
962
|
+
startedAt: number;
|
|
963
|
+
}): void;
|
|
964
|
+
};
|
|
965
|
+
declare function createUsageTracker(config: UsageTrackerConfig, provider?: UsageProvider, storage?: Storage): UsageTracker;
|
|
966
|
+
//#endregion
|
|
967
|
+
export { AdapterRegistry, type AgentErrorEvent, type AgentEvent, type AgentMetric, type ApiMetric, type BuildResultEvent, ConsoleTelemetrySink, type CreditBalance, type CreditProvider, CreditTracker, type CreditTrackerConfig, type CreditTransaction, type CustomEvent, type Diagnostic, type DiagnosticEvent, type DiagnosticSeverity, type DiagnosticSummary, type EnrichmentContext, type EnvironmentEvent, type EnvironmentType, type ErrorEvent, type ExecutionTrace, type FileChangeEvent, type 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, type GenAiUsage, HttpTelemetrySink, type InitOtelProviderResult, LangfuseSink, type LangfuseSinkConfig, type LifecycleOp, MemoryCreditProvider, type MessagePartUpdatedEvent, type MessagePartUpdatedEventWithTimestamp, type MessageUpdatedEvent, type MetadataBlob, type MetadataBlobAdapter, type MetadataBlobFormat, MultiTelemetrySink, type OtelSinkConfig, OtelTelemetrySink, type Outcome, PROVISION_TRACE_ID_HEADER, PTID_PREFIX, type ParsedSSEEvent, type Part, type PerformanceMetric, type ProductType, type ReasoningPart, type RecordOptions, type ResultEvent, SSEChunkParser, type SSEEventData, type SSEParserOptions, type ServerTimingEntry, type Signal, type SignalEvent, type SpanComponent, SpanRecorder, type SpanStatus, type StageSpan, type StageSpanInput, type StatusEvent, type StreamTokenUsage, type StreamUsageAccumulator, StreamUsageExtractor, type SubscriptionTier, TOKEN_USAGE_COST_KEYS, TOKEN_USAGE_INPUT_KEYS, TOKEN_USAGE_OUTPUT_KEYS, type TelemetryConfig, type TelemetryEvent, type TelemetryEventType, type TelemetrySink, TelemetryTracker, type TestResultEvent, TestTelemetrySink, type TextPart, type TokenUsageCounts, type ToolPart, type ToolState, TraceCollector, type TraceCollectorConfig, type TraceContext, type TraceEvent, type TraceEventType, type TraceScope, type UsageProvider, type UsageRecord, type UsageSummary, UsageTracker, type UsageTrackerConfig, addTokenUsage, consumeSSEStream, createConsoleSink, createCreditTracker, createEmptyContext, createHttpSink, createJsonAdapter, createLangfuseSinkFromEnv, createOtelSink, createOtelSinkFromEnv, createStreamUsageExtractor, createTelemetryTracker, createTestSink, createTraceCollector, createUsageCallback, createUsageInterceptor, createUsageTracker, firstTokenCount, firstUsageCostUsd, genAiUsageAttributes, getDefaultRegistry, initOtelProvider, initializeDefaultAdapters, isAdoptablePtid, isBuildResultEvent, isCompletionEvent, isCustomEvent, isDiagnosticEvent, isEnvironmentEvent, isErrorEvent, isFileChangeEvent, isFilePart, isMessagePartUpdatedEvent, isMessageUpdatedEvent, isReasoningPart, isTestResultEvent, isTextPart, isToolPart, jsonAdapter, mintPtid, monotonicNs, parseMetadataBlob, parseSSEData, parseSSEStream, parseServerTiming, readOrMintPtid, readTokenCostUsd, readTokenUsage, resetDefaultRegistry, shutdownOtelProvider, spanDurationMs, sseToSignal, sseToTraceEvent, tokenCount, tokenUsageSource };
|
|
968
|
+
//# sourceMappingURL=index.d.mts.map
|