@ragbits/api-client-react 1.3.0 → 1.4.0-dev.202512050236
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/__tests__/mocks/handlers.ts +4 -5
- package/dist/hooks.d.ts +3 -3
- package/dist/index.cjs +4 -3
- package/dist/index.js +4 -3
- package/dist/types.d.ts +11 -4
- package/package.json +3 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { http, HttpResponse } from 'msw'
|
|
2
2
|
import type { FeedbackResponse, ChatResponse } from '@ragbits/api-client'
|
|
3
|
-
import { ChatResponseType } from '@ragbits/api-client'
|
|
4
3
|
import { defaultConfigResponse } from '../utils'
|
|
5
4
|
|
|
6
5
|
export const handlers = [
|
|
@@ -26,10 +25,10 @@ export const handlers = [
|
|
|
26
25
|
start(controller) {
|
|
27
26
|
// Send multiple chunks to simulate streaming with proper TypedChatResponse format
|
|
28
27
|
const chunks: string[] = [
|
|
29
|
-
`data: ${JSON.stringify({ type:
|
|
30
|
-
`data: ${JSON.stringify({ type:
|
|
31
|
-
`data: ${JSON.stringify({ type:
|
|
32
|
-
`data: ${JSON.stringify({ type:
|
|
28
|
+
`data: ${JSON.stringify({ type: 'text', content: 'Hello' } as ChatResponse)}\n\n`,
|
|
29
|
+
`data: ${JSON.stringify({ type: 'text', content: ' there!' } as ChatResponse)}\n\n`,
|
|
30
|
+
`data: ${JSON.stringify({ type: 'message_id', content: 'msg-123' } as ChatResponse)}\n\n`,
|
|
31
|
+
`data: ${JSON.stringify({ type: 'conversation_id', content: 'conv-456' } as ChatResponse)}\n\n`,
|
|
33
32
|
]
|
|
34
33
|
|
|
35
34
|
let index = 0
|
package/dist/hooks.d.ts
CHANGED
|
@@ -7,13 +7,13 @@ import type { RagbitsCallResult, RagbitsStreamResult } from './types';
|
|
|
7
7
|
* @param defaultOptions - Default options for the API call
|
|
8
8
|
*/
|
|
9
9
|
export declare function useRagbitsCall<Endpoints extends {
|
|
10
|
-
[K in keyof Endpoints]: EndpointDefinition
|
|
11
|
-
} = BaseApiEndpoints, URL extends keyof Endpoints = keyof Endpoints>(endpoint: URL, defaultOptions?: RequestOptions<URL, Endpoints
|
|
10
|
+
[K in keyof Endpoints]: EndpointDefinition<any, any, any, any>;
|
|
11
|
+
} = BaseApiEndpoints, URL extends keyof Endpoints = keyof Endpoints>(endpoint: URL, defaultOptions?: Partial<RequestOptions<URL, Endpoints>>): RagbitsCallResult<URL, Endpoints, Error>;
|
|
12
12
|
/**
|
|
13
13
|
* Hook for handling streaming responses from Ragbits endpoints
|
|
14
14
|
* - Supports any streaming endpoints by providing `Endpoints` generic argument
|
|
15
15
|
* @param endpoint - The predefined streaming endpoint
|
|
16
16
|
*/
|
|
17
17
|
export declare function useRagbitsStream<Endpoints extends {
|
|
18
|
-
[K in keyof Endpoints]: EndpointDefinition
|
|
18
|
+
[K in keyof Endpoints]: EndpointDefinition<any, any, any, any>;
|
|
19
19
|
} = BaseStreamingEndpoints, URL extends keyof Endpoints = keyof Endpoints>(endpoint: URL, customHeaders?: Record<string, string>): RagbitsStreamResult<URL, Endpoints, Error>;
|
package/dist/index.cjs
CHANGED
|
@@ -78,7 +78,8 @@ function useRagbitsCall(endpoint, defaultOptions) {
|
|
|
78
78
|
setIsLoading(false);
|
|
79
79
|
}, []);
|
|
80
80
|
const call = (0, import_react2.useCallback)(
|
|
81
|
-
async (
|
|
81
|
+
async (...args) => {
|
|
82
|
+
const options = args[0];
|
|
82
83
|
if (abortControllerRef.current && isLoading) {
|
|
83
84
|
abortControllerRef.current.abort();
|
|
84
85
|
}
|
|
@@ -89,10 +90,10 @@ function useRagbitsCall(endpoint, defaultOptions) {
|
|
|
89
90
|
try {
|
|
90
91
|
const mergedOptions = {
|
|
91
92
|
...defaultOptions,
|
|
92
|
-
...options,
|
|
93
|
+
...options || {},
|
|
93
94
|
headers: {
|
|
94
95
|
...defaultOptions?.headers,
|
|
95
|
-
...options
|
|
96
|
+
...options?.headers || {}
|
|
96
97
|
}
|
|
97
98
|
};
|
|
98
99
|
const requestOptions = {
|
package/dist/index.js
CHANGED
|
@@ -50,7 +50,8 @@ function useRagbitsCall(endpoint, defaultOptions) {
|
|
|
50
50
|
setIsLoading(false);
|
|
51
51
|
}, []);
|
|
52
52
|
const call = useCallback(
|
|
53
|
-
async (
|
|
53
|
+
async (...args) => {
|
|
54
|
+
const options = args[0];
|
|
54
55
|
if (abortControllerRef.current && isLoading) {
|
|
55
56
|
abortControllerRef.current.abort();
|
|
56
57
|
}
|
|
@@ -61,10 +62,10 @@ function useRagbitsCall(endpoint, defaultOptions) {
|
|
|
61
62
|
try {
|
|
62
63
|
const mergedOptions = {
|
|
63
64
|
...defaultOptions,
|
|
64
|
-
...options,
|
|
65
|
+
...options || {},
|
|
65
66
|
headers: {
|
|
66
67
|
...defaultOptions?.headers,
|
|
67
|
-
...options
|
|
68
|
+
...options?.headers || {}
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
71
|
const requestOptions = {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
import type { StreamCallbacks, RagbitsClient, RequestOptions, EndpointDefinition, BaseApiEndpoints, EndpointRequest, EndpointResponse, BaseStreamingEndpoints } from '@ragbits/api-client';
|
|
1
|
+
import type { StreamCallbacks, RagbitsClient, RequestOptions, EndpointDefinition, BaseApiEndpoints, EndpointRequest, EndpointResponse, BaseStreamingEndpoints, HasRequiredParams } from '@ragbits/api-client';
|
|
2
|
+
export type { BaseApiEndpoints, BaseStreamingEndpoints, EndpointDefinition, } from '@ragbits/api-client';
|
|
3
|
+
/**
|
|
4
|
+
* Call function type - mirrors makeRequest signature
|
|
5
|
+
*/
|
|
6
|
+
export type CallFunction<URL extends keyof Endpoints, Endpoints extends {
|
|
7
|
+
[K in keyof Endpoints]: EndpointDefinition<any, any, any, any>;
|
|
8
|
+
}> = HasRequiredParams<URL, Endpoints> extends true ? (options: RequestOptions<URL, Endpoints>) => Promise<EndpointResponse<URL, Endpoints>> : (options?: RequestOptions<URL, Endpoints>) => Promise<EndpointResponse<URL, Endpoints>>;
|
|
2
9
|
export interface RagbitsCallResult<URL extends keyof Endpoints, Endpoints extends {
|
|
3
|
-
[K in keyof Endpoints]: EndpointDefinition
|
|
10
|
+
[K in keyof Endpoints]: EndpointDefinition<any, any, any, any>;
|
|
4
11
|
} = BaseApiEndpoints, Err = Error> {
|
|
5
12
|
data: EndpointResponse<URL, Endpoints> | null;
|
|
6
13
|
error: Err | null;
|
|
7
14
|
isLoading: boolean;
|
|
8
|
-
call:
|
|
15
|
+
call: CallFunction<URL, Endpoints>;
|
|
9
16
|
reset: () => void;
|
|
10
17
|
abort: () => void;
|
|
11
18
|
}
|
|
12
19
|
export interface RagbitsStreamResult<URL extends keyof Endpoints, Endpoints extends {
|
|
13
|
-
[K in keyof Endpoints]: EndpointDefinition
|
|
20
|
+
[K in keyof Endpoints]: EndpointDefinition<any, any, any, any>;
|
|
14
21
|
} = BaseStreamingEndpoints, Err = Error> {
|
|
15
22
|
isStreaming: boolean;
|
|
16
23
|
error: Err | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ragbits/api-client-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0-dev.202512050236",
|
|
4
4
|
"description": "React hooks for the Ragbits API client",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@testing-library/user-event": "^14.5.0",
|
|
43
43
|
"@types/react": "^18.2.0",
|
|
44
44
|
"@types/react-dom": "^18.2.0",
|
|
45
|
-
"@vitest/coverage-v8": "^
|
|
45
|
+
"@vitest/coverage-v8": "^4.0.7",
|
|
46
46
|
"eslint": "^9.17.0",
|
|
47
47
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
48
48
|
"eslint-plugin-react-refresh": "^0.4.16",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"tsup": "^8.0.0",
|
|
54
54
|
"typescript": "^5.0.0",
|
|
55
55
|
"typescript-eslint": "^8.18.2",
|
|
56
|
-
"vitest": "^
|
|
56
|
+
"vitest": "^4.0.7"
|
|
57
57
|
},
|
|
58
58
|
"keywords": [
|
|
59
59
|
"ragbits",
|