PageSourceSearch

https://www.dealtrail.ai/assets/PlaygroundPage-C6e_SGwg.js

js dealtrail.ai collected 2026-09-24 14:29:49 UTC 46,625 bytes, 27 lines download raw bytes

1import{s as be,b as ce,e as ue,av as es,aG as me,aH as ss,r as i,j as e,S as ze,I as A,a8 as ts,a9 as rs,h as ve,g as re,aa as as,v as I,c as S,P as Fe,C as ie,m as Ce,n as Se,ab as ns,o as ge,L as oe,D as Le,a2 as os,bp as ls,a3 as cs,x as _e,y as ye,X as Ve,l as is,w as we,E as ds,G as us,J as ms,K as xs,N as hs,T as Ae,O as ps,$ as fs,a0 as gs,a1 as js}from"./index-Cm2t7kDb.js";import{P as Ns}from"./PageLayout-BVLvt_xh.js";import{T as bs,a as vs,b as xe,c as he}from"./tabs-Cgg6vDst.js";import{S as pe}from"./skeleton-BO8Y2G0C.js";import{S as ys}from"./switch-BD_lLcmw.js";import{T as ke}from"./trash-2-CT_Sbc1a.js";import{H as Te,P as Re,u as ws,a as ks,c as Cs,i as Ss,C as Ts,B as Rs,b as $s}from"./style-CSQF72tL.js";import{P as Es}from"./pause-DRoQDaxd.js";import{R as Je}from"./rotate-ccw-BdSef4Oo.js";import{S as Os}from"./square-72_TaR9Z.js";import{S as Ps,a as Ms,b as Ds,c as zs,d as Fs}from"./select-BjkmoG7F.js";import{f as Ls}from"./index-BYuYo3sT.js";import{S as _s}from"./save-ByG45qDv.js";import{U as Vs}from"./undo-2-CJmxNT1J.js";import{R as As}from"./redo-2-CqEijlGr.js";import{C as Js}from"./chevron-up-ClFueLu7.js";import{T as Ks,a as Is,b as fe,c as q,d as Us,e as B}from"./table-BwKB9oyj.js";import{D as Bs,a as Ws,b as Hs,c as ne}from"./dropdown-menu-86XvX_ss.js";import{R as $e}from"./refresh-cw-BK8QRVfu.js";import{S as qs}from"./star-DdWk3sSV.js";import{M as Gs}from"./more-horizontal-BCATWubu.js";import{P as Ys}from"./pencil-CDulSZL1.js";import{A as Xs}from"./archive-47M-aT1D.js";import"./index-Dv-nw5np.js";import"./index-D1aO_FJ8.js";import"./index-CZdFtJ3M.js";import"./value-DqH_WevB.js";import"./with-selector-CfCISqHg.js";import"./index-DZ6tDFr9.js";/**
2 * @license lucide-react v0.294.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Zs=be("Beaker",[["path",{d:"M4.5 3h15",key:"c7n0jr"}],["path",{d:"M6 3v16a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V3",key:"m1uhx7"}],["path",{d:"M6 14h12",key:"4cwo0f"}]]);/**
7 * @license lucide-react v0.294.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Qs=be("FastForward",[["polygon",{points:"13 19 22 12 13 5 13 19",key:"587y9g"}],["polygon",{points:"2 19 11 12 2 5 2 19",key:"3pweh0"}]]);/**
12 * @license lucide-react v0.294.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const Ee=be("StepForward",[["line",{x1:"6",x2:"6",y1:"4",y2:"20",key:"fy8qot"}],["polygon",{points:"10,4 20,12 10,20",key:"1mc1pf"}]]),V="/api/admin";class D{static async getTools(){const t=await ce(`${V}/donna-tools`);return(t==null?void 0:t.tools)??t}static async executeTool(t,s){return ue(`${V}/donna-tools/execute`,{toolName:t,params:s})}static async listWorkflows(){return await ce(`${V}/workflows`)??[]}static async getWorkflow(t){return ce(`${V}/workflows/${t}`)}static async createWorkflow(t){return ue(`${V}/workflows`,t)}static async updateWorkflow(t,s){return es(`${V}/workflows/${t}`,s)}static async updateWorkflowStatus(t,s){return me(`${V}/workflows/${t}/status`,{status:s})}static async saveTestResult(t,s){return me(`${V}/workflows/${t}/test-result`,{testResult:s})}static async toggleWorkflowPin(t){return me(`${V}/workflows/${t}/pin`,{})}static async deleteWorkflow(t){return ss(`${V}/workflows/${t}`)}static async getWorkflowRevisions(t){return ce(`${V}/workflows/${t}/revisions`)}static async restoreWorkflowRevision(t,s){return ue(`${V}/workflows/${t}/revisions/${s}/restore`)}}function et({tools:r,selectedTool:t,onSelect:s}){const[l,c]=i.useState(""),n=i.useMemo(()=>{if(!l)return r;const o=l.toLowerCase();return r.filter(d=>d.name.toLowerCase().includes(o)||d.label.toLowerCase().includes(o)||d.description.toLowerCase().includes(o)||d.category.toLowerCase().includes(o))},[r,l]),a=i.useMemo(()=>{const o={};for(const d of n){const p=d.category||"general";o[p]||(o[p]=[]),o[p].push(d)}return Object.entries(o).sort(([d],[p])=>d.localeCompare(p))},[n]);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ze,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}
16),e.jsx(A,{placeholder:"Search tools...",value:l,onChange:o=>c(o.target.value),className:"pl-8"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[n.length," of ",r.length," tools"]}),e.jsx("div",{className:"space-y-1",children:a.map(([o,d])=>e.jsxs(ts,{defaultOpen:!0,children:[e.jsxs(rs,{className:"flex items-center gap-1.5 w-full text-left py-1.5 px-1 text-xs font-semibold text-muted-foreground uppercase tracking-wider hover:text-foreground group",children:[e.jsx(ve,{className:"h-3 w-3 transition-transform group-data-[state=open]:rotate-90"}),o,e.jsx(re,{variant:"secondary",className:"ml-auto text-[10px]",children:d.length})]}),e.jsx(as,{children:e.jsx("div",{className:"space-y-0.5 ml-2",children:d.map(p=>e.jsx("button",{onClick:()=>s(p.name),className:`w-full text-left px-2 py-1.5 rounded-md text-sm transition-colors ${t===p.name?"bg-primary text-primary-foreground":"hover:bg-muted"}`,children:e.jsx("div",{className:"font-mono text-xs truncate",children:p.name})},p.name))})})]},o))})]})}function st(r){return r.type==="boolean"?"boolean":r.type==="number"||r.type==="integer"?"number":r.type==="object"&&r.additionalProperties?"record":r.type==="array"?"array":"string"}function tt(r,t){return!(t.required||[]).includes(r)}function Ke({schema:r,value:t,onChange:s,workflowMode:l}){const c=r.properties||{},n=Object.keys(c);return n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"This tool has no parameters."}):e.jsx("div",{className:"space-y-4",children:n.map(a=>{const o=c[a],d=st(o),p=tt(a,r),j=o.description||"";return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(I,{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-mono text-xs",children:a}),p&&e.jsx("span",{className:"text-muted-foreground text-[10px]",children:"(optional)"})]}),j&&e.jsx("p",{className:"text-xs text-muted-foreground",children:j}),l&&e.jsxs("p",{className:"text-[10px] text-blue-500",children:["Use ","{{source.nodeId.result.path}}"," or ","{{input.KEY}}"," for flow inputs"]}),d==="boolean"?e.jsx(ys,{checked:!!t[a],onCheckedChange:f=>s({...t,[a]:f})}):d==="number"?e.jsx(A,{type:"number",value:t[a]??"",onChange:f=>{const m=f.target.value;s({...t,[a]:m===""?void 0:Number(m)})},placeholder:o.default!==void 0?String(o.default):""}):d==="record"?e.jsx(rt,{value:t[a]||{},onChange:f=>s({...t,[a]:f})}):d==="array"?e.jsx(A,{value:t[a]?JSON.stringify(t[a]):"",onChange:f=>{try{s({...t,[a]:JSON.parse(f.target.value)})}catch{}},placeholder:"JSON array, e.g. [1, 2, 3]"}):e.jsx(A,{value:t[a]??"",onChange:f=>s({...t,[a]:f.target.value||void 0}),placeholder:o.default!==void 0?String(o.default):""})]},a)})})}function rt({value:r,onChange:t}){const[s,l]=i.useState(""),c=Object.entries(r);return e.jsxs("div",{className:"space-y-2",children:[c.map(([n,a])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{value:n,disabled:!0,className:"w-1/3 font-mono text-xs"}),e.jsx(A,{value:a,onChange:o=>t({...r,[n]:o.target.value}),className:"flex-1"}),e.jsx(S,{variant:"ghost",size:"icon",onClick:()=>{const o={...r};delete o[n],t(o)},children:e.jsx(ke,{className:"h-3 w-3"})})]},n)),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{value:s,onChange:n=>l(n.target.value),placeholder:"Key",className:"w-1/3 font-mono text-xs"}),e.jsxs(S,{variant:"outline",size:"sm",disabled:!s||s in r,onClick:()=>{t({...r,[s]:""}),l("")},children:[e.jsx(Fe,{className:"h-3 w-3 mr-1"})," Add"]})]})]})}function at({tool:r}){const[t,s]=i.useState({}),[l,c]=i.useState(!1),[n,a]=i.useState(null);if(!r)return e.jsx("div",{className:"flex items-center justify-center h-64 text-muted-foreground text-sm",children:"Select a tool from the catalog to test it."});const o=async()=>{c(!0),a(null);try{const d={};for(const[j,f]of Object.entries(t))f!==void 0&&f!==""&&(d[j]=f);const p=await D.executeTool(r.name,d);a(p)}catch(d){a({success:!1,error:d.message||"Execution failed"})}finally{c(!1)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(ie,{children:[e.jsxs(Ce,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Se,{className:"text-lg font-mono",children:r.name}),e.jsx(ns,{children:r.label})]}),e.jsx(re,{variant:"outline",children:r.category})]}),r.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:r.description})]}),e.jsxs(ge,{className:"space-y-4",children:[e.jsx(Ke,{schema:r.parameters,value:t,onChange:s}),e.jsx(S,{onClick:o,disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-4 w-4 mr-2 animate-spin"})," Executing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Le,{className:"h-4 w-4 mr-2"})," Execute"]})})]})]}),n&&e.jsxs(ie,{children:[e.jsx(Ce,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Se,{className:"text-sm",children:"Result"}),e.jsxs("div",{className:"flex items-center gap-2",children:[n.durationMs!==void 0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[n.durationMs,"ms"]}),e.jsx(re,{variant:n.success?"default":"destructive",children:n.success?"Success":"Error"})]})]})}),e.jsx(ge,{children:n.error?e.jsx("pre",{className:"text-sm text-red-600 dark:text-red-400 whitespace-pre-wrap font-mono bg-red-50 dark:bg-red-950/20 p-3 rounded-md overflow-auto max-h-96",children:n.error}):e.jsx("pre",{className:"text-sm whitespace-pre-wrap font-mono bg-muted p-3 rounded-md overflow-auto max-h-96",children:JSON.stringify(n.result,null,2)})})]})]})}function nt({tools:r}){const[t,s]=i.useState(""),l=r.filter(a=>a.name.toLowerCase().includes(t.toLowerCase())||a.label.toLowerCase().includes(t.toLowerCase())||a.category.toLowerCase().includes(t.toLowerCase())),c=l.reduce((a,o)=>{const d=o.category||"general";return a[d]||(a[d]=[]),a[d].push(o),a},{}),n=(a,o)=>{a.dataTransfer.setData("application/reactflow-tool",JSON.stringify(o)),a.dataTransfer.effectAllowed="move"};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ze,{className:"absolute left-2.5 top-2.5 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(A,{value:t,onChange:a=>s(a.target.value),placeholder:"Search tools...",className:"h-8 pl-8 text-xs"})]}),e.jsxs("div",{className:"space-y-3 overflow-y-auto pr-1",children:[Object.entries(c).sort(([a],[o])=>a.localeCompare(o)).map(([a,o])=>e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase text-muted-foreground mb-1.5 tracking-wider",children:a.replace(/_/g," ")}),e.jsx("div",{className:"space-y-1",children:o.map(d=>e.jsxs("div",{draggable:!0,onDragStart:p=>n(p,d),className:`flex items-center gap-1.5 px-2 py-1.5 rounded-md border border-transparent
17                               hover:border-gray-200 dark:hover:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-800/50
18                               cursor-grab active:cursor-grabbing select-none transition-colors`,title:d.description,children:[e.jsx(os,{className:"h-3 w-3 text-muted-foreground
18/50 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-mono text-[11px] font-medium truncate",children:d.name}),d.label!==d.name&&e.jsx("p",{className:"text-[10px] text-muted-foreground truncate",children:d.label})]})]},d.name))})]},a)),l.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"No tools match."})]})]})}const Oe={deal_lookup:"border-blue-400",document_search:"border-purple-400",communication:"border-green-400",envelope:"border-amber-400",template_design:"border-pink-400",timeline:"border-cyan-400",zipform:"border-orange-400",offer:"border-red-400",paperwork:"border-teal-400",general:"border-gray-400"};function ot({status:r}){switch(r){case"idle":return e.jsx(ye,{className:"h-3.5 w-3.5 text-muted-foreground"});case"running":return e.jsx(oe,{className:"h-3.5 w-3.5 animate-spin text-blue-500"});case"done":return e.jsx(_e,{className:"h-3.5 w-3.5 text-green-500"});case"failed":return e.jsx(cs,{className:"h-3.5 w-3.5 text-red-500"});case"paused":return e.jsx(Es,{className:"h-3.5 w-3.5 text-amber-500"})}}function lt({data:r,selected:t}){const s=r,l=s.missing?"border-red-500 border-dashed":Oe[s.category]||Oe.general;return e.jsxs("div",{className:`
19        rounded-lg border-2 bg-white dark:bg-gray-900 shadow-sm px-3 py-2 min-w-[180px] max-w-[240px]
20        ${l}
21        ${s.status==="paused"?"ring-2 ring-amber-400 ring-offset-1 animate-pulse":t?"ring-2 ring-blue-500 ring-offset-1":""}
22        ${s.status==="running"?"animate-pulse":""}
23      `,children:[e.jsx(Te,{type:"target",position:Re.Top,className:"!bg-gray-400 !border-gray-500 !w-2.5 !h-2.5"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ls,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"font-mono text-xs font-semibold truncate flex-1",children:s.toolName}),e.jsx(ot,{status:s.status})]}),s.missing&&e.jsx("p",{className:"text-[10px] text-red-500 font-semibold mt-1",children:"Tool not in manifest"}),s.label&&s.label!==s.toolName&&e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1 truncate",children:s.label}),s.status==="done"&&s.durationMs!==void 0&&e.jsxs("p",{className:"text-[10px] text-green-600 dark:text-green-400 mt-0.5",children:[s.durationMs,"ms"]}),s.status==="failed"&&s.error&&e.jsx("p",{className:"text-[10px] text-red-500 mt-0.5 truncate",children:s.error}),e.jsx(Te,{type:"source",position:Re.Bottom,className:"!bg-gray-400 !border-gray-500 !w-2.5 !h-2.5"})]})}const ct=i.memo(lt);function it({node:r,tools:t,onUpdate:s,onClose:l,onRunFromNode:c,onDelete:n}){const a=r.data,o=t.find(d=>d.name===a.toolName);return e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Node Configuration"}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:l,children:e.jsx(Ve,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{className:"text-xs",children:"Tool"}),e.jsx("p",{className:"font-mono text-xs bg-muted px-2 py-1 rounded",children:a.toolName})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{className:"text-xs",children:"Label"}),e.jsx(A,{value:a.label,onChange:d=>s(r.id,{label:d.target.value}),placeholder:"Describe what this step does",className:"h-8 text-sm"})]}),o&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{className:"text-xs",children:"Parameters"}),e.jsxs("p",{className:"text-[10px] text-blue-500 mb-1",children:["Use ","{{source.nodeId.result.path}}"," or ","{{input.KEY}}"," for flow inputs"]}),e.jsx(Ke,{schema:o.parameters,value:a.params,onChange:d=>s(r.id,{params:d}),workflowMode:!0})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>c(r.id),children:[e.jsx(Je,{className:"h-3.5 w-3.5 mr-1"})," Run from here"]}),n&&e.jsxs(S,{variant:"outline",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-950/20",onClick:()=>n(r.id),children:[e.jsx(ke,{className:"h-3.5 w-3.5 mr-1"})," Delete"]})]}),a.status==="done"&&a.result&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{className:"text-xs",children:"Result"}),e.jsx("pre",{className:"text-xs whitespace-pre-wrap font-mono bg-muted p-2 rounded overflow-auto max-h-32",children:JSON.stringify(a.result,null,2)})]}),a.status==="failed"&&a.error&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{className:"text-xs",children:"Error"}),e.jsx("pre",{className:"text-xs text-red-600 dark:text-red-400 whitespace-pre-wrap font-mono bg-red-50 dark:bg-red-950/20 p-2 rounded overflow-auto max-h-32",children:a.error})]})]})}function Pe(r,t){const s={},l={};for(const a of r)s[a.id]=0,l[a.id]=[];for(const a of t)l[a.source]&&l[a.source].push(a.target),s[a.target]=(s[a.target]||0)+1;const c=Object.keys(s).filter(a=>s[a]===0),n=[];for(;c.length>0;){const a=c.shift();n.push(a);for(const o of l[a]||[])s[o]--,s[o]===0&&c.push(o)}return n}function dt(r,t){const s=new Set([r]),l={};for(const n of t)l[n.source]||(l[n.source]=[]),l[n.source].push(n.target);const c=[r];for(;c.length>0;){const n=c.shift();for(const a of l[n]||[])s.has(a)||(s.add(a),c.push(a))}return s}function Me(r,t,s={}){const l={},c=[];for(const[n,a]of Object.entries(r)){if(typeof a!="string"){l[n]=a;continue}const o=/\{\{source\.[^}]+\}\}/.test(a),d=/\{\{input\.[^}]+\}\}/.test(a);if(!o&&!d){l[n]=a;continue}const p=a.match(/^\{\{source\.([^.]+)\.(.*?)\}\}$/);if(p){const[,m,x]=p,v=t[m];
23if(v!=null){let N=v;for(const u of x.split(".")){if(N==null)break;N=N[u]}if(N!==void 0){l[n]=N,c.push({param:n,template:a,resolvedValue:typeof N=="object"?JSON.stringify(N):String(N)});continue}}l[n]=a;continue}const j=a.match(/^\{\{input\.(.+?)\}\}$/);if(j){const[,m]=j,x=s[m];if(x!==void 0){l[n]=x,c.push({param:n,template:a,resolvedValue:typeof x=="object"?JSON.stringify(x):String(x)});continue}l[n]=a;continue}let f=a;f=f.replace(/\{\{source\.([^.]+)\.(.*?)\}\}/g,(m,x,v)=>{const N=t[x];if(!N)return m;let u=N;for(const E of v.split(".")){if(u==null)break;u=u[E]}const b=u!==void 0?typeof u=="object"?JSON.stringify(u):String(u):m;return c.push({param:n,template:m,resolvedValue:b}),b}),f=f.replace(/\{\{input\.(.+?)\}\}/g,(m,x)=>{const v=s[x];if(v===void 0)return m;const N=typeof v=="object"?JSON.stringify(v):String(v);return c.push({param:n,template:m,resolvedValue:N}),N}),l[n]=f}return{resolved:l,resolutions:c}}function ut({nodes:r,edges:t,flowInputs:s,onNodeStatusChange:l,onResetStatuses:c,onDebugStep:n,onPausedNodeChange:a,runFromNodeId:o,onRunFromNodeConsumed:d}){const[p,j]=i.useState(!1),[f,m]=i.useState(!1),x=i.useRef(null),v=i.useRef(!1),N=i.useRef(!1),u=i.useRef(r);u.current=r;const b=i.useRef({}),E=i.useCallback(()=>v.current||N.current?Promise.resolve():new Promise(g=>{x.current=g}),[]),C=i.useCallback(()=>{var g;(g=x.current)==null||g.call(x),x.current=null},[]),M=i.useCallback(()=>{var g;v.current=!0,(g=x.current)==null||g.call(x),x.current=null},[]),W=i.useCallback(()=>{var g;N.current=!0,(g=x.current)==null||g.call(x),x.current=null},[]),se=async()=>{const g=u.current;if(g.length===0)return;j(!0),c(),b.current={};const Y=Pe(g,t);for(const z of Y){const R=u.current.find(y=>y.id===z);if(!R)continue;const F=R.data;l(z,"running");try{const{resolved:y}=Me(F.params,b.current,s),X={};for(const[L,_]of Object.entries(y))_!==void 0&&_!==""&&(X[L]=_);const J=await D.executeTool(F.toolName,X);if(J.success)b.current[z]=J.result,l(z,"done",J.result,J.durationMs);else{l(z,"failed",void 0,J.durationMs,J.error||"Execution failed");break}}catch(y){l(z,"failed",void 0,void 0,y.message||"Execution failed");break}}j(!1)},G=async g=>{const Y=u.current;if(Y.length===0)return;m(!0),j(!0),v.current=!1,N.current=!1;const z=Pe(Y,t);let R=0;if(g){const F=dt(g,t);for(const y of F)delete b.current[y],l(y,"idle");R=z.indexOf(g),R<0&&(R=0)}else b.current={},c();for(let F=R;F<z.length;F++){const y=z[F];if(N.current)break;const X=u.current.find(K=>K.id===y);if(!X)continue;const J=X.data;if(l(y,"paused"),a==null||a(y),n==null||n({nodeId:y,toolName:J.toolName,rawParams:{...J.params},resolvedParams:{},templateResolutions:[],phase:"before"}),await E(),N.current)break;const L=u.current.find(K=>K.id===y);if(!L)continue;const _=L.data,Z={..._.params},{resolved:de,resolutions:ae}=Me(_.params,b.current,s),Q={};for(const[K,$]of Object.entries(de))$!==void 0&&$!==""&&(Q[K]=$);l(y,"running");try{const K=performance.now(),$=await D.executeTool(_.toolName,Q),te=Math.round(performance.now()-K);if($.success)b.current[y]=$.result,l(y,"done",$.result,$.durationMs??te),v.current||(n==null||n({nodeId:y,toolName:_.toolName,rawParams:Z,resolvedParams:Q,templateResolutions:ae,result:$.result,durationMs:$.durationMs??te,phase:"after"}),await E());else{const le=$.error||"Execution failed";l(y,"failed",void 0,$.durationMs??te,le),n==null||n({nodeId:y,toolName:_.toolName,rawParams:Z,resolvedParams:Q,templateResolutions:ae,error:le,durationMs:$.durationMs??te,phase:"after"});break}}catch(K){const $=K.message||"Execution failed";l(y,"failed",void 0,void 0,$),n==null||n({nodeId:y,toolName:_.toolName,rawParams:Z,resolvedParams:Q,templateResolutions:ae,error:$,phase:"after"});break}}n==null||n(null),a==null||a(null),m(!1),j(!1)};return i.useEffect(()=>{o&&!p&&(d==null||d(),G(o))},[o]),e.jsx("div",{className:"flex items-center gap-1.5",children:f?e.jsxs(e.Fragment,{children:[e.jsxs(S,{onClick:C,size:"sm",children:[e.jsx(Ee,{className:"h-4 w-4 mr-1"})," Step"]}),e.jsxs(S,{onClick:M,size:"sm",variant:"outline",children:[e.jsx(Qs,{className:"h-4 w-4 mr-1"})," Continue"]}),e.jsxs(S,{onClick:W,size:"sm",variant:"destructive",children:[e.jsx(Os,{className:"h-4 w-4 mr-1"})," Stop"]})]}):e.jsxs(e.Fragment,{children:[e.jsx(S,{onClick:se,disabled:p||r.length===0,size:"sm",children:p?e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-4 w-4 mr-1 animate-spin"})," Running..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Le,{className:"h-4 w-4 mr-1"})," Run Flow"]})}),e.jsxs(S,{onClick:()=>G(),disabled:p||r.length===0,size:"sm",variant:"outline",children:[e.jsx(Ee,{className:"h-4 w-4 mr-1"})," Step Through"]})]})})}function mt({data:r,label:t}){const[s,l]=i.useState(!1),c=JSON.stringify(r,null,2),n=c.split(`
24`).length,a=n>8;return e.jsxs("div",{children:[a?e.jsxs("button",{type:"button",className:"flex items-center gap-1 text-xs font-medium text-muted-foreground hover:text-foreground mb-1",onClick:()=>l(!s),children:[s?e.jsx(we,{className:"h-3 w-3"}):e.jsx(ve,{className:"h-3 w-3"}),t," (",n," lines)"]}):e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:t}),e.jsx("pre",{className:`text-xs font-mono bg-gray-100 dark:bg-gray-800 rounded p-2 overflow-x-auto ${a&&!s?"max-h-[160px] overflow-y-hidden":"max-h-[400px] overflow-y-auto"}`,children:c})]})}function xt({debugInfo:r}){const t=r.phase==="before",s=r.phase==="after"&&!!r.error;return e.jsxs("div",{className:`border rounded-lg p-3 space-y-3 ${s?"border-red-300 dark:border-red-800 bg-red-50/50 dark:bg-red-950/20":t?"border-amber-300 dark:border-amber-800 bg-amber-50/50 dark:bg-amber-950/20":"border-green-300 dark:border-green-800 bg-green-50/50 dark:bg-green-950/20"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${s?"bg-red-100 dark:bg-red-900 text-red-700 dark:text-red-300":t?"bg-amber-100 dar
24k:bg-amber-900 text-amber-700 dark:text-amber-300":"bg-green-100 dark:bg-green-900 text-green-700 dark:text-green-300"}`,children:s?"Failed":t?"Paused":"Completed"}),e.jsx("span",{className:"font-mono text-sm font-semibold",children:r.toolName}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",r.nodeId,")"]})]}),r.durationMs!==void 0&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(ye,{className:"h-3 w-3"}),r.durationMs,"ms"]})]}),t&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Input Params"}),Object.keys(r.resolvedParams).length===0?e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"No parameters"}):e.jsx("div",{className:"space-y-1",children:Object.entries(r.resolvedParams).map(([l,c])=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("span",{className:"font-mono text-xs font-medium text-foreground shrink-0",children:[l,":"]}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground break-all",children:typeof c=="object"?JSON.stringify(c):String(c)})]},l))}),r.templateResolutions.length>0&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Template Resolutions"}),r.templateResolutions.map((l,c)=>e.jsxs("div",{className:"text-xs font-mono flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"text-amber-600 dark:text-amber-400",children:l.template}),e.jsx("span",{className:"text-muted-foreground",children:"→"}),e.jsxs("span",{className:"text-green-600 dark:text-green-400 break-all",children:['"',l.resolvedValue,'"']})]},c))]}),e.jsx("p",{className:"text-[10px] text-muted-foreground italic",children:"Click Step to execute this tool"})]}),r.phase==="after"&&!r.error&&r.result!==void 0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(mt,{data:r.result,label:"Output"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["Downstream nodes can reference via"," ",e.jsxs("code",{className:"bg-gray-200 dark:bg-gray-700 px-1 rounded",children:["{{","source.",r.nodeId,".result.*","}}"]})]})]}),r.phase==="after"&&r.error&&e.jsxs("div",{className:"flex items-start gap-2 text-red-600 dark:text-red-400",children:[e.jsx(is,{className:"h-4 w-4 shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs font-mono break-all",children:r.error})]})]})}const ht=["deal_lookup","document_search","communication","envelope","template_design","timeline","zipform","offer","general"];function Ie({open:r,onOpenChange:t,workflow:s,initialSteps:l,initialInstructions:c,initialGraph:n,onSaved:a}){const[o,d]=i.useState(""),[p,j]=i.useState(""),[f,m]=i.useState(""),[x,v]=i.useState("general"),[N,u]=i.useState(""),[b,E]=i.useState(!1),[C,M]=i.useState(""),W=!!s;i.useEffect(()=>{r&&(s?(d(s.name),j(s.slug),m(s.description||""),v(s.category||"general"),u(c??s.instructions)):(d(""),j(""),m(""),v("general"),u(c||"")),M(""))},[r,s,c]);const se=g=>{d(g),W||j(g.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},G=async()=>{if(!o||!p){M("Name and slug are required");return}E(!0),M("");try{W?await D.updateWorkflow(s.id,{name:o,slug:p,description:f,category:x,instructions:N,...n?{graph:n}:{}}):await D.createWorkflow({name:o,slug:p,description:f,category:x,steps:l||[],instructions:N,...n?{graph:n}:{}}),a()}catch(g){M(g.message||"Failed to save")}finally{E(!1)}};return e.jsx(ds,{open:r,onOpenChange:t,children:e.jsxs(us,{className:"max-w-lg",children:[e.jsxs(ms,{children:[e.jsx(xs,{children:W?"Edit Workflow":"Save Workflow"}),e.jsx(hs,{children:W?"Update workflow template details.":"Save this workflow as a reusable template."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{children:"Name"}),e.jsx(A,{value:o,onChange:g=>se(g.target.value),placeholder:"e.g. Create Listing via zipForm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{children:"Slug"}),e.jsx(A,{value:p,onChange:g=>j(g.target.value),placeholder:"create-listing-zipform",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{children:"Description"}),e.jsx(A,{value:f,onChange:g=>m(g.target.value),placeholder:"Optional description"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{children:"Category"}),e.jsxs(Ps,{value:x,onValueChange:v,children:[e.jsx(Ms,{children:e.jsx(Ds,{})}),e.jsx(zs,{children:ht.map(g=>e.jsx(Fs,{value:g,children:g},g))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{children:"Instructions (injected into system prompt when approved)"}),e.jsx(Ae,{value:N,onChange:g=>u(g.target.value),placeholder:"Markdown instructions for Donna...",rows:8,className:"font-mono text-xs"})]}),C&&e.jsx("p",{className:"text-sm text-red-500",children:C})]}),e.jsxs(ps,{children:[e.jsx(S,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsxs(S,{onClick:G,disabled:b,children:[b&&e.jsx(oe,{className:"h-4 w-4 mr-2 animate-spin"}),W?"Update":"Save"]})]})]})})}function Ue(r,t){const s=new Set,l=[],c=/\b([a-z][a-z0-9]*(?:_[a-z0-9]+)+)\b/g;let n;for(;(n=c.exec(r))!==null;){const a=n[1];t.has(a)&&!s.has(a)&&(s.add(a),l.push(a))}return l}function pt(r,t,s,l){const c=i.useRef([]),n=i.useRef([]),a=i.useRef(0),o=i.useCallback(()=>{c.current=[...c.current.slice(-49),{nodes:structuredClone(r),edges:structuredClone(t)}],n.current=[],a.current++},[r,t]),d=i.useCallback(()=>{const m=c.current.pop();m&&(n.current.push({nodes:structuredClone(r),edges:structuredClone(t)}),s(m.nodes),l(m.edges),a.current++)},[r,t,s,l]),p=i.useCallback(()=>{const m=n.current.pop();m&&(c.current.push({nodes:structuredClone(r),edges:structuredClone(t)}),s(m.nodes),l(m.edges),a.current++)},[r,t,s,l]),j=c.current.length>0,f=n.current.length>0;return{takeSnapshot:o,undo:d,redo:p,canUndo:j,canRedo:f}}function ft({workflowId:r,currentVersion:t,onRestore:s,onClose:l}){const[c,n]=i.useState([]),[a,o]=i.useState(!0),[d,p]=i.useState(null),j=i.useCallback(async()=>{try{o(!0);const m=await D.getWorkflowRevisions(r);n(Array.isArray(m)?m:[])}catch(m){console.error("Failed to load revisions:",m)}finally{o(!1)}},[r]);i.useEffect(()=>{j()},[j]);const f=async m=>{if(confirm("Restore this version? The current state will be saved as a new version first."))try{p(m),await D.restoreWorkflowRevision(r,m),s()}catch(x){console.error("Failed to restore revision:",x)}finally{p(null)}};return e.jsxs("div",{className:"p-3 flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Version History"}),e.jsx("button",{type:"button",onClick:l,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ve,{className:"h-4 w-4"})})]}),a?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading..."}):c.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No saved versions yet. Save the workflow to create the first snapshot."}):e.jsx("div",{className:"flex flex-col gap-1.5 overflow-y-auto min-h-0",children:c.map(m=>{const x=m.version===t;return e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${x?"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800":"hover:bg-muted/50"}`,children:[e.jsxs("span",{className:"font-mono font-semibold shrink-0",children:["v",m.version]}),e.jsx("span",{className:"text-muted-foreground truncate flex-1",children:Ls(new Date(m.created_at),{addSuffix:!0})}
24),x?e.jsx("span",{className:"text-[10px] text-blue-600 dark:text-blue-400 font-medium shrink-0",children:"current"}):e.jsxs(S,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-xs",disabled:d===m.id,onClick:()=>f(m.id),children:[e.jsx(Je,{className:"h-3 w-3 mr-1"}),d===m.id?"...":"Restore"]})]},m.id)})})]})}const gt={toolNode:ct};let je=0;function Ne(){return`tool-${++je}`}function Be(r,t){var a;const s={},l={};for(const o of r)s[o.id]=0,l[o.id]=[];for(const o of t)(a=l[o.source])==null||a.push(o.target),s[o.target]=(s[o.target]||0)+1;const c=Object.keys(s).filter(o=>s[o]===0),n=[];for(;c.length>0;){const o=c.shift();n.push(o);for(const d of l[o]||[])s[d]--,s[d]===0&&c.push(d)}return n.map((o,d)=>{const p=r.find(f=>f.id===o),j=(p==null?void 0:p.data)||{};return{stepIndex:d,toolName:j.toolName||"",params:j.params||{},label:j.label||""}})}function jt(r,t){const s=Be(r,t);return s.length===0?"":s.map((c,n)=>{const a=Object.entries(c.params).filter(([,o])=>o!==void 0&&o!=="").map(([o,d])=>`${o}: ${typeof d=="string"&&d.startsWith("{{")?d:JSON.stringify(d)}`).join(", ");return`${n+1}. \`${c.toolName}${a?`(${a})`:""}\` -- ${c.label}`}).join(`
25`)}function Nt(r,t){return r.map((s,l)=>{const c=t==null?void 0:t.get(s.toolName);return{id:Ne(),type:"toolNode",position:{x:250,y:l*120},data:{toolName:s.toolName,label:s.label||(c==null?void 0:c.label)||s.toolName,category:(c==null?void 0:c.category)||"general",status:"idle",params:s.params||{},missing:t?!c:!1}}})}function De(r){const t=[];for(let s=0;s<r.length-1;s++)t.push({id:`e-${r[s].id}-${r[s+1].id}`,source:r[s].id,target:r[s+1].id,animated:!0});return t}function bt({tools:r,editingWorkflow:t,onWorkflowSaved:s,onClearEditing:l}){const[c,n,a]=ws([]),[o,d,p]=ks([]),[j,f]=i.useState(null),[m,x]=i.useState(!1),[v,N]=i.useState(""),[u,b]=i.useState(!1),[E,C]=i.useState(null),[M]=i.useState({}),[W,se]=i.useState(null),[G,g]=i.useState(!1),Y=i.useRef(null),z=i.useRef(null),{takeSnapshot:R,undo:F,redo:y,canUndo:X,canRedo:J}=pt(c,o,n,d);i.useEffect(()=>{var h,w;if(t){if(t.graph&&((h=t.graph.nodes)==null?void 0:h.length)>0){const k=new Map(r.map(P=>[P.name,P])),O=t.graph.nodes.map(P=>{var ee;const T=(ee=P.data)==null?void 0:ee.toolName;return T&&k.size>0&&!k.has(T)?{...P,data:{...P.data,missing:!0}}:P});n(O),d(t.graph.edges||[]),je=t.graph.nodes.reduce((P,T)=>{var H;const ee=(H=T.id)==null?void 0:H.match(/^tool-(\d+)$/);return ee?Math.max(P,parseInt(ee[1],10)):P},je)}else if(((w=t.steps)==null?void 0:w.length)>0){const k=new Map(r.map(U=>[U.name,U])),O=Nt(t.steps,k);n(O),d(De(O))}else if(t.instructions&&r.length>0){const k=new Set(r.map(T=>T.name)),O=Ue(t.instructions,k),U=new Map(r.map(T=>[T.name,T])),P=O.map((T,ee)=>{const H=U.get(T);return{id:Ne(),type:"toolNode",position:{x:250,y:ee*120},data:{toolName:T,label:(H==null?void 0:H.label)||T,category:(H==null?void 0:H.category)||"general",status:"idle",params:{}}}});n(P),d(De(P))}else n([]),d([]);N(t.instructions||""),b(!0),f(null)}},[t,n,d,r]);const L=!!t,_=i.useCallback(()=>{n([]),d([]),N(""),b(!1),f(null),l==null||l()},[n,d,l]),Z=c.find(h=>h.id===j)||null,de=i.useCallback(h=>{R(),d(w=>Cs({...h,animated:!0},w))},[d,R]),ae=i.useCallback(h=>{h.preventDefault(),h.dataTransfer.dropEffect="move"},[]),Q=i.useCallback(h=>{h.preventDefault();const w=h.dataTransfer.getData("application/reactflow-tool");if(!w)return;const k=JSON.parse(w),O=Y.current;if(!O)return;const U=O.screenToFlowPosition({x:h.clientX,y:h.clientY});R();const P={id:Ne(),type:"toolNode",position:U,data:{toolName:k.name,label:k.label||k.name,category:k.category||"general",status:"idle",params:{}}};n(T=>[...T,P])},[n,R]),K=i.useCallback((h,w)=>{f(w.id)},[]),$=i.useCallback(()=>{f(null)},[]),te=i.useCallback((h,w)=>{n(k=>k.map(O=>O.id===h?{...O,data:{...O.data,...w}}:O))},[n]),le=i.useCallback(()=>{j&&(R(),n(h=>h.filter(w=>w.id!==j)),d(h=>h.filter(w=>w.source!==j&&w.target!==j)),f(null))},[j,n,d,R]),We=i.useCallback(h=>{h.some(k=>k.type==="position"&&"dragging"in k&&k.dragging===!1)&&R(),a(h)},[a,R]),He=i.useCallback(h=>{h.some(k=>k.type==="remove")&&R(),p(h)},[p,R]),qe=i.useCallback(h=>{(h.metaKey||h.ctrlKey)&&h.key==="z"&&(h.preventDefault(),h.shiftKey?y():F())},[F,y]),Ge=i.useCallback(()=>{g(!1),s==null||s()},[s]),Ye=i.useCallback((h,w,k,O,U)=>{n(P=>P.map(T=>T.id===h?{...T,data:{...T.data,status:w,...k!==void 0?{result:k}:{},...O!==void 0?{durationMs:O}:{},...U!==void 0?{error:U}:{}}}:T))},[n]),Xe=i.useCallback(h=>{h&&f(h)},[]),Ze=i.useCallback(()=>{n(h=>h.map(w=>({...w,data:{...w.data,status:"idle",result:void 0,durationMs:void 0,error:void 0}})))},[n]),Qe=v||jt(c,o);return e.jsxs("div",{className:"flex flex-col outline-none",style:{height:"calc(100vh - 160px)"},tabIndex:0,onKeyDown:qe,ref:z,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3 shrink-0",children:[L&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex items-center gap-3 px-3 py-1.5 bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 rounded-lg mr-auto min-w-0",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:t.name}),e.jsx("span",{className:"text-xs text-muted-foreground font-mono shrink-0",children:t.slug})]})}),(c.length>0||L)&&e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>x(!0),children:[e.jsx(_s,{className:"h-4 w-4 mr-1"})," Save Workflow"]}),e.jsx(S,{variant:"ghost",size:"sm",onClick:F,disabled:!X,title:"Undo (Cmd+Z)",children:e.jsx(Vs,{className:"h-4 w-4"})}),e.jsx(S,{variant:"ghost",size:"sm",onClick:y,disabled:!J,title:"Redo (Cmd+Shift+Z)",children:e.jsx(As,{className:"h-4 w-4"})}),L&&e.jsx(S,{variant:G?"secondary":"ghost",size:"sm",onClick:()=>g(h=>!h),title:"Version History",children:e.jsx(ye,{className:"h-4 w-4"})}
25),e.jsx(ut,{nodes:c,edges:o,flowInputs:M,runFromNodeId:W,onRunFromNodeConsumed:()=>se(null),onNodeStatusChange:Ye,onResetStatuses:Ze,onDebugStep:C,onPausedNodeChange:Xe}),L&&e.jsxs(S,{variant:"outline",size:"sm",onClick:_,className:"ml-auto",children:[e.jsx(Fe,{className:"h-3.5 w-3.5 mr-1"})," New Workflow"]})]}),e.jsx("div",{className:"shrink-0 mb-3",children:u?e.jsxs("div",{className:"border rounded-lg max-h-[200px] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 shrink-0",children:[e.jsxs("span",{className:"text-sm font-medium",children:["Instructions ",v?`(${v.split(`
26`).length} lines)`:""]}),e.jsx("button",{type:"button",className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>b(!1),children:e.jsx(Js,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"px-3 pb-3 overflow-y-auto min-h-0",children:e.jsx(Ae,{value:v,onChange:h=>N(h.target.value),placeholder:"Markdown instructions for this workflow...",rows:6,className:"font-mono text-xs"})})]}):e.jsxs("button",{type:"button",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground",onClick:()=>b(!0),children:[e.jsx(we,{className:"h-4 w-4"}),"Show Instructions ",v?`(${v.split(`
27`).length} lines)`:""]})}),e.jsxs("div",{className:`flex-1 min-h-0 grid grid-cols-1 gap-3 ${Z||G&&L?"lg:grid-cols-[200px_1fr_300px]":"lg:grid-cols-[200px_1fr]"}`,children:[e.jsxs("div",{className:"border rounded-lg p-2 overflow-y-auto min-h-0",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase text-muted-foreground mb-2 tracking-wider",children:"Drag tools onto canvas"}),e.jsx(nt,{tools:r})]}),e.jsxs("div",{className:"flex flex-col min-h-0 gap-3",children:[e.jsx("div",{className:"border rounded-lg bg-gray-50 dark:bg-gray-950 flex-1 min-h-0",children:e.jsxs(Ss,{nodes:c,edges:o,onNodesChange:We,onEdgesChange:He,onConnect:de,onDrop:Q,onDragOver:ae,onNodeClick:K,onPaneClick:$,onInit:h=>{Y.current=h},nodeTypes:gt,fitView:!0,deleteKeyCode:["Backspace","Delete"],children:[e.jsx(Ts,{}),e.jsx(Rs,{variant:$s.Dots,gap:16,size:1})]})}),E&&e.jsx("div",{className:"shrink-0 max-h-[150px] overflow-y-auto",children:e.jsx(xt,{debugInfo:E})})]}),Z?e.jsx("div",{className:"border rounded-lg overflow-y-auto min-h-0",children:e.jsx(it,{node:Z,tools:r,onUpdate:te,onClose:()=>f(null),onRunFromNode:se,onDelete:le})}):G&&L?e.jsx("div",{className:"border rounded-lg overflow-y-auto min-h-0",children:e.jsx(ft,{workflowId:t.id,currentVersion:t.version,onRestore:Ge,onClose:()=>g(!1)})}):null]}),e.jsx(Ie,{open:m,onOpenChange:x,workflow:L?t:void 0,initialSteps:Be(c,o),initialInstructions:Qe,initialGraph:{nodes:c,edges:o},onSaved:()=>{x(!1),s==null||s()}})]})}const vt={draft:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300",testing:"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300",approved:"bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300",archived:"bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300"};function yt({tools:r}){return r.length===0?e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"No tool chain — guidance only"}):e.jsx("div",{className:"flex flex-wrap items-center gap-1",children:r.map((t,s)=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"inline-block rounded-full bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200 px-2.5 py-0.5 text-[11px] font-mono whitespace-nowrap",children:t}),s<r.length-1&&e.jsx("span",{className:"text-muted-foreground text-xs select-none",children:"→"})]},t))})}function wt({refreshKey:r,onEditWorkflow:t}){const[s,l]=i.useState([]),[c,n]=i.useState(!0),[a,o]=i.useState(null),[d,p]=i.useState(new Set),[j,f]=i.useState(new Set),m=i.useCallback(async()=>{n(!0);try{const u=await D.listWorkflows();l(Array.isArray(u)?u:[])}catch(u){console.error("Failed to load workflows:",u)}finally{n(!1)}},[]);i.useEffect(()=>{m()},[m,r]),i.useEffect(()=>{D.getTools().then(u=>{f(new Set(u.map(b=>b.name)))}).catch(u=>console.error("Failed to load tools:",u))},[]);const x=async(u,b)=>{try{await D.updateWorkflowStatus(u,b),m()}catch(E){console.error("Failed to update status:",E)}},v=u=>{l(b=>{const E=b.map(C=>C.id===u?{...C,is_pinned:!C.is_pinned}:C);return E.sort((C,M)=>C.is_pinned!==M.is_pinned?C.is_pinned?-1:1:C.sort_order-M.sort_order),E}),D.toggleWorkflowPin(u).catch(b=>{console.error("Failed to toggle pin:",b),m()})},N=async u=>
27{if(confirm("Delete this workflow template?"))try{await D.deleteWorkflow(u),m()}catch(b){console.error("Failed to delete:",b)}};return c?e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(oe,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s.length," workflow",s.length!==1?"s":""]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:m,children:[e.jsx($e,{className:"h-3.5 w-3.5 mr-1"})," Refresh"]})]}),s.length===0?e.jsx(ie,{children:e.jsx(ge,{className:"flex items-center justify-center h-32 text-muted-foreground text-sm",children:"No workflows yet. Build and save one from the Workflow Builder tab."})}):e.jsx(ie,{children:e.jsxs(Ks,{children:[e.jsx(Is,{children:e.jsxs(fe,{children:[e.jsx(q,{className:"w-[36px]"}),e.jsx(q,{className:"w-[52px]",children:"Type"}),e.jsx(q,{children:"Name"}),e.jsx(q,{children:"Slug"}),e.jsx(q,{children:"Category"}),e.jsx(q,{children:"Status"}),e.jsx(q,{children:"Version"}),e.jsx(q,{children:"Last Tested"}),e.jsx(q,{className:"w-[50px]"})]})}),e.jsx(Us,{children:s.map(u=>{const b=d.has(u.id),E=b?Ue(u.instructions||"",j):[];return e.jsxs(i.Fragment,{children:[e.jsxs(fe,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>p(C=>{const M=new Set(C);return M.has(u.id)?M.delete(u.id):M.add(u.id),M}),children:[e.jsx(B,{className:"px-2",onClick:C=>C.stopPropagation(),children:e.jsx("button",{type:"button",onClick:()=>v(u.id),className:"text-muted-foreground/40 hover:text-amber-400 transition-colors",children:e.jsx(qs,{className:`h-4 w-4 ${u.is_pinned?"fill-amber-400 text-amber-400":""}`})})}),e.jsx(B,{children:e.jsx(re,{variant:"outline",className:u.workflow_type==="sub"?"text-[10px] bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400":"text-[10px] bg-blue-50 text-blue-700 dark:bg-blue-950 dark:text-blue-300",children:u.workflow_type||"main"})}),e.jsx(B,{children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[b?e.jsx(we,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}):e.jsx(ve,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),u.description?e.jsxs(fs,{children:[e.jsx(gs,{asChild:!0,children:e.jsx("span",{className:"font-medium cursor-default border-b border-dotted border-muted-foreground/40",children:u.name})}),e.jsx(js,{side:"bottom",className:"max-w-xs",children:u.description})]}):e.jsx("span",{className:"font-medium",children:u.name})]})}),e.jsx(B,{className:"font-mono text-xs",children:u.slug}),e.jsx(B,{children:u.category&&e.jsx(re,{variant:"outline",className:"text-[10px]",children:u.category})}),e.jsx(B,{children:e.jsx(re,{className:vt[u.status]||"",children:u.status})}),e.jsxs(B,{className:"text-xs text-muted-foreground",children:["v",u.version]}),e.jsx(B,{className:"text-xs text-muted-foreground",children:u.last_tested_at?new Date(u.last_tested_at).toLocaleDateString():"--"}),e.jsx(B,{onClick:C=>C.stopPropagation(),children:e.jsxs(Bs,{children:[e.jsx(Ws,{asChild:!0,children:e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7",children:e.jsx(Gs,{className:"h-4 w-4"})})}),e.jsxs(Hs,{align:"end",children:[e.jsxs(ne,{onClick:()=>t?t(u):o(u),children:[e.jsx(Ys,{className:"h-3.5 w-3.5 mr-2"})," Edit"]}),u.status!=="approved"&&e.jsxs(ne,{onClick:()=>x(u.id,"approved"),children:[e.jsx(_e,{className:"h-3.5 w-3.5 mr-2"})," Approve"]}),u.status!=="archived"&&e.jsxs(ne,{onClick:()=>x(u.id,"archived"),children:[e.jsx(Xs,{className:"h-3.5 w-3.5 mr-2"})," Archive"]}),u.status==="archived"&&e.jsxs(ne,{onClick:()=>x(u.id,"draft"),children:[e.jsx($e,{className:"h-3.5 w-3.5 mr-2"})," Unarchive"]}),e.jsxs(ne,{onClick:()=>N(u.id),className:"text-red-600 dark:text-red-400",children:[e.jsx(ke,{className:"h-3.5 w-3.5 mr-2"})," Delete"]})]})]})})]}),b&&e.jsx(fe,{children:e.jsx(B,{colSpan:9,className:"bg-muted/30 py-3 px-6",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Tool Chain"}),e.jsx(yt,{tools:E})]})})},`${u.id}-tools`)]},u.id)})})]})}),e.jsx(Ie,{open:!!a,onOpenChange:u=>{u||o(null)},workflow:a,onSaved:()=>{o(null),m()}})]})}function Qt(){const[r,t]=i.useState([]),[s,l]=i.useState(!0),[c,n]=i.useState(""),[a,o]=i.useState(null),[d,p]=i.useState(0),[j,f]=i.useState("tester"),[m,x]=i.useState(null),v=i.useCallback(u=>{x(u),f("builder")},[]);i.useEffect(()=>{D.getTools().then(u=>t(u)).catch(u=>n(u.message||"Failed to load tools")).finally(()=>l(!1))},[]);const N=r.find(u=>u.name===a)||null;return e.jsxs(Ns,{icon:Zs,title:"Donna Playground",subheader:`${r.length} tools available`,children:[c&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 dark:bg-red-950/20 text-red-700 dark:text-red-400 text-sm rounded-md",children:c}),e.jsxs(bs,{value:j,onValueChange:f,children:[e.jsxs(vs,{children:[e.jsx(xe,{value:"tester",children:"Tool Tester"}),e.jsx(xe,{value:"builder",children:"Workflow Builder"}),e.jsx(xe,{value:"workflows",children:"Workflows"})]}),e.jsx(he,{value:"tester",className:"mt-4",children:s?e.jsxs("div",{className:"space-y-3",children:[e.jsx(pe,{className:"h-8 w-full"}),e.jsx(pe,{className:"h-48 w-full"})]}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[280px_1fr] gap-4",children:[e.jsx("div",{className:"border rounded-lg p-3 max-h-[calc(100vh-200px)] overflow-y-auto",children:e.jsx(et,{tools:r,selectedTool:a,onSelect:o})}),e.jsx("div",{children:e.jsx(at,{tool:N})})]})}),e.jsx(he,{value:"builder",className:"mt-4",children:s?e.jsx(pe,{className:"h-48 w-full"}):e.jsx(bt,{tools:r,editingWorkflow:m,onWorkflowSaved:()=>{p(u=>u+1),x(null),f("workflows")},onClearEditing:()=>x(null)})}),e.jsx(he,{value:"workflows",className:"mt-4",children:e.jsx(wt,{refreshKey:d,onEditWorkflow:v})})]})]})}export{Qt as PlaygroundPage};

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.