( payload: CursorRequestPayload, accessToken: string, convKey: string, )
| 1449 | } |
| 1450 | |
| 1451 | async function collectFullResponse( |
| 1452 | payload: CursorRequestPayload, |
| 1453 | accessToken: string, |
| 1454 | convKey: string, |
| 1455 | ): Promise<CollectedResponse> { |
| 1456 | const { promise, resolve } = Promise.withResolvers<CollectedResponse>(); |
| 1457 | let fullText = ""; |
| 1458 | |
| 1459 | const { bridge, heartbeatTimer } = startBridge(accessToken, payload.requestBytes); |
| 1460 | |
| 1461 | const state: StreamState = { |
| 1462 | toolCallIndex: 0, |
| 1463 | pendingExecs: [], |
| 1464 | outputTokens: 0, |
| 1465 | totalTokens: 0, |
| 1466 | }; |
| 1467 | const tagFilter = createThinkingTagFilter(); |
| 1468 | |
| 1469 | bridge.onData(createConnectFrameParser( |
| 1470 | (messageBytes) => { |
| 1471 | try { |
| 1472 | const serverMessage = fromBinary( |
| 1473 | AgentServerMessageSchema, |
| 1474 | messageBytes, |
| 1475 | ); |
| 1476 | processServerMessage( |
| 1477 | serverMessage, |
| 1478 | payload.blobStore, |
| 1479 | payload.mcpTools, |
| 1480 | (data) => bridge.write(data), |
| 1481 | state, |
| 1482 | (text, isThinking) => { |
| 1483 | if (isThinking) return; |
| 1484 | const { content } = tagFilter.process(text); |
| 1485 | fullText += content; |
| 1486 | }, |
| 1487 | () => {}, |
| 1488 | (checkpointBytes) => { |
| 1489 | const stored = conversationStates.get(convKey); |
| 1490 | if (stored) { |
| 1491 | stored.checkpoint = checkpointBytes; |
| 1492 | stored.lastAccessMs = Date.now(); |
| 1493 | } |
| 1494 | }, |
| 1495 | ); |
| 1496 | } catch { |
| 1497 | // Skip |
| 1498 | } |
| 1499 | }, |
| 1500 | () => {}, |
| 1501 | )); |
| 1502 | |
| 1503 | bridge.onClose(() => { |
| 1504 | clearInterval(heartbeatTimer); |
| 1505 | const stored = conversationStates.get(convKey); |
| 1506 | if (stored) { |
| 1507 | for (const [k, v] of payload.blobStore) stored.blobStore.set(k, v); |
| 1508 | stored.lastAccessMs = Date.now(); |
no test coverage detected