@amaster.ai/client 1.1.0-beta.2 → 1.1.0-beta.21
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 +9 -9
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -3
- package/dist/index.d.ts +32 -3
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +15 -11
- package/types/copilot.d.ts +206 -41
- package/types/index.d.ts +57 -0
- package/types/s3.d.ts +127 -0
package/README.md
CHANGED
|
@@ -73,15 +73,18 @@ yarn add @amaster.ai/client axios
|
|
|
73
73
|
```typescript
|
|
74
74
|
import { createClient } from "@amaster.ai/client";
|
|
75
75
|
|
|
76
|
-
// 1. Create client instance
|
|
76
|
+
// 1. Create client instance (baseURL is optional)
|
|
77
77
|
const client = createClient({
|
|
78
|
-
baseURL: "https://api.amaster.ai",
|
|
78
|
+
baseURL: "https://api.amaster.ai", // Optional - auto-detects from env in Taro/Mini-program
|
|
79
79
|
onUnauthorized: () => {
|
|
80
80
|
// Handle unauthorized (redirect to login, show modal, etc.)
|
|
81
81
|
window.location.href = "/login";
|
|
82
82
|
},
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
+
// Or simply:
|
|
86
|
+
// const client = createClient({}); // Auto-uses VITE_API_BASE_URL or dev proxy
|
|
87
|
+
|
|
85
88
|
// 2. Login
|
|
86
89
|
await client.auth.login({
|
|
87
90
|
email: "user@example.com",
|
|
@@ -484,13 +487,10 @@ const result = await client.copilot.sendMessage([
|
|
|
484
487
|
console.log(result.data.content);
|
|
485
488
|
|
|
486
489
|
// Streaming response
|
|
487
|
-
await client.copilot.sendMessage(
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
onChunk: (chunk) => console.log(chunk),
|
|
492
|
-
}
|
|
493
|
-
);
|
|
490
|
+
await client.copilot.sendMessage([{ role: "user", content: "Tell me a story" }], {
|
|
491
|
+
stream: true,
|
|
492
|
+
onChunk: (chunk) => console.log(chunk),
|
|
493
|
+
});
|
|
494
494
|
```
|
|
495
495
|
|
|
496
496
|
### `client.function`
|
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,7 @@ var asrClient = require('@amaster.ai/asr-client');
|
|
|
8
8
|
var copilotClient = require('@amaster.ai/copilot-client');
|
|
9
9
|
var functionClient = require('@amaster.ai/function-client');
|
|
10
10
|
var ttsClient = require('@amaster.ai/tts-client');
|
|
11
|
+
var s3Client = require('@amaster.ai/s3-client');
|
|
11
12
|
var httpClient = require('@amaster.ai/http-client');
|
|
12
13
|
|
|
13
14
|
// src/client.ts
|
|
@@ -49,6 +50,7 @@ function createClient(options) {
|
|
|
49
50
|
const workflow = workflowClient.createWorkflowClient(authenticatedHttpClient);
|
|
50
51
|
const functionClient$1 = functionClient.createFunctionClient(authenticatedHttpClient);
|
|
51
52
|
const copilot = copilotClient.createCopilotA2UIClient(authenticatedHttpClient);
|
|
53
|
+
const s3 = s3Client.createS3Client(authenticatedHttpClient);
|
|
52
54
|
const asr = asrClient.createASRClient({});
|
|
53
55
|
const tts = ttsClient.createTTSClient({});
|
|
54
56
|
const client = {
|
|
@@ -60,6 +62,7 @@ function createClient(options) {
|
|
|
60
62
|
copilot,
|
|
61
63
|
function: functionClient$1,
|
|
62
64
|
tts,
|
|
65
|
+
s3,
|
|
63
66
|
// Expose token management methods from auth client
|
|
64
67
|
isAuthenticated: () => auth.isAuthenticated(),
|
|
65
68
|
getAccessToken: () => auth.getAccessToken(),
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"names":["createHttpClient","createAuthClient","createEntityClient","createBpmClient","createWorkflowClient","functionClient","createFunctionClient","createCopilotA2UIClient","createASRClient","createTTSClient"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":["createHttpClient","createAuthClient","createEntityClient","createBpmClient","createWorkflowClient","functionClient","createFunctionClient","createCopilotA2UIClient","createS3Client","createASRClient","createTTSClient"],"mappings":";;;;;;;;;;;;;;AA+FO,SAAS,aAAa,OAAA,EAA8C;AACzE,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,GAAU,EAAC,EAAG,cAAA,EAAgB,gBAAe,GAAI,OAAA;AAGlE,EAAA,MAAM,iBAAiBA,2BAAA,CAAiB;AAAA,IACtC,OAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,OAAmBC,2BAAA,CAAiB;AAAA,IACxC,OAAA;AAAA,IACA,OAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,gCAAgC,MAAkB;AACtD,IAAA,OAAO;AAAA,MACL,MAAM,QAAW,MAAA,EAAiD;AAEhE,QAAA,MAAM,KAAA,GAAQ,KAAK,cAAA,EAAe;AAGlC,QAAA,MAAM,WAAA,GAAc,QAAQ,EAAE,aAAA,EAAe,UAAU,KAAK,CAAA,CAAA,KAAO,EAAC;AACpE,QAAA,MAAM,YAAA,GAA8B;AAAA,UAClC,GAAG,MAAA;AAAA,UACH,OAAA,EAAS;AAAA,YACP,GAAG,MAAA,CAAO,OAAA;AAAA,YACV,GAAG;AAAA;AACL,SACF;AAGA,QAAA,MAAM,MAAA,GAAS,MAAM,cAAA,CAAe,OAAA,CAAW,YAAY,CAAA;AAG3D,QAAA,IAAI,MAAA,CAAO,MAAA,KAAW,GAAA,IAAO,cAAA,EAAgB;AAC3C,UAAA,cAAA,EAAe;AAAA,QACjB;AAEA,QAAA,OAAO,MAAA;AAAA,MACT;AAAA,KACF;AAAA,EACF,CAAA;AAGA,EAAA,MAAM,0BAA0B,6BAAA,EAA8B;AAG9D,EAAA,MAAM,MAAA,GAAuBC,gCAAmB,uBAAuB,CAAA;AACvE,EAAA,MAAM,GAAA,GAAiBC,0BAAgB,uBAAuB,CAAA;AAC9D,EAAA,MAAM,QAAA,GAA2BC,oCAAqB,uBAAuB,CAAA;AAC7E,EAAA,MAAMC,gBAAA,GAAiCC,oCAAqB,uBAAuB,CAAA;AACnF,EAAA,MAAM,OAAA,GAA6BC,sCAAwB,uBAAuB,CAAA;AAClF,EAAA,MAAM,EAAA,GAAeC,wBAAe,uBAAuB,CAAA;AAI3D,EAAA,MAAM,GAAA,GAAiBC,yBAAA,CAAgB,EAAE,CAAA;AACzC,EAAA,MAAM,GAAA,GAAiBC,yBAAA,CAAgB,EAAE,CAAA;AAGzC,EAAA,MAAM,MAAA,GAAwB;AAAA,IAC5B,IAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,EAAUL,gBAAA;AAAA,IACV,GAAA;AAAA,IACA,EAAA;AAAA;AAAA,IAGA,eAAA,EAAiB,MAAM,IAAA,CAAK,eAAA,EAAgB;AAAA,IAC5C,cAAA,EAAgB,MAAM,IAAA,CAAK,cAAA,EAAe;AAAA,IAC1C,cAAA,EAAgB,CAAC,KAAA,KAAkB,IAAA,CAAK,eAAe,KAAK,CAAA;AAAA,IAC5D,SAAA,EAAW,MAAM,IAAA,CAAK,SAAA;AAAU,GAClC;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.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 * // With explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => window.location.href = '/login'\n * });\n * \n * // Auto-detect baseURL from env (Taro/Mini-program)\n * const client = createClient({\n * onUnauthorized: () => window.location.href = '/login'\n * });\n * \n * // Login\n * await client.auth.login({ email, password });\n * \n * // All subsequent requests automatically include auth token\n * await client.entity.list('default', 'users');\n * await client.bpm.startProcess({ processKey: 'approval' });\n * ```\n */\n\nimport { createAuthClient, type AuthClient } from \"@amaster.ai/auth-client\";\nimport { createEntityClient, type EntityClient } from \"@amaster.ai/entity-client\";\nimport { createBpmClient, type BpmClient } from \"@amaster.ai/bpm-client\";\nimport { createWorkflowClient, type WorkflowClient } from \"@amaster.ai/workflow-client\";\nimport { createASRClient, type ASRClient } from \"@amaster.ai/asr-client\";\nimport { createCopilotA2UIClient, type CopilotA2UIClient } from \"@amaster.ai/copilot-client\";\nimport { createFunctionClient, type FunctionClient } from \"@amaster.ai/function-client\";\nimport { createTTSClient, type TTSClient } from \"@amaster.ai/tts-client\";\nimport { createS3Client, type S3Client } from \"@amaster.ai/s3-client\";\nimport { createHttpClient, type HttpClient, type RequestConfig, type ClientResult } from \"@amaster.ai/http-client\";\nimport type { AmasterClient, AmasterClientOptions } from \"./types\";\n\n/**\n * Create a unified Amaster client instance\n * \n * This function creates a single client that provides access to all Amaster services:\n * - Authentication (login, register, logout)\n * - Entity CRUD operations\n * - BPM (Business Process Management)\n * - Workflow execution\n * \n * All sub-clients automatically share the same HTTP client and authentication state,\n * ensuring that tokens are consistently attached to all requests.\n * \n * @param options - Client configuration options\n * @returns A unified Amaster client instance\n * \n * @example\n * ```typescript\n * // Basic usage with explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai'\n * });\n * \n * // Auto-detect baseURL (for Taro/Mini-program or dev proxy)\n * const client = createClient({});\n * \n * // With authentication callbacks\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => {\n * // Redirect to login or show auth modal\n * window.location.href = '/login';\n * },\n * onTokenExpired: () => {\n * console.log('Token expired, refreshing...');\n * }\n * });\n * \n * // Login\n * await client.auth.login({\n * email: 'user@example.com',\n * password: 'password123'\n * });\n * \n * // Now all requests automatically include the auth token\n * const users = await client.entity.list('default', 'users');\n * const tasks = await client.bpm.getMyTasks();\n * ```\n */\nexport function createClient(options: AmasterClientOptions): AmasterClient {\n const { baseURL, headers = {}, onUnauthorized, onTokenExpired } = options;\n\n // Create the base HTTP client\n const baseHttpClient = createHttpClient({\n baseURL,\n headers,\n });\n\n // Create the auth client first (it manages its own HTTP client internally)\n const auth: AuthClient = createAuthClient({\n baseURL,\n headers,\n onTokenExpired,\n onUnauthorized,\n });\n\n // Create a wrapper HTTP client that automatically adds the auth token\n const createAuthenticatedHttpClient = (): HttpClient => {\n return {\n async request<T>(config: RequestConfig): Promise<ClientResult<T>> {\n // Get the current token from auth client\n const token = auth.getAccessToken();\n \n // Merge Authorization header with existing headers\n const authHeaders = token ? { Authorization: `Bearer ${token}` } : {};\n const mergedConfig: RequestConfig = {\n ...config,\n headers: {\n ...config.headers,\n ...authHeaders,\n },\n };\n\n // Make the request with the updated config\n const result = await baseHttpClient.request<T>(mergedConfig);\n\n // Handle 401 errors\n if (result.status === 401 && onUnauthorized) {\n onUnauthorized();\n }\n\n return result;\n },\n };\n };\n\n // Create the authenticated HTTP client\n const authenticatedHttpClient = createAuthenticatedHttpClient();\n\n // Create other clients using the authenticated HTTP client\n const entity: EntityClient = createEntityClient(authenticatedHttpClient);\n const bpm: BpmClient = createBpmClient(authenticatedHttpClient);\n const workflow: WorkflowClient = createWorkflowClient(authenticatedHttpClient);\n const functionClient: FunctionClient = createFunctionClient(authenticatedHttpClient);\n const copilot: CopilotA2UIClient = createCopilotA2UIClient(authenticatedHttpClient);\n const s3: S3Client = createS3Client(authenticatedHttpClient);\n\n // ASR and TTS clients use WebSocket, create with default config\n // Users can reconfigure by accessing client.asr / client.tts directly\n const asr: ASRClient = createASRClient({});\n const tts: TTSClient = createTTSClient({});\n\n // Return unified client interface\n const client: AmasterClient = {\n auth,\n entity,\n bpm,\n workflow,\n asr,\n copilot,\n function: functionClient,\n tts,\n s3,\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
|
@@ -14,6 +14,8 @@ import { FunctionClient } from '@amaster.ai/function-client';
|
|
|
14
14
|
export { FunctionClient } from '@amaster.ai/function-client';
|
|
15
15
|
import { TTSClient } from '@amaster.ai/tts-client';
|
|
16
16
|
export { TTSClient, TTSClientConfig } from '@amaster.ai/tts-client';
|
|
17
|
+
import { S3Client } from '@amaster.ai/s3-client';
|
|
18
|
+
export { S3Client, S3Metadata, UploadRes } from '@amaster.ai/s3-client';
|
|
17
19
|
export { ClientError, ClientResult } from '@amaster.ai/http-client';
|
|
18
20
|
|
|
19
21
|
/**
|
|
@@ -21,10 +23,15 @@ export { ClientError, ClientResult } from '@amaster.ai/http-client';
|
|
|
21
23
|
*/
|
|
22
24
|
interface AmasterClientOptions {
|
|
23
25
|
/**
|
|
24
|
-
* Base URL for the Amaster API
|
|
26
|
+
* Base URL for the Amaster API (optional)
|
|
27
|
+
*
|
|
28
|
+
* If not provided:
|
|
29
|
+
* - Browser/H5: Uses dev proxy or relative URLs
|
|
30
|
+
* - Taro/Mini-program: Auto-reads from process.env.TARO_APP_API_BASE_URL or VITE_API_BASE_URL
|
|
31
|
+
*
|
|
25
32
|
* @example 'https://api.amaster.ai'
|
|
26
33
|
*/
|
|
27
|
-
baseURL
|
|
34
|
+
baseURL?: string;
|
|
28
35
|
/**
|
|
29
36
|
* Optional custom headers to include in all requests
|
|
30
37
|
*/
|
|
@@ -188,6 +195,19 @@ interface AmasterClient {
|
|
|
188
195
|
* ```
|
|
189
196
|
*/
|
|
190
197
|
tts: TTSClient;
|
|
198
|
+
/**
|
|
199
|
+
* S3 Storage module
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* // Upload file
|
|
204
|
+
* await client.s3.upload(file);
|
|
205
|
+
*
|
|
206
|
+
* // Download file
|
|
207
|
+
* await client.s3.download('path/to/file');
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
s3: S3Client;
|
|
191
211
|
/**
|
|
192
212
|
* Check if the user is currently authenticated
|
|
193
213
|
*/
|
|
@@ -221,11 +241,17 @@ interface AmasterClient {
|
|
|
221
241
|
*
|
|
222
242
|
* @example
|
|
223
243
|
* ```typescript
|
|
244
|
+
* // With explicit baseURL
|
|
224
245
|
* const client = createClient({
|
|
225
246
|
* baseURL: 'https://api.amaster.ai',
|
|
226
247
|
* onUnauthorized: () => window.location.href = '/login'
|
|
227
248
|
* });
|
|
228
249
|
*
|
|
250
|
+
* // Auto-detect baseURL from env (Taro/Mini-program)
|
|
251
|
+
* const client = createClient({
|
|
252
|
+
* onUnauthorized: () => window.location.href = '/login'
|
|
253
|
+
* });
|
|
254
|
+
*
|
|
229
255
|
* // Login
|
|
230
256
|
* await client.auth.login({ email, password });
|
|
231
257
|
*
|
|
@@ -252,11 +278,14 @@ interface AmasterClient {
|
|
|
252
278
|
*
|
|
253
279
|
* @example
|
|
254
280
|
* ```typescript
|
|
255
|
-
* // Basic usage
|
|
281
|
+
* // Basic usage with explicit baseURL
|
|
256
282
|
* const client = createClient({
|
|
257
283
|
* baseURL: 'https://api.amaster.ai'
|
|
258
284
|
* });
|
|
259
285
|
*
|
|
286
|
+
* // Auto-detect baseURL (for Taro/Mini-program or dev proxy)
|
|
287
|
+
* const client = createClient({});
|
|
288
|
+
*
|
|
260
289
|
* // With authentication callbacks
|
|
261
290
|
* const client = createClient({
|
|
262
291
|
* baseURL: 'https://api.amaster.ai',
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ import { FunctionClient } from '@amaster.ai/function-client';
|
|
|
14
14
|
export { FunctionClient } from '@amaster.ai/function-client';
|
|
15
15
|
import { TTSClient } from '@amaster.ai/tts-client';
|
|
16
16
|
export { TTSClient, TTSClientConfig } from '@amaster.ai/tts-client';
|
|
17
|
+
import { S3Client } from '@amaster.ai/s3-client';
|
|
18
|
+
export { S3Client, S3Metadata, UploadRes } from '@amaster.ai/s3-client';
|
|
17
19
|
export { ClientError, ClientResult } from '@amaster.ai/http-client';
|
|
18
20
|
|
|
19
21
|
/**
|
|
@@ -21,10 +23,15 @@ export { ClientError, ClientResult } from '@amaster.ai/http-client';
|
|
|
21
23
|
*/
|
|
22
24
|
interface AmasterClientOptions {
|
|
23
25
|
/**
|
|
24
|
-
* Base URL for the Amaster API
|
|
26
|
+
* Base URL for the Amaster API (optional)
|
|
27
|
+
*
|
|
28
|
+
* If not provided:
|
|
29
|
+
* - Browser/H5: Uses dev proxy or relative URLs
|
|
30
|
+
* - Taro/Mini-program: Auto-reads from process.env.TARO_APP_API_BASE_URL or VITE_API_BASE_URL
|
|
31
|
+
*
|
|
25
32
|
* @example 'https://api.amaster.ai'
|
|
26
33
|
*/
|
|
27
|
-
baseURL
|
|
34
|
+
baseURL?: string;
|
|
28
35
|
/**
|
|
29
36
|
* Optional custom headers to include in all requests
|
|
30
37
|
*/
|
|
@@ -188,6 +195,19 @@ interface AmasterClient {
|
|
|
188
195
|
* ```
|
|
189
196
|
*/
|
|
190
197
|
tts: TTSClient;
|
|
198
|
+
/**
|
|
199
|
+
* S3 Storage module
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* // Upload file
|
|
204
|
+
* await client.s3.upload(file);
|
|
205
|
+
*
|
|
206
|
+
* // Download file
|
|
207
|
+
* await client.s3.download('path/to/file');
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
s3: S3Client;
|
|
191
211
|
/**
|
|
192
212
|
* Check if the user is currently authenticated
|
|
193
213
|
*/
|
|
@@ -221,11 +241,17 @@ interface AmasterClient {
|
|
|
221
241
|
*
|
|
222
242
|
* @example
|
|
223
243
|
* ```typescript
|
|
244
|
+
* // With explicit baseURL
|
|
224
245
|
* const client = createClient({
|
|
225
246
|
* baseURL: 'https://api.amaster.ai',
|
|
226
247
|
* onUnauthorized: () => window.location.href = '/login'
|
|
227
248
|
* });
|
|
228
249
|
*
|
|
250
|
+
* // Auto-detect baseURL from env (Taro/Mini-program)
|
|
251
|
+
* const client = createClient({
|
|
252
|
+
* onUnauthorized: () => window.location.href = '/login'
|
|
253
|
+
* });
|
|
254
|
+
*
|
|
229
255
|
* // Login
|
|
230
256
|
* await client.auth.login({ email, password });
|
|
231
257
|
*
|
|
@@ -252,11 +278,14 @@ interface AmasterClient {
|
|
|
252
278
|
*
|
|
253
279
|
* @example
|
|
254
280
|
* ```typescript
|
|
255
|
-
* // Basic usage
|
|
281
|
+
* // Basic usage with explicit baseURL
|
|
256
282
|
* const client = createClient({
|
|
257
283
|
* baseURL: 'https://api.amaster.ai'
|
|
258
284
|
* });
|
|
259
285
|
*
|
|
286
|
+
* // Auto-detect baseURL (for Taro/Mini-program or dev proxy)
|
|
287
|
+
* const client = createClient({});
|
|
288
|
+
*
|
|
260
289
|
* // With authentication callbacks
|
|
261
290
|
* const client = createClient({
|
|
262
291
|
* baseURL: 'https://api.amaster.ai',
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { createASRClient } from '@amaster.ai/asr-client';
|
|
|
6
6
|
import { createCopilotA2UIClient } from '@amaster.ai/copilot-client';
|
|
7
7
|
import { createFunctionClient } from '@amaster.ai/function-client';
|
|
8
8
|
import { createTTSClient } from '@amaster.ai/tts-client';
|
|
9
|
+
import { createS3Client } from '@amaster.ai/s3-client';
|
|
9
10
|
import { createHttpClient } from '@amaster.ai/http-client';
|
|
10
11
|
|
|
11
12
|
// src/client.ts
|
|
@@ -47,6 +48,7 @@ function createClient(options) {
|
|
|
47
48
|
const workflow = createWorkflowClient(authenticatedHttpClient);
|
|
48
49
|
const functionClient = createFunctionClient(authenticatedHttpClient);
|
|
49
50
|
const copilot = createCopilotA2UIClient(authenticatedHttpClient);
|
|
51
|
+
const s3 = createS3Client(authenticatedHttpClient);
|
|
50
52
|
const asr = createASRClient({});
|
|
51
53
|
const tts = createTTSClient({});
|
|
52
54
|
const client = {
|
|
@@ -58,6 +60,7 @@ function createClient(options) {
|
|
|
58
60
|
copilot,
|
|
59
61
|
function: functionClient,
|
|
60
62
|
tts,
|
|
63
|
+
s3,
|
|
61
64
|
// Expose token management methods from auth client
|
|
62
65
|
isAuthenticated: () => auth.isAuthenticated(),
|
|
63
66
|
getAccessToken: () => auth.getAccessToken(),
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;AA+FO,SAAS,aAAa,OAAA,EAA8C;AACzE,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,GAAU,EAAC,EAAG,cAAA,EAAgB,gBAAe,GAAI,OAAA;AAGlE,EAAA,MAAM,iBAAiB,gBAAA,CAAiB;AAAA,IACtC,OAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,OAAmB,gBAAA,CAAiB;AAAA,IACxC,OAAA;AAAA,IACA,OAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,gCAAgC,MAAkB;AACtD,IAAA,OAAO;AAAA,MACL,MAAM,QAAW,MAAA,EAAiD;AAEhE,QAAA,MAAM,KAAA,GAAQ,KAAK,cAAA,EAAe;AAGlC,QAAA,MAAM,WAAA,GAAc,QAAQ,EAAE,aAAA,EAAe,UAAU,KAAK,CAAA,CAAA,KAAO,EAAC;AACpE,QAAA,MAAM,YAAA,GAA8B;AAAA,UAClC,GAAG,MAAA;AAAA,UACH,OAAA,EAAS;AAAA,YACP,GAAG,MAAA,CAAO,OAAA;AAAA,YACV,GAAG;AAAA;AACL,SACF;AAGA,QAAA,MAAM,MAAA,GAAS,MAAM,cAAA,CAAe,OAAA,CAAW,YAAY,CAAA;AAG3D,QAAA,IAAI,MAAA,CAAO,MAAA,KAAW,GAAA,IAAO,cAAA,EAAgB;AAC3C,UAAA,cAAA,EAAe;AAAA,QACjB;AAEA,QAAA,OAAO,MAAA;AAAA,MACT;AAAA,KACF;AAAA,EACF,CAAA;AAGA,EAAA,MAAM,0BAA0B,6BAAA,EAA8B;AAG9D,EAAA,MAAM,MAAA,GAAuB,mBAAmB,uBAAuB,CAAA;AACvE,EAAA,MAAM,GAAA,GAAiB,gBAAgB,uBAAuB,CAAA;AAC9D,EAAA,MAAM,QAAA,GAA2B,qBAAqB,uBAAuB,CAAA;AAC7E,EAAA,MAAM,cAAA,GAAiC,qBAAqB,uBAAuB,CAAA;AACnF,EAAA,MAAM,OAAA,GAA6B,wBAAwB,uBAAuB,CAAA;AAClF,EAAA,MAAM,EAAA,GAAe,eAAe,uBAAuB,CAAA;AAI3D,EAAA,MAAM,GAAA,GAAiB,eAAA,CAAgB,EAAE,CAAA;AACzC,EAAA,MAAM,GAAA,GAAiB,eAAA,CAAgB,EAAE,CAAA;AAGzC,EAAA,MAAM,MAAA,GAAwB;AAAA,IAC5B,IAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,EAAU,cAAA;AAAA,IACV,GAAA;AAAA,IACA,EAAA;AAAA;AAAA,IAGA,eAAA,EAAiB,MAAM,IAAA,CAAK,eAAA,EAAgB;AAAA,IAC5C,cAAA,EAAgB,MAAM,IAAA,CAAK,cAAA,EAAe;AAAA,IAC1C,cAAA,EAAgB,CAAC,KAAA,KAAkB,IAAA,CAAK,eAAe,KAAK,CAAA;AAAA,IAC5D,SAAA,EAAW,MAAM,IAAA,CAAK,SAAA;AAAU,GAClC;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["/**\n * ============================================================================\n * @amaster.ai/client - Unified Amaster Client\n * ============================================================================\n * \n * Supabase-inspired unified API client for the Amaster platform\n * \n * Features:\n * - Single client instance for all services (auth, entity, bpm, workflow)\n * - Automatic token management and refresh\n * - Auto-attach authentication to all requests\n * - Centralized error handling\n * \n * @example\n * ```typescript\n * // With explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => window.location.href = '/login'\n * });\n * \n * // Auto-detect baseURL from env (Taro/Mini-program)\n * const client = createClient({\n * onUnauthorized: () => window.location.href = '/login'\n * });\n * \n * // Login\n * await client.auth.login({ email, password });\n * \n * // All subsequent requests automatically include auth token\n * await client.entity.list('default', 'users');\n * await client.bpm.startProcess({ processKey: 'approval' });\n * ```\n */\n\nimport { createAuthClient, type AuthClient } from \"@amaster.ai/auth-client\";\nimport { createEntityClient, type EntityClient } from \"@amaster.ai/entity-client\";\nimport { createBpmClient, type BpmClient } from \"@amaster.ai/bpm-client\";\nimport { createWorkflowClient, type WorkflowClient } from \"@amaster.ai/workflow-client\";\nimport { createASRClient, type ASRClient } from \"@amaster.ai/asr-client\";\nimport { createCopilotA2UIClient, type CopilotA2UIClient } from \"@amaster.ai/copilot-client\";\nimport { createFunctionClient, type FunctionClient } from \"@amaster.ai/function-client\";\nimport { createTTSClient, type TTSClient } from \"@amaster.ai/tts-client\";\nimport { createS3Client, type S3Client } from \"@amaster.ai/s3-client\";\nimport { createHttpClient, type HttpClient, type RequestConfig, type ClientResult } from \"@amaster.ai/http-client\";\nimport type { AmasterClient, AmasterClientOptions } from \"./types\";\n\n/**\n * Create a unified Amaster client instance\n * \n * This function creates a single client that provides access to all Amaster services:\n * - Authentication (login, register, logout)\n * - Entity CRUD operations\n * - BPM (Business Process Management)\n * - Workflow execution\n * \n * All sub-clients automatically share the same HTTP client and authentication state,\n * ensuring that tokens are consistently attached to all requests.\n * \n * @param options - Client configuration options\n * @returns A unified Amaster client instance\n * \n * @example\n * ```typescript\n * // Basic usage with explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai'\n * });\n * \n * // Auto-detect baseURL (for Taro/Mini-program or dev proxy)\n * const client = createClient({});\n * \n * // With authentication callbacks\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => {\n * // Redirect to login or show auth modal\n * window.location.href = '/login';\n * },\n * onTokenExpired: () => {\n * console.log('Token expired, refreshing...');\n * }\n * });\n * \n * // Login\n * await client.auth.login({\n * email: 'user@example.com',\n * password: 'password123'\n * });\n * \n * // Now all requests automatically include the auth token\n * const users = await client.entity.list('default', 'users');\n * const tasks = await client.bpm.getMyTasks();\n * ```\n */\nexport function createClient(options: AmasterClientOptions): AmasterClient {\n const { baseURL, headers = {}, onUnauthorized, onTokenExpired } = options;\n\n // Create the base HTTP client\n const baseHttpClient = createHttpClient({\n baseURL,\n headers,\n });\n\n // Create the auth client first (it manages its own HTTP client internally)\n const auth: AuthClient = createAuthClient({\n baseURL,\n headers,\n onTokenExpired,\n onUnauthorized,\n });\n\n // Create a wrapper HTTP client that automatically adds the auth token\n const createAuthenticatedHttpClient = (): HttpClient => {\n return {\n async request<T>(config: RequestConfig): Promise<ClientResult<T>> {\n // Get the current token from auth client\n const token = auth.getAccessToken();\n \n // Merge Authorization header with existing headers\n const authHeaders = token ? { Authorization: `Bearer ${token}` } : {};\n const mergedConfig: RequestConfig = {\n ...config,\n headers: {\n ...config.headers,\n ...authHeaders,\n },\n };\n\n // Make the request with the updated config\n const result = await baseHttpClient.request<T>(mergedConfig);\n\n // Handle 401 errors\n if (result.status === 401 && onUnauthorized) {\n onUnauthorized();\n }\n\n return result;\n },\n };\n };\n\n // Create the authenticated HTTP client\n const authenticatedHttpClient = createAuthenticatedHttpClient();\n\n // Create other clients using the authenticated HTTP client\n const entity: EntityClient = createEntityClient(authenticatedHttpClient);\n const bpm: BpmClient = createBpmClient(authenticatedHttpClient);\n const workflow: WorkflowClient = createWorkflowClient(authenticatedHttpClient);\n const functionClient: FunctionClient = createFunctionClient(authenticatedHttpClient);\n const copilot: CopilotA2UIClient = createCopilotA2UIClient(authenticatedHttpClient);\n const s3: S3Client = createS3Client(authenticatedHttpClient);\n\n // ASR and TTS clients use WebSocket, create with default config\n // Users can reconfigure by accessing client.asr / client.tts directly\n const asr: ASRClient = createASRClient({});\n const tts: TTSClient = createTTSClient({});\n\n // Return unified client interface\n const client: AmasterClient = {\n auth,\n entity,\n bpm,\n workflow,\n asr,\n copilot,\n function: functionClient,\n tts,\n s3,\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.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.21",
|
|
4
4
|
"description": "Unified API client for Amaster platform - All services in one package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -38,6 +38,9 @@
|
|
|
38
38
|
"tts": [
|
|
39
39
|
"./types/tts.d.ts"
|
|
40
40
|
],
|
|
41
|
+
"s3": [
|
|
42
|
+
"./types/s3.d.ts"
|
|
43
|
+
],
|
|
41
44
|
"common": [
|
|
42
45
|
"./types/common.d.ts"
|
|
43
46
|
]
|
|
@@ -69,16 +72,17 @@
|
|
|
69
72
|
"registry": "https://registry.npmjs.org/"
|
|
70
73
|
},
|
|
71
74
|
"dependencies": {
|
|
72
|
-
"@amaster.ai/
|
|
73
|
-
"@amaster.ai/
|
|
74
|
-
"@amaster.ai/
|
|
75
|
-
"@amaster.ai/
|
|
76
|
-
"@amaster.ai/
|
|
77
|
-
"@amaster.ai/
|
|
78
|
-
"@amaster.ai/
|
|
79
|
-
"@amaster.ai/
|
|
80
|
-
"@amaster.ai/
|
|
81
|
-
"@amaster.ai/tts-client": "1.1.0-beta.
|
|
75
|
+
"@amaster.ai/auth-client": "1.1.0-beta.21",
|
|
76
|
+
"@amaster.ai/entity-client": "1.1.0-beta.21",
|
|
77
|
+
"@amaster.ai/bpm-client": "1.1.0-beta.21",
|
|
78
|
+
"@amaster.ai/http-client": "1.1.0-beta.21",
|
|
79
|
+
"@amaster.ai/function-client": "1.1.0-beta.21",
|
|
80
|
+
"@amaster.ai/s3-client": "1.1.0-beta.21",
|
|
81
|
+
"@amaster.ai/copilot-client": "1.1.0-beta.21",
|
|
82
|
+
"@amaster.ai/asr-client": "1.1.0-beta.21",
|
|
83
|
+
"@amaster.ai/workflow-client": "1.1.0-beta.21",
|
|
84
|
+
"@amaster.ai/tts-client": "1.1.0-beta.21",
|
|
85
|
+
"@amaster.ai/asr-http-client": "1.1.0-beta.21"
|
|
82
86
|
},
|
|
83
87
|
"peerDependencies": {
|
|
84
88
|
"axios": "^1.11.0"
|
package/types/copilot.d.ts
CHANGED
|
@@ -10,6 +10,150 @@
|
|
|
10
10
|
|
|
11
11
|
import type { ClientResult } from './common';
|
|
12
12
|
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// A2UI Protocol Types (for streaming UI)
|
|
15
|
+
// ============================================================================
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* String value with data binding support
|
|
19
|
+
*/
|
|
20
|
+
export interface StringValue {
|
|
21
|
+
path?: string;
|
|
22
|
+
literalString?: string;
|
|
23
|
+
literal?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Number value with data binding support
|
|
28
|
+
*/
|
|
29
|
+
export interface NumberValue {
|
|
30
|
+
path?: string;
|
|
31
|
+
literalNumber?: number;
|
|
32
|
+
literal?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Boolean value with data binding support
|
|
37
|
+
*/
|
|
38
|
+
export interface BooleanValue {
|
|
39
|
+
path?: string;
|
|
40
|
+
literalBoolean?: boolean;
|
|
41
|
+
literal?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Component properties in A2UI protocol
|
|
46
|
+
*/
|
|
47
|
+
export type ComponentProperties = Record<string, unknown>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Component instance from server
|
|
51
|
+
*/
|
|
52
|
+
export interface ComponentInstance {
|
|
53
|
+
id: string;
|
|
54
|
+
weight?: number;
|
|
55
|
+
component?: ComponentProperties;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Value map for data model updates
|
|
60
|
+
*/
|
|
61
|
+
export interface ValueMap {
|
|
62
|
+
key: string;
|
|
63
|
+
valueString?: string;
|
|
64
|
+
valueNumber?: number;
|
|
65
|
+
valueBoolean?: boolean;
|
|
66
|
+
valueMap?: ValueMap[];
|
|
67
|
+
[k: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Begin rendering message - initializes a new UI surface
|
|
72
|
+
*/
|
|
73
|
+
export interface BeginRenderingMessage {
|
|
74
|
+
surfaceId: string;
|
|
75
|
+
root: string;
|
|
76
|
+
styles?: Record<string, string>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Surface update message - updates UI components
|
|
81
|
+
*/
|
|
82
|
+
export interface SurfaceUpdateMessage {
|
|
83
|
+
surfaceId: string;
|
|
84
|
+
components: ComponentInstance[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Data model update message - updates data bindings
|
|
89
|
+
*/
|
|
90
|
+
export interface DataModelUpdate {
|
|
91
|
+
surfaceId: string;
|
|
92
|
+
path?: string;
|
|
93
|
+
contents: ValueMap[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Delete surface message - removes a UI surface
|
|
98
|
+
*/
|
|
99
|
+
export interface DeleteSurfaceMessage {
|
|
100
|
+
surfaceId: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Server-to-client message in A2UI protocol
|
|
105
|
+
*
|
|
106
|
+
* Used by the chat() streaming API to send UI updates.
|
|
107
|
+
* Each message can contain one of several update types.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const stream = client.copilot.chat([
|
|
112
|
+
* { role: 'user', content: 'Show me a chart' }
|
|
113
|
+
* ]);
|
|
114
|
+
*
|
|
115
|
+
* for await (const messages of stream) {
|
|
116
|
+
* for (const msg of messages) {
|
|
117
|
+
* if (msg.surfaceUpdate) {
|
|
118
|
+
* // Render UI components
|
|
119
|
+
* renderComponents(msg.surfaceUpdate.components);
|
|
120
|
+
* }
|
|
121
|
+
* if (msg.dataModelUpdate) {
|
|
122
|
+
* // Update data bindings
|
|
123
|
+
* updateData(msg.dataModelUpdate.contents);
|
|
124
|
+
* }
|
|
125
|
+
* }
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export interface ServerToClientMessage {
|
|
130
|
+
beginRendering?: BeginRenderingMessage;
|
|
131
|
+
surfaceUpdate?: SurfaceUpdateMessage;
|
|
132
|
+
dataModelUpdate?: DataModelUpdate;
|
|
133
|
+
deleteSurface?: DeleteSurfaceMessage;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Complete UI surface state
|
|
138
|
+
*/
|
|
139
|
+
export interface Surface {
|
|
140
|
+
rootComponentId: string | null;
|
|
141
|
+
componentTree: unknown | null;
|
|
142
|
+
dataModel: Record<string, unknown>;
|
|
143
|
+
components: Map<string, ComponentInstance>;
|
|
144
|
+
styles: Record<string, string>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Message processor for handling A2UI updates
|
|
149
|
+
*/
|
|
150
|
+
export interface MessageProcessor {
|
|
151
|
+
getSurfaces(): ReadonlyMap<string, Surface>;
|
|
152
|
+
clearSurfaces(): void;
|
|
153
|
+
processMessages(messages: ServerToClientMessage[]): void;
|
|
154
|
+
resolvePath(path: string, dataContextPath?: string): string;
|
|
155
|
+
}
|
|
156
|
+
|
|
13
157
|
/**
|
|
14
158
|
* Text content in a message
|
|
15
159
|
*/
|
|
@@ -76,8 +220,9 @@ export interface ChatMessage {
|
|
|
76
220
|
/**
|
|
77
221
|
* Chat options
|
|
78
222
|
*/
|
|
79
|
-
export interface ChatOptions {
|
|
80
|
-
|
|
223
|
+
export interface ChatOptions { /** Task ID for conversation continuity */
|
|
224
|
+
taskId?: string;
|
|
225
|
+
/** Stream response */
|
|
81
226
|
stream?: boolean;
|
|
82
227
|
|
|
83
228
|
/** Temperature (0-1) */
|
|
@@ -101,91 +246,111 @@ export interface ChatOptions {
|
|
|
101
246
|
* ```typescript
|
|
102
247
|
* const client = createClient({ baseURL: 'https://api.amaster.ai' });
|
|
103
248
|
*
|
|
104
|
-
* const
|
|
249
|
+
* const stream = client.copilot.chat([
|
|
105
250
|
* { role: 'user', content: 'Hello, how are you?' }
|
|
106
251
|
* ]);
|
|
107
252
|
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
253
|
+
* for await (const messages of stream) {
|
|
254
|
+
* // Process A2UI messages
|
|
110
255
|
* }
|
|
111
256
|
* ```
|
|
112
257
|
*
|
|
113
258
|
* @example
|
|
114
|
-
*
|
|
259
|
+
* With task ID for conversation continuity:
|
|
115
260
|
* ```typescript
|
|
116
|
-
*
|
|
261
|
+
* const stream = client.copilot.chat(
|
|
117
262
|
* [{ role: 'user', content: 'Tell me a story' }],
|
|
118
|
-
* {
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
263
|
+
* { taskId: 'conv-123' }
|
|
264
|
+
* );
|
|
265
|
+
*
|
|
266
|
+
* for await (const messages of stream) {
|
|
267
|
+
* for (const msg of messages) {
|
|
268
|
+
* if (msg.dataModelUpdate) {
|
|
269
|
+
* // Extract and display text content
|
|
125
270
|
* }
|
|
126
271
|
* }
|
|
127
|
-
*
|
|
272
|
+
* }
|
|
128
273
|
* ```
|
|
129
274
|
*
|
|
130
275
|
* @example
|
|
131
276
|
* Multi-turn conversation:
|
|
132
277
|
* ```typescript
|
|
133
278
|
* const conversation: ChatMessage[] = [
|
|
134
|
-
* { role: '
|
|
135
|
-
* { role: '
|
|
136
|
-
* { role: 'user', content: 'How do I define interfaces?' }
|
|
279
|
+
* { role: 'system', content: 'You are a helpful assistant' },
|
|
280
|
+
* { role: 'user', content: 'What is TypeScript?' }
|
|
137
281
|
* ];
|
|
138
282
|
*
|
|
139
|
-
* const
|
|
283
|
+
* for await (const messages of client.copilot.chat(conversation)) {
|
|
284
|
+
* // Process streaming response
|
|
285
|
+
* }
|
|
140
286
|
* ```
|
|
141
287
|
*/
|
|
142
288
|
export interface CopilotA2UIClient {
|
|
143
289
|
/**
|
|
144
|
-
*
|
|
290
|
+
* Start a streaming chat session with the AI assistant
|
|
145
291
|
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
292
|
+
* Returns an async generator that yields A2UI ServerToClientMessage arrays.
|
|
293
|
+
* Each yielded array contains UI updates that should be processed by an A2UI renderer.
|
|
294
|
+
*
|
|
295
|
+
* @param messages - Conversation messages (system, user, assistant)
|
|
296
|
+
* @param options - Chat options (taskId for conversation continuity)
|
|
297
|
+
* @returns AsyncGenerator yielding arrays of A2UI messages
|
|
149
298
|
*
|
|
150
299
|
* @example
|
|
151
|
-
* Simple
|
|
300
|
+
* Simple chat:
|
|
152
301
|
* ```typescript
|
|
153
|
-
* const
|
|
302
|
+
* const stream = client.copilot.chat([
|
|
154
303
|
* { role: 'user', content: 'What is the capital of France?' }
|
|
155
304
|
* ]);
|
|
156
305
|
*
|
|
157
|
-
*
|
|
306
|
+
* for await (const messages of stream) {
|
|
307
|
+
* // Process A2UI updates
|
|
308
|
+
* }
|
|
158
309
|
* ```
|
|
159
310
|
*
|
|
160
311
|
* @example
|
|
161
312
|
* With system prompt:
|
|
162
313
|
* ```typescript
|
|
163
|
-
* const
|
|
314
|
+
* const stream = client.copilot.chat([
|
|
164
315
|
* { role: 'system', content: 'You are a helpful coding assistant' },
|
|
165
316
|
* { role: 'user', content: 'How do I reverse a string in JavaScript?' }
|
|
166
317
|
* ]);
|
|
167
318
|
* ```
|
|
168
319
|
*
|
|
169
320
|
* @example
|
|
170
|
-
*
|
|
321
|
+
* Extracting text content from A2UI messages:
|
|
171
322
|
* ```typescript
|
|
172
|
-
* await
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* onComplete: (fullText) => {
|
|
181
|
-
* console.log('Complete response received');
|
|
323
|
+
* for await (const messages of stream) {
|
|
324
|
+
* for (const msg of messages) {
|
|
325
|
+
* if (msg.dataModelUpdate?.contents) {
|
|
326
|
+
* for (const content of msg.dataModelUpdate.contents) {
|
|
327
|
+
* if (content.valueString) {
|
|
328
|
+
* console.log(content.valueString); // Display text
|
|
329
|
+
* }
|
|
330
|
+
* }
|
|
182
331
|
* }
|
|
183
332
|
* }
|
|
184
|
-
*
|
|
333
|
+
* }
|
|
185
334
|
* ```
|
|
186
335
|
*/
|
|
187
|
-
|
|
336
|
+
chat(
|
|
188
337
|
messages: ChatMessage[],
|
|
189
338
|
options?: ChatOptions
|
|
190
|
-
):
|
|
339
|
+
): AsyncGenerator<ServerToClientMessage[], void, unknown>;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Cancel an ongoing chat session
|
|
343
|
+
*
|
|
344
|
+
* @param taskId - Task ID to cancel
|
|
345
|
+
* @returns Cancellation result
|
|
346
|
+
*/
|
|
347
|
+
cancelChat(taskId: string): Promise<ClientResult<unknown>>;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Get the status of a chat session
|
|
351
|
+
*
|
|
352
|
+
* @param taskId - Task ID to query
|
|
353
|
+
* @returns Task status information
|
|
354
|
+
*/
|
|
355
|
+
getChatStatus(taskId: string): Promise<ClientResult<unknown>>;
|
|
191
356
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -54,6 +54,10 @@ import type { AuthClientAPI } from './auth/index';
|
|
|
54
54
|
import type { EntityClientAPI } from './entity';
|
|
55
55
|
import type { BpmClientAPI } from './bpm';
|
|
56
56
|
import type { WorkflowClientAPI } from './workflow';
|
|
57
|
+
import type { ASRClient } from './asr';
|
|
58
|
+
import type { CopilotA2UIClient } from './copilot';
|
|
59
|
+
import type { FunctionClient } from './function';
|
|
60
|
+
import type { TTSClient } from './tts';
|
|
57
61
|
|
|
58
62
|
/**
|
|
59
63
|
* Configuration options for creating an Amaster client
|
|
@@ -335,6 +339,54 @@ export interface AmasterClient {
|
|
|
335
339
|
*/
|
|
336
340
|
workflow: WorkflowClientAPI;
|
|
337
341
|
|
|
342
|
+
/**
|
|
343
|
+
* ASR (Automatic Speech Recognition) module
|
|
344
|
+
*
|
|
345
|
+
* Provides methods for real-time speech-to-text conversion via WebSocket.
|
|
346
|
+
*
|
|
347
|
+
* For detailed documentation, see {@link ./asr.d.ts}
|
|
348
|
+
*/
|
|
349
|
+
asr: ASRClient;
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Copilot AI Assistant module
|
|
353
|
+
*
|
|
354
|
+
* Provides methods for interactive AI conversations with A2UI streaming.
|
|
355
|
+
*
|
|
356
|
+
* For detailed documentation, see {@link ./copilot.d.ts}
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* Chat with AI:
|
|
360
|
+
* ```typescript
|
|
361
|
+
* const stream = client.copilot.chat([
|
|
362
|
+
* { role: 'user', content: 'Hello' }
|
|
363
|
+
* ]);
|
|
364
|
+
*
|
|
365
|
+
* for await (const messages of stream) {
|
|
366
|
+
* // Process A2UI messages
|
|
367
|
+
* }
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
copilot: CopilotA2UIClient;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Serverless Function module
|
|
374
|
+
*
|
|
375
|
+
* Provides methods for invoking serverless functions.
|
|
376
|
+
*
|
|
377
|
+
* For detailed documentation, see {@link ./function.d.ts}
|
|
378
|
+
*/
|
|
379
|
+
function: FunctionClient;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* TTS (Text-to-Speech) module
|
|
383
|
+
*
|
|
384
|
+
* Provides methods for real-time text-to-speech conversion via WebSocket.
|
|
385
|
+
*
|
|
386
|
+
* For detailed documentation, see {@link ./tts.d.ts}
|
|
387
|
+
*/
|
|
388
|
+
tts: TTSClient;
|
|
389
|
+
|
|
338
390
|
/**
|
|
339
391
|
* Check if the user is currently authenticated
|
|
340
392
|
*
|
|
@@ -491,9 +543,14 @@ export type { AuthClientAPI } from './auth';
|
|
|
491
543
|
export type { EntityClientAPI } from './entity';
|
|
492
544
|
export type { BpmClientAPI } from './bpm';
|
|
493
545
|
export type { WorkflowClientAPI } from './workflow';
|
|
546
|
+
export type { ASRClient } from './asr';
|
|
547
|
+
export type { CopilotA2UIClient } from './copilot';
|
|
548
|
+
export type { FunctionClient } from './function';
|
|
549
|
+
export type { TTSClient } from './tts';
|
|
494
550
|
|
|
495
551
|
// For detailed types, import directly from submodules:
|
|
496
552
|
// import type { LoginParams, User } from '@amaster.ai/client/auth'
|
|
497
553
|
// import type { EntityQueryParams } from '@amaster.ai/client/entity'
|
|
498
554
|
// import type { Task, ProcessInstance } from '@amaster.ai/client/bpm'
|
|
499
555
|
// import type { WorkflowRunRequest } from '@amaster.ai/client/workflow'
|
|
556
|
+
// import type { ServerToClientMessage } from '@amaster.ai/client/copilot'
|
package/types/s3.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* S3 Storage Module - Type Definitions
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* This module provides operations for interacting with S3-compatible object storage.
|
|
7
|
+
*
|
|
8
|
+
* ## Key Features
|
|
9
|
+
* - File upload (multipart/form-data)
|
|
10
|
+
* - File download
|
|
11
|
+
* - Metadata retrieval
|
|
12
|
+
*
|
|
13
|
+
* @module s3
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { ClientResult } from './common';
|
|
17
|
+
|
|
18
|
+
// ==================== Response Types ====================
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Upload response data
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* {
|
|
26
|
+
* key: "uploads/2024/image.png",
|
|
27
|
+
* url: "https://cdn.example.com/uploads/2024/image.png"
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export interface UploadRes {
|
|
32
|
+
/** File key in storage */
|
|
33
|
+
key: string;
|
|
34
|
+
/** Full access URL */
|
|
35
|
+
url: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* File metadata
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* {
|
|
44
|
+
* contentType: "image/png",
|
|
45
|
+
* contentLength: 1024,
|
|
46
|
+
* lastModified: "2024-01-01T12:00:00Z"
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export interface S3Metadata {
|
|
51
|
+
contentType?: string;
|
|
52
|
+
contentLength?: number;
|
|
53
|
+
lastModified?: string;
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ==================== S3 Client API ====================
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* S3 Storage Client API
|
|
61
|
+
*
|
|
62
|
+
* Provides methods for uploading, downloading, and managing files in object storage.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const client = createClient();
|
|
67
|
+
*
|
|
68
|
+
* // 1. Upload file
|
|
69
|
+
* const uploadRes = await client.s3.upload(file);
|
|
70
|
+
* console.log(uploadRes.data.url);
|
|
71
|
+
*
|
|
72
|
+
* // 2. Get metadata
|
|
73
|
+
* const meta = await client.s3.getMetadata(uploadRes.data.key);
|
|
74
|
+
*
|
|
75
|
+
* // 3. Download file
|
|
76
|
+
* const blob = await client.s3.download(uploadRes.data.key);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export interface S3Client {
|
|
80
|
+
/**
|
|
81
|
+
* Download a file
|
|
82
|
+
*
|
|
83
|
+
* @param filename - The name/key of the file to download
|
|
84
|
+
* @returns Blob data of the file
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const result = await client.s3.download('uploads/image.png');
|
|
89
|
+
* if (result.data) {
|
|
90
|
+
* const url = URL.createObjectURL(result.data);
|
|
91
|
+
* window.open(url);
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
download(filename: string): Promise<ClientResult<Blob>>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Get metadata for a file
|
|
99
|
+
*
|
|
100
|
+
* @param key - The key of the file
|
|
101
|
+
* @returns File metadata
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const result = await client.s3.getMetadata('uploads/image.png');
|
|
106
|
+
* console.log('Size:', result.data.contentLength);
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
getMetadata(key: string): Promise<ClientResult<S3Metadata>>;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Upload a file
|
|
113
|
+
*
|
|
114
|
+
* @param file - The file to upload (File or Blob)
|
|
115
|
+
* @returns Upload result containing key and URL
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const file = event.target.files[0];
|
|
120
|
+
* const result = await client.s3.upload(file);
|
|
121
|
+
* if (result.data) {
|
|
122
|
+
* console.log('Uploaded to:', result.data.url);
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
upload(file: File | Blob): Promise<ClientResult<UploadRes>>;
|
|
127
|
+
}
|