@fencyai/js 0.1.6 → 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.
- package/dist/index.js +1 -1
- package/dist/types.d.ts +5 -12
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -17
- package/package.json +1 -1
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}
|
|
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
|
|
33
|
+
export declare const isStream: (data: any) => data is Stream;
|
|
34
|
+
export type OpenAiModel = 'gpt-4o' | 'gpt-4o-mini' | 'gpt-3.5-turbo';
|
|
34
35
|
export interface CreateChatCompletionRequest {
|
|
35
36
|
streamId: string;
|
|
36
37
|
openai: {
|
|
37
|
-
model:
|
|
38
|
+
model: OpenAiModel;
|
|
38
39
|
messages: Array<{
|
|
39
|
-
role:
|
|
40
|
+
role: 'user' | 'assistant' | 'system';
|
|
40
41
|
content: string;
|
|
41
42
|
}>;
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
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
|
|
48
|
+
export declare const isCreateChatCompletionResponse: (data: any) => data is CreateChatCompletionResponse;
|
|
56
49
|
//# 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,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,
|
|
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,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,4BAA4B;IAC3C,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,eAAO,MAAM,8BAA8B,GAAI,MAAM,GAAG,KAAG,IAAI,IAAI,4BAElE,CAAA"}
|
package/dist/types.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
);
|
|
8
|
-
}
|
|
9
|
-
export function isCreateChatCompletionResponse(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
|
+
};
|