@fencyai/js 0.1.9 → 0.1.13
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/README.md +4 -181
- package/{dist → lib}/api/createChatCompletion.d.ts +5 -3
- package/{dist → lib}/api/createChatCompletion.js +4 -18
- package/lib/api/createChatCompletionStream.d.ts +12 -0
- package/{dist/api/createStream.js → lib/api/createChatCompletionStream.js} +6 -8
- package/{dist → lib}/availability.d.ts +1 -2
- package/{dist/index.d.ts → lib/js.d.ts} +11 -13
- package/lib/js.js +20 -0
- package/{dist → lib}/loadFency.d.ts +0 -1
- package/{dist → lib}/types.d.ts +11 -8
- package/lib/types.js +6 -0
- package/package.json +27 -48
- package/dist/api/createChatCompletion.d.ts.map +0 -1
- package/dist/api/createStream.d.ts +0 -15
- package/dist/api/createStream.d.ts.map +0 -1
- package/dist/availability.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -1
- package/dist/loadFency.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- /package/{dist → lib}/availability.js +0 -0
- /package/{dist → lib}/loadFency.js +0 -0
package/README.md
CHANGED
|
@@ -1,188 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@fencyai/js`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @fencyai/js
|
|
9
|
-
```
|
|
3
|
+
> TODO: description
|
|
10
4
|
|
|
11
5
|
## Usage
|
|
12
6
|
|
|
13
|
-
### Basic Usage
|
|
14
|
-
|
|
15
|
-
```javascript
|
|
16
|
-
import { loadFency } from '@fencyai/js';
|
|
17
|
-
|
|
18
|
-
// Make sure to call `loadFency` outside of a component's render to avoid
|
|
19
|
-
// recreating the Fency object on every render.
|
|
20
|
-
const fencyPromise = loadFency('pk_test_your_publishable_key_here');
|
|
21
|
-
|
|
22
|
-
// Use the promise
|
|
23
|
-
fencyPromise.then((fency) => {
|
|
24
|
-
console.log('Fency loaded:', fency.publishableKey);
|
|
25
|
-
console.log('Version:', fency.version);
|
|
26
|
-
});
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### With Configuration Options
|
|
30
|
-
|
|
31
|
-
```javascript
|
|
32
|
-
import { loadFency } from '@fencyai/js';
|
|
33
|
-
|
|
34
|
-
const fencyPromise = loadFency('pk_test_your_key', {
|
|
35
|
-
config: {
|
|
36
|
-
apiVersion: '2024-01-01',
|
|
37
|
-
endpoint: 'https://api.fency.ai'
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Error Handling
|
|
43
|
-
|
|
44
|
-
```javascript
|
|
45
|
-
import { loadFency } from '@fencyai/js';
|
|
46
|
-
|
|
47
|
-
const fencyPromise = loadFency('invalid_key')
|
|
48
|
-
.then((fency) => {
|
|
49
|
-
// Success
|
|
50
|
-
})
|
|
51
|
-
.catch((error) => {
|
|
52
|
-
console.error('Failed to load Fency:', error.message);
|
|
53
|
-
});
|
|
54
7
|
```
|
|
8
|
+
const js = require('@fencyai/js');
|
|
55
9
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
```html
|
|
59
|
-
<!DOCTYPE html>
|
|
60
|
-
<html>
|
|
61
|
-
<head>
|
|
62
|
-
<title>Fency JS Demo</title>
|
|
63
|
-
</head>
|
|
64
|
-
<body>
|
|
65
|
-
<script type="module">
|
|
66
|
-
import { loadFency } from 'https://unpkg.com/@fencyai/js@latest/dist/index.js';
|
|
67
|
-
|
|
68
|
-
const fencyPromise = loadFency('pk_test_your_key');
|
|
69
|
-
fencyPromise.then(fency => {
|
|
70
|
-
document.body.innerHTML = `<p>Fency loaded: ${fency.version}</p>`;
|
|
71
|
-
});
|
|
72
|
-
</script>
|
|
73
|
-
</body>
|
|
74
|
-
</html>
|
|
10
|
+
// TODO: DEMONSTRATE API
|
|
75
11
|
```
|
|
76
|
-
|
|
77
|
-
## API Reference
|
|
78
|
-
|
|
79
|
-
### `loadFency(publishableKey, options?)`
|
|
80
|
-
|
|
81
|
-
Loads the Fency library with the given publishable key.
|
|
82
|
-
|
|
83
|
-
**Parameters:**
|
|
84
|
-
- `publishableKey` (string): Your Fency publishable key (must start with `pk_`)
|
|
85
|
-
- `options` (object, optional): Configuration options
|
|
86
|
-
- `config.apiVersion` (string, optional): API version to use (default: `'2024-01-01'`)
|
|
87
|
-
- `config.endpoint` (string, optional): Custom endpoint URL (default: `'https://api.fency.ai'`)
|
|
88
|
-
|
|
89
|
-
**Returns:** Promise<FencyInstance>
|
|
90
|
-
|
|
91
|
-
**Throws:** Error if publishable key is invalid
|
|
92
|
-
|
|
93
|
-
### `isFencyAvailable()`
|
|
94
|
-
|
|
95
|
-
Check if Fency is available in the current environment.
|
|
96
|
-
|
|
97
|
-
**Returns:** boolean
|
|
98
|
-
|
|
99
|
-
## Development
|
|
100
|
-
|
|
101
|
-
### Prerequisites
|
|
102
|
-
|
|
103
|
-
- Node.js 16.0.0 or higher
|
|
104
|
-
- npm
|
|
105
|
-
|
|
106
|
-
### Versioning
|
|
107
|
-
|
|
108
|
-
This project follows [Semantic Versioning](https://semver.org/). See [VERSIONING.md](./VERSIONING.md) for detailed guidelines.
|
|
109
|
-
|
|
110
|
-
**Quick version commands:**
|
|
111
|
-
```bash
|
|
112
|
-
npm run version:patch # Bug fixes (0.1.0 → 0.1.1)
|
|
113
|
-
npm run version:minor # New features (0.1.0 → 0.2.0)
|
|
114
|
-
npm run version:major # Breaking changes (0.1.0 → 1.0.0)
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### Setup
|
|
118
|
-
|
|
119
|
-
1. Clone the repository:
|
|
120
|
-
```bash
|
|
121
|
-
git clone https://github.com/fencyai/fency-js.git
|
|
122
|
-
cd fency-js
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
2. Install dependencies:
|
|
126
|
-
```bash
|
|
127
|
-
npm install
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
3. Start development mode:
|
|
131
|
-
```bash
|
|
132
|
-
npm run dev
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Build
|
|
136
|
-
|
|
137
|
-
Build the project for production:
|
|
138
|
-
```bash
|
|
139
|
-
npm run build
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
This will:
|
|
143
|
-
- Compile TypeScript to JavaScript
|
|
144
|
-
- Generate type definitions
|
|
145
|
-
- Bundle and minify the code for browser use
|
|
146
|
-
|
|
147
|
-
### Publishing
|
|
148
|
-
|
|
149
|
-
Before publishing, make sure to:
|
|
150
|
-
|
|
151
|
-
1. Update the version: `npm run version:patch|minor|major`
|
|
152
|
-
2. Update the CHANGELOG.md with your changes
|
|
153
|
-
3. Build the project: `npm run build`
|
|
154
|
-
4. Publish to npm: `npm publish`
|
|
155
|
-
|
|
156
|
-
**Quick publish commands:**
|
|
157
|
-
```bash
|
|
158
|
-
npm run publish:patch # Bump patch + publish
|
|
159
|
-
npm run publish:minor # Bump minor + publish
|
|
160
|
-
npm run publish:major # Bump major + publish
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
## Project Structure
|
|
164
|
-
|
|
165
|
-
```
|
|
166
|
-
fency-js/
|
|
167
|
-
├── src/
|
|
168
|
-
│ └── index.ts # Main entry point with loadFency
|
|
169
|
-
├── dist/ # Built files (generated)
|
|
170
|
-
├── package.json # Package configuration
|
|
171
|
-
├── tsconfig.json # TypeScript configuration
|
|
172
|
-
└── README.md # This file
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
## Features
|
|
176
|
-
|
|
177
|
-
- ✅ TypeScript support with full type definitions
|
|
178
|
-
- ✅ ESM module format for modern browsers
|
|
179
|
-
- ✅ Tree-shakable exports
|
|
180
|
-
- ✅ Minified production builds
|
|
181
|
-
- ✅ Browser-compatible
|
|
182
|
-
- ✅ Publishable key validation
|
|
183
|
-
- ✅ Promise-based loading
|
|
184
|
-
- ✅ npm package ready
|
|
185
|
-
|
|
186
|
-
## License
|
|
187
|
-
|
|
188
|
-
MIT
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ChatCompletion, CreateChatCompletionRequest } from '../types.js';
|
|
2
2
|
export interface CreateChatCompletionOptions {
|
|
3
3
|
apiUrl?: string;
|
|
4
|
-
request
|
|
4
|
+
request: CreateChatCompletionRequest;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Creates a chat completion by making a POST request to the Fency API.
|
|
@@ -12,5 +12,7 @@ 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(
|
|
16
|
-
|
|
15
|
+
export declare function createChatCompletion(params: {
|
|
16
|
+
pk: string;
|
|
17
|
+
request: CreateChatCompletionRequest;
|
|
18
|
+
}): Promise<ChatCompletion>;
|
|
@@ -8,29 +8,15 @@ import { isChatCompletion } from '../types.js';
|
|
|
8
8
|
* @returns A promise that resolves to a ChatCompletionResponse
|
|
9
9
|
* @throws Error if the request fails or the response is invalid
|
|
10
10
|
*/
|
|
11
|
-
export async function createChatCompletion(
|
|
12
|
-
const apiUrl =
|
|
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
|
-
};
|
|
11
|
+
export async function createChatCompletion(params) {
|
|
12
|
+
const apiUrl = 'http://localhost:8080/v1/pub/chat-completions';
|
|
27
13
|
const response = await fetch(apiUrl, {
|
|
28
14
|
method: 'POST',
|
|
29
15
|
headers: {
|
|
30
16
|
'Content-Type': 'application/json',
|
|
31
|
-
Authorization: `Bearer ${pk}`,
|
|
17
|
+
Authorization: `Bearer ${params.pk}`,
|
|
32
18
|
},
|
|
33
|
-
body: JSON.stringify(
|
|
19
|
+
body: JSON.stringify(params.request),
|
|
34
20
|
});
|
|
35
21
|
if (!response.ok) {
|
|
36
22
|
throw new Error(`Failed to create chat completion: ${response.status} ${response.statusText}`);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChatCompletionStream } 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 ChatCompletionStream
|
|
8
|
+
* @throws Error if the request fails or the response is invalid
|
|
9
|
+
*/
|
|
10
|
+
export declare function createChatCompletionStream(params: {
|
|
11
|
+
pk: string;
|
|
12
|
+
}): Promise<ChatCompletionStream>;
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isChatCompletionStream } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a new stream by making a POST request to the Fency API.
|
|
4
4
|
*
|
|
5
5
|
* @param pk - The publishable key (used as Bearer token and default name)
|
|
6
6
|
* @param options - Optional configuration (apiUrl, name)
|
|
7
|
-
* @returns A promise that resolves to a
|
|
7
|
+
* @returns A promise that resolves to a ChatCompletionStream
|
|
8
8
|
* @throws Error if the request fails or the response is invalid
|
|
9
9
|
*/
|
|
10
|
-
export async function
|
|
11
|
-
const apiUrl =
|
|
12
|
-
const name = options.name || pk;
|
|
10
|
+
export async function createChatCompletionStream(params) {
|
|
11
|
+
const apiUrl = 'http://localhost:8080/v1/pub/chat-completion-streams';
|
|
13
12
|
const response = await fetch(apiUrl, {
|
|
14
13
|
method: 'POST',
|
|
15
14
|
headers: {
|
|
16
15
|
'Content-Type': 'application/json',
|
|
17
|
-
Authorization: `Bearer ${pk}`,
|
|
16
|
+
Authorization: `Bearer ${params.pk}`,
|
|
18
17
|
},
|
|
19
|
-
body: JSON.stringify({ name }),
|
|
20
18
|
});
|
|
21
19
|
if (!response.ok) {
|
|
22
20
|
throw new Error(`Failed to create stream: ${response.status} ${response.statusText}`);
|
|
23
21
|
}
|
|
24
22
|
const stream = await response.json();
|
|
25
|
-
if (!
|
|
23
|
+
if (!isChatCompletionStream(stream)) {
|
|
26
24
|
throw new Error('Invalid stream response');
|
|
27
25
|
}
|
|
28
26
|
return stream;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FencyAvailabilityInfo } from './types
|
|
1
|
+
import { FencyAvailabilityInfo } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Check if Fency is available in the current environment
|
|
4
4
|
* This checks for browser compatibility and required APIs
|
|
@@ -9,4 +9,3 @@ export declare function isFencyAvailable(): boolean;
|
|
|
9
9
|
* Returns an object with availability status and missing requirements
|
|
10
10
|
*/
|
|
11
11
|
export declare function getFencyAvailabilityInfo(): FencyAvailabilityInfo;
|
|
12
|
-
//# sourceMappingURL=availability.d.ts.map
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { loadFency } from './loadFency
|
|
5
|
-
export type {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
9
|
-
export {
|
|
10
|
-
export
|
|
11
|
-
export { loadFency } from './loadFency.js';
|
|
1
|
+
import { createChatCompletion } from './api/createChatCompletion';
|
|
2
|
+
import { createChatCompletionStream } from './api/createChatCompletionStream';
|
|
3
|
+
import { getFencyAvailabilityInfo, isFencyAvailable } from './availability';
|
|
4
|
+
import { loadFency } from './loadFency';
|
|
5
|
+
export type { ChatCompletion, ChatCompletionStream, FencyAvailabilityInfo, FencyInstance, FencyOptions } from './types';
|
|
6
|
+
export { createChatCompletion } from './api/createChatCompletion';
|
|
7
|
+
export type { CreateChatCompletionOptions } from './api/createChatCompletion';
|
|
8
|
+
export { createChatCompletionStream } from './api/createChatCompletionStream';
|
|
9
|
+
export { getFencyAvailabilityInfo, isFencyAvailable } from './availability';
|
|
10
|
+
export { loadFency } from './loadFency';
|
|
12
11
|
declare const _default: {
|
|
13
12
|
loadFency: typeof loadFency;
|
|
14
13
|
isFencyAvailable: typeof isFencyAvailable;
|
|
15
14
|
getFencyAvailabilityInfo: typeof getFencyAvailabilityInfo;
|
|
16
|
-
createStream: typeof createStream;
|
|
17
15
|
createChatCompletion: typeof createChatCompletion;
|
|
16
|
+
createChatCompletionStream: typeof createChatCompletionStream;
|
|
18
17
|
};
|
|
19
18
|
export default _default;
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|
package/lib/js.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Core Fency library - equivalent to @stripe/stripe-js
|
|
2
|
+
// This is the base library that provides the loadFency method
|
|
3
|
+
// Import main functions
|
|
4
|
+
import { createChatCompletion } from './api/createChatCompletion';
|
|
5
|
+
import { createChatCompletionStream } from './api/createChatCompletionStream';
|
|
6
|
+
import { getFencyAvailabilityInfo, isFencyAvailable } from './availability';
|
|
7
|
+
import { loadFency } from './loadFency';
|
|
8
|
+
// Re-export main functions
|
|
9
|
+
export { createChatCompletion } from './api/createChatCompletion';
|
|
10
|
+
export { createChatCompletionStream } from './api/createChatCompletionStream';
|
|
11
|
+
export { getFencyAvailabilityInfo, isFencyAvailable } from './availability';
|
|
12
|
+
export { loadFency } from './loadFency';
|
|
13
|
+
// Default export for convenience
|
|
14
|
+
export default {
|
|
15
|
+
loadFency,
|
|
16
|
+
isFencyAvailable,
|
|
17
|
+
getFencyAvailabilityInfo,
|
|
18
|
+
createChatCompletion,
|
|
19
|
+
createChatCompletionStream,
|
|
20
|
+
};
|
package/{dist → lib}/types.d.ts
RENAMED
|
@@ -26,24 +26,27 @@ export interface FencyAvailabilityInfo {
|
|
|
26
26
|
/** List of warnings */
|
|
27
27
|
warnings: string[];
|
|
28
28
|
}
|
|
29
|
-
export interface
|
|
30
|
-
|
|
29
|
+
export interface ChatCompletionStream {
|
|
30
|
+
chatCompletionStreamId: string;
|
|
31
31
|
}
|
|
32
|
-
export declare const
|
|
32
|
+
export declare const isChatCompletionStream: (data: any) => data is ChatCompletionStream;
|
|
33
33
|
export type OpenAiModel = 'gpt-4o' | 'gpt-4o-mini' | 'gpt-3.5-turbo';
|
|
34
34
|
export interface CreateChatCompletionRequest {
|
|
35
|
-
|
|
35
|
+
chatCompletionStreamId?: string;
|
|
36
36
|
openai: {
|
|
37
37
|
model: OpenAiModel;
|
|
38
|
+
responseJsonSchema?: string;
|
|
38
39
|
messages: Array<{
|
|
39
40
|
role: 'user' | 'assistant' | 'system';
|
|
40
41
|
content: string;
|
|
41
42
|
}>;
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
|
-
export
|
|
45
|
-
|
|
45
|
+
export type ChatCompletion = {
|
|
46
|
+
chatCompletionId: string;
|
|
47
|
+
chatCompletionStreamId?: string;
|
|
48
|
+
response?: string;
|
|
49
|
+
responseIsStructured?: boolean;
|
|
46
50
|
createdAt: string;
|
|
47
|
-
}
|
|
51
|
+
};
|
|
48
52
|
export declare const isChatCompletion: (data: any) => data is ChatCompletion;
|
|
49
|
-
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const isChatCompletionStream = (data) => {
|
|
2
|
+
return typeof data === 'object' && data !== null && 'chatCompletionStreamId' in data;
|
|
3
|
+
};
|
|
4
|
+
export const isChatCompletion = (data) => {
|
|
5
|
+
return typeof data === 'object' && data !== null && 'chatCompletionId' in data && 'createdAt' in data;
|
|
6
|
+
};
|
package/package.json
CHANGED
|
@@ -1,62 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fencyai/js",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.13",
|
|
4
|
+
"description": "> TODO: description",
|
|
5
|
+
"author": "staklau <steinaageklaussen@gmail.com>",
|
|
6
|
+
"homepage": "",
|
|
7
|
+
"license": "MIT",
|
|
5
8
|
"type": "module",
|
|
6
|
-
"main": "
|
|
7
|
-
"
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
+
"main": "lib/js.js",
|
|
10
|
+
"types": "lib/js.d.ts",
|
|
9
11
|
"exports": {
|
|
10
12
|
".": {
|
|
11
|
-
"import": "./
|
|
12
|
-
"types": "./
|
|
13
|
+
"import": "./lib/js.js",
|
|
14
|
+
"types": "./lib/js.d.ts"
|
|
13
15
|
}
|
|
14
16
|
},
|
|
17
|
+
"directories": {
|
|
18
|
+
"lib": "lib",
|
|
19
|
+
"test": "__tests__"
|
|
20
|
+
},
|
|
15
21
|
"files": [
|
|
16
|
-
"
|
|
22
|
+
"lib"
|
|
17
23
|
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
18
27
|
"scripts": {
|
|
19
|
-
"build": "tsc
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"test:watch": "jest --watch",
|
|
20
31
|
"dev": "tsc --watch",
|
|
21
|
-
"
|
|
22
|
-
"prepublishOnly": "npm run clean && npm run build",
|
|
23
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
24
|
-
"version:patch": "npm version patch",
|
|
25
|
-
"version:minor": "npm version minor",
|
|
26
|
-
"version:major": "npm version major",
|
|
27
|
-
"version:prepatch": "npm version prepatch",
|
|
28
|
-
"version:preminor": "npm version preminor",
|
|
29
|
-
"version:premajor": "npm version premajor",
|
|
30
|
-
"version:prerelease": "npm version prerelease",
|
|
31
|
-
"publish:patch": "npm run version:patch && npm publish --access public",
|
|
32
|
-
"publish:minor": "npm run version:minor && npm publish --access public",
|
|
33
|
-
"publish:major": "npm run version:major && npm publish --access public"
|
|
32
|
+
"prepublishOnly": "npm run build"
|
|
34
33
|
},
|
|
35
|
-
"keywords": [
|
|
36
|
-
"fency",
|
|
37
|
-
"fencyai",
|
|
38
|
-
"browser",
|
|
39
|
-
"typescript",
|
|
40
|
-
"esm",
|
|
41
|
-
"loadfency",
|
|
42
|
-
"publishable-key"
|
|
43
|
-
],
|
|
44
|
-
"author": "",
|
|
45
|
-
"license": "MIT",
|
|
46
34
|
"devDependencies": {
|
|
47
|
-
"@types/
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
"repository": {
|
|
55
|
-
"type": "git",
|
|
56
|
-
"url": "git+https://github.com/fencyai/fency-js.git"
|
|
57
|
-
},
|
|
58
|
-
"bugs": {
|
|
59
|
-
"url": "https://github.com/fencyai/fency-js/issues"
|
|
60
|
-
},
|
|
61
|
-
"homepage": "https://github.com/fencyai/fency-js#readme"
|
|
35
|
+
"@types/jest": "^29.5.11",
|
|
36
|
+
"@types/node": "^20.10.5",
|
|
37
|
+
"jest": "^29.7.0",
|
|
38
|
+
"ts-jest": "^29.1.1",
|
|
39
|
+
"typescript": "^5.3.3"
|
|
40
|
+
}
|
|
62
41
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createChatCompletion.d.ts","sourceRoot":"","sources":["../../src/api/createChatCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAoB,MAAM,aAAa,CAAC;AAE5F,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,cAAc,CAAC,CAmCzB"}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createStream.d.ts","sourceRoot":"","sources":["../../src/api/createStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,aAAa,CAAC;AAE/C,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"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,+BAA+B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,YAAY,EACV,qBAAqB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAC3E,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,wBAAwB,EAAE,gBAAgB,EAC3C,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,YAAY,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;;;;;;;;AAG3C,wBAME"}
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/loadFency.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;CACZ;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,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,gBAAgB,GAAI,MAAM,GAAG,KAAG,IAAI,IAAI,cAEpD,CAAA"}
|
package/dist/types.js
DELETED
|
File without changes
|
|
File without changes
|