@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/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.content;
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
- const hasToolCalls = (chunk.tool_calls && chunk.tool_calls.length > 0) ?? false;
54
+ let hasToolCalls = false;
55
55
  const hasToolCallChunks = (chunk.tool_call_chunks && chunk.tool_call_chunks.length > 0) ?? false;
56
56
 
57
- if (hasToolCalls && chunk.tool_calls?.every((tc) => tc.id)) {
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 = !content || !content.length;
111
+ const isEmptyContent = typeof content === 'undefined' || !content.length || typeof content === 'string' && !content;
111
112
  const isEmptyChunk = isEmptyContent && !hasToolCallChunks;
112
- if (isEmptyChunk && chunk.id && chunk.id.startsWith('msg')) {
113
- if (graph.messageIdsByStepKey.has(chunk.id)) {
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(chunk.id)) {
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, chunk.id);
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 && chunk.tool_call_chunks?.length && typeof chunk.tool_call_chunks[0]?.index === 'number') {
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) {
@@ -124,6 +124,7 @@ export type StreamEvent = {
124
124
  export type GraphConfig = {
125
125
  provider: string;
126
126
  thread_id?: string;
127
+ run_id?: string;
127
128
  };
128
129
 
129
130
  export type PartMetadata = {
@@ -90,8 +90,8 @@ export type MessageCreationDetails = {
90
90
  };
91
91
  };
92
92
 
93
- export type ToolEndData = { input: string | Record<string, unknown>, output: ToolMessage };
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: AgentToolCall[]; // #new
125
+ tool_calls?: AgentToolCall[]; // #new
126
126
  };
127
127
 
128
128
  export type ToolCallDelta = {