@amaster.ai/client 1.1.0-beta.3 → 1.1.0-beta.30
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 +4 -7
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/package.json +15 -11
- package/types/auth/index.d.ts +107 -3
- package/types/auth/user.d.ts +7 -1
- package/types/copilot.d.ts +206 -41
- package/types/index.d.ts +57 -0
- package/types/s3.d.ts +127 -0
- package/types/auth/permissions.d.ts +0 -254
package/README.md
CHANGED
|
@@ -487,13 +487,10 @@ const result = await client.copilot.sendMessage([
|
|
|
487
487
|
console.log(result.data.content);
|
|
488
488
|
|
|
489
489
|
// Streaming response
|
|
490
|
-
await client.copilot.sendMessage(
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
onChunk: (chunk) => console.log(chunk),
|
|
495
|
-
}
|
|
496
|
-
);
|
|
490
|
+
await client.copilot.sendMessage([{ role: "user", content: "Tell me a story" }], {
|
|
491
|
+
stream: true,
|
|
492
|
+
onChunk: (chunk) => console.log(chunk),
|
|
493
|
+
});
|
|
497
494
|
```
|
|
498
495
|
|
|
499
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
|
|
@@ -48,7 +49,8 @@ function createClient(options) {
|
|
|
48
49
|
const bpm = bpmClient.createBpmClient(authenticatedHttpClient);
|
|
49
50
|
const workflow = workflowClient.createWorkflowClient(authenticatedHttpClient);
|
|
50
51
|
const functionClient$1 = functionClient.createFunctionClient(authenticatedHttpClient);
|
|
51
|
-
const copilot = copilotClient.createCopilotA2UIClient(authenticatedHttpClient);
|
|
52
|
+
const copilot = copilotClient.createCopilotA2UIClient(authenticatedHttpClient, baseURL);
|
|
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,qCAAA,CAAwB,uBAAA,EAAyB,OAAO,CAAA;AAC3F,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, baseURL);\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
|
/**
|
|
@@ -193,6 +195,19 @@ interface AmasterClient {
|
|
|
193
195
|
* ```
|
|
194
196
|
*/
|
|
195
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;
|
|
196
211
|
/**
|
|
197
212
|
* Check if the user is currently authenticated
|
|
198
213
|
*/
|
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
|
/**
|
|
@@ -193,6 +195,19 @@ interface AmasterClient {
|
|
|
193
195
|
* ```
|
|
194
196
|
*/
|
|
195
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;
|
|
196
211
|
/**
|
|
197
212
|
* Check if the user is currently authenticated
|
|
198
213
|
*/
|
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
|
|
@@ -46,7 +47,8 @@ function createClient(options) {
|
|
|
46
47
|
const bpm = createBpmClient(authenticatedHttpClient);
|
|
47
48
|
const workflow = createWorkflowClient(authenticatedHttpClient);
|
|
48
49
|
const functionClient = createFunctionClient(authenticatedHttpClient);
|
|
49
|
-
const copilot = createCopilotA2UIClient(authenticatedHttpClient);
|
|
50
|
+
const copilot = createCopilotA2UIClient(authenticatedHttpClient, baseURL);
|
|
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,uBAAA,CAAwB,uBAAA,EAAyB,OAAO,CAAA;AAC3F,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, baseURL);\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.30",
|
|
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/
|
|
75
|
+
"@amaster.ai/asr-client": "1.1.0-beta.30",
|
|
76
|
+
"@amaster.ai/asr-http-client": "1.1.0-beta.30",
|
|
77
|
+
"@amaster.ai/copilot-client": "1.1.0-beta.30",
|
|
78
|
+
"@amaster.ai/function-client": "1.1.0-beta.30",
|
|
79
|
+
"@amaster.ai/http-client": "1.1.0-beta.30",
|
|
80
|
+
"@amaster.ai/auth-client": "1.1.0-beta.30",
|
|
81
|
+
"@amaster.ai/entity-client": "1.1.0-beta.30",
|
|
82
|
+
"@amaster.ai/s3-client": "1.1.0-beta.30",
|
|
83
|
+
"@amaster.ai/bpm-client": "1.1.0-beta.30",
|
|
84
|
+
"@amaster.ai/tts-client": "1.1.0-beta.30",
|
|
85
|
+
"@amaster.ai/workflow-client": "1.1.0-beta.30"
|
|
82
86
|
},
|
|
83
87
|
"peerDependencies": {
|
|
84
88
|
"axios": "^1.11.0"
|
package/types/auth/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
* - `@amaster.ai/client/auth/password-auth` - Password login/register
|
|
11
11
|
* - `@amaster.ai/client/auth/code-auth` - Verification code login
|
|
12
12
|
* - `@amaster.ai/client/auth/oauth` - OAuth & social login
|
|
13
|
-
* - `@amaster.ai/client/auth/permissions` - Permission checking helpers
|
|
14
13
|
* - `@amaster.ai/client/auth/profile` - User profile management
|
|
15
14
|
*
|
|
16
15
|
* @example
|
|
@@ -23,7 +22,6 @@
|
|
|
23
22
|
* Import specific types (recommended for AI):
|
|
24
23
|
* ```typescript
|
|
25
24
|
* import type { LoginParams, User } from '@amaster.ai/client/auth/password-auth';
|
|
26
|
-
* import type { hasPermission } from '@amaster.ai/client/auth/permissions';
|
|
27
25
|
* import type { OAuthProvider } from '@amaster.ai/client/auth/oauth';
|
|
28
26
|
* ```
|
|
29
27
|
*
|
|
@@ -37,7 +35,6 @@ export * from './user';
|
|
|
37
35
|
export * from './password-auth';
|
|
38
36
|
export * from './code-auth';
|
|
39
37
|
export * from './oauth';
|
|
40
|
-
export * from './permissions';
|
|
41
38
|
export * from './profile';
|
|
42
39
|
|
|
43
40
|
// Import for unified API
|
|
@@ -177,4 +174,111 @@ export interface AuthClientAPI
|
|
|
177
174
|
* ```
|
|
178
175
|
*/
|
|
179
176
|
refreshToken(): Promise<ClientResult<RefreshTokenResponse>>;
|
|
177
|
+
|
|
178
|
+
// ==================== Permission Checks ====================
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Check if current user has a specific role (local check, fast)
|
|
182
|
+
*
|
|
183
|
+
* Works for both authenticated and anonymous users.
|
|
184
|
+
* Checks against locally cached user roles.
|
|
185
|
+
*
|
|
186
|
+
* @param roleCode - Role code to check (e.g., "admin", "user", "anonymous")
|
|
187
|
+
* @returns True if user has the role
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* Check admin role:
|
|
191
|
+
* ```typescript
|
|
192
|
+
* if (client.auth.hasRole('admin')) {
|
|
193
|
+
* showAdminPanel();
|
|
194
|
+
* }
|
|
195
|
+
* ```
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* Check anonymous user:
|
|
199
|
+
* ```typescript
|
|
200
|
+
* if (client.auth.hasRole('anonymous')) {
|
|
201
|
+
* showLoginPrompt();
|
|
202
|
+
* }
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
hasRole(roleCode: string): boolean;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Check if current user has a specific permission (local check, fast)
|
|
209
|
+
*
|
|
210
|
+
* Works for both authenticated and anonymous users.
|
|
211
|
+
* Checks against locally cached user permissions.
|
|
212
|
+
*
|
|
213
|
+
* @param resource - Resource name (e.g., "user", "order")
|
|
214
|
+
* @param action - Action name (e.g., "read", "write", "delete")
|
|
215
|
+
* @returns True if user has the permission
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* Check permission for authenticated users:
|
|
219
|
+
* ```typescript
|
|
220
|
+
* if (client.auth.hasPermission('user', 'delete')) {
|
|
221
|
+
* showDeleteButton();
|
|
222
|
+
* }
|
|
223
|
+
* ```
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* Check permission for anonymous users:
|
|
227
|
+
* ```typescript
|
|
228
|
+
* // If backend configured anonymous role with article:read permission
|
|
229
|
+
* if (client.auth.hasPermission('article', 'read')) {
|
|
230
|
+
* showArticleList();
|
|
231
|
+
* }
|
|
232
|
+
* ```
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* Control UI elements:
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const canEdit = client.auth.hasPermission('post', 'write');
|
|
238
|
+
* const canDelete = client.auth.hasPermission('post', 'delete');
|
|
239
|
+
*
|
|
240
|
+
* return (
|
|
241
|
+
* <div>
|
|
242
|
+
* {canEdit && <button>Edit</button>}
|
|
243
|
+
* {canDelete && <button>Delete</button>}
|
|
244
|
+
* </div>
|
|
245
|
+
* );
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
hasPermission(resource: string, action: string): boolean;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Check if current user is anonymous (not authenticated)
|
|
252
|
+
*
|
|
253
|
+
* Convenience method equivalent to `hasRole('anonymous')`.
|
|
254
|
+
* Returns true if user has the 'anonymous' role.
|
|
255
|
+
*
|
|
256
|
+
* @returns True if user is anonymous
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* Show login prompt for anonymous users:
|
|
260
|
+
* ```typescript
|
|
261
|
+
* if (client.auth.isAnonymous()) {
|
|
262
|
+
* showLoginButton();
|
|
263
|
+
* showLimitedFeatures();
|
|
264
|
+
* } else {
|
|
265
|
+
* showFullFeatures();
|
|
266
|
+
* }
|
|
267
|
+
* ```
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* Conditional rendering:
|
|
271
|
+
* ```typescript
|
|
272
|
+
* return (
|
|
273
|
+
* <div>
|
|
274
|
+
* {client.auth.isAnonymous() ? (
|
|
275
|
+
* <button onClick={handleLogin}>Login to continue</button>
|
|
276
|
+
* ) : (
|
|
277
|
+
* <UserDashboard />
|
|
278
|
+
* )}
|
|
279
|
+
* </div>
|
|
280
|
+
* );
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
isAnonymous(): boolean;
|
|
180
284
|
}
|
package/types/auth/user.d.ts
CHANGED
|
@@ -77,8 +77,14 @@ export interface User {
|
|
|
77
77
|
phoneVerifiedAt: string | null;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
* Role codes assigned to user
|
|
80
|
+
* Role codes assigned to user
|
|
81
|
+
*
|
|
82
|
+
* Includes system roles and custom roles:
|
|
83
|
+
* - System roles: "anonymous" (unauthenticated), "member" (default), "admin"
|
|
84
|
+
* - Custom roles: defined in app.settings.yml
|
|
85
|
+
*
|
|
81
86
|
* @example ["admin", "user", "manager"]
|
|
87
|
+
* @example ["anonymous"] // For unauthenticated users
|
|
82
88
|
*/
|
|
83
89
|
roles: string[];
|
|
84
90
|
|
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
|
+
}
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ============================================================================
|
|
3
|
-
* Permission Checking - Type Definitions & Helpers
|
|
4
|
-
* ============================================================================
|
|
5
|
-
*
|
|
6
|
-
* Permission and role checking utilities:
|
|
7
|
-
* - Type-safe permission checking
|
|
8
|
-
* - Role validation
|
|
9
|
-
* - Permission helpers
|
|
10
|
-
*
|
|
11
|
-
* @module auth/permissions
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import type { User } from './user';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Permission check result
|
|
18
|
-
*/
|
|
19
|
-
export interface PermissionCheckResult {
|
|
20
|
-
/** Whether the permission check passed */
|
|
21
|
-
granted: boolean;
|
|
22
|
-
|
|
23
|
-
/** Optional reason if denied */
|
|
24
|
-
reason?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Permission checking helpers
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* Check single permission:
|
|
32
|
-
* ```typescript
|
|
33
|
-
* import { hasPermission } from '@amaster.ai/client/auth/permissions';
|
|
34
|
-
*
|
|
35
|
-
* const user = await client.auth.getMe().then(r => r.data);
|
|
36
|
-
*
|
|
37
|
-
* if (hasPermission(user, 'user:delete')) {
|
|
38
|
-
* showDeleteButton();
|
|
39
|
-
* }
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* Check role:
|
|
44
|
-
* ```typescript
|
|
45
|
-
* import { hasRole } from '@amaster.ai/client/auth/permissions';
|
|
46
|
-
*
|
|
47
|
-
* if (hasRole(user, 'admin')) {
|
|
48
|
-
* showAdminPanel();
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* Check any of multiple permissions:
|
|
54
|
-
* ```typescript
|
|
55
|
-
* import { hasAnyPermission } from '@amaster.ai/client/auth/permissions';
|
|
56
|
-
*
|
|
57
|
-
* if (hasAnyPermission(user, ['user:read', 'user:write', 'user:delete'])) {
|
|
58
|
-
* showUserManagement();
|
|
59
|
-
* }
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export namespace PermissionHelpers {
|
|
63
|
-
/**
|
|
64
|
-
* Check if user has a specific permission
|
|
65
|
-
*
|
|
66
|
-
* @param user - User object with permissions
|
|
67
|
-
* @param permission - Permission to check (format: "resource:action")
|
|
68
|
-
* @returns True if user has the permission
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const canDelete = hasPermission(user, 'user:delete');
|
|
73
|
-
* const canRead = hasPermission(user, 'order:read');
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
export function hasPermission(user: User | null | undefined, permission: string): boolean;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Check if user has a specific role
|
|
80
|
-
*
|
|
81
|
-
* @param user - User object with roles
|
|
82
|
-
* @param role - Role code to check
|
|
83
|
-
* @returns True if user has the role
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```typescript
|
|
87
|
-
* const isAdmin = hasRole(user, 'admin');
|
|
88
|
-
* const isManager = hasRole(user, 'manager');
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
export function hasRole(user: User | null | undefined, role: string): boolean;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Check if user has ANY of the specified permissions
|
|
95
|
-
*
|
|
96
|
-
* @param user - User object with permissions
|
|
97
|
-
* @param permissions - Array of permissions to check
|
|
98
|
-
* @returns True if user has at least one permission
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* // User can access if they have ANY of these permissions
|
|
103
|
-
* const canAccessUsers = hasAnyPermission(user, [
|
|
104
|
-
* 'user:read',
|
|
105
|
-
* 'user:write',
|
|
106
|
-
* 'user:delete'
|
|
107
|
-
* ]);
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
export function hasAnyPermission(user: User | null | undefined, permissions: string[]): boolean;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Check if user has ALL of the specified permissions
|
|
114
|
-
*
|
|
115
|
-
* @param user - User object with permissions
|
|
116
|
-
* @param permissions - Array of permissions to check
|
|
117
|
-
* @returns True if user has all permissions
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* // User needs ALL of these permissions
|
|
122
|
-
* const canManageUsers = hasAllPermissions(user, [
|
|
123
|
-
* 'user:read',
|
|
124
|
-
* 'user:write',
|
|
125
|
-
* 'user:delete'
|
|
126
|
-
* ]);
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
export function hasAllPermissions(user: User | null | undefined, permissions: string[]): boolean;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Check if user has ANY of the specified roles
|
|
133
|
-
*
|
|
134
|
-
* @param user - User object with roles
|
|
135
|
-
* @param roles - Array of role codes to check
|
|
136
|
-
* @returns True if user has at least one role
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ```typescript
|
|
140
|
-
* const isStaff = hasAnyRole(user, ['admin', 'moderator', 'support']);
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
export function hasAnyRole(user: User | null | undefined, roles: string[]): boolean;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Check if user has ALL of the specified roles
|
|
147
|
-
*
|
|
148
|
-
* @param user - User object with roles
|
|
149
|
-
* @param roles - Array of role codes to check
|
|
150
|
-
* @returns True if user has all roles
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```typescript
|
|
154
|
-
* const isSuperAdmin = hasAllRoles(user, ['admin', 'superuser']);
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
export function hasAllRoles(user: User | null | undefined, roles: string[]): boolean;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Re-export helpers as individual functions for convenience
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```typescript
|
|
165
|
-
* import { hasPermission, hasRole } from '@amaster.ai/client/auth/permissions';
|
|
166
|
-
*
|
|
167
|
-
* const canDelete = hasPermission(user, 'user:delete');
|
|
168
|
-
* const isAdmin = hasRole(user, 'admin');
|
|
169
|
-
* ```
|
|
170
|
-
*/
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Check if user has a specific permission
|
|
174
|
-
*
|
|
175
|
-
* @param user - User object with permissions
|
|
176
|
-
* @param permission - Permission to check (format: "resource:action")
|
|
177
|
-
* @returns True if user has the permission
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```typescript
|
|
181
|
-
* const canDelete = hasPermission(user, 'user:delete');
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
export declare function hasPermission(user: User | null | undefined, permission: string): boolean;
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Check if user has a specific role
|
|
188
|
-
*
|
|
189
|
-
* @param user - User object with roles
|
|
190
|
-
* @param role - Role code to check
|
|
191
|
-
* @returns True if user has the role
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* ```typescript
|
|
195
|
-
* const isAdmin = hasRole(user, 'admin');
|
|
196
|
-
* ```
|
|
197
|
-
*/
|
|
198
|
-
export declare function hasRole(user: User | null | undefined, role: string): boolean;
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Check if user has ANY of the specified permissions
|
|
202
|
-
*
|
|
203
|
-
* @param user - User object with permissions
|
|
204
|
-
* @param permissions - Array of permissions to check
|
|
205
|
-
* @returns True if user has at least one permission
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* ```typescript
|
|
209
|
-
* const canAccessUsers = hasAnyPermission(user, ['user:read', 'user:write']);
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
export declare function hasAnyPermission(user: User | null | undefined, permissions: string[]): boolean;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Check if user has ALL of the specified permissions
|
|
216
|
-
*
|
|
217
|
-
* @param user - User object with permissions
|
|
218
|
-
* @param permissions - Array of permissions to check
|
|
219
|
-
* @returns True if user has all permissions
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* ```typescript
|
|
223
|
-
* const canManageUsers = hasAllPermissions(user, ['user:read', 'user:write', 'user:delete']);
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
export declare function hasAllPermissions(user: User | null | undefined, permissions: string[]): boolean;
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Check if user has ANY of the specified roles
|
|
230
|
-
*
|
|
231
|
-
* @param user - User object with roles
|
|
232
|
-
* @param roles - Array of role codes to check
|
|
233
|
-
* @returns True if user has at least one role
|
|
234
|
-
*
|
|
235
|
-
* @example
|
|
236
|
-
* ```typescript
|
|
237
|
-
* const isStaff = hasAnyRole(user, ['admin', 'moderator']);
|
|
238
|
-
* ```
|
|
239
|
-
*/
|
|
240
|
-
export declare function hasAnyRole(user: User | null | undefined, roles: string[]): boolean;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Check if user has ALL of the specified roles
|
|
244
|
-
*
|
|
245
|
-
* @param user - User object with roles
|
|
246
|
-
* @param roles - Array of role codes to check
|
|
247
|
-
* @returns True if user has all roles
|
|
248
|
-
*
|
|
249
|
-
* @example
|
|
250
|
-
* ```typescript
|
|
251
|
-
* const isSuperAdmin = hasAllRoles(user, ['admin', 'superuser']);
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
export declare function hasAllRoles(user: User | null | undefined, roles: string[]): boolean;
|