feat: switch model or agent and start new sessions
- chat: a searchable sheet picks the model or agent for the session; the choice is applied through the server and mirrored in the session list - sessions: a new-session sheet with a title and a working directory (the server's default plus the directories already listed); creating one opens its chat - ocapi: list models with their display names and read the server's default location - bump version to 0.1.1 (build 2)
This commit is contained in:
1 parent
254d08b1bd
commit
23f72fc46d
9 files changed
+461
-42
No files matched your search
@@ -19,6 +19,8 @@ type chatServer struct {
|
||||
*httptest.Server
|
||||
prompts chan map[string]any
|
||||
replies chan map[string]any
|
||||
models chan map[string]any
|
||||
created chan map[string]any
|
||||
events chan string
|
||||
ready chan struct{}
|
||||
readyOne sync.Once
|
||||
@@ -37,6 +39,8 @@ func newChatServer(t *testing.T) *chatServer {
|
||||
cs := &chatServer{
|
||||
prompts: make(chan map[string]any, 1),
|
||||
replies: make(chan map[string]any, 1),
|
||||
models: make(chan map[string]any, 1),
|
||||
created: make(chan map[string]any, 1),
|
||||
events: make(chan string, 8),
|
||||
ready: make(chan struct{}),
|
||||
}
|
||||
@@ -47,10 +51,6 @@ func newChatServer(t *testing.T) *chatServer {
|
||||
mux.HandleFunc("/auth/session", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"authenticated":true,"disabled":true}`)
|
||||
})
|
||||
mux.HandleFunc("/api/session", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"data":[{"id":"ses_1","title":"First session","time":{"created":1,"updated":2},
|
||||
"location":{"directory":"/home/me/project"},"model":{"id":"m","providerID":"p"}}],"cursor":{}}`)
|
||||
})
|
||||
mux.HandleFunc("/api/session/active", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"data":{}}`)
|
||||
})
|
||||
@@ -64,6 +64,9 @@ func newChatServer(t *testing.T) *chatServer {
|
||||
"content":[{"type":"text","text":"**Hello** from the agent"}]}
|
||||
],"cursor":{}}`)
|
||||
})
|
||||
mux.HandleFunc("/api/session/ses_new/message", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"data":[],"cursor":{}}`)
|
||||
})
|
||||
mux.HandleFunc("/api/session/ses_1/prompt", func(w http.ResponseWriter, r *http.Request) {
|
||||
var body map[string]any
|
||||
_ = json.NewDecoder(r.Body).Decode(&body)
|
||||
@@ -75,6 +78,41 @@ func newChatServer(t *testing.T) *chatServer {
|
||||
cs.events <- `{"id":"evt_3","created":101,"type":"session.text.delta","data":{"sessionID":"ses_1","assistantMessageID":"msg_stream","ordinal":0,"delta":"streamed"}}`
|
||||
fmt.Fprint(w, `{"data":{}}`)
|
||||
})
|
||||
mux.HandleFunc("/api/location", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"directory":"/home/me/project","project":{"id":"p1"}}`)
|
||||
})
|
||||
mux.HandleFunc("/api/model", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"data":[
|
||||
{"id":"gpt-4","providerID":"openai","name":"GPT-4"},
|
||||
{"id":"claude","providerID":"anthropic","name":"Claude"}]}`)
|
||||
})
|
||||
mux.HandleFunc("/api/agent", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"data":[{"id":"build","name":"Build"},{"id":"plan","name":"Plan"}]}`)
|
||||
})
|
||||
mux.HandleFunc("/api/session/ses_1/model", func(w http.ResponseWriter, r *http.Request) {
|
||||
var body map[string]any
|
||||
_ = json.NewDecoder(r.Body).Decode(&body)
|
||||
select {
|
||||
case cs.models <- body:
|
||||
default:
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
mux.HandleFunc("/api/session", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
fmt.Fprint(w, `{"data":[{"id":"ses_1","title":"First session","time":{"created":1,"updated":2},
|
||||
"location":{"directory":"/home/me/project"},"model":{"id":"m","providerID":"p"}}],"cursor":{}}`)
|
||||
return
|
||||
}
|
||||
var body map[string]any
|
||||
_ = json.NewDecoder(r.Body).Decode(&body)
|
||||
select {
|
||||
case cs.created <- body:
|
||||
default:
|
||||
}
|
||||
fmt.Fprint(w, `{"data":{"id":"ses_new","title":"New chat","time":{"created":3,"updated":3},
|
||||
"location":{"directory":"/home/me/project"}}}`)
|
||||
})
|
||||
mux.HandleFunc("/api/session/ses_1/permission/per_1/reply", func(w http.ResponseWriter, r *http.Request) {
|
||||
var body map[string]any
|
||||
_ = json.NewDecoder(r.Body).Decode(&body)
|
||||
@@ -174,3 +212,54 @@ func TestPermissionCardAndReply(t *testing.T) {
|
||||
t.Fatal("no permission reply reached the server")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSwitchModel(t *testing.T) {
|
||||
srv := newChatServer(t)
|
||||
a := uitest.Mount(t, func() ui.Node { return rootWithStore(&memStore{}) }, uitest.Platform(ui.PlatformAndroid))
|
||||
a.Type("http://192.168.1.5:3000", srv.URL)
|
||||
a.Tap("连接")
|
||||
a.WaitFor("First session")
|
||||
a.Tap("First session")
|
||||
a.WaitFor("Hello from the agent")
|
||||
|
||||
a.Tap("模型")
|
||||
a.WaitFor("GPT-4")
|
||||
a.Tap("GPT-4")
|
||||
|
||||
select {
|
||||
case body := <-srv.models:
|
||||
model, _ := body["model"].(map[string]any)
|
||||
if model["id"] != "gpt-4" || model["providerID"] != "openai" {
|
||||
t.Errorf("model switch = %v", body)
|
||||
}
|
||||
case <-time.After(3 * time.Second):
|
||||
t.Fatal("no model switch reached the server")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateSession(t *testing.T) {
|
||||
srv := newChatServer(t)
|
||||
a := uitest.Mount(t, func() ui.Node { return rootWithStore(&memStore{}) }, uitest.Platform(ui.PlatformAndroid))
|
||||
a.Type("http://192.168.1.5:3000", srv.URL)
|
||||
a.Tap("连接")
|
||||
a.WaitFor("First session")
|
||||
|
||||
a.Tap("新建")
|
||||
a.WaitFor("新建会话")
|
||||
a.Type("标题(可选,留空由服务端生成)", "Test chat")
|
||||
a.Tap("创建")
|
||||
a.WaitFor("New chat")
|
||||
|
||||
select {
|
||||
case body := <-srv.created:
|
||||
if body["title"] != "Test chat" {
|
||||
t.Errorf("created title = %v", body["title"])
|
||||
}
|
||||
loc, _ := body["location"].(map[string]any)
|
||||
if loc["directory"] != "/home/me/project" {
|
||||
t.Errorf("created location = %v", body["location"])
|
||||
}
|
||||
case <-time.After(3 * time.Second):
|
||||
t.Fatal("no create request reached the server")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user