@ragbits/api-client 0.0.3 → 1.4.0-dev.202512021005
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/README.md +51 -101
- package/__tests__/mocks/handlers.ts +98 -0
- package/__tests__/setup.ts +23 -0
- package/__tests__/utils.ts +45 -0
- package/dist/autogen.types.d.ts +495 -0
- package/dist/index.cjs +149 -55
- package/dist/index.d.ts +14 -5
- package/dist/index.js +146 -53
- package/dist/types.d.ts +38 -198
- package/package.json +8 -4
package/dist/types.d.ts
CHANGED
|
@@ -1,156 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
export declare enum MessageRole {
|
|
6
|
-
USER = "user",
|
|
7
|
-
ASSISTANT = "assistant",
|
|
8
|
-
SYSTEM = "system"
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Message structure for chat conversations
|
|
12
|
-
*/
|
|
13
|
-
export interface Message {
|
|
14
|
-
role: MessageRole;
|
|
15
|
-
content: string;
|
|
16
|
-
id?: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Reference structure for document references
|
|
20
|
-
*/
|
|
21
|
-
export interface Reference {
|
|
22
|
-
title: string;
|
|
23
|
-
content: string;
|
|
24
|
-
url?: string;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Response types from the API
|
|
28
|
-
*/
|
|
29
|
-
export declare enum ChatResponseType {
|
|
30
|
-
MESSAGE = "message",
|
|
31
|
-
REFERENCE = "reference",
|
|
32
|
-
STATE_UPDATE = "state_update",
|
|
33
|
-
TEXT = "text",
|
|
34
|
-
MESSAGE_ID = "message_id",
|
|
35
|
-
CONVERSATION_ID = "conversation_id",
|
|
36
|
-
LIVE_UPDATE = "live_update",
|
|
37
|
-
FOLLOWUP_MESSAGES = "followup_messages"
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Feedback types for user feedback
|
|
41
|
-
*/
|
|
42
|
-
export declare enum FeedbackType {
|
|
43
|
-
LIKE = "like",
|
|
44
|
-
DISLIKE = "dislike"
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Server state interface for state updates
|
|
48
|
-
*/
|
|
49
|
-
export interface ServerState {
|
|
50
|
-
state: Record<string, unknown>;
|
|
51
|
-
signature: string;
|
|
52
|
-
}
|
|
53
|
-
export declare enum LiveUpdateType {
|
|
54
|
-
START = "START",
|
|
55
|
-
FINISH = "FINISH"
|
|
56
|
-
}
|
|
57
|
-
export interface LiveUpdate {
|
|
58
|
-
update_id: string;
|
|
59
|
-
type: LiveUpdateType;
|
|
60
|
-
content: {
|
|
61
|
-
label: string;
|
|
62
|
-
description?: string;
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Specific chat response types
|
|
67
|
-
*/
|
|
68
|
-
interface MessageIdChatResponse {
|
|
69
|
-
type: ChatResponseType.MESSAGE_ID;
|
|
70
|
-
content: string;
|
|
71
|
-
}
|
|
72
|
-
interface TextChatResponse {
|
|
73
|
-
type: ChatResponseType.TEXT;
|
|
74
|
-
content: string;
|
|
75
|
-
}
|
|
76
|
-
interface ReferenceChatResponse {
|
|
77
|
-
type: ChatResponseType.REFERENCE;
|
|
78
|
-
content: Reference;
|
|
79
|
-
}
|
|
80
|
-
interface ConversationIdChatResponse {
|
|
81
|
-
type: ChatResponseType.CONVERSATION_ID;
|
|
82
|
-
content: string;
|
|
83
|
-
}
|
|
84
|
-
interface StateUpdateChatResponse {
|
|
85
|
-
type: ChatResponseType.STATE_UPDATE;
|
|
86
|
-
content: ServerState;
|
|
87
|
-
}
|
|
88
|
-
interface LiveUpdateChatResponse {
|
|
89
|
-
type: ChatResponseType.LIVE_UPDATE;
|
|
90
|
-
content: LiveUpdate;
|
|
91
|
-
}
|
|
92
|
-
interface FollowupMessagesChatResponse {
|
|
93
|
-
type: ChatResponseType.FOLLOWUP_MESSAGES;
|
|
94
|
-
content: string[];
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Typed chat response union
|
|
98
|
-
*/
|
|
99
|
-
export type TypedChatResponse = TextChatResponse | ReferenceChatResponse | MessageIdChatResponse | ConversationIdChatResponse | StateUpdateChatResponse | LiveUpdateChatResponse | FollowupMessagesChatResponse;
|
|
100
|
-
/**
|
|
101
|
-
* Base chat request to the API
|
|
102
|
-
*/
|
|
103
|
-
export interface ChatRequest {
|
|
104
|
-
message: string;
|
|
105
|
-
history: Message[];
|
|
106
|
-
context?: Record<string, unknown>;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Feedback request to the API
|
|
110
|
-
*/
|
|
111
|
-
export interface FeedbackRequest {
|
|
112
|
-
message_id: string;
|
|
113
|
-
feedback: FeedbackType;
|
|
114
|
-
payload: Record<string, unknown> | null;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Feedback response from the API
|
|
118
|
-
*/
|
|
119
|
-
export interface FeedbackResponse {
|
|
120
|
-
status: string;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* UI customization configuration
|
|
124
|
-
*/
|
|
125
|
-
export interface UICustomization {
|
|
126
|
-
header: {
|
|
127
|
-
title?: string;
|
|
128
|
-
subtitle?: string;
|
|
129
|
-
logo?: string;
|
|
130
|
-
};
|
|
131
|
-
welcome_message?: string;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Configuration response from the API
|
|
135
|
-
*/
|
|
136
|
-
export interface ConfigResponse {
|
|
137
|
-
feedback: {
|
|
138
|
-
like: {
|
|
139
|
-
enabled: boolean;
|
|
140
|
-
form: RJSFSchema | null;
|
|
141
|
-
};
|
|
142
|
-
dislike: {
|
|
143
|
-
enabled: boolean;
|
|
144
|
-
form: RJSFSchema | null;
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
customization: UICustomization | null;
|
|
1
|
+
import { ConfigResponse, FeedbackRequest, FeedbackResponse, ChatRequest, ChatResponse, LogoutRequest, LoginRequest, LoginResponse } from './autogen.types';
|
|
2
|
+
export interface GenericResponse {
|
|
3
|
+
success: boolean;
|
|
148
4
|
}
|
|
149
5
|
/**
|
|
150
6
|
* Configuration for the client
|
|
151
7
|
*/
|
|
152
8
|
export interface ClientConfig {
|
|
153
9
|
baseUrl?: string;
|
|
10
|
+
auth?: {
|
|
11
|
+
getToken?: () => string;
|
|
12
|
+
onUnauthorized?: () => Promise<void> | void;
|
|
13
|
+
};
|
|
154
14
|
}
|
|
155
15
|
/**
|
|
156
16
|
* Callbacks for handling streaming responses
|
|
@@ -160,79 +20,59 @@ export interface StreamCallbacks<T, E = Error> {
|
|
|
160
20
|
onError: (error: E) => void | Promise<void>;
|
|
161
21
|
onClose?: () => void | Promise<void>;
|
|
162
22
|
}
|
|
23
|
+
export interface EndpointDefinition<Req = any, Res = any> {
|
|
24
|
+
method: string;
|
|
25
|
+
request: Req;
|
|
26
|
+
response: Res;
|
|
27
|
+
}
|
|
163
28
|
/**
|
|
164
|
-
*
|
|
29
|
+
* Base predefined API endpoint definitions with their request/response types
|
|
165
30
|
*/
|
|
166
|
-
export interface
|
|
167
|
-
'/api/config':
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
'/api/feedback': {
|
|
173
|
-
method: 'POST';
|
|
174
|
-
request: FeedbackRequest;
|
|
175
|
-
response: FeedbackResponse;
|
|
176
|
-
};
|
|
31
|
+
export interface BaseApiEndpoints {
|
|
32
|
+
'/api/config': EndpointDefinition<never, ConfigResponse>;
|
|
33
|
+
'/api/feedback': EndpointDefinition<FeedbackRequest, FeedbackResponse>;
|
|
34
|
+
'/api/auth/login': EndpointDefinition<LoginRequest, LoginResponse>;
|
|
35
|
+
'/api/auth/logout': EndpointDefinition<LogoutRequest, GenericResponse>;
|
|
36
|
+
'/api/theme': EndpointDefinition<never, string>;
|
|
177
37
|
}
|
|
178
38
|
/**
|
|
179
39
|
* Streaming API endpoint definitions with their request/stream response types
|
|
180
40
|
*/
|
|
181
|
-
export interface
|
|
182
|
-
'/api/chat':
|
|
183
|
-
method: 'POST';
|
|
184
|
-
request: ChatRequest;
|
|
185
|
-
stream: TypedChatResponse;
|
|
186
|
-
};
|
|
41
|
+
export interface BaseStreamingEndpoints {
|
|
42
|
+
'/api/chat': EndpointDefinition<ChatRequest, ChatResponse>;
|
|
187
43
|
}
|
|
188
44
|
/**
|
|
189
45
|
* Extract endpoint paths as a union type
|
|
190
46
|
*/
|
|
191
|
-
export type
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
*/
|
|
195
|
-
export type StreamingEndpointPath = keyof StreamingEndpoints;
|
|
47
|
+
export type EndpointPath<Endpoints extends {
|
|
48
|
+
[K in keyof Endpoints]: EndpointDefinition;
|
|
49
|
+
}> = keyof Endpoints;
|
|
196
50
|
/**
|
|
197
51
|
* Extract request type for a specific API endpoint
|
|
198
52
|
*/
|
|
199
|
-
export type
|
|
53
|
+
export type EndpointRequest<URL extends keyof Endpoints, Endpoints extends {
|
|
54
|
+
[K in keyof Endpoints]: EndpointDefinition;
|
|
55
|
+
}> = Endpoints[URL]['request'];
|
|
200
56
|
/**
|
|
201
57
|
* Extract response type for a specific API endpoint
|
|
202
58
|
*/
|
|
203
|
-
export type
|
|
59
|
+
export type EndpointResponse<URL extends keyof Endpoints, Endpoints extends {
|
|
60
|
+
[K in keyof Endpoints]: EndpointDefinition;
|
|
61
|
+
}> = Endpoints[URL]['response'];
|
|
204
62
|
/**
|
|
205
63
|
* Extract HTTP method for a specific API endpoint
|
|
206
64
|
*/
|
|
207
|
-
export type
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
*/
|
|
211
|
-
export type StreamingEndpointRequest<T extends StreamingEndpointPath> = StreamingEndpoints[T]['request'];
|
|
212
|
-
/**
|
|
213
|
-
* Extract stream response type for a specific streaming endpoint
|
|
214
|
-
*/
|
|
215
|
-
export type StreamingEndpointStream<T extends StreamingEndpointPath> = StreamingEndpoints[T]['stream'];
|
|
216
|
-
/**
|
|
217
|
-
* Extract HTTP method for a specific streaming endpoint
|
|
218
|
-
*/
|
|
219
|
-
export type StreamingEndpointMethod<T extends StreamingEndpointPath> = StreamingEndpoints[T]['method'];
|
|
65
|
+
export type EndpointMethod<URL extends keyof Endpoints, Endpoints extends {
|
|
66
|
+
[K in keyof Endpoints]: EndpointDefinition;
|
|
67
|
+
}> = Endpoints[URL]['method'];
|
|
220
68
|
/**
|
|
221
69
|
* Generic request options for API endpoints with typed methods and body
|
|
222
70
|
*/
|
|
223
|
-
export interface
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Typed request options for specific streaming endpoints
|
|
231
|
-
*/
|
|
232
|
-
export interface TypedStreamRequestOptions<T extends StreamingEndpointPath> {
|
|
233
|
-
method?: StreamingEndpointMethod<T>;
|
|
234
|
-
body?: StreamingEndpointRequest<T>;
|
|
71
|
+
export interface RequestOptions<URL extends keyof Endpoints, Endpoints extends {
|
|
72
|
+
[K in keyof Endpoints]: EndpointDefinition;
|
|
73
|
+
}> {
|
|
74
|
+
method?: Endpoints[URL]['method'];
|
|
75
|
+
body?: Endpoints[URL]['request'] extends never ? undefined : Endpoints[URL]['request'];
|
|
235
76
|
headers?: Record<string, string>;
|
|
236
77
|
signal?: AbortSignal;
|
|
237
78
|
}
|
|
238
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ragbits/api-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.4.0-dev.202512021005",
|
|
4
4
|
"description": "JavaScript client for the Ragbits API",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/deepsense-ai/ragbits"
|
|
8
|
+
},
|
|
5
9
|
"main": "dist/index.cjs",
|
|
6
10
|
"module": "dist/index.js",
|
|
7
11
|
"types": "dist/index.d.ts",
|
|
@@ -22,7 +26,7 @@
|
|
|
22
26
|
"lint": "eslint .",
|
|
23
27
|
"format": "prettier --write .",
|
|
24
28
|
"format:check": "prettier --check .",
|
|
25
|
-
"clean": "rm -rf ./dist"
|
|
29
|
+
"clean": "rm -rf ./dist && rm -f ./tsconfig.tsbuildinfo"
|
|
26
30
|
},
|
|
27
31
|
"keywords": [
|
|
28
32
|
"ragbits",
|
|
@@ -36,7 +40,7 @@
|
|
|
36
40
|
"@rjsf/utils": "^5.24.12",
|
|
37
41
|
"@testing-library/jest-dom": "^6.4.0",
|
|
38
42
|
"@types/node": "^20.0.0",
|
|
39
|
-
"@vitest/coverage-v8": "^
|
|
43
|
+
"@vitest/coverage-v8": "^4.0.7",
|
|
40
44
|
"eslint": "^9.17.0",
|
|
41
45
|
"globals": "^15.14.0",
|
|
42
46
|
"msw": "^2.0.0",
|
|
@@ -44,6 +48,6 @@
|
|
|
44
48
|
"tsup": "^8.0.0",
|
|
45
49
|
"typescript": "^5.0.0",
|
|
46
50
|
"typescript-eslint": "^8.18.2",
|
|
47
|
-
"vitest": "^
|
|
51
|
+
"vitest": "^4.0.7"
|
|
48
52
|
}
|
|
49
53
|
}
|