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:
Douwe Osinga
2025-09-03 10:31:24 -04:00
committed by GitHub
parent db94c5b7c3
commit d2195289cf
65 changed files with 1473 additions and 1601 deletions
+3 -20
View File
@@ -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,