UNPKG

@forbespro/lead-agent

Version:
2 lines (1 loc) 9.25 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("react/jsx-runtime"),I=require("framer-motion"),N=require("react"),w=require("./index28.js"),$=require("./index29.js"),k=require("./index15.js"),_=({product:e})=>e?l.jsx("div",{className:"fpl-mt-3 fpl-mb-1 fpl-border fpl-rounded-lg fpl-overflow-hidden fpl-shadow-sm fpl-bg-white",children:l.jsx("a",{href:`${e.slug||e.id?`${e.slug||e.id}`:"#"}`,className:"fpl-block fpl-no-underline fpl-text-inherit hover:fpl-bg-gray-50","aria-label":`View ${e.name||e.product_type} details`,target:"_blank",children:l.jsxs("div",{className:"fpl-flex fpl-items-center",children:[e.product_image&&l.jsx("div",{className:"fpl-w-20 fpl-h-20 fpl-flex-shrink-0",children:l.jsx("img",{src:e.product_image,alt:e.product_image_alt||e.name||e.product_type,className:"fpl-w-full fpl-h-full fpl-object-cover"})}),l.jsxs("div",{className:"fpl-p-3 fpl-flex-1",children:[l.jsxs("h4",{className:"fpl-font-medium fpl-text-primary fpl-text-sm",children:[e.manufacturer," ",e.name||e.product_type]}),e.model_number&&l.jsxs("div",{className:"fpl-text-xs fpl-text-gray-600",children:["Model: ",e.model_number]}),l.jsx("span",{className:"fpl-text-xs fpl-text-blue-600",children:"View details"})]})]})})}):null,S=e=>e.length>0?e.map((n,r)=>{const t=`product-card-${n.id||n.objectID||r}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`;return l.jsx(_,{product:n},t)}):null,b=({text:e,className:n,role:r})=>{if(r==="user")return l.jsx("div",{className:n||"fpl-inline",children:l.jsx("div",{className:"fpl-leading-relaxed",children:e})});const a=N.useMemo(()=>typeof e!="string"?"":e,[e]);return l.jsx("div",{className:n||"fpl-inline",children:l.jsx("div",{className:"fpl-leading-relaxed fpl-overflow-auto last:!fpl-mb-0",children:l.jsx($.Markdown,{components:{a:({href:t,children:i})=>l.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"fpl-text-blue-600 fpl-underline fpl-text-base",children:i}),p:({children:t})=>l.jsx("p",{className:"fpl-mb-2 fpl-text-base",children:t}),ul:({children:t})=>l.jsx("ul",{className:"fpl-list-disc fpl-ml-5 fpl-mb-2 fpl-text-base",children:t}),ol:({children:t})=>l.jsx("ol",{className:"fpl-list-decimal fpl-ml-5 fpl-mb-2 fpl-text-base ",children:t}),li:({children:t})=>l.jsx("li",{className:"fpl-mb-1 fpl-text-sm",children:t}),h1:({children:t})=>l.jsx("h1",{className:"fpl-text-lg fpl-font-bold fpl-mb-2",children:t}),h2:({children:t})=>l.jsx("h2",{className:"fpl-text-md fpl-font-bold fpl-mb-1",children:t}),h3:({children:t})=>l.jsx("h3",{className:"fpl-text-base fpl-font-bold fpl-mb-1",children:t}),code:({children:t})=>l.jsx("code",{className:"fpl-bg-gray-100 fpl-p-1 fpl-rounded",children:t}),pre:({children:t})=>l.jsx("pre",{className:"fpl-bg-gray-100 fpl-p-2 fpl-rounded fpl-mb-4 fpl-overflow-auto",children:t}),strong:({children:t})=>l.jsx("strong",{className:"fpl-font-bold",children:t})},children:a})})})},g=e=>{if(!e)return"";const n=typeof e=="object"?e:new Date(e),r=typeof navigator!="undefined"?navigator.language:"en-GB";return n.toLocaleDateString(r,{month:"numeric",day:"numeric",year:"numeric"})+", "+n.toLocaleTimeString(r,{hour:"2-digit",minute:"2-digit",hour12:!0})},M=e=>{var n;if(((n=e.toolInvocation)==null?void 0:n.toolName)==="searchProducts"&&e.toolInvocation.result){const r=e.toolInvocation.result.products;if(!r||r.length===0)return null;const a=r.reduce((i,f)=>{const s=f.id||f.objectID||JSON.stringify(f);return i.some(p=>(p.id||p.objectID)===s)||i.push(f),i},[]);if(a.length===0)return null;const t=`product-tool-${e.toolInvocation.toolCallId}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`;return l.jsx("div",{className:"fpl-mt-2",children:a.map((i,f)=>{const s=i.id||i.objectID||f,p=`product-${e.toolInvocation.toolCallId}-${s}-${f}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`;return l.jsx("div",{children:S([i])},p)})},t)}return null},q=(e,n)=>{var r;return((r=e.toolInvocation)==null?void 0:r.toolName)==="searchBookings"&&e.toolInvocation.result?l.jsx("div",{className:"fpl-mt-2",children:e.toolInvocation.result.bookings.map((a,t)=>l.jsx("div",{children:n([a])},`booking-${e.toolInvocation.toolCallId}-${t}`))},`booking-tool-${e.toolInvocation.toolCallId}`):null},C=(e,n)=>{var r;return((r=e.toolInvocation)==null?void 0:r.toolName)==="buildQuote"&&e.toolInvocation.result?l.jsx("div",{className:"fpl-mt-2",children:n(e.toolInvocation.result)},`quote-tool-${e.toolInvocation.toolCallId}`):null},j=({type:e="text",placeholder:n="",onSubmit:r})=>{const[a,t]=N.useState(""),i=f=>{f.preventDefault(),r(a),t("")};return l.jsxs("form",{onSubmit:i,className:"fpl-mt-2",children:[l.jsx("input",{type:e,placeholder:n,value:a,onChange:f=>t(f.target.value),className:"fpl-w-full fpl-p-2 fpl-border fpl-rounded",required:!0}),l.jsxs("button",{type:"submit",className:"fpl-mt-2 fpl-px-4 fpl-py-2 fpl-bg-blue-500 fpl-text-white fpl-rounded",children:[l.jsx("span",{className:"fpl-sr-only",children:"Submit"}),l.jsx(k.default,{strokeLinecap:"round",strokeWidth:4,className:"fpl-w-5 fpl-h-5"})]})]})},v=({options:e,onSelect:n})=>l.jsx("div",{className:"fpl-flex fpl-flex-wrap fpl-gap-2 fpl-mt-2",children:e.map((r,a)=>l.jsx("button",{onClick:()=>n(r),className:"fpl-px-4 fpl-py-2 fpl-bg-gray-200 hover:fpl-bg-gray-300 fpl-rounded",children:r},a))}),T=({question:e,onSelect:n})=>l.jsxs("div",{className:"fpl-mt-2",children:[l.jsx("p",{className:"fpl-mb-2",children:e}),l.jsxs("div",{className:"fpl-flex fpl-gap-2",children:[l.jsx("button",{onClick:()=>n("Yes"),className:"fpl-px-4 fpl-py-2 fpl-bg-green-500 fpl-text-white fpl-rounded",children:"Yes"}),l.jsx("button",{onClick:()=>n("No"),className:"fpl-px-4 fpl-py-2 fpl-bg-gray-500 fpl-text-white fpl-rounded",children:"No"})]})]}),y=({message:e,renderBookingResults:n,renderQuoteBuilder:r,isStreaming:a=!1,handleTriggerAction:t})=>{const i=(s,p)=>{t&&t(s,p)},f=()=>{var p;const s=(p=e.annotations)==null?void 0:p.find(o=>o.type==="ui_trigger");return e.parts&&Array.isArray(e.parts)&&e.parts.length>0?(e.parts.filter(o=>o.type==="text").length,l.jsx(l.Fragment,{children:e.parts.map((o,c)=>{var u,d,x,m,h;if(o.type==="step-start")return l.jsx("div",{className:"fpl-hidden fpl-mt-0"},`step-start-${c}`);if(o.type==="text")return l.jsx("div",{"aria-label":`Message content for ${e.role}`,className:`fpl-order-first fpl-max-w-[275px] fpl-mb-2 fpl-rounded-lg fpl-p-3 fpl-w-full fpl-flex-f fpl-shadow-sm fpl-break-words ${e.role==="user"?"fpl-bg-[#132968] !fpl-text-white fpl-rounded-br-none":"fpl-bg-gray-200 !fpl-text-black fpl-rounded-bl-none"}`,children:l.jsx(b,{text:o.text||"",role:e.role,isStreaming:a,className:`${e.role==="user"?"!fpl-text-white":"!fpl-text-black"} fpl-text-base`})},`text-${c}`);if(o.type==="tool-invocation"){if(((u=o.toolInvocation)==null?void 0:u.toolName)==="openExternalLink"&&((d=o.toolInvocation.result)!=null&&d.url))return l.jsx(w.default,{url:o.toolInvocation.result.url,displayText:o.toolInvocation.result.displayText||"Open Link",openInNewTab:!0},`link-${c}`);if(((x=o.toolInvocation)==null?void 0:x.toolName)==="searchProducts")return M(o);if(((m=o.toolInvocation)==null?void 0:m.toolName)==="searchBookings"&&n)return q(o,n);if(((h=o.toolInvocation)==null?void 0:h.toolName)==="buildQuote"&&r)return C(o,r)}return null})})):l.jsxs(l.Fragment,{children:[l.jsx("div",{"aria-label":`Message content for ${e.role}`,className:`fpl-order-first fpl-max-w-[275px] fpl-rounded-lg fpl-p-3 fpl-w-full fpl-flex-f fpl-shadow-sm fpl-break-words ${e.role==="user"?"fpl-bg-[#132968] !fpl-text-white fpl-rounded-br-none":"fpl-bg-gray-200 !fpl-text-black fpl-rounded-bl-none"}`,children:l.jsx(b,{text:e.content||"",role:e.role,isStreaming:a,className:`fpl-mb-2 ${e.role==="user"?"!fpl-text-white":"!fpl-text-black"} fpl-text-base`})}),e.role==="assistant"&&s&&l.jsxs("div",{className:"fpl-mt-4 fpl-w-full",children:[s.trigger==="input_field"&&l.jsx(j,{type:s.inputType||"text",placeholder:s.placeholder||"",onSubmit:o=>i(s.trigger,o)}),s.trigger==="button_options"&&s.options&&l.jsx(v,{options:s.options,onSelect:o=>i(s.trigger,o)}),s.trigger==="yes_no_buttons"&&l.jsx(T,{question:s.question||"Please confirm:",onSelect:o=>i(s.trigger,o)}),s.trigger==="sector_search"&&l.jsx(j,{type:"text",placeholder:"Search for your industry",onSubmit:o=>i("sector",o)}),s.trigger==="welcome_options"&&l.jsx(v,{options:["Get a quote","Product information","Contact us"],onSelect:o=>i("welcome",o)})]})]})};return a?null:l.jsxs(I.motion.div,{className:`fpl-mb-4 fpl-flex ${e.role==="user"?"fpl-flex-col fpl-items-end":"fpl-flex-col fpl-items-start"}`,initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.3},role:"listitem","aria-label":`${e.role==="user"?"You":"Assistant"} message`,children:[l.jsx("div",{className:`fpl-message-content fpl-flex ${e.role==="user"?"fpl-flex-col fpl-items-end":"fpl-flex-col fpl-items-start"}`,lang:"en",children:f()}),(!e.parts||e.parts.length!==1||e.parts[0].type!=="step-start")&&l.jsx("div",{className:`fpl-text-xs fpl-mt-1 ${e.role==="user"?"fpl-text-right fpl-text-gray-500":"fpl-text-left fpl-text-gray-500"}`,"aria-label":`Sent ${g(e.createdAt||Date.now())}`,children:g(e.createdAt||Date.now())})]})};exports.ChatMessage=y;exports.default=y;