@amaster.ai/client 1.1.0-beta.73 → 1.1.0-beta.75

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
@@ -22,6 +22,18 @@ type AdapterResponse = {
22
22
  };
23
23
  type HttpAdapter = (_config: RequestConfig) => Promise<AdapterResponse>;
24
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:
@@ -67,6 +79,10 @@ type HttpClientOptions = {
67
79
  * Set to false to disable automatic error logging
68
80
  */
69
81
  logErrors?: boolean;
82
+ /**
83
+ * Explicitly provide the Taro runtime object when it is not exposed on `globalThis`.
84
+ */
85
+ runtime?: Partial<MiniProgramRuntime>;
70
86
  };
71
87
  type HttpClient = {
72
88
  request<T>(_config: RequestConfig): Promise<ClientResult<T>>;
@@ -95,4 +111,4 @@ declare function getMiniProgramRequest(): MiniProgramRequest | null;
95
111
  */
96
112
  declare function createHttpClient(axiosInstanceOrOptions?: AxiosInstance | HttpClientOptions): HttpClient;
97
113
 
98
- export { type AdapterResponse, type ClientError, type ClientResult, type HttpAdapter, type HttpClient, type HttpClientOptions, type MiniProgramRequest, type RequestConfig, createHttpClient, getMiniProgramRequest, resolveMiniProgramGlobals };
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
@@ -66,6 +65,19 @@ export interface AmasterClientOptions {
66
65
  */
67
66
  baseURL?: string;
68
67
 
68
+ /**
69
+ * Application identifier used for workflow-scoped headers and workflow input auto-fill.
70
+ *
71
+ */
72
+ appId?: string;
73
+
74
+ /**
75
+ * Runtime environment identifier used for workflow headers and workflow input auto-fill.
76
+ *
77
+ * @default "dev"
78
+ */
79
+ env?: string;
80
+
69
81
  /**
70
82
  * Optional custom headers to include in ALL requests
71
83
  *
@@ -123,6 +135,20 @@ export interface AmasterClientOptions {
123
135
  * @default true
124
136
  */
125
137
  autoHandleOAuthCallback?: boolean;
138
+
139
+ /**
140
+ * Automatically redirect to the current page's `?redirect=...` target after successful login
141
+ *
142
+ * Applies to password login, code login, Mini Program login, and OAuth callback handling.
143
+ *
144
+ * @default true
145
+ */
146
+ autoRedirectAfterLogin?: boolean;
147
+
148
+ /**
149
+ * Explicitly provide the Taro runtime object when it is not exposed on `globalThis`.
150
+ */
151
+ runtime?: Partial<MiniProgramRuntime>;
126
152
  }
127
153
 
128
154
  /**
@@ -229,7 +255,7 @@ export interface AmasterClient {
229
255
  *
230
256
  * For detailed documentation, see {@link ./tts.d.ts}
231
257
  */
232
- tts: TTSClientAPI;
258
+ tts: (config: TTSClientConfig) => TTSClientAPI;
233
259
 
234
260
  /**
235
261
  * S3 Storage module
@@ -313,22 +339,59 @@ export interface AmasterClient {
313
339
  * @returns A configured Amaster client instance
314
340
  *
315
341
  */
316
- export declare function createClient(options: AmasterClientOptions): AmasterClient;
342
+ export declare function createClient(options?: AmasterClientOptions): AmasterClient;
343
+
344
+ export { createAutoVoiceReplyController } from "./copilot";
345
+ export {
346
+ createTTSSpeakController,
347
+ preprocessTTSContent,
348
+ splitTextIntoFragments,
349
+ } from "./tts";
317
350
 
318
351
  // Re-export shared common types
319
- export type { ClientResult } from "./common";
352
+ export type { ClientError, ClientResult } from "./common";
320
353
 
321
354
  // Re-export main client interfaces
322
- export type { AuthClientAPI } from "./auth";
323
- export type { EntityClientAPI } from "./entity";
324
- export type { BpmClientAPI } from "./bpm";
325
- export type { WorkflowClientAPI } from "./workflow";
355
+ export type { AuthClientAPI, AuthClientAPI as AuthClient } from "./auth";
356
+ export type {
357
+ AuthEvent,
358
+ EventHandler,
359
+ LoginParams,
360
+ LoginResponse,
361
+ RegisterParams,
362
+ RegisterResponse,
363
+ RefreshTokenResponse,
364
+ SuccessResponse,
365
+ CodeLoginParams,
366
+ CodeLoginType,
367
+ SendCodeParams,
368
+ SendCodeType,
369
+ CaptchaResponse,
370
+ OAuthProvider,
371
+ OAuthBinding,
372
+ MiniProgramLoginParams,
373
+ MiniProgramPhoneParams,
374
+ MiniProgramPhoneResponse,
375
+ UpdateMeParams,
376
+ UpdateProfileParams,
377
+ PermissionCheck,
378
+ Session,
379
+ RevokeAllSessionsResponse,
380
+ User,
381
+ Role,
382
+ Permission,
383
+ RoleDetail,
384
+ PermissionDetail,
385
+ } from "./auth";
386
+ export type { EntityClientAPI, EntityQueryParams, EntityListResponse, FilterOperator, FilterItem, FilterGroup } from "./entity";
387
+ export type { BpmClientAPI, ProcessInstance, Task, TaskQueryParams, ProcessVariable, HistoryTask, HistoryProcessInstance, HistoryActivityInstance, ActivityInstanceTree, UserOperationLog, CamundaVariable, TaskFormSchema } from "./bpm";
388
+ export type { WorkflowClientAPI, WorkflowRunRequest, WorkflowRunResponse, WorkflowInputValue, WorkflowFile } from "./workflow";
326
389
  export type { ASRClient, ASRClientConfig, ASRHttpClient, ASRHttpClientConfig, Recorder, RecorderOptions } from "./asr";
327
- export type { CopilotClientAPI } from "./copilot";
328
- export type { FunctionClientAPI } from "./function";
329
- export type { TTSClientAPI } from "./tts";
330
- export type { S3ClientAPI } from "./s3";
331
- export type { HttpClient } from "./http";
390
+ 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";
391
+ export type { FunctionClientAPI, FunctionClientAPI as FunctionClient } from "./function";
392
+ export type { TTSClientAPI, TTSClientAPI as TTSClient, TTSClientConfig, TTSAudioFormat, TTSSnapshot, TTSSpeakController, TTSSpeakControllerOptions, TTSSpeakOptions, TTSStreamOptions, TTSRuntime, TTSStorageAdapter } from "./tts";
393
+ export type { S3ClientAPI, UploadRes, S3Metadata, S3ClientAPI as S3Client } from "./s3";
394
+ export type { HttpClient, MiniProgramRuntime, RequestConfig } from "./http";
332
395
 
333
396
  // For detailed types, import directly from submodules:
334
397
  // 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;
@@ -108,7 +108,9 @@ export interface WorkflowClientAPI {
108
108
  * Execute a workflow
109
109
  *
110
110
  * Runs a workflow with the provided inputs and returns the result.
111
- * Automatically injects `app_id` from URL if in browser environment.
111
+ * When the parent client is created with `appId` / `env`, workflow requests
112
+ * automatically include `x-tenant-id` / `x-env` headers and backfill
113
+ * `inputs.app_id` / `inputs.env` if those keys are absent.
112
114
  *
113
115
  * @template TOutput - The type of workflow outputs
114
116
  * @param workflowName - Workflow identifier (key/name)
@@ -122,7 +124,7 @@ export interface WorkflowClientAPI {
122
124
  * limit: 100
123
125
  * });
124
126
  *
125
- * if (result.success) {
127
+ * if (result.data) {
126
128
  * console.log('Output:', result.data.outputs);
127
129
  * }
128
130
  *