Add session to agents (#4216)
Co-authored-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Jack Amadeo <jackamadeo@squareup.com> Co-authored-by: Jack Amadeo <jackamadeo@block.xyz>
This commit is contained in:
@@ -4,6 +4,7 @@ import { generateSessionId } from '../sessions';
|
||||
import { Recipe } from '../recipe';
|
||||
import { useDraftContext } from './DraftContext';
|
||||
|
||||
// TODO(Douwe): We should not need this anymore
|
||||
export const DEFAULT_CHAT_TITLE = 'New Chat';
|
||||
|
||||
interface ChatContextType {
|
||||
@@ -13,8 +14,6 @@ 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;
|
||||
@@ -57,12 +56,12 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
||||
const resetChat = () => {
|
||||
const newSessionId = generateSessionId();
|
||||
setChat({
|
||||
id: newSessionId,
|
||||
sessionId: newSessionId,
|
||||
title: DEFAULT_CHAT_TITLE,
|
||||
messages: [],
|
||||
messageHistoryIndex: 0,
|
||||
recipeConfig: null, // Clear recipe when resetting chat
|
||||
recipeParameters: null, // Clear parameters when resetting chat
|
||||
recipeParameters: null, // Clear when resetting chat
|
||||
});
|
||||
// Clear draft when resetting chat
|
||||
clearDraft();
|
||||
@@ -82,20 +81,6 @@ 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 = {
|
||||
@@ -105,8 +90,6 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
||||
hasActiveSession,
|
||||
setRecipeConfig,
|
||||
clearRecipeConfig,
|
||||
setRecipeParameters,
|
||||
clearRecipeParameters,
|
||||
draft,
|
||||
setDraft,
|
||||
clearDraft,
|
||||
|
||||
Reference in New Issue
Block a user