Skip to content

Commit 520ecdb

Browse files
committed
refactor: rename PostTasksActionRoute to TaskActionRoute
1 parent 7964db4 commit 520ecdb

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

a2acompat/a2av0/rest_server.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func NewRESTHandler(handler a2asrv.RequestHandler, opts ...a2asrv.TransportOptio
5656
mux.HandleFunc("POST "+paths.SendMessage(), h.handleSendMessage)
5757
mux.HandleFunc("POST "+paths.StreamMessage(), h.handleStreamMessage)
5858
mux.HandleFunc("GET "+paths.ListTasks(), h.handleListTasks)
59-
mux.HandleFunc("GET "+paths.PostTasksActionRoute(), h.handleGETTasks)
60-
mux.HandleFunc("POST "+paths.PostTasksActionRoute(), h.handlePOSTTasks)
59+
mux.HandleFunc("GET "+paths.TaskActionRoute(), h.handleGetOrSubscribeTask)
60+
mux.HandleFunc("POST "+paths.TaskActionRoute(), h.handleCancelOrSubscribeTask)
6161
mux.HandleFunc("POST "+paths.CreatePushConfig("{id}"), h.handleCreateTaskPushConfig)
6262
mux.HandleFunc("GET "+paths.ListPushConfigs("{id}"), h.handleListTaskPushConfigs)
6363
mux.HandleFunc("GET "+paths.GetPushConfig("{id}", "{configId}"), h.handleGetTaskPushConfig)
@@ -139,7 +139,7 @@ func (h *restCompatHandler) handleGetTask(taskID string, rw http.ResponseWriter,
139139
writeJSON(ctx, rw, data)
140140
}
141141

142-
func (h *restCompatHandler) handlePOSTTasks(rw http.ResponseWriter, req *http.Request) {
142+
func (h *restCompatHandler) handleCancelOrSubscribeTask(rw http.ResponseWriter, req *http.Request) {
143143
ctx := req.Context()
144144
idAndAction := req.PathValue("idAndAction")
145145
if idAndAction == "" {
@@ -151,22 +151,26 @@ func (h *restCompatHandler) handlePOSTTasks(rw http.ResponseWriter, req *http.Re
151151
return
152152
}
153153
if before, ok := strings.CutSuffix(idAndAction, ":subscribe"); ok {
154-
h.handleStreamingRequest(h.handler.SubscribeToTask(ctx, &a2a.SubscribeToTaskRequest{ID: a2a.TaskID(before)}), rw, req)
154+
h.handleSubscribeToTask(before, rw, req)
155155
return
156156
}
157157
writeRESTCompatError(ctx, rw, a2a.ErrInvalidRequest, a2a.TaskID(""))
158158
}
159159

160-
func (h *restCompatHandler) handleGETTasks(rw http.ResponseWriter, req *http.Request) {
161-
ctx := req.Context()
160+
func (h *restCompatHandler) handleGetOrSubscribeTask(rw http.ResponseWriter, req *http.Request) {
162161
idAndAction := req.PathValue("idAndAction")
163162
if before, ok := strings.CutSuffix(idAndAction, ":subscribe"); ok {
164-
h.handleStreamingRequest(h.handler.SubscribeToTask(ctx, &a2a.SubscribeToTaskRequest{ID: a2a.TaskID(before)}), rw, req)
163+
h.handleSubscribeToTask(before, rw, req)
165164
return
166165
}
167166
h.handleGetTask(idAndAction, rw, req)
168167
}
169168

169+
func (h *restCompatHandler) handleSubscribeToTask(taskID string, rw http.ResponseWriter, req *http.Request) {
170+
ctx := req.Context()
171+
h.handleStreamingRequest(h.handler.SubscribeToTask(ctx, &a2a.SubscribeToTaskRequest{ID: a2a.TaskID(taskID)}), rw, req)
172+
}
173+
170174
func (h *restCompatHandler) handleCancelTask(taskID string, rw http.ResponseWriter, req *http.Request) {
171175
ctx := req.Context()
172176
result, err := h.handler.CancelTask(ctx, &a2a.CancelTaskRequest{ID: a2a.TaskID(taskID)})

internal/rest/rest.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ func (p PathBuilder) DeletePushConfig(taskID, configID string) string {
9999
return p.prefix + "/tasks/" + taskID + "/pushNotificationConfigs/" + configID
100100
}
101101

102-
// PostTasksActionRoute returns the mux route pattern for handling any
103-
// POST /tasks/{id}:action verb (e.g. :cancel, :subscribe).
104-
func (p PathBuilder) PostTasksActionRoute() string {
102+
// TaskActionRoute returns the mux route pattern for handling any
103+
// /tasks/{id}:action verb (e.g. :cancel, :subscribe).
104+
func (p PathBuilder) TaskActionRoute() string {
105105
return p.prefix + "/tasks/{idAndAction}"
106106
}
107107

internal/rest/rest_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestPathBuilder(t *testing.T) {
5151
{"v1 ListPushConfigs", PathBuilder{}, PathBuilder{}.ListPushConfigs("t1"), "/tasks/t1/pushNotificationConfigs"},
5252
{"v1 DeletePushConfig", PathBuilder{}, PathBuilder{}.DeletePushConfig("t1", "c1"), "/tasks/t1/pushNotificationConfigs/c1"},
5353
{"v1 GetExtendedAgentCard", PathBuilder{}, PathBuilder{}.GetExtendedAgentCard(), "/extendedAgentCard"},
54-
{"v1 PostTasksActionRoute", PathBuilder{}, PathBuilder{}.PostTasksActionRoute(), "/tasks/{idAndAction}"},
54+
{"v1 TaskActionRoute", PathBuilder{}, PathBuilder{}.TaskActionRoute(), "/tasks/{idAndAction}"},
5555

5656
{"v03 ListTasks", NewPathBuilder("/v1"), NewPathBuilder("/v1").ListTasks(), "/v1/tasks"},
5757
{"v03 SendMessage", NewPathBuilder("/v1"), NewPathBuilder("/v1").SendMessage(), "/v1/message:send"},
@@ -64,7 +64,7 @@ func TestPathBuilder(t *testing.T) {
6464
{"v03 ListPushConfigs", NewPathBuilder("/v1"), NewPathBuilder("/v1").ListPushConfigs("t1"), "/v1/tasks/t1/pushNotificationConfigs"},
6565
{"v03 DeletePushConfig", NewPathBuilder("/v1"), NewPathBuilder("/v1").DeletePushConfig("t1", "c1"), "/v1/tasks/t1/pushNotificationConfigs/c1"},
6666
{"v03 GetExtendedAgentCard", NewPathBuilder("/v1"), NewPathBuilder("/v1").GetExtendedAgentCard(), "/v1/extendedAgentCard"},
67-
{"v03 PostTasksActionRoute", NewPathBuilder("/v1"), NewPathBuilder("/v1").PostTasksActionRoute(), "/v1/tasks/{idAndAction}"},
67+
{"v03 TaskActionRoute", NewPathBuilder("/v1"), NewPathBuilder("/v1").TaskActionRoute(), "/v1/tasks/{idAndAction}"},
6868
}
6969
for _, tc := range tests {
7070
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)