fix chat streaming and prompt writes
- Return chat file as text/plain to preserve line ordering - Fix handleWrite: single-key JSON writes raw value, not key=value - Fixes broken chat display and 'prompt=' corruption in chat log
This commit is contained in:
parent
ec092055fe
commit
830849e193
19
main.go
19
main.go
|
|
@ -218,6 +218,11 @@ func handleRead(w http.ResponseWriter, fsys *client.Fsys, p string) {
|
|||
writeJSON(w, http.StatusOK, parseIdx(content))
|
||||
return
|
||||
}
|
||||
if path.Base(p) == "chat" {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
w.Write(content)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, parseContent(content, path.Base(p)))
|
||||
}
|
||||
|
||||
|
|
@ -318,12 +323,24 @@ func handleWrite(w http.ResponseWriter, r *http.Request, fsys *client.Fsys, p st
|
|||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
// If the body has a single key matching the file name, write just the value.
|
||||
// Otherwise serialize as key=value lines (e.g. for "new").
|
||||
var payload []byte
|
||||
base := path.Base(p)
|
||||
if len(m) == 1 {
|
||||
if v, ok := m[base]; ok {
|
||||
payload = []byte(fmt.Sprintf("%v", v))
|
||||
}
|
||||
}
|
||||
if payload == nil {
|
||||
payload = serializeKV(m)
|
||||
}
|
||||
fid, err := fsys.Open(p, plan9.OWRITE)
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusNotFound, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
n, err := fid.Write(serializeKV(m))
|
||||
n, err := fid.Write(payload)
|
||||
fid.Close()
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
|
|
|
|||
Loading…
Reference in New Issue