Sync thread names from Codex

This commit is contained in:
Codex
2026-05-21 09:47:05 +00:00
parent 660458af32
commit 1d433038ab
5 changed files with 162 additions and 21 deletions

View File

@@ -203,6 +203,22 @@ func (c *Client) ResumeThread(ctx context.Context, threadID string) (Thread, err
return result.Thread, nil
}
func (c *Client) ReadThread(ctx context.Context, threadID string) (Thread, error) {
if err := c.EnsureConnected(ctx); err != nil {
return Thread{}, err
}
var result struct {
Thread Thread `json:"thread"`
}
if err := c.call(ctx, "thread/read", map[string]any{
"threadId": threadID,
"includeTurns": false,
}, &result); err != nil {
return Thread{}, err
}
return result.Thread, nil
}
func (c *Client) ForkThread(ctx context.Context, threadID string) (Thread, error) {
if err := c.EnsureConnected(ctx); err != nil {
return Thread{}, err

View File

@@ -86,6 +86,31 @@ func TestClientWebSocketUnixJSONRPC(t *testing.T) {
return
}
var readThread map[string]any
if err := conn.ReadJSON(&readThread); err != nil {
serverDone <- err
return
}
if readThread["method"] != "thread/read" {
serverDone <- unexpectedMessage("thread/read", readThread["method"])
return
}
readParams := readThread["params"].(map[string]any)
if readParams["threadId"] != "thr_1" || readParams["includeTurns"] != false {
payload, _ := json.Marshal(readParams)
serverDone <- unexpectedMessage("thread/read params", string(payload))
return
}
if err := conn.WriteJSON(map[string]any{
"id": readThread["id"],
"result": map[string]any{
"thread": map[string]any{"id": "thr_1", "name": "Read title", "preview": "test"},
},
}); err != nil {
serverDone <- err
return
}
var setName map[string]any
if err := conn.ReadJSON(&setName); err != nil {
serverDone <- err
@@ -145,6 +170,13 @@ func TestClientWebSocketUnixJSONRPC(t *testing.T) {
if thread.ID != "thr_1" {
t.Fatalf("unexpected thread: %+v", thread)
}
readThread, err := client.ReadThread(ctx, "thr_1")
if err != nil {
t.Fatal(err)
}
if readThread.ID != "thr_1" || readThread.Name != "Read title" {
t.Fatalf("unexpected read thread: %+v", readThread)
}
if err := client.SetThreadName(ctx, "thr_1", "Short title"); err != nil {
t.Fatal(err)
}