@march-ai/history-sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +449 -0
- package/dist/index.cjs +4790 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +759 -0
- package/dist/index.d.ts +759 -0
- package/dist/index.js +4771 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retry configuration options
|
|
5
|
+
*/
|
|
6
|
+
interface RetryConfig {
|
|
7
|
+
/** Maximum number of retry attempts */
|
|
8
|
+
maxRetries: number;
|
|
9
|
+
/** Exponential backoff multiplier */
|
|
10
|
+
backoffFactor: number;
|
|
11
|
+
/** HTTP status codes that should trigger a retry */
|
|
12
|
+
retryStatusCodes: number[];
|
|
13
|
+
/** Maximum backoff delay in seconds */
|
|
14
|
+
maxBackoffSeconds: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Default retry configuration
|
|
18
|
+
*/
|
|
19
|
+
declare const DEFAULT_RETRY_CONFIG: RetryConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Internal client configuration
|
|
22
|
+
*/
|
|
23
|
+
interface ClientConfig {
|
|
24
|
+
/** Base URL of the API */
|
|
25
|
+
baseUrl: string;
|
|
26
|
+
/** Request timeout in milliseconds */
|
|
27
|
+
timeout: number;
|
|
28
|
+
/** Retry configuration */
|
|
29
|
+
retryConfig: RetryConfig;
|
|
30
|
+
/** Optional API key for X-API-Key header (backend) */
|
|
31
|
+
apiKey?: string;
|
|
32
|
+
/** Optional JWT bearer token for Authorization header (frontend) */
|
|
33
|
+
bearerToken?: string;
|
|
34
|
+
/** Custom headers to include in all requests */
|
|
35
|
+
customHeaders?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* User-facing client options (all fields optional except those required)
|
|
39
|
+
*/
|
|
40
|
+
interface MarchHistoryClientOptions {
|
|
41
|
+
/** Base URL of the API (default: http://localhost:8000) */
|
|
42
|
+
baseUrl?: string;
|
|
43
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
44
|
+
timeout?: number;
|
|
45
|
+
/** Maximum number of retry attempts (default: 3) */
|
|
46
|
+
maxRetries?: number;
|
|
47
|
+
/** Custom retry configuration (overrides maxRetries if provided) */
|
|
48
|
+
retryConfig?: Partial<RetryConfig>;
|
|
49
|
+
/** Optional API key for X-API-Key header (backend use) */
|
|
50
|
+
apiKey?: string;
|
|
51
|
+
/** Optional JWT bearer token for Authorization header (frontend use) */
|
|
52
|
+
bearerToken?: string;
|
|
53
|
+
/** Custom headers to include in all requests */
|
|
54
|
+
customHeaders?: Record<string, string>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Base HTTP client with fetch API and retry logic
|
|
59
|
+
*/
|
|
60
|
+
declare class BaseHTTPClient {
|
|
61
|
+
private config;
|
|
62
|
+
private abortController;
|
|
63
|
+
constructor(config: ClientConfig);
|
|
64
|
+
/**
|
|
65
|
+
* Build headers for requests
|
|
66
|
+
*/
|
|
67
|
+
private getHeaders;
|
|
68
|
+
/**
|
|
69
|
+
* Wrapper around native fetch with timeout support
|
|
70
|
+
*/
|
|
71
|
+
private fetch;
|
|
72
|
+
/**
|
|
73
|
+
* Handle response and parse JSON or throw error
|
|
74
|
+
*/
|
|
75
|
+
private handleResponse;
|
|
76
|
+
/**
|
|
77
|
+
* GET request with retry logic
|
|
78
|
+
*/
|
|
79
|
+
get<T>(path: string, params?: Record<string, any>): Promise<T>;
|
|
80
|
+
/**
|
|
81
|
+
* POST request with retry logic
|
|
82
|
+
*/
|
|
83
|
+
post<T>(path: string, body?: Record<string, any>): Promise<T>;
|
|
84
|
+
/**
|
|
85
|
+
* PATCH request with retry logic
|
|
86
|
+
*/
|
|
87
|
+
patch<T>(path: string, body?: Record<string, any>): Promise<T>;
|
|
88
|
+
/**
|
|
89
|
+
* DELETE request with retry logic
|
|
90
|
+
*/
|
|
91
|
+
delete(path: string): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Close the client and abort any in-flight requests
|
|
94
|
+
*/
|
|
95
|
+
close(): void;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Base resource class with HTTP client methods
|
|
100
|
+
*/
|
|
101
|
+
declare abstract class BaseResource {
|
|
102
|
+
protected config: ClientConfig;
|
|
103
|
+
protected httpClient: BaseHTTPClient;
|
|
104
|
+
constructor(config: ClientConfig);
|
|
105
|
+
/**
|
|
106
|
+
* GET request helper
|
|
107
|
+
*/
|
|
108
|
+
protected get<T>(path: string, params?: Record<string, any>): Promise<T>;
|
|
109
|
+
/**
|
|
110
|
+
* POST request helper
|
|
111
|
+
*/
|
|
112
|
+
protected post<T>(path: string, body?: Record<string, any>): Promise<T>;
|
|
113
|
+
/**
|
|
114
|
+
* PATCH request helper
|
|
115
|
+
*/
|
|
116
|
+
protected patch<T>(path: string, body?: Record<string, any>): Promise<T>;
|
|
117
|
+
/**
|
|
118
|
+
* DELETE request helper
|
|
119
|
+
*/
|
|
120
|
+
protected delete(path: string): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Close the HTTP client
|
|
123
|
+
*/
|
|
124
|
+
close(): void;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Tenant schema
|
|
129
|
+
*/
|
|
130
|
+
declare const TenantSchema: z.ZodObject<{
|
|
131
|
+
created_at: z.ZodString;
|
|
132
|
+
updated_at: z.ZodString;
|
|
133
|
+
} & {
|
|
134
|
+
id: z.ZodNumber;
|
|
135
|
+
name: z.ZodString;
|
|
136
|
+
}, "strip", z.ZodTypeAny, {
|
|
137
|
+
created_at: string;
|
|
138
|
+
updated_at: string;
|
|
139
|
+
id: number;
|
|
140
|
+
name: string;
|
|
141
|
+
}, {
|
|
142
|
+
created_at: string;
|
|
143
|
+
updated_at: string;
|
|
144
|
+
id: number;
|
|
145
|
+
name: string;
|
|
146
|
+
}>;
|
|
147
|
+
/**
|
|
148
|
+
* Tenant type
|
|
149
|
+
*/
|
|
150
|
+
type Tenant = z.infer<typeof TenantSchema>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Message role constants
|
|
154
|
+
*/
|
|
155
|
+
declare const MessageRole: {
|
|
156
|
+
readonly USER: "user";
|
|
157
|
+
readonly ASSISTANT: "assistant";
|
|
158
|
+
readonly SYSTEM: "system";
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Message role type
|
|
162
|
+
*/
|
|
163
|
+
type MessageRole = typeof MessageRole[keyof typeof MessageRole];
|
|
164
|
+
/**
|
|
165
|
+
* Message schema
|
|
166
|
+
*/
|
|
167
|
+
declare const MessageSchema: z.ZodObject<{
|
|
168
|
+
created_at: z.ZodString;
|
|
169
|
+
updated_at: z.ZodString;
|
|
170
|
+
} & {
|
|
171
|
+
id: z.ZodNumber;
|
|
172
|
+
conversation_id: z.ZodNumber;
|
|
173
|
+
sequence_number: z.ZodNumber;
|
|
174
|
+
role: z.ZodEnum<["user", "assistant", "system"]>;
|
|
175
|
+
content: z.ZodString;
|
|
176
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
177
|
+
}, "strip", z.ZodTypeAny, {
|
|
178
|
+
created_at: string;
|
|
179
|
+
updated_at: string;
|
|
180
|
+
id: number;
|
|
181
|
+
conversation_id: number;
|
|
182
|
+
sequence_number: number;
|
|
183
|
+
role: "user" | "assistant" | "system";
|
|
184
|
+
content: string;
|
|
185
|
+
metadata: Record<string, any>;
|
|
186
|
+
}, {
|
|
187
|
+
created_at: string;
|
|
188
|
+
updated_at: string;
|
|
189
|
+
id: number;
|
|
190
|
+
conversation_id: number;
|
|
191
|
+
sequence_number: number;
|
|
192
|
+
role: "user" | "assistant" | "system";
|
|
193
|
+
content: string;
|
|
194
|
+
metadata?: Record<string, any> | undefined;
|
|
195
|
+
}>;
|
|
196
|
+
/**
|
|
197
|
+
* Message type
|
|
198
|
+
*/
|
|
199
|
+
type Message = z.infer<typeof MessageSchema>;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Conversation status constants
|
|
203
|
+
*/
|
|
204
|
+
declare const ConversationStatus: {
|
|
205
|
+
readonly ACTIVE: "active";
|
|
206
|
+
readonly ARCHIVED: "archived";
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Conversation status type
|
|
210
|
+
*/
|
|
211
|
+
type ConversationStatus = typeof ConversationStatus[keyof typeof ConversationStatus];
|
|
212
|
+
/**
|
|
213
|
+
* Conversation schema
|
|
214
|
+
* Note: Uses z.lazy() for the messages array to handle circular reference
|
|
215
|
+
*/
|
|
216
|
+
declare const ConversationSchema: z.ZodObject<{
|
|
217
|
+
created_at: z.ZodString;
|
|
218
|
+
updated_at: z.ZodString;
|
|
219
|
+
} & {
|
|
220
|
+
id: z.ZodNumber;
|
|
221
|
+
tenant_id: z.ZodNumber;
|
|
222
|
+
user_id: z.ZodString;
|
|
223
|
+
agent_identifier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
224
|
+
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
225
|
+
status: z.ZodEnum<["active", "archived"]>;
|
|
226
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
227
|
+
messages: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodLazy<z.ZodObject<{
|
|
228
|
+
created_at: z.ZodString;
|
|
229
|
+
updated_at: z.ZodString;
|
|
230
|
+
} & {
|
|
231
|
+
id: z.ZodNumber;
|
|
232
|
+
conversation_id: z.ZodNumber;
|
|
233
|
+
sequence_number: z.ZodNumber;
|
|
234
|
+
role: z.ZodEnum<["user", "assistant", "system"]>;
|
|
235
|
+
content: z.ZodString;
|
|
236
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
237
|
+
}, "strip", z.ZodTypeAny, {
|
|
238
|
+
created_at: string;
|
|
239
|
+
updated_at: string;
|
|
240
|
+
id: number;
|
|
241
|
+
conversation_id: number;
|
|
242
|
+
sequence_number: number;
|
|
243
|
+
role: "user" | "assistant" | "system";
|
|
244
|
+
content: string;
|
|
245
|
+
metadata: Record<string, any>;
|
|
246
|
+
}, {
|
|
247
|
+
created_at: string;
|
|
248
|
+
updated_at: string;
|
|
249
|
+
id: number;
|
|
250
|
+
conversation_id: number;
|
|
251
|
+
sequence_number: number;
|
|
252
|
+
role: "user" | "assistant" | "system";
|
|
253
|
+
content: string;
|
|
254
|
+
metadata?: Record<string, any> | undefined;
|
|
255
|
+
}>>, "many">>>;
|
|
256
|
+
}, "strip", z.ZodTypeAny, {
|
|
257
|
+
created_at: string;
|
|
258
|
+
updated_at: string;
|
|
259
|
+
status: "active" | "archived";
|
|
260
|
+
id: number;
|
|
261
|
+
metadata: Record<string, any>;
|
|
262
|
+
tenant_id: number;
|
|
263
|
+
user_id: string;
|
|
264
|
+
agent_identifier?: string | null | undefined;
|
|
265
|
+
title?: string | null | undefined;
|
|
266
|
+
messages?: {
|
|
267
|
+
created_at: string;
|
|
268
|
+
updated_at: string;
|
|
269
|
+
id: number;
|
|
270
|
+
conversation_id: number;
|
|
271
|
+
sequence_number: number;
|
|
272
|
+
role: "user" | "assistant" | "system";
|
|
273
|
+
content: string;
|
|
274
|
+
metadata: Record<string, any>;
|
|
275
|
+
}[] | null | undefined;
|
|
276
|
+
}, {
|
|
277
|
+
created_at: string;
|
|
278
|
+
updated_at: string;
|
|
279
|
+
status: "active" | "archived";
|
|
280
|
+
id: number;
|
|
281
|
+
tenant_id: number;
|
|
282
|
+
user_id: string;
|
|
283
|
+
metadata?: Record<string, any> | undefined;
|
|
284
|
+
agent_identifier?: string | null | undefined;
|
|
285
|
+
title?: string | null | undefined;
|
|
286
|
+
messages?: {
|
|
287
|
+
created_at: string;
|
|
288
|
+
updated_at: string;
|
|
289
|
+
id: number;
|
|
290
|
+
conversation_id: number;
|
|
291
|
+
sequence_number: number;
|
|
292
|
+
role: "user" | "assistant" | "system";
|
|
293
|
+
content: string;
|
|
294
|
+
metadata?: Record<string, any> | undefined;
|
|
295
|
+
}[] | null | undefined;
|
|
296
|
+
}>;
|
|
297
|
+
/**
|
|
298
|
+
* Conversation type
|
|
299
|
+
*/
|
|
300
|
+
type Conversation = z.infer<typeof ConversationSchema>;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Create conversation request schema
|
|
304
|
+
*/
|
|
305
|
+
declare const CreateConversationRequestSchema: z.ZodObject<{
|
|
306
|
+
tenant_name: z.ZodString;
|
|
307
|
+
user_id: z.ZodString;
|
|
308
|
+
title: z.ZodOptional<z.ZodString>;
|
|
309
|
+
agent_identifier: z.ZodOptional<z.ZodString>;
|
|
310
|
+
status: z.ZodOptional<z.ZodEnum<["active", "archived"]>>;
|
|
311
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
312
|
+
}, "strip", z.ZodTypeAny, {
|
|
313
|
+
user_id: string;
|
|
314
|
+
tenant_name: string;
|
|
315
|
+
status?: "active" | "archived" | undefined;
|
|
316
|
+
metadata?: Record<string, any> | undefined;
|
|
317
|
+
agent_identifier?: string | undefined;
|
|
318
|
+
title?: string | undefined;
|
|
319
|
+
}, {
|
|
320
|
+
user_id: string;
|
|
321
|
+
tenant_name: string;
|
|
322
|
+
status?: "active" | "archived" | undefined;
|
|
323
|
+
metadata?: Record<string, any> | undefined;
|
|
324
|
+
agent_identifier?: string | undefined;
|
|
325
|
+
title?: string | undefined;
|
|
326
|
+
}>;
|
|
327
|
+
type CreateConversationRequest = z.infer<typeof CreateConversationRequestSchema>;
|
|
328
|
+
/**
|
|
329
|
+
* Update conversation request schema
|
|
330
|
+
*/
|
|
331
|
+
declare const UpdateConversationRequestSchema: z.ZodObject<{
|
|
332
|
+
user_id: z.ZodOptional<z.ZodString>;
|
|
333
|
+
title: z.ZodOptional<z.ZodString>;
|
|
334
|
+
status: z.ZodOptional<z.ZodEnum<["active", "archived"]>>;
|
|
335
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
336
|
+
}, "strip", z.ZodTypeAny, {
|
|
337
|
+
status?: "active" | "archived" | undefined;
|
|
338
|
+
metadata?: Record<string, any> | undefined;
|
|
339
|
+
user_id?: string | undefined;
|
|
340
|
+
title?: string | undefined;
|
|
341
|
+
}, {
|
|
342
|
+
status?: "active" | "archived" | undefined;
|
|
343
|
+
metadata?: Record<string, any> | undefined;
|
|
344
|
+
user_id?: string | undefined;
|
|
345
|
+
title?: string | undefined;
|
|
346
|
+
}>;
|
|
347
|
+
type UpdateConversationRequest = z.infer<typeof UpdateConversationRequestSchema>;
|
|
348
|
+
/**
|
|
349
|
+
* Create message request schema
|
|
350
|
+
*/
|
|
351
|
+
declare const CreateMessageRequestSchema: z.ZodObject<{
|
|
352
|
+
role: z.ZodEnum<["user", "assistant", "system"]>;
|
|
353
|
+
content: z.ZodString;
|
|
354
|
+
sequence_number: z.ZodOptional<z.ZodNumber>;
|
|
355
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
356
|
+
}, "strip", z.ZodTypeAny, {
|
|
357
|
+
role: "user" | "assistant" | "system";
|
|
358
|
+
content: string;
|
|
359
|
+
sequence_number?: number | undefined;
|
|
360
|
+
metadata?: Record<string, any> | undefined;
|
|
361
|
+
}, {
|
|
362
|
+
role: "user" | "assistant" | "system";
|
|
363
|
+
content: string;
|
|
364
|
+
sequence_number?: number | undefined;
|
|
365
|
+
metadata?: Record<string, any> | undefined;
|
|
366
|
+
}>;
|
|
367
|
+
type CreateMessageRequest = z.infer<typeof CreateMessageRequestSchema>;
|
|
368
|
+
/**
|
|
369
|
+
* Batch messages request schema
|
|
370
|
+
*/
|
|
371
|
+
declare const BatchMessagesRequestSchema: z.ZodObject<{
|
|
372
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
373
|
+
role: z.ZodEnum<["user", "assistant", "system"]>;
|
|
374
|
+
content: z.ZodString;
|
|
375
|
+
sequence_number: z.ZodOptional<z.ZodNumber>;
|
|
376
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
377
|
+
}, "strip", z.ZodTypeAny, {
|
|
378
|
+
role: "user" | "assistant" | "system";
|
|
379
|
+
content: string;
|
|
380
|
+
sequence_number?: number | undefined;
|
|
381
|
+
metadata?: Record<string, any> | undefined;
|
|
382
|
+
}, {
|
|
383
|
+
role: "user" | "assistant" | "system";
|
|
384
|
+
content: string;
|
|
385
|
+
sequence_number?: number | undefined;
|
|
386
|
+
metadata?: Record<string, any> | undefined;
|
|
387
|
+
}>, "many">;
|
|
388
|
+
}, "strip", z.ZodTypeAny, {
|
|
389
|
+
messages: {
|
|
390
|
+
role: "user" | "assistant" | "system";
|
|
391
|
+
content: string;
|
|
392
|
+
sequence_number?: number | undefined;
|
|
393
|
+
metadata?: Record<string, any> | undefined;
|
|
394
|
+
}[];
|
|
395
|
+
}, {
|
|
396
|
+
messages: {
|
|
397
|
+
role: "user" | "assistant" | "system";
|
|
398
|
+
content: string;
|
|
399
|
+
sequence_number?: number | undefined;
|
|
400
|
+
metadata?: Record<string, any> | undefined;
|
|
401
|
+
}[];
|
|
402
|
+
}>;
|
|
403
|
+
type BatchMessagesRequest = z.infer<typeof BatchMessagesRequestSchema>;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Container for a single page of results
|
|
407
|
+
*/
|
|
408
|
+
declare class Page<T> {
|
|
409
|
+
items: T[];
|
|
410
|
+
offset: number;
|
|
411
|
+
limit: number;
|
|
412
|
+
total: number | null;
|
|
413
|
+
hasMore: boolean;
|
|
414
|
+
constructor(items: T[], offset: number, limit: number, total?: number | null);
|
|
415
|
+
/**
|
|
416
|
+
* Make the page iterable
|
|
417
|
+
*/
|
|
418
|
+
[Symbol.iterator](): Iterator<T>;
|
|
419
|
+
/**
|
|
420
|
+
* Get the number of items in this page
|
|
421
|
+
*/
|
|
422
|
+
get length(): number;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Async paginator that automatically fetches pages and yields individual items
|
|
427
|
+
*/
|
|
428
|
+
declare class AsyncPaginator<T> {
|
|
429
|
+
private fetchPage;
|
|
430
|
+
private pageSize;
|
|
431
|
+
private maxItems;
|
|
432
|
+
private offset;
|
|
433
|
+
private totalFetched;
|
|
434
|
+
constructor(fetchPage: (offset: number, limit: number) => Promise<T[]>, pageSize?: number, maxItems?: number | null);
|
|
435
|
+
/**
|
|
436
|
+
* Make this class async iterable for use with "for await...of"
|
|
437
|
+
*/
|
|
438
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
439
|
+
/**
|
|
440
|
+
* Iterate over pages instead of individual items
|
|
441
|
+
*/
|
|
442
|
+
pages(): AsyncIterator<Page<T>>;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Tenant resource for managing tenants
|
|
447
|
+
*/
|
|
448
|
+
declare class TenantResource extends BaseResource {
|
|
449
|
+
/**
|
|
450
|
+
* List tenants with pagination
|
|
451
|
+
*/
|
|
452
|
+
list(params?: {
|
|
453
|
+
offset?: number;
|
|
454
|
+
limit?: number;
|
|
455
|
+
}): Promise<Tenant[]>;
|
|
456
|
+
/**
|
|
457
|
+
* List tenants with auto-pagination
|
|
458
|
+
*/
|
|
459
|
+
listIter(pageSize?: number, maxItems?: number | null): AsyncPaginator<Tenant>;
|
|
460
|
+
/**
|
|
461
|
+
* Get a tenant by ID
|
|
462
|
+
*/
|
|
463
|
+
getById(tenantId: number): Promise<Tenant>;
|
|
464
|
+
/**
|
|
465
|
+
* Get a tenant by name
|
|
466
|
+
*/
|
|
467
|
+
getByName(tenantName: string): Promise<Tenant>;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Parameters for creating a conversation
|
|
472
|
+
*/
|
|
473
|
+
interface CreateConversationParams {
|
|
474
|
+
tenant_name: string;
|
|
475
|
+
user_id: string;
|
|
476
|
+
title?: string;
|
|
477
|
+
agent_identifier?: string;
|
|
478
|
+
status?: ConversationStatus;
|
|
479
|
+
metadata?: Record<string, any>;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Parameters for listing conversations
|
|
483
|
+
*/
|
|
484
|
+
interface ListConversationsParams {
|
|
485
|
+
tenant_name?: string;
|
|
486
|
+
tenant_id?: number;
|
|
487
|
+
user_id?: string;
|
|
488
|
+
agent_identifier?: string;
|
|
489
|
+
status?: ConversationStatus;
|
|
490
|
+
offset?: number;
|
|
491
|
+
limit?: number;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Parameters for searching conversations
|
|
495
|
+
*/
|
|
496
|
+
interface SearchConversationsParams {
|
|
497
|
+
q?: string;
|
|
498
|
+
metadata_key?: string;
|
|
499
|
+
metadata_value?: string;
|
|
500
|
+
tenant_name?: string;
|
|
501
|
+
tenant_id?: number;
|
|
502
|
+
user_id?: string;
|
|
503
|
+
agent_identifier?: string;
|
|
504
|
+
status?: ConversationStatus;
|
|
505
|
+
offset?: number;
|
|
506
|
+
limit?: number;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Conversation resource for managing conversations
|
|
510
|
+
*/
|
|
511
|
+
declare class ConversationResource extends BaseResource {
|
|
512
|
+
/**
|
|
513
|
+
* Create a new conversation
|
|
514
|
+
*/
|
|
515
|
+
create(params: CreateConversationParams): Promise<Conversation>;
|
|
516
|
+
/**
|
|
517
|
+
* List conversations with optional filters
|
|
518
|
+
*/
|
|
519
|
+
list(params?: ListConversationsParams): Promise<Conversation[]>;
|
|
520
|
+
/**
|
|
521
|
+
* List conversations with auto-pagination
|
|
522
|
+
*/
|
|
523
|
+
listIter(params?: Omit<ListConversationsParams, 'offset' | 'limit'>, pageSize?: number, maxItems?: number | null): AsyncPaginator<Conversation>;
|
|
524
|
+
/**
|
|
525
|
+
* Get a conversation by ID
|
|
526
|
+
*/
|
|
527
|
+
getById(conversationId: number, includeMessages?: boolean): Promise<Conversation>;
|
|
528
|
+
/**
|
|
529
|
+
* Update a conversation
|
|
530
|
+
*/
|
|
531
|
+
update(conversationId: number, updates: {
|
|
532
|
+
user_id?: string;
|
|
533
|
+
title?: string;
|
|
534
|
+
status?: ConversationStatus;
|
|
535
|
+
metadata?: Record<string, any>;
|
|
536
|
+
}): Promise<Conversation>;
|
|
537
|
+
/**
|
|
538
|
+
* Archive a conversation
|
|
539
|
+
*/
|
|
540
|
+
archive(conversationId: number): Promise<Conversation>;
|
|
541
|
+
/**
|
|
542
|
+
* Unarchive a conversation
|
|
543
|
+
*/
|
|
544
|
+
unarchive(conversationId: number): Promise<Conversation>;
|
|
545
|
+
/**
|
|
546
|
+
* Delete a conversation
|
|
547
|
+
*/
|
|
548
|
+
deleteById(conversationId: number): Promise<void>;
|
|
549
|
+
/**
|
|
550
|
+
* Search conversations
|
|
551
|
+
*/
|
|
552
|
+
search(params?: SearchConversationsParams): Promise<Conversation[]>;
|
|
553
|
+
/**
|
|
554
|
+
* Search conversations with auto-pagination
|
|
555
|
+
*/
|
|
556
|
+
searchIter(params?: Omit<SearchConversationsParams, 'offset' | 'limit'>, pageSize?: number, maxItems?: number | null): AsyncPaginator<Conversation>;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Parameters for creating a message
|
|
561
|
+
*/
|
|
562
|
+
interface CreateMessageParams {
|
|
563
|
+
conversation_id: number;
|
|
564
|
+
role: MessageRole;
|
|
565
|
+
content: string;
|
|
566
|
+
sequence_number?: number;
|
|
567
|
+
metadata?: Record<string, any>;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Parameters for batch creating messages
|
|
571
|
+
*/
|
|
572
|
+
interface BatchCreateMessageParams {
|
|
573
|
+
role: MessageRole;
|
|
574
|
+
content: string;
|
|
575
|
+
sequence_number?: number;
|
|
576
|
+
metadata?: Record<string, any>;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Parameters for listing messages
|
|
580
|
+
*/
|
|
581
|
+
interface ListMessagesParams {
|
|
582
|
+
conversation_id: number;
|
|
583
|
+
role?: MessageRole;
|
|
584
|
+
offset?: number;
|
|
585
|
+
limit?: number;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Parameters for searching messages in a conversation
|
|
589
|
+
*/
|
|
590
|
+
interface SearchMessagesParams {
|
|
591
|
+
conversation_id: number;
|
|
592
|
+
q: string;
|
|
593
|
+
role?: MessageRole;
|
|
594
|
+
offset?: number;
|
|
595
|
+
limit?: number;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Parameters for searching messages globally
|
|
599
|
+
*/
|
|
600
|
+
interface SearchMessagesGlobalParams {
|
|
601
|
+
q: string;
|
|
602
|
+
conversation_id?: number;
|
|
603
|
+
role?: MessageRole;
|
|
604
|
+
offset?: number;
|
|
605
|
+
limit?: number;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Message resource for managing messages
|
|
609
|
+
*/
|
|
610
|
+
declare class MessageResource extends BaseResource {
|
|
611
|
+
/**
|
|
612
|
+
* Create a single message
|
|
613
|
+
*/
|
|
614
|
+
create(params: CreateMessageParams): Promise<Message>;
|
|
615
|
+
/**
|
|
616
|
+
* Batch create multiple messages
|
|
617
|
+
*/
|
|
618
|
+
createBatch(conversationId: number, messages: BatchCreateMessageParams[]): Promise<Message[]>;
|
|
619
|
+
/**
|
|
620
|
+
* List messages in a conversation
|
|
621
|
+
*/
|
|
622
|
+
list(params: ListMessagesParams): Promise<Message[]>;
|
|
623
|
+
/**
|
|
624
|
+
* List messages with auto-pagination
|
|
625
|
+
*/
|
|
626
|
+
listIter(params: Omit<ListMessagesParams, 'offset' | 'limit'>, pageSize?: number, maxItems?: number | null): AsyncPaginator<Message>;
|
|
627
|
+
/**
|
|
628
|
+
* Get a message by ID
|
|
629
|
+
*/
|
|
630
|
+
getById(messageId: number): Promise<Message>;
|
|
631
|
+
/**
|
|
632
|
+
* Search messages in a conversation
|
|
633
|
+
*/
|
|
634
|
+
search(params: SearchMessagesParams): Promise<Message[]>;
|
|
635
|
+
/**
|
|
636
|
+
* Search messages globally across all conversations
|
|
637
|
+
*/
|
|
638
|
+
searchGlobal(params: SearchMessagesGlobalParams): Promise<Message[]>;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Main client for the March History API
|
|
643
|
+
*
|
|
644
|
+
* Works in both Node.js and browser environments.
|
|
645
|
+
* Supports dual authentication: API key (backend) and JWT bearer token (frontend).
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* // Backend with API key
|
|
649
|
+
* const client = new MarchHistoryClient({
|
|
650
|
+
* baseUrl: 'http://localhost:8000',
|
|
651
|
+
* apiKey: 'your-api-key'
|
|
652
|
+
* });
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* // Frontend with JWT
|
|
656
|
+
* const client = new MarchHistoryClient({
|
|
657
|
+
* baseUrl: 'https://api.example.com',
|
|
658
|
+
* bearerToken: jwtToken
|
|
659
|
+
* });
|
|
660
|
+
*
|
|
661
|
+
* @example
|
|
662
|
+
* // Both API key and JWT
|
|
663
|
+
* const client = new MarchHistoryClient({
|
|
664
|
+
* baseUrl: 'https://api.example.com',
|
|
665
|
+
* apiKey: 'project-key',
|
|
666
|
+
* bearerToken: userJWT
|
|
667
|
+
* });
|
|
668
|
+
*/
|
|
669
|
+
declare class MarchHistoryClient {
|
|
670
|
+
/**
|
|
671
|
+
* Tenant resource for managing tenants
|
|
672
|
+
*/
|
|
673
|
+
readonly tenants: TenantResource;
|
|
674
|
+
/**
|
|
675
|
+
* Conversation resource for managing conversations
|
|
676
|
+
*/
|
|
677
|
+
readonly conversations: ConversationResource;
|
|
678
|
+
/**
|
|
679
|
+
* Message resource for managing messages
|
|
680
|
+
*/
|
|
681
|
+
readonly messages: MessageResource;
|
|
682
|
+
/**
|
|
683
|
+
* Create a new March History API client
|
|
684
|
+
*
|
|
685
|
+
* @param options - Client configuration options
|
|
686
|
+
*/
|
|
687
|
+
constructor(options?: MarchHistoryClientOptions);
|
|
688
|
+
/**
|
|
689
|
+
* Close all HTTP connections and cancel in-flight requests
|
|
690
|
+
*
|
|
691
|
+
* This is optional - connections are managed automatically.
|
|
692
|
+
* Use this for explicit cleanup when you're done with the client.
|
|
693
|
+
*/
|
|
694
|
+
close(): void;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Base error class for all March History SDK errors
|
|
699
|
+
*/
|
|
700
|
+
declare class MarchHistoryError extends Error {
|
|
701
|
+
constructor(message: string);
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Base class for API errors with HTTP status codes
|
|
705
|
+
*/
|
|
706
|
+
declare class APIError extends MarchHistoryError {
|
|
707
|
+
statusCode?: number;
|
|
708
|
+
responseBody: Record<string, any>;
|
|
709
|
+
errorCode?: string;
|
|
710
|
+
details: any[];
|
|
711
|
+
constructor(message: string, statusCode?: number, responseBody?: Record<string, any>);
|
|
712
|
+
toString(): string;
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* 400 Bad Request error
|
|
716
|
+
*/
|
|
717
|
+
declare class BadRequestError extends APIError {
|
|
718
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, any>);
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* 404 Not Found error
|
|
722
|
+
*/
|
|
723
|
+
declare class NotFoundError extends APIError {
|
|
724
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, any>);
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* 409 Conflict error (e.g., duplicate sequence number)
|
|
728
|
+
*/
|
|
729
|
+
declare class ConflictError extends APIError {
|
|
730
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, any>);
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* 422 Validation error (invalid request data)
|
|
734
|
+
*/
|
|
735
|
+
declare class ValidationError extends APIError {
|
|
736
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, any>);
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* 500+ Server error
|
|
740
|
+
*/
|
|
741
|
+
declare class ServerError extends APIError {
|
|
742
|
+
constructor(message: string, statusCode: number, responseBody: Record<string, any>);
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Network error (connection failed, timeout, etc.)
|
|
746
|
+
*/
|
|
747
|
+
declare class NetworkError extends MarchHistoryError {
|
|
748
|
+
constructor(message: string);
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Retry exhausted error (after max retries)
|
|
752
|
+
*/
|
|
753
|
+
declare class RetryError extends MarchHistoryError {
|
|
754
|
+
lastException: Error;
|
|
755
|
+
constructor(message: string, lastException: Error);
|
|
756
|
+
toString(): string;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
export { APIError, AsyncPaginator, BadRequestError, type BatchCreateMessageParams, type BatchMessagesRequest, type ClientConfig, ConflictError, type Conversation, ConversationSchema, ConversationStatus, type CreateConversationParams, type CreateConversationRequest, type CreateMessageParams, type CreateMessageRequest, DEFAULT_RETRY_CONFIG, type ListConversationsParams, type ListMessagesParams, MarchHistoryClient, type MarchHistoryClientOptions, MarchHistoryError, type Message, MessageRole, MessageSchema, NetworkError, NotFoundError, Page, type RetryConfig, RetryError, type SearchConversationsParams, type SearchMessagesGlobalParams, type SearchMessagesParams, ServerError, type Tenant, TenantSchema, type UpdateConversationRequest, ValidationError };
|