@fencyai/react 0.1.59 → 0.1.61
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/lib/hooks/useCreateFiles/index.d.ts +3 -0
- package/lib/hooks/{useFiles → useCreateFiles}/index.js +8 -17
- package/lib/hooks/useListFiles/index.d.ts +3 -0
- package/lib/hooks/useListFiles/index.js +109 -0
- package/lib/hooks/useSearchFiles/index.d.ts +2 -0
- package/lib/hooks/useSearchFiles/index.js +26 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/types/CreateFileParams.d.ts +3 -0
- package/lib/types/FencyProviderProps.d.ts +0 -3
- package/lib/types/ListFilesPage.d.ts +8 -0
- package/lib/types/ListFilesParams.d.ts +5 -0
- package/lib/types/ListFilesResult.d.ts +9 -0
- package/lib/types/ListFilesResult.js +1 -0
- package/lib/types/UseCreateFiles.d.ts +6 -0
- package/lib/types/UseCreateFiles.js +1 -0
- package/lib/types/{UseFilesProps.d.ts → UseCreateFilesProps.d.ts} +1 -1
- package/lib/types/UseCreateFilesProps.js +1 -0
- package/lib/types/UseListFiles.d.ts +9 -0
- package/lib/types/UseListFiles.js +1 -0
- package/lib/types/UseListFilesProps.d.ts +3 -0
- package/lib/types/UseListFilesProps.js +1 -0
- package/lib/types/UseSearchFiles.d.ts +6 -0
- package/lib/types/UseSearchFiles.js +1 -0
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.js +2 -2
- package/package.json +4 -4
- package/lib/hooks/useFiles/index.d.ts +0 -3
- package/lib/types/UseFiles.d.ts +0 -8
- /package/lib/types/{UseFiles.js → ListFilesPage.js} +0 -0
- /package/lib/types/{UseFilesProps.js → ListFilesParams.js} +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { createFile as createFileApi,
|
|
1
|
+
import { createFile as createFileApi, } from '@fencyai/js';
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { useFencyContext } from '../../provider/useFencyContext';
|
|
4
4
|
import { useStream } from '../useStream';
|
|
5
|
-
export function
|
|
5
|
+
export function useCreateFiles(props) {
|
|
6
6
|
const [files, setFiles] = useState([]);
|
|
7
7
|
const context = useFencyContext();
|
|
8
8
|
const { createStream } = useStream({
|
|
9
9
|
onFileUploadCompleted: (streamData) => {
|
|
10
|
-
props
|
|
10
|
+
props?.onUploadCompleted?.(streamData);
|
|
11
11
|
setFiles((prev) => prev.map((fileUpload) => {
|
|
12
12
|
return fileUpload.id === streamData.uploadId
|
|
13
13
|
? { ...fileUpload, status: 'upload_complete' }
|
|
@@ -15,13 +15,16 @@ export function useFiles(props) {
|
|
|
15
15
|
}));
|
|
16
16
|
},
|
|
17
17
|
onFileTextContentReady: (streamData) => {
|
|
18
|
-
props
|
|
18
|
+
props?.onTextContentReady?.(streamData);
|
|
19
19
|
setFiles((prev) => prev.map((fileUpload) => fileUpload.id === streamData.fileId
|
|
20
20
|
? { ...fileUpload, textContent: streamData.textContent }
|
|
21
21
|
: fileUpload));
|
|
22
22
|
},
|
|
23
23
|
});
|
|
24
24
|
const createFile = async (params) => {
|
|
25
|
+
const clientSecret = params.fetchClientSecret
|
|
26
|
+
? await params.fetchClientSecret()
|
|
27
|
+
: undefined;
|
|
25
28
|
const streamResponse = await createStream({
|
|
26
29
|
type: 'FileStream',
|
|
27
30
|
});
|
|
@@ -34,6 +37,7 @@ export function useFiles(props) {
|
|
|
34
37
|
fileType: params.fileType,
|
|
35
38
|
fileSize: params.fileSize,
|
|
36
39
|
extractTextContent: params.extractTextContent || true,
|
|
40
|
+
clientSecret: clientSecret?.clientSecret,
|
|
37
41
|
},
|
|
38
42
|
baseUrl: context.fency.baseUrl,
|
|
39
43
|
});
|
|
@@ -55,21 +59,8 @@ export function useFiles(props) {
|
|
|
55
59
|
};
|
|
56
60
|
}
|
|
57
61
|
};
|
|
58
|
-
const searchFiles = async (params) => {
|
|
59
|
-
const clientSecret = await params.fetchClientSecret();
|
|
60
|
-
const response = await searchFilesApi({
|
|
61
|
-
pk: context.fency.publishableKey,
|
|
62
|
-
request: {
|
|
63
|
-
text: params.text,
|
|
64
|
-
clientSecret: clientSecret.clientSecret,
|
|
65
|
-
},
|
|
66
|
-
baseUrl: context.fency.baseUrl,
|
|
67
|
-
});
|
|
68
|
-
return response;
|
|
69
|
-
};
|
|
70
62
|
return {
|
|
71
63
|
createFile,
|
|
72
|
-
searchFiles,
|
|
73
64
|
files,
|
|
74
65
|
};
|
|
75
66
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { listFiles as listFilesApi } from '@fencyai/js';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useFencyContext } from '../../provider/useFencyContext';
|
|
4
|
+
export function useListFiles(props) {
|
|
5
|
+
const [currentPage, setCurrentPage] = useState(null);
|
|
6
|
+
const context = useFencyContext();
|
|
7
|
+
const listFilesInternal = async (params) => {
|
|
8
|
+
const clientSecret = await params.fetchClientSecret();
|
|
9
|
+
const response = await listFilesApi({
|
|
10
|
+
pk: context.fency.publishableKey,
|
|
11
|
+
request: {
|
|
12
|
+
limit: props?.pageSize ?? 50,
|
|
13
|
+
pagination: {
|
|
14
|
+
nextPageToken: params.nextPageToken,
|
|
15
|
+
previousPageToken: params.previousPageToken,
|
|
16
|
+
},
|
|
17
|
+
clientSecret: clientSecret.clientSecret,
|
|
18
|
+
},
|
|
19
|
+
baseUrl: context.fency.baseUrl,
|
|
20
|
+
});
|
|
21
|
+
if (response.type === 'success') {
|
|
22
|
+
return {
|
|
23
|
+
type: 'success',
|
|
24
|
+
page: {
|
|
25
|
+
items: response.files,
|
|
26
|
+
hasNextPage: response.pagination.nextPageToken != null,
|
|
27
|
+
hasPreviousPage: response.pagination.previousPageToken != null,
|
|
28
|
+
pagination: response.pagination,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return response;
|
|
33
|
+
};
|
|
34
|
+
const listFirstPage = async (params) => {
|
|
35
|
+
const result = await listFilesInternal({
|
|
36
|
+
...params,
|
|
37
|
+
nextPageToken: undefined,
|
|
38
|
+
previousPageToken: undefined,
|
|
39
|
+
});
|
|
40
|
+
if (result.type === 'success') {
|
|
41
|
+
setCurrentPage(result.page);
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
const listNextPage = async (params) => {
|
|
46
|
+
if (currentPage == null) {
|
|
47
|
+
return {
|
|
48
|
+
type: 'error',
|
|
49
|
+
error: {
|
|
50
|
+
code: 'NO_CURRENT_PAGE',
|
|
51
|
+
message: 'No current page',
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (currentPage.pagination.nextPageToken == null) {
|
|
56
|
+
return {
|
|
57
|
+
type: 'error',
|
|
58
|
+
error: {
|
|
59
|
+
code: 'NO_NEXT_PAGE',
|
|
60
|
+
message: 'No next page',
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const result = await listFilesInternal({
|
|
65
|
+
...params,
|
|
66
|
+
nextPageToken: currentPage.pagination.nextPageToken,
|
|
67
|
+
previousPageToken: undefined,
|
|
68
|
+
});
|
|
69
|
+
if (result.type === 'success') {
|
|
70
|
+
setCurrentPage(result.page);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
};
|
|
74
|
+
const listPreviousPage = async (params) => {
|
|
75
|
+
if (currentPage == null) {
|
|
76
|
+
return {
|
|
77
|
+
type: 'error',
|
|
78
|
+
error: {
|
|
79
|
+
code: 'NO_CURRENT_PAGE',
|
|
80
|
+
message: 'No current page',
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (currentPage.pagination.previousPageToken == null) {
|
|
85
|
+
return {
|
|
86
|
+
type: 'error',
|
|
87
|
+
error: {
|
|
88
|
+
code: 'NO_PREVIOUS_PAGE',
|
|
89
|
+
message: 'No previous page',
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const result = await listFilesInternal({
|
|
94
|
+
...params,
|
|
95
|
+
nextPageToken: undefined,
|
|
96
|
+
previousPageToken: currentPage.pagination.previousPageToken,
|
|
97
|
+
});
|
|
98
|
+
if (result.type === 'success') {
|
|
99
|
+
setCurrentPage(result.page);
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
listFirstPage,
|
|
105
|
+
listNextPage,
|
|
106
|
+
listPreviousPage,
|
|
107
|
+
currentPage,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { searchFiles as searchFilesApi, } from '@fencyai/js';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useFencyContext } from '../../provider/useFencyContext';
|
|
4
|
+
export function useSearchFiles() {
|
|
5
|
+
const [searchResults, setSearchResults] = useState(undefined);
|
|
6
|
+
const context = useFencyContext();
|
|
7
|
+
const searchFiles = async (params) => {
|
|
8
|
+
const clientSecret = await params.fetchClientSecret();
|
|
9
|
+
const response = await searchFilesApi({
|
|
10
|
+
pk: context.fency.publishableKey,
|
|
11
|
+
request: {
|
|
12
|
+
text: params.text,
|
|
13
|
+
clientSecret: clientSecret.clientSecret,
|
|
14
|
+
},
|
|
15
|
+
baseUrl: context.fency.baseUrl,
|
|
16
|
+
});
|
|
17
|
+
if (response.type === 'success') {
|
|
18
|
+
setSearchResults(response.results);
|
|
19
|
+
}
|
|
20
|
+
return response;
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
searchFiles,
|
|
24
|
+
searchResults,
|
|
25
|
+
};
|
|
26
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { useBasicChatCompletions } from './hooks/useBasicChatCompletions';
|
|
2
|
-
export {
|
|
2
|
+
export { useSearchFiles } from './hooks/useSearchFiles';
|
|
3
|
+
export { useCreateFiles } from './hooks/useCreateFiles';
|
|
3
4
|
export { useStreamingChatCompletions } from './hooks/useStreamingChatCompletions';
|
|
4
5
|
export { useStructuredChatCompletions } from './hooks/useStructuredChatCompletions';
|
|
5
6
|
export { useWebsites } from './hooks/useWebsites';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Re-export components and hooks
|
|
2
2
|
export { useBasicChatCompletions } from './hooks/useBasicChatCompletions';
|
|
3
|
-
export {
|
|
3
|
+
export { useSearchFiles } from './hooks/useSearchFiles';
|
|
4
|
+
export { useCreateFiles } from './hooks/useCreateFiles';
|
|
4
5
|
export { useStreamingChatCompletions } from './hooks/useStreamingChatCompletions';
|
|
5
6
|
export { useStructuredChatCompletions } from './hooks/useStructuredChatCompletions';
|
|
6
7
|
export { useWebsites } from './hooks/useWebsites';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PaginationDto } from '@fencyai/js/lib/openapi';
|
|
2
|
+
import { FencyListFile } from '@fencyai/js/lib/types/FencyListFile';
|
|
3
|
+
export interface ListFilesPage {
|
|
4
|
+
items: FencyListFile[];
|
|
5
|
+
hasNextPage: boolean;
|
|
6
|
+
hasPreviousPage: boolean;
|
|
7
|
+
pagination: PaginationDto;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FileTextContentReady, FileUploadCompleted } from './StreamData';
|
|
2
|
-
export interface
|
|
2
|
+
export interface UseCreateFilesProps {
|
|
3
3
|
onUploadCompleted?: (event: FileUploadCompleted) => void;
|
|
4
4
|
onTextContentReady?: (event: FileTextContentReady) => void;
|
|
5
5
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ListFilesPage } from './ListFilesPage';
|
|
2
|
+
import { ListFilesParams } from './ListFilesParams';
|
|
3
|
+
import { ListFilesResult } from './ListFilesResult';
|
|
4
|
+
export interface UseListFiles {
|
|
5
|
+
listFirstPage: (params: ListFilesParams) => Promise<ListFilesResult>;
|
|
6
|
+
listNextPage: (params: ListFilesParams) => Promise<ListFilesResult>;
|
|
7
|
+
listPreviousPage: (params: ListFilesParams) => Promise<ListFilesResult>;
|
|
8
|
+
currentPage: ListFilesPage | null;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FileSearchItem, SearchFilesResponse } from '@fencyai/js';
|
|
2
|
+
import { SearchFilesParams } from './SearchFilesParams';
|
|
3
|
+
export interface UseSearchFiles {
|
|
4
|
+
searchFiles: (params: SearchFilesParams) => Promise<SearchFilesResponse>;
|
|
5
|
+
searchResults?: FileSearchItem[];
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -23,9 +23,9 @@ export * from './UseStream';
|
|
|
23
23
|
export * from './CreateStreamResponse';
|
|
24
24
|
export * from './StreamError';
|
|
25
25
|
export * from './UseStreamProps';
|
|
26
|
-
export * from './
|
|
27
|
-
export * from './UseFilesProps';
|
|
26
|
+
export * from './UseSearchFiles';
|
|
28
27
|
export * from './CreateFileParams';
|
|
28
|
+
export * from './SearchFilesParams';
|
|
29
29
|
export * from './UseWebsites';
|
|
30
30
|
export * from './UseWebsitesProps';
|
|
31
31
|
export * from './CreateWebsiteParams';
|
package/lib/types/index.js
CHANGED
|
@@ -30,9 +30,9 @@ export * from './CreateStreamResponse';
|
|
|
30
30
|
export * from './StreamError';
|
|
31
31
|
export * from './UseStreamProps';
|
|
32
32
|
// File upload types
|
|
33
|
-
export * from './
|
|
34
|
-
export * from './UseFilesProps';
|
|
33
|
+
export * from './UseSearchFiles';
|
|
35
34
|
export * from './CreateFileParams';
|
|
35
|
+
export * from './SearchFilesParams';
|
|
36
36
|
// Website types
|
|
37
37
|
export * from './UseWebsites';
|
|
38
38
|
export * from './UseWebsitesProps';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fencyai/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.61",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "staklau <steinaageklaussen@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"prepublishOnly": "npm run build"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@fencyai/js": "^0.1.
|
|
37
|
+
"@fencyai/js": "^0.1.61",
|
|
38
38
|
"@types/jest": "^29.5.11",
|
|
39
39
|
"@types/node": "^20.10.5",
|
|
40
40
|
"@types/react": "^18.2.45",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"typescript": "^5.3.3"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@fencyai/js": "^0.1.
|
|
46
|
+
"@fencyai/js": "^0.1.61",
|
|
47
47
|
"react": ">=16.8.0",
|
|
48
48
|
"zod": "^4.0.5"
|
|
49
49
|
},
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"optional": false
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "2846bdcfc0d8b16c5d1857fd4d1f63d3a584b737"
|
|
56
56
|
}
|
package/lib/types/UseFiles.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CreateFileResponse, FencyFile, SearchFilesResponse } from '@fencyai/js';
|
|
2
|
-
import { CreateFileParams } from './CreateFileParams';
|
|
3
|
-
import { SearchFilesParams } from './SearchFilesParams';
|
|
4
|
-
export interface UseFiles {
|
|
5
|
-
createFile: (params: CreateFileParams) => Promise<CreateFileResponse>;
|
|
6
|
-
files: FencyFile[];
|
|
7
|
-
searchFiles: (params: SearchFilesParams) => Promise<SearchFilesResponse>;
|
|
8
|
-
}
|
|
File without changes
|
|
File without changes
|