-
Notifications
You must be signed in to change notification settings - Fork 3.3k
v0.4.5: copilot updates, kb improvements, payment failure fix #1544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4da355d
fix(billing-blocked): block platform usage if payment fails for regul…
icecrasher321 c42d2a3
feat(copilot): fix context / json parsing edge cases (#1542)
icecrasher321 7cc9a23
fix(copilot): tool renaming
Sg312 0e83894
fix(copilot): targeted auto-layout for copilot edits + custom tool pe…
icecrasher321 86ed32e
feat(kb): added json/yaml parser+chunker, added dedicated csv chunker…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import { eq } from 'drizzle-orm' | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { auth } from '@/lib/auth' | ||
| import { createLogger } from '@/lib/logs/console/logger' | ||
| import { db } from '@/../../packages/db' | ||
| import { settings } from '@/../../packages/db/schema' | ||
|
|
||
| const logger = createLogger('CopilotUserModelsAPI') | ||
|
|
||
| const DEFAULT_ENABLED_MODELS: Record<string, boolean> = { | ||
| 'gpt-4o': false, | ||
| 'gpt-4.1': false, | ||
| 'gpt-5-fast': false, | ||
| 'gpt-5': true, | ||
| 'gpt-5-medium': true, | ||
| 'gpt-5-high': false, | ||
| o3: true, | ||
| 'claude-4-sonnet': true, | ||
| 'claude-4.5-sonnet': true, | ||
| 'claude-4.1-opus': true, | ||
| } | ||
|
|
||
| // GET - Fetch user's enabled models | ||
| export async function GET(request: NextRequest) { | ||
| try { | ||
| const session = await auth.api.getSession({ headers: request.headers }) | ||
|
|
||
| if (!session?.user?.id) { | ||
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| const userId = session.user.id | ||
|
|
||
| // Try to fetch existing settings record | ||
| const [userSettings] = await db | ||
| .select() | ||
| .from(settings) | ||
| .where(eq(settings.userId, userId)) | ||
| .limit(1) | ||
|
|
||
| if (userSettings) { | ||
| const userModelsMap = (userSettings.copilotEnabledModels as Record<string, boolean>) || {} | ||
|
|
||
| // Merge: start with defaults, then override with user's existing preferences | ||
| const mergedModels = { ...DEFAULT_ENABLED_MODELS } | ||
| for (const [modelId, enabled] of Object.entries(userModelsMap)) { | ||
| mergedModels[modelId] = enabled | ||
| } | ||
|
|
||
| // If we added any new models, update the database | ||
| const hasNewModels = Object.keys(DEFAULT_ENABLED_MODELS).some( | ||
| (key) => !(key in userModelsMap) | ||
| ) | ||
|
|
||
| if (hasNewModels) { | ||
| await db | ||
| .update(settings) | ||
| .set({ | ||
| copilotEnabledModels: mergedModels, | ||
| updatedAt: new Date(), | ||
| }) | ||
| .where(eq(settings.userId, userId)) | ||
| } | ||
|
|
||
| return NextResponse.json({ | ||
| enabledModels: mergedModels, | ||
| }) | ||
| } | ||
|
|
||
| // If no settings record exists, create one with empty object (client will use defaults) | ||
| const [created] = await db | ||
| .insert(settings) | ||
| .values({ | ||
| id: userId, | ||
| userId, | ||
| copilotEnabledModels: {}, | ||
| }) | ||
| .returning() | ||
|
|
||
| return NextResponse.json({ | ||
| enabledModels: DEFAULT_ENABLED_MODELS, | ||
| }) | ||
| } catch (error) { | ||
| logger.error('Failed to fetch user models', { error }) | ||
| return NextResponse.json({ error: 'Internal server error' }, { status: 500 }) | ||
| } | ||
| } | ||
|
|
||
| // PUT - Update user's enabled models | ||
| export async function PUT(request: NextRequest) { | ||
| try { | ||
| const session = await auth.api.getSession({ headers: request.headers }) | ||
|
|
||
| if (!session?.user?.id) { | ||
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| const userId = session.user.id | ||
| const body = await request.json() | ||
|
|
||
| if (!body.enabledModels || typeof body.enabledModels !== 'object') { | ||
| return NextResponse.json({ error: 'enabledModels must be an object' }, { status: 400 }) | ||
| } | ||
|
|
||
| // Check if settings record exists | ||
| const [existing] = await db.select().from(settings).where(eq(settings.userId, userId)).limit(1) | ||
|
|
||
| if (existing) { | ||
| // Update existing record | ||
| await db | ||
| .update(settings) | ||
| .set({ | ||
| copilotEnabledModels: body.enabledModels, | ||
| updatedAt: new Date(), | ||
| }) | ||
| .where(eq(settings.userId, userId)) | ||
| } else { | ||
| // Create new settings record | ||
| await db.insert(settings).values({ | ||
| id: userId, | ||
| userId, | ||
| copilotEnabledModels: body.enabledModels, | ||
| }) | ||
| } | ||
|
|
||
| return NextResponse.json({ success: true }) | ||
| } catch (error) { | ||
| logger.error('Failed to update user models', { error }) | ||
| return NextResponse.json({ error: 'Internal server error' }, { status: 500 }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The
createdvariable is declared but never used, and the insert operation could potentially fail if the user already has settingsPrompt To Fix With AI