From fc2458c4c1194f163b8cae06f5490674d6ac37ad Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Wed, 14 Jan 2026 12:23:03 -0300 Subject: [PATCH] Rewrite store-server.gbai: use WITH notation, use products table fields --- .../store-server.gbdialog/auto-register.bas | 8 ++-- .../calculate-shipping.bas | 37 ++++++------------- .../classify-product.bas | 8 ++-- .../store-server.gbdialog/enrich-product.bas | 15 ++------ .../store-server.gbdialog/get-ncm.bas | 11 +++--- .../store-server.gbdialog/scan-barcode.bas | 23 ++++-------- .../scan-product-image.bas | 7 ++-- .../store-server.gbdialog/search-products.bas | 14 ++++--- 8 files changed, 51 insertions(+), 72 deletions(-) diff --git a/store-server.gbai/store-server.gbdialog/auto-register.bas b/store-server.gbai/store-server.gbdialog/auto-register.bas index 1a98963..ee20941 100644 --- a/store-server.gbai/store-server.gbdialog/auto-register.bas +++ b/store-server.gbai/store-server.gbdialog/auto-register.bas @@ -5,8 +5,8 @@ IF LEN(existing) > 0 THEN RETURN existing[0] END IF -info = LLM "Extract product info: " + query + ". Return JSON {name, category, brand, description}" -info.is_active = true +info = LLM "Extract product info: " + query + ". Return JSON with name, category, brand, description" -SAVE "products", info -RETURN info +SAVE "products" WITH name AS info.name, category AS info.category, brand AS info.brand, description AS info.description, is_active AS true + +RETURN FIND "products" WITH "name = '" + info.name + "'" diff --git a/store-server.gbai/store-server.gbdialog/calculate-shipping.bas b/store-server.gbai/store-server.gbdialog/calculate-shipping.bas index 41e34d8..51e75de 100644 --- a/store-server.gbai/store-server.gbdialog/calculate-shipping.bas +++ b/store-server.gbai/store-server.gbdialog/calculate-shipping.bas @@ -3,39 +3,26 @@ PARAM quantity AS INTEGER product = PRODUCT product_id IF NOT product THEN - RETURN {error: "Product not found"} + RETURN WITH error AS "Product not found" END IF IF NOT quantity THEN quantity = 1 END IF -dimensions = { - length: product.length, - width: product.width, - height: product.height, - weight: product.gross_weight -} - -IF NOT dimensions.weight THEN - dimensions = LLM "Estimate shipping dimensions for: " + product.name + ". Return JSON {length_cm, width_cm, height_cm, weight_kg}" +IF NOT product.gross_weight THEN + dims = LLM "Estimate shipping dimensions for: " + product.name + ". Return JSON with length_cm, width_cm, height_cm, weight_kg" + UPDATE "products" WITH length AS dims.length_cm, width AS dims.width_cm, height AS dims.height_cm, gross_weight AS dims.weight_kg WHERE id = product_id + product = PRODUCT product_id END IF -volume = dimensions.length * dimensions.width * dimensions.height * quantity +volume = product.length * product.width * product.height * quantity volumetric_weight = volume / 5000 -billable = MAX(dimensions.weight * quantity, volumetric_weight) +actual_weight = product.gross_weight * quantity +billable = MAX actual_weight, volumetric_weight -shipping = { - product_id: product_id, - quantity: quantity, - dimensions: dimensions, - volume_cm3: volume, - billable_weight_kg: billable, - options: [ - {carrier: "Ground", days: "5-7", cost: 5.99 + billable * 1.5}, - {carrier: "Express", days: "2-3", cost: 12.99 + billable * 2.5}, - {carrier: "Overnight", days: "1", cost: 24.99 + billable * 4.0} - ] -} +ground_cost = 5.99 + billable * 1.5 +express_cost = 12.99 + billable * 2.5 +overnight_cost = 24.99 + billable * 4.0 -RETURN shipping +RETURN WITH product_id AS product_id, quantity AS quantity, length AS product.length, width AS product.width, height AS product.height, weight AS product.gross_weight, volume_cm3 AS volume, billable_weight_kg AS billable, ground_cost AS ground_cost, ground_days AS "5-7", express_cost AS express_cost, express_days AS "2-3", overnight_cost AS overnight_cost, overnight_days AS "1" diff --git a/store-server.gbai/store-server.gbdialog/classify-product.bas b/store-server.gbai/store-server.gbdialog/classify-product.bas index 9bf9b88..b231fc0 100644 --- a/store-server.gbai/store-server.gbdialog/classify-product.bas +++ b/store-server.gbai/store-server.gbdialog/classify-product.bas @@ -2,12 +2,12 @@ PARAM query AS STRING categories = FIND "categories" similar = SEARCH PRODUCTS query, 5 -result = LLM "Classify '" + query + "' into: " + categories + ". Similar: " + similar + ". Return JSON {category_id, name, confidence, brand, type}" +result = LLM "Classify '" + query + "' into: " + categories + ". Similar: " + similar + ". Return JSON with category_id, name, confidence, brand, type" -cached = FIND "product_cache", "query=" + query +cached = FIND "products" WITH "name LIKE '%" + query + "%'" IF cached THEN - RETURN cached.result + RETURN cached END IF -SAVE "product_cache", {query: query, result: result} +SAVE "products" WITH name AS query, category AS result.name, brand AS result.brand, external_metadata AS result RETURN result diff --git a/store-server.gbai/store-server.gbdialog/enrich-product.bas b/store-server.gbai/store-server.gbdialog/enrich-product.bas index 295ace4..7a1baa6 100644 --- a/store-server.gbai/store-server.gbdialog/enrich-product.bas +++ b/store-server.gbai/store-server.gbdialog/enrich-product.bas @@ -2,7 +2,7 @@ PARAM product_id AS STRING product = PRODUCT product_id IF NOT product THEN - RETURN {error: "Product not found"} + RETURN WITH error AS "Product not found" END IF IF product.description AND product.brand THEN @@ -21,15 +21,8 @@ FOR i = 0 TO 2 END IF NEXT -result = LLM "Analyze these product descriptions: " + enriched + ". Create best description for: " + product.name + ". Return JSON {description, brand, material, features}" +result = LLM "Analyze these product descriptions: " + enriched + ". Create best description for: " + product.name + ". Return JSON with description, brand, material, features" -UPDATE "products", product_id, { - description: result.description, - brand: result.brand, - material: result.material, - external_metadata: result -} +UPDATE "products" WITH description AS result.description, brand AS result.brand, material AS result.material, external_metadata AS result WHERE id = product_id -product.description = result.description -product.brand = result.brand -RETURN product +RETURN PRODUCT product_id diff --git a/store-server.gbai/store-server.gbdialog/get-ncm.bas b/store-server.gbai/store-server.gbdialog/get-ncm.bas index 1ae6eae..f9ecb21 100644 --- a/store-server.gbai/store-server.gbdialog/get-ncm.bas +++ b/store-server.gbai/store-server.gbdialog/get-ncm.bas @@ -2,13 +2,14 @@ PARAM product_id AS STRING product = PRODUCT product_id IF NOT product THEN - RETURN {error: "Product not found"} + RETURN WITH error AS "Product not found" END IF IF product.tax_code THEN - RETURN {tax_code: product.tax_code, tax_class: product.tax_class} + RETURN WITH tax_code AS product.tax_code, tax_class AS product.tax_class END IF -info = LLM "Get NCM/tax classification for: " + product.name + " " + product.category + ". Return JSON {tax_code, tax_class, description}" -UPDATE "products", product_id, {tax_code: info.tax_code, tax_class: info.tax_class} -RETURN info +info = LLM "Get NCM/tax classification for: " + product.name + " " + product.category + ". Return JSON with tax_code, tax_class, description" +UPDATE "products" WITH tax_code AS info.tax_code, tax_class AS info.tax_class WHERE id = product_id + +RETURN WITH tax_code AS info.tax_code, tax_class AS info.tax_class, description AS info.description diff --git a/store-server.gbai/store-server.gbdialog/scan-barcode.bas b/store-server.gbai/store-server.gbdialog/scan-barcode.bas index 556caf1..b4573ba 100644 --- a/store-server.gbai/store-server.gbdialog/scan-barcode.bas +++ b/store-server.gbai/store-server.gbdialog/scan-barcode.bas @@ -2,29 +2,22 @@ PARAM image AS STRING barcode = SCAN BARCODE image IF NOT barcode THEN - RETURN {error: "No barcode found"} + RETURN WITH error AS "No barcode found" END IF ean = barcode.data -cached = FIND "products", "global_trade_number=" + ean +cached = FIND "products" WITH "global_trade_number = '" + ean + "'" IF cached THEN RETURN cached END IF data = GET "https://world.openfoodfacts.org/api/v0/product/" + ean + ".json" IF data.product THEN - product = { - name: data.product.product_name, - brand: data.product.brands, - global_trade_number: ean, - description: data.product.generic_name, - category: data.product.categories, - net_weight: data.product.quantity - } -ELSE - product = LLM "Search product info for EAN: " + ean + ". Return JSON {name, brand, description, category}" - product.global_trade_number = ean + SAVE "products" WITH name AS data.product.product_name, brand AS data.product.brands, global_trade_number AS ean, description AS data.product.generic_name, category AS data.product.categories, net_weight AS data.product.quantity + RETURN FIND "products" WITH "global_trade_number = '" + ean + "'" END IF -SAVE "products", product -RETURN product +info = LLM "Search product info for EAN: " + ean + ". Return JSON with name, brand, description, category" +SAVE "products" WITH name AS info.name, brand AS info.brand, description AS info.description, category AS info.category, global_trade_number AS ean + +RETURN FIND "products" WITH "global_trade_number = '" + ean + "'" diff --git a/store-server.gbai/store-server.gbdialog/scan-product-image.bas b/store-server.gbai/store-server.gbdialog/scan-product-image.bas index 3f9072e..7d395d8 100644 --- a/store-server.gbai/store-server.gbdialog/scan-product-image.bas +++ b/store-server.gbai/store-server.gbdialog/scan-product-image.bas @@ -7,6 +7,7 @@ IF LEN(similar) > 0 THEN RETURN similar[0] END IF -product = LLM "Extract product info from: " + description + ". Return JSON {name, brand, category, color, material}" -SAVE "products", product -RETURN product +product = LLM "Extract product info from: " + description + ". Return JSON with name, brand, category, color, material" +SAVE "products" WITH name AS product.name, brand AS product.brand, category AS product.category, color AS product.color, material AS product.material + +RETURN FIND "products" WITH "name = '" + product.name + "'" diff --git a/store-server.gbai/store-server.gbdialog/search-products.bas b/store-server.gbai/store-server.gbdialog/search-products.bas index 867d62b..71cebdb 100644 --- a/store-server.gbai/store-server.gbdialog/search-products.bas +++ b/store-server.gbai/store-server.gbdialog/search-products.bas @@ -1,16 +1,20 @@ PARAM query AS STRING -cached = FIND "search_cache", "query=" + query +cached = FIND "products" WITH "name ILIKE '%" + query + "%' OR description ILIKE '%" + query + "%'" IF cached THEN - RETURN cached.result + RETURN cached END IF result = SEARCH PRODUCTS query, 10 IF LEN(result) = 0 THEN web = SCRAPE_ALL "https://www.google.com/search?q=" + query + "+product", ".g" - result = LLM "Extract products from: " + web + ". Return JSON [{name, price, description}]" + result = LLM "Extract products from: " + web + ". Return JSON array with name, price, description" END IF -enhanced = LLM "Add descriptions: " + result + ". Return JSON [{id, name, price, description, stock}]" -SAVE "search_cache", {query: query, result: enhanced} +enhanced = LLM "Add descriptions: " + result + ". Return JSON array with id, name, price, description, stock" + +FOR EACH item IN enhanced + SAVE "products" WITH name AS item.name, description AS item.description, price AS item.price, external_metadata AS item +NEXT + RETURN enhanced