@fencyai/react 0.1.36 → 0.1.37

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.
@@ -6,7 +6,7 @@ interface Completions {
6
6
  structuredResponse?: any;
7
7
  };
8
8
  chunks: ChatCompletionChunk[];
9
- fullMessage: string;
9
+ response: string;
10
10
  }
11
11
  interface HookResponse {
12
12
  chatCompletions: Completions[];
@@ -30,7 +30,7 @@ interface HookResponse {
30
30
  chatCompletionStreamId: string;
31
31
  chatCompletionId: string;
32
32
  }>;
33
- latestCompletion: Completions | null;
33
+ latest: Completions | null;
34
34
  }
35
35
  export declare function useChatCompletions(): HookResponse;
36
36
  export {};
@@ -2,10 +2,10 @@
2
2
  import { createChatCompletion, createChatCompletionStream, } from '@fencyai/js';
3
3
  import { useCallback, useEffect, useMemo, useState } from 'react';
4
4
  import z from 'zod';
5
- import { useChatCompletionContext } from './useChatCompletionContext';
5
+ import { useFencyContext } from '../provider/useFencyContext';
6
6
  import { useEventSource } from './useEventSource';
7
7
  export function useChatCompletions() {
8
- const context = useChatCompletionContext();
8
+ const context = useFencyContext();
9
9
  const { chunks, setUrl } = useEventSource();
10
10
  const [chatCompletions, setChatCompletions] = useState([]);
11
11
  const [stream, setStream] = useState(null);
@@ -120,12 +120,12 @@ export function useChatCompletions() {
120
120
  completions.push({
121
121
  chatCompletion,
122
122
  chunks: relevantChunks,
123
- fullMessage,
123
+ response: fullMessage,
124
124
  });
125
125
  }
126
126
  return completions;
127
127
  }, [chunks, chatCompletions]);
128
- const latestCompletion = useMemo(() => {
128
+ const latest = useMemo(() => {
129
129
  return completions[completions.length - 1];
130
130
  }, [completions]);
131
131
  useEffect(() => {
@@ -138,6 +138,6 @@ export function useChatCompletions() {
138
138
  createStructuredChatCompletion: createStructuredChatCompletion,
139
139
  createStreamingChatCompletion: createStreamingChatCompletion,
140
140
  chatCompletions: completions,
141
- latestCompletion,
141
+ latest,
142
142
  };
143
143
  }
package/lib/index.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- export { ChatCompletionProvider } from './chat-completions/ChatCompletionProvider';
2
- export { useChatCompletionContext } from './chat-completions/useChatCompletionContext';
3
1
  export { useChatCompletions } from './chat-completions/useChatCompletions';
4
- export type { ChatCompletionContext, ChatCompletionProviderProps, } from './chat-completions/ChatCompletionProvider';
2
+ export { FencyProvider, FencyProviderProps } from './provider/FencyProvider';
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Re-export components and hooks
2
- export { ChatCompletionProvider } from './chat-completions/ChatCompletionProvider';
3
- export { useChatCompletionContext } from './chat-completions/useChatCompletionContext';
4
2
  export { useChatCompletions } from './chat-completions/useChatCompletions';
3
+ // Re-export types
4
+ export { FencyProvider } from './provider/FencyProvider';
@@ -0,0 +1,7 @@
1
+ import { FencyInstance } from '@fencyai/js';
2
+ export declare const FencyContextValue: import("react").Context<FencyContext | undefined>;
3
+ export interface FencyContext {
4
+ fency: FencyInstance;
5
+ loading: boolean;
6
+ error: Error | null;
7
+ }
@@ -0,0 +1,3 @@
1
+ import { createContext } from 'react';
2
+ // Create the context
3
+ export const FencyContextValue = createContext(undefined);
@@ -0,0 +1,9 @@
1
+ import { FencyInstance } from '@fencyai/js';
2
+ export interface FencyProviderProps {
3
+ fency: Promise<FencyInstance>;
4
+ children: React.ReactNode;
5
+ options?: {
6
+ fetchClientSecret: () => Promise<string>;
7
+ };
8
+ }
9
+ export declare function FencyProvider({ fency, children }: FencyProviderProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,12 +1,7 @@
1
1
  import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useEffect, useState } from 'react';
3
- // Create the context
4
- export const ChatCompletionContextValue = createContext(undefined);
5
- /**
6
- * Provider component that provides Fency instance to child components
7
- * Expects a promise that resolves to a Fency instance
8
- */
9
- export function ChatCompletionProvider({ fency, children, }) {
2
+ import { useEffect, useState } from 'react';
3
+ import { FencyContextValue } from './FencyContext';
4
+ export function FencyProvider({ fency, children }) {
10
5
  const [fencyInstance, setFencyInstance] = useState(null);
11
6
  const [loading, setLoading] = useState(true);
12
7
  const [error, setError] = useState(null);
@@ -33,5 +28,5 @@ export function ChatCompletionProvider({ fency, children, }) {
33
28
  loading,
34
29
  error,
35
30
  };
36
- return (_jsx(ChatCompletionContextValue.Provider, { value: value, children: children }));
31
+ return (_jsx(FencyContextValue.Provider, { value: value, children: children }));
37
32
  }
@@ -0,0 +1,5 @@
1
+ import type { FencyContext } from './FencyContext';
2
+ /**
3
+ * Hook to access Fency instance and loading state
4
+ */
5
+ export declare function useFencyContext(): FencyContext;
@@ -0,0 +1,12 @@
1
+ import { useContext } from 'react';
2
+ import { FencyContextValue } from './FencyContext';
3
+ /**
4
+ * Hook to access Fency instance and loading state
5
+ */
6
+ export function useFencyContext() {
7
+ const context = useContext(FencyContextValue);
8
+ if (context === undefined) {
9
+ throw new Error('useFencyContext must be used within a FencyProvider');
10
+ }
11
+ return context;
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fencyai/react",
3
- "version": "0.1.36",
3
+ "version": "0.1.37",
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.36",
39
+ "@fencyai/js": "^0.1.37",
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.36",
48
+ "@fencyai/js": "^0.1.37",
49
49
  "react": ">=16.8.0"
50
50
  },
51
- "gitHead": "6b27d7a3144538c097e8ef6ee20ace01d29ea367"
51
+ "gitHead": "dec184b1288042cf37fa26c8fbf2f648f7ce533e"
52
52
  }
@@ -1,22 +0,0 @@
1
- import { FencyInstance } from '@fencyai/js';
2
- export declare const ChatCompletionContextValue: import("react").Context<ChatCompletionContext | undefined>;
3
- /**
4
- * Provider component that provides Fency instance to child components
5
- * Expects a promise that resolves to a Fency instance
6
- */
7
- export declare function ChatCompletionProvider({ fency, children, }: ChatCompletionProviderProps): import("react/jsx-runtime").JSX.Element | null;
8
- export interface ChatCompletionContext {
9
- fency: FencyInstance;
10
- loading: boolean;
11
- error: Error | null;
12
- }
13
- /**
14
- * Props for ChatCompletionProvider
15
- */
16
- export interface ChatCompletionProviderProps {
17
- fency: Promise<FencyInstance>;
18
- children: React.ReactNode;
19
- options?: {
20
- fetchClientSecret: () => Promise<string>;
21
- };
22
- }
@@ -1,5 +0,0 @@
1
- import type { ChatCompletionContext } from './ChatCompletionProvider';
2
- /**
3
- * Hook to access Fency instance and loading state
4
- */
5
- export declare function useChatCompletionContext(): ChatCompletionContext;
@@ -1,12 +0,0 @@
1
- import { useContext } from 'react';
2
- import { ChatCompletionContextValue } from './ChatCompletionProvider';
3
- /**
4
- * Hook to access Fency instance and loading state
5
- */
6
- export function useChatCompletionContext() {
7
- const context = useContext(ChatCompletionContextValue);
8
- if (context === undefined) {
9
- throw new Error('useChatCompletionContext must be used within a ChatCompletionProvider');
10
- }
11
- return context;
12
- }