Skip to content

Commit 58251e2

Browse files
Sg312icecrasher321waleedlatif1
authored
feat(copilot): superagent (#2201)
* Superagent poc * Checkpoint brokeN * tool call rag * Fix * Fixes * Improvements * Creds stuff * Fix * Fix tools * Fix stream * Prompt * Update sheets descriptions * Better * Copilot components * Delete stuff * Remove db migration * Fix migrations * Fix things * Copilot side superagent * Build workflow from chat * Combine superagent into copilkot * Render tools * Function execution * Max mode indicators * Tool call confirmations * Credential settings * Remove betas * Bump version * Dropdown options in block metadata * Copilot kb tools * Fix lint * Credentials modal * Fix lint * Cleanup * Env var resolution in superagent tools * Get id for workflow vars * Fix insert into subflow * Fix executor for while and do while loops * Fix metadata for parallel * Remove db migration * Rebase * Add migrations back * Clean up code * Fix executor logic issue * Cleanup * Diagram tool * Fix tool naems * Comment out g3p * Remove popup option * Hide o3 * Remove db migration * Fix merge conflicts * Fix lint * Fix tests * Remove webhook change * Remove cb change * Fix lint * Fix * Fix lint * Fix build * comment out gemini * Add gemini back * Remove bad test * Fix * Fix test * Fix * Nuke bad test * Fix lint --------- Co-authored-by: Vikhyath Mondreti <[email protected]> Co-authored-by: Waleed <[email protected]> Co-authored-by: waleedlatif1 <[email protected]>
1 parent 8ef9a45 commit 58251e2

File tree

56 files changed

+11238
-1701
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+11238
-1701
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import { db } from '@sim/db'
2+
import { settings } from '@sim/db/schema'
3+
import { eq } from 'drizzle-orm'
4+
import { type NextRequest, NextResponse } from 'next/server'
5+
import { auth } from '@/lib/auth'
6+
import { createLogger } from '@/lib/logs/console/logger'
7+
8+
const logger = createLogger('CopilotAutoAllowedToolsAPI')
9+
10+
/**
11+
* GET - Fetch user's auto-allowed integration tools
12+
*/
13+
export async function GET(request: NextRequest) {
14+
try {
15+
const session = await auth.api.getSession({ headers: request.headers })
16+
17+
if (!session?.user?.id) {
18+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
19+
}
20+
21+
const userId = session.user.id
22+
23+
const [userSettings] = await db
24+
.select()
25+
.from(settings)
26+
.where(eq(settings.userId, userId))
27+
.limit(1)
28+
29+
if (userSettings) {
30+
const autoAllowedTools = (userSettings.copilotAutoAllowedTools as string[]) || []
31+
return NextResponse.json({ autoAllowedTools })
32+
}
33+
34+
// If no settings record exists, create one with empty array
35+
await db.insert(settings).values({
36+
id: userId,
37+
userId,
38+
copilotAutoAllowedTools: [],
39+
})
40+
41+
return NextResponse.json({ autoAllowedTools: [] })
42+
} catch (error) {
43+
logger.error('Failed to fetch auto-allowed tools', { error })
44+
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
45+
}
46+
}
47+
48+
/**
49+
* POST - Add a tool to the auto-allowed list
50+
*/
51+
export async function POST(request: NextRequest) {
52+
try {
53+
const session = await auth.api.getSession({ headers: request.headers })
54+
55+
if (!session?.user?.id) {
56+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
57+
}
58+
59+
const userId = session.user.id
60+
const body = await request.json()
61+
62+
if (!body.toolId || typeof body.toolId !== 'string') {
63+
return NextResponse.json({ error: 'toolId must be a string' }, { status: 400 })
64+
}
65+
66+
const toolId = body.toolId
67+
68+
// Get existing settings
69+
const [existing] = await db.select().from(settings).where(eq(settings.userId, userId)).limit(1)
70+
71+
if (existing) {
72+
const currentTools = (existing.copilotAutoAllowedTools as string[]) || []
73+
74+
// Add tool if not already present
75+
if (!currentTools.includes(toolId)) {
76+
const updatedTools = [...currentTools, toolId]
77+
await db
78+
.update(settings)
79+
.set({
80+
copilotAutoAllowedTools: updatedTools,
81+
updatedAt: new Date(),
82+
})
83+
.where(eq(settings.userId, userId))
84+
85+
logger.info('Added tool to auto-allowed list', { userId, toolId })
86+
return NextResponse.json({ success: true, autoAllowedTools: updatedTools })
87+
}
88+
89+
return NextResponse.json({ success: true, autoAllowedTools: currentTools })
90+
}
91+
92+
// Create new settings record with the tool
93+
await db.insert(settings).values({
94+
id: userId,
95+
userId,
96+
copilotAutoAllowedTools: [toolId],
97+
})
98+
99+
logger.info('Created settings and added tool to auto-allowed list', { userId, toolId })
100+
return NextResponse.json({ success: true, autoAllowedTools: [toolId] })
101+
} catch (error) {
102+
logger.error('Failed to add auto-allowed tool', { error })
103+
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
104+
}
105+
}
106+
107+
/**
108+
* DELETE - Remove a tool from the auto-allowed list
109+
*/
110+
export async function DELETE(request: NextRequest) {
111+
try {
112+
const session = await auth.api.getSession({ headers: request.headers })
113+
114+
if (!session?.user?.id) {
115+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
116+
}
117+
118+
const userId = session.user.id
119+
const { searchParams } = new URL(request.url)
120+
const toolId = searchParams.get('toolId')
121+
122+
if (!toolId) {
123+
return NextResponse.json({ error: 'toolId query parameter is required' }, { status: 400 })
124+
}
125+
126+
// Get existing settings
127+
const [existing] = await db.select().from(settings).where(eq(settings.userId, userId)).limit(1)
128+
129+
if (existing) {
130+
const currentTools = (existing.copilotAutoAllowedTools as string[]) || []
131+
const updatedTools = currentTools.filter((t) => t !== toolId)
132+
133+
await db
134+
.update(settings)
135+
.set({
136+
copilotAutoAllowedTools: updatedTools,
137+
updatedAt: new Date(),
138+
})
139+
.where(eq(settings.userId, userId))
140+
141+
logger.info('Removed tool from auto-allowed list', { userId, toolId })
142+
return NextResponse.json({ success: true, autoAllowedTools: updatedTools })
143+
}
144+
145+
return NextResponse.json({ success: true, autoAllowedTools: [] })
146+
} catch (error) {
147+
logger.error('Failed to remove auto-allowed tool', { error })
148+
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
149+
}
150+
}

0 commit comments

Comments
 (0)