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

Function mapPrincipalSource

src/auth/runtime/AuthRuntime.ts:122–185  ·  view source on GitHub ↗
(params: {
  apiKeySource: ReturnType<typeof getAnthropicApiKeyWithSource>['source']
  authTokenSource: ReturnType<typeof getAuthTokenSource>['source']
  hasStoredManagedPrincipal: boolean
  using3P: boolean
})

Source from the content-addressed store, hash-verified

120}
121
122function mapPrincipalSource(params: {
123 apiKeySource: ReturnType<typeof getAnthropicApiKeyWithSource>['source']
124 authTokenSource: ReturnType<typeof getAuthTokenSource>['source']
125 hasStoredManagedPrincipal: boolean
126 using3P: boolean
127}): PrincipalSource {
128 const { apiKeySource, authTokenSource, hasStoredManagedPrincipal, using3P } = params
129
130 if (using3P) {
131 return 'third_party_provider'
132 }
133
134 if (
135 process.env.NCODE_REMOTE_RUNTIME_TOKEN_TRANSPORT ===
136 'static_api_key_env' &&
137 isDirectApiKeyEnvVarName(apiKeySource)
138 ) {
139 return 'direct_api_key_env'
140 }
141
142 if (
143 process.env.NCODE_REMOTE_RUNTIME_PROVIDER_MODE === 'byok' &&
144 apiKeySource === 'ANTHROPIC_API_KEY'
145 ) {
146 return 'direct_api_key_env'
147 }
148 if (
149 process.env.NCODE_REMOTE_RUNTIME_PROVIDER_MODE === 'byok_openai' &&
150 apiKeySource === 'OPENAI_API_KEY'
151 ) {
152 return 'direct_api_key_env'
153 }
154
155 if (authTokenSource === 'ANTHROPIC_AUTH_TOKEN') {
156 return 'external_bearer_compat'
157 }
158 if (
159 authTokenSource === 'NCODE_OAUTH_TOKEN' ||
160 authTokenSource === 'CLAUDE_CODE_OAUTH_TOKEN'
161 ) {
162 return 'service_oauth_env'
163 }
164 if (
165 authTokenSource === 'NCODE_OAUTH_TOKEN_FILE_DESCRIPTOR' ||
166 authTokenSource === 'CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR' ||
167 authTokenSource === 'CCR_OAUTH_TOKEN_FILE'
168 ) {
169 return 'service_oauth_fd'
170 }
171 if (isDirectApiKeyEnvVarName(apiKeySource)) {
172 return 'direct_api_key_env'
173 }
174 if (hasStoredManagedPrincipal || authTokenSource === 'noumena.com') {
175 return 'managed_oauth'
176 }
177 if (apiKeySource === '/login managed key') {
178 return 'console_api_key'
179 }

Callers 1

resolveSessionSnapshotFunction · 0.85

Calls 1

isDirectApiKeyEnvVarNameFunction · 0.85

Tested by

no test coverage detected