@fencyai/react 0.1.41 → 0.1.43
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/index.d.ts +4 -4
- package/lib/index.js +5 -1
- package/lib/provider/FencyContextValue.d.ts +2 -0
- package/lib/provider/FencyProvider.d.ts +1 -8
- package/lib/provider/FencyProvider.js +1 -1
- package/lib/provider/useFencyContext.d.ts +1 -1
- package/lib/provider/useFencyContext.js +1 -1
- package/lib/types/CombinedChatCompletion.d.ts +14 -0
- package/lib/types/CreateAnthropicChatCompletionParams.d.ts +9 -0
- package/lib/types/CreateAnthropicChatCompletionParams.js +1 -0
- package/lib/types/CreateGeminiChatCompletionParams.d.ts +8 -0
- package/lib/types/CreateGeminiChatCompletionParams.js +1 -0
- package/lib/types/CreateOpenAiChatCompletionParams.d.ts +8 -0
- package/lib/types/CreateOpenAiChatCompletionParams.js +1 -0
- package/lib/types/CreateStreamResponse.d.ts +8 -0
- package/lib/types/CreateStreamResponse.js +1 -0
- package/lib/types/CreateStreamingChatCompletionParams.d.ts +8 -0
- package/lib/types/CreateStreamingChatCompletionParams.js +1 -0
- package/lib/types/CreateStructuredChatCompletionParams.d.ts +8 -0
- package/lib/types/CreateStructuredChatCompletionParams.js +1 -0
- package/lib/types/CreateSynchronousChatCompletionParams.d.ts +8 -0
- package/lib/types/CreateSynchronousChatCompletionParams.js +1 -0
- package/lib/types/CreateUploadParams.d.ts +5 -0
- package/lib/types/CreateUploadParams.js +1 -0
- package/lib/types/CreateWebsiteParams.d.ts +3 -0
- package/lib/types/CreateWebsiteParams.js +1 -0
- package/lib/{provider → types}/FencyContext.d.ts +0 -1
- package/lib/types/FencyContext.js +1 -0
- package/lib/types/FencyProviderProps.d.ts +8 -0
- package/lib/types/FencyProviderProps.js +1 -0
- package/lib/types/FileUpload.d.ts +9 -0
- package/lib/types/FileUpload.js +1 -0
- package/lib/types/FileUploadStatus.d.ts +1 -0
- package/lib/types/FileUploadStatus.js +1 -0
- package/lib/types/StreamError.d.ts +5 -0
- package/lib/types/StreamError.js +1 -0
- package/lib/types/StreamingChatCompletion.d.ts +11 -0
- package/lib/types/StreamingChatCompletion.js +1 -0
- package/lib/types/StreamingChatCompletionData.d.ts +5 -0
- package/lib/types/StreamingChatCompletionData.js +1 -0
- package/lib/types/StructuredChatCompletion.d.ts +9 -0
- package/lib/types/StructuredChatCompletion.js +1 -0
- package/lib/types/StructuredChatCompletionData.d.ts +7 -0
- package/lib/types/StructuredChatCompletionData.js +1 -0
- package/lib/types/StructuredChatCompletionResponse.d.ts +10 -0
- package/lib/types/StructuredChatCompletionResponse.js +1 -0
- package/lib/types/SynchronousChatCompletion.d.ts +8 -0
- package/lib/types/SynchronousChatCompletion.js +1 -0
- package/lib/types/SynchronousChatCompletionData.d.ts +5 -0
- package/lib/types/SynchronousChatCompletionData.js +1 -0
- package/lib/types/SynchronousChatCompletionResponse.d.ts +9 -0
- package/lib/types/SynchronousChatCompletionResponse.js +1 -0
- package/lib/types/UseChatCompletions.d.ts +29 -0
- package/lib/types/UseChatCompletions.js +1 -0
- package/lib/types/UseFileUploadProps.d.ts +4 -0
- package/lib/types/UseFileUploadProps.js +1 -0
- package/lib/types/UseFileUploads.d.ts +7 -0
- package/lib/types/UseFileUploads.js +1 -0
- package/lib/types/UseStream.d.ts +6 -0
- package/lib/types/UseStream.js +1 -0
- package/lib/types/UseStreamProps.d.ts +10 -0
- package/lib/types/UseStreamProps.js +1 -0
- package/lib/types/UseWebsites.d.ts +4 -0
- package/lib/types/UseWebsites.js +1 -0
- package/lib/types/index.d.ts +27 -0
- package/lib/types/index.js +36 -0
- package/lib/useChatCompletions/index.d.ts +2 -35
- package/lib/useChatCompletions/index.js +4 -3
- package/lib/useChatCompletions/useStreamingChatCompletions.d.ts +6 -26
- package/lib/useChatCompletions/useStreamingChatCompletions.js +27 -22
- package/lib/useChatCompletions/useStructuredChatCompletions.d.ts +4 -27
- package/lib/useChatCompletions/useSynchronousChatCompletions.d.ts +4 -26
- package/lib/useEventSource.d.ts +11 -10
- package/lib/useEventSource.js +12 -44
- package/lib/useFileUploads/index.d.ts +3 -0
- package/lib/useFileUploads/index.js +56 -0
- package/lib/useStream/index.d.ts +3 -0
- package/lib/useStream/index.js +87 -0
- package/lib/useWebsites/index.d.ts +2 -0
- package/lib/useWebsites/index.js +16 -0
- package/package.json +4 -4
- package/lib/useChatCompletions/types.d.ts +0 -24
- /package/lib/provider/{FencyContext.js → FencyContextValue.js} +0 -0
- /package/lib/{useChatCompletions/types.js → types/CombinedChatCompletion.js} +0 -0
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { useChatCompletions } from './useChatCompletions';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
2
|
+
export { useFileUploads } from './useFileUploads';
|
|
3
|
+
export { useWebsites } from './useWebsites';
|
|
4
|
+
export { FencyProvider } from './provider/FencyProvider';
|
|
5
|
+
export * from './types';
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// Re-export components and hooks
|
|
2
2
|
export { useChatCompletions } from './useChatCompletions';
|
|
3
|
-
|
|
3
|
+
export { useFileUploads } from './useFileUploads';
|
|
4
|
+
export { useWebsites } from './useWebsites';
|
|
5
|
+
// Re-export providers
|
|
4
6
|
export { FencyProvider } from './provider/FencyProvider';
|
|
7
|
+
// Re-export all types from centralized location
|
|
8
|
+
export * from './types';
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface FencyProviderProps {
|
|
3
|
-
fency: Promise<FencyInstance>;
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
options?: {
|
|
6
|
-
fetchClientSecret: () => Promise<string>;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
1
|
+
import { FencyProviderProps } from '../types/FencyProviderProps';
|
|
9
2
|
export declare function FencyProvider({ fency, children }: FencyProviderProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
|
-
import { FencyContextValue } from './
|
|
3
|
+
import { FencyContextValue } from './FencyContextValue';
|
|
4
4
|
export function FencyProvider({ fency, children }) {
|
|
5
5
|
const [fencyInstance, setFencyInstance] = useState(null);
|
|
6
6
|
const [loading, setLoading] = useState(true);
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AnthropicModel } from '@fencyai/js/lib/types/AnthropicModel';
|
|
2
|
+
import { ChatCompletionMessage } from '@fencyai/js/lib/types/ChatCompletionMessage';
|
|
3
|
+
export interface CreateAnthropicChatCompletionParams {
|
|
4
|
+
model: AnthropicModel;
|
|
5
|
+
messages: Array<ChatCompletionMessage>;
|
|
6
|
+
temperature?: number;
|
|
7
|
+
topP?: number;
|
|
8
|
+
topK?: number;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpenAiModel } from '@fencyai/js/lib/types/OpenAiModel';
|
|
2
|
+
import { ChatCompletionMessage } from '@fencyai/js/lib/types/ChatCompletionMessage';
|
|
3
|
+
export interface CreateOpenAiChatCompletionParams {
|
|
4
|
+
model: OpenAiModel;
|
|
5
|
+
messages: Array<ChatCompletionMessage>;
|
|
6
|
+
temperature?: number;
|
|
7
|
+
topP?: number;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CreateOpenAiChatCompletionParams } from './CreateOpenAiChatCompletionParams';
|
|
2
|
+
import { CreateGeminiChatCompletionParams } from './CreateGeminiChatCompletionParams';
|
|
3
|
+
import { CreateAnthropicChatCompletionParams } from './CreateAnthropicChatCompletionParams';
|
|
4
|
+
export interface CreateStreamingChatCompletionParams {
|
|
5
|
+
openai?: CreateOpenAiChatCompletionParams;
|
|
6
|
+
gemini?: CreateGeminiChatCompletionParams;
|
|
7
|
+
anthropic?: CreateAnthropicChatCompletionParams;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ZodTypeAny } from 'zod';
|
|
2
|
+
import { CreateOpenAiChatCompletionParams } from './CreateOpenAiChatCompletionParams';
|
|
3
|
+
import { CreateGeminiChatCompletionParams } from './CreateGeminiChatCompletionParams';
|
|
4
|
+
export interface CreateStructuredChatCompletionParams<T extends ZodTypeAny> {
|
|
5
|
+
openai?: CreateOpenAiChatCompletionParams;
|
|
6
|
+
gemini?: CreateGeminiChatCompletionParams;
|
|
7
|
+
responseFormat: T;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CreateOpenAiChatCompletionParams } from './CreateOpenAiChatCompletionParams';
|
|
2
|
+
import { CreateGeminiChatCompletionParams } from './CreateGeminiChatCompletionParams';
|
|
3
|
+
import { CreateAnthropicChatCompletionParams } from './CreateAnthropicChatCompletionParams';
|
|
4
|
+
export interface CreateSynchronousChatCompletionParams {
|
|
5
|
+
openai?: CreateOpenAiChatCompletionParams;
|
|
6
|
+
gemini?: CreateGeminiChatCompletionParams;
|
|
7
|
+
anthropic?: CreateAnthropicChatCompletionParams;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ApiError, FencyFile, FencyUpload, FileUploadCompleted } from '@fencyai/js';
|
|
2
|
+
import { FileUploadStatus } from './FileUploadStatus';
|
|
3
|
+
export interface FileUpload {
|
|
4
|
+
status: FileUploadStatus;
|
|
5
|
+
upload: FencyUpload;
|
|
6
|
+
file: FencyFile | null;
|
|
7
|
+
error: ApiError | null;
|
|
8
|
+
onUploadComplete?: (fileUpload: FileUploadCompleted) => void;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type FileUploadStatus = 'uploading' | 'upload_failed' | 'upload_complete';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ApiError, NewChatCompletionStreamChunk } from '@fencyai/js';
|
|
2
|
+
import { StreamingChatCompletionData } from './StreamingChatCompletionData';
|
|
3
|
+
export interface StreamingChatCompletion {
|
|
4
|
+
streamId: string;
|
|
5
|
+
data: StreamingChatCompletionData | null;
|
|
6
|
+
error: ApiError | null;
|
|
7
|
+
response: string;
|
|
8
|
+
chunks: NewChatCompletionStreamChunk[];
|
|
9
|
+
loading: boolean;
|
|
10
|
+
doneStreaming: boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ApiError } from '@fencyai/js';
|
|
2
|
+
import { ZodTypeAny } from 'zod';
|
|
3
|
+
import { StructuredChatCompletionData } from './StructuredChatCompletionData';
|
|
4
|
+
export interface StructuredChatCompletion<T extends ZodTypeAny> {
|
|
5
|
+
triggeredAt: string;
|
|
6
|
+
data: StructuredChatCompletionData<T> | null;
|
|
7
|
+
error: ApiError | null;
|
|
8
|
+
loading: boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ApiError } from '@fencyai/js';
|
|
2
|
+
import { ZodTypeAny } from 'zod';
|
|
3
|
+
import { StructuredChatCompletionData } from './StructuredChatCompletionData';
|
|
4
|
+
export type StructuredChatCompletionResponse<T extends ZodTypeAny> = {
|
|
5
|
+
type: 'success';
|
|
6
|
+
data: StructuredChatCompletionData<T>;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'error';
|
|
9
|
+
error: ApiError;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
};
|
|
18
|
+
chatCompletions: CombinedChatCompletion[];
|
|
19
|
+
createChatCompletion: (params: CreateSynchronousChatCompletionParams) => Promise<SynchronousChatCompletionResponse>;
|
|
20
|
+
createStructuredChatCompletion: <T extends ZodTypeAny>(params: CreateStructuredChatCompletionParams<T>) => Promise<StructuredChatCompletionResponse<T>>;
|
|
21
|
+
createStreamingChatCompletion: (params: CreateStreamingChatCompletionParams) => Promise<{
|
|
22
|
+
type: 'success';
|
|
23
|
+
streamId: string;
|
|
24
|
+
chatCompletionId: string;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'error';
|
|
27
|
+
error: ApiError;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CreateUploadResponse } from '@fencyai/js';
|
|
2
|
+
import { CreateUploadParams } from './CreateUploadParams';
|
|
3
|
+
import { FileUpload } from './FileUpload';
|
|
4
|
+
export interface UseFileUploads {
|
|
5
|
+
createFileUpload: (params: CreateUploadParams) => Promise<CreateUploadResponse>;
|
|
6
|
+
fileUploads: FileUpload[];
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChatCompletionStreamCompleted, FileUploadCompleted, NewChatCompletionStreamChunk, StreamNotFound, StreamTimeout } from '@fencyai/js';
|
|
2
|
+
import { StreamError } from './StreamError';
|
|
3
|
+
export interface UseStreamProps {
|
|
4
|
+
onNewChatCompletionStreamChunk?: (streamData: NewChatCompletionStreamChunk) => void;
|
|
5
|
+
onChatCompletionStreamCompleted?: (stream: ChatCompletionStreamCompleted) => void;
|
|
6
|
+
onStreamTimeout?: (error: StreamTimeout) => void;
|
|
7
|
+
onStreamNotFound?: (error: StreamNotFound) => void;
|
|
8
|
+
onFileUploadCompleted?: (error: FileUploadCompleted) => void;
|
|
9
|
+
onStreamError?: (error: StreamError) => void;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from './FencyProviderProps';
|
|
2
|
+
export * from './FencyContext';
|
|
3
|
+
export * from './CreateOpenAiChatCompletionParams';
|
|
4
|
+
export * from './CreateGeminiChatCompletionParams';
|
|
5
|
+
export * from './CreateAnthropicChatCompletionParams';
|
|
6
|
+
export * from './SynchronousChatCompletionData';
|
|
7
|
+
export * from './SynchronousChatCompletion';
|
|
8
|
+
export * from './SynchronousChatCompletionResponse';
|
|
9
|
+
export * from './CreateSynchronousChatCompletionParams';
|
|
10
|
+
export * from './StreamingChatCompletionData';
|
|
11
|
+
export * from './StreamingChatCompletion';
|
|
12
|
+
export * from './CreateStreamingChatCompletionParams';
|
|
13
|
+
export * from './StructuredChatCompletionData';
|
|
14
|
+
export * from './StructuredChatCompletion';
|
|
15
|
+
export * from './StructuredChatCompletionResponse';
|
|
16
|
+
export * from './CreateStructuredChatCompletionParams';
|
|
17
|
+
export * from './CombinedChatCompletion';
|
|
18
|
+
export * from './UseChatCompletions';
|
|
19
|
+
export * from './UseStream';
|
|
20
|
+
export * from './CreateStreamResponse';
|
|
21
|
+
export * from './StreamError';
|
|
22
|
+
export * from './UseStreamProps';
|
|
23
|
+
export * from './UseFileUploads';
|
|
24
|
+
export * from './UseFileUploadProps';
|
|
25
|
+
export * from './FileUploadStatus';
|
|
26
|
+
export * from './FileUpload';
|
|
27
|
+
export * from './UseWebsites';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Provider types
|
|
2
|
+
export * from './FencyProviderProps';
|
|
3
|
+
export * from './FencyContext';
|
|
4
|
+
// Chat completion parameter types
|
|
5
|
+
export * from './CreateOpenAiChatCompletionParams';
|
|
6
|
+
export * from './CreateGeminiChatCompletionParams';
|
|
7
|
+
export * from './CreateAnthropicChatCompletionParams';
|
|
8
|
+
// Synchronous chat completion types
|
|
9
|
+
export * from './SynchronousChatCompletionData';
|
|
10
|
+
export * from './SynchronousChatCompletion';
|
|
11
|
+
export * from './SynchronousChatCompletionResponse';
|
|
12
|
+
export * from './CreateSynchronousChatCompletionParams';
|
|
13
|
+
// Streaming chat completion types
|
|
14
|
+
export * from './StreamingChatCompletionData';
|
|
15
|
+
export * from './StreamingChatCompletion';
|
|
16
|
+
export * from './CreateStreamingChatCompletionParams';
|
|
17
|
+
// Structured chat completion types
|
|
18
|
+
export * from './StructuredChatCompletionData';
|
|
19
|
+
export * from './StructuredChatCompletion';
|
|
20
|
+
export * from './StructuredChatCompletionResponse';
|
|
21
|
+
export * from './CreateStructuredChatCompletionParams';
|
|
22
|
+
// Combined chat completion types
|
|
23
|
+
export * from './CombinedChatCompletion';
|
|
24
|
+
export * from './UseChatCompletions';
|
|
25
|
+
// Stream types
|
|
26
|
+
export * from './UseStream';
|
|
27
|
+
export * from './CreateStreamResponse';
|
|
28
|
+
export * from './StreamError';
|
|
29
|
+
export * from './UseStreamProps';
|
|
30
|
+
// File upload types
|
|
31
|
+
export * from './UseFileUploads';
|
|
32
|
+
export * from './UseFileUploadProps';
|
|
33
|
+
export * from './FileUploadStatus';
|
|
34
|
+
export * from './FileUpload';
|
|
35
|
+
// Website types
|
|
36
|
+
export * from './UseWebsites';
|
|
@@ -1,35 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { CreateStreamingChatCompletionParams, StreamingChatCompletion } from './useStreamingChatCompletions';
|
|
4
|
-
import { CreateStructuredChatCompletionParams, StructuredChatCompletion, StructuredChatCompletionResponse } from './useStructuredChatCompletions';
|
|
5
|
-
import { CreateSynchronousChatCompletionParams, SynchronousChatCompletion, SynchronousChatCompletionResponse } from './useSynchronousChatCompletions';
|
|
6
|
-
type CombinedChatCompletion = {
|
|
7
|
-
type: 'synchronous';
|
|
8
|
-
chatCompletion: SynchronousChatCompletion;
|
|
9
|
-
} | {
|
|
10
|
-
type: 'structured';
|
|
11
|
-
chatCompletion: StructuredChatCompletion<ZodTypeAny>;
|
|
12
|
-
} | {
|
|
13
|
-
type: 'streaming';
|
|
14
|
-
chatCompletion: StreamingChatCompletion;
|
|
15
|
-
};
|
|
16
|
-
interface HookResponse {
|
|
17
|
-
latest: {
|
|
18
|
-
basic: SynchronousChatCompletion | null;
|
|
19
|
-
structured: StructuredChatCompletion<ZodTypeAny> | null;
|
|
20
|
-
streaming: StreamingChatCompletion | null;
|
|
21
|
-
};
|
|
22
|
-
chatCompletions: CombinedChatCompletion[];
|
|
23
|
-
createChatCompletion: (params: CreateSynchronousChatCompletionParams) => Promise<SynchronousChatCompletionResponse>;
|
|
24
|
-
createStructuredChatCompletion: <T extends ZodTypeAny>(params: CreateStructuredChatCompletionParams<T>) => Promise<StructuredChatCompletionResponse<T>>;
|
|
25
|
-
createStreamingChatCompletion: (params: CreateStreamingChatCompletionParams) => Promise<{
|
|
26
|
-
type: 'success';
|
|
27
|
-
chatCompletionStreamId: string;
|
|
28
|
-
chatCompletionId: string;
|
|
29
|
-
} | {
|
|
30
|
-
type: 'error';
|
|
31
|
-
error: ApiError;
|
|
32
|
-
}>;
|
|
33
|
-
}
|
|
34
|
-
export declare function useChatCompletions(): HookResponse;
|
|
35
|
-
export {};
|
|
1
|
+
import { UseChatCompletions } from '../types/UseChatCompletions';
|
|
2
|
+
export declare function useChatCompletions(): UseChatCompletions;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
// hooks/useChatCompletion.ts
|
|
1
2
|
import { useMemo } from 'react';
|
|
2
3
|
import { useFencyContext } from '../provider/useFencyContext';
|
|
3
|
-
import { useStreamingChatCompletions
|
|
4
|
-
import { useStructuredChatCompletions
|
|
5
|
-
import { useSynchronousChatCompletions
|
|
4
|
+
import { useStreamingChatCompletions } from './useStreamingChatCompletions';
|
|
5
|
+
import { useStructuredChatCompletions } from './useStructuredChatCompletions';
|
|
6
|
+
import { useSynchronousChatCompletions } from './useSynchronousChatCompletions';
|
|
6
7
|
export function useChatCompletions() {
|
|
7
8
|
const context = useFencyContext();
|
|
8
9
|
const synchronousChatCompletions = useSynchronousChatCompletions(context);
|
|
@@ -1,36 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { CreateAnthropicChatCompletionParams, CreateGeminiChatCompletionParams, CreateOpenAiChatCompletionParams } from './types';
|
|
6
|
-
export interface StreamingChatCompletionData {
|
|
7
|
-
id: string;
|
|
8
|
-
createdAt: string;
|
|
9
|
-
streamId: string;
|
|
10
|
-
}
|
|
11
|
-
export interface StreamingChatCompletion {
|
|
12
|
-
streamId: string;
|
|
13
|
-
data: StreamingChatCompletionData | null;
|
|
14
|
-
error: ApiError | null;
|
|
15
|
-
response: string;
|
|
16
|
-
chunks: ChatCompletionChunk[];
|
|
17
|
-
loading: boolean;
|
|
18
|
-
doneStreaming: boolean;
|
|
19
|
-
}
|
|
20
|
-
export interface CreateStreamingChatCompletionParams {
|
|
21
|
-
openai?: CreateOpenAiChatCompletionParams;
|
|
22
|
-
gemini?: CreateGeminiChatCompletionParams;
|
|
23
|
-
anthropic?: CreateAnthropicChatCompletionParams;
|
|
24
|
-
}
|
|
1
|
+
import { ApiError } from '@fencyai/js';
|
|
2
|
+
import { CreateStreamingChatCompletionParams } from '../types/CreateStreamingChatCompletionParams';
|
|
3
|
+
import { StreamingChatCompletion } from '../types/StreamingChatCompletion';
|
|
4
|
+
import { FencyContext } from '../types/FencyContext';
|
|
25
5
|
export declare const useStreamingChatCompletions: (context: FencyContext) => {
|
|
26
6
|
chatCompletions: StreamingChatCompletion[];
|
|
27
7
|
createStreamingChatCompletion: (params: CreateStreamingChatCompletionParams) => Promise<{
|
|
28
8
|
type: "success";
|
|
29
|
-
|
|
9
|
+
streamId: string;
|
|
30
10
|
chatCompletionId: string;
|
|
31
11
|
} | {
|
|
32
12
|
type: "error";
|
|
33
13
|
error: ApiError;
|
|
34
14
|
}>;
|
|
35
|
-
stream:
|
|
15
|
+
stream: import("@fencyai/js").Stream | null;
|
|
36
16
|
};
|
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
import { createChatCompletion
|
|
1
|
+
import { createChatCompletion } from '@fencyai/js';
|
|
2
2
|
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { useStream } from '../useStream';
|
|
4
4
|
export const useStreamingChatCompletions = (context) => {
|
|
5
5
|
const [chatCompletions, setChatCompletions] = useState([]);
|
|
6
|
-
const [stream, setStream] = useState(null);
|
|
7
6
|
const [completedStreamIds, setCompletedStreamIds] = useState([]);
|
|
8
|
-
const [
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
throw new Error(`Stream ID not found for URL: ${url}`);
|
|
7
|
+
const [chunks, setChunks] = useState([]);
|
|
8
|
+
const { stream, createStream } = useStream({
|
|
9
|
+
onNewChatCompletionStreamChunk: (streamData) => {
|
|
10
|
+
if (streamData.type === 'NewChatCompletionStreamChunk') {
|
|
11
|
+
setChunks((prev) => [...prev, streamData]);
|
|
14
12
|
}
|
|
15
|
-
|
|
13
|
+
},
|
|
14
|
+
onChatCompletionStreamCompleted: (stream) => {
|
|
15
|
+
setCompletedStreamIds((prev) => [...prev, stream.streamId]);
|
|
16
|
+
},
|
|
17
|
+
onStreamError: (error) => {
|
|
18
|
+
setChatCompletions((prev) => {
|
|
19
|
+
const existing = prev.find((c) => c.streamId === error.streamId);
|
|
20
|
+
if (!existing)
|
|
21
|
+
return prev;
|
|
22
|
+
return [
|
|
23
|
+
...prev.filter((c) => c.streamId !== error.streamId),
|
|
24
|
+
{
|
|
25
|
+
...existing,
|
|
26
|
+
error: error.error,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
});
|
|
16
30
|
},
|
|
17
31
|
});
|
|
18
32
|
useEffect(() => {
|
|
@@ -29,13 +43,6 @@ export const useStreamingChatCompletions = (context) => {
|
|
|
29
43
|
});
|
|
30
44
|
});
|
|
31
45
|
}, [completedStreamIds]);
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (stream) {
|
|
34
|
-
const url = `${context.fency.baseUrl}/v1/pub/chat-completion-streams/${stream.id}?pk=${context.fency.publishableKey}`;
|
|
35
|
-
setUrl(url);
|
|
36
|
-
setUrlToStreamIdMapping((prev) => ({ ...prev, [url]: stream.id }));
|
|
37
|
-
}
|
|
38
|
-
}, [stream, context.fency.publishableKey, setUrl]);
|
|
39
46
|
useEffect(() => {
|
|
40
47
|
const newChatCompletions = [];
|
|
41
48
|
for (const chatCompletion of chatCompletions) {
|
|
@@ -65,12 +72,10 @@ export const useStreamingChatCompletions = (context) => {
|
|
|
65
72
|
}, [chunks]);
|
|
66
73
|
const createStreamingChatCompletion = useCallback(async (params) => {
|
|
67
74
|
// Step 1: Create stream if not exists
|
|
68
|
-
const streamResponse = await
|
|
69
|
-
|
|
70
|
-
baseUrl: context.fency.baseUrl,
|
|
75
|
+
const streamResponse = await createStream({
|
|
76
|
+
type: 'ChatCompletionStream',
|
|
71
77
|
});
|
|
72
78
|
if (streamResponse.type === 'success') {
|
|
73
|
-
setStream(streamResponse.stream);
|
|
74
79
|
setChatCompletions([
|
|
75
80
|
...chatCompletions,
|
|
76
81
|
{
|
|
@@ -131,7 +136,7 @@ export const useStreamingChatCompletions = (context) => {
|
|
|
131
136
|
]);
|
|
132
137
|
return {
|
|
133
138
|
type: 'success',
|
|
134
|
-
|
|
139
|
+
streamId: streamResponse.stream.id,
|
|
135
140
|
chatCompletionId: chatCompletion.completion.id,
|
|
136
141
|
};
|
|
137
142
|
}
|
|
@@ -1,31 +1,8 @@
|
|
|
1
|
-
import { ApiError } from '@fencyai/js/lib/types/ApiError';
|
|
2
1
|
import { z, ZodTypeAny } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
createdAt: string;
|
|
8
|
-
response: object;
|
|
9
|
-
structuredResponse: z.infer<T>;
|
|
10
|
-
}
|
|
11
|
-
export interface StructuredChatCompletion<T extends ZodTypeAny> {
|
|
12
|
-
triggeredAt: string;
|
|
13
|
-
data: StructuredChatCompletionData<T> | null;
|
|
14
|
-
error: ApiError | null;
|
|
15
|
-
loading: boolean;
|
|
16
|
-
}
|
|
17
|
-
export type StructuredChatCompletionResponse<T extends ZodTypeAny> = {
|
|
18
|
-
type: 'success';
|
|
19
|
-
data: StructuredChatCompletionData<T>;
|
|
20
|
-
} | {
|
|
21
|
-
type: 'error';
|
|
22
|
-
error: ApiError;
|
|
23
|
-
};
|
|
24
|
-
export interface CreateStructuredChatCompletionParams<T extends ZodTypeAny> {
|
|
25
|
-
openai?: CreateOpenAiChatCompletionParams;
|
|
26
|
-
gemini?: CreateGeminiChatCompletionParams;
|
|
27
|
-
responseFormat: T;
|
|
28
|
-
}
|
|
2
|
+
import { CreateStructuredChatCompletionParams } from '../types/CreateStructuredChatCompletionParams';
|
|
3
|
+
import { StructuredChatCompletion } from '../types/StructuredChatCompletion';
|
|
4
|
+
import { StructuredChatCompletionResponse } from '../types/StructuredChatCompletionResponse';
|
|
5
|
+
import { FencyContext } from '../types/FencyContext';
|
|
29
6
|
export declare const useStructuredChatCompletions: (context: FencyContext) => {
|
|
30
7
|
chatCompletions: StructuredChatCompletion<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>[];
|
|
31
8
|
createStructuredChatCompletion: <T extends ZodTypeAny>(params: CreateStructuredChatCompletionParams<T>) => Promise<StructuredChatCompletionResponse<T>>;
|
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
id: string;
|
|
6
|
-
createdAt: string;
|
|
7
|
-
response: string;
|
|
8
|
-
}
|
|
9
|
-
export interface SynchronousChatCompletion {
|
|
10
|
-
triggeredAt: string;
|
|
11
|
-
data: SynchronousChatCompletionData | null;
|
|
12
|
-
error: ApiError | null;
|
|
13
|
-
loading: boolean;
|
|
14
|
-
}
|
|
15
|
-
export type SynchronousChatCompletionResponse = {
|
|
16
|
-
type: 'success';
|
|
17
|
-
data: SynchronousChatCompletionData;
|
|
18
|
-
} | {
|
|
19
|
-
type: 'error';
|
|
20
|
-
error: ApiError;
|
|
21
|
-
};
|
|
22
|
-
export interface CreateSynchronousChatCompletionParams {
|
|
23
|
-
openai?: CreateOpenAiChatCompletionParams;
|
|
24
|
-
gemini?: CreateGeminiChatCompletionParams;
|
|
25
|
-
anthropic?: CreateAnthropicChatCompletionParams;
|
|
26
|
-
}
|
|
1
|
+
import { CreateSynchronousChatCompletionParams } from '../types/CreateSynchronousChatCompletionParams';
|
|
2
|
+
import { SynchronousChatCompletion } from '../types/SynchronousChatCompletion';
|
|
3
|
+
import { SynchronousChatCompletionResponse } from '../types/SynchronousChatCompletionResponse';
|
|
4
|
+
import { FencyContext } from '../types/FencyContext';
|
|
27
5
|
export declare const useSynchronousChatCompletions: (context: FencyContext) => {
|
|
28
6
|
chatCompletions: SynchronousChatCompletion[];
|
|
29
7
|
createSynchronousChatCompletion: (params: CreateSynchronousChatCompletionParams) => Promise<SynchronousChatCompletionResponse>;
|
package/lib/useEventSource.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
export type Message = {
|
|
2
|
+
url: string;
|
|
3
|
+
data: string;
|
|
4
|
+
};
|
|
5
|
+
export type EventSource = {
|
|
6
|
+
url: string;
|
|
7
|
+
};
|
|
1
8
|
export declare function useEventSource(props?: {
|
|
2
|
-
|
|
9
|
+
onError: (streamId: string) => void;
|
|
10
|
+
onMessage: (message: Message) => void;
|
|
3
11
|
}): {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
url: string | null | undefined;
|
|
12
|
+
setSource: import("react").Dispatch<import("react").SetStateAction<EventSource | null>>;
|
|
13
|
+
source: EventSource | null;
|
|
7
14
|
};
|
|
8
|
-
export interface ChatCompletionChunk {
|
|
9
|
-
chatCompletionId: string;
|
|
10
|
-
streamId: string;
|
|
11
|
-
timestamp: string;
|
|
12
|
-
content: string;
|
|
13
|
-
}
|
package/lib/useEventSource.js
CHANGED
|
@@ -1,39 +1,28 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
export function useEventSource(props) {
|
|
3
|
-
const [
|
|
4
|
-
const [url, setUrl] = useState();
|
|
3
|
+
const [source, setSource] = useState(null);
|
|
5
4
|
useEffect(() => {
|
|
6
|
-
if (!
|
|
5
|
+
if (!source)
|
|
7
6
|
return;
|
|
8
|
-
const eventSource = new EventSource(url);
|
|
7
|
+
const eventSource = new EventSource(source.url);
|
|
9
8
|
eventSource.onmessage = (message) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const chunk = getChatCompletionChunk(message);
|
|
17
|
-
if (chunk) {
|
|
18
|
-
setChunks((prev) => [...prev, chunk]);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
console.warn('Unknown message:', message);
|
|
22
|
-
}
|
|
9
|
+
props?.onMessage({
|
|
10
|
+
url: source.url,
|
|
11
|
+
data: base64Decode(message.data),
|
|
12
|
+
});
|
|
23
13
|
};
|
|
24
14
|
eventSource.onerror = (error) => {
|
|
25
15
|
console.error('EventSource error:', error);
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
props?.onError(source.url);
|
|
17
|
+
setSource(null);
|
|
28
18
|
};
|
|
29
19
|
return () => {
|
|
30
20
|
eventSource.close();
|
|
31
21
|
};
|
|
32
|
-
}, [
|
|
22
|
+
}, [source]);
|
|
33
23
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
url,
|
|
24
|
+
setSource,
|
|
25
|
+
source,
|
|
37
26
|
};
|
|
38
27
|
}
|
|
39
28
|
function base64Decode(base64) {
|
|
@@ -47,24 +36,3 @@ function base64Decode(base64) {
|
|
|
47
36
|
// Decode UTF-8 bytes -> proper string
|
|
48
37
|
return new TextDecoder('utf-8').decode(bytes);
|
|
49
38
|
}
|
|
50
|
-
const getChatCompletionChunk = (message) => {
|
|
51
|
-
try {
|
|
52
|
-
const json = JSON.parse(base64Decode(message.data));
|
|
53
|
-
if (isChatCompletionChunk(json)) {
|
|
54
|
-
return json;
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
console.error('Error parsing message:', error);
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const isChatCompletionChunk = (data) => {
|
|
64
|
-
return (typeof data === 'object' &&
|
|
65
|
-
data !== null &&
|
|
66
|
-
'chatCompletionId' in data &&
|
|
67
|
-
'streamId' in data &&
|
|
68
|
-
'timestamp' in data &&
|
|
69
|
-
'content' in data);
|
|
70
|
-
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createUpload } from '@fencyai/js';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useFencyContext } from '../provider/useFencyContext';
|
|
4
|
+
import { useStream } from '../useStream';
|
|
5
|
+
export function useFileUploads(props) {
|
|
6
|
+
const [fileUploads, setFileUploads] = useState([]);
|
|
7
|
+
const context = useFencyContext();
|
|
8
|
+
const { createStream } = useStream({
|
|
9
|
+
onFileUploadCompleted: (streamData) => {
|
|
10
|
+
props.onUploadComplete?.(streamData);
|
|
11
|
+
setFileUploads((prev) => prev.map((fileUpload) => fileUpload.upload.id === streamData.uploadId
|
|
12
|
+
? { ...fileUpload, status: 'upload_complete' }
|
|
13
|
+
: fileUpload));
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const createFileUpload = async (params) => {
|
|
17
|
+
const stream = await createStream({
|
|
18
|
+
type: 'FileUploadStream',
|
|
19
|
+
});
|
|
20
|
+
if (stream.type === 'success') {
|
|
21
|
+
const response = await createUpload({
|
|
22
|
+
pk: context.fency.publishableKey,
|
|
23
|
+
request: {
|
|
24
|
+
streamId: stream.stream.id,
|
|
25
|
+
fileName: params.fileName,
|
|
26
|
+
fileType: params.fileType,
|
|
27
|
+
fileSize: params.fileSize,
|
|
28
|
+
},
|
|
29
|
+
baseUrl: context.fency.baseUrl,
|
|
30
|
+
});
|
|
31
|
+
if (response.type === 'success') {
|
|
32
|
+
setFileUploads([
|
|
33
|
+
...fileUploads,
|
|
34
|
+
{
|
|
35
|
+
status: 'uploading',
|
|
36
|
+
upload: response.upload,
|
|
37
|
+
file: null,
|
|
38
|
+
error: null,
|
|
39
|
+
onUploadComplete: props.onUploadComplete,
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return {
|
|
47
|
+
type: 'error',
|
|
48
|
+
error: stream.error,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
createFileUpload,
|
|
54
|
+
fileUploads,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createStream as createStreamApi } from '@fencyai/js';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useFencyContext } from '../provider/useFencyContext';
|
|
4
|
+
import { useEventSource } from '../useEventSource';
|
|
5
|
+
export const useStream = (props) => {
|
|
6
|
+
const context = useFencyContext();
|
|
7
|
+
const [urlToStreamIdMapping, setUrlToStreamIdMapping] = useState({});
|
|
8
|
+
const [stream, setStream] = useState(null);
|
|
9
|
+
const eventSource = useEventSource({
|
|
10
|
+
onError: (url) => {
|
|
11
|
+
console.error('Stream error:', url);
|
|
12
|
+
},
|
|
13
|
+
onMessage: (message) => {
|
|
14
|
+
const streamId = requireStreamId(message.url, urlToStreamIdMapping);
|
|
15
|
+
const streamData = toStreamData(message.data, streamId);
|
|
16
|
+
switch (streamData?.type) {
|
|
17
|
+
case 'NewChatCompletionStreamChunk':
|
|
18
|
+
props?.onNewChatCompletionStreamChunk?.(streamData);
|
|
19
|
+
return true;
|
|
20
|
+
case 'ChatCompletionStreamCompleted':
|
|
21
|
+
props?.onChatCompletionStreamCompleted?.(streamData);
|
|
22
|
+
return true;
|
|
23
|
+
case 'StreamTimeout':
|
|
24
|
+
props?.onStreamTimeout?.(streamData);
|
|
25
|
+
return true;
|
|
26
|
+
case 'StreamNotFound':
|
|
27
|
+
props?.onStreamNotFound?.(streamData);
|
|
28
|
+
return true;
|
|
29
|
+
case 'FileUploadCompleted':
|
|
30
|
+
props?.onFileUploadCompleted?.(streamData);
|
|
31
|
+
return true;
|
|
32
|
+
default:
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const createStream = async (params) => {
|
|
38
|
+
const response = await createStreamApi({
|
|
39
|
+
pk: context.fency.publishableKey,
|
|
40
|
+
baseUrl: context.fency.baseUrl,
|
|
41
|
+
request: params,
|
|
42
|
+
});
|
|
43
|
+
if (response.type === 'success') {
|
|
44
|
+
setStream(response.stream);
|
|
45
|
+
const url = `${context.fency.baseUrl}/v1/pub/streams/${response.stream.id}?pk=${context.fency.publishableKey}`;
|
|
46
|
+
setUrlToStreamIdMapping((prev) => ({
|
|
47
|
+
...prev,
|
|
48
|
+
[url]: response.stream.id,
|
|
49
|
+
}));
|
|
50
|
+
eventSource.setSource({
|
|
51
|
+
url,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return response;
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
createStream: createStream,
|
|
58
|
+
stream,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const requireStreamId = (url, urlToStreamIdMapping) => {
|
|
62
|
+
const streamId = urlToStreamIdMapping[url];
|
|
63
|
+
if (!streamId) {
|
|
64
|
+
throw new Error(`Stream ID not found for URL: ${url}`);
|
|
65
|
+
}
|
|
66
|
+
return streamId;
|
|
67
|
+
};
|
|
68
|
+
const toStreamData = (data, streamId) => {
|
|
69
|
+
try {
|
|
70
|
+
const json = JSON.parse(data);
|
|
71
|
+
if (isStreamData(json)) {
|
|
72
|
+
return json;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error('Error parsing message:', error);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const isStreamData = (data) => {
|
|
82
|
+
return (typeof data === 'object' &&
|
|
83
|
+
data !== null &&
|
|
84
|
+
'type' in data &&
|
|
85
|
+
'streamId' in data &&
|
|
86
|
+
'timestamp' in data);
|
|
87
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fencyai/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.43",
|
|
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.43",
|
|
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.43",
|
|
49
49
|
"react": ">=16.8.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "0c797d40ee1243848951a464a5140d9defbb5785"
|
|
52
52
|
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { AnthropicModel } from '@fencyai/js/lib/types/AnthropicModel';
|
|
2
|
-
import { ChatCompletionMessage } from '@fencyai/js/lib/types/ChatCompletionMessage';
|
|
3
|
-
import { GeminiModel } from '@fencyai/js/lib/types/GeminiModel';
|
|
4
|
-
import { OpenAiModel } from '@fencyai/js/lib/types/OpenAiModel';
|
|
5
|
-
export interface CreateOpenAiChatCompletionParams {
|
|
6
|
-
model: OpenAiModel;
|
|
7
|
-
messages: Array<ChatCompletionMessage>;
|
|
8
|
-
temperature?: number;
|
|
9
|
-
topP?: number;
|
|
10
|
-
}
|
|
11
|
-
export interface CreateGeminiChatCompletionParams {
|
|
12
|
-
model: GeminiModel;
|
|
13
|
-
content: string;
|
|
14
|
-
temperature?: number;
|
|
15
|
-
topP?: number;
|
|
16
|
-
topK?: number;
|
|
17
|
-
}
|
|
18
|
-
export interface CreateAnthropicChatCompletionParams {
|
|
19
|
-
model: AnthropicModel;
|
|
20
|
-
messages: Array<ChatCompletionMessage>;
|
|
21
|
-
temperature?: number;
|
|
22
|
-
topP?: number;
|
|
23
|
-
topK?: number;
|
|
24
|
-
}
|
|
File without changes
|
|
File without changes
|