okengine 0.17.2 → 0.18.3

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 (197) hide show
  1. package/README.md +9 -5
  2. package/manifest.v1.schema.json +61 -2
  3. package/package.json +18 -4
  4. package/site/content/docs/elements/clock.mdx +1 -1
  5. package/site/content/docs/elements/flow.mdx +25 -1
  6. package/site/content/docs/elements/store.mdx +287 -341
  7. package/site/content/docs/elements/vault.mdx +5 -5
  8. package/site/content/docs/get-started/installation.mdx +1 -2
  9. package/site/content/docs/get-started/introduction.mdx +54 -110
  10. package/site/content/docs/get-started/meta.json +9 -1
  11. package/site/content/docs/get-started/testing.mdx +328 -0
  12. package/site/content/docs/get-started/why.mdx +94 -70
  13. package/site/content/docs/index.mdx +1 -1
  14. package/site/content/docs/plugins/apple.mdx +151 -0
  15. package/site/content/docs/plugins/discord.mdx +139 -0
  16. package/site/content/docs/plugins/facebook.mdx +134 -0
  17. package/site/content/docs/plugins/figma.mdx +138 -0
  18. package/site/content/docs/plugins/github.mdx +138 -0
  19. package/site/content/docs/plugins/google.mdx +153 -0
  20. package/site/content/docs/plugins/index.mdx +47 -1
  21. package/site/content/docs/plugins/meta.json +10 -0
  22. package/site/content/docs/plugins/microsoft.mdx +151 -0
  23. package/site/content/docs/plugins/oauth.mdx +188 -0
  24. package/site/content/docs/plugins/x.mdx +125 -0
  25. package/site/content/docs/reference/cli.md +3 -2
  26. package/site/content/docs/reference/client.mdx +58 -1
  27. package/site/content/docs/reference/configuration.mdx +2 -4
  28. package/site/content/docs/reference/fx.mdx +3 -1
  29. package/site/content/docs/reference/index.mdx +0 -5
  30. package/site/content/docs/reference/meta.json +2 -2
  31. package/site/content/docs/reference/okid.mdx +137 -0
  32. package/src/auth/bindings.ts +1 -1
  33. package/src/auth/config.ts +9 -0
  34. package/src/auth/identity-sql.ts +314 -0
  35. package/src/auth/identity.ts +140 -2
  36. package/src/auth/index.ts +17 -1
  37. package/src/auth/method-context.ts +3 -0
  38. package/src/auth/oauth-as/cimd.ts +132 -0
  39. package/src/auth/oauth-as/crypto.test.ts +101 -0
  40. package/src/auth/oauth-as/crypto.ts +393 -0
  41. package/src/auth/oauth-as/errors.ts +68 -0
  42. package/src/auth/oauth-as/http.test.ts +419 -0
  43. package/src/auth/oauth-as/http.ts +842 -0
  44. package/src/auth/oauth-as/stores.ts +61 -0
  45. package/src/auth/oauth-as/tables.ts +142 -0
  46. package/src/auth/tables.ts +0 -11
  47. package/src/bench/README.md +83 -0
  48. package/src/bench/REPORT.md +176 -0
  49. package/src/bench/g01-rls-stamp.bench.ts +194 -0
  50. package/src/bench/g02-clock-per-tenant.bench.ts +158 -0
  51. package/src/bench/g03-signal-once.bench.ts +157 -0
  52. package/src/bench/g03-signal-reconnect.bench.ts +254 -0
  53. package/src/bench/g03-signal-sse-memory.bench.ts +191 -0
  54. package/src/bench/g04-auth-vault-hotpath.bench.ts +170 -0
  55. package/src/bench/g05-sustained-full.bench.ts +265 -0
  56. package/src/bench/g06-mixed-load.bench.ts +260 -0
  57. package/src/bench/g07-vault-crypto.bench.ts +100 -0
  58. package/src/bench/g07-vault-rotate-under-read.bench.ts +285 -0
  59. package/src/bench/g08-conn-oversubscribe.bench.ts +194 -0
  60. package/src/bench/g08-store-kv-durable.bench.ts +133 -0
  61. package/src/bench/g08-store-sql.bench.ts +178 -0
  62. package/src/bench/g09-journal-sustained.bench.ts +203 -0
  63. package/src/bench/g10-observability-contention.bench.ts +246 -0
  64. package/src/bench/g11-cold-start-cycle.bench.ts +164 -0
  65. package/src/bench/g13-elements.bench.ts +427 -0
  66. package/src/bench/g14-graceful-shutdown.bench.ts +244 -0
  67. package/src/bench/g15-postgres-degradation.bench.ts +264 -0
  68. package/src/bench/g16-live-query-fanout.bench.ts +206 -0
  69. package/src/bench/lib/event-loop-lag.ts +26 -0
  70. package/src/bench/lib/infra.ts +60 -0
  71. package/src/bench/lib/report.ts +52 -0
  72. package/src/bench/lib/rss-sampler.ts +61 -0
  73. package/src/bench/lib/signal-pg.ts +88 -0
  74. package/src/bench/load-app.ts +337 -0
  75. package/src/bench/load-child.ts +108 -0
  76. package/src/bench/smoke.bench.ts +43 -0
  77. package/src/cli/competitor-mention-removal.test.ts +28 -0
  78. package/src/cli/doctor-fd.ts +117 -0
  79. package/src/cli/doctor.test.ts +192 -0
  80. package/src/cli/doctor.ts +129 -1
  81. package/src/client/create.ts +95 -1
  82. package/src/client/index.ts +9 -2
  83. package/src/client/transport.ts +11 -4
  84. package/src/client/use-live-query.ts +154 -0
  85. package/src/client-react/index.ts +15 -1
  86. package/src/client-react/live-resource.ts +246 -0
  87. package/src/client-react/use-live-query.test.ts +475 -0
  88. package/src/client-react/use-live-query.ts +530 -0
  89. package/src/compiler/extract.test.ts +518 -0
  90. package/src/compiler/extract.ts +386 -19
  91. package/src/console/server/invoke-user-flow.ts +2 -1
  92. package/src/console/ui-next/dist/assets/{access-page-DnWbnGzq.js → access-page-DY4N6nnk.js} +1 -1
  93. package/src/console/ui-next/dist/assets/{flows-page-BiZ4-6yQ.js → flows-page-CsPDMrVM.js} +1 -1
  94. package/src/console/ui-next/dist/assets/{index-C8NRK2R-.js → index-CcTDXHuz.js} +3 -3
  95. package/src/console/ui-next/dist/assets/{observability-page-CrB6vd1T.js → observability-page-CKR595wP.js} +1 -1
  96. package/src/console/ui-next/dist/assets/{store-page-CS5-aETQ.js → store-page-02xOiqIK.js} +3 -3
  97. package/src/console/ui-next/dist/assets/{units-page-CjtdlW8l.js → units-page-CpPFFKyE.js} +1 -1
  98. package/src/console/ui-next/dist/assets/{vault-page-C6Xxm9SA.js → vault-page-BsMf-9_W.js} +1 -1
  99. package/src/console/ui-next/dist/index.html +1 -1
  100. package/src/console/ui-next/src/features/store/lib/fields-from-table.ts +36 -2
  101. package/src/drivers/cdc-outbox.ts +389 -0
  102. package/src/drivers/memory.ts +20 -0
  103. package/src/drivers/oauth-apple.ts +156 -0
  104. package/src/drivers/oauth-discord.ts +79 -0
  105. package/src/drivers/oauth-facebook.ts +80 -0
  106. package/src/drivers/oauth-figma.ts +116 -0
  107. package/src/drivers/oauth-github.ts +92 -0
  108. package/src/drivers/oauth-google.ts +142 -0
  109. package/src/drivers/oauth-microsoft.ts +174 -0
  110. package/src/drivers/oauth-oidc.ts +293 -0
  111. package/src/drivers/oauth-shared.ts +326 -0
  112. package/src/drivers/oauth-types.ts +159 -0
  113. package/src/drivers/oauth-x.ts +77 -0
  114. package/src/drivers/oauth2-common.ts +95 -0
  115. package/src/drivers/oauth2-token.ts +61 -0
  116. package/src/drivers/pg-rls-row-passes.ts +251 -0
  117. package/src/drivers/pg-rls.ts +2 -0
  118. package/src/drivers/postgres.ts +45 -2
  119. package/src/drivers/signal-postgres.ts +2 -1
  120. package/src/elements/channel/runtime.ts +29 -2
  121. package/src/elements/channel.test.ts +52 -0
  122. package/src/elements/gate/boot.ts +29 -2
  123. package/src/elements/store/emit-drizzle.ts +147 -14
  124. package/src/elements/store/field-ddl.test.ts +118 -0
  125. package/src/elements/store/field-types.test.ts +455 -0
  126. package/src/elements/store/list-query.golden.json +777 -0
  127. package/src/elements/store/list-query.parity.test.ts +396 -0
  128. package/src/elements/store/list-query.ts +792 -0
  129. package/src/elements/store/live-default.test.ts +136 -0
  130. package/src/elements/store/live-http.test.ts +160 -0
  131. package/src/elements/store/live-isolation.test.ts +291 -0
  132. package/src/elements/store/live-query-runtime.test.ts +323 -0
  133. package/src/elements/store/live-query-runtime.ts +403 -0
  134. package/src/elements/store/live-query-server.test.ts +377 -0
  135. package/src/elements/store/live-query-server.ts +102 -0
  136. package/src/elements/store/live-query.ts +97 -0
  137. package/src/elements/store/resource.ts +189 -680
  138. package/src/elements/store/rls-row-passes-policies.parity.test.ts +665 -0
  139. package/src/elements/store/schema-decl.ts +539 -41
  140. package/src/elements/store/sql-rls-stamp.test.ts +27 -0
  141. package/src/elements/store/sql-session.ts +297 -35
  142. package/src/elements/store/table.ts +102 -21
  143. package/src/elements/store.test.ts +3 -1
  144. package/src/elements/store.ts +12 -1
  145. package/src/elements/vault/chaos-child.ts +74 -1
  146. package/src/elements/vault/chaos.test.ts +4 -2
  147. package/src/elements/vault/storage.ts +4 -2
  148. package/src/index.ts +4 -1
  149. package/src/kernel/app-auth.ts +1 -0
  150. package/src/kernel/app.ts +116 -2
  151. package/src/kernel/auth-sharing.test.ts +196 -0
  152. package/src/kernel/boot.test.ts +3 -3
  153. package/src/kernel/errors.ts +8 -0
  154. package/src/kernel/fx.test.ts +1 -0
  155. package/src/kernel/fx.ts +14 -2
  156. package/src/kernel/horizontal-child.ts +2 -1
  157. package/src/kernel/http-resource.ts +33 -7
  158. package/src/kernel/identity-host-persist.test.ts +119 -0
  159. package/src/kernel/instance-id.ts +4 -2
  160. package/src/kernel/journal.ts +2 -1
  161. package/src/kernel/mcp-tool.test.ts +95 -0
  162. package/src/kernel/on.ts +9 -0
  163. package/src/kernel/realtime-bind.ts +326 -0
  164. package/src/kernel/resource-live.ts +117 -0
  165. package/src/kernel/triggers.ts +86 -4
  166. package/src/manifest/diff.ts +37 -0
  167. package/src/manifest/types.ts +64 -2
  168. package/src/okid.bench.test.ts +64 -0
  169. package/src/okid.test.ts +338 -0
  170. package/src/okid.ts +245 -0
  171. package/src/plugins/anonymous.ts +19 -1
  172. package/src/plugins/auth/shared.ts +15 -0
  173. package/src/plugins/index.ts +2 -0
  174. package/src/plugins/magic-link.ts +10 -8
  175. package/src/plugins/mcp-oauth.ts +208 -0
  176. package/src/plugins/oauth/flow-store.ts +117 -0
  177. package/src/plugins/oauth/link.ts +69 -0
  178. package/src/plugins/oauth/shared.ts +108 -0
  179. package/src/plugins/oauth/token-vault.ts +100 -0
  180. package/src/plugins/oauth.security.test.ts +535 -0
  181. package/src/plugins/oauth.ts +532 -0
  182. package/src/plugins/otp.ts +48 -6
  183. package/src/plugins/passkey.ts +20 -1
  184. package/src/plugins/two-factor.ts +11 -0
  185. package/src/plugins/username.ts +40 -7
  186. package/src/release/build-lib.ts +7 -1
  187. package/src/release/measure.ts +1 -0
  188. package/src/release/official-plugins.ts +4 -1
  189. package/src/runs/collect.ts +2 -1
  190. package/src/runs/drivers/files.ts +2 -1
  191. package/src/test/create-test-app.ts +114 -5
  192. package/src/test/export-bundle.test.ts +33 -0
  193. package/src/test/live-signals.test.ts +83 -0
  194. package/src/test/tenant-isolation.test.ts +175 -0
  195. package/src/testing.ts +26 -0
  196. package/src/upgrade/codemods.ts +1 -1
  197. package/site/content/docs/reference/migrating-environments.mdx +0 -158
@@ -36,6 +36,6 @@ list`}function md(e,t,n){let r=e.filter(e=>e.facet===t);if(r.length===0)return n
36
36
  `))),n.push(...o),r=i}return n.join(`
37
37
  `).replace(/\n{3,}/g,`
38
38
 
39
- `).trim()}function Vf(e){let t=Xd(e);return t.kind===`error`?e.trim():Hf(t)}function Hf(e){switch(e.kind){case`list`:return e.prefix.length===0?`list()`:`list(${JSON.stringify(e.prefix)})`;case`get`:case`delete`:case`ttl`:return`${e.kind}(${JSON.stringify(e.key)})`;case`set`:{let t=[JSON.stringify(e.key),e.keepValue?`value`:Uf(e.value)];return e.ttl!==void 0&&e.ttl!==null&&t.push(JSON.stringify(e.ttl)),`set(${t.join(`, `)})`}}}function Uf(e){if(typeof e==`object`&&e)try{return JSON.stringify(e,null,2)??`null`}catch{return`null`}try{return JSON.stringify(e)??`null`}catch{return`null`}}function Wf(e,t,n,r){let i=e?.stores?.[t]?.tables?.[n];return i?.columns?Gf(i.columns,r):[]}function Gf(e,t){return Object.entries(e).map(([e,n])=>Kf(e,n,t?.[e]))}function Kf(e,t,n){let r=qf(t)?t:null,i=r?.type===`integer`?`integer`:r?.type===`text`?`string`:`unknown`,a=r?.nullable===!1||r?.primaryKey===!0,o=n??(typeof r?.description==`string`?r.description:void 0);return{path:`/${e}`,name:e,type:i,required:a,...o===void 0?{}:{description:o},...t.pii===!0?{pii:!0}:{},...t.sensitive===!0?{sensitive:!0}:{},...r?.primaryKey===!0?{primaryKey:!0}:{},...r?.unique===!0&&r.primaryKey!==!0?{unique:!0}:{},...r?.references?.table?{foreignKey:!0,references:{table:r.references.table,...r.references.column===void 0?{}:{column:r.references.column}}}:{}}}function qf(e){return`type`in e||`nullable`in e||`primaryKey`in e||`unique`in e||`sqlName`in e||`description`in e||`references`in e||`default`in e}function Jf(e,t,n){if(e){let r=Wf(n,e.name,t.name,t.columnDescriptions);if(r.length>0)return r}let r=Ri(t.piiColumns);return[...new Set([...Object.keys(t.columnDescriptions),...t.piiColumns])].map(e=>({path:`/${e}`,name:e,type:`unknown`,required:!1,...t.columnDescriptions[e]===void 0?{}:{description:t.columnDescriptions[e]},...r.has(e)?{pii:!0}:{}}))}function Yf(e){let t=new Map;for(let n of e)if(!(!n||typeof n!=`object`||Array.isArray(n)))for(let[e,r]of Object.entries(n))t.has(e)||t.set(e,Xf(r));return[...t.entries()].map(([e,t])=>({name:e,type:t}))}function Xf(e){return e==null?`unknown`:Array.isArray(e)?`array`:typeof e==`object`?`object`:typeof e==`number`?Number.isInteger(e)?`integer`:`number`:typeof e==`boolean`?`boolean`:typeof e==`string`?`string`:`unknown`}function Zf(e,t){if(!e)return[];let n=new Map(e.facet===`sql`?un([e],t).map(e=>[e.name,e]):[]);return e.children.filter(e=>!jn(e)).map(r=>({name:r.name,columns:Jf(e,r,t).map(e=>{let t=n.get(r.name)?.columns.find(t=>t.name===e.name);return{name:e.name,type:e.type,...e.pii===!0?{pii:!0}:{},...e.primaryKey===!0||t?.primaryKey===!0?{primaryKey:!0}:{},...t?.unique===!0?{unique:!0}:{},...t?.references?{references:t.references,...t.inferredRef===!0?{inferredRef:!0}:{}}:{}}})}))}function Qf({store:e,facet:t,manifest:n,onPickTable:r,onPickColumn:i,onCollapse:a,tenant:s=null,tenancyDeclared:c=!1}){let l=e?.children??[],u=t===`sql`,d=(0,Z.useMemo)(()=>Zf(e,n),[e,n]);return(0,Q.jsxs)(`aside`,{className:`flex h-full min-h-0 w-56 shrink-0 flex-col overflow-hidden border-l border-border/60`,"data-slot":`store-query-schema-panel`,children:[(0,Q.jsxs)(`header`,{className:o(be,`justify-between px-2`),children:[(0,Q.jsx)(`p`,{className:o(et,`min-w-0 truncate font-mono`),children:u?`Schema`:`Namespaces`}),a?(0,Q.jsx)(xr,{label:`Collapse schema`,className:`flex self-stretch`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Collapse schema`,"data-slot":`store-query-schema-collapse`,onClick:a,className:oe,children:(0,Q.jsx)(q,{icon:v,className:`size-3.5`})})}):null]}),(0,Q.jsx)(`ul`,{className:`min-h-0 flex-1 overflow-y-auto`,children:l.length===0?(0,Q.jsx)(`li`,{className:`px-2 py-4 text-[11px] text-muted-foreground`,children:`No resources.`}):l.map(a=>(0,Q.jsx)($f,{store:e,child:a,facet:t,manifest:n,sqlColumns:d.find(e=>e.name===a.name)?.columns,onPickTable:r,onPickColumn:i,tenant:s,tenancyDeclared:c},a.effectRef))})]})}function $f({store:e,child:t,facet:n,manifest:r,sqlColumns:i,onPickTable:a,onPickColumn:s,tenant:c,tenancyDeclared:l}){let u=n===`sql`,[d,f]=(0,Z.useState)(!0),p=i??Jf(e,t,r),m=!u||p.length>0;return(0,Q.jsxs)(`li`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center`,children:[m?(0,Q.jsx)(`button`,{type:`button`,"aria-expanded":d,"aria-label":`${d?`Collapse`:`Expand`} ${t.name}`,onClick:()=>f(e=>!e),className:Se,children:(0,Q.jsx)(q,{icon:E,className:o(`size-3 transition-transform`,!d&&`-rotate-90`)})}):(0,Q.jsx)(`span`,{className:`size-6`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(t.name),className:`min-w-0 flex-1 truncate px-2 py-1.5 text-left font-mono text-[11px] text-foreground hover:bg-muted/50`,title:u?`SELECT * FROM "${t.name}"`:`list ${t.name}:`,children:t.name})]}),u&&d&&p.length>0?(0,Q.jsx)(`ul`,{className:`border-l border-border/60 ml-3`,children:p.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(t.name,e.name),className:`flex w-full items-center gap-1.5 px-2 py-1 text-left hover:bg-muted/50`,children:[(0,Q.jsx)(zi,{primaryKey:e.primaryKey,foreignKey:`references`in e&&e.references!==void 0,unique:`unique`in e?e.unique:void 0,inferred:`inferredRef`in e?e.inferredRef:void 0}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,children:e.name}),`references`in e&&e.references?.table?(0,Q.jsxs)(`span`,{className:`max-w-[4rem] shrink-0 truncate font-mono text-[8px] text-muted-foreground`,children:[`→ `,e.references.table]}):null,(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] tracking-wide text-muted-foreground/70 uppercase`,children:e.type===`unknown`?``:e.type}),e.pii?(0,Q.jsx)(`span`,{className:`shrink-0 rounded border border-sky-500/30 px-1 text-[8px] text-sky-700 dark:text-sky-400`,children:`PII`}):null]})},e.name))}):null,!u&&d&&e?(0,Q.jsx)(ep,{store:e,namespace:t.name,tenant:c,tenancyDeclared:l,onPickField:e=>s(t.name,e)}):null]})}function ep({store:e,namespace:t,tenant:n,tenancyDeclared:r,onPickField:i}){let a=!r||n!==null&&n.length>0,o=Kn({ref:e.ref,child:t,prefix:`${t}:`,limit:40,...n?{tenant:n}:{}},a),s=Yf((o.data?.keys??[]).map(e=>e.value));return(0,Q.jsx)(`ul`,{className:`ml-3 border-l border-border/60`,children:a?o.isPending?(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-muted-foreground`,children:`Loading…`}):o.isError?(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-destructive`,children:`Couldn’t read fields.`}):s.length===0?(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-muted-foreground`,children:`No fields.`}):s.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i(e.name),className:`flex w-full items-center gap-1.5 px-2 py-1 text-left hover:bg-muted/50`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,children:e.name}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] tracking-wide text-muted-foreground/70 uppercase`,children:e.type===`unknown`?``:e.type})]})},e.name)):(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-muted-foreground`,children:`Select a tenant.`})})}function tp({facet:e,onExpand:t}){let n=e===`sql`?`Schema`:`Fields`;return(0,Q.jsx)(xr,{label:`Expand ${n.toLowerCase()}`,className:`h-full`,children:(0,Q.jsxs)(`button`,{type:`button`,"aria-label":`Expand ${n.toLowerCase()}`,"data-slot":`store-query-schema-expand`,onClick:t,className:`flex h-full w-7 shrink-0 flex-col items-center gap-2 border-l border-border/60 py-2 text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(q,{icon:j,className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`font-mono text-[10px] font-semibold tracking-[0.08em] uppercase [writing-mode:vertical-rl]`,children:n})]})})}function np({facet:e,stores:t,selectedEffectRef:n,tenancyDeclared:s,tenants:c,tenant:l,onTenantChange:u,manifest:d=null,leading:p}){let m=aa[e],h=(0,Z.useMemo)(()=>t.filter(t=>t.facet===e),[t,e]),[g,_]=(0,Z.useState)(()=>md(t,e,n)?.ref??h[0]?.ref??``),v=h.find(e=>e.ref===g)??md(h,e,null),y=op(v,e,n),b=v?.children.map(e=>e.name)??[],[x,C]=(0,Z.useState)(()=>ap(xf(e)??[{id:`q_1`,title:`Query 1`,text:y}],b,e)),[w,T]=(0,Z.useState)(()=>x[0]?.id??`q_1`),D=x.find(e=>e.id===w)??x[0],O=D?.text??y,[A,j]=(0,Z.useState)(null),[M,P]=(0,Z.useState)(null),[F,I]=(0,Z.useState)(null),[ee,L]=(0,Z.useState)(null),[te,R]=(0,Z.useState)(!1),[z,B]=(0,Z.useState)(!1),[V,re]=(0,Z.useState)(!0),[H,ie]=(0,Z.useState)({asGate:null,asUserId:null}),[ae,se]=(0,Z.useState)(!0),[ce,le]=(0,Z.useState)(()=>Cf(e)),[ue,de]=(0,Z.useState)(()=>Tf(e)),[pe,me]=(0,Z.useState)(!1),[U,he]=(0,Z.useState)(null),[ge,_e]=(0,Z.useState)(``),[ve,ye]=(0,Z.useState)({start:0,end:0}),[W,xe]=(0,Z.useState)([]),[Se,Ce]=(0,Z.useState)(0),[Te,Ee]=(0,Z.useState)(!1),De=(0,Z.useRef)(null),Oe=(0,Z.useRef)(!1),ke=(0,Z.useRef)(null),je=Zo(),Me=f(),G=!s||l!==null&&l.length>0,Ne=v?_d(v.ref):!1,K=e===`sql`,Pe=ur(`Enter`),Le=ur(`S`),Re=(0,Z.useMemo)(()=>Zf(v,d),[v,d]),ze=(0,Z.useMemo)(()=>K?ni(O):[],[K,O]),Be=(0,Z.useMemo)(()=>ze.map(e=>e.startLine),[ze]),Ve=ve.end!==ve.start,He=(0,Z.useMemo)(()=>K?ri(O,ve.start,ve.end,`current`):[O],[ve.end,ve.start,K,O]),We=K&&He.some(e=>ei(e));(0,Z.useEffect)(()=>{let r=md(t,e,n);r&&_(e=>h.some(t=>t.ref===e)?e:r.ref)},[t,e,n,h]);let Ge=b.join(`\0`);(0,Z.useEffect)(()=>{let t=Ge.length===0?[]:Ge.split(`\0`);t.length!==0&&C(n=>ap(n,t,e))},[Ge,e]),(0,Z.useEffect)(()=>{Sf(e,x)},[e,x]),(0,Z.useEffect)(()=>{Ef(e,ue)},[e,ue]),(0,Z.useEffect)(()=>()=>{ke.current!==null&&window.clearTimeout(ke.current)},[]);let Ke=e=>{D&&C(t=>gf(t,D.id,e))},qe=t=>{le(n=>{let r=yf(n,t);return wf(e,r),r})},Ye=e=>{let t=Math.max(0,Date.now()-e.started);xe([]),Ce(0),j(e.nextRows),P(e.nextMeta?`${e.nextMeta} · ${t}ms`:`${t}ms`),I(e.sqlText),L(e.nextError),qe({at:Date.now(),storeRef:v?.ref??``,text:e.sqlText,ok:e.nextError===null,rowCount:e.nextRows?.length??null,durationMs:t,...e.nextError?{error:e.nextError}:{}})},Xe=(e,t)=>{let n=e[t];xe(e),Ce(t),j(n?.rows??null),L(n?.error??null),P(n?.meta??null),I(n?.executed??e.map(e=>e.executed).join(`
40
- `)??null)},Ze=(e,t=!V,n=H)=>{if(!v)return;if(se(!0),L(null),!G){L(`Select a tenant first.`);return}if(Ne){L(`oke_console is the operator-plane auth schema — read-only from Store browse.`);return}let r=e.map(e=>e.trim()).filter(e=>e.length>0);if(r.length===0){L(`Nothing to run.`);return}let i=Date.now();Ee(!0),xe([]),Ce(0),(async()=>{try{let e=[],a=!1;for(let i of r){let r=si(i);r&&(a=!0);try{let a=await je.mutateAsync({ref:v.ref,sql:i,...r?{allowWrite:!0}:{},...t?{revealPii:!0}:{},...n.asGate?{asGate:n.asGate}:{},...n.asUserId?{asUserId:n.asUserId}:{},...l?{tenant:l}:{}}),o=ip(a.rows),s=[o===null?`${a.rows.length} row${a.rows.length===1?``:`s`}`:`${o} change${o===1?``:`s`}`,`routed ${a.routedRole}`];if(a.masked?s.push(`PII masked`):t&&s.push(`PII visible`),a.rls?.gate??a.asGate){let e=a.rls?.userId?`${a.rls.gate} / ${a.rls.userId}`:a.rls?.gate??a.asGate;s.push(a.gateApplied||a.rls?.applied?`as ${e}`:`as ${e} (not applied)`)}e.push({label:ci(i),rows:a.rows,error:null,meta:s.join(` · `),executed:i})}catch(t){e.push({label:ci(i),rows:null,error:t instanceof Error?t.message:String(t),meta:null,executed:i});break}}a&&Me.invalidateQueries({queryKey:tr});let o=Math.max(0,Date.now()-i),s=e[e.length-1],c=r.join(`
41
- `);Xe(e.map(e=>({...e,meta:e.meta?`${e.meta} · ${o}ms`:e.error?null:`${o}ms`})),Math.max(0,e.length-1)),qe({at:Date.now(),storeRef:v.ref,text:c,ok:s?.error==null,rowCount:e.reduce((e,t)=>e+(t.rows?.length??0),0),durationMs:o,...s?.error?{error:s.error}:{}})}finally{Ee(!1)}})()},Qe=(e,t=!V,n=H)=>{if(!v)return;if(se(!0),L(null),!G){L(`Select a tenant first.`);return}if(K){Ze([e],t,n);return}let r=Date.now(),i=Xd(e);if(i.kind===`error`){L(i.message);return}R(!0);let a=l?{tenant:l}:{};(async()=>{try{if(i.kind===`delete`){let t=await S({ref:v.ref,keys:[i.key],...a});if(t.error){Ye({sqlText:e,nextRows:null,nextMeta:null,nextError:rp(t.error),started:r});return}await Me.invalidateQueries({queryKey:tr});let n=t.data?.deleted??0;Ye({sqlText:e,nextRows:[{key:i.key,deleted:n}],nextMeta:n>0?`delete ${i.key}`:`delete ${i.key} · missing`,nextError:null,started:r});return}if(i.kind===`set`){let t=await Ie({ref:v.ref,key:i.key,...a,patch:Zd(i),commit:!0});if(t.error){Ye({sqlText:e,nextRows:null,nextMeta:null,nextError:rp(t.error),started:r});return}await Me.invalidateQueries({queryKey:tr})}let t=i.kind===`list`?i.prefix:i.key,n=await ne({ref:v.ref,prefix:t,limit:i.kind===`list`?200:1,...a});if(n.error){Ye({sqlText:e,nextRows:null,nextMeta:null,nextError:rp(n.error),started:r});return}let o=n.data?.keys??[],s=i.kind===`list`?o:o.filter(e=>e.key===i.key);if(i.kind===`ttl`){let t=s[0];Ye({sqlText:e,nextRows:[{key:i.key,ttlMs:t?.ttlMs??null,ttl:oi(t?.ttlMs??null)}],nextMeta:t?`ttl ${i.key}`:`ttl ${i.key} · missing`,nextError:null,started:r});return}let c=s.length>0?s.map(e=>({key:e.key,value:e.value??null,ttlMs:e.ttlMs??null,sizeBytes:e.sizeBytes??null})):i.kind===`set`&&!i.keepValue?[{key:i.key,value:i.value??null,ttlMs:null,sizeBytes:null}]:[];Ye({sqlText:e,nextRows:c,nextMeta:i.kind===`set`?`set ${i.key}`:`${c.length} key${c.length===1?``:`s`}`,nextError:null,started:r})}finally{R(!1)}})()},$e=()=>{if(K){Ze(He);return}let e=Math.min(ve.start,ve.end),t=Math.max(ve.start,ve.end);Qe(t>e?O.slice(e,t):O)},tt=()=>{Ze(ri(O,ve.start,ve.end,`all`))},rt=e=>{Ze(He.map(t=>Ii(t,e)))},it=e=>{let t=ze.find(t=>t.startLine===e);t&&Ze([t.text])},at=t=>{let n=h.find(e=>e.ref===t);_(t),D&&C(t=>gf(t,D.id,op(n,e,null))),j(null),P(null),I(null),L(null),xe([]),Ce(0)},ot=e=>{Ke(K?sd(e):pd(`${e}:`))},st=()=>{let t=mf(x,op(v,e,null)),n=t[t.length-1];!n||t===x||(C(t),T(n.id))},ct=e=>{ff(e.title)||(de(t=>vf(t,{id:e.id,title:e.title,text:e.text})),me(!0),ke.current!==null&&window.clearTimeout(ke.current),ke.current=window.setTimeout(()=>me(!1),1200))},lt=(e,t)=>{let n=_f(x,e,t);if(C(n),he(null),!Oe.current)return;Oe.current=!1;let r=n.find(t=>t.id===e);r&&ct(r)},ut=()=>{Oe.current=!1,he(null)},dt=e=>{T(e.id),he(e.id),_e(e.title)},ft=()=>{if(D){if(ff(D.title)){Oe.current=!0,dt(D);return}ct(D)}},pt=e=>{if(x.find(t=>t.id===e.id)){C(t=>gf(_f(t,e.id,e.title),e.id,e.text)),T(e.id);return}if(x.length>=8){if(!D)return;C(t=>gf(_f(t,D.id,e.title),D.id,e.text));return}let t=[...x,{id:e.id,title:e.title,text:e.text}];C(t),T(e.id)},mt=e=>{U===e&&ut();let t=hf(x,e,y);C(t),w===e&&T(t[t.length-1]?.id??t[0]?.id??`q_1`)},ht=K?je.isPending||Te:te,gt=lr(`Enter`);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`store-query-console`,onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&e.key===`s`&&(e.preventDefault(),ft())},children:[(0,Q.jsx)(Pr,{dataSlot:`store-query-header`,className:`relative z-30`,leading:p,icon:(0,Q.jsx)(q,{icon:m.icon,className:`size-4`}),wellClassName:m.wellClass,title:K?`SQL Query`:`KV Query`,badge:(0,Q.jsx)(`span`,{className:`font-mono text-[10px] font-medium tracking-[0.08em] text-muted-foreground`,children:v?.ref??`No store`}),subtitle:(0,Q.jsxs)(`span`,{className:`truncate font-mono text-[11px] leading-none text-muted-foreground`,children:[K?`DML / DDL`:`list / get / set / delete / ttl`,Ve?` · selection${He.length>1?` (${He.length})`:``}`:K?ze.length>1?` · ${ze.length} statements`:` · current statement`:``]}),actions:(0,Q.jsxs)(Q.Fragment,{children:[h.length>1?(0,Q.jsxs)(`div`,{className:`flex h-full items-stretch`,"data-slot":`store-query-store`,children:[(0,Q.jsx)(`span`,{className:o(et,`flex items-center px-2`),children:`Store`}),(0,Q.jsxs)(Oa,{value:v?.ref??``,onValueChange:at,className:`z-40 inline-flex h-full min-w-[8rem]`,children:[(0,Q.jsx)(ka,{flat:!0,"aria-label":`Query store`,className:`h-full w-auto px-2 font-mono text-[11px] hover:bg-muted/50`,children:(0,Q.jsx)(Aa,{})}),(0,Q.jsx)(ja,{children:h.map(e=>(0,Q.jsx)(Ma,{value:e.ref,className:`font-mono text-[11px]`,children:e.name},e.ref))})]})]}):null,s?(0,Q.jsx)(`div`,{className:`flex h-full items-stretch`,"data-slot":`store-query-tenant`,children:(0,Q.jsxs)(Oa,{value:l??``,onValueChange:e=>u(e.length>0?e:null),className:`z-40 inline-flex h-full min-w-[8rem]`,children:[(0,Q.jsx)(ka,{flat:!0,"aria-label":`Tenant`,className:`h-full w-auto px-2 font-mono text-[11px] hover:bg-muted/50`,children:(0,Q.jsx)(Aa,{placeholder:`Select tenant…`})}),(0,Q.jsx)(ja,{children:c.map(e=>(0,Q.jsx)(Ma,{value:e,className:`font-mono text-[11px]`,children:e},e))})]})}):null]})}),(0,Q.jsxs)(`div`,{className:`${be} overflow-x-auto`,role:`tablist`,"aria-label":`Query tabs`,children:[x.map(e=>(0,Q.jsxs)(`div`,{className:o(`group/tab flex h-full items-center gap-0.5 border-b-2 px-1`,e.id===w?`border-foreground text-foreground`:`border-transparent text-muted-foreground`),children:[U===e.id?(0,Q.jsx)(`input`,{autoFocus:!0,value:ge,maxLength:48,"aria-label":`Rename query`,"data-slot":`store-query-tab-rename`,onFocus:e=>e.currentTarget.select(),onChange:e=>_e(e.target.value),onBlur:()=>lt(e.id,ge),onKeyDown:t=>{t.key===`Enter`&&(t.preventDefault(),lt(e.id,ge)),t.key===`Escape`&&(t.preventDefault(),ut())},className:`h-5 min-w-[4.5rem] bg-transparent px-1.5 font-mono text-[11px] text-foreground outline-none`,style:{width:`${Math.max(6,ge.length+1)}ch`}}):(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e.id===w,title:`Double-click to rename`,"data-slot":`store-query-tab`,onClick:()=>T(e.id),onDoubleClick:t=>{t.preventDefault(),dt(e)},className:`max-w-[12rem] truncate px-1.5 font-mono text-[11px]`,children:e.title}),ue.some(t=>t.id===e.id)?(0,Q.jsx)(`span`,{className:`size-1 shrink-0 rounded-full bg-foreground/50`,"aria-label":`Saved`,title:`Saved`}):null,(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Close ${e.title}`,onClick:()=>mt(e.id),className:`flex size-4 items-center justify-center rounded-sm opacity-0 hover:bg-muted group-hover/tab:opacity-100`,children:(0,Q.jsx)(q,{icon:a,className:`size-2.5`})})]},e.id)),(0,Q.jsx)(xr,{label:`New query`,className:`flex self-stretch`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`New query`,disabled:x.length>=8,onClick:st,"data-slot":`store-query-tab-add`,className:oe,children:(0,Q.jsx)(q,{icon:i,className:`size-3.5`})})})]}),(0,Q.jsxs)(`div`,{className:be,children:[(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,onClick:()=>Ke(K?Xr(O):Bf(O)),"data-slot":`store-query-prettify`,children:[(0,Q.jsx)(q,{icon:N,"data-icon":`inline-start`,className:`size-3.5`}),`Prettify`]}),(0,Q.jsx)(xr,{label:pe?`Saved`:`Save`,keys:Le,className:`flex self-stretch`,children:(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,onClick:ft,"data-slot":`store-query-save`,children:[(0,Q.jsx)(q,{icon:pe?Ae:Fe,"data-icon":`inline-start`,className:`size-3.5`}),pe?`Saved`:`Save`]})}),(0,Q.jsx)(sp,{entries:ce,saved:ue,onPick:e=>{Ke(e.text),De.current?.focus()},onPickSaved:e=>{pt(e),De.current?.focus()}}),(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:o(`h-full rounded-none px-2 text-[11px]`,z&&`text-foreground`),"aria-pressed":z,onClick:()=>B(e=>!e),"data-slot":`store-query-schema`,children:[(0,Q.jsx)(q,{icon:r,"data-icon":`inline-start`,className:`size-3.5`}),K?`Schema`:`Keys`]}),K?(0,Q.jsx)(xr,{label:V?`PII hidden. Click to include cleartext (audited).`:`PII included. Click to remask.`,className:`flex self-stretch`,children:(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:o(`h-full rounded-none px-2 text-[11px]`,!V&&`text-amber-800 dark:text-amber-300`),"aria-pressed":!V,"aria-label":V?`Include PII: disabled`:`Include PII: enabled`,onClick:()=>{let e=!V;re(e),F&&!si(F)&&Qe(F,!e)},"data-slot":`store-query-pii`,children:[(0,Q.jsx)(q,{icon:V?fe:Je,"data-icon":`inline-start`,className:`size-3.5`}),`PII`]})}):null,K?(0,Q.jsx)(ju,{manifest:d,value:H,onChange:e=>{ie(e),F&&!si(F)&&Qe(F,!V,e)}}):null,We?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 text-[10px] text-amber-800 dark:text-amber-300`,title:`This SELECT has no LIMIT`,"data-slot":`store-query-unbounded`,children:[(0,Q.jsx)(q,{icon:we,className:`size-3`}),`No LIMIT`]}):null,(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsxs)(`div`,{className:`flex items-stretch`,children:[(0,Q.jsx)(xr,{label:Ve?`Run selection`:`Run`,keys:Pe,className:`flex self-stretch`,children:(0,Q.jsxs)(J,{type:`button`,size:`sm`,className:`h-full gap-1.5 rounded-none`,disabled:!v||ht,onClick:$e,"data-slot":`store-query-run`,children:[ht?(0,Q.jsx)(q,{icon:k,className:`size-3.5 animate-spin`}):(0,Q.jsx)(q,{icon:nt,className:`size-3.5`}),Ve?`Run selection`:`Run`]})}),K?(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(Gt,{render:e=>(0,Q.jsx)(J,{...e,type:`button`,size:`sm`,className:`h-full rounded-none border-l border-primary-foreground/20 px-1.5`,disabled:!v||ht,"aria-label":`More run options`,"data-slot":`store-query-run-menu`,children:(0,Q.jsx)(q,{icon:E,className:`size-3.5`})})}),(0,Q.jsxs)(Xt,{align:`end`,className:`w-56`,children:[(0,Q.jsxs)(Kt,{children:[(0,Q.jsxs)(Ut,{onClick:$e,children:[`Run current`,(0,Q.jsx)($t,{children:(0,Q.jsx)(Ue,{keys:Pe})})]}),(0,Q.jsxs)(Ut,{onClick:tt,disabled:ze.length<2,children:[`Run all`,(0,Q.jsx)($t,{children:(0,Q.jsx)(Ue,{keys:gt})})]})]}),(0,Q.jsx)(qt,{}),(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Ut,{onClick:()=>rt(!1),children:`EXPLAIN`}),(0,Q.jsx)(Ut,{onClick:()=>rt(!0),children:`EXPLAIN ANALYZE`})]})]})]}):null]})]}),(0,Q.jsxs)(dr,{orientation:`vertical`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(hr,{defaultSize:`72%`,minSize:`18%`,className:`min-h-0 overflow-hidden`,children:(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,Q.jsx)(ii,{value:O,onChange:Ke,language:K?`sql`:`kv`,onRun:$e,onRunAll:K?tt:void 0,onRunLine:K?it:void 0,runLines:Be,onCursorChange:(e,t)=>ye({start:e,end:t}),editorRef:De,label:K?`SQL query`:`KV command`,tables:Re,facet:e}),z?(0,Q.jsx)(Qf,{store:v,facet:e,manifest:d,tenant:l,tenancyDeclared:s,onPickTable:ot,onPickColumn:(e,t)=>{De.current?.insert(K?`"${t}"`:t)},onCollapse:()=>B(!1)}):(0,Q.jsx)(tp,{facet:e,onExpand:()=>B(!0)})]})}),ae?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(br,{withHandle:!0,className:`justify-end pr-8`}),(0,Q.jsx)(hr,{defaultSize:`28%`,minSize:`20%`,className:`min-h-0 overflow-hidden`,children:(0,Q.jsx)(Ti,{rows:A,error:ee,pending:ht,meta:M,executed:F,executedLanguage:K?`sql`:`kv`,storeRef:v?.ref,sets:W,activeSet:Se,onSelectSet:e=>Xe(W,e),onToggleCollapse:()=>se(!1)})})]}):null]}),ae?null:(0,Q.jsx)(Ti,{rows:A,error:ee,pending:ht,meta:M,executed:F,executedLanguage:K?`sql`:`kv`,storeRef:v?.ref,sets:W,activeSet:Se,onSelectSet:e=>Xe(W,e),collapsed:!0,onToggleCollapse:()=>se(!0)})]})}function rp(e){let t=e.data;return(t&&typeof t==`object`&&`ref`in t&&typeof t.ref==`string`?t.ref:null)??e.message??e.code}function ip(e){if(e.length!==1)return null;let t=e[0]?.changes;return typeof t==`number`&&Number.isFinite(t)?t:null}function ap(e,t,n){let r=!1,i=e.map(e=>{let i=fd(e.text,t,n);return i===e.text?e:(r=!0,{...e,text:i})});return r?i:e}function op(e,t,n){if(!e)return t===`sql`?sd():pd();let r=(n?e.children.find(e=>e.effectRef===n)?.name:void 0)??gd(e);return t===`sql`?sd(r):pd(r?`${r}:`:void 0)}function sp({entries:e,saved:t,onPick:n,onPickSaved:r}){return(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(Gt,{render:e=>(0,Q.jsxs)(J,{...e,type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,"data-slot":`store-query-history`,children:[(0,Q.jsx)(q,{icon:R,"data-icon":`inline-start`,className:`size-3.5`}),`History`]})}),(0,Q.jsxs)(Xt,{align:`start`,className:`w-80`,children:[(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Yt,{className:`font-mono text-[10px] tracking-[0.12em] uppercase`,children:`Saved`}),(0,Q.jsx)(qt,{}),t.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:`Save a named query to keep it across sessions.`}):t.map(e=>(0,Q.jsxs)(Ut,{className:`flex flex-col items-start gap-0.5 py-1.5`,onClick:()=>r(e),children:[(0,Q.jsx)(`span`,{className:`w-full truncate text-[11px]`,children:e.title}),(0,Q.jsx)(`span`,{className:`w-full truncate font-mono text-[10px] text-muted-foreground`,children:bf(e.text)})]},e.id))]}),(0,Q.jsx)(qt,{}),(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Yt,{className:`font-mono text-[10px] tracking-[0.12em] uppercase`,children:`Recent runs`}),(0,Q.jsx)(qt,{}),e.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:`No runs this session.`}):e.map(e=>(0,Q.jsxs)(Ut,{className:`flex flex-col items-start gap-0.5 py-1.5`,onClick:()=>n(e),children:[(0,Q.jsx)(`span`,{className:`w-full truncate font-mono text-[11px]`,children:bf(e.text)}),(0,Q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.ok?`${e.rowCount??0} · ${e.durationMs}ms`:e.error??`failed`})]},e.id))]})]})]})}var cp=`#38BDF8`,lp=[`#38BDF8`,`#34D399`,`#FBBF24`,`#A78BFA`,`#FB7185`,`#22D3EE`,`#F472B6`,`#4ADE80`,`#F59E0B`,`#818CF8`];function up(e){let t=new Set(e.map(e=>e.name)),n=new Map;for(let r of e)n.set(r.name,hp(r,t));return n}function dp(e){let t=up(e),n=[...new Set(t.values())].sort(),r=new Map;for(let[e,t]of n.entries())r.set(t,lp[e]??bp(t));let i=new Map;for(let n of e){let e=t.get(n.name)??yp(n.name);i.set(n.id,{cluster:e,hex:r.get(e)??`#38BDF8`})}return i}function fp(e,t){let n=t?dp(e.tables):new Map(e.tables.map(e=>[e.id,{cluster:`schema`,hex:cp}])),r=new Map;for(let t of e.tables){let e=n.get(t.id)?.hex;e&&r.set(t.name,e)}return{...e,nodes:e.nodes.map(e=>pp(e,n.get(e.id),r)),edges:e.edges.map(e=>mp(e,n.get(e.target)))}}function pp(e,t,n){let r=t??{cluster:`schema`,hex:`#38BDF8`},i={};for(let t of e.data.table.columns){let e=t.references?.table,r=e?n.get(e):void 0;r&&(i[t.name]=r)}return{...e,data:{...e.data,color:r,...Object.keys(i).length>0?{refHex:i}:{}}}}function mp(e,t){let n=t?.hex??`#38BDF8`,r=e.data?.inferred===!0;return{...e,markerEnd:{type:dt.ArrowClosed,width:16,height:16,color:n},style:{stroke:n,strokeWidth:1.5,...r?{strokeDasharray:`5 4`}:{}},data:{kind:`references`,inferred:r,relation:e.data?.relation??`many-to-one`,column:e.data?.column??``,hex:n}}}function hp(e,t){let n=gp(e.name,t);if(n)return n;if(_p(e.name,t))return yp(e.name);let r=e.columns.filter(t=>t.references?.table&&t.references.table!==e.name);if(r.length===1){let e=r[0]?.references?.table;if(e)return gp(e,t)??yp(e)}return yp(e.name)}function gp(e,t){let n=e.split(`_`)[0];if(!n||n===e)return null;for(let r of[n,`${n}s`,vp(n)])if(t.has(r)&&r!==e)return yp(r);return null}function _p(e,t){let n=yp(e);for(let r of t)if(r!==e&&gp(r,t)===n)return!0;return!1}function vp(e){return e.endsWith(`y`)&&!/[aeiou]y$/i.test(e)?`${e.slice(0,-1)}ies`:/(?:s|x|z|ch|sh)$/i.test(e)?`${e}es`:`${e}s`}function yp(e){return e.endsWith(`ies`)&&e.length>3?`${e.slice(0,-3)}y`:/(?:ses|xes|zes|ches|shes)$/i.test(e)?e.slice(0,-2):e.endsWith(`s`)&&!e.endsWith(`ss`)&&e.length>1?e.slice(0,-1):e}function bp(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+(e.codePointAt(n)??0)>>>0;return`hsl(${t%360} 70% 62%)`}var xp={"many-to-one":`Many-to-one`,"one-to-one":`One-to-one`,"many-to-many":`Many-to-many`,self:`Self`};function Sp({kind:e,className:t,hex:n}){return(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,className:o(`size-3.5 shrink-0`,!n&&`text-muted-foreground`,t),style:n?{color:n}:void 0,"aria-label":xp[e],fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,Q.jsx)(Cp,{kind:e})})}function Cp({kind:e}){return e===`one-to-one`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M6 7 V17`}),(0,Q.jsx)(`path`,{d:`M6 12 H18`}),(0,Q.jsx)(`path`,{d:`M18 7 V17`})]}):e===`many-to-many`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M3 6 L10 12 L3 18`}),(0,Q.jsx)(`path`,{d:`M10 12 H14`}),(0,Q.jsx)(`path`,{d:`M21 6 L14 12 L21 18`})]}):e===`self`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M8 16.5 A5.5 5.5 0 1 1 16.5 16.2`}),(0,Q.jsx)(`path`,{d:`M14.2 13.6 L16.5 16.4 L18.9 13.7`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M3 6 L10 12 L3 18`}),(0,Q.jsx)(`path`,{d:`M10 12 H16`}),(0,Q.jsx)(`path`,{d:`M16 7 V17`}),(0,Q.jsx)(`path`,{d:`M16 12 H21`})]})}function wp({id:e,sourceX:t,sourceY:n,targetX:r,targetY:i,sourcePosition:a,targetPosition:o,style:s,markerEnd:c,data:l}){let[d,f,p]=mt({sourceX:t,sourceY:n,sourcePosition:a,targetX:r,targetY:i,targetPosition:o}),m=l?.relation??`many-to-one`,h=l?.column??``,g=`${l?.inferred===!0?`Inferred`:`Declared`} ${Tn(m,h)}`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ht,{id:e,path:d,markerEnd:c,style:s}),(0,Q.jsx)(ft,{children:(0,Q.jsx)(`div`,{className:`nodrag nopan pointer-events-auto absolute`,style:{transform:`translate(-50%, -50%) translate(${f}px,${p}px)`,opacity:typeof s?.opacity==`number`?s.opacity:1},children:(0,Q.jsxs)(A,{children:[(0,Q.jsx)(C,{render:e=>(0,Q.jsx)(`span`,{...e,"aria-label":g,className:`flex items-center justify-center rounded-sm border border-border/60 bg-background/90 p-0.5 shadow-sm`,children:(0,Q.jsx)(Sp,{kind:m,hex:l?.hex})})}),(0,Q.jsx)(u,{side:`top`,className:`text-[11px]`,children:g})]})})})]})}var Tp={relation:wp};function Ep({data:e}){let{table:t,showStore:n,dimmed:r,selected:i,color:a,refHex:s}=e,c=a?.hex??`#38BDF8`;return(0,Q.jsxs)(`div`,{"data-slot":`store-schema-table`,"data-table":t.name,"data-cluster":a?.cluster,className:o(`flex h-full w-full flex-col overflow-hidden rounded-lg border bg-card text-[11px] shadow-sm`,r&&`opacity-30 saturate-[0.4]`),style:{borderColor:i?c:`color-mix(in oklab, ${c} 42%, var(--border))`,boxShadow:i?`0 0 0 2px color-mix(in oklab, ${c} 35%, transparent)`:void 0},children:[(0,Q.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-1.5 border-b px-2`,style:{background:`color-mix(in oklab, ${c} 22%, var(--card))`,borderColor:`color-mix(in oklab, ${c} 28%, var(--border))`},children:[(0,Q.jsx)(`span`,{className:`size-2 shrink-0 rounded-full`,style:{background:c},"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-semibold text-foreground`,children:t.name}),(0,Q.jsx)(`span`,{"data-slot":`store-schema-rls`,"data-rls":t.rls===!0?`on`:`off`,title:t.rls===!0?`RLS enabled`:`RLS disabled`,className:o(`shrink-0`,t.rls===!0?`text-emerald-500`:`text-muted-foreground/35`),children:(0,Q.jsx)(q,{icon:t.rls===!0?B:b,className:`size-3`,"aria-hidden":!0})}),n?(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] tracking-[0.08em] text-muted-foreground uppercase`,children:t.storeName}):(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums text-[10px] text-muted-foreground`,children:t.columns.length})]}),(0,Q.jsx)(`ul`,{className:`flex min-h-0 flex-1 flex-col`,children:t.columns.length===0?(0,Q.jsx)(`li`,{className:`relative flex h-[22px] items-center px-2 text-muted-foreground`,children:`No columns`}):t.columns.map(e=>(0,Q.jsx)(Dp,{column:e,tableName:t.name,junction:Op(t.columns),tableHex:c,refHex:s?.[e.name]},e.name))})]})}function Dp({column:e,tableName:t,junction:n,tableHex:r,refHex:i}){let a=i??r,s=e.type===`integer`?`text-teal-600 dark:text-teal-400`:e.type===`text`?`text-muted-foreground`:`text-muted-foreground/80`;return(0,Q.jsxs)(`li`,{className:`relative flex h-[22px] items-center gap-1.5 px-2`,children:[(0,Q.jsx)(ct,{type:`target`,position:_t.Left,id:`in:${e.name}`,className:`!size-1.5 !border-0`,style:{background:r}}),(0,Q.jsx)(`span`,{className:o(`size-1.5 shrink-0 rounded-full`,e.nullable===!1?`bg-foreground/70`:`border border-foreground/50`),title:e.nullable===!1?`Not null`:`Nullable`,"aria-hidden":!0}),(0,Q.jsx)(zi,{primaryKey:e.primaryKey,foreignKey:e.references!==void 0,unique:e.unique,inferred:e.inferredRef,hex:a}),(0,Q.jsx)(`span`,{className:o(`min-w-0 truncate font-mono text-[10px]`,!i&&`text-foreground`),style:i?{color:i}:void 0,title:Ap(e),children:e.name}),e.references?.table?(0,Q.jsxs)(`span`,{className:`inline-flex max-w-[6rem] shrink-0 items-center gap-0.5 truncate text-muted-foreground`,title:Ap(e,t,n),children:[(0,Q.jsx)(Sp,{kind:kp(e,t,n),hex:a,className:`size-3`}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-[8px]`,children:e.references.table})]}):null,(0,Q.jsx)(`span`,{className:o(`ml-auto shrink-0 font-mono text-[9px]`,s),children:e.type}),e.pii?(0,Q.jsx)(`span`,{className:`shrink-0 rounded border border-border/70 px-1 text-[8px] font-semibold tracking-[0.08em] text-muted-foreground uppercase`,children:`PII`}):null,(0,Q.jsx)(ct,{type:`source`,position:_t.Right,id:`out:${e.name}`,className:`!size-1.5 !border-0`,style:{background:a}})]})}function Op(e){return e.filter(e=>e.references?.table).length<2?!1:e.every(e=>e.primaryKey===!0||e.references!==void 0)}function kp(e,t,n){return e.references?.table===t?`self`:e.unique===!0||e.primaryKey===!0?`one-to-one`:n?`many-to-many`:`many-to-one`}function Ap(e,t,n=!1){if(!e.references)return;let r=e.references.column?`${e.references.table}.${e.references.column}`:e.references.table,i=t===void 0?`FK`:Tn(kp(e,t,n),e.name);return`${e.inferredRef?`Inferred`:`Declared`} ${i} → ${r}`}var jp={table:Ep};function Mp(e){return(0,Q.jsx)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`store-schema-visualizer`,children:(0,Q.jsx)(yt,{children:(0,Q.jsx)(Np,{...e})})})}function Np({stores:e,manifest:t,selectedEffectRef:n,onSelectTable:r,leading:i}){let{fitView:a}=ut(),{theme:s}=Ht(),c=Ft(),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(0),[p,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(!0),[v,y]=(0,Z.useState)(!0),b=s===`system`?window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:s,S=(0,Z.useMemo)(()=>un(e,t),[e,t]),C=(0,Z.useMemo)(()=>fp(sr(S),g),[S,g]),[w,T,E]=xt([...C.nodes]),[D,O,k]=pt([...C.edges]);(0,Z.useEffect)(()=>{T(wn(C.nodes,l,n,C.edges,v)),O(rn(C.edges,n,v,c!==!0))},[C,v,d,l,c,n,O,T]),(0,Z.useEffect)(()=>{let e=window.setTimeout(()=>{a({padding:.18,duration:240})},40);return()=>window.clearTimeout(e)},[a,d,S.length]);let A=(0,Z.useCallback)(async()=>{let e=Cn(S);if(e.length!==0)try{await navigator.clipboard.writeText(e),h(!0),window.setTimeout(()=>h(!1),1400)}catch{h(!1)}},[S]);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:se,"data-slot":`store-schema-toolbar`,children:[i?(0,Q.jsxs)(Q.Fragment,{children:[i,(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0})]}):null,(0,Q.jsx)(`span`,{className:o(et,`flex items-center px-2`),children:`Schema`}),(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,Q.jsx)(fr,{value:l,onChange:e=>u(e.target.value),placeholder:`Find table…`,"aria-label":`Find table`,"data-slot":`store-schema-find`}),(0,Q.jsxs)(`span`,{className:o(Me,`flex items-center px-2`),children:[S.length,` `,S.length===1?`table`:`tables`]}),(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-stretch`,children:[(0,Q.jsxs)(jr,{active:g,"aria-pressed":g,onClick:()=>_(e=>!e),className:`h-full`,"data-slot":`store-schema-colorize`,children:[(0,Q.jsx)(q,{icon:m,className:`size-3`,"aria-hidden":!0}),`Colorize`]}),(0,Q.jsxs)(jr,{active:p,disabled:S.length===0,onClick:()=>void A(),className:`h-full disabled:pointer-events-none disabled:opacity-40`,"data-slot":`store-schema-copy-sql`,children:[(0,Q.jsx)(q,{icon:p?Ae:x,className:`size-3`,"aria-hidden":!0}),p?`Copied`:`Copy as SQL`]}),(0,Q.jsx)(jr,{active:!1,disabled:S.length===0,onClick:()=>f(e=>e+1),className:`h-full disabled:pointer-events-none disabled:opacity-40`,"data-slot":`store-schema-auto-layout`,children:`Auto layout`})]})]}),(0,Q.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[S.length===0?(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-6`,children:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No SQL tables to visualize.`})}):(0,Q.jsxs)(lt,{nodes:w,edges:D,nodeTypes:jp,edgeTypes:Tp,onNodesChange:E,onEdgesChange:k,colorMode:b,fitView:!0,nodesConnectable:!1,elementsSelectable:!0,proOptions:{hideAttribution:!0},minZoom:.15,maxZoom:1.8,defaultEdgeOptions:{type:`relation`,style:{stroke:`#38BDF8`,strokeWidth:1.5}},onNodeClick:(e,t)=>{y(!0),r(t.id)},onPaneClick:()=>y(!1),"data-slot":`store-schema-canvas`,children:[(0,Q.jsx)(bt,{gap:24,size:1,color:`color-mix(in oklab, var(--foreground) 14%, transparent)`}),(0,Q.jsx)(vt,{showInteractive:!1}),(0,Q.jsx)(gt,{pannable:!0,zoomable:!0,ariaLabel:`Schema graph overview`,bgColor:`var(--card)`,maskColor:`color-mix(in oklab, var(--background) 55%, transparent)`,nodeColor:e=>e.data.color?.hex??`#64748B`,nodeStrokeColor:`transparent`,nodeStrokeWidth:12,nodeBorderRadius:8})]}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute bottom-3 left-1/2 z-10 max-w-[min(720px,calc(100%-2rem))] -translate-x-1/2`,children:(0,Q.jsxs)(`p`,{className:`flex flex-wrap items-center justify-center gap-x-2 gap-y-0.5 rounded-md border border-border/60 bg-background/80 px-2 py-1 text-[10px] text-muted-foreground backdrop-blur-sm`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Bi,{kind:`pk`}),`primary`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Bi,{kind:`fk`}),`foreign`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Bi,{kind:`unique`}),`unique`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Sp,{kind:`many-to-one`}),`many`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Sp,{kind:`one-to-one`}),`one`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Sp,{kind:`many-to-many`}),`join`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Sp,{kind:`self`}),`self`]}),(0,Q.jsx)(`span`,{children:`dashed = inferred`}),(0,Q.jsx)(`span`,{children:`filled = not null`})]})})]})]})}function Pp(){let e=ti(),t=Rr(),n=Hr();Lr(!0);let{selectedResource:r,selectedTenant:i,queryFacet:a,schemaView:o,performanceView:s,performanceFacet:c,setSelectedResource:l,setSelectedTenant:u,setQueryFacet:d,setSchemaView:f,setPerformanceView:p}=Ct(),m=_r(),h=(0,Q.jsx)(vr,{open:m.open,onToggle:m.toggle,noun:`store`,controlsId:`store-tree`,dataSlot:`store-tree-toggle`}),g=e.data?.stores??[],_=r??ga(g),v=(0,Z.useMemo)(()=>_?ca(g,_):null,[g,_]);return(0,Q.jsx)(`div`,{className:de,"data-slot":`store-page`,children:(0,Q.jsxs)(dr,{orientation:`horizontal`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(hr,{panelRef:m.panelRef,collapsible:!0,collapsedSize:0,defaultSize:ke.start.defaultSize,minSize:ke.start.minSize,onResize:m.onResize,className:`min-h-0 overflow-hidden`,children:(0,Q.jsx)(`div`,{id:`store-tree`,className:`h-full min-h-0 overflow-hidden`,"data-slot":`store-tree`,children:(0,Q.jsx)(Ku,{stores:g,selectedEffectRef:_,onSelect:e=>{l(e,{keepView:o||s})},queryFacet:a,schemaActive:o,performanceActive:s,performanceFacet:c,onOpenQuery:e=>{d(a===e?null:e)},onOpenSchema:()=>{f(!o)},onOpenPerformance:e=>{s&&(c??`sql`)===e?p(!1):p(!0,e)}})})}),m.open?(0,Q.jsx)(br,{withHandle:!0}):null,(0,Q.jsx)(hr,{defaultSize:ke.end.defaultSize,minSize:ke.end.minSize,className:`min-h-0 overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full min-h-0 overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,children:o?(0,Q.jsx)(Mp,{stores:g,manifest:t.data??null,selectedEffectRef:_,onSelectTable:e=>l(e,{keepView:!0}),leading:h}):s?(0,Q.jsx)(Rd,{stores:g,selectedEffectRef:_,tenant:i,facet:c??`sql`,leading:h}):a?(0,Q.jsx)(np,{facet:a,stores:g,selectedEffectRef:_,tenancyDeclared:e.data?.tenancyDeclared??!1,tenants:e.data?.tenants??[],tenant:i,onTenantChange:u,manifest:t.data??null,leading:h},a):v?(0,Q.jsx)(Vu,{store:v.store,child:v.child,manifest:t.data??null,tenancyDeclared:e.data?.tenancyDeclared??!1,tenants:e.data?.tenants??[],tenant:i,onTenantChange:u,runs:n.data??[],leading:h}):(0,Q.jsx)(wr,{leading:h,icon:Sr.store.icon,title:e.isLoading?`Loading stores…`:e.isError?`Store unavailable`:`Select a resource`,description:e.isLoading?`Reading store catalogs.`:e.isError?e.error.message:`Pick a table, namespace, bucket, or index from the tree.`})})})})]})})}export{Pp as StorePage};
39
+ `).trim()}function Vf(e){let t=Xd(e);return t.kind===`error`?e.trim():Hf(t)}function Hf(e){switch(e.kind){case`list`:return e.prefix.length===0?`list()`:`list(${JSON.stringify(e.prefix)})`;case`get`:case`delete`:case`ttl`:return`${e.kind}(${JSON.stringify(e.key)})`;case`set`:{let t=[JSON.stringify(e.key),e.keepValue?`value`:Uf(e.value)];return e.ttl!==void 0&&e.ttl!==null&&t.push(JSON.stringify(e.ttl)),`set(${t.join(`, `)})`}}}function Uf(e){if(typeof e==`object`&&e)try{return JSON.stringify(e,null,2)??`null`}catch{return`null`}try{return JSON.stringify(e)??`null`}catch{return`null`}}function Wf(e,t,n,r){let i=e?.stores?.[t]?.tables?.[n];return i?.columns?Gf(i.columns,r):[]}function Gf(e,t){return Object.entries(e).map(([e,n])=>Kf(e,n,t?.[e]))}function Kf(e,t,n){let r=Yf(t)?t:null,i=Jf(r),a=r?.nullable===!1||r?.primaryKey===!0,o=n??(typeof r?.description==`string`?r.description:void 0);return{path:`/${e}`,name:e,type:i,required:a,...r?.enumValues!==void 0&&r.enumValues.length>0?{enumValues:[...r.enumValues]}:{},...o===void 0?{}:{description:o},...t.pii===!0?{pii:!0}:{},...t.sensitive===!0?{sensitive:!0}:{},...r?.primaryKey===!0?{primaryKey:!0}:{},...r?.unique===!0&&r.primaryKey!==!0?{unique:!0}:{},...r?.references?.table?{foreignKey:!0,references:{table:r.references.table,...r.references.column===void 0?{}:{column:r.references.column}}}:{}}}var qf=new Set([`smallint`,`integer`,`bigint`,`serial`,`smallserial`,`bigserial`,`real`,`doublePrecision`]);function Jf(e){let t=e?.type;return t===void 0?`unknown`:t===`boolean`?`boolean`:qf.has(t)?t===`real`||t===`doublePrecision`?`number`:`integer`:t===`json`||t===`jsonb`?`object`:`string`}function Yf(e){return`type`in e||`nullable`in e||`primaryKey`in e||`unique`in e||`sqlName`in e||`description`in e||`references`in e||`default`in e}function Xf(e,t,n){if(e){let r=Wf(n,e.name,t.name,t.columnDescriptions);if(r.length>0)return r}let r=Ri(t.piiColumns);return[...new Set([...Object.keys(t.columnDescriptions),...t.piiColumns])].map(e=>({path:`/${e}`,name:e,type:`unknown`,required:!1,...t.columnDescriptions[e]===void 0?{}:{description:t.columnDescriptions[e]},...r.has(e)?{pii:!0}:{}}))}function Zf(e){let t=new Map;for(let n of e)if(!(!n||typeof n!=`object`||Array.isArray(n)))for(let[e,r]of Object.entries(n))t.has(e)||t.set(e,Qf(r));return[...t.entries()].map(([e,t])=>({name:e,type:t}))}function Qf(e){return e==null?`unknown`:Array.isArray(e)?`array`:typeof e==`object`?`object`:typeof e==`number`?Number.isInteger(e)?`integer`:`number`:typeof e==`boolean`?`boolean`:typeof e==`string`?`string`:`unknown`}function $f(e,t){if(!e)return[];let n=new Map(e.facet===`sql`?un([e],t).map(e=>[e.name,e]):[]);return e.children.filter(e=>!jn(e)).map(r=>({name:r.name,columns:Xf(e,r,t).map(e=>{let t=n.get(r.name)?.columns.find(t=>t.name===e.name);return{name:e.name,type:e.type,...e.pii===!0?{pii:!0}:{},...e.primaryKey===!0||t?.primaryKey===!0?{primaryKey:!0}:{},...t?.unique===!0?{unique:!0}:{},...t?.references?{references:t.references,...t.inferredRef===!0?{inferredRef:!0}:{}}:{}}})}))}function ep({store:e,facet:t,manifest:n,onPickTable:r,onPickColumn:i,onCollapse:a,tenant:s=null,tenancyDeclared:c=!1}){let l=e?.children??[],u=t===`sql`,d=(0,Z.useMemo)(()=>$f(e,n),[e,n]);return(0,Q.jsxs)(`aside`,{className:`flex h-full min-h-0 w-56 shrink-0 flex-col overflow-hidden border-l border-border/60`,"data-slot":`store-query-schema-panel`,children:[(0,Q.jsxs)(`header`,{className:o(be,`justify-between px-2`),children:[(0,Q.jsx)(`p`,{className:o(et,`min-w-0 truncate font-mono`),children:u?`Schema`:`Namespaces`}),a?(0,Q.jsx)(xr,{label:`Collapse schema`,className:`flex self-stretch`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Collapse schema`,"data-slot":`store-query-schema-collapse`,onClick:a,className:oe,children:(0,Q.jsx)(q,{icon:v,className:`size-3.5`})})}):null]}),(0,Q.jsx)(`ul`,{className:`min-h-0 flex-1 overflow-y-auto`,children:l.length===0?(0,Q.jsx)(`li`,{className:`px-2 py-4 text-[11px] text-muted-foreground`,children:`No resources.`}):l.map(a=>(0,Q.jsx)(tp,{store:e,child:a,facet:t,manifest:n,sqlColumns:d.find(e=>e.name===a.name)?.columns,onPickTable:r,onPickColumn:i,tenant:s,tenancyDeclared:c},a.effectRef))})]})}function tp({store:e,child:t,facet:n,manifest:r,sqlColumns:i,onPickTable:a,onPickColumn:s,tenant:c,tenancyDeclared:l}){let u=n===`sql`,[d,f]=(0,Z.useState)(!0),p=i??Xf(e,t,r),m=!u||p.length>0;return(0,Q.jsxs)(`li`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center`,children:[m?(0,Q.jsx)(`button`,{type:`button`,"aria-expanded":d,"aria-label":`${d?`Collapse`:`Expand`} ${t.name}`,onClick:()=>f(e=>!e),className:Se,children:(0,Q.jsx)(q,{icon:E,className:o(`size-3 transition-transform`,!d&&`-rotate-90`)})}):(0,Q.jsx)(`span`,{className:`size-6`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(t.name),className:`min-w-0 flex-1 truncate px-2 py-1.5 text-left font-mono text-[11px] text-foreground hover:bg-muted/50`,title:u?`SELECT * FROM "${t.name}"`:`list ${t.name}:`,children:t.name})]}),u&&d&&p.length>0?(0,Q.jsx)(`ul`,{className:`border-l border-border/60 ml-3`,children:p.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(t.name,e.name),className:`flex w-full items-center gap-1.5 px-2 py-1 text-left hover:bg-muted/50`,children:[(0,Q.jsx)(zi,{primaryKey:e.primaryKey,foreignKey:`references`in e&&e.references!==void 0,unique:`unique`in e?e.unique:void 0,inferred:`inferredRef`in e?e.inferredRef:void 0}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,children:e.name}),`references`in e&&e.references?.table?(0,Q.jsxs)(`span`,{className:`max-w-[4rem] shrink-0 truncate font-mono text-[8px] text-muted-foreground`,children:[`→ `,e.references.table]}):null,(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] tracking-wide text-muted-foreground/70 uppercase`,children:e.type===`unknown`?``:e.type}),e.pii?(0,Q.jsx)(`span`,{className:`shrink-0 rounded border border-sky-500/30 px-1 text-[8px] text-sky-700 dark:text-sky-400`,children:`PII`}):null]})},e.name))}):null,!u&&d&&e?(0,Q.jsx)(np,{store:e,namespace:t.name,tenant:c,tenancyDeclared:l,onPickField:e=>s(t.name,e)}):null]})}function np({store:e,namespace:t,tenant:n,tenancyDeclared:r,onPickField:i}){let a=!r||n!==null&&n.length>0,o=Kn({ref:e.ref,child:t,prefix:`${t}:`,limit:40,...n?{tenant:n}:{}},a),s=Zf((o.data?.keys??[]).map(e=>e.value));return(0,Q.jsx)(`ul`,{className:`ml-3 border-l border-border/60`,children:a?o.isPending?(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-muted-foreground`,children:`Loading…`}):o.isError?(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-destructive`,children:`Couldn’t read fields.`}):s.length===0?(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-muted-foreground`,children:`No fields.`}):s.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i(e.name),className:`flex w-full items-center gap-1.5 px-2 py-1 text-left hover:bg-muted/50`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,children:e.name}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] tracking-wide text-muted-foreground/70 uppercase`,children:e.type===`unknown`?``:e.type})]})},e.name)):(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-muted-foreground`,children:`Select a tenant.`})})}function rp({facet:e,onExpand:t}){let n=e===`sql`?`Schema`:`Fields`;return(0,Q.jsx)(xr,{label:`Expand ${n.toLowerCase()}`,className:`h-full`,children:(0,Q.jsxs)(`button`,{type:`button`,"aria-label":`Expand ${n.toLowerCase()}`,"data-slot":`store-query-schema-expand`,onClick:t,className:`flex h-full w-7 shrink-0 flex-col items-center gap-2 border-l border-border/60 py-2 text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(q,{icon:j,className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`font-mono text-[10px] font-semibold tracking-[0.08em] uppercase [writing-mode:vertical-rl]`,children:n})]})})}function ip({facet:e,stores:t,selectedEffectRef:n,tenancyDeclared:s,tenants:c,tenant:l,onTenantChange:u,manifest:d=null,leading:p}){let m=aa[e],h=(0,Z.useMemo)(()=>t.filter(t=>t.facet===e),[t,e]),[g,_]=(0,Z.useState)(()=>md(t,e,n)?.ref??h[0]?.ref??``),v=h.find(e=>e.ref===g)??md(h,e,null),y=cp(v,e,n),b=v?.children.map(e=>e.name)??[],[x,C]=(0,Z.useState)(()=>sp(xf(e)??[{id:`q_1`,title:`Query 1`,text:y}],b,e)),[w,T]=(0,Z.useState)(()=>x[0]?.id??`q_1`),D=x.find(e=>e.id===w)??x[0],O=D?.text??y,[A,j]=(0,Z.useState)(null),[M,P]=(0,Z.useState)(null),[F,I]=(0,Z.useState)(null),[ee,L]=(0,Z.useState)(null),[te,R]=(0,Z.useState)(!1),[z,B]=(0,Z.useState)(!1),[V,re]=(0,Z.useState)(!0),[H,ie]=(0,Z.useState)({asGate:null,asUserId:null}),[ae,se]=(0,Z.useState)(!0),[ce,le]=(0,Z.useState)(()=>Cf(e)),[ue,de]=(0,Z.useState)(()=>Tf(e)),[pe,me]=(0,Z.useState)(!1),[U,he]=(0,Z.useState)(null),[ge,_e]=(0,Z.useState)(``),[ve,ye]=(0,Z.useState)({start:0,end:0}),[W,xe]=(0,Z.useState)([]),[Se,Ce]=(0,Z.useState)(0),[Te,Ee]=(0,Z.useState)(!1),De=(0,Z.useRef)(null),Oe=(0,Z.useRef)(!1),ke=(0,Z.useRef)(null),je=Zo(),Me=f(),G=!s||l!==null&&l.length>0,Ne=v?_d(v.ref):!1,K=e===`sql`,Pe=ur(`Enter`),Le=ur(`S`),Re=(0,Z.useMemo)(()=>$f(v,d),[v,d]),ze=(0,Z.useMemo)(()=>K?ni(O):[],[K,O]),Be=(0,Z.useMemo)(()=>ze.map(e=>e.startLine),[ze]),Ve=ve.end!==ve.start,He=(0,Z.useMemo)(()=>K?ri(O,ve.start,ve.end,`current`):[O],[ve.end,ve.start,K,O]),We=K&&He.some(e=>ei(e));(0,Z.useEffect)(()=>{let r=md(t,e,n);r&&_(e=>h.some(t=>t.ref===e)?e:r.ref)},[t,e,n,h]);let Ge=b.join(`\0`);(0,Z.useEffect)(()=>{let t=Ge.length===0?[]:Ge.split(`\0`);t.length!==0&&C(n=>sp(n,t,e))},[Ge,e]),(0,Z.useEffect)(()=>{Sf(e,x)},[e,x]),(0,Z.useEffect)(()=>{Ef(e,ue)},[e,ue]),(0,Z.useEffect)(()=>()=>{ke.current!==null&&window.clearTimeout(ke.current)},[]);let Ke=e=>{D&&C(t=>gf(t,D.id,e))},qe=t=>{le(n=>{let r=yf(n,t);return wf(e,r),r})},Ye=e=>{let t=Math.max(0,Date.now()-e.started);xe([]),Ce(0),j(e.nextRows),P(e.nextMeta?`${e.nextMeta} · ${t}ms`:`${t}ms`),I(e.sqlText),L(e.nextError),qe({at:Date.now(),storeRef:v?.ref??``,text:e.sqlText,ok:e.nextError===null,rowCount:e.nextRows?.length??null,durationMs:t,...e.nextError?{error:e.nextError}:{}})},Xe=(e,t)=>{let n=e[t];xe(e),Ce(t),j(n?.rows??null),L(n?.error??null),P(n?.meta??null),I(n?.executed??e.map(e=>e.executed).join(`
40
+ `)??null)},Ze=(e,t=!V,n=H)=>{if(!v)return;if(se(!0),L(null),!G){L(`Select a tenant first.`);return}if(Ne){L(`oke_console is the operator-plane auth schema — read-only from Store browse.`);return}let r=e.map(e=>e.trim()).filter(e=>e.length>0);if(r.length===0){L(`Nothing to run.`);return}let i=Date.now();Ee(!0),xe([]),Ce(0),(async()=>{try{let e=[],a=!1;for(let i of r){let r=si(i);r&&(a=!0);try{let a=await je.mutateAsync({ref:v.ref,sql:i,...r?{allowWrite:!0}:{},...t?{revealPii:!0}:{},...n.asGate?{asGate:n.asGate}:{},...n.asUserId?{asUserId:n.asUserId}:{},...l?{tenant:l}:{}}),o=op(a.rows),s=[o===null?`${a.rows.length} row${a.rows.length===1?``:`s`}`:`${o} change${o===1?``:`s`}`,`routed ${a.routedRole}`];if(a.masked?s.push(`PII masked`):t&&s.push(`PII visible`),a.rls?.gate??a.asGate){let e=a.rls?.userId?`${a.rls.gate} / ${a.rls.userId}`:a.rls?.gate??a.asGate;s.push(a.gateApplied||a.rls?.applied?`as ${e}`:`as ${e} (not applied)`)}e.push({label:ci(i),rows:a.rows,error:null,meta:s.join(` · `),executed:i})}catch(t){e.push({label:ci(i),rows:null,error:t instanceof Error?t.message:String(t),meta:null,executed:i});break}}a&&Me.invalidateQueries({queryKey:tr});let o=Math.max(0,Date.now()-i),s=e[e.length-1],c=r.join(`
41
+ `);Xe(e.map(e=>({...e,meta:e.meta?`${e.meta} · ${o}ms`:e.error?null:`${o}ms`})),Math.max(0,e.length-1)),qe({at:Date.now(),storeRef:v.ref,text:c,ok:s?.error==null,rowCount:e.reduce((e,t)=>e+(t.rows?.length??0),0),durationMs:o,...s?.error?{error:s.error}:{}})}finally{Ee(!1)}})()},Qe=(e,t=!V,n=H)=>{if(!v)return;if(se(!0),L(null),!G){L(`Select a tenant first.`);return}if(K){Ze([e],t,n);return}let r=Date.now(),i=Xd(e);if(i.kind===`error`){L(i.message);return}R(!0);let a=l?{tenant:l}:{};(async()=>{try{if(i.kind===`delete`){let t=await S({ref:v.ref,keys:[i.key],...a});if(t.error){Ye({sqlText:e,nextRows:null,nextMeta:null,nextError:ap(t.error),started:r});return}await Me.invalidateQueries({queryKey:tr});let n=t.data?.deleted??0;Ye({sqlText:e,nextRows:[{key:i.key,deleted:n}],nextMeta:n>0?`delete ${i.key}`:`delete ${i.key} · missing`,nextError:null,started:r});return}if(i.kind===`set`){let t=await Ie({ref:v.ref,key:i.key,...a,patch:Zd(i),commit:!0});if(t.error){Ye({sqlText:e,nextRows:null,nextMeta:null,nextError:ap(t.error),started:r});return}await Me.invalidateQueries({queryKey:tr})}let t=i.kind===`list`?i.prefix:i.key,n=await ne({ref:v.ref,prefix:t,limit:i.kind===`list`?200:1,...a});if(n.error){Ye({sqlText:e,nextRows:null,nextMeta:null,nextError:ap(n.error),started:r});return}let o=n.data?.keys??[],s=i.kind===`list`?o:o.filter(e=>e.key===i.key);if(i.kind===`ttl`){let t=s[0];Ye({sqlText:e,nextRows:[{key:i.key,ttlMs:t?.ttlMs??null,ttl:oi(t?.ttlMs??null)}],nextMeta:t?`ttl ${i.key}`:`ttl ${i.key} · missing`,nextError:null,started:r});return}let c=s.length>0?s.map(e=>({key:e.key,value:e.value??null,ttlMs:e.ttlMs??null,sizeBytes:e.sizeBytes??null})):i.kind===`set`&&!i.keepValue?[{key:i.key,value:i.value??null,ttlMs:null,sizeBytes:null}]:[];Ye({sqlText:e,nextRows:c,nextMeta:i.kind===`set`?`set ${i.key}`:`${c.length} key${c.length===1?``:`s`}`,nextError:null,started:r})}finally{R(!1)}})()},$e=()=>{if(K){Ze(He);return}let e=Math.min(ve.start,ve.end),t=Math.max(ve.start,ve.end);Qe(t>e?O.slice(e,t):O)},tt=()=>{Ze(ri(O,ve.start,ve.end,`all`))},rt=e=>{Ze(He.map(t=>Ii(t,e)))},it=e=>{let t=ze.find(t=>t.startLine===e);t&&Ze([t.text])},at=t=>{let n=h.find(e=>e.ref===t);_(t),D&&C(t=>gf(t,D.id,cp(n,e,null))),j(null),P(null),I(null),L(null),xe([]),Ce(0)},ot=e=>{Ke(K?sd(e):pd(`${e}:`))},st=()=>{let t=mf(x,cp(v,e,null)),n=t[t.length-1];!n||t===x||(C(t),T(n.id))},ct=e=>{ff(e.title)||(de(t=>vf(t,{id:e.id,title:e.title,text:e.text})),me(!0),ke.current!==null&&window.clearTimeout(ke.current),ke.current=window.setTimeout(()=>me(!1),1200))},lt=(e,t)=>{let n=_f(x,e,t);if(C(n),he(null),!Oe.current)return;Oe.current=!1;let r=n.find(t=>t.id===e);r&&ct(r)},ut=()=>{Oe.current=!1,he(null)},dt=e=>{T(e.id),he(e.id),_e(e.title)},ft=()=>{if(D){if(ff(D.title)){Oe.current=!0,dt(D);return}ct(D)}},pt=e=>{if(x.find(t=>t.id===e.id)){C(t=>gf(_f(t,e.id,e.title),e.id,e.text)),T(e.id);return}if(x.length>=8){if(!D)return;C(t=>gf(_f(t,D.id,e.title),D.id,e.text));return}let t=[...x,{id:e.id,title:e.title,text:e.text}];C(t),T(e.id)},mt=e=>{U===e&&ut();let t=hf(x,e,y);C(t),w===e&&T(t[t.length-1]?.id??t[0]?.id??`q_1`)},ht=K?je.isPending||Te:te,gt=lr(`Enter`);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`store-query-console`,onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&e.key===`s`&&(e.preventDefault(),ft())},children:[(0,Q.jsx)(Pr,{dataSlot:`store-query-header`,className:`relative z-30`,leading:p,icon:(0,Q.jsx)(q,{icon:m.icon,className:`size-4`}),wellClassName:m.wellClass,title:K?`SQL Query`:`KV Query`,badge:(0,Q.jsx)(`span`,{className:`font-mono text-[10px] font-medium tracking-[0.08em] text-muted-foreground`,children:v?.ref??`No store`}),subtitle:(0,Q.jsxs)(`span`,{className:`truncate font-mono text-[11px] leading-none text-muted-foreground`,children:[K?`DML / DDL`:`list / get / set / delete / ttl`,Ve?` · selection${He.length>1?` (${He.length})`:``}`:K?ze.length>1?` · ${ze.length} statements`:` · current statement`:``]}),actions:(0,Q.jsxs)(Q.Fragment,{children:[h.length>1?(0,Q.jsxs)(`div`,{className:`flex h-full items-stretch`,"data-slot":`store-query-store`,children:[(0,Q.jsx)(`span`,{className:o(et,`flex items-center px-2`),children:`Store`}),(0,Q.jsxs)(Oa,{value:v?.ref??``,onValueChange:at,className:`z-40 inline-flex h-full min-w-[8rem]`,children:[(0,Q.jsx)(ka,{flat:!0,"aria-label":`Query store`,className:`h-full w-auto px-2 font-mono text-[11px] hover:bg-muted/50`,children:(0,Q.jsx)(Aa,{})}),(0,Q.jsx)(ja,{children:h.map(e=>(0,Q.jsx)(Ma,{value:e.ref,className:`font-mono text-[11px]`,children:e.name},e.ref))})]})]}):null,s?(0,Q.jsx)(`div`,{className:`flex h-full items-stretch`,"data-slot":`store-query-tenant`,children:(0,Q.jsxs)(Oa,{value:l??``,onValueChange:e=>u(e.length>0?e:null),className:`z-40 inline-flex h-full min-w-[8rem]`,children:[(0,Q.jsx)(ka,{flat:!0,"aria-label":`Tenant`,className:`h-full w-auto px-2 font-mono text-[11px] hover:bg-muted/50`,children:(0,Q.jsx)(Aa,{placeholder:`Select tenant…`})}),(0,Q.jsx)(ja,{children:c.map(e=>(0,Q.jsx)(Ma,{value:e,className:`font-mono text-[11px]`,children:e},e))})]})}):null]})}),(0,Q.jsxs)(`div`,{className:`${be} overflow-x-auto`,role:`tablist`,"aria-label":`Query tabs`,children:[x.map(e=>(0,Q.jsxs)(`div`,{className:o(`group/tab flex h-full items-center gap-0.5 border-b-2 px-1`,e.id===w?`border-foreground text-foreground`:`border-transparent text-muted-foreground`),children:[U===e.id?(0,Q.jsx)(`input`,{autoFocus:!0,value:ge,maxLength:48,"aria-label":`Rename query`,"data-slot":`store-query-tab-rename`,onFocus:e=>e.currentTarget.select(),onChange:e=>_e(e.target.value),onBlur:()=>lt(e.id,ge),onKeyDown:t=>{t.key===`Enter`&&(t.preventDefault(),lt(e.id,ge)),t.key===`Escape`&&(t.preventDefault(),ut())},className:`h-5 min-w-[4.5rem] bg-transparent px-1.5 font-mono text-[11px] text-foreground outline-none`,style:{width:`${Math.max(6,ge.length+1)}ch`}}):(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e.id===w,title:`Double-click to rename`,"data-slot":`store-query-tab`,onClick:()=>T(e.id),onDoubleClick:t=>{t.preventDefault(),dt(e)},className:`max-w-[12rem] truncate px-1.5 font-mono text-[11px]`,children:e.title}),ue.some(t=>t.id===e.id)?(0,Q.jsx)(`span`,{className:`size-1 shrink-0 rounded-full bg-foreground/50`,"aria-label":`Saved`,title:`Saved`}):null,(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Close ${e.title}`,onClick:()=>mt(e.id),className:`flex size-4 items-center justify-center rounded-sm opacity-0 hover:bg-muted group-hover/tab:opacity-100`,children:(0,Q.jsx)(q,{icon:a,className:`size-2.5`})})]},e.id)),(0,Q.jsx)(xr,{label:`New query`,className:`flex self-stretch`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`New query`,disabled:x.length>=8,onClick:st,"data-slot":`store-query-tab-add`,className:oe,children:(0,Q.jsx)(q,{icon:i,className:`size-3.5`})})})]}),(0,Q.jsxs)(`div`,{className:be,children:[(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,onClick:()=>Ke(K?Xr(O):Bf(O)),"data-slot":`store-query-prettify`,children:[(0,Q.jsx)(q,{icon:N,"data-icon":`inline-start`,className:`size-3.5`}),`Prettify`]}),(0,Q.jsx)(xr,{label:pe?`Saved`:`Save`,keys:Le,className:`flex self-stretch`,children:(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,onClick:ft,"data-slot":`store-query-save`,children:[(0,Q.jsx)(q,{icon:pe?Ae:Fe,"data-icon":`inline-start`,className:`size-3.5`}),pe?`Saved`:`Save`]})}),(0,Q.jsx)(lp,{entries:ce,saved:ue,onPick:e=>{Ke(e.text),De.current?.focus()},onPickSaved:e=>{pt(e),De.current?.focus()}}),(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:o(`h-full rounded-none px-2 text-[11px]`,z&&`text-foreground`),"aria-pressed":z,onClick:()=>B(e=>!e),"data-slot":`store-query-schema`,children:[(0,Q.jsx)(q,{icon:r,"data-icon":`inline-start`,className:`size-3.5`}),K?`Schema`:`Keys`]}),K?(0,Q.jsx)(xr,{label:V?`PII hidden. Click to include cleartext (audited).`:`PII included. Click to remask.`,className:`flex self-stretch`,children:(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:o(`h-full rounded-none px-2 text-[11px]`,!V&&`text-amber-800 dark:text-amber-300`),"aria-pressed":!V,"aria-label":V?`Include PII: disabled`:`Include PII: enabled`,onClick:()=>{let e=!V;re(e),F&&!si(F)&&Qe(F,!e)},"data-slot":`store-query-pii`,children:[(0,Q.jsx)(q,{icon:V?fe:Je,"data-icon":`inline-start`,className:`size-3.5`}),`PII`]})}):null,K?(0,Q.jsx)(ju,{manifest:d,value:H,onChange:e=>{ie(e),F&&!si(F)&&Qe(F,!V,e)}}):null,We?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 text-[10px] text-amber-800 dark:text-amber-300`,title:`This SELECT has no LIMIT`,"data-slot":`store-query-unbounded`,children:[(0,Q.jsx)(q,{icon:we,className:`size-3`}),`No LIMIT`]}):null,(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsxs)(`div`,{className:`flex items-stretch`,children:[(0,Q.jsx)(xr,{label:Ve?`Run selection`:`Run`,keys:Pe,className:`flex self-stretch`,children:(0,Q.jsxs)(J,{type:`button`,size:`sm`,className:`h-full gap-1.5 rounded-none`,disabled:!v||ht,onClick:$e,"data-slot":`store-query-run`,children:[ht?(0,Q.jsx)(q,{icon:k,className:`size-3.5 animate-spin`}):(0,Q.jsx)(q,{icon:nt,className:`size-3.5`}),Ve?`Run selection`:`Run`]})}),K?(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(Gt,{render:e=>(0,Q.jsx)(J,{...e,type:`button`,size:`sm`,className:`h-full rounded-none border-l border-primary-foreground/20 px-1.5`,disabled:!v||ht,"aria-label":`More run options`,"data-slot":`store-query-run-menu`,children:(0,Q.jsx)(q,{icon:E,className:`size-3.5`})})}),(0,Q.jsxs)(Xt,{align:`end`,className:`w-56`,children:[(0,Q.jsxs)(Kt,{children:[(0,Q.jsxs)(Ut,{onClick:$e,children:[`Run current`,(0,Q.jsx)($t,{children:(0,Q.jsx)(Ue,{keys:Pe})})]}),(0,Q.jsxs)(Ut,{onClick:tt,disabled:ze.length<2,children:[`Run all`,(0,Q.jsx)($t,{children:(0,Q.jsx)(Ue,{keys:gt})})]})]}),(0,Q.jsx)(qt,{}),(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Ut,{onClick:()=>rt(!1),children:`EXPLAIN`}),(0,Q.jsx)(Ut,{onClick:()=>rt(!0),children:`EXPLAIN ANALYZE`})]})]})]}):null]})]}),(0,Q.jsxs)(dr,{orientation:`vertical`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(hr,{defaultSize:`72%`,minSize:`18%`,className:`min-h-0 overflow-hidden`,children:(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,Q.jsx)(ii,{value:O,onChange:Ke,language:K?`sql`:`kv`,onRun:$e,onRunAll:K?tt:void 0,onRunLine:K?it:void 0,runLines:Be,onCursorChange:(e,t)=>ye({start:e,end:t}),editorRef:De,label:K?`SQL query`:`KV command`,tables:Re,facet:e}),z?(0,Q.jsx)(ep,{store:v,facet:e,manifest:d,tenant:l,tenancyDeclared:s,onPickTable:ot,onPickColumn:(e,t)=>{De.current?.insert(K?`"${t}"`:t)},onCollapse:()=>B(!1)}):(0,Q.jsx)(rp,{facet:e,onExpand:()=>B(!0)})]})}),ae?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(br,{withHandle:!0,className:`justify-end pr-8`}),(0,Q.jsx)(hr,{defaultSize:`28%`,minSize:`20%`,className:`min-h-0 overflow-hidden`,children:(0,Q.jsx)(Ti,{rows:A,error:ee,pending:ht,meta:M,executed:F,executedLanguage:K?`sql`:`kv`,storeRef:v?.ref,sets:W,activeSet:Se,onSelectSet:e=>Xe(W,e),onToggleCollapse:()=>se(!1)})})]}):null]}),ae?null:(0,Q.jsx)(Ti,{rows:A,error:ee,pending:ht,meta:M,executed:F,executedLanguage:K?`sql`:`kv`,storeRef:v?.ref,sets:W,activeSet:Se,onSelectSet:e=>Xe(W,e),collapsed:!0,onToggleCollapse:()=>se(!0)})]})}function ap(e){let t=e.data;return(t&&typeof t==`object`&&`ref`in t&&typeof t.ref==`string`?t.ref:null)??e.message??e.code}function op(e){if(e.length!==1)return null;let t=e[0]?.changes;return typeof t==`number`&&Number.isFinite(t)?t:null}function sp(e,t,n){let r=!1,i=e.map(e=>{let i=fd(e.text,t,n);return i===e.text?e:(r=!0,{...e,text:i})});return r?i:e}function cp(e,t,n){if(!e)return t===`sql`?sd():pd();let r=(n?e.children.find(e=>e.effectRef===n)?.name:void 0)??gd(e);return t===`sql`?sd(r):pd(r?`${r}:`:void 0)}function lp({entries:e,saved:t,onPick:n,onPickSaved:r}){return(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(Gt,{render:e=>(0,Q.jsxs)(J,{...e,type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,"data-slot":`store-query-history`,children:[(0,Q.jsx)(q,{icon:R,"data-icon":`inline-start`,className:`size-3.5`}),`History`]})}),(0,Q.jsxs)(Xt,{align:`start`,className:`w-80`,children:[(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Yt,{className:`font-mono text-[10px] tracking-[0.12em] uppercase`,children:`Saved`}),(0,Q.jsx)(qt,{}),t.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:`Save a named query to keep it across sessions.`}):t.map(e=>(0,Q.jsxs)(Ut,{className:`flex flex-col items-start gap-0.5 py-1.5`,onClick:()=>r(e),children:[(0,Q.jsx)(`span`,{className:`w-full truncate text-[11px]`,children:e.title}),(0,Q.jsx)(`span`,{className:`w-full truncate font-mono text-[10px] text-muted-foreground`,children:bf(e.text)})]},e.id))]}),(0,Q.jsx)(qt,{}),(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Yt,{className:`font-mono text-[10px] tracking-[0.12em] uppercase`,children:`Recent runs`}),(0,Q.jsx)(qt,{}),e.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:`No runs this session.`}):e.map(e=>(0,Q.jsxs)(Ut,{className:`flex flex-col items-start gap-0.5 py-1.5`,onClick:()=>n(e),children:[(0,Q.jsx)(`span`,{className:`w-full truncate font-mono text-[11px]`,children:bf(e.text)}),(0,Q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.ok?`${e.rowCount??0} · ${e.durationMs}ms`:e.error??`failed`})]},e.id))]})]})]})}var up=`#38BDF8`,dp=[`#38BDF8`,`#34D399`,`#FBBF24`,`#A78BFA`,`#FB7185`,`#22D3EE`,`#F472B6`,`#4ADE80`,`#F59E0B`,`#818CF8`];function fp(e){let t=new Set(e.map(e=>e.name)),n=new Map;for(let r of e)n.set(r.name,_p(r,t));return n}function pp(e){let t=fp(e),n=[...new Set(t.values())].sort(),r=new Map;for(let[e,t]of n.entries())r.set(t,dp[e]??Sp(t));let i=new Map;for(let n of e){let e=t.get(n.name)??xp(n.name);i.set(n.id,{cluster:e,hex:r.get(e)??`#38BDF8`})}return i}function mp(e,t){let n=t?pp(e.tables):new Map(e.tables.map(e=>[e.id,{cluster:`schema`,hex:up}])),r=new Map;for(let t of e.tables){let e=n.get(t.id)?.hex;e&&r.set(t.name,e)}return{...e,nodes:e.nodes.map(e=>hp(e,n.get(e.id),r)),edges:e.edges.map(e=>gp(e,n.get(e.target)))}}function hp(e,t,n){let r=t??{cluster:`schema`,hex:`#38BDF8`},i={};for(let t of e.data.table.columns){let e=t.references?.table,r=e?n.get(e):void 0;r&&(i[t.name]=r)}return{...e,data:{...e.data,color:r,...Object.keys(i).length>0?{refHex:i}:{}}}}function gp(e,t){let n=t?.hex??`#38BDF8`,r=e.data?.inferred===!0;return{...e,markerEnd:{type:dt.ArrowClosed,width:16,height:16,color:n},style:{stroke:n,strokeWidth:1.5,...r?{strokeDasharray:`5 4`}:{}},data:{kind:`references`,inferred:r,relation:e.data?.relation??`many-to-one`,column:e.data?.column??``,hex:n}}}function _p(e,t){let n=vp(e.name,t);if(n)return n;if(yp(e.name,t))return xp(e.name);let r=e.columns.filter(t=>t.references?.table&&t.references.table!==e.name);if(r.length===1){let e=r[0]?.references?.table;if(e)return vp(e,t)??xp(e)}return xp(e.name)}function vp(e,t){let n=e.split(`_`)[0];if(!n||n===e)return null;for(let r of[n,`${n}s`,bp(n)])if(t.has(r)&&r!==e)return xp(r);return null}function yp(e,t){let n=xp(e);for(let r of t)if(r!==e&&vp(r,t)===n)return!0;return!1}function bp(e){return e.endsWith(`y`)&&!/[aeiou]y$/i.test(e)?`${e.slice(0,-1)}ies`:/(?:s|x|z|ch|sh)$/i.test(e)?`${e}es`:`${e}s`}function xp(e){return e.endsWith(`ies`)&&e.length>3?`${e.slice(0,-3)}y`:/(?:ses|xes|zes|ches|shes)$/i.test(e)?e.slice(0,-2):e.endsWith(`s`)&&!e.endsWith(`ss`)&&e.length>1?e.slice(0,-1):e}function Sp(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+(e.codePointAt(n)??0)>>>0;return`hsl(${t%360} 70% 62%)`}var Cp={"many-to-one":`Many-to-one`,"one-to-one":`One-to-one`,"many-to-many":`Many-to-many`,self:`Self`};function wp({kind:e,className:t,hex:n}){return(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,className:o(`size-3.5 shrink-0`,!n&&`text-muted-foreground`,t),style:n?{color:n}:void 0,"aria-label":Cp[e],fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,Q.jsx)(Tp,{kind:e})})}function Tp({kind:e}){return e===`one-to-one`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M6 7 V17`}),(0,Q.jsx)(`path`,{d:`M6 12 H18`}),(0,Q.jsx)(`path`,{d:`M18 7 V17`})]}):e===`many-to-many`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M3 6 L10 12 L3 18`}),(0,Q.jsx)(`path`,{d:`M10 12 H14`}),(0,Q.jsx)(`path`,{d:`M21 6 L14 12 L21 18`})]}):e===`self`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M8 16.5 A5.5 5.5 0 1 1 16.5 16.2`}),(0,Q.jsx)(`path`,{d:`M14.2 13.6 L16.5 16.4 L18.9 13.7`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M3 6 L10 12 L3 18`}),(0,Q.jsx)(`path`,{d:`M10 12 H16`}),(0,Q.jsx)(`path`,{d:`M16 7 V17`}),(0,Q.jsx)(`path`,{d:`M16 12 H21`})]})}function Ep({id:e,sourceX:t,sourceY:n,targetX:r,targetY:i,sourcePosition:a,targetPosition:o,style:s,markerEnd:c,data:l}){let[d,f,p]=mt({sourceX:t,sourceY:n,sourcePosition:a,targetX:r,targetY:i,targetPosition:o}),m=l?.relation??`many-to-one`,h=l?.column??``,g=`${l?.inferred===!0?`Inferred`:`Declared`} ${Tn(m,h)}`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ht,{id:e,path:d,markerEnd:c,style:s}),(0,Q.jsx)(ft,{children:(0,Q.jsx)(`div`,{className:`nodrag nopan pointer-events-auto absolute`,style:{transform:`translate(-50%, -50%) translate(${f}px,${p}px)`,opacity:typeof s?.opacity==`number`?s.opacity:1},children:(0,Q.jsxs)(A,{children:[(0,Q.jsx)(C,{render:e=>(0,Q.jsx)(`span`,{...e,"aria-label":g,className:`flex items-center justify-center rounded-sm border border-border/60 bg-background/90 p-0.5 shadow-sm`,children:(0,Q.jsx)(wp,{kind:m,hex:l?.hex})})}),(0,Q.jsx)(u,{side:`top`,className:`text-[11px]`,children:g})]})})})]})}var Dp={relation:Ep};function Op({data:e}){let{table:t,showStore:n,dimmed:r,selected:i,color:a,refHex:s}=e,c=a?.hex??`#38BDF8`;return(0,Q.jsxs)(`div`,{"data-slot":`store-schema-table`,"data-table":t.name,"data-cluster":a?.cluster,className:o(`flex h-full w-full flex-col overflow-hidden rounded-lg border bg-card text-[11px] shadow-sm`,r&&`opacity-30 saturate-[0.4]`),style:{borderColor:i?c:`color-mix(in oklab, ${c} 42%, var(--border))`,boxShadow:i?`0 0 0 2px color-mix(in oklab, ${c} 35%, transparent)`:void 0},children:[(0,Q.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-1.5 border-b px-2`,style:{background:`color-mix(in oklab, ${c} 22%, var(--card))`,borderColor:`color-mix(in oklab, ${c} 28%, var(--border))`},children:[(0,Q.jsx)(`span`,{className:`size-2 shrink-0 rounded-full`,style:{background:c},"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-semibold text-foreground`,children:t.name}),(0,Q.jsx)(`span`,{"data-slot":`store-schema-rls`,"data-rls":t.rls===!0?`on`:`off`,title:t.rls===!0?`RLS enabled`:`RLS disabled`,className:o(`shrink-0`,t.rls===!0?`text-emerald-500`:`text-muted-foreground/35`),children:(0,Q.jsx)(q,{icon:t.rls===!0?B:b,className:`size-3`,"aria-hidden":!0})}),n?(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] tracking-[0.08em] text-muted-foreground uppercase`,children:t.storeName}):(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums text-[10px] text-muted-foreground`,children:t.columns.length})]}),(0,Q.jsx)(`ul`,{className:`flex min-h-0 flex-1 flex-col`,children:t.columns.length===0?(0,Q.jsx)(`li`,{className:`relative flex h-[22px] items-center px-2 text-muted-foreground`,children:`No columns`}):t.columns.map(e=>(0,Q.jsx)(kp,{column:e,tableName:t.name,junction:Ap(t.columns),tableHex:c,refHex:s?.[e.name]},e.name))})]})}function kp({column:e,tableName:t,junction:n,tableHex:r,refHex:i}){let a=i??r,s=e.type===`integer`?`text-teal-600 dark:text-teal-400`:e.type===`text`?`text-muted-foreground`:`text-muted-foreground/80`;return(0,Q.jsxs)(`li`,{className:`relative flex h-[22px] items-center gap-1.5 px-2`,children:[(0,Q.jsx)(ct,{type:`target`,position:_t.Left,id:`in:${e.name}`,className:`!size-1.5 !border-0`,style:{background:r}}),(0,Q.jsx)(`span`,{className:o(`size-1.5 shrink-0 rounded-full`,e.nullable===!1?`bg-foreground/70`:`border border-foreground/50`),title:e.nullable===!1?`Not null`:`Nullable`,"aria-hidden":!0}),(0,Q.jsx)(zi,{primaryKey:e.primaryKey,foreignKey:e.references!==void 0,unique:e.unique,inferred:e.inferredRef,hex:a}),(0,Q.jsx)(`span`,{className:o(`min-w-0 truncate font-mono text-[10px]`,!i&&`text-foreground`),style:i?{color:i}:void 0,title:Mp(e),children:e.name}),e.references?.table?(0,Q.jsxs)(`span`,{className:`inline-flex max-w-[6rem] shrink-0 items-center gap-0.5 truncate text-muted-foreground`,title:Mp(e,t,n),children:[(0,Q.jsx)(wp,{kind:jp(e,t,n),hex:a,className:`size-3`}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-[8px]`,children:e.references.table})]}):null,(0,Q.jsx)(`span`,{className:o(`ml-auto shrink-0 font-mono text-[9px]`,s),children:e.type}),e.pii?(0,Q.jsx)(`span`,{className:`shrink-0 rounded border border-border/70 px-1 text-[8px] font-semibold tracking-[0.08em] text-muted-foreground uppercase`,children:`PII`}):null,(0,Q.jsx)(ct,{type:`source`,position:_t.Right,id:`out:${e.name}`,className:`!size-1.5 !border-0`,style:{background:a}})]})}function Ap(e){return e.filter(e=>e.references?.table).length<2?!1:e.every(e=>e.primaryKey===!0||e.references!==void 0)}function jp(e,t,n){return e.references?.table===t?`self`:e.unique===!0||e.primaryKey===!0?`one-to-one`:n?`many-to-many`:`many-to-one`}function Mp(e,t,n=!1){if(!e.references)return;let r=e.references.column?`${e.references.table}.${e.references.column}`:e.references.table,i=t===void 0?`FK`:Tn(jp(e,t,n),e.name);return`${e.inferredRef?`Inferred`:`Declared`} ${i} → ${r}`}var Np={table:Op};function Pp(e){return(0,Q.jsx)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`store-schema-visualizer`,children:(0,Q.jsx)(yt,{children:(0,Q.jsx)(Fp,{...e})})})}function Fp({stores:e,manifest:t,selectedEffectRef:n,onSelectTable:r,leading:i}){let{fitView:a}=ut(),{theme:s}=Ht(),c=Ft(),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(0),[p,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(!0),[v,y]=(0,Z.useState)(!0),b=s===`system`?window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:s,S=(0,Z.useMemo)(()=>un(e,t),[e,t]),C=(0,Z.useMemo)(()=>mp(sr(S),g),[S,g]),[w,T,E]=xt([...C.nodes]),[D,O,k]=pt([...C.edges]);(0,Z.useEffect)(()=>{T(wn(C.nodes,l,n,C.edges,v)),O(rn(C.edges,n,v,c!==!0))},[C,v,d,l,c,n,O,T]),(0,Z.useEffect)(()=>{let e=window.setTimeout(()=>{a({padding:.18,duration:240})},40);return()=>window.clearTimeout(e)},[a,d,S.length]);let A=(0,Z.useCallback)(async()=>{let e=Cn(S);if(e.length!==0)try{await navigator.clipboard.writeText(e),h(!0),window.setTimeout(()=>h(!1),1400)}catch{h(!1)}},[S]);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:se,"data-slot":`store-schema-toolbar`,children:[i?(0,Q.jsxs)(Q.Fragment,{children:[i,(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0})]}):null,(0,Q.jsx)(`span`,{className:o(et,`flex items-center px-2`),children:`Schema`}),(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,Q.jsx)(fr,{value:l,onChange:e=>u(e.target.value),placeholder:`Find table…`,"aria-label":`Find table`,"data-slot":`store-schema-find`}),(0,Q.jsxs)(`span`,{className:o(Me,`flex items-center px-2`),children:[S.length,` `,S.length===1?`table`:`tables`]}),(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-stretch`,children:[(0,Q.jsxs)(jr,{active:g,"aria-pressed":g,onClick:()=>_(e=>!e),className:`h-full`,"data-slot":`store-schema-colorize`,children:[(0,Q.jsx)(q,{icon:m,className:`size-3`,"aria-hidden":!0}),`Colorize`]}),(0,Q.jsxs)(jr,{active:p,disabled:S.length===0,onClick:()=>void A(),className:`h-full disabled:pointer-events-none disabled:opacity-40`,"data-slot":`store-schema-copy-sql`,children:[(0,Q.jsx)(q,{icon:p?Ae:x,className:`size-3`,"aria-hidden":!0}),p?`Copied`:`Copy as SQL`]}),(0,Q.jsx)(jr,{active:!1,disabled:S.length===0,onClick:()=>f(e=>e+1),className:`h-full disabled:pointer-events-none disabled:opacity-40`,"data-slot":`store-schema-auto-layout`,children:`Auto layout`})]})]}),(0,Q.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[S.length===0?(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-6`,children:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No SQL tables to visualize.`})}):(0,Q.jsxs)(lt,{nodes:w,edges:D,nodeTypes:Np,edgeTypes:Dp,onNodesChange:E,onEdgesChange:k,colorMode:b,fitView:!0,nodesConnectable:!1,elementsSelectable:!0,proOptions:{hideAttribution:!0},minZoom:.15,maxZoom:1.8,defaultEdgeOptions:{type:`relation`,style:{stroke:`#38BDF8`,strokeWidth:1.5}},onNodeClick:(e,t)=>{y(!0),r(t.id)},onPaneClick:()=>y(!1),"data-slot":`store-schema-canvas`,children:[(0,Q.jsx)(bt,{gap:24,size:1,color:`color-mix(in oklab, var(--foreground) 14%, transparent)`}),(0,Q.jsx)(vt,{showInteractive:!1}),(0,Q.jsx)(gt,{pannable:!0,zoomable:!0,ariaLabel:`Schema graph overview`,bgColor:`var(--card)`,maskColor:`color-mix(in oklab, var(--background) 55%, transparent)`,nodeColor:e=>e.data.color?.hex??`#64748B`,nodeStrokeColor:`transparent`,nodeStrokeWidth:12,nodeBorderRadius:8})]}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute bottom-3 left-1/2 z-10 max-w-[min(720px,calc(100%-2rem))] -translate-x-1/2`,children:(0,Q.jsxs)(`p`,{className:`flex flex-wrap items-center justify-center gap-x-2 gap-y-0.5 rounded-md border border-border/60 bg-background/80 px-2 py-1 text-[10px] text-muted-foreground backdrop-blur-sm`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Bi,{kind:`pk`}),`primary`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Bi,{kind:`fk`}),`foreign`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Bi,{kind:`unique`}),`unique`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(wp,{kind:`many-to-one`}),`many`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(wp,{kind:`one-to-one`}),`one`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(wp,{kind:`many-to-many`}),`join`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(wp,{kind:`self`}),`self`]}),(0,Q.jsx)(`span`,{children:`dashed = inferred`}),(0,Q.jsx)(`span`,{children:`filled = not null`})]})})]})]})}function Ip(){let e=ti(),t=Rr(),n=Hr();Lr(!0);let{selectedResource:r,selectedTenant:i,queryFacet:a,schemaView:o,performanceView:s,performanceFacet:c,setSelectedResource:l,setSelectedTenant:u,setQueryFacet:d,setSchemaView:f,setPerformanceView:p}=Ct(),m=_r(),h=(0,Q.jsx)(vr,{open:m.open,onToggle:m.toggle,noun:`store`,controlsId:`store-tree`,dataSlot:`store-tree-toggle`}),g=e.data?.stores??[],_=r??ga(g),v=(0,Z.useMemo)(()=>_?ca(g,_):null,[g,_]);return(0,Q.jsx)(`div`,{className:de,"data-slot":`store-page`,children:(0,Q.jsxs)(dr,{orientation:`horizontal`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(hr,{panelRef:m.panelRef,collapsible:!0,collapsedSize:0,defaultSize:ke.start.defaultSize,minSize:ke.start.minSize,onResize:m.onResize,className:`min-h-0 overflow-hidden`,children:(0,Q.jsx)(`div`,{id:`store-tree`,className:`h-full min-h-0 overflow-hidden`,"data-slot":`store-tree`,children:(0,Q.jsx)(Ku,{stores:g,selectedEffectRef:_,onSelect:e=>{l(e,{keepView:o||s})},queryFacet:a,schemaActive:o,performanceActive:s,performanceFacet:c,onOpenQuery:e=>{d(a===e?null:e)},onOpenSchema:()=>{f(!o)},onOpenPerformance:e=>{s&&(c??`sql`)===e?p(!1):p(!0,e)}})})}),m.open?(0,Q.jsx)(br,{withHandle:!0}):null,(0,Q.jsx)(hr,{defaultSize:ke.end.defaultSize,minSize:ke.end.minSize,className:`min-h-0 overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full min-h-0 overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,children:o?(0,Q.jsx)(Pp,{stores:g,manifest:t.data??null,selectedEffectRef:_,onSelectTable:e=>l(e,{keepView:!0}),leading:h}):s?(0,Q.jsx)(Rd,{stores:g,selectedEffectRef:_,tenant:i,facet:c??`sql`,leading:h}):a?(0,Q.jsx)(ip,{facet:a,stores:g,selectedEffectRef:_,tenancyDeclared:e.data?.tenancyDeclared??!1,tenants:e.data?.tenants??[],tenant:i,onTenantChange:u,manifest:t.data??null,leading:h},a):v?(0,Q.jsx)(Vu,{store:v.store,child:v.child,manifest:t.data??null,tenancyDeclared:e.data?.tenancyDeclared??!1,tenants:e.data?.tenants??[],tenant:i,onTenantChange:u,runs:n.data??[],leading:h}):(0,Q.jsx)(wr,{leading:h,icon:Sr.store.icon,title:e.isLoading?`Loading stores…`:e.isError?`Store unavailable`:`Select a resource`,description:e.isLoading?`Reading store catalogs.`:e.isError?e.error.message:`Pick a table, namespace, bucket, or index from the tree.`})})})})]})})}export{Ip as StorePage};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$n as t,Br as n,Cr as r,Di as i,E as a,Er as o,F as s,Fr as c,Jr as l,L as u,Mr as d,Nr as f,Oi as p,P as m,Qi as h,Qn as g,Sr as _,Wi as v,Zn as y,_r as b,a as x,ar as S,bi as C,br as w,ca as T,cr as E,dr as D,er as O,gr as k,hi as A,hr as j,i as M,kr as N,l as P,li as F,lr as ee,mr as I,na as L,nr as R,o as te,or as z,qi as ne,ra as re,rr as ie,s as ae,sr as oe,ta as se,tr as ce,u as le,ur as ue,vr as de,wr as B,x as fe,xr as V,zi as pe}from"./shortcut-keys-DKxNTe_m.js";import{r as me}from"./react-dom-Bph1y7z7.js";import{A as he}from"./xyflow-D7n4g6go.js";import{t as ge}from"./link-BX6Vqztd.js";import{d as _e,r as ve,t as ye}from"./dropdown-menu-_NjTEo5_.js";import{$ as be,G as xe,Q as H,X as U,Y as W,a as Se,c as Ce,d as we,et as G,f as Te,h as Ee,i as De,n as Oe,nt as ke,o as Ae,p as je,r as Me,s as Ne,t as Pe,u as Fe,v as Ie}from"./tree-expand-toggle-BtyhmWb4.js";import{u as Le}from"./index-C8NRK2R-.js";import{a as Re,c as ze,i as K,n as Be,o as Ve,r as He,s as Ue,t as We}from"./element-icons-BVXtRyd3.js";import{t as Ge}from"./explorer-empty-2uIhBu0_.js";import{c as q,n as Ke,t as qe,u as Je}from"./detail-header-DhHM1iaZ.js";import{a as Ye,n as Xe,r as Ze,t as Qe}from"./http-method-_UHM2ODJ.js";import{a as $e,c as et,i as tt,s as nt,t as rt}from"./highlighted-json-Awq7gYdu.js";import{a as it,c as at,d as ot,f as st,l as ct,m as lt,o as ut,p as J,s as dt,t as ft,u as pt}from"./request-meta-DV0ywz7t.js";import{c as mt,n as ht,s as gt,t as _t}from"./cache-glyph-B5X-NM0-.js";import{i as vt,n as yt,r as bt,t as xt}from"./collapsible-DGnOM2ph.js";import{n as St,o as Ct,r as wt,t as Tt}from"./call-pii-button-ChAUiLo9.js";var Y=e(me(),1),X=he();function Et(e,t){let n=Ne(e.asGate);return n===`operator`?`Operator`:n===`public`?`Public`:e.asUserId?t.find(t=>t.id===e.asUserId)?.name??e.asUserId:e.asGate?`As · ${e.asGate}`:`As`}function Dt(e){let t=Ne(e.asGate);return t===`operator`||t===`public`||!!(e.asUserId||e.asGate)}function Ot({manifest:e,identities:t,value:n,onChange:i}){let a=xe(!0),o=(0,Y.useMemo)(()=>Ee(Ie(e),a.data??null),[e,a.data]),s=(0,Y.useMemo)(()=>Ce(o),[o]),c=(0,Y.useMemo)(()=>Fe(t,o),[t,o]),l=o.gates.find(e=>e.kind===`public`)?.description??`Intentionally unauthenticated.`,u=Ne(n.asGate),d=n.asGate!==null,[f,p]=(0,Y.useState)(n.asUserId?`user`:`policy`),m=s.find(e=>e.id===n.asGate)??null,h=c.find(e=>e.id===n.asUserId&&e.gate===n.asGate)??null,g=s.length>0||c.length>0,_=e=>{if(e===`operator`){i({asGate:null,asUserId:null});return}if(e===`public`){i({asGate:`public`,asUserId:null});return}if(u===`as`)return;let t=m?.id??s[0]?.id??c[0]?.gate??null;if(t!==null){if(c[0]&&t===c[0].gate&&s.length===0){p(`user`),i({asGate:c[0].gate,asUserId:c[0].id});return}p(`policy`),i({asGate:t,asUserId:null})}};return(0,X.jsxs)(ye,{children:[(0,X.jsx)(_e,{render:e=>(0,X.jsxs)(fe,{...e,type:`button`,variant:`ghost`,size:`sm`,className:r(`h-full max-w-44 min-w-0 rounded-none px-2 text-[11px]`,d&&`text-sky-800 dark:text-sky-300`),"aria-label":d?`Invoke as Gate ${n.asGate}`:`Invoke as Operator (bypass gates)`,"data-slot":`call-api-identity`,children:[(0,X.jsx)(B,{icon:We.gate.icon,"data-icon":`inline-start`,className:`size-3.5`}),(0,X.jsx)(`span`,{className:`truncate`,children:Et(n,t)})]})}),(0,X.jsxs)(ve,{align:`end`,className:`w-80 overflow-hidden p-0`,children:[(0,X.jsx)(Ae,{children:`Invoke as`}),(0,X.jsxs)(Se,{label:`Invoke as`,children:[(0,X.jsx)(Me,{mode:`operator`,title:`Operator`,caption:`Bypass`,selected:u===`operator`,onSelect:()=>_(`operator`)}),(0,X.jsx)(Me,{mode:`public`,title:`Public`,caption:`Anonymous`,selected:u===`public`,onSelect:()=>_(`public`)}),(0,X.jsx)(Me,{mode:`as`,title:`As`,caption:h?h.label:m?.label??`User / policy`,selected:u===`as`,disabled:!g,onSelect:()=>_(`as`)})]}),u===`operator`?(0,X.jsx)(De,{title:`Operator`,badge:`Default`,children:`Bypasses the flow's gate chain.`}):null,u===`public`?(0,X.jsxs)(De,{title:`Public`,children:[l,` Only `,(0,X.jsx)(`span`,{className:`font-mono`,children:`gate.public`}),` flows succeed.`]}):null,u===`as`?(0,X.jsx)(Oe,{tab:f,onTabChange:p,policies:s,users:c,asGate:n.asGate,asUserId:h?.id??null,onSelectPolicy:e=>{p(`policy`),i({asGate:e.id,asUserId:null})},onSelectUser:e=>{p(`user`),i({asGate:e.gate,asUserId:e.id})},hint:h?(0,X.jsxs)(`p`,{className:`border-t border-border/60 px-2 py-2 text-[10px] leading-relaxed text-muted-foreground`,children:[`Calls as `,(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:h.label}),` `,`via `,(0,X.jsx)(`span`,{className:`font-mono`,children:n.asGate}),`.`]}):m?(0,X.jsxs)(`p`,{className:`border-t border-border/60 px-2 py-2 text-[10px] leading-relaxed text-muted-foreground`,children:[m.detail,` Sets scopes for`,` `,(0,X.jsx)(`span`,{className:`font-mono`,children:m.id}),`.`]}):null}):null]})]})}var kt=new Set([`q`,`query`,`search`,`limit`,`offset`,`cursor`,`page`,`pageSize`,`perPage`,`per_page`,`page_size`,`order`,`orderBy`,`order_by`,`sort`,`sortBy`,`sort_by`,`direction`]);function At(e,t=[]){let n=new Set,r=[];for(let i of t){n.add(i);let t=e.find(e=>e.name===i);r.push(t??jt(i))}let i=[];for(let t of e)n.has(t.name)||(kt.has(t.name)?r.push(t):i.push(t));return{parameters:r,fields:i}}function jt(e){return{path:`/path/${e}`,name:e,type:`string`,required:!0}}function Mt(e,t={}){let n=t.pathParams??[],r=new Set(n);if(t.http!==!0)return{path:[],query:[],body:e};let i=e.filter(e=>!r.has(e.name));return Xe(t.method)?{path:n,query:[],body:i}:{path:n,query:i,body:[]}}function Nt(e,t){let n={};for(let r of t)Object.hasOwn(e,r.name)&&(n[r.name]=e[r.name]);return n}function Z(e,t=``){if(!e)return[];if(e.type===`object`||e.properties){let n=e.properties??{},r=new Set(Array.isArray(e.required)?e.required:[]);return Object.entries(n).map(([e,n])=>Pt(e,`${t}/${e}`,n,r.has(e)))}return[Pt(`value`,t||`/`,e,!0)]}function Pt(e,t,n,r){let i=Ft(e,n),a=typeof n.description==`string`?n.description:void 0;if(Array.isArray(n.enum)){let o=Ht(n);return{path:t,name:e,type:`enum`,required:r,enumValues:n.enum.map(String),...a===void 0?{}:{description:a},...o===void 0?{}:{valueMeanings:o},...i}}let o=n.type;if(o===`object`||n.properties)return{path:t,name:e,type:`object`,required:r,...a===void 0?{}:{description:a},...i,children:Z(n,t)};if(o===`array`)return{path:t,name:e,type:`array`,required:r,...a===void 0?{}:{description:a},...i,children:n.items?Z(n.items,`${t}/0`):void 0};let s=o===`integer`||o===`number`||o===`boolean`||o===`string`?o:`unknown`,c=Ht(n);return{path:t,name:e,type:s,required:r,minimum:typeof n.minimum==`number`?n.minimum:void 0,maximum:typeof n.maximum==`number`?n.maximum:void 0,...a===void 0?{}:{description:a},...c===void 0?{}:{valueMeanings:c},...i}}function Ft(e,t){let n=It(e),r=Lt(t.references),i=t.primaryKey===!0||n.primaryKey===!0,a=r!==void 0||n.foreignKey===!0,o=!i&&(t.unique===!0||n.unique===!0);return{...t.pii===!0?{pii:!0}:{},...t.sensitive===!0?{sensitive:!0}:{},...i?{primaryKey:!0}:{},...a?{foreignKey:!0}:{},...o?{unique:!0}:{},...r===void 0?{}:{references:r}}}function It(e){return e===`id`?{primaryKey:!0}:/(?:Id|_id)$/.test(e)||/(?:Key|_key)$/.test(e)&&e!==`key`?{foreignKey:!0}:e===`identifier`||e===`key`?{unique:!0}:{}}function Lt(e){if(!e||typeof e!=`object`)return;let t=`table`in e&&typeof e.table==`string`?e.table:void 0;if(!t)return;let n=`column`in e&&typeof e.column==`string`?e.column:void 0;return n===void 0?{table:t}:{table:t,column:n}}var Rt=12;function zt(e){return e.enumValues&&e.enumValues.length>0?e.enumValues.join(` · `):e.minimum!==void 0&&e.maximum!==void 0?`${e.minimum}–${e.maximum}`:e.minimum===void 0?e.maximum===void 0?null:`≤ ${e.maximum}`:`≥ ${e.minimum}`}function Bt(e){return e.minimum!==void 0&&e.maximum!==void 0?`Must be from ${e.minimum} up to ${e.maximum}.`:e.minimum===void 0?e.maximum===void 0?null:`Must be at most ${e.maximum}.`:`Must be at least ${e.minimum}.`}function Vt(e){return e.filter(e=>e.minimum!==void 0||e.maximum!==void 0||(e.enumValues?.length??0)>0||(e.valueMeanings?.length??0)>0)}function Ht(e){let t=Array.isArray(e.oneOf)?e.oneOf:Array.isArray(e.anyOf)?e.anyOf:null;if(t){let e=[];for(let n of t){if(!n||typeof n!=`object`)continue;let t=n;if(!(`const`in t))continue;let r=String(t.const),i=typeof t.title==`string`?t.title:typeof t.description==`string`?t.description:void 0;i&&e.push({value:r,label:i})}return e.length>0?e:void 0}}function Ut(e){if(e.type!==`integer`||e.minimum===void 0||e.maximum===void 0||!Number.isInteger(e.minimum)||!Number.isInteger(e.maximum))return null;let t=e.maximum-e.minimum;return t<0||t>Rt?null:Array.from({length:t+1},(t,n)=>e.minimum+n)}function Wt(e){return e?Gt(e):{}}function Gt(e){if(Array.isArray(e.enum)&&e.enum.length>0)return e.enum[0];let t=e.type;if(t===`object`||!t&&e.properties){let t=e.properties??{},n=new Set(Array.isArray(e.required)?e.required:[]),r={};for(let[e,i]of Object.entries(t))(n.has(e)||`default`in i||Object.keys(t).length<=4)&&(r[e]=Gt(i));return r}if(t===`array`){let t=e.items;return t?[Gt(t)]:[]}return t===`integer`||t===`number`?typeof e.default==`number`?e.default:typeof e.minimum==`number`?e.minimum:1:t===`boolean`?!1:t===`string`?e.format===`email`?`user@example.com`:e.format===`uuid`?`00000000-0000-4000-8000-000000000001`:typeof e.default==`string`?e.default:e.minLength?`x`.repeat(Number(e.minLength)):``:null}function Kt(e){return!e||typeof e==`string`?null:e}function qt(e,t){if(!e.foreignKey||!t)return null;let n=Zt(t);if(n.length===0)return null;if(e.references?.table){let t=Qt(n,e.references.table);return t?Yt(t,e.references.column??en(t.table)??`id`):null}let r=Xt(e.name);if(!r)return null;let i=$t(n,r.stem);return i?Yt(i,r.kind===`key`?tn(i.table,`key`)??en(i.table)??`id`:en(i.table)??`id`):null}function Jt(e,t){if(!t)return[];let n=new Set,r=[];for(let i of e){let e=i[t.column];if(e==null)continue;let a=String(e);if(n.has(a))continue;n.add(a);let o=t.labelColumn?i[t.labelColumn]:void 0,s=o!=null&&String(o)!==a?String(o):null;r.push({value:a,label:s?`${a} · ${s}`:a})}return r}function Yt(e,t){let n=nn(e.table,t);return{ref:e.ref,child:e.name,column:t,...n===void 0?{}:{labelColumn:n}}}function Xt(e){return e===`id`?null:e.endsWith(`Id`)?{stem:e.slice(0,-2),kind:`id`}:e.endsWith(`_id`)?{stem:e.slice(0,-3),kind:`id`}:e.endsWith(`Key`)?{stem:e.slice(0,-3),kind:`key`}:e.endsWith(`_key`)?{stem:e.slice(0,-4),kind:`key`}:null}function Zt(e){let t=[];for(let[n,r]of Object.entries(e.stores??{}))r.facet!==`sql`||!r.tables||t.push({ref:`sql:${n}`,tables:r.tables});return t}function Qt(e,t){let n=t.toLowerCase();for(let t of e)for(let[e,r]of Object.entries(t.tables))if(e.toLowerCase()===n)return{ref:t.ref,name:e,table:r};return null}function $t(e,t){let n=on(t),r=[t,n,an(t),an(n)].map(e=>e.toLowerCase());for(let t of e)for(let[e,n]of Object.entries(t.tables))if(r.includes(e.toLowerCase()))return{ref:t.ref,name:e,table:n};return null}function en(e){for(let[t,n]of Object.entries(e.columns??{}))if(rn(n)&&n.primaryKey===!0)return t;if(e.columns&&`id`in e.columns)return`id`}function tn(e,t){return e.columns&&t in e.columns?t:void 0}function nn(e,t){if(t!==`name`&&e.columns&&`name`in e.columns)return`name`}function rn(e){return`type`in e||`primaryKey`in e||`references`in e}function an(e){return e.endsWith(`y`)&&!/[aeiou]y$/i.test(e)?`${e.slice(0,-1)}ies`:/(?:s|x|z|ch|sh)$/i.test(e)?`${e}es`:`${e}s`}function on(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).replace(/([A-Z])([A-Z][a-z])/g,`$1_$2`).toLowerCase()}function sn(e){let t=[];for(let n of e.split(`/`))n.startsWith(`:`)&&n.length>1&&t.push(n.slice(1));return t}function cn(e){return`:${e}`}var ln={"attachments:id":`attachments/tsk_eng_12/spec.pdf`,"tasks:id":`tsk_eng_12`,"comments:id":`cmt_1`,"projects:id":`proj_api`,"spaces:id":`space_eng`,"tags:id":`tag_bug`,"tags:tagId":`tag_feature`,"goals:id":`goal_harbor`,"documents:id":`doc_prd_api`,"members:id":`mem_aria`,"forms:id":`form_customer`,"drafts:id":`ENG-12`,"views:id":`view_web_board`,"inbox:id":`inb_1`};function un(e,t){let n=e.split(`/`).filter(Boolean),r=`:${t}`,i=n.indexOf(r),a=i>0?n[i-1]:void 0;return(a?ln[`${a}:${t}`]:void 0)??ln[`:${t}`]}function dn(e,t){let n={};if(!e)return n;for(let r of t){let t=un(e,r);t&&(n[r]=t)}return n}function fn(e,t){let n=e?.flows?.[t],r=n?.trigger?.cron,i=n?.trigger?.every;if(!r&&!i)return{kind:`unmatched`};let a=e?.clocks??{},o=new Set;for(let[e,n]of Object.entries(a)){if(t===e||t.endsWith(`.${e}`)){o.add(e);continue}if(r&&n.cron===r){o.add(e);continue}i&&n.every===i&&o.add(e)}if(o.size!==1)return{kind:`unmatched`};let s=[...o][0],c=a[s];return{kind:`matched`,clockName:s,timezone:c.timezone??null,description:c.description??null,cron:c.cron??null,every:c.every??null}}function pn(e){let t=e.handlerMs!=null&&Number.isFinite(e.handlerMs)?e.handlerMs:null;return t===null?e.rttMs!==null&&Number.isFinite(e.rttMs)?{primaryMs:e.rttMs,primaryKind:`rtt`,rttMs:e.rttMs}:null:{primaryMs:t,primaryKind:`handler`,rttMs:e.rttMs}}function mn(e){let t=new Set;if(!e?.stores)return t;for(let n of Object.values(e.stores)){for(let e of Object.values(n.tables??{}))for(let[n,r]of Object.entries(e.columns??{}))r?.pii&&wt(t,n);for(let[e,r]of Object.entries(n.classifications??{}))if(r&&typeof r==`object`&&!Array.isArray(r)&&`pii`in r&&r.pii){let n=e.includes(`.`)?e.slice(e.lastIndexOf(`.`)+1):e;wt(t,n)}}return t}function hn(e,t,n=St){if(t.size===0||e==null)return e;if(Array.isArray(e))return e.map(e=>hn(e,t,n));if(typeof e==`object`){let r={};for(let[i,a]of Object.entries(e))r[i]=t.has(i)?n:hn(a,t,n);return r}return e}function gn(e){return e.failure==null?e.response!==void 0&&e.response!==null?JSON.stringify(e.response,null,2):JSON.stringify({status:e.status??200,failure:null,response:null},null,2):JSON.stringify({status:e.status??null,failure:e.failure,response:e.response??null},null,2)}function _n(e,t,n){return t&&e.masked===!1?gn({...e,response:hn(e.response,n),failure:e.failure===void 0?void 0:{...e.failure,data:hn(e.failure.data,n)},masked:!0}):gn(e)}function vn(e){let t=e.flow.effects;return!t||(t.writes?.length??0)===0&&(t.emits?.length??0)===0&&(t.sends?.length??0)===0&&(t.asks?.length??0)===0}function yn(e,t){return!t&&vn(e)}function bn(e,t){if(!e)return{ok:!0,errors:[],value:t};let n=[];return xn(e,t,``,n),{ok:n.length===0,errors:n,value:t}}function xn(e,t,n,r){let i=e.type;if(i===`object`||e.properties){if(typeof t!=`object`||!t||Array.isArray(t)){r.push({path:n||`/`,message:`must be object`});return}let i=t,a=e.properties??{},o=Array.isArray(e.required)?e.required:[];for(let e of o)(i[e]===void 0||i[e]===null||i[e]===``)&&r.push({path:`${n}/${e}`,message:`required`});for(let[e,t]of Object.entries(a))i[e]!==void 0&&xn(t,i[e],`${n}/${e}`,r);return}if(Array.isArray(e.enum)){e.enum.map(String).includes(String(t))||r.push({path:n||`/`,message:`invalid enum`});return}i===`string`&&typeof t!=`string`?r.push({path:n||`/`,message:`must be string`}):i===`integer`?typeof t!=`number`||!Number.isInteger(t)?r.push({path:n||`/`,message:`must be integer`}):Sn(e,t,n,r):i===`number`?typeof t!=`number`||Number.isNaN(t)?r.push({path:n||`/`,message:`must be number`}):Sn(e,t,n,r):i===`boolean`&&typeof t!=`boolean`&&r.push({path:n||`/`,message:`must be boolean`})}function Sn(e,t,n,r){let i=typeof e.minimum==`number`?e.minimum:void 0,a=typeof e.maximum==`number`?e.maximum:void 0;i!==void 0&&t<i&&r.push({path:n||`/`,message:`must be ≥ ${i}`}),a!==void 0&&t>a&&r.push({path:n||`/`,message:`must be ≤ ${a}`})}function Cn(e){return JSON.stringify(e,null,2)}function wn({row:e,manifest:t}){let n=J(e.flow.trigger);return n===`cron`||n===`every`?(0,X.jsx)(Tn,{row:e,manifest:t}):(0,X.jsx)(En,{row:e,kind:n,manifest:t})}function Tn({row:e,manifest:t}){let n=(0,Y.useMemo)(()=>fn(t,e.id),[t,e.id]),r=we(),i=Te(),a=je(),[o,s]=(0,Y.useState)({asGate:null,asUserId:null}),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{r.reset(),a.reset(),d(null),l(null)},[e.id]);let f=n.kind===`matched`;async function m(){if(l(performance.now()),f){d(`clock`);try{await r.mutateAsync({name:n.clockName})}catch{}return}if(Dt(o)){d(`invoke`);try{await a.mutateAsync({flowId:e.id,body:{},...o.asUserId?{asUserId:o.asUserId}:{},...o.asGate?{asGate:o.asGate}:{}})}catch{}}}let h=f?r.isPending:a.isPending,g=f?r.isError:a.isError||a.isSuccess&&a.data?.failure!=null,_=f?r.isSuccess:a.isSuccess&&!a.data?.failure,v=c!==null&&(_||g)?performance.now()-c:null,y=(0,Y.useMemo)(()=>f&&r.data?JSON.stringify(r.data,null,2):!f&&a.data?gn(a.data):null,[f,r.data,a.data]),b=f?`Run now`:`Run handler`,x=f?`Run now`:`Run handler once`;return(0,X.jsx)(An,{title:b,dataMode:f?`clock`:`invoke-fallback`,actions:(0,X.jsxs)(X.Fragment,{children:[f?null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ot,{manifest:t,identities:i.data??[],value:o,onChange:s}),(0,X.jsx)(Fn,{})]}),(0,X.jsx)(fe,{type:`button`,"data-slot":`call-api-submit`,disabled:h||!f&&!Dt(o),onClick:()=>void m(),className:Pn,children:h?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{icon:p,className:`animate-spin`,"data-icon":`inline-start`}),`Running…`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{icon:pe,"data-icon":`inline-start`}),x]})})]}),children:(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[f?(0,X.jsxs)(`p`,{className:`px-3 pt-2.5 pb-2 text-[11px] leading-snug text-muted-foreground`,"data-slot":`clock-path-copy`,children:[`Fires Manifest clock`,` `,(0,X.jsx)(`code`,{className:`rounded bg-muted/50 px-1 py-px font-mono text-[10px]`,children:n.clockName}),` `,`via`,` `,(0,X.jsx)(`code`,{className:`rounded bg-muted/50 px-1 py-px font-mono text-[10px]`,children:`/console/clock/run-now`}),` `,`(lease-gated — the real scheduler path).`,n.timezone?(0,X.jsxs)(X.Fragment,{children:[` `,`Timezone · `,(0,X.jsx)(`span`,{className:`font-mono`,children:n.timezone}),`.`]}):null]}):(0,X.jsxs)(`div`,{className:`mx-3 mt-2.5 rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-[11px] leading-snug text-foreground/90`,"data-slot":`invoke-fallback-copy`,role:`note`,children:[`No unique Manifest clock matches this flow's schedule.`,` `,(0,X.jsx)(`strong`,{className:`font-medium`,children:`Run handler once`}),` uses`,` `,(0,X.jsx)(`code`,{className:`rounded bg-muted/50 px-1 py-px font-mono text-[10px]`,children:`/console/flows/invoke`}),` `,`with empty input — it does `,(0,X.jsx)(`em`,{children:`not`}),` exercise the Clock lease / scheduler path.`]}),(0,X.jsx)(Dn,{failed:!!g,success:!!_,elapsed:v,handlerMs:f?null:a.data?.durationMs,statusCode:f?r.data?.ran?200:409:a.data?.status,errorMessage:f?r.isError?r.error.message:null:a.isError?a.error.message:null,responseJson:y,emptyHint:f?`Run now to fire the real clock tick.`:`Run handler once to invoke with empty input.`,pathUsed:u,cache:f?void 0:a.data?.cache})]})})}function En({row:e,kind:t,manifest:n}){let i=Te(),o=je(),l=Kt(e.flow.in),d=(0,Y.useMemo)(()=>Z(l),[l]),f=(0,Y.useMemo)(()=>t===`http`&&e.path?sn(e.path):[],[t,e.path]),h=(0,Y.useMemo)(()=>Mt(d,{http:t===`http`,method:e.method,pathParams:f}),[d,t,e.method,f]),g=t!==`http`||Xe(e.method),[_,v]=(0,Y.useState)({asGate:null,asUserId:null}),[y,b]=(0,Y.useState)(!0),[x,S]=(0,Y.useState)(()=>dn(e.path,f)),C=(0,Y.useMemo)(()=>Wt(l)??{},[l]),w=(0,Y.useMemo)(()=>Nt(C,h.query),[C,h.query]),T=(0,Y.useMemo)(()=>Nt(C,h.body),[C,h.body]),[E,D]=(0,Y.useState)(w),[O,k]=(0,Y.useState)(T),[A,j]=(0,Y.useState)(`fields`),[M,N]=(0,Y.useState)(()=>Cn(T)),[P,F]=(0,Y.useState)(null),[ee,I]=(0,Y.useState)([]),[L,R]=(0,Y.useState)(null),[te,z]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{D(w),k(T),N(Cn(T)),F(null),j(`fields`),S(dn(e.path,f)),I([]),z(null),R(null),o.reset()},[e.id]);function ne(e){try{let t=JSON.parse(e);return typeof t!=`object`||!t||Array.isArray(t)?(F(`Body must be a JSON object.`),!1):(k(t),F(null),!0)}catch(e){return F(e instanceof Error?e.message:`Invalid JSON.`),!1}}function re(e){if(e!==A){if(e===`raw`){N(Cn(O)),F(null),j(`raw`);return}ne(M)&&j(`fields`)}}async function ie(t=!y){let n=g?O:{};if(g&&A===`raw`){if(!ne(M))return;try{n=JSON.parse(M)}catch{return}}let r={...E,...n},i=bn(l,{...x,...r});if(!i.ok){I(i.errors);return}if(I([]),Dt(_)){R(performance.now());try{await o.mutateAsync({flowId:e.id,body:r,..._.asUserId?{asUserId:_.asUserId}:{},..._.asGate?{asGate:_.asGate}:{},...f.length>0?{pathParams:x}:{},...t?{revealPii:!0}:{}})}catch{}}}function ae(){D(w),k(T),N(Cn(T)),F(null),S(dn(e.path,f)),I([])}(0,Y.useEffect)(()=>{L===null||o.isPending||(o.isSuccess||o.isError)&&z(performance.now()-L)},[o.isSuccess,o.isError,o.isPending,L]);let oe=(0,Y.useMemo)(()=>o.data?_n(o.data,y,mn(n)):null,[o.data,y,n]),se=o.data?.failure!=null,ce=o.data?.status,le=t===`http`?`Call API`:t===`signal`?`Run handler`:`Invoke`,ue=le;return(0,X.jsx)(An,{title:le,dataTrigger:t,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ot,{manifest:n,identities:i.data??[],value:_,onChange:v}),(0,X.jsx)(Tt,{piiMasked:y,disabled:o.isPending,onToggle:()=>{let t=!y;b(t),o.data&&!o.isPending&&yn(e,t)&&ie(!0)}}),g?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Fn,{}),(0,X.jsx)(jn,{view:A,onChange:re})]}):null,(0,X.jsx)(Fn,{}),(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:e=>(0,X.jsxs)(fe,{...e,type:`button`,variant:`ghost`,"data-slot":`call-api-reset`,disabled:o.isPending,onClick:ae,className:Nn,children:[(0,X.jsx)(B,{icon:c,"data-icon":`inline-start`}),`Reset`]})}),(0,X.jsx)(s,{side:`bottom`,className:`text-[11px]`,children:g?`Reset body to the schema example`:`Reset to schema examples`})]}),(0,X.jsx)(Fn,{}),(0,X.jsx)(fe,{type:`button`,"data-slot":`call-api-submit`,disabled:o.isPending||!Dt(_),onClick:()=>void ie(),className:Pn,children:o.isPending?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{icon:p,className:`animate-spin`,"data-icon":`inline-start`}),`Calling…`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{icon:pe,"data-icon":`inline-start`}),ue]})})]}),children:(0,X.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`min-h-0 min-w-0 shrink overflow-y-auto`,children:[t===`http`?(0,X.jsxs)(`p`,{className:`px-3 pt-2.5 pb-2 text-[11px] leading-snug text-muted-foreground`,children:[`Operator session · invoke-as`,` `,(0,X.jsx)(`code`,{className:`rounded bg-muted/50 px-1 py-px font-mono text-[10px]`,children:`console:flows:invoke-as`})]}):null,t===`signal`?(0,X.jsxs)(`div`,{className:`mx-3 mt-2.5 rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-[11px] leading-snug text-foreground/90`,"data-slot":`signal-honest-copy`,role:`note`,children:[(0,X.jsx)(`strong`,{className:`font-medium`,children:`Run handler directly`}),` — invokes the flow with your payload via`,` `,(0,X.jsx)(`code`,{className:`rounded bg-muted/50 px-1 py-px font-mono text-[10px]`,children:`/console/flows/invoke`}),`. It does `,(0,X.jsx)(`em`,{children:`not`}),` publish on the signal bus, so it does not test delivery physics (once / broadcast / live, retries, dead-letter).`]}):null,t===`internal`?(0,X.jsxs)(`div`,{className:`mx-3 mt-2.5 rounded-md border border-border/60 bg-muted/20 px-3 py-2 text-[11px] leading-snug text-muted-foreground`,"data-slot":`call-only-bypass-copy`,role:`note`,children:[`This flow has no external trigger. Invoking here bypasses its normal caller (`,(0,X.jsx)(`code`,{className:`font-mono text-[10px]`,children:`fx.call`}),` /`,` `,(0,X.jsx)(`code`,{className:`font-mono text-[10px]`,children:`effects.calls`}),`). The body still matches `,(0,X.jsx)(`code`,{className:`font-mono text-[10px]`,children:`flow.in`}),`.`]}):null,t===`cdc`?(0,X.jsx)(`p`,{className:`px-3 pt-2.5 pb-2 text-[11px] leading-snug text-muted-foreground`,children:`Direct handler invoke — not a Store CDC event.`}):null,f.length>0?(0,X.jsxs)(`section`,{className:`min-w-0`,"aria-label":`Path params`,"data-slot":`call-api-path`,children:[(0,X.jsx)(Ln,{title:`Path params`,hint:e.path??void 0}),f.map(e=>(0,X.jsx)(q,{label:e,className:`[&>span]:px-3`,children:(0,X.jsx)(a,{id:`path-${e}`,flat:!0,className:r(Ke,`px-3 font-mono`),placeholder:cn(e),value:x[e]??``,onChange:t=>S(n=>({...n,[e]:t.target.value}))})},e))]}):null,h.query.length>0?(0,X.jsxs)(`section`,{className:`min-w-0`,"aria-label":`Query params`,"data-slot":`call-api-query`,children:[(0,X.jsx)(Ln,{title:`Query params`,hint:`seeded from schema`}),(0,X.jsx)(Je,{children:h.query.map(e=>(0,X.jsx)(Rn,{field:e,idPrefix:`query`,value:E[e.name],onChange:t=>D(n=>({...n,[e.name]:t})),error:ee.find(t=>t.path===`/${e.name}`||t.path===e.path),wide:e.type===`object`||e.type===`array`,manifest:n},e.path))})]}):null,g?(0,X.jsxs)(`section`,{className:`min-w-0`,"aria-label":`Body`,"data-slot":`call-api-body`,children:[(0,X.jsx)(Ln,{title:`Body`,hint:A===`raw`?`raw JSON`:`seeded from schema`}),A===`raw`?(0,X.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,X.jsx)(`textarea`,{"data-slot":`call-api-body-raw`,"aria-label":`Raw JSON body`,spellCheck:!1,value:M,onChange:e=>{N(e.target.value),P&&F(null)},className:r(`min-h-40 w-full resize-y rounded-none border-0 bg-transparent px-3 py-2 font-mono text-xs leading-relaxed text-foreground outline-none`,`placeholder:text-muted-foreground focus-visible:bg-muted/20`,P&&`text-destructive`)}),P?(0,X.jsx)(`p`,{role:`alert`,className:`px-3 pb-2 text-xs text-destructive`,"data-slot":`call-api-raw-error`,children:P}):null]}):h.body.length===0?(0,X.jsx)(`p`,{className:`border-b border-border/50 px-3 py-2 text-xs text-muted-foreground`,children:`No body fields (empty object).`}):(0,X.jsx)(Je,{children:h.body.map(e=>(0,X.jsx)(Rn,{field:e,value:O[e.name],onChange:t=>k(n=>({...n,[e.name]:t})),error:ee.find(t=>t.path===`/${e.name}`||t.path===e.path),wide:e.type===`object`||e.type===`array`,manifest:n},e.path))})]}):null,ee.length>0?(0,X.jsx)(`p`,{role:`alert`,className:`px-3 py-2 text-xs text-destructive`,"data-slot":`call-api-validation`,children:`Fix contract errors before sending.`}):null]}),(0,X.jsx)(Dn,{failed:!!se,success:!!o.data&&!se,elapsed:te,handlerMs:o.data?.durationMs,statusCode:ce,errorMessage:o.isError?o.error.message:null,responseJson:oe,emptyHint:`Call to see a real host response.`,pathUsed:null,cache:o.data?.cache})]})})}function Dn({failed:e,success:t,elapsed:i,handlerMs:a,statusCode:o,errorMessage:s,responseJson:c,emptyHint:l,pathUsed:u,cache:d}){let[p,m]=(0,Y.useState)(!1),h=(0,X.jsx)(kn,{failed:e,success:t,elapsed:i,handlerMs:a,statusCode:o,pathUsed:u,cache:d});return(0,X.jsxs)(`section`,{className:`flex min-h-56 min-w-0 flex-1 flex-col overflow-hidden`,"aria-label":`Response`,"data-slot":`call-api-response-block`,children:[(0,X.jsxs)(`div`,{className:j,children:[(0,X.jsx)(`h4`,{className:r(V,`flex items-center px-2`),children:`Response`}),(0,X.jsxs)(`div`,{className:`ml-auto flex h-full items-stretch`,children:[h,c?(0,X.jsx)(Ue,{label:`Expand response`,className:`flex self-stretch`,children:(0,X.jsx)(`button`,{type:`button`,"aria-label":`Expand response`,"data-slot":`call-api-response-expand`,className:S,onClick:()=>m(!0),children:(0,X.jsx)(B,{icon:f,className:`size-3.5`,"aria-hidden":!0})})}):null]})]}),s?(0,X.jsx)(`p`,{role:`alert`,className:`px-2 py-2 text-sm text-destructive`,"data-slot":`call-api-error`,children:s}):null,c?(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 overflow-hidden`,"data-slot":`call-api-response-frame`,children:[(0,X.jsx)(`div`,{className:r(`w-1 shrink-0 self-stretch`,e?`bg-destructive`:`bg-emerald-500`),"aria-hidden":!0,"data-slot":`call-api-response-rail`}),(0,X.jsx)(rt,{json:c,dataSlot:`call-api-response`,className:`flex min-h-0 flex-1 overflow-auto`})]}):(0,X.jsx)(`p`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:l}),c?(0,X.jsx)(M,{open:p,onOpenChange:m,children:(0,X.jsxs)(te,{side:`right`,showCloseButton:!1,className:`gap-0 p-0 data-[side=right]:w-[min(48rem,calc(100vw-2rem))] data-[side=right]:sm:max-w-[min(48rem,calc(100vw-2rem))]`,"data-slot":`call-api-response-dialog`,children:[(0,X.jsxs)(P,{className:r(j,`flex-row gap-0 border-border/60 p-0`),children:[(0,X.jsx)(le,{className:r(V,`flex items-center px-2`),children:`Response`}),(0,X.jsx)(ae,{className:`sr-only`,children:`Full Call API response JSON`}),(0,X.jsxs)(`div`,{className:`ml-auto flex h-full items-stretch`,children:[h,(0,X.jsx)(On,{json:c}),(0,X.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,X.jsxs)(x,{"aria-label":`Close`,className:S,"data-slot":`call-api-response-close`,children:[(0,X.jsx)(B,{icon:n,className:`size-3.5`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,X.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,X.jsx)(`div`,{className:r(`w-1 shrink-0 self-stretch`,e?`bg-destructive`:`bg-emerald-500`),"aria-hidden":!0}),(0,X.jsx)(rt,{json:c,dataSlot:`call-api-response-expanded`,className:`flex min-h-0 flex-1 overflow-auto`})]})})]})}):null]})}function On({json:e}){let[t,n]=(0,Y.useState)(!1);return(0,X.jsx)(Ue,{label:t?`Copied`:`Copy response`,className:`flex self-stretch`,children:(0,X.jsx)(`button`,{type:`button`,"aria-label":t?`Copied`:`Copy response`,"data-slot":`call-api-response-copy`,className:S,onClick:()=>{navigator.clipboard&&navigator.clipboard.writeText(e).then(()=>{n(!0),window.setTimeout(()=>n(!1),1200)})},children:(0,X.jsx)(B,{icon:t?L:l,className:`size-3.5`,"aria-hidden":!0})})})}function kn({failed:e,success:t,elapsed:n,handlerMs:i,statusCode:a,pathUsed:o,cache:c}){let l=t||e,d=l?pn({handlerMs:i,rttMs:n}):null;return(0,X.jsxs)(X.Fragment,{children:[o?(0,X.jsxs)(`span`,{className:`flex h-full items-center px-2 font-mono text-[10px] text-muted-foreground`,"data-slot":`call-api-path-used`,"data-path":o,children:[`via `,o===`clock`?`clock.run-now`:`flows.invoke`]}):null,l?(0,X.jsxs)(`span`,{className:r(`inline-flex h-full items-center gap-1 px-2 font-mono text-[10px] font-semibold`,e?`text-destructive`:`text-emerald-700 dark:text-emerald-400`),"data-slot":`call-api-status`,"data-failed":e?`true`:`false`,children:[(0,X.jsx)(B,{icon:e?N:L,className:`size-3`,"aria-hidden":!0}),a??(e?`error`:`ok`)]}):null,l?(0,X.jsx)(`span`,{className:`flex h-full items-center px-2`,children:(0,X.jsx)(_t,{cache:c??`none`,dataSlot:`call-api-cache`})}):null,d?(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:e=>(0,X.jsx)(`span`,{...e,className:`flex h-full items-center px-2 font-mono text-[10px] tabular-nums text-muted-foreground`,"data-slot":`call-api-duration`,"data-kind":d.primaryKind,children:tt(d.primaryMs)})}),(0,X.jsx)(s,{side:`bottom`,className:`max-w-xs text-[11px]`,children:d.primaryKind===`handler`?`Handler time — same clock as Traces.`:`Browser round-trip. Handler time is on the Traces row.`})]}):null,d?.primaryKind===`handler`&&d.rttMs!==null?(0,X.jsxs)(`span`,{className:`flex h-full items-center px-2 font-mono text-[10px] tabular-nums text-muted-foreground/70`,"data-slot":`call-api-rtt`,title:`Browser round-trip`,children:[tt(d.rttMs),` rtt`]}):null]})}function An({title:e,actions:t,children:n,dataTrigger:i,dataMode:a}){return(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`call-api-panel`,"data-trigger":i,"data-mode":a,children:[(0,X.jsxs)(`div`,{className:r(w,`min-w-0`),children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 px-2`,children:[(0,X.jsx)(B,{icon:pe,className:`size-3.5 text-muted-foreground`,"aria-hidden":!0}),(0,X.jsx)(`h3`,{className:r(V,`text-foreground`),children:e})]}),(0,X.jsx)(`div`,{className:`ml-auto flex h-full min-w-0 items-stretch`,children:t})]}),(0,X.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:n})]})}function jn({view:e,onChange:t}){return(0,X.jsxs)(`div`,{className:`flex h-full shrink-0 items-stretch`,role:`group`,"aria-label":`Body view`,"data-slot":`call-api-body-view-toggle`,children:[(0,X.jsx)(Mn,{active:e===`fields`,label:`Fields`,icon:i,onClick:()=>t(`fields`)}),(0,X.jsx)(Mn,{active:e===`raw`,label:`Raw`,icon:h,onClick:()=>t(`raw`)})]})}function Mn({active:e,label:t,icon:n,onClick:i}){return(0,X.jsxs)(`button`,{type:`button`,className:r(b,`font-semibold tracking-[0.08em] uppercase`,e?k:de),"aria-pressed":e,"aria-label":t,onClick:i,children:[(0,X.jsx)(B,{icon:n,className:`size-3`}),(0,X.jsx)(`span`,{className:`hidden sm:inline`,children:t})]})}var Nn=`h-full rounded-none border-0 bg-transparent px-2 text-[10px] font-semibold tracking-[0.08em] uppercase shadow-none hover:bg-muted/50`,Pn=`h-full rounded-none border-0 px-3 text-[10px] font-semibold tracking-[0.14em] uppercase shadow-none`;function Fn(){return(0,X.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0})}var In=`h-7 w-full justify-between rounded-none border-0 bg-transparent px-2 shadow-none focus-visible:border-0 focus-visible:ring-0 dark:bg-transparent dark:hover:bg-transparent`;function Ln({title:e,hint:t}){return(0,X.jsxs)(`div`,{className:j,children:[(0,X.jsx)(`h4`,{className:r(V,`flex items-center px-2`),children:e}),t?(0,X.jsx)(`span`,{className:`ml-auto flex items-center px-2 text-[10px] text-muted-foreground`,children:t}):null]})}function Rn({field:e,value:t,onChange:n,error:i,wide:o=!1,manifest:s,idPrefix:c=`body`}){let l=`${c}-${e.name}`,u=zn(e,s),d=[e.required?null:`optional`,u.lookup?`fk · ${u.lookup.child}.${u.lookup.column}`:e.type,u.lookup?null:zt(e)].filter(Boolean).join(` · `),f=i?(0,X.jsx)(`p`,{className:`px-3 pb-2 text-xs text-destructive`,children:i.message}):null,p=r(o&&`col-span-full border-r-0`);if(u.lookup){let r=t==null||t===``?``:String(t),i=Bn(u.options,r);return(0,X.jsxs)(q,{label:e.name,hint:d,dense:!0,className:p,children:[(0,X.jsxs)(W,{value:r||null,onValueChange:e=>{e==null||Array.isArray(e)||n(String(e))},children:[(0,X.jsx)(be,{id:l,className:In,disabled:u.isLoading,children:(0,X.jsx)(G,{placeholder:u.isLoading?`Loading…`:`Select…`})}),(0,X.jsx)(U,{children:i.map(e=>(0,X.jsx)(H,{value:e.value,children:e.label},e.value))})]}),f]})}if(e.type===`enum`&&e.enumValues)return(0,X.jsxs)(q,{label:e.name,hint:d,dense:!0,className:p,children:[(0,X.jsxs)(W,{value:String(t??``),onValueChange:e=>{e==null||Array.isArray(e)||n(String(e))},children:[(0,X.jsx)(be,{id:l,className:In,children:(0,X.jsx)(G,{})}),(0,X.jsx)(U,{children:e.enumValues.map(e=>(0,X.jsx)(H,{value:e,children:e},e))})]}),f]});if(e.type===`boolean`)return(0,X.jsx)(q,{label:e.name,hint:d,dense:!0,className:p,children:(0,X.jsxs)(W,{value:t===!0?`true`:`false`,onValueChange:e=>{e==null||Array.isArray(e)||n(String(e)===`true`)},children:[(0,X.jsx)(be,{id:l,className:In,children:(0,X.jsx)(G,{})}),(0,X.jsxs)(U,{children:[(0,X.jsx)(H,{value:`true`,children:`true`}),(0,X.jsx)(H,{value:`false`,children:`false`})]})]})});if(e.type===`integer`||e.type===`number`){let i=Ut(e);if(i){let r=typeof t==`number`?String(t):``;return(0,X.jsxs)(q,{label:e.name,hint:d,dense:!0,className:p,children:[(0,X.jsxs)(W,{value:r||null,onValueChange:e=>{e==null||Array.isArray(e)||n(Number(e))},children:[(0,X.jsx)(be,{id:l,className:In,children:(0,X.jsx)(G,{placeholder:`Select…`})}),(0,X.jsx)(U,{children:i.map(t=>{let n=e.valueMeanings?.find(e=>e.value===String(t));return(0,X.jsx)(H,{value:String(t),children:n?`${t} · ${n.label}`:t},t)})})]}),f]})}return(0,X.jsxs)(q,{label:e.name,hint:d,dense:!0,className:p,children:[(0,X.jsx)(a,{id:l,type:`number`,flat:!0,className:r(Ke,`h-7 px-2 font-mono`),min:e.minimum,max:e.maximum,step:e.type===`integer`?1:void 0,value:typeof t==`number`?t:``,onChange:t=>{if(t.target.value===``){n(void 0);return}n(Vn(Number(t.target.value),e.minimum,e.maximum))}}),f]})}return(0,X.jsxs)(q,{label:e.name,hint:d,dense:!0,className:p,children:[(0,X.jsx)(a,{id:l,flat:!0,className:r(Ke,`h-7 px-2 font-mono`),value:typeof t==`string`?t:t==null?``:String(t),onChange:e=>n(e.target.value)}),f]})}function zn(e,t){let n=(0,Y.useMemo)(()=>qt(e,t),[e,t]),r=ke(n?{ref:n.ref,child:n.child,limit:200}:null,n!==null);return{lookup:n,options:(0,Y.useMemo)(()=>Jt(r.data?.rows??[],n),[r.data?.rows,n]),isLoading:r.isFetching}}function Bn(e,t){return!t||e.some(e=>e.value===t)?e:[{value:t,label:t},...e]}function Vn(e,t,n){let r=e;return t!==void 0&&r<t&&(r=t),n!==void 0&&r>n&&(r=n),r}function Q({title:e,meta:t,ruled:n=!0}){return(0,X.jsxs)(`div`,{className:r(`flex items-baseline justify-between gap-2`,n&&`border-b border-border/60 pb-1.5`),children:[(0,X.jsx)(`h3`,{className:V,children:e}),t?(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:t}):null]})}function Hn({method:e,className:t}){return(0,X.jsx)(vt,{variant:`outline`,className:r(`h-5 px-1.5 font-mono text-[10px] uppercase`,Qe(e),t),"data-slot":`http-method-badge`,children:e})}var Un=[`once`,`broadcast`,`live`],Wn={once:{delivery:`once`,icon:se,label:`once`,title:`once — one consumer claims; retries + DLQ`,wellClass:`border-amber-500/35 bg-amber-500/10 text-amber-700 dark:text-amber-400`,badgeClass:`border-amber-500/35 bg-amber-500/15 text-amber-800 dark:text-amber-400`},broadcast:{delivery:`broadcast`,icon:ne,label:`broadcast`,title:`broadcast — every subscriber gets a copy`,wellClass:`border-sky-500/35 bg-sky-500/10 text-sky-700 dark:text-sky-400`,badgeClass:`border-sky-500/35 bg-sky-500/15 text-sky-700 dark:text-sky-400`},live:{delivery:`live`,icon:o,label:`live`,title:`live — retained feed; late subscribers replay history`,wellClass:`border-emerald-500/35 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,badgeClass:`border-emerald-500/35 bg-emerald-500/15 text-emerald-700 dark:text-emerald-400`}};function Gn({delivery:e,className:t}){let n=Wn[e];return(0,X.jsx)(vt,{variant:`outline`,title:n.title,className:r(`h-5 px-1.5 font-mono text-[10px]`,n.badgeClass,t),"data-slot":`signal-delivery-badge`,"data-delivery":e,children:n.label})}function Kn({effects:e}){let t=qn(e);return t.length===0?null:(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"data-slot":`effects-summary`,"aria-label":`Effects`,children:[(0,X.jsx)(Q,{title:`Effects`,meta:String(t.length)}),(0,X.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>{let t=dt(e.kind),n=at(e.kind,e.ref),r=e.kind===`call`?it(e.ref):null;return(0,X.jsxs)(`li`,{className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px]`,style:{borderColor:`${t}55`,color:t},title:r??`${ut[e.kind]} ${e.ref}`,children:[(0,X.jsx)(B,{icon:n,className:`size-3`}),r?(0,X.jsx)(`span`,{className:`text-foreground/90`,children:r}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:ut[e.kind]}),(0,X.jsx)(`span`,{className:`text-foreground/90`,children:e.ref})]})]},`${e.kind}:${e.ref}`)})})]})}function qn(e){if(!e)return[];let t=[],n=(e,n)=>{for(let r of n??[]){let n=typeof r==`string`?r:r.ref??String(r);t.push({kind:e,ref:n})}};return n(`read`,e.reads),n(`write`,e.writes),n(`emit`,e.emits),n(`send`,e.sends),n(`ask`,e.asks),n(`secret`,e.secrets),n(`call`,e.calls),t}function Jn({errors:e}){let t=Yn(e);return t.length===0?null:(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"data-slot":`errors-section`,"aria-label":`Flow errors`,children:[(0,X.jsx)(Q,{title:`Flow errors`,meta:String(t.length)}),(0,X.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>{let t=(e.schema?Z(e.schema):[]).map(e=>e.name).join(`, `);return(0,X.jsxs)(`li`,{className:`inline-flex items-center gap-1 rounded-md border border-destructive/25 bg-destructive/[0.04] px-1.5 py-0.5 font-mono text-[10px] text-destructive`,title:t?`{ code, data: { ${t} } }`:`Typed error — { code, data }`,"data-slot":`error-code`,"data-code":e.code,children:[(0,X.jsx)(B,{icon:N,className:`size-3`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`text-foreground/90`,children:e.code}),t?(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:t}):null]},e.code)})})]})}function Yn(e){return e?Array.isArray(e)?e.map(e=>({code:e,schema:null})):Object.entries(e).map(([e,t])=>({code:e,schema:Kt(t)})):[]}var Xn=36e5;function Zn(e,t,n,r=Xn){let i=ht(e,new Set([t])),a=n-r,o=i.filter(e=>e.startedAt>=a);if(o.length===0)return{kind:`empty`};let s=o.filter(e=>e.error!=null&&e.error.length>0).length,c=o[0];return{kind:`summary`,calls:o.length,errors:s,errorRate:s/o.length,lastStartedAt:c.startedAt,latestRunId:c.id,windowMs:r}}function Qn({flowId:e,runs:t,nowMs:n=Date.now(),windowMs:i=Xn,children:a}){let o=Zn(t??[],e,n,i);return(0,X.jsxs)(`div`,{className:r(j,`px-2`),"data-slot":`flow-activity-strip`,"data-kind":o.kind,"aria-label":`Recent activity`,children:[(0,X.jsx)(`span`,{className:r(V,`flex items-center`),children:`Activity`}),(0,X.jsx)($n,{summary:o,nowMs:n}),a?(0,X.jsx)(`div`,{className:`ml-auto flex h-full items-stretch`,children:a}):null]})}function $n({summary:e,nowMs:t}){if(e.kind===`empty`)return(0,X.jsx)(`p`,{className:`flex items-center text-[11px] text-muted-foreground`,"data-slot":`flow-activity-empty`,children:`No recent runs in the Console buffer.`});let n=Math.round(e.errorRate*100),i=er(e.lastStartedAt,t);return(0,X.jsxs)(`p`,{className:`flex min-w-0 items-center gap-x-2 text-[11px] text-foreground/85`,children:[(0,X.jsxs)(`span`,{className:`tabular-nums`,"data-slot":`flow-activity-calls`,children:[e.calls,` call`,e.calls===1?``:`s`]}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,"aria-hidden":!0,children:`·`}),(0,X.jsxs)(`span`,{className:`tabular-nums`,"data-slot":`flow-activity-errors`,children:[n,`% errors`]}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,"aria-hidden":!0,children:`·`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,"data-slot":`flow-activity-ago`,children:i}),(0,X.jsx)(ge,{to:`/overview`,search:{run:e.latestRunId},className:r(b,de),"data-slot":`flow-activity-open-run`,children:`Open latest`})]})}function er(e,t){let n=Math.max(0,t-e);return n<6e4?`${Math.max(1,Math.round(n/1e3))}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function tr(e){switch(e){case`string`:return`border-teal-500/35 bg-teal-500/10 text-teal-800 dark:text-teal-300`;case`integer`:return`border-blue-500/35 bg-blue-500/10 text-blue-800 dark:text-blue-300`;case`number`:return`border-amber-500/35 bg-amber-500/10 text-amber-800 dark:text-amber-300`;case`boolean`:return`border-violet-500/35 bg-violet-500/10 text-violet-800 dark:text-violet-300`;case`enum`:return`border-indigo-500/35 bg-indigo-500/10 text-indigo-800 dark:text-indigo-300`;case`array`:return`border-cyan-500/35 bg-cyan-500/10 text-cyan-800 dark:text-cyan-300`;case`object`:return`border-zinc-500/35 bg-zinc-500/10 text-zinc-700 dark:text-zinc-300`;default:return`border-border/70 bg-muted/40 text-muted-foreground`}}function nr({fields:e,emptyLabel:t=`No schema fields declared.`,layout:n=`list`}){return e.length===0?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-slot":`schema-fields-empty`,children:t}):n===`grid`?(0,X.jsx)(`div`,{"data-slot":`schema-fields`,"data-layout":`grid`,children:(0,X.jsx)(Je,{columns:3,children:e.map(e=>(0,X.jsx)(rr,{field:e,depth:0,cell:!0},e.path))})}):(0,X.jsx)(`ul`,{className:`flex flex-col`,"data-slot":`schema-fields`,children:e.map(e=>(0,X.jsx)(rr,{field:e,depth:0},e.path))})}function rr({field:e,depth:t,cell:n=!1}){let i=e.type===`enum`&&e.enumValues,a=zt(e);return(0,X.jsxs)(n?`div`:`li`,{className:n?`min-w-0 border-b border-border/50`:void 0,children:[(0,X.jsxs)(`div`,{className:n?`flex items-center gap-1.5 px-2 py-1.5`:`flex items-center gap-2 py-1`,style:n?void 0:{paddingLeft:t*14},"data-slot":`schema-field-row`,children:[(0,X.jsx)(`span`,{className:`shrink-0`,"data-slot":`schema-field-keys`,title:ir(e),children:(0,X.jsx)(Ct,{primaryKey:e.primaryKey,foreignKey:e.foreignKey,unique:e.unique,empty:`none`})}),(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[11px] font-medium text-foreground/90`,children:e.name}),e.required?null:(0,X.jsx)(`span`,{className:`shrink-0 rounded border border-border/60 bg-muted/30 px-1 py-px text-[9px] font-medium tracking-wide text-muted-foreground uppercase`,"data-slot":`schema-field-optional`,children:`optional`}),e.pii?(0,X.jsx)(`span`,{className:`shrink-0 rounded border border-amber-500/40 bg-amber-500/10 px-1 py-px text-[9px] font-medium tracking-wide text-amber-800 uppercase dark:text-amber-300`,"data-slot":`schema-field-pii`,children:`pii`}):null,e.sensitive?(0,X.jsx)(`span`,{className:`shrink-0 rounded border border-rose-500/40 bg-rose-500/10 px-1 py-px text-[9px] font-medium tracking-wide text-rose-700 uppercase dark:text-rose-300`,"data-slot":`schema-field-sensitive`,children:`sensitive`}):null,a&&!i?(0,X.jsx)(`span`,{className:`shrink-0 rounded border border-blue-500/35 bg-blue-500/10 px-1 py-px font-mono text-[9px] font-medium tracking-wide text-blue-800 dark:text-blue-300`,"data-slot":`schema-field-constraint`,title:`Allowed range ${a}`,children:a}):null,(0,X.jsx)(`span`,{className:r(`ml-auto shrink-0 rounded border px-1.5 py-px font-mono text-[9px] font-medium tracking-wide`,tr(e.type)),"data-slot":`schema-field-type`,title:i?e.enumValues?.join(` | `):e.type,children:e.type})]}),e.children?.map(e=>(0,X.jsx)(rr,{field:e,depth:t+1,cell:n},e.path))]})}function ir(e){let t=[];if(e.primaryKey&&t.push(`Primary key`),e.foreignKey){let n=e.references?[e.references.table,e.references.column].filter(Boolean).join(`.`):null;t.push(n?`Foreign key → ${n}`:`Foreign key`)}return e.unique&&t.push(`Unique`),t.length>0?t.join(` · `):`None`}function ar({fields:e}){let t=Vt(e);return t.length===0?null:(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"data-slot":`validation-section`,"aria-label":`Validation`,children:[(0,X.jsx)(Q,{title:`Validation`,meta:String(t.length)}),(0,X.jsx)(`ul`,{className:`flex flex-col gap-3`,children:t.map(e=>(0,X.jsx)(or,{field:e},e.path))})]})}function or({field:e}){let t=Bt(e),n=e.valueMeanings?.length?e.valueMeanings:e.enumValues?.map(e=>({value:e,label:e}));return(0,X.jsxs)(`li`,{className:`flex flex-col gap-1.5`,"data-slot":`validation-field`,"data-field":e.name,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`font-mono text-[11px] font-medium text-foreground/90`,children:e.name}),t?(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:t}):null]}),n&&n.length>0?(0,X.jsx)(`ul`,{className:`grid grid-cols-2 gap-x-4 gap-y-1 sm:grid-cols-3 lg:grid-cols-5`,children:n.map(e=>(0,X.jsxs)(`li`,{className:`flex min-w-0 items-baseline gap-1.5 font-mono text-[11px]`,"data-slot":`validation-option`,children:[(0,X.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:e.value}),(0,X.jsx)(`span`,{className:`truncate text-foreground/90`,children:e.label})]},e.value))}):null]})}function sr({row:e,manifest:t,runs:n,leading:i}){let a=J(e.flow.trigger),o=lt(e.flow.trigger),s=ft(t,e.id,a===`http`?`http`:a===`internal`?`internal`:a),c=Kt(e.flow.in),l=Kt(e.flow.out),u=pt(e.flow.gates??[],t),d=a===`signal`&&e.flow.trigger?.signal?t?.signals?.[e.flow.trigger.signal]:void 0,f=a===`cron`||a===`every`?fn(t,e.id):null,p=a===`internal`?gt(t,e.id):[],m=a===`http`?`Request`:`Input`,h=a===`http`?`Response`:`Output`,g=a!==`cron`&&a!==`every`,_=Z(c),v=Z(l),y=At(_,a===`http`&&e.path?sn(e.path):[]);return(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`flow-contract-panel`,"data-trigger":a,children:[(0,X.jsx)(qe,{dataSlot:`endpoint-header`,leading:i,icon:(0,X.jsx)(`span`,{"data-slot":`trigger-kind-icon`,"data-kind":a,children:(0,X.jsx)(B,{icon:o.icon,className:`size-4`})}),wellClassName:o.wellClass,title:(0,X.jsx)(`span`,{className:`font-mono`,children:e.id}),badge:(0,X.jsx)(`span`,{className:`font-mono text-[10px] font-medium tracking-[0.08em] text-muted-foreground uppercase`,"data-slot":`trigger-kind-badge`,children:o.label}),subtitle:a===`http`&&s.method&&s.path?(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,"data-slot":`http-endpoint-line`,children:[(0,X.jsx)(Hn,{method:s.method}),(0,X.jsx)(`code`,{className:`min-w-0 truncate font-mono text-[11px] leading-none text-muted-foreground select-all`,children:s.path})]}):a===`signal`&&d?(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,"data-slot":`signal-endpoint-line`,children:[(0,X.jsx)(Gn,{delivery:d.delivery}),(0,X.jsx)(`code`,{className:`min-w-0 truncate font-mono text-[11px] leading-none text-muted-foreground select-all`,children:e.flow.trigger?.signal})]}):(0,X.jsx)(`span`,{className:`truncate font-mono text-[11px] leading-none text-muted-foreground`,"data-slot":`trigger-headline`,children:s.headline}),actions:(0,X.jsxs)(ge,{to:`/overview`,search:{flow:e.id},"data-slot":`open-in-graph`,className:r(b,`text-sky-700 dark:text-sky-400`),children:[(0,X.jsx)(B,{icon:We.flow.icon,className:`size-3.5`,"aria-hidden":!0}),`Open in graph`]})}),(0,X.jsxs)(Qn,{flowId:e.id,runs:n,children:[e.flow.plane?(0,X.jsx)(cr,{plane:e.flow.plane}):null,e.flow.durable?(0,X.jsx)(lr,{icon:re,label:`durable`,title:`Durable — long-running, retryable steps`}):null,e.flow.live?(0,X.jsx)(lr,{icon:C,label:`live`,title:typeof e.flow.live==`string`?`Live — SSE for ${e.flow.live}`:`Live — SSE signal feed`}):null]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3 py-3`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsx)(Kn,{effects:e.flow.effects}),(0,X.jsx)(ct,{gates:u}),(0,X.jsx)(Jn,{errors:e.flow.errors}),a===`signal`&&d&&(d.retries!==void 0||d.deadLetter)?(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,"data-slot":`signal-delivery`,children:[d.retries===void 0?null:`retries ${d.retries}`,d.deadLetter?`dead-letter`:null].filter(e=>e!==null).join(` · `)}):null,(a===`cron`||a===`every`)&&f?.kind===`matched`?(0,X.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,"data-slot":`clock-join`,children:[`Clock · `,(0,X.jsx)(`span`,{className:`font-mono`,children:f.clockName}),f.timezone?` · ${f.timezone}`:``]}):null,a===`internal`?(0,X.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,"data-slot":`call-only-note`,children:[`No external trigger — reachable via `,(0,X.jsx)(`code`,{className:`font-mono`,children:`effects.calls`}),` /`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`fx.call`}),`.`]}):null,a===`internal`?(0,X.jsxs)(`section`,{className:`flex flex-col gap-1.5`,"aria-label":`Callers`,"data-slot":`callers-list`,children:[(0,X.jsx)(Q,{title:`Called by`,meta:String(p.length)}),p.length===0?(0,X.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`No Manifest caller declares `,(0,X.jsx)(`code`,{className:`font-mono`,children:`effects.calls`}),` for this flow.`]}):(0,X.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:p.map(e=>(0,X.jsx)(`li`,{className:`font-mono text-xs text-foreground/90`,children:e},e))})]}):null,g&&y.parameters.length>0?(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"aria-label":`Parameters`,"data-slot":`parameters`,children:[(0,X.jsx)(Q,{title:`Parameters`,meta:String(y.parameters.length)}),(0,X.jsx)(nr,{fields:y.parameters,layout:`grid`})]}):null,(0,X.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[g&&(y.fields.length>0||y.parameters.length===0)?(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"aria-label":m,"data-slot":`request`,children:[(0,X.jsx)(Q,{title:m,meta:String(y.fields.length)}),(0,X.jsx)(nr,{fields:y.fields,emptyLabel:typeof e.flow.in==`string`?`Schema not expanded in Manifest.`:a===`signal`?`No flow input schema — signal payload shape lives on the signal when declared.`:`No input schema declared.`})]}):null,(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"aria-label":h,children:[(0,X.jsx)(Q,{title:h,meta:String(v.length)}),(0,X.jsx)(nr,{fields:v,emptyLabel:typeof e.flow.out==`string`?`Schema not expanded in Manifest.`:`No output schema declared.`})]})]}),g?(0,X.jsx)(ar,{fields:_}):null]})})]})}function cr({plane:e}){let t=e===`operator`,n=t?v:T,i=t?`operator`:`user`;return(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:t=>(0,X.jsxs)(`span`,{...t,className:r(b,`cursor-help`),"data-slot":`plane-badge`,"data-plane":e,children:[(0,X.jsx)(B,{icon:n,className:`size-3`,"aria-hidden":!0}),i]})}),(0,X.jsx)(s,{side:`bottom`,className:`max-w-xs text-[11px]`,children:t?`Operator plane — runs under a Console operator identity, not an application user.`:`User plane — runs under an application user identity (invoke-as).`})]})}function lr({icon:e,label:t,title:n}){return(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:n=>(0,X.jsxs)(`span`,{...n,className:r(b,de,`cursor-help`),children:[(0,X.jsx)(B,{icon:e,className:`size-3`,"aria-hidden":!0}),t]})}),(0,X.jsx)(s,{side:`bottom`,className:`max-w-xs text-[11px]`,children:n})]})}function ur(e){let t=new Map(ot.map(e=>[e,[]]));for(let n of e){let e=new Map;for(let t of n.flows){let n=J(t.flow.trigger),r=e.get(n)??[];r.push(t),e.set(n,r)}for(let[r,i]of e)t.get(r)?.push({unit:n.unit,flows:i})}return ot.flatMap(e=>{let n=t.get(e)??[];return n.length===0?[]:[{id:e,label:st[e].label,groups:n}]})}function dr(e){return`band:${e}`}function fr(e,t){return`unit:${e}:${t}`}function pr(e,t,n=!1){let r=t[e];return r===void 0?n:r}function mr(e){let t=[];for(let n of e){t.push(dr(n.id));for(let e of n.groups)t.push(fr(n.id,e.unit))}return t}function hr(e,t){for(let n of e)for(let e of n.groups)if(e.flows.some(e=>e.id===t))return[dr(n.id),fr(n.id,e.unit)];return[]}function gr(e,t){let n=Ye(e.method)-Ye(t.method);return n===0?e.id.localeCompare(t.id):n}function _r(e){let t=e?.flows;if(!t)return[];let n=new Map;for(let[r,i]of Object.entries(t)){let t=mt(r),a=r.includes(`.`)?r.slice(r.indexOf(`.`)+1):r,o=i.trigger?.http,s=i.trigger?.signal??null,c={id:r,unit:t,action:a,flow:i,method:o?.method??null,path:o?.path??null,signal:s,delivery:s?e.signals?.[s]?.delivery??null:null},l=n.get(t)??[];l.push(c),n.set(t,l)}return[...n.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({unit:e,flows:t.sort(gr)}))}function vr(e,t){let n=t.trim().toLowerCase();return n?e.map(e=>{let t=e.unit.toLowerCase().includes(n)?e.flows:e.flows.filter(e=>e.id.toLowerCase().includes(n)||e.action.toLowerCase().includes(n)||(e.method?.toLowerCase().includes(n)??!1)||(e.path?.toLowerCase().includes(n)??!1)||(e.signal?.toLowerCase().includes(n)??!1)||(e.delivery?.toLowerCase().includes(n)??!1));return t.length>0?{unit:e.unit,flows:t}:null}).filter(e=>e!==null):e}function yr(e){return(e.triggerKinds?.length??0)+(e.planes?.length??0)+(e.deliveries?.length??0)+ +!!e.durableOnly+ +!!e.liveOnly}function br(e,t){let n=t.triggerKinds?.length?new Set(t.triggerKinds):null,r=t.planes?.length?new Set(t.planes):null,i=t.deliveries?.length?new Set(t.deliveries):null,a=t.durableOnly===!0,o=t.liveOnly===!0;return!n&&!r&&!i&&!a&&!o?e:e.map(e=>{let t=e.flows.filter(e=>!(n&&!n.has(J(e.flow.trigger))||r&&!r.has(e.flow.plane??`user`)||i&&(e.delivery===null||!i.has(e.delivery))||a&&!e.flow.durable||o&&!e.flow.live));return t.length>0?{unit:e.unit,flows:t}:null}).filter(e=>e!==null)}var xr={user:{icon:T,label:`user`},operator:{icon:v,label:`operator`}},Sr=[`user`,`operator`];function Cr({groups:e,selectedFlowId:t,onSelect:n}){let[i,a]=(0,Y.useState)(``),[o,c]=(0,Y.useState)(!1),[l,d]=(0,Y.useState)({}),[f,p]=(0,Y.useState)({}),h=(0,Y.useMemo)(()=>{let t=new Set;for(let n of e)for(let e of n.flows)t.add(J(e.flow.trigger));return ot.filter(e=>t.has(e))},[e]),g=(0,Y.useMemo)(()=>{let t=new Set;for(let n of e)for(let e of n.flows)e.flow.plane&&t.add(e.flow.plane);return Sr.filter(e=>t.has(e))},[e]),{hasDurable:_,hasLive:v,availableDeliveries:y}=(0,Y.useMemo)(()=>{let t=!1,n=!1,r=new Set;for(let i of e)for(let e of i.flows)e.flow.durable&&(t=!0),e.flow.live&&(n=!0),e.delivery&&r.add(e.delivery);return{hasDurable:t,hasLive:n,availableDeliveries:Un.filter(e=>r.has(e))}},[e]),b=yr(l),x=(0,Y.useMemo)(()=>ur(br(vr(e,i),l)),[e,i,l]),T=(0,Y.useMemo)(()=>mr(x),[x]),E=i.trim().length>0,D=T.length>0&&T.every(e=>pr(e,f,E));(0,Y.useEffect)(()=>{if(!t)return;let e=hr(x,t);e.length!==0&&p(t=>{let n=!1,r={...t};for(let t of e)r[t]!==!0&&(r[t]=!0,n=!0);return n?r:t})},[t,x]);let O=(e,t)=>{p(n=>n[e]===t?n:{...n,[e]:t})},k=()=>{let e=!D;p(t=>{let n={...t};for(let t of T)n[t]=e;return n})},A=e=>d(t=>({...t,triggerKinds:Tr(t.triggerKinds??[],e)})),j=e=>d(t=>({...t,planes:Tr(t.planes??[],e)})),M=e=>d(t=>({...t,[e]:!t[e]})),N=e=>d(t=>({...t,deliveries:Tr(t.deliveries??[],e)}));return(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`units-tree`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 border-b border-border/60`,children:[(0,X.jsxs)(`div`,{className:r(w,`border-b-0`),children:[(0,X.jsx)(ze,{value:i,onChange:e=>a(e.target.value),placeholder:`Search flows…`,"aria-label":`Search flows`,"data-slot":`units-search`}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-stretch pr-0.5`,children:[(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:e=>(0,X.jsxs)(`button`,{...e,type:`button`,"aria-expanded":o,"aria-controls":`units-advanced-panel`,"aria-label":b>0?`Advanced filters, ${b} active`:`Advanced filters`,"data-slot":`units-advanced-toggle`,onClick:t=>{e.onClick?.(t),c(e=>!e)},className:r(S,`relative`,(o||b>0)&&`text-foreground`),children:[(0,X.jsx)(B,{icon:F,className:`size-3`,"aria-hidden":!0}),b>0?(0,X.jsx)(`span`,{"data-slot":`units-advanced-count`,className:`absolute -top-0.5 -inset-e-0.5 flex size-3.5 items-center justify-center rounded-full bg-foreground text-[8px] font-medium text-background`,"aria-hidden":!0,children:b}):null]})}),(0,X.jsx)(s,{side:`bottom`,children:`Advanced`})]}),(0,X.jsx)(Pe,{allOpen:D,disabled:T.length===0,onToggle:k,dataSlot:`units-tree-expand-toggle`})]})]}),o?(0,X.jsxs)(`div`,{id:`units-advanced-panel`,"data-slot":`units-advanced-panel`,className:`flex flex-col gap-2 border-t border-border/60 bg-muted/20 p-2`,children:[(0,X.jsx)(wr,{label:`Trigger`,groupLabel:`Trigger kind filter`,children:h.map(e=>{let t=st[e];return(0,X.jsx)($,{icon:t.icon,label:t.label,pressed:l.triggerKinds?.includes(e)??!1,onToggle:()=>A(e),dataFacet:`kind:${e}`},e)})}),y.length>0?(0,X.jsx)(wr,{label:`Delivery`,groupLabel:`Signal delivery filter`,children:y.map(e=>{let t=Wn[e];return(0,X.jsx)($,{icon:t.icon,label:t.label,pressed:l.deliveries?.includes(e)??!1,onToggle:()=>N(e),dataFacet:`delivery:${e}`},e)})}):null,g.length>0?(0,X.jsx)(wr,{label:`Plane`,groupLabel:`Plane filter`,children:g.map(e=>{let t=xr[e];return(0,X.jsx)($,{icon:t.icon,label:t.label,pressed:l.planes?.includes(e)??!1,onToggle:()=>j(e),dataFacet:`plane:${e}`},e)})}):null,_||v?(0,X.jsxs)(wr,{label:`Flags`,groupLabel:`Flow flags filter`,children:[_?(0,X.jsx)($,{icon:re,label:`durable`,pressed:l.durableOnly??!1,onToggle:()=>M(`durableOnly`),dataFacet:`flag:durable`}):null,v?(0,X.jsx)($,{icon:C,label:`live`,pressed:l.liveOnly??!1,onToggle:()=>M(`liveOnly`),dataFacet:`flag:live`}):null]}):null,b>0?(0,X.jsx)(`button`,{type:`button`,"data-slot":`units-advanced-clear`,onClick:()=>d({}),className:`self-end px-2 py-1 text-[10px] font-medium text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground`,children:`Clear all`}):null]}):null]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-x-hidden overflow-y-auto`,children:x.length===0?(0,X.jsx)(`p`,{className:oe,children:`No flows match.`}):(0,X.jsx)(`div`,{className:`flex flex-col`,children:x.map(e=>{let r=dr(e.id);return(0,X.jsx)(Er,{band:e,open:pr(r,f,E),onOpenChange:e=>O(r,e),groupOpen:t=>pr(fr(e.id,t),f,E),onGroupOpenChange:(t,n)=>O(fr(e.id,t),n),selectedFlowId:t,onSelect:n},e.id)})})})]})}function wr({label:e,groupLabel:t,children:n}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`w-14 shrink-0 text-[9px] font-semibold tracking-[0.08em] text-muted-foreground uppercase`,children:e}),(0,X.jsx)(`div`,{className:`flex min-h-7 flex-wrap items-stretch`,role:`group`,"aria-label":t,children:n})]})}function $({icon:e,label:t,pressed:n,onToggle:i,dataFacet:a}){return(0,X.jsxs)(`button`,{type:`button`,"data-slot":`units-facet-chip`,"data-facet":a,"aria-pressed":n,onClick:i,className:r(`inline-flex items-center gap-1 px-2 text-[10px] font-medium transition-colors hover:bg-muted/50`,n?`text-foreground`:`text-muted-foreground hover:text-foreground`),children:[(0,X.jsx)(B,{icon:e,className:`size-3`,"aria-hidden":!0}),t]})}function Tr(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function Er({band:e,open:n,onOpenChange:i,groupOpen:a,onGroupOpenChange:o,selectedFlowId:s,onSelect:c}){let l=st[e.id],u=e.groups.reduce((e,t)=>e+t.flows.length,0),f=e.groups.map(e=>e.unit),p=f.length>0&&f.every(e=>a(e)),m=()=>{let e=!p;for(let t of f)o(t,e);e&&i(!0)};return(0,X.jsx)(`section`,{"data-slot":`units-trigger-band`,"data-band":e.id,"aria-label":e.label,className:g,children:(0,X.jsxs)(xt,{open:n,onOpenChange:i,children:[(0,X.jsx)(bt,{nativeButton:!1,className:t,"data-slot":`units-trigger-band-toggle`,render:t=>(0,X.jsxs)(`div`,{...t,children:[(0,X.jsx)(B,{icon:d,className:r(ce,!n&&`-rotate-90`),"aria-hidden":!0}),(0,X.jsx)(B,{icon:l.icon,className:r(z,_(l.wellClass)),"aria-hidden":!0}),(0,X.jsx)(`span`,{className:r(O,`flex-1`),children:e.label}),(0,X.jsx)(`span`,{className:R,children:u}),(0,X.jsx)(`span`,{className:y,children:(0,X.jsx)(Pe,{allOpen:p,disabled:f.length===0,onToggle:m,collapseLabel:`Collapse all in ${e.label}`,expandLabel:`Expand all in ${e.label}`,dataSlot:`units-band-expand-toggle`,disclose:!0,bare:!0})})]})}),(0,X.jsx)(yt,{children:(0,X.jsx)(`ul`,{className:`flex flex-col`,children:e.groups.map(t=>(0,X.jsx)(Dr,{group:t,open:a(t.unit),onOpenChange:e=>o(t.unit,e),selectedFlowId:s,onSelect:c},`${e.id}:${t.unit}`))})})]})})}function Dr({group:e,open:t,onOpenChange:n,selectedFlowId:i,onSelect:a}){return(0,X.jsx)(`li`,{"data-slot":`unit-group`,"data-unit":e.unit,children:(0,X.jsxs)(xt,{open:t,onOpenChange:n,children:[(0,X.jsxs)(bt,{className:r(ie,`pl-4`),children:[(0,X.jsx)(B,{icon:d,className:r(ce,!t&&`-rotate-90`),"aria-hidden":!0}),(0,X.jsx)(B,{icon:A,className:r(z,`text-muted-foreground`),"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:e.unit}),(0,X.jsx)(`span`,{className:R,children:e.flows.length})]}),(0,X.jsx)(yt,{children:(0,X.jsx)(`ul`,{className:`flex flex-col`,children:e.flows.map(e=>(0,X.jsx)(Or,{flow:e,selected:i===e.id,onSelect:a},e.id))})})]})})}function Or({flow:e,selected:t,onSelect:n}){let i=lt(e.flow.trigger),a=e.delivery?Wn[e.delivery]:null,o=a?.icon??(e.method?Ze(e.method):i.icon),c=_(a?.wellClass??(e.method?Qe(e.method):i.wellClass)),l=a?e.signal?`${a.title} · ${e.signal}`:a.title:i.detail?`${i.label} · ${i.detail}`:i.label;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,"data-slot":`unit-flow-item`,"data-flow-id":e.id,"data-delivery":e.delivery??void 0,"aria-current":t?`true`:void 0,onClick:()=>n(e.id),className:r(D,`group/flow pl-8`,t&&`bg-muted/70 text-foreground`),children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:r(ue,t?ee:`bg-transparent`)}),(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:e=>(0,X.jsx)(`span`,{...e,className:r(z,c),"aria-hidden":!0,children:(0,X.jsx)(B,{icon:o,className:`size-3.5`})})}),(0,X.jsx)(s,{side:`right`,className:`text-[11px]`,children:l})]}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:e.action}),e.method?(0,X.jsx)(Hn,{method:e.method,className:`ml-auto h-3.5 px-1 text-[8px] leading-none`}):null]})})}function kr(){let e=et(),t=nt();$e(!0);let{selectedFlowId:n,setSelectedFlow:r}=Le(),i=Be(),a=(0,Y.useMemo)(()=>_r(e.data??null),[e.data]),o=(0,X.jsx)(Ve,{open:i.open,onToggle:i.toggle,noun:`flows`,controlsId:`flows-tree`,dataSlot:`flows-tree-toggle`}),s=n??a[0]?.flows[0]?.id??null,c=(0,Y.useMemo)(()=>{if(!s)return null;for(let e of a){let t=e.flows.find(e=>e.id===s);if(t)return t}return null},[a,s]);return(0,X.jsx)(`div`,{className:E,"data-slot":`units-page`,children:(0,X.jsxs)(Re,{orientation:`horizontal`,className:`min-h-0 flex-1`,children:[(0,X.jsx)(K,{panelRef:i.panelRef,collapsible:!0,collapsedSize:0,defaultSize:I.start.defaultSize,minSize:I.start.minSize,onResize:i.onResize,className:`min-h-0 overflow-hidden`,children:(0,X.jsx)(`div`,{id:`flows-tree`,className:`h-full min-h-0 overflow-hidden`,"data-slot":`flows-tree`,children:(0,X.jsx)(Cr,{groups:a,selectedFlowId:s,onSelect:e=>{r(e)}})})}),i.open?(0,X.jsx)(He,{withHandle:!0}):null,(0,X.jsx)(K,{defaultSize:I.end.defaultSize,minSize:I.end.minSize,className:`min-h-0 overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full min-h-0 overflow-hidden`,children:c?(0,X.jsxs)(Re,{orientation:`vertical`,className:`min-h-0 flex-1`,"data-slot":`units-inspector`,children:[(0,X.jsx)(K,{defaultSize:`56%`,minSize:`28%`,className:`min-h-0 overflow-hidden`,children:(0,X.jsx)(sr,{row:c,manifest:e.data??null,runs:t.data,leading:o})}),(0,X.jsx)(He,{withHandle:!0}),(0,X.jsx)(K,{defaultSize:`44%`,minSize:`220px`,className:`min-h-0 overflow-hidden`,children:(0,X.jsx)(wn,{row:c,manifest:e.data??null})})]}):(0,X.jsx)(Ge,{icon:We.flow.icon,title:e.isLoading?`Loading Manifest…`:`Select a flow`,description:e.isLoading?`Reading the derived Manifest.`:`Pick a flow from the tree to inspect its contract.`,leading:o})})})]})})}export{kr as UnitsPage};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$n as t,Br as n,Cr as r,Di as i,E as a,Er as o,F as s,Fr as c,Jr as l,L as u,Mr as d,Nr as f,Oi as p,P as m,Qi as h,Qn as g,Sr as _,Wi as v,Zn as y,_r as b,a as x,ar as S,bi as C,br as w,ca as T,cr as E,dr as D,er as O,gr as k,hi as A,hr as j,i as M,kr as N,l as P,li as F,lr as ee,mr as I,na as L,nr as R,o as te,or as z,qi as ne,ra as re,rr as ie,s as ae,sr as oe,ta as se,tr as ce,u as le,ur as ue,vr as de,wr as B,x as fe,xr as V,zi as pe}from"./shortcut-keys-DKxNTe_m.js";import{r as me}from"./react-dom-Bph1y7z7.js";import{A as he}from"./xyflow-D7n4g6go.js";import{t as ge}from"./link-BX6Vqztd.js";import{d as _e,r as ve,t as ye}from"./dropdown-menu-_NjTEo5_.js";import{$ as be,G as xe,Q as H,X as U,Y as W,a as Se,c as Ce,d as we,et as G,f as Te,h as Ee,i as De,n as Oe,nt as ke,o as Ae,p as je,r as Me,s as Ne,t as Pe,u as Fe,v as Ie}from"./tree-expand-toggle-BtyhmWb4.js";import{u as Le}from"./index-CcTDXHuz.js";import{a as Re,c as ze,i as K,n as Be,o as Ve,r as He,s as Ue,t as We}from"./element-icons-BVXtRyd3.js";import{t as Ge}from"./explorer-empty-2uIhBu0_.js";import{c as q,n as Ke,t as qe,u as Je}from"./detail-header-DhHM1iaZ.js";import{a as Ye,n as Xe,r as Ze,t as Qe}from"./http-method-_UHM2ODJ.js";import{a as $e,c as et,i as tt,s as nt,t as rt}from"./highlighted-json-Awq7gYdu.js";import{a as it,c as at,d as ot,f as st,l as ct,m as lt,o as ut,p as J,s as dt,t as ft,u as pt}from"./request-meta-DV0ywz7t.js";import{c as mt,n as ht,s as gt,t as _t}from"./cache-glyph-B5X-NM0-.js";import{i as vt,n as yt,r as bt,t as xt}from"./collapsible-DGnOM2ph.js";import{n as St,o as Ct,r as wt,t as Tt}from"./call-pii-button-ChAUiLo9.js";var Y=e(me(),1),X=he();function Et(e,t){let n=Ne(e.asGate);return n===`operator`?`Operator`:n===`public`?`Public`:e.asUserId?t.find(t=>t.id===e.asUserId)?.name??e.asUserId:e.asGate?`As · ${e.asGate}`:`As`}function Dt(e){let t=Ne(e.asGate);return t===`operator`||t===`public`||!!(e.asUserId||e.asGate)}function Ot({manifest:e,identities:t,value:n,onChange:i}){let a=xe(!0),o=(0,Y.useMemo)(()=>Ee(Ie(e),a.data??null),[e,a.data]),s=(0,Y.useMemo)(()=>Ce(o),[o]),c=(0,Y.useMemo)(()=>Fe(t,o),[t,o]),l=o.gates.find(e=>e.kind===`public`)?.description??`Intentionally unauthenticated.`,u=Ne(n.asGate),d=n.asGate!==null,[f,p]=(0,Y.useState)(n.asUserId?`user`:`policy`),m=s.find(e=>e.id===n.asGate)??null,h=c.find(e=>e.id===n.asUserId&&e.gate===n.asGate)??null,g=s.length>0||c.length>0,_=e=>{if(e===`operator`){i({asGate:null,asUserId:null});return}if(e===`public`){i({asGate:`public`,asUserId:null});return}if(u===`as`)return;let t=m?.id??s[0]?.id??c[0]?.gate??null;if(t!==null){if(c[0]&&t===c[0].gate&&s.length===0){p(`user`),i({asGate:c[0].gate,asUserId:c[0].id});return}p(`policy`),i({asGate:t,asUserId:null})}};return(0,X.jsxs)(ye,{children:[(0,X.jsx)(_e,{render:e=>(0,X.jsxs)(fe,{...e,type:`button`,variant:`ghost`,size:`sm`,className:r(`h-full max-w-44 min-w-0 rounded-none px-2 text-[11px]`,d&&`text-sky-800 dark:text-sky-300`),"aria-label":d?`Invoke as Gate ${n.asGate}`:`Invoke as Operator (bypass gates)`,"data-slot":`call-api-identity`,children:[(0,X.jsx)(B,{icon:We.gate.icon,"data-icon":`inline-start`,className:`size-3.5`}),(0,X.jsx)(`span`,{className:`truncate`,children:Et(n,t)})]})}),(0,X.jsxs)(ve,{align:`end`,className:`w-80 overflow-hidden p-0`,children:[(0,X.jsx)(Ae,{children:`Invoke as`}),(0,X.jsxs)(Se,{label:`Invoke as`,children:[(0,X.jsx)(Me,{mode:`operator`,title:`Operator`,caption:`Bypass`,selected:u===`operator`,onSelect:()=>_(`operator`)}),(0,X.jsx)(Me,{mode:`public`,title:`Public`,caption:`Anonymous`,selected:u===`public`,onSelect:()=>_(`public`)}),(0,X.jsx)(Me,{mode:`as`,title:`As`,caption:h?h.label:m?.label??`User / policy`,selected:u===`as`,disabled:!g,onSelect:()=>_(`as`)})]}),u===`operator`?(0,X.jsx)(De,{title:`Operator`,badge:`Default`,children:`Bypasses the flow's gate chain.`}):null,u===`public`?(0,X.jsxs)(De,{title:`Public`,children:[l,` Only `,(0,X.jsx)(`span`,{className:`font-mono`,children:`gate.public`}),` flows succeed.`]}):null,u===`as`?(0,X.jsx)(Oe,{tab:f,onTabChange:p,policies:s,users:c,asGate:n.asGate,asUserId:h?.id??null,onSelectPolicy:e=>{p(`policy`),i({asGate:e.id,asUserId:null})},onSelectUser:e=>{p(`user`),i({asGate:e.gate,asUserId:e.id})},hint:h?(0,X.jsxs)(`p`,{className:`border-t border-border/60 px-2 py-2 text-[10px] leading-relaxed text-muted-foreground`,children:[`Calls as `,(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:h.label}),` `,`via `,(0,X.jsx)(`span`,{className:`font-mono`,children:n.asGate}),`.`]}):m?(0,X.jsxs)(`p`,{className:`border-t border-border/60 px-2 py-2 text-[10px] leading-relaxed text-muted-foreground`,children:[m.detail,` Sets scopes for`,` `,(0,X.jsx)(`span`,{className:`font-mono`,children:m.id}),`.`]}):null}):null]})]})}var kt=new Set([`q`,`query`,`search`,`limit`,`offset`,`cursor`,`page`,`pageSize`,`perPage`,`per_page`,`page_size`,`order`,`orderBy`,`order_by`,`sort`,`sortBy`,`sort_by`,`direction`]);function At(e,t=[]){let n=new Set,r=[];for(let i of t){n.add(i);let t=e.find(e=>e.name===i);r.push(t??jt(i))}let i=[];for(let t of e)n.has(t.name)||(kt.has(t.name)?r.push(t):i.push(t));return{parameters:r,fields:i}}function jt(e){return{path:`/path/${e}`,name:e,type:`string`,required:!0}}function Mt(e,t={}){let n=t.pathParams??[],r=new Set(n);if(t.http!==!0)return{path:[],query:[],body:e};let i=e.filter(e=>!r.has(e.name));return Xe(t.method)?{path:n,query:[],body:i}:{path:n,query:i,body:[]}}function Nt(e,t){let n={};for(let r of t)Object.hasOwn(e,r.name)&&(n[r.name]=e[r.name]);return n}function Z(e,t=``){if(!e)return[];if(e.type===`object`||e.properties){let n=e.properties??{},r=new Set(Array.isArray(e.required)?e.required:[]);return Object.entries(n).map(([e,n])=>Pt(e,`${t}/${e}`,n,r.has(e)))}return[Pt(`value`,t||`/`,e,!0)]}function Pt(e,t,n,r){let i=Ft(e,n),a=typeof n.description==`string`?n.description:void 0;if(Array.isArray(n.enum)){let o=Ht(n);return{path:t,name:e,type:`enum`,required:r,enumValues:n.enum.map(String),...a===void 0?{}:{description:a},...o===void 0?{}:{valueMeanings:o},...i}}let o=n.type;if(o===`object`||n.properties)return{path:t,name:e,type:`object`,required:r,...a===void 0?{}:{description:a},...i,children:Z(n,t)};if(o===`array`)return{path:t,name:e,type:`array`,required:r,...a===void 0?{}:{description:a},...i,children:n.items?Z(n.items,`${t}/0`):void 0};let s=o===`integer`||o===`number`||o===`boolean`||o===`string`?o:`unknown`,c=Ht(n);return{path:t,name:e,type:s,required:r,minimum:typeof n.minimum==`number`?n.minimum:void 0,maximum:typeof n.maximum==`number`?n.maximum:void 0,...a===void 0?{}:{description:a},...c===void 0?{}:{valueMeanings:c},...i}}function Ft(e,t){let n=It(e),r=Lt(t.references),i=t.primaryKey===!0||n.primaryKey===!0,a=r!==void 0||n.foreignKey===!0,o=!i&&(t.unique===!0||n.unique===!0);return{...t.pii===!0?{pii:!0}:{},...t.sensitive===!0?{sensitive:!0}:{},...i?{primaryKey:!0}:{},...a?{foreignKey:!0}:{},...o?{unique:!0}:{},...r===void 0?{}:{references:r}}}function It(e){return e===`id`?{primaryKey:!0}:/(?:Id|_id)$/.test(e)||/(?:Key|_key)$/.test(e)&&e!==`key`?{foreignKey:!0}:e===`identifier`||e===`key`?{unique:!0}:{}}function Lt(e){if(!e||typeof e!=`object`)return;let t=`table`in e&&typeof e.table==`string`?e.table:void 0;if(!t)return;let n=`column`in e&&typeof e.column==`string`?e.column:void 0;return n===void 0?{table:t}:{table:t,column:n}}var Rt=12;function zt(e){return e.enumValues&&e.enumValues.length>0?e.enumValues.join(` · `):e.minimum!==void 0&&e.maximum!==void 0?`${e.minimum}–${e.maximum}`:e.minimum===void 0?e.maximum===void 0?null:`≤ ${e.maximum}`:`≥ ${e.minimum}`}function Bt(e){return e.minimum!==void 0&&e.maximum!==void 0?`Must be from ${e.minimum} up to ${e.maximum}.`:e.minimum===void 0?e.maximum===void 0?null:`Must be at most ${e.maximum}.`:`Must be at least ${e.minimum}.`}function Vt(e){return e.filter(e=>e.minimum!==void 0||e.maximum!==void 0||(e.enumValues?.length??0)>0||(e.valueMeanings?.length??0)>0)}function Ht(e){let t=Array.isArray(e.oneOf)?e.oneOf:Array.isArray(e.anyOf)?e.anyOf:null;if(t){let e=[];for(let n of t){if(!n||typeof n!=`object`)continue;let t=n;if(!(`const`in t))continue;let r=String(t.const),i=typeof t.title==`string`?t.title:typeof t.description==`string`?t.description:void 0;i&&e.push({value:r,label:i})}return e.length>0?e:void 0}}function Ut(e){if(e.type!==`integer`||e.minimum===void 0||e.maximum===void 0||!Number.isInteger(e.minimum)||!Number.isInteger(e.maximum))return null;let t=e.maximum-e.minimum;return t<0||t>Rt?null:Array.from({length:t+1},(t,n)=>e.minimum+n)}function Wt(e){return e?Gt(e):{}}function Gt(e){if(Array.isArray(e.enum)&&e.enum.length>0)return e.enum[0];let t=e.type;if(t===`object`||!t&&e.properties){let t=e.properties??{},n=new Set(Array.isArray(e.required)?e.required:[]),r={};for(let[e,i]of Object.entries(t))(n.has(e)||`default`in i||Object.keys(t).length<=4)&&(r[e]=Gt(i));return r}if(t===`array`){let t=e.items;return t?[Gt(t)]:[]}return t===`integer`||t===`number`?typeof e.default==`number`?e.default:typeof e.minimum==`number`?e.minimum:1:t===`boolean`?!1:t===`string`?e.format===`email`?`user@example.com`:e.format===`uuid`?`00000000-0000-4000-8000-000000000001`:typeof e.default==`string`?e.default:e.minLength?`x`.repeat(Number(e.minLength)):``:null}function Kt(e){return!e||typeof e==`string`?null:e}function qt(e,t){if(!e.foreignKey||!t)return null;let n=Zt(t);if(n.length===0)return null;if(e.references?.table){let t=Qt(n,e.references.table);return t?Yt(t,e.references.column??en(t.table)??`id`):null}let r=Xt(e.name);if(!r)return null;let i=$t(n,r.stem);return i?Yt(i,r.kind===`key`?tn(i.table,`key`)??en(i.table)??`id`:en(i.table)??`id`):null}function Jt(e,t){if(!t)return[];let n=new Set,r=[];for(let i of e){let e=i[t.column];if(e==null)continue;let a=String(e);if(n.has(a))continue;n.add(a);let o=t.labelColumn?i[t.labelColumn]:void 0,s=o!=null&&String(o)!==a?String(o):null;r.push({value:a,label:s?`${a} · ${s}`:a})}return r}function Yt(e,t){let n=nn(e.table,t);return{ref:e.ref,child:e.name,column:t,...n===void 0?{}:{labelColumn:n}}}function Xt(e){return e===`id`?null:e.endsWith(`Id`)?{stem:e.slice(0,-2),kind:`id`}:e.endsWith(`_id`)?{stem:e.slice(0,-3),kind:`id`}:e.endsWith(`Key`)?{stem:e.slice(0,-3),kind:`key`}:e.endsWith(`_key`)?{stem:e.slice(0,-4),kind:`key`}:null}function Zt(e){let t=[];for(let[n,r]of Object.entries(e.stores??{}))r.facet!==`sql`||!r.tables||t.push({ref:`sql:${n}`,tables:r.tables});return t}function Qt(e,t){let n=t.toLowerCase();for(let t of e)for(let[e,r]of Object.entries(t.tables))if(e.toLowerCase()===n)return{ref:t.ref,name:e,table:r};return null}function $t(e,t){let n=on(t),r=[t,n,an(t),an(n)].map(e=>e.toLowerCase());for(let t of e)for(let[e,n]of Object.entries(t.tables))if(r.includes(e.toLowerCase()))return{ref:t.ref,name:e,table:n};return null}function en(e){for(let[t,n]of Object.entries(e.columns??{}))if(rn(n)&&n.primaryKey===!0)return t;if(e.columns&&`id`in e.columns)return`id`}function tn(e,t){return e.columns&&t in e.columns?t:void 0}function nn(e,t){if(t!==`name`&&e.columns&&`name`in e.columns)return`name`}function rn(e){return`type`in e||`primaryKey`in e||`references`in e}function an(e){return e.endsWith(`y`)&&!/[aeiou]y$/i.test(e)?`${e.slice(0,-1)}ies`:/(?:s|x|z|ch|sh)$/i.test(e)?`${e}es`:`${e}s`}function on(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).replace(/([A-Z])([A-Z][a-z])/g,`$1_$2`).toLowerCase()}function sn(e){let t=[];for(let n of e.split(`/`))n.startsWith(`:`)&&n.length>1&&t.push(n.slice(1));return t}function cn(e){return`:${e}`}var ln={"attachments:id":`attachments/tsk_eng_12/spec.pdf`,"tasks:id":`tsk_eng_12`,"comments:id":`cmt_1`,"projects:id":`proj_api`,"spaces:id":`space_eng`,"tags:id":`tag_bug`,"tags:tagId":`tag_feature`,"goals:id":`goal_harbor`,"documents:id":`doc_prd_api`,"members:id":`mem_aria`,"forms:id":`form_customer`,"drafts:id":`ENG-12`,"views:id":`view_web_board`,"inbox:id":`inb_1`};function un(e,t){let n=e.split(`/`).filter(Boolean),r=`:${t}`,i=n.indexOf(r),a=i>0?n[i-1]:void 0;return(a?ln[`${a}:${t}`]:void 0)??ln[`:${t}`]}function dn(e,t){let n={};if(!e)return n;for(let r of t){let t=un(e,r);t&&(n[r]=t)}return n}function fn(e,t){let n=e?.flows?.[t],r=n?.trigger?.cron,i=n?.trigger?.every;if(!r&&!i)return{kind:`unmatched`};let a=e?.clocks??{},o=new Set;for(let[e,n]of Object.entries(a)){if(t===e||t.endsWith(`.${e}`)){o.add(e);continue}if(r&&n.cron===r){o.add(e);continue}i&&n.every===i&&o.add(e)}if(o.size!==1)return{kind:`unmatched`};let s=[...o][0],c=a[s];return{kind:`matched`,clockName:s,timezone:c.timezone??null,description:c.description??null,cron:c.cron??null,every:c.every??null}}function pn(e){let t=e.handlerMs!=null&&Number.isFinite(e.handlerMs)?e.handlerMs:null;return t===null?e.rttMs!==null&&Number.isFinite(e.rttMs)?{primaryMs:e.rttMs,primaryKind:`rtt`,rttMs:e.rttMs}:null:{primaryMs:t,primaryKind:`handler`,rttMs:e.rttMs}}function mn(e){let t=new Set;if(!e?.stores)return t;for(let n of Object.values(e.stores)){for(let e of Object.values(n.tables??{}))for(let[n,r]of Object.entries(e.columns??{}))r?.pii&&wt(t,n);for(let[e,r]of Object.entries(n.classifications??{}))if(r&&typeof r==`object`&&!Array.isArray(r)&&`pii`in r&&r.pii){let n=e.includes(`.`)?e.slice(e.lastIndexOf(`.`)+1):e;wt(t,n)}}return t}function hn(e,t,n=St){if(t.size===0||e==null)return e;if(Array.isArray(e))return e.map(e=>hn(e,t,n));if(typeof e==`object`){let r={};for(let[i,a]of Object.entries(e))r[i]=t.has(i)?n:hn(a,t,n);return r}return e}function gn(e){return e.failure==null?e.response!==void 0&&e.response!==null?JSON.stringify(e.response,null,2):JSON.stringify({status:e.status??200,failure:null,response:null},null,2):JSON.stringify({status:e.status??null,failure:e.failure,response:e.response??null},null,2)}function _n(e,t,n){return t&&e.masked===!1?gn({...e,response:hn(e.response,n),failure:e.failure===void 0?void 0:{...e.failure,data:hn(e.failure.data,n)},masked:!0}):gn(e)}function vn(e){let t=e.flow.effects;return!t||(t.writes?.length??0)===0&&(t.emits?.length??0)===0&&(t.sends?.length??0)===0&&(t.asks?.length??0)===0}function yn(e,t){return!t&&vn(e)}function bn(e,t){if(!e)return{ok:!0,errors:[],value:t};let n=[];return xn(e,t,``,n),{ok:n.length===0,errors:n,value:t}}function xn(e,t,n,r){let i=e.type;if(i===`object`||e.properties){if(typeof t!=`object`||!t||Array.isArray(t)){r.push({path:n||`/`,message:`must be object`});return}let i=t,a=e.properties??{},o=Array.isArray(e.required)?e.required:[];for(let e of o)(i[e]===void 0||i[e]===null||i[e]===``)&&r.push({path:`${n}/${e}`,message:`required`});for(let[e,t]of Object.entries(a))i[e]!==void 0&&xn(t,i[e],`${n}/${e}`,r);return}if(Array.isArray(e.enum)){e.enum.map(String).includes(String(t))||r.push({path:n||`/`,message:`invalid enum`});return}i===`string`&&typeof t!=`string`?r.push({path:n||`/`,message:`must be string`}):i===`integer`?typeof t!=`number`||!Number.isInteger(t)?r.push({path:n||`/`,message:`must be integer`}):Sn(e,t,n,r):i===`number`?typeof t!=`number`||Number.isNaN(t)?r.push({path:n||`/`,message:`must be number`}):Sn(e,t,n,r):i===`boolean`&&typeof t!=`boolean`&&r.push({path:n||`/`,message:`must be boolean`})}function Sn(e,t,n,r){let i=typeof e.minimum==`number`?e.minimum:void 0,a=typeof e.maximum==`number`?e.maximum:void 0;i!==void 0&&t<i&&r.push({path:n||`/`,message:`must be ≥ ${i}`}),a!==void 0&&t>a&&r.push({path:n||`/`,message:`must be ≤ ${a}`})}function Cn(e){return JSON.stringify(e,null,2)}function wn({row:e,manifest:t}){let n=J(e.flow.trigger);return n===`cron`||n===`every`?(0,X.jsx)(Tn,{row:e,manifest:t}):(0,X.jsx)(En,{row:e,kind:n,manifest:t})}function Tn({row:e,manifest:t}){let n=(0,Y.useMemo)(()=>fn(t,e.id),[t,e.id]),r=we(),i=Te(),a=je(),[o,s]=(0,Y.useState)({asGate:null,asUserId:null}),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{r.reset(),a.reset(),d(null),l(null)},[e.id]);let f=n.kind===`matched`;async function m(){if(l(performance.now()),f){d(`clock`);try{await r.mutateAsync({name:n.clockName})}catch{}return}if(Dt(o)){d(`invoke`);try{await a.mutateAsync({flowId:e.id,body:{},...o.asUserId?{asUserId:o.asUserId}:{},...o.asGate?{asGate:o.asGate}:{}})}catch{}}}let h=f?r.isPending:a.isPending,g=f?r.isError:a.isError||a.isSuccess&&a.data?.failure!=null,_=f?r.isSuccess:a.isSuccess&&!a.data?.failure,v=c!==null&&(_||g)?performance.now()-c:null,y=(0,Y.useMemo)(()=>f&&r.data?JSON.stringify(r.data,null,2):!f&&a.data?gn(a.data):null,[f,r.data,a.data]),b=f?`Run now`:`Run handler`,x=f?`Run now`:`Run handler once`;return(0,X.jsx)(An,{title:b,dataMode:f?`clock`:`invoke-fallback`,actions:(0,X.jsxs)(X.Fragment,{children:[f?null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ot,{manifest:t,identities:i.data??[],value:o,onChange:s}),(0,X.jsx)(Fn,{})]}),(0,X.jsx)(fe,{type:`button`,"data-slot":`call-api-submit`,disabled:h||!f&&!Dt(o),onClick:()=>void m(),className:Pn,children:h?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{icon:p,className:`animate-spin`,"data-icon":`inline-start`}),`Running…`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{icon:pe,"data-icon":`inline-start`}),x]})})]}),children:(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[f?(0,X.jsxs)(`p`,{className:`px-3 pt-2.5 pb-2 text-[11px] leading-snug text-muted-foreground`,"data-slot":`clock-path-copy`,children:[`Fires Manifest clock`,` `,(0,X.jsx)(`code`,{className:`rounded bg-muted/50 px-1 py-px font-mono text-[10px]`,children:n.clockName}),` `,`via`,` `,(0,X.jsx)(`code`,{className:`rounded bg-muted/50 px-1 py-px font-mono text-[10px]`,children:`/console/clock/run-now`}),` `,`(lease-gated — the real scheduler path).`,n.timezone?(0,X.jsxs)(X.Fragment,{children:[` `,`Timezone · `,(0,X.jsx)(`span`,{className:`font-mono`,children:n.timezone}),`.`]}):null]}):(0,X.jsxs)(`div`,{className:`mx-3 mt-2.5 rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-[11px] leading-snug text-foreground/90`,"data-slot":`invoke-fallback-copy`,role:`note`,children:[`No unique Manifest clock matches this flow's schedule.`,` `,(0,X.jsx)(`strong`,{className:`font-medium`,children:`Run handler once`}),` uses`,` `,(0,X.jsx)(`code`,{className:`rounded bg-muted/50 px-1 py-px font-mono text-[10px]`,children:`/console/flows/invoke`}),` `,`with empty input — it does `,(0,X.jsx)(`em`,{children:`not`}),` exercise the Clock lease / scheduler path.`]}),(0,X.jsx)(Dn,{failed:!!g,success:!!_,elapsed:v,handlerMs:f?null:a.data?.durationMs,statusCode:f?r.data?.ran?200:409:a.data?.status,errorMessage:f?r.isError?r.error.message:null:a.isError?a.error.message:null,responseJson:y,emptyHint:f?`Run now to fire the real clock tick.`:`Run handler once to invoke with empty input.`,pathUsed:u,cache:f?void 0:a.data?.cache})]})})}function En({row:e,kind:t,manifest:n}){let i=Te(),o=je(),l=Kt(e.flow.in),d=(0,Y.useMemo)(()=>Z(l),[l]),f=(0,Y.useMemo)(()=>t===`http`&&e.path?sn(e.path):[],[t,e.path]),h=(0,Y.useMemo)(()=>Mt(d,{http:t===`http`,method:e.method,pathParams:f}),[d,t,e.method,f]),g=t!==`http`||Xe(e.method),[_,v]=(0,Y.useState)({asGate:null,asUserId:null}),[y,b]=(0,Y.useState)(!0),[x,S]=(0,Y.useState)(()=>dn(e.path,f)),C=(0,Y.useMemo)(()=>Wt(l)??{},[l]),w=(0,Y.useMemo)(()=>Nt(C,h.query),[C,h.query]),T=(0,Y.useMemo)(()=>Nt(C,h.body),[C,h.body]),[E,D]=(0,Y.useState)(w),[O,k]=(0,Y.useState)(T),[A,j]=(0,Y.useState)(`fields`),[M,N]=(0,Y.useState)(()=>Cn(T)),[P,F]=(0,Y.useState)(null),[ee,I]=(0,Y.useState)([]),[L,R]=(0,Y.useState)(null),[te,z]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{D(w),k(T),N(Cn(T)),F(null),j(`fields`),S(dn(e.path,f)),I([]),z(null),R(null),o.reset()},[e.id]);function ne(e){try{let t=JSON.parse(e);return typeof t!=`object`||!t||Array.isArray(t)?(F(`Body must be a JSON object.`),!1):(k(t),F(null),!0)}catch(e){return F(e instanceof Error?e.message:`Invalid JSON.`),!1}}function re(e){if(e!==A){if(e===`raw`){N(Cn(O)),F(null),j(`raw`);return}ne(M)&&j(`fields`)}}async function ie(t=!y){let n=g?O:{};if(g&&A===`raw`){if(!ne(M))return;try{n=JSON.parse(M)}catch{return}}let r={...E,...n},i=bn(l,{...x,...r});if(!i.ok){I(i.errors);return}if(I([]),Dt(_)){R(performance.now());try{await o.mutateAsync({flowId:e.id,body:r,..._.asUserId?{asUserId:_.asUserId}:{},..._.asGate?{asGate:_.asGate}:{},...f.length>0?{pathParams:x}:{},...t?{revealPii:!0}:{}})}catch{}}}function ae(){D(w),k(T),N(Cn(T)),F(null),S(dn(e.path,f)),I([])}(0,Y.useEffect)(()=>{L===null||o.isPending||(o.isSuccess||o.isError)&&z(performance.now()-L)},[o.isSuccess,o.isError,o.isPending,L]);let oe=(0,Y.useMemo)(()=>o.data?_n(o.data,y,mn(n)):null,[o.data,y,n]),se=o.data?.failure!=null,ce=o.data?.status,le=t===`http`?`Call API`:t===`signal`?`Run handler`:`Invoke`,ue=le;return(0,X.jsx)(An,{title:le,dataTrigger:t,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ot,{manifest:n,identities:i.data??[],value:_,onChange:v}),(0,X.jsx)(Tt,{piiMasked:y,disabled:o.isPending,onToggle:()=>{let t=!y;b(t),o.data&&!o.isPending&&yn(e,t)&&ie(!0)}}),g?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Fn,{}),(0,X.jsx)(jn,{view:A,onChange:re})]}):null,(0,X.jsx)(Fn,{}),(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:e=>(0,X.jsxs)(fe,{...e,type:`button`,variant:`ghost`,"data-slot":`call-api-reset`,disabled:o.isPending,onClick:ae,className:Nn,children:[(0,X.jsx)(B,{icon:c,"data-icon":`inline-start`}),`Reset`]})}),(0,X.jsx)(s,{side:`bottom`,className:`text-[11px]`,children:g?`Reset body to the schema example`:`Reset to schema examples`})]}),(0,X.jsx)(Fn,{}),(0,X.jsx)(fe,{type:`button`,"data-slot":`call-api-submit`,disabled:o.isPending||!Dt(_),onClick:()=>void ie(),className:Pn,children:o.isPending?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{icon:p,className:`animate-spin`,"data-icon":`inline-start`}),`Calling…`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{icon:pe,"data-icon":`inline-start`}),ue]})})]}),children:(0,X.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`min-h-0 min-w-0 shrink overflow-y-auto`,children:[t===`http`?(0,X.jsxs)(`p`,{className:`px-3 pt-2.5 pb-2 text-[11px] leading-snug text-muted-foreground`,children:[`Operator session · invoke-as`,` `,(0,X.jsx)(`code`,{className:`rounded bg-muted/50 px-1 py-px font-mono text-[10px]`,children:`console:flows:invoke-as`})]}):null,t===`signal`?(0,X.jsxs)(`div`,{className:`mx-3 mt-2.5 rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-[11px] leading-snug text-foreground/90`,"data-slot":`signal-honest-copy`,role:`note`,children:[(0,X.jsx)(`strong`,{className:`font-medium`,children:`Run handler directly`}),` — invokes the flow with your payload via`,` `,(0,X.jsx)(`code`,{className:`rounded bg-muted/50 px-1 py-px font-mono text-[10px]`,children:`/console/flows/invoke`}),`. It does `,(0,X.jsx)(`em`,{children:`not`}),` publish on the signal bus, so it does not test delivery physics (once / broadcast / live, retries, dead-letter).`]}):null,t===`internal`?(0,X.jsxs)(`div`,{className:`mx-3 mt-2.5 rounded-md border border-border/60 bg-muted/20 px-3 py-2 text-[11px] leading-snug text-muted-foreground`,"data-slot":`call-only-bypass-copy`,role:`note`,children:[`This flow has no external trigger. Invoking here bypasses its normal caller (`,(0,X.jsx)(`code`,{className:`font-mono text-[10px]`,children:`fx.call`}),` /`,` `,(0,X.jsx)(`code`,{className:`font-mono text-[10px]`,children:`effects.calls`}),`). The body still matches `,(0,X.jsx)(`code`,{className:`font-mono text-[10px]`,children:`flow.in`}),`.`]}):null,t===`cdc`?(0,X.jsx)(`p`,{className:`px-3 pt-2.5 pb-2 text-[11px] leading-snug text-muted-foreground`,children:`Direct handler invoke — not a Store CDC event.`}):null,f.length>0?(0,X.jsxs)(`section`,{className:`min-w-0`,"aria-label":`Path params`,"data-slot":`call-api-path`,children:[(0,X.jsx)(Ln,{title:`Path params`,hint:e.path??void 0}),f.map(e=>(0,X.jsx)(q,{label:e,className:`[&>span]:px-3`,children:(0,X.jsx)(a,{id:`path-${e}`,flat:!0,className:r(Ke,`px-3 font-mono`),placeholder:cn(e),value:x[e]??``,onChange:t=>S(n=>({...n,[e]:t.target.value}))})},e))]}):null,h.query.length>0?(0,X.jsxs)(`section`,{className:`min-w-0`,"aria-label":`Query params`,"data-slot":`call-api-query`,children:[(0,X.jsx)(Ln,{title:`Query params`,hint:`seeded from schema`}),(0,X.jsx)(Je,{children:h.query.map(e=>(0,X.jsx)(Rn,{field:e,idPrefix:`query`,value:E[e.name],onChange:t=>D(n=>({...n,[e.name]:t})),error:ee.find(t=>t.path===`/${e.name}`||t.path===e.path),wide:e.type===`object`||e.type===`array`,manifest:n},e.path))})]}):null,g?(0,X.jsxs)(`section`,{className:`min-w-0`,"aria-label":`Body`,"data-slot":`call-api-body`,children:[(0,X.jsx)(Ln,{title:`Body`,hint:A===`raw`?`raw JSON`:`seeded from schema`}),A===`raw`?(0,X.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,X.jsx)(`textarea`,{"data-slot":`call-api-body-raw`,"aria-label":`Raw JSON body`,spellCheck:!1,value:M,onChange:e=>{N(e.target.value),P&&F(null)},className:r(`min-h-40 w-full resize-y rounded-none border-0 bg-transparent px-3 py-2 font-mono text-xs leading-relaxed text-foreground outline-none`,`placeholder:text-muted-foreground focus-visible:bg-muted/20`,P&&`text-destructive`)}),P?(0,X.jsx)(`p`,{role:`alert`,className:`px-3 pb-2 text-xs text-destructive`,"data-slot":`call-api-raw-error`,children:P}):null]}):h.body.length===0?(0,X.jsx)(`p`,{className:`border-b border-border/50 px-3 py-2 text-xs text-muted-foreground`,children:`No body fields (empty object).`}):(0,X.jsx)(Je,{children:h.body.map(e=>(0,X.jsx)(Rn,{field:e,value:O[e.name],onChange:t=>k(n=>({...n,[e.name]:t})),error:ee.find(t=>t.path===`/${e.name}`||t.path===e.path),wide:e.type===`object`||e.type===`array`,manifest:n},e.path))})]}):null,ee.length>0?(0,X.jsx)(`p`,{role:`alert`,className:`px-3 py-2 text-xs text-destructive`,"data-slot":`call-api-validation`,children:`Fix contract errors before sending.`}):null]}),(0,X.jsx)(Dn,{failed:!!se,success:!!o.data&&!se,elapsed:te,handlerMs:o.data?.durationMs,statusCode:ce,errorMessage:o.isError?o.error.message:null,responseJson:oe,emptyHint:`Call to see a real host response.`,pathUsed:null,cache:o.data?.cache})]})})}function Dn({failed:e,success:t,elapsed:i,handlerMs:a,statusCode:o,errorMessage:s,responseJson:c,emptyHint:l,pathUsed:u,cache:d}){let[p,m]=(0,Y.useState)(!1),h=(0,X.jsx)(kn,{failed:e,success:t,elapsed:i,handlerMs:a,statusCode:o,pathUsed:u,cache:d});return(0,X.jsxs)(`section`,{className:`flex min-h-56 min-w-0 flex-1 flex-col overflow-hidden`,"aria-label":`Response`,"data-slot":`call-api-response-block`,children:[(0,X.jsxs)(`div`,{className:j,children:[(0,X.jsx)(`h4`,{className:r(V,`flex items-center px-2`),children:`Response`}),(0,X.jsxs)(`div`,{className:`ml-auto flex h-full items-stretch`,children:[h,c?(0,X.jsx)(Ue,{label:`Expand response`,className:`flex self-stretch`,children:(0,X.jsx)(`button`,{type:`button`,"aria-label":`Expand response`,"data-slot":`call-api-response-expand`,className:S,onClick:()=>m(!0),children:(0,X.jsx)(B,{icon:f,className:`size-3.5`,"aria-hidden":!0})})}):null]})]}),s?(0,X.jsx)(`p`,{role:`alert`,className:`px-2 py-2 text-sm text-destructive`,"data-slot":`call-api-error`,children:s}):null,c?(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 overflow-hidden`,"data-slot":`call-api-response-frame`,children:[(0,X.jsx)(`div`,{className:r(`w-1 shrink-0 self-stretch`,e?`bg-destructive`:`bg-emerald-500`),"aria-hidden":!0,"data-slot":`call-api-response-rail`}),(0,X.jsx)(rt,{json:c,dataSlot:`call-api-response`,className:`flex min-h-0 flex-1 overflow-auto`})]}):(0,X.jsx)(`p`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:l}),c?(0,X.jsx)(M,{open:p,onOpenChange:m,children:(0,X.jsxs)(te,{side:`right`,showCloseButton:!1,className:`gap-0 p-0 data-[side=right]:w-[min(48rem,calc(100vw-2rem))] data-[side=right]:sm:max-w-[min(48rem,calc(100vw-2rem))]`,"data-slot":`call-api-response-dialog`,children:[(0,X.jsxs)(P,{className:r(j,`flex-row gap-0 border-border/60 p-0`),children:[(0,X.jsx)(le,{className:r(V,`flex items-center px-2`),children:`Response`}),(0,X.jsx)(ae,{className:`sr-only`,children:`Full Call API response JSON`}),(0,X.jsxs)(`div`,{className:`ml-auto flex h-full items-stretch`,children:[h,(0,X.jsx)(On,{json:c}),(0,X.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,X.jsxs)(x,{"aria-label":`Close`,className:S,"data-slot":`call-api-response-close`,children:[(0,X.jsx)(B,{icon:n,className:`size-3.5`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,X.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,X.jsx)(`div`,{className:r(`w-1 shrink-0 self-stretch`,e?`bg-destructive`:`bg-emerald-500`),"aria-hidden":!0}),(0,X.jsx)(rt,{json:c,dataSlot:`call-api-response-expanded`,className:`flex min-h-0 flex-1 overflow-auto`})]})})]})}):null]})}function On({json:e}){let[t,n]=(0,Y.useState)(!1);return(0,X.jsx)(Ue,{label:t?`Copied`:`Copy response`,className:`flex self-stretch`,children:(0,X.jsx)(`button`,{type:`button`,"aria-label":t?`Copied`:`Copy response`,"data-slot":`call-api-response-copy`,className:S,onClick:()=>{navigator.clipboard&&navigator.clipboard.writeText(e).then(()=>{n(!0),window.setTimeout(()=>n(!1),1200)})},children:(0,X.jsx)(B,{icon:t?L:l,className:`size-3.5`,"aria-hidden":!0})})})}function kn({failed:e,success:t,elapsed:n,handlerMs:i,statusCode:a,pathUsed:o,cache:c}){let l=t||e,d=l?pn({handlerMs:i,rttMs:n}):null;return(0,X.jsxs)(X.Fragment,{children:[o?(0,X.jsxs)(`span`,{className:`flex h-full items-center px-2 font-mono text-[10px] text-muted-foreground`,"data-slot":`call-api-path-used`,"data-path":o,children:[`via `,o===`clock`?`clock.run-now`:`flows.invoke`]}):null,l?(0,X.jsxs)(`span`,{className:r(`inline-flex h-full items-center gap-1 px-2 font-mono text-[10px] font-semibold`,e?`text-destructive`:`text-emerald-700 dark:text-emerald-400`),"data-slot":`call-api-status`,"data-failed":e?`true`:`false`,children:[(0,X.jsx)(B,{icon:e?N:L,className:`size-3`,"aria-hidden":!0}),a??(e?`error`:`ok`)]}):null,l?(0,X.jsx)(`span`,{className:`flex h-full items-center px-2`,children:(0,X.jsx)(_t,{cache:c??`none`,dataSlot:`call-api-cache`})}):null,d?(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:e=>(0,X.jsx)(`span`,{...e,className:`flex h-full items-center px-2 font-mono text-[10px] tabular-nums text-muted-foreground`,"data-slot":`call-api-duration`,"data-kind":d.primaryKind,children:tt(d.primaryMs)})}),(0,X.jsx)(s,{side:`bottom`,className:`max-w-xs text-[11px]`,children:d.primaryKind===`handler`?`Handler time — same clock as Traces.`:`Browser round-trip. Handler time is on the Traces row.`})]}):null,d?.primaryKind===`handler`&&d.rttMs!==null?(0,X.jsxs)(`span`,{className:`flex h-full items-center px-2 font-mono text-[10px] tabular-nums text-muted-foreground/70`,"data-slot":`call-api-rtt`,title:`Browser round-trip`,children:[tt(d.rttMs),` rtt`]}):null]})}function An({title:e,actions:t,children:n,dataTrigger:i,dataMode:a}){return(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`call-api-panel`,"data-trigger":i,"data-mode":a,children:[(0,X.jsxs)(`div`,{className:r(w,`min-w-0`),children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 px-2`,children:[(0,X.jsx)(B,{icon:pe,className:`size-3.5 text-muted-foreground`,"aria-hidden":!0}),(0,X.jsx)(`h3`,{className:r(V,`text-foreground`),children:e})]}),(0,X.jsx)(`div`,{className:`ml-auto flex h-full min-w-0 items-stretch`,children:t})]}),(0,X.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:n})]})}function jn({view:e,onChange:t}){return(0,X.jsxs)(`div`,{className:`flex h-full shrink-0 items-stretch`,role:`group`,"aria-label":`Body view`,"data-slot":`call-api-body-view-toggle`,children:[(0,X.jsx)(Mn,{active:e===`fields`,label:`Fields`,icon:i,onClick:()=>t(`fields`)}),(0,X.jsx)(Mn,{active:e===`raw`,label:`Raw`,icon:h,onClick:()=>t(`raw`)})]})}function Mn({active:e,label:t,icon:n,onClick:i}){return(0,X.jsxs)(`button`,{type:`button`,className:r(b,`font-semibold tracking-[0.08em] uppercase`,e?k:de),"aria-pressed":e,"aria-label":t,onClick:i,children:[(0,X.jsx)(B,{icon:n,className:`size-3`}),(0,X.jsx)(`span`,{className:`hidden sm:inline`,children:t})]})}var Nn=`h-full rounded-none border-0 bg-transparent px-2 text-[10px] font-semibold tracking-[0.08em] uppercase shadow-none hover:bg-muted/50`,Pn=`h-full rounded-none border-0 px-3 text-[10px] font-semibold tracking-[0.14em] uppercase shadow-none`;function Fn(){return(0,X.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0})}var In=`h-7 w-full justify-between rounded-none border-0 bg-transparent px-2 shadow-none focus-visible:border-0 focus-visible:ring-0 dark:bg-transparent dark:hover:bg-transparent`;function Ln({title:e,hint:t}){return(0,X.jsxs)(`div`,{className:j,children:[(0,X.jsx)(`h4`,{className:r(V,`flex items-center px-2`),children:e}),t?(0,X.jsx)(`span`,{className:`ml-auto flex items-center px-2 text-[10px] text-muted-foreground`,children:t}):null]})}function Rn({field:e,value:t,onChange:n,error:i,wide:o=!1,manifest:s,idPrefix:c=`body`}){let l=`${c}-${e.name}`,u=zn(e,s),d=[e.required?null:`optional`,u.lookup?`fk · ${u.lookup.child}.${u.lookup.column}`:e.type,u.lookup?null:zt(e)].filter(Boolean).join(` · `),f=i?(0,X.jsx)(`p`,{className:`px-3 pb-2 text-xs text-destructive`,children:i.message}):null,p=r(o&&`col-span-full border-r-0`);if(u.lookup){let r=t==null||t===``?``:String(t),i=Bn(u.options,r);return(0,X.jsxs)(q,{label:e.name,hint:d,dense:!0,className:p,children:[(0,X.jsxs)(W,{value:r||null,onValueChange:e=>{e==null||Array.isArray(e)||n(String(e))},children:[(0,X.jsx)(be,{id:l,className:In,disabled:u.isLoading,children:(0,X.jsx)(G,{placeholder:u.isLoading?`Loading…`:`Select…`})}),(0,X.jsx)(U,{children:i.map(e=>(0,X.jsx)(H,{value:e.value,children:e.label},e.value))})]}),f]})}if(e.type===`enum`&&e.enumValues)return(0,X.jsxs)(q,{label:e.name,hint:d,dense:!0,className:p,children:[(0,X.jsxs)(W,{value:String(t??``),onValueChange:e=>{e==null||Array.isArray(e)||n(String(e))},children:[(0,X.jsx)(be,{id:l,className:In,children:(0,X.jsx)(G,{})}),(0,X.jsx)(U,{children:e.enumValues.map(e=>(0,X.jsx)(H,{value:e,children:e},e))})]}),f]});if(e.type===`boolean`)return(0,X.jsx)(q,{label:e.name,hint:d,dense:!0,className:p,children:(0,X.jsxs)(W,{value:t===!0?`true`:`false`,onValueChange:e=>{e==null||Array.isArray(e)||n(String(e)===`true`)},children:[(0,X.jsx)(be,{id:l,className:In,children:(0,X.jsx)(G,{})}),(0,X.jsxs)(U,{children:[(0,X.jsx)(H,{value:`true`,children:`true`}),(0,X.jsx)(H,{value:`false`,children:`false`})]})]})});if(e.type===`integer`||e.type===`number`){let i=Ut(e);if(i){let r=typeof t==`number`?String(t):``;return(0,X.jsxs)(q,{label:e.name,hint:d,dense:!0,className:p,children:[(0,X.jsxs)(W,{value:r||null,onValueChange:e=>{e==null||Array.isArray(e)||n(Number(e))},children:[(0,X.jsx)(be,{id:l,className:In,children:(0,X.jsx)(G,{placeholder:`Select…`})}),(0,X.jsx)(U,{children:i.map(t=>{let n=e.valueMeanings?.find(e=>e.value===String(t));return(0,X.jsx)(H,{value:String(t),children:n?`${t} · ${n.label}`:t},t)})})]}),f]})}return(0,X.jsxs)(q,{label:e.name,hint:d,dense:!0,className:p,children:[(0,X.jsx)(a,{id:l,type:`number`,flat:!0,className:r(Ke,`h-7 px-2 font-mono`),min:e.minimum,max:e.maximum,step:e.type===`integer`?1:void 0,value:typeof t==`number`?t:``,onChange:t=>{if(t.target.value===``){n(void 0);return}n(Vn(Number(t.target.value),e.minimum,e.maximum))}}),f]})}return(0,X.jsxs)(q,{label:e.name,hint:d,dense:!0,className:p,children:[(0,X.jsx)(a,{id:l,flat:!0,className:r(Ke,`h-7 px-2 font-mono`),value:typeof t==`string`?t:t==null?``:String(t),onChange:e=>n(e.target.value)}),f]})}function zn(e,t){let n=(0,Y.useMemo)(()=>qt(e,t),[e,t]),r=ke(n?{ref:n.ref,child:n.child,limit:200}:null,n!==null);return{lookup:n,options:(0,Y.useMemo)(()=>Jt(r.data?.rows??[],n),[r.data?.rows,n]),isLoading:r.isFetching}}function Bn(e,t){return!t||e.some(e=>e.value===t)?e:[{value:t,label:t},...e]}function Vn(e,t,n){let r=e;return t!==void 0&&r<t&&(r=t),n!==void 0&&r>n&&(r=n),r}function Q({title:e,meta:t,ruled:n=!0}){return(0,X.jsxs)(`div`,{className:r(`flex items-baseline justify-between gap-2`,n&&`border-b border-border/60 pb-1.5`),children:[(0,X.jsx)(`h3`,{className:V,children:e}),t?(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:t}):null]})}function Hn({method:e,className:t}){return(0,X.jsx)(vt,{variant:`outline`,className:r(`h-5 px-1.5 font-mono text-[10px] uppercase`,Qe(e),t),"data-slot":`http-method-badge`,children:e})}var Un=[`once`,`broadcast`,`live`],Wn={once:{delivery:`once`,icon:se,label:`once`,title:`once — one consumer claims; retries + DLQ`,wellClass:`border-amber-500/35 bg-amber-500/10 text-amber-700 dark:text-amber-400`,badgeClass:`border-amber-500/35 bg-amber-500/15 text-amber-800 dark:text-amber-400`},broadcast:{delivery:`broadcast`,icon:ne,label:`broadcast`,title:`broadcast — every subscriber gets a copy`,wellClass:`border-sky-500/35 bg-sky-500/10 text-sky-700 dark:text-sky-400`,badgeClass:`border-sky-500/35 bg-sky-500/15 text-sky-700 dark:text-sky-400`},live:{delivery:`live`,icon:o,label:`live`,title:`live — retained feed; late subscribers replay history`,wellClass:`border-emerald-500/35 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,badgeClass:`border-emerald-500/35 bg-emerald-500/15 text-emerald-700 dark:text-emerald-400`}};function Gn({delivery:e,className:t}){let n=Wn[e];return(0,X.jsx)(vt,{variant:`outline`,title:n.title,className:r(`h-5 px-1.5 font-mono text-[10px]`,n.badgeClass,t),"data-slot":`signal-delivery-badge`,"data-delivery":e,children:n.label})}function Kn({effects:e}){let t=qn(e);return t.length===0?null:(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"data-slot":`effects-summary`,"aria-label":`Effects`,children:[(0,X.jsx)(Q,{title:`Effects`,meta:String(t.length)}),(0,X.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>{let t=dt(e.kind),n=at(e.kind,e.ref),r=e.kind===`call`?it(e.ref):null;return(0,X.jsxs)(`li`,{className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px]`,style:{borderColor:`${t}55`,color:t},title:r??`${ut[e.kind]} ${e.ref}`,children:[(0,X.jsx)(B,{icon:n,className:`size-3`}),r?(0,X.jsx)(`span`,{className:`text-foreground/90`,children:r}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:ut[e.kind]}),(0,X.jsx)(`span`,{className:`text-foreground/90`,children:e.ref})]})]},`${e.kind}:${e.ref}`)})})]})}function qn(e){if(!e)return[];let t=[],n=(e,n)=>{for(let r of n??[]){let n=typeof r==`string`?r:r.ref??String(r);t.push({kind:e,ref:n})}};return n(`read`,e.reads),n(`write`,e.writes),n(`emit`,e.emits),n(`send`,e.sends),n(`ask`,e.asks),n(`secret`,e.secrets),n(`call`,e.calls),t}function Jn({errors:e}){let t=Yn(e);return t.length===0?null:(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"data-slot":`errors-section`,"aria-label":`Flow errors`,children:[(0,X.jsx)(Q,{title:`Flow errors`,meta:String(t.length)}),(0,X.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>{let t=(e.schema?Z(e.schema):[]).map(e=>e.name).join(`, `);return(0,X.jsxs)(`li`,{className:`inline-flex items-center gap-1 rounded-md border border-destructive/25 bg-destructive/[0.04] px-1.5 py-0.5 font-mono text-[10px] text-destructive`,title:t?`{ code, data: { ${t} } }`:`Typed error — { code, data }`,"data-slot":`error-code`,"data-code":e.code,children:[(0,X.jsx)(B,{icon:N,className:`size-3`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`text-foreground/90`,children:e.code}),t?(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:t}):null]},e.code)})})]})}function Yn(e){return e?Array.isArray(e)?e.map(e=>({code:e,schema:null})):Object.entries(e).map(([e,t])=>({code:e,schema:Kt(t)})):[]}var Xn=36e5;function Zn(e,t,n,r=Xn){let i=ht(e,new Set([t])),a=n-r,o=i.filter(e=>e.startedAt>=a);if(o.length===0)return{kind:`empty`};let s=o.filter(e=>e.error!=null&&e.error.length>0).length,c=o[0];return{kind:`summary`,calls:o.length,errors:s,errorRate:s/o.length,lastStartedAt:c.startedAt,latestRunId:c.id,windowMs:r}}function Qn({flowId:e,runs:t,nowMs:n=Date.now(),windowMs:i=Xn,children:a}){let o=Zn(t??[],e,n,i);return(0,X.jsxs)(`div`,{className:r(j,`px-2`),"data-slot":`flow-activity-strip`,"data-kind":o.kind,"aria-label":`Recent activity`,children:[(0,X.jsx)(`span`,{className:r(V,`flex items-center`),children:`Activity`}),(0,X.jsx)($n,{summary:o,nowMs:n}),a?(0,X.jsx)(`div`,{className:`ml-auto flex h-full items-stretch`,children:a}):null]})}function $n({summary:e,nowMs:t}){if(e.kind===`empty`)return(0,X.jsx)(`p`,{className:`flex items-center text-[11px] text-muted-foreground`,"data-slot":`flow-activity-empty`,children:`No recent runs in the Console buffer.`});let n=Math.round(e.errorRate*100),i=er(e.lastStartedAt,t);return(0,X.jsxs)(`p`,{className:`flex min-w-0 items-center gap-x-2 text-[11px] text-foreground/85`,children:[(0,X.jsxs)(`span`,{className:`tabular-nums`,"data-slot":`flow-activity-calls`,children:[e.calls,` call`,e.calls===1?``:`s`]}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,"aria-hidden":!0,children:`·`}),(0,X.jsxs)(`span`,{className:`tabular-nums`,"data-slot":`flow-activity-errors`,children:[n,`% errors`]}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,"aria-hidden":!0,children:`·`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,"data-slot":`flow-activity-ago`,children:i}),(0,X.jsx)(ge,{to:`/overview`,search:{run:e.latestRunId},className:r(b,de),"data-slot":`flow-activity-open-run`,children:`Open latest`})]})}function er(e,t){let n=Math.max(0,t-e);return n<6e4?`${Math.max(1,Math.round(n/1e3))}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function tr(e){switch(e){case`string`:return`border-teal-500/35 bg-teal-500/10 text-teal-800 dark:text-teal-300`;case`integer`:return`border-blue-500/35 bg-blue-500/10 text-blue-800 dark:text-blue-300`;case`number`:return`border-amber-500/35 bg-amber-500/10 text-amber-800 dark:text-amber-300`;case`boolean`:return`border-violet-500/35 bg-violet-500/10 text-violet-800 dark:text-violet-300`;case`enum`:return`border-indigo-500/35 bg-indigo-500/10 text-indigo-800 dark:text-indigo-300`;case`array`:return`border-cyan-500/35 bg-cyan-500/10 text-cyan-800 dark:text-cyan-300`;case`object`:return`border-zinc-500/35 bg-zinc-500/10 text-zinc-700 dark:text-zinc-300`;default:return`border-border/70 bg-muted/40 text-muted-foreground`}}function nr({fields:e,emptyLabel:t=`No schema fields declared.`,layout:n=`list`}){return e.length===0?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-slot":`schema-fields-empty`,children:t}):n===`grid`?(0,X.jsx)(`div`,{"data-slot":`schema-fields`,"data-layout":`grid`,children:(0,X.jsx)(Je,{columns:3,children:e.map(e=>(0,X.jsx)(rr,{field:e,depth:0,cell:!0},e.path))})}):(0,X.jsx)(`ul`,{className:`flex flex-col`,"data-slot":`schema-fields`,children:e.map(e=>(0,X.jsx)(rr,{field:e,depth:0},e.path))})}function rr({field:e,depth:t,cell:n=!1}){let i=e.type===`enum`&&e.enumValues,a=zt(e);return(0,X.jsxs)(n?`div`:`li`,{className:n?`min-w-0 border-b border-border/50`:void 0,children:[(0,X.jsxs)(`div`,{className:n?`flex items-center gap-1.5 px-2 py-1.5`:`flex items-center gap-2 py-1`,style:n?void 0:{paddingLeft:t*14},"data-slot":`schema-field-row`,children:[(0,X.jsx)(`span`,{className:`shrink-0`,"data-slot":`schema-field-keys`,title:ir(e),children:(0,X.jsx)(Ct,{primaryKey:e.primaryKey,foreignKey:e.foreignKey,unique:e.unique,empty:`none`})}),(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[11px] font-medium text-foreground/90`,children:e.name}),e.required?null:(0,X.jsx)(`span`,{className:`shrink-0 rounded border border-border/60 bg-muted/30 px-1 py-px text-[9px] font-medium tracking-wide text-muted-foreground uppercase`,"data-slot":`schema-field-optional`,children:`optional`}),e.pii?(0,X.jsx)(`span`,{className:`shrink-0 rounded border border-amber-500/40 bg-amber-500/10 px-1 py-px text-[9px] font-medium tracking-wide text-amber-800 uppercase dark:text-amber-300`,"data-slot":`schema-field-pii`,children:`pii`}):null,e.sensitive?(0,X.jsx)(`span`,{className:`shrink-0 rounded border border-rose-500/40 bg-rose-500/10 px-1 py-px text-[9px] font-medium tracking-wide text-rose-700 uppercase dark:text-rose-300`,"data-slot":`schema-field-sensitive`,children:`sensitive`}):null,a&&!i?(0,X.jsx)(`span`,{className:`shrink-0 rounded border border-blue-500/35 bg-blue-500/10 px-1 py-px font-mono text-[9px] font-medium tracking-wide text-blue-800 dark:text-blue-300`,"data-slot":`schema-field-constraint`,title:`Allowed range ${a}`,children:a}):null,(0,X.jsx)(`span`,{className:r(`ml-auto shrink-0 rounded border px-1.5 py-px font-mono text-[9px] font-medium tracking-wide`,tr(e.type)),"data-slot":`schema-field-type`,title:i?e.enumValues?.join(` | `):e.type,children:e.type})]}),e.children?.map(e=>(0,X.jsx)(rr,{field:e,depth:t+1,cell:n},e.path))]})}function ir(e){let t=[];if(e.primaryKey&&t.push(`Primary key`),e.foreignKey){let n=e.references?[e.references.table,e.references.column].filter(Boolean).join(`.`):null;t.push(n?`Foreign key → ${n}`:`Foreign key`)}return e.unique&&t.push(`Unique`),t.length>0?t.join(` · `):`None`}function ar({fields:e}){let t=Vt(e);return t.length===0?null:(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"data-slot":`validation-section`,"aria-label":`Validation`,children:[(0,X.jsx)(Q,{title:`Validation`,meta:String(t.length)}),(0,X.jsx)(`ul`,{className:`flex flex-col gap-3`,children:t.map(e=>(0,X.jsx)(or,{field:e},e.path))})]})}function or({field:e}){let t=Bt(e),n=e.valueMeanings?.length?e.valueMeanings:e.enumValues?.map(e=>({value:e,label:e}));return(0,X.jsxs)(`li`,{className:`flex flex-col gap-1.5`,"data-slot":`validation-field`,"data-field":e.name,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`font-mono text-[11px] font-medium text-foreground/90`,children:e.name}),t?(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:t}):null]}),n&&n.length>0?(0,X.jsx)(`ul`,{className:`grid grid-cols-2 gap-x-4 gap-y-1 sm:grid-cols-3 lg:grid-cols-5`,children:n.map(e=>(0,X.jsxs)(`li`,{className:`flex min-w-0 items-baseline gap-1.5 font-mono text-[11px]`,"data-slot":`validation-option`,children:[(0,X.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:e.value}),(0,X.jsx)(`span`,{className:`truncate text-foreground/90`,children:e.label})]},e.value))}):null]})}function sr({row:e,manifest:t,runs:n,leading:i}){let a=J(e.flow.trigger),o=lt(e.flow.trigger),s=ft(t,e.id,a===`http`?`http`:a===`internal`?`internal`:a),c=Kt(e.flow.in),l=Kt(e.flow.out),u=pt(e.flow.gates??[],t),d=a===`signal`&&e.flow.trigger?.signal?t?.signals?.[e.flow.trigger.signal]:void 0,f=a===`cron`||a===`every`?fn(t,e.id):null,p=a===`internal`?gt(t,e.id):[],m=a===`http`?`Request`:`Input`,h=a===`http`?`Response`:`Output`,g=a!==`cron`&&a!==`every`,_=Z(c),v=Z(l),y=At(_,a===`http`&&e.path?sn(e.path):[]);return(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`flow-contract-panel`,"data-trigger":a,children:[(0,X.jsx)(qe,{dataSlot:`endpoint-header`,leading:i,icon:(0,X.jsx)(`span`,{"data-slot":`trigger-kind-icon`,"data-kind":a,children:(0,X.jsx)(B,{icon:o.icon,className:`size-4`})}),wellClassName:o.wellClass,title:(0,X.jsx)(`span`,{className:`font-mono`,children:e.id}),badge:(0,X.jsx)(`span`,{className:`font-mono text-[10px] font-medium tracking-[0.08em] text-muted-foreground uppercase`,"data-slot":`trigger-kind-badge`,children:o.label}),subtitle:a===`http`&&s.method&&s.path?(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,"data-slot":`http-endpoint-line`,children:[(0,X.jsx)(Hn,{method:s.method}),(0,X.jsx)(`code`,{className:`min-w-0 truncate font-mono text-[11px] leading-none text-muted-foreground select-all`,children:s.path})]}):a===`signal`&&d?(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,"data-slot":`signal-endpoint-line`,children:[(0,X.jsx)(Gn,{delivery:d.delivery}),(0,X.jsx)(`code`,{className:`min-w-0 truncate font-mono text-[11px] leading-none text-muted-foreground select-all`,children:e.flow.trigger?.signal})]}):(0,X.jsx)(`span`,{className:`truncate font-mono text-[11px] leading-none text-muted-foreground`,"data-slot":`trigger-headline`,children:s.headline}),actions:(0,X.jsxs)(ge,{to:`/overview`,search:{flow:e.id},"data-slot":`open-in-graph`,className:r(b,`text-sky-700 dark:text-sky-400`),children:[(0,X.jsx)(B,{icon:We.flow.icon,className:`size-3.5`,"aria-hidden":!0}),`Open in graph`]})}),(0,X.jsxs)(Qn,{flowId:e.id,runs:n,children:[e.flow.plane?(0,X.jsx)(cr,{plane:e.flow.plane}):null,e.flow.durable?(0,X.jsx)(lr,{icon:re,label:`durable`,title:`Durable — long-running, retryable steps`}):null,e.flow.live?(0,X.jsx)(lr,{icon:C,label:`live`,title:typeof e.flow.live==`string`?`Live — SSE for ${e.flow.live}`:`Live — SSE signal feed`}):null]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3 py-3`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsx)(Kn,{effects:e.flow.effects}),(0,X.jsx)(ct,{gates:u}),(0,X.jsx)(Jn,{errors:e.flow.errors}),a===`signal`&&d&&(d.retries!==void 0||d.deadLetter)?(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,"data-slot":`signal-delivery`,children:[d.retries===void 0?null:`retries ${d.retries}`,d.deadLetter?`dead-letter`:null].filter(e=>e!==null).join(` · `)}):null,(a===`cron`||a===`every`)&&f?.kind===`matched`?(0,X.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,"data-slot":`clock-join`,children:[`Clock · `,(0,X.jsx)(`span`,{className:`font-mono`,children:f.clockName}),f.timezone?` · ${f.timezone}`:``]}):null,a===`internal`?(0,X.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,"data-slot":`call-only-note`,children:[`No external trigger — reachable via `,(0,X.jsx)(`code`,{className:`font-mono`,children:`effects.calls`}),` /`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`fx.call`}),`.`]}):null,a===`internal`?(0,X.jsxs)(`section`,{className:`flex flex-col gap-1.5`,"aria-label":`Callers`,"data-slot":`callers-list`,children:[(0,X.jsx)(Q,{title:`Called by`,meta:String(p.length)}),p.length===0?(0,X.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`No Manifest caller declares `,(0,X.jsx)(`code`,{className:`font-mono`,children:`effects.calls`}),` for this flow.`]}):(0,X.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:p.map(e=>(0,X.jsx)(`li`,{className:`font-mono text-xs text-foreground/90`,children:e},e))})]}):null,g&&y.parameters.length>0?(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"aria-label":`Parameters`,"data-slot":`parameters`,children:[(0,X.jsx)(Q,{title:`Parameters`,meta:String(y.parameters.length)}),(0,X.jsx)(nr,{fields:y.parameters,layout:`grid`})]}):null,(0,X.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[g&&(y.fields.length>0||y.parameters.length===0)?(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"aria-label":m,"data-slot":`request`,children:[(0,X.jsx)(Q,{title:m,meta:String(y.fields.length)}),(0,X.jsx)(nr,{fields:y.fields,emptyLabel:typeof e.flow.in==`string`?`Schema not expanded in Manifest.`:a===`signal`?`No flow input schema — signal payload shape lives on the signal when declared.`:`No input schema declared.`})]}):null,(0,X.jsxs)(`section`,{className:`flex flex-col gap-2`,"aria-label":h,children:[(0,X.jsx)(Q,{title:h,meta:String(v.length)}),(0,X.jsx)(nr,{fields:v,emptyLabel:typeof e.flow.out==`string`?`Schema not expanded in Manifest.`:`No output schema declared.`})]})]}),g?(0,X.jsx)(ar,{fields:_}):null]})})]})}function cr({plane:e}){let t=e===`operator`,n=t?v:T,i=t?`operator`:`user`;return(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:t=>(0,X.jsxs)(`span`,{...t,className:r(b,`cursor-help`),"data-slot":`plane-badge`,"data-plane":e,children:[(0,X.jsx)(B,{icon:n,className:`size-3`,"aria-hidden":!0}),i]})}),(0,X.jsx)(s,{side:`bottom`,className:`max-w-xs text-[11px]`,children:t?`Operator plane — runs under a Console operator identity, not an application user.`:`User plane — runs under an application user identity (invoke-as).`})]})}function lr({icon:e,label:t,title:n}){return(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:n=>(0,X.jsxs)(`span`,{...n,className:r(b,de,`cursor-help`),children:[(0,X.jsx)(B,{icon:e,className:`size-3`,"aria-hidden":!0}),t]})}),(0,X.jsx)(s,{side:`bottom`,className:`max-w-xs text-[11px]`,children:n})]})}function ur(e){let t=new Map(ot.map(e=>[e,[]]));for(let n of e){let e=new Map;for(let t of n.flows){let n=J(t.flow.trigger),r=e.get(n)??[];r.push(t),e.set(n,r)}for(let[r,i]of e)t.get(r)?.push({unit:n.unit,flows:i})}return ot.flatMap(e=>{let n=t.get(e)??[];return n.length===0?[]:[{id:e,label:st[e].label,groups:n}]})}function dr(e){return`band:${e}`}function fr(e,t){return`unit:${e}:${t}`}function pr(e,t,n=!1){let r=t[e];return r===void 0?n:r}function mr(e){let t=[];for(let n of e){t.push(dr(n.id));for(let e of n.groups)t.push(fr(n.id,e.unit))}return t}function hr(e,t){for(let n of e)for(let e of n.groups)if(e.flows.some(e=>e.id===t))return[dr(n.id),fr(n.id,e.unit)];return[]}function gr(e,t){let n=Ye(e.method)-Ye(t.method);return n===0?e.id.localeCompare(t.id):n}function _r(e){let t=e?.flows;if(!t)return[];let n=new Map;for(let[r,i]of Object.entries(t)){let t=mt(r),a=r.includes(`.`)?r.slice(r.indexOf(`.`)+1):r,o=i.trigger?.http,s=i.trigger?.signal??null,c={id:r,unit:t,action:a,flow:i,method:o?.method??null,path:o?.path??null,signal:s,delivery:s?e.signals?.[s]?.delivery??null:null},l=n.get(t)??[];l.push(c),n.set(t,l)}return[...n.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({unit:e,flows:t.sort(gr)}))}function vr(e,t){let n=t.trim().toLowerCase();return n?e.map(e=>{let t=e.unit.toLowerCase().includes(n)?e.flows:e.flows.filter(e=>e.id.toLowerCase().includes(n)||e.action.toLowerCase().includes(n)||(e.method?.toLowerCase().includes(n)??!1)||(e.path?.toLowerCase().includes(n)??!1)||(e.signal?.toLowerCase().includes(n)??!1)||(e.delivery?.toLowerCase().includes(n)??!1));return t.length>0?{unit:e.unit,flows:t}:null}).filter(e=>e!==null):e}function yr(e){return(e.triggerKinds?.length??0)+(e.planes?.length??0)+(e.deliveries?.length??0)+ +!!e.durableOnly+ +!!e.liveOnly}function br(e,t){let n=t.triggerKinds?.length?new Set(t.triggerKinds):null,r=t.planes?.length?new Set(t.planes):null,i=t.deliveries?.length?new Set(t.deliveries):null,a=t.durableOnly===!0,o=t.liveOnly===!0;return!n&&!r&&!i&&!a&&!o?e:e.map(e=>{let t=e.flows.filter(e=>!(n&&!n.has(J(e.flow.trigger))||r&&!r.has(e.flow.plane??`user`)||i&&(e.delivery===null||!i.has(e.delivery))||a&&!e.flow.durable||o&&!e.flow.live));return t.length>0?{unit:e.unit,flows:t}:null}).filter(e=>e!==null)}var xr={user:{icon:T,label:`user`},operator:{icon:v,label:`operator`}},Sr=[`user`,`operator`];function Cr({groups:e,selectedFlowId:t,onSelect:n}){let[i,a]=(0,Y.useState)(``),[o,c]=(0,Y.useState)(!1),[l,d]=(0,Y.useState)({}),[f,p]=(0,Y.useState)({}),h=(0,Y.useMemo)(()=>{let t=new Set;for(let n of e)for(let e of n.flows)t.add(J(e.flow.trigger));return ot.filter(e=>t.has(e))},[e]),g=(0,Y.useMemo)(()=>{let t=new Set;for(let n of e)for(let e of n.flows)e.flow.plane&&t.add(e.flow.plane);return Sr.filter(e=>t.has(e))},[e]),{hasDurable:_,hasLive:v,availableDeliveries:y}=(0,Y.useMemo)(()=>{let t=!1,n=!1,r=new Set;for(let i of e)for(let e of i.flows)e.flow.durable&&(t=!0),e.flow.live&&(n=!0),e.delivery&&r.add(e.delivery);return{hasDurable:t,hasLive:n,availableDeliveries:Un.filter(e=>r.has(e))}},[e]),b=yr(l),x=(0,Y.useMemo)(()=>ur(br(vr(e,i),l)),[e,i,l]),T=(0,Y.useMemo)(()=>mr(x),[x]),E=i.trim().length>0,D=T.length>0&&T.every(e=>pr(e,f,E));(0,Y.useEffect)(()=>{if(!t)return;let e=hr(x,t);e.length!==0&&p(t=>{let n=!1,r={...t};for(let t of e)r[t]!==!0&&(r[t]=!0,n=!0);return n?r:t})},[t,x]);let O=(e,t)=>{p(n=>n[e]===t?n:{...n,[e]:t})},k=()=>{let e=!D;p(t=>{let n={...t};for(let t of T)n[t]=e;return n})},A=e=>d(t=>({...t,triggerKinds:Tr(t.triggerKinds??[],e)})),j=e=>d(t=>({...t,planes:Tr(t.planes??[],e)})),M=e=>d(t=>({...t,[e]:!t[e]})),N=e=>d(t=>({...t,deliveries:Tr(t.deliveries??[],e)}));return(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`units-tree`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 border-b border-border/60`,children:[(0,X.jsxs)(`div`,{className:r(w,`border-b-0`),children:[(0,X.jsx)(ze,{value:i,onChange:e=>a(e.target.value),placeholder:`Search flows…`,"aria-label":`Search flows`,"data-slot":`units-search`}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-stretch pr-0.5`,children:[(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:e=>(0,X.jsxs)(`button`,{...e,type:`button`,"aria-expanded":o,"aria-controls":`units-advanced-panel`,"aria-label":b>0?`Advanced filters, ${b} active`:`Advanced filters`,"data-slot":`units-advanced-toggle`,onClick:t=>{e.onClick?.(t),c(e=>!e)},className:r(S,`relative`,(o||b>0)&&`text-foreground`),children:[(0,X.jsx)(B,{icon:F,className:`size-3`,"aria-hidden":!0}),b>0?(0,X.jsx)(`span`,{"data-slot":`units-advanced-count`,className:`absolute -top-0.5 -inset-e-0.5 flex size-3.5 items-center justify-center rounded-full bg-foreground text-[8px] font-medium text-background`,"aria-hidden":!0,children:b}):null]})}),(0,X.jsx)(s,{side:`bottom`,children:`Advanced`})]}),(0,X.jsx)(Pe,{allOpen:D,disabled:T.length===0,onToggle:k,dataSlot:`units-tree-expand-toggle`})]})]}),o?(0,X.jsxs)(`div`,{id:`units-advanced-panel`,"data-slot":`units-advanced-panel`,className:`flex flex-col gap-2 border-t border-border/60 bg-muted/20 p-2`,children:[(0,X.jsx)(wr,{label:`Trigger`,groupLabel:`Trigger kind filter`,children:h.map(e=>{let t=st[e];return(0,X.jsx)($,{icon:t.icon,label:t.label,pressed:l.triggerKinds?.includes(e)??!1,onToggle:()=>A(e),dataFacet:`kind:${e}`},e)})}),y.length>0?(0,X.jsx)(wr,{label:`Delivery`,groupLabel:`Signal delivery filter`,children:y.map(e=>{let t=Wn[e];return(0,X.jsx)($,{icon:t.icon,label:t.label,pressed:l.deliveries?.includes(e)??!1,onToggle:()=>N(e),dataFacet:`delivery:${e}`},e)})}):null,g.length>0?(0,X.jsx)(wr,{label:`Plane`,groupLabel:`Plane filter`,children:g.map(e=>{let t=xr[e];return(0,X.jsx)($,{icon:t.icon,label:t.label,pressed:l.planes?.includes(e)??!1,onToggle:()=>j(e),dataFacet:`plane:${e}`},e)})}):null,_||v?(0,X.jsxs)(wr,{label:`Flags`,groupLabel:`Flow flags filter`,children:[_?(0,X.jsx)($,{icon:re,label:`durable`,pressed:l.durableOnly??!1,onToggle:()=>M(`durableOnly`),dataFacet:`flag:durable`}):null,v?(0,X.jsx)($,{icon:C,label:`live`,pressed:l.liveOnly??!1,onToggle:()=>M(`liveOnly`),dataFacet:`flag:live`}):null]}):null,b>0?(0,X.jsx)(`button`,{type:`button`,"data-slot":`units-advanced-clear`,onClick:()=>d({}),className:`self-end px-2 py-1 text-[10px] font-medium text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground`,children:`Clear all`}):null]}):null]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-x-hidden overflow-y-auto`,children:x.length===0?(0,X.jsx)(`p`,{className:oe,children:`No flows match.`}):(0,X.jsx)(`div`,{className:`flex flex-col`,children:x.map(e=>{let r=dr(e.id);return(0,X.jsx)(Er,{band:e,open:pr(r,f,E),onOpenChange:e=>O(r,e),groupOpen:t=>pr(fr(e.id,t),f,E),onGroupOpenChange:(t,n)=>O(fr(e.id,t),n),selectedFlowId:t,onSelect:n},e.id)})})})]})}function wr({label:e,groupLabel:t,children:n}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`w-14 shrink-0 text-[9px] font-semibold tracking-[0.08em] text-muted-foreground uppercase`,children:e}),(0,X.jsx)(`div`,{className:`flex min-h-7 flex-wrap items-stretch`,role:`group`,"aria-label":t,children:n})]})}function $({icon:e,label:t,pressed:n,onToggle:i,dataFacet:a}){return(0,X.jsxs)(`button`,{type:`button`,"data-slot":`units-facet-chip`,"data-facet":a,"aria-pressed":n,onClick:i,className:r(`inline-flex items-center gap-1 px-2 text-[10px] font-medium transition-colors hover:bg-muted/50`,n?`text-foreground`:`text-muted-foreground hover:text-foreground`),children:[(0,X.jsx)(B,{icon:e,className:`size-3`,"aria-hidden":!0}),t]})}function Tr(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function Er({band:e,open:n,onOpenChange:i,groupOpen:a,onGroupOpenChange:o,selectedFlowId:s,onSelect:c}){let l=st[e.id],u=e.groups.reduce((e,t)=>e+t.flows.length,0),f=e.groups.map(e=>e.unit),p=f.length>0&&f.every(e=>a(e)),m=()=>{let e=!p;for(let t of f)o(t,e);e&&i(!0)};return(0,X.jsx)(`section`,{"data-slot":`units-trigger-band`,"data-band":e.id,"aria-label":e.label,className:g,children:(0,X.jsxs)(xt,{open:n,onOpenChange:i,children:[(0,X.jsx)(bt,{nativeButton:!1,className:t,"data-slot":`units-trigger-band-toggle`,render:t=>(0,X.jsxs)(`div`,{...t,children:[(0,X.jsx)(B,{icon:d,className:r(ce,!n&&`-rotate-90`),"aria-hidden":!0}),(0,X.jsx)(B,{icon:l.icon,className:r(z,_(l.wellClass)),"aria-hidden":!0}),(0,X.jsx)(`span`,{className:r(O,`flex-1`),children:e.label}),(0,X.jsx)(`span`,{className:R,children:u}),(0,X.jsx)(`span`,{className:y,children:(0,X.jsx)(Pe,{allOpen:p,disabled:f.length===0,onToggle:m,collapseLabel:`Collapse all in ${e.label}`,expandLabel:`Expand all in ${e.label}`,dataSlot:`units-band-expand-toggle`,disclose:!0,bare:!0})})]})}),(0,X.jsx)(yt,{children:(0,X.jsx)(`ul`,{className:`flex flex-col`,children:e.groups.map(t=>(0,X.jsx)(Dr,{group:t,open:a(t.unit),onOpenChange:e=>o(t.unit,e),selectedFlowId:s,onSelect:c},`${e.id}:${t.unit}`))})})]})})}function Dr({group:e,open:t,onOpenChange:n,selectedFlowId:i,onSelect:a}){return(0,X.jsx)(`li`,{"data-slot":`unit-group`,"data-unit":e.unit,children:(0,X.jsxs)(xt,{open:t,onOpenChange:n,children:[(0,X.jsxs)(bt,{className:r(ie,`pl-4`),children:[(0,X.jsx)(B,{icon:d,className:r(ce,!t&&`-rotate-90`),"aria-hidden":!0}),(0,X.jsx)(B,{icon:A,className:r(z,`text-muted-foreground`),"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:e.unit}),(0,X.jsx)(`span`,{className:R,children:e.flows.length})]}),(0,X.jsx)(yt,{children:(0,X.jsx)(`ul`,{className:`flex flex-col`,children:e.flows.map(e=>(0,X.jsx)(Or,{flow:e,selected:i===e.id,onSelect:a},e.id))})})]})})}function Or({flow:e,selected:t,onSelect:n}){let i=lt(e.flow.trigger),a=e.delivery?Wn[e.delivery]:null,o=a?.icon??(e.method?Ze(e.method):i.icon),c=_(a?.wellClass??(e.method?Qe(e.method):i.wellClass)),l=a?e.signal?`${a.title} · ${e.signal}`:a.title:i.detail?`${i.label} · ${i.detail}`:i.label;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,"data-slot":`unit-flow-item`,"data-flow-id":e.id,"data-delivery":e.delivery??void 0,"aria-current":t?`true`:void 0,onClick:()=>n(e.id),className:r(D,`group/flow pl-8`,t&&`bg-muted/70 text-foreground`),children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:r(ue,t?ee:`bg-transparent`)}),(0,X.jsxs)(m,{children:[(0,X.jsx)(u,{render:e=>(0,X.jsx)(`span`,{...e,className:r(z,c),"aria-hidden":!0,children:(0,X.jsx)(B,{icon:o,className:`size-3.5`})})}),(0,X.jsx)(s,{side:`right`,className:`text-[11px]`,children:l})]}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:e.action}),e.method?(0,X.jsx)(Hn,{method:e.method,className:`ml-auto h-3.5 px-1 text-[8px] leading-none`}):null]})})}function kr(){let e=et(),t=nt();$e(!0);let{selectedFlowId:n,setSelectedFlow:r}=Le(),i=Be(),a=(0,Y.useMemo)(()=>_r(e.data??null),[e.data]),o=(0,X.jsx)(Ve,{open:i.open,onToggle:i.toggle,noun:`flows`,controlsId:`flows-tree`,dataSlot:`flows-tree-toggle`}),s=n??a[0]?.flows[0]?.id??null,c=(0,Y.useMemo)(()=>{if(!s)return null;for(let e of a){let t=e.flows.find(e=>e.id===s);if(t)return t}return null},[a,s]);return(0,X.jsx)(`div`,{className:E,"data-slot":`units-page`,children:(0,X.jsxs)(Re,{orientation:`horizontal`,className:`min-h-0 flex-1`,children:[(0,X.jsx)(K,{panelRef:i.panelRef,collapsible:!0,collapsedSize:0,defaultSize:I.start.defaultSize,minSize:I.start.minSize,onResize:i.onResize,className:`min-h-0 overflow-hidden`,children:(0,X.jsx)(`div`,{id:`flows-tree`,className:`h-full min-h-0 overflow-hidden`,"data-slot":`flows-tree`,children:(0,X.jsx)(Cr,{groups:a,selectedFlowId:s,onSelect:e=>{r(e)}})})}),i.open?(0,X.jsx)(He,{withHandle:!0}):null,(0,X.jsx)(K,{defaultSize:I.end.defaultSize,minSize:I.end.minSize,className:`min-h-0 overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full min-h-0 overflow-hidden`,children:c?(0,X.jsxs)(Re,{orientation:`vertical`,className:`min-h-0 flex-1`,"data-slot":`units-inspector`,children:[(0,X.jsx)(K,{defaultSize:`56%`,minSize:`28%`,className:`min-h-0 overflow-hidden`,children:(0,X.jsx)(sr,{row:c,manifest:e.data??null,runs:t.data,leading:o})}),(0,X.jsx)(He,{withHandle:!0}),(0,X.jsx)(K,{defaultSize:`44%`,minSize:`220px`,className:`min-h-0 overflow-hidden`,children:(0,X.jsx)(wn,{row:c,manifest:e.data??null})})]}):(0,X.jsx)(Ge,{icon:We.flow.icon,title:e.isLoading?`Loading Manifest…`:`Select a flow`,description:e.isLoading?`Reading the derived Manifest.`:`Pick a flow from the tree to inspect its contract.`,leading:o})})})]})})}export{kr as UnitsPage};