MCPcopy Create free account
hub / github.com/Noumena-Network/code / fetchEnvironments

Function fetchEnvironments

src/utils/teleport/environments.ts:55–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53 * @throws Error if the API request fails or no access token is available
54 */
55export async function fetchEnvironments(): Promise<EnvironmentResource[]> {
56 const { accessToken, orgUUID } = await resolveManagedRemoteCapability()
57
58 const url = buildNoumenaPlatformUrl('/v1/environment_providers')
59
60 try {
61 const headers = {
62 ...getOAuthHeaders(accessToken),
63 'x-organization-uuid': orgUUID,
64 }
65
66 const response = await axios.get<EnvironmentListResponse>(url, {
67 headers,
68 timeout: 15000,
69 })
70
71 if (response.status !== 200) {
72 throw new Error(
73 `Failed to fetch environments: ${response.status} ${response.statusText}`,
74 )
75 }
76
77 return response.data.environments.map(environment => ({
78 ...environment,
79 kind: normalizeEnvironmentKind(environment.kind),
80 }))
81 } catch (error) {
82 const err = toError(error)
83 logError(err)
84 throw new Error(`Failed to fetch environments: ${err.message}`)
85 }
86}
87
88/**
89 * Creates a default noumena_cloud environment for users who have none.

Callers 6

teleportToRemoteFunction · 0.85
hasExistingEnvironmentFunction · 0.85
getPromptForCommandFunction · 0.85

Calls 6

buildNoumenaPlatformUrlFunction · 0.85
getOAuthHeadersFunction · 0.85
normalizeEnvironmentKindFunction · 0.85
toErrorFunction · 0.50
logErrorFunction · 0.50

Tested by

no test coverage detected