@wudao-org/web 0.4.21 → 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 V,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 U,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-D-f0h-_m.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 H(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=H("/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 $=["idle","thinking","working","answering","waiting-user","done","drag"],tt=H(V.sakura),nt=H(V.lake),st=H(V.honey),it={default:{component:H(V.default),states:$},sakura:{component:tt,states:$},lake:{component:nt,states:$},honey:{component:st,states:$}},lt={turns:[]};function G(e){const t=Array.from(e);return t.length<=24?e:`${t.slice(0,24).join("")}…`}function rt(e,t){return{turns:[...e.turns.map(s=>s.live?{...s,live:!1}:s),{q:t,a:"",live:!0}]}}function at(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 ut(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 q({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 ot(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(q,{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(q,{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(q,{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(q,{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(q,{s})]},l))},i))}const be=me.memo(function({source:t}){return n.jsx("div",{className:"pet-md",children:ot(Ee(t))})}),ue=2500,ct=250,dt=3e4,ft=600,oe=100;function mt(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 bt(e,t){return e!==null&&e.kind==="stream"&&e.text===t}function vt(e,t,i,s){const l=o=>o!==null&&!bt(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 ht(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 yt(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=mt(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),[T,k]=r.useState(!1),E=b!==null;r.useEffect(()=>{if(E){x(!0),k(!1);return}if(!N)return;const u=y.current?.kind;if(u===void 0||u==="stream")return;const w=setTimeout(()=>k(!0),ue),se=setTimeout(()=>x(!1),ue+ct);return()=>{clearTimeout(w),clearTimeout(se)}},[E,N]);const _=r.useRef("compact"),F=r.useRef(e.onLayoutMode);F.current=e.onLayoutMode;const h=r.useRef(e.onDeliveryClose);h.current=e.onDeliveryClose,r.useEffect(()=>{if(a===null)return;const u=setTimeout(()=>h.current(),dt);return()=>clearTimeout(u)},[a]),r.useEffect(()=>{if(a===null||t||(e.ask??null)!==null||(e.selection??null)!==null)return;const u=w=>{w.key==="Escape"&&(w.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=w=>{w.key==="Escape"&&(w.preventDefault(),f.current())};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[e.selection,e.ask]);const[v,A]=r.useState(!1),g=e.ask??null,K=g===null?"":`${g.toolName} ${g.summary} ${String(g.canAlways)}`;r.useEffect(()=>{A(!1)},[K]);const R=(u,w)=>{A(!0),U(_e,w===void 0?{allow:u}:{allow:u,scope:w})},P=e.selection??null,W=P===null?"":`${P.granted}|${P.truncated}|${P.text}`,[L,O]=r.useState(!1),[I,B]=r.useState(""),m=r.useRef({composing:!1,endedAt:0}),p=r.useRef({composing:!1,endedAt:0});r.useEffect(()=>{O(!1),B("")},[W]);const X=u=>{L||(O(!0),U(Ae,{text:u}),e.onPetTurn(G(u)),f.current())},ee=()=>{if(P===null)return;const u=I.trim();X(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)),U(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)},Y=vt(_.current,b,N?c:null,S);r.useEffect(()=>{Y!==_.current&&(_.current=Y,F.current?.(Y))},[Y]);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=V[e.skinId??"default"];if(!N||c===null)return null;const xe=()=>{h.current(),U(Ne,null)};return n.jsxs("div",{className:"pet-bubble","data-bubble":"","data-bubble-state":c.kind,"data-bubble-fading":T&&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,w)=>{const pe=w===e.transcript.length-1&&u.live&&u.a==="";return n.jsx(ht,{turn:u,thinking:pe,avatarSheet:ke},w)})}),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:()=>X(we(c.selection.text)),children:"翻译"}),n.jsx("button",{type:"button","data-selection-explain":"",disabled:L,onClick:()=>X(Te(c.selection.text)),children:"解释"}),Se(c.selection.text)&&n.jsx("button",{type:"button","data-selection-url":"",disabled:L,onClick:()=>X(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=>B(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>ft&&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 kt=4e3,J=Symbol("bad-ask");function xt(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 pt(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=xt(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 Et(e){r.useEffect(()=>{Z("set_pet_layout",{mode:e})},[e])}function gt(){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 wt(){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 Tt(){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 St(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),kt))}).then(o=>{l?o?.():s=o}),()=>{l=!0,s?.(),a!==null&&clearTimeout(a)}},[]),t}function jt(){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=()=>{U(We,{}).catch(()=>{})};return r.useEffect(()=>{i()},[]),{history:e,requestHistory:i}}function Nt(){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 _t(e){r.useEffect(()=>{let t=null,i=!1;return M(He,s=>{const l=pt(s);l!==null&&e(l)}).then(s=>{i?s?.():t=s}),()=>{i=!0,t?.()}},[])}const Pt=650,At=2200,Dt=600,Q=["呀!","在呢在呢~","嘿嘿,别捏啦","痒痒的!","元气满满!","有什么吩咐?"];function Ct(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 Rt(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 Lt(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,Ot=600,de=4;function It(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 Mt(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),T=r.useRef(null),k=r.useRef(null),E=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,Rt(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,g=f.clientY-v.y,K=Date.now()-v.t;A*A+g*g<ce*ce&&K<Ot&&(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,g=f.clientY-v.y;A*A+g*g>=de*de&&(N.current=!0,Xe())};return window.addEventListener("pointermove",h),()=>{window.removeEventListener("pointermove",h)}},[s]),r.useEffect(()=>()=>{x.current!==null&&clearTimeout(x.current),T.current!==null&&clearTimeout(T.current),k.current!==null&&clearTimeout(k.current),E.current!==null&&clearTimeout(E.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,!Lt(y.current!==null?{x:y.current.sx,y:y.current.sy}:null,{x:window.screenX,y:window.screenY})&&(_.current=Ct(_.current,Math.random),o(f=>f+1),S(!0),E.current!==null&&clearTimeout(E.current),E.current=setTimeout(()=>{E.current=null,S(!1)},Dt),C(_.current),T.current!==null&&clearTimeout(T.current),T.current=setTimeout(()=>{T.current=null,C(null)},At))},Pt)}}}function Ft(){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(lt),[C,D]=r.useState(!1);Et(o);const{delivery:b,clearDelivery:y}=gt(),{selection:N,clearSelection:x}=wt(),T=Tt(),k=St(()=>{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:E,requestHistory:_}=jt();Nt(),_t(m=>{s(m),t(p=>Je(p,Ye(m),Date.now())),j(p=>at(p,m)),D(!1)});const F=It(_),{dragging:h,releaseFlash:f,pokeEpoch:v,pokeFlash:A,pokeExpr:g,onPointerDown:K}=Mt({inputOpen:l,setInputOpen:a}),R=it[T].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,W=r.useRef(!1);r.useEffect(()=>{W.current&&!P&&_(),W.current=P},[P]);const L=m=>{j(p=>rt(p,m)),D(!0)},O=r.useMemo(()=>E===null?S.turns:ut(E,S).turns,[E,S]),I=O.length>0?O[O.length-1]:void 0,B=C||I!==void 0&&I.live&&I.q!==""&&I.a===""&&(i?.busy??!1)===!0;return n.jsxs(n.Fragment,{children:[n.jsx(yt,{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:B,skinId:T}),n.jsx(et,{display:h?"drag":f?"release":e.display,skinId:T,figure:R,pokeEpoch:v,poked:A,onPointerDown:K},F),k!==null&&n.jsx("div",{className:"pet-toast","data-pet-toast":"",role:"status",children:k}),g!==null&&n.jsx("div",{className:"pet-expr","data-pet-expr":"",role:"status",children:g})]})}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 Kt=document.getElementById("pet-root")??document.body;$e.createRoot(Kt).render(n.jsx(r.StrictMode,{children:n.jsx(Ft,{})}));
@@ -1 +0,0 @@
1
- :root{--pet-accent: 14 159 110;--pet-accent-ink: 20 21 25}.pet-root{position:fixed;left:50%;bottom:12px;transform:translate(-50%);width:96px;height:96px;user-select:none;-webkit-user-select:none;cursor:grab;touch-action:none}.pet-root[data-pet-state=drag]{cursor:grabbing}.pet-figure{position:relative;width:100%;height:100%}.pet-sprite-img{position:absolute;bottom:0;left:0;display:block;width:96px;aspect-ratio:390 / 238;background-size:200% 100%;background-repeat:no-repeat;background-position:0 0;pointer-events:none;user-select:none;-webkit-user-select:none;will-change:transform,background-position;transform-origin:50% 100%}@keyframes pet-blink{0%,23.5%{background-position:0% 0}24%,25.6%{background-position:100% 0}26.1%,47.5%{background-position:0% 0}48%,49.6%{background-position:100% 0}50.1%,71.5%{background-position:0% 0}72%,73.6%{background-position:100% 0}74.1%,91%{background-position:0% 0}91.5%,93.1%{background-position:100% 0}93.6%,94.4%{background-position:0% 0}94.9%,96.5%{background-position:100% 0}97%,to{background-position:0% 0}}@keyframes pet-idle{0%{transform:scale(1.06,.92)}9%{transform:scale(.95,1.07)}18%{transform:scale(1.06,.92)}27%{transform:scale(.95,1.07)}36%{transform:scale(1.06,.92)}42%,48%{transform:scale(1.06,.92) rotate(-4deg)}54%{transform:scale(1.06,.92)}60%{transform:scale(.95,1.07)}66%{transform:scale(1.06,.92)}71%{transform:translateY(0) scale(1.05,.95)}74%{transform:translateY(-5px) scale(.97,1.05)}77%{transform:translateY(0) scale(1.04,.96)}80%{transform:translateY(-2px) scale(1)}90%{transform:scale(.95,1.07)}to{transform:scale(1.06,.92)}}@keyframes pet-thinking{0%,to{transform:rotate(-3deg)}25%,75%{transform:rotate(1deg)}50%{transform:rotate(3deg)}}@keyframes pet-working{0%,to{transform:translateY(0) scale(1)}35%{transform:translateY(0) scale(1.04,.94)}70%{transform:translateY(-7px) scale(.97,1.03)}}@keyframes pet-answering{0%{transform:scale(1)}30%{transform:scale(1.09,.93)}60%{transform:scale(.96,1.05)}to{transform:scale(1)}}@keyframes pet-waiting{0%,to{transform:rotate(0)}20%{transform:rotate(-6deg)}40%{transform:rotate(6deg)}60%{transform:rotate(-4deg)}80%{transform:rotate(4deg)}}@keyframes pet-done{0%{transform:translateY(-10px) scale(.98,1.02)}40%{transform:translateY(0) scale(1.06,.92)}70%{transform:translateY(-2px) scale(.98,1.02)}to{transform:translateY(0) scale(1)}}@keyframes pet-drag{0%{transform:scale(1)}to{transform:scale(1.05)}}@keyframes pet-squash{0%{transform:scale(1)}35%{transform:scale(1.22,.78)}65%{transform:scale(.92,1.08)}to{transform:scale(1)}}@keyframes pet-release{0%{transform:scale(1.05)}40%{transform:scale(.94,1.06)}70%{transform:scale(1.02,.98)}to{transform:scale(1)}}@keyframes pet-sway{0%,to{transform:rotate(0)}25%{transform:rotate(-2.5deg)}50%{transform:rotate(0)}75%{transform:rotate(2.5deg)}}[data-pet-state=idle] .pet-sprite-img{animation:pet-idle 12s ease-in-out infinite,pet-blink 9.6s steps(1,end) infinite}[data-pet-state=thinking] .pet-sprite-img{animation:pet-thinking 2.2s ease-in-out infinite,pet-blink 9.6s steps(1,end) infinite}[data-pet-state=working] .pet-sprite-img{animation:pet-working .6s ease-in-out infinite,pet-blink 9.6s steps(1,end) infinite}[data-pet-state=answering] .pet-sprite-img{animation:pet-answering 1s ease-in-out infinite,pet-blink 9.6s steps(1,end) infinite}[data-pet-state=waiting-user] .pet-sprite-img{animation:pet-waiting 1.6s ease-in-out infinite,pet-blink 9.6s steps(1,end) infinite}[data-pet-state=done] .pet-sprite-img{animation:pet-done .7s ease-out 1,pet-blink 9.6s steps(1,end) infinite}[data-pet-state=drag] .pet-sprite-img{animation:pet-drag .16s ease-out 1 forwards,pet-blink 9.6s steps(1,end) infinite}[data-pet-state=release] .pet-sprite-img{animation:pet-release .45s cubic-bezier(.2,.8,.3,1.15) 1,pet-blink 9.6s steps(1,end) infinite}[data-pet-state=idle] .pet-figure{animation:pet-sway 4.8s ease-in-out infinite;transform-origin:50% 100%}.pet-poke-layer{width:100%;height:100%}.pet-poke-layer[data-poked]{animation:pet-squash .6s cubic-bezier(.3,1.2,.4,1) 1;transform-origin:50% 100%}[data-paused] *{animation-play-state:paused!important}@media (prefers-reduced-motion: reduce){[data-pet-state=idle] .pet-sprite-img,[data-pet-state=thinking] .pet-sprite-img,[data-pet-state=working] .pet-sprite-img,[data-pet-state=answering] .pet-sprite-img,[data-pet-state=waiting-user] .pet-sprite-img{animation-iteration-count:0,infinite!important}[data-pet-state=done] .pet-sprite-img,[data-pet-state=drag] .pet-sprite-img{animation-iteration-count:1,infinite!important}[data-pet-state=idle] .pet-figure{animation-iteration-count:0!important}.pet-bubble{transition:none!important}.pet-bubble-thinking,.pet-bubble-hint[data-bubble-thinking]{animation:none}}.pet-bubble{position:fixed;left:50%;bottom:79px;transform:translate(-50%);width:min(204px,calc(100vw - 16px));max-height:min(176px,calc(100vh - 96px));box-sizing:border-box;padding:8px 10px;border-radius:var(--radius-lg);background:var(--surface);color:var(--text-1);box-shadow:var(--elev-2);font:12px/1.55 var(--font);overflow:hidden;opacity:1;transition:opacity .25s ease}.pet-bubble[data-bubble-fading]{opacity:0}.pet-bubble[data-bubble-state=stream]{width:min(396px,calc(100vw - 16px));max-height:min(452px,calc(100vh - 104px));padding:12px 14px;font-size:13px;line-height:1.65}.pet-bubble[data-bubble-state=stream] .pet-bubble-stream[data-stream-expanded]{justify-content:flex-start;overflow-y:auto}.pet-bubble[data-bubble-state=stream] .pet-bubble-stream{max-height:396px;padding-right:22px;border-left:3px solid rgb(var(--pet-accent) / .5);padding-left:10px}.pet-bubble-close{position:absolute;top:4px;right:4px;width:18px;height:18px;border:none;border-radius:var(--radius-sm);padding:0;background:transparent;color:var(--text-3);font:inherit;line-height:18px;cursor:pointer}.pet-bubble-close:hover{color:var(--text-1)}.pet-bubble[data-bubble-state=input]{width:min(396px,calc(100vw - 16px));max-height:max(176px,min(452px,calc(100vh - 104px)));padding:12px 14px;font-size:13px;line-height:1.65;display:flex;flex-direction:column}.pet-bubble-chat{display:flex;flex-direction:column;gap:8px;flex:1 1 auto;min-height:0}.pet-bubble-transcript{flex:1 1 auto;min-height:0;overflow-y:auto;display:flex;flex-direction:column;gap:10px;padding-right:4px}.pet-bubble-transcript::-webkit-scrollbar,.pet-bubble-stream[data-stream-expanded]::-webkit-scrollbar{width:8px}.pet-bubble-transcript::-webkit-scrollbar-thumb,.pet-bubble-stream[data-stream-expanded]::-webkit-scrollbar-thumb{background:var(--hair-3);border-radius:50%}.pet-bubble-transcript::-webkit-scrollbar-track,.pet-bubble-stream[data-stream-expanded]::-webkit-scrollbar-track{background:transparent}.pet-turn{display:flex;flex-direction:column;gap:6px}.pet-msg-user{display:flex;flex-direction:column;align-items:flex-end}.pet-row-pet{display:flex;align-items:flex-start;gap:6px}.pet-avatar{flex:0 0 auto;width:34px;height:34px;background-size:200% auto;background-position:0 center;background-repeat:no-repeat}.pet-bubble-q{max-width:85%;box-sizing:border-box;padding:5px 10px;border-radius:var(--radius-md);background:var(--bubble-user-bg);color:var(--bubble-user-ink);display:flex;flex-direction:column;align-items:flex-end;gap:2px}.pet-bubble-body{white-space:pre-wrap;word-break:break-word}.pet-bubble-a{box-sizing:border-box;padding:2px 0;border-radius:var(--radius-md);background:transparent;display:flex;flex-direction:column;align-items:stretch;gap:2px}.pet-row-pet>.pet-bubble-a,.pet-row-pet>.pet-bubble-thinking{flex:0 1 auto;max-width:calc(100% - 40px)}.pet-bubble-a[data-folded] .pet-bubble-body,.pet-bubble-q[data-folded] .pet-bubble-body{max-height:calc(3 * 1.65em);overflow:hidden;-webkit-mask-image:linear-gradient(180deg,var(--shade) calc(100% - 1.4em),transparent);mask-image:linear-gradient(180deg,var(--shade) calc(100% - 1.4em),transparent)}.pet-bubble-fold{align-self:flex-start;border:none;border-radius:var(--radius-sm);padding:3px 10px;background:transparent;color:var(--text-2);font:inherit;font-size:12px;cursor:pointer;margin-top:2px}.pet-bubble-q .pet-bubble-fold{align-self:flex-end}.pet-bubble-fold:hover{color:var(--text-1);background:var(--hover)}@keyframes pet-thinking-breath{0%,to{opacity:1}50%{opacity:.55}}.pet-bubble-thinking{color:var(--warn);animation:pet-thinking-breath 1.2s ease-in-out infinite;padding:2px 0;border-radius:var(--radius-md);background:transparent}.pet-bubble-hint[data-bubble-thinking]{animation:pet-thinking-breath 1.2s ease-in-out infinite}.pet-bubble-input{display:flex;flex-direction:column;gap:6px;border-top:1px solid var(--hair-1);padding-top:8px}.pet-bubble-input textarea{box-sizing:border-box;width:100%;resize:none;border:none;border-radius:var(--radius-sm);padding:6px 8px;background:var(--surface-2);color:var(--text-1);font:inherit;outline:none}.pet-bubble-input textarea:focus{background:var(--surface-2);box-shadow:0 0 0 1.5px rgb(var(--pet-accent))}.pet-bubble-send{align-self:flex-end;border:none;border-radius:var(--radius-md);padding:4px 12px;background:rgb(var(--pet-accent));color:rgb(var(--pet-accent-ink));font:inherit;cursor:pointer}.pet-bubble-input-row{display:flex;justify-content:flex-end;gap:14px}.pet-bubble-cancel{border:none;border-radius:var(--radius-sm);padding:4px 8px;background:transparent;color:var(--text-3);font:inherit;font-size:12px;cursor:pointer}.pet-bubble-cancel:hover{color:var(--text-1)}.pet-bubble-stream{display:flex;flex-direction:column;justify-content:flex-end;max-height:160px;overflow:hidden;white-space:pre-wrap;word-break:break-word}.pet-bubble-hint{color:var(--warn)}.pet-bubble-ask{display:flex;flex-direction:column;gap:6px;box-sizing:border-box;padding:6px 8px;border-radius:var(--radius-md);background:var(--surface-2);color:var(--text-1)}.pet-bubble-ask-tool{align-self:flex-start;padding:0 6px;border-radius:var(--radius-sm);background:var(--bubble-user-bg);color:var(--text-2);font-size:11px;line-height:18px}.pet-bubble-ask-summary{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.pet-bubble-ask-actions{display:flex;flex-wrap:wrap;gap:6px}.pet-bubble-ask-actions button{flex:1 1 auto;border:none;border-radius:var(--radius-md);padding:4px 10px;background:rgb(var(--pet-accent));color:rgb(var(--pet-accent-ink));font:inherit;cursor:pointer}.pet-bubble-ask-actions button[data-ask-always]{background:transparent;border:1px solid rgb(var(--pet-accent));color:var(--text-1)}.pet-bubble-ask-actions button[data-ask-deny]{background:transparent;border:1px solid var(--hair-2);color:var(--text-1)}.pet-bubble-ask-actions button[disabled]{opacity:.5;cursor:default}.pet-bubble-selection{display:flex;flex-direction:column;gap:6px;box-sizing:border-box;padding:6px 8px;border-radius:var(--radius-md);background:var(--surface-2);color:var(--text-1)}.pet-bubble-selection-text{max-height:64px;overflow:hidden;white-space:pre-wrap;word-break:break-word;border-radius:var(--radius-sm);padding:4px 6px;background:var(--bg);color:var(--text-2)}.pet-bubble-selection-actions{display:flex;flex-wrap:wrap;gap:6px}.pet-bubble-selection button{border:none;border-radius:var(--radius-md);padding:4px 10px;background:rgb(var(--pet-accent));color:rgb(var(--pet-accent-ink));font:inherit;cursor:pointer}.pet-bubble-selection button[data-selection-explain]{background:transparent;border:1px solid rgb(var(--pet-accent));color:var(--text-1)}.pet-bubble-selection button[data-selection-cancel]{background:transparent;border:1px solid var(--hair-2);color:var(--text-1)}.pet-bubble-selection button[disabled]{opacity:.5;cursor:default}.pet-bubble-selection-row{display:flex;gap:6px;align-items:center}.pet-bubble-selection-row input{flex:1 1 auto;min-width:0;box-sizing:border-box;border:1px solid var(--hair-2);border-radius:var(--radius-md);padding:4px 8px;background:var(--bg);color:var(--text-1);font:inherit;outline:none}.pet-bubble-selection-row input:focus{border-color:rgb(var(--pet-accent))}.pet-md{display:flex;flex-direction:column;gap:6px}.pet-md-heading{font-weight:700}.pet-md-heading[data-level="1"],.pet-md-heading[data-level="2"]{font-size:14px}.pet-md-pre{box-sizing:border-box;max-width:100%;overflow-x:auto;border-radius:var(--radius-md);padding:6px 8px;background:var(--bg);border:1px solid var(--hair-1);font:11px/1.5 var(--mono);white-space:pre}.pet-md-quote{border-left:2px solid var(--hair-1);padding:2px 0 2px 8px;color:var(--text-2)}.pet-md-list{padding-left:2px}.pet-md-table{display:block;max-width:100%;overflow-x:auto;border-collapse:collapse}.pet-md-table th,.pet-md-table td{padding:2px 6px;border:1px solid var(--hair-1);text-align:left}.pet-md-table th{background:var(--surface-2);color:var(--text-1)}.pet-md-bold{font-weight:700}.pet-md-code{padding:0 4px;border-radius:var(--radius-sm);border:1px solid var(--hair-1);background:var(--surface-2);font-family:var(--mono);font-size:.92em;color:var(--tok-str)}.pet-toast{position:fixed;top:8px;left:50%;transform:translate(-50%);width:min(204px,calc(100vw - 16px));box-sizing:border-box;padding:8px 10px;border-radius:var(--radius-lg);background:var(--surface);color:var(--text-1);box-shadow:var(--elev-2);font:12px/1.55 var(--font);text-align:center;z-index:var(--z-modal)}.pet-expr{position:fixed;bottom:83px;left:50%;transform:translate(-50%);box-sizing:border-box;padding:4px 10px;border-radius:var(--radius-md);background:var(--surface);color:var(--text-1);box-shadow:var(--elev-2);font:12px/1.45 var(--font);text-align:center;white-space:nowrap;z-index:var(--z-modal)}.pet-expr:after{content:"";position:absolute;bottom:-5px;left:50%;transform:translate(-50%);border:5px solid transparent;border-top-color:var(--surface);border-bottom:none}