@librechat/agents 1.6.4 → 1.6.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/cjs/events.cjs +1 -1
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +4 -3
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/run.cjs +13 -3
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +15 -10
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/esm/events.mjs +1 -1
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +4 -3
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/run.mjs +13 -3
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +15 -10
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/types/run.d.ts +2 -1
- package/dist/types/types/graph.d.ts +1 -0
- package/dist/types/types/stream.d.ts +3 -3
- package/package.json +1 -1
- package/src/events.ts +1 -1
- package/src/graphs/Graph.ts +6 -4
- package/src/run.ts +19 -4
- package/src/scripts/code_exec_simple.ts +1 -0
- package/src/stream.ts +16 -11
- package/src/types/graph.ts +1 -0
- package/src/types/stream.ts +3 -3
package/src/stream.ts
CHANGED
|
@@ -39,8 +39,8 @@ export class ChatModelStreamHandler implements t.EventHandler {
|
|
|
39
39
|
throw new Error('Graph not found');
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
const chunk = data.chunk as AIMessageChunk;
|
|
43
|
-
const content = chunk
|
|
42
|
+
const chunk = data.chunk as AIMessageChunk | undefined;
|
|
43
|
+
const content = chunk?.content;
|
|
44
44
|
|
|
45
45
|
if (!graph.config) {
|
|
46
46
|
throw new Error('Config not found in graph');
|
|
@@ -51,10 +51,11 @@ export class ChatModelStreamHandler implements t.EventHandler {
|
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
let hasToolCalls = false;
|
|
55
55
|
const hasToolCallChunks = (chunk.tool_call_chunks && chunk.tool_call_chunks.length > 0) ?? false;
|
|
56
56
|
|
|
57
|
-
if (
|
|
57
|
+
if (chunk.tool_calls && chunk.tool_calls.length > 0 && chunk.tool_calls.every((tc) => tc.id)) {
|
|
58
|
+
hasToolCalls = true;
|
|
58
59
|
const tool_calls: ToolCall[] = [];
|
|
59
60
|
const tool_call_ids: string[] = [];
|
|
60
61
|
for (const tool_call of chunk.tool_calls) {
|
|
@@ -107,17 +108,18 @@ export class ChatModelStreamHandler implements t.EventHandler {
|
|
|
107
108
|
});
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
const isEmptyContent =
|
|
111
|
+
const isEmptyContent = typeof content === 'undefined' || !content.length || typeof content === 'string' && !content;
|
|
111
112
|
const isEmptyChunk = isEmptyContent && !hasToolCallChunks;
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
const chunkId = chunk.id ?? '';
|
|
114
|
+
if (isEmptyChunk && chunkId && chunkId.startsWith('msg')) {
|
|
115
|
+
if (graph.messageIdsByStepKey.has(chunkId)) {
|
|
114
116
|
return;
|
|
115
|
-
} else if (graph.prelimMessageIdsByStepKey.has(
|
|
117
|
+
} else if (graph.prelimMessageIdsByStepKey.has(chunkId)) {
|
|
116
118
|
return;
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
const stepKey = graph.getStepKey(metadata);
|
|
120
|
-
graph.prelimMessageIdsByStepKey.set(stepKey,
|
|
122
|
+
graph.prelimMessageIdsByStepKey.set(stepKey, chunkId);
|
|
121
123
|
return;
|
|
122
124
|
} else if (isEmptyChunk) {
|
|
123
125
|
return;
|
|
@@ -125,7 +127,10 @@ export class ChatModelStreamHandler implements t.EventHandler {
|
|
|
125
127
|
|
|
126
128
|
const stepKey = graph.getStepKey(metadata);
|
|
127
129
|
|
|
128
|
-
if (hasToolCallChunks
|
|
130
|
+
if (hasToolCallChunks
|
|
131
|
+
&& chunk.tool_call_chunks
|
|
132
|
+
&& chunk.tool_call_chunks.length
|
|
133
|
+
&& typeof chunk.tool_call_chunks[0]?.index === 'number') {
|
|
129
134
|
const prevStepId = graph.getStepIdByKey(stepKey, graph.contentData.length - 1);
|
|
130
135
|
const prevRunStep = graph.getRunStep(prevStepId);
|
|
131
136
|
const stepId = graph.getStepIdByKey(stepKey, prevRunStep?.index);
|
|
@@ -287,7 +292,7 @@ export function createContentAggregator(): ContentAggregatorResult {
|
|
|
287
292
|
stepMap.set(runStep.id, runStep);
|
|
288
293
|
|
|
289
294
|
// Store tool call IDs if present
|
|
290
|
-
if (runStep.stepDetails.type === StepTypes.TOOL_CALLS) {
|
|
295
|
+
if (runStep.stepDetails.type === StepTypes.TOOL_CALLS && runStep.stepDetails.tool_calls) {
|
|
291
296
|
runStep.stepDetails.tool_calls.forEach((toolCall) => {
|
|
292
297
|
const toolCallId = toolCall.id ?? '';
|
|
293
298
|
if ('id' in toolCall && toolCallId) {
|
package/src/types/graph.ts
CHANGED
package/src/types/stream.ts
CHANGED
|
@@ -90,8 +90,8 @@ export type MessageCreationDetails = {
|
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
export type ToolEndData = { input: string | Record<string, unknown>, output
|
|
94
|
-
export type ToolEndCallback = (data: ToolEndData) => void;
|
|
93
|
+
export type ToolEndData = { input: string | Record<string, unknown>, output?: ToolMessage };
|
|
94
|
+
export type ToolEndCallback = (data: ToolEndData, metadata?: Record<string, unknown>) => void;
|
|
95
95
|
|
|
96
96
|
export type ProcessedToolCall = {
|
|
97
97
|
name: string;
|
|
@@ -122,7 +122,7 @@ export type ToolCompleteEvent = ToolCallCompleted & {
|
|
|
122
122
|
|
|
123
123
|
export type ToolCallsDetails = {
|
|
124
124
|
type: StepTypes.TOOL_CALLS;
|
|
125
|
-
tool_calls
|
|
125
|
+
tool_calls?: AgentToolCall[]; // #new
|
|
126
126
|
};
|
|
127
127
|
|
|
128
128
|
export type ToolCallDelta = {
|