From ca3290620280fdea1b0312f42cf9c2ae4e604c8d Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Tue, 26 Nov 2024 20:10:50 +0000 Subject: [PATCH 1/7] add cleanup for generated audio files; ensure temporary files are removed after processing --- api/src/utils/generate_audiocast.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/src/utils/generate_audiocast.py b/api/src/utils/generate_audiocast.py index 5ba3530..2adfe1e 100644 --- a/api/src/utils/generate_audiocast.py +++ b/api/src/utils/generate_audiocast.py @@ -1,3 +1,5 @@ +import os + from fastapi import BackgroundTasks, HTTPException from src.services.storage import StorageManager @@ -36,6 +38,9 @@ def post_generate_audio( waveform_utils.run_all() except Exception as e: print(f"Error in generate_audiocast background_tasks: {str(e)}") + finally: + if os.path.exists(audio_path): + os.remove(audio_path) async def generate_audiocast(request: GenerateAudioCastRequest, background_tasks: BackgroundTasks): From 35478e5d55b52da75ebcee3c4e0a8b551fbc591c Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Wed, 27 Nov 2024 14:31:44 +0000 Subject: [PATCH 2/7] install alert-dialog component --- app/package.json | 2 +- .../alert-dialog/alert-dialog-action.svelte | 21 ++++++++++ .../alert-dialog/alert-dialog-cancel.svelte | 21 ++++++++++ .../alert-dialog/alert-dialog-content.svelte | 28 +++++++++++++ .../alert-dialog-description.svelte | 16 ++++++++ .../alert-dialog/alert-dialog-footer.svelte | 16 ++++++++ .../alert-dialog/alert-dialog-header.svelte | 13 ++++++ .../alert-dialog/alert-dialog-overlay.svelte | 21 ++++++++++ .../alert-dialog/alert-dialog-portal.svelte | 9 +++++ .../ui/alert-dialog/alert-dialog-title.svelte | 14 +++++++ .../lib/components/ui/alert-dialog/index.ts | 40 +++++++++++++++++++ pnpm-lock.yaml | 6 +-- 12 files changed, 203 insertions(+), 4 deletions(-) create mode 100644 app/src/lib/components/ui/alert-dialog/alert-dialog-action.svelte create mode 100644 app/src/lib/components/ui/alert-dialog/alert-dialog-cancel.svelte create mode 100644 app/src/lib/components/ui/alert-dialog/alert-dialog-content.svelte create mode 100644 app/src/lib/components/ui/alert-dialog/alert-dialog-description.svelte create mode 100644 app/src/lib/components/ui/alert-dialog/alert-dialog-footer.svelte create mode 100644 app/src/lib/components/ui/alert-dialog/alert-dialog-header.svelte create mode 100644 app/src/lib/components/ui/alert-dialog/alert-dialog-overlay.svelte create mode 100644 app/src/lib/components/ui/alert-dialog/alert-dialog-portal.svelte create mode 100644 app/src/lib/components/ui/alert-dialog/alert-dialog-title.svelte create mode 100644 app/src/lib/components/ui/alert-dialog/index.ts diff --git a/app/package.json b/app/package.json index 02aaad1..1e69c2d 100644 --- a/app/package.json +++ b/app/package.json @@ -19,7 +19,6 @@ "test": "npm run test:integration && npm run test:unit" }, "dependencies": { - "bits-ui": "^0.21.16", "canvas-confetti": "^1.9.3", "clsx": "^2.1.1", "copy-to-clipboard": "^3.3.3", @@ -55,6 +54,7 @@ "@types/ramda": "^0.30.1", "@types/throttle-debounce": "^5.0.2", "autoprefixer": "^10.4.20", + "bits-ui": "^0.21.16", "eslint": "^9.0.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.36.0", diff --git a/app/src/lib/components/ui/alert-dialog/alert-dialog-action.svelte b/app/src/lib/components/ui/alert-dialog/alert-dialog-action.svelte new file mode 100644 index 0000000..51dbd6a --- /dev/null +++ b/app/src/lib/components/ui/alert-dialog/alert-dialog-action.svelte @@ -0,0 +1,21 @@ + + + + + diff --git a/app/src/lib/components/ui/alert-dialog/alert-dialog-cancel.svelte b/app/src/lib/components/ui/alert-dialog/alert-dialog-cancel.svelte new file mode 100644 index 0000000..88b2cf7 --- /dev/null +++ b/app/src/lib/components/ui/alert-dialog/alert-dialog-cancel.svelte @@ -0,0 +1,21 @@ + + + + + diff --git a/app/src/lib/components/ui/alert-dialog/alert-dialog-content.svelte b/app/src/lib/components/ui/alert-dialog/alert-dialog-content.svelte new file mode 100644 index 0000000..b6efc0d --- /dev/null +++ b/app/src/lib/components/ui/alert-dialog/alert-dialog-content.svelte @@ -0,0 +1,28 @@ + + + + + + + + diff --git a/app/src/lib/components/ui/alert-dialog/alert-dialog-description.svelte b/app/src/lib/components/ui/alert-dialog/alert-dialog-description.svelte new file mode 100644 index 0000000..972cc63 --- /dev/null +++ b/app/src/lib/components/ui/alert-dialog/alert-dialog-description.svelte @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/lib/components/ui/alert-dialog/alert-dialog-footer.svelte b/app/src/lib/components/ui/alert-dialog/alert-dialog-footer.svelte new file mode 100644 index 0000000..e843c0d --- /dev/null +++ b/app/src/lib/components/ui/alert-dialog/alert-dialog-footer.svelte @@ -0,0 +1,16 @@ + + +
+ +
diff --git a/app/src/lib/components/ui/alert-dialog/alert-dialog-header.svelte b/app/src/lib/components/ui/alert-dialog/alert-dialog-header.svelte new file mode 100644 index 0000000..88bf04b --- /dev/null +++ b/app/src/lib/components/ui/alert-dialog/alert-dialog-header.svelte @@ -0,0 +1,13 @@ + + +
+ +
diff --git a/app/src/lib/components/ui/alert-dialog/alert-dialog-overlay.svelte b/app/src/lib/components/ui/alert-dialog/alert-dialog-overlay.svelte new file mode 100644 index 0000000..659bb81 --- /dev/null +++ b/app/src/lib/components/ui/alert-dialog/alert-dialog-overlay.svelte @@ -0,0 +1,21 @@ + + + diff --git a/app/src/lib/components/ui/alert-dialog/alert-dialog-portal.svelte b/app/src/lib/components/ui/alert-dialog/alert-dialog-portal.svelte new file mode 100644 index 0000000..e227219 --- /dev/null +++ b/app/src/lib/components/ui/alert-dialog/alert-dialog-portal.svelte @@ -0,0 +1,9 @@ + + + + + diff --git a/app/src/lib/components/ui/alert-dialog/alert-dialog-title.svelte b/app/src/lib/components/ui/alert-dialog/alert-dialog-title.svelte new file mode 100644 index 0000000..594fe5e --- /dev/null +++ b/app/src/lib/components/ui/alert-dialog/alert-dialog-title.svelte @@ -0,0 +1,14 @@ + + + + + diff --git a/app/src/lib/components/ui/alert-dialog/index.ts b/app/src/lib/components/ui/alert-dialog/index.ts new file mode 100644 index 0000000..be56dd7 --- /dev/null +++ b/app/src/lib/components/ui/alert-dialog/index.ts @@ -0,0 +1,40 @@ +import { AlertDialog as AlertDialogPrimitive } from "bits-ui"; + +import Title from "./alert-dialog-title.svelte"; +import Action from "./alert-dialog-action.svelte"; +import Cancel from "./alert-dialog-cancel.svelte"; +import Portal from "./alert-dialog-portal.svelte"; +import Footer from "./alert-dialog-footer.svelte"; +import Header from "./alert-dialog-header.svelte"; +import Overlay from "./alert-dialog-overlay.svelte"; +import Content from "./alert-dialog-content.svelte"; +import Description from "./alert-dialog-description.svelte"; + +const Root = AlertDialogPrimitive.Root; +const Trigger = AlertDialogPrimitive.Trigger; + +export { + Root, + Title, + Action, + Cancel, + Portal, + Footer, + Header, + Trigger, + Overlay, + Content, + Description, + // + Root as AlertDialog, + Title as AlertDialogTitle, + Action as AlertDialogAction, + Cancel as AlertDialogCancel, + Portal as AlertDialogPortal, + Footer as AlertDialogFooter, + Header as AlertDialogHeader, + Trigger as AlertDialogTrigger, + Overlay as AlertDialogOverlay, + Content as AlertDialogContent, + Description as AlertDialogDescription, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e23ba7c..4339e7d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,9 +29,6 @@ importers: app: dependencies: - bits-ui: - specifier: ^0.21.16 - version: 0.21.16(svelte@4.2.19) canvas-confetti: specifier: ^1.9.3 version: 1.9.3 @@ -132,6 +129,9 @@ importers: autoprefixer: specifier: ^10.4.20 version: 10.4.20(postcss@8.4.49) + bits-ui: + specifier: ^0.21.16 + version: 0.21.16(svelte@4.2.19) eslint: specifier: ^9.0.0 version: 9.14.0(jiti@1.21.6) From 5f3c50f86d63dcba53cf32f7f5124c3c3cd67bb9 Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Wed, 27 Nov 2024 14:41:43 +0000 Subject: [PATCH 3/7] wip: use a sidebar_item_action --- app/src/lib/components/SidebarItem.svelte | 10 ++-- .../lib/components/SidebarItemActions.svelte | 51 +++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 app/src/lib/components/SidebarItemActions.svelte diff --git a/app/src/lib/components/SidebarItem.svelte b/app/src/lib/components/SidebarItem.svelte index aef35b3..10ce671 100644 --- a/app/src/lib/components/SidebarItem.svelte +++ b/app/src/lib/components/SidebarItem.svelte @@ -15,13 +15,11 @@ import { page } from '$app/stores'; import { Button } from './ui/button'; import { cn } from '@/utils/ui.utils'; + import SidebarItemActions from './SidebarItemActions.svelte'; export let item: SidebarItemModel; - const [send, receive] = crossfade({ - duration: 250, - easing: cubicInOut - }); + const [send, receive] = crossfade({ duration: 250, easing: cubicInOut }); $: href = item.completed ? `/audiocast/${item.sessionId}` @@ -52,7 +50,9 @@ {item.title} - - - Open - - - Delete audiocast? - - This action cannot be undone. This will permanently delete your audiocast data. - - - - (openDialog = false)}>Cancel - Continue - - - +{#if openDialog} + + + + Delete audiocast? + + This action cannot be undone. This will permanently delete your audiocast data. + + + + + (openDialog = false)}>Cancel + + Continue + + + + +{/if} From 494d1d230a69757a1b2f3a4d38ce1c63ac956d79 Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Wed, 27 Nov 2024 15:12:36 +0000 Subject: [PATCH 5/7] create sessionItems$ store value --- app/src/lib/components/Sidebar.svelte | 20 +++----------------- app/src/lib/stores/sessionContext.svelte.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/src/lib/components/Sidebar.svelte b/app/src/lib/components/Sidebar.svelte index fb12f09..45e4c43 100644 --- a/app/src/lib/components/Sidebar.svelte +++ b/app/src/lib/components/Sidebar.svelte @@ -6,8 +6,7 @@ diff --git a/app/src/lib/components/RenderExamples.svelte b/app/src/lib/components/RenderExamples.svelte index fb4f041..6a3e3ea 100644 --- a/app/src/lib/components/RenderExamples.svelte +++ b/app/src/lib/components/RenderExamples.svelte @@ -29,7 +29,7 @@
{#each contentExamplesDict as [category, content]} - {@const href = `/chat/${sessionId}?category=${category}`} + {@const href = `/chat/${sessionId}?category=${category}&chat`} {/each}
diff --git a/app/src/lib/components/Sidebar.svelte b/app/src/lib/components/Sidebar.svelte index 45e4c43..3da27fd 100644 --- a/app/src/lib/components/Sidebar.svelte +++ b/app/src/lib/components/Sidebar.svelte @@ -1,34 +1,55 @@ -
Today
- {#each inLast24Hrs as item} - + {#each inLast24Hrs as item (item.sessionId)} + {/each}
Last 7 days
- {#each inLast7Days as item} - + {#each inLast7Days as item (item.sessionId)} + {/each}
Last month
- {#each inLast30Days as item} - + {#each inLast30Days as item (item.sessionId)} + {/each}
diff --git a/app/src/lib/components/SidebarItem.svelte b/app/src/lib/components/SidebarItem.svelte index bfc0428..bd6eb49 100644 --- a/app/src/lib/components/SidebarItem.svelte +++ b/app/src/lib/components/SidebarItem.svelte @@ -54,5 +54,5 @@ {item.category} - + diff --git a/app/src/lib/components/SidebarItemActions.svelte b/app/src/lib/components/SidebarItemActions.svelte index 5ac2f45..3bdef2d 100644 --- a/app/src/lib/components/SidebarItemActions.svelte +++ b/app/src/lib/components/SidebarItemActions.svelte @@ -1,23 +1,15 @@ @@ -44,7 +36,7 @@ (openDialog = false)}>Cancel Continue diff --git a/app/src/lib/stores/sessionContext.svelte.ts b/app/src/lib/stores/sessionContext.svelte.ts index 3f20310..21cd590 100644 --- a/app/src/lib/stores/sessionContext.svelte.ts +++ b/app/src/lib/stores/sessionContext.svelte.ts @@ -1,10 +1,11 @@ import { browser } from '$app/environment'; +import { page } from '$app/stores'; import { getCustomSources$ } from '@/db/db.customSources'; import { getSession$ } from '@/db/db.session'; import type { ContentCategory } from '@/utils/types'; import { setContext, getContext } from 'svelte'; import { persisted } from 'svelte-persisted-store'; -import { derived, writable } from 'svelte/store'; +import { derived, get, writable } from 'svelte/store'; const CONTEXT_KEY = {}; export const SESSION_KEY = 'AUDIOCAST_SESSION'; @@ -26,24 +27,15 @@ export type Session = { summary?: string; }; -export function getSessionItems() { - return Object.entries(localStorage) - .filter(([key]) => key.startsWith(SESSION_KEY)) - .map( - ([key, value]) => [key.replace(`${SESSION_KEY}_`, ''), JSON.parse(value) as Session] as const - ) - .filter(([_, v]) => Boolean(v)); -} - export function setSessionContext(sessionId: string) { - const session$ = persisted(`${SESSION_KEY}_${sessionId}`, null); const sessionId$ = writable(sessionId); + const session$ = persisted(`${SESSION_KEY}_${sessionId}`, null); const sessionCompleted$ = derived(session$, ($session) => !!$session?.completed); const fetchingSource$ = writable(false); const audioSource$ = persisted(`AUDIOCAST_SOURCE_${sessionId}`, ''); - const sessionItems$ = derived(session$, (v) => (browser || v ? getSessionItems() : [])); + const refreshSidebar$ = derived(page, ({ url }) => browser && url.searchParams.has('chat')); return setContext(CONTEXT_KEY, { session$, @@ -53,7 +45,7 @@ export function setSessionContext(sessionId: string) { audioSource$, customSources$: getCustomSources$(sessionId), sessionModel$: getSession$(sessionId), - sessionItems$, + refreshSidebar$, startSession: (category: ContentCategory) => { session$.set({ id: sessionId, diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte index 79f6d6b..201dd39 100644 --- a/app/src/routes/+page.svelte +++ b/app/src/routes/+page.svelte @@ -21,14 +21,14 @@ searchTerm = ''; } - function continueChat(category: ContentCategory) { + async function continueChat(category: ContentCategory) { startSession(category); const content = `${selectContent}\nCategory: ${category} `; addChatItem({ id: uuid(), content, role: 'user', loading: false }); - const href = `/chat/${sessionId}?category=${category}`; - goto(href); + const href = `/chat/${sessionId}?category=${category}&chat`; + return goto(href, { invalidateAll: true, replaceState: true }); } From bcabb28ab6cd1c2ca5e7fd638679b6cb3fd85b46 Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Wed, 27 Nov 2024 22:31:48 +0000 Subject: [PATCH 7/7] implement delete audiocast session on the server --- api/src/main.py | 9 +++++++++ api/src/utils/session_manager.py | 4 ++++ app/src/lib/components/Sidebar.svelte | 14 +++++++------- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/api/src/main.py b/api/src/main.py index 4d88349..3f142d9 100644 --- a/api/src/main.py +++ b/api/src/main.py @@ -190,3 +190,12 @@ async def save_uploaded_files_endpoint(files: list[UploadFile], sessionId: str = """ result = await UploadedFiles(session_id=sessionId)._save_sources(files) return result + + +@app.delete("/delete-session/{sessionId}") +def delete_session_endpoint(sessionId: str): + """ + Delete audiocast session + """ + SessionManager._delete_session(sessionId) + return "Deleted" diff --git a/api/src/utils/session_manager.py b/api/src/utils/session_manager.py index 37f57e5..704779e 100644 --- a/api/src/utils/session_manager.py +++ b/api/src/utils/session_manager.py @@ -146,3 +146,7 @@ def on_snapshot(doc_snapshot, _changes, _read_time): callback(info) return doc_ref.on_snapshot(on_snapshot) + + @staticmethod + def _delete_session(doc_id: str): + return DBManager()._delete_document(collections["audiora_sessions"], doc_id) diff --git a/app/src/lib/components/Sidebar.svelte b/app/src/lib/components/Sidebar.svelte index 3da27fd..a9c93a7 100644 --- a/app/src/lib/components/Sidebar.svelte +++ b/app/src/lib/components/Sidebar.svelte @@ -40,7 +40,7 @@ import NewAudiocastButton from './NewAudiocastButton.svelte'; import { goto } from '$app/navigation'; import { browser } from '$app/environment'; - // import { env } from '@env'; + import { env } from '@env'; const dispatch = createEventDispatcher<{ clickItem: void }>(); const { openSettingsDrawer$ } = getAppContext(); @@ -66,9 +66,9 @@ localStorage.removeItem(`${SESSION_KEY}_${sessionId}`); sidebarItems = getSidebarItems(getSessionItems()); - // void fetch(`${env.API_BASE_URL}/delete-session/${sessionId}`, { - // method: 'DELETE' - // }).catch(() => {}); + void fetch(`${env.API_BASE_URL}/delete-session/${sessionId}`, { + method: 'DELETE' + }).catch(() => void 0); return goto('/', { invalidateAll: true, replaceState: true }); }; @@ -104,7 +104,7 @@ {/if}
-
Today
+
Today
{#each inLast24Hrs as item (item.sessionId)}
-
Last 7 days
+
Last 7 days
{#each inLast7Days as item (item.sessionId)}
-
Last month
+
Last month
{#each inLast30Days as item (item.sessionId)}