@codeyam-editor/codeyam-editor 0.1.0-staging.27ed016
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/npm/cli.js +16 -0
- package/npm/container.js +35 -0
- package/npm/editor-dev.js +128 -0
- package/npm/editor.js +191 -0
- package/npm/open.js +15 -0
- package/npm/scenario-check.js +215 -0
- package/npm/scenario-handlers.js +71 -0
- package/npm/scenario-issues.js +35 -0
- package/npm/scenario-metrics.js +94 -0
- package/npm/scenario-mocks.js +70 -0
- package/npm/scenario-playwright.js +192 -0
- package/npm/utils.js +356 -0
- package/package.json +32 -0
- package/ui/dist/assets/ContainerInspector-CVhTYjTR.js +2 -0
- package/ui/dist/assets/EditorShell-1FTR28BA.js +32 -0
- package/ui/dist/assets/Markdown-BHBqz-Mj.js +1 -0
- package/ui/dist/assets/ScenarioDataPanel-Bb7egwjC.js +5 -0
- package/ui/dist/assets/ScenarioDataPanel-DYP7pi_n.css +32 -0
- package/ui/dist/assets/ScenarioDataPanelFullPage-I0tbkDlL.js +1 -0
- package/ui/dist/assets/ScenarioRenderer-DIwirbX6.js +1 -0
- package/ui/dist/assets/StepsSimulator-CRtmlyNZ.js +1 -0
- package/ui/dist/assets/index-6jueUhB_.js +27 -0
- package/ui/dist/assets/index-Bik6WLGP.css +1 -0
- package/ui/dist/assets/markdown-v0F0UEt3.js +37 -0
- package/ui/dist/assets/react-CSS0HapR.js +28 -0
- package/ui/dist/assets/useEvents-DggWrtHe.js +1 -0
- package/ui/dist/assets/xterm--24IGk-x.js +9 -0
- package/ui/dist/favicon.ico +0 -0
- package/ui/dist/favicon.png +0 -0
- package/ui/dist/index.html +16 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as r,M as a,r as c}from"./markdown-v0F0UEt3.js";const i={color:"var(--text-secondary)",fontSize:"var(--text-sm, 14px)",lineHeight:1.6},s={...i,fontSize:"var(--text-xs, 12px)",lineHeight:1.5};function x({children:l,variant:d="default"}){const n=d==="compact",t=n?"0.375rem":"0.5rem";return r.jsx("div",{className:"markdown-content",style:n?s:i,children:r.jsx(a,{remarkPlugins:[c],components:{h1:({children:e})=>r.jsx("h1",{style:{fontSize:n?"1rem":"1.125rem",fontWeight:600,color:"var(--text-primary)",margin:`${t} 0`},children:e}),h2:({children:e})=>r.jsx("h2",{style:{fontSize:n?"0.875rem":"1rem",fontWeight:600,color:"var(--text-primary)",margin:`${t} 0`},children:e}),h3:({children:e})=>r.jsx("h3",{style:{fontSize:n?"0.8125rem":"0.875rem",fontWeight:600,color:"var(--text-primary)",margin:`${t} 0`},children:e}),p:({children:e})=>r.jsx("p",{style:{margin:`${t} 0`},children:e}),ul:({children:e})=>r.jsx("ul",{style:{margin:`${t} 0`,paddingLeft:"1.25rem",listStyleType:"disc"},children:e}),ol:({children:e})=>r.jsx("ol",{style:{margin:`${t} 0`,paddingLeft:"1.25rem",listStyleType:"decimal"},children:e}),li:({children:e})=>r.jsx("li",{style:{marginBottom:"0.125rem"},children:e}),code:({className:e,children:o})=>(e==null?void 0:e.includes("language-"))?r.jsx("code",{className:e,style:{fontFamily:"'IBM Plex Mono', monospace",fontSize:"0.8125rem"},children:o}):r.jsx("code",{style:{fontFamily:"'IBM Plex Mono', monospace",fontSize:"0.85em",background:"var(--bg-input)",padding:"0.1em 0.35em",borderRadius:"3px",color:"var(--accent-orange)"},children:o}),pre:({children:e})=>r.jsx("pre",{style:{background:"var(--bg-input)",borderRadius:"6px",padding:n?"0.5rem":"0.75rem",margin:`${t} 0`,overflowX:"auto",fontSize:"0.8125rem",lineHeight:1.5,border:"1px solid var(--border-subtle)"},children:e}),a:({href:e,children:o})=>r.jsx("a",{href:e,style:{color:"var(--accent-blue)",textDecoration:"underline",textUnderlineOffset:"2px"},target:"_blank",rel:"noopener noreferrer",children:o}),strong:({children:e})=>r.jsx("strong",{style:{fontWeight:600,color:"var(--text-primary)"},children:e}),blockquote:({children:e})=>r.jsx("blockquote",{style:{borderLeft:"3px solid var(--accent-blue)",paddingLeft:"0.75rem",margin:`${t} 0`,color:"var(--text-muted)",fontStyle:"italic"},children:e}),table:({children:e})=>r.jsx("div",{style:{overflowX:"auto",margin:`${t} 0`},children:r.jsx("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"0.8125rem"},children:e})}),th:({children:e})=>r.jsx("th",{style:{borderBottom:"2px solid var(--border-default)",padding:"0.375rem 0.5rem",textAlign:"left",fontWeight:600,color:"var(--text-primary)"},children:e}),td:({children:e})=>r.jsx("td",{style:{borderBottom:"1px solid var(--border-subtle)",padding:"0.375rem 0.5rem"},children:e})},children:l})})}export{x as M};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{j as n}from"./markdown-v0F0UEt3.js";import{b as x}from"./react-CSS0HapR.js";import{u as Be}from"./useEvents-DggWrtHe.js";import{r as Ye,a as He}from"./xterm--24IGk-x.js";import{l as pe,b as Ve}from"./index-6jueUhB_.js";const ee=4e3;function xe(e){let t;try{t=JSON.stringify(e,null,2)}catch{t=String(e)}return t.length>ee?`${t.slice(0,ee)}
|
|
2
|
+
… (truncated, ${t.length-ee} more chars)`:t}function _e({slug:e,scenarioName:t,seedTabs:r,mockEntries:s,selectedMock:o,selectedSeedTab:a,selectedSeedRows:i}){const c=[],h=t??e;if(c.push(`# Edit Scenario Data: "${h}"`),c.push(""),c.push(`**Slug**: ${e}`),c.push(`**Scenario file**: .codeyam/scenarios/${e}.json`),c.push(""),c.push("## Scenario overview"),r.length>0){c.push("### Seed & Local tables");for(const d of r){const g=d.category?` (${d.category})`:"";c.push(`- **${d.label}**${g} — dataKey \`${d.dataKey}\``)}c.push("")}if(s.length>0){c.push("### HTTP mocks");const d=new Map;for(const g of s){const p=d.get(g.source)??[];p.push(g),d.set(g.source,p)}for(const[g,p]of d){c.push(`**${g}** (${p.length}):`);for(const l of p)c.push(`- \`${l.method} ${l.pathPattern}\``)}c.push("")}if(o){const d=`${o.method} ${o.pathPattern}`;c.push(`## Currently viewing: mock \`${d}\``),c.push(`- **Source**: ${o.source}`),o.status!==void 0&&c.push(`- **Status**: ${o.status}`);const g=o.headers??{},p=Object.entries(g);if(p.length>0){c.push("- **Headers**:");for(const[l,u]of p)c.push(` - \`${l}: ${u}\``)}o.body!==void 0&&o.body!==null?(c.push("- **Body**:"),c.push("```json"),c.push(xe(o.body)),c.push("```")):c.push("- **Body**: (empty)"),c.push("")}else if(a){if(c.push(`## Currently viewing: seed table **${a.label}**`),c.push(`- **dataKey**: \`${a.dataKey}\``),a.category&&c.push(`- **Category**: ${a.category}`),a.description&&c.push(`- **Description**: ${a.description}`),a.schemaFields&&a.schemaFields.length>0){c.push("- **Schema**:");for(const d of a.schemaFields){const g=d.isId?" (PK)":"";c.push(` - \`${d.name}\`: ${d.type}${g}`)}}i&&i.length>0?(c.push(`- **Rows** (${i.length}):`),c.push("```json"),c.push(xe(i)),c.push("```")):c.push("- **Rows**: (none yet)"),c.push("")}return c.push("## Your task"),c.push("The user is looking at the Scenario Data Panel and wants your help adjusting its data. Ask what change they'd like to make."),c.push(""),c.push("Typical edits:"),c.push('- Tweak an HTTP mock body, status, or headers → update `mocks.http["METHOD /path"]` in the scenario JSON'),c.push("- Add or remove seed rows → update the `seed` section"),c.push("- Adjust `localStorage` values → update the `localStorage` section"),c.push(""),c.push("To save changes:"),c.push("1. Write the updated scenario JSON to `.codeyam/tmp/scenario.json`"),c.push("2. Run: `codeyam-editor editor register @.codeyam/tmp/scenario.json`"),c.push("3. The editor will reload automatically and the panel will reflect the new data."),c.join(`
|
|
3
|
+
`)}const se=new Set;let F=null;const Xe=150;function on(e){return se.add(e),()=>{se.delete(e)}}function _(){F&&clearTimeout(F),F=setTimeout(()=>{F=null;for(const e of se)e()},Xe)}const ae=new Set;function cn(e){for(const t of ae)t(e)}function Fe(e){return ae.add(e),()=>{ae.delete(e)}}function Je({onSelect:e,onFocus:t}){x.useEffect(()=>Fe(({routeKey:r,jsonPath:s})=>{e(r),t(s)}),[e,t])}const Ue="claude";function Ne(e){switch(e){case"codex":return"Codex";case"gemini":return"Gemini";default:return"Claude"}}function Ee(){const[e,t]=x.useState(null),[r,s]=x.useState(!0),[o,a]=x.useState(null);return x.useEffect(()=>{fetch("/api/config").then(i=>{if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}).then(i=>{t({projectName:i.projectName??null,projectDescription:i.projectDescription??null,provider:i.provider??Ue,port:i.port??3e3,screenSizes:i.screenSizes??{},defaultScreenSize:i.defaultScreenSize??null,apps:i.apps??[]}),s(!1)}).catch(i=>{a(i instanceof Error?i.message:"Failed to load config"),s(!1)})},[]),{config:e,apps:(e==null?void 0:e.apps)??[],loading:r,error:o}}async function U(e){try{const t=await e.json();if(t.error)return t.error}catch{}return`Request failed (${e.status})`}async function ze(e,t=null){const r=t!=null?`?since_ms=${encodeURIComponent(t)}`:"",o=await(await fetch(`/api/mock-panel/${encodeURIComponent(e)}${r}`)).json();if("error"in o)throw new Error(o.error);return o}async function he(e,t){const r=`/api/scenarios/${encodeURIComponent(e)}/mocks/${encodeURIComponent(t.routeKey)}`,s=await fetch(r,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:t.status,body:t.body,headers:t.headers})});if(!s.ok)throw new Error(await U(s))}async function We(e,t){const r=`/api/scenarios/${encodeURIComponent(e)}/mocks/${encodeURIComponent(t)}`,s=await fetch(r,{method:"DELETE"});if(!s.ok)throw new Error(await U(s))}async function qe(e,t){const r=`/api/scenarios/${encodeURIComponent(e)}/mocks/${encodeURIComponent(t)}/passthrough`,s=await fetch(r,{method:"POST"});if(!s.ok)throw new Error(await U(s))}function K(e){return e.kind==="shared"?`shared:${e.slug}`:e.kind}async function Ge(e){const t=await fetch("/api/mocks/save-scoped",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),r=await t.json();if(!t.ok||"success"in r&&r.success===!1)throw new Error("error"in r?r.error:`Save failed (${t.status})`);return r}async function Qe(e,t,r){const s=new URLSearchParams({scenarioSlug:e,routeKey:t,scope:K(r)}),o=await fetch(`/api/mocks/save-scope-impact?${s.toString()}`);if(!o.ok)throw new Error(await U(o));return(await o.json()).impactedScenarios??[]}function Ze(){const[e,t]=x.useState(null),[r,s]=x.useState(null),o=x.useRef(null),a=async()=>{try{const c=await fetch("/api/editor-dev-server");if(!c.ok)throw new Error(`Failed to fetch dev server status: ${c.statusText}`);const h=await c.json(),d=JSON.stringify(h);if(d===o.current){s(null);return}o.current=d,t(h),s(null)}catch(c){s(c instanceof Error?c.message:String(c))}};return x.useEffect(()=>{a();const c=setInterval(a,1e3);return()=>clearInterval(c)},[]),{status:e,error:r,restart:async()=>{try{const c=await fetch("/api/editor-dev-server",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"restart"})});if(!c.ok)throw new Error(`Failed to restart dev server: ${c.statusText}`);a()}catch(c){s(c instanceof Error?c.message:String(c))}}}}function et(e){const[t,r]=x.useState([]),[s,o]=x.useState(null),[a,i]=x.useState(!1),[c,h]=x.useState(null),{events:d}=Be(),{status:g}=Ze(),p=(g==null?void 0:g.lastIframeLoadedAtMs)??null,l=x.useCallback(async()=>{if(!e){r([]),o(null);return}i(!0),h(null);try{const f=await ze(e,p);r(f.entries),o(f.defaultSlug)}catch(f){h(f instanceof Error?f.message:"Failed to load mocks")}finally{i(!1)}},[e,p]);x.useEffect(()=>{l()},[l]),x.useEffect(()=>{const f=d[d.length-1];!f||f.type!=="http_request"||l()},[d,l]);const u=x.useCallback(async f=>{e&&(await he(e,f),await l())},[e,l]),m=x.useCallback(async f=>{e&&(f.scope.kind==="scenario"?await he(e,{routeKey:f.routeKey,status:f.status,body:f.body,headers:f.headers}):await Ge({scenarioSlug:e,routeKey:f.routeKey,scope:f.scope,status:f.status,body:f.body,headers:f.headers}),await l())},[e,l]),b=x.useCallback(async f=>{e&&(await We(e,f),await l())},[e,l]),y=x.useCallback(async f=>{e&&(await qe(e,f),await l())},[e,l]);return{entries:t,defaultSlug:s,loading:a,error:c,refresh:l,upsert:u,upsertScoped:m,remove:b,setPassthrough:y}}function tt(e){const t={};for(const[r,s]of Object.entries(e))if(typeof s=="string")try{const o=JSON.parse(s);Array.isArray(o)?t[r]=o:typeof o=="object"&&o!==null&&(t[r]=[o])}catch{}else Array.isArray(s)&&(t[r]=s);return t}function rt(e,t){return e.length===0||t.length===0?!1:e.filter(s=>t.includes(s)).length>=Math.min(e.length,t.length)*.5}function nt(e){return e==null?"null":typeof e=="number"?Number.isInteger(e)?"int4":"float":typeof e=="boolean"?"bool":typeof e=="object"?Array.isArray(e)?"array":"json":"text"}function st(e,t){return e.length>0?Object.keys(e[0]):t?t.map(r=>r.name):[]}function at(e,t,r){const s=new Map((r||[]).map(a=>[a.name,a.type])),o={};for(const a of e)o[a]=s.get(a)||(t.length>0?nt(t[0][a]):"text");return o}function ot(e,t){var r;return((r=t==null?void 0:t.find(s=>s.isId))==null?void 0:r.name)||e.find(s=>s==="id")||null}function it(e,t){const{_metadata:r,...s}=t,o=s.localStorage&&typeof s.localStorage=="object"&&!Array.isArray(s.localStorage)?tt(s.localStorage):{},a={};if(s.seed&&typeof s.seed=="object"&&!Array.isArray(s.seed))for(const[l,u]of Object.entries(s.seed))Array.isArray(u)&&(a[l]=u);const i={},c=[],h=new Set,d=new Set,g=new Set;for(const l of e){const u=l.name.charAt(0).toLowerCase()+l.name.slice(1),m=l.fields.map(f=>f.name);let b=null,y=[];for(const f of[l.name,u,`${u}s`])if(f in s&&Array.isArray(s[f])){b=f,y=s[f],d.add(f);break}if(!b){for(const f of[l.name,u,`${u}s`])if(f in a){b=f,y=a[f],g.add(f),f in o&&h.add(f);break}}if(!b){for(const f of[l.name,u,`${u}s`])if(f in o){b=u,y=o[f],h.add(f);break}}if(!b){for(const[f,v]of Object.entries(o))if(!h.has(f)&&v.length>0&&rt(m,Object.keys(v[0]))){b=u,y=v,h.add(f);break}}b||(b=u),i[b]=y,c.push({label:l.name,dataKey:b,category:l.category,description:l.description,schemaFields:l.fields.map(f=>({name:f.name,type:f.type,isId:f.isId??!1}))})}const p=new Set(["name","id","url","dimensions","componentName","scenarioType","pageFilePath","routeName","description","props","env"]);for(const[l,u]of Object.entries(s))l==="_metadata"||l==="localStorage"||l==="seed"||l==="type"||l==="mocks"||p.has(l)||d.has(l)||ct(u)&&(i[l]=u,c.push({label:l,dataKey:l}));for(const[l,u]of Object.entries(a))g.has(l)||(i[l]=u,c.push({label:l,dataKey:l}));for(const[l,u]of Object.entries(o))h.has(l)||(i[l]=u,c.push({label:l,dataKey:l}));return{data:i,tabs:c}}function me(e){return e==="null"?null:e==="true"?!0:e==="false"?!1:e===""?"":isNaN(Number(e))?e:Number(e)}function ct(e){return Array.isArray(e)&&e.length>0&&typeof e[0]=="object"&&e[0]!==null}function lt(e){if(typeof e!="object"||e===null||!("props"in e))return null;const t=e.props;return typeof t!="object"||t===null||Array.isArray(t)?null:t}function dt(e,t){const r=new Set;for(const s of t){const o=e[s.dataKey];Array.isArray(o)&&o.length>0&&r.add(s.dataKey)}return r}function ut(e){if(typeof e=="object"&&e!==null&&"shares"in e){const t=e.shares;if(Array.isArray(t))return t.filter(r=>typeof r=="string")}return[]}function ft(e){const[t,r]=x.useState({data:null,tableTabs:[],scenarioOwnedDataKeys:new Set,shares:[],props:null,loading:!0,error:null});return x.useEffect(()=>{r(s=>({...s,loading:!0,error:null})),Promise.all([fetch("/api/data-structure").then(s=>s.json()).catch(()=>[]),fetch(`/api/scenarios/${encodeURIComponent(e)}`).then(s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.json()})]).then(([s,o])=>{const a=it(Array.isArray(s)?s:[],o);r({data:a.data,tableTabs:a.tabs,scenarioOwnedDataKeys:dt(a.data,a.tabs),shares:ut(o),props:lt(o),loading:!1,error:null})}).catch(s=>r({data:null,tableTabs:[],scenarioOwnedDataKeys:new Set,shares:[],props:null,loading:!1,error:s instanceof Error?s.message:"Failed to load"}))},[e]),t}function ce(e,t=""){return`/api/scenarios/${encodeURIComponent(e)}/draft${t}`}async function pt(e){const t=await fetch(ce(e,"/status"));if(!t.ok)return{isDirty:!1,diffSummary:null};const r=await t.json();return{isDirty:!!r.isDirty,diffSummary:r.diffSummary??null}}async function xt(e){const t=await fetch(ce(e,"/commit"),{method:"POST"});if(!t.ok)throw new Error(`Save failed (${t.status})`)}async function ht(e){const t=await fetch(ce(e),{method:"DELETE"});if(!t.ok)throw new Error(`Cancel failed (${t.status})`)}function mt({slug:e,onPreviewReload:t}){const[r,s]=x.useState(!1),[o,a]=x.useState(null),[i,c]=x.useState(!1),[h,d]=x.useState(!1),[g,p]=x.useState(null),l=x.useRef(null),u=x.useCallback(async()=>{if(!e){s(!1),a(null);return}try{const v=await pt(e);s(v.isDirty),a(v.diffSummary)}catch{}},[e]);x.useEffect(()=>{u()},[u]),x.useEffect(()=>{if(!r)return;const v=j=>{j.preventDefault(),j.returnValue=""};return window.addEventListener("beforeunload",v),()=>window.removeEventListener("beforeunload",v)},[r]);const m=x.useCallback(()=>{l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{u()},100)},[u]),b=x.useCallback(async()=>{if(e){c(!0),p(null);try{await xt(e),s(!1),a(null),t&&t()}catch(v){p(v instanceof Error?v.message:"Save failed")}finally{c(!1)}}},[e,t]),y=x.useCallback(async()=>{if(e){d(!0),p(null);try{await ht(e),s(!1),a(null),t&&t()}catch(v){p(v instanceof Error?v.message:"Cancel failed")}finally{d(!1)}}},[e,t]),f=x.useCallback(v=>r?window.confirm(v):!0,[r]);return{isDirty:r,saving:i,cancelling:h,error:g,diffSummary:o,save:b,cancel:y,markDirty:m,confirmIfDirty:f}}const bt={scenario:"Scenario",shared:"Shared",default:"Defaults","catalog-only":"Observed only",passthrough:"Passthrough"},gt={scenario:null,shared:null,default:null,"catalog-only":"Observed during live traffic but not mocked yet. Promote it to a scenario mock to capture and edit the response.",passthrough:null};function Te(e){return bt[e]??e}function yt(e){return gt[e]??null}const vt={scenario:"bg-emerald-500/15 text-emerald-300 border-emerald-500/40",shared:"bg-violet-500/15 text-violet-300 border-violet-500/40",default:"bg-blue-500/15 text-blue-300 border-blue-500/40","catalog-only":"bg-slate-500/15 text-slate-300 border-slate-500/40",passthrough:"bg-zinc-500/15 text-zinc-300 border-zinc-500/40"};function De({source:e}){const t=yt(e);return n.jsx("span",{className:`px-1.5 py-0.5 rounded border ${vt[e]}`,title:t??`source: ${e}`,children:Te(e)})}function jt({label:e,scenarioCount:t,inheritedCount:r,expanded:s,onToggle:o}){const a=r===0;return n.jsxs("h3",{className:"px-3 pb-1 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-dim)]",children:[n.jsx("div",{className:"mb-0.5",children:e}),n.jsxs("div",{className:"flex items-center gap-1 normal-case tracking-normal font-normal",children:[n.jsxs("span",{children:[t," scenario-specific"]}),n.jsx("span",{"aria-hidden":!0,children:"·"}),n.jsxs("button",{type:"button",onClick:o,disabled:a,"aria-expanded":s,className:`inline-flex items-center gap-0.5 ${a?"cursor-default text-[var(--text-dim)]":"cursor-pointer hover:text-[var(--text-primary)]"}`,children:[n.jsx("span",{"aria-hidden":!0,className:"inline-block w-2 text-[9px]",children:a?"":s?"▾":"▸"}),n.jsxs("span",{children:[r," inherited from default"]})]})]})]})}function wt({children:e}){return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"mx-3 my-1 border-t border-[var(--border-subtle)]"}),n.jsx("div",{className:"px-3 pb-1 text-[9px] uppercase tracking-wider text-[var(--text-dim)]",children:"Inherited from default"}),e]})}function kt({slug:e}){return n.jsx("span",{className:"px-1 py-0.5 rounded border text-[9px] font-mono bg-violet-500/10 text-violet-300 border-violet-500/30",title:`from shared-data set: ${e}`,children:e})}const St={GET:"text-emerald-400",POST:"text-blue-400",PUT:"text-amber-400",PATCH:"text-purple-400",DELETE:"text-red-400"};function Ct({entry:e,routeKey:t,active:r,onSelect:s}){const o=St[e.method]??"text-[var(--text-muted)]";return n.jsxs("button",{onClick:s,className:`w-full text-left px-3 py-1.5 text-xs flex items-center gap-2 border-l-2 transition-colors cursor-pointer ${r?"bg-[var(--accent-blue)]/10 border-[var(--accent-blue)] text-[var(--text-primary)]":"border-transparent text-[var(--text-muted)] hover:bg-[var(--bg-card)] hover:text-[var(--text-primary)]"}`,title:t,children:[n.jsx("span",{className:`font-mono text-[9px] font-semibold ${o}`,children:e.method}),n.jsx("span",{className:"truncate flex-1 font-mono",children:e.pathPattern}),e.source==="shared"&&e.sharedSlug&&n.jsx(kt,{slug:e.sharedSlug})]})}const Nt=["scenario","shared","default","catalog-only","passthrough"];function V(e){return`${e.method} ${e.pathPattern}`}function Et({seedTabs:e,mockEntries:t,selection:r,onSelect:s,overrides:o}){const a=new Map;for(const i of t){const c=a.get(i.source)??[];c.push(i),a.set(i.source,c)}return n.jsxs("nav",{className:"w-56 shrink-0 border-r border-[var(--border-subtle)] bg-[var(--bg-deep)] overflow-y-auto",children:[n.jsx(ye,{label:"Seed & Local",count:e.length,emptyHint:"No seed or localStorage data",override:o?{scenarioCount:o.scenarioSeedCount,inheritedCount:o.inheritedSeedCount,renderInherited:()=>be({tabs:o.inheritedSeedTabs,selection:r,onSelect:s})}:void 0,children:be({tabs:e,selection:r,onSelect:s})}),n.jsx(ye,{label:"Mock APIs",count:t.length,emptyHint:"No HTTP mocks registered",override:o?{scenarioCount:o.scenarioMockCount,inheritedCount:o.inheritedMockCount,renderInherited:()=>ge({entries:o.inheritedMockEntries,selection:r,onSelect:s})}:void 0,children:ge({entries:t,grouped:a,selection:r,onSelect:s})})]})}function be({tabs:e,selection:t,onSelect:r}){return e.map(s=>{const o=(t==null?void 0:t.kind)==="seed"&&t.dataKey===s.dataKey;return n.jsxs("button",{onClick:()=>r({kind:"seed",dataKey:s.dataKey}),className:`w-full text-left px-3 py-1.5 text-xs flex items-center gap-2 border-l-2 transition-colors cursor-pointer ${o?"bg-[var(--accent-active)]/10 border-[var(--accent-active)] text-[var(--text-primary)]":"border-transparent text-[var(--text-muted)] hover:bg-[var(--bg-card)] hover:text-[var(--text-primary)]"}`,children:[n.jsx("span",{className:"truncate flex-1",children:s.label}),s.category&&n.jsx("span",{className:"text-[9px] uppercase tracking-wide text-[var(--text-dim)]",children:s.category==="mock-api"?"API":s.category})]},s.dataKey)})}function ge({entries:e,grouped:t,selection:r,onSelect:s}){const o=t??Tt(e);return Nt.flatMap(a=>{const i=o.get(a)??[];return i.length===0?[]:[n.jsxs("div",{className:"px-3 pt-2 pb-1 text-[9px] uppercase tracking-wider text-[var(--text-dim)] font-semibold flex items-center gap-1.5",children:[Te(a),n.jsx(De,{source:a})]},`hdr-${a}`),...i.map(c=>{const h=V(c),d=(r==null?void 0:r.kind)==="mock"&&r.routeKey===h;return n.jsx(Ct,{entry:c,routeKey:h,active:d,onSelect:()=>s({kind:"mock",routeKey:h})},h)})]})}function Tt(e){const t=new Map;for(const r of e){const s=t.get(r.source)??[];s.push(r),t.set(r.source,s)}return t}function ye({label:e,count:t,emptyHint:r,children:s,override:o}){const[a,i]=x.useState(!1);if(o){const{scenarioCount:c,inheritedCount:h,renderInherited:d}=o,g=c+(a?h:0);return n.jsxs("section",{className:"py-2",children:[n.jsx(jt,{label:e,scenarioCount:c,inheritedCount:h,expanded:a,onToggle:()=>i(p=>!p)}),g===0?n.jsx("p",{className:"px-3 py-1 text-[10px] italic text-[var(--text-dim)]",children:r}):n.jsxs("div",{children:[s,a&&h>0&&n.jsx(wt,{children:d()})]})]})}return n.jsxs("section",{className:"py-2",children:[n.jsxs("h3",{className:"px-3 pb-1 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-dim)] flex items-center justify-between",children:[n.jsx("span",{children:e}),n.jsx("span",{children:t})]}),t===0?n.jsx("p",{className:"px-3 py-1 text-[10px] italic text-[var(--text-dim)]",children:r}):n.jsx("div",{children:s})]})}function Dt({seedTabs:e,mockEntries:t,initialSection:r,selection:s,setSelection:o}){x.useEffect(()=>{if(s)return;const a=r==="mocks",i=r==="seed";if(a&&t.length>0){o({kind:"mock",routeKey:V(t[0])});return}if(i&&e.length>0){o({kind:"seed",dataKey:e[0].dataKey});return}e.length>0?o({kind:"seed",dataKey:e[0].dataKey}):t.length>0&&o({kind:"mock",routeKey:V(t[0])})},[r,t,e,s,o])}var Ot=Ye(),Mt=He();function $t(e){const t=window.location.protocol==="https:"?"wss:":"ws:",r=new URL(`${t}//${window.location.host}/ws/terminal`);return e!=null&&e.provider&&r.searchParams.set("provider",e.provider),e!=null&&e.mode&&r.searchParams.set("mode",e.mode),e!=null&&e.sessionId&&r.searchParams.set("sessionId",e.sessionId),r.toString()}const At=40;function Pt(e){const t=e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return t&&t.slice(0,At).replace(/-+$/,"")||"session"}function Oe(e){window.dispatchEvent(new CustomEvent("terminal-send-input",{detail:e}))}const Rt=50;function It(e,t=Oe){return new Promise(r=>{t(e),setTimeout(()=>{t("\r"),r()},Rt)})}const te=3e3;function Me(e){return e==="gemini"?"gemini":"claude"}function Lt(e,t){return`${Me(e)} '${t}'\r`}function Kt(e){const t=e.trim(),r=t.match(/^\/codeyam-edit-plan\s+(\S+)/);if(r)return`Edit Plan: ${r[1]}`;const s=t.split(/\s+/)[0],o={"/codeyam-plan":"Plan","/codeyam-editor":"Editor","/codeyam-diagnose":"Diagnose"};return o[s]?o[s]:s.replace(/^\//,"").replace(/^codeyam-/,"").split("-").filter(i=>i.length>0).map(i=>i[0].toUpperCase()+i.slice(1).toLowerCase()).join(" ")}async function Bt(e,t=Oe){const r=Pt(e);await It(`/rename ${r}`,t)}function Yt(e,t,r){pe("dispatch-rename",{phase:"queued",caller:t,label:e,delayMs:te}),setTimeout(()=>{pe("dispatch-rename",{phase:"fired",caller:t,label:e,delayMs:te}),Bt(e,r)},te)}function Ht(e,t){const r=Me(e),s=`mkdir -p .codeyam/tmp && cat > .codeyam/tmp/inline-prompt.md << 'INLINE_PROMPT_EOF'
|
|
4
|
+
${t}
|
|
5
|
+
INLINE_PROMPT_EOF\r`,o=`${r} "Read the file at '.codeyam/tmp/inline-prompt.md' for your instructions."\r`;return[s,o]}function Vt(){if(typeof navigator>"u")return!1;const e=navigator.platform??"";return e?/Mac|iPhone|iPad|iPod/i.test(e):/Mac|iPhone|iPad|iPod/i.test(navigator.userAgent??"")}function _t(e,t,r={}){const s=r.isMac??Vt(),o=r.onError;let a=null;async function i(){if(!e.hasSelection())return;const l=e.getSelection();try{await navigator.clipboard.writeText(l)}catch(u){o==null||o(je("copy",u))}}async function c(){try{const l=await navigator.clipboard.readText();l&&e.paste(l)}catch(l){o==null||o(je("paste",l))}}function h(l){return l.type!=="keydown"?!0:s?l.metaKey&&!l.ctrlKey&&!l.altKey&&l.key.toLowerCase()==="c"&&e.hasSelection()?(i(),!1):!0:l.ctrlKey&&l.shiftKey&&!l.metaKey&&!l.altKey&&l.key.toLowerCase()==="c"&&e.hasSelection()?(i(),!1):!0}e.attachCustomKeyEventHandler(h);function d(){if(!a)return;const{root:l,onDocumentClick:u,onKeyDown:m}=a;document.removeEventListener("mousedown",u,!0),document.removeEventListener("keydown",m,!0),l.remove(),a=null}function g(l,u){d();const m=document.createElement("div");m.setAttribute("data-terminal-clipboard-menu","true"),m.style.position="fixed",m.style.left=`${l}px`,m.style.top=`${u}px`,m.style.zIndex="1000",m.style.minWidth="140px",m.style.padding="4px 0",m.style.background="var(--bg-card)",m.style.border="1px solid var(--border-subtle)",m.style.borderRadius="6px",m.style.boxShadow="0 8px 24px rgba(0, 0, 0, 0.35)",m.style.fontSize="12px",m.style.color="var(--text-primary)",m.style.userSelect="none";const b=e.hasSelection(),y=ve("Copy",!b,()=>{i(),d()}),f=ve("Paste",!1,()=>{c(),d()});m.appendChild(y),m.appendChild(f),document.body.appendChild(m);const v=k=>{m.contains(k.target)||d()},j=k=>{k.key==="Escape"&&(k.preventDefault(),d())};document.addEventListener("mousedown",v,!0),document.addEventListener("keydown",j,!0),a={root:m,onDocumentClick:v,onKeyDown:j}}function p(l){l.preventDefault(),g(l.clientX,l.clientY)}return t.addEventListener("contextmenu",p),()=>{t.removeEventListener("contextmenu",p),d(),e.attachCustomKeyEventHandler(()=>!0)}}function ve(e,t,r){const s=document.createElement("button");return s.type="button",s.textContent=e,s.disabled=t,s.style.display="block",s.style.width="100%",s.style.padding="6px 12px",s.style.border="none",s.style.background="transparent",s.style.textAlign="left",s.style.fontSize="12px",s.style.cursor=t?"default":"pointer",s.style.color=t?"var(--text-dim)":"var(--text-primary)",t||(s.addEventListener("mouseenter",()=>{s.style.background="var(--border-subtle)"}),s.addEventListener("mouseleave",()=>{s.style.background="transparent"}),s.addEventListener("click",()=>r())),s}function je(e,t){const r=t instanceof Error?t.message:String(t);return`Clipboard ${e} failed: ${r}`}function Xt(e,t,r,s,o,a){const i=e.leftBorderCol+1;if(t===s)return o-r;if(s<t){let d=r-i;d+=1;for(let p=s+1;p<t;p++){const l=a(p);if(l===null)return null;d+=Math.max(1,l-i+1)}const g=a(s);return g===null?null:(d+=Math.max(0,g-o),-d)}const c=a(t);if(c===null)return null;let h=Math.max(0,c-r)+1;for(let d=t+1;d<s;d++){const g=a(d);if(g===null)return null;h+=Math.max(1,g-i+1)}return h+=o-i,h}const J=new Set(["│","┃","║","|"]);function Ft(e,t,r,s){const o=e.baseY,a=(u,m)=>{const b=e.getLine(o+u);if(!b)return null;const y=b.getCell(m);return y?y.getChars():null},i=u=>{let m=-1;for(let y=0;y<r;y++){const f=a(u,y);if(f!==null&&J.has(f)){m=y;break}}if(m===-1)return null;let b=-1;for(let y=r-1;y>m;y--){const f=a(u,y);if(f!==null&&J.has(f)){b=y;break}}return b===-1?null:{leftBorderCol:m,rightBorderCol:b}};let c=t,h=i(t);if(!h){const u=i(t-1);if(u)c=t-1,h=u;else{const m=i(t+1);m&&(c=t+1,h=m)}}if(!h)return null;const{leftBorderCol:d,rightBorderCol:g}=h;let p=c;for(let u=c-1;u>=0;u--){const m=a(u,d);if(m===null)break;if(!(m===""||m===" ")){if(!J.has(m))break;p=u}}let l=c;for(let u=c+1;u<s;u++){const m=a(u,d);if(m===null)break;if(!(m===""||m===" ")){if(!J.has(m))break;l=u}}return{topRow:p,bottomRow:l,leftBorderCol:d,rightBorderCol:g}}function Jt(e,t,r,s){const o=e.getLine(e.baseY+t);if(!o)return null;for(let a=s;a>=r;a--){const i=o.getCell(a);if(!i)continue;const c=i.getChars();if(c!==""&&c!==" ")return a}return r-1}const Ut=200;function zt(e){const{click:t,terminal:r,cellSurface:s,debug:o}=e,a=r.buffer.active,i=k=>{o==null||o({cursorY:a.cursorY,cursorX:a.cursorX,originalTargetCol:k.originalTargetCol??k.targetCol,snapped:k.snapped??!1,...k})};if(a.type==="alternate")return i({targetRow:-1,targetCol:-1,box:null,rejected:"alt-screen",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;if(a.viewportY!==a.baseY)return i({targetRow:-1,targetCol:-1,box:null,rejected:"scrollback",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const c=s.getBoundingClientRect();if(c.width===0||c.height===0)return i({targetRow:-1,targetCol:-1,box:null,rejected:"outside-grid",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const h=t.clientX-c.left,d=t.clientY-c.top;if(h<0||d<0||h>=c.width||d>=c.height)return i({targetRow:-1,targetCol:-1,box:null,rejected:"outside-grid",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const g=c.width/r.cols,p=c.height/r.rows,l=Math.floor(h/g),u=Math.floor(d/p),m=r.modes.applicationCursorKeysMode,b=m?"\x1BOC":"\x1B[C",y=m?"\x1BOD":"\x1B[D",f=Ft(a,a.cursorY,r.cols,r.rows);if(f){if(u<f.topRow||u>f.bottomRow)return i({targetRow:u,targetCol:l,box:f,rejected:"out-of-box",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;if(l<=f.leftBorderCol||l>=f.rightBorderCol)return i({targetRow:u,targetCol:l,box:f,rejected:"border",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const k=f.leftBorderCol+1,D=f.rightBorderCol-1,R=$=>Jt(a,$,k,D),A=a.cursorY<f.topRow||a.cursorY>f.bottomRow,M=A?f.bottomRow:a.cursorY,C=A?D:a.cursorX,E=u!==M;let P=null;if(E&&(P=R(u),P===null))return i({targetRow:u,targetCol:l,originalTargetCol:l,snapped:!1,box:f,rejected:"unreadable-row",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;let O=l,S=!1;if(E&&P!==null){const $=Math.max(k,P);l>$&&(O=$,S=!0)}if(u===M&&O===C)return i({targetRow:u,targetCol:O,originalTargetCol:l,snapped:S,box:f,rejected:"same-cell",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const w=Xt(f,M,C,u,O,R);if(w===null)return i({targetRow:u,targetCol:O,originalTargetCol:l,snapped:S,box:f,rejected:"unreadable-row",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;if(w===0)return i({targetRow:u,targetCol:O,originalTargetCol:l,snapped:S,box:f,rejected:"same-cell",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;if(Math.abs(w)>Ut)return i({targetRow:u,targetCol:O,originalTargetCol:l,snapped:S,box:f,rejected:"emit-cap",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const T=w<0?y.repeat(-w):b.repeat(w);return i({targetRow:u,targetCol:O,originalTargetCol:l,snapped:S,box:f,rejected:null,emittedDirection:w<0?"left":"right",emittedByteCount:T.length,predictedCursorY:u,predictedCursorX:O}),T}if(u!==a.cursorY)return i({targetRow:u,targetCol:l,box:null,rejected:"out-of-box",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const v=l-a.cursorX;if(v===0)return i({targetRow:u,targetCol:l,box:null,rejected:"same-cell",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const j=v<0?y.repeat(-v):b.repeat(v);return i({targetRow:u,targetCol:l,box:null,rejected:null,emittedDirection:v<0?"left":"right",emittedByteCount:j.length,predictedCursorY:u,predictedCursorX:l}),j}const we=1;function Wt(e,t){const{sendInput:r,pixelThreshold:s=3,timeThresholdMs:o=300,now:a=()=>Date.now(),onVerificationDisable:i}=t,c=e.element;if(!c)return()=>{};const h=c.querySelector(".xterm-screen")??c;let d=null,g=!1,p=null,l=null;const u=typeof e.onRender=="function"?e.onRender.bind(e):null;u&&(l=u(()=>{const y=p;if(!y)return;p=null;const f=e.buffer.active,v=Math.abs(f.cursorY-y.y),j=Math.abs(f.cursorX-y.x);if(v>we||j>we){g=!0;const k={predicted:y,actual:{y:f.cursorY,x:f.cursorX}};i?i(k):console.warn("[click-cursor] disabled — cursor diverged from prediction",k)}}));function m(y){if(y.button!==0||y.altKey||y.shiftKey||y.metaKey||y.ctrlKey){d=null;return}d={clientX:y.clientX,clientY:y.clientY,at:a()}}function b(y){var M;const f=d;if(d=null,!f)return;const v=y.clientX-f.clientX,j=y.clientY-f.clientY;if(Math.hypot(v,j)>s||a()-f.at>o)return;const k=typeof window<"u"&&((M=window.localStorage)==null?void 0:M.getItem("codeyam.terminalClickDebug"))==="1";if(k)try{const C=e.buffer.active,E=C.cursorY,P={};for(let O=-2;O<=2;O++){const S=E+O,w=C.getLine(C.baseY+S);if(!w)continue;const T=[];for(let $=0;$<e.cols;$++){const I=w.getCell($);T.push(I?I.getChars():"")}P[`row${S}`]=T.join("|")}console.log("[click-cursor] buffer dump",{cursorY:E,cursorX:C.cursorX,viewportY:C.viewportY,baseY:C.baseY,rows:P})}catch{}let D=null;const R=C=>{D=C,k&&console.log("[click-cursor] result",C)},A=zt({click:{clientX:y.clientX,clientY:y.clientY},terminal:e,cellSurface:h,debug:R});if(A){if(D){const C=D,E=C.box!==null&&C.targetRow!==C.cursorY;if(E&&g){k&&console.log("[click-cursor] suppressed by verification-disabled");return}E&&C.predictedCursorY!==null&&C.predictedCursorX!==null&&(p={y:C.predictedCursorY,x:C.predictedCursorX})}r(A)}}return h.addEventListener("mousedown",m),h.addEventListener("mouseup",b),()=>{h.removeEventListener("mousedown",m),h.removeEventListener("mouseup",b),l==null||l.dispose()}}async function $e(e=1500){try{return(await fetch("/api/health",{signal:AbortSignal.timeout(e)})).ok}catch{return!1}}function qt(e,t){let r=!1,s=null;async function o(){if(!r){if(await $e(1500)){r||t();return}r||(s=setTimeout(o,e))}}return s=setTimeout(o,e),()=>{r=!0,s&&(clearTimeout(s),s=null)}}function Gt(){return n.jsx("div",{"data-testid":"terminal-connecting-hint",className:"absolute top-2 right-3 text-xs font-mono text-[#aaa] pointer-events-none z-10 select-none",children:"Connecting…"})}function Qt({attempt:e,maxAttempts:t,pulseKey:r}){return n.jsx("div",{"data-testid":"terminal-reconnecting-banner",className:"absolute inset-0 flex items-start justify-center pt-3 z-10 bg-black/40",children:n.jsxs("div",{"data-testid":"terminal-reconnecting-banner-label",className:"px-4 py-2 rounded font-mono text-sm shadow terminal-disconnect-pulse bg-amber-500/90 text-black",children:["Reconnecting… (attempt ",e," of ",t,")"]},r)})}function Zt({onRefresh:e}){return n.jsx("div",{"data-testid":"terminal-failed-banner",className:"absolute inset-0 flex items-start justify-center pt-3 z-10 bg-black/60",children:n.jsxs("div",{className:"px-4 py-2 rounded font-mono text-sm shadow flex items-center gap-3 terminal-disconnect-pulse bg-red-500/90 text-white",children:[n.jsx("span",{children:"Connection lost. The page must be refreshed to continue."}),n.jsx("button",{type:"button",onClick:e,"data-testid":"terminal-failed-banner-refresh",className:"px-2 py-1 rounded bg-white text-red-700 font-medium cursor-pointer hover:bg-red-50",children:"Refresh page"})]})})}function er({onReload:e}){return n.jsx("div",{"data-testid":"terminal-server-stopped-banner",className:"absolute inset-0 flex items-start justify-center pt-3 z-10 bg-black/60",children:n.jsxs("div",{className:"px-4 py-2 rounded font-mono text-sm shadow flex items-center gap-3 terminal-disconnect-pulse bg-red-500/90 text-white",children:[n.jsx("span",{children:"Editor stopped — restart it from your terminal to continue."}),n.jsx("button",{type:"button",onClick:e,"data-testid":"terminal-server-stopped-banner-reload",className:"px-2 py-1 rounded bg-white text-red-700 font-medium cursor-pointer hover:bg-red-50",children:"Reload page"})]})})}function tr({status:e,pulseKey:t,onRefresh:r}){return e.kind==="open"||e.kind==="ended"?null:e.kind==="connecting"?n.jsx(Gt,{}):e.kind==="reconnecting"?n.jsx(Qt,{attempt:e.attempt,maxAttempts:e.maxAttempts,pulseKey:t}):e.kind==="server-stopped"?n.jsx(er,{onReload:r}):n.jsx(Zt,{onRefresh:r})}const ke=15;function rr({prompt:e,slashCommand:t,height:r=400,onClose:s}){const o=x.useRef(null),a=x.useRef(null),i=x.useRef(null),c=x.useRef(e),{config:h}=Ee(),d=(h==null?void 0:h.provider)??"claude",[g,p]=x.useState({kind:"connecting"}),[l,u]=x.useState(0);return x.useEffect(()=>{const m=o.current;if(!m)return;const b=new Ot.Terminal({theme:{background:"#1a1a1a",foreground:"#d4d4d4",cursor:"#d4d4d4",selectionBackground:"#264f78"},fontSize:12,fontFamily:"'IBM Plex Mono', 'Menlo', 'Monaco', monospace",cursorBlink:!0,scrollback:5e3,allowProposedApi:!0}),y=new Mt.FitAddon;b.loadAddon(y),b.open(m);const f=_t(b,m,{onError:S=>console.warn("[MiniAgentChat]",S)}),v=Wt(b,{sendInput:S=>{const w=a.current;(w==null?void 0:w.readyState)===WebSocket.OPEN&&w.send(JSON.stringify({type:"input",data:S}))}});requestAnimationFrame(()=>{try{y.fit()}catch{}}),i.current=b;const j={current:"inline"},k={current:null},D={current:!1},R={current:!1};let A=0,M=null;function C(){p({kind:"connecting"});const S=$t({mode:j.current,sessionId:k.current??void 0}),w=new WebSocket(S);w.binaryType="arraybuffer",a.current=w,w.onopen=()=>{A=0,p({kind:"open"}),w.send(JSON.stringify({type:"resize",cols:b.cols,rows:b.rows}))},w.onmessage=T=>{if(T.data instanceof ArrayBuffer){b.write(new Uint8Array(T.data)),window.dispatchEvent(new CustomEvent("miniagent-output"));return}try{const $=JSON.parse(T.data);if($.type==="session-id"){$.sessionId&&(k.current=$.sessionId,j.current="resume"),D.current||(D.current=!0,setTimeout(()=>{if(t)w.send(JSON.stringify({type:"input",data:Lt(d,t)})),Yt(Kt(t),"mini-agent-chat",I=>w.send(JSON.stringify({type:"input",data:I})));else{const[I,W]=Ht(d,c.current??"");w.send(JSON.stringify({type:"input",data:I})),setTimeout(()=>{w.send(JSON.stringify({type:"input",data:W}))},500)}},1500));return}}catch{b.write(T.data),window.dispatchEvent(new CustomEvent("miniagent-output"))}},w.onerror=()=>{},w.onclose=async()=>{if(R.current){p({kind:"ended"});return}const T=await $e();if(!R.current){if(!T){p({kind:"server-stopped"}),M==null||M(),M=qt(2e3,()=>{R.current||window.location.reload()});return}if(A<ke){const $=A<4?1e3*Math.pow(2,A):1e4;A++,p({kind:"reconnecting",attempt:A,maxAttempts:ke}),setTimeout(()=>{R.current||C()},$)}else p({kind:"failed"})}}}C(),b.onData(S=>{const w=a.current;(w==null?void 0:w.readyState)===WebSocket.OPEN?w.send(JSON.stringify({type:"input",data:S})):u(T=>T+1)});const E=new ResizeObserver(()=>{try{y.fit();const S=a.current;(S==null?void 0:S.readyState)===WebSocket.OPEN&&S.send(JSON.stringify({type:"resize",cols:b.cols,rows:b.rows}))}catch{}});E.observe(m);function P(){var S;(S=i.current)==null||S.focus()}window.addEventListener("terminal-focus",P);function O(S){const w=S.detail,T=a.current;typeof w=="string"&&(T==null?void 0:T.readyState)===WebSocket.OPEN&&T.send(JSON.stringify({type:"input",data:w}))}return window.addEventListener("miniagent-send-input",O),()=>{var w;R.current=!0,M==null||M(),M=null,window.removeEventListener("terminal-focus",P),window.removeEventListener("miniagent-send-input",O),E.disconnect(),f(),v();const S=a.current;(S==null?void 0:S.readyState)===WebSocket.OPEN&&S.close(),(w=i.current)==null||w.dispose()}},[d]),n.jsxs("div",{className:"mt-2 border border-[var(--border-subtle)] rounded-lg overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-[var(--bg-card)]",children:[n.jsx("span",{className:"text-xs font-medium text-[var(--accent-active)]",children:Ne(d)}),s&&n.jsx("button",{onClick:s,className:"text-[var(--text-dim)] hover:text-[var(--text-primary)] text-xs bg-transparent border-none cursor-pointer",children:"Close"})]}),n.jsx("div",{ref:o,onClick:()=>{var m;return(m=i.current)==null?void 0:m.focus()},style:{height:r,background:"#1a1a1a",padding:"6px 10px",position:"relative",overflow:"hidden"},children:n.jsx(tr,{status:g,pulseKey:l,onRefresh:()=>window.location.reload()})})]})}function nr(){return n.jsx("div",{className:"flex h-full items-center justify-center p-6",children:n.jsxs("div",{className:"max-w-xs text-center space-y-2",children:[n.jsx("p",{className:"text-sm text-[var(--text-muted)]",children:"No scenario data yet."}),n.jsx("p",{className:"text-xs text-[var(--text-dim)]",children:"Seed data and HTTP mocks will appear here as the scenario captures them, or add them with the scenario editor."})]})})}function sr({variant:e,onClose:t}){return e!=="slideOver"?null:n.jsx("button",{onClick:t,className:"rounded border border-[var(--border-default)] bg-transparent px-2 py-1 text-xs text-[var(--text-muted)] hover:text-[var(--text-primary)] cursor-pointer",children:"Close"})}function ar({variant:e,providerLabel:t,chatOpen:r,onToggleChat:s}){const o=e==="inline",a=o?"flex items-center gap-1.5 px-3 py-1.5 rounded border text-xs font-medium cursor-pointer transition-colors":"flex items-center gap-1.5 px-2.5 py-1 rounded border text-xs cursor-pointer transition-colors",i=r?"border-[var(--accent-active)] bg-[var(--accent-active)]/15 text-[var(--accent-active)]":o?"border-[var(--accent-active)] bg-[var(--accent-active)] text-black hover:bg-[var(--accent-active)]/90":"border-[var(--border-default)] bg-transparent text-[var(--text-muted)] hover:text-[var(--text-primary)] hover:border-[var(--accent-active)]/40";return n.jsxs("button",{type:"button",onClick:s,className:`${a} ${i}`,title:`Open a chat with ${t} seeded with this scenario's context`,children:[n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),"Edit with ",t]})}const oe=new Set,ie=new Set;let Ae={isActive:!1,previewSlug:null};function or(){for(const e of oe)e()}function ln(e){return oe.add(e),()=>{oe.delete(e)}}function dn(e){Ae=e;for(const t of ie)t(e)}function ir(e){return ie.add(e),()=>{ie.delete(e)}}function Se(){return Ae}function cr(){const[e,t]=x.useState(()=>Se());return x.useEffect(()=>(t(Se()),ir(t)),[]),e}function lr({panelSlug:e,scenarioState:t}){const r=cr(),{isActive:s,previewSlug:o}=t??r;return o!==e?null:n.jsxs("button",{type:"button","aria-pressed":s,onClick:()=>or(),title:s?"Exit inspect data source":"Inspect data source — click a value in the live preview to see its mock",className:s?"flex items-center gap-1.5 px-2.5 py-1 rounded border text-xs cursor-pointer transition-colors border-[var(--accent-active)] bg-[var(--accent-active)]/15 text-[var(--accent-active)]":"flex items-center gap-1.5 px-2.5 py-1 rounded border text-xs cursor-pointer transition-colors border-[var(--border-default)] bg-transparent text-[var(--text-muted)] hover:text-[var(--text-primary)] hover:border-[var(--accent-active)]/40",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),s?"Inspecting…":"Inspect data"]})}function dr({variant:e,slug:t}){const r=()=>window.open(Ve(t),"_blank");return e==="slideOver"?n.jsx("button",{type:"button",onClick:r,className:"p-1.5 rounded text-[var(--text-dim)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card)] transition-colors cursor-pointer",title:"Open in new window",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),n.jsx("polyline",{points:"15 3 21 3 21 9"}),n.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}):e==="inline"?n.jsxs("button",{type:"button",onClick:r,className:"flex items-center gap-1.5 px-2.5 py-1 rounded border border-[var(--border-default)] bg-transparent text-xs text-[var(--text-muted)] hover:text-[var(--text-primary)] hover:border-[var(--accent-active)]/40 transition-colors cursor-pointer",title:"Open the full data editor in a new browser tab",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),n.jsx("polyline",{points:"15 3 21 3 21 9"}),n.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),"Open in new tab"]}):null}function ur(e){if(!e)return"Unsaved changes";const t=[];e.mocks.length>0&&t.push(`${e.mocks.length} mock${e.mocks.length===1?"":"s"}`);const r=e.seed.length;return r>0&&t.push(`${r} seed ${r===1?"table":"tables"}`),t.length>0?`Unsaved changes (${t.join(", ")})`:"Unsaved changes"}function fr({diff:e,saving:t,cancelling:r,error:s,onSave:o,onCancel:a}){return n.jsxs("div",{className:"flex items-center justify-between gap-2 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-1.5","data-testid":"scenario-draft-bar",children:[n.jsx("span",{className:"text-xs text-amber-300 font-medium",children:ur(e)}),n.jsxs("div",{className:"flex items-center gap-2",children:[s&&n.jsx("span",{className:"text-xs text-red-400",children:s}),n.jsx("button",{type:"button",onClick:a,disabled:r||t,className:"px-2 py-0.5 text-xs rounded border border-[var(--border-default)] bg-[var(--bg-surface)] text-[var(--text-primary)] hover:bg-[var(--bg-input)] disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer",children:r?"Discarding…":"Cancel"}),n.jsx("button",{type:"button",onClick:o,disabled:r||t,className:"px-3 py-0.5 text-xs rounded border border-[var(--accent-blue)] bg-[var(--accent-blue)]/20 text-[var(--accent-blue)] hover:bg-[var(--accent-blue)]/30 disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer",children:t?"Saving…":"Save"})]})]})}function pr({title:e,slug:t,provider:r,chatOpen:s,onToggleChat:o,variant:a,onClose:i,draftDirty:c,draftDiff:h,draftSaving:d,draftCancelling:g,draftError:p,onSave:l,onCancel:u}){const m=Ne(r),b=!!c&&!!l&&!!u;return n.jsxs("header",{className:"flex flex-col gap-2 border-b border-[var(--border-subtle)] bg-[var(--bg-deep)] px-4 py-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("div",{className:"min-w-0",children:n.jsxs("h2",{className:"text-sm font-medium text-[var(--text-primary)] truncate",children:["Scenario data: ",e]})}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(ar,{variant:a,providerLabel:m,chatOpen:s,onToggleChat:o}),n.jsx(lr,{panelSlug:t}),n.jsx(dr,{variant:a,slug:t}),i&&n.jsx(sr,{variant:a,onClose:i})]})]}),b&&l&&u&&n.jsx(fr,{diff:h??null,saving:d??!1,cancelling:g??!1,error:p??null,onSave:l,onCancel:u})]})}function xr(e,t){const[r,s]=x.useState(e.status??200),[o,a]=x.useState(e.body??null),[i,c]=x.useState(()=>Object.entries(e.headers??{}).map(([p,l])=>({name:p,value:l})));x.useEffect(()=>{s(e.status??200),a(e.body??null),c(Object.entries(e.headers??{}).map(([p,l])=>({name:p,value:l})))},[t,e.status,e.body,e.headers]);const h=x.useMemo(()=>e.headers??{},[e.headers]),d=x.useMemo(()=>{if((e.status??200)!==r||JSON.stringify(e.body??null)!==JSON.stringify(o))return!0;const p={};for(const b of i)b.name.trim()&&(p[b.name.trim()]=b.value);const l=h,u=Object.keys(l),m=Object.keys(p);if(u.length!==m.length)return!0;for(const b of m)if(l[b]!==p[b])return!0;return!1},[r,o,i,e.status,e.body,h]);return{status:r,setStatus:s,body:o,setBody:a,headers:i,setHeaders:c,isDirty:d,buildPayload:()=>{const p={};for(const l of i)l.name.trim()&&(p[l.name.trim()]=l.value);return{status:r,body:o,headers:p}}}}const hr=e=>navigator.clipboard.writeText(e);function mr(e={}){const{writer:t=hr,resetMs:r=2e3}=e,[s,o]=x.useState(!1),a=x.useRef(null),i=x.useCallback(async c=>{await t(c),o(!0),a.current!==null&&clearTimeout(a.current),a.current=setTimeout(()=>{o(!1),a.current=null},r)},[t,r]);return{copied:s,copy:i}}function br({body:e,onBodyChange:t}){const{copied:r,copy:s}=mr();async function o(){try{const i=await navigator.clipboard.readText(),c=JSON.parse(i);t(c)}catch{}}function a(){s(JSON.stringify(e,null,2))}return n.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[n.jsx("button",{type:"button",onClick:()=>void o(),className:"text-[10px] px-2 py-0.5 rounded border border-[var(--border-default)] bg-transparent text-[var(--text-muted)] hover:text-[var(--text-primary)] cursor-pointer",children:"Paste"}),n.jsx("button",{type:"button",onClick:a,className:"text-[10px] px-2 py-0.5 rounded border border-[var(--border-default)] bg-transparent text-[var(--text-muted)] hover:text-[var(--text-primary)] cursor-pointer",children:r?"Copied":"Copy"})]})}function X(e){return JSON.stringify(e)}function Pe(e,t){return e?e instanceof Set?e.has(t):e.includes(t):!1}function gr(e){const t=new Set;function r(s,o){if(s!==null&&typeof s=="object")if(t.add(X(o)),Array.isArray(s))s.forEach((a,i)=>r(a,[...o,i]));else for(const[a,i]of Object.entries(s))r(i,[...o,a])}return r(e,[]),t}function yr(e){return e===null?"text-slate-400 italic":typeof e=="string"?"text-emerald-300":typeof e=="number"?"text-amber-300":typeof e=="boolean"?"text-blue-300":"text-[var(--text-primary)]"}function vr(e){return e===null?"null":typeof e=="string"?`"${e}"`:String(e)}function jr(e){return e===null?"null":typeof e=="string"?e:String(e)}function wr(e){const t=e.trim();if(t==="")return"";if(t==="null")return null;if(t==="true")return!0;if(t==="false")return!1;try{return JSON.parse(t)}catch{return e}}function z(e){return JSON.parse(JSON.stringify(e))}function kr(e,t,r){if(t.length===0)return r;const s=z(e);let o=s;for(let a=0;a<t.length-1;a++)o=o[t[a]];return o[t[t.length-1]]=r,s}function le(e,t){if(t.length===0)return e;const r=z(e);let s=r;for(let a=0;a<t.length-1;a++)s=s[t[a]];const o=t[t.length-1];return Array.isArray(s)?s.splice(o,1):delete s[o],r}function Sr(e,t){const r=z(e);let s=r;for(const o of t)s=s[o];return Array.isArray(s)&&s.push(null),r}function Cr(e,t,r){const s=z(e);let o=s;for(const a of t)o=o[a];return o&&typeof o=="object"&&!Array.isArray(o)&&(o[r]=""),s}function Nr(e){if(typeof e!="string"||e.length===0||e!=="$"&&!e.startsWith("$.")&&!e.startsWith("$["))return null;const t=[];let r=e[0]==="$"?1:0;for(;r<e.length;){const s=e[r];if(s==="."){r+=1;const o=r;for(;r<e.length&&e[r]!=="."&&e[r]!=="[";)r+=1;const a=e.slice(o,r);if(a.length===0)return null;t.push(a)}else if(s==="["){const o=e.indexOf("]",r);if(o===-1)return null;const a=e.slice(r+1,o);if(a.length===0)return null;const i=Number(a);if(!Number.isInteger(i)||i<0)return null;t.push(i),r=o+1}else return null}return t}function Er(e,t){x.useEffect(()=>{if(!e)return;const r=Nr(e);r&&t(s=>{const o=new Set(s);for(let a=0;a<r.length;a++)o.add(X(r.slice(0,a)));return o})},[e,t])}function de({collapsible:e,isOpen:t,onToggle:r,parentKey:s,readOnly:o,onRemove:a,children:i}){return n.jsxs("div",{className:"group/row flex items-center gap-1 min-h-[1.5em] hover:bg-[var(--bg-card)]/30 rounded px-1",children:[e?n.jsx("button",{type:"button",onClick:r,className:"w-4 h-4 flex items-center justify-center text-[var(--text-dim)] hover:text-[var(--text-primary)] bg-transparent border-none cursor-pointer p-0","aria-label":t?"Collapse":"Expand",children:n.jsx("span",{className:"text-[10px]",children:t?"▾":"▸"})}):n.jsx("span",{className:"w-4"}),s!==null&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-cyan-300",children:typeof s=="number"?`[${s}]`:s}),n.jsx("span",{className:"text-[var(--text-dim)]",children:":"})]}),n.jsx("div",{className:"flex-1 min-w-0 flex items-center gap-1",children:i}),!o&&a&&n.jsx("button",{type:"button",onClick:a,className:"opacity-0 group-hover/row:opacity-100 text-[10px] text-[var(--text-dim)] hover:text-red-400 bg-transparent border-none cursor-pointer px-1",title:"Remove",children:"×"})]})}function Tr(e){const{value:t,path:r,parentKey:s,expanded:o,onToggle:a,readOnly:i}=e,c=X(r),h=Pe(o,c),d=t.length>0;return n.jsxs("div",{children:[n.jsxs(de,{collapsible:d,isOpen:h,onToggle:()=>a(c),parentKey:s,readOnly:i,onRemove:r.length>0?()=>e.onValueChange(le(e.rootValue,r)):null,children:[n.jsx("span",{className:"text-[var(--text-dim)]",children:"["}),!h&&n.jsxs(n.Fragment,{children:[d&&n.jsxs("span",{className:"text-[var(--text-dim)] italic",children:[" ","…",t.length," item",t.length===1?"":"s"," "]}),n.jsx("span",{className:"text-[var(--text-dim)]",children:"]"})]})]}),h&&n.jsxs("div",{className:"ml-4 border-l border-[var(--border-subtle)] pl-2",children:[t.map((g,p)=>x.createElement(ue,{...e,key:p,value:g,path:[...r,p],parentKey:p,isLast:p===t.length-1})),!i&&n.jsx("button",{type:"button",onClick:()=>e.onValueChange(Sr(e.rootValue,r)),className:"text-[10px] text-[var(--accent-blue)] hover:underline bg-transparent border-none cursor-pointer py-0.5",children:"+ Add item"})]}),h&&n.jsx("div",{className:"text-[var(--text-dim)]",children:"]"})]})}function Dr({onSave:e,onCancel:t}){const[r,s]=x.useState("");return n.jsxs("div",{className:"flex items-center gap-1 py-0.5",children:[n.jsx("span",{className:"text-[var(--text-dim)] text-[10px]",children:"+ key:"}),n.jsx("input",{autoFocus:!0,value:r,onChange:o=>s(o.target.value),onBlur:()=>e(r),onKeyDown:o=>{o.key==="Enter"?(o.preventDefault(),e(r)):o.key==="Escape"&&(o.preventDefault(),t())},placeholder:"keyName",className:"rounded border border-[var(--accent-active)]/50 bg-[var(--bg-surface)] px-1 py-0 text-xs font-mono text-[var(--text-primary)] min-w-[6rem]"})]})}function Or(e){const{value:t,path:r,parentKey:s,expanded:o,onToggle:a,readOnly:i,addingKeyAtPath:c,onStartAddKey:h,onStopAddKey:d}=e,g=X(r),p=Pe(o,g),l=Object.entries(t),u=l.length>0,m=c===g;return n.jsxs("div",{children:[n.jsxs(de,{collapsible:u,isOpen:p,onToggle:()=>a(g),parentKey:s,readOnly:i,onRemove:r.length>0?()=>e.onValueChange(le(e.rootValue,r)):null,children:[n.jsx("span",{className:"text-[var(--text-dim)]",children:"{"}),!p&&n.jsxs(n.Fragment,{children:[u&&n.jsxs("span",{className:"text-[var(--text-dim)] italic",children:[" ","…",l.length," key",l.length===1?"":"s"," "]}),n.jsx("span",{className:"text-[var(--text-dim)]",children:"}"})]})]}),p&&n.jsxs("div",{className:"ml-4 border-l border-[var(--border-subtle)] pl-2",children:[l.map(([b,y],f)=>x.createElement(ue,{...e,key:b,value:y,path:[...r,b],parentKey:b,isLast:f===l.length-1})),!i&&!m&&n.jsx("button",{type:"button",onClick:()=>h(g),className:"text-[10px] text-[var(--accent-blue)] hover:underline bg-transparent border-none cursor-pointer py-0.5",children:"+ Add key"}),!i&&m&&n.jsx(Dr,{onSave:b=>{b.trim()&&e.onValueChange(Cr(e.rootValue,r,b.trim())),d()},onCancel:d})]}),p&&n.jsx("div",{className:"text-[var(--text-dim)]",children:"}"})]})}function Mr({initial:e,onSave:t,onCancel:r}){const[s,o]=x.useState(e);return n.jsx("input",{autoFocus:!0,value:s,onChange:a=>o(a.target.value),onBlur:()=>t(s),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),t(s)):a.key==="Escape"&&(a.preventDefault(),r())},className:"flex-1 min-w-[4rem] rounded border border-[var(--accent-active)]/50 bg-[var(--bg-surface)] px-1 py-0 text-xs font-mono text-[var(--text-primary)]"})}function $r(e){const{value:t,path:r,parentKey:s,readOnly:o,editingPath:a,onStartEdit:i,onStopEdit:c}=e,h=X(r),d=a===h;return n.jsx(de,{collapsible:!1,isOpen:!1,parentKey:s,readOnly:o,onToggle:()=>{},onRemove:r.length>0?()=>e.onValueChange(le(e.rootValue,r)):null,children:d?n.jsx(Mr,{initial:jr(t),onSave:g=>{const p=wr(g);e.onValueChange(kr(e.rootValue,r,p)),c()},onCancel:c}):n.jsx("button",{type:"button",onClick:o?void 0:()=>i(h),disabled:o,className:`${o?"":"hover:bg-[var(--bg-card)] cursor-pointer"} bg-transparent border-none px-1 py-0 rounded ${yr(t)} text-left font-mono`,title:o?void 0:"Click to edit",children:vr(t)})})}function ue(e){const{value:t}=e;return Array.isArray(t)?n.jsx(Tr,{...e,value:t}):t!==null&&typeof t=="object"?n.jsx(Or,{...e,value:t}):n.jsx($r,{...e})}function Re({value:e,onChange:t,readOnly:r=!1,focusJsonPath:s}){const[o,a]=x.useState(()=>gr(e)),[i,c]=x.useState(null),[h,d]=x.useState(null);Er(s,a);function g(p){a(l=>{const u=new Set(l);return u.has(p)?u.delete(p):u.add(p),u})}return n.jsx("div",{className:"flex flex-col h-full min-h-0",children:n.jsx("div",{className:"flex-1 min-h-0 overflow-auto font-mono text-xs leading-relaxed text-[var(--text-primary)] bg-[var(--bg-input)] border border-[var(--border-default)] rounded p-3",children:n.jsx(ue,{value:e,path:[],parentKey:null,isLast:!0,readOnly:r,expanded:o,editingPath:i,addingKeyAtPath:h,onToggle:g,onStartEdit:c,onStopEdit:()=>c(null),onStartAddKey:d,onStopAddKey:()=>d(null),onValueChange:t,rootValue:e})})})}function Ar({headers:e,onChange:t}){function r(a,i){t(e.map((c,h)=>h===a?{...c,...i}:c))}function s(){t([...e,{name:"",value:""}])}function o(a){t(e.filter((i,c)=>c!==a))}return n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("label",{className:"text-xs text-[var(--text-muted)]",children:"Headers"}),n.jsx("button",{type:"button",onClick:s,className:"text-xs text-[var(--accent-blue)] hover:underline bg-transparent border-none cursor-pointer",children:"+ Add"})]}),e.length===0&&n.jsx("p",{className:"text-xs text-[var(--text-dim)] italic",children:"No headers"}),e.map((a,i)=>n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{value:a.name,onChange:c=>r(i,{name:c.target.value}),placeholder:"Name",className:"flex-1 rounded border border-[var(--border-default)] bg-[var(--bg-surface)] px-2 py-1 text-xs font-mono"}),n.jsx("input",{value:a.value,onChange:c=>r(i,{value:c.target.value}),placeholder:"Value",className:"flex-1 rounded border border-[var(--border-default)] bg-[var(--bg-surface)] px-2 py-1 text-xs font-mono"}),n.jsx("button",{type:"button",onClick:()=>o(i),className:"px-2 text-xs text-[var(--text-dim)] hover:text-red-400 bg-transparent border-none cursor-pointer",children:"×"})]},i))]})}const re=5;function Pr(e,t){if(e==="loading")return"Computing impact…";if(e==null)return"";if(t.kind==="scenario")return"Affects only this scenario.";if(e.length===0)return"Affects no other scenarios.";const r=e.length===1?"scenario":"scenarios",s=e.slice(0,re).join(", "),o=e.length>re?`, +${e.length-re} more`:"";return`Affects ${e.length} ${r}: ${s}${o}`}function Rr(e){const t=[{label:"This scenario only",description:"Write to this scenario's mocks file. The row's source flips to scenario.",scope:{kind:"scenario"}}];return e.source==="shared"&&e.sharedSlug&&t.push({label:`Shared data set "${e.sharedSlug}"`,description:"Write to the shared set this row came from. Affects every scenario opted into it.",scope:{kind:"shared",slug:e.sharedSlug}}),(e.source==="default"||e.source==="shared")&&t.push({label:"Defaults",description:"Write to _default.json. Affects every scenario that falls through to defaults for this route.",scope:{kind:"default"}}),t}function Ir(e,t){if(e.source==="default"){const r=t.findIndex(s=>s.scope.kind==="default");if(r>=0)return r}if(e.source==="shared"){const r=t.findIndex(s=>s.scope.kind==="shared"&&s.scope.slug===(e.sharedSlug??""));if(r>=0)return r}return 0}function Lr(e,t,r){const[s,o]=x.useState({}),a=r.map(i=>K(i.scope)).join("|");return x.useEffect(()=>{let i=!1;return(async()=>{const h={};for(const d of r)h[K(d.scope)]="loading";o(h);for(const d of r)try{const g=await Qe(e,t,d.scope);if(i)return;o(p=>({...p,[K(d.scope)]:g}))}catch{if(i)return;o(g=>({...g,[K(d.scope)]:[]}))}})(),()=>{i=!0}},[e,t,a]),s}function Kr({choice:e,selected:t,impactLabel:r,onSelect:s}){return n.jsxs("label",{className:`flex cursor-pointer flex-col rounded border p-3 text-xs transition-colors ${t?"border-violet-500 bg-violet-500/10":"border-[var(--border-subtle)] hover:bg-[var(--bg-elevated)]"}`,children:[n.jsxs("span",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"radio",name:"save-scope",checked:t,onChange:s}),n.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:e.label})]}),n.jsx("span",{className:"mt-1 pl-6 text-[var(--text-muted)]",children:e.description}),n.jsx("span",{className:"mt-1 pl-6 text-[var(--text-dim)] italic",children:r})]})}function Br({entry:e,scenarioSlug:t,routeKey:r,onCancel:s,onConfirm:o}){const a=Rr(e),[i,c]=x.useState(()=>Ir(e,a)),h=Lr(t,r,a),[d,g]=x.useState(!1),[p,l]=x.useState(null),u=async()=>{const m=a[i];if(m){g(!0),l(null);try{await o(m.scope)}catch(b){l(b instanceof Error?b.message:"Save failed")}finally{g(!1)}}};return n.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"save-scope-modal-title",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",children:n.jsxs("div",{className:"w-[28rem] max-w-[90vw] rounded-lg border border-[var(--border-default)] bg-[var(--bg-surface)] p-5 shadow-xl",children:[n.jsx("h2",{id:"save-scope-modal-title",className:"text-sm font-semibold text-[var(--text-primary)]",children:"Where should this save land?"}),n.jsx("p",{className:"mt-1 text-xs text-[var(--text-muted)]",children:r}),n.jsx("div",{className:"mt-4 space-y-2",children:a.map((m,b)=>n.jsx(Kr,{choice:m,selected:i===b,impactLabel:Pr(h[K(m.scope)],m.scope),onSelect:()=>c(b)},K(m.scope)))}),p&&n.jsx("p",{className:"mt-3 text-xs text-red-400",role:"alert",children:p}),n.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:s,disabled:d,className:"rounded border border-[var(--border-default)] px-3 py-1.5 text-xs text-[var(--text-primary)] hover:bg-[var(--bg-elevated)] disabled:opacity-50",children:"Cancel"}),n.jsx("button",{type:"button",onClick:()=>void u(),disabled:d,className:"rounded bg-violet-500 px-3 py-1.5 text-xs font-medium text-white hover:bg-violet-400 disabled:opacity-50",children:d?"Saving…":"Save"})]})]})})}function Yr({entry:e,routeKey:t,scenarioSlug:r,onSave:s,focusJsonPath:o}){const a=xr(e,t),[i,c]=x.useState(null),[h,d]=x.useState(!1),[g,p]=x.useState(!1);x.useEffect(()=>{c(null),p(!1)},[t]);const l=async m=>{d(!0),c(null);try{const b=a.buildPayload();await s({routeKey:t,...b,scope:m})}catch(b){throw c(b instanceof Error?b.message:"Save failed"),b}finally{d(!1)}},u=async()=>{if(a.isDirty){if(e.source==="scenario"){try{await l({kind:"scenario"})}catch{}return}p(!0)}};return n.jsxs("div",{className:"flex flex-col gap-3 h-full min-h-0",children:[i&&n.jsx("p",{className:"text-xs text-red-400",children:i}),n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsx("label",{className:"text-xs text-[var(--text-muted)]",children:"Status"}),n.jsx("input",{type:"number",value:a.status,onChange:m=>a.setStatus(Number(m.target.value)),className:"w-20 rounded border border-[var(--border-default)] bg-[var(--bg-surface)] px-2 py-1 text-xs font-mono"}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{type:"button",onClick:()=>void u(),disabled:!a.isDirty||h,className:"rounded bg-violet-500 px-3 py-1 text-xs font-medium text-white hover:bg-violet-400 disabled:opacity-50",children:h?"Saving…":a.isDirty?"Save changes":"Saved"})]}),n.jsx(Ar,{headers:a.headers,onChange:a.setHeaders}),n.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[n.jsxs("div",{className:"flex items-center gap-2 pb-1",children:[n.jsx("label",{className:"text-xs text-[var(--text-muted)]",children:"Body"}),n.jsx(br,{body:a.body,onBodyChange:a.setBody})]}),n.jsx(Re,{value:a.body,onChange:a.setBody,focusJsonPath:o},t)]}),g&&n.jsx(Br,{entry:e,scenarioSlug:r,routeKey:t,onCancel:()=>p(!1),onConfirm:async m=>{await l(m),p(!1)}})]})}function Hr(e,t){if(e==null)return"never";const r=Math.max(0,Math.floor((t-e)/1e3));if(r<60)return`${r}s ago`;const s=Math.floor(r/60);return s<60?`${s}m ago`:`${Math.floor(s/60)}h ago`}const Ce={GET:"text-emerald-400 border-emerald-400/40",POST:"text-blue-400 border-blue-400/40",PUT:"text-amber-400 border-amber-400/40",PATCH:"text-purple-400 border-purple-400/40",DELETE:"text-red-400 border-red-400/40"};function Vr(e){return Ce[e]??Ce.GET}function _r({entry:e,scenarioHasDefaultFallback:t,onSave:r,onRemove:s,onPassthrough:o}){const a=`${e.method} ${e.pathPattern}`,i=Vr(e.method),c=e.status??e.lastObservedStatus,h=x.useMemo(()=>e.lastObservedMs?Hr(e.lastObservedMs,Date.now()):null,[e.lastObservedMs]),d="px-3 py-1 rounded border border-[var(--border-default)] bg-transparent text-[var(--text-muted)] hover:text-[var(--text-primary)] cursor-pointer text-xs";return n.jsxs("header",{className:"border-b border-[var(--border-subtle)] bg-[var(--bg-deep)] px-4 py-3 space-y-2 flex-shrink-0",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:`px-2 py-0.5 rounded border font-mono text-xs ${i}`,children:e.method}),n.jsx("span",{className:"font-mono text-sm text-[var(--text-primary)] break-all",children:e.pathPattern}),n.jsx(De,{source:e.source}),c!==void 0&&n.jsx("span",{className:"px-1.5 py-0.5 rounded border border-[var(--border-default)] text-[var(--text-muted)] font-mono text-xs",children:c}),e.observedCount>0&&n.jsxs("span",{className:"ml-auto text-xs text-[var(--text-dim)]",children:[e.observedCount,"× ",h?`· ${h}`:""]})]}),e.variants.length>1&&n.jsxs("div",{className:"text-[10px] text-[var(--text-dim)] font-mono",children:["variants: ",e.variants.filter(g=>g!==a).join(", ")]}),n.jsxs("div",{className:"flex flex-wrap gap-2 pt-1",children:[e.source==="scenario"&&t&&n.jsx("button",{onClick:()=>void s(a),className:d,title:"Remove this scenario mock and fall back to the default",children:"Revert to default"}),e.source==="scenario"&&n.jsx("button",{onClick:()=>void o(a),className:d,children:"Mark passthrough"}),e.source==="default"&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>void r({routeKey:a,status:e.status??200,body:e.body,headers:e.headers??{},scope:{kind:"scenario"}}),className:"px-3 py-1 rounded border border-emerald-500/50 bg-emerald-500/10 text-emerald-300 hover:bg-emerald-500/20 cursor-pointer text-xs",title:"Copy default body into this scenario",children:"Promote to scenario"}),n.jsx("button",{onClick:()=>void o(a),className:d,children:"Mark passthrough"})]}),e.source==="passthrough"&&n.jsx("button",{onClick:()=>void s(a),className:d,children:"Undo passthrough"})]})]})}function Xr({entry:e}){const t=Object.entries(e.headers??{}),r=e.body!==void 0&&e.body!==null;return!r&&t.length===0?n.jsx("p",{className:"text-xs italic text-[var(--text-dim)]",children:e.source==="catalog-only"?"No mock body yet — this endpoint has only been observed, not mocked. Promote it to a scenario to start editing.":e.source==="passthrough"?"This endpoint passes through to the upstream service.":"No body configured."}):n.jsxs("div",{className:"space-y-3 h-full min-h-0 flex flex-col",children:[t.length>0&&n.jsxs("section",{className:"space-y-1 flex-shrink-0",children:[n.jsx("h4",{className:"text-xs font-medium uppercase tracking-wide text-[var(--text-dim)]",children:"Headers"}),n.jsx("dl",{className:"text-xs font-mono space-y-0.5",children:t.map(([s,o])=>n.jsxs("div",{className:"flex gap-2",children:[n.jsxs("dt",{className:"text-[var(--text-muted)]",children:[s,":"]}),n.jsx("dd",{className:"text-[var(--text-primary)] break-all",children:o})]},s))})]}),r&&n.jsxs("section",{className:"flex-1 min-h-0 flex flex-col",children:[n.jsx("h4",{className:"text-xs font-medium uppercase tracking-wide text-[var(--text-dim)] pb-1",children:"Body"}),n.jsx(Re,{value:e.body,onChange:()=>{},readOnly:!0},`${e.method} ${e.pathPattern}`)]})]})}function Fr({entry:e,scenarioSlug:t,scenarioHasDefaultFallback:r,onSave:s,onRemove:o,onPassthrough:a,focusJsonPath:i}){const c=`${e.method} ${e.pathPattern}`,h=e.source==="scenario"||e.source==="default"||e.source==="shared";return n.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[n.jsx(_r,{entry:e,scenarioHasDefaultFallback:r,onSave:s,onRemove:o,onPassthrough:a}),n.jsx("div",{className:"flex-1 min-h-0 overflow-auto p-4",children:h?n.jsx(Yr,{entry:e,routeKey:c,scenarioSlug:t,onSave:s,focusJsonPath:i}):n.jsx(Xr,{entry:e})})]})}function Jr({slug:e,tab:t,initialRows:r,onCellEdited:s}){const[o,a]=x.useState(r),[i,c]=x.useState(null),[h,d]=x.useState(""),[g,p]=x.useState(""),l=x.useRef(null);x.useEffect(()=>{a(r),c(null)},[t.dataKey,r]);function u(v,j){const k=o[v];c({row:v,col:j});const D=k[j]===null?"":typeof k[j]=="object"?JSON.stringify(k[j]):String(k[j]);d(D),p(D)}function m(v){if(d(v),l.current&&clearTimeout(l.current),!i)return;const j=i;l.current=setTimeout(()=>{f(j.row,j.col,v)},600)}function b(){i&&(l.current&&clearTimeout(l.current),f(i.row,i.col,h),c(null))}function y(){if(l.current&&clearTimeout(l.current),!!i){if(h!==g){const v=[...o];v[i.row]={...v[i.row],[i.col]:me(g)},a(v),fetch(`/api/scenarios/${encodeURIComponent(e)}/data`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({table:t.dataKey,rowIndex:i.row,column:i.col,value:g})}).then(()=>{_(),s&&s()}).catch(()=>{})}c(null)}}async function f(v,j,k){const D=[...o];D[v]={...D[v],[j]:me(k)},a(D);try{await fetch(`/api/scenarios/${encodeURIComponent(e)}/data`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({table:t.dataKey,rowIndex:v,column:j,value:k})}),_(),s&&s()}catch{}}return{rows:o,editingCell:i,editValue:h,handleEditCell:u,handleEditValueChange:m,handleSave:b,handleCancelEdit:y}}function Ur({tab:e}){return!e.description&&!e.category?null:n.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-[var(--bg-deep)] border-b border-[var(--border-subtle)]",children:[e.category&&n.jsx("span",{className:`text-[9px] rounded px-1.5 py-0 border ${e.category==="datastore"?"text-[var(--accent-active)]/80 bg-[var(--accent-active)]/10 border-[var(--accent-active)]/30":e.category==="mock-api"?"text-blue-400/80 bg-blue-400/10 border-blue-400/30":"text-[var(--text-muted)] bg-[var(--bg-surface)]/30 border-[var(--text-dim)]/30"}`,children:e.category==="mock-api"?"API Mock":e.category}),e.description&&n.jsx("span",{className:"text-[10px] text-[var(--text-dim)]",children:e.description})]})}function zr({editingCell:e,editValue:t,onEditValueChange:r,onSave:s,onCancel:o}){return n.jsxs("div",{className:"border-t border-[var(--border-default)] bg-[var(--bg-deep)] px-3 py-2",children:[n.jsx("div",{className:"flex items-center gap-2 mb-1.5",children:n.jsxs("span",{className:"text-[10px] text-[var(--text-muted)]",children:["Editing"," ",n.jsx("strong",{className:"text-[var(--text-secondary)]",children:e.col})," ","in row ",e.row+1]})}),n.jsx("textarea",{value:t,onChange:a=>r(a.target.value),className:"w-full px-2 py-1.5 text-[11px] bg-[var(--bg-card)] text-[var(--text-primary)] border border-[var(--border-default)] rounded outline-none focus:border-[var(--accent-active)]/50 resize-y min-h-[60px] max-h-[200px] font-mono",autoFocus:!0,rows:t.length>100?4:2,onKeyDown:a=>{a.key==="Escape"&&o(),a.key==="Enter"&&(a.metaKey||a.ctrlKey)&&s()}}),n.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[n.jsx("button",{onClick:s,className:"px-3 py-1 text-[10px] font-medium text-[var(--bg-deep)] bg-[var(--accent-active)] rounded cursor-pointer border-none hover:bg-[var(--accent-active)]/80 transition-colors",children:"Save"}),n.jsx("button",{onClick:o,className:"px-3 py-1 text-[10px] text-[var(--text-muted)] hover:text-[var(--text-primary)] bg-transparent border-none cursor-pointer",children:"Cancel"}),n.jsxs("span",{className:"text-[9px] text-[var(--text-dim)] ml-auto",children:["⌘","+Enter to save, Esc to cancel"]})]})]})}function Wr({columns:e,colTypes:t,pkCol:r,rows:s,onEditCell:o}){return e.length===0?n.jsx("div",{className:"px-3 py-4 text-[10px] text-[var(--text-dim)] text-center",children:"No columns defined for this table"}):n.jsx("div",{className:"overflow-x-auto max-h-[300px] overflow-y-auto",children:n.jsxs("table",{className:"w-full text-[10px] border-collapse table-fixed",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"bg-[var(--bg-deep)] sticky top-0 z-10",children:[n.jsx("th",{className:"text-right text-[var(--text-dim)] font-normal px-2 py-1.5 border-b border-[var(--border-default)] w-8",children:"#"}),e.map(a=>n.jsx(qr,{name:a,type:t[a],isPk:a===r},a))]})}),n.jsx("tbody",{children:s.map((a,i)=>n.jsx(Gr,{row:a,rowIndex:i,columns:e,pkCol:r,onEditCell:o},i))})]})})}function qr({name:e,type:t,isPk:r}){return n.jsxs("th",{className:"text-left px-2 py-1.5 border-b border-[var(--border-default)] whitespace-nowrap overflow-hidden",children:[r&&n.jsx("span",{className:"inline-block text-[8px] font-bold text-[var(--bg-deep)] bg-[var(--accent-active)] rounded px-1 py-0 mr-1.5 align-middle",children:"PK"}),n.jsx("span",{className:"text-[var(--text-secondary)] font-medium",children:e}),n.jsx("span",{className:"text-[var(--text-dim)] font-normal ml-1",children:t})]})}function Gr({row:e,rowIndex:t,columns:r,pkCol:s,onEditCell:o}){return n.jsxs("tr",{className:"border-b border-[var(--border-subtle)] hover:bg-[var(--bg-card)] group/row",children:[n.jsx("td",{className:"text-right text-[var(--text-dim)] px-2 py-1.5 w-8 select-none",children:t+1}),r.map(a=>n.jsx(Qr,{value:e[a],isPk:a===s,onEdit:()=>o(t,a)},a))]})}function Qr({value:e,isPk:t,onEdit:r}){return n.jsxs("td",{className:`px-2 py-1.5 overflow-hidden relative group/cell ${t?"text-[var(--accent-active)] font-medium":"text-[var(--text-secondary)]"}`,title:String(e??""),children:[n.jsx("span",{className:"truncate block whitespace-nowrap",children:e===null?n.jsx("span",{className:"text-[var(--text-dim)] italic",children:"null"}):typeof e=="object"?n.jsx("span",{className:"text-[var(--text-dim)]",children:JSON.stringify(e)}):typeof e=="number"?n.jsx("span",{className:"text-amber-400",children:String(e)}):String(e)}),n.jsx("button",{onClick:s=>{s.stopPropagation(),r()},className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 group-hover/cell:opacity-100 text-[var(--text-dim)] hover:text-[var(--text-primary)] bg-[var(--bg-card)] border border-[var(--border-default)] rounded cursor-pointer p-0.5 transition-opacity",title:"Edit",children:n.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})]})}function Zr({slug:e,tab:t,initialRows:r,onCellEdited:s}){const{rows:o,editingCell:a,editValue:i,handleEditCell:c,handleEditValueChange:h,handleSave:d,handleCancelEdit:g}=Jr({slug:e,tab:t,initialRows:r,onCellEdited:s}),p=st(o,t.schemaFields),l=at(p,o,t.schemaFields),u=ot(p,t.schemaFields);return n.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[n.jsx(Ur,{tab:t}),n.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:n.jsx(Wr,{columns:p,colTypes:l,pkCol:u,rows:o,onEditCell:c})}),a&&n.jsx(zr,{editingCell:a,editValue:i,onEditValueChange:h,onSave:d,onCancel:g})]})}function ne({label:e,active:t,onClick:r}){return n.jsx("button",{type:"button",onClick:r,className:`px-2 py-0.5 rounded-full border text-[10px] font-mono transition-colors cursor-pointer ${t?"bg-violet-500/25 text-violet-100 border-violet-400/70":"bg-violet-500/10 text-violet-300 border-violet-500/40 hover:bg-violet-500/20"}`,"aria-pressed":t,children:e})}function en({shares:e,activeBadge:t,onSelect:r}){return n.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap border-b border-[var(--border-subtle)] bg-[var(--bg-deep)] px-4 py-2","data-testid":"scenario-mock-data-strip",children:[n.jsx("span",{className:"text-[10px] uppercase tracking-wider text-[var(--text-dim)] font-semibold",children:"Mock Data:"}),n.jsx(ne,{label:"This Page",active:t.kind==="this-page",onClick:()=>r({kind:"this-page"})}),e.map(s=>n.jsx(ne,{label:s,active:t.kind==="share"&&t.slug===s,onClick:()=>r({kind:"share",slug:s})},s)),n.jsx(ne,{label:"Defaults",active:t.kind==="defaults",onClick:()=>r({kind:"defaults"})})]})}function un({slug:e,scenarioName:t,initialSection:r,onClose:s,variant:o="slideOver"}){const{data:a,tableTabs:i,scenarioOwnedDataKeys:c,shares:h,loading:d,error:g}=ft(e),{entries:p,loading:l,error:u,upsertScoped:m,remove:b,setPassthrough:y}=et(e),{config:f}=Ee(),v=(f==null?void 0:f.provider)??"claude",j=mt({slug:e,onPreviewReload:_}),k=x.useCallback(()=>{j.markDirty(),_()},[j]),D=x.useCallback(async N=>{await m(N),k()},[m,k]),R=x.useCallback(async N=>{await b(N),k()},[b,k]),A=x.useCallback(async N=>{await y(N),k()},[y,k]),M=x.useCallback(()=>{j.markDirty(),_()},[j]),C=x.useCallback(()=>{s&&j.confirmIfDirty("Discard unsaved changes to this scenario?")&&s()},[s,j]),[E,P]=x.useState(null),[O,S]=x.useState(null),[w,T]=x.useState(!1),$=x.useCallback(N=>P({kind:"mock",routeKey:N}),[]);Je({onSelect:$,onFocus:S});const[I,W]=x.useState({kind:"this-page"}),q=d||l,B=x.useMemo(()=>o==="inline"?i.filter(N=>c.has(N.dataKey)):i,[o,i,c]),Y=x.useMemo(()=>{if(o!=="inline")return p;switch(I.kind){case"this-page":return p.filter(N=>N.consumedThisPageLoad);case"defaults":return p.filter(N=>N.source==="default");case"share":return p.filter(N=>N.source==="shared"&&N.sharedSlug===I.slug)}},[o,p,I]);Dt({seedTabs:B,mockEntries:Y,initialSection:r,selection:E,setSelection:P});const Ie=x.useMemo(()=>{const N=new Set;for(const fe of p)fe.source==="default"&&N.add(V(fe));return N},[p]),L=(E==null?void 0:E.kind)==="seed"?B.find(N=>N.dataKey===E.dataKey)??null:null,H=(E==null?void 0:E.kind)==="mock"?Y.find(N=>V(N)===E.routeKey)??null:null,G=L&&a?a[L.dataKey]??[]:[],Le=x.useMemo(()=>_e({slug:e,scenarioName:t,seedTabs:B,mockEntries:Y,selectedMock:H,selectedSeedTab:L,selectedSeedRows:G}),[e,t,B,Y,H,L,G]),Ke=t??e,Q=B.length>0||Y.length>0,Z=n.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[n.jsx(pr,{title:Ke,slug:e,provider:v,chatOpen:w,onToggleChat:()=>T(N=>!N),variant:o,onClose:s?C:void 0,draftDirty:j.isDirty,draftDiff:j.diffSummary,draftSaving:j.saving,draftCancelling:j.cancelling,draftError:j.error,onSave:()=>void j.save(),onCancel:()=>void j.cancel()}),o==="inline"&&n.jsx(en,{shares:h,activeBadge:I,onSelect:W}),w&&n.jsx("div",{className:"flex-shrink-0 border-b border-[var(--border-subtle)] bg-[var(--bg-deep)]",children:n.jsx(rr,{prompt:Le,height:360,onClose:()=>T(!1)})}),n.jsxs("div",{className:"flex flex-1 min-h-0",children:[n.jsx(Et,{seedTabs:B,mockEntries:Y,selection:E,onSelect:P}),n.jsx("main",{className:"flex-1 min-w-0 min-h-0 bg-[var(--bg-deep)] flex flex-col",children:n.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[g&&n.jsxs("p",{className:"p-4 text-xs text-red-400",children:["Seed error: ",g]}),u&&n.jsxs("p",{className:"p-4 text-xs text-red-400",children:["Mocks error: ",u]}),!q&&!Q&&n.jsx(nr,{}),L&&n.jsx(Zr,{slug:e,tab:L,initialRows:G,onCellEdited:M}),H&&n.jsx(Fr,{entry:H,scenarioSlug:e,scenarioHasDefaultFallback:Ie.has(V(H)),onSave:D,onRemove:R,onPassthrough:A,focusJsonPath:O}),!L&&!H&&Q&&!q&&n.jsx("p",{className:"p-4 text-xs text-[var(--text-dim)] italic",children:"Select a data source from the left to view it."}),q&&!Q&&n.jsx("p",{className:"p-4 text-xs text-[var(--text-dim)]",children:"Loading scenario data…"})]})})]})]});return o==="fullPage"?n.jsx("div",{className:"fixed inset-0 bg-[var(--bg-deep)] text-[var(--text-primary)]",children:Z}):o==="inline"?n.jsx("div",{className:"rounded-md border border-[var(--border-subtle)] bg-[var(--bg-deep)] max-h-[min(640px,70vh)] min-h-0 flex flex-col overflow-hidden",children:Z}):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-40 bg-black/40",onClick:C,"aria-label":"Close scenario data panel"}),n.jsx("aside",{className:"fixed right-0 top-0 z-50 h-full w-full max-w-4xl border-l border-[var(--border-default)] bg-[var(--bg-deep)] shadow-2xl",children:Z})]})}export{$e as $,pr as A,nr as B,ar as C,sr as D,Wr as E,zr as F,Ur as G,wt as H,jt as I,$r as J,Zt as K,Qt as L,Ar as M,Gt as N,tr as O,Ne as P,Oe as Q,Bt as R,un as S,er as T,te as U,Kt as V,Ot as W,Mt as X,_t as Y,Wt as Z,$t as _,De as a,qt as a0,Ee as a1,me as a2,_ as a3,mt as a4,ft as a5,et as a6,mr as a7,Ze as a8,on as a9,dn as aa,ln as ab,cn as ac,Ue as ad,rr as b,Mr as c,Or as d,de as e,Hr as f,ue as g,Re as h,Tr as i,Dr as j,br as k,fr as l,kt as m,Ct as n,Br as o,Kr as p,Et as q,en as r,ne as s,dr as t,Zr as u,Xr as v,_r as w,Yr as x,Fr as y,lr as z};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2014 The xterm.js authors. All rights reserved.
|
|
3
|
+
* Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
|
|
4
|
+
* https://github.com/chjj/term.js
|
|
5
|
+
* @license MIT
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
|
15
|
+
* all copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
* THE SOFTWARE.
|
|
24
|
+
*
|
|
25
|
+
* Originally forked from (with the author's permission):
|
|
26
|
+
* Fabrice Bellard's javascript vt100 for jslinux:
|
|
27
|
+
* http://bellard.org/jslinux/
|
|
28
|
+
* Copyright (c) 2011 Fabrice Bellard
|
|
29
|
+
* The original design remains. The terminal itself
|
|
30
|
+
* has been extended to include xterm CSI codes, among
|
|
31
|
+
* other features.
|
|
32
|
+
*/.xterm{cursor:text;position:relative;user-select:none;-ms-user-select:none;-webkit-user-select:none}.xterm.focus,.xterm:focus{outline:none}.xterm .xterm-helpers{position:absolute;top:0;z-index:5}.xterm .xterm-helper-textarea{padding:0;border:0;margin:0;position:absolute;opacity:0;left:-9999em;top:0;width:0;height:0;z-index:-5;white-space:nowrap;overflow:hidden;resize:none}.xterm .composition-view{background:#000;color:#fff;display:none;position:absolute;white-space:nowrap;z-index:1}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{background-color:#000;overflow-y:scroll;cursor:default;position:absolute;right:0;left:0;top:0;bottom:0}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{position:absolute;left:0;top:0}.xterm .xterm-scroll-area{visibility:hidden}.xterm-char-measure-element{display:inline-block;visibility:hidden;position:absolute;top:0;left:-9999em;line-height:normal}.xterm.enable-mouse-events{cursor:default}.xterm.xterm-cursor-pointer,.xterm .xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{position:absolute;left:0;top:0;bottom:0;right:0;z-index:10;color:transparent;pointer-events:none}.xterm .xterm-accessibility-tree:not(.debug) *::selection{color:transparent}.xterm .xterm-accessibility-tree{-webkit-user-select:text;user-select:text;white-space:pre}.xterm .live-region{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{text-decoration:double underline}.xterm-underline-3{text-decoration:wavy underline}.xterm-underline-4{text-decoration:dotted underline}.xterm-underline-5{text-decoration:dashed underline}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:overline underline}.xterm-overline.xterm-underline-2{text-decoration:overline double underline}.xterm-overline.xterm-underline-3{text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{z-index:6;position:absolute}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{z-index:8;position:absolute;top:0;right:0;pointer-events:none}.xterm-decoration-top{z-index:2;position:relative}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as c}from"./markdown-v0F0UEt3.js";import{b as o}from"./react-CSS0HapR.js";import{S as m}from"./ScenarioDataPanel-Bb7egwjC.js";import"./useEvents-DggWrtHe.js";import"./xterm--24IGk-x.js";import"./index-6jueUhB_.js";function S({slug:t}){const[r,i]=o.useState(void 0);return o.useEffect(()=>{let n=!1;return fetch(`/api/scenarios/${encodeURIComponent(t)}`).then(e=>e.ok?e.json():null).then(e=>{if(n||!e)return;const a=typeof e=="object"&&e!==null&&"name"in e?String(e.name):void 0;i(a),a&&(document.title=`${a} · data`)}).catch(()=>{}),()=>{n=!0}},[t]),c.jsx(m,{slug:t,scenarioName:r,variant:"fullPage"})}export{S as ScenarioDataPanelFullPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./markdown-v0F0UEt3.js";import{b as d}from"./react-CSS0HapR.js";import{c as xe,C as L,S as H,f as ue,T as F,e as me,N as D,b as pe,a as A,r as he,d as _,R as k,p as be,g as $,I as ve,h as fe,i as ge,j as je,k as ye,l as Se,m as Ne,n as Pe,o as Ce,q as we,s as Te,t as Re,u as Ee,v as De,w as ke,x as Be,y as Me,E as Oe,z as Ie,A as Le,B as He,D as Fe,F as Ae,G as _e,H as $e,J as Ve,K as Je,L as Ge,M as qe,P as ze,O as Ue,Q as We,U as Ke,V as Qe,W as Ye,X as Xe,Y as Ze,Z as et,_ as tt,$ as at,a0 as st,a1 as rt,a2 as nt,a3 as ot,a4 as it,a5 as lt,a6 as ct,a7 as dt,a8 as xt,a9 as ut,aa as mt,ab as pt,ac as ht,ad as bt,ae as vt,af as ft,ag as gt,ah as jt,ai as yt,aj as St,ak as Nt,al as Pt,am as Ct,an as wt,ao as Tt,ap as Rt,aq as Et,ar as Dt,as as kt,at as Bt,au as Mt,av as Ot,aw as It,ax as Lt,ay as Ht,az as Ft,aA as At,aB as _t,aC as $t,aD as Vt,aE as Jt,aF as Gt,aG as qt,aH as zt,aI as Ut,aJ as Wt,aK as Kt,aL as Qt,aM as Yt,aN as Xt,aO as Zt,aP as ea,aQ as ta,aR as aa,aS as sa,aT as ra,aU as na,aV as oa,aW as ia,aX as la,aY as ca,aZ as da,a_ as xa,a$ as ua,b0 as ma,b1 as pa,b2 as ha,b3 as ba,b4 as va,b5 as fa,b6 as ga,b7 as ja,b8 as ya,b9 as Sa,ba as Na,bb as Pa,bc as Ca,bd as wa,be as Ta,bf as Ra,bg as Ea,bh as Da,bi as ka,bj as Ba,bk as Ma,bl as Oa,bm as Ia,bn as La,bo as Ha,bp as Fa,bq as Aa,br as _a,bs as $a,bt as Va,bu as Ja,bv as Ga,bw as qa,bx as za,by as Ua,bz as Wa,bA as Ka,bB as Qa,bC as Ya,bD as Xa,bE as Za,bF as es,bG as ts,bH as as,bI as ss,bJ as rs,bK as ns,bL as os,bM as is,bN as ls,bO as cs,bP as ds,bQ as xs,bR as us,bS as ms,bT as ps,bU as hs,bV as bs,bW as vs,bX as fs,bY as gs,bZ as js,b_ as ys,b$ as Ss,c0 as Ns,c1 as Ps,c2 as Cs,c3 as B,c4 as ws,c5 as Ts,c6 as Rs,c7 as Es,c8 as Ds,c9 as ks,ca as Bs,cb as Ms,cc as Os,cd as Is,ce as Ls,cf as Hs,cg as Fs,ch as As,ci as _s,cj as $s,ck as Vs,cl as Js,cm as Gs,cn as qs,co as zs,cp as Us,cq as Ws,cr as Ks,cs as Qs,ct as Ys,cu as Xs,cv as Zs,cw as er,cx as tr,cy as ar,cz as sr,cA as rr,cB as nr,cC as or,cD as ir,cE as lr,cF as cr,cG as dr,cH as xr,cI as ur,cJ as mr,cK as pr,cL as hr,cM as br,cN as vr,cO as fr,cP as gr,cQ as jr,cR as yr,cS as Sr,cT as Nr,cU as Pr,cV as Cr,cW as wr,cX as Tr,cY as Rr,cZ as Er,c_ as Dr,c$ as kr,d0 as Br,d1 as Mr,d2 as Or,d3 as Ir,d4 as Lr,d5 as Hr,d6 as Fr,d7 as Ar,d8 as _r,d9 as $r,da as Vr,db as Jr,dc as Gr,dd as qr,de as zr,df as Ur}from"./EditorShell-1FTR28BA.js";import{S as Wr,a as Kr,b as Qr,c as Yr}from"./StepsSimulator-CRtmlyNZ.js";import{M as V}from"./Markdown-BHBqz-Mj.js";import{S as Xr,B as w,M as P,a as E,t as S,I as Zr,b as en,c as tn,d as an,e as sn,f as rn,g as nn,h as on,i as ln,j as cn,k as dn,C as xn,l as un}from"./ContainerInspector-CVhTYjTR.js";import{S as J,M as G,f as mn,a as q,b as pn,J as hn,c as bn,d as vn,e as fn,g as gn,h as jn,i as yn,j as Sn,k as Nn,l as Pn,m as Cn,n as wn,o as Tn,p as Rn,q as En,r as Dn,s as kn,t as Bn,u as Mn,v as On,w as In,x as Ln,y as Hn,z as Fn,A as An,B as _n,C as $n,D as Vn,E as Jn,F as Gn,G as qn,H as zn,I as Un,T as Wn,K as Kn,L as Qn,N as Yn,O as Xn}from"./ScenarioDataPanel-Bb7egwjC.js";import{ScenarioDataPanelFullPage as Zn}from"./ScenarioDataPanelFullPage-I0tbkDlL.js";import"./index-6jueUhB_.js";import"./useEvents-DggWrtHe.js";import"./xterm--24IGk-x.js";function z({files:t}){if(t.length===0)return null;const{added:a,modified:s,deleted:r}=xe(t);return e.jsxs("span",{className:"text-xs text-[var(--text-muted)]",children:[a>0&&e.jsxs("span",{className:"text-[var(--accent-green)]",children:["+",a," "]}),s>0&&e.jsxs("span",{className:"text-[var(--accent-orange)]",children:["~",s," "]}),r>0&&e.jsxs("span",{className:"text-[var(--accent-red)]",children:["-",r," "]}),"file",t.length!==1?"s":""]})}function v({label:t,children:a}){return e.jsxs("div",{className:"mb-2",children:[e.jsx("p",{className:"text-xs font-medium mb-1",style:{color:"var(--text-muted)"},children:t}),e.jsx("div",{className:"mt-0.5",children:a})]})}function U({files:t}){return t.length===0?null:e.jsx("div",{className:"max-h-32 overflow-y-auto",children:t.map(a=>e.jsxs("p",{className:"font-mono text-xs text-[var(--text-muted)]",children:[e.jsx(W,{status:a.status})," ",a.path]},a.path))})}function W({status:t}){const a=t==="added"?"text-[var(--accent-green)]":t==="deleted"?"text-[var(--accent-red)]":"text-[var(--accent-orange)]",s=t==="added"?"+":t==="deleted"?"-":"~";return e.jsx("span",{className:a,children:s})}function K({entry:t}){return e.jsxs("div",{className:"mt-3 pt-3",style:{borderTop:"1px solid var(--border-default)"},children:[t.userRequest&&e.jsx(v,{label:"Request",children:e.jsx(L,{children:t.userRequest})}),e.jsx(v,{label:"Description",children:e.jsx(V,{variant:"compact",children:t.description})}),t.scenarioScreenshots.length>0&&e.jsx(v,{label:"Scenarios",children:e.jsx(H,{screenshots:t.scenarioScreenshots})}),t.modifiedFiles.length>0&&e.jsx(v,{label:"Modified Files",children:e.jsx(U,{files:t.modifiedFiles})}),t.commitSha&&e.jsxs("p",{className:"text-xs",style:{color:"var(--text-dim)"},children:["Commit: ",e.jsx("span",{className:"font-mono",children:t.commitSha.slice(0,7)}),t.commitMessage&&` — ${t.commitMessage}`]})]})}function Q({entry:t}){const[a,s]=d.useState(!1);return e.jsxs("div",{className:"rounded-lg border p-4",style:{borderColor:"var(--border-default)",background:"var(--bg-surface)"},children:[e.jsxs("button",{onClick:()=>s(!a),className:"flex w-full items-start gap-3 text-left",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{type:t.type}),e.jsx("h3",{className:"text-sm font-medium",style:{color:"var(--text-secondary)"},children:t.title})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-3",children:[e.jsx("span",{className:"text-xs",style:{color:"var(--text-dim)"},children:ue(t.timestamp)}),t.testResults&&e.jsx(F,{total:t.testResults.total,passed:t.testResults.passed,failed:t.testResults.failed}),e.jsx(z,{files:t.modifiedFiles})]})]}),e.jsx("span",{className:"text-xs mt-1",style:{color:"var(--text-dim)"},children:a?"▼":"▶"})]}),a&&e.jsx(K,{entry:t})]})}function Y({type:t}){return e.jsx("span",{className:`text-xs font-medium ${me(t)}`,children:t})}function eo({entries:t,total:a,hasMore:s,loading:r,loadingMore:n,error:i,onLoadMore:l}){if(r)return e.jsx("div",{className:"py-12 text-center text-[var(--text-muted)]",children:"Loading journal..."});if(i)return e.jsxs("div",{className:"py-12 text-center text-[var(--accent-red)]",children:["Failed to load journal: ",i]});if(t.length===0)return e.jsxs("div",{className:"py-12 text-center text-[var(--text-dim)]",children:[e.jsx("p",{children:"No journal entries yet."}),e.jsx("p",{className:"mt-2 text-sm text-[var(--text-dim)]",children:"Journal entries capture what was requested, what changed, and the state of tests and scenarios."})]});const c=Math.max(a,t.length);return e.jsxs("div",{className:"overflow-y-auto px-6 py-4",style:{maxHeight:"calc(100vh - 110px)"},children:[e.jsxs("p",{className:"mb-4 text-sm text-[var(--text-muted)]",children:[t.length," of ",c," journal entr",c===1?"y":"ies"]}),e.jsx("div",{className:"flex flex-col gap-3",children:t.map(o=>e.jsx(Q,{entry:o},o.timestamp))}),s?e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx("button",{type:"button",onClick:l,disabled:n,className:"rounded border border-[var(--border)] px-3 py-1 text-sm text-[var(--text-muted)] hover:bg-[var(--bg-subtle)] disabled:opacity-50",children:n?"Loading...":"Load older entries"})}):null]})}function to({apps:t,selected:a,onChange:s}){return t.length===0?null:e.jsxs("div",{className:"flex gap-1",children:[t.map(r=>e.jsx(D,{href:pe(r.dir),onNavigate:()=>s(r.dir),className:`rounded-md px-3 py-1 text-sm ${a===r.dir?"bg-[var(--bg-input)] text-[var(--text-primary)]":"text-[var(--text-muted)] hover:text-[var(--text-secondary)]"}`,children:r.name},r.dir)),e.jsx(D,{href:"/apps",onNavigate:()=>s(null),className:`rounded-md px-3 py-1 text-sm ${a===null?"bg-[var(--bg-input)] text-[var(--text-primary)]":"text-[var(--text-muted)] hover:text-[var(--text-secondary)]"}`,children:"All"})]})}function ao({segments:t}){return t.length===0?null:e.jsx("span",{className:"text-sm",style:{color:"var(--text-muted)"},children:t.map((a,s)=>e.jsxs("span",{children:[e.jsx("span",{style:{color:"var(--text-dim)"},children:" / "}),a]},s))})}function so(){return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-slate-500 space-y-4 px-10 text-center",children:[e.jsx("div",{className:"text-lg font-medium text-slate-400",children:"Ready to build"}),e.jsx("p",{className:"max-w-md",children:"Your first session will start automatically. You can queue changes or wait for the project to initialize."})]})}const ro={http_request:"#3fb950",db_query:"#58a6ff",process_output:"#6e7681",health_check:"#d29922",hook_execution:"#bc8cff",error:"#f85149",scenario_switch:"#d29922"};function no(t){const a=ro[t.type]??"#6e7681";switch(t.type){case"http_request":{const s=t.status??"";return{label:"HTTP",detail:`${t.method} ${t.url} ${s} ${t.durationMs}ms`,badge:t.mocked?"MOCKED":"LIVE",color:a}}case"db_query":return{label:"DB",detail:`${t.query} (${t.durationMs}ms)`,badge:t.mocked?"MOCKED":"LIVE",color:a};case"process_output":return{label:"Process",detail:`[${t.stream}] ${t.line}`,color:a};case"health_check":return{label:"Health",detail:t.healthy?"healthy":"unhealthy",color:a};case"hook_execution":return{label:"Hook",detail:`${t.hook} exit=${t.exitCode} ${t.durationMs}ms`,color:a};case"error":return{label:"Error",detail:`${t.source}: ${t.message}`,color:a};case"scenario_switch":return{label:"Scenario",detail:`${t.from??"(none)"} → ${t.to}`,color:a}}}function X({event:t}){const{label:a,detail:s,badge:r,color:n}=no(t);return e.jsxs("div",{className:"my-1 rounded-md bg-[var(--bg-surface)] px-3 py-2 font-mono text-sm",style:{borderLeft:`3px solid ${n}`},children:[e.jsx("span",{className:"mr-2 font-semibold",children:a}),e.jsx("span",{className:"text-[var(--text-secondary)]",children:s}),r&&e.jsx("span",{className:`ml-2 text-xs ${r==="MOCKED"?"text-[var(--accent-green)]":"text-[var(--text-muted)]"}`,children:r})]})}function oo({events:t}){return t.length===0?e.jsx("div",{className:"py-12 text-center text-[var(--text-dim)]",children:"Waiting for events..."}):e.jsx("div",{className:"overflow-y-auto px-6 py-2",style:{maxHeight:"calc(100vh - 110px)"},children:t.map(a=>e.jsx(X,{event:a},a.id))})}function Z({passed:t,failed:a,total:s}){return a>0?e.jsxs("span",{className:"rounded bg-[var(--accent-red)]/20 px-2 py-0.5 text-xs text-[var(--accent-red)]",children:[a," failed"]}):t===s&&s>0?e.jsxs("span",{className:"rounded bg-[var(--accent-green)]/20 px-2 py-0.5 text-xs text-[var(--accent-green)]",children:[t," passed"]}):e.jsxs("span",{className:"text-xs text-[var(--text-dim)]",children:["(",s,")"]})}function ee({group:t}){const[a,s]=d.useState(!0),r=t.tests.filter(l=>l.status==="passed").length,n=t.tests.filter(l=>l.status==="failed").length,i=t.tests.length;return e.jsxs("div",{className:"mb-4",children:[e.jsxs("button",{onClick:()=>s(!a),className:"flex w-full items-center gap-2 text-left text-sm font-medium text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:[e.jsx("span",{className:"text-[var(--text-dim)]",children:a?"▼":"▶"}),e.jsx("span",{children:t.feature}),e.jsx(Z,{passed:r,failed:n,total:i})]}),a&&e.jsx("div",{className:"ml-5 mt-1 border-l border-[var(--border-default)] pl-3",children:t.tests.map((l,c)=>e.jsx(A,{test:l},c))})]})}function io({filters:t,active:a,onChange:s}){return e.jsx("div",{className:"flex gap-2 border-b px-6 py-3",style:{borderColor:"var(--border-default)"},children:t.map(r=>e.jsx("button",{onClick:()=>s(r),className:"rounded-md border px-3 py-1 text-sm",style:r===a?{borderColor:"var(--accent-active)",background:"var(--accent-active)",color:"var(--bg-nav)"}:{borderColor:"var(--border-default)",background:"var(--bg-surface)",color:"var(--text-secondary)"},children:r},r))})}function te({scenario:t,onPreview:a}){const s=t.screenshotPaths.length>0,[r,n]=d.useState(!1),i=s&&!r;return e.jsxs("div",{className:`rounded-lg border border-[var(--border-default)] bg-[var(--bg-surface)] p-3 ${a?"cursor-pointer hover:border-[var(--border-subtle)]":""}`,onClick:a,children:[i?e.jsx("img",{src:he(t.screenshotPaths[0]),alt:t.name,className:"mb-2 w-full rounded border border-[var(--border-default)]",onError:()=>n(!0)}):e.jsx("div",{className:"mb-2 flex h-32 items-center justify-center rounded border border-dashed border-[var(--border-default)] text-sm text-[var(--text-dim)]",children:"No screenshot"}),e.jsx("p",{className:"text-sm font-medium text-[var(--text-secondary)]",children:t.name}),e.jsxs("div",{className:"mt-1 flex gap-1",children:[t.hasMocks&&e.jsx("span",{className:"rounded bg-[var(--accent-blue)]/20 px-1.5 py-0.5 text-xs text-[var(--accent-blue)]",children:"mocks"}),t.hasSeed&&e.jsx("span",{className:"rounded bg-[var(--accent-purple)]/20 px-1.5 py-0.5 text-xs text-[var(--accent-purple)]",children:"seed"}),t.dimensions.map(l=>e.jsx("span",{className:"rounded bg-[var(--bg-input)] px-1.5 py-0.5 text-xs text-[var(--text-muted)]",children:l},l))]})]})}function ae({group:t,onPreviewScenario:a}){const[s,r]=d.useState(!0);return e.jsxs("div",{className:"mb-6",children:[e.jsxs("button",{onClick:()=>r(!s),className:"flex w-full items-center gap-2 text-left text-sm font-medium text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:[e.jsx("span",{className:"text-[var(--text-dim)]",children:s?"▼":"▶"}),e.jsx("span",{className:"font-mono",children:t.route}),e.jsxs("span",{className:"text-[var(--text-dim)]",children:["(",t.scenarios.length,")"]})]}),s&&e.jsx("div",{className:"mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",children:t.scenarios.map(n=>e.jsx(te,{scenario:n,onPreview:a?()=>a(n.slug):void 0},n.slug))})]})}function se({fileName:t,dirPath:a}){return e.jsxs("div",{className:"flex items-center gap-3 rounded-md px-3 py-2 text-left bg-[var(--bg-card)] border border-[var(--border-subtle)] hover:border-[var(--border-default)] transition",children:[e.jsx("span",{className:"text-xs text-[var(--text-secondary)]",children:t}),e.jsxs("span",{className:"font-mono text-[10px] text-[var(--text-dim)]",children:[a,"/"]})]})}function lo({slug:t,name:a,url:s,componentName:r,props:n,mocks:i,seed:l,localStorage:c,dimensions:o}){const[u,f]=d.useState(!1),b=Object.keys((i==null?void 0:i.http)??{}).length,p=Object.keys((i==null?void 0:i.db)??{}).length,h=Object.keys(c??{});return e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsx("h3",{className:"font-medium text-[var(--text-secondary)]",children:a}),s&&e.jsx(v,{label:"URL",children:e.jsx("span",{className:"font-mono text-xs text-[var(--text-muted)]",children:s})}),r&&e.jsx(v,{label:"Component",children:e.jsx("span",{className:"font-mono text-xs text-[var(--accent-blue)]",children:r})}),n&&e.jsx(v,{label:"Props",children:e.jsx("pre",{className:"max-h-32 overflow-auto rounded bg-[var(--bg-input)] p-2 font-mono text-xs text-[var(--text-muted)]",children:JSON.stringify(n,null,2)})}),b>0&&e.jsxs(v,{label:"Mocks",children:[t?e.jsxs("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-[var(--accent-blue)] hover:underline bg-transparent border-none cursor-pointer p-0",children:[b," HTTP mock",b!==1?"s":""," →"]}):e.jsxs("span",{className:"text-xs text-[var(--text-muted)]",children:[b," HTTP mock",b!==1?"s":""]}),p>0&&e.jsxs("span",{className:"ml-2 text-xs text-[var(--text-muted)]",children:[p," DB mock",p!==1?"s":""]})]}),l&&e.jsx(v,{label:"Seed",children:l.command&&e.jsx("span",{className:"font-mono text-xs text-[var(--text-muted)]",children:l.command})}),h.length>0&&e.jsx(v,{label:"localStorage",children:h.map(m=>e.jsxs("p",{className:"font-mono text-xs text-[var(--text-muted)]",children:[m,": ",c[m]]},m))}),o.length>0&&e.jsx(v,{label:"Dimensions",children:e.jsx("div",{className:"flex gap-1",children:o.map(m=>e.jsx("span",{className:"rounded bg-[var(--bg-input)] px-1.5 py-0.5 text-xs text-[var(--text-muted)]",children:m},m))})}),u&&t&&e.jsx(J,{slug:t,scenarioName:a,initialSection:"mocks",onClose:()=>f(!1)})]})}function re({value:t,onChange:a=()=>{},parseError:s,onParseError:r=()=>{}}){return d.useEffect(()=>{if(t.trim()===""){r(null);return}try{JSON.parse(t),r(null)}catch(n){r(n instanceof Error?n.message:"Invalid JSON")}},[t,r]),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-[var(--text-muted)]",children:"Body (JSON)"}),e.jsx("textarea",{value:t,onChange:n=>a(n.target.value),rows:8,spellCheck:!1,className:`w-full rounded border bg-[var(--bg-surface)] px-2 py-1 text-xs font-mono resize-y ${s?"border-red-500":"border-[var(--border-default)]"}`}),s&&e.jsx("p",{className:"text-xs text-red-400 font-mono",children:s})]})}function ne({initialStatus:t,initialBody:a,initialHeaders:s,onSave:r,onCancel:n}){const i=d.useMemo(()=>{if(a==null)return"";try{return JSON.stringify(a,null,2)}catch{return""}},[a]),[l,c]=d.useState(t),[o,u]=d.useState(i),[f,b]=d.useState(null),[p,h]=d.useState(()=>Object.entries(s).map(([x,C])=>({name:x,value:C}))),[m,j]=d.useState(!0),y=f!==null||m;function g(){const x=o.trim()===""?null:JSON.parse(o),C={};for(const R of p)R.name.trim()&&(C[R.name.trim()]=R.value);r({status:l,body:x,headers:C})}return e.jsxs("div",{className:"mt-2 border border-[var(--border-subtle)] rounded bg-[var(--bg-input)] p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("label",{className:"text-xs text-[var(--text-muted)]",children:"Status"}),e.jsx("input",{type:"number",value:l,onChange:x=>{j(!1),c(Number(x.target.value))},className:"w-20 rounded border border-[var(--border-default)] bg-[var(--bg-surface)] px-2 py-1 text-xs font-mono"})]}),e.jsx(G,{headers:p,onChange:x=>{j(!1),h(x)}}),e.jsx(re,{value:o,parseError:f,onChange:x=>{j(!1),u(x)},onParseError:b}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:n,className:"px-3 py-1 text-xs rounded border border-[var(--border-default)] bg-transparent text-[var(--text-muted)] hover:text-[var(--text-primary)] cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"button",onClick:g,disabled:y,className:"px-3 py-1 text-xs rounded border border-[var(--accent-blue)] bg-[var(--accent-blue)]/10 text-[var(--accent-blue)] hover:bg-[var(--accent-blue)]/20 disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer",children:"Save"})]})]})}function oe({entry:t,scenarioHasDefaultFallback:a,editing:s,onToggleEdit:r,onPromoteDefaultToScenario:n,onRemove:i,onPassthrough:l,onCaptureLive:c}){const[o,u]=d.useState(!1),[f,b]=d.useState(null);async function p(){u(!0),b(null);try{await c()}catch(m){b(m instanceof Error?m.message:"Capture failed")}finally{u(!1)}}const h="px-2 py-0.5 rounded border border-[var(--border-default)] bg-transparent text-[var(--text-muted)] hover:text-[var(--text-primary)] cursor-pointer text-[10px]";return e.jsxs("div",{className:"flex flex-wrap gap-1 pt-1",children:[t.source==="scenario"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:h,children:s?"Close":"Edit"}),a&&e.jsx("button",{onClick:i,className:h,title:"Revert to default",children:"Revert to default"}),e.jsx("button",{onClick:l,className:h,children:"Mark passthrough"})]}),t.source==="default"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:n,className:"px-2 py-0.5 rounded border border-emerald-500/50 bg-emerald-500/10 text-emerald-300 hover:bg-emerald-500/20 cursor-pointer text-[10px]",title:"Copy default body into this scenario",children:"Promote to scenario"}),e.jsx("button",{onClick:l,className:h,children:"Mark passthrough"})]}),t.source==="catalog-only"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:p,disabled:o,className:"px-2 py-0.5 rounded border border-blue-500/50 bg-blue-500/10 text-blue-300 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-wait cursor-pointer text-[10px]",title:"Write last-observed body as this scenario's mock",children:o?"Capturing…":"Capture from live"}),f&&e.jsx("span",{className:"text-red-400 text-[10px]",children:f})]}),t.source==="passthrough"&&e.jsx("button",{onClick:i,className:h,children:"Undo passthrough"})]})}const M={GET:"text-emerald-400 border-emerald-400/40",POST:"text-blue-400 border-blue-400/40",PUT:"text-amber-400 border-amber-400/40",PATCH:"text-purple-400 border-purple-400/40",DELETE:"text-red-400 border-red-400/40"};function ie({entry:t}){const a=M[t.method]??M.GET,s=t.status??t.lastObservedStatus,r=t.lastObservedMs?mn(t.lastObservedMs,Date.now()):null;return e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded border font-mono ${a}`,children:t.method}),e.jsx("span",{className:"font-mono text-[var(--text-primary)] break-all",children:t.pathPattern}),e.jsx(q,{source:t.source}),s!==void 0&&e.jsx("span",{className:"px-1.5 py-0.5 rounded border border-[var(--border-default)] text-[var(--text-muted)] font-mono",children:s}),t.observedCount>0&&e.jsxs("span",{className:"ml-auto text-[var(--text-dim)]",children:[t.observedCount,"× ",r?`· ${r}`:""]})]})}function le({entry:t,scenarioHasDefaultFallback:a,onSave:s,onRemove:r,onPassthrough:n,onCaptureLive:i}){const[l,c]=d.useState(!1),o=`${t.method} ${t.pathPattern}`;return e.jsxs("div",{className:"border border-[var(--border-subtle)] rounded p-2 text-xs space-y-1",children:[e.jsx(ie,{entry:t}),t.variants.length>1&&e.jsxs("div",{className:"text-[10px] text-[var(--text-dim)] font-mono",children:["variants: ",t.variants.filter(u=>u!==o).join(", ")]}),e.jsx(oe,{entry:t,scenarioHasDefaultFallback:a,editing:l,onToggleEdit:()=>c(u=>!u),onPromoteDefaultToScenario:()=>s({routeKey:o,status:t.status??200,body:t.body,headers:t.headers??{}}),onRemove:()=>r(o),onPassthrough:()=>n(o),onCaptureLive:()=>i(t.method,t.pathPattern)}),l&&e.jsx(ne,{initialStatus:t.status??200,initialBody:t.body,initialHeaders:t.headers??{},onCancel:()=>c(!1),onSave:async u=>{await s({routeKey:o,...u}),c(!1)}})]})}const T=async()=>{};function co({label:t,entries:a,defaultEndpointKeys:s=[],onSave:r=T,onRemove:n=T,onPassthrough:i=T,onCaptureLive:l=T}){if(a.length===0)return null;const c=s instanceof Set?s:new Set(s);return e.jsxs("section",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--text-dim)]",children:[t," (",a.length,")"]}),e.jsx("div",{className:"space-y-2",children:a.map(o=>e.jsx(le,{entry:o,scenarioHasDefaultFallback:c.has(`${o.method} ${o.pathPattern}`),onSave:r,onRemove:n,onPassthrough:i,onCaptureLive:l},`${o.method} ${o.pathPattern}`))})]})}function xo({scenarioName:t,defaultSlug:a,onClose:s}){return e.jsxs("header",{className:"sticky top-0 z-10 flex items-center justify-between gap-2 border-b border-[var(--border-subtle)] bg-[var(--bg-deep)] px-4 py-3",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm font-medium text-[var(--text-primary)]",children:["Mocks for ",t]}),a&&e.jsxs("p",{className:"text-xs text-[var(--text-dim)]",children:["Defaults inherited from ",e.jsx("span",{className:"font-mono",children:a})]})]}),e.jsx("button",{onClick:s,className:"rounded border border-[var(--border-default)] bg-transparent px-2 py-1 text-xs text-[var(--text-muted)] hover:text-[var(--text-primary)] cursor-pointer",children:"Close"})]})}function uo({total:t,passed:a,failed:s,discovered:r}){if(t===0&&(r??0)>0)return e.jsxs("span",{className:"text-[var(--text-dim)]",children:[r," ",r===1?"test":"tests"," (not run)"]});if(t===0)return e.jsx("span",{className:"text-[var(--text-dim)]",children:"No tests"});const n=(r??t)>t?(r??t)-t:0;return n>0?e.jsxs("span",{children:[e.jsxs("span",{className:"text-[var(--accent-green)]",children:[a," passed"]}),s>0&&e.jsxs("span",{className:"text-[var(--accent-red)]",children:[" · ",s," failed"]}),e.jsxs("span",{className:"text-[var(--text-dim)]",children:[" · ",n," not run"]})]}):s>0?e.jsxs("span",{className:"text-[var(--accent-red)]",children:[a,"/",t," passed"]}):e.jsxs("span",{className:"text-[var(--accent-green)]",children:[a,"/",t," passed"]})}function mo({groups:t,loading:a,error:s,totalScenarios:r,onPreviewScenario:n}){return a?e.jsx("div",{className:"py-12 text-center text-[var(--text-muted)]",children:"Loading scenarios..."}):s?e.jsxs("div",{className:"py-12 text-center text-[var(--accent-red)]",children:["Failed to load scenarios: ",s]}):t.length===0?e.jsxs("div",{className:"py-12 text-center text-[var(--text-dim)]",children:[e.jsx("p",{children:"No scenarios defined yet."}),e.jsx("p",{className:"mt-2 text-sm text-[var(--text-dim)]",children:"Create scenario JSON files in .codeyam/scenarios/"})]}):e.jsxs("div",{className:"overflow-y-auto px-6 py-4",style:{maxHeight:"calc(100vh - 110px)"},children:[e.jsxs("p",{className:"mb-4 text-sm text-[var(--text-muted)]",children:[r," scenarios across ",t.length," routes"]}),t.map(i=>e.jsx(ae,{group:i,onPreviewScenario:n},i.route))]})}function po({groups:t,loading:a,error:s,cached:r,totalTests:n,passedTests:i,coverage:l,onRefresh:c}){return a?e.jsx("div",{className:"py-12 text-center text-[var(--text-muted)]",children:"Loading tests..."}):s?e.jsxs("div",{className:"py-12 text-center text-[var(--accent-red)]",children:["Failed to load tests: ",s]}):t.length===0?e.jsx("div",{className:"py-12 text-center text-[var(--text-dim)]",children:"No tests found"}):e.jsxs("div",{className:"overflow-y-auto px-6 py-4",style:{maxHeight:"calc(100vh - 110px)"},children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3 text-sm text-[var(--text-muted)]",children:[e.jsxs("span",{children:[i,"/",n," passed across ",t.length," features"]}),e.jsx(_,{coverage:l,testId:"tests-view-coverage",className:"rounded bg-[var(--bg-input)] px-2 py-0.5 text-xs font-medium text-[var(--text-secondary)]"}),r&&e.jsx("span",{className:"rounded bg-[var(--bg-input)] px-2 py-0.5 text-xs text-[var(--text-muted)]",children:"cached"}),e.jsx("button",{onClick:c,disabled:a,className:"rounded bg-[var(--bg-input)] px-2 py-0.5 text-xs text-[var(--text-muted)] hover:bg-[var(--bg-surface)] hover:text-[var(--text-secondary)] disabled:opacity-50",children:a?"Running...":"Run Tests"})]}),t.map(o=>e.jsx(ee,{group:o},o.feature))]})}function ho({tabs:t,active:a,onChange:s}){return e.jsx("div",{className:"flex gap-0",children:t.map(r=>e.jsx("button",{onClick:()=>s(r.key),className:`px-3 py-2 text-sm transition-colors border-b-2 ${a===r.key?"font-medium":"border-transparent hover:text-[var(--text-primary)]"}`,style:a===r.key?{color:"var(--accent-active)",borderBottomColor:"var(--accent-active)"}:{color:"var(--text-muted)"},children:r.label},r.key))})}function bo({restartCount:t}){return e.jsx("div",{className:"absolute inset-0 bg-white/90 dark:bg-gray-900/90 backdrop-blur-sm flex flex-col items-center justify-center z-50 animate-in fade-in duration-300",children:e.jsxs("div",{className:"flex flex-col items-center space-y-4 text-center max-w-md p-6",children:[e.jsx(k,{restartCount:t}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:"Dev Server Restarting"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"The Live Preview server crashed unexpectedly. CodeYam is automatically recovering it..."})]}),t>2&&e.jsx("div",{className:"pt-2",children:e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 font-medium",children:"Recovery is taking longer than usual..."})})]})})}function vo(){return e.jsx("div",{className:"absolute inset-0 bg-white/90 dark:bg-gray-900/90 backdrop-blur-sm flex flex-col items-center justify-center z-50 animate-in fade-in duration-300",children:e.jsxs("div",{className:"flex flex-col items-center space-y-4 text-center max-w-md p-6",children:[e.jsx(k,{restartCount:0}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:"Starting Dev Server"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Waiting for the development server to start..."})]})]})})}function fo(){return e.jsx("div",{className:"absolute inset-0 bg-white/90 dark:bg-gray-900/90 backdrop-blur-sm flex flex-col items-center justify-center z-50 animate-in fade-in duration-300",children:e.jsxs("div",{className:"flex flex-col items-center space-y-4 text-center max-w-md p-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-gray-200 dark:bg-gray-700 flex items-center justify-center",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-6 h-6 text-gray-500 dark:text-gray-400","aria-hidden":"true",children:[e.jsx("rect",{x:"6",y:"5",width:"4",height:"14",rx:"1"}),e.jsx("rect",{x:"14",y:"5",width:"4",height:"14",rx:"1"})]})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:"Dev Server Not Running"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Starting automatically…"})]})]})})}function go({title:t,count:a,children:s}){return e.jsxs("div",{className:"mt-5",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.18em] text-[var(--text-dim)]",children:t}),e.jsxs("p",{className:"text-xs text-[var(--text-dim)]",children:[a," total"]})]}),s]})}function ce(){return e.jsx("div",{className:"rounded-xl border border-dashed border-[var(--border-default)] px-4 py-5 text-sm text-[var(--text-dim)]",children:"No direct imports were found for this route file."})}function jo({directImports:t}){return t.length===0?e.jsx(ce,{}):e.jsx("div",{className:"grid grid-cols-1 gap-1",children:t.map(a=>{const{fileName:s,dirPath:r}=be(a);return e.jsx(se,{fileName:s,dirPath:r},a)})})}function yo({routeEntity:t}){return e.jsxs("div",{className:"rounded-xl border border-[var(--border-default)] bg-[var(--bg-elevated)] px-4 py-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.18em] text-[var(--text-dim)]",children:"Route"}),e.jsx("p",{className:"mt-2 text-lg font-semibold text-[var(--text-primary)]",children:t.displayName}),e.jsx("p",{className:"mt-1 font-mono text-xs text-[var(--accent-blue)]",children:t.route}),t.pageFilePath?e.jsx("p",{className:"mt-3 text-sm text-[var(--text-muted)]",children:t.pageFilePath}):e.jsx("p",{className:"mt-3 text-sm text-[var(--text-dim)]",children:"No source file is linked to this route yet."})]})}function So({tabs:t,activeTable:a,onSelectTable:s,onClose:r}){return e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 bg-[var(--bg-card)] border-b border-[var(--border-default)] flex-wrap",children:[t.map(n=>e.jsx(No,{tab:n,isActive:a===n.dataKey,onClick:()=>s(n.dataKey)},n.dataKey)),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:r,className:"w-5 h-5 flex items-center justify-center text-[var(--text-dim)] hover:text-[var(--text-primary)] bg-[var(--bg-input)] hover:bg-[var(--border-default)] rounded-full border-none cursor-pointer text-xs transition-colors",title:"Close",children:"×"})]})}function No({tab:t,isActive:a,onClick:s}){const r=t.category==="datastore"?a?"text-[var(--accent-active)] bg-[var(--accent-active)]/15 border-[var(--accent-active)]/40":"text-[var(--accent-active)]/60 bg-transparent border-transparent hover:text-[var(--accent-active)]/80":t.category==="mock-api"?a?"text-blue-400 bg-blue-400/15 border-blue-400/40":"text-blue-400/60 bg-transparent border-transparent hover:text-blue-400/80":a?"text-[var(--text-primary)] bg-[var(--border-default)] border-[var(--border-default)]":"text-[var(--text-dim)] bg-transparent border-transparent hover:text-[var(--text-secondary)]";return e.jsx("button",{onClick:s,className:`px-2.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider rounded cursor-pointer border transition-colors ${r}`,children:t.label})}function Po({featureName:t,onClose:a}){return e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center",style:{background:"rgba(30, 30, 30, 0.90)"},children:e.jsx($,{featureName:t,onClose:a})})}function O(){return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16,padding:16,background:"#0d1117",color:"#c9d1d9",fontFamily:"'SF Mono', Menlo, monospace",fontSize:13},children:[e.jsx(Xr,{title:"Section Header Example"}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx(w,{color:"#238636",children:"ACTIVE"}),e.jsx(w,{color:"#d29922",children:"WARNING"}),e.jsx(w,{color:"#da3633",children:"ERROR"}),e.jsx(w,{color:"#58a6ff",children:"INFO"})]}),e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsx(P,{method:"GET"}),e.jsx(P,{method:"POST"}),e.jsx(P,{method:"PUT"}),e.jsx(P,{method:"DELETE"}),e.jsx(P,{method:"PATCH"})]}),e.jsx(E,{color:"#238636",children:"Success status message"}),e.jsx(E,{color:"#d29922",children:"Warning status message"}),e.jsx(E,{color:"#8b949e",children:"Neutral status message"})]})}const Co=[{type:"http_request",id:"evt-1",timestampMs:Date.now(),method:"GET",url:"/api/tasks",status:200,durationMs:2,mocked:!0},{type:"http_request",id:"evt-2",timestampMs:Date.now(),method:"POST",url:"/api/users/register",status:201,durationMs:145,mocked:!1}];function I({events:t}){const a=t??Co;return e.jsx("div",{style:{background:"#0d1117",padding:16},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12,fontFamily:"'SF Mono', Menlo, monospace",color:"#c9d1d9"},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{borderBottom:"1px solid #30363d"},children:[e.jsx("th",{style:S,children:"Time"}),e.jsx("th",{style:S,children:"Method"}),e.jsx("th",{style:{...S,textAlign:"left"},children:"URL"}),e.jsx("th",{style:S,children:"Status"}),e.jsx("th",{style:S,children:"Duration"}),e.jsx("th",{style:S,children:"Source"})]})}),e.jsx("tbody",{children:a.map(s=>e.jsx(Zr,{event:s},s.id))})]})})}function wo(){return e.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-0",style:{background:"repeating-linear-gradient(45deg, transparent 0 24px, rgba(255,255,255,0.025) 24px 48px)"}})}function de({error:t}){return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-[var(--bg-deep)] text-[var(--accent-red)]",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-lg",children:"Seed Error"}),e.jsx("p",{className:"mt-2 text-sm",children:t}),e.jsx("p",{className:"mt-2 text-xs text-[var(--text-muted)]",children:"The database state shown may not match this scenario."})]})})}const To={AppCard:Ur,AppDetail:zr,AppOverview:qr,BuildTab:Gr,BuildTabLayout:Jr,BuildTabPane:Vr,BuildTabPaneLayout:$r,BuildTabRecoveryPanel:_r,BuildTabSessionContent:Ar,BuildTabStartupError:Fr,BuildTabReadyToBuildPlaceholder:so,BuildTabTerminalSession:Hr,AppSelector:to,AppTypeBadge:Lr,BreadcrumbNav:ao,BuildingPreviewOverlay:Ir,ConnectionBadge:un,DebugModeButton:Or,DebugModal:Mr,DebugModalElementPreview:Br,DebugModalInfoPanel:kr,DebugOverlay:Dr,DebugAncestryList:Er,DebugAncestrySection:Rr,DebugPropsChips:Tr,DebugFreezePill:wr,OpenInEditorErrorToast:Cr,CyLogo:Pr,DeviceIcon:Nr,EditorNavBar:Sr,IdleBanner:yr,EditorSessionRecoveryActionButton:jr,EditorSessionRecoveryDialog:gr,EditorSessionRecoveryHeader:fr,EditorSessionRecovery:vr,EditorSessionRecoverySummaryRow:br,EditorSessionRecoverySummary:hr,EditorShellHomeTabContent:pr,EditorShellBuildLayer:mr,EditorShellLayout:ur,EditorShellLeftPane:xr,EditorShellPlanLayer:dr,EditorShellPreviewPane:B,EditorShellTabLayer:cr,GearIcon:lr,EventCard:X,EventStream:oo,EntryTypeBadge:Y,CollapsibleMarkdown:L,FeatureNameButton:ir,FeatureGroupView:ee,FileChangeSummary:z,FileStatusIndicator:W,FileStatusIndicatorStandalone:or,HistoryTab:nr,HistoryEntryCard:rr,CommitOnlyHistoryRow:sr,NotificationSettingsPopover:ar,DebugNotificationsButton:tr,IdleTriggerCheckbox:er,JournalEntryCard:Q,JournalEntryDetails:K,JournalView:eo,LabeledSection:v,FilterBar:io,LeftPanel:Zs,ModifiedFilesList:U,NavLink:D,StepProgressBar:Xs,TestRunnerStatsBar:Ys,TestsSummaryCard:Qs,NarrativeSection:Ks,PreNarrativeFallback:Ws,ModifiedFilesSection:Us,Markdown:V,NewProjectQuestionnaire:zs,QuestionnaireIntroBanner:qs,QuestionnaireDeviceSelector:Gs,QuestionnaireNavButtons:Js,QuestionnaireOptionCard:Vs,PanelDivider:$s,PromptDropdownPanel:_s,PreviewCanvas:As,PreviewEmptyState:Fs,PreviewFrame:Hs,BackendResultsPanelView:Ls,PlanPreviewPanelView:Is,PlanPreviewEmptyState:Os,PlanPreviewHeader:Ms,ProjectSetupPreviewView:Bs,ProjectSetupHeader:ks,ProjectSetupDescriptionCard:Ds,ProjectSetupProgressList:Es,ProjectSetupProgressRow:Rs,ProjectSetupFooterHint:Ts,LiveIframeHealthPill:ws,PreviewPanel:B,QuestionnaireStepNav:Cs,QuestionnaireStepPanel:Ps,AppDetailContent:Ns,AppDetailContentError:Ss,AppDetailContentLoading:ys,AppDetailHeader:js,RouteDependencyCard:gs,RouteDependencyCardHeader:fs,RouteDependencyEmptyState:vs,RouteDependencyList:bs,RouteDependencyScenarioStrip:hs,RouteEntityDetail:ps,RouteEntityDetailContent:ms,RouteFunctionCard:us,RouteFunctionEmptyState:xs,RouteFunctionList:ds,RouteEntityDetailHeader:cs,RouteEntityTabs:ls,RouteGroupView:ae,RouteImportRow:se,RouteList:is,RouteListCardThumbnail:os,RouteScenarioList:ns,ScenarioCard:te,ScenarioRow:rs,ScenarioDetailPanel:lo,MockBodyEditor:ne,MockBodyHeadersEditor:G,MockBodyJsonTextarea:re,MockPanelGroup:co,MockPanelHeader:xo,MockPanelRow:le,MockPanelRowActions:oe,MockPanelRowHeader:ie,MockSourceBadge:q,ScenarioThumbnailGrid:H,StatusBadge:Z,StepIndicatorBar:ss,StepIndicatorDropdownItem:as,TabPane:ts,TestItem:A,TestGroupHeader:es,TestGroupList:Za,TestGroupRow:Xa,TestResultsBadge:F,TestSummary:uo,TestStatusIcon:Ya,ThumbnailStrip:Qa,CollapseToggleButton:Ka,DimensionInput:Wa,EditorShell:Ua,FillPreviewButton:za,OpenInNewTabButton:qa,PlaceholderPane:Ga,PlanTab:Ja,PlanTabHeader:Va,PlanNextChangeButton:$a,PlanAuthoringChat:_a,PlanRow:Aa,PlanRowDependencyEntry:Fa,PlanRowEditButton:Ha,PlanRowEditChatButton:La,PlanRowExpandedBody:Ia,PlanRowExpandedChat:Oa,PlanRowExpandedDependencies:Ma,PlanRowExpandedEdit:Ba,PlanRowExpandedView:ka,PlanRunButton:Da,PlanRunBlockedModal:Ea,PlanRunDependenciesModal:Ra,QueuedChangesSection:Ta,SortablePlanRow:wa,RecentPlansSection:Ca,CompletedPlanRow:Pa,CompletedPlanExpandedBody:Na,TabScrollPanel:Sa,BuildLaunchModal:ya,PostPushTransition:ja,PostPushTransitionDialog:ga,SelectPlanModal:fa,SelectPlanCard:va,PlanCompleteDialog:ba,PlanCompleteTransition:ha,ScenarioRenderer:Oo,ScenariosView:mo,TerminalEmulator:pa,TerminalDropOverlay:ma,TerminalDropToast:ua,TerminalDisconnectOverlay:Xn,TerminalConnectingHint:Yn,TerminalReconnectingBanner:Qn,TerminalFailedBanner:Kn,TerminalServerStoppedBanner:Wn,TestsView:po,NavigationBar:xa,PagePill:da,PagePickerDropdown:ca,StatesDropdown:la,CreateStatePlaceholderModal:ia,StatesPillButton:oa,EditDataButton:na,EditDataPopover:ra,EditDataPopoverBody:sa,EditDataPopoverDescribeInput:aa,EditDataPopoverHeader:ta,EditDataPopoverResizeHandleLeft:ea,EditDataPopoverSaveCancelClose:Zt,EditDataPopoverSearchInput:Xt,EditDataPopoverSectionSelector:Yt,EditDataPopoverTabStrip:Qt,ScenarioDataPanelMainProps:Kt,ScenarioDataPanelPropsEditor:Wt,ViewportPresetButton:Ut,PagePickerTabButton:zt,PagePickerEmptyMessage:qt,PagePickerScenarioThumbnail:Gt,PagePickerRouteSection:Jt,StatesDropdownRow:Vt,ComponentGlyph:$t,DropdownChevron:_t,PageGlyph:At,ViewTabs:ho,SessionResultsPanel:Ft,SessionResultsPanelHeader:Ht,BackendResultsPage:Lt,BackendConnectionStatusBadge:It,BackendConnectionLogEntryRow:Ot,BackendConnectionLogSection:Mt,NarrativeTestStatusIcon:Bt,CoverageBadge:_,CoverageBar:kt,CoverageWarningsBanner:Dt,FunctionsCoverageSection:Et,CoverageSectionHeader:Rt,OrphanedFileRow:Tt,FunctionsCoverageEmptyState:wt,ProjectWideCoverageRollup:Ct,CoverageDetailsModal:Pt,CoverageFileDrilldown:Nt,CoverageDetailsEntriesSection:St,CoverageDetailsEntryRow:yt,CoverageDetailsOrphanedSection:jt,CoverageDetailsDirectoriesSection:gt,CoverageDetailsDirectoryGroup:ft,CoverageDetailsDirectoryFileRow:vt,CoverageLineRow:bt,AppCardFooter:ht,RunTestsButton:pt,TestBar:mt,AppCardHeader:ut,AppCardScenarioStrip:xt,AppOverviewEmptyState:dt,AppOverviewEmptyStateBuildingPanel:ct,AppOverviewEmptyStateNoAppPanel:lt,OpenBuildTabButton:it,AppOverviewGrid:ot,AppOverviewHeader:nt,CopyButton:rt,CrashLogFooter:st,CrashLogFooterMessage:at,CrashLogHeader:tt,CrashLogViewer:et,DevServerCrashLog:Ze,DevServerRestartingOverlay:bo,DevServerStartingOverlay:vo,DevServerStoppedOverlay:fo,PreviewUnhealthyOverlay:Xe,PreviewErrorOverlay:Ye,PreviewErrorOverlayHeader:Qe,PreviewErrorOverlayFooter:Ke,PreviewErrorList:We,PreviewErrorRow:Ue,PreviewErrorBadge:ze,BuildSpinner:qe,RestartSpinner:k,RouteEntitySection:go,RouteImportEmptyState:ce,RouteImportList:jo,RouteListCard:Ge,RouteListEmptyState:Je,RouteListSectionHeader:Ve,RouteScenarioEmptyState:$e,RouteSummaryCard:yo,SafeScreenshot:_e,ScenarioRowMeta:Ae,ScenarioRowOverrideBadge:Fe,ScenarioRowThumbnail:He,SidebarGroupOverrideHeader:Un,SidebarInheritedSection:zn,DataViewerCategoryBadge:qn,DataViewerCellEditor:Gn,DataViewerTabBar:So,DataViewerTable:Jn,ScenarioDataPanel:J,ScenarioDataPanelCloseButton:Vn,ScenarioDataPanelEditChatButton:$n,ScenarioDataPanelEmptyState:_n,ScenarioDataPanelFullPage:Zn,ScenarioDataPanelHeader:An,ScenarioDataPanelInspectButton:Fn,ScenarioDataPanelMainMock:Hn,ScenarioDataPanelMainMockEditable:Ln,ScenarioDataPanelMainMockHeader:In,ScenarioDataPanelMainMockReadOnly:On,ScenarioDataPanelMainTable:Mn,ScenarioDataPanelOpenInNewButton:Bn,ScenarioDataPanelMockDataBadge:kn,ScenarioDataPanelMockDataStrip:Dn,ScenarioDataPanelSidebar:En,SaveScopeChoiceRow:Rn,SaveScopeModal:Tn,SidebarMockEntryRow:wn,MockSharedSlugBadge:Cn,ScenarioDraftBar:Pn,JsonBodyActions:Nn,JsonTreeAddKeyInput:Sn,JsonTreeArrayNode:yn,JsonTreeEditor:jn,JsonTreeNode:gn,JsonTreeNodeLine:fn,JsonTreeObjectNode:vn,JsonTreePrimitiveEditor:bn,JsonTreePrimitiveNode:hn,ScenarioRenameForm:Le,ScenarioRowActions:Ie,MiniAgentChat:pn,EnvelopeIcon:Oe,SendTranscriptModal:$,SendTranscriptOverlay:Po,ContainerInspector:xn,InspectorScenarioSection:dn,InspectorRouteTable:cn,InspectorTrafficSection:ln,InspectorExplainerSection:on,InspectorExplainerResult:nn,InspectorPrimitivesShowcase:O,InspectorTrafficRowShowcase:I,InspectorTrafficDetail:rn,InspectorTrafficFilterBar:sn,InspectorTrafficTable:an,InspectorTrafficUrlChips:tn,InspectorUrlGlossary:en,InspectorPrimitives:O,InspectorTrafficRow:I,StepsSimulator:Yr,StepsSimulatorStepList:Qr,StepsSimulatorVariableControl:Kr,StepsSimulatorInstructionsPanel:Wr,SeedErrorBanner:Me,SeedLoadingOverlay:Be,StaleDbStripeOverlay:wo,ScenarioSeedErrorView:de,CoverageThresholdsPanel:ke,CoverageThresholdsEmptyState:De,CoverageThresholdsHeader:Ee,CoverageThresholdsDefaultNotice:Re,CoverageThresholdsPassSummary:Te,CoverageThresholdsFailureList:we,CoverageThresholdFailureGroup:Ce,InspectModeRibbon:Pe,IframeClickThroughErrorCard:Ne,InspectResultCard:Se,InspectResultCardBackdrop:ye,InspectResultCardBody:je,InspectResultCardHeader:ge,InspectResultCardMatchButton:fe,InspectResultCardMatchList:ve};function Ro(t){const a={};for(const[s,r]of Object.entries(t))a[s]=N(r);return a}const Eo=new Set(["div","span","p","strong","em","code","pre","h1","h2","h3","h4","h5","h6","ul","ol","li","a","br","hr","img","section","header","footer","nav","article","button"]);function N(t){if(t==="__noop__")return()=>{};if(t==null||typeof t!="object")return t;if(Array.isArray(t))return t.map(N);if(t.__type==="noop")return()=>{};if(t.__type==="undefined")return;if(t.__type==="Ref")return{current:null};if(t.__type==="Date"&&typeof t.value=="string")return new Date(t.value);if(t.__type==="Set"&&Array.isArray(t.values))return new Set(t.values.map(N));if(t.__type==="ReactNode"){if(typeof t.text=="string")return t.text;if(typeof t.element=="string"){if(!Eo.has(t.element))return null;const s=t.children!=null?N(t.children):void 0;return d.createElement(t.element,t.props||null,s)}}if(t.__type==="Map"&&typeof t.entries=="object"&&t.entries!==null){const s=new Map;for(const[r,n]of Object.entries(t.entries))s.set(r,N(n));return s}const a={};for(const[s,r]of Object.entries(t))a[s]=N(r);return a}function Do(t){if(!t||typeof t!="object")return!1;const a=t,s=a.http?Object.keys(a.http).length:0,r=a.db?Object.keys(a.db).length:0;return s>0||r>0}const ko=new Set(["EditorShell"]);function Bo(t){return t?To[t]??null:null}function Mo(t){const[a,s]=d.useState({Component:null,props:{},name:"",loading:!0,error:null,needsRouter:!1,displayHints:null,seed:null,scenarioType:null,hasMocks:!1});return d.useEffect(()=>{let r=!1;return s(n=>({...n,loading:!0,error:null})),fetch(`/api/scenarios/${encodeURIComponent(t)}`).then(n=>n.json()).then(n=>{if(r)return;if(n.error){s({Component:null,props:{},name:"",loading:!1,error:n.error,needsRouter:!1,displayHints:null,seed:null,scenarioType:null,hasMocks:!1});return}const i=Bo(n.componentName),l=n.scenarioType==="application"||n.scenarioType==="component"?n.scenarioType:null,c=n.seed??null,o=Do(n.mocks);if(!i&&n.componentName){s({Component:null,props:{},name:n.name??"",loading:!1,error:`Component "${n.componentName}" not found in registry`,needsRouter:!1,displayHints:null,seed:c,scenarioType:l,hasMocks:o});return}s({Component:i,props:Ro(n.props??{}),name:n.name??"",loading:!1,error:null,needsRouter:ko.has(n.componentName??""),displayHints:n.displayHints??null,seed:c,scenarioType:l,hasMocks:o})}).catch(n=>{r||s({Component:null,props:{},name:"",loading:!1,error:n.message,needsRouter:!1,displayHints:null,seed:null,scenarioType:null,hasMocks:!1})}),()=>{r=!0}},[t]),a}function Oo({slug:t}){const{Component:a,props:s,name:r,loading:n,error:i,needsRouter:l,displayHints:c,seed:o,scenarioType:u,hasMocks:f}=Mo(t),[b,p]=d.useState(!1),[h,m]=d.useState(null);if(d.useEffect(()=>{if(n)return;let y=!1;return p(!1),m(null),u==="component"&&o==null&&!f?(p(!0),()=>{y=!0}):(fetch("/api/editor-activate-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:t})}).then(async g=>{const x=await g.json().catch(()=>null);y||(x&&(x.seedError||x.success===!1)&&(o!=null?m(x.seedError||x.error||"scenario activation failed"):console.warn("[scenario] activation returned failure for no-seed scenario; ignoring",x)),p(!0))}).catch(g=>{y||(o!=null?m(g instanceof Error?g.message:String(g)):console.warn("[scenario] activation request failed for no-seed scenario; ignoring",g),p(!0))}),()=>{y=!0,fetch("/api/editor-deactivate-scenario",{method:"POST"}).catch(()=>{})})},[t,n,o,u,f]),n||!b)return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-[var(--bg-deep)] text-[var(--text-muted)]",children:"Loading scenario..."});if(h)return e.jsx(de,{error:h});if(i)return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-[var(--bg-deep)] text-[var(--accent-red)]",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-lg",children:"Scenario Error"}),e.jsx("p",{className:"mt-2 text-sm",children:i})]})});if(!a)return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-[var(--bg-deep)] text-[var(--text-muted)]",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-lg",children:r}),e.jsx("p",{className:"mt-2 text-sm",children:"No component specified for this scenario"})]})});const j=e.jsx(a,{...s});return l?j:e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-[var(--bg-deep)] p-4",children:e.jsx("div",{className:"w-full",style:c!=null&&c.maxWidth?{maxWidth:c.maxWidth}:void 0,children:j})})}export{Oo as ScenarioRenderer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./markdown-v0F0UEt3.js";import{b as d}from"./react-CSS0HapR.js";import{M as I}from"./Markdown-BHBqz-Mj.js";function E({workflow:n,selectedSlug:r,onSelectSlug:t}){return e.jsx("div",{style:{padding:"4px 8px 16px",flex:1},children:n.steps.map(o=>o.kind==="slug"?e.jsx(k,{position:o.position,slug:o.slug,label:o.label,description:o.description,isSelected:r===o.slug,onSelect:()=>t(o.slug)},`slug-${o.position}-${o.slug}`):e.jsx(D,{position:o.position,ifKey:o.ifKey,arms:o.arms,selectedSlug:r,onSelectSlug:t},`branch-${o.position}`))})}function k({position:n,slug:r,label:t,description:o,isSelected:s,onSelect:i,indent:l=0,branchHint:a}){return e.jsxs("button",{onClick:i,style:{display:"flex",alignItems:"flex-start",gap:8,padding:"7px 8px",paddingLeft:8+l,borderRadius:4,border:"none",cursor:"pointer",textAlign:"left",fontSize:13,width:"100%",background:s?"var(--bg-input)":"transparent",color:s?"var(--accent-active)":"var(--text-secondary)",fontWeight:s?600:400},children:[e.jsx("span",{style:{width:22,textAlign:"right",color:"var(--text-muted)",fontSize:11,fontFamily:"'IBM Plex Mono', monospace",flexShrink:0,paddingTop:1},children:n}),e.jsxs("span",{style:{flex:1,display:"flex",flexDirection:"column"},children:[e.jsxs("span",{children:[t,a&&e.jsx("span",{style:{marginLeft:6,fontSize:10,color:"var(--text-dim)",fontFamily:"'IBM Plex Mono', monospace"},children:a})]}),e.jsx("span",{style:{fontSize:11,color:o?"var(--text-muted)":"var(--accent-error, #d44)",marginTop:2,fontWeight:400},children:o??"(missing description)"}),e.jsx("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:1,fontFamily:"'IBM Plex Mono', monospace"},children:r})]})]})}function D({position:n,ifKey:r,arms:t,selectedSlug:o,onSelectSlug:s}){return e.jsxs("div",{children:[e.jsxs("div",{style:{padding:"4px 8px",fontSize:11,color:"var(--text-dim)",fontStyle:"italic"},children:["Branch on ",e.jsx("code",{children:r})," (position ",n,")"]}),t.map(i=>e.jsx(k,{position:n,slug:i.slug,label:i.label,description:i.description,isSelected:o===i.slug,onSelect:()=>s(i.slug),indent:20,branchHint:`(${i.outcome})`},`${n}-${i.slug}`))]})}const F=["provider","feature","dimension","screenSizes","hasProject","isResuming","designSystem","stack","needsScaffold","projectDescription","startCommand","hasGlossary","hasUserPrompt","selectedPlan","needsInitialStartingSurface","port","controlPort"],L={provider:"Provider",feature:"Feature Name",dimension:"Dimension",screenSizes:"Screen Sizes",hasProject:"Has Project",isResuming:"Is Resuming",designSystem:"Design System",stack:"Stack Config",needsScaffold:"Needs Scaffold",projectDescription:"Project Description",startCommand:"Start Command",hasGlossary:"Has Glossary",hasUserPrompt:"Has User Prompt",selectedPlan:"Selected Plan",needsInitialStartingSurface:"Needs Initial Starting Surface",port:"Port",controlPort:"Control Port"};function V({visibleVariables:n,vars:r,onVarChange:t}){return n.length===0?e.jsx("div",{style:{padding:"12px 20px",borderBottom:"1px solid var(--border-default)",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"This step has no input variables — its rendered output is the same in every context."}):e.jsx("div",{style:{padding:"12px 20px",borderBottom:"1px solid var(--border-default)",display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:12},children:n.filter(o=>F.includes(o)).map(o=>e.jsx(A,{fieldKey:o,value:r[o],onChange:s=>t(o,s)},o))})}function A({fieldKey:n,value:r,onChange:t}){const o=L[n],s=typeof r=="boolean",i=typeof r=="number",l=Array.isArray(r);return e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[e.jsx("span",{children:o}),s?e.jsx("input",{type:"checkbox",checked:r,onChange:a=>t(a.target.checked),style:{alignSelf:"flex-start"}}):i?e.jsx("input",{type:"number",value:r,onChange:a=>t(Number(a.target.value)),style:y()}):l?e.jsx("input",{type:"text",value:r.join(", "),onChange:a=>t(a.target.value.split(",").map(f=>f.trim()).filter(Boolean)),placeholder:"comma-separated",style:y()}):e.jsx("input",{type:"text",value:typeof r=="string"?r:"",onChange:a=>t(a.target.value||null),placeholder:"(unset)",style:y()})]})}function y(){return{background:"var(--bg-input)",border:"1px solid var(--border-default)",borderRadius:3,padding:"4px 6px",fontSize:12,color:"var(--text-primary)",fontFamily:"'IBM Plex Mono', monospace"}}function W({rendered:n,renderError:r,renderLoading:t,selectedSlug:o,selectedDescription:s,visibleVariables:i,vars:l,onVarChange:a}){return e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(T,{rendered:n,selectedSlug:o,selectedDescription:s}),e.jsx(V,{visibleVariables:i,vars:l,onVarChange:a}),e.jsx($,{rendered:n,renderError:r,renderLoading:t})]})}function T({rendered:n,selectedSlug:r,selectedDescription:t}){return e.jsxs("div",{style:{padding:"16px 20px 12px",borderBottom:"1px solid var(--border-default)"},children:[e.jsx("div",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"'IBM Plex Mono', monospace",marginBottom:4},children:r??"no step selected"}),e.jsx("h2",{style:{fontSize:18,fontWeight:600,color:"var(--text-primary)",margin:0},children:(n==null?void 0:n.label)??"—"}),e.jsx("p",{style:{fontSize:13,color:t?"var(--text-muted)":"var(--accent-error, #d44)",margin:"6px 0 0"},children:t??"(missing description)"})]})}function $({rendered:n,renderError:r,renderLoading:t}){return e.jsx("div",{style:{flex:1,overflow:"auto",padding:"16px 20px"},children:r?e.jsx(S,{message:r,kind:"render"}):n?e.jsx("div",{style:{opacity:t?.6:1},children:e.jsx(I,{children:n.instructions})}):e.jsx("div",{style:{color:"var(--text-muted)",fontSize:13},children:t?"Rendering…":"Select a step."})})}function N(){return{provider:"claude",port:3e3,controlPort:14199,dimension:"Desktop",screenSizes:["Desktop"],hasProject:!1,isResuming:!1,needsScaffold:!1,startCommand:"npm run dev",hasGlossary:!1,hasUserPrompt:!1,selectedPlan:null,needsInitialStartingSurface:!1}}function _(){const[n,r]=d.useState("ui"),[t,o]=d.useState(null),[s,i]=d.useState(null),[l,a]=d.useState(null),[f,P]=d.useState(N),[w,g]=d.useState(null),[B,m]=d.useState(null),[z,b]=d.useState(!1),v=d.useCallback(async x=>{i(null),o(null),g(null),m(null),a(null);try{const u=await(await fetch(`/api/workflow?mode=${x}`)).json();if("error"in u){i(u.error);return}o(u);const p=H(u);a(p)}catch(c){i(c instanceof Error?c.message:String(c))}},[]);d.useEffect(()=>{v(n)},[n,v]);const j=d.useCallback(async(x,c,u)=>{b(!0),m(null);try{const h=await(await fetch("/api/workflow/render",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:x,mode:c,vars:u})})).json();if("error"in h){g(null),m(h.error);return}g(h)}catch(p){g(null),m(p instanceof Error?p.message:String(p))}finally{b(!1)}},[]);d.useEffect(()=>{l&&j(l,n,f)},[l,n,f,j]);const C=l?O(t,l):null,M=t&&l?U(t,l):[],R=t?[...M,...t.globalVariables??[]]:[];return e.jsxs("div",{style:{display:"flex",height:"100vh",background:"var(--bg-deep)",color:"var(--text-secondary)",fontFamily:"'IBM Plex Sans', system-ui, sans-serif"},children:[e.jsx(G,{mode:n,workflow:t,loadError:s,selectedSlug:l,onModeChange:r,onSelectSlug:a}),e.jsx(W,{rendered:w,renderError:B,renderLoading:z,selectedSlug:l,selectedDescription:C,visibleVariables:R,vars:f,onVarChange:(x,c)=>P(u=>({...u,[x]:c}))})]})}function H(n){for(const r of n.steps){if(r.kind==="slug")return r.slug;if(r.kind==="branch"&&r.arms.length>0)return r.arms[0].slug}return null}function O(n,r){if(!n)return null;for(const t of n.steps){if(t.kind==="slug"&&t.slug===r)return t.description;if(t.kind==="branch"){const o=t.arms.find(s=>s.slug===r);if(o)return o.description}}return null}function U(n,r){for(const t of n.steps){if(t.kind==="slug"&&t.slug===r)return t.variables??[];if(t.kind==="branch"){const o=t.arms.find(s=>s.slug===r);if(o)return o.variables??[]}}return[]}function G({mode:n,workflow:r,loadError:t,selectedSlug:o,onModeChange:s,onSelectSlug:i}){return e.jsxs("div",{style:{width:360,minWidth:360,borderRight:"1px solid var(--border-default)",display:"flex",flexDirection:"column",overflow:"auto"},children:[e.jsx(K,{}),e.jsx(J,{mode:n,onChange:s}),t?e.jsx(S,{message:t,kind:"load"}):r?e.jsx(E,{workflow:r,selectedSlug:o,onSelectSlug:i}):e.jsx("div",{style:{padding:16,color:"var(--text-muted)"},children:"Loading…"})]})}function K(){return e.jsxs("div",{style:{padding:"16px 16px 12px",borderBottom:"1px solid var(--border-default)"},children:[e.jsx("h1",{style:{fontSize:16,fontWeight:600,color:"var(--text-primary)",margin:0},children:"Workflow Viewer"}),e.jsx("p",{style:{fontSize:12,color:"var(--text-muted)",margin:"4px 0 0"},children:"Live data from the server. Click a step to see its instructions and edit variables to see how the rendered text changes."})]})}function J({mode:n,onChange:r}){return e.jsx("div",{style:{padding:"12px 16px 8px"},children:e.jsx("div",{style:{display:"flex",gap:4},children:["ui","backend"].map(t=>e.jsx("button",{onClick:()=>r(t),style:{padding:"5px 12px",borderRadius:4,border:"none",cursor:"pointer",fontSize:12,fontWeight:500,flex:1,background:n===t?"var(--accent-active)":"var(--bg-input)",color:n===t?"#000":"var(--text-secondary)"},children:t==="ui"?"UI":"Backend"},t))})})}function S({message:n,kind:r}){return e.jsxs("div",{style:{margin:16,padding:12,borderRadius:4,background:"rgba(220, 60, 60, 0.1)",border:"1px solid rgba(220, 60, 60, 0.3)",color:"#f99",fontSize:12,fontFamily:"'IBM Plex Mono', monospace",whiteSpace:"pre-wrap"},children:[e.jsx("div",{style:{fontWeight:600,marginBottom:4},children:r==="load"?"Failed to load workflow":"Failed to render step"}),n]})}const X=Object.freeze(Object.defineProperty({__proto__:null,ErrorBanner:S,StepsSimulator:_},Symbol.toStringTag,{value:"Module"}));export{W as S,V as a,E as b,_ as c,X as d};
|