mcp in cart
Build and Publish / BuildAndDeployArm64 (push) Failing after 6s
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled

This commit is contained in:
2026-06-17 21:43:38 +02:00
parent ad410d217c
commit 74dc252279
9 changed files with 1054 additions and 13 deletions
+20 -12
View File
@@ -15,6 +15,7 @@ import (
"git.k6n.net/mats/go-cart-actor/pkg/actor"
"git.k6n.net/mats/go-cart-actor/pkg/cart"
"git.k6n.net/mats/go-cart-actor/pkg/promotions"
promotionmcp "git.k6n.net/mats/go-cart-actor/pkg/promotions/mcp"
"git.k6n.net/mats/go-cart-actor/pkg/proxy"
"git.k6n.net/mats/go-cart-actor/pkg/voucher"
"git.k6n.net/mats/go-redis-inventory/pkg/inventory"
@@ -111,16 +112,18 @@ func main() {
controlPlaneConfig := actor.DefaultServerConfig()
promotionData, err := promotions.LoadStateFile("data/promotions.json")
promotionStore, err := promotions.NewStore("data/promotions.json")
if err != nil {
log.Printf("Error loading promotions: %v\n", err)
log.Fatalf("Error loading promotions: %v\n", err)
}
log.Printf("loaded %d promotions", len(promotionData.State.Promotions))
log.Printf("loaded %d promotions", len(promotionStore.List()))
promotionService := promotions.NewPromotionService(nil)
promotionMCP := promotionmcp.New(promotionStore, promotionService)
//inventoryPubSub := actor.NewPubSub[inventory.InventoryChange]()
// promotionService := promotions.NewPromotionService(nil)
// rdb := redis.NewClient(&redis.Options{
// Addr: redisAddress,
// Password: redisPassword,
@@ -142,15 +145,13 @@ func main() {
_, span := tracer.Start(ctx, "Totals and promotions")
defer span.End()
g.UpdateTotals()
// Evaluate active promotions against the freshly-totalled cart and apply
// any matched actions (e.g. the Volymrabatt volume discount), which adjust
// TotalPrice/TotalDiscount on top of line items and vouchers.
promotionCtx := promotions.NewContextFromCart(g, promotions.WithNow(time.Now()))
_, actions := promotionService.EvaluateAll(promotionStore.Snapshot(), promotionCtx)
promotions.ApplyActions(g, actions)
g.Version++
// promotionCtx := promotions.NewContextFromCart(g, promotions.WithNow(time.Now()), promotions.WithCustomerSegment("vip"))
// _, actions := promotionService.EvaluateAll(promotionData.State.Promotions, promotionCtx)
// for _, action := range actions {
// log.Printf("apply: %+v", action)
// g.UpdateTotals()
// }
return nil
}),
)
@@ -267,6 +268,13 @@ func main() {
}
syncedServer.Serve(mux)
// Promotion MCP edge: list/get/upsert/status/delete promotions and preview
// discounts. Mutations persist to data/promotions.json and are picked up by
// the cart's totals processor on the next mutation (it reads a fresh snapshot).
mux.Handle("/mcp", promotionMCP.Handler())
mux.Handle("/mcp/", promotionMCP.Handler())
// only for local
mux.HandleFunc("GET /add/remote/{host}", func(w http.ResponseWriter, r *http.Request) {
pool.AddRemote(r.PathValue("host"))