feat(context): verify product session scope

This commit is contained in:
2026-09-22 10:43:36 +08:00
parent 88b41ba04c
commit 9faed59f23
12 changed files with 358 additions and 56 deletions
+8 -2
View File
@@ -15,10 +15,12 @@ export type SessionBinding = {
};
export type SessionContext = {
actorKey?: string;
clientSessionId: string;
network?: string;
projectId?: string;
userId?: string;
projectKey?: string;
};
export type ChatRequestContext = SessionContext & {
@@ -38,6 +40,8 @@ export class ChatSessionBridge {
projectId?: string;
traceId?: string;
userId?: string;
actorKey?: string;
projectKey?: string;
}): Promise<{
binding: SessionBinding;
requestContext: ChatRequestContext;
@@ -139,19 +143,21 @@ export class ChatSessionBridge {
}
private buildRequestContext(context: {
actorKey?: string;
sessionId?: string;
network?: string;
projectId?: string;
traceId?: string;
userId?: string;
projectKey?: string;
}): ChatRequestContext {
const sessionId = context.sessionId?.trim();
return {
clientSessionId: sessionId || this.createClientSessionId(),
actorKey: toActorKey(context.userId),
actorKey: context.actorKey ?? toActorKey(`local:${context.userId ?? "local-user"}`),
network: context.network,
projectId: context.projectId,
projectKey: toProjectKey(context.projectId),
projectKey: context.projectKey ?? toProjectKey(`local:${context.projectId ?? "local-project"}`),
traceId: context.traceId?.trim() || `trace-${randomUUID().slice(0, 12)}`,
userId: context.userId?.trim(),
};