Removed drafts and agentIsReady in ChatInput (#5366)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import React, { createContext, useContext, ReactNode } from 'react';
|
||||
import { ChatType } from '../types/chat';
|
||||
import { Recipe } from '../recipe';
|
||||
import { useDraftContext } from './DraftContext';
|
||||
|
||||
// TODO(Douwe): We should not need this anymore
|
||||
export const DEFAULT_CHAT_TITLE = 'New Chat';
|
||||
@@ -13,10 +12,6 @@ interface ChatContextType {
|
||||
hasActiveSession: boolean;
|
||||
setRecipe: (recipe: Recipe | null) => void;
|
||||
clearRecipe: () => void;
|
||||
// Draft functionality
|
||||
draft: string;
|
||||
setDraft: (draft: string) => void;
|
||||
clearDraft: () => void;
|
||||
// Context identification
|
||||
contextKey: string; // 'hub' or 'pair-{sessionId}'
|
||||
agentWaitingMessage: string | null;
|
||||
@@ -39,19 +34,6 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
||||
agentWaitingMessage,
|
||||
contextKey = 'hub',
|
||||
}) => {
|
||||
const draftContext = useDraftContext();
|
||||
|
||||
// Draft functionality using the app-level DraftContext
|
||||
const draft = draftContext.getDraft(contextKey);
|
||||
|
||||
const setDraft = (newDraft: string) => {
|
||||
draftContext.setDraft(contextKey, newDraft);
|
||||
};
|
||||
|
||||
const clearDraft = () => {
|
||||
draftContext.clearDraft(contextKey);
|
||||
};
|
||||
|
||||
const resetChat = () => {
|
||||
setChat({
|
||||
sessionId: '',
|
||||
@@ -61,7 +43,6 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
||||
recipe: null,
|
||||
recipeParameterValues: null,
|
||||
});
|
||||
clearDraft();
|
||||
};
|
||||
|
||||
const setRecipe = (recipe: Recipe | null) => {
|
||||
@@ -88,9 +69,6 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
||||
hasActiveSession,
|
||||
setRecipe,
|
||||
clearRecipe,
|
||||
draft,
|
||||
setDraft,
|
||||
clearDraft,
|
||||
contextKey,
|
||||
agentWaitingMessage,
|
||||
};
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
import React, { createContext, useContext, useState, ReactNode } from 'react';
|
||||
|
||||
interface DraftContextType {
|
||||
getDraft: (contextKey: string) => string;
|
||||
setDraft: (contextKey: string, draft: string) => void;
|
||||
clearDraft: (contextKey: string) => void;
|
||||
}
|
||||
|
||||
const DraftContext = createContext<DraftContextType | undefined>(undefined);
|
||||
|
||||
export const DraftProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||
// Store all drafts by contextKey
|
||||
const [drafts, setDrafts] = useState<Record<string, string>>({});
|
||||
|
||||
const getDraft = (contextKey: string): string => {
|
||||
return drafts[contextKey] || '';
|
||||
};
|
||||
|
||||
const setDraft = (contextKey: string, draft: string) => {
|
||||
setDrafts((prev) => ({ ...prev, [contextKey]: draft }));
|
||||
};
|
||||
|
||||
const clearDraft = (contextKey: string) => {
|
||||
setDrafts((prev) => {
|
||||
const newDrafts = { ...prev };
|
||||
delete newDrafts[contextKey];
|
||||
return newDrafts;
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<DraftContext.Provider value={{ getDraft, setDraft, clearDraft }}>
|
||||
{children}
|
||||
</DraftContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useDraftContext = (): DraftContextType => {
|
||||
const context = useContext(DraftContext);
|
||||
if (context === undefined) {
|
||||
throw new Error('useDraftContext must be used within a DraftProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
Reference in New Issue
Block a user