fix(chat): recover web approvals and questions across clients and reconnects
This commit is contained in:
@@ -442,8 +442,9 @@ func (c *Chat) Reply(ctx context.Context, request protocol.ChatReplyRequest) err
|
||||
}
|
||||
|
||||
// Permissions lists the session's pending OpenCode approval requests, mirroring
|
||||
// GET /api/permission/request. The endpoint is global, so the decoded list is
|
||||
// filtered to sessionID; a malformed response is an error, never an empty
|
||||
// GET /api/session/{id}/permission. The location-wide endpoint can silently
|
||||
// miss chats in another directory. Results are still filtered to sessionID;
|
||||
// a malformed response is an error, never an empty
|
||||
// success. It reuses Connection.Call so the request keeps the shared bounds,
|
||||
// auth and translation, and reuses ValidSessionID for the same rejection the
|
||||
// other chat calls apply.
|
||||
@@ -451,7 +452,7 @@ func (c *Chat) Permissions(ctx context.Context, id string) ([]protocol.ChatPermi
|
||||
if !sessionID.MatchString(id) {
|
||||
return nil, fmt.Errorf("invalid OpenCode session id")
|
||||
}
|
||||
data, err := c.call(ctx, "get", "/api/permission/request", nil)
|
||||
data, err := c.call(ctx, "get", "/api/session/"+id+"/permission", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -874,6 +875,36 @@ type chatFormPayload struct {
|
||||
Fields []chatFormField `json:"fields"`
|
||||
}
|
||||
|
||||
// Forms recovers pending questions even when their creation event preceded the
|
||||
// browser connection or the Pipelines process. Session ownership is explicit.
|
||||
func (c *Chat) Forms(ctx context.Context, id string) ([]protocol.ChatForm, error) {
|
||||
if !ValidSessionID(id) {
|
||||
return nil, fmt.Errorf("invalid OpenCode session id")
|
||||
}
|
||||
data, err := c.call(ctx, "get", "/api/session/"+id+"/form", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
forms, ok := chatEnvelope[chatFormPayload](data)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid OpenCode form response")
|
||||
}
|
||||
result := make([]protocol.ChatForm, 0, len(forms))
|
||||
for _, form := range forms {
|
||||
if form.ID == "" || form.SessionID != id {
|
||||
continue
|
||||
}
|
||||
frame, valid, err := normalizeFormEvent("form.created", chatEvent{Form: &form}, id, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if valid {
|
||||
result = append(result, *frame.Form)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type chatFormField struct {
|
||||
Key string `json:"key"`
|
||||
Title string `json:"title"`
|
||||
|
||||
Reference in New Issue
Block a user