Skip to content

Commit e8bcdd4

Browse files
committed
docs: add JSDoc comments to all REST API handlers in rest_handler.ts
1 parent d7135d8 commit e8bcdd4

1 file changed

Lines changed: 112 additions & 11 deletions

File tree

src/server/express/rest_handler.ts

Lines changed: 112 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,14 @@ export function restHandler(options: RestHandlerOptions): RequestHandler {
299299
router[method](`/:tenant${path}`, tenantMiddleware, asyncHandler(handler));
300300
};
301301

302-
// GET /extendedAgentCard
302+
/**
303+
* GET /extendedAgentCard
304+
*
305+
* Retrieves the authenticated extended agent card.
306+
*
307+
* @returns 200 OK with agent card
308+
* @returns 500 Internal Server Error on failure
309+
*/
303310
registerRoute('get', '/extendedAgentCard', async (req, res) => {
304311
const context = await buildContext(req);
305312
const result = await restTransportHandler.getAuthenticatedExtendedAgentCard(
@@ -309,7 +316,17 @@ export function restHandler(options: RestHandlerOptions): RequestHandler {
309316
sendResponse<AgentCard>(res, HTTP_STATUS.OK, context, result, AgentCard);
310317
});
311318

312-
// POST /message:send (colon escaped for Express).
319+
/**
320+
* POST /message:send
321+
*
322+
* Sends a message to the agent synchronously.
323+
* Returns either a Message (for immediate responses) or a Task (for async processing).
324+
* Note: Colon is escaped in route definition for Express compatibility.
325+
*
326+
* @param req.body - MessageSendParams (accepts both snake_case and camelCase)
327+
* @returns 201 Created with RestMessage or RestTask
328+
* @returns 400 Bad Request if message is invalid
329+
*/
313330
registerRoute('post', '/message\\:send', async (req, res) => {
314331
const context = await buildContext(req);
315332
const params = SendMessageRequest.fromJSON(req.body ?? {});
@@ -324,15 +341,36 @@ export function restHandler(options: RestHandlerOptions): RequestHandler {
324341
);
325342
});
326343

327-
// POST /message:stream (SSE).
344+
/**
345+
* POST /message:stream
346+
*
347+
* Sends a message to the agent with streaming response.
348+
* Returns a Server-Sent Events (SSE) stream of updates.
349+
* Note: Colon is escaped in route definition for Express compatibility.
350+
*
351+
* @param req.body - MessageSendParams (accepts both snake_case and camelCase)
352+
* @returns 200 OK with SSE stream of messages, tasks, and status updates
353+
* @returns 400 Bad Request if message is invalid
354+
* @returns 501 Not Implemented if streaming not supported
355+
*/
328356
registerRoute('post', '/message\\:stream', async (req, res) => {
329357
const context = await buildContext(req);
330358
const params = SendMessageRequest.fromJSON(req.body ?? {});
331359
const stream = await restTransportHandler.sendMessageStream(params, context);
332360
await sendStreamResponse(res, stream, context);
333361
});
334362

335-
// GET /tasks/:taskId
363+
/**
364+
* GET /tasks/:taskId
365+
*
366+
* Retrieves the current status and details of a task.
367+
*
368+
* @param req.params.taskId - Task identifier
369+
* @param req.query.historyLength - Optional number of history messages to include
370+
* @returns 200 OK with RestTask
371+
* @returns 400 Bad Request if historyLength is invalid
372+
* @returns 404 Not Found if task doesn't exist
373+
*/
336374
registerRoute('get', '/tasks/:taskId', async (req, res) => {
337375
const context = await buildContext(req);
338376
const result = await restTransportHandler.getTask(
@@ -344,7 +382,17 @@ export function restHandler(options: RestHandlerOptions): RequestHandler {
344382
sendResponse<Task>(res, HTTP_STATUS.OK, context, result, Task);
345383
});
346384

347-
// POST /tasks/:taskId:cancel
385+
/**
386+
* POST /tasks/:taskId:cancel
387+
*
388+
* Attempts to cancel an ongoing task.
389+
* The task may not be immediately canceled depending on its current state.
390+
*
391+
* @param req.params.taskId - Task identifier
392+
* @returns 200 OK with RestTask (task in its post-cancel state)
393+
* @returns 404 Not Found if task doesn't exist
394+
* @returns 400 Bad Request if task cannot be canceled
395+
*/
348396
registerRoute('post', '/tasks/:taskId\\:cancel', async (req, res) => {
349397
const context = await buildContext(req);
350398
const result = await restTransportHandler.cancelTask(
@@ -355,14 +403,31 @@ export function restHandler(options: RestHandlerOptions): RequestHandler {
355403
sendResponse<Task>(res, HTTP_STATUS.OK, context, result, Task);
356404
});
357405

358-
// GET /tasks
406+
/**
407+
* GET /tasks
408+
*
409+
* Retrieves a list of tasks with optional filtering and pagination capabilities.
410+
*
411+
* @returns 200 OK with ListTasksResponse
412+
* @returns 400 Bad Request if filter or pageSize is invalid
413+
*/
359414
registerRoute('get', '/tasks', async (req, res) => {
360415
const context = await buildContext(req);
361416
const result = await restTransportHandler.listTasks(req.query, context);
362417
sendResponse<ListTasksResponse>(res, HTTP_STATUS.OK, context, result, ListTasksResponse);
363418
});
364419

365-
// POST /tasks/:taskId:subscribe (SSE).
420+
/**
421+
* POST /tasks/:taskId:subscribe
422+
*
423+
* Resubscribes to an existing task's updates via Server-Sent Events (SSE).
424+
* Useful for reconnecting to long-running tasks or receiving missed updates.
425+
*
426+
* @param req.params.taskId - Task identifier
427+
* @returns 200 OK with SSE stream of task status and artifact updates
428+
* @returns 404 Not Found if task doesn't exist
429+
* @returns 501 Not Implemented if streaming not supported
430+
*/
366431
registerRoute('post', '/tasks/:taskId\\:subscribe', async (req, res) => {
367432
const context = await buildContext(req);
368433
const stream = await restTransportHandler.resubscribe(
@@ -373,7 +438,17 @@ export function restHandler(options: RestHandlerOptions): RequestHandler {
373438
await sendStreamResponse(res, stream, context);
374439
});
375440

376-
// POST /tasks/:taskId/pushNotificationConfigs
441+
/**
442+
* POST /tasks/:taskId/pushNotificationConfigs
443+
*
444+
* Creates a push notification configuration for a task.
445+
* The agent will send task updates to the configured webhook URL.
446+
*
447+
* @param req.params.taskId - Task identifier
448+
* @param req.body - Push notification configuration (snake_case format)
449+
* @returns 201 Created with TaskPushNotificationConfig
450+
* @returns 501 Not Implemented if push notifications not supported
451+
*/
377452
registerRoute('post', '/tasks/:taskId/pushNotificationConfigs', async (req, res) => {
378453
const context = await buildContext(req);
379454
const params = TaskPushNotificationConfig.fromJSON(req.body ?? {});
@@ -387,7 +462,15 @@ export function restHandler(options: RestHandlerOptions): RequestHandler {
387462
);
388463
});
389464

390-
// GET /tasks/:taskId/pushNotificationConfigs
465+
/**
466+
* GET /tasks/:taskId/pushNotificationConfigs
467+
*
468+
* Lists all push notification configurations for a task.
469+
*
470+
* @param req.params.taskId - Task identifier
471+
* @returns 200 OK with array of TaskPushNotificationConfig
472+
* @returns 404 Not Found if task doesn't exist
473+
*/
391474
registerRoute('get', '/tasks/:taskId/pushNotificationConfigs', async (req, res) => {
392475
const context = await buildContext(req);
393476
const result = await restTransportHandler.listTaskPushNotificationConfigs(
@@ -404,7 +487,16 @@ export function restHandler(options: RestHandlerOptions): RequestHandler {
404487
);
405488
});
406489

407-
// GET /tasks/:taskId/pushNotificationConfigs/:configId
490+
/**
491+
* GET /tasks/:taskId/pushNotificationConfigs/:configId
492+
*
493+
* Retrieves a specific push notification configuration.
494+
*
495+
* @param req.params.taskId - Task identifier
496+
* @param req.params.configId - Push notification configuration identifier
497+
* @returns 200 OK with TaskPushNotificationConfig
498+
* @returns 404 Not Found if task or config doesn't exist
499+
*/
408500
registerRoute('get', '/tasks/:taskId/pushNotificationConfigs/:configId', async (req, res) => {
409501
const context = await buildContext(req);
410502
const result = await restTransportHandler.getTaskPushNotificationConfig(
@@ -422,7 +514,16 @@ export function restHandler(options: RestHandlerOptions): RequestHandler {
422514
);
423515
});
424516

425-
// DELETE /tasks/:taskId/pushNotificationConfigs/:configId
517+
/**
518+
* DELETE /tasks/:taskId/pushNotificationConfigs/:configId
519+
*
520+
* Deletes a push notification configuration.
521+
*
522+
* @param req.params.taskId - Task identifier
523+
* @param req.params.configId - Push notification configuration identifier
524+
* @returns 204 No Content on success
525+
* @returns 404 Not Found if task or config doesn't exist
526+
*/
426527
registerRoute('delete', '/tasks/:taskId/pushNotificationConfigs/:configId', async (req, res) => {
427528
const context = await buildContext(req);
428529
await restTransportHandler.deleteTaskPushNotificationConfig(

0 commit comments

Comments
 (0)