返回 DeepSeek-Reasonix
context.go
根目录 / internal / sessiontemp / context.go
1 package sessiontemp
2
3 import "context"
4
5 type ctxKey struct{}
6
7 // WithManager attaches m to ctx so tool executions in this scope (for example
8 // one sub-agent run) share a private temporary directory distinct from the
9 // parent agent and from sibling runs.
10 func WithManager(ctx context.Context, m *Manager) context.Context {
11 if ctx == nil {
12 ctx = context.Background()
13 }
14 if m == nil {
15 return ctx
16 }
17 return context.WithValue(ctx, ctxKey{}, m)
18 }
19
20 // FromContext returns the Manager attached by WithManager, or nil.
21 func FromContext(ctx context.Context) *Manager {
22 if ctx == nil {
23 return nil
24 }
25 m, _ := ctx.Value(ctxKey{}).(*Manager)
26 return m
27 }
28
28 lines GO