@juggernautlabs/cloud 0.0.1
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 +21 -0
- package/build/CloudDatabaseManager.d.ts +15 -0
- package/build/CloudDatabaseManager.js +112 -0
- package/build/CloudResourceAPI.d.ts +22 -0
- package/build/CloudResourceAPI.js +357 -0
- package/build/index.d.ts +9 -0
- package/build/index.js +87 -0
- package/build/min.d.ts +9 -0
- package/build/min.js +24 -0
- package/build/poller.d.ts +22 -0
- package/build/poller.js +66 -0
- package/build/types.d.ts +22 -0
- package/build/types.js +2 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Juggernaut Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class DatabaseSchema {
|
|
2
|
+
schemaId: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
constructor(schemaId: string, name?: string);
|
|
5
|
+
getRecord(id: string): Record<string, any>;
|
|
6
|
+
query(queryString: string, parameters?: Record<string, any>): Promise<any>;
|
|
7
|
+
insert(record: Record<string, any>): Promise<any>;
|
|
8
|
+
insertMany(data: Record<string, any>[]): Promise<any>;
|
|
9
|
+
update(id: string, data: Record<string, any>): Promise<any>;
|
|
10
|
+
updateMany(query: Record<string, any>, data: Record<string, any>): Promise<any>;
|
|
11
|
+
delete(id: string): Promise<any>;
|
|
12
|
+
bulkDelete(query: string): Promise<any>;
|
|
13
|
+
count(query: string): Promise<any>;
|
|
14
|
+
exists(query: string): Promise<any>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DatabaseSchema = void 0;
|
|
7
|
+
const CloudResourceAPI_1 = __importDefault(require("./CloudResourceAPI"));
|
|
8
|
+
class CloudDatabaseManager {
|
|
9
|
+
static async handleDatabaseOperation(schema, operation, data = {}) {
|
|
10
|
+
if (!schema) {
|
|
11
|
+
throw new Error('Schema or database connection is not provided');
|
|
12
|
+
}
|
|
13
|
+
const request = {
|
|
14
|
+
schema: schema,
|
|
15
|
+
data
|
|
16
|
+
};
|
|
17
|
+
return CloudResourceAPI_1.default.executeDatabaseOperation(operation, request);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
class DatabaseSchema {
|
|
21
|
+
constructor(schemaId, name) {
|
|
22
|
+
this.schemaId = schemaId;
|
|
23
|
+
this.name = name;
|
|
24
|
+
}
|
|
25
|
+
getRecord(id) {
|
|
26
|
+
if (!id) {
|
|
27
|
+
throw new Error('Record ID is required to fetch a record.');
|
|
28
|
+
}
|
|
29
|
+
return CloudDatabaseManager.handleDatabaseOperation(this.schemaId, 'record', {
|
|
30
|
+
id
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
query(queryString, parameters) {
|
|
34
|
+
if (!queryString) {
|
|
35
|
+
throw new Error('Query string is required to perform a query.');
|
|
36
|
+
}
|
|
37
|
+
return CloudDatabaseManager.handleDatabaseOperation(this.schemaId, 'query', {
|
|
38
|
+
query: queryString
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
insert(record) {
|
|
42
|
+
if (!record || typeof record !== 'object') {
|
|
43
|
+
throw new Error('Valid record data is required to insert a record.');
|
|
44
|
+
}
|
|
45
|
+
return CloudDatabaseManager.handleDatabaseOperation(this.schemaId, 'insert', record);
|
|
46
|
+
}
|
|
47
|
+
insertMany(data) {
|
|
48
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
49
|
+
throw new Error('An array of record data is required to insert multiple records.');
|
|
50
|
+
}
|
|
51
|
+
return CloudDatabaseManager.handleDatabaseOperation(this.schemaId, 'bulk:insert', {
|
|
52
|
+
data
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
update(id, data) {
|
|
56
|
+
if (!id) {
|
|
57
|
+
throw new Error('Record ID is required to update a record.');
|
|
58
|
+
}
|
|
59
|
+
if (!data || typeof data !== 'object') {
|
|
60
|
+
throw new Error('Valid record data is required to update a record.');
|
|
61
|
+
}
|
|
62
|
+
return CloudDatabaseManager.handleDatabaseOperation(this.schemaId, 'update', {
|
|
63
|
+
id,
|
|
64
|
+
data
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
updateMany(query, data) {
|
|
68
|
+
if (!query || typeof query !== 'object') {
|
|
69
|
+
throw new Error('Valid query object is required to bulk update records.');
|
|
70
|
+
}
|
|
71
|
+
if (!data || typeof data !== 'object') {
|
|
72
|
+
throw new Error('Valid record data is required to bulk update records.');
|
|
73
|
+
}
|
|
74
|
+
return CloudDatabaseManager.handleDatabaseOperation(this.schemaId, 'bulk:update', {
|
|
75
|
+
query,
|
|
76
|
+
data
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
delete(id) {
|
|
80
|
+
if (!id) {
|
|
81
|
+
throw new Error('Record ID is required to delete a record.');
|
|
82
|
+
}
|
|
83
|
+
return CloudDatabaseManager.handleDatabaseOperation(this.schemaId, 'delete', {
|
|
84
|
+
id
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
bulkDelete(query) {
|
|
88
|
+
if (!query) {
|
|
89
|
+
throw new Error('Query string is required to bulk delete records.');
|
|
90
|
+
}
|
|
91
|
+
return CloudDatabaseManager.handleDatabaseOperation(this.schemaId, 'bulk:delete', {
|
|
92
|
+
query
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
count(query) {
|
|
96
|
+
if (!query) {
|
|
97
|
+
throw new Error('Query string is required to count records.');
|
|
98
|
+
}
|
|
99
|
+
return CloudDatabaseManager.handleDatabaseOperation(this.schemaId, 'count', {
|
|
100
|
+
query
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
exists(query) {
|
|
104
|
+
if (!query) {
|
|
105
|
+
throw new Error('Query string is required to check existence of records.');
|
|
106
|
+
}
|
|
107
|
+
return CloudDatabaseManager.handleDatabaseOperation(this.schemaId, 'exists', {
|
|
108
|
+
query
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.DatabaseSchema = DatabaseSchema;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare const AuthKey: unique symbol;
|
|
2
|
+
export default class CloudResourceManager {
|
|
3
|
+
static [AuthKey]: {};
|
|
4
|
+
static init(client: string, secret: string): void;
|
|
5
|
+
static uploadProcess(processJSON: Record<string, any>): Promise<any>;
|
|
6
|
+
static executePlugin(pluginId: string, command: string, scope: string, pluginArguments: Record<string, any>): Promise<void>;
|
|
7
|
+
static runProcess(processId: string, inputs: Record<string, any>, metadata: Record<string, any>): Promise<any>;
|
|
8
|
+
static runProcessViaAccessPoint(processId: string, inputs: Record<string, any>, accessPoint: string, metadata: Record<string, any>): Promise<any>;
|
|
9
|
+
static scheduleProcess(processId: string, schedule: Record<string, any>): Promise<any>;
|
|
10
|
+
static getPromptContent(promptId: string): Promise<any>;
|
|
11
|
+
static getReport(reportId: string): Promise<any>;
|
|
12
|
+
static createReport(schemaId: string, reportData: Record<string, any>): Promise<any>;
|
|
13
|
+
static getProcessJobEvents(referenceId: string): Promise<any>;
|
|
14
|
+
static getProcessJobEventsViaAccessPoint(referenceId: string, accessPoint: string): Promise<any>;
|
|
15
|
+
static getProcessJobResults(jobId: string): Promise<any>;
|
|
16
|
+
static getProcessJobResultsViaAccessPoint(jobId: string, accessPoint: string): Promise<any>;
|
|
17
|
+
static getJobIdByReferenceId(referenceId: string): Promise<any>;
|
|
18
|
+
static getJobResultsByReferenceId(referenceId: string): Promise<any>;
|
|
19
|
+
static executeDatabaseOperation(operation: string, request: Record<string, any>): Promise<any>;
|
|
20
|
+
static getJobFile(jobId: string, fileType: string, fileId: string): Promise<ReadableStream<Uint8Array<ArrayBuffer>>>;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const CloudRoutes = {
|
|
4
|
+
process: {
|
|
5
|
+
upload: '/api/resource/process/upload',
|
|
6
|
+
run: '/api/resource/process/{{id}}/run',
|
|
7
|
+
runViaAccessPoint: '/api/resource/process/public/{{id}}/run', // Handled differently
|
|
8
|
+
events: '/api/resource/process/events/{{referenceId}}',
|
|
9
|
+
eventsViaAccessPoint: '/api/resource/process/public/events/{{referenceId}}',
|
|
10
|
+
schedule: '/api/resource/process/{{id}}/schedule/create',
|
|
11
|
+
deleteSchedule: '/api/resource/process/{{id}}/schedule/delete',
|
|
12
|
+
},
|
|
13
|
+
job: {
|
|
14
|
+
results: '/api/resource/job/{{id}}/results',
|
|
15
|
+
resultsViaAccessPoint: '/api/resource/job/public/{{id}}/results',
|
|
16
|
+
file: '/api/resource/job/{{id}}/file/{{fileType}}/{{fileId}}',
|
|
17
|
+
getJobIdByReferenceId: '/api/resource/job/reference/{{referenceId}}/id',
|
|
18
|
+
},
|
|
19
|
+
plugin: {
|
|
20
|
+
content: '/api/resource/plugin/{{id}}/content',
|
|
21
|
+
},
|
|
22
|
+
prompt: {
|
|
23
|
+
upload: '/api/resource/prompt/upload',
|
|
24
|
+
getContent: '/api/resource/prompt/{{id}}/content',
|
|
25
|
+
list: '/api/resource/prompt/list',
|
|
26
|
+
delete: '/api/resource/prompt/delete',
|
|
27
|
+
},
|
|
28
|
+
integrations: {
|
|
29
|
+
webSearch: '/api/integrations/web/search',
|
|
30
|
+
webScrape: '/api/integrations/web/scrape',
|
|
31
|
+
database: '/api/integrations/database',
|
|
32
|
+
},
|
|
33
|
+
reporting: {
|
|
34
|
+
getReport: '/api/resource/schema/report/{{id}}',
|
|
35
|
+
createReport: '/api/resource/schema/report/{{schemaId}}',
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const BasePath = 'https://core.juggernautlabs.ai';
|
|
39
|
+
const buildPath = (route, variables) => {
|
|
40
|
+
if (route.includes('{{') && route.includes('}}') && variables !== undefined) {
|
|
41
|
+
let formattedRoute = route;
|
|
42
|
+
for (const key in variables) {
|
|
43
|
+
formattedRoute = formattedRoute.replace(`{{${key}}}`, variables[key]);
|
|
44
|
+
}
|
|
45
|
+
return `${BasePath}${formattedRoute}`;
|
|
46
|
+
}
|
|
47
|
+
return `${BasePath}${route}`;
|
|
48
|
+
};
|
|
49
|
+
const handleResponse = async (response) => {
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
const errorContent = await response.text();
|
|
52
|
+
console.error('Error Response Content:', errorContent);
|
|
53
|
+
//Error for USER to see
|
|
54
|
+
const error = new Error(`Juggernaut SDK Error: ${response.status} ${response.statusText}`);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
return response.json();
|
|
58
|
+
};
|
|
59
|
+
const AuthKey = Symbol('AuthKey');
|
|
60
|
+
class CloudResourceManager {
|
|
61
|
+
static init(client, secret) {
|
|
62
|
+
if (secret && client) {
|
|
63
|
+
this[AuthKey] = {
|
|
64
|
+
'authorization': `Bearer ${secret}`,
|
|
65
|
+
'client-key': client
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
console.warn('CloudResourceManager initialization missing client or secret key.');
|
|
70
|
+
}
|
|
71
|
+
if (Object.keys(this[AuthKey]).length === 0) {
|
|
72
|
+
console.warn('No cloud authentication provided, some features may not work as expected.');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
static async uploadProcess(processJSON) {
|
|
76
|
+
const response = await fetch(buildPath(CloudRoutes.process.upload), {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/json',
|
|
80
|
+
...this[AuthKey]
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify(processJSON)
|
|
83
|
+
});
|
|
84
|
+
return handleResponse(response);
|
|
85
|
+
}
|
|
86
|
+
static async executePlugin(pluginId, command, scope, pluginArguments) {
|
|
87
|
+
// const response = await fetch(buildPath(
|
|
88
|
+
// CloudRoutes.plugin.execute,
|
|
89
|
+
// {id: pluginId}
|
|
90
|
+
// ), {
|
|
91
|
+
// method: 'POST',
|
|
92
|
+
// headers: {
|
|
93
|
+
// 'Content-Type': 'application/json',
|
|
94
|
+
//...this[AuthKey]
|
|
95
|
+
// },
|
|
96
|
+
// body: JSON.stringify({command, data: pluginArguments, scope})
|
|
97
|
+
// });
|
|
98
|
+
// const { data, message, status } = await response.json();
|
|
99
|
+
// console.log('Plugin Results:', data);
|
|
100
|
+
// return data;
|
|
101
|
+
}
|
|
102
|
+
static async runProcess(processId, inputs, metadata) {
|
|
103
|
+
try {
|
|
104
|
+
const response = await fetch(buildPath(CloudRoutes.process.run, { id: processId }), {
|
|
105
|
+
method: 'POST',
|
|
106
|
+
headers: {
|
|
107
|
+
//'Content-Type': 'application/json',
|
|
108
|
+
...this[AuthKey]
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify({ inputs, metadata })
|
|
111
|
+
});
|
|
112
|
+
if (!response.ok) {
|
|
113
|
+
const errorContent = await response.text();
|
|
114
|
+
console.error('Error Response Content:', errorContent);
|
|
115
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
116
|
+
}
|
|
117
|
+
const { data, message, status } = await response.json();
|
|
118
|
+
return data;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.error('Error running process:', error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
static async runProcessViaAccessPoint(processId, inputs, accessPoint, metadata) {
|
|
126
|
+
const response = await fetch(buildPath(CloudRoutes.process.runViaAccessPoint, { id: processId }), {
|
|
127
|
+
method: 'POST',
|
|
128
|
+
headers: {
|
|
129
|
+
'Content-Type': 'application/json',
|
|
130
|
+
'access-point': accessPoint,
|
|
131
|
+
// No auth headers for public access point
|
|
132
|
+
},
|
|
133
|
+
body: JSON.stringify({ inputs, metadata })
|
|
134
|
+
});
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
const errorContent = await response.text();
|
|
137
|
+
console.error('Error Response Content:', errorContent);
|
|
138
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
139
|
+
}
|
|
140
|
+
const { data, message, status } = await response.json();
|
|
141
|
+
return data;
|
|
142
|
+
}
|
|
143
|
+
static async scheduleProcess(processId, schedule) {
|
|
144
|
+
const response = await fetch(buildPath(CloudRoutes.process.schedule, { id: processId }), {
|
|
145
|
+
method: 'POST',
|
|
146
|
+
headers: {
|
|
147
|
+
'Content-Type': 'application/json',
|
|
148
|
+
...this[AuthKey]
|
|
149
|
+
},
|
|
150
|
+
body: JSON.stringify({ schedule: schedule })
|
|
151
|
+
});
|
|
152
|
+
if (!response.ok) {
|
|
153
|
+
const errorContent = await response.text();
|
|
154
|
+
console.error('Error Response Content:', errorContent);
|
|
155
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
156
|
+
}
|
|
157
|
+
const { data, message, status } = await response.json();
|
|
158
|
+
return data;
|
|
159
|
+
}
|
|
160
|
+
static async getPromptContent(promptId) {
|
|
161
|
+
try {
|
|
162
|
+
const response = await fetch(buildPath(CloudRoutes.prompt.getContent, { id: promptId }), {
|
|
163
|
+
method: 'GET',
|
|
164
|
+
headers: {
|
|
165
|
+
'Content-Type': 'application/json',
|
|
166
|
+
...this[AuthKey]
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
if (!response.ok) {
|
|
170
|
+
const errorContent = await response.text();
|
|
171
|
+
console.error('Error Response Content:', errorContent);
|
|
172
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
173
|
+
}
|
|
174
|
+
const { data, message, status } = await response.json();
|
|
175
|
+
return data;
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
console.error('Error fetching prompt content:', error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
static async getReport(reportId) {
|
|
182
|
+
const response = await fetch(buildPath(CloudRoutes.reporting.getReport, { id: reportId }), {
|
|
183
|
+
method: 'GET',
|
|
184
|
+
headers: {
|
|
185
|
+
'Content-Type': 'application/json',
|
|
186
|
+
...this[AuthKey]
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
const { data, message, status } = await response.json();
|
|
190
|
+
return data;
|
|
191
|
+
}
|
|
192
|
+
static async createReport(schemaId, reportData) {
|
|
193
|
+
const response = await fetch(buildPath(CloudRoutes.reporting.createReport, { schemaId }), {
|
|
194
|
+
method: 'POST',
|
|
195
|
+
headers: {
|
|
196
|
+
'Content-Type': 'application/json',
|
|
197
|
+
...this[AuthKey]
|
|
198
|
+
},
|
|
199
|
+
body: JSON.stringify(reportData)
|
|
200
|
+
});
|
|
201
|
+
if (!response.ok) {
|
|
202
|
+
const errorContent = await response.text();
|
|
203
|
+
console.error('Error Response Content:', errorContent);
|
|
204
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
205
|
+
}
|
|
206
|
+
const { data, message, status } = await response.json();
|
|
207
|
+
return data;
|
|
208
|
+
}
|
|
209
|
+
static async getProcessJobEvents(referenceId) {
|
|
210
|
+
const response = await fetch(buildPath(CloudRoutes.process.events, { referenceId }), {
|
|
211
|
+
method: 'GET',
|
|
212
|
+
headers: {
|
|
213
|
+
'Content-Type': 'application/json',
|
|
214
|
+
...this[AuthKey]
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
if (!response.ok) {
|
|
218
|
+
const errorContent = await response.text();
|
|
219
|
+
console.error('Error Response Content:', errorContent);
|
|
220
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
221
|
+
}
|
|
222
|
+
const { data, message, status } = await response.json();
|
|
223
|
+
return data;
|
|
224
|
+
}
|
|
225
|
+
static async getProcessJobEventsViaAccessPoint(referenceId, accessPoint) {
|
|
226
|
+
const response = await fetch(buildPath(CloudRoutes.process.eventsViaAccessPoint, { referenceId }), {
|
|
227
|
+
method: 'GET',
|
|
228
|
+
headers: {
|
|
229
|
+
'Content-Type': 'application/json',
|
|
230
|
+
'access-point': accessPoint,
|
|
231
|
+
// No auth headers for public access point
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
if (!response.ok) {
|
|
235
|
+
const errorContent = await response.text();
|
|
236
|
+
console.error('Error Response Content:', errorContent);
|
|
237
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
238
|
+
}
|
|
239
|
+
const { data, message, status } = await response.json();
|
|
240
|
+
return data;
|
|
241
|
+
}
|
|
242
|
+
static async getProcessJobResults(jobId) {
|
|
243
|
+
try {
|
|
244
|
+
const response = await fetch(buildPath(CloudRoutes.job.results, { id: jobId }), {
|
|
245
|
+
method: 'GET',
|
|
246
|
+
headers: {
|
|
247
|
+
'Content-Type': 'application/json',
|
|
248
|
+
...this[AuthKey]
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
if (!response.ok) {
|
|
252
|
+
const errorContent = await response.text();
|
|
253
|
+
console.error('Error Response Content:', errorContent);
|
|
254
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
255
|
+
}
|
|
256
|
+
const { data, message, status } = await response.json();
|
|
257
|
+
return data;
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
console.error('Error fetching job results:', error);
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
static async getProcessJobResultsViaAccessPoint(jobId, accessPoint) {
|
|
265
|
+
const response = await fetch(buildPath(CloudRoutes.job.resultsViaAccessPoint, { id: jobId }), {
|
|
266
|
+
method: 'GET',
|
|
267
|
+
headers: {
|
|
268
|
+
'Content-Type': 'application/json',
|
|
269
|
+
'access-point': accessPoint,
|
|
270
|
+
// No auth headers for public access point
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
if (!response.ok) {
|
|
274
|
+
const errorContent = await response.text();
|
|
275
|
+
console.error('Error Response Content:', errorContent);
|
|
276
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
277
|
+
}
|
|
278
|
+
const { data, message, status } = await response.json();
|
|
279
|
+
return data;
|
|
280
|
+
}
|
|
281
|
+
static async getJobIdByReferenceId(referenceId) {
|
|
282
|
+
const response = await fetch(buildPath(CloudRoutes.job.getJobIdByReferenceId, { referenceId }), {
|
|
283
|
+
method: 'GET',
|
|
284
|
+
headers: {
|
|
285
|
+
'Content-Type': 'application/json',
|
|
286
|
+
...this[AuthKey]
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
if (!response.ok) {
|
|
290
|
+
const errorContent = await response.text();
|
|
291
|
+
console.error('Error Response Content:', errorContent);
|
|
292
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
293
|
+
}
|
|
294
|
+
const { data, message, status } = await response.json();
|
|
295
|
+
return data;
|
|
296
|
+
}
|
|
297
|
+
static async getJobResultsByReferenceId(referenceId) {
|
|
298
|
+
try {
|
|
299
|
+
const jobIdData = await this.getJobIdByReferenceId(referenceId);
|
|
300
|
+
if (jobIdData && jobIdData.jobId) {
|
|
301
|
+
return this.getProcessJobResults(jobIdData.jobId);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
throw new Error('Job ID not found for the given reference ID');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
console.error('Error fetching job results by reference ID:', error);
|
|
309
|
+
throw error;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
static async executeDatabaseOperation(operation, request) {
|
|
313
|
+
//const { data } = await this.postRequest(CloudRoutes.integrations.database, { }, {operation, request});
|
|
314
|
+
const response = await fetch(buildPath(CloudRoutes.integrations.database), {
|
|
315
|
+
method: 'POST',
|
|
316
|
+
headers: {
|
|
317
|
+
'Content-Type': 'application/json',
|
|
318
|
+
...this[AuthKey]
|
|
319
|
+
},
|
|
320
|
+
body: JSON.stringify({ operation, request })
|
|
321
|
+
});
|
|
322
|
+
if (!response.ok) {
|
|
323
|
+
const errorContent = await response.text();
|
|
324
|
+
console.error('Error Response Content:', errorContent);
|
|
325
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
326
|
+
}
|
|
327
|
+
const { data, message, status } = await response.json();
|
|
328
|
+
return data?.data || data;
|
|
329
|
+
}
|
|
330
|
+
static async getJobFile(jobId, fileType, fileId) {
|
|
331
|
+
try {
|
|
332
|
+
const response = await fetch(buildPath(CloudRoutes.job.file, { id: jobId, fileType, fileId }), {
|
|
333
|
+
method: 'GET',
|
|
334
|
+
headers: {
|
|
335
|
+
//'Content-Type': 'application/json',
|
|
336
|
+
...this[AuthKey]
|
|
337
|
+
},
|
|
338
|
+
//credentials: 'include',
|
|
339
|
+
});
|
|
340
|
+
// Validate response
|
|
341
|
+
//await this.validateReponse(response);
|
|
342
|
+
if (!response.ok) {
|
|
343
|
+
throw new Error(`Failed to fetch file: ${response.statusText}`);
|
|
344
|
+
}
|
|
345
|
+
// Ensure the response is of type readable stream
|
|
346
|
+
if (!response.body) {
|
|
347
|
+
throw new Error("Response body is empty, no stream available.");
|
|
348
|
+
}
|
|
349
|
+
return response.body; // Return the ReadableStream for the file
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
console.error('Error fetching job file:', error);
|
|
353
|
+
throw error;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
exports.default = CloudResourceManager;
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DatabaseSchema } from "./CloudDatabaseManager";
|
|
2
|
+
import { ProcessExecutionOptions, ProcessScheduleOptions, ProcessJobEventsRequest } from './types';
|
|
3
|
+
export declare const init: (clientId: string, apiKey: string) => void;
|
|
4
|
+
export declare const runProcess: (options: ProcessExecutionOptions) => Promise<any>;
|
|
5
|
+
export declare const getJobResults: (jobId: string) => Promise<any>;
|
|
6
|
+
export declare const getProcessJobEvents: (request: ProcessJobEventsRequest) => Promise<any>;
|
|
7
|
+
export declare const scheduleProcess: (options: ProcessScheduleOptions) => Promise<any>;
|
|
8
|
+
export declare const getPromptContent: (promptId: string) => Promise<any>;
|
|
9
|
+
export declare const getJobFile: (jobId: string, link: string) => Promise<ReadableStream<Uint8Array<ArrayBuffer>>>;
|
package/build/index.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getJobFile = exports.getPromptContent = exports.scheduleProcess = exports.getProcessJobEvents = exports.getJobResults = exports.runProcess = exports.init = exports.DatabaseSchema = void 0;
|
|
7
|
+
const CloudResourceAPI_1 = __importDefault(require("./CloudResourceAPI"));
|
|
8
|
+
const poller_1 = require("./poller");
|
|
9
|
+
var CloudDatabaseManager_1 = require("./CloudDatabaseManager");
|
|
10
|
+
Object.defineProperty(exports, "DatabaseSchema", { enumerable: true, get: function () { return CloudDatabaseManager_1.DatabaseSchema; } });
|
|
11
|
+
const JOB_COMPLETE_STATUS = new Set([
|
|
12
|
+
'job-end',
|
|
13
|
+
'job-error',
|
|
14
|
+
'job-completed',
|
|
15
|
+
'process-completed',
|
|
16
|
+
'process-ended'
|
|
17
|
+
]);
|
|
18
|
+
const isJobComplete = (events = []) => {
|
|
19
|
+
return events.some((val) => JOB_COMPLETE_STATUS.has(val.eventType?.toLowerCase()));
|
|
20
|
+
};
|
|
21
|
+
const init = (clientId, apiKey) => {
|
|
22
|
+
CloudResourceAPI_1.default.init(clientId, apiKey);
|
|
23
|
+
};
|
|
24
|
+
exports.init = init;
|
|
25
|
+
const runProcess = (options) => {
|
|
26
|
+
if (options.accessPoint) {
|
|
27
|
+
return CloudResourceAPI_1.default.runProcessViaAccessPoint(options.processId, options.inputs, options.accessPoint, options.metadata || {});
|
|
28
|
+
}
|
|
29
|
+
return CloudResourceAPI_1.default.runProcess(options.processId, options.inputs, options.metadata || {});
|
|
30
|
+
};
|
|
31
|
+
exports.runProcess = runProcess;
|
|
32
|
+
const getJobResults = async (jobId) => {
|
|
33
|
+
//Polling
|
|
34
|
+
return CloudResourceAPI_1.default.getProcessJobResults(jobId);
|
|
35
|
+
};
|
|
36
|
+
exports.getJobResults = getJobResults;
|
|
37
|
+
const getProcessJobEvents = async (request
|
|
38
|
+
// referenceId: string,
|
|
39
|
+
// polling?: { intervalMs: number, durationMs?: number }
|
|
40
|
+
) => {
|
|
41
|
+
const { referenceId, polling, accessPoint } = request;
|
|
42
|
+
//Polling
|
|
43
|
+
if (polling) {
|
|
44
|
+
const poller = (0, poller_1.createPoller)(async () => {
|
|
45
|
+
const events = accessPoint ? await CloudResourceAPI_1.default.getProcessJobEventsViaAccessPoint(referenceId, accessPoint) : await CloudResourceAPI_1.default.getProcessJobEvents(referenceId);
|
|
46
|
+
const isComplete = isJobComplete(events);
|
|
47
|
+
let results;
|
|
48
|
+
if (isComplete) {
|
|
49
|
+
results = await CloudResourceAPI_1.default.getJobResultsByReferenceId(referenceId);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
data: events,
|
|
53
|
+
done: isComplete,
|
|
54
|
+
results: results || null
|
|
55
|
+
};
|
|
56
|
+
}, polling.intervalMs);
|
|
57
|
+
return poller;
|
|
58
|
+
}
|
|
59
|
+
return CloudResourceAPI_1.default.getProcessJobEvents(referenceId);
|
|
60
|
+
};
|
|
61
|
+
exports.getProcessJobEvents = getProcessJobEvents;
|
|
62
|
+
const scheduleProcess = (options) => {
|
|
63
|
+
return CloudResourceAPI_1.default.scheduleProcess(options.processId, options);
|
|
64
|
+
};
|
|
65
|
+
exports.scheduleProcess = scheduleProcess;
|
|
66
|
+
const getPromptContent = (promptId) => {
|
|
67
|
+
return CloudResourceAPI_1.default.getPromptContent(promptId);
|
|
68
|
+
};
|
|
69
|
+
exports.getPromptContent = getPromptContent;
|
|
70
|
+
const JOB_FILE_PATTERN = /^file\((image|audio|text)\):([a-f\d]{24})$/;
|
|
71
|
+
const getJobFileDetails = (link) => {
|
|
72
|
+
//Format is like file:audio(fileId)
|
|
73
|
+
const match = link.match(JOB_FILE_PATTERN);
|
|
74
|
+
if (!match) {
|
|
75
|
+
throw new Error('Invalid file link format');
|
|
76
|
+
}
|
|
77
|
+
const fileType = match[1];
|
|
78
|
+
const fileId = match[2];
|
|
79
|
+
return { fileType, fileId };
|
|
80
|
+
};
|
|
81
|
+
const getJobFile = async (jobId, link) => {
|
|
82
|
+
//Format is like file:audio(fileId)
|
|
83
|
+
const { fileType, fileId } = getJobFileDetails(link);
|
|
84
|
+
return CloudResourceAPI_1.default.getJobFile(jobId, fileType, fileId);
|
|
85
|
+
};
|
|
86
|
+
exports.getJobFile = getJobFile;
|
|
87
|
+
console.log("Loaded Juggernaut Cloud SDK");
|
package/build/min.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const SDK: Readonly<{
|
|
2
|
+
runProcess: (options: import("./types").ProcessExecutionOptions) => Promise<any>;
|
|
3
|
+
getProcessJobEvents: (request: import("./types").ProcessJobEventsRequest) => Promise<any>;
|
|
4
|
+
scheduleProcess: (options: import("./types").ProcessScheduleOptions) => Promise<any>;
|
|
5
|
+
getPromptContent: (promptId: string) => Promise<any>;
|
|
6
|
+
getJobFile: (jobId: string, link: string) => Promise<ReadableStream<Uint8Array<ArrayBuffer>>>;
|
|
7
|
+
getJobResults: (jobId: string) => Promise<any>;
|
|
8
|
+
}>;
|
|
9
|
+
export default SDK;
|
package/build/min.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("./index");
|
|
4
|
+
const SDK = Object.freeze({
|
|
5
|
+
runProcess: index_1.runProcess,
|
|
6
|
+
getProcessJobEvents: index_1.getProcessJobEvents,
|
|
7
|
+
scheduleProcess: index_1.scheduleProcess,
|
|
8
|
+
getPromptContent: index_1.getPromptContent,
|
|
9
|
+
getJobFile: index_1.getJobFile,
|
|
10
|
+
getJobResults: index_1.getJobResults
|
|
11
|
+
});
|
|
12
|
+
//Exporting for minified build for a browser environment
|
|
13
|
+
const exportGlobals = () => {
|
|
14
|
+
if (typeof window !== "undefined") {
|
|
15
|
+
window.JuggernautCloud = SDK;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (globalThis) {
|
|
19
|
+
globalThis.JuggernautCloud = SDK;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exportGlobals();
|
|
24
|
+
exports.default = SDK;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type for the listener callback.
|
|
3
|
+
* @param data The data returned by the polling function.
|
|
4
|
+
*/
|
|
5
|
+
type Listener<T> = (data: T) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a polling mechanism that repeatedly calls an async function and
|
|
8
|
+
* emits its results to registered listeners.
|
|
9
|
+
*
|
|
10
|
+
* Supports both Node.js and Browser environments.
|
|
11
|
+
*
|
|
12
|
+
* @param pollFn The async function to execute on each poll interval.
|
|
13
|
+
* @param intervalMs The polling interval in milliseconds.
|
|
14
|
+
* @param stopCondition Optional function to determine if polling should stop based on the data.
|
|
15
|
+
* @returns An object with start/stop controls and an 'on' method for listening.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createPoller<T>(pollFn: () => Promise<T>, intervalMs: number, stopCondition?: (data: T) => boolean): {
|
|
18
|
+
start: (listener?: Listener<T>) => void;
|
|
19
|
+
stop: () => void;
|
|
20
|
+
listen: (listener: Listener<T>) => () => void;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
package/build/poller.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPoller = createPoller;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a polling mechanism that repeatedly calls an async function and
|
|
6
|
+
* emits its results to registered listeners.
|
|
7
|
+
*
|
|
8
|
+
* Supports both Node.js and Browser environments.
|
|
9
|
+
*
|
|
10
|
+
* @param pollFn The async function to execute on each poll interval.
|
|
11
|
+
* @param intervalMs The polling interval in milliseconds.
|
|
12
|
+
* @param stopCondition Optional function to determine if polling should stop based on the data.
|
|
13
|
+
* @returns An object with start/stop controls and an 'on' method for listening.
|
|
14
|
+
*/
|
|
15
|
+
function createPoller(pollFn, intervalMs,
|
|
16
|
+
// New optional parameter to check if we should stop
|
|
17
|
+
stopCondition) {
|
|
18
|
+
let intervalId = null;
|
|
19
|
+
const listeners = [];
|
|
20
|
+
const listen = (listener) => {
|
|
21
|
+
listeners.push(listener);
|
|
22
|
+
// Return an unsubscribe function
|
|
23
|
+
return () => {
|
|
24
|
+
const index = listeners.indexOf(listener);
|
|
25
|
+
if (index > -1) {
|
|
26
|
+
listeners.splice(index, 1);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const poll = async () => {
|
|
31
|
+
try {
|
|
32
|
+
const data = await pollFn();
|
|
33
|
+
listeners.forEach(listener => listener(data));
|
|
34
|
+
if (stopCondition && stopCondition(data)) {
|
|
35
|
+
stop();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error('Polling error:', error);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const start = (listener) => {
|
|
43
|
+
if (intervalId === null) {
|
|
44
|
+
// Execute once immediately
|
|
45
|
+
poll();
|
|
46
|
+
// Set the interval
|
|
47
|
+
intervalId = setInterval(poll, intervalMs);
|
|
48
|
+
if (listener) {
|
|
49
|
+
listen(listener);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/** Stops the polling process. */
|
|
54
|
+
const stop = () => {
|
|
55
|
+
if (intervalId !== null) {
|
|
56
|
+
clearInterval(intervalId);
|
|
57
|
+
intervalId = null;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
//Include start with optional listener
|
|
62
|
+
start,
|
|
63
|
+
stop,
|
|
64
|
+
listen
|
|
65
|
+
};
|
|
66
|
+
}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type ProcessExecutionOptions = {
|
|
2
|
+
processId: string;
|
|
3
|
+
inputs: Record<string, any>;
|
|
4
|
+
metadata?: Record<string, any>;
|
|
5
|
+
accessPoint?: string;
|
|
6
|
+
};
|
|
7
|
+
export type ProcessScheduleOptions = {
|
|
8
|
+
processId: string;
|
|
9
|
+
name: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
intervals: 'once' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'custom';
|
|
12
|
+
cronExpression?: string;
|
|
13
|
+
timezone?: string;
|
|
14
|
+
};
|
|
15
|
+
export type ProcessJobEventsRequest = {
|
|
16
|
+
referenceId: string;
|
|
17
|
+
polling?: {
|
|
18
|
+
intervalMs: number;
|
|
19
|
+
durationMs?: number;
|
|
20
|
+
};
|
|
21
|
+
accessPoint?: string;
|
|
22
|
+
};
|
package/build/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@juggernautlabs/cloud",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"unpkg": "build/min.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"build"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "jest",
|
|
12
|
+
"compile": "tsc",
|
|
13
|
+
"build": "npm run compile",
|
|
14
|
+
"prepublishOnly": "npm run compile",
|
|
15
|
+
"publish": "npm publish --access public"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"juggernaut",
|
|
19
|
+
"cloud",
|
|
20
|
+
"sdk",
|
|
21
|
+
"beta"
|
|
22
|
+
],
|
|
23
|
+
"author": "Juggernaut Labs",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"jest": "^30.2.0",
|
|
27
|
+
"ts-jest": "^29.4.6"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/jest": "^30.0.0"
|
|
31
|
+
}
|
|
32
|
+
}
|