diff --git a/packages/chat-client/src/api/orchestration.js b/packages/chat-client/src/api/orchestration.js index 5f3674c..e019bf2 100644 --- a/packages/chat-client/src/api/orchestration.js +++ b/packages/chat-client/src/api/orchestration.js @@ -142,4 +142,21 @@ export async function fetchModels() { const res = await fetch(`${BASE_URL}/models`); if(!res.ok) throw new Error(`Failted to fetch models: ${res.status}`); return res.json(); +} + +export async function renameSession(sessionId, name) { + const res = await fetch(`${BASE_URL}/sessions/${sessionId}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ name }), + }); + if (!res.ok) throw new Error(`Failed to rename session: ${res.status}`); + return res.json(); +} + +export async function deleteSession(sessionId) { + const res = await fetch(`${BASE_URL}/sessions/${sessionId}`, { + method: 'DELETE', + }); + if (!res.ok) throw new Error(`Failed to delete session: ${res.status}`); } \ No newline at end of file diff --git a/packages/chat-client/src/components/SessionModal.jsx b/packages/chat-client/src/components/SessionModal.jsx new file mode 100644 index 0000000..e69de29 diff --git a/packages/chat-client/src/hooks/useContextMenu.js b/packages/chat-client/src/hooks/useContextMenu.js new file mode 100644 index 0000000..6c86ee2 --- /dev/null +++ b/packages/chat-client/src/hooks/useContextMenu.js @@ -0,0 +1,22 @@ +import { useState, useEffect, useCallback } from 'react'; + +export function useContextMenu() { + const [menu, setMenu] = useState(null); // { x, y, session } + + const open = useCallback((e, session) => { + e.preventDefault(); + setMenu({ x: e.clientX, y: e.clientY, session }); + }, []); + + const close = useCallback(() => setMenu(null), []); + + // Close on any click outside + useEffect(() => { + if (!menu) return; + const handler = () => close(); + window.addEventListener('click', handler); + return () => window.removeEventListener('click', handler); + }, [menu, close]); + + return { menu, open, close }; +} \ No newline at end of file diff --git a/packages/orchestration-service/src/routes/sessions.js b/packages/orchestration-service/src/routes/sessions.js index 4068321..16791fd 100644 --- a/packages/orchestration-service/src/routes/sessions.js +++ b/packages/orchestration-service/src/routes/sessions.js @@ -29,4 +29,25 @@ router.get('/', async (req, res) => { } }) +router.patch('/:sessionId', async (req, res) => { + const { name } = req.body; + if (!name?.trim()) return res.status(400).json({ error: 'name is required' }); + + try { + const session = await memory.updateSession(req.params.sessionId, { name: name.trim() }); + res.json(session); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +router.delete('/:sessionId', async (req, res) => { + try { + await memory.deleteSession(req.params.sessionId); + res.status(204).send(); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + module.exports = router; \ No newline at end of file diff --git a/packages/orchestration-service/src/services/memory.js b/packages/orchestration-service/src/services/memory.js index a59e246..a9531a8 100644 --- a/packages/orchestration-service/src/services/memory.js +++ b/packages/orchestration-service/src/services/memory.js @@ -63,6 +63,23 @@ async function getSessions(limit = EPISODIC.DEFAULT_SESSIONS_LIMIT, offset = EPI return res.json(); } +async function updateSession(externalId, { name }) { + const res = await fetch(`${BASE_URL}/sessions/by-external/${externalId}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ name }), + }); + if (!res.ok) throw new Error(`Failed to update session: ${res.status}`); + return res.json(); +} + +async function deleteSession(externalId) { + const res = await fetch(`${BASE_URL}/sessions/by-external/${externalId}`, { + method: 'DELETE', + }); + if (!res.ok) throw new Error(`Failed to delete session: ${res.status}`); +} + module.exports = { getSessionByExternalId, createSession, @@ -70,5 +87,7 @@ module.exports = { createEpisode, getEpisodeById, getSessionHistory, - getSessions + getSessions, + updateSession, + deleteSession, } \ No newline at end of file