(
modelId: string,
systemPrompt: string,
userText: string,
turns: Array<{ userText: string; assistantText: string }>,
conversationId: string,
checkpoint: Uint8Array | null,
existingBlobStore?: Map<string, Uint8Array>,
)
| 612 | } |
| 613 | |
| 614 | function buildCursorRequest( |
| 615 | modelId: string, |
| 616 | systemPrompt: string, |
| 617 | userText: string, |
| 618 | turns: Array<{ userText: string; assistantText: string }>, |
| 619 | conversationId: string, |
| 620 | checkpoint: Uint8Array | null, |
| 621 | existingBlobStore?: Map<string, Uint8Array>, |
| 622 | ): CursorRequestPayload { |
| 623 | const blobStore = new Map<string, Uint8Array>(existingBlobStore ?? []); |
| 624 | |
| 625 | // System prompt → blob store (Cursor requests it back via KV handshake) |
| 626 | const systemJson = JSON.stringify({ role: "system", content: systemPrompt }); |
| 627 | const systemBytes = new TextEncoder().encode(systemJson); |
| 628 | const systemBlobId = new Uint8Array( |
| 629 | createHash("sha256").update(systemBytes).digest(), |
| 630 | ); |
| 631 | blobStore.set(Buffer.from(systemBlobId).toString("hex"), systemBytes); |
| 632 | |
| 633 | let conversationState; |
| 634 | if (checkpoint) { |
| 635 | conversationState = fromBinary(ConversationStateStructureSchema, checkpoint); |
| 636 | } else { |
| 637 | const turnBytes: Uint8Array[] = []; |
| 638 | for (const turn of turns) { |
| 639 | const userMsg = create(UserMessageSchema, { |
| 640 | text: turn.userText, |
| 641 | messageId: crypto.randomUUID(), |
| 642 | }); |
| 643 | const userMsgBytes = toBinary(UserMessageSchema, userMsg); |
| 644 | |
| 645 | const stepBytes: Uint8Array[] = []; |
| 646 | if (turn.assistantText) { |
| 647 | const step = create(ConversationStepSchema, { |
| 648 | message: { |
| 649 | case: "assistantMessage", |
| 650 | value: create(AssistantMessageSchema, { text: turn.assistantText }), |
| 651 | }, |
| 652 | }); |
| 653 | stepBytes.push(toBinary(ConversationStepSchema, step)); |
| 654 | } |
| 655 | |
| 656 | const agentTurn = create(AgentConversationTurnStructureSchema, { |
| 657 | userMessage: userMsgBytes, |
| 658 | steps: stepBytes, |
| 659 | }); |
| 660 | const turnStructure = create(ConversationTurnStructureSchema, { |
| 661 | turn: { case: "agentConversationTurn", value: agentTurn }, |
| 662 | }); |
| 663 | turnBytes.push(toBinary(ConversationTurnStructureSchema, turnStructure)); |
| 664 | } |
| 665 | |
| 666 | conversationState = create(ConversationStateStructureSchema, { |
| 667 | rootPromptMessagesJson: [systemBlobId], |
| 668 | turns: turnBytes, |
| 669 | todos: [], |
| 670 | pendingToolCalls: [], |
| 671 | previousWorkspaceUris: [], |
no outgoing calls
no test coverage detected