@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.
@@ -1,3 +1,3 @@
1
- import { UseFileUploadProps } from '../../types/UseFileUploadProps';
2
- import { UseFileUploads } from '../../types/UseFileUploads';
3
- export declare function useFiles(props: UseFileUploadProps): UseFileUploads;
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.onUploadComplete?.(streamData);
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.onFileTextContentReady?.(streamData);
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: 'FileUploadStream',
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
- onUploadComplete: props.onUploadComplete,
49
- onFileTextContentReady: props.onFileTextContentReady,
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
- switch (streamData?.type) {
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
- default:
41
- return false;
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,2 +1,3 @@
1
1
  import { UseWebsites } from '../../types/UseWebsites';
2
- export declare function useWebsites(): UseWebsites;
2
+ import { UseWebsitesProps } from '../../types/UseWebsitesProps';
3
+ export declare function useWebsites(props: UseWebsitesProps): UseWebsites;
@@ -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
- export function useWebsites() {
4
+ import { useStream } from '../useStream';
5
+ export function useWebsites(props) {
4
6
  const context = useFencyContext();
5
- const scrapeContent = async (params) => {
6
- const response = await createWebsite({
7
- pk: context.fency.publishableKey,
8
- request: params,
9
- baseUrl: context.fency.baseUrl,
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
- return response;
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
- scrapeContent,
50
+ createWebsite,
51
+ websites,
15
52
  };
16
53
  }
@@ -1,11 +1,11 @@
1
- import { ApiError, FencyFile, FencyUpload, FileTextContentReady, FileUploadCompleted } from '@fencyai/js';
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: FencyUpload;
5
+ upload: Upload;
6
6
  file: FencyFile | null;
7
7
  error: ApiError | null;
8
8
  textContent: string | null;
9
- onUploadComplete?: (fileUpload: FileUploadCompleted) => void;
10
- onFileTextContentReady?: (fileTextContentReady: FileTextContentReady) => void;
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 UseFileUploads {
4
+ export interface UseFiles {
5
5
  createFileUpload: (params: CreateUploadParams) => Promise<CreateUploadResponse>;
6
6
  fileUploads: FileUpload[];
7
7
  }
@@ -0,0 +1,5 @@
1
+ import { FileTextContentReady, FileUploadCompleted } from '@fencyai/js/lib/types/StreamData';
2
+ export interface UseFilesProps {
3
+ onUploadCompleted?: (event: FileUploadCompleted) => void;
4
+ onTextContentReady?: (event: FileTextContentReady) => void;
5
+ }
@@ -1,6 +1,6 @@
1
- import { ChatCompletionStreamCompleted, FileUploadCompleted, NewChatCompletionStreamChunk, StreamNotFound, StreamTimeout } from '@fencyai/js';
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
- scrapeContent: (params: CreateWebsiteRequest) => Promise<CreateWebsiteResponse>;
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 {};
@@ -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 './UseFileUploads';
22
- export * from './UseFileUploadProps';
21
+ export * from './UseFiles';
22
+ export * from './UseFilesProps';
23
23
  export * from './FileUploadStatus';
24
24
  export * from './FileUpload';
25
25
  export * from './UseWebsites';
@@ -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 './UseFileUploads';
29
- export * from './UseFileUploadProps';
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.47",
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.47",
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.47",
48
+ "@fencyai/js": "^0.1.48",
49
49
  "react": ">=16.8.0"
50
50
  },
51
- "gitHead": "f86bd2ae856f0dfc51edbf434e62e63f4c86f79b"
51
+ "gitHead": "889ff241bad28cb096835f3e72389bfdcf1d51ee"
52
52
  }
@@ -1,5 +0,0 @@
1
- import { FileUploadCompleted, FileTextContentReady } from '@fencyai/js';
2
- export interface UseFileUploadProps {
3
- onUploadComplete?: (fileUpload: FileUploadCompleted) => void;
4
- onFileTextContentReady?: (fileTextContentReady: FileTextContentReady) => void;
5
- }