feat: context usage ring and tool image previews
- the composer shows a context ring and percentage from the last token-bearing assistant message, toned at 75% and 90%; tapping opens a sheet with the model, used tokens, limits, output reserve and turn cost - images a tool call names (read attachments as data URLs, input paths, and image paths in output text) get a link under the tool row; tapping previews it from the data URL or /api/fs/raw, allowing paths outside the workspace - directory-scoped requests now send x-opencode-directory-encoding: uri, which scoped routes such as /api/fs/raw need to decode the header - ocprobe gains a raw file command for checking previews Bump version to 0.2.2 (build 16).
This commit is contained in:
1 parent
dc3730eba7
commit
2fb4a8ea79
16 files changed
+884
-26
No files matched your search
@@ -65,11 +65,16 @@ func newChatServer(t *testing.T) *chatServer {
|
||||
fmt.Fprint(w, `{"data":[
|
||||
{"id":"msg_1","type":"user","text":"What is this?","time":{"created":10}},
|
||||
{"id":"msg_2","type":"assistant","agent":"build","model":{"id":"gpt-4","providerID":"openai"},
|
||||
"time":{"created":11,"completed":12000},
|
||||
"time":{"created":11,"completed":12000},"cost":0.02,
|
||||
"tokens":{"input":100500,"output":0,"reasoning":0,"cache":{"read":0,"write":0}},
|
||||
"content":[{"type":"text","text":"**Hello** from the agent"},
|
||||
{"type":"tool","id":"call_1","name":"shell","state":{"status":"completed",
|
||||
"input":{"command":"echo hi"},"content":[],
|
||||
"metadata":{"openchamberContentShell":{}}}}]}
|
||||
"metadata":{"openchamberContentShell":{}}}},
|
||||
{"type":"tool","id":"call_2","name":"read","state":{"status":"completed",
|
||||
"input":{"filePath":"/home/me/project/shot.png"},"content":[],
|
||||
"attachments":[{"type":"file","mime":"image/png","filename":"shot.png",
|
||||
"url":"data:image/png;base64,iVBORw0KGgo="}]}}]}
|
||||
],"cursor":{}}`)
|
||||
})
|
||||
mux.HandleFunc("/api/session/ses_new/message", func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -91,8 +96,8 @@ func newChatServer(t *testing.T) *chatServer {
|
||||
})
|
||||
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"}]}`)
|
||||
{"id":"gpt-4","providerID":"openai","name":"GPT-4","limit":{"context":200000,"output":64000}},
|
||||
{"id":"claude","providerID":"anthropic","name":"Claude","limit":{"context":200000,"output":32000}}]}`)
|
||||
})
|
||||
mux.HandleFunc("/api/agent", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"data":[
|
||||
@@ -127,10 +132,15 @@ func newChatServer(t *testing.T) *chatServer {
|
||||
})
|
||||
mux.HandleFunc("/api/session/ses_1/message/msg_2", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"id":"msg_2","type":"assistant","agent":"build","model":{"id":"gpt-4","providerID":"openai"},
|
||||
"time":{"created":11,"completed":12000},
|
||||
"time":{"created":11,"completed":12000},"cost":0.02,
|
||||
"tokens":{"input":100500,"output":0,"reasoning":0,"cache":{"read":0,"write":0}},
|
||||
"content":[{"type":"text","text":"**Hello** from the agent"},
|
||||
{"type":"tool","id":"call_1","name":"shell","state":{"status":"completed",
|
||||
"input":{"command":"echo hi"},"content":[{"type":"text","text":"tool output here"}]}}]}`)
|
||||
"input":{"command":"echo hi"},"content":[{"type":"text","text":"tool output here"}]}},
|
||||
{"type":"tool","id":"call_2","name":"read","state":{"status":"completed",
|
||||
"input":{"filePath":"/home/me/project/shot.png"},"content":[],
|
||||
"attachments":[{"type":"file","mime":"image/png","filename":"shot.png",
|
||||
"url":"data:image/png;base64,iVBORw0KGgo="}]}}]}`)
|
||||
})
|
||||
mux.HandleFunc("/api/session/ses_1/revert/stage", func(w http.ResponseWriter, r *http.Request) {
|
||||
var body map[string]any
|
||||
@@ -416,3 +426,32 @@ func TestRevertFromUserMessage(t *testing.T) {
|
||||
t.Errorf("commit not sent: %v", commit)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextUsageRingAndSheet(t *testing.T) {
|
||||
srv := newChatServer(t)
|
||||
a := uitest.Mount(t, func() ui.Node { return rootWithStore(&memStore{}) }, uitest.Platform(ui.PlatformAndroid))
|
||||
connectViaForm(t, a, srv.URL)
|
||||
a.WaitFor("First session")
|
||||
a.Tap("First session")
|
||||
a.WaitFor("Hello from the agent")
|
||||
|
||||
// 100500 tokens over 200000 - min(64000, 32000).
|
||||
a.WaitFor("59.8%")
|
||||
a.Tap("上下文占用")
|
||||
a.WaitFor("上下文上限")
|
||||
a.WaitFor("200.0K")
|
||||
a.WaitFor("64.0K")
|
||||
}
|
||||
|
||||
func TestToolImagePreviewSheet(t *testing.T) {
|
||||
srv := newChatServer(t)
|
||||
a := uitest.Mount(t, func() ui.Node { return rootWithStore(&memStore{}) }, uitest.Platform(ui.PlatformAndroid))
|
||||
connectViaForm(t, a, srv.URL)
|
||||
a.WaitFor("First session")
|
||||
a.Tap("First session")
|
||||
a.WaitFor("Hello from the agent")
|
||||
|
||||
a.WaitFor("预览 shot.png")
|
||||
a.Tap("预览 shot.png")
|
||||
a.WaitFor("图片预览")
|
||||
}
|
||||
Reference in new issue
Block a user