feat(auth): validate agent context upstream

This commit is contained in:
2026-06-12 10:18:41 +08:00
parent 4b572d9264
commit 8857b18dc9
13 changed files with 247 additions and 57 deletions
+22
View File
@@ -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);
};