@fencyai/react 0.1.2
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 +206 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/package.json +69 -0
package/README.md
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# @fencyai/react
|
|
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
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Basic Usage
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
import { ChatCompletionProvider, useChatCompletion } from '@fencyai/react';
|
|
17
|
+
|
|
18
|
+
function App() {
|
|
19
|
+
return (
|
|
20
|
+
<ChatCompletionProvider publishableKey="pk_test_your_publishable_key_here">
|
|
21
|
+
<ChatComponent />
|
|
22
|
+
</ChatCompletionProvider>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function ChatComponent() {
|
|
27
|
+
const { fency, loading, error, sendMessage } = useChatCompletion();
|
|
28
|
+
|
|
29
|
+
if (loading) return <div>Loading Fency...</div>;
|
|
30
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
31
|
+
|
|
32
|
+
const handleSendMessage = async () => {
|
|
33
|
+
try {
|
|
34
|
+
await sendMessage("Hello, how are you?");
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error('Failed to send message:', err);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div>
|
|
42
|
+
<p>Fency loaded: {fency.publishableKey}</p>
|
|
43
|
+
<p>Version: {fency.version}</p>
|
|
44
|
+
<button onClick={handleSendMessage}>Send Message</button>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### With Configuration Options
|
|
51
|
+
|
|
52
|
+
```jsx
|
|
53
|
+
import { ChatCompletionProvider, useChatCompletion } from '@fencyai/react';
|
|
54
|
+
|
|
55
|
+
function App() {
|
|
56
|
+
return (
|
|
57
|
+
<ChatCompletionProvider
|
|
58
|
+
publishableKey="pk_test_your_key"
|
|
59
|
+
options={{
|
|
60
|
+
config: {
|
|
61
|
+
apiVersion: '2024-01-01',
|
|
62
|
+
endpoint: 'https://api.fency.ai'
|
|
63
|
+
}
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
<ChatComponent />
|
|
67
|
+
</ChatCompletionProvider>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Error Handling
|
|
73
|
+
|
|
74
|
+
```jsx
|
|
75
|
+
import { ChatCompletionProvider, useChatCompletion } from '@fencyai/react';
|
|
76
|
+
|
|
77
|
+
function ChatComponent() {
|
|
78
|
+
const { fency, loading, error, sendMessage } = useChatCompletion();
|
|
79
|
+
|
|
80
|
+
if (loading) return <div>Loading...</div>;
|
|
81
|
+
if (error) {
|
|
82
|
+
return (
|
|
83
|
+
<div>
|
|
84
|
+
<h3>Failed to load Fency</h3>
|
|
85
|
+
<p>{error.message}</p>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return <div>Fency is ready!</div>;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## API Reference
|
|
95
|
+
|
|
96
|
+
### `ChatCompletionProvider`
|
|
97
|
+
|
|
98
|
+
React context provider that loads and provides Fency instance for chat completion functionality.
|
|
99
|
+
|
|
100
|
+
**Props:**
|
|
101
|
+
- `publishableKey` (string): Your Fency publishable key (must start with `pk_`)
|
|
102
|
+
- `options` (object, optional): Configuration options
|
|
103
|
+
- `config.apiVersion` (string, optional): API version to use (default: `'2024-01-01'`)
|
|
104
|
+
- `config.endpoint` (string, optional): Custom endpoint URL (default: `'https://api.fency.ai'`)
|
|
105
|
+
|
|
106
|
+
### `useChatCompletion()`
|
|
107
|
+
|
|
108
|
+
React hook that provides access to chat completion functionality and Fency instance.
|
|
109
|
+
|
|
110
|
+
**Returns:** `{ fency, loading, error, sendMessage }`
|
|
111
|
+
- `fency` (FencyInstance | null): The loaded Fency instance
|
|
112
|
+
- `loading` (boolean): Whether Fency is currently loading
|
|
113
|
+
- `error` (Error | null): Any error that occurred during loading
|
|
114
|
+
- `sendMessage` (function): Function to send messages for chat completion
|
|
115
|
+
|
|
116
|
+
## Development
|
|
117
|
+
|
|
118
|
+
### Prerequisites
|
|
119
|
+
|
|
120
|
+
- Node.js 16.0.0 or higher
|
|
121
|
+
- npm
|
|
122
|
+
|
|
123
|
+
### Versioning
|
|
124
|
+
|
|
125
|
+
This project follows [Semantic Versioning](https://semver.org/). See [VERSIONING.md](./VERSIONING.md) for detailed guidelines.
|
|
126
|
+
|
|
127
|
+
**Quick version commands:**
|
|
128
|
+
```bash
|
|
129
|
+
npm run version:patch # Bug fixes (0.1.0 → 0.1.1)
|
|
130
|
+
npm run version:minor # New features (0.1.0 → 0.2.0)
|
|
131
|
+
npm run version:major # Breaking changes (0.1.0 → 1.0.0)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Setup
|
|
135
|
+
|
|
136
|
+
1. Clone the repository:
|
|
137
|
+
```bash
|
|
138
|
+
git clone https://github.com/fencyai/fency-react.git
|
|
139
|
+
cd fency-react
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
2. Install dependencies:
|
|
143
|
+
```bash
|
|
144
|
+
npm install
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
3. Start development mode:
|
|
148
|
+
```bash
|
|
149
|
+
npm run dev
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Build
|
|
153
|
+
|
|
154
|
+
Build the project for production:
|
|
155
|
+
```bash
|
|
156
|
+
npm run build
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
This will:
|
|
160
|
+
- Compile TypeScript to JavaScript
|
|
161
|
+
- Generate type definitions
|
|
162
|
+
- Bundle and minify the code for browser use
|
|
163
|
+
|
|
164
|
+
### Publishing
|
|
165
|
+
|
|
166
|
+
Before publishing, make sure to:
|
|
167
|
+
|
|
168
|
+
1. Update the version: `npm run version:patch|minor|major`
|
|
169
|
+
2. Update the CHANGELOG.md with your changes
|
|
170
|
+
3. Build the project: `npm run build`
|
|
171
|
+
4. Publish to npm: `npm publish`
|
|
172
|
+
|
|
173
|
+
**Quick publish commands:**
|
|
174
|
+
```bash
|
|
175
|
+
npm run publish:patch # Bump patch + publish
|
|
176
|
+
npm run publish:minor # Bump minor + publish
|
|
177
|
+
npm run publish:major # Bump major + publish
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Project Structure
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
fency-react/
|
|
184
|
+
├── src/
|
|
185
|
+
│ └── index.ts # Main entry point with React components and hooks
|
|
186
|
+
├── dist/ # Built files (generated)
|
|
187
|
+
├── package.json # Package configuration
|
|
188
|
+
├── tsconfig.json # TypeScript configuration
|
|
189
|
+
└── README.md # This file
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Features
|
|
193
|
+
|
|
194
|
+
- ✅ React hooks and components for easy integration
|
|
195
|
+
- ✅ TypeScript support with full type definitions
|
|
196
|
+
- ✅ ESM module format for modern browsers
|
|
197
|
+
- ✅ Tree-shakable exports
|
|
198
|
+
- ✅ Minified production builds
|
|
199
|
+
- ✅ Context-based state management
|
|
200
|
+
- ✅ Publishable key validation
|
|
201
|
+
- ✅ Loading and error states
|
|
202
|
+
- ✅ npm package ready
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FencyInstance, FencyOptions } from '@fencyai/js';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Context for Fency instance
|
|
5
|
+
*/
|
|
6
|
+
interface FencyContext {
|
|
7
|
+
fency: FencyInstance | null;
|
|
8
|
+
loading: boolean;
|
|
9
|
+
error: Error | null;
|
|
10
|
+
}
|
|
11
|
+
declare const FencyContext: import("react").Context<FencyContext | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Props for FencyProvider
|
|
14
|
+
*/
|
|
15
|
+
interface FencyProviderProps {
|
|
16
|
+
publishableKey: string;
|
|
17
|
+
options?: Omit<FencyOptions, 'publishableKey'>;
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Provider component that loads and provides Fency instance to child components
|
|
22
|
+
*/
|
|
23
|
+
export declare function FencyProvider({ publishableKey, options, children }: FencyProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
/**
|
|
25
|
+
* Hook to access Fency instance and loading state
|
|
26
|
+
*/
|
|
27
|
+
export declare function useFency(): FencyContext;
|
|
28
|
+
/**
|
|
29
|
+
* Props for ChatCompletionProvider
|
|
30
|
+
*/
|
|
31
|
+
interface ChatCompletionProviderProps {
|
|
32
|
+
publishableKey: string;
|
|
33
|
+
options?: Omit<FencyOptions, 'publishableKey'>;
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Provider component specifically for chat completion functionality
|
|
38
|
+
* This wraps FencyProvider and provides chat-specific context
|
|
39
|
+
*/
|
|
40
|
+
export declare function ChatCompletionProvider({ publishableKey, options, children }: ChatCompletionProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
41
|
+
/**
|
|
42
|
+
* Hook to access chat completion functionality
|
|
43
|
+
*/
|
|
44
|
+
export declare function useChatCompletion(): {
|
|
45
|
+
fency: FencyInstance | null;
|
|
46
|
+
loading: boolean;
|
|
47
|
+
error: Error | null;
|
|
48
|
+
sendMessage: (message: string) => Promise<void>;
|
|
49
|
+
};
|
|
50
|
+
export type { FencyInstance, FencyOptions } from '@fencyai/js';
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAa,MAAM,aAAa,CAAC;AACrE,OAAO,EAAiB,SAAS,EAAmC,MAAM,OAAO,CAAC;AAElF;;GAEG;AACH,UAAU,YAAY;IACpB,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED,QAAA,MAAM,YAAY,mDAAqD,CAAC;AAExE;;GAEG;AACH,UAAU,kBAAkB;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IAC/C,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,cAAc,EAAE,OAAY,EAAE,QAAQ,EAAE,EAAE,kBAAkB,2CA8B3F;AAED;;GAEG;AACH,wBAAgB,QAAQ,iBAMvB;AAED;;GAEG;AACH,UAAU,2BAA2B;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IAC/C,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,cAAc,EAAE,OAAY,EAAE,QAAQ,EAAE,EAAE,2BAA2B,2CAM7G;AAED;;GAEG;AACH,wBAAgB,iBAAiB;;;;2BAQA,MAAM;EAQtC;AAGD,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var Y=Object.create;var R=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var X=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var h=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var ee=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Q(t))!Z.call(e,o)&&o!==r&&R(e,o,{get:()=>t[o],enumerable:!(n=G(t,o))||n.enumerable});return e};var S=(e,t,r)=>(r=e!=null?Y(X(e)):{},ee(t||!e||!e.__esModule?R(r,"default",{value:e,enumerable:!0}):r,e));var M=h(u=>{"use strict";var d=Symbol.for("react.element"),te=Symbol.for("react.portal"),re=Symbol.for("react.fragment"),ne=Symbol.for("react.strict_mode"),oe=Symbol.for("react.profiler"),ue=Symbol.for("react.provider"),ie=Symbol.for("react.context"),se=Symbol.for("react.forward_ref"),ce=Symbol.for("react.suspense"),le=Symbol.for("react.memo"),fe=Symbol.for("react.lazy"),j=Symbol.iterator;function ae(e){return e===null||typeof e!="object"?null:(e=j&&e[j]||e["@@iterator"],typeof e=="function"?e:null)}var T={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},A=Object.assign,q={};function y(e,t,r){this.props=e,this.context=t,this.refs=q,this.updater=r||T}y.prototype.isReactComponent={};y.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};y.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function V(){}V.prototype=y.prototype;function F(e,t,r){this.props=e,this.context=t,this.refs=q,this.updater=r||T}var P=F.prototype=new V;P.constructor=F;A(P,y.prototype);P.isPureReactComponent=!0;var I=Array.isArray,D=Object.prototype.hasOwnProperty,g={current:null},L={key:!0,ref:!0,__self:!0,__source:!0};function U(e,t,r){var n,o={},i=null,s=null;if(t!=null)for(n in t.ref!==void 0&&(s=t.ref),t.key!==void 0&&(i=""+t.key),t)D.call(t,n)&&!L.hasOwnProperty(n)&&(o[n]=t[n]);var l=arguments.length-2;if(l===1)o.children=r;else if(1<l){for(var c=Array(l),a=0;a<l;a++)c[a]=arguments[a+2];o.children=c}if(e&&e.defaultProps)for(n in l=e.defaultProps,l)o[n]===void 0&&(o[n]=l[n]);return{$$typeof:d,type:e,key:i,ref:s,props:o,_owner:g.current}}function pe(e,t){return{$$typeof:d,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function C(e){return typeof e=="object"&&e!==null&&e.$$typeof===d}function ye(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(r){return t[r]})}var N=/\/+/g;function E(e,t){return typeof e=="object"&&e!==null&&e.key!=null?ye(""+e.key):t.toString(36)}function v(e,t,r,n,o){var i=typeof e;(i==="undefined"||i==="boolean")&&(e=null);var s=!1;if(e===null)s=!0;else switch(i){case"string":case"number":s=!0;break;case"object":switch(e.$$typeof){case d:case te:s=!0}}if(s)return s=e,o=o(s),e=n===""?"."+E(s,0):n,I(o)?(r="",e!=null&&(r=e.replace(N,"$&/")+"/"),v(o,t,r,"",function(a){return a})):o!=null&&(C(o)&&(o=pe(o,r+(!o.key||s&&s.key===o.key?"":(""+o.key).replace(N,"$&/")+"/")+e)),t.push(o)),1;if(s=0,n=n===""?".":n+":",I(e))for(var l=0;l<e.length;l++){i=e[l];var c=n+E(i,l);s+=v(i,t,r,c,o)}else if(c=ae(e),typeof c=="function")for(e=c.call(e),l=0;!(i=e.next()).done;)i=i.value,c=n+E(i,l++),s+=v(i,t,r,c,o);else if(i==="object")throw t=String(e),Error("Objects are not valid as a React child (found: "+(t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t)+"). If you meant to render a collection of children, use an array instead.");return s}function m(e,t,r){if(e==null)return e;var n=[],o=0;return v(e,n,"","",function(i){return t.call(r,i,o++)}),n}function de(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(r){(e._status===0||e._status===-1)&&(e._status=1,e._result=r)},function(r){(e._status===0||e._status===-1)&&(e._status=2,e._result=r)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var f={current:null},_={transition:null},he={ReactCurrentDispatcher:f,ReactCurrentBatchConfig:_,ReactCurrentOwner:g};function K(){throw Error("act(...) is not supported in production builds of React.")}u.Children={map:m,forEach:function(e,t,r){m(e,function(){t.apply(this,arguments)},r)},count:function(e){var t=0;return m(e,function(){t++}),t},toArray:function(e){return m(e,function(t){return t})||[]},only:function(e){if(!C(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};u.Component=y;u.Fragment=re;u.Profiler=oe;u.PureComponent=F;u.StrictMode=ne;u.Suspense=ce;u.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=he;u.act=K;u.cloneElement=function(e,t,r){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var n=A({},e.props),o=e.key,i=e.ref,s=e._owner;if(t!=null){if(t.ref!==void 0&&(i=t.ref,s=g.current),t.key!==void 0&&(o=""+t.key),e.type&&e.type.defaultProps)var l=e.type.defaultProps;for(c in t)D.call(t,c)&&!L.hasOwnProperty(c)&&(n[c]=t[c]===void 0&&l!==void 0?l[c]:t[c])}var c=arguments.length-2;if(c===1)n.children=r;else if(1<c){l=Array(c);for(var a=0;a<c;a++)l[a]=arguments[a+2];n.children=l}return{$$typeof:d,type:e.type,key:o,ref:i,props:n,_owner:s}};u.createContext=function(e){return e={$$typeof:ie,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:ue,_context:e},e.Consumer=e};u.createElement=U;u.createFactory=function(e){var t=U.bind(null,e);return t.type=e,t};u.createRef=function(){return{current:null}};u.forwardRef=function(e){return{$$typeof:se,render:e}};u.isValidElement=C;u.lazy=function(e){return{$$typeof:fe,_payload:{_status:-1,_result:e},_init:de}};u.memo=function(e,t){return{$$typeof:le,type:e,compare:t===void 0?null:t}};u.startTransition=function(e){var t=_.transition;_.transition={};try{e()}finally{_.transition=t}};u.unstable_act=K;u.useCallback=function(e,t){return f.current.useCallback(e,t)};u.useContext=function(e){return f.current.useContext(e)};u.useDebugValue=function(){};u.useDeferredValue=function(e){return f.current.useDeferredValue(e)};u.useEffect=function(e,t){return f.current.useEffect(e,t)};u.useId=function(){return f.current.useId()};u.useImperativeHandle=function(e,t,r){return f.current.useImperativeHandle(e,t,r)};u.useInsertionEffect=function(e,t){return f.current.useInsertionEffect(e,t)};u.useLayoutEffect=function(e,t){return f.current.useLayoutEffect(e,t)};u.useMemo=function(e,t){return f.current.useMemo(e,t)};u.useReducer=function(e,t,r){return f.current.useReducer(e,t,r)};u.useRef=function(e){return f.current.useRef(e)};u.useState=function(e){return f.current.useState(e)};u.useSyncExternalStore=function(e,t,r){return f.current.useSyncExternalStore(e,t,r)};u.useTransition=function(){return f.current.useTransition()};u.version="18.3.1"});var k=h((Oe,B)=>{"use strict";B.exports=M()});var J=h(w=>{"use strict";var me=k(),ve=Symbol.for("react.element"),_e=Symbol.for("react.fragment"),we=Object.prototype.hasOwnProperty,be=me.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Se={key:!0,ref:!0,__self:!0,__source:!0};function H(e,t,r){var n,o={},i=null,s=null;r!==void 0&&(i=""+r),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(s=t.ref);for(n in t)we.call(t,n)&&!Se.hasOwnProperty(n)&&(o[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps,t)o[n]===void 0&&(o[n]=t[n]);return{$$typeof:ve,type:e,key:i,ref:s,props:o,_owner:be.current}}w.Fragment=_e;w.jsx=H;w.jsxs=H});var O=h((Re,W)=>{"use strict";W.exports=J()});function $(e,t={}){return new Promise((r,n)=>{if(!e||typeof e!="string"){n(new Error("Fency: A valid publishable key is required."));return}if(!e.startsWith("pk_")){n(new Error('Fency: Invalid publishable key format. Keys should start with "pk_".'));return}let o={publishableKey:e,config:{apiVersion:t.config?.apiVersion||"2024-01-01",endpoint:t.config?.endpoint||"https://api.fency.ai"},version:"0.1.1"};setTimeout(()=>{r(o)},0)})}var p=S(k(),1),x=S(O(),1),z=(0,p.createContext)(void 0);function Ee({publishableKey:e,options:t={},children:r}){let[n,o]=(0,p.useState)(null),[i,s]=(0,p.useState)(!0),[l,c]=(0,p.useState)(null);(0,p.useEffect)(()=>{$(e,t).then(b=>{o(b),s(!1)}).catch(b=>{c(b),s(!1)})},[e,JSON.stringify(t)]);let a={fency:n,loading:i,error:l};return(0,x.jsx)(z.Provider,{value:a,children:r})}function Fe(){let e=(0,p.useContext)(z);if(e===void 0)throw new Error("useFency must be used within a FencyProvider");return e}function Te({publishableKey:e,options:t={},children:r}){return(0,x.jsx)(Ee,{publishableKey:e,options:t,children:r})}function Ae(){let{fency:e,loading:t,error:r}=Fe();return{fency:e,loading:t,error:r,sendMessage:async n=>{if(!e)throw new Error("Fency not loaded");console.log("Sending message:",n)}}}export{Te as ChatCompletionProvider,Ee as FencyProvider,Ae as useChatCompletion,Fe as useFency};
|
|
2
|
+
/*! Bundled license information:
|
|
3
|
+
|
|
4
|
+
react/cjs/react.production.min.js:
|
|
5
|
+
(**
|
|
6
|
+
* @license React
|
|
7
|
+
* react.production.min.js
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
10
|
+
*
|
|
11
|
+
* This source code is licensed under the MIT license found in the
|
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
|
13
|
+
*)
|
|
14
|
+
|
|
15
|
+
react/cjs/react-jsx-runtime.production.min.js:
|
|
16
|
+
(**
|
|
17
|
+
* @license React
|
|
18
|
+
* react-jsx-runtime.production.min.js
|
|
19
|
+
*
|
|
20
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
21
|
+
*
|
|
22
|
+
* This source code is licensed under the MIT license found in the
|
|
23
|
+
* LICENSE file in the root directory of this source tree.
|
|
24
|
+
*)
|
|
25
|
+
*/
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fencyai/react",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "React components for Fency integration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc && esbuild src/index.tsx --bundle --format=esm --outfile=dist/index.js --minify",
|
|
20
|
+
"dev": "tsc --watch",
|
|
21
|
+
"clean": "rm -rf dist",
|
|
22
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
23
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
24
|
+
"version:patch": "npm version patch",
|
|
25
|
+
"version:minor": "npm version minor",
|
|
26
|
+
"version:major": "npm version major",
|
|
27
|
+
"version:prepatch": "npm version prepatch",
|
|
28
|
+
"version:preminor": "npm version preminor",
|
|
29
|
+
"version:premajor": "npm version premajor",
|
|
30
|
+
"version:prerelease": "npm version prerelease",
|
|
31
|
+
"publish:patch": "npm run version:patch && npm publish --access public",
|
|
32
|
+
"publish:minor": "npm run version:minor && npm publish --access public",
|
|
33
|
+
"publish:major": "npm run version:major && npm publish --access public"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"fency",
|
|
37
|
+
"fencyai",
|
|
38
|
+
"react",
|
|
39
|
+
"react-hooks",
|
|
40
|
+
"typescript",
|
|
41
|
+
"esm",
|
|
42
|
+
"publishable-key"
|
|
43
|
+
],
|
|
44
|
+
"author": "",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": "^18.0.0",
|
|
48
|
+
"@fencyai/js": "^0.1.2"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^20.10.0",
|
|
52
|
+
"@types/react": "^18.0.0",
|
|
53
|
+
"esbuild": "^0.19.0",
|
|
54
|
+
"typescript": "^5.3.0",
|
|
55
|
+
"react": "^18.0.0",
|
|
56
|
+
"@fencyai/js": "^0.1.3"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=16.0.0"
|
|
60
|
+
},
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "git+https://github.com/fencyai/fency-react.git"
|
|
64
|
+
},
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://github.com/fencyai/fency-react/issues"
|
|
67
|
+
},
|
|
68
|
+
"homepage": "https://github.com/fencyai/fency-react#readme"
|
|
69
|
+
}
|