refactor, improve docs
This commit is contained in:
parent
dc6c2a00e9
commit
112997d352
1 changed files with 30079 additions and 1640 deletions
|
|
@ -1,36 +0,0 @@
|
|||
import { AsyncLocalStorage } from "async_hooks";
|
||||
import { FakeUpstreamInstallation } from "./types.js";
|
||||
|
||||
interface RequestContext {
|
||||
mcpAccessToken: string;
|
||||
fakeUpstreamInstallation: FakeUpstreamInstallation;
|
||||
}
|
||||
|
||||
export const asyncLocalStorage = new AsyncLocalStorage<RequestContext>();
|
||||
|
||||
export function getFakeUpstreamInstallation(): FakeUpstreamInstallation {
|
||||
const context = asyncLocalStorage.getStore();
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
"No request context found - are you calling this from within a request handler?",
|
||||
);
|
||||
}
|
||||
return context.fakeUpstreamInstallation;
|
||||
}
|
||||
|
||||
export function getMcpAccessToken(): string {
|
||||
const context = asyncLocalStorage.getStore();
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
"No request context found - are you calling this from within a request handler?",
|
||||
);
|
||||
}
|
||||
return context.mcpAccessToken;
|
||||
}
|
||||
|
||||
export function withContext<T>(
|
||||
context: RequestContext,
|
||||
fn: () => T | Promise<T>,
|
||||
): T | Promise<T> {
|
||||
return asyncLocalStorage.run(context, fn);
|
||||
}
|
||||
Loading…
Reference in a new issue