wizards 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/runtime/dist/auth/index.js +7 -1
- package/apps/web/dist/assets/{AboutDialog-BsBmdR7v.js → AboutDialog-CtFJFiTQ.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-BmvSfyui.js → ChangelogDialog-gC54y5X0.js} +1 -1
- package/apps/web/dist/assets/{ChatView-E1MWQD6-.js → ChatView-CMqiLToD.js} +1 -1
- package/apps/web/dist/assets/EditorPage-CFI0p1Mg.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-CKrwLPN0.js → FlowPreview-B4-ipMdE.js} +1 -1
- package/apps/web/dist/assets/{Harness-sYYL7BJ7.js → Harness-CEA124j3.js} +1 -1
- package/apps/web/dist/assets/{NewWizardChannels-LRRojdQ6.js → NewWizardChannels-CO4X-osP.js} +1 -1
- package/apps/web/dist/assets/{NewWizardPage-CYPMkvll.js → NewWizardPage-DXmiWISd.js} +1 -1
- package/apps/web/dist/assets/{OnboardingPage-CzMAwZbk.js → OnboardingPage-XCfDhXMW.js} +1 -1
- package/apps/web/dist/assets/{ProjectPage-DxEAcc_A.js → ProjectPage-DSKtAuMi.js} +1 -1
- package/apps/web/dist/assets/{PublicRunner-CUM7eOVM.js → PublicRunner-BGUTg4zc.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly-2fcWBEVe.js → ReadOnly-DbdGw_4p.js} +1 -1
- package/apps/web/dist/assets/{RunDrawer-DRa5bHnP.js → RunDrawer-Dity6egV.js} +1 -1
- package/apps/web/dist/assets/{RunnerView-Cv5crRaO.js → RunnerView-C8vdGgXx.js} +1 -1
- package/apps/web/dist/assets/{SettingsPage-Du-vweTQ.js → SettingsPage-gcAFjAi2.js} +1 -1
- package/apps/web/dist/assets/{SetupPage-CGkshuQ3.js → SetupPage-BTV9ET3H.js} +1 -1
- package/apps/web/dist/assets/{SharePage-DHyXHr7X.js → SharePage-DlkWmaal.js} +1 -1
- package/apps/web/dist/assets/changelog-CQ352XL_.js +1 -0
- package/apps/web/dist/assets/{esm-DfapVSy6.js → esm-J06O1nN_.js} +1 -1
- package/apps/web/dist/assets/index-CZFfDGHy.css +1 -0
- package/apps/web/dist/assets/{index-UA2WOyDH.js → index-D_0jeO3M.js} +7 -7
- package/apps/web/dist/assets/{lock-B-tJwE4p.js → lock-ChDlFFHO.js} +1 -1
- package/apps/web/dist/assets/{phone-DRHxY0l_.js → phone-Cr7jz_kf.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-OPrJTW8a.js → settings-menu-BAwHMXCR.js} +1 -1
- package/apps/web/dist/assets/{ui-DftgEA2k.js → ui-C5_NcAmG.js} +1 -1
- package/apps/web/dist/assets/{upload-B73coFNw.js → upload-DcAIMe8d.js} +1 -1
- package/apps/web/dist/index.html +3 -3
- package/apps/web/dist/mcp/flow.html +3 -3
- package/package.json +1 -1
- package/apps/web/dist/assets/EditorPage-DijD0jFa.js +0 -3
- package/apps/web/dist/assets/changelog-xZj7xRiE.js +0 -1
- package/apps/web/dist/assets/index-DSbQiZY8.css +0 -1
|
@@ -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{$ as r,J as i,Qn as a,Ut as o,W as s,Yt as c,ar as l,dn as u,en as d,gn as f,lr as p,on as m,pr as h,tr as g,ur as _,vn as v}from"./ui-DftgEA2k.js";import{a as y,i as b,n as x,o as S,r as C,s as w,t as T}from"./ChatView-E1MWQD6-.js";import{a as E,dt as D,ft as O,gt as ee,n as k,o as A,pt as j}from"./index-UA2WOyDH.js";import{t as M}from"./RunnerView-Cv5crRaO.js";var N={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`}]]};N.node;var P=g(N),F={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};F.node;var te=g(F),I={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`]};I.node;var L=g(I),R=e(t(),1);function ne(){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 z=ne(),re=z?new URLSearchParams(window.location.search).get(`page`):null,B=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),ie=()=>B(`close`);function V(e){(0,R.useEffect)(()=>{if(z===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>B(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(z===`modal`||z===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&B(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var H=e(n(),1);function U(e){(0,R.useEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`--raw-primary`,e),()=>{t.style.removeProperty(`--raw-primary`)}},[e])}function W(e,t){(0,R.useEffect)(()=>{if(!e||!t)return;let n=r(`/api/public/wizards/${e}`),i=[{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}]}),a=document.createElement(`meta`);return a.name=`apple-mobile-web-app-title`,a.content=t,document.head.appendChild(a),()=>{for(let{link:e,before:t}of i)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);a.remove()}},[e,t])}var G=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,K=G||/Android/.test(navigator.userAgent);function q(){let[e,t]=(0,R.useState)(()=>window.wizardInstall??null),[n,r]=(0,R.useState)(!1);if((0,R.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||K&&!e&&!G)return null;let i=/Mac/.test(navigator.platform),a=f(K?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,H.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:()=>{K&&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:[K?(0,H.jsx)(L,{className:`size-4`}):(0,H.jsx)(P,{className:`size-4`}),f(K?`install.add`:`install.bookmark`)]}),n?(0,H.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function J({brand:e,toggle:t=!0}){return(0,H.jsx)(`header`,{className:`safe-top`,children:(0,H.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[e.logoUrl?(0,H.jsx)(`img`,{src:r(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,H.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,H.jsx)(`div`,{className:`absolute right-3`,children:(0,H.jsx)(j,{})}):null]})})}function Y({siteKey:e,onToken:t}){let n=(0,R.useRef)(null);return(0,R.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,H.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function ae({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||k||z?null:(0,H.jsxs)(`a`,{href:E(`${window.location.origin}${i}/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,H.jsx)(te,{className:`size-4`}),` `,f(`install.app`)]})}var X=e=>`wz.run.${e}`,Z=k&&new URLSearchParams(window.location.search).get(`start`)===`1`,Q=z===`inline`?`min-h-80`:`min-h-dvh`;function $(e,t){let n=p(),[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(null),[c,l]=(0,R.useState)(null),u=(()=>{try{return localStorage.getItem(X(e.token))}catch{return null}})();return{busy:r,error:a,captcha:c,setCaptcha:l,start:async()=>{i(!0),o(null);try{let{runId:r}=await s.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:c??void 0,embedded:z!==null,origin:re??void 0});try{localStorage.setItem(X(e.token),r)}catch{}n(`${t}/${r}`,{replace:Z})}catch(e){o(e.message),i(!1)}},resume:u?()=>n(`${t}/${u}`):null}}function oe({wizard:e}){let{busy:t,error:n,captcha:r,setCaptcha:i,start:o,resume:s}=$(e,`/w/${e.token}`),l=Z&&e.available&&!e.turnstileSiteKey,u=(0,R.useRef)(!1);return(0,R.useEffect)(()=>{l&&!u.current&&(u.current=!0,o())},[l]),l&&!n?(0,H.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,H.jsx)(m,{})}):(0,H.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:[(0,H.jsx)(O,{kind:e.avatar,size:190,fluffy:!0}),(0,H.jsx)(`h1`,{className:`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,H.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,e.available?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(c,{size:`lg`,className:`mt-10 min-w-48`,busy:t,disabled:!!e.turnstileSiteKey&&!r,onClick:o,children:[f(`run.start`),` `,(0,H.jsx)(a,{className:`size-4`})]}),e.turnstileSiteKey?(0,H.jsx)(Y,{siteKey:e.turnstileSiteKey,onToken:i}):null,s?(0,H.jsx)(`button`,{type:`button`,onClick:s,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:f(`run.resume`)}):null,(0,H.jsx)(se,{wizard:e,current:`steps`}),z||k?null:(0,H.jsx)(q,{}),(0,H.jsx)(ae,{token:e.token})]}):(0,H.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??f(`run.unavailable`)}),n?(0,H.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:n}):null]})}function se({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,H.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,H.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:f(`run.orAs`,{label:e.label})},e.id))}):null}function ce({wizard:e}){let t=w();return(0,H.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,H.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,H.jsx)(`span`,{className:u(t?.speaking&&`animate-breathe`),children:(0,H.jsx)(O,{kind:e.avatar,size:38})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,H.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null]}),e.brand.logoUrl&&z!==`popout`?(0,H.jsx)(`img`,{src:r(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,z?null:(0,H.jsx)(j,{}),z===`popout`?(0,H.jsx)(d,{label:f(`common.close`),onClick:ie,children:(0,H.jsx)(v,{className:`size-5`})}):null]})})}function le({door:e,wizard:t,header:n,footer:r}){let{busy:i,error:o,captcha:s,setCaptcha:c,start:l,resume:u}=$(t,`/w/${t.token}/${e}`),d=[{key:`hello`,who:`bot`,node:t.description||t.title}];return e!==`chat`&&d.push({key:e,who:`bot`,node:f(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||d.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??f(`run.unavailable`)}),o&&d.push({key:`error`,who:`bot`,node:o,tone:`error`}),t.available&&d.push(S(`start`,(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(b,{primary:!0,busy:i,disabled:!!t.turnstileSiteKey&&!s,onClick:()=>void l(),children:[f(`run.start`),` `,(0,H.jsx)(a,{className:`size-4`})]}),u?(0,H.jsx)(b,{onClick:u,children:f(`run.resume`)}):null,t.turnstileSiteKey?(0,H.jsx)(Y,{siteKey:t.turnstileSiteKey,onToken:c}):null]}))),(0,H.jsxs)(x,{header:n,footer:r,children:[(0,H.jsx)(y,{avatar:t.avatar,lines:d}),(0,H.jsx)(C,{})]})}function ue({className:e}){return(0,H.jsx)(`footer`,{className:u(`text-center text-ink-4`,e),children:(0,H.jsx)(`a`,{href:`${i}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:f(`run.madeWith`).replace(`engenty wizards`,D.name)})})}function de({chat:e=!1,steps:t=!1,talk:n=!1,video:r=!1}){let{token:a,runId:d}=_(),g=p(),v=h({queryKey:[`public`,a],queryFn:()=>s.get(`/api/public/wizards/${a}`),retry:(e,t)=>o(t)&&e<3}),y=v.data?.runners??[],b=!v.data||y.some(e=>e.id===`talk`),x=!v.data||y.some(e=>e.id===`video`),S=!v.data||y.some(e=>e.id===`chat`)||n&&b||r&&x,C=y[0]?.id,w=e||z===`popout`||!t&&!d&&S&&(C===`chat`||C===`talk`||C===`video`),E=r&&x||!t&&!e&&!n&&C===`video`,j=!E&&(n&&b||!t&&!e&&C===`talk`),N=E?`video`:j?`talk`:`chat`;if(U(v.data?.brand.accent),ee(v.data?.avatar),W(a,v.data?.title),V(w),(0,R.useEffect)(()=>{v.data&&(document.title=v.data.title)},[v.data]),(0,R.useEffect)(()=>{a&&d&&A(`run`,{token:a,runId:d})},[a,d]),v.isLoading)return(0,H.jsx)(`div`,{className:u(`flex items-center justify-center text-ink-4`,Q),children:(0,H.jsx)(m,{})});if(e&&v.data&&!S||n&&v.data&&!b||r&&v.data&&!x)return(0,H.jsx)(l,{to:`/w/${a}`,replace:!0});if(!v.data){let e=o(v.error);return(0,H.jsxs)(`div`,{className:u(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Q),children:[(0,H.jsx)(O,{kind:`pebble`,size:80}),(0,H.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:f(e?`common.offline`:`run.notFound`)}),e?(0,H.jsx)(c,{variant:`secondary`,onClick:()=>void v.refetch(),children:f(`common.retry`)}):null]})}if(w){let e=(0,H.jsx)(ce,{wizard:v.data}),t=k?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(ue,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,H.jsx)(`div`,{className:`flex h-dvh flex-col`,children:d?(0,H.jsx)(T,{runId:d,talk:j,call:E?`video`:j?`audio`:!1,onRestart:()=>g(`/w/${a}/${N}`),header:E||j?void 0:e,footer:t}):(0,H.jsx)(le,{wizard:v.data,header:e,footer:t,door:N})})}return(0,H.jsxs)(`div`,{className:u(`flex flex-col`,Q),children:[z===`inline`||k?null:(0,H.jsx)(J,{brand:v.data.brand,toggle:!z}),(0,H.jsx)(`div`,{className:`flex-1`,children:d?(0,H.jsx)(M,{runId:d,onRestart:()=>g(`/w/${a}`)}):(0,H.jsx)(oe,{wizard:v.data})}),k?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,H.jsx)(`a`,{href:`${i}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:f(`run.madeWith`).replace(`engenty wizards`,D.name)})})]})}export{J as BrandHeader,de as PublicRunner,U as useBrandAccent};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$ as r,J as i,Qn as a,Ut as o,W as s,Yt as c,ar as l,dn as u,en as d,gn as f,lr as p,on as m,pr as h,tr as g,ur as _,vn as v}from"./ui-C5_NcAmG.js";import{a as y,i as b,n as x,o as S,r as C,s as w,t as T}from"./ChatView-CMqiLToD.js";import{a as E,dt as D,ft as O,gt as ee,n as k,o as A,pt as j}from"./index-D_0jeO3M.js";import{t as M}from"./RunnerView-C8vdGgXx.js";var N={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`}]]};N.node;var P=g(N),F={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};F.node;var te=g(F),I={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`]};I.node;var L=g(I),R=e(t(),1);function ne(){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 z=ne(),re=z?new URLSearchParams(window.location.search).get(`page`):null,B=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),ie=()=>B(`close`);function V(e){(0,R.useEffect)(()=>{if(z===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>B(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(z===`modal`||z===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&B(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var H=e(n(),1);function U(e){(0,R.useEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`--raw-primary`,e),()=>{t.style.removeProperty(`--raw-primary`)}},[e])}function W(e,t){(0,R.useEffect)(()=>{if(!e||!t)return;let n=r(`/api/public/wizards/${e}`),i=[{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}]}),a=document.createElement(`meta`);return a.name=`apple-mobile-web-app-title`,a.content=t,document.head.appendChild(a),()=>{for(let{link:e,before:t}of i)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);a.remove()}},[e,t])}var G=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,K=G||/Android/.test(navigator.userAgent);function q(){let[e,t]=(0,R.useState)(()=>window.wizardInstall??null),[n,r]=(0,R.useState)(!1);if((0,R.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||K&&!e&&!G)return null;let i=/Mac/.test(navigator.platform),a=f(K?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,H.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:()=>{K&&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:[K?(0,H.jsx)(L,{className:`size-4`}):(0,H.jsx)(P,{className:`size-4`}),f(K?`install.add`:`install.bookmark`)]}),n?(0,H.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function J({brand:e,toggle:t=!0}){return(0,H.jsx)(`header`,{className:`safe-top`,children:(0,H.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[e.logoUrl?(0,H.jsx)(`img`,{src:r(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,H.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,H.jsx)(`div`,{className:`absolute right-3`,children:(0,H.jsx)(j,{})}):null]})})}function Y({siteKey:e,onToken:t}){let n=(0,R.useRef)(null);return(0,R.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,H.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function ae({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||k||z?null:(0,H.jsxs)(`a`,{href:E(`${window.location.origin}${i}/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,H.jsx)(te,{className:`size-4`}),` `,f(`install.app`)]})}var X=e=>`wz.run.${e}`,Z=k&&new URLSearchParams(window.location.search).get(`start`)===`1`,Q=z===`inline`?`min-h-80`:`min-h-dvh`;function $(e,t){let n=p(),[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(null),[c,l]=(0,R.useState)(null),u=(()=>{try{return localStorage.getItem(X(e.token))}catch{return null}})();return{busy:r,error:a,captcha:c,setCaptcha:l,start:async()=>{i(!0),o(null);try{let{runId:r}=await s.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:c??void 0,embedded:z!==null,origin:re??void 0});try{localStorage.setItem(X(e.token),r)}catch{}n(`${t}/${r}`,{replace:Z})}catch(e){o(e.message),i(!1)}},resume:u?()=>n(`${t}/${u}`):null}}function oe({wizard:e}){let{busy:t,error:n,captcha:r,setCaptcha:i,start:o,resume:s}=$(e,`/w/${e.token}`),l=Z&&e.available&&!e.turnstileSiteKey,u=(0,R.useRef)(!1);return(0,R.useEffect)(()=>{l&&!u.current&&(u.current=!0,o())},[l]),l&&!n?(0,H.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,H.jsx)(m,{})}):(0,H.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:[(0,H.jsx)(O,{kind:e.avatar,size:190,fluffy:!0}),(0,H.jsx)(`h1`,{className:`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,H.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,e.available?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(c,{size:`lg`,className:`mt-10 min-w-48`,busy:t,disabled:!!e.turnstileSiteKey&&!r,onClick:o,children:[f(`run.start`),` `,(0,H.jsx)(a,{className:`size-4`})]}),e.turnstileSiteKey?(0,H.jsx)(Y,{siteKey:e.turnstileSiteKey,onToken:i}):null,s?(0,H.jsx)(`button`,{type:`button`,onClick:s,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:f(`run.resume`)}):null,(0,H.jsx)(se,{wizard:e,current:`steps`}),z||k?null:(0,H.jsx)(q,{}),(0,H.jsx)(ae,{token:e.token})]}):(0,H.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??f(`run.unavailable`)}),n?(0,H.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:n}):null]})}function se({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,H.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,H.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:f(`run.orAs`,{label:e.label})},e.id))}):null}function ce({wizard:e}){let t=w();return(0,H.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,H.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,H.jsx)(`span`,{className:u(t?.speaking&&`animate-breathe`),children:(0,H.jsx)(O,{kind:e.avatar,size:38})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,H.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null]}),e.brand.logoUrl&&z!==`popout`?(0,H.jsx)(`img`,{src:r(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,z?null:(0,H.jsx)(j,{}),z===`popout`?(0,H.jsx)(d,{label:f(`common.close`),onClick:ie,children:(0,H.jsx)(v,{className:`size-5`})}):null]})})}function le({door:e,wizard:t,header:n,footer:r}){let{busy:i,error:o,captcha:s,setCaptcha:c,start:l,resume:u}=$(t,`/w/${t.token}/${e}`),d=[{key:`hello`,who:`bot`,node:t.description||t.title}];return e!==`chat`&&d.push({key:e,who:`bot`,node:f(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||d.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??f(`run.unavailable`)}),o&&d.push({key:`error`,who:`bot`,node:o,tone:`error`}),t.available&&d.push(S(`start`,(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(b,{primary:!0,busy:i,disabled:!!t.turnstileSiteKey&&!s,onClick:()=>void l(),children:[f(`run.start`),` `,(0,H.jsx)(a,{className:`size-4`})]}),u?(0,H.jsx)(b,{onClick:u,children:f(`run.resume`)}):null,t.turnstileSiteKey?(0,H.jsx)(Y,{siteKey:t.turnstileSiteKey,onToken:c}):null]}))),(0,H.jsxs)(x,{header:n,footer:r,children:[(0,H.jsx)(y,{avatar:t.avatar,lines:d}),(0,H.jsx)(C,{})]})}function ue({className:e}){return(0,H.jsx)(`footer`,{className:u(`text-center text-ink-4`,e),children:(0,H.jsx)(`a`,{href:`${i}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:f(`run.madeWith`).replace(`engenty wizards`,D.name)})})}function de({chat:e=!1,steps:t=!1,talk:n=!1,video:r=!1}){let{token:a,runId:d}=_(),g=p(),v=h({queryKey:[`public`,a],queryFn:()=>s.get(`/api/public/wizards/${a}`),retry:(e,t)=>o(t)&&e<3}),y=v.data?.runners??[],b=!v.data||y.some(e=>e.id===`talk`),x=!v.data||y.some(e=>e.id===`video`),S=!v.data||y.some(e=>e.id===`chat`)||n&&b||r&&x,C=y[0]?.id,w=e||z===`popout`||!t&&!d&&S&&(C===`chat`||C===`talk`||C===`video`),E=r&&x||!t&&!e&&!n&&C===`video`,j=!E&&(n&&b||!t&&!e&&C===`talk`),N=E?`video`:j?`talk`:`chat`;if(U(v.data?.brand.accent),ee(v.data?.avatar),W(a,v.data?.title),V(w),(0,R.useEffect)(()=>{v.data&&(document.title=v.data.title)},[v.data]),(0,R.useEffect)(()=>{a&&d&&A(`run`,{token:a,runId:d})},[a,d]),v.isLoading)return(0,H.jsx)(`div`,{className:u(`flex items-center justify-center text-ink-4`,Q),children:(0,H.jsx)(m,{})});if(e&&v.data&&!S||n&&v.data&&!b||r&&v.data&&!x)return(0,H.jsx)(l,{to:`/w/${a}`,replace:!0});if(!v.data){let e=o(v.error);return(0,H.jsxs)(`div`,{className:u(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Q),children:[(0,H.jsx)(O,{kind:`pebble`,size:80}),(0,H.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:f(e?`common.offline`:`run.notFound`)}),e?(0,H.jsx)(c,{variant:`secondary`,onClick:()=>void v.refetch(),children:f(`common.retry`)}):null]})}if(w){let e=(0,H.jsx)(ce,{wizard:v.data}),t=k?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(ue,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,H.jsx)(`div`,{className:`flex h-dvh flex-col`,children:d?(0,H.jsx)(T,{runId:d,talk:j,call:E?`video`:j?`audio`:!1,onRestart:()=>g(`/w/${a}/${N}`),header:E||j?void 0:e,footer:t}):(0,H.jsx)(le,{wizard:v.data,header:e,footer:t,door:N})})}return(0,H.jsxs)(`div`,{className:u(`flex flex-col`,Q),children:[z===`inline`||k?null:(0,H.jsx)(J,{brand:v.data.brand,toggle:!z}),(0,H.jsx)(`div`,{className:`flex-1`,children:d?(0,H.jsx)(M,{runId:d,onRestart:()=>g(`/w/${a}`)}):(0,H.jsx)(oe,{wizard:v.data})}),k?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,H.jsx)(`a`,{href:`${i}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:f(`run.madeWith`).replace(`engenty wizards`,D.name)})})]})}export{J as BrandHeader,de as PublicRunner,U as useBrandAccent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{gn as n,tr as r}from"./ui-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{gn as n,tr as r}from"./ui-C5_NcAmG.js";import{Rt as i}from"./index-D_0jeO3M.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=r(a),s=e(t(),1);function c(e){return n(e.origin===`local`?`readonly.project`:`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)(i,{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,4 +1,4 @@
|
|
|
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,B as i,Bn as a,C as o,En as s,Fn as c,Ht as l,Jn as u,Kn as d,Mn as f,On as p,Qt as m,Rr as h,S as g,V as _,W as v,Xt as y,Yn as b,Yt as x,Zt as S,an as C,bn as w,cn as T,dn as E,en as D,gn as O,in as k,nn as A,on as j,ot as M,pn as N,pr as P,tn as F,tr as I,un as ee,v as te,vn as L,z as R}from"./ui-
|
|
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,B as i,Bn as a,C as o,En as s,Fn as c,Ht as l,Jn as u,Kn as d,Mn as f,On as p,Qt as m,Rr as h,S as g,V as _,W as v,Xt as y,Yn as b,Yt as x,Zt as S,an as C,bn as w,cn as T,dn as E,en as D,gn as O,in as k,nn as A,on as j,ot as M,pn as N,pr as P,tn as F,tr as I,un as ee,v as te,vn as L,z as R}from"./ui-C5_NcAmG.js";import{t as ne}from"./upload-DcAIMe8d.js";import{St as re,Yt as z,xt as ie}from"./index-D_0jeO3M.js";var ae={name:`calendar`,size:24,node:[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};ae.node;var oe=I(ae),se={name:`files`,size:24,node:[[`path`,{d:`M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8`,key:`14sh0y`}],[`path`,{d:`M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z`,key:`1970lx`}],[`path`,{d:`M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1`,key:`l4dndm`}]]};se.node;var ce=I(se),le={name:`hash`,size:24,node:[[`line`,{x1:`4`,x2:`20`,y1:`9`,y2:`9`,key:`4lhtct`}],[`line`,{x1:`4`,x2:`20`,y1:`15`,y2:`15`,key:`vyu0kd`}],[`line`,{x1:`10`,x2:`8`,y1:`3`,y2:`21`,key:`1ggp8o`}],[`line`,{x1:`16`,x2:`14`,y1:`3`,y2:`21`,key:`weycgp`}]]};le.node;var ue=I(le),de={name:`list-ordered`,size:24,node:[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]};de.node;var fe=I(de),B={name:`messages-square`,size:24,node:[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]};B.node;var V=I(B),pe={name:`minimize-2`,size:24,node:[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]};pe.node;var me=I(pe),he={name:`tags`,size:24,node:[[`path`,{d:`M13.172 2a2 2 0 0 1 1.414.586l6.71 6.71a2.4 2.4 0 0 1 0 3.408l-4.592 4.592a2.4 2.4 0 0 1-3.408 0l-6.71-6.71A2 2 0 0 1 6 9.172V3a1 1 0 0 1 1-1z`,key:`16rjxf`}],[`path`,{d:`M2 7v6.172a2 2 0 0 0 .586 1.414l6.71 6.71a2.4 2.4 0 0 0 3.191.193`,key:`178nd4`}],[`circle`,{cx:`10.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`12ikhr`}]]};he.node;var ge=I(he),_e={name:`toggle-left`,size:24,node:[[`circle`,{cx:`9`,cy:`12`,r:`3`,key:`u3jwor`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`7`,key:`g7kal2`}]]};_e.node;var H=I(_e),U=e(t(),1),W=e(n(),1),G={choice:ge,date:oe,number:ue,text:ie,boolean:H},K=e=>[`knowledge`,e];function ve(e){return e===1?O(`know.item`):O(`know.items`,{n:e})}function q(e,t){if(e.type===`boolean`||typeof t==`boolean`)return O(t?`know.yes`:`know.no`);if(e.type===`date`&&typeof t==`string`){let[e,n]=t.split(` `),r=new Date(`${e}T00:00:00`),i=Number.isNaN(r.getTime())?t:r.toLocaleDateString(N,{day:`2-digit`,month:`2-digit`,year:`numeric`});return n?`${i} ${n}`:i}return e.type===`number`&&typeof t==`number`?`${t.toLocaleString(N)}${e.unit?` ${e.unit}`:``}`:String(t)}function ye(e,t){return e.flatMap(e=>{let n=t.find(t=>t.categoryId===e.id);return n?e.type===`boolean`?n.values[0]===!0?[e.name]:[]:[n.values.map(t=>q(e,t)).join(`, `)]:[]}).join(` · `)}function be({trigger:e,open:t,onOpen:n,children:r}){let i=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(!t)return;let e=e=>{i.current?.contains(e.target)||n(!1)},r=e=>e.key===`Escape`&&n(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,r),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,r)}},[t,n]),(0,W.jsxs)(`div`,{ref:i,className:`relative inline-flex`,children:[e,t?(0,W.jsx)(`div`,{className:`absolute top-full left-0 z-30 mt-1.5 w-72 max-w-[calc(100vw-32px)] rounded-xl bg-card p-3 shadow-overlay ring-1 ring-border-soft`,children:r}):null]})}function xe({category:e,current:t,onSave:n}){let[r,i]=(0,U.useState)(t[0]===void 0?``:String(t[0]));if(e.type===`choice`){let a=t.map(String);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[e.values.length?(0,W.jsx)(k,{multi:!0,value:a,options:e.values.map(e=>e.value),onChange:t=>n(e.multiple?t:t.filter(e=>!a.includes(e)).slice(0,1))}):null,(0,W.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),r.trim()&&n(e.multiple?[...a,r.trim()]:[r.trim()])},children:[(0,W.jsx)(F,{"data-autofocus":!0,value:a.includes(r)?``:r,placeholder:O(`know.addValue`),onChange:e=>i(e.target.value),className:`h-9`}),(0,W.jsx)(D,{label:O(`know.addValue`),type:`submit`,children:(0,W.jsx)(p,{className:`size-4`})})]})]})}return e.type===`boolean`?(0,W.jsx)(k,{value:t[0]===!0?O(`know.yes`):t[0]===!1?O(`know.no`):``,options:[O(`know.yes`),O(`know.no`)],onChange:e=>n([e===O(`know.yes`)])}):(0,W.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),n(r.trim()?[e.type===`number`?Number(r.replace(`,`,`.`)):r.trim()]:[])},children:[(0,W.jsx)(F,{"data-autofocus":!0,type:e.type===`date`?`date`:e.type===`number`?`number`:`text`,step:`any`,value:e.type===`date`?r.slice(0,10):r,onChange:e=>i(e.target.value),className:`h-9`}),(0,W.jsx)(x,{type:`submit`,size:`sm`,children:`OK`})]})}function Se({projectId:e,itemKey:t,has:n,categories:r,readOnly:i}){let a=h(),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)(n);(0,U.useEffect)(()=>l(n),[n]);let u=z({mutationFn:({categoryId:n,next:r})=>v.put(`/api/studio/projects/${e}/items/${t}/categories/${n}`,{values:r}),onSuccess:()=>a.invalidateQueries({queryKey:K(e)})}),d=r.filter(e=>!(e.proposed||e.tableId)),f=(e,t)=>{l(n=>[...n.filter(t=>t.categoryId!==e.id),...t.length?[{categoryId:e.id,values:t,by:`person`}]:[]]),u.mutate({categoryId:e.id,next:t}),s(null)},m=d.filter(e=>c.some(t=>t.categoryId===e.id)),g=d.filter(e=>!c.some(t=>t.categoryId===e.id));return d.length?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[m.map(e=>{let t=c.find(t=>t.categoryId===e.id),n=G[e.type],r=(0,W.jsxs)(`button`,{type:`button`,disabled:i,title:`${e.name} · ${O(`know.by.${t.by}`)}`,onClick:()=>s(o===e.id?null:e.id),className:`inline-flex h-7 items-center gap-1.5 rounded-full bg-paper-2 px-2.5 text-[0.75rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink disabled:pointer-events-none`,children:[(0,W.jsx)(n,{className:`size-3.5 text-ink-3`}),(0,W.jsx)(`span`,{className:`text-ink-3`,children:e.name}),(0,W.jsx)(`span`,{className:`font-medium`,children:t.values.map(t=>q(e,t)).join(`, `)})]},e.id);return i?(0,W.jsx)(`span`,{children:r},e.id):(0,W.jsxs)(be,{trigger:r,open:o===e.id,onOpen:t=>s(t?e.id:null),children:[(0,W.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-[0.8125rem]`,children:e.name}),(0,W.jsx)(D,{label:O(`know.remove`),onClick:()=>f(e,[]),className:`size-7`,children:(0,W.jsx)(L,{className:`size-3.5`})})]}),(0,W.jsx)(xe,{category:e,current:t.values,onSave:t=>f(e,t)})]},e.id)}),i||!g.length?null:(0,W.jsx)(be,{open:o===`+`,onOpen:e=>s(e?`+`:null),trigger:(0,W.jsxs)(`button`,{type:`button`,onClick:()=>s(o===`+`?null:`+`),className:`inline-flex h-7 items-center gap-1 rounded-full px-2 text-[0.75rem] text-ink-3 ring-1 ring-border-soft transition hover:text-ink hover:ring-border`,children:[(0,W.jsx)(p,{className:`size-3.5`}),` `,O(`know.category`)]}),children:(0,W.jsx)(Ce,{categories:g,onSave:f})})]}):null}function Ce({categories:e,onSave:t}){let[n,r]=(0,U.useState)(e[0]?.id??``),i=e.find(e=>e.id===n);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,W.jsx)(C,{value:n,onChange:r,options:e.map(e=>({value:e.id,label:e.name}))}),i?(0,W.jsx)(xe,{category:i,current:[],onSave:e=>t(i,e)},i.id):null]})}function we({projectId:e,open:t,onClose:n,onMade:r}){let i=h(),[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(`choice`),[l,u]=(0,U.useState)(``),[d,f]=(0,U.useState)(!1),[p,g]=(0,U.useState)(!1),[_,y]=(0,U.useState)(``),[b,S]=(0,U.useState)(``),w=z({mutationFn:()=>v.post(`/api/studio/projects/${e}/categories`,{name:a.trim(),type:s,unit:s===`number`&&l.trim()||null,multiple:s===`choice`&&d,ordered:s===`choice`&&p,hint:b.trim()||null,values:s===`choice`?_.split(`
|
|
2
2
|
`).map(e=>e.trim()).filter(Boolean):void 0}),onSuccess:async({id:t})=>{await i.invalidateQueries({queryKey:K(e)}),o(``),y(``),S(``),r(t)}});return(0,W.jsx)(m,{open:t,onClose:n,title:O(`know.newCategory`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.trim()&&w.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{children:O(`know.name`)}),(0,W.jsx)(F,{"data-autofocus":!0,value:a,maxLength:80,onChange:e=>o(e.target.value)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{children:O(`know.type`)}),(0,W.jsx)(C,{value:s,onChange:e=>c(e),options:[`choice`,`date`,`number`,`text`,`boolean`].map(e=>({value:e,label:O(`know.type.${e}`)}))})]}),s===`number`?(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{hint:O(`know.unitHint`),children:O(`know.unit`)}),(0,W.jsx)(F,{value:l,maxLength:20,onChange:e=>u(e.target.value)})]}):null,s===`choice`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{hint:O(`know.valuesHint`),children:O(`know.values`)}),(0,W.jsx)(ee,{minRows:3,value:_,onChange:e=>y(e.target.value)})]}),(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[O(`know.multiple`),(0,W.jsx)(T,{checked:d,onChange:f})]}),(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[O(`know.ordered`),(0,W.jsx)(T,{checked:p,onChange:g})]})]}):null,(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{hint:O(`know.hintFieldHint`),children:O(`know.hintField`)}),(0,W.jsx)(F,{value:b,maxLength:120,onChange:e=>S(e.target.value)})]}),w.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:w.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(x,{variant:`ghost`,onClick:n,children:O(`common.cancel`)}),(0,W.jsx)(x,{type:`submit`,busy:w.isPending,disabled:!a.trim(),children:O(`know.create`)})]})]})})}function Te({projectId:e,category:t,readOnly:n,onOpen:i,onGone:a}){let s=h(),c=()=>s.invalidateQueries({queryKey:K(e)}),[l,u]=(0,U.useState)(``),d=z({mutationFn:e=>e(),onSuccess:c}),f=G[t.type],m=new Map(t.values.map(e=>[e.id,e]));return(0,W.jsxs)(o,{title:t.name,hint:[O(`know.type.${t.type}`),t.unit,t.hint].filter(Boolean).join(` · `),plain:!0,action:n?null:(0,W.jsx)(D,{label:O(`know.deleteCategory`),className:`hover:text-rose`,onClick:()=>confirm(O(`know.confirmCategory`,{name:t.name}))&&d.mutate(async()=>{await v.del(`/api/studio/categories/${t.id}`),a()}),children:(0,W.jsx)(w,{className:`size-4`})}),children:[t.proposed&&!n?(0,W.jsxs)(y,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,W.jsx)(S,{tone:`ember`,children:O(`know.proposed`)}),(0,W.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:O(`know.proposedHint`)}),(0,W.jsx)(x,{size:`sm`,onClick:()=>d.mutate(()=>v.patch(`/api/studio/categories/${t.id}`,{proposed:!1})),children:O(`know.accept`)})]}):null,t.alike.map(([e,t])=>{let r=m.get(e),i=m.get(t);if(!(r&&i))return null;let[a,o]=r.count<i.count?[r,i]:[i,r];return(0,W.jsxs)(y,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,W.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:O(`know.alike`,{a:a.value,b:o.value})}),n?null:(0,W.jsx)(x,{size:`sm`,variant:`secondary`,busy:d.isPending,onClick:()=>d.mutate(()=>v.post(`/api/studio/values/${a.id}/merge`,{into:o.id})),children:O(`know.merge`)})]},`${e}:${t}`)}),(0,W.jsxs)(y,{className:`flex flex-col p-1.5`,children:[t.type===`choice`?t.values.length?t.values.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i(`v:${e.id}`),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,W.jsx)(f,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.value}),e.summary?(0,W.jsx)(S,{children:O(`know.summary`)}):null,(0,W.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:ve(e.count)})]},e.id)):(0,W.jsx)(r,{children:O(`know.empty`)}):(0,W.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5 text-[0.875rem]`,children:[(0,W.jsx)(f,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`flex-1 text-ink-2`,children:t.range?O(`know.range`,{min:q(t,t.range.min),max:q(t,t.range.max)}):O(`know.unset`)}),(0,W.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:ve(t.count)})]}),t.type===`choice`&&!n?(0,W.jsxs)(`form`,{className:`flex gap-2 border-border-soft border-t p-2`,onSubmit:e=>{e.preventDefault();let n=l.trim();n&&(u(``),d.mutate(()=>v.post(`/api/studio/categories/${t.id}/values`,{value:n})))},children:[(0,W.jsx)(F,{value:l,placeholder:O(`know.addValue`),onChange:e=>u(e.target.value),className:`h-9`}),(0,W.jsx)(D,{label:O(`know.addValue`),type:`submit`,children:(0,W.jsx)(p,{className:`size-4`})})]}):null]}),d.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:d.error.message}):null]})}function Ee(e){return P({queryKey:[`knowledge-value`,e],queryFn:()=>v.get(`/api/studio/values/${e}`),enabled:!!e})}function De({value:e,readOnly:t,children:n}){let r=h(),i=z({mutationFn:()=>v.post(`/api/studio/values/${e.id}/summary`),onSuccess:()=>r.invalidateQueries({queryKey:[`knowledge-value`,e.id]})});return(0,W.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,W.jsx)(o,{title:O(`know.summary`),hint:O(`know.summaryHint`),plain:!0,action:t?null:(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,busy:i.isPending,onClick:()=>i.mutate(),children:[e.summary?(0,W.jsx)(s,{className:`size-4`}):null,e.summary?O(`know.summaryAgain`):O(`know.summaryWrite`)]}),children:(0,W.jsxs)(y,{className:`p-4 sm:p-5`,children:[i.isPending?(0,W.jsx)(`div`,{className:`flex h-24 items-center justify-center text-ink-3`,children:(0,W.jsx)(j,{})}):e.summary?(0,W.jsx)(M,{text:e.summary,className:`text-[0.875rem]`}):(0,W.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:O(`know.summaryEmpty`)}),i.error?(0,W.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:i.error.message}):null]})}),(0,W.jsx)(o,{title:O(`know.toc`),plain:!0,children:n})]})}function Oe(e){return P({queryKey:[`knowledge`,e],queryFn:()=>v.get(`/api/studio/projects/${e}/knowledge`),enabled:!!e,refetchInterval:e=>e.state.data?.items.some(e=>e.status===`pending`)?2e3:!1})}function ke(e){return e.kind===`table`?e.format===`faq`?V:re:e.kind===`file`?f:e.children?ce:a}function J({item:e,categories:t,onOpen:n}){let r=ke(e),i=[ye(t,e.categories),e.children?e.children===1?O(`know.oneSub`):O(`know.sub`,{n:e.children}):``,e.rows===null?``:e.rows===1?O(`know.row`):O(`know.rows`,{n:e.rows}),e.originLabel??``].filter(Boolean).join(` · `);return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(e.key),disabled:e.status===`pending`,className:`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent disabled:pointer-events-none`,children:[(0,W.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`span`,{className:`block truncate text-[0.875rem]`,children:e.title}),i?(0,W.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:i}):null]}),e.status===`pending`?(0,W.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[(0,W.jsx)(j,{className:`size-3`}),` `,O(`know.reading`)]}):e.review?(0,W.jsx)(S,{tone:`warn`,title:e.review,children:O(`know.review`)}):null]})}function Y({projectId:e,itemKey:t,has:n,originLabel:r,kept:i,review:a,file:o,readOnly:s,onReviewed:c}){let l=Oe(e),u=[r?O(i?`know.kept`:`know.from`,{label:r}):``].filter(Boolean);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 px-1`,children:[l.data?(0,W.jsx)(Se,{projectId:e,itemKey:t,has:n,categories:l.data.categories,readOnly:s}):null,u.length||o||a?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[0.8125rem] text-ink-3`,children:[u.map(e=>(0,W.jsx)(`span`,{children:e},e)),o?(0,W.jsxs)(`a`,{href:R(e,o.id),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 underline-offset-2 hover:text-ink hover:underline`,children:[(0,W.jsx)(f,{className:`size-3.5`}),` `,O(`know.original`),`: `,o.name]}):null,a?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,W.jsx)(S,{tone:`warn`,children:O(`know.review`)}),(0,W.jsx)(`span`,{children:a}),s?null:(0,W.jsx)(`button`,{type:`button`,onClick:c,className:`underline hover:text-ink`,children:O(`know.reviewed`)})]}):null]}):null]})}function Ae(e){let t=e.filter(Number.isFinite).sort((e,t)=>e-t);if(new Set(t).size<=4)return[];let n=t[0],r=t.at(-1),i=e=>e.slice(0,-1).map((t,n)=>({lo:t,hi:e[n+1]})).filter(e=>t.some(t=>t>=e.lo&&t<e.hi));if(n>0&&r/n>=30){let e=Math.floor(Math.log10(n)),t=Math.floor(Math.log10(r))+1;for(let a of[[1,2,5],[1,3],[1]]){let o=[];for(let n=e;n<=t;n++)for(let e of a)o.push(e*10**n);let s=i(o.filter((e,t)=>e<=n||o[t-1]<=r));if(s.length<=7)return s}}let a=(r-n)/5,o=10**Math.floor(Math.log10(a)),s=([1,2,2.5,5,10].map(e=>e*o).find(e=>e>=a)??a)||1,c=[];for(let e=Math.floor(n/s)*s;e<=r;e+=s)c.push(e);return c.push(c.at(-1)+s),i(c)}function je({projectId:e,category:t,categories:n,onOpen:r}){let i=P({queryKey:[`knowledge`,e,`category`,t.id],queryFn:()=>v.get(`/api/studio/categories/${t.id}/items`)});if(!i.data)return i.isLoading?(0,W.jsx)(j,{className:`mx-auto size-4 text-ink-3`}):null;let a=e=>e.categories.find(e=>e.categoryId===t.id)?.values[0],o=[...i.data.items].sort((e,t)=>{let n=a(e),r=a(t);return typeof n==`number`&&typeof r==`number`?n-r:String(r??``).localeCompare(String(n??``),N)}),s=t.type===`number`?Ae(o.map(a).filter(e=>typeof e==`number`)):[],c=new Intl.NumberFormat(N,{notation:`compact`,maximumFractionDigits:1}),l=t.unit?` ${t.unit}`:``,u=new Map;for(let e of o){let n=a(e),r=typeof n==`number`?s.find(e=>n>=e.lo&&n<e.hi):void 0,i=n===void 0?``:t.type===`date`?new Date(`${String(n).slice(0,7)}-01T00:00:00`).toLocaleDateString(N,{month:`long`,year:`numeric`}):r?O(`know.range`,{min:`${c.format(r.lo)}${l}`,max:`${c.format(r.hi)}${l}`}):q(t,n);u.set(i,[...u.get(i)??[],e])}return(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[[...u].map(([e,t])=>(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[e?(0,W.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e}):null,(0,W.jsx)(y,{className:`flex flex-col p-1.5`,children:t.map(e=>(0,W.jsx)(J,{item:e,categories:n,onOpen:r},e.key))})]},e)),i.data.rows.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>r(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:O(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})}function Me(e,t,n){return Array.isArray(n)?t.some(e=>n.map(String).includes(String(e))):typeof n==`object`&&n?t.some(t=>{if(e.type===`number`&&typeof t==`number`)return(n.gte===void 0||t>=n.gte)&&(n.lte===void 0||t<=n.lte);if(e.type===`date`){let e=String(t).slice(0,10);return(!n.after||e>=n.after)&&(!n.before||e<=n.before)}return!n.contains||String(t).toLowerCase().includes(n.contains.toLowerCase())}):t.some(e=>e===n)}function Ne(e,t){if(Array.isArray(t))return t.map(String).join(`, `);if(typeof t==`boolean`)return O(t?`know.yes`:`know.no`);if(typeof t==`object`&&t){let n=t.gte??t.after,r=t.lte??t.before;return t.contains?`${O(`know.contains`)} ${t.contains}`:[n===void 0?``:`${O(`know.minimum`)} ${q(e,n)}`,r===void 0?``:`${O(`know.maximum`)} ${q(e,r)}`].filter(Boolean).join(` `)}return String(t)}function Pe({category:e,value:t,onChange:n}){let[r,i]=(0,U.useState)(!1),a=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!r)return;let e=e=>!a.current?.contains(e.target)&&i(!1);return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[r]);let o=G[e.type],s=typeof t==`object`&&t&&!Array.isArray(t)?t:{},c=(t,r)=>{let i={...s,[t]:r===``?void 0:e.type===`number`?Number(r):r},a=Object.fromEntries(Object.entries(i).filter(([,e])=>e!==void 0));n(Object.keys(a).length?a:void 0)};return(0,W.jsxs)(`div`,{ref:a,className:`relative`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:E(`inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-[0.8125rem] transition`,t===void 0?`text-ink-2 ring-1 ring-border-soft hover:ring-border`:`bg-ember-tint text-ink ring-1 ring-ember/30`),children:[(0,W.jsx)(o,{className:`size-3.5 text-ink-3`}),e.name,t===void 0?null:(0,W.jsxs)(`span`,{className:`font-medium`,children:[`: `,Ne(e,t)]}),(0,W.jsx)(u,{className:`size-3.5 text-ink-3`})]}),r?(0,W.jsxs)(`div`,{className:`absolute top-full left-0 z-30 mt-1.5 w-72 max-w-[calc(100vw-32px)] rounded-xl bg-card p-3 shadow-overlay ring-1 ring-border-soft`,children:[e.type===`choice`?(0,W.jsx)(k,{multi:!0,value:Array.isArray(t)?t.map(String):[],options:e.values.map(e=>e.value),onChange:e=>n(e.length?e:void 0)}):e.type===`boolean`?(0,W.jsx)(k,{value:t===!0?O(`know.yes`):t===!1?O(`know.no`):``,options:[O(`know.yes`),O(`know.no`)],onChange:e=>n(e===O(`know.yes`))}):e.type===`text`?(0,W.jsx)(F,{"data-autofocus":!0,value:s.contains??``,placeholder:O(`know.contains`),onChange:e=>n(e.target.value?{contains:e.target.value}:void 0),className:`h-9`}):(0,W.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:(e.type===`number`?[`gte`,`lte`]:[`after`,`before`]).map((t,n)=>(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{children:O(n===0?`know.minimum`:`know.maximum`)}),(0,W.jsx)(F,{type:e.type===`number`?`number`:`date`,step:`any`,value:String(s[t]??``),placeholder:e.range?String(n===0?e.range.min:e.range.max):``,onChange:e=>c(t,e.target.value),className:`h-9`})]},t))}),t===void 0?null:(0,W.jsx)(`button`,{type:`button`,onClick:()=>{n(void 0),i(!1)},className:`mt-3 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:O(`know.clear`)})]}):null]})}function Fe({found:e,onOpen:t}){return e.hits.length?(0,W.jsxs)(`div`,{className:`flex flex-col`,children:[(0,W.jsx)(`p`,{className:`px-3 pt-1 pb-2 text-[0.75rem] text-ink-3`,children:e.checked?O(`know.searchStats`,{candidates:e.candidates,hits:e.hits.length}):O(`know.searchUnchecked`,{hits:e.hits.length})}),e.hits.map(e=>{let n=e.open;return(0,W.jsxs)(`button`,{type:`button`,disabled:!n,onClick:()=>n&&t(n),className:`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent disabled:pointer-events-none`,children:[(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`span`,{className:`block truncate text-[0.875rem]`,children:[e.title,e.heading&&e.heading!==e.title?(0,W.jsxs)(`span`,{className:`text-ink-3`,children:[` › `,e.heading]}):null]}),(0,W.jsx)(`span`,{className:`line-clamp-2 text-[0.8125rem] text-ink-3`,children:e.text})]}),e.relevance===null?null:(0,W.jsx)(`span`,{className:`shrink-0 font-medium text-[0.75rem] text-moss tabular-nums`,children:e.relevance.toLocaleString(N,{minimumFractionDigits:2})})]},`${e.key}:${e.heading}`)})]}):(0,W.jsx)(`p`,{className:`px-3 py-4 text-[0.875rem] text-ink-3`,children:O(`know.searchNone`)})}function Ie({kind:e,projectId:t,onClose:n,onMade:r}){let i=h(),[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(!1),l=z({mutationFn:()=>v.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:a.trim(),...e===`table`&&s?{format:`faq`}:{}}),onSuccess:async({id:n})=>{await i.invalidateQueries({queryKey:[`knowledge`,t]}),r(`${e===`table`?`t`:`p`}:${n}`),o(``),c(!1)}});return(0,W.jsx)(m,{open:e!==null,onClose:n,title:O(e===`table`?`know.newTable`:`know.newPage`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.trim()&&l.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{children:O(`data.title`)}),(0,W.jsx)(F,{"data-autofocus":!0,value:a,maxLength:120,onChange:e=>o(e.target.value)})]}),e===`table`?(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[O(`know.asFaq`),(0,W.jsx)(T,{checked:s,onChange:c})]}):null,l.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(x,{variant:`ghost`,onClick:n,children:O(`common.cancel`)}),(0,W.jsx)(x,{type:`submit`,busy:l.isPending,disabled:!a.trim(),children:O(`know.create`)})]})]})})}function Le({projectId:e,data:t,readOnly:n,onOpen:i}){let a=h(),s=_(e,n),[c,l]=(0,U.useState)({}),[u,d]=(0,U.useState)(``),[f,m]=(0,U.useState)(null),[b,C]=(0,U.useState)(!1),[w,T]=(0,U.useState)(null),E=t.categories.filter(e=>!e.proposed&&e.count>0),D=t.categories.filter(e=>e.proposed),k=t.items.filter(e=>Object.entries(c).every(([n,r])=>{let i=t.categories.find(e=>e.name===n),a=e.categories.find(e=>e.categoryId===i?.id);return i&&a?Me(i,a.values,r):!1})),A=async()=>{if(!u.trim()){m(null);return}C(!0);try{m(await v.post(`/api/studio/projects/${e}/search`,{query:u,...Object.keys(c).length?{where:c}:{}}))}catch{m({hits:[],candidates:0,checked:!1,filtered:null})}finally{C(!1)}},M=z({mutationFn:({id:e,keep:t})=>t?v.patch(`/api/studio/categories/${e}`,{proposed:!1}):v.del(`/api/studio/categories/${e}`),onSuccess:()=>a.invalidateQueries({queryKey:[`knowledge`,e]})});return(0,W.jsxs)(o,{title:O(`know.title`),hint:O(`know.hint`),plain:!0,action:n?null:(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,onClick:()=>T(`page`),children:[(0,W.jsx)(p,{className:`size-4`}),` `,O(`know.page`)]}),(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,onClick:()=>T(`table`),children:[(0,W.jsx)(p,{className:`size-4`}),` `,O(`know.table`)]}),(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,onClick:()=>T(`category`),children:[(0,W.jsx)(p,{className:`size-4`}),` `,O(`know.category`)]})]}),children:[D.length&&!n?(0,W.jsx)(y,{className:`flex flex-col gap-2 p-4`,children:D.map(e=>{let t=G[e.type];return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,W.jsx)(S,{tone:`ember`,children:O(`know.proposed`)}),(0,W.jsx)(t,{className:`size-4 text-ink-3`}),(0,W.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:e.name}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem] text-ink-3`,children:[O(`know.type.${e.type}`),e.hint].filter(Boolean).join(` · `)}),(0,W.jsx)(x,{size:`sm`,variant:`ghost`,onClick:()=>M.mutate({id:e.id,keep:!1}),children:O(`know.dismiss`)}),(0,W.jsx)(x,{size:`sm`,onClick:()=>M.mutate({id:e.id,keep:!0}),children:O(`know.accept`)})]},e.id)})}):null,t.items.length?(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,W.jsx)(g,{value:u,placeholder:O(`know.search`),busy:b,onEnter:()=>void A(),onChange:e=>{d(e),e.trim()||m(null)}}),E.length?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[E.map(e=>(0,W.jsx)(Pe,{category:e,value:c[e.name],onChange:t=>{m(null),l(n=>{let r={...n};return t===void 0?delete r[e.name]:r[e.name]=t,r})}},e.id)),Object.keys(c).length?(0,W.jsx)(`button`,{type:`button`,onClick:()=>l({}),className:`px-2 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:O(`know.clear`)}):null]}):null]}):null,(0,W.jsx)(y,{className:`flex flex-col p-1.5`,children:f?(0,W.jsx)(Fe,{found:f,onOpen:i}):k.length?k.map(e=>(0,W.jsx)(J,{item:e,categories:t.categories,onOpen:i},e.key)):(0,W.jsx)(r,{children:O(`know.empty`)})}),n?null:(0,W.jsxs)(te,{accept:`.pdf,.docx,.doc,.xlsx,.csv,.tsv,.txt,.md,.json,.html,.eml,image/*`,onFiles:async t=>{await s.upload(`document`,t),await a.invalidateQueries({queryKey:[`knowledge`,e]})},className:`h-14 w-full`,children:[s.busy?(0,W.jsx)(j,{className:`size-4`}):(0,W.jsx)(ne,{className:`size-4`}),O(`know.drop`),` `,(0,W.jsx)(`span`,{className:`underline`,children:O(`know.pick`)})]}),s.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s.error}):null,t.items.length&&!(t.checked&&t.embeddings)?(0,W.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:[t.embeddings?``:O(`know.keywordsOnly`),t.checked?``:O(`know.unchecked`)].filter(Boolean).join(` `)}):null,(0,W.jsx)(Ie,{kind:w===`page`||w===`table`?w:null,projectId:e,onClose:()=>T(null),onMade:e=>{T(null),i(e)}}),(0,W.jsx)(we,{projectId:e,open:w===`category`,onClose:()=>T(null),onMade:e=>{T(null),i(`c:${e}`)}})]})}function Re({page:e,onGone:t,onOpen:n}){let r=h(),[o,s]=(0,U.useState)(e.title),[c,l]=(0,U.useState)(e.markdown),[u,f]=(0,U.useState)(e.markdown?`read`:`write`),m=e.knowledge,g=async()=>{await r.invalidateQueries({queryKey:[`space-data`,e.projectId]}),await r.invalidateQueries({queryKey:[`knowledge`,e.projectId]})},_=i({title:o.trim()||e.title,markdown:c},async t=>{await v.patch(`/api/studio/pages/${e.id}`,t),r.setQueryData([`space-page`,e.id],e=>e&&{...e,...t}),t.title!==e.title&&await g()}),S=z({mutationFn:()=>v.del(`/api/studio/pages/${e.id}`),onSuccess:async()=>{await g(),t()}}),C=z({mutationFn:()=>v.post(`/api/studio/projects/${e.projectId}/pages`,{title:O(`know.addSub`),parentId:e.id}),onSuccess:async({id:e})=>{await g(),n?.(`p:${e}`)}}),T=z({mutationFn:()=>v.patch(`/api/studio/pages/${e.id}`,{review:null}),onSuccess:()=>r.invalidateQueries({queryKey:[`space-page`,e.id]})}),k=async t=>{let r=t.target.closest(`a`)?.getAttribute(`href`);if(!(r?.startsWith(`pages/`)&&n))return;t.preventDefault();let i=await v.get(`/api/studio/projects/${e.projectId}/resolve?path=${encodeURIComponent(r)}`).catch(()=>null);i?.kind===`page`&&n(`p:${i.id}`)},A=e.readOnly,N=m?.file&&(m.file.mime===`application/pdf`||m.file.mime.startsWith(`image/`))?m.file:null,P=(e,t)=>(0,W.jsx)(`button`,{type:`button`,"aria-pressed":u===e,onClick:()=>f(e),className:E(`rounded-full px-3 py-1 text-[0.8125rem] transition`,u===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,W.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[m?.parents.length&&n?(0,W.jsx)(`nav`,{className:`-mb-1.5 flex flex-wrap items-center gap-1 px-1 text-[0.8125rem] text-ink-3`,children:m.parents.map(e=>(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>n(`p:${e.id}`),className:`hover:text-ink`,children:e.title}),(0,W.jsx)(d,{className:`size-3.5`})]},e.id))}):null,(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,W.jsx)(`input`,{value:o,disabled:A,maxLength:200,onChange:e=>s(e.target.value),"aria-label":O(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),_.state===`saving`?(0,W.jsx)(j,{className:`size-3.5 text-ink-3`}):_.state===`saved`?(0,W.jsx)(b,{className:`size-4 text-moss`,"aria-label":O(`settings.saved`)}):null,A?null:(0,W.jsx)(D,{label:O(`data.deletePage`),onClick:()=>confirm(O(`data.confirmDelete`,{title:e.title}))&&S.mutate(),className:`hover:text-rose`,children:(0,W.jsx)(w,{className:`size-4`})})]}),m?(0,W.jsx)(Y,{projectId:e.projectId,itemKey:`p:${e.id}`,has:m.categories,originLabel:m.originLabel,kept:m.kept,review:m.review,file:N?null:m.file,readOnly:A,onReviewed:()=>T.mutate()}):null,(0,W.jsxs)(y,{className:`flex flex-col`,children:[A&&!N?null:(0,W.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[A?null:P(`write`,O(`data.write`)),P(`read`,O(`data.preview`)),N?P(`original`,O(`know.original`)):null,(0,W.jsx)(`span`,{className:`ml-auto truncate px-2 text-[0.75rem] text-ink-4 max-sm:hidden`,children:u===`original`&&N?N.name:O(`data.markdownHint`)})]}),u===`original`&&N?N.mime===`application/pdf`?(0,W.jsx)(`iframe`,{src:R(e.projectId,N.id),title:N.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,W.jsx)(`img`,{src:R(e.projectId,N.id),alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):u===`write`&&!A?(0,W.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),"aria-label":e.title,placeholder:O(`data.pageEmpty`),className:`field-sizing-content min-h-[50vh] w-full resize-none bg-transparent p-4 font-mono text-[0.8125rem] leading-relaxed outline-none placeholder:text-ink-4 sm:p-5`}):(0,W.jsx)(`div`,{className:`min-h-40 p-4 sm:p-5`,onClick:k,children:c.trim()?(0,W.jsx)(M,{text:c}):(0,W.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:O(`data.pageEmpty`)})})]}),_.state===`error`&&_.error?(0,W.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:_.error}):null,m&&n&&(m.children.length||!A)?(0,W.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-1`,children:[(0,W.jsx)(`p`,{className:`font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:m.children.length?O(`know.subPages`):null}),A?null:(0,W.jsxs)(x,{variant:`ghost`,size:`sm`,busy:C.isPending,onClick:()=>C.mutate(),children:[(0,W.jsx)(p,{className:`size-4`}),` `,O(`know.addSub`)]})]}),m.children.length?(0,W.jsx)(y,{className:`flex flex-col p-1.5`,children:m.children.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(`p:${e.id}`),className:`flex items-center gap-3 rounded-lg px-3 py-2 text-left transition hover:bg-accent`,children:[(0,W.jsx)(a,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title})]},e.id))}):null]}):null]})}function ze({pageId:e,onGone:t,onOpen:n}){let r=P({queryKey:[`space-page`,e],queryFn:()=>v.get(`/api/studio/pages/${e}`),refetchOnWindowFocus:!1});return r.data?(0,W.jsx)(Re,{page:r.data,onGone:t,onOpen:n},r.data.id):r.isError?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:r.error.message}):null}function Be(e){return P({queryKey:[`space-data`,e],queryFn:()=>v.get(`/api/studio/projects/${e}/data`),enabled:!!e})}function Ve(e){let t=t=>[...e.tables.filter(e=>e.wizardId===t).map(e=>({key:`t:${e.id}`,kind:`table`,title:e.title,rows:e.rows})),...e.pages.filter(e=>e.wizardId===t).map(e=>({key:`p:${e.id}`,kind:`page`,title:e.title}))];return[{key:`own`,label:O(`data.own`),items:t(null)},...e.wizards.map(e=>({key:e.id,label:e.title,items:t(e.id)}))].filter(e=>e.items.length)}var He={table:re,page:a};function Ue({kind:e,projectId:t,data:n,onClose:r,onMade:i}){let a=h(),[o,s]=(0,U.useState)(``),[c,l]=(0,U.useState)(``),u=z({mutationFn:()=>v.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:o.trim(),wizardId:c||null}),onSuccess:async({id:n})=>{await a.invalidateQueries({queryKey:[`space-data`,t]}),i(`${e===`table`?`t`:`p`}:${n}`),s(``),l(``)}});return(0,W.jsx)(m,{open:e!==null,onClose:r,title:O(e===`table`?`data.newTable`:`data.newPage`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o.trim()&&u.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{children:O(`data.title`)}),(0,W.jsx)(F,{"data-autofocus":!0,value:o,maxLength:120,onChange:e=>s(e.target.value)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{children:O(`data.owner`)}),(0,W.jsx)(C,{value:c,onChange:l,options:[{value:``,label:O(`data.own`)},...n.wizards.map(e=>({value:e.id,label:e.title}))]})]}),u.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:u.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(x,{variant:`ghost`,onClick:r,children:O(`common.cancel`)}),(0,W.jsx)(x,{type:`submit`,busy:u.isPending,disabled:!o.trim(),children:O(`data.create`)})]})]})})}function We({projectId:e,data:t,readOnly:n,onOpen:i}){let[a,s]=(0,U.useState)(null),c=Ve(t),l=new Map([...t.tables.map(e=>[`t:${e.id}`,e.updatedAt]),...t.pages.map(e=>[`p:${e.id}`,e.updatedAt])]),u=new Intl.DateTimeFormat(N,{dateStyle:`medium`});return(0,W.jsxs)(o,{title:O(`space.data`),hint:O(`data.hint`),plain:!0,action:n?null:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,onClick:()=>s(`table`),children:[(0,W.jsx)(p,{className:`size-4`}),` `,O(`data.table`)]}),(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,onClick:()=>s(`page`),children:[(0,W.jsx)(p,{className:`size-4`}),` `,O(`data.page`)]})]}),children:[c.length?(0,W.jsx)(`div`,{className:`flex flex-col gap-5`,children:c.map(e=>(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e.label}),(0,W.jsx)(y,{className:`flex flex-col p-1.5`,children:e.items.map(e=>{let t=He[e.kind];return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i(e.key),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,W.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title}),(0,W.jsxs)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:[e.kind===`table`?`${O(`data.rows`,{n:e.rows??0})} · `:``,u.format(new Date(l.get(e.key)??Date.now()))]})]},e.key)})})]},e.key))}):(0,W.jsx)(y,{children:(0,W.jsx)(r,{children:O(`data.empty`)})}),(0,W.jsx)(Ue,{kind:a,projectId:e,data:t,onClose:()=>s(null),onMade:e=>{s(null),i(e)}})]})}function Ge(e,t){let n=e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).replace(/^[^a-z]+/,``).slice(0,48)||`column`,r=n,i=2;for(;t.includes(r);)r=`${n}_${i++}`;return r}var Ke={milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5},qe=[`text`,`number`,`date`,`duration`,`select`,`boolean`];function Je(e,t){if(t==null)return``;if(e.type===`duration`&&typeof t==`number`)return String(t/Ke[e.format.inputUnit]);if(e.type===`date`&&e.format.kind===`datetime`&&typeof t==`string`){let e=new Date(t);return new Date(e.getTime()-e.getTimezoneOffset()*6e4).toISOString().slice(0,16)}return String(t)}function Ye(e,t){return t.trim()===``?null:e.type===`date`&&e.format.kind===`datetime`?new Date(t).toISOString():t}var X=`w-full min-w-0 rounded-md bg-transparent px-2 py-1.5 text-[0.875rem] outline-none transition placeholder:text-ink-4 hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`;function Xe({column:e,value:t,readOnly:n,invalid:r,onSave:i}){let a=Je(e,t),[o,s]=(0,U.useState)(a);(0,U.useEffect)(()=>s(a),[a]);let c=(t=o)=>{t!==a&&i(Ye(e,t))};if(e.type===`boolean`)return(0,W.jsx)(`div`,{className:`px-2 py-1.5`,children:(0,W.jsx)(`input`,{type:`checkbox`,checked:t===!0,disabled:n,onChange:e=>i(e.target.checked),"aria-label":e.name,className:`size-4 accent-[var(--ember)]`})});if(e.type===`select`&&e.format.multiple){let r=Array.isArray(t)?t:[],a=t=>e.format.options.find(e=>e.id===t)?.label??t;return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-2 py-1`,children:[r.map(e=>(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-paper-2 py-0.5 pr-1 pl-2 text-[0.75rem]`,children:[a(e),n?null:(0,W.jsx)(`button`,{type:`button`,"aria-label":O(`data.removeOption`),onClick:()=>i(r.filter(t=>t!==e)),className:`rounded-full text-ink-3 hover:text-ink`,children:(0,W.jsx)(L,{className:`size-3`})})]},e)),n?null:(0,W.jsxs)(`select`,{value:``,onChange:e=>e.target.value&&i([...r,e.target.value]),"aria-label":e.name,className:`h-7 rounded-md bg-transparent px-1 text-[0.75rem] text-ink-3 outline-none hover:bg-accent`,children:[(0,W.jsx)(`option`,{value:``,children:`+`}),e.format.options.filter(e=>!r.includes(e.id)).map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})}if(e.type===`select`)return(0,W.jsxs)(`select`,{value:typeof t==`string`?t:``,disabled:n,onChange:e=>i(e.target.value||null),"aria-label":e.name,className:X,children:[(0,W.jsx)(`option`,{value:``}),e.format.options.map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]});if(e.type===`text`&&e.format?.style&&e.format.style!==`single`)return(0,W.jsx)(`textarea`,{value:o,rows:1,disabled:n,onChange:e=>s(e.target.value),onBlur:()=>c(),"aria-label":e.name,className:E(X,`field-sizing-content max-h-40 resize-none`)});let l=e.type===`date`?{date:`date`,datetime:`datetime-local`,time:`time`}[e.format.kind]:`text`;return(0,W.jsx)(`input`,{type:l,inputMode:e.type===`number`||e.type===`duration`?`decimal`:void 0,value:o,disabled:n,onChange:t=>{s(t.target.value),e.type===`date`&&c(t.target.value)},onBlur:()=>e.type!==`date`&&c(),onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&s(a)},"aria-label":e.name,className:E(X,(e.type===`number`||e.type===`duration`)&&`text-right tabular-nums`,r&&`ring-1 ring-rose`)})}function Ze(e){return e.type===`number`&&e.format.style===`currency`?e.format.currency??null:e.type===`number`&&e.format.style===`percent`?`%`:e.type===`duration`?O(`data.unit.${e.format.inputUnit}`):null}function Qe(e){return{name:e?.name??``,type:e?.type??`text`,required:e?.required??!1,textStyle:e?.type===`text`&&(e.format?.style??`single`)!==`single`?`multiline`:`single`,numberStyle:e?.type===`number`?e.format.style:`decimal`,currency:e?.type===`number`?e.format.currency??`EUR`:`EUR`,dateKind:e?.type===`date`?e.format.kind:`date`,unit:e?.type===`duration`&&[`minutes`,`hours`,`days`].includes(e.format.inputUnit)?e.format.inputUnit:`minutes`,options:e?.type===`select`?e.format.options.map(e=>e.label).join(`
|
|
3
3
|
`):``,multiple:e?.type===`select`&&!!e.format.multiple}}function $e(e,t,n){let r={id:t,name:e.name.trim(),...e.required?{required:!0}:{}};switch(e.type){case`number`:return{...r,type:`number`,format:e.numberStyle===`currency`?{style:`currency`,currency:e.currency.trim().toUpperCase()}:{style:e.numberStyle}};case`date`:return{...r,type:`date`,format:{kind:e.dateKind}};case`duration`:return{...r,type:`duration`,format:{inputUnit:e.unit,display:`hms`}};case`select`:{let t=n?.type===`select`?n.format.options:[],i=[],a=e.options.split(`
|
|
4
4
|
`).map(e=>e.trim()).filter(Boolean).map(e=>{let n=t.find(t=>t.label===e)?.id??Ge(e,i);return i.push(n),{id:n,label:e}});return{...r,type:`select`,format:{allowCustom:!1,options:a,...e.multiple?{multiple:!0}:{}}}}case`boolean`:return{...r,type:`boolean`};default:return{...r,type:`text`,...e.textStyle===`multiline`?{format:{style:`multiline`}}:{}}}}function et({open:e,column:t,columns:n,onClose:r,onSave:i}){let[a,o]=(0,U.useState)(()=>Qe(t)),[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(!1);(0,U.useEffect)(()=>{e&&(o(Qe(t)),c(null))},[e,t]);let d=e=>o(t=>({...t,...e})),f=async e=>{u(!0),c(null);try{await i(e),r()}catch(e){c(e.message)}finally{u(!1)}},p=()=>{let e=t?.id??Ge(a.name,n.map(e=>e.id)),r=$e(a,e,t);return f(t?n.map(e=>e.id===t.id?r:e):[...n,r])};return(0,W.jsx)(m,{open:e,onClose:r,title:t?t.name:O(`data.newColumn`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.name.trim()&&p()},children:[(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{children:O(`data.columnName`)}),(0,W.jsx)(F,{"data-autofocus":!0,value:a.name,maxLength:128,onChange:e=>d({name:e.target.value})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{children:O(`data.columnType`)}),(0,W.jsx)(C,{value:a.type,onChange:e=>d({type:e}),options:qe.map(e=>({value:e,label:O(`data.type.${e}`)}))})]})]}),a.type===`text`?(0,W.jsx)(C,{value:a.textStyle,onChange:e=>d({textStyle:e}),options:[{value:`single`,label:O(`data.text.single`)},{value:`multiline`,label:O(`data.text.multiline`)}]}):null,a.type===`number`?(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsx)(C,{value:a.numberStyle,onChange:e=>d({numberStyle:e}),options:[`integer`,`decimal`,`percent`,`currency`].map(e=>({value:e,label:O(`data.number.${e}`)}))}),a.numberStyle===`currency`?(0,W.jsx)(F,{value:a.currency,maxLength:3,"aria-label":O(`data.currency`),placeholder:`EUR`,onChange:e=>d({currency:e.target.value})}):null]}):null,a.type===`date`?(0,W.jsx)(C,{value:a.dateKind,onChange:e=>d({dateKind:e}),options:[`date`,`datetime`,`time`].map(e=>({value:e,label:O(`data.date.${e}`)}))}):null,a.type===`duration`?(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{children:O(`data.unit`)}),(0,W.jsx)(C,{value:a.unit,onChange:e=>d({unit:e}),options:[`minutes`,`hours`,`days`].map(e=>({value:e,label:O(`data.unit.${e}`)}))})]}):null,a.type===`select`?(0,W.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(A,{children:O(`data.options`)}),(0,W.jsx)(ee,{minRows:3,value:a.options,onChange:e=>d({options:e.target.value})})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,W.jsx)(T,{checked:a.multiple,onChange:e=>d({multiple:e})}),O(`data.multiple`)]})]}):null,(0,W.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,W.jsx)(T,{checked:a.required,onChange:e=>d({required:e})}),O(`data.required`)]}),s?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&n.length>1?(0,W.jsx)(x,{variant:`ghost`,className:`text-rose`,disabled:l,onClick:()=>confirm(O(`data.confirmDelete`,{title:t.name}))&&void f(n.filter(e=>e.id!==t.id)),children:O(`data.deleteColumn`)}):null,(0,W.jsx)(`span`,{className:`flex-1`}),(0,W.jsx)(x,{variant:`ghost`,onClick:r,children:O(`common.cancel`)}),(0,W.jsx)(x,{type:`submit`,busy:l,disabled:!a.name.trim(),children:O(`settings.save`)})]})]})})}function tt({tableId:e,onGone:t}){let n=h(),r=[`space-table`,e],i=P({queryKey:r,queryFn:()=>v.get(`/api/studio/tables/${e}`)}),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(null),[u,d]=(0,U.useState)(null),[f,m]=(0,U.useState)(``);(0,U.useEffect)(()=>m(i.data?.title??``),[i.data?.title]);let g=async()=>{await n.invalidateQueries({queryKey:[`space-data`,i.data?.projectId]}),await n.invalidateQueries({queryKey:[`knowledge`,i.data?.projectId]})},_=e=>n.setQueryData(r,t=>t&&{...t,rows:e(t.rows)}),b=e=>{c(e.message),i.refetch()},S=async t=>{await v.patch(`/api/studio/tables/${e}`,t),await i.refetch(),await g()},C=z({mutationFn:({row:t,column:n,value:r})=>v.patch(`/api/studio/tables/${e}/rows/${t}`,{cells:{[n]:r}}),onSuccess:(e,{row:t,column:n})=>{c(null),d(e=>e===`${t}:${n}`?null:e),_(t=>t.map(t=>t.id===e.id?{...t,cells:e.cells}:t))},onError:(e,{row:t,column:n})=>{if(e instanceof l&&e.body?.column===n){let e=i.data?.columns.find(e=>e.id===n)?.name??n;d(`${t}:${n}`),c(O(`data.badCell`,{column:e}));return}b(e)}}),T=z({mutationFn:()=>v.post(`/api/studio/tables/${e}/rows`,{}),onSuccess:async e=>{_(t=>[...t,{...e,updatedAt:new Date().toISOString()}]),await g()},onError:b}),E=z({mutationFn:t=>v.post(`/api/studio/tables/${e}/rows/delete`,{ids:[t]}),onSuccess:async(e,t)=>{_(e=>e.filter(e=>e.id!==t)),await g()},onError:b}),k=z({mutationFn:()=>v.del(`/api/studio/tables/${e}`),onSuccess:async()=>{await g(),t()}});if(!i.data)return i.isError?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:i.error.message}):null;let{columns:A,rows:j,readOnly:M}=i.data,N=!!i.data.list;return(0,W.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,W.jsx)(`input`,{value:f,disabled:M,maxLength:120,onChange:e=>m(e.target.value),onBlur:()=>f.trim()&&f!==i.data?.title&&void S({title:f}).catch(b),onKeyDown:e=>e.key===`Enter`&&e.target.blur(),"aria-label":O(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),M?null:(0,W.jsx)(D,{label:O(`data.deleteTable`),onClick:()=>confirm(O(`data.confirmDelete`,{title:i.data.title}))&&k.mutate(),className:`hover:text-rose`,children:(0,W.jsx)(w,{className:`size-4`})})]}),N?(0,W.jsx)(`p`,{className:`-mt-1.5 px-1 text-[0.8125rem] text-ink-3`,children:O(`data.fromList`)}):null,i.data.knowledge?(0,W.jsx)(Y,{projectId:i.data.projectId,itemKey:`t:${i.data.id}`,has:i.data.knowledge.categories,originLabel:i.data.knowledge.originLabel,kept:i.data.knowledge.kept,review:i.data.knowledge.review,file:i.data.knowledge.file,readOnly:M,onReviewed:()=>void v.patch(`/api/studio/tables/${e}`,{review:null}).then(()=>i.refetch()).catch(b)}):null,(0,W.jsxs)(y,{className:`overflow-hidden`,children:[(0,W.jsx)(`div`,{className:`overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full border-collapse text-left`,children:[(0,W.jsx)(`thead`,{children:(0,W.jsxs)(`tr`,{className:`border-border-soft border-b`,children:[A.map(e=>(0,W.jsx)(`th`,{className:`min-w-36 border-border-soft border-l p-1 font-medium first:border-l-0`,children:(0,W.jsxs)(`button`,{type:`button`,disabled:M||N,onClick:()=>o(e),className:`flex w-full items-center gap-1 rounded-md px-2 py-1.5 text-left text-[0.8125rem] text-ink-2 transition hover:bg-accent hover:text-ink disabled:hover:bg-transparent`,children:[(0,W.jsx)(`span`,{className:`truncate`,children:e.name}),e.required?(0,W.jsx)(`span`,{className:`text-ember`,children:`*`}):null,Ze(e)?(0,W.jsx)(`span`,{className:`font-normal text-ink-4`,children:Ze(e)}):null]})},e.id)),(0,W.jsx)(`th`,{className:`w-10 p-1`,children:M||N?null:(0,W.jsx)(D,{label:O(`data.newColumn`),onClick:()=>o(`new`),className:`size-8`,children:(0,W.jsx)(p,{className:`size-4`})})})]})}),(0,W.jsx)(`tbody`,{children:j.map(e=>(0,W.jsxs)(`tr`,{className:`group border-border-soft border-b last:border-b-0`,children:[A.map(t=>(0,W.jsx)(`td`,{className:`border-border-soft border-l p-1 align-top first:border-l-0`,children:(0,W.jsx)(Xe,{column:t,value:e.cells[t.id],readOnly:M,invalid:u===`${e.id}:${t.id}`,onSave:n=>C.mutate({row:e.id,column:t.id,value:n})})},t.id)),(0,W.jsx)(`td`,{className:`w-10 p-1 align-top`,children:M?null:(0,W.jsx)(D,{label:O(`data.deleteRow`),onClick:()=>E.mutate(e.id),className:`size-8 opacity-0 hover:text-rose focus:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:(0,W.jsx)(w,{className:`size-3.5`})})})]},e.id))})]})}),j.length?null:(0,W.jsx)(`p`,{className:`px-4 py-6 text-center text-[0.875rem] text-ink-3`,children:O(`data.noRows`)}),M?null:(0,W.jsx)(`div`,{className:`border-border-soft border-t p-1.5`,children:(0,W.jsxs)(x,{variant:`ghost`,size:`sm`,busy:T.isPending,onClick:()=>T.mutate(),children:[(0,W.jsx)(p,{className:`size-4`}),` `,O(`data.addRow`)]})})]}),s?(0,W.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:s}):null,(0,W.jsx)(et,{open:a!==null,column:a===`new`?null:a,columns:A,onClose:()=>o(null),onSave:e=>S({columns:e})})]})}var nt=`wizards.runDrawer.width`,rt=`wizards.runDrawer.wide`,it=`wizards.runDrawer.look`,at=680,Z=400,ot=()=>Math.max(Z,window.innerWidth-120);function Q(e){try{return localStorage.getItem(e)}catch{return null}}function $(e,t){try{localStorage.setItem(e,t)}catch{}}function st(){let[e,t]=(0,U.useState)(()=>{let e=Number(Q(nt));return e?Math.min(Math.max(e,Z),ot()):at}),[n,r]=(0,U.useState)(()=>Q(rt)===`1`),i=(0,U.useCallback)(e=>{let n=Math.round(Math.min(Math.max(e,Z),ot()));t(n),$(nt,String(n))},[]);return{width:e,wide:n,toggleWide:()=>{r(!n),$(rt,n?`0`:`1`)},onPointerDown:t=>{t.preventDefault();let n=t.clientX,r=e,a=e=>i(r+n-e.clientX),o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`)};document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o)},onKeyDown:t=>{let n=t.shiftKey?64:16;t.key===`ArrowLeft`?(t.preventDefault(),i(e+n)):t.key===`ArrowRight`&&(t.preventDefault(),i(e-n))},reset:()=>i(at)}}function ct(){let[e,t]=(0,U.useState)(()=>Q(it)===`chat`?`chat`:`steps`);return[e,e=>{t(e),$(it,e)}]}function lt({look:e,onChange:t}){let n=[{id:`steps`,label:O(`chat.steps`),Icon:fe},{id:`chat`,label:O(`chat.chat`),Icon:V}];return(0,W.jsx)(`fieldset`,{"aria-label":O(`chat.view`),className:`m-0 flex min-w-0 rounded-full border-0 bg-paper-2 p-0.5`,children:n.map(({id:n,label:r,Icon:i})=>(0,W.jsxs)(`button`,{type:`button`,"aria-pressed":e===n,title:r,onClick:()=>t(n),className:E(`inline-flex h-7 items-center gap-1.5 rounded-full px-2.5 font-medium text-[0.75rem] transition coarse:h-9`,e===n?`bg-card text-ink shadow-soft`:`text-ink-3 hover:text-ink`),children:[(0,W.jsx)(i,{className:`size-3.5`}),(0,W.jsx)(`span`,{className:`max-sm:hidden`,children:r})]},n))})}function ut({header:e,actions:t,onClose:n,children:r}){let i=st();return(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 flex justify-end bg-[oklch(20%_0.01_60/0.22)] backdrop-blur-[1px]`,onClick:n,children:(0,W.jsxs)(`div`,{className:E(`relative flex h-full w-full animate-rise flex-col bg-background shadow-overlay`,!i.wide&&`sm:w-[var(--drawer)]`),style:{"--drawer":`${i.width}px`},onClick:e=>e.stopPropagation(),children:[i.wide?null:(0,W.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":O(`editor.resize`),"aria-valuenow":i.width,tabIndex:0,title:O(`editor.resize`),onPointerDown:i.onPointerDown,onKeyDown:i.onKeyDown,onDoubleClick:i.reset,className:`group -left-2.5 absolute inset-y-0 z-10 hidden w-5 cursor-col-resize outline-none sm:block`,children:(0,W.jsx)(`span`,{className:`-translate-y-1/2 absolute top-1/2 left-[7px] h-12 w-1.5 rounded-full bg-ink-4/40 transition group-hover:bg-ember/70 group-focus-visible:bg-ember group-active:h-16 group-active:bg-ember`})}),(0,W.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4`,children:[(0,W.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:e}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t,(0,W.jsx)(D,{label:O(i.wide?`runDrawer.shrink`:`runDrawer.expand`),onClick:i.toggleWide,className:`max-sm:hidden`,children:i.wide?(0,W.jsx)(me,{className:`size-4`}):(0,W.jsx)(c,{className:`size-4`})}),(0,W.jsx)(D,{label:O(`editor.close`),onClick:n,children:(0,W.jsx)(L,{className:`size-5`})})]})]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:r})]})})}export{De as _,He as a,ue as b,Be as c,J as d,Y as f,Te as g,G as h,tt as i,ze as l,Oe as m,ut as n,We as o,Le as p,ct as r,Ve as s,lt as t,je as u,Ee as v,oe as x,H as y};
|
|
@@ -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{$ as r,Ht as i,W as a,et as o}from"./ui-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$ as r,Ht as i,W as a,et as o}from"./ui-C5_NcAmG.js";import{i as s,r as c}from"./index-D_0jeO3M.js";var l=e(t(),1),u=e(n(),1),d=[`classifier`,`standard`],f=12e3;function p(e){s(`think`)&&a.post(`/api/runs/${e}/device`,{think:{classes:d,maxChars:f}}).catch(()=>void 0)}async function m(e,t){if(t.kind!==`think`)return;let n;try{let e=await c(`think`,{system:t.system,prompt:t.prompt,schema:t.schema});n={text:String(e?.text??``)}}catch(e){n={error:e.message.slice(0,500)}}await a.post(`/api/runs/${e}/device/${t.id}`,n).catch(()=>void 0)}var h=45e3;function g(e){let[t,n]=(0,l.useState)(null),[o,s]=(0,l.useState)(null),[c,u]=(0,l.useState)(!1),[d,f]=(0,l.useState)(!1),[g,_]=(0,l.useState)({});(0,l.useEffect)(()=>{if(n(null),u(!1),!e)return;let t=!1,o=0,s,c=null,l=Date.now(),d=()=>{t=!0,c?.close(),u(!0)},f=async()=>{try{let r=await a.get(`/api/runs/${e}`);t||n(r)}catch(e){e instanceof i&&e.status===404&&d()}},g=()=>{if(clearTimeout(s),c?.close(),t)return;let i=new EventSource(r(`/api/runs/${e}/stream`),{withCredentials:!0});c=i,l=Date.now(),p(e),i.addEventListener(`device`,t=>{l=Date.now(),m(e,JSON.parse(t.data))}),i.addEventListener(`view`,e=>{o=0,l=Date.now(),n(JSON.parse(e.data))}),i.addEventListener(`ping`,()=>{l=Date.now()}),i.onerror=()=>{i.close(),!(t||c!==i)&&(c=null,f(),o=Math.min(o+1,6),s=setTimeout(g,500*2**o))}},_=()=>{t||document.visibilityState!==`visible`||(!c||c.readyState===EventSource.CLOSED||Date.now()-l>h?(o=0,g()):f())},v=setInterval(()=>{!t&&c&&Date.now()-l>h&&(o=0,g())},15e3);return g(),document.addEventListener(`visibilitychange`,_),window.addEventListener(`pageshow`,_),window.addEventListener(`online`,_),()=>{t=!0,clearTimeout(s),clearInterval(v),document.removeEventListener(`visibilitychange`,_),window.removeEventListener(`pageshow`,_),window.removeEventListener(`online`,_),c?.close()}},[e]);let v=(0,l.useCallback)(async(t,n)=>{if(!e)return!1;f(!0),s(null),_({});try{return await a.post(`/api/runs/${e}/${t}`,n),!0}catch(e){return e instanceof i&&e.status===422&&Array.isArray(e.body?.fields)&&_(Object.fromEntries(e.body.fields.map(e=>[e.field,e.message]))),s(e.message),!1}finally{f(!1)}},[e]);return{view:t,notFound:c,error:o,busy:d,fieldErrors:g,submitPage:(e,t)=>v(`pages/${e}`,{values:t}),accept:(e,t)=>v(`reviews/${e}`,{type:`accept`,edits:t}),regenerate:(e,t,n,r)=>v(`reviews/${e}`,{type:`regenerate`,target:t,note:n,items:r?.length?r:void 0}),back:()=>v(`back`),retry:()=>v(`retry`)}}function _({runId:e,...t}){let n=g(e);return(0,u.jsx)(o,{run:n,...t})}export{g as n,_ as t};
|