@amaster.ai/client 1.1.0-beta.5 → 1.1.0-beta.50

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/types/common.d.ts CHANGED
@@ -1,12 +1,38 @@
1
1
  /**
2
- * ============================================================================
3
- * Common Types - Shared across all modules
4
- * ============================================================================
2
+ * Error information structure
5
3
  *
6
- * This file contains shared type definitions used by all Amaster client modules.
7
- *
8
- * @packageDocumentation
4
+ * @since 1.1.0
9
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
+ }
10
36
 
11
37
  /**
12
38
  * Standard API response wrapper
@@ -17,33 +43,21 @@
17
43
  * @template T - The type of the successful response data
18
44
  *
19
45
  * @example
20
- * Success response:
21
- * ```typescript
22
- * const result: ClientResult<User> = await client.auth.getMe();
23
- * if (result.data) {
24
- * console.log('User:', result.data); // Type: User
25
- * }
26
- * ```
27
- *
28
- * @example
29
- * Error handling:
30
- * ```typescript
31
- * const result = await client.entity.get('default', 'users', '123');
32
- * if (result.error) {
33
- * console.error(`Error ${result.error.status}:`, result.error.message);
46
+ * // Success case
47
+ * const result = await client.entity.list('default', 'users');
48
+ * if (result.success) {
49
+ * console.log('Data:', result.data);
34
50
  * }
35
- * ```
36
51
  *
37
52
  * @example
38
- * Check by HTTP status:
39
- * ```typescript
53
+ * // Error case
40
54
  * const result = await client.auth.login({ email, password });
41
- * if (result.status === 200 && result.data) {
42
- * // Success
43
- * } else if (result.status === 401) {
44
- * // Unauthorized
55
+ * if (!result.success) {
56
+ * console.error('Error:', result.error.message);
57
+ * console.error('Code:', result.error.code);
45
58
  * }
46
- * ```
59
+ *
60
+ * @since 1.0.0
47
61
  */
48
62
  export interface ClientResult<T> {
49
63
  /**
@@ -54,27 +68,21 @@ export interface ClientResult<T> {
54
68
  /**
55
69
  * Error information (null if successful)
56
70
  */
57
- error: {
58
- /**
59
- * HTTP status code
60
- */
61
- status: number;
62
-
63
- /**
64
- * Error message
65
- */
66
- message: string;
67
-
68
- /**
69
- * Additional error details (optional)
70
- */
71
- details?: unknown;
72
- } | null;
71
+ error: ClientError | null;
73
72
 
74
73
  /**
75
74
  * HTTP response status code
76
75
  */
77
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;
78
86
  }
79
87
 
80
88
  /**
@@ -1,335 +1,49 @@
1
- /**
2
- * ============================================================================
3
- * Copilot AI Assistant - Type Definitions
4
- * ============================================================================
5
- *
6
- * AI-powered assistant for interactive conversations and task assistance.
7
- *
8
- * @module copilot
9
- */
10
-
1
+ import type { SendStreamingMessageResponse, CancelTaskResponse, GetTaskResponse } from '@a2a-js/sdk';
11
2
  import type { ClientResult } from './common';
12
3
 
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
-
157
- /**
158
- * Text content in a message
159
- */
160
- export interface TextContent {
161
- type: 'text';
162
- text: string;
163
- }
164
-
165
- /**
166
- * Image content in a message
167
- */
168
- export interface ImageContent {
169
- type: 'image';
170
- imageUrl: string;
171
- }
172
-
173
- /**
174
- * File content in a message
175
- */
176
- export interface FileContent {
177
- type: 'file';
178
- fileUrl: string;
179
- fileName?: string;
180
- mimeType?: string;
181
- }
182
-
183
- /**
184
- * Message content (text, image, or file)
185
- */
186
- export type MessageContent = TextContent | ImageContent | FileContent;
187
-
188
- /**
189
- * Chat message
190
- *
191
- * @example
192
- * Text message:
193
- * ```typescript
194
- * const message: ChatMessage = {
195
- * role: 'user',
196
- * content: 'Hello, how can you help me?'
197
- * };
198
- * ```
199
- *
200
- * @example
201
- * Message with image:
202
- * ```typescript
203
- * const message: ChatMessage = {
204
- * role: 'user',
205
- * content: [
206
- * { type: 'text', text: 'What is in this image?' },
207
- * { type: 'image', imageUrl: 'https://example.com/image.jpg' }
208
- * ]
209
- * };
210
- * ```
211
- */
212
- export interface ChatMessage {
213
- /** Message role */
214
- role: 'system' | 'user' | 'assistant';
215
-
216
- /** Message content (string or structured content) */
217
- content: string | MessageContent[];
218
- }
219
-
220
- /**
221
- * Chat options
222
- */
223
- export interface ChatOptions {
224
- /** Stream response */
225
- stream?: boolean;
226
-
227
- /** Temperature (0-1) */
228
- temperature?: number;
229
-
230
- /** Maximum tokens to generate */
231
- maxTokens?: number;
232
-
233
- /** Callback for streamed chunks */
234
- onChunk?: (chunk: string) => void;
235
-
236
- /** Callback when streaming completes */
237
- onComplete?: (fullResponse: string) => void;
238
- }
239
-
240
- /**
241
- * Copilot AI Assistant Client API
242
- *
243
- * @example
244
- * Basic chat:
245
- * ```typescript
246
- * const client = createClient({ baseURL: 'https://api.amaster.ai' });
247
- *
248
- * const result = await client.copilot.sendMessage([
249
- * { role: 'user', content: 'Hello, how are you?' }
250
- * ]);
251
- *
252
- * if (result.data) {
253
- * console.log('AI Response:', result.data.content);
254
- * }
255
- * ```
256
- *
257
- * @example
258
- * Streaming response:
259
- * ```typescript
260
- * await client.copilot.sendMessage(
261
- * [{ role: 'user', content: 'Tell me a story' }],
262
- * {
263
- * stream: true,
264
- * onChunk: (chunk) => {
265
- * process.stdout.write(chunk);
266
- * },
267
- * onComplete: (fullResponse) => {
268
- * console.log('\n\nFull response:', fullResponse);
269
- * }
270
- * }
271
- * );
272
- * ```
273
- *
274
- * @example
275
- * Multi-turn conversation:
276
- * ```typescript
277
- * const conversation: ChatMessage[] = [
278
- * { role: 'user', content: 'What is TypeScript?' },
279
- * { role: 'assistant', content: 'TypeScript is a typed superset of JavaScript...' },
280
- * { role: 'user', content: 'How do I define interfaces?' }
281
- * ];
282
- *
283
- * const result = await client.copilot.sendMessage(conversation);
284
- * ```
285
- */
286
- export interface CopilotA2UIClient {
287
- /**
288
- * Send a message to the AI assistant
289
- *
290
- * @param messages - Conversation messages
291
- * @param options - Chat options (streaming, temperature, etc.)
292
- * @returns AI response
293
- *
294
- * @example
295
- * Simple question:
296
- * ```typescript
297
- * const result = await client.copilot.sendMessage([
298
- * { role: 'user', content: 'What is the capital of France?' }
299
- * ]);
300
- *
301
- * console.log(result.data.content); // "Paris"
302
- * ```
303
- *
304
- * @example
305
- * With system prompt:
306
- * ```typescript
307
- * const result = await client.copilot.sendMessage([
308
- * { role: 'system', content: 'You are a helpful coding assistant' },
309
- * { role: 'user', content: 'How do I reverse a string in JavaScript?' }
310
- * ]);
311
- * ```
312
- *
313
- * @example
314
- * Streaming response:
315
- * ```typescript
316
- * await client.copilot.sendMessage(
317
- * [{ role: 'user', content: 'Explain async/await' }],
318
- * {
319
- * stream: true,
320
- * onChunk: (chunk) => {
321
- * // Update UI with each chunk
322
- * appendToChat(chunk);
323
- * },
324
- * onComplete: (fullText) => {
325
- * console.log('Complete response received');
326
- * }
327
- * }
328
- * );
329
- * ```
330
- */
331
- sendMessage(
332
- messages: ChatMessage[],
333
- options?: ChatOptions
334
- ): Promise<ClientResult<{ content: string; role: 'assistant' }>>;
335
- }
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 };