@fallom/trace 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +275 -0
- package/dist/index.d.mts +245 -0
- package/dist/index.d.ts +245 -0
- package/dist/index.js +1049 -0
- package/dist/index.mjs +1032 -0
- package/package.json +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fallom tracing module.
|
|
3
|
+
*
|
|
4
|
+
* Auto-instruments all LLM calls via OTEL and groups them by session.
|
|
5
|
+
* Also supports custom spans for business metrics.
|
|
6
|
+
*/
|
|
7
|
+
interface SessionContext {
|
|
8
|
+
configKey: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Initialize Fallom tracing. Auto-instruments all LLM calls.
|
|
13
|
+
*
|
|
14
|
+
* @param options - Configuration options
|
|
15
|
+
* @param options.apiKey - Your Fallom API key. Defaults to FALLOM_API_KEY env var.
|
|
16
|
+
* @param options.baseUrl - API base URL. Defaults to FALLOM_BASE_URL env var, or https://spans.fallom.com
|
|
17
|
+
* @param options.captureContent - Whether to capture prompt/completion content in traces.
|
|
18
|
+
* Set to false for privacy/compliance. Defaults to true.
|
|
19
|
+
* Also respects FALLOM_CAPTURE_CONTENT env var ("true"/"false").
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import fallom from 'fallom';
|
|
24
|
+
*
|
|
25
|
+
* // Normal usage (captures everything)
|
|
26
|
+
* fallom.trace.init();
|
|
27
|
+
*
|
|
28
|
+
* // Privacy mode (no prompts/completions stored)
|
|
29
|
+
* fallom.trace.init({ captureContent: false });
|
|
30
|
+
*
|
|
31
|
+
* fallom.trace.setSession("my-agent", sessionId);
|
|
32
|
+
* await agent.run(message); // Automatically traced
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function init$2(options?: {
|
|
36
|
+
apiKey?: string;
|
|
37
|
+
baseUrl?: string;
|
|
38
|
+
captureContent?: boolean;
|
|
39
|
+
}): void;
|
|
40
|
+
/**
|
|
41
|
+
* Set the current session context.
|
|
42
|
+
*
|
|
43
|
+
* All subsequent LLM calls in this async context will be
|
|
44
|
+
* automatically tagged with this configKey and sessionId.
|
|
45
|
+
*
|
|
46
|
+
* @param configKey - Your config name (e.g., "linkedin-agent")
|
|
47
|
+
* @param sessionId - Your session/conversation ID
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* trace.setSession("linkedin-agent", sessionId);
|
|
52
|
+
* await agent.run(message); // Automatically traced with session
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare function setSession(configKey: string, sessionId: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Run a function with session context.
|
|
58
|
+
* Use this to ensure session context propagates across async boundaries.
|
|
59
|
+
*
|
|
60
|
+
* @param configKey - Your config name
|
|
61
|
+
* @param sessionId - Your session ID
|
|
62
|
+
* @param fn - Function to run with session context
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* await trace.runWithSession("my-agent", sessionId, async () => {
|
|
67
|
+
* await agent.run(message); // Has session context
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function runWithSession<T>(configKey: string, sessionId: string, fn: () => T): T;
|
|
72
|
+
/**
|
|
73
|
+
* Get current session context, if any.
|
|
74
|
+
*/
|
|
75
|
+
declare function getSession(): SessionContext | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Clear session context.
|
|
78
|
+
*/
|
|
79
|
+
declare function clearSession(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Record custom business metrics. Latest value per field wins.
|
|
82
|
+
*
|
|
83
|
+
* Use this for metrics that OTEL can't capture automatically:
|
|
84
|
+
* - Outlier scores
|
|
85
|
+
* - Engagement metrics
|
|
86
|
+
* - Conversion rates
|
|
87
|
+
* - Any business-specific outcome
|
|
88
|
+
*
|
|
89
|
+
* @param data - Dict of metrics to record
|
|
90
|
+
* @param options - Optional session identifiers
|
|
91
|
+
* @param options.configKey - Config name (optional if setSession was called)
|
|
92
|
+
* @param options.sessionId - Session ID (optional if setSession was called)
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* // If session context is set:
|
|
97
|
+
* trace.span({ outlier_score: 0.8, engagement: 42 });
|
|
98
|
+
*
|
|
99
|
+
* // Or explicitly:
|
|
100
|
+
* trace.span(
|
|
101
|
+
* { outlier_score: 0.8 },
|
|
102
|
+
* { configKey: "linkedin-agent", sessionId: "user123-convo456" }
|
|
103
|
+
* );
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function span(data: Record<string, unknown>, options?: {
|
|
107
|
+
configKey?: string;
|
|
108
|
+
sessionId?: string;
|
|
109
|
+
}): void;
|
|
110
|
+
/**
|
|
111
|
+
* Shutdown the tracing SDK gracefully.
|
|
112
|
+
*/
|
|
113
|
+
declare function shutdown(): Promise<void>;
|
|
114
|
+
|
|
115
|
+
declare const trace_clearSession: typeof clearSession;
|
|
116
|
+
declare const trace_getSession: typeof getSession;
|
|
117
|
+
declare const trace_runWithSession: typeof runWithSession;
|
|
118
|
+
declare const trace_setSession: typeof setSession;
|
|
119
|
+
declare const trace_shutdown: typeof shutdown;
|
|
120
|
+
declare const trace_span: typeof span;
|
|
121
|
+
declare namespace trace {
|
|
122
|
+
export { trace_clearSession as clearSession, trace_getSession as getSession, init$2 as init, trace_runWithSession as runWithSession, trace_setSession as setSession, trace_shutdown as shutdown, trace_span as span };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Fallom models module.
|
|
127
|
+
*
|
|
128
|
+
* Provides model A/B testing with versioned configs.
|
|
129
|
+
* Zero latency on get() - uses local hash + cached config.
|
|
130
|
+
*
|
|
131
|
+
* Design principles:
|
|
132
|
+
* - Never block user's app if Fallom is down
|
|
133
|
+
* - Very short timeouts (1-2 seconds max)
|
|
134
|
+
* - Always return a usable model (fallback if needed)
|
|
135
|
+
* - Background sync keeps configs fresh
|
|
136
|
+
*/
|
|
137
|
+
/**
|
|
138
|
+
* Initialize Fallom models.
|
|
139
|
+
*
|
|
140
|
+
* This is optional - get() will auto-init if needed.
|
|
141
|
+
* Non-blocking: starts background config fetch immediately.
|
|
142
|
+
*/
|
|
143
|
+
declare function init$1(options?: {
|
|
144
|
+
apiKey?: string;
|
|
145
|
+
baseUrl?: string;
|
|
146
|
+
}): void;
|
|
147
|
+
/**
|
|
148
|
+
* Get model assignment for a session.
|
|
149
|
+
*
|
|
150
|
+
* This is zero latency - uses local hash computation + cached config.
|
|
151
|
+
* No network call on the hot path.
|
|
152
|
+
*
|
|
153
|
+
* Same session_id always returns same model (sticky assignment).
|
|
154
|
+
*
|
|
155
|
+
* Also automatically sets trace context, so all subsequent LLM calls
|
|
156
|
+
* are tagged with this session.
|
|
157
|
+
*
|
|
158
|
+
* @param configKey - Your config name (e.g., "linkedin-agent")
|
|
159
|
+
* @param sessionId - Your session/conversation ID (must be consistent)
|
|
160
|
+
* @param options - Optional settings
|
|
161
|
+
* @param options.version - Pin to specific version (1, 2, etc). undefined = latest
|
|
162
|
+
* @param options.fallback - Model to return if config not found or Fallom is down
|
|
163
|
+
* @param options.debug - Enable debug logging
|
|
164
|
+
* @returns Model string (e.g., "claude-opus", "gpt-4o")
|
|
165
|
+
* @throws Error if config not found AND no fallback provided
|
|
166
|
+
*/
|
|
167
|
+
declare function get(configKey: string, sessionId: string, options?: {
|
|
168
|
+
version?: number;
|
|
169
|
+
fallback?: string;
|
|
170
|
+
debug?: boolean;
|
|
171
|
+
}): Promise<string>;
|
|
172
|
+
|
|
173
|
+
declare const models_get: typeof get;
|
|
174
|
+
declare namespace models {
|
|
175
|
+
export { models_get as get, init$1 as init };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Combined initialization for both trace and models.
|
|
180
|
+
*/
|
|
181
|
+
interface InitOptions {
|
|
182
|
+
apiKey?: string;
|
|
183
|
+
baseUrl?: string;
|
|
184
|
+
captureContent?: boolean;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Initialize both trace and models at once.
|
|
188
|
+
*
|
|
189
|
+
* @param options - Configuration options
|
|
190
|
+
* @param options.apiKey - Your Fallom API key. Defaults to FALLOM_API_KEY env var.
|
|
191
|
+
* @param options.baseUrl - API base URL. Defaults to FALLOM_BASE_URL or https://spans.fallom.com
|
|
192
|
+
* @param options.captureContent - Whether to capture prompt/completion content (default: true)
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* import fallom from 'fallom';
|
|
197
|
+
*
|
|
198
|
+
* // Basic initialization
|
|
199
|
+
* fallom.init({ apiKey: "your-api-key" });
|
|
200
|
+
*
|
|
201
|
+
* // Local development
|
|
202
|
+
* fallom.init({ baseUrl: "http://localhost:8001" });
|
|
203
|
+
*
|
|
204
|
+
* // Privacy mode
|
|
205
|
+
* fallom.init({ captureContent: false });
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
declare function init(options?: InitOptions): void;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Fallom - Model A/B testing and tracing for LLM applications.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* import fallom from 'fallom';
|
|
216
|
+
*
|
|
217
|
+
* // Initialize (call this early, before LLM imports if possible)
|
|
218
|
+
* fallom.init({ apiKey: "your-api-key" });
|
|
219
|
+
*
|
|
220
|
+
* // Set session context for tracing
|
|
221
|
+
* fallom.trace.setSession("my-agent", sessionId);
|
|
222
|
+
*
|
|
223
|
+
* // Get A/B tested model
|
|
224
|
+
* const model = await fallom.models.get("my-config", sessionId, {
|
|
225
|
+
* fallback: "gpt-4o-mini"
|
|
226
|
+
* });
|
|
227
|
+
*
|
|
228
|
+
* // Use with OpenAI
|
|
229
|
+
* const response = await openai.chat.completions.create({
|
|
230
|
+
* model,
|
|
231
|
+
* messages: [...]
|
|
232
|
+
* });
|
|
233
|
+
*
|
|
234
|
+
* // Record custom metrics
|
|
235
|
+
* fallom.trace.span({ user_satisfaction: 5 });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
|
|
239
|
+
declare const _default: {
|
|
240
|
+
init: typeof init;
|
|
241
|
+
trace: typeof trace;
|
|
242
|
+
models: typeof models;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
export { type InitOptions, _default as default, init, models, trace };
|