@axiom-lattice/client-sdk 1.0.23 → 1.0.24
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 +33 -0
- package/dist/index.d.ts +121 -20
- package/dist/index.js +538 -369
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +537 -359
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -5
package/README.md
CHANGED
|
@@ -182,6 +182,39 @@ Steps for future migration:
|
|
|
182
182
|
|
|
183
183
|
The main client class for interacting with the Axiom Lattice Agent Service API.
|
|
184
184
|
|
|
185
|
+
### WeChatClient
|
|
186
|
+
|
|
187
|
+
A specialized client implementation for WeChat Mini Programs that uses the native `wx` API for network requests.
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import { WeChatClient } from "@axiom-lattice/client-sdk";
|
|
191
|
+
|
|
192
|
+
// Create a WeChat client
|
|
193
|
+
const client = new WeChatClient({
|
|
194
|
+
baseURL: "https://api.example.com",
|
|
195
|
+
apiKey: "your-api-key",
|
|
196
|
+
assistantId: "your-assistant-id",
|
|
197
|
+
transport: "sse",
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Use the same API methods as the standard Client
|
|
201
|
+
const threadId = await client.createThread({
|
|
202
|
+
metadata: { user: "user123" },
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Send a message
|
|
206
|
+
const response = await client.chat.send({
|
|
207
|
+
threadId,
|
|
208
|
+
messages: [
|
|
209
|
+
{
|
|
210
|
+
role: "user",
|
|
211
|
+
content: "Hello, how can you help me?",
|
|
212
|
+
id: "msg-1",
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
185
218
|
### ChunkMessageMerger
|
|
186
219
|
|
|
187
220
|
A utility for processing streaming message chunks and merging them into complete messages.
|
package/dist/index.d.ts
CHANGED
|
@@ -9,10 +9,6 @@ import { Message, MessageChunk, AssistantMessage } from '@axiom-lattice/protocol
|
|
|
9
9
|
* Note: Currently only "ws" is used for tool registration
|
|
10
10
|
*/
|
|
11
11
|
type Transport = "sse" | "ws";
|
|
12
|
-
/**
|
|
13
|
-
* Runtime environment for the client
|
|
14
|
-
*/
|
|
15
|
-
type RuntimeEnvironment = "web" | "wechat-miniprogram";
|
|
16
12
|
/**
|
|
17
13
|
* Configuration options for the Client
|
|
18
14
|
*/
|
|
@@ -33,11 +29,6 @@ interface ClientConfig {
|
|
|
33
29
|
* Transport method (Server-Sent Events or WebSocket)
|
|
34
30
|
*/
|
|
35
31
|
transport: Transport;
|
|
36
|
-
/**
|
|
37
|
-
* Runtime environment (web or wechat-miniprogram)
|
|
38
|
-
* Defaults to "web" if not specified
|
|
39
|
-
*/
|
|
40
|
-
environment?: RuntimeEnvironment;
|
|
41
32
|
/**
|
|
42
33
|
* Request timeout in milliseconds (optional, defaults to 30000)
|
|
43
34
|
*/
|
|
@@ -271,22 +262,26 @@ declare class AuthenticationError extends Error {
|
|
|
271
262
|
* Main client class for interacting with the Axiom Lattice Agent Service API
|
|
272
263
|
*/
|
|
273
264
|
declare class Client {
|
|
274
|
-
private client;
|
|
275
265
|
private config;
|
|
276
266
|
private assistantId;
|
|
277
267
|
private tenantId;
|
|
278
268
|
private registeredTools;
|
|
279
|
-
private
|
|
269
|
+
private headers;
|
|
280
270
|
/**
|
|
281
271
|
* Creates a new Client instance
|
|
282
272
|
* @param config - Configuration options for the client
|
|
283
273
|
*/
|
|
284
274
|
constructor(config: ClientConfig);
|
|
285
275
|
/**
|
|
286
|
-
*
|
|
276
|
+
* Helper method to handle fetch responses and errors
|
|
277
|
+
* @private
|
|
278
|
+
*/
|
|
279
|
+
private handleResponse;
|
|
280
|
+
/**
|
|
281
|
+
* Helper method to make fetch requests
|
|
287
282
|
* @private
|
|
288
283
|
*/
|
|
289
|
-
private
|
|
284
|
+
private fetchWithTimeout;
|
|
290
285
|
/**
|
|
291
286
|
* Set tenant ID for multi-tenant environments
|
|
292
287
|
* @param tenantId - Tenant identifier
|
|
@@ -336,7 +331,7 @@ declare class Client {
|
|
|
336
331
|
/**
|
|
337
332
|
* Run agent with options
|
|
338
333
|
* @param options - Options for running the agent
|
|
339
|
-
* @returns A promise that resolves to the run result
|
|
334
|
+
* @returns A promise that resolves to the run result
|
|
340
335
|
*/
|
|
341
336
|
run(options: RunOptions): Promise<any>;
|
|
342
337
|
/**
|
|
@@ -349,15 +344,121 @@ declare class Client {
|
|
|
349
344
|
*/
|
|
350
345
|
private streamRun;
|
|
351
346
|
/**
|
|
352
|
-
*
|
|
353
|
-
|
|
347
|
+
* Chat namespace for sending messages and streaming responses
|
|
348
|
+
*/
|
|
349
|
+
chat: {
|
|
350
|
+
/**
|
|
351
|
+
* Sends a message to a thread and receives a response
|
|
352
|
+
* @param options - Options for sending a message
|
|
353
|
+
* @returns A promise that resolves to the chat response
|
|
354
|
+
*/
|
|
355
|
+
send: (options: ChatSendOptions) => Promise<ChatResponse>;
|
|
356
|
+
/**
|
|
357
|
+
* Sends a message to a thread and streams the response
|
|
358
|
+
* @param options - Options for streaming a message
|
|
359
|
+
* @param onEvent - Callback function that receives stream events
|
|
360
|
+
* @param onComplete - Optional callback function called when streaming completes
|
|
361
|
+
* @param onError - Optional callback function called when an error occurs
|
|
362
|
+
* @returns A function that can be called to stop the stream
|
|
363
|
+
*/
|
|
364
|
+
stream: (options: ChatStreamOptions, onEvent: (event: MessageChunk) => void, onComplete?: (state?: AgentState) => void, onError?: (error: Error) => void) => (() => void);
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* Tools namespace for registering and unregistering client-side tools
|
|
368
|
+
*/
|
|
369
|
+
tools: {
|
|
370
|
+
/**
|
|
371
|
+
* Registers a client-side tool
|
|
372
|
+
* @param options - Options for registering a tool
|
|
373
|
+
*/
|
|
374
|
+
register: (options: RegisterToolOptions) => void;
|
|
375
|
+
/**
|
|
376
|
+
* Unregisters a client-side tool
|
|
377
|
+
* @param name - Tool name
|
|
378
|
+
*/
|
|
379
|
+
unregister: (name: string) => void;
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* WeChat Mini Program client for interacting with the Axiom Lattice Agent Service API
|
|
385
|
+
*/
|
|
386
|
+
declare class WeChatClient {
|
|
387
|
+
private config;
|
|
388
|
+
private assistantId;
|
|
389
|
+
private tenantId;
|
|
390
|
+
private registeredTools;
|
|
391
|
+
/**
|
|
392
|
+
* Creates a new WeChatClient instance
|
|
393
|
+
* @param config - Configuration options for the client
|
|
394
|
+
*/
|
|
395
|
+
constructor(config: ClientConfig);
|
|
396
|
+
/**
|
|
397
|
+
* Set tenant ID for multi-tenant environments
|
|
398
|
+
* @param tenantId - Tenant identifier
|
|
354
399
|
*/
|
|
355
|
-
|
|
400
|
+
setTenantId(tenantId: string): void;
|
|
356
401
|
/**
|
|
357
|
-
*
|
|
402
|
+
* Helper method to make WeChat HTTP requests
|
|
358
403
|
* @private
|
|
359
404
|
*/
|
|
360
|
-
private
|
|
405
|
+
private request;
|
|
406
|
+
/**
|
|
407
|
+
* Creates a new thread
|
|
408
|
+
* @param options - Options for creating a thread
|
|
409
|
+
* @returns A promise that resolves to the thread ID
|
|
410
|
+
*/
|
|
411
|
+
createThread(options: CreateThreadOptions): Promise<string>;
|
|
412
|
+
/**
|
|
413
|
+
* Retrieves thread information
|
|
414
|
+
* @param threadId - Thread identifier
|
|
415
|
+
* @returns A promise that resolves to the thread information
|
|
416
|
+
*/
|
|
417
|
+
getThread(threadId: string): Promise<Thread>;
|
|
418
|
+
/**
|
|
419
|
+
* Lists all threads
|
|
420
|
+
* @param options - Options for listing threads
|
|
421
|
+
* @returns A promise that resolves to an array of threads
|
|
422
|
+
*/
|
|
423
|
+
listThreads(options?: ListThreadsOptions): Promise<Thread[]>;
|
|
424
|
+
/**
|
|
425
|
+
* Deletes a thread
|
|
426
|
+
* @param threadId - Thread identifier
|
|
427
|
+
* @returns A promise that resolves when the thread is deleted
|
|
428
|
+
*/
|
|
429
|
+
deleteThread(threadId: string): Promise<void>;
|
|
430
|
+
/**
|
|
431
|
+
* Retrieves messages from a thread
|
|
432
|
+
* @param options - Options for retrieving messages
|
|
433
|
+
* @returns A promise that resolves to an array of messages
|
|
434
|
+
*/
|
|
435
|
+
getMessages(options: GetMessagesOptions): Promise<Message[]>;
|
|
436
|
+
/**
|
|
437
|
+
* Retrieves agent state
|
|
438
|
+
* @param threadId - Thread identifier
|
|
439
|
+
* @returns A promise that resolves to the agent state
|
|
440
|
+
*/
|
|
441
|
+
getAgentState(threadId: string): Promise<AgentState>;
|
|
442
|
+
/**
|
|
443
|
+
* Gets agent graph visualization
|
|
444
|
+
* @returns A promise that resolves to the graph visualization data
|
|
445
|
+
*/
|
|
446
|
+
getAgentGraph(): Promise<string>;
|
|
447
|
+
/**
|
|
448
|
+
* Run agent with options
|
|
449
|
+
* @param options - Options for running the agent
|
|
450
|
+
* @returns A promise that resolves to the run result
|
|
451
|
+
*/
|
|
452
|
+
run(options: RunOptions): Promise<any>;
|
|
453
|
+
/**
|
|
454
|
+
* Stream run results using WeChat's downloadFile API
|
|
455
|
+
* @param options - Options for streaming run results
|
|
456
|
+
* @param onEvent - Callback function that receives stream events
|
|
457
|
+
* @param onComplete - Optional callback function called when streaming completes
|
|
458
|
+
* @param onError - Optional callback function called when an error occurs
|
|
459
|
+
* @returns A function that can be called to stop the stream
|
|
460
|
+
*/
|
|
461
|
+
private streamRun;
|
|
361
462
|
/**
|
|
362
463
|
* Chat namespace for sending messages and streaming responses
|
|
363
464
|
*/
|
|
@@ -413,4 +514,4 @@ declare function createSimpleMessageMerger(): {
|
|
|
413
514
|
reset: () => void;
|
|
414
515
|
};
|
|
415
516
|
|
|
416
|
-
export { AgentState, ApiError, AuthenticationError, ChatResponse, ChatSendOptions, ChatStreamOptions, Client, ClientConfig, CreateThreadOptions, GetMessagesOptions, ListThreadsOptions, NetworkError, RegisterToolOptions, RetryConfig, RunOptions,
|
|
517
|
+
export { AgentState, ApiError, AuthenticationError, ChatResponse, ChatSendOptions, ChatStreamOptions, Client, ClientConfig, CreateThreadOptions, GetMessagesOptions, ListThreadsOptions, NetworkError, RegisterToolOptions, RetryConfig, RunOptions, StreamCallbacks, Thread, Transport, WeChatClient, createSimpleMessageMerger };
|