Skip to content

Commit

Permalink
feat: ✨ add clear method to AzureTokenResolver and update usages
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 19, 2024
1 parent 44dd8a4 commit 19236d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/cli/src/azuretoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ class AzureTokenResolverImpl implements AzureTokenResolver {
return this._error
}

clear() {
this._token = undefined
this._error = undefined
this._resolver = undefined
}

async token(
credentialsType: AzureCredentialsType,
options?: CancellationOptions
Expand All @@ -121,23 +127,25 @@ class AzureTokenResolverImpl implements AzureTokenResolver {
if (!this._resolver) {
const scope = await runtimeHost.readSecret(this.envName)
const scopes = scope ? scope.split(",") : this.scopes
this._resolver = createAzureToken(
const resolver = (this._resolver = createAzureToken(
scopes,
credentialsType,
cancellationToken
)
.then((res) => {
if (this._resolver !== resolver) return undefined
this._token = res
this._error = undefined
this._resolver = undefined
return { token: this._token, error: this._error }
})
.catch((err) => {
if (this._resolver !== resolver) return undefined
this._resolver = undefined
this._token = undefined
this._error = serializeError(err)
return { token: this._token, error: this._error }
})
}))
}
return this._resolver
}
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/nodehost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class NodeHost implements RuntimeHost {
source: "default",
candidates: DEFAULT_REASONING_SMALL_MODEL_CANDIDATES,
},
long: { model: LARGE_MODEL_ID, source: "default" },
agent: { model: LARGE_MODEL_ID, source: "default" },
memory: { model: SMALL_MODEL_ID, source: "default" },
},
Expand Down Expand Up @@ -195,6 +196,9 @@ export class NodeHost implements RuntimeHost {
}

async readConfig(): Promise<HostConfiguration> {
this.azureToken.clear()
this.azureServerlessToken.clear()

const config = await resolveGlobalConfiguration(this.dotEnvPath)
const { envFile, modelAliases } = config
if (modelAliases)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export function isAzureTokenExpired(token: AuthenticationToken) {
}

export interface AzureTokenResolver {
clear(): void
token(
credentialsType: AzureCredentialsType,
options?: CancellationOptions
Expand Down

0 comments on commit 19236d2

Please sign in to comment.