-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat(copilot): fix context / json parsing edge cases #1542
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 21 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f15ab45
Add get ops examples
Sg312 c180aa7
input format incorrectly created by copilot should not crash workflow
icecrasher321 c1d7063
fix tool edits triggering overall delta
icecrasher321 8b6c9fd
fix(db): add more options for SSL connection, add envvar for base64 d…
waleedlatif1 94c1017
fix trigger additions
icecrasher321 3095b5d
fix nested outputs for triggers
icecrasher321 e1aa73c
add condition subblock sanitization
icecrasher321 5807987
fix custom tools json
icecrasher321 6afea31
Model selector
Sg312 fa6f17c
fix response format sanitization
icecrasher321 c436bde
Merge branch 'feat/copilot-operations' of github.com:simstudioai/sim …
icecrasher321 0f64d43
remove dead code
icecrasher321 c41068f
fix export sanitization
icecrasher321 29e7fbd
Update migration
Sg312 818a0f3
fix import race cond
icecrasher321 e9487a9
Merge branch 'feat/copilot-operations' of github.com:simstudioai/sim …
icecrasher321 84fcba0
Copilot settings
Sg312 ff1ab81
fix response format
icecrasher321 3900762
Merge branch 'feat/copilot-operations' of github.com:simstudioai/sim …
icecrasher321 96379c1
stop loops/parallels copilot generation from breaking diff view
icecrasher321 6abd7bf
fix lint
icecrasher321 929a69d
Merge origin/staging into feat/copilot-operations
icecrasher321 3fbb7be
Apply suggestion from @greptile-apps[bot]
icecrasher321 cac7050
fix tests
icecrasher321 6340a85
fix lint
icecrasher321 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
| 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)) | ||
| } | ||
icecrasher321 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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() | ||
icecrasher321 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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
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.
Uh oh!
There was an error while loading. Please reload this page.