handleListProcesses lists all tracked processes.
(rw http.ResponseWriter, r *http.Request)
| 119 | |
| 120 | // handleListProcesses lists all tracked processes. |
| 121 | func (api *API) handleListProcesses(rw http.ResponseWriter, r *http.Request) { |
| 122 | ctx := r.Context() |
| 123 | |
| 124 | var chatID string |
| 125 | if chatContext, ok := agentchat.FromContext(ctx); ok { |
| 126 | chatID = chatContext.ID.String() |
| 127 | } |
| 128 | |
| 129 | infos := api.manager.list(chatID) |
| 130 | |
| 131 | // Sort by running state (running first), then by started_at |
| 132 | // descending so the most recent processes appear first. |
| 133 | sort.Slice(infos, func(i, j int) bool { |
| 134 | if infos[i].Running != infos[j].Running { |
| 135 | return infos[i].Running |
| 136 | } |
| 137 | return infos[i].StartedAt > infos[j].StartedAt |
| 138 | }) |
| 139 | |
| 140 | // Cap the response to avoid bloating LLM context. |
| 141 | const maxListProcesses = 10 |
| 142 | if len(infos) > maxListProcesses { |
| 143 | infos = infos[:maxListProcesses] |
| 144 | } |
| 145 | |
| 146 | httpapi.Write(ctx, rw, http.StatusOK, workspacesdk.ListProcessesResponse{ |
| 147 | Processes: infos, |
| 148 | }) |
| 149 | } |
| 150 | |
| 151 | // handleProcessOutput returns the output of a process. |
| 152 | func (api *API) handleProcessOutput(rw http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected