infinium-o2 0.1.0
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/README.md +550 -0
- package/dist/cjs/asyncClient.d.ts +119 -0
- package/dist/cjs/asyncClient.d.ts.map +1 -0
- package/dist/cjs/asyncClient.js +464 -0
- package/dist/cjs/asyncClient.js.map +1 -0
- package/dist/cjs/client.d.ts +92 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +354 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/errors.d.ts +102 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +218 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.d.ts +12 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +61 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.ts +231 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +23 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.d.ts +130 -0
- package/dist/cjs/utils.d.ts.map +1 -0
- package/dist/cjs/utils.js +381 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/asyncClient.d.ts +119 -0
- package/dist/esm/asyncClient.d.ts.map +1 -0
- package/dist/esm/asyncClient.js +457 -0
- package/dist/esm/asyncClient.js.map +1 -0
- package/dist/esm/client.d.ts +92 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +347 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/errors.d.ts +102 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +200 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/types.d.ts +231 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +20 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.d.ts +130 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +355 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Asynchronous client for Infinium API.
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AsyncInfiniumClient = void 0;
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
|
+
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
12
|
+
const types_1 = require("./types");
|
|
13
|
+
const errors_1 = require("./errors");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
/**
|
|
16
|
+
* Asynchronous client for Infinium API.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { AsyncInfiniumClient, AgentType } from 'infinium';
|
|
21
|
+
*
|
|
22
|
+
* const client = new AsyncInfiniumClient({
|
|
23
|
+
* agentId: 'your-agent-id',
|
|
24
|
+
* agentSecret: 'your-agent-secret'
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Send a simple task
|
|
28
|
+
* const response = await client.sendTask({
|
|
29
|
+
* name: 'Process customer inquiry',
|
|
30
|
+
* description: 'Handled customer question about pricing',
|
|
31
|
+
* duration: 120.5
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Use with proper cleanup
|
|
35
|
+
* async function example() {
|
|
36
|
+
* const client = new AsyncInfiniumClient({
|
|
37
|
+
* agentId: 'your-agent-id',
|
|
38
|
+
* agentSecret: 'your-agent-secret'
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* try {
|
|
42
|
+
* const health = await client.testConnection();
|
|
43
|
+
* console.log('Connected:', health.agentName);
|
|
44
|
+
*
|
|
45
|
+
* const response = await client.sendTask({
|
|
46
|
+
* name: 'Marketing campaign analysis',
|
|
47
|
+
* description: 'Analyzed Q3 campaign performance',
|
|
48
|
+
* duration: 300.0,
|
|
49
|
+
* agentType: AgentType.MARKETING_ASSISTANT
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* console.log('Task sent:', response.success);
|
|
53
|
+
* } finally {
|
|
54
|
+
* await client.close();
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
class AsyncInfiniumClient {
|
|
60
|
+
agentId;
|
|
61
|
+
agentSecret;
|
|
62
|
+
baseUrl;
|
|
63
|
+
timeout;
|
|
64
|
+
maxRetries;
|
|
65
|
+
userAgent;
|
|
66
|
+
logger;
|
|
67
|
+
rateLimiter;
|
|
68
|
+
httpClient;
|
|
69
|
+
closed = false;
|
|
70
|
+
/**
|
|
71
|
+
* Initialize the async Infinium client.
|
|
72
|
+
*/
|
|
73
|
+
constructor(config) {
|
|
74
|
+
// Validate configuration
|
|
75
|
+
(0, utils_1.validateAgentCredentials)(config.agentId, config.agentSecret);
|
|
76
|
+
this.agentId = config.agentId;
|
|
77
|
+
this.agentSecret = config.agentSecret;
|
|
78
|
+
this.baseUrl = (0, utils_1.normalizeUrl)(config.baseUrl || 'https://api.i42m.ai/api/v1');
|
|
79
|
+
this.timeout = config.timeout || 30000;
|
|
80
|
+
this.maxRetries = config.maxRetries || 3;
|
|
81
|
+
this.userAgent = config.userAgent || (0, utils_1.generateUserAgent)('1.0.0');
|
|
82
|
+
this.logger = (0, utils_1.setupLogging)(config.enableLogging, config.logLevel);
|
|
83
|
+
// Setup rate limiter if enabled
|
|
84
|
+
this.rateLimiter =
|
|
85
|
+
config.enableRateLimiting !== false
|
|
86
|
+
? new utils_1.RateLimiter({
|
|
87
|
+
requestsPerSecond: config.requestsPerSecond || 10,
|
|
88
|
+
burstSize: (config.requestsPerSecond || 10) * 2,
|
|
89
|
+
})
|
|
90
|
+
: null;
|
|
91
|
+
// Setup HTTP client
|
|
92
|
+
this.httpClient = this.createHttpClient();
|
|
93
|
+
this.logger.info('Async Infinium client initialized', {
|
|
94
|
+
agentId: this.agentId,
|
|
95
|
+
baseUrl: this.baseUrl,
|
|
96
|
+
timeout: this.timeout,
|
|
97
|
+
maxRetries: this.maxRetries,
|
|
98
|
+
rateLimitingEnabled: !!this.rateLimiter,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create and configure HTTP client.
|
|
103
|
+
*/
|
|
104
|
+
createHttpClient() {
|
|
105
|
+
const client = axios_1.default.create({
|
|
106
|
+
baseURL: this.baseUrl,
|
|
107
|
+
timeout: this.timeout,
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
'User-Agent': this.userAgent,
|
|
111
|
+
'x-agent-id': this.agentId,
|
|
112
|
+
'x-agent-key': this.agentSecret,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
// Setup retry logic
|
|
116
|
+
(0, axios_retry_1.default)(client, {
|
|
117
|
+
retries: this.maxRetries,
|
|
118
|
+
retryDelay: (retryCount) => {
|
|
119
|
+
return Math.min(1000 * 2 ** (retryCount - 1), 30000);
|
|
120
|
+
},
|
|
121
|
+
retryCondition: (error) => {
|
|
122
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
123
|
+
return (0, utils_1.shouldRetryError)(error);
|
|
124
|
+
},
|
|
125
|
+
onRetry: (retryCount, error, requestConfig) => {
|
|
126
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
127
|
+
this.logger.warn('Retrying request', {
|
|
128
|
+
retryCount,
|
|
129
|
+
url: requestConfig.url,
|
|
130
|
+
method: requestConfig.method,
|
|
131
|
+
error: error.message,
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
// Request interceptor for rate limiting
|
|
136
|
+
client.interceptors.request.use(async (config) => {
|
|
137
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
138
|
+
if (this.closed) {
|
|
139
|
+
throw new errors_1.InfiniumError('Client has been closed');
|
|
140
|
+
}
|
|
141
|
+
if (this.rateLimiter) {
|
|
142
|
+
if (!this.rateLimiter.canMakeRequest()) {
|
|
143
|
+
const waitTime = this.rateLimiter.getWaitTime();
|
|
144
|
+
this.logger.debug('Rate limit hit, waiting', { waitTime });
|
|
145
|
+
await (0, utils_1.sleep)(waitTime);
|
|
146
|
+
// Check again after waiting
|
|
147
|
+
if (!this.rateLimiter.canMakeRequest()) {
|
|
148
|
+
throw new errors_1.RateLimitError(`Rate limit exceeded. Tried waiting ${waitTime}ms but still limited.`, waitTime);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
this.logger.debug('Making request', {
|
|
153
|
+
url: config.url,
|
|
154
|
+
method: config.method,
|
|
155
|
+
});
|
|
156
|
+
return config;
|
|
157
|
+
});
|
|
158
|
+
// Response interceptor for logging and error handling
|
|
159
|
+
client.interceptors.response.use((response) => {
|
|
160
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
161
|
+
this.logger.debug('Request successful', {
|
|
162
|
+
url: response.config.url,
|
|
163
|
+
method: response.config.method,
|
|
164
|
+
status: response.status,
|
|
165
|
+
});
|
|
166
|
+
return response;
|
|
167
|
+
}, (error) => {
|
|
168
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
169
|
+
this.logger.error('Request failed', {
|
|
170
|
+
url: error.config?.url,
|
|
171
|
+
method: error.config?.method,
|
|
172
|
+
status: error.response?.status,
|
|
173
|
+
message: error.message,
|
|
174
|
+
});
|
|
175
|
+
throw (0, errors_1.handleAxiosError)(error);
|
|
176
|
+
});
|
|
177
|
+
return client;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Make HTTP request with proper error handling.
|
|
181
|
+
*/
|
|
182
|
+
async makeRequest(method, endpoint, data, options) {
|
|
183
|
+
if (this.closed) {
|
|
184
|
+
throw new errors_1.InfiniumError('Client has been closed');
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
const config = {
|
|
188
|
+
method,
|
|
189
|
+
url: endpoint,
|
|
190
|
+
data,
|
|
191
|
+
timeout: options?.timeout || this.timeout,
|
|
192
|
+
...(options?.headers && { headers: options.headers }),
|
|
193
|
+
};
|
|
194
|
+
const response = await this.httpClient.request(config);
|
|
195
|
+
return response.data;
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
throw (0, errors_1.handleAxiosError)(error);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Send task data to the API.
|
|
203
|
+
*/
|
|
204
|
+
async sendTask(task) {
|
|
205
|
+
// Validate required fields
|
|
206
|
+
(0, utils_1.validateRequiredField)(task.name, 'name');
|
|
207
|
+
(0, utils_1.validateRequiredField)(task.description, 'description');
|
|
208
|
+
(0, utils_1.validateRequiredField)(task.duration, 'duration', 'number');
|
|
209
|
+
// Validate and normalize data
|
|
210
|
+
(0, utils_1.validateDuration)(task.duration);
|
|
211
|
+
const agentType = task.agentType ? (0, utils_1.validateAgentType)(task.agentType) : types_1.AgentType.OTHER;
|
|
212
|
+
const currentDatetime = task.currentDatetime || (0, utils_1.getCurrentIsoDatetime)();
|
|
213
|
+
if (!(0, utils_1.validateIsoDatetime)(currentDatetime)) {
|
|
214
|
+
throw new errors_1.ValidationError('Invalid currentDatetime format. Must be ISO 8601.', 'currentDatetime');
|
|
215
|
+
}
|
|
216
|
+
// Build task payload
|
|
217
|
+
const taskPayload = {
|
|
218
|
+
name: task.name.trim(),
|
|
219
|
+
description: task.description.trim(),
|
|
220
|
+
current_datetime: currentDatetime,
|
|
221
|
+
duration: task.duration,
|
|
222
|
+
agent_type: agentType,
|
|
223
|
+
time_tracking: task.timeTracking,
|
|
224
|
+
customer: task.customer,
|
|
225
|
+
support: task.support,
|
|
226
|
+
sales: task.sales,
|
|
227
|
+
marketing: task.marketing,
|
|
228
|
+
content: task.content,
|
|
229
|
+
research: task.research,
|
|
230
|
+
project: task.project,
|
|
231
|
+
development: task.development,
|
|
232
|
+
executive: task.executive,
|
|
233
|
+
general: task.general,
|
|
234
|
+
};
|
|
235
|
+
// Remove undefined values
|
|
236
|
+
const cleanPayload = this.cleanPayload(taskPayload);
|
|
237
|
+
this.logger.info('Sending task', {
|
|
238
|
+
agentId: this.agentId,
|
|
239
|
+
taskName: task.name,
|
|
240
|
+
agentType,
|
|
241
|
+
});
|
|
242
|
+
return this.makeRequest('POST', `/agents/${this.agentId}/trace`, cleanPayload);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Send pre-built TaskData object.
|
|
246
|
+
*/
|
|
247
|
+
async sendTaskData(taskData) {
|
|
248
|
+
return this.sendTask(taskData);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Send multiple tasks in batch.
|
|
252
|
+
*/
|
|
253
|
+
async sendBatch(tasks) {
|
|
254
|
+
if (!Array.isArray(tasks) || tasks.length === 0) {
|
|
255
|
+
throw new errors_1.ValidationError('Tasks array cannot be empty', 'tasks');
|
|
256
|
+
}
|
|
257
|
+
if (tasks.length > 100) {
|
|
258
|
+
throw new errors_1.ValidationError('Batch size cannot exceed 100 tasks', 'tasks');
|
|
259
|
+
}
|
|
260
|
+
const results = [];
|
|
261
|
+
const errors = [];
|
|
262
|
+
let successfulTasks = 0;
|
|
263
|
+
this.logger.info('Sending batch tasks', {
|
|
264
|
+
agentId: this.agentId,
|
|
265
|
+
taskCount: tasks.length,
|
|
266
|
+
});
|
|
267
|
+
// Process tasks concurrently but with rate limiting
|
|
268
|
+
const promises = tasks.map(async (task, index) => {
|
|
269
|
+
try {
|
|
270
|
+
const result = await this.sendTaskData(task);
|
|
271
|
+
if (result.success) {
|
|
272
|
+
successfulTasks++;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
errors.push(`Task ${index + 1}: ${result.message}`);
|
|
276
|
+
}
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
281
|
+
errors.push(`Task ${index + 1}: ${errorMessage}`);
|
|
282
|
+
const errorResponse = {
|
|
283
|
+
success: false,
|
|
284
|
+
message: errorMessage,
|
|
285
|
+
...(error instanceof errors_1.InfiniumError && error.statusCode
|
|
286
|
+
? { statusCode: error.statusCode }
|
|
287
|
+
: {}),
|
|
288
|
+
};
|
|
289
|
+
return errorResponse;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
const resolvedResults = await Promise.all(promises);
|
|
293
|
+
results.push(...resolvedResults);
|
|
294
|
+
const batchResult = {
|
|
295
|
+
totalTasks: tasks.length,
|
|
296
|
+
successfulTasks,
|
|
297
|
+
failedTasks: tasks.length - successfulTasks,
|
|
298
|
+
results,
|
|
299
|
+
errors,
|
|
300
|
+
};
|
|
301
|
+
if (batchResult.failedTasks > 0) {
|
|
302
|
+
this.logger.warn('Batch completed with errors', {
|
|
303
|
+
totalTasks: batchResult.totalTasks,
|
|
304
|
+
successfulTasks: batchResult.successfulTasks,
|
|
305
|
+
failedTasks: batchResult.failedTasks,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
this.logger.info('Batch completed successfully', {
|
|
310
|
+
totalTasks: batchResult.totalTasks,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
return batchResult;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Send tasks in sequential batch (for rate limiting).
|
|
317
|
+
*/
|
|
318
|
+
async sendBatchSequential(tasks) {
|
|
319
|
+
if (!Array.isArray(tasks) || tasks.length === 0) {
|
|
320
|
+
throw new errors_1.ValidationError('Tasks array cannot be empty', 'tasks');
|
|
321
|
+
}
|
|
322
|
+
if (tasks.length > 100) {
|
|
323
|
+
throw new errors_1.ValidationError('Batch size cannot exceed 100 tasks', 'tasks');
|
|
324
|
+
}
|
|
325
|
+
const results = [];
|
|
326
|
+
const errors = [];
|
|
327
|
+
let successfulTasks = 0;
|
|
328
|
+
this.logger.info('Sending sequential batch tasks', {
|
|
329
|
+
agentId: this.agentId,
|
|
330
|
+
taskCount: tasks.length,
|
|
331
|
+
});
|
|
332
|
+
for (let i = 0; i < tasks.length; i++) {
|
|
333
|
+
try {
|
|
334
|
+
const result = await this.sendTaskData(tasks[i]);
|
|
335
|
+
results.push(result);
|
|
336
|
+
if (result.success) {
|
|
337
|
+
successfulTasks++;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
errors.push(`Task ${i + 1}: ${result.message}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
345
|
+
errors.push(`Task ${i + 1}: ${errorMessage}`);
|
|
346
|
+
const errorResponse = {
|
|
347
|
+
success: false,
|
|
348
|
+
message: errorMessage,
|
|
349
|
+
...(error instanceof errors_1.InfiniumError && error.statusCode
|
|
350
|
+
? { statusCode: error.statusCode }
|
|
351
|
+
: {}),
|
|
352
|
+
};
|
|
353
|
+
results.push(errorResponse);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const batchResult = {
|
|
357
|
+
totalTasks: tasks.length,
|
|
358
|
+
successfulTasks,
|
|
359
|
+
failedTasks: tasks.length - successfulTasks,
|
|
360
|
+
results,
|
|
361
|
+
errors,
|
|
362
|
+
};
|
|
363
|
+
if (batchResult.failedTasks > 0) {
|
|
364
|
+
this.logger.warn('Sequential batch completed with errors', {
|
|
365
|
+
totalTasks: batchResult.totalTasks,
|
|
366
|
+
successfulTasks: batchResult.successfulTasks,
|
|
367
|
+
failedTasks: batchResult.failedTasks,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
this.logger.info('Sequential batch completed successfully', {
|
|
372
|
+
totalTasks: batchResult.totalTasks,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
return batchResult;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Test connection to the API.
|
|
379
|
+
*/
|
|
380
|
+
async testConnection() {
|
|
381
|
+
this.logger.info('Testing connection', { agentId: this.agentId });
|
|
382
|
+
const response = await this.makeRequest('GET', `/agents/${this.agentId}/health`);
|
|
383
|
+
if (!response.success || !response.data) {
|
|
384
|
+
throw new errors_1.ServerError(response.message || 'Health check failed', response.statusCode);
|
|
385
|
+
}
|
|
386
|
+
this.logger.info('Connection test successful', {
|
|
387
|
+
agentId: this.agentId,
|
|
388
|
+
agentName: response.data.agentName,
|
|
389
|
+
status: response.data.status,
|
|
390
|
+
});
|
|
391
|
+
return response.data;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Get interpreted task result.
|
|
395
|
+
*/
|
|
396
|
+
async getInterpretedTaskResult(taskId) {
|
|
397
|
+
(0, utils_1.validateRequiredField)(taskId, 'taskId');
|
|
398
|
+
this.logger.info('Getting interpreted task result', {
|
|
399
|
+
agentId: this.agentId,
|
|
400
|
+
taskId,
|
|
401
|
+
});
|
|
402
|
+
return this.makeRequest('GET', `/agents/${this.agentId}/interpreted-result/${taskId}`);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Get current ISO datetime string.
|
|
406
|
+
*/
|
|
407
|
+
getCurrentIsoDatetime() {
|
|
408
|
+
return (0, utils_1.getCurrentIsoDatetime)();
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Get client configuration.
|
|
412
|
+
*/
|
|
413
|
+
getConfig() {
|
|
414
|
+
return {
|
|
415
|
+
agentId: this.agentId,
|
|
416
|
+
baseUrl: this.baseUrl,
|
|
417
|
+
timeout: this.timeout,
|
|
418
|
+
maxRetries: this.maxRetries,
|
|
419
|
+
userAgent: this.userAgent,
|
|
420
|
+
enableRateLimiting: !!this.rateLimiter,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Check if client is closed.
|
|
425
|
+
*/
|
|
426
|
+
isClosed() {
|
|
427
|
+
return this.closed;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Close the client and cleanup resources.
|
|
431
|
+
*/
|
|
432
|
+
async close() {
|
|
433
|
+
if (this.closed) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
this.logger.info('Closing Infinium client', { agentId: this.agentId });
|
|
437
|
+
this.closed = true;
|
|
438
|
+
// Cancel any pending requests
|
|
439
|
+
// Note: axios doesn't provide a direct way to cancel all requests,
|
|
440
|
+
// but setting closed=true will prevent new requests
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Clean payload by removing undefined values.
|
|
444
|
+
*/
|
|
445
|
+
cleanPayload(payload) {
|
|
446
|
+
const cleaned = {};
|
|
447
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
448
|
+
if (value !== undefined && value !== null) {
|
|
449
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
450
|
+
const cleanedNested = this.cleanPayload(value);
|
|
451
|
+
if (Object.keys(cleanedNested).length > 0) {
|
|
452
|
+
cleaned[key] = cleanedNested;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
cleaned[key] = value;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return cleaned;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
exports.AsyncInfiniumClient = AsyncInfiniumClient;
|
|
464
|
+
//# sourceMappingURL=asyncClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncClient.js","sourceRoot":"","sources":["../../src/asyncClient.ts"],"names":[],"mapp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AI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;oBACvD,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,KAAgC,CAAC,CAAC;oBAC1E,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAC1C,OAAO,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC;oBAC/B,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBACvB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAjeD,kDAieC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous client for Infinium API.
|
|
3
|
+
*/
|
|
4
|
+
import { TaskData, ApiResponse, HealthCheck, BatchResult, ClientConfig } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Synchronous client for Infinium API.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { InfiniumClient, AgentType } from 'infinium';
|
|
11
|
+
*
|
|
12
|
+
* const client = new InfiniumClient({
|
|
13
|
+
* agentId: 'your-agent-id',
|
|
14
|
+
* agentSecret: 'your-agent-secret'
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Send a simple task
|
|
18
|
+
* const response = client.sendTask({
|
|
19
|
+
* name: 'Process customer inquiry',
|
|
20
|
+
* description: 'Handled customer question about pricing',
|
|
21
|
+
* duration: 120.5
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Send with additional data
|
|
25
|
+
* const taskData = {
|
|
26
|
+
* name: 'Marketing campaign analysis',
|
|
27
|
+
* description: 'Analyzed Q3 campaign performance',
|
|
28
|
+
* currentDatetime: client.getCurrentIsoDatetime(),
|
|
29
|
+
* duration: 300.0,
|
|
30
|
+
* agentType: AgentType.MARKETING_ASSISTANT
|
|
31
|
+
* };
|
|
32
|
+
* const response2 = client.sendTaskData(taskData);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class InfiniumClient {
|
|
36
|
+
private readonly agentId;
|
|
37
|
+
private readonly agentSecret;
|
|
38
|
+
private readonly baseUrl;
|
|
39
|
+
private readonly timeout;
|
|
40
|
+
private readonly maxRetries;
|
|
41
|
+
private readonly userAgent;
|
|
42
|
+
private readonly logger;
|
|
43
|
+
private readonly rateLimiter;
|
|
44
|
+
private readonly httpClient;
|
|
45
|
+
/**
|
|
46
|
+
* Initialize the Infinium client.
|
|
47
|
+
*/
|
|
48
|
+
constructor(config: ClientConfig);
|
|
49
|
+
/**
|
|
50
|
+
* Create and configure HTTP client.
|
|
51
|
+
*/
|
|
52
|
+
private createHttpClient;
|
|
53
|
+
/**
|
|
54
|
+
* Make HTTP request with proper error handling.
|
|
55
|
+
*/
|
|
56
|
+
private makeRequest;
|
|
57
|
+
/**
|
|
58
|
+
* Send task data to the API.
|
|
59
|
+
*/
|
|
60
|
+
sendTask(task: Omit<TaskData, 'currentDatetime'> & {
|
|
61
|
+
currentDatetime?: string;
|
|
62
|
+
}): Promise<ApiResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* Send pre-built TaskData object.
|
|
65
|
+
*/
|
|
66
|
+
sendTaskData(taskData: TaskData): Promise<ApiResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Send multiple tasks in batch.
|
|
69
|
+
*/
|
|
70
|
+
sendBatch(tasks: TaskData[]): Promise<BatchResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Test connection to the API.
|
|
73
|
+
*/
|
|
74
|
+
testConnection(): Promise<HealthCheck>;
|
|
75
|
+
/**
|
|
76
|
+
* Get interpreted task result.
|
|
77
|
+
*/
|
|
78
|
+
getInterpretedTaskResult(taskId: string): Promise<ApiResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Get current ISO datetime string.
|
|
81
|
+
*/
|
|
82
|
+
getCurrentIsoDatetime(): string;
|
|
83
|
+
/**
|
|
84
|
+
* Get client configuration.
|
|
85
|
+
*/
|
|
86
|
+
getConfig(): Partial<ClientConfig>;
|
|
87
|
+
/**
|
|
88
|
+
* Clean payload by removing undefined values.
|
|
89
|
+
*/
|
|
90
|
+
private cleanPayload;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAEL,QAAQ,EACR,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EAab,MAAM,SAAS,CAAC;AA8BjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IAErC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IAEjD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE3C;;OAEG;gBACS,MAAM,EAAE,YAAY;IAiChC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAgFxB;;OAEG;YACW,WAAW;IAuBzB;;OAEG;IACG,QAAQ,CACZ,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,iBAAiB,CAAC,GAAG;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GACrE,OAAO,CAAC,WAAW,CAAC;IAmDvB;;OAEG;IACG,YAAY,CAAC,QAAQ,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