@amaster.ai/client 1.1.0-beta.4 → 1.1.0-beta.41

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,9 +1,5 @@
1
1
  /**
2
- * ============================================================================
3
- * Copilot AI Assistant - Type Definitions
4
- * ============================================================================
5
- *
6
- * AI-powered assistant for interactive conversations and task assistance.
2
+ * * AI-powered assistant for interactive conversations and task assistance.
7
3
  *
8
4
  * @module copilot
9
5
  */
@@ -105,26 +101,7 @@ export interface DeleteSurfaceMessage {
105
101
  *
106
102
  * Used by the chat() streaming API to send UI updates.
107
103
  * 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
- * ```
104
+ *
128
105
  */
129
106
  export interface ServerToClientMessage {
130
107
  beginRendering?: BeginRenderingMessage;
@@ -187,27 +164,7 @@ export type MessageContent = TextContent | ImageContent | FileContent;
187
164
 
188
165
  /**
189
166
  * 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
- * ```
167
+ *
211
168
  */
212
169
  export interface ChatMessage {
213
170
  /** Message role */
@@ -220,8 +177,9 @@ export interface ChatMessage {
220
177
  /**
221
178
  * Chat options
222
179
  */
223
- export interface ChatOptions {
224
- /** Stream response */
180
+ export interface ChatOptions { /** Task ID for conversation continuity */
181
+ taskId?: string;
182
+ /** Stream response */
225
183
  stream?: boolean;
226
184
 
227
185
  /** Temperature (0-1) */
@@ -240,96 +198,92 @@ export interface ChatOptions {
240
198
  /**
241
199
  * Copilot AI Assistant Client API
242
200
  *
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
- * ```
201
+ * @since 1.0.0
285
202
  */
286
- export interface CopilotA2UIClient {
203
+ export interface CopilotClientAPI {
287
204
  /**
288
- * Send a message to the AI assistant
205
+ * Start a streaming chat session with the AI assistant
289
206
  *
290
- * @param messages - Conversation messages
291
- * @param options - Chat options (streaming, temperature, etc.)
292
- * @returns AI response
207
+ * Returns an async generator that yields A2UI ServerToClientMessage arrays.
208
+ * Each yielded array contains UI updates that should be processed by an A2UI renderer.
209
+ *
210
+ * @param messages - Conversation messages (system, user, assistant)
211
+ * @param options - Chat options (taskId for conversation continuity)
212
+ * @returns AsyncGenerator yielding arrays of A2UI messages
293
213
  *
294
214
  * @example
295
- * Simple question:
296
- * ```typescript
297
- * const result = await client.copilot.sendMessage([
298
- * { role: 'user', content: 'What is the capital of France?' }
215
+ * // Simple chat
216
+ * const chatStream = client.copilot.chat([
217
+ * { role: 'user', content: 'Hello, how can you help me?' }
299
218
  * ]);
300
219
  *
301
- * console.log(result.data.content); // "Paris"
302
- * ```
220
+ * for await (const messages of chatStream) {
221
+ * messages.forEach(msg => {
222
+ * if (msg.surfaceUpdate) {
223
+ * console.log('UI update:', msg.surfaceUpdate);
224
+ * }
225
+ * });
226
+ * }
303
227
  *
304
228
  * @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
- * ```
229
+ * // With conversation history
230
+ * const chatStream = client.copilot.chat([
231
+ * { role: 'system', content: 'You are a helpful assistant.' },
232
+ * { role: 'user', content: 'What is TypeScript?' },
233
+ * { role: 'assistant', content: 'TypeScript is...' },
234
+ * { role: 'user', content: 'Can you give an example?' }
235
+ * ], {
236
+ * taskId: 'conversation-123'
237
+ * });
312
238
  *
313
239
  * @example
314
- * Streaming response:
315
- * ```typescript
316
- * await client.copilot.sendMessage(
317
- * [{ role: 'user', content: 'Explain async/await' }],
240
+ * // With image content
241
+ * const chatStream = client.copilot.chat([
318
242
  * {
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
- * }
243
+ * role: 'user',
244
+ * content: [
245
+ * { type: 'text', text: 'What is in this image?' },
246
+ * { type: 'image', imageUrl: 'https://example.com/image.jpg' }
247
+ * ]
327
248
  * }
328
- * );
329
- * ```
249
+ * ]);
250
+ *
251
+ * @since 1.0.0
330
252
  */
331
- sendMessage(
253
+ chat(
332
254
  messages: ChatMessage[],
333
255
  options?: ChatOptions
334
- ): Promise<ClientResult<{ content: string; role: 'assistant' }>>;
256
+ ): AsyncGenerator<ServerToClientMessage[], void, unknown>;
257
+
258
+ /**
259
+ * Cancel an ongoing chat session
260
+ *
261
+ * @param taskId - Task ID to cancel
262
+ * @returns Cancellation result
263
+ *
264
+ * @example
265
+ * const result = await client.copilot.cancelChat('task-123');
266
+ * if (result.success) {
267
+ * console.log('Chat cancelled');
268
+ * }
269
+ *
270
+ * @since 1.0.0
271
+ */
272
+ cancelChat(taskId: string): Promise<ClientResult<unknown>>;
273
+
274
+ /**
275
+ * Get the status of a chat session
276
+ *
277
+ * @param taskId - Task ID to query
278
+ * @returns Task status information
279
+ *
280
+ * @example
281
+ * const result = await client.copilot.getChatStatus('task-123');
282
+ * if (result.success) {
283
+ * console.log('Status:', result.data);
284
+ * }
285
+ *
286
+ * @since 1.0.0
287
+ */
288
+ getChatStatus(taskId: string): Promise<ClientResult<unknown>>;
335
289
  }