-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor content category handling and implement chat session m…
…anagement
- Loading branch information
1 parent
22966f1
commit 352ea4a
Showing
7 changed files
with
52 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { setContext, getContext } from 'svelte'; | ||
import { persisted } from 'svelte-persisted-store'; | ||
|
||
const CONTEXT_KEY = {}; | ||
const CHAT_SESSION_KEY = 'CHAT_SESSION_KEY'; | ||
|
||
export type ChatItem = { | ||
id: string; | ||
content: string; | ||
role: 'user' | 'assistant'; | ||
}; | ||
|
||
export function setChatSession(sessionId: string) { | ||
const chatSession$ = persisted<ChatItem[]>(`${CHAT_SESSION_KEY}_${sessionId}`, []); | ||
|
||
return setContext(CONTEXT_KEY, { | ||
chatSession$ | ||
}); | ||
} | ||
|
||
export type ChatSession = ReturnType<typeof setChatSession>; | ||
export const getChatSession = (): ChatSession => getContext(CONTEXT_KEY); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type ContentCategory = | ||
| 'podcast' | ||
| 'sermon' | ||
| 'audiodrama' | ||
| 'lecture' | ||
| 'commentary' | ||
| 'voicenote' | ||
| 'interview' | ||
| 'soundbite'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import type { ContentCategory } from '@/utils/types'; | ||
import type { LayoutServerLoad } from './$types'; | ||
|
||
export const ssr = true; | ||
export const prerender = false; | ||
export const load: LayoutServerLoad = ({ locals }) => { | ||
return { | ||
sessionId: locals.sessionId | ||
sessionId: locals.sessionId, | ||
category: null as ContentCategory | null | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { LayoutServerLoad } from './$types'; | ||
export const load: LayoutServerLoad = ({ url }) => { | ||
return { | ||
category: url.searchParams.get('category') | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters