@amaster.ai/client 1.1.0-beta.1 → 1.1.0-beta.16

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @amaster.ai/client
2
2
 
3
- > Unified API client for the Amaster platform - Supabase-style developer experience
3
+ > Unified API client for the Amaster platform - All services in one package
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@amaster.ai/client.svg)](https://www.npmjs.com/package/@amaster.ai/client)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
@@ -19,10 +19,21 @@ 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.d.ts # Authentication API (login, register, etc.)
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
- └── workflow.d.ts # Workflow execution
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:
@@ -41,7 +52,8 @@ Each module contains:
41
52
  🔐 **Automatic authentication** - tokens attached to all requests
42
53
  🔄 **Token auto-refresh** - never worry about expiration
43
54
  📦 **Type-safe** - Full TypeScript support with auto-completion
44
- 🎯 **Simple API** - Clean, consistent method naming
55
+ 🎯 **Simple API** - Clean, consistent method naming
56
+ 🌐 **Complete Integration** - Auth, Entity, BPM, Workflow, ASR, Copilot, Function, TTS
45
57
 
46
58
  ## 📦 Installation
47
59
 
@@ -61,15 +73,18 @@ yarn add @amaster.ai/client axios
61
73
  ```typescript
62
74
  import { createClient } from "@amaster.ai/client";
63
75
 
64
- // 1. Create client instance
76
+ // 1. Create client instance (baseURL is optional)
65
77
  const client = createClient({
66
- baseURL: "https://api.amaster.ai",
78
+ baseURL: "https://api.amaster.ai", // Optional - auto-detects from env in Taro/Mini-program
67
79
  onUnauthorized: () => {
68
80
  // Handle unauthorized (redirect to login, show modal, etc.)
69
81
  window.location.href = "/login";
70
82
  },
71
83
  });
72
84
 
85
+ // Or simply:
86
+ // const client = createClient({}); // Auto-uses VITE_API_BASE_URL or dev proxy
87
+
73
88
  // 2. Login
74
89
  await client.auth.login({
75
90
  email: "user@example.com",
@@ -427,6 +442,104 @@ Workflow execution API from `@amaster.ai/workflow-client`:
427
442
  - `getStatus(executionId)` - Get execution status
428
443
  - And more...
429
444
 
445
+ ### `client.asr`
446
+
447
+ Real-time speech recognition API from `@amaster.ai/asr-client`:
448
+
449
+ - `connect()` - Connect to ASR service via WebSocket
450
+ - `startRecording()` - Start microphone recording
451
+ - `stopRecording()` - Stop recording
452
+ - `close()` - Close connection
453
+
454
+ **Example:**
455
+
456
+ ```typescript
457
+ // Configure callbacks
458
+ client.asr = createASRClient({
459
+ onTranscript: (text, isFinal) => {
460
+ console.log(isFinal ? `[FINAL] ${text}` : `[INTERIM] ${text}`);
461
+ },
462
+ });
463
+
464
+ // Connect and start
465
+ await client.asr.connect();
466
+ await client.asr.startRecording();
467
+
468
+ // Stop when done
469
+ client.asr.stopRecording();
470
+ client.asr.close();
471
+ ```
472
+
473
+ ### `client.copilot`
474
+
475
+ AI assistant / chatbot API from `@amaster.ai/copilot-client`:
476
+
477
+ - `sendMessage(messages, options?)` - Send messages to AI assistant
478
+
479
+ **Example:**
480
+
481
+ ```typescript
482
+ // Simple chat
483
+ const result = await client.copilot.sendMessage([
484
+ { role: "user", content: "Hello, how can you help?" },
485
+ ]);
486
+
487
+ console.log(result.data.content);
488
+
489
+ // Streaming response
490
+ await client.copilot.sendMessage([{ role: "user", content: "Tell me a story" }], {
491
+ stream: true,
492
+ onChunk: (chunk) => console.log(chunk),
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
+
430
543
  ## 🔐 Token Management Flow
431
544
 
432
545
  ```
@@ -453,11 +566,17 @@ MIT © Amaster Team
453
566
 
454
567
  ## 🤝 Related Packages
455
568
 
456
- - `@amaster.ai/auth-client` - Authentication client
457
- - `@amaster.ai/entity-client` - Entity CRUD client
458
- - `@amaster.ai/bpm-client` - BPM client
459
- - `@amaster.ai/workflow-client` - Workflow client
460
- - `@amaster.ai/http-client` - HTTP client foundation
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)
461
580
 
462
581
  ## 💡 Inspiration
463
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(),
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts"],"names":["createHttpClient","createAuthClient","createEntityClient","createBpmClient","createWorkflowClient"],"mappings":";;;;;;;;;AAiFO,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;AAG7E,EAAA,MAAM,MAAA,GAAwB;AAAA,IAC5B,IAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA;AAAA,IACA,QAAA;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 { 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\n // Return unified client interface\n const client: AmasterClient = {\n auth,\n entity,\n bpm,\n workflow,\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"]}
1
+ {"version":3,"sources":["../src/client.ts"],"names":["createHttpClient","createAuthClient","createEntityClient","createBpmClient","createWorkflowClient","functionClient","createFunctionClient","createCopilotA2UIClient","createASRClient","createTTSClient"],"mappings":";;;;;;;;;;;;;AA8FO,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 * // With explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => window.location.href = '/login'\n * });\n * \n * // Auto-detect baseURL from env (Taro/Mini-program)\n * const client = createClient({\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 with explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai'\n * });\n * \n * // Auto-detect baseURL (for Taro/Mini-program or dev proxy)\n * const client = createClient({});\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
  /**
@@ -13,10 +21,15 @@ export { ClientError, ClientResult } from '@amaster.ai/http-client';
13
21
  */
14
22
  interface AmasterClientOptions {
15
23
  /**
16
- * Base URL for the Amaster API
24
+ * Base URL for the Amaster API (optional)
25
+ *
26
+ * If not provided:
27
+ * - Browser/H5: Uses dev proxy or relative URLs
28
+ * - Taro/Mini-program: Auto-reads from process.env.TARO_APP_API_BASE_URL or VITE_API_BASE_URL
29
+ *
17
30
  * @example 'https://api.amaster.ai'
18
31
  */
19
- baseURL: string;
32
+ baseURL?: string;
20
33
  /**
21
34
  * Optional custom headers to include in all requests
22
35
  */
@@ -125,6 +138,61 @@ interface AmasterClient {
125
138
  * ```
126
139
  */
127
140
  workflow: WorkflowClient;
141
+ /**
142
+ * ASR (Automatic Speech Recognition) module
143
+ * WebSocket-based real-time speech recognition
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * // Connect and start recording
148
+ * await client.asr.connect();
149
+ * await client.asr.startRecording();
150
+ *
151
+ * // Stop and close
152
+ * client.asr.stopRecording();
153
+ * client.asr.close();
154
+ * ```
155
+ */
156
+ asr: ASRClient;
157
+ /**
158
+ * Copilot AI assistant module
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * // Send a message
163
+ * const result = await client.copilot.sendMessage([
164
+ * { role: 'user', content: 'Hello' }
165
+ * ]);
166
+ * ```
167
+ */
168
+ copilot: CopilotA2UIClient;
169
+ /**
170
+ * Function invocation module
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * // Call a function
175
+ * const result = await client.function.invoke('myFunction', {
176
+ * param: 'value'
177
+ * });
178
+ * ```
179
+ */
180
+ function: FunctionClient;
181
+ /**
182
+ * TTS (Text-to-Speech) module
183
+ * WebSocket-based real-time speech synthesis
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // Connect and speak
188
+ * await client.tts.connect();
189
+ * await client.tts.speak('Hello world');
190
+ *
191
+ * // Close connection
192
+ * client.tts.close();
193
+ * ```
194
+ */
195
+ tts: TTSClient;
128
196
  /**
129
197
  * Check if the user is currently authenticated
130
198
  */
@@ -158,11 +226,17 @@ interface AmasterClient {
158
226
  *
159
227
  * @example
160
228
  * ```typescript
229
+ * // With explicit baseURL
161
230
  * const client = createClient({
162
231
  * baseURL: 'https://api.amaster.ai',
163
232
  * onUnauthorized: () => window.location.href = '/login'
164
233
  * });
165
234
  *
235
+ * // Auto-detect baseURL from env (Taro/Mini-program)
236
+ * const client = createClient({
237
+ * onUnauthorized: () => window.location.href = '/login'
238
+ * });
239
+ *
166
240
  * // Login
167
241
  * await client.auth.login({ email, password });
168
242
  *
@@ -189,11 +263,14 @@ interface AmasterClient {
189
263
  *
190
264
  * @example
191
265
  * ```typescript
192
- * // Basic usage
266
+ * // Basic usage with explicit baseURL
193
267
  * const client = createClient({
194
268
  * baseURL: 'https://api.amaster.ai'
195
269
  * });
196
270
  *
271
+ * // Auto-detect baseURL (for Taro/Mini-program or dev proxy)
272
+ * const client = createClient({});
273
+ *
197
274
  * // With authentication callbacks
198
275
  * const client = createClient({
199
276
  * baseURL: 'https://api.amaster.ai',
package/dist/index.d.ts 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
  /**
@@ -13,10 +21,15 @@ export { ClientError, ClientResult } from '@amaster.ai/http-client';
13
21
  */
14
22
  interface AmasterClientOptions {
15
23
  /**
16
- * Base URL for the Amaster API
24
+ * Base URL for the Amaster API (optional)
25
+ *
26
+ * If not provided:
27
+ * - Browser/H5: Uses dev proxy or relative URLs
28
+ * - Taro/Mini-program: Auto-reads from process.env.TARO_APP_API_BASE_URL or VITE_API_BASE_URL
29
+ *
17
30
  * @example 'https://api.amaster.ai'
18
31
  */
19
- baseURL: string;
32
+ baseURL?: string;
20
33
  /**
21
34
  * Optional custom headers to include in all requests
22
35
  */
@@ -125,6 +138,61 @@ interface AmasterClient {
125
138
  * ```
126
139
  */
127
140
  workflow: WorkflowClient;
141
+ /**
142
+ * ASR (Automatic Speech Recognition) module
143
+ * WebSocket-based real-time speech recognition
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * // Connect and start recording
148
+ * await client.asr.connect();
149
+ * await client.asr.startRecording();
150
+ *
151
+ * // Stop and close
152
+ * client.asr.stopRecording();
153
+ * client.asr.close();
154
+ * ```
155
+ */
156
+ asr: ASRClient;
157
+ /**
158
+ * Copilot AI assistant module
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * // Send a message
163
+ * const result = await client.copilot.sendMessage([
164
+ * { role: 'user', content: 'Hello' }
165
+ * ]);
166
+ * ```
167
+ */
168
+ copilot: CopilotA2UIClient;
169
+ /**
170
+ * Function invocation module
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * // Call a function
175
+ * const result = await client.function.invoke('myFunction', {
176
+ * param: 'value'
177
+ * });
178
+ * ```
179
+ */
180
+ function: FunctionClient;
181
+ /**
182
+ * TTS (Text-to-Speech) module
183
+ * WebSocket-based real-time speech synthesis
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // Connect and speak
188
+ * await client.tts.connect();
189
+ * await client.tts.speak('Hello world');
190
+ *
191
+ * // Close connection
192
+ * client.tts.close();
193
+ * ```
194
+ */
195
+ tts: TTSClient;
128
196
  /**
129
197
  * Check if the user is currently authenticated
130
198
  */
@@ -158,11 +226,17 @@ interface AmasterClient {
158
226
  *
159
227
  * @example
160
228
  * ```typescript
229
+ * // With explicit baseURL
161
230
  * const client = createClient({
162
231
  * baseURL: 'https://api.amaster.ai',
163
232
  * onUnauthorized: () => window.location.href = '/login'
164
233
  * });
165
234
  *
235
+ * // Auto-detect baseURL from env (Taro/Mini-program)
236
+ * const client = createClient({
237
+ * onUnauthorized: () => window.location.href = '/login'
238
+ * });
239
+ *
166
240
  * // Login
167
241
  * await client.auth.login({ email, password });
168
242
  *
@@ -189,11 +263,14 @@ interface AmasterClient {
189
263
  *
190
264
  * @example
191
265
  * ```typescript
192
- * // Basic usage
266
+ * // Basic usage with explicit baseURL
193
267
  * const client = createClient({
194
268
  * baseURL: 'https://api.amaster.ai'
195
269
  * });
196
270
  *
271
+ * // Auto-detect baseURL (for Taro/Mini-program or dev proxy)
272
+ * const client = createClient({});
273
+ *
197
274
  * // With authentication callbacks
198
275
  * const client = createClient({
199
276
  * baseURL: 'https://api.amaster.ai',
package/dist/index.js CHANGED
@@ -2,6 +2,10 @@ import { createAuthClient } from '@amaster.ai/auth-client';
2
2
  import { createEntityClient } from '@amaster.ai/entity-client';
3
3
  import { createBpmClient } from '@amaster.ai/bpm-client';
4
4
  import { createWorkflowClient } from '@amaster.ai/workflow-client';
5
+ import { createASRClient } from '@amaster.ai/asr-client';
6
+ import { createCopilotA2UIClient } from '@amaster.ai/copilot-client';
7
+ import { createFunctionClient } from '@amaster.ai/function-client';
8
+ import { createTTSClient } from '@amaster.ai/tts-client';
5
9
  import { createHttpClient } from '@amaster.ai/http-client';
6
10
 
7
11
  // src/client.ts
@@ -41,11 +45,19 @@ function createClient(options) {
41
45
  const entity = createEntityClient(authenticatedHttpClient);
42
46
  const bpm = createBpmClient(authenticatedHttpClient);
43
47
  const workflow = createWorkflowClient(authenticatedHttpClient);
48
+ const functionClient = createFunctionClient(authenticatedHttpClient);
49
+ const copilot = createCopilotA2UIClient(authenticatedHttpClient);
50
+ const asr = createASRClient({});
51
+ const tts = createTTSClient({});
44
52
  const client = {
45
53
  auth,
46
54
  entity,
47
55
  bpm,
48
56
  workflow,
57
+ asr,
58
+ copilot,
59
+ function: functionClient,
60
+ tts,
49
61
  // Expose token management methods from auth client
50
62
  isAuthenticated: () => auth.isAuthenticated(),
51
63
  getAccessToken: () => auth.getAccessToken(),
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;AAiFO,SAAS,aAAa,OAAA,EAA8C;AACzE,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,GAAU,EAAC,EAAG,cAAA,EAAgB,gBAAe,GAAI,OAAA;AAGlE,EAAA,MAAM,iBAAiB,gBAAA,CAAiB;AAAA,IACtC,OAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,OAAmB,gBAAA,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,GAAuB,mBAAmB,uBAAuB,CAAA;AACvE,EAAA,MAAM,GAAA,GAAiB,gBAAgB,uBAAuB,CAAA;AAC9D,EAAA,MAAM,QAAA,GAA2B,qBAAqB,uBAAuB,CAAA;AAG7E,EAAA,MAAM,MAAA,GAAwB;AAAA,IAC5B,IAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA;AAAA,IACA,QAAA;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.js","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 { 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\n // Return unified client interface\n const client: AmasterClient = {\n auth,\n entity,\n bpm,\n workflow,\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"]}
1
+ {"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;AA8FO,SAAS,aAAa,OAAA,EAA8C;AACzE,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,GAAU,EAAC,EAAG,cAAA,EAAgB,gBAAe,GAAI,OAAA;AAGlE,EAAA,MAAM,iBAAiB,gBAAA,CAAiB;AAAA,IACtC,OAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,OAAmB,gBAAA,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,GAAuB,mBAAmB,uBAAuB,CAAA;AACvE,EAAA,MAAM,GAAA,GAAiB,gBAAgB,uBAAuB,CAAA;AAC9D,EAAA,MAAM,QAAA,GAA2B,qBAAqB,uBAAuB,CAAA;AAC7E,EAAA,MAAM,cAAA,GAAiC,qBAAqB,uBAAuB,CAAA;AACnF,EAAA,MAAM,OAAA,GAA6B,wBAAwB,uBAAuB,CAAA;AAIlF,EAAA,MAAM,GAAA,GAAiB,eAAA,CAAgB,EAAE,CAAA;AACzC,EAAA,MAAM,GAAA,GAAiB,eAAA,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,EAAU,cAAA;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.js","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 * // With explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => window.location.href = '/login'\n * });\n * \n * // Auto-detect baseURL from env (Taro/Mini-program)\n * const client = createClient({\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 with explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai'\n * });\n * \n * // Auto-detect baseURL (for Taro/Mini-program or dev proxy)\n * const client = createClient({});\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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@amaster.ai/client",
3
- "version": "1.1.0-beta.1",
4
- "description": "Unified API client for Amaster platform - Supabase-style interface",
3
+ "version": "1.1.0-beta.16",
4
+ "description": "Unified API client for Amaster platform - All services in one package",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -12,7 +12,10 @@
12
12
  "./types/index.d.ts"
13
13
  ],
14
14
  "auth": [
15
- "./types/auth.d.ts"
15
+ "./types/auth/index.d.ts"
16
+ ],
17
+ "auth/*": [
18
+ "./types/auth/*.d.ts"
16
19
  ],
17
20
  "entity": [
18
21
  "./types/entity.d.ts"
@@ -23,6 +26,18 @@
23
26
  "workflow": [
24
27
  "./types/workflow.d.ts"
25
28
  ],
29
+ "asr": [
30
+ "./types/asr.d.ts"
31
+ ],
32
+ "copilot": [
33
+ "./types/copilot.d.ts"
34
+ ],
35
+ "function": [
36
+ "./types/function.d.ts"
37
+ ],
38
+ "tts": [
39
+ "./types/tts.d.ts"
40
+ ],
26
41
  "common": [
27
42
  "./types/common.d.ts"
28
43
  ]
@@ -54,11 +69,16 @@
54
69
  "registry": "https://registry.npmjs.org/"
55
70
  },
56
71
  "dependencies": {
57
- "@amaster.ai/bpm-client": "1.1.0-beta.1",
58
- "@amaster.ai/workflow-client": "1.1.0-beta.1",
59
- "@amaster.ai/http-client": "1.1.0-beta.1",
60
- "@amaster.ai/auth-client": "1.1.0-beta.1",
61
- "@amaster.ai/entity-client": "1.1.0-beta.1"
72
+ "@amaster.ai/asr-client": "1.1.0-beta.16",
73
+ "@amaster.ai/asr-http-client": "1.1.0-beta.16",
74
+ "@amaster.ai/auth-client": "1.1.0-beta.16",
75
+ "@amaster.ai/bpm-client": "1.1.0-beta.16",
76
+ "@amaster.ai/copilot-client": "1.1.0-beta.16",
77
+ "@amaster.ai/entity-client": "1.1.0-beta.16",
78
+ "@amaster.ai/function-client": "1.1.0-beta.16",
79
+ "@amaster.ai/http-client": "1.1.0-beta.16",
80
+ "@amaster.ai/tts-client": "1.1.0-beta.16",
81
+ "@amaster.ai/workflow-client": "1.1.0-beta.16"
62
82
  },
63
83
  "peerDependencies": {
64
84
  "axios": "^1.11.0"