@iblai/data-layer 1.13.1 → 1.13.3
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/dist/index.d.ts +879 -99
- package/dist/index.esm.js +126 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +132 -17
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/src/features/analytics/__tests__/llm-usage.test.d.ts +1 -0
- package/dist/src/features/analytics/api-slice.d.ts +710 -45
- package/dist/src/features/analytics/constants.d.ts +31 -9
- package/dist/src/features/analytics/types.d.ts +164 -53
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import { SERVICES } from '../../constants';
|
|
2
|
-
import {
|
|
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[];
|
|
@@ -69,6 +69,8 @@ export interface TranscriptsMessagesDetailsResponse {
|
|
|
69
69
|
model: string;
|
|
70
70
|
username: string;
|
|
71
71
|
name: string;
|
|
72
|
+
/** Preferred over `name`/`username` in the UI; older deployments omit it. */
|
|
73
|
+
email?: string | null;
|
|
72
74
|
first_user_message: string;
|
|
73
75
|
topics: string[];
|
|
74
76
|
message_count: number;
|
|
@@ -102,6 +104,8 @@ export interface TranscriptsMessagesResponse {
|
|
|
102
104
|
cost: number;
|
|
103
105
|
username: string;
|
|
104
106
|
name: string;
|
|
107
|
+
/** Preferred over `name`/`username` in the UI; older deployments omit it. */
|
|
108
|
+
email?: string | null;
|
|
105
109
|
first_user_message: string;
|
|
106
110
|
topics: string[];
|
|
107
111
|
message_count: number;
|
|
@@ -327,67 +331,47 @@ export interface UserDetailsStatsResponse {
|
|
|
327
331
|
end_index: number;
|
|
328
332
|
};
|
|
329
333
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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;
|
|
341
346
|
start_date: string;
|
|
342
347
|
end_date: string;
|
|
343
|
-
granularity: string;
|
|
344
|
-
all_time: boolean;
|
|
345
348
|
}
|
|
346
|
-
export interface
|
|
347
|
-
|
|
348
|
-
end_date: string;
|
|
349
|
-
period_days: number;
|
|
350
|
-
range_type: string;
|
|
349
|
+
export interface ClickhouseAgentCostArgs extends ClickhouseCostRangeArgs {
|
|
350
|
+
mentor_unique_id: string;
|
|
351
351
|
}
|
|
352
|
-
export interface
|
|
353
|
-
|
|
354
|
-
filters: FinancialStatsFilters;
|
|
355
|
-
value: number;
|
|
356
|
-
percentage_change: number | undefined;
|
|
357
|
-
overtime: Array<{
|
|
358
|
-
date: string;
|
|
359
|
-
value: number;
|
|
360
|
-
}>;
|
|
361
|
-
period_info: FinancialStatsPeriodInfo;
|
|
362
|
-
comparison_info: Record<string, any>;
|
|
352
|
+
export interface ClickhouseCostResponse {
|
|
353
|
+
total_cost: number;
|
|
363
354
|
}
|
|
364
|
-
export interface
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
group_by: 'llm_model' | 'provider' | 'username';
|
|
368
|
-
date_filter: DateFilter;
|
|
369
|
-
platform_key: string;
|
|
370
|
-
mentor_unique_id?: string;
|
|
371
|
-
start_date?: string;
|
|
372
|
-
end_date?: string;
|
|
373
|
-
page?: number;
|
|
374
|
-
limit?: number;
|
|
375
|
-
search?: string;
|
|
376
|
-
usergroup_ids?: number[];
|
|
355
|
+
export interface ClickhouseModelCost {
|
|
356
|
+
model: string;
|
|
357
|
+
total_cost: number;
|
|
377
358
|
}
|
|
378
|
-
export interface
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
description: string;
|
|
359
|
+
export interface ClickhousePerUserCostsArgs extends ClickhouseCostRangeArgs {
|
|
360
|
+
limit?: number;
|
|
361
|
+
offset?: number;
|
|
382
362
|
}
|
|
383
|
-
export interface
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
total_pages: number;
|
|
387
|
-
total_records: number;
|
|
388
|
-
rows: Record<string, any>[];
|
|
363
|
+
export interface ClickhousePerUserCostRow {
|
|
364
|
+
username?: string;
|
|
365
|
+
email?: string;
|
|
389
366
|
total_cost: number;
|
|
390
|
-
|
|
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;
|
|
391
375
|
}
|
|
392
376
|
export interface TimeTrackingRequest {
|
|
393
377
|
timestamp: string;
|
|
@@ -696,3 +680,130 @@ export interface LearnerDetailsResponse {
|
|
|
696
680
|
user: LearnerDetailsUser;
|
|
697
681
|
data: LearnerDetailsData;
|
|
698
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 {};
|