@ragbits/api-client 0.0.3 → 1.3.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.
package/dist/types.d.ts CHANGED
@@ -1,156 +1,16 @@
1
- import { RJSFSchema } from '@rjsf/utils';
2
- /**
3
- * Message roles for chat conversations
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,58 @@ 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
- * Regular API endpoint definitions with their request/response types
29
+ * Base predefined API endpoint definitions with their request/response types
165
30
  */
166
- export interface ApiEndpoints {
167
- '/api/config': {
168
- method: 'GET';
169
- request: never;
170
- response: ConfigResponse;
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>;
177
36
  }
178
37
  /**
179
38
  * Streaming API endpoint definitions with their request/stream response types
180
39
  */
181
- export interface StreamingEndpoints {
182
- '/api/chat': {
183
- method: 'POST';
184
- request: ChatRequest;
185
- stream: TypedChatResponse;
186
- };
40
+ export interface BaseStreamingEndpoints {
41
+ '/api/chat': EndpointDefinition<ChatRequest, ChatResponse>;
187
42
  }
188
43
  /**
189
44
  * Extract endpoint paths as a union type
190
45
  */
191
- export type ApiEndpointPath = keyof ApiEndpoints;
192
- /**
193
- * Extract streaming endpoint paths as a union type
194
- */
195
- export type StreamingEndpointPath = keyof StreamingEndpoints;
46
+ export type EndpointPath<Endpoints extends {
47
+ [K in keyof Endpoints]: EndpointDefinition;
48
+ }> = keyof Endpoints;
196
49
  /**
197
50
  * Extract request type for a specific API endpoint
198
51
  */
199
- export type ApiEndpointRequest<T extends ApiEndpointPath> = ApiEndpoints[T]['request'];
52
+ export type EndpointRequest<URL extends keyof Endpoints, Endpoints extends {
53
+ [K in keyof Endpoints]: EndpointDefinition;
54
+ }> = Endpoints[URL]['request'];
200
55
  /**
201
56
  * Extract response type for a specific API endpoint
202
57
  */
203
- export type ApiEndpointResponse<T extends ApiEndpointPath> = ApiEndpoints[T]['response'];
58
+ export type EndpointResponse<URL extends keyof Endpoints, Endpoints extends {
59
+ [K in keyof Endpoints]: EndpointDefinition;
60
+ }> = Endpoints[URL]['response'];
204
61
  /**
205
62
  * Extract HTTP method for a specific API endpoint
206
63
  */
207
- export type ApiEndpointMethod<T extends ApiEndpointPath> = ApiEndpoints[T]['method'];
208
- /**
209
- * Extract request type for a specific streaming endpoint
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'];
64
+ export type EndpointMethod<URL extends keyof Endpoints, Endpoints extends {
65
+ [K in keyof Endpoints]: EndpointDefinition;
66
+ }> = Endpoints[URL]['method'];
220
67
  /**
221
68
  * Generic request options for API endpoints with typed methods and body
222
69
  */
223
- export interface TypedApiRequestOptions<T extends ApiEndpointPath> {
224
- method?: ApiEndpointMethod<T>;
225
- body?: ApiEndpointRequest<T> extends never ? undefined : ApiEndpointRequest<T>;
226
- headers?: Record<string, string>;
227
- signal?: AbortSignal;
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>;
70
+ export interface RequestOptions<URL extends keyof Endpoints, Endpoints extends {
71
+ [K in keyof Endpoints]: EndpointDefinition;
72
+ }> {
73
+ method?: Endpoints[URL]['method'];
74
+ body?: Endpoints[URL]['request'] extends never ? undefined : Endpoints[URL]['request'];
235
75
  headers?: Record<string, string>;
236
76
  signal?: AbortSignal;
237
77
  }
238
- export {};
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@ragbits/api-client",
3
- "version": "0.0.3",
3
+ "version": "1.3.0",
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",