MCPcopy
hub / github.com/7836246/cursor2api / handleOpenAIMockStream

Function handleOpenAIMockStream

src/openai-handler.ts:516–535  ·  view source on GitHub ↗
(res: Response, body: OpenAIChatRequest, mockText: string)

Source from the content-addressed store, hash-verified

514// ==================== 身份探针模拟响应 ====================
515
516function handleOpenAIMockStream(res: Response, body: OpenAIChatRequest, mockText: string): void {
517 res.writeHead(200, {
518 'Content-Type': 'text/event-stream',
519 'Cache-Control': 'no-cache',
520 'Connection': 'keep-alive',
521 'X-Accel-Buffering': 'no',
522 });
523 const id = chatId();
524 const created = Math.floor(Date.now() / 1000);
525 writeOpenAISSE(res, {
526 id, object: 'chat.completion.chunk', created, model: body.model,
527 choices: [{ index: 0, delta: { role: 'assistant', content: mockText }, finish_reason: null }],
528 });
529 writeOpenAISSE(res, {
530 id, object: 'chat.completion.chunk', created, model: body.model,
531 choices: [{ index: 0, delta: {}, finish_reason: 'stop' }],
532 });
533 res.write('data: [DONE]\n\n');
534 res.end();
535}
536
537function handleOpenAIMockNonStream(res: Response, body: OpenAIChatRequest, mockText: string): void {
538 res.json({

Callers 1

Calls 5

chatIdFunction · 0.85
writeOpenAISSEFunction · 0.85
writeHeadMethod · 0.45
writeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected