1import{e as y,r as p,d as N,u as I,j as e}from"./vendor-query-CnAhr2B8.js";import{a as A,H as w,p as T,q as R,r as q,$ as u,d as M,aT as E,s as L,B as i,ak as h,W as F,D as $,o as D}from"./index-CLUtDhnY.js";import{T as H}from"./textarea-VdIEZsUv.js";import{C as P}from"./circle-x-CDWbgxd-.js";import"./vendor-ui-CYA7SV0W.js";import"./vendor-charts-CPMWc2oJ.js";import"./vendor-forms-UY-il7MQ.js";const B=[{label:"5 LinkedIn posts (mixed types)",prompt:"Generate 5 LinkedIn posts targeting small service business owners (HVAC, plumbing, salons, restaurants). Mix content types: 1 stat-driven, 1 personal story, 1 myth-buster, 1 actionable tip, 1 question post. Each 1500-2000 chars. Skip topics covered in the last 7 days."},{label:"Launch week (3 posts)",prompt:"I'm launching SmallBizAgent on LinkedIn this week. Generate 3 LinkedIn posts: post 1 announces the launch with a personal 'I missed a $3k job to a missed call' story, post 2 explains the Free CRM tier as a no-risk trial, post 3 invites first 10 customers as design partners. Voice: direct, confident, no corporate hype. 1500-2000 chars each."},{label:"HVAC vertical push (full mix)",prompt:"Generate a coordinated HVAC content batch: 3 social posts (1 Twitter, 1 LinkedIn, 1 Facebook) about how AI receptionists help HVAC shops capture after-hours emergency calls. Plus 1 short blog post (800 words) with target keyword 'HVAC AI receptionist.' Use winner posts as style reference if available."}];function W(){const{toast:a}=A(),l=y(),[r,x]=p.useState(""),[o,d]=p.useState(null),g=N({mutationFn:async t=>await(await w("POST","/api/social-media/run-smart-agent",{prompt:t})).json(),onSuccess:t=>{d(t.runId),a({title:"Smart agent started",description:`Run #${t.runId} is now running in the background. This usually takes 15-90 seconds.`})},onError:t=>{a({title:"Couldn't start smart agent",description:(t==null?void 0:t.message)||"Run failed to start. Check server logs.",variant:"destructive"})}}),{data:s}=I({queryKey:["/api/social-media/run-smart-agent",o],queryFn:async()=>await(await w("GET",`/api/social-media/run-smart-agent/${o}`)).json(),enabled:o!==null,refetchInterval:t=>{const n=t.state.data;return n?n.status==="running"?3e3:!1:3e3},refetchIntervalInBackground:!0});p.useEffect(()=>{if(s)if(s.status==="completed"){l.invalidateQueries({queryKey:["/api/social-media/posts"]}),l.invalidateQueries({queryKey:["/api/admin/blog-posts"]}),l.invalidateQueries({queryKey:["/api/social-media/video-briefs"]});const t=s.toolCallsExecuted??0,n=s.estimatedCost??0;a({title:"Smart agent finished",description:`${t} tool call${t===1?"":"s"} ⢠~$${n.toFixed(4)}`})}else s.status==="failed"&&a({title:"Smart agent failed",description:s.errorMessage||"Run failed. Check server logs.",variant:"destructive"})},[s==null?void 0:s.runId,s==null?void 0:s.status]);const b=()=>{if(!r.trim()){a({title:"Prompt required",description:"Tell the agent what to generate.",variant:"destructive"});return}d(null),g.mutate(r)},k=t=>{x(t)},f=()=>{d(null)},j=g.isPending,c=(s==null?void 0:s.status)==="running",v=(s==null?void 0:s.status)==="completed"||(s==null?void 0:s.status)==="failed",m=j||c,C=s!=null&&s.startedAt?Math.max(0,Math.floor((Date.now()-new Date(s.startedAt).getTime())/1e3)):0;return e.jsxs(T,{children:[e.jsxs(R,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(u,{className:"h-5 w-5 text-purple-500"}),"Smart Agent (Claude Managed)",e.jsx(M,{variant:"outline",className:"text-xs",children:"On-demand"})]}),e.jsx(E,{children:"Invoke the autonomous Social Media Brain. Reads live platform stats, winner posts, and recent content, then drafts coordinated content via tool calls. Drafts appear in the approval queue below."})]}),e.jsxs(L,{className:"space-y-4",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:B.map(t=>e.jsx(i,{variant:"outline",size:"sm",onClick:()=>k(t.prompt),disabled:m,type:"button",children:t.label},t.label))}),e.jsx(H,{value:r,onChange:t=>x(t.target.value),placeholder:"Tell the agent what to generate. e.g. 'Generate 5 LinkedIn posts for HVAC business owners. Mix content types. Skip recent topics.'",rows:5,className:"font-mono text-sm",disabled:m,maxLength:4e3,"data-testid":"smart-agent-prompt"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[r.length," / 4000 chars · ~$0.05â0.10 per run"]}),e.jsx(i,{onClick:b,disabled:m||!r.trim(),"data-testid":"smart-agent-run",children:j?e.jsxs(e.Fragment,{children:[e.jsx(h,{className:"mr-2 h-4 w-4 animate-spin"}),"Startingâ¦"]}):c?e.jsxs(e.Fragment,{children:[e.jsx(h,{className:"mr-2 h-4 w-4 animate-spin"}),"Workingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(u,{className:"mr-2 h-4 w-4"}),"Run Smart Agent"]})})]}),c&&e.jsx("div",{className:"rounded-md border border-purple-200 bg-purple-50 dark:bg-purple-950/20 dark:border-purple-900 p-3 text-sm",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(h,{className:"h-4 w-4 animate-spin mt-0.5 text-purple-600 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Agent is reasoning across your data⦠(",C,"s)"]}),e.jsxs("p",{className:"text-muted-foreground mt-1",children:["Run #",s==null?void 0:s.runId,". Calling tools (winner posts, platform stats, recent content), drafting, writing to your DB. You can leave this page â the run keeps going on the server. Drafts will appear in the queue below when finished."]})]})]})}),v&&(s==null?void 0:s.status)==="completed"&&e.jsxs("div",{className:"rounded-md border bg-muted/30 p-4 space-y-3","data-testid":"smart-agent-result",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"font-semibold flex items-center gap-2",children:[e.jsx(u,{className:"h-4 w-4 text-purple-500"}),"Run #",s.runId," complete"]}),e.jsxs("div",{className:"flex gap-3 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(F,{className:"h-3 w-3"}),s.toolCallsExecuted??0," tool call",(s.toolCallsExecuted??0)===1?"":"s"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx($,{className:"h-3 w-3"}),"$",(s.estimatedCost??0).toFixed(4)]})]})]}),s.resultText?e.jsx("div",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:s.resultText}):e.jsxs("div",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(D,{className:"h-4 w-4 mt-0.5 flex-shrink-0"}),e.jsx("p",{children:"Agent finished without a text response. Check the drafts queue below for newly created content."})]}),e.jsxs("div",{className:"flex justify-between items-center text-xs text-muted-foreground border-t pt-2",children:[e.jsxs("span",{children:["Tokens: ",(s.usage.inputTokens??0).toLocaleStr
1ing()," in /"," ",(s.usage.outputTokens??0).toLocaleString()," out"]}),e.jsx(i,{variant:"ghost",size:"sm",onClick:f,children:"Clear"})]})]}),v&&(s==null?void 0:s.status)==="failed"&&e.jsxs("div",{className:"rounded-md border border-red-200 bg-red-50 dark:bg-red-950/20 dark:border-red-900 p-4 space-y-2","data-testid":"smart-agent-failed",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 text-red-600 flex-shrink-0"}),e.jsxs("h4",{className:"font-semibold text-red-700 dark:text-red-400",children:["Run #",s.runId," failed"]})]}),e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:s.errorMessage||"The agent run failed. Check server logs for details."}),e.jsx(i,{variant:"ghost",size:"sm",onClick:f,children:"Clear"})]})]})]})}export{W 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.