@amaster.ai/client 1.1.0-beta.0 → 1.1.0-beta.2
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/README.md +198 -78
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/package.json +28 -8
- package/types/asr.d.ts +192 -0
- package/types/auth/code-auth.d.ts +254 -0
- package/types/auth/index.d.ts +180 -0
- package/types/auth/oauth.d.ts +280 -0
- package/types/auth/password-auth.d.ts +325 -0
- package/types/auth/permissions.d.ts +254 -0
- package/types/auth/profile.d.ts +163 -0
- package/types/auth/user.d.ts +97 -0
- package/types/copilot.d.ts +191 -0
- package/types/function.d.ts +118 -0
- package/types/index.d.ts +14 -2
- package/types/tts.d.ts +208 -0
- package/types/auth.d.ts +0 -674
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @amaster.ai/client
|
|
2
2
|
|
|
3
|
-
> Unified API client for the Amaster platform -
|
|
3
|
+
> Unified API client for the Amaster platform - All services in one package
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@amaster.ai/client)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -19,13 +19,25 @@ This package is designed with AI tools (GitHub Copilot, Cursor, etc.) in mind:
|
|
|
19
19
|
```
|
|
20
20
|
types/
|
|
21
21
|
├── index.d.ts # Main entry (lightweight)
|
|
22
|
-
├── auth
|
|
22
|
+
├── auth/ # Authentication (split into 7 focused modules)
|
|
23
|
+
│ ├── user.d.ts
|
|
24
|
+
│ ├── password-auth.d.ts
|
|
25
|
+
│ ├── code-auth.d.ts
|
|
26
|
+
│ ├── oauth.d.ts
|
|
27
|
+
│ ├── permissions.d.ts
|
|
28
|
+
│ ├── profile.d.ts
|
|
29
|
+
│ └── index.d.ts
|
|
23
30
|
├── entity.d.ts # Entity CRUD operations
|
|
24
31
|
├── bpm.d.ts # Business Process Management
|
|
25
|
-
|
|
32
|
+
├── workflow.d.ts # Workflow execution
|
|
33
|
+
├── asr.d.ts # Speech Recognition (WebSocket)
|
|
34
|
+
├── copilot.d.ts # AI Assistant / Chat
|
|
35
|
+
├── function.d.ts # Function invocation
|
|
36
|
+
└── tts.d.ts # Text-to-Speech (WebSocket)
|
|
26
37
|
```
|
|
27
38
|
|
|
28
39
|
Each module contains:
|
|
40
|
+
|
|
29
41
|
- Complete method signatures
|
|
30
42
|
- Parameter descriptions
|
|
31
43
|
- Return type definitions
|
|
@@ -41,6 +53,7 @@ Each module contains:
|
|
|
41
53
|
🔄 **Token auto-refresh** - never worry about expiration
|
|
42
54
|
📦 **Type-safe** - Full TypeScript support with auto-completion
|
|
43
55
|
🎯 **Simple API** - Clean, consistent method naming
|
|
56
|
+
🌐 **Complete Integration** - Auth, Entity, BPM, Workflow, ASR, Copilot, Function, TTS
|
|
44
57
|
|
|
45
58
|
## 📦 Installation
|
|
46
59
|
|
|
@@ -58,27 +71,27 @@ yarn add @amaster.ai/client axios
|
|
|
58
71
|
## 🎯 Quick Start
|
|
59
72
|
|
|
60
73
|
```typescript
|
|
61
|
-
import { createClient } from
|
|
74
|
+
import { createClient } from "@amaster.ai/client";
|
|
62
75
|
|
|
63
76
|
// 1. Create client instance
|
|
64
77
|
const client = createClient({
|
|
65
|
-
baseURL:
|
|
78
|
+
baseURL: "https://api.amaster.ai",
|
|
66
79
|
onUnauthorized: () => {
|
|
67
80
|
// Handle unauthorized (redirect to login, show modal, etc.)
|
|
68
|
-
window.location.href =
|
|
69
|
-
}
|
|
81
|
+
window.location.href = "/login";
|
|
82
|
+
},
|
|
70
83
|
});
|
|
71
84
|
|
|
72
85
|
// 2. Login
|
|
73
86
|
await client.auth.login({
|
|
74
|
-
email:
|
|
75
|
-
password:
|
|
87
|
+
email: "user@example.com",
|
|
88
|
+
password: "password123",
|
|
76
89
|
});
|
|
77
90
|
|
|
78
91
|
// 3. Use any service - auth token is automatically attached!
|
|
79
|
-
const users = await client.entity.list(
|
|
92
|
+
const users = await client.entity.list("default", "users");
|
|
80
93
|
const tasks = await client.bpm.getMyTasks();
|
|
81
|
-
const result = await client.workflow.execute(
|
|
94
|
+
const result = await client.workflow.execute("my-workflow", { input: {} });
|
|
82
95
|
```
|
|
83
96
|
|
|
84
97
|
## 🔑 Authentication
|
|
@@ -88,12 +101,12 @@ const result = await client.workflow.execute('my-workflow', { input: {} });
|
|
|
88
101
|
```typescript
|
|
89
102
|
// Email/Password login
|
|
90
103
|
const result = await client.auth.login({
|
|
91
|
-
email:
|
|
92
|
-
password:
|
|
104
|
+
email: "user@example.com",
|
|
105
|
+
password: "password123",
|
|
93
106
|
});
|
|
94
107
|
|
|
95
108
|
if (result.success) {
|
|
96
|
-
console.log(
|
|
109
|
+
console.log("Logged in:", result.data.user);
|
|
97
110
|
}
|
|
98
111
|
```
|
|
99
112
|
|
|
@@ -101,9 +114,9 @@ if (result.success) {
|
|
|
101
114
|
|
|
102
115
|
```typescript
|
|
103
116
|
const result = await client.auth.register({
|
|
104
|
-
username:
|
|
105
|
-
email:
|
|
106
|
-
password:
|
|
117
|
+
username: "johndoe",
|
|
118
|
+
email: "john@example.com",
|
|
119
|
+
password: "securePassword123",
|
|
107
120
|
});
|
|
108
121
|
```
|
|
109
122
|
|
|
@@ -112,7 +125,7 @@ const result = await client.auth.register({
|
|
|
112
125
|
```typescript
|
|
113
126
|
const result = await client.auth.getMe();
|
|
114
127
|
if (result.success) {
|
|
115
|
-
console.log(
|
|
128
|
+
console.log("Current user:", result.data);
|
|
116
129
|
}
|
|
117
130
|
```
|
|
118
131
|
|
|
@@ -126,7 +139,7 @@ await client.auth.logout();
|
|
|
126
139
|
|
|
127
140
|
```typescript
|
|
128
141
|
if (client.isAuthenticated()) {
|
|
129
|
-
console.log(
|
|
142
|
+
console.log("User is logged in");
|
|
130
143
|
}
|
|
131
144
|
```
|
|
132
145
|
|
|
@@ -137,14 +150,14 @@ Full CRUD operations for your data entities with type safety.
|
|
|
137
150
|
### List Entities
|
|
138
151
|
|
|
139
152
|
```typescript
|
|
140
|
-
const result = await client.entity.list(
|
|
153
|
+
const result = await client.entity.list("default", "users", {
|
|
141
154
|
page: 1,
|
|
142
155
|
perPage: 20,
|
|
143
|
-
orderBy:
|
|
144
|
-
orderDir:
|
|
156
|
+
orderBy: "createdAt",
|
|
157
|
+
orderDir: "desc",
|
|
145
158
|
// Filters
|
|
146
|
-
|
|
147
|
-
|
|
159
|
+
"status[eq]": "active",
|
|
160
|
+
"age[gt]": 18,
|
|
148
161
|
});
|
|
149
162
|
|
|
150
163
|
if (result.success) {
|
|
@@ -156,48 +169,48 @@ if (result.success) {
|
|
|
156
169
|
### Get Single Entity
|
|
157
170
|
|
|
158
171
|
```typescript
|
|
159
|
-
const result = await client.entity.get(
|
|
172
|
+
const result = await client.entity.get("default", "users", 123);
|
|
160
173
|
if (result.success) {
|
|
161
|
-
console.log(
|
|
174
|
+
console.log("User:", result.data);
|
|
162
175
|
}
|
|
163
176
|
```
|
|
164
177
|
|
|
165
178
|
### Create Entity
|
|
166
179
|
|
|
167
180
|
```typescript
|
|
168
|
-
const result = await client.entity.create(
|
|
169
|
-
name:
|
|
170
|
-
email:
|
|
171
|
-
status:
|
|
181
|
+
const result = await client.entity.create("default", "users", {
|
|
182
|
+
name: "John Doe",
|
|
183
|
+
email: "john@example.com",
|
|
184
|
+
status: "active",
|
|
172
185
|
});
|
|
173
186
|
```
|
|
174
187
|
|
|
175
188
|
### Update Entity
|
|
176
189
|
|
|
177
190
|
```typescript
|
|
178
|
-
const result = await client.entity.update(
|
|
179
|
-
name:
|
|
180
|
-
status:
|
|
191
|
+
const result = await client.entity.update("default", "users", 123, {
|
|
192
|
+
name: "Jane Doe",
|
|
193
|
+
status: "inactive",
|
|
181
194
|
});
|
|
182
195
|
```
|
|
183
196
|
|
|
184
197
|
### Delete Entity
|
|
185
198
|
|
|
186
199
|
```typescript
|
|
187
|
-
await client.entity.delete(
|
|
200
|
+
await client.entity.delete("default", "users", 123);
|
|
188
201
|
```
|
|
189
202
|
|
|
190
203
|
### Bulk Operations
|
|
191
204
|
|
|
192
205
|
```typescript
|
|
193
206
|
// Bulk update
|
|
194
|
-
await client.entity.bulkUpdate(
|
|
195
|
-
{ id: 1, status:
|
|
196
|
-
{ id: 2, status:
|
|
207
|
+
await client.entity.bulkUpdate("default", "users", [
|
|
208
|
+
{ id: 1, status: "active" },
|
|
209
|
+
{ id: 2, status: "inactive" },
|
|
197
210
|
]);
|
|
198
211
|
|
|
199
212
|
// Bulk delete
|
|
200
|
-
await client.entity.bulkDelete(
|
|
213
|
+
await client.entity.bulkDelete("default", "users", [1, 2, 3]);
|
|
201
214
|
```
|
|
202
215
|
|
|
203
216
|
## 🔄 BPM (Business Process Management)
|
|
@@ -208,12 +221,12 @@ Manage business processes powered by Camunda 7.
|
|
|
208
221
|
|
|
209
222
|
```typescript
|
|
210
223
|
const result = await client.bpm.startProcess({
|
|
211
|
-
processKey:
|
|
212
|
-
businessKey:
|
|
224
|
+
processKey: "approval-process",
|
|
225
|
+
businessKey: "ORDER-12345",
|
|
213
226
|
variables: {
|
|
214
227
|
amount: 1000,
|
|
215
|
-
requester:
|
|
216
|
-
}
|
|
228
|
+
requester: "john@example.com",
|
|
229
|
+
},
|
|
217
230
|
});
|
|
218
231
|
```
|
|
219
232
|
|
|
@@ -223,28 +236,28 @@ const result = await client.bpm.startProcess({
|
|
|
223
236
|
const result = await client.bpm.getMyTasks({
|
|
224
237
|
page: 1,
|
|
225
238
|
perPage: 20,
|
|
226
|
-
sortBy:
|
|
227
|
-
sortOrder:
|
|
239
|
+
sortBy: "created",
|
|
240
|
+
sortOrder: "desc",
|
|
228
241
|
});
|
|
229
242
|
|
|
230
243
|
if (result.success) {
|
|
231
|
-
console.log(
|
|
244
|
+
console.log("Tasks:", result.data.items);
|
|
232
245
|
}
|
|
233
246
|
```
|
|
234
247
|
|
|
235
248
|
### Complete a Task
|
|
236
249
|
|
|
237
250
|
```typescript
|
|
238
|
-
await client.bpm.completeTask(
|
|
251
|
+
await client.bpm.completeTask("task-id", {
|
|
239
252
|
approved: true,
|
|
240
|
-
comments:
|
|
253
|
+
comments: "Looks good!",
|
|
241
254
|
});
|
|
242
255
|
```
|
|
243
256
|
|
|
244
257
|
### Claim a Task
|
|
245
258
|
|
|
246
259
|
```typescript
|
|
247
|
-
await client.bpm.claimTask(
|
|
260
|
+
await client.bpm.claimTask("task-id");
|
|
248
261
|
```
|
|
249
262
|
|
|
250
263
|
## ⚡ Workflow Execution
|
|
@@ -252,15 +265,15 @@ await client.bpm.claimTask('task-id');
|
|
|
252
265
|
Execute workflows and automation flows.
|
|
253
266
|
|
|
254
267
|
```typescript
|
|
255
|
-
const result = await client.workflow.execute(
|
|
268
|
+
const result = await client.workflow.execute("data-processing-workflow", {
|
|
256
269
|
input: {
|
|
257
|
-
dataSource:
|
|
258
|
-
filters: { status:
|
|
259
|
-
}
|
|
270
|
+
dataSource: "users",
|
|
271
|
+
filters: { status: "active" },
|
|
272
|
+
},
|
|
260
273
|
});
|
|
261
274
|
|
|
262
275
|
if (result.success) {
|
|
263
|
-
console.log(
|
|
276
|
+
console.log("Workflow result:", result.data);
|
|
264
277
|
}
|
|
265
278
|
```
|
|
266
279
|
|
|
@@ -294,23 +307,23 @@ interface AmasterClientOptions {
|
|
|
294
307
|
|
|
295
308
|
```typescript
|
|
296
309
|
const client = createClient({
|
|
297
|
-
baseURL:
|
|
298
|
-
|
|
310
|
+
baseURL: "https://api.amaster.ai",
|
|
311
|
+
|
|
299
312
|
headers: {
|
|
300
|
-
|
|
313
|
+
"X-App-Version": "1.0.0",
|
|
301
314
|
},
|
|
302
|
-
|
|
315
|
+
|
|
303
316
|
onUnauthorized: () => {
|
|
304
|
-
console.log(
|
|
305
|
-
window.location.href =
|
|
317
|
+
console.log("Session expired, redirecting to login...");
|
|
318
|
+
window.location.href = "/login";
|
|
306
319
|
},
|
|
307
|
-
|
|
320
|
+
|
|
308
321
|
onTokenExpired: () => {
|
|
309
|
-
console.log(
|
|
322
|
+
console.log("Token expired, will auto-refresh");
|
|
310
323
|
},
|
|
311
|
-
|
|
324
|
+
|
|
312
325
|
autoRefresh: true,
|
|
313
|
-
refreshThreshold: 300 // Refresh 5 minutes before expiry
|
|
326
|
+
refreshThreshold: 300, // Refresh 5 minutes before expiry
|
|
314
327
|
});
|
|
315
328
|
```
|
|
316
329
|
|
|
@@ -323,7 +336,7 @@ const client = createClient({
|
|
|
323
336
|
const token = client.getAccessToken();
|
|
324
337
|
|
|
325
338
|
// Set token manually (useful for SSR or external auth)
|
|
326
|
-
client.setAccessToken(
|
|
339
|
+
client.setAccessToken("your-jwt-token");
|
|
327
340
|
|
|
328
341
|
// Clear all auth data
|
|
329
342
|
client.clearAuth();
|
|
@@ -332,15 +345,15 @@ client.clearAuth();
|
|
|
332
345
|
### Error Handling
|
|
333
346
|
|
|
334
347
|
```typescript
|
|
335
|
-
const result = await client.entity.list(
|
|
348
|
+
const result = await client.entity.list("default", "users");
|
|
336
349
|
|
|
337
350
|
if (result.success) {
|
|
338
351
|
// Success case
|
|
339
|
-
console.log(
|
|
352
|
+
console.log("Data:", result.data);
|
|
340
353
|
} else {
|
|
341
354
|
// Error case
|
|
342
|
-
console.error(
|
|
343
|
-
console.error(
|
|
355
|
+
console.error("Error:", result.error);
|
|
356
|
+
console.error("Status:", result.statusCode);
|
|
344
357
|
}
|
|
345
358
|
```
|
|
346
359
|
|
|
@@ -349,9 +362,9 @@ if (result.success) {
|
|
|
349
362
|
### Before (Using separate clients)
|
|
350
363
|
|
|
351
364
|
```typescript
|
|
352
|
-
import { createAuthClient } from
|
|
353
|
-
import { createEntityClient } from
|
|
354
|
-
import { createBpmClient } from
|
|
365
|
+
import { createAuthClient } from "@amaster.ai/auth-client";
|
|
366
|
+
import { createEntityClient } from "@amaster.ai/entity-client";
|
|
367
|
+
import { createBpmClient } from "@amaster.ai/bpm-client";
|
|
355
368
|
|
|
356
369
|
const authClient = createAuthClient({ baseURL });
|
|
357
370
|
const entityClient = createEntityClient({ baseURL });
|
|
@@ -367,13 +380,13 @@ const token = authClient.getAccessToken();
|
|
|
367
380
|
### After (Using unified client)
|
|
368
381
|
|
|
369
382
|
```typescript
|
|
370
|
-
import { createClient } from
|
|
383
|
+
import { createClient } from "@amaster.ai/client";
|
|
371
384
|
|
|
372
385
|
const client = createClient({ baseURL });
|
|
373
386
|
|
|
374
387
|
// One client, automatic token management
|
|
375
388
|
await client.auth.login({ email, password });
|
|
376
|
-
await client.entity.list(
|
|
389
|
+
await client.entity.list("default", "users"); // Token automatically attached
|
|
377
390
|
await client.bpm.getMyTasks(); // Token automatically attached
|
|
378
391
|
```
|
|
379
392
|
|
|
@@ -426,6 +439,107 @@ Workflow execution API from `@amaster.ai/workflow-client`:
|
|
|
426
439
|
- `getStatus(executionId)` - Get execution status
|
|
427
440
|
- And more...
|
|
428
441
|
|
|
442
|
+
### `client.asr`
|
|
443
|
+
|
|
444
|
+
Real-time speech recognition API from `@amaster.ai/asr-client`:
|
|
445
|
+
|
|
446
|
+
- `connect()` - Connect to ASR service via WebSocket
|
|
447
|
+
- `startRecording()` - Start microphone recording
|
|
448
|
+
- `stopRecording()` - Stop recording
|
|
449
|
+
- `close()` - Close connection
|
|
450
|
+
|
|
451
|
+
**Example:**
|
|
452
|
+
|
|
453
|
+
```typescript
|
|
454
|
+
// Configure callbacks
|
|
455
|
+
client.asr = createASRClient({
|
|
456
|
+
onTranscript: (text, isFinal) => {
|
|
457
|
+
console.log(isFinal ? `[FINAL] ${text}` : `[INTERIM] ${text}`);
|
|
458
|
+
},
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
// Connect and start
|
|
462
|
+
await client.asr.connect();
|
|
463
|
+
await client.asr.startRecording();
|
|
464
|
+
|
|
465
|
+
// Stop when done
|
|
466
|
+
client.asr.stopRecording();
|
|
467
|
+
client.asr.close();
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### `client.copilot`
|
|
471
|
+
|
|
472
|
+
AI assistant / chatbot API from `@amaster.ai/copilot-client`:
|
|
473
|
+
|
|
474
|
+
- `sendMessage(messages, options?)` - Send messages to AI assistant
|
|
475
|
+
|
|
476
|
+
**Example:**
|
|
477
|
+
|
|
478
|
+
```typescript
|
|
479
|
+
// Simple chat
|
|
480
|
+
const result = await client.copilot.sendMessage([
|
|
481
|
+
{ role: "user", content: "Hello, how can you help?" },
|
|
482
|
+
]);
|
|
483
|
+
|
|
484
|
+
console.log(result.data.content);
|
|
485
|
+
|
|
486
|
+
// Streaming response
|
|
487
|
+
await client.copilot.sendMessage(
|
|
488
|
+
[{ role: "user", content: "Tell me a story" }],
|
|
489
|
+
{
|
|
490
|
+
stream: true,
|
|
491
|
+
onChunk: (chunk) => console.log(chunk),
|
|
492
|
+
}
|
|
493
|
+
);
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
### `client.function`
|
|
497
|
+
|
|
498
|
+
Function invocation API from `@amaster.ai/function-client`:
|
|
499
|
+
|
|
500
|
+
- `invoke<T>(funcName, params?)` - Invoke a serverless function
|
|
501
|
+
|
|
502
|
+
**Example:**
|
|
503
|
+
|
|
504
|
+
```typescript
|
|
505
|
+
// Call a function
|
|
506
|
+
const result = await client.function.invoke<{ result: string }>("sendEmail", {
|
|
507
|
+
to: "user@example.com",
|
|
508
|
+
subject: "Hello",
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
if (result.data) {
|
|
512
|
+
console.log("Function result:", result.data.result);
|
|
513
|
+
}
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### `client.tts`
|
|
517
|
+
|
|
518
|
+
Real-time text-to-speech API from `@amaster.ai/tts-client`:
|
|
519
|
+
|
|
520
|
+
- `connect()` - Connect to TTS service via WebSocket
|
|
521
|
+
- `speak(text)` - Synthesize and play speech
|
|
522
|
+
- `play()` - Manually play audio (when autoPlay is off)
|
|
523
|
+
- `close()` - Close connection
|
|
524
|
+
|
|
525
|
+
**Example:**
|
|
526
|
+
|
|
527
|
+
```typescript
|
|
528
|
+
// Configure TTS
|
|
529
|
+
client.tts = createTTSClient({
|
|
530
|
+
voice: "Cherry",
|
|
531
|
+
autoPlay: true,
|
|
532
|
+
onAudioStart: () => console.log("Playing audio"),
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
// Connect and speak
|
|
536
|
+
await client.tts.connect();
|
|
537
|
+
await client.tts.speak("Hello, welcome to Amaster!");
|
|
538
|
+
|
|
539
|
+
// Close when done
|
|
540
|
+
client.tts.close();
|
|
541
|
+
```
|
|
542
|
+
|
|
429
543
|
## 🔐 Token Management Flow
|
|
430
544
|
|
|
431
545
|
```
|
|
@@ -452,11 +566,17 @@ MIT © Amaster Team
|
|
|
452
566
|
|
|
453
567
|
## 🤝 Related Packages
|
|
454
568
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
- `@amaster.ai/
|
|
458
|
-
- `@amaster.ai/
|
|
459
|
-
- `@amaster.ai/
|
|
569
|
+
All these packages are now integrated into `@amaster.ai/client`:
|
|
570
|
+
|
|
571
|
+
- `@amaster.ai/auth-client` - Authentication (login, register, etc.)
|
|
572
|
+
- `@amaster.ai/entity-client` - Entity CRUD operations
|
|
573
|
+
- `@amaster.ai/bpm-client` - Business Process Management
|
|
574
|
+
- `@amaster.ai/workflow-client` - Workflow execution
|
|
575
|
+
- `@amaster.ai/asr-client` - Speech recognition (WebSocket)
|
|
576
|
+
- `@amaster.ai/copilot-client` - AI assistant / chatbot
|
|
577
|
+
- `@amaster.ai/function-client` - Function invocation
|
|
578
|
+
- `@amaster.ai/tts-client` - Text-to-speech (WebSocket)
|
|
579
|
+
- `@amaster.ai/http-client` - HTTP client foundation (internal)
|
|
460
580
|
|
|
461
581
|
## 💡 Inspiration
|
|
462
582
|
|
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,10 @@ var authClient = require('@amaster.ai/auth-client');
|
|
|
4
4
|
var entityClient = require('@amaster.ai/entity-client');
|
|
5
5
|
var bpmClient = require('@amaster.ai/bpm-client');
|
|
6
6
|
var workflowClient = require('@amaster.ai/workflow-client');
|
|
7
|
+
var asrClient = require('@amaster.ai/asr-client');
|
|
8
|
+
var copilotClient = require('@amaster.ai/copilot-client');
|
|
9
|
+
var functionClient = require('@amaster.ai/function-client');
|
|
10
|
+
var ttsClient = require('@amaster.ai/tts-client');
|
|
7
11
|
var httpClient = require('@amaster.ai/http-client');
|
|
8
12
|
|
|
9
13
|
// src/client.ts
|
|
@@ -43,11 +47,19 @@ function createClient(options) {
|
|
|
43
47
|
const entity = entityClient.createEntityClient(authenticatedHttpClient);
|
|
44
48
|
const bpm = bpmClient.createBpmClient(authenticatedHttpClient);
|
|
45
49
|
const workflow = workflowClient.createWorkflowClient(authenticatedHttpClient);
|
|
50
|
+
const functionClient$1 = functionClient.createFunctionClient(authenticatedHttpClient);
|
|
51
|
+
const copilot = copilotClient.createCopilotA2UIClient(authenticatedHttpClient);
|
|
52
|
+
const asr = asrClient.createASRClient({});
|
|
53
|
+
const tts = ttsClient.createTTSClient({});
|
|
46
54
|
const client = {
|
|
47
55
|
auth,
|
|
48
56
|
entity,
|
|
49
57
|
bpm,
|
|
50
58
|
workflow,
|
|
59
|
+
asr,
|
|
60
|
+
copilot,
|
|
61
|
+
function: functionClient$1,
|
|
62
|
+
tts,
|
|
51
63
|
// Expose token management methods from auth client
|
|
52
64
|
isAuthenticated: () => auth.isAuthenticated(),
|
|
53
65
|
getAccessToken: () => auth.getAccessToken(),
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"names":["createHttpClient","createAuthClient","createEntityClient","createBpmClient","createWorkflowClient"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":["createHttpClient","createAuthClient","createEntityClient","createBpmClient","createWorkflowClient","functionClient","createFunctionClient","createCopilotA2UIClient","createASRClient","createTTSClient"],"mappings":";;;;;;;;;;;;;AAqFO,SAAS,aAAa,OAAA,EAA8C;AACzE,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,GAAU,EAAC,EAAG,cAAA,EAAgB,gBAAe,GAAI,OAAA;AAGlE,EAAA,MAAM,iBAAiBA,2BAAA,CAAiB;AAAA,IACtC,OAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,OAAmBC,2BAAA,CAAiB;AAAA,IACxC,OAAA;AAAA,IACA,OAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,gCAAgC,MAAkB;AACtD,IAAA,OAAO;AAAA,MACL,MAAM,QAAW,MAAA,EAAiD;AAEhE,QAAA,MAAM,KAAA,GAAQ,KAAK,cAAA,EAAe;AAGlC,QAAA,MAAM,WAAA,GAAc,QAAQ,EAAE,aAAA,EAAe,UAAU,KAAK,CAAA,CAAA,KAAO,EAAC;AACpE,QAAA,MAAM,YAAA,GAA8B;AAAA,UAClC,GAAG,MAAA;AAAA,UACH,OAAA,EAAS;AAAA,YACP,GAAG,MAAA,CAAO,OAAA;AAAA,YACV,GAAG;AAAA;AACL,SACF;AAGA,QAAA,MAAM,MAAA,GAAS,MAAM,cAAA,CAAe,OAAA,CAAW,YAAY,CAAA;AAG3D,QAAA,IAAI,MAAA,CAAO,MAAA,KAAW,GAAA,IAAO,cAAA,EAAgB;AAC3C,UAAA,cAAA,EAAe;AAAA,QACjB;AAEA,QAAA,OAAO,MAAA;AAAA,MACT;AAAA,KACF;AAAA,EACF,CAAA;AAGA,EAAA,MAAM,0BAA0B,6BAAA,EAA8B;AAG9D,EAAA,MAAM,MAAA,GAAuBC,gCAAmB,uBAAuB,CAAA;AACvE,EAAA,MAAM,GAAA,GAAiBC,0BAAgB,uBAAuB,CAAA;AAC9D,EAAA,MAAM,QAAA,GAA2BC,oCAAqB,uBAAuB,CAAA;AAC7E,EAAA,MAAMC,gBAAA,GAAiCC,oCAAqB,uBAAuB,CAAA;AACnF,EAAA,MAAM,OAAA,GAA6BC,sCAAwB,uBAAuB,CAAA;AAIlF,EAAA,MAAM,GAAA,GAAiBC,yBAAA,CAAgB,EAAE,CAAA;AACzC,EAAA,MAAM,GAAA,GAAiBC,yBAAA,CAAgB,EAAE,CAAA;AAGzC,EAAA,MAAM,MAAA,GAAwB;AAAA,IAC5B,IAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,EAAUJ,gBAAA;AAAA,IACV,GAAA;AAAA;AAAA,IAGA,eAAA,EAAiB,MAAM,IAAA,CAAK,eAAA,EAAgB;AAAA,IAC5C,cAAA,EAAgB,MAAM,IAAA,CAAK,cAAA,EAAe;AAAA,IAC1C,cAAA,EAAgB,CAAC,KAAA,KAAkB,IAAA,CAAK,eAAe,KAAK,CAAA;AAAA,IAC5D,SAAA,EAAW,MAAM,IAAA,CAAK,SAAA;AAAU,GAClC;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * ============================================================================\n * @amaster.ai/client - Unified Amaster Client\n * ============================================================================\n * \n * Supabase-inspired unified API client for the Amaster platform\n * \n * Features:\n * - Single client instance for all services (auth, entity, bpm, workflow)\n * - Automatic token management and refresh\n * - Auto-attach authentication to all requests\n * - Centralized error handling\n * \n * @example\n * ```typescript\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => window.location.href = '/login'\n * });\n * \n * // Login\n * await client.auth.login({ email, password });\n * \n * // All subsequent requests automatically include auth token\n * await client.entity.list('default', 'users');\n * await client.bpm.startProcess({ processKey: 'approval' });\n * ```\n */\n\nimport { createAuthClient, type AuthClient } from \"@amaster.ai/auth-client\";\nimport { createEntityClient, type EntityClient } from \"@amaster.ai/entity-client\";\nimport { createBpmClient, type BpmClient } from \"@amaster.ai/bpm-client\";\nimport { createWorkflowClient, type WorkflowClient } from \"@amaster.ai/workflow-client\";\nimport { createASRClient, type ASRClient } from \"@amaster.ai/asr-client\";\nimport { createCopilotA2UIClient, type CopilotA2UIClient } from \"@amaster.ai/copilot-client\";\nimport { createFunctionClient, type FunctionClient } from \"@amaster.ai/function-client\";\nimport { createTTSClient, type TTSClient } from \"@amaster.ai/tts-client\";\nimport { createHttpClient, type HttpClient, type RequestConfig, type ClientResult } from \"@amaster.ai/http-client\";\nimport type { AmasterClient, AmasterClientOptions } from \"./types\";\n\n/**\n * Create a unified Amaster client instance\n * \n * This function creates a single client that provides access to all Amaster services:\n * - Authentication (login, register, logout)\n * - Entity CRUD operations\n * - BPM (Business Process Management)\n * - Workflow execution\n * \n * All sub-clients automatically share the same HTTP client and authentication state,\n * ensuring that tokens are consistently attached to all requests.\n * \n * @param options - Client configuration options\n * @returns A unified Amaster client instance\n * \n * @example\n * ```typescript\n * // Basic usage\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai'\n * });\n * \n * // With authentication callbacks\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => {\n * // Redirect to login or show auth modal\n * window.location.href = '/login';\n * },\n * onTokenExpired: () => {\n * console.log('Token expired, refreshing...');\n * }\n * });\n * \n * // Login\n * await client.auth.login({\n * email: 'user@example.com',\n * password: 'password123'\n * });\n * \n * // Now all requests automatically include the auth token\n * const users = await client.entity.list('default', 'users');\n * const tasks = await client.bpm.getMyTasks();\n * ```\n */\nexport function createClient(options: AmasterClientOptions): AmasterClient {\n const { baseURL, headers = {}, onUnauthorized, onTokenExpired } = options;\n\n // Create the base HTTP client\n const baseHttpClient = createHttpClient({\n baseURL,\n headers,\n });\n\n // Create the auth client first (it manages its own HTTP client internally)\n const auth: AuthClient = createAuthClient({\n baseURL,\n headers,\n onTokenExpired,\n onUnauthorized,\n });\n\n // Create a wrapper HTTP client that automatically adds the auth token\n const createAuthenticatedHttpClient = (): HttpClient => {\n return {\n async request<T>(config: RequestConfig): Promise<ClientResult<T>> {\n // Get the current token from auth client\n const token = auth.getAccessToken();\n \n // Merge Authorization header with existing headers\n const authHeaders = token ? { Authorization: `Bearer ${token}` } : {};\n const mergedConfig: RequestConfig = {\n ...config,\n headers: {\n ...config.headers,\n ...authHeaders,\n },\n };\n\n // Make the request with the updated config\n const result = await baseHttpClient.request<T>(mergedConfig);\n\n // Handle 401 errors\n if (result.status === 401 && onUnauthorized) {\n onUnauthorized();\n }\n\n return result;\n },\n };\n };\n\n // Create the authenticated HTTP client\n const authenticatedHttpClient = createAuthenticatedHttpClient();\n\n // Create other clients using the authenticated HTTP client\n const entity: EntityClient = createEntityClient(authenticatedHttpClient);\n const bpm: BpmClient = createBpmClient(authenticatedHttpClient);\n const workflow: WorkflowClient = createWorkflowClient(authenticatedHttpClient);\n const functionClient: FunctionClient = createFunctionClient(authenticatedHttpClient);\n const copilot: CopilotA2UIClient = createCopilotA2UIClient(authenticatedHttpClient);\n\n // ASR and TTS clients use WebSocket, create with default config\n // Users can reconfigure by accessing client.asr / client.tts directly\n const asr: ASRClient = createASRClient({});\n const tts: TTSClient = createTTSClient({});\n\n // Return unified client interface\n const client: AmasterClient = {\n auth,\n entity,\n bpm,\n workflow,\n asr,\n copilot,\n function: functionClient,\n tts,\n\n // Expose token management methods from auth client\n isAuthenticated: () => auth.isAuthenticated(),\n getAccessToken: () => auth.getAccessToken(),\n setAccessToken: (token: string) => auth.setAccessToken(token),\n clearAuth: () => auth.clearAuth(),\n };\n\n return client;\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,14 @@ import { BpmClient } from '@amaster.ai/bpm-client';
|
|
|
6
6
|
export { CamundaVariable, HistoryProcessInstance, HistoryTask, ProcessInstance, ProcessVariable, Task, TaskFormSchema, TaskQueryParams } from '@amaster.ai/bpm-client';
|
|
7
7
|
import { WorkflowClient } from '@amaster.ai/workflow-client';
|
|
8
8
|
export { WorkflowFile, WorkflowInputValue, WorkflowRunRequest, WorkflowRunResponse } from '@amaster.ai/workflow-client';
|
|
9
|
+
import { ASRClient } from '@amaster.ai/asr-client';
|
|
10
|
+
export { ASRClient, ASRClientConfig } from '@amaster.ai/asr-client';
|
|
11
|
+
import { CopilotA2UIClient } from '@amaster.ai/copilot-client';
|
|
12
|
+
export { ChatMessage, ChatOptions, CopilotA2UIClient, FileContent, ImageContent, MessageContent, TextContent } from '@amaster.ai/copilot-client';
|
|
13
|
+
import { FunctionClient } from '@amaster.ai/function-client';
|
|
14
|
+
export { FunctionClient } from '@amaster.ai/function-client';
|
|
15
|
+
import { TTSClient } from '@amaster.ai/tts-client';
|
|
16
|
+
export { TTSClient, TTSClientConfig } from '@amaster.ai/tts-client';
|
|
9
17
|
export { ClientError, ClientResult } from '@amaster.ai/http-client';
|
|
10
18
|
|
|
11
19
|
/**
|
|
@@ -125,6 +133,61 @@ interface AmasterClient {
|
|
|
125
133
|
* ```
|
|
126
134
|
*/
|
|
127
135
|
workflow: WorkflowClient;
|
|
136
|
+
/**
|
|
137
|
+
* ASR (Automatic Speech Recognition) module
|
|
138
|
+
* WebSocket-based real-time speech recognition
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // Connect and start recording
|
|
143
|
+
* await client.asr.connect();
|
|
144
|
+
* await client.asr.startRecording();
|
|
145
|
+
*
|
|
146
|
+
* // Stop and close
|
|
147
|
+
* client.asr.stopRecording();
|
|
148
|
+
* client.asr.close();
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
asr: ASRClient;
|
|
152
|
+
/**
|
|
153
|
+
* Copilot AI assistant module
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // Send a message
|
|
158
|
+
* const result = await client.copilot.sendMessage([
|
|
159
|
+
* { role: 'user', content: 'Hello' }
|
|
160
|
+
* ]);
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
copilot: CopilotA2UIClient;
|
|
164
|
+
/**
|
|
165
|
+
* Function invocation module
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // Call a function
|
|
170
|
+
* const result = await client.function.invoke('myFunction', {
|
|
171
|
+
* param: 'value'
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
function: FunctionClient;
|
|
176
|
+
/**
|
|
177
|
+
* TTS (Text-to-Speech) module
|
|
178
|
+
* WebSocket-based real-time speech synthesis
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* // Connect and speak
|
|
183
|
+
* await client.tts.connect();
|
|
184
|
+
* await client.tts.speak('Hello world');
|
|
185
|
+
*
|
|
186
|
+
* // Close connection
|
|
187
|
+
* client.tts.close();
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
tts: TTSClient;
|
|
128
191
|
/**
|
|
129
192
|
* Check if the user is currently authenticated
|
|
130
193
|
*/
|