-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy path+layout.ts
More file actions
56 lines (48 loc) · 1.69 KB
/
Copy path+layout.ts
File metadata and controls
56 lines (48 loc) · 1.69 KB
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
49
50
51
52
53
54
55
56
import { UrlDependency } from "$lib/types/UrlDependency";
import type { ConvSidebar } from "$lib/types/ConvSidebar";
import { useAPIClient, handleResponse } from "$lib/APIClient";
import { getConfigManager } from "$lib/utils/PublicConfig.svelte";
export const load = async ({ depends, fetch, url }) => {
depends(UrlDependency.ConversationList);
const client = useAPIClient({ fetch, origin: url.origin });
const [settings, models, user, publicConfig, featureFlags, conversationsData] = await Promise.all(
[
client.user.settings.get().then(handleResponse),
client.models.get().then(handleResponse),
client.user.get().then(handleResponse),
client["public-config"].get().then(handleResponse),
client["feature-flags"].get().then(handleResponse),
client.conversations.get({ query: { p: 0 } }).then(handleResponse),
]
);
const defaultModel = models[0];
const { conversations: rawConversations } = conversationsData;
const conversations = rawConversations.map((conv) => {
const trimmedTitle = conv.title.trim();
conv.title = trimmedTitle;
return {
id: conv._id.toString(),
title: conv.title,
model: conv.model ?? defaultModel,
updatedAt: new Date(conv.updatedAt),
} satisfies ConvSidebar;
});
return {
conversations,
models,
oldModels: [],
user,
settings: {
...settings,
welcomeModalSeenAt: settings.welcomeModalSeenAt
? new Date(settings.welcomeModalSeenAt)
: null,
// Ensure providerOverrides has a default value (may not exist in older DB records)
providerOverrides:
(settings as unknown as { providerOverrides?: Record<string, string> }).providerOverrides ??
{},
},
publicConfig: getConfigManager(publicConfig),
...featureFlags,
};
};