@amaster.ai/client 1.0.0-alpha.1

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.
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Error information structure
3
+ *
4
+ * @since 1.1.0
5
+ */
6
+ export interface ClientError {
7
+ /**
8
+ * HTTP status code
9
+ */
10
+ status: number;
11
+
12
+ /**
13
+ * Error message
14
+ */
15
+ message: string;
16
+
17
+ /**
18
+ * Application-specific error code (e.g., 'INVALID_TOKEN', 'PERMISSION_DENIED')
19
+ *
20
+ * @since 1.1.0
21
+ */
22
+ code?: string;
23
+
24
+ /**
25
+ * Additional error details (optional)
26
+ */
27
+ details?: unknown;
28
+
29
+ /**
30
+ * Error timestamp (ISO 8601 format)
31
+ *
32
+ * @since 1.1.0
33
+ */
34
+ timestamp?: string;
35
+ }
36
+
37
+ /**
38
+ * Standard API response wrapper
39
+ *
40
+ * All Amaster API methods return results wrapped in this structure for
41
+ * consistent error handling and type safety.
42
+ *
43
+ * @template T - The type of the successful response data
44
+ *
45
+ * @example
46
+ * // Success case
47
+ * const result = await client.entity.list('default', 'users');
48
+ * if (result.success) {
49
+ * console.log('Data:', result.data);
50
+ * }
51
+ *
52
+ * @example
53
+ * // Error case
54
+ * const result = await client.auth.login({ email, password });
55
+ * if (!result.success) {
56
+ * console.error('Error:', result.error.message);
57
+ * console.error('Code:', result.error.code);
58
+ * }
59
+ *
60
+ * @since 1.0.0
61
+ */
62
+ export interface ClientResult<T> {
63
+ /**
64
+ * Response data (null if error occurred)
65
+ */
66
+ data: T | null;
67
+
68
+ /**
69
+ * Error information (null if successful)
70
+ */
71
+ error: ClientError | null;
72
+
73
+ /**
74
+ * HTTP response status code
75
+ */
76
+ status: number;
77
+
78
+ /**
79
+ * Convenience flag for checking if request was successful
80
+ *
81
+ * Equivalent to `error === null`
82
+ *
83
+ * @since 1.1.0
84
+ */
85
+ success: boolean;
86
+ }
87
+
88
+ /**
89
+ * HTTP request methods
90
+ */
91
+ export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
92
+
93
+ /**
94
+ * Pagination parameters for list queries
95
+ */
96
+ export interface PaginationParams {
97
+ /**
98
+ * Page number (1-based)
99
+ * @default 1
100
+ */
101
+ page?: number;
102
+
103
+ /**
104
+ * Number of items per page
105
+ * @default 20
106
+ */
107
+ perPage?: number;
108
+ }
109
+
110
+ /**
111
+ * Paginated response structure
112
+ *
113
+ * @template T - The type of items in the list
114
+ */
115
+ export interface PaginatedResult<T> {
116
+ /**
117
+ * Array of items for current page
118
+ */
119
+ items: T[];
120
+
121
+ /**
122
+ * Total number of items across all pages
123
+ */
124
+ total: number;
125
+
126
+ /**
127
+ * Current page number (1-based)
128
+ */
129
+ page: number;
130
+
131
+ /**
132
+ * Number of items per page
133
+ */
134
+ perPage: number;
135
+
136
+ /**
137
+ * Total number of pages
138
+ */
139
+ totalPages?: number;
140
+ }
@@ -0,0 +1,49 @@
1
+ import type { SendStreamingMessageResponse, CancelTaskResponse, GetTaskResponse } from '@a2a-js/sdk';
2
+ import type { ClientResult } from './common';
3
+
4
+ interface TextContent {
5
+ type: "text";
6
+ text: string;
7
+ }
8
+ interface ImageContent {
9
+ type: "image";
10
+ data?: string;
11
+ url?: string;
12
+ mimeType?: string;
13
+ }
14
+ interface FileContent {
15
+ type: "file";
16
+ data?: string;
17
+ url?: string;
18
+ mimeType?: string;
19
+ name?: string;
20
+ }
21
+ type MessageContent = TextContent | ImageContent | FileContent;
22
+ interface ChatMessage {
23
+ role: "system" | "user" | "assistant";
24
+ content: string | MessageContent[];
25
+ }
26
+ interface ChatOptions {
27
+ taskId?: string;
28
+ }
29
+ type CopilotClientAPI = {
30
+ /**
31
+ * Stream messages from Copilot Agent.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { createCopilotClient, Data } from "@amaster.ai/copilot-client";
36
+ *
37
+ * const client = createCopilotClient();
38
+ *
39
+ * for await (const response of client.chat([{ role: "user", content: "Hello" }])) {
40
+ * // deal response
41
+ * }
42
+ * ```
43
+ */
44
+ chat(messages: ChatMessage[], options?: ChatOptions): AsyncGenerator<SendStreamingMessageResponse, void, unknown>;
45
+ cancelChat(taskId: string): Promise<ClientResult<CancelTaskResponse>>;
46
+ getChatStatus(taskId: string): Promise<ClientResult<GetTaskResponse>>;
47
+ };
48
+
49
+ export { type ChatMessage, type ChatOptions, type CopilotClientAPI, type FileContent, type ImageContent, type MessageContent, type TextContent };
@@ -0,0 +1,433 @@
1
+ /**
2
+ *
3
+ * @module entity
4
+ */
5
+
6
+ import type { ClientResult } from './common';
7
+
8
+ // ==================== Filter Types ====================
9
+
10
+ /**
11
+ * Simple filter operators for query string format
12
+ *
13
+ * Usage: `{ 'field[op]': value }`
14
+ *
15
+ */
16
+ export type FilterOperator =
17
+ | 'eq' // Equal (default if no operator specified)
18
+ | 'ne' // Not equal
19
+ | 'gt' // Greater than
20
+ | 'ge' // Greater or equal
21
+ | 'lt' // Less than
22
+ | 'le' // Less or equal
23
+ | 'like' // Fuzzy match (auto wraps with %)
24
+ | 'sw' // Starts with
25
+ | 'ew' // Ends with
26
+ | 'bt' // Between (requires {from, to})
27
+ | 'in'; // In array
28
+
29
+ /**
30
+ * Advanced filter operators for condition builder
31
+ *
32
+ */
33
+ export type AdvancedFilterOperator =
34
+ | 'equal'
35
+ | 'not_equal'
36
+ | 'less'
37
+ | 'less_or_equal'
38
+ | 'greater'
39
+ | 'greater_or_equal'
40
+ | 'like'
41
+ | 'not_like'
42
+ | 'starts_with'
43
+ | 'ends_with'
44
+ | 'between'
45
+ | 'is_empty'
46
+ | 'is_not_empty'
47
+ | 'select_any_in'
48
+ | 'select_not_any_in';
49
+
50
+ /**
51
+ * Advanced filter item (single condition)
52
+ *
53
+ */
54
+ export interface FilterItem {
55
+ op: AdvancedFilterOperator;
56
+ left: {
57
+ /** Field name, supports dot notation for relations (e.g., 'user.email') */
58
+ field: string;
59
+ };
60
+ right?: string | number | boolean | Date | null | string[] | number[];
61
+ }
62
+
63
+ /**
64
+ * Advanced filter group (supports AND/OR with nesting)
65
+ *
66
+ */
67
+ export interface FilterGroup {
68
+ conjunction: 'and' | 'or';
69
+ children: Array<FilterGroup | FilterItem>;
70
+ }
71
+
72
+ /**
73
+ * Keywords search configuration
74
+ *
75
+ */
76
+ export interface KeywordsSearch {
77
+ /** Fields to search in */
78
+ fields: string[];
79
+ /** Search value */
80
+ value: string;
81
+ }
82
+
83
+ /**
84
+ * Between filter value
85
+ *
86
+ */
87
+ export interface BetweenValue {
88
+ from?: string | number | Date;
89
+ to?: string | number | Date;
90
+ }
91
+
92
+ // ==================== Query Parameters ====================
93
+
94
+ /**
95
+ * Entity query parameters
96
+ *
97
+ * Supports pagination, sorting, filtering, searching, and relation loading.
98
+ *
99
+ */
100
+ export interface EntityQueryParams {
101
+ // ==================== Pagination ====================
102
+
103
+ /**
104
+ * Page number (1-based)
105
+ * @default 1
106
+ */
107
+ page?: number;
108
+
109
+ /**
110
+ * Items per page
111
+ * @default 20
112
+ */
113
+ perPage?: number;
114
+
115
+ /**
116
+ * Maximum items to return (alternative to perPage)
117
+ */
118
+ limit?: number;
119
+
120
+ /**
121
+ * Number of items to skip (alternative to page)
122
+ */
123
+ offset?: number;
124
+
125
+ // ==================== Sorting ====================
126
+
127
+ /**
128
+ * Field to sort by
129
+ */
130
+ orderBy?: string;
131
+
132
+ /**
133
+ * Sort direction
134
+ * @default 'asc'
135
+ */
136
+ orderDir?: 'asc' | 'desc';
137
+
138
+ /**
139
+ * Multiple sort orders (comma-separated)
140
+ * Format: "field1:asc,field2:desc"
141
+ */
142
+ __orders?: string;
143
+
144
+ // ==================== Search ====================
145
+
146
+ /**
147
+ * Keywords search
148
+ * - String: search all searchable fields (backend determines)
149
+ * - Object: search specific fields
150
+ *
151
+ */
152
+ __keywords?: string | KeywordsSearch;
153
+
154
+ // ==================== Relations & Fields ====================
155
+
156
+ /**
157
+ * Relations to load (eager loading)
158
+ */
159
+ __relations?: string[];
160
+
161
+ /**
162
+ * Fields to select (only return these fields)
163
+ */
164
+ __fields?: string[];
165
+
166
+ // ==================== Filters ====================
167
+
168
+ /**
169
+ * Advanced filter (condition builder with AND/OR)
170
+ */
171
+ __filter?: FilterGroup;
172
+
173
+ /**
174
+ * Simple filters using field=value or field[op]=value
175
+ */
176
+ [key: string]: unknown;
177
+ }
178
+
179
+ // ==================== Response Types ====================
180
+
181
+ /**
182
+ * Entity list response
183
+ *
184
+ * @template T - The entity type
185
+ *
186
+ */
187
+ export interface EntityListResponse<T = Record<string, unknown>> {
188
+ /** Array of entities */
189
+ items: T[];
190
+ /** Total count of entities (for pagination) */
191
+ total: number;
192
+ /** Current page number */
193
+ page?: number;
194
+ /** Items per page */
195
+ perPage?: number;
196
+ }
197
+
198
+ // ==================== Entity Client API ====================
199
+
200
+ /**
201
+ * Entity CRUD Operations Client API
202
+ *
203
+ * Provides methods for creating, reading, updating, and deleting entities.
204
+ *
205
+ * @since 1.0.0
206
+ */
207
+ export interface EntityClientAPI {
208
+ /**
209
+ * List entities with pagination, filtering, and sorting
210
+ *
211
+ * @template T - The entity type
212
+ * @param source - Data source name (e.g., 'default', 'app-123')
213
+ * @param entity - Entity name (table name)
214
+ * @param params - Query parameters
215
+ * @returns List of entities with pagination info
216
+ *
217
+ * @example
218
+ * // Basic usage
219
+ * const result = await client.entity.list('default', 'users');
220
+ * console.log('Users:', result.data.items);
221
+ *
222
+ * @example
223
+ * // With pagination
224
+ * const result = await client.entity.list('default', 'users', {
225
+ * page: 1,
226
+ * perPage: 20
227
+ * });
228
+ *
229
+ * @example
230
+ * // With filters and sorting
231
+ * const result = await client.entity.list('default', 'users', {
232
+ * page: 1,
233
+ * perPage: 20,
234
+ * orderBy: 'createdAt',
235
+ * orderDir: 'desc',
236
+ * 'status[eq]': 'active',
237
+ * 'age[gt]': 18
238
+ * });
239
+ *
240
+ * @example
241
+ * // With type safety
242
+ * type User = { id: number; name: string; email: string };
243
+ * const result = await client.entity.list<User>('default', 'users');
244
+ * if (result.success) {
245
+ * result.data.items.forEach(user => {
246
+ * console.log(user.name); // Type-safe
247
+ * });
248
+ * }
249
+ *
250
+ * @since 1.0.0
251
+ */
252
+ list<T = Record<string, unknown>>(
253
+ source: string,
254
+ entity: string,
255
+ params?: EntityQueryParams
256
+ ): Promise<ClientResult<EntityListResponse<T>>>;
257
+
258
+ /**
259
+ * Get a single entity by ID
260
+ *
261
+ * @template T - The entity type
262
+ * @param source - Data source name
263
+ * @param entity - Entity name
264
+ * @param id - Entity ID
265
+ * @returns The entity data
266
+ *
267
+ * @example
268
+ * const result = await client.entity.get('default', 'users', 123);
269
+ * if (result.success) {
270
+ * console.log('User:', result.data);
271
+ * }
272
+ *
273
+ * @example
274
+ * // With type safety
275
+ * type User = { id: number; name: string };
276
+ * const result = await client.entity.get<User>('default', 'users', 123);
277
+ *
278
+ * @since 1.0.0
279
+ */
280
+ get<T = Record<string, unknown>>(
281
+ source: string,
282
+ entity: string,
283
+ id: string | number
284
+ ): Promise<ClientResult<T>>;
285
+
286
+ /**
287
+ * Create a new entity
288
+ *
289
+ * @template T - The entity type
290
+ * @param source - Data source name
291
+ * @param entity - Entity name
292
+ * @param data - Entity data to create
293
+ * @returns The created entity
294
+ *
295
+ * @example
296
+ * const result = await client.entity.create('default', 'users', {
297
+ * name: 'John Doe',
298
+ * email: 'john@example.com',
299
+ * status: 'active'
300
+ * });
301
+ *
302
+ * if (result.success) {
303
+ * console.log('Created user with ID:', result.data.id);
304
+ * }
305
+ *
306
+ * @since 1.0.0
307
+ */
308
+ create<T = Record<string, unknown>>(
309
+ source: string,
310
+ entity: string,
311
+ data: Record<string, unknown>
312
+ ): Promise<ClientResult<T>>;
313
+
314
+ /**
315
+ * Update an existing entity
316
+ *
317
+ * @template T - The entity type
318
+ * @param source - Data source name
319
+ * @param entity - Entity name
320
+ * @param id - Entity ID to update
321
+ * @param data - Fields to update
322
+ * @returns The updated entity
323
+ *
324
+ * @example
325
+ * const result = await client.entity.update('default', 'users', 123, {
326
+ * name: 'Jane Doe',
327
+ * status: 'inactive'
328
+ * });
329
+ *
330
+ * if (result.success) {
331
+ * console.log('Updated:', result.data);
332
+ * }
333
+ *
334
+ * @since 1.0.0
335
+ */
336
+ update<T = Record<string, unknown>>(
337
+ source: string,
338
+ entity: string,
339
+ id: string | number,
340
+ data: Record<string, unknown>
341
+ ): Promise<ClientResult<T>>;
342
+
343
+ /**
344
+ * Delete an entity by ID
345
+ *
346
+ * @param source - Data source name
347
+ * @param entity - Entity name
348
+ * @param id - Entity ID to delete
349
+ * @returns null on success
350
+ *
351
+ * @example
352
+ * const result = await client.entity.delete('default', 'users', 123);
353
+ * if (result.success) {
354
+ * console.log('User deleted');
355
+ * }
356
+ *
357
+ * @since 1.0.0
358
+ */
359
+ delete(
360
+ source: string,
361
+ entity: string,
362
+ id: string | number
363
+ ): Promise<ClientResult<null>>;
364
+
365
+ /**
366
+ * Get options for select/dropdown fields
367
+ *
368
+ * @template T - The option type
369
+ * @param source - Data source name
370
+ * @param entity - Entity name
371
+ * @param fields - Fields to include in options
372
+ * @returns Array of option objects
373
+ *
374
+ * @example
375
+ * const result = await client.entity.options('default', 'users', ['id', 'name']);
376
+ * if (result.success) {
377
+ * result.data.forEach(opt => console.log(opt.name));
378
+ * }
379
+ *
380
+ * @since 1.0.0
381
+ */
382
+ options<T = Record<string, unknown>>(
383
+ source: string,
384
+ entity: string,
385
+ fields?: string[]
386
+ ): Promise<ClientResult<T[]>>;
387
+
388
+ /**
389
+ * Bulk update multiple entities
390
+ *
391
+ * @template T - The response type
392
+ * @param source - Data source name
393
+ * @param entity - Entity name
394
+ * @param items - Array of entities to update (each must have an id)
395
+ * @returns Update result
396
+ *
397
+ * @example
398
+ * const result = await client.entity.bulkUpdate('default', 'users', [
399
+ * { id: 1, status: 'active' },
400
+ * { id: 2, status: 'inactive' },
401
+ * { id: 3, status: 'active' }
402
+ * ]);
403
+ *
404
+ * @since 1.0.0
405
+ */
406
+ bulkUpdate<T = Record<string, unknown>>(
407
+ source: string,
408
+ entity: string,
409
+ items: Array<Record<string, unknown> & { id: string | number }>
410
+ ): Promise<ClientResult<T>>;
411
+
412
+ /**
413
+ * Bulk delete multiple entities
414
+ *
415
+ * @param source - Data source name
416
+ * @param entity - Entity name
417
+ * @param ids - Array of entity IDs to delete
418
+ * @returns null on success
419
+ *
420
+ * @example
421
+ * const result = await client.entity.bulkDelete('default', 'users', [1, 2, 3]);
422
+ * if (result.success) {
423
+ * console.log('3 users deleted');
424
+ * }
425
+ *
426
+ * @since 1.0.0
427
+ */
428
+ bulkDelete(
429
+ source: string,
430
+ entity: string,
431
+ ids: Array<string | number>
432
+ ): Promise<ClientResult<null>>;
433
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * * Invoke serverless functions deployed on the Amaster platform.
3
+ *
4
+ * @module function
5
+ */
6
+
7
+ import type { ClientResult } from './common';
8
+
9
+ /**
10
+ * Function Client API
11
+ *
12
+ * Execute serverless functions with type-safe parameters and results.
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ export interface FunctionClientAPI {
17
+ /**
18
+ * Invoke a serverless function
19
+ *
20
+ * @param funcName - Function name (corresponds to directory in src/functions/)
21
+ * @param params - Function parameters (sent as JSON body)
22
+ * @returns Function execution result
23
+ *
24
+ * @example
25
+ * const result = await client.function.invoke<{ message: string }>('sendEmail', {
26
+ * to: 'user@example.com',
27
+ * subject: 'Hello',
28
+ * body: 'Welcome!'
29
+ * });
30
+ *
31
+ * if (result.success) {
32
+ * console.log(result.data.message);
33
+ * }
34
+ *
35
+ * @since 1.0.0
36
+ */
37
+ invoke<T = unknown>(
38
+ funcName: string,
39
+ params?: Record<string, unknown>
40
+ ): Promise<ClientResult<T>>;
41
+ }