Initialize onboarding agent scaffold
This commit is contained in:
commit
4294f3c92e
57 files changed
+14388
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { AsyncLocalStorage } from 'node:async_hooks';
|
||||
|
||||
import type { Logger } from 'pino';
|
||||
|
||||
import { getLogger } from './logger.js';
|
||||
|
||||
export interface RequestContext {
|
||||
chatroomId: string;
|
||||
deadlineAt?: string;
|
||||
logger: Logger;
|
||||
requestId: string;
|
||||
skill: string;
|
||||
startedAt: string;
|
||||
trigger: string;
|
||||
userId: string;
|
||||
}
|
||||
|
||||
const requestContextStorage = new AsyncLocalStorage<RequestContext>();
|
||||
|
||||
export function runWithContext<T>(
|
||||
context: Omit<RequestContext, 'logger'> & { logger?: Logger },
|
||||
fn: () => T,
|
||||
): T {
|
||||
const logger =
|
||||
context.logger ??
|
||||
getLogger({
|
||||
chatroomId: context.chatroomId,
|
||||
requestId: context.requestId,
|
||||
skill: context.skill,
|
||||
trigger: context.trigger,
|
||||
userId: context.userId,
|
||||
});
|
||||
|
||||
return requestContextStorage.run(
|
||||
{
|
||||
...context,
|
||||
logger,
|
||||
},
|
||||
fn,
|
||||
);
|
||||
}
|
||||
|
||||
export function getContext(): RequestContext | undefined {
|
||||
return requestContextStorage.getStore();
|
||||
}
|
||||
|
||||
export function getRequestLogger(): Logger {
|
||||
return getContext()?.logger ?? getLogger();
|
||||
}
|
||||
Reference in new issue
Block a user