Skip to content

Commit f09c5f3

Browse files
authored
Use JSON5 for parsing all config vars (#671)
1 parent c208e39 commit f09c5f3

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"highlight.js": "^11.7.0",
5757
"image-size": "^1.0.2",
5858
"jsdom": "^22.0.0",
59+
"json5": "^2.2.3",
5960
"marked": "^4.3.0",
6061
"mongodb": "^5.8.0",
6162
"nanoid": "^4.0.2",

src/lib/components/chat/ChatIntroduction.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import { findCurrentModel } from "$lib/utils/models";
1313
import { base } from "$app/paths";
1414
import { useSettingsStore } from "$lib/stores/settings";
15+
import JSON5 from "json5";
1516
1617
export let currentModel: Model;
1718
export let models: Model[];
@@ -21,7 +22,7 @@
2122
$: currentModelMetadata = findCurrentModel(models, $settings.activeModel);
2223
2324
const announcementBanners = PUBLIC_ANNOUNCEMENT_BANNERS
24-
? JSON.parse(PUBLIC_ANNOUNCEMENT_BANNERS)
25+
? JSON5.parse(PUBLIC_ANNOUNCEMENT_BANNERS)
2526
: [];
2627
2728
const dispatch = createEventDispatcher<{ message: string }>();

src/lib/server/auth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { z } from "zod";
1515
import { dev } from "$app/environment";
1616
import type { Cookies } from "@sveltejs/kit";
1717
import { collections } from "./database";
18+
import JSON5 from "json5";
1819

1920
export interface OIDCSettings {
2021
redirectURI: string;
@@ -40,7 +41,7 @@ const OIDConfig = z
4041
TOLERANCE: stringWithDefault(OPENID_TOLERANCE),
4142
RESOURCE: stringWithDefault(OPENID_RESOURCE),
4243
})
43-
.parse(JSON.parse(OPENID_CONFIG));
44+
.parse(JSON5.parse(OPENID_CONFIG));
4445

4546
export const requiresUser = !!OIDConfig.CLIENT_ID && !!OIDConfig.CLIENT_SECRET;
4647

src/lib/server/models.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import endpoints, { endpointSchema, type Endpoint } from "./endpoints/endpoints"
1313
import endpointTgi from "./endpoints/tgi/endpointTgi";
1414
import { sum } from "$lib/utils/sum";
1515

16+
import JSON5 from "json5";
17+
1618
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
1719

1820
const modelConfig = z.object({
@@ -68,7 +70,7 @@ const modelConfig = z.object({
6870
unlisted: z.boolean().default(false),
6971
});
7072

71-
const modelsRaw = z.array(modelConfig).parse(JSON.parse(MODELS));
73+
const modelsRaw = z.array(modelConfig).parse(JSON5.parse(MODELS));
7274

7375
const processModel = async (m: z.infer<typeof modelConfig>) => ({
7476
...m,
@@ -138,7 +140,7 @@ export const oldModels = OLD_MODELS
138140
displayName: z.string().min(1).optional(),
139141
})
140142
)
141-
.parse(JSON.parse(OLD_MODELS))
143+
.parse(JSON5.parse(OLD_MODELS))
142144
.map((m) => ({ ...m, id: m.id || m.name, displayName: m.displayName || m.name }))
143145
: [];
144146

@@ -151,7 +153,7 @@ export const validateModel = (_models: BackendModel[]) => {
151153

152154
export const smallModel = TASK_MODEL
153155
? (models.find((m) => m.name === TASK_MODEL) ||
154-
(await processModel(modelConfig.parse(JSON.parse(TASK_MODEL))).then((m) =>
156+
(await processModel(modelConfig.parse(JSON5.parse(TASK_MODEL))).then((m) =>
155157
addEndpoint(m)
156158
))) ??
157159
defaultModel

src/lib/server/websearch/generateQuery.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { format } from "date-fns";
33
import { generateFromDefaultEndpoint } from "../generateFromDefaultEndpoint";
44
import { WEBSEARCH_ALLOWLIST, WEBSEARCH_BLOCKLIST } from "$env/static/private";
55
import { z } from "zod";
6+
import JSON5 from "json5";
67

78
const listSchema = z.array(z.string()).default([]);
89

9-
const allowList = listSchema.parse(JSON.parse(WEBSEARCH_ALLOWLIST));
10-
const blockList = listSchema.parse(JSON.parse(WEBSEARCH_BLOCKLIST));
10+
const allowList = listSchema.parse(JSON5.parse(WEBSEARCH_ALLOWLIST));
11+
const blockList = listSchema.parse(JSON5.parse(WEBSEARCH_BLOCKLIST));
1112

1213
const queryModifier = [
1314
...allowList.map((item) => "site:" + item),

0 commit comments

Comments
 (0)