@codeyam-editor/codeyam-editor 0.1.0 → 0.1.2
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 +5 -2
- package/npm/cloud-branch-switch.js +442 -0
- package/npm/cloud.js +1521 -0
- package/npm/container.js +28 -5
- package/npm/editor-dev.js +378 -0
- package/npm/editor.js +199 -12
- package/npm/empty-project-dir.js +33 -0
- package/npm/fleet-auth.js +111 -0
- package/npm/fleet-cleanup.js +124 -0
- package/npm/fleet-env.js +125 -0
- package/npm/fleet-memory.js +127 -0
- package/npm/fleet-pool-policy.js +78 -0
- package/npm/fleet-pool.js +401 -0
- package/npm/fleet-queue.js +40 -0
- package/npm/fleet-reconcile.js +36 -0
- package/npm/fleet-reset.js +144 -0
- package/npm/fleet-roster.js +81 -0
- package/npm/launch-config.js +544 -0
- package/npm/preflight-guidance.js +68 -0
- package/npm/scenario-check.js +355 -290
- package/npm/scenario-handlers.js +82 -0
- package/npm/scenario-interactivity.js +199 -0
- package/npm/scenario-issues.js +35 -0
- package/npm/scenario-metrics.js +108 -0
- package/npm/scenario-mocks.js +107 -0
- package/npm/scenario-playwright.js +355 -0
- package/npm/utils.js +548 -22
- package/npm/vm-urls.js +117 -0
- package/package.json +13 -6
- package/ui/dist/assets/ContainerInspector-C8EkH4PP.js +2 -0
- package/ui/dist/assets/EditorShell-DWaeBxgj.js +186 -0
- package/ui/dist/assets/Markdown-BHBqz-Mj.js +1 -0
- package/ui/dist/assets/ScenarioDataPanel-DYP7pi_n.css +32 -0
- package/ui/dist/assets/ScenarioDataPanel-zJSXtXL4.js +5 -0
- package/ui/dist/assets/ScenarioDataPanelFullPage-C0YHQB-T.js +1 -0
- package/ui/dist/assets/ScenarioRenderer-CgDxuigm.js +1 -0
- package/ui/dist/assets/StepsSimulator-CRtmlyNZ.js +1 -0
- package/ui/dist/assets/index-BUYNFqKK.js +27 -0
- package/ui/dist/assets/index-DVr5rY2d.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
- package/npm/postinstall.js +0 -95
|
@@ -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,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,5 @@
|
|
|
1
|
+
import{j as n}from"./markdown-v0F0UEt3.js";import{b as u}from"./react-CSS0HapR.js";import{u as Ve}from"./useEvents-DggWrtHe.js";import{r as Xe,a as Ue}from"./xterm--24IGk-x.js";import{l as K,b as ze}from"./index-BUYNFqKK.js";const se=4e3;function je(e){let t;try{t=JSON.stringify(e,null,2)}catch{t=String(e)}return t.length>se?`${t.slice(0,se)}
|
|
2
|
+
… (truncated, ${t.length-se} more chars)`:t}function We({slug:e,scenarioName:t,seedTabs:r,mockEntries:a,selectedMock:s,selectedSeedTab:o,selectedSeedRows:c}){const i=[],f=t??e;if(i.push(`# Edit Scenario Data: "${f}"`),i.push(""),i.push(`**Slug**: ${e}`),i.push(`**Scenario file**: .codeyam/scenarios/${e}.json`),i.push(""),i.push("## Scenario overview"),r.length>0){i.push("### Seed & Local tables");for(const h of r){const g=h.category?` (${h.category})`:"";i.push(`- **${h.label}**${g} — dataKey \`${h.dataKey}\``)}i.push("")}if(a.length>0){i.push("### HTTP mocks");const h=new Map;for(const g of a){const m=h.get(g.source)??[];m.push(g),h.set(g.source,m)}for(const[g,m]of h){i.push(`**${g}** (${m.length}):`);for(const l of m)i.push(`- \`${l.method} ${l.pathPattern}\``)}i.push("")}if(s){const h=`${s.method} ${s.pathPattern}`;i.push(`## Currently viewing: mock \`${h}\``),i.push(`- **Source**: ${s.source}`),s.status!==void 0&&i.push(`- **Status**: ${s.status}`);const g=s.headers??{},m=Object.entries(g);if(m.length>0){i.push("- **Headers**:");for(const[l,p]of m)i.push(` - \`${l}: ${p}\``)}s.body!==void 0&&s.body!==null?(i.push("- **Body**:"),i.push("```json"),i.push(je(s.body)),i.push("```")):i.push("- **Body**: (empty)"),i.push("")}else if(o){if(i.push(`## Currently viewing: seed table **${o.label}**`),i.push(`- **dataKey**: \`${o.dataKey}\``),o.category&&i.push(`- **Category**: ${o.category}`),o.description&&i.push(`- **Description**: ${o.description}`),o.schemaFields&&o.schemaFields.length>0){i.push("- **Schema**:");for(const h of o.schemaFields){const g=h.isId?" (PK)":"";i.push(` - \`${h.name}\`: ${h.type}${g}`)}}c&&c.length>0?(i.push(`- **Rows** (${c.length}):`),i.push("```json"),i.push(je(c)),i.push("```")):i.push("- **Rows**: (none yet)"),i.push("")}return i.push("## Your task"),i.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."),i.push(""),i.push("Typical edits:"),i.push('- Tweak an HTTP mock body, status, or headers → update `mocks.http["METHOD /path"]` in the scenario JSON'),i.push("- Add or remove seed rows → update the `seed` section"),i.push("- Adjust `localStorage` values → update the `localStorage` section"),i.push(""),i.push("To save changes:"),i.push("1. Write the updated scenario JSON to `.codeyam/tmp/scenario.json`"),i.push("2. Run: `codeyam-editor editor register @.codeyam/tmp/scenario.json`"),i.push("3. The editor will reload automatically and the panel will reflect the new data."),i.join(`
|
|
3
|
+
`)}const fe=new Set;let J=null;const Je=150;function En(e){return fe.add(e),()=>{fe.delete(e)}}function U(){J&&clearTimeout(J),J=setTimeout(()=>{J=null;for(const e of fe)e()},Je)}const pe=new Set;function Tn(e){for(const t of pe)t(e)}function qe(e){return pe.add(e),()=>{pe.delete(e)}}function Ge({onSelect:e,onFocus:t}){u.useEffect(()=>qe(({routeKey:r,jsonPath:a})=>{e(r),t(a)}),[e,t])}const Qe="claude";function Oe(e){switch(e){case"codex":return"Codex";case"gemini":return"Gemini";default:return"Claude"}}function Ae(){const[e,t]=u.useState(null),[r,a]=u.useState(!0),[s,o]=u.useState(null),c=u.useCallback(async()=>{try{const i=await fetch("/api/config");if(!i.ok)throw new Error(`HTTP ${i.status}`);const f=await i.json();t({projectTitle:f.projectTitle??null,projectDescription:f.projectDescription??null,provider:f.provider??Qe,port:f.port??3e3,previewOrigin:f.previewOrigin??null,screenSizes:f.screenSizes??{},defaultScreenSize:f.defaultScreenSize??null,apps:f.apps??[]}),o(null)}catch(i){o(i instanceof Error?i.message:"Failed to load config")}finally{a(!1)}},[]);return u.useEffect(()=>{c()},[c]),{config:e,apps:(e==null?void 0:e.apps)??[],loading:r,error:s,refetch:c}}async function Z(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)}`:"",s=await(await fetch(`/api/mock-panel/${encodeURIComponent(e)}${r}`)).json();if("error"in s)throw new Error(s.error);return s}async function Se(e,t){const r=`/api/scenarios/${encodeURIComponent(e)}/mocks/${encodeURIComponent(t.routeKey)}`,a=await fetch(r,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:t.status,body:t.body,headers:t.headers})});if(!a.ok)throw new Error(await Z(a))}async function et(e,t){const r=`/api/scenarios/${encodeURIComponent(e)}/mocks/${encodeURIComponent(t)}`,a=await fetch(r,{method:"DELETE"});if(!a.ok)throw new Error(await Z(a))}async function tt(e,t){const r=`/api/scenarios/${encodeURIComponent(e)}/mocks/${encodeURIComponent(t)}/passthrough`,a=await fetch(r,{method:"POST"});if(!a.ok)throw new Error(await Z(a))}function H(e){return e.kind==="shared"?`shared:${e.slug}`:e.kind}async function rt(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 nt(e,t,r){const a=new URLSearchParams({scenarioSlug:e,routeKey:t,scope:H(r)}),s=await fetch(`/api/mocks/save-scope-impact?${a.toString()}`);if(!s.ok)throw new Error(await Z(s));return(await s.json()).impactedScenarios??[]}function at(){const[e,t]=u.useState(null),[r,a]=u.useState(null),s=u.useRef(null),o=async()=>{try{const i=await fetch("/api/editor-dev-server");if(!i.ok)throw new Error(`Failed to fetch dev server status: ${i.statusText}`);const f=await i.json(),h=JSON.stringify(f);if(h===s.current){a(null);return}s.current=h,t(f),a(null)}catch(i){a(i instanceof Error?i.message:String(i))}};return u.useEffect(()=>{o();const i=setInterval(o,1e3);return()=>clearInterval(i)},[]),{status:e,error:r,restart:async()=>{try{const i=await fetch("/api/editor-dev-server",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"restart"})});if(!i.ok)throw new Error(`Failed to restart dev server: ${i.statusText}`);o()}catch(i){a(i instanceof Error?i.message:String(i))}}}}function st(e){const[t,r]=u.useState([]),[a,s]=u.useState(null),[o,c]=u.useState(!1),[i,f]=u.useState(null),{events:h}=Ve(),{status:g}=at(),m=(g==null?void 0:g.lastIframeLoadedAtMs)??null,l=u.useCallback(async()=>{if(!e){r([]),s(null);return}c(!0),f(null);try{const d=await Ze(e,m);r(d.entries),s(d.defaultSlug)}catch(d){f(d instanceof Error?d.message:"Failed to load mocks")}finally{c(!1)}},[e,m]);u.useEffect(()=>{l()},[l]),u.useEffect(()=>{const d=h[h.length-1];!d||d.type!=="http_request"||l()},[h,l]);const p=u.useCallback(async d=>{e&&(await Se(e,d),await l())},[e,l]),x=u.useCallback(async d=>{e&&(d.scope.kind==="scenario"?await Se(e,{routeKey:d.routeKey,status:d.status,body:d.body,headers:d.headers}):await rt({scenarioSlug:e,routeKey:d.routeKey,scope:d.scope,status:d.status,body:d.body,headers:d.headers}),await l())},[e,l]),b=u.useCallback(async d=>{e&&(await et(e,d),await l())},[e,l]),v=u.useCallback(async d=>{e&&(await tt(e,d),await l())},[e,l]);return{entries:t,defaultSlug:a,loading:o,error:i,refresh:l,upsert:p,upsertScoped:x,remove:b,setPassthrough:v}}function ot(e){const t={};for(const[r,a]of Object.entries(e))if(typeof a=="string")try{const s=JSON.parse(a);Array.isArray(s)?t[r]=s:typeof s=="object"&&s!==null&&(t[r]=[s])}catch{}else Array.isArray(a)&&(t[r]=a);return t}function it(e,t){return e.length===0||t.length===0?!1:e.filter(a=>t.includes(a)).length>=Math.min(e.length,t.length)*.5}function ct(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 lt(e,t){return e.length>0?Object.keys(e[0]):t?t.map(r=>r.name):[]}function dt(e,t,r){const a=new Map((r||[]).map(o=>[o.name,o.type])),s={};for(const o of e)s[o]=a.get(o)||(t.length>0?ct(t[0][o]):"text");return s}function ut(e,t){var r;return((r=t==null?void 0:t.find(a=>a.isId))==null?void 0:r.name)||e.find(a=>a==="id")||null}function ft(e,t){const{_metadata:r,...a}=t,s=a.localStorage&&typeof a.localStorage=="object"&&!Array.isArray(a.localStorage)?ot(a.localStorage):{},o={};if(a.seed&&typeof a.seed=="object"&&!Array.isArray(a.seed))for(const[l,p]of Object.entries(a.seed))Array.isArray(p)&&(o[l]=p);const c={},i=[],f=new Set,h=new Set,g=new Set;for(const l of e){const p=l.name.charAt(0).toLowerCase()+l.name.slice(1),x=l.fields.map(d=>d.name);let b=null,v=[];for(const d of[l.name,p,`${p}s`])if(d in a&&Array.isArray(a[d])){b=d,v=a[d],h.add(d);break}if(!b){for(const d of[l.name,p,`${p}s`])if(d in o){b=d,v=o[d],g.add(d),d in s&&f.add(d);break}}if(!b){for(const d of[l.name,p,`${p}s`])if(d in s){b=p,v=s[d],f.add(d);break}}if(!b){for(const[d,y]of Object.entries(s))if(!f.has(d)&&y.length>0&&it(x,Object.keys(y[0]))){b=p,v=y,f.add(d);break}}b||(b=p),c[b]=v,i.push({label:l.name,dataKey:b,category:l.category,description:l.description,schemaFields:l.fields.map(d=>({name:d.name,type:d.type,isId:d.isId??!1}))})}const m=new Set(["name","id","url","dimensions","componentName","scenarioType","pageFilePath","routeName","description","props","env"]);for(const[l,p]of Object.entries(a))l==="_metadata"||l==="localStorage"||l==="seed"||l==="type"||l==="mocks"||m.has(l)||h.has(l)||pt(p)&&(c[l]=p,i.push({label:l,dataKey:l}));for(const[l,p]of Object.entries(o))g.has(l)||(c[l]=p,i.push({label:l,dataKey:l}));for(const[l,p]of Object.entries(s))f.has(l)||(c[l]=p,i.push({label:l,dataKey:l}));return{data:c,tabs:i}}function ke(e){return e==="null"?null:e==="true"?!0:e==="false"?!1:e===""?"":isNaN(Number(e))?e:Number(e)}function pt(e){return Array.isArray(e)&&e.length>0&&typeof e[0]=="object"&&e[0]!==null}function ht(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 mt(e){if(typeof e!="object"||e===null||!("browserState"in e))return null;const t=e.browserState;return typeof t!="object"||t===null||Array.isArray(t)?null:t}function xt(e,t){const r=new Set;for(const a of t){const s=e[a.dataKey];Array.isArray(s)&&s.length>0&&r.add(a.dataKey)}return r}function bt(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 gt(e){const[t,r]=u.useState({data:null,tableTabs:[],scenarioOwnedDataKeys:new Set,shares:[],props:null,browserState:null,loading:!0,error:null});return u.useEffect(()=>{r(a=>({...a,loading:!0,error:null})),Promise.all([fetch("/api/data-structure").then(a=>a.json()).catch(()=>[]),fetch(`/api/scenarios/${encodeURIComponent(e)}`).then(a=>{if(!a.ok)throw new Error(`HTTP ${a.status}`);return a.json()})]).then(([a,s])=>{const o=ft(Array.isArray(a)?a:[],s);r({data:o.data,tableTabs:o.tabs,scenarioOwnedDataKeys:xt(o.data,o.tabs),shares:bt(s),props:ht(s),browserState:mt(s),loading:!1,error:null})}).catch(a=>r({data:null,tableTabs:[],scenarioOwnedDataKeys:new Set,shares:[],props:null,browserState:null,loading:!1,error:a instanceof Error?a.message:"Failed to load"}))},[e]),t}function xe(e,t=""){return`/api/scenarios/${encodeURIComponent(e)}/draft${t}`}async function yt(e){const t=await fetch(xe(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 vt(e){const t=await fetch(xe(e,"/commit"),{method:"POST"});if(!t.ok)throw new Error(`Save failed (${t.status})`)}async function wt(e){const t=await fetch(xe(e),{method:"DELETE"});if(!t.ok)throw new Error(`Cancel failed (${t.status})`)}function jt({slug:e,onPreviewReload:t}){const[r,a]=u.useState(!1),[s,o]=u.useState(null),[c,i]=u.useState(!1),[f,h]=u.useState(!1),[g,m]=u.useState(null),l=u.useRef(null),p=u.useCallback(async()=>{if(!e){a(!1),o(null);return}try{const y=await yt(e);a(y.isDirty),o(y.diffSummary)}catch{}},[e]);u.useEffect(()=>{p()},[p]),u.useEffect(()=>{if(!r)return;const y=C=>{C.preventDefault(),C.returnValue=""};return window.addEventListener("beforeunload",y),()=>window.removeEventListener("beforeunload",y)},[r]);const x=u.useCallback(()=>{l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{p()},100)},[p]),b=u.useCallback(async()=>{if(e){i(!0),m(null);try{await vt(e),a(!1),o(null),t&&t()}catch(y){m(y instanceof Error?y.message:"Save failed")}finally{i(!1)}}},[e,t]),v=u.useCallback(async()=>{if(e){h(!0),m(null);try{await wt(e),a(!1),o(null),t&&t()}catch(y){m(y instanceof Error?y.message:"Cancel failed")}finally{h(!1)}}},[e,t]),d=u.useCallback(y=>r?window.confirm(y):!0,[r]);return{isDirty:r,saving:c,cancelling:f,error:g,diffSummary:s,save:b,cancel:v,markDirty:x,confirmIfDirty:d}}const St={scenario:"Scenario",shared:"Shared",default:"Defaults","catalog-only":"Observed only",passthrough:"Passthrough"},kt={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 $e(e){return St[e]??e}function Ct(e){return kt[e]??null}const Nt={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-[#D7FF63]/15 text-[#D7FF63] border-[#D7FF63]/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 Le({source:e}){const t=Ct(e);return n.jsx("span",{className:`px-1.5 py-0.5 rounded border ${Nt[e]}`,title:t??`source: ${e}`,children:$e(e)})}function Et({label:e,scenarioCount:t,inheritedCount:r,expanded:a,onToggle:s}){const o=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:s,disabled:o,"aria-expanded":a,className:`inline-flex items-center gap-0.5 ${o?"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:o?"":a?"▾":"▸"}),n.jsxs("span",{children:[r," inherited from default"]})]})]})]})}function Tt({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 Dt({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 Mt={GET:"text-emerald-400",POST:"text-[#D7FF63]",PUT:"text-amber-400",PATCH:"text-purple-400",DELETE:"text-red-400"};function Rt({entry:e,routeKey:t,active:r,onSelect:a}){const s=Mt[e.method]??"text-[var(--text-muted)]";return n.jsxs("button",{onClick:a,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 ${s}`,children:e.method}),n.jsx("span",{className:"truncate flex-1 font-mono",children:e.pathPattern}),e.source==="shared"&&e.sharedSlug&&n.jsx(Dt,{slug:e.sharedSlug})]})}const Ot=["scenario","shared","default","catalog-only","passthrough"];function z(e){return`${e.method} ${e.pathPattern}`}function At({seedTabs:e,mockEntries:t,selection:r,onSelect:a,overrides:s}){const o=new Map;for(const c of t){const i=o.get(c.source)??[];i.push(c),o.set(c.source,i)}return n.jsxs("nav",{className:"w-56 shrink-0 border-r border-[var(--border-subtle)] bg-[var(--bg-deep)] overflow-y-auto",children:[n.jsxs(oe,{label:"Browser Environment",count:4,emptyHint:"",children:[n.jsx(q,{label:"Cookies",active:(r==null?void 0:r.kind)==="browser"&&r.tab==="cookies",onSelect:()=>a({kind:"browser",tab:"cookies"})}),n.jsx(q,{label:"Local Storage",active:(r==null?void 0:r.kind)==="browser"&&r.tab==="localStorage",onSelect:()=>a({kind:"browser",tab:"localStorage"})}),n.jsx(q,{label:"Session Storage",active:(r==null?void 0:r.kind)==="browser"&&r.tab==="sessionStorage",onSelect:()=>a({kind:"browser",tab:"sessionStorage"})}),n.jsx(q,{label:"Request Headers",active:(r==null?void 0:r.kind)==="browser"&&r.tab==="headers",onSelect:()=>a({kind:"browser",tab:"headers"})})]}),n.jsx(oe,{label:"Seed & Local",count:e.length,emptyHint:"No seed or localStorage data",override:s?{scenarioCount:s.scenarioSeedCount,inheritedCount:s.inheritedSeedCount,renderInherited:()=>Ce({tabs:s.inheritedSeedTabs,selection:r,onSelect:a})}:void 0,children:Ce({tabs:e,selection:r,onSelect:a})}),n.jsx(oe,{label:"Mock APIs",count:t.length,emptyHint:"No HTTP mocks registered",override:s?{scenarioCount:s.scenarioMockCount,inheritedCount:s.inheritedMockCount,renderInherited:()=>Ne({entries:s.inheritedMockEntries,selection:r,onSelect:a})}:void 0,children:Ne({entries:t,grouped:o,selection:r,onSelect:a})})]})}function Ce({tabs:e,selection:t,onSelect:r}){return e.map(a=>{const s=(t==null?void 0:t.kind)==="seed"&&t.dataKey===a.dataKey;return n.jsxs("button",{onClick:()=>r({kind:"seed",dataKey:a.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 ${s?"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:a.label}),a.category&&n.jsx("span",{className:"text-[9px] uppercase tracking-wide text-[var(--text-dim)]",children:a.category==="mock-api"?"API":a.category})]},a.dataKey)})}function q({label:e,active:t,onSelect:r}){return n.jsxs("button",{onClick:r,className:`w-full text-left px-3 py-1.5 text-xs flex items-center gap-2 border-l-2 transition-colors cursor-pointer ${t?"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:e}),n.jsx("span",{className:"text-[9px] uppercase tracking-wide text-[var(--text-dim)]",children:"ENV"})]})}function Ne({entries:e,grouped:t,selection:r,onSelect:a}){const s=t??$t(e);return Ot.flatMap(o=>{const c=s.get(o)??[];return c.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:[$e(o),n.jsx(Le,{source:o})]},`hdr-${o}`),...c.map(i=>{const f=z(i),h=(r==null?void 0:r.kind)==="mock"&&r.routeKey===f;return n.jsx(Rt,{entry:i,routeKey:f,active:h,onSelect:()=>a({kind:"mock",routeKey:f})},f)})]})}function $t(e){const t=new Map;for(const r of e){const a=t.get(r.source)??[];a.push(r),t.set(r.source,a)}return t}function oe({label:e,count:t,emptyHint:r,children:a,override:s}){const[o,c]=u.useState(!1);if(s){const{scenarioCount:i,inheritedCount:f,renderInherited:h}=s,g=i+(o?f:0);return n.jsxs("section",{className:"py-2",children:[n.jsx(Et,{label:e,scenarioCount:i,inheritedCount:f,expanded:o,onToggle:()=>c(m=>!m)}),g===0?n.jsx("p",{className:"px-3 py-1 text-[10px] italic text-[var(--text-dim)]",children:r}):n.jsxs("div",{children:[a,o&&f>0&&n.jsx(Tt,{children:h()})]})]})}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:a})]})}function Lt({seedTabs:e,mockEntries:t,initialSection:r,selection:a,setSelection:s}){u.useEffect(()=>{if(a)return;const o=r==="mocks",c=r==="seed";if(o&&t.length>0){s({kind:"mock",routeKey:z(t[0])});return}if(c&&e.length>0){s({kind:"seed",dataKey:e[0].dataKey});return}e.length>0?s({kind:"seed",dataKey:e[0].dataKey}):t.length>0&&s({kind:"mock",routeKey:z(t[0])})},[r,t,e,a,s])}var It=Xe(),Pt=Ue();function Bt(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()}async function Kt(e){try{if(typeof navigator<"u"&&navigator.clipboard&&typeof navigator.clipboard.writeText=="function")return await navigator.clipboard.writeText(e),!0}catch{}return Ft(e)}function Ft(e){var s;if(typeof document>"u"||!document.body)return!1;const t=document.activeElement,r=document.createElement("textarea");r.value=e,r.setAttribute("readonly",""),r.style.position="fixed",r.style.top="0",r.style.left="-9999px",r.style.opacity="0",r.style.pointerEvents="none",document.body.appendChild(r);let a=!1;try{r.focus(),r.select(),a=document.execCommand("copy")}catch{a=!1}finally{r.remove(),(s=t==null?void 0:t.focus)==null||s.call(t)}return a}function _t(){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 Ht(e,t,r={}){const a=r.isMac??_t(),s=r.onError,o=r.onCopy;let c=null;async function i(x){if(!x)return!1;let b=!1;try{b=await Kt(x)}catch(v){return s==null||s(Ee("copy",v)),!1}if(b){try{e.clearSelection()}catch{}o==null||o()}else s==null||s(Vt("copy"));return b}async function f(){return e.hasSelection()?i(e.getSelection()):!1}async function h(){try{const x=await navigator.clipboard.readText();x&&e.paste(x)}catch(x){s==null||s(Ee("paste",x))}}function g(x){return x.type!=="keydown"?!0:a?(x.metaKey&&!x.ctrlKey&&!x.altKey&&x.key.toLowerCase()==="c"||x.ctrlKey&&!x.metaKey&&!x.altKey&&!x.shiftKey&&x.key.toLowerCase()==="c")&&e.hasSelection()?(f(),!1):!0:(x.ctrlKey&&x.shiftKey&&!x.metaKey&&!x.altKey&&x.key.toLowerCase()==="c"||x.ctrlKey&&!x.shiftKey&&!x.metaKey&&!x.altKey&&x.key.toLowerCase()==="c")&&e.hasSelection()?(f(),!1):!0}e.attachCustomKeyEventHandler(g);function m(){if(!c)return;const{root:x,onDocumentClick:b,onKeyDown:v}=c;document.removeEventListener("mousedown",b,!0),document.removeEventListener("keydown",v,!0),x.remove(),c=null}function l(x,b,v){m();const d=document.createElement("div");d.setAttribute("data-terminal-clipboard-menu","true"),d.style.position="fixed",d.style.left=`${x}px`,d.style.top=`${b}px`,d.style.zIndex="1000",d.style.minWidth="180px",d.style.padding="4px 0",d.style.background="var(--bg-card)",d.style.border="1px solid var(--border-subtle)",d.style.borderRadius="6px",d.style.boxShadow="0 8px 24px rgba(0, 0, 0, 0.35)",d.style.fontSize="12px",d.style.color="var(--text-primary)",d.style.userSelect="none";const y=a?"⌘C":"Ctrl+Shift+C",C=a?"⌘V":"Ctrl+Shift+V",j=ie("Copy",y,!v,()=>{i(v),m()}),T=ie("Paste",C,!1,()=>{h(),m()}),P=ie("Select All","",!1,()=>{try{e.selectAll()}catch{}const w=e.hasSelection()?e.getSelection():"";i(w),m()});d.appendChild(j),d.appendChild(T),d.appendChild(P),document.body.appendChild(d),Yt(d,x,b);const L=w=>{d.contains(w.target)||m()},M=w=>{w.key==="Escape"&&(w.preventDefault(),m())};document.addEventListener("mousedown",L,!0),document.addEventListener("keydown",M,!0),c={root:d,onDocumentClick:L,onKeyDown:M}}function p(x){x.preventDefault();const b=e.hasSelection()?e.getSelection():"";l(x.clientX,x.clientY,b)}return t.addEventListener("contextmenu",p),()=>{t.removeEventListener("contextmenu",p),m(),e.attachCustomKeyEventHandler(()=>!0)}}function ie(e,t,r,a){const s=document.createElement("button");s.type="button",s.disabled=r,s.style.display="flex",s.style.justifyContent="space-between",s.style.alignItems="center",s.style.gap="16px",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=r?"default":"pointer",s.style.color=r?"var(--text-dim)":"var(--text-primary)";const o=document.createElement("span");if(o.textContent=e,s.appendChild(o),t){const c=document.createElement("span");c.textContent=t,c.style.color="var(--text-dim)",c.style.fontSize="11px",s.appendChild(c)}return r||(s.addEventListener("mouseenter",()=>{s.style.background="var(--border-subtle)"}),s.addEventListener("mouseleave",()=>{s.style.background="transparent"}),s.addEventListener("click",()=>a())),s}function Yt(e,t,r){const a=typeof window<"u"?window.innerWidth:0,s=typeof window<"u"?window.innerHeight:0;if(!a||!s)return;const o=e.getBoundingClientRect(),c=4;let i=t,f=r;o.width&&t+o.width+c>a&&(i=Math.max(c,a-o.width-c)),o.height&&r+o.height+c>s&&(f=Math.max(c,s-o.height-c)),e.style.left=`${i}px`,e.style.top=`${f}px`}function Ee(e,t){const r=t instanceof Error?t.message:String(t);return`Clipboard ${e} failed: ${r}`}function Vt(e){return`Clipboard ${e} blocked by the browser.`}function Xt(e,t,r,a,s,o){const c=e.leftBorderCol+1;if(t===a)return s-r;if(a<t){let h=r-c;h+=1;for(let m=a+1;m<t;m++){const l=o(m);if(l===null)return null;h+=Math.max(1,l-c+1)}const g=o(a);return g===null?null:(h+=Math.max(0,g-s),-h)}const i=o(t);if(i===null)return null;let f=Math.max(0,i-r)+1;for(let h=t+1;h<a;h++){const g=o(h);if(g===null)return null;f+=Math.max(1,g-c+1)}return f+=s-c,f}const G=new Set(["│","┃","║","|"]);function Ut(e,t,r,a){const s=e.baseY,o=(p,x)=>{const b=e.getLine(s+p);if(!b)return null;const v=b.getCell(x);return v?v.getChars():null},c=p=>{let x=-1;for(let v=0;v<r;v++){const d=o(p,v);if(d!==null&&G.has(d)){x=v;break}}if(x===-1)return null;let b=-1;for(let v=r-1;v>x;v--){const d=o(p,v);if(d!==null&&G.has(d)){b=v;break}}return b===-1?null:{leftBorderCol:x,rightBorderCol:b}};let i=t,f=c(t);if(!f){const p=c(t-1);if(p)i=t-1,f=p;else{const x=c(t+1);x&&(i=t+1,f=x)}}if(!f)return null;const{leftBorderCol:h,rightBorderCol:g}=f;let m=i;for(let p=i-1;p>=0;p--){const x=o(p,h);if(x===null)break;if(!(x===""||x===" ")){if(!G.has(x))break;m=p}}let l=i;for(let p=i+1;p<a;p++){const x=o(p,h);if(x===null)break;if(!(x===""||x===" ")){if(!G.has(x))break;l=p}}return{topRow:m,bottomRow:l,leftBorderCol:h,rightBorderCol:g}}function zt(e,t,r,a){const s=e.getLine(e.baseY+t);if(!s)return null;for(let o=a;o>=r;o--){const c=s.getCell(o);if(!c)continue;const i=c.getChars();if(i!==""&&i!==" ")return o}return r-1}const Wt=200;function Jt(e){const{click:t,terminal:r,cellSurface:a,debug:s}=e,o=r.buffer.active,c=j=>{s==null||s({cursorY:o.cursorY,cursorX:o.cursorX,originalTargetCol:j.originalTargetCol??j.targetCol,snapped:j.snapped??!1,...j})};if(o.type==="alternate")return c({targetRow:-1,targetCol:-1,box:null,rejected:"alt-screen",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;if(o.viewportY!==o.baseY)return c({targetRow:-1,targetCol:-1,box:null,rejected:"scrollback",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const i=a.getBoundingClientRect();if(i.width===0||i.height===0)return c({targetRow:-1,targetCol:-1,box:null,rejected:"outside-grid",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const f=t.clientX-i.left,h=t.clientY-i.top;if(f<0||h<0||f>=i.width||h>=i.height)return c({targetRow:-1,targetCol:-1,box:null,rejected:"outside-grid",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const g=i.width/r.cols,m=i.height/r.rows,l=Math.floor(f/g),p=Math.floor(h/m),x=r.modes.applicationCursorKeysMode,b=x?"\x1BOC":"\x1B[C",v=x?"\x1BOD":"\x1B[D",d=Ut(o,o.cursorY,r.cols,r.rows);if(d){if(p<d.topRow||p>d.bottomRow)return c({targetRow:p,targetCol:l,box:d,rejected:"out-of-box",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;if(l<=d.leftBorderCol||l>=d.rightBorderCol)return c({targetRow:p,targetCol:l,box:d,rejected:"border",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const j=d.leftBorderCol+1,T=d.rightBorderCol-1,P=k=>zt(o,k,j,T),L=o.cursorY<d.topRow||o.cursorY>d.bottomRow,M=L?d.bottomRow:o.cursorY,w=L?T:o.cursorX,D=p!==M;let S=null;if(D&&(S=P(p),S===null))return c({targetRow:p,targetCol:l,originalTargetCol:l,snapped:!1,box:d,rejected:"unreadable-row",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;let N=l,O=!1;if(D&&S!==null){const k=Math.max(j,S);l>k&&(N=k,O=!0)}if(p===M&&N===w)return c({targetRow:p,targetCol:N,originalTargetCol:l,snapped:O,box:d,rejected:"same-cell",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const $=Xt(d,M,w,p,N,P);if($===null)return c({targetRow:p,targetCol:N,originalTargetCol:l,snapped:O,box:d,rejected:"unreadable-row",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;if($===0)return c({targetRow:p,targetCol:N,originalTargetCol:l,snapped:O,box:d,rejected:"same-cell",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;if(Math.abs($)>Wt)return c({targetRow:p,targetCol:N,originalTargetCol:l,snapped:O,box:d,rejected:"emit-cap",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const B=$<0?v.repeat(-$):b.repeat($);return c({targetRow:p,targetCol:N,originalTargetCol:l,snapped:O,box:d,rejected:null,emittedDirection:$<0?"left":"right",emittedByteCount:B.length,predictedCursorY:p,predictedCursorX:N}),B}if(p!==o.cursorY)return c({targetRow:p,targetCol:l,box:null,rejected:"out-of-box",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const y=l-o.cursorX;if(y===0)return c({targetRow:p,targetCol:l,box:null,rejected:"same-cell",emittedDirection:null,emittedByteCount:0,predictedCursorY:null,predictedCursorX:null}),null;const C=y<0?v.repeat(-y):b.repeat(y);return c({targetRow:p,targetCol:l,box:null,rejected:null,emittedDirection:y<0?"left":"right",emittedByteCount:C.length,predictedCursorY:p,predictedCursorX:l}),C}const Te=1;function qt(e,t){const{sendInput:r,pixelThreshold:a=3,timeThresholdMs:s=300,now:o=()=>Date.now(),onVerificationDisable:c}=t,i=e.element;if(!i)return()=>{};const f=i.querySelector(".xterm-screen")??i;let h=null,g=!1,m=null,l=null;const p=typeof e.onRender=="function"?e.onRender.bind(e):null;p&&(l=p(()=>{const v=m;if(!v)return;m=null;const d=e.buffer.active,y=Math.abs(d.cursorY-v.y),C=Math.abs(d.cursorX-v.x);if(y>Te||C>Te){g=!0;const j={predicted:v,actual:{y:d.cursorY,x:d.cursorX}};c?c(j):console.warn("[click-cursor] disabled — cursor diverged from prediction",j)}}));function x(v){if(v.button!==0||v.altKey||v.shiftKey||v.metaKey||v.ctrlKey){h=null;return}h={clientX:v.clientX,clientY:v.clientY,at:o()}}function b(v){var M;const d=h;if(h=null,!d)return;const y=v.clientX-d.clientX,C=v.clientY-d.clientY;if(Math.hypot(y,C)>a||o()-d.at>s)return;const j=typeof window<"u"&&((M=window.localStorage)==null?void 0:M.getItem("codeyam.terminalClickDebug"))==="1";if(j)try{const w=e.buffer.active,D=w.cursorY,S={};for(let N=-2;N<=2;N++){const O=D+N,$=w.getLine(w.baseY+O);if(!$)continue;const B=[];for(let k=0;k<e.cols;k++){const E=$.getCell(k);B.push(E?E.getChars():"")}S[`row${O}`]=B.join("|")}console.log("[click-cursor] buffer dump",{cursorY:D,cursorX:w.cursorX,viewportY:w.viewportY,baseY:w.baseY,rows:S})}catch{}let T=null;const P=w=>{T=w,j&&console.log("[click-cursor] result",w)},L=Jt({click:{clientX:v.clientX,clientY:v.clientY},terminal:e,cellSurface:f,debug:P});if(L){if(T){const w=T,D=w.box!==null&&w.targetRow!==w.cursorY;if(D&&g){j&&console.log("[click-cursor] suppressed by verification-disabled");return}D&&w.predictedCursorY!==null&&w.predictedCursorX!==null&&(m={y:w.predictedCursorY,x:w.predictedCursorX})}r(L)}}return f.addEventListener("mousedown",x),f.addEventListener("mouseup",b),()=>{f.removeEventListener("mousedown",x),f.removeEventListener("mouseup",b),l==null||l.dispose()}}async function Ie(e=1500){try{return(await fetch("/api/health",{signal:AbortSignal.timeout(e)})).ok}catch{return!1}}function Gt(e,t){let r=!1,a=null;async function s(){if(!r){if(await Ie(1500)){r||t();return}r||(a=setTimeout(s,e))}}return a=setTimeout(s,e),()=>{r=!0,a&&(clearTimeout(a),a=null)}}const Qt="The editor server closed the terminal connection with no further detail.";function Zt(e){if(e&&typeof e=="object"&&"message"in e){const t=e.message;if(typeof t=="string"&&t.length>0)return t}return Qt}function er(){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 tr({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 rr({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 nr({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 ar({message:e,onRefresh:t}){return n.jsx("div",{"data-testid":"terminal-server-error-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-3 rounded font-mono text-sm shadow flex items-start gap-3 max-w-2xl bg-amber-500/95 text-black border border-amber-700",children:[n.jsx("pre",{"data-testid":"terminal-server-error-banner-message",className:"whitespace-pre-wrap break-words flex-1 m-0 font-mono text-xs leading-snug",children:e}),n.jsx("button",{type:"button",onClick:t,"data-testid":"terminal-server-error-banner-refresh",className:"px-2 py-1 rounded bg-white text-amber-900 font-medium cursor-pointer hover:bg-amber-50 self-start",children:"Refresh"})]})})}function sr({status:e,pulseKey:t,onRefresh:r}){return e.kind==="open"||e.kind==="ended"?null:e.kind==="connecting"?n.jsx(er,{}):e.kind==="reconnecting"?n.jsx(tr,{attempt:e.attempt,maxAttempts:e.maxAttempts,pulseKey:t}):e.kind==="server-stopped"?n.jsx(nr,{onReload:r}):e.kind==="server-error"?n.jsx(ar,{message:e.message,onRefresh:r}):n.jsx(rr,{onRefresh:r})}function or({status:e,onRetry:t}){return e==="retrying"?n.jsx("div",{"data-testid":"mini-agent-launch-retrying",className:"absolute inset-x-0 top-2 z-10 flex justify-center pointer-events-none",children:n.jsx("span",{className:"font-mono text-xs italic text-[var(--text-dim)] bg-black/40 px-2 py-1 rounded",children:"Launch slow — retrying…"})}):e==="awaiting-auth"?n.jsx("div",{"data-testid":"mini-agent-launch-awaiting-auth",className:"absolute inset-x-0 top-2 z-10 flex justify-center pointer-events-none",children:n.jsx("span",{className:"font-mono text-xs italic text-[var(--text-dim)] bg-black/40 px-2 py-1 rounded",children:"Sign in to Claude in the terminal to continue. (Opens a URL in your browser.)"})}):e==="failed"?n.jsx("div",{role:"alert","data-testid":"mini-agent-launch-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:"Couldn't launch the build agent — the shell prompt didn't respond in time."}),n.jsx("button",{type:"button",onClick:t,"data-testid":"mini-agent-launch-failed-retry",className:"px-2 py-1 rounded bg-white text-red-700 font-medium cursor-pointer hover:bg-red-50",children:"Retry"})]})}):null}const ir=40;function cr(e){const t=e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return t&&t.slice(0,ir).replace(/-+$/,"")||"session"}function Pe(e){window.dispatchEvent(new CustomEvent("terminal-send-input",{detail:e}))}const Q=50;function lr(e,t=Pe){return new Promise(r=>{t(e),setTimeout(()=>{t("\r"),r()},Q)})}const ce=3e3;function Be(e){return e==="gemini"?"gemini":"claude"}function dr(e,t){return`${Be(e)} '${t}'\r`}async function ur(e,t=Pe){const r=cr(e);await lr(`/rename ${r}`,t)}function fr(e,t,r){K("dispatch-rename",{phase:"queued",caller:t,label:e,delayMs:ce}),setTimeout(()=>{K("dispatch-rename",{phase:"fired",caller:t,label:e,delayMs:ce}),ur(e,r)},ce)}function pr(e,t){const r=Be(e),a=`mkdir -p .codeyam/tmp && cat > .codeyam/tmp/inline-prompt.md << 'INLINE_PROMPT_EOF'
|
|
4
|
+
${t}
|
|
5
|
+
INLINE_PROMPT_EOF\r`,s=`${r} "Read the file at '.codeyam/tmp/inline-prompt.md' for your instructions."\r`;return[a,s]}function hr({idleMs:e,ceilingMs:t}){return new Promise(r=>{let a=null,s=null,o=!1;function c(){o||(o=!0,a!==null&&clearTimeout(a),s!==null&&clearTimeout(s),window.removeEventListener("miniagent-output",f),r())}function i(){a!==null&&clearTimeout(a),a=setTimeout(c,e)}function f(){i()}window.addEventListener("miniagent-output",f),s=setTimeout(c,t),i()})}const mr=350,xr=4e3,br=8e3,gr=500,F={armed:"mini-agent-launch-armed",fired:"mini-agent-launch-fired",confirmed:"mini-agent-launch-confirmed",relaunch:"mini-agent-relaunch",authRequired:"mini-agent-auth-required",failed:"mini-agent-launch-failed"};function yr(e){const{provider:t,slashCommand:r,prompt:a,chatName:s,sendInput:o}=e,[c,i]=u.useState("idle"),f=u.useRef(o),h=u.useRef(r),g=u.useRef(a),m=u.useRef(s),l=u.useRef(t);u.useEffect(()=>{f.current=o},[o]),u.useEffect(()=>{h.current=r},[r]),u.useEffect(()=>{g.current=a},[a]),u.useEffect(()=>{m.current=s},[s]),u.useEffect(()=>{l.current=t},[t]);const p=u.useRef(0),x=u.useRef(!1),b=u.useRef(0),v=u.useRef(!1),d=u.useCallback((M,w)=>{const D=h.current,S=g.current;if(D){const N=dr(l.current,D),O=le(N);M(O),setTimeout(()=>{w()&&M("\r")},Q)}else{const[N,O]=pr(l.current,S??""),$=le(N),B=le(O);M($),setTimeout(()=>{w()&&(M("\r"),setTimeout(()=>{w()&&(M(B),setTimeout(()=>{w()&&M("\r")},Q))},gr))},Q)}},[]),y=u.useCallback(()=>{const M=++p.current,w=Date.now();b.current=w,v.current=!1,i("armed"),K(F.armed,{provider:l.current,slashCommand:h.current,chatName:m.current,hasPrompt:typeof g.current=="string"});function D(){return p.current===M}function S(N){D()&&(i(N===1?"firing":"retrying"),K(N===1?F.fired:F.relaunch,{provider:l.current,slashCommand:h.current,chatName:m.current,attempt:N,elapsedMs:Date.now()-w}),d(f.current,D),x.current||(x.current=!0,fr(m.current,"mini-agent-chat",O=>f.current(O))),setTimeout(()=>{D()&&(N===1?S(2):(i("failed"),K(F.failed,{provider:l.current,slashCommand:h.current,reason:"banner-timeout",elapsedMs:Date.now()-w})))},br))}hr({idleMs:mr,ceilingMs:xr}).then(()=>{D()&&S(1)})},[d]),C=u.useCallback(()=>{x.current=!1,y()},[y]),j=u.useCallback(()=>{y()},[y]),T=u.useCallback(()=>{if(p.current!==0){if(v.current){v.current=!1;const M=++p.current,w=()=>p.current===M;K(F.relaunch,{provider:l.current,slashCommand:h.current,reason:"post-auth",elapsedMs:Date.now()-b.current}),d(f.current,w),i("confirmed"),K(F.confirmed,{reason:"post-auth",elapsedMs:Date.now()-b.current});return}p.current++,i("confirmed"),K(F.confirmed,{elapsedMs:Date.now()-b.current})}},[d]),P=u.useCallback(()=>{p.current!==0&&(p.current++,v.current=!1,i("failed"),K(F.failed,{reason:"startup-failed",elapsedMs:Date.now()-b.current}))},[]),L=u.useCallback(()=>{p.current!==0&&(p.current++,v.current=!0,i("awaiting-auth"),K(F.authRequired,{provider:l.current,slashCommand:h.current,elapsedMs:Date.now()-b.current}))},[]);return u.useEffect(()=>()=>{p.current++},[]),{status:c,arm:C,retry:j,onBannerReady:T,onStartupFailed:P,onAuthRequired:L}}function le(e){return e.endsWith("\r")?e.slice(0,-1):e}const De=15;function vr({chatName:e,prompt:t,slashCommand:r,height:a=400,onClose:s}){const o=u.useRef(null),c=u.useRef(null),i=u.useRef(null);u.useRef(t);const{config:f}=Ae(),h=(f==null?void 0:f.provider)??"claude",[g,m]=u.useState({kind:"connecting"}),[l,p]=u.useState(0),x=u.useCallback(d=>{const y=c.current;(y==null?void 0:y.readyState)===WebSocket.OPEN&&y.send(JSON.stringify({type:"input",data:d}))},[]),b=yr({provider:h,slashCommand:r,prompt:t,chatName:e,sendInput:x}),v=u.useRef(b);return u.useEffect(()=>{v.current=b}),u.useEffect(()=>{const d=o.current;if(!d)return;const y=new It.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}),C=new Pt.FitAddon;y.loadAddon(C),y.open(d);const j=Ht(y,d,{onError:k=>console.warn("[MiniAgentChat]",k)}),T=qt(y,{sendInput:k=>{const E=c.current;(E==null?void 0:E.readyState)===WebSocket.OPEN&&E.send(JSON.stringify({type:"input",data:k}))}});requestAnimationFrame(()=>{try{C.fit()}catch{}}),i.current=y;const P={current:"inline"},L={current:null},M={current:!1},w={current:!1};let D=0,S=null;function N(){m({kind:"connecting"});const k=Bt({mode:P.current,sessionId:L.current??void 0}),E=new WebSocket(k);E.binaryType="arraybuffer",c.current=E,E.onopen=()=>{D=0,m({kind:"open"}),E.send(JSON.stringify({type:"resize",cols:y.cols,rows:y.rows}))},E.onmessage=A=>{if(A.data instanceof ArrayBuffer){y.write(new Uint8Array(A.data)),window.dispatchEvent(new CustomEvent("miniagent-output"));return}try{const I=JSON.parse(A.data);if(I.type==="error"){w.current=!0,m({kind:"server-error",message:Zt(I)});return}if(I.type==="session-id"){I.sessionId&&(L.current=I.sessionId,P.current="resume"),M.current||(M.current=!0,v.current.arm());return}if(I.type==="agent-banner-ready"){v.current.onBannerReady();return}if(I.type==="agent-auth-required"){v.current.onAuthRequired();return}if(I.type==="startup-failed"){v.current.onStartupFailed();return}}catch{y.write(A.data),window.dispatchEvent(new CustomEvent("miniagent-output"))}},E.onerror=()=>{},E.onclose=async()=>{if(w.current){m(I=>I.kind==="server-error"?I:{kind:"ended"});return}const A=await Ie();if(!w.current){if(!A){m({kind:"server-stopped"}),S==null||S(),S=Gt(2e3,()=>{w.current||window.location.reload()});return}if(D<De){const I=D<4?1e3*Math.pow(2,D):1e4;D++,m({kind:"reconnecting",attempt:D,maxAttempts:De}),setTimeout(()=>{w.current||N()},I)}else m({kind:"failed"})}}}N(),y.onData(k=>{const E=c.current;(E==null?void 0:E.readyState)===WebSocket.OPEN?E.send(JSON.stringify({type:"input",data:k})):p(A=>A+1)});const O=new ResizeObserver(()=>{try{C.fit();const k=c.current;(k==null?void 0:k.readyState)===WebSocket.OPEN&&k.send(JSON.stringify({type:"resize",cols:y.cols,rows:y.rows}))}catch{}});O.observe(d);function $(){var k;(k=i.current)==null||k.focus()}window.addEventListener("terminal-focus",$);function B(k){const E=k.detail,A=c.current;typeof E=="string"&&(A==null?void 0:A.readyState)===WebSocket.OPEN&&A.send(JSON.stringify({type:"input",data:E}))}return window.addEventListener("miniagent-send-input",B),()=>{var E;w.current=!0,S==null||S(),S=null,window.removeEventListener("terminal-focus",$),window.removeEventListener("miniagent-send-input",B),O.disconnect(),j(),T();const k=c.current;(k==null?void 0:k.readyState)===WebSocket.OPEN&&k.close(),(E=i.current)==null||E.dispose()}},[h]),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:Oe(h)}),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.jsxs("div",{ref:o,onClick:()=>{var d;return(d=i.current)==null?void 0:d.focus()},style:{height:a,background:"#1a1a1a",padding:"6px 10px",position:"relative",overflow:"hidden"},children:[n.jsx(sr,{status:g,pulseKey:l,onRefresh:()=>window.location.reload()}),n.jsx(or,{status:b.status,onRetry:b.retry})]})]})}function wr(){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 jr({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 Sr({variant:e,providerLabel:t,chatOpen:r,onToggleChat:a}){const s=e==="inline",o=s?"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",c=r?"border-[var(--accent-active)] bg-[var(--accent-active)]/15 text-[var(--accent-active)]":s?"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:a,className:`${o} ${c}`,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 he=new Set,me=new Set;let Ke={isActive:!1,previewSlug:null};function kr(){for(const e of he)e()}function Dn(e){return he.add(e),()=>{he.delete(e)}}function Mn(e){Ke=e;for(const t of me)t(e)}function Cr(e){return me.add(e),()=>{me.delete(e)}}function Me(){return Ke}function Nr(){const[e,t]=u.useState(()=>Me());return u.useEffect(()=>(t(Me()),Cr(t)),[]),e}function Er({panelSlug:e,scenarioState:t}){const r=Nr(),{isActive:a,previewSlug:s}=t??r;return s!==e?null:n.jsxs("button",{type:"button","aria-pressed":a,onClick:()=>kr(),title:a?"Exit inspect data source":"Inspect data source — click a value in the live preview to see its mock",className:a?"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"})]}),a?"Inspecting…":"Inspect data"]})}function Tr({variant:e,slug:t}){const r=()=>window.open(ze(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 Dr(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 Mr({diff:e,saving:t,cancelling:r,error:a,onSave:s,onCancel:o}){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:Dr(e)}),n.jsxs("div",{className:"flex items-center gap-2",children:[a&&n.jsx("span",{className:"text-xs text-red-400",children:a}),n.jsx("button",{type:"button",onClick:o,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:s,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 Rr({title:e,slug:t,provider:r,chatOpen:a,onToggleChat:s,variant:o,onClose:c,draftDirty:i,draftDiff:f,draftSaving:h,draftCancelling:g,draftError:m,onSave:l,onCancel:p}){const x=Oe(r),b=!!i&&!!l&&!!p;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(Sr,{variant:o,providerLabel:x,chatOpen:a,onToggleChat:s}),n.jsx(Er,{panelSlug:t}),n.jsx(Tr,{variant:o,slug:t}),c&&n.jsx(jr,{variant:o,onClose:c})]})]}),b&&l&&p&&n.jsx(Mr,{diff:f??null,saving:h??!1,cancelling:g??!1,error:m??null,onSave:l,onCancel:p})]})}function Or(e,t){const[r,a]=u.useState(e.status??200),[s,o]=u.useState(e.body??null),[c,i]=u.useState(()=>Object.entries(e.headers??{}).map(([m,l])=>({name:m,value:l})));u.useEffect(()=>{a(e.status??200),o(e.body??null),i(Object.entries(e.headers??{}).map(([m,l])=>({name:m,value:l})))},[t,e.status,e.body,e.headers]);const f=u.useMemo(()=>e.headers??{},[e.headers]),h=u.useMemo(()=>{if((e.status??200)!==r||JSON.stringify(e.body??null)!==JSON.stringify(s))return!0;const m={};for(const b of c)b.name.trim()&&(m[b.name.trim()]=b.value);const l=f,p=Object.keys(l),x=Object.keys(m);if(p.length!==x.length)return!0;for(const b of x)if(l[b]!==m[b])return!0;return!1},[r,s,c,e.status,e.body,f]);return{status:r,setStatus:a,body:s,setBody:o,headers:c,setHeaders:i,isDirty:h,buildPayload:()=>{const m={};for(const l of c)l.name.trim()&&(m[l.name.trim()]=l.value);return{status:r,body:s,headers:m}}}}const Ar=e=>navigator.clipboard.writeText(e);function $r(e={}){const{writer:t=Ar,resetMs:r=2e3}=e,[a,s]=u.useState(!1),o=u.useRef(null),c=u.useCallback(async i=>{await t(i),s(!0),o.current!==null&&clearTimeout(o.current),o.current=setTimeout(()=>{s(!1),o.current=null},r)},[t,r]);return{copied:a,copy:c}}function Lr({body:e,onBodyChange:t}){const{copied:r,copy:a}=$r();async function s(){try{const c=await navigator.clipboard.readText(),i=JSON.parse(c);t(i)}catch{}}function o(){a(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 s(),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: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:r?"Copied":"Copy"})]})}function W(e){return JSON.stringify(e)}function Fe(e,t){return e?e instanceof Set?e.has(t):e.includes(t):!1}function Ir(e){const t=new Set;function r(a,s){if(a!==null&&typeof a=="object")if(t.add(W(s)),Array.isArray(a))a.forEach((o,c)=>r(o,[...s,c]));else for(const[o,c]of Object.entries(a))r(c,[...s,o])}return r(e,[]),t}function Pr(e){return e===null?"text-slate-400 italic":typeof e=="string"?"text-emerald-300":typeof e=="number"?"text-amber-300":typeof e=="boolean"?"text-[#D7FF63]":"text-[var(--text-primary)]"}function Br(e){return e===null?"null":typeof e=="string"?`"${e}"`:String(e)}function Kr(e){return e===null?"null":typeof e=="string"?e:String(e)}function Fr(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 ee(e){return JSON.parse(JSON.stringify(e))}function _r(e,t,r){if(t.length===0)return r;const a=ee(e);let s=a;for(let o=0;o<t.length-1;o++)s=s[t[o]];return s[t[t.length-1]]=r,a}function be(e,t){if(t.length===0)return e;const r=ee(e);let a=r;for(let o=0;o<t.length-1;o++)a=a[t[o]];const s=t[t.length-1];return Array.isArray(a)?a.splice(s,1):delete a[s],r}function Hr(e,t){const r=ee(e);let a=r;for(const s of t)a=a[s];return Array.isArray(a)&&a.push(null),r}function Yr(e,t,r){const a=ee(e);let s=a;for(const o of t)s=s[o];return s&&typeof s=="object"&&!Array.isArray(s)&&(s[r]=""),a}function Vr(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 a=e[r];if(a==="."){r+=1;const s=r;for(;r<e.length&&e[r]!=="."&&e[r]!=="[";)r+=1;const o=e.slice(s,r);if(o.length===0)return null;t.push(o)}else if(a==="["){const s=e.indexOf("]",r);if(s===-1)return null;const o=e.slice(r+1,s);if(o.length===0)return null;const c=Number(o);if(!Number.isInteger(c)||c<0)return null;t.push(c),r=s+1}else return null}return t}function Xr(e,t){u.useEffect(()=>{if(!e)return;const r=Vr(e);r&&t(a=>{const s=new Set(a);for(let o=0;o<r.length;o++)s.add(W(r.slice(0,o)));return s})},[e,t])}function ge({collapsible:e,isOpen:t,onToggle:r,parentKey:a,readOnly:s,onRemove:o,children:c}){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"}),a!==null&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-cyan-300",children:typeof a=="number"?`[${a}]`:a}),n.jsx("span",{className:"text-[var(--text-dim)]",children:":"})]}),n.jsx("div",{className:"flex-1 min-w-0 flex items-center gap-1",children:c}),!s&&o&&n.jsx("button",{type:"button",onClick:o,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 Ur(e){const{value:t,path:r,parentKey:a,expanded:s,onToggle:o,readOnly:c}=e,i=W(r),f=Fe(s,i),h=t.length>0;return n.jsxs("div",{children:[n.jsxs(ge,{collapsible:h,isOpen:f,onToggle:()=>o(i),parentKey:a,readOnly:c,onRemove:r.length>0?()=>e.onValueChange(be(e.rootValue,r)):null,children:[n.jsx("span",{className:"text-[var(--text-dim)]",children:"["}),!f&&n.jsxs(n.Fragment,{children:[h&&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:"]"})]})]}),f&&n.jsxs("div",{className:"ml-4 border-l border-[var(--border-subtle)] pl-2",children:[t.map((g,m)=>u.createElement(ye,{...e,key:m,value:g,path:[...r,m],parentKey:m,isLast:m===t.length-1})),!c&&n.jsx("button",{type:"button",onClick:()=>e.onValueChange(Hr(e.rootValue,r)),className:"text-[10px] text-[var(--accent-blue)] hover:underline bg-transparent border-none cursor-pointer py-0.5",children:"+ Add item"})]}),f&&n.jsx("div",{className:"text-[var(--text-dim)]",children:"]"})]})}function zr({onSave:e,onCancel:t}){const[r,a]=u.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:s=>a(s.target.value),onBlur:()=>e(r),onKeyDown:s=>{s.key==="Enter"?(s.preventDefault(),e(r)):s.key==="Escape"&&(s.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 Wr(e){const{value:t,path:r,parentKey:a,expanded:s,onToggle:o,readOnly:c,addingKeyAtPath:i,onStartAddKey:f,onStopAddKey:h}=e,g=W(r),m=Fe(s,g),l=Object.entries(t),p=l.length>0,x=i===g;return n.jsxs("div",{children:[n.jsxs(ge,{collapsible:p,isOpen:m,onToggle:()=>o(g),parentKey:a,readOnly:c,onRemove:r.length>0?()=>e.onValueChange(be(e.rootValue,r)):null,children:[n.jsx("span",{className:"text-[var(--text-dim)]",children:"{"}),!m&&n.jsxs(n.Fragment,{children:[p&&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:"}"})]})]}),m&&n.jsxs("div",{className:"ml-4 border-l border-[var(--border-subtle)] pl-2",children:[l.map(([b,v],d)=>u.createElement(ye,{...e,key:b,value:v,path:[...r,b],parentKey:b,isLast:d===l.length-1})),!c&&!x&&n.jsx("button",{type:"button",onClick:()=>f(g),className:"text-[10px] text-[var(--accent-blue)] hover:underline bg-transparent border-none cursor-pointer py-0.5",children:"+ Add key"}),!c&&x&&n.jsx(zr,{onSave:b=>{b.trim()&&e.onValueChange(Yr(e.rootValue,r,b.trim())),h()},onCancel:h})]}),m&&n.jsx("div",{className:"text-[var(--text-dim)]",children:"}"})]})}function Jr({initial:e,onSave:t,onCancel:r}){const[a,s]=u.useState(e);return n.jsx("input",{autoFocus:!0,value:a,onChange:o=>s(o.target.value),onBlur:()=>t(a),onKeyDown:o=>{o.key==="Enter"?(o.preventDefault(),t(a)):o.key==="Escape"&&(o.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 qr(e){const{value:t,path:r,parentKey:a,readOnly:s,editingPath:o,onStartEdit:c,onStopEdit:i}=e,f=W(r),h=o===f;return n.jsx(ge,{collapsible:!1,isOpen:!1,parentKey:a,readOnly:s,onToggle:()=>{},onRemove:r.length>0?()=>e.onValueChange(be(e.rootValue,r)):null,children:h?n.jsx(Jr,{initial:Kr(t),onSave:g=>{const m=Fr(g);e.onValueChange(_r(e.rootValue,r,m)),i()},onCancel:i}):n.jsx("button",{type:"button",onClick:s?void 0:()=>c(f),disabled:s,className:`${s?"":"hover:bg-[var(--bg-card)] cursor-pointer"} bg-transparent border-none px-1 py-0 rounded ${Pr(t)} text-left font-mono`,title:s?void 0:"Click to edit",children:Br(t)})})}function ye(e){const{value:t}=e;return Array.isArray(t)?n.jsx(Ur,{...e,value:t}):t!==null&&typeof t=="object"?n.jsx(Wr,{...e,value:t}):n.jsx(qr,{...e})}function ve({value:e,onChange:t,readOnly:r=!1,focusJsonPath:a}){const[s,o]=u.useState(()=>Ir(e)),[c,i]=u.useState(null),[f,h]=u.useState(null);Xr(a,o);function g(m){o(l=>{const p=new Set(l);return p.has(m)?p.delete(m):p.add(m),p})}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(ye,{value:e,path:[],parentKey:null,isLast:!0,readOnly:r,expanded:s,editingPath:c,addingKeyAtPath:f,onToggle:g,onStartEdit:i,onStopEdit:()=>i(null),onStartAddKey:h,onStopAddKey:()=>h(null),onValueChange:t,rootValue:e})})})}function Gr({headers:e,onChange:t}){function r(o,c){t(e.map((i,f)=>f===o?{...i,...c}:i))}function a(){t([...e,{name:"",value:""}])}function s(o){t(e.filter((c,i)=>i!==o))}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:a,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((o,c)=>n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{value:o.name,onChange:i=>r(c,{name:i.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:o.value,onChange:i=>r(c,{value:i.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:()=>s(c),className:"px-2 text-xs text-[var(--text-dim)] hover:text-red-400 bg-transparent border-none cursor-pointer",children:"×"})]},c))]})}const de=5;function Qr(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",a=e.slice(0,de).join(", "),s=e.length>de?`, +${e.length-de} more`:"";return`Affects ${e.length} ${r}: ${a}${s}`}function Zr(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 en(e,t){if(e.source==="default"){const r=t.findIndex(a=>a.scope.kind==="default");if(r>=0)return r}if(e.source==="shared"){const r=t.findIndex(a=>a.scope.kind==="shared"&&a.scope.slug===(e.sharedSlug??""));if(r>=0)return r}return 0}function tn(e,t,r){const[a,s]=u.useState({}),o=r.map(c=>H(c.scope)).join("|");return u.useEffect(()=>{let c=!1;return(async()=>{const f={};for(const h of r)f[H(h.scope)]="loading";s(f);for(const h of r)try{const g=await nt(e,t,h.scope);if(c)return;s(m=>({...m,[H(h.scope)]:g}))}catch{if(c)return;s(g=>({...g,[H(h.scope)]:[]}))}})(),()=>{c=!0}},[e,t,o]),a}function rn({choice:e,selected:t,impactLabel:r,onSelect:a}){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:a}),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 nn({entry:e,scenarioSlug:t,routeKey:r,onCancel:a,onConfirm:s}){const o=Zr(e),[c,i]=u.useState(()=>en(e,o)),f=tn(t,r,o),[h,g]=u.useState(!1),[m,l]=u.useState(null),p=async()=>{const x=o[c];if(x){g(!0),l(null);try{await s(x.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:o.map((x,b)=>n.jsx(rn,{choice:x,selected:c===b,impactLabel:Qr(f[H(x.scope)],x.scope),onSelect:()=>i(b)},H(x.scope)))}),m&&n.jsx("p",{className:"mt-3 text-xs text-red-400",role:"alert",children:m}),n.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:a,disabled:h,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 p(),disabled:h,className:"rounded bg-violet-500 px-3 py-1.5 text-xs font-medium text-white hover:bg-violet-400 disabled:opacity-50",children:h?"Saving…":"Save"})]})]})})}function an({entry:e,routeKey:t,scenarioSlug:r,onSave:a,focusJsonPath:s}){const o=Or(e,t),[c,i]=u.useState(null),[f,h]=u.useState(!1),[g,m]=u.useState(!1);u.useEffect(()=>{i(null),m(!1)},[t]);const l=async x=>{h(!0),i(null);try{const b=o.buildPayload();await a({routeKey:t,...b,scope:x})}catch(b){throw i(b instanceof Error?b.message:"Save failed"),b}finally{h(!1)}},p=async()=>{if(o.isDirty){if(e.source==="scenario"){try{await l({kind:"scenario"})}catch{}return}m(!0)}};return n.jsxs("div",{className:"flex flex-col gap-3 h-full min-h-0",children:[c&&n.jsx("p",{className:"text-xs text-red-400",children:c}),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:o.status,onChange:x=>o.setStatus(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"}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{type:"button",onClick:()=>void p(),disabled:!o.isDirty||f,className:"rounded bg-violet-500 px-3 py-1 text-xs font-medium text-white hover:bg-violet-400 disabled:opacity-50",children:f?"Saving…":o.isDirty?"Save changes":"Saved"})]}),n.jsx(Gr,{headers:o.headers,onChange:o.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(Lr,{body:o.body,onBodyChange:o.setBody})]}),n.jsx(ve,{value:o.body,onChange:o.setBody,focusJsonPath:s},t)]}),g&&n.jsx(nn,{entry:e,scenarioSlug:r,routeKey:t,onCancel:()=>m(!1),onConfirm:async x=>{await l(x),m(!1)}})]})}function sn(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 a=Math.floor(r/60);return a<60?`${a}m ago`:`${Math.floor(a/60)}h ago`}const Re={GET:"text-emerald-400 border-emerald-400/40",POST:"text-[#D7FF63] border-[#D7FF63]/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 on(e){return Re[e]??Re.GET}function cn({entry:e,scenarioHasDefaultFallback:t,onSave:r,onRemove:a,onPassthrough:s}){const o=`${e.method} ${e.pathPattern}`,c=on(e.method),i=e.status??e.lastObservedStatus,f=u.useMemo(()=>e.lastObservedMs?sn(e.lastObservedMs,Date.now()):null,[e.lastObservedMs]),h="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 ${c}`,children:e.method}),n.jsx("span",{className:"font-mono text-sm text-[var(--text-primary)] break-all",children:e.pathPattern}),n.jsx(Le,{source:e.source}),i!==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:i}),e.observedCount>0&&n.jsxs("span",{className:"ml-auto text-xs text-[var(--text-dim)]",children:[e.observedCount,"× ",f?`· ${f}`:""]})]}),e.variants.length>1&&n.jsxs("div",{className:"text-[10px] text-[var(--text-dim)] font-mono",children:["variants: ",e.variants.filter(g=>g!==o).join(", ")]}),n.jsxs("div",{className:"flex flex-wrap gap-2 pt-1",children:[e.source==="scenario"&&t&&n.jsx("button",{onClick:()=>void a(o),className:h,title:"Remove this scenario mock and fall back to the default",children:"Revert to default"}),e.source==="scenario"&&n.jsx("button",{onClick:()=>void s(o),className:h,children:"Mark passthrough"}),e.source==="default"&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>void r({routeKey:o,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 s(o),className:h,children:"Mark passthrough"})]}),e.source==="passthrough"&&n.jsx("button",{onClick:()=>void a(o),className:h,children:"Undo passthrough"})]})]})}function ln({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(([a,s])=>n.jsxs("div",{className:"flex gap-2",children:[n.jsxs("dt",{className:"text-[var(--text-muted)]",children:[a,":"]}),n.jsx("dd",{className:"text-[var(--text-primary)] break-all",children:s})]},a))})]}),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(ve,{value:e.body,onChange:()=>{},readOnly:!0},`${e.method} ${e.pathPattern}`)]})]})}function dn({entry:e,scenarioSlug:t,scenarioHasDefaultFallback:r,onSave:a,onRemove:s,onPassthrough:o,focusJsonPath:c}){const i=`${e.method} ${e.pathPattern}`,f=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(cn,{entry:e,scenarioHasDefaultFallback:r,onSave:a,onRemove:s,onPassthrough:o}),n.jsx("div",{className:"flex-1 min-h-0 overflow-auto p-4",children:f?n.jsx(an,{entry:e,routeKey:i,scenarioSlug:t,onSave:a,focusJsonPath:c}):n.jsx(ln,{entry:e})})]})}function un({slug:e,tab:t,initialRows:r,onCellEdited:a}){const[s,o]=u.useState(r),[c,i]=u.useState(null),[f,h]=u.useState(""),[g,m]=u.useState(""),l=u.useRef(null);u.useEffect(()=>{o(r),i(null)},[t.dataKey,r]);function p(y,C){const j=s[y];i({row:y,col:C});const T=j[C]===null?"":typeof j[C]=="object"?JSON.stringify(j[C]):String(j[C]);h(T),m(T)}function x(y){if(h(y),l.current&&clearTimeout(l.current),!c)return;const C=c;l.current=setTimeout(()=>{d(C.row,C.col,y)},600)}function b(){c&&(l.current&&clearTimeout(l.current),d(c.row,c.col,f),i(null))}function v(){if(l.current&&clearTimeout(l.current),!!c){if(f!==g){const y=[...s];y[c.row]={...y[c.row],[c.col]:ke(g)},o(y),fetch(`/api/scenarios/${encodeURIComponent(e)}/data`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({table:t.dataKey,rowIndex:c.row,column:c.col,value:g})}).then(()=>{U(),a&&a()}).catch(()=>{})}i(null)}}async function d(y,C,j){const T=[...s];T[y]={...T[y],[C]:ke(j)},o(T);try{await fetch(`/api/scenarios/${encodeURIComponent(e)}/data`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({table:t.dataKey,rowIndex:y,column:C,value:j})}),U(),a&&a()}catch{}}return{rows:s,editingCell:c,editValue:f,handleEditCell:p,handleEditValueChange:x,handleSave:b,handleCancelEdit:v}}function fn({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-[#D7FF63]/80 bg-[#D7FF63]/10 border-[#D7FF63]/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 pn({editingCell:e,editValue:t,onEditValueChange:r,onSave:a,onCancel:s}){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:o=>r(o.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:o=>{o.key==="Escape"&&s(),o.key==="Enter"&&(o.metaKey||o.ctrlKey)&&a()}}),n.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[n.jsx("button",{onClick:a,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:s,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 hn({columns:e,colTypes:t,pkCol:r,rows:a,onEditCell:s}){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(o=>n.jsx(mn,{name:o,type:t[o],isPk:o===r},o))]})}),n.jsx("tbody",{children:a.map((o,c)=>n.jsx(xn,{row:o,rowIndex:c,columns:e,pkCol:r,onEditCell:s},c))})]})})}function mn({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 xn({row:e,rowIndex:t,columns:r,pkCol:a,onEditCell:s}){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(o=>n.jsx(bn,{value:e[o],isPk:o===a,onEdit:()=>s(t,o)},o))]})}function bn({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:a=>{a.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 gn({slug:e,tab:t,initialRows:r,onCellEdited:a}){const{rows:s,editingCell:o,editValue:c,handleEditCell:i,handleEditValueChange:f,handleSave:h,handleCancelEdit:g}=un({slug:e,tab:t,initialRows:r,onCellEdited:a}),m=lt(s,t.schemaFields),l=dt(m,s,t.schemaFields),p=ut(m,t.schemaFields);return n.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[n.jsx(fn,{tab:t}),n.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:n.jsx(hn,{columns:m,colTypes:l,pkCol:p,rows:s,onEditCell:i})}),o&&n.jsx(pn,{editingCell:o,editValue:c,onEditValueChange:f,onSave:h,onCancel:g})]})}function yn({slug:e,browserState:t,tab:r,onCellEdited:a}){const s=u.useMemo(()=>{if(!t)return{};switch(r){case"cookies":return t.cookies??{};case"localStorage":return t.localStorage??{};case"sessionStorage":return t.sessionStorage??{};case"headers":return t.requestHeaders??{};default:return{}}},[t,r]),o=u.useCallback(async f=>{const h=r==="headers"?"browserState.requestHeaders":`browserState.${r}`;try{await fetch(`/api/scenarios/${encodeURIComponent(e)}/data`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:h,value:JSON.stringify(f)})}),U(),a&&a()}catch{}},[e,r,a]),c=u.useMemo(()=>{switch(r){case"cookies":return"Cookies";case"localStorage":return"Local Storage";case"sessionStorage":return"Session Storage";case"headers":return"Request Headers"}},[r]),i=u.useMemo(()=>{switch(r){case"cookies":return"Cookies injected via Set-Cookie headers on the scenario's initial response.";case"localStorage":return"localStorage items set before the app's JavaScript executes.";case"sessionStorage":return"sessionStorage items set before the app's JavaScript executes.";case"headers":return"Custom headers added to every outbound HTTP request from the iframe."}},[r]);return{value:s,handleChange:o,label:c,description:i}}function vn({slug:e,browserState:t,tab:r,onCellEdited:a}){const{value:s,handleChange:o,label:c,description:i}=yn({slug:e,browserState:t,tab:r,onCellEdited:a});return n.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[n.jsxs("div",{className:"px-4 py-3 border-b border-[var(--border-subtle)]",children:[n.jsx("h2",{className:"text-sm font-semibold text-[var(--text-primary)]",children:c}),n.jsx("p",{className:"text-xs text-[var(--text-dim)] mt-1",children:i})]}),n.jsx("div",{className:"flex-1 min-h-0 p-4 overflow-auto",children:n.jsx(ve,{value:s,onChange:o})})]})}function ue({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 wn({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(ue,{label:"This Page",active:t.kind==="this-page",onClick:()=>r({kind:"this-page"})}),e.map(a=>n.jsx(ue,{label:a,active:t.kind==="share"&&t.slug===a,onClick:()=>r({kind:"share",slug:a})},a)),n.jsx(ue,{label:"Defaults",active:t.kind==="defaults",onClick:()=>r({kind:"defaults"})})]})}function Rn({slug:e,scenarioName:t,initialSection:r,onClose:a,variant:s="slideOver"}){const{data:o,tableTabs:c,scenarioOwnedDataKeys:i,shares:f,browserState:h,loading:g,error:m}=gt(e),{entries:l,loading:p,error:x,upsertScoped:b,remove:v,setPassthrough:d}=st(e),{config:y}=Ae(),C=(y==null?void 0:y.provider)??"claude",j=jt({slug:e,onPreviewReload:U}),T=u.useCallback(()=>{j.markDirty(),U()},[j]),P=u.useCallback(async R=>{await b(R),T()},[b,T]),L=u.useCallback(async R=>{await v(R),T()},[v,T]),M=u.useCallback(async R=>{await d(R),T()},[d,T]),w=u.useCallback(()=>{j.markDirty(),U()},[j]),D=u.useCallback(()=>{a&&j.confirmIfDirty("Discard unsaved changes to this scenario?")&&a()},[a,j]),[S,N]=u.useState(null),[O,$]=u.useState(null),[B,k]=u.useState(!1),E=u.useCallback(R=>N({kind:"mock",routeKey:R}),[]);Ge({onSelect:E,onFocus:$});const[A,I]=u.useState({kind:"this-page"}),te=g||p,Y=u.useMemo(()=>s==="inline"?c.filter(R=>i.has(R.dataKey)):c,[s,c,i]),V=u.useMemo(()=>{if(s!=="inline")return l;switch(A.kind){case"this-page":return l.filter(R=>R.consumedThisPageLoad);case"defaults":return l.filter(R=>R.source==="default");case"share":return l.filter(R=>R.source==="shared"&&R.sharedSlug===A.slug)}},[s,l,A]);Lt({seedTabs:Y,mockEntries:V,initialSection:r,selection:S,setSelection:N});const _e=u.useMemo(()=>{const R=new Set;for(const we of l)we.source==="default"&&R.add(z(we));return R},[l]),_=(S==null?void 0:S.kind)==="seed"?Y.find(R=>R.dataKey===S.dataKey)??null:null,X=(S==null?void 0:S.kind)==="mock"?V.find(R=>z(R)===S.routeKey)??null:null,re=_&&o?o[_.dataKey]??[]:[],He=u.useMemo(()=>We({slug:e,scenarioName:t,seedTabs:Y,mockEntries:V,selectedMock:X,selectedSeedTab:_,selectedSeedRows:re}),[e,t,Y,V,X,_,re]),Ye=t??e,ne=Y.length>0||V.length>0,ae=n.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[n.jsx(Rr,{title:Ye,slug:e,provider:C,chatOpen:B,onToggleChat:()=>k(R=>!R),variant:s,onClose:a?D: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()}),s==="inline"&&n.jsx(wn,{shares:f,activeBadge:A,onSelect:I}),B&&n.jsx("div",{className:"flex-shrink-0 border-b border-[var(--border-subtle)] bg-[var(--bg-deep)]",children:n.jsx(vr,{chatName:`edit-data-${e}`,prompt:He,height:360,onClose:()=>k(!1)})}),n.jsxs("div",{className:"flex flex-1 min-h-0",children:[n.jsx(At,{seedTabs:Y,mockEntries:V,selection:S,onSelect:N}),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:[m&&n.jsxs("p",{className:"p-4 text-xs text-red-400",children:["Seed error: ",m]}),x&&n.jsxs("p",{className:"p-4 text-xs text-red-400",children:["Mocks error: ",x]}),!te&&!ne&&n.jsx(wr,{}),_&&n.jsx(gn,{slug:e,tab:_,initialRows:re,onCellEdited:w}),X&&n.jsx(dn,{entry:X,scenarioSlug:e,scenarioHasDefaultFallback:_e.has(z(X)),onSave:P,onRemove:L,onPassthrough:M,focusJsonPath:O}),(S==null?void 0:S.kind)==="browser"&&n.jsx(vn,{slug:e,browserState:h,tab:S.tab,onCellEdited:w}),!_&&!X&&(S==null?void 0:S.kind)!=="browser"&&ne&&!te&&n.jsx("p",{className:"p-4 text-xs text-[var(--text-dim)] italic",children:"Select a data source from the left to view it."}),te&&!ne&&n.jsx("p",{className:"p-4 text-xs text-[var(--text-dim)]",children:"Loading scenario data…"})]})})]})]});return s==="fullPage"?n.jsx("div",{className:"fixed inset-0 bg-[var(--bg-deep)] text-[var(--text-primary)]",children:ae}):s==="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:ae}):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-40 bg-black/40",onClick:D,"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:ae})]})}export{ce as $,wn as A,ue as B,Tr as C,cn as D,dn as E,Er as F,Rr as G,wr as H,Sr as I,qr as J,jr as K,hn as L,Gr as M,pn as N,fn as O,Tt as P,Et as Q,rr as R,Rn as S,nr as T,tr as U,er as V,sr as W,Ae as X,Oe as Y,Pe as Z,ur as _,Le as a,It as a0,Pt as a1,Ht as a2,qt as a3,Bt as a4,Zt as a5,Ie as a6,Gt as a7,$r as a8,Q as a9,Kt as aa,at as ab,En as ac,Mn as ad,Dn as ae,Tn as af,Qe as ag,gn as b,an as c,ln as d,U as e,sn as f,gt as g,st as h,or as i,vr as j,Jr as k,Wr as l,ge as m,ye as n,ve as o,ke as p,Ur as q,zr as r,Lr as s,Mr as t,jt as u,Dt as v,Rt as w,nn as x,rn as y,At as z};
|
|
@@ -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-zJSXtXL4.js";import"./useEvents-DggWrtHe.js";import"./xterm--24IGk-x.js";import"./index-BUYNFqKK.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 Y,S as X,f as Ze,T as Z,e as et,N as I,b as tt,a as ee,r as at,d as te,R as H,p as st,g as ae,P as rt,h as nt,I as ot,i as it,j as ct,k as lt,l as dt,m as ut,n as xt,o as pt,q as mt,s as ht,t as bt,u as ft,v as vt,w as gt,x as yt,y as jt,z as St,E as Nt,A as Ct,B as wt,D as Pt,F as kt,G as Et,H as Rt,J as Dt,K as Tt,L as Bt,M as Mt,O as Ft,Q as Ot,U as Lt,V as It,W as At,X as Ht,Y as $t,Z as Vt,_ as _t,$ as Kt,a0 as Jt,a1 as Gt,a2 as zt,a3 as Wt,a4 as Qt,a5 as Ut,a6 as qt,a7 as Yt,a8 as Xt,a9 as Zt,aa as ea,ab as ta,ac as aa,ad as sa,ae as ra,af as na,ag as oa,ah as ia,ai as ca,aj as la,ak as da,al as ua,am as xa,an as pa,ao as ma,ap as ha,aq as ba,ar as fa,as as va,at as ga,au as ya,av as ja,aw as Sa,ax as Na,ay as Ca,az as wa,aA as Pa,aB as ka,aC as Ea,aD as Ra,aE as Da,aF as Ta,aG as Ba,aH as Ma,aI as Fa,aJ as Oa,aK as La,aL as Ia,aM as Aa,aN as Ha,aO as $a,aP as Va,aQ as _a,aR as Ka,aS as Ja,aT as Ga,aU as za,aV as Wa,aW as Qa,aX as Ua,aY as qa,aZ as Ya,a_ as Xa,a$ as Za,b0 as es,b1 as ts,b2 as as,b3 as ss,b4 as rs,b5 as ns,b6 as os,b7 as is,b8 as cs,b9 as ls,ba as ds,bb as us,bc as xs,bd as ps,be as ms,bf as hs,bg as bs,bh as fs,bi as vs,bj as gs,bk as ys,bl as js,bm as Ss,bn as Ns,bo as Cs,bp as ws,bq as Ps,br as ks,bs as Es,bt as Rs,bu as Ds,bv as Ts,bw as Bs,bx as Ms,by as Fs,bz as Os,bA as Ls,bB as Is,bC as As,bD as Hs,bE as $s,bF as Vs,bG as _s,bH as Ks,bI as Js,bJ as Gs,bK as zs,bL as Ws,bM as Qs,bN as Us,bO as qs,bP as Ys,bQ as Xs,bR as Zs,bS as er,bT as tr,bU as ar,bV as sr,bW as rr,bX as nr,bY as or,bZ as ir,b_ as cr,b$ as lr,c0 as dr,c1 as ur,c2 as xr,c3 as pr,c4 as mr,c5 as hr,c6 as br,c7 as fr,c8 as vr,c9 as gr,ca as yr,cb as jr,cc as Sr,cd as Nr,ce as Cr,cf as wr,cg as Pr,ch as kr,ci as Er,cj as Rr,ck as Dr,cl as Tr,cm as Br,cn as Mr,co as Fr,cp as Or,cq as Lr,cr as Ir,cs as Ar,ct as Hr,cu as $r,cv as Vr,cw as G,cx as _r,cy as Kr,cz as Jr,cA as Gr,cB as zr,cC as Wr,cD as Qr,cE as Ur,cF as qr,cG as Yr,cH as Xr,cI as Zr,cJ as en,cK as tn,cL as an,cM as sn,cN as rn,cO as nn,cP as on,cQ as cn,cR as ln,cS as dn,cT as un,cU as xn,cV as pn,cW as mn,cX as hn,cY as bn,cZ as fn,c_ as vn,c$ as gn,d0 as yn,d1 as jn,d2 as Sn,d3 as Nn,d4 as Cn,d5 as wn,d6 as Pn,d7 as kn,d8 as En,d9 as Rn,da as Dn,db as Tn,dc as Bn,dd as Mn,de as Fn,df as On,dg as Ln,dh as In,di as An,dj as Hn,dk as $n,dl as Vn,dm as _n,dn as Kn,dp as Jn,dq as Gn,dr as zn,ds as Wn,dt as Qn,du as Un,dv as qn,dw as Yn,dx as Xn,dy as Zn,dz as eo,dA as to,dB as ao,dC as so,dD as ro,dE as no,dF as oo,dG as io,dH as co,dI as lo,dJ as uo,dK as xo,dL as po,dM as mo,dN as ho,dO as bo,dP as fo,dQ as vo,dR as go,dS as yo,dT as jo,dU as So,dV as No,dW as Co,dX as wo,dY as Po,dZ as ko,d_ as Eo,d$ as Ro,e0 as Do,e1 as To,e2 as Bo}from"./EditorShell-DWaeBxgj.js";import{S as Mo,a as Fo,b as Oo,c as Lo}from"./StepsSimulator-CRtmlyNZ.js";import{M as se}from"./Markdown-BHBqz-Mj.js";import{S as Io,B as D,M as k,a as L,t as w,I as Ao,b as Ho,c as $o,d as Vo,e as _o,f as Ko,g as Jo,h as Go,i as zo,j as Wo,k as Qo,C as Uo,l as qo}from"./ContainerInspector-C8EkH4PP.js";import{S as re,M as ne,f as Yo,a as oe,p as z,e as B,b as ie,c as ce,d as le,u as Xo,g as Zo,h as ei,i as ti,j as ai,J as si,k as ri,l as ni,m as oi,n as ii,o as ci,q as li,r as di,s as ui,t as xi,v as pi,w as mi,x as hi,y as bi,z as fi,A as vi,B as gi,C as yi,D as ji,E as Si,F as Ni,G as Ci,H as wi,I as Pi,K as ki,L as Ei,N as Ri,O as Di,P as Ti,Q as Bi,T as Mi,R as Fi,U as Oi,V as Li,W as Ii}from"./ScenarioDataPanel-zJSXtXL4.js";import{ScenarioDataPanelFullPage as Ai}from"./ScenarioDataPanelFullPage-C0YHQB-T.js";import"./index-BUYNFqKK.js";import"./useEvents-DggWrtHe.js";import"./xterm--24IGk-x.js";function de({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 C({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 ue({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(xe,{status:a.status})," ",a.path]},a.path))})}function xe({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 pe({entry:t}){return e.jsxs("div",{className:"mt-3 pt-3",style:{borderTop:"1px solid var(--border-default)"},children:[t.userRequest&&e.jsx(C,{label:"Request",children:e.jsx(Y,{children:t.userRequest})}),e.jsx(C,{label:"Description",children:e.jsx(se,{variant:"compact",children:t.description})}),t.scenarioScreenshots.length>0&&e.jsx(C,{label:"Scenarios",children:e.jsx(X,{screenshots:t.scenarioScreenshots})}),t.modifiedFiles.length>0&&e.jsx(C,{label:"Modified Files",children:e.jsx(ue,{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 me({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(he,{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:Ze(t.timestamp)}),t.testResults&&e.jsx(Z,{total:t.testResults.total,passed:t.testResults.passed,failed:t.testResults.failed}),e.jsx(de,{files:t.modifiedFiles})]})]}),e.jsx("span",{className:"text-xs mt-1",style:{color:"var(--text-dim)"},children:a?"▼":"▶"})]}),a&&e.jsx(pe,{entry:t})]})}function he({type:t}){return e.jsx("span",{className:`text-xs font-medium ${et(t)}`,children:t})}function Hi({entries:t,total:a,hasMore:s,loading:r,loadingMore:n,error:o,onLoadMore:i}){if(r)return e.jsx("div",{className:"py-12 text-center text-[var(--text-muted)]",children:"Loading journal..."});if(o)return e.jsxs("div",{className:"py-12 text-center text-[var(--accent-red)]",children:["Failed to load journal: ",o]});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 l=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 ",l," journal entr",l===1?"y":"ies"]}),e.jsx("div",{className:"flex flex-col gap-3",children:t.map(c=>e.jsx(me,{entry:c},c.timestamp))}),s?e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx("button",{type:"button",onClick:i,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 $i({apps:t,selected:a,onChange:s}){return t.length===0?null:e.jsxs("div",{className:"flex gap-1",children:[t.map(r=>e.jsx(I,{href:tt(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(I,{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 Vi(){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."})]})}function _i({size:t=16}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}const Ki={http_request:"#3fb950",db_query:"#D7FF63",process_output:"#6e7681",health_check:"#d29922",hook_execution:"#bc8cff",error:"#f85149",scenario_switch:"#d29922"};function Ji(t){const a=Ki[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 be({event:t}){const{label:a,detail:s,badge:r,color:n}=Ji(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 Gi({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(be,{event:a},a.id))})}function fe({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 ve({group:t}){const[a,s]=d.useState(!0),r=t.tests.filter(i=>i.status==="passed").length,n=t.tests.filter(i=>i.status==="failed").length,o=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(fe,{passed:r,failed:n,total:o})]}),a&&e.jsx("div",{className:"ml-5 mt-1 border-l border-[var(--border-default)] pl-3",children:t.tests.map((i,l)=>e.jsx(ee,{test:i},l))})]})}function zi({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 ge({scenario:t,onPreview:a}){const s=t.screenshotPaths.length>0,[r,n]=d.useState(!1),o=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:[o?e.jsx("img",{src:at(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(i=>e.jsx("span",{className:"rounded bg-[var(--bg-input)] px-1.5 py-0.5 text-xs text-[var(--text-muted)]",children:i},i))]})]})}function ye({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(ge,{scenario:n,onPreview:a?()=>a(n.slug):void 0},n.slug))})]})}function je({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 Wi({slug:t,name:a,url:s,componentName:r,props:n,mocks:o,seed:i,localStorage:l,dimensions:c}){const[p,h]=d.useState(!1),b=Object.keys((o==null?void 0:o.http)??{}).length,u=Object.keys((o==null?void 0:o.db)??{}).length,f=Object.keys(l??{});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(C,{label:"URL",children:e.jsx("span",{className:"font-mono text-xs text-[var(--text-muted)]",children:s})}),r&&e.jsx(C,{label:"Component",children:e.jsx("span",{className:"font-mono text-xs text-[var(--accent-blue)]",children:r})}),n&&e.jsx(C,{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(C,{label:"Mocks",children:[t?e.jsxs("button",{type:"button",onClick:()=>h(!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":""]}),u>0&&e.jsxs("span",{className:"ml-2 text-xs text-[var(--text-muted)]",children:[u," DB mock",u!==1?"s":""]})]}),i&&e.jsx(C,{label:"Seed",children:i.command&&e.jsx("span",{className:"font-mono text-xs text-[var(--text-muted)]",children:i.command})}),f.length>0&&e.jsx(C,{label:"localStorage",children:f.map(v=>e.jsxs("p",{className:"font-mono text-xs text-[var(--text-muted)]",children:[v,": ",l[v]]},v))}),c.length>0&&e.jsx(C,{label:"Dimensions",children:e.jsx("div",{className:"flex gap-1",children:c.map(v=>e.jsx("span",{className:"rounded bg-[var(--bg-input)] px-1.5 py-0.5 text-xs text-[var(--text-muted)]",children:v},v))})}),p&&t&&e.jsx(re,{slug:t,scenarioName:a,initialSection:"mocks",onClose:()=>h(!1)})]})}function Se({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 o=d.useMemo(()=>{if(a==null)return"";try{return JSON.stringify(a,null,2)}catch{return""}},[a]),[i,l]=d.useState(t),[c,p]=d.useState(o),[h,b]=d.useState(null),[u,f]=d.useState(()=>Object.entries(s).map(([x,y])=>({name:x,value:y}))),[v,g]=d.useState(!0),j=h!==null||v;function m(){const x=c.trim()===""?null:JSON.parse(c),y={};for(const N of u)N.name.trim()&&(y[N.name.trim()]=N.value);r({status:i,body:x,headers:y})}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:i,onChange:x=>{g(!1),l(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(ne,{headers:u,onChange:x=>{g(!1),f(x)}}),e.jsx(Se,{value:c,parseError:h,onChange:x=>{g(!1),p(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:m,disabled:j,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 Ce({entry:t,scenarioHasDefaultFallback:a,editing:s,onToggleEdit:r,onPromoteDefaultToScenario:n,onRemove:o,onPassthrough:i,onCaptureLive:l}){const[c,p]=d.useState(!1),[h,b]=d.useState(null);async function u(){p(!0),b(null);try{await l()}catch(v){b(v instanceof Error?v.message:"Capture failed")}finally{p(!1)}}const f="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:f,children:s?"Close":"Edit"}),a&&e.jsx("button",{onClick:o,className:f,title:"Revert to default",children:"Revert to default"}),e.jsx("button",{onClick:i,className:f,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:i,className:f,children:"Mark passthrough"})]}),t.source==="catalog-only"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:u,disabled:c,className:"px-2 py-0.5 rounded border border-[#D7FF63]/50 bg-[#D7FF63]/10 text-[#D7FF63] hover:bg-[#D7FF63]/20 disabled:opacity-50 disabled:cursor-wait cursor-pointer text-[10px]",title:"Write last-observed body as this scenario's mock",children:c?"Capturing…":"Capture from live"}),h&&e.jsx("span",{className:"text-red-400 text-[10px]",children:h})]}),t.source==="passthrough"&&e.jsx("button",{onClick:o,className:f,children:"Undo passthrough"})]})}const W={GET:"text-emerald-400 border-emerald-400/40",POST:"text-[#D7FF63] border-[#D7FF63]/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 we({entry:t}){const a=W[t.method]??W.GET,s=t.status??t.lastObservedStatus,r=t.lastObservedMs?Yo(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(oe,{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 Pe({entry:t,scenarioHasDefaultFallback:a,onSave:s,onRemove:r,onPassthrough:n,onCaptureLive:o}){const[i,l]=d.useState(!1),c=`${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(we,{entry:t}),t.variants.length>1&&e.jsxs("div",{className:"text-[10px] text-[var(--text-dim)] font-mono",children:["variants: ",t.variants.filter(p=>p!==c).join(", ")]}),e.jsx(Ce,{entry:t,scenarioHasDefaultFallback:a,editing:i,onToggleEdit:()=>l(p=>!p),onPromoteDefaultToScenario:()=>s({routeKey:c,status:t.status??200,body:t.body,headers:t.headers??{}}),onRemove:()=>r(c),onPassthrough:()=>n(c),onCaptureLive:()=>o(t.method,t.pathPattern)}),i&&e.jsx(Ne,{initialStatus:t.status??200,initialBody:t.body,initialHeaders:t.headers??{},onCancel:()=>l(!1),onSave:async p=>{await s({routeKey:c,...p}),l(!1)}})]})}const T=async()=>{};function Qi({label:t,entries:a,defaultEndpointKeys:s=[],onSave:r=T,onRemove:n=T,onPassthrough:o=T,onCaptureLive:i=T}){if(a.length===0)return null;const l=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(c=>e.jsx(Pe,{entry:c,scenarioHasDefaultFallback:l.has(`${c.method} ${c.pathPattern}`),onSave:r,onRemove:n,onPassthrough:o,onCaptureLive:i},`${c.method} ${c.pathPattern}`))})]})}function Ui({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 qi({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 Yi({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(o=>e.jsx(ye,{group:o,onPreviewScenario:n},o.route))]})}function Xi({groups:t,loading:a,error:s,cached:r,totalTests:n,passedTests:o,coverage:i,onRefresh:l}){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:[o,"/",n," passed across ",t.length," features"]}),e.jsx(te,{coverage:i,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:l,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(c=>e.jsx(ve,{group:c},c.feature))]})}function Zi({onClick:t,isOpen:a,disabled:s}){return e.jsx("button",{type:"button",onClick:t,disabled:s,"aria-expanded":a,"aria-haspopup":"dialog",className:`flex items-center h-7 px-2 rounded text-[11px] font-mono tracking-wide cursor-pointer transition-colors ${s?"text-gray-500 bg-[#2d2d2d] cursor-not-allowed":a?"text-white bg-[#555]":"text-gray-300 bg-[#3a3a3a] hover:bg-[#444]"}`,title:"Edit scenario data",children:"EDIT DATA"})}function $(t){return`${t.method} ${t.pathPattern}`}function ec({slug:t,onApplied:a}){const[s,r]=d.useState({kind:"idle"}),n=d.useCallback(async o=>{r({kind:"submitting"});try{const l=await(await fetch(`/api/scenarios/${encodeURIComponent(t)}/data/describe`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:o})})).json();l.success?(a(),r({kind:"applied",message:l.message??"Changes applied. Review the table and click Save."})):r({kind:"error",message:l.error??"AI rewrite failed."})}catch(i){r({kind:"error",message:i instanceof Error?i.message:"Network error"})}},[t,a]);return{status:s,submit:n}}function tc(t,a){d.useEffect(()=>{function s(n){t.current&&!t.current.contains(n.target)&&a()}function r(n){n.key==="Escape"&&a()}return document.addEventListener("mousedown",s),document.addEventListener("keydown",r),()=>{document.removeEventListener("mousedown",s),document.removeEventListener("keydown",r)}},[t,a])}function ac({props:t,seedTabs:a,mockEntries:s}){const[r,n]=d.useState(null),[o,i]=d.useState(null),[l,c]=d.useState(null),p=d.useMemo(()=>{const u=[];return t&&Object.keys(t).length>0&&u.push({kind:"props",label:"Props",tabs:[]}),a.length>0&&u.push({kind:"seed",label:"Seed Data",tabs:a.map(f=>({id:f.dataKey,label:f.label}))}),s.length>0&&u.push({kind:"mock",label:"Mock Data",tabs:s.map(f=>({id:$(f),label:`${f.method} ${f.pathPattern}`}))}),u},[t,a,s]);d.useEffect(()=>{if(r!==null||p.length===0)return;const u=p[0];n(u.kind),u.kind==="seed"&&u.tabs[0]?i(u.tabs[0].id):u.kind==="mock"&&u.tabs[0]&&c(u.tabs[0].id)},[r,p]);const h=p.find(u=>u.kind===r)??null;function b(u){var f,v,g,j;if(n(u),u==="seed"&&!o){const m=(v=(f=p.find(x=>x.kind==="seed"))==null?void 0:f.tabs[0])==null?void 0:v.id;m&&i(m)}if(u==="mock"&&!l){const m=(j=(g=p.find(x=>x.kind==="mock"))==null?void 0:g.tabs[0])==null?void 0:j.id;m&&c(m)}}return{sections:p,activeSection:h,section:r,activeSeedKey:o,activeMockKey:l,selectSection:b,selectSeedKey:i,selectMockKey:c}}function sc(t){const[a,s]=d.useState(null);return d.useEffect(()=>{var i;const r=(i=t.current)==null?void 0:i.closest("[data-preview-pane='true']");if(!r)return;const n=()=>s(r.getBoundingClientRect().width);n();const o=new ResizeObserver(n);return o.observe(r),()=>o.disconnect()},[t]),a}function V(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function rc(t){return Array.isArray(t)&&t.length>0&&t.every(V)}function A(t,a,s){if(V(t)){for(const[r,n]of Object.entries(t)){const o=a?`${a}.${r}`:r;A(n,o,s)}return}if(rc(t)){t.forEach((r,n)=>A(r,`${a}[${n}]`,s));return}s.push({path:a,value:t})}function Q(t){if(!V(t))return[];const a=[];return A(t,"",a),a}function nc(t){return t===null?"null":t===void 0?"":typeof t=="object"?JSON.stringify(t):String(t)}function oc({slug:t,initialProps:a,onCellEdited:s}){const[r,n]=d.useState(()=>Q(a)),[o,i]=d.useState(null),[l,c]=d.useState(""),[p,h]=d.useState(""),b=d.useRef(null);d.useEffect(()=>{n(Q(a)),i(null)},[a]);function u(m){const x=r.find(M=>M.path===m);i(m);const y=x==null?void 0:x.value,N=y==null?"":typeof y=="object"?JSON.stringify(y):String(y);c(N),h(N)}function f(m){if(c(m),b.current&&clearTimeout(b.current),!o)return;const x=o;b.current=setTimeout(()=>{j(x,m)},600)}function v(){o&&(b.current&&clearTimeout(b.current),j(o,l),i(null))}function g(){if(b.current&&clearTimeout(b.current),!!o){if(l!==p){const m=r.map(x=>x.path===o?{...x,value:z(p)}:x);n(m),fetch(`/api/scenarios/${encodeURIComponent(t)}/data`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:`props.${o}`,value:p})}).then(()=>{B(),s&&s()}).catch(()=>{})}i(null)}}async function j(m,x){const y=r.map(N=>N.path===m?{...N,value:z(x)}:N);n(y);try{await fetch(`/api/scenarios/${encodeURIComponent(t)}/data`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:`props.${m}`,value:x})}),B(),s&&s()}catch{}}return{rows:r,editingPath:o,editValue:l,handleEditPath:u,handleEditValueChange:f,handleSave:v,handleCancelEdit:g}}function ke({path:t,value:a,onValueChange:s,onSave:r,onCancel:n}){return e.jsxs("div",{className:"border-t border-[var(--border-default)] bg-[var(--bg-deep)] px-3 py-2",children:[e.jsx("div",{className:"flex items-center gap-2 mb-1.5",children:e.jsxs("span",{className:"text-[10px] text-[var(--text-muted)]",children:["Editing"," ",e.jsx("strong",{className:"text-[var(--text-secondary)] font-mono",children:t})]})}),e.jsx("textarea",{value:a,onChange:o=>s(o.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:a.length>100?4:2,onKeyDown:o=>{o.key==="Escape"&&n(),o.key==="Enter"&&(o.metaKey||o.ctrlKey)&&r()}}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsx("button",{onClick:r,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"}),e.jsx("button",{onClick:n,className:"px-3 py-1 text-[10px] text-[var(--text-muted)] hover:text-[var(--text-primary)] bg-transparent border-none cursor-pointer",children:"Cancel"}),e.jsxs("span",{className:"text-[9px] text-[var(--text-dim)] ml-auto",children:["⌘","+Enter to save, Esc to cancel"]})]})]})}function Ee({slug:t,props:a,onCellEdited:s}){const{rows:r,editingPath:n,editValue:o,handleEditPath:i,handleEditValueChange:l,handleSave:c,handleCancelEdit:p}=oc({slug:t,initialProps:a,onCellEdited:s});return r.length===0?e.jsx("p",{className:"p-4 text-xs text-[var(--text-dim)] italic",children:"This scenario has no props to edit."}):e.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[e.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:e.jsxs("table",{className:"w-full text-[11px] border-separate border-spacing-0",children:[e.jsx("thead",{className:"bg-[var(--bg-card)] sticky top-0 z-10",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left font-medium text-[var(--text-secondary)] px-3 py-2 border-b border-[var(--border-default)] w-1/3",children:"Key"}),e.jsx("th",{className:"text-left font-medium text-[var(--text-secondary)] px-3 py-2 border-b border-[var(--border-default)]",children:"Value"})]})}),e.jsx("tbody",{children:r.map(h=>e.jsxs("tr",{className:"hover:bg-[var(--bg-card)]",children:[e.jsx("td",{className:"px-3 py-1.5 border-b border-[var(--border-subtle)] font-mono text-[var(--text-secondary)] align-top",children:h.path}),e.jsx("td",{className:"px-3 py-1.5 border-b border-[var(--border-subtle)] cursor-text text-[var(--text-primary)] align-top",onClick:()=>i(h.path),children:nc(h.value)})]},h.path))})]})}),n&&e.jsx(ke,{path:n,value:o,onValueChange:l,onSave:c,onCancel:p})]})}function Re({slug:t,section:a,hasAnything:s,loading:r,seedError:n,mocksError:o,draftError:i,props:l,selectedSeedTab:c,filteredSeedRows:p,selectedMock:h,onSeedCellEdit:b,onMockSave:u}){return e.jsxs("div",{className:"min-h-0 flex-1 flex flex-col bg-[var(--bg-deep)] overflow-hidden",children:[n&&e.jsxs("p",{className:"p-3 text-xs text-red-400",children:["Seed error: ",n]}),o&&e.jsxs("p",{className:"p-3 text-xs text-red-400",children:["Mocks error: ",o]}),i&&e.jsxs("p",{className:"p-3 text-xs text-red-400",children:["Draft error: ",i]}),r&&!s&&e.jsx("p",{className:"p-4 text-xs text-[var(--text-dim)]",children:"Loading scenario data…"}),!r&&!s&&e.jsx("p",{className:"p-4 text-xs text-[var(--text-dim)] italic",children:"This scenario has no data, mocks, or props to edit."}),a==="props"&&e.jsx(Ee,{slug:t,props:l,onCellEdited:b}),a==="seed"&&c&&e.jsx(ie,{slug:t,tab:c,initialRows:p,onCellEdited:b}),a==="mock"&&h&&e.jsx("div",{className:"flex-1 min-h-0 overflow-auto p-3",children:h.source==="scenario"||h.source==="default"||h.source==="shared"?e.jsx(ce,{entry:h,routeKey:$(h),scenarioSlug:t,onSave:u}):e.jsx(le,{entry:h})})]})}function De({status:t,onSubmit:a}){const[s,r]=d.useState(""),n=t.kind==="submitting";function o(){const i=s.trim();!i||n||(a(i),r(""))}return e.jsxs("div",{className:"shrink-0 border-t border-[var(--border-default)] bg-[var(--bg-deep)] px-4 py-3",children:[e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("textarea",{value:s,onChange:i=>r(i.target.value),placeholder:"Describe Changes",rows:2,disabled:n,className:"flex-1 px-3 py-2 text-[12px] bg-[var(--bg-card)] text-[var(--text-primary)] border border-[var(--border-default)] rounded outline-none focus:border-[var(--accent-active)]/50 resize-none min-h-[44px] disabled:opacity-50",onKeyDown:i=>{i.key==="Enter"&&(i.metaKey||i.ctrlKey)&&(i.preventDefault(),o())}}),e.jsx("button",{type:"button",onClick:o,disabled:n||!s.trim(),className:"px-3 py-2 text-[11px] font-medium text-[var(--bg-deep)] bg-[var(--accent-active)] rounded cursor-pointer border-none hover:bg-[var(--accent-active)]/80 disabled:opacity-50 disabled:cursor-not-allowed transition-colors h-fit",children:n?"Applying…":"Submit"})]}),t.kind==="applied"&&e.jsx("p",{className:"text-[10px] text-[var(--accent-active)] mt-1.5",children:t.message}),t.kind==="error"&&e.jsx("p",{className:"text-[10px] text-red-400 mt-1.5",children:t.message})]})}function Te({isDirty:t,saving:a,cancelling:s,onSave:r,onCancel:n,onClose:o}){const i=a||s;return e.jsxs(e.Fragment,{children:[t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:r,disabled:i,className:"px-2 py-0.5 text-[10px] font-medium text-[var(--bg-deep)] bg-[var(--accent-active)] rounded cursor-pointer border-none hover:bg-[var(--accent-active)]/80 disabled:opacity-50",children:a?"Saving…":"Save"}),e.jsx("button",{type:"button",onClick:n,disabled:i,className:"px-2 py-0.5 text-[10px] text-[var(--text-muted)] hover:text-[var(--text-primary)] bg-transparent border border-[var(--border-default)] rounded cursor-pointer disabled:opacity-50",children:s?"Cancelling…":"Cancel"})]}),e.jsx("button",{type:"button",onClick:o,"aria-label":"Close",className:"text-[var(--text-muted)] hover:text-[var(--text-primary)] text-sm bg-transparent border-none cursor-pointer px-1 leading-none",children:"✕"})]})}function Be({value:t,disabled:a,onChange:s}){return e.jsx("input",{type:"search",value:t,onChange:r=>s(r.target.value),placeholder:"Search…",disabled:a,className:"text-[10px] bg-[var(--bg-card)] text-[var(--text-primary)] border border-[var(--border-default)] rounded px-2 py-0.5 outline-none focus:border-[var(--accent-active)]/50 disabled:opacity-40 w-36"})}function Me({sections:t,section:a,activeSection:s,onSelect:r}){return t.length>1?e.jsx("select",{value:a??"",onChange:n=>r(n.target.value),className:"text-[9px] font-semibold tracking-wider uppercase text-[var(--text-primary)] bg-[var(--bg-card)] border border-[var(--border-default)] rounded px-1.5 py-0.5 cursor-pointer outline-none",children:t.map(n=>e.jsx("option",{value:n.kind,children:n.label},n.kind))}):s?e.jsx("span",{className:"text-[9px] font-semibold tracking-wider uppercase text-[var(--text-primary)] px-1.5 py-0.5",children:s.label}):null}function Fe({tabs:t,activeId:a,onSelect:s}){return e.jsx("div",{className:"flex items-center gap-0.5 overflow-x-auto min-w-0",children:t.map(r=>{const n=r.id===a;return e.jsx("button",{type:"button",onClick:()=>s(r.id),className:`px-1.5 py-0.5 text-[9px] font-medium tracking-wide uppercase rounded whitespace-nowrap cursor-pointer transition-colors ${n?"text-[var(--accent-active)] bg-[var(--accent-active)]/10":"text-[var(--text-muted)] hover:text-[var(--text-primary)]"}`,children:r.label},r.id)})})}function Oe({sections:t,section:a,activeSection:s,activeTabId:r,onSelectSection:n,onSelectTab:o,search:i,searchDisabled:l,onSearchChange:c,isDirty:p,saving:h,cancelling:b,onSave:u,onCancel:f,onClose:v}){return e.jsxs("header",{className:"shrink-0 flex items-center justify-between gap-3 px-3 py-1.5 border-b border-[var(--border-subtle)]",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 flex-1",children:[e.jsx(Me,{sections:t,section:a,activeSection:s,onSelect:n}),e.jsx("span",{className:"text-[var(--text-dim)] text-[10px]",children:"/"}),e.jsx(Fe,{tabs:(s==null?void 0:s.tabs)??[],activeId:r,onSelect:o})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(Be,{value:i,disabled:l,onChange:c}),e.jsx(Te,{isDirty:p,saving:h,cancelling:b,onSave:u,onCancel:f,onClose:v})]})]})}function Le({popoverRef:t,paneWidth:a}){return e.jsx("div",{"aria-hidden":"true",onMouseDown:s=>{const r=t.current;if(!r)return;s.preventDefault();const n=r.getBoundingClientRect(),o=s.clientX,i=s.clientY,l=n.width,c=n.height,p=n.right,h=u=>{const f=u.clientX-o,v=u.clientY-i,g=420,j=280,m=a?Math.max(g,a-16):l+1e3,x=Math.max(g,Math.min(m,l-f)),y=Math.max(j,c+v);r.style.width=`${x}px`,r.style.height=`${y}px`,r.style.right=`${r.parentElement.getBoundingClientRect().right-p}px`},b=()=>{window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",b)};window.addEventListener("mousemove",h),window.addEventListener("mouseup",b)},className:"absolute bottom-0 left-0 w-3 h-3 z-50",style:{cursor:"nesw-resize"}})}function ic({slug:t,scenarioName:a,onClose:s}){const r=d.useRef(null),n=Xo({slug:t,onPreviewReload:B}),o=sc(r),{data:i,tableTabs:l,props:c,loading:p,error:h}=Zo(t),{entries:b,loading:u,error:f,upsertScoped:v}=ei(t),{sections:g,activeSection:j,section:m,activeSeedKey:x,activeMockKey:y,selectSection:N,selectSeedKey:M,selectMockKey:He}=ac({props:c,seedTabs:l,mockEntries:b}),[E,_]=d.useState(""),F=m==="seed"?l.find(S=>S.dataKey===x)??null:null,$e=m==="mock"?b.find(S=>$(S)===y)??null:null,O=F&&i?i[F.dataKey]??[]:[],Ve=d.useMemo(()=>{if(!E.trim())return O;const S=E.toLowerCase();return O.filter(qe=>Object.values(qe).some(Ye=>String(Ye??"").toLowerCase().includes(S)))},[O,E]),R=d.useCallback(()=>{n.markDirty(),B()},[n]),_e=d.useCallback(async S=>{await v(S),R()},[v,R]),K=d.useCallback(()=>{n.confirmIfDirty("Discard unsaved changes to this scenario?")&&s()},[n,s]);tc(r,K);const Ke=d.useCallback(async()=>{await n.save(),n.error||s()},[n,s]),J=ec({slug:t,onApplied:R}),Je=m==="seed"?x:m==="mock"?y:null;function Ge(S){m==="seed"&&M(S),m==="mock"&&He(S)}function ze(S){S!==null&&(N(S),_(""))}const We=a??t,Qe=g.length>0,Ue=p||u;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30 bg-black/30 pointer-events-none","aria-hidden":"true"}),e.jsxs("div",{ref:r,role:"dialog","aria-label":`Edit data for ${We}`,style:{resize:"both",maxWidth:o?`${Math.max(420,o-16)}px`:"calc(100vw - 2rem)"},className:"absolute right-0 top-full mt-1 z-40 flex flex-col rounded-lg border border-[var(--border-default)] bg-[var(--bg-deep)] shadow-2xl overflow-hidden w-[640px] max-h-[calc(100vh-6rem)] min-w-[420px] min-h-[200px]",children:[e.jsx(Oe,{sections:g,section:m,activeSection:j,activeTabId:Je,onSelectSection:ze,onSelectTab:Ge,search:E,searchDisabled:m!=="seed",onSearchChange:_,isDirty:n.isDirty,saving:n.saving,cancelling:n.cancelling,onSave:Ke,onCancel:()=>void n.cancel(),onClose:K}),e.jsx(Re,{slug:t,section:m,hasAnything:Qe,loading:Ue,seedError:h,mocksError:f,draftError:n.error,props:c,selectedSeedTab:F,filteredSeedRows:Ve,selectedMock:$e,onSeedCellEdit:R,onMockSave:_e}),e.jsx(De,{status:J.status,onSubmit:J.submit}),e.jsx(Le,{popoverRef:r,paneWidth:o})]})]})}function cc({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 lc({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(H,{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 dc(){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(H,{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 uc(){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 xc({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 Ie(){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 pc({directImports:t}){return t.length===0?e.jsx(Ie,{}):e.jsx("div",{className:"grid grid-cols-1 gap-1",children:t.map(a=>{const{fileName:s,dirPath:r}=st(a);return e.jsx(je,{fileName:s,dirPath:r},a)})})}function mc({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 hc({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(bc,{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 bc({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-[#D7FF63] bg-[#D7FF63]/15 border-[#D7FF63]/40":"text-[#D7FF63]/60 bg-transparent border-transparent hover:text-[#D7FF63]/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 fc({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(ae,{featureName:t,onClose:a})})}function U(){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(Io,{title:"Section Header Example"}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx(D,{color:"#238636",children:"ACTIVE"}),e.jsx(D,{color:"#d29922",children:"WARNING"}),e.jsx(D,{color:"#da3633",children:"ERROR"}),e.jsx(D,{color:"#D7FF63",children:"INFO"})]}),e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsx(k,{method:"GET"}),e.jsx(k,{method:"POST"}),e.jsx(k,{method:"PUT"}),e.jsx(k,{method:"DELETE"}),e.jsx(k,{method:"PATCH"})]}),e.jsx(L,{color:"#238636",children:"Success status message"}),e.jsx(L,{color:"#d29922",children:"Warning status message"}),e.jsx(L,{color:"#8b949e",children:"Neutral status message"})]})}const vc=[{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 q({events:t}){const a=t??vc;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:w,children:"Time"}),e.jsx("th",{style:w,children:"Method"}),e.jsx("th",{style:{...w,textAlign:"left"},children:"URL"}),e.jsx("th",{style:w,children:"Status"}),e.jsx("th",{style:w,children:"Duration"}),e.jsx("th",{style:w,children:"Source"})]})}),e.jsx("tbody",{children:a.map(s=>e.jsx(Ao,{event:s},s.id))})]})})}function gc(){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 Ae({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 yc={ProviderAuthGate:Bo,ProviderAuthModal:To,ClaudeOAuthFlow:Do,ApiKeyFlow:Ro,AppCard:Eo,AppDetail:ko,AppOverview:Po,BuildTab:wo,BuildTabLayout:Co,BuildTabPane:No,BuildTabPaneLayout:So,BuildTabRecoveryPanel:jo,BuildTabSessionContent:yo,BuildTabStartupError:go,BuildTabReadyToBuildPlaceholder:Vi,BuildTabTerminalSession:vo,AppSelector:$i,AppTypeBadge:fo,BreadcrumbNav:bo,EntityBreadcrumb:ho,BuildingPreviewOverlay:mo,ConnectionBadge:qo,DebugModeButton:po,DebugModal:xo,DebugModalElementPreview:uo,DebugModalInfoPanel:lo,DebugOverlay:co,DebugAncestryList:io,DebugAncestrySection:oo,DebugPropsChips:no,DebugFreezePill:ro,OpenInEditorErrorToast:so,CyLogo:ao,DeviceIcon:to,EditorNavBar:eo,IdleBanner:Zn,EditorSessionRecoveryActionButton:Xn,EditorSessionRecoveryDialog:Yn,EditorSessionRecoveryHeader:qn,EditorSessionRecovery:Un,EditorSessionRecoverySummaryRow:Qn,EditorSessionRecoverySummary:Wn,EditorShellHomeTabContent:zn,EditorShellBuildLayer:Gn,EditorShellLayout:Jn,EditorShellLeftPane:Kn,EditorShellPlanLayer:_n,EditorShellPreviewPane:G,EditorShellTabLayer:Vn,MobilePaneSwitcher:$n,GearIcon:_i,EventCard:be,EventStream:Gi,EntryTypeBadge:he,CollapsibleMarkdown:Y,FeatureNameButton:Hn,FeatureGroupView:ve,FileChangeSummary:de,FileStatusIndicator:xe,FileStatusIndicatorStandalone:An,HistoryTab:In,HistoryEntryCard:Ln,CommitOnlyHistoryRow:On,NotificationSettingsPopover:Fn,DebugNotificationsButton:Mn,IdleTriggerCheckbox:Bn,JournalEntryCard:me,JournalEntryDetails:pe,JournalView:Hi,LabeledSection:C,FilterBar:zi,LeftPanel:Tn,ModifiedFilesList:ue,NavLink:I,StepProgressBar:Dn,TestRunnerStatsBar:Rn,TestsSummaryCard:En,NarrativeSection:kn,PreNarrativeFallback:Pn,ModifiedFilesSection:wn,Markdown:se,NewProjectQuestionnaire:Cn,DesignFileUploadStep:Nn,QuestionnaireDesignApproachStep:Sn,QuestionnaireDesignChatStep:jn,QuestionnaireDesignChatLaunchPanel:yn,MockupArchivedRoundView:gn,MockupCard:vn,MockupCardFeedback:fn,MockupFeedbackCommentBox:bn,MockupFeedbackRatingSlider:hn,MockupGridInfoBanner:mn,MockupGridIterateButton:pn,MockupPlaceholderCard:xn,MockupRoundPager:un,DesignExplorationView:dn,QuestionnaireIntroBanner:ln,QuestionnaireDeviceSelector:cn,QuestionnaireNavButtons:on,QuestionnaireOptionCard:nn,PanelDivider:rn,PromptDropdownPanel:sn,PreviewCanvas:an,PreviewEmptyState:tn,PreviewFrame:en,BackendResultsPanelView:Zr,PlanPreviewPanelView:Xr,PlanPreviewEmptyState:Yr,PlanPreviewHeader:qr,ProjectSetupPreviewView:Ur,ProjectSetupPreviewPane:Qr,StartBuildingConfirmModal:Wr,ProjectSetupHeader:zr,ProjectSetupDescriptionCard:Gr,ProjectSetupProgressList:Jr,ProjectSetupProgressRow:Kr,LiveIframeHealthPill:_r,PreviewPanel:G,BuildLogsModal:Vr,SimulatorLauncherControls:$r,SimulatorPreviewFrame:Hr,NoBootedSimulatorPlaceholder:Ar,QuestionnaireStepNav:Ir,QuestionnaireStepPanel:Lr,AppDetailContent:Or,AppDetailContentError:Fr,AppDetailContentLoading:Mr,AppDetailHeader:Br,AppDetailProjectBand:Tr,AppCapabilitiesPanel:Dr,AppStackPanel:Rr,AppStackPanelSummary:Er,AppStackPanelBody:kr,AppStackCapabilitiesSlot:Pr,CapabilityRow:wr,AppTestSummary:Cr,LayoutChainCard:Nr,LayoutChainSection:Sr,RouteDependencyCard:jr,RouteDependencyCardHeader:yr,RouteDependencyEmptyState:gr,RouteDependencyList:vr,RouteDependencyScenarioStrip:fr,RouteEntityDetail:br,RouteEntityDetailContent:hr,RouteFunctionCard:mr,RouteFunctionEmptyState:pr,RouteFunctionList:xr,RouteEntityDetailHeader:ur,RouteEntityTabs:dr,RouteGroupView:ye,RouteImportRow:je,RouteList:lr,RouteListCardThumbnail:cr,RouteScenarioList:ir,ScenarioCard:ge,ScenarioRow:or,ScenarioDetailPanel:Wi,MockBodyEditor:Ne,MockBodyHeadersEditor:ne,MockBodyJsonTextarea:Se,MockPanelGroup:Qi,MockPanelHeader:Ui,MockPanelRow:Pe,MockPanelRowActions:Ce,MockPanelRowHeader:we,MockSourceBadge:oe,ScenarioThumbnailGrid:X,StatusBadge:fe,StepIndicatorBar:nr,StepIndicatorDropdownItem:rr,TabPane:sr,TestItem:ee,TestGroupHeader:ar,TestGroupList:tr,TestGroupRow:er,TestResultsBadge:Z,TestSummary:qi,TestStatusIcon:Zs,ThumbnailStrip:Xs,CollapseToggleButton:Ys,DimensionInput:qs,EditorShell:Us,EntityDetail:Qs,EntityDetailContent:Ws,EntityDetailHeader:zs,EntityRefCard:Gs,EntityRefList:Js,FillPreviewButton:Ks,OpenInNewTabButton:_s,PlaceholderPane:Vs,PlanTab:$s,PlanTabHeader:Hs,PlanNextChangeButton:As,PlanAuthoringChat:Is,PlanSubTabs:Ls,DescribePane:Os,PrototypePane:Fs,PrototypeAgentChat:Ms,StartPrototypingButton:Bs,FinishAndFormalizeButton:Ts,PrototypeBuildingInProgressBanner:Ds,PlanChatLaunchCaption:Rs,PlanExpandedHeader:Es,PlanRow:ks,PlanRowClaimBadge:Ps,PlanRowDependencyEntry:ws,PlanRowEditButton:Cs,PlanRowEditChatButton:Ns,PlanRowExpandedBody:Ss,PlanRowExpandedChat:js,PlanRowExpandedDependencies:ys,PlanRowExpandedEdit:gs,PlanRowExpandedView:vs,PlanRunButton:fs,PlanRunBlockedModal:bs,PlanRunForeignClaimModal:hs,PlanRunDependenciesModal:ms,QueuedChangesSection:ps,InFlightSection:xs,InFlightPlanRow:us,CommitQueueSection:ds,CommitQueueRow:ls,CommitQueuePriorityChip:cs,CommitQueueReleaseButton:is,CommitQueueRowIdentity:os,SortablePlanRow:ns,RecentPlansSection:rs,CompletedPlanRow:ss,CompletedPlanExpandedBody:as,TabScrollPanel:ts,BuildLaunchModal:es,PostPushTransition:Za,PostPushTransitionDialog:Xa,SelectPlanModal:Ya,PlanCompleteDialog:qa,PlanCompleteTransition:Ua,ScenarioRenderer:kc,ScenariosView:Yi,TerminalEmulator:Qa,RawTerminalModal:Wa,RawTerminalEmulator:za,TerminalDropOverlay:Ga,TerminalDropToast:Ja,TerminalDisconnectOverlay:Ii,TerminalConnectingHint:Li,TerminalReconnectingBanner:Oi,TerminalFailedBanner:Fi,TerminalServerStoppedBanner:Mi,TestsView:Xi,NavigationBar:Ka,PagePill:_a,PagePickerDropdown:Va,StatesDropdown:$a,CreateStatePlaceholderModal:Ha,StatesPillButton:Aa,EditDataButton:Zi,EditDataPopover:ic,EditDataPopoverBody:Re,EditDataPopoverDescribeInput:De,EditDataPopoverHeader:Oe,EditDataPopoverResizeHandleLeft:Le,EditDataPopoverSaveCancelClose:Te,EditDataPopoverSearchInput:Be,EditDataPopoverSectionSelector:Me,EditDataPopoverTabStrip:Fe,ScenarioDataPanelMainProps:Ee,ScenarioDataPanelPropsEditor:ke,ViewportPresetButton:Ia,PagePickerTabButton:La,PagePickerEmptyMessage:Oa,PagePickerScenarioThumbnail:Fa,PagePickerRouteSection:Ma,StatesDropdownRow:Ba,ComponentGlyph:Ta,DropdownChevron:Da,PageGlyph:Ra,ViewTabs:cc,SessionResultsPanel:Ea,SessionResultsPanelHeader:ka,BackendResultsPage:Pa,BackendConnectionStatusBadge:wa,BackendConnectionLogEntryRow:Ca,BackendConnectionLogSection:Na,NarrativeTestStatusIcon:Sa,CoverageBadge:te,CoverageBar:ja,CoverageWarningsBanner:ya,FunctionsCoverageSection:ga,CoverageSectionHeader:va,OrphanedFileRow:fa,FunctionsCoverageEmptyState:ba,ProjectWideCoverageRollup:ha,CoverageDetailsModal:ma,CoverageFileDrilldown:pa,CoverageDetailsEntriesSection:xa,CoverageDetailsEntryRow:ua,CoverageDetailsOrphanedSection:da,CoverageDetailsDirectoriesSection:la,CoverageDetailsDirectoryGroup:ca,CoverageDetailsDirectoryFileRow:ia,CoverageLineRow:oa,AppCardFooter:na,RunTestsButton:ra,TestBar:sa,AppCardHeader:aa,AppCardScenarioStrip:ta,AppOverviewEmptyState:ea,AppOverviewEmptyStateBuildingPanel:Zt,AppOverviewEmptyStateNoAppPanel:Xt,OpenBuildTabButton:Yt,AppOverviewGrid:qt,AppOverviewHeader:Ut,CopyButton:Qt,CrashLogFooter:Wt,CrashLogFooterMessage:zt,CrashLogHeader:Gt,CrashLogViewer:Jt,DevServerCrashLog:Kt,DevServerRestartingOverlay:lc,DevServerStartingOverlay:dc,DevServerStoppedOverlay:uc,PreviewUnhealthyOverlay:_t,PreviewErrorOverlay:Vt,PreviewErrorOverlayHeader:$t,PreviewErrorOverlayFooter:Ht,PreviewErrorList:At,PreviewErrorRow:It,PreviewErrorBadge:Lt,BuildSpinner:Ot,BuildShaBadge:Ft,RestartSpinner:H,RouteEntitySection:xc,RouteImportEmptyState:Ie,RouteImportList:pc,RouteListCard:Mt,RouteListEmptyState:Bt,RouteListSectionHeader:Tt,RouteScenarioEmptyState:Dt,RouteSummaryCard:mc,SafeScreenshot:Rt,ScenarioRowMeta:Et,ScenarioRowOverrideBadge:kt,ScenarioRowThumbnail:Pt,SidebarGroupOverrideHeader:Bi,SidebarInheritedSection:Ti,DataViewerCategoryBadge:Di,DataViewerCellEditor:Ri,DataViewerTabBar:hc,DataViewerTable:Ei,ScenarioDataPanel:re,ScenarioDataPanelCloseButton:ki,ScenarioDataPanelEditChatButton:Pi,ScenarioDataPanelEmptyState:wi,ScenarioDataPanelFullPage:Ai,ScenarioDataPanelHeader:Ci,ScenarioDataPanelInspectButton:Ni,ScenarioDataPanelMainMock:Si,ScenarioDataPanelMainMockEditable:ce,ScenarioDataPanelMainMockHeader:ji,ScenarioDataPanelMainMockReadOnly:le,ScenarioDataPanelMainTable:ie,ScenarioDataPanelOpenInNewButton:yi,ScenarioDataPanelMockDataBadge:gi,ScenarioDataPanelMockDataStrip:vi,ScenarioDataPanelSidebar:fi,SaveScopeChoiceRow:bi,SaveScopeModal:hi,SidebarMockEntryRow:mi,MockSharedSlugBadge:pi,ScenarioDraftBar:xi,JsonBodyActions:ui,JsonTreeAddKeyInput:di,JsonTreeArrayNode:li,JsonTreeEditor:ci,JsonTreeNode:ii,JsonTreeNodeLine:oi,JsonTreeObjectNode:ni,JsonTreePrimitiveEditor:ri,JsonTreePrimitiveNode:si,ScenarioRenameForm:wt,ScenarioRowActions:Ct,MiniAgentChat:ai,MiniAgentLaunchOverlay:ti,EnvelopeIcon:Nt,SendTranscriptModal:ae,SendTranscriptOverlay:fc,ContainerInspector:Uo,InspectorScenarioSection:Qo,InspectorRouteTable:Wo,InspectorTrafficSection:zo,InspectorExplainerSection:Go,InspectorExplainerResult:Jo,InspectorPrimitivesShowcase:U,InspectorTrafficRowShowcase:q,InspectorTrafficDetail:Ko,InspectorTrafficFilterBar:_o,InspectorTrafficTable:Vo,InspectorTrafficUrlChips:$o,InspectorUrlGlossary:Ho,InspectorPrimitives:U,InspectorTrafficRow:q,StepsSimulator:Lo,StepsSimulatorStepList:Oo,StepsSimulatorVariableControl:Fo,StepsSimulatorInstructionsPanel:Mo,SeedErrorBanner:St,SeedLoadingOverlay:jt,StaleDbStripeOverlay:gc,ScenarioSeedErrorView:Ae,CoverageThresholdsPanel:yt,CoverageThresholdsEmptyState:gt,CoverageThresholdsHeader:vt,CoverageThresholdsDefaultNotice:ft,CoverageThresholdsPassSummary:bt,CoverageThresholdsFailureList:ht,CoverageThresholdFailureGroup:mt,InspectModeRibbon:pt,IframeClickThroughErrorCard:xt,InspectResultCard:ut,InspectResultCardBackdrop:dt,InspectResultCardBody:lt,InspectResultCardHeader:ct,InspectResultCardMatchButton:it,InspectResultCardMatchList:ot,SkeletonBar:nt,PreviewWaitingPlaceholder:rt};function jc(t){const a={};for(const[s,r]of Object.entries(t))a[s]=P(r);return a}const Sc=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 P(t){if(t==="__noop__")return()=>{};if(t==null||typeof t!="object")return t;if(Array.isArray(t))return t.map(P);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(P));if(t.__type==="ReactNode"){if(typeof t.text=="string")return t.text;if(typeof t.element=="string"){if(!Sc.has(t.element))return null;const s=t.children!=null?P(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,P(n));return s}const a={};for(const[s,r]of Object.entries(t))a[s]=P(r);return a}function Nc(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 Cc=new Set(["EditorShell"]);function wc(t){return t?yc[t]??null:null}function Pc(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 o=wc(n.componentName),i=n.scenarioType==="application"||n.scenarioType==="component"?n.scenarioType:null,l=n.seed??null,c=Nc(n.mocks);if(!o&&n.componentName){s({Component:null,props:{},name:n.name??"",loading:!1,error:`Component "${n.componentName}" not found in registry`,needsRouter:!1,displayHints:null,seed:l,scenarioType:i,hasMocks:c});return}s({Component:o,props:jc(n.props??{}),name:n.name??"",loading:!1,error:null,needsRouter:Cc.has(n.componentName??""),displayHints:n.displayHints??null,seed:l,scenarioType:i,hasMocks:c})}).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 kc({slug:t}){const{Component:a,props:s,name:r,loading:n,error:o,needsRouter:i,displayHints:l,seed:c,scenarioType:p,hasMocks:h}=Pc(t),[b,u]=d.useState(!1),[f,v]=d.useState(null);if(d.useEffect(()=>{if(n)return;let j=!1;return u(!1),v(null),p==="component"&&c==null&&!h?(u(!0),()=>{j=!0}):(fetch("/api/editor-activate-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:t})}).then(async m=>{const x=await m.json().catch(()=>null);j||(x&&(x.seedError||x.success===!1)&&(c!=null?v(x.seedError||x.error||"scenario activation failed"):console.warn("[scenario] activation returned failure for no-seed scenario; ignoring",x)),u(!0))}).catch(m=>{j||(c!=null?v(m instanceof Error?m.message:String(m)):console.warn("[scenario] activation request failed for no-seed scenario; ignoring",m),u(!0))}),()=>{j=!0,fetch("/api/editor-deactivate-scenario",{method:"POST"}).catch(()=>{})})},[t,n,c,p,h]),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(f)return e.jsx(Ae,{error:f});if(o)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:o})]})});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 g=e.jsx(a,{...s});return i?g: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:l!=null&&l.maxWidth?{maxWidth:l.maxWidth}:void 0,children:g})})}export{kc 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};
|