MCPcopy Create free account
hub / github.com/github/copilot-sdk / findSavedChatCompletionResponse

Function findSavedChatCompletionResponse

test/harness/replayingCapiProxy.ts:638–673  ·  view source on GitHub ↗
(
  storedData: NormalizedData,
  requestBody: string | undefined,
  workDir: string,
  toolResultNormalizers: ToolResultNormalizer[],
)

Source from the content-addressed store, hash-verified

636}
637
638async function findSavedChatCompletionResponse(
639 storedData: NormalizedData,
640 requestBody: string | undefined,
641 workDir: string,
642 toolResultNormalizers: ToolResultNormalizer[],
643): Promise<ChatCompletion | undefined> {
644 // Normalize the incoming request the same way we normalize for caching
645 const normalized = await parseAndNormalizeRequest(
646 requestBody,
647 workDir,
648 toolResultNormalizers,
649 );
650 const requestMessages = normalized.conversations[0]?.messages ?? [];
651 const requestModel = normalized.models[0];
652 if (!requestModel) {
653 throw new Error("Unable to determine model from request");
654 }
655
656 // Now find a matching cached conversation (i.e., one for which this request is a prefix)
657 for (const conversation of storedData.conversations) {
658 const replyIndex = findAssistantIndexAfterPrefix(
659 requestMessages,
660 conversation.messages,
661 );
662 if (replyIndex !== undefined) {
663 return createOpenAIResponse(
664 requestModel,
665 conversation.messages,
666 replyIndex,
667 workDir,
668 );
669 }
670 }
671
672 return undefined;
673}
674
675async function findSavedChatCompletionError(
676 storedData: NormalizedData,

Callers 1

performRequestMethod · 0.85

Calls 3

parseAndNormalizeRequestFunction · 0.85
createOpenAIResponseFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…