@axiom-lattice/client-sdk 2.1.4 → 2.1.6
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/dist/ChunkMessageMerger.d.ts.map +1 -1
- package/dist/ChunkMessageMerger.js +32 -1
- package/dist/ChunkMessageMerger.js.map +1 -1
- package/dist/abstract-client.d.ts +80 -1
- package/dist/abstract-client.d.ts.map +1 -1
- package/dist/abstract-client.js +206 -19
- package/dist/abstract-client.js.map +1 -1
- package/dist/index.d.ts +248 -2
- package/dist/index.js +257 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +257 -20
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +168 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -80,6 +80,10 @@ interface Thread {
|
|
|
80
80
|
* Thread identifier
|
|
81
81
|
*/
|
|
82
82
|
id: string;
|
|
83
|
+
/**
|
|
84
|
+
* Assistant identifier this thread belongs to
|
|
85
|
+
*/
|
|
86
|
+
assistantId: string;
|
|
83
87
|
/**
|
|
84
88
|
* Thread metadata
|
|
85
89
|
*/
|
|
@@ -87,7 +91,11 @@ interface Thread {
|
|
|
87
91
|
/**
|
|
88
92
|
* Thread creation timestamp
|
|
89
93
|
*/
|
|
90
|
-
createdAt: string;
|
|
94
|
+
createdAt: Date | string;
|
|
95
|
+
/**
|
|
96
|
+
* Thread last update timestamp
|
|
97
|
+
*/
|
|
98
|
+
updatedAt: Date | string;
|
|
91
99
|
}
|
|
92
100
|
/**
|
|
93
101
|
* Chat send options
|
|
@@ -283,6 +291,7 @@ type RunOptions = {
|
|
|
283
291
|
* Agent state
|
|
284
292
|
*/
|
|
285
293
|
interface AgentState {
|
|
294
|
+
createdAt?: string;
|
|
286
295
|
values: {
|
|
287
296
|
messages: Message[];
|
|
288
297
|
[key: string]: any;
|
|
@@ -294,6 +303,164 @@ interface AgentState {
|
|
|
294
303
|
}>;
|
|
295
304
|
}>;
|
|
296
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Assistant information
|
|
308
|
+
*/
|
|
309
|
+
interface Assistant {
|
|
310
|
+
/**
|
|
311
|
+
* Assistant identifier
|
|
312
|
+
*/
|
|
313
|
+
id: string;
|
|
314
|
+
/**
|
|
315
|
+
* Assistant name
|
|
316
|
+
*/
|
|
317
|
+
name: string;
|
|
318
|
+
/**
|
|
319
|
+
* Assistant description (optional)
|
|
320
|
+
*/
|
|
321
|
+
description?: string;
|
|
322
|
+
/**
|
|
323
|
+
* Graph definition for the assistant
|
|
324
|
+
*/
|
|
325
|
+
graphDefinition: any;
|
|
326
|
+
/**
|
|
327
|
+
* Creation timestamp
|
|
328
|
+
*/
|
|
329
|
+
createdAt: Date | string;
|
|
330
|
+
/**
|
|
331
|
+
* Last update timestamp
|
|
332
|
+
*/
|
|
333
|
+
updatedAt: Date | string;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Create assistant request options
|
|
337
|
+
*/
|
|
338
|
+
interface CreateAssistantOptions {
|
|
339
|
+
/**
|
|
340
|
+
* Assistant name
|
|
341
|
+
*/
|
|
342
|
+
name: string;
|
|
343
|
+
/**
|
|
344
|
+
* Assistant description (optional)
|
|
345
|
+
*/
|
|
346
|
+
description?: string;
|
|
347
|
+
/**
|
|
348
|
+
* Graph definition for the assistant
|
|
349
|
+
*/
|
|
350
|
+
graphDefinition: any;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Update assistant request options
|
|
354
|
+
*/
|
|
355
|
+
interface UpdateAssistantOptions {
|
|
356
|
+
/**
|
|
357
|
+
* Assistant name (optional)
|
|
358
|
+
*/
|
|
359
|
+
name?: string;
|
|
360
|
+
/**
|
|
361
|
+
* Assistant description (optional)
|
|
362
|
+
*/
|
|
363
|
+
description?: string;
|
|
364
|
+
/**
|
|
365
|
+
* Graph definition for the assistant (optional)
|
|
366
|
+
*/
|
|
367
|
+
graphDefinition?: any;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Assistant list response
|
|
371
|
+
*/
|
|
372
|
+
interface AssistantListResponse {
|
|
373
|
+
/**
|
|
374
|
+
* Whether the operation was successful
|
|
375
|
+
*/
|
|
376
|
+
success: boolean;
|
|
377
|
+
/**
|
|
378
|
+
* Response message
|
|
379
|
+
*/
|
|
380
|
+
message: string;
|
|
381
|
+
/**
|
|
382
|
+
* Response data
|
|
383
|
+
*/
|
|
384
|
+
data: {
|
|
385
|
+
/**
|
|
386
|
+
* List of assistants
|
|
387
|
+
*/
|
|
388
|
+
records: Assistant[];
|
|
389
|
+
/**
|
|
390
|
+
* Total number of assistants
|
|
391
|
+
*/
|
|
392
|
+
total: number;
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Assistant response
|
|
397
|
+
*/
|
|
398
|
+
interface AssistantResponse {
|
|
399
|
+
/**
|
|
400
|
+
* Whether the operation was successful
|
|
401
|
+
*/
|
|
402
|
+
success: boolean;
|
|
403
|
+
/**
|
|
404
|
+
* Response message
|
|
405
|
+
*/
|
|
406
|
+
message: string;
|
|
407
|
+
/**
|
|
408
|
+
* Assistant data (optional)
|
|
409
|
+
*/
|
|
410
|
+
data?: Assistant;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Thread list response
|
|
414
|
+
*/
|
|
415
|
+
interface ThreadListResponse {
|
|
416
|
+
/**
|
|
417
|
+
* Whether the operation was successful
|
|
418
|
+
*/
|
|
419
|
+
success: boolean;
|
|
420
|
+
/**
|
|
421
|
+
* Response message
|
|
422
|
+
*/
|
|
423
|
+
message: string;
|
|
424
|
+
/**
|
|
425
|
+
* Response data
|
|
426
|
+
*/
|
|
427
|
+
data: {
|
|
428
|
+
/**
|
|
429
|
+
* List of threads
|
|
430
|
+
*/
|
|
431
|
+
records: Thread[];
|
|
432
|
+
/**
|
|
433
|
+
* Total number of threads
|
|
434
|
+
*/
|
|
435
|
+
total: number;
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Thread response
|
|
440
|
+
*/
|
|
441
|
+
interface ThreadResponse {
|
|
442
|
+
/**
|
|
443
|
+
* Whether the operation was successful
|
|
444
|
+
*/
|
|
445
|
+
success: boolean;
|
|
446
|
+
/**
|
|
447
|
+
* Response message
|
|
448
|
+
*/
|
|
449
|
+
message: string;
|
|
450
|
+
/**
|
|
451
|
+
* Thread data (optional)
|
|
452
|
+
*/
|
|
453
|
+
data?: Thread;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Update thread request options
|
|
457
|
+
*/
|
|
458
|
+
interface UpdateThreadOptions {
|
|
459
|
+
/**
|
|
460
|
+
* Thread metadata (optional)
|
|
461
|
+
*/
|
|
462
|
+
metadata?: Record<string, any>;
|
|
463
|
+
}
|
|
297
464
|
/**
|
|
298
465
|
* Custom error classes
|
|
299
466
|
*/
|
|
@@ -371,24 +538,28 @@ declare abstract class AbstractClient {
|
|
|
371
538
|
protected abstract streamRequest(options: RunOptions, onEvent: (event: MessageChunk) => void, onComplete?: (state?: AgentState) => void, onError?: (error: Error) => void): () => void;
|
|
372
539
|
/**
|
|
373
540
|
* Creates a new thread
|
|
541
|
+
* @deprecated Use threads.create() instead
|
|
374
542
|
* @param options - Options for creating a thread
|
|
375
543
|
* @returns A promise that resolves to the thread ID
|
|
376
544
|
*/
|
|
377
545
|
createThread(options: CreateThreadOptions): Promise<string>;
|
|
378
546
|
/**
|
|
379
547
|
* Retrieves thread information
|
|
548
|
+
* @deprecated Use threads.get() instead
|
|
380
549
|
* @param threadId - Thread identifier
|
|
381
550
|
* @returns A promise that resolves to the thread information
|
|
382
551
|
*/
|
|
383
552
|
getThread(threadId: string): Promise<Thread>;
|
|
384
553
|
/**
|
|
385
554
|
* Lists all threads
|
|
555
|
+
* @deprecated Use threads.list() instead
|
|
386
556
|
* @param options - Options for listing threads
|
|
387
557
|
* @returns A promise that resolves to an array of threads
|
|
388
558
|
*/
|
|
389
559
|
listThreads(options?: ListThreadsOptions): Promise<Thread[]>;
|
|
390
560
|
/**
|
|
391
561
|
* Deletes a thread
|
|
562
|
+
* @deprecated Use threads.delete() instead
|
|
392
563
|
* @param threadId - Thread identifier
|
|
393
564
|
* @returns A promise that resolves when the thread is deleted
|
|
394
565
|
*/
|
|
@@ -460,6 +631,81 @@ declare abstract class AbstractClient {
|
|
|
460
631
|
*/
|
|
461
632
|
unregister: (name: string) => void;
|
|
462
633
|
};
|
|
634
|
+
/**
|
|
635
|
+
* Assistants namespace for managing assistants
|
|
636
|
+
*/
|
|
637
|
+
assistants: {
|
|
638
|
+
/**
|
|
639
|
+
* Lists all available assistants
|
|
640
|
+
* Returns both code-configured and stored assistants
|
|
641
|
+
* @returns A promise that resolves to the list of assistants
|
|
642
|
+
*/
|
|
643
|
+
list: () => Promise<Assistant[]>;
|
|
644
|
+
/**
|
|
645
|
+
* Retrieves a single assistant by ID
|
|
646
|
+
* Checks both code-configured and stored assistants
|
|
647
|
+
* @param id - Assistant identifier
|
|
648
|
+
* @returns A promise that resolves to the assistant information
|
|
649
|
+
*/
|
|
650
|
+
get: (id: string) => Promise<Assistant>;
|
|
651
|
+
/**
|
|
652
|
+
* Creates a new assistant
|
|
653
|
+
* Only creates stored assistants (code-configured assistants cannot be created via API)
|
|
654
|
+
* @param options - Options for creating an assistant
|
|
655
|
+
* @returns A promise that resolves to the created assistant
|
|
656
|
+
*/
|
|
657
|
+
create: (options: CreateAssistantOptions) => Promise<Assistant>;
|
|
658
|
+
/**
|
|
659
|
+
* Updates an existing assistant by ID
|
|
660
|
+
* Only works on stored assistants (code-configured assistants cannot be updated)
|
|
661
|
+
* @param id - Assistant identifier
|
|
662
|
+
* @param options - Options for updating an assistant
|
|
663
|
+
* @returns A promise that resolves to the updated assistant
|
|
664
|
+
*/
|
|
665
|
+
update: (id: string, options: UpdateAssistantOptions) => Promise<Assistant>;
|
|
666
|
+
/**
|
|
667
|
+
* Deletes an assistant by ID
|
|
668
|
+
* Only works on stored assistants (code-configured assistants cannot be deleted)
|
|
669
|
+
* @param id - Assistant identifier
|
|
670
|
+
* @returns A promise that resolves when the assistant is deleted
|
|
671
|
+
*/
|
|
672
|
+
delete: (id: string) => Promise<void>;
|
|
673
|
+
};
|
|
674
|
+
/**
|
|
675
|
+
* Threads namespace for managing threads for the current assistant
|
|
676
|
+
*/
|
|
677
|
+
threads: {
|
|
678
|
+
/**
|
|
679
|
+
* Lists all threads for the current assistant
|
|
680
|
+
* @returns A promise that resolves to the list of threads
|
|
681
|
+
*/
|
|
682
|
+
list: () => Promise<Thread[]>;
|
|
683
|
+
/**
|
|
684
|
+
* Retrieves a single thread by ID for the current assistant
|
|
685
|
+
* @param threadId - Thread identifier
|
|
686
|
+
* @returns A promise that resolves to the thread information
|
|
687
|
+
*/
|
|
688
|
+
get: (threadId: string) => Promise<Thread>;
|
|
689
|
+
/**
|
|
690
|
+
* Creates a new thread for the current assistant
|
|
691
|
+
* @param options - Options for creating a thread
|
|
692
|
+
* @returns A promise that resolves to the created thread
|
|
693
|
+
*/
|
|
694
|
+
create: (options: CreateThreadOptions) => Promise<Thread>;
|
|
695
|
+
/**
|
|
696
|
+
* Updates an existing thread by ID for the current assistant
|
|
697
|
+
* @param threadId - Thread identifier
|
|
698
|
+
* @param options - Options for updating a thread
|
|
699
|
+
* @returns A promise that resolves to the updated thread
|
|
700
|
+
*/
|
|
701
|
+
update: (threadId: string, options: UpdateThreadOptions) => Promise<Thread>;
|
|
702
|
+
/**
|
|
703
|
+
* Deletes a thread by ID for the current assistant
|
|
704
|
+
* @param threadId - Thread identifier
|
|
705
|
+
* @returns A promise that resolves when the thread is deleted
|
|
706
|
+
*/
|
|
707
|
+
delete: (threadId: string) => Promise<void>;
|
|
708
|
+
};
|
|
463
709
|
}
|
|
464
710
|
|
|
465
711
|
/**
|
|
@@ -615,4 +861,4 @@ declare function createSimpleMessageMerger(): {
|
|
|
615
861
|
reset: () => void;
|
|
616
862
|
};
|
|
617
863
|
|
|
618
|
-
export { AbstractClient, AgentState, ApiError, AuthenticationError, ChatResponse, ChatSendOptions, ChatStreamOptions, Client, ClientConfig, CreateThreadOptions, GetMessagesOptions, ListThreadsOptions, NetworkError, RegisterToolOptions, ResumeStreamOptions, RetryConfig, RunOptions, StreamCallbacks, Thread, Transport, WeChatClient, createSimpleMessageMerger };
|
|
864
|
+
export { AbstractClient, AgentState, ApiError, Assistant, AssistantListResponse, AssistantResponse, AuthenticationError, ChatResponse, ChatSendOptions, ChatStreamOptions, Client, ClientConfig, CreateAssistantOptions, CreateThreadOptions, GetMessagesOptions, ListThreadsOptions, NetworkError, RegisterToolOptions, ResumeStreamOptions, RetryConfig, RunOptions, StreamCallbacks, Thread, ThreadListResponse, ThreadResponse, Transport, UpdateAssistantOptions, UpdateThreadOptions, WeChatClient, createSimpleMessageMerger };
|
package/dist/index.js
CHANGED
|
@@ -1955,6 +1955,209 @@ var AbstractClient = class {
|
|
|
1955
1955
|
this.registeredTools.delete(name);
|
|
1956
1956
|
}
|
|
1957
1957
|
};
|
|
1958
|
+
/**
|
|
1959
|
+
* Assistants namespace for managing assistants
|
|
1960
|
+
*/
|
|
1961
|
+
this.assistants = {
|
|
1962
|
+
/**
|
|
1963
|
+
* Lists all available assistants
|
|
1964
|
+
* Returns both code-configured and stored assistants
|
|
1965
|
+
* @returns A promise that resolves to the list of assistants
|
|
1966
|
+
*/
|
|
1967
|
+
list: async () => {
|
|
1968
|
+
try {
|
|
1969
|
+
const response = await this.makeRequest(
|
|
1970
|
+
"/api/assistants"
|
|
1971
|
+
);
|
|
1972
|
+
return response.data.records;
|
|
1973
|
+
} catch (error) {
|
|
1974
|
+
throw error;
|
|
1975
|
+
}
|
|
1976
|
+
},
|
|
1977
|
+
/**
|
|
1978
|
+
* Retrieves a single assistant by ID
|
|
1979
|
+
* Checks both code-configured and stored assistants
|
|
1980
|
+
* @param id - Assistant identifier
|
|
1981
|
+
* @returns A promise that resolves to the assistant information
|
|
1982
|
+
*/
|
|
1983
|
+
get: async (id) => {
|
|
1984
|
+
try {
|
|
1985
|
+
const response = await this.makeRequest(
|
|
1986
|
+
`/api/assistants/${id}`
|
|
1987
|
+
);
|
|
1988
|
+
if (!response.data) {
|
|
1989
|
+
throw new ApiError("Assistant not found", 404);
|
|
1990
|
+
}
|
|
1991
|
+
return response.data;
|
|
1992
|
+
} catch (error) {
|
|
1993
|
+
throw error;
|
|
1994
|
+
}
|
|
1995
|
+
},
|
|
1996
|
+
/**
|
|
1997
|
+
* Creates a new assistant
|
|
1998
|
+
* Only creates stored assistants (code-configured assistants cannot be created via API)
|
|
1999
|
+
* @param options - Options for creating an assistant
|
|
2000
|
+
* @returns A promise that resolves to the created assistant
|
|
2001
|
+
*/
|
|
2002
|
+
create: async (options) => {
|
|
2003
|
+
try {
|
|
2004
|
+
const response = await this.makeRequest(
|
|
2005
|
+
"/api/assistants",
|
|
2006
|
+
{
|
|
2007
|
+
method: "POST",
|
|
2008
|
+
body: options
|
|
2009
|
+
}
|
|
2010
|
+
);
|
|
2011
|
+
if (!response.data) {
|
|
2012
|
+
throw new ApiError("Failed to create assistant", 500);
|
|
2013
|
+
}
|
|
2014
|
+
return response.data;
|
|
2015
|
+
} catch (error) {
|
|
2016
|
+
throw error;
|
|
2017
|
+
}
|
|
2018
|
+
},
|
|
2019
|
+
/**
|
|
2020
|
+
* Updates an existing assistant by ID
|
|
2021
|
+
* Only works on stored assistants (code-configured assistants cannot be updated)
|
|
2022
|
+
* @param id - Assistant identifier
|
|
2023
|
+
* @param options - Options for updating an assistant
|
|
2024
|
+
* @returns A promise that resolves to the updated assistant
|
|
2025
|
+
*/
|
|
2026
|
+
update: async (id, options) => {
|
|
2027
|
+
try {
|
|
2028
|
+
const response = await this.makeRequest(
|
|
2029
|
+
`/api/assistants/${id}`,
|
|
2030
|
+
{
|
|
2031
|
+
method: "PUT",
|
|
2032
|
+
body: options
|
|
2033
|
+
}
|
|
2034
|
+
);
|
|
2035
|
+
if (!response.data) {
|
|
2036
|
+
throw new ApiError("Failed to update assistant", 500);
|
|
2037
|
+
}
|
|
2038
|
+
return response.data;
|
|
2039
|
+
} catch (error) {
|
|
2040
|
+
throw error;
|
|
2041
|
+
}
|
|
2042
|
+
},
|
|
2043
|
+
/**
|
|
2044
|
+
* Deletes an assistant by ID
|
|
2045
|
+
* Only works on stored assistants (code-configured assistants cannot be deleted)
|
|
2046
|
+
* @param id - Assistant identifier
|
|
2047
|
+
* @returns A promise that resolves when the assistant is deleted
|
|
2048
|
+
*/
|
|
2049
|
+
delete: async (id) => {
|
|
2050
|
+
try {
|
|
2051
|
+
await this.makeRequest(
|
|
2052
|
+
`/api/assistants/${id}`,
|
|
2053
|
+
{
|
|
2054
|
+
method: "DELETE"
|
|
2055
|
+
}
|
|
2056
|
+
);
|
|
2057
|
+
} catch (error) {
|
|
2058
|
+
throw error;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
};
|
|
2062
|
+
/**
|
|
2063
|
+
* Threads namespace for managing threads for the current assistant
|
|
2064
|
+
*/
|
|
2065
|
+
this.threads = {
|
|
2066
|
+
/**
|
|
2067
|
+
* Lists all threads for the current assistant
|
|
2068
|
+
* @returns A promise that resolves to the list of threads
|
|
2069
|
+
*/
|
|
2070
|
+
list: async () => {
|
|
2071
|
+
try {
|
|
2072
|
+
const response = await this.makeRequest(
|
|
2073
|
+
`/api/assistants/${this.assistantId}/threads`
|
|
2074
|
+
);
|
|
2075
|
+
return response.data.records;
|
|
2076
|
+
} catch (error) {
|
|
2077
|
+
throw error;
|
|
2078
|
+
}
|
|
2079
|
+
},
|
|
2080
|
+
/**
|
|
2081
|
+
* Retrieves a single thread by ID for the current assistant
|
|
2082
|
+
* @param threadId - Thread identifier
|
|
2083
|
+
* @returns A promise that resolves to the thread information
|
|
2084
|
+
*/
|
|
2085
|
+
get: async (threadId) => {
|
|
2086
|
+
try {
|
|
2087
|
+
const response = await this.makeRequest(
|
|
2088
|
+
`/api/assistants/${this.assistantId}/threads/${threadId}`
|
|
2089
|
+
);
|
|
2090
|
+
if (!response.data) {
|
|
2091
|
+
throw new ApiError("Thread not found", 404);
|
|
2092
|
+
}
|
|
2093
|
+
return response.data;
|
|
2094
|
+
} catch (error) {
|
|
2095
|
+
throw error;
|
|
2096
|
+
}
|
|
2097
|
+
},
|
|
2098
|
+
/**
|
|
2099
|
+
* Creates a new thread for the current assistant
|
|
2100
|
+
* @param options - Options for creating a thread
|
|
2101
|
+
* @returns A promise that resolves to the created thread
|
|
2102
|
+
*/
|
|
2103
|
+
create: async (options) => {
|
|
2104
|
+
try {
|
|
2105
|
+
const response = await this.makeRequest(
|
|
2106
|
+
`/api/assistants/${this.assistantId}/threads`,
|
|
2107
|
+
{
|
|
2108
|
+
method: "POST",
|
|
2109
|
+
body: options
|
|
2110
|
+
}
|
|
2111
|
+
);
|
|
2112
|
+
if (!response.data) {
|
|
2113
|
+
throw new ApiError("Failed to create thread", 500);
|
|
2114
|
+
}
|
|
2115
|
+
return response.data;
|
|
2116
|
+
} catch (error) {
|
|
2117
|
+
throw error;
|
|
2118
|
+
}
|
|
2119
|
+
},
|
|
2120
|
+
/**
|
|
2121
|
+
* Updates an existing thread by ID for the current assistant
|
|
2122
|
+
* @param threadId - Thread identifier
|
|
2123
|
+
* @param options - Options for updating a thread
|
|
2124
|
+
* @returns A promise that resolves to the updated thread
|
|
2125
|
+
*/
|
|
2126
|
+
update: async (threadId, options) => {
|
|
2127
|
+
try {
|
|
2128
|
+
const response = await this.makeRequest(
|
|
2129
|
+
`/api/assistants/${this.assistantId}/threads/${threadId}`,
|
|
2130
|
+
{
|
|
2131
|
+
method: "PUT",
|
|
2132
|
+
body: options
|
|
2133
|
+
}
|
|
2134
|
+
);
|
|
2135
|
+
if (!response.data) {
|
|
2136
|
+
throw new ApiError("Failed to update thread", 500);
|
|
2137
|
+
}
|
|
2138
|
+
return response.data;
|
|
2139
|
+
} catch (error) {
|
|
2140
|
+
throw error;
|
|
2141
|
+
}
|
|
2142
|
+
},
|
|
2143
|
+
/**
|
|
2144
|
+
* Deletes a thread by ID for the current assistant
|
|
2145
|
+
* @param threadId - Thread identifier
|
|
2146
|
+
* @returns A promise that resolves when the thread is deleted
|
|
2147
|
+
*/
|
|
2148
|
+
delete: async (threadId) => {
|
|
2149
|
+
try {
|
|
2150
|
+
await this.makeRequest(
|
|
2151
|
+
`/api/assistants/${this.assistantId}/threads/${threadId}`,
|
|
2152
|
+
{
|
|
2153
|
+
method: "DELETE"
|
|
2154
|
+
}
|
|
2155
|
+
);
|
|
2156
|
+
} catch (error) {
|
|
2157
|
+
throw error;
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
};
|
|
1958
2161
|
this.config = {
|
|
1959
2162
|
timeout: 3e5,
|
|
1960
2163
|
// Default timeout
|
|
@@ -2017,65 +2220,74 @@ var AbstractClient = class {
|
|
|
2017
2220
|
}
|
|
2018
2221
|
/**
|
|
2019
2222
|
* Creates a new thread
|
|
2223
|
+
* @deprecated Use threads.create() instead
|
|
2020
2224
|
* @param options - Options for creating a thread
|
|
2021
2225
|
* @returns A promise that resolves to the thread ID
|
|
2022
2226
|
*/
|
|
2023
2227
|
async createThread(options) {
|
|
2024
2228
|
try {
|
|
2025
|
-
const
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2229
|
+
const response = await this.makeRequest(
|
|
2230
|
+
`/api/assistants/${this.assistantId}/threads`,
|
|
2231
|
+
{
|
|
2232
|
+
method: "POST",
|
|
2233
|
+
body: options
|
|
2030
2234
|
}
|
|
2031
|
-
|
|
2032
|
-
|
|
2235
|
+
);
|
|
2236
|
+
if (!response.data) {
|
|
2237
|
+
throw new ApiError("Failed to create thread", 500);
|
|
2238
|
+
}
|
|
2239
|
+
return response.data.id;
|
|
2033
2240
|
} catch (error) {
|
|
2034
2241
|
throw error;
|
|
2035
2242
|
}
|
|
2036
2243
|
}
|
|
2037
2244
|
/**
|
|
2038
2245
|
* Retrieves thread information
|
|
2246
|
+
* @deprecated Use threads.get() instead
|
|
2039
2247
|
* @param threadId - Thread identifier
|
|
2040
2248
|
* @returns A promise that resolves to the thread information
|
|
2041
2249
|
*/
|
|
2042
2250
|
async getThread(threadId) {
|
|
2043
2251
|
try {
|
|
2044
|
-
const
|
|
2045
|
-
|
|
2252
|
+
const response = await this.makeRequest(
|
|
2253
|
+
`/api/assistants/${this.assistantId}/threads/${threadId}`
|
|
2254
|
+
);
|
|
2255
|
+
if (!response.data) {
|
|
2256
|
+
throw new ApiError("Thread not found", 404);
|
|
2257
|
+
}
|
|
2258
|
+
return response.data;
|
|
2046
2259
|
} catch (error) {
|
|
2047
2260
|
throw error;
|
|
2048
2261
|
}
|
|
2049
2262
|
}
|
|
2050
2263
|
/**
|
|
2051
2264
|
* Lists all threads
|
|
2265
|
+
* @deprecated Use threads.list() instead
|
|
2052
2266
|
* @param options - Options for listing threads
|
|
2053
2267
|
* @returns A promise that resolves to an array of threads
|
|
2054
2268
|
*/
|
|
2055
2269
|
async listThreads(options) {
|
|
2056
2270
|
try {
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
if (options?.offset !== void 0) {
|
|
2062
|
-
url += `&offset=${options.offset}`;
|
|
2063
|
-
}
|
|
2064
|
-
const data = await this.makeRequest(url);
|
|
2065
|
-
return data.threads;
|
|
2271
|
+
const response = await this.makeRequest(
|
|
2272
|
+
`/api/assistants/${this.assistantId}/threads`
|
|
2273
|
+
);
|
|
2274
|
+
return response.data.records;
|
|
2066
2275
|
} catch (error) {
|
|
2067
2276
|
throw error;
|
|
2068
2277
|
}
|
|
2069
2278
|
}
|
|
2070
2279
|
/**
|
|
2071
2280
|
* Deletes a thread
|
|
2281
|
+
* @deprecated Use threads.delete() instead
|
|
2072
2282
|
* @param threadId - Thread identifier
|
|
2073
2283
|
* @returns A promise that resolves when the thread is deleted
|
|
2074
2284
|
*/
|
|
2075
2285
|
async deleteThread(threadId) {
|
|
2076
2286
|
try {
|
|
2077
|
-
|
|
2078
|
-
|
|
2287
|
+
await this.makeRequest(
|
|
2288
|
+
`/api/assistants/${this.assistantId}/threads/${threadId}`,
|
|
2289
|
+
{ method: "DELETE" }
|
|
2290
|
+
);
|
|
2079
2291
|
} catch (error) {
|
|
2080
2292
|
throw error;
|
|
2081
2293
|
}
|
|
@@ -2840,6 +3052,31 @@ function createSimpleMessageMerger() {
|
|
|
2840
3052
|
}
|
|
2841
3053
|
function initialMessages(msgs) {
|
|
2842
3054
|
messages = msgs;
|
|
3055
|
+
messageMap.clear();
|
|
3056
|
+
messages.forEach((msg, index) => {
|
|
3057
|
+
if (msg.id) {
|
|
3058
|
+
messageMap.set(msg.id, index);
|
|
3059
|
+
}
|
|
3060
|
+
});
|
|
3061
|
+
toolBuilders.clear();
|
|
3062
|
+
messages.forEach((msg) => {
|
|
3063
|
+
if (msg.role === "ai" && msg.tool_calls && Array.isArray(msg.tool_calls)) {
|
|
3064
|
+
const builders = /* @__PURE__ */ new Map();
|
|
3065
|
+
msg.tool_calls.forEach((toolCall, index) => {
|
|
3066
|
+
if (toolCall.id && toolCall.name) {
|
|
3067
|
+
const argsStr = typeof toolCall.args === "object" ? JSON.stringify(toolCall.args) : String(toolCall.args || "");
|
|
3068
|
+
builders.set(index, {
|
|
3069
|
+
id: toolCall.id,
|
|
3070
|
+
name: toolCall.name,
|
|
3071
|
+
args: argsStr
|
|
3072
|
+
});
|
|
3073
|
+
}
|
|
3074
|
+
});
|
|
3075
|
+
if (builders.size > 0) {
|
|
3076
|
+
toolBuilders.set(msg.id, builders);
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
});
|
|
2843
3080
|
}
|
|
2844
3081
|
function push(chunk) {
|
|
2845
3082
|
const role = normalizeRole(chunk.type);
|