@fencyai/react 0.1.60 → 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.
@@ -0,0 +1,3 @@
1
+ import { UseCreateFiles } from '../../types/UseCreateFiles';
2
+ import { UseCreateFilesProps } from '../../types/UseCreateFilesProps';
3
+ export declare function useCreateFiles(props?: UseCreateFilesProps): UseCreateFiles;
@@ -1,8 +1,8 @@
1
- import { createFile as createFileApi, searchFiles as searchFilesApi, } from '@fencyai/js';
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 useFiles(props) {
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,3 @@
1
+ import { UseListFiles } from '../../types/UseListFiles';
2
+ import { UseListFilesProps } from '../../types/UseListFilesProps';
3
+ export declare function useListFiles(props?: UseListFilesProps): UseListFiles;
@@ -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,2 @@
1
+ import { UseSearchFiles } from '../../types/UseSearchFiles';
2
+ export declare function useSearchFiles(): UseSearchFiles;
@@ -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 { useFiles } from './hooks/useFiles';
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 { useFiles } from './hooks/useFiles';
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,5 @@
1
+ export interface ListFilesParams {
2
+ fetchClientSecret: () => Promise<{
3
+ clientSecret: string;
4
+ }>;
5
+ }
@@ -0,0 +1,9 @@
1
+ import { ApiError } from '@fencyai/js';
2
+ import { ListFilesPage } from './ListFilesPage';
3
+ export type ListFilesResult = {
4
+ type: 'success';
5
+ page: ListFilesPage;
6
+ } | {
7
+ type: 'error';
8
+ error: ApiError;
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { CreateFileResponse, FencyFile } from '@fencyai/js';
2
+ import { CreateFileParams } from './CreateFileParams';
3
+ export interface UseCreateFiles {
4
+ createFile: (params: CreateFileParams) => Promise<CreateFileResponse>;
5
+ files: FencyFile[];
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { FileTextContentReady, FileUploadCompleted } from './StreamData';
2
- export interface UseFilesProps {
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,3 @@
1
+ export interface UseListFilesProps {
2
+ pageSize?: number;
3
+ }
@@ -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 {};
@@ -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 './UseFiles';
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';
@@ -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 './UseFiles';
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.60",
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.60",
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.60",
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": "75f1fd665a806dcaa11208084cbb55af65382567"
55
+ "gitHead": "2846bdcfc0d8b16c5d1857fd4d1f63d3a584b737"
56
56
  }
@@ -1,3 +0,0 @@
1
- import { UseFiles } from '../../types/UseFiles';
2
- import { UseFilesProps } from '../../types/UseFilesProps';
3
- export declare function useFiles(props?: UseFilesProps): UseFiles;
@@ -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