@engenty/wizards-runtime 0.17.0 → 0.17.1

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 (128) hide show
  1. package/apps/runtime/dist/app.js +2 -0
  2. package/apps/runtime/dist/broker/account.js +20 -1
  3. package/apps/runtime/dist/broker/call.js +116 -20
  4. package/apps/runtime/dist/broker/host.js +8 -2
  5. package/apps/runtime/dist/broker/index.js +3 -2
  6. package/apps/runtime/dist/broker/log.js +149 -14
  7. package/apps/runtime/dist/broker/over.js +38 -0
  8. package/apps/runtime/dist/broker/rights.js +192 -0
  9. package/apps/runtime/dist/broker/rwx.js +295 -51
  10. package/apps/runtime/dist/broker/send.js +25 -12
  11. package/apps/runtime/dist/bundles/fetch.js +119 -0
  12. package/apps/runtime/dist/bundles/index.js +621 -0
  13. package/apps/runtime/dist/bundles/read.js +607 -0
  14. package/apps/runtime/dist/connectors/external.js +532 -61
  15. package/apps/runtime/dist/connectors/person-sign-ins.js +1 -0
  16. package/apps/runtime/dist/connectors/reload.js +73 -0
  17. package/apps/runtime/dist/connectors/space-connections.js +73 -6
  18. package/apps/runtime/dist/db/migrations/tenant/0058_mcp_state_across_roles.sql +26 -0
  19. package/apps/runtime/dist/db/migrations/tenant/0059_space_connection_paused.sql +2 -0
  20. package/apps/runtime/dist/db/migrations/tenant/0060_space_bundle.sql +21 -0
  21. package/apps/runtime/dist/db/migrations/tenant/0061_space_connection_limits.sql +2 -0
  22. package/apps/runtime/dist/db/migrations/tenant/meta/0058_snapshot.json +6696 -0
  23. package/apps/runtime/dist/db/migrations/tenant/meta/0059_snapshot.json +6710 -0
  24. package/apps/runtime/dist/db/migrations/tenant/meta/0060_snapshot.json +6857 -0
  25. package/apps/runtime/dist/db/migrations/tenant/meta/0061_snapshot.json +6871 -0
  26. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +28 -0
  27. package/apps/runtime/dist/db/schema.js +81 -3
  28. package/apps/runtime/dist/docs/dev/broker.md +251 -31
  29. package/apps/runtime/dist/docs/user-guide/capabilities.md +123 -5
  30. package/apps/runtime/dist/docs/user-guide/connectors.md +52 -5
  31. package/apps/runtime/dist/docs/user-guide/protocol.md +15 -4
  32. package/apps/runtime/dist/docs/user-guide/test-and-share.md +1 -1
  33. package/apps/runtime/dist/elements/caller.js +2 -2
  34. package/apps/runtime/dist/engenty/connections-external/build-connector.js +23 -8
  35. package/apps/runtime/dist/engenty/connections-external/import-service.js +18 -9
  36. package/apps/runtime/dist/engenty/connections-external/importer/classify.js +12 -0
  37. package/apps/runtime/dist/engenty/connections-external/invoke/http-invoker.js +1 -0
  38. package/apps/runtime/dist/engenty/connections-external/net/guarded-fetch.js +6 -3
  39. package/apps/runtime/dist/engenty/connections-sdk/oauth2.js +2 -2
  40. package/apps/runtime/dist/engenty/shims/web-ingest.js +64 -0
  41. package/apps/runtime/dist/engine/resources.js +15 -6
  42. package/apps/runtime/dist/engine/runner.js +2 -1
  43. package/apps/runtime/dist/env.js +2 -0
  44. package/apps/runtime/dist/index.js +11 -2
  45. package/apps/runtime/dist/mcp/handler.js +2 -2
  46. package/apps/runtime/dist/mcp/seen.js +71 -51
  47. package/apps/runtime/dist/mcp/tools.js +5 -1
  48. package/apps/runtime/dist/prompts/mcp.md +1 -1
  49. package/apps/runtime/dist/prompts/tools.md +16 -0
  50. package/apps/runtime/dist/routes/broker.js +1 -1
  51. package/apps/runtime/dist/routes/bundles.js +91 -0
  52. package/apps/runtime/dist/routes/connections.js +14 -3
  53. package/apps/runtime/dist/routes/rules.js +53 -9
  54. package/apps/runtime/dist/routes/studio.js +23 -18
  55. package/apps/runtime/dist/services/cloud.js +2 -0
  56. package/apps/runtime/dist/services/draft-events.js +79 -6
  57. package/apps/runtime/dist/services/files.js +2 -2
  58. package/apps/runtime/dist/services/skills.js +61 -5
  59. package/apps/runtime/dist/services/space-index.js +102 -10
  60. package/apps/runtime/dist/services/synced-spaces.js +5 -1
  61. package/apps/runtime/dist/services/wizards.js +48 -2
  62. package/apps/runtime/dist/sharing/jobs.js +6 -2
  63. package/apps/runtime/dist/sync/records.js +6 -1
  64. package/apps/runtime/dist/texts.js +36 -1
  65. package/apps/runtime/dist/tools/connections.js +8 -0
  66. package/apps/runtime/dist/tools/connector.js +13 -1
  67. package/apps/runtime/dist/tools/index.js +8 -3
  68. package/apps/runtime/dist/tools/skills.js +11 -1
  69. package/apps/web/dist/assets/{AboutDialog-B2Xmxyj4.js → AboutDialog-mZCBU7KF.js} +1 -1
  70. package/apps/web/dist/assets/{BlockEditor-D0HoUSih.js → BlockEditor-Dk0QwLSU.js} +1 -1
  71. package/apps/web/dist/assets/CapabilitiesPage-GkpgF-wZ.js +2 -0
  72. package/apps/web/dist/assets/{ChangelogDialog-BIrJbAKi.js → ChangelogDialog-BhyilZWA.js} +1 -1
  73. package/apps/web/dist/assets/{CodeEditor-DUVcXI5P.js → CodeEditor-DULYZbuE.js} +1 -1
  74. package/apps/web/dist/assets/EditorPage-D_mCdYdZ.js +3 -0
  75. package/apps/web/dist/assets/{FlowPreview-BIag8_Be.js → FlowPreview-ykxZxWnk.js} +1 -1
  76. package/apps/web/dist/assets/{LangSwitch-CJ00IgaO.js → LangSwitch-iO54w9AP.js} +1 -1
  77. package/apps/web/dist/assets/{Marketplace-D7-ot9Dz.js → Marketplace-C97fH7UC.js} +2 -2
  78. package/apps/web/dist/assets/{NewWizardChannels-DI3SQ4iS.js → NewWizardChannels-CsSV7sm2.js} +1 -1
  79. package/apps/web/dist/assets/{NewWizardPage-CytheHxX.js → NewWizardPage-Ebgw-Vf_.js} +1 -1
  80. package/apps/web/dist/assets/{OnboardingPage-_91Pa8Ad.js → OnboardingPage-BZlloT7v.js} +1 -1
  81. package/apps/web/dist/assets/PreviewPane-CJuqY5uA.js +7 -0
  82. package/apps/web/dist/assets/ProtocolSection-CPaDKVpZ.js +1 -0
  83. package/apps/web/dist/assets/{PublicRunner-CEgXSk3r.js → PublicRunner-4Lf4SnwB.js} +1 -1
  84. package/apps/web/dist/assets/{ReadOnly-CWf5x74a.js → ReadOnly-CXQ41R9Q.js} +1 -1
  85. package/apps/web/dist/assets/{SettingsPage-Dr8SDk-L.js → SettingsPage-C-8BgK9O.js} +2 -2
  86. package/apps/web/dist/assets/{SetupPage-B68n0l4I.js → SetupPage-4_K083Wl.js} +1 -1
  87. package/apps/web/dist/assets/{SharePage-DfznN7ar.js → SharePage-CQjgMcDI.js} +1 -1
  88. package/apps/web/dist/assets/{SkillEditor-BIcIczRc.js → SkillEditor-DT5hQwbg.js} +1 -1
  89. package/apps/web/dist/assets/{Skills-CN4QE7Kx.js → Skills-D7V_9_xo.js} +1 -1
  90. package/apps/web/dist/assets/SpacePage-D3rYS1bA.js +2 -0
  91. package/apps/web/dist/assets/{UpdateCheck-QhBI3rlQ.js → UpdateCheck-DVgAJmy8.js} +2 -2
  92. package/apps/web/dist/assets/changelog-DzQCUSsx.js +1 -0
  93. package/apps/web/dist/assets/{code-editor-DkPo1C-L.js → code-editor-5T7ilBjd.js} +2 -2
  94. package/apps/web/dist/assets/{host-D6H6Z9Jp.js → host-CCijW1hj.js} +6 -6
  95. package/apps/web/dist/assets/i18n-DCPDesT-.js +55 -0
  96. package/apps/web/dist/assets/{index-De0Wb42y.js → index-C_iWl8iS.js} +3 -3
  97. package/apps/web/dist/assets/index-zcPlodHx.css +1 -0
  98. package/apps/web/dist/assets/minus-BpYkOkYw.js +1 -0
  99. package/apps/web/dist/assets/{read-aloud-CnFwDSGD.js → read-aloud-Qb719not.js} +1 -1
  100. package/apps/web/dist/assets/{runners-0sTPbWzr.js → runners-BeZ84YH_.js} +1 -1
  101. package/apps/web/dist/assets/{session-BMiUrqHg.js → session-CEJRkSP5.js} +1 -1
  102. package/apps/web/dist/assets/{theme-CkNTe-_Z.js → theme-y_owNosi.js} +1 -1
  103. package/apps/web/dist/assets/{ui-DAk_vjrL.js → ui-BacfkQ7Q.js} +1 -1
  104. package/apps/web/dist/assets/{useMutation-isHfB33W.js → useMutation-CgzFr4qH.js} +1 -1
  105. package/apps/web/dist/assets/{viewers-ijNZHJFG.js → viewers-CkyHAjnk.js} +2 -2
  106. package/apps/web/dist/index.html +12 -12
  107. package/apps/web/dist/mcp/flow.html +2 -2
  108. package/node_modules/@engenty/wizards-shared/dist/bundles.d.ts +219 -0
  109. package/node_modules/@engenty/wizards-shared/dist/bundles.js +19 -0
  110. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +105 -4
  111. package/node_modules/@engenty/wizards-shared/dist/connectors.js +6 -0
  112. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +8 -0
  113. package/node_modules/@engenty/wizards-shared/dist/run.js +16 -0
  114. package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +84 -1
  115. package/node_modules/@engenty/wizards-shared/dist/rwx.js +69 -1
  116. package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +20 -3
  117. package/node_modules/@engenty/wizards-shared/dist/skills.js +5 -2
  118. package/package.json +1 -1
  119. package/plugin/.claude-plugin/plugin.json +1 -1
  120. package/plugin/plugin.json +1 -1
  121. package/apps/web/dist/assets/CapabilitiesPage-C1th2cZE.js +0 -2
  122. package/apps/web/dist/assets/EditorPage-56sIqEfF.js +0 -3
  123. package/apps/web/dist/assets/PreviewPane-BDsYm-_K.js +0 -7
  124. package/apps/web/dist/assets/ProtocolSection-D_zaxHEL.js +0 -1
  125. package/apps/web/dist/assets/SpacePage-DiVTwhnJ.js +0 -2
  126. package/apps/web/dist/assets/changelog-a_CuplMX.js +0 -1
  127. package/apps/web/dist/assets/i18n-BaPKbQ1s.js +0 -55
  128. package/apps/web/dist/assets/index-CCUG6Vnh.css +0 -1
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$n as r,$t as i,Dn as a,Jn as o,Q as s,S as c,Tn as l,Vr as u,X as d,Zn as f,an as p,cr as m,en as h,fn as g,gr as _,hn as v,i as y,in as b,ln as x,nn as S,on as C,or as w,pn as T,rn as E,tn as D,un as O,vn as k,x as A}from"./ui-BacfkQ7Q.js";import{k as j}from"./Marketplace-C97fH7UC.js";import{t as M}from"./useMutation-CgzFr4qH.js";import{d as N,i as P,r as F}from"./marked.esm-DQ7XA7AC.js";import{$n as I,Tn as L,p as ee,pn as R,vn as te,wn as ne}from"./host-CCijW1hj.js";import{n as re}from"./volume-2-BqlBtCIJ.js";import{t as ie}from"./circle-check-DDLzlcXP.js";import{d as ae,h as oe,n as se,u as ce}from"./session-CEJRkSP5.js";import{n as z,s as B}from"./i18n-DCPDesT-.js";import{d as le,p as ue}from"./UpdateCheck-DVgAJmy8.js";var de={name:`circle-pause`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`10`,x2:`10`,y1:`15`,y2:`9`,key:`c1nkhi`}],[`line`,{x1:`14`,x2:`14`,y1:`15`,y2:`9`,key:`h65svq`}]],aliases:[`pause-circle`]};de.node;var fe=N(de),pe={name:`circle-x`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]],aliases:[`x-circle`]};pe.node;var me=N(pe),V=e(t(),1),H=e(n(),1),he=[`read`,`write`,`send`,`destructive`],ge={read:`connectors.group.read`,write:`connectors.group.write`,send:`connectors.group.send`,destructive:`connectors.group.destructive`};function _e({label:e,value:t,onChange:n,options:r,disabled:i,mono:a}){return(0,H.jsx)(`select`,{"aria-label":e,value:t,disabled:i,onChange:e=>n(e.target.value),className:v(`h-8 max-w-full rounded-lg border border-input bg-card px-2 text-[0.8125rem] text-ink outline-none transition focus:border-focus focus:ring-4 focus:ring-focus-glow disabled:opacity-60 coarse:h-10`,a&&`font-mono text-[0.75rem]`),children:r.map(e=>(0,H.jsx)(`option`,{value:e.value,children:e.label},e.value))})}function ve({actions:e,onChange:t,disabled:n}){return(0,H.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:e.map(e=>(0,H.jsxs)(`li`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5 px-3 py-2`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1 basis-48`,children:[(0,H.jsx)(`div`,{className:`truncate font-mono text-[0.75rem] text-ink-2`,children:e.id}),e.summary?(0,H.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-4`,children:e.summary}):null]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.group===`send`?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:B(`connectors.address.recipient`)}),(0,H.jsx)(_e,{mono:!!e.recipientField,label:B(`connectors.address.recipientOf`,{id:e.id}),value:e.recipientField??``,disabled:n,onChange:n=>t(e.id,{kind:`send`,...n?{recipientField:n}:{}}),options:[{value:``,label:B(`connectors.address.recipientNone`)},...[...new Set([...e.fields??[],e.recipientField??``])].filter(Boolean).map(e=>({value:e,label:e}))]})]}):null,(0,H.jsx)(_e,{label:B(`connectors.address.kindOf`,{id:e.id}),value:e.group,disabled:n,onChange:n=>t(e.id,{kind:n}),options:he.map(e=>({value:e,label:B(ge[e])}))})]})]},e.id))})}function ye(e){let t=e.trim();return!t||/^https?:\/\//i.test(t)?t:/^(localhost|\[|\d+\.\d+\.\d+\.\d+)/i.test(t)?`http://${t}`:`https://${t}`}var be=e=>e.signIn.described===null?`header`:e.signIn.described===`none`?`none`:`described`;function xe(e,t){let{described:n,needsOAuthClient:r,keyIn:i}=e.signIn;return t===`header`?B(`connectors.address.signIn.headerHint`):t===`none`?B(n===`none`?`connectors.address.signIn.open`:`connectors.address.signIn.noneHint`):n===`oauth2`?B(r?`connectors.address.signIn.oauthClient`:`connectors.address.signIn.oauth`):B(`connectors.address.signIn.key`,{name:i??``})}function Se({spaceId:e,taken:t,onDone:n}){let r=u(),[a,o]=(0,V.useState)(``),[c,f]=(0,V.useState)(null),[m,h]=(0,V.useState)(``),[g,_]=(0,V.useState)(``),[y,b]=(0,V.useState)(`described`),[x,S]=(0,V.useState)({name:`Authorization`,scheme:`Bearer`,value:``}),[w,E]=(0,V.useState)({id:``,secret:``}),[O,k]=(0,V.useState)({}),A=e=>({kind:`header`,name:x.name.trim(),...x.scheme.trim()?{scheme:x.scheme.trim()}:{},...e&&x.value?{value:x.value}:{}}),j=M({mutationFn:t=>s.post(`/api/studio/spaces/${e}/connectors/preview`,{sourceUrl:ye(a),...t?{signIn:A(!0)}:{}}),onSuccess:(e,t)=>{f(e),k(t=>Object.fromEntries(Object.entries(t).filter(([t])=>e.actions.some(e=>e.id===t)))),t||(h(e.title??e.host),_(e.suggestedToolPrefix),b(be(e)),k({}))}}),N=!!c&&j.variables===!0,P=g.replaceAll(`_`,`-`),F=/^[a-z][a-z0-9_]{1,30}$/.test(g)?t.includes(P)?B(`connectors.address.shortTaken`):null:B(`connectors.address.shortInvalid`),I=y===`described`&&c?.signIn.described===`oauth2`&&c.signIn.needsOAuthClient,L=M({mutationFn:t=>s.post(`/api/studio/spaces/${e}/connectors`,{sourceKind:t.sourceKind,sourceUrl:ye(a),id:P,toolPrefix:g,name:m.trim()||t.host,signIn:y===`header`?A(!0):{kind:y},...Object.keys(O).length?{actionKinds:O}:{},...I&&w.id&&w.secret?{oauthClientId:w.id,oauthClientSecret:w.secret}:{}}),onSuccess:async t=>{await r.invalidateQueries({queryKey:d.connectors(e)}),f(null),o(``),S(e=>({...e,value:``})),n(t.connector.id)}}),ee=e=>{e.preventDefault(),a.trim()&&(L.reset(),j.mutate(!1))},R=(c?.actions??[]).map(e=>{let t=O[e.id];return t?{...e,group:t.kind,recipientField:t.recipientField}:e}),te=c?c.signIn.described===null?[`header`,`none`]:c.signIn.described===`none`?[`none`,`header`]:[`described`,`header`,`none`]:[],ne=m.trim()||c?.host||``;return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsxs)(`form`,{className:`flex flex-col gap-2`,onSubmit:ee,children:[(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:B(`connectors.address.hint`)}),(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsx)(p,{"aria-label":B(`connectors.address.label`),className:`font-mono text-[0.8125rem]`,value:a,inputMode:`url`,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1,placeholder:B(`connectors.address.placeholder`),onChange:e=>o(e.target.value)}),(0,H.jsxs)(i,{type:`submit`,variant:`secondary`,busy:j.isPending&&!c,children:[(0,H.jsx)(l,{className:`size-4`}),` `,B(`connectors.address.check`)]})]})]}),j.error&&!N?(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:j.error.message}):null,c?(0,H.jsxs)(`div`,{className:`flex flex-col gap-5 border-border-soft border-t pt-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,className:`flex size-11 shrink-0 items-center justify-center rounded-lg bg-paper-2 font-semibold text-[0.875rem] text-ink-2`,children:se(ne)||`?`}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`div`,{className:`truncate font-display font-semibold text-[0.9375rem]`,children:ne}),(0,H.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[B(`connectors.address.kind.${c.sourceKind}`),` · `,c.host,` ·`,` `,c.toolsPending?B(`connectors.address.actions.pending`):B(c.actions.length===1?`connectors.address.actions.one`:`connectors.address.actions.n`,{n:c.actions.length})]})]}),c.fromAddress?(0,H.jsx)(D,{tone:`warn`,title:B(`connectors.uncheckedHint`),children:B(`connectors.unchecked`)}):null]}),c.privateAddress?(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:B(`connectors.address.private`)}):null,c.blockers.map(e=>(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:e},e)),(0,H.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-[minmax(0,3fr)_minmax(0,2fr)]`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(C,{children:B(`connectors.address.name`)}),(0,H.jsx)(p,{"aria-label":B(`connectors.address.name`),value:m,maxLength:120,onChange:e=>h(e.target.value)})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(C,{children:B(`connectors.address.short`)}),(0,H.jsx)(p,{"aria-label":B(`connectors.address.short`),className:`font-mono text-[0.8125rem]`,value:g,maxLength:31,autoCapitalize:`off`,spellCheck:!1,onChange:e=>_(e.target.value.toLowerCase())}),(0,H.jsx)(`p`,{className:v(`mt-1.5 text-[0.75rem]`,F?`text-rose`:`text-ink-3`),children:F??B(`connectors.address.shortHint`)})]})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(C,{children:B(`connectors.address.signIn`)}),c.signIn.described===null?(0,H.jsx)(`p`,{className:`mb-2 text-[0.8125rem] text-ink-2`,children:B(`connectors.address.signIn.unknown`)}):null,(0,H.jsx)(`div`,{className:`max-w-full overflow-x-auto`,children:(0,H.jsx)(T,{label:B(`connectors.address.signIn`),value:y,onChange:b,options:te.map(e=>({id:e,label:B(`connectors.address.signIn.${e}`)}))})}),(0,H.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-ink-3`,children:xe(c,y)}),y===`header`?(0,H.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-[0.75rem] text-ink-3`,children:[B(`connectors.address.header.name`),(0,H.jsx)(p,{className:`font-mono text-[0.8125rem]`,value:x.name,autoCapitalize:`off`,spellCheck:!1,onChange:e=>S(t=>({...t,name:e.target.value}))})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-[0.75rem] text-ink-3`,children:[B(`connectors.address.header.scheme`),(0,H.jsx)(p,{className:`font-mono text-[0.8125rem]`,value:x.scheme,placeholder:B(`connectors.address.header.schemePlaceholder`),autoCapitalize:`off`,spellCheck:!1,onChange:e=>S(t=>({...t,scheme:e.target.value}))})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-[0.75rem] text-ink-3`,children:[B(`connectors.address.header.value`),(0,H.jsx)(p,{type:`password`,autoComplete:`off`,value:x.value,onChange:e=>S(t=>({...t,value:e.target.value}))})]})]}),j.error&&N?(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:j.error.message}):null,c.sourceKind===`mcp`&&c.signIn.described!==`none`?(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[(0,H.jsx)(i,{size:`sm`,variant:`secondary`,busy:j.isPending,disabled:!(x.name.trim()&&x.value),onClick:()=>j.mutate(!0),children:B(`connectors.address.header.read`)}),(0,H.jsx)(`span`,{className:`min-w-48 flex-1 text-[0.75rem] text-ink-3`,children:B(`connectors.address.header.valueHint`)})]}):null]}):null,I?(0,H.jsxs)(`div`,{className:`mt-3 grid gap-2 sm:grid-cols-2`,children:[(0,H.jsx)(p,{"aria-label":B(`connectors.clientId`),placeholder:B(`connectors.clientId`),value:w.id,onChange:e=>E(t=>({...t,id:e.target.value}))}),(0,H.jsx)(p,{"aria-label":B(`connectors.clientSecret`),type:`password`,autoComplete:`off`,placeholder:B(`connectors.clientSecret`),value:w.secret,onChange:e=>E(t=>({...t,secret:e.target.value}))})]}):null]}),R.length?(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`font-semibold text-[0.875rem]`,children:B(`connectors.address.kinds`)}),(0,H.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-3`,children:B(`connectors.address.kindsHint`)})]}),(0,H.jsx)(`div`,{className:`max-h-96 overflow-y-auto rounded-lg bg-card ring-1 ring-border-soft`,children:(0,H.jsx)(ve,{actions:R,onChange:(e,t)=>k(n=>({...n,[e]:t}))})}),R.some(e=>e.group===`send`)?(0,H.jsx)(`p`,{className:`text-[0.75rem] text-ink-3`,children:B(`connectors.address.recipientHint`)}):null,c.dropped?(0,H.jsx)(`p`,{className:`text-[0.75rem] text-ink-3`,children:B(`connectors.address.dropped`,{n:c.dropped})}):null]}):c.toolsPending?(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:B(`connectors.address.pending`)}):null,L.error?(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:L.error.message}):null,(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[(0,H.jsx)(i,{busy:L.isPending,disabled:!!F||c.blockers.length>0||y===`header`&&!x.name.trim(),onClick:()=>L.mutate(c),children:B(`connectors.import`)}),(0,H.jsx)(i,{variant:`ghost`,onClick:()=>f(null),children:B(`orgSettings.cancel`)}),(0,H.jsx)(`span`,{className:`min-w-48 flex-1 text-[0.8125rem] text-ink-3`,children:B(`connectors.address.after`)})]})]}):null]})}function Ce({connector:e}){let[t,n]=(0,V.useState)(!1);return(0,H.jsxs)(`div`,{className:`rounded-lg bg-paper ring-1 ring-border-soft`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`flex w-full items-center gap-3 px-3 py-2 text-left`,children:[(0,H.jsx)(`span`,{className:v(`size-2 shrink-0 rounded-full`,e.usable?`bg-moss`:`bg-ink-4`)}),(0,H.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem]`,children:[e.name,` `,(0,H.jsx)(`span`,{className:`font-mono text-[0.6875rem] text-ink-4`,children:e.id})]}),(0,H.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3`,children:e.usable?B(e.actions.length===1?`connectors.actions.one`:`connectors.actions.n`,{n:e.actions.length,r:e.actions.filter(e=>e.group===`read`).length}):B(`connectors.notSetUp`)})]}),t?(0,H.jsxs)(`div`,{className:`border-border-soft border-t px-3 py-2 text-[0.75rem]`,children:[e.missingSetup?(0,H.jsxs)(`p`,{className:`mb-1 text-ink-3`,children:[B(`connectors.setup`),` `,(0,H.jsx)(`span`,{className:`font-mono text-ink-2`,children:e.missingSetup})]}):null,(0,H.jsx)(`p`,{className:`text-ink-4`,children:e.actions.map(e=>e.group===`read`?e.id:`${e.id} (${B(`connectors.group.${e.group}`)})`).join(` · `)})]}):null]})}var we={none:`connectors.authNone`,oauth2:`connectors.authOauth`,api_key:`connectors.authKey`};function Te({spaceId:e,connector:t,readOnly:n,onSetUp:r}){let o=u(),[c,l]=(0,V.useState)(!1),f=()=>o.invalidateQueries({queryKey:d.connectors(e)}),p=`/api/studio/spaces/${e}/connectors/${t.id}`,m=M({mutationFn:()=>s.post(`${p}/refresh`),onSuccess:f}),h=M({mutationFn:()=>s.del(p),onSuccess:f}),g=M({mutationFn:e=>s.patch(`${p}/actions`,{actions:{[e.id]:e.choice}}),onSuccess:t=>{o.setQueryData(d.connectors(e),e=>e?.map(e=>e.id===t.id?t:e)),o.invalidateQueries({queryKey:[`space-connections`,e]})}}),_=t.actions.filter(e=>e.group===`read`).length;return(0,H.jsxs)(`div`,{className:`rounded-lg bg-paper ring-1 ring-border-soft`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 p-3`,children:[(0,H.jsx)(`div`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-paper-2 text-ink-2`,children:(0,H.jsx)(re,{className:`size-4`})}),(0,H.jsxs)(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`min-w-0 flex-1 basis-44 text-left`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,H.jsx)(`span`,{className:`truncate font-medium text-[0.875rem]`,children:t.name}),(0,H.jsx)(`span`,{className:`font-mono text-[0.6875rem] text-ink-4`,children:t.id}),t.fromAddress?(0,H.jsx)(D,{tone:`warn`,title:B(`connectors.uncheckedHint`),children:B(`connectors.unchecked`)}):null]}),(0,H.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t.domain,` · `,t.sourceKind===`mcp`?`MCP`:`OpenAPI`,` ·`,` `,B(we[t.auth]),` ·`,` `,t.toolsPending?B(`connectors.pending`):B(t.actions.length===1?`connectors.actions.one`:`connectors.actions.n`,{n:t.actions.length,r:_})]})]}),n?null:(0,H.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[r?(0,H.jsx)(i,{size:`sm`,variant:`secondary`,onClick:()=>r(t.id),children:B(`capabilities.connectors.setUp`)}):null,(0,H.jsx)(b,{label:B(`connectors.refresh`),onClick:()=>m.mutate(),children:m.isPending?(0,H.jsx)(O,{className:`size-4`}):(0,H.jsx)(a,{className:`size-4`})}),(0,H.jsx)(b,{label:B(`connectors.remove`),className:`hover:text-rose`,onClick:async()=>await y(B(`connectors.removeConfirm`,{name:t.name}))&&h.mutate(),children:(0,H.jsx)(F,{className:`size-4`})})]})]}),t.needsOAuthClient?(0,H.jsx)(`p`,{className:`border-border-soft border-t px-3 py-2 text-[0.75rem] text-rose`,children:B(`connectors.needsClient`)}):null,m.error??h.error??g.error?(0,H.jsx)(`p`,{className:`border-border-soft border-t px-3 py-2 text-[0.75rem] text-rose`,children:(m.error??h.error??g.error).message}):null,c&&t.actions.length&&!n?(0,H.jsxs)(`div`,{className:`border-border-soft border-t`,children:[(0,H.jsx)(`p`,{className:`px-3 pt-2 text-[0.75rem] text-ink-3`,children:B(`connectors.address.kindsHint`)}),(0,H.jsx)(`div`,{className:`max-h-80 overflow-y-auto`,children:(0,H.jsx)(ve,{actions:t.actions,disabled:g.isPending,onChange:(e,t)=>g.mutate({id:e,choice:t})})}),t.actions.some(e=>e.group===`send`)?(0,H.jsx)(`p`,{className:`px-3 pb-2 text-[0.75rem] text-ink-3`,children:B(`connectors.address.recipientHint`)}):null]}):null,c&&t.actions.length&&n?(0,H.jsx)(`ul`,{className:`max-h-64 overflow-y-auto border-border-soft border-t px-3 py-2`,children:t.actions.map(e=>(0,H.jsxs)(`li`,{className:`flex items-baseline gap-2 py-1 text-[0.75rem]`,children:[(0,H.jsx)(`span`,{className:v(`w-14 shrink-0 text-[0.6875rem] uppercase tracking-wide`,e.group===`read`?`text-moss`:e.group===`write`?`text-ink-3`:`text-rose`),children:B(`connectors.group.${e.group}`)}),(0,H.jsx)(`span`,{className:`shrink-0 font-mono text-ink-2`,children:e.id}),(0,H.jsx)(`span`,{className:`min-w-0 truncate text-ink-4`,children:e.summary})]},e.id))}):null]})}function Ee({spaceId:e,domain:t,source:n,taken:r,onDone:a}){let o=u(),[c,l]=(0,V.useState)({id:``,secret:``}),[f,m]=(0,V.useState)(!1),h=r.includes(n.suggestedId),g=M({mutationFn:()=>s.post(`/api/studio/spaces/${e}/connectors`,{domain:t,sourceKind:n.sourceKind,sourceUrl:n.sourceUrl,id:n.suggestedId,toolPrefix:n.suggestedToolPrefix,...n.name?{name:n.name}:{},...c.id&&c.secret?{oauthClientId:c.id,oauthClientSecret:c.secret}:{}}),onSuccess:async t=>{await o.invalidateQueries({queryKey:d.connectors(e)}),a(t.warnings,t.connector.id)}});return(0,H.jsxs)(`div`,{className:`rounded-lg bg-card p-3 ring-1 ring-border-soft`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(D,{tone:n.sourceKind===`mcp`?`ember`:`neutral`,children:n.sourceKind===`mcp`?`MCP`:`OpenAPI`}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`div`,{className:`truncate text-[0.8125rem]`,children:n.name??n.suggestedId}),(0,H.jsx)(`div`,{className:`truncate font-mono text-[0.6875rem] text-ink-4`,children:n.sourceUrl})]}),n.blocked||h?null:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`text-[0.75rem] text-ink-3 hover:text-ink`,children:B(`connectors.ownClient`)}),(0,H.jsx)(i,{size:`sm`,busy:g.isPending,onClick:()=>g.mutate(),children:B(`connectors.import`)})]})]}),n.blocked?(0,H.jsx)(`p`,{className:`mt-2 text-[0.75rem] text-ink-3`,children:n.blocked}):null,h?(0,H.jsx)(`p`,{className:`mt-2 text-[0.75rem] text-ink-3`,children:B(`connectors.exists`)}):null,f?(0,H.jsxs)(`div`,{className:`mt-3 grid gap-2 sm:grid-cols-2`,children:[(0,H.jsx)(p,{placeholder:B(`connectors.clientId`),value:c.id,onChange:e=>l(t=>({...t,id:e.target.value}))}),(0,H.jsx)(p,{type:`password`,autoComplete:`off`,placeholder:B(`connectors.clientSecret`),value:c.secret,onChange:e=>l(t=>({...t,secret:e.target.value}))})]}):null,g.error?(0,H.jsx)(`p`,{className:`mt-2 text-[0.75rem] text-rose`,children:g.error.message}):null]})}function De({spaceId:e,readOnly:t,embedded:n,onSetUp:r,domain:a}){let o=R(`unsetConnectors`),[c,u]=(0,V.useState)(``),[m,h]=(0,V.useState)(null),[g,v]=(0,V.useState)(null),[y,b]=(0,V.useState)([]),[x,S]=(0,V.useState)(`registry`),C=_({queryKey:d.connectors(e),queryFn:()=>s.get(`/api/studio/spaces/${e}/connectors`)}),w=M({mutationFn:()=>s.post(`/api/studio/connectors/search`,{query:c}),onSuccess:e=>{h(e),v(null),b([])}}),E=M({mutationFn:e=>s.get(`/api/studio/connectors/registry/${encodeURIComponent(e)}`),onSuccess:v}),D=E.mutate;(0,V.useEffect)(()=>{a&&!t&&(S(`registry`),D(a))},[a,t,D]);let k=C.data??[],A=k.filter(e=>e.sourceKind===`builtin`&&(o||e.usable)),j=k.filter(e=>e.sourceKind!==`builtin`);return(0,H.jsxs)(n?ke:Oe,{children:[n?null:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`h2`,{className:`font-display font-semibold text-lg`,children:B(`connectors.title`)}),(0,H.jsx)(`p`,{className:`mt-1 mb-5 text-[0.875rem] text-ink-3`,children:B(`connectors.hint`)})]}),A.length&&!n?(0,H.jsx)(`div`,{className:`mb-5 grid gap-1.5 sm:grid-cols-2`,children:A.map(e=>(0,H.jsx)(Ce,{connector:e},e.id))}):null,j.length||t?(0,H.jsx)(`h3`,{className:`mb-2 font-medium text-[0.75rem] text-ink-3 uppercase tracking-[0.07em]`,children:B(`connectors.imported`)}):null,j.length?(0,H.jsx)(`div`,{className:`mb-4 flex flex-col gap-2`,children:j.map(n=>(0,H.jsx)(Te,{spaceId:e,connector:n,readOnly:t,onSetUp:r},n.id))}):null,t?null:(0,H.jsx)(`div`,{className:`mb-3 max-w-full overflow-x-auto`,children:(0,H.jsx)(T,{label:B(`connectors.from`),value:x,onChange:S,options:[{id:`registry`,label:B(`connectors.from.registry`)},{id:`address`,label:B(`connectors.from.address`)}]})}),t?j.length?null:(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:B(`connectors.noneImported`)}):x===`address`?(0,H.jsx)(Se,{spaceId:e,taken:k.map(e=>e.id),onDone:e=>r?.(e)}):(0,H.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),c.trim()&&w.mutate()},children:[(0,H.jsx)(p,{value:c,placeholder:B(`connectors.search`),onChange:e=>u(e.target.value)}),(0,H.jsxs)(i,{type:`submit`,variant:`secondary`,busy:w.isPending,children:[(0,H.jsx)(l,{className:`size-4`}),` `,B(`connectors.find`)]})]}),x===`registry`&&w.error?(0,H.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:w.error.message}):null,x===`registry`&&m&&!g?(0,H.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[m.length?null:(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:B(`connectors.none`)}),m.map(e=>(0,H.jsxs)(`button`,{type:`button`,disabled:!e.kinds.length,onClick:()=>E.mutate(e.domain),className:`flex items-center gap-3 rounded-lg px-3 py-2 text-left transition hover:bg-paper-2 disabled:opacity-50`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:e.domain}),(0,H.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.description})]}),(0,H.jsx)(`span`,{className:`text-[0.6875rem] text-ink-4 uppercase`,children:e.kinds.join(` · `)}),(0,H.jsx)(f,{className:`-rotate-90 size-4 text-ink-4`})]},e.domain)),E.isPending?(0,H.jsx)(O,{className:`mx-auto mt-2 size-4 text-ink-4`}):null,E.error?(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:E.error.message}):null]}):null,x===`registry`&&g?(0,H.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,H.jsx)(`div`,{className:`font-medium text-[0.875rem]`,children:g.domain}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>v(null),className:`text-[0.75rem] text-ink-3 hover:text-ink`,children:B(`run.back`)})]}),g.summary?(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:g.summary}):null,g.sources.map(t=>(0,H.jsx)(Ee,{spaceId:e,domain:g.domain,source:t,taken:k.map(e=>e.id),onDone:(e,t)=>{b(e),r?.(t)}},`${t.sourceKind}:${t.sourceUrl}`)),g.credentials.filter(e=>e.setup||e.url).map(e=>(0,H.jsxs)(`p`,{className:`text-[0.75rem] text-ink-3`,children:[(0,H.jsxs)(`span`,{className:`text-ink-2`,children:[e.label,`:`]}),` `,e.setup,` `,e.url?(0,H.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-ember underline`,children:e.url}):null]},e.label)),y.map(e=>(0,H.jsx)(`p`,{className:`text-[0.75rem] text-ink-3`,children:e},e))]}):null]})}function Oe({children:e}){return(0,H.jsx)(h,{className:`p-4 sm:p-6`,children:e})}function ke({children:e}){return(0,H.jsx)(`div`,{children:e})}var Ae=[`space`,`person`],je=[`admins`,`members`,`all`],Me=[`read`,`write`,`destructive`,`send`],Ne=[`allow`,`ask`,`deny`],Pe={name:80,perSpace:200,calls:1e6};function U(e){return e.audience===`all`&&e.signIn===`space`}function Fe(e){(0,V.useEffect)(()=>{let t=t=>{t.data?.type===`wizards:connected`&&e()};return window.addEventListener(`message`,t),()=>window.removeEventListener(`message`,t)},[e])}function W(e,t){let[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(!1);return{keys:n,setKeys:r,confirm:i,setConfirm:a,signIn:M({mutationFn:async t=>{if(t)return s.post(e,{credentials:t});let n=window.open(``,`_blank`,`popup,width=520,height=700`);try{let{url:t}=await s.post(e,{oauth:!0});n?n.location.href=t:window.location.href=t}catch(e){throw n?.close(),e}},onSuccess:async(e,n)=>{n&&(r(null),await t())}}),signOut:M({mutationFn:()=>s.del(e),onSuccess:async()=>{a(!1),await t()}})}}function G({s:e,auth:t,signedIn:n}){return(0,H.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:n?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{className:`max-sm:hidden`,children:(0,H.jsx)(D,{tone:`live`,children:B(`konto.signedIn`)})}),(0,H.jsx)(i,{variant:`ghost`,size:`sm`,onClick:()=>e.setConfirm(!0),children:B(`konto.signOut`)})]}):(0,H.jsx)(i,{size:`sm`,busy:e.signIn.isPending&&!e.keys,onClick:()=>t===`api_key`?e.setKeys(e.keys?null:{}):e.signIn.mutate(void 0),children:B(`konto.connectionSignIn`)})})}function K({s:e,fields:t,signedIn:n,confirmText:r,className:a}){let{keys:o}=e;return(0,H.jsxs)(H.Fragment,{children:[o&&!n?(0,H.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),e.signIn.mutate(o??{})},className:v(`mt-3 flex flex-col gap-3`,a),children:[t.map(t=>(0,H.jsxs)(`div`,{children:[(0,H.jsx)(C,{children:t.label}),(0,H.jsx)(p,{type:t.secret?`password`:`text`,autoComplete:`off`,placeholder:t.placeholder,required:t.required!==!1,maxLength:500,value:o[t.key]??``,onChange:n=>e.setKeys({...o,[t.key]:n.target.value})})]},t.key)),(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsx)(i,{type:`submit`,size:`sm`,busy:e.signIn.isPending,children:B(`konto.connectionSignIn`)}),(0,H.jsx)(i,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>e.setKeys(null),children:B(`orgSettings.cancel`)})]})]}):null,e.signIn.isError?(0,H.jsx)(`p`,{className:v(`mt-2 text-[0.8125rem] text-rose`,a),children:e.signIn.error.message}):null,e.signOut.isError?(0,H.jsx)(`p`,{className:v(`mt-2 text-[0.8125rem] text-rose`,a),children:e.signOut.error.message}):null,e.confirm?(0,H.jsxs)(`div`,{className:v(`mt-3 flex flex-wrap items-center gap-3 rounded-lg bg-paper p-3 text-[0.875rem] ring-1 ring-border-soft`,a),children:[(0,H.jsx)(`p`,{className:`min-w-48 flex-1`,children:r}),(0,H.jsx)(i,{variant:`ghost`,onClick:()=>e.setConfirm(!1),children:B(`orgSettings.cancel`)}),(0,H.jsx)(i,{busy:e.signOut.isPending,onClick:()=>e.signOut.mutate(),children:B(`konto.signOut`)})]}):null]})}function Ie(e){return e===null?``:String(e)}function Le(e){let t=e.trim();if(!t)return null;if(!/^\d+$/.test(t))return;let n=Number(t);return n>=1&&n<=Pe.calls?n:void 0}function Re(e){return e.callsPerDay===null?B(`connection.callsToday`,{n:e.callsToday}):B(`connection.callsTodayOf`,{n:e.callsToday.toLocaleString(z),limit:e.callsPerDay.toLocaleString(z)})}var q=e=>[`space-connections`,e];function ze(e){return _({enabled:!!e,queryKey:q(e),queryFn:()=>s.get(`/api/studio/spaces/${e}/connections`)})}function Be(e){return _({enabled:!!e,queryKey:d.connectors(e),queryFn:()=>s.get(`/api/studio/spaces/${e}/connectors`)})}function Ve(e,t,n){let r=new Set(t.map(e=>e.connectorId));return e.filter(e=>e.sourceKind===`builtin`&&!r.has(e.id)&&(e.usable||n))}var J={admins:`connection.audience.admins`,members:`connection.audience.members`,all:`connection.audience.all`},He={admins:`connection.audience.adminsHint`,members:`connection.audience.membersHint`,all:`connection.audience.allHint`},Ue={read:`connection.kind.read`,write:`connection.kind.write`,destructive:`connection.kind.destructive`,send:`connection.kind.send`},We={read:`connection.kind.readHint`,write:`connection.kind.writeHint`,destructive:`connection.kind.destructiveHint`,send:`connection.kind.sendHint`},Ge={allow:`connection.outcome.allow`,ask:`connection.outcome.ask`,deny:`connection.outcome.deny`},Ke={space:`connection.signIn.space`,person:`connection.signIn.person`},qe={space:`connection.signIn.spaceHint`,person:`connection.signIn.personHint`},Y=e=>new Intl.DateTimeFormat(z,{dateStyle:`medium`}).format(new Date(e));function Je(e){let t=Math.round((Date.parse(e)-Date.now())/1e3),n=new Intl.RelativeTimeFormat(z,{numeric:`auto`});for(let[e,r]of[[`day`,86400],[`hour`,3600],[`minute`,60]])if(Math.abs(t)>=r)return n.format(Math.round(t/r),e);return n.format(0,`minute`)}function X(e){let t=e.connector?.name??e.connectorId;return e.name===t?e.name:`${t} · ${e.name}`}var Z=e=>e.pluginName??e.plugin??``;function Ye(){let e=oe().data,t=R(`personSignIn`);if(!e||e.mode!==`managed`||t)return{allowed:!0,why:null};let n=e.tenant.plan?.name;return{allowed:!1,why:n?B(`connection.signIn.personPlan`,{plan:n}):B(`connection.signIn.personNoPlan`)}}function Xe(e){return e.signIn===`space`?e.account?B(`connection.asSpaceAccount`,{label:e.account.label}):B(`connection.asSpaceNotYet`):B(`connection.eachPersonCount`,{n:e.signedIn})}function Ze(e){return e.lastUsedAt?B(`connection.lastUsed`,{when:Je(e.lastUsedAt)}):B(`connection.neverUsed`)}function Qe(e){let t=e.toLowerCase().replace(/^https?:\/\//,``).split(`/`)[0].split(`.`);return t.length>1?t[t.length-2]:t[0]}function $e(e,t){if(!e)return null;let n=t.find(t=>t.id===e);if(n)return{connectorId:n.id};let r=t.find(t=>t.domain&&t.domain===e.toLowerCase());if(r)return{connectorId:r.id};let i=Qe(e),a=t.find(e=>e.sourceKind===`builtin`&&(e.id===i||e.id.endsWith(`-${i}`)||e.name.toLowerCase()===i));return a?{connectorId:a.id}:e.includes(`.`)?{domain:e}:null}function et({name:e,large:t}){return(0,H.jsx)(`span`,{"aria-hidden":`true`,className:v(`flex shrink-0 items-center justify-center rounded-lg bg-paper-2 font-semibold text-ink-2`,t?`size-12 text-[0.9375rem]`:`size-9 text-[0.75rem]`),children:se(e)||`?`})}function tt(){let[e,t]=m(),{space:n}=ce(),r=ae(),{narrow:i}=ue(),a=u(),o=n?.id??``,s=e.get(`show`),c=e.get(`setup`),l=r&&!n?.readOnly,d=ze(o),f=Be(o),p=d.data?.connections??[],h=p.find(e=>e.id===s)??null;le(h?X(h):null),Fe((0,V.useCallback)(()=>{a.invalidateQueries({queryKey:[`space-connections`]}),a.invalidateQueries({queryKey:[`person-sign-ins`]})},[a])),(0,V.useEffect)(()=>{i||ee().scrollTo({top:0})},[i,s]);let g=e=>i?t({show:e}):t(e===`all`?{}:{show:e},{replace:!0});return(0,H.jsx)(H.Fragment,{children:n?(0,H.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:h?(0,H.jsx)(ot,{connection:h,connector:f.data?.find(e=>e.id===h.connectorId),writable:l,onGone:()=>g(`all`)},h.id):(0,H.jsx)(nt,{spaceId:n.id,connections:p,loading:d.isPending,error:d.error,connectors:f.data??[],writable:l,setup:c,onOpen:g,onSetUp:e=>{t({setup:e},{replace:!i}),i||ee().scrollTo({top:0,behavior:`smooth`})},onSetUpDone:()=>t({},{replace:!0})})}):null})}function nt({spaceId:e,connections:t,loading:n,error:r,connectors:a,writable:o,setup:s,onOpen:l,onSetUp:u,onSetUpDone:d}){let f=R(`unsetConnectors`),p=(0,V.useRef)(null),m=s&&a.length?$e(s,a):null,g=m&&`domain`in m?m.domain:null;(0,V.useEffect)(()=>{g&&p.current?.scrollIntoView({block:`start`,behavior:`smooth`})},[g]);let _=Ve(a,t,f);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(c,{title:B(`capabilities.connectors`),hint:B(`capabilities.connectors.hint`),plain:!0,action:o&&s===null?(0,H.jsxs)(i,{size:`sm`,onClick:()=>u(``),children:[(0,H.jsx)(P,{className:`size-4`}),` `,B(`capabilities.connectors.add`)]}):null,children:[o&&s!==null?(0,H.jsx)(at,{spaceId:e,connectors:a,initial:m&&`connectorId`in m?m.connectorId:``,onCancel:d,onDone:l},m&&`connectorId`in m?m.connectorId:`new`):null,(0,H.jsx)(`h3`,{className:`px-1 pt-2 font-display font-semibold text-base`,children:B(`capabilities.inSpace`)}),o?(0,H.jsx)(it,{connections:t,onOpen:l}):null,r?(0,H.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:r.message}):t.length?(0,H.jsx)(h,{className:`flex flex-col divide-y divide-border-soft p-0`,children:t.map(e=>(0,H.jsx)(rt,{connection:e,onOpen:()=>l(e.id)},e.id))}):n?null:(0,H.jsx)(h,{children:(0,H.jsx)(E,{children:B(o?`capabilities.connectors.noneAdmin`:`capabilities.connectors.none`)})})]}),_.length?(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 px-1`,children:[(0,H.jsx)(`h3`,{className:`font-semibold text-[0.875rem]`,children:B(`capabilities.connectors.builtin`)}),(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:B(o?`capabilities.connectors.builtinHint`:`capabilities.connectors.builtinHintMember`)}),(0,H.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,children:_.map(e=>(0,H.jsx)(`li`,{children:o&&e.usable?(0,H.jsxs)(`button`,{type:`button`,onClick:()=>u(e.id),title:B(`capabilities.connectors.setUpNamed`,{name:e.name}),className:`inline-flex h-8 items-center gap-1.5 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,H.jsx)(P,{className:`size-3.5`,"aria-hidden":`true`}),e.name]}):(0,H.jsx)(`span`,{title:e.missingSetup??void 0,className:v(`inline-flex h-8 items-center rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-3`,!e.usable&&`opacity-60`),children:e.name})},e.id))})]}):null,(0,H.jsx)(`div`,{ref:p,className:`scroll-mt-6`,children:(0,H.jsx)(c,{title:B(`capabilities.connectors.more`),hint:B(`capabilities.connectors.moreHint`),children:(0,H.jsx)(De,{spaceId:e,readOnly:!o,embedded:!0,onSetUp:o?u:void 0,domain:g})})})]})}function rt({connection:e,onOpen:t}){let n=u(),r=W(`/api/studio/connections/${encodeURIComponent(e.id)}/my-sign-in`,()=>n.invalidateQueries({queryKey:q(e.spaceId)})),i=Object.values(e.rules).includes(`ask`),a=e.signIn===`person`,o=U(e),s=e.connector?.fromAddress===!0;return(0,H.jsxs)(`div`,{className:`px-3.5 py-3 sm:px-5`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:t,className:`-my-1 -ml-1 flex min-w-0 flex-1 items-center gap-3 rounded-lg p-1 text-left transition hover:bg-paper-2`,children:[(0,H.jsx)(et,{name:e.connector?.name??e.connectorId}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`div`,{className:`truncate text-[0.9375rem]`,children:X(e)}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[a?(0,H.jsx)(te,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}):(0,H.jsx)(I,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,H.jsxs)(`span`,{className:`truncate`,children:[Xe(e),e.plugin?` · ${B(`connection.pluginNamed`,{plugin:Z(e)})}`:``,` · `,Ze(e)]})]}),o||e.pausedAt||s?(0,H.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1.5 sm:hidden`,children:[e.pausedAt?(0,H.jsx)(D,{tone:`ember`,children:B(`connection.paused`)}):null,s?(0,H.jsx)(D,{tone:`warn`,title:B(`connectors.uncheckedHint`),children:B(`connectors.unchecked`)}):null,o?(0,H.jsx)(D,{tone:`warn`,children:B(`connection.guests`)}):null]}):null]}),(0,H.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5 max-sm:hidden`,children:[e.pausedAt?(0,H.jsx)(D,{tone:`ember`,children:B(`connection.paused`)}):null,s?(0,H.jsx)(D,{tone:`warn`,title:B(`connectors.uncheckedHint`),children:B(`connectors.unchecked`)}):null,i?(0,H.jsx)(D,{tone:`warn`,children:B(`connection.outcome.ask`)}):null,o?(0,H.jsx)(D,{tone:`warn`,children:B(`connection.guests`)}):(0,H.jsx)(D,{children:B(J[e.audience])})]})]}),a?(0,H.jsx)(G,{s:r,auth:e.connector?.auth,signedIn:!!e.mySignIn}):null]}),a?(0,H.jsx)(K,{s:r,fields:e.connector?.fields??[],signedIn:!!e.mySignIn,confirmText:B(`konto.connectionSignOutConfirm`,{name:X(e)}),className:`ml-12`}):null]})}function it({connections:e,onOpen:t}){let n=u(),r=e.filter(U),a=M({mutationFn:e=>s.patch(`/api/studio/connections/${encodeURIComponent(e.id)}`,{audience:`members`}),onSuccess:e=>{n.setQueryData(q(e.spaceId),t=>t&&{connections:t.connections.map(t=>t.id===e.id?e:t)}),n.invalidateQueries({queryKey:[`person-sign-ins`]})}});return r.length?(0,H.jsxs)(`section`,{className:`rounded-xl bg-paper-2 px-3.5 py-3 ring-1 ring-border-soft sm:px-5 sm:py-4`,children:[(0,H.jsx)(`h4`,{className:`font-semibold text-[0.875rem]`,children:B(`connection.guests.title`,{n:r.length})}),(0,H.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-2`,children:B(`connection.guests.hint`)}),(0,H.jsx)(`ul`,{className:`mt-2 flex flex-col divide-y divide-border-soft`,children:r.map(e=>(0,H.jsxs)(`li`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 py-2.5`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1 basis-56`,children:[(0,H.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`max-w-full truncate text-left font-medium text-[0.875rem] hover:underline`,children:X(e)}),e.plugin?(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:B(`connection.guests.plugin`,{plugin:Z(e)})}):null]}),(0,H.jsx)(i,{size:`sm`,variant:`secondary`,"aria-label":B(`connection.guests.narrowNamed`,{name:X(e)}),busy:a.isPending&&a.variables?.id===e.id,onClick:()=>a.mutate(e),children:B(`connection.guests.narrow`)})]},e.id))}),a.error?(0,H.jsx)(`p`,{className:`mt-1 text-[0.8125rem] text-rose`,children:a.error.message}):null]}):null}function at({spaceId:e,connectors:t,initial:n,onCancel:r,onDone:a}){let o=u(),c=t.filter(e=>e.usable),[l,d]=(0,V.useState)(c.some(e=>e.id===n)?n:``),f=c.find(e=>e.id===l),[m,g]=(0,V.useState)(f?.name??``),_=Ye(),[v,y]=(0,V.useState)(_.allowed&&f?.auth===`oauth2`?`person`:`space`),[b,S]=(0,V.useState)(f?.fromAddress?`admins`:`members`),[w,E]=(0,V.useState)(!1),D=M({mutationFn:()=>s.post(`/api/studio/spaces/${e}/connections`,{connectorId:l,name:m.trim()||f?.name,signIn:v,audience:b}),onSuccess:async t=>{await o.invalidateQueries({queryKey:q(e)}),await o.invalidateQueries({queryKey:[`person-sign-ins`]}),a(t.id)}});return(0,H.jsx)(h,{className:`p-3.5 sm:p-5`,children:(0,H.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),l&&D.mutate()},className:`flex flex-col gap-5`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`font-display font-semibold text-base`,children:B(`capabilities.connectors.add`)}),(0,H.jsx)(`p`,{className:`mt-1 text-[0.8125rem] text-ink-3`,children:B(`connection.setupHint`)})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(C,{children:B(`connection.connector`)}),(0,H.jsx)(x,{value:l,onChange:e=>{let t=c.find(t=>t.id===e);(!m.trim()||m===f?.name)&&g(t?.name??``),w||S(t?.fromAddress?`admins`:`members`),d(e)},placeholder:B(`connection.connectorPick`),options:c.map(e=>({value:e.id,label:e.name}))})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(C,{hint:B(`connection.nameHint`),children:B(`connection.name`)}),(0,H.jsx)(p,{value:m,maxLength:Pe.name,placeholder:B(`connection.namePlaceholder`),onChange:e=>g(e.target.value)})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(C,{hint:B(qe[v]),children:B(`connection.signIn`)}),(0,H.jsx)(T,{label:B(`connection.signIn`),value:v,onChange:y,options:Ae.map(e=>({id:e,label:B(Ke[e]),disabled:e===`person`&&!_.allowed}))}),(0,H.jsx)(`p`,{className:`mt-2 text-[0.75rem] text-ink-3`,children:_.why??B(`connection.signInLater`)})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(C,{hint:B(He[b]),children:B(`connection.audience`)}),(0,H.jsx)(T,{label:B(`connection.audience`),value:b,onChange:e=>{S(e),E(!0)},options:je.map(e=>({id:e,label:B(J[e])}))}),f?.fromAddress?(0,H.jsx)(`p`,{className:`mt-2 text-[0.75rem] text-ink-3`,children:B(`connectors.address.adminsFirst`)}):null]}),D.error?(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:D.error.message}):null,(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsx)(i,{type:`submit`,busy:D.isPending,disabled:!l,children:B(`capabilities.connectors.setUp`)}),(0,H.jsx)(i,{type:`button`,variant:`ghost`,onClick:r,children:B(`orgSettings.cancel`)})]})]})})}function ot({connection:e,connector:t,writable:n,onGone:r}){let a=u(),o=q(e.spaceId),c=()=>a.invalidateQueries({queryKey:o}),[l,d]=(0,V.useState)(e.name),[f,m]=(0,V.useState)(!1),[g,_]=(0,V.useState)(null),v=Ye(),y=`/api/studio/connections/${encodeURIComponent(e.id)}`,b=M({mutationFn:e=>s.patch(y,e),onSuccess:e=>{a.setQueryData(o,t=>t&&{connections:t.connections.map(t=>t.id===e.id?e:t)}),a.invalidateQueries({queryKey:[`person-sign-ins`]})}}),x=M({mutationFn:()=>s.del(y),onSuccess:async()=>{await c(),a.invalidateQueries({queryKey:[`person-sign-ins`]}),r()}}),S=M({mutationFn:e=>s.post(`${y}/${e?`pause`:`resume`}`),onSuccess:e=>{a.setQueryData(o,t=>t&&{connections:t.connections.map(t=>t.id===e.id?e:t)}),a.invalidateQueries({queryKey:[`person-sign-ins`]})}}),C=W(`${y}/sign-in`,c),E=W(`${y}/my-sign-in`,c),O=()=>{let t=l.trim();t&&t!==e.name?b.mutate({name:t}):d(e.name)},k=e.connector?.name??e.connectorId,A=e.connector?.fields??[],j=e.setUpByName?B(`konto.connectionSetUpBy`,{name:e.setUpByName,when:Y(e.setUpAt)}):B(`konto.connectionSetUpAt`,{when:Y(e.setUpAt)}),N=e.plugin?B(`connection.signIn.pluginSpace`,{plugin:Z(e)}):v.allowed?null:e.signIn===`person`?B(`connection.signIn.personKept`):v.why,P=n=>(t?.actions??[]).filter(e=>e.group===n).filter(t=>!e.actions.length||e.actions.includes(t.id));return(0,H.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[e.pausedAt?(0,H.jsxs)(`div`,{role:`status`,className:`flex flex-wrap items-center gap-x-4 gap-y-3 rounded-xl bg-ember-tint p-3.5 sm:px-5`,children:[(0,H.jsx)(fe,{className:`size-5 shrink-0 text-ember-strong`,"aria-hidden":`true`}),(0,H.jsx)(`p`,{className:`min-w-48 flex-1 text-[0.875rem] text-ink`,children:e.pausedByName?B(`connection.pausedNoteBy`,{name:e.pausedByName,when:Y(e.pausedAt)}):B(`connection.pausedNote`,{when:Y(e.pausedAt)})}),n?(0,H.jsx)(i,{size:`sm`,busy:S.isPending,onClick:()=>S.mutate(!1),children:B(`connection.resume`)}):null]}):null,(0,H.jsxs)(`div`,{className:`flex items-center gap-4 px-1`,children:[(0,H.jsx)(et,{name:k,large:!0}),(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsxs)(`h2`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1 font-display font-semibold text-lg leading-tight`,children:[k,e.connector?.fromAddress?(0,H.jsx)(D,{tone:`warn`,title:B(`connectors.uncheckedHint`),children:B(`connectors.unchecked`)}):null]}),e.connector?.description?(0,H.jsx)(`p`,{className:`mt-1 line-clamp-2 text-[0.875rem] text-ink-3`,children:e.connector.description}):null]})]}),(0,H.jsxs)(h,{className:`flex flex-col gap-5 p-3.5 sm:p-5`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,children:[n?(0,H.jsx)(p,{"aria-label":B(`connection.name`),className:`max-w-sm font-semibold`,value:l,maxLength:Pe.name,onChange:e=>d(e.target.value),onBlur:O,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),O())}}):(0,H.jsx)(`b`,{className:`text-[0.9375rem]`,children:e.name}),(0,H.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:n?j:B(`connection.adminsManage`)})]}),(0,H.jsx)(Q,{label:B(`connection.signIn`),children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[n?(0,H.jsx)(`div`,{className:`max-w-full overflow-x-auto`,children:(0,H.jsx)(T,{label:B(`connection.signIn`),value:e.signIn,onChange:t=>_(t===e.signIn?null:t),options:Ae.map(e=>({id:e,label:B(Ke[e]),disabled:e===`person`&&!!N}))})}):(0,H.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.875rem]`,children:[e.signIn===`space`?(0,H.jsx)(I,{className:`size-4 text-ink-3`,"aria-hidden":`true`}):(0,H.jsx)(te,{className:`size-4 text-ink-3`,"aria-hidden":`true`}),B(Ke[e.signIn])]}),(0,H.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:B(qe[e.signIn])}),n&&N?(0,H.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:N}):null,n&&g?(0,H.jsxs)(`div`,{className:`mt-1 flex flex-col gap-3 rounded-lg bg-paper p-3 text-[0.875rem] ring-1 ring-border-soft`,children:[(0,H.jsx)(`p`,{children:B(g===`space`?`connection.signIn.toSpaceConfirm`:`connection.signIn.toPersonConfirm`)}),(0,H.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,H.jsx)(i,{variant:`ghost`,onClick:()=>_(null),children:B(`orgSettings.cancel`)}),(0,H.jsx)(i,{busy:b.isPending,onClick:()=>b.mutate({signIn:g},{onSettled:()=>_(null)}),children:B(`connection.signIn.change`)})]})]}):null]})}),e.signIn===`space`?(0,H.jsx)(Q,{label:B(`connection.account`),children:(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,H.jsx)(`span`,{className:`text-[0.875rem]`,children:e.account?B(`connection.accountSignedIn`,{label:e.account.label}):B(n?`connection.accountNotYetAdmin`:`connection.accountNotYet`)}),n?(0,H.jsx)(G,{s:C,auth:e.connector?.auth,signedIn:!!e.account}):null]}),n?(0,H.jsx)(K,{s:C,fields:A,signedIn:!!e.account,confirmText:B(`connection.signOutSpaceConfirm`,{name:X(e)})}):null]})}):(0,H.jsx)(Q,{label:B(`connection.people`),children:(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,H.jsxs)(`span`,{className:`text-[0.875rem]`,children:[B(`connection.peopleSignedIn`,{n:e.signedIn}),` · `,e.mySignIn?B(`connection.youSignedIn`,{label:e.mySignIn.label}):B(`connection.youNotYet`)]}),(0,H.jsx)(G,{s:E,auth:e.connector?.auth,signedIn:!!e.mySignIn})]}),(0,H.jsx)(K,{s:E,fields:A,signedIn:!!e.mySignIn,confirmText:B(`konto.connectionSignOutConfirm`,{name:X(e)})})]})}),(0,H.jsx)(Q,{label:B(`connection.audience`),children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[n?(0,H.jsx)(`div`,{children:(0,H.jsx)(T,{label:B(`connection.audience`),value:e.audience,onChange:e=>b.mutate({audience:e}),options:je.map(e=>({id:e,label:B(J[e])}))})}):(0,H.jsx)(`span`,{children:(0,H.jsx)(D,{children:B(J[e.audience])})}),(0,H.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:B(He[e.audience])}),n&&e.plugin&&U(e)?(0,H.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:B(`connection.guests.plugin`,{plugin:Z(e)})}):null]})}),(0,H.jsx)(`div`,{className:`border-border-soft border-t`}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsx)(`h3`,{className:`font-semibold text-[0.875rem]`,children:B(`connection.rules`)}),Me.map(t=>{let r=P(t);return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`font-medium text-[0.875rem]`,children:B(Ue[t])}),(0,H.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:B(We[t])}),r.length?(0,H.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[0.6875rem] text-ink-4`,children:r.map(e=>e.id).join(` · `)}):null]}),(0,H.jsx)(`div`,{className:`shrink-0`,children:n?(0,H.jsx)(T,{label:B(Ue[t]),value:e.rules[t],onChange:n=>b.mutate({rules:{...e.rules,[t]:n}}),options:Ne.map(e=>({id:e,label:B(Ge[e])}))}):(0,H.jsx)(D,{tone:e.rules[t]===`ask`?`warn`:`neutral`,children:B(Ge[e.rules[t]])})})]},t)}),(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:B(n?`connection.askHint`:`connection.askHintMember`)})]}),(0,H.jsx)(`div`,{className:`border-border-soft border-t`}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3 gap-y-1`,children:[(0,H.jsx)(`h3`,{className:`font-semibold text-[0.875rem]`,children:B(`connection.limits`)}),(0,H.jsx)(`span`,{className:`min-w-48 flex-1 text-[0.8125rem] text-ink-3`,children:B(`connection.limitsHint`)})]}),(0,H.jsx)(Q,{label:B(`connection.limits.perRun`),children:(0,H.jsx)(st,{label:B(`connection.limits.perRun`),hint:B(`connection.limits.perRunHint`),limit:e.callsPerRun,writable:n,onSave:e=>b.mutate({callsPerRun:e})})}),(0,H.jsx)(Q,{label:B(`connection.limits.perDay`),children:(0,H.jsx)(st,{label:B(`connection.limits.perDay`),hint:B(`connection.limits.perDayHint`),limit:e.callsPerDay,writable:n,onSave:e=>b.mutate({callsPerDay:e})})})]}),b.error?(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:b.error.message}):null]}),(0,H.jsxs)(h,{className:`flex flex-col gap-1 p-3.5 sm:p-5`,children:[(0,H.jsx)(Q,{label:B(`connection.use`),children:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,H.jsxs)(`span`,{className:`text-[0.875rem] tabular-nums`,children:[Re(e),(0,H.jsxs)(`span`,{className:`text-ink-3`,children:[` · `,Ze(e)]})]}),(0,H.jsx)(w,{to:`/capabilities/protocol?connection=${encodeURIComponent(e.id)}`,className:`inline-flex h-8 items-center rounded-full bg-paper-2 px-3 font-medium text-[0.8125rem] text-ink transition hover:bg-paper-3 coarse:h-11 coarse:px-4`,children:B(`connection.inAudit`)})]})}),e.plugin?(0,H.jsx)(Q,{label:B(`connection.plugin`),children:(0,H.jsx)(`span`,{className:`text-[0.875rem]`,children:B(`connection.pluginUses`,{plugin:Z(e)})})}):null]}),n?(0,H.jsxs)(`div`,{className:`px-1`,children:[f?(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-lg bg-paper p-3 text-[0.875rem] ring-1 ring-border-soft`,children:[(0,H.jsx)(`p`,{className:`min-w-48 flex-1`,children:B(`connection.removeConfirm`,{name:X(e)})}),(0,H.jsx)(i,{variant:`ghost`,onClick:()=>m(!1),children:B(`orgSettings.cancel`)}),(0,H.jsx)(i,{variant:`danger`,busy:x.isPending,onClick:()=>x.mutate(),children:B(`connection.remove`)})]}):(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3`,children:[e.pausedAt?null:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(i,{variant:`secondary`,size:`sm`,busy:S.isPending,onClick:()=>S.mutate(!0),children:B(`connection.pause`)}),(0,H.jsx)(`p`,{className:`min-w-48 flex-1 text-[0.8125rem] text-ink-3`,children:B(`connection.pauseHint`)})]}),(0,H.jsx)(i,{variant:`danger`,size:`sm`,onClick:()=>m(!0),children:B(`connection.remove`)})]}),x.error||S.error?(0,H.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-rose`,children:(x.error??S.error).message}):null]}):null]})}function st({label:e,hint:t,limit:n,writable:r,onSave:i}){let[a,o]=(0,V.useState)(Ie(n));(0,V.useEffect)(()=>o(Ie(n)),[n]);let s=()=>{let e=Le(a);e===void 0||e===n?o(Ie(n)):i(e)};return(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[r?(0,H.jsx)(p,{"aria-label":e,inputMode:`numeric`,className:`w-24 text-right tabular-nums`,value:a,onChange:e=>o(e.target.value.replace(/\D/g,``)),onBlur:s,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),s())}}):(0,H.jsx)(`span`,{className:`text-[0.875rem] tabular-nums`,children:n===null?B(`connection.limits.none`):n.toLocaleString(z)}),(0,H.jsx)(`span`,{className:`min-w-48 flex-1 text-[0.8125rem] text-ink-3`,children:t})]})}function Q({label:e,children:t}){return(0,H.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-[11rem_minmax(0,1fr)] sm:gap-4`,children:[(0,H.jsx)(`span`,{className:`pt-0.5 text-[0.8125rem] text-ink-3`,children:e}),t]})}var ct={not_connected:`protocol.refused.not_connected`,no_action:`protocol.refused.no_action`,not_in_grant:`protocol.refused.not_in_grant`,denied:`protocol.refused.denied`,declined:`protocol.refused.declined`,nobody:`protocol.refused.nobody`,needs_approval:`protocol.refused.needs_approval`,ai_step_writes:`protocol.refused.ai_step_writes`,not_allowed_recipient:`protocol.refused.not_allowed_recipient`,channel_not_fixed:`protocol.refused.channel_not_fixed`,run_limit:`protocol.refused.run_limit`,day_limit:`protocol.refused.day_limit`,calls_per_run:`protocol.refused.calls_per_run`,calls_per_day:`protocol.refused.calls_per_day`,run_ended:`protocol.refused.run_ended`,paused:`protocol.refused.paused`},lt={"run.cancelled":`protocol.why.runStopped`,"run.done":`protocol.why.runDone`,"run.failed":`protocol.why.runFailed`},ut={read:`protocol.kind.read`,write:`protocol.kind.write`,destructive:`protocol.kind.destructive`,send:`protocol.kind.send`},dt={read:`protocol.verb.read`,write:`protocol.verb.write`,destructive:`protocol.verb.destructive`,send:`protocol.verb.send`},ft={refused_write:`work.critical.refused_write`,outside_audience:`work.critical.outside_audience`,host_not_in_grant:`work.critical.host_not_in_grant`,limit_reached:`work.critical.limit_reached`,sign_in_failed:`work.critical.sign_in_failed`,first_use:`work.critical.first_use`,rule_changed:`work.critical.rule_changed`},pt={grant:`protocol.rule.grant`,audience:`protocol.rule.audience`,actions:`protocol.rule.actions`,ai_step_writes:`protocol.rule.ai_step_writes`,destructive:`protocol.rule.destructive`,policy:`protocol.rule.policy`,read:`protocol.rule.read`,own_job:`protocol.rule.own_job`,guest_send:`protocol.rule.guest_send`,run:`protocol.rule.run`,paused:`protocol.rule.paused`,limits:`protocol.rule.limits`},mt={admins:`protocol.audience.admins`,members:`protocol.audience.members`,all:`protocol.audience.all`};function ht(e){return e in ut}function gt(e){return ht(e)?B(ut[e]):e}function _t(e){return ht(e)?B(dt[e]):e}function vt(e){return e&&e in ft?B(ft[e]):``}function yt(e){if(!e)return B(`protocol.rule.none`);if(e.startsWith(`rules.`))return B(`protocol.rule.rules`,{kind:gt(e.slice(6))});let t=pt[e]??pt[e.split(`.`)[0]??``];return t?B(t):e}function bt(e,t,n){return e===`run_ended`&&t&&t in lt?B(lt[t]):e&&e!==`denied`&&e in ct?B(ct[e]):t===`audience`?n&&n in mt?B(`protocol.why.audienceFor`,{audience:B(mt[n])}):B(`protocol.why.audience`):t===`actions`?B(`protocol.why.actions`):t===`grant`?B(`protocol.refused.not_in_grant`):t?.startsWith(`rules.`)?B(`protocol.why.rule`):B(`protocol.refused.denied`)}var xt={waiting_input:`runs.status.waiting_input`,sleeping:`runs.status.sleeping`,running:`runs.status.running`,done:`runs.status.done`,failed:`runs.status.failed`,cancelled:`protocol.detail.runStopped`};function St(e){let t=xt[e];return t?B(t):e}function Ct(e){return e===`running`||e===`waiting_input`||e===`sleeping`}function wt(e){let{outcome:t,result:n,rule:r}=e;return n===null&&t!==`deny`?{tone:`held`,text:B(`protocol.outcome.running`)}:n===`ok`?{tone:`done`,text:B(t===`ask`?`protocol.outcome.doneApproved`:`protocol.outcome.done`)}:n===`needs_approval`?{tone:`held`,text:B(`protocol.outcome.held`)}:n===`sign_in_failed`?{tone:`failed`,text:B(`protocol.outcome.signInFailed`)}:n===`nobody`||n===`not_connected`?{tone:`failed`,text:B(`protocol.outcome.notDone`,{why:B(ct[n])})}:t===`deny`||n===`declined`?{tone:`refused`,text:B(`protocol.outcome.refused`,{why:bt(n,r)})}:{tone:`failed`,text:B(`protocol.outcome.failed`,{error:n??``})}}function Tt(e){switch(e.kind){case`guest`:return B(`protocol.who.guest`);case`person`:return e.name??B(`protocol.who.person`);case`admin`:return e.name?B(`protocol.who.adminNamed`,{name:e.name}):B(`protocol.who.admin`);case`goose`:return e.name?B(`protocol.who.gooseFor`,{name:e.name}):B(`protocol.who.goose`);case`plugin`:return B(`protocol.who.plugin`,{name:e.id??``});case`step`:return e.for?e.for.kind===`guest`?B(`protocol.who.stepForGuest`):B(`protocol.who.stepFor`,{name:e.for.name??B(`protocol.who.person`)}):B(`protocol.who.step`);default:return e.kind}}function Et(e){return e.runId?e.wizardName?B(e.runMode===`test`?`protocol.where.testRunOf`:`protocol.where.runOf`,{wizard:e.wizardName}):B(`protocol.where.run`):e.chatId?e.chatTitle?B(`protocol.where.chatNamed`,{title:e.chatTitle}):B(`protocol.where.chat`):e.who.kind===`goose`?B(`protocol.where.goose`):e.who.kind===`plugin`?B(`protocol.where.plugin`):``}function Dt(e){let{connectionId:t}=e;return e.connectionName?e.connectorName&&!e.connectionName.includes(e.connectorName)?`${e.connectorName} · ${e.connectionName}`:e.connectionName:t.startsWith(`host:`)?B(`protocol.connection.host`,{host:t.slice(5)}):t===`mail:server`?B(`protocol.connection.serverMail`):t===`rwx`?B(`protocol.connection.rwx`):e.connectorName?`${e.connectorName} · ${t}`:t}function Ot(e){switch(e.actionId){case`change_rules`:return e.input?.fields&&`paused`in e.input.fields?B(e.input.sample===`paused: yes`?`protocol.action.paused`:`protocol.action.resumed`):e.input?.fields&&Object.keys(e.input.fields).join()===`limits`?B(`protocol.action.limits`):B(`protocol.action.changeRules`);case`http_request`:return B(`protocol.action.request`);case`read_secret`:return B(`protocol.action.readSecret`);case`send_message`:return e.actionName??B(`protocol.action.sendMail`);default:return e.actionName??e.actionId}}function kt(e,t){let n={who:t.who,connection:t.connection,verb:_t(e.action.kind)};return e.outcome===`allow`?B(`protocol.ask.allow`,n):e.outcome===`ask`?B(e.admins?`protocol.ask.askAdmins`:`protocol.ask.askPerson`,n):B(`protocol.ask.deny`,{...n,why:bt(e.refused??null,e.rule,t.audience)})}function At(e){return e.fixedChannel?B(`protocol.ask.fixedChannel`):null}function jt(){let[e,t]=m(),{space:n}=ce(),a=ae(),o=e.get(`show`),c=a&&(o===`ask`||o===`notify`)?o:null,l=e=>t(e?{show:e}:{},{replace:!0}),u=e.get(`connection`)??``,d=_({queryKey:[`broker-choices`,n?.id],queryFn:()=>s.get(`/api/studio/spaces/${n?.id}/broker/choices`),enabled:!!n&&a});return n?a?(0,H.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[(0,H.jsx)(It,{spaceId:n.id,connection:u,action:(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsxs)(i,{variant:`secondary`,size:`sm`,onClick:()=>l(`ask`),children:[(0,H.jsx)(ne,{className:`size-4`}),` `,B(`protocol.ask.title`)]}),(0,H.jsx)(i,{variant:`secondary`,size:`sm`,onClick:()=>l(`notify`),"aria-label":B(`protocol.notify.title`),title:B(`protocol.notify.title`),children:(0,H.jsx)(r,{className:`size-4`})})]})}),(0,H.jsxs)(S,{open:c===`ask`,onClose:()=>l(null),wide:!0,title:B(`protocol.ask.title`),children:[(0,H.jsx)(`p`,{className:`-mt-2 mb-4 text-[0.875rem] text-ink-3`,children:B(`protocol.ask.hint`)}),(0,H.jsx)(Gt,{choices:d.data,spaceId:n.id})]}),(0,H.jsxs)(S,{open:c===`notify`,onClose:()=>l(null),title:B(`protocol.notify.title`),children:[(0,H.jsx)(`p`,{className:`-mt-2 mb-4 text-[0.875rem] text-ink-3`,children:B(`protocol.notify.hint`)}),(0,H.jsx)(Jt,{space:n})]})]}):(0,H.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:(0,H.jsx)(It,{spaceId:n.id,own:!0,connection:u})}):null}var Mt={hour:36e5,day:864e5,week:6048e5,month:2592e6},Nt=[`guest`,`person`,`admin`,`goose`,`plugin`,`step`],Pt=50;function Ft(e,t=300){let[n,r]=(0,V.useState)(e);return(0,V.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function It({spaceId:e,own:t=!1,connection:n=``,action:r}){let[a,o]=(0,V.useState)(`all`),[l,u]=(0,V.useState)(``),[d,f]=(0,V.useState)(n),[p,m]=(0,V.useState)(`week`),[h,g]=(0,V.useState)(``),_=Ft(h).trim(),[y,b]=(0,V.useState)(null),S=ze(e).data?.connections??[],C=j({queryKey:[`broker-log`,e,{outcome:a,who:l,connection:d,range:p,q:_}],initialPageParam:null,queryFn:({pageParam:t})=>{let n=new URLSearchParams({limit:String(Pt)});return a===`refused`?n.set(`refused`,`true`):a===`critical`?n.set(`critical`,`true`):a===`held`&&n.set(`result`,`needs_approval`),l&&n.set(`who`,l),d&&n.set(`connection`,d),p!==`all`&&n.set(`since`,new Date(Date.now()-Mt[p]).toISOString()),_&&n.set(`q`,_),t&&n.set(`cursor`,t),s.get(`/api/studio/spaces/${e}/broker/log?${n}`)},getNextPageParam:e=>e.next}),w=C.data?.pages.flatMap(e=>e.lines)??[],E=a!==`all`||l!==``||d!==``||p!==`all`||_!==``,D=new Set(S.map(e=>e.id));return(0,H.jsx)(c,{title:B(`capabilities.protocol`),hint:B(t?`protocol.own.hint`:`protocol.hint`),action:r,plain:!0,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsx)(`div`,{className:`flex flex-wrap items-center gap-3`,children:(0,H.jsx)(T,{value:a,onChange:o,label:B(`protocol.filter.outcome`),options:[{id:`all`,label:B(`protocol.filter.all`)},{id:`refused`,label:B(`protocol.filter.refused`)},{id:`critical`,label:B(`protocol.filter.critical`)},{id:`held`,label:B(`protocol.filter.held`)}]})}),(0,H.jsxs)(`div`,{className:v(`grid gap-2`,t?`sm:grid-cols-2`:`sm:grid-cols-3`),children:[t?null:(0,H.jsx)(x,{value:l,onChange:u,placeholder:B(`protocol.filter.everyone`),options:Nt.map(e=>({value:e,label:B(`protocol.filter.who.${e}`)}))}),(0,H.jsx)(x,{value:d,onChange:f,placeholder:B(`protocol.filter.everyConnection`),options:S.map(e=>({value:e.id,label:e.connector?`${e.connector.name} · ${e.name}`:e.name}))}),(0,H.jsx)(x,{value:p,onChange:e=>m(e),options:[`hour`,`day`,`week`,`month`,`all`].map(e=>({value:e,label:B(`protocol.range.${e}`)}))})]}),(0,H.jsx)(A,{value:h,onChange:g,placeholder:B(t?`protocol.own.search`:`protocol.search`),busy:C.isFetching&&!C.isFetchingNextPage}),C.error?(0,H.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:C.error.message}):C.isPending?(0,H.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,H.jsx)(O,{className:`text-ink-3`})}):w.length===0?(0,H.jsx)(`p`,{className:`py-12 text-center text-[0.9375rem] text-ink-3`,children:B(E?`protocol.emptyFiltered`:t?`protocol.own.empty`:`protocol.empty`)}):(0,H.jsx)(`ul`,{className:`flex flex-col gap-2`,children:w.map(t=>(0,H.jsx)(`li`,{children:(0,H.jsx)(Bt,{line:t,spaceId:e,open:y===t.id,onToggle:()=>b(y===t.id?null:t.id),ofSpace:D.has(t.connectionId)})},t.id))}),C.hasNextPage?(0,H.jsx)(`div`,{className:`flex justify-center`,children:(0,H.jsx)(i,{variant:`quiet`,size:`sm`,busy:C.isFetchingNextPage,onClick:()=>void C.fetchNextPage(),children:B(`protocol.more`)})}):null]})})}var Lt={done:ie,refused:me,held:o,failed:k},Rt={done:`text-moss`,refused:`text-rose`,held:`text-ember`,failed:`text-ink-3`};function zt(e,t=!1){return new Date(e).toLocaleString(z,{dateStyle:t?`medium`:`short`,timeStyle:t?`medium`:`short`})}function Bt({line:e,spaceId:t,open:n,onToggle:r,ofSpace:i}){let a=wt(e),o=Lt[a.tone],s=Et(e),c=e.critical||a.tone===`refused`;return(0,H.jsxs)(`div`,{className:v(`rounded-xl bg-card ring-1 transition`,e.critical?`ring-ember/50`:a.tone===`refused`?`ring-rose/40`:`ring-border-soft`),children:[(0,H.jsxs)(`button`,{type:`button`,onClick:r,"aria-expanded":n,className:`flex w-full items-start gap-3 px-3.5 py-3 text-left`,children:[(0,H.jsx)(o,{className:v(`mt-0.5 size-4 shrink-0`,Rt[a.tone])}),(0,H.jsxs)(`span`,{className:`grid min-w-0 flex-1 gap-0.5`,children:[(0,H.jsxs)(`span`,{className:`text-[0.9375rem] text-ink leading-snug`,children:[(0,H.jsx)(`b`,{className:`font-medium`,children:Tt(e.who)}),` · `,gt(e.kind),`: `,Ot(e),` · `,Dt(e)]}),(0,H.jsxs)(`span`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:[zt(e.at),s?` · ${s}`:``,` · `,(0,H.jsx)(`span`,{className:v(c&&Rt[a.tone],c&&`font-medium`),children:a.text})]})]}),e.critical?(0,H.jsx)(`span`,{className:`shrink-0`,children:(0,H.jsx)(D,{tone:`ember`,icon:(0,H.jsx)(L,{className:`size-3`}),title:vt(e.criticalKind),children:B(`protocol.critical`)})}):null,(0,H.jsx)(f,{className:v(`mt-0.5 size-4 shrink-0 text-ink-4 transition-transform`,n&&`rotate-180`)})]}),n?(0,H.jsx)(Vt,{line:e,spaceId:t,ofSpace:i}):null]})}function $({label:e,children:t}){return(0,H.jsxs)(`div`,{className:`grid gap-0.5 sm:grid-cols-[11rem_minmax(0,1fr)] sm:gap-3`,children:[(0,H.jsx)(`dt`,{className:`text-[0.8125rem] text-ink-3`,children:e}),(0,H.jsx)(`dd`,{className:`min-w-0 break-words text-[0.875rem] text-ink-2`,children:t})]})}function Vt({line:e,spaceId:t,ofSpace:n}){let r=_({queryKey:[`broker-line`,t,e.id],queryFn:()=>s.get(`/api/studio/spaces/${t}/broker/log/${e.id}`)}),a=r.data?.run,o=ae(),c=u(),l=M({mutationFn:()=>s.post(`/api/runs/${e.runId}/cancel`),onSuccess:()=>c.invalidateQueries({queryKey:[`broker-line`,t]})}),d=e.input,f=Object.keys(d?.fields??{}),p=e.connectionId.startsWith(`host:`);return(0,H.jsxs)(`div`,{className:`border-border-soft border-t px-3.5 py-3`,children:[(0,H.jsxs)(`dl`,{className:`grid gap-2`,children:[(0,H.jsxs)($,{label:B(`protocol.detail.when`),children:[zt(e.at,!0),` · `,B(`protocol.detail.duration`,{ms:e.durationMs})]}),e.critical?(0,H.jsx)($,{label:B(`protocol.critical`),children:vt(e.criticalKind)}):null,(0,H.jsxs)($,{label:B(`protocol.detail.input`),children:[f.length?B(`protocol.detail.inputFields`,{fields:f.join(`, `),size:d?.size??0}):B(`protocol.detail.inputEmpty`),d?.sample?(0,H.jsx)(`span`,{className:`mt-0.5 block font-mono text-[0.8125rem] text-ink-3`,children:d.sample}):null]}),(0,H.jsx)($,{label:B(`protocol.detail.result`),children:e.resultSize===null?B(`protocol.detail.resultNone`):B(`protocol.detail.resultSize`,{size:e.resultSize})}),(0,H.jsxs)($,{label:B(`protocol.detail.rule`),children:[yt(e.rule),e.reason?(0,H.jsx)(`span`,{className:`mt-0.5 block text-[0.8125rem] text-ink-3`,children:e.reason}):null]}),a?(0,H.jsx)($,{label:B(`protocol.detail.run`),children:St(a.status)}):null,e.runId?(0,H.jsx)($,{label:B(`protocol.detail.grant`),children:r.isPending?(0,H.jsx)(O,{className:`size-4 text-ink-3`}):n?B(`protocol.detail.grantSpace`):a?.grant?p?a.grant.hosts.length?B(`protocol.detail.grantHosts`,{hosts:a.grant.hosts.join(`, `)}):B(`protocol.detail.grantNoHosts`):a.grant.actions?.length?B(`protocol.detail.grantActions`,{actions:a.grant.actions.join(`, `)}):B(`protocol.detail.grantNoActions`):B(`protocol.detail.grantNone`)}):null]}),(0,H.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[e.runId&&e.wizardId?(0,H.jsx)(Ht,{to:`/edit/${e.wizardId}?run=${e.runId}`,children:B(`protocol.detail.openRun`)}):null,e.chatId?(0,H.jsx)(Ht,{to:`/work/c/${e.chatId}`,children:B(`protocol.detail.openChat`)}):null,n?(0,H.jsx)(Ht,{to:`/capabilities/connectors?show=${e.connectionId}`,children:B(`protocol.detail.openConnection`)}):null,o&&a&&Ct(a.status)?(0,H.jsx)(`span`,{className:`sm:ml-auto`,children:(0,H.jsx)(i,{variant:`danger`,size:`sm`,busy:l.isPending,onClick:async()=>{await y(B(`protocol.detail.stopRunAsk`),{detail:B(`protocol.detail.stopRunDetail`),action:B(`protocol.detail.stopRun`)})&&l.mutate()},children:B(`protocol.detail.stopRun`)})}):null]}),l.error?(0,H.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-rose`,children:l.error.message}):null]})}function Ht({to:e,children:t}){return(0,H.jsx)(w,{to:e,className:`inline-flex h-8 items-center rounded-full bg-paper-2 px-3 font-medium text-[0.8125rem] text-ink transition hover:bg-paper-3 coarse:h-11 coarse:px-4`,children:t})}function Ut(e,t){if(e.startsWith(`person:`)){let n=t.people.find(t=>`person:${t.id}`===e);return{who:n&&n.role!==`member`?`admin`:`person`}}return e.startsWith(`step:`)?{who:`step`,for:e.slice(5)}:{who:e}}function Wt(e,t){return e.startsWith(`person:`)?t.people.find(t=>`person:${t.id}`===e)?.name??``:B(e===`guest`?`protocol.ask.who.guest`:e===`goose`?`protocol.ask.who.goose`:`protocol.ask.who.step`)}function Gt({choices:e,spaceId:t}){let[n,r]=(0,V.useState)(``),[i,a]=(0,V.useState)(``),[o,c]=(0,V.useState)(``),[l,u]=(0,V.useState)(`run`),d=e?.connections.find(e=>e.id===i),f=d?.actions.find(e=>e.id===o),p=n.startsWith(`step:`)?`run`:l,m=!!(e&&n&&d&&f),h=_({queryKey:[`broker-ask`,t,n,i,o,p],queryFn:()=>{let r=new URLSearchParams({...Ut(n,e),resource:i,action:o,in:p});return s.get(`/api/studio/spaces/${t}/broker/ask?${r}`)},enabled:m});if(!e)return(0,H.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,H.jsx)(O,{className:`text-ink-3`})});let g=[...e.people.map(e=>({value:`person:${e.id}`,label:e.role===`member`?e.name:B(`protocol.who.adminNamed`,{name:e.name})})),{value:`guest`,label:B(`protocol.ask.who.guest`)},{value:`goose`,label:B(`protocol.ask.who.goose`)},{value:`step:guest`,label:B(`protocol.ask.who.stepGuest`)},{value:`step:person`,label:B(`protocol.ask.who.stepPerson`)}];return(0,H.jsx)(H.Fragment,{children:e.connections.length===0?(0,H.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:B(`protocol.ask.noConnections`)}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,H.jsx)(qt,{label:B(`protocol.ask.who`),children:(0,H.jsx)(x,{value:n,onChange:e=>r(e),placeholder:B(`protocol.ask.choose`),options:g})}),(0,H.jsx)(qt,{label:B(`protocol.ask.connection`),children:(0,H.jsx)(x,{value:i,onChange:e=>{a(e),c(``)},placeholder:B(`protocol.ask.choose`),options:e.connections.map(e=>({value:e.id,label:e.connector?`${e.connector.name} · ${e.name}`:e.name}))})}),(0,H.jsx)(qt,{label:B(`protocol.ask.action`),children:(0,H.jsx)(x,{value:o,onChange:c,placeholder:B(`protocol.ask.choose`),options:(d?.actions??[]).map(e=>({value:e.id,label:`${e.name} (${gt(e.kind)})`}))})}),(0,H.jsx)(qt,{label:B(`protocol.ask.where`),children:(0,H.jsx)(x,{value:p,onChange:e=>u(e),options:[{value:`run`,label:B(`protocol.ask.inRun`)},{value:`chat`,label:B(`protocol.ask.inChat`),disabled:n.startsWith(`step:`)}]})})]}),(0,H.jsx)(`div`,{className:`rounded-xl bg-paper-2 px-4 py-3.5`,children:m?h.error?(0,H.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:h.error.message}):h.data?(0,H.jsx)(Kt,{answer:h.data,who:Wt(n,e),connection:d?d.connector?`${d.connector.name} · ${d.name}`:d.name:``,audience:d?.audience}):(0,H.jsx)(O,{className:`size-4 text-ink-3`}):(0,H.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:B(`protocol.ask.pick`)})})]})})}function Kt({answer:e,who:t,connection:n,audience:r}){let i=e.outcome===`allow`?`done`:e.outcome===`ask`?`held`:`refused`,a=Lt[i],o=At(e);return(0,H.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,H.jsx)(a,{className:v(`mt-1 size-4 shrink-0`,Rt[i])}),(0,H.jsxs)(`div`,{className:`grid min-w-0 gap-1.5`,children:[(0,H.jsx)(`p`,{className:`font-medium text-[0.9375rem] text-ink leading-snug`,children:kt(e,{who:t,connection:n,audience:r})}),o?(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:o}):null,(0,H.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:B(`protocol.ask.rule`,{rule:yt(e.rule)})}),(0,H.jsx)(`div`,{children:(0,H.jsx)(Ht,{to:`/capabilities/connectors?show=${e.connection.id}`,children:B(`protocol.ask.change`)})})]})]})}function qt({label:e,children:t}){return(0,H.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,H.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink-2`,children:e}),t]})}function Jt({space:e}){let t=u(),[n,r]=(0,V.useState)(!1),[i,a]=(0,V.useState)(null),o=e.notify??{bell:!0,mail:`hourly`},c=async n=>{r(!0),a(null);try{await s.patch(`/api/studio/spaces/${e.id}`,{notify:n}),await t.invalidateQueries({queryKey:d.spaces()})}catch(e){a(e.message)}finally{r(!1)}},l=e.readOnly||n;return(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsx)(Yt,{label:B(`protocol.notify.bell`),hint:B(`protocol.notify.bellHint`),checked:o.bell,disabled:l,onChange:e=>void c({...o,bell:e})}),(0,H.jsx)(Yt,{label:B(`protocol.notify.mail`),hint:B(`protocol.notify.mailHint`),checked:o.mail===`hourly`,disabled:l,onChange:e=>void c({...o,mail:e?`hourly`:`off`})}),i?(0,H.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:i}):null]})}function Yt({label:e,hint:t,checked:n,disabled:r,onChange:i}){return(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`font-medium text-[0.9375rem] text-ink`,children:e}),(0,H.jsx)(`div`,{className:`mt-0.5 text-[0.8125rem] text-ink-3`,children:t})]}),(0,H.jsx)(g,{checked:n,onChange:i,label:e,disabled:r})]})}export{it as a,ze as c,Fe as d,W as f,me as h,tt as i,G as l,De as m,jt as n,Ve as o,U as p,rt as r,Be as s,Jt as t,K as u};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$t as r,Q as i,at as a,gr as o,hn as s,hr as c,in as l,lr as u,mr as d,mt as f,nr as p,pr as m,pt as h,qt as g,un as _,vt as v,yt as ee}from"./ui-DAk_vjrL.js";import{d as y,n as b}from"./marked.esm-DQ7XA7AC.js";import{c as x}from"./read-aloud-CnFwDSGD.js";import{_ as S,b as C,d as w,f as te,g as T,h as E,m as D,n as ne,p as re,v as O,y as k}from"./theme-CkNTe-_Z.js";import{C as A,S as j,k as ie,x as M}from"./session-BMiUrqHg.js";import{J as N,a as P,l as F,s as I}from"./i18n-BaPKbQ1s.js";import{n as L}from"./LangSwitch-CJ00IgaO.js";var R={name:`bookmark`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};R.node;var ae=y(R),z={name:`square-plus`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]],aliases:[`plus-square`]};z.node;var oe=y(z),B=e(t(),1);function se(){if(window.self===window.top)return null;let e=new URLSearchParams(window.location.search).get(`embed`);return e===`inline`||e===`modal`||e===`popout`?e:null}var V=se(),ce=V?new URLSearchParams(window.location.search).get(`page`):null,H=new URLSearchParams(window.location.search).get(`theme`),U=H?`?theme=${encodeURIComponent(H)}`:``,W=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),le=()=>W(`close`);function ue(e){(0,B.useEffect)(()=>{if(V===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>W(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(V===`modal`||V===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&W(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var G=e(n(),1),K=`wizards.runner.translate`,q=new Set;function de(){try{return localStorage.getItem(K)===`on`}catch{return!1}}function fe(e){try{localStorage.setItem(K,e?`on`:`off`)}catch{}for(let e of q)e()}function pe(){return(0,B.useSyncExternalStore)(e=>(q.add(e),()=>q.delete(e)),de)}function me(e){let t=pe(),[n]=(0,B.useState)(()=>F()),r=e?.lang??`en`,a=e?.translatable&&n&&n!==r?n:null,s=a&&t?a:r,c=e?.token,l=o({queryKey:[`public-translation`,c,s],enabled:!!(c&&s!==r),queryFn:()=>i.post(`/api/public/wizards/${c}/translation${U}`,{lang:s}),staleTime:1/0,retry:!1}),u=o({queryKey:[`public-texts`,c,s],enabled:!(!c||N(s)),queryFn:()=>i.get(`/api/public/wizards/${c}/texts/${s}`),staleTime:1/0,retry:!1}),d=!N(s),f=s===r||l.data&&(!d||u.data),p=s!==r&&(l.isError||d&&u.isError),m=f&&!p?s:r,h=(0,B.useMemo)(()=>!N(m)&&u.data?.lang===m?{lang:u.data.lang,runner:u.data.runner,notes:u.data.notes}:null,[m,u.data]);if((0,B.useEffect)(()=>{e&&P(m,h)},[e,m,h]),(0,B.useEffect)(()=>()=>P(null),[]),!e)return null;let g=m!==r&&l.data?l.data:null;return{own:r,other:a,shown:m,wizard:g??e,translating:s!==r&&!f&&!p,failed:!!p,translated:!!g,machine:g?.translation?.machine??!1,pick:e=>fe(e!==r)}}function J({page:e,tone:t=`ground`}){if(!e?.other)return null;let n=e.translating?e.other:e.shown;return(0,G.jsx)(L,{langs:[e.own,e.other],value:n,onPick:e.pick,tone:t})}function Y({page:e,small:t}){if(!e)return null;let n=t?`truncate text-[0.75rem]`:`text-[0.8125rem]`;return e.failed?(0,G.jsx)(`p`,{className:s(`text-ink-3`,n),children:I(`translation.failed`)}):e.translated?(0,G.jsxs)(`p`,{className:s(`text-ink-3`,n),children:[e.machine?(0,G.jsxs)(G.Fragment,{children:[I(`translation.machine`),` · `]}):null,(0,G.jsx)(`button`,{type:`button`,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,onClick:()=>e.pick(e.own),children:I(`translation.showOriginal`)})]}):null}function he(e,t){let n=(0,B.useRef)(null),r=t&&!t.translating?t.translated?t.shown:null:void 0;(0,B.useEffect)(()=>{if(!e||r===void 0)return;let t=`${e}:${r}`;n.current!==t&&(n.current=t,i.post(`/api/runs/${e}/lang`,{lang:r}).catch(()=>void 0))},[e,r])}function ge(e,t){(0,B.useEffect)(()=>{if(!e||!t)return;let n=h(`/api/public/wizards/${e}`),r=[{rel:`manifest`,href:`${n}/manifest.webmanifest`},{rel:`apple-touch-icon`,href:`${n}/icons/apple-touch-icon.png`},{rel:`icon`,href:`${n}/icons/favicon.png`,type:`image/png`}].flatMap(({rel:e,href:t,type:n})=>{let r=document.querySelector(`link[rel="${e}"]`);if(!r)return[];let i={href:r.getAttribute(`href`),type:r.getAttribute(`type`)};return r.setAttribute(`href`,t),n&&r.setAttribute(`type`,n),[{link:r,before:i}]}),i=document.createElement(`meta`);return i.name=`apple-mobile-web-app-title`,i.content=t,document.head.appendChild(i),()=>{for(let{link:e,before:t}of r)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);i.remove()}},[e,t])}var _e=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,X=_e||/Android/.test(navigator.userAgent);function ve(){let[e,t]=(0,B.useState)(()=>window.wizardInstall??null),[n,r]=(0,B.useState)(!1);if((0,B.useEffect)(()=>{let e=()=>t(window.wizardInstall??null);return window.addEventListener(`wizard-install`,e),()=>window.removeEventListener(`wizard-install`,e)},[]),window.matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0||X&&!e&&!_e)return null;let i=/Mac/.test(navigator.platform),a=I(X?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,G.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{X&&e?(e.prompt(),window.wizardInstall=null,t(null)):r(e=>!e)},className:`inline-flex items-center gap-1.5 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[X?(0,G.jsx)(oe,{className:`size-4`}):(0,G.jsx)(ae,{className:`size-4`}),I(X?`install.add`:`install.bookmark`)]}),n?(0,G.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function ye({brand:e,toggle:t=!0,start:n}){return(0,G.jsx)(`header`,{className:`safe-top`,children:(0,G.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[n?(0,G.jsx)(`div`,{className:`absolute left-3`,children:n}):null,e.logoUrl?(0,G.jsx)(`img`,{src:h(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,G.jsx)(`span`,{className:`max-w-[60%] truncate font-display font-semibold text-[0.9375rem] text-ink-2 tracking-tight`,children:e.name}):null,t?(0,G.jsx)(`div`,{className:`absolute right-3`,children:(0,G.jsx)(A,{})}):null]})})}function be({siteKey:e,onToken:t}){let n=(0,B.useRef)(null);return(0,B.useEffect)(()=>{let r=()=>{n.current&&window.turnstile&&!n.current.childElementCount&&window.turnstile.render(n.current,{sitekey:e,callback:t,appearance:`interaction-only`})};if(window.turnstile){r();return}let i=document.createElement(`script`);i.src=`https://challenges.cloudflare.com/turnstile/v0/api.js`,i.async=!0,i.onload=r,document.head.appendChild(i)},[e,t]),(0,G.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function xe({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||f||V?null:(0,G.jsxs)(`a`,{href:v(`${window.location.origin}${a}/w/${e}`),className:`mt-3 inline-flex items-center gap-1.5 text-[0.8125rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[(0,G.jsx)(C,{className:`size-4`}),` `,I(`install.app`)]})}var Z=e=>`wz.run.${e}`,Se=()=>m().state?.elsewhere===!0,Ce=f&&new URLSearchParams(window.location.search).get(`start`)===`1`,Q=V===`inline`?`min-h-80`:`min-h-dvh`;function $(e,t,n){let r=d(),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(null),f=(()=>{try{return localStorage.getItem(Z(e.token))}catch{return null}})();return{busy:a,error:s,captcha:l,setCaptcha:u,start:async()=>{o(!0),c(null);try{let{runId:a}=await i.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:l??void 0,embedded:V!==null,origin:ce??void 0,lang:n??void 0});try{localStorage.setItem(Z(e.token),a)}catch{}r(`${t}/${a}`,{replace:Ce})}catch(e){c(e.message),o(!1)}},resume:f?()=>r(`${t}/${f}`):null}}function we({wizard:e,page:t}){let{busy:n,error:i,captcha:a,setCaptcha:o,start:s,resume:c}=$(e,`/w/${e.token}`,t?.translated?t.shown:null),l=Se(),u=Ce&&e.available&&!e.turnstileSiteKey,d=(0,B.useRef)(!1);return(0,B.useEffect)(()=>{u&&!d.current&&(d.current=!0,s())},[u]),u&&!i?(0,G.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,G.jsx)(_,{})}):(0,G.jsxs)(`div`,{className:`mx-auto flex max-w-lg animate-rise flex-col items-center px-6 pt-6 pb-12 text-center sm:pt-16 sm:pb-16`,children:[l?(0,G.jsx)(`p`,{className:`mb-6 rounded-xl bg-paper-2 px-5 py-3 text-[0.875rem] text-ink-2`,children:I(`run.elsewhere`)}):null,(0,G.jsx)(j,{kind:e.avatar,costume:e.costume,size:190,fluffy:!0}),(0,G.jsx)(`h1`,{className:`wizard-title mt-2 text-balance font-display font-semibold text-[1.875rem] leading-[1.1] tracking-tight sm:text-[2.125rem]`,children:e.title}),e.description?(0,G.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,(0,G.jsx)(`div`,{className:`mt-3`,children:(0,G.jsx)(Y,{page:t})}),e.available?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(r,{size:`lg`,className:`mt-10 min-w-48`,busy:n,disabled:!!e.turnstileSiteKey&&!a,onClick:s,children:[I(`run.start`),` `,(0,G.jsx)(p,{className:`size-4`})]}),e.turnstileSiteKey?(0,G.jsx)(be,{siteKey:e.turnstileSiteKey,onToken:o}):null,c?(0,G.jsx)(`button`,{type:`button`,onClick:c,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:I(`run.resume`)}):null,(0,G.jsx)(Te,{wizard:e,current:`steps`}),V||f?null:(0,G.jsx)(ve,{}),(0,G.jsx)(xe,{token:e.token})]}):(0,G.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??I(`run.unavailable`)}),i?(0,G.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:i}):null]})}function Te({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,G.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,G.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:I(`run.orAs`,{label:e.label})},e.id))}):null}function Ee({wizard:e,page:t}){let n=k();return(0,G.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,G.jsxs)(`div`,{className:`mx-auto flex h-16 w-full max-w-[760px] items-center gap-3 pr-2 pl-4 sm:pr-4 sm:pl-6`,children:[(0,G.jsx)(`span`,{className:s(n?.speaking&&`animate-breathe`),children:(0,G.jsx)(j,{kind:e.avatar,costume:e.costume,size:38})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,G.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null,(0,G.jsx)(Y,{page:t,small:!0})]}),e.brand.logoUrl&&V!==`popout`?(0,G.jsx)(`img`,{src:h(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,(0,G.jsx)(J,{page:t,tone:`surface`}),V?null:(0,G.jsx)(A,{}),V===`popout`?(0,G.jsx)(l,{label:I(`common.close`),onClick:le,children:(0,G.jsx)(b,{className:`size-5`})}):null]})})}function De({door:e,wizard:t,page:n,header:r,footer:i}){let{busy:a,error:o,captcha:s,setCaptcha:c,start:l,resume:u}=$(t,`/w/${t.token}/${e}`,n?.translated?n.shown:null),d=Se(),f=[];return d&&f.push({key:`elsewhere`,who:`bot`,node:I(`run.elsewhere`)}),f.push({key:`hello`,who:`bot`,node:t.description||t.title}),e!==`chat`&&f.push({key:e,who:`bot`,node:I(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||f.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??I(`run.unavailable`)}),o&&f.push({key:`error`,who:`bot`,node:o,tone:`error`}),t.available&&f.push(O(`start`,(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(T,{primary:!0,busy:a,disabled:!!t.turnstileSiteKey&&!s,onClick:()=>void l(),children:[I(`run.start`),` `,(0,G.jsx)(p,{className:`size-4`})]}),u?(0,G.jsx)(T,{onClick:u,children:I(`run.resume`)}):null,t.turnstileSiteKey?(0,G.jsx)(be,{siteKey:t.turnstileSiteKey,onToken:c}):null]}))),(0,G.jsxs)(D,{header:r,footer:i,children:[(0,G.jsx)(S,{avatar:t.avatar,costume:t.costume,lines:f}),(0,G.jsx)(E,{})]})}function Oe({className:e}){return(0,G.jsx)(`footer`,{className:s(`text-center text-ink-4`,e),children:(0,G.jsx)(`a`,{href:`${a}/`,target:V?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:I(`run.madeWith`).replace(`engenty wizards`,M.name)})})}function ke({chat:e=!1,steps:t=!1,talk:n=!1,video:l=!1}){let{token:p,runId:m}=c(),h=d(),v=o({queryKey:[`public`,p,U],queryFn:()=>i.get(`/api/public/wizards/${p}${U}`),retry:(e,t)=>g(t)&&e<3}),y=v.data?.runners??[],b=!v.data||y.some(e=>e.id===`talk`),S=!v.data||y.some(e=>e.id===`video`),C=!v.data||y.some(e=>e.id===`chat`)||n&&b||l&&S,T=y[0]?.id,E=e||V===`popout`||!t&&!m&&C&&(T===`chat`||T===`talk`||T===`video`),D=l&&S||!t&&!e&&!n&&T===`video`,O=!D&&(n&&b||!t&&!e&&T===`talk`),k=D?`video`:O?`talk`:`chat`,A=me(v.data);he(m,A),ne(v.data?.brand.theme),ie(v.data?.avatar),ge(p,v.data?.title),ue(E);let N=A?.wizard.title??v.data?.title;(0,B.useEffect)(()=>{N&&(document.title=N)},[N]);let P=(0,B.useCallback)(e=>{try{p&&localStorage.getItem(Z(p))===m&&localStorage.removeItem(Z(p))}catch{}h(e,{replace:!0,state:{elsewhere:!0}})},[h,p,m]);if((0,B.useEffect)(()=>{p&&m&&ee(`run`,{token:p,runId:m})},[p,m]),v.isLoading)return(0,G.jsx)(`div`,{className:s(`flex items-center justify-center text-ink-4`,Q),children:(0,G.jsx)(_,{})});if(e&&v.data&&!C||n&&v.data&&!b||l&&v.data&&!S)return(0,G.jsx)(u,{to:`/w/${p}`,replace:!0});if(!v.data){let e=g(v.error);return(0,G.jsxs)(`div`,{className:s(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Q),children:[(0,G.jsx)(j,{kind:`pebble`,size:80}),(0,G.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:I(e?`common.offline`:`run.notFound`)}),e?(0,G.jsx)(r,{variant:`secondary`,onClick:()=>void v.refetch(),children:I(`common.retry`)}):null]})}let F=A?.wizard??v.data,L=A?.translating?(0,G.jsxs)(`div`,{className:s(`flex flex-col items-center justify-center gap-3 text-ink-3`,Q),children:[(0,G.jsx)(_,{}),(0,G.jsx)(`p`,{className:`text-[0.875rem]`,children:I(`translation.working`)})]}):null;if(E){let e=(0,G.jsx)(Ee,{wizard:F,page:A}),t=f?(0,G.jsx)(`div`,{className:`safe-bottom`}):(0,G.jsx)(Oe,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,G.jsxs)(`div`,{className:`wizard-page flex h-dvh flex-col`,children:[(0,G.jsx)(w,{effects:v.data.brand.theme.effects}),V||f?null:(0,G.jsx)(x,{}),L??(m?(0,G.jsx)(re,{runId:m,talk:O,call:D?`video`:O?`audio`:!1,onRestart:()=>h(`/w/${p}/${k}`),onNotFound:()=>P(`/w/${p}/${k}`),header:D||O?void 0:e,footer:t}):(0,G.jsx)(De,{wizard:F,page:A,header:e,footer:t,door:k}))]})}return(0,G.jsxs)(`div`,{className:s(`wizard-page flex flex-col`,Q),children:[(0,G.jsx)(w,{effects:v.data.brand.theme.effects}),V||f?null:(0,G.jsx)(x,{}),V===`inline`||f?null:(0,G.jsx)(ye,{brand:v.data.brand,toggle:!V,start:(0,G.jsx)(J,{page:A})}),V===`inline`||f?(0,G.jsx)(`div`,{className:`flex justify-end px-3 pt-2`,children:(0,G.jsx)(J,{page:A,tone:`surface`})}):null,m&&(A?.translated||A?.failed)?(0,G.jsx)(`div`,{className:`flex justify-center px-5`,children:(0,G.jsx)(Y,{page:A})}):null,(0,G.jsx)(`div`,{className:`flex-1`,children:L??(m?(0,G.jsx)(te,{runId:m,onRestart:()=>h(`/w/${p}`),onNotFound:()=>P(`/w/${p}`)}):(0,G.jsx)(we,{wizard:F,page:A}))}),f?(0,G.jsx)(`div`,{className:`safe-bottom`}):(0,G.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,G.jsx)(`a`,{href:`${a}/`,target:V?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:I(`run.madeWith`).replace(`engenty wizards`,M.name)})})]})}export{ye as BrandHeader,ke as PublicRunner};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$t as r,Q as i,at as a,gr as o,hn as s,hr as c,in as l,lr as u,mr as d,mt as f,nr as p,pr as m,pt as h,qt as g,un as _,vt as v,yt as ee}from"./ui-BacfkQ7Q.js";import{d as y,n as b}from"./marked.esm-DQ7XA7AC.js";import{c as x}from"./read-aloud-Qb719not.js";import{_ as S,b as C,d as w,f as te,g as T,h as E,m as D,n as ne,p as re,v as O,y as k}from"./theme-y_owNosi.js";import{C as A,S as j,k as ie,x as M}from"./session-CEJRkSP5.js";import{J as N,a as P,l as F,s as I}from"./i18n-DCPDesT-.js";import{n as L}from"./LangSwitch-iO54w9AP.js";var R={name:`bookmark`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};R.node;var ae=y(R),z={name:`square-plus`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]],aliases:[`plus-square`]};z.node;var oe=y(z),B=e(t(),1);function se(){if(window.self===window.top)return null;let e=new URLSearchParams(window.location.search).get(`embed`);return e===`inline`||e===`modal`||e===`popout`?e:null}var V=se(),ce=V?new URLSearchParams(window.location.search).get(`page`):null,H=new URLSearchParams(window.location.search).get(`theme`),U=H?`?theme=${encodeURIComponent(H)}`:``,W=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),le=()=>W(`close`);function ue(e){(0,B.useEffect)(()=>{if(V===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>W(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(V===`modal`||V===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&W(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var G=e(n(),1),K=`wizards.runner.translate`,q=new Set;function de(){try{return localStorage.getItem(K)===`on`}catch{return!1}}function fe(e){try{localStorage.setItem(K,e?`on`:`off`)}catch{}for(let e of q)e()}function pe(){return(0,B.useSyncExternalStore)(e=>(q.add(e),()=>q.delete(e)),de)}function me(e){let t=pe(),[n]=(0,B.useState)(()=>F()),r=e?.lang??`en`,a=e?.translatable&&n&&n!==r?n:null,s=a&&t?a:r,c=e?.token,l=o({queryKey:[`public-translation`,c,s],enabled:!!(c&&s!==r),queryFn:()=>i.post(`/api/public/wizards/${c}/translation${U}`,{lang:s}),staleTime:1/0,retry:!1}),u=o({queryKey:[`public-texts`,c,s],enabled:!(!c||N(s)),queryFn:()=>i.get(`/api/public/wizards/${c}/texts/${s}`),staleTime:1/0,retry:!1}),d=!N(s),f=s===r||l.data&&(!d||u.data),p=s!==r&&(l.isError||d&&u.isError),m=f&&!p?s:r,h=(0,B.useMemo)(()=>!N(m)&&u.data?.lang===m?{lang:u.data.lang,runner:u.data.runner,notes:u.data.notes}:null,[m,u.data]);if((0,B.useEffect)(()=>{e&&P(m,h)},[e,m,h]),(0,B.useEffect)(()=>()=>P(null),[]),!e)return null;let g=m!==r&&l.data?l.data:null;return{own:r,other:a,shown:m,wizard:g??e,translating:s!==r&&!f&&!p,failed:!!p,translated:!!g,machine:g?.translation?.machine??!1,pick:e=>fe(e!==r)}}function J({page:e,tone:t=`ground`}){if(!e?.other)return null;let n=e.translating?e.other:e.shown;return(0,G.jsx)(L,{langs:[e.own,e.other],value:n,onPick:e.pick,tone:t})}function Y({page:e,small:t}){if(!e)return null;let n=t?`truncate text-[0.75rem]`:`text-[0.8125rem]`;return e.failed?(0,G.jsx)(`p`,{className:s(`text-ink-3`,n),children:I(`translation.failed`)}):e.translated?(0,G.jsxs)(`p`,{className:s(`text-ink-3`,n),children:[e.machine?(0,G.jsxs)(G.Fragment,{children:[I(`translation.machine`),` · `]}):null,(0,G.jsx)(`button`,{type:`button`,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,onClick:()=>e.pick(e.own),children:I(`translation.showOriginal`)})]}):null}function he(e,t){let n=(0,B.useRef)(null),r=t&&!t.translating?t.translated?t.shown:null:void 0;(0,B.useEffect)(()=>{if(!e||r===void 0)return;let t=`${e}:${r}`;n.current!==t&&(n.current=t,i.post(`/api/runs/${e}/lang`,{lang:r}).catch(()=>void 0))},[e,r])}function ge(e,t){(0,B.useEffect)(()=>{if(!e||!t)return;let n=h(`/api/public/wizards/${e}`),r=[{rel:`manifest`,href:`${n}/manifest.webmanifest`},{rel:`apple-touch-icon`,href:`${n}/icons/apple-touch-icon.png`},{rel:`icon`,href:`${n}/icons/favicon.png`,type:`image/png`}].flatMap(({rel:e,href:t,type:n})=>{let r=document.querySelector(`link[rel="${e}"]`);if(!r)return[];let i={href:r.getAttribute(`href`),type:r.getAttribute(`type`)};return r.setAttribute(`href`,t),n&&r.setAttribute(`type`,n),[{link:r,before:i}]}),i=document.createElement(`meta`);return i.name=`apple-mobile-web-app-title`,i.content=t,document.head.appendChild(i),()=>{for(let{link:e,before:t}of r)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);i.remove()}},[e,t])}var _e=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,X=_e||/Android/.test(navigator.userAgent);function ve(){let[e,t]=(0,B.useState)(()=>window.wizardInstall??null),[n,r]=(0,B.useState)(!1);if((0,B.useEffect)(()=>{let e=()=>t(window.wizardInstall??null);return window.addEventListener(`wizard-install`,e),()=>window.removeEventListener(`wizard-install`,e)},[]),window.matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0||X&&!e&&!_e)return null;let i=/Mac/.test(navigator.platform),a=I(X?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,G.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{X&&e?(e.prompt(),window.wizardInstall=null,t(null)):r(e=>!e)},className:`inline-flex items-center gap-1.5 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[X?(0,G.jsx)(oe,{className:`size-4`}):(0,G.jsx)(ae,{className:`size-4`}),I(X?`install.add`:`install.bookmark`)]}),n?(0,G.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function ye({brand:e,toggle:t=!0,start:n}){return(0,G.jsx)(`header`,{className:`safe-top`,children:(0,G.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[n?(0,G.jsx)(`div`,{className:`absolute left-3`,children:n}):null,e.logoUrl?(0,G.jsx)(`img`,{src:h(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,G.jsx)(`span`,{className:`max-w-[60%] truncate font-display font-semibold text-[0.9375rem] text-ink-2 tracking-tight`,children:e.name}):null,t?(0,G.jsx)(`div`,{className:`absolute right-3`,children:(0,G.jsx)(A,{})}):null]})})}function be({siteKey:e,onToken:t}){let n=(0,B.useRef)(null);return(0,B.useEffect)(()=>{let r=()=>{n.current&&window.turnstile&&!n.current.childElementCount&&window.turnstile.render(n.current,{sitekey:e,callback:t,appearance:`interaction-only`})};if(window.turnstile){r();return}let i=document.createElement(`script`);i.src=`https://challenges.cloudflare.com/turnstile/v0/api.js`,i.async=!0,i.onload=r,document.head.appendChild(i)},[e,t]),(0,G.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function xe({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||f||V?null:(0,G.jsxs)(`a`,{href:v(`${window.location.origin}${a}/w/${e}`),className:`mt-3 inline-flex items-center gap-1.5 text-[0.8125rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[(0,G.jsx)(C,{className:`size-4`}),` `,I(`install.app`)]})}var Z=e=>`wz.run.${e}`,Se=()=>m().state?.elsewhere===!0,Ce=f&&new URLSearchParams(window.location.search).get(`start`)===`1`,Q=V===`inline`?`min-h-80`:`min-h-dvh`;function $(e,t,n){let r=d(),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(null),f=(()=>{try{return localStorage.getItem(Z(e.token))}catch{return null}})();return{busy:a,error:s,captcha:l,setCaptcha:u,start:async()=>{o(!0),c(null);try{let{runId:a}=await i.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:l??void 0,embedded:V!==null,origin:ce??void 0,lang:n??void 0});try{localStorage.setItem(Z(e.token),a)}catch{}r(`${t}/${a}`,{replace:Ce})}catch(e){c(e.message),o(!1)}},resume:f?()=>r(`${t}/${f}`):null}}function we({wizard:e,page:t}){let{busy:n,error:i,captcha:a,setCaptcha:o,start:s,resume:c}=$(e,`/w/${e.token}`,t?.translated?t.shown:null),l=Se(),u=Ce&&e.available&&!e.turnstileSiteKey,d=(0,B.useRef)(!1);return(0,B.useEffect)(()=>{u&&!d.current&&(d.current=!0,s())},[u]),u&&!i?(0,G.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,G.jsx)(_,{})}):(0,G.jsxs)(`div`,{className:`mx-auto flex max-w-lg animate-rise flex-col items-center px-6 pt-6 pb-12 text-center sm:pt-16 sm:pb-16`,children:[l?(0,G.jsx)(`p`,{className:`mb-6 rounded-xl bg-paper-2 px-5 py-3 text-[0.875rem] text-ink-2`,children:I(`run.elsewhere`)}):null,(0,G.jsx)(j,{kind:e.avatar,costume:e.costume,size:190,fluffy:!0}),(0,G.jsx)(`h1`,{className:`wizard-title mt-2 text-balance font-display font-semibold text-[1.875rem] leading-[1.1] tracking-tight sm:text-[2.125rem]`,children:e.title}),e.description?(0,G.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,(0,G.jsx)(`div`,{className:`mt-3`,children:(0,G.jsx)(Y,{page:t})}),e.available?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(r,{size:`lg`,className:`mt-10 min-w-48`,busy:n,disabled:!!e.turnstileSiteKey&&!a,onClick:s,children:[I(`run.start`),` `,(0,G.jsx)(p,{className:`size-4`})]}),e.turnstileSiteKey?(0,G.jsx)(be,{siteKey:e.turnstileSiteKey,onToken:o}):null,c?(0,G.jsx)(`button`,{type:`button`,onClick:c,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:I(`run.resume`)}):null,(0,G.jsx)(Te,{wizard:e,current:`steps`}),V||f?null:(0,G.jsx)(ve,{}),(0,G.jsx)(xe,{token:e.token})]}):(0,G.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??I(`run.unavailable`)}),i?(0,G.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:i}):null]})}function Te({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,G.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,G.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:I(`run.orAs`,{label:e.label})},e.id))}):null}function Ee({wizard:e,page:t}){let n=k();return(0,G.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,G.jsxs)(`div`,{className:`mx-auto flex h-16 w-full max-w-[760px] items-center gap-3 pr-2 pl-4 sm:pr-4 sm:pl-6`,children:[(0,G.jsx)(`span`,{className:s(n?.speaking&&`animate-breathe`),children:(0,G.jsx)(j,{kind:e.avatar,costume:e.costume,size:38})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,G.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null,(0,G.jsx)(Y,{page:t,small:!0})]}),e.brand.logoUrl&&V!==`popout`?(0,G.jsx)(`img`,{src:h(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,(0,G.jsx)(J,{page:t,tone:`surface`}),V?null:(0,G.jsx)(A,{}),V===`popout`?(0,G.jsx)(l,{label:I(`common.close`),onClick:le,children:(0,G.jsx)(b,{className:`size-5`})}):null]})})}function De({door:e,wizard:t,page:n,header:r,footer:i}){let{busy:a,error:o,captcha:s,setCaptcha:c,start:l,resume:u}=$(t,`/w/${t.token}/${e}`,n?.translated?n.shown:null),d=Se(),f=[];return d&&f.push({key:`elsewhere`,who:`bot`,node:I(`run.elsewhere`)}),f.push({key:`hello`,who:`bot`,node:t.description||t.title}),e!==`chat`&&f.push({key:e,who:`bot`,node:I(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||f.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??I(`run.unavailable`)}),o&&f.push({key:`error`,who:`bot`,node:o,tone:`error`}),t.available&&f.push(O(`start`,(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(T,{primary:!0,busy:a,disabled:!!t.turnstileSiteKey&&!s,onClick:()=>void l(),children:[I(`run.start`),` `,(0,G.jsx)(p,{className:`size-4`})]}),u?(0,G.jsx)(T,{onClick:u,children:I(`run.resume`)}):null,t.turnstileSiteKey?(0,G.jsx)(be,{siteKey:t.turnstileSiteKey,onToken:c}):null]}))),(0,G.jsxs)(D,{header:r,footer:i,children:[(0,G.jsx)(S,{avatar:t.avatar,costume:t.costume,lines:f}),(0,G.jsx)(E,{})]})}function Oe({className:e}){return(0,G.jsx)(`footer`,{className:s(`text-center text-ink-4`,e),children:(0,G.jsx)(`a`,{href:`${a}/`,target:V?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:I(`run.madeWith`).replace(`engenty wizards`,M.name)})})}function ke({chat:e=!1,steps:t=!1,talk:n=!1,video:l=!1}){let{token:p,runId:m}=c(),h=d(),v=o({queryKey:[`public`,p,U],queryFn:()=>i.get(`/api/public/wizards/${p}${U}`),retry:(e,t)=>g(t)&&e<3}),y=v.data?.runners??[],b=!v.data||y.some(e=>e.id===`talk`),S=!v.data||y.some(e=>e.id===`video`),C=!v.data||y.some(e=>e.id===`chat`)||n&&b||l&&S,T=y[0]?.id,E=e||V===`popout`||!t&&!m&&C&&(T===`chat`||T===`talk`||T===`video`),D=l&&S||!t&&!e&&!n&&T===`video`,O=!D&&(n&&b||!t&&!e&&T===`talk`),k=D?`video`:O?`talk`:`chat`,A=me(v.data);he(m,A),ne(v.data?.brand.theme),ie(v.data?.avatar),ge(p,v.data?.title),ue(E);let N=A?.wizard.title??v.data?.title;(0,B.useEffect)(()=>{N&&(document.title=N)},[N]);let P=(0,B.useCallback)(e=>{try{p&&localStorage.getItem(Z(p))===m&&localStorage.removeItem(Z(p))}catch{}h(e,{replace:!0,state:{elsewhere:!0}})},[h,p,m]);if((0,B.useEffect)(()=>{p&&m&&ee(`run`,{token:p,runId:m})},[p,m]),v.isLoading)return(0,G.jsx)(`div`,{className:s(`flex items-center justify-center text-ink-4`,Q),children:(0,G.jsx)(_,{})});if(e&&v.data&&!C||n&&v.data&&!b||l&&v.data&&!S)return(0,G.jsx)(u,{to:`/w/${p}`,replace:!0});if(!v.data){let e=g(v.error);return(0,G.jsxs)(`div`,{className:s(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Q),children:[(0,G.jsx)(j,{kind:`pebble`,size:80}),(0,G.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:I(e?`common.offline`:`run.notFound`)}),e?(0,G.jsx)(r,{variant:`secondary`,onClick:()=>void v.refetch(),children:I(`common.retry`)}):null]})}let F=A?.wizard??v.data,L=A?.translating?(0,G.jsxs)(`div`,{className:s(`flex flex-col items-center justify-center gap-3 text-ink-3`,Q),children:[(0,G.jsx)(_,{}),(0,G.jsx)(`p`,{className:`text-[0.875rem]`,children:I(`translation.working`)})]}):null;if(E){let e=(0,G.jsx)(Ee,{wizard:F,page:A}),t=f?(0,G.jsx)(`div`,{className:`safe-bottom`}):(0,G.jsx)(Oe,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,G.jsxs)(`div`,{className:`wizard-page flex h-dvh flex-col`,children:[(0,G.jsx)(w,{effects:v.data.brand.theme.effects}),V||f?null:(0,G.jsx)(x,{}),L??(m?(0,G.jsx)(re,{runId:m,talk:O,call:D?`video`:O?`audio`:!1,onRestart:()=>h(`/w/${p}/${k}`),onNotFound:()=>P(`/w/${p}/${k}`),header:D||O?void 0:e,footer:t}):(0,G.jsx)(De,{wizard:F,page:A,header:e,footer:t,door:k}))]})}return(0,G.jsxs)(`div`,{className:s(`wizard-page flex flex-col`,Q),children:[(0,G.jsx)(w,{effects:v.data.brand.theme.effects}),V||f?null:(0,G.jsx)(x,{}),V===`inline`||f?null:(0,G.jsx)(ye,{brand:v.data.brand,toggle:!V,start:(0,G.jsx)(J,{page:A})}),V===`inline`||f?(0,G.jsx)(`div`,{className:`flex justify-end px-3 pt-2`,children:(0,G.jsx)(J,{page:A,tone:`surface`})}):null,m&&(A?.translated||A?.failed)?(0,G.jsx)(`div`,{className:`flex justify-center px-5`,children:(0,G.jsx)(Y,{page:A})}):null,(0,G.jsx)(`div`,{className:`flex-1`,children:L??(m?(0,G.jsx)(te,{runId:m,onRestart:()=>h(`/w/${p}`),onNotFound:()=>P(`/w/${p}`)}):(0,G.jsx)(we,{wizard:F,page:A}))}),f?(0,G.jsx)(`div`,{className:`safe-bottom`}):(0,G.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,G.jsx)(`a`,{href:`${a}/`,target:V?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:I(`run.madeWith`).replace(`engenty wizards`,M.name)})})]})}export{ye as BrandHeader,ke as PublicRunner};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{d as n}from"./marked.esm-DQ7XA7AC.js";import{Rn as r}from"./host-D6H6Z9Jp.js";import{s as i}from"./i18n-BaPKbQ1s.js";var a={name:`text-align-start`,size:24,node:[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]],aliases:[`text`,`align-left`]};a.node;var o=n(a),s=e(t(),1);function c(e){return i(e.origin===`local`?`readonly.space`:`readonly.server`)}function l({children:e}){return(0,s.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-amber-tint px-4 py-3 font-medium text-[0.875rem] text-ink leading-relaxed`,children:[(0,s.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-amber`}),(0,s.jsx)(`p`,{className:`min-w-0`,children:e})]})}export{c as n,o as r,l as t};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{d as n}from"./marked.esm-DQ7XA7AC.js";import{zn as r}from"./host-CCijW1hj.js";import{s as i}from"./i18n-DCPDesT-.js";var a={name:`text-align-start`,size:24,node:[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]],aliases:[`text`,`align-left`]};a.node;var o=n(a),s=e(t(),1);function c(e){return i(e.origin===`local`?`readonly.space`:`readonly.server`)}function l({children:e}){return(0,s.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-amber-tint px-4 py-3 font-medium text-[0.875rem] text-ink leading-relaxed`,children:[(0,s.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-amber`}),(0,s.jsx)(`p`,{className:`min-w-0`,children:e})]})}export{c as n,o as r,l as t};