MCPcopy
hub / github.com/cursor/cookbook / requireSession

Function requireSession

sdk/agent-kanban/src/lib/agents/server.ts:183–203  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

181}
182
183export async function requireSession(request: Request): Promise<Session> {
184 const sessionId =
185 request.headers.get("x-agent-kanban-session")?.trim() ??
186 getCookie(request, "agent-kanban-session")?.trim()
187 if (!sessionId) {
188 throw new MissingCursorApiKeyError()
189 }
190
191 const session = sessions.get(sessionId)
192 if (session) {
193 return session
194 }
195
196 const restored = await restoreSession(sessionId)
197 const restoredSession = sessions.get(restored.id)
198 if (!restoredSession) {
199 throw new UnknownSessionError()
200 }
201
202 return restoredSession
203}
204
205function getCookie(request: Request, name: string) {
206 const cookies = request.headers.get("cookie") ?? ""

Callers 7

GETFunction · 0.90
GETFunction · 0.90
GETFunction · 0.90
POSTFunction · 0.90
GETFunction · 0.90
GETFunction · 0.90
GETFunction · 0.90

Calls 2

getCookieFunction · 0.85
restoreSessionFunction · 0.70

Tested by

no test coverage detected