@lunora/studio 1.0.0-alpha.101 → 1.0.0-alpha.102

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.
Files changed (62) hide show
  1. package/dist/standalone/{chunk-LEJV3YKH.js → chunk-22SUVVIR.js} +1 -1
  2. package/dist/standalone/{chunk-C2OHUG2J.js → chunk-35SAF2LS.js} +1 -1
  3. package/dist/standalone/{chunk-F2O4CDVZ.js → chunk-37PXYIVK.js} +1 -1
  4. package/dist/standalone/{chunk-QJQWXV2E.js → chunk-3RC2X4I2.js} +1 -1
  5. package/dist/standalone/{chunk-AYZUNJKK.js → chunk-4KPBTODU.js} +1 -1
  6. package/dist/standalone/{chunk-SDVDPAD2.js → chunk-4PDTGZDC.js} +2 -2
  7. package/dist/standalone/{chunk-6MUFUH3T.js → chunk-4V4RO52I.js} +1 -1
  8. package/dist/standalone/{chunk-6JBWLC63.js → chunk-5BEGIQM7.js} +1 -1
  9. package/dist/standalone/{chunk-KFQXMD7C.js → chunk-5HMBKUFH.js} +1 -1
  10. package/dist/standalone/{chunk-RX5D4SLS.js → chunk-6C6FRIYD.js} +1 -1
  11. package/dist/standalone/{chunk-322ZP3GW.js → chunk-6IZBFC3G.js} +1 -1
  12. package/dist/standalone/{chunk-BUVIRYQM.js → chunk-6THGMZNI.js} +1 -1
  13. package/dist/standalone/{chunk-FSXERBWP.js → chunk-7AY2447G.js} +1 -1
  14. package/dist/standalone/{chunk-BCAPWLLU.js → chunk-7GNNMMT4.js} +1 -1
  15. package/dist/standalone/{chunk-34SDRCH2.js → chunk-7MT6C3FS.js} +1 -1
  16. package/dist/standalone/{chunk-A6ZHBJ76.js → chunk-A3DCTWSA.js} +1 -1
  17. package/dist/standalone/{chunk-M43KO276.js → chunk-APBWFKW5.js} +1 -1
  18. package/dist/standalone/{chunk-FBQNAZHM.js → chunk-B5FMYLVA.js} +1 -1
  19. package/dist/standalone/{chunk-NZZB7PPI.js → chunk-BB7WLC24.js} +1 -1
  20. package/dist/standalone/{chunk-Y7XGNPT6.js → chunk-BCMLQ3LV.js} +1 -1
  21. package/dist/standalone/{chunk-55PVLIN3.js → chunk-BIVP5DZB.js} +1 -1
  22. package/dist/standalone/{chunk-DGRAPESO.js → chunk-DBAMCESO.js} +1 -1
  23. package/dist/standalone/{chunk-GGADAESO.js → chunk-DC23USXJ.js} +1 -1
  24. package/dist/standalone/{chunk-N6DBTBBZ.js → chunk-DSDJ3QRD.js} +1 -1
  25. package/dist/standalone/{chunk-Z4EWPIMU.js → chunk-DY34ZZ5K.js} +1 -1
  26. package/dist/standalone/{chunk-JNYM5V6I.js → chunk-ELI5HREQ.js} +1 -1
  27. package/dist/standalone/{chunk-XAEG372C.js → chunk-ELJZNBBJ.js} +1 -1
  28. package/dist/standalone/{chunk-RTMMB3OY.js → chunk-EWGPDRH3.js} +1 -1
  29. package/dist/standalone/{chunk-DRDGV6G3.js → chunk-G6VZTEGG.js} +1 -1
  30. package/dist/standalone/{chunk-MZ2JNVMR.js → chunk-GRRBUXEI.js} +1 -1
  31. package/dist/standalone/{chunk-F7IRBXWY.js → chunk-GSQDZMV5.js} +1 -1
  32. package/dist/standalone/{chunk-NE4N6I57.js → chunk-IID7VT2A.js} +1 -1
  33. package/dist/standalone/{chunk-PVF5J5UD.js → chunk-IRXDBOOU.js} +1 -1
  34. package/dist/standalone/{chunk-546EVK7X.js → chunk-LKBKYLWK.js} +1 -1
  35. package/dist/standalone/{chunk-UF6XZKV3.js → chunk-LPBWDHKM.js} +1 -1
  36. package/dist/standalone/{chunk-M3NGYXDR.js → chunk-LYVP5PT6.js} +1 -1
  37. package/dist/standalone/{chunk-WMLKVJUX.js → chunk-MRK53LUL.js} +1 -1
  38. package/dist/standalone/{chunk-H23VFWFW.js → chunk-NH4HJFG3.js} +1 -1
  39. package/dist/standalone/{chunk-KG6FVK5P.js → chunk-NLHEYDAA.js} +1 -1
  40. package/dist/standalone/{chunk-GVSKCIJR.js → chunk-NLWDTGEP.js} +1 -1
  41. package/dist/standalone/{chunk-ZKPKUHTX.js → chunk-OHOWUEQ3.js} +1 -1
  42. package/dist/standalone/{chunk-DBYTTQBC.js → chunk-ORNIQZ2P.js} +1 -1
  43. package/dist/standalone/{chunk-ZMYRKEA6.js → chunk-PCAI3G4M.js} +1 -1
  44. package/dist/standalone/{chunk-V76WCOMM.js → chunk-QJW2Z3SI.js} +1 -1
  45. package/dist/standalone/{chunk-OZ4CUX5O.js → chunk-RO6LEET3.js} +1 -1
  46. package/dist/standalone/{chunk-O6XSMU4X.js → chunk-RTXAZLAE.js} +1 -1
  47. package/dist/standalone/{chunk-CKPKUMYJ.js → chunk-T6YGEL6X.js} +1 -1
  48. package/dist/standalone/{chunk-B2QO6Q52.js → chunk-TFSGDOCG.js} +1 -1
  49. package/dist/standalone/{chunk-FKAUVTSS.js → chunk-TQEVFVNP.js} +1 -1
  50. package/dist/standalone/{chunk-2LU3W7JY.js → chunk-U4THUBUT.js} +1 -1
  51. package/dist/standalone/{chunk-4HNNNIDW.js → chunk-U62QRT34.js} +1 -1
  52. package/dist/standalone/{chunk-SO52T6RL.js → chunk-UALL2OBT.js} +1 -1
  53. package/dist/standalone/{chunk-BQNVN2OD.js → chunk-UP7OTXKF.js} +1 -1
  54. package/dist/standalone/{chunk-GR62EIAU.js → chunk-W3VOX7VR.js} +1 -1
  55. package/dist/standalone/{chunk-NBZH4PVA.js → chunk-W3XKLUWQ.js} +1 -1
  56. package/dist/standalone/{chunk-6UPCJAAI.js → chunk-WMBDXCYL.js} +1 -1
  57. package/dist/standalone/{chunk-YC52XCPK.js → chunk-X7B6PLEW.js} +4 -4
  58. package/dist/standalone/{chunk-K3PSOZXH.js → chunk-YZ7OINPX.js} +1 -1
  59. package/dist/standalone/{chunk-HGSIVV32.js → chunk-ZMDNTTAC.js} +1 -1
  60. package/dist/standalone/{chunk-P4BOVBMR.js → chunk-ZNNKWEH5.js} +1 -1
  61. package/dist/standalone/studio.js +1 -1
  62. package/package.json +6 -6
@@ -1 +1 @@
1
- import{a as te}from"./chunk-V53KNYRN.js";import{R as Z}from"./chunk-CFPZYHPY.js";import"./chunk-7QIFDWQV.js";import{a as I}from"./chunk-MWIKAR7F.js";import"./chunk-DJZYD5I5.js";import"./chunk-2OUPA2WJ.js";import"./chunk-6ST5ECQA.js";import{a as K}from"./chunk-VDW32UET.js";import{c as ee}from"./chunk-BQNVN2OD.js";import{f as M}from"./chunk-M3NGYXDR.js";import"./chunk-XBDKZZ67.js";import{a as q}from"./chunk-XQCVZAGU.js";import{a as z,b as D,c as F,d as h,e as o,f as i}from"./chunk-WJQLNYGX.js";import{a as T,e as j}from"./chunk-WQH3LT2P.js";import{d as H,f as Q,g as V,h as W,o as $}from"./chunk-IUYFXK4X.js";import"./chunk-YC52XCPK.js";import{a as n,e as Y,f as ne,h as le}from"./chunk-3XIESWL4.js";var c=Y(ne(),1);var e=Y(le(),1);var oe=["queued","running","paused","waiting","complete","errored","terminated"],ie=["pause","resume","terminate"],de="WORKFLOWS_NOT_CONFIGURED",ce=n(l=>typeof l=="object"&&l!==null&&l.code===de,"ie"),me=n(l=>{let r=l.error??l.output;if(r===void 0)return"\u2014";try{return JSON.stringify(r)}catch{return"(unserializable)"}},"de"),ue=n(({loadDetail:l,loadInstances:r,readOnly:N,runAction:R,workflowName:g})=>{let A=M(),s=H(),[p,k]=(0,c.useState)(null),[S,O]=(0,c.useState)(null),[v,_]=(0,c.useState)(""),[b,f]=(0,c.useState)(null),[J,C]=(0,c.useState)(!1),[L,P]=(0,c.useState)(null),w=l??(a=>A.getWorkflowInstance(a)),x=N?void 0:R??(r===void 0?a=>A.setWorkflowInstanceStatus(a):void 0),E=n(async()=>{f(null),C(!1);let a=v===""?void 0:v;try{if(r===void 0){let d=await A.listWorkflowInstances({name:g,status:a});if(d.configured===!1){k(null),C(!0);return}k(d.instances);return}k(await r({name:g,status:a}))}catch(d){k(null),ce(d)?C(!0):f(W(d))}},"O");(0,c.useEffect)(()=>{O(null),$(E())},[g,v]);let U=n(async a=>{f(null);try{O(await w({id:a,name:g}))}catch(d){f(W(d))}},"D"),B=n(async(a,d)=>{if(x!==void 0){P(a),f(null);try{await x({action:d,id:a,name:g}),await E()}catch(G){f(W(G))}P(null)}},"K");return(0,e.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"lunora-workflow-instances",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsx)("h3",{className:"text-sm font-medium",children:s("Instance history")}),(0,e.jsxs)("select",{"aria-label":s("Filter by status"),className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"workflow-instances-filter",onChange:n(a=>{_(a.target.value)},"onChange"),value:v,children:[(0,e.jsx)("option",{value:"",children:s("All statuses")}),oe.map(a=>(0,e.jsx)("option",{value:a,children:a},a))]})]}),b!==null&&(0,e.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflow-instances-error",role:"alert",children:b}),J&&(0,e.jsx)(q,{description:s("Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN in your .dev.vars to enable workflow instance history."),testId:"workflow-instances-unconfigured",title:s("Workflow inspection not configured")}),!J&&p!==null&&p.length===0&&(0,e.jsx)(q,{description:s("No instances match this filter for the selected workflow."),testId:"workflow-instances-empty",title:s("No instances")}),p!==null&&p.length>0&&(0,e.jsx)(T,{className:"overflow-hidden py-0",children:(0,e.jsx)(j,{className:"px-0",children:(0,e.jsxs)(z,{"data-testid":"workflow-instances-table",children:[(0,e.jsx)(D,{children:(0,e.jsxs)(h,{children:[(0,e.jsx)(o,{children:s("Instance id")}),(0,e.jsx)(o,{children:s("Status")}),(0,e.jsx)(o,{children:s("Created")}),(0,e.jsx)(o,{children:s("Ended")}),(0,e.jsx)(o,{"aria-label":s("Actions")})]})}),(0,e.jsx)(F,{children:p.map(a=>(0,e.jsxs)(h,{"data-testid":`workflow-instance-${a.id}`,children:[(0,e.jsx)(i,{className:"font-mono text-xs",children:a.id}),(0,e.jsx)(i,{className:"font-mono text-xs",children:a.status}),(0,e.jsx)(i,{className:"text-muted-foreground tabular-nums",children:a.createdOn??"\u2014"}),(0,e.jsx)(i,{className:"text-muted-foreground tabular-nums",children:a.endedOn??"\u2014"}),(0,e.jsx)(i,{className:"text-right",children:(0,e.jsxs)("div",{className:"flex justify-end gap-1.5",children:[(0,e.jsx)(I,{"data-testid":`workflow-instance-steps-${a.id}`,onClick:n(()=>{$(U(a.id))},"onClick"),size:"sm",type:"button",variant:"outline",children:s("Steps")}),x!==void 0&&ie.map(d=>(0,e.jsx)(I,{"data-testid":`workflow-instance-${d}-${a.id}`,disabled:L===a.id,onClick:n(()=>{$(B(a.id,d))},"onClick"),size:"sm",type:"button",variant:"ghost",children:s(d)},d))]})})]},a.id))})]})})}),S!==null&&(0,e.jsx)(T,{className:"overflow-hidden py-0","data-testid":"workflow-instance-detail",children:(0,e.jsxs)(j,{className:"flex flex-col gap-2 px-4 py-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("span",{className:"font-mono text-xs",children:[s("Steps")," \xB7 ",S.id]}),(0,e.jsx)(I,{"data-testid":"workflow-instance-detail-close",onClick:n(()=>{O(null)},"onClick"),size:"xs",type:"button",variant:"ghost",children:s("Close")})]}),S.steps.length===0?(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:s("This instance has no recorded steps yet.")}):(0,e.jsxs)(z,{"data-testid":"workflow-instance-steps",children:[(0,e.jsx)(D,{children:(0,e.jsxs)(h,{children:[(0,e.jsx)(o,{children:s("Step")}),(0,e.jsx)(o,{children:s("Type")}),(0,e.jsx)(o,{children:s("Attempts")}),(0,e.jsx)(o,{children:s("Started")}),(0,e.jsx)(o,{children:s("Output")})]})}),(0,e.jsx)(F,{children:S.steps.map((a,d)=>(0,e.jsxs)(h,{"data-testid":`workflow-step-${String(d)}`,children:[(0,e.jsx)(i,{className:"font-mono text-xs",children:a.name}),(0,e.jsx)(i,{className:"text-xs text-muted-foreground",children:a.type??"\u2014"}),(0,e.jsx)(i,{className:"tabular-nums",children:a.attempts??"\u2014"}),(0,e.jsx)(i,{className:"text-muted-foreground tabular-nums",children:a.start??"\u2014"}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:me(a)})]},`${a.name}:${String(d)}`))})]})]})})]})},"ce"),fe=Q(K.createWorkflowInstance),he=Q(K.getWorkflowInstanceStatus),pe=n(l=>{if(l.error)return`${l.error.name}: ${l.error.message}`;if(l.output===void 0)return"\u2014";try{return JSON.stringify(l.output)}catch{return"(unserializable)"}},"fe"),we=n((l,r)=>l.some(N=>N.exportName===r)?r:l[0]?.exportName??"","he"),We=n(()=>{let l=M(),r=H(),{data:N,error:R}=ee(K.listWorkflows,{}),[g,A]=(0,c.useState)(""),[s,p]=(0,c.useState)(""),[k,S]=(0,c.useState)(""),[O,v]=(0,c.useState)(!1),[_,b]=(0,c.useState)(null),[f,J]=(0,c.useState)([]),[C,L]=(0,c.useState)(null),P=N!==void 0,w=Array.isArray(N?.workflows)?[...N.workflows].toSorted((t,u)=>t.exportName.localeCompare(u.exportName)):[],x=we(w,g),E=w.find(t=>t.exportName===x),U=n(t=>{J(u=>{let m=u.filter(y=>!(y.exportName===t.exportName&&y.id===t.id));return[t,...m]})},"D"),B=n(async()=>{let t=x;if(t==="")return;let u,m=k.trim();if(m!=="")try{u=JSON.parse(m)}catch{b(r("Params must be valid JSON"));return}v(!0),b(null);try{let y=s.trim(),X=await l.query(fe,{exportName:t,id:y===""?void 0:y,params:u},V(""));U({exportName:t,id:X.id,status:X.status}),p("")}catch(y){b(W(y))}v(!1)},"K"),a=n(()=>{$(B())},"a"),d=n(async(t,u)=>{L(u);try{let m=await l.query(he,{exportName:t,id:u},V(""));U({error:m.error,exportName:t,id:m.id,output:m.output,status:m.status})}catch(m){b(W(m))}L(null)},"l"),G=n(t=>{A(t.target.value)},"P"),ae=n(t=>{p(t.target.value)},"Y"),re=n(t=>{S(t.target.value)},"Z"),se=n(t=>{let{export:u,id:m}=t.currentTarget.dataset;u!==void 0&&m!==void 0&&$(d(u,m))},"ee");return(0,e.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-workflows-panel",children:[R!==null&&(0,e.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflows-error",role:"alert",children:R}),(0,e.jsx)("p",{className:"text-sm text-muted-foreground",children:r("Workflows are declared in code with defineWorkflow and run as durable Cloudflare Workflows. Start an instance and observe its status below.")}),P&&w.length===0?(0,e.jsx)(q,{description:r("No defineWorkflow is declared in lunora/workflows.ts in this deployment. Add one to run a durable, multi-step workflow."),testId:"workflows-empty",title:r("No workflows defined")}):(0,e.jsx)(T,{className:"overflow-hidden py-0",children:(0,e.jsx)(j,{className:"px-0",children:(0,e.jsxs)(z,{"data-testid":"workflows-table",children:[(0,e.jsx)(D,{children:(0,e.jsxs)(h,{children:[(0,e.jsx)(o,{children:r("Export")}),(0,e.jsx)(o,{children:r("Name")}),(0,e.jsx)(o,{children:r("Class")}),(0,e.jsx)(o,{children:r("Binding")})]})}),(0,e.jsx)(F,{children:w.map(t=>(0,e.jsxs)(h,{"data-testid":`workflows-row-${t.exportName}`,children:[(0,e.jsx)(i,{className:"font-mono text-xs",children:t.exportName}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:t.name}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:t.className}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:t.binding})]},t.exportName))})]})})}),w.length>0&&(0,e.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"workflows-start",children:[(0,e.jsx)("h3",{className:"text-sm font-medium",children:r("Start instance")}),_!==null&&(0,e.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflows-start-error",role:"alert",children:_}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsx)("select",{"aria-label":r("Workflow"),className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"workflows-start-select",onChange:G,value:x,children:w.map(t=>(0,e.jsx)("option",{value:t.exportName,children:t.exportName},t.exportName))}),(0,e.jsx)(Z,{"aria-label":r("Instance id (optional)"),className:"max-w-48","data-testid":"workflows-start-id",onChange:ae,placeholder:r("Instance id (optional)"),value:s}),(0,e.jsx)(I,{"data-testid":"workflows-start-button",disabled:O||x==="",onClick:a,children:r(O?"Starting\u2026":"Start instance")})]}),(0,e.jsx)(te,{"aria-label":r("Params (JSON)"),className:"font-mono","data-testid":"workflows-start-params",onChange:re,placeholder:r("Params (JSON, optional)"),value:k})]}),f.length>0&&(0,e.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"workflows-instances",children:[(0,e.jsx)("h3",{className:"text-sm font-medium",children:r("Instances")}),(0,e.jsx)(T,{className:"overflow-hidden py-0",children:(0,e.jsx)(j,{className:"px-0",children:(0,e.jsxs)(z,{"data-testid":"workflows-instances-table",children:[(0,e.jsx)(D,{children:(0,e.jsxs)(h,{children:[(0,e.jsx)(o,{children:r("Workflow")}),(0,e.jsx)(o,{children:r("Instance id")}),(0,e.jsx)(o,{children:r("Status")}),(0,e.jsx)(o,{children:r("Output")}),(0,e.jsx)(o,{})]})}),(0,e.jsx)(F,{children:f.map(t=>(0,e.jsxs)(h,{"data-testid":`workflows-instance-${t.id}`,children:[(0,e.jsx)(i,{className:"font-mono text-xs",children:t.exportName}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:t.id}),(0,e.jsx)(i,{className:"font-mono text-xs",children:t.status}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:pe(t)}),(0,e.jsx)(i,{children:(0,e.jsx)(I,{"data-export":t.exportName,"data-id":t.id,"data-testid":`workflows-instance-refresh-${t.id}`,disabled:C===t.id,onClick:se,size:"xs",variant:"outline",children:C===t.id?r("Refreshing\u2026"):r("Refresh")})})]},`${t.exportName}:${t.id}`))})]})})})]}),E!==void 0&&(0,e.jsx)(ue,{workflowName:E.name})]})},"Oe");export{We as default};
1
+ import{a as te}from"./chunk-V53KNYRN.js";import{R as Z}from"./chunk-CFPZYHPY.js";import"./chunk-7QIFDWQV.js";import{a as I}from"./chunk-MWIKAR7F.js";import"./chunk-DJZYD5I5.js";import"./chunk-2OUPA2WJ.js";import"./chunk-6ST5ECQA.js";import{a as K}from"./chunk-VDW32UET.js";import{c as ee}from"./chunk-UP7OTXKF.js";import{f as M}from"./chunk-LYVP5PT6.js";import"./chunk-XBDKZZ67.js";import{a as q}from"./chunk-XQCVZAGU.js";import{a as z,b as D,c as F,d as h,e as o,f as i}from"./chunk-WJQLNYGX.js";import{a as T,e as j}from"./chunk-WQH3LT2P.js";import{d as H,f as Q,g as V,h as W,o as $}from"./chunk-IUYFXK4X.js";import"./chunk-X7B6PLEW.js";import{a as n,e as Y,f as ne,h as le}from"./chunk-3XIESWL4.js";var c=Y(ne(),1);var e=Y(le(),1);var oe=["queued","running","paused","waiting","complete","errored","terminated"],ie=["pause","resume","terminate"],de="WORKFLOWS_NOT_CONFIGURED",ce=n(l=>typeof l=="object"&&l!==null&&l.code===de,"ie"),me=n(l=>{let r=l.error??l.output;if(r===void 0)return"\u2014";try{return JSON.stringify(r)}catch{return"(unserializable)"}},"de"),ue=n(({loadDetail:l,loadInstances:r,readOnly:N,runAction:R,workflowName:g})=>{let A=M(),s=H(),[p,k]=(0,c.useState)(null),[S,O]=(0,c.useState)(null),[v,_]=(0,c.useState)(""),[b,f]=(0,c.useState)(null),[J,C]=(0,c.useState)(!1),[L,P]=(0,c.useState)(null),w=l??(a=>A.getWorkflowInstance(a)),x=N?void 0:R??(r===void 0?a=>A.setWorkflowInstanceStatus(a):void 0),E=n(async()=>{f(null),C(!1);let a=v===""?void 0:v;try{if(r===void 0){let d=await A.listWorkflowInstances({name:g,status:a});if(d.configured===!1){k(null),C(!0);return}k(d.instances);return}k(await r({name:g,status:a}))}catch(d){k(null),ce(d)?C(!0):f(W(d))}},"O");(0,c.useEffect)(()=>{O(null),$(E())},[g,v]);let U=n(async a=>{f(null);try{O(await w({id:a,name:g}))}catch(d){f(W(d))}},"D"),B=n(async(a,d)=>{if(x!==void 0){P(a),f(null);try{await x({action:d,id:a,name:g}),await E()}catch(G){f(W(G))}P(null)}},"K");return(0,e.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"lunora-workflow-instances",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsx)("h3",{className:"text-sm font-medium",children:s("Instance history")}),(0,e.jsxs)("select",{"aria-label":s("Filter by status"),className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"workflow-instances-filter",onChange:n(a=>{_(a.target.value)},"onChange"),value:v,children:[(0,e.jsx)("option",{value:"",children:s("All statuses")}),oe.map(a=>(0,e.jsx)("option",{value:a,children:a},a))]})]}),b!==null&&(0,e.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflow-instances-error",role:"alert",children:b}),J&&(0,e.jsx)(q,{description:s("Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN in your .dev.vars to enable workflow instance history."),testId:"workflow-instances-unconfigured",title:s("Workflow inspection not configured")}),!J&&p!==null&&p.length===0&&(0,e.jsx)(q,{description:s("No instances match this filter for the selected workflow."),testId:"workflow-instances-empty",title:s("No instances")}),p!==null&&p.length>0&&(0,e.jsx)(T,{className:"overflow-hidden py-0",children:(0,e.jsx)(j,{className:"px-0",children:(0,e.jsxs)(z,{"data-testid":"workflow-instances-table",children:[(0,e.jsx)(D,{children:(0,e.jsxs)(h,{children:[(0,e.jsx)(o,{children:s("Instance id")}),(0,e.jsx)(o,{children:s("Status")}),(0,e.jsx)(o,{children:s("Created")}),(0,e.jsx)(o,{children:s("Ended")}),(0,e.jsx)(o,{"aria-label":s("Actions")})]})}),(0,e.jsx)(F,{children:p.map(a=>(0,e.jsxs)(h,{"data-testid":`workflow-instance-${a.id}`,children:[(0,e.jsx)(i,{className:"font-mono text-xs",children:a.id}),(0,e.jsx)(i,{className:"font-mono text-xs",children:a.status}),(0,e.jsx)(i,{className:"text-muted-foreground tabular-nums",children:a.createdOn??"\u2014"}),(0,e.jsx)(i,{className:"text-muted-foreground tabular-nums",children:a.endedOn??"\u2014"}),(0,e.jsx)(i,{className:"text-right",children:(0,e.jsxs)("div",{className:"flex justify-end gap-1.5",children:[(0,e.jsx)(I,{"data-testid":`workflow-instance-steps-${a.id}`,onClick:n(()=>{$(U(a.id))},"onClick"),size:"sm",type:"button",variant:"outline",children:s("Steps")}),x!==void 0&&ie.map(d=>(0,e.jsx)(I,{"data-testid":`workflow-instance-${d}-${a.id}`,disabled:L===a.id,onClick:n(()=>{$(B(a.id,d))},"onClick"),size:"sm",type:"button",variant:"ghost",children:s(d)},d))]})})]},a.id))})]})})}),S!==null&&(0,e.jsx)(T,{className:"overflow-hidden py-0","data-testid":"workflow-instance-detail",children:(0,e.jsxs)(j,{className:"flex flex-col gap-2 px-4 py-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("span",{className:"font-mono text-xs",children:[s("Steps")," \xB7 ",S.id]}),(0,e.jsx)(I,{"data-testid":"workflow-instance-detail-close",onClick:n(()=>{O(null)},"onClick"),size:"xs",type:"button",variant:"ghost",children:s("Close")})]}),S.steps.length===0?(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:s("This instance has no recorded steps yet.")}):(0,e.jsxs)(z,{"data-testid":"workflow-instance-steps",children:[(0,e.jsx)(D,{children:(0,e.jsxs)(h,{children:[(0,e.jsx)(o,{children:s("Step")}),(0,e.jsx)(o,{children:s("Type")}),(0,e.jsx)(o,{children:s("Attempts")}),(0,e.jsx)(o,{children:s("Started")}),(0,e.jsx)(o,{children:s("Output")})]})}),(0,e.jsx)(F,{children:S.steps.map((a,d)=>(0,e.jsxs)(h,{"data-testid":`workflow-step-${String(d)}`,children:[(0,e.jsx)(i,{className:"font-mono text-xs",children:a.name}),(0,e.jsx)(i,{className:"text-xs text-muted-foreground",children:a.type??"\u2014"}),(0,e.jsx)(i,{className:"tabular-nums",children:a.attempts??"\u2014"}),(0,e.jsx)(i,{className:"text-muted-foreground tabular-nums",children:a.start??"\u2014"}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:me(a)})]},`${a.name}:${String(d)}`))})]})]})})]})},"ce"),fe=Q(K.createWorkflowInstance),he=Q(K.getWorkflowInstanceStatus),pe=n(l=>{if(l.error)return`${l.error.name}: ${l.error.message}`;if(l.output===void 0)return"\u2014";try{return JSON.stringify(l.output)}catch{return"(unserializable)"}},"fe"),we=n((l,r)=>l.some(N=>N.exportName===r)?r:l[0]?.exportName??"","he"),We=n(()=>{let l=M(),r=H(),{data:N,error:R}=ee(K.listWorkflows,{}),[g,A]=(0,c.useState)(""),[s,p]=(0,c.useState)(""),[k,S]=(0,c.useState)(""),[O,v]=(0,c.useState)(!1),[_,b]=(0,c.useState)(null),[f,J]=(0,c.useState)([]),[C,L]=(0,c.useState)(null),P=N!==void 0,w=Array.isArray(N?.workflows)?[...N.workflows].toSorted((t,u)=>t.exportName.localeCompare(u.exportName)):[],x=we(w,g),E=w.find(t=>t.exportName===x),U=n(t=>{J(u=>{let m=u.filter(y=>!(y.exportName===t.exportName&&y.id===t.id));return[t,...m]})},"D"),B=n(async()=>{let t=x;if(t==="")return;let u,m=k.trim();if(m!=="")try{u=JSON.parse(m)}catch{b(r("Params must be valid JSON"));return}v(!0),b(null);try{let y=s.trim(),X=await l.query(fe,{exportName:t,id:y===""?void 0:y,params:u},V(""));U({exportName:t,id:X.id,status:X.status}),p("")}catch(y){b(W(y))}v(!1)},"K"),a=n(()=>{$(B())},"a"),d=n(async(t,u)=>{L(u);try{let m=await l.query(he,{exportName:t,id:u},V(""));U({error:m.error,exportName:t,id:m.id,output:m.output,status:m.status})}catch(m){b(W(m))}L(null)},"l"),G=n(t=>{A(t.target.value)},"P"),ae=n(t=>{p(t.target.value)},"Y"),re=n(t=>{S(t.target.value)},"Z"),se=n(t=>{let{export:u,id:m}=t.currentTarget.dataset;u!==void 0&&m!==void 0&&$(d(u,m))},"ee");return(0,e.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-workflows-panel",children:[R!==null&&(0,e.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflows-error",role:"alert",children:R}),(0,e.jsx)("p",{className:"text-sm text-muted-foreground",children:r("Workflows are declared in code with defineWorkflow and run as durable Cloudflare Workflows. Start an instance and observe its status below.")}),P&&w.length===0?(0,e.jsx)(q,{description:r("No defineWorkflow is declared in lunora/workflows.ts in this deployment. Add one to run a durable, multi-step workflow."),testId:"workflows-empty",title:r("No workflows defined")}):(0,e.jsx)(T,{className:"overflow-hidden py-0",children:(0,e.jsx)(j,{className:"px-0",children:(0,e.jsxs)(z,{"data-testid":"workflows-table",children:[(0,e.jsx)(D,{children:(0,e.jsxs)(h,{children:[(0,e.jsx)(o,{children:r("Export")}),(0,e.jsx)(o,{children:r("Name")}),(0,e.jsx)(o,{children:r("Class")}),(0,e.jsx)(o,{children:r("Binding")})]})}),(0,e.jsx)(F,{children:w.map(t=>(0,e.jsxs)(h,{"data-testid":`workflows-row-${t.exportName}`,children:[(0,e.jsx)(i,{className:"font-mono text-xs",children:t.exportName}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:t.name}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:t.className}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:t.binding})]},t.exportName))})]})})}),w.length>0&&(0,e.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"workflows-start",children:[(0,e.jsx)("h3",{className:"text-sm font-medium",children:r("Start instance")}),_!==null&&(0,e.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflows-start-error",role:"alert",children:_}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsx)("select",{"aria-label":r("Workflow"),className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"workflows-start-select",onChange:G,value:x,children:w.map(t=>(0,e.jsx)("option",{value:t.exportName,children:t.exportName},t.exportName))}),(0,e.jsx)(Z,{"aria-label":r("Instance id (optional)"),className:"max-w-48","data-testid":"workflows-start-id",onChange:ae,placeholder:r("Instance id (optional)"),value:s}),(0,e.jsx)(I,{"data-testid":"workflows-start-button",disabled:O||x==="",onClick:a,children:r(O?"Starting\u2026":"Start instance")})]}),(0,e.jsx)(te,{"aria-label":r("Params (JSON)"),className:"font-mono","data-testid":"workflows-start-params",onChange:re,placeholder:r("Params (JSON, optional)"),value:k})]}),f.length>0&&(0,e.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"workflows-instances",children:[(0,e.jsx)("h3",{className:"text-sm font-medium",children:r("Instances")}),(0,e.jsx)(T,{className:"overflow-hidden py-0",children:(0,e.jsx)(j,{className:"px-0",children:(0,e.jsxs)(z,{"data-testid":"workflows-instances-table",children:[(0,e.jsx)(D,{children:(0,e.jsxs)(h,{children:[(0,e.jsx)(o,{children:r("Workflow")}),(0,e.jsx)(o,{children:r("Instance id")}),(0,e.jsx)(o,{children:r("Status")}),(0,e.jsx)(o,{children:r("Output")}),(0,e.jsx)(o,{})]})}),(0,e.jsx)(F,{children:f.map(t=>(0,e.jsxs)(h,{"data-testid":`workflows-instance-${t.id}`,children:[(0,e.jsx)(i,{className:"font-mono text-xs",children:t.exportName}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:t.id}),(0,e.jsx)(i,{className:"font-mono text-xs",children:t.status}),(0,e.jsx)(i,{className:"font-mono text-xs text-muted-foreground",children:pe(t)}),(0,e.jsx)(i,{children:(0,e.jsx)(I,{"data-export":t.exportName,"data-id":t.id,"data-testid":`workflows-instance-refresh-${t.id}`,disabled:C===t.id,onClick:se,size:"xs",variant:"outline",children:C===t.id?r("Refreshing\u2026"):r("Refresh")})})]},`${t.exportName}:${t.id}`))})]})})})]}),E!==void 0&&(0,e.jsx)(ue,{workflowName:E.name})]})},"Oe");export{We as default};
@@ -1 +1 @@
1
- import{a as O}from"./chunk-IGCNMZSB.js";import{b as C}from"./chunk-THIXMMZD.js";import"./chunk-6ST5ECQA.js";import"./chunk-QLQADHFE.js";import{a as L}from"./chunk-VDW32UET.js";import{c as $}from"./chunk-BQNVN2OD.js";import"./chunk-M3NGYXDR.js";import"./chunk-XBDKZZ67.js";import{a as I}from"./chunk-XQCVZAGU.js";import{a as k,b as A,c as D,d as g,e as c,f as l}from"./chunk-WJQLNYGX.js";import{a as b,e as S}from"./chunk-WQH3LT2P.js";import{d as w}from"./chunk-IUYFXK4X.js";import"./chunk-YC52XCPK.js";import{a as p,e as y,g as j,h as E}from"./chunk-3XIESWL4.js";var _=y(j(),1);var t=y(E(),1);var T="container:",M={error:"error",sleep:"sleeping",start:"running",stop:"stopped"},W=p(e=>{let n=e.indexOf(":");if(n===-1)return{event:e.trim()};let r=e.slice(n+1).trim(),a=e.slice(0,n).trim();return r===""?{event:a}:{detail:r,event:a}},"_"),B=p(e=>{let n=new Map;for(let r of e){let a=r.functionPath??"";if(!a.startsWith(T))continue;let i=a.slice(T.length);if(i==="")continue;let s=JSON.stringify([i,r.instance??""]),o=n.get(s);if(o!==void 0&&o.timestamp>=r.timestamp)continue;let{detail:u,event:d}=W(r.message);n.set(s,{detail:u,event:d,exitCode:r.exitCode,instance:r.instance,level:r.level,name:i,state:M[d]??"unknown",timestamp:r.timestamp})}return[...n.values()].toSorted((r,a)=>r.name.localeCompare(a.name)||(r.instance??"").localeCompare(a.instance??""))},"j"),F={error:"destructive",running:"success",sleeping:"info",stopped:"outline",unknown:"secondary"},H=p(e=>{let{entries:n}=e??{};return Array.isArray(n)?n:[]},"W"),V=p(()=>{let e=(0,_.c)(19),n=w(),r,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},a={live:!0,shardKey:""},e[0]=r,e[1]=a):(r=e[0],a=e[1]);let{data:i,error:s,liveError:o}=$(L.getLogs,r,a),u=i!==void 0,d;if(e[2]!==i||e[3]!==s||e[4]!==o||e[5]!==u||e[6]!==n){let N=B(H(i)),x;e[8]!==s?(x=s!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"containers-error",role:"alert",children:s}),e[8]=s,e[9]=x):x=e[9];let m;e[10]!==n?(m=n("Cloudflare Containers are observed from their lifecycle log stream. This shows the current state per instance \u2014 ports and health checks aren't carried in that stream."),e[10]=n,e[11]=m):m=e[11];let f;e[12]!==m?(f=(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:m}),e[12]=m,e[13]=f):f=e[13];let h;e[14]!==o?(h=(0,t.jsx)(O,{message:o,prefix:"containers"}),e[14]=o,e[15]=h):h=e[15];let v;e[16]!==f||e[17]!==h?(v=(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[f,h]}),e[16]=f,e[17]=h,e[18]=v):v=e[18],d=(0,t.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-containers-panel",children:[x,v,u&&N.length===0?(0,t.jsx)(I,{description:n("No container lifecycle activity yet. Instances declared with defineContainer show up here once they start, sleep, stop, or error."),testId:"containers-empty",title:n("No container activity")}):(0,t.jsx)(b,{className:"overflow-hidden py-0",children:(0,t.jsx)(S,{className:"px-0",children:(0,t.jsxs)(k,{"data-testid":"containers-table",children:[(0,t.jsx)(A,{children:(0,t.jsxs)(g,{children:[(0,t.jsx)(c,{children:n("Container")}),(0,t.jsx)(c,{children:n("Instance")}),(0,t.jsx)(c,{children:n("State")}),(0,t.jsx)(c,{children:n("Last event")}),(0,t.jsx)(c,{children:n("Detail")}),(0,t.jsx)(c,{children:n("Exit")}),(0,t.jsx)(c,{children:n("When")})]})}),(0,t.jsx)(D,{children:N.map(J)})]})})})]}),e[2]=i,e[3]=s,e[4]=o,e[5]=u,e[6]=n,e[7]=d}else d=e[7];return d},"H");function J(e){return(0,t.jsxs)(g,{"data-testid":`containers-row-${e.name}${e.instance===void 0?"":`-${e.instance}`}`,children:[(0,t.jsx)(l,{className:"font-mono text-xs",children:e.name}),(0,t.jsx)(l,{className:"max-w-40 truncate font-mono text-xs text-muted-foreground",title:e.instance,children:e.instance??"\u2014"}),(0,t.jsx)(l,{children:(0,t.jsx)(C,{variant:F[e.state],children:e.state})}),(0,t.jsx)(l,{className:"font-mono text-xs text-muted-foreground",children:e.event}),(0,t.jsx)(l,{className:"max-w-64 truncate text-xs text-muted-foreground",title:e.detail,children:e.detail??"\u2014"}),(0,t.jsx)(l,{className:"font-mono text-xs tabular-nums text-muted-foreground",children:e.exitCode??"\u2014"}),(0,t.jsx)(l,{className:"text-xs tabular-nums text-muted-foreground",children:new Date(e.timestamp).toLocaleString()})]},`${e.name}/${e.instance??""}`)}p(J,"B");export{V as default};
1
+ import{a as O}from"./chunk-IGCNMZSB.js";import{b as C}from"./chunk-THIXMMZD.js";import"./chunk-6ST5ECQA.js";import"./chunk-QLQADHFE.js";import{a as L}from"./chunk-VDW32UET.js";import{c as $}from"./chunk-UP7OTXKF.js";import"./chunk-LYVP5PT6.js";import"./chunk-XBDKZZ67.js";import{a as I}from"./chunk-XQCVZAGU.js";import{a as k,b as A,c as D,d as g,e as c,f as l}from"./chunk-WJQLNYGX.js";import{a as b,e as S}from"./chunk-WQH3LT2P.js";import{d as w}from"./chunk-IUYFXK4X.js";import"./chunk-X7B6PLEW.js";import{a as p,e as y,g as j,h as E}from"./chunk-3XIESWL4.js";var _=y(j(),1);var t=y(E(),1);var T="container:",M={error:"error",sleep:"sleeping",start:"running",stop:"stopped"},W=p(e=>{let n=e.indexOf(":");if(n===-1)return{event:e.trim()};let r=e.slice(n+1).trim(),a=e.slice(0,n).trim();return r===""?{event:a}:{detail:r,event:a}},"_"),B=p(e=>{let n=new Map;for(let r of e){let a=r.functionPath??"";if(!a.startsWith(T))continue;let i=a.slice(T.length);if(i==="")continue;let s=JSON.stringify([i,r.instance??""]),o=n.get(s);if(o!==void 0&&o.timestamp>=r.timestamp)continue;let{detail:u,event:d}=W(r.message);n.set(s,{detail:u,event:d,exitCode:r.exitCode,instance:r.instance,level:r.level,name:i,state:M[d]??"unknown",timestamp:r.timestamp})}return[...n.values()].toSorted((r,a)=>r.name.localeCompare(a.name)||(r.instance??"").localeCompare(a.instance??""))},"j"),F={error:"destructive",running:"success",sleeping:"info",stopped:"outline",unknown:"secondary"},H=p(e=>{let{entries:n}=e??{};return Array.isArray(n)?n:[]},"W"),V=p(()=>{let e=(0,_.c)(19),n=w(),r,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},a={live:!0,shardKey:""},e[0]=r,e[1]=a):(r=e[0],a=e[1]);let{data:i,error:s,liveError:o}=$(L.getLogs,r,a),u=i!==void 0,d;if(e[2]!==i||e[3]!==s||e[4]!==o||e[5]!==u||e[6]!==n){let N=B(H(i)),x;e[8]!==s?(x=s!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"containers-error",role:"alert",children:s}),e[8]=s,e[9]=x):x=e[9];let m;e[10]!==n?(m=n("Cloudflare Containers are observed from their lifecycle log stream. This shows the current state per instance \u2014 ports and health checks aren't carried in that stream."),e[10]=n,e[11]=m):m=e[11];let f;e[12]!==m?(f=(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:m}),e[12]=m,e[13]=f):f=e[13];let h;e[14]!==o?(h=(0,t.jsx)(O,{message:o,prefix:"containers"}),e[14]=o,e[15]=h):h=e[15];let v;e[16]!==f||e[17]!==h?(v=(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[f,h]}),e[16]=f,e[17]=h,e[18]=v):v=e[18],d=(0,t.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-containers-panel",children:[x,v,u&&N.length===0?(0,t.jsx)(I,{description:n("No container lifecycle activity yet. Instances declared with defineContainer show up here once they start, sleep, stop, or error."),testId:"containers-empty",title:n("No container activity")}):(0,t.jsx)(b,{className:"overflow-hidden py-0",children:(0,t.jsx)(S,{className:"px-0",children:(0,t.jsxs)(k,{"data-testid":"containers-table",children:[(0,t.jsx)(A,{children:(0,t.jsxs)(g,{children:[(0,t.jsx)(c,{children:n("Container")}),(0,t.jsx)(c,{children:n("Instance")}),(0,t.jsx)(c,{children:n("State")}),(0,t.jsx)(c,{children:n("Last event")}),(0,t.jsx)(c,{children:n("Detail")}),(0,t.jsx)(c,{children:n("Exit")}),(0,t.jsx)(c,{children:n("When")})]})}),(0,t.jsx)(D,{children:N.map(J)})]})})})]}),e[2]=i,e[3]=s,e[4]=o,e[5]=u,e[6]=n,e[7]=d}else d=e[7];return d},"H");function J(e){return(0,t.jsxs)(g,{"data-testid":`containers-row-${e.name}${e.instance===void 0?"":`-${e.instance}`}`,children:[(0,t.jsx)(l,{className:"font-mono text-xs",children:e.name}),(0,t.jsx)(l,{className:"max-w-40 truncate font-mono text-xs text-muted-foreground",title:e.instance,children:e.instance??"\u2014"}),(0,t.jsx)(l,{children:(0,t.jsx)(C,{variant:F[e.state],children:e.state})}),(0,t.jsx)(l,{className:"font-mono text-xs text-muted-foreground",children:e.event}),(0,t.jsx)(l,{className:"max-w-64 truncate text-xs text-muted-foreground",title:e.detail,children:e.detail??"\u2014"}),(0,t.jsx)(l,{className:"font-mono text-xs tabular-nums text-muted-foreground",children:e.exitCode??"\u2014"}),(0,t.jsx)(l,{className:"text-xs tabular-nums text-muted-foreground",children:new Date(e.timestamp).toLocaleString()})]},`${e.name}/${e.instance??""}`)}p(J,"B");export{V as default};
@@ -1 +1 @@
1
- import{b as we}from"./chunk-LZFOZFYW.js";import{a as Ne,c as ve,d as ye}from"./chunk-K2E4OECF.js";import{a as ge}from"./chunk-3DH35OZ5.js";import{a as xe}from"./chunk-IGCNMZSB.js";import"./chunk-IVFHIQOT.js";import"./chunk-QBWRC5YX.js";import{a as fe}from"./chunk-3CWGJYBB.js";import{a as pe}from"./chunk-RMN2JN4S.js";import{b as he}from"./chunk-GRL5MG3Z.js";import"./chunk-7T7UOTYK.js";import{R as me}from"./chunk-CFPZYHPY.js";import"./chunk-7QIFDWQV.js";import"./chunk-DJZYD5I5.js";import"./chunk-2OUPA2WJ.js";import{b as oe}from"./chunk-THIXMMZD.js";import"./chunk-6ST5ECQA.js";import{a as be}from"./chunk-322ZP3GW.js";import"./chunk-XXQUMVWH.js";import"./chunk-P4BOVBMR.js";import"./chunk-QLQADHFE.js";import{a as ce}from"./chunk-VDW32UET.js";import{c as ie}from"./chunk-BQNVN2OD.js";import"./chunk-M3NGYXDR.js";import"./chunk-XBDKZZ67.js";import{a as ue}from"./chunk-XQCVZAGU.js";import{d as W,r as de}from"./chunk-IUYFXK4X.js";import"./chunk-YC52XCPK.js";import{a as m,e as le,f as _e,g as $e,h as Ce,j as te}from"./chunk-3XIESWL4.js";var B=le($e(),1),O=le(_e(),1);var s=le(Ce(),1);var Me=m(n=>Math.min(100,Math.max(0,n)),"ie"),Le=m((n,e)=>{if(!Number.isFinite(e)||e<=0)return{leftPercent:0,widthPercent:100};let t=Me(n.offsetMs/e*100),a=n.durationMs/e*100,l=Math.max(.5,Math.min(Me(a),100-t));return{leftPercent:t,widthPercent:l}},"_e"),Te=m((n,e,t=!1)=>{let a=e.trim().toLowerCase(),l=t?n.filter(r=>!r.ok):n;return a===""?[...l]:l.filter(r=>r.rootName.toLowerCase().includes(a)||r.functionPath.toLowerCase().includes(a)||r.traceId.toLowerCase().includes(a)||r.spans.some(o=>o.name.toLowerCase().includes(a)||o.spanId.toLowerCase().includes(a)))},"Te"),j=m(n=>Number.isFinite(n)?n>0&&n<1?`${n.toFixed(2)}ms`:`${String(Math.round(n))}ms`:"\u2014","U"),Pe=m(n=>!Number.isFinite(n)||n<=0?[]:Array.from({length:4},(e,t)=>{let a=(t+1)/4;return{label:j(n*a),percent:a*100}}),"Le"),Ie=m(n=>{if(typeof n=="string")return n;try{return JSON.stringify(n)}catch{return String(n)}},"ue"),ee=m(n=>{let e=(0,B.c)(7),{label:t,value:a}=n,l;e[0]!==t?(l=(0,s.jsx)("dt",{className:"w-40 shrink-0 text-muted-foreground",children:t}),e[0]=t,e[1]=l):l=e[1];let r;e[2]!==a?(r=(0,s.jsx)("dd",{className:"min-w-0 break-all",children:a}),e[2]=a,e[3]=r):r=e[3];let o;return e[4]!==l||e[5]!==r?(o=(0,s.jsxs)("div",{className:"flex gap-2",children:[l,r]}),e[4]=l,e[5]=r,e[6]=o):o=e[6],o},"V"),Ke=m(n=>{let e=(0,B.c)(68),{span:t}=n,a=W(),l,r,o,d,i,u;if(e[0]!==t.attributes||e[1]!==t.durationMs||e[2]!==t.error||e[3]!==t.events||e[4]!==t.kind||e[5]!==t.offsetMs||e[6]!==t.parentSpanId||e[7]!==t.spanId||e[8]!==a){let $=Object.entries(t.attributes??{}),_;e[15]!==t.events?(_=t.events??[],e[15]=t.events,e[16]=_):_=e[16],l=_,r="border-t border-border bg-background/60 px-3 py-2 font-mono text-xs",o="tr-span-detail";let y;e[17]!==a?(y=a("Span ID"),e[17]=a,e[18]=y):y=e[18];let w;e[19]!==t.spanId||e[20]!==y?(w=(0,s.jsx)(ee,{label:y,value:t.spanId}),e[19]=t.spanId,e[20]=y,e[21]=w):w=e[21];let M;e[22]!==a?(M=a("Parent span ID"),e[22]=a,e[23]=M):M=e[23];let h;e[24]!==t.parentSpanId||e[25]!==a?(h=t.parentSpanId===""?a("\u2014 (trace root)"):t.parentSpanId,e[24]=t.parentSpanId,e[25]=a,e[26]=h):h=e[26];let p;e[27]!==h||e[28]!==M?(p=(0,s.jsx)(ee,{label:M,value:h}),e[27]=h,e[28]=M,e[29]=p):p=e[29];let b;e[30]!==a?(b=a("Kind"),e[30]=a,e[31]=b):b=e[31];let C=t.kind??"internal",S;e[32]!==b||e[33]!==C?(S=(0,s.jsx)(ee,{label:b,value:C}),e[32]=b,e[33]=C,e[34]=S):S=e[34];let I;e[35]!==a?(I=a("Started at"),e[35]=a,e[36]=I):I=e[36];let g;e[37]!==t.offsetMs||e[38]!==a?(g=a("+{offset}",{offset:j(t.offsetMs)}),e[37]=t.offsetMs,e[38]=a,e[39]=g):g=e[39];let x;e[40]!==I||e[41]!==g?(x=(0,s.jsx)(ee,{label:I,value:g}),e[40]=I,e[41]=g,e[42]=x):x=e[42];let k;e[43]!==a?(k=a("Duration"),e[43]=a,e[44]=k):k=e[44];let f;e[45]!==t.durationMs?(f=j(t.durationMs),e[45]=t.durationMs,e[46]=f):f=e[46];let N;e[47]!==k||e[48]!==f?(N=(0,s.jsx)(ee,{label:k,value:f}),e[47]=k,e[48]=f,e[49]=N):N=e[49],e[50]!==p||e[51]!==S||e[52]!==x||e[53]!==N||e[54]!==w?(d=(0,s.jsxs)("dl",{className:"flex flex-col gap-1",children:[w,p,S,x,N]}),e[50]=p,e[51]=S,e[52]=x,e[53]=N,e[54]=w,e[55]=d):d=e[55],e[56]!==t.error?(i=t.error!==void 0&&(0,s.jsxs)("div",{className:"mt-2 rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1.5","data-testid":"tr-detail-error",children:[(0,s.jsx)("span",{className:"font-semibold text-destructive",children:t.error.type}),(0,s.jsx)("p",{className:"whitespace-pre-wrap break-all text-destructive",children:t.error.message})]}),e[56]=t.error,e[57]=i):i=e[57],u=$.length>0&&(0,s.jsxs)("div",{className:"mt-2","data-testid":"tr-detail-attributes",children:[(0,s.jsx)("p",{className:"mb-1 text-muted-foreground",children:a("Attributes")}),(0,s.jsx)("dl",{className:"flex flex-col gap-1",children:$.map(De)})]}),e[0]=t.attributes,e[1]=t.durationMs,e[2]=t.error,e[3]=t.events,e[4]=t.kind,e[5]=t.offsetMs,e[6]=t.parentSpanId,e[7]=t.spanId,e[8]=a,e[9]=l,e[10]=r,e[11]=o,e[12]=d,e[13]=i,e[14]=u}else l=e[9],r=e[10],o=e[11],d=e[12],i=e[13],u=e[14];let c;e[58]!==l||e[59]!==a?(c=l.length>0&&(0,s.jsxs)("div",{className:"mt-2","data-testid":"tr-detail-events",children:[(0,s.jsx)("p",{className:"mb-1 text-muted-foreground",children:a("Events")}),(0,s.jsx)("ul",{className:"flex flex-col gap-1",children:l.map(Ee)})]}),e[58]=l,e[59]=a,e[60]=c):c=e[60];let v;return e[61]!==r||e[62]!==o||e[63]!==d||e[64]!==i||e[65]!==u||e[66]!==c?(v=(0,s.jsxs)("div",{className:r,"data-testid":o,children:[d,i,u,c]}),e[61]=r,e[62]=o,e[63]=d,e[64]=i,e[65]=u,e[66]=c,e[67]=v):v=e[67],v},"Pe");function De(n){let[e,t]=n;return(0,s.jsx)(ee,{label:e,value:Ie(t)},e)}m(De,"Ce");function Fe(n){let[e,t]=n;return`${e}=${Ie(t)}`}m(Fe,"Fe");function Ee(n){return(0,s.jsxs)("li",{className:"flex gap-2",children:[(0,s.jsx)("span",{className:"shrink-0 tabular-nums text-muted-foreground",children:de(n.ts)}),(0,s.jsx)(oe,{variant:"secondary",children:n.name}),(0,s.jsx)("span",{className:"min-w-0 break-all text-muted-foreground",children:Object.entries(n.attributes??{}).map(Fe).join(" ")})]},`${n.name}:${String(n.ts)}`)}m(Ee,"Ke");var Ae=14,Se="grid grid-cols-[14rem_1fr_4rem_16rem_16rem] items-center gap-2 px-3",Oe=m(n=>{let e=(0,B.c)(17),{traceDurationMs:t}=n,a,l,r,o,d,i;if(e[0]!==t){i=Symbol.for("react.early_return_sentinel");e:{let v=Pe(t);if(v.length===0){i=null;break e}e[7]===Symbol.for("react.memo_cache_sentinel")?(r=te(Se,"border-b border-border py-1 font-mono text-[10px] text-muted-foreground"),e[7]=r):r=e[7],o="tr-ruler",e[8]===Symbol.for("react.memo_cache_sentinel")?(d=(0,s.jsx)("span",{}),e[8]=d):d=e[8],a="relative h-3",l=v.map(Je)}e[0]=t,e[1]=a,e[2]=l,e[3]=r,e[4]=o,e[5]=d,e[6]=i}else a=e[1],l=e[2],r=e[3],o=e[4],d=e[5],i=e[6];if(i!==Symbol.for("react.early_return_sentinel"))return i;let u;e[9]!==a||e[10]!==l?(u=(0,s.jsx)("span",{className:a,children:l}),e[9]=a,e[10]=l,e[11]=u):u=e[11];let c;return e[12]!==r||e[13]!==o||e[14]!==d||e[15]!==u?(c=(0,s.jsxs)("div",{className:r,"data-testid":o,children:[d,u]}),e[12]=r,e[13]=o,e[14]=d,e[15]=u,e[16]=c):c=e[16],c},"je"),Be=m(n=>{let e=(0,B.c)(60),{span:t,traceDurationMs:a}=n,l=W(),[r,o]=(0,O.useState)(!1),d;e[0]!==t||e[1]!==a?(d=Le(t,a),e[0]=t,e[1]=a,e[2]=d):d=e[2];let{leftPercent:i,widthPercent:u}=d,c;e[3]!==t.attributes?(c=Ne(t.attributes),e[3]=t.attributes,e[4]=c):c=e[4];let v=c,$=t.depth*Ae,_;e[5]!==$?(_={paddingLeft:$},e[5]=$,e[6]=_):_=e[6];let y=_,w=`${String(i)}%`,M=`${String(u)}%`,h;e[7]!==w||e[8]!==M?(h={left:w,width:M},e[7]=w,e[8]=M,e[9]=h):h=e[9];let p=h,b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=m(()=>{o(Ue)},"h"),e[10]=b):b=e[10];let C=b,S=t.depth,I=`tr-span-detail-${t.spanId}`,g;e[11]!==t.durationMs||e[12]!==t.error||e[13]!==t.name||e[14]!==t.offsetMs||e[15]!==l?(g=l("{name}, {duration}, starts {offset} in{failure}",{duration:j(t.durationMs),failure:t.error===void 0?"":l(", failed: {message}",{message:t.error.message}),name:t.name,offset:j(t.offsetMs)}),e[11]=t.durationMs,e[12]=t.error,e[13]=t.name,e[14]=t.offsetMs,e[15]=l,e[16]=g):g=e[16];let x;e[17]===Symbol.for("react.memo_cache_sentinel")?(x=te(Se,"w-full border-b border-border py-1.5 text-left font-mono text-xs hover:bg-muted/50"),e[17]=x):x=e[17];let k=`tr-span-toggle-${t.spanId}`,f;e[18]!==t.ok?(f=t.ok?null:(0,s.jsx)("span",{"aria-hidden":"true",className:"mr-1 text-destructive","data-testid":"tr-span-error",children:"\u25CF"}),e[18]=t.ok,e[19]=f):f=e[19];let N;e[20]!==y||e[21]!==t.name||e[22]!==f?(N=(0,s.jsxs)("span",{className:"truncate",style:y,title:t.name,children:[f,t.name]}),e[20]=y,e[21]=t.name,e[22]=f,e[23]=N):N=e[23];let R=t.ok?"bg-primary/70":"bg-destructive",L;e[24]!==R?(L=te("absolute inset-y-0 rounded-sm",R),e[24]=R,e[25]=L):L=e[25];let A;e[26]!==p||e[27]!==i||e[28]!==L||e[29]!==u?(A=(0,s.jsx)("span",{"aria-hidden":"true",className:"relative h-3 overflow-hidden rounded-sm bg-muted",children:(0,s.jsx)("span",{className:L,"data-left":i,"data-testid":"tr-span-bar","data-width":u,style:p})}),e[26]=p,e[27]=i,e[28]=L,e[29]=u,e[30]=A):A=e[30];let J;e[31]!==t.durationMs?(J=j(t.durationMs),e[31]=t.durationMs,e[32]=J):J=e[32];let D;e[33]!==J?(D=(0,s.jsx)("span",{className:"text-right tabular-nums text-muted-foreground",children:J}),e[33]=J,e[34]=D):D=e[34];let U;e[35]!==t.error?(U=t.error===void 0?null:(0,s.jsx)("span",{className:"text-destructive","data-testid":"tr-span-error-message",title:t.error.message,children:`${t.error.type}: ${t.error.message}`}),e[35]=t.error,e[36]=U):U=e[36];let T;e[37]!==U?(T=(0,s.jsx)("span",{className:"truncate text-muted-foreground",children:U}),e[37]=U,e[38]=T):T=e[38];let q;e[39]!==v?(q=v===""?null:(0,s.jsx)("span",{"data-testid":"tr-span-attributes",title:v,children:v}),e[39]=v,e[40]=q):q=e[40];let P;e[41]!==q?(P=(0,s.jsx)("span",{className:"truncate text-muted-foreground",children:q}),e[41]=q,e[42]=P):P=e[42];let z;e[43]!==r||e[44]!==I||e[45]!==g||e[46]!==k||e[47]!==N||e[48]!==A||e[49]!==D||e[50]!==T||e[51]!==P?(z=(0,s.jsxs)("button",{"aria-controls":I,"aria-expanded":r,"aria-label":g,className:x,"data-testid":k,onClick:C,type:"button",children:[N,A,D,T,P]}),e[43]=r,e[44]=I,e[45]=g,e[46]=k,e[47]=N,e[48]=A,e[49]=D,e[50]=T,e[51]=P,e[52]=z):z=e[52];let F;e[53]!==r||e[54]!==t?(F=r&&(0,s.jsx)("div",{id:`tr-span-detail-${t.spanId}`,children:(0,s.jsx)(Ke,{span:t})}),e[53]=r,e[54]=t,e[55]=F):F=e[55];let K;return e[56]!==t.depth||e[57]!==z||e[58]!==F?(K=(0,s.jsxs)("li",{"data-depth":S,"data-testid":"tr-span-row",children:[z,F]}),e[56]=t.depth,e[57]=z,e[58]=F,e[59]=K):K=e[59],K},"Ee"),Re=m(n=>{let e=(0,B.c)(15),{durationMs:t,spans:a}=n,l=W(),r;e[0]!==t?(r=(0,s.jsx)(Oe,{traceDurationMs:t}),e[0]=t,e[1]=r):r=e[1];let o;e[2]!==l?(o=l("Trace waterfall"),e[2]=l,e[3]=o):o=e[3];let d;if(e[4]!==t||e[5]!==a){let c;e[7]!==t?(c=m(v=>(0,s.jsx)(Be,{span:v,traceDurationMs:t},v.spanId),"c"),e[7]=t,e[8]=c):c=e[8],d=a.map(c),e[4]=t,e[5]=a,e[6]=d}else d=e[6];let i;e[9]!==o||e[10]!==d?(i=(0,s.jsx)("ul",{"aria-label":o,children:d}),e[9]=o,e[10]=d,e[11]=i):i=e[11];let u;return e[12]!==r||e[13]!==i?(u=(0,s.jsxs)(s.Fragment,{children:[r,i]}),e[12]=r,e[13]=i,e[14]=u):u=e[14],u},"Ae");function Je(n){return(0,s.jsx)("span",{className:te("absolute inset-y-0 border-l border-border/70",n.percent===100?"-translate-x-full pr-1":"pl-1"),style:{left:`${String(n.percent)}%`},children:n.label},n.percent)}m(Je,"Be");function Ue(n){return!n}m(Ue,"Oe");var qe=m(n=>Array.isArray(n?.traces)?n.traces:[],"Re"),ze=m(n=>{let e=(0,B.c)(12),{entries:t}=n,a=W(),l;e[0]!==t.length||e[1]!==a?(l=a("Logs ({count})",{count:t.length}),e[0]=t.length,e[1]=a,e[2]=l):l=e[2];let r;e[3]!==l?(r=(0,s.jsx)("p",{className:"mb-1 font-mono text-xs text-muted-foreground",children:l}),e[3]=l,e[4]=r):r=e[4];let o;e[5]!==t?(o=t.map(je),e[5]=t,e[6]=o):o=e[6];let d;e[7]!==o?(d=(0,s.jsx)("div",{role:"grid",children:o}),e[7]=o,e[8]=d):d=e[8];let i;return e[9]!==r||e[10]!==d?(i=(0,s.jsxs)("div",{className:"border-t border-border px-3 py-2","data-testid":"tr-logs",children:[r,d]}),e[9]=r,e[10]=d,e[11]=i):i=e[11],i},"Je"),We=m(n=>{let e=(0,B.c)(50),{expanded:t,logs:a,onToggle:l,trace:r}=n,o=W(),d;e[0]!==l||e[1]!==r.traceId?(d=m(()=>{l(r.traceId)},"d"),e[0]=l,e[1]=r.traceId,e[2]=d):d=e[2];let i=d,u=`tr-row-${r.traceId}`,c=`tr-waterfall-${r.traceId}`,v=`tr-toggle-${r.traceId}`,$=t?"\u25BE":"\u25B8",_;e[3]!==$?(_=(0,s.jsx)("span",{"aria-hidden":"true",className:"w-3 shrink-0 text-xs text-muted-foreground",children:$}),e[3]=$,e[4]=_):_=e[4];let y;e[5]!==r.rootName?(y=(0,s.jsx)("span",{className:"w-56 shrink-0 truncate text-sm font-medium",title:r.rootName,children:r.rootName}),e[5]=r.rootName,e[6]=y):y=e[6];let w;e[7]!==r.functionPath?(w=(0,s.jsx)("span",{className:"w-48 shrink-0 truncate font-mono text-xs text-muted-foreground",title:r.functionPath,children:r.functionPath}),e[7]=r.functionPath,e[8]=w):w=e[8];let M;e[9]!==r.durationMs?(M=j(r.durationMs),e[9]=r.durationMs,e[10]=M):M=e[10];let h;e[11]!==M?(h=(0,s.jsx)("span",{className:"w-20 shrink-0 text-right font-mono text-xs tabular-nums text-muted-foreground",children:M}),e[11]=M,e[12]=h):h=e[12];let p;e[13]!==o||e[14]!==r.spans.length?(p=o("{count} spans",{count:r.spans.length}),e[13]=o,e[14]=r.spans.length,e[15]=p):p=e[15];let b;e[16]!==p?(b=(0,s.jsx)("span",{className:"w-20 shrink-0 text-right font-mono text-xs tabular-nums text-muted-foreground",children:p}),e[16]=p,e[17]=b):b=e[17];let C=r.ok?"secondary":"destructive",S;e[18]!==o||e[19]!==r.ok?(S=r.ok?o("ok"):o("error"),e[18]=o,e[19]=r.ok,e[20]=S):S=e[20];let I;e[21]!==C||e[22]!==S?(I=(0,s.jsx)("span",{className:"shrink-0",children:(0,s.jsx)(oe,{variant:C,children:S})}),e[21]=C,e[22]=S,e[23]=I):I=e[23];let g;e[24]!==r.startTs?(g=de(r.startTs),e[24]=r.startTs,e[25]=g):g=e[25];let x;e[26]!==g?(x=(0,s.jsx)("span",{className:"flex-1 truncate text-right font-mono text-xs tabular-nums text-muted-foreground",children:g}),e[26]=g,e[27]=x):x=e[27];let k;e[28]!==t||e[29]!==i||e[30]!==h||e[31]!==b||e[32]!==I||e[33]!==x||e[34]!==c||e[35]!==v||e[36]!==_||e[37]!==y||e[38]!==w?(k=(0,s.jsxs)("button",{"aria-controls":c,"aria-expanded":t,className:"flex w-full items-center gap-3 px-3 py-2 text-left hover:bg-muted/50","data-testid":v,onClick:i,type:"button",children:[_,y,w,h,b,I,x]}),e[28]=t,e[29]=i,e[30]=h,e[31]=b,e[32]=I,e[33]=x,e[34]=c,e[35]=v,e[36]=_,e[37]=y,e[38]=w,e[39]=k):k=e[39];let f;e[40]!==t||e[41]!==a||e[42]!==r.durationMs||e[43]!==r.spans||e[44]!==r.traceId?(f=t&&(0,s.jsxs)("div",{className:"bg-muted/20","data-testid":`tr-waterfall-${r.traceId}`,id:`tr-waterfall-${r.traceId}`,children:[(0,s.jsx)(Re,{durationMs:r.durationMs,spans:r.spans}),a.length>0&&(0,s.jsx)(ze,{entries:a})]}),e[40]=t,e[41]=a,e[42]=r.durationMs,e[43]=r.spans,e[44]=r.traceId,e[45]=f):f=e[45];let N;return e[46]!==k||e[47]!==f||e[48]!==u?(N=(0,s.jsxs)("div",{className:"border-b border-border last:border-b-0","data-testid":u,children:[k,f]}),e[46]=k,e[47]=f,e[48]=u,e[49]=N):N=e[49],N},"ze"),ut=m(n=>{let e=(0,B.c)(58),{initialShardKey:t}=n,a=W(),[l]=(0,O.useState)(ve),{queryShardKey:r,setShardKey:o,shardKey:d}=fe(l?.shardKey!==void 0&&l.shardKey!==""?l.shardKey:t??""),[i,u]=(0,O.useState)(l?.traceId??""),[c,v]=(0,O.useState)(!1),[$,_]=(0,O.useState)(He),y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=[],e[0]=y):y=e[0],(0,O.useEffect)(Ge,y);let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w={},e[1]=w):w=e[1];let M;e[2]!==r?(M={live:!0,shardKey:r},e[2]=r,e[3]=M):M=e[3];let{data:h,error:p,errorSource:b,isLoading:C,liveError:S}=ie(ce.getTraces,w,M),I;e[4]===Symbol.for("react.memo_cache_sentinel")?(I={},e[4]=I):I=e[4];let g=$.size>0,x;e[5]!==r||e[6]!==g?(x={enabled:g,live:!0,shardKey:r},e[5]=r,e[6]=g,e[7]=x):x=e[7];let{data:k}=ie(ce.getLogs,I,x),f,N;e[8]!==h||e[9]!==r?(f=m(()=>{h!==void 0&&he(r)},"p"),N=[h,r],e[8]=h,e[9]=r,e[10]=f,e[11]=N):(f=e[10],N=e[11]),(0,O.useEffect)(f,N);let R;if(e[12]!==h||e[13]!==p||e[14]!==b||e[15]!==$||e[16]!==C||e[17]!==S||e[18]!==k?.entries||e[19]!==c||e[20]!==i||e[21]!==o||e[22]!==d||e[23]!==a){let L=qe(h),A=h?.total??L.length,J=A>L.length,D=Te(L,i,c),U=Map.groupBy((k?.entries??[]).toReversed(),Qe),T;e[25]===Symbol.for("react.memo_cache_sentinel")?(T=m(E=>{u(E.target.value)},"P"),e[25]=T):T=e[25];let q=T,P;e[26]===Symbol.for("react.memo_cache_sentinel")?(P=m(E=>{_(ke=>{let ne=new Set(ke);return ne.has(E)?ne.delete(E):ne.add(E),ne})},"C"),e[26]=P):P=e[26];let z=P,F=p===null&&D.length===0&&!C,K;e[27]!==o||e[28]!==d?(K=(0,s.jsx)(pe,{onChange:o,testId:"tr-shard-input",value:d}),e[27]=o,e[28]=d,e[29]=K):K=e[29];let H;e[30]!==a?(H=a("Search traces"),e[30]=a,e[31]=H):H=e[31];let G;e[32]!==a?(G=a("search trace, span, or function"),e[32]=a,e[33]=G):G=e[33];let Q;e[34]!==i||e[35]!==H||e[36]!==G?(Q=(0,s.jsx)(me,{"aria-label":H,className:"h-8 w-56","data-testid":"tr-search",onChange:q,placeholder:G,value:i}),e[34]=i,e[35]=H,e[36]=G,e[37]=Q):Q=e[37];let V;e[38]!==c?(V=(0,s.jsx)(ge,{checked:c,"data-testid":"tr-only-errors",id:"tr-only-errors",onCheckedChange:v}),e[38]=c,e[39]=V):V=e[39];let X;e[40]!==a?(X=a("Errors only"),e[40]=a,e[41]=X):X=e[41];let Y;e[42]!==V||e[43]!==X?(Y=(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",htmlFor:"tr-only-errors",children:[V,X]}),e[42]=V,e[43]=X,e[44]=Y):Y=e[44];let Z;e[45]!==S?(Z=(0,s.jsx)(xe,{message:S,prefix:"tr"}),e[45]=S,e[46]=Z):Z=e[46];let re;e[47]!==K||e[48]!==Q||e[49]!==Y||e[50]!==Z?(re=(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[K,Q,Y,Z]}),e[47]=K,e[48]=Q,e[49]=Y,e[50]=Z,e[51]=re):re=e[51];let ae;e[52]!==p||e[53]!==b?(ae=p!==null&&(0,s.jsx)(be,{error:b,testId:"tr-error"}),e[52]=p,e[53]=b,e[54]=ae):ae=e[54];let se;e[55]!==F||e[56]!==a?(se=F&&(0,s.jsx)(ue,{description:a("Traces recorded with ctx.trace show up here as your app handles traffic. The span buffer resets when the shard hibernates."),icon:(0,s.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,s.jsx)("path",{d:"M4 6h10M7 12h13M10 18h7"})}),testId:"tr-empty",title:a("No traces")}),e[55]=F,e[56]=a,e[57]=se):se=e[57],R=(0,s.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-traces-panel",children:[re,ae,se,p===null&&J&&(0,s.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"tr-truncated",children:a("Showing the {shown} most recent of {total} traces in the buffer.",{shown:L.length,total:A})}),p===null&&D.length>0&&(0,s.jsx)("div",{"aria-label":a("Recent traces"),className:"overflow-hidden rounded-xl border border-border shadow-xs","data-testid":"tr-list",children:D.map(E=>(0,s.jsx)(We,{expanded:$.has(E.traceId),logs:U.get(E.traceId)??[],onToggle:z,trace:E},E.traceId))})]}),e[12]=h,e[13]=p,e[14]=b,e[15]=$,e[16]=C,e[17]=S,e[18]=k?.entries,e[19]=c,e[20]=i,e[21]=o,e[22]=d,e[23]=a,e[24]=R}else R=e[24];return R},"ft");function je(n,e){return(0,s.jsx)("div",{className:"flex items-center border-b border-border py-1 font-mono text-xs last:border-b-0","data-testid":"tr-log-row",role:"row",children:(0,s.jsx)(we,{entry:n})},`${String(e)}:${String(n.timestamp)}`)}m(je,"Ue");function He(){return new Set}m(He,"We");function Ge(){ye()}m(Ge,"qe");function Qe(n){return n.traceId}m(Qe,"He");export{ut as default};
1
+ import{b as we}from"./chunk-LZFOZFYW.js";import{a as Ne,c as ve,d as ye}from"./chunk-K2E4OECF.js";import{a as ge}from"./chunk-3DH35OZ5.js";import{a as xe}from"./chunk-IGCNMZSB.js";import"./chunk-IVFHIQOT.js";import"./chunk-QBWRC5YX.js";import{a as fe}from"./chunk-3CWGJYBB.js";import{a as pe}from"./chunk-RMN2JN4S.js";import{b as he}from"./chunk-GRL5MG3Z.js";import"./chunk-7T7UOTYK.js";import{R as me}from"./chunk-CFPZYHPY.js";import"./chunk-7QIFDWQV.js";import"./chunk-DJZYD5I5.js";import"./chunk-2OUPA2WJ.js";import{b as oe}from"./chunk-THIXMMZD.js";import"./chunk-6ST5ECQA.js";import{a as be}from"./chunk-6IZBFC3G.js";import"./chunk-XXQUMVWH.js";import"./chunk-ZNNKWEH5.js";import"./chunk-QLQADHFE.js";import{a as ce}from"./chunk-VDW32UET.js";import{c as ie}from"./chunk-UP7OTXKF.js";import"./chunk-LYVP5PT6.js";import"./chunk-XBDKZZ67.js";import{a as ue}from"./chunk-XQCVZAGU.js";import{d as W,r as de}from"./chunk-IUYFXK4X.js";import"./chunk-X7B6PLEW.js";import{a as m,e as le,f as _e,g as $e,h as Ce,j as te}from"./chunk-3XIESWL4.js";var B=le($e(),1),O=le(_e(),1);var s=le(Ce(),1);var Me=m(n=>Math.min(100,Math.max(0,n)),"ie"),Le=m((n,e)=>{if(!Number.isFinite(e)||e<=0)return{leftPercent:0,widthPercent:100};let t=Me(n.offsetMs/e*100),a=n.durationMs/e*100,l=Math.max(.5,Math.min(Me(a),100-t));return{leftPercent:t,widthPercent:l}},"_e"),Te=m((n,e,t=!1)=>{let a=e.trim().toLowerCase(),l=t?n.filter(r=>!r.ok):n;return a===""?[...l]:l.filter(r=>r.rootName.toLowerCase().includes(a)||r.functionPath.toLowerCase().includes(a)||r.traceId.toLowerCase().includes(a)||r.spans.some(o=>o.name.toLowerCase().includes(a)||o.spanId.toLowerCase().includes(a)))},"Te"),j=m(n=>Number.isFinite(n)?n>0&&n<1?`${n.toFixed(2)}ms`:`${String(Math.round(n))}ms`:"\u2014","U"),Pe=m(n=>!Number.isFinite(n)||n<=0?[]:Array.from({length:4},(e,t)=>{let a=(t+1)/4;return{label:j(n*a),percent:a*100}}),"Le"),Ie=m(n=>{if(typeof n=="string")return n;try{return JSON.stringify(n)}catch{return String(n)}},"ue"),ee=m(n=>{let e=(0,B.c)(7),{label:t,value:a}=n,l;e[0]!==t?(l=(0,s.jsx)("dt",{className:"w-40 shrink-0 text-muted-foreground",children:t}),e[0]=t,e[1]=l):l=e[1];let r;e[2]!==a?(r=(0,s.jsx)("dd",{className:"min-w-0 break-all",children:a}),e[2]=a,e[3]=r):r=e[3];let o;return e[4]!==l||e[5]!==r?(o=(0,s.jsxs)("div",{className:"flex gap-2",children:[l,r]}),e[4]=l,e[5]=r,e[6]=o):o=e[6],o},"V"),Ke=m(n=>{let e=(0,B.c)(68),{span:t}=n,a=W(),l,r,o,d,i,u;if(e[0]!==t.attributes||e[1]!==t.durationMs||e[2]!==t.error||e[3]!==t.events||e[4]!==t.kind||e[5]!==t.offsetMs||e[6]!==t.parentSpanId||e[7]!==t.spanId||e[8]!==a){let $=Object.entries(t.attributes??{}),_;e[15]!==t.events?(_=t.events??[],e[15]=t.events,e[16]=_):_=e[16],l=_,r="border-t border-border bg-background/60 px-3 py-2 font-mono text-xs",o="tr-span-detail";let y;e[17]!==a?(y=a("Span ID"),e[17]=a,e[18]=y):y=e[18];let w;e[19]!==t.spanId||e[20]!==y?(w=(0,s.jsx)(ee,{label:y,value:t.spanId}),e[19]=t.spanId,e[20]=y,e[21]=w):w=e[21];let M;e[22]!==a?(M=a("Parent span ID"),e[22]=a,e[23]=M):M=e[23];let h;e[24]!==t.parentSpanId||e[25]!==a?(h=t.parentSpanId===""?a("\u2014 (trace root)"):t.parentSpanId,e[24]=t.parentSpanId,e[25]=a,e[26]=h):h=e[26];let p;e[27]!==h||e[28]!==M?(p=(0,s.jsx)(ee,{label:M,value:h}),e[27]=h,e[28]=M,e[29]=p):p=e[29];let b;e[30]!==a?(b=a("Kind"),e[30]=a,e[31]=b):b=e[31];let C=t.kind??"internal",S;e[32]!==b||e[33]!==C?(S=(0,s.jsx)(ee,{label:b,value:C}),e[32]=b,e[33]=C,e[34]=S):S=e[34];let I;e[35]!==a?(I=a("Started at"),e[35]=a,e[36]=I):I=e[36];let g;e[37]!==t.offsetMs||e[38]!==a?(g=a("+{offset}",{offset:j(t.offsetMs)}),e[37]=t.offsetMs,e[38]=a,e[39]=g):g=e[39];let x;e[40]!==I||e[41]!==g?(x=(0,s.jsx)(ee,{label:I,value:g}),e[40]=I,e[41]=g,e[42]=x):x=e[42];let k;e[43]!==a?(k=a("Duration"),e[43]=a,e[44]=k):k=e[44];let f;e[45]!==t.durationMs?(f=j(t.durationMs),e[45]=t.durationMs,e[46]=f):f=e[46];let N;e[47]!==k||e[48]!==f?(N=(0,s.jsx)(ee,{label:k,value:f}),e[47]=k,e[48]=f,e[49]=N):N=e[49],e[50]!==p||e[51]!==S||e[52]!==x||e[53]!==N||e[54]!==w?(d=(0,s.jsxs)("dl",{className:"flex flex-col gap-1",children:[w,p,S,x,N]}),e[50]=p,e[51]=S,e[52]=x,e[53]=N,e[54]=w,e[55]=d):d=e[55],e[56]!==t.error?(i=t.error!==void 0&&(0,s.jsxs)("div",{className:"mt-2 rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1.5","data-testid":"tr-detail-error",children:[(0,s.jsx)("span",{className:"font-semibold text-destructive",children:t.error.type}),(0,s.jsx)("p",{className:"whitespace-pre-wrap break-all text-destructive",children:t.error.message})]}),e[56]=t.error,e[57]=i):i=e[57],u=$.length>0&&(0,s.jsxs)("div",{className:"mt-2","data-testid":"tr-detail-attributes",children:[(0,s.jsx)("p",{className:"mb-1 text-muted-foreground",children:a("Attributes")}),(0,s.jsx)("dl",{className:"flex flex-col gap-1",children:$.map(De)})]}),e[0]=t.attributes,e[1]=t.durationMs,e[2]=t.error,e[3]=t.events,e[4]=t.kind,e[5]=t.offsetMs,e[6]=t.parentSpanId,e[7]=t.spanId,e[8]=a,e[9]=l,e[10]=r,e[11]=o,e[12]=d,e[13]=i,e[14]=u}else l=e[9],r=e[10],o=e[11],d=e[12],i=e[13],u=e[14];let c;e[58]!==l||e[59]!==a?(c=l.length>0&&(0,s.jsxs)("div",{className:"mt-2","data-testid":"tr-detail-events",children:[(0,s.jsx)("p",{className:"mb-1 text-muted-foreground",children:a("Events")}),(0,s.jsx)("ul",{className:"flex flex-col gap-1",children:l.map(Ee)})]}),e[58]=l,e[59]=a,e[60]=c):c=e[60];let v;return e[61]!==r||e[62]!==o||e[63]!==d||e[64]!==i||e[65]!==u||e[66]!==c?(v=(0,s.jsxs)("div",{className:r,"data-testid":o,children:[d,i,u,c]}),e[61]=r,e[62]=o,e[63]=d,e[64]=i,e[65]=u,e[66]=c,e[67]=v):v=e[67],v},"Pe");function De(n){let[e,t]=n;return(0,s.jsx)(ee,{label:e,value:Ie(t)},e)}m(De,"Ce");function Fe(n){let[e,t]=n;return`${e}=${Ie(t)}`}m(Fe,"Fe");function Ee(n){return(0,s.jsxs)("li",{className:"flex gap-2",children:[(0,s.jsx)("span",{className:"shrink-0 tabular-nums text-muted-foreground",children:de(n.ts)}),(0,s.jsx)(oe,{variant:"secondary",children:n.name}),(0,s.jsx)("span",{className:"min-w-0 break-all text-muted-foreground",children:Object.entries(n.attributes??{}).map(Fe).join(" ")})]},`${n.name}:${String(n.ts)}`)}m(Ee,"Ke");var Ae=14,Se="grid grid-cols-[14rem_1fr_4rem_16rem_16rem] items-center gap-2 px-3",Oe=m(n=>{let e=(0,B.c)(17),{traceDurationMs:t}=n,a,l,r,o,d,i;if(e[0]!==t){i=Symbol.for("react.early_return_sentinel");e:{let v=Pe(t);if(v.length===0){i=null;break e}e[7]===Symbol.for("react.memo_cache_sentinel")?(r=te(Se,"border-b border-border py-1 font-mono text-[10px] text-muted-foreground"),e[7]=r):r=e[7],o="tr-ruler",e[8]===Symbol.for("react.memo_cache_sentinel")?(d=(0,s.jsx)("span",{}),e[8]=d):d=e[8],a="relative h-3",l=v.map(Je)}e[0]=t,e[1]=a,e[2]=l,e[3]=r,e[4]=o,e[5]=d,e[6]=i}else a=e[1],l=e[2],r=e[3],o=e[4],d=e[5],i=e[6];if(i!==Symbol.for("react.early_return_sentinel"))return i;let u;e[9]!==a||e[10]!==l?(u=(0,s.jsx)("span",{className:a,children:l}),e[9]=a,e[10]=l,e[11]=u):u=e[11];let c;return e[12]!==r||e[13]!==o||e[14]!==d||e[15]!==u?(c=(0,s.jsxs)("div",{className:r,"data-testid":o,children:[d,u]}),e[12]=r,e[13]=o,e[14]=d,e[15]=u,e[16]=c):c=e[16],c},"je"),Be=m(n=>{let e=(0,B.c)(60),{span:t,traceDurationMs:a}=n,l=W(),[r,o]=(0,O.useState)(!1),d;e[0]!==t||e[1]!==a?(d=Le(t,a),e[0]=t,e[1]=a,e[2]=d):d=e[2];let{leftPercent:i,widthPercent:u}=d,c;e[3]!==t.attributes?(c=Ne(t.attributes),e[3]=t.attributes,e[4]=c):c=e[4];let v=c,$=t.depth*Ae,_;e[5]!==$?(_={paddingLeft:$},e[5]=$,e[6]=_):_=e[6];let y=_,w=`${String(i)}%`,M=`${String(u)}%`,h;e[7]!==w||e[8]!==M?(h={left:w,width:M},e[7]=w,e[8]=M,e[9]=h):h=e[9];let p=h,b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=m(()=>{o(Ue)},"h"),e[10]=b):b=e[10];let C=b,S=t.depth,I=`tr-span-detail-${t.spanId}`,g;e[11]!==t.durationMs||e[12]!==t.error||e[13]!==t.name||e[14]!==t.offsetMs||e[15]!==l?(g=l("{name}, {duration}, starts {offset} in{failure}",{duration:j(t.durationMs),failure:t.error===void 0?"":l(", failed: {message}",{message:t.error.message}),name:t.name,offset:j(t.offsetMs)}),e[11]=t.durationMs,e[12]=t.error,e[13]=t.name,e[14]=t.offsetMs,e[15]=l,e[16]=g):g=e[16];let x;e[17]===Symbol.for("react.memo_cache_sentinel")?(x=te(Se,"w-full border-b border-border py-1.5 text-left font-mono text-xs hover:bg-muted/50"),e[17]=x):x=e[17];let k=`tr-span-toggle-${t.spanId}`,f;e[18]!==t.ok?(f=t.ok?null:(0,s.jsx)("span",{"aria-hidden":"true",className:"mr-1 text-destructive","data-testid":"tr-span-error",children:"\u25CF"}),e[18]=t.ok,e[19]=f):f=e[19];let N;e[20]!==y||e[21]!==t.name||e[22]!==f?(N=(0,s.jsxs)("span",{className:"truncate",style:y,title:t.name,children:[f,t.name]}),e[20]=y,e[21]=t.name,e[22]=f,e[23]=N):N=e[23];let R=t.ok?"bg-primary/70":"bg-destructive",L;e[24]!==R?(L=te("absolute inset-y-0 rounded-sm",R),e[24]=R,e[25]=L):L=e[25];let A;e[26]!==p||e[27]!==i||e[28]!==L||e[29]!==u?(A=(0,s.jsx)("span",{"aria-hidden":"true",className:"relative h-3 overflow-hidden rounded-sm bg-muted",children:(0,s.jsx)("span",{className:L,"data-left":i,"data-testid":"tr-span-bar","data-width":u,style:p})}),e[26]=p,e[27]=i,e[28]=L,e[29]=u,e[30]=A):A=e[30];let J;e[31]!==t.durationMs?(J=j(t.durationMs),e[31]=t.durationMs,e[32]=J):J=e[32];let D;e[33]!==J?(D=(0,s.jsx)("span",{className:"text-right tabular-nums text-muted-foreground",children:J}),e[33]=J,e[34]=D):D=e[34];let U;e[35]!==t.error?(U=t.error===void 0?null:(0,s.jsx)("span",{className:"text-destructive","data-testid":"tr-span-error-message",title:t.error.message,children:`${t.error.type}: ${t.error.message}`}),e[35]=t.error,e[36]=U):U=e[36];let T;e[37]!==U?(T=(0,s.jsx)("span",{className:"truncate text-muted-foreground",children:U}),e[37]=U,e[38]=T):T=e[38];let q;e[39]!==v?(q=v===""?null:(0,s.jsx)("span",{"data-testid":"tr-span-attributes",title:v,children:v}),e[39]=v,e[40]=q):q=e[40];let P;e[41]!==q?(P=(0,s.jsx)("span",{className:"truncate text-muted-foreground",children:q}),e[41]=q,e[42]=P):P=e[42];let z;e[43]!==r||e[44]!==I||e[45]!==g||e[46]!==k||e[47]!==N||e[48]!==A||e[49]!==D||e[50]!==T||e[51]!==P?(z=(0,s.jsxs)("button",{"aria-controls":I,"aria-expanded":r,"aria-label":g,className:x,"data-testid":k,onClick:C,type:"button",children:[N,A,D,T,P]}),e[43]=r,e[44]=I,e[45]=g,e[46]=k,e[47]=N,e[48]=A,e[49]=D,e[50]=T,e[51]=P,e[52]=z):z=e[52];let F;e[53]!==r||e[54]!==t?(F=r&&(0,s.jsx)("div",{id:`tr-span-detail-${t.spanId}`,children:(0,s.jsx)(Ke,{span:t})}),e[53]=r,e[54]=t,e[55]=F):F=e[55];let K;return e[56]!==t.depth||e[57]!==z||e[58]!==F?(K=(0,s.jsxs)("li",{"data-depth":S,"data-testid":"tr-span-row",children:[z,F]}),e[56]=t.depth,e[57]=z,e[58]=F,e[59]=K):K=e[59],K},"Ee"),Re=m(n=>{let e=(0,B.c)(15),{durationMs:t,spans:a}=n,l=W(),r;e[0]!==t?(r=(0,s.jsx)(Oe,{traceDurationMs:t}),e[0]=t,e[1]=r):r=e[1];let o;e[2]!==l?(o=l("Trace waterfall"),e[2]=l,e[3]=o):o=e[3];let d;if(e[4]!==t||e[5]!==a){let c;e[7]!==t?(c=m(v=>(0,s.jsx)(Be,{span:v,traceDurationMs:t},v.spanId),"c"),e[7]=t,e[8]=c):c=e[8],d=a.map(c),e[4]=t,e[5]=a,e[6]=d}else d=e[6];let i;e[9]!==o||e[10]!==d?(i=(0,s.jsx)("ul",{"aria-label":o,children:d}),e[9]=o,e[10]=d,e[11]=i):i=e[11];let u;return e[12]!==r||e[13]!==i?(u=(0,s.jsxs)(s.Fragment,{children:[r,i]}),e[12]=r,e[13]=i,e[14]=u):u=e[14],u},"Ae");function Je(n){return(0,s.jsx)("span",{className:te("absolute inset-y-0 border-l border-border/70",n.percent===100?"-translate-x-full pr-1":"pl-1"),style:{left:`${String(n.percent)}%`},children:n.label},n.percent)}m(Je,"Be");function Ue(n){return!n}m(Ue,"Oe");var qe=m(n=>Array.isArray(n?.traces)?n.traces:[],"Re"),ze=m(n=>{let e=(0,B.c)(12),{entries:t}=n,a=W(),l;e[0]!==t.length||e[1]!==a?(l=a("Logs ({count})",{count:t.length}),e[0]=t.length,e[1]=a,e[2]=l):l=e[2];let r;e[3]!==l?(r=(0,s.jsx)("p",{className:"mb-1 font-mono text-xs text-muted-foreground",children:l}),e[3]=l,e[4]=r):r=e[4];let o;e[5]!==t?(o=t.map(je),e[5]=t,e[6]=o):o=e[6];let d;e[7]!==o?(d=(0,s.jsx)("div",{role:"grid",children:o}),e[7]=o,e[8]=d):d=e[8];let i;return e[9]!==r||e[10]!==d?(i=(0,s.jsxs)("div",{className:"border-t border-border px-3 py-2","data-testid":"tr-logs",children:[r,d]}),e[9]=r,e[10]=d,e[11]=i):i=e[11],i},"Je"),We=m(n=>{let e=(0,B.c)(50),{expanded:t,logs:a,onToggle:l,trace:r}=n,o=W(),d;e[0]!==l||e[1]!==r.traceId?(d=m(()=>{l(r.traceId)},"d"),e[0]=l,e[1]=r.traceId,e[2]=d):d=e[2];let i=d,u=`tr-row-${r.traceId}`,c=`tr-waterfall-${r.traceId}`,v=`tr-toggle-${r.traceId}`,$=t?"\u25BE":"\u25B8",_;e[3]!==$?(_=(0,s.jsx)("span",{"aria-hidden":"true",className:"w-3 shrink-0 text-xs text-muted-foreground",children:$}),e[3]=$,e[4]=_):_=e[4];let y;e[5]!==r.rootName?(y=(0,s.jsx)("span",{className:"w-56 shrink-0 truncate text-sm font-medium",title:r.rootName,children:r.rootName}),e[5]=r.rootName,e[6]=y):y=e[6];let w;e[7]!==r.functionPath?(w=(0,s.jsx)("span",{className:"w-48 shrink-0 truncate font-mono text-xs text-muted-foreground",title:r.functionPath,children:r.functionPath}),e[7]=r.functionPath,e[8]=w):w=e[8];let M;e[9]!==r.durationMs?(M=j(r.durationMs),e[9]=r.durationMs,e[10]=M):M=e[10];let h;e[11]!==M?(h=(0,s.jsx)("span",{className:"w-20 shrink-0 text-right font-mono text-xs tabular-nums text-muted-foreground",children:M}),e[11]=M,e[12]=h):h=e[12];let p;e[13]!==o||e[14]!==r.spans.length?(p=o("{count} spans",{count:r.spans.length}),e[13]=o,e[14]=r.spans.length,e[15]=p):p=e[15];let b;e[16]!==p?(b=(0,s.jsx)("span",{className:"w-20 shrink-0 text-right font-mono text-xs tabular-nums text-muted-foreground",children:p}),e[16]=p,e[17]=b):b=e[17];let C=r.ok?"secondary":"destructive",S;e[18]!==o||e[19]!==r.ok?(S=r.ok?o("ok"):o("error"),e[18]=o,e[19]=r.ok,e[20]=S):S=e[20];let I;e[21]!==C||e[22]!==S?(I=(0,s.jsx)("span",{className:"shrink-0",children:(0,s.jsx)(oe,{variant:C,children:S})}),e[21]=C,e[22]=S,e[23]=I):I=e[23];let g;e[24]!==r.startTs?(g=de(r.startTs),e[24]=r.startTs,e[25]=g):g=e[25];let x;e[26]!==g?(x=(0,s.jsx)("span",{className:"flex-1 truncate text-right font-mono text-xs tabular-nums text-muted-foreground",children:g}),e[26]=g,e[27]=x):x=e[27];let k;e[28]!==t||e[29]!==i||e[30]!==h||e[31]!==b||e[32]!==I||e[33]!==x||e[34]!==c||e[35]!==v||e[36]!==_||e[37]!==y||e[38]!==w?(k=(0,s.jsxs)("button",{"aria-controls":c,"aria-expanded":t,className:"flex w-full items-center gap-3 px-3 py-2 text-left hover:bg-muted/50","data-testid":v,onClick:i,type:"button",children:[_,y,w,h,b,I,x]}),e[28]=t,e[29]=i,e[30]=h,e[31]=b,e[32]=I,e[33]=x,e[34]=c,e[35]=v,e[36]=_,e[37]=y,e[38]=w,e[39]=k):k=e[39];let f;e[40]!==t||e[41]!==a||e[42]!==r.durationMs||e[43]!==r.spans||e[44]!==r.traceId?(f=t&&(0,s.jsxs)("div",{className:"bg-muted/20","data-testid":`tr-waterfall-${r.traceId}`,id:`tr-waterfall-${r.traceId}`,children:[(0,s.jsx)(Re,{durationMs:r.durationMs,spans:r.spans}),a.length>0&&(0,s.jsx)(ze,{entries:a})]}),e[40]=t,e[41]=a,e[42]=r.durationMs,e[43]=r.spans,e[44]=r.traceId,e[45]=f):f=e[45];let N;return e[46]!==k||e[47]!==f||e[48]!==u?(N=(0,s.jsxs)("div",{className:"border-b border-border last:border-b-0","data-testid":u,children:[k,f]}),e[46]=k,e[47]=f,e[48]=u,e[49]=N):N=e[49],N},"ze"),ut=m(n=>{let e=(0,B.c)(58),{initialShardKey:t}=n,a=W(),[l]=(0,O.useState)(ve),{queryShardKey:r,setShardKey:o,shardKey:d}=fe(l?.shardKey!==void 0&&l.shardKey!==""?l.shardKey:t??""),[i,u]=(0,O.useState)(l?.traceId??""),[c,v]=(0,O.useState)(!1),[$,_]=(0,O.useState)(He),y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=[],e[0]=y):y=e[0],(0,O.useEffect)(Ge,y);let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w={},e[1]=w):w=e[1];let M;e[2]!==r?(M={live:!0,shardKey:r},e[2]=r,e[3]=M):M=e[3];let{data:h,error:p,errorSource:b,isLoading:C,liveError:S}=ie(ce.getTraces,w,M),I;e[4]===Symbol.for("react.memo_cache_sentinel")?(I={},e[4]=I):I=e[4];let g=$.size>0,x;e[5]!==r||e[6]!==g?(x={enabled:g,live:!0,shardKey:r},e[5]=r,e[6]=g,e[7]=x):x=e[7];let{data:k}=ie(ce.getLogs,I,x),f,N;e[8]!==h||e[9]!==r?(f=m(()=>{h!==void 0&&he(r)},"p"),N=[h,r],e[8]=h,e[9]=r,e[10]=f,e[11]=N):(f=e[10],N=e[11]),(0,O.useEffect)(f,N);let R;if(e[12]!==h||e[13]!==p||e[14]!==b||e[15]!==$||e[16]!==C||e[17]!==S||e[18]!==k?.entries||e[19]!==c||e[20]!==i||e[21]!==o||e[22]!==d||e[23]!==a){let L=qe(h),A=h?.total??L.length,J=A>L.length,D=Te(L,i,c),U=Map.groupBy((k?.entries??[]).toReversed(),Qe),T;e[25]===Symbol.for("react.memo_cache_sentinel")?(T=m(E=>{u(E.target.value)},"P"),e[25]=T):T=e[25];let q=T,P;e[26]===Symbol.for("react.memo_cache_sentinel")?(P=m(E=>{_(ke=>{let ne=new Set(ke);return ne.has(E)?ne.delete(E):ne.add(E),ne})},"C"),e[26]=P):P=e[26];let z=P,F=p===null&&D.length===0&&!C,K;e[27]!==o||e[28]!==d?(K=(0,s.jsx)(pe,{onChange:o,testId:"tr-shard-input",value:d}),e[27]=o,e[28]=d,e[29]=K):K=e[29];let H;e[30]!==a?(H=a("Search traces"),e[30]=a,e[31]=H):H=e[31];let G;e[32]!==a?(G=a("search trace, span, or function"),e[32]=a,e[33]=G):G=e[33];let Q;e[34]!==i||e[35]!==H||e[36]!==G?(Q=(0,s.jsx)(me,{"aria-label":H,className:"h-8 w-56","data-testid":"tr-search",onChange:q,placeholder:G,value:i}),e[34]=i,e[35]=H,e[36]=G,e[37]=Q):Q=e[37];let V;e[38]!==c?(V=(0,s.jsx)(ge,{checked:c,"data-testid":"tr-only-errors",id:"tr-only-errors",onCheckedChange:v}),e[38]=c,e[39]=V):V=e[39];let X;e[40]!==a?(X=a("Errors only"),e[40]=a,e[41]=X):X=e[41];let Y;e[42]!==V||e[43]!==X?(Y=(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",htmlFor:"tr-only-errors",children:[V,X]}),e[42]=V,e[43]=X,e[44]=Y):Y=e[44];let Z;e[45]!==S?(Z=(0,s.jsx)(xe,{message:S,prefix:"tr"}),e[45]=S,e[46]=Z):Z=e[46];let re;e[47]!==K||e[48]!==Q||e[49]!==Y||e[50]!==Z?(re=(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[K,Q,Y,Z]}),e[47]=K,e[48]=Q,e[49]=Y,e[50]=Z,e[51]=re):re=e[51];let ae;e[52]!==p||e[53]!==b?(ae=p!==null&&(0,s.jsx)(be,{error:b,testId:"tr-error"}),e[52]=p,e[53]=b,e[54]=ae):ae=e[54];let se;e[55]!==F||e[56]!==a?(se=F&&(0,s.jsx)(ue,{description:a("Traces recorded with ctx.trace show up here as your app handles traffic. The span buffer resets when the shard hibernates."),icon:(0,s.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,s.jsx)("path",{d:"M4 6h10M7 12h13M10 18h7"})}),testId:"tr-empty",title:a("No traces")}),e[55]=F,e[56]=a,e[57]=se):se=e[57],R=(0,s.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-traces-panel",children:[re,ae,se,p===null&&J&&(0,s.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"tr-truncated",children:a("Showing the {shown} most recent of {total} traces in the buffer.",{shown:L.length,total:A})}),p===null&&D.length>0&&(0,s.jsx)("div",{"aria-label":a("Recent traces"),className:"overflow-hidden rounded-xl border border-border shadow-xs","data-testid":"tr-list",children:D.map(E=>(0,s.jsx)(We,{expanded:$.has(E.traceId),logs:U.get(E.traceId)??[],onToggle:z,trace:E},E.traceId))})]}),e[12]=h,e[13]=p,e[14]=b,e[15]=$,e[16]=C,e[17]=S,e[18]=k?.entries,e[19]=c,e[20]=i,e[21]=o,e[22]=d,e[23]=a,e[24]=R}else R=e[24];return R},"ft");function je(n,e){return(0,s.jsx)("div",{className:"flex items-center border-b border-border py-1 font-mono text-xs last:border-b-0","data-testid":"tr-log-row",role:"row",children:(0,s.jsx)(we,{entry:n})},`${String(e)}:${String(n.timestamp)}`)}m(je,"Ue");function He(){return new Set}m(He,"We");function Ge(){ye()}m(Ge,"qe");function Qe(n){return n.traceId}m(Qe,"He");export{ut as default};
@@ -1 +1 @@
1
- import{a as Ze}from"./chunk-BCAPWLLU.js";import"./chunk-GMR677FL.js";import"./chunk-GG6PIGQO.js";import"./chunk-SD4BERSA.js";import"./chunk-IC4L6G56.js";import{a as Me}from"./chunk-5Y3QLNWX.js";import{a as Ye}from"./chunk-IGCNMZSB.js";import"./chunk-I6A5C46N.js";import"./chunk-2QSHLBCO.js";import"./chunk-BGBLQ563.js";import"./chunk-IVFHIQOT.js";import"./chunk-QBWRC5YX.js";import"./chunk-4UOFSGUS.js";import{a as Xe}from"./chunk-Y32QIKBS.js";import{a as ze}from"./chunk-3CWGJYBB.js";import{a as We}from"./chunk-RMN2JN4S.js";import{b as Ve}from"./chunk-GRL5MG3Z.js";import{d as De,e as Fe}from"./chunk-SMIESS7P.js";import"./chunk-7T7UOTYK.js";import{R as Ae}from"./chunk-CFPZYHPY.js";import"./chunk-T6VMSOBB.js";import"./chunk-7QIFDWQV.js";import{a as Ee}from"./chunk-MWIKAR7F.js";import"./chunk-DJZYD5I5.js";import"./chunk-2OUPA2WJ.js";import{b as _e}from"./chunk-THIXMMZD.js";import"./chunk-6ST5ECQA.js";import{a as we}from"./chunk-322ZP3GW.js";import"./chunk-XXQUMVWH.js";import"./chunk-P4BOVBMR.js";import"./chunk-QLQADHFE.js";import{a as C}from"./chunk-VDW32UET.js";import{c as de}from"./chunk-BQNVN2OD.js";import{f as Te}from"./chunk-M3NGYXDR.js";import"./chunk-XBDKZZ67.js";import{a as ye}from"./chunk-XQCVZAGU.js";import{a as Ge,b as He,c as Qe,d as Ie,e as O,f as I}from"./chunk-WJQLNYGX.js";import{a as Le,e as Je}from"./chunk-WQH3LT2P.js";import{d as oe,f as Ue,g as Pe,h as Be,o as ke,r as Ne}from"./chunk-IUYFXK4X.js";import"./chunk-YC52XCPK.js";import{a as m,e as ie,f as qe,g as Ce,h as Ke,j as ne}from"./chunk-3XIESWL4.js";var me=ie(Ce(),1),ce=ie(qe(),1);var et=ie(Ce(),1);var j=ie(qe(),1);var l=ie(Ke(),1);var ct=Ue(C.runMigration),tt=m(a=>{let e=(0,et.c)(98),{initialShardKey:r}=a,s=Te(),t=oe(),{queryShardKey:d,setShardKey:i,shardKey:n}=ze(r),[u,b]=(0,j.useState)(""),[h,v]=(0,j.useState)("up"),[p,g]=(0,j.useState)(!0),[f,y]=(0,j.useState)(!1),[x,c]=(0,j.useState)(null),[N,k]=(0,j.useState)(null),K;e[0]!==n?(K=n.trim(),e[0]=n,e[1]=K):K=e[1];let M=K===d,S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S={},e[2]=S):S=e[2];let R;e[3]!==d?(R={live:!0,shardKey:d},e[3]=d,e[4]=R):R=e[4];let w=de(C.migrationStatus,S,R),$=w.data?.migrations??null,$e=w.error,{errorSource:je,liveError:Se}=w,ue,he;e[5]!==d||e[6]!==w.data?(ue=m(()=>{w.data!==void 0&&Ve(d)},"Q"),he=[w.data,d],e[5]=d,e[6]=w.data,e[7]=ue,e[8]=he):(ue=e[7],he=e[8]),(0,j.useEffect)(ue,he);let pe;if(e[9]!==s||e[10]!==h||e[11]!==p||e[12]!==u||e[13]!==n||e[14]!==w||e[15]!==t){let q=m(async()=>{let Re=u.trim();if(Re===""){k(t("Enter a migration id")),c(null);return}y(!0),k(null);try{let Oe=await s.query(ct,{direction:h,dryRun:p,id:Re},Pe(n));c(Oe),w.refetch()}catch(Oe){let lt=Oe;c(null),k(Be(lt))}y(!1)},"m");pe=m(()=>{ke(q())},"X"),e[9]=s,e[10]=h,e[11]=p,e[12]=u,e[13]=n,e[14]=w,e[15]=t,e[16]=pe}else pe=e[16];let fe=pe,ge;e[17]===Symbol.for("react.memo_cache_sentinel")?(ge=m(q=>{b(q.target.value)},"Z"),e[17]=ge):ge=e[17];let nt=ge,be;e[18]===Symbol.for("react.memo_cache_sentinel")?(be=m(q=>{v(q.target.value==="down"?"down":"up")},"H"),e[18]=be):be=e[18];let ot=be,ve;e[19]===Symbol.for("react.memo_cache_sentinel")?(ve=m(q=>{g(q.target.checked)},"ee"),e[19]=ve):ve=e[19];let dt=ve,T;e[20]!==i||e[21]!==n?(T=(0,l.jsx)(We,{onChange:i,testId:"mg-shard-input",value:n}),e[20]=i,e[21]=n,e[22]=T):T=e[22];let D;e[23]!==Se?(D=(0,l.jsx)(Ye,{message:Se,prefix:"mg"}),e[23]=Se,e[24]=D):D=e[24];let F;e[25]!==T||e[26]!==D?(F=(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[T,D]}),e[25]=T,e[26]=D,e[27]=F):F=e[27];let _;e[28]!==$e||e[29]!==je?(_=$e!==null&&(0,l.jsx)(we,{error:je,testId:"mg-status-error"}),e[28]=$e,e[29]=je,e[30]=_):_=e[30];let A;e[31]!==$||e[32]!==t?(A=$!==null&&$.length===0&&(0,l.jsx)(ye,{description:t("Data migrations you run against this shard will be tracked here."),icon:(0,l.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,l.jsx)("path",{d:"M4 12a8 8 0 0 1 13.7-5.6L20 8M20 4v4h-4M20 12a8 8 0 0 1-13.7 5.6L4 16m0 4v-4h4"})}),testId:"mg-empty",title:t("No migrations have run on this shard.")}),e[31]=$,e[32]=t,e[33]=A):A=e[33];let E;e[34]!==$||e[35]!==t?(E=$!==null&&$.length>0&&(0,l.jsx)(Le,{className:"overflow-hidden py-0",children:(0,l.jsx)(Je,{className:"px-0",children:(0,l.jsxs)(Ge,{"data-testid":"mg-table",children:[(0,l.jsx)(He,{children:(0,l.jsxs)(Ie,{children:[(0,l.jsx)(O,{children:t("id")}),(0,l.jsx)(O,{children:t("direction")}),(0,l.jsx)(O,{children:t("status")}),(0,l.jsx)(O,{children:t("processed")}),(0,l.jsx)(O,{children:t("changed")}),(0,l.jsx)(O,{children:t("updated")}),(0,l.jsx)(O,{children:t("error")})]})}),(0,l.jsx)(Qe,{children:$.map(mt)})]})})}),e[34]=$,e[35]=t,e[36]=E):E=e[36];let L;e[37]!==t?(L=t("Run migration"),e[37]=t,e[38]=L):L=e[38];let J;e[39]!==L?(J=(0,l.jsx)(Me,{children:L}),e[39]=L,e[40]=J):J=e[40];let U;e[41]!==t?(U=t("Migration id"),e[41]=t,e[42]=U):U=e[42];let P;e[43]!==t?(P=t("migration id"),e[43]=t,e[44]=P):P=e[44];let B;e[45]!==u||e[46]!==U||e[47]!==P?(B=(0,l.jsx)(Ae,{"aria-label":U,className:"w-auto","data-testid":"mg-id-input",onChange:nt,placeholder:P,value:u}),e[45]=u,e[46]=U,e[47]=P,e[48]=B):B=e[48];let V;e[49]!==t?(V=t("Direction"),e[49]=t,e[50]=V):V=e[50];let W;e[51]!==t?(W=t("up"),e[51]=t,e[52]=W):W=e[52];let z;e[53]!==W?(z=(0,l.jsx)("option",{value:"up",children:W}),e[53]=W,e[54]=z):z=e[54];let G;e[55]!==t?(G=t("down"),e[55]=t,e[56]=G):G=e[56];let H;e[57]!==G?(H=(0,l.jsx)("option",{value:"down",children:G}),e[57]=G,e[58]=H):H=e[58];let Q;e[59]!==h||e[60]!==V||e[61]!==z||e[62]!==H?(Q=(0,l.jsxs)("select",{"aria-label":V,className:"flex h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs transition-colors outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 dark:bg-input/30","data-testid":"mg-direction",onChange:ot,value:h,children:[z,H]}),e[59]=h,e[60]=V,e[61]=z,e[62]=H,e[63]=Q):Q=e[63];let X;e[64]!==p?(X=(0,l.jsx)("input",{checked:p,className:"size-4 accent-primary","data-testid":"mg-dry-run",id:"mg-dry-run",onChange:dt,type:"checkbox"}),e[64]=p,e[65]=X):X=e[65];let Y;e[66]!==t?(Y=t("Dry run"),e[66]=t,e[67]=Y):Y=e[67];let Z;e[68]!==X||e[69]!==Y?(Z=(0,l.jsxs)(Me,{className:"flex items-center gap-1.5",htmlFor:"mg-dry-run",children:[X,Y]}),e[68]=X,e[69]=Y,e[70]=Z):Z=e[70];let ee;e[71]!==p||e[72]!==fe||e[73]!==f||e[74]!==M||e[75]!==t?(ee=p?(0,l.jsx)(Ee,{"data-testid":"mg-run",disabled:f||!M,onClick:fe,type:"button",children:t(f?"Running\u2026":"Run")}):(0,l.jsx)(Xe,{confirmLabel:t(f?"Running\u2026":"Run migration?"),disabled:f||!M,onConfirm:fe,testId:"mg-run",children:t("Run")}),e[71]=p,e[72]=fe,e[73]=f,e[74]=M,e[75]=t,e[76]=ee):ee=e[76];let te;e[77]!==B||e[78]!==Q||e[79]!==Z||e[80]!==ee?(te=(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[B,Q,Z,ee]}),e[77]=B,e[78]=Q,e[79]=Z,e[80]=ee,e[81]=te):te=e[81];let ae;e[82]!==J||e[83]!==te?(ae=(0,l.jsxs)("div",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs",children:[J,te]}),e[82]=J,e[83]=te,e[84]=ae):ae=e[84];let re;e[85]!==N?(re=N!==null&&(0,l.jsx)("pre",{className:"text-sm text-destructive whitespace-pre-wrap","data-testid":"mg-run-error",role:"alert",children:N}),e[85]=N,e[86]=re):re=e[86];let se;e[87]!==x||e[88]!==t?(se=x!==null&&(0,l.jsxs)("p",{className:"text-sm text-muted-foreground","data-testid":"mg-run-result",children:[x.dryRun?t("Dry run: "):"",t("{status} \u2014 processed",{status:x.status}),x.processed,t(", changed"),x.changed]}),e[87]=x,e[88]=t,e[89]=se):se=e[89];let xe;return e[90]!==F||e[91]!==_||e[92]!==A||e[93]!==E||e[94]!==ae||e[95]!==re||e[96]!==se?(xe=(0,l.jsxs)("div",{className:"flex flex-col gap-3 pt-4","data-testid":"lunora-migrations",children:[F,_,A,E,ae,re,se]}),e[90]=F,e[91]=_,e[92]=A,e[93]=E,e[94]=ae,e[95]=re,e[96]=se,e[97]=xe):xe=e[97],xe},"yr");function mt(a){return(0,l.jsxs)(Ie,{"data-testid":`mg-row-${a.id}`,children:[(0,l.jsx)(I,{children:a.id}),(0,l.jsx)(I,{children:a.direction}),(0,l.jsx)(I,{children:(0,l.jsx)(_e,{variant:"secondary",children:a.status})}),(0,l.jsx)(I,{children:a.processed}),(0,l.jsx)(I,{children:a.changed}),(0,l.jsx)(I,{children:Ne(a.updatedAt)}),(0,l.jsx)(I,{children:a.error??""})]},a.id)}m(mt,"Ve");var o=ie(Ke(),1);var le=m(a=>typeof a=="object"&&a!==null,"k"),ut=m(a=>le(a)&&le(a.fields)&&le(a.indexes)&&le(a.relations)&&typeof a.shardMode=="string","z"),ht=m(a=>{if(a===void 0||a.trim()==="")return{status:"absent"};let e;try{e=JSON.parse(a)}catch(r){return{error:`baseline is not valid JSON: ${r instanceof Error?r.message:String(r)}`,status:"invalid"}}if(!le(e)||e.version!==1||!le(e.tables))return{error:`baseline is malformed or written by an incompatible version (expected version ${String(1)})`,status:"invalid"};for(let[r,s]of Object.entries(e.tables))if(!ut(s))return{error:`baseline table "${r}" has an invalid structure`,status:"invalid"};return{snapshot:{jurisdiction:typeof e.jurisdiction=="string"?e.jurisdiction:void 0,migrationIds:Array.isArray(e.migrationIds)?e.migrationIds:[],tables:e.tables,version:1},status:"ok"}},"B"),pt=m((a,e)=>a.unique===e.unique&&a.fields.length===e.fields.length&&a.fields.every((r,s)=>r===e.fields[s]),"L"),ft=m((a,e,r,s)=>{let t=[];return r.kind!==s.kind&&t.push({severity:"breaking",summary:`field ${a}.${e} changed type: ${r.kind} \u2192 ${s.kind} \u2014 add a data migration to convert existing values`,table:a,scope:"table",type:"changedFieldKind"}),r.optional&&!s.optional?t.push({severity:"breaking",summary:`field ${a}.${e} became required \u2014 rows missing it would be invalid; add a data migration to backfill it`,table:a,scope:"table",type:"fieldOptionalToRequired"}):!r.optional&&s.optional&&t.push({scope:"table",severity:"safe",summary:`field ${a}.${e} became optional`,table:a,type:"fieldRequiredToOptional"}),t},"Q"),gt=m((a,e,r)=>r.optional?{scope:"table",severity:"safe",summary:`added optional field ${a}.${e}`,table:a,type:"addedOptionalField"}:{severity:"breaking",summary:`added required field ${a}.${e} \u2014 existing rows have no value; add a data migration to backfill it`,table:a,scope:"table",type:"addedRequiredField"},"G"),bt=m((a,e,r,s)=>{for(let[t,d]of Object.entries(r.fields)){let i=e.fields[t];i===void 0?s.push(gt(a,t,d)):s.push(...ft(a,t,i,d))}for(let t of Object.keys(e.fields))r.fields[t]===void 0&&s.push({severity:"breaking",summary:`removed field ${a}.${t} \u2014 add a data migration if stored data must be cleaned up`,table:a,scope:"table",type:"removedField"})},"X"),vt=m((a,e,r,s)=>{for(let[t,d]of Object.entries(r.indexes)){let i=e.indexes[t];if(i===void 0){s.push({scope:"table",severity:"safe",summary:`added index ${t} on ${a}`,table:a,type:"addedIndex"});continue}pt(i,d)||s.push({severity:"breaking",summary:`index ${t} on ${a} changed shape \u2014 a query may have relied on the old index`,table:a,scope:"table",type:"changedIndex"})}for(let t of Object.keys(e.indexes))r.indexes[t]===void 0&&s.push({severity:"breaking",summary:`removed index ${t} on ${a} \u2014 a query that used \`.withIndex("${t}")\` would break`,table:a,scope:"table",type:"removedIndex"})},"Y"),xt=m((a,e,r,s)=>{for(let t of Object.keys(r.relations))e.relations[t]===void 0&&s.push({scope:"schema",severity:"safe",summary:`added relation ${a}.${t}`,table:a,type:"addedRelation"});for(let t of Object.keys(e.relations))r.relations[t]===void 0&&s.push({scope:"schema",severity:"breaking",summary:`removed relation ${a}.${t}`,table:a,type:"removedRelation"})},"Z"),yt=m((a,e,r,s)=>{e.shardMode!==r.shardMode&&s.push({severity:"breaking",summary:`table ${a} changed shard mode: ${e.shardMode} \u2192 ${r.shardMode} \u2014 its physical storage moves; add a data migration / re-shard plan`,table:a,scope:"table",type:"changedShardMode"}),bt(a,e,r,s),vt(a,e,r,s),xt(a,e,r,s)},"ee"),kt=m((a,e)=>{let r=[],s=a?.tables??{};for(let[t,d]of Object.entries(e.tables)){let i=s[t];if(i===void 0){r.push({scope:"table",severity:"safe",summary:`added table ${t}`,table:t,type:"addedTable"});continue}yt(t,i,d,r)}for(let t of Object.keys(s))e.tables[t]===void 0&&r.push({scope:"table",severity:"breaking",summary:`removed table ${t} \u2014 add a data migration if its data must be archived/cleaned up`,table:t,type:"removedTable"});if(a!==void 0&&a.jurisdiction!==e.jurisdiction){let t=a.jurisdiction??"(none)",d=e.jurisdiction??"(none)";r.push({scope:"schema",severity:"breaking",summary:`Durable Object jurisdiction changed from ${t} to ${d} \u2014 this re-homes every DO and strands all existing shard, scheduler, and session-DO data in the old region (no in-place migration; export then import to move it). Revert the change, or override the gate to proceed intentionally.`,type:"changedJurisdiction"})}return{changes:r}},"te"),at=m(a=>Object.entries(a.fields).map(([e,r])=>({name:e,optional:r.optional,ref:Object.values(a.relations).find(s=>s.field===e&&s.kind==="one")?.table,type:r.kind})),"T"),rt=m((a,e)=>{let r={},s=a?.fields??{},t=e?.fields??{};for(let[d,i]of Object.entries(t)){let n=s[d];n===void 0?r[d]=a===void 0?"unchanged":"added":r[d]=n.kind===i.kind&&n.optional===i.optional?"unchanged":"changed"}for(let d of Object.keys(s))t[d]===void 0&&(r[d]="removed");return r},"F"),Nt=m((a,e)=>{let{changes:r}=kt(a,e),s=new Set(r.filter(i=>i.scope==="table"&&i.table!==void 0).map(i=>i.table)),t=[],d=m((i,n)=>i?"added":s.has(n)?"changed":"context","o");for(let[i,n]of Object.entries(e.tables)){let u=a?.tables[i],b=d(u===void 0,i);t.push({columns:at(n),fieldStatus:rt(u,n),name:i,shardMode:n.shardMode,status:b})}for(let[i,n]of Object.entries(a?.tables??{}))e.tables[i]===void 0&&t.push({columns:at(n),fieldStatus:rt(n,void 0),name:i,shardMode:n.shardMode,status:"removed"});return t.sort((i,n)=>i.name.localeCompare(n.name)),{breakingCount:r.filter(i=>i.severity==="breaking").length,changes:r,tables:t}},"ae"),st=m(a=>{let e=ht(a);return e.status==="ok"?e.snapshot:void 0},"K"),wt={added:"ring-2 ring-emerald-500/60",changed:"ring-2 ring-amber-500/70",context:"opacity-55",removed:"opacity-70 ring-2 ring-destructive/60"},$t=m(a=>a==="global"?"global":"shard","se"),jt=m(a=>{let e=(0,me.c)(24),{appliedAt:r,hash:s,onSelect:t,selected:d,seq:i}=a,n=d?"border-s-primary bg-accent/60 text-foreground":"border-s-transparent text-muted-foreground hover:bg-accent/30 hover:text-foreground",u;e[0]!==n?(u=ne("flex w-full flex-col items-start gap-1 border-s-2 px-4 py-3 text-start outline-none transition-colors",n),e[0]=n,e[1]=u):u=e[1];let b=`sh-version-${s}`,h;e[2]!==s||e[3]!==t?(h=m(()=>{t(s)},"m"),e[2]=s,e[3]=t,e[4]=h):h=e[4];let v;e[5]!==i?(v=(0,o.jsxs)("span",{className:"font-mono text-[13px] tabular-nums",children:["v",i]}),e[5]=i,e[6]=v):v=e[6];let p;e[7]!==s?(p=s.slice(0,7),e[7]=s,e[8]=p):p=e[8];let g;e[9]!==p?(g=(0,o.jsx)("span",{className:"ms-auto font-mono text-[10px] tracking-wider text-muted-foreground/70 uppercase",children:p}),e[9]=p,e[10]=g):g=e[10];let f;e[11]!==v||e[12]!==g?(f=(0,o.jsxs)("span",{className:"flex w-full items-baseline gap-2",children:[v,g]}),e[11]=v,e[12]=g,e[13]=f):f=e[13];let y;e[14]!==r?(y=Ne(r),e[14]=r,e[15]=y):y=e[15];let x;e[16]!==y?(x=(0,o.jsx)("span",{className:"font-mono text-[10px] tracking-wide text-muted-foreground/70",children:y}),e[16]=y,e[17]=x):x=e[17];let c;return e[18]!==x||e[19]!==u||e[20]!==b||e[21]!==h||e[22]!==f?(c=(0,o.jsx)("li",{children:(0,o.jsxs)("button",{className:u,"data-testid":b,onClick:h,type:"button",children:[f,x]})}),e[18]=x,e[19]=u,e[20]=b,e[21]=h,e[22]=f,e[23]=c):c=e[23],c},"ie"),St=m(a=>{let e=(0,me.c)(26),{breaking:r,count:s,first:t}=a,d=oe();if(t){let g;e[0]!==s?(g=(0,o.jsx)("span",{className:"text-3xl leading-none font-light tracking-tight tabular-nums",children:s}),e[0]=s,e[1]=g):g=e[1];let f;e[2]!==d?(f=d("tables"),e[2]=d,e[3]=f):f=e[3];let y;e[4]!==f?(y=(0,o.jsx)("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:f}),e[4]=f,e[5]=y):y=e[5];let x;return e[6]!==g||e[7]!==y?(x=(0,o.jsxs)("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[g,y]}),e[6]=g,e[7]=y,e[8]=x):x=e[8],x}let i=r>0&&"text-destructive",n;e[9]!==i?(n=ne("text-3xl leading-none font-light tracking-tight tabular-nums",i),e[9]=i,e[10]=n):n=e[10];let u;e[11]!==s||e[12]!==n?(u=(0,o.jsx)("span",{className:n,children:s}),e[11]=s,e[12]=n,e[13]=u):u=e[13];let b;e[14]!==s||e[15]!==d?(b=d(s===1?"change":"changes"),e[14]=s,e[15]=d,e[16]=b):b=e[16];let h;e[17]!==b?(h=(0,o.jsx)("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:b}),e[17]=b,e[18]=h):h=e[18];let v;e[19]!==r||e[20]!==d?(v=r>0&&(0,o.jsxs)("span",{className:"font-mono text-[11px] tracking-widest text-destructive uppercase",children:["\xB7 ",d("{count} breaking",{count:r})]}),e[19]=r,e[20]=d,e[21]=v):v=e[21];let p;return e[22]!==u||e[23]!==h||e[24]!==v?(p=(0,o.jsxs)("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[u,h,v]}),e[22]=u,e[23]=h,e[24]=v,e[25]=p):p=e[25],p},"re"),it={addedIndex:{action:"added",kind:"index"},addedOptionalField:{action:"added",kind:"field?"},addedRelation:{action:"added",kind:"relation"},addedRequiredField:{action:"added",kind:"field"},addedTable:{action:"added",kind:"table"},changedFieldKind:{action:"changed",kind:"field kind"},changedIndex:{action:"changed",kind:"index"},changedJurisdiction:{action:"changed",kind:"jurisdiction"},changedShardMode:{action:"changed",kind:"shard mode"},fieldOptionalToRequired:{action:"changed",kind:"field \u2192 required"},fieldRequiredToOptional:{action:"changed",kind:"field \u2192 optional"},removedField:{action:"removed",kind:"field"},removedIndex:{action:"removed",kind:"index"},removedRelation:{action:"removed",kind:"relation"},removedTable:{action:"removed",kind:"table"}},Ot=m((a,e)=>{let r=`${it[a.type].action} ${e} `;return a.summary.startsWith(r)?a.summary.slice(r.length):a.summary},"oe"),It=m(a=>{let e=new Map;for(let s of a){let t=s.table??"",d=e.get(t);d===void 0?e.set(t,[s]):d.push(s)}let r=[...e].map(([s,t])=>({changes:t,table:s}));return[...r.filter(s=>s.table!==""),...r.filter(s=>s.table==="")]},"de"),Mt=m(a=>{let e=(0,me.c)(2),{children:r}=a,s;return e[0]!==r?(s=(0,o.jsx)("div",{className:"px-4 pt-4 pb-2 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:r}),e[0]=r,e[1]=s):s=e[1],s},"le"),Rt=m(({pane:a,shardKey:e=""})=>{let r=oe(),s=Fe(),t=De({strict:!1}).version,d=m(c=>{ke(s({search:{version:c},to:"/migrations"}))},"o"),i=de(C.schemaHistory,{},{shardKey:e}),n=i.data?.versions??[],u=t!==void 0&&n.some(c=>c.hash===t)?t:n[0]?.hash,b=n.findIndex(c=>c.hash===u),h=b===-1?void 0:n[b+1]?.hash,v=de(C.schemaVersion,{hash:u??""},{enabled:u!==void 0,shardKey:e}),p=de(C.schemaVersion,{hash:h??""},{enabled:h!==void 0,shardKey:e}),g=(0,ce.useMemo)(()=>{let c=st(v.data?.version?.snapshotJson);if(c!==void 0)return Nt(st(p.data?.version?.snapshotJson),c)},[v.data,p.data]),f=(0,ce.useMemo)(()=>(g?.tables??[]).map(c=>({columns:c.columns,name:c.name,tier:$t(c.shardMode)})),[g]),y=(0,ce.useMemo)(()=>{let c={};for(let N of g?.tables??[])c[N.name]=wt[N.status];return c},[g]);if(i.error!==null)return(0,o.jsx)(we,{error:i.errorSource,testId:"sh-error"});if(n.length===0)return(0,o.jsx)(ye,{description:r("Each distinct schema shape this shard runs is recorded here, so you can see what changed and when."),testId:"sh-empty",title:r("No schema versions recorded yet.")});let x=g?.changes??[];return(0,o.jsxs)("div",{className:"flex min-h-0 flex-1 gap-4","data-testid":"lunora-schema-history",children:[(0,o.jsxs)("nav",{className:"flex w-56 shrink-0 flex-col overflow-hidden border-e border-border","data-testid":"sh-timeline-rail",children:[(0,o.jsx)(Mt,{children:r("Schema versions")}),(0,o.jsx)("ul",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-timeline",children:n.map(c=>(0,o.jsx)(jt,{appliedAt:c.appliedAt,hash:c.hash,onSelect:d,selected:c.hash===u,seq:c.seq},c.hash))})]}),(0,o.jsxs)("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4 pe-1 pt-4",children:[(0,o.jsx)(St,{breaking:g?.breakingCount??0,count:h===void 0?f.length:x.length,first:h===void 0}),a==="diagram"?(0,o.jsx)("div",{className:"flex min-h-0 flex-1 flex-col",children:(0,o.jsx)(Ze,{fill:!0,nodeClasses:y,tables:f,testIdPrefix:"sh"})}):(0,o.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-changes",children:It(x).map(c=>{let N=(g?.tables??[]).find(k=>k.name===c.table);return(0,o.jsxs)("section",{className:"mb-6",children:[(0,o.jsxs)("div",{className:"flex items-baseline gap-3 border-b border-border/60 pb-1.5",children:[(0,o.jsx)("span",{className:"font-mono text-[13px] text-foreground",children:c.table===""?r("schema"):c.table}),N!==void 0&&(0,o.jsx)("span",{className:"font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums uppercase",children:r("{count} columns",{count:N.columns.length})}),c.changes.length>1&&(0,o.jsx)("span",{className:"ms-auto font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums",children:c.changes.length})]}),(0,o.jsx)("ul",{children:c.changes.map(k=>{let{action:K,kind:M}=it[k.type],S=k.severity==="breaking",R=Ot(k,M);return(0,o.jsxs)("li",{className:"flex items-baseline gap-4 border-s-2 py-1.5 ps-3 transition-colors hover:bg-accent/30",children:[(0,o.jsx)("span",{"aria-hidden":"true",className:ne("-ms-3 h-3 w-0.5 shrink-0 self-center",S?"bg-destructive":"bg-transparent")}),(0,o.jsxs)("span",{className:"w-44 shrink-0 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:[r(K)," ",M]}),R!==c.table&&(0,o.jsx)("span",{className:ne("min-w-0 font-mono text-[13px]",S?"text-destructive":"text-foreground"),children:R}),S&&(0,o.jsx)("span",{className:"ms-auto shrink-0 font-mono text-[10px] tracking-widest text-destructive uppercase",children:r("breaking")})]},`${k.type}-${k.summary}`)})})]},c.table)})})]})]})},"ce"),qt=m(a=>ne("-mb-px border-b-2 px-3 py-2.5 font-mono text-[11px] tracking-wider uppercase transition-colors outline-none","hover:bg-accent/40 focus-visible:bg-accent/40",a?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),"me"),da=m(a=>{let e=(0,me.c)(11),{initialShardKey:r}=a,s=oe(),[t,d]=(0,ce.useState)("diagram"),i;e[0]!==t?(i=m((v,p,g,f)=>(0,o.jsxs)("button",{"aria-selected":t===v,className:qt(t===v),"data-testid":g,onClick:m(()=>{d(v)},"onClick"),role:"tab",type:"button",children:[p,f!==void 0&&(0,o.jsx)("span",{className:"ms-2 tabular-nums text-muted-foreground/70",children:f})]}),"i"),e[0]=t,e[1]=i):i=e[1];let n=i,u;e[2]!==s||e[3]!==n?(u=(0,o.jsxs)("div",{className:"flex shrink-0 items-center gap-1 border-b border-border px-3","data-testid":"mg-panes",role:"tablist",children:[n("diagram",s("Diagram"),"mg-pane-diagram"),n("changes",s("Changes"),"mg-pane-changes"),n("data",s("Data migrations"),"mg-pane-data")]}),e[2]=s,e[3]=n,e[4]=u):u=e[4];let b;e[5]!==r||e[6]!==t?(b=(0,o.jsx)("div",{className:"flex min-h-0 flex-1 flex-col",children:t==="data"?(0,o.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto px-4",children:(0,o.jsx)(tt,{initialShardKey:r})}):(0,o.jsx)(Rt,{pane:t,shardKey:r})}),e[5]=r,e[6]=t,e[7]=b):b=e[7];let h;return e[8]!==u||e[9]!==b?(h=(0,o.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col pt-4","data-testid":"lunora-migrations-route",children:[u,b]}),e[8]=u,e[9]=b,e[10]=h):h=e[10],h},"je");export{da as default};
1
+ import{a as Ze}from"./chunk-7GNNMMT4.js";import"./chunk-GMR677FL.js";import"./chunk-GG6PIGQO.js";import"./chunk-SD4BERSA.js";import"./chunk-IC4L6G56.js";import{a as Me}from"./chunk-5Y3QLNWX.js";import{a as Ye}from"./chunk-IGCNMZSB.js";import"./chunk-I6A5C46N.js";import"./chunk-2QSHLBCO.js";import"./chunk-BGBLQ563.js";import"./chunk-IVFHIQOT.js";import"./chunk-QBWRC5YX.js";import"./chunk-4UOFSGUS.js";import{a as Xe}from"./chunk-Y32QIKBS.js";import{a as ze}from"./chunk-3CWGJYBB.js";import{a as We}from"./chunk-RMN2JN4S.js";import{b as Ve}from"./chunk-GRL5MG3Z.js";import{d as De,e as Fe}from"./chunk-SMIESS7P.js";import"./chunk-7T7UOTYK.js";import{R as Ae}from"./chunk-CFPZYHPY.js";import"./chunk-T6VMSOBB.js";import"./chunk-7QIFDWQV.js";import{a as Ee}from"./chunk-MWIKAR7F.js";import"./chunk-DJZYD5I5.js";import"./chunk-2OUPA2WJ.js";import{b as _e}from"./chunk-THIXMMZD.js";import"./chunk-6ST5ECQA.js";import{a as we}from"./chunk-6IZBFC3G.js";import"./chunk-XXQUMVWH.js";import"./chunk-ZNNKWEH5.js";import"./chunk-QLQADHFE.js";import{a as C}from"./chunk-VDW32UET.js";import{c as de}from"./chunk-UP7OTXKF.js";import{f as Te}from"./chunk-LYVP5PT6.js";import"./chunk-XBDKZZ67.js";import{a as ye}from"./chunk-XQCVZAGU.js";import{a as Ge,b as He,c as Qe,d as Ie,e as O,f as I}from"./chunk-WJQLNYGX.js";import{a as Le,e as Je}from"./chunk-WQH3LT2P.js";import{d as oe,f as Ue,g as Pe,h as Be,o as ke,r as Ne}from"./chunk-IUYFXK4X.js";import"./chunk-X7B6PLEW.js";import{a as m,e as ie,f as qe,g as Ce,h as Ke,j as ne}from"./chunk-3XIESWL4.js";var me=ie(Ce(),1),ce=ie(qe(),1);var et=ie(Ce(),1);var j=ie(qe(),1);var l=ie(Ke(),1);var ct=Ue(C.runMigration),tt=m(a=>{let e=(0,et.c)(98),{initialShardKey:r}=a,s=Te(),t=oe(),{queryShardKey:d,setShardKey:i,shardKey:n}=ze(r),[u,b]=(0,j.useState)(""),[h,v]=(0,j.useState)("up"),[p,g]=(0,j.useState)(!0),[f,y]=(0,j.useState)(!1),[x,c]=(0,j.useState)(null),[N,k]=(0,j.useState)(null),K;e[0]!==n?(K=n.trim(),e[0]=n,e[1]=K):K=e[1];let M=K===d,S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S={},e[2]=S):S=e[2];let R;e[3]!==d?(R={live:!0,shardKey:d},e[3]=d,e[4]=R):R=e[4];let w=de(C.migrationStatus,S,R),$=w.data?.migrations??null,$e=w.error,{errorSource:je,liveError:Se}=w,ue,he;e[5]!==d||e[6]!==w.data?(ue=m(()=>{w.data!==void 0&&Ve(d)},"Q"),he=[w.data,d],e[5]=d,e[6]=w.data,e[7]=ue,e[8]=he):(ue=e[7],he=e[8]),(0,j.useEffect)(ue,he);let pe;if(e[9]!==s||e[10]!==h||e[11]!==p||e[12]!==u||e[13]!==n||e[14]!==w||e[15]!==t){let q=m(async()=>{let Re=u.trim();if(Re===""){k(t("Enter a migration id")),c(null);return}y(!0),k(null);try{let Oe=await s.query(ct,{direction:h,dryRun:p,id:Re},Pe(n));c(Oe),w.refetch()}catch(Oe){let lt=Oe;c(null),k(Be(lt))}y(!1)},"m");pe=m(()=>{ke(q())},"X"),e[9]=s,e[10]=h,e[11]=p,e[12]=u,e[13]=n,e[14]=w,e[15]=t,e[16]=pe}else pe=e[16];let fe=pe,ge;e[17]===Symbol.for("react.memo_cache_sentinel")?(ge=m(q=>{b(q.target.value)},"Z"),e[17]=ge):ge=e[17];let nt=ge,be;e[18]===Symbol.for("react.memo_cache_sentinel")?(be=m(q=>{v(q.target.value==="down"?"down":"up")},"H"),e[18]=be):be=e[18];let ot=be,ve;e[19]===Symbol.for("react.memo_cache_sentinel")?(ve=m(q=>{g(q.target.checked)},"ee"),e[19]=ve):ve=e[19];let dt=ve,T;e[20]!==i||e[21]!==n?(T=(0,l.jsx)(We,{onChange:i,testId:"mg-shard-input",value:n}),e[20]=i,e[21]=n,e[22]=T):T=e[22];let D;e[23]!==Se?(D=(0,l.jsx)(Ye,{message:Se,prefix:"mg"}),e[23]=Se,e[24]=D):D=e[24];let F;e[25]!==T||e[26]!==D?(F=(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[T,D]}),e[25]=T,e[26]=D,e[27]=F):F=e[27];let _;e[28]!==$e||e[29]!==je?(_=$e!==null&&(0,l.jsx)(we,{error:je,testId:"mg-status-error"}),e[28]=$e,e[29]=je,e[30]=_):_=e[30];let A;e[31]!==$||e[32]!==t?(A=$!==null&&$.length===0&&(0,l.jsx)(ye,{description:t("Data migrations you run against this shard will be tracked here."),icon:(0,l.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,l.jsx)("path",{d:"M4 12a8 8 0 0 1 13.7-5.6L20 8M20 4v4h-4M20 12a8 8 0 0 1-13.7 5.6L4 16m0 4v-4h4"})}),testId:"mg-empty",title:t("No migrations have run on this shard.")}),e[31]=$,e[32]=t,e[33]=A):A=e[33];let E;e[34]!==$||e[35]!==t?(E=$!==null&&$.length>0&&(0,l.jsx)(Le,{className:"overflow-hidden py-0",children:(0,l.jsx)(Je,{className:"px-0",children:(0,l.jsxs)(Ge,{"data-testid":"mg-table",children:[(0,l.jsx)(He,{children:(0,l.jsxs)(Ie,{children:[(0,l.jsx)(O,{children:t("id")}),(0,l.jsx)(O,{children:t("direction")}),(0,l.jsx)(O,{children:t("status")}),(0,l.jsx)(O,{children:t("processed")}),(0,l.jsx)(O,{children:t("changed")}),(0,l.jsx)(O,{children:t("updated")}),(0,l.jsx)(O,{children:t("error")})]})}),(0,l.jsx)(Qe,{children:$.map(mt)})]})})}),e[34]=$,e[35]=t,e[36]=E):E=e[36];let L;e[37]!==t?(L=t("Run migration"),e[37]=t,e[38]=L):L=e[38];let J;e[39]!==L?(J=(0,l.jsx)(Me,{children:L}),e[39]=L,e[40]=J):J=e[40];let U;e[41]!==t?(U=t("Migration id"),e[41]=t,e[42]=U):U=e[42];let P;e[43]!==t?(P=t("migration id"),e[43]=t,e[44]=P):P=e[44];let B;e[45]!==u||e[46]!==U||e[47]!==P?(B=(0,l.jsx)(Ae,{"aria-label":U,className:"w-auto","data-testid":"mg-id-input",onChange:nt,placeholder:P,value:u}),e[45]=u,e[46]=U,e[47]=P,e[48]=B):B=e[48];let V;e[49]!==t?(V=t("Direction"),e[49]=t,e[50]=V):V=e[50];let W;e[51]!==t?(W=t("up"),e[51]=t,e[52]=W):W=e[52];let z;e[53]!==W?(z=(0,l.jsx)("option",{value:"up",children:W}),e[53]=W,e[54]=z):z=e[54];let G;e[55]!==t?(G=t("down"),e[55]=t,e[56]=G):G=e[56];let H;e[57]!==G?(H=(0,l.jsx)("option",{value:"down",children:G}),e[57]=G,e[58]=H):H=e[58];let Q;e[59]!==h||e[60]!==V||e[61]!==z||e[62]!==H?(Q=(0,l.jsxs)("select",{"aria-label":V,className:"flex h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs transition-colors outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 dark:bg-input/30","data-testid":"mg-direction",onChange:ot,value:h,children:[z,H]}),e[59]=h,e[60]=V,e[61]=z,e[62]=H,e[63]=Q):Q=e[63];let X;e[64]!==p?(X=(0,l.jsx)("input",{checked:p,className:"size-4 accent-primary","data-testid":"mg-dry-run",id:"mg-dry-run",onChange:dt,type:"checkbox"}),e[64]=p,e[65]=X):X=e[65];let Y;e[66]!==t?(Y=t("Dry run"),e[66]=t,e[67]=Y):Y=e[67];let Z;e[68]!==X||e[69]!==Y?(Z=(0,l.jsxs)(Me,{className:"flex items-center gap-1.5",htmlFor:"mg-dry-run",children:[X,Y]}),e[68]=X,e[69]=Y,e[70]=Z):Z=e[70];let ee;e[71]!==p||e[72]!==fe||e[73]!==f||e[74]!==M||e[75]!==t?(ee=p?(0,l.jsx)(Ee,{"data-testid":"mg-run",disabled:f||!M,onClick:fe,type:"button",children:t(f?"Running\u2026":"Run")}):(0,l.jsx)(Xe,{confirmLabel:t(f?"Running\u2026":"Run migration?"),disabled:f||!M,onConfirm:fe,testId:"mg-run",children:t("Run")}),e[71]=p,e[72]=fe,e[73]=f,e[74]=M,e[75]=t,e[76]=ee):ee=e[76];let te;e[77]!==B||e[78]!==Q||e[79]!==Z||e[80]!==ee?(te=(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[B,Q,Z,ee]}),e[77]=B,e[78]=Q,e[79]=Z,e[80]=ee,e[81]=te):te=e[81];let ae;e[82]!==J||e[83]!==te?(ae=(0,l.jsxs)("div",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs",children:[J,te]}),e[82]=J,e[83]=te,e[84]=ae):ae=e[84];let re;e[85]!==N?(re=N!==null&&(0,l.jsx)("pre",{className:"text-sm text-destructive whitespace-pre-wrap","data-testid":"mg-run-error",role:"alert",children:N}),e[85]=N,e[86]=re):re=e[86];let se;e[87]!==x||e[88]!==t?(se=x!==null&&(0,l.jsxs)("p",{className:"text-sm text-muted-foreground","data-testid":"mg-run-result",children:[x.dryRun?t("Dry run: "):"",t("{status} \u2014 processed",{status:x.status}),x.processed,t(", changed"),x.changed]}),e[87]=x,e[88]=t,e[89]=se):se=e[89];let xe;return e[90]!==F||e[91]!==_||e[92]!==A||e[93]!==E||e[94]!==ae||e[95]!==re||e[96]!==se?(xe=(0,l.jsxs)("div",{className:"flex flex-col gap-3 pt-4","data-testid":"lunora-migrations",children:[F,_,A,E,ae,re,se]}),e[90]=F,e[91]=_,e[92]=A,e[93]=E,e[94]=ae,e[95]=re,e[96]=se,e[97]=xe):xe=e[97],xe},"yr");function mt(a){return(0,l.jsxs)(Ie,{"data-testid":`mg-row-${a.id}`,children:[(0,l.jsx)(I,{children:a.id}),(0,l.jsx)(I,{children:a.direction}),(0,l.jsx)(I,{children:(0,l.jsx)(_e,{variant:"secondary",children:a.status})}),(0,l.jsx)(I,{children:a.processed}),(0,l.jsx)(I,{children:a.changed}),(0,l.jsx)(I,{children:Ne(a.updatedAt)}),(0,l.jsx)(I,{children:a.error??""})]},a.id)}m(mt,"Ve");var o=ie(Ke(),1);var le=m(a=>typeof a=="object"&&a!==null,"k"),ut=m(a=>le(a)&&le(a.fields)&&le(a.indexes)&&le(a.relations)&&typeof a.shardMode=="string","z"),ht=m(a=>{if(a===void 0||a.trim()==="")return{status:"absent"};let e;try{e=JSON.parse(a)}catch(r){return{error:`baseline is not valid JSON: ${r instanceof Error?r.message:String(r)}`,status:"invalid"}}if(!le(e)||e.version!==1||!le(e.tables))return{error:`baseline is malformed or written by an incompatible version (expected version ${String(1)})`,status:"invalid"};for(let[r,s]of Object.entries(e.tables))if(!ut(s))return{error:`baseline table "${r}" has an invalid structure`,status:"invalid"};return{snapshot:{jurisdiction:typeof e.jurisdiction=="string"?e.jurisdiction:void 0,migrationIds:Array.isArray(e.migrationIds)?e.migrationIds:[],tables:e.tables,version:1},status:"ok"}},"B"),pt=m((a,e)=>a.unique===e.unique&&a.fields.length===e.fields.length&&a.fields.every((r,s)=>r===e.fields[s]),"L"),ft=m((a,e,r,s)=>{let t=[];return r.kind!==s.kind&&t.push({severity:"breaking",summary:`field ${a}.${e} changed type: ${r.kind} \u2192 ${s.kind} \u2014 add a data migration to convert existing values`,table:a,scope:"table",type:"changedFieldKind"}),r.optional&&!s.optional?t.push({severity:"breaking",summary:`field ${a}.${e} became required \u2014 rows missing it would be invalid; add a data migration to backfill it`,table:a,scope:"table",type:"fieldOptionalToRequired"}):!r.optional&&s.optional&&t.push({scope:"table",severity:"safe",summary:`field ${a}.${e} became optional`,table:a,type:"fieldRequiredToOptional"}),t},"Q"),gt=m((a,e,r)=>r.optional?{scope:"table",severity:"safe",summary:`added optional field ${a}.${e}`,table:a,type:"addedOptionalField"}:{severity:"breaking",summary:`added required field ${a}.${e} \u2014 existing rows have no value; add a data migration to backfill it`,table:a,scope:"table",type:"addedRequiredField"},"G"),bt=m((a,e,r,s)=>{for(let[t,d]of Object.entries(r.fields)){let i=e.fields[t];i===void 0?s.push(gt(a,t,d)):s.push(...ft(a,t,i,d))}for(let t of Object.keys(e.fields))r.fields[t]===void 0&&s.push({severity:"breaking",summary:`removed field ${a}.${t} \u2014 add a data migration if stored data must be cleaned up`,table:a,scope:"table",type:"removedField"})},"X"),vt=m((a,e,r,s)=>{for(let[t,d]of Object.entries(r.indexes)){let i=e.indexes[t];if(i===void 0){s.push({scope:"table",severity:"safe",summary:`added index ${t} on ${a}`,table:a,type:"addedIndex"});continue}pt(i,d)||s.push({severity:"breaking",summary:`index ${t} on ${a} changed shape \u2014 a query may have relied on the old index`,table:a,scope:"table",type:"changedIndex"})}for(let t of Object.keys(e.indexes))r.indexes[t]===void 0&&s.push({severity:"breaking",summary:`removed index ${t} on ${a} \u2014 a query that used \`.withIndex("${t}")\` would break`,table:a,scope:"table",type:"removedIndex"})},"Y"),xt=m((a,e,r,s)=>{for(let t of Object.keys(r.relations))e.relations[t]===void 0&&s.push({scope:"schema",severity:"safe",summary:`added relation ${a}.${t}`,table:a,type:"addedRelation"});for(let t of Object.keys(e.relations))r.relations[t]===void 0&&s.push({scope:"schema",severity:"breaking",summary:`removed relation ${a}.${t}`,table:a,type:"removedRelation"})},"Z"),yt=m((a,e,r,s)=>{e.shardMode!==r.shardMode&&s.push({severity:"breaking",summary:`table ${a} changed shard mode: ${e.shardMode} \u2192 ${r.shardMode} \u2014 its physical storage moves; add a data migration / re-shard plan`,table:a,scope:"table",type:"changedShardMode"}),bt(a,e,r,s),vt(a,e,r,s),xt(a,e,r,s)},"ee"),kt=m((a,e)=>{let r=[],s=a?.tables??{};for(let[t,d]of Object.entries(e.tables)){let i=s[t];if(i===void 0){r.push({scope:"table",severity:"safe",summary:`added table ${t}`,table:t,type:"addedTable"});continue}yt(t,i,d,r)}for(let t of Object.keys(s))e.tables[t]===void 0&&r.push({scope:"table",severity:"breaking",summary:`removed table ${t} \u2014 add a data migration if its data must be archived/cleaned up`,table:t,type:"removedTable"});if(a!==void 0&&a.jurisdiction!==e.jurisdiction){let t=a.jurisdiction??"(none)",d=e.jurisdiction??"(none)";r.push({scope:"schema",severity:"breaking",summary:`Durable Object jurisdiction changed from ${t} to ${d} \u2014 this re-homes every DO and strands all existing shard, scheduler, and session-DO data in the old region (no in-place migration; export then import to move it). Revert the change, or override the gate to proceed intentionally.`,type:"changedJurisdiction"})}return{changes:r}},"te"),at=m(a=>Object.entries(a.fields).map(([e,r])=>({name:e,optional:r.optional,ref:Object.values(a.relations).find(s=>s.field===e&&s.kind==="one")?.table,type:r.kind})),"T"),rt=m((a,e)=>{let r={},s=a?.fields??{},t=e?.fields??{};for(let[d,i]of Object.entries(t)){let n=s[d];n===void 0?r[d]=a===void 0?"unchanged":"added":r[d]=n.kind===i.kind&&n.optional===i.optional?"unchanged":"changed"}for(let d of Object.keys(s))t[d]===void 0&&(r[d]="removed");return r},"F"),Nt=m((a,e)=>{let{changes:r}=kt(a,e),s=new Set(r.filter(i=>i.scope==="table"&&i.table!==void 0).map(i=>i.table)),t=[],d=m((i,n)=>i?"added":s.has(n)?"changed":"context","o");for(let[i,n]of Object.entries(e.tables)){let u=a?.tables[i],b=d(u===void 0,i);t.push({columns:at(n),fieldStatus:rt(u,n),name:i,shardMode:n.shardMode,status:b})}for(let[i,n]of Object.entries(a?.tables??{}))e.tables[i]===void 0&&t.push({columns:at(n),fieldStatus:rt(n,void 0),name:i,shardMode:n.shardMode,status:"removed"});return t.sort((i,n)=>i.name.localeCompare(n.name)),{breakingCount:r.filter(i=>i.severity==="breaking").length,changes:r,tables:t}},"ae"),st=m(a=>{let e=ht(a);return e.status==="ok"?e.snapshot:void 0},"K"),wt={added:"ring-2 ring-emerald-500/60",changed:"ring-2 ring-amber-500/70",context:"opacity-55",removed:"opacity-70 ring-2 ring-destructive/60"},$t=m(a=>a==="global"?"global":"shard","se"),jt=m(a=>{let e=(0,me.c)(24),{appliedAt:r,hash:s,onSelect:t,selected:d,seq:i}=a,n=d?"border-s-primary bg-accent/60 text-foreground":"border-s-transparent text-muted-foreground hover:bg-accent/30 hover:text-foreground",u;e[0]!==n?(u=ne("flex w-full flex-col items-start gap-1 border-s-2 px-4 py-3 text-start outline-none transition-colors",n),e[0]=n,e[1]=u):u=e[1];let b=`sh-version-${s}`,h;e[2]!==s||e[3]!==t?(h=m(()=>{t(s)},"m"),e[2]=s,e[3]=t,e[4]=h):h=e[4];let v;e[5]!==i?(v=(0,o.jsxs)("span",{className:"font-mono text-[13px] tabular-nums",children:["v",i]}),e[5]=i,e[6]=v):v=e[6];let p;e[7]!==s?(p=s.slice(0,7),e[7]=s,e[8]=p):p=e[8];let g;e[9]!==p?(g=(0,o.jsx)("span",{className:"ms-auto font-mono text-[10px] tracking-wider text-muted-foreground/70 uppercase",children:p}),e[9]=p,e[10]=g):g=e[10];let f;e[11]!==v||e[12]!==g?(f=(0,o.jsxs)("span",{className:"flex w-full items-baseline gap-2",children:[v,g]}),e[11]=v,e[12]=g,e[13]=f):f=e[13];let y;e[14]!==r?(y=Ne(r),e[14]=r,e[15]=y):y=e[15];let x;e[16]!==y?(x=(0,o.jsx)("span",{className:"font-mono text-[10px] tracking-wide text-muted-foreground/70",children:y}),e[16]=y,e[17]=x):x=e[17];let c;return e[18]!==x||e[19]!==u||e[20]!==b||e[21]!==h||e[22]!==f?(c=(0,o.jsx)("li",{children:(0,o.jsxs)("button",{className:u,"data-testid":b,onClick:h,type:"button",children:[f,x]})}),e[18]=x,e[19]=u,e[20]=b,e[21]=h,e[22]=f,e[23]=c):c=e[23],c},"ie"),St=m(a=>{let e=(0,me.c)(26),{breaking:r,count:s,first:t}=a,d=oe();if(t){let g;e[0]!==s?(g=(0,o.jsx)("span",{className:"text-3xl leading-none font-light tracking-tight tabular-nums",children:s}),e[0]=s,e[1]=g):g=e[1];let f;e[2]!==d?(f=d("tables"),e[2]=d,e[3]=f):f=e[3];let y;e[4]!==f?(y=(0,o.jsx)("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:f}),e[4]=f,e[5]=y):y=e[5];let x;return e[6]!==g||e[7]!==y?(x=(0,o.jsxs)("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[g,y]}),e[6]=g,e[7]=y,e[8]=x):x=e[8],x}let i=r>0&&"text-destructive",n;e[9]!==i?(n=ne("text-3xl leading-none font-light tracking-tight tabular-nums",i),e[9]=i,e[10]=n):n=e[10];let u;e[11]!==s||e[12]!==n?(u=(0,o.jsx)("span",{className:n,children:s}),e[11]=s,e[12]=n,e[13]=u):u=e[13];let b;e[14]!==s||e[15]!==d?(b=d(s===1?"change":"changes"),e[14]=s,e[15]=d,e[16]=b):b=e[16];let h;e[17]!==b?(h=(0,o.jsx)("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:b}),e[17]=b,e[18]=h):h=e[18];let v;e[19]!==r||e[20]!==d?(v=r>0&&(0,o.jsxs)("span",{className:"font-mono text-[11px] tracking-widest text-destructive uppercase",children:["\xB7 ",d("{count} breaking",{count:r})]}),e[19]=r,e[20]=d,e[21]=v):v=e[21];let p;return e[22]!==u||e[23]!==h||e[24]!==v?(p=(0,o.jsxs)("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[u,h,v]}),e[22]=u,e[23]=h,e[24]=v,e[25]=p):p=e[25],p},"re"),it={addedIndex:{action:"added",kind:"index"},addedOptionalField:{action:"added",kind:"field?"},addedRelation:{action:"added",kind:"relation"},addedRequiredField:{action:"added",kind:"field"},addedTable:{action:"added",kind:"table"},changedFieldKind:{action:"changed",kind:"field kind"},changedIndex:{action:"changed",kind:"index"},changedJurisdiction:{action:"changed",kind:"jurisdiction"},changedShardMode:{action:"changed",kind:"shard mode"},fieldOptionalToRequired:{action:"changed",kind:"field \u2192 required"},fieldRequiredToOptional:{action:"changed",kind:"field \u2192 optional"},removedField:{action:"removed",kind:"field"},removedIndex:{action:"removed",kind:"index"},removedRelation:{action:"removed",kind:"relation"},removedTable:{action:"removed",kind:"table"}},Ot=m((a,e)=>{let r=`${it[a.type].action} ${e} `;return a.summary.startsWith(r)?a.summary.slice(r.length):a.summary},"oe"),It=m(a=>{let e=new Map;for(let s of a){let t=s.table??"",d=e.get(t);d===void 0?e.set(t,[s]):d.push(s)}let r=[...e].map(([s,t])=>({changes:t,table:s}));return[...r.filter(s=>s.table!==""),...r.filter(s=>s.table==="")]},"de"),Mt=m(a=>{let e=(0,me.c)(2),{children:r}=a,s;return e[0]!==r?(s=(0,o.jsx)("div",{className:"px-4 pt-4 pb-2 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:r}),e[0]=r,e[1]=s):s=e[1],s},"le"),Rt=m(({pane:a,shardKey:e=""})=>{let r=oe(),s=Fe(),t=De({strict:!1}).version,d=m(c=>{ke(s({search:{version:c},to:"/migrations"}))},"o"),i=de(C.schemaHistory,{},{shardKey:e}),n=i.data?.versions??[],u=t!==void 0&&n.some(c=>c.hash===t)?t:n[0]?.hash,b=n.findIndex(c=>c.hash===u),h=b===-1?void 0:n[b+1]?.hash,v=de(C.schemaVersion,{hash:u??""},{enabled:u!==void 0,shardKey:e}),p=de(C.schemaVersion,{hash:h??""},{enabled:h!==void 0,shardKey:e}),g=(0,ce.useMemo)(()=>{let c=st(v.data?.version?.snapshotJson);if(c!==void 0)return Nt(st(p.data?.version?.snapshotJson),c)},[v.data,p.data]),f=(0,ce.useMemo)(()=>(g?.tables??[]).map(c=>({columns:c.columns,name:c.name,tier:$t(c.shardMode)})),[g]),y=(0,ce.useMemo)(()=>{let c={};for(let N of g?.tables??[])c[N.name]=wt[N.status];return c},[g]);if(i.error!==null)return(0,o.jsx)(we,{error:i.errorSource,testId:"sh-error"});if(n.length===0)return(0,o.jsx)(ye,{description:r("Each distinct schema shape this shard runs is recorded here, so you can see what changed and when."),testId:"sh-empty",title:r("No schema versions recorded yet.")});let x=g?.changes??[];return(0,o.jsxs)("div",{className:"flex min-h-0 flex-1 gap-4","data-testid":"lunora-schema-history",children:[(0,o.jsxs)("nav",{className:"flex w-56 shrink-0 flex-col overflow-hidden border-e border-border","data-testid":"sh-timeline-rail",children:[(0,o.jsx)(Mt,{children:r("Schema versions")}),(0,o.jsx)("ul",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-timeline",children:n.map(c=>(0,o.jsx)(jt,{appliedAt:c.appliedAt,hash:c.hash,onSelect:d,selected:c.hash===u,seq:c.seq},c.hash))})]}),(0,o.jsxs)("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4 pe-1 pt-4",children:[(0,o.jsx)(St,{breaking:g?.breakingCount??0,count:h===void 0?f.length:x.length,first:h===void 0}),a==="diagram"?(0,o.jsx)("div",{className:"flex min-h-0 flex-1 flex-col",children:(0,o.jsx)(Ze,{fill:!0,nodeClasses:y,tables:f,testIdPrefix:"sh"})}):(0,o.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-changes",children:It(x).map(c=>{let N=(g?.tables??[]).find(k=>k.name===c.table);return(0,o.jsxs)("section",{className:"mb-6",children:[(0,o.jsxs)("div",{className:"flex items-baseline gap-3 border-b border-border/60 pb-1.5",children:[(0,o.jsx)("span",{className:"font-mono text-[13px] text-foreground",children:c.table===""?r("schema"):c.table}),N!==void 0&&(0,o.jsx)("span",{className:"font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums uppercase",children:r("{count} columns",{count:N.columns.length})}),c.changes.length>1&&(0,o.jsx)("span",{className:"ms-auto font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums",children:c.changes.length})]}),(0,o.jsx)("ul",{children:c.changes.map(k=>{let{action:K,kind:M}=it[k.type],S=k.severity==="breaking",R=Ot(k,M);return(0,o.jsxs)("li",{className:"flex items-baseline gap-4 border-s-2 py-1.5 ps-3 transition-colors hover:bg-accent/30",children:[(0,o.jsx)("span",{"aria-hidden":"true",className:ne("-ms-3 h-3 w-0.5 shrink-0 self-center",S?"bg-destructive":"bg-transparent")}),(0,o.jsxs)("span",{className:"w-44 shrink-0 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:[r(K)," ",M]}),R!==c.table&&(0,o.jsx)("span",{className:ne("min-w-0 font-mono text-[13px]",S?"text-destructive":"text-foreground"),children:R}),S&&(0,o.jsx)("span",{className:"ms-auto shrink-0 font-mono text-[10px] tracking-widest text-destructive uppercase",children:r("breaking")})]},`${k.type}-${k.summary}`)})})]},c.table)})})]})]})},"ce"),qt=m(a=>ne("-mb-px border-b-2 px-3 py-2.5 font-mono text-[11px] tracking-wider uppercase transition-colors outline-none","hover:bg-accent/40 focus-visible:bg-accent/40",a?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),"me"),da=m(a=>{let e=(0,me.c)(11),{initialShardKey:r}=a,s=oe(),[t,d]=(0,ce.useState)("diagram"),i;e[0]!==t?(i=m((v,p,g,f)=>(0,o.jsxs)("button",{"aria-selected":t===v,className:qt(t===v),"data-testid":g,onClick:m(()=>{d(v)},"onClick"),role:"tab",type:"button",children:[p,f!==void 0&&(0,o.jsx)("span",{className:"ms-2 tabular-nums text-muted-foreground/70",children:f})]}),"i"),e[0]=t,e[1]=i):i=e[1];let n=i,u;e[2]!==s||e[3]!==n?(u=(0,o.jsxs)("div",{className:"flex shrink-0 items-center gap-1 border-b border-border px-3","data-testid":"mg-panes",role:"tablist",children:[n("diagram",s("Diagram"),"mg-pane-diagram"),n("changes",s("Changes"),"mg-pane-changes"),n("data",s("Data migrations"),"mg-pane-data")]}),e[2]=s,e[3]=n,e[4]=u):u=e[4];let b;e[5]!==r||e[6]!==t?(b=(0,o.jsx)("div",{className:"flex min-h-0 flex-1 flex-col",children:t==="data"?(0,o.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto px-4",children:(0,o.jsx)(tt,{initialShardKey:r})}):(0,o.jsx)(Rt,{pane:t,shardKey:r})}),e[5]=r,e[6]=t,e[7]=b):b=e[7];let h;return e[8]!==u||e[9]!==b?(h=(0,o.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col pt-4","data-testid":"lunora-migrations-route",children:[u,b]}),e[8]=u,e[9]=b,e[10]=h):h=e[10],h},"je");export{da as default};
@@ -1 +1 @@
1
- import{a as ge,b as fe,c as xe,d as Ne,e as we}from"./chunk-RA5DW5MU.js";import"./chunk-2PJNAWB3.js";import"./chunk-SD4BERSA.js";import"./chunk-IC4L6G56.js";import{a as ce}from"./chunk-V53KNYRN.js";import{a as ue}from"./chunk-3DH35OZ5.js";import{a as q}from"./chunk-5Y3QLNWX.js";import{g as me,h as ve,i as pe,j as ye}from"./chunk-A6ZHBJ76.js";import"./chunk-SDVDPAD2.js";import"./chunk-3C3CG7ZK.js";import"./chunk-I6A5C46N.js";import"./chunk-2QSHLBCO.js";import"./chunk-BGBLQ563.js";import"./chunk-IVFHIQOT.js";import"./chunk-QBWRC5YX.js";import"./chunk-HPFLBYRI.js";import"./chunk-CZZWYUTR.js";import"./chunk-SFDOII3B.js";import"./chunk-SMIESS7P.js";import{R as ae}from"./chunk-CFPZYHPY.js";import"./chunk-T6VMSOBB.js";import"./chunk-7QIFDWQV.js";import{a as B}from"./chunk-MWIKAR7F.js";import"./chunk-DJZYD5I5.js";import"./chunk-2OUPA2WJ.js";import{b as he}from"./chunk-THIXMMZD.js";import"./chunk-6ST5ECQA.js";import"./chunk-QLQADHFE.js";import"./chunk-VDW32UET.js";import"./chunk-BQNVN2OD.js";import{f as G}from"./chunk-M3NGYXDR.js";import"./chunk-XBDKZZ67.js";import{a as ke}from"./chunk-XQCVZAGU.js";import{a as se,b as ie,c as oe,d as Q,e as X,f as Y}from"./chunk-WJQLNYGX.js";import{a as re,e as ne}from"./chunk-WQH3LT2P.js";import{d as R,h as Z,l as be,o as A,q as de}from"./chunk-IUYFXK4X.js";import"./chunk-YC52XCPK.js";import{a as i,e as le,f as Oe,g as _e,h as De}from"./chunk-3XIESWL4.js";var $=le(Oe(),1);var ee=le(_e(),1);var a=le(De(),1);var Je=i(r=>{let e=r.trim();if(e==="")return;let d=Number(e);return Number.isFinite(d)&&d>0?Math.floor(d):void 0},"_e"),Le=i(r=>r===void 0?"\u2014":new Date(r*1e3).toISOString(),"Je"),Pe=i(r=>new TextEncoder().encode(r).length,"De"),Fe=i(r=>{if(r.trim()!=="")try{return JSON.stringify(JSON.parse(r),void 0,2)}catch{return}},"ge"),Ke=i(r=>{if(r.trim()==="")return!0;try{return JSON.parse(r),!0}catch{return!1}},"xe"),Ee=[{key:"seconds",seconds:1},{key:"minutes",seconds:60},{key:"hours",seconds:3600},{key:"days",seconds:86400}],Ce=i((r,e)=>{let d=r.trim();if(d==="")return"";let u=Number(d),s=Ee.find(v=>v.key===e)?.seconds??1;return Number.isFinite(u)&&u>0?String(Math.round(u*s)):d},"ue"),Ve=i(r=>{let e=r.trim();if(e==="")return!0;let d=Number(e);return Number.isInteger(d)&&d>=60},"Ce"),Te=i((r,e,d,u)=>{let s=Je(r.ttl);return{expiration:s===void 0?u:void 0,expirationTtl:s,key:e,metadata:r.metadata.trim()===""?void 0:JSON.parse(r.metadata),namespace:d,value:r.value}},"we"),Me=i(r=>{let e=(0,ee.c)(60),{helper:d,id:u,invalid:s,onChange:v,testId:o}=r,t=R(),[l,p]=(0,$.useState)(""),[c,x]=(0,$.useState)("seconds"),g;e[0]!==v||e[1]!==c?(g=i(f=>{p(f.target.value),v(Ce(f.target.value,c))},"f"),e[0]=v,e[1]=c,e[2]=g):g=e[2];let O=g,V;e[3]!==l||e[4]!==v?(V=i(f=>{f!==null&&(x(f),v(Ce(l,f)))},"K"),e[3]=l,e[4]=v,e[5]=V):V=e[5];let _=V,y;e[6]!==t?(y=t("days"),e[6]=t,e[7]=y):y=e[7];let m;e[8]!==t?(m=t("hours"),e[8]=t,e[9]=m):m=e[9];let h;e[10]!==t?(h=t("minutes"),e[10]=t,e[11]=h):h=e[11];let N;e[12]!==t?(N=t("seconds"),e[12]=t,e[13]=N):N=e[13];let w;e[14]!==y||e[15]!==m||e[16]!==h||e[17]!==N?(w={days:y,hours:m,minutes:h,seconds:N},e[14]=y,e[15]=m,e[16]=h,e[17]=N,e[18]=w):w=e[18];let C=w,b;e[19]!==t?(b=t("Expires after"),e[19]=t,e[20]=b):b=e[20];let S;e[21]!==u||e[22]!==b?(S=(0,a.jsx)(q,{className:"text-xs",htmlFor:u,children:b}),e[21]=u,e[22]=b,e[23]=S):S=e[23];let E;e[24]!==t?(E=t("No expiration"),e[24]=t,e[25]=E):E=e[25];let J;e[26]!==l||e[27]!==u||e[28]!==s||e[29]!==O||e[30]!==E||e[31]!==o?(J=(0,a.jsx)(ae,{"aria-invalid":s,className:"flex-1","data-testid":o,id:u,inputMode:"numeric",onChange:O,placeholder:E,value:l}),e[26]=l,e[27]=u,e[28]=s,e[29]=O,e[30]=E,e[31]=o,e[32]=J):J=e[32];let T;e[33]!==t?(T=t("TTL unit"),e[33]=t,e[34]=T):T=e[34];let P=`${o}-unit`,L;e[35]===Symbol.for("react.memo_cache_sentinel")?(L=(0,a.jsx)(fe,{}),e[35]=L):L=e[35];let M;e[36]!==T||e[37]!==P?(M=(0,a.jsx)(xe,{"aria-label":T,className:"w-[7.5rem]","data-testid":P,children:L}),e[36]=T,e[37]=P,e[38]=M):M=e[38];let n;e[39]!==C?(n=Ee.map(f=>(0,a.jsx)(we,{value:f.key,children:C[f.key]},f.key)),e[39]=C,e[40]=n):n=e[40];let k;e[41]!==n?(k=(0,a.jsx)(Ne,{children:n}),e[41]=n,e[42]=k):k=e[42];let F;e[43]!==_||e[44]!==M||e[45]!==k||e[46]!==c?(F=(0,a.jsxs)(ge,{onValueChange:_,value:c,children:[M,k]}),e[43]=_,e[44]=M,e[45]=k,e[46]=c,e[47]=F):F=e[47];let I;e[48]!==J||e[49]!==F?(I=(0,a.jsxs)("div",{className:"flex gap-2",children:[J,F]}),e[48]=J,e[49]=F,e[50]=I):I=e[50];let K;e[51]!==d||e[52]!==s||e[53]!==t||e[54]!==o?(K=s?(0,a.jsx)("p",{className:"text-xs text-destructive","data-testid":`${o}-invalid`,children:t("TTL must be at least 60 seconds.")}):d!==void 0&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:d}),e[51]=d,e[52]=s,e[53]=t,e[54]=o,e[55]=K):K=e[55];let D;return e[56]!==I||e[57]!==K||e[58]!==S?(D=(0,a.jsxs)("div",{className:"mb-3 grid gap-1",children:[S,I,K]}),e[56]=I,e[57]=K,e[58]=S,e[59]=D):D=e[59],D},"Se"),Ie=i(r=>{let e=(0,ee.c)(36),{id:d,invalidTestId:u,onChange:s,testId:v,valid:o,value:t}=r,l=R(),p;e[0]!==t?(p=Fe(t),e[0]=t,e[1]=p):p=e[1];let c=p,x;e[2]!==l?(x=l("Metadata (JSON)"),e[2]=l,e[3]=x):x=e[3];let g;e[4]!==d||e[5]!==x?(g=(0,a.jsx)(q,{className:"text-xs",htmlFor:d,children:x}),e[4]=d,e[5]=x,e[6]=g):g=e[6];let O=`${v}-format`,V=c===void 0,_;e[7]!==c||e[8]!==s?(_=i(()=>{c!==void 0&&s(c)},"O"),e[7]=c,e[8]=s,e[9]=_):_=e[9];let y;e[10]!==l?(y=l("Format JSON"),e[10]=l,e[11]=y):y=e[11];let m;e[12]!==O||e[13]!==V||e[14]!==_||e[15]!==y?(m=(0,a.jsx)(B,{"data-testid":O,disabled:V,onClick:_,size:"sm",variant:"outline",children:y}),e[12]=O,e[13]=V,e[14]=_,e[15]=y,e[16]=m):m=e[16];let h;e[17]!==g||e[18]!==m?(h=(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[g,m]}),e[17]=g,e[18]=m,e[19]=h):h=e[19];let N=!o,w;e[20]!==s?(w=i(E=>{s(E.target.value)},"N"),e[20]=s,e[21]=w):w=e[21];let C;e[22]!==d||e[23]!==N||e[24]!==w||e[25]!==v||e[26]!==t?(C=(0,a.jsx)(ce,{"aria-invalid":N,className:"min-h-[4rem] font-mono text-xs","data-testid":v,id:d,onChange:w,value:t}),e[22]=d,e[23]=N,e[24]=w,e[25]=v,e[26]=t,e[27]=C):C=e[27];let b;e[28]!==u||e[29]!==l||e[30]!==o?(b=!o&&(0,a.jsx)("p",{className:"text-xs text-destructive","data-testid":u,children:l("Metadata must be valid JSON.")}),e[28]=u,e[29]=l,e[30]=o,e[31]=b):b=e[31];let S;return e[32]!==C||e[33]!==b||e[34]!==h?(S=(0,a.jsxs)("div",{className:"mb-3 grid gap-1",children:[h,C,b]}),e[32]=C,e[33]=b,e[34]=h,e[35]=S):S=e[35],S},"$e"),$e={busy:!1,error:null,metadata:"",name:"",ttl:"",value:""},Be=i((r,e)=>{switch(e.type){case"setField":return{...r,[e.field]:e.value};case"submitFailed":return{...r,busy:!1,error:e.error};case"submitStart":return{...r,busy:!0,error:null};default:return r}},"Be"),je=i(r=>{let e=(0,ee.c)(73),{namespace:d,onCancel:u,onCreated:s}=r,v=G(),o=R(),[t,l]=(0,$.useReducer)(Be,$e),p;e[0]!==t.metadata?(p=Ke(t.metadata),e[0]=t.metadata,e[1]=p):p=e[1];let c=p,x;e[2]!==t.ttl?(x=Ve(t.ttl),e[2]=t.ttl,e[3]=x):x=e[3];let g=x,O;e[4]!==c||e[5]!==t.busy||e[6]!==t.name||e[7]!==g?(O=t.name.trim()!==""&&c&&g&&!t.busy,e[4]=c,e[5]=t.busy,e[6]=t.name,e[7]=g,e[8]=O):O=e[8];let V=O,_;e[9]!==V||e[10]!==v||e[11]!==d||e[12]!==s||e[13]!==t.metadata||e[14]!==t.name||e[15]!==t.ttl||e[16]!==t.value?(_=i(()=>{V&&(l({type:"submitStart"}),A((async()=>{try{await v.putKvValue(Te({metadata:t.metadata,ttl:t.ttl,value:t.value},t.name,d)),s()}catch(z){l({error:Z(z),type:"submitFailed"})}})()))},"O"),e[9]=V,e[10]=v,e[11]=d,e[12]=s,e[13]=t.metadata,e[14]=t.name,e[15]=t.ttl,e[16]=t.value,e[17]=_):_=e[17];let y=_,m;e[18]!==o?(m=o("Key name"),e[18]=o,e[19]=m):m=e[19];let h;e[20]!==m?(h=(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-create-name",children:m}),e[20]=m,e[21]=h):h=e[21];let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=i(z=>{l({field:"name",type:"setField",value:z.target.value})},"x"),e[22]=N):N=e[22];let w;e[23]!==o?(w=o("Key name"),e[23]=o,e[24]=w):w=e[24];let C;e[25]!==t.name||e[26]!==w?(C=(0,a.jsx)(ae,{autoFocus:!0,"data-testid":"kv-create-name",id:"kv-create-name",onChange:N,placeholder:w,value:t.name}),e[25]=t.name,e[26]=w,e[27]=C):C=e[27];let b;e[28]!==h||e[29]!==C?(b=(0,a.jsxs)("div",{className:"grid gap-1",children:[h,C]}),e[28]=h,e[29]=C,e[30]=b):b=e[30];let S;e[31]!==o?(S=o("Value"),e[31]=o,e[32]=S):S=e[32];let E;e[33]!==S?(E=(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-create-value",children:S}),e[33]=S,e[34]=E):E=e[34];let J;e[35]===Symbol.for("react.memo_cache_sentinel")?(J=i(z=>{l({field:"value",type:"setField",value:z.target.value})},"J"),e[35]=J):J=e[35];let T;e[36]!==t.value?(T=(0,a.jsx)(ce,{className:"min-h-[6rem] font-mono text-xs","data-testid":"kv-create-value",id:"kv-create-value",onChange:J,value:t.value}),e[36]=t.value,e[37]=T):T=e[37];let P;e[38]!==E||e[39]!==T?(P=(0,a.jsxs)("div",{className:"grid gap-1",children:[E,T]}),e[38]=E,e[39]=T,e[40]=P):P=e[40];let L=!g,M;e[41]===Symbol.for("react.memo_cache_sentinel")?(M=i(z=>{l({field:"ttl",type:"setField",value:z})},"M"),e[41]=M):M=e[41];let n;e[42]!==L?(n=(0,a.jsx)(Me,{id:"kv-create-ttl",invalid:L,onChange:M,testId:"kv-create-ttl"}),e[42]=L,e[43]=n):n=e[43];let k;e[44]===Symbol.for("react.memo_cache_sentinel")?(k=i(z=>{l({field:"metadata",type:"setField",value:z})},"h"),e[44]=k):k=e[44];let F;e[45]!==c||e[46]!==t.metadata?(F=(0,a.jsx)(Ie,{id:"kv-create-metadata",invalidTestId:"kv-create-metadata-invalid",onChange:k,testId:"kv-create-metadata",valid:c,value:t.metadata}),e[45]=c,e[46]=t.metadata,e[47]=F):F=e[47];let I=!V,K;e[48]!==t.busy||e[49]!==o?(K=t.busy?o("Creating\u2026"):o("Create key"),e[48]=t.busy,e[49]=o,e[50]=K):K=e[50];let D;e[51]!==y||e[52]!==I||e[53]!==K?(D=(0,a.jsx)(B,{"data-testid":"kv-create-submit",disabled:I,onClick:y,children:K}),e[51]=y,e[52]=I,e[53]=K,e[54]=D):D=e[54];let f=t.busy,j;e[55]!==o?(j=o("Cancel"),e[55]=o,e[56]=j):j=e[56];let H;e[57]!==u||e[58]!==t.busy||e[59]!==j?(H=(0,a.jsx)(B,{"data-testid":"kv-create-cancel",disabled:f,onClick:u,variant:"outline",children:j}),e[57]=u,e[58]=t.busy,e[59]=j,e[60]=H):H=e[60];let U;e[61]!==D||e[62]!==H?(U=(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[D,H]}),e[61]=D,e[62]=H,e[63]=U):U=e[63];let W;e[64]!==t.error?(W=t.error!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-create-error",role:"alert",children:t.error}),e[64]=t.error,e[65]=W):W=e[65];let te;return e[66]!==b||e[67]!==P||e[68]!==n||e[69]!==F||e[70]!==U||e[71]!==W?(te=(0,a.jsxs)("div",{className:"grid gap-3 px-4 pb-4","data-testid":"kv-create-form",children:[b,P,n,F,U,W]}),e[66]=b,e[67]=P,e[68]=n,e[69]=F,e[70]=U,e[71]=W,e[72]=te):te=e[72],te},"Pe"),ze={busy:"",editedMetadata:"",editedTtl:"",editedValue:"",loadError:null,loading:!0,value:null,writeError:null},Ae=i((r,e)=>{switch(e.type){case"deleteStart":return{...r,busy:"deleting",writeError:null};case"editMetadata":return{...r,editedMetadata:e.value};case"editTtl":return{...r,editedTtl:e.value};case"editValue":return{...r,editedValue:e.value};case"loaded":return{...r,editedMetadata:e.metadata===null||e.metadata===void 0?"":JSON.stringify(e.metadata,null,2),editedValue:e.value??"",loading:!1,value:e.value};case"loadFailed":return{...r,loadError:e.error,loading:!1};case"saveOk":return{...r,busy:"",value:r.editedValue};case"saveStart":return{...r,busy:"saving",writeError:null};case"writeFailed":return{...r,busy:"",writeError:e.error};default:return r}},"Ae"),He=i(r=>{let e=(0,ee.c)(67),{expiration:d,keyName:u,namespace:s,onDeleted:v}=r,o=G(),t=R(),[l,p]=(0,$.useReducer)(Ae,ze),c,x;e[0]!==o||e[1]!==u||e[2]!==s?(c=i(()=>{let f={cancelled:!1};return A((async()=>{try{let j=await o.getKvValue({key:u,namespace:s});f.cancelled||p({metadata:j.metadata,type:"loaded",value:j.value})}catch(j){let H=j;f.cancelled||p({error:Z(H),type:"loadFailed"})}})()),()=>{f.cancelled=!0}},"o"),x=[o,s,u],e[0]=o,e[1]=u,e[2]=s,e[3]=c,e[4]=x):(c=e[3],x=e[4]),(0,$.useEffect)(c,x);let g;e[5]===Symbol.for("react.memo_cache_sentinel")?(g=i(f=>{p({type:"editValue",value:f.target.value})},"f"),e[5]=g):g=e[5];let O=g,V;e[6]===Symbol.for("react.memo_cache_sentinel")?(V=i(f=>{p({type:"editMetadata",value:f})},"K"),e[6]=V):V=e[6];let _=V,y;e[7]!==l.editedValue?(y=Fe(l.editedValue),e[7]=l.editedValue,e[8]=y):y=e[8];let m=y,h;e[9]!==l.editedMetadata?(h=Ke(l.editedMetadata),e[9]=l.editedMetadata,e[10]=h):h=e[10];let N=h,w;e[11]!==l.editedTtl?(w=Ve(l.editedTtl),e[11]=l.editedTtl,e[12]=w):w=e[12];let C=w,b;e[13]!==m?(b=i(()=>{m!==void 0&&p({type:"editValue",value:m})},"k"),e[13]=m,e[14]=b):b=e[14];let S=b,E;e[15]!==o||e[16]!==d||e[17]!==u||e[18]!==N||e[19]!==s||e[20]!==l.editedMetadata||e[21]!==l.editedTtl||e[22]!==l.editedValue||e[23]!==t?(E=i(()=>{if(!N){p({error:t("Metadata must be valid JSON."),type:"writeFailed"});return}p({type:"saveStart"}),A((async()=>{try{await o.putKvValue(Te({metadata:l.editedMetadata,ttl:l.editedTtl,value:l.editedValue},u,s,d)),p({type:"saveOk"})}catch(f){p({error:Z(f),type:"writeFailed"})}})())},"E"),e[15]=o,e[16]=d,e[17]=u,e[18]=N,e[19]=s,e[20]=l.editedMetadata,e[21]=l.editedTtl,e[22]=l.editedValue,e[23]=t,e[24]=E):E=e[24];let J=E,T;e[25]!==o||e[26]!==u||e[27]!==s||e[28]!==v?(T=i(()=>{p({type:"deleteStart"}),A((async()=>{try{await o.deleteKvKey({key:u,namespace:s}),v(u)}catch(f){p({error:Z(f),type:"writeFailed"})}})())},"V"),e[25]=o,e[26]=u,e[27]=s,e[28]=v,e[29]=T):T=e[29];let P=T,L;e[30]!==u?(L=i(()=>{de(u)},"D"),e[30]=u,e[31]=L):L=e[31];let M;e[32]!==t?(M=t("Copy key"),e[32]=t,e[33]=M):M=e[33];let n;e[34]!==L||e[35]!==M?(n=(0,a.jsx)("div",{className:"mb-2 flex justify-end",children:(0,a.jsx)(B,{"data-testid":"kv-copy-key-btn",onClick:L,size:"sm",variant:"outline",children:M})}),e[34]=L,e[35]=M,e[36]=n):n=e[36];let k;e[37]!==l.loadError?(k=l.loadError!==null&&(0,a.jsx)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-value-error",role:"alert",children:l.loadError}),e[37]=l.loadError,e[38]=k):k=e[38];let F;e[39]!==l.loading||e[40]!==t?(F=l.loading&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-value-loading",children:t("Loading\u2026")}),e[39]=l.loading,e[40]=t,e[41]=F):F=e[41];let I;e[42]!==m||e[43]!==N||e[44]!==P||e[45]!==S||e[46]!==J||e[47]!==l.busy||e[48]!==l.editedMetadata||e[49]!==l.editedValue||e[50]!==l.loading||e[51]!==l.value||e[52]!==l.writeError||e[53]!==t||e[54]!==C?(I=!l.loading&&l.value!==null&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"mb-1 flex flex-wrap items-center gap-2",children:[(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-value-editor",children:t("Value")}),m!==void 0&&(0,a.jsx)(he,{variant:"secondary",children:t("JSON")}),(0,a.jsx)("span",{className:"ml-auto text-xs tabular-nums text-muted-foreground","data-testid":"kv-value-size",children:be(Pe(l.editedValue))})]}),(0,a.jsx)("textarea",{"aria-label":t("KV value"),className:"mb-2 min-h-[8rem] w-full rounded border border-border bg-muted/30 p-2 font-mono text-xs","data-testid":"kv-value-editor",id:"kv-value-editor",onChange:O,value:l.editedValue}),(0,a.jsxs)("div",{className:"mb-3 flex flex-wrap gap-2",children:[(0,a.jsx)(B,{"data-testid":"kv-format-btn",disabled:m===void 0,onClick:S,size:"sm",variant:"outline",children:t("Format JSON")}),(0,a.jsx)(B,{"data-testid":"kv-copy-value-btn",onClick:i(()=>{de(l.editedValue)},"onClick"),size:"sm",variant:"outline",children:t("Copy value")})]}),(0,a.jsx)(Me,{helper:t("Leave blank to keep the current expiration."),id:"kv-ttl-input",invalid:!C,onChange:i(f=>{p({type:"editTtl",value:f})},"onChange"),testId:"kv-ttl-input"}),(0,a.jsx)(Ie,{id:"kv-metadata-editor",invalidTestId:"kv-metadata-invalid",onChange:_,testId:"kv-metadata-editor",valid:N,value:l.editedMetadata}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,a.jsx)(B,{"data-testid":"kv-save-btn",disabled:l.busy!==""||!N||!C,onClick:J,children:l.busy==="saving"?t("Saving\u2026"):t("Save")}),(0,a.jsx)(B,{"data-testid":"kv-delete-btn",disabled:l.busy!=="",onClick:P,variant:"destructive",children:l.busy==="deleting"?t("Deleting\u2026"):t("Delete")})]}),l.writeError!==null&&(0,a.jsx)("p",{className:"mt-2 text-sm text-destructive","data-testid":"kv-save-error",role:"alert",children:l.writeError})]}),e[42]=m,e[43]=N,e[44]=P,e[45]=S,e[46]=J,e[47]=l.busy,e[48]=l.editedMetadata,e[49]=l.editedValue,e[50]=l.loading,e[51]=l.value,e[52]=l.writeError,e[53]=t,e[54]=C,e[55]=I):I=e[55];let K;e[56]!==l.loadError||e[57]!==l.loading||e[58]!==l.value||e[59]!==t?(K=!l.loading&&l.value===null&&l.loadError===null&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-absent",children:t("Key is absent or has no value.")}),e[56]=l.loadError,e[57]=l.loading,e[58]=l.value,e[59]=t,e[60]=K):K=e[60];let D;return e[61]!==n||e[62]!==k||e[63]!==F||e[64]!==I||e[65]!==K?(D=(0,a.jsxs)("div",{className:"px-4 pb-4","data-testid":"kv-value-section",children:[n,k,F,I,K]}),e[61]=n,e[62]=k,e[63]=F,e[64]=I,e[65]=K,e[66]=D):D=e[66],D},"ze"),Se=100,Ze={appliedPrefix:"",bulk:[],bulkBusy:!1,bulkError:null,cursor:null,keys:null,listComplete:!1,loadError:null,loading:!1,prefixInput:"",reloadNonce:0,selectedKey:null},Re=i((r,e)=>{switch(e.type){case"appendPage":return{...r,cursor:e.cursor,keys:[...r.keys??[],...e.keys],listComplete:e.listComplete,loading:!1};case"applyFilter":return{...r,appliedPrefix:r.prefixInput,bulk:[],bulkError:null,cursor:null,keys:null,listComplete:!1,selectedKey:null};case"bulkDeleted":{let d=new Set(e.deleted);return{...r,bulk:r.bulk.filter(u=>!d.has(u)),bulkBusy:!1,bulkError:e.error,keys:r.keys===null?null:r.keys.filter(u=>!d.has(u.name)),selectedKey:r.selectedKey!==null&&d.has(r.selectedKey)?null:r.selectedKey}}case"bulkDeleteStart":return{...r,bulkBusy:!0,bulkError:null};case"firstPage":return{...r,cursor:e.cursor,keys:e.keys,listComplete:e.listComplete,loading:!1};case"keyDeleted":return{...r,bulk:r.bulk.filter(d=>d!==e.name),keys:r.keys===null?null:r.keys.filter(d=>d.name!==e.name),selectedKey:null};case"loadFailed":return{...r,loadError:e.error,loading:!1};case"loadStart":return{...r,loadError:null,loading:!0};case"prefixInput":return{...r,prefixInput:e.value};case"reload":return{...r,bulk:[],bulkError:null,reloadNonce:r.reloadNonce+1,selectedKey:null};case"selectKey":return{...r,selectedKey:e.name};case"toggleAllBulk":return{...r,bulk:e.names};case"toggleBulk":return{...r,bulk:r.bulk.includes(e.name)?r.bulk.filter(d=>d!==e.name):[...r.bulk,e.name]};default:return r}},"Re"),Ue=i(({namespace:r})=>{let e=G(),d=R(),[u,s]=(0,$.useReducer)(Re,Ze),{appliedPrefix:v,bulk:o,bulkBusy:t,bulkError:l,cursor:p,keys:c,listComplete:x,loadError:g,loading:O,prefixInput:V,reloadNonce:_,selectedKey:y}=u,[m,h]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let n={cancelled:!1};return A((async()=>{s({type:"loadStart"});try{let k=await e.listKvKeys({limit:Se,namespace:r,prefix:v===""?void 0:v});n.cancelled||s({cursor:k.cursor??null,keys:k.keys,listComplete:k.listComplete,type:"firstPage"})}catch(k){n.cancelled||s({error:Z(k),type:"loadFailed"})}})()),()=>{n.cancelled=!0}},[e,r,v,_]);let N=i(n=>{s({type:"prefixInput",value:n.target.value})},"x"),w=i(()=>{s({type:"applyFilter"})},"N"),C=i(n=>{s({name:n.currentTarget.dataset.key??null,type:"selectKey"})},"C"),b=i(()=>{p!==null&&(s({type:"loadStart"}),A((async()=>{try{let n=await e.listKvKeys({cursor:p,limit:Se,namespace:r,prefix:v===""?void 0:v});s({cursor:n.cursor??null,keys:n.keys,listComplete:n.listComplete,type:"appendPage"})}catch(n){s({error:Z(n),type:"loadFailed"})}})()))},"k"),S=i(n=>{s({name:n,type:"keyDeleted"})},"w"),E=i(n=>{s({name:n,type:"toggleBulk"})},"E"),J=i(n=>{s({names:n&&c!==null?c.map(k=>k.name):[],type:"toggleAllBulk"})},"J"),T=i(()=>{if(o.length===0)return;let n=[...o];s({type:"bulkDeleteStart"}),A((async()=>{let k=await Promise.allSettled(n.map(K=>e.deleteKvKey({key:K,namespace:r}))),F=n.filter((K,D)=>k[D]?.status==="fulfilled"),I=n.length-F.length;s({deleted:F,error:I>0?d("Failed to delete {count} keys.",{count:I}):null,type:"bulkDeleted"})})())},"V"),P=i(()=>{h(!1),s({type:"reload"})},"L"),L=c!==null&&c.length>0&&o.length===c.length,M=new Set(o);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("section",{className:"border border-border bg-card p-3","data-testid":"kv-keys-section",children:[(0,a.jsxs)("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[(0,a.jsx)(ae,{"aria-label":d("Filter keys by prefix"),className:"min-w-[16rem] flex-1","data-testid":"kv-prefix-input",onChange:N,placeholder:d("Filter by prefix\u2026"),value:V}),(0,a.jsx)(B,{"data-testid":"kv-filter-btn",disabled:O,onClick:w,children:d("Filter")}),(0,a.jsx)(B,{"data-testid":"kv-new-key-btn",onClick:i(()=>{h(n=>!n)},"onClick"),variant:"outline",children:d("New key")}),o.length>0&&(0,a.jsx)(B,{"data-testid":"kv-bulk-delete-btn",disabled:t,onClick:T,variant:"destructive",children:t?d("Deleting\u2026"):d("Delete {count}",{count:o.length})})]}),l!==null&&(0,a.jsx)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-bulk-error",role:"alert",children:l}),g!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-keys-error",role:"alert",children:g}),c!==null&&c.length===0&&!O&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-no-keys",children:d("No keys.")}),c!==null&&c.length>0&&(0,a.jsx)(re,{className:"overflow-hidden py-0",children:(0,a.jsx)(ne,{className:"px-0",children:(0,a.jsxs)(se,{"data-testid":"kv-key-table",children:[(0,a.jsx)(ie,{children:(0,a.jsxs)(Q,{children:[(0,a.jsx)(X,{className:"w-10",children:(0,a.jsx)(ue,{"aria-label":d("Select all"),checked:L,"data-testid":"kv-select-all",onCheckedChange:J})}),(0,a.jsx)(X,{children:d("Key")}),(0,a.jsx)(X,{children:d("Expiration")})]})}),(0,a.jsx)(oe,{children:c.map(n=>(0,a.jsxs)(Q,{className:n.name===y?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-key":n.name,"data-testid":`kv-key-row-${n.name}`,onClick:C,children:[(0,a.jsx)(Y,{onClick:i(k=>{k.stopPropagation()},"onClick"),children:(0,a.jsx)(ue,{"aria-label":d("Select {name}",{name:n.name}),checked:M.has(n.name),"data-testid":`kv-select-${n.name}`,onCheckedChange:i(()=>{E(n.name)},"onCheckedChange")})}),(0,a.jsx)(Y,{className:"font-mono text-xs",children:n.name}),(0,a.jsx)(Y,{className:"tabular-nums text-xs",children:Le(n.expiration)})]},n.name))})]})})}),!x&&p!==null&&(0,a.jsx)("div",{className:"mt-2",children:(0,a.jsx)(B,{"data-testid":"kv-load-more",disabled:O,onClick:b,variant:"outline",children:d(O?"Loading\u2026":"Load more")})})]}),(0,a.jsx)(me,{onOpenChange:i(n=>{n||h(!1)},"onOpenChange"),open:m,children:(0,a.jsxs)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-create-sheet",side:"right",children:[(0,a.jsx)(pe,{children:(0,a.jsx)(ye,{children:d("New key")})}),(0,a.jsx)(je,{namespace:r,onCancel:i(()=>{h(!1)},"onCancel"),onCreated:P})]})}),(0,a.jsx)(me,{onOpenChange:i(n=>{n||s({name:null,type:"selectKey"})},"onOpenChange"),open:y!==null,children:(0,a.jsxs)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-editor-sheet",side:"right",children:[(0,a.jsx)(pe,{children:(0,a.jsx)(ye,{className:"truncate font-mono text-xs",children:y})}),y!==null&&(0,a.jsx)(He,{expiration:c?.find(n=>n.name===y)?.expiration,keyName:y,namespace:r,onDeleted:S},`${r}:${y}`)]})})]})},"Ue"),it=i(({loadNamespaces:r}={})=>{let e=G(),d=R(),[u,s]=(0,$.useState)(null),[v,o]=(0,$.useState)(null),[t,l]=(0,$.useState)(null);(0,$.useEffect)(()=>{let c={cancelled:!1};return A((async()=>{try{let x=await(r??(()=>e.listKvNamespaces()))();c.cancelled||(s(x),o(null),l(g=>g??x[0]?.binding??null))}catch(x){c.cancelled||(s(null),o(Z(x)))}})()),()=>{c.cancelled=!0}},[e,r]);let p=i(c=>{l(c.currentTarget.dataset.ns??null)},"v");return(0,a.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-kv-browser",children:[v!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-ns-error",role:"alert",children:v}),u!==null&&u.length===0&&(0,a.jsx)(ke,{description:d("Add a kv_namespaces binding to wrangler.jsonc \u2014 it appears here automatically, no wiring needed."),icon:(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"M5 5h14v4H5V5Zm0 5h14v4H5v-4Zm0 5h14v4H5v-4Z"})}),testId:"kv-empty",title:d("No KV namespaces.")}),u!==null&&u.length>0&&(0,a.jsx)(re,{className:"overflow-hidden py-0",children:(0,a.jsx)(ne,{className:"px-0",children:(0,a.jsxs)(se,{"data-testid":"kv-namespace-table",children:[(0,a.jsx)(ie,{children:(0,a.jsx)(Q,{children:(0,a.jsx)(X,{children:d("Namespace")})})}),(0,a.jsx)(oe,{children:u.map(c=>(0,a.jsx)(Q,{className:c.binding===t?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-ns":c.binding,"data-testid":`kv-ns-row-${c.binding}`,onClick:p,children:(0,a.jsx)(Y,{className:"font-mono text-xs",children:c.binding})},c.binding))})]})})}),t!==null&&(0,a.jsx)(Ue,{namespace:t},t)]})},"ct");export{it as KvBrowser};
1
+ import{a as ge,b as fe,c as xe,d as Ne,e as we}from"./chunk-RA5DW5MU.js";import"./chunk-2PJNAWB3.js";import"./chunk-SD4BERSA.js";import"./chunk-IC4L6G56.js";import{a as ce}from"./chunk-V53KNYRN.js";import{a as ue}from"./chunk-3DH35OZ5.js";import{a as q}from"./chunk-5Y3QLNWX.js";import{g as me,h as ve,i as pe,j as ye}from"./chunk-A3DCTWSA.js";import"./chunk-4PDTGZDC.js";import"./chunk-3C3CG7ZK.js";import"./chunk-I6A5C46N.js";import"./chunk-2QSHLBCO.js";import"./chunk-BGBLQ563.js";import"./chunk-IVFHIQOT.js";import"./chunk-QBWRC5YX.js";import"./chunk-HPFLBYRI.js";import"./chunk-CZZWYUTR.js";import"./chunk-SFDOII3B.js";import"./chunk-SMIESS7P.js";import{R as ae}from"./chunk-CFPZYHPY.js";import"./chunk-T6VMSOBB.js";import"./chunk-7QIFDWQV.js";import{a as B}from"./chunk-MWIKAR7F.js";import"./chunk-DJZYD5I5.js";import"./chunk-2OUPA2WJ.js";import{b as he}from"./chunk-THIXMMZD.js";import"./chunk-6ST5ECQA.js";import"./chunk-QLQADHFE.js";import"./chunk-VDW32UET.js";import"./chunk-UP7OTXKF.js";import{f as G}from"./chunk-LYVP5PT6.js";import"./chunk-XBDKZZ67.js";import{a as ke}from"./chunk-XQCVZAGU.js";import{a as se,b as ie,c as oe,d as Q,e as X,f as Y}from"./chunk-WJQLNYGX.js";import{a as re,e as ne}from"./chunk-WQH3LT2P.js";import{d as R,h as Z,l as be,o as A,q as de}from"./chunk-IUYFXK4X.js";import"./chunk-X7B6PLEW.js";import{a as i,e as le,f as Oe,g as _e,h as De}from"./chunk-3XIESWL4.js";var $=le(Oe(),1);var ee=le(_e(),1);var a=le(De(),1);var Je=i(r=>{let e=r.trim();if(e==="")return;let d=Number(e);return Number.isFinite(d)&&d>0?Math.floor(d):void 0},"_e"),Le=i(r=>r===void 0?"\u2014":new Date(r*1e3).toISOString(),"Je"),Pe=i(r=>new TextEncoder().encode(r).length,"De"),Fe=i(r=>{if(r.trim()!=="")try{return JSON.stringify(JSON.parse(r),void 0,2)}catch{return}},"ge"),Ke=i(r=>{if(r.trim()==="")return!0;try{return JSON.parse(r),!0}catch{return!1}},"xe"),Ee=[{key:"seconds",seconds:1},{key:"minutes",seconds:60},{key:"hours",seconds:3600},{key:"days",seconds:86400}],Ce=i((r,e)=>{let d=r.trim();if(d==="")return"";let u=Number(d),s=Ee.find(v=>v.key===e)?.seconds??1;return Number.isFinite(u)&&u>0?String(Math.round(u*s)):d},"ue"),Ve=i(r=>{let e=r.trim();if(e==="")return!0;let d=Number(e);return Number.isInteger(d)&&d>=60},"Ce"),Te=i((r,e,d,u)=>{let s=Je(r.ttl);return{expiration:s===void 0?u:void 0,expirationTtl:s,key:e,metadata:r.metadata.trim()===""?void 0:JSON.parse(r.metadata),namespace:d,value:r.value}},"we"),Me=i(r=>{let e=(0,ee.c)(60),{helper:d,id:u,invalid:s,onChange:v,testId:o}=r,t=R(),[l,p]=(0,$.useState)(""),[c,x]=(0,$.useState)("seconds"),g;e[0]!==v||e[1]!==c?(g=i(f=>{p(f.target.value),v(Ce(f.target.value,c))},"f"),e[0]=v,e[1]=c,e[2]=g):g=e[2];let O=g,V;e[3]!==l||e[4]!==v?(V=i(f=>{f!==null&&(x(f),v(Ce(l,f)))},"K"),e[3]=l,e[4]=v,e[5]=V):V=e[5];let _=V,y;e[6]!==t?(y=t("days"),e[6]=t,e[7]=y):y=e[7];let m;e[8]!==t?(m=t("hours"),e[8]=t,e[9]=m):m=e[9];let h;e[10]!==t?(h=t("minutes"),e[10]=t,e[11]=h):h=e[11];let N;e[12]!==t?(N=t("seconds"),e[12]=t,e[13]=N):N=e[13];let w;e[14]!==y||e[15]!==m||e[16]!==h||e[17]!==N?(w={days:y,hours:m,minutes:h,seconds:N},e[14]=y,e[15]=m,e[16]=h,e[17]=N,e[18]=w):w=e[18];let C=w,b;e[19]!==t?(b=t("Expires after"),e[19]=t,e[20]=b):b=e[20];let S;e[21]!==u||e[22]!==b?(S=(0,a.jsx)(q,{className:"text-xs",htmlFor:u,children:b}),e[21]=u,e[22]=b,e[23]=S):S=e[23];let E;e[24]!==t?(E=t("No expiration"),e[24]=t,e[25]=E):E=e[25];let J;e[26]!==l||e[27]!==u||e[28]!==s||e[29]!==O||e[30]!==E||e[31]!==o?(J=(0,a.jsx)(ae,{"aria-invalid":s,className:"flex-1","data-testid":o,id:u,inputMode:"numeric",onChange:O,placeholder:E,value:l}),e[26]=l,e[27]=u,e[28]=s,e[29]=O,e[30]=E,e[31]=o,e[32]=J):J=e[32];let T;e[33]!==t?(T=t("TTL unit"),e[33]=t,e[34]=T):T=e[34];let P=`${o}-unit`,L;e[35]===Symbol.for("react.memo_cache_sentinel")?(L=(0,a.jsx)(fe,{}),e[35]=L):L=e[35];let M;e[36]!==T||e[37]!==P?(M=(0,a.jsx)(xe,{"aria-label":T,className:"w-[7.5rem]","data-testid":P,children:L}),e[36]=T,e[37]=P,e[38]=M):M=e[38];let n;e[39]!==C?(n=Ee.map(f=>(0,a.jsx)(we,{value:f.key,children:C[f.key]},f.key)),e[39]=C,e[40]=n):n=e[40];let k;e[41]!==n?(k=(0,a.jsx)(Ne,{children:n}),e[41]=n,e[42]=k):k=e[42];let F;e[43]!==_||e[44]!==M||e[45]!==k||e[46]!==c?(F=(0,a.jsxs)(ge,{onValueChange:_,value:c,children:[M,k]}),e[43]=_,e[44]=M,e[45]=k,e[46]=c,e[47]=F):F=e[47];let I;e[48]!==J||e[49]!==F?(I=(0,a.jsxs)("div",{className:"flex gap-2",children:[J,F]}),e[48]=J,e[49]=F,e[50]=I):I=e[50];let K;e[51]!==d||e[52]!==s||e[53]!==t||e[54]!==o?(K=s?(0,a.jsx)("p",{className:"text-xs text-destructive","data-testid":`${o}-invalid`,children:t("TTL must be at least 60 seconds.")}):d!==void 0&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:d}),e[51]=d,e[52]=s,e[53]=t,e[54]=o,e[55]=K):K=e[55];let D;return e[56]!==I||e[57]!==K||e[58]!==S?(D=(0,a.jsxs)("div",{className:"mb-3 grid gap-1",children:[S,I,K]}),e[56]=I,e[57]=K,e[58]=S,e[59]=D):D=e[59],D},"Se"),Ie=i(r=>{let e=(0,ee.c)(36),{id:d,invalidTestId:u,onChange:s,testId:v,valid:o,value:t}=r,l=R(),p;e[0]!==t?(p=Fe(t),e[0]=t,e[1]=p):p=e[1];let c=p,x;e[2]!==l?(x=l("Metadata (JSON)"),e[2]=l,e[3]=x):x=e[3];let g;e[4]!==d||e[5]!==x?(g=(0,a.jsx)(q,{className:"text-xs",htmlFor:d,children:x}),e[4]=d,e[5]=x,e[6]=g):g=e[6];let O=`${v}-format`,V=c===void 0,_;e[7]!==c||e[8]!==s?(_=i(()=>{c!==void 0&&s(c)},"O"),e[7]=c,e[8]=s,e[9]=_):_=e[9];let y;e[10]!==l?(y=l("Format JSON"),e[10]=l,e[11]=y):y=e[11];let m;e[12]!==O||e[13]!==V||e[14]!==_||e[15]!==y?(m=(0,a.jsx)(B,{"data-testid":O,disabled:V,onClick:_,size:"sm",variant:"outline",children:y}),e[12]=O,e[13]=V,e[14]=_,e[15]=y,e[16]=m):m=e[16];let h;e[17]!==g||e[18]!==m?(h=(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[g,m]}),e[17]=g,e[18]=m,e[19]=h):h=e[19];let N=!o,w;e[20]!==s?(w=i(E=>{s(E.target.value)},"N"),e[20]=s,e[21]=w):w=e[21];let C;e[22]!==d||e[23]!==N||e[24]!==w||e[25]!==v||e[26]!==t?(C=(0,a.jsx)(ce,{"aria-invalid":N,className:"min-h-[4rem] font-mono text-xs","data-testid":v,id:d,onChange:w,value:t}),e[22]=d,e[23]=N,e[24]=w,e[25]=v,e[26]=t,e[27]=C):C=e[27];let b;e[28]!==u||e[29]!==l||e[30]!==o?(b=!o&&(0,a.jsx)("p",{className:"text-xs text-destructive","data-testid":u,children:l("Metadata must be valid JSON.")}),e[28]=u,e[29]=l,e[30]=o,e[31]=b):b=e[31];let S;return e[32]!==C||e[33]!==b||e[34]!==h?(S=(0,a.jsxs)("div",{className:"mb-3 grid gap-1",children:[h,C,b]}),e[32]=C,e[33]=b,e[34]=h,e[35]=S):S=e[35],S},"$e"),$e={busy:!1,error:null,metadata:"",name:"",ttl:"",value:""},Be=i((r,e)=>{switch(e.type){case"setField":return{...r,[e.field]:e.value};case"submitFailed":return{...r,busy:!1,error:e.error};case"submitStart":return{...r,busy:!0,error:null};default:return r}},"Be"),je=i(r=>{let e=(0,ee.c)(73),{namespace:d,onCancel:u,onCreated:s}=r,v=G(),o=R(),[t,l]=(0,$.useReducer)(Be,$e),p;e[0]!==t.metadata?(p=Ke(t.metadata),e[0]=t.metadata,e[1]=p):p=e[1];let c=p,x;e[2]!==t.ttl?(x=Ve(t.ttl),e[2]=t.ttl,e[3]=x):x=e[3];let g=x,O;e[4]!==c||e[5]!==t.busy||e[6]!==t.name||e[7]!==g?(O=t.name.trim()!==""&&c&&g&&!t.busy,e[4]=c,e[5]=t.busy,e[6]=t.name,e[7]=g,e[8]=O):O=e[8];let V=O,_;e[9]!==V||e[10]!==v||e[11]!==d||e[12]!==s||e[13]!==t.metadata||e[14]!==t.name||e[15]!==t.ttl||e[16]!==t.value?(_=i(()=>{V&&(l({type:"submitStart"}),A((async()=>{try{await v.putKvValue(Te({metadata:t.metadata,ttl:t.ttl,value:t.value},t.name,d)),s()}catch(z){l({error:Z(z),type:"submitFailed"})}})()))},"O"),e[9]=V,e[10]=v,e[11]=d,e[12]=s,e[13]=t.metadata,e[14]=t.name,e[15]=t.ttl,e[16]=t.value,e[17]=_):_=e[17];let y=_,m;e[18]!==o?(m=o("Key name"),e[18]=o,e[19]=m):m=e[19];let h;e[20]!==m?(h=(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-create-name",children:m}),e[20]=m,e[21]=h):h=e[21];let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=i(z=>{l({field:"name",type:"setField",value:z.target.value})},"x"),e[22]=N):N=e[22];let w;e[23]!==o?(w=o("Key name"),e[23]=o,e[24]=w):w=e[24];let C;e[25]!==t.name||e[26]!==w?(C=(0,a.jsx)(ae,{autoFocus:!0,"data-testid":"kv-create-name",id:"kv-create-name",onChange:N,placeholder:w,value:t.name}),e[25]=t.name,e[26]=w,e[27]=C):C=e[27];let b;e[28]!==h||e[29]!==C?(b=(0,a.jsxs)("div",{className:"grid gap-1",children:[h,C]}),e[28]=h,e[29]=C,e[30]=b):b=e[30];let S;e[31]!==o?(S=o("Value"),e[31]=o,e[32]=S):S=e[32];let E;e[33]!==S?(E=(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-create-value",children:S}),e[33]=S,e[34]=E):E=e[34];let J;e[35]===Symbol.for("react.memo_cache_sentinel")?(J=i(z=>{l({field:"value",type:"setField",value:z.target.value})},"J"),e[35]=J):J=e[35];let T;e[36]!==t.value?(T=(0,a.jsx)(ce,{className:"min-h-[6rem] font-mono text-xs","data-testid":"kv-create-value",id:"kv-create-value",onChange:J,value:t.value}),e[36]=t.value,e[37]=T):T=e[37];let P;e[38]!==E||e[39]!==T?(P=(0,a.jsxs)("div",{className:"grid gap-1",children:[E,T]}),e[38]=E,e[39]=T,e[40]=P):P=e[40];let L=!g,M;e[41]===Symbol.for("react.memo_cache_sentinel")?(M=i(z=>{l({field:"ttl",type:"setField",value:z})},"M"),e[41]=M):M=e[41];let n;e[42]!==L?(n=(0,a.jsx)(Me,{id:"kv-create-ttl",invalid:L,onChange:M,testId:"kv-create-ttl"}),e[42]=L,e[43]=n):n=e[43];let k;e[44]===Symbol.for("react.memo_cache_sentinel")?(k=i(z=>{l({field:"metadata",type:"setField",value:z})},"h"),e[44]=k):k=e[44];let F;e[45]!==c||e[46]!==t.metadata?(F=(0,a.jsx)(Ie,{id:"kv-create-metadata",invalidTestId:"kv-create-metadata-invalid",onChange:k,testId:"kv-create-metadata",valid:c,value:t.metadata}),e[45]=c,e[46]=t.metadata,e[47]=F):F=e[47];let I=!V,K;e[48]!==t.busy||e[49]!==o?(K=t.busy?o("Creating\u2026"):o("Create key"),e[48]=t.busy,e[49]=o,e[50]=K):K=e[50];let D;e[51]!==y||e[52]!==I||e[53]!==K?(D=(0,a.jsx)(B,{"data-testid":"kv-create-submit",disabled:I,onClick:y,children:K}),e[51]=y,e[52]=I,e[53]=K,e[54]=D):D=e[54];let f=t.busy,j;e[55]!==o?(j=o("Cancel"),e[55]=o,e[56]=j):j=e[56];let H;e[57]!==u||e[58]!==t.busy||e[59]!==j?(H=(0,a.jsx)(B,{"data-testid":"kv-create-cancel",disabled:f,onClick:u,variant:"outline",children:j}),e[57]=u,e[58]=t.busy,e[59]=j,e[60]=H):H=e[60];let U;e[61]!==D||e[62]!==H?(U=(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[D,H]}),e[61]=D,e[62]=H,e[63]=U):U=e[63];let W;e[64]!==t.error?(W=t.error!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-create-error",role:"alert",children:t.error}),e[64]=t.error,e[65]=W):W=e[65];let te;return e[66]!==b||e[67]!==P||e[68]!==n||e[69]!==F||e[70]!==U||e[71]!==W?(te=(0,a.jsxs)("div",{className:"grid gap-3 px-4 pb-4","data-testid":"kv-create-form",children:[b,P,n,F,U,W]}),e[66]=b,e[67]=P,e[68]=n,e[69]=F,e[70]=U,e[71]=W,e[72]=te):te=e[72],te},"Pe"),ze={busy:"",editedMetadata:"",editedTtl:"",editedValue:"",loadError:null,loading:!0,value:null,writeError:null},Ae=i((r,e)=>{switch(e.type){case"deleteStart":return{...r,busy:"deleting",writeError:null};case"editMetadata":return{...r,editedMetadata:e.value};case"editTtl":return{...r,editedTtl:e.value};case"editValue":return{...r,editedValue:e.value};case"loaded":return{...r,editedMetadata:e.metadata===null||e.metadata===void 0?"":JSON.stringify(e.metadata,null,2),editedValue:e.value??"",loading:!1,value:e.value};case"loadFailed":return{...r,loadError:e.error,loading:!1};case"saveOk":return{...r,busy:"",value:r.editedValue};case"saveStart":return{...r,busy:"saving",writeError:null};case"writeFailed":return{...r,busy:"",writeError:e.error};default:return r}},"Ae"),He=i(r=>{let e=(0,ee.c)(67),{expiration:d,keyName:u,namespace:s,onDeleted:v}=r,o=G(),t=R(),[l,p]=(0,$.useReducer)(Ae,ze),c,x;e[0]!==o||e[1]!==u||e[2]!==s?(c=i(()=>{let f={cancelled:!1};return A((async()=>{try{let j=await o.getKvValue({key:u,namespace:s});f.cancelled||p({metadata:j.metadata,type:"loaded",value:j.value})}catch(j){let H=j;f.cancelled||p({error:Z(H),type:"loadFailed"})}})()),()=>{f.cancelled=!0}},"o"),x=[o,s,u],e[0]=o,e[1]=u,e[2]=s,e[3]=c,e[4]=x):(c=e[3],x=e[4]),(0,$.useEffect)(c,x);let g;e[5]===Symbol.for("react.memo_cache_sentinel")?(g=i(f=>{p({type:"editValue",value:f.target.value})},"f"),e[5]=g):g=e[5];let O=g,V;e[6]===Symbol.for("react.memo_cache_sentinel")?(V=i(f=>{p({type:"editMetadata",value:f})},"K"),e[6]=V):V=e[6];let _=V,y;e[7]!==l.editedValue?(y=Fe(l.editedValue),e[7]=l.editedValue,e[8]=y):y=e[8];let m=y,h;e[9]!==l.editedMetadata?(h=Ke(l.editedMetadata),e[9]=l.editedMetadata,e[10]=h):h=e[10];let N=h,w;e[11]!==l.editedTtl?(w=Ve(l.editedTtl),e[11]=l.editedTtl,e[12]=w):w=e[12];let C=w,b;e[13]!==m?(b=i(()=>{m!==void 0&&p({type:"editValue",value:m})},"k"),e[13]=m,e[14]=b):b=e[14];let S=b,E;e[15]!==o||e[16]!==d||e[17]!==u||e[18]!==N||e[19]!==s||e[20]!==l.editedMetadata||e[21]!==l.editedTtl||e[22]!==l.editedValue||e[23]!==t?(E=i(()=>{if(!N){p({error:t("Metadata must be valid JSON."),type:"writeFailed"});return}p({type:"saveStart"}),A((async()=>{try{await o.putKvValue(Te({metadata:l.editedMetadata,ttl:l.editedTtl,value:l.editedValue},u,s,d)),p({type:"saveOk"})}catch(f){p({error:Z(f),type:"writeFailed"})}})())},"E"),e[15]=o,e[16]=d,e[17]=u,e[18]=N,e[19]=s,e[20]=l.editedMetadata,e[21]=l.editedTtl,e[22]=l.editedValue,e[23]=t,e[24]=E):E=e[24];let J=E,T;e[25]!==o||e[26]!==u||e[27]!==s||e[28]!==v?(T=i(()=>{p({type:"deleteStart"}),A((async()=>{try{await o.deleteKvKey({key:u,namespace:s}),v(u)}catch(f){p({error:Z(f),type:"writeFailed"})}})())},"V"),e[25]=o,e[26]=u,e[27]=s,e[28]=v,e[29]=T):T=e[29];let P=T,L;e[30]!==u?(L=i(()=>{de(u)},"D"),e[30]=u,e[31]=L):L=e[31];let M;e[32]!==t?(M=t("Copy key"),e[32]=t,e[33]=M):M=e[33];let n;e[34]!==L||e[35]!==M?(n=(0,a.jsx)("div",{className:"mb-2 flex justify-end",children:(0,a.jsx)(B,{"data-testid":"kv-copy-key-btn",onClick:L,size:"sm",variant:"outline",children:M})}),e[34]=L,e[35]=M,e[36]=n):n=e[36];let k;e[37]!==l.loadError?(k=l.loadError!==null&&(0,a.jsx)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-value-error",role:"alert",children:l.loadError}),e[37]=l.loadError,e[38]=k):k=e[38];let F;e[39]!==l.loading||e[40]!==t?(F=l.loading&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-value-loading",children:t("Loading\u2026")}),e[39]=l.loading,e[40]=t,e[41]=F):F=e[41];let I;e[42]!==m||e[43]!==N||e[44]!==P||e[45]!==S||e[46]!==J||e[47]!==l.busy||e[48]!==l.editedMetadata||e[49]!==l.editedValue||e[50]!==l.loading||e[51]!==l.value||e[52]!==l.writeError||e[53]!==t||e[54]!==C?(I=!l.loading&&l.value!==null&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"mb-1 flex flex-wrap items-center gap-2",children:[(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-value-editor",children:t("Value")}),m!==void 0&&(0,a.jsx)(he,{variant:"secondary",children:t("JSON")}),(0,a.jsx)("span",{className:"ml-auto text-xs tabular-nums text-muted-foreground","data-testid":"kv-value-size",children:be(Pe(l.editedValue))})]}),(0,a.jsx)("textarea",{"aria-label":t("KV value"),className:"mb-2 min-h-[8rem] w-full rounded border border-border bg-muted/30 p-2 font-mono text-xs","data-testid":"kv-value-editor",id:"kv-value-editor",onChange:O,value:l.editedValue}),(0,a.jsxs)("div",{className:"mb-3 flex flex-wrap gap-2",children:[(0,a.jsx)(B,{"data-testid":"kv-format-btn",disabled:m===void 0,onClick:S,size:"sm",variant:"outline",children:t("Format JSON")}),(0,a.jsx)(B,{"data-testid":"kv-copy-value-btn",onClick:i(()=>{de(l.editedValue)},"onClick"),size:"sm",variant:"outline",children:t("Copy value")})]}),(0,a.jsx)(Me,{helper:t("Leave blank to keep the current expiration."),id:"kv-ttl-input",invalid:!C,onChange:i(f=>{p({type:"editTtl",value:f})},"onChange"),testId:"kv-ttl-input"}),(0,a.jsx)(Ie,{id:"kv-metadata-editor",invalidTestId:"kv-metadata-invalid",onChange:_,testId:"kv-metadata-editor",valid:N,value:l.editedMetadata}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,a.jsx)(B,{"data-testid":"kv-save-btn",disabled:l.busy!==""||!N||!C,onClick:J,children:l.busy==="saving"?t("Saving\u2026"):t("Save")}),(0,a.jsx)(B,{"data-testid":"kv-delete-btn",disabled:l.busy!=="",onClick:P,variant:"destructive",children:l.busy==="deleting"?t("Deleting\u2026"):t("Delete")})]}),l.writeError!==null&&(0,a.jsx)("p",{className:"mt-2 text-sm text-destructive","data-testid":"kv-save-error",role:"alert",children:l.writeError})]}),e[42]=m,e[43]=N,e[44]=P,e[45]=S,e[46]=J,e[47]=l.busy,e[48]=l.editedMetadata,e[49]=l.editedValue,e[50]=l.loading,e[51]=l.value,e[52]=l.writeError,e[53]=t,e[54]=C,e[55]=I):I=e[55];let K;e[56]!==l.loadError||e[57]!==l.loading||e[58]!==l.value||e[59]!==t?(K=!l.loading&&l.value===null&&l.loadError===null&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-absent",children:t("Key is absent or has no value.")}),e[56]=l.loadError,e[57]=l.loading,e[58]=l.value,e[59]=t,e[60]=K):K=e[60];let D;return e[61]!==n||e[62]!==k||e[63]!==F||e[64]!==I||e[65]!==K?(D=(0,a.jsxs)("div",{className:"px-4 pb-4","data-testid":"kv-value-section",children:[n,k,F,I,K]}),e[61]=n,e[62]=k,e[63]=F,e[64]=I,e[65]=K,e[66]=D):D=e[66],D},"ze"),Se=100,Ze={appliedPrefix:"",bulk:[],bulkBusy:!1,bulkError:null,cursor:null,keys:null,listComplete:!1,loadError:null,loading:!1,prefixInput:"",reloadNonce:0,selectedKey:null},Re=i((r,e)=>{switch(e.type){case"appendPage":return{...r,cursor:e.cursor,keys:[...r.keys??[],...e.keys],listComplete:e.listComplete,loading:!1};case"applyFilter":return{...r,appliedPrefix:r.prefixInput,bulk:[],bulkError:null,cursor:null,keys:null,listComplete:!1,selectedKey:null};case"bulkDeleted":{let d=new Set(e.deleted);return{...r,bulk:r.bulk.filter(u=>!d.has(u)),bulkBusy:!1,bulkError:e.error,keys:r.keys===null?null:r.keys.filter(u=>!d.has(u.name)),selectedKey:r.selectedKey!==null&&d.has(r.selectedKey)?null:r.selectedKey}}case"bulkDeleteStart":return{...r,bulkBusy:!0,bulkError:null};case"firstPage":return{...r,cursor:e.cursor,keys:e.keys,listComplete:e.listComplete,loading:!1};case"keyDeleted":return{...r,bulk:r.bulk.filter(d=>d!==e.name),keys:r.keys===null?null:r.keys.filter(d=>d.name!==e.name),selectedKey:null};case"loadFailed":return{...r,loadError:e.error,loading:!1};case"loadStart":return{...r,loadError:null,loading:!0};case"prefixInput":return{...r,prefixInput:e.value};case"reload":return{...r,bulk:[],bulkError:null,reloadNonce:r.reloadNonce+1,selectedKey:null};case"selectKey":return{...r,selectedKey:e.name};case"toggleAllBulk":return{...r,bulk:e.names};case"toggleBulk":return{...r,bulk:r.bulk.includes(e.name)?r.bulk.filter(d=>d!==e.name):[...r.bulk,e.name]};default:return r}},"Re"),Ue=i(({namespace:r})=>{let e=G(),d=R(),[u,s]=(0,$.useReducer)(Re,Ze),{appliedPrefix:v,bulk:o,bulkBusy:t,bulkError:l,cursor:p,keys:c,listComplete:x,loadError:g,loading:O,prefixInput:V,reloadNonce:_,selectedKey:y}=u,[m,h]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let n={cancelled:!1};return A((async()=>{s({type:"loadStart"});try{let k=await e.listKvKeys({limit:Se,namespace:r,prefix:v===""?void 0:v});n.cancelled||s({cursor:k.cursor??null,keys:k.keys,listComplete:k.listComplete,type:"firstPage"})}catch(k){n.cancelled||s({error:Z(k),type:"loadFailed"})}})()),()=>{n.cancelled=!0}},[e,r,v,_]);let N=i(n=>{s({type:"prefixInput",value:n.target.value})},"x"),w=i(()=>{s({type:"applyFilter"})},"N"),C=i(n=>{s({name:n.currentTarget.dataset.key??null,type:"selectKey"})},"C"),b=i(()=>{p!==null&&(s({type:"loadStart"}),A((async()=>{try{let n=await e.listKvKeys({cursor:p,limit:Se,namespace:r,prefix:v===""?void 0:v});s({cursor:n.cursor??null,keys:n.keys,listComplete:n.listComplete,type:"appendPage"})}catch(n){s({error:Z(n),type:"loadFailed"})}})()))},"k"),S=i(n=>{s({name:n,type:"keyDeleted"})},"w"),E=i(n=>{s({name:n,type:"toggleBulk"})},"E"),J=i(n=>{s({names:n&&c!==null?c.map(k=>k.name):[],type:"toggleAllBulk"})},"J"),T=i(()=>{if(o.length===0)return;let n=[...o];s({type:"bulkDeleteStart"}),A((async()=>{let k=await Promise.allSettled(n.map(K=>e.deleteKvKey({key:K,namespace:r}))),F=n.filter((K,D)=>k[D]?.status==="fulfilled"),I=n.length-F.length;s({deleted:F,error:I>0?d("Failed to delete {count} keys.",{count:I}):null,type:"bulkDeleted"})})())},"V"),P=i(()=>{h(!1),s({type:"reload"})},"L"),L=c!==null&&c.length>0&&o.length===c.length,M=new Set(o);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("section",{className:"border border-border bg-card p-3","data-testid":"kv-keys-section",children:[(0,a.jsxs)("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[(0,a.jsx)(ae,{"aria-label":d("Filter keys by prefix"),className:"min-w-[16rem] flex-1","data-testid":"kv-prefix-input",onChange:N,placeholder:d("Filter by prefix\u2026"),value:V}),(0,a.jsx)(B,{"data-testid":"kv-filter-btn",disabled:O,onClick:w,children:d("Filter")}),(0,a.jsx)(B,{"data-testid":"kv-new-key-btn",onClick:i(()=>{h(n=>!n)},"onClick"),variant:"outline",children:d("New key")}),o.length>0&&(0,a.jsx)(B,{"data-testid":"kv-bulk-delete-btn",disabled:t,onClick:T,variant:"destructive",children:t?d("Deleting\u2026"):d("Delete {count}",{count:o.length})})]}),l!==null&&(0,a.jsx)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-bulk-error",role:"alert",children:l}),g!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-keys-error",role:"alert",children:g}),c!==null&&c.length===0&&!O&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-no-keys",children:d("No keys.")}),c!==null&&c.length>0&&(0,a.jsx)(re,{className:"overflow-hidden py-0",children:(0,a.jsx)(ne,{className:"px-0",children:(0,a.jsxs)(se,{"data-testid":"kv-key-table",children:[(0,a.jsx)(ie,{children:(0,a.jsxs)(Q,{children:[(0,a.jsx)(X,{className:"w-10",children:(0,a.jsx)(ue,{"aria-label":d("Select all"),checked:L,"data-testid":"kv-select-all",onCheckedChange:J})}),(0,a.jsx)(X,{children:d("Key")}),(0,a.jsx)(X,{children:d("Expiration")})]})}),(0,a.jsx)(oe,{children:c.map(n=>(0,a.jsxs)(Q,{className:n.name===y?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-key":n.name,"data-testid":`kv-key-row-${n.name}`,onClick:C,children:[(0,a.jsx)(Y,{onClick:i(k=>{k.stopPropagation()},"onClick"),children:(0,a.jsx)(ue,{"aria-label":d("Select {name}",{name:n.name}),checked:M.has(n.name),"data-testid":`kv-select-${n.name}`,onCheckedChange:i(()=>{E(n.name)},"onCheckedChange")})}),(0,a.jsx)(Y,{className:"font-mono text-xs",children:n.name}),(0,a.jsx)(Y,{className:"tabular-nums text-xs",children:Le(n.expiration)})]},n.name))})]})})}),!x&&p!==null&&(0,a.jsx)("div",{className:"mt-2",children:(0,a.jsx)(B,{"data-testid":"kv-load-more",disabled:O,onClick:b,variant:"outline",children:d(O?"Loading\u2026":"Load more")})})]}),(0,a.jsx)(me,{onOpenChange:i(n=>{n||h(!1)},"onOpenChange"),open:m,children:(0,a.jsxs)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-create-sheet",side:"right",children:[(0,a.jsx)(pe,{children:(0,a.jsx)(ye,{children:d("New key")})}),(0,a.jsx)(je,{namespace:r,onCancel:i(()=>{h(!1)},"onCancel"),onCreated:P})]})}),(0,a.jsx)(me,{onOpenChange:i(n=>{n||s({name:null,type:"selectKey"})},"onOpenChange"),open:y!==null,children:(0,a.jsxs)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-editor-sheet",side:"right",children:[(0,a.jsx)(pe,{children:(0,a.jsx)(ye,{className:"truncate font-mono text-xs",children:y})}),y!==null&&(0,a.jsx)(He,{expiration:c?.find(n=>n.name===y)?.expiration,keyName:y,namespace:r,onDeleted:S},`${r}:${y}`)]})})]})},"Ue"),it=i(({loadNamespaces:r}={})=>{let e=G(),d=R(),[u,s]=(0,$.useState)(null),[v,o]=(0,$.useState)(null),[t,l]=(0,$.useState)(null);(0,$.useEffect)(()=>{let c={cancelled:!1};return A((async()=>{try{let x=await(r??(()=>e.listKvNamespaces()))();c.cancelled||(s(x),o(null),l(g=>g??x[0]?.binding??null))}catch(x){c.cancelled||(s(null),o(Z(x)))}})()),()=>{c.cancelled=!0}},[e,r]);let p=i(c=>{l(c.currentTarget.dataset.ns??null)},"v");return(0,a.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-kv-browser",children:[v!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-ns-error",role:"alert",children:v}),u!==null&&u.length===0&&(0,a.jsx)(ke,{description:d("Add a kv_namespaces binding to wrangler.jsonc \u2014 it appears here automatically, no wiring needed."),icon:(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"M5 5h14v4H5V5Zm0 5h14v4H5v-4Zm0 5h14v4H5v-4Z"})}),testId:"kv-empty",title:d("No KV namespaces.")}),u!==null&&u.length>0&&(0,a.jsx)(re,{className:"overflow-hidden py-0",children:(0,a.jsx)(ne,{className:"px-0",children:(0,a.jsxs)(se,{"data-testid":"kv-namespace-table",children:[(0,a.jsx)(ie,{children:(0,a.jsx)(Q,{children:(0,a.jsx)(X,{children:d("Namespace")})})}),(0,a.jsx)(oe,{children:u.map(c=>(0,a.jsx)(Q,{className:c.binding===t?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-ns":c.binding,"data-testid":`kv-ns-row-${c.binding}`,onClick:p,children:(0,a.jsx)(Y,{className:"font-mono text-xs",children:c.binding})},c.binding))})]})})}),t!==null&&(0,a.jsx)(Ue,{namespace:t},t)]})},"ct");export{it as KvBrowser};