improvement(copilot): added session context checks in copilot tool calls (#1466)

* improvement(copilot): added session context checks in copilot tool calls

* remove extraneous comments, remove the ability to view copilot API keys after creation

* updated skeleton

---------

Co-authored-by: waleed <waleed>
This commit is contained in:
Waleed
2025-09-26 19:04:49 -07:00
committed by GitHub
parent 3ff6509028
commit a63f3a3d8d
18 changed files with 249 additions and 162 deletions

View File

@@ -15,6 +15,8 @@ export async function POST(req: NextRequest) {
// Move environment variable access inside the function
const SIM_AGENT_API_URL = env.SIM_AGENT_API_URL || SIM_AGENT_API_URL_DEFAULT
await req.json().catch(() => ({}))
const res = await fetch(`${SIM_AGENT_API_URL}/api/validate-key/generate`, {
method: 'POST',
headers: {
@@ -31,14 +33,14 @@ export async function POST(req: NextRequest) {
)
}
const data = (await res.json().catch(() => null)) as { apiKey?: string } | null
const data = (await res.json().catch(() => null)) as { apiKey?: string; id?: string } | null
if (!data?.apiKey) {
return NextResponse.json({ error: 'Invalid response from Sim Agent' }, { status: 500 })
}
return NextResponse.json(
{ success: true, key: { id: 'new', apiKey: data.apiKey } },
{ success: true, key: { id: data?.id || 'new', apiKey: data.apiKey } },
{ status: 201 }
)
} catch (error) {

View File

@@ -33,7 +33,12 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ error: 'Invalid response from Sim Agent' }, { status: 500 })
}
const keys = apiKeys
const keys = apiKeys.map((k) => {
const value = typeof k.apiKey === 'string' ? k.apiKey : ''
const last6 = value.slice(-6)
const displayKey = `•••••${last6}`
return { id: k.id, displayKey }
})
return NextResponse.json({ keys }, { status: 200 })
} catch (error) {

View File

@@ -34,7 +34,7 @@ export async function POST(req: NextRequest) {
const { toolName, payload } = ExecuteSchema.parse(body)
logger.info(`[${tracker.requestId}] Executing server tool`, { toolName })
const result = await routeExecution(toolName, payload)
const result = await routeExecution(toolName, payload, { userId })
try {
const resultPreview = JSON.stringify(result).slice(0, 300)

View File

@@ -13,10 +13,8 @@ import { SIM_AGENT_API_URL_DEFAULT } from '@/lib/sim-agent/constants'
const logger = createLogger('CopilotMarkToolCompleteAPI')
// Sim Agent API configuration
const SIM_AGENT_API_URL = env.SIM_AGENT_API_URL || SIM_AGENT_API_URL_DEFAULT
// Schema for mark-complete request
const MarkCompleteSchema = z.object({
id: z.string(),
name: z.string(),