import { AppsSDKUIProvider } from "@openai/apps-sdk-ui/components/AppsSDKUIProvider"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { McpUseProvider, useWidget, type WidgetMetadata } from "mcp-use/react"; import React from "react"; import { Link } from "react-router"; import { ProductCard, PricingDeal, Features, ImageGallery, ProductSpecs, DeliveryInfo, CustomerReviews, SellerInfo, } from "./components"; import { useProductAnalysis } from "./hooks"; import type { AmazonProductAnalysisProps } from "./types"; import { propSchema } from "./types"; import "../styles.css"; export const widgetMetadata: WidgetMetadata = { description: "Analyze any Amazon product by URL. Returns comprehensive product details including pricing, features, specifications, delivery options, customer reviews, and seller information.", inputs: propSchema, appsSdkMetadata: { "openai/widgetDescription": "Interactive Amazon product analysis widget with full product insights", }, }; const queryClient = new QueryClient(); const AmazonProductAnalysisContent: React.FC = () => { const { props, mcp_url } = useWidget(); const { url, zipcode } = props; // Fetch product analysis data using the custom hook const { data: analysis, isLoading, error } = useProductAnalysis(url, zipcode, mcp_url); return (
{/* Header gradient */}
{/* Title Section */}
Product Analysis

Amazon Product Insights

Comprehensive analysis powered by AI

{/* Loading State */} {isLoading && (

Analyzing product...

Fetching data from Amazon via Bright Data

)} {/* Error State */} {error && (

Failed to analyze product

{error.message}

)} {/* Success State - Show Analysis */} {analysis && ( <> {/* Product Card - shows available fields only */} {analysis.product && ( )} {/* Image Gallery - if multiple images available */} {analysis.images && analysis.images.length > 1 && ( )} {/* Two column layout for Pricing and Features - only show if we have data */} {(analysis.pricing || (analysis.features && analysis.features.length > 0)) && (
{analysis.pricing && ( )} {analysis.features && analysis.features.length > 0 && ( )}
)} {/* Delivery and Seller Info Row */} {(analysis.delivery || analysis.seller || analysis.rankings || analysis.categories) && (
{analysis.delivery && analysis.delivery.length > 0 && ( )} {(analysis.seller || (analysis.rankings && analysis.rankings.length > 0) || (analysis.categories && analysis.categories.length > 0)) && ( )}
)} {/* Customer Reviews */} {analysis.customerReview && (analysis.customerReview.summary || analysis.customerReview.topReview) && ( )} {/* Product Specifications */} {analysis.specifications && analysis.specifications.length > 0 && ( )} )} {/* Footer */}
Data sourced via Bright Data • Analysis by AI
); }; const AmazonProductAnalysis: React.FC = () => { return ( ); }; export default AmazonProductAnalysis;