@amaster.ai/client 1.1.0-beta.72 → 1.1.0-beta.74

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/types/entity.d.ts CHANGED
@@ -241,7 +241,7 @@ export interface EntityClientAPI {
241
241
  * // With type safety
242
242
  * type User = { id: number; name: string; email: string };
243
243
  * const result = await client.entity.list<User>('default', 'users');
244
- * if (result.success) {
244
+ * if (result.data) {
245
245
  * result.data.items.forEach(user => {
246
246
  * console.log(user.name); // Type-safe
247
247
  * });
@@ -266,7 +266,7 @@ export interface EntityClientAPI {
266
266
  *
267
267
  * @example
268
268
  * const result = await client.entity.get('default', 'users', 123);
269
- * if (result.success) {
269
+ * if (result.data) {
270
270
  * console.log('User:', result.data);
271
271
  * }
272
272
  *
@@ -299,7 +299,7 @@ export interface EntityClientAPI {
299
299
  * status: 'active'
300
300
  * });
301
301
  *
302
- * if (result.success) {
302
+ * if (result.data) {
303
303
  * console.log('Created user with ID:', result.data.id);
304
304
  * }
305
305
  *
@@ -327,7 +327,7 @@ export interface EntityClientAPI {
327
327
  * status: 'inactive'
328
328
  * });
329
329
  *
330
- * if (result.success) {
330
+ * if (result.data) {
331
331
  * console.log('Updated:', result.data);
332
332
  * }
333
333
  *
@@ -350,7 +350,7 @@ export interface EntityClientAPI {
350
350
  *
351
351
  * @example
352
352
  * const result = await client.entity.delete('default', 'users', 123);
353
- * if (result.success) {
353
+ * if (!result.error) {
354
354
  * console.log('User deleted');
355
355
  * }
356
356
  *
@@ -373,7 +373,7 @@ export interface EntityClientAPI {
373
373
  *
374
374
  * @example
375
375
  * const result = await client.entity.options('default', 'users', ['id', 'name']);
376
- * if (result.success) {
376
+ * if (result.data) {
377
377
  * result.data.forEach(opt => console.log(opt.name));
378
378
  * }
379
379
  *
@@ -419,7 +419,7 @@ export interface EntityClientAPI {
419
419
  *
420
420
  * @example
421
421
  * const result = await client.entity.bulkDelete('default', 'users', [1, 2, 3]);
422
- * if (result.success) {
422
+ * if (!result.error) {
423
423
  * console.log('3 users deleted');
424
424
  * }
425
425
  *
@@ -28,7 +28,7 @@ export interface FunctionClientAPI {
28
28
  * body: 'Welcome!'
29
29
  * });
30
30
  *
31
- * if (result.success) {
31
+ * if (result.data) {
32
32
  * console.log(result.data.message);
33
33
  * }
34
34
  *
package/types/http.d.ts CHANGED
@@ -21,7 +21,19 @@ type AdapterResponse = {
21
21
  headers?: unknown;
22
22
  };
23
23
  type HttpAdapter = (_config: RequestConfig) => Promise<AdapterResponse>;
24
- type MiniProgramRequest = (_options: any) => any;
24
+ type MiniProgramRequest = (_opts: any) => any;
25
+ type MiniProgramRuntime = {
26
+ Taro?: {
27
+ request?: (_opts: any) => any;
28
+ login?: (_opts?: any) => any;
29
+ getEnv?: () => unknown;
30
+ ENV_TYPE?: Record<string, unknown>;
31
+ miniGlobal?: unknown;
32
+ options?: {
33
+ miniGlobal?: unknown;
34
+ };
35
+ };
36
+ };
25
37
  type HttpClientOptions = {
26
38
  /**
27
39
  * HTTP adapter to use:
@@ -32,10 +44,6 @@ type HttpClientOptions = {
32
44
  * - function: custom adapter
33
45
  */
34
46
  adapter?: "taro" | "axios" | AxiosInstance | HttpAdapter;
35
- /**
36
- * Explicit mini-program request implementation, for example `Taro.request`.
37
- */
38
- miniProgramRequest?: MiniProgramRequest;
39
47
  /**
40
48
  * Base URL to prefix when `config.url` is relative (e.g. "/api/...").
41
49
  *
@@ -71,11 +79,16 @@ type HttpClientOptions = {
71
79
  * Set to false to disable automatic error logging
72
80
  */
73
81
  logErrors?: boolean;
82
+ /**
83
+ * Explicitly provide the Taro runtime object when it is not exposed on `globalThis`.
84
+ */
85
+ runtime?: Partial<MiniProgramRuntime>;
74
86
  };
75
87
  type HttpClient = {
76
88
  request<T>(_config: RequestConfig): Promise<ClientResult<T>>;
77
- miniProgramRequest?: MiniProgramRequest;
78
89
  };
90
+ declare function resolveMiniProgramGlobals(): any;
91
+ declare function getMiniProgramRequest(): MiniProgramRequest | null;
79
92
  /**
80
93
  * Create an HTTP client instance
81
94
  *
@@ -98,4 +111,4 @@ type HttpClient = {
98
111
  */
99
112
  declare function createHttpClient(axiosInstanceOrOptions?: AxiosInstance | HttpClientOptions): HttpClient;
100
113
 
101
- export { type AdapterResponse, type ClientError, type ClientResult, type HttpAdapter, type HttpClient, type HttpClientOptions, type MiniProgramRequest, type RequestConfig, createHttpClient };
114
+ export { type AdapterResponse, type ClientError, type ClientResult, type HttpAdapter, type HttpClient, type HttpClientOptions, type MiniProgramRequest, type MiniProgramRuntime, type RequestConfig, createHttpClient, getMiniProgramRequest, resolveMiniProgramGlobals };
package/types/index.d.ts CHANGED
@@ -9,24 +9,23 @@
9
9
  *
10
10
  * ## Quick Start
11
11
  * ```typescript
12
- * import { createClient } from '@amaster.ai/client';
13
- *
14
- * const client = createClient({
15
- * baseURL: 'https://api.amaster.ai',
16
- * onUnauthorized: () => window.location.href = '/login'
17
- * });
12
+ * import { createClient } from '@amaster.ai/client';
13
+ *
14
+ * const client = createClient({
15
+ * onUnauthorized: () => window.location.href = '/login'
16
+ * });
18
17
  *
19
18
  * // Login
20
19
  * await client.auth.login({ email, password });
21
20
  *
22
21
  * // All subsequent requests automatically include auth token
23
22
  * await client.entity.list('default', 'users');
24
- * await client.bpm.startProcess('approval', {});
23
+ * await client.bpm.startProcess({ processKey: 'approval' });
25
24
  * ```
26
25
  *
27
26
  * ## Module Documentation
28
27
  * For detailed API documentation, see individual module type definitions:
29
- * - **Authentication**: {@link ./auth/index.d.ts} (split into user, password-auth, code-auth, oauth, permissions, profile)
28
+ * - **Authentication**: {@link ./auth/index.d.ts} (split into user, password-auth, code-auth, oauth, permissions, profile, sessions)
30
29
  * - **Entity Operations**: {@link ./entity.d.ts}
31
30
  * - **BPM (Business Process)**: {@link ./bpm.d.ts}
32
31
  * - **Workflow Execution**: {@link ./workflow.d.ts}
@@ -51,9 +50,9 @@ import type { WorkflowClientAPI } from "./workflow";
51
50
  import type { ASRClientConfig, ASRClient, ASRHttpClientConfig, ASRHttpClient } from "./asr";
52
51
  import type { CopilotClientAPI } from "./copilot";
53
52
  import type { FunctionClientAPI } from "./function";
54
- import type { TTSClientAPI } from "./tts";
53
+ import type { TTSClientAPI, TTSClientConfig } from "./tts";
55
54
  import type { S3ClientAPI } from "./s3";
56
- import type { HttpClient } from "./http";
55
+ import type { HttpClient, MiniProgramRuntime } from "./http";
57
56
 
58
57
  /**
59
58
  * Configuration options for creating an Amaster client
@@ -75,11 +74,6 @@ export interface AmasterClientOptions {
75
74
  */
76
75
  headers?: Record<string, string>;
77
76
 
78
- /**
79
- * Explicit mini-program request implementation, for example `Taro.request`.
80
- */
81
- miniProgramRequest?: import("./http").MiniProgramRequest;
82
-
83
77
  /**
84
78
  * Callback triggered when a 401 Unauthorized response is received
85
79
  *
@@ -128,6 +122,20 @@ export interface AmasterClientOptions {
128
122
  * @default true
129
123
  */
130
124
  autoHandleOAuthCallback?: boolean;
125
+
126
+ /**
127
+ * Automatically redirect to the current page's `?redirect=...` target after successful login
128
+ *
129
+ * Applies to password login, code login, Mini Program login, and OAuth callback handling.
130
+ *
131
+ * @default true
132
+ */
133
+ autoRedirectAfterLogin?: boolean;
134
+
135
+ /**
136
+ * Explicitly provide the Taro runtime object when it is not exposed on `globalThis`.
137
+ */
138
+ runtime?: Partial<MiniProgramRuntime>;
131
139
  }
132
140
 
133
141
  /**
@@ -234,7 +242,7 @@ export interface AmasterClient {
234
242
  *
235
243
  * For detailed documentation, see {@link ./tts.d.ts}
236
244
  */
237
- tts: TTSClientAPI;
245
+ tts: (config: TTSClientConfig) => TTSClientAPI;
238
246
 
239
247
  /**
240
248
  * S3 Storage module
@@ -318,22 +326,59 @@ export interface AmasterClient {
318
326
  * @returns A configured Amaster client instance
319
327
  *
320
328
  */
321
- export declare function createClient(options: AmasterClientOptions): AmasterClient;
329
+ export declare function createClient(options?: AmasterClientOptions): AmasterClient;
330
+
331
+ export { createAutoVoiceReplyController } from "./copilot";
332
+ export {
333
+ createTTSSpeakController,
334
+ preprocessTTSContent,
335
+ splitTextIntoFragments,
336
+ } from "./tts";
322
337
 
323
338
  // Re-export shared common types
324
- export type { ClientResult } from "./common";
339
+ export type { ClientError, ClientResult } from "./common";
325
340
 
326
341
  // Re-export main client interfaces
327
- export type { AuthClientAPI } from "./auth";
328
- export type { EntityClientAPI } from "./entity";
329
- export type { BpmClientAPI } from "./bpm";
330
- export type { WorkflowClientAPI } from "./workflow";
342
+ export type { AuthClientAPI, AuthClientAPI as AuthClient } from "./auth";
343
+ export type {
344
+ AuthEvent,
345
+ EventHandler,
346
+ LoginParams,
347
+ LoginResponse,
348
+ RegisterParams,
349
+ RegisterResponse,
350
+ RefreshTokenResponse,
351
+ SuccessResponse,
352
+ CodeLoginParams,
353
+ CodeLoginType,
354
+ SendCodeParams,
355
+ SendCodeType,
356
+ CaptchaResponse,
357
+ OAuthProvider,
358
+ OAuthBinding,
359
+ MiniProgramLoginParams,
360
+ MiniProgramPhoneParams,
361
+ MiniProgramPhoneResponse,
362
+ UpdateMeParams,
363
+ UpdateProfileParams,
364
+ PermissionCheck,
365
+ Session,
366
+ RevokeAllSessionsResponse,
367
+ User,
368
+ Role,
369
+ Permission,
370
+ RoleDetail,
371
+ PermissionDetail,
372
+ } from "./auth";
373
+ export type { EntityClientAPI, EntityQueryParams, EntityListResponse, FilterOperator, FilterItem, FilterGroup } from "./entity";
374
+ export type { BpmClientAPI, ProcessInstance, Task, TaskQueryParams, ProcessVariable, HistoryTask, HistoryProcessInstance, HistoryActivityInstance, ActivityInstanceTree, UserOperationLog, CamundaVariable, TaskFormSchema } from "./bpm";
375
+ export type { WorkflowClientAPI, WorkflowRunRequest, WorkflowRunResponse, WorkflowInputValue, WorkflowFile } from "./workflow";
331
376
  export type { ASRClient, ASRClientConfig, ASRHttpClient, ASRHttpClientConfig, Recorder, RecorderOptions } from "./asr";
332
- export type { CopilotClientAPI } from "./copilot";
333
- export type { FunctionClientAPI } from "./function";
334
- export type { TTSClientAPI } from "./tts";
335
- export type { S3ClientAPI } from "./s3";
336
- export type { HttpClient } from "./http";
377
+ export type { CopilotClientAPI, CopilotClientAPI as CopilotClient, MessageContent, TextContent, ImageContent, FileContent, ConversationController, ConversationControllerOptions, ConversationControllerSnapshot, AutoVoiceReplyController, AutoVoiceReplyConversation, AutoVoiceReplyMessage, AutoVoiceReplySnapshot, AutoVoiceReplySource, AutoVoiceReplySourceSnapshot, AutoVoiceReplySpeechDriver, AutoVoiceReplySpeechSnapshot, AutoVoiceReplyStorage, CreateAutoVoiceReplyControllerOptions, ConversationRequestState, ConversationRuntimeError, Conversation, MessagesItem, TextMessage, ErrorMessage, ThoughtMessage, ToolMessage, UIRenderMessage, Role as CopilotRole } from "./copilot";
378
+ export type { FunctionClientAPI, FunctionClientAPI as FunctionClient } from "./function";
379
+ export type { TTSClientAPI, TTSClientAPI as TTSClient, TTSClientConfig, TTSAudioFormat, TTSSnapshot, TTSSpeakController, TTSSpeakControllerOptions, TTSSpeakOptions, TTSStreamOptions, TTSRuntime, TTSStorageAdapter } from "./tts";
380
+ export type { S3ClientAPI, UploadRes, S3Metadata, S3ClientAPI as S3Client } from "./s3";
381
+ export type { HttpClient, MiniProgramRuntime, RequestConfig } from "./http";
337
382
 
338
383
  // For detailed types, import directly from submodules:
339
384
  // import type { LoginParams, User } from '@amaster.ai/client/auth'
package/types/s3.d.ts CHANGED
@@ -47,7 +47,7 @@ export interface S3ClientAPI {
47
47
  *
48
48
  * @example
49
49
  * const result = await client.s3.download('documents/report.pdf');
50
- * if (result.success) {
50
+ * if (result.data) {
51
51
  * const blob = result.data;
52
52
  * const url = URL.createObjectURL(blob);
53
53
  * window.open(url);
@@ -65,7 +65,7 @@ export interface S3ClientAPI {
65
65
  *
66
66
  * @example
67
67
  * const result = await client.s3.getMetadata('images/photo.jpg');
68
- * if (result.success) {
68
+ * if (result.data) {
69
69
  * console.log('Size:', result.data.contentLength);
70
70
  * console.log('Type:', result.data.contentType);
71
71
  * }
@@ -85,7 +85,7 @@ export interface S3ClientAPI {
85
85
  * const file = fileInput.files[0];
86
86
  *
87
87
  * const result = await client.s3.upload(file);
88
- * if (result.success) {
88
+ * if (result.data) {
89
89
  * console.log('File uploaded:', result.data.url);
90
90
  * console.log('File key:', result.data.key);
91
91
  * }
package/types/tts.d.ts CHANGED
@@ -4,11 +4,57 @@
4
4
  * @module tts
5
5
  */
6
6
 
7
+ export type TTSAudioFormat = "pcm" | "mp3" | "wav" | "opus";
8
+
9
+ export interface TTSStorageAdapter {
10
+ getItem(key: string): string | null | undefined;
11
+ setItem(key: string, value: string): void;
12
+ removeItem?(key: string): void;
13
+ }
14
+
15
+ export interface TTSRuntime {
16
+ Taro?: {
17
+ createInnerAudioContext?: () => {
18
+ src: string;
19
+ autoplay?: boolean;
20
+ obeyMuteSwitch?: boolean;
21
+ play?: () => void;
22
+ stop?: () => void;
23
+ destroy?: () => void;
24
+ onPlay?: (callback: () => void) => void;
25
+ onEnded?: (callback: () => void) => void;
26
+ onStop?: (callback: () => void) => void;
27
+ onError?: (callback: (error: { errMsg?: string }) => void) => void;
28
+ };
29
+ getFileSystemManager?: () => {
30
+ writeFile?: (options: {
31
+ filePath: string;
32
+ data: ArrayBuffer;
33
+ encoding?: string;
34
+ success?: () => void;
35
+ fail?: (error: unknown) => void;
36
+ }) => void;
37
+ unlink?: (options: {
38
+ filePath: string;
39
+ success?: () => void;
40
+ fail?: () => void;
41
+ }) => void;
42
+ };
43
+ env?: {
44
+ USER_DATA_PATH?: string;
45
+ };
46
+ getEnv?: () => unknown;
47
+ ENV_TYPE?: Record<string, unknown>;
48
+ };
49
+ }
50
+
7
51
  /**
8
52
  * TTS Client Configuration
9
53
  *
10
54
  */
11
55
  export interface TTSClientConfig {
56
+ /** Get access token for WebSocket authentication */
57
+ getAccessToken?: () => string | null;
12
58
 
13
59
  /** Voice name, default 'Cherry' */
14
60
  voice?: string;
@@ -17,10 +63,13 @@ export interface TTSClientConfig {
17
63
  autoPlay?: boolean;
18
64
 
19
65
  /** Audio format, default 'pcm' */
20
- audioFormat?: "pcm" | "mp3" | "wav" | "opus";
66
+ audioFormat?: TTSAudioFormat;
21
67
 
22
68
  /** Sample rate, default 24000 */
23
69
  sampleRate?: number;
70
+
71
+ /** Optional runtime bridges for mini-program environments */
72
+ runtime?: TTSRuntime;
24
73
 
25
74
  /** Called when connection is ready */
26
75
  onReady?: () => void;
@@ -39,6 +88,9 @@ export interface TTSClientConfig {
39
88
 
40
89
  /** Called on error */
41
90
  onError?: (error: Error) => void;
91
+
92
+ /** Called when socket is closed */
93
+ onClose?: () => void;
42
94
  }
43
95
 
44
96
  /**
@@ -70,6 +122,21 @@ export interface TTSClientAPI {
70
122
  */
71
123
  speak(text: string): Promise<void>;
72
124
 
125
+ /**
126
+ * Start a streaming TTS request.
127
+ */
128
+ startStream(): void;
129
+
130
+ /**
131
+ * Append text to the current streaming request.
132
+ */
133
+ appendText(text: string): void;
134
+
135
+ /**
136
+ * Commit the current buffered text to the TTS service.
137
+ */
138
+ commitText(): void;
139
+
73
140
  /**
74
141
  * Play audio from chunks
75
142
  *
@@ -91,4 +158,86 @@ export interface TTSClientAPI {
91
158
  *
92
159
  */
93
160
  close(): void;
161
+
162
+ /**
163
+ * Whether the client currently has an open WebSocket connection.
164
+ */
165
+ isConnected(): boolean;
166
+
167
+ /**
168
+ * Whether any audio has been received for the current request.
169
+ */
170
+ hasAudio(): boolean;
171
+
172
+ /**
173
+ * Whether the current response has finished streaming.
174
+ */
175
+ isResponseDone(): boolean;
176
+
177
+ /**
178
+ * Whether audio is currently playing.
179
+ */
180
+ isPlaying(): boolean;
181
+
182
+ /**
183
+ * Whether the current runtime supports streaming playback.
184
+ */
185
+ isStreamingPlayback(): boolean;
186
+ }
187
+
188
+ export interface TTSSpeakOptions {
189
+ id?: string;
190
+ text: string;
191
+ voice?: string;
192
+ audioFormat?: TTSAudioFormat;
193
+ sampleRate?: number;
194
+ }
195
+
196
+ export interface TTSStreamOptions {
197
+ id?: string;
198
+ voice?: string;
199
+ audioFormat?: TTSAudioFormat;
200
+ sampleRate?: number;
201
+ }
202
+
203
+ export interface TTSSnapshot {
204
+ status: "idle" | "connecting" | "speaking" | "error";
205
+ activeId: string | null;
206
+ error: string | null;
207
+ requestId: number;
208
+ text: string | null;
209
+ voice: string | null;
210
+ fallbackMode: "none" | "system";
211
+ }
212
+
213
+ export interface TTSSpeakController {
214
+ getSnapshot(): TTSSnapshot;
215
+ subscribe(listener: (snapshot: TTSSnapshot) => void): () => void;
216
+ speak(options: TTSSpeakOptions): Promise<void>;
217
+ startStream(options: TTSStreamOptions): Promise<void>;
218
+ appendStreamText(options: TTSSpeakOptions): Promise<void>;
219
+ commitStream(): void;
220
+ finishStream(): void;
221
+ stop(options?: { preserveClient?: boolean }): void;
222
+ release(): void;
223
+ toggle(options: TTSSpeakOptions): Promise<void>;
224
+ isActive(id?: string | null): boolean;
225
+ setVoice(voice: string | null): void;
226
+ getVoice(): string | null;
227
+ }
228
+
229
+ export interface TTSSpeakControllerOptions {
230
+ storage?: TTSStorageAdapter;
231
+ voiceStorageKey?: string;
232
+ runtime?: TTSRuntime;
233
+ fallbackToSystemSpeech?: boolean;
94
234
  }
235
+
236
+ export declare function splitTextIntoFragments(text: string, maxLength?: number): string[];
237
+
238
+ export declare function preprocessTTSContent(text: string): string;
239
+
240
+ export declare function createTTSSpeakController(
241
+ createClient: (config: TTSClientConfig) => TTSClientAPI,
242
+ options?: TTSSpeakControllerOptions
243
+ ): TTSSpeakController;
@@ -122,7 +122,7 @@ export interface WorkflowClientAPI {
122
122
  * limit: 100
123
123
  * });
124
124
  *
125
- * if (result.success) {
125
+ * if (result.data) {
126
126
  * console.log('Output:', result.data.outputs);
127
127
  * }
128
128
  *