Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 263x 263x 263x 11x 263x 1809x | /**
* The configured instance and token a static-token call works with when its chat switched
* to one. Kept apart from the account list so the HTTP layer can read it without importing
* the instance registry.
*/
import { AsyncLocalStorage } from 'node:async_hooks';
export interface TokenAccountContext {
instanceUrl: string;
token: string;
}
const storage = new AsyncLocalStorage<TokenAccountContext>();
/** Run `fn` with the chat's chosen instance and token. */
export function runWithTokenAccount<T>(account: TokenAccountContext, fn: () => T): T {
return storage.run(account, fn);
}
/** The instance and token of the running call, when its chat switched to one. */
export function currentTokenAccount(): TokenAccountContext | undefined {
return storage.getStore();
}
|