feat(context): verify product session scope
This commit is contained in:
@@ -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(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user