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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Xyen Digital
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
# Infinium SDK for Node.js
|
|
2
|
+
|
|
3
|
+
A production-ready Node.js SDK for interacting with the Infinium Hosted MCP Bridge API.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Synchronous and Asynchronous Support**: Choose the right approach for your application
|
|
8
|
+
- **Automatic Retries**: Built-in exponential backoff for failed requests
|
|
9
|
+
- **Rate Limiting**: Client-side rate limiting to prevent API abuse
|
|
10
|
+
- **Comprehensive Error Handling**: Meaningful exceptions for different error types
|
|
11
|
+
- **Input Validation**: Thorough validation of all inputs before sending to API
|
|
12
|
+
- **Type Safety**: Full TypeScript types for better IDE support and code quality
|
|
13
|
+
- **Flexible Data Structures**: Support for various task types and specialized data sections
|
|
14
|
+
- **Batch Operations**: Send multiple tasks efficiently (concurrent or sequential)
|
|
15
|
+
- **Production Ready**: Designed for enterprise use with proper logging and monitoring
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install infinium
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
For development:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install infinium --save-dev
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### Basic Usage
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { InfiniumClient, AgentType } from "infinium";
|
|
35
|
+
|
|
36
|
+
// Initialize client
|
|
37
|
+
const client = new InfiniumClient({
|
|
38
|
+
agentId: "your-agent-id",
|
|
39
|
+
agentSecret: "your-agent-secret",
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Send a simple task
|
|
43
|
+
const response = client.sendTask({
|
|
44
|
+
name: "Process customer inquiry",
|
|
45
|
+
description: "Handled customer question about pricing",
|
|
46
|
+
duration: 120.5,
|
|
47
|
+
agentType: AgentType.CUSTOMER_SUPPORT_ASSISTANT,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
console.log("Success:", response.success);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Async Usage
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { AsyncInfiniumClient, AgentType } from "infinium";
|
|
57
|
+
|
|
58
|
+
async function example() {
|
|
59
|
+
const client = new AsyncInfiniumClient({
|
|
60
|
+
agentId: "your-agent-id",
|
|
61
|
+
agentSecret: "your-agent-secret",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
// Test connection
|
|
66
|
+
const health = await client.testConnection();
|
|
67
|
+
console.log("Connected:", health.agentName);
|
|
68
|
+
|
|
69
|
+
// Send a task
|
|
70
|
+
const response = await client.sendTask({
|
|
71
|
+
name: "Marketing campaign analysis",
|
|
72
|
+
description: "Analyzed Q3 campaign performance",
|
|
73
|
+
duration: 300.0,
|
|
74
|
+
agentType: AgentType.MARKETING_ASSISTANT,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log("Task sent:", response.success);
|
|
78
|
+
} finally {
|
|
79
|
+
await client.close();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Configuration
|
|
85
|
+
|
|
86
|
+
### Client Configuration
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const client = new InfiniumClient({
|
|
90
|
+
agentId: "your-agent-id", // Required: Your agent ID
|
|
91
|
+
agentSecret: "your-agent-secret", // Required: Your agent secret
|
|
92
|
+
baseUrl: "https://api.i42m.ai/api/v1", // Optional: API base URL
|
|
93
|
+
timeout: 30000, // Optional: Request timeout (ms)
|
|
94
|
+
maxRetries: 3, // Optional: Max retry attempts
|
|
95
|
+
enableRateLimiting: true, // Optional: Enable client-side rate limiting
|
|
96
|
+
requestsPerSecond: 10, // Optional: Rate limit (requests/second)
|
|
97
|
+
userAgent: "my-app/1.0.0", // Optional: Custom user agent
|
|
98
|
+
enableLogging: true, // Optional: Enable SDK logging
|
|
99
|
+
logLevel: "INFO", // Optional: Log level (DEBUG, INFO, WARN, ERROR)
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Environment Variables
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# .env file
|
|
107
|
+
INFINIUM_AGENT_ID=your-agent-id
|
|
108
|
+
INFINIUM_AGENT_SECRET=your-agent-secret
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const client = new InfiniumClient({
|
|
113
|
+
agentId: process.env.INFINIUM_AGENT_ID!,
|
|
114
|
+
agentSecret: process.env.INFINIUM_AGENT_SECRET!,
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## API Reference
|
|
119
|
+
|
|
120
|
+
### InfiniumClient (Synchronous)
|
|
121
|
+
|
|
122
|
+
#### Constructor
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
new InfiniumClient(config: ClientConfig)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### Methods
|
|
129
|
+
|
|
130
|
+
##### `sendTask(task)`
|
|
131
|
+
|
|
132
|
+
Send a single task to the API.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
const response = client.sendTask({
|
|
136
|
+
name: "Task name",
|
|
137
|
+
description: "Task description",
|
|
138
|
+
duration: 120.5,
|
|
139
|
+
agentType: AgentType.CUSTOMER_SUPPORT_ASSISTANT,
|
|
140
|
+
// ... additional optional fields
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
##### `sendTaskData(taskData)`
|
|
145
|
+
|
|
146
|
+
Send a pre-built TaskData object.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
const taskData: TaskData = {
|
|
150
|
+
name: "Process inquiry",
|
|
151
|
+
description: "Handled customer question",
|
|
152
|
+
currentDatetime: client.getCurrentIsoDatetime(),
|
|
153
|
+
duration: 120,
|
|
154
|
+
agentType: AgentType.CUSTOMER_SUPPORT_ASSISTANT,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const response = client.sendTaskData(taskData);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
##### `sendBatch(tasks)`
|
|
161
|
+
|
|
162
|
+
Send multiple tasks in batch (up to 100 tasks).
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
const tasks: TaskData[] = [
|
|
166
|
+
{ name: 'Task 1', /* ... */ },
|
|
167
|
+
{ name: 'Task 2', /* ... */ },
|
|
168
|
+
// ...
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
const batchResult = client.sendBatch(tasks);
|
|
172
|
+
console.log(\`\${batchResult.successfulTasks}/\${batchResult.totalTasks} successful\`);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
##### `testConnection()`
|
|
176
|
+
|
|
177
|
+
Test API connectivity and authentication.
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
const health = client.testConnection();
|
|
181
|
+
console.log("Agent:", health.agentName);
|
|
182
|
+
console.log("Status:", health.status);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
##### `getInterpretedTaskResult(taskId)`
|
|
186
|
+
|
|
187
|
+
Get AI-interpreted results for a task.
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
const result = client.getInterpretedTaskResult("task-uuid");
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### AsyncInfiniumClient (Asynchronous)
|
|
194
|
+
|
|
195
|
+
The async client has the same methods as the synchronous client, but all methods return Promises:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
const response = await client.sendTask(taskData);
|
|
199
|
+
const health = await client.testConnection();
|
|
200
|
+
const batchResult = await client.sendBatch(tasks);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### Additional Async Methods
|
|
204
|
+
|
|
205
|
+
##### `sendBatchSequential(tasks)`
|
|
206
|
+
|
|
207
|
+
Send tasks sequentially (better for strict rate limiting).
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
const batchResult = await client.sendBatchSequential(tasks);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
##### `close()`
|
|
214
|
+
|
|
215
|
+
Close the client and cleanup resources.
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
await client.close();
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Data Structures
|
|
222
|
+
|
|
223
|
+
### AgentType
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
enum AgentType {
|
|
227
|
+
OTHER = "OTHER",
|
|
228
|
+
EXECUTIVE_ASSISTANT = "EXECUTIVE_ASSISTANT",
|
|
229
|
+
MARKETING_ASSISTANT = "MARKETING_ASSISTANT",
|
|
230
|
+
DATA_ANALYST = "DATA_ANALYST",
|
|
231
|
+
RESEARCH_ASSISTANT = "RESEARCH_ASSISTANT",
|
|
232
|
+
CUSTOMER_SUPPORT_ASSISTANT = "CUSTOMER_SUPPORT_ASSISTANT",
|
|
233
|
+
CONTENT_CREATOR = "CONTENT_CREATOR",
|
|
234
|
+
SALES_ASSISTANT = "SALES_ASSISTANT",
|
|
235
|
+
PROJECT_MANAGER = "PROJECT_MANAGER",
|
|
236
|
+
DEVELOPMENT_ASSISTANT = "DEVELOPMENT_ASSISTANT",
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### TaskData Structure
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
interface TaskData {
|
|
244
|
+
name: string; // Required: Task name
|
|
245
|
+
description: string; // Required: Task description
|
|
246
|
+
currentDatetime: string; // Required: ISO 8601 timestamp
|
|
247
|
+
duration: number; // Required: Duration in seconds
|
|
248
|
+
agentType?: AgentType; // Optional: Agent type
|
|
249
|
+
|
|
250
|
+
// Optional specialized sections
|
|
251
|
+
timeTracking?: TimeTracking;
|
|
252
|
+
customer?: Customer;
|
|
253
|
+
support?: Support;
|
|
254
|
+
sales?: Sales;
|
|
255
|
+
marketing?: Marketing;
|
|
256
|
+
content?: Content;
|
|
257
|
+
research?: Research;
|
|
258
|
+
project?: Project;
|
|
259
|
+
development?: Development;
|
|
260
|
+
executive?: Executive;
|
|
261
|
+
general?: General;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Specialized Data Sections
|
|
266
|
+
|
|
267
|
+
#### Customer Information
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
interface Customer {
|
|
271
|
+
customerName?: string;
|
|
272
|
+
customerEmail?: string;
|
|
273
|
+
customerPhone?: string;
|
|
274
|
+
customerAddress?: string;
|
|
275
|
+
clientCompany?: string;
|
|
276
|
+
clientIndustry?: string;
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
#### Support Information
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
interface Support {
|
|
284
|
+
callId?: string;
|
|
285
|
+
issueDescription?: string;
|
|
286
|
+
issueType?: string;
|
|
287
|
+
resolution?: string;
|
|
288
|
+
status?: string;
|
|
289
|
+
priority?: string;
|
|
290
|
+
followUpRequired?: boolean;
|
|
291
|
+
agentNotes?: string;
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
#### Sales Information
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
interface Sales {
|
|
299
|
+
leadSource?: string;
|
|
300
|
+
salesStage?: string;
|
|
301
|
+
dealValue?: number;
|
|
302
|
+
conversionRate?: number;
|
|
303
|
+
salesNotes?: string;
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
#### Marketing Information
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
interface Marketing {
|
|
311
|
+
campaignName?: string;
|
|
312
|
+
campaignType?: string;
|
|
313
|
+
targetAudience?: string;
|
|
314
|
+
marketingChannel?: string;
|
|
315
|
+
engagementMetrics?: string;
|
|
316
|
+
conversionMetrics?: string;
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
[Additional interfaces for Content, Research, Project, Development, Executive, and General sections...]
|
|
321
|
+
|
|
322
|
+
## Error Handling
|
|
323
|
+
|
|
324
|
+
The SDK provides comprehensive error handling with specific error types:
|
|
325
|
+
|
|
326
|
+
### Error Types
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
import {
|
|
330
|
+
InfiniumError, // Base error class
|
|
331
|
+
AuthenticationError, // 401/403 errors
|
|
332
|
+
ValidationError, // Input validation errors
|
|
333
|
+
RateLimitError, // Rate limit exceeded
|
|
334
|
+
NetworkError, // Network/connection errors
|
|
335
|
+
TimeoutError, // Request timeout
|
|
336
|
+
ServerError, // Server errors (5xx)
|
|
337
|
+
NotFoundError, // 404 errors
|
|
338
|
+
BatchError, // Batch operation errors
|
|
339
|
+
} from "infinium";
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Error Handling Examples
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
try {
|
|
346
|
+
const response = await client.sendTask(taskData);
|
|
347
|
+
} catch (error) {
|
|
348
|
+
if (error instanceof AuthenticationError) {
|
|
349
|
+
console.error("Check your credentials");
|
|
350
|
+
} else if (error instanceof ValidationError) {
|
|
351
|
+
console.error("Invalid input:", error.field);
|
|
352
|
+
} else if (error instanceof RateLimitError) {
|
|
353
|
+
console.error("Rate limited, retry after:", error.retryAfter);
|
|
354
|
+
} else if (error instanceof NetworkError) {
|
|
355
|
+
console.error("Network issue:", error.originalError);
|
|
356
|
+
} else {
|
|
357
|
+
console.error("Unknown error:", error);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
## Advanced Usage
|
|
363
|
+
|
|
364
|
+
### Rate Limiting
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
// Configure rate limiting
|
|
368
|
+
const client = new AsyncInfiniumClient({
|
|
369
|
+
agentId: "your-agent-id",
|
|
370
|
+
agentSecret: "your-agent-secret",
|
|
371
|
+
enableRateLimiting: true,
|
|
372
|
+
requestsPerSecond: 5, // 5 requests per second
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// Rate limiting is handled automatically
|
|
376
|
+
for (let i = 0; i < 10; i++) {
|
|
377
|
+
await client.sendTask(taskData); // Will automatically throttle
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Batch Processing
|
|
382
|
+
|
|
383
|
+
```typescript
|
|
384
|
+
// Concurrent batch (faster, but may hit rate limits)
|
|
385
|
+
const concurrentResult = await client.sendBatch(tasks);
|
|
386
|
+
|
|
387
|
+
// Sequential batch (slower, but respects rate limits)
|
|
388
|
+
const sequentialResult = await client.sendBatchSequential(tasks);
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Custom Request Configuration
|
|
392
|
+
|
|
393
|
+
```typescript
|
|
394
|
+
const response = await client.sendTask(taskData, {
|
|
395
|
+
timeout: 60000, // 60 second timeout
|
|
396
|
+
headers: {
|
|
397
|
+
"X-Custom-Header": "value",
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Logging
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
const client = new InfiniumClient({
|
|
406
|
+
agentId: "your-agent-id",
|
|
407
|
+
agentSecret: "your-agent-secret",
|
|
408
|
+
enableLogging: true,
|
|
409
|
+
logLevel: "DEBUG", // DEBUG, INFO, WARN, ERROR
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
// Logs will include:
|
|
413
|
+
// - Request/response details
|
|
414
|
+
// - Rate limiting information
|
|
415
|
+
// - Retry attempts
|
|
416
|
+
// - Error details
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
## Examples
|
|
420
|
+
|
|
421
|
+
See the `examples/` directory for complete usage examples:
|
|
422
|
+
|
|
423
|
+
- `examples/basicUsage.ts` - Synchronous client examples
|
|
424
|
+
- `examples/asyncUsage.ts` - Asynchronous client examples with advanced patterns
|
|
425
|
+
|
|
426
|
+
## Testing
|
|
427
|
+
|
|
428
|
+
```bash
|
|
429
|
+
# Run tests
|
|
430
|
+
npm test
|
|
431
|
+
|
|
432
|
+
# Run with coverage
|
|
433
|
+
npm run test:coverage
|
|
434
|
+
|
|
435
|
+
# Watch mode
|
|
436
|
+
npm run test:watch
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
## Building from Source
|
|
440
|
+
|
|
441
|
+
```bash
|
|
442
|
+
# Install dependencies
|
|
443
|
+
npm install
|
|
444
|
+
|
|
445
|
+
# Build TypeScript
|
|
446
|
+
npm run build
|
|
447
|
+
|
|
448
|
+
# Lint code
|
|
449
|
+
npm run lint
|
|
450
|
+
|
|
451
|
+
# Format code
|
|
452
|
+
npm run format
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
## Authentication
|
|
456
|
+
|
|
457
|
+
The SDK authenticates with the Infinium API using your agent ID and agent secret:
|
|
458
|
+
|
|
459
|
+
1. Sign up for an Infinium account
|
|
460
|
+
2. Create an agent and get your credentials
|
|
461
|
+
3. Use the credentials in your SDK configuration
|
|
462
|
+
|
|
463
|
+
**Security Note**: Never commit your credentials to version control. Use environment variables or secure configuration management.
|
|
464
|
+
|
|
465
|
+
## API Endpoints
|
|
466
|
+
|
|
467
|
+
The SDK communicates with these API endpoints:
|
|
468
|
+
|
|
469
|
+
- `POST /agent/{agentId}/task` - Send task data
|
|
470
|
+
- `GET /agent/{agentId}/health` - Health check
|
|
471
|
+
- `GET /agent-tasks/{taskId}/interpreted-result` - Get interpreted results
|
|
472
|
+
- `GET /agent-tasks/{taskId}/custom-result` - Get custom schemas
|
|
473
|
+
|
|
474
|
+
## Rate Limits
|
|
475
|
+
|
|
476
|
+
- Default: 10 requests per second
|
|
477
|
+
- Configurable via `requestsPerSecond` option
|
|
478
|
+
- Automatic retry with exponential backoff
|
|
479
|
+
- Client-side rate limiting prevents server-side limits
|
|
480
|
+
|
|
481
|
+
## TypeScript Support
|
|
482
|
+
|
|
483
|
+
The SDK is written in TypeScript and provides complete type definitions:
|
|
484
|
+
|
|
485
|
+
```typescript
|
|
486
|
+
import { InfiniumClient, TaskData, AgentType, ApiResponse } from 'infinium';
|
|
487
|
+
|
|
488
|
+
// Full IntelliSense support
|
|
489
|
+
const client: InfiniumClient = new InfiniumClient({...});
|
|
490
|
+
const response: ApiResponse = client.sendTask({...});
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
## Browser Support
|
|
494
|
+
|
|
495
|
+
This SDK is designed for Node.js environments. For browser usage, consider:
|
|
496
|
+
|
|
497
|
+
- Server-side proxy to avoid CORS issues
|
|
498
|
+
- Environment variable substitution for credentials
|
|
499
|
+
- Bundle size optimization
|
|
500
|
+
|
|
501
|
+
## Migration from Python SDK
|
|
502
|
+
|
|
503
|
+
The Node.js SDK follows the same patterns as the Python SDK:
|
|
504
|
+
|
|
505
|
+
```python
|
|
506
|
+
# Python
|
|
507
|
+
from infinium_sdk import InfiniumClient, AgentType
|
|
508
|
+
|
|
509
|
+
client = InfiniumClient(agent_id="...", agent_secret="...")
|
|
510
|
+
response = client.send_task(name="...", duration=120, ...)
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
```typescript
|
|
514
|
+
// Node.js
|
|
515
|
+
import { InfiniumClient, AgentType } from 'infinium';
|
|
516
|
+
|
|
517
|
+
const client = new InfiniumClient({agentId: "...", agentSecret: "..."});
|
|
518
|
+
const response = client.sendTask({name: "...", duration: 120, ...});
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
## Contributing
|
|
522
|
+
|
|
523
|
+
1. Fork the repository
|
|
524
|
+
2. Create a feature branch
|
|
525
|
+
3. Make your changes
|
|
526
|
+
4. Add tests for new functionality
|
|
527
|
+
5. Run `npm run lint` and `npm test`
|
|
528
|
+
6. Submit a pull request
|
|
529
|
+
|
|
530
|
+
## License
|
|
531
|
+
|
|
532
|
+
MIT License - see LICENSE file for details.
|
|
533
|
+
|
|
534
|
+
## Support
|
|
535
|
+
|
|
536
|
+
For support and questions:
|
|
537
|
+
|
|
538
|
+
- 📧 Email: support@xyendigital.com
|
|
539
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/yourusername/infinium-npm-sdk/issues)
|
|
540
|
+
- 📚 Documentation: See this README for complete usage guide
|
|
541
|
+
|
|
542
|
+
## API Information
|
|
543
|
+
|
|
544
|
+
- **Base URL**: `https://api.i42m.ai/api/v1`
|
|
545
|
+
- **Authentication**: Agent ID and Agent Secret
|
|
546
|
+
- **Version**: v1
|
|
547
|
+
|
|
548
|
+
---
|
|
549
|
+
|
|
550
|
+
**Made with ❤️ by XyenDigital**
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronous client for Infinium API.
|
|
3
|
+
*/
|
|
4
|
+
import { TaskData, ApiResponse, HealthCheck, BatchResult, ClientConfig } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Asynchronous client for Infinium API.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { AsyncInfiniumClient, AgentType } from 'infinium';
|
|
11
|
+
*
|
|
12
|
+
* const client = new AsyncInfiniumClient({
|
|
13
|
+
* agentId: 'your-agent-id',
|
|
14
|
+
* agentSecret: 'your-agent-secret'
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Send a simple task
|
|
18
|
+
* const response = await client.sendTask({
|
|
19
|
+
* name: 'Process customer inquiry',
|
|
20
|
+
* description: 'Handled customer question about pricing',
|
|
21
|
+
* duration: 120.5
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Use with proper cleanup
|
|
25
|
+
* async function example() {
|
|
26
|
+
* const client = new AsyncInfiniumClient({
|
|
27
|
+
* agentId: 'your-agent-id',
|
|
28
|
+
* agentSecret: 'your-agent-secret'
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* try {
|
|
32
|
+
* const health = await client.testConnection();
|
|
33
|
+
* console.log('Connected:', health.agentName);
|
|
34
|
+
*
|
|
35
|
+
* const response = await client.sendTask({
|
|
36
|
+
* name: 'Marketing campaign analysis',
|
|
37
|
+
* description: 'Analyzed Q3 campaign performance',
|
|
38
|
+
* duration: 300.0,
|
|
39
|
+
* agentType: AgentType.MARKETING_ASSISTANT
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* console.log('Task sent:', response.success);
|
|
43
|
+
* } finally {
|
|
44
|
+
* await client.close();
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare class AsyncInfiniumClient {
|
|
50
|
+
private readonly agentId;
|
|
51
|
+
private readonly agentSecret;
|
|
52
|
+
private readonly baseUrl;
|
|
53
|
+
private readonly timeout;
|
|
54
|
+
private readonly maxRetries;
|
|
55
|
+
private readonly userAgent;
|
|
56
|
+
private readonly logger;
|
|
57
|
+
private readonly rateLimiter;
|
|
58
|
+
private readonly httpClient;
|
|
59
|
+
private closed;
|
|
60
|
+
/**
|
|
61
|
+
* Initialize the async Infinium client.
|
|
62
|
+
*/
|
|
63
|
+
constructor(config: ClientConfig);
|
|
64
|
+
/**
|
|
65
|
+
* Create and configure HTTP client.
|
|
66
|
+
*/
|
|
67
|
+
private createHttpClient;
|
|
68
|
+
/**
|
|
69
|
+
* Make HTTP request with proper error handling.
|
|
70
|
+
*/
|
|
71
|
+
private makeRequest;
|
|
72
|
+
/**
|
|
73
|
+
* Send task data to the API.
|
|
74
|
+
*/
|
|
75
|
+
sendTask(task: Omit<TaskData, 'currentDatetime'> & {
|
|
76
|
+
currentDatetime?: string;
|
|
77
|
+
}): Promise<ApiResponse>;
|
|
78
|
+
/**
|
|
79
|
+
* Send pre-built TaskData object.
|
|
80
|
+
*/
|
|
81
|
+
sendTaskData(taskData: TaskData): Promise<ApiResponse>;
|
|
82
|
+
/**
|
|
83
|
+
* Send multiple tasks in batch.
|
|
84
|
+
*/
|
|
85
|
+
sendBatch(tasks: TaskData[]): Promise<BatchResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Send tasks in sequential batch (for rate limiting).
|
|
88
|
+
*/
|
|
89
|
+
sendBatchSequential(tasks: TaskData[]): Promise<BatchResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Test connection to the API.
|
|
92
|
+
*/
|
|
93
|
+
testConnection(): Promise<HealthCheck>;
|
|
94
|
+
/**
|
|
95
|
+
* Get interpreted task result.
|
|
96
|
+
*/
|
|
97
|
+
getInterpretedTaskResult(taskId: string): Promise<ApiResponse>;
|
|
98
|
+
/**
|
|
99
|
+
* Get current ISO datetime string.
|
|
100
|
+
*/
|
|
101
|
+
getCurrentIsoDatetime(): string;
|
|
102
|
+
/**
|
|
103
|
+
* Get client configuration.
|
|
104
|
+
*/
|
|
105
|
+
getConfig(): Partial<ClientConfig>;
|
|
106
|
+
/**
|
|
107
|
+
* Check if client is closed.
|
|
108
|
+
*/
|
|
109
|
+
isClosed(): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Close the client and cleanup resources.
|
|
112
|
+
*/
|
|
113
|
+
close(): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Clean payload by removing undefined values.
|
|
116
|
+
*/
|
|
117
|
+
private cleanPayload;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=asyncClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncClient.d.ts","sourceRoot":"","sources":["../../src/asyncClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAEL,QAAQ,EACR,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EAab,MAAM,SAAS,CAAC;AA+BjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,qBAAa,mBAAmB;IAC9B,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,OAAO,CAAC,MAAM,CAAS;IAEvB;;OAEG;gBACS,MAAM,EAAE,YAAY;IAiChC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA0FxB;;OAEG;YACW,WAAW;IA2BzB;;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,EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;IAI5D;;OAEG;IACG,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAoExD;;OAEG;IACG,mBAAmB,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAgElE;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAkB5C;;OAEG;IACG,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAWpE;;OAEG;IACH,qBAAqB,IAAI,MAAM;IAI/B;;OAEG;IACH,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC;IAWlC;;OAEG;IACH,QAAQ,IAAI,OAAO;IAInB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B;;OAEG;IACH,OAAO,CAAC,YAAY;CAkBrB"}
|