@axiom-lattice/client-sdk 1.0.13 → 1.0.15

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,304 @@
1
+ /**
2
+ * Core types for the Axiom Lattice Client SDK
3
+ */
4
+ import { Message, MessageChunk } from "@axiom-lattice/protocols";
5
+ /**
6
+ * Transport method for client-server communication
7
+ * Note: Currently only "ws" is used for tool registration
8
+ */
9
+ export type Transport = "sse" | "ws";
10
+ /**
11
+ * Configuration options for the Client
12
+ */
13
+ export interface ClientConfig {
14
+ /**
15
+ * Base URL for the API
16
+ */
17
+ baseURL: string;
18
+ /**
19
+ * API key for authentication
20
+ */
21
+ apiKey: string;
22
+ /**
23
+ * Assistant identifier
24
+ */
25
+ assistantId: string;
26
+ /**
27
+ * Transport method (Server-Sent Events or WebSocket)
28
+ */
29
+ transport: Transport;
30
+ /**
31
+ * Request timeout in milliseconds (optional, defaults to 30000)
32
+ */
33
+ timeout?: number;
34
+ /**
35
+ * Additional headers to include in requests (optional)
36
+ */
37
+ headers?: Record<string, string>;
38
+ /**
39
+ * Configuration for retry behavior (optional)
40
+ */
41
+ retry?: RetryConfig;
42
+ }
43
+ /**
44
+ * Configuration for retry behavior
45
+ */
46
+ export interface RetryConfig {
47
+ /**
48
+ * Maximum number of retry attempts
49
+ */
50
+ maxRetries: number;
51
+ /**
52
+ * Initial delay between retries in milliseconds
53
+ */
54
+ initialDelayMs: number;
55
+ /**
56
+ * Maximum delay between retries in milliseconds
57
+ */
58
+ maxDelayMs: number;
59
+ /**
60
+ * Factor to multiply delay by after each retry attempt
61
+ */
62
+ backoffFactor: number;
63
+ }
64
+ /**
65
+ * Thread creation options
66
+ */
67
+ export interface CreateThreadOptions {
68
+ /**
69
+ * Optional metadata for the thread
70
+ */
71
+ metadata?: Record<string, any>;
72
+ }
73
+ /**
74
+ * Thread information
75
+ */
76
+ export interface Thread {
77
+ /**
78
+ * Thread identifier
79
+ */
80
+ id: string;
81
+ /**
82
+ * Thread metadata
83
+ */
84
+ metadata?: Record<string, any>;
85
+ /**
86
+ * Thread creation timestamp
87
+ */
88
+ createdAt: string;
89
+ }
90
+ /**
91
+ * Chat send options
92
+ */
93
+ export interface ChatSendOptions {
94
+ /**
95
+ * Thread identifier
96
+ */
97
+ threadId: string;
98
+ /**
99
+ * Messages to send
100
+ */
101
+ messages: Message[];
102
+ /**
103
+ * Files to attach (optional)
104
+ */
105
+ files?: any[];
106
+ /**
107
+ * Command to execute (optional)
108
+ */
109
+ command?: {
110
+ resume?: {
111
+ action: string;
112
+ data: Record<string, any> & {
113
+ config?: {
114
+ thread_id?: string;
115
+ work_log_id?: string;
116
+ };
117
+ };
118
+ message: string;
119
+ };
120
+ update?: any;
121
+ send?: {
122
+ node: string;
123
+ input: any;
124
+ };
125
+ };
126
+ [key: string]: any;
127
+ }
128
+ /**
129
+ * Chat stream options
130
+ */
131
+ export interface ChatStreamOptions extends ChatSendOptions {
132
+ /**
133
+ * Whether to run in background (optional)
134
+ */
135
+ background?: boolean;
136
+ /**
137
+ * Whether to return agent state when stream completes (optional)
138
+ */
139
+ enableReturnStateWhenSteamCompleted?: boolean;
140
+ }
141
+ /**
142
+ * Stream callbacks interface
143
+ */
144
+ export interface StreamCallbacks {
145
+ /**
146
+ * Called when a stream event is received
147
+ */
148
+ onEvent: (event: MessageChunk) => void;
149
+ /**
150
+ * Called when the stream completes, with optional agent state
151
+ */
152
+ onComplete?: (state?: AgentState) => void;
153
+ /**
154
+ * Called when an error occurs
155
+ */
156
+ onError?: (error: Error) => void;
157
+ }
158
+ /**
159
+ * Chat response
160
+ */
161
+ export interface ChatResponse {
162
+ /**
163
+ * Response messages
164
+ */
165
+ messages: Message[];
166
+ /**
167
+ * Trace ID for debugging
168
+ */
169
+ traceId?: string;
170
+ }
171
+ /**
172
+ * Tool registration options
173
+ */
174
+ export interface RegisterToolOptions {
175
+ /**
176
+ * Tool name
177
+ */
178
+ name: string;
179
+ /**
180
+ * Tool parameter schema
181
+ */
182
+ schema: object;
183
+ /**
184
+ * Tool handler function
185
+ */
186
+ handler: (params: any) => Promise<any>;
187
+ }
188
+ /**
189
+ * Get messages options
190
+ */
191
+ export interface GetMessagesOptions {
192
+ /**
193
+ * Thread identifier
194
+ */
195
+ threadId: string;
196
+ /**
197
+ * Maximum number of messages to return
198
+ */
199
+ limit?: number;
200
+ /**
201
+ * Message ID to start from (for pagination)
202
+ */
203
+ after?: string;
204
+ /**
205
+ * Whether to return messages in reverse chronological order
206
+ */
207
+ reverse?: boolean;
208
+ }
209
+ /**
210
+ * Resume stream options
211
+ */
212
+ export interface ResumeStreamOptions {
213
+ /**
214
+ * Thread identifier
215
+ */
216
+ threadId: string;
217
+ /**
218
+ * Message identifier (usually run_id)
219
+ */
220
+ messageId: string;
221
+ /**
222
+ * Content already received (used to find resume position)
223
+ */
224
+ knownContent: string;
225
+ /**
226
+ * Polling interval in milliseconds (default: 100ms)
227
+ */
228
+ pollInterval?: number;
229
+ }
230
+ /**
231
+ * Thread list options
232
+ */
233
+ export interface ListThreadsOptions {
234
+ /**
235
+ * Maximum number of threads to return
236
+ */
237
+ limit?: number;
238
+ /**
239
+ * Offset for pagination
240
+ */
241
+ offset?: number;
242
+ }
243
+ /**
244
+ * Run options
245
+ */
246
+ export type RunOptions = {
247
+ /**
248
+ * Thread identifier
249
+ */
250
+ threadId: string;
251
+ /**
252
+ * Message to send
253
+ */
254
+ message: string;
255
+ /**
256
+ * Files to attach (optional)
257
+ */
258
+ files?: any[];
259
+ /**
260
+ * Command to execute (optional)
261
+ */
262
+ command?: any;
263
+ /**
264
+ * Whether to stream the response (optional)
265
+ */
266
+ streaming?: boolean;
267
+ /**
268
+ * Whether to run in background (optional)
269
+ */
270
+ background?: boolean;
271
+ /**
272
+ * Whether to return agent state when stream completes (optional)
273
+ */
274
+ enableReturnStateWhenSteamCompleted?: boolean;
275
+ } & Record<string, any>;
276
+ /**
277
+ * Agent state
278
+ */
279
+ export interface AgentState {
280
+ values: {
281
+ messages: Message[];
282
+ [key: string]: any;
283
+ };
284
+ tasks: Array<{
285
+ interrupts: Array<{
286
+ value: any;
287
+ }>;
288
+ }>;
289
+ }
290
+ /**
291
+ * Custom error classes
292
+ */
293
+ export declare class ApiError extends Error {
294
+ statusCode: number;
295
+ responseBody?: any | undefined;
296
+ constructor(message: string, statusCode: number, responseBody?: any | undefined);
297
+ }
298
+ export declare class NetworkError extends Error {
299
+ constructor(message: string);
300
+ }
301
+ export declare class AuthenticationError extends Error {
302
+ constructor(message: string);
303
+ }
304
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,OAAO,EAMP,YAAY,EACb,MAAM,0BAA0B,CAAC;AAElC;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,IAAI,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;OAEG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;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OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;IAEd;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,mCAAmC,CAAC,EAAE,OAAO,CAAC;CAC/C,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE;QACN,QAAQ,EAAE,OAAO,EAAE,CAAC;QACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,KAAK,EAAE,KAAK,CAAC;QACX,UAAU,EAAE,KAAK,CAAC;YAChB,KAAK,EAAE,GAAG,CAAC;SACZ,CAAC,CAAC;KACJ,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAGxB,UAAU,EAAE,MAAM;IAClB,YAAY,CAAC,EAAE,GAAG;gBAFzB,OAAO,EAAE,MAAM,EACR,UAAU,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,GAAG,YAAA;CAK5B;AAED,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B"}
package/dist/types.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Core types for the Axiom Lattice Client SDK
3
+ */
4
+ /**
5
+ * Custom error classes
6
+ */
7
+ export class ApiError extends Error {
8
+ constructor(message, statusCode, responseBody) {
9
+ super(message);
10
+ this.statusCode = statusCode;
11
+ this.responseBody = responseBody;
12
+ this.name = "ApiError";
13
+ }
14
+ }
15
+ export class NetworkError extends Error {
16
+ constructor(message) {
17
+ super(message);
18
+ this.name = "NetworkError";
19
+ }
20
+ }
21
+ export class AuthenticationError extends Error {
22
+ constructor(message) {
23
+ super(message);
24
+ this.name = "AuthenticationError";
25
+ }
26
+ }
27
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmVH;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YACE,OAAe,EACR,UAAkB,EAClB,YAAkB;QAEzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,eAAU,GAAV,UAAU,CAAQ;QAClB,iBAAY,GAAZ,YAAY,CAAM;QAGzB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,65 @@
1
+ import { MessageChunk } from "@axiom-lattice/protocols";
2
+ import { AgentState, ClientConfig, ResumeStreamOptions, RunOptions } from "./types";
3
+ import { AbstractClient } from "./abstract-client";
4
+ /**
5
+ * WeChat Mini Program client for interacting with the Axiom Lattice Agent Service API
6
+ */
7
+ export declare class WeChatClient extends AbstractClient {
8
+ /**
9
+ * Creates a new WeChatClient instance
10
+ * @param config - Configuration options for the client
11
+ */
12
+ constructor(config: ClientConfig);
13
+ /**
14
+ * Set tenant ID for multi-tenant environments
15
+ * @param tenantId - Tenant identifier
16
+ */
17
+ setTenantId(tenantId: string): void;
18
+ /**
19
+ * Implementation of the abstract makeRequest method for WeChat clients
20
+ * @param url - The URL to make the request to
21
+ * @param options - Request options
22
+ * @returns A promise that resolves to the response data
23
+ */
24
+ protected makeRequest<T>(url: string, options?: {
25
+ method?: string;
26
+ body?: any;
27
+ headers?: Record<string, string>;
28
+ }): Promise<T>;
29
+ /**
30
+ * Implementation of the abstract streamRequest method for WeChat clients
31
+ */
32
+ protected streamRequest(options: RunOptions, onEvent: (event: MessageChunk) => void, onComplete?: (state?: AgentState) => void, onError?: (error: Error) => void): () => void;
33
+ /**
34
+ * Resume streaming from a known position
35
+ * @param options - Options for resuming the stream
36
+ * @param onEvent - Callback function that receives stream events
37
+ * @param onComplete - Optional callback function called when streaming completes
38
+ * @param onError - Optional callback function called when an error occurs
39
+ * @returns A function that can be called to stop the stream
40
+ */
41
+ resumeStream(options: ResumeStreamOptions, onEvent: (event: MessageChunk) => void, onComplete?: () => void, onError?: (error: Error) => void): () => void;
42
+ /**
43
+ * Helper method to make WeChat HTTP requests
44
+ * @private
45
+ */
46
+ private request;
47
+ /**
48
+ * Stream run results using WeChat's downloadFile API
49
+ * @param options - Options for streaming run results
50
+ * @param onEvent - Callback function that receives stream events
51
+ * @param onComplete - Optional callback function called when streaming completes
52
+ * @param onError - Optional callback function called when an error occurs
53
+ * @returns A function that can be called to stop the stream
54
+ */
55
+ private streamRun;
56
+ decodeUint8Array(uint8Array: ArrayBuffer): any;
57
+ buf2hex(arrayBuffer: ArrayBuffer): string;
58
+ /**
59
+ * Convert hexadecimal string to text (supports Chinese characters)
60
+ * @param {String} hex - Hexadecimal string
61
+ * @return {String} Decoded string including Chinese characters
62
+ */
63
+ hexToStr(hex: string): any;
64
+ }
65
+ //# sourceMappingURL=wechat-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wechat-client.d.ts","sourceRoot":"","sources":["../src/wechat-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,UAAU,EAMV,YAAY,EAMZ,mBAAmB,EAC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