feat: add GET endpoint by primitive kind#2907
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new administrative endpoint to retrieve lists of resource names by category (sources, auth services, tools, etc.) and adds corresponding methods to the ResourceManager. Feedback suggests improving the getPrimitive handler by adding instrumentation for consistency, renaming variables for clarity, and enhancing error messages. Additionally, it is recommended to use slices.Sorted when collecting map keys in the ResourceManager to ensure deterministic API responses and prevent flaky tests.
6e28433 to
6b31505
Compare
| func (r *ResourceManager) GetSources() []string { | ||
| r.mu.RLock() | ||
| defer r.mu.RUnlock() | ||
| return slices.Sorted(maps.Keys(r.sources)) |
There was a problem hiding this comment.
this may return nil if sorting empty list. we should probably ensure we are returning an empty list in that case.
| r.Put("/{kind}/{name}", func(w http.ResponseWriter, r *http.Request) { createOrUpdatePrimitives(s, w, r) }) | ||
| r.Delete("/{kind}/{name}", func(w http.ResponseWriter, r *http.Request) { deletePrimitives(s, w, r) }) | ||
| r.Get("/{kind}/{name}", func(w http.ResponseWriter, r *http.Request) { getPrimitiveByName(s, w, r) }) | ||
| r.Route("/{kind}", func(r chi.Router) { |
There was a problem hiding this comment.
Any reason not to stack these like
1 r.Route("/{kind}", func(r chi.Router) {
2 r.Get("/", ...)
3 r.Get("/{name}", ...)
4 r.Put("/{name}", ...)
5 r.Delete("/{name}", ...)
6 })
| return slices.Sorted(maps.Keys(r.toolsets)) | ||
| } | ||
|
|
||
| func (r *ResourceManager) GetPrompts() []string { |
There was a problem hiding this comment.
Remind me why we do prompts and not promptset as well?
This will be the path to get a list of primitives that are configured within Toolbox.
For example, /admin/source will return a list of sources. The available api includes the following (non-case sensitive):
An invalid primitive name will result in a bad request error.