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:
@@ -501,6 +501,44 @@ func TestDecodeChatMessagesSkipsUnknownPartsAndRoles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeChatMessagesMapsTopLevelUserFiles(t *testing.T) {
|
||||
raw := `{"data":[{"id":"msg_user","time":{"created":1},"type":"user","text":"see attached","files":[
|
||||
{"data":"aGVsbG8=","mime":"text/plain","source":{"type":"uri","uri":"file:///tmp/note.txt"},"name":"note.txt"}
|
||||
]}]}`
|
||||
messages, err := decodeChatMessages("ses_1", []byte(raw))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(messages) != 1 || len(messages[0].Parts) != 2 {
|
||||
t.Fatalf("messages = %+v", messages)
|
||||
}
|
||||
file := messages[0].Parts[1]
|
||||
if file.Type != protocol.ChatPartFile || file.Name != "note.txt" || file.URI != "file:///tmp/note.txt" || file.Mime != "text/plain" {
|
||||
t.Fatalf("file part = %+v", file)
|
||||
}
|
||||
if strings.Contains(file.URI, "aGVsbG8=") {
|
||||
t.Fatal("history exposed inline file data")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeChatMessagesMapsUserFileParts(t *testing.T) {
|
||||
raw := `{"data":[{"id":"msg_user","time":{"created":1},"type":"user","parts":[
|
||||
{"type":"text","text":"see attached"},
|
||||
{"type":"file","uri":"file:///tmp/note.txt","name":"note.txt","mime":"text/plain"}
|
||||
]}]}`
|
||||
messages, err := decodeChatMessages("ses_1", []byte(raw))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(messages) != 1 || len(messages[0].Parts) != 2 {
|
||||
t.Fatalf("messages = %+v", messages)
|
||||
}
|
||||
file := messages[0].Parts[1]
|
||||
if file.Type != protocol.ChatPartFile || file.Name != "note.txt" || file.URI != "file:///tmp/note.txt" || file.Mime != "text/plain" {
|
||||
t.Fatalf("file part = %+v", file)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatMessagesPagesLargeToolHistoryWithoutGlobalResponseLimit(t *testing.T) {
|
||||
large := strings.Repeat("x", MaxResponse+1)
|
||||
var paths []string
|
||||
|
||||
Reference in New Issue
Block a user