axios+telemetry cleanup
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
import { tmpdir } from 'os'
|
||||
import { extname, join } from 'path'
|
||||
import type { Command } from '../commands.js'
|
||||
import { VERSION } from '../constants/product.js'
|
||||
import { queryWithModel } from '../services/api/claude.js'
|
||||
import {
|
||||
AGENT_TOOL_NAME,
|
||||
@@ -2682,7 +2683,7 @@ export function buildExportData(
|
||||
facets: Map<string, SessionFacets>,
|
||||
remoteStats?: { hosts: RemoteHostInfo[]; totalCopied: number },
|
||||
): InsightsExport {
|
||||
const version = typeof MACRO !== 'undefined' ? MACRO.VERSION : 'unknown'
|
||||
const version = VERSION
|
||||
|
||||
const remote_hosts_collected = remoteStats?.hosts
|
||||
.filter(h => h.sessionCount > 0)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import axios from 'axios'
|
||||
import { isHttpError, nativeRequest } from '../../utils/http.js'
|
||||
import { getOauthConfig } from '../../constants/oauth.js'
|
||||
import { logForDebugging } from '../../utils/debug.js'
|
||||
import { getOAuthHeaders, prepareApiRequest } from '../../utils/teleport/api.js'
|
||||
@@ -69,32 +69,30 @@ export async function importGithubToken(
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.post<ImportTokenResult>(
|
||||
url,
|
||||
{ token: token.reveal() },
|
||||
{ headers, timeout: 15000, validateStatus: () => true },
|
||||
)
|
||||
if (response.status === 200) {
|
||||
return { ok: true, result: response.data }
|
||||
}
|
||||
if (response.status === 400) {
|
||||
const response = await nativeRequest<ImportTokenResult>(url, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: { token: token.reveal() },
|
||||
timeout: 15000,
|
||||
responseType: 'json',
|
||||
})
|
||||
return { ok: true, result: response.data }
|
||||
} catch (err) {
|
||||
if (isHttpError(err) && err.status === 400) {
|
||||
return { ok: false, error: { kind: 'invalid_token' } }
|
||||
}
|
||||
if (response.status === 401) {
|
||||
if (isHttpError(err) && err.status === 401) {
|
||||
return { ok: false, error: { kind: 'not_signed_in' } }
|
||||
}
|
||||
logForDebugging(`import-token returned ${response.status}`, {
|
||||
level: 'error',
|
||||
})
|
||||
return { ok: false, error: { kind: 'server', status: response.status } }
|
||||
} catch (err) {
|
||||
if (axios.isAxiosError(err)) {
|
||||
// err.config.data would contain the POST body with the raw token.
|
||||
// Do not include it in any log. The error code alone is enough.
|
||||
logForDebugging(`import-token network error: ${err.code ?? 'unknown'}`, {
|
||||
if (isHttpError(err) && err.status >= 400 && err.status < 500) {
|
||||
logForDebugging(`import-token returned ${err.status}`, {
|
||||
level: 'error',
|
||||
})
|
||||
return { ok: false, error: { kind: 'server', status: err.status } }
|
||||
}
|
||||
logForDebugging(`import-token network error: ${err instanceof Error ? err.message : 'unknown'}`, {
|
||||
level: 'error',
|
||||
})
|
||||
return { ok: false, error: { kind: 'network' } }
|
||||
}
|
||||
}
|
||||
@@ -138,9 +136,10 @@ export async function createDefaultEnvironment(): Promise<boolean> {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.post(
|
||||
url,
|
||||
{
|
||||
const response = await nativeRequest(url, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: {
|
||||
name: 'Default',
|
||||
kind: 'anthropic_cloud',
|
||||
description: 'Default - trusted network access',
|
||||
@@ -159,8 +158,9 @@ export async function createDefaultEnvironment(): Promise<boolean> {
|
||||
},
|
||||
},
|
||||
},
|
||||
{ headers, timeout: 15000, validateStatus: () => true },
|
||||
)
|
||||
timeout: 15000,
|
||||
responseType: 'json',
|
||||
})
|
||||
return response.status >= 200 && response.status < 300
|
||||
} catch {
|
||||
return false
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { Command, LocalCommandCall } from '../types/command.js'
|
||||
import { VERSION, BUILD_TIME } from '../constants/product.js'
|
||||
|
||||
const call: LocalCommandCall = async () => {
|
||||
return {
|
||||
type: 'text',
|
||||
value: MACRO.BUILD_TIME
|
||||
? `${MACRO.VERSION} (built ${MACRO.BUILD_TIME})`
|
||||
: MACRO.VERSION,
|
||||
value: BUILD_TIME ? `${VERSION} (built ${BUILD_TIME})` : VERSION,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user