@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.
@@ -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;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Main CloudGlue client class and configuration types
3
+ */
4
+ export { CloudGlue, type CloudGlueConfig, type CloudGlueError } from './client';
5
+ /**
6
+ * Generated API clients for advanced usage
7
+ * These provide direct access to the underlying API endpoints
8
+ */
9
+ export { FilesApi, CollectionsApi, ChatApi, DescribeApi, ExtractApi } from '../generated';
10
+ /**
11
+ * Common type definitions used throughout the SDK
12
+ */
13
+ export type { File, Collection, CollectionFile, CollectionFileList, ChatMessage, ChatCompletionResponse, Describe, Extract, DescriptionSegment, CollectionVideoDescription, EntitySegment, CollectionVideoEntities, NewCollectionParams, } from './types';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtractApi = exports.DescribeApi = exports.ChatApi = exports.CollectionsApi = exports.FilesApi = exports.CloudGlue = void 0;
4
+ /**
5
+ * Main CloudGlue client class and configuration types
6
+ */
7
+ var client_1 = require("./client");
8
+ Object.defineProperty(exports, "CloudGlue", { enumerable: true, get: function () { return client_1.CloudGlue; } });
9
+ /**
10
+ * Generated API clients for advanced usage
11
+ * These provide direct access to the underlying API endpoints
12
+ */
13
+ var generated_1 = require("../generated");
14
+ Object.defineProperty(exports, "FilesApi", { enumerable: true, get: function () { return generated_1.FilesApi; } });
15
+ Object.defineProperty(exports, "CollectionsApi", { enumerable: true, get: function () { return generated_1.CollectionsApi; } });
16
+ Object.defineProperty(exports, "ChatApi", { enumerable: true, get: function () { return generated_1.ChatApi; } });
17
+ Object.defineProperty(exports, "DescribeApi", { enumerable: true, get: function () { return generated_1.DescribeApi; } });
18
+ Object.defineProperty(exports, "ExtractApi", { enumerable: true, get: function () { return generated_1.ExtractApi; } });
@@ -0,0 +1,70 @@
1
+ import type { z } from 'zod';
2
+ import { schemas as collectionsSchemas } from '../generated/Collections';
3
+ import { schemas as chatSchemas } from '../generated/Chat';
4
+ import { schemas as describeSchemas } from '../generated/Describe';
5
+ import { schemas as extractSchemas } from '../generated/Extract';
6
+ /**
7
+ * Represents a video file in the CloudGlue system
8
+ * Contains metadata about the file including its status, size, and video information
9
+ */
10
+ export type { File } from '../generated/common';
11
+ /**
12
+ * Parameters for creating a new collection
13
+ */
14
+ export type NewCollectionParams = z.infer<typeof collectionsSchemas.NewCollection>;
15
+ /**
16
+ * Represents a collection of videos
17
+ * Contains metadata about the collection and its configuration
18
+ */
19
+ export type Collection = z.infer<typeof collectionsSchemas.Collection>;
20
+ /**
21
+ * Represents a video file within a collection
22
+ * Contains metadata about the file and its processing status within the collection
23
+ */
24
+ export type CollectionFile = z.infer<typeof collectionsSchemas.CollectionFile>;
25
+ /**
26
+ * Represents a paginated list of files within a collection
27
+ */
28
+ export type CollectionFileList = z.infer<typeof collectionsSchemas.CollectionFileList>;
29
+ /**
30
+ * Represents a segment of video description containing speech, text, and visual information
31
+ * This is inferred from the FileDescription schema's segment_docs array type
32
+ */
33
+ export type DescriptionSegment = NonNullable<z.infer<typeof collectionsSchemas.FileDescription>['segment_docs']>[number];
34
+ /**
35
+ * Represents the full description response for a video in a collection
36
+ */
37
+ export type CollectionVideoDescription = z.infer<typeof collectionsSchemas.FileDescription>;
38
+ /**
39
+ * Represents a segment of video with extracted entities
40
+ * This is inferred from the FileEntities schema's segment_entities array type
41
+ */
42
+ export type EntitySegment = NonNullable<z.infer<typeof collectionsSchemas.FileEntities>['segment_entities']>[number];
43
+ /**
44
+ * Represents the full entities response for a video in a collection
45
+ */
46
+ export type CollectionVideoEntities = z.infer<typeof collectionsSchemas.FileEntities>;
47
+ /**
48
+ * Represents a message in a chat conversation
49
+ * Used for interacting with videos through natural language
50
+ */
51
+ export type ChatMessage = {
52
+ role: "system" | "user" | "assistant";
53
+ content: string;
54
+ name?: string;
55
+ };
56
+ /**
57
+ * Represents the response from a chat completion request
58
+ * Contains the model's response and any relevant citations from videos
59
+ */
60
+ export type ChatCompletionResponse = z.infer<typeof chatSchemas.ChatCompletionResponse>;
61
+ /**
62
+ * Represents the result of a video description request
63
+ * Contains detailed information about the video content
64
+ */
65
+ export type Describe = z.infer<typeof describeSchemas.Describe>;
66
+ /**
67
+ * Represents the result of a video information extraction request
68
+ * Contains structured data extracted from the video
69
+ */
70
+ export type Extract = z.infer<typeof extractSchemas.Extract>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,70 @@
1
+ import type { z } from 'zod';
2
+ import { schemas as collectionsSchemas } from '../generated/Collections';
3
+ import { schemas as chatSchemas } from '../generated/Chat';
4
+ import { schemas as describeSchemas } from '../generated/Describe';
5
+ import { schemas as extractSchemas } from '../generated/Extract';
6
+ /**
7
+ * Represents a video file in the CloudGlue system
8
+ * Contains metadata about the file including its status, size, and video information
9
+ */
10
+ export type { File } from '../generated/common';
11
+ /**
12
+ * Parameters for creating a new collection
13
+ */
14
+ export type NewCollectionParams = z.infer<typeof collectionsSchemas.NewCollection>;
15
+ /**
16
+ * Represents a collection of videos
17
+ * Contains metadata about the collection and its configuration
18
+ */
19
+ export type Collection = z.infer<typeof collectionsSchemas.Collection>;
20
+ /**
21
+ * Represents a video file within a collection
22
+ * Contains metadata about the file and its processing status within the collection
23
+ */
24
+ export type CollectionFile = z.infer<typeof collectionsSchemas.CollectionFile>;
25
+ /**
26
+ * Represents a paginated list of files within a collection
27
+ */
28
+ export type CollectionFileList = z.infer<typeof collectionsSchemas.CollectionFileList>;
29
+ /**
30
+ * Represents a segment of video description containing speech, text, and visual information
31
+ * This is inferred from the FileDescription schema's segment_docs array type
32
+ */
33
+ export type DescriptionSegment = NonNullable<z.infer<typeof collectionsSchemas.FileDescription>['segment_docs']>[number];
34
+ /**
35
+ * Represents the full description response for a video in a collection
36
+ */
37
+ export type CollectionVideoDescription = z.infer<typeof collectionsSchemas.FileDescription>;
38
+ /**
39
+ * Represents a segment of video with extracted entities
40
+ * This is inferred from the FileEntities schema's segment_entities array type
41
+ */
42
+ export type EntitySegment = NonNullable<z.infer<typeof collectionsSchemas.FileEntities>['segment_entities']>[number];
43
+ /**
44
+ * Represents the full entities response for a video in a collection
45
+ */
46
+ export type CollectionVideoEntities = z.infer<typeof collectionsSchemas.FileEntities>;
47
+ /**
48
+ * Represents a message in a chat conversation
49
+ * Used for interacting with videos through natural language
50
+ */
51
+ export type ChatMessage = {
52
+ role: "system" | "user" | "assistant";
53
+ content: string;
54
+ name?: string;
55
+ };
56
+ /**
57
+ * Represents the response from a chat completion request
58
+ * Contains the model's response and any relevant citations from videos
59
+ */
60
+ export type ChatCompletionResponse = z.infer<typeof chatSchemas.ChatCompletionResponse>;
61
+ /**
62
+ * Represents the result of a video description request
63
+ * Contains detailed information about the video content
64
+ */
65
+ export type Describe = z.infer<typeof describeSchemas.Describe>;
66
+ /**
67
+ * Represents the result of a video information extraction request
68
+ * Contains structured data extracted from the video
69
+ */
70
+ export type Extract = z.infer<typeof extractSchemas.Extract>;
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@aviaryhq/cloudglue-js",
3
+ "version": "0.0.9",
4
+ "description": "CloudGlue API client for Node.js",
5
+ "main": "dist/src/index.js",
6
+ "types": "dist/src/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "clean": "rimraf dist",
12
+ "generate": "openapi-zod-client spec/spec/openapi.json --group-strategy=tag-file -o generated --export-schemas=true --export-types=true --base-url=https://api.cloudglue.dev/v1 --strict-objects && sed -i '' 's/z.instanceof(File)/z.instanceof(globalThis.File)/' generated/Files.ts",
13
+ "build": "tsc",
14
+ "watch": "tsc --watch",
15
+ "prepare": "npm run build"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/aviaryhq/cloudglue-js.git"
20
+ },
21
+ "keywords": [
22
+ "cloudglue",
23
+ "api",
24
+ "sdk"
25
+ ],
26
+ "author": "Aviary Inc.",
27
+ "license": "Elastic-2.0",
28
+ "bugs": {
29
+ "url": "https://github.com/aviaryhq/cloudglue-js/issues"
30
+ },
31
+ "homepage": "https://github.com/aviaryhq/cloudglue-js#readme",
32
+ "dependencies": {
33
+ "@zodios/core": "^10.0.0",
34
+ "axios": "^1.6.7",
35
+ "zod": "^3.22.4"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^20.0.0",
39
+ "openapi-zod-client": "^1.18.3",
40
+ "rimraf": "^5.0.0",
41
+ "typescript": "^5.3.3"
42
+ },
43
+ "peerDependencies": {
44
+ "@zodios/core": "^10.0.0"
45
+ }
46
+ }