PageSourceSearch

https://javawhiskers.co.uk/assets/AdminIntelligence-BkRapUES.js

js javawhiskers.co.uk collected 2026-10-05 01:10:46 UTC 17,017 bytes, 7 lines download raw bytes

1import{r as o,j as e}from"./vendor-react-Bt3w6bFX.js";import{supabase as P}from"./client-Dq1sIdUg.js";import{C as J,b as Q,c as Y,d as Z,a as ee}from"./card-Bi2qPvvW.js";import{T as se,a as te,b,c as v}from"./tabs-Db3X4Xz7.js";import{B as $}from"./button-Df1CPV9Y.js";import{B as p}from"./badge-DDbBmJ7-.js";import{I as ae}from"./input-CV5g6U6p.js";import{L as ne}from"./label-X0P9YXaL.js";import{T as ie}from"./textarea-mZ1qwnuB.js";import{a2 as N}from"./index-B3NwW_rO.js";import{e as le}from"./slideDeck-C_7-CdBn.js";import{a2 as re,B as u,bb as ce,b9 as _,bF as de,bG as H,bH as oe,aL as me,H as he,aF as pe,bI as ue,x as xe,aX as ge,aI as fe,a_ as je,a as ye}from"./vendor-icons-Bt7APd9S.js";import"./vendor-supabase-B8wCO4e6.js";import"./index-De_AyhTI.js";const f=x=>x==="high"?"bg-red-500/10 text-red-600 border-red-500/30":x==="medium"?"bg-amber-500/10 text-amber-600 border-amber-500/30":"bg-emerald-500/10 text-emerald-600 border-emerald-500/30",k=[{key:"diagnose.discourse",title:"Discourse Analysis",desc:"What visitors are talking about, chat & contact",icon:oe,kind:"insight"},{key:"diagnose.segmentation",title:"Segmentation Studies",desc:"Psychographic target group profiles",icon:_,kind:"insight"},{key:"diagnose.trends",title:"Trends Discovery",desc:"Ups and downs in the last period",icon:me,kind:"insight"},{key:"diagnose.brand_health",title:"Brand Health Tracking",desc:"Brand health check in real time",icon:he,kind:"insight"}],w=[{key:"generate.positioning",title:"Brand Positioning",desc:"Strategisk differentiering",icon:_,kind:"creative",inputs:[{name:"focus",label:"Specific angle (optional)",placeholder:"e.g. premium segment, family, sustainability"}]},{key:"generate.campaign",title:"Campaign Ideation",desc:"AI-genererade kampanjkoncept",icon:pe,kind:"creative",inputs:[{name:"goal",label:"Goal",placeholder:"e.g. increase weekend bookings 20%"},{name:"budget",label:"Budget",placeholder:"e.g. £5,000"},{name:"season",label:"Season/time period",placeholder:"ex: oktober-jul"}]},{key:"generate.concept",title:"Concept Innovation",desc:"Insights → creative briefs",icon:ue,kind:"creative",inputs:[{name:"theme",label:"Theme (optional)",placeholder:"e.g. new revenue streams, partnerships"}]},{key:"generate.copy",title:"Conversational AI Copy",desc:"Targeted marketing copy",icon:xe,kind:"creative",inputs:[{name:"format",label:"Format",placeholder:"Instagram post, email, push"},{name:"message",label:"Message",type:"textarea",placeholder:"What should the copy say?"},{name:"tone",label:"Tone",placeholder:"warm, playful, selling"},{name:"variants",label:"Number of variants",placeholder:"4"}]}],C=[{key:"predict.creative_eval",title:"Creative Evaluation",desc:"Evaluate a creative before launch",icon:ge,kind:"forecast",inputs:[{name:"creative",label:"Describe creative",type:"textarea",placeholder:"Headline, bild, CTA…"},{name:"channel",label:"Channel",placeholder:"Meta, Google Display, email"},{name:"audience",label:"Target audience",placeholder:"ex: kvinnor 25-40, London"}]},{key:"predict.concept_test",title:"Concept Testing",desc:"Predict resonance with target audience",icon:fe,kind:"forecast",inputs:[{name:"concept",label:"The concept",type:"textarea",placeholder:"Describe the idea in 2-4 sentences"}]},{key:"predict.performance",title:"Performance Forecasting",desc:"Forecast for the upcoming period",icon:H,kind:"forecast",inputs:[{name:"horizon_days",label:"Horizon (days)",placeholder:"30"},{name:"plans",label:"Planned initiatives",type:"textarea",placeholder:"e.g. launch new event, paid social campaign"}]}],Ee=()=>{const[x,S]=o.useState(null),[h,I]=o.useState({}),[j,M]=o.useState({}
1),[T,R]=o.useState(!1),[D,B]=o.useState({done:0,total:0}),[z,O]=o.useState(!0),[g,U]=o.useState(null),[A,E]=o.useState(!1),F=o.useRef(!1),G=(a,c,i)=>M(s=>({...s,[a]:{...s[a]||{},[c]:i}})),L=async a=>{const c=a.key;S(c);try{const{data:i,error:s}=await P.functions.invoke("intelligence-agent",{body:{action:a.key,input:j[a.key]||{}}});if(s)throw s;if(i?.error)throw new Error(i.error);I(t=>({...t,[c]:i}))}catch(i){throw console.error(`[intelligence] ${a.key} failed:`,i),i}finally{S(null)}},W=async()=>{R(!0);const a=[...k,...w,...C];B({done:0,total:a.length});let c=0;const i=4;try{for(let s=0;s<a.length;s+=i){const t=a.slice(s,s+i);await Promise.all(t.map(l=>L(l).catch(()=>{}).finally(()=>{c+=1,B({done:c,total:a.length})})))}N.success("All analyses complete")}finally{R(!1)}};o.useEffect(()=>{(async()=>{try{const{data:a,error:c}=await P.from("intelligence_results").select("action, result, data_snapshot, updated_at");if(c)throw c;const i={};let s=null;(a||[]).forEach(t=>{i[t.action]={action:t.action,result:t.result,data_snapshot:t.data_snapshot},(!s||t.updated_at>s)&&(s=t.updated_at)}),I(i),U(s),Object.keys(i).length===0&&!F.current&&(F.current=!0,W())}catch(a){console.error("[intelligence] could not read saved analyses:",a)}finally{O(!1)}})()},[]);const K=a=>h[a.key]?X(a):null,V=()=>{const a=[{kicker:"Diagnose",items:k},{kicker:"Generate",items:w},{kicker:"Predict",items:C}],c=[],i=Object.values(h)[0]?.data_snapshot;return i&&c.push({title:"Data source",kicker:"Intelligence Agent",blocks:[{type:"kpis",items:[{label:"Sessions",value:new Intl.NumberFormat("en-GB").format(Number(i.sessions_total||0))},{label:"Purchases",value:new Intl.NumberFormat("en-GB").format(Number(i.purchases_count||0))},{label:"Revenue",value:`${new Intl.NumberFormat("en-GB").format(Math.round(Number(i.revenue_total||0)))} GBP`},{label:"Bounce rate",value:`${Number(i.bounce_rate_pct||0).toFixed(1)}%`}]},{type:"note",text:"The analyses are based on the entire history of first-party tracking and sales data from Roller."}]}),a.forEach(({kicker:s,items:t})=>{t.forEach(l=>{const m=h[l.key];if(!m)return;const r=[];if(l.kind==="insight"){const n=m.result;r.push({type:"note",text:`${n.headline}
2
3${n.summary}`}),n.key_findings?.length&&r.push({type:"table",title:"Key findings",cols:[{header:"Finding",width:1.1},{header:"Detail",width:2.4,align:"left"},{header:"Severity",width:.6}],rows:n.key_findings.map(d=>[d.title,d.detail,d.severity])}),n.recommendations?.length&&r.push({type:"table",title:"Recommendations",cols:[{header:"Action",width:1.4},{header:"Rationale",width:2.2,align:"left"},{header:"Impact",width:.5},{header:"Effort",width:.5}],rows:n.recommendations.map(d=>[d.action,d.rationale,d.impact,d.effort])})}else if(l.kind==="creative"){const n=m.result;r.push({type:"note",text:`${n.headline}
4
5${n.summary}`}),n.ideas?.length&&r.push({type:"table",title:"Ideas",cols:[{header:"Idea",width:1},{header:"Concept",width:2,align:"left"},{header:"Hook",width:1.2,align:"left"},{header:"Channels",width:.9,align:"left"}],rows:n.ideas.map(d=>[d.title,d.concept,d.hook,(d.channels||[]).join(", ")])}),n.next_steps?.length&&r.push({type:"bullets",title:"Next steps",items:n.next_steps})}else{const n=m.result;r.push({type:"kpis",items:[{label:"Score",value:String(Math.round(n.score||0)),sub:n.score_label}]}),r.push({type:"note",text:`${n.headline}
6
7${n.summary}`}),n.strengths?.length&&r.push({type:"bullets",title:"Strengths",items:n.strengths}),n.weaknesses?.length&&r.push({type:"bullets",title:"Weaknesses",items:n.weaknesses}),n.predicted_metrics?.length&&r.push({type:"table",title:"Forecasts",cols:[{header:"Metric",width:1},{header:"Forecast",width:2,align:"left"},{header:"Confidence",width:.6}],rows:n.predicted_metrics.map(d=>[d.metric,d.forecast,d.confidence])}),n.recommendations?.length&&r.push({type:"bullets",title:"Recommendations",items:n.recommendations})}c.push({title:l.title,kicker:`Intelligence · ${s}`,blocks:r})})}),c},q=async()=>
7{if(Object.keys(h).length===0){N.error("No analysis to export yet.");return}E(!0);try{await le({title:"Intelligence Agent",subtitle:`Consumer intelligence · ${g?new Date(g).toLocaleDateString("en-GB"):new Date().toLocaleDateString("en-GB")}`,fileName:`javawhiskers-intelligence-${new Date().toISOString().slice(0,10)}.pdf`,slides:V()})}catch(a){console.error(a),N.error("Could not create report.")}finally{E(!1)}},X=(a,c)=>{const i=h[a.key];if(!i)return null;if(a.kind==="insight"){const s=i.result;return e.jsxs("div",{className:"mt-4 space-y-4 border-t pt-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase text-muted-foreground mb-1",children:"Insight"}),e.jsx("h4",{className:"font-semibold text-base",children:s.headline}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s.summary}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-2",children:["Confidence: ",Math.round((s.confidence||0)*100),"%"]})]}),s.key_findings?.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase text-muted-foreground mb-2",children:"Key findings"}),e.jsx("div",{className:"space-y-2",children:s.key_findings.map((t,l)=>e.jsxs("div",{className:"border rounded-md p-3 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"font-medium",children:t.title}),e.jsx(p,{variant:"outline",className:f(t.severity),children:t.severity})]}),e.jsx("p",{className:"text-muted-foreground",children:t.detail})]},l))})]}),s.recommendations?.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase text-muted-foreground mb-2",children:"Recommendations"}),e.jsx("div",{className:"space-y-2",children:s.recommendations.map((t,l)=>e.jsxs("div",{className:"border rounded-md p-3 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1 gap-2",children:[e.jsxs("span",{className:"font-medium flex items-start gap-2",children:[e.jsx(ye,{className:"h-4 w-4 mt-0.5 shrink-0"}),t.action]}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[e.jsxs(p,{variant:"outline",className:f(t.impact),children:["Impact: ",t.impact]}),e.jsxs(p,{variant:"outline",className:f(t.effort==="high"?"low":t.effort==="low"?"high":"medium"),children:["Effort: ",t.effort]})]})]}),e.jsx("p",{className:"text-muted-foreground ml-6",children:t.rationale})]},l))})]})]})}if(a.kind==="creative"){const s=i.result;return e.jsxs("div",{className:"mt-4 space-y-4 border-t pt-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-base",children:s.headline}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s.summary})]}),e.jsx("div",{className:"grid gap-3",children:s.ideas.map((t,l)=>e.jsxs("div",{className:"border rounded-md p-3 space-y-2",children:[e.jsx("div",{className:"font-medium text-sm",children:t.title}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.concept}),e.jsxs("div",{className:"text-sm italic border-l-2 border-primary pl-3",children:['"',t.hook,'"']}),e.jsx("div",{className:"bg-muted/50 rounded p-2 text-sm whitespace-pre-wrap",children:t.example_copy}),e.jsxs("div",{className:"flex flex-wrap gap-1 text-xs",children:[e.jsx(p,{variant:"secondary",children:t.target_audience}),t.channels.map((m,r)=>e.jsx(p,{variant:"outline",children:m},r))]})]},l))}),s.next_steps?.length>0&&e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"text-xs uppercase text-muted-foreground mb-1",children:"Next steps"}),e.jsx("ul",{className:"list-disc pl-5 space-y-1",children:s.next_steps.map((t,l)=>e.jsx("li",{children:t},l))})]})]})}if(a.kind==="forecast"){const s=i.result;return e.jsxs("div",{className:"mt-4 space-y-4 border-t pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-base",children:s.headline}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s.summary})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("div",{className:"text-3xl font-bold",children:Math.round(s.score)}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.score_label})]})]}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{className:"border rounded-md p-3",children:[e.jsx("div",{className:"text-xs uppercase text-muted-foreground mb-2",children:"Styrkor"}),e.jsx("ul",{className:"list-disc pl-5 space-y-1",children:s.strengths.map((t,l)=>e.jsx("li",{children:t},l))})]}),e.jsxs("div",{className:"border rounded-md p-3",children:[e.jsx("div",{className:"text-xs uppercase text-muted-foreground mb-2",children:"Svagheter"}),e.jsx("ul",{className:"list-disc pl-5 space-y-1",children:s.weaknesses.map((t,l)=>e.jsx("li",{children:t},l))})]})]}),s.predicted_metrics?.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase text-muted-foreground mb-2",children:"Prognoser"}),e.jsx("div",{className:"space-y-1.5",children:s.predicted_metrics.map((t,l)=>e.jsxs("div",{className:"flex items-center justify-between border rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:t.metric}),e.jsx("span",{className:"text-muted-foreground",children:t.forecast}),e.jsx(p,{variant:"outline",className:f(t.confidence),children:t.confidence})]},l))})]}),s.recommendations?.length>0&&e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"text-xs uppercase text-muted-foreground mb-1",children:"Recommendations"}),e.jsx("ul",{className:"list-disc pl-5 space-y-1",children:s.recommendations.map((t,l)=>e.jsx("li",{children:t},l))})]})]})}return null},y=({items:a,title:c,subtitle:i})=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:c}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i})]}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:a.map(s=>{const t=s.icon,l=x===s.key,m=!!h[s.key];return e.jsxs(J,{className:"overflow-hidden",children:[e.jsx(Q,{children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"bg-primary/10 p-2 rounded-md",children:e.jsx(t,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(Y,{className:"text-base",children:s.title}),e.jsx(Z,{children:s.desc})]}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>L(s),disabled:l||T,title:"Rerun this analysis",children:l?e.jsx(u,{className:"h-4 w-4 animate-spin"}):e.jsx(je,{className:"h-4 w-4"})})]})}),e.jsxs(ee,{className:"space-y-3",children:[s.inputs?.map(r=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(ne,{className:"text-xs",children:r.label}),r.type==="textarea"?e.jsx(ie,{rows:2,placeholder:r.placeholder,value:j[s.key]?.[r.name]||"",onChange:n=>G(s.key,r.name,n.target.value)}):e.jsx(ae,{placeholder:r.placeholder,value:j[s.key]?.[r.name]||"",onChange:n=>G(s.key,r.name,n.target.value)})]},r.name)),l&&!m&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(u,{className:"h-4 w-4 animate-spin"}),"Analyzing…"]}),!l&&!m&&e.jsx("div",{className:"text-xs text-muted-foreground italic",children:"No anal
7ysis yet."}),K(s)]})]},s.key)})})]});return e.jsxs("div",{className:"space-y-6 p-6 max-w-7xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"bg-primary/10 p-3 rounded-lg",children:e.jsx(re,{className:"h-7 w-7 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Intelligence Agent"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Consumer intelligence at AI speed, powered by GPT-5 and your real data."})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[T?e.jsxs("span",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(u,{className:"h-4 w-4 animate-spin"}),"Analyzing… ",D.done,"/",D.total," complete"]}):z?e.jsxs("span",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(u,{className:"h-4 w-4 animate-spin"}),"Fetching analyses…"]}):g?e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Last analyzed ",new Date(g).toLocaleString("en-GB")]}):null,e.jsxs($,{variant:"outline",size:"sm",onClick:q,disabled:A||Object.keys(h).length===0,children:[A?e.jsx(u,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(ce,{className:"h-4 w-4 mr-2"}),"Slide-rapport (PDF)"]})]})]}),e.jsxs(se,{defaultValue:"diagnose",children:[e.jsxs(te,{className:"grid w-full max-w-md grid-cols-3",children:[e.jsxs(b,{value:"diagnose",children:[e.jsx(_,{className:"h-4 w-4 mr-2"}),"Diagnose"]}),e.jsxs(b,{value:"generate",children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Generate"]}),e.jsxs(b,{value:"predict",children:[e.jsx(H,{className:"h-4 w-4 mr-2"}),"Predict"]})]}),e.jsx(v,{value:"diagnose",className:"mt-6",children:e.jsx(y,{items:k,title:"Diagnose",subtitle:"Reveals what really drives your market."})}),e.jsx(v,{value:"generate",className:"mt-6",children:e.jsx(y,{items:w,title:"Generate",subtitle:"Transforms insights into creative solutions."})}),e.jsx(v,{value:"predict",className:"mt-6",children:e.jsx(y,{items:C,title:"Predict",subtitle:"Visar vilken creative som kommer att lyckas."})})]})]})};export{Ee as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.