()
| 337 | } |
| 338 | |
| 339 | func (s *Server) registerMessages() { |
| 340 | huma.Register(s.API, huma.Operation{ |
| 341 | OperationID: "listMessages", |
| 342 | Method: http.MethodGet, |
| 343 | Path: "/v1/agents/{email}/messages", |
| 344 | Summary: "List messages", |
| 345 | Description: "List an agent's messages (inbound + outbound) with filters and cursor pagination. Held outbound drafts appear as status=pending_review.", |
| 346 | Tags: []string{"messages"}, |
| 347 | Security: []map[string][]string{{"bearer": {}}}, |
| 348 | }, s.handleListMessages) |
| 349 | |
| 350 | huma.Register(s.API, huma.Operation{ |
| 351 | OperationID: "getMessage", |
| 352 | Method: http.MethodGet, |
| 353 | Path: "/v1/agents/{email}/messages/{id}", |
| 354 | Summary: "Get a message", |
| 355 | Description: "Fetch a single message (inbound or outbound) by id, scoped to an agent the caller owns. Includes the raw message and inbound auth headers.", |
| 356 | Tags: []string{"messages"}, |
| 357 | Security: []map[string][]string{{"bearer": {}}}, |
| 358 | }, func(ctx context.Context, in *MessageIDParam) (*messageOutput, error) { |
| 359 | ag, err := s.resolveOwnedAgent(ctx, in.Address) |
| 360 | if err != nil { |
| 361 | return nil, err |
| 362 | } |
| 363 | if s.deps.GetMessage == nil { |
| 364 | return nil, NewError(http.StatusInternalServerError, "internal_error", "message lookup unavailable") |
| 365 | } |
| 366 | msg, err := s.deps.GetMessage(ctx, in.MessageID, ag.ID) |
| 367 | if err != nil || msg == nil { |
| 368 | return nil, NewError(http.StatusNotFound, "not_found", "message not found") |
| 369 | } |
| 370 | return &messageOutput{Body: messageViewFromIdentity(msg)}, nil |
| 371 | }) |
| 372 | |
| 373 | huma.Register(s.API, huma.Operation{ |
| 374 | OperationID: "updateMessage", |
| 375 | Method: http.MethodPatch, |
| 376 | Path: "/v1/agents/{email}/messages/{id}", |
| 377 | Summary: "Update a message (labels)", |
| 378 | Description: "Apply a labels delta (`add_labels` / `remove_labels`) to a message the caller owns; returns the post-update label set. Each list is capped at 50 entries; labels are lowercase `[a-z0-9:_-]+` up to 64 chars; the `e2a:` prefix is reserved for system labels. A message carries at most 100 labels. An empty delta is a read of the current labels.", |
| 379 | Tags: []string{"messages"}, |
| 380 | Security: []map[string][]string{{"bearer": {}}}, |
| 381 | }, s.handleUpdateMessage) |
| 382 | } |
| 383 | |
| 384 | // UpdateMessageRequest is the labels-delta body for PATCH …/messages/{id}. |
| 385 | // A label in both add and remove is removed (remove wins, per the store). |
no test coverage detected