Skip to content

Commit 05b6554

Browse files
committed
feat: add feature flag for AI Chat
1 parent 565fa93 commit 05b6554

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ OPENAI_BASE_URL=xxx
3131
GOOGLE_CLIENT_ID=xxx
3232
GOOGLE_CLIENT_SECRET=xxx
3333
GOOGLE_HOSTED_DOMAIN=
34+
35+
# The feature flags.
36+
FEATURE_AI_CHAT=true

src/routes/(main)/(protected)/+layout.server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { error, redirect } from '@sveltejs/kit';
22

3+
import { env } from '$env/dynamic/private';
34
import { db, type UserFindUniqueArgs, type UserGetPayload } from '$lib/server/db';
45

56
import type { LayoutServerLoad } from './$types';
@@ -39,5 +40,8 @@ export const load: LayoutServerLoad = async (event) => {
3940
username: user.name,
4041
csrfToken: event.locals.session.csrfToken(),
4142
onboarded,
43+
featureFlags: {
44+
aiChat: env.FEATURE_AI_CHAT === 'true',
45+
},
4246
};
4347
};

src/routes/(main)/(protected)/+layout.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@
198198
/>
199199
{/if}
200200

201-
<ChatWidget onclick={handleChatWidgetClick} />
201+
{#if page.data.featureFlags.aiChat}
202+
<ChatWidget onclick={handleChatWidgetClick} />
203+
{/if}
202204
</div>
203205
</div>
204206
{/if}
@@ -327,6 +329,8 @@
327329
</Modal>
328330
{/if}
329331

330-
<ChatView isopen={isChatViewOpen} onclose={handleChatViewClose} />
332+
{#if page.data.featureFlags.aiChat}
333+
<ChatView isopen={isChatViewOpen} onclose={handleChatViewClose} />
334+
{/if}
331335

332336
<OnboardingView isopen={isOnboardingViewOpen} onclose={handleOnboardingViewClose} />

src/routes/(main)/api/messages/+server.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { json, type RequestHandler } from '@sveltejs/kit';
22

3+
import { env } from '$env/dynamic/private';
34
import { learnerAuth } from '$lib/server/auth';
45
import { db, type MessageFindManyArgs, type MessageGetPayload, Role } from '$lib/server/db.js';
56
import { DEVELOPER_MESSAGE, openAI } from '$lib/server/openai.js';
@@ -8,6 +9,10 @@ import { search } from '$lib/server/weaviate';
89
import type { JSONObject } from '../types';
910

1011
export const GET: RequestHandler = async (event) => {
12+
if (env.FEATURE_AI_CHAT !== 'true') {
13+
return json(null, { status: 403 });
14+
}
15+
1116
const logger = event.locals.logger.child({ handler: 'api_get_messages' });
1217

1318
const { user } = event.locals.session;
@@ -36,6 +41,10 @@ export const GET: RequestHandler = async (event) => {
3641
};
3742

3843
export const POST: RequestHandler = async (event) => {
44+
if (env.FEATURE_AI_CHAT !== 'true') {
45+
return json(null, { status: 403 });
46+
}
47+
3948
const logger = event.locals.logger.child({ handler: 'api_create_message' });
4049

4150
if (event.request.headers.get('content-type')?.split(';')[0] !== 'application/json') {
@@ -266,6 +275,10 @@ export const POST: RequestHandler = async (event) => {
266275
};
267276

268277
export const DELETE: RequestHandler = async (event) => {
278+
if (env.FEATURE_AI_CHAT !== 'true') {
279+
return json(null, { status: 403 });
280+
}
281+
269282
const logger = event.locals.logger.child({ handler: 'api_delete_messages' });
270283

271284
const { user } = event.locals.session;

0 commit comments

Comments
 (0)