@wudao-org/web 0.5.0 → 0.5.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.
@@ -1,3 +0,0 @@
1
- import{j as n,H as F,R as me,g as Ee,p as ge,r,b as ie,c as le,J as we,K as Te,L as Se,M as je,f as Z,t as W,N as Ne,u as _e,i as re,q as Pe,w as Ae,O as De,Q as Ce,h as M,S as Re,T as Le,U as Oe,V as Ie,C as ae,G as Me,X as Fe,z as Ke,Y as qe,y as Ue,W as Ve,A as He,x as We,Z as Be,n as Xe,_ as Ye,F as $e}from"./tokens-Cd73jvpR.js";const Qe=1500;function ze(){return{display:"idle",busy:!1,doneAt:null}}function Ge(e){return e.pendingPermission!=null?"waiting-user":e.live.busyTools.length>0?"working":e.live.reasoning!==""?"thinking":e.live.answer!==""?"answering":"idle"}function Je(e,t,i){const s=Ge(t);let l,a=e.doneAt;return t.busy||s==="waiting-user"?l=s:e.busy&&!t.busy?(l="done",a=i):e.display==="done"&&e.doneAt!==null&&i-e.doneAt<Qe?l="done":l=s,l!=="done"&&(a=null),{display:l,busy:t.busy,doneAt:a}}function K(e){return function(i){return n.jsx("div",{className:"pet-figure",children:n.jsx("div",{className:"pet-sprite-img",style:{backgroundImage:`url(${e})`}})})}}const Ze=K("/pet/skin-default.png");function et({display:e,skinId:t="default",figure:i=Ze,paused:s=!1,pokeEpoch:l,poked:a,onPointerDown:o}){return n.jsx("div",{className:"pet-root","data-pet-root":"","data-skin":t,"data-pet-state":e,"data-paused":s?"":void 0,title:"wudao pet",onPointerDown:o,children:n.jsx("div",{className:"pet-poke-layer","data-poked":a?"":void 0,children:n.jsx(i,{display:e})},l??0)})}const V=["idle","thinking","working","answering","waiting-user","done","drag"],tt=K(F.sakura),nt=K(F.lake),st=K(F.honey),it=K(F.power),lt={default:{component:K(F.default),states:V},sakura:{component:tt,states:V},lake:{component:nt,states:V},honey:{component:st,states:V},power:{component:it,states:V}},rt={turns:[]};function G(e){const t=Array.from(e);return t.length<=24?e:`${t.slice(0,24).join("")}…`}function at(e,t){return{turns:[...e.turns.map(s=>s.live?{...s,live:!1}:s),{q:t,a:"",live:!0}]}}function ut(e,t){const i=e.turns.length>0?e.turns[e.turns.length-1]:void 0;if(i===void 0)return t.answerTail===""?e:{turns:[{q:"",a:t.answerTail,live:!0}]};if(i.live){if(t.answerTail!==""){if(i.a===t.answerTail)return e;const s=e.turns.slice();return s[s.length-1]={...i,a:t.answerTail},{turns:s}}if(!t.busy){const s=e.turns.slice();return s[s.length-1]={...i,live:!1},{turns:s}}return e}return t.answerTail!==""?{turns:[...e.turns,{q:"",a:t.answerTail,live:!0}]}:e}function ot(e,t){const i=e.map(o=>({q:o.q,a:o.a,live:!1})),s=[];let l=t.turns.length-1,a=i.length-1;for(;l>=0||a>=0;){const o=l>=0?t.turns[l]:void 0,d=a>=0?i[a]:void 0;o!==void 0&&d!==void 0&&o.q!==""&&o.q===G(d.q)?(s.push({q:d.q,a:d.a,live:o.live}),l-=1,a-=1):o!==void 0?(s.push(o),l-=1):(s.push(d),a-=1)}return{turns:s.reverse()}}function H({s:e}){return n.jsx(n.Fragment,{children:ge(e).map((t,i)=>t.code?n.jsx("code",{className:"pet-md-code",children:t.text},i):t.bold?n.jsx("span",{className:"pet-md-bold",children:t.text},i):n.jsx("span",{children:t.text},i))})}function ct(e){return e.map((t,i)=>t.kind==="code"?n.jsx("div",{className:"pet-md-pre",children:n.jsx("code",{children:t.lines.join(`
2
- `)})},i):t.kind==="heading"?n.jsx("div",{className:"pet-md-heading","data-level":t.level,children:n.jsx(H,{s:t.text})},i):t.kind==="list"?n.jsx("div",{className:"pet-md-list",children:t.items.map((s,l)=>n.jsxs("div",{children:["• ",n.jsx(H,{s})]},l))},i):t.kind==="quote"?n.jsx("div",{className:"pet-md-quote",children:t.lines.map((s,l)=>n.jsx("div",{children:`| ${s}`},l))},i):t.kind==="table"?n.jsxs("table",{className:"pet-md-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:t.header.map((s,l)=>n.jsx("th",{children:n.jsx(H,{s})},l))})}),n.jsx("tbody",{children:t.rows.map((s,l)=>n.jsx("tr",{children:s.map((a,o)=>n.jsx("td",{children:n.jsx(H,{s:a})},o))},l))})]},i):n.jsx("div",{className:"pet-md-para",children:t.lines.map((s,l)=>n.jsxs(me.Fragment,{children:[l>0?`
3
- `:null,n.jsx(H,{s})]},l))},i))}const be=me.memo(function({source:t}){return n.jsx("div",{className:"pet-md",children:ct(Ee(t))})}),ue=2500,dt=250,ft=3e4,mt=600,oe=100;function bt(e,t){const i=e.ask??null;if(i!==null)return{kind:"ask",ask:i};const s=e.selection??null;if(s!==null)return{kind:"selection",selection:s};if(e.inputOpen)return{kind:"input"};if(e.waitingUser)return{kind:"hint"};const l=e.busyNarration??null;return l!==null&&l!==""?{kind:"narration",text:l}:e.livePending?{kind:"thinking"}:e.answerTail!==""&&e.answerTail!==t?{kind:"stream",text:e.answerTail}:e.delivery!==null?{kind:"delivery",delivery:e.delivery}:null}function vt(e,t){return e!==null&&e.kind==="stream"&&e.text===t}function ht(e,t,i,s){const l=o=>o!==null&&!vt(o,s)?o:null,a=l(t)??l(i);return a===null?"compact":a.kind==="stream"||a.kind==="thinking"||a.kind==="input"||e==="answer"?"answer":"bubble"}function yt(e){const[t,i]=r.useState(!0),[s,l]=r.useState(!0),a=e.turn.q.length>oe,o=!e.turn.live&&e.turn.a.length>oe;return n.jsxs("div",{className:"pet-turn",children:[e.turn.q!==""&&n.jsx("div",{className:"pet-msg pet-msg-user",children:n.jsxs("div",{className:"pet-bubble-q","data-folded":a&&t?"":void 0,children:[n.jsx("div",{className:"pet-bubble-body",children:e.turn.q}),a&&n.jsx("button",{type:"button",className:"pet-bubble-fold","data-bubble-fold":"",onClick:()=>i(d=>!d),children:t?"查看全文":"收起"})]})}),(e.thinking||e.turn.a!=="")&&n.jsxs("div",{className:"pet-row pet-row-pet","data-pet-msg":"",children:[n.jsx("div",{className:"pet-avatar","data-pet-avatar":"",style:{backgroundImage:`url(${e.avatarSheet})`}}),e.thinking&&n.jsx("div",{className:"pet-bubble-thinking",children:"思考中…"}),!e.thinking&&e.turn.a!==""&&n.jsxs("div",{className:"pet-bubble-a","data-folded":o&&s?"":void 0,children:[n.jsx("div",{className:"pet-bubble-body",children:n.jsx(be,{source:e.turn.a})}),o&&n.jsx("button",{type:"button",className:"pet-bubble-fold","data-bubble-fold":"",onClick:()=>l(d=>!d),children:s?"查看全文":"收起"})]})]})]})}function kt(e){const{inputOpen:t,answerTail:i,waitingUser:s,onInputClose:l,delivery:a}=e,[o,d]=r.useState(""),[S,j]=r.useState(""),[C,D]=r.useState(!1),b=bt(e,S);r.useEffect(()=>{i===""&&(j(""),D(!1))},[i]);const y=r.useRef(null);b===null||(b.kind==="input"||b.kind==="delivery"||b.kind==="ask"||b.kind==="selection"?y.current=null:y.current=b);const[N,x]=r.useState(b!==null),[E,k]=r.useState(!1),g=b!==null;r.useEffect(()=>{if(g){x(!0),k(!1);return}if(!N)return;const u=y.current?.kind;if(u===void 0||u==="stream")return;const T=setTimeout(()=>k(!0),ue),se=setTimeout(()=>x(!1),ue+dt);return()=>{clearTimeout(T),clearTimeout(se)}},[g,N]);const _=r.useRef("compact"),q=r.useRef(e.onLayoutMode);q.current=e.onLayoutMode;const h=r.useRef(e.onDeliveryClose);h.current=e.onDeliveryClose,r.useEffect(()=>{if(a===null)return;const u=setTimeout(()=>h.current(),ft);return()=>clearTimeout(u)},[a]),r.useEffect(()=>{if(a===null||t||(e.ask??null)!==null||(e.selection??null)!==null)return;const u=T=>{T.key==="Escape"&&(T.preventDefault(),h.current())};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[a,t,e.ask,e.selection]);const f=r.useRef(e.onSelectionClose);f.current=e.onSelectionClose,r.useEffect(()=>{if((e.selection??null)===null||(e.ask??null)!==null)return;const u=T=>{T.key==="Escape"&&(T.preventDefault(),f.current())};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[e.selection,e.ask]);const[v,A]=r.useState(!1),w=e.ask??null,U=w===null?"":`${w.toolName} ${w.summary} ${String(w.canAlways)}`;r.useEffect(()=>{A(!1)},[U]);const R=(u,T)=>{A(!0),W(_e,T===void 0?{allow:u}:{allow:u,scope:T})},P=e.selection??null,B=P===null?"":`${P.granted}|${P.truncated}|${P.text}`,[L,O]=r.useState(!1),[I,X]=r.useState(""),m=r.useRef({composing:!1,endedAt:0}),p=r.useRef({composing:!1,endedAt:0});r.useEffect(()=>{O(!1),X("")},[B]);const Y=u=>{L||(O(!0),W(Ae,{text:u}),e.onPetTurn(G(u)),f.current())},ee=()=>{if(P===null)return;const u=I.trim();Y(u===""?De(P.text):Ce(P.text,u))},ve=u=>{re(u.nativeEvent,p.current,Date.now())||u.key==="Enter"&&(u.preventDefault(),ee())},te=()=>{const u=o.trim();u!==""&&(d(""),e.onPetTurn(G(u)),W(Pe,{text:u}))},he=u=>{if(!re(u.nativeEvent,m.current,Date.now())){if(u.key==="Escape"){u.preventDefault(),l();return}u.key==="Enter"&&(u.preventDefault(),te())}},c=b??y.current,ye=()=>{c===null||c.kind!=="stream"||(j(c.text),y.current=null)},$=ht(_.current,b,N?c:null,S);r.useEffect(()=>{$!==_.current&&(_.current=$,q.current?.($))},[$]);const ne=r.useRef(null);r.useEffect(()=>{const u=ne.current;u!==null&&(u.scrollTop=u.scrollHeight)},[e.transcript,e.answerTail,e.livePending]);const ke=F[e.skinId??"default"];if(!N||c===null)return null;const xe=()=>{h.current(),W(Ne,null)};return n.jsxs("div",{className:"pet-bubble","data-bubble":"","data-bubble-state":c.kind,"data-bubble-fading":E&&b===null?"":void 0,"data-bubble-held":b===null&&c.kind==="stream"?"":void 0,onClick:c.kind==="delivery"?xe:void 0,style:c.kind==="delivery"?{cursor:"pointer"}:void 0,children:[c.kind==="ask"&&n.jsxs("div",{className:"pet-bubble-ask","data-ask-card":"",children:[n.jsx("div",{className:"pet-bubble-ask-tool","data-ask-tool":"",children:c.ask.toolName}),n.jsx("div",{className:"pet-bubble-ask-summary","data-ask-summary":"",children:c.ask.summary}),n.jsxs("div",{className:"pet-bubble-ask-actions","data-ask-actions":"",children:[n.jsx("button",{type:"button","data-ask-allow":"",disabled:v,onClick:()=>R(!0),children:"允许"}),c.ask.canAlways&&n.jsx("button",{type:"button","data-ask-always":"",disabled:v,onClick:()=>R(!0,"always"),children:"总是允许"}),n.jsx("button",{type:"button","data-ask-deny":"",disabled:v,onClick:()=>R(!1),children:"拒绝"})]})]}),c.kind==="input"&&n.jsxs("div",{className:"pet-bubble-chat",children:[n.jsx("div",{className:"pet-bubble-transcript","data-bubble-transcript":"",ref:ne,children:e.transcript.map((u,T)=>{const pe=T===e.transcript.length-1&&u.live&&u.a==="";return n.jsx(yt,{turn:u,thinking:pe,avatarSheet:ke},T)})}),n.jsxs("div",{className:"pet-bubble-input",children:[n.jsx("textarea",{"data-bubble-input":"",placeholder:"问点什么…",rows:1,autoFocus:!0,value:o,onChange:u=>d(u.target.value),onCompositionStart:()=>{m.current=le(m.current)},onCompositionEnd:()=>{m.current=ie(m.current,Date.now())},onKeyDown:he}),n.jsxs("div",{className:"pet-bubble-input-row","data-bubble-actions":"",children:[n.jsx("button",{type:"button","data-bubble-cancel":"",className:"pet-bubble-cancel",onClick:l,children:"取消"}),n.jsx("button",{type:"button","data-bubble-send":"",className:"pet-bubble-send",onClick:te,children:"发送"})]})]})]}),c.kind==="selection"&&c.selection.granted&&c.selection.text!==""&&n.jsxs("div",{className:"pet-bubble-selection","data-selection-card":"",children:[n.jsx("div",{className:"pet-bubble-selection-text","data-selection-text":"",children:c.selection.text}),n.jsxs("div",{className:"pet-bubble-selection-actions","data-selection-actions":"",children:[n.jsx("button",{type:"button","data-selection-translate":"",disabled:L,onClick:()=>Y(we(c.selection.text)),children:"翻译"}),n.jsx("button",{type:"button","data-selection-explain":"",disabled:L,onClick:()=>Y(Te(c.selection.text)),children:"解释"}),Se(c.selection.text)&&n.jsx("button",{type:"button","data-selection-url":"",disabled:L,onClick:()=>Y(je(c.selection.text)),children:"读这个网页"})]}),n.jsxs("div",{className:"pet-bubble-selection-row","data-selection-row":"",children:[n.jsx("input",{"data-selection-question":"",placeholder:"想问它什么?",value:I,onChange:u=>X(u.target.value),onCompositionStart:()=>{p.current=le(p.current)},onCompositionEnd:()=>{p.current=ie(p.current,Date.now())},onKeyDown:ve}),n.jsx("button",{type:"button","data-selection-send":"",disabled:L,onClick:ee,children:"发送"}),n.jsx("button",{type:"button","data-selection-cancel":"",onClick:()=>f.current(),children:"取消"})]})]}),c.kind==="selection"&&c.selection.granted&&c.selection.text===""&&n.jsxs("div",{className:"pet-bubble-selection","data-selection-empty":"",children:[n.jsx("div",{className:"pet-bubble-selection-text",children:"没划到文字"}),n.jsx("div",{className:"pet-bubble-selection-actions",children:n.jsx("button",{type:"button","data-selection-cancel":"",onClick:()=>f.current(),children:"取消"})})]}),c.kind==="selection"&&!c.selection.granted&&n.jsxs("div",{className:"pet-bubble-selection","data-selection-guide":"",children:[n.jsx("div",{className:"pet-bubble-selection-text",children:"需要辅助功能权限"}),n.jsxs("div",{className:"pet-bubble-selection-actions",children:[n.jsx("button",{type:"button","data-selection-open-settings":"",onClick:()=>void Z("open_accessibility_settings",{}),children:"去系统设置打开"}),n.jsx("button",{type:"button","data-selection-cancel":"",onClick:()=>f.current(),children:"取消"})]})]}),c.kind==="hint"&&n.jsx("div",{className:"pet-bubble-hint",children:"在等你确认操作"}),c.kind==="narration"&&n.jsx("div",{className:"pet-bubble-hint","data-bubble-narration":"","data-work-kind":e.workKind??void 0,children:c.text}),c.kind==="thinking"&&n.jsx("div",{className:"pet-bubble-hint","data-bubble-thinking":"",children:"思考中…"}),c.kind==="stream"&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"pet-bubble-close","data-bubble-close":"","aria-label":"关闭回答",onClick:ye,children:"✕"}),n.jsx("div",{className:"pet-bubble-stream","data-stream-expanded":C?"":void 0,children:n.jsx(be,{source:c.text})}),c.text.length>mt&&n.jsx("button",{type:"button",className:"pet-bubble-fold","data-stream-toggle":"",onClick:()=>D(u=>!u),children:C?"收起":"展开全文"})]}),c.kind==="delivery"&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"pet-bubble-hint",children:"定时任务送达"}),n.jsx("div",{className:"pet-bubble-stream","data-delivery-prompt":"",children:c.delivery.promptDigest}),c.delivery.answerDigest!==""&&n.jsx("div",{className:"pet-bubble-stream","data-delivery-answer":"",children:c.delivery.answerDigest})]})]})}const xt=4e3,J=Symbol("bad-ask");function pt(e){if(e==null)return null;if(typeof e!="object")return J;const t=e;return typeof t.toolName!="string"||typeof t.summary!="string"||typeof t.canAlways!="boolean"?J:{toolName:t.toolName,summary:t.summary,canAlways:t.canAlways}}function Et(e){if(typeof e!="object"||e===null)return null;const t=e;if(typeof t.busy!="boolean"||typeof t.pendingPermission!="boolean"||typeof t.reasoningActive!="boolean"||typeof t.answerTail!="string"||typeof t.busyToolCount!="number"||t.busyNarration!==void 0&&t.busyNarration!==null&&typeof t.busyNarration!="string"||t.workKind!==void 0&&t.workKind!==null&&typeof t.workKind!="string")return null;const i=pt(t.ask);return i===J?null:{busy:t.busy,pendingPermission:t.pendingPermission,reasoningActive:t.reasoningActive,answerTail:t.answerTail,busyToolCount:t.busyToolCount,busyNarration:typeof t.busyNarration=="string"?t.busyNarration:null,workKind:typeof t.workKind=="string"?t.workKind:null,ask:i}}function gt(e,t){r.useEffect(()=>{Z("set_pet_layout",{mode:e})},[e,t])}function wt(){const[e,t]=r.useState(null);return r.useEffect(()=>{let i=null,s=!1;return M(Le,l=>{const a=Re(l);a!==null&&t(a)}).then(l=>{s?l?.():i=l}),()=>{s=!0,i?.()}},[]),{delivery:e,clearDelivery:()=>t(null)}}function Tt(){const[e,t]=r.useState(null);return r.useEffect(()=>{let i=null,s=!1;return M(Ie,l=>{const a=Oe(l);a!==null&&t(a)}).then(l=>{s?l?.():i=l}),()=>{s=!0,i?.()}},[]),{selection:e,clearSelection:()=>t(null)}}function St(){const[e,t]=r.useState("default");return r.useEffect(()=>{let i=!1;return Z("get_pet_skin",{}).then(s=>{i||t(ae(s))}),()=>{i=!0}},[]),r.useEffect(()=>{let i=null,s=!1;return M(Me,l=>{if(typeof l!="object"||l===null)return;const a=l.skin;if(typeof a!="string")return;const o=ae(a);o===a&&t(o)}).then(l=>{s?l?.():i=l}),()=>{s=!0,i?.()}},[]),e}function jt(e){const[t,i]=r.useState(null);return r.useEffect(()=>{let s=null,l=!1,a=null;return M(Ke,o=>{const d=Fe(o);d!==null&&(i(d.text),e(d.text),a!==null&&clearTimeout(a),a=setTimeout(()=>i(null),xt))}).then(o=>{l?o?.():s=o}),()=>{l=!0,s?.(),a!==null&&clearTimeout(a)}},[]),t}function Nt(){const[e,t]=r.useState(null);r.useEffect(()=>{let s=null,l=!1;return M(Ue,a=>{const o=qe(a);o!==null&&t(o.turns)}).then(a=>{l?a?.():s=a}),()=>{l=!0,s?.()}},[]);const i=()=>{W(We,{}).catch(()=>{})};return r.useEffect(()=>{i()},[]),{history:e,requestHistory:i}}function _t(){r.useEffect(()=>{let e=null,t=!1;return M(Ve,i=>{if(typeof i!="object"||i===null)return;const s=i.theme;s!=="light"&&s!=="dark"||(document.documentElement.dataset.theme=s)}).then(i=>{t?i?.():e=i}),()=>{t=!0,e?.()}},[])}function Pt(e){r.useEffect(()=>{let t=null,i=!1;return M(He,s=>{const l=Et(s);l!==null&&e(l)}).then(s=>{i?s?.():t=s}),()=>{i=!0,t?.()}},[])}const At=650,Dt=2200,Ct=600,Q=["呀!","在呢在呢~","嘿嘿,别捏啦","痒痒的!","元气满满!","有什么吩咐?"];function Rt(e,t){const i=Q.length,s=e===null?-1:Q.indexOf(e),l=s>=0?i-1:i,a=t(),o=a>=0&&a<1?a:0,d=Math.min(Math.floor(o*l),l-1),S=s>=0&&d>=s?d+1:d,j=Q[S];return j!==void 0?j:Q[0]}const z=5;function Lt(e,t){if(e===null||t.type==="pointercancel"||e.x===void 0||e.y===void 0||t.clientX===void 0||t.clientY===void 0)return!1;const i=t.clientX-e.x,s=t.clientY-e.y;return i*i+s*s>=z*z}function Ot(e,t){if(e===null||!Number.isFinite(e.x)||!Number.isFinite(e.y)||!Number.isFinite(t.x)||!Number.isFinite(t.y))return!1;const i=t.x-e.x,s=t.y-e.y;return i*i+s*s>=z*z}const ce=5,It=600,de=4;function Mt(e){const[t,i]=r.useState(0),s=r.useRef(document.hidden);return r.useEffect(()=>{const l=()=>{s.current&&!document.hidden&&(i(a=>a+1),e()),s.current=document.hidden};return document.addEventListener("visibilitychange",l),()=>document.removeEventListener("visibilitychange",l)},[]),t}function Ft(e){const{inputOpen:t,setInputOpen:i}=e,[s,l]=r.useState(!1),[a,o]=r.useState(0),[d,S]=r.useState(!1),[j,C]=r.useState(null),[D,b]=r.useState(!1),y=r.useRef(null),N=r.useRef(!1),x=r.useRef(null),E=r.useRef(null),k=r.useRef(null),g=r.useRef(null),_=r.useRef(null);return r.useEffect(()=>{if(!s)return;const h=f=>{x.current!==null&&(clearTimeout(x.current),x.current=null),l(!1);const v=y.current;if(y.current=null,Lt(v,f)&&(b(!0),k.current!==null&&clearTimeout(k.current),k.current=setTimeout(()=>{k.current=null,b(!1)},450)),v===null||f.type==="pointercancel"||v.x===void 0||v.y===void 0||f.clientX===void 0||f.clientY===void 0)return;const A=f.clientX-v.x,w=f.clientY-v.y,U=Date.now()-v.t;A*A+w*w<ce*ce&&U<It&&(i(R=>!R),t||Be())};return window.addEventListener("pointerup",h),window.addEventListener("pointercancel",h),()=>{window.removeEventListener("pointerup",h),window.removeEventListener("pointercancel",h)}},[s,t]),r.useEffect(()=>{if(!s){N.current=!1;return}const h=f=>{const v=y.current;if(N.current){f.buttons===0&&(N.current=!1,y.current=null,l(!1),b(!0),k.current!==null&&clearTimeout(k.current),k.current=setTimeout(()=>{k.current=null,b(!1)},450));return}if(v===null||v.x===void 0||v.y===void 0)return;const A=f.clientX-v.x,w=f.clientY-v.y;A*A+w*w>=de*de&&(N.current=!0,Xe())};return window.addEventListener("pointermove",h),()=>{window.removeEventListener("pointermove",h)}},[s]),r.useEffect(()=>()=>{x.current!==null&&clearTimeout(x.current),E.current!==null&&clearTimeout(E.current),k.current!==null&&clearTimeout(k.current),g.current!==null&&clearTimeout(g.current)},[]),{dragging:s,releaseFlash:D,pokeEpoch:a,pokeFlash:d,pokeExpr:j,onPointerDown:h=>{y.current={x:h.clientX,y:h.clientY,sx:window.screenX,sy:window.screenY,t:Date.now()},l(!0),x.current!==null&&clearTimeout(x.current),x.current=setTimeout(()=>{x.current=null,!Ot(y.current!==null?{x:y.current.sx,y:y.current.sy}:null,{x:window.screenX,y:window.screenY})&&(_.current=Rt(_.current,Math.random),o(f=>f+1),S(!0),g.current!==null&&clearTimeout(g.current),g.current=setTimeout(()=>{g.current=null,S(!1)},Ct),C(_.current),E.current!==null&&clearTimeout(E.current),E.current=setTimeout(()=>{E.current=null,C(null)},Dt))},At)}}}function Kt(){const[e,t]=r.useState(ze),[i,s]=r.useState(null),[l,a]=r.useState(!1),[o,d]=r.useState("compact"),[S,j]=r.useState(rt),[C,D]=r.useState(!1),{delivery:b,clearDelivery:y}=wt(),{selection:N,clearSelection:x}=Tt(),E=St();gt(o,E);const k=jt(()=>{D(!1),j(m=>{const p=m.turns.length>0?m.turns[m.turns.length-1]:void 0;return p===void 0||!p.live?m:{turns:m.turns.slice(0,-1)}})}),{history:g,requestHistory:_}=Nt();_t(),Pt(m=>{s(m),t(p=>Je(p,Ye(m),Date.now())),j(p=>ut(p,m)),D(!1)});const q=Mt(_),{dragging:h,releaseFlash:f,pokeEpoch:v,pokeFlash:A,pokeExpr:w,onPointerDown:U}=Ft({inputOpen:l,setInputOpen:a}),R=lt[E].component;r.useEffect(()=>{if(!l)return;const m=()=>a(!1);return window.addEventListener("blur",m),()=>window.removeEventListener("blur",m)},[l]),r.useEffect(()=>{l&&_()},[l]);const P=i?.busy??!1,B=r.useRef(!1);r.useEffect(()=>{B.current&&!P&&_(),B.current=P},[P]);const L=m=>{j(p=>at(p,m)),D(!0)},O=r.useMemo(()=>g===null?S.turns:ot(g,S).turns,[g,S]),I=O.length>0?O[O.length-1]:void 0,X=C||I!==void 0&&I.live&&I.q!==""&&I.a===""&&(i?.busy??!1)===!0;return n.jsxs(n.Fragment,{children:[n.jsx(kt,{inputOpen:l,answerTail:i?.answerTail??"",waitingUser:e.display==="waiting-user",busyNarration:i?.busyNarration??null,workKind:i?.workKind??null,onInputClose:()=>a(!1),delivery:b,onDeliveryClose:y,ask:i?.ask??null,selection:N,onSelectionClose:x,onLayoutMode:d,transcript:O,onPetTurn:L,livePending:X,skinId:E}),n.jsx(et,{display:h?"drag":f?"release":e.display,skinId:E,figure:R,pokeEpoch:v,poked:A,onPointerDown:U},q),k!==null&&n.jsx("div",{className:"pet-toast","data-pet-toast":"",role:"status",children:k}),w!==null&&n.jsx("div",{className:"pet-expr","data-pet-expr":"",role:"status",children:w})]})}const fe=new URLSearchParams(window.location.search).get("view");fe!==null&&(document.documentElement.dataset.view=fe);try{document.documentElement.dataset.theme=localStorage.getItem("wudao.ui.theme")==="light"?"light":"dark"}catch{document.documentElement.dataset.theme="dark"}const qt=document.getElementById("pet-root")??document.body;$e.createRoot(qt).render(n.jsx(r.StrictMode,{children:n.jsx(Kt,{})}));