@lynxops/sdk 1.0.2

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.
@@ -0,0 +1,601 @@
1
+ /**
2
+ * Execution context stored for the active Lynx trace.
3
+ */
4
+ interface LynxContext {
5
+ runId: string;
6
+ agentName: string;
7
+ spanId?: string;
8
+ parentSpanId?: string;
9
+ sampled?: boolean;
10
+ workspaceId?: string;
11
+ agentId?: string;
12
+ sessionId?: string;
13
+ eventCounts?: Record<string, number>;
14
+ attributes?: Record<string, any>;
15
+ }
16
+ /**
17
+ * Options used when starting an agent run.
18
+ */
19
+ interface LynxRunOptions {
20
+ agentName: string;
21
+ workspaceId?: string;
22
+ agentId?: string;
23
+ sessionId?: string;
24
+ runId?: string;
25
+ }
26
+ /**
27
+ * Configuration options for the Lynx SDK runtime.
28
+ */
29
+ interface LynxConfig {
30
+ clientId: string;
31
+ endpoint?: string;
32
+ workspaceId?: string;
33
+ agentId?: string;
34
+ apiKey?: string;
35
+ appVersion?: string;
36
+ deploymentId?: string;
37
+ environment?: string;
38
+ policyVersion?: string;
39
+ /**
40
+ * Telemetry sampling ratio between 0.0 and 1.0.
41
+ *
42
+ * For example, `0.1` captures roughly 10% of traces. When omitted, all traces
43
+ * are captured unless a runtime context overrides sampling.
44
+ */
45
+ sampleRate?: number;
46
+ /**
47
+ * Whether request/input payloads should be captured.
48
+ */
49
+ captureInput?: boolean;
50
+ /**
51
+ * Whether response/output payloads should be captured.
52
+ */
53
+ captureOutput?: boolean;
54
+ /**
55
+ * Maximum serialized payload length for a single event.
56
+ */
57
+ maxPayloadLength?: number;
58
+ /**
59
+ * Telemetry capture and retention mode.
60
+ *
61
+ * - `full`: Capture full input/output payloads.
62
+ * - `metadata-only`: Capture structure, timing, usage, status, and error
63
+ * metadata without raw content.
64
+ * - `smart`: Prefer metadata for normal events while preserving richer
65
+ * details for failures, policy violations, and abnormal latency.
66
+ */
67
+ captureMode?: "full" | "metadata-only" | "smart";
68
+ /**
69
+ * Structured telemetry delivery configuration.
70
+ */
71
+ delivery?: {
72
+ mode?: "BLOCKING" | "BACKGROUND";
73
+ timeoutMs?: number;
74
+ flushOnRunEnd?: boolean;
75
+ flushIntervalMs?: number;
76
+ batchSize?: number;
77
+ maxQueueSize?: number;
78
+ overflowStrategy?: "DROP_OLDEST" | "DROP_NEWEST";
79
+ };
80
+ /**
81
+ * Circuit breaker configuration for telemetry export only.
82
+ */
83
+ circuitBreaker?: {
84
+ enabled?: boolean;
85
+ failureThreshold?: number;
86
+ cooldownMs?: number;
87
+ };
88
+ }
89
+ /**
90
+ * Token usage returned by an LLM provider.
91
+ */
92
+ interface TokenUsage {
93
+ promptTokens: number;
94
+ completionTokens: number;
95
+ totalTokens: number;
96
+ }
97
+ type LynxSessionStatus = "COMPLETED" | "FAILED" | "CANCELLED";
98
+ type LynxBusinessStatus = "SUCCEEDED" | "FAILED" | "PARTIAL" | "UNKNOWN";
99
+ type LynxRiskLevel = "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
100
+ type LynxPolicyAction = "ALLOW" | "BLOCK" | "WARN" | "REQUIRE_APPROVAL" | "REDACT" | "MODIFY";
101
+ type LynxGuardFailureMode = "FAIL_OPEN" | "FAIL_CLOSED" | "REQUIRE_APPROVAL";
102
+ interface LynxOutcomeOptions {
103
+ status: LynxSessionStatus;
104
+ businessStatus?: LynxBusinessStatus;
105
+ reason?: string;
106
+ userImpact?: LynxRiskLevel;
107
+ metadata?: Record<string, any>;
108
+ }
109
+ interface LynxDecisionOptions {
110
+ name: string;
111
+ description?: string;
112
+ selected?: string;
113
+ alternatives?: string[];
114
+ confidence?: number;
115
+ reason?: string;
116
+ metadata?: Record<string, any>;
117
+ }
118
+ interface LynxToolMetadata {
119
+ toolVersion?: string;
120
+ sideEffect?: boolean;
121
+ riskLevel?: LynxRiskLevel;
122
+ externalTarget?: string;
123
+ idempotencyKey?: string;
124
+ failureMode?: LynxGuardFailureMode;
125
+ [key: string]: any;
126
+ }
127
+ interface LynxPolicyDecision {
128
+ allow?: boolean;
129
+ action?: LynxPolicyAction;
130
+ policyId?: string;
131
+ policyVersion?: string;
132
+ reason?: string;
133
+ severity?: LynxRiskLevel;
134
+ metadata?: Record<string, any>;
135
+ }
136
+ interface LynxGuardToolOptions<TArgs extends any[] = any[]> extends LynxToolMetadata {
137
+ beforeCall?: (context: {
138
+ toolName: string;
139
+ input: TArgs[0];
140
+ args: TArgs;
141
+ metadata?: LynxToolMetadata;
142
+ }) => LynxPolicyDecision | Promise<LynxPolicyDecision>;
143
+ }
144
+ interface LynxShutdownOptions {
145
+ timeoutMs?: number;
146
+ }
147
+ interface LynxStatus {
148
+ queueSize: number;
149
+ droppedEvents: number;
150
+ circuitState: "CLOSED" | "OPEN" | "HALF_OPEN" | "DISABLED";
151
+ lastDeliveryAt?: string;
152
+ lastError?: string;
153
+ pendingTransmissions: number;
154
+ }
155
+ /**
156
+ * Custom instrumentation rule for wrapping an LLM client method.
157
+ */
158
+ interface LlmInstrumentationRule {
159
+ /**
160
+ * Returns whether the current method path should be instrumented.
161
+ */
162
+ isTargetMethod: (path: string[]) => boolean;
163
+ /**
164
+ * Extracts prompt or input data from the intercepted method arguments.
165
+ */
166
+ extractInput?: (args: any[]) => any;
167
+ /**
168
+ * Extracts response content or structured output from the method result.
169
+ */
170
+ extractOutput?: (result: any) => any;
171
+ /**
172
+ * Extracts token usage from the method result.
173
+ */
174
+ extractUsage?: (result: any) => TokenUsage | undefined;
175
+ /**
176
+ * Estimates call cost from model and token usage.
177
+ */
178
+ estimateCost?: (model: string, promptTokens: number, completionTokens: number) => number;
179
+ }
180
+ /**
181
+ * Event types captured by the Lynx SDK.
182
+ */
183
+ type LynxEventType = "USER_INPUT" | "AGENT_DECISION" | "LLM_CALL" | "LLM_REASONING" | "TOOL_CALL" | "TOOL_RESULT" | "CALL_TOOLS" | "MEMORY_ACCESS" | "CONTEXT_RETRIEVAL" | "POLICY_EVALUATION" | "POLICY_VIOLATION" | "GUARDRAIL_ACTIVATED" | "SESSION_OUTCOME" | "LOOP_DETECTED" | "ERROR" | "CONTEXT_ALERT";
184
+ /**
185
+ * Event payload schema used for trace, replay, and root-cause analysis.
186
+ */
187
+ interface LynxEventPayloadDto {
188
+ input?: any;
189
+ output?: any;
190
+ error?: string;
191
+ arguments?: any;
192
+ spanId?: string;
193
+ parentSpanId?: string;
194
+ latency?: number;
195
+ usage?: TokenUsage;
196
+ cost?: number;
197
+ provider?: string;
198
+ model?: string;
199
+ temperature?: number;
200
+ topP?: number;
201
+ maxTokens?: number;
202
+ seed?: number | string;
203
+ promptVersion?: string;
204
+ systemPromptHash?: string;
205
+ userPromptHash?: string;
206
+ messageCount?: number;
207
+ contextLength?: number;
208
+ sdkVersion?: string;
209
+ droppedEventCount?: number;
210
+ appVersion?: string;
211
+ deploymentId?: string;
212
+ environment?: string;
213
+ policyVersion?: string;
214
+ toolName?: string;
215
+ toolVersion?: string;
216
+ args?: any;
217
+ argsHash?: string;
218
+ result?: any;
219
+ resultSummary?: string;
220
+ sideEffect?: boolean;
221
+ riskLevel?: LynxRiskLevel;
222
+ externalTarget?: string;
223
+ retryCount?: number;
224
+ idempotencyKey?: string;
225
+ loopDetected?: boolean;
226
+ loopCount?: number;
227
+ repeatedLabel?: string;
228
+ isPolluted?: boolean;
229
+ pollutionReason?: string;
230
+ [key: string]: any;
231
+ }
232
+ interface LynxEventDto {
233
+ eventId?: string;
234
+ clientId: string;
235
+ runId: string;
236
+ agentName: string;
237
+ eventType: LynxEventType;
238
+ label: string;
239
+ payload: LynxEventPayloadDto;
240
+ timestamp: number;
241
+ workspaceId?: string;
242
+ agentId?: string;
243
+ sessionId?: string;
244
+ schemaVersion?: string;
245
+ }
246
+
247
+ declare const DEFAULT_ENDPOINT = "https://api.lynxops.co";
248
+ declare class LynxPolicyError extends Error {
249
+ readonly action: Extract<LynxPolicyAction, "BLOCK" | "REQUIRE_APPROVAL">;
250
+ readonly policyId?: string | undefined;
251
+ readonly severity?: LynxToolMetadata["riskLevel"];
252
+ readonly reason?: string | undefined;
253
+ readonly metadata?: Record<string, any> | undefined;
254
+ constructor(message: string, action: Extract<LynxPolicyAction, "BLOCK" | "REQUIRE_APPROVAL">, policyId?: string | undefined, severity?: LynxToolMetadata["riskLevel"], reason?: string | undefined, metadata?: Record<string, any> | undefined);
255
+ }
256
+ /**
257
+ * Main telemetry collector for Lynx-instrumented AI agent runtimes.
258
+ *
259
+ * `LynxTracer` owns the active async execution context, captures semantic
260
+ * agent events, batches telemetry, retries failed deliveries, and provides
261
+ * helpers for LLM/tool instrumentation. In most applications, use the shared
262
+ * `lynx` instance exported from `@lynxops/sdk`; create a new instance only when
263
+ * you need custom configuration per process or per test.
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * const tracer = new LynxTracer({
268
+ * clientId: "support-service",
269
+ * apiKey: process.env.LYNX_API_KEY,
270
+ * });
271
+ *
272
+ * await tracer.run("SupportAgent", async () => {
273
+ * tracer.userInput("refund my last order");
274
+ * tracer.decision("selected refund workflow");
275
+ * });
276
+ * ```
277
+ */
278
+ declare class LynxTracer {
279
+ private static readonly storage;
280
+ private static readonly instances;
281
+ private static beforeExitHookRegistered;
282
+ private readonly config;
283
+ private readonly pendingPromises;
284
+ private readonly eventQueue;
285
+ private readonly retryQueue;
286
+ private lastFailureTime;
287
+ private backoffDelayMs;
288
+ private flushTimer;
289
+ private isShuttingDown;
290
+ private isFlushInProgress;
291
+ private consecutiveFlushFailures;
292
+ private circuitOpenedAt;
293
+ private droppedEventCount;
294
+ private lastDeliveryAt?;
295
+ private lastError?;
296
+ /**
297
+ * Creates a tracer with the provided Lynx telemetry configuration.
298
+ *
299
+ * The constructor starts a background flush timer. The timer is unref'ed in
300
+ * Node.js so it will not keep the process alive by itself. Call `shutdown()`
301
+ * in tests, short-lived scripts, or server shutdown hooks to flush remaining
302
+ * telemetry and clear the timer.
303
+ *
304
+ * @param config Runtime configuration for telemetry capture and delivery.
305
+ */
306
+ constructor(config: LynxConfig);
307
+ private static shutdownAll;
308
+ /**
309
+ * Returns the current Lynx async execution context, if one is active.
310
+ *
311
+ * This is mainly useful for advanced instrumentation helpers that need to
312
+ * attach their own telemetry to the currently running `run()` context.
313
+ *
314
+ * @returns The current context, or `undefined` when called outside `run()`.
315
+ */
316
+ static getStore(): LynxContext | undefined;
317
+ private getFlushOnRunEnd;
318
+ private getRequestTimeoutMs;
319
+ private isBackgroundOnly;
320
+ private getMaxQueueSize;
321
+ private getOverflowStrategy;
322
+ private enqueueEvent;
323
+ private enqueueRetryEvent;
324
+ /**
325
+ * Flushes queued telemetry events to the Lynx ingestion endpoint.
326
+ *
327
+ * Events are sent in a single batch request. If delivery fails, the batch is
328
+ * moved into an in-memory retry queue and future flushes are delayed with
329
+ * exponential backoff. Normal applications usually do not need to call this
330
+ * manually because the tracer flushes on an interval.
331
+ *
332
+ * @returns A promise that resolves after the current flush attempt completes.
333
+ */
334
+ flush(): Promise<void>;
335
+ private flushInternal;
336
+ /**
337
+ * Returns a lightweight snapshot of SDK delivery health.
338
+ *
339
+ * Use this for readiness diagnostics, operational dashboards, or tests. The
340
+ * status reflects local SDK state only; it does not perform a network request.
341
+ *
342
+ * @returns Current queue, circuit breaker, and delivery state.
343
+ */
344
+ getStatus(): LynxStatus;
345
+ /**
346
+ * Flushes queued telemetry and releases SDK timers.
347
+ *
348
+ * Use this for graceful process shutdown, tests, CLI scripts, and serverless
349
+ * handlers where the runtime may terminate before the background interval
350
+ * fires. Calling `shutdown()` more than once is safe.
351
+ *
352
+ * @returns A promise that resolves after pending telemetry transmissions settle.
353
+ */
354
+ shutdown(options?: LynxShutdownOptions): Promise<void>;
355
+ private isCircuitBreakerEnabled;
356
+ private isCircuitOpen;
357
+ private getCircuitState;
358
+ private handleSuccessfulFlush;
359
+ private handleFailedEvents;
360
+ /**
361
+ * Runs code inside a Lynx trace context.
362
+ *
363
+ * Every semantic event, instrumented LLM call, and instrumented tool call made
364
+ * inside `executionBlock` will be associated with the same run/session. Nested
365
+ * `run()` calls automatically inherit the parent run id and create a child
366
+ * span relationship.
367
+ *
368
+ * @typeParam T The value returned by the wrapped execution block.
369
+ * @param optionsOrAgentName Agent name or detailed run options.
370
+ * @param executionBlock Function to execute while the Lynx context is active.
371
+ * @returns The original return value of `executionBlock`.
372
+ *
373
+ * @example
374
+ * ```ts
375
+ * await lynx.run({ agentName: "SupportAgent", sessionId: "s-123" }, async () => {
376
+ * lynx.userInput("I need a refund");
377
+ * return await agent.handle();
378
+ * });
379
+ * ```
380
+ */
381
+ run<T>(optionsOrAgentName: string | LynxRunOptions, executionBlock: () => Promise<T> | T): Promise<T>;
382
+ /**
383
+ * Captures a custom context event for the active run.
384
+ *
385
+ * Prefer semantic helpers such as `userInput()`, `decision()`, `context()`,
386
+ * `memory()`, and `outcome()` when the event has a clear meaning. Use `log()`
387
+ * for compatibility or for ad-hoc diagnostic payloads.
388
+ *
389
+ * @param label Human-readable event label.
390
+ * @param payload JSON-serializable diagnostic payload.
391
+ */
392
+ log(label: string, payload: any): void;
393
+ /**
394
+ * Captures the user input that started or influenced the current agent run.
395
+ *
396
+ * This event gives root-cause analysis a clear starting point and separates
397
+ * user intent from prompts, tool results, and internal agent state.
398
+ *
399
+ * @param input Raw or structured user input.
400
+ * @param metadata Optional metadata such as `userId`, `channel`, or `locale`.
401
+ */
402
+ userInput(input: any, metadata?: Record<string, any>): void;
403
+ /**
404
+ * Captures an agent decision and the reason behind it.
405
+ *
406
+ * Use this when the agent chooses a workflow, tool, policy branch, or final
407
+ * action. The `options` object can include candidates, confidence scores, or
408
+ * any domain-specific reasoning metadata.
409
+ *
410
+ * @param reason Short explanation of the selected action.
411
+ * @param options Optional structured metadata about the decision.
412
+ */
413
+ decision(reasonOrDecision: string | LynxDecisionOptions, options?: Record<string, any>): void;
414
+ /**
415
+ * Captures retrieved or constructed context used by the agent.
416
+ *
417
+ * Use this for RAG results, conversation summaries, selected documents,
418
+ * request-scoped state, or any context that may have influenced the next LLM
419
+ * or tool call.
420
+ *
421
+ * @param data Context data or a summary of the context.
422
+ * @param metadata Optional metadata such as source, query, score, or label.
423
+ */
424
+ context(labelOrData: string | any, dataOrMetadata?: any, metadata?: Record<string, any>): void;
425
+ /**
426
+ * Adds attributes to the current run context.
427
+ *
428
+ * Attributes are attached to subsequent events captured in the same async
429
+ * context. Use this for stable request or business identifiers such as
430
+ * `orderId`, `tenantId`, or `workflowId`.
431
+ *
432
+ * @param attributes Key-value attributes to merge into the active context.
433
+ */
434
+ setAttributes(attributes: Record<string, any>): void;
435
+ /**
436
+ * Captures access to short-term or long-term agent memory.
437
+ *
438
+ * This helps identify stale memory, missing memory, or memory values that
439
+ * influenced an incorrect action.
440
+ *
441
+ * @param operation Memory operation name, such as `read`, `write`, or `search`.
442
+ * @param data Memory key/value, query result, or a safe summary.
443
+ * @param metadata Optional metadata such as hit/miss, store name, or freshness.
444
+ */
445
+ memory(operation: string, data: any, metadata?: Record<string, any>): void;
446
+ /**
447
+ * Captures the final technical and business outcome of the current session.
448
+ *
449
+ * Use this to distinguish "the code ran successfully" from "the business task
450
+ * succeeded." That distinction is central for detecting AI failures that do
451
+ * not throw runtime exceptions.
452
+ *
453
+ * @param options Outcome status, business status, reason, impact, and metadata.
454
+ */
455
+ outcome(options: LynxOutcomeOptions): void;
456
+ /**
457
+ * Captures a human-readable annotation for the active run.
458
+ *
459
+ * `annotate()` is intended for breadcrumbs that help operators understand the
460
+ * trace but do not fit one of the stricter semantic event helpers.
461
+ *
462
+ * @param label Annotation label.
463
+ * @param payload JSON-serializable annotation payload.
464
+ */
465
+ annotate(label: string, payload: any): void;
466
+ /**
467
+ * Captures a semantic event for the active Lynx run context.
468
+ */
469
+ private capture;
470
+ /**
471
+ * Captures an event using an explicit Lynx context.
472
+ *
473
+ * This method is public for low-level instrumentation modules, but application
474
+ * code should usually call the semantic helpers or `instrumentLLM()` /
475
+ * `instrumentTool()` instead. Payloads are processed for PII masking,
476
+ * capture-mode filtering, runtime metadata, and loop detection before they are
477
+ * queued for delivery.
478
+ *
479
+ * @param eventType Lynx event type to record.
480
+ * @param label Human-readable event label.
481
+ * @param payload JSON-serializable event payload.
482
+ * @param context Explicit Lynx trace context.
483
+ */
484
+ captureInternal(eventType: LynxEventDto["eventType"], label: string, payload: any, context: LynxContext): void;
485
+ /**
486
+ * Wraps an LLM client with automatic Lynx telemetry.
487
+ *
488
+ * The returned proxy preserves the original client shape while intercepting
489
+ * supported generation methods such as OpenAI `chat.completions.create`,
490
+ * Anthropic `messages.create`, Google `generateContent`, Vercel AI SDK
491
+ * `generateText`, LangChain `invoke`, and similar methods. Captured telemetry
492
+ * includes input/output, provider, model, generation config, latency, token
493
+ * usage, span ids, and errors.
494
+ *
495
+ * @typeParam T LLM client object type.
496
+ * @param instance LLM client instance to wrap.
497
+ * @param optionsOrLabel Event label or custom extraction/interception rules.
498
+ * @returns A proxy with the same public interface as `instance`.
499
+ */
500
+ instrumentLLM<T extends object>(instance: T, optionsOrLabel?: string | {
501
+ modelLabel?: string;
502
+ customRule?: Partial<LlmInstrumentationRule>;
503
+ }): T;
504
+ /**
505
+ * Wraps a tool function with automatic Lynx telemetry.
506
+ *
507
+ * The wrapped function emits `TOOL_CALL` before execution and `TOOL_RESULT`
508
+ * after success. Errors are captured as `ERROR` and then rethrown. Use
509
+ * `metadata` to describe side effects, risk level, external targets, or tool
510
+ * version so debugging and governance views can reason about the call.
511
+ *
512
+ * @typeParam T Tool function type.
513
+ * @param toolName Stable tool name shown in traces and analytics.
514
+ * @param fn Tool function to execute.
515
+ * @param metadata Optional tool metadata for governance and RCA.
516
+ * @returns A wrapped function with the same call signature as `fn`.
517
+ */
518
+ instrumentTool<T extends (...args: any[]) => any>(toolName: string, fn: T, metadata?: LynxToolMetadata): T;
519
+ private getDefaultFailureMode;
520
+ private normalizePolicyDecision;
521
+ private decisionFromPolicyError;
522
+ /**
523
+ * Wraps a tool with a local policy check before execution.
524
+ *
525
+ * `guardTool()` emits a `POLICY_EVALUATION` event before the tool runs. When
526
+ * `beforeCall` returns `{ allow: false }`, Lynx also emits
527
+ * `POLICY_VIOLATION` and `GUARDRAIL_ACTIVATED`, then throws before executing
528
+ * the original tool. This provides the SDK-side hook needed for "observe first,
529
+ * then prevent recurrence" workflows.
530
+ *
531
+ * @typeParam T Tool function type.
532
+ * @param toolName Stable tool name shown in traces and policy events.
533
+ * @param fn Tool function to guard.
534
+ * @param options Tool metadata and an optional `beforeCall` policy callback.
535
+ * @returns A guarded function with the same call signature as `fn`.
536
+ */
537
+ guardTool<T extends (...args: any[]) => any>(toolName: string, fn: T, options?: LynxGuardToolOptions<Parameters<T>>): T;
538
+ private detectLoop;
539
+ }
540
+
541
+ /**
542
+ * Default Lynx tracer instance configured from environment variables.
543
+ *
544
+ * This is the recommended entry point for most applications. Configure it with
545
+ * `LYNX_CLIENT_ID`, `LYNX_API_KEY`, and optional endpoint, capture,
546
+ * delivery, and deployment metadata variables before importing the SDK.
547
+ *
548
+ * @example
549
+ * ```ts
550
+ * import { lynx } from "@lynxops/sdk";
551
+ *
552
+ * await lynx.run("SupportAgent", async () => {
553
+ * lynx.userInput("Where is my order?");
554
+ * });
555
+ * ```
556
+ */
557
+ declare const lynx: LynxTracer;
558
+
559
+ /**
560
+ * Wraps an LLM client object with Lynx telemetry instrumentation.
561
+ *
562
+ * This low-level helper is used by `LynxTracer.instrumentLLM()`. It returns a
563
+ * recursive proxy that preserves the original client API and intercepts known
564
+ * generation methods. Each intercepted call emits start/end `LLM_CALL` events,
565
+ * token usage when available, model configuration metadata, latency, span ids,
566
+ * and errors.
567
+ *
568
+ * Most application code should call `lynx.instrumentLLM(client, options)`
569
+ * instead of importing this helper directly.
570
+ *
571
+ * @typeParam T LLM client object type.
572
+ * @param tracer Tracer that receives captured telemetry.
573
+ * @param instance LLM client instance to wrap.
574
+ * @param optionsOrLabel Event label or custom extraction/interception rules.
575
+ * @returns A proxy with the same public shape as `instance`.
576
+ */
577
+ declare function instrumentLLM<T extends object>(tracer: LynxTracer, instance: T, optionsOrLabel?: string | {
578
+ modelLabel?: string;
579
+ customRule?: Partial<LlmInstrumentationRule>;
580
+ }): T;
581
+ /**
582
+ * Wraps a tool function with Lynx telemetry instrumentation.
583
+ *
584
+ * This low-level helper is used by `LynxTracer.instrumentTool()`. The wrapped
585
+ * function emits `TOOL_CALL` before execution and `TOOL_RESULT` after success.
586
+ * If the tool throws, an `ERROR` event is captured and the original error is
587
+ * rethrown.
588
+ *
589
+ * Most application code should call `lynx.instrumentTool(name, fn, metadata)`
590
+ * instead of importing this helper directly.
591
+ *
592
+ * @typeParam T Tool function type.
593
+ * @param tracer Tracer that receives captured telemetry.
594
+ * @param toolName Stable tool name shown in traces and analytics.
595
+ * @param fn Tool function to execute.
596
+ * @param metadata Optional tool metadata such as risk level or side effects.
597
+ * @returns A wrapped function with the same call signature as `fn`.
598
+ */
599
+ declare function instrumentTool<T extends (...args: any[]) => any>(tracer: LynxTracer, toolName: string, fn: T, metadata?: LynxToolMetadata): T;
600
+
601
+ export { DEFAULT_ENDPOINT, type LlmInstrumentationRule, type LynxBusinessStatus, type LynxConfig, type LynxContext, type LynxDecisionOptions, type LynxEventDto, type LynxEventPayloadDto, type LynxEventType, type LynxGuardFailureMode, type LynxGuardToolOptions, type LynxOutcomeOptions, type LynxPolicyAction, type LynxPolicyDecision, LynxPolicyError, type LynxRiskLevel, type LynxRunOptions, type LynxSessionStatus, type LynxShutdownOptions, type LynxStatus, type LynxToolMetadata, LynxTracer, type TokenUsage, instrumentLLM, instrumentTool, lynx };