Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions client/src/Providers/ComposerPreferencesContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createContext, useContext } from 'react';

/**
* The reader's composer preferences, which belong to the app and which a composer only
* consumes. The chat view reads them once and hands them to every composer under it: main
* chat's, and the one of a conversation open beside it.
*/
export type ComposerPreferences = {
/** Whether Enter sends the message rather than adding a line. */
enterToSend: boolean;
/** Seconds after which dictated text is sent by itself; negative for never. */
autoSendText: number;
/** Whether the shell has loaded the speech settings yet; dictation stays off until it has. */
speechSettingsInitialized: boolean;
};

/** The preferences' own defaults, for a composer drawn outside a chat view. */
export const defaultComposerPreferences: ComposerPreferences = {
enterToSend: true,
autoSendText: -1,
speechSettingsInitialized: false,
};

export const ComposerPreferencesContext = createContext<ComposerPreferences>(
defaultComposerPreferences,
);

export const useComposerPreferences = (): ComposerPreferences =>
useContext(ComposerPreferencesContext);
24 changes: 22 additions & 2 deletions client/src/Providers/SideChatHostContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useCallback, useMemo } from 'react';
import { useFollowChat } from '@librechat/chat/react';
import { useStore } from 'jotai';
import { useQueryClient } from '@tanstack/react-query';
import { createGenerationTransport } from '@librechat/chat';
import { filesFamily, useFollowChat, SIDE_CHAT_PANE } from '@librechat/chat/react';
import {
dataService,
QueryKeys,
Expand All @@ -11,11 +12,13 @@ import {
import type { Agent, TMessage, TConversation, ChatFinalFrame } from 'librechat-data-provider';
import type { FollowedChat, SideChatHost, FollowChatOptions } from '@librechat/chat/react';
import { isTemporaryConversation, proveFetchedReplyByIdentity } from '~/utils';
import { stagedForHandoff, handedComposerFilesFamily } from '~/store/handoff';
import useNavigateToConvo from '~/hooks/Conversations/useNavigateToConvo';
import useAttachmentHandler from '~/hooks/SSE/useAttachmentHandler';
import { ARTIFACTS_SHEET_MAX_WIDTH } from '~/utils/breakpoints';
import { createConversationCache } from '~/hooks/SSE/services';
import { useConfiguredFooter } from '~/components/Chat/Footer';
import SideChatSurface from '~/components/Chat/Side/Surface';
import { retryTransientQuery } from '~/data-provider/retry';
import useScaledMaxWidth from '~/hooks/useScaledMaxWidth';
import { useChatTransport } from './ChatTransportContext';
Expand Down Expand Up @@ -122,9 +125,25 @@ function useChat(
});
}

/**
* Opens the side conversation as the page's main chat. What its composer has staged and
* finished uploading goes with it: taken from the side pane before the navigation clears every
* pane's files, and left for main chat's composer to pick up once it holds the conversation.
*/
function useOpenConversation(): (conversation: TConversation) => void {
const { navigateToConvo } = useNavigateToConvo();
return useCallback((conversation) => navigateToConvo(conversation), [navigateToConvo]);
const store = useStore();
return useCallback(
(conversation) => {
const staged = stagedForHandoff(store.get(filesFamily(SIDE_CHAT_PANE)));
const { conversationId } = conversation;
if (staged.size > 0 && conversationId != null && conversationId !== '') {
store.set(handedComposerFilesFamily(conversationId), staged);
}
navigateToConvo(conversation);
},
[navigateToConvo, store],
);
}

/** What a side chat reads from the app. */
Expand All @@ -133,4 +152,5 @@ export const appSideChatHost: SideChatHost = {
useOpenConversation,
useSheetLayout: () => useScaledMaxWidth(ARTIFACTS_SHEET_MAX_WIDTH),
useClearsFooter: useConfiguredFooter,
Surface: SideChatSurface,
};
2 changes: 1 addition & 1 deletion client/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export type LocalizeFunction = (

export type ChatFormValues = { text: string };

export { mainTextareaId } from '@librechat/chat';
export { mainTextareaId, composerTextareaId } from '@librechat/chat';
export const globalAudioId = 'global-audio';

export type NavLink = {
Expand Down
130 changes: 71 additions & 59 deletions client/src/components/Chat/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { ChatFormValues } from '~/common';
import { AddedChatContext, ChatFormProvider, useChatContext, useFileMapContext } from '~/Providers';
import { AssistantsMapContext, useAssistantsMapContext } from '~/Providers/AssistantsMapContext';
import { AgentsMapContext, useAgentsMapContext } from '~/Providers/AgentsMapContext';
import { ComposerPreferencesContext } from '~/Providers/ComposerPreferencesContext';
import Footer, { useLandingFooter, useConfiguredFooter } from './Footer';
import { useChatSettings } from '~/Providers/ChatSettingsContext';
import ApprovalProvider from './Messages/Content/ApprovalContext';
Expand Down Expand Up @@ -109,6 +110,10 @@ function ChatViewPane({
const methods = useForm<ChatFormValues>({
defaultValues: { text: '' },
});
const composerPreferences = useMemo(
() => ({ enterToSend, autoSendText, speechSettingsInitialized }),
[enterToSend, autoSendText, speechSettingsInitialized],
);

const fileMap = useFileMapContext();
const chat = useChatContext();
Expand Down Expand Up @@ -157,69 +162,76 @@ function ChatViewPane({
<QueuedTurnPortalProvider>
<AddedChatContext.Provider value={addedChatHelpers}>
<ApprovalProvider pendingAction={pendingAction}>
<Presentation routePending={routePending}>
<TraceSurface conversationId={conversationId}>
<ChatScreen
index={index}
conversationId={conversationId}
messages={messages}
fileMap={fileMap}
isLoading={isLoading}
project={project}
landingFooter={landingFooter}
configuredFooter={configuredFooter}
renderHeader={({ parentConversationId, readOnly }) => (
<Header
parentConversationId={parentConversationId}
readOnly={readOnly}
/>
)}
renderBadge={(projectId) => <ProjectBadge projectId={projectId} />}
renderMessages={renderMessages}
landing={<Landing centerFormOnLanding={centerFormOnLanding} />}
renderColumn={(column, { isLanding }) => (
<OwnerTextProvider
messages={messages}
conversationId={conversationId}
isSubmitting={chat.isSubmitting}
>
{/* The welcome screen only, behind its column: a theme's
<ComposerPreferencesContext.Provider value={composerPreferences}>
<Presentation routePending={routePending}>
<TraceSurface conversationId={conversationId}>
<ChatScreen
index={index}
conversationId={conversationId}
messages={messages}
fileMap={fileMap}
isLoading={isLoading}
project={project}
landingFooter={landingFooter}
configuredFooter={configuredFooter}
renderHeader={({ parentConversationId, readOnly }) => (
<Header
parentConversationId={parentConversationId}
readOnly={readOnly}
/>
)}
renderBadge={(projectId) => <ProjectBadge projectId={projectId} />}
renderMessages={renderMessages}
landing={<Landing centerFormOnLanding={centerFormOnLanding} />}
renderColumn={(column, { isLanding }) => (
<OwnerTextProvider
messages={messages}
conversationId={conversationId}
isSubmitting={chat.isSubmitting}
>
{/* The welcome screen only, behind its column: a theme's
backdrop covers the greeting and the composer together and
goes with them on the first message. It paints nothing unless
the theme asks and the build registers one. */}
{isLanding && <WelcomeBackdrop />}
{column}
</OwnerTextProvider>
)}
starters={<ConversationStarters />}
renderComposer={({ isLanding, footerBelow, project, placeholder }) => (
/* Typing a first message is the cue that the list is next. */
<div className="contents" onFocusCapture={warmMessages}>
<ChatForm
index={index}
routePending={routePending}
placeholder={placeholder}
project={project}
isLandingPage={isLanding}
enterToSend={enterToSend}
autoSendText={autoSendText}
speechSettingsInitialized={speechSettingsInitialized}
footerBelow={footerBelow}
centerFormOnLanding={centerFormOnLanding}
{isLanding && <WelcomeBackdrop />}
{column}
</OwnerTextProvider>
)}
starters={<ConversationStarters />}
renderComposer={({
isLanding,
footerBelow,
project,
placeholder,
}) => (
/* Typing a first message is the cue that the list is next. */
<div className="contents" onFocusCapture={warmMessages}>
<ChatForm
index={index}
routePending={routePending}
placeholder={placeholder}
project={project}
isLandingPage={isLanding}
enterToSend={enterToSend}
autoSendText={autoSendText}
speechSettingsInitialized={speechSettingsInitialized}
footerBelow={footerBelow}
centerFormOnLanding={centerFormOnLanding}
/>
</div>
)}
renderFooter={renderFooter}
renderMascot={(bandRef, landing) => (
<Lia
bandRef={bandRef}
landing={landing}
submission={rootSubmission}
/>
</div>
)}
renderFooter={renderFooter}
renderMascot={(bandRef, landing) => (
<Lia
bandRef={bandRef}
landing={landing}
submission={rootSubmission}
/>
)}
/>
</TraceSurface>
</Presentation>
)}
/>
</TraceSurface>
</Presentation>
</ComposerPreferencesContext.Provider>
</ApprovalProvider>
</AddedChatContext.Provider>
</QueuedTurnPortalProvider>
Expand Down
Loading
Loading