@aviaryhq/cloudglue-js 0.0.9
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/LICENSE.md +44 -0
- package/README.md +105 -0
- package/dist/client.d.ts +156 -0
- package/dist/client.js +189 -0
- package/dist/generated/Chat.d.ts +416 -0
- package/dist/generated/Chat.js +182 -0
- package/dist/generated/Collections.d.ts +2940 -0
- package/dist/generated/Collections.js +666 -0
- package/dist/generated/Describe.d.ts +7027 -0
- package/dist/generated/Describe.js +159 -0
- package/dist/generated/Extract.d.ts +1168 -0
- package/dist/generated/Extract.js +128 -0
- package/dist/generated/Files.d.ts +735 -0
- package/dist/generated/Files.js +190 -0
- package/dist/generated/common.d.ts +99 -0
- package/dist/generated/common.js +37 -0
- package/dist/generated/index.d.ts +5 -0
- package/dist/generated/index.js +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +18 -0
- package/dist/src/client.d.ts +1550 -0
- package/dist/src/client.js +189 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.js +18 -0
- package/dist/src/types.d.ts +70 -0
- package/dist/src/types.js +2 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js +2 -0
- package/package.json +46 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Elastic License 2.0 (ELv2)
|
|
2
|
+
|
|
3
|
+
**Acceptance**
|
|
4
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
5
|
+
|
|
6
|
+
**Copyright License**
|
|
7
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below.
|
|
8
|
+
|
|
9
|
+
**Limitations**
|
|
10
|
+
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
|
|
11
|
+
|
|
12
|
+
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
|
|
13
|
+
|
|
14
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
15
|
+
|
|
16
|
+
**Patents**
|
|
17
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
18
|
+
|
|
19
|
+
**Notices**
|
|
20
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
21
|
+
|
|
22
|
+
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
23
|
+
|
|
24
|
+
**No Other Rights**
|
|
25
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
26
|
+
|
|
27
|
+
**Termination**
|
|
28
|
+
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
29
|
+
|
|
30
|
+
**No Liability**
|
|
31
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
32
|
+
|
|
33
|
+
**Definitions**
|
|
34
|
+
The *licensor* is the entity offering these terms, and the *software* is the software the licensor makes available under these terms, including any portion of it.
|
|
35
|
+
|
|
36
|
+
*you* refers to the individual or entity agreeing to these terms.
|
|
37
|
+
|
|
38
|
+
*your company* is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. *control* means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
39
|
+
|
|
40
|
+
*your licenses* are all the licenses granted to you for the software under these terms.
|
|
41
|
+
|
|
42
|
+
*use* means anything you do with the software requiring one of your licenses.
|
|
43
|
+
|
|
44
|
+
*trademark* means trademarks, service marks, and similar rights.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# CloudGlue JavaScript SDK
|
|
2
|
+
|
|
3
|
+
Official JavaScript SDK for the CloudGlue API.
|
|
4
|
+
|
|
5
|
+
## 📖 Resources
|
|
6
|
+
|
|
7
|
+
- [CloudGlue API Docs](https://docs.cloudglue.dev)
|
|
8
|
+
- [Terms of Service](https://cloudglue.dev/terms)
|
|
9
|
+
- [Privacy Policy](https://cloudglue.dev/privacy)
|
|
10
|
+
- [Pricing](https://cloudglue.dev/pricing)
|
|
11
|
+
|
|
12
|
+
> By using this SDK, you agree to the [CloudGlue Terms of Service](https://cloudglue.dev/terms) and acknowledge our [Privacy Policy](https://cloudglue.dev/privacy).
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @aviaryhq/cloudglue-js
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { CloudGlue } from '@aviaryhq/cloudglue-js';
|
|
24
|
+
|
|
25
|
+
// Initialize the client
|
|
26
|
+
const client = new CloudGlue({
|
|
27
|
+
apiKey: process.env.CLOUDGLUE_API_KEY
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// List your video files
|
|
31
|
+
const response = await client.files.listFiles({ limit: 10 });
|
|
32
|
+
|
|
33
|
+
// Chat with a collection
|
|
34
|
+
const chatResponse = await client.chat.createCompletion({
|
|
35
|
+
model: 'nimbus-001',
|
|
36
|
+
messages: [
|
|
37
|
+
{ role: 'user', content: 'What are the key points discussed in these videos?' }
|
|
38
|
+
],
|
|
39
|
+
// Assumes collection already exists, otherwise create one first then reference here by collection id
|
|
40
|
+
collections: ['your_collection_id'],
|
|
41
|
+
include_citations: true,
|
|
42
|
+
force_search: true
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
The `CloudGlue` client accepts the following configuration options:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
interface CloudGlueConfig {
|
|
52
|
+
apiKey?: string; // Your API key (can also use CLOUDGLUE_API_KEY env var)
|
|
53
|
+
baseUrl?: string; // Optional custom base URL
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Development
|
|
58
|
+
|
|
59
|
+
### Prerequisites
|
|
60
|
+
- Node.js 16+
|
|
61
|
+
- npm or yarn
|
|
62
|
+
- Git (for spec submodule)
|
|
63
|
+
|
|
64
|
+
### Setup
|
|
65
|
+
|
|
66
|
+
1. Clone the repository:
|
|
67
|
+
```bash
|
|
68
|
+
git clone https://github.com/aviaryhq/cloudglue-js.git
|
|
69
|
+
cd cloudglue-js
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
2. Initialize the spec submodule:
|
|
73
|
+
```bash
|
|
74
|
+
make submodule-init
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
3. Install dependencies:
|
|
78
|
+
```bash
|
|
79
|
+
npm install
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
4. Generate API clients:
|
|
83
|
+
```bash
|
|
84
|
+
npm run generate
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Available Commands
|
|
88
|
+
|
|
89
|
+
- `make submodule-init`: Initialize the OpenAPI spec submodule
|
|
90
|
+
- `make submodule-update`: Update the OpenAPI spec submodule
|
|
91
|
+
- `npm run generate`: Generate API clients from the spec
|
|
92
|
+
- `npm run build`: Build the package
|
|
93
|
+
- `npm run clean`: Clean build artifacts
|
|
94
|
+
- `npm run prepare`: Build the package (used by npm)
|
|
95
|
+
- `npm run watch`: Watch for changes and rebuild automatically (development)
|
|
96
|
+
|
|
97
|
+
### Building
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm run build
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
This will:
|
|
104
|
+
1. Clean the previous build
|
|
105
|
+
2. Compile TypeScript files
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { FilesApi, CollectionsApi, ChatApi, DescribeApi, ExtractApi } from '../generated';
|
|
2
|
+
export declare class CloudGlueError extends Error {
|
|
3
|
+
readonly statusCode?: number | undefined;
|
|
4
|
+
readonly data?: string | undefined;
|
|
5
|
+
readonly headers?: Record<string, any> | undefined;
|
|
6
|
+
constructor(message: string, statusCode?: number | undefined, data?: string | undefined, headers?: Record<string, any> | undefined);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Configuration options for initializing the CloudGlue client
|
|
10
|
+
*/
|
|
11
|
+
export interface CloudGlueConfig {
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
interface ListFilesParams {
|
|
16
|
+
status?: 'pending' | 'processing' | 'ready' | 'completed' | 'failed' | 'not_applicable';
|
|
17
|
+
limit?: number;
|
|
18
|
+
offset?: number;
|
|
19
|
+
order?: 'created_at' | 'filename';
|
|
20
|
+
sort?: 'asc' | 'desc';
|
|
21
|
+
}
|
|
22
|
+
interface UploadFileParams {
|
|
23
|
+
file: globalThis.File;
|
|
24
|
+
metadata?: Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
interface ListCollectionParams {
|
|
27
|
+
limit?: number;
|
|
28
|
+
offset?: number;
|
|
29
|
+
order?: 'name' | 'created_at';
|
|
30
|
+
sort?: 'asc' | 'desc';
|
|
31
|
+
}
|
|
32
|
+
interface CreateCollectionParams {
|
|
33
|
+
name: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
describe_config?: {
|
|
36
|
+
enable_speech?: boolean;
|
|
37
|
+
enable_scene_text?: boolean;
|
|
38
|
+
enable_visual_scene_description?: boolean;
|
|
39
|
+
};
|
|
40
|
+
extract_config?: {
|
|
41
|
+
prompt?: string;
|
|
42
|
+
schema?: Record<string, any>;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
interface ListCollectionVideosParams {
|
|
46
|
+
limit?: number;
|
|
47
|
+
offset?: number;
|
|
48
|
+
status?: 'pending' | 'processing' | 'ready' | 'completed' | 'failed' | 'not_applicable';
|
|
49
|
+
order?: 'added_at' | 'filename';
|
|
50
|
+
sort?: 'asc' | 'desc';
|
|
51
|
+
}
|
|
52
|
+
interface ChatCompletionParams {
|
|
53
|
+
model?: string;
|
|
54
|
+
messages: Array<{
|
|
55
|
+
role: 'system' | 'user' | 'assistant';
|
|
56
|
+
content: string;
|
|
57
|
+
name?: string;
|
|
58
|
+
}>;
|
|
59
|
+
collections: string[];
|
|
60
|
+
filter?: {
|
|
61
|
+
metadata?: Array<{
|
|
62
|
+
path: string;
|
|
63
|
+
operator: 'NotEqual' | 'Equal' | 'LessThan' | 'GreaterThan' | 'In' | 'ContainsAny' | 'ContainsAll';
|
|
64
|
+
valueText?: string;
|
|
65
|
+
valueTextArray?: string[];
|
|
66
|
+
}>;
|
|
67
|
+
};
|
|
68
|
+
force_search?: boolean;
|
|
69
|
+
result_format?: 'text' | 'markdown' | 'json';
|
|
70
|
+
include_citations?: boolean;
|
|
71
|
+
temperature?: number;
|
|
72
|
+
top_p?: number;
|
|
73
|
+
max_tokens?: number;
|
|
74
|
+
}
|
|
75
|
+
declare class EnhancedFilesApi {
|
|
76
|
+
private readonly api;
|
|
77
|
+
constructor(api: typeof FilesApi);
|
|
78
|
+
listFiles(params?: ListFilesParams): Promise<any>;
|
|
79
|
+
uploadFile(params: UploadFileParams): Promise<any>;
|
|
80
|
+
getFile(fileId: string): Promise<any>;
|
|
81
|
+
deleteFile(fileId: string): Promise<any>;
|
|
82
|
+
}
|
|
83
|
+
declare class EnhancedCollectionsApi {
|
|
84
|
+
private readonly api;
|
|
85
|
+
constructor(api: typeof CollectionsApi);
|
|
86
|
+
listCollections(params?: ListCollectionParams): Promise<any>;
|
|
87
|
+
createCollection(params: CreateCollectionParams): Promise<any>;
|
|
88
|
+
getCollection(collectionId: string): Promise<any>;
|
|
89
|
+
deleteCollection(collectionId: string): Promise<any>;
|
|
90
|
+
addVideo(collectionId: string, fileId: string): Promise<any>;
|
|
91
|
+
listVideos(collectionId: string, params?: ListCollectionVideosParams): Promise<any>;
|
|
92
|
+
getVideo(collectionId: string, fileId: string): Promise<any>;
|
|
93
|
+
deleteVideo(collectionId: string, fileId: string): Promise<any>;
|
|
94
|
+
getEntities(collectionId: string, fileId: string, limit?: number, offset?: number): Promise<any>;
|
|
95
|
+
getDescription(collectionId: string, fileId: string, limit?: number, offset?: number): Promise<any>;
|
|
96
|
+
addYouTubeVideo(collectionId: string, url: string, metadata?: Record<string, any>): Promise<any>;
|
|
97
|
+
}
|
|
98
|
+
declare class EnhancedChatApi {
|
|
99
|
+
private readonly api;
|
|
100
|
+
constructor(api: typeof ChatApi);
|
|
101
|
+
createCompletion(params: ChatCompletionParams): Promise<any>;
|
|
102
|
+
}
|
|
103
|
+
declare class EnhancedDescribeApi {
|
|
104
|
+
private readonly api;
|
|
105
|
+
constructor(api: typeof DescribeApi);
|
|
106
|
+
createDescribe(url: string, options?: {
|
|
107
|
+
enable_speech?: boolean;
|
|
108
|
+
enable_scene_text?: boolean;
|
|
109
|
+
enable_visual_scene_description?: boolean;
|
|
110
|
+
}): Promise<any>;
|
|
111
|
+
getDescribe(jobId: string): Promise<any>;
|
|
112
|
+
}
|
|
113
|
+
declare class EnhancedExtractApi {
|
|
114
|
+
private readonly api;
|
|
115
|
+
constructor(api: typeof ExtractApi);
|
|
116
|
+
createExtract(url: string, options?: {
|
|
117
|
+
prompt?: string;
|
|
118
|
+
schema?: Record<string, any>;
|
|
119
|
+
}): Promise<any>;
|
|
120
|
+
getExtract(jobId: string): Promise<any>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Main CloudGlue client class that provides access to all API functionality
|
|
124
|
+
* through enhanced, user-friendly interfaces
|
|
125
|
+
*/
|
|
126
|
+
export declare class CloudGlue {
|
|
127
|
+
private readonly baseUrl;
|
|
128
|
+
private readonly apiKey;
|
|
129
|
+
/**
|
|
130
|
+
* Files API for managing video files
|
|
131
|
+
* Provides methods for uploading, listing, and managing video files
|
|
132
|
+
*/
|
|
133
|
+
readonly files: EnhancedFilesApi;
|
|
134
|
+
/**
|
|
135
|
+
* Collections API for organizing videos into collections
|
|
136
|
+
* Provides methods for creating and managing collections of videos
|
|
137
|
+
*/
|
|
138
|
+
readonly collections: EnhancedCollectionsApi;
|
|
139
|
+
/**
|
|
140
|
+
* Chat API for interacting with videos through natural language
|
|
141
|
+
* Provides methods for querying and getting responses about video content
|
|
142
|
+
*/
|
|
143
|
+
readonly chat: EnhancedChatApi;
|
|
144
|
+
/**
|
|
145
|
+
* Describe API for generating rich descriptions of videos
|
|
146
|
+
* Provides methods for getting detailed descriptions of video content
|
|
147
|
+
*/
|
|
148
|
+
readonly describe: EnhancedDescribeApi;
|
|
149
|
+
/**
|
|
150
|
+
* Extract API for extracting structured data from videos
|
|
151
|
+
* Provides methods for extracting specific information from video content
|
|
152
|
+
*/
|
|
153
|
+
readonly extract: EnhancedExtractApi;
|
|
154
|
+
constructor(config?: CloudGlueConfig);
|
|
155
|
+
}
|
|
156
|
+
export {};
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloudGlue = exports.CloudGlueError = void 0;
|
|
4
|
+
const generated_1 = require("../generated");
|
|
5
|
+
class CloudGlueError extends Error {
|
|
6
|
+
constructor(message, statusCode, data, headers) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.data = data;
|
|
10
|
+
this.headers = headers;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.CloudGlueError = CloudGlueError;
|
|
14
|
+
// Enhanced API client classes
|
|
15
|
+
class EnhancedFilesApi {
|
|
16
|
+
constructor(api) {
|
|
17
|
+
this.api = api;
|
|
18
|
+
}
|
|
19
|
+
async listFiles(params = {}) {
|
|
20
|
+
return this.api.listFiles({ queries: params });
|
|
21
|
+
}
|
|
22
|
+
async uploadFile(params) {
|
|
23
|
+
// File uploads require special handling for multipart/form-data that the generated Zodios client doesn't handle automatically.
|
|
24
|
+
// We need to:
|
|
25
|
+
// 1. Create a FormData object and append the file with the correct field name
|
|
26
|
+
// 2. JSON stringify the metadata if present
|
|
27
|
+
// 3. Set the correct Content-Type header
|
|
28
|
+
// This is why we use axios directly instead of the generated client method.
|
|
29
|
+
const formData = new FormData();
|
|
30
|
+
formData.append('file', params.file);
|
|
31
|
+
// Add metadata if provided
|
|
32
|
+
if (params.metadata) {
|
|
33
|
+
formData.append('metadata', JSON.stringify(params.metadata));
|
|
34
|
+
}
|
|
35
|
+
// Use axios directly to bypass Zodios validation
|
|
36
|
+
return this.api.axios({
|
|
37
|
+
method: 'post',
|
|
38
|
+
url: '/files',
|
|
39
|
+
data: formData,
|
|
40
|
+
headers: {
|
|
41
|
+
'Content-Type': 'multipart/form-data'
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async getFile(fileId) {
|
|
46
|
+
return this.api.getFile({ params: { file_id: fileId } });
|
|
47
|
+
}
|
|
48
|
+
async deleteFile(fileId) {
|
|
49
|
+
return this.api.deleteFile({ params: { file_id: fileId } }, { params: { file_id: fileId } });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class EnhancedCollectionsApi {
|
|
53
|
+
constructor(api) {
|
|
54
|
+
this.api = api;
|
|
55
|
+
}
|
|
56
|
+
async listCollections(params = {}) {
|
|
57
|
+
return this.api.listCollections({ queries: params });
|
|
58
|
+
}
|
|
59
|
+
async createCollection(params) {
|
|
60
|
+
return this.api.createCollection(params);
|
|
61
|
+
}
|
|
62
|
+
async getCollection(collectionId) {
|
|
63
|
+
return this.api.getCollection({ params: { collection_id: collectionId } });
|
|
64
|
+
}
|
|
65
|
+
async deleteCollection(collectionId) {
|
|
66
|
+
return this.api.deleteCollection({ params: { collection_id: collectionId } }, { params: { collection_id: collectionId } });
|
|
67
|
+
}
|
|
68
|
+
async addVideo(collectionId, fileId) {
|
|
69
|
+
return this.api.addVideo({ file_id: fileId }, { params: { collection_id: collectionId } });
|
|
70
|
+
}
|
|
71
|
+
async listVideos(collectionId, params = {}) {
|
|
72
|
+
return this.api.listVideos({
|
|
73
|
+
params: { collection_id: collectionId },
|
|
74
|
+
queries: params
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async getVideo(collectionId, fileId) {
|
|
78
|
+
return this.api.getVideo({
|
|
79
|
+
params: { collection_id: collectionId, file_id: fileId }
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async deleteVideo(collectionId, fileId) {
|
|
83
|
+
return this.api.deleteVideo({
|
|
84
|
+
params: { collection_id: collectionId, file_id: fileId }
|
|
85
|
+
}, { params: { collection_id: collectionId, file_id: fileId } });
|
|
86
|
+
}
|
|
87
|
+
async getEntities(collectionId, fileId, limit, offset) {
|
|
88
|
+
return this.api.getEntities({
|
|
89
|
+
params: { collection_id: collectionId, file_id: fileId },
|
|
90
|
+
queries: { limit, offset }
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async getDescription(collectionId, fileId, limit, offset) {
|
|
94
|
+
return this.api.getDescription({
|
|
95
|
+
params: { collection_id: collectionId, file_id: fileId },
|
|
96
|
+
queries: { limit, offset }
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async addYouTubeVideo(collectionId, url, metadata) {
|
|
100
|
+
return this.api.addYouTubeVideo({ url, metadata }, { params: { collection_id: collectionId } });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
class EnhancedChatApi {
|
|
104
|
+
constructor(api) {
|
|
105
|
+
this.api = api;
|
|
106
|
+
}
|
|
107
|
+
async createCompletion(params) {
|
|
108
|
+
return this.api.createCompletion({
|
|
109
|
+
model: params.model || 'nimbus-001',
|
|
110
|
+
...params
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
class EnhancedDescribeApi {
|
|
115
|
+
constructor(api) {
|
|
116
|
+
this.api = api;
|
|
117
|
+
}
|
|
118
|
+
async createDescribe(url, options = {}) {
|
|
119
|
+
return this.api.createDescribe({
|
|
120
|
+
url,
|
|
121
|
+
...options
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async getDescribe(jobId) {
|
|
125
|
+
return this.api.getDescribe({ params: { job_id: jobId } });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
class EnhancedExtractApi {
|
|
129
|
+
constructor(api) {
|
|
130
|
+
this.api = api;
|
|
131
|
+
}
|
|
132
|
+
async createExtract(url, options) {
|
|
133
|
+
return this.api.createExtract({
|
|
134
|
+
url,
|
|
135
|
+
...options
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async getExtract(jobId) {
|
|
139
|
+
return this.api.getExtract({ params: { job_id: jobId } });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Main CloudGlue client class that provides access to all API functionality
|
|
144
|
+
* through enhanced, user-friendly interfaces
|
|
145
|
+
*/
|
|
146
|
+
class CloudGlue {
|
|
147
|
+
constructor(config = {}) {
|
|
148
|
+
this.apiKey = config.apiKey || process.env.CLOUDGLUE_API_KEY || '';
|
|
149
|
+
this.baseUrl = config.baseUrl || 'https://api.cloudglue.dev/v1';
|
|
150
|
+
if (!this.apiKey) {
|
|
151
|
+
throw new Error('API key is required. Please provide an API key via constructor or CLOUDGLUE_API_KEY environment variable.');
|
|
152
|
+
}
|
|
153
|
+
const axiosConfig = {
|
|
154
|
+
headers: {
|
|
155
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
// Initialize all API clients with the configured base URL and auth
|
|
159
|
+
const filesApi = generated_1.FilesApi;
|
|
160
|
+
const collectionsApi = generated_1.CollectionsApi;
|
|
161
|
+
const chatApi = generated_1.ChatApi;
|
|
162
|
+
const describeApi = generated_1.DescribeApi;
|
|
163
|
+
const extractApi = generated_1.ExtractApi;
|
|
164
|
+
// Configure base URL and axios config for all clients
|
|
165
|
+
[filesApi, collectionsApi, chatApi, describeApi, extractApi].forEach(client => {
|
|
166
|
+
client.axios.defaults.baseURL = this.baseUrl;
|
|
167
|
+
client.axios.interceptors.response.use((response) => {
|
|
168
|
+
return response;
|
|
169
|
+
}, (error) => {
|
|
170
|
+
if (error.response) {
|
|
171
|
+
// The request was made and the server responded with a status code
|
|
172
|
+
// that falls out of the range of 2xx
|
|
173
|
+
const data = error.response.data;
|
|
174
|
+
return Promise.reject(new CloudGlueError(data.error, error.response.status, error.config.data, error.response.headers));
|
|
175
|
+
}
|
|
176
|
+
// Something happened in setting up the request that triggered an Error
|
|
177
|
+
return Promise.reject(new CloudGlueError(error.message, error.statusCode ?? 500, error.data, error.headers));
|
|
178
|
+
});
|
|
179
|
+
Object.assign(client.axios.defaults, axiosConfig);
|
|
180
|
+
});
|
|
181
|
+
// Create enhanced API clients
|
|
182
|
+
this.files = new EnhancedFilesApi(filesApi);
|
|
183
|
+
this.collections = new EnhancedCollectionsApi(collectionsApi);
|
|
184
|
+
this.chat = new EnhancedChatApi(chatApi);
|
|
185
|
+
this.describe = new EnhancedDescribeApi(describeApi);
|
|
186
|
+
this.extract = new EnhancedExtractApi(extractApi);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.CloudGlue = CloudGlue;
|