@amaster.ai/client 1.1.0-beta.7 → 1.1.0-beta.70

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/dist/index.d.cts CHANGED
@@ -3,18 +3,21 @@ export { LoginParams, LoginResponse, OAuthProvider, Permission, RegisterParams,
3
3
  import { EntityClient } from '@amaster.ai/entity-client';
4
4
  export { EntityListResponse, EntityQueryParams, FilterGroup, FilterItem, FilterOperator } from '@amaster.ai/entity-client';
5
5
  import { BpmClient } from '@amaster.ai/bpm-client';
6
- export { CamundaVariable, HistoryProcessInstance, HistoryTask, ProcessInstance, ProcessVariable, Task, TaskFormSchema, TaskQueryParams } from '@amaster.ai/bpm-client';
6
+ export { ActivityInstanceTree, CamundaVariable, HistoryActivityInstance, HistoryProcessInstance, HistoryTask, ProcessInstance, ProcessVariable, Task, TaskFormSchema, TaskQueryParams, UserOperationLog } 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';
9
+ import { ASRClientConfig, ASRClient, ASRHttpClientConfig, ASRHttpClient } from '@amaster.ai/asr-client';
10
+ export { ASRClient, ASRClientConfig, ASRHttpClient, ASRHttpClientConfig, ASRLanguage } from '@amaster.ai/asr-client';
11
+ import { CopilotClient } from '@amaster.ai/copilot-client';
12
+ export { ChatMessage, ChatOptions, CopilotClient, FileContent, ImageContent, MessageContent, TextContent } from '@amaster.ai/copilot-client';
13
13
  import { FunctionClient } from '@amaster.ai/function-client';
14
14
  export { FunctionClient } from '@amaster.ai/function-client';
15
- import { TTSClient } from '@amaster.ai/tts-client';
15
+ import { TTSClientConfig, TTSClient } from '@amaster.ai/tts-client';
16
16
  export { TTSClient, TTSClientConfig } from '@amaster.ai/tts-client';
17
- export { ClientError, ClientResult } from '@amaster.ai/http-client';
17
+ import { S3Client } from '@amaster.ai/s3-client';
18
+ export { S3Client, S3Metadata, UploadRes } from '@amaster.ai/s3-client';
19
+ import { HttpClient } from '@amaster.ai/http-client';
20
+ export { ClientError, ClientResult, HttpClient, RequestConfig } from '@amaster.ai/http-client';
18
21
 
19
22
  /**
20
23
  * Amaster Client Configuration Options
@@ -54,6 +57,18 @@ interface AmasterClientOptions {
54
57
  * Tokens will be refreshed this many seconds before expiry
55
58
  */
56
59
  refreshThreshold?: number;
60
+ /**
61
+ * Automatically handle OAuth callback on initialization (default: true)
62
+ *
63
+ * When enabled, the client will automatically detect and process OAuth
64
+ * callback URLs containing #access_token. After processing, the hash
65
+ * is automatically cleared from the URL for security.
66
+ *
67
+ * Set to false if you want to manually handle OAuth callbacks.
68
+ *
69
+ * @default true
70
+ */
71
+ autoHandleOAuthCallback?: boolean;
57
72
  }
58
73
  /**
59
74
  * Unified Amaster Client
@@ -139,21 +154,67 @@ interface AmasterClient {
139
154
  */
140
155
  workflow: WorkflowClient;
141
156
  /**
142
- * ASR (Automatic Speech Recognition) module
143
- * WebSocket-based real-time speech recognition
157
+ * ASR (Automatic Speech Recognition) module - WebSocket-based real-time speech recognition
158
+ *
159
+ * Suitable for scenarios requiring real-time transcription results, such as voice input, live captions, etc.
144
160
  *
145
161
  * @example
146
162
  * ```typescript
147
- * // Connect and start recording
148
- * await client.asr.connect();
149
- * await client.asr.startRecording();
163
+ * // Real-time streaming recognition
164
+ * const asrClient = client.asr({
165
+ * onReady() {
166
+ * console.log('ASR Ready');
167
+ * },
168
+ * onTranscript(text, isFinal) {
169
+ * console.log(isFinal ? '[Final]' : '[Interim]', text);
170
+ * },
171
+ * onError(err) {
172
+ * console.error('ASR Error:', err);
173
+ * },
174
+ * onClose() {
175
+ * console.log('ASR Connection Closed');
176
+ * },
177
+ * });
178
+ *
179
+ * await asrClient.connect();
180
+ * await asrClient.startRecording();
150
181
  *
151
182
  * // Stop and close
152
- * client.asr.stopRecording();
153
- * client.asr.close();
183
+ * asrClient.stopRecording();
184
+ * asrClient.close();
185
+ * ```
186
+ */
187
+ asr: (config: ASRClientConfig) => ASRClient;
188
+ /**
189
+ * ASR Http module - HTTP-based press-to-talk speech recognition
190
+ *
191
+ * Suitable for press-to-talk scenarios where you hold to speak and release to recognize,
192
+ * such as voice messages, voice search, etc.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * // Press-to-talk recognition
197
+ * const asrHttpClient = client.asrHttp({
198
+ * onRecordingStart() {
199
+ * console.log('Recording started');
200
+ * },
201
+ * onRecordingStop() {
202
+ * console.log('Recording stopped');
203
+ * },
204
+ * onResult(text) {
205
+ * console.log('Recognition result:', text);
206
+ * },
207
+ * onError(err) {
208
+ * console.error('ASR HTTP Error:', err);
209
+ * },
210
+ * });
211
+ *
212
+ * await asrHttpClient.startRecording();
213
+ * // ... user speaks ...
214
+ * const result = await asrHttpClient.stopRecording();
154
215
  * ```
155
216
  */
156
- asr: ASRClient;
217
+ asrHttp: (config: ASRHttpClientConfig) => ASRHttpClient;
157
218
  /**
158
219
  * Copilot AI assistant module
159
220
  *
@@ -165,7 +226,7 @@ interface AmasterClient {
165
226
  * ]);
166
227
  * ```
167
228
  */
168
- copilot: CopilotA2UIClient;
229
+ copilot: CopilotClient;
169
230
  /**
170
231
  * Function invocation module
171
232
  *
@@ -179,20 +240,81 @@ interface AmasterClient {
179
240
  */
180
241
  function: FunctionClient;
181
242
  /**
182
- * TTS (Text-to-Speech) module
183
- * WebSocket-based real-time speech synthesis
243
+ * TTS (Text-to-Speech) module - WebSocket-based real-time speech synthesis
244
+ *
245
+ * Supports multiple voices and audio formats. Built-in playback only supports PCM format.
184
246
  *
185
247
  * @example
186
248
  * ```typescript
187
249
  * // Connect and speak
188
- * await client.tts.connect();
189
- * await client.tts.speak('Hello world');
250
+ * const ttsClient = client.tts({
251
+ * voice: 'Cherry',
252
+ * autoPlay: true,
253
+ * onReady() {
254
+ * console.log('TTS Ready');
255
+ * },
256
+ * onAudioStart() {
257
+ * console.log('Playing audio');
258
+ * },
259
+ * onAudioEnd() {
260
+ * console.log('Audio playback ended');
261
+ * },
262
+ * });
263
+ *
264
+ * await ttsClient.connect();
265
+ * await ttsClient.speak('Hello, welcome to Amaster!');
190
266
  *
191
- * // Close connection
192
- * client.tts.close();
267
+ * // Close when done
268
+ * ttsClient.close();
269
+ * ```
270
+ */
271
+ tts: (config: TTSClientConfig) => TTSClient;
272
+ /**
273
+ * S3 Storage module
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * // Upload file
278
+ * await client.s3.upload(file);
279
+ *
280
+ * // Download file
281
+ * await client.s3.download('path/to/file');
282
+ * ```
283
+ */
284
+ s3: S3Client;
285
+ /**
286
+ * HTTP client for custom requests
287
+ *
288
+ * Provides direct access to the underlying HTTP client with automatic
289
+ * authentication token attachment. Useful for calling custom endpoints
290
+ * or APIs not covered by the specialized clients.
291
+ *
292
+ * Supports both `data` (Axios style) and `body` (Fetch API style) for request payload.
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * // Make a custom GET request
297
+ * const { data, error } = await client.http.request({
298
+ * url: '/custom/endpoint',
299
+ * method: 'GET'
300
+ * });
301
+ *
302
+ * // Make a POST request with data (Axios style)
303
+ * const { data, error } = await client.http.request({
304
+ * url: '/custom/endpoint',
305
+ * method: 'POST',
306
+ * data: { key: 'value' }
307
+ * });
308
+ *
309
+ * // Make a POST request with body (Fetch API style, auto-converted to data)
310
+ * const { data, error } = await client.http.request({
311
+ * url: '/custom/endpoint',
312
+ * method: 'POST',
313
+ * body: { key: 'value' }
314
+ * });
193
315
  * ```
194
316
  */
195
- tts: TTSClient;
317
+ http: HttpClient;
196
318
  /**
197
319
  * Check if the user is currently authenticated
198
320
  */
package/dist/index.d.ts CHANGED
@@ -3,18 +3,21 @@ export { LoginParams, LoginResponse, OAuthProvider, Permission, RegisterParams,
3
3
  import { EntityClient } from '@amaster.ai/entity-client';
4
4
  export { EntityListResponse, EntityQueryParams, FilterGroup, FilterItem, FilterOperator } from '@amaster.ai/entity-client';
5
5
  import { BpmClient } from '@amaster.ai/bpm-client';
6
- export { CamundaVariable, HistoryProcessInstance, HistoryTask, ProcessInstance, ProcessVariable, Task, TaskFormSchema, TaskQueryParams } from '@amaster.ai/bpm-client';
6
+ export { ActivityInstanceTree, CamundaVariable, HistoryActivityInstance, HistoryProcessInstance, HistoryTask, ProcessInstance, ProcessVariable, Task, TaskFormSchema, TaskQueryParams, UserOperationLog } 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';
9
+ import { ASRClientConfig, ASRClient, ASRHttpClientConfig, ASRHttpClient } from '@amaster.ai/asr-client';
10
+ export { ASRClient, ASRClientConfig, ASRHttpClient, ASRHttpClientConfig, ASRLanguage } from '@amaster.ai/asr-client';
11
+ import { CopilotClient } from '@amaster.ai/copilot-client';
12
+ export { ChatMessage, ChatOptions, CopilotClient, FileContent, ImageContent, MessageContent, TextContent } from '@amaster.ai/copilot-client';
13
13
  import { FunctionClient } from '@amaster.ai/function-client';
14
14
  export { FunctionClient } from '@amaster.ai/function-client';
15
- import { TTSClient } from '@amaster.ai/tts-client';
15
+ import { TTSClientConfig, TTSClient } from '@amaster.ai/tts-client';
16
16
  export { TTSClient, TTSClientConfig } from '@amaster.ai/tts-client';
17
- export { ClientError, ClientResult } from '@amaster.ai/http-client';
17
+ import { S3Client } from '@amaster.ai/s3-client';
18
+ export { S3Client, S3Metadata, UploadRes } from '@amaster.ai/s3-client';
19
+ import { HttpClient } from '@amaster.ai/http-client';
20
+ export { ClientError, ClientResult, HttpClient, RequestConfig } from '@amaster.ai/http-client';
18
21
 
19
22
  /**
20
23
  * Amaster Client Configuration Options
@@ -54,6 +57,18 @@ interface AmasterClientOptions {
54
57
  * Tokens will be refreshed this many seconds before expiry
55
58
  */
56
59
  refreshThreshold?: number;
60
+ /**
61
+ * Automatically handle OAuth callback on initialization (default: true)
62
+ *
63
+ * When enabled, the client will automatically detect and process OAuth
64
+ * callback URLs containing #access_token. After processing, the hash
65
+ * is automatically cleared from the URL for security.
66
+ *
67
+ * Set to false if you want to manually handle OAuth callbacks.
68
+ *
69
+ * @default true
70
+ */
71
+ autoHandleOAuthCallback?: boolean;
57
72
  }
58
73
  /**
59
74
  * Unified Amaster Client
@@ -139,21 +154,67 @@ interface AmasterClient {
139
154
  */
140
155
  workflow: WorkflowClient;
141
156
  /**
142
- * ASR (Automatic Speech Recognition) module
143
- * WebSocket-based real-time speech recognition
157
+ * ASR (Automatic Speech Recognition) module - WebSocket-based real-time speech recognition
158
+ *
159
+ * Suitable for scenarios requiring real-time transcription results, such as voice input, live captions, etc.
144
160
  *
145
161
  * @example
146
162
  * ```typescript
147
- * // Connect and start recording
148
- * await client.asr.connect();
149
- * await client.asr.startRecording();
163
+ * // Real-time streaming recognition
164
+ * const asrClient = client.asr({
165
+ * onReady() {
166
+ * console.log('ASR Ready');
167
+ * },
168
+ * onTranscript(text, isFinal) {
169
+ * console.log(isFinal ? '[Final]' : '[Interim]', text);
170
+ * },
171
+ * onError(err) {
172
+ * console.error('ASR Error:', err);
173
+ * },
174
+ * onClose() {
175
+ * console.log('ASR Connection Closed');
176
+ * },
177
+ * });
178
+ *
179
+ * await asrClient.connect();
180
+ * await asrClient.startRecording();
150
181
  *
151
182
  * // Stop and close
152
- * client.asr.stopRecording();
153
- * client.asr.close();
183
+ * asrClient.stopRecording();
184
+ * asrClient.close();
185
+ * ```
186
+ */
187
+ asr: (config: ASRClientConfig) => ASRClient;
188
+ /**
189
+ * ASR Http module - HTTP-based press-to-talk speech recognition
190
+ *
191
+ * Suitable for press-to-talk scenarios where you hold to speak and release to recognize,
192
+ * such as voice messages, voice search, etc.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * // Press-to-talk recognition
197
+ * const asrHttpClient = client.asrHttp({
198
+ * onRecordingStart() {
199
+ * console.log('Recording started');
200
+ * },
201
+ * onRecordingStop() {
202
+ * console.log('Recording stopped');
203
+ * },
204
+ * onResult(text) {
205
+ * console.log('Recognition result:', text);
206
+ * },
207
+ * onError(err) {
208
+ * console.error('ASR HTTP Error:', err);
209
+ * },
210
+ * });
211
+ *
212
+ * await asrHttpClient.startRecording();
213
+ * // ... user speaks ...
214
+ * const result = await asrHttpClient.stopRecording();
154
215
  * ```
155
216
  */
156
- asr: ASRClient;
217
+ asrHttp: (config: ASRHttpClientConfig) => ASRHttpClient;
157
218
  /**
158
219
  * Copilot AI assistant module
159
220
  *
@@ -165,7 +226,7 @@ interface AmasterClient {
165
226
  * ]);
166
227
  * ```
167
228
  */
168
- copilot: CopilotA2UIClient;
229
+ copilot: CopilotClient;
169
230
  /**
170
231
  * Function invocation module
171
232
  *
@@ -179,20 +240,81 @@ interface AmasterClient {
179
240
  */
180
241
  function: FunctionClient;
181
242
  /**
182
- * TTS (Text-to-Speech) module
183
- * WebSocket-based real-time speech synthesis
243
+ * TTS (Text-to-Speech) module - WebSocket-based real-time speech synthesis
244
+ *
245
+ * Supports multiple voices and audio formats. Built-in playback only supports PCM format.
184
246
  *
185
247
  * @example
186
248
  * ```typescript
187
249
  * // Connect and speak
188
- * await client.tts.connect();
189
- * await client.tts.speak('Hello world');
250
+ * const ttsClient = client.tts({
251
+ * voice: 'Cherry',
252
+ * autoPlay: true,
253
+ * onReady() {
254
+ * console.log('TTS Ready');
255
+ * },
256
+ * onAudioStart() {
257
+ * console.log('Playing audio');
258
+ * },
259
+ * onAudioEnd() {
260
+ * console.log('Audio playback ended');
261
+ * },
262
+ * });
263
+ *
264
+ * await ttsClient.connect();
265
+ * await ttsClient.speak('Hello, welcome to Amaster!');
190
266
  *
191
- * // Close connection
192
- * client.tts.close();
267
+ * // Close when done
268
+ * ttsClient.close();
269
+ * ```
270
+ */
271
+ tts: (config: TTSClientConfig) => TTSClient;
272
+ /**
273
+ * S3 Storage module
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * // Upload file
278
+ * await client.s3.upload(file);
279
+ *
280
+ * // Download file
281
+ * await client.s3.download('path/to/file');
282
+ * ```
283
+ */
284
+ s3: S3Client;
285
+ /**
286
+ * HTTP client for custom requests
287
+ *
288
+ * Provides direct access to the underlying HTTP client with automatic
289
+ * authentication token attachment. Useful for calling custom endpoints
290
+ * or APIs not covered by the specialized clients.
291
+ *
292
+ * Supports both `data` (Axios style) and `body` (Fetch API style) for request payload.
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * // Make a custom GET request
297
+ * const { data, error } = await client.http.request({
298
+ * url: '/custom/endpoint',
299
+ * method: 'GET'
300
+ * });
301
+ *
302
+ * // Make a POST request with data (Axios style)
303
+ * const { data, error } = await client.http.request({
304
+ * url: '/custom/endpoint',
305
+ * method: 'POST',
306
+ * data: { key: 'value' }
307
+ * });
308
+ *
309
+ * // Make a POST request with body (Fetch API style, auto-converted to data)
310
+ * const { data, error } = await client.http.request({
311
+ * url: '/custom/endpoint',
312
+ * method: 'POST',
313
+ * body: { key: 'value' }
314
+ * });
193
315
  * ```
194
316
  */
195
- tts: TTSClient;
317
+ http: HttpClient;
196
318
  /**
197
319
  * Check if the user is currently authenticated
198
320
  */
package/dist/index.js CHANGED
@@ -2,15 +2,22 @@ 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';
5
+ import { createASRClient, createASRHttpClient } from '@amaster.ai/asr-client';
6
+ import { createCopilotClient } from '@amaster.ai/copilot-client';
7
7
  import { createFunctionClient } from '@amaster.ai/function-client';
8
8
  import { createTTSClient } from '@amaster.ai/tts-client';
9
+ import { createS3Client } from '@amaster.ai/s3-client';
9
10
  import { createHttpClient } from '@amaster.ai/http-client';
10
11
 
11
12
  // src/client.ts
12
13
  function createClient(options) {
13
- const { baseURL, headers = {}, onUnauthorized, onTokenExpired } = options;
14
+ const {
15
+ baseURL,
16
+ headers = {},
17
+ onUnauthorized,
18
+ onTokenExpired,
19
+ autoHandleOAuthCallback
20
+ } = options;
14
21
  const baseHttpClient = createHttpClient({
15
22
  baseURL,
16
23
  headers
@@ -19,9 +26,34 @@ function createClient(options) {
19
26
  baseURL,
20
27
  headers,
21
28
  onTokenExpired,
22
- onUnauthorized
29
+ onUnauthorized,
30
+ autoHandleOAuthCallback
23
31
  });
24
32
  const createAuthenticatedHttpClient = () => {
33
+ let isRefreshing = false;
34
+ let refreshPromise = null;
35
+ function isTokenExpired(result) {
36
+ if (result.status !== 401) return false;
37
+ if (result.error?.message && /expired/i.test(result.error.message)) {
38
+ return true;
39
+ }
40
+ if (result.error?.details) {
41
+ const details = result.error.details;
42
+ if (typeof details === "string" && /expired/i.test(details)) {
43
+ return true;
44
+ }
45
+ if (typeof details === "object" && details !== null) {
46
+ const detailsObj = details;
47
+ if (typeof detailsObj.message === "string" && /expired/i.test(detailsObj.message)) {
48
+ return true;
49
+ }
50
+ }
51
+ }
52
+ if (typeof result.data === "string" && /expired/i.test(result.data)) {
53
+ return true;
54
+ }
55
+ return !!auth.getAccessToken();
56
+ }
25
57
  return {
26
58
  async request(config) {
27
59
  const token = auth.getAccessToken();
@@ -33,7 +65,32 @@ function createClient(options) {
33
65
  ...authHeaders
34
66
  }
35
67
  };
36
- const result = await baseHttpClient.request(mergedConfig);
68
+ let result = await baseHttpClient.request(mergedConfig);
69
+ if (result.status === 401 && isTokenExpired(result)) {
70
+ if (!isRefreshing) {
71
+ isRefreshing = true;
72
+ refreshPromise = (async () => {
73
+ try {
74
+ const refreshResult = await auth.refreshToken();
75
+ return !!refreshResult.data;
76
+ } finally {
77
+ isRefreshing = false;
78
+ refreshPromise = null;
79
+ }
80
+ })();
81
+ }
82
+ const refreshed = await refreshPromise;
83
+ if (refreshed) {
84
+ const newToken = auth.getAccessToken();
85
+ result = await baseHttpClient.request({
86
+ ...config,
87
+ headers: {
88
+ ...config.headers,
89
+ ...newToken ? { Authorization: `Bearer ${newToken}` } : {}
90
+ }
91
+ });
92
+ }
93
+ }
37
94
  if (result.status === 401 && onUnauthorized) {
38
95
  onUnauthorized();
39
96
  }
@@ -42,22 +99,54 @@ function createClient(options) {
42
99
  };
43
100
  };
44
101
  const authenticatedHttpClient = createAuthenticatedHttpClient();
102
+ let cachedUserUid = null;
103
+ auth.on("login", (user) => {
104
+ cachedUserUid = user?.uid ?? null;
105
+ });
106
+ auth.on("logout", () => {
107
+ cachedUserUid = null;
108
+ });
109
+ if (auth.isAuthenticated()) {
110
+ auth.getMe().then((result) => {
111
+ if (result.data?.uid) {
112
+ cachedUserUid = result.data.uid;
113
+ }
114
+ }).catch(() => {
115
+ });
116
+ }
45
117
  const entity = createEntityClient(authenticatedHttpClient);
46
118
  const bpm = createBpmClient(authenticatedHttpClient);
47
119
  const workflow = createWorkflowClient(authenticatedHttpClient);
48
120
  const functionClient = createFunctionClient(authenticatedHttpClient);
49
- const copilot = createCopilotA2UIClient(authenticatedHttpClient);
50
- const asr = createASRClient({});
51
- const tts = createTTSClient({});
121
+ const copilot = createCopilotClient(
122
+ authenticatedHttpClient,
123
+ baseURL,
124
+ () => auth.getAccessToken(),
125
+ () => cachedUserUid
126
+ );
127
+ const s3 = createS3Client(authenticatedHttpClient);
128
+ const asr = createASRClient({
129
+ getAccessToken: () => auth.getAccessToken()
130
+ });
131
+ const asrHttp = createASRHttpClient({
132
+ getAccessToken: () => auth.getAccessToken(),
133
+ http: authenticatedHttpClient
134
+ });
135
+ const tts = createTTSClient({
136
+ getAccessToken: () => auth.getAccessToken()
137
+ });
52
138
  const client = {
53
139
  auth,
54
140
  entity,
55
141
  bpm,
56
142
  workflow,
57
143
  asr,
144
+ asrHttp,
58
145
  copilot,
59
146
  function: functionClient,
60
147
  tts,
148
+ s3,
149
+ http: authenticatedHttpClient,
61
150
  // Expose token management methods from auth client
62
151
  isAuthenticated: () => auth.isAuthenticated(),
63
152
  getAccessToken: () => auth.getAccessToken(),
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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"]}
1
+ {"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;AA2GO,SAAS,aAAa,OAAA,EAA8C;AACzE,EAAA,MAAM;AAAA,IACJ,OAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,cAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAGJ,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,cAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,gCAAgC,MAAkB;AAEtD,IAAA,IAAI,YAAA,GAAe,KAAA;AACnB,IAAA,IAAI,cAAA,GAA0C,IAAA;AAM9C,IAAA,SAAS,eAAe,MAAA,EAAwC;AAC9D,MAAA,IAAI,MAAA,CAAO,MAAA,KAAW,GAAA,EAAK,OAAO,KAAA;AAGlC,MAAA,IAAI,MAAA,CAAO,OAAO,OAAA,IAAW,UAAA,CAAW,KAAK,MAAA,CAAO,KAAA,CAAM,OAAO,CAAA,EAAG;AAClE,QAAA,OAAO,IAAA;AAAA,MACT;AAGA,MAAA,IAAI,MAAA,CAAO,OAAO,OAAA,EAAS;AACzB,QAAA,MAAM,OAAA,GAAU,OAAO,KAAA,CAAM,OAAA;AAC7B,QAAA,IAAI,OAAO,OAAA,KAAY,QAAA,IA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AAA,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 {\n createASRClient,\n createASRHttpClient,\n type ASRClientConfig,\n type ASRClient,\n type ASRHttpClientConfig,\n type ASRHttpClient,\n} from \"@amaster.ai/asr-client\";\nimport { createCopilotClient, type CopilotClient } from \"@amaster.ai/copilot-client\";\nimport { createFunctionClient, type FunctionClient } from \"@amaster.ai/function-client\";\nimport { createTTSClient, TTSClientConfig, type TTSClient } from \"@amaster.ai/tts-client\";\nimport { createS3Client, type S3Client } from \"@amaster.ai/s3-client\";\nimport {\n createHttpClient,\n type HttpClient,\n type RequestConfig,\n type ClientResult,\n} 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 {\n baseURL,\n headers = {},\n onUnauthorized,\n onTokenExpired,\n autoHandleOAuthCallback,\n } = 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 autoHandleOAuthCallback,\n });\n\n // Create a wrapper HTTP client that automatically adds the auth token\n const createAuthenticatedHttpClient = (): HttpClient => {\n // Track if we're currently refreshing to avoid multiple simultaneous refreshes\n let isRefreshing = false;\n let refreshPromise: Promise<boolean> | null = null;\n\n /**\n * Check if 401 error is due to token expiration\n * Traefik JWT plugin returns plain text like \"Jwt is expired\" or \"Token is expired\"\n */\n function isTokenExpired(result: ClientResult<unknown>): boolean {\n if (result.status !== 401) return false;\n\n // Check error message (could be from backend JSON response)\n if (result.error?.message && /expired/i.test(result.error.message)) {\n return true;\n }\n\n // Check error details (traefik returns plain text in details)\n if (result.error?.details) {\n const details = result.error.details;\n if (typeof details === \"string\" && /expired/i.test(details)) {\n return true;\n }\n // Also check if details is an object with message field\n if (typeof details === \"object\" && details !== null) {\n const detailsObj = details as Record<string, unknown>;\n if (typeof detailsObj.message === \"string\" && /expired/i.test(detailsObj.message)) {\n return true;\n }\n }\n }\n\n // Check raw data (could be plain text from traefik)\n if (typeof result.data === \"string\" && /expired/i.test(result.data)) {\n return true;\n }\n\n // If we have a token but got 401, assume it might be expired\n return !!auth.getAccessToken();\n }\n\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 let result = await baseHttpClient.request<T>(mergedConfig);\n\n // Handle 401 errors with automatic token refresh\n if (result.status === 401 && isTokenExpired(result)) {\n // Attempt to refresh token\n if (!isRefreshing) {\n isRefreshing = true;\n refreshPromise = (async () => {\n try {\n const refreshResult = await auth.refreshToken();\n return !!refreshResult.data;\n } finally {\n isRefreshing = false;\n refreshPromise = null;\n }\n })();\n }\n\n const refreshed = await refreshPromise;\n\n if (refreshed) {\n // Retry with new token\n const newToken = auth.getAccessToken();\n result = await baseHttpClient.request<T>({\n ...config,\n headers: {\n ...config.headers,\n ...(newToken ? { Authorization: `Bearer ${newToken}` } : {}),\n },\n });\n }\n }\n\n // Trigger unauthorized if still 401\n if (result.status === 401 && onUnauthorized) {\n onUnauthorized();\n }\n\n return result;\n },\n };\n };\n\n const authenticatedHttpClient = createAuthenticatedHttpClient();\n\n let cachedUserUid: string | null = null;\n\n auth.on(\"login\", (user: { uid?: string }) => {\n cachedUserUid = user?.uid ?? null;\n });\n auth.on(\"logout\", () => {\n cachedUserUid = null;\n });\n\n if (auth.isAuthenticated()) {\n auth\n .getMe()\n .then((result) => {\n if (result.data?.uid) {\n cachedUserUid = result.data.uid;\n }\n })\n .catch(() => {});\n }\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: CopilotClient = createCopilotClient(\n authenticatedHttpClient,\n baseURL,\n () => auth.getAccessToken(),\n () => cachedUserUid\n );\n const s3: S3Client = createS3Client(authenticatedHttpClient);\n\n // ASR and TTS clients use WebSocket, pass token getter for authentication\n // Token can be appended to WebSocket URL as query parameter\n const asr: (config: ASRClientConfig) => ASRClient = createASRClient({\n getAccessToken: () => auth.getAccessToken(),\n });\n const asrHttp: (config: ASRHttpClientConfig) => ASRHttpClient = createASRHttpClient({\n getAccessToken: () => auth.getAccessToken(),\n http: authenticatedHttpClient,\n });\n const tts: (config: TTSClientConfig) => TTSClient = createTTSClient({\n getAccessToken: () => auth.getAccessToken(),\n });\n\n // Return unified client interface\n const client: AmasterClient = {\n auth,\n entity,\n bpm,\n workflow,\n asr,\n asrHttp,\n copilot,\n function: functionClient,\n tts,\n s3,\n http: authenticatedHttpClient,\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"]}