MCPcopy Create free account
hub / github.com/echoVic/blade-code / loadSession

Method loadSession

src/context/ContextManager.ts:142–188  ·  view source on GitHub ↗

* 加载现有会话

(sessionId: string)

Source from the content-addressed store, hash-verified

140 * 加载现有会话
141 */
142 async loadSession(sessionId: string): Promise<boolean> {
143 try {
144 // 先尝试从内存加载
145 let contextData = this.memory.getContext();
146
147 if (!contextData || contextData.layers.session.sessionId !== sessionId) {
148 // 从持久化存储加载
149 const [session, conversation] = await Promise.all([
150 this.persistent.loadSession(sessionId),
151 this.persistent.loadConversation(sessionId),
152 ]);
153
154 if (!session || !conversation) {
155 return false;
156 }
157
158 // 重建完整的上下文数据
159 contextData = {
160 layers: {
161 system: await this.createSystemContext(),
162 session,
163 conversation,
164 tool: {
165 recentCalls: [],
166 toolStates: {},
167 dependencies: {},
168 },
169 workspace: await this.createWorkspaceContext(),
170 },
171 metadata: {
172 totalTokens: 0,
173 priority: 1,
174 lastUpdated: Date.now(),
175 },
176 };
177
178 this.memory.setContext(contextData);
179 }
180
181 this.currentSessionId = sessionId;
182 console.log(`会话已加载: ${sessionId}`);
183 return true;
184 } catch (error) {
185 console.error('加载会话失败:', error);
186 return false;
187 }
188 }
189
190 /**
191 * 添加消息到当前会话

Callers

nothing calls this directly

Calls 7

createSystemContextMethod · 0.95
getContextMethod · 0.80
loadConversationMethod · 0.80
setContextMethod · 0.80
logMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected