feat: express-batch dispatch — manual trigger for the AI agent

Adds the backend half of the ExpressDispatchAgent flow. Express orders can now
be created batch by batch (bulk create only accumulates them, unassigned), then
an operator hits one endpoint to hand the whole pending set to the agent for
tenant-scoped assignment + road sequencing. The normal B2C flow is untouched.

- POST /admin/expressbooking/dispatch: manual trigger. Console-auth, tenant-
  scoped; gathers the tenant's pending unassigned express orders (or a chosen
  subset) and publishes express.dispatch_requested.
- internal API for the agent: GET /internal/express/riders (tenant's available
  riders), GET /internal/express/bookings, POST /internal/express/assign (writes
  the agent's decided assignments with their sequence; re-checks the already-
  assigned guard so the agent can't double-assign).
- booking_assignment_service.go: extracted a behavior-preserving assignMilerTx
  core; AssignMilerToBooking is unchanged in behavior. assignExpressStops writes
  a batch, one FCM per rider instead of one per stop.
- EXPRESS JetStream stream / express.dispatch_requested subject.
- Gated behind EXPRESS_AGENT_ENABLED (default off): deploying this changes
  nothing until the agent is confirmed running and the flag is flipped.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Suriyakumarvijayanayagam
2026-08-17 19:33:48 +05:30
parent cfdc99ec9a
commit f09efcaf59
6 changed files with 526 additions and 20 deletions

View File

@@ -270,6 +270,10 @@ func RegisterRoutes(app *fiber.App, cfg *config.Config) {
adminAuth.Get("/bookings", controllers.GetAdminBookings)
adminAuth.Post("/expressbooking", middlewares.CityGateMiddleware, controllers.CreateExpressBooking)
adminAuth.Post("/expressbooking/bulk", middlewares.CityGateMiddleware, controllers.AdminBulkCreateBookings)
// Manual trigger: hand all pending express orders for the tenant to the
// ExpressDispatchAgent (assign + road-sequence). Operator-controlled, after
// orders have accumulated batch by batch.
adminAuth.Post("/expressbooking/dispatch", controllers.DispatchExpressBatch)
adminAuth.Get("/bookings/:id", controllers.GetAdminBookingDetails)
adminAuth.Get("/bookings/:id/track", controllers.GetAdminBookingTrack)
adminAuth.Post("/bookings/:id/assign-miler", controllers.AdminAssignMiler)
@@ -418,6 +422,12 @@ func RegisterRoutes(app *fiber.App, cfg *config.Config) {
internal.Get("/agent-decisions/similar", controllers.FindSimilarDecisions)
internal.Patch("/agent-decisions/:id/outcome", controllers.UpdateDecisionOutcome)
// Express-batch dispatch: the ExpressDispatchAgent reads a tenant's riders
// and the batch's bookings, then writes back the assignments it decided.
internal.Get("/express/riders", controllers.GetExpressRiders)
internal.Get("/express/bookings", controllers.GetExpressBookings)
internal.Post("/express/assign", controllers.AssignExpressBatch)
// --------------------
// WEBSOCKET — live miler tracking (no auth, public tracking link)
// --------------------