MCPcopy Create free account
hub / github.com/diillson/chatcli / LoadSession

Method LoadSession

server/handler_session.go:208–242  ·  view source on GitHub ↗

LoadSession loads a saved session.

(ctx context.Context, req *pb.LoadSessionRequest)

Source from the content-addressed store, hash-verified

206
207// LoadSession loads a saved session.
208func (h *Handler) LoadSession(ctx context.Context, req *pb.LoadSessionRequest) (*pb.LoadSessionResponse, error) {
209 if h.sessionManager == nil {
210 return nil, status.Errorf(codes.Unavailable, "%s", i18n.T("server.session.mgmt_unavailable"))
211 }
212
213 if req.Name == "" {
214 return nil, status.Errorf(codes.InvalidArgument, "%s", i18n.T("server.session.name_empty"))
215 }
216
217 // Try v2 first if store supports it
218 if v2Store, ok := h.sessionManager.(SessionStoreV2); ok {
219 sd, err := v2Store.LoadSessionV2(req.Name)
220 if err != nil {
221 return nil, status.Errorf(codes.NotFound, "%s", i18n.T("server.session.not_found", err))
222 }
223 if h.sessionMetrics != nil {
224 h.sessionMetrics.OperationsTotal.WithLabelValues("load").Inc()
225 }
226 return &pb.LoadSessionResponse{
227 Messages: historyToProto(sd.ChatHistory), // v1 compat
228 SessionData: modelsSessionDataToProto(sd), // v2 full data
229 }, nil
230 }
231
232 // Fallback to v1
233 msgs, err := h.sessionManager.LoadSession(req.Name)
234 if err != nil {
235 return nil, status.Errorf(codes.NotFound, "%s", i18n.T("server.session.not_found", err))
236 }
237
238 if h.sessionMetrics != nil {
239 h.sessionMetrics.OperationsTotal.WithLabelValues("load").Inc()
240 }
241 return &pb.LoadSessionResponse{Messages: historyToProto(msgs)}, nil
242}
243
244// SaveSession saves the conversation history.
245func (h *Handler) SaveSession(ctx context.Context, req *pb.SaveSessionRequest) (*pb.SaveSessionResponse, error) {

Calls 6

TFunction · 0.92
historyToProtoFunction · 0.85
ErrorfMethod · 0.80
modelsSessionDataToProtoFunction · 0.70
LoadSessionV2Method · 0.65
LoadSessionMethod · 0.65