File size: 1,478 Bytes
5da61b4
 
 
831f161
2606dde
cad3e14
2606dde
cad3e14
 
831f161
82fcab7
 
831f161
cad3e14
 
067b52a
831f161
067b52a
cad3e14
2606dde
cad3e14
2606dde
cad3e14
 
5da61b4
cad3e14
2606dde
 
 
 
 
5da61b4
82fcab7
 
 
ad6275a
82fcab7
2606dde
 
 
 
 
 
 
 
cad3e14
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { LayoutServerLoad } from "./$types";
import { collections } from "$lib/server/database";
import type { Conversation } from "$lib/types/Conversation";
import { UrlDependency } from "$lib/types/UrlDependency";
import { defaultModel, models } from "$lib/server/models";

export const load: LayoutServerLoad = async ({ locals, depends, url }) => {
	const { conversations } = collections;

	depends(UrlDependency.ConversationList);

	const settings = await collections.settings.findOne({ sessionId: locals.sessionId });

	return {
		conversations: await conversations
			.find({
				sessionId: locals.sessionId,
			})
			.sort({ updatedAt: -1 })
			.project<Pick<Conversation, "title" | "model" | "_id" | "updatedAt" | "createdAt">>({
				title: 1,
				model: 1,
				_id: 1,
				updatedAt: 1,
				createdAt: 1,
			})
			.map((conv) => ({
				id: conv._id.toString(),
				title: conv.title,
				model: conv.model ?? defaultModel,
			}))
			.toArray(),
		settings: {
			shareConversationsWithModelAuthors: settings?.shareConversationsWithModelAuthors ?? true,
			ethicsModalAcceptedAt: settings?.ethicsModalAcceptedAt ?? null,
			activeModel: url.searchParams.get("model") ?? settings?.activeModel ?? defaultModel.name,
		},
		models: models.map((model) => ({
			name: model.name,
			websiteUrl: model.websiteUrl,
			datasetName: model.datasetName,
			displayName: model.displayName,
			promptExamples: model.promptExamples,
			parameters: model.parameters,
		})),
	};
};