Repository navigation
Expand file tree
/
Copy pathnative_session_state.go
More file actions
94 lines (88 loc) · 2.79 KB
/
Copy pathnative_session_state.go
File metadata and controls
94 lines (88 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package acpruntime
import (
"encoding/json"
"fmt"
)
func nativeCodexModel(agent Agent, meta map[string]any) string {
if model := metaString(meta, "model"); model != "" {
return model
}
var config struct {
Model string `json:"model"`
}
_ = json.Unmarshal([]byte(agent.Env["CODEX_CONFIG"]), &config)
return config.Model
}
func nativeModelOption(model string) SessionConfigOption {
category := "model"
return SessionConfigOption{Type: "string", ID: "model", Name: "Model", Category: &category, Value: model}
}
func (e *codexNativeEngine) SessionState(sessionID string) NewSessionResponse {
e.mu.Lock()
defer e.mu.Unlock()
response := NewSessionResponse{SessionID: sessionID}
if session := e.sessions[sessionID]; session != nil {
response.ConfigOptions = []SessionConfigOption{nativeModelOption(session.model)}
response.Models = &SessionModelState{CurrentModelID: session.model}
if session.model != "" {
response.Models.AvailableModels = []ModelInfo{{ID: session.model, Name: session.model}}
}
}
return response
}
// Codex's native boot config is immutable. Equal assignments acknowledge the
// actual thread/start readback; other changes require a fresh connection.
func (e *codexNativeEngine) SetSpawnOption(sessionID, key string, value any) error {
e.mu.Lock()
defer e.mu.Unlock()
if session := e.sessions[sessionID]; session != nil && key == "model" && value == session.model {
return nil
}
return wrapError(ErrorProtocol, "native.codex.config", fmt.Sprintf("%s is fixed at session start; create a new session to change it", key), nil)
}
func (e *claudeNativeEngine) SessionState(sessionID string) NewSessionResponse {
proc, err := e.proc(sessionID)
if err != nil {
return NewSessionResponse{SessionID: sessionID}
}
proc.mu.Lock()
defer proc.mu.Unlock()
model, mode := proc.model, proc.permissionMode
if proc.pendingReq != nil {
if model == "" {
model = metaString(proc.pendingReq.Meta, "model")
}
if mode == "" {
mode = metaString(proc.pendingReq.Meta, "mode")
}
}
if model == "" {
model = e.opts.Agent.Env["ANTHROPIC_MODEL"]
}
if mode == "" {
mode = "default"
}
category := "mode"
models := &SessionModelState{CurrentModelID: model}
if model != "" {
models.AvailableModels = []ModelInfo{{ID: model, Name: model}}
}
return NewSessionResponse{
SessionID: sessionID,
Models: models,
Modes: &SessionModeState{
CurrentModeID: mode,
AvailableModes: []SessionMode{
{ID: "default", Name: "Default"},
{ID: "acceptEdits", Name: "Accept Edits"},
{ID: "plan", Name: "Plan"},
{ID: "bypassPermissions", Name: "Bypass Permissions"},
{ID: "dontAsk", Name: "Don't Ask"},
},
},
ConfigOptions: []SessionConfigOption{
nativeModelOption(model),
{Type: "string", ID: "mode", Name: "Permission mode", Category: &category, Value: mode},
},
}
}