Skip to content

Commit 0f8ae8f

Browse files
chore: refactored TS types for config
1 parent 6c45d06 commit 0f8ae8f

File tree

11 files changed

+37
-35
lines changed

11 files changed

+37
-35
lines changed

actions/auth/get-login-quote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const getLoginQuote = async () => {
1616

1717
const provider = AIProvider(config?.ai?.provider as string);
1818

19-
const DEFAULT_MODEL = (config?.ai?.['text-models']?.[0] as Record<string, string>)?.value;
19+
const DEFAULT_MODEL = config?.ai?.['text-models']?.[0].value;
2020

2121
try {
2222
const response = await fetchCachedData(

actions/chat/get-chat-initial.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const getChatInitial = async () => {
1616

1717
const provider = AIProvider(config?.ai?.provider as string);
1818

19-
const DEFAULT_MODEL = (config?.ai?.['text-models']?.[0] as Record<string, string>)?.value;
19+
const DEFAULT_MODEL = config?.ai?.['text-models']?.[0].value;
2020

2121
try {
2222
const introMessages = await fetchCachedData(

actions/configs/get-app-config.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import { promises as fs } from 'fs';
55
import { getGithubContents } from '../github/get-contents';
66

77
export type GetAppConfig = {
8-
ai: Record<string, string | Record<string, string>[]>;
9-
auth: Record<string, boolean>;
10-
features: Record<string, boolean>;
11-
providers: Record<string, boolean>;
8+
ai: {
9+
'image-models': { value: string; label: string }[];
10+
'text-models': { value: string; label: string }[];
11+
provider: string;
12+
};
13+
auth: { isBlockedNewLogin: true; providers: Record<string, boolean> };
14+
features: { christmas: boolean };
1215
};
1316

1417
export const getAppConfig = async (): Promise<GetAppConfig> => {
@@ -30,19 +33,19 @@ export const getAppConfig = async (): Promise<GetAppConfig> => {
3033
},
3134
auth: {
3235
isBlockedNewLogin: true,
36+
providers: {
37+
google: false,
38+
yandex: false,
39+
vk: false,
40+
mailru: false,
41+
linkedin: false,
42+
slack: false,
43+
github: true,
44+
},
3345
},
3446
features: {
3547
christmas: false,
3648
},
37-
providers: {
38-
google: false,
39-
yandex: false,
40-
vk: false,
41-
mailru: false,
42-
linkedin: false,
43-
slack: false,
44-
github: true,
45-
},
4649
};
4750
}
4851
};

app/(chat)/(routes)/chat/[[...slug]]/_components/chat-main/chat-input-footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const ChatInputFooter = ({
2929
config: state.config,
3030
}));
3131

32-
const IMAGE_MODELS = (appConfig?.ai?.['image-models'] as Record<string, string>[]) ?? [];
32+
const IMAGE_MODELS = appConfig?.ai?.['image-models'] ?? [];
3333

3434
return (
3535
<div className="flex bg-background justify-between px-2 py-2 items-center">

app/(chat)/(routes)/chat/[[...slug]]/_components/chat-main/chat-top-bar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const ChatTopBar = ({
5656

5757
const [open, setOpen] = useState(false);
5858

59-
const TEXT_MODELS = (appConfig?.ai?.['text-models'] as Record<string, string>[]) ?? [];
59+
const TEXT_MODELS = appConfig?.ai?.['text-models'] ?? [];
6060

6161
const messages = chatMessages[conversationId] ?? [];
6262
const models = isOwner(user?.userId) ? TEXT_MODELS : TEXT_MODELS.slice(0, 2);

app/(chat)/(routes)/chat/[[...slug]]/_components/chat-main/chat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const Chat = ({ conversations = [], initialData, isEmbed, isShared }: Cha
5252

5353
const abortControllerRef = useRef<AbortController | null>(null);
5454

55-
const IMAGE_MODELS = (appConfig?.ai?.['image-models'] as Record<string, string>[]) ?? [];
55+
const IMAGE_MODELS = appConfig?.ai?.['image-models'] ?? [];
5656

5757
useEffect(() => {
5858
if (conversations.length) {

app/api/ai/completions/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const POST = async (req: NextRequest) => {
2222
return new NextResponse(ReasonPhrases.UNAUTHORIZED, { status: StatusCodes.UNAUTHORIZED });
2323
}
2424

25-
const TEXT_MODELS = (config?.ai?.['text-models'] as Record<string, string>[]) ?? [];
25+
const TEXT_MODELS = config?.ai?.['text-models'] ?? [];
2626
const models = (isOwner(user?.userId) ? TEXT_MODELS : TEXT_MODELS.slice(0, 2)).map(
2727
({ value }) => value,
2828
);

app/api/ai/image/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const POST = async (req: NextRequest) => {
2222
return new NextResponse(ReasonPhrases.UNAUTHORIZED, { status: StatusCodes.UNAUTHORIZED });
2323
}
2424

25-
const IMAGE_MODELS = (config?.ai?.['image-models'] as Record<string, string>[]) ?? [];
25+
const IMAGE_MODELS = config?.ai?.['image-models'] ?? [];
2626
const models = IMAGE_MODELS.map(({ value }) => value);
2727

2828
if (!models.includes(model)) {

components/ai/generate-text-response-ai.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const GenerateTextResponseAi = ({
4545
const [alreadyTranslated, setAlreadyTranslated] = useState(false);
4646

4747
const shouldCacheResponse = isTranslateButton && cacheKey;
48-
const DEFAULT_MODEL = (appConfig?.ai?.['text-models']?.[0] as Record<string, string>)?.value;
48+
const DEFAULT_MODEL = appConfig?.ai?.['text-models']?.[0].value;
4949

5050
const handleGenerate = async () => {
5151
try {

components/auth/auth-form.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ export const AuthForm = ({ callbackUrl }: AuthFormProps) => {
5050
const locale = useLocale();
5151

5252
const { config } = useAppConfigStore((state) => ({ config: state.config }));
53-
const providers = config?.providers ?? {};
54-
const isBlockedNewLogin = config?.auth?.isBlockedNewLogin;
53+
const { isBlockedNewLogin = false, providers = {} } = config?.auth ?? {};
5554

5655
const [isDisabledButtons, setIsDisabledButtons] = useState(false);
5756
const [isSignUpFlow, setIsSignUpFlow] = useState(false);
@@ -101,7 +100,7 @@ export const AuthForm = ({ callbackUrl }: AuthFormProps) => {
101100
}
102101
};
103102

104-
const hasCredentialsProvider = providers[Provider.CREDENTIALS];
103+
const hasCredentialsProvider = providers?.[Provider.CREDENTIALS];
105104

106105
return (
107106
<>

configs/app.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
"isBlockedNewLogin": false
1818
},
1919
"features": {
20-
"christmas": false
21-
},
22-
"providers": {
23-
"credentials": true,
24-
"github": true,
25-
"google": true,
26-
"linkedin": true,
27-
"mailru": true,
28-
"slack": true,
29-
"vk": true,
30-
"yandex": true
20+
"christmas": false,
21+
"providers": {
22+
"credentials": true,
23+
"github": true,
24+
"google": true,
25+
"linkedin": true,
26+
"mailru": true,
27+
"slack": true,
28+
"vk": true,
29+
"yandex": true
30+
}
3131
}
3232
}

0 commit comments

Comments
 (0)