@iblai/data-layer 1.13.2 → 1.13.4

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.
@@ -1,10 +1,26 @@
1
1
  import { SERVICES } from '../../constants';
2
- import { DetailedFinancialStatsArgs, FinancialStatsArgs, TranscriptsConversationHeadlineArgs, TranscriptsMessagesArgs, TranscriptsMessagesDetailsArgs } from './types';
2
+ import { TranscriptsConversationHeadlineArgs, TranscriptsMessagesArgs, TranscriptsMessagesDetailsArgs } from './types';
3
3
  export declare const ANALYTICS_ENDPOINTS: {
4
4
  GET_OVERVIEW_SUMMARY: {
5
5
  service: SERVICES;
6
6
  path: (org: string, userId: string) => string;
7
7
  };
8
+ GET_TENANT_COST: {
9
+ service: SERVICES;
10
+ path: (org: string, userId: string) => string;
11
+ };
12
+ GET_AGENT_COST: {
13
+ service: SERVICES;
14
+ path: (org: string, userId: string, mentorUniqueId: string) => string;
15
+ };
16
+ GET_MODEL_COSTS: {
17
+ service: SERVICES;
18
+ path: (org: string, userId: string) => string;
19
+ };
20
+ GET_PER_USER_COSTS: {
21
+ service: SERVICES;
22
+ path: (org: string, userId: string) => string;
23
+ };
8
24
  GET_CONVERSATION: {
9
25
  service: SERVICES;
10
26
  path: (org: string, userId: string) => string;
@@ -79,14 +95,6 @@ export declare const NON_AI_ANALYTICS_ENDPOINTS: {
79
95
  service: SERVICES;
80
96
  path: (platform_key: string, mentor_unique_id?: string, date_filter?: string, start_date?: string, end_date?: string) => string;
81
97
  };
82
- GET_FINANCIAL_STATS: {
83
- service: SERVICES;
84
- path: (args: FinancialStatsArgs) => string;
85
- };
86
- GET_DETAILED_FINANCIAL_STATS: {
87
- service: SERVICES;
88
- path: (args: DetailedFinancialStatsArgs) => string;
89
- };
90
98
  GET_TRANSCRIPTS_MESSAGES: {
91
99
  service: SERVICES;
92
100
  path: (args: TranscriptsMessagesArgs) => string;
@@ -115,9 +123,23 @@ export declare const NON_AI_ANALYTICS_ENDPOINTS: {
115
123
  service: SERVICES;
116
124
  path: (username: string, platform_key: string, metrics: string, course_id?: string, include_edx_progress?: boolean, program_id?: string) => string;
117
125
  };
126
+ /**
127
+ * LLM cost/usage analytics (Langfuse proxy; renamed from
128
+ * `/api/analytics/langfuse/`). One endpoint, three resources — the caller
129
+ * picks with `resource` and the typed args in `types.ts` keep unsupported
130
+ * parameter combinations unrepresentable.
131
+ */
132
+ GET_LLM_USAGE: {
133
+ service: SERVICES;
134
+ path: (resource: "metrics" | "observations" | "traces", args: Record<string, string | number | string[] | undefined>) => string;
135
+ };
118
136
  };
119
137
  export declare const ANALYTICS_QUERY_KEYS: {
120
138
  GET_OVERVIEW_SUMMARY: () => string[];
139
+ GET_TENANT_COST: () => string[];
140
+ GET_AGENT_COST: () => string[];
141
+ GET_MODEL_COSTS: () => string[];
142
+ GET_PER_USER_COSTS: () => string[];
121
143
  GET_CONVERSATION: () => string[];
122
144
  GET_MOST_DISCUSSED_TOPICS: () => string[];
123
145
  GET_AVERAGE_MESSAGES_PER_SESSION: () => string[];
@@ -331,67 +331,47 @@ export interface UserDetailsStatsResponse {
331
331
  end_index: number;
332
332
  };
333
333
  }
334
- export interface FinancialStatsArgs {
335
- metric: 'total_costs' | 'weekly_costs' | 'monthly_costs';
336
- date_filter?: DateFilter;
337
- platform_key: string;
338
- mentor_unique_id?: string;
339
- start_date?: string;
340
- end_date?: string;
341
- all_time?: 'true';
342
- usergroup_ids?: number[];
343
- }
344
- export interface FinancialStatsFilters {
334
+ /**
335
+ * ClickHouse-backed cost analytics (`/api/ai-analytics/.../tenant-cost/`,
336
+ * `agents/{id}/cost/`, `costs/model/`, `costs/peruser/`). These replace the
337
+ * deprecated `/api/analytics/financial/` family. Every endpoint takes an
338
+ * explicit YYYY-MM-DD date range — there is no `date_filter` shorthand and
339
+ * no period comparison, so deltas are computed client-side from a second
340
+ * request over the previous window.
341
+ */
342
+ export interface ClickhouseCostRangeArgs {
343
+ org: string;
344
+ /** The requesting admin's username — an `/orgs/{org}/users/{userId}/` path segment. */
345
+ userId: string;
345
346
  start_date: string;
346
347
  end_date: string;
347
- granularity: string;
348
- all_time: boolean;
349
348
  }
350
- export interface FinancialStatsPeriodInfo {
351
- start_date: string;
352
- end_date: string;
353
- period_days: number;
354
- range_type: string;
349
+ export interface ClickhouseAgentCostArgs extends ClickhouseCostRangeArgs {
350
+ mentor_unique_id: string;
355
351
  }
356
- export interface FinancialStatsResponse {
357
- metric: string;
358
- filters: FinancialStatsFilters;
359
- value: number;
360
- percentage_change: number | undefined;
361
- overtime: Array<{
362
- date: string;
363
- value: number;
364
- }>;
365
- period_info: FinancialStatsPeriodInfo;
366
- comparison_info: Record<string, any>;
352
+ export interface ClickhouseCostResponse {
353
+ total_cost: number;
367
354
  }
368
- export interface DetailedFinancialStatsArgs {
369
- metric?: string;
370
- metrics?: string;
371
- group_by: 'llm_model' | 'provider' | 'username';
372
- date_filter: DateFilter;
373
- platform_key: string;
374
- mentor_unique_id?: string;
375
- start_date?: string;
376
- end_date?: string;
377
- page?: number;
378
- limit?: number;
379
- search?: string;
380
- usergroup_ids?: number[];
355
+ export interface ClickhouseModelCost {
356
+ model: string;
357
+ total_cost: number;
381
358
  }
382
- export interface DetailedFinancialStatsMetric {
383
- name: string;
384
- unit: string;
385
- description: string;
359
+ export interface ClickhousePerUserCostsArgs extends ClickhouseCostRangeArgs {
360
+ limit?: number;
361
+ offset?: number;
386
362
  }
387
- export interface DetailedFinancialStatsResponse {
388
- page: number;
389
- limit: number;
390
- total_pages: number;
391
- total_records: number;
392
- rows: Record<string, any>[];
363
+ export interface ClickhousePerUserCostRow {
364
+ username?: string;
365
+ email?: string;
393
366
  total_cost: number;
394
- metrics: DetailedFinancialStatsMetric[];
367
+ /** Not every deployment returns these — render them conditionally. */
368
+ sessions?: number;
369
+ last_active?: string;
370
+ }
371
+ export interface ClickhousePerUserCostsResponse {
372
+ results: ClickhousePerUserCostRow[];
373
+ /** Total records across all pages, when the backend reports it. */
374
+ count?: number;
395
375
  }
396
376
  export interface TimeTrackingRequest {
397
377
  timestamp: string;
@@ -700,3 +680,130 @@ export interface LearnerDetailsResponse {
700
680
  user: LearnerDetailsUser;
701
681
  data: LearnerDetailsData;
702
682
  }
683
+ /** Measures the metrics resource can aggregate. */
684
+ export type LlmUsageMeasure = 'total_cost' | 'input_tokens' | 'output_tokens' | 'total_tokens' | 'count' | 'latency';
685
+ export type LlmUsageAggregation = 'sum' | 'avg' | 'count' | 'min' | 'max' | 'p50' | 'p75' | 'p90' | 'p95' | 'p99';
686
+ /** Dimensions Langfuse accepts. Per-mentor ranking rides `tags`; per-user and
687
+ * per-session are not supported here by design. */
688
+ export type LlmUsageGroupBy = 'type' | 'model' | 'tags' | 'environment';
689
+ export type LlmUsageGranularity = 'day' | 'week' | 'month';
690
+ interface LlmUsageCommonArgs {
691
+ platform_key: string;
692
+ /**
693
+ * ⚠️ The endpoint's own default is `today`, not all-time. Callers should
694
+ * always pass an explicit filter so the shared date-range control and this
695
+ * endpoint never disagree.
696
+ */
697
+ date_filter?: DateFilter;
698
+ start_date?: string;
699
+ end_date?: string;
700
+ username?: string;
701
+ /** Service that produced the trace: `chat`, `call`, `memory`, `grading`, … */
702
+ trace_name?: string;
703
+ }
704
+ export interface LlmUsageMetricsArgs extends LlmUsageCommonArgs {
705
+ mentor_unique_id?: string;
706
+ session_id?: string;
707
+ llm_model?: string;
708
+ /** Joined as a comma-separated list. Defaults to `total_cost` upstream. */
709
+ measures?: LlmUsageMeasure[];
710
+ aggregation?: LlmUsageAggregation;
711
+ group_by?: LlmUsageGroupBy;
712
+ granularity?: LlmUsageGranularity;
713
+ order_by?: LlmUsageMeasure;
714
+ direction?: 'asc' | 'desc';
715
+ limit?: number;
716
+ view?: 'observations' | 'scores';
717
+ }
718
+ export interface LlmUsageTracesArgs extends LlmUsageCommonArgs {
719
+ mentor_unique_id?: string;
720
+ session_id?: string;
721
+ /** Get-by-id; a cross-tenant id answers 404, never 403. */
722
+ trace_id?: string;
723
+ order_by?: 'timestamp' | 'name' | 'username' | 'session_id';
724
+ direction?: 'asc' | 'desc';
725
+ page?: number;
726
+ limit?: number;
727
+ }
728
+ /** No `mentor_unique_id` (upstream 403) and no `session_id` (upstream 400) —
729
+ * scope row-level drill-down with `trace_id` instead. */
730
+ export interface LlmUsageObservationsArgs extends LlmUsageCommonArgs {
731
+ trace_id?: string;
732
+ observation_id?: string;
733
+ page?: number;
734
+ limit?: number;
735
+ }
736
+ /**
737
+ * A metrics row: the grouped dimension (if any) plus one key per measure named
738
+ * `{aggregation}_{langfuseMeasure}` (`sum_totalCost`, `p95_latency`, …), and
739
+ * `time_dimension` when a granularity was requested.
740
+ */
741
+ export interface LlmUsageMetricsRow {
742
+ traceName?: string;
743
+ providedModelName?: string;
744
+ tags?: string[];
745
+ environment?: string;
746
+ time_dimension?: string;
747
+ [measureKey: string]: string | number | string[] | null | undefined;
748
+ }
749
+ export interface LlmUsageMetricsResponse {
750
+ resource: 'metrics';
751
+ data: LlmUsageMetricsRow[];
752
+ }
753
+ export interface LlmUsagePaginationMeta {
754
+ page: number;
755
+ limit: number;
756
+ totalItems: number;
757
+ totalPages: number;
758
+ }
759
+ export interface LlmUsageTrace {
760
+ id: string;
761
+ timestamp: string;
762
+ name?: string;
763
+ userId?: string;
764
+ sessionId?: string;
765
+ environment?: string;
766
+ tags?: string[];
767
+ latency?: number;
768
+ totalCost?: number;
769
+ input?: unknown;
770
+ output?: unknown;
771
+ metadata?: Record<string, unknown>;
772
+ observations?: string[];
773
+ [key: string]: unknown;
774
+ }
775
+ export interface LlmUsageTracesResponse {
776
+ resource: 'traces';
777
+ /** A list page, or the single record when `trace_id` was passed. */
778
+ data: LlmUsageTrace[] | LlmUsageTrace;
779
+ meta?: LlmUsagePaginationMeta;
780
+ }
781
+ export interface LlmUsageObservation {
782
+ id: string;
783
+ traceId?: string;
784
+ type?: string;
785
+ name?: string;
786
+ startTime?: string;
787
+ endTime?: string;
788
+ latency?: number;
789
+ model?: string;
790
+ providedModelName?: string;
791
+ usage?: {
792
+ input?: number;
793
+ output?: number;
794
+ total?: number;
795
+ };
796
+ usageDetails?: Record<string, number>;
797
+ calculatedTotalCost?: number;
798
+ totalCost?: number;
799
+ input?: unknown;
800
+ output?: unknown;
801
+ [key: string]: unknown;
802
+ }
803
+ export interface LlmUsageObservationsResponse {
804
+ resource: 'observations';
805
+ /** A list page, or the single record when `observation_id` was passed. */
806
+ data: LlmUsageObservation[] | LlmUsageObservation;
807
+ meta?: LlmUsagePaginationMeta;
808
+ }
809
+ export {};
@@ -2,6 +2,7 @@ import { Assertion, Issuer } from '@iblai/iblai-api';
2
2
  export interface CredentialsSchema {
3
3
  name: string;
4
4
  schema: Record<string, string>;
5
+ service_info?: LLMServiceInfo;
5
6
  }
6
7
  export interface IntegrationCredentialsSchemaField {
7
8
  type: string;
@@ -16,7 +17,7 @@ export interface LLMServiceInfo {
16
17
  id: number;
17
18
  name: string;
18
19
  display_name: string;
19
- logo: string;
20
+ logo?: string | null;
20
21
  }
21
22
  export interface MaskLLM {
22
23
  name: string;