返回 DeepSeek-Reasonix
native_session.go
根目录 / internal / acp / native_session.go
1 package acp
2
3 import (
4 "context"
5 "errors"
6 "os"
7
8 "reasonix/internal/control"
9 "reasonix/internal/session"
10 )
11
12 func existingTranscript(path string) bool {
13 _, err := os.Stat(path)
14 return err == nil
15 }
16
17 func canonicalSessionExists(ctx context.Context, ctrl *control.Controller, id string) (bool, error) {
18 service := ctrl.SessionService()
19 if service == nil {
20 return ctrl.UsesExclusiveSession(), nil
21 }
22 _, err := service.Query().Stat(ctx, session.SessionRef{HostID: service.HostID(), SessionID: id})
23 if errors.Is(err, session.ErrSessionNotFound) || os.IsNotExist(err) {
24 return ctrl.UsesExclusiveSession(), nil
25 }
26 return err == nil, err
27 }
28
29 func openCanonicalSession(ctx context.Context, ctrl *control.Controller, id, method string) error {
30 service := ctrl.SessionService()
31 if service == nil {
32 return &RPCError{Code: ErrInternal, Message: method + ": v3 session service is unavailable"}
33 }
34 if _, err := ctrl.OpenSession(ctx, session.SessionRef{HostID: service.HostID(), SessionID: id}); err != nil {
35 return &RPCError{Code: ErrInvalidParams, Message: method + ": unknown session " + id}
36 }
37 return nil
38 }
39
40 func (s *service) bindSessionClients(id string, params *SessionParams) {
41 s.bindSessionPathHandlers(id, params)
42 s.bindClientIO(params, id)
43 }
44
44 lines GO