Skip to content

Commit eb26341

Browse files
lsr911claude
andcommitted
fix(feishu,browser,msteams,bedrock-mantle,googlechat,huggingface): bound JSON via shared provider helpers
Use readProviderJsonResponse (shared 16 MiB default cap) for HTTP JSON reads. Co-Authored-By: Claude <[email protected]> Signed-off-by: lsr911 <[email protected]>
1 parent fbfadbd commit eb26341

11 files changed

Lines changed: 25 additions & 19 deletions

File tree

extensions/amazon-bedrock-mantle/discovery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export async function discoverMantleModels(params: {
302302
return cached?.models ?? [];
303303
}
304304

305-
const body = (await response.json()) as OpenAIModelsResponse;
305+
const body = (await readProviderJsonResponse(response, "discovery")) as OpenAIModelsResponse;
306306
const rawModels = body.data ?? [];
307307

308308
const models = rawModels

extensions/browser/src/browser/cdp.helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export async function fetchJson<T>(
306306
): Promise<T> {
307307
const { response, release } = await fetchCdpChecked(url, timeoutMs, init, ssrfPolicy);
308308
try {
309-
return (await response.json()) as T;
309+
return (await readProviderJsonResponse(response, "cdp.helpers")) as T;
310310
} finally {
311311
await release();
312312
}

extensions/browser/src/browser/chrome.diagnostics.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ export async function readChromeVersion(
110110
ssrfPolicy,
111111
);
112112
try {
113-
const data = (await response.json()) as ChromeVersion;
113+
const data = (await readProviderJsonResponse(
114+
response,
115+
"chrome.diagnostics",
116+
)) as ChromeVersion;
114117
if (!data || typeof data !== "object") {
115118
throw new Error("CDP /json/version returned non-object JSON");
116119
}

extensions/browser/src/browser/client-fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ async function fetchHttpJson<T>(
270270
const text = await res.text().catch(() => "");
271271
throw new BrowserServiceError(text || `HTTP ${res.status}`);
272272
}
273-
return (await res.json()) as T;
273+
return (await readProviderJsonResponse(res, "client-fetch")) as T;
274274
} finally {
275275
clearTimeout(t);
276276
await release?.();

extensions/feishu/src/app-registration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async function fetchFeishuJson<T>(params: {
109109
});
110110
try {
111111
// Registration poll returns 4xx for pending/error states with a JSON body.
112-
return (await response.json()) as T;
112+
return (await readProviderJsonResponse(response, "app-registration")) as T;
113113
} finally {
114114
await release();
115115
}

extensions/feishu/src/streaming-card.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async function getToken(creds: Credentials): Promise<string> {
116116
await release();
117117
throw new Error(`Token request failed with HTTP ${response.status}`);
118118
}
119-
const data = (await response.json()) as {
119+
const data = (await readProviderJsonResponse(response, "streaming-card")) as {
120120
code: number;
121121
msg: string;
122122
tenant_access_token?: string;
@@ -276,7 +276,7 @@ export class FeishuStreamingSession {
276276
await releaseCreate();
277277
throw new Error(`Create card request failed with HTTP ${createRes.status}`);
278278
}
279-
const createData = (await createRes.json()) as {
279+
const createData = (await readProviderJsonResponse(createRes, "streaming-card")) as {
280280
code: number;
281281
msg: string;
282282
data?: { card_id: string };

extensions/huggingface/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export async function discoverHuggingfaceModels(
165165
return HUGGINGFACE_MODEL_CATALOG.map(buildHuggingfaceModelDefinition);
166166
}
167167

168-
const body = (await response.json()) as OpenAIListModelsResponse;
168+
const body = (await readProviderJsonResponse(response, "models")) as OpenAIListModelsResponse;
169169
const data = body?.data;
170170
if (!Array.isArray(data) || data.length === 0) {
171171
return HUGGINGFACE_MODEL_CATALOG.map(buildHuggingfaceModelDefinition);

extensions/msteams/src/attachments/bot-framework.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ async function fetchBotFrameworkAttachmentInfo(params: {
112112
return undefined;
113113
}
114114
try {
115-
return (await response.json()) as BotFrameworkAttachmentInfo;
115+
return (await readProviderJsonResponse(
116+
response,
117+
"bot-framework",
118+
)) as BotFrameworkAttachmentInfo;
116119
} catch (err) {
117120
params.logger?.warn?.("msteams botFramework attachmentInfo parse failed", {
118121
error: err instanceof Error ? err.message : String(err),

extensions/msteams/src/attachments/graph.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async function fetchGraphCollection(params: {
143143
return { status, items: [] };
144144
}
145145
try {
146-
const data = (await response.json()) as { value?: unknown[] };
146+
const data = (await readProviderJsonResponse(response, "graph")) as { value?: unknown[] };
147147
return { status, items: Array.isArray(data.value) ? data.value : [] };
148148
} catch {
149149
return { status, items: [] };
@@ -345,7 +345,7 @@ export async function downloadMSTeamsGraphMedia(params: {
345345
attachments?: GraphAttachment[];
346346
};
347347
try {
348-
msgData = (await msgRes.json()) as typeof msgData;
348+
msgData = (await readProviderJsonResponse(msgRes, "graph")) as typeof msgData;
349349
} catch (err) {
350350
debugLog?.debug?.("graph media message parse failed", {
351351
messageUrl,

extensions/msteams/src/graph-upload.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function uploadToOneDrive(params: {
5454
throw await createMSTeamsHttpError(res, "OneDrive upload failed");
5555
}
5656

57-
const data = (await res.json()) as {
57+
const data = (await readProviderJsonResponse(res, "graph-upload")) as {
5858
id?: string;
5959
webUrl?: string;
6060
name?: string;
@@ -106,7 +106,7 @@ async function createSharingLink(params: {
106106
throw await createMSTeamsHttpError(res, "Create sharing link failed");
107107
}
108108

109-
const data = (await res.json()) as {
109+
const data = (await readProviderJsonResponse(res, "graph-upload")) as {
110110
link?: { webUrl?: string };
111111
};
112112

@@ -200,7 +200,7 @@ export async function uploadToSharePoint(params: {
200200
throw await createMSTeamsHttpError(res, "SharePoint upload failed");
201201
}
202202

203-
const data = (await res.json()) as {
203+
const data = (await readProviderJsonResponse(res, "graph-upload")) as {
204204
id?: string;
205205
webUrl?: string;
206206
name?: string;
@@ -260,7 +260,7 @@ export async function getDriveItemProperties(params: {
260260
throw await createMSTeamsHttpError(res, "Get driveItem properties failed");
261261
}
262262

263-
const data = (await res.json()) as {
263+
const data = (await readProviderJsonResponse(res, "graph-upload")) as {
264264
eTag?: string;
265265
webDavUrl?: string;
266266
name?: string;
@@ -331,7 +331,7 @@ export async function resolveGraphChatId(params: {
331331
return null;
332332
}
333333

334-
const data = (await res.json()) as {
334+
const data = (await readProviderJsonResponse(res, "graph-upload")) as {
335335
value?: Array<{ id?: string }>;
336336
};
337337

@@ -371,7 +371,7 @@ async function getChatMembers(params: {
371371
throw await createMSTeamsHttpError(res, "Get chat members failed");
372372
}
373373

374-
const data = (await res.json()) as {
374+
const data = (await readProviderJsonResponse(res, "graph-upload")) as {
375375
value?: Array<{
376376
userId?: string;
377377
displayName?: string;
@@ -435,7 +435,7 @@ async function createSharePointSharingLink(params: {
435435
throw await createMSTeamsHttpError(res, "Create SharePoint sharing link failed");
436436
}
437437

438-
const data = (await res.json()) as {
438+
const data = (await readProviderJsonResponse(res, "graph-upload")) as {
439439
link?: { webUrl?: string };
440440
};
441441

0 commit comments

Comments
 (0)