@fencyai/js 0.1.4 → 0.1.5

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/dist/index.js CHANGED
@@ -1 +1 @@
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};
1
+ function a(){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 s(){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,endpoint:o.endpoint||"https://api.fency.ai"};setTimeout(()=>{t(i)},0)})}function f(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(!f(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 m=await r.json();if(!y(m))throw new Error("Invalid chat completion response");return m}var P={loadFency:c,isFencyAvailable:a,getFencyAvailabilityInfo:s,createStream:p,createChatCompletion:l};export{l as createChatCompletion,p as createStream,P as default,s as getFencyAvailabilityInfo,a as isFencyAvailable,c as loadFency};
@@ -1,4 +1,4 @@
1
- import { FencyOptions, FencyInstance } from './types.js';
1
+ import { FencyInstance, FencyOptions } from './types.js';
2
2
  /**
3
3
  * Loads the Fency library with the given publishable key.
4
4
  * This method should be called outside of a component's render to avoid
@@ -1 +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"}
1
+ {"version":3,"file":"loadFency.d.ts","sourceRoot":"","sources":["../src/loadFency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,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,CAwBxB"}
package/dist/loadFency.js CHANGED
@@ -28,11 +28,7 @@ export function loadFency(publishableKey, options = {}) {
28
28
  // Create the Fency instance
29
29
  const fencyInstance = {
30
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
31
+ endpoint: options.endpoint || 'https://api.fency.ai',
36
32
  };
37
33
  // Simulate async loading (in a real implementation, this might load external scripts)
38
34
  setTimeout(() => {
package/dist/types.d.ts CHANGED
@@ -5,12 +5,7 @@ export interface FencyOptions {
5
5
  /** Your Fency publishable key */
6
6
  publishableKey: string;
7
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
- };
8
+ endpoint?: string;
14
9
  }
15
10
  /**
16
11
  * Fency instance interface
@@ -18,10 +13,7 @@ export interface FencyOptions {
18
13
  export interface FencyInstance {
19
14
  /** The publishable key used to initialize this instance */
20
15
  publishableKey: string;
21
- /** Configuration options */
22
- config: Required<FencyOptions['config']>;
23
- /** Version of the Fency library */
24
- version: string;
16
+ endpoint: string;
25
17
  }
26
18
  /**
27
19
  * Availability information interface
@@ -1 +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,E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AoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB;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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fencyai/js",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
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",