Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🚚 refactor: Move the Steering Hooks into the Chat Package (#17158)

Marco Berettad9f2b2679548
diff --git a/client/src/components/Chat/Input/ChatForm.tsx b/client/src/components/Chat/Input/ChatForm.tsx
index 1a3f38c740..5df46cc66c 100644
--- a/client/src/components/Chat/Input/ChatForm.tsx
+++ b/client/src/components/Chat/Input/ChatForm.tsx
@@ -3,7 +3,7 @@ import { useAtom } from 'jotai';
import { useRecoilValue } from 'recoil';
import { useWatch } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
-import { showStopButtonByIndex } from '@librechat/chat/react';
+import { useSteering, showStopButtonByIndex } from '@librechat/chat/react';
import {
composerSurfaceClasses,
composerSurfaceShadow,
@@ -18,9 +18,9 @@ import {
isAssistantsEndpoint,
} from 'librechat-data-provider';
import type { TChatProject, TMessage, TConversation } from 'librechat-data-provider';
+import type { QueuedMessageContext } from '@librechat/chat';
import type { SetterOrUpdater } from 'recoil';
import type { ExtendedFile, FileSetter, ConvoGenerator, TAskFunction } from '~/common';
-import type { QueuedMessageContext } from '~/hooks/Chat/useSteering';
import {
cn,
getModelSpec,
@@ -70,7 +70,6 @@ import useHasAccess from '~/hooks/Roles/useHasAccess';
import useDictation from '~/hooks/Input/useDictation';
import { useGetStartupConfig } from '~/data-provider';
import CodeWorkspaceMenu from './CodeWorkspaceMenu';
-import useSteering from '~/hooks/Chat/useSteering';
import CodeApprovalMenu from './CodeApprovalMenu';
import TextareaHeader from './TextareaHeader';
import PromptsCommand from './PromptsCommand';
diff --git a/client/src/components/Chat/Input/Composer/Queue.tsx b/client/src/components/Chat/Input/Composer/Queue.tsx
index 29adc478f6..ec219aa203 100644
--- a/client/src/components/Chat/Input/Composer/Queue.tsx
+++ b/client/src/components/Chat/Input/Composer/Queue.tsx
@@ -30,9 +30,9 @@ import {
TriangleAlert,
MessageSquarePlus,
} from 'lucide-react';
+import type { SteeringControls } from '@librechat/chat/react';
import type { MenuItemProps } from '@librechat/client';
import type { RestoreToComposer } from '~/Providers/ComposerRestoreContext';
-import type { SteeringControls } from '~/hooks/Chat/useSteering';
import type { QueuedMessage } from '~/hooks/Chat/queue';
import { useQueuedTurnPortal } from '~/components/Chat/Steering/QueuedTurnPortal';
import EscalateNowButton from '~/components/Chat/Input/EscalateNowButton';
diff --git a/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsx b/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsx
index e3f58bb6b5..ceeff9538a 100644
--- a/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsx
+++ b/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsx
@@ -11,7 +11,7 @@ import {
resetSteerFamilies,
resetQueueFamilies,
} from '@librechat/chat/react';
-import type { SteeringControls } from '~/hooks/Chat/useSteering';
+import type { SteeringControls } from '@librechat/chat/react';
import type { QueuedMessage } from '~/hooks/Chat/queue';
import {
QueuedTurnPortalProvider,
diff --git a/client/src/components/Chat/Input/DuringRunSendButton.tsx b/client/src/components/Chat/Input/DuringRunSendButton.tsx
index 69bc175e05..609144f0e3 100644
--- a/client/src/components/Chat/Input/DuringRunSendButton.tsx
+++ b/client/src/components/Chat/Input/DuringRunSendButton.tsx
@@ -2,10 +2,10 @@ import React, { forwardRef, useMemo, useRef } from 'react';
import { useWatch } from 'react-hook-form';
import { Zap, Clock, ZapOff } from 'lucide-react';
import { composerSubmitClasses, SendActions, SendIcon } from '@librechat/client';
+import type { SteeringControls } from '@librechat/chat/react';
import type { SendAction } from '@librechat/client';
import type { Control } from 'react-hook-form';
import type { ComposerKeyContext, KeyChordSource } from '~/utils/shortcuts';
-import type { SteeringControls } from '~/hooks/Chat/useSteering';
import { isMacPlatform, resolveComposerKeyDown } from '~/utils/shortcuts';
import useComposerBindings from '~/hooks/Input/useComposerBindings';
import { useLocalize } from '~/hooks';
diff --git a/client/src/components/Chat/Input/__tests__/DuringRunSendButton.test.tsx b/client/src/components/Chat/Input/__tests__/DuringRunSendButton.test.tsx
index f3dc0cacc2..3787c43989 100644
--- a/client/src/components/Chat/Input/__tests__/DuringRunSendButton.test.tsx
+++ b/client/src/components/Chat/Input/__tests__/DuringRunSendButton.test.tsx
@@ -2,7 +2,7 @@ import React from 'react';
import { RecoilRoot } from 'recoil';
import { useForm } from 'react-hook-form';
import { render, screen, fireEvent } from '@testing-library/react';
-import type { SteeringControls } from '~/hooks/Chat/useSteering';
+import type { SteeringControls } from '@librechat/chat/react';
import type { ShortcutOverride } from '~/store/misc';
import DuringRunSendButton from '../DuringRunSendButton';
import store from '~/store';
diff --git a/client/src/components/Chat/Messages/Content/Parts/PendingSteers.tsx b/client/src/components/Chat/Messages/Content/Parts/PendingSteers.tsx
index e59a8124c8..16b0e64645 100644
--- a/client/src/components/Chat/Messages/Content/Parts/PendingSteers.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/PendingSteers.tsx
@@ -1,16 +1,20 @@
import { memo, useMemo, useRef, useState } from 'react';
+import { hasLiveRunPause } from '@librechat/chat';
import { Clock, TextQuote, X } from 'lucide-react';
import { useQueryClient } from '@tanstack/react-query';
import { Button, TooltipAnchor } from '@librechat/client';
import { QueryKeys, type TMessage } from 'librechat-data-provider';
+import {
+ useSteerCancel,
+ useSteerMoveToQueue,
+ useSteerRehome,
+ useSteerEscalate,
+} from '@librechat/chat/react';
import type { SteerReceiptState } from '~/components/Chat/Steering/Receipt';
-import useSteerCancel, { useSteerMoveToQueue, useSteerRehome } from '~/hooks/Chat/useSteerCancel';
import { getMessageRowWidthClass } from '~/components/Chat/Messages/ui/MessageRow';
import EscalateNowButton from '~/components/Chat/Input/EscalateNowButton';
import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
-import useSteerEscalate from '~/hooks/Chat/useSteerEscalate';
import useSteerRecovery from '~/hooks/Chat/useSteerRecovery';
-import { hasLiveRunPause } from '~/hooks/Chat/useSteering';
import { useGetMessagesByConvoId } from '~/data-provider';
import { cn, isLegacyDeliveryUncertain } from '~/utils';
import { useLatestMessage } from '~/hooks/Messages';
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/PendingSteers.test.tsx b/client/src/components/Chat/Messages/Content/Parts/__tests__/PendingSteers.test.tsx
index eef407ebaf..0e61497e18 100644
--- a/client/src/components/Chat/Messages/Content/Parts/__tests__/PendingSteers.test.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/PendingSteers.test.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import { RecoilRoot } from 'recoil';
import { MemoryRouter } from 'react-router-dom';
+import { hasLiveRunPause } from '@librechat/chat';
import { Provider as JotaiProvider, createStore } from 'jotai';
import { pendingSteersByConvoId } from '@librechat/chat/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
@@ -9,7 +10,6 @@ import { render, screen, fireEvent, waitFor, act } from '@testing-library/react'
import type { Agents, TConversation, TMessage } from 'librechat-data-provider';
import type { PendingSteer } from '~/hooks/Chat/queue';
import { siblingIdxFamily, siblingKey } from '~/components/Chat/Messages/Thread/state';
-import { hasLiveRunPause } from '~/hooks/Chat/useSteering';
import { applyPendingAction } from '~/utils/approval';
import PendingSteers from '../PendingSteers';
import store from '~/store';
@@ -30,19 +30,15 @@ jest.mock('~/hooks', () => ({
useLocalize: () => (key: string) => key,
}));
-jest.mock('~/hooks/Chat/useSteerEscalate', () => ({
- __esModule: true,
- default: () => mockEscalate,
-}));
-
jest.mock('~/hooks/Chat/useSteerRecovery', () => ({
__esModule: true,
default: () => ({ retry: mockRetry, sendAsNew: mockSendAsNew }),
}));
-jest.mock('~/hooks/Chat/useSteerCancel', () => ({
- __esModule: true,
- default: () => jest.fn(),
+jest.mock('@librechat/chat/react', () => ({
+ ...jest.requireActual('@librechat/chat/react'),
+ useSteerEscalate: () => mockEscalate,
+ useSteerCancel: () => jest.fn(),
useSteerMoveToQueue: () => mockMoveToQueue,
useSteerRehome: () => mockRehome,
}));
diff --git a/client/src/hooks/Chat/__tests__/abort.spec.tsx b/client/src/hooks/Chat/__tests__/abort.spec.tsx
index e78ff6c139..9da3b708a2 100644
--- a/client/src/hooks/Chat/__tests__/abort.spec.tsx
+++ b/client/src/hooks/Chat/__tests__/abort.spec.tsx
@@ -46,9 +46,9 @@ jest.mock('~/hooks/useNewConvo', () => ({
default: () => ({ newConversation: jest.fn() }),
}));
-jest.mock('~/hooks/Chat/useSteerConvert', () => ({
- __esModule: true,
- default: () => mockConvertSteersToQueued,
+jest.mock('@librechat/chat/react', () => ({
+ ...jest.requireActual('@librechat/chat/react'),
+ useSteerConvert: () => mockConvertSteersToQueued,
}));
const INDEX = 0;
diff --git a/client/src/hooks/Chat/__tests__/contract.spec.tsx b/client/src/hooks/Chat/__tests__/contract.spec.tsx
index abf47cf9a8..98447f19cd 100644
--- a/client/src/hooks/Chat/__tests__/contract.spec.tsx
+++ b/client/src/hooks/Chat/__tests__/contract.spec.tsx
@@ -35,9 +35,9 @@ jest.mock('~/hooks/useNewConvo', () => ({
default: () => ({ newConversation: jest.fn() }),
}));
-jest.mock('~/hooks/Chat/useSteerConvert', () => ({
- __esModule: true,
- default: () => jest.fn(),
+jest.mock('@librechat/chat/react', () => ({
+ ...jest.requireActual('@librechat/chat/react'),
+ useSteerConvert: () => jest.fn(),
}));
function createWrapper(
diff --git a/client/src/hooks/Chat/__tests__/feedback.spec.tsx b/client/src/hooks/Chat/__tests__/feedback.spec.tsx
index 0053c41564..1671fd9729 100644
--- a/client/src/hooks/Chat/__tests__/feedback.spec.tsx
+++ b/client/src/hooks/Chat/__tests__/feedback.spec.tsx
@@ -33,9 +33,9 @@ jest.mock('~/hooks/useNewConvo', () => ({
default: () => ({ newConversation: jest.fn() }),
}));
-jest.mock('~/hooks/Chat/useSteerConvert', () => ({
- __esModule: true,
- default: () => jest.fn(),
+jest.mock('@librechat/chat/react', () => ({
+ ...jest.requireActual('@librechat/chat/react'),
+ useSteerConvert: () => jest.fn(),
}));
function renderChatHelpers() {
diff --git a/client/src/hooks/Chat/__tests__/transport.spec.tsx b/client/src/hooks/Chat/__tests__/transport.spec.tsx
index 80f3d26980..edd7d192fe 100644
--- a/client/src/hooks/Chat/__tests__/transport.spec.tsx
+++ b/client/src/hooks/Chat/__tests__/transport.spec.tsx
@@ -8,11 +8,15 @@ import { Tools, QueryKeys, ContentTypes, EModelEndpoint, request } from 'librech
import {
activeGenerationCreatedAtByConvoId,
activeGenerationProtocolVersionByConvoId,
+ queuedMessagesByConvoId,
pendingSteersByConvoId,
resetSteerFamilies,
submissionByIndex,
clearSubmissions,
resetQueueFamilies,
+ useSteerReclaim,
+ useSteerEscalate,
+ useSteering,
} from '@librechat/chat/react';
import type {
TEnqueueAgentQueuedTurnRequest,
@@ -29,14 +33,10 @@ import type { PendingSteer } from '~/hooks/Chat/queue';
import { ChatTransportContext } from '~/Providers/ChatTransportContext';
import { ChatContext, useChatContext } from '~/Providers/ChatContext';
import { startupConfigKey } from '~/data-provider/Endpoints/queries';
-import { useSteerReclaim } from '~/hooks/Chat/useSteerCancel';
-import { queuedMessagesByConvoId } from '~/hooks/Chat/queue';
-import useSteerEscalate from '~/hooks/Chat/useSteerEscalate';
import useResumableSSE from '~/hooks/SSE/useResumableSSE';
import useResumeOnLoad from '~/hooks/SSE/useResumeOnLoad';
import useChatHelpers from '~/hooks/Chat/useChatHelpers';
import { resumeRequestsAtom } from '~/hooks/Chat/resume';
-import useSteering from '~/hooks/Chat/useSteering';
import { useChat } from '~/hooks/Chat/facade';
import useSSE from '~/hooks/SSE/useSSE';
import store from '~/store';
diff --git a/client/src/hooks/Chat/__tests__/useSteerCancel.spec.tsx b/client/src/hooks/Chat/__tests__/useSteerCancel.spec.tsx
index 52b34a84f8..db7e41b37f 100644
--- a/client/src/hooks/Chat/__tests__/useSteerCancel.spec.tsx
+++ b/client/src/hooks/Chat/__tests__/useSteerCancel.spec.tsx
@@ -15,9 +15,9 @@ import {
ComposerRestoreProvider,
useComposerRestoreHost,
} from '~/Providers/ComposerRestoreContext';
-import useSteerCancel, { useSteerMoveToQueue } from '../useSteerCancel';
-import '~/Providers/SteerHostContext';
import { queuedMessagesByConvoId } from '~/hooks/Chat/queue';
+import '~/Providers/SteerHostContext';
+import { useSteerCancel, useSteerMoveToQueue } from '@librechat/chat/react';
const mockCancelAsync = jest.fn();
diff --git a/client/src/hooks/Chat/__tests__/useSteerConvert.spec.tsx b/client/src/hooks/Chat/__tests__/useSteerConvert.spec.tsx
index eb32ff2a98..2a5562a758 100644
--- a/client/src/hooks/Chat/__tests__/useSteerConvert.spec.tsx
+++ b/client/src/hooks/Chat/__tests__/useSteerConvert.spec.tsx
@@ -11,8 +11,8 @@ import {
} from '@librechat/chat/react';
import { recoveryDispositionsFamily } from '~/components/Chat/Steering/recovery';
import { queuedMessagesByConvoId } from '~/hooks/Chat/queue';
-import useSteerConvert from '../useSteerConvert';
import '~/Providers/SteerHostContext';
+import { useSteerConvert } from '@librechat/chat/react';
const mockFetchStreamStatus = jest.fn();
let mockFileMap: Record<string, { llmDeliveryPath: 'text' }> = {};
diff --git a/client/src/hooks/Chat/__tests__/useSteerEscalate.spec.tsx b/client/src/hooks/Chat/__tests__/useSteerEscalate.spec.tsx
index 4a3ae8ae65..2ea6d2011c 100644
--- a/client/src/hooks/Chat/__tests__/useSteerEscalate.spec.tsx
+++ b/client/src/hooks/Chat/__tests__/useSteerEscalate.spec.tsx
@@ -11,8 +11,8 @@ import {
} from '@librechat/chat/react';
import type { PendingSteer } from '~/hooks/Chat/queue';
import { ChatSettingsContext, defaultChatSettings } from '~/Providers/ChatSettingsContext';
-import useSteerEscalate from '../useSteerEscalate';
import '~/Providers/SteerHostContext';
+import { useSteerEscalate } from '@librechat/chat/react';
const mockArmMutateAsync = jest.fn();
const mockShowToast = jest.fn();
diff --git a/client/src/hooks/Chat/__tests__/useSteering.spec.tsx b/client/src/hooks/Chat/__tests__/useSteering.spec.tsx
index f8848adfa6..72e47fdfa9 100644
--- a/client/src/hooks/Chat/__tests__/useSteering.spec.tsx
+++ b/client/src/hooks/Chat/__tests__/useSteering.spec.tsx
@@ -45,7 +45,6 @@ import {
pendingManualSkillsByConvoId,
pendingReasoningOverrideFamily,
} from '~/components/Chat/Input/Composer/state';
-import useSteering, { hasLiveRunPause, mergeQueuedTurnFileMetadata } from '../useSteering';
import { clearAllDrafts, getPendingDraftId, getNewConversationDraftId } from '~/utils';
import { recoveryDispositionsFamily } from '~/components/Chat/Steering/recovery';
import useUpdateFiles from '~/hooks/Files/useUpdateFiles';
@@ -55,6 +54,11 @@ import { applyPendingAction } from '~/utils/approval';
import English from '~/locales/en/translation.json';
import useQueueDrain from '../useQueueDrain';
import '~/Providers/SteerHostContext';
+import { useSteering } from '@librechat/chat/react';
+import {
+ hasLiveRunPause,
+ hydrateFileDeliveryMetadata as mergeQueuedTurnFileMetadata,
+} from '@librechat/chat';
const CONVO_ID = 'convo-steer-ui';
const UUID_V4_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
diff --git a/client/src/hooks/Chat/index.ts b/client/src/hooks/Chat/index.ts
index 82241590da..136e6e1cfb 100644
--- a/client/src/hooks/Chat/index.ts
+++ b/client/src/hooks/Chat/index.ts
@@ -6,5 +6,3 @@ export { default as useIdChangeEffect } from './useIdChangeEffect';
export { default as useFocusChatEffect } from './useFocusChatEffect';
export { default as useQueueDrain } from './useQueueDrain';
export { default as useQueuedTurnReveal } from './useQueuedTurnReveal';
-export { default as useSteering } from './useSteering';
-export { default as useSteerConvert } from './useSteerConvert';
diff --git a/client/src/hooks/Chat/useChatHelpers.ts b/client/src/hooks/Chat/useChatHelpers.ts
index 4ea1b22b5f..96299c167f 100644
--- a/client/src/hooks/Chat/useChatHelpers.ts
+++ b/client/src/hooks/Chat/useChatHelpers.ts
@@ -14,6 +14,7 @@ import {
abortScrollFamily,
submissionByIndex,
useClearSubmissions,
+ useSteerConvert,
} from '@librechat/chat/react';
import type { TMessage } from 'librechat-data-provider';
import type { ChatContract } from './contract';
@@ -23,7 +24,6 @@ import { useAbortStreamMutation, supportsGenerationProtocolV2 } from '~/data-pro
import { siblingIdxFamily, siblingKey } from '~/components/Chat/Messages/Thread/state';
import { useChatSettings } from '~/Providers/ChatSettingsContext';
import useChatFunctions from '~/hooks/Chat/useChatFunctions';
-import useSteerConvert from '~/hooks/Chat/useSteerConvert';
import { resolveAbortSteerTarget } from '~/utils';
import useNewConvo from '~/hooks/useNewConvo';
import { getMessageCacheIds } from './cache';
diff --git a/client/src/hooks/Chat/useSteerRecovery.ts b/client/src/hooks/Chat/useSteerRecovery.ts
index c2c464d85d..0518332f4e 100644
--- a/client/src/hooks/Chat/useSteerRecovery.ts
+++ b/client/src/hooks/Chat/useSteerRecovery.ts
@@ -1,22 +1,19 @@
import { useCallback } from 'react';
import { useStore } from 'jotai';
+import { getSteerErrorCode, isDefiniteSteerRejection } from '@librechat/chat';
import {
+ useSteerRehome,
+ useSteerConvert,
isSubmittingFamily,
pendingSteersByConvoId,
+ resolveAcknowledgedSteer,
pendingSteerCancelClientIdsFamily,
} from '@librechat/chat/react';
import type { PendingSteer } from '~/hooks/Chat/queue';
-import {
- getSteerErrorCode,
- isDefiniteSteerRejection,
- resolveAcknowledgedSteer,
-} from '~/hooks/Chat/useSteering';
import { useSteerMessageMutation, useCancelSteerMutation } from '~/data-provider';
import { useComposerRestoreHost } from '~/Providers/ComposerRestoreContext';
import { carriedSteerContext, isLegacyDeliveryUncertain } from '~/utils';
import { useChatSettings } from '~/Providers/ChatSettingsContext';
-import { useSteerRehome } from '~/hooks/Chat/useSteerCancel';
-import useSteerConvert from '~/hooks/Chat/useSteerConvert';
/**
* Retry or re-route a pending steer from OUTSIDE the composer. The thread's
diff --git a/client/src/hooks/Input/useComposerRestore.ts b/client/src/hooks/Input/useComposerRestore.ts
index 5671c9e2ca..a01a9182fb 100644
--- a/client/src/hooks/Input/useComposerRestore.ts
+++ b/client/src/hooks/Input/useComposerRestore.ts
@@ -1,7 +1,7 @@
import { useRef, useEffect, useCallback } from 'react';
import { useStore } from 'jotai';
+import type { QueuedMessageContext } from '@librechat/chat';
import type { TMessage } from 'librechat-data-provider';
-import type { QueuedMessageContext } from '~/hooks/Chat/useSteering';
import type { ExtendedFile, FileSetter } from '~/common';
import type { useChatFormContext } from '~/Providers';
import {
diff --git a/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts b/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts
index 63f2591ce9..4dffcaf2c5 100644
--- a/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts
+++ b/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts
@@ -225,9 +225,9 @@ jest.mock('~/data-provider', () => ({
postGenerationRequest: (...args: unknown[]) => mockPostGenerationRequest(...args),
}));
-jest.mock('~/hooks/Chat/useSteerConvert', () => ({
- __esModule: true,
- default: () => mockConvertSteersToQueued,
+jest.mock('@librechat/chat/react', () => ({
+ ...jest.requireActual('@librechat/chat/react'),
+ useSteerConvert: () => mockConvertSteersToQueued,
}));
/** The steer-chip/queue writers are swapped for stable named spies, so these tests
diff --git a/client/src/hooks/SSE/steer.ts b/client/src/hooks/SSE/steer.ts
index e0fa2aa1fd..c71a0709e7 100644
--- a/client/src/hooks/SSE/steer.ts
+++ b/client/src/hooks/SSE/steer.ts
@@ -1,5 +1,6 @@
import { useCallback, useMemo, useRef } from 'react';
import { useStore } from 'jotai';
+import { useSteerConvert } from '@librechat/chat/react';
import {
pendingSteersByConvoId,
appliedSteerIdsByConvoId,
@@ -27,7 +28,6 @@ import {
} from '~/utils';
import { pendingQuotesByConvoId } from '~/components/Chat/Input/Composer/state';
import { queuedMessagesByConvoId } from '~/hooks/Chat/queue';
-import useSteerConvert from '~/hooks/Chat/useSteerConvert';
import { useFileMapContext } from '~/Providers';
/**
diff --git a/package-lock.json b/package-lock.json
index c9b50149c7..4755ea97b2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -41442,7 +41442,8 @@
"react-dom": "^18.2.0",
"rimraf": "^6.1.3",
"tsdown": "0.22.2",
- "typescript": "^5.9.3"
+ "typescript": "^5.9.3",
+ "uuid": "^11.1.1"
},
"peerDependencies": {
"@librechat/client": "*",
@@ -41450,7 +41451,8 @@
"librechat-data-provider": "*",
"lucide": "^0.528.0",
"lucide-react": "^0.528.0",
- "react": "^18.2.0 || ^19.1.0"
+ "react": "^18.2.0 || ^19.1.0",
+ "uuid": "^11.1.1"
}
},
"packages/chat/node_modules/@babel/generator": {
diff --git a/packages/chat/package.json b/packages/chat/package.json
index ceb9e033e2..f426752675 100644
--- a/packages/chat/package.json
+++ b/packages/chat/package.json
@@ -63,7 +63,8 @@
"librechat-data-provider": "*",
"lucide": "^0.528.0",
"lucide-react": "^0.528.0",
- "react": "^18.2.0 || ^19.1.0"
+ "react": "^18.2.0 || ^19.1.0",
+ "uuid": "^11.1.1"
},
"dependencies": {
"sse.js": "^2.8.0"
@@ -88,6 +89,7 @@
"react-dom": "^18.2.0",
"rimraf": "^6.1.3",
"tsdown": "0.22.2",
- "typescript": "^5.9.3"
+ "typescript": "^5.9.3",
+ "uuid": "^11.1.1"
}
}
diff --git a/packages/chat/src/react.ts b/packages/chat/src/react.ts
index 88b6480078..aed5eb9858 100644
--- a/packages/chat/src/react.ts
+++ b/packages/chat/src/react.ts
@@ -76,3 +76,22 @@ export type {
} from './react/steer/host';
export { presetFamily, filesFamily, optionSettingsFamily } from './react/pane';
export type { PaneOptionSettings } from './react/pane';
+export { default as useSteering } from './react/steering/useSteering';
+export type { SteeringControls, UseSteeringParams } from './react/steering/useSteering';
+export type { ComposerFile, ComposerFileSetter } from './react/steering/types';
+export {
+ default as useSteerCancel,
+ useSteerRehome,
+ useSteerReclaim,
+ useSteerMoveToQueue,
+} from './react/steering/useSteerCancel';
+export type {
+ SteerRehomeOptions,
+ SteerCancelOutcome,
+ SteerRehomeTarget,
+} from './react/steering/useSteerCancel';
+export { default as useSteerConvert } from './react/steering/useSteerConvert';
+export type { ConvertibleSteer, SteerConvertOptions } from './react/steering/useSteerConvert';
+export { default as useSteerEscalate } from './react/steering/useSteerEscalate';
+export type { EscalateTarget } from './react/steering/useSteerEscalate';
+export { resolveAcknowledgedSteer } from './react/steering/chips';
diff --git a/client/src/hooks/Chat/steering/actions.ts b/packages/chat/src/react/steering/actions.ts
similarity index 94%
rename from client/src/hooks/Chat/steering/actions.ts
rename to packages/chat/src/react/steering/actions.ts
index cefcc3d84d..877e4b296a 100644
--- a/client/src/hooks/Chat/steering/actions.ts
+++ b/packages/chat/src/react/steering/actions.ts
@@ -1,11 +1,19 @@
import { useCallback, useMemo } from 'react';
import type { TMessage } from 'librechat-data-provider';
import type { MutableRefObject } from 'react';
-import type { DuringRunAction } from '../contract';
+import type { DuringRunAction } from '../../core';
import type { ComposerTake } from './composer';
import type { QueueEnqueue } from './enqueue';
import type { SubmitSteer } from './submit';
+export interface DuringRunActions {
+ steerFromComposer: (text: string, preempt?: boolean) => boolean;
+ queueFromComposer: (text: string) => boolean;
+ interruptAndSend: (text: string) => boolean;
+ interruptSteer: (text: string) => boolean;
+ submitDuringRun: (text: string) => boolean;
+}
+
/** What the composer's own controls do during a run: steer, queue, interrupt
* and send, or interrupt the step and steer, each taking the composer's staged
* attachments, quotes and picks with the words. */
@@ -41,7 +49,7 @@ export default function useDuringRunActions({
submitSteer: SubmitSteer;
armDrainAfterAbort: () => void;
stopGenerating: () => void;
-}) {
+}): DuringRunActions {
const { takeComposerFiles, takeComposerContext, takeComposerQuotes } = composer;
/** Composer-originated steer: consumes the composer's attachments and quote
* chips so they ride the steer as one unit (the server re-fetches + encodes
diff --git a/client/src/hooks/Chat/steering/chips.ts b/packages/chat/src/react/steering/chips.ts
similarity index 91%
rename from client/src/hooks/Chat/steering/chips.ts
rename to packages/chat/src/react/steering/chips.ts
index 2e0df72f77..42d4bf0d6f 100644
--- a/client/src/hooks/Chat/steering/chips.ts
+++ b/packages/chat/src/react/steering/chips.ts
@@ -1,18 +1,22 @@
import { useCallback, useMemo } from 'react';
import { useStore } from 'jotai';
-import { isSteerRunReplaced, acknowledgeSteerChips } from '@librechat/chat';
+import type { MutableRefObject } from 'react';
+import type { createStore } from 'jotai';
+import type { PendingSteer } from '../../core';
import {
pendingSteerCancelClientIdsFamily,
pendingSteersByConvoId,
appliedSteerIdsByConvoId,
acceptedSteerClientIdsByConvoId,
activeGenerationCreatedAtByConvoId,
-} from '@librechat/chat/react';
-import type { PendingSteer } from '@librechat/chat';
-import type { MutableRefObject } from 'react';
-import type { createStore } from 'jotai';
-import { pendingQuotesByConvoId } from '~/components/Chat/Input/Composer/state';
-import { appendAppliedSteerIds, mergeRestagedQuotes } from '~/utils';
+} from '../steer/atoms';
+import {
+ isSteerRunReplaced,
+ acknowledgeSteerChips,
+ appendAppliedSteerIds,
+ mergeRestagedQuotes,
+} from '../../core';
+import { pendingQuotesByConvoId } from '../composer';
/**
* Resolves a steer's 202 ACK against the applied-id set and the run's live
@@ -67,6 +71,17 @@ export function resolveAcknowledgedSteer(
return true;
}
+export interface SteerChips {
+ upsertSteerChip: (convoId: string, steer: PendingSteer) => void;
+ replaceSteerChip: (convoId: string, localId: string, steer: PendingSteer | null) => void;
+ acknowledgeSteer: (convoId: string, localId: string, steer: PendingSteer) => boolean;
+ settleReceiptReplay: (convoId: string, localId: string, serverId: string) => void;
+ isSteerAcceptedOrSettled: (convoId: string, clientSteerId: string) => boolean;
+ hasPendingSteerCancel: (convoId: string, clientSteerId: string) => boolean;
+ clearPendingSteerCancel: (convoId: string, clientSteerId: string) => void;
+ reclaimRejectedChipQuotes: (convoId: string, steerIds: string[]) => void;
+}
+
/** The pending-steer chips of every conversation this composer has steered:
* optimistic writes, ACK and replay settlement, and the cancel markers a POST
* callback must honour. */
@@ -78,7 +93,7 @@ export default function useSteerChips({
visibleConversationRef: MutableRefObject<string>;
/** The visible pane's live submission state, read when a POST callback lands. */
isSubmittingRef: MutableRefObject<boolean>;
-}) {
+}): SteerChips {
const jotaiStore = useStore();
const upsertSteerChip = useCallback(
(convoId: string, steer: PendingSteer) => {
@@ -244,5 +259,3 @@ export default function useSteerChips({
],
);
}
-
-export type SteerChips = ReturnType<typeof useSteerChips>;
diff --git a/client/src/hooks/Chat/steering/composer.ts b/packages/chat/src/react/steering/composer.ts
similarity index 92%
rename from client/src/hooks/Chat/steering/composer.ts
rename to packages/chat/src/react/steering/composer.ts
index 3ab2fde771..1a3551de51 100644
--- a/client/src/hooks/Chat/steering/composer.ts
+++ b/packages/chat/src/react/steering/composer.ts
@@ -1,15 +1,15 @@
import { useCallback, useMemo } from 'react';
import { useStore } from 'jotai';
-import { useSteerHost } from '@librechat/chat/react';
-import type { QueuedMessageContext } from '@librechat/chat';
import type { TMessage } from 'librechat-data-provider';
-import type { ExtendedFile, FileSetter } from '~/common';
+import type { ComposerFile, ComposerFileSetter } from './types';
+import type { QueuedMessageContext } from '../../core';
import {
pendingQuotesByConvoId,
pendingManualSkillsByConvoId,
pendingReasoningOverrideFamily,
-} from '~/components/Chat/Input/Composer/state';
-import { markComposerFilesTaken } from '~/utils/composerFiles';
+} from '../composer';
+import { markComposerFilesTaken } from '../../core';
+import { useSteerHost } from '../steer/host';
export interface ComposerTake {
takeComposerFiles: () => TMessage['files'];
@@ -19,7 +19,7 @@ export interface ComposerTake {
/** Drains what the composer has staged so it travels with one during-run
* submission instead of the next one. */
-export default function useComposerTake({
+export default function useComposerTake<File extends ComposerFile>({
conversationId,
reasoningStateKey,
files,
@@ -27,8 +27,8 @@ export default function useComposerTake({
}: {
conversationId: string;
reasoningStateKey: string;
- files?: Map<string, ExtendedFile>;
- setFiles?: FileSetter;
+ files?: Map<string, File>;
+ setFiles?: ComposerFileSetter<File>;
}): ComposerTake {
const reasoningStore = useStore();
const clearFilesToDelete = useSteerHost().useClearFilesToDelete();
diff --git a/client/src/hooks/Chat/steering/enqueue.ts b/packages/chat/src/react/steering/enqueue.ts
similarity index 85%
rename from client/src/hooks/Chat/steering/enqueue.ts
rename to packages/chat/src/react/steering/enqueue.ts
index dfa0c504c7..64fb534b7b 100644
--- a/client/src/hooks/Chat/steering/enqueue.ts
+++ b/packages/chat/src/react/steering/enqueue.ts
@@ -1,16 +1,46 @@
import { useCallback, useMemo } from 'react';
import { v4 } from 'uuid';
import { useStore } from 'jotai';
-import { useSteerHost } from '@librechat/chat/react';
-import { getSteerErrorCode, toQueuedTurnFileRefs, QUEUE_USAGE_MAX_FILES } from '@librechat/chat';
-import { isDefiniteQueuedTurnRejection, isDefiniteQueuedTurnsUnsupported } from '@librechat/chat';
import type { TMessage, CodeApprovalMode } from 'librechat-data-provider';
-import type { RevealedQueuedTurn } from '@librechat/chat/react';
-import type { QueuedMessage } from '@librechat/chat';
+import type { RevealedQueuedTurn } from '../steer/atoms';
import type { QueuedTurnReceipts } from './receipts';
+import type { QueuedMessage } from '../../core';
import type { QueueRows } from './rows';
-import { pendingQueuedTurnEnqueueIdsByConvoId, queuedMessagesByConvoId } from '~/hooks/Chat/queue';
-import { insertQueuedMessage } from '~/utils/queue';
+import {
+ getSteerErrorCode,
+ toQueuedTurnFileRefs,
+ QUEUE_USAGE_MAX_FILES,
+ isDefiniteQueuedTurnRejection,
+ isDefiniteQueuedTurnsUnsupported,
+ insertQueuedMessage,
+} from '../../core';
+import { pendingQueuedTurnEnqueueIdsByConvoId, queuedMessagesByConvoId } from '../steer/queue';
+import { useSteerHost } from '../steer/host';
+
+/** How a follow-up enters the queue. */
+export type EnqueueOptions = {
+ front?: boolean;
+ files?: TMessage['files'];
+ quotes?: string[];
+ manualSkills?: string[];
+ reasoningOverride?: TMessage['reasoningOverride'];
+ /** Set when the files were ALREADY queued/steered: their TTL was
+ * held when they first entered the queue (or at the steer 202). */
+ skipUsageMark?: boolean;
+ id?: string;
+ createdAt?: number;
+ clientRequestId?: string;
+ expectedPredecessorCreatedAt?: number;
+ /** The queue lineage of a row being put back after its parked copy was
+ * cancelled. The run it waited on may have ended meanwhile, which
+ * clears the live pair, and the row must stay durable regardless. */
+ lineage?: { parentMessageId: string; predecessorCreatedAt: number };
+};
+
+export interface QueueEnqueue {
+ markQueuedFilesUsage: (files?: TMessage['files']) => void;
+ enqueue: (text: string, options?: EnqueueOptions) => void;
+}
/** Adds follow-up messages to the conversation's queue, server-owned (a durable
* queued turn) when the run's lineage is known, otherwise local to this tab. */
@@ -36,7 +66,7 @@ export default function useQueueEnqueue({
applyQueuedTurnReceipts: QueuedTurnReceipts['applyQueuedTurnReceipts'];
finishQueuedTurnEnqueue: QueuedTurnReceipts['finishQueuedTurnEnqueue'];
updateQueuedMessage: QueueRows['updateQueuedMessage'];
-}) {
+}): QueueEnqueue {
const jotaiStore = useStore();
const host = useSteerHost();
const markFilesUsage = host.useMarkFilesUsage();
@@ -68,27 +98,7 @@ export default function useQueueEnqueue({
);
const enqueue = useCallback(
- (
- text: string,
- options?: {
- front?: boolean;
- files?: TMessage['files'];
- quotes?: string[];
- manualSkills?: string[];
- reasoningOverride?: TMessage['reasoningOverride'];
- /** Set when the files were ALREADY queued/steered: their TTL was
- * held when they first entered the queue (or at the steer 202). */
- skipUsageMark?: boolean;
- id?: string;
- createdAt?: number;
- clientRequestId?: string;
- expectedPredecessorCreatedAt?: number;
- /** The queue lineage of a row being put back after its parked copy was
- * cancelled. The run it waited on may have ended meanwhile, which
- * clears the live pair, and the row must stay durable regardless. */
- lineage?: { parentMessageId: string; predecessorCreatedAt: number };
- },
- ) => {
+ (text: string, options?: EnqueueOptions) => {
const trimmed = text.trim();
if (trimmed.length === 0) {
return;
@@ -242,5 +252,3 @@ export default function useQueueEnqueue({
[markQueuedFilesUsage, enqueue],
);
}
-
-export type QueueEnqueue = ReturnType<typeof useQueueEnqueue>;
diff --git a/client/src/hooks/Chat/steering/receipts.ts b/packages/chat/src/react/steering/receipts.ts
similarity index 97%
rename from client/src/hooks/Chat/steering/receipts.ts
rename to packages/chat/src/react/steering/receipts.ts
index 2925a9c366..ceaf17c9c8 100644
--- a/client/src/hooks/Chat/steering/receipts.ts
+++ b/packages/chat/src/react/steering/receipts.ts
@@ -1,15 +1,15 @@
import { useCallback, useEffect, useMemo } from 'react';
-import { useSteerHost } from '@librechat/chat/react';
import { useAtomValue, useSetAtom, useStore } from 'jotai';
import { DEFAULT_QUEUED_TURN_RECONCILIATION_TIMEOUT_MS } from 'librechat-data-provider';
-import { reconcileServerQueuedTurns, mergeSettledQueuedTurnEvidence } from '@librechat/chat';
import type { TAgentQueuedTurnReceipt as AgentQueuedTurnReceipt } from 'librechat-data-provider';
-import type { QueuedTurnReceiptSource } from '@librechat/chat';
+import type { QueuedTurnReceiptSource } from '../../core';
import {
queuedMessagesByConvoId,
settledQueuedTurnReceiptsByConvoId,
pendingQueuedTurnEnqueueIdsByConvoId,
-} from '~/hooks/Chat/queue';
+} from '../steer/queue';
+import { reconcileServerQueuedTurns, mergeSettledQueuedTurnEvidence } from '../../core';
+import { useSteerHost } from '../steer/host';
export interface QueuedTurnReceipts {
/** Folds server receipts into the settled evidence and, unless `direct`, the visible queue. */
diff --git a/client/src/hooks/Chat/steering/recovery.ts b/packages/chat/src/react/steering/recovery.ts
similarity index 93%
rename from client/src/hooks/Chat/steering/recovery.ts
rename to packages/chat/src/react/steering/recovery.ts
index b7dddbe3ef..7cd12cbf05 100644
--- a/client/src/hooks/Chat/steering/recovery.ts
+++ b/packages/chat/src/react/steering/recovery.ts
@@ -1,12 +1,17 @@
import { useCallback, useMemo } from 'react';
import { useStore } from 'jotai';
-import { useSteerHost } from '@librechat/chat/react';
-import { revealedQueuedTurnFamily } from '@librechat/chat/react';
-import { blockRecovery, canRestoreRecovery, recoveryDisposition } from '@librechat/chat';
-import type { QueuedMessage } from '@librechat/chat';
import type { QueuedTurnReceipts } from './receipts';
+import type { QueuedMessage } from '../../core';
import type { QueueRows } from './rows';
-import { recoveryDispositionsFamily } from '~/components/Chat/Steering/recovery';
+import { blockRecovery, canRestoreRecovery, recoveryDisposition } from '../../core';
+import { recoveryDispositionsFamily } from '../steer/recovery';
+import { revealedQueuedTurnFamily } from '../steer/atoms';
+import { useSteerHost } from '../steer/host';
+
+export interface QueuedRecovery {
+ discardQueued: (item: QueuedMessage) => Promise<boolean>;
+ dismissRecovery: (item: QueuedMessage) => void;
+}
/** Lets go of a queued row's server copy (a durable queued turn or a parked
* steer receipt) before the row is edited, removed or sent another way. */
@@ -24,7 +29,7 @@ export default function useQueuedRecovery({
applyQueuedTurnReceipts: QueuedTurnReceipts['applyQueuedTurnReceipts'];
downgradeServerQueuedTurn: QueueRows['downgradeServerQueuedTurn'];
removeQueued: QueueRows['removeQueued'];
-}) {
+}): QueuedRecovery {
const host = useSteerHost();
const localize = host.useLocalize();
const jotaiStore = useStore();
@@ -173,5 +178,3 @@ export default function useQueuedRecovery({
[discardQueued, dismissRecovery],
);
}
-
-export type QueuedRecovery = ReturnType<typeof useQueuedRecovery>;
diff --git a/client/src/hooks/Chat/steering/rows.ts b/packages/chat/src/react/steering/rows.ts
similarity index 93%
rename from client/src/hooks/Chat/steering/rows.ts
rename to packages/chat/src/react/steering/rows.ts
index 2b6c93b6cb..eaa21d9d03 100644
--- a/client/src/hooks/Chat/steering/rows.ts
+++ b/packages/chat/src/react/steering/rows.ts
@@ -1,14 +1,31 @@
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useAtomValue, useStore } from 'jotai';
-import { isSameRunEpoch, insertQueuedOrigin, canRestoreRecovery } from '@librechat/chat';
-import type { PendingSteer, QueuedMessage, QueuedMessageOrigin, RunEnd } from '@librechat/chat';
+import type { PendingSteer, QueuedMessage, QueuedMessageOrigin, RunEnd } from '../../core';
import {
runEndByIndex,
drainAfterAbortByIndex,
pendingRunEndByConvoId,
queuedMessagesByConvoId,
-} from '~/hooks/Chat/queue';
-import { recoveryDispositionsFamily } from '~/components/Chat/Steering/recovery';
+} from '../steer/queue';
+import { isSameRunEpoch, insertQueuedOrigin, canRestoreRecovery } from '../../core';
+import { recoveryDispositionsFamily } from '../steer/recovery';
+
+export interface QueueRows {
+ updateQueuedMessage: (id: string, update: (item: QueuedMessage) => QueuedMessage | null) => void;
+ removeQueued: (id: string) => void;
+ holdQueued: (id: string) => void;
+ toggleQueuedHold: (id: string, held: boolean) => void;
+ downgradeServerQueuedTurn: (id: string) => boolean;
+ reorderQueued: (id: string, targetIndex: number) => void;
+ restoreQueuedOrder: (ids: readonly string[]) => void;
+ takeQueued: (id: string) => QueuedMessageOrigin | undefined;
+ releaseQueuedOrigin: (origin: QueuedMessageOrigin) => void;
+ registerQueuedOrigin: (origin: QueuedMessageOrigin) => void;
+ restoreQueued: (origin: QueuedMessageOrigin) => void;
+ rearmDrain: (convoId: string, end: RunEnd) => void;
+ rewakeDrain: (convoId: string) => void;
+ armDrainAfterAbort: () => void;
+}
/**
* The conversation's queue rows and the bookkeeping that keeps them restorable:
@@ -29,7 +46,7 @@ export default function useQueueRows({
isSubmitting: boolean;
pendingSteers: PendingSteer[];
activeGenerationCreatedAt: number | null;
-}) {
+}): QueueRows {
const jotaiStore = useStore();
/** Queue rows can be sent concurrently. Keep their captured origins while
* absent so a later capture still sees the complete logical queue. Origins
@@ -367,5 +384,3 @@ export default function useQueueRows({
],
);
}
-
-export type QueueRows = ReturnType<typeof useQueueRows>;
diff --git a/client/src/hooks/Chat/steering/send.ts b/packages/chat/src/react/steering/send.ts
similarity index 97%
rename from client/src/hooks/Chat/steering/send.ts
rename to packages/chat/src/react/steering/send.ts
index 34d4f85eca..42b5f2f78d 100644
--- a/client/src/hooks/Chat/steering/send.ts
+++ b/packages/chat/src/react/steering/send.ts
@@ -1,17 +1,21 @@
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useStore } from 'jotai';
+import type { TMessage } from 'librechat-data-provider';
+import type { QueueSendLock, QueuedMessage, QueuedMessageContext } from '../../core';
+import type { QueuedRecovery } from './recovery';
+import type { SubmitSteer } from './submit';
+import type { QueueRows } from './rows';
import {
hasQueuedIntent,
recoveryDisposition,
acquireQueueSendLock,
releaseQueueSendLock,
-} from '@librechat/chat';
-import type { QueueSendLock, QueuedMessage, QueuedMessageContext } from '@librechat/chat';
-import type { TMessage } from 'librechat-data-provider';
-import type { QueuedRecovery } from './recovery';
-import type { SubmitSteer } from './submit';
-import type { QueueRows } from './rows';
-import { recoveryDispositionsFamily } from '~/components/Chat/Steering/recovery';
+} from '../../core';
+import { recoveryDispositionsFamily } from '../steer/recovery';
+
+export interface QueuedSend {
+ sendQueuedNow: (item: QueuedMessage, opts?: { preempt?: boolean }) => void;
+}
/** Sends one queued row now: into the live run as a steer when it can take
* one, otherwise as a new turn once the pane's submission slot is free. */
@@ -41,7 +45,7 @@ export default function useQueuedSend({
submitSteer: SubmitSteer;
rows: Pick<QueueRows, 'takeQueued' | 'restoreQueued' | 'releaseQueuedOrigin'>;
discardQueued: QueuedRecovery['discardQueued'];
-}) {
+}): QueuedSend {
const jotaiStore = useStore();
const { takeQueued, restoreQueued, releaseQueuedOrigin } = rows;
/** `ask()` does not flip `isSubmitting` until the submission effect renders.
diff --git a/client/src/hooks/Chat/steering/submit.ts b/packages/chat/src/react/steering/submit.ts
similarity index 98%
rename from client/src/hooks/Chat/steering/submit.ts
rename to packages/chat/src/react/steering/submit.ts
index 53c9014aeb..142af5852a 100644
--- a/client/src/hooks/Chat/steering/submit.ts
+++ b/packages/chat/src/react/steering/submit.ts
@@ -1,13 +1,7 @@
import { useCallback, useRef } from 'react';
import { v4 } from 'uuid';
-import { useSteerHost } from '@librechat/chat/react';
-import {
- steerAttemptChip,
- routeSteerFailure,
- carriedSteerContext,
- createSteerDispatch,
- supportsGenerationProtocolV2,
-} from '@librechat/chat';
+import type { TMessage } from 'librechat-data-provider';
+import type { MutableRefObject } from 'react';
import type {
SteerAttempt,
PendingSteer,
@@ -15,14 +9,20 @@ import type {
QueuedMessageOrigin,
QueuedMessageContext,
GenerationProtocolVersion,
-} from '@librechat/chat';
-import type { TMessage } from 'librechat-data-provider';
-import type { MutableRefObject } from 'react';
+} from '../../core';
import type { QueueEnqueue } from './enqueue';
import type { SteerChips } from './chips';
import type { QueueRows } from './rows';
-import { useSteerRehome } from '~/hooks/Chat/useSteerCancel';
-import useSteerConvert from '~/hooks/Chat/useSteerConvert';
+import {
+ steerAttemptChip,
+ routeSteerFailure,
+ carriedSteerContext,
+ createSteerDispatch,
+ supportsGenerationProtocolV2,
+} from '../../core';
+import { useSteerRehome } from './useSteerCancel';
+import useSteerConvert from './useSteerConvert';
+import { useSteerHost } from '../steer/host';
export type SubmitSteer = (
text: string,
diff --git a/packages/chat/src/react/steering/types.ts b/packages/chat/src/react/steering/types.ts
new file mode 100644
index 0000000000..08200bbae2
--- /dev/null
+++ b/packages/chat/src/react/steering/types.ts
@@ -0,0 +1,22 @@
+import type { Dispatch, SetStateAction } from 'react';
+import type { TFile } from 'librechat-data-provider';
+
+/** The fields of a composer attachment a during-run submit reads. Hosts pass their own richer
+ * attachment type; the hooks keep it intact through the setter. */
+export type ComposerFile = {
+ file_id: string;
+ temp_file_id?: string;
+ type?: string;
+ filepath?: string;
+ filename?: string;
+ width?: number;
+ height?: number;
+ size: number;
+ progress: number;
+ llmDeliveryPath?: TFile['llmDeliveryPath'];
+};
+
+/** Updates the composer's attachments, keyed by upload id. */
+export type ComposerFileSetter<File extends ComposerFile> = Dispatch<
+ SetStateAction<Map<string, File>>
+>;
diff --git a/client/src/hooks/Chat/useSteerCancel.ts b/packages/chat/src/react/steering/useSteerCancel.ts
similarity index 89%
rename from client/src/hooks/Chat/useSteerCancel.ts
rename to packages/chat/src/react/steering/useSteerCancel.ts
index 6b4a8e747a..c1b50b3d72 100644
--- a/client/src/hooks/Chat/useSteerCancel.ts
+++ b/packages/chat/src/react/steering/useSteerCancel.ts
@@ -1,17 +1,17 @@
import { useCallback } from 'react';
-import { useSteerHost } from '@librechat/chat/react';
import { useSetAtom, useStore, useAtomValue } from 'jotai';
+import type { PendingSteer } from '../../core';
import {
pendingSteerCancelClientIdsFamily,
pendingSteersByConvoId,
appliedSteerIdsByConvoId,
activeGenerationCreatedAtByConvoId,
-} from '@librechat/chat/react';
-import type { PendingSteer } from '~/hooks/Chat/queue';
-import { useComposerRestoreHost } from '~/Providers/ComposerRestoreContext';
-import { appendAppliedSteerIds, carriedSteerContext } from '~/utils';
-import { queuedMessagesByConvoId } from '~/hooks/Chat/queue';
-import useSteerConvert from '~/hooks/Chat/useSteerConvert';
+} from '../steer/atoms';
+import { appendAppliedSteerIds, carriedSteerContext } from '../../core';
+import { useComposerRestoreHost } from '../steer/restore';
+import { queuedMessagesByConvoId } from '../steer/queue';
+import useSteerConvert from './useSteerConvert';
+import { useSteerHost } from '../steer/host';
export type SteerCancelOutcome = 'reclaimed' | 'applied' | 'failed';
@@ -22,7 +22,9 @@ export type SteerRehomeTarget = 'composer' | 'queue';
* Asks the server to drop a steer before its injection boundary. Only a
* confirmed reclaim proves the words remain safe to move elsewhere.
*/
-export function useSteerReclaim(conversationId: string) {
+export function useSteerReclaim(
+ conversationId: string,
+): (steer: PendingSteer) => Promise<SteerCancelOutcome> {
const cancelSteer = useSteerHost().useCancelSteer();
const activeGenerationCreatedAt = useAtomValue(
activeGenerationCreatedAtByConvoId(conversationId),
@@ -83,7 +85,9 @@ export function useSteerReclaim(conversationId: string) {
);
}
-export function useSteerMoveToQueue(conversationId: string) {
+export function useSteerMoveToQueue(
+ conversationId: string,
+): (steer: PendingSteer) => Promise<SteerCancelOutcome> {
const reclaim = useSteerReclaim(conversationId);
const convertSteersToQueued = useSteerConvert();
const { rewakeDrain } = useComposerRestoreHost();
@@ -129,7 +133,9 @@ export interface SteerRehomeOptions {
rejectedByServer?: boolean;
}
-export function useSteerRehome(conversationId: string) {
+export function useSteerRehome(
+ conversationId: string,
+): (steer: PendingSteer, options?: SteerRehomeOptions) => SteerRehomeTarget {
const { restore, rewakeDrain } = useComposerRestoreHost();
const convertSteersToQueued = useSteerConvert();
const jotaiStore = useStore();
@@ -170,7 +176,9 @@ export function useSteerRehome(conversationId: string) {
);
}
-export default function useSteerCancel(conversationId: string) {
+export default function useSteerCancel(
+ conversationId: string,
+): (steer: PendingSteer) => Promise<SteerCancelOutcome> {
const reclaim = useSteerReclaim(conversationId);
const rehome = useSteerRehome(conversationId);
const setPendingCancelIds = useSetAtom(pendingSteerCancelClientIdsFamily(conversationId));
diff --git a/client/src/hooks/Chat/useSteerConvert.ts b/packages/chat/src/react/steering/useSteerConvert.ts
similarity index 94%
rename from client/src/hooks/Chat/useSteerConvert.ts
rename to packages/chat/src/react/steering/useSteerConvert.ts
index 46a36cca09..a195d9a085 100644
--- a/client/src/hooks/Chat/useSteerConvert.ts
+++ b/packages/chat/src/react/steering/useSteerConvert.ts
@@ -1,35 +1,36 @@
import { useCallback, useRef } from 'react';
import { v4 } from 'uuid';
import { useStore } from 'jotai';
-import { useSteerHost } from '@librechat/chat/react';
-import { getGenerationProtocolVersion } from '@librechat/chat';
-import {
- pendingSteersByConvoId,
- appliedSteerIdsByConvoId,
- activeGenerationProtocolVersionByConvoId,
-} from '@librechat/chat/react';
-import type { GenerationProtocolVersion } from '@librechat/chat';
import type { TPendingSteer } from 'librechat-data-provider';
-import type { QueuedMessage, QueuedMessageOrigin } from '~/hooks/Chat/queue';
-import type { SteerCarriedContext } from '~/utils';
+import type {
+ GenerationProtocolVersion,
+ QueuedMessage,
+ QueuedMessageOrigin,
+ SteerCarriedContext,
+} from '../../core';
import {
+ getGenerationProtocolVersion,
appendAppliedSteerIds,
carriedSteerContext,
insertQueuedOrigin,
hydrateFileDeliveryMetadata,
-} from '~/utils';
-import {
- recoveryDispositionsFamily,
canRestoreRecovery,
-} from '~/components/Chat/Steering/recovery';
-import { queuedMessagesByConvoId } from '~/hooks/Chat/queue';
+} from '../../core';
+import {
+ pendingSteersByConvoId,
+ appliedSteerIdsByConvoId,
+ activeGenerationProtocolVersionByConvoId,
+} from '../steer/atoms';
+import { recoveryDispositionsFamily } from '../steer/recovery';
+import { queuedMessagesByConvoId } from '../steer/queue';
+import { useSteerHost } from '../steer/host';
/** A server-reported steer, or a local one that carries its own client-only
* context (quotes / skill picks) because its chip may already be gone. */
-type ConvertibleSteer = TPendingSteer &
+export type ConvertibleSteer = TPendingSteer &
SteerCarriedContext & { queuedOrigin?: QueuedMessageOrigin };
-interface SteerConvertOptions {
+export interface SteerConvertOptions {
/** Live-delivered terminal steers also have a parked server copy (the
* terminal drain parks before knowing the final reached a subscriber);
* set on final/abort/error surfaces to reconcile that durable copy. */
@@ -67,7 +68,11 @@ interface SteerConvertOptions {
* the only recovery source. Exact recovery or explicit dismissal commits the
* server-side removal.
*/
-export default function useSteerConvert() {
+export default function useSteerConvert(): (
+ conversationId: string,
+ steers: ConvertibleSteer[],
+ options?: SteerConvertOptions,
+) => void {
const jotaiStore = useStore();
const host = useSteerHost();
const fileMap = host.useFileMap();
diff --git a/client/src/hooks/Chat/useSteerEscalate.ts b/packages/chat/src/react/steering/useSteerEscalate.ts
similarity index 96%
rename from client/src/hooks/Chat/useSteerEscalate.ts
rename to packages/chat/src/react/steering/useSteerEscalate.ts
index 0f0a54b366..c4469f04cd 100644
--- a/client/src/hooks/Chat/useSteerEscalate.ts
+++ b/packages/chat/src/react/steering/useSteerEscalate.ts
@@ -1,14 +1,14 @@
import { useCallback } from 'react';
-import { useSteerHost } from '@librechat/chat/react';
import { useSetAtom, useAtomValue, useStore } from 'jotai';
-import { supportsGenerationProtocolV2 } from '@librechat/chat';
import { DEFAULT_STEER_ARM_CONFIRMATION_TIMEOUT_MS } from 'librechat-data-provider';
import {
escalatingSteerFamily,
pendingSteersByConvoId,
activeGenerationCreatedAtByConvoId,
activeGenerationProtocolVersionByConvoId,
-} from '@librechat/chat/react';
+} from '../steer/atoms';
+import { supportsGenerationProtocolV2 } from '../../core';
+import { useSteerHost } from '../steer/host';
type ArmFailure = {
name?: string;
@@ -44,7 +44,9 @@ export interface EscalateTarget {
* steers escalate through identical race rules rather than two approximations.
* `onArmed` lets a caller move focus off a control the success state removes.
*/
-export default function useSteerEscalate(conversationId: string) {
+export default function useSteerEscalate(
+ conversationId: string,
+): (target: EscalateTarget, onArmed?: () => void) => void {
const host = useSteerHost();
const localize = host.useLocalize();
const notify = host.useNotify();
diff --git a/client/src/hooks/Chat/useSteering.ts b/packages/chat/src/react/steering/useSteering.ts
similarity index 81%
rename from client/src/hooks/Chat/useSteering.ts
rename to packages/chat/src/react/steering/useSteering.ts
index 21812d8a8d..fd31f0b169 100644
--- a/client/src/hooks/Chat/useSteering.ts
+++ b/packages/chat/src/react/steering/useSteering.ts
@@ -1,55 +1,46 @@
import { useCallback, useMemo, useRef } from 'react';
import { useAtomValue } from 'jotai';
-import { useSteerHost } from '@librechat/chat/react';
-import { hasLiveRunPause, selectLiveMessageState } from '@librechat/chat';
import {
Constants,
isAgentsEndpoint,
isAssistantsEndpoint,
DEFAULT_QUEUED_SEND_LOCK_TIMEOUT_MS,
} from 'librechat-data-provider';
+import type { TMessage, TConversation, CodeEnvironmentMode } from 'librechat-data-provider';
+import type {
+ SubmitSteerOptions,
+ QueuedMessageContext,
+ QueuedMessageOrigin,
+ PendingSteer,
+ DuringRunAction,
+} from '../../core';
+import type { ComposerFile, ComposerFileSetter } from './types';
+import type { DuringRunActions } from './actions';
+import type { QueuedRecovery } from './recovery';
+import type { QueueEnqueue } from './enqueue';
+import type { SubmitSteer } from './submit';
+import type { QueuedSend } from './send';
+import type { QueueRows } from './rows';
import {
revealedQueuedTurnFamily,
pendingSteersByConvoId,
activeGenerationCreatedAtByConvoId,
activeGenerationProtocolVersionByConvoId,
-} from '@librechat/chat/react';
-import type { TMessage, TConversation, CodeEnvironmentMode } from 'librechat-data-provider';
-import type { SubmitSteerOptions, QueuedMessageContext } from '@librechat/chat';
-import type { QueuedMessageOrigin } from '~/hooks/Chat/queue';
-import type { ExtendedFile, FileSetter } from '~/common';
-import type { PendingSteer } from '~/hooks/Chat/queue';
-import type { DuringRunAction } from './contract';
-import {
- getReasoningStateKey,
- pendingReasoningOverrideFamily,
-} from '~/components/Chat/Input/Composer/state';
-import useQueuedTurnReceipts from './steering/receipts';
-import useDuringRunActions from './steering/actions';
-import useQueuedRecovery from './steering/recovery';
-import useComposerTake from './steering/composer';
-import useQueueEnqueue from './steering/enqueue';
-import useSubmitSteer from './steering/submit';
-import { carriedSteerContext } from '~/utils';
-import useSteerChips from './steering/chips';
-import useQueuedSend from './steering/send';
-import useQueueRows from './steering/rows';
-
-export type { DuringRunAction };
+} from '../steer/atoms';
+import { hasLiveRunPause, selectLiveMessageState, carriedSteerContext } from '../../core';
+import { getReasoningStateKey, pendingReasoningOverrideFamily } from '../composer';
+import useQueuedTurnReceipts from './receipts';
+import { useSteerHost } from '../steer/host';
+import useDuringRunActions from './actions';
+import useQueuedRecovery from './recovery';
+import useComposerTake from './composer';
+import useQueueEnqueue from './enqueue';
+import useSubmitSteer from './submit';
+import useSteerChips from './chips';
+import useQueuedSend from './send';
+import useQueueRows from './rows';
-export type { QueuedMessageContext } from '@librechat/chat';
-export { resolveAcknowledgedSteer } from './steering/chips';
-
-export {
- getSteerErrorCode,
- hasLiveRunPause,
- hasLiveToolApproval,
- isDefiniteSteerRejection,
-} from '@librechat/chat';
-export { hydrateFileDeliveryMetadata as mergeQueuedTurnFileMetadata } from '@librechat/chat';
-export type { SteerErrorCode } from '@librechat/chat';
-
-export interface UseSteeringParams {
+export interface UseSteeringParams<File extends ComposerFile = ComposerFile> {
/** Consume the actual storage key selected by the composer’s autosave owner. */
consumeDraft: () => void;
index: number;
@@ -63,8 +54,8 @@ export interface UseSteeringParams {
/** Host-owned preparation hold; existing queued-message and Stop actions remain independent. */
composerDisabled?: boolean;
/** Composer attachments: consumed into queued items (steering is text-only). */
- files?: Map<string, ExtendedFile>;
- setFiles?: FileSetter;
+ files?: Map<string, File>;
+ setFiles?: ComposerFileSetter<File>;
/** Uploads still in flight: during-run submits are held like the send button. */
filesLoading?: boolean;
/** Submits text (and optional attachments/quotes/skills) as a normal new
@@ -82,6 +73,53 @@ export interface UseSteeringParams {
stopGenerating: () => void;
}
+/** What the composer, the queue rail and the pending steers drive a run's steering through. */
+export interface SteeringControls {
+ enabled: boolean;
+ queueKey: string;
+ canSteer: boolean;
+ canControlGeneration: boolean;
+ duringRunActive: boolean;
+ canSendQueuedNow: boolean;
+ effectiveAction: DuringRunAction;
+ defaultAction: DuringRunAction;
+ pendingReasoningOverride: TMessage['reasoningOverride'];
+ pausedOnApproval: boolean;
+ setDefaultAction: (action: DuringRunAction) => void;
+ submitDuringRun: DuringRunActions['submitDuringRun'];
+ steerFromComposer: DuringRunActions['steerFromComposer'];
+ queueFromComposer: DuringRunActions['queueFromComposer'];
+ submitSteer: SubmitSteer;
+ retrySteer: (
+ steerId: string,
+ text: string,
+ steerFiles?: TMessage['files'],
+ context?: QueuedMessageContext,
+ opts?: SubmitSteerOptions,
+ ) => void;
+ removeSteer: (steerId: string) => void;
+ convertSteerToQueue: (
+ steerId: string,
+ text: string,
+ steerFiles?: TMessage['files'],
+ context?: QueuedMessageContext,
+ queuedOrigin?: QueuedMessageOrigin,
+ ) => void;
+ queueReclaimedSteer: (steer: PendingSteer) => void;
+ enqueue: QueueEnqueue['enqueue'];
+ removeQueued: QueueRows['removeQueued'];
+ holdQueued: QueueRows['holdQueued'];
+ toggleQueuedHold: QueueRows['toggleQueuedHold'];
+ discardQueued: QueuedRecovery['discardQueued'];
+ dismissRecovery: QueuedRecovery['dismissRecovery'];
+ rewakeDrain: QueueRows['rewakeDrain'];
+ reorderQueued: QueueRows['reorderQueued'];
+ restoreQueuedOrder: QueueRows['restoreQueuedOrder'];
+ sendQueuedNow: QueuedSend['sendQueuedNow'];
+ interruptAndSend: DuringRunActions['interruptAndSend'];
+ interruptSteer: DuringRunActions['interruptSteer'];
+}
+
/**
* The composer's during-run brain: decides what Enter does while a run is
* generating (steer vs queue, per the user preference and run state), owns the
@@ -89,7 +127,7 @@ export interface UseSteeringParams {
* steer (POST + optimistic chip), queue (client-side), and interrupt & send
* (abort, then auto-send via the one-shot drain override).
*/
-export default function useSteering({
+export default function useSteering<File extends ComposerFile = ComposerFile>({
consumeDraft: takeComposerDraft,
index,
conversationId,
@@ -104,7 +142,7 @@ export default function useSteering({
filesLoading = false,
sendNow,
stopGenerating,
-}: UseSteeringParams) {
+}: UseSteeringParams<File>): SteeringControls {
const composerDisabledRef = useRef(composerDisabled);
composerDisabledRef.current = composerDisabled;
const host = useSteerHost();
@@ -433,5 +471,3 @@ export default function useSteering({
],
);
}
-
-export type SteeringControls = ReturnType<typeof useSteering>;