@fencyai/js 0.1.42 → 0.1.43
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 +0 -4
- package/lib/api/createChatCompletion.js +15 -31
- package/lib/api/createStream.d.ts +14 -0
- package/lib/api/createStream.js +53 -0
- package/lib/api/createUpload.d.ts +16 -0
- package/lib/api/createUpload.js +53 -0
- package/lib/api/createWebsite.d.ts +16 -0
- package/lib/api/createWebsite.js +39 -0
- package/lib/index.d.ts +17 -5
- package/lib/index.js +10 -4
- package/lib/openapi/core/ApiError.d.ts +10 -0
- package/lib/openapi/core/ApiError.js +11 -0
- package/lib/openapi/core/ApiRequestOptions.d.ts +13 -0
- package/lib/openapi/core/ApiRequestOptions.js +1 -0
- package/lib/openapi/core/ApiResult.d.ts +7 -0
- package/lib/openapi/core/ApiResult.js +1 -0
- package/lib/openapi/core/CancelablePromise.d.ts +20 -0
- package/lib/openapi/core/CancelablePromise.js +111 -0
- package/lib/openapi/core/OpenAPI.d.ts +16 -0
- package/lib/openapi/core/OpenAPI.js +11 -0
- package/lib/openapi/core/request.d.ts +30 -0
- package/lib/openapi/core/request.js +275 -0
- package/lib/openapi/index.d.ts +31 -0
- package/lib/openapi/index.js +11 -0
- package/lib/openapi/models/ApiDtoType.d.ts +6 -0
- package/lib/openapi/models/ApiDtoType.js +11 -0
- package/lib/openapi/models/ChatCompletionDto.d.ts +10 -0
- package/lib/openapi/models/ChatCompletionDto.js +1 -0
- package/lib/openapi/models/ChatCompletionStreamCompletedEventDto.d.ts +9 -0
- package/lib/openapi/models/ChatCompletionStreamCompletedEventDto.js +1 -0
- package/lib/openapi/models/CreateAnthropicChatCompletionDto.d.ts +8 -0
- package/lib/openapi/models/CreateAnthropicChatCompletionDto.js +1 -0
- package/lib/openapi/models/CreateChatCompletionRequest.d.ts +10 -0
- package/lib/openapi/models/CreateChatCompletionRequest.js +1 -0
- package/lib/openapi/models/CreateChatCompletionStreamRequest.d.ts +3 -0
- package/lib/openapi/models/CreateChatCompletionStreamRequest.js +1 -0
- package/lib/openapi/models/CreateGeminiChatCompletionDto.d.ts +8 -0
- package/lib/openapi/models/CreateGeminiChatCompletionDto.js +1 -0
- package/lib/openapi/models/CreateOpenAiChatCompletionDto.d.ts +8 -0
- package/lib/openapi/models/CreateOpenAiChatCompletionDto.js +1 -0
- package/lib/openapi/models/CreateOpenAiChatCompletionMessageDto.d.ts +4 -0
- package/lib/openapi/models/CreateOpenAiChatCompletionMessageDto.js +1 -0
- package/lib/openapi/models/CreateStreamRequest.d.ts +6 -0
- package/lib/openapi/models/CreateStreamRequest.js +1 -0
- package/lib/openapi/models/CreateWebsiteRequest.d.ts +3 -0
- package/lib/openapi/models/CreateWebsiteRequest.js +1 -0
- package/lib/openapi/models/FileUploadCompletedEventDto.d.ts +11 -0
- package/lib/openapi/models/FileUploadCompletedEventDto.js +1 -0
- package/lib/openapi/models/NewChatCompletionStreamChunkEventDto.d.ts +10 -0
- package/lib/openapi/models/NewChatCompletionStreamChunkEventDto.js +1 -0
- package/lib/openapi/models/PubCreateUploadRequest.d.ts +6 -0
- package/lib/openapi/models/PubCreateUploadRequest.js +1 -0
- package/lib/openapi/models/PubUploadDto.d.ts +6 -0
- package/lib/openapi/models/PubUploadDto.js +1 -0
- package/lib/openapi/models/PubWebsiteDto.d.ts +5 -0
- package/lib/openapi/models/PubWebsiteDto.js +1 -0
- package/lib/openapi/models/S3PostRequestDto.d.ts +10 -0
- package/lib/openapi/models/S3PostRequestDto.js +1 -0
- package/lib/openapi/models/StoredChatCompletionId.d.ts +3 -0
- package/lib/openapi/models/StoredChatCompletionId.js +1 -0
- package/lib/openapi/models/StoredFileId.d.ts +3 -0
- package/lib/openapi/models/StoredFileId.js +1 -0
- package/lib/openapi/models/StoredStreamId.d.ts +3 -0
- package/lib/openapi/models/StoredStreamId.js +1 -0
- package/lib/openapi/models/StoredUploadId.d.ts +3 -0
- package/lib/openapi/models/StoredUploadId.js +1 -0
- package/lib/openapi/models/StreamDto.d.ts +6 -0
- package/lib/openapi/models/StreamDto.js +1 -0
- package/lib/openapi/models/StreamEventType.d.ts +7 -0
- package/lib/openapi/models/StreamEventType.js +12 -0
- package/lib/openapi/models/StreamNotFoundEventDto.d.ts +7 -0
- package/lib/openapi/models/StreamNotFoundEventDto.js +1 -0
- package/lib/openapi/models/StreamTimeoutEventDto.d.ts +7 -0
- package/lib/openapi/models/StreamTimeoutEventDto.js +1 -0
- package/lib/openapi/models/StreamType.d.ts +4 -0
- package/lib/openapi/models/StreamType.js +9 -0
- package/lib/openapi/services/PubService.d.ts +50 -0
- package/lib/openapi/services/PubService.js +71 -0
- package/lib/types/CreateStreamRequest.d.ts +6 -0
- package/lib/types/CreateStreamRequest.js +1 -0
- package/lib/types/CreateStreamResponse.d.ts +9 -0
- package/lib/types/CreateStreamResponse.js +1 -0
- package/lib/types/CreateUploadRequest.d.ts +6 -0
- package/lib/types/CreateUploadRequest.js +1 -0
- package/lib/types/CreateUploadResponse.d.ts +9 -0
- package/lib/types/CreateUploadResponse.js +1 -0
- package/lib/types/CreateWebsiteRequest.d.ts +3 -0
- package/lib/types/CreateWebsiteRequest.js +1 -0
- package/lib/types/CreateWebsiteResponse.d.ts +9 -0
- package/lib/types/CreateWebsiteResponse.js +1 -0
- package/lib/types/FencyFile.d.ts +8 -0
- package/lib/types/FencyFile.js +1 -0
- package/lib/types/FencyUpload.d.ts +6 -0
- package/lib/types/FencyUpload.js +1 -0
- package/lib/types/FencyWebsite.d.ts +5 -0
- package/lib/types/FencyWebsite.js +1 -0
- package/lib/types/S3PostRequest.d.ts +10 -0
- package/lib/types/S3PostRequest.js +1 -0
- package/lib/types/Stream.d.ts +5 -0
- package/lib/types/{ChatCompletionStream.js → Stream.js} +2 -2
- package/lib/types/StreamData.d.ts +31 -0
- package/lib/types/StreamData.js +1 -0
- package/lib/utils/version.js +1 -1
- package/package.json +5 -3
- package/lib/api/createChatCompletionStream.d.ts +0 -21
- package/lib/api/createChatCompletionStream.js +0 -46
- package/lib/types/ChatCompletionStream.d.ts +0 -5
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { ApiError } from '../types/ApiError';
|
|
2
2
|
import { ChatCompletion } from '../types/ChatCompletion';
|
|
3
3
|
import { CreateChatCompletionRequest } from '../types/CreateChatCompletionRequest';
|
|
4
|
-
export interface CreateChatCompletionOptions {
|
|
5
|
-
apiUrl?: string;
|
|
6
|
-
request: CreateChatCompletionRequest;
|
|
7
|
-
}
|
|
8
4
|
/**
|
|
9
5
|
* Creates a chat completion by making a POST request to the Fency API.
|
|
10
6
|
*
|
|
@@ -1,39 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { parseNonOkResponse } from '../utils/parseNonOkResponse';
|
|
1
|
+
import { OpenAPI, PubService } from '../openapi';
|
|
3
2
|
import { getPackageVersion } from '../utils/version';
|
|
4
3
|
export async function createChatCompletion(params) {
|
|
5
|
-
const apiUrl = `${params.baseUrl}/v1/pub/chat-completions`;
|
|
6
|
-
console.log('request', params.request);
|
|
7
4
|
try {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
body: JSON.stringify(params.request),
|
|
16
|
-
});
|
|
17
|
-
if (!response.ok) {
|
|
18
|
-
const error = await parseNonOkResponse(response);
|
|
19
|
-
return {
|
|
20
|
-
type: 'error',
|
|
21
|
-
error: error,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
const completion = await response.json();
|
|
25
|
-
if (!isChatCompletion(completion)) {
|
|
26
|
-
return {
|
|
27
|
-
type: 'error',
|
|
28
|
-
error: {
|
|
29
|
-
code: 'InvalidResponse',
|
|
30
|
-
message: `Invalid chat completion response: ${JSON.stringify(completion)}`,
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
5
|
+
OpenAPI.BASE = params.baseUrl;
|
|
6
|
+
OpenAPI.HEADERS = {
|
|
7
|
+
'Content-Type': 'application/json',
|
|
8
|
+
Authorization: `Bearer ${params.pk}`,
|
|
9
|
+
'X-Fency-Sdk-Version': getPackageVersion(),
|
|
10
|
+
};
|
|
11
|
+
const response = await PubService.createChatCompletion(params.request);
|
|
34
12
|
return {
|
|
35
13
|
type: 'success',
|
|
36
|
-
completion
|
|
14
|
+
completion: {
|
|
15
|
+
id: response.id,
|
|
16
|
+
createdAt: response.createdAt,
|
|
17
|
+
streamId: response.streamId ?? undefined,
|
|
18
|
+
response: response.response ?? undefined,
|
|
19
|
+
responseIsStructured: response.responseIsStructured ?? undefined,
|
|
20
|
+
},
|
|
37
21
|
};
|
|
38
22
|
}
|
|
39
23
|
catch (error) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CreateStreamRequest, CreateStreamResponse } from '..';
|
|
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 declare function createStream(params: {
|
|
11
|
+
pk: string;
|
|
12
|
+
request: CreateStreamRequest;
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
}): Promise<CreateStreamResponse>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { OpenAPI, PubService, StreamType } from '../openapi';
|
|
2
|
+
import { getPackageVersion } from '../utils/version';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new stream by making a POST request to the Fency API.
|
|
5
|
+
*
|
|
6
|
+
* @param pk - The publishable key (used as Bearer token and default name)
|
|
7
|
+
* @param options - Optional configuration (apiUrl, name)
|
|
8
|
+
* @returns A promise that resolves to a Stream
|
|
9
|
+
* @throws Error if the request fails or the response is invalid
|
|
10
|
+
*/
|
|
11
|
+
export async function createStream(params) {
|
|
12
|
+
try {
|
|
13
|
+
OpenAPI.BASE = params.baseUrl;
|
|
14
|
+
OpenAPI.HEADERS = {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
Authorization: `Bearer ${params.pk}`,
|
|
17
|
+
'X-Fency-Sdk-Version': getPackageVersion(),
|
|
18
|
+
};
|
|
19
|
+
const response = await PubService.createStream({
|
|
20
|
+
type: mapTypeToStreamType(params.request.type),
|
|
21
|
+
chatCompletionStream: params.request.type === 'ChatCompletionStream'
|
|
22
|
+
? {
|
|
23
|
+
clientSecret: params.request.chatCompletionStreamOptions
|
|
24
|
+
?.sessionClientSecret,
|
|
25
|
+
}
|
|
26
|
+
: undefined,
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
type: 'success',
|
|
30
|
+
stream: {
|
|
31
|
+
id: response.id,
|
|
32
|
+
createdAt: response.createdAt,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return {
|
|
38
|
+
type: 'error',
|
|
39
|
+
error: {
|
|
40
|
+
code: 'UnknownError',
|
|
41
|
+
message: `Unknown error!\n${error ? `Error: ${error}\n` : ''}`.trim(),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const mapTypeToStreamType = (type) => {
|
|
47
|
+
switch (type) {
|
|
48
|
+
case 'ChatCompletionStream':
|
|
49
|
+
return StreamType.CHAT_COMPLETION_STREAM;
|
|
50
|
+
case 'FileUploadStream':
|
|
51
|
+
return StreamType.FILE_UPLOAD_STREAM;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CreateUploadRequest } from '../types/CreateUploadRequest';
|
|
2
|
+
import { CreateUploadResponse } from '../types/CreateUploadResponse';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a website by making a POST request to the Fency API.
|
|
5
|
+
*
|
|
6
|
+
* @param pk - The publishable key (used as Bearer token)
|
|
7
|
+
* @param request - The request body
|
|
8
|
+
* @param options - Optional configuration (apiUrl, request overrides)
|
|
9
|
+
* @returns A promise that resolves to a CreateWebsiteResponse
|
|
10
|
+
* @throws Error if the request fails or the response is invalid
|
|
11
|
+
*/
|
|
12
|
+
export declare function createUpload(params: {
|
|
13
|
+
pk: string;
|
|
14
|
+
request: CreateUploadRequest;
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
}): Promise<CreateUploadResponse>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { OpenAPI, PubService } from '../openapi';
|
|
2
|
+
import { getPackageVersion } from '../utils/version';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a website by making a POST request to the Fency API.
|
|
5
|
+
*
|
|
6
|
+
* @param pk - The publishable key (used as Bearer token)
|
|
7
|
+
* @param request - The request body
|
|
8
|
+
* @param options - Optional configuration (apiUrl, request overrides)
|
|
9
|
+
* @returns A promise that resolves to a CreateWebsiteResponse
|
|
10
|
+
* @throws Error if the request fails or the response is invalid
|
|
11
|
+
*/
|
|
12
|
+
export async function createUpload(params) {
|
|
13
|
+
try {
|
|
14
|
+
OpenAPI.BASE = params.baseUrl;
|
|
15
|
+
OpenAPI.HEADERS = {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
Authorization: `Bearer ${params.pk}`,
|
|
18
|
+
'X-Fency-Sdk-Version': getPackageVersion(),
|
|
19
|
+
};
|
|
20
|
+
const response = await PubService.createUpload({
|
|
21
|
+
streamId: params.request.streamId,
|
|
22
|
+
fileName: params.request.fileName,
|
|
23
|
+
mimeType: params.request.fileType,
|
|
24
|
+
fileSize: params.request.fileSize,
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
type: 'success',
|
|
28
|
+
upload: {
|
|
29
|
+
id: response.id,
|
|
30
|
+
createdAt: response.createdAt,
|
|
31
|
+
s3PostRequest: {
|
|
32
|
+
xAmzDate: response.s3PostRequest.amzDate,
|
|
33
|
+
xAmzSignature: response.s3PostRequest.amzSignature,
|
|
34
|
+
xAmzAlgorithm: response.s3PostRequest.amzAlgorithm,
|
|
35
|
+
xAmzCredential: response.s3PostRequest.amzCredential,
|
|
36
|
+
policy: response.s3PostRequest.policy,
|
|
37
|
+
key: response.s3PostRequest.key,
|
|
38
|
+
uploadUrl: response.s3PostRequest.uploadUrl,
|
|
39
|
+
sessionToken: response.s3PostRequest.sessionToken,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return {
|
|
46
|
+
type: 'error',
|
|
47
|
+
error: {
|
|
48
|
+
code: 'UnknownError',
|
|
49
|
+
message: `Unknown error!\n${error ? `Error: ${error}\n` : ''}`.trim(),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CreateWebsiteRequest } from '../types/CreateWebsiteRequest';
|
|
2
|
+
import { CreateWebsiteResponse } from '../types/CreateWebsiteResponse';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a website by making a POST request to the Fency API.
|
|
5
|
+
*
|
|
6
|
+
* @param pk - The publishable key (used as Bearer token)
|
|
7
|
+
* @param request - The request body
|
|
8
|
+
* @param options - Optional configuration (apiUrl, request overrides)
|
|
9
|
+
* @returns A promise that resolves to a CreateWebsiteResponse
|
|
10
|
+
* @throws Error if the request fails or the response is invalid
|
|
11
|
+
*/
|
|
12
|
+
export declare function createWebsite(params: {
|
|
13
|
+
pk: string;
|
|
14
|
+
request: CreateWebsiteRequest;
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
}): Promise<CreateWebsiteResponse>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { OpenAPI, PubService } from '../openapi';
|
|
2
|
+
import { getPackageVersion } from '../utils/version';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a website by making a POST request to the Fency API.
|
|
5
|
+
*
|
|
6
|
+
* @param pk - The publishable key (used as Bearer token)
|
|
7
|
+
* @param request - The request body
|
|
8
|
+
* @param options - Optional configuration (apiUrl, request overrides)
|
|
9
|
+
* @returns A promise that resolves to a CreateWebsiteResponse
|
|
10
|
+
* @throws Error if the request fails or the response is invalid
|
|
11
|
+
*/
|
|
12
|
+
export async function createWebsite(params) {
|
|
13
|
+
try {
|
|
14
|
+
OpenAPI.BASE = params.baseUrl;
|
|
15
|
+
OpenAPI.HEADERS = {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
Authorization: `Bearer ${params.pk}`,
|
|
18
|
+
'X-Fency-Sdk-Version': getPackageVersion(),
|
|
19
|
+
};
|
|
20
|
+
const response = await PubService.createWebsite(params.request);
|
|
21
|
+
return {
|
|
22
|
+
type: 'success',
|
|
23
|
+
website: {
|
|
24
|
+
id: response.id,
|
|
25
|
+
createdAt: response.createdAt,
|
|
26
|
+
content: response.content,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
return {
|
|
32
|
+
type: 'error',
|
|
33
|
+
error: {
|
|
34
|
+
code: 'UnknownError',
|
|
35
|
+
message: `Unknown error!\n${error ? `Error: ${error}\n` : ''}`.trim(),
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
import { createChatCompletion } from './api/createChatCompletion';
|
|
2
|
-
import {
|
|
2
|
+
import { createStream } from './api/createStream';
|
|
3
3
|
import { loadFency } from './loadFency';
|
|
4
4
|
export type { FencyInstance, FencyOptions } from './types';
|
|
5
5
|
export type { AnthropicModel } from './types/AnthropicModel';
|
|
6
6
|
export type { ChatCompletion, isChatCompletion } from './types/ChatCompletion';
|
|
7
7
|
export type { ChatCompletionMessage } from './types/ChatCompletionMessage';
|
|
8
|
-
export type { ChatCompletionStream } from './types/ChatCompletionStream';
|
|
9
8
|
export type { CreateAnthropicChatCompletionParams } from './types/CreateAnthropicChatCompletionParams';
|
|
10
9
|
export type { CreateChatCompletionRequest } from './types/CreateChatCompletionRequest';
|
|
11
10
|
export type { CreateGeminiChatCompletionParams } from './types/CreateGeminiChatCompletionParams';
|
|
12
11
|
export type { CreateOpenAiChatCompletionParams } from './types/CreateOpenAiChatCompletionParams';
|
|
12
|
+
export type { CreateStreamRequest } from './types/CreateStreamRequest';
|
|
13
|
+
export type { CreateStreamResponse } from './types/CreateStreamResponse';
|
|
14
|
+
export type { CreateWebsiteRequest } from './types/CreateWebsiteRequest';
|
|
15
|
+
export type { FencyUpload } from './types/FencyUpload';
|
|
16
|
+
export type { FencyWebsite } from './types/FencyWebsite';
|
|
13
17
|
export type { GeminiModel } from './types/GeminiModel';
|
|
14
18
|
export type { OpenAiModel } from './types/OpenAiModel';
|
|
19
|
+
export type { Stream } from './types/Stream';
|
|
15
20
|
export { createChatCompletion } from './api/createChatCompletion';
|
|
16
|
-
export type {
|
|
17
|
-
export {
|
|
21
|
+
export type { CreateChatCompletionResponse } from './api/createChatCompletion';
|
|
22
|
+
export { createUpload } from './api/createUpload';
|
|
23
|
+
export type { CreateUploadRequest } from './types/CreateUploadRequest';
|
|
24
|
+
export type { CreateUploadResponse } from './types/CreateUploadResponse';
|
|
25
|
+
export type { FencyFile } from './types/FencyFile';
|
|
26
|
+
export { createStream } from './api/createStream';
|
|
27
|
+
export type { ChatCompletionStreamCompleted, FileUploadCompleted, NewChatCompletionStreamChunk, StreamData, StreamNotFound, StreamTimeout, } from './types/StreamData';
|
|
28
|
+
export { createWebsite } from './api/createWebsite';
|
|
29
|
+
export type { CreateWebsiteResponse } from './types/CreateWebsiteResponse';
|
|
18
30
|
export { loadFency } from './loadFency';
|
|
19
31
|
export type { ApiError } from './types/ApiError';
|
|
20
32
|
declare const _default: {
|
|
21
33
|
loadFency: typeof loadFency;
|
|
22
34
|
createChatCompletion: typeof createChatCompletion;
|
|
23
|
-
|
|
35
|
+
createStream: typeof createStream;
|
|
24
36
|
};
|
|
25
37
|
export default _default;
|
package/lib/index.js
CHANGED
|
@@ -2,15 +2,21 @@
|
|
|
2
2
|
// This is the base library that provides the loadFency method
|
|
3
3
|
// Import main functions
|
|
4
4
|
import { createChatCompletion } from './api/createChatCompletion';
|
|
5
|
-
import {
|
|
5
|
+
import { createStream } from './api/createStream';
|
|
6
6
|
import { loadFency } from './loadFency';
|
|
7
|
-
//
|
|
7
|
+
// create chat completion
|
|
8
8
|
export { createChatCompletion } from './api/createChatCompletion';
|
|
9
|
-
|
|
9
|
+
// uploads
|
|
10
|
+
export { createUpload } from './api/createUpload';
|
|
11
|
+
// create chat completion stream
|
|
12
|
+
export { createStream } from './api/createStream';
|
|
13
|
+
// create website
|
|
14
|
+
export { createWebsite } from './api/createWebsite';
|
|
15
|
+
// load fency
|
|
10
16
|
export { loadFency } from './loadFency';
|
|
11
17
|
// Default export for convenience
|
|
12
18
|
export default {
|
|
13
19
|
loadFency,
|
|
14
20
|
createChatCompletion,
|
|
15
|
-
|
|
21
|
+
createStream,
|
|
16
22
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
2
|
+
import type { ApiResult } from './ApiResult';
|
|
3
|
+
export declare class ApiError extends Error {
|
|
4
|
+
readonly url: string;
|
|
5
|
+
readonly status: number;
|
|
6
|
+
readonly statusText: string;
|
|
7
|
+
readonly body: any;
|
|
8
|
+
readonly request: ApiRequestOptions;
|
|
9
|
+
constructor(request: ApiRequestOptions, response: ApiResult, message: string);
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class ApiError extends Error {
|
|
2
|
+
constructor(request, response, message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'ApiError';
|
|
5
|
+
this.url = response.url;
|
|
6
|
+
this.status = response.status;
|
|
7
|
+
this.statusText = response.statusText;
|
|
8
|
+
this.body = response.body;
|
|
9
|
+
this.request = request;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ApiRequestOptions = {
|
|
2
|
+
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
|
|
3
|
+
readonly url: string;
|
|
4
|
+
readonly path?: Record<string, any>;
|
|
5
|
+
readonly cookies?: Record<string, any>;
|
|
6
|
+
readonly headers?: Record<string, any>;
|
|
7
|
+
readonly query?: Record<string, any>;
|
|
8
|
+
readonly formData?: Record<string, any>;
|
|
9
|
+
readonly body?: any;
|
|
10
|
+
readonly mediaType?: string;
|
|
11
|
+
readonly responseHeader?: string;
|
|
12
|
+
readonly errors?: Record<number, string>;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare class CancelError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
get isCancelled(): boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface OnCancel {
|
|
6
|
+
readonly isResolved: boolean;
|
|
7
|
+
readonly isRejected: boolean;
|
|
8
|
+
readonly isCancelled: boolean;
|
|
9
|
+
(cancelHandler: () => void): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class CancelablePromise<T> implements Promise<T> {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void, onCancel: OnCancel) => void);
|
|
14
|
+
get [Symbol.toStringTag](): string;
|
|
15
|
+
then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
16
|
+
catch<TResult = never>(onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
|
|
17
|
+
finally(onFinally?: (() => void) | null): Promise<T>;
|
|
18
|
+
cancel(): void;
|
|
19
|
+
get isCancelled(): boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _CancelablePromise_isResolved, _CancelablePromise_isRejected, _CancelablePromise_isCancelled, _CancelablePromise_cancelHandlers, _CancelablePromise_promise, _CancelablePromise_resolve, _CancelablePromise_reject;
|
|
13
|
+
/* generated using openapi-typescript-codegen -- do not edit */
|
|
14
|
+
/* istanbul ignore file */
|
|
15
|
+
/* tslint:disable */
|
|
16
|
+
/* eslint-disable */
|
|
17
|
+
export class CancelError extends Error {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = 'CancelError';
|
|
21
|
+
}
|
|
22
|
+
get isCancelled() {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class CancelablePromise {
|
|
27
|
+
constructor(executor) {
|
|
28
|
+
_CancelablePromise_isResolved.set(this, void 0);
|
|
29
|
+
_CancelablePromise_isRejected.set(this, void 0);
|
|
30
|
+
_CancelablePromise_isCancelled.set(this, void 0);
|
|
31
|
+
_CancelablePromise_cancelHandlers.set(this, void 0);
|
|
32
|
+
_CancelablePromise_promise.set(this, void 0);
|
|
33
|
+
_CancelablePromise_resolve.set(this, void 0);
|
|
34
|
+
_CancelablePromise_reject.set(this, void 0);
|
|
35
|
+
__classPrivateFieldSet(this, _CancelablePromise_isResolved, false, "f");
|
|
36
|
+
__classPrivateFieldSet(this, _CancelablePromise_isRejected, false, "f");
|
|
37
|
+
__classPrivateFieldSet(this, _CancelablePromise_isCancelled, false, "f");
|
|
38
|
+
__classPrivateFieldSet(this, _CancelablePromise_cancelHandlers, [], "f");
|
|
39
|
+
__classPrivateFieldSet(this, _CancelablePromise_promise, new Promise((resolve, reject) => {
|
|
40
|
+
__classPrivateFieldSet(this, _CancelablePromise_resolve, resolve, "f");
|
|
41
|
+
__classPrivateFieldSet(this, _CancelablePromise_reject, reject, "f");
|
|
42
|
+
const onResolve = (value) => {
|
|
43
|
+
if (__classPrivateFieldGet(this, _CancelablePromise_isResolved, "f") || __classPrivateFieldGet(this, _CancelablePromise_isRejected, "f") || __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f")) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
__classPrivateFieldSet(this, _CancelablePromise_isResolved, true, "f");
|
|
47
|
+
if (__classPrivateFieldGet(this, _CancelablePromise_resolve, "f"))
|
|
48
|
+
__classPrivateFieldGet(this, _CancelablePromise_resolve, "f").call(this, value);
|
|
49
|
+
};
|
|
50
|
+
const onReject = (reason) => {
|
|
51
|
+
if (__classPrivateFieldGet(this, _CancelablePromise_isResolved, "f") || __classPrivateFieldGet(this, _CancelablePromise_isRejected, "f") || __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f")) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
__classPrivateFieldSet(this, _CancelablePromise_isRejected, true, "f");
|
|
55
|
+
if (__classPrivateFieldGet(this, _CancelablePromise_reject, "f"))
|
|
56
|
+
__classPrivateFieldGet(this, _CancelablePromise_reject, "f").call(this, reason);
|
|
57
|
+
};
|
|
58
|
+
const onCancel = (cancelHandler) => {
|
|
59
|
+
if (__classPrivateFieldGet(this, _CancelablePromise_isResolved, "f") || __classPrivateFieldGet(this, _CancelablePromise_isRejected, "f") || __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f")) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
__classPrivateFieldGet(this, _CancelablePromise_cancelHandlers, "f").push(cancelHandler);
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(onCancel, 'isResolved', {
|
|
65
|
+
get: () => __classPrivateFieldGet(this, _CancelablePromise_isResolved, "f"),
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(onCancel, 'isRejected', {
|
|
68
|
+
get: () => __classPrivateFieldGet(this, _CancelablePromise_isRejected, "f"),
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(onCancel, 'isCancelled', {
|
|
71
|
+
get: () => __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f"),
|
|
72
|
+
});
|
|
73
|
+
return executor(onResolve, onReject, onCancel);
|
|
74
|
+
}), "f");
|
|
75
|
+
}
|
|
76
|
+
get [(_CancelablePromise_isResolved = new WeakMap(), _CancelablePromise_isRejected = new WeakMap(), _CancelablePromise_isCancelled = new WeakMap(), _CancelablePromise_cancelHandlers = new WeakMap(), _CancelablePromise_promise = new WeakMap(), _CancelablePromise_resolve = new WeakMap(), _CancelablePromise_reject = new WeakMap(), Symbol.toStringTag)]() {
|
|
77
|
+
return "Cancellable Promise";
|
|
78
|
+
}
|
|
79
|
+
then(onFulfilled, onRejected) {
|
|
80
|
+
return __classPrivateFieldGet(this, _CancelablePromise_promise, "f").then(onFulfilled, onRejected);
|
|
81
|
+
}
|
|
82
|
+
catch(onRejected) {
|
|
83
|
+
return __classPrivateFieldGet(this, _CancelablePromise_promise, "f").catch(onRejected);
|
|
84
|
+
}
|
|
85
|
+
finally(onFinally) {
|
|
86
|
+
return __classPrivateFieldGet(this, _CancelablePromise_promise, "f").finally(onFinally);
|
|
87
|
+
}
|
|
88
|
+
cancel() {
|
|
89
|
+
if (__classPrivateFieldGet(this, _CancelablePromise_isResolved, "f") || __classPrivateFieldGet(this, _CancelablePromise_isRejected, "f") || __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f")) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
__classPrivateFieldSet(this, _CancelablePromise_isCancelled, true, "f");
|
|
93
|
+
if (__classPrivateFieldGet(this, _CancelablePromise_cancelHandlers, "f").length) {
|
|
94
|
+
try {
|
|
95
|
+
for (const cancelHandler of __classPrivateFieldGet(this, _CancelablePromise_cancelHandlers, "f")) {
|
|
96
|
+
cancelHandler();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
console.warn('Cancellation threw an error', error);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
__classPrivateFieldGet(this, _CancelablePromise_cancelHandlers, "f").length = 0;
|
|
105
|
+
if (__classPrivateFieldGet(this, _CancelablePromise_reject, "f"))
|
|
106
|
+
__classPrivateFieldGet(this, _CancelablePromise_reject, "f").call(this, new CancelError('Request aborted'));
|
|
107
|
+
}
|
|
108
|
+
get isCancelled() {
|
|
109
|
+
return __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
2
|
+
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
|
|
3
|
+
type Headers = Record<string, string>;
|
|
4
|
+
export type OpenAPIConfig = {
|
|
5
|
+
BASE: string;
|
|
6
|
+
VERSION: string;
|
|
7
|
+
WITH_CREDENTIALS: boolean;
|
|
8
|
+
CREDENTIALS: 'include' | 'omit' | 'same-origin';
|
|
9
|
+
TOKEN?: string | Resolver<string> | undefined;
|
|
10
|
+
USERNAME?: string | Resolver<string> | undefined;
|
|
11
|
+
PASSWORD?: string | Resolver<string> | undefined;
|
|
12
|
+
HEADERS?: Headers | Resolver<Headers> | undefined;
|
|
13
|
+
ENCODE_PATH?: ((path: string) => string) | undefined;
|
|
14
|
+
};
|
|
15
|
+
export declare const OpenAPI: OpenAPIConfig;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
2
|
+
import type { ApiResult } from './ApiResult';
|
|
3
|
+
import { CancelablePromise } from './CancelablePromise';
|
|
4
|
+
import type { OnCancel } from './CancelablePromise';
|
|
5
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
6
|
+
export declare const isDefined: <T>(value: T | null | undefined) => value is Exclude<T, null | undefined>;
|
|
7
|
+
export declare const isString: (value: any) => value is string;
|
|
8
|
+
export declare const isStringWithValue: (value: any) => value is string;
|
|
9
|
+
export declare const isBlob: (value: any) => value is Blob;
|
|
10
|
+
export declare const isFormData: (value: any) => value is FormData;
|
|
11
|
+
export declare const base64: (str: string) => string;
|
|
12
|
+
export declare const getQueryString: (params: Record<string, any>) => string;
|
|
13
|
+
export declare const getFormData: (options: ApiRequestOptions) => FormData | undefined;
|
|
14
|
+
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
|
|
15
|
+
export declare const resolve: <T>(options: ApiRequestOptions, resolver?: T | Resolver<T>) => Promise<T | undefined>;
|
|
16
|
+
export declare const getHeaders: (config: OpenAPIConfig, options: ApiRequestOptions) => Promise<Headers>;
|
|
17
|
+
export declare const getRequestBody: (options: ApiRequestOptions) => any;
|
|
18
|
+
export declare const sendRequest: (config: OpenAPIConfig, options: ApiRequestOptions, url: string, body: any, formData: FormData | undefined, headers: Headers, onCancel: OnCancel) => Promise<Response>;
|
|
19
|
+
export declare const getResponseHeader: (response: Response, responseHeader?: string) => string | undefined;
|
|
20
|
+
export declare const getResponseBody: (response: Response) => Promise<any>;
|
|
21
|
+
export declare const catchErrorCodes: (options: ApiRequestOptions, result: ApiResult) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Request method
|
|
24
|
+
* @param config The OpenAPI configuration object
|
|
25
|
+
* @param options The request options from the service
|
|
26
|
+
* @returns CancelablePromise<T>
|
|
27
|
+
* @throws ApiError
|
|
28
|
+
*/
|
|
29
|
+
export declare const request: <T>(config: OpenAPIConfig, options: ApiRequestOptions) => CancelablePromise<T>;
|
|
30
|
+
export {};
|