axios+telemetry cleanup

This commit is contained in:
2026-04-02 15:19:11 +03:00
parent a3cbca1e11
commit 7e1eac8002
100 changed files with 3048 additions and 4491 deletions

View File

@@ -13,7 +13,7 @@
*/
import { feature } from 'bun:bundle'
import axios from 'axios'
import { nativeRequest } from '../../utils/http.js'
import { randomUUID } from 'crypto'
import { readFile } from 'fs/promises'
import { basename, extname } from 'path'
@@ -137,7 +137,9 @@ export async function uploadBriefAttachment(
])
try {
const response = await axios.post(url, body, {
const response = await nativeRequest(url, {
method: 'POST',
body,
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': `multipart/form-data; boundary=${boundary}`,
@@ -145,7 +147,6 @@ export async function uploadBriefAttachment(
},
timeout: UPLOAD_TIMEOUT_MS,
signal: ctx.signal,
validateStatus: () => true,
})
if (response.status !== 201) {

View File

@@ -1,4 +1,4 @@
import axios from 'axios'
import { nativeRequest } from '../../utils/http.js'
import { z } from 'zod/v4'
import { getOauthConfig } from '../../constants/oauth.js'
import { getFeatureValue_CACHED_MAY_BE_STALE } from '../../services/analytics/growthbook.js'
@@ -132,14 +132,12 @@ export const RemoteTriggerTool = buildTool({
break
}
const res = await axios.request({
const res = await nativeRequest(url, {
method,
url,
headers,
data,
body: data,
timeout: 20_000,
signal: context.abortController.signal,
validateStatus: () => true,
})
return {

View File

@@ -1,4 +1,4 @@
import axios, { type AxiosResponse } from 'axios'
import { isHttpError, nativeRequest } from '../../utils/http.js'
import { LRUCache } from 'lru-cache'
import {
type AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
@@ -180,7 +180,7 @@ export async function checkDomainBlocklist(
return { status: 'allowed' }
}
try {
const response = await axios.get(
const response = await nativeRequest(
`https://api.anthropic.com/api/web/domain_info?domain=${encodeURIComponent(domain)}`,
{ timeout: DOMAIN_CHECK_TIMEOUT_MS },
)
@@ -264,17 +264,16 @@ export async function getWithPermittedRedirects(
signal: AbortSignal,
redirectChecker: (originalUrl: string, redirectUrl: string) => boolean,
depth = 0,
): Promise<AxiosResponse<ArrayBuffer> | RedirectInfo> {
): Promise<{ data: ArrayBuffer; status: number; headers: Record<string, string> } | RedirectInfo> {
if (depth > MAX_REDIRECTS) {
throw new Error(`Too many redirects (exceeded ${MAX_REDIRECTS})`)
}
try {
return await axios.get(url, {
return await nativeRequest<ArrayBuffer>(url, {
method: 'GET',
signal,
timeout: FETCH_TIMEOUT_MS,
maxRedirects: 0,
responseType: 'arraybuffer',
maxContentLength: MAX_HTTP_CONTENT_LENGTH,
headers: {
Accept: 'text/markdown, text/html, */*',
'User-Agent': getWebFetchUserAgent(),
@@ -282,11 +281,11 @@ export async function getWithPermittedRedirects(
})
} catch (error) {
if (
axios.isAxiosError(error) &&
error.response &&
[301, 302, 307, 308].includes(error.response.status)
isHttpError(error) &&
error.status &&
[301, 302, 307, 308].includes(error.status)
) {
const redirectLocation = error.response.headers.location
const redirectLocation = error.headers?.location
if (!redirectLocation) {
throw new Error('Redirect missing Location header')
}
@@ -302,23 +301,22 @@ export async function getWithPermittedRedirects(
redirectChecker,
depth + 1,
)
} else {
// Return redirect information to the caller
return {
type: 'redirect',
originalUrl: url,
redirectUrl,
statusCode: error.response.status,
}
}
// Return redirect information to the caller
return {
type: 'redirect',
originalUrl: url,
redirectUrl,
statusCode: error.status,
}
}
// Detect egress proxy blocks: the proxy returns 403 with
// X-Proxy-Error: blocked-by-allowlist when egress is restricted
if (
axios.isAxiosError(error) &&
error.response?.status === 403 &&
error.response.headers['x-proxy-error'] === 'blocked-by-allowlist'
isHttpError(error) &&
error.status === 403 &&
error.headers?.['x-proxy-error'] === 'blocked-by-allowlist'
) {
const hostname = new URL(url).hostname
throw new EgressBlockedError(hostname)
@@ -329,7 +327,7 @@ export async function getWithPermittedRedirects(
}
function isRedirectInfo(
response: AxiosResponse<ArrayBuffer> | RedirectInfo,
response: { data: ArrayBuffer; status: number; headers: Record<string, string> } | RedirectInfo,
): response is RedirectInfo {
return 'type' in response && response.type === 'redirect'
}