@fencyai/js 0.1.2 → 0.1.4

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,6 +1,6 @@
1
1
  # @fencyai/js
2
2
 
3
- A TypeScript ESM module designed for browser use, published as an npm package.
3
+ Core Fency library for browser integration - equivalent to `@stripe/stripe-js`. Load Fency instances with your publishable key.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,27 +10,47 @@ npm install @fencyai/js
10
10
 
11
11
  ## Usage
12
12
 
13
- ### ES Modules (Recommended)
13
+ ### Basic Usage
14
14
 
15
15
  ```javascript
16
- import { greet, FencyUtils } from '@fencyai/js';
16
+ import { loadFency } from '@fencyai/js';
17
17
 
18
- // Use the utility function
19
- console.log(greet('World')); // "Hello from fency-js: World"
18
+ // Make sure to call `loadFency` outside of a component's render to avoid
19
+ // recreating the Fency object on every render.
20
+ const fencyPromise = loadFency('pk_test_your_publishable_key_here');
20
21
 
21
- // Use the utility class
22
- const utils = new FencyUtils('2.0.0');
23
- console.log(utils.getVersion()); // "2.0.0"
24
- console.log(utils.formatDate(new Date())); // Current date formatted
22
+ // Use the promise
23
+ fencyPromise.then((fency) => {
24
+ console.log('Fency loaded:', fency.publishableKey);
25
+ console.log('Version:', fency.version);
26
+ });
25
27
  ```
26
28
 
27
- ### Default Import
29
+ ### With Configuration Options
28
30
 
29
31
  ```javascript
30
- import fency from '@fencyai/js';
32
+ import { loadFency } from '@fencyai/js';
33
+
34
+ const fencyPromise = loadFency('pk_test_your_key', {
35
+ config: {
36
+ apiVersion: '2024-01-01',
37
+ endpoint: 'https://api.fency.ai'
38
+ }
39
+ });
40
+ ```
41
+
42
+ ### Error Handling
31
43
 
32
- console.log(fency.greet('Browser')); // "Hello from fency-js: Browser"
33
- const utils = new fency.FencyUtils();
44
+ ```javascript
45
+ import { loadFency } from '@fencyai/js';
46
+
47
+ const fencyPromise = loadFency('invalid_key')
48
+ .then((fency) => {
49
+ // Success
50
+ })
51
+ .catch((error) => {
52
+ console.error('Failed to load Fency:', error.message);
53
+ });
34
54
  ```
35
55
 
36
56
  ### Browser Usage
@@ -43,16 +63,39 @@ const utils = new fency.FencyUtils();
43
63
  </head>
44
64
  <body>
45
65
  <script type="module">
46
- import { greet, FencyUtils } from 'https://unpkg.com/@fencyai/js@latest/dist/index.js';
66
+ import { loadFency } from 'https://unpkg.com/@fencyai/js@latest/dist/index.js';
47
67
 
48
- console.log(greet('Browser User'));
49
- const utils = new FencyUtils();
50
- document.body.innerHTML = `<p>Version: ${utils.getVersion()}</p>`;
68
+ const fencyPromise = loadFency('pk_test_your_key');
69
+ fencyPromise.then(fency => {
70
+ document.body.innerHTML = `<p>Fency loaded: ${fency.version}</p>`;
71
+ });
51
72
  </script>
52
73
  </body>
53
74
  </html>
54
75
  ```
55
76
 
77
+ ## API Reference
78
+
79
+ ### `loadFency(publishableKey, options?)`
80
+
81
+ Loads the Fency library with the given publishable key.
82
+
83
+ **Parameters:**
84
+ - `publishableKey` (string): Your Fency publishable key (must start with `pk_`)
85
+ - `options` (object, optional): Configuration options
86
+ - `config.apiVersion` (string, optional): API version to use (default: `'2024-01-01'`)
87
+ - `config.endpoint` (string, optional): Custom endpoint URL (default: `'https://api.fency.ai'`)
88
+
89
+ **Returns:** Promise<FencyInstance>
90
+
91
+ **Throws:** Error if publishable key is invalid
92
+
93
+ ### `isFencyAvailable()`
94
+
95
+ Check if Fency is available in the current environment.
96
+
97
+ **Returns:** boolean
98
+
56
99
  ## Development
57
100
 
58
101
  ### Prerequisites
@@ -122,7 +165,7 @@ npm run publish:major # Bump major + publish
122
165
  ```
123
166
  fency-js/
124
167
  ├── src/
125
- │ └── index.ts # Main entry point
168
+ │ └── index.ts # Main entry point with loadFency
126
169
  ├── dist/ # Built files (generated)
127
170
  ├── package.json # Package configuration
128
171
  ├── tsconfig.json # TypeScript configuration
@@ -136,6 +179,8 @@ fency-js/
136
179
  - ✅ Tree-shakable exports
137
180
  - ✅ Minified production builds
138
181
  - ✅ Browser-compatible
182
+ - ✅ Publishable key validation
183
+ - ✅ Promise-based loading
139
184
  - ✅ npm package ready
140
185
 
141
186
  ## License
@@ -0,0 +1,12 @@
1
+ import { FencyAvailabilityInfo } from './types.js';
2
+ /**
3
+ * Check if Fency is available in the current environment
4
+ * This checks for browser compatibility and required APIs
5
+ */
6
+ export declare function isFencyAvailable(): boolean;
7
+ /**
8
+ * Get detailed information about Fency availability
9
+ * Returns an object with availability status and missing requirements
10
+ */
11
+ export declare function getFencyAvailabilityInfo(): FencyAvailabilityInfo;
12
+ //# sourceMappingURL=availability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"availability.d.ts","sourceRoot":"","sources":["../src/availability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAgC1C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,qBAAqB,CAwChE"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Check if Fency is available in the current environment
3
+ * This checks for browser compatibility and required APIs
4
+ */
5
+ export function isFencyAvailable() {
6
+ // Check if we're in a browser environment
7
+ if (typeof window === 'undefined') {
8
+ return false;
9
+ }
10
+ // Check for required browser APIs
11
+ const requiredAPIs = [
12
+ 'fetch',
13
+ 'Promise',
14
+ 'JSON'
15
+ ];
16
+ for (const api of requiredAPIs) {
17
+ if (typeof window[api] === 'undefined') {
18
+ return false;
19
+ }
20
+ }
21
+ // Check for HTTPS in production (recommended for security)
22
+ if (typeof window.location !== 'undefined') {
23
+ const isLocalhost = window.location.hostname === 'localhost' ||
24
+ window.location.hostname === '127.0.0.1';
25
+ const isSecure = window.location.protocol === 'https:';
26
+ // Warn in console if not secure (but don't block)
27
+ if (!isLocalhost && !isSecure) {
28
+ console.warn('Fency: For security, we recommend using HTTPS in production.');
29
+ }
30
+ }
31
+ return true;
32
+ }
33
+ /**
34
+ * Get detailed information about Fency availability
35
+ * Returns an object with availability status and missing requirements
36
+ */
37
+ export function getFencyAvailabilityInfo() {
38
+ const result = {
39
+ available: true,
40
+ missing: [],
41
+ warnings: []
42
+ };
43
+ // Check if we're in a browser environment
44
+ if (typeof window === 'undefined') {
45
+ result.available = false;
46
+ result.missing.push('Browser environment');
47
+ return result;
48
+ }
49
+ // Check for required browser APIs
50
+ const requiredAPIs = [
51
+ 'fetch',
52
+ 'Promise',
53
+ 'JSON'
54
+ ];
55
+ for (const api of requiredAPIs) {
56
+ if (typeof window[api] === 'undefined') {
57
+ result.available = false;
58
+ result.missing.push(`${api} API`);
59
+ }
60
+ }
61
+ // Check for HTTPS in production
62
+ if (typeof window.location !== 'undefined') {
63
+ const isLocalhost = window.location.hostname === 'localhost' ||
64
+ window.location.hostname === '127.0.0.1';
65
+ const isSecure = window.location.protocol === 'https:';
66
+ if (!isLocalhost && !isSecure) {
67
+ result.warnings.push('HTTPS is recommended for production use');
68
+ }
69
+ }
70
+ return result;
71
+ }
@@ -0,0 +1,16 @@
1
+ import { ChatCompletionRequest, ChatCompletionResponse } from './types.js';
2
+ export interface CreateChatCompletionOptions {
3
+ apiUrl?: string;
4
+ request?: Partial<ChatCompletionRequest>;
5
+ }
6
+ /**
7
+ * Creates a chat completion by making a POST request to the Fency API.
8
+ *
9
+ * @param pk - The publishable key (used as Bearer token)
10
+ * @param streamId - The stream ID to associate with the chat completion
11
+ * @param options - Optional configuration (apiUrl, request overrides)
12
+ * @returns A promise that resolves to a ChatCompletionResponse
13
+ * @throws Error if the request fails or the response is invalid
14
+ */
15
+ export declare function createChatCompletion(pk: string, streamId: string, options?: CreateChatCompletionOptions): Promise<ChatCompletionResponse>;
16
+ //# sourceMappingURL=createChatCompletion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createChatCompletion.d.ts","sourceRoot":"","sources":["../src/createChatCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAA4B,MAAM,YAAY,CAAC;AAErG,MAAM,WAAW,2BAA2B;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC1C;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,sBAAsB,CAAC,CAmCjC"}
@@ -0,0 +1,43 @@
1
+ import { isChatCompletionResponse } from './types.js';
2
+ /**
3
+ * Creates a chat completion by making a POST request to the Fency API.
4
+ *
5
+ * @param pk - The publishable key (used as Bearer token)
6
+ * @param streamId - The stream ID to associate with the chat completion
7
+ * @param options - Optional configuration (apiUrl, request overrides)
8
+ * @returns A promise that resolves to a ChatCompletionResponse
9
+ * @throws Error if the request fails or the response is invalid
10
+ */
11
+ export async function createChatCompletion(pk, streamId, options = {}) {
12
+ const apiUrl = options.apiUrl || 'http://localhost:8080/v1/chat-completions';
13
+ const requestBody = {
14
+ ...options.request,
15
+ streamId, // always override with provided streamId
16
+ openai: {
17
+ model: 'gpt-4o-mini',
18
+ messages: [
19
+ {
20
+ role: 'user',
21
+ content: 'Hello, how are you?',
22
+ },
23
+ ],
24
+ ...options.request?.openai,
25
+ },
26
+ };
27
+ const response = await fetch(apiUrl, {
28
+ method: 'POST',
29
+ headers: {
30
+ 'Content-Type': 'application/json',
31
+ Authorization: `Bearer ${pk}`,
32
+ },
33
+ body: JSON.stringify(requestBody),
34
+ });
35
+ if (!response.ok) {
36
+ throw new Error(`Failed to create chat completion: ${response.status} ${response.statusText}`);
37
+ }
38
+ const completion = await response.json();
39
+ if (!isChatCompletionResponse(completion)) {
40
+ throw new Error('Invalid chat completion response');
41
+ }
42
+ return completion;
43
+ }
@@ -0,0 +1,15 @@
1
+ import { Stream } from './types.js';
2
+ export interface CreateStreamOptions {
3
+ apiUrl?: string;
4
+ name?: string;
5
+ }
6
+ /**
7
+ * Creates a new stream by making a POST request to the Fency API.
8
+ *
9
+ * @param pk - The publishable key (used as Bearer token and default name)
10
+ * @param options - Optional configuration (apiUrl, name)
11
+ * @returns A promise that resolves to a Stream
12
+ * @throws Error if the request fails or the response is invalid
13
+ */
14
+ export declare function createStream(pk: string, options?: CreateStreamOptions): Promise<Stream>;
15
+ //# sourceMappingURL=createStream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createStream.d.ts","sourceRoot":"","sources":["../src/createStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,MAAM,CAAC,CAsBjB"}
@@ -0,0 +1,29 @@
1
+ import { isStream } from './types.js';
2
+ /**
3
+ * Creates a new stream by making a POST request to the Fency API.
4
+ *
5
+ * @param pk - The publishable key (used as Bearer token and default name)
6
+ * @param options - Optional configuration (apiUrl, name)
7
+ * @returns A promise that resolves to a Stream
8
+ * @throws Error if the request fails or the response is invalid
9
+ */
10
+ export async function createStream(pk, options = {}) {
11
+ const apiUrl = options.apiUrl || 'http://localhost:8080/v1/streams';
12
+ const name = options.name || pk;
13
+ const response = await fetch(apiUrl, {
14
+ method: 'POST',
15
+ headers: {
16
+ 'Content-Type': 'application/json',
17
+ Authorization: `Bearer ${pk}`,
18
+ },
19
+ body: JSON.stringify({ name }),
20
+ });
21
+ if (!response.ok) {
22
+ throw new Error(`Failed to create stream: ${response.status} ${response.statusText}`);
23
+ }
24
+ const stream = await response.json();
25
+ if (!isStream(stream)) {
26
+ throw new Error('Invalid stream response');
27
+ }
28
+ return stream;
29
+ }
package/dist/index.d.ts CHANGED
@@ -1,27 +1,20 @@
1
- /**
2
- * A sample utility function that demonstrates the module structure
3
- * @param message - The message to log
4
- * @returns A formatted greeting
5
- */
6
- export declare function greet(message: string): string;
7
- /**
8
- * A sample class that can be used in browser environments
9
- */
10
- export declare class FencyUtils {
11
- private version;
12
- constructor(version?: string);
13
- /**
14
- * Get the current version
15
- */
16
- getVersion(): string;
17
- /**
18
- * Format a date for display
19
- */
20
- formatDate(date: Date): string;
21
- }
1
+ import { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
2
+ import { loadFency } from './loadFency.js';
3
+ import { createStream } from './createStream.js';
4
+ import { createChatCompletion } from './createChatCompletion.js';
5
+ export type { FencyAvailabilityInfo, FencyInstance, FencyOptions } from './types.js';
6
+ export { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
7
+ export { loadFency } from './loadFency.js';
8
+ export { createStream } from './createStream.js';
9
+ export type { CreateStreamOptions } from './createStream.js';
10
+ export { createChatCompletion } from './createChatCompletion.js';
11
+ export type { CreateChatCompletionOptions } from './createChatCompletion.js';
22
12
  declare const _default: {
23
- greet: typeof greet;
24
- FencyUtils: typeof FencyUtils;
13
+ loadFency: typeof loadFency;
14
+ isFencyAvailable: typeof isFencyAvailable;
15
+ getFencyAvailabilityInfo: typeof getFencyAvailabilityInfo;
16
+ createStream: typeof createStream;
17
+ createChatCompletion: typeof createChatCompletion;
25
18
  };
26
19
  export default _default;
27
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,GAAE,MAAgB;IAIrC;;OAEG;IACH,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;CAG/B;;;;;AAGD,wBAGE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAIjE,YAAY,EACV,qBAAqB,EAAE,aAAa,EAAE,YAAY,EACnD,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,wBAAwB,EAAE,gBAAgB,EAC3C,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,YAAY,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;;;;;;;;AAG7E,wBAME"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function n(e){return`Hello from @fencyai/js: ${e}`}var t=class{constructor(r="1.0.0"){this.version=r}getVersion(){return this.version}formatDate(r){return r.toLocaleDateString()}},i={greet:n,FencyUtils:t};export{t as FencyUtils,i as default,n as greet};
1
+ function s(){if(typeof window>"u")return!1;let e=["fetch","Promise","JSON"];for(let o of e)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",t=window.location.protocol==="https:";!o&&!t&&console.warn("Fency: For security, we recommend using HTTPS in production.")}return!0}function a(){let e={available:!0,missing:[],warnings:[]};if(typeof window>"u")return e.available=!1,e.missing.push("Browser environment"),e;let o=["fetch","Promise","JSON"];for(let t of o)typeof window[t]>"u"&&(e.available=!1,e.missing.push(`${t} API`));if(typeof window.location<"u"){let t=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",n=window.location.protocol==="https:";!t&&!n&&e.warnings.push("HTTPS is recommended for production use")}return e}function c(e,o={}){return new Promise((t,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 i={publishableKey:e,config:{apiVersion:o.config?.apiVersion||"2024-01-01",endpoint:o.config?.endpoint||"https://api.fency.ai"},version:"0.1.3"};setTimeout(()=>{t(i)},0)})}function m(e){return e&&typeof e=="object"&&typeof e.id=="string"&&typeof e.name=="string"}function y(e){return e&&typeof e=="object"&&typeof e.id=="string"&&typeof e.streamId=="string"&&Array.isArray(e.choices)}async function p(e,o={}){let t=o.apiUrl||"http://localhost:8080/v1/streams",n=o.name||e,i=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},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(!m(r))throw new Error("Invalid stream response");return r}async function l(e,o,t={}){let n=t.apiUrl||"http://localhost:8080/v1/chat-completions",i={...t.request,streamId:o,openai:{model:"gpt-4o-mini",messages:[{role:"user",content:"Hello, how are you?"}],...t.request?.openai}},r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(i)});if(!r.ok)throw new Error(`Failed to create chat completion: ${r.status} ${r.statusText}`);let f=await r.json();if(!y(f))throw new Error("Invalid chat completion response");return f}var P={loadFency:c,isFencyAvailable:s,getFencyAvailabilityInfo:a,createStream:p,createChatCompletion:l};export{l as createChatCompletion,p as createStream,P as default,a as getFencyAvailabilityInfo,s as isFencyAvailable,c as loadFency};
@@ -0,0 +1,19 @@
1
+ import { FencyOptions, FencyInstance } from './types.js';
2
+ /**
3
+ * Loads the Fency library with the given publishable key.
4
+ * This method should be called outside of a component's render to avoid
5
+ * recreating the Fency object on every render.
6
+ *
7
+ * @param publishableKey - Your Fency publishable key
8
+ * @param options - Optional configuration options
9
+ * @returns A promise that resolves to a Fency instance
10
+ *
11
+ * @example
12
+ * ```javascript
13
+ * import { loadFency } from '@fencyai/js';
14
+ *
15
+ * const fencyPromise = loadFency('pk_your_publishable_key');
16
+ * ```
17
+ */
18
+ export declare function loadFency(publishableKey: string, options?: Omit<FencyOptions, 'publishableKey'>): Promise<FencyInstance>;
19
+ //# sourceMappingURL=loadFency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadFency.d.ts","sourceRoot":"","sources":["../src/loadFency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEzD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CACvB,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE,IAAI,CAAC,YAAY,EAAE,gBAAgB,CAAM,GACjD,OAAO,CAAC,aAAa,CAAC,CA4BxB"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Loads the Fency library with the given publishable key.
3
+ * This method should be called outside of a component's render to avoid
4
+ * recreating the Fency object on every render.
5
+ *
6
+ * @param publishableKey - Your Fency publishable key
7
+ * @param options - Optional configuration options
8
+ * @returns A promise that resolves to a Fency instance
9
+ *
10
+ * @example
11
+ * ```javascript
12
+ * import { loadFency } from '@fencyai/js';
13
+ *
14
+ * const fencyPromise = loadFency('pk_your_publishable_key');
15
+ * ```
16
+ */
17
+ export function loadFency(publishableKey, options = {}) {
18
+ return new Promise((resolve, reject) => {
19
+ // Validate the publishable key
20
+ if (!publishableKey || typeof publishableKey !== 'string') {
21
+ reject(new Error('Fency: A valid publishable key is required.'));
22
+ return;
23
+ }
24
+ if (!publishableKey.startsWith('pk_')) {
25
+ reject(new Error('Fency: Invalid publishable key format. Keys should start with "pk_".'));
26
+ return;
27
+ }
28
+ // Create the Fency instance
29
+ const fencyInstance = {
30
+ publishableKey,
31
+ config: {
32
+ apiVersion: options.config?.apiVersion || '2024-01-01',
33
+ endpoint: options.config?.endpoint || 'https://api.fency.ai',
34
+ },
35
+ version: '0.1.3', // This should match your package version
36
+ };
37
+ // Simulate async loading (in a real implementation, this might load external scripts)
38
+ setTimeout(() => {
39
+ resolve(fencyInstance);
40
+ }, 0);
41
+ });
42
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Configuration options for Fency
3
+ */
4
+ export interface FencyOptions {
5
+ /** Your Fency publishable key */
6
+ publishableKey: string;
7
+ /** Optional configuration for the Fency instance */
8
+ config?: {
9
+ /** API version to use */
10
+ apiVersion?: string;
11
+ /** Custom endpoint URL */
12
+ endpoint?: string;
13
+ };
14
+ }
15
+ /**
16
+ * Fency instance interface
17
+ */
18
+ export interface FencyInstance {
19
+ /** The publishable key used to initialize this instance */
20
+ publishableKey: string;
21
+ /** Configuration options */
22
+ config: Required<FencyOptions['config']>;
23
+ /** Version of the Fency library */
24
+ version: string;
25
+ }
26
+ /**
27
+ * Availability information interface
28
+ */
29
+ export interface FencyAvailabilityInfo {
30
+ /** Whether Fency is available in the current environment */
31
+ available: boolean;
32
+ /** List of missing requirements */
33
+ missing: string[];
34
+ /** List of warnings */
35
+ warnings: string[];
36
+ }
37
+ export interface Stream {
38
+ id: string;
39
+ name: string;
40
+ }
41
+ export declare function isStream(obj: any): obj is Stream;
42
+ export interface ChatCompletionRequest {
43
+ streamId: string;
44
+ openai: {
45
+ model: string;
46
+ messages: Array<{
47
+ role: string;
48
+ content: string;
49
+ }>;
50
+ };
51
+ }
52
+ export interface ChatCompletionResponse {
53
+ id: string;
54
+ streamId: string;
55
+ choices: Array<{
56
+ message: {
57
+ role: string;
58
+ content: string;
59
+ };
60
+ finish_reason?: string;
61
+ }>;
62
+ }
63
+ export declare function isChatCompletionResponse(obj: any): obj is ChatCompletionResponse;
64
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iCAAiC;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,MAAM,CAAC,EAAE;QACP,yBAAyB;QACzB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,0BAA0B;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzC,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,4DAA4D;IAC5D,SAAS,EAAE,OAAO,CAAC;IACnB,mCAAmC;IACnC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,uBAAuB;IACvB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CAEd;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAQhD;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,KAAK,CAAC;YACd,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC,CAAC;KACJ,CAAC;CACH;AAED,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC;QACb,OAAO,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;QACF,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC,CAAC;CAEJ;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,sBAAsB,CAShF"}
package/dist/types.js ADDED
@@ -0,0 +1,17 @@
1
+ export function isStream(obj) {
2
+ return (obj &&
3
+ typeof obj === 'object' &&
4
+ typeof obj.id === 'string' &&
5
+ typeof obj.name === 'string'
6
+ // Add more checks for required fields if needed
7
+ );
8
+ }
9
+ export function isChatCompletionResponse(obj) {
10
+ return (obj &&
11
+ typeof obj === 'object' &&
12
+ typeof obj.id === 'string' &&
13
+ typeof obj.streamId === 'string' &&
14
+ Array.isArray(obj.choices)
15
+ // Add more checks for required fields if needed
16
+ );
17
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fencyai/js",
3
- "version": "0.1.2",
4
- "description": "A TypeScript ESM module for browser use",
3
+ "version": "0.1.4",
4
+ "description": "Core Fency library for browser integration - load Fency instances with your publishable key",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -33,10 +33,13 @@
33
33
  "publish:major": "npm run version:major && npm publish --access public"
34
34
  },
35
35
  "keywords": [
36
+ "fency",
37
+ "fencyai",
38
+ "browser",
36
39
  "typescript",
37
40
  "esm",
38
- "browser",
39
- "module"
41
+ "loadfency",
42
+ "publishable-key"
40
43
  ],
41
44
  "author": "",
42
45
  "license": "MIT",