@amaster.ai/client 1.1.9 → 1.1.10
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 +3 -1
- package/dist/index.cjs +16 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/types/copilot.d.ts +122 -0
- package/types/http.d.ts +17 -1
- package/types/index.d.ts +16 -4
- package/types/tts.d.ts +150 -1
package/README.md
CHANGED
|
@@ -719,7 +719,9 @@ Full authentication API from `@amaster.ai/auth-client`:
|
|
|
719
719
|
- `changePassword(params)` - Change password
|
|
720
720
|
- `refreshToken()` - Manually refresh token
|
|
721
721
|
- `sendCode(params)` - Send verification code
|
|
722
|
-
- `hasPermission(
|
|
722
|
+
- `hasPermission(resource, action)` - Check user permission
|
|
723
|
+
- `hasAnyPermission(permissions)` - Check whether any permission matches
|
|
724
|
+
- `hasAllPermissions(permissions)` - Check whether all permissions match
|
|
723
725
|
- `hasRole(role)` - Check user role
|
|
724
726
|
|
|
725
727
|
### `client.entity`
|
package/dist/index.cjs
CHANGED
|
@@ -163,6 +163,22 @@ function createClient(options = {}) {
|
|
|
163
163
|
return client;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
Object.defineProperty(exports, "createAutoVoiceReplyController", {
|
|
167
|
+
enumerable: true,
|
|
168
|
+
get: function () { return copilotClient.createAutoVoiceReplyController; }
|
|
169
|
+
});
|
|
170
|
+
Object.defineProperty(exports, "createTTSSpeakController", {
|
|
171
|
+
enumerable: true,
|
|
172
|
+
get: function () { return ttsClient.createTTSSpeakController; }
|
|
173
|
+
});
|
|
174
|
+
Object.defineProperty(exports, "preprocessTTSContent", {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: function () { return ttsClient.preprocessTTSContent; }
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(exports, "splitTextIntoFragments", {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
get: function () { return ttsClient.splitTextIntoFragments; }
|
|
181
|
+
});
|
|
166
182
|
exports.createClient = createClient;
|
|
167
183
|
//# sourceMappingURL=index.cjs.map
|
|
168
184
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -9,11 +9,11 @@ export { WorkflowFile, WorkflowInputValue, WorkflowRunRequest, WorkflowRunRespon
|
|
|
9
9
|
import { ASRClientConfig, ASRClient, ASRHttpClientConfig, ASRHttpClient } from '@amaster.ai/asr-client';
|
|
10
10
|
export { ASRClient, ASRClientConfig, ASRHttpClient, ASRHttpClientConfig, ASRLanguage } from '@amaster.ai/asr-client';
|
|
11
11
|
import { CopilotClient } from '@amaster.ai/copilot-client';
|
|
12
|
-
export { Conversation, ConversationController, ConversationControllerOptions, ConversationControllerSnapshot, ConversationRequestState, ConversationRuntimeError, CopilotClient, Role as CopilotRole, ErrorMessage, FileContent, ImageContent, MessageContent, MessagesItem, TextContent, TextMessage, ThoughtMessage, ToolMessage, UIRenderMessage } from '@amaster.ai/copilot-client';
|
|
12
|
+
export { AutoVoiceReplyController, AutoVoiceReplyConversation, AutoVoiceReplyMessage, AutoVoiceReplySnapshot, AutoVoiceReplySource, AutoVoiceReplySourceSnapshot, AutoVoiceReplySpeechDriver, AutoVoiceReplySpeechSnapshot, AutoVoiceReplyStorage, Conversation, ConversationController, ConversationControllerOptions, ConversationControllerSnapshot, ConversationRequestState, ConversationRuntimeError, CopilotClient, Role as CopilotRole, CreateAutoVoiceReplyControllerOptions, ErrorMessage, FileContent, ImageContent, MessageContent, MessagesItem, TextContent, TextMessage, ThoughtMessage, ToolMessage, UIRenderMessage, createAutoVoiceReplyController } from '@amaster.ai/copilot-client';
|
|
13
13
|
import { FunctionClient } from '@amaster.ai/function-client';
|
|
14
14
|
export { FunctionClient } from '@amaster.ai/function-client';
|
|
15
15
|
import { TTSClientConfig, TTSClient } from '@amaster.ai/tts-client';
|
|
16
|
-
export { TTSClient, TTSClientConfig } from '@amaster.ai/tts-client';
|
|
16
|
+
export { TTSClient, TTSClientConfig, TTSRuntime, TTSSnapshot, TTSSpeakController, TTSSpeakControllerOptions, TTSSpeakOptions, TTSStorageAdapter, createTTSSpeakController, preprocessTTSContent, splitTextIntoFragments } from '@amaster.ai/tts-client';
|
|
17
17
|
import { S3Client } from '@amaster.ai/s3-client';
|
|
18
18
|
export { S3Client, S3Metadata, UploadRes } from '@amaster.ai/s3-client';
|
|
19
19
|
import { MiniProgramRuntime, HttpClient } from '@amaster.ai/http-client';
|
package/dist/index.d.ts
CHANGED
|
@@ -9,11 +9,11 @@ export { WorkflowFile, WorkflowInputValue, WorkflowRunRequest, WorkflowRunRespon
|
|
|
9
9
|
import { ASRClientConfig, ASRClient, ASRHttpClientConfig, ASRHttpClient } from '@amaster.ai/asr-client';
|
|
10
10
|
export { ASRClient, ASRClientConfig, ASRHttpClient, ASRHttpClientConfig, ASRLanguage } from '@amaster.ai/asr-client';
|
|
11
11
|
import { CopilotClient } from '@amaster.ai/copilot-client';
|
|
12
|
-
export { Conversation, ConversationController, ConversationControllerOptions, ConversationControllerSnapshot, ConversationRequestState, ConversationRuntimeError, CopilotClient, Role as CopilotRole, ErrorMessage, FileContent, ImageContent, MessageContent, MessagesItem, TextContent, TextMessage, ThoughtMessage, ToolMessage, UIRenderMessage } from '@amaster.ai/copilot-client';
|
|
12
|
+
export { AutoVoiceReplyController, AutoVoiceReplyConversation, AutoVoiceReplyMessage, AutoVoiceReplySnapshot, AutoVoiceReplySource, AutoVoiceReplySourceSnapshot, AutoVoiceReplySpeechDriver, AutoVoiceReplySpeechSnapshot, AutoVoiceReplyStorage, Conversation, ConversationController, ConversationControllerOptions, ConversationControllerSnapshot, ConversationRequestState, ConversationRuntimeError, CopilotClient, Role as CopilotRole, CreateAutoVoiceReplyControllerOptions, ErrorMessage, FileContent, ImageContent, MessageContent, MessagesItem, TextContent, TextMessage, ThoughtMessage, ToolMessage, UIRenderMessage, createAutoVoiceReplyController } from '@amaster.ai/copilot-client';
|
|
13
13
|
import { FunctionClient } from '@amaster.ai/function-client';
|
|
14
14
|
export { FunctionClient } from '@amaster.ai/function-client';
|
|
15
15
|
import { TTSClientConfig, TTSClient } from '@amaster.ai/tts-client';
|
|
16
|
-
export { TTSClient, TTSClientConfig } from '@amaster.ai/tts-client';
|
|
16
|
+
export { TTSClient, TTSClientConfig, TTSRuntime, TTSSnapshot, TTSSpeakController, TTSSpeakControllerOptions, TTSSpeakOptions, TTSStorageAdapter, createTTSSpeakController, preprocessTTSContent, splitTextIntoFragments } from '@amaster.ai/tts-client';
|
|
17
17
|
import { S3Client } from '@amaster.ai/s3-client';
|
|
18
18
|
export { S3Client, S3Metadata, UploadRes } from '@amaster.ai/s3-client';
|
|
19
19
|
import { MiniProgramRuntime, HttpClient } from '@amaster.ai/http-client';
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,10 @@ import { createBpmClient } from '@amaster.ai/bpm-client';
|
|
|
4
4
|
import { createWorkflowClient } from '@amaster.ai/workflow-client';
|
|
5
5
|
import { createASRClient, createASRHttpClient } from '@amaster.ai/asr-client';
|
|
6
6
|
import { createCopilotClient } from '@amaster.ai/copilot-client';
|
|
7
|
+
export { createAutoVoiceReplyController } from '@amaster.ai/copilot-client';
|
|
7
8
|
import { createFunctionClient } from '@amaster.ai/function-client';
|
|
8
9
|
import { createTTSClient } from '@amaster.ai/tts-client';
|
|
10
|
+
export { createTTSSpeakController, preprocessTTSContent, splitTextIntoFragments } from '@amaster.ai/tts-client';
|
|
9
11
|
import { createS3Client } from '@amaster.ai/s3-client';
|
|
10
12
|
import { createHttpClient } from '@amaster.ai/http-client';
|
|
11
13
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;AA8FO,SAAS,YAAA,CAAa,OAAA,GAAgC,EAAC,EAAkB;AAC9E,EAAA,MAAM;AAAA,IACJ,OAAA;AA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BAAuB,CAAA;AACnF,EAAA,MAAM,OAAA,GAAyB,mBAAA;AAAA,IAC7B,uBAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAM,KAAK,cAAA,EAAe;AAAA,IAC1B,MAAM;AAAA,GACR;AACA,EAAA,MAAM,EAAA,GAAe,eAAe,uBAAuB,CAAA;AAI3D,EAAA,MAAM,MAA8C,eAAA,CAAgB;AAAA,IAClE,cAAA,EAAgB,MAAM,IAAA,CAAK,cAAA;AAAe,GAC3C,CAAA;AACD,EAAA,MAAM,UAA0D,mBAAA,CAAoB;AAAA,IAClF,cAAA,EAAgB,MAAM,IAAA,CAAK,cAAA,EAAe;AAAA,IAC1C,IAAA,EAAM;AAAA,GACP,CAAA;AACD,EAAA,MAAM,MAA8C,eAAA,CAAgB;AAAA,IAClE,cAAA,EAAgB,MAAM,IAAA,CAAK,cAAA;AAAe,GAC3C,CAAA;AAGD,EAAA,MAAM,MAAA,GAAwB;AAAA,IAC5B,IAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,EAAU,cAAA;AAAA,IACV,GAAA;AAAA,IACA,EAAA;AAAA,IACA,IAAA,EAAM,uBAAA;AAAA;AAAA,IAGN,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 * 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\n * const client = createClient();\n *\n * // With authentication callbacks\n * const client = createClient({\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 autoRedirectAfterLogin,\n runtime,\n } = options;\n\n // Create the base HTTP client\n const baseHttpClient = createHttpClient({\n baseURL,\n headers,\n runtime,\n });\n\n // Create the auth client first using the same base HTTP implementation so\n // mini-program request handling stays consistent across all modules.\n const auth: AuthClient = createAuthClient({\n baseURL,\n headers,\n onTokenExpired,\n onUnauthorized,\n autoHandleOAuthCallback,\n autoRedirectAfterLogin,\n runtime,\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"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AA8FO,SAAS,YAAA,CAAa,OAAA,GAAgC,EAAC,EAAkB;AAC9E,EAAA,MAAM;AAAA,IACJ,OAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,cAAA;AAAA,IACA,cAAA;AAAA,IACA,uBAAA;AAAA,IACA,sBAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAGJ,EAAA,MAAM,iBAAiB,gBAAA,CAAiB;AAAA,IACtC,OAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACD,CAAA;AAID,EAAA,MAAM,OAAmB,gBAAA,CAAiB;AAAA,IACxC,OAAA;AAAA,IACA,OAAA;AAAA,IACA,cAAA;AAAA,IACA,cAAA;AAAA,IACA,uBAAA;AAAA,IACA,sBAAA;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,M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AAAe,GAC3C,CAAA;AAGD,EAAA,MAAM,MAAA,GAAwB;AAAA,IAC5B,IAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,EAAU,cAAA;AAAA,IACV,GAAA;AAAA,IACA,EAAA;AAAA,IACA,IAAA,EAAM,uBAAA;AAAA;AAAA,IAGN,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 * 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\n * const client = createClient();\n *\n * // With authentication callbacks\n * const client = createClient({\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 autoRedirectAfterLogin,\n runtime,\n } = options;\n\n // Create the base HTTP client\n const baseHttpClient = createHttpClient({\n baseURL,\n headers,\n runtime,\n });\n\n // Create the auth client first using the same base HTTP implementation so\n // mini-program request handling stays consistent across all modules.\n const auth: AuthClient = createAuthClient({\n baseURL,\n headers,\n onTokenExpired,\n onUnauthorized,\n autoHandleOAuthCallback,\n autoRedirectAfterLogin,\n runtime,\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amaster.ai/client",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "Unified API client for Amaster platform - All services in one package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -72,16 +72,16 @@
|
|
|
72
72
|
"registry": "https://registry.npmjs.org/"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@amaster.ai/
|
|
76
|
-
"@amaster.ai/
|
|
77
|
-
"@amaster.ai/
|
|
78
|
-
"@amaster.ai/
|
|
79
|
-
"@amaster.ai/
|
|
80
|
-
"@amaster.ai/
|
|
81
|
-
"@amaster.ai/
|
|
82
|
-
"@amaster.ai/
|
|
83
|
-
"@amaster.ai/
|
|
84
|
-
"@amaster.ai/
|
|
75
|
+
"@amaster.ai/asr-client": "1.1.10",
|
|
76
|
+
"@amaster.ai/copilot-client": "1.1.10",
|
|
77
|
+
"@amaster.ai/auth-client": "1.1.10",
|
|
78
|
+
"@amaster.ai/bpm-client": "1.1.10",
|
|
79
|
+
"@amaster.ai/entity-client": "1.1.10",
|
|
80
|
+
"@amaster.ai/function-client": "1.1.10",
|
|
81
|
+
"@amaster.ai/http-client": "1.1.10",
|
|
82
|
+
"@amaster.ai/s3-client": "1.1.10",
|
|
83
|
+
"@amaster.ai/tts-client": "1.1.10",
|
|
84
|
+
"@amaster.ai/workflow-client": "1.1.10"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"axios": "^1.11.0"
|
package/types/copilot.d.ts
CHANGED
|
@@ -80,6 +80,9 @@ interface Conversation {
|
|
|
80
80
|
status: "submitted" | "working" | "completed" | "error";
|
|
81
81
|
messages: MessagesItem[];
|
|
82
82
|
lastUpdated: string;
|
|
83
|
+
requestState?: ConversationRequestState;
|
|
84
|
+
runtimeError?: ConversationRuntimeError | null;
|
|
85
|
+
role?: Role;
|
|
83
86
|
historyId?: string;
|
|
84
87
|
system?: {
|
|
85
88
|
level: "newConversation";
|
|
@@ -92,6 +95,21 @@ interface HistoryState {
|
|
|
92
95
|
hasMore: boolean;
|
|
93
96
|
}
|
|
94
97
|
|
|
98
|
+
type ConversationRequestState =
|
|
99
|
+
| "idle"
|
|
100
|
+
| "submitting"
|
|
101
|
+
| "streaming"
|
|
102
|
+
| "recovering"
|
|
103
|
+
| "error";
|
|
104
|
+
|
|
105
|
+
interface ConversationRuntimeError {
|
|
106
|
+
code: "network" | "unknown";
|
|
107
|
+
message: string;
|
|
108
|
+
retryable: boolean;
|
|
109
|
+
source: "send" | "stream" | "recovery";
|
|
110
|
+
timestamp: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
95
113
|
interface UpdateMessageInput {
|
|
96
114
|
taskId: string;
|
|
97
115
|
messageId: string;
|
|
@@ -140,17 +158,121 @@ interface ConversationController {
|
|
|
140
158
|
updateMessage(input: UpdateMessageInput): void;
|
|
141
159
|
}
|
|
142
160
|
|
|
161
|
+
interface AutoVoiceReplyMessage {
|
|
162
|
+
messageId?: string;
|
|
163
|
+
role?: string;
|
|
164
|
+
kind: string;
|
|
165
|
+
content?: string;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
interface AutoVoiceReplyConversation {
|
|
169
|
+
taskId: string;
|
|
170
|
+
status: string;
|
|
171
|
+
requestState?: string;
|
|
172
|
+
messages: AutoVoiceReplyMessage[];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
interface AutoVoiceReplySourceSnapshot {
|
|
176
|
+
conversations: AutoVoiceReplyConversation[];
|
|
177
|
+
isLoading: boolean;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface AutoVoiceReplySource {
|
|
181
|
+
subscribe(listener: () => void): () => void;
|
|
182
|
+
getSnapshot(): AutoVoiceReplySourceSnapshot;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
interface AutoVoiceReplySpeechSnapshot {
|
|
186
|
+
status: "idle" | "connecting" | "speaking" | "error";
|
|
187
|
+
error?: string | null;
|
|
188
|
+
voice?: string | null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
interface AutoVoiceReplySpeechDriver {
|
|
192
|
+
subscribe(listener: () => void): () => void;
|
|
193
|
+
getSnapshot(): AutoVoiceReplySpeechSnapshot;
|
|
194
|
+
startStream(input: {
|
|
195
|
+
id: string;
|
|
196
|
+
voice?: string | null;
|
|
197
|
+
audioFormat?: "pcm" | "mp3" | "wav" | "opus";
|
|
198
|
+
sampleRate?: number;
|
|
199
|
+
}): Promise<void>;
|
|
200
|
+
appendText(input: { id: string; text: string }): Promise<void>;
|
|
201
|
+
commit(): void;
|
|
202
|
+
finish(): void;
|
|
203
|
+
stop(): void;
|
|
204
|
+
setVoice?(voice: string | null): void;
|
|
205
|
+
getVoice?(): string | null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
interface AutoVoiceReplyStorage {
|
|
209
|
+
getItem(key: string): string | null | undefined;
|
|
210
|
+
setItem(key: string, value: string): void;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
interface AutoVoiceReplySnapshot {
|
|
214
|
+
enabled: boolean;
|
|
215
|
+
status: "idle" | "connecting" | "speaking" | "error";
|
|
216
|
+
connecting: boolean;
|
|
217
|
+
speaking: boolean;
|
|
218
|
+
voice: string | null;
|
|
219
|
+
activeTaskId: string | null;
|
|
220
|
+
suppressedTaskId: string | null;
|
|
221
|
+
error: string | null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
interface AutoVoiceReplyController {
|
|
225
|
+
subscribe(listener: () => void): () => void;
|
|
226
|
+
getSnapshot(): AutoVoiceReplySnapshot;
|
|
227
|
+
setEnabled(enabled: boolean): void;
|
|
228
|
+
toggleEnabled(): void;
|
|
229
|
+
toggleEnabledOrStop(): void;
|
|
230
|
+
stop(): void;
|
|
231
|
+
setVoice(voice: string | null): void;
|
|
232
|
+
getVoice(): string | null;
|
|
233
|
+
destroy(): void;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
interface CreateAutoVoiceReplyControllerOptions {
|
|
237
|
+
source: AutoVoiceReplySource;
|
|
238
|
+
speech: AutoVoiceReplySpeechDriver;
|
|
239
|
+
storage?: AutoVoiceReplyStorage;
|
|
240
|
+
enabledStorageKey?: string;
|
|
241
|
+
defaultVoice?: string | null;
|
|
242
|
+
id?: string;
|
|
243
|
+
audioFormat?: "pcm" | "mp3" | "wav" | "opus";
|
|
244
|
+
sampleRate?: number;
|
|
245
|
+
preprocessText?: (text: string) => string;
|
|
246
|
+
}
|
|
247
|
+
|
|
143
248
|
type CopilotClientAPI = {
|
|
144
249
|
createConversationController(options: ConversationControllerOptions): ConversationController;
|
|
145
250
|
};
|
|
146
251
|
|
|
252
|
+
declare function createAutoVoiceReplyController(
|
|
253
|
+
options: CreateAutoVoiceReplyControllerOptions
|
|
254
|
+
): AutoVoiceReplyController;
|
|
255
|
+
|
|
147
256
|
export {
|
|
257
|
+
createAutoVoiceReplyController,
|
|
258
|
+
type AutoVoiceReplyController,
|
|
259
|
+
type AutoVoiceReplyConversation,
|
|
260
|
+
type AutoVoiceReplyMessage,
|
|
261
|
+
type AutoVoiceReplySnapshot,
|
|
262
|
+
type AutoVoiceReplySource,
|
|
263
|
+
type AutoVoiceReplySourceSnapshot,
|
|
264
|
+
type AutoVoiceReplySpeechDriver,
|
|
265
|
+
type AutoVoiceReplySpeechSnapshot,
|
|
266
|
+
type AutoVoiceReplyStorage,
|
|
148
267
|
type CopilotClientAPI,
|
|
149
268
|
type ConversationController,
|
|
150
269
|
type ConversationControllerOptions,
|
|
151
270
|
type ConversationControllerSnapshot,
|
|
271
|
+
type ConversationRequestState,
|
|
272
|
+
type ConversationRuntimeError,
|
|
152
273
|
type ConversationStrings,
|
|
153
274
|
type Conversation,
|
|
275
|
+
type CreateAutoVoiceReplyControllerOptions,
|
|
154
276
|
type MessagesItem,
|
|
155
277
|
type TextMessage,
|
|
156
278
|
type ErrorMessage,
|
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
|
@@ -52,7 +52,7 @@ import type { CopilotClientAPI } from "./copilot";
|
|
|
52
52
|
import type { FunctionClientAPI } from "./function";
|
|
53
53
|
import type { TTSClientAPI, TTSClientConfig } from "./tts";
|
|
54
54
|
import type { S3ClientAPI } from "./s3";
|
|
55
|
-
import type { HttpClient } from "./http";
|
|
55
|
+
import type { HttpClient, MiniProgramRuntime } from "./http";
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* Configuration options for creating an Amaster client
|
|
@@ -131,6 +131,11 @@ export interface AmasterClientOptions {
|
|
|
131
131
|
* @default true
|
|
132
132
|
*/
|
|
133
133
|
autoRedirectAfterLogin?: boolean;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Explicitly provide the Taro runtime object when it is not exposed on `globalThis`.
|
|
137
|
+
*/
|
|
138
|
+
runtime?: Partial<MiniProgramRuntime>;
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
/**
|
|
@@ -323,6 +328,13 @@ export interface AmasterClient {
|
|
|
323
328
|
*/
|
|
324
329
|
export declare function createClient(options?: AmasterClientOptions): AmasterClient;
|
|
325
330
|
|
|
331
|
+
export { createAutoVoiceReplyController } from "./copilot";
|
|
332
|
+
export {
|
|
333
|
+
createTTSSpeakController,
|
|
334
|
+
preprocessTTSContent,
|
|
335
|
+
splitTextIntoFragments,
|
|
336
|
+
} from "./tts";
|
|
337
|
+
|
|
326
338
|
// Re-export shared common types
|
|
327
339
|
export type { ClientError, ClientResult } from "./common";
|
|
328
340
|
|
|
@@ -362,11 +374,11 @@ export type { EntityClientAPI, EntityQueryParams, EntityListResponse, FilterOper
|
|
|
362
374
|
export type { BpmClientAPI, ProcessInstance, Task, TaskQueryParams, ProcessVariable, HistoryTask, HistoryProcessInstance, HistoryActivityInstance, ActivityInstanceTree, UserOperationLog, CamundaVariable, TaskFormSchema } from "./bpm";
|
|
363
375
|
export type { WorkflowClientAPI, WorkflowRunRequest, WorkflowRunResponse, WorkflowInputValue, WorkflowFile } from "./workflow";
|
|
364
376
|
export type { ASRClient, ASRClientConfig, ASRHttpClient, ASRHttpClientConfig, Recorder, RecorderOptions } from "./asr";
|
|
365
|
-
export type { CopilotClientAPI, CopilotClientAPI as CopilotClient, MessageContent, TextContent, ImageContent, FileContent, ConversationController, ConversationControllerOptions, ConversationControllerSnapshot, Conversation, MessagesItem, TextMessage, ErrorMessage, ThoughtMessage, ToolMessage, UIRenderMessage, Role as CopilotRole } from "./copilot";
|
|
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";
|
|
366
378
|
export type { FunctionClientAPI, FunctionClientAPI as FunctionClient } from "./function";
|
|
367
|
-
export type { TTSClientAPI, TTSClientAPI as TTSClient, TTSClientConfig } from "./tts";
|
|
379
|
+
export type { TTSClientAPI, TTSClientAPI as TTSClient, TTSClientConfig, TTSAudioFormat, TTSSnapshot, TTSSpeakController, TTSSpeakControllerOptions, TTSSpeakOptions, TTSStreamOptions, TTSRuntime, TTSStorageAdapter } from "./tts";
|
|
368
380
|
export type { S3ClientAPI, UploadRes, S3Metadata, S3ClientAPI as S3Client } from "./s3";
|
|
369
|
-
export type { HttpClient, RequestConfig } from "./http";
|
|
381
|
+
export type { HttpClient, MiniProgramRuntime, RequestConfig } from "./http";
|
|
370
382
|
|
|
371
383
|
// For detailed types, import directly from submodules:
|
|
372
384
|
// import type { LoginParams, User } from '@amaster.ai/client/auth'
|
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?:
|
|
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;
|