@fencyai/js 0.1.9 → 0.1.12

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.
@@ -9,7 +9,7 @@ import { isChatCompletion } from '../types.js';
9
9
  * @throws Error if the request fails or the response is invalid
10
10
  */
11
11
  export async function createChatCompletion(pk, streamId, options = {}) {
12
- const apiUrl = options.apiUrl || 'http://localhost:8080/v1/chat-completions';
12
+ const apiUrl = options.apiUrl || 'http://localhost:8080/v1/chat_completions';
13
13
  const requestBody = {
14
14
  ...options.request,
15
15
  streamId, // always override with provided streamId
@@ -0,0 +1,15 @@
1
+ import { ChatCompletionStream } from '../types.js';
2
+ export interface CreateChatCompletionStreamOptions {
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 ChatCompletionStream
12
+ * @throws Error if the request fails or the response is invalid
13
+ */
14
+ export declare function createChatCompletionStream(pk: string, options?: CreateChatCompletionStreamOptions): Promise<ChatCompletionStream>;
15
+ //# sourceMappingURL=createChatCompletionStream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createChatCompletionStream.d.ts","sourceRoot":"","sources":["../../src/api/createChatCompletionStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA0B,MAAM,aAAa,CAAC;AAE3E,MAAM,WAAW,iCAAiC;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,iCAAsC,GAC9C,OAAO,CAAC,oBAAoB,CAAC,CAsB/B"}
@@ -1,14 +1,14 @@
1
- import { isStream } from '../types.js';
1
+ import { isChatCompletionStream } from '../types.js';
2
2
  /**
3
3
  * Creates a new stream by making a POST request to the Fency API.
4
4
  *
5
5
  * @param pk - The publishable key (used as Bearer token and default name)
6
6
  * @param options - Optional configuration (apiUrl, name)
7
- * @returns A promise that resolves to a Stream
7
+ * @returns A promise that resolves to a ChatCompletionStream
8
8
  * @throws Error if the request fails or the response is invalid
9
9
  */
10
- export async function createStream(pk, options = {}) {
11
- const apiUrl = options.apiUrl || 'http://localhost:8080/v1/streams';
10
+ export async function createChatCompletionStream(pk, options = {}) {
11
+ const apiUrl = options.apiUrl || 'http://localhost:8080/v1/chat_completion_streams';
12
12
  const name = options.name || pk;
13
13
  const response = await fetch(apiUrl, {
14
14
  method: 'POST',
@@ -22,7 +22,7 @@ export async function createStream(pk, options = {}) {
22
22
  throw new Error(`Failed to create stream: ${response.status} ${response.statusText}`);
23
23
  }
24
24
  const stream = await response.json();
25
- if (!isStream(stream)) {
25
+ if (!isChatCompletionStream(stream)) {
26
26
  throw new Error('Invalid stream response');
27
27
  }
28
28
  return stream;
package/dist/index.d.ts CHANGED
@@ -1,20 +1,20 @@
1
- import { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
2
1
  import { createChatCompletion } from './api/createChatCompletion.js';
3
- import { createStream } from './api/createStream.js';
2
+ import { createChatCompletionStream } from './api/createChatCompletionStream.js';
3
+ import { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
4
4
  import { loadFency } from './loadFency.js';
5
- export type { FencyAvailabilityInfo, FencyInstance, FencyOptions, Stream, ChatCompletion } from './types.js';
6
- export { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
5
+ export type { ChatCompletion, ChatCompletionStream, FencyAvailabilityInfo, FencyInstance, FencyOptions } from './types.js';
7
6
  export { createChatCompletion } from './api/createChatCompletion.js';
8
7
  export type { CreateChatCompletionOptions } from './api/createChatCompletion.js';
9
- export { createStream } from './api/createStream.js';
10
- export type { CreateStreamOptions } from './api/createStream.js';
8
+ export { createChatCompletionStream } from './api/createChatCompletionStream.js';
9
+ export type { CreateChatCompletionStreamOptions } from './api/createChatCompletionStream.js';
10
+ export { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
11
11
  export { loadFency } from './loadFency.js';
12
12
  declare const _default: {
13
13
  loadFency: typeof loadFency;
14
14
  isFencyAvailable: typeof isFencyAvailable;
15
15
  getFencyAvailabilityInfo: typeof getFencyAvailabilityInfo;
16
- createStream: typeof createStream;
17
16
  createChatCompletion: typeof createChatCompletion;
17
+ createChatCompletionStream: typeof createChatCompletionStream;
18
18
  };
19
19
  export default _default;
20
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,YAAY,EACV,qBAAqB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAC3E,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,wBAAwB,EAAE,gBAAgB,EAC3C,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,YAAY,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;;;;;;;;AAG3C,wBAME"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,YAAY,EAAE,cAAc,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG3H,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,YAAY,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,YAAY,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,EACL,wBAAwB,EAAE,gBAAgB,EAC3C,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;;;;;;;;AAG3C,wBAME"}
package/dist/index.js CHANGED
@@ -1 +1 @@
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}var f=e=>typeof e=="object"&&e!==null&&"id"in e,y=e=>typeof e=="object"&&e!==null&&"id"in e;async function p(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}async function c(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}function l(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)})}var P={loadFency:l,isFencyAvailable:a,getFencyAvailabilityInfo:s,createStream:c,createChatCompletion:p};export{p as createChatCompletion,c as createStream,P as default,s as getFencyAvailabilityInfo,a as isFencyAvailable,l as loadFency};
1
+ 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};
package/dist/types.d.ts CHANGED
@@ -26,10 +26,10 @@ export interface FencyAvailabilityInfo {
26
26
  /** List of warnings */
27
27
  warnings: string[];
28
28
  }
29
- export interface Stream {
29
+ export interface ChatCompletionStream {
30
30
  id: string;
31
31
  }
32
- export declare const isStream: (data: any) => data is Stream;
32
+ export declare const isChatCompletionStream: (data: any) => data is ChatCompletionStream;
33
33
  export type OpenAiModel = 'gpt-4o' | 'gpt-4o-mini' | 'gpt-3.5-turbo';
34
34
  export interface CreateChatCompletionRequest {
35
35
  streamId: string;
@@ -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,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;CACZ;AAED,eAAO,MAAM,QAAQ,GAAI,MAAM,GAAG,KAAG,IAAI,IAAI,MAE5C,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,aAAa,GAAG,eAAe,CAAA;AAEpE,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE;QACN,KAAK,EAAE,WAAW,CAAC;QACnB,QAAQ,EAAE,KAAK,CAAC;YACd,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;YACtC,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC,CAAC;KACJ,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,gBAAgB,GAAI,MAAM,GAAG,KAAG,IAAI,IAAI,cAEpD,CAAA"}
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,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,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,eAAO,MAAM,sBAAsB,GAAI,MAAM,GAAG,KAAG,IAAI,IAAI,oBAE1D,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,aAAa,GAAG,eAAe,CAAA;AAEpE,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE;QACN,KAAK,EAAE,WAAW,CAAC;QACnB,QAAQ,EAAE,KAAK,CAAC;YACd,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;YACtC,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC,CAAC;KACJ,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,gBAAgB,GAAI,MAAM,GAAG,KAAG,IAAI,IAAI,cAEpD,CAAA"}
package/dist/types.js CHANGED
@@ -1,4 +1,4 @@
1
- export const isStream = (data) => {
1
+ export const isChatCompletionStream = (data) => {
2
2
  return typeof data === 'object' && data !== null && 'id' in data;
3
3
  };
4
4
  export const isChatCompletion = (data) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fencyai/js",
3
- "version": "0.1.9",
3
+ "version": "0.1.12",
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",
@@ -1,15 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"createStream.d.ts","sourceRoot":"","sources":["../../src/api/createStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,aAAa,CAAC;AAE/C,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"}