Skip to content

Commit b555cfe

Browse files
authored
feat: add back hasSession$ (#47)
* feat: add back hasSession$ * style: remove console log
1 parent cc37ad7 commit b555cfe

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/components/ChatInput.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ interface Props {
3030
defaultModel?: string;
3131
availableModels?: string[];
3232
autoFocus$: Observable<boolean>;
33+
hasSession$: Observable<boolean>;
3334
}
3435

3536
export const ChatInput: FC<Props> = ({
@@ -40,6 +41,7 @@ export const ChatInput: FC<Props> = ({
4041
defaultModel = '',
4142
availableModels = [],
4243
autoFocus$,
44+
hasSession$,
4345
}) => {
4446
const [message, setMessage] = useState('');
4547
const [streamingEnabled, setStreamingEnabled] = useState(true);
@@ -51,14 +53,16 @@ export const ChatInput: FC<Props> = ({
5153
const autoFocus = use$(autoFocus$);
5254
const conversation = use$(conversations$.get(conversationId));
5355
const isGenerating = conversation?.isGenerating || false;
54-
56+
const hasSession = use$(hasSession$);
5557
const placeholder = isReadOnly
5658
? 'This is a demo conversation (read-only)'
5759
: !isConnected
5860
? 'Connect to gptme to send messages'
59-
: 'Send a message...';
61+
: !hasSession
62+
? 'Waiting for chat session to be established...'
63+
: 'Send a message...';
6064

61-
const isDisabled = isReadOnly || !isConnected;
65+
const isDisabled = isReadOnly || !isConnected || !hasSession;
6266

6367
// Focus the textarea when autoFocus is true and component is interactive
6468
useEffect(() => {

src/components/ConversationContent.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Label } from './ui/label';
88
import { ToolConfirmationDialog } from './ToolConfirmationDialog';
99
import { For, Memo, useObservable, useObserveEffect } from '@legendapp/state/react';
1010
import { getObservableIndex } from '@legendapp/state';
11+
import { useApi } from '@/contexts/ApiContext';
1112

1213
interface Props {
1314
conversationId: string;
@@ -33,6 +34,15 @@ export const ConversationContent: FC<Props> = ({ conversationId, isReadOnly }) =
3334
// Store the previous conversation ID to detect changes
3435
const prevConversationIdRef = useRef<string | null>(null);
3536

37+
const { api } = useApi();
38+
const hasSession$ = useObservable<boolean>(false);
39+
40+
useObserveEffect(api.sessions$.get(conversationId), () => {
41+
if (!isReadOnly) {
42+
hasSession$.set(api.sessions$.get(conversationId).get() !== undefined);
43+
}
44+
});
45+
3646
// Detect when the conversation changes and set focus
3747
useEffect(() => {
3848
if (conversationId !== prevConversationIdRef.current) {
@@ -216,6 +226,7 @@ export const ConversationContent: FC<Props> = ({ conversationId, isReadOnly }) =
216226
onSend={handleSendMessage}
217227
onInterrupt={interruptGeneration}
218228
isReadOnly={isReadOnly}
229+
hasSession$={hasSession$}
219230
defaultModel={AVAILABLE_MODELS[0]}
220231
availableModels={AVAILABLE_MODELS}
221232
autoFocus$={shouldFocus$}

0 commit comments

Comments
 (0)