Use JSON5 for parsing all config vars (#671)
Browse files- package-lock.json +12 -0
- package.json +1 -0
- src/lib/components/chat/ChatIntroduction.svelte +2 -1
- src/lib/server/auth.ts +2 -1
- src/lib/server/models.ts +5 -3
- src/lib/server/websearch/generateQuery.ts +3 -2
package-lock.json
CHANGED
@@ -20,6 +20,7 @@
|
|
20 |
"highlight.js": "^11.7.0",
|
21 |
"image-size": "^1.0.2",
|
22 |
"jsdom": "^22.0.0",
|
|
|
23 |
"marked": "^4.3.0",
|
24 |
"mongodb": "^5.8.0",
|
25 |
"nanoid": "^4.0.2",
|
@@ -3597,6 +3598,17 @@
|
|
3597 |
"integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==",
|
3598 |
"dev": true
|
3599 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3600 |
"node_modules/jsonc-parser": {
|
3601 |
"version": "3.2.0",
|
3602 |
"resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.2.0.tgz",
|
|
|
20 |
"highlight.js": "^11.7.0",
|
21 |
"image-size": "^1.0.2",
|
22 |
"jsdom": "^22.0.0",
|
23 |
+
"json5": "^2.2.3",
|
24 |
"marked": "^4.3.0",
|
25 |
"mongodb": "^5.8.0",
|
26 |
"nanoid": "^4.0.2",
|
|
|
3598 |
"integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==",
|
3599 |
"dev": true
|
3600 |
},
|
3601 |
+
"node_modules/json5": {
|
3602 |
+
"version": "2.2.3",
|
3603 |
+
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
|
3604 |
+
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
|
3605 |
+
"bin": {
|
3606 |
+
"json5": "lib/cli.js"
|
3607 |
+
},
|
3608 |
+
"engines": {
|
3609 |
+
"node": ">=6"
|
3610 |
+
}
|
3611 |
+
},
|
3612 |
"node_modules/jsonc-parser": {
|
3613 |
"version": "3.2.0",
|
3614 |
"resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.2.0.tgz",
|
package.json
CHANGED
@@ -56,6 +56,7 @@
|
|
56 |
"highlight.js": "^11.7.0",
|
57 |
"image-size": "^1.0.2",
|
58 |
"jsdom": "^22.0.0",
|
|
|
59 |
"marked": "^4.3.0",
|
60 |
"mongodb": "^5.8.0",
|
61 |
"nanoid": "^4.0.2",
|
|
|
56 |
"highlight.js": "^11.7.0",
|
57 |
"image-size": "^1.0.2",
|
58 |
"jsdom": "^22.0.0",
|
59 |
+
"json5": "^2.2.3",
|
60 |
"marked": "^4.3.0",
|
61 |
"mongodb": "^5.8.0",
|
62 |
"nanoid": "^4.0.2",
|
src/lib/components/chat/ChatIntroduction.svelte
CHANGED
@@ -12,6 +12,7 @@
|
|
12 |
import { findCurrentModel } from "$lib/utils/models";
|
13 |
import { base } from "$app/paths";
|
14 |
import { useSettingsStore } from "$lib/stores/settings";
|
|
|
15 |
|
16 |
export let currentModel: Model;
|
17 |
export let models: Model[];
|
@@ -21,7 +22,7 @@
|
|
21 |
$: currentModelMetadata = findCurrentModel(models, $settings.activeModel);
|
22 |
|
23 |
const announcementBanners = PUBLIC_ANNOUNCEMENT_BANNERS
|
24 |
-
?
|
25 |
: [];
|
26 |
|
27 |
const dispatch = createEventDispatcher<{ message: string }>();
|
|
|
12 |
import { findCurrentModel } from "$lib/utils/models";
|
13 |
import { base } from "$app/paths";
|
14 |
import { useSettingsStore } from "$lib/stores/settings";
|
15 |
+
import JSON5 from "json5";
|
16 |
|
17 |
export let currentModel: Model;
|
18 |
export let models: Model[];
|
|
|
22 |
$: currentModelMetadata = findCurrentModel(models, $settings.activeModel);
|
23 |
|
24 |
const announcementBanners = PUBLIC_ANNOUNCEMENT_BANNERS
|
25 |
+
? JSON5.parse(PUBLIC_ANNOUNCEMENT_BANNERS)
|
26 |
: [];
|
27 |
|
28 |
const dispatch = createEventDispatcher<{ message: string }>();
|
src/lib/server/auth.ts
CHANGED
@@ -15,6 +15,7 @@ import { z } from "zod";
|
|
15 |
import { dev } from "$app/environment";
|
16 |
import type { Cookies } from "@sveltejs/kit";
|
17 |
import { collections } from "./database";
|
|
|
18 |
|
19 |
export interface OIDCSettings {
|
20 |
redirectURI: string;
|
@@ -40,7 +41,7 @@ const OIDConfig = z
|
|
40 |
TOLERANCE: stringWithDefault(OPENID_TOLERANCE),
|
41 |
RESOURCE: stringWithDefault(OPENID_RESOURCE),
|
42 |
})
|
43 |
-
.parse(
|
44 |
|
45 |
export const requiresUser = !!OIDConfig.CLIENT_ID && !!OIDConfig.CLIENT_SECRET;
|
46 |
|
|
|
15 |
import { dev } from "$app/environment";
|
16 |
import type { Cookies } from "@sveltejs/kit";
|
17 |
import { collections } from "./database";
|
18 |
+
import JSON5 from "json5";
|
19 |
|
20 |
export interface OIDCSettings {
|
21 |
redirectURI: string;
|
|
|
41 |
TOLERANCE: stringWithDefault(OPENID_TOLERANCE),
|
42 |
RESOURCE: stringWithDefault(OPENID_RESOURCE),
|
43 |
})
|
44 |
+
.parse(JSON5.parse(OPENID_CONFIG));
|
45 |
|
46 |
export const requiresUser = !!OIDConfig.CLIENT_ID && !!OIDConfig.CLIENT_SECRET;
|
47 |
|
src/lib/server/models.ts
CHANGED
@@ -13,6 +13,8 @@ import endpoints, { endpointSchema, type Endpoint } from "./endpoints/endpoints"
|
|
13 |
import endpointTgi from "./endpoints/tgi/endpointTgi";
|
14 |
import { sum } from "$lib/utils/sum";
|
15 |
|
|
|
|
|
16 |
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
17 |
|
18 |
const modelConfig = z.object({
|
@@ -68,7 +70,7 @@ const modelConfig = z.object({
|
|
68 |
unlisted: z.boolean().default(false),
|
69 |
});
|
70 |
|
71 |
-
const modelsRaw = z.array(modelConfig).parse(
|
72 |
|
73 |
const processModel = async (m: z.infer<typeof modelConfig>) => ({
|
74 |
...m,
|
@@ -138,7 +140,7 @@ export const oldModels = OLD_MODELS
|
|
138 |
displayName: z.string().min(1).optional(),
|
139 |
})
|
140 |
)
|
141 |
-
.parse(
|
142 |
.map((m) => ({ ...m, id: m.id || m.name, displayName: m.displayName || m.name }))
|
143 |
: [];
|
144 |
|
@@ -151,7 +153,7 @@ export const validateModel = (_models: BackendModel[]) => {
|
|
151 |
|
152 |
export const smallModel = TASK_MODEL
|
153 |
? (models.find((m) => m.name === TASK_MODEL) ||
|
154 |
-
(await processModel(modelConfig.parse(
|
155 |
addEndpoint(m)
|
156 |
))) ??
|
157 |
defaultModel
|
|
|
13 |
import endpointTgi from "./endpoints/tgi/endpointTgi";
|
14 |
import { sum } from "$lib/utils/sum";
|
15 |
|
16 |
+
import JSON5 from "json5";
|
17 |
+
|
18 |
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
19 |
|
20 |
const modelConfig = z.object({
|
|
|
70 |
unlisted: z.boolean().default(false),
|
71 |
});
|
72 |
|
73 |
+
const modelsRaw = z.array(modelConfig).parse(JSON5.parse(MODELS));
|
74 |
|
75 |
const processModel = async (m: z.infer<typeof modelConfig>) => ({
|
76 |
...m,
|
|
|
140 |
displayName: z.string().min(1).optional(),
|
141 |
})
|
142 |
)
|
143 |
+
.parse(JSON5.parse(OLD_MODELS))
|
144 |
.map((m) => ({ ...m, id: m.id || m.name, displayName: m.displayName || m.name }))
|
145 |
: [];
|
146 |
|
|
|
153 |
|
154 |
export const smallModel = TASK_MODEL
|
155 |
? (models.find((m) => m.name === TASK_MODEL) ||
|
156 |
+
(await processModel(modelConfig.parse(JSON5.parse(TASK_MODEL))).then((m) =>
|
157 |
addEndpoint(m)
|
158 |
))) ??
|
159 |
defaultModel
|
src/lib/server/websearch/generateQuery.ts
CHANGED
@@ -3,11 +3,12 @@ import { format } from "date-fns";
|
|
3 |
import { generateFromDefaultEndpoint } from "../generateFromDefaultEndpoint";
|
4 |
import { WEBSEARCH_ALLOWLIST, WEBSEARCH_BLOCKLIST } from "$env/static/private";
|
5 |
import { z } from "zod";
|
|
|
6 |
|
7 |
const listSchema = z.array(z.string()).default([]);
|
8 |
|
9 |
-
const allowList = listSchema.parse(
|
10 |
-
const blockList = listSchema.parse(
|
11 |
|
12 |
const queryModifier = [
|
13 |
...allowList.map((item) => "site:" + item),
|
|
|
3 |
import { generateFromDefaultEndpoint } from "../generateFromDefaultEndpoint";
|
4 |
import { WEBSEARCH_ALLOWLIST, WEBSEARCH_BLOCKLIST } from "$env/static/private";
|
5 |
import { z } from "zod";
|
6 |
+
import JSON5 from "json5";
|
7 |
|
8 |
const listSchema = z.array(z.string()).default([]);
|
9 |
|
10 |
+
const allowList = listSchema.parse(JSON5.parse(WEBSEARCH_ALLOWLIST));
|
11 |
+
const blockList = listSchema.parse(JSON5.parse(WEBSEARCH_BLOCKLIST));
|
12 |
|
13 |
const queryModifier = [
|
14 |
...allowList.map((item) => "site:" + item),
|