@fencyai/react 0.1.60 → 0.1.62
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 +2 -15
- 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 +3 -1
- package/lib/index.js +3 -1
- 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 +19 -12
- package/lib/types/index.js +21 -12
- 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,8 +1,8 @@
|
|
|
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({
|
|
@@ -59,21 +59,8 @@ export function useFiles(props) {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
const searchFiles = async (params) => {
|
|
63
|
-
const clientSecret = await params.fetchClientSecret();
|
|
64
|
-
const response = await searchFilesApi({
|
|
65
|
-
pk: context.fency.publishableKey,
|
|
66
|
-
request: {
|
|
67
|
-
text: params.text,
|
|
68
|
-
clientSecret: clientSecret.clientSecret,
|
|
69
|
-
},
|
|
70
|
-
baseUrl: context.fency.baseUrl,
|
|
71
|
-
});
|
|
72
|
-
return response;
|
|
73
|
-
};
|
|
74
62
|
return {
|
|
75
63
|
createFile,
|
|
76
|
-
searchFiles,
|
|
77
64
|
files,
|
|
78
65
|
};
|
|
79
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,7 @@
|
|
|
1
1
|
export { useBasicChatCompletions } from './hooks/useBasicChatCompletions';
|
|
2
|
-
export {
|
|
2
|
+
export { useSearchFiles } from './hooks/useSearchFiles';
|
|
3
|
+
export { useCreateFiles } from './hooks/useCreateFiles';
|
|
4
|
+
export { useListFiles } from './hooks/useListFiles';
|
|
3
5
|
export { useStreamingChatCompletions } from './hooks/useStreamingChatCompletions';
|
|
4
6
|
export { useStructuredChatCompletions } from './hooks/useStructuredChatCompletions';
|
|
5
7
|
export { useWebsites } from './hooks/useWebsites';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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';
|
|
5
|
+
export { useListFiles } from './hooks/useListFiles';
|
|
4
6
|
export { useStreamingChatCompletions } from './hooks/useStreamingChatCompletions';
|
|
5
7
|
export { useStructuredChatCompletions } from './hooks/useStructuredChatCompletions';
|
|
6
8
|
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
|
@@ -1,31 +1,38 @@
|
|
|
1
|
-
export * from './FencyProviderProps';
|
|
2
1
|
export * from './FencyContext';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './CreateGeminiChatCompletionParams';
|
|
2
|
+
export * from './FencyProviderProps';
|
|
5
3
|
export * from './CreateClaudeChatCompletionParams';
|
|
6
|
-
export * from './
|
|
4
|
+
export * from './CreateGeminiChatCompletionParams';
|
|
5
|
+
export * from './CreateOpenAiChatCompletionParams';
|
|
7
6
|
export * from './BasicChatCompletion';
|
|
7
|
+
export * from './BasicChatCompletionData';
|
|
8
8
|
export * from './BasicChatCompletionResponse';
|
|
9
9
|
export * from './CreateBasicChatCompletionParams';
|
|
10
10
|
export * from './UseBasicChatCompletions';
|
|
11
|
-
export * from './StreamingChatCompletionData';
|
|
12
|
-
export * from './StreamingChatCompletion';
|
|
13
11
|
export * from './CreateStreamingChatCompletionParams';
|
|
14
12
|
export * from './CreateStreamingChatCompletionResponse';
|
|
13
|
+
export * from './StreamingChatCompletion';
|
|
14
|
+
export * from './StreamingChatCompletionData';
|
|
15
15
|
export * from './UseStreamingChatCompletions';
|
|
16
16
|
export * from './UseStreamingChatCompletionsProps';
|
|
17
|
-
export * from './
|
|
17
|
+
export * from './CreateStructuredChatCompletionParams';
|
|
18
18
|
export * from './StructuredChatCompletion';
|
|
19
|
+
export * from './StructuredChatCompletionData';
|
|
19
20
|
export * from './StructuredChatCompletionResponse';
|
|
20
|
-
export * from './CreateStructuredChatCompletionParams';
|
|
21
21
|
export * from './UseStructuredChatCompletions';
|
|
22
|
-
export * from './UseStream';
|
|
23
22
|
export * from './CreateStreamResponse';
|
|
24
23
|
export * from './StreamError';
|
|
24
|
+
export * from './UseStream';
|
|
25
25
|
export * from './UseStreamProps';
|
|
26
|
-
export * from './UseFiles';
|
|
27
|
-
export * from './UseFilesProps';
|
|
28
26
|
export * from './CreateFileParams';
|
|
27
|
+
export * from './SearchFilesParams';
|
|
28
|
+
export * from './UseSearchFiles';
|
|
29
|
+
export * from './CreateWebsiteParams';
|
|
29
30
|
export * from './UseWebsites';
|
|
30
31
|
export * from './UseWebsitesProps';
|
|
31
|
-
export * from './
|
|
32
|
+
export * from './ListFilesPage';
|
|
33
|
+
export * from './ListFilesParams';
|
|
34
|
+
export * from './ListFilesResult';
|
|
35
|
+
export * from './UseListFiles';
|
|
36
|
+
export * from './UseListFilesProps';
|
|
37
|
+
export * from './SearchFilesParams';
|
|
38
|
+
export * from './UseSearchFiles';
|
package/lib/types/index.js
CHANGED
|
@@ -1,39 +1,48 @@
|
|
|
1
1
|
// Provider types
|
|
2
|
-
export * from './FencyProviderProps';
|
|
3
2
|
export * from './FencyContext';
|
|
3
|
+
export * from './FencyProviderProps';
|
|
4
4
|
// Chat completion parameter types
|
|
5
|
-
export * from './CreateOpenAiChatCompletionParams';
|
|
6
|
-
export * from './CreateGeminiChatCompletionParams';
|
|
7
5
|
export * from './CreateClaudeChatCompletionParams';
|
|
6
|
+
export * from './CreateGeminiChatCompletionParams';
|
|
7
|
+
export * from './CreateOpenAiChatCompletionParams';
|
|
8
8
|
// Basic chat completion types
|
|
9
|
-
export * from './BasicChatCompletionData';
|
|
10
9
|
export * from './BasicChatCompletion';
|
|
10
|
+
export * from './BasicChatCompletionData';
|
|
11
11
|
export * from './BasicChatCompletionResponse';
|
|
12
12
|
export * from './CreateBasicChatCompletionParams';
|
|
13
13
|
export * from './UseBasicChatCompletions';
|
|
14
14
|
// Streaming chat completion types
|
|
15
|
-
export * from './StreamingChatCompletionData';
|
|
16
|
-
export * from './StreamingChatCompletion';
|
|
17
15
|
export * from './CreateStreamingChatCompletionParams';
|
|
18
16
|
export * from './CreateStreamingChatCompletionResponse';
|
|
17
|
+
export * from './StreamingChatCompletion';
|
|
18
|
+
export * from './StreamingChatCompletionData';
|
|
19
19
|
export * from './UseStreamingChatCompletions';
|
|
20
20
|
export * from './UseStreamingChatCompletionsProps';
|
|
21
21
|
// Structured chat completion types
|
|
22
|
-
export * from './
|
|
22
|
+
export * from './CreateStructuredChatCompletionParams';
|
|
23
23
|
export * from './StructuredChatCompletion';
|
|
24
|
+
export * from './StructuredChatCompletionData';
|
|
24
25
|
export * from './StructuredChatCompletionResponse';
|
|
25
|
-
export * from './CreateStructuredChatCompletionParams';
|
|
26
26
|
export * from './UseStructuredChatCompletions';
|
|
27
27
|
// Stream types
|
|
28
|
-
export * from './UseStream';
|
|
29
28
|
export * from './CreateStreamResponse';
|
|
30
29
|
export * from './StreamError';
|
|
30
|
+
export * from './UseStream';
|
|
31
31
|
export * from './UseStreamProps';
|
|
32
32
|
// File upload types
|
|
33
|
-
export * from './UseFiles';
|
|
34
|
-
export * from './UseFilesProps';
|
|
35
33
|
export * from './CreateFileParams';
|
|
34
|
+
export * from './SearchFilesParams';
|
|
35
|
+
export * from './UseSearchFiles';
|
|
36
36
|
// Website types
|
|
37
|
+
export * from './CreateWebsiteParams';
|
|
37
38
|
export * from './UseWebsites';
|
|
38
39
|
export * from './UseWebsitesProps';
|
|
39
|
-
|
|
40
|
+
// List files types
|
|
41
|
+
export * from './ListFilesPage';
|
|
42
|
+
export * from './ListFilesParams';
|
|
43
|
+
export * from './ListFilesResult';
|
|
44
|
+
export * from './UseListFiles';
|
|
45
|
+
export * from './UseListFilesProps';
|
|
46
|
+
// Search files types
|
|
47
|
+
export * from './SearchFilesParams';
|
|
48
|
+
export * from './UseSearchFiles';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fencyai/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.62",
|
|
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.62",
|
|
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.62",
|
|
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": "922223209403b8f4c393a027ac5c3a5b60e1b0c2"
|
|
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
|