MCPcopy Index your code
hub / github.com/simstudioai/sim / handleResumeRequestBody

Function handleResumeRequestBody

apps/sim/app/api/copilot/chat/stream/route.ts:183–483  ·  view source on GitHub ↗
({
  request,
  streamId,
  afterCursor,
  batchMode,
  authenticatedUserId,
  rootSpan,
  rootContext,
}: {
  request: NextRequest
  streamId: string
  afterCursor: string
  batchMode: boolean
  authenticatedUserId: string
  rootSpan: Span
  rootContext: Context
})

Source from the content-addressed store, hash-verified

181})
182
183async function handleResumeRequestBody({
184 request,
185 streamId,
186 afterCursor,
187 batchMode,
188 authenticatedUserId,
189 rootSpan,
190 rootContext,
191}: {
192 request: NextRequest
193 streamId: string
194 afterCursor: string
195 batchMode: boolean
196 authenticatedUserId: string
197 rootSpan: Span
198 rootContext: Context
199}) {
200 const run = await getLatestRunForStream(streamId, authenticatedUserId).catch((err) => {
201 logger.warn('Failed to fetch latest run for stream', {
202 streamId,
203 error: getErrorMessage(err),
204 })
205 return null
206 })
207 logger.info('[Resume] Stream lookup', {
208 streamId,
209 afterCursor,
210 batchMode,
211 hasRun: !!run,
212 runStatus: run?.status,
213 })
214 if (!run) {
215 rootSpan.setAttribute(TraceAttr.CopilotResumeOutcome, CopilotResumeOutcome.StreamNotFound)
216 rootSpan.end()
217 return NextResponse.json({ error: 'Stream not found' }, { status: 404 })
218 }
219 rootSpan.setAttribute(TraceAttr.CopilotRunStatus, run.status)
220
221 if (batchMode) {
222 const afterSeq = afterCursor || '0'
223 const [events, previewSessions] = await Promise.all([
224 readEvents(streamId, afterSeq),
225 readFilePreviewSessions(streamId).catch((error) => {
226 logger.warn('Failed to read preview sessions for stream batch', {
227 streamId,
228 error: getErrorMessage(error),
229 })
230 return []
231 }),
232 ])
233 const batchEvents = events.map(toStreamBatchEvent)
234 logger.info('[Resume] Batch response', {
235 streamId,
236 afterCursor: afterSeq,
237 eventCount: batchEvents.length,
238 previewSessionCount: previewSessions.length,
239 runStatus: run.status,
240 })

Callers 1

route.tsFile · 0.85

Calls 6

getLatestRunForStreamFunction · 0.90
getErrorMessageFunction · 0.90
readEventsFunction · 0.90
readFilePreviewSessionsFunction · 0.90
infoMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected