mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-11 23:14:58 -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
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import { type NextRequest, NextResponse } from 'next/server'
|
|
import { z } from 'zod'
|
|
import { SIM_AGENT_API_URL } from '@/lib/copilot/constants'
|
|
import {
|
|
authenticateCopilotRequestSessionOnly,
|
|
createBadRequestResponse,
|
|
createInternalServerErrorResponse,
|
|
createRequestTracker,
|
|
createUnauthorizedResponse,
|
|
} from '@/lib/copilot/request-helpers'
|
|
import { env } from '@/lib/core/config/env'
|
|
|
|
const BodySchema = z.object({
|
|
messageId: z.string(),
|
|
diffCreated: z.boolean(),
|
|
diffAccepted: z.boolean(),
|
|
})
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const tracker = createRequestTracker()
|
|
try {
|
|
const { userId, isAuthenticated } = await authenticateCopilotRequestSessionOnly()
|
|
if (!isAuthenticated || !userId) {
|
|
return createUnauthorizedResponse()
|
|
}
|
|
|
|
const json = await req.json().catch(() => ({}))
|
|
const parsed = BodySchema.safeParse(json)
|
|
if (!parsed.success) {
|
|
return createBadRequestResponse('Invalid request body for copilot stats')
|
|
}
|
|
|
|
const { messageId, diffCreated, diffAccepted } = parsed.data as any
|
|
|
|
// Build outgoing payload for Sim Agent with only required fields
|
|
const payload: Record<string, any> = {
|
|
messageId,
|
|
diffCreated,
|
|
diffAccepted,
|
|
}
|
|
|
|
const agentRes = await fetch(`${SIM_AGENT_API_URL}/api/stats`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...(env.COPILOT_API_KEY ? { 'x-api-key': env.COPILOT_API_KEY } : {}),
|
|
},
|
|
body: JSON.stringify(payload),
|
|
})
|
|
|
|
// Prefer not to block clients; still relay status
|
|
let agentJson: any = null
|
|
try {
|
|
agentJson = await agentRes.json()
|
|
} catch {}
|
|
|
|
if (!agentRes.ok) {
|
|
const message = (agentJson && (agentJson.error || agentJson.message)) || 'Upstream error'
|
|
return NextResponse.json({ success: false, error: message }, { status: 400 })
|
|
}
|
|
|
|
return NextResponse.json({ success: true })
|
|
} catch (error) {
|
|
return createInternalServerErrorResponse('Failed to forward copilot stats')
|
|
}
|
|
}
|