新增会话标题管理功能,优化会话标题生成
This commit is contained in:
@@ -11,6 +11,7 @@ export type ChatRequestContext = SessionContext & {
|
||||
export class ChatSessionBridge {
|
||||
// 这里额外保存 session -> 用户上下文,供工具桥在服务端代发真实后端请求时复用。
|
||||
private readonly sessionContexts = new Map<string, ChatRequestContext>();
|
||||
private readonly sessionTitles = new Map<string, string>();
|
||||
|
||||
constructor(
|
||||
private readonly registry: SessionRegistry,
|
||||
@@ -70,6 +71,18 @@ export class ChatSessionBridge {
|
||||
return this.sessionContexts.get(sessionId) ?? null;
|
||||
}
|
||||
|
||||
getSessionTitle(sessionId: string) {
|
||||
return this.sessionTitles.get(sessionId);
|
||||
}
|
||||
|
||||
setSessionTitle(sessionId: string, title: string) {
|
||||
const normalized = title.trim();
|
||||
if (!normalized) {
|
||||
return;
|
||||
}
|
||||
this.sessionTitles.set(sessionId, normalized);
|
||||
}
|
||||
|
||||
async abort(context: {
|
||||
clientSessionId?: string;
|
||||
accessToken?: string;
|
||||
@@ -167,6 +180,7 @@ export class ChatSessionBridge {
|
||||
const expiredSessionIds = this.registry.evictExpired();
|
||||
for (const sessionId of expiredSessionIds) {
|
||||
this.sessionContexts.delete(sessionId);
|
||||
this.sessionTitles.delete(sessionId);
|
||||
// 这里用 abort 做轻量清理;即使失败,也不阻断本地过期回收。
|
||||
void this.runtime.abortSession(sessionId).catch((error) => {
|
||||
logger.debug({ sessionId, err: error }, "ignoring failed abort for expired session");
|
||||
|
||||
Reference in New Issue
Block a user