feat(auth): validate agent context upstream
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
export type RuntimeSessionContext = {
|
||||
accessToken?: string;
|
||||
actorKey: string;
|
||||
authExpired?: {
|
||||
message: string;
|
||||
reason: "access_token_expired" | "access_token_rejected";
|
||||
};
|
||||
allowLearningWrite?: boolean;
|
||||
clientSessionId: string;
|
||||
learningMode?: "interactive" | "review";
|
||||
@@ -8,6 +12,7 @@ export type RuntimeSessionContext = {
|
||||
projectId?: string;
|
||||
projectKey: string;
|
||||
sessionId: string;
|
||||
tokenExpiresAt?: string;
|
||||
traceId: string;
|
||||
};
|
||||
|
||||
@@ -22,6 +27,23 @@ export const getRuntimeSessionContext = (sessionId: string) => {
|
||||
return context ? { ...context } : null;
|
||||
};
|
||||
|
||||
export const markRuntimeSessionAuthExpired = (
|
||||
sessionId: string,
|
||||
reason: NonNullable<RuntimeSessionContext["authExpired"]>["reason"],
|
||||
message = "登录态已过期,请刷新登录后重试",
|
||||
) => {
|
||||
const context = contexts.get(sessionId);
|
||||
if (!context) {
|
||||
return null;
|
||||
}
|
||||
const nextContext: RuntimeSessionContext = {
|
||||
...context,
|
||||
authExpired: { message, reason },
|
||||
};
|
||||
contexts.set(sessionId, nextContext);
|
||||
return { ...nextContext };
|
||||
};
|
||||
|
||||
export const removeRuntimeSessionContext = (sessionId: string) => {
|
||||
contexts.delete(sessionId);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user