@appsolutely-io/waypoint 0.0.0-stage → 0.1.1-next.0
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/LICENSE +21 -0
- package/README.md +260 -2
- package/dist/block-reply-DN4RiLL0.d.cts +169 -0
- package/dist/block-reply-Dtof9ild.d.ts +169 -0
- package/dist/blocks-25YOJ5SS.cjs +1 -0
- package/dist/blocks-UJ7GUJHD.js +1 -0
- package/dist/chunk-3KV7TDDR.cjs +3 -0
- package/dist/chunk-4BWV3SEL.cjs +1 -0
- package/dist/chunk-4ZGW4HM4.cjs +1 -0
- package/dist/chunk-5TBO732O.js +1 -0
- package/dist/chunk-6OZSKCPT.cjs +1 -0
- package/dist/chunk-C3VS33WJ.js +1 -0
- package/dist/chunk-D2EGPBCX.cjs +1 -0
- package/dist/chunk-FBADWFRR.cjs +1 -0
- package/dist/chunk-FQSWQLRW.js +1 -0
- package/dist/chunk-GT6PI4CT.cjs +1 -0
- package/dist/chunk-II26UWZM.cjs +1 -0
- package/dist/chunk-JFMVVGGB.js +1 -0
- package/dist/chunk-K73VV7KA.js +1 -0
- package/dist/chunk-L4PFFRDE.js +3 -0
- package/dist/chunk-LLPGVQUT.cjs +1 -0
- package/dist/chunk-M3UENQ6L.cjs +1 -0
- package/dist/chunk-M63QOANE.js +1 -0
- package/dist/chunk-MEKDQDSV.js +1 -0
- package/dist/chunk-OEPKPDLD.js +1 -0
- package/dist/chunk-OWT55N6J.js +3 -0
- package/dist/chunk-PFR2J5BV.js +1 -0
- package/dist/chunk-Q6BD2YL3.cjs +1 -0
- package/dist/chunk-Q7BULGQG.cjs +1 -0
- package/dist/chunk-QS3MKZOY.cjs +3 -0
- package/dist/chunk-RHBDQGD4.js +1 -0
- package/dist/chunk-RZZDQWC2.js +1 -0
- package/dist/chunk-S73WZWDP.js +1 -0
- package/dist/chunk-SD2KAIVE.js +1 -0
- package/dist/chunk-T5XF2R74.js +1 -0
- package/dist/chunk-TCFCSGQ3.js +1 -0
- package/dist/chunk-TGL3DR2K.js +1 -0
- package/dist/chunk-TODYQ3SG.cjs +1 -0
- package/dist/chunk-TVSQHTK2.cjs +1 -0
- package/dist/chunk-UYR3UEIW.cjs +1 -0
- package/dist/chunk-VGGJGRNK.cjs +1 -0
- package/dist/chunk-W6Y7H56X.js +1 -0
- package/dist/chunk-XSHOLIC7.cjs +1 -0
- package/dist/chunk-XWDB2LS3.cjs +1 -0
- package/dist/cli.js +3 -0
- package/dist/confirmation-view-CICNJJIO.js +1 -0
- package/dist/confirmation-view-OMWHUYVC.cjs +1 -0
- package/dist/conformance.cjs +1 -0
- package/dist/conformance.d.cts +10 -0
- package/dist/conformance.d.ts +10 -0
- package/dist/conformance.js +1 -0
- package/dist/flow-parser.cjs +1 -0
- package/dist/flow-parser.d.cts +3 -0
- package/dist/flow-parser.d.ts +3 -0
- package/dist/flow-parser.js +1 -0
- package/dist/flows-panel-AIULKYOS.cjs +1 -0
- package/dist/flows-panel-YEJ36RTY.js +1 -0
- package/dist/form-extras-QYE32TUY.cjs +1 -0
- package/dist/form-extras-SBBOMJS2.js +1 -0
- package/dist/form-fill-C32AHxSr.d.cts +653 -0
- package/dist/form-fill-Dp3ut1_Y.d.ts +653 -0
- package/dist/form-session.cjs +1 -0
- package/dist/form-session.d.cts +7 -0
- package/dist/form-session.d.ts +7 -0
- package/dist/form-session.js +1 -0
- package/dist/frame-decoder.cjs +3 -0
- package/dist/frame-decoder.d.cts +5 -0
- package/dist/frame-decoder.d.ts +5 -0
- package/dist/frame-decoder.js +3 -0
- package/dist/generated-C9tbjwK0.d.cts +797 -0
- package/dist/generated-C9tbjwK0.d.ts +797 -0
- package/dist/hooks/index.cjs +1 -0
- package/dist/hooks/index.d.cts +48 -0
- package/dist/hooks/index.d.ts +48 -0
- package/dist/hooks/index.js +1 -0
- package/dist/i18n-DPNfYTMG.d.cts +148 -0
- package/dist/i18n-DPNfYTMG.d.ts +148 -0
- package/dist/index-B5idIFTx.d.cts +34 -0
- package/dist/index-DPzoKXCK.d.ts +34 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +3 -0
- package/dist/intent-BQPPows1.d.cts +154 -0
- package/dist/intent-BuvqEU3Q.d.ts +154 -0
- package/dist/intent.cjs +1 -0
- package/dist/intent.d.cts +2 -0
- package/dist/intent.d.ts +2 -0
- package/dist/intent.js +1 -0
- package/dist/markdown-BSRKJFFE.cjs +17 -0
- package/dist/markdown-ETLB66BK.js +17 -0
- package/dist/message-actions-3HGE6VTS.js +1 -0
- package/dist/message-actions-F6SPLTT7.cjs +1 -0
- package/dist/messages/en/index.cjs +1 -0
- package/dist/messages/en/index.d.cts +3 -0
- package/dist/messages/en/index.d.ts +3 -0
- package/dist/messages/en/index.js +1 -0
- package/dist/messages/index.cjs +1 -0
- package/dist/messages/index.d.cts +14 -0
- package/dist/messages/index.d.ts +14 -0
- package/dist/messages/index.js +1 -0
- package/dist/messages/zh-Hans/index.cjs +1 -0
- package/dist/messages/zh-Hans/index.d.cts +3 -0
- package/dist/messages/zh-Hans/index.d.ts +3 -0
- package/dist/messages/zh-Hans/index.js +1 -0
- package/dist/on-demand.cjs +1 -0
- package/dist/on-demand.d.cts +56 -0
- package/dist/on-demand.d.ts +56 -0
- package/dist/on-demand.js +1 -0
- package/dist/problem-messages-THONMXFZ.cjs +1 -0
- package/dist/problem-messages-Z5QGO6RE.js +1 -0
- package/dist/react/index.cjs +1 -0
- package/dist/react/index.d.cts +419 -0
- package/dist/react/index.d.ts +419 -0
- package/dist/react/index.js +1 -0
- package/dist/reads-Bk84x_rt.d.ts +38 -0
- package/dist/reads-DlpCt8dE.d.cts +38 -0
- package/dist/recovery-panel-OWY2CWOH.cjs +3 -0
- package/dist/recovery-panel-VOKVDDZD.js +3 -0
- package/dist/reply-controls-5CWIAKIG.js +1 -0
- package/dist/reply-controls-CPWB4VBK.cjs +1 -0
- package/dist/run-XBABOEXK.js +1 -0
- package/dist/schema.json +2900 -0
- package/dist/skin-antd/index.cjs +1 -0
- package/dist/skin-antd/index.d.cts +30 -0
- package/dist/skin-antd/index.d.ts +30 -0
- package/dist/skin-antd/index.js +1 -0
- package/dist/skin-default/index.cjs +1 -0
- package/dist/skin-default/index.d.cts +42 -0
- package/dist/skin-default/index.d.ts +42 -0
- package/dist/skin-default/index.js +1 -0
- package/dist/step-name-3hQ6CCGr.d.cts +19 -0
- package/dist/step-name-BdkYnb5g.d.ts +19 -0
- package/dist/storage-commit.cjs +1 -0
- package/dist/storage-commit.d.cts +17 -0
- package/dist/storage-commit.d.ts +17 -0
- package/dist/storage-commit.js +1 -0
- package/dist/stream-reads.cjs +1 -0
- package/dist/stream-reads.d.cts +22 -0
- package/dist/stream-reads.d.ts +22 -0
- package/dist/stream-reads.js +1 -0
- package/dist/styles.css +796 -0
- package/dist/testing/index.cjs +1 -0
- package/dist/testing/index.d.cts +57 -0
- package/dist/testing/index.d.ts +57 -0
- package/dist/testing/index.js +1 -0
- package/docs/examples/message-versions.tsx +74 -0
- package/docs/form-fill-protocol.md +83 -0
- package/docs/message-versions.md +64 -0
- package/docs/plan-protocol.md +83 -0
- package/docs/reply-protocol.md +75 -0
- package/etc/hooks.api.md +2385 -0
- package/etc/index.api.md +2159 -0
- package/etc/messages-en.api.md +13 -0
- package/etc/messages-zh-Hans.api.md +13 -0
- package/etc/messages.api.md +183 -0
- package/etc/react.api.md +2968 -0
- package/etc/skin-antd.api.md +2989 -0
- package/etc/skin-default.api.md +61 -0
- package/etc/testing.api.md +3034 -0
- package/package.json +168 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as k,j as S}from"./chunk-T5XF2R74.js";import"./chunk-5TBO732O.js";async function j(o){let u=[],w=[],h=(await o("/__conformance/session",{method:"POST"})).body,d={"Content-Type":"application/json",Cookie:`waypoint=${h.session}`,"X-CSRF-Token":h.csrf},t=(e,s)=>o(e,{method:"POST",headers:d,body:JSON.stringify({protocol:"1.1",...s})}),l=e=>o(`/conversations/${encodeURIComponent(e)}`,{headers:d}),y=async(e,s)=>{w.push(e);try{await s()||u.push(e)}catch{u.push(e)}},b={key:"form-fixture-a",resource:"items",label:"Item",route:"/items/new",state:"pending"},v={mode:"form-fill",title:"Form fixture",subject:b,clientCreationId:"form-create-a"},a;try{a=(await t("/conversations",v)).body}catch{return{passed:!1,failures:["form create"],scenarios:["form create"]}}await y("form creation replay",async()=>(await t("/conversations",v)).body.id===a.id),await y("form mode survives refetch",async()=>{let e=(await l(a.id)).body;return e.mode==="form-fill"&&e.subject?.key===b.key}),await y("form subject filtering",async()=>{await t("/conversations",{...v,subject:{...b,key:"form-fixture-b"},clientCreationId:"form-create-b"});let e=await o(`/conversations?subject=${b.key}`,{headers:d}),s=e.body;return e.status===200&&s.some(n=>n.id===a.id)&&s.every(n=>n.subject?.key===b.key)});let g={kind:"form-fill",clientReplyId:"form-fill-a",request:{requestId:"form-request-a",text:"Draft",references:["https://example.test/reference"],attachments:["private-image"],fields:[{name:"title",label:"Title",tier:"low",value:""}]}},I=async e=>{let s=await t(`/conversations/${e}/replies`,g),n=await t(`/conversations/${e}/replies`,g),c=(await l(e)).body.messages.flatMap(i=>i.blocks).filter(i=>i.type==="form.fill"),p=c[0];return s.status===200&&s.body.id===n.body.id&&c.length===1&&p?.body.requestId===g.request.requestId&&Object.keys(p.body.values).join()==="title"&&["valid","invalid"].includes(p.body.values.title.validation.status)&&Array.isArray(p.body.values.title.validation.messages)};return await y("form values and validation replay",()=>I(a.id)),await y("form rejects non-low input",async()=>(await t(`/conversations/${a.id}/replies`,{...g,clientReplyId:"forbidden",request:{...g.request,fields:[{name:"secret",tier:"sensitive",label:"Secret",value:""}]}})).status>=400),await y("form child inherits mode and values",async()=>{let e=(await t("/conversations",{...v,clientCreationId:"form-child-a",parentConversationId:a.id,field:"title"})).body;return e.parentConversationId===a.id&&e.mode==="form-fill"&&e.subject?.key===b.key&&await I(e.id)}),await y("form rejects wrong-subject child",async()=>(await t("/conversations",{...v,clientCreationId:"form-child-wrong",parentConversationId:a.id,field:"title",subject:{...b,key:"another"}})).status>=400),await y("form refuses general replies",async()=>{let e=await t("/conversations",{title:"Ordinary fixture"});if(e.status<200||e.status>=300)return!1;let s={kind:"message",clientReplyId:"general-reply",clientMessageId:"general-message",content:"An ordinary message"},n=await t(`/conversations/${e.body.id}/messages`,s),r=await t(`/conversations/${a.id}/messages`,{...s,clientReplyId:"form-general-reply",clientMessageId:"form-general-message"});return n.status>=200&&n.status<300&&r.status>=400&&r.body?.code==="refused"}),{passed:u.length===0,failures:u,scenarios:w}}async function O(o){let u=[],w=[],h=(await o("/__conformance/session",{method:"POST"})).body,d={"Content-Type":"application/json",Cookie:`waypoint=${h.session}`,"X-CSRF-Token":h.csrf},t=(l,y)=>o(l,{method:"POST",headers:d,body:JSON.stringify({protocol:"1.0",...y})});for(let l of["run","refuse"]){w.push(`plan ${l}`);try{await t("/__conformance/script",{planScenario:l});let v=`/conversations/${(await t("/conversations",{title:"Plan"})).body.id}/replies`,a=async i=>(await o(`/plans/${i}`,{headers:d})).body,g=await a("plan-a");if(g.plan.kind!=="immediate"||g.plan.stage!=="draft")throw new Error("Missing draft");let I=await o("/items/a",{headers:d});await t(v,{kind:"plan.values",clientReplyId:"values-a",planId:"plan-a",steps:[{stepId:"step-a",...I.body}]});let e=await a("plan-a"),s=e.plan;if(s.stage!=="final"||!s.digest)throw new Error("Missing final");let n=e.confirmation?.token;if(!n)throw new Error("Missing confirmation record");let r=(i,m)=>t(v,{kind:"confirm",clientReplyId:i,planId:"plan-a",digest:s.digest,...m});for(let[i,m]of[["no-token",{}],["wrong-token",{confirmationToken:`${n}x`}]])if((await r(i,m)).status!==409)throw new Error("Confirmation without its token accepted");if((await r("confirm-a",{confirmationToken:n})).status!==200)throw new Error("Confirmation refused");if((await r("confirm-b",{confirmationToken:n})).status!==409)throw new Error("Confirmation token used twice");let c=S({read:a,heartbeat:async i=>{await t(`/plans/${i}/heartbeat`,{})},request:async(i,m)=>{if((await o(i.path,{method:i.method,headers:{...d,...m.headers},body:i.body})).status>=400)throw new Error("Step refused")}});await c.run("plan-a",s.digest);let p=await a("plan-a");if(l==="run"&&p.state!=="completed")throw new Error("Not completed");if(l==="refuse"&&(p.state==="undoing"||p.undoPlanId!==void 0))throw new Error("Undo requested automatically");if(l==="run"){await t("/plans/plan-a/stop",{}),await c.run("undo-a",(await a("undo-a")).plan.digest);let i=await o("/items/a",{headers:d});if(JSON.stringify(i.body).includes("After"))throw new Error("Not restored")}c.dispose()}catch{u.push(`plan ${l}`)}}return{passed:u.length===0,failures:u,scenarios:w}}var _={kind:"action",clientReplyId:"card-answer-a",blockId:"card-answer-choice",actionId:"accept"};function T(o){return o===void 0?!0:typeof o!="object"||o===null||Array.isArray(o)?!1:Object.entries(_).every(([u,w])=>o[u]===w)}async function U(o){let u=[],w=[],R=await o.request("/__conformance/session",{method:"POST"});if(R.status!==200)return{passed:!1,failures:["test session unavailable"],scenarios:[]};let h=R.body,d={"Content-Type":"application/json",Cookie:`waypoint=${h.session}`,"X-CSRF-Token":h.csrf},t=(e,s)=>o.request(e,{method:"POST",headers:d,body:JSON.stringify({protocol:"1.0",...s})}),l=async(e,s)=>{w.push(e);try{await s()||u.push(e)}catch{u.push(e)}};await l("negotiation",async()=>{let e=await t("/negotiate",{supported:k});return e.status===200&&k.some(s=>s===e.body.protocol)&&Array.isArray(e.body.capabilities)});let b=(await t("/negotiate",{supported:k})).body;if(b.protocol==="1.1"&&b.capabilities?.includes("form-fill")){let e=await j(o.request);u.push(...e.failures),w.push(...e.scenarios)}let a=(await t("/conversations",{title:"Fixture"})).body.id;await l("optimistic replay",async()=>{let e={clientMessageId:"replay-a",content:"Request"},s=await t(`/conversations/${a}/messages`,e),n=await t(`/conversations/${a}/messages`,e);return s.body.id===n.body.id}),await l("closed failures",async()=>{for(let e of["in-doubt","replaced","retryable","refused","closed","full","declined","unavailable"]){await t("/__conformance/script",{turns:[{problem:{id:"failure-a",code:e}}]});let s=await t(`/conversations/${a}/messages`,{clientMessageId:`failure-${e}`,content:"Request"});if(s.status<400||s.body.code!==e)return!1}return!0}),await l("blocks and fallback",async()=>{let e=["markdown","card","details","list","table","form","choice","buttons","diff","plan","route-link","notice","example/future"],s=e.map(c=>({type:c,id:c,fallback:"Readable",body:F(c)}));await t("/__conformance/script",{turns:[{blocks:s}]}),await t(`/conversations/${a}/messages`,{clientMessageId:"blocks-a",content:"Request"});let r=(await o.request(`/conversations/${a}`,{headers:d})).body;return e.every(c=>r.messages.some(p=>p.blocks.some(i=>i.type===c&&i.fallback==="Readable")))}),await l("drop then refetch",async()=>(await t("/__conformance/script",{turns:[{content:"Authoritative after drop"}]}),await t(`/conversations/${a}/messages`,{clientMessageId:"drop-a",content:"Request"}),await o.request(`/conversations/${a}/stream`,{headers:d}),(await o.request(`/conversations/${a}`,{headers:d})).body.messages.some(s=>s.content==="Authoritative after drop"))),await l("one answer per card",async()=>{await t("/__conformance/script",{turns:[{blocks:[{type:"card",id:"card-answer",fallback:"Answer",body:{title:"Question",blocks:[{type:"buttons",id:"card-answer-choice",fallback:"Answer",body:{actions:[{id:"accept",label:"Accept"},{id:"decline",label:"Decline"}]}}]}}]}]}),await t(`/conversations/${a}/messages`,{clientMessageId:"card-answer",content:"Request"});let e=(f,P)=>t(`/conversations/${a}/replies`,{kind:"action",clientReplyId:f,blockId:"card-answer-choice",actionId:P}),s=f=>f.status===409&&f.body.code==="refused",n=await e("card-answer-a","accept"),r=await e("card-answer-a","accept"),c=await e("card-answer-a","decline"),p=await e("card-answer-b","decline"),m=(await o.request(`/conversations/${a}`,{headers:d})).body.messages.flatMap(f=>f.blocks).find(f=>f.id==="card-answer");return n.status>=200&&n.status<300&&r.status===n.status&&JSON.stringify(r.body)===JSON.stringify(n.body)&&(s(c)||c.status===422)&&s(p)&&m?.answered===!0&&T(m.answer)}),await l("agreement binding",async()=>{let e=await t("/negotiate",{supported:k,offer:{capabilities:["plans"]}}),s=e.body;if(e.status===200&&s.agreementId===void 0)return!0;if(e.status!==200||typeof s.agreementId!="string")return!1;let n={...d,"Waypoint-Agreement":"conformance-unknown"},r=await o.request(`/conversations/${a}`,{headers:n}),c=await o.request(`/conversations/${a}/messages`,{method:"POST",headers:n,body:JSON.stringify({protocol:"1.0",clientMessageId:"binding-a",content:"Request"})}),p=await o.request(`/conversations/${a}`,{headers:d}),i=await o.request(`/conversations/${a}`,{headers:{...d,"Waypoint-Agreement":s.agreementId}});return r.status===409&&r.body.code==="agreement-expired"&&c.status===409&&c.body.code==="agreement-expired"&&!p.body.messages.some(m=>m.clientMessageId==="binding-a")&&i.status===200}),await l("agreement keeps its answer",async()=>{let e=await t("/negotiate",{supported:["1.0"],offer:{capabilities:["plans"]}}),s=await t("/negotiate",{supported:k,offer:{capabilities:["plans"]}}),n=e.body,r=s.body;if(!n.agreementId||!r.agreementId||n.protocol===r.protocol)return!0;let c=await o.request(`/conversations/${a}`,{headers:{...d,"Waypoint-Agreement":n.agreementId}});return c.status===200&&c.body.protocol===n.protocol});let g=await t("/negotiate",{supported:k,offer:{capabilities:["reply-stop"]}});g.body.capabilities?.includes("reply-stop")&&await l("reply stop",async()=>{await t("/__conformance/script",{turns:[{chunks:["Partial answer"],interval:0,ending:"held"}]}),await t(`/conversations/${a}/messages`,{clientMessageId:"stop-a",content:"Request"});let e=C=>C?{...d,"Waypoint-Agreement":C}:d,s=g.body.agreementId,n=async(C=s)=>(await o.request(`/conversations/${a}`,{headers:e(C)})).body.messages.at(-1),r=await n();for(let C=0;r?.content!=="Partial answer"&&C<100;C++)r=await n();if(!s||r?.role!=="assistant"||r.status!=="writing")return!1;let c=r.versionIndex??1,p=await t(`/conversations/${a}/replies`,{kind:"stop",clientReplyId:"stop-a-other-version",messageId:r.id,versionIndex:c+1}),i=await n(),m={kind:"stop",clientReplyId:"stop-a-reply",messageId:r.id,versionIndex:c},f=await t(`/conversations/${a}/replies`,m),P=await t(`/conversations/${a}/replies`,m),x=await t(`/conversations/${a}/replies`,{kind:"stop",clientReplyId:"stop-a-reply-2",messageId:r.id}),$=await n(),A=(await t("/negotiate",{supported:k,offer:{capabilities:["plans"]}})).body.agreementId,q=A?await n(A):void 0;return p.status<500&&i?.status==="writing"&&(!q||q.status==="failed"&&q.content==="Partial answer")&&f.status>=200&&f.status<300&&P.status===f.status&&JSON.stringify(P.body)===JSON.stringify(f.body)&&x.status>=200&&x.status<300&&$?.id===r.id&&$.status==="stopped"&&$.content==="Partial answer"});let I=await O(o.request);return u.push(...I.failures),w.push(...I.scenarios),{passed:u.length===0,failures:u,scenarios:w}}function F(o){return{markdown:{text:"Readable"},card:{title:"Card",blocks:[]},details:{summary:"Details",blocks:[]},list:{items:[]},table:{columns:[],rows:[]},form:{fields:[]},choice:{mode:"single",options:[]},buttons:{actions:[]},diff:{before:"Before",after:"After"},plan:{planId:"plan-a"},"route-link":{label:"View",route:"/items/a"},notice:{text:"Ready"}}[o]??{}}export{U as runConformance,j as runFormFillConformance,O as runPlanConformance};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-II26UWZM.cjs');var _jsyaml = require('js-yaml');function s(n){return _jsyaml.load.call(void 0, n,{schema:_jsyaml.JSON_SCHEMA,listener:(o,r)=>{if(o==="close"&&r.anchor)throw new Error("Flow aliases are not supported")}})}exports.loadFrontmatter = s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunk-5TBO732O.js";import{load as t,JSON_SCHEMA as e}from"js-yaml";function s(n){return t(n,{schema:e,listener:(o,r)=>{if(o==="close"&&r.anchor)throw new Error("Flow aliases are not supported")}})}export{s as loadFrontmatter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunk4ZGW4HM4cjs = require('./chunk-4ZGW4HM4.cjs');var _chunkVGGJGRNKcjs = require('./chunk-VGGJGRNK.cjs');var _chunkUYR3UEIWcjs = require('./chunk-UYR3UEIW.cjs');require('./chunk-FBADWFRR.cjs');require('./chunk-QS3MKZOY.cjs');var _chunkM3UENQ6Lcjs = require('./chunk-M3UENQ6L.cjs');require('./chunk-4BWV3SEL.cjs');var _chunkGT6PI4CTcjs = require('./chunk-GT6PI4CT.cjs');require('./chunk-3KV7TDDR.cjs');require('./chunk-Q7BULGQG.cjs');require('./chunk-XSHOLIC7.cjs');require('./chunk-II26UWZM.cjs');var _react = require('react');var _jsxruntime = require('react/jsx-runtime');_chunkUYR3UEIWcjs.q.call(void 0, _chunkVGGJGRNKcjs.a,_chunkVGGJGRNKcjs.b);function oe({id:c,labelledBy:m,flows:a,all:r,list:l,onRetryList:k,onRunFlow:p}){let{client:s,format:b,primitives:S}=_chunkUYR3UEIWcjs.y.call(void 0, ),y=S.button,e=_react.useRef.call(void 0, null),[o,i]=_react.useState.call(void 0, void 0),[u,E]=_react.useState.call(void 0, new Set),[g,F]=_react.useState.call(void 0, void 0),R=_react.useRef.call(void 0, !1),d=(n,P)=>{u.has(n)||(E(f=>new Set(f).add(n)),F(f=>_optionalChain([f, 'optionalAccess', _2 => _2.id])===n?f:void 0),s.setFavourite(n,P).then(()=>F(f=>_optionalChain([f, 'optionalAccess', _3 => _3.id])===n?void 0:f),()=>F({id:n,value:P})).finally(()=>E(f=>{let A=new Set(f);return A.delete(n),A})))},w=_react.useRef.call(void 0, r);_react.useEffect.call(void 0, ()=>{w.current!==r&&(w.current=r,!o&&R.current&&(R.current=!1,s.prepareFlow()))},[r,o,s]);let x=_react.useRef.call(void 0, 0),z=_chunkUYR3UEIWcjs.e.call(void 0, ()=>{let n=_nullishCoalesce(_optionalChain([e, 'access', _4 => _4.current, 'optionalAccess', _5 => _5.querySelectorAll, 'call', _6 => _6("li")]), () => ([]));return[_optionalChain([n, 'access', _7 => _7[x.current], 'optionalAccess', _8 => _8.querySelector, 'call', _9 => _9("button")]),_optionalChain([n, 'access', _10 => _10[x.current-1], 'optionalAccess', _11 => _11.querySelector, 'call', _12 => _12("button")]),e.current]}),C=_react.useRef.call(void 0, void 0),J=_chunkUYR3UEIWcjs.e.call(void 0, ()=>[_optionalChain([[..._nullishCoalesce(_optionalChain([e, 'access', _13 => _13.current, 'optionalAccess', _14 => _14.querySelectorAll, 'call', _15 => _15("li[data-flow]")]), () => ([]))], 'access', _16 => _16.find, 'call', _17 => _17(n=>n.getAttribute("data-flow")===C.current), 'optionalAccess', _18 => _18.querySelector, 'call', _19 => _19("button")]),e.current]),K=!_optionalChain([a, 'optionalAccess', _20 => _20.length]);return _jsxruntime.jsxs.call(void 0, "div",{ref:e,id:c,role:"tabpanel","aria-labelledby":m,tabIndex:K?0:-1,onFocus:n=>{if(n.target.closest(_chunkGT6PI4CTcjs.a)||n.target.closest("[data-favourite-failure]"))return;let P=n.target.closest("li");x.current=P?[..._nullishCoalesce(_optionalChain([P, 'access', _21 => _21.parentElement, 'optionalAccess', _22 => _22.children]), () => ([]))].indexOf(P):0,z(n)},children:[g?_jsxruntime.jsx.call(void 0, "div",{"data-favourite-failure":"",children:_jsxruntime.jsx.call(void 0, _chunkUYR3UEIWcjs.H,{retrying:u.has(g.id),onFocus:n=>{C.current=g.id,J(n)},onRetry:()=>d(g.id,g.value)})}):null,_optionalChain([a, 'optionalAccess', _23 => _23.length])?_jsxruntime.jsx.call(void 0, "ul",{children:a.map(n=>_jsxruntime.jsxs.call(void 0, "li",{"data-flow":n.id,children:[_jsxruntime.jsx.call(void 0, y,{onPress:()=>{if(!s.canPrepareFlow())return p(n.id);R.current=!0,i(n)},children:n.title}),_jsxruntime.jsx.call(void 0, y,{label:b("chat.block.favourite",{title:n.title}),"aria-pressed":n.favourite===!0,"aria-busy":u.has(n.id)||void 0,onPress:()=>d(n.id,!n.favourite),children:_jsxruntime.jsx.call(void 0, "span",{"aria-hidden":"true",children:n.favourite?"\u2605":"\u2606"})})]},n.id))}):l==="failed"||l==="retrying"?_jsxruntime.jsx.call(void 0, _chunkUYR3UEIWcjs.H,{retrying:l==="retrying",onRetry:k}):_jsxruntime.jsx.call(void 0, "p",{children:b(l==="loading"&&!a?"chat.block.flowsLoading":"chat.block.flowsEmpty")}),o?_jsxruntime.jsx.call(void 0, Q,{flow:o,prepare:()=>s.prepareFlow(o.id),onRun:n=>{p(o.id,n),i(void 0)},onCancel:()=>{i(void 0),s.prepareFlow()},panel:()=>e.current},o.id):null]})}function Q({flow:c,prepare:m,onRun:a,onCancel:r,panel:l}){let{format:k,primitives:p}=_chunkUYR3UEIWcjs.y.call(void 0, ),s=_chunkUYR3UEIWcjs.l.call(void 0, "flow-parameters",void 0,l),b=_react.useRef.call(void 0, r);b.current=r;let S=_chunkUYR3UEIWcjs.h.call(void 0, !0,_chunkM3UENQ6Lcjs.e.call(void 0, ).conversationId,r),[y,e]=_react.useState.call(void 0, void 0),[o,i]=_react.useState.call(void 0, ),[u,E]=_react.useState.call(void 0, 0),g=_react.useRef.call(void 0, a);g.current=a;let F=_react.useRef.call(void 0, null),R=_chunkUYR3UEIWcjs.e.call(void 0, ()=>[_optionalChain([F, 'access', _24 => _24.current, 'optionalAccess', _25 => _25.querySelector, 'call', _26 => _26("input,button")]),F.current]);return _react.useEffect.call(void 0, ()=>{let d=!0;return m().then(w=>{if(d){if(!w)return i("failed");i(void 0),w.parameters.length?e(w):g.current({})}},w=>{d&&(_optionalChain([w, 'optionalAccess', _27 => _27.id])==="flow-prepare"?b.current():i("failed"))}),()=>{d=!1}},[u]),S?null:_jsxruntime.jsx.call(void 0, _chunkUYR3UEIWcjs.k,{as:p.drawer,open:!0,label:c.title,onClose:r,closeLabel:k("chat.close"),...s,children:_jsxruntime.jsx.call(void 0, "div",{ref:F,onFocus:R,tabIndex:-1,children:o?_jsxruntime.jsx.call(void 0, _chunkUYR3UEIWcjs.H,{retrying:o==="retrying",onRetry:()=>{i("retrying"),E(d=>d+1)}}):y?_jsxruntime.jsx.call(void 0, X,{parameters:y.parameters,onRun:d=>a(d),onCancel:r}):_jsxruntime.jsx.call(void 0, "p",{role:"status",children:k("chat.block.flowLoading")})})})}var U=(c,m)=>c.type==="boolean"?!0:m!==void 0&&m!=="";function X({parameters:c,onRun:m,onCancel:a}){let{format:r,primitives:l}=_chunkUYR3UEIWcjs.y.call(void 0, ),k=l.checkbox,[p,s]=_react.useState.call(void 0, ()=>Object.fromEntries(c.map(e=>[e.name,_nullishCoalesce(e.default, () => ((e.type==="boolean"?!1:void 0)))]))),b=c.some(e=>e.required&&!U(e,p[e.name])),S=()=>{b||m(p)},y=(e,o)=>s(i=>({...i,[e]:o}));return _jsxruntime.jsxs.call(void 0, "form",{className:"wp-flow-form",onSubmit:e=>{e.preventDefault(),S()},children:[c.map(e=>{let o=e.required?r("chat.block.required",{label:e.label}):e.label,i=p[e.name];return e.type==="boolean"?_jsxruntime.jsx.call(void 0, k,{label:o,checked:i===!0,onChange:u=>y(e.name,u)},e.name):_jsxruntime.jsx.call(void 0, l.input,{label:o,type:e.type==="number"?"number":"text",required:e.required,value:i===void 0?"":String(i),onChange:u=>y(e.name,e.type==="number"?u.trim()===""||!Number.isFinite(Number(u))?void 0:Number(u):u===""?void 0:u)},e.name)}),_jsxruntime.jsxs.call(void 0, "div",{className:"wp-actions",children:[_jsxruntime.jsx.call(void 0, _chunk4ZGW4HM4cjs.a,{disabled:!1,blocked:b,reason:r("chat.block.runMissing"),label:r("chat.block.run"),onPress:S}),_jsxruntime.jsx.call(void 0, l.button,{onPress:a,children:r("chat.cancel")})]})]})}exports.FlowDrawer = Q; exports.FlowPanel = oe;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as _}from"./chunk-SD2KAIVE.js";import{a as V,b as W}from"./chunk-PFR2J5BV.js";import{H as L,e as D,h as N,k as O,l as B,q as T,y as q}from"./chunk-TGL3DR2K.js";import"./chunk-FQSWQLRW.js";import"./chunk-OWT55N6J.js";import{e as G}from"./chunk-RHBDQGD4.js";import"./chunk-RZZDQWC2.js";import{a as H}from"./chunk-M63QOANE.js";import"./chunk-L4PFFRDE.js";import"./chunk-T5XF2R74.js";import"./chunk-K73VV7KA.js";import"./chunk-5TBO732O.js";import{useEffect as j,useRef as v,useState as h}from"react";import{jsx as t,jsxs as M}from"react/jsx-runtime";T(V,W);function oe({id:c,labelledBy:m,flows:a,all:r,list:l,onRetryList:k,onRunFlow:p}){let{client:s,format:b,primitives:S}=q(),y=S.button,e=v(null),[o,i]=h(void 0),[u,E]=h(new Set),[g,F]=h(void 0),R=v(!1),d=(n,P)=>{u.has(n)||(E(f=>new Set(f).add(n)),F(f=>f?.id===n?f:void 0),s.setFavourite(n,P).then(()=>F(f=>f?.id===n?void 0:f),()=>F({id:n,value:P})).finally(()=>E(f=>{let A=new Set(f);return A.delete(n),A})))},w=v(r);j(()=>{w.current!==r&&(w.current=r,!o&&R.current&&(R.current=!1,s.prepareFlow()))},[r,o,s]);let x=v(0),z=D(()=>{let n=e.current?.querySelectorAll("li")??[];return[n[x.current]?.querySelector("button"),n[x.current-1]?.querySelector("button"),e.current]}),C=v(void 0),J=D(()=>[[...e.current?.querySelectorAll("li[data-flow]")??[]].find(n=>n.getAttribute("data-flow")===C.current)?.querySelector("button"),e.current]),K=!a?.length;return M("div",{ref:e,id:c,role:"tabpanel","aria-labelledby":m,tabIndex:K?0:-1,onFocus:n=>{if(n.target.closest(H)||n.target.closest("[data-favourite-failure]"))return;let P=n.target.closest("li");x.current=P?[...P.parentElement?.children??[]].indexOf(P):0,z(n)},children:[g?t("div",{"data-favourite-failure":"",children:t(L,{retrying:u.has(g.id),onFocus:n=>{C.current=g.id,J(n)},onRetry:()=>d(g.id,g.value)})}):null,a?.length?t("ul",{children:a.map(n=>M("li",{"data-flow":n.id,children:[t(y,{onPress:()=>{if(!s.canPrepareFlow())return p(n.id);R.current=!0,i(n)},children:n.title}),t(y,{label:b("chat.block.favourite",{title:n.title}),"aria-pressed":n.favourite===!0,"aria-busy":u.has(n.id)||void 0,onPress:()=>d(n.id,!n.favourite),children:t("span",{"aria-hidden":"true",children:n.favourite?"\u2605":"\u2606"})})]},n.id))}):l==="failed"||l==="retrying"?t(L,{retrying:l==="retrying",onRetry:k}):t("p",{children:b(l==="loading"&&!a?"chat.block.flowsLoading":"chat.block.flowsEmpty")}),o?t(Q,{flow:o,prepare:()=>s.prepareFlow(o.id),onRun:n=>{p(o.id,n),i(void 0)},onCancel:()=>{i(void 0),s.prepareFlow()},panel:()=>e.current},o.id):null]})}function Q({flow:c,prepare:m,onRun:a,onCancel:r,panel:l}){let{format:k,primitives:p}=q(),s=B("flow-parameters",void 0,l),b=v(r);b.current=r;let S=N(!0,G().conversationId,r),[y,e]=h(void 0),[o,i]=h(),[u,E]=h(0),g=v(a);g.current=a;let F=v(null),R=D(()=>[F.current?.querySelector("input,button"),F.current]);return j(()=>{let d=!0;return m().then(w=>{if(d){if(!w)return i("failed");i(void 0),w.parameters.length?e(w):g.current({})}},w=>{d&&(w?.id==="flow-prepare"?b.current():i("failed"))}),()=>{d=!1}},[u]),S?null:t(O,{as:p.drawer,open:!0,label:c.title,onClose:r,closeLabel:k("chat.close"),...s,children:t("div",{ref:F,onFocus:R,tabIndex:-1,children:o?t(L,{retrying:o==="retrying",onRetry:()=>{i("retrying"),E(d=>d+1)}}):y?t(X,{parameters:y.parameters,onRun:d=>a(d),onCancel:r}):t("p",{role:"status",children:k("chat.block.flowLoading")})})})}var U=(c,m)=>c.type==="boolean"?!0:m!==void 0&&m!=="";function X({parameters:c,onRun:m,onCancel:a}){let{format:r,primitives:l}=q(),k=l.checkbox,[p,s]=h(()=>Object.fromEntries(c.map(e=>[e.name,e.default??(e.type==="boolean"?!1:void 0)]))),b=c.some(e=>e.required&&!U(e,p[e.name])),S=()=>{b||m(p)},y=(e,o)=>s(i=>({...i,[e]:o}));return M("form",{className:"wp-flow-form",onSubmit:e=>{e.preventDefault(),S()},children:[c.map(e=>{let o=e.required?r("chat.block.required",{label:e.label}):e.label,i=p[e.name];return e.type==="boolean"?t(k,{label:o,checked:i===!0,onChange:u=>y(e.name,u)},e.name):t(l.input,{label:o,type:e.type==="number"?"number":"text",required:e.required,value:i===void 0?"":String(i),onChange:u=>y(e.name,e.type==="number"?u.trim()===""||!Number.isFinite(Number(u))?void 0:Number(u):u===""?void 0:u)},e.name)}),M("div",{className:"wp-actions",children:[t(_,{disabled:!1,blocked:b,reason:r("chat.block.runMissing"),label:r("chat.block.run"),onPress:S}),t(l.button,{onPress:a,children:r("chat.cancel")})]})]})}export{Q as FlowDrawer,oe as FlowPanel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkXWDB2LS3cjs = require('./chunk-XWDB2LS3.cjs');var _chunkVGGJGRNKcjs = require('./chunk-VGGJGRNK.cjs');var _chunkUYR3UEIWcjs = require('./chunk-UYR3UEIW.cjs');require('./chunk-FBADWFRR.cjs');require('./chunk-QS3MKZOY.cjs');require('./chunk-M3UENQ6L.cjs');require('./chunk-4BWV3SEL.cjs');require('./chunk-GT6PI4CT.cjs');require('./chunk-3KV7TDDR.cjs');require('./chunk-Q7BULGQG.cjs');require('./chunk-XSHOLIC7.cjs');require('./chunk-II26UWZM.cjs');var _react = require('react');var be={"form.generating":"Generating draft\u2026","form.ready":"Draft ready{choice, plural, =0 {} one {, # field needs your choice} other {, # fields need your choice}}{invalid, plural, =0 {} one {, # field needs attention} other {, # fields need attention}}","form.attention":"{count, plural, one {# field needs attention} other {# fields need attention}}","form.reverted":"Fill reverted.","form.revert":"Revert this fill ({fields})","form.revertWait":"Wait for the draft to finish.","form.suggested":"Suggested value for {field}","form.replaceIt":"Replace","form.keepMine":"Keep mine","form.attach":"Attach images","form.remove":"Remove {name}","form.uploading":"{count, plural, one {Uploading # image\u2026} other {Uploading # images\u2026}}","form.attached":"{count, plural, one {# image attached} other {# images attached}}","form.attachFailed":"{name} could not be attached.","form.removeFailed":"{name} could not be removed.","form.onlyImages":"Only images can be attached.","form.busy":"Wait for the current upload to finish.","form.unusable":"The draft could not be used."},ye={"form.generating":"\u6B63\u5728\u751F\u6210\u8349\u7A3F\u2026\u2026","form.ready":"\u8349\u7A3F\u5DF2\u5C31\u7EEA{choice, plural, =0 {} other {\uFF0C# \u4E2A\u5B57\u6BB5\u9700\u8981\u4F60\u9009\u62E9}}{invalid, plural, =0 {} other {\uFF0C# \u4E2A\u5B57\u6BB5\u9700\u8981\u5904\u7406}}","form.attention":"{count} \u4E2A\u5B57\u6BB5\u9700\u8981\u5904\u7406","form.reverted":"\u5DF2\u64A4\u9500\u672C\u6B21\u586B\u5145\u3002","form.revert":"\u64A4\u9500\u672C\u6B21\u586B\u5145\uFF08{fields}\uFF09","form.revertWait":"\u8BF7\u7B49\u5F85\u8349\u7A3F\u5B8C\u6210\u3002","form.suggested":"{field}\u7684\u5EFA\u8BAE\u503C","form.replaceIt":"\u66FF\u6362","form.keepMine":"\u4FDD\u7559\u6211\u7684","form.attach":"\u9644\u52A0\u56FE\u7247","form.remove":"\u79FB\u9664{name}","form.uploading":"\u6B63\u5728\u4E0A\u4F20 {count} \u5F20\u56FE\u7247\u2026\u2026","form.attached":"\u5DF2\u9644\u52A0 {count} \u5F20\u56FE\u7247","form.attachFailed":"\u65E0\u6CD5\u9644\u52A0{name}\u3002","form.removeFailed":"\u65E0\u6CD5\u79FB\u9664{name}\u3002","form.onlyImages":"\u53EA\u80FD\u9644\u52A0\u56FE\u7247\u3002","form.busy":"\u8BF7\u7B49\u5F85\u5F53\u524D\u4E0A\u4F20\u5B8C\u6210\u3002","form.unusable":"\u65E0\u6CD5\u4F7F\u7528\u6B64\u8349\u7A3F\u3002"};var _jsxruntime = require('react/jsx-runtime');_chunkUYR3UEIWcjs.q.call(void 0, be,ye);_chunkUYR3UEIWcjs.q.call(void 0, _chunkVGGJGRNKcjs.a,_chunkVGGJGRNKcjs.b);var xe=100,Se=new WeakMap;function Re(e){let n=Se.get(e);return n||(n=new Map,Se.set(e,n)),n}function ce(e){for(let[n,t]of e){if(e.size<=xe)break;t.inFlight===0&&e.delete(n)}}var Ce=e=>Object.values(e.fields).filter(n=>_optionalChain([n, 'access', _2 => _2.validation, 'optionalAccess', _3 => _3.status])==="invalid"||n.localInvalid).length;function $e({name:e,draft:n,session:t,t:c,primitives:l,onReplace:A}){let m=l.button,a=n.replacement,u=a.validation.status==="invalid",d=_react.useId.call(void 0, );return _jsxruntime.jsxs.call(void 0, "div",{role:"group","aria-labelledby":d,"data-suggestion":"",children:[_jsxruntime.jsx.call(void 0, "p",{id:d,children:c("form.suggested",{field:n.label})}),_jsxruntime.jsx.call(void 0, "div",{children:_jsxruntime.jsx.call(void 0, _chunkXWDB2LS3cjs.a,{value:a.value,t:c})}),a.validation.messages.length?_jsxruntime.jsxs.call(void 0, "div",{className:u?"wp-invalid":void 0,children:[u?_jsxruntime.jsx.call(void 0, "strong",{children:c("form.invalid")}):null,a.validation.messages.map((r,s)=>_jsxruntime.jsx.call(void 0, "p",{children:r},s))]}):null,_jsxruntime.jsxs.call(void 0, "div",{className:"wp-actions",children:[_jsxruntime.jsx.call(void 0, m,{onPress:()=>{t.replace(e,a.revision)&&A()},children:c("form.replaceIt")}),_jsxruntime.jsx.call(void 0, m,{onPress:()=>t.cancelReplacement(e),children:c("form.keepMine")})]})]})}function Ge({text:e}){return _jsxruntime.jsx.call(void 0, "span",{role:"status",className:"wp-sr-only",children:e})}var Ue=(e,n)=>{let t=Ce(e);return t?n("form.attention",{count:t}):""};function Fe({B:e,reason:n,onPress:t,children:c}){let l=_react.useId.call(void 0, );return _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment,{children:[_jsxruntime.jsx.call(void 0, e,{"aria-disabled":n?!0:void 0,"aria-describedby":n?l:void 0,onPress:n?void 0:t,children:c}),n?_jsxruntime.jsx.call(void 0, "span",{id:l,children:n}):null]})}var Te=(e,n)=>{let t=n;for(let c=2;e.some(l=>l.name===t);c++)t=`${n} (${c})`;return t};async function ke(e,n){let{t,attachments:c}=e;if(!n.length)return;let l=n.filter(r=>r.type.startsWith("image/")),A=l.length<n.length?t("form.onlyImages"):"",m=(...r)=>e.say([...r,A].filter(Boolean).join(" "));if(!l.length)return m();if(!c)return m(t("form.imagesHere"));if(!e.claim())return m(t("form.busy"));let a=e.scope();m(t("form.uploading",{count:l.length}));let u=[],d=[];for(let r of l)try{let s=await c.upload(r);u.push({reference:s,name:r.name||"image"})}catch (e2){d.push(r.name||"image")}if(a!==e.scope()){await Promise.allSettled(u.map(r=>c.remove(r.reference)));return}e.setFiles(r=>{let s=[...r];for(let C of u)s.some(h=>h.reference===C.reference)||s.push({...C,name:Te(s,C.name)});return s}),e.release(),m(u.length?t("form.attached",{count:u.length}):"",...d.map(r=>t("form.attachFailed",{name:r})))}function je({control:e}){let{session:n,t,primitives:c,attachments:l,files:A,accepted:m,sent:a}=e,u=c.button,d=_react.useSyncExternalStore.call(void 0, n.subscribe,n.getSnapshot,n.getSnapshot),r=_react.useId.call(void 0, ),s=e.removalBlocked(),C=_react.useRef.call(void 0, null),h=_react.useRef.call(void 0, null),O=_react.useRef.call(void 0, null),w=_react.useRef.call(void 0, null),H=_react.useRef.call(void 0, void 0);_react.useLayoutEffect.call(void 0, ()=>{m&&m!==H.current&&e.say(t("form.generating")),H.current=m},[m,e,t]);let _=_react.useRef.call(void 0, d.pending);_react.useLayoutEffect.call(void 0, ()=>{let o=_.current&&!d.pending;if(_.current=d.pending,!o||!a)return;let p=_optionalChain([d, 'access', _4 => _4.fills, 'optionalAccess', _5 => _5.some, 'call', _6 => _6(M=>M.id===a)]),j=Object.values(d.fields).filter(M=>_optionalChain([M, 'access', _7 => _7.replacement, 'optionalAccess', _8 => _8.fill])===a).length;(p||j)&&e.say(t("form.ready",{choice:j,invalid:Ce(d)}))},[d,a,e,t]);let K=_react.useRef.call(void 0, 0),T=o=>{let p=_nullishCoalesce(_optionalChain([o, 'optionalAccess', _9 => _9.querySelectorAll, 'call', _10 => _10("button")]), () => ([]));return[p[K.current],p[K.current-1]]},L=o=>{K.current=[...o.currentTarget.querySelectorAll("button")].indexOf(o.target)},D=_chunkUYR3UEIWcjs.e.call(void 0, ()=>[...T(O.current),_optionalChain([h, 'access', _11 => _11.current, 'optionalAccess', _12 => _12.querySelector, 'call', _13 => _13("button")])]),ee=_chunkUYR3UEIWcjs.e.call(void 0, ()=>[...T(w.current),e.messageField()]),z=_chunkUYR3UEIWcjs.e.call(void 0, ()=>[e.messageField()]),te=o=>o.map(p=>_nullishCoalesce(_optionalChain([d, 'access', _14 => _14.fields, 'access', _15 => _15[p], 'optionalAccess', _16 => _16.label]), () => (p))).join(", "),ne=o=>{if(!l)return;if(e.removalBlocked())return e.say(t("form.revertWait"));if(!e.claim())return e.say(t("form.busy"));let p=e.scope();l.remove(o.reference).then(()=>{p===e.scope()&&(e.setFiles(j=>j.filter(M=>M.reference!==o.reference)),e.release())},()=>{p===e.scope()&&(e.release(),e.say(t("form.removeFailed",{name:o.name})))})};return _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment,{children:[_jsxruntime.jsx.call(void 0, "p",{role:"status",className:"wp-form-status",children:e.status}),_jsxruntime.jsx.call(void 0, "div",{onFocus:z,children:e.unusable&&e.unusable===a?_jsxruntime.jsxs.call(void 0, "p",{role:"alert",children:[t("form.unusable")," ",_jsxruntime.jsx.call(void 0, Fe,{B:u,reason:e.blocked,onPress:e.generate,children:t("chat.retry")})]}):null}),_jsxruntime.jsx.call(void 0, "div",{ref:w,onFocus:o=>{L(o),ee(o)},children:(_nullishCoalesce(d.fills, () => ([]))).map(o=>_jsxruntime.jsx.call(void 0, Fe,{B:u,reason:d.pending?t("form.revertWait"):void 0,onPress:()=>{n.revert(o.id)&&e.say(t("form.reverted"))},children:t("form.revert",{fields:te(o.fields)})},o.id))}),l?_jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment,{children:[_jsxruntime.jsx.call(void 0, "input",{ref:C,type:"file",accept:"image/*",multiple:!0,hidden:!0,onChange:o=>{let p=[..._nullishCoalesce(o.target.files, () => ([]))];o.target.value="",ke(e,p)}}),_jsxruntime.jsx.call(void 0, "div",{ref:h,children:_jsxruntime.jsx.call(void 0, u,{onPress:()=>_optionalChain([C, 'access', _17 => _17.current, 'optionalAccess', _18 => _18.click, 'call', _19 => _19()]),children:t("form.attach")})}),s&&A.length?_jsxruntime.jsx.call(void 0, "span",{id:r,className:"wp-sr-only",children:t("form.revertWait")}):null,_jsxruntime.jsx.call(void 0, "ul",{ref:O,onFocus:o=>{L(o),D(o)},className:"wp-attachments",children:A.map(o=>_jsxruntime.jsxs.call(void 0, "li",{children:[_jsxruntime.jsx.call(void 0, "span",{children:o.name}),_jsxruntime.jsx.call(void 0, u,{"aria-disabled":s||void 0,"aria-describedby":s?r:void 0,onPress:()=>ne(o),children:t("form.remove",{name:o.name})})]},o.reference))})]}):null]})}function _e({session:e,open:n,field:t,source:c,attachments:l,text:A,references:m,scope:a,upload:u,messageField:d}){let{client:r,format:s,primitives:C}=_chunkUYR3UEIWcjs.y.call(void 0, ),h=_react.useSyncExternalStore.call(void 0, r.subscribe,r.getSnapshot,r.getSnapshot),O=_react.useSyncExternalStore.call(void 0, e.subscribe,e.getSnapshot,e.getSnapshot),{pending:w}=O,[H,_]=_react.useState.call(void 0, []),[K,T]=_react.useState.call(void 0, !1),[L,D]=_react.useState.call(void 0, !1),[ee,z]=_react.useState.call(void 0, !1),[te,ne]=_react.useState.call(void 0, ""),[o,p]=_react.useState.call(void 0, void 0),[j,M]=_react.useState.call(void 0, void 0),[Pe,le]=_react.useState.call(void 0, void 0),$=_react.useRef.call(void 0, !1),G=_react.useRef.call(void 0, !1),b=Re(r),J=_react.useRef.call(void 0, void 0),y=_react.useRef.call(void 0, void 0),Ae=_react.useRef.call(void 0, 0),Be=_react.useId.call(void 0, ),re=_react.useId.call(void 0, ),we=()=>`${h.conversationId}:${Be}:${++Ae.current}`,ue=C.button;_react.useEffect.call(void 0, ()=>($.current=!1,G.current=!1,T(!1),D(!1),()=>{y.current=void 0}),[n,e,t]),_react.useEffect.call(void 0, ()=>{if(_optionalChain([h, 'access', _20 => _20.conversation, 'optionalAccess', _21 => _21.mode])==="form-fill"){for(let g of h.conversation.messages)for(let I of g.blocks)if(I.type==="form.fill"){let q=_optionalChain([I, 'access', _22 => _22.body, 'optionalAccess', _23 => _23.requestId]);!e.receive(I.body)&&q===_optionalChain([y, 'access', _24 => _24.current, 'optionalAccess', _25 => _25.request, 'access', _26 => _26.requestId])&&e.getSnapshot().pending&&(e.failRequest(q),y.current=void 0,le(q))}}},[h.conversation,e]);let oe=async(g=!1)=>{if($.current||G.current||!n||e.getSnapshot().pending&&!g||g&&(!_optionalChain([y, 'access', _27 => _27.current, 'optionalAccess', _28 => _28.failed])||y.current.conversationId!==r.getSnapshot().conversationId))return;$.current=!0,D(!0),z(!1),le(void 0);let I=a.current,q,E;try{await r.ready;let S=r.getSnapshot();if(g&&_optionalChain([y, 'access', _29 => _29.current, 'optionalAccess', _30 => _30.conversationId])!==S.conversationId)return;let me=k=>k.field===t&&k.conversationId===S.conversationId,ie=t?_nullishCoalesce([...b.values()].find(me), () => ((J.current&&me(J.current)?J.current:void 0))):void 0,V=_nullishCoalesce(_optionalChain([S, 'access', _31 => _31.conversation, 'optionalAccess', _32 => _32.subject]), () => (_optionalChain([ie, 'optionalAccess', _33 => _33.subject])));if(S.protocol!=="1.1"||!S.capabilities.includes("form-fill")||(S.conversation?S.conversation.mode!=="form-fill":!ie)||!V)throw new Error("Form unavailable");if(I!==a.current)return;if(g&&(E=_optionalChain([y, 'access', _34 => _34.current, 'optionalAccess', _35 => _35.creationAttempt]),E&&(E.inFlight++,ce(b))),t&&!g){if(!c)throw new Error("Subthreads unavailable");let k=_nullishCoalesce(_nullishCoalesce(_optionalChain([S, 'access', _36 => _36.conversation, 'optionalAccess', _37 => _37.parentConversationId]), () => (_optionalChain([ie, 'optionalAccess', _38 => _38.parent]))), () => (S.conversationId)),W=JSON.stringify([k,t]);q=W,b.has(W)||b.set(W,{id:we(),parent:k,field:t,subject:V,inFlight:0});let f=b.get(W);if(E=f,f.inFlight++,ce(b),!f.conversationId){let Q=await c.create({protocol:S.protocol,title:t,mode:"form-fill",subject:V,parentConversationId:k,field:t,clientCreationId:f.id});if(Q.mode!=="form-fill"||Q.parentConversationId!==k||_optionalChain([Q, 'access', _39 => _39.subject, 'optionalAccess', _40 => _40.key])!==V.key)throw new Error("Invalid child");f.conversationId=Q.id}if(I!==a.current||r.getSnapshot().conversationId!==S.conversationId)return;J.current=f;let N=r.getSnapshot(),R=N.conversationId===f.conversationId&&_optionalChain([N, 'access', _41 => _41.conversation, 'optionalAccess', _42 => _42.id])===f.conversationId&&N.status==="open"&&!N.conversationUnavailable&&_optionalChain([N, 'access', _43 => _43.problem, 'optionalAccess', _44 => _44.id])!=="conversation-read"?{kind:"loaded",conversationId:f.conversationId,conversation:N.conversation}:await r.switchConversation(f.conversationId);if(I!==a.current||r.getSnapshot().conversationId!==f.conversationId)return;if(_optionalChain([R, 'optionalAccess', _45 => _45.kind])==="missing"&&R.conversationId===f.conversationId&&b.get(W)===f&&b.delete(W),_optionalChain([R, 'optionalAccess', _46 => _46.kind])!=="loaded"||R.conversationId!==f.conversationId||R.conversation.id!==f.conversationId||R.conversation.mode!=="form-fill"||_optionalChain([R, 'access', _47 => _47.conversation, 'access', _48 => _48.subject, 'optionalAccess', _49 => _49.key])!==f.subject.key)throw new Error("Child unavailable")}if(I!==a.current)return;let Me={text:A,field:_nullishCoalesce(t, () => (_optionalChain([r, 'access', _50 => _50.getSnapshot, 'call', _51 => _51(), 'access', _52 => _52.conversation, 'optionalAccess', _53 => _53.field]))),references:m.split(/\r?\n/).filter(Boolean),attachments:H.map(k=>k.reference)};g||(y.current={request:e.begin(Me),conversationId:r.getSnapshot().conversationId,creationKey:q,creationAttempt:E});let x=y.current,X=x.request;x.failed=!1,p(X.requestId);let Ee=await r.reply({kind:"form-fill",clientReplyId:X.requestId,request:X});if(I!==a.current)return;if(!Ee)throw x.failed=!0,new Error("Form send failed");M(X.requestId),x.creationKey&&b.get(x.creationKey)===x.creationAttempt&&b.delete(x.creationKey)}catch (e3){I===a.current&&z(!0)}finally{E&&(E.inFlight--,ce(b)),I===a.current&&($.current=!1,D(!1))}},F=Object.values(O.fields).some(g=>g.localInvalid)?s("form.fixFirst"):K?s("form.busy"):void 0,fe={session:e,t:s,primitives:C,attachments:l,files:H,setFiles:_,removalBlocked:()=>$.current||e.getSnapshot().pending,claim:()=>G.current?!1:(G.current=!0,T(!0),!0),release:()=>{G.current=!1,T(!1)},scope:()=>a.current,accepted:w?j:void 0,sent:o,generate:()=>{F||oe()},say:ne,status:te,unusable:Pe,blocked:F,messageField:d};return u.current=g=>{ke(fe,g)},_react.useEffect.call(void 0, ()=>()=>u.current=void 0,[u]),_jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment,{children:[_jsxruntime.jsx.call(void 0, je,{control:fe}),w&&_jsxruntime.jsx.call(void 0, "p",{children:s("form.closeHint")}),ee&&_jsxruntime.jsx.call(void 0, "p",{role:"alert",children:s("chat.failure")}),w&&_optionalChain([y, 'access', _54 => _54.current, 'optionalAccess', _55 => _55.failed])&&_jsxruntime.jsx.call(void 0, ue,{disabled:L||y.current.conversationId!==h.conversationId,"aria-disabled":F?!0:void 0,"aria-describedby":F?re:void 0,onPress:()=>{F||oe(!0)},children:s("chat.retry")}),_jsxruntime.jsx.call(void 0, ue,{disabled:L||w||!h.capabilities.includes("form-fill"),"aria-disabled":F?!0:void 0,"aria-describedby":F?re:void 0,onPress:()=>{F||oe()},children:s("form.generate")}),F?_jsxruntime.jsx.call(void 0, "span",{id:re,children:F}):null]})}exports.FieldsStatus = Ge; exports.PopupBody = _e; exports.Suggestion = $e; exports.Value = _chunkXWDB2LS3cjs.a; exports.attentionText = Ue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as ve}from"./chunk-MEKDQDSV.js";import{a as pe,b as ge}from"./chunk-PFR2J5BV.js";import{e as Y,q as ae,y as he}from"./chunk-TGL3DR2K.js";import"./chunk-FQSWQLRW.js";import"./chunk-OWT55N6J.js";import"./chunk-RHBDQGD4.js";import"./chunk-RZZDQWC2.js";import"./chunk-M63QOANE.js";import"./chunk-L4PFFRDE.js";import"./chunk-T5XF2R74.js";import"./chunk-K73VV7KA.js";import"./chunk-5TBO732O.js";import{useEffect as se,useId as U,useLayoutEffect as Ie,useRef as v,useState as B,useSyncExternalStore as de}from"react";var be={"form.generating":"Generating draft\u2026","form.ready":"Draft ready{choice, plural, =0 {} one {, # field needs your choice} other {, # fields need your choice}}{invalid, plural, =0 {} one {, # field needs attention} other {, # fields need attention}}","form.attention":"{count, plural, one {# field needs attention} other {# fields need attention}}","form.reverted":"Fill reverted.","form.revert":"Revert this fill ({fields})","form.revertWait":"Wait for the draft to finish.","form.suggested":"Suggested value for {field}","form.replaceIt":"Replace","form.keepMine":"Keep mine","form.attach":"Attach images","form.remove":"Remove {name}","form.uploading":"{count, plural, one {Uploading # image\u2026} other {Uploading # images\u2026}}","form.attached":"{count, plural, one {# image attached} other {# images attached}}","form.attachFailed":"{name} could not be attached.","form.removeFailed":"{name} could not be removed.","form.onlyImages":"Only images can be attached.","form.busy":"Wait for the current upload to finish.","form.unusable":"The draft could not be used."},ye={"form.generating":"\u6B63\u5728\u751F\u6210\u8349\u7A3F\u2026\u2026","form.ready":"\u8349\u7A3F\u5DF2\u5C31\u7EEA{choice, plural, =0 {} other {\uFF0C# \u4E2A\u5B57\u6BB5\u9700\u8981\u4F60\u9009\u62E9}}{invalid, plural, =0 {} other {\uFF0C# \u4E2A\u5B57\u6BB5\u9700\u8981\u5904\u7406}}","form.attention":"{count} \u4E2A\u5B57\u6BB5\u9700\u8981\u5904\u7406","form.reverted":"\u5DF2\u64A4\u9500\u672C\u6B21\u586B\u5145\u3002","form.revert":"\u64A4\u9500\u672C\u6B21\u586B\u5145\uFF08{fields}\uFF09","form.revertWait":"\u8BF7\u7B49\u5F85\u8349\u7A3F\u5B8C\u6210\u3002","form.suggested":"{field}\u7684\u5EFA\u8BAE\u503C","form.replaceIt":"\u66FF\u6362","form.keepMine":"\u4FDD\u7559\u6211\u7684","form.attach":"\u9644\u52A0\u56FE\u7247","form.remove":"\u79FB\u9664{name}","form.uploading":"\u6B63\u5728\u4E0A\u4F20 {count} \u5F20\u56FE\u7247\u2026\u2026","form.attached":"\u5DF2\u9644\u52A0 {count} \u5F20\u56FE\u7247","form.attachFailed":"\u65E0\u6CD5\u9644\u52A0{name}\u3002","form.removeFailed":"\u65E0\u6CD5\u79FB\u9664{name}\u3002","form.onlyImages":"\u53EA\u80FD\u9644\u52A0\u56FE\u7247\u3002","form.busy":"\u8BF7\u7B49\u5F85\u5F53\u524D\u4E0A\u4F20\u5B8C\u6210\u3002","form.unusable":"\u65E0\u6CD5\u4F7F\u7528\u6B64\u8349\u7A3F\u3002"};import{Fragment as Z,jsx as i,jsxs as P}from"react/jsx-runtime";ae(be,ye);ae(pe,ge);var xe=100,Se=new WeakMap;function Re(e){let n=Se.get(e);return n||(n=new Map,Se.set(e,n)),n}function ce(e){for(let[n,t]of e){if(e.size<=xe)break;t.inFlight===0&&e.delete(n)}}var Ce=e=>Object.values(e.fields).filter(n=>n.validation?.status==="invalid"||n.localInvalid).length;function $e({name:e,draft:n,session:t,t:c,primitives:l,onReplace:A}){let m=l.button,a=n.replacement,u=a.validation.status==="invalid",d=U();return P("div",{role:"group","aria-labelledby":d,"data-suggestion":"",children:[i("p",{id:d,children:c("form.suggested",{field:n.label})}),i("div",{children:i(ve,{value:a.value,t:c})}),a.validation.messages.length?P("div",{className:u?"wp-invalid":void 0,children:[u?i("strong",{children:c("form.invalid")}):null,a.validation.messages.map((r,s)=>i("p",{children:r},s))]}):null,P("div",{className:"wp-actions",children:[i(m,{onPress:()=>{t.replace(e,a.revision)&&A()},children:c("form.replaceIt")}),i(m,{onPress:()=>t.cancelReplacement(e),children:c("form.keepMine")})]})]})}function Ge({text:e}){return i("span",{role:"status",className:"wp-sr-only",children:e})}var Ue=(e,n)=>{let t=Ce(e);return t?n("form.attention",{count:t}):""};function Fe({B:e,reason:n,onPress:t,children:c}){let l=U();return P(Z,{children:[i(e,{"aria-disabled":n?!0:void 0,"aria-describedby":n?l:void 0,onPress:n?void 0:t,children:c}),n?i("span",{id:l,children:n}):null]})}var Te=(e,n)=>{let t=n;for(let c=2;e.some(l=>l.name===t);c++)t=`${n} (${c})`;return t};async function ke(e,n){let{t,attachments:c}=e;if(!n.length)return;let l=n.filter(r=>r.type.startsWith("image/")),A=l.length<n.length?t("form.onlyImages"):"",m=(...r)=>e.say([...r,A].filter(Boolean).join(" "));if(!l.length)return m();if(!c)return m(t("form.imagesHere"));if(!e.claim())return m(t("form.busy"));let a=e.scope();m(t("form.uploading",{count:l.length}));let u=[],d=[];for(let r of l)try{let s=await c.upload(r);u.push({reference:s,name:r.name||"image"})}catch{d.push(r.name||"image")}if(a!==e.scope()){await Promise.allSettled(u.map(r=>c.remove(r.reference)));return}e.setFiles(r=>{let s=[...r];for(let C of u)s.some(h=>h.reference===C.reference)||s.push({...C,name:Te(s,C.name)});return s}),e.release(),m(u.length?t("form.attached",{count:u.length}):"",...d.map(r=>t("form.attachFailed",{name:r})))}function je({control:e}){let{session:n,t,primitives:c,attachments:l,files:A,accepted:m,sent:a}=e,u=c.button,d=de(n.subscribe,n.getSnapshot,n.getSnapshot),r=U(),s=e.removalBlocked(),C=v(null),h=v(null),O=v(null),w=v(null),H=v(void 0);Ie(()=>{m&&m!==H.current&&e.say(t("form.generating")),H.current=m},[m,e,t]);let _=v(d.pending);Ie(()=>{let o=_.current&&!d.pending;if(_.current=d.pending,!o||!a)return;let p=d.fills?.some(M=>M.id===a),j=Object.values(d.fields).filter(M=>M.replacement?.fill===a).length;(p||j)&&e.say(t("form.ready",{choice:j,invalid:Ce(d)}))},[d,a,e,t]);let K=v(0),T=o=>{let p=o?.querySelectorAll("button")??[];return[p[K.current],p[K.current-1]]},L=o=>{K.current=[...o.currentTarget.querySelectorAll("button")].indexOf(o.target)},D=Y(()=>[...T(O.current),h.current?.querySelector("button")]),ee=Y(()=>[...T(w.current),e.messageField()]),z=Y(()=>[e.messageField()]),te=o=>o.map(p=>d.fields[p]?.label??p).join(", "),ne=o=>{if(!l)return;if(e.removalBlocked())return e.say(t("form.revertWait"));if(!e.claim())return e.say(t("form.busy"));let p=e.scope();l.remove(o.reference).then(()=>{p===e.scope()&&(e.setFiles(j=>j.filter(M=>M.reference!==o.reference)),e.release())},()=>{p===e.scope()&&(e.release(),e.say(t("form.removeFailed",{name:o.name})))})};return P(Z,{children:[i("p",{role:"status",className:"wp-form-status",children:e.status}),i("div",{onFocus:z,children:e.unusable&&e.unusable===a?P("p",{role:"alert",children:[t("form.unusable")," ",i(Fe,{B:u,reason:e.blocked,onPress:e.generate,children:t("chat.retry")})]}):null}),i("div",{ref:w,onFocus:o=>{L(o),ee(o)},children:(d.fills??[]).map(o=>i(Fe,{B:u,reason:d.pending?t("form.revertWait"):void 0,onPress:()=>{n.revert(o.id)&&e.say(t("form.reverted"))},children:t("form.revert",{fields:te(o.fields)})},o.id))}),l?P(Z,{children:[i("input",{ref:C,type:"file",accept:"image/*",multiple:!0,hidden:!0,onChange:o=>{let p=[...o.target.files??[]];o.target.value="",ke(e,p)}}),i("div",{ref:h,children:i(u,{onPress:()=>C.current?.click(),children:t("form.attach")})}),s&&A.length?i("span",{id:r,className:"wp-sr-only",children:t("form.revertWait")}):null,i("ul",{ref:O,onFocus:o=>{L(o),D(o)},className:"wp-attachments",children:A.map(o=>P("li",{children:[i("span",{children:o.name}),i(u,{"aria-disabled":s||void 0,"aria-describedby":s?r:void 0,onPress:()=>ne(o),children:t("form.remove",{name:o.name})})]},o.reference))})]}):null]})}function _e({session:e,open:n,field:t,source:c,attachments:l,text:A,references:m,scope:a,upload:u,messageField:d}){let{client:r,format:s,primitives:C}=he(),h=de(r.subscribe,r.getSnapshot,r.getSnapshot),O=de(e.subscribe,e.getSnapshot,e.getSnapshot),{pending:w}=O,[H,_]=B([]),[K,T]=B(!1),[L,D]=B(!1),[ee,z]=B(!1),[te,ne]=B(""),[o,p]=B(void 0),[j,M]=B(void 0),[Pe,le]=B(void 0),$=v(!1),G=v(!1),b=Re(r),J=v(void 0),y=v(void 0),Ae=v(0),Be=U(),re=U(),we=()=>`${h.conversationId}:${Be}:${++Ae.current}`,ue=C.button;se(()=>($.current=!1,G.current=!1,T(!1),D(!1),()=>{y.current=void 0}),[n,e,t]),se(()=>{if(h.conversation?.mode==="form-fill"){for(let g of h.conversation.messages)for(let I of g.blocks)if(I.type==="form.fill"){let q=I.body?.requestId;!e.receive(I.body)&&q===y.current?.request.requestId&&e.getSnapshot().pending&&(e.failRequest(q),y.current=void 0,le(q))}}},[h.conversation,e]);let oe=async(g=!1)=>{if($.current||G.current||!n||e.getSnapshot().pending&&!g||g&&(!y.current?.failed||y.current.conversationId!==r.getSnapshot().conversationId))return;$.current=!0,D(!0),z(!1),le(void 0);let I=a.current,q,E;try{await r.ready;let S=r.getSnapshot();if(g&&y.current?.conversationId!==S.conversationId)return;let me=k=>k.field===t&&k.conversationId===S.conversationId,ie=t?[...b.values()].find(me)??(J.current&&me(J.current)?J.current:void 0):void 0,V=S.conversation?.subject??ie?.subject;if(S.protocol!=="1.1"||!S.capabilities.includes("form-fill")||(S.conversation?S.conversation.mode!=="form-fill":!ie)||!V)throw new Error("Form unavailable");if(I!==a.current)return;if(g&&(E=y.current?.creationAttempt,E&&(E.inFlight++,ce(b))),t&&!g){if(!c)throw new Error("Subthreads unavailable");let k=S.conversation?.parentConversationId??ie?.parent??S.conversationId,W=JSON.stringify([k,t]);q=W,b.has(W)||b.set(W,{id:we(),parent:k,field:t,subject:V,inFlight:0});let f=b.get(W);if(E=f,f.inFlight++,ce(b),!f.conversationId){let Q=await c.create({protocol:S.protocol,title:t,mode:"form-fill",subject:V,parentConversationId:k,field:t,clientCreationId:f.id});if(Q.mode!=="form-fill"||Q.parentConversationId!==k||Q.subject?.key!==V.key)throw new Error("Invalid child");f.conversationId=Q.id}if(I!==a.current||r.getSnapshot().conversationId!==S.conversationId)return;J.current=f;let N=r.getSnapshot(),R=N.conversationId===f.conversationId&&N.conversation?.id===f.conversationId&&N.status==="open"&&!N.conversationUnavailable&&N.problem?.id!=="conversation-read"?{kind:"loaded",conversationId:f.conversationId,conversation:N.conversation}:await r.switchConversation(f.conversationId);if(I!==a.current||r.getSnapshot().conversationId!==f.conversationId)return;if(R?.kind==="missing"&&R.conversationId===f.conversationId&&b.get(W)===f&&b.delete(W),R?.kind!=="loaded"||R.conversationId!==f.conversationId||R.conversation.id!==f.conversationId||R.conversation.mode!=="form-fill"||R.conversation.subject?.key!==f.subject.key)throw new Error("Child unavailable")}if(I!==a.current)return;let Me={text:A,field:t??r.getSnapshot().conversation?.field,references:m.split(/\r?\n/).filter(Boolean),attachments:H.map(k=>k.reference)};g||(y.current={request:e.begin(Me),conversationId:r.getSnapshot().conversationId,creationKey:q,creationAttempt:E});let x=y.current,X=x.request;x.failed=!1,p(X.requestId);let Ee=await r.reply({kind:"form-fill",clientReplyId:X.requestId,request:X});if(I!==a.current)return;if(!Ee)throw x.failed=!0,new Error("Form send failed");M(X.requestId),x.creationKey&&b.get(x.creationKey)===x.creationAttempt&&b.delete(x.creationKey)}catch{I===a.current&&z(!0)}finally{E&&(E.inFlight--,ce(b)),I===a.current&&($.current=!1,D(!1))}},F=Object.values(O.fields).some(g=>g.localInvalid)?s("form.fixFirst"):K?s("form.busy"):void 0,fe={session:e,t:s,primitives:C,attachments:l,files:H,setFiles:_,removalBlocked:()=>$.current||e.getSnapshot().pending,claim:()=>G.current?!1:(G.current=!0,T(!0),!0),release:()=>{G.current=!1,T(!1)},scope:()=>a.current,accepted:w?j:void 0,sent:o,generate:()=>{F||oe()},say:ne,status:te,unusable:Pe,blocked:F,messageField:d};return u.current=g=>{ke(fe,g)},se(()=>()=>u.current=void 0,[u]),P(Z,{children:[i(je,{control:fe}),w&&i("p",{children:s("form.closeHint")}),ee&&i("p",{role:"alert",children:s("chat.failure")}),w&&y.current?.failed&&i(ue,{disabled:L||y.current.conversationId!==h.conversationId,"aria-disabled":F?!0:void 0,"aria-describedby":F?re:void 0,onPress:()=>{F||oe(!0)},children:s("chat.retry")}),i(ue,{disabled:L||w||!h.capabilities.includes("form-fill"),"aria-disabled":F?!0:void 0,"aria-describedby":F?re:void 0,onPress:()=>{F||oe()},children:s("form.generate")}),F?i("span",{id:re,children:F}):null]})}export{Ge as FieldsStatus,_e as PopupBody,$e as Suggestion,ve as Value,Ue as attentionText};
|