@ragbits/api-client 0.0.2 → 0.0.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/README.md +252 -58
- package/dist/index.cjs +9 -0
- package/dist/index.d.ts +3 -220
- package/dist/index.js +8 -0
- package/dist/{index.d.cts → types.d.ts} +50 -69
- package/package.json +5 -4
- package/eslint.config.js +0 -21
- package/prettier.config.js +0 -6
- package/src/index.ts +0 -213
- package/src/test/RagbitsClient.test.ts +0 -484
- package/src/test/mocks/handlers.ts +0 -98
- package/src/test/setup.ts +0 -23
- package/src/test/types.test.ts +0 -35
- package/src/test/utils.ts +0 -28
- package/src/types.ts +0 -259
- package/tsconfig.json +0 -16
- package/vitest.config.ts +0 -20
package/README.md
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ragbits/api-client
|
|
2
2
|
|
|
3
|
-
A TypeScript client for communicating with the Ragbits API. This client provides methods for both regular HTTP requests and server-sent events (streaming) functionality.
|
|
3
|
+
A TypeScript client for communicating with the Ragbits API. This client provides type-safe methods for both regular HTTP requests and server-sent events (streaming) functionality.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Type-safe API calls** - Full TypeScript support with predefined endpoints
|
|
8
|
+
- **Streaming support** - Real-time server-sent events with proper error handling
|
|
9
|
+
- **Modern JavaScript** - ES modules and CommonJS support
|
|
10
|
+
- **Abortable requests** - Cancel ongoing requests and streams
|
|
11
|
+
- **Error handling** - Comprehensive error handling with detailed error messages
|
|
12
|
+
- **Zero dependencies** - Lightweight with no runtime dependencies
|
|
4
13
|
|
|
5
14
|
## Installation
|
|
6
15
|
|
|
7
16
|
```bash
|
|
8
|
-
npm install ragbits
|
|
17
|
+
npm install @ragbits/api-client
|
|
9
18
|
```
|
|
10
19
|
|
|
11
|
-
##
|
|
20
|
+
## Quick Start
|
|
12
21
|
|
|
13
22
|
```typescript
|
|
14
|
-
import { RagbitsClient
|
|
23
|
+
import { RagbitsClient } from '@ragbits/api-client'
|
|
15
24
|
|
|
16
25
|
// Initialize the client
|
|
17
26
|
const client = new RagbitsClient({
|
|
@@ -19,20 +28,21 @@ const client = new RagbitsClient({
|
|
|
19
28
|
})
|
|
20
29
|
|
|
21
30
|
// Get API configuration
|
|
22
|
-
const config = await client.
|
|
31
|
+
const config = await client.makeRequest('/api/config')
|
|
23
32
|
|
|
24
33
|
// Send a chat message with streaming response
|
|
25
|
-
const cleanup = client.
|
|
34
|
+
const cleanup = client.makeStreamRequest(
|
|
35
|
+
'/api/chat',
|
|
26
36
|
{
|
|
27
37
|
message: 'Hello!',
|
|
28
38
|
history: [],
|
|
29
39
|
context: {}, // Optional
|
|
30
40
|
},
|
|
31
41
|
{
|
|
32
|
-
onMessage: (data
|
|
42
|
+
onMessage: (data) => {
|
|
33
43
|
console.log('Received message:', data)
|
|
34
44
|
},
|
|
35
|
-
onError: (error
|
|
45
|
+
onError: (error) => {
|
|
36
46
|
console.error('Error:', error)
|
|
37
47
|
},
|
|
38
48
|
onClose: () => {
|
|
@@ -45,10 +55,13 @@ const cleanup = client.sendChatMessage(
|
|
|
45
55
|
cleanup()
|
|
46
56
|
|
|
47
57
|
// Send feedback
|
|
48
|
-
await client.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
await client.makeRequest('/api/feedback', {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
body: {
|
|
61
|
+
message_id: 'message-123',
|
|
62
|
+
feedback: 'like',
|
|
63
|
+
payload: { reason: 'helpful' },
|
|
64
|
+
},
|
|
52
65
|
})
|
|
53
66
|
```
|
|
54
67
|
|
|
@@ -61,86 +74,267 @@ The main client class for interacting with the Ragbits API.
|
|
|
61
74
|
#### Constructor
|
|
62
75
|
|
|
63
76
|
```typescript
|
|
64
|
-
new RagbitsClient(config?:
|
|
77
|
+
new RagbitsClient(config?: ClientConfig)
|
|
65
78
|
```
|
|
66
79
|
|
|
80
|
+
**Parameters:**
|
|
81
|
+
|
|
67
82
|
- `config.baseUrl` (optional): Base URL for the API. Defaults to 'http://127.0.0.1:8000'
|
|
68
83
|
|
|
84
|
+
**Throws:** `Error` if the base URL is invalid
|
|
85
|
+
|
|
69
86
|
#### Methods
|
|
70
87
|
|
|
71
|
-
##### `
|
|
88
|
+
##### `getBaseUrl(): string`
|
|
89
|
+
|
|
90
|
+
Get the base URL used by this client.
|
|
91
|
+
|
|
92
|
+
**Returns:** The configured base URL
|
|
93
|
+
|
|
94
|
+
##### `makeRequest<T>(endpoint, options?): Promise<T>`
|
|
95
|
+
|
|
96
|
+
Make a type-safe API request to predefined endpoints.
|
|
97
|
+
|
|
98
|
+
**Parameters:**
|
|
72
99
|
|
|
73
|
-
|
|
100
|
+
- `endpoint`: Predefined API endpoint path (e.g., '/api/config', '/api/feedback')
|
|
101
|
+
- `options` (optional): Request options
|
|
102
|
+
- `method`: HTTP method (defaults to endpoint's predefined method)
|
|
103
|
+
- `body`: Request body (typed based on endpoint)
|
|
104
|
+
- `headers`: Additional headers
|
|
105
|
+
- `signal`: AbortSignal for cancelling the request
|
|
74
106
|
|
|
75
|
-
|
|
107
|
+
**Returns:** Promise with the typed response
|
|
76
108
|
|
|
77
|
-
|
|
109
|
+
**Example:**
|
|
78
110
|
|
|
79
|
-
|
|
111
|
+
```typescript
|
|
112
|
+
// GET request
|
|
113
|
+
const config = await client.makeRequest('/api/config')
|
|
114
|
+
|
|
115
|
+
// POST request
|
|
116
|
+
const feedback = await client.makeRequest('/api/feedback', {
|
|
117
|
+
method: 'POST',
|
|
118
|
+
body: {
|
|
119
|
+
message_id: 'msg-123',
|
|
120
|
+
feedback: 'like',
|
|
121
|
+
payload: { rating: 5 },
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
##### `makeStreamRequest<T>(endpoint, data, callbacks, signal?): () => void`
|
|
80
127
|
|
|
81
|
-
-
|
|
82
|
-
- `chatRequest`: ChatRequest
|
|
83
|
-
- `message`: string - User message
|
|
84
|
-
- `history`: Array<{ role: string; content: string; id?: string }> - Chat history
|
|
85
|
-
- `context`: Record<string, unknown> (optional) - Additional context
|
|
86
|
-
- `callbacks`: StreamCallbacks
|
|
87
|
-
- `onMessage`: (data: ChatResponse) => void | Promise<void> - Called when a message chunk is received
|
|
88
|
-
- `onError`: (error: string) => void | Promise<void> - Called when an error occurs
|
|
89
|
-
- `onClose`: () => void | Promise<void> (optional) - Called when the stream closes
|
|
90
|
-
- Returns: `() => void` - Cleanup function to cancel the stream
|
|
128
|
+
Make a type-safe streaming request to predefined streaming endpoints.
|
|
91
129
|
|
|
92
|
-
|
|
130
|
+
**Parameters:**
|
|
93
131
|
|
|
94
|
-
|
|
132
|
+
- `endpoint`: Predefined streaming endpoint path (e.g., '/api/chat')
|
|
133
|
+
- `data`: Request data (typed based on endpoint)
|
|
134
|
+
- `callbacks`: Stream callbacks
|
|
135
|
+
- `onMessage`: Called when a message chunk is received
|
|
136
|
+
- `onError`: Called when an error occurs
|
|
137
|
+
- `onClose`: Called when the stream closes (optional)
|
|
138
|
+
- `signal` (optional): AbortSignal for cancelling the stream
|
|
95
139
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
140
|
+
**Returns:** Cleanup function to cancel the stream
|
|
141
|
+
|
|
142
|
+
**Example:**
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
const cleanup = client.makeStreamRequest(
|
|
146
|
+
'/api/chat',
|
|
147
|
+
{
|
|
148
|
+
message: 'Tell me about AI',
|
|
149
|
+
history: [
|
|
150
|
+
{ role: 'user', content: 'Hello', id: 'msg-1' },
|
|
151
|
+
{ role: 'assistant', content: 'Hi there!', id: 'msg-2' },
|
|
152
|
+
],
|
|
153
|
+
context: { user_id: 'user-123' },
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
onMessage: (data) => {
|
|
157
|
+
switch (data.type) {
|
|
158
|
+
case 'text':
|
|
159
|
+
console.log('Text:', data.content)
|
|
160
|
+
break
|
|
161
|
+
case 'reference':
|
|
162
|
+
console.log('Reference:', data.content.title)
|
|
163
|
+
break
|
|
164
|
+
case 'message_id':
|
|
165
|
+
console.log('Message ID:', data.content)
|
|
166
|
+
break
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
onError: (error) => {
|
|
170
|
+
console.error('Stream error:', error)
|
|
171
|
+
},
|
|
172
|
+
onClose: () => {
|
|
173
|
+
console.log('Stream completed')
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
// Cancel stream
|
|
179
|
+
cleanup()
|
|
180
|
+
```
|
|
102
181
|
|
|
103
182
|
## Types
|
|
104
183
|
|
|
105
|
-
###
|
|
184
|
+
### Core Types
|
|
185
|
+
|
|
186
|
+
#### `ClientConfig`
|
|
106
187
|
|
|
107
188
|
```typescript
|
|
108
|
-
{
|
|
109
|
-
|
|
110
|
-
content: any
|
|
189
|
+
interface ClientConfig {
|
|
190
|
+
baseUrl?: string
|
|
111
191
|
}
|
|
112
192
|
```
|
|
113
193
|
|
|
114
|
-
|
|
194
|
+
#### `Message`
|
|
115
195
|
|
|
116
196
|
```typescript
|
|
117
|
-
{
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
197
|
+
interface Message {
|
|
198
|
+
role: MessageRole
|
|
199
|
+
content: string
|
|
200
|
+
id?: string
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
enum MessageRole {
|
|
204
|
+
USER = 'user',
|
|
205
|
+
ASSISTANT = 'assistant',
|
|
206
|
+
SYSTEM = 'system',
|
|
125
207
|
}
|
|
126
208
|
```
|
|
127
209
|
|
|
128
|
-
|
|
210
|
+
#### `ChatRequest`
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
interface ChatRequest {
|
|
214
|
+
message: string
|
|
215
|
+
history: Message[]
|
|
216
|
+
context?: Record<string, unknown>
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### `TypedChatResponse`
|
|
221
|
+
|
|
222
|
+
Union type for all possible chat response types:
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
type TypedChatResponse =
|
|
226
|
+
| { type: 'text'; content: string }
|
|
227
|
+
| { type: 'reference'; content: Reference }
|
|
228
|
+
| { type: 'message_id'; content: string }
|
|
229
|
+
| { type: 'conversation_id'; content: string }
|
|
230
|
+
| { type: 'state_update'; content: ServerState }
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### `FeedbackRequest`
|
|
129
234
|
|
|
130
235
|
```typescript
|
|
131
|
-
{
|
|
236
|
+
interface FeedbackRequest {
|
|
132
237
|
message_id: string
|
|
133
|
-
feedback:
|
|
238
|
+
feedback: FeedbackType
|
|
134
239
|
payload: Record<string, unknown> | null
|
|
135
240
|
}
|
|
241
|
+
|
|
242
|
+
enum FeedbackType {
|
|
243
|
+
LIKE = 'like',
|
|
244
|
+
DISLIKE = 'dislike',
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
#### `ConfigResponse`
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
interface ConfigResponse {
|
|
252
|
+
feedback: {
|
|
253
|
+
like: { enabled: boolean; form: RJSFSchema | null }
|
|
254
|
+
dislike: { enabled: boolean; form: RJSFSchema | null }
|
|
255
|
+
}
|
|
256
|
+
customization: UICustomization | null
|
|
257
|
+
}
|
|
136
258
|
```
|
|
137
259
|
|
|
138
|
-
|
|
260
|
+
#### `StreamCallbacks<T, E>`
|
|
139
261
|
|
|
140
262
|
```typescript
|
|
141
|
-
{
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
263
|
+
interface StreamCallbacks<T, E = Error> {
|
|
264
|
+
onMessage: (data: T) => void | Promise<void>
|
|
265
|
+
onError: (error: E) => void | Promise<void>
|
|
266
|
+
onClose?: () => void | Promise<void>
|
|
145
267
|
}
|
|
146
268
|
```
|
|
269
|
+
|
|
270
|
+
### Advanced Types
|
|
271
|
+
|
|
272
|
+
The package provides extensive TypeScript support with predefined endpoint types:
|
|
273
|
+
|
|
274
|
+
- `ApiEndpointPath` - Union of all available API endpoints
|
|
275
|
+
- `StreamingEndpointPath` - Union of all available streaming endpoints
|
|
276
|
+
- `ApiEndpointResponse<T>` - Response type for a specific endpoint
|
|
277
|
+
- `StreamingEndpointStream<T>` - Stream response type for a specific endpoint
|
|
278
|
+
|
|
279
|
+
## Error Handling
|
|
280
|
+
|
|
281
|
+
The client provides comprehensive error handling:
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
try {
|
|
285
|
+
const config = await client.makeRequest('/api/config')
|
|
286
|
+
} catch (error) {
|
|
287
|
+
if (error instanceof Error) {
|
|
288
|
+
console.error('API Error:', error.message)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Common error scenarios:
|
|
294
|
+
|
|
295
|
+
- **Network errors** - Connection failures, timeouts
|
|
296
|
+
- **HTTP errors** - 4xx/5xx status codes
|
|
297
|
+
- **Invalid URLs** - Malformed base URL
|
|
298
|
+
- **Stream errors** - Connection drops, parsing errors
|
|
299
|
+
|
|
300
|
+
## Aborting Requests
|
|
301
|
+
|
|
302
|
+
Both regular requests and streams can be aborted:
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
// Abort regular request
|
|
306
|
+
const controller = new AbortController()
|
|
307
|
+
const request = client.makeRequest('/api/config', {
|
|
308
|
+
signal: controller.signal,
|
|
309
|
+
})
|
|
310
|
+
controller.abort() // Cancels the request
|
|
311
|
+
|
|
312
|
+
// Abort stream
|
|
313
|
+
const cleanup = client.makeStreamRequest(
|
|
314
|
+
'/api/chat',
|
|
315
|
+
data,
|
|
316
|
+
callbacks,
|
|
317
|
+
controller.signal
|
|
318
|
+
)
|
|
319
|
+
controller.abort() // Cancels the stream
|
|
320
|
+
cleanup() // Also cancels the stream
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## Browser Support
|
|
324
|
+
|
|
325
|
+
This package supports all modern browsers with fetch API support:
|
|
326
|
+
|
|
327
|
+
- Chrome 42+
|
|
328
|
+
- Firefox 39+
|
|
329
|
+
- Safari 10.1+
|
|
330
|
+
- Edge 14+
|
|
331
|
+
|
|
332
|
+
## Node.js Support
|
|
333
|
+
|
|
334
|
+
For Node.js environments, you'll need:
|
|
335
|
+
|
|
336
|
+
- Node.js 18+
|
|
337
|
+
|
|
338
|
+
## License
|
|
339
|
+
|
|
340
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
ChatResponseType: () => ChatResponseType,
|
|
24
24
|
FeedbackType: () => FeedbackType,
|
|
25
|
+
LiveUpdateType: () => LiveUpdateType,
|
|
25
26
|
MessageRole: () => MessageRole,
|
|
26
27
|
RagbitsClient: () => RagbitsClient
|
|
27
28
|
});
|
|
@@ -41,6 +42,8 @@ var ChatResponseType = /* @__PURE__ */ ((ChatResponseType2) => {
|
|
|
41
42
|
ChatResponseType2["TEXT"] = "text";
|
|
42
43
|
ChatResponseType2["MESSAGE_ID"] = "message_id";
|
|
43
44
|
ChatResponseType2["CONVERSATION_ID"] = "conversation_id";
|
|
45
|
+
ChatResponseType2["LIVE_UPDATE"] = "live_update";
|
|
46
|
+
ChatResponseType2["FOLLOWUP_MESSAGES"] = "followup_messages";
|
|
44
47
|
return ChatResponseType2;
|
|
45
48
|
})(ChatResponseType || {});
|
|
46
49
|
var FeedbackType = /* @__PURE__ */ ((FeedbackType2) => {
|
|
@@ -48,6 +51,11 @@ var FeedbackType = /* @__PURE__ */ ((FeedbackType2) => {
|
|
|
48
51
|
FeedbackType2["DISLIKE"] = "dislike";
|
|
49
52
|
return FeedbackType2;
|
|
50
53
|
})(FeedbackType || {});
|
|
54
|
+
var LiveUpdateType = /* @__PURE__ */ ((LiveUpdateType2) => {
|
|
55
|
+
LiveUpdateType2["START"] = "START";
|
|
56
|
+
LiveUpdateType2["FINISH"] = "FINISH";
|
|
57
|
+
return LiveUpdateType2;
|
|
58
|
+
})(LiveUpdateType || {});
|
|
51
59
|
|
|
52
60
|
// src/index.ts
|
|
53
61
|
var RagbitsClient = class {
|
|
@@ -206,6 +214,7 @@ var RagbitsClient = class {
|
|
|
206
214
|
0 && (module.exports = {
|
|
207
215
|
ChatResponseType,
|
|
208
216
|
FeedbackType,
|
|
217
|
+
LiveUpdateType,
|
|
209
218
|
MessageRole,
|
|
210
219
|
RagbitsClient
|
|
211
220
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,224 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Message roles for chat conversations
|
|
5
|
-
*/
|
|
6
|
-
declare enum MessageRole {
|
|
7
|
-
USER = "user",
|
|
8
|
-
ASSISTANT = "assistant",
|
|
9
|
-
SYSTEM = "system"
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Message structure for chat conversations
|
|
13
|
-
*/
|
|
14
|
-
interface Message {
|
|
15
|
-
role: MessageRole;
|
|
16
|
-
content: string;
|
|
17
|
-
id?: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Reference structure for document references
|
|
21
|
-
*/
|
|
22
|
-
interface Reference {
|
|
23
|
-
title: string;
|
|
24
|
-
content: string;
|
|
25
|
-
url?: string;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Response types from the API
|
|
29
|
-
*/
|
|
30
|
-
declare enum ChatResponseType {
|
|
31
|
-
MESSAGE = "message",
|
|
32
|
-
REFERENCE = "reference",
|
|
33
|
-
STATE_UPDATE = "state_update",
|
|
34
|
-
TEXT = "text",
|
|
35
|
-
MESSAGE_ID = "message_id",
|
|
36
|
-
CONVERSATION_ID = "conversation_id"
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Feedback types for user feedback
|
|
40
|
-
*/
|
|
41
|
-
declare enum FeedbackType {
|
|
42
|
-
LIKE = "like",
|
|
43
|
-
DISLIKE = "dislike"
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Server state interface for state updates
|
|
47
|
-
*/
|
|
48
|
-
interface ServerState {
|
|
49
|
-
state: Record<string, unknown>;
|
|
50
|
-
signature: string;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Specific chat response types
|
|
54
|
-
*/
|
|
55
|
-
interface MessageIdChatResponse {
|
|
56
|
-
type: ChatResponseType.MESSAGE_ID;
|
|
57
|
-
content: string;
|
|
58
|
-
}
|
|
59
|
-
interface TextChatResponse {
|
|
60
|
-
type: ChatResponseType.TEXT;
|
|
61
|
-
content: string;
|
|
62
|
-
}
|
|
63
|
-
interface ReferenceChatResponse {
|
|
64
|
-
type: ChatResponseType.REFERENCE;
|
|
65
|
-
content: Reference;
|
|
66
|
-
}
|
|
67
|
-
interface ConversationIdChatResponse {
|
|
68
|
-
type: ChatResponseType.CONVERSATION_ID;
|
|
69
|
-
content: string;
|
|
70
|
-
}
|
|
71
|
-
interface StateUpdateChatResponse {
|
|
72
|
-
type: ChatResponseType.STATE_UPDATE;
|
|
73
|
-
content: ServerState;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Typed chat response union
|
|
77
|
-
*/
|
|
78
|
-
type TypedChatResponse = TextChatResponse | ReferenceChatResponse | MessageIdChatResponse | ConversationIdChatResponse | StateUpdateChatResponse;
|
|
79
|
-
/**
|
|
80
|
-
* Base chat request to the API
|
|
81
|
-
*/
|
|
82
|
-
interface ChatRequest {
|
|
83
|
-
message: string;
|
|
84
|
-
history: Message[];
|
|
85
|
-
context?: Record<string, unknown>;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Feedback request to the API
|
|
89
|
-
*/
|
|
90
|
-
interface FeedbackRequest {
|
|
91
|
-
message_id: string;
|
|
92
|
-
feedback: FeedbackType;
|
|
93
|
-
payload: Record<string, unknown> | null;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Feedback response from the API
|
|
97
|
-
*/
|
|
98
|
-
interface FeedbackResponse {
|
|
99
|
-
status: string;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* UI customization configuration
|
|
103
|
-
*/
|
|
104
|
-
interface UICustomization {
|
|
105
|
-
header: {
|
|
106
|
-
title?: string;
|
|
107
|
-
subtitle?: string;
|
|
108
|
-
logo?: string;
|
|
109
|
-
};
|
|
110
|
-
welcome_message?: string;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Configuration response from the API
|
|
114
|
-
*/
|
|
115
|
-
interface ConfigResponse {
|
|
116
|
-
feedback: {
|
|
117
|
-
like: {
|
|
118
|
-
enabled: boolean;
|
|
119
|
-
form: RJSFSchema | null;
|
|
120
|
-
};
|
|
121
|
-
dislike: {
|
|
122
|
-
enabled: boolean;
|
|
123
|
-
form: RJSFSchema | null;
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
customization: UICustomization | null;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Configuration for the client
|
|
130
|
-
*/
|
|
131
|
-
interface ClientConfig {
|
|
132
|
-
baseUrl?: string;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Callbacks for handling streaming responses
|
|
136
|
-
*/
|
|
137
|
-
interface StreamCallbacks<T, E = Error> {
|
|
138
|
-
onMessage: (data: T) => void | Promise<void>;
|
|
139
|
-
onError: (error: E) => void | Promise<void>;
|
|
140
|
-
onClose?: () => void | Promise<void>;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Regular API endpoint definitions with their request/response types
|
|
144
|
-
*/
|
|
145
|
-
interface ApiEndpoints {
|
|
146
|
-
'/api/config': {
|
|
147
|
-
method: 'GET';
|
|
148
|
-
request: never;
|
|
149
|
-
response: ConfigResponse;
|
|
150
|
-
};
|
|
151
|
-
'/api/feedback': {
|
|
152
|
-
method: 'POST';
|
|
153
|
-
request: FeedbackRequest;
|
|
154
|
-
response: FeedbackResponse;
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Streaming API endpoint definitions with their request/stream response types
|
|
159
|
-
*/
|
|
160
|
-
interface StreamingEndpoints {
|
|
161
|
-
'/api/chat': {
|
|
162
|
-
method: 'POST';
|
|
163
|
-
request: ChatRequest;
|
|
164
|
-
stream: TypedChatResponse;
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Extract endpoint paths as a union type
|
|
169
|
-
*/
|
|
170
|
-
type ApiEndpointPath = keyof ApiEndpoints;
|
|
171
|
-
/**
|
|
172
|
-
* Extract streaming endpoint paths as a union type
|
|
173
|
-
*/
|
|
174
|
-
type StreamingEndpointPath = keyof StreamingEndpoints;
|
|
175
|
-
/**
|
|
176
|
-
* Extract request type for a specific API endpoint
|
|
177
|
-
*/
|
|
178
|
-
type ApiEndpointRequest<T extends ApiEndpointPath> = ApiEndpoints[T]['request'];
|
|
179
|
-
/**
|
|
180
|
-
* Extract response type for a specific API endpoint
|
|
181
|
-
*/
|
|
182
|
-
type ApiEndpointResponse<T extends ApiEndpointPath> = ApiEndpoints[T]['response'];
|
|
183
|
-
/**
|
|
184
|
-
* Extract HTTP method for a specific API endpoint
|
|
185
|
-
*/
|
|
186
|
-
type ApiEndpointMethod<T extends ApiEndpointPath> = ApiEndpoints[T]['method'];
|
|
187
|
-
/**
|
|
188
|
-
* Extract request type for a specific streaming endpoint
|
|
189
|
-
*/
|
|
190
|
-
type StreamingEndpointRequest<T extends StreamingEndpointPath> = StreamingEndpoints[T]['request'];
|
|
191
|
-
/**
|
|
192
|
-
* Extract stream response type for a specific streaming endpoint
|
|
193
|
-
*/
|
|
194
|
-
type StreamingEndpointStream<T extends StreamingEndpointPath> = StreamingEndpoints[T]['stream'];
|
|
195
|
-
/**
|
|
196
|
-
* Extract HTTP method for a specific streaming endpoint
|
|
197
|
-
*/
|
|
198
|
-
type StreamingEndpointMethod<T extends StreamingEndpointPath> = StreamingEndpoints[T]['method'];
|
|
199
|
-
/**
|
|
200
|
-
* Generic request options for API endpoints with typed methods and body
|
|
201
|
-
*/
|
|
202
|
-
interface TypedApiRequestOptions<T extends ApiEndpointPath> {
|
|
203
|
-
method?: ApiEndpointMethod<T>;
|
|
204
|
-
body?: ApiEndpointRequest<T> extends never ? undefined : ApiEndpointRequest<T>;
|
|
205
|
-
headers?: Record<string, string>;
|
|
206
|
-
signal?: AbortSignal;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Typed request options for specific streaming endpoints
|
|
210
|
-
*/
|
|
211
|
-
interface TypedStreamRequestOptions<T extends StreamingEndpointPath> {
|
|
212
|
-
method?: StreamingEndpointMethod<T>;
|
|
213
|
-
body?: StreamingEndpointRequest<T>;
|
|
214
|
-
headers?: Record<string, string>;
|
|
215
|
-
signal?: AbortSignal;
|
|
216
|
-
}
|
|
217
|
-
|
|
1
|
+
import type { ClientConfig, StreamCallbacks, ApiEndpointPath, ApiEndpointResponse, TypedApiRequestOptions, StreamingEndpointPath, StreamingEndpointRequest, StreamingEndpointStream } from './types';
|
|
218
2
|
/**
|
|
219
3
|
* Client for communicating with the Ragbits API
|
|
220
4
|
*/
|
|
221
|
-
declare class RagbitsClient {
|
|
5
|
+
export declare class RagbitsClient {
|
|
222
6
|
private readonly baseUrl;
|
|
223
7
|
/**
|
|
224
8
|
* @param config - Configuration object
|
|
@@ -253,5 +37,4 @@ declare class RagbitsClient {
|
|
|
253
37
|
*/
|
|
254
38
|
makeStreamRequest<T extends StreamingEndpointPath>(endpoint: T, data: StreamingEndpointRequest<T>, callbacks: StreamCallbacks<StreamingEndpointStream<T>>, signal?: AbortSignal): () => void;
|
|
255
39
|
}
|
|
256
|
-
|
|
257
|
-
export { type ApiEndpointMethod, type ApiEndpointPath, type ApiEndpointRequest, type ApiEndpointResponse, type ApiEndpoints, type ChatRequest, ChatResponseType, type ClientConfig, type ConfigResponse, type FeedbackRequest, type FeedbackResponse, FeedbackType, type Message, MessageRole, RagbitsClient, type Reference, type ServerState, type StreamCallbacks, type StreamingEndpointMethod, type StreamingEndpointPath, type StreamingEndpointRequest, type StreamingEndpointStream, type StreamingEndpoints, type TypedApiRequestOptions, type TypedChatResponse, type TypedStreamRequestOptions, type UICustomization };
|
|
40
|
+
export * from './types';
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,8 @@ var ChatResponseType = /* @__PURE__ */ ((ChatResponseType2) => {
|
|
|
12
12
|
ChatResponseType2["TEXT"] = "text";
|
|
13
13
|
ChatResponseType2["MESSAGE_ID"] = "message_id";
|
|
14
14
|
ChatResponseType2["CONVERSATION_ID"] = "conversation_id";
|
|
15
|
+
ChatResponseType2["LIVE_UPDATE"] = "live_update";
|
|
16
|
+
ChatResponseType2["FOLLOWUP_MESSAGES"] = "followup_messages";
|
|
15
17
|
return ChatResponseType2;
|
|
16
18
|
})(ChatResponseType || {});
|
|
17
19
|
var FeedbackType = /* @__PURE__ */ ((FeedbackType2) => {
|
|
@@ -19,6 +21,11 @@ var FeedbackType = /* @__PURE__ */ ((FeedbackType2) => {
|
|
|
19
21
|
FeedbackType2["DISLIKE"] = "dislike";
|
|
20
22
|
return FeedbackType2;
|
|
21
23
|
})(FeedbackType || {});
|
|
24
|
+
var LiveUpdateType = /* @__PURE__ */ ((LiveUpdateType2) => {
|
|
25
|
+
LiveUpdateType2["START"] = "START";
|
|
26
|
+
LiveUpdateType2["FINISH"] = "FINISH";
|
|
27
|
+
return LiveUpdateType2;
|
|
28
|
+
})(LiveUpdateType || {});
|
|
22
29
|
|
|
23
30
|
// src/index.ts
|
|
24
31
|
var RagbitsClient = class {
|
|
@@ -176,6 +183,7 @@ var RagbitsClient = class {
|
|
|
176
183
|
export {
|
|
177
184
|
ChatResponseType,
|
|
178
185
|
FeedbackType,
|
|
186
|
+
LiveUpdateType,
|
|
179
187
|
MessageRole,
|
|
180
188
|
RagbitsClient
|
|
181
189
|
};
|