@fencyai/js 0.1.4 → 0.1.6
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/createChatCompletion.d.ts +3 -3
- package/dist/createChatCompletion.d.ts.map +1 -1
- package/dist/createChatCompletion.js +2 -2
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/loadFency.d.ts +1 -1
- package/dist/loadFency.d.ts.map +1 -1
- package/dist/loadFency.js +1 -5
- package/dist/types.d.ts +5 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateChatCompletionRequest, CreateChatCompletionResponse } from './types.js';
|
|
2
2
|
export interface CreateChatCompletionOptions {
|
|
3
3
|
apiUrl?: string;
|
|
4
|
-
request?: Partial<
|
|
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<
|
|
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,
|
|
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 {
|
|
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 (!
|
|
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
|
-
|
|
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;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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
|
|
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 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 c(e,o,t={}){let n=t.apiUrl||"http://localhost:8080/v1/chat-completions",r={...t.request,streamId:o,openai:{model:"gpt-4o-mini",messages:[{role:"user",content:"Hello, how are you?"}],...t.request?.openai}},i=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(r)});if(!i.ok)throw new Error(`Failed to create chat completion: ${i.status} ${i.statusText}`);let m=await i.json();if(!y(m))throw new Error("Invalid chat completion response");return m}async function p(e,o={}){let t=o.apiUrl||"http://localhost:8080/v1/streams",n=o.name||e,r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify({name:n})});if(!r.ok)throw new Error(`Failed to create stream: ${r.status} ${r.statusText}`);let i=await r.json();if(!f(i))throw new Error("Invalid stream response");return i}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 r={publishableKey:e,endpoint:o.endpoint||"https://api.fency.ai"};setTimeout(()=>{t(r)},0)})}var P={loadFency:l,isFencyAvailable:a,getFencyAvailabilityInfo:s,createStream:p,createChatCompletion:c};export{c as createChatCompletion,p as createStream,P as default,s as getFencyAvailabilityInfo,a as isFencyAvailable,l as loadFency};
|
package/dist/loadFency.d.ts
CHANGED
package/dist/loadFency.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadFency.d.ts","sourceRoot":"","sources":["../src/loadFency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
@@ -39,7 +31,7 @@ export interface Stream {
|
|
|
39
31
|
name: string;
|
|
40
32
|
}
|
|
41
33
|
export declare function isStream(obj: any): obj is Stream;
|
|
42
|
-
export interface
|
|
34
|
+
export interface CreateChatCompletionRequest {
|
|
43
35
|
streamId: string;
|
|
44
36
|
openai: {
|
|
45
37
|
model: string;
|
|
@@ -49,7 +41,7 @@ export interface ChatCompletionRequest {
|
|
|
49
41
|
}>;
|
|
50
42
|
};
|
|
51
43
|
}
|
|
52
|
-
export interface
|
|
44
|
+
export interface CreateChatCompletionResponse {
|
|
53
45
|
id: string;
|
|
54
46
|
streamId: string;
|
|
55
47
|
choices: Array<{
|
|
@@ -60,5 +52,5 @@ export interface ChatCompletionResponse {
|
|
|
60
52
|
finish_reason?: string;
|
|
61
53
|
}>;
|
|
62
54
|
}
|
|
63
|
-
export declare function
|
|
55
|
+
export declare function isCreateChatCompletionResponse(obj: any): obj is CreateChatCompletionResponse;
|
|
64
56
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -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,
|
|
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,2BAA2B;IAC1C,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,4BAA4B;IAC3C,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,8BAA8B,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,4BAA4B,CAS5F"}
|
package/dist/types.js
CHANGED
|
@@ -6,7 +6,7 @@ export function isStream(obj) {
|
|
|
6
6
|
// Add more checks for required fields if needed
|
|
7
7
|
);
|
|
8
8
|
}
|
|
9
|
-
export function
|
|
9
|
+
export function isCreateChatCompletionResponse(obj) {
|
|
10
10
|
return (obj &&
|
|
11
11
|
typeof obj === 'object' &&
|
|
12
12
|
typeof obj.id === 'string' &&
|