@fencyai/react 0.1.14 → 0.1.15

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/README.md CHANGED
@@ -1,202 +1,11 @@
1
- # @fencyai/react
1
+ # `@fencyai/react`
2
2
 
3
- React components for Fency integration. Provides React hooks and components for easy Fency integration in React applications.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @fencyai/react
9
- ```
3
+ > TODO: description
10
4
 
11
5
  ## Usage
12
6
 
13
- ### Basic Usage
14
-
15
- ```jsx
16
- import { FencyProvider, useFency } from '@fencyai/react';
17
- import { loadFency } from '@fencyai/js';
18
-
19
- // Make sure to call `loadFency` outside of a component's render to avoid
20
- // recreating the Fency object on every render.
21
- const fencyPromise = loadFency('pk_test_your_publishable_key_here');
22
-
23
- function App() {
24
- return (
25
- <FencyProvider fency={fencyPromise}>
26
- <MyComponent />
27
- </FencyProvider>
28
- );
29
- }
30
-
31
- function MyComponent() {
32
- const { fency, loading, error } = useFency();
33
-
34
- if (loading) return <div>Loading Fency...</div>;
35
- if (error) return <div>Error: {error.message}</div>;
36
-
37
- return (
38
- <div>
39
- <p>Fency loaded: {fency.publishableKey}</p>
40
- <p>Version: {fency.version}</p>
41
- </div>
42
- );
43
- }
44
7
  ```
8
+ const react = require('@fencyai/react');
45
9
 
46
- ### With Configuration Options
47
-
48
- ```jsx
49
- import { ChatCompletionProvider, useChatCompletion } from '@fencyai/react';
50
-
51
- function App() {
52
- return (
53
- <ChatCompletionProvider
54
- publishableKey="pk_test_your_key"
55
- options={{
56
- config: {
57
- apiVersion: '2024-01-01',
58
- endpoint: 'https://api.fency.ai'
59
- }
60
- }}
61
- >
62
- <ChatComponent />
63
- </ChatCompletionProvider>
64
- );
65
- }
66
- ```
67
-
68
- ### Error Handling
69
-
70
- ```jsx
71
- import { ChatCompletionProvider, useChatCompletion } from '@fencyai/react';
72
-
73
- function ChatComponent() {
74
- const { fency, loading, error, sendMessage } = useChatCompletion();
75
-
76
- if (loading) return <div>Loading...</div>;
77
- if (error) {
78
- return (
79
- <div>
80
- <h3>Failed to load Fency</h3>
81
- <p>{error.message}</p>
82
- </div>
83
- );
84
- }
85
-
86
- return <div>Fency is ready!</div>;
87
- }
10
+ // TODO: DEMONSTRATE API
88
11
  ```
89
-
90
- ## API Reference
91
-
92
- ### `ChatCompletionProvider`
93
-
94
- React context provider that loads and provides Fency instance for chat completion functionality.
95
-
96
- **Props:**
97
- - `publishableKey` (string): Your Fency publishable key (must start with `pk_`)
98
- - `options` (object, optional): Configuration options
99
- - `config.apiVersion` (string, optional): API version to use (default: `'2024-01-01'`)
100
- - `config.endpoint` (string, optional): Custom endpoint URL (default: `'https://api.fency.ai'`)
101
-
102
- ### `useChatCompletion()`
103
-
104
- React hook that provides access to chat completion functionality and Fency instance.
105
-
106
- **Returns:** `{ fency, loading, error, sendMessage }`
107
- - `fency` (FencyInstance | null): The loaded Fency instance
108
- - `loading` (boolean): Whether Fency is currently loading
109
- - `error` (Error | null): Any error that occurred during loading
110
- - `sendMessage` (function): Function to send messages for chat completion
111
-
112
- ## Development
113
-
114
- ### Prerequisites
115
-
116
- - Node.js 16.0.0 or higher
117
- - npm
118
-
119
- ### Versioning
120
-
121
- This project follows [Semantic Versioning](https://semver.org/). See [VERSIONING.md](./VERSIONING.md) for detailed guidelines.
122
-
123
- **Quick version commands:**
124
- ```bash
125
- npm run version:patch # Bug fixes (0.1.0 → 0.1.1)
126
- npm run version:minor # New features (0.1.0 → 0.2.0)
127
- npm run version:major # Breaking changes (0.1.0 → 1.0.0)
128
- ```
129
-
130
- ### Setup
131
-
132
- 1. Clone the repository:
133
- ```bash
134
- git clone https://github.com/fencyai/fency-react.git
135
- cd fency-react
136
- ```
137
-
138
- 2. Install dependencies:
139
- ```bash
140
- npm install
141
- ```
142
-
143
- 3. Start development mode:
144
- ```bash
145
- npm run dev
146
- ```
147
-
148
- ### Build
149
-
150
- Build the project for production:
151
- ```bash
152
- npm run build
153
- ```
154
-
155
- This will:
156
- - Compile TypeScript to JavaScript
157
- - Generate type definitions
158
- - Bundle and minify the code for browser use
159
-
160
- ### Publishing
161
-
162
- Before publishing, make sure to:
163
-
164
- 1. Update the version: `npm run version:patch|minor|major`
165
- 2. Update the CHANGELOG.md with your changes
166
- 3. Build the project: `npm run build`
167
- 4. Publish to npm: `npm publish`
168
-
169
- **Quick publish commands:**
170
- ```bash
171
- npm run publish:patch # Bump patch + publish
172
- npm run publish:minor # Bump minor + publish
173
- npm run publish:major # Bump major + publish
174
- ```
175
-
176
- ## Project Structure
177
-
178
- ```
179
- fency-react/
180
- ├── src/
181
- │ └── index.ts # Main entry point with React components and hooks
182
- ├── dist/ # Built files (generated)
183
- ├── package.json # Package configuration
184
- ├── tsconfig.json # TypeScript configuration
185
- └── README.md # This file
186
- ```
187
-
188
- ## Features
189
-
190
- - ✅ React hooks and components for easy integration
191
- - ✅ TypeScript support with full type definitions
192
- - ✅ ESM module format for modern browsers
193
- - ✅ Tree-shakable exports
194
- - ✅ Minified production builds
195
- - ✅ Context-based state management
196
- - ✅ Publishable key validation
197
- - ✅ Loading and error states
198
- - ✅ npm package ready
199
-
200
- ## License
201
-
202
- MIT
@@ -24,4 +24,3 @@ export interface FencyProviderProps {
24
24
  fency: Promise<FencyInstance>;
25
25
  children: React.ReactNode;
26
26
  }
27
- //# sourceMappingURL=FencyProvider.d.ts.map
@@ -1,22 +1,30 @@
1
1
  import { ChatCompletion } from '@fencyai/js';
2
+ import z, { ZodTypeAny } from 'zod';
2
3
  import { ChatCompletionChunk } from './useEventSource';
3
4
  interface Completions {
4
- chatCompletion: ChatCompletion;
5
- streamId: string;
5
+ chatCompletion: ChatCompletion & {
6
+ structuredResponse?: any;
7
+ };
6
8
  chunks: ChatCompletionChunk[];
7
9
  fullMessage: string;
8
10
  }
9
11
  interface HookResponse {
10
12
  chatCompletions: Completions[];
11
- createChatCompletion: (params: {
13
+ createStreamingChatCompletion: (params: {
12
14
  prompt: string;
13
15
  model: 'gpt-4o-mini' | 'gpt-4o';
14
16
  }) => Promise<{
15
- streamId: string;
17
+ chatCompletionStreamId: string;
16
18
  chatCompletionId: string;
17
19
  }>;
20
+ createSynchronousChatCompletion: <T extends ZodTypeAny>(params: {
21
+ prompt: string;
22
+ model: 'gpt-4o-mini' | 'gpt-4o';
23
+ responseFormat?: T;
24
+ }) => Promise<ChatCompletion & {
25
+ structuredResponse?: z.infer<T>;
26
+ }>;
18
27
  latestCompletion: Completions | null;
19
28
  }
20
29
  export declare function useChatCompletion(): HookResponse;
21
30
  export {};
22
- //# sourceMappingURL=useChatCompletion.d.ts.map
@@ -1,6 +1,7 @@
1
1
  // hooks/useChatCompletion.ts
2
2
  import { createChatCompletion, createChatCompletionStream } from '@fencyai/js';
3
3
  import { useCallback, useEffect, useMemo, useState } from 'react';
4
+ import z from 'zod';
4
5
  import { useEventSource } from './useEventSource';
5
6
  import { useFency } from './useFency';
6
7
  export function useChatCompletion() {
@@ -8,13 +9,15 @@ export function useChatCompletion() {
8
9
  const { chunks, setUrl } = useEventSource();
9
10
  const [chatCompletions, setChatCompletions] = useState([]);
10
11
  const [stream, setStream] = useState(null);
11
- const create = useCallback(async (params) => {
12
+ const createStreamingChatCompletion = useCallback(async (params) => {
12
13
  // Step 1: Create stream if not exists
13
- const s = await createChatCompletionStream(fency.fency.publishableKey);
14
+ const s = await createChatCompletionStream({ pk: fency.fency.publishableKey });
14
15
  setStream(s);
15
16
  // Step 2: Send chat completion
16
- const chatCompletion = await createChatCompletion(fency.fency.publishableKey, s.id, {
17
+ const chatCompletion = await createChatCompletion({
18
+ pk: fency.fency.publishableKey,
17
19
  request: {
20
+ chatCompletionStreamId: s.chatCompletionStreamId,
18
21
  openai: {
19
22
  model: params.model,
20
23
  messages: [{ role: 'user', content: params.prompt }],
@@ -23,22 +26,43 @@ export function useChatCompletion() {
23
26
  });
24
27
  setChatCompletions((prev) => [...prev, chatCompletion]);
25
28
  return {
26
- streamId: s.id,
27
- chatCompletionId: s.id,
29
+ chatCompletionStreamId: s.chatCompletionStreamId,
30
+ chatCompletionId: chatCompletion.chatCompletionId,
28
31
  };
29
32
  }, [fency]);
33
+ const createSynchronousChatCompletion = useCallback(async (params) => {
34
+ const jsonSchema = params.responseFormat ? z.toJSONSchema(params.responseFormat) : undefined;
35
+ console.log(jsonSchema);
36
+ const chatCompletion = await createChatCompletion({
37
+ pk: fency.fency.publishableKey,
38
+ request: {
39
+ openai: {
40
+ model: params.model,
41
+ responseJsonSchema: jsonSchema ? JSON.stringify(jsonSchema) : undefined,
42
+ messages: [{ role: 'user', content: params.prompt }],
43
+ },
44
+ },
45
+ });
46
+ setChatCompletions((prev) => [...prev, chatCompletion]);
47
+ if (chatCompletion.responseIsStructured && params.responseFormat && chatCompletion.response) {
48
+ return {
49
+ ...chatCompletion,
50
+ structuredResponse: params.responseFormat.parse(JSON.parse(chatCompletion.response))
51
+ };
52
+ }
53
+ return chatCompletion;
54
+ }, [fency]);
30
55
  const completions = useMemo(() => {
31
56
  const completions = [];
32
57
  for (const chatCompletion of chatCompletions) {
33
58
  const relevantChunks = chunks
34
- .filter((chunk) => chunk.chatCompletionId === chatCompletion.id)
59
+ .filter((chunk) => chunk.chatCompletionId === chatCompletion.chatCompletionId)
35
60
  .sort((a, b) => a.timestamp.localeCompare(b.timestamp));
36
61
  const fullMessage = relevantChunks
37
62
  .map((chunk) => chunk.content)
38
63
  .join('');
39
64
  completions.push({
40
65
  chatCompletion,
41
- streamId: relevantChunks[0].streamId,
42
66
  chunks: relevantChunks,
43
67
  fullMessage,
44
68
  });
@@ -50,11 +74,12 @@ export function useChatCompletion() {
50
74
  }, [completions]);
51
75
  useEffect(() => {
52
76
  if (stream) {
53
- setUrl(`http://localhost:8080/v1/chat_completion_streams/${stream.id}?pk=${fency.fency.publishableKey}`);
77
+ setUrl(`http://localhost:8080/v1/pub/chat-completion-streams/${stream.chatCompletionStreamId}?pk=${fency.fency.publishableKey}`);
54
78
  }
55
79
  }, [stream, fency.fency.publishableKey, setUrl]);
56
80
  return {
57
- createChatCompletion: create,
81
+ createStreamingChatCompletion: createStreamingChatCompletion,
82
+ createSynchronousChatCompletion: createSynchronousChatCompletion,
58
83
  chatCompletions: completions,
59
84
  latestCompletion,
60
85
  };
@@ -9,4 +9,3 @@ export interface ChatCompletionChunk {
9
9
  timestamp: string;
10
10
  content: string;
11
11
  }
12
- //# sourceMappingURL=useEventSource.d.ts.map
@@ -11,6 +11,9 @@ export function useEventSource() {
11
11
  if (chunk) {
12
12
  setChunks((prev) => [...prev, chunk]);
13
13
  }
14
+ else {
15
+ console.warn('Unknown message:', event);
16
+ }
14
17
  };
15
18
  eventSource.onerror = (error) => {
16
19
  console.error('EventSource error:', error);
@@ -3,4 +3,3 @@ import type { FencyContext } from '../FencyProvider';
3
3
  * Hook to access Fency instance and loading state
4
4
  */
5
5
  export declare function useFency(): FencyContext;
6
- //# sourceMappingURL=useFency.d.ts.map
@@ -1,5 +1,4 @@
1
1
  export { FencyProvider } from './FencyProvider';
2
- export { useFency } from './hooks/useFency';
3
2
  export { useChatCompletion } from './hooks/useChatCompletion';
3
+ export { useFency } from './hooks/useFency';
4
4
  export type { FencyContext, FencyOptions, FencyProviderProps } from './FencyProvider';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,5 @@
1
1
  // Re-export components and hooks
2
2
  export { FencyProvider } from './FencyProvider';
3
- export { useFency } from './hooks/useFency';
4
3
  export { useChatCompletion } from './hooks/useChatCompletion';
4
+ export { useFency } from './hooks/useFency';
5
+ console.log("hello world");
package/lib/react.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare function react(): string;
2
+ export declare function createFormattedMessage(message: string): string;
3
+ export declare function validateUserEmail(email: string): {
4
+ isValid: boolean;
5
+ message: string;
6
+ };
7
+ export default react;
package/lib/react.js ADDED
@@ -0,0 +1,17 @@
1
+ import { formatMessage, validateEmail } from '@fencyai/js';
2
+ export function react() {
3
+ return 'Hello from react';
4
+ }
5
+ export function createFormattedMessage(message) {
6
+ return formatMessage(message, 'React');
7
+ }
8
+ export function validateUserEmail(email) {
9
+ const isValid = validateEmail(email);
10
+ return {
11
+ isValid,
12
+ message: isValid
13
+ ? formatMessage('Email is valid!', 'Validation')
14
+ : formatMessage('Invalid email format', 'Validation')
15
+ };
16
+ }
17
+ export default react;
package/package.json CHANGED
@@ -1,69 +1,49 @@
1
1
  {
2
2
  "name": "@fencyai/react",
3
- "version": "0.1.14",
4
- "description": "React components for Fency integration",
3
+ "version": "0.1.15",
4
+ "description": "> TODO: description",
5
+ "author": "staklau <steinaageklaussen@gmail.com>",
6
+ "homepage": "",
7
+ "license": "MIT",
5
8
  "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.mjs",
8
- "types": "./dist/index.d.ts",
9
+ "main": "lib/react.js",
10
+ "types": "lib/react.d.ts",
9
11
  "exports": {
10
12
  ".": {
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.cjs",
13
- "types": "./dist/index.d.ts"
13
+ "import": "./lib/react.js",
14
+ "types": "./lib/react.d.ts"
14
15
  }
15
16
  },
17
+ "directories": {
18
+ "lib": "lib",
19
+ "test": "__tests__"
20
+ },
16
21
  "files": [
17
- "dist"
22
+ "lib"
18
23
  ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
19
27
  "scripts": {
20
- "build": "tsc && node esbuild.config.js",
28
+ "build": "tsc",
29
+ "test": "jest",
30
+ "test:watch": "jest --watch",
21
31
  "dev": "tsc --watch",
22
- "clean": "rm -rf dist",
23
- "prepublishOnly": "npm run clean && npm run build",
24
- "test": "echo \"Error: no test specified\" && exit 1",
25
- "version:patch": "npm version patch",
26
- "version:minor": "npm version minor",
27
- "version:major": "npm version major",
28
- "version:prepatch": "npm version prepatch",
29
- "version:preminor": "npm version preminor",
30
- "version:premajor": "npm version premajor",
31
- "version:prerelease": "npm version prerelease",
32
- "publish:patch": "npm run version:patch && npm publish --access public",
33
- "publish:minor": "npm run version:minor && npm publish --access public",
34
- "publish:major": "npm run version:major && npm publish --access public"
32
+ "prepublishOnly": "npm run build"
35
33
  },
36
- "keywords": [
37
- "fency",
38
- "fencyai",
39
- "react",
40
- "react-hooks",
41
- "typescript",
42
- "esm",
43
- "publishable-key"
44
- ],
45
- "author": "",
46
- "license": "MIT",
47
- "peerDependencies": {
48
- "react": "^18.0.0",
49
- "@fencyai/js": "^0.1.12"
34
+ "dependencies": {
35
+ "@fencyai/js": "^0.1.15",
36
+ "zod": "^4.0.5"
50
37
  },
51
38
  "devDependencies": {
52
- "@types/node": "^20.10.0",
53
- "@types/react": "^18.0.0",
54
- "esbuild": "^0.19.0",
55
- "react": "^18.0.0",
56
- "typescript": "^5.3.0"
57
- },
58
- "engines": {
59
- "node": ">=16.0.0"
60
- },
61
- "repository": {
62
- "type": "git",
63
- "url": "git+https://github.com/fencyai/fency-react.git"
39
+ "@types/jest": "^29.5.11",
40
+ "@types/node": "^20.10.5",
41
+ "@types/react": "^18.2.45",
42
+ "jest": "^29.7.0",
43
+ "ts-jest": "^29.1.1",
44
+ "typescript": "^5.3.3"
64
45
  },
65
- "bugs": {
66
- "url": "https://github.com/fencyai/fency-react/issues"
67
- },
68
- "homepage": "https://github.com/fencyai/fency-react#readme"
46
+ "peerDependencies": {
47
+ "react": ">=16.8.0"
48
+ }
69
49
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"FencyProvider.d.ts","sourceRoot":"","sources":["../src/FencyProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,eAAO,MAAM,iBAAiB,mDAAqD,CAAC;AAEpF;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,kBAAkB,kDAiCpE;AAED,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useChatCompletion.d.ts","sourceRoot":"","sources":["../../src/hooks/useChatCompletion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAA0E,MAAM,aAAa,CAAA;AAEpH,OAAO,EAAE,mBAAmB,EAAkB,MAAM,kBAAkB,CAAA;AAGtE,UAAU,WAAW;IACjB,cAAc,EAAE,cAAc,CAAA;IAC9B,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,mBAAmB,EAAE,CAAA;IAC7B,WAAW,EAAE,MAAM,CAAA;CACtB;AAED,UAAU,YAAY;IAClB,eAAe,EAAE,WAAW,EAAE,CAAA;IAC9B,oBAAoB,EAAE,CAAC,MAAM,EAAE;QAC3B,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,aAAa,GAAG,QAAQ,CAAA;KAClC,KAAK,OAAO,CAAC;QACV,QAAQ,EAAE,MAAM,CAAA;QAChB,gBAAgB,EAAE,MAAM,CAAA;KAC3B,CAAC,CAAA;IACF,gBAAgB,EAAE,WAAW,GAAG,IAAI,CAAA;CACvC;AAED,wBAAgB,iBAAiB,IAAI,YAAY,CA8EhD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEventSource.d.ts","sourceRoot":"","sources":["../../src/hooks/useEventSource.ts"],"names":[],"mappings":"AAQA,wBAAgB,cAAc;;;;EAgC7B;AAgCD,MAAM,WAAW,mBAAmB;IAChC,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;CAClB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useFency.d.ts","sourceRoot":"","sources":["../../src/hooks/useFency.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;GAEG;AACH,wBAAgB,QAAQ,IAAI,YAAY,CAMvC"}
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";var g=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var j=(e,t)=>{for(var o in t)g(e,o,{get:t[o],enumerable:!0})},A=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of O(t))!$.call(e,n)&&n!==o&&g(e,n,{get:()=>t[n],enumerable:!(i=T(t,n))||i.enumerable});return e};var K=e=>A(g({},"__esModule",{value:!0}),e);var q={};j(q,{FencyProvider:()=>v,useChatCompletion:()=>S,useFency:()=>y});module.exports=K(q);var l=require("react"),b=require("react/jsx-runtime"),F=(0,l.createContext)(void 0);function v({fency:e,children:t}){let[o,i]=(0,l.useState)(null),[n,r]=(0,l.useState)(!0),[a,m]=(0,l.useState)(null);if((0,l.useEffect)(()=>{e.then(u=>{i(u),r(!1)}).catch(u=>{m(u),r(!1)})},[e]),!o)return null;let p={fency:o,loading:n,error:a};return(0,b.jsx)(F.Provider,{value:p,children:t})}var I=require("react");function y(){let e=(0,I.useContext)(F);if(e===void 0)throw new Error("useFency must be used within a FencyProvider");return e}var _=e=>typeof e=="object"&&e!==null&&"id"in e,M=e=>typeof e=="object"&&e!==null&&"id"in e;async function x(e,t,o={}){let i=o.apiUrl||"http://localhost:8080/v1/chat_completions",n={...o.request,streamId:t,openai:{model:"gpt-4o-mini",messages:[{role:"user",content:"Hello, how are you?"}],...o.request?.openai}},r=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(n)});if(!r.ok)throw new Error(`Failed to create chat completion: ${r.status} ${r.statusText}`);let a=await r.json();if(!M(a))throw new Error("Invalid chat completion response");return a}async function k(e,t={}){let o=t.apiUrl||"http://localhost:8080/v1/chat_completion_streams",i=t.name||e,n=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify({name:i})});if(!n.ok)throw new Error(`Failed to create stream: ${n.status} ${n.statusText}`);let r=await n.json();if(!_(r))throw new Error("Invalid stream response");return r}var s=require("react");var d=require("react");function P(){let[e,t]=(0,d.useState)([]),[o,i]=(0,d.useState)();return(0,d.useEffect)(()=>{if(!o)return;let n=new EventSource(o);return n.onmessage=r=>{let a=H(r);a&&t(m=>[...m,a])},n.onerror=r=>{console.error("EventSource error:",r)},()=>{n.close()}},[o]),{chunks:e,setUrl:i,url:o}}var N=e=>atob(e),H=e=>{try{let t=JSON.parse(N(e.data));return J(t)?t:null}catch(t){return console.error("Error parsing message:",t),null}},J=e=>typeof e=="object"&&e!==null&&"chatCompletionId"in e&&"streamId"in e&&"timestamp"in e&&"content"in e;function S(){let e=y(),{chunks:t,setUrl:o}=P(),[i,n]=(0,s.useState)([]),[r,a]=(0,s.useState)(null),m=(0,s.useCallback)(async h=>{let c=await k(e.fency.publishableKey);a(c);let f=await x(e.fency.publishableKey,c.id,{request:{openai:{model:h.model,messages:[{role:"user",content:h.prompt}]}}});return n(w=>[...w,f]),{streamId:c.id,chatCompletionId:c.id}},[e]),p=(0,s.useMemo)(()=>{let h=[];for(let c of i){let f=t.filter(C=>C.chatCompletionId===c.id).sort((C,E)=>C.timestamp.localeCompare(E.timestamp)),w=f.map(C=>C.content).join("");h.push({chatCompletion:c,streamId:f[0].streamId,chunks:f,fullMessage:w})}return h},[t,i]),u=(0,s.useMemo)(()=>p[p.length-1],[p]);return(0,s.useEffect)(()=>{r&&o(`http://localhost:8080/v1/chat_completion_streams/${r.id}?pk=${e.fency.publishableKey}`)},[r,e.fency.publishableKey,o]),{createChatCompletion:m,chatCompletions:p,latestCompletion:u}}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG9D,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.mjs DELETED
@@ -1,2 +0,0 @@
1
- import{createContext as k,useEffect as P,useState as C}from"react";import{jsx as E}from"react/jsx-runtime";var d=k(void 0);function S({fency:e,children:o}){let[n,i]=C(null),[r,t]=C(!0),[s,c]=C(null);if(P(()=>{e.then(p=>{i(p),t(!1)}).catch(p=>{c(p),t(!1)})},[e]),!n)return null;let l={fency:n,loading:r,error:s};return E(d.Provider,{value:l,children:o})}import{useContext as T}from"react";function y(){let e=T(d);if(e===void 0)throw new Error("useFency must be used within a FencyProvider");return e}var O=e=>typeof e=="object"&&e!==null&&"id"in e,$=e=>typeof e=="object"&&e!==null&&"id"in e;async function w(e,o,n={}){let i=n.apiUrl||"http://localhost:8080/v1/chat_completions",r={...n.request,streamId:o,openai:{model:"gpt-4o-mini",messages:[{role:"user",content:"Hello, how are you?"}],...n.request?.openai}},t=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(r)});if(!t.ok)throw new Error(`Failed to create chat completion: ${t.status} ${t.statusText}`);let s=await t.json();if(!$(s))throw new Error("Invalid chat completion response");return s}async function g(e,o={}){let n=o.apiUrl||"http://localhost:8080/v1/chat_completion_streams",i=o.name||e,r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify({name:i})});if(!r.ok)throw new Error(`Failed to create stream: ${r.status} ${r.statusText}`);let t=await r.json();if(!O(t))throw new Error("Invalid stream response");return t}import{useCallback as M,useEffect as N,useMemo as b,useState as I}from"react";import{useEffect as j,useState as F}from"react";function v(){let[e,o]=F([]),[n,i]=F();return j(()=>{if(!n)return;let r=new EventSource(n);return r.onmessage=t=>{let s=K(t);s&&o(c=>[...c,s])},r.onerror=t=>{console.error("EventSource error:",t)},()=>{r.close()}},[n]),{chunks:e,setUrl:i,url:n}}var A=e=>atob(e),K=e=>{try{let o=JSON.parse(A(e.data));return _(o)?o:null}catch(o){return console.error("Error parsing message:",o),null}},_=e=>typeof e=="object"&&e!==null&&"chatCompletionId"in e&&"streamId"in e&&"timestamp"in e&&"content"in e;function H(){let e=y(),{chunks:o,setUrl:n}=v(),[i,r]=I([]),[t,s]=I(null),c=M(async m=>{let a=await g(e.fency.publishableKey);s(a);let u=await w(e.fency.publishableKey,a.id,{request:{openai:{model:m.model,messages:[{role:"user",content:m.prompt}]}}});return r(f=>[...f,u]),{streamId:a.id,chatCompletionId:a.id}},[e]),l=b(()=>{let m=[];for(let a of i){let u=o.filter(h=>h.chatCompletionId===a.id).sort((h,x)=>h.timestamp.localeCompare(x.timestamp)),f=u.map(h=>h.content).join("");m.push({chatCompletion:a,streamId:u[0].streamId,chunks:u,fullMessage:f})}return m},[o,i]),p=b(()=>l[l.length-1],[l]);return N(()=>{t&&n(`http://localhost:8080/v1/chat_completion_streams/${t.id}?pk=${e.fency.publishableKey}`)},[t,e.fency.publishableKey,n]),{createChatCompletion:c,chatCompletions:l,latestCompletion:p}}export{S as FencyProvider,H as useChatCompletion,y as useFency};
2
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/FencyProvider.tsx", "../src/hooks/useFency.ts", "../node_modules/@fencyai/js/dist/index.js", "../src/hooks/useChatCompletion.ts", "../src/hooks/useEventSource.ts"],
4
- "sourcesContent": ["import { FencyInstance } from '@fencyai/js';\nimport { createContext, useEffect, useState } from 'react';\n\n// Create the context\nexport const FencyContextValue = createContext<FencyContext | undefined>(undefined);\n\n/**\n * Provider component that provides Fency instance to child components\n * Expects a promise that resolves to a Fency instance\n */\nexport function FencyProvider({ fency, children }: FencyProviderProps) {\n const [fencyInstance, setFencyInstance] = useState<FencyInstance | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n fency\n .then((instance: FencyInstance) => {\n setFencyInstance(instance);\n setLoading(false);\n })\n .catch((err: Error) => {\n setError(err);\n setLoading(false);\n });\n }, [fency]);\n\n // Only render children and provide context when fency is loaded\n if (!fencyInstance) {\n return null;\n }\n\n const value: FencyContext = {\n fency: fencyInstance,\n loading,\n error,\n };\n\n return (\n <FencyContextValue.Provider value={value}>\n {children}\n </FencyContextValue.Provider>\n );\n} \n\nexport interface FencyOptions {\n publishableKey: string;\n endpoint?: string;\n}\n\n/**\n * Context for Fency instance\n */\nexport interface FencyContext {\n fency: FencyInstance;\n loading: boolean;\n error: Error | null;\n}\n\n/**\n * Props for FencyProvider\n */\nexport interface FencyProviderProps {\n fency: Promise<FencyInstance>;\n children: React.ReactNode;\n} ", "import { useContext } from 'react';\nimport { FencyContextValue } from '../FencyProvider';\nimport type { FencyContext } from '../FencyProvider';\n\n/**\n * Hook to access Fency instance and loading state\n */\nexport function useFency(): FencyContext {\n const context = useContext(FencyContextValue);\n if (context === undefined) {\n throw new Error('useFency must be used within a FencyProvider');\n }\n return context;\n} ", "var f=t=>typeof t==\"object\"&&t!==null&&\"id\"in t,C=t=>typeof t==\"object\"&&t!==null&&\"id\"in t;async function a(t,o,e={}){let n=e.apiUrl||\"http://localhost:8080/v1/chat_completions\",i={...e.request,streamId:o,openai:{model:\"gpt-4o-mini\",messages:[{role:\"user\",content:\"Hello, how are you?\"}],...e.request?.openai}},r=await fetch(n,{method:\"POST\",headers:{\"Content-Type\":\"application/json\",Authorization:`Bearer ${t}`},body:JSON.stringify(i)});if(!r.ok)throw new Error(`Failed to create chat completion: ${r.status} ${r.statusText}`);let m=await r.json();if(!C(m))throw new Error(\"Invalid chat completion response\");return m}async function s(t,o={}){let e=o.apiUrl||\"http://localhost:8080/v1/chat_completion_streams\",n=o.name||t,i=await fetch(e,{method:\"POST\",headers:{\"Content-Type\":\"application/json\",Authorization:`Bearer ${t}`},body:JSON.stringify({name:n})});if(!i.ok)throw new Error(`Failed to create stream: ${i.status} ${i.statusText}`);let r=await i.json();if(!f(r))throw new Error(\"Invalid stream response\");return r}function p(){if(typeof window>\"u\")return!1;let t=[\"fetch\",\"Promise\",\"JSON\"];for(let o of t)if(typeof window[o]>\"u\")return!1;if(typeof window.location<\"u\"){let o=window.location.hostname===\"localhost\"||window.location.hostname===\"127.0.0.1\",e=window.location.protocol===\"https:\";!o&&!e&&console.warn(\"Fency: For security, we recommend using HTTPS in production.\")}return!0}function l(){let t={available:!0,missing:[],warnings:[]};if(typeof window>\"u\")return t.available=!1,t.missing.push(\"Browser environment\"),t;let o=[\"fetch\",\"Promise\",\"JSON\"];for(let e of o)typeof window[e]>\"u\"&&(t.available=!1,t.missing.push(`${e} API`));if(typeof window.location<\"u\"){let e=window.location.hostname===\"localhost\"||window.location.hostname===\"127.0.0.1\",n=window.location.protocol===\"https:\";!e&&!n&&t.warnings.push(\"HTTPS is recommended for production use\")}return t}function c(t,o={}){return new Promise((e,n)=>{if(!t||typeof t!=\"string\"){n(new Error(\"Fency: A valid publishable key is required.\"));return}if(!t.startsWith(\"pk_\")){n(new Error('Fency: Invalid publishable key format. Keys should start with \"pk_\".'));return}let i={publishableKey:t,endpoint:o.endpoint||\"https://api.fency.ai\"};setTimeout(()=>{e(i)},0)})}var P={loadFency:c,isFencyAvailable:p,getFencyAvailabilityInfo:l,createChatCompletion:a,createChatCompletionStream:s};export{a as createChatCompletion,s as createChatCompletionStream,P as default,l as getFencyAvailabilityInfo,p as isFencyAvailable,c as loadFency};\n", "// hooks/useChatCompletion.ts\nimport { ChatCompletion, ChatCompletionStream, createChatCompletion, createChatCompletionStream } from '@fencyai/js'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport { ChatCompletionChunk, useEventSource } from './useEventSource'\nimport { useFency } from './useFency'\n\ninterface Completions {\n chatCompletion: ChatCompletion\n streamId: string\n chunks: ChatCompletionChunk[]\n fullMessage: string\n}\n\ninterface HookResponse {\n chatCompletions: Completions[]\n createChatCompletion: (params: {\n prompt: string\n model: 'gpt-4o-mini' | 'gpt-4o'\n }) => Promise<{\n streamId: string\n chatCompletionId: string\n }>\n latestCompletion: Completions | null\n}\n\nexport function useChatCompletion(): HookResponse {\n const fency = useFency()\n const { chunks, setUrl } = useEventSource()\n const [chatCompletions, setChatCompletions] = useState<ChatCompletion[]>([])\n const [stream, setStream] = useState<ChatCompletionStream | null>(null)\n\n const create = useCallback(\n async (params: {\n prompt: string\n model: 'gpt-4o-mini' | 'gpt-4o'\n }): Promise<{\n streamId: string\n chatCompletionId: string\n }> => {\n // Step 1: Create stream if not exists\n const s = await createChatCompletionStream(fency.fency.publishableKey)\n setStream(s)\n\n // Step 2: Send chat completion\n const chatCompletion = await createChatCompletion(fency.fency.publishableKey, s.id, {\n request: {\n openai: {\n model: params.model,\n messages: [{ role: 'user', content: params.prompt }],\n },\n },\n })\n\n setChatCompletions((prev) => [...prev, chatCompletion])\n\n return {\n streamId: s.id,\n chatCompletionId: s.id,\n }\n },\n [fency]\n )\n\n const completions = useMemo(() => {\n const completions: Completions[] = []\n\n for (const chatCompletion of chatCompletions) {\n const relevantChunks = chunks\n .filter((chunk) => chunk.chatCompletionId === chatCompletion.id)\n .sort((a, b) => a.timestamp.localeCompare(b.timestamp))\n\n const fullMessage = relevantChunks\n .map((chunk) => chunk.content)\n .join('')\n\n completions.push({\n chatCompletion,\n streamId: relevantChunks[0].streamId,\n chunks: relevantChunks,\n fullMessage,\n })\n }\n\n return completions\n }, [chunks, chatCompletions])\n\n const latestCompletion = useMemo(() => {\n return completions[completions.length - 1]\n }, [completions])\n\n useEffect(() => {\n if (stream) {\n setUrl(\n `http://localhost:8080/v1/chat_completion_streams/${stream.id}?pk=${fency.fency.publishableKey}`\n )\n }\n }, [stream, fency.fency.publishableKey, setUrl])\n\n return {\n createChatCompletion: create,\n chatCompletions: completions,\n latestCompletion,\n }\n}\n", "import { useEffect, useState } from 'react'\n\ntype Message = {\n data: string\n event?: string\n lastEventId?: string\n}\n\nexport function useEventSource() {\n const [chunks, setChunks] = useState<ChatCompletionChunk[]>([])\n const [url, setUrl] = useState<string | null>()\n\n \n\n useEffect(() => {\n if (!url) return\n\n const eventSource = new EventSource(url)\n\n eventSource.onmessage = (event: MessageEvent) => {\n const chunk = getChatCompletionChunk(event)\n if (chunk) {\n setChunks((prev) => [...prev, chunk])\n }\n }\n\n eventSource.onerror = (error) => {\n console.error('EventSource error:', error)\n }\n\n return () => {\n eventSource.close()\n }\n }, [url])\n\n return {\n chunks,\n setUrl,\n url,\n }\n}\n\nconst base64Decode = (str: string) => {\n return atob(str)\n}\n\nconst getChatCompletionChunk = (\n message: Message\n): ChatCompletionChunk | null => {\n try {\n const json = JSON.parse(base64Decode(message.data))\n if (isChatCompletionChunk(json)) {\n return json\n }\n return null\n } catch (error) {\n console.error('Error parsing message:', error)\n return null\n }\n}\n\nconst isChatCompletionChunk = (data: unknown): boolean => {\n return (\n typeof data === 'object' &&\n data !== null &&\n 'chatCompletionId' in data &&\n 'streamId' in data &&\n 'timestamp' in data &&\n 'content' in data\n )\n}\n\nexport interface ChatCompletionChunk {\n chatCompletionId: string\n streamId: string\n timestamp: string\n content: string\n}\n"],
5
- "mappings": "AACA,OAAS,iBAAAA,EAAe,aAAAC,EAAW,YAAAC,MAAgB,QAsC/C,cAAAC,MAAA,oBAnCG,IAAMC,EAAoBJ,EAAwC,MAAS,EAM3E,SAASK,EAAc,CAAE,MAAAC,EAAO,SAAAC,CAAS,EAAuB,CACrE,GAAM,CAACC,EAAeC,CAAgB,EAAIP,EAA+B,IAAI,EACvE,CAACQ,EAASC,CAAU,EAAIT,EAAS,EAAI,EACrC,CAACU,EAAOC,CAAQ,EAAIX,EAAuB,IAA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,CACb,eAAAH,EACA,SAAUK,EAAe,CAAC,EAAE,SAC5B,OAAQA,EACR,YAAAG,CACJ,CAAC,CACL,CAEA,OAAOL,CACX,EAAG,CAACf,EAAQG,CAAe,CAAC,EAEtBkB,EAAmBL,EAAQ,IACtBD,EAAYA,EAAY,OAAS,CAAC,EAC1C,CAACA,CAAW,CAAC,EAEhB,OAAAO,EAAU,IAAM,CACRhB,GACAL,EACI,oDAAoDK,EAAO,EAAE,OAAOR,EAAM,MAAM,cAAc,EAClG,CAER,EAAG,CAACQ,EAAQR,EAAM,MAAM,eAAgBG,CAAM,CAAC,EAExC,CACH,qBAAsBO,EACtB,gBAAiBO,EACjB,iBAAAM,CACJ,CACJ",
6
- "names": ["createContext", "useEffect", "useState", "jsx", "FencyContextValue", "FencyProvider", "fency", "children", "fencyInstance", "setFencyInstance", "loading", "setLoading", "error", "setError", "instance", "err", "value", "useContext", "useFency", "context", "useContext", "FencyContextValue", "f", "t", "C", "a", "e", "n", "i", "r", "m", "s", "useCallback", "useEffect", "useMemo", "useState", "useEffect", "useState", "useEventSource", "chunks", "setChunks", "url", "setUrl", "eventSource", "event", "chunk", "getChatCompletionChunk", "prev", "error", "base64Decode", "str", "message", "json", "isChatCompletionChunk", "data", "useChatCompletion", "fency", "useFency", "chunks", "setUrl", "useEventSource", "chatCompletions", "setChatCompletions", "useState", "stream", "setStream", "create", "useCallback", "params", "s", "chatCompletion", "a", "prev", "completions", "useMemo", "relevantChunks", "chunk", "b", "fullMessage", "latestCompletion", "useEffect"]
7
- }
File without changes
File without changes