chat: deliver attachments and cancel runs immediately
Carry browser files as base64 prompt attachments, write them to private temporary files and pass file:// references to OpenCode, and map the user turn's top-level files back into history. Replay a running step on subscribe, forward only a caller-supplied msg_ id, and persist cancel on the run and live step before interrupting the runner.
This commit is contained in:
@@ -83,6 +83,34 @@ func TestChatV2PromptWithMessageID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatV2PromptWithFiles(t *testing.T) {
|
||||
var body struct {
|
||||
Text string `json:"text"`
|
||||
Files []map[string]string `json:"files"`
|
||||
}
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"data":{"id":"msg_files","sessionID":"ses_1","type":"user"}}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
chat := NewChat(&Connection{Backend: "v2", URL: srv.URL})
|
||||
err := chat.PromptWithMessageIDFiles(context.Background(), "ses_1", "read this", "msg_files", []PromptFile{
|
||||
{URI: "file:///tmp/note.txt", Name: "note.txt"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if body.Text != "read this" || len(body.Files) != 1 {
|
||||
t.Fatalf("prompt body = %+v", body)
|
||||
}
|
||||
if body.Files[0]["uri"] != "file:///tmp/note.txt" || body.Files[0]["name"] != "note.txt" {
|
||||
t.Fatalf("file = %+v", body.Files[0])
|
||||
}
|
||||
}
|
||||
|
||||
// TestChatStreamRealV2Shapes replays the exact event frames the installed 2.0.20
|
||||
// service emitted on /api/event during a live turn (captured, not documented):
|
||||
// a step start, token text delta, usage and a step end whose data carries no
|
||||
|
||||
Reference in New Issue
Block a user