@@ -7,7 +7,10 @@ import {
|
7 | 7 | type MemoryEmbeddingProviderAdapter, |
8 | 8 | } from "openclaw/plugin-sdk/memory-core-host-engine-embeddings"; |
9 | 9 | import { buildCopilotIdeHeaders } from "openclaw/plugin-sdk/provider-auth"; |
10 | | -import { readResponseTextLimited } from "openclaw/plugin-sdk/provider-http"; |
| 10 | +import { |
| 11 | +readProviderJsonResponse, |
| 12 | +readResponseTextLimited, |
| 13 | +} from "openclaw/plugin-sdk/provider-http"; |
11 | 14 | import { resolveConfiguredSecretInputString } from "openclaw/plugin-sdk/secret-input-runtime"; |
12 | 15 | import { fetchWithSsrFGuard, type SsrFPolicy } from "openclaw/plugin-sdk/ssrf-runtime"; |
13 | 16 | import { resolveFirstGithubToken } from "./auth.js"; |
@@ -29,6 +32,7 @@ const COPILOT_HEADERS_STATIC: Record<string, string> = {
|
29 | 32 | ...buildCopilotIdeHeaders(), |
30 | 33 | }; |
31 | 34 | const COPILOT_ERROR_BODY_LIMIT_BYTES = 8 * 1024; |
| 35 | +const COPILOT_EMBEDDINGS_RESPONSE_MAX_BYTES = 64 * 1024 * 1024; |
32 | 36 | |
33 | 37 | function buildSsrfPolicy(baseUrl: string): SsrFPolicy | undefined { |
34 | 38 | try { |
@@ -70,6 +74,7 @@ function isCopilotSetupError(err: unknown): boolean {
|
70 | 74 | err.message.includes("Copilot token response") || |
71 | 75 | err.message.includes("No embedding models available") || |
72 | 76 | err.message.includes("GitHub Copilot model discovery") || |
| 77 | +err.message.includes("github-copilot.model-discovery") || |
73 | 78 | err.message.includes("GitHub Copilot embedding model") || |
74 | 79 | err.message.includes("Unexpected response from GitHub Copilot token endpoint") |
75 | 80 | ); |
@@ -100,12 +105,7 @@ async function discoverEmbeddingModels(params: {
|
100 | 105 | const detail = await readResponseTextLimited(response, COPILOT_ERROR_BODY_LIMIT_BYTES); |
101 | 106 | throw new Error(`GitHub Copilot model discovery HTTP ${response.status}: ${detail}`); |
102 | 107 | } |
103 | | -let payload: unknown; |
104 | | -try { |
105 | | -payload = await response.json(); |
106 | | -} catch { |
107 | | -throw new Error("GitHub Copilot model discovery returned invalid JSON"); |
108 | | -} |
| 108 | +const payload = await readProviderJsonResponse(response, "github-copilot.model-discovery"); |
109 | 109 | const allModels = Array.isArray((payload as { data?: unknown })?.data) |
110 | 110 | ? ((payload as { data: CopilotModelEntry[] }).data ?? []) |
111 | 111 | : []; |
@@ -246,12 +246,9 @@ async function createGitHubCopilotEmbeddingProvider(
|
246 | 246 | throw new Error(`GitHub Copilot embeddings HTTP ${response.status}: ${detail}`); |
247 | 247 | } |
248 | 248 | |
249 | | -let payload: unknown; |
250 | | -try { |
251 | | -payload = await response.json(); |
252 | | -} catch { |
253 | | -throw new Error("GitHub Copilot embeddings returned invalid JSON"); |
254 | | -} |
| 249 | +const payload = await readProviderJsonResponse(response, "github-copilot.embeddings", { |
| 250 | +maxBytes: COPILOT_EMBEDDINGS_RESPONSE_MAX_BYTES, |
| 251 | +}); |
255 | 252 | return parseGitHubCopilotEmbeddingPayload(payload, input.length); |
256 | 253 | }, |
257 | 254 | }); |
|