Skip to content

Commit 2df768d

Browse files
committed
order flow is kind of working but still bugs
1 parent 0d33b02 commit 2df768d

File tree

7 files changed

+226
-48
lines changed

7 files changed

+226
-48
lines changed

packages/plugin-dominos/src/PizzaOrderManager.ts

+51-40
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { IAgentRuntime, UUID } from "@ai16z/eliza";
2+
import { NearbyStores, Order } from "dominos";
23
import {
3-
NearbyStores,
4-
Order,
54
Customer,
65
ErrorType,
76
OrderError,
@@ -15,7 +14,7 @@ import {
1514
PizzaSize,
1615
PizzaTopping,
1716
ToppingPortion,
18-
} from "dominos";
17+
} from "./types";
1918

2019
export class PizzaOrderManager implements OrderManager {
2120
storeId: string;
@@ -231,6 +230,7 @@ export class PizzaOrderManager implements OrderManager {
231230

232231
// Get next required action based on order state
233232
getNextRequiredAction(order: Order, customer: Customer): string {
233+
console.log("getNextRequiredAction: ", order, customer);
234234
if (!order.items || order.items.length === 0) {
235235
return "Collect initial pizza order details - show size, crust, and topping options to customer";
236236
}
@@ -270,6 +270,7 @@ export class PizzaOrderManager implements OrderManager {
270270
}
271271

272272
getNextRequiredActionDialogue(order: Order, customer: Customer): string {
273+
console.log("getNextRequiredActionDialogue: ", order, customer);
273274
if (!order.items || order.items.length === 0) {
274275
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.";
275276
}
@@ -352,7 +353,7 @@ export class PizzaOrderManager implements OrderManager {
352353

353354
// Format currency
354355
private formatCurrency(amount: number): string {
355-
return `$${amount.toFixed(2)}`;
356+
return `$${amount?.toFixed(2) || "?"}`;
356357
}
357358

358359
// Format topping for display with category
@@ -375,10 +376,11 @@ export class PizzaOrderManager implements OrderManager {
375376

376377
// Generate detailed order summary
377378
getOrderSummary(order: Order, customer: Customer): string {
379+
console.log("getOrderSummary: ", order, customer);
378380
let summary = "===== CURRENT ORDER =====\n\n";
379381

380382
// Add items
381-
order.items.forEach((item, index) => {
383+
order.items?.forEach((item, index) => {
382384
summary += `PIZZA ${index + 1}\n`;
383385
summary += `==================\n`;
384386
summary += `Size: ${item.size} (${this.formatCurrency(this.menuConfig.basePrices[item.size])})\n`;
@@ -393,7 +395,7 @@ export class PizzaOrderManager implements OrderManager {
393395

394396
if (item.toppings && item.toppings.length > 0) {
395397
summary += "\nTOPPINGS:\n";
396-
item.toppings.forEach((topping) => {
398+
item.toppings?.forEach((topping) => {
397399
const toppingInfo = this.getToppingInfo(topping.code);
398400
summary += `• ${this.formatTopping(topping)} `;
399401
summary += `(+${this.formatCurrency(
@@ -427,7 +429,7 @@ export class PizzaOrderManager implements OrderManager {
427429
if (customer.phone) summary += `Phone: ${customer.phone}\n`;
428430
if (customer.address) {
429431
summary += "Delivery Address:\n";
430-
summary += `${customer.address}\n`;
432+
summary += `${(customer?.address && JSON.stringify(customer.address)) || "Not provided"}\n`;
431433
}
432434
if (customer.email) summary += `Email: ${customer.email}\n`;
433435
summary += "==================\n\n";
@@ -626,6 +628,7 @@ export class PizzaOrderManager implements OrderManager {
626628

627629
// Calculate order progress
628630
calculateOrderProgress(order: Order, customer: Customer): OrderProgress {
631+
console.log("calculateOrderProgress: ", order, customer);
629632
return {
630633
hasCustomerInfo: !this.validateCustomerInfo(customer),
631634
hasPaymentMethod: order.paymentMethod !== undefined,
@@ -642,46 +645,54 @@ export class PizzaOrderManager implements OrderManager {
642645
customer: Customer
643646
): Promise<Order | OrderError> {
644647
// 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+
}
654658

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+
}
663667

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+
}
669673

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+
}
677682
}
683+
} else {
684+
console.warn("No order items found");
678685
}
679686

680687
// 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+
}
685696

686697
// Validate customer information
687698
const customerError = this.validateCustomerInfo(customer);

packages/plugin-dominos/src/actions/startOrder.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {
99
ModelClass,
1010
State,
1111
} from "@ai16z/eliza";
12-
import { Customer, Item, Order, PizzaCrust, PizzaSize } from "dominos";
12+
import { Customer, Item, Order } from "dominos";
13+
import { PizzaCrust, PizzaSize } from "../types";
14+
1315
import { z } from "zod";
1416
import { PizzaOrderManager } from "../PizzaOrderManager";
1517

@@ -27,6 +29,8 @@ const handler: Handler = async (
2729
return "There is already an active order. Please complete or cancel the existing order before starting a new one.";
2830
}
2931

32+
console.log("Existing order: ", existingOrder);
33+
3034
// Extract order details from message using LLM
3135
const extractionTemplate = `
3236
Extract pizza order details from the following text. Include size, crust type, toppings, quantity, and any special instructions.
@@ -80,7 +84,7 @@ const handler: Handler = async (
8084
})) as z.infer<typeof PizzaOrderSchema>;
8185

8286
// Create new order
83-
const customer = new Customer();
87+
const customer = new Customer({});
8488
await orderManager.saveCustomer(userId, customer);
8589

8690
const order = new Order(customer);
@@ -107,7 +111,7 @@ const handler: Handler = async (
107111
return response;
108112
} catch (error) {
109113
// Fallback to basic order if extraction fails
110-
const customer = new Customer();
114+
const customer = new Customer({});
111115
await orderManager.saveCustomer(userId, customer);
112116

113117
const order = new Order(customer);

packages/plugin-dominos/src/actions/updateCustomer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const handler: Handler = async (
4040

4141
let customer = await orderManager.getCustomer(userId);
4242
if (!customer) {
43-
customer = new Customer();
43+
customer = new Customer({});
4444
}
4545

4646
// Extract customer details using LLM and schema

packages/plugin-dominos/src/actions/updateOrder.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {
99
ModelClass,
1010
State,
1111
} from "@ai16z/eliza";
12-
import { Item, PizzaCrust, PizzaSize, ToppingPortion } from "dominos";
12+
import { Item } from "dominos";
13+
import { PizzaCrust, PizzaSize, ToppingPortion } from "../types";
14+
1315
import { z } from "zod";
1416
import { PizzaOrderManager } from "../PizzaOrderManager";
1517

@@ -152,7 +154,7 @@ export const handler: Handler = async (
152154

153155
// Apply modifications
154156
for (const mod of orderUpdates.modifications) {
155-
const item = order.items[mod.itemIndex];
157+
const item = order.items && order.items[mod.itemIndex];
156158
if (!item) continue;
157159

158160
switch (mod.type) {

packages/plugin-dominos/src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { Plugin } from "@ai16z/eliza";
22
import { startOrder } from "./actions/startOrder.ts";
33
import { pizzaOrderProvider } from "./providers/pizzaOrder.ts";
4+
import { endOrder } from "./actions/endOrder.ts";
5+
import { updateCustomer } from "./actions/updateCustomer.ts";
6+
import { updateOrder } from "./actions/updateOrder.ts";
47

58
export * as actions from "./actions/index.ts";
69
export * as providers from "./providers/index.ts";
710

811
export const dominosPlugin: Plugin = {
912
name: "dominos",
1013
description: "Order a dominos pizza",
11-
actions: [startOrder],
14+
actions: [startOrder, endOrder, updateCustomer, updateOrder],
1215
providers: [pizzaOrderProvider],
1316
};

packages/plugin-dominos/src/providers/pizzaOrder.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IAgentRuntime, Memory, Provider } from "@ai16z/eliza";
2-
import { OrderStatus } from "dominos";
2+
import { OrderStatus } from "../types";
33
import { PizzaOrderManager } from "../PizzaOrderManager";
44

55
export const pizzaOrderProvider: Provider = {
@@ -37,6 +37,8 @@ export const pizzaOrderProvider: Provider = {
3737
context += "Order is being processed but needs confirmation.\n";
3838
}
3939

40+
console.log("Order context:\n", context);
41+
4042
return context;
4143
},
4244
};

0 commit comments

Comments
 (0)