@fencyai/js 0.1.3 → 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.
@@ -0,0 +1,12 @@
1
+ import { FencyAvailabilityInfo } from './types.js';
2
+ /**
3
+ * Check if Fency is available in the current environment
4
+ * This checks for browser compatibility and required APIs
5
+ */
6
+ export declare function isFencyAvailable(): boolean;
7
+ /**
8
+ * Get detailed information about Fency availability
9
+ * Returns an object with availability status and missing requirements
10
+ */
11
+ export declare function getFencyAvailabilityInfo(): FencyAvailabilityInfo;
12
+ //# sourceMappingURL=availability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"availability.d.ts","sourceRoot":"","sources":["../src/availability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAgC1C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,qBAAqB,CAwChE"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Check if Fency is available in the current environment
3
+ * This checks for browser compatibility and required APIs
4
+ */
5
+ export function isFencyAvailable() {
6
+ // Check if we're in a browser environment
7
+ if (typeof window === 'undefined') {
8
+ return false;
9
+ }
10
+ // Check for required browser APIs
11
+ const requiredAPIs = [
12
+ 'fetch',
13
+ 'Promise',
14
+ 'JSON'
15
+ ];
16
+ for (const api of requiredAPIs) {
17
+ if (typeof window[api] === 'undefined') {
18
+ return false;
19
+ }
20
+ }
21
+ // Check for HTTPS in production (recommended for security)
22
+ if (typeof window.location !== 'undefined') {
23
+ const isLocalhost = window.location.hostname === 'localhost' ||
24
+ window.location.hostname === '127.0.0.1';
25
+ const isSecure = window.location.protocol === 'https:';
26
+ // Warn in console if not secure (but don't block)
27
+ if (!isLocalhost && !isSecure) {
28
+ console.warn('Fency: For security, we recommend using HTTPS in production.');
29
+ }
30
+ }
31
+ return true;
32
+ }
33
+ /**
34
+ * Get detailed information about Fency availability
35
+ * Returns an object with availability status and missing requirements
36
+ */
37
+ export function getFencyAvailabilityInfo() {
38
+ const result = {
39
+ available: true,
40
+ missing: [],
41
+ warnings: []
42
+ };
43
+ // Check if we're in a browser environment
44
+ if (typeof window === 'undefined') {
45
+ result.available = false;
46
+ result.missing.push('Browser environment');
47
+ return result;
48
+ }
49
+ // Check for required browser APIs
50
+ const requiredAPIs = [
51
+ 'fetch',
52
+ 'Promise',
53
+ 'JSON'
54
+ ];
55
+ for (const api of requiredAPIs) {
56
+ if (typeof window[api] === 'undefined') {
57
+ result.available = false;
58
+ result.missing.push(`${api} API`);
59
+ }
60
+ }
61
+ // Check for HTTPS in production
62
+ if (typeof window.location !== 'undefined') {
63
+ const isLocalhost = window.location.hostname === 'localhost' ||
64
+ window.location.hostname === '127.0.0.1';
65
+ const isSecure = window.location.protocol === 'https:';
66
+ if (!isLocalhost && !isSecure) {
67
+ result.warnings.push('HTTPS is recommended for production use');
68
+ }
69
+ }
70
+ return result;
71
+ }
@@ -0,0 +1,16 @@
1
+ import { ChatCompletionRequest, ChatCompletionResponse } from './types.js';
2
+ export interface CreateChatCompletionOptions {
3
+ apiUrl?: string;
4
+ request?: Partial<ChatCompletionRequest>;
5
+ }
6
+ /**
7
+ * Creates a chat completion by making a POST request to the Fency API.
8
+ *
9
+ * @param pk - The publishable key (used as Bearer token)
10
+ * @param streamId - The stream ID to associate with the chat completion
11
+ * @param options - Optional configuration (apiUrl, request overrides)
12
+ * @returns A promise that resolves to a ChatCompletionResponse
13
+ * @throws Error if the request fails or the response is invalid
14
+ */
15
+ export declare function createChatCompletion(pk: string, streamId: string, options?: CreateChatCompletionOptions): Promise<ChatCompletionResponse>;
16
+ //# sourceMappingURL=createChatCompletion.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,43 @@
1
+ import { isChatCompletionResponse } from './types.js';
2
+ /**
3
+ * Creates a chat completion by making a POST request to the Fency API.
4
+ *
5
+ * @param pk - The publishable key (used as Bearer token)
6
+ * @param streamId - The stream ID to associate with the chat completion
7
+ * @param options - Optional configuration (apiUrl, request overrides)
8
+ * @returns A promise that resolves to a ChatCompletionResponse
9
+ * @throws Error if the request fails or the response is invalid
10
+ */
11
+ export async function createChatCompletion(pk, streamId, options = {}) {
12
+ const apiUrl = options.apiUrl || 'http://localhost:8080/v1/chat-completions';
13
+ const requestBody = {
14
+ ...options.request,
15
+ streamId, // always override with provided streamId
16
+ openai: {
17
+ model: 'gpt-4o-mini',
18
+ messages: [
19
+ {
20
+ role: 'user',
21
+ content: 'Hello, how are you?',
22
+ },
23
+ ],
24
+ ...options.request?.openai,
25
+ },
26
+ };
27
+ const response = await fetch(apiUrl, {
28
+ method: 'POST',
29
+ headers: {
30
+ 'Content-Type': 'application/json',
31
+ Authorization: `Bearer ${pk}`,
32
+ },
33
+ body: JSON.stringify(requestBody),
34
+ });
35
+ if (!response.ok) {
36
+ throw new Error(`Failed to create chat completion: ${response.status} ${response.statusText}`);
37
+ }
38
+ const completion = await response.json();
39
+ if (!isChatCompletionResponse(completion)) {
40
+ throw new Error('Invalid chat completion response');
41
+ }
42
+ return completion;
43
+ }
@@ -0,0 +1,15 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createStream.d.ts","sourceRoot":"","sources":["../src/createStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,YAAY,CAAC;AAE9C,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"}
@@ -0,0 +1,29 @@
1
+ import { isStream } from './types.js';
2
+ /**
3
+ * Creates a new stream by making a POST request to the Fency API.
4
+ *
5
+ * @param pk - The publishable key (used as Bearer token and default name)
6
+ * @param options - Optional configuration (apiUrl, name)
7
+ * @returns A promise that resolves to a Stream
8
+ * @throws Error if the request fails or the response is invalid
9
+ */
10
+ export async function createStream(pk, options = {}) {
11
+ const apiUrl = options.apiUrl || 'http://localhost:8080/v1/streams';
12
+ const name = options.name || pk;
13
+ const response = await fetch(apiUrl, {
14
+ method: 'POST',
15
+ headers: {
16
+ 'Content-Type': 'application/json',
17
+ Authorization: `Bearer ${pk}`,
18
+ },
19
+ body: JSON.stringify({ name }),
20
+ });
21
+ if (!response.ok) {
22
+ throw new Error(`Failed to create stream: ${response.status} ${response.statusText}`);
23
+ }
24
+ const stream = await response.json();
25
+ if (!isStream(stream)) {
26
+ throw new Error('Invalid stream response');
27
+ }
28
+ return stream;
29
+ }
package/dist/index.d.ts CHANGED
@@ -1,63 +1,20 @@
1
- /**
2
- * Configuration options for Fency
3
- */
4
- export interface FencyOptions {
5
- /** Your Fency publishable key */
6
- publishableKey: string;
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
- };
14
- }
15
- /**
16
- * Fency instance interface
17
- */
18
- export interface FencyInstance {
19
- /** The publishable key used to initialize this instance */
20
- publishableKey: string;
21
- /** Configuration options */
22
- config: Required<FencyOptions['config']>;
23
- /** Version of the Fency library */
24
- version: string;
25
- }
26
- /**
27
- * Loads the Fency library with the given publishable key.
28
- * This method should be called outside of a component's render to avoid
29
- * recreating the Fency object on every render.
30
- *
31
- * @param publishableKey - Your Fency publishable key
32
- * @param options - Optional configuration options
33
- * @returns A promise that resolves to a Fency instance
34
- *
35
- * @example
36
- * ```javascript
37
- * import { loadFency } from '@fencyai/js';
38
- *
39
- * const fencyPromise = loadFency('pk_your_publishable_key');
40
- * ```
41
- */
42
- export declare function loadFency(publishableKey: string, options?: Omit<FencyOptions, 'publishableKey'>): Promise<FencyInstance>;
43
- /**
44
- * Check if Fency is available in the current environment
45
- * This checks for browser compatibility and required APIs
46
- */
47
- export declare function isFencyAvailable(): boolean;
48
- /**
49
- * Get detailed information about Fency availability
50
- * Returns an object with availability status and missing requirements
51
- */
52
- export declare function getFencyAvailabilityInfo(): {
53
- available: boolean;
54
- missing: string[];
55
- warnings: string[];
56
- };
1
+ import { getFencyAvailabilityInfo, isFencyAvailable } from './availability.js';
2
+ import { loadFency } from './loadFency.js';
3
+ import { createStream } from './createStream.js';
4
+ import { createChatCompletion } from './createChatCompletion.js';
5
+ export type { FencyAvailabilityInfo, FencyInstance, FencyOptions } from './types.js';
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
+ export { createChatCompletion } from './createChatCompletion.js';
11
+ export type { CreateChatCompletionOptions } from './createChatCompletion.js';
57
12
  declare const _default: {
58
13
  loadFency: typeof loadFency;
59
14
  isFencyAvailable: typeof isFencyAvailable;
60
15
  getFencyAvailabilityInfo: typeof getFencyAvailabilityInfo;
16
+ createStream: typeof createStream;
17
+ createChatCompletion: typeof createChatCompletion;
61
18
  };
62
19
  export default _default;
63
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;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,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzC,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CACvB,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE,IAAI,CAAC,YAAY,EAAE,gBAAgB,CAAM,GACjD,OAAO,CAAC,aAAa,CAAC,CA4BxB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAgC1C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAwCA;;;;;;AAGD,wBAIE"}
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"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function s(n,i={}){return new Promise((e,o)=>{if(!n||typeof n!="string"){o(new Error("Fency: A valid publishable key is required."));return}if(!n.startsWith("pk_")){o(new Error('Fency: Invalid publishable key format. Keys should start with "pk_".'));return}let t={publishableKey:n,config:{apiVersion:i.config?.apiVersion||"2024-01-01",endpoint:i.config?.endpoint||"https://api.fency.ai"},version:"0.1.1"};setTimeout(()=>{e(t)},0)})}function r(){if(typeof window>"u")return!1;let n=["fetch","Promise","JSON"];for(let i of n)if(typeof window[i]>"u")return!1;if(typeof window.location<"u"){let i=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",e=window.location.protocol==="https:";!i&&!e&&console.warn("Fency: For security, we recommend using HTTPS in production.")}return!0}function a(){let n={available:!0,missing:[],warnings:[]};if(typeof window>"u")return n.available=!1,n.missing.push("Browser environment"),n;let i=["fetch","Promise","JSON"];for(let e of i)typeof window[e]>"u"&&(n.available=!1,n.missing.push(`${e} API`));if(typeof window.location<"u"){let e=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",o=window.location.protocol==="https:";!e&&!o&&n.warnings.push("HTTPS is recommended for production use")}return n}var c={loadFency:s,isFencyAvailable:r,getFencyAvailabilityInfo:a};export{c as default,a as getFencyAvailabilityInfo,r as isFencyAvailable,s 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};
@@ -0,0 +1,19 @@
1
+ import { FencyInstance, FencyOptions } from './types.js';
2
+ /**
3
+ * Loads the Fency library with the given publishable key.
4
+ * This method should be called outside of a component's render to avoid
5
+ * recreating the Fency object on every render.
6
+ *
7
+ * @param publishableKey - Your Fency publishable key
8
+ * @param options - Optional configuration options
9
+ * @returns A promise that resolves to a Fency instance
10
+ *
11
+ * @example
12
+ * ```javascript
13
+ * import { loadFency } from '@fencyai/js';
14
+ *
15
+ * const fencyPromise = loadFency('pk_your_publishable_key');
16
+ * ```
17
+ */
18
+ export declare function loadFency(publishableKey: string, options?: Omit<FencyOptions, 'publishableKey'>): Promise<FencyInstance>;
19
+ //# sourceMappingURL=loadFency.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Loads the Fency library with the given publishable key.
3
+ * This method should be called outside of a component's render to avoid
4
+ * recreating the Fency object on every render.
5
+ *
6
+ * @param publishableKey - Your Fency publishable key
7
+ * @param options - Optional configuration options
8
+ * @returns A promise that resolves to a Fency instance
9
+ *
10
+ * @example
11
+ * ```javascript
12
+ * import { loadFency } from '@fencyai/js';
13
+ *
14
+ * const fencyPromise = loadFency('pk_your_publishable_key');
15
+ * ```
16
+ */
17
+ export function loadFency(publishableKey, options = {}) {
18
+ return new Promise((resolve, reject) => {
19
+ // Validate the publishable key
20
+ if (!publishableKey || typeof publishableKey !== 'string') {
21
+ reject(new Error('Fency: A valid publishable key is required.'));
22
+ return;
23
+ }
24
+ if (!publishableKey.startsWith('pk_')) {
25
+ reject(new Error('Fency: Invalid publishable key format. Keys should start with "pk_".'));
26
+ return;
27
+ }
28
+ // Create the Fency instance
29
+ const fencyInstance = {
30
+ publishableKey,
31
+ endpoint: options.endpoint || 'https://api.fency.ai',
32
+ };
33
+ // Simulate async loading (in a real implementation, this might load external scripts)
34
+ setTimeout(() => {
35
+ resolve(fencyInstance);
36
+ }, 0);
37
+ });
38
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Configuration options for Fency
3
+ */
4
+ export interface FencyOptions {
5
+ /** Your Fency publishable key */
6
+ publishableKey: string;
7
+ /** Optional configuration for the Fency instance */
8
+ endpoint?: string;
9
+ }
10
+ /**
11
+ * Fency instance interface
12
+ */
13
+ export interface FencyInstance {
14
+ /** The publishable key used to initialize this instance */
15
+ publishableKey: string;
16
+ endpoint: string;
17
+ }
18
+ /**
19
+ * Availability information interface
20
+ */
21
+ export interface FencyAvailabilityInfo {
22
+ /** Whether Fency is available in the current environment */
23
+ available: boolean;
24
+ /** List of missing requirements */
25
+ missing: string[];
26
+ /** List of warnings */
27
+ warnings: string[];
28
+ }
29
+ export interface Stream {
30
+ id: string;
31
+ name: string;
32
+ }
33
+ export declare function isStream(obj: any): obj is Stream;
34
+ export interface ChatCompletionRequest {
35
+ streamId: string;
36
+ openai: {
37
+ model: string;
38
+ messages: Array<{
39
+ role: string;
40
+ content: string;
41
+ }>;
42
+ };
43
+ }
44
+ export interface ChatCompletionResponse {
45
+ id: string;
46
+ streamId: string;
47
+ choices: Array<{
48
+ message: {
49
+ role: string;
50
+ content: string;
51
+ };
52
+ finish_reason?: string;
53
+ }>;
54
+ }
55
+ export declare function isChatCompletionResponse(obj: any): obj is ChatCompletionResponse;
56
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC,CAAC;CAEJ;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,sBAAsB,CAShF"}
package/dist/types.js ADDED
@@ -0,0 +1,17 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fencyai/js",
3
- "version": "0.1.3",
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",