Restore recipe parameters functionality (#3530)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { createContext, useContext, ReactNode } from 'react';
|
||||
import { ChatType } from '../components/BaseChat';
|
||||
import { ChatType } from '../types/chat';
|
||||
import { generateSessionId } from '../sessions';
|
||||
import { Recipe } from '../recipe';
|
||||
import { useDraftContext } from './DraftContext';
|
||||
@@ -11,6 +11,8 @@ interface ChatContextType {
|
||||
hasActiveSession: boolean;
|
||||
setRecipeConfig: (recipe: Recipe | null) => void;
|
||||
clearRecipeConfig: () => void;
|
||||
setRecipeParameters: (parameters: Record<string, string> | null) => void;
|
||||
clearRecipeParameters: () => void;
|
||||
// Draft functionality
|
||||
draft: string;
|
||||
setDraft: (draft: string) => void;
|
||||
@@ -55,6 +57,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
||||
messages: [],
|
||||
messageHistoryIndex: 0,
|
||||
recipeConfig: null, // Clear recipe when resetting chat
|
||||
recipeParameters: null, // Clear parameters when resetting chat
|
||||
});
|
||||
// Clear draft when resetting chat
|
||||
clearDraft();
|
||||
@@ -74,6 +77,20 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
||||
});
|
||||
};
|
||||
|
||||
const setRecipeParameters = (parameters: Record<string, string> | null) => {
|
||||
setChat({
|
||||
...chat,
|
||||
recipeParameters: parameters,
|
||||
});
|
||||
};
|
||||
|
||||
const clearRecipeParameters = () => {
|
||||
setChat({
|
||||
...chat,
|
||||
recipeParameters: null,
|
||||
});
|
||||
};
|
||||
|
||||
const hasActiveSession = chat.messages.length > 0;
|
||||
|
||||
const value: ChatContextType = {
|
||||
@@ -83,6 +100,8 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
||||
hasActiveSession,
|
||||
setRecipeConfig,
|
||||
clearRecipeConfig,
|
||||
setRecipeParameters,
|
||||
clearRecipeParameters,
|
||||
draft,
|
||||
setDraft,
|
||||
clearDraft,
|
||||
|
||||
Reference in New Issue
Block a user