mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-10 14:45:16 -05:00
* v0 * v1 * Basic ss tes * Ss tests * Stuff * Add mcp * mcp v1 * Improvement * Fix * BROKEN * Checkpoint * Streaming * Fix abort * Things are broken * Streaming seems to work but copilot is dumb * Fix edge issue * LUAAAA * Fix stream buffer * Fix lint * Checkpoint * Initial temp state, in the middle of a refactor * Initial test shows diff store still working * Tool refactor * First cleanup pass complete - untested * Continued cleanup * Refactor * Refactor complete - no testing yet * Fix - cursor makes me sad * Fix mcp * Clean up mcp * Updated mcp * Add respond to subagents * Fix definitions * Add tools * Add tools * Add copilot mcp tracking * Fix lint * Fix mcp * Fix * Updates * Clean up mcp * Fix copilot mcp tool names to be sim prefixed * Add opus 4.6 * Fix discovery tool * Fix * Remove logs * Fix go side tool rendering * Update docs * Fix hydration * Fix tool call resolution * Fix * Fix lint * Fix superagent and autoallow integrations * Fix always allow * Update block * Remove plan docs * Fix hardcoded ff * Fix dropped provider * Fix lint * Fix tests * Fix dead messages array * Fix discovery * Fix run workflow * Fix run block * Fix run from block in copilot * Fix lint * Fix skip and mtb * Fix typing * Fix tool call * Bump api version * Fix bun lock * Nuke bad files
92 lines
2.9 KiB
TypeScript
92 lines
2.9 KiB
TypeScript
import { type NextRequest, NextResponse } from 'next/server'
|
|
import { getSession } from '@/lib/auth'
|
|
import { SIM_AGENT_API_URL } from '@/lib/copilot/constants'
|
|
import { env } from '@/lib/core/config/env'
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const session = await getSession()
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
const userId = session.user.id
|
|
|
|
const res = await fetch(`${SIM_AGENT_API_URL}/api/validate-key/get-api-keys`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...(env.COPILOT_API_KEY ? { 'x-api-key': env.COPILOT_API_KEY } : {}),
|
|
},
|
|
body: JSON.stringify({ userId }),
|
|
})
|
|
|
|
if (!res.ok) {
|
|
return NextResponse.json({ error: 'Failed to get keys' }, { status: res.status || 500 })
|
|
}
|
|
|
|
const apiKeys = (await res.json().catch(() => null)) as
|
|
| { id: string; apiKey: string; name?: string; createdAt?: string; lastUsed?: string }[]
|
|
| null
|
|
|
|
if (!Array.isArray(apiKeys)) {
|
|
return NextResponse.json({ error: 'Invalid response from Sim Agent' }, { status: 500 })
|
|
}
|
|
|
|
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,
|
|
name: k.name || null,
|
|
createdAt: k.createdAt || null,
|
|
lastUsed: k.lastUsed || null,
|
|
}
|
|
})
|
|
|
|
return NextResponse.json({ keys }, { status: 200 })
|
|
} catch (error) {
|
|
return NextResponse.json({ error: 'Failed to get keys' }, { status: 500 })
|
|
}
|
|
}
|
|
|
|
export async function DELETE(request: NextRequest) {
|
|
try {
|
|
const session = await getSession()
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
const userId = session.user.id
|
|
const url = new URL(request.url)
|
|
const id = url.searchParams.get('id')
|
|
if (!id) {
|
|
return NextResponse.json({ error: 'id is required' }, { status: 400 })
|
|
}
|
|
|
|
const res = await fetch(`${SIM_AGENT_API_URL}/api/validate-key/delete`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...(env.COPILOT_API_KEY ? { 'x-api-key': env.COPILOT_API_KEY } : {}),
|
|
},
|
|
body: JSON.stringify({ userId, apiKeyId: id }),
|
|
})
|
|
|
|
if (!res.ok) {
|
|
return NextResponse.json({ error: 'Failed to delete key' }, { status: res.status || 500 })
|
|
}
|
|
|
|
const data = (await res.json().catch(() => null)) as { success?: boolean } | null
|
|
if (!data?.success) {
|
|
return NextResponse.json({ error: 'Invalid response from Sim Agent' }, { status: 500 })
|
|
}
|
|
|
|
return NextResponse.json({ success: true }, { status: 200 })
|
|
} catch (error) {
|
|
return NextResponse.json({ error: 'Failed to delete key' }, { status: 500 })
|
|
}
|
|
}
|