@fencyai/react 0.1.47 → 0.1.48
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/useFiles/index.d.ts +3 -3
- package/lib/hooks/useFiles/index.js +5 -5
- package/lib/hooks/useStream/index.js +10 -3
- package/lib/hooks/useWebsites/index.d.ts +2 -1
- package/lib/hooks/useWebsites/index.js +46 -9
- package/lib/types/FileUpload.d.ts +4 -4
- package/lib/types/{UseFileUploads.d.ts → UseFiles.d.ts} +1 -1
- package/lib/types/UseFilesProps.d.ts +5 -0
- package/lib/types/UseStreamProps.d.ts +4 -2
- package/lib/types/UseWebsites.d.ts +3 -2
- package/lib/types/UseWebsitesProps.d.ts +5 -0
- package/lib/types/UseWebsitesProps.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/types/UseFileUploadProps.d.ts +0 -5
- /package/lib/types/{UseFileUploadProps.js → UseFiles.js} +0 -0
- /package/lib/types/{UseFileUploads.js → UseFilesProps.js} +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare function useFiles(props:
|
|
1
|
+
import { UseFiles } from '../../types/UseFiles';
|
|
2
|
+
import { UseFilesProps } from '../../types/UseFilesProps';
|
|
3
|
+
export declare function useFiles(props: UseFilesProps): UseFiles;
|
|
@@ -7,7 +7,7 @@ export function useFiles(props) {
|
|
|
7
7
|
const context = useFencyContext();
|
|
8
8
|
const { createStream } = useStream({
|
|
9
9
|
onFileUploadCompleted: (streamData) => {
|
|
10
|
-
props.
|
|
10
|
+
props.onUploadCompleted?.(streamData);
|
|
11
11
|
setFileUploads((prev) => prev.map((fileUpload) => {
|
|
12
12
|
return fileUpload.upload.id === streamData.uploadId
|
|
13
13
|
? { ...fileUpload, status: 'upload_complete' }
|
|
@@ -15,7 +15,7 @@ export function useFiles(props) {
|
|
|
15
15
|
}));
|
|
16
16
|
},
|
|
17
17
|
onFileTextContentReady: (streamData) => {
|
|
18
|
-
props.
|
|
18
|
+
props.onTextContentReady?.(streamData);
|
|
19
19
|
setFileUploads((prev) => prev.map((fileUpload) => fileUpload.upload.id === streamData.uploadId
|
|
20
20
|
? { ...fileUpload, textContent: streamData.text }
|
|
21
21
|
: fileUpload));
|
|
@@ -23,7 +23,7 @@ export function useFiles(props) {
|
|
|
23
23
|
});
|
|
24
24
|
const createFileUpload = async (params) => {
|
|
25
25
|
const stream = await createStream({
|
|
26
|
-
type: '
|
|
26
|
+
type: 'FileStream',
|
|
27
27
|
});
|
|
28
28
|
if (stream.type === 'success') {
|
|
29
29
|
const response = await createUpload({
|
|
@@ -45,8 +45,8 @@ export function useFiles(props) {
|
|
|
45
45
|
file: null,
|
|
46
46
|
error: null,
|
|
47
47
|
textContent: null,
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
onUploadCompleted: props.onUploadCompleted,
|
|
49
|
+
onTextContentReady: props.onTextContentReady,
|
|
50
50
|
},
|
|
51
51
|
]);
|
|
52
52
|
}
|
|
@@ -18,7 +18,10 @@ export const useStream = (props) => {
|
|
|
18
18
|
},
|
|
19
19
|
onMessage: (message) => {
|
|
20
20
|
const streamData = toStreamData(message.data);
|
|
21
|
-
|
|
21
|
+
if (!streamData) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
switch (streamData.type) {
|
|
22
25
|
case 'NewChatCompletionStreamChunk':
|
|
23
26
|
props?.onNewChatCompletionStreamChunk?.(streamData);
|
|
24
27
|
return true;
|
|
@@ -37,8 +40,12 @@ export const useStream = (props) => {
|
|
|
37
40
|
case 'FileTextContentReady':
|
|
38
41
|
props?.onFileTextContentReady?.(streamData);
|
|
39
42
|
return true;
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
case 'WebsiteHtmlContentReady':
|
|
44
|
+
props?.onWebsiteHtmlContentReady?.(streamData);
|
|
45
|
+
return true;
|
|
46
|
+
case 'WebsiteTextContentReady':
|
|
47
|
+
props?.onWebsiteTextContentReady?.(streamData);
|
|
48
|
+
return true;
|
|
42
49
|
}
|
|
43
50
|
},
|
|
44
51
|
});
|
|
@@ -1,16 +1,53 @@
|
|
|
1
|
-
import { createWebsite } from '@fencyai/js';
|
|
1
|
+
import { createWebsite as createWebsiteApi, } from '@fencyai/js';
|
|
2
|
+
import { useState } from 'react';
|
|
2
3
|
import { useFencyContext } from '../../provider/useFencyContext';
|
|
3
|
-
|
|
4
|
+
import { useStream } from '../useStream';
|
|
5
|
+
export function useWebsites(props) {
|
|
4
6
|
const context = useFencyContext();
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const [websites, setWebsites] = useState([]);
|
|
8
|
+
const { createStream } = useStream({
|
|
9
|
+
onWebsiteHtmlContentReady: (streamData) => {
|
|
10
|
+
props.onHtmlContentReady?.(streamData);
|
|
11
|
+
setWebsites((prev) => prev.map((website) => {
|
|
12
|
+
return website.id === streamData.websiteId
|
|
13
|
+
? { ...website, status: 'website_complete' }
|
|
14
|
+
: website;
|
|
15
|
+
}));
|
|
16
|
+
},
|
|
17
|
+
onWebsiteTextContentReady: (streamData) => {
|
|
18
|
+
props.onTextContentReady?.(streamData);
|
|
19
|
+
setWebsites((prev) => prev.map((website) => website.id === streamData.websiteId
|
|
20
|
+
? { ...website, textContent: streamData.textContent }
|
|
21
|
+
: website));
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
const createWebsite = async (params) => {
|
|
25
|
+
const stream = await createStream({
|
|
26
|
+
type: 'ChatCompletionStream',
|
|
10
27
|
});
|
|
11
|
-
|
|
28
|
+
if (stream.type === 'success') {
|
|
29
|
+
const response = await createWebsiteApi({
|
|
30
|
+
pk: context.fency.publishableKey,
|
|
31
|
+
request: {
|
|
32
|
+
url: params.url,
|
|
33
|
+
streamId: stream.stream.id,
|
|
34
|
+
},
|
|
35
|
+
baseUrl: context.fency.baseUrl,
|
|
36
|
+
});
|
|
37
|
+
if (response.type === 'success') {
|
|
38
|
+
setWebsites([...websites, response.website]);
|
|
39
|
+
}
|
|
40
|
+
return response;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return {
|
|
44
|
+
type: 'error',
|
|
45
|
+
error: stream.error,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
12
48
|
};
|
|
13
49
|
return {
|
|
14
|
-
|
|
50
|
+
createWebsite,
|
|
51
|
+
websites,
|
|
15
52
|
};
|
|
16
53
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ApiError, FencyFile,
|
|
1
|
+
import { ApiError, FencyFile, FileUploadCompleted, FileTextContentReady, Upload } from '@fencyai/js';
|
|
2
2
|
import { FileUploadStatus } from './FileUploadStatus';
|
|
3
3
|
export interface FileUpload {
|
|
4
4
|
status: FileUploadStatus;
|
|
5
|
-
upload:
|
|
5
|
+
upload: Upload;
|
|
6
6
|
file: FencyFile | null;
|
|
7
7
|
error: ApiError | null;
|
|
8
8
|
textContent: string | null;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
onUploadCompleted?: (event: FileUploadCompleted) => void;
|
|
10
|
+
onTextContentReady?: (event: FileTextContentReady) => void;
|
|
11
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CreateUploadResponse } from '@fencyai/js';
|
|
2
2
|
import { CreateUploadParams } from './CreateUploadParams';
|
|
3
3
|
import { FileUpload } from './FileUpload';
|
|
4
|
-
export interface
|
|
4
|
+
export interface UseFiles {
|
|
5
5
|
createFileUpload: (params: CreateUploadParams) => Promise<CreateUploadResponse>;
|
|
6
6
|
fileUploads: FileUpload[];
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ChatCompletionStreamCompleted,
|
|
1
|
+
import { ChatCompletionStreamCompleted, NewChatCompletionStreamChunk, StreamNotFound, StreamTimeout } from '@fencyai/js';
|
|
2
|
+
import { FileUploadCompleted, FileTextContentReady, WebsiteHtmlContentReady, WebsiteTextContentReady } from '@fencyai/js/lib/types/StreamData';
|
|
2
3
|
import { StreamError } from './StreamError';
|
|
3
|
-
import { FileTextContentReady } from '@fencyai/js/lib/types/StreamData';
|
|
4
4
|
export interface UseStreamProps {
|
|
5
5
|
onNewChatCompletionStreamChunk?: (streamData: NewChatCompletionStreamChunk) => void;
|
|
6
6
|
onChatCompletionStreamCompleted?: (stream: ChatCompletionStreamCompleted) => void;
|
|
@@ -8,5 +8,7 @@ export interface UseStreamProps {
|
|
|
8
8
|
onStreamNotFound?: (error: StreamNotFound) => void;
|
|
9
9
|
onFileUploadCompleted?: (error: FileUploadCompleted) => void;
|
|
10
10
|
onFileTextContentReady?: (error: FileTextContentReady) => void;
|
|
11
|
+
onWebsiteHtmlContentReady?: (error: WebsiteHtmlContentReady) => void;
|
|
12
|
+
onWebsiteTextContentReady?: (error: WebsiteTextContentReady) => void;
|
|
11
13
|
onStreamError?: (error: StreamError) => void;
|
|
12
14
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CreateWebsiteRequest, CreateWebsiteResponse } from '@fencyai/js';
|
|
1
|
+
import { CreateWebsiteRequest, CreateWebsiteResponse, Website } from '@fencyai/js';
|
|
2
2
|
export interface UseWebsites {
|
|
3
|
-
|
|
3
|
+
websites: Website[];
|
|
4
|
+
createWebsite: (params: CreateWebsiteRequest) => Promise<CreateWebsiteResponse>;
|
|
4
5
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { WebsiteHtmlContentReady, WebsiteTextContentReady } from '@fencyai/js/lib/types/StreamData';
|
|
2
|
+
export interface UseWebsitesProps {
|
|
3
|
+
onHtmlContentReady?: (event: WebsiteHtmlContentReady) => void;
|
|
4
|
+
onTextContentReady?: (event: WebsiteTextContentReady) => void;
|
|
5
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -18,8 +18,8 @@ export * from './UseStream';
|
|
|
18
18
|
export * from './CreateStreamResponse';
|
|
19
19
|
export * from './StreamError';
|
|
20
20
|
export * from './UseStreamProps';
|
|
21
|
-
export * from './
|
|
22
|
-
export * from './
|
|
21
|
+
export * from './UseFiles';
|
|
22
|
+
export * from './UseFilesProps';
|
|
23
23
|
export * from './FileUploadStatus';
|
|
24
24
|
export * from './FileUpload';
|
|
25
25
|
export * from './UseWebsites';
|
package/lib/types/index.js
CHANGED
|
@@ -25,8 +25,8 @@ export * from './CreateStreamResponse';
|
|
|
25
25
|
export * from './StreamError';
|
|
26
26
|
export * from './UseStreamProps';
|
|
27
27
|
// File upload types
|
|
28
|
-
export * from './
|
|
29
|
-
export * from './
|
|
28
|
+
export * from './UseFiles';
|
|
29
|
+
export * from './UseFilesProps';
|
|
30
30
|
export * from './FileUploadStatus';
|
|
31
31
|
export * from './FileUpload';
|
|
32
32
|
// Website types
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fencyai/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.48",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "staklau <steinaageklaussen@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"zod": "^4.0.5"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@fencyai/js": "^0.1.
|
|
39
|
+
"@fencyai/js": "^0.1.48",
|
|
40
40
|
"@types/jest": "^29.5.11",
|
|
41
41
|
"@types/node": "^20.10.5",
|
|
42
42
|
"@types/react": "^18.2.45",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"typescript": "^5.3.3"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@fencyai/js": "^0.1.
|
|
48
|
+
"@fencyai/js": "^0.1.48",
|
|
49
49
|
"react": ">=16.8.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "889ff241bad28cb096835f3e72389bfdcf1d51ee"
|
|
52
52
|
}
|
|
File without changes
|
|
File without changes
|