@juspay/neurolink 9.94.7 → 9.95.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.
@@ -13,6 +13,7 @@ import { ExternalServerManager } from "./mcp/externalServerManager.js";
13
13
  import { MCPToolRegistry } from "./mcp/toolRegistry.js";
14
14
  import type { DynamicOptions } from "./types/index.js";
15
15
  import { SkillsManager } from "./skills/skillsManager.js";
16
+ import type { CostAnalysisOptions, CostAnalysisResult, ProviderMetricsOptions, ProviderMetricsResult, TeamAnalyticsOptions, TeamAnalyticsResult } from "./types/index.js";
16
17
  import { TaskManager } from "./tasks/taskManager.js";
17
18
  import type { SessionExport, SessionListItem } from "./types/index.js";
18
19
  /**
@@ -220,6 +221,7 @@ export declare class NeuroLink {
220
221
  */
221
222
  private observabilityConfig?;
222
223
  private metricsAggregator;
224
+ private analyticsService;
223
225
  /**
224
226
  * Per-request metrics trace context backed by AsyncLocalStorage.
225
227
  * Safe for concurrent requests on the same SDK instance.
@@ -532,6 +534,30 @@ export declare class NeuroLink {
532
534
  * Record a span for metrics tracking
533
535
  */
534
536
  recordMetricsSpan(span: SpanData): void;
537
+ /**
538
+ * Get provider metrics analysis
539
+ * Retrieves aggregated performance, token usage, latency, and success rates per provider.
540
+ *
541
+ * @param options - Filtering options
542
+ * @returns Comprehensive provider metrics result
543
+ */
544
+ getProviderMetrics(options?: ProviderMetricsOptions): Promise<ProviderMetricsResult>;
545
+ /**
546
+ * Get cost analysis breakdown
547
+ * Analyzes AI generation costs across requested groups and provides future projections.
548
+ *
549
+ * @param options - Cost configuration options
550
+ * @returns Detailed cost analysis breakdown
551
+ */
552
+ getCostAnalysis(options?: CostAnalysisOptions): Promise<CostAnalysisResult>;
553
+ /**
554
+ * Get team-wide usage analytics
555
+ * Retrieves request counts, unique active users, provider breakdown, and quality scoring.
556
+ *
557
+ * @param options - Team query options
558
+ * @returns Comprehensive team analytics report
559
+ */
560
+ getTeamAnalytics(options?: TeamAnalyticsOptions): Promise<TeamAnalyticsResult>;
535
561
  /**
536
562
  * Record a memory operation span to both instance and global metrics aggregators.
537
563
  * This ensures memory spans are visible via sdk.getSpans() and getMetricsAggregator().getSpans().
@@ -546,6 +572,34 @@ export declare class NeuroLink {
546
572
  * Gracefully shutdown NeuroLink and all MCP connections
547
573
  */
548
574
  shutdown(): Promise<void>;
575
+ /**
576
+ * Fire-and-forget analytics tracking with rejection logging.
577
+ */
578
+ private enqueueAnalyticsTrackRequest;
579
+ /**
580
+ * Estimate cost using the canonical SDK pricing table (same source as
581
+ * AnalyticsService.trackRequest) — avoids diverging TokenTracker rates.
582
+ */
583
+ private estimateCostFromUsage;
584
+ /**
585
+ * Handle generation:end for Pipeline B spans + advanced analytics.
586
+ * When pipelineAHandled is set, skips Pipeline B spans but still tracks
587
+ * analytics so successful AI-SDK generate/stream calls are recorded.
588
+ * Stream analytics are owned here (not stream:complete) to avoid duplicates.
589
+ */
590
+ private handleGenerationEndMetrics;
591
+ /**
592
+ * Pipeline B span recording for stream:complete.
593
+ * Advanced analytics are recorded from generation:end only (avoids duplicates
594
+ * when both stream:complete and generation:end fire for the same request).
595
+ */
596
+ private handleStreamCompleteMetrics;
597
+ private handleToolEndMetrics;
598
+ /**
599
+ * Pipeline B span recording for stream:error.
600
+ * Analytics for failed streams come from generation:end (success: false).
601
+ */
602
+ private handleStreamErrorMetrics;
549
603
  /**
550
604
  * Initialize event listeners that feed span data to MetricsAggregator.
551
605
  * Listens to generation:end, stream:complete, and tool:end events.