
























@@ -37,7 +37,7 @@ import {
3737loadAuthProfileStoreForSecretsRuntime,
3838resolvePersistedAuthProfileOwnerAgentDir,
3939} from "./store.js";
40-import type { AuthProfileStore, OAuthCredential } from "./types.js";
40+import type { AuthProfileCredential, AuthProfileStore, OAuthCredential } from "./types.js";
41414242export {
4343isSafeToCopyOAuthIdentity,
@@ -120,12 +120,37 @@ async function buildOAuthApiKey(
120120return typeof formatted === "string" && formatted.length > 0 ? formatted : credentials.access;
121121}
122122123-function buildApiKeyProfileResult(params: { apiKey: string; provider: string; email?: string }) {
124-return {
123+type ResolveApiKeyForProfileResult = {
124+apiKey: string;
125+provider: string;
126+email?: string;
127+profileId: string;
128+profileType: AuthProfileCredential["type"];
129+};
130+131+function buildApiKeyProfileResult(params: {
132+apiKey: string;
133+provider: string;
134+email?: string;
135+profileId: string;
136+profileType: AuthProfileCredential["type"];
137+}): ResolveApiKeyForProfileResult {
138+const result = {
125139apiKey: params.apiKey,
126140provider: params.provider,
127141email: params.email,
128142};
143+Object.defineProperties(result, {
144+profileId: {
145+value: params.profileId,
146+enumerable: false,
147+},
148+profileType: {
149+value: params.profileType,
150+enumerable: false,
151+},
152+});
153+return result as ResolveApiKeyForProfileResult;
129154}
130155131156function extractErrorMessage(error: unknown): string {
@@ -214,7 +239,7 @@ export function resetOAuthRefreshQueuesForTest(): void {
214239215240async function tryResolveOAuthProfile(
216241params: ResolveApiKeyForProfileParams,
217-): Promise<{ apiKey: string; provider: string; email?: string } | null> {
242+): Promise<ResolveApiKeyForProfileResult | null> {
218243const { cfg, store, profileId } = params;
219244const cred = store.profiles[profileId];
220245if (!cred || cred.type !== "oauth") {
@@ -246,6 +271,8 @@ async function tryResolveOAuthProfile(
246271apiKey: resolved.apiKey,
247272provider: resolved.credential.provider,
248273email: resolved.credential.email ?? cred.email,
274+ profileId,
275+profileType: cred.type,
249276});
250277}
251278@@ -302,7 +329,7 @@ async function resolveProfileSecretString(params: {
302329303330export async function resolveApiKeyForProfile(
304331params: ResolveApiKeyForProfileParams,
305-): Promise<{ apiKey: string; provider: string; email?: string } | null> {
332+): Promise<ResolveApiKeyForProfileResult | null> {
306333const { cfg, store, profileId } = params;
307334const cred = store.profiles[profileId];
308335if (!cred) {
@@ -346,7 +373,13 @@ export async function resolveApiKeyForProfile(
346373if (!key) {
347374return null;
348375}
349-return buildApiKeyProfileResult({ apiKey: key, provider: cred.provider, email: cred.email });
376+return buildApiKeyProfileResult({
377+apiKey: key,
378+provider: cred.provider,
379+email: cred.email,
380+ profileId,
381+profileType: cred.type,
382+});
350383}
351384if (cred.type === "token") {
352385const expiryState = resolveTokenExpiryState(cred.expires);
@@ -367,7 +400,13 @@ export async function resolveApiKeyForProfile(
367400if (!token) {
368401return null;
369402}
370-return buildApiKeyProfileResult({ apiKey: token, provider: cred.provider, email: cred.email });
403+return buildApiKeyProfileResult({
404+apiKey: token,
405+provider: cred.provider,
406+email: cred.email,
407+ profileId,
408+profileType: cred.type,
409+});
371410}
372411373412try {
@@ -386,6 +425,8 @@ export async function resolveApiKeyForProfile(
386425apiKey: resolved.apiKey,
387426provider: resolved.credential.provider,
388427email: resolved.credential.email ?? cred.email,
428+ profileId,
429+profileType: cred.type,
389430});
390431} catch (error) {
391432let refreshedStore =
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。