@fencyai/react 0.1.46 → 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/useBasicChatCompletions/index.d.ts +2 -0
- package/lib/{useChatCompletions/useSynchronousChatCompletions.js → hooks/useBasicChatCompletions/index.js} +5 -3
- package/lib/hooks/useFiles/index.d.ts +3 -0
- package/lib/{useFileUploads → hooks/useFiles}/index.js +7 -7
- package/lib/hooks/useStream/index.d.ts +3 -0
- package/lib/{useStream → hooks/useStream}/index.js +11 -4
- package/lib/hooks/useStreamingChatCompletions/index.d.ts +2 -0
- package/lib/{useChatCompletions/useStreamingChatCompletions.js → hooks/useStreamingChatCompletions/index.js} +4 -3
- package/lib/hooks/useStructuredChatCompletions/index.d.ts +2 -0
- package/lib/{useChatCompletions/useStructuredChatCompletions.js → hooks/useStructuredChatCompletions/index.js} +3 -1
- package/lib/hooks/useWebsites/index.d.ts +3 -0
- package/lib/hooks/useWebsites/index.js +53 -0
- package/lib/index.d.ts +5 -3
- package/lib/index.js +5 -3
- package/lib/types/BasicChatCompletion.d.ts +8 -0
- package/lib/types/{SynchronousChatCompletionData.d.ts → BasicChatCompletionData.d.ts} +1 -1
- package/lib/types/BasicChatCompletionResponse.d.ts +9 -0
- package/lib/types/{CreateSynchronousChatCompletionParams.d.ts → CreateBasicChatCompletionParams.d.ts} +1 -1
- package/lib/types/CreateStreamingChatCompletionResponse.d.ts +9 -0
- package/lib/types/FileUpload.d.ts +4 -4
- package/lib/types/UseBasicChatCompletions.d.ts +7 -0
- 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/UseStreamingChatCompletions.d.ts +7 -0
- package/lib/types/UseStreamingChatCompletions.js +1 -0
- package/lib/types/UseStructuredChatCompletions.d.ts +8 -0
- package/lib/types/UseStructuredChatCompletions.js +1 -0
- 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 +6 -8
- package/lib/types/index.js +7 -10
- package/package.json +4 -4
- package/lib/types/CombinedChatCompletion.d.ts +0 -14
- package/lib/types/SynchronousChatCompletion.d.ts +0 -8
- package/lib/types/SynchronousChatCompletionResponse.d.ts +0 -9
- package/lib/types/UseChatCompletions.d.ts +0 -30
- package/lib/types/UseFileUploadProps.d.ts +0 -5
- package/lib/useChatCompletions/index.d.ts +0 -2
- package/lib/useChatCompletions/index.js +0 -66
- package/lib/useChatCompletions/useStreamingChatCompletions.d.ts +0 -16
- package/lib/useChatCompletions/useStructuredChatCompletions.d.ts +0 -9
- package/lib/useChatCompletions/useSynchronousChatCompletions.d.ts +0 -8
- package/lib/useFileUploads/index.d.ts +0 -3
- package/lib/useStream/index.d.ts +0 -3
- package/lib/useWebsites/index.d.ts +0 -2
- package/lib/useWebsites/index.js +0 -16
- /package/lib/{useEventSource.d.ts → hooks/useEventSource/index.d.ts} +0 -0
- /package/lib/{useEventSource.js → hooks/useEventSource/index.js} +0 -0
- /package/lib/types/{CombinedChatCompletion.js → BasicChatCompletion.js} +0 -0
- /package/lib/types/{CreateSynchronousChatCompletionParams.js → BasicChatCompletionData.js} +0 -0
- /package/lib/types/{SynchronousChatCompletion.js → BasicChatCompletionResponse.js} +0 -0
- /package/lib/types/{SynchronousChatCompletionData.js → CreateBasicChatCompletionParams.js} +0 -0
- /package/lib/types/{SynchronousChatCompletionResponse.js → CreateStreamingChatCompletionResponse.js} +0 -0
- /package/lib/types/{UseChatCompletions.js → UseBasicChatCompletions.js} +0 -0
- /package/lib/types/{UseFileUploadProps.js → UseFiles.js} +0 -0
- /package/lib/types/{UseFileUploads.js → UseFilesProps.js} +0 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createChatCompletion } from '@fencyai/js';
|
|
2
2
|
import { useCallback, useState } from 'react';
|
|
3
|
-
|
|
3
|
+
import { useFencyContext } from '../../provider/useFencyContext';
|
|
4
|
+
export const useBasicChatCompletions = () => {
|
|
5
|
+
const context = useFencyContext();
|
|
4
6
|
const [chatCompletions, setChatCompletions] = useState([]);
|
|
5
|
-
const
|
|
7
|
+
const createBasicChatCompletion = useCallback(async (params) => {
|
|
6
8
|
const triggeredAt = new Date().toISOString();
|
|
7
9
|
setChatCompletions((prev) => [
|
|
8
10
|
...prev,
|
|
@@ -101,6 +103,6 @@ export const useSynchronousChatCompletions = (context) => {
|
|
|
101
103
|
}, [context]);
|
|
102
104
|
return {
|
|
103
105
|
chatCompletions,
|
|
104
|
-
|
|
106
|
+
createBasicChatCompletion,
|
|
105
107
|
};
|
|
106
108
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createUpload } from '@fencyai/js';
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import { useFencyContext } from '
|
|
3
|
+
import { useFencyContext } from '../../provider/useFencyContext';
|
|
4
4
|
import { useStream } from '../useStream';
|
|
5
|
-
export function
|
|
5
|
+
export function useFiles(props) {
|
|
6
6
|
const [fileUploads, setFileUploads] = useState([]);
|
|
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 useFileUploads(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 useFileUploads(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 useFileUploads(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
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createStream as createStreamApi, } from '@fencyai/js';
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import { useFencyContext } from '
|
|
3
|
+
import { useFencyContext } from '../../provider/useFencyContext';
|
|
4
4
|
import { useEventSource } from '../useEventSource';
|
|
5
5
|
export const useStream = (props) => {
|
|
6
6
|
const context = useFencyContext();
|
|
@@ -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,7 +1,9 @@
|
|
|
1
|
-
import { createChatCompletion
|
|
1
|
+
import { createChatCompletion } from '@fencyai/js';
|
|
2
2
|
import { useCallback, useEffect, useState } from 'react';
|
|
3
3
|
import { useStream } from '../useStream';
|
|
4
|
-
|
|
4
|
+
import { useFencyContext } from '../../provider/useFencyContext';
|
|
5
|
+
export const useStreamingChatCompletions = () => {
|
|
6
|
+
const context = useFencyContext();
|
|
5
7
|
const [chatCompletions, setChatCompletions] = useState([]);
|
|
6
8
|
const [completedStreamIds, setCompletedStreamIds] = useState([]);
|
|
7
9
|
const [chunks, setChunks] = useState([]);
|
|
@@ -190,6 +192,5 @@ export const useStreamingChatCompletions = (context) => {
|
|
|
190
192
|
return {
|
|
191
193
|
chatCompletions,
|
|
192
194
|
createStreamingChatCompletion,
|
|
193
|
-
stream,
|
|
194
195
|
};
|
|
195
196
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { createChatCompletion } from '@fencyai/js';
|
|
2
2
|
import { useCallback, useState } from 'react';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
|
|
4
|
+
import { useFencyContext } from '../../provider/useFencyContext';
|
|
5
|
+
export const useStructuredChatCompletions = () => {
|
|
6
|
+
const context = useFencyContext();
|
|
5
7
|
const [chatCompletions, setChatCompletions] = useState([]);
|
|
6
8
|
const createStructuredChatCompletion = useCallback(async (params) => {
|
|
7
9
|
const triggeredAt = new Date().toISOString();
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createWebsite as createWebsiteApi, } from '@fencyai/js';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useFencyContext } from '../../provider/useFencyContext';
|
|
4
|
+
import { useStream } from '../useStream';
|
|
5
|
+
export function useWebsites(props) {
|
|
6
|
+
const context = useFencyContext();
|
|
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',
|
|
27
|
+
});
|
|
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
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
createWebsite,
|
|
51
|
+
websites,
|
|
52
|
+
};
|
|
53
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { useBasicChatCompletions } from './hooks/useBasicChatCompletions';
|
|
2
|
+
export { useFiles } from './hooks/useFiles';
|
|
3
|
+
export { useStreamingChatCompletions } from './hooks/useStreamingChatCompletions';
|
|
4
|
+
export { useStructuredChatCompletions } from './hooks/useStructuredChatCompletions';
|
|
5
|
+
export { useWebsites } from './hooks/useWebsites';
|
|
4
6
|
export { FencyProvider } from './provider/FencyProvider';
|
|
5
7
|
export * from './types';
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Re-export components and hooks
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
2
|
+
export { useBasicChatCompletions } from './hooks/useBasicChatCompletions';
|
|
3
|
+
export { useFiles } from './hooks/useFiles';
|
|
4
|
+
export { useStreamingChatCompletions } from './hooks/useStreamingChatCompletions';
|
|
5
|
+
export { useStructuredChatCompletions } from './hooks/useStructuredChatCompletions';
|
|
6
|
+
export { useWebsites } from './hooks/useWebsites';
|
|
5
7
|
// Re-export providers
|
|
6
8
|
export { FencyProvider } from './provider/FencyProvider';
|
|
7
9
|
// Re-export all types from centralized location
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CreateOpenAiChatCompletionParams } from './CreateOpenAiChatCompletionParams';
|
|
2
2
|
import { CreateGeminiChatCompletionParams } from './CreateGeminiChatCompletionParams';
|
|
3
3
|
import { CreateAnthropicChatCompletionParams } from './CreateAnthropicChatCompletionParams';
|
|
4
|
-
export interface
|
|
4
|
+
export interface CreateBasicChatCompletionParams {
|
|
5
5
|
openai?: CreateOpenAiChatCompletionParams;
|
|
6
6
|
gemini?: CreateGeminiChatCompletionParams;
|
|
7
7
|
anthropic?: CreateAnthropicChatCompletionParams;
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BasicChatCompletion } from "./BasicChatCompletion";
|
|
2
|
+
import { CreateBasicChatCompletionParams } from "./CreateBasicChatCompletionParams";
|
|
3
|
+
import { BasicChatCompletionResponse } from "./BasicChatCompletionResponse";
|
|
4
|
+
export interface UseBasicChatCompletions {
|
|
5
|
+
chatCompletions: BasicChatCompletion[];
|
|
6
|
+
createBasicChatCompletion: (params: CreateBasicChatCompletionParams) => Promise<BasicChatCompletionResponse>;
|
|
7
|
+
}
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CreateStreamingChatCompletionParams } from "./CreateStreamingChatCompletionParams";
|
|
2
|
+
import { CreateStreamingChatCompletionResponse } from "./CreateStreamingChatCompletionResponse";
|
|
3
|
+
import { StreamingChatCompletion } from "./StreamingChatCompletion";
|
|
4
|
+
export interface UseStreamingChatCompletions {
|
|
5
|
+
chatCompletions: StreamingChatCompletion[];
|
|
6
|
+
createStreamingChatCompletion: (params: CreateStreamingChatCompletionParams) => Promise<CreateStreamingChatCompletionResponse>;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ZodTypeAny } from 'zod';
|
|
2
|
+
import { CreateStructuredChatCompletionParams } from './CreateStructuredChatCompletionParams';
|
|
3
|
+
import { StructuredChatCompletion } from './StructuredChatCompletion';
|
|
4
|
+
import { StructuredChatCompletionResponse } from './StructuredChatCompletionResponse';
|
|
5
|
+
export interface UseStructuredChatCompletions {
|
|
6
|
+
chatCompletions: StructuredChatCompletion<ZodTypeAny>[];
|
|
7
|
+
createStructuredChatCompletion: <T extends ZodTypeAny>(params: CreateStructuredChatCompletionParams<T>) => Promise<StructuredChatCompletionResponse<T>>;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
@@ -3,10 +3,10 @@ export * from './FencyContext';
|
|
|
3
3
|
export * from './CreateOpenAiChatCompletionParams';
|
|
4
4
|
export * from './CreateGeminiChatCompletionParams';
|
|
5
5
|
export * from './CreateAnthropicChatCompletionParams';
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
6
|
+
export * from './BasicChatCompletionData';
|
|
7
|
+
export * from './BasicChatCompletion';
|
|
8
|
+
export * from './BasicChatCompletionResponse';
|
|
9
|
+
export * from './CreateBasicChatCompletionParams';
|
|
10
10
|
export * from './StreamingChatCompletionData';
|
|
11
11
|
export * from './StreamingChatCompletion';
|
|
12
12
|
export * from './CreateStreamingChatCompletionParams';
|
|
@@ -14,14 +14,12 @@ export * from './StructuredChatCompletionData';
|
|
|
14
14
|
export * from './StructuredChatCompletion';
|
|
15
15
|
export * from './StructuredChatCompletionResponse';
|
|
16
16
|
export * from './CreateStructuredChatCompletionParams';
|
|
17
|
-
export * from './CombinedChatCompletion';
|
|
18
|
-
export * from './UseChatCompletions';
|
|
19
17
|
export * from './UseStream';
|
|
20
18
|
export * from './CreateStreamResponse';
|
|
21
19
|
export * from './StreamError';
|
|
22
20
|
export * from './UseStreamProps';
|
|
23
|
-
export * from './
|
|
24
|
-
export * from './
|
|
21
|
+
export * from './UseFiles';
|
|
22
|
+
export * from './UseFilesProps';
|
|
25
23
|
export * from './FileUploadStatus';
|
|
26
24
|
export * from './FileUpload';
|
|
27
25
|
export * from './UseWebsites';
|
package/lib/types/index.js
CHANGED
|
@@ -5,11 +5,11 @@ export * from './FencyContext';
|
|
|
5
5
|
export * from './CreateOpenAiChatCompletionParams';
|
|
6
6
|
export * from './CreateGeminiChatCompletionParams';
|
|
7
7
|
export * from './CreateAnthropicChatCompletionParams';
|
|
8
|
-
//
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
8
|
+
// Basic chat completion types
|
|
9
|
+
export * from './BasicChatCompletionData';
|
|
10
|
+
export * from './BasicChatCompletion';
|
|
11
|
+
export * from './BasicChatCompletionResponse';
|
|
12
|
+
export * from './CreateBasicChatCompletionParams';
|
|
13
13
|
// Streaming chat completion types
|
|
14
14
|
export * from './StreamingChatCompletionData';
|
|
15
15
|
export * from './StreamingChatCompletion';
|
|
@@ -19,17 +19,14 @@ export * from './StructuredChatCompletionData';
|
|
|
19
19
|
export * from './StructuredChatCompletion';
|
|
20
20
|
export * from './StructuredChatCompletionResponse';
|
|
21
21
|
export * from './CreateStructuredChatCompletionParams';
|
|
22
|
-
// Combined chat completion types
|
|
23
|
-
export * from './CombinedChatCompletion';
|
|
24
|
-
export * from './UseChatCompletions';
|
|
25
22
|
// Stream types
|
|
26
23
|
export * from './UseStream';
|
|
27
24
|
export * from './CreateStreamResponse';
|
|
28
25
|
export * from './StreamError';
|
|
29
26
|
export * from './UseStreamProps';
|
|
30
27
|
// File upload types
|
|
31
|
-
export * from './
|
|
32
|
-
export * from './
|
|
28
|
+
export * from './UseFiles';
|
|
29
|
+
export * from './UseFilesProps';
|
|
33
30
|
export * from './FileUploadStatus';
|
|
34
31
|
export * from './FileUpload';
|
|
35
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
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ZodTypeAny } from 'zod';
|
|
2
|
-
import { SynchronousChatCompletion } from './SynchronousChatCompletion';
|
|
3
|
-
import { StructuredChatCompletion } from './StructuredChatCompletion';
|
|
4
|
-
import { StreamingChatCompletion } from './StreamingChatCompletion';
|
|
5
|
-
export type CombinedChatCompletion = {
|
|
6
|
-
type: 'synchronous';
|
|
7
|
-
chatCompletion: SynchronousChatCompletion;
|
|
8
|
-
} | {
|
|
9
|
-
type: 'structured';
|
|
10
|
-
chatCompletion: StructuredChatCompletion<ZodTypeAny>;
|
|
11
|
-
} | {
|
|
12
|
-
type: 'streaming';
|
|
13
|
-
chatCompletion: StreamingChatCompletion;
|
|
14
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ApiError } from '@fencyai/js';
|
|
2
|
-
import { SynchronousChatCompletionData } from './SynchronousChatCompletionData';
|
|
3
|
-
export interface SynchronousChatCompletion {
|
|
4
|
-
triggeredAt: string;
|
|
5
|
-
data: SynchronousChatCompletionData | null;
|
|
6
|
-
error: ApiError | null;
|
|
7
|
-
loading: boolean;
|
|
8
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ApiError } from '@fencyai/js';
|
|
2
|
-
import { SynchronousChatCompletionData } from './SynchronousChatCompletionData';
|
|
3
|
-
export type SynchronousChatCompletionResponse = {
|
|
4
|
-
type: 'success';
|
|
5
|
-
data: SynchronousChatCompletionData;
|
|
6
|
-
} | {
|
|
7
|
-
type: 'error';
|
|
8
|
-
error: ApiError;
|
|
9
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ApiError } from '@fencyai/js';
|
|
2
|
-
import { ZodTypeAny } from 'zod';
|
|
3
|
-
import { CombinedChatCompletion } from './CombinedChatCompletion';
|
|
4
|
-
import { SynchronousChatCompletion } from './SynchronousChatCompletion';
|
|
5
|
-
import { StructuredChatCompletion } from './StructuredChatCompletion';
|
|
6
|
-
import { StreamingChatCompletion } from './StreamingChatCompletion';
|
|
7
|
-
import { CreateSynchronousChatCompletionParams } from './CreateSynchronousChatCompletionParams';
|
|
8
|
-
import { SynchronousChatCompletionResponse } from './SynchronousChatCompletionResponse';
|
|
9
|
-
import { CreateStructuredChatCompletionParams } from './CreateStructuredChatCompletionParams';
|
|
10
|
-
import { StructuredChatCompletionResponse } from './StructuredChatCompletionResponse';
|
|
11
|
-
import { CreateStreamingChatCompletionParams } from './CreateStreamingChatCompletionParams';
|
|
12
|
-
export interface UseChatCompletions {
|
|
13
|
-
latest: {
|
|
14
|
-
basic: SynchronousChatCompletion | null;
|
|
15
|
-
structured: StructuredChatCompletion<ZodTypeAny> | null;
|
|
16
|
-
streaming: StreamingChatCompletion | null;
|
|
17
|
-
response: string | null;
|
|
18
|
-
};
|
|
19
|
-
chatCompletions: CombinedChatCompletion[];
|
|
20
|
-
createChatCompletion: (params: CreateSynchronousChatCompletionParams) => Promise<SynchronousChatCompletionResponse>;
|
|
21
|
-
createStructuredChatCompletion: <T extends ZodTypeAny>(params: CreateStructuredChatCompletionParams<T>) => Promise<StructuredChatCompletionResponse<T>>;
|
|
22
|
-
createStreamingChatCompletion: (params: CreateStreamingChatCompletionParams) => Promise<{
|
|
23
|
-
type: 'success';
|
|
24
|
-
streamId: string;
|
|
25
|
-
chatCompletionId: string;
|
|
26
|
-
} | {
|
|
27
|
-
type: 'error';
|
|
28
|
-
error: ApiError;
|
|
29
|
-
}>;
|
|
30
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// hooks/useChatCompletion.ts
|
|
2
|
-
import { useMemo } from 'react';
|
|
3
|
-
import { useFencyContext } from '../provider/useFencyContext';
|
|
4
|
-
import { useStreamingChatCompletions } from './useStreamingChatCompletions';
|
|
5
|
-
import { useStructuredChatCompletions } from './useStructuredChatCompletions';
|
|
6
|
-
import { useSynchronousChatCompletions } from './useSynchronousChatCompletions';
|
|
7
|
-
export function useChatCompletions() {
|
|
8
|
-
const context = useFencyContext();
|
|
9
|
-
const synchronousChatCompletions = useSynchronousChatCompletions(context);
|
|
10
|
-
const streamingChatCompletions = useStreamingChatCompletions(context);
|
|
11
|
-
const structuredChatCompletions = useStructuredChatCompletions(context);
|
|
12
|
-
const combinedChatCompletions = useMemo(() => {
|
|
13
|
-
const completions = [];
|
|
14
|
-
for (const chatCompletion of synchronousChatCompletions.chatCompletions) {
|
|
15
|
-
completions.push({
|
|
16
|
-
type: 'synchronous',
|
|
17
|
-
chatCompletion: chatCompletion,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
for (const chatCompletion of structuredChatCompletions.chatCompletions) {
|
|
21
|
-
completions.push({
|
|
22
|
-
type: 'structured',
|
|
23
|
-
chatCompletion: chatCompletion,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
for (const chatCompletion of streamingChatCompletions.chatCompletions) {
|
|
27
|
-
completions.push({
|
|
28
|
-
type: 'streaming',
|
|
29
|
-
chatCompletion: chatCompletion,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return completions;
|
|
33
|
-
}, [
|
|
34
|
-
synchronousChatCompletions.chatCompletions,
|
|
35
|
-
structuredChatCompletions.chatCompletions,
|
|
36
|
-
streamingChatCompletions.chatCompletions,
|
|
37
|
-
]);
|
|
38
|
-
const latest = useMemo(() => {
|
|
39
|
-
const lastCompletion = combinedChatCompletions[combinedChatCompletions.length - 1];
|
|
40
|
-
return {
|
|
41
|
-
basic: lastCompletion?.type === 'synchronous'
|
|
42
|
-
? lastCompletion.chatCompletion
|
|
43
|
-
: null,
|
|
44
|
-
structured: lastCompletion?.type === 'structured'
|
|
45
|
-
? lastCompletion.chatCompletion
|
|
46
|
-
: null,
|
|
47
|
-
streaming: lastCompletion?.type === 'streaming'
|
|
48
|
-
? lastCompletion.chatCompletion
|
|
49
|
-
: null,
|
|
50
|
-
response: lastCompletion?.type === 'synchronous'
|
|
51
|
-
? lastCompletion.chatCompletion.data?.response ?? null
|
|
52
|
-
: lastCompletion?.type === 'structured'
|
|
53
|
-
? JSON.stringify(lastCompletion.chatCompletion.data?.structuredResponse)
|
|
54
|
-
: lastCompletion?.type === 'streaming'
|
|
55
|
-
? lastCompletion.chatCompletion.response
|
|
56
|
-
: null,
|
|
57
|
-
};
|
|
58
|
-
}, [combinedChatCompletions]);
|
|
59
|
-
return {
|
|
60
|
-
createChatCompletion: synchronousChatCompletions.createSynchronousChatCompletion,
|
|
61
|
-
createStructuredChatCompletion: structuredChatCompletions.createStructuredChatCompletion,
|
|
62
|
-
createStreamingChatCompletion: streamingChatCompletions.createStreamingChatCompletion,
|
|
63
|
-
chatCompletions: combinedChatCompletions,
|
|
64
|
-
latest,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ApiError } from '@fencyai/js';
|
|
2
|
-
import { CreateStreamingChatCompletionParams } from '../types/CreateStreamingChatCompletionParams';
|
|
3
|
-
import { StreamingChatCompletion } from '../types/StreamingChatCompletion';
|
|
4
|
-
import { FencyContext } from '../types/FencyContext';
|
|
5
|
-
export declare const useStreamingChatCompletions: (context: FencyContext) => {
|
|
6
|
-
chatCompletions: StreamingChatCompletion[];
|
|
7
|
-
createStreamingChatCompletion: (params: CreateStreamingChatCompletionParams) => Promise<{
|
|
8
|
-
type: "success";
|
|
9
|
-
streamId: string;
|
|
10
|
-
chatCompletionId: string;
|
|
11
|
-
} | {
|
|
12
|
-
type: "error";
|
|
13
|
-
error: ApiError;
|
|
14
|
-
}>;
|
|
15
|
-
stream: import("@fencyai/js").Stream | null;
|
|
16
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { z, ZodTypeAny } from 'zod';
|
|
2
|
-
import { CreateStructuredChatCompletionParams } from '../types/CreateStructuredChatCompletionParams';
|
|
3
|
-
import { StructuredChatCompletion } from '../types/StructuredChatCompletion';
|
|
4
|
-
import { StructuredChatCompletionResponse } from '../types/StructuredChatCompletionResponse';
|
|
5
|
-
import { FencyContext } from '../types/FencyContext';
|
|
6
|
-
export declare const useStructuredChatCompletions: (context: FencyContext) => {
|
|
7
|
-
chatCompletions: StructuredChatCompletion<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>[];
|
|
8
|
-
createStructuredChatCompletion: <T extends ZodTypeAny>(params: CreateStructuredChatCompletionParams<T>) => Promise<StructuredChatCompletionResponse<T>>;
|
|
9
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CreateSynchronousChatCompletionParams } from '../types/CreateSynchronousChatCompletionParams';
|
|
2
|
-
import { SynchronousChatCompletion } from '../types/SynchronousChatCompletion';
|
|
3
|
-
import { SynchronousChatCompletionResponse } from '../types/SynchronousChatCompletionResponse';
|
|
4
|
-
import { FencyContext } from '../types/FencyContext';
|
|
5
|
-
export declare const useSynchronousChatCompletions: (context: FencyContext) => {
|
|
6
|
-
chatCompletions: SynchronousChatCompletion[];
|
|
7
|
-
createSynchronousChatCompletion: (params: CreateSynchronousChatCompletionParams) => Promise<SynchronousChatCompletionResponse>;
|
|
8
|
-
};
|
package/lib/useStream/index.d.ts
DELETED
package/lib/useWebsites/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { createWebsite } from '@fencyai/js';
|
|
2
|
-
import { useFencyContext } from '../provider/useFencyContext';
|
|
3
|
-
export function useWebsites() {
|
|
4
|
-
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,
|
|
10
|
-
});
|
|
11
|
-
return response;
|
|
12
|
-
};
|
|
13
|
-
return {
|
|
14
|
-
scrapeContent,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/lib/types/{SynchronousChatCompletionResponse.js → CreateStreamingChatCompletionResponse.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|