@librechat/agents-types 2.4.0 → 2.4.1
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/package.json +1 -1
- package/stream.ts +111 -50
package/package.json
CHANGED
package/stream.ts
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
// src/types/stream.ts
|
2
2
|
import type OpenAITypes from 'openai';
|
3
|
-
import type {
|
3
|
+
import type {
|
4
|
+
MessageContentImageUrl,
|
5
|
+
MessageContentText,
|
6
|
+
ToolMessage,
|
7
|
+
BaseMessage,
|
8
|
+
} from '@langchain/core/messages';
|
4
9
|
import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
|
5
10
|
import type { LLMResult, Generation } from '@langchain/core/outputs';
|
6
11
|
import type { ToolEndEvent } from '@/types/tools';
|
7
12
|
import { StepTypes, ContentTypes, GraphEvents } from '@/common/enum';
|
8
13
|
|
9
|
-
export type HandleLLMEnd = (
|
14
|
+
export type HandleLLMEnd = (
|
15
|
+
output: LLMResult,
|
16
|
+
runId: string,
|
17
|
+
parentRunId?: string,
|
18
|
+
tags?: string[]
|
19
|
+
) => void;
|
10
20
|
|
11
21
|
export type MetadataAggregatorResult = {
|
12
22
|
handleLLMEnd: HandleLLMEnd;
|
@@ -15,7 +25,7 @@ export type MetadataAggregatorResult = {
|
|
15
25
|
|
16
26
|
export type StreamGeneration = Generation & {
|
17
27
|
text?: string;
|
18
|
-
message?: BaseMessage
|
28
|
+
message?: BaseMessage;
|
19
29
|
};
|
20
30
|
|
21
31
|
/** Event names are of the format: on_[runnable_type]_(start|stream|end).
|
@@ -58,10 +68,10 @@ export type RunStep = {
|
|
58
68
|
stepDetails: StepDetails;
|
59
69
|
usage?: null | object;
|
60
70
|
// {
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
71
|
+
// Define usage structure if it's ever non-null
|
72
|
+
// prompt_tokens: number; // #new
|
73
|
+
// completion_tokens: number; // #new
|
74
|
+
// total_tokens: number; // #new
|
65
75
|
// };
|
66
76
|
};
|
67
77
|
|
@@ -80,9 +90,7 @@ export interface RunStepDeltaEvent {
|
|
80
90
|
delta: ToolCallDelta;
|
81
91
|
}
|
82
92
|
|
83
|
-
export type StepDetails =
|
84
|
-
| MessageCreationDetails
|
85
|
-
| ToolCallsDetails;
|
93
|
+
export type StepDetails = MessageCreationDetails | ToolCallsDetails;
|
86
94
|
|
87
95
|
export type StepCompleted = ToolCallCompleted;
|
88
96
|
|
@@ -93,13 +101,19 @@ export type MessageCreationDetails = {
|
|
93
101
|
};
|
94
102
|
};
|
95
103
|
|
96
|
-
export type ToolEndData = {
|
104
|
+
export type ToolEndData = {
|
105
|
+
input: string | Record<string, unknown>;
|
106
|
+
output?: ToolMessage;
|
107
|
+
};
|
97
108
|
export type ToolErrorData = {
|
98
|
-
id: string
|
99
|
-
name: string
|
100
|
-
error?: Error
|
109
|
+
id: string;
|
110
|
+
name: string;
|
111
|
+
error?: Error;
|
101
112
|
} & Pick<ToolEndData, 'input'>;
|
102
|
-
export type ToolEndCallback = (
|
113
|
+
export type ToolEndCallback = (
|
114
|
+
data: ToolEndData,
|
115
|
+
metadata?: Record<string, unknown>
|
116
|
+
) => void;
|
103
117
|
|
104
118
|
export type ProcessedToolCall = {
|
105
119
|
name: string;
|
@@ -138,14 +152,16 @@ export type ToolCallDelta = {
|
|
138
152
|
tool_calls?: ToolCallChunk[]; // #new
|
139
153
|
};
|
140
154
|
|
141
|
-
export type AgentToolCall =
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
}
|
155
|
+
export type AgentToolCall =
|
156
|
+
| {
|
157
|
+
id: string; // #new
|
158
|
+
type: 'function'; // #new
|
159
|
+
function: {
|
160
|
+
name: string; // #new
|
161
|
+
arguments: string | object; // JSON string // #new
|
162
|
+
};
|
163
|
+
}
|
164
|
+
| ToolCall;
|
149
165
|
|
150
166
|
export interface ExtendedMessageContent {
|
151
167
|
type?: string;
|
@@ -162,7 +178,7 @@ export type AgentUpdate = {
|
|
162
178
|
index: number;
|
163
179
|
runId: string;
|
164
180
|
agentId: string;
|
165
|
-
}
|
181
|
+
};
|
166
182
|
};
|
167
183
|
|
168
184
|
/**
|
@@ -221,8 +237,12 @@ export interface ReasoningDelta {
|
|
221
237
|
content?: MessageContentComplex[];
|
222
238
|
}
|
223
239
|
|
224
|
-
export type MessageDeltaUpdate = {
|
225
|
-
|
240
|
+
export type MessageDeltaUpdate = {
|
241
|
+
type: ContentTypes.TEXT;
|
242
|
+
text: string;
|
243
|
+
tool_call_ids?: string[];
|
244
|
+
};
|
245
|
+
export type ReasoningDeltaUpdate = { type: ContentTypes.THINK; think: string };
|
226
246
|
|
227
247
|
export type ContentType = 'text' | 'image_url' | 'tool_call' | 'think' | string;
|
228
248
|
|
@@ -243,7 +263,7 @@ export type ThinkingContentText = {
|
|
243
263
|
export type BedrockReasoningContentText = {
|
244
264
|
type: ContentTypes.REASONING_CONTENT;
|
245
265
|
index?: number;
|
246
|
-
reasoningText: { text?: string; signature?: string
|
266
|
+
reasoningText: { text?: string; signature?: string };
|
247
267
|
};
|
248
268
|
|
249
269
|
/**
|
@@ -273,13 +293,22 @@ export type ToolCallContent = {
|
|
273
293
|
tool_call?: ToolCallPart;
|
274
294
|
};
|
275
295
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
296
|
+
export type MessageContentComplex = (
|
297
|
+
| ThinkingContentText
|
298
|
+
| AgentUpdate
|
299
|
+
| ToolCallContent
|
300
|
+
| ReasoningContentText
|
301
|
+
| MessageContentText
|
302
|
+
| MessageContentImageUrl
|
303
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
304
|
+
| (Record<string, any> & {
|
305
|
+
type?: 'text' | 'image_url' | 'think' | 'thinking' | string;
|
306
|
+
})
|
307
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
308
|
+
| (Record<string, any> & {
|
309
|
+
type?: never;
|
310
|
+
})
|
311
|
+
) & {
|
283
312
|
tool_call_ids?: string[];
|
284
313
|
};
|
285
314
|
|
@@ -291,29 +320,61 @@ export interface TMessage {
|
|
291
320
|
|
292
321
|
export type TPayload = Array<Partial<TMessage>>;
|
293
322
|
|
294
|
-
export type
|
295
|
-
|
296
|
-
|
323
|
+
export type CustomChunkDelta =
|
324
|
+
| null
|
325
|
+
| undefined
|
326
|
+
| (Partial<OpenAITypes.Chat.Completions.ChatCompletionChunk.Choice.Delta> & {
|
297
327
|
reasoning?: string | null;
|
298
328
|
reasoning_content?: string | null;
|
299
|
-
};
|
300
|
-
|
301
|
-
|
329
|
+
});
|
330
|
+
export type CustomChunkChoice = Partial<
|
331
|
+
Omit<OpenAITypes.Chat.Completions.ChatCompletionChunk.Choice, 'delta'> & {
|
332
|
+
delta?: CustomChunkDelta;
|
333
|
+
}
|
334
|
+
>;
|
335
|
+
export type CustomChunk = Partial<OpenAITypes.ChatCompletionChunk> & {
|
336
|
+
choices?: Partial<Array<CustomChunkChoice>>;
|
337
|
+
};
|
302
338
|
|
303
339
|
export type SplitStreamHandlers = Partial<{
|
304
|
-
[GraphEvents.ON_RUN_STEP]: ({
|
305
|
-
|
306
|
-
|
307
|
-
}
|
308
|
-
|
309
|
-
|
340
|
+
[GraphEvents.ON_RUN_STEP]: ({
|
341
|
+
event,
|
342
|
+
data,
|
343
|
+
}: {
|
344
|
+
event: GraphEvents;
|
345
|
+
data: RunStep;
|
346
|
+
}) => void;
|
347
|
+
[GraphEvents.ON_MESSAGE_DELTA]: ({
|
348
|
+
event,
|
349
|
+
data,
|
350
|
+
}: {
|
351
|
+
event: GraphEvents;
|
352
|
+
data: MessageDeltaEvent;
|
353
|
+
}) => void;
|
354
|
+
[GraphEvents.ON_REASONING_DELTA]: ({
|
355
|
+
event,
|
356
|
+
data,
|
357
|
+
}: {
|
358
|
+
event: GraphEvents;
|
359
|
+
data: ReasoningDeltaEvent;
|
360
|
+
}) => void;
|
361
|
+
}>;
|
362
|
+
|
363
|
+
export type ContentAggregator = ({
|
364
|
+
event,
|
365
|
+
data,
|
366
|
+
}: {
|
310
367
|
event: GraphEvents;
|
311
|
-
data:
|
312
|
-
|
313
|
-
|
368
|
+
data:
|
369
|
+
| RunStep
|
370
|
+
| MessageDeltaEvent
|
371
|
+
| RunStepDeltaEvent
|
372
|
+
| {
|
373
|
+
result: ToolEndEvent;
|
374
|
+
};
|
314
375
|
}) => void;
|
315
376
|
export type ContentAggregatorResult = {
|
316
377
|
stepMap: Map<string, RunStep | undefined>;
|
317
378
|
contentParts: Array<MessageContentComplex | undefined>;
|
318
379
|
aggregateContent: ContentAggregator;
|
319
|
-
};
|
380
|
+
};
|