|
2 | 2 | * Copyright (c) Microsoft Corporation. All rights reserved. |
3 | 3 | *--------------------------------------------------------------------------------------------*/ |
4 | 4 |
|
5 | | -import type { retrieveAvailableModels } from "@github/copilot/sdk"; |
6 | 5 | import { existsSync } from "fs"; |
7 | 6 | import { mkdir, readFile, writeFile } from "fs/promises"; |
8 | 7 | import type { |
@@ -663,9 +662,23 @@ function transformOpenAIRequestMessage( |
663 | 662 | } else if (m.role === "user" && typeof m.content === "string") { |
664 | 663 | content = normalizeUserMessage(m.content); |
665 | 664 | } else if (m.role === "tool" && typeof m.content === "string") { |
666 | | - // If it's a JSON tool call result, normalize the whitespace and property ordering |
| 665 | + // If it's a JSON tool call result, normalize the whitespace and property ordering. |
| 666 | + // For successful tool results wrapped in {resultType, textResultForLlm}, unwrap to |
| 667 | + // just the inner value so snapshots stay stable across envelope format changes. |
667 | 668 | try { |
668 | | - content = JSON.stringify(sortJsonKeys(JSON.parse(m.content))); |
| 669 | + const parsed = JSON.parse(m.content); |
| 670 | + if ( |
| 671 | + parsed && |
| 672 | + typeof parsed === "object" && |
| 673 | + parsed.resultType === "success" && |
| 674 | + "textResultForLlm" in parsed |
| 675 | + ) { |
| 676 | + content = typeof parsed.textResultForLlm === "string" |
| 677 | + ? parsed.textResultForLlm |
| 678 | + : JSON.stringify(sortJsonKeys(parsed.textResultForLlm)); |
| 679 | + } else { |
| 680 | + content = JSON.stringify(sortJsonKeys(parsed)); |
| 681 | + } |
669 | 682 | } catch { |
670 | 683 | content = m.content.trim(); |
671 | 684 | } |
@@ -950,9 +963,7 @@ function convertToStreamingResponseChunks( |
950 | 963 | return chunks; |
951 | 964 | } |
952 | 965 |
|
953 | | -function createGetModelsResponse(modelIds: string[]): { |
954 | | - data: Awaited<ReturnType<typeof retrieveAvailableModels>>; |
955 | | -} { |
| 966 | +function createGetModelsResponse(modelIds: string[]) { |
956 | 967 | // Obviously the following might not match any given model. We could track the original responses from /models, |
957 | 968 | // but that risks invalidating the caches too frequently and making this unmaintainable. If this approximation |
958 | 969 | // turns out to be insufficient, we can tweak the logic here based on known model IDs. |
|
0 commit comments