@amaster.ai/client 1.1.9 β 1.1.11
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 +46 -36
- package/dist/index.cjs +20 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -14
- package/dist/index.d.ts +25 -14
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/types/bpm.d.ts +30 -0
- package/types/copilot.d.ts +122 -0
- package/types/http.d.ts +17 -1
- package/types/index.d.ts +26 -6
- package/types/tts.d.ts +150 -1
- package/types/workflow.d.ts +3 -1
package/README.md
CHANGED
|
@@ -92,8 +92,8 @@ await client.auth.login({
|
|
|
92
92
|
|
|
93
93
|
// 3. Use any service - auth token is automatically attached!
|
|
94
94
|
const users = await client.entity.list("default", "users");
|
|
95
|
-
const tasks = await client.bpm.
|
|
96
|
-
const result = await client.workflow.
|
|
95
|
+
const tasks = await client.bpm.getTasks();
|
|
96
|
+
const result = await client.workflow.run("my-workflow", { data: "value" });
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
## π Authentication
|
|
@@ -168,6 +168,8 @@ if (result.success) {
|
|
|
168
168
|
}
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
`client.entity.list(...)` also accepts `limit` / `offset`, `__orders`, `__keywords`, `__relations`, `__fields`, and `__filter` from `EntityQueryParams`.
|
|
172
|
+
|
|
171
173
|
### Get Single Entity
|
|
172
174
|
|
|
173
175
|
```typescript
|
|
@@ -222,28 +224,24 @@ Manage business processes powered by Camunda 7.
|
|
|
222
224
|
### Start a Process
|
|
223
225
|
|
|
224
226
|
```typescript
|
|
225
|
-
const result = await client.bpm.startProcess({
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
variables: {
|
|
229
|
-
amount: 1000,
|
|
230
|
-
requester: "john@example.com",
|
|
231
|
-
},
|
|
227
|
+
const result = await client.bpm.startProcess("approval-process", {
|
|
228
|
+
amount: 1000,
|
|
229
|
+
requester: "john@example.com",
|
|
232
230
|
});
|
|
233
231
|
```
|
|
234
232
|
|
|
235
|
-
### Get
|
|
233
|
+
### Get Tasks
|
|
236
234
|
|
|
237
235
|
```typescript
|
|
238
|
-
const result = await client.bpm.
|
|
239
|
-
|
|
240
|
-
|
|
236
|
+
const result = await client.bpm.getTasks({
|
|
237
|
+
assignee: "user-123",
|
|
238
|
+
maxResults: 20,
|
|
241
239
|
sortBy: "created",
|
|
242
240
|
sortOrder: "desc",
|
|
243
241
|
});
|
|
244
242
|
|
|
245
|
-
if (result.
|
|
246
|
-
console.log("Tasks:", result.data
|
|
243
|
+
if (result.data) {
|
|
244
|
+
console.log("Tasks:", result.data);
|
|
247
245
|
}
|
|
248
246
|
```
|
|
249
247
|
|
|
@@ -256,10 +254,10 @@ await client.bpm.completeTask("task-id", {
|
|
|
256
254
|
});
|
|
257
255
|
```
|
|
258
256
|
|
|
259
|
-
###
|
|
257
|
+
### Delegate a Task
|
|
260
258
|
|
|
261
259
|
```typescript
|
|
262
|
-
await client.bpm.
|
|
260
|
+
await client.bpm.delegateTask("task-id", "manager-123");
|
|
263
261
|
```
|
|
264
262
|
|
|
265
263
|
## β‘ Workflow Execution
|
|
@@ -267,15 +265,13 @@ await client.bpm.claimTask("task-id");
|
|
|
267
265
|
Execute workflows and automation flows.
|
|
268
266
|
|
|
269
267
|
```typescript
|
|
270
|
-
const result = await client.workflow.
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
filters: { status: "active" },
|
|
274
|
-
},
|
|
268
|
+
const result = await client.workflow.run("data-processing-workflow", {
|
|
269
|
+
dataSource: "users",
|
|
270
|
+
filters: { status: "active" },
|
|
275
271
|
});
|
|
276
272
|
|
|
277
|
-
if (result.
|
|
278
|
-
console.log("Workflow result:", result.data);
|
|
273
|
+
if (result.data) {
|
|
274
|
+
console.log("Workflow result:", result.data.outputs);
|
|
279
275
|
}
|
|
280
276
|
```
|
|
281
277
|
|
|
@@ -570,7 +566,7 @@ if (result.data) {
|
|
|
570
566
|
|
|
571
567
|
## βοΈ S3 Storage
|
|
572
568
|
|
|
573
|
-
|
|
569
|
+
File upload, download, and metadata lookup.
|
|
574
570
|
|
|
575
571
|
```typescript
|
|
576
572
|
// Upload file
|
|
@@ -578,6 +574,9 @@ await client.s3.upload(file);
|
|
|
578
574
|
|
|
579
575
|
// Download file
|
|
580
576
|
await client.s3.download("path/to/file");
|
|
577
|
+
|
|
578
|
+
// Get object metadata
|
|
579
|
+
await client.s3.getMetadata("path/to/file");
|
|
581
580
|
```
|
|
582
581
|
|
|
583
582
|
## βοΈ Configuration
|
|
@@ -702,7 +701,7 @@ const client = createClient();
|
|
|
702
701
|
// One client, automatic token management
|
|
703
702
|
await client.auth.login({ email, password });
|
|
704
703
|
await client.entity.list("default", "users"); // Token automatically attached
|
|
705
|
-
await client.bpm.
|
|
704
|
+
await client.bpm.getTasks(); // Token automatically attached
|
|
706
705
|
```
|
|
707
706
|
|
|
708
707
|
## π API Reference
|
|
@@ -719,14 +718,16 @@ Full authentication API from `@amaster.ai/auth-client`:
|
|
|
719
718
|
- `changePassword(params)` - Change password
|
|
720
719
|
- `refreshToken()` - Manually refresh token
|
|
721
720
|
- `sendCode(params)` - Send verification code
|
|
722
|
-
- `hasPermission(
|
|
721
|
+
- `hasPermission(resource, action)` - Check user permission
|
|
722
|
+
- `hasAnyPermission(permissions)` - Check whether any permission matches
|
|
723
|
+
- `hasAllPermissions(permissions)` - Check whether all permissions match
|
|
723
724
|
- `hasRole(role)` - Check user role
|
|
724
725
|
|
|
725
726
|
### `client.entity`
|
|
726
727
|
|
|
727
728
|
Full CRUD API from `@amaster.ai/entity-client`:
|
|
728
729
|
|
|
729
|
-
- `list(source, entity, params?)` - List entities with pagination
|
|
730
|
+
- `list(source, entity, params?)` - List entities with pagination, filtering, sorting, and query params
|
|
730
731
|
- `get(source, entity, id)` - Get single entity
|
|
731
732
|
- `create(source, entity, data)` - Create new entity
|
|
732
733
|
- `update(source, entity, id, data)` - Update entity
|
|
@@ -739,20 +740,29 @@ Full CRUD API from `@amaster.ai/entity-client`:
|
|
|
739
740
|
|
|
740
741
|
Full BPM API from `@amaster.ai/bpm-client`:
|
|
741
742
|
|
|
742
|
-
- `startProcess(
|
|
743
|
-
- `
|
|
744
|
-
- `
|
|
745
|
-
- `
|
|
746
|
-
- `
|
|
743
|
+
- `startProcess(processKey, inputs?)` - Start process instance
|
|
744
|
+
- `getTasks(params?)` - Query tasks
|
|
745
|
+
- `getTaskCount(params?)` - Get task count
|
|
746
|
+
- `completeTask(taskId, variables)` - Complete a task
|
|
747
|
+
- `delegateTask(taskId, userId)` - Delegate a task
|
|
748
|
+
- `getProcessDefinitions(params?)` - Query process definitions
|
|
749
|
+
- `getHistoryTasks(params?)` - Query historical tasks
|
|
750
|
+
- `getRoles()` / `getUserRoles(userId)` - Query runtime roles
|
|
747
751
|
- And more...
|
|
748
752
|
|
|
749
753
|
### `client.workflow`
|
|
750
754
|
|
|
751
755
|
Workflow execution API from `@amaster.ai/workflow-client`:
|
|
752
756
|
|
|
753
|
-
- `
|
|
754
|
-
|
|
755
|
-
|
|
757
|
+
- `run(workflowName, inputs?)` - Run a workflow
|
|
758
|
+
|
|
759
|
+
### `client.s3`
|
|
760
|
+
|
|
761
|
+
S3 storage API:
|
|
762
|
+
|
|
763
|
+
- `upload(file)` - Upload file
|
|
764
|
+
- `download(path)` - Download file as a blob
|
|
765
|
+
- `getMetadata(key)` - Read object metadata
|
|
756
766
|
|
|
757
767
|
### `client.asr`
|
|
758
768
|
|
package/dist/index.cjs
CHANGED
|
@@ -15,6 +15,7 @@ var httpClient = require('@amaster.ai/http-client');
|
|
|
15
15
|
function createClient(options = {}) {
|
|
16
16
|
const {
|
|
17
17
|
baseURL,
|
|
18
|
+
env = "dev",
|
|
18
19
|
headers = {},
|
|
19
20
|
onUnauthorized,
|
|
20
21
|
onTokenExpired,
|
|
@@ -123,7 +124,9 @@ function createClient(options = {}) {
|
|
|
123
124
|
}
|
|
124
125
|
const entity = entityClient.createEntityClient(authenticatedHttpClient);
|
|
125
126
|
const bpm = bpmClient.createBpmClient(authenticatedHttpClient);
|
|
126
|
-
const workflow = workflowClient.createWorkflowClient(authenticatedHttpClient
|
|
127
|
+
const workflow = workflowClient.createWorkflowClient(authenticatedHttpClient, {
|
|
128
|
+
env
|
|
129
|
+
});
|
|
127
130
|
const functionClient$1 = functionClient.createFunctionClient(authenticatedHttpClient);
|
|
128
131
|
const copilot = copilotClient.createCopilotClient(
|
|
129
132
|
authenticatedHttpClient,
|
|
@@ -163,6 +166,22 @@ function createClient(options = {}) {
|
|
|
163
166
|
return client;
|
|
164
167
|
}
|
|
165
168
|
|
|
169
|
+
Object.defineProperty(exports, "createAutoVoiceReplyController", {
|
|
170
|
+
enumerable: true,
|
|
171
|
+
get: function () { return copilotClient.createAutoVoiceReplyController; }
|
|
172
|
+
});
|
|
173
|
+
Object.defineProperty(exports, "createTTSSpeakController", {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
get: function () { return ttsClient.createTTSSpeakController; }
|
|
176
|
+
});
|
|
177
|
+
Object.defineProperty(exports, "preprocessTTSContent", {
|
|
178
|
+
enumerable: true,
|
|
179
|
+
get: function () { return ttsClient.preprocessTTSContent; }
|
|
180
|
+
});
|
|
181
|
+
Object.defineProperty(exports, "splitTextIntoFragments", {
|
|
182
|
+
enumerable: true,
|
|
183
|
+
get: function () { return ttsClient.splitTextIntoFragments; }
|
|
184
|
+
});
|
|
166
185
|
exports.createClient = createClient;
|
|
167
186
|
//# sourceMappingURL=index.cjs.map
|
|
168
187
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"names":["createHttpClient","createAuthClient","createEntityClient","createBpmClient","createWorkflowClient","functionClient","createFunctionClient","createCopilotClient","createS3Client","createASRClient","createASRHttpClient","createTTSClient"],"mappings":";;;;;;;;;;;;;;AA8FO,SAAS,YAAA,CAA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,GAA2BC,oCAAqB,uBAAuB,CAAA;AAC7E,EAAA,MAAMC,gBAAA,GAAiCC,oCAAqB,uBAAuB,CAAA;AACnF,EAAA,MAAM,OAAA,GAAyBC,iCAAA;AAAA,IAC7B,uBAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAM,KAAK,cAAA,EAAe;AAAA,IAC1B,MAAM;AAAA,GACR;AACA,EAAA,MAAM,EAAA,GAAeC,wBAAe,uBAAuB,CAAA;AAI3D,EAAA,MAAM,MAA8CC,yBAAA,CAAgB;AAAA,IAClE,cAAA,EAAgB,MAAM,IAAA,CAAK,cAAA;AAAe,GAC3C,CAAA;AACD,EAAA,MAAM,UAA0DC,6BAAA,CAAoB;AAAA,IAClF,cAAA,EAAgB,MAAM,IAAA,CAAK,cAAA,EAAe;AAAA,IAC1C,IAAA,EAAM;AAAA,GACP,CAAA;AACD,EAAA,MAAM,MAA8CC,yBAAA,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,EAAUN,gBAAA;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.cjs","sourcesContent":["/**\n * ============================================================================\n * @amaster.ai/client - Unified Amaster Client\n * ============================================================================\n *\n * Supabase-inspired unified API client for the Amaster platform\n *\n * Features:\n * - Single client instance for all services (auth, entity, bpm, workflow)\n * - Automatic token management and refresh\n * - Auto-attach authentication to all requests\n * - Centralized error handling\n *\n * @example\n * ```typescript\n * const client = createClient({\n * 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":["createHttpClient","createAuthClient","createEntityClient","createBpmClient","createWorkflowClient","functionClient","createFunctionClient","createCopilotClient","createS3Client","createASRClient","createASRHttpClient","createTTSClient"],"mappings":";;;;;;;;;;;;;;AA+FO,SAAS,YAAA,CAAa,OAAA,GAAgC,EAAC,EAAkB;AAC9E,EAAA,MAAM;AAAA,IACJ,OAAA;AAAA,IACA,GAAA,GAAM,KAAA;AAAA,IACN,UAAU,EAAC;AAAA,IACX,cAAA;AAAA,IACA,cAAA;AAAA,IACA,uBAAA;AAAA,IACA,sBAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAGJ,EAAA,MAAM,iBAAiBA,2BAAA,CAAiB;AAAA,IACtC,OAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACD,CAAA;AAID,EAAA,MAAM,OAAmBC,2BAAA,CAAiB;AAAA,IACxC,OAAA;AAAA,IACA,OAAA;AAAA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B,MAAM,IAAA,CAAK,cAAA;AAAe,GAC3C,CAAA;AACD,EAAA,MAAM,UAA0DC,6BAAA,CAAoB;AAAA,IAClF,cAAA,EAAgB,MAAM,IAAA,CAAK,cAAA,EAAe;AAAA,IAC1C,IAAA,EAAM;AAAA,GACP,CAAA;AACD,EAAA,MAAM,MAA8CC,yBAAA,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,EAAUN,gBAAA;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.cjs","sourcesContent":["/**\n * ============================================================================\n * @amaster.ai/client - Unified Amaster Client\n * ============================================================================\n *\n * Supabase-inspired unified API client for the Amaster platform\n *\n * Features:\n * - Single client instance for all services (auth, entity, bpm, workflow)\n * - Automatic token management and refresh\n * - Auto-attach authentication to all requests\n * - Centralized error handling\n *\n * @example\n * ```typescript\n * const client = createClient({\n * 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('approval', { amount: 1000 });\n * await client.bpm.getTasks({ assignee: 'currentUserId' });\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.getTasks({ assignee: 'currentUserId' });\n * ```\n */\nexport function createClient(options: AmasterClientOptions = {}): AmasterClient {\n const {\n baseURL,\n env = \"dev\",\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 env,\n });\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/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';
|
|
@@ -33,6 +33,14 @@ interface AmasterClientOptions {
|
|
|
33
33
|
* @example 'https://api.amaster.ai'
|
|
34
34
|
*/
|
|
35
35
|
baseURL?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Runtime environment identifier.
|
|
38
|
+
* Used for request headers such as `x-env` and injected into workflow inputs
|
|
39
|
+
* when `workflow.run(...)` needs environment-aware downstream calls.
|
|
40
|
+
*
|
|
41
|
+
* @default "dev"
|
|
42
|
+
*/
|
|
43
|
+
env?: string;
|
|
36
44
|
/**
|
|
37
45
|
* Optional custom headers to include in all requests
|
|
38
46
|
*/
|
|
@@ -141,13 +149,12 @@ interface AmasterClient {
|
|
|
141
149
|
* @example
|
|
142
150
|
* ```typescript
|
|
143
151
|
* // Start a process
|
|
144
|
-
* await client.bpm.startProcess({
|
|
145
|
-
*
|
|
146
|
-
* variables: { amount: 1000 }
|
|
152
|
+
* await client.bpm.startProcess('approval-process', {
|
|
153
|
+
* amount: 1000
|
|
147
154
|
* });
|
|
148
155
|
*
|
|
149
|
-
* // Get
|
|
150
|
-
* const tasks = await client.bpm.
|
|
156
|
+
* // Get tasks
|
|
157
|
+
* const tasks = await client.bpm.getTasks({ assignee: 'currentUserId' });
|
|
151
158
|
*
|
|
152
159
|
* // Complete a task
|
|
153
160
|
* await client.bpm.completeTask(taskId, { approved: true });
|
|
@@ -159,9 +166,9 @@ interface AmasterClient {
|
|
|
159
166
|
*
|
|
160
167
|
* @example
|
|
161
168
|
* ```typescript
|
|
162
|
-
* //
|
|
163
|
-
* const result = await client.workflow.
|
|
164
|
-
*
|
|
169
|
+
* // Run a workflow
|
|
170
|
+
* const result = await client.workflow.run('my-workflow', {
|
|
171
|
+
* data: 'value'
|
|
165
172
|
* });
|
|
166
173
|
* ```
|
|
167
174
|
*/
|
|
@@ -296,8 +303,11 @@ interface AmasterClient {
|
|
|
296
303
|
* // Upload file
|
|
297
304
|
* await client.s3.upload(file);
|
|
298
305
|
*
|
|
299
|
-
|
|
300
|
-
|
|
306
|
+
* // Download file
|
|
307
|
+
* await client.s3.download('path/to/file');
|
|
308
|
+
*
|
|
309
|
+
* // Read metadata
|
|
310
|
+
* await client.s3.getMetadata('path/to/file');
|
|
301
311
|
* ```
|
|
302
312
|
*/
|
|
303
313
|
s3: S3Client;
|
|
@@ -376,7 +386,8 @@ interface AmasterClient {
|
|
|
376
386
|
*
|
|
377
387
|
* // All subsequent requests automatically include auth token
|
|
378
388
|
* await client.entity.list('default', 'users');
|
|
379
|
-
* await client.bpm.startProcess({
|
|
389
|
+
* await client.bpm.startProcess('approval', { amount: 1000 });
|
|
390
|
+
* await client.bpm.getTasks({ assignee: 'currentUserId' });
|
|
380
391
|
* ```
|
|
381
392
|
*/
|
|
382
393
|
|
|
@@ -419,7 +430,7 @@ interface AmasterClient {
|
|
|
419
430
|
*
|
|
420
431
|
* // Now all requests automatically include the auth token
|
|
421
432
|
* const users = await client.entity.list('default', 'users');
|
|
422
|
-
* const tasks = await client.bpm.
|
|
433
|
+
* const tasks = await client.bpm.getTasks({ assignee: 'currentUserId' });
|
|
423
434
|
* ```
|
|
424
435
|
*/
|
|
425
436
|
declare function createClient(options?: AmasterClientOptions): AmasterClient;
|
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';
|
|
@@ -33,6 +33,14 @@ interface AmasterClientOptions {
|
|
|
33
33
|
* @example 'https://api.amaster.ai'
|
|
34
34
|
*/
|
|
35
35
|
baseURL?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Runtime environment identifier.
|
|
38
|
+
* Used for request headers such as `x-env` and injected into workflow inputs
|
|
39
|
+
* when `workflow.run(...)` needs environment-aware downstream calls.
|
|
40
|
+
*
|
|
41
|
+
* @default "dev"
|
|
42
|
+
*/
|
|
43
|
+
env?: string;
|
|
36
44
|
/**
|
|
37
45
|
* Optional custom headers to include in all requests
|
|
38
46
|
*/
|
|
@@ -141,13 +149,12 @@ interface AmasterClient {
|
|
|
141
149
|
* @example
|
|
142
150
|
* ```typescript
|
|
143
151
|
* // Start a process
|
|
144
|
-
* await client.bpm.startProcess({
|
|
145
|
-
*
|
|
146
|
-
* variables: { amount: 1000 }
|
|
152
|
+
* await client.bpm.startProcess('approval-process', {
|
|
153
|
+
* amount: 1000
|
|
147
154
|
* });
|
|
148
155
|
*
|
|
149
|
-
* // Get
|
|
150
|
-
* const tasks = await client.bpm.
|
|
156
|
+
* // Get tasks
|
|
157
|
+
* const tasks = await client.bpm.getTasks({ assignee: 'currentUserId' });
|
|
151
158
|
*
|
|
152
159
|
* // Complete a task
|
|
153
160
|
* await client.bpm.completeTask(taskId, { approved: true });
|
|
@@ -159,9 +166,9 @@ interface AmasterClient {
|
|
|
159
166
|
*
|
|
160
167
|
* @example
|
|
161
168
|
* ```typescript
|
|
162
|
-
* //
|
|
163
|
-
* const result = await client.workflow.
|
|
164
|
-
*
|
|
169
|
+
* // Run a workflow
|
|
170
|
+
* const result = await client.workflow.run('my-workflow', {
|
|
171
|
+
* data: 'value'
|
|
165
172
|
* });
|
|
166
173
|
* ```
|
|
167
174
|
*/
|
|
@@ -296,8 +303,11 @@ interface AmasterClient {
|
|
|
296
303
|
* // Upload file
|
|
297
304
|
* await client.s3.upload(file);
|
|
298
305
|
*
|
|
299
|
-
|
|
300
|
-
|
|
306
|
+
* // Download file
|
|
307
|
+
* await client.s3.download('path/to/file');
|
|
308
|
+
*
|
|
309
|
+
* // Read metadata
|
|
310
|
+
* await client.s3.getMetadata('path/to/file');
|
|
301
311
|
* ```
|
|
302
312
|
*/
|
|
303
313
|
s3: S3Client;
|
|
@@ -376,7 +386,8 @@ interface AmasterClient {
|
|
|
376
386
|
*
|
|
377
387
|
* // All subsequent requests automatically include auth token
|
|
378
388
|
* await client.entity.list('default', 'users');
|
|
379
|
-
* await client.bpm.startProcess({
|
|
389
|
+
* await client.bpm.startProcess('approval', { amount: 1000 });
|
|
390
|
+
* await client.bpm.getTasks({ assignee: 'currentUserId' });
|
|
380
391
|
* ```
|
|
381
392
|
*/
|
|
382
393
|
|
|
@@ -419,7 +430,7 @@ interface AmasterClient {
|
|
|
419
430
|
*
|
|
420
431
|
* // Now all requests automatically include the auth token
|
|
421
432
|
* const users = await client.entity.list('default', 'users');
|
|
422
|
-
* const tasks = await client.bpm.
|
|
433
|
+
* const tasks = await client.bpm.getTasks({ assignee: 'currentUserId' });
|
|
423
434
|
* ```
|
|
424
435
|
*/
|
|
425
436
|
declare function createClient(options?: AmasterClientOptions): AmasterClient;
|
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
|
|
|
@@ -13,6 +15,7 @@ import { createHttpClient } from '@amaster.ai/http-client';
|
|
|
13
15
|
function createClient(options = {}) {
|
|
14
16
|
const {
|
|
15
17
|
baseURL,
|
|
18
|
+
env = "dev",
|
|
16
19
|
headers = {},
|
|
17
20
|
onUnauthorized,
|
|
18
21
|
onTokenExpired,
|
|
@@ -121,7 +124,9 @@ function createClient(options = {}) {
|
|
|
121
124
|
}
|
|
122
125
|
const entity = createEntityClient(authenticatedHttpClient);
|
|
123
126
|
const bpm = createBpmClient(authenticatedHttpClient);
|
|
124
|
-
const workflow = createWorkflowClient(authenticatedHttpClient
|
|
127
|
+
const workflow = createWorkflowClient(authenticatedHttpClient, {
|
|
128
|
+
env
|
|
129
|
+
});
|
|
125
130
|
const functionClient = createFunctionClient(authenticatedHttpClient);
|
|
126
131
|
const copilot = createCopilotClient(
|
|
127
132
|
authenticatedHttpClient,
|
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;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,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E,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":";;;;;;;;;;;;;;AA+FO,SAAS,YAAA,CAAa,OAAA,GAAgC,EAAC,EAAkB;AAC9E,EAAA,MAAM;AAAA,IACJ,OAAA;AAAA,IACA,GAAA,GAAM,KAAA;AAAA,IACN,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,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;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AA;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('approval', { amount: 1000 });\n * await client.bpm.getTasks({ assignee: 'currentUserId' });\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.getTasks({ assignee: 'currentUserId' });\n * ```\n */\nexport function createClient(options: AmasterClientOptions = {}): AmasterClient {\n const {\n baseURL,\n env = \"dev\",\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 env,\n });\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.11",
|
|
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.11",
|
|
76
|
+
"@amaster.ai/auth-client": "1.1.11",
|
|
77
|
+
"@amaster.ai/bpm-client": "1.1.11",
|
|
78
|
+
"@amaster.ai/copilot-client": "1.1.11",
|
|
79
|
+
"@amaster.ai/entity-client": "1.1.11",
|
|
80
|
+
"@amaster.ai/function-client": "1.1.11",
|
|
81
|
+
"@amaster.ai/http-client": "1.1.11",
|
|
82
|
+
"@amaster.ai/s3-client": "1.1.11",
|
|
83
|
+
"@amaster.ai/tts-client": "1.1.11",
|
|
84
|
+
"@amaster.ai/workflow-client": "1.1.11"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"axios": "^1.11.0"
|
package/types/bpm.d.ts
CHANGED
|
@@ -445,6 +445,22 @@ export interface BpmClientAPI {
|
|
|
445
445
|
params?: { skipCustomListeners?: boolean }
|
|
446
446
|
): Promise<ClientResult<null>>;
|
|
447
447
|
|
|
448
|
+
/**
|
|
449
|
+
* Get currently active activity instances for a process instance
|
|
450
|
+
*
|
|
451
|
+
* @param processInstanceId - Process instance ID
|
|
452
|
+
* @returns Array of active activity instances
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```typescript
|
|
456
|
+
* const result = await client.bpm.getActiveActivities('proc-123');
|
|
457
|
+
* result.data?.forEach((activity) => {
|
|
458
|
+
* console.log(activity.activityId, activity.activityName);
|
|
459
|
+
* });
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
getActiveActivities(processInstanceId: string): Promise<ClientResult<ActivityInstance[]>>;
|
|
463
|
+
|
|
448
464
|
/**
|
|
449
465
|
* Get process variables
|
|
450
466
|
*
|
|
@@ -916,6 +932,20 @@ export interface ProcessXmlResponse {
|
|
|
916
932
|
processDefinitionId: string;
|
|
917
933
|
}
|
|
918
934
|
|
|
935
|
+
/**
|
|
936
|
+
* Runtime active activity instance
|
|
937
|
+
*/
|
|
938
|
+
export interface ActivityInstance {
|
|
939
|
+
id: string;
|
|
940
|
+
activityId: string;
|
|
941
|
+
activityName: string;
|
|
942
|
+
activityType: string;
|
|
943
|
+
processInstanceId: string;
|
|
944
|
+
executionId: string;
|
|
945
|
+
startTime: string;
|
|
946
|
+
endTime?: string;
|
|
947
|
+
}
|
|
948
|
+
|
|
919
949
|
/**
|
|
920
950
|
* Runtime activity instance tree
|
|
921
951
|
*/
|
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
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
*
|
|
21
21
|
* // All subsequent requests automatically include auth token
|
|
22
22
|
* await client.entity.list('default', 'users');
|
|
23
|
-
* await client.bpm.startProcess({
|
|
23
|
+
* await client.bpm.startProcess('approval', { amount: 1000 });
|
|
24
|
+
* await client.bpm.getTasks({ assignee: 'currentUserId' });
|
|
24
25
|
* ```
|
|
25
26
|
*
|
|
26
27
|
* ## Module Documentation
|
|
@@ -52,7 +53,7 @@ import type { CopilotClientAPI } from "./copilot";
|
|
|
52
53
|
import type { FunctionClientAPI } from "./function";
|
|
53
54
|
import type { TTSClientAPI, TTSClientConfig } from "./tts";
|
|
54
55
|
import type { S3ClientAPI } from "./s3";
|
|
55
|
-
import type { HttpClient } from "./http";
|
|
56
|
+
import type { HttpClient, MiniProgramRuntime } from "./http";
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
59
|
* Configuration options for creating an Amaster client
|
|
@@ -65,6 +66,13 @@ export interface AmasterClientOptions {
|
|
|
65
66
|
*/
|
|
66
67
|
baseURL?: string;
|
|
67
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Runtime environment identifier used for workflow headers and workflow input auto-fill.
|
|
71
|
+
*
|
|
72
|
+
* @default "dev"
|
|
73
|
+
*/
|
|
74
|
+
env?: string;
|
|
75
|
+
|
|
68
76
|
/**
|
|
69
77
|
* Optional custom headers to include in ALL requests
|
|
70
78
|
*
|
|
@@ -131,6 +139,11 @@ export interface AmasterClientOptions {
|
|
|
131
139
|
* @default true
|
|
132
140
|
*/
|
|
133
141
|
autoRedirectAfterLogin?: boolean;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Explicitly provide the Taro runtime object when it is not exposed on `globalThis`.
|
|
145
|
+
*/
|
|
146
|
+
runtime?: Partial<MiniProgramRuntime>;
|
|
134
147
|
}
|
|
135
148
|
|
|
136
149
|
/**
|
|
@@ -242,7 +255,7 @@ export interface AmasterClient {
|
|
|
242
255
|
/**
|
|
243
256
|
* S3 Storage module
|
|
244
257
|
*
|
|
245
|
-
* Provides methods for file upload, download, and
|
|
258
|
+
* Provides methods for file upload, download, and metadata lookup.
|
|
246
259
|
*
|
|
247
260
|
* For detailed documentation, see {@link ./s3.d.ts}
|
|
248
261
|
*/
|
|
@@ -323,6 +336,13 @@ export interface AmasterClient {
|
|
|
323
336
|
*/
|
|
324
337
|
export declare function createClient(options?: AmasterClientOptions): AmasterClient;
|
|
325
338
|
|
|
339
|
+
export { createAutoVoiceReplyController } from "./copilot";
|
|
340
|
+
export {
|
|
341
|
+
createTTSSpeakController,
|
|
342
|
+
preprocessTTSContent,
|
|
343
|
+
splitTextIntoFragments,
|
|
344
|
+
} from "./tts";
|
|
345
|
+
|
|
326
346
|
// Re-export shared common types
|
|
327
347
|
export type { ClientError, ClientResult } from "./common";
|
|
328
348
|
|
|
@@ -362,11 +382,11 @@ export type { EntityClientAPI, EntityQueryParams, EntityListResponse, FilterOper
|
|
|
362
382
|
export type { BpmClientAPI, ProcessInstance, Task, TaskQueryParams, ProcessVariable, HistoryTask, HistoryProcessInstance, HistoryActivityInstance, ActivityInstanceTree, UserOperationLog, CamundaVariable, TaskFormSchema } from "./bpm";
|
|
363
383
|
export type { WorkflowClientAPI, WorkflowRunRequest, WorkflowRunResponse, WorkflowInputValue, WorkflowFile } from "./workflow";
|
|
364
384
|
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";
|
|
385
|
+
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
386
|
export type { FunctionClientAPI, FunctionClientAPI as FunctionClient } from "./function";
|
|
367
|
-
export type { TTSClientAPI, TTSClientAPI as TTSClient, TTSClientConfig } from "./tts";
|
|
387
|
+
export type { TTSClientAPI, TTSClientAPI as TTSClient, TTSClientConfig, TTSAudioFormat, TTSSnapshot, TTSSpeakController, TTSSpeakControllerOptions, TTSSpeakOptions, TTSStreamOptions, TTSRuntime, TTSStorageAdapter } from "./tts";
|
|
368
388
|
export type { S3ClientAPI, UploadRes, S3Metadata, S3ClientAPI as S3Client } from "./s3";
|
|
369
|
-
export type { HttpClient, RequestConfig } from "./http";
|
|
389
|
+
export type { HttpClient, MiniProgramRuntime, RequestConfig } from "./http";
|
|
370
390
|
|
|
371
391
|
// For detailed types, import directly from submodules:
|
|
372
392
|
// 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;
|
package/types/workflow.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
111
|
+
* When the parent client is created with `env`, workflow requests
|
|
112
|
+
* automatically include the `x-env` header and backfill `inputs.env`
|
|
113
|
+
* when that key is absent.
|
|
112
114
|
*
|
|
113
115
|
* @template TOutput - The type of workflow outputs
|
|
114
116
|
* @param workflowName - Workflow identifier (key/name)
|