1
1
import { IAgentRuntime , UUID } from "@ai16z/eliza" ;
2
+ import { NearbyStores , Order } from "dominos" ;
2
3
import {
3
- NearbyStores ,
4
- Order ,
5
4
Customer ,
6
5
ErrorType ,
7
6
OrderError ,
@@ -15,7 +14,7 @@ import {
15
14
PizzaSize ,
16
15
PizzaTopping ,
17
16
ToppingPortion ,
18
- } from "dominos " ;
17
+ } from "./types " ;
19
18
20
19
export class PizzaOrderManager implements OrderManager {
21
20
storeId : string ;
@@ -231,6 +230,7 @@ export class PizzaOrderManager implements OrderManager {
231
230
232
231
// Get next required action based on order state
233
232
getNextRequiredAction ( order : Order , customer : Customer ) : string {
233
+ console . log ( "getNextRequiredAction: " , order , customer ) ;
234
234
if ( ! order . items || order . items . length === 0 ) {
235
235
return "Collect initial pizza order details - show size, crust, and topping options to customer" ;
236
236
}
@@ -270,6 +270,7 @@ export class PizzaOrderManager implements OrderManager {
270
270
}
271
271
272
272
getNextRequiredActionDialogue ( order : Order , customer : Customer ) : string {
273
+ console . log ( "getNextRequiredActionDialogue: " , order , customer ) ;
273
274
if ( ! order . items || order . items . length === 0 ) {
274
275
return "Let me help you build your perfect pizza! What size would you like? We have Small, Medium, Large and Extra Large. Then I can help you choose your crust type and toppings." ;
275
276
}
@@ -352,7 +353,7 @@ export class PizzaOrderManager implements OrderManager {
352
353
353
354
// Format currency
354
355
private formatCurrency ( amount : number ) : string {
355
- return `$${ amount . toFixed ( 2 ) } ` ;
356
+ return `$${ amount ? .toFixed ( 2 ) || "?" } ` ;
356
357
}
357
358
358
359
// Format topping for display with category
@@ -375,10 +376,11 @@ export class PizzaOrderManager implements OrderManager {
375
376
376
377
// Generate detailed order summary
377
378
getOrderSummary ( order : Order , customer : Customer ) : string {
379
+ console . log ( "getOrderSummary: " , order , customer ) ;
378
380
let summary = "===== CURRENT ORDER =====\n\n" ;
379
381
380
382
// Add items
381
- order . items . forEach ( ( item , index ) => {
383
+ order . items ? .forEach ( ( item , index ) => {
382
384
summary += `PIZZA ${ index + 1 } \n` ;
383
385
summary += `==================\n` ;
384
386
summary += `Size: ${ item . size } (${ this . formatCurrency ( this . menuConfig . basePrices [ item . size ] ) } )\n` ;
@@ -393,7 +395,7 @@ export class PizzaOrderManager implements OrderManager {
393
395
394
396
if ( item . toppings && item . toppings . length > 0 ) {
395
397
summary += "\nTOPPINGS:\n" ;
396
- item . toppings . forEach ( ( topping ) => {
398
+ item . toppings ? .forEach ( ( topping ) => {
397
399
const toppingInfo = this . getToppingInfo ( topping . code ) ;
398
400
summary += `• ${ this . formatTopping ( topping ) } ` ;
399
401
summary += `(+${ this . formatCurrency (
@@ -427,7 +429,7 @@ export class PizzaOrderManager implements OrderManager {
427
429
if ( customer . phone ) summary += `Phone: ${ customer . phone } \n` ;
428
430
if ( customer . address ) {
429
431
summary += "Delivery Address:\n" ;
430
- summary += `${ customer . address } \n` ;
432
+ summary += `${ ( customer ? .address && JSON . stringify ( customer . address ) ) || "Not provided" } \n` ;
431
433
}
432
434
if ( customer . email ) summary += `Email: ${ customer . email } \n` ;
433
435
summary += "==================\n\n" ;
@@ -626,6 +628,7 @@ export class PizzaOrderManager implements OrderManager {
626
628
627
629
// Calculate order progress
628
630
calculateOrderProgress ( order : Order , customer : Customer ) : OrderProgress {
631
+ console . log ( "calculateOrderProgress: " , order , customer ) ;
629
632
return {
630
633
hasCustomerInfo : ! this . validateCustomerInfo ( customer ) ,
631
634
hasPaymentMethod : order . paymentMethod !== undefined ,
@@ -642,46 +645,54 @@ export class PizzaOrderManager implements OrderManager {
642
645
customer : Customer
643
646
) : Promise < Order | OrderError > {
644
647
// Validate pizza configuration
645
- for ( const item of order . items ) {
646
- // Validate size
647
- if ( ! Object . values ( PizzaSize ) . includes ( item . size ) ) {
648
- return {
649
- type : ErrorType . VALIDATION_FAILED ,
650
- message : `Invalid pizza size: ${ item . size } ` ,
651
- code : "INVALID_SIZE" ,
652
- } ;
653
- }
648
+ if ( order && order . items ) {
649
+ for ( const item of order . items ) {
650
+ // Validate size
651
+ if ( ! Object . values ( PizzaSize ) . includes ( item . size ) ) {
652
+ return {
653
+ type : ErrorType . VALIDATION_FAILED ,
654
+ message : `Invalid pizza size: ${ item . size } ` ,
655
+ code : "INVALID_SIZE" ,
656
+ } ;
657
+ }
654
658
655
- // Validate crust
656
- if ( ! Object . values ( PizzaCrust ) . includes ( item . crust ) ) {
657
- return {
658
- type : ErrorType . VALIDATION_FAILED ,
659
- message : `Invalid crust type: ${ item . crust } ` ,
660
- code : "INVALID_CRUST" ,
661
- } ;
662
- }
659
+ // Validate crust
660
+ if ( ! Object . values ( PizzaCrust ) . includes ( item . crust ) ) {
661
+ return {
662
+ type : ErrorType . VALIDATION_FAILED ,
663
+ message : `Invalid crust type: ${ item . crust } ` ,
664
+ code : "INVALID_CRUST" ,
665
+ } ;
666
+ }
663
667
664
- // Validate toppings
665
- if ( item . toppings ) {
666
- const toppingError = this . validateToppings ( item . toppings ) ;
667
- if ( toppingError ) return toppingError ;
668
- }
668
+ // Validate toppings
669
+ if ( item . toppings ) {
670
+ const toppingError = this . validateToppings ( item . toppings ) ;
671
+ if ( toppingError ) return toppingError ;
672
+ }
669
673
670
- // Validate quantity
671
- if ( item . quantity < 1 || item . quantity > 10 ) {
672
- return {
673
- type : ErrorType . VALIDATION_FAILED ,
674
- message : "Quantity must be between 1 and 10" ,
675
- code : "INVALID_QUANTITY" ,
676
- } ;
674
+ // Validate quantity
675
+ if ( item . quantity < 1 || item . quantity > 10 ) {
676
+ return {
677
+ type : ErrorType . VALIDATION_FAILED ,
678
+ message : "Quantity must be between 1 and 10" ,
679
+ code : "INVALID_QUANTITY" ,
680
+ } ;
681
+ }
677
682
}
683
+ } else {
684
+ console . warn ( "No order items found" ) ;
678
685
}
679
686
680
687
// Calculate total price
681
- order . total = order . items . reduce (
682
- ( total , item ) => total + this . calculatePizzaPrice ( item ) ,
683
- 0
684
- ) ;
688
+ if ( order . items ) {
689
+ order . total = order . items ?. reduce (
690
+ ( total , item ) => total + this . calculatePizzaPrice ( item ) ,
691
+ 0
692
+ ) ;
693
+ } else {
694
+ console . warn ( "No order items found" ) ;
695
+ }
685
696
686
697
// Validate customer information
687
698
const customerError = this . validateCustomerInfo ( customer ) ;
0 commit comments