@fencyai/js 0.1.23 → 0.1.26
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/lib/api/createChatCompletion.d.ts +1 -0
- package/lib/api/createChatCompletion.js +2 -2
- package/lib/api/createChatCompletionStream.d.ts +1 -0
- package/lib/api/createChatCompletionStream.js +1 -1
- package/lib/index.d.ts +1 -5
- package/lib/index.js +0 -4
- package/lib/loadFency.d.ts +1 -1
- package/lib/loadFency.js +4 -9
- package/lib/types.d.ts +2 -13
- package/lib/types.js +7 -2
- package/package.json +2 -2
- package/lib/availability.d.ts +0 -11
- package/lib/availability.js +0 -71
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isChatCompletion } from '../types.js';
|
|
1
|
+
import { isChatCompletion, } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a chat completion by making a POST request to the Fency API.
|
|
4
4
|
*
|
|
@@ -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(params) {
|
|
12
|
-
const apiUrl =
|
|
12
|
+
const apiUrl = `${params.baseUrl}/v1/pub/chat-completions`;
|
|
13
13
|
const response = await fetch(apiUrl, {
|
|
14
14
|
method: 'POST',
|
|
15
15
|
headers: {
|
|
@@ -8,7 +8,7 @@ import { isChatCompletionStream } from '../types.js';
|
|
|
8
8
|
* @throws Error if the request fails or the response is invalid
|
|
9
9
|
*/
|
|
10
10
|
export async function createChatCompletionStream(params) {
|
|
11
|
-
const apiUrl =
|
|
11
|
+
const apiUrl = `${params.baseUrl}/v1/pub/chat-completion-streams`;
|
|
12
12
|
const response = await fetch(apiUrl, {
|
|
13
13
|
method: 'POST',
|
|
14
14
|
headers: {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { createChatCompletion } from './api/createChatCompletion';
|
|
2
2
|
import { createChatCompletionStream } from './api/createChatCompletionStream';
|
|
3
|
-
import { getFencyAvailabilityInfo, isFencyAvailable } from './availability';
|
|
4
3
|
import { loadFency } from './loadFency';
|
|
5
|
-
export type { ChatCompletion, ChatCompletionStream,
|
|
4
|
+
export type { ChatCompletion, ChatCompletionStream, FencyInstance, FencyOptions, } from './types';
|
|
6
5
|
export { createChatCompletion } from './api/createChatCompletion';
|
|
7
6
|
export type { CreateChatCompletionOptions } from './api/createChatCompletion';
|
|
8
7
|
export { createChatCompletionStream } from './api/createChatCompletionStream';
|
|
9
|
-
export { getFencyAvailabilityInfo, isFencyAvailable } from './availability';
|
|
10
8
|
export { loadFency } from './loadFency';
|
|
11
9
|
declare const _default: {
|
|
12
10
|
loadFency: typeof loadFency;
|
|
13
|
-
isFencyAvailable: typeof isFencyAvailable;
|
|
14
|
-
getFencyAvailabilityInfo: typeof getFencyAvailabilityInfo;
|
|
15
11
|
createChatCompletion: typeof createChatCompletion;
|
|
16
12
|
createChatCompletionStream: typeof createChatCompletionStream;
|
|
17
13
|
};
|
package/lib/index.js
CHANGED
|
@@ -3,18 +3,14 @@
|
|
|
3
3
|
// Import main functions
|
|
4
4
|
import { createChatCompletion } from './api/createChatCompletion';
|
|
5
5
|
import { createChatCompletionStream } from './api/createChatCompletionStream';
|
|
6
|
-
import { getFencyAvailabilityInfo, isFencyAvailable } from './availability';
|
|
7
6
|
import { loadFency } from './loadFency';
|
|
8
7
|
// Re-export main functions
|
|
9
8
|
export { createChatCompletion } from './api/createChatCompletion';
|
|
10
9
|
export { createChatCompletionStream } from './api/createChatCompletionStream';
|
|
11
|
-
export { getFencyAvailabilityInfo, isFencyAvailable } from './availability';
|
|
12
10
|
export { loadFency } from './loadFency';
|
|
13
11
|
// Default export for convenience
|
|
14
12
|
export default {
|
|
15
13
|
loadFency,
|
|
16
|
-
isFencyAvailable,
|
|
17
|
-
getFencyAvailabilityInfo,
|
|
18
14
|
createChatCompletion,
|
|
19
15
|
createChatCompletionStream,
|
|
20
16
|
};
|
package/lib/loadFency.d.ts
CHANGED
|
@@ -15,4 +15,4 @@ import { FencyInstance, FencyOptions } from './types.js';
|
|
|
15
15
|
* const fencyPromise = loadFency('pk_your_publishable_key');
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
export declare function loadFency(
|
|
18
|
+
export declare function loadFency(options: FencyOptions): Promise<FencyInstance>;
|
package/lib/loadFency.js
CHANGED
|
@@ -14,21 +14,16 @@
|
|
|
14
14
|
* const fencyPromise = loadFency('pk_your_publishable_key');
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
export function loadFency(
|
|
17
|
+
export function loadFency(options) {
|
|
18
18
|
return new Promise((resolve, reject) => {
|
|
19
|
-
|
|
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_')) {
|
|
19
|
+
if (!options.publishableKey.startsWith('pk_')) {
|
|
25
20
|
reject(new Error('Fency: Invalid publishable key format. Keys should start with "pk_".'));
|
|
26
21
|
return;
|
|
27
22
|
}
|
|
28
23
|
// Create the Fency instance
|
|
29
24
|
const fencyInstance = {
|
|
30
|
-
publishableKey,
|
|
31
|
-
|
|
25
|
+
publishableKey: options.publishableKey,
|
|
26
|
+
baseUrl: options.baseUrl || 'https://api.fency.ai',
|
|
32
27
|
};
|
|
33
28
|
// Simulate async loading (in a real implementation, this might load external scripts)
|
|
34
29
|
setTimeout(() => {
|
package/lib/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface FencyOptions {
|
|
|
5
5
|
/** Your Fency publishable key */
|
|
6
6
|
publishableKey: string;
|
|
7
7
|
/** Optional configuration for the Fency instance */
|
|
8
|
-
|
|
8
|
+
baseUrl?: string;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Fency instance interface
|
|
@@ -13,18 +13,7 @@ export interface FencyOptions {
|
|
|
13
13
|
export interface FencyInstance {
|
|
14
14
|
/** The publishable key used to initialize this instance */
|
|
15
15
|
publishableKey: string;
|
|
16
|
-
|
|
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[];
|
|
16
|
+
baseUrl: string;
|
|
28
17
|
}
|
|
29
18
|
export interface ChatCompletionStream {
|
|
30
19
|
chatCompletionStreamId: string;
|
package/lib/types.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export const isChatCompletionStream = (data) => {
|
|
2
|
-
return typeof data === 'object' &&
|
|
2
|
+
return (typeof data === 'object' &&
|
|
3
|
+
data !== null &&
|
|
4
|
+
'chatCompletionStreamId' in data);
|
|
3
5
|
};
|
|
4
6
|
export const isChatCompletion = (data) => {
|
|
5
|
-
return typeof data === 'object' &&
|
|
7
|
+
return (typeof data === 'object' &&
|
|
8
|
+
data !== null &&
|
|
9
|
+
'chatCompletionId' in data &&
|
|
10
|
+
'createdAt' in data);
|
|
6
11
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fencyai/js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.26",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "staklau <steinaageklaussen@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"ts-jest": "^29.1.1",
|
|
39
39
|
"typescript": "^5.3.3"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "6459e4ef59624f71aa5fc50208e06c4e18419e6f"
|
|
42
42
|
}
|
package/lib/availability.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { FencyAvailabilityInfo } from './types';
|
|
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;
|
package/lib/availability.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
}
|