@lelemon-ai/trace 0.0.0-stage → 0.12.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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1183 -2
  3. package/dist/anthropic.d.mts +25 -0
  4. package/dist/anthropic.d.ts +25 -0
  5. package/dist/anthropic.js +4 -0
  6. package/dist/anthropic.mjs +4 -0
  7. package/dist/bedrock.d.mts +25 -0
  8. package/dist/bedrock.d.ts +25 -0
  9. package/dist/bedrock.js +4 -0
  10. package/dist/bedrock.mjs +4 -0
  11. package/dist/capture-CC6pIfa4.d.mts +354 -0
  12. package/dist/capture-CC6pIfa4.d.ts +354 -0
  13. package/dist/express-BrfMWEVl.d.mts +67 -0
  14. package/dist/express-BrfMWEVl.d.ts +67 -0
  15. package/dist/express.d.mts +1 -0
  16. package/dist/express.d.ts +1 -0
  17. package/dist/express.js +3 -0
  18. package/dist/express.mjs +3 -0
  19. package/dist/gemini.d.mts +28 -0
  20. package/dist/gemini.d.ts +28 -0
  21. package/dist/gemini.js +4 -0
  22. package/dist/gemini.mjs +4 -0
  23. package/dist/google-genai.d.mts +31 -0
  24. package/dist/google-genai.d.ts +31 -0
  25. package/dist/google-genai.js +4 -0
  26. package/dist/google-genai.mjs +4 -0
  27. package/dist/hono-MTDbviM5.d.mts +80 -0
  28. package/dist/hono-MTDbviM5.d.ts +80 -0
  29. package/dist/hono.d.mts +1 -0
  30. package/dist/hono.d.ts +1 -0
  31. package/dist/hono.js +3 -0
  32. package/dist/hono.mjs +3 -0
  33. package/dist/index.d.mts +40 -0
  34. package/dist/index.d.ts +40 -0
  35. package/dist/index.js +4 -0
  36. package/dist/index.mjs +4 -0
  37. package/dist/integrations.d.mts +4 -0
  38. package/dist/integrations.d.ts +4 -0
  39. package/dist/integrations.js +3 -0
  40. package/dist/integrations.mjs +3 -0
  41. package/dist/lambda-Drx54kXf.d.mts +79 -0
  42. package/dist/lambda-Drx54kXf.d.ts +79 -0
  43. package/dist/lambda.d.mts +1 -0
  44. package/dist/lambda.d.ts +1 -0
  45. package/dist/lambda.js +3 -0
  46. package/dist/lambda.mjs +3 -0
  47. package/dist/next-DONwf0f5.d.mts +100 -0
  48. package/dist/next-DONwf0f5.d.ts +100 -0
  49. package/dist/next.d.mts +1 -0
  50. package/dist/next.d.ts +1 -0
  51. package/dist/next.js +3 -0
  52. package/dist/next.mjs +3 -0
  53. package/dist/openai.d.mts +25 -0
  54. package/dist/openai.d.ts +25 -0
  55. package/dist/openai.js +4 -0
  56. package/dist/openai.mjs +4 -0
  57. package/dist/openrouter.d.mts +33 -0
  58. package/dist/openrouter.d.ts +33 -0
  59. package/dist/openrouter.js +4 -0
  60. package/dist/openrouter.mjs +4 -0
  61. package/package.json +173 -4
@@ -0,0 +1,354 @@
1
+ /**
2
+ * Core types for Lelemon SDK
3
+ */
4
+ interface ServiceConfig {
5
+ /** Service name (e.g., "my-ai-chatbot") */
6
+ name?: string;
7
+ /** Service version (e.g., "1.2.3") */
8
+ version?: string;
9
+ /** Deployment environment (e.g., "production", "staging", "development") */
10
+ environment?: string;
11
+ }
12
+ interface RedactionConfig {
13
+ /** Custom regex patterns to redact (replaced with [REDACTED]) */
14
+ patterns?: RegExp[];
15
+ /** Additional key names to redact (case-insensitive, partial match) */
16
+ keys?: string[];
17
+ /** Redact all email addresses (replaced with [EMAIL]) */
18
+ emails?: boolean;
19
+ /** Redact phone numbers with 9+ digits (replaced with [PHONE]) */
20
+ phones?: boolean;
21
+ }
22
+ interface LelemonConfig {
23
+ /** API key (or set LELEMON_API_KEY env var) */
24
+ apiKey?: string;
25
+ /** API endpoint (default: https://api.lelemon.dev) */
26
+ endpoint?: string;
27
+ /** Enable debug logging */
28
+ debug?: boolean;
29
+ /** Disable tracing */
30
+ disabled?: boolean;
31
+ /** Batch size before flush (default: 10) */
32
+ batchSize?: number;
33
+ /** Auto-flush interval in ms (default: 1000) */
34
+ flushIntervalMs?: number;
35
+ /** Request timeout in ms (default: 10000) */
36
+ requestTimeoutMs?: number;
37
+ /** Service metadata for telemetry */
38
+ service?: ServiceConfig;
39
+ /** Optional PII redaction configuration */
40
+ redaction?: RedactionConfig;
41
+ }
42
+ interface SDKTelemetry {
43
+ /** SDK name */
44
+ 'telemetry.sdk.name': string;
45
+ /** SDK version */
46
+ 'telemetry.sdk.version': string;
47
+ /** SDK language */
48
+ 'telemetry.sdk.language': string;
49
+ /** Runtime name (nodejs, deno, bun, browser) */
50
+ 'process.runtime.name'?: string;
51
+ /** Runtime version */
52
+ 'process.runtime.version'?: string;
53
+ /** OS type (linux, darwin, windows) */
54
+ 'os.type'?: string;
55
+ /** Service name */
56
+ 'service.name'?: string;
57
+ /** Service version */
58
+ 'service.version'?: string;
59
+ /** Deployment environment */
60
+ 'deployment.environment'?: string;
61
+ }
62
+ type ProviderName = 'openai' | 'anthropic' | 'gemini' | 'bedrock' | 'openrouter' | 'agent' | 'unknown';
63
+ interface ObserveOptions {
64
+ /** Session ID to group related calls */
65
+ sessionId?: string;
66
+ /** User ID for the end user */
67
+ userId?: string;
68
+ /** Custom metadata added to all traces */
69
+ metadata?: Record<string, unknown>;
70
+ /** Tags for filtering */
71
+ tags?: string[];
72
+ }
73
+ type SpanType = 'llm' | 'agent' | 'tool' | 'retrieval' | 'embedding' | 'guardrail' | 'rerank' | 'custom';
74
+ interface CaptureSpanOptions {
75
+ /** Span type */
76
+ type: SpanType;
77
+ /** Span name (tool name, retrieval source, custom name) */
78
+ name: string;
79
+ /** Input data */
80
+ input: unknown;
81
+ /** Output data */
82
+ output: unknown;
83
+ /** Duration in milliseconds */
84
+ durationMs: number;
85
+ /** Status */
86
+ status?: 'success' | 'error';
87
+ /** Error message if status is 'error' */
88
+ errorMessage?: string;
89
+ /** Tool call ID (for linking tool results) */
90
+ toolCallId?: string;
91
+ /** Custom metadata */
92
+ metadata?: Record<string, unknown>;
93
+ /** Session, user, metadata and tags for a span captured outside trace() */
94
+ context?: ObserveOptions;
95
+ }
96
+
97
+ /**
98
+ * Global Configuration
99
+ *
100
+ * Manages SDK configuration and transport instance.
101
+ */
102
+
103
+ /**
104
+ * Initialize the SDK
105
+ * Call once at app startup
106
+ */
107
+ declare function init(config?: LelemonConfig): void;
108
+ /**
109
+ * Check if SDK is enabled
110
+ */
111
+ declare function isEnabled(): boolean;
112
+ /**
113
+ * Flush all pending traces
114
+ */
115
+ declare function flush(): Promise<void>;
116
+
117
+ /**
118
+ * Trace Context Module
119
+ *
120
+ * Provides AsyncLocalStorage-based context for grouping spans under a parent trace.
121
+ * Supports hierarchical tracing where:
122
+ * - trace() creates a root "agent" span
123
+ * - LLM calls become children of the root
124
+ * - Tool calls become children of the LLM that triggered them (via toolCallId linking)
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { trace, span } from '@lelemon-ai/trace';
129
+ *
130
+ * await trace({ name: 'sales-agent', input: userMessage }, async () => {
131
+ * const response = await client.send(new ConverseCommand({...}));
132
+ * // Tools automatically linked to their parent LLM via toolCallId
133
+ * return response;
134
+ * });
135
+ * ```
136
+ */
137
+ interface TraceContext {
138
+ /** Unique trace ID (shared by all spans in this trace) */
139
+ traceId: string;
140
+ /** Root span ID (the agent/workflow span) */
141
+ rootSpanId: string;
142
+ /** Current span ID (for nesting - LLM calls become children of this) */
143
+ currentSpanId: string;
144
+ /** Parent span ID (for nested trace() calls) */
145
+ parentSpanId?: string;
146
+ /** Trace name */
147
+ name: string;
148
+ /** Start time in ms */
149
+ startTime: number;
150
+ /** Input data */
151
+ input?: unknown;
152
+ /** Trace metadata */
153
+ metadata?: Record<string, unknown>;
154
+ /** Trace tags */
155
+ tags?: string[];
156
+ /** Output extraction config */
157
+ outputKey?: string | false;
158
+ /** Output transform function */
159
+ outputTransform?: (result: unknown) => unknown;
160
+ /** Session ID for grouping traces */
161
+ sessionId?: string;
162
+ /** User ID for filtering by user */
163
+ userId?: string;
164
+ /** Visual styling options */
165
+ style?: StyleOptions;
166
+ /** Map of toolCallId → llmSpanId for linking tool spans to their parent LLM */
167
+ pendingToolCalls: Map<string, string>;
168
+ }
169
+ /** Visual styling options for traces and spans in the Lelemon dashboard */
170
+ interface StyleOptions {
171
+ /** Hex color for the trace/span (e.g., '#22c55e') */
172
+ color?: string;
173
+ /** Emoji or icon name displayed next to the name (e.g., '🛒', '🤖', '🔍') */
174
+ icon?: string;
175
+ /** Short label shown as a badge (e.g., 'Sales', 'Support', 'RAG') */
176
+ label?: string;
177
+ }
178
+ interface TraceOptions {
179
+ /** Name for the trace (e.g., 'sales-agent', 'rag-query') */
180
+ name: string;
181
+ /** Input data for the trace */
182
+ input?: unknown;
183
+ /** Custom metadata */
184
+ metadata?: Record<string, unknown>;
185
+ /** Tags for filtering */
186
+ tags?: string[];
187
+ /** Visual styling in the dashboard */
188
+ style?: StyleOptions;
189
+ /**
190
+ * Key to extract from result object for cleaner output display.
191
+ * If not specified, auto-detection tries: text, content, message, output, response, result, answer.
192
+ * Set to `false` to disable auto-extraction and show raw result.
193
+ *
194
+ * @example
195
+ * // Auto-extract 'text' field
196
+ * trace({ name: 'agent' }, async () => ({ text: 'hello', tokens: 100 }));
197
+ * // Output: "hello"
198
+ *
199
+ * @example
200
+ * // Explicit key
201
+ * trace({ name: 'agent', outputKey: 'response' }, async () => ({ response: 'hello' }));
202
+ *
203
+ * @example
204
+ * // Disable auto-extraction
205
+ * trace({ name: 'agent', outputKey: false }, async () => ({ a: 1, b: 2 }));
206
+ * // Output: { a: 1, b: 2 }
207
+ */
208
+ outputKey?: string | false;
209
+ /**
210
+ * Transform function for custom output formatting.
211
+ * Takes precedence over outputKey.
212
+ *
213
+ * @example
214
+ * trace({
215
+ * name: 'agent',
216
+ * outputTransform: (r) => `Response: ${r.text} (${r.tokens} tokens)`
217
+ * }, async () => ({ text: 'hello', tokens: 100 }));
218
+ * // Output: "Response: hello (100 tokens)"
219
+ */
220
+ outputTransform?: (result: unknown) => unknown;
221
+ /**
222
+ * Session ID for grouping related traces (e.g., conversation ID).
223
+ * Useful for multi-tenant servers where each request has different context.
224
+ */
225
+ sessionId?: string;
226
+ /**
227
+ * User ID for filtering traces by user.
228
+ * Useful for multi-tenant servers where each request has different context.
229
+ */
230
+ userId?: string;
231
+ }
232
+ interface SpanOptions {
233
+ /** Span type */
234
+ type: 'retrieval' | 'embedding' | 'tool' | 'guardrail' | 'rerank' | 'custom';
235
+ /** Span name (e.g., 'pinecone-search', 'cohere-rerank') */
236
+ name: string;
237
+ /** Input data */
238
+ input?: unknown;
239
+ /** Output data */
240
+ output?: unknown;
241
+ /** Duration in milliseconds (optional, will be set automatically if not provided) */
242
+ durationMs?: number;
243
+ /** Status */
244
+ status?: 'success' | 'error';
245
+ /** Error message if status is 'error' */
246
+ errorMessage?: string;
247
+ /** Tool call ID (links this tool span to the LLM that requested it) */
248
+ toolCallId?: string;
249
+ /** Custom metadata */
250
+ metadata?: Record<string, unknown>;
251
+ /** Visual styling in the dashboard */
252
+ style?: StyleOptions;
253
+ }
254
+ /**
255
+ * Get the current trace context, if any
256
+ */
257
+ declare function getTraceContext(): TraceContext | undefined;
258
+ /**
259
+ * Execute a function within a trace context.
260
+ * Creates a root "agent" span that contains all LLM calls and tool executions.
261
+ *
262
+ * **Output Auto-Extraction:** If the function returns an object with common text fields
263
+ * (`text`, `content`, `message`, `output`, `response`, `result`, `answer`),
264
+ * the SDK automatically extracts that field for cleaner display.
265
+ * Use `outputKey` to specify a custom field, or `outputKey: false` to disable.
266
+ *
267
+ * @example Simple usage
268
+ * ```typescript
269
+ * await trace('sales-agent', async () => {
270
+ * return { text: 'Hello!', tokens: 100 };
271
+ * // Output shown: "Hello!" (auto-extracted from 'text')
272
+ * });
273
+ * ```
274
+ *
275
+ * @example With options and explicit outputKey
276
+ * ```typescript
277
+ * await trace({ name: 'agent', outputKey: 'reply' }, async () => {
278
+ * return { reply: 'Hello!', cost: 0.01 };
279
+ * // Output shown: "Hello!"
280
+ * });
281
+ * ```
282
+ *
283
+ * @example Disable auto-extraction
284
+ * ```typescript
285
+ * await trace({ name: 'agent', outputKey: false }, async () => {
286
+ * return { a: 1, b: 2 };
287
+ * // Output shown: { a: 1, b: 2 }
288
+ * });
289
+ * ```
290
+ */
291
+ declare function trace<T>(nameOrOptions: string | TraceOptions, fn: () => Promise<T>): Promise<T>;
292
+ /**
293
+ * Manually capture a span for non-LLM operations (retrieval, embedding, tool, etc.)
294
+ * Must be called within a trace() block.
295
+ *
296
+ * @example Tool with toolCallId (links to parent LLM)
297
+ * ```typescript
298
+ * span({
299
+ * type: 'tool',
300
+ * name: 'query_database',
301
+ * toolCallId: 'tooluse_abc123', // Links to LLM that requested this
302
+ * input: { sql: 'SELECT ...' },
303
+ * output: { rows: [...] },
304
+ * durationMs: 15,
305
+ * });
306
+ * ```
307
+ *
308
+ * @example Retrieval without toolCallId
309
+ * ```typescript
310
+ * span({
311
+ * type: 'retrieval',
312
+ * name: 'pinecone-search',
313
+ * input: { topK: 5 },
314
+ * output: { count: 10 },
315
+ * durationMs: 50,
316
+ * });
317
+ * ```
318
+ */
319
+ declare function span(options: SpanOptions): void;
320
+
321
+ /**
322
+ * Capture Module
323
+ *
324
+ * Handles trace capture and batching.
325
+ * Called by providers to record LLM calls.
326
+ */
327
+
328
+ /**
329
+ * Manually capture a span (tool call, retrieval, custom)
330
+ * Use this when auto-detection doesn't cover your use case
331
+ *
332
+ * @example
333
+ * // Capture a tool call
334
+ * captureSpan({
335
+ * type: 'tool',
336
+ * name: 'get_weather',
337
+ * input: { location: 'San Francisco' },
338
+ * output: { temperature: 72, conditions: 'sunny' },
339
+ * durationMs: 150,
340
+ * });
341
+ *
342
+ * @example
343
+ * // Capture a retrieval/RAG operation
344
+ * captureSpan({
345
+ * type: 'retrieval',
346
+ * name: 'vector_search',
347
+ * input: { query: 'user question', k: 5 },
348
+ * output: { documents: [...] },
349
+ * durationMs: 50,
350
+ * });
351
+ */
352
+ declare function captureSpan(options: CaptureSpanOptions): void;
353
+
354
+ export { type CaptureSpanOptions as C, type LelemonConfig as L, type ObserveOptions as O, type ProviderName as P, type ServiceConfig as S, type TraceContext as T, isEnabled as a, type SDKTelemetry as b, captureSpan as c, type SpanType as d, type TraceOptions as e, flush as f, getTraceContext as g, type SpanOptions as h, init as i, type StyleOptions as j, span as s, trace as t };
@@ -0,0 +1,354 @@
1
+ /**
2
+ * Core types for Lelemon SDK
3
+ */
4
+ interface ServiceConfig {
5
+ /** Service name (e.g., "my-ai-chatbot") */
6
+ name?: string;
7
+ /** Service version (e.g., "1.2.3") */
8
+ version?: string;
9
+ /** Deployment environment (e.g., "production", "staging", "development") */
10
+ environment?: string;
11
+ }
12
+ interface RedactionConfig {
13
+ /** Custom regex patterns to redact (replaced with [REDACTED]) */
14
+ patterns?: RegExp[];
15
+ /** Additional key names to redact (case-insensitive, partial match) */
16
+ keys?: string[];
17
+ /** Redact all email addresses (replaced with [EMAIL]) */
18
+ emails?: boolean;
19
+ /** Redact phone numbers with 9+ digits (replaced with [PHONE]) */
20
+ phones?: boolean;
21
+ }
22
+ interface LelemonConfig {
23
+ /** API key (or set LELEMON_API_KEY env var) */
24
+ apiKey?: string;
25
+ /** API endpoint (default: https://api.lelemon.dev) */
26
+ endpoint?: string;
27
+ /** Enable debug logging */
28
+ debug?: boolean;
29
+ /** Disable tracing */
30
+ disabled?: boolean;
31
+ /** Batch size before flush (default: 10) */
32
+ batchSize?: number;
33
+ /** Auto-flush interval in ms (default: 1000) */
34
+ flushIntervalMs?: number;
35
+ /** Request timeout in ms (default: 10000) */
36
+ requestTimeoutMs?: number;
37
+ /** Service metadata for telemetry */
38
+ service?: ServiceConfig;
39
+ /** Optional PII redaction configuration */
40
+ redaction?: RedactionConfig;
41
+ }
42
+ interface SDKTelemetry {
43
+ /** SDK name */
44
+ 'telemetry.sdk.name': string;
45
+ /** SDK version */
46
+ 'telemetry.sdk.version': string;
47
+ /** SDK language */
48
+ 'telemetry.sdk.language': string;
49
+ /** Runtime name (nodejs, deno, bun, browser) */
50
+ 'process.runtime.name'?: string;
51
+ /** Runtime version */
52
+ 'process.runtime.version'?: string;
53
+ /** OS type (linux, darwin, windows) */
54
+ 'os.type'?: string;
55
+ /** Service name */
56
+ 'service.name'?: string;
57
+ /** Service version */
58
+ 'service.version'?: string;
59
+ /** Deployment environment */
60
+ 'deployment.environment'?: string;
61
+ }
62
+ type ProviderName = 'openai' | 'anthropic' | 'gemini' | 'bedrock' | 'openrouter' | 'agent' | 'unknown';
63
+ interface ObserveOptions {
64
+ /** Session ID to group related calls */
65
+ sessionId?: string;
66
+ /** User ID for the end user */
67
+ userId?: string;
68
+ /** Custom metadata added to all traces */
69
+ metadata?: Record<string, unknown>;
70
+ /** Tags for filtering */
71
+ tags?: string[];
72
+ }
73
+ type SpanType = 'llm' | 'agent' | 'tool' | 'retrieval' | 'embedding' | 'guardrail' | 'rerank' | 'custom';
74
+ interface CaptureSpanOptions {
75
+ /** Span type */
76
+ type: SpanType;
77
+ /** Span name (tool name, retrieval source, custom name) */
78
+ name: string;
79
+ /** Input data */
80
+ input: unknown;
81
+ /** Output data */
82
+ output: unknown;
83
+ /** Duration in milliseconds */
84
+ durationMs: number;
85
+ /** Status */
86
+ status?: 'success' | 'error';
87
+ /** Error message if status is 'error' */
88
+ errorMessage?: string;
89
+ /** Tool call ID (for linking tool results) */
90
+ toolCallId?: string;
91
+ /** Custom metadata */
92
+ metadata?: Record<string, unknown>;
93
+ /** Session, user, metadata and tags for a span captured outside trace() */
94
+ context?: ObserveOptions;
95
+ }
96
+
97
+ /**
98
+ * Global Configuration
99
+ *
100
+ * Manages SDK configuration and transport instance.
101
+ */
102
+
103
+ /**
104
+ * Initialize the SDK
105
+ * Call once at app startup
106
+ */
107
+ declare function init(config?: LelemonConfig): void;
108
+ /**
109
+ * Check if SDK is enabled
110
+ */
111
+ declare function isEnabled(): boolean;
112
+ /**
113
+ * Flush all pending traces
114
+ */
115
+ declare function flush(): Promise<void>;
116
+
117
+ /**
118
+ * Trace Context Module
119
+ *
120
+ * Provides AsyncLocalStorage-based context for grouping spans under a parent trace.
121
+ * Supports hierarchical tracing where:
122
+ * - trace() creates a root "agent" span
123
+ * - LLM calls become children of the root
124
+ * - Tool calls become children of the LLM that triggered them (via toolCallId linking)
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { trace, span } from '@lelemon-ai/trace';
129
+ *
130
+ * await trace({ name: 'sales-agent', input: userMessage }, async () => {
131
+ * const response = await client.send(new ConverseCommand({...}));
132
+ * // Tools automatically linked to their parent LLM via toolCallId
133
+ * return response;
134
+ * });
135
+ * ```
136
+ */
137
+ interface TraceContext {
138
+ /** Unique trace ID (shared by all spans in this trace) */
139
+ traceId: string;
140
+ /** Root span ID (the agent/workflow span) */
141
+ rootSpanId: string;
142
+ /** Current span ID (for nesting - LLM calls become children of this) */
143
+ currentSpanId: string;
144
+ /** Parent span ID (for nested trace() calls) */
145
+ parentSpanId?: string;
146
+ /** Trace name */
147
+ name: string;
148
+ /** Start time in ms */
149
+ startTime: number;
150
+ /** Input data */
151
+ input?: unknown;
152
+ /** Trace metadata */
153
+ metadata?: Record<string, unknown>;
154
+ /** Trace tags */
155
+ tags?: string[];
156
+ /** Output extraction config */
157
+ outputKey?: string | false;
158
+ /** Output transform function */
159
+ outputTransform?: (result: unknown) => unknown;
160
+ /** Session ID for grouping traces */
161
+ sessionId?: string;
162
+ /** User ID for filtering by user */
163
+ userId?: string;
164
+ /** Visual styling options */
165
+ style?: StyleOptions;
166
+ /** Map of toolCallId → llmSpanId for linking tool spans to their parent LLM */
167
+ pendingToolCalls: Map<string, string>;
168
+ }
169
+ /** Visual styling options for traces and spans in the Lelemon dashboard */
170
+ interface StyleOptions {
171
+ /** Hex color for the trace/span (e.g., '#22c55e') */
172
+ color?: string;
173
+ /** Emoji or icon name displayed next to the name (e.g., '🛒', '🤖', '🔍') */
174
+ icon?: string;
175
+ /** Short label shown as a badge (e.g., 'Sales', 'Support', 'RAG') */
176
+ label?: string;
177
+ }
178
+ interface TraceOptions {
179
+ /** Name for the trace (e.g., 'sales-agent', 'rag-query') */
180
+ name: string;
181
+ /** Input data for the trace */
182
+ input?: unknown;
183
+ /** Custom metadata */
184
+ metadata?: Record<string, unknown>;
185
+ /** Tags for filtering */
186
+ tags?: string[];
187
+ /** Visual styling in the dashboard */
188
+ style?: StyleOptions;
189
+ /**
190
+ * Key to extract from result object for cleaner output display.
191
+ * If not specified, auto-detection tries: text, content, message, output, response, result, answer.
192
+ * Set to `false` to disable auto-extraction and show raw result.
193
+ *
194
+ * @example
195
+ * // Auto-extract 'text' field
196
+ * trace({ name: 'agent' }, async () => ({ text: 'hello', tokens: 100 }));
197
+ * // Output: "hello"
198
+ *
199
+ * @example
200
+ * // Explicit key
201
+ * trace({ name: 'agent', outputKey: 'response' }, async () => ({ response: 'hello' }));
202
+ *
203
+ * @example
204
+ * // Disable auto-extraction
205
+ * trace({ name: 'agent', outputKey: false }, async () => ({ a: 1, b: 2 }));
206
+ * // Output: { a: 1, b: 2 }
207
+ */
208
+ outputKey?: string | false;
209
+ /**
210
+ * Transform function for custom output formatting.
211
+ * Takes precedence over outputKey.
212
+ *
213
+ * @example
214
+ * trace({
215
+ * name: 'agent',
216
+ * outputTransform: (r) => `Response: ${r.text} (${r.tokens} tokens)`
217
+ * }, async () => ({ text: 'hello', tokens: 100 }));
218
+ * // Output: "Response: hello (100 tokens)"
219
+ */
220
+ outputTransform?: (result: unknown) => unknown;
221
+ /**
222
+ * Session ID for grouping related traces (e.g., conversation ID).
223
+ * Useful for multi-tenant servers where each request has different context.
224
+ */
225
+ sessionId?: string;
226
+ /**
227
+ * User ID for filtering traces by user.
228
+ * Useful for multi-tenant servers where each request has different context.
229
+ */
230
+ userId?: string;
231
+ }
232
+ interface SpanOptions {
233
+ /** Span type */
234
+ type: 'retrieval' | 'embedding' | 'tool' | 'guardrail' | 'rerank' | 'custom';
235
+ /** Span name (e.g., 'pinecone-search', 'cohere-rerank') */
236
+ name: string;
237
+ /** Input data */
238
+ input?: unknown;
239
+ /** Output data */
240
+ output?: unknown;
241
+ /** Duration in milliseconds (optional, will be set automatically if not provided) */
242
+ durationMs?: number;
243
+ /** Status */
244
+ status?: 'success' | 'error';
245
+ /** Error message if status is 'error' */
246
+ errorMessage?: string;
247
+ /** Tool call ID (links this tool span to the LLM that requested it) */
248
+ toolCallId?: string;
249
+ /** Custom metadata */
250
+ metadata?: Record<string, unknown>;
251
+ /** Visual styling in the dashboard */
252
+ style?: StyleOptions;
253
+ }
254
+ /**
255
+ * Get the current trace context, if any
256
+ */
257
+ declare function getTraceContext(): TraceContext | undefined;
258
+ /**
259
+ * Execute a function within a trace context.
260
+ * Creates a root "agent" span that contains all LLM calls and tool executions.
261
+ *
262
+ * **Output Auto-Extraction:** If the function returns an object with common text fields
263
+ * (`text`, `content`, `message`, `output`, `response`, `result`, `answer`),
264
+ * the SDK automatically extracts that field for cleaner display.
265
+ * Use `outputKey` to specify a custom field, or `outputKey: false` to disable.
266
+ *
267
+ * @example Simple usage
268
+ * ```typescript
269
+ * await trace('sales-agent', async () => {
270
+ * return { text: 'Hello!', tokens: 100 };
271
+ * // Output shown: "Hello!" (auto-extracted from 'text')
272
+ * });
273
+ * ```
274
+ *
275
+ * @example With options and explicit outputKey
276
+ * ```typescript
277
+ * await trace({ name: 'agent', outputKey: 'reply' }, async () => {
278
+ * return { reply: 'Hello!', cost: 0.01 };
279
+ * // Output shown: "Hello!"
280
+ * });
281
+ * ```
282
+ *
283
+ * @example Disable auto-extraction
284
+ * ```typescript
285
+ * await trace({ name: 'agent', outputKey: false }, async () => {
286
+ * return { a: 1, b: 2 };
287
+ * // Output shown: { a: 1, b: 2 }
288
+ * });
289
+ * ```
290
+ */
291
+ declare function trace<T>(nameOrOptions: string | TraceOptions, fn: () => Promise<T>): Promise<T>;
292
+ /**
293
+ * Manually capture a span for non-LLM operations (retrieval, embedding, tool, etc.)
294
+ * Must be called within a trace() block.
295
+ *
296
+ * @example Tool with toolCallId (links to parent LLM)
297
+ * ```typescript
298
+ * span({
299
+ * type: 'tool',
300
+ * name: 'query_database',
301
+ * toolCallId: 'tooluse_abc123', // Links to LLM that requested this
302
+ * input: { sql: 'SELECT ...' },
303
+ * output: { rows: [...] },
304
+ * durationMs: 15,
305
+ * });
306
+ * ```
307
+ *
308
+ * @example Retrieval without toolCallId
309
+ * ```typescript
310
+ * span({
311
+ * type: 'retrieval',
312
+ * name: 'pinecone-search',
313
+ * input: { topK: 5 },
314
+ * output: { count: 10 },
315
+ * durationMs: 50,
316
+ * });
317
+ * ```
318
+ */
319
+ declare function span(options: SpanOptions): void;
320
+
321
+ /**
322
+ * Capture Module
323
+ *
324
+ * Handles trace capture and batching.
325
+ * Called by providers to record LLM calls.
326
+ */
327
+
328
+ /**
329
+ * Manually capture a span (tool call, retrieval, custom)
330
+ * Use this when auto-detection doesn't cover your use case
331
+ *
332
+ * @example
333
+ * // Capture a tool call
334
+ * captureSpan({
335
+ * type: 'tool',
336
+ * name: 'get_weather',
337
+ * input: { location: 'San Francisco' },
338
+ * output: { temperature: 72, conditions: 'sunny' },
339
+ * durationMs: 150,
340
+ * });
341
+ *
342
+ * @example
343
+ * // Capture a retrieval/RAG operation
344
+ * captureSpan({
345
+ * type: 'retrieval',
346
+ * name: 'vector_search',
347
+ * input: { query: 'user question', k: 5 },
348
+ * output: { documents: [...] },
349
+ * durationMs: 50,
350
+ * });
351
+ */
352
+ declare function captureSpan(options: CaptureSpanOptions): void;
353
+
354
+ export { type CaptureSpanOptions as C, type LelemonConfig as L, type ObserveOptions as O, type ProviderName as P, type ServiceConfig as S, type TraceContext as T, isEnabled as a, type SDKTelemetry as b, captureSpan as c, type SpanType as d, type TraceOptions as e, flush as f, getTraceContext as g, type SpanOptions as h, init as i, type StyleOptions as j, span as s, trace as t };