observa-sdk 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +547 -19
- package/dist/index.d.cts +134 -2
- package/dist/index.d.ts +134 -2
- package/dist/index.js +547 -19
- package/package.json +5 -2
package/dist/index.d.cts
CHANGED
|
@@ -13,6 +13,11 @@ interface TrackEventInput {
|
|
|
13
13
|
context?: string;
|
|
14
14
|
model?: string;
|
|
15
15
|
metadata?: Record<string, any>;
|
|
16
|
+
conversationId?: string;
|
|
17
|
+
sessionId?: string;
|
|
18
|
+
userId?: string;
|
|
19
|
+
messageIndex?: number;
|
|
20
|
+
parentMessageId?: string;
|
|
16
21
|
}
|
|
17
22
|
declare class Observa {
|
|
18
23
|
private apiKey;
|
|
@@ -23,10 +28,137 @@ declare class Observa {
|
|
|
23
28
|
private isProduction;
|
|
24
29
|
private sampleRate;
|
|
25
30
|
private maxResponseChars;
|
|
31
|
+
private eventBuffer;
|
|
32
|
+
private flushPromise;
|
|
33
|
+
private flushInProgress;
|
|
34
|
+
private maxBufferSize;
|
|
35
|
+
private flushIntervalMs;
|
|
36
|
+
private flushIntervalId;
|
|
37
|
+
private currentTraceId;
|
|
38
|
+
private rootSpanId;
|
|
39
|
+
private spanStack;
|
|
40
|
+
private traceStartTime;
|
|
26
41
|
constructor(config: ObservaInitConfig);
|
|
27
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Flush buffered events to the API
|
|
44
|
+
* Returns a promise that resolves when all events are sent
|
|
45
|
+
*/
|
|
46
|
+
flush(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Helper: Create base event properties
|
|
49
|
+
*/
|
|
50
|
+
private createBaseEventProperties;
|
|
51
|
+
/**
|
|
52
|
+
* Helper: Add event to buffer with proper span hierarchy
|
|
53
|
+
*/
|
|
54
|
+
private addEvent;
|
|
55
|
+
/**
|
|
56
|
+
* Start a new trace (manual trace management)
|
|
57
|
+
*/
|
|
58
|
+
startTrace(options?: {
|
|
59
|
+
name?: string;
|
|
60
|
+
metadata?: Record<string, any>;
|
|
61
|
+
conversationId?: string;
|
|
62
|
+
sessionId?: string;
|
|
63
|
+
userId?: string;
|
|
64
|
+
}): string;
|
|
65
|
+
/**
|
|
66
|
+
* Track a tool call
|
|
67
|
+
*/
|
|
68
|
+
trackToolCall(options: {
|
|
69
|
+
toolName: string;
|
|
70
|
+
args?: Record<string, any>;
|
|
71
|
+
result?: any;
|
|
72
|
+
resultStatus: "success" | "error" | "timeout";
|
|
73
|
+
latencyMs: number;
|
|
74
|
+
errorMessage?: string;
|
|
75
|
+
}): string;
|
|
76
|
+
/**
|
|
77
|
+
* Track a retrieval operation
|
|
78
|
+
*/
|
|
79
|
+
trackRetrieval(options: {
|
|
80
|
+
contextIds?: string[];
|
|
81
|
+
contextHashes?: string[];
|
|
82
|
+
k?: number;
|
|
83
|
+
similarityScores?: number[];
|
|
84
|
+
latencyMs: number;
|
|
85
|
+
}): string;
|
|
86
|
+
/**
|
|
87
|
+
* Track an error with stack trace support
|
|
88
|
+
*/
|
|
89
|
+
trackError(options: {
|
|
90
|
+
errorType: string;
|
|
91
|
+
errorMessage: string;
|
|
92
|
+
stackTrace?: string;
|
|
93
|
+
context?: Record<string, any>;
|
|
94
|
+
error?: Error;
|
|
95
|
+
}): string;
|
|
96
|
+
/**
|
|
97
|
+
* Track user feedback
|
|
98
|
+
*/
|
|
99
|
+
trackFeedback(options: {
|
|
100
|
+
type: "like" | "dislike" | "rating" | "correction";
|
|
101
|
+
rating?: number;
|
|
102
|
+
comment?: string;
|
|
103
|
+
outcome?: "success" | "failure" | "partial";
|
|
104
|
+
conversationId?: string;
|
|
105
|
+
sessionId?: string;
|
|
106
|
+
userId?: string;
|
|
107
|
+
messageIndex?: number;
|
|
108
|
+
parentMessageId?: string;
|
|
109
|
+
agentName?: string;
|
|
110
|
+
version?: string;
|
|
111
|
+
route?: string;
|
|
112
|
+
parentSpanId?: string | null;
|
|
113
|
+
spanId?: string;
|
|
114
|
+
}): string;
|
|
115
|
+
/**
|
|
116
|
+
* Track final output
|
|
117
|
+
*/
|
|
118
|
+
trackOutput(options: {
|
|
119
|
+
finalOutput?: string;
|
|
120
|
+
outputLength?: number;
|
|
121
|
+
}): string;
|
|
122
|
+
/**
|
|
123
|
+
* Execute a function within a span context (for nested operations)
|
|
124
|
+
* This allows tool calls to be nested under LLM calls, etc.
|
|
125
|
+
*/
|
|
126
|
+
withSpan<T>(spanId: string, fn: () => T): T;
|
|
127
|
+
/**
|
|
128
|
+
* Execute an async function within a span context (for nested operations)
|
|
129
|
+
*/
|
|
130
|
+
withSpanAsync<T>(spanId: string, fn: () => Promise<T>): Promise<T>;
|
|
131
|
+
/**
|
|
132
|
+
* End trace and send events (manual trace management)
|
|
133
|
+
*/
|
|
134
|
+
endTrace(options?: {
|
|
135
|
+
outcome?: "success" | "error" | "timeout";
|
|
136
|
+
}): Promise<string>;
|
|
137
|
+
/**
|
|
138
|
+
* Convert legacy TraceData to canonical events
|
|
139
|
+
*/
|
|
140
|
+
private traceDataToCanonicalEvents;
|
|
141
|
+
/**
|
|
142
|
+
* Internal flush implementation
|
|
143
|
+
*/
|
|
144
|
+
private _doFlush;
|
|
145
|
+
/**
|
|
146
|
+
* Send canonical events with exponential backoff retry
|
|
147
|
+
*/
|
|
148
|
+
private _sendEventsWithRetry;
|
|
149
|
+
/**
|
|
150
|
+
* Cleanup (call when shutting down)
|
|
151
|
+
*/
|
|
152
|
+
end(): Promise<void>;
|
|
153
|
+
track(event: TrackEventInput, action: () => Promise<Response>, options?: {
|
|
154
|
+
trackBlocking?: boolean;
|
|
155
|
+
}): Promise<any>;
|
|
28
156
|
private captureStream;
|
|
29
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Send canonical events to Observa backend
|
|
159
|
+
* (internal method, use _sendEventsWithRetry for retry logic)
|
|
160
|
+
*/
|
|
161
|
+
private sendEvents;
|
|
30
162
|
}
|
|
31
163
|
declare const init: (config: ObservaInitConfig) => Observa;
|
|
32
164
|
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ interface TrackEventInput {
|
|
|
13
13
|
context?: string;
|
|
14
14
|
model?: string;
|
|
15
15
|
metadata?: Record<string, any>;
|
|
16
|
+
conversationId?: string;
|
|
17
|
+
sessionId?: string;
|
|
18
|
+
userId?: string;
|
|
19
|
+
messageIndex?: number;
|
|
20
|
+
parentMessageId?: string;
|
|
16
21
|
}
|
|
17
22
|
declare class Observa {
|
|
18
23
|
private apiKey;
|
|
@@ -23,10 +28,137 @@ declare class Observa {
|
|
|
23
28
|
private isProduction;
|
|
24
29
|
private sampleRate;
|
|
25
30
|
private maxResponseChars;
|
|
31
|
+
private eventBuffer;
|
|
32
|
+
private flushPromise;
|
|
33
|
+
private flushInProgress;
|
|
34
|
+
private maxBufferSize;
|
|
35
|
+
private flushIntervalMs;
|
|
36
|
+
private flushIntervalId;
|
|
37
|
+
private currentTraceId;
|
|
38
|
+
private rootSpanId;
|
|
39
|
+
private spanStack;
|
|
40
|
+
private traceStartTime;
|
|
26
41
|
constructor(config: ObservaInitConfig);
|
|
27
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Flush buffered events to the API
|
|
44
|
+
* Returns a promise that resolves when all events are sent
|
|
45
|
+
*/
|
|
46
|
+
flush(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Helper: Create base event properties
|
|
49
|
+
*/
|
|
50
|
+
private createBaseEventProperties;
|
|
51
|
+
/**
|
|
52
|
+
* Helper: Add event to buffer with proper span hierarchy
|
|
53
|
+
*/
|
|
54
|
+
private addEvent;
|
|
55
|
+
/**
|
|
56
|
+
* Start a new trace (manual trace management)
|
|
57
|
+
*/
|
|
58
|
+
startTrace(options?: {
|
|
59
|
+
name?: string;
|
|
60
|
+
metadata?: Record<string, any>;
|
|
61
|
+
conversationId?: string;
|
|
62
|
+
sessionId?: string;
|
|
63
|
+
userId?: string;
|
|
64
|
+
}): string;
|
|
65
|
+
/**
|
|
66
|
+
* Track a tool call
|
|
67
|
+
*/
|
|
68
|
+
trackToolCall(options: {
|
|
69
|
+
toolName: string;
|
|
70
|
+
args?: Record<string, any>;
|
|
71
|
+
result?: any;
|
|
72
|
+
resultStatus: "success" | "error" | "timeout";
|
|
73
|
+
latencyMs: number;
|
|
74
|
+
errorMessage?: string;
|
|
75
|
+
}): string;
|
|
76
|
+
/**
|
|
77
|
+
* Track a retrieval operation
|
|
78
|
+
*/
|
|
79
|
+
trackRetrieval(options: {
|
|
80
|
+
contextIds?: string[];
|
|
81
|
+
contextHashes?: string[];
|
|
82
|
+
k?: number;
|
|
83
|
+
similarityScores?: number[];
|
|
84
|
+
latencyMs: number;
|
|
85
|
+
}): string;
|
|
86
|
+
/**
|
|
87
|
+
* Track an error with stack trace support
|
|
88
|
+
*/
|
|
89
|
+
trackError(options: {
|
|
90
|
+
errorType: string;
|
|
91
|
+
errorMessage: string;
|
|
92
|
+
stackTrace?: string;
|
|
93
|
+
context?: Record<string, any>;
|
|
94
|
+
error?: Error;
|
|
95
|
+
}): string;
|
|
96
|
+
/**
|
|
97
|
+
* Track user feedback
|
|
98
|
+
*/
|
|
99
|
+
trackFeedback(options: {
|
|
100
|
+
type: "like" | "dislike" | "rating" | "correction";
|
|
101
|
+
rating?: number;
|
|
102
|
+
comment?: string;
|
|
103
|
+
outcome?: "success" | "failure" | "partial";
|
|
104
|
+
conversationId?: string;
|
|
105
|
+
sessionId?: string;
|
|
106
|
+
userId?: string;
|
|
107
|
+
messageIndex?: number;
|
|
108
|
+
parentMessageId?: string;
|
|
109
|
+
agentName?: string;
|
|
110
|
+
version?: string;
|
|
111
|
+
route?: string;
|
|
112
|
+
parentSpanId?: string | null;
|
|
113
|
+
spanId?: string;
|
|
114
|
+
}): string;
|
|
115
|
+
/**
|
|
116
|
+
* Track final output
|
|
117
|
+
*/
|
|
118
|
+
trackOutput(options: {
|
|
119
|
+
finalOutput?: string;
|
|
120
|
+
outputLength?: number;
|
|
121
|
+
}): string;
|
|
122
|
+
/**
|
|
123
|
+
* Execute a function within a span context (for nested operations)
|
|
124
|
+
* This allows tool calls to be nested under LLM calls, etc.
|
|
125
|
+
*/
|
|
126
|
+
withSpan<T>(spanId: string, fn: () => T): T;
|
|
127
|
+
/**
|
|
128
|
+
* Execute an async function within a span context (for nested operations)
|
|
129
|
+
*/
|
|
130
|
+
withSpanAsync<T>(spanId: string, fn: () => Promise<T>): Promise<T>;
|
|
131
|
+
/**
|
|
132
|
+
* End trace and send events (manual trace management)
|
|
133
|
+
*/
|
|
134
|
+
endTrace(options?: {
|
|
135
|
+
outcome?: "success" | "error" | "timeout";
|
|
136
|
+
}): Promise<string>;
|
|
137
|
+
/**
|
|
138
|
+
* Convert legacy TraceData to canonical events
|
|
139
|
+
*/
|
|
140
|
+
private traceDataToCanonicalEvents;
|
|
141
|
+
/**
|
|
142
|
+
* Internal flush implementation
|
|
143
|
+
*/
|
|
144
|
+
private _doFlush;
|
|
145
|
+
/**
|
|
146
|
+
* Send canonical events with exponential backoff retry
|
|
147
|
+
*/
|
|
148
|
+
private _sendEventsWithRetry;
|
|
149
|
+
/**
|
|
150
|
+
* Cleanup (call when shutting down)
|
|
151
|
+
*/
|
|
152
|
+
end(): Promise<void>;
|
|
153
|
+
track(event: TrackEventInput, action: () => Promise<Response>, options?: {
|
|
154
|
+
trackBlocking?: boolean;
|
|
155
|
+
}): Promise<any>;
|
|
28
156
|
private captureStream;
|
|
29
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Send canonical events to Observa backend
|
|
159
|
+
* (internal method, use _sendEventsWithRetry for retry logic)
|
|
160
|
+
*/
|
|
161
|
+
private sendEvents;
|
|
30
162
|
}
|
|
31
163
|
declare const init: (config: ObservaInitConfig) => Observa;
|
|
32
164
|
|