@fencyai/js 0.1.5 → 0.1.7

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.
@@ -1,7 +1,7 @@
1
- import { ChatCompletionRequest, ChatCompletionResponse } from './types.js';
1
+ import { CreateChatCompletionRequest, CreateChatCompletionResponse } from './types.js';
2
2
  export interface CreateChatCompletionOptions {
3
3
  apiUrl?: string;
4
- request?: Partial<ChatCompletionRequest>;
4
+ request?: Partial<CreateChatCompletionRequest>;
5
5
  }
6
6
  /**
7
7
  * Creates a chat completion by making a POST request to the Fency API.
@@ -12,5 +12,5 @@ export interface CreateChatCompletionOptions {
12
12
  * @returns A promise that resolves to a ChatCompletionResponse
13
13
  * @throws Error if the request fails or the response is invalid
14
14
  */
15
- export declare function createChatCompletion(pk: string, streamId: string, options?: CreateChatCompletionOptions): Promise<ChatCompletionResponse>;
15
+ export declare function createChatCompletion(pk: string, streamId: string, options?: CreateChatCompletionOptions): Promise<CreateChatCompletionResponse>;
16
16
  //# sourceMappingURL=createChatCompletion.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"createChatCompletion.d.ts","sourceRoot":"","sources":["../src/createChatCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,4BAA4B,EAAkC,MAAM,YAAY,CAAC;AAEvH,MAAM,WAAW,2BAA2B;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAC;CAChD;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,4BAA4B,CAAC,CAmCvC"}
@@ -1,4 +1,4 @@
1
- import { isChatCompletionResponse } from './types.js';
1
+ import { isCreateChatCompletionResponse } from './types.js';
2
2
  /**
3
3
  * Creates a chat completion by making a POST request to the Fency API.
4
4
  *
@@ -36,7 +36,7 @@ export async function createChatCompletion(pk, streamId, options = {}) {
36
36
  throw new Error(`Failed to create chat completion: ${response.status} ${response.statusText}`);
37
37
  }
38
38
  const completion = await response.json();
39
- if (!isChatCompletionResponse(completion)) {
39
+ if (!isCreateChatCompletionResponse(completion)) {
40
40
  throw new Error('Invalid chat completion response');
41
41
  }
42
42
  return completion;
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
2
- import { loadFency } from './loadFency.js';
3
- import { createStream } from './createStream.js';
4
2
  import { createChatCompletion } from './createChatCompletion.js';
5
- export type { FencyAvailabilityInfo, FencyInstance, FencyOptions } from './types.js';
3
+ import { createStream } from './createStream.js';
4
+ import { loadFency } from './loadFency.js';
5
+ export type { FencyAvailabilityInfo, FencyInstance, FencyOptions, Stream } from './types.js';
6
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
7
  export { createChatCompletion } from './createChatCompletion.js';
11
8
  export type { CreateChatCompletionOptions } from './createChatCompletion.js';
9
+ export { createStream } from './createStream.js';
10
+ export type { CreateStreamOptions } from './createStream.js';
11
+ export { loadFency } from './loadFency.js';
12
12
  declare const _default: {
13
13
  loadFency: typeof loadFency;
14
14
  isFencyAvailable: typeof isFencyAvailable;
@@ -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,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"}
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,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,YAAY,EACV,qBAAqB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,EAC3D,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,wBAAwB,EAAE,gBAAgB,EAC3C,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,YAAY,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,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}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
+ 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};
package/dist/types.d.ts CHANGED
@@ -30,27 +30,20 @@ export interface Stream {
30
30
  id: string;
31
31
  name: string;
32
32
  }
33
- export declare function isStream(obj: any): obj is Stream;
34
- export interface ChatCompletionRequest {
33
+ export declare const isStream: (data: any) => data is Stream;
34
+ export type OpenAiModel = 'gpt-4o' | 'gpt-4o-mini' | 'gpt-3.5-turbo';
35
+ export interface CreateChatCompletionRequest {
35
36
  streamId: string;
36
37
  openai: {
37
- model: string;
38
+ model: OpenAiModel;
38
39
  messages: Array<{
39
- role: string;
40
+ role: 'user' | 'assistant' | 'system';
40
41
  content: string;
41
42
  }>;
42
43
  };
43
44
  }
44
- export interface ChatCompletionResponse {
45
+ export interface CreateChatCompletionResponse {
45
46
  id: string;
46
- streamId: string;
47
- choices: Array<{
48
- message: {
49
- role: string;
50
- content: string;
51
- };
52
- finish_reason?: string;
53
- }>;
54
47
  }
55
- export declare function isChatCompletionResponse(obj: any): obj is ChatCompletionResponse;
48
+ export declare const isCreateChatCompletionResponse: (data: any) => data is CreateChatCompletionResponse;
56
49
  //# sourceMappingURL=types.d.ts.map
@@ -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;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,CA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,KAAG,IAAI,IAAI,4BAElE,CAAA"}
package/dist/types.js CHANGED
@@ -1,17 +1,6 @@
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
- }
1
+ export const isStream = (data) => {
2
+ return typeof data === 'object' && data !== null && 'id' in data;
3
+ };
4
+ export const isCreateChatCompletionResponse = (data) => {
5
+ return typeof data === 'object' && data !== null && 'id' in data;
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fencyai/js",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
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",