From 206ef476f652d89a8291003eaeb29a436f3f32e4 Mon Sep 17 00:00:00 2001 From: Lia Date: Wed, 30 Sep 2026 01:41:15 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9B=B4=EF=B8=8F=20fix:=20Align=20Canary=20Ti?= =?UTF-8?q?ming=20Types=20and=20CI=20Formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 5bd84bb6273aeeecf4e3dd6e21a4a9d0141ae2f1) Original-PR: https://github.com/LibreChat-AI/LibreChat/pull/16457 --- .../src/components/Auth/TwoFactorScreen.tsx | 2 +- .../Chat/Input/InterruptSteerButton.tsx | 2 +- .../Messages/Content/ActivityPhaseGroup.tsx | 11 ++- .../components/Chat/Messages/Content/Part.tsx | 2 +- .../Chat/Messages/Content/ProgressText.tsx | 24 ++++-- .../Chat/Messages/Content/ToolCall.tsx | 2 +- .../Chat/Messages/Content/ToolCallGroup.tsx | 77 +++++++++++++---- .../Chat/Messages/Content/reveal.tsx | 2 +- .../SidePanel/Agents/MCPToolItem.tsx | 2 +- .../Tools/ItemDialog/sections/McpSection.tsx | 4 +- client/src/hooks/SSE/__tests__/steps.spec.ts | 84 +++++++++++++++++++ client/src/hooks/SSE/steps/content.ts | 4 +- client/src/hooks/SSE/steps/tools.ts | 6 ++ 13 files changed, 186 insertions(+), 36 deletions(-) diff --git a/client/src/components/Auth/TwoFactorScreen.tsx b/client/src/components/Auth/TwoFactorScreen.tsx index 8e543a4b44..ffb8772aad 100644 --- a/client/src/components/Auth/TwoFactorScreen.tsx +++ b/client/src/components/Auth/TwoFactorScreen.tsx @@ -86,7 +86,7 @@ const TwoFactorScreen: React.FC = React.memo(() => { return (
-
{showOAuth && (
-
+
diff --git a/client/src/components/SidePanel/Agents/Tools/ItemDialog/sections/McpSection.tsx b/client/src/components/SidePanel/Agents/Tools/ItemDialog/sections/McpSection.tsx index 8c13d1237f..44796ed4c7 100644 --- a/client/src/components/SidePanel/Agents/Tools/ItemDialog/sections/McpSection.tsx +++ b/client/src/components/SidePanel/Agents/Tools/ItemDialog/sections/McpSection.tsx @@ -440,7 +440,7 @@ export default function McpSection({ item }: Props) { return (
{item.description && ( -

+

{item.description}

)} @@ -489,7 +489,7 @@ export default function McpSection({ item }: Props) {
- + {localize('com_ui_tools_mcp_tools_section')} {(hasTools || runtimeToolsAvailable) && ( diff --git a/client/src/hooks/SSE/__tests__/steps.spec.ts b/client/src/hooks/SSE/__tests__/steps.spec.ts index 00279a944a..3a4a6057a7 100644 --- a/client/src/hooks/SSE/__tests__/steps.spec.ts +++ b/client/src/hooks/SSE/__tests__/steps.spec.ts @@ -457,6 +457,90 @@ describe('steps', () => { expect(replayed.message.content).toEqual(closed.content); }); + it('retains existing timing metadata when a delta and closure omit new timing', () => { + const stamps = { toolPreparationStartedAt: 1_000, toolDispatchedAt: 1_100 }; + const opened = applyToolCallsStep(createResponse(), search, 0, () => stamps).message; + const streamed = applyToolCallDelta( + opened, + search, + argsDelta(search.id, '{}'), + 'call-1', + 0, + ) as TMessage; + const closed = applyRunStepClosed( + streamed, + search, + { + id: search.id, + index: 1, + type: StepTypes.TOOL_CALLS, + status: 'completed', + created_at: 1_000, + closed_at: 1_250, + }, + 0, + ); + expect(closed?.content?.[1]).toMatchObject({ + tool_call: { + ...stamps, + args: '{}', + runStepStatus: 'completed', + runStepDurationMs: 250, + runStepClosedAt: 1_250, + }, + }); + expect(closed?.content?.[1]).not.toHaveProperty('tool_call.toolPreparationDurationMs'); + expect(closed?.content?.[1]).not.toHaveProperty('tool_call.toolExecutionDurationMs'); + }); + + it('preserves tool timing through completion and settled-step replay', () => { + const getTiming = () => ({ toolPreparationStartedAt: 1_000, toolDispatchedAt: 1_100 }); + const opened = applyToolCallsStep(createResponse(), search, 0, getTiming).message; + const streamed = applyToolCallDelta( + opened, + search, + argsDelta(search.id, '{}'), + 'call-1', + 0, + getTiming, + ) as TMessage; + const completed = applyToolCallCompleted( + streamed, + search, + toolEnd(search.id, { id: 'call-1', name: 'search', output: 'done' }), + 0, + ); + const closed = applyRunStepClosed( + completed, + search, + { + id: search.id, + index: 1, + type: StepTypes.TOOL_CALLS, + status: 'completed', + created_at: 1_000, + closed_at: 1_250, + }, + 0, + { toolPreparationDurationMs: 100, toolExecutionDurationMs: 150 }, + ) as TMessage; + expect(closed.content?.[1]).toMatchObject({ + tool_call: { + args: '{}', + output: 'done', + progress: 1, + toolPreparationStartedAt: 1_000, + toolDispatchedAt: 1_100, + toolPreparationDurationMs: 100, + toolExecutionDurationMs: 150, + runStepDurationMs: 250, + }, + }); + expect(applyToolCallsStep(closed, search, 0, getTiming).message.content).toEqual( + closed.content, + ); + }); + it('keeps streamed args when the completion omits them', () => { const opened = applyToolCallsStep(createResponse(), search, 0).message; const streamed = applyToolCallDelta(opened, search, argsDelta(search.id, '{}'), 'call-1', 0); diff --git a/client/src/hooks/SSE/steps/content.ts b/client/src/hooks/SSE/steps/content.ts index fc2b7cd311..021584e8a1 100644 --- a/client/src/hooks/SSE/steps/content.ts +++ b/client/src/hooks/SSE/steps/content.ts @@ -299,7 +299,9 @@ export function updateContent( }; } else if (contentType === ContentTypes.TOOL_CALL && 'tool_call' in contentPart) { const existingContent = updatedContent[index] as Agents.ToolCallContent | undefined; - const existingToolCall = existingContent?.tool_call; + const existingToolCall = existingContent?.tool_call as + | (Agents.ToolCall & PartMetadata) + | undefined; const toolCallArgs = (contentPart.tool_call as Agents.ToolCall).args; /** When args are a valid object, they are likely already invoked */ let args = diff --git a/client/src/hooks/SSE/steps/tools.ts b/client/src/hooks/SSE/steps/tools.ts index 09462d23bd..20240a090b 100644 --- a/client/src/hooks/SSE/steps/tools.ts +++ b/client/src/hooks/SSE/steps/tools.ts @@ -2,6 +2,11 @@ import { StepTypes, ContentTypes, getRunStepDurationMs } from 'librechat-data-pr import type { Agents, TMessage, PartMetadata } from 'librechat-data-provider'; import { getStepMetadata, updateContent } from './content'; +type ToolTimingLookup = ( + callId: string, + index?: number, +) => Pick; + /** Mirrors `SKILL_FILE_PREFIX` in `@librechat/api` file-authoring handlers. */ const SKILL_FILE_PREFIX = 'skills/'; const FILE_AUTHORING_TOOLS = new Set(['create_file', 'edit_file']); @@ -150,6 +155,7 @@ export function applyRunStepClosed( runStep: Agents.RunStep, closed: Agents.RunStepClosedEvent, editPrefixOffset: number, + timing: Pick = {}, ): TMessage | undefined { const index = runStep.index + editPrefixOffset; const existing = message.content?.[index];