@runtypelabs/persona 4.28.0 → 4.28.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.
- package/README.md +25 -0
- package/dist/{approval-ui-QAKWNFNM.js → approval-ui-OBBI62ES.js} +1 -1
- package/dist/approval-ui.cjs +2 -2
- package/dist/approval-ui.d.cts +7 -5
- package/dist/approval-ui.d.ts +7 -5
- package/dist/approval-ui.js +2 -2
- package/dist/artifacts-ui.d.cts +7 -5
- package/dist/artifacts-ui.d.ts +7 -5
- package/dist/{chunk-NQLDCJAP.js → chunk-D4TDKCT5.js} +2 -2
- package/dist/chunk-FNXK3VTC.js +1 -0
- package/dist/{client-history-LV3KHEFA.js → client-history-QGAFMCBE.js} +1 -1
- package/dist/client-history.js +1 -1
- package/dist/{client-stream-N22JHTLE.js → client-stream-WXD2FL23.js} +1 -1
- package/dist/client-stream.js +3 -3
- package/dist/codegen.cjs +4 -4
- package/dist/codegen.js +5 -5
- package/dist/context-mentions.d.cts +7 -5
- package/dist/context-mentions.d.ts +7 -5
- package/dist/event-stream-view.d.cts +7 -5
- package/dist/event-stream-view.d.ts +7 -5
- package/dist/forms-ui.d.cts +7 -5
- package/dist/forms-ui.d.ts +7 -5
- package/dist/index.cjs +40 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -30
- package/dist/index.d.ts +32 -30
- package/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +41 -41
- package/dist/index.js.map +1 -1
- package/dist/session-reconnect.d.cts +7 -5
- package/dist/session-reconnect.d.ts +7 -5
- package/dist/smart-dom-reader.d.cts +7 -5
- package/dist/smart-dom-reader.d.ts +7 -5
- package/dist/theme-editor-preview.cjs +51 -51
- package/dist/theme-editor-preview.d.cts +7 -5
- package/dist/theme-editor-preview.d.ts +7 -5
- package/dist/theme-editor-preview.js +4 -4
- package/dist/theme-editor.d.cts +8 -6
- package/dist/theme-editor.d.ts +8 -6
- package/dist/{voice-runtime-LVUMPUDS.js → voice-runtime-TWFJ4UUS.js} +1 -1
- package/dist/voice-runtime.cjs +1 -1
- package/dist/voice-runtime.d.cts +7 -5
- package/dist/voice-runtime.d.ts +7 -5
- package/dist/voice-runtime.js +1 -1
- package/dist/webmcp-runtime-5Q3IHAHP.js +6 -0
- package/dist/webmcp-runtime.cjs +2 -2
- package/dist/webmcp-runtime.d.cts +22 -26
- package/dist/webmcp-runtime.d.ts +22 -26
- package/dist/webmcp-runtime.js +2 -2
- package/package.json +5 -2
- package/src/generated/runtype-openapi-contract.ts +3 -0
- package/src/theme-editor/webmcp/types.ts +1 -1
- package/src/types.ts +7 -5
- package/src/webmcp-bridge.test.ts +87 -21
- package/src/webmcp-bridge.ts +21 -26
- package/src/webmcp-polyfill.integration.test.ts +339 -0
- package/src/webmcp-polyfill.ts +7 -4
- package/src/webmcp-runtime-bundle.test.ts +1 -1
- package/src/webmcp-runtime-entry.ts +34 -19
- package/dist/chunk-AALCT54S.js +0 -1
- package/dist/webmcp-runtime-V6ZWW3PI.js +0 -6
package/README.md
CHANGED
|
@@ -235,3 +235,28 @@ Add `RUNTYPE_API_KEY` to your environment. The proxy constructs the Runtype payl
|
|
|
235
235
|
- The proxy prefers port `43111` but automatically selects the next free port if needed.
|
|
236
236
|
- `features.askUserQuestion.expose` and `suggestions.followUps.expose` advertise built-in LOCAL client tools through `clientTools[]`; leave `expose` off if the flow already declares those tools server-side.
|
|
237
237
|
- `webmcp: { enabled: true }` snapshots page-registered tools on `document.modelContext`, sends them as `clientTools[]`, executes returned `webmcp:*` calls in the browser, and resumes the paused execution.
|
|
238
|
+
|
|
239
|
+
### WebMCP compatibility
|
|
240
|
+
|
|
241
|
+
Persona supports host-installed `@mcp-b/webmcp-polyfill` v5 and v6 without
|
|
242
|
+
replacing their registry. Producer pages using v5 call
|
|
243
|
+
`initializeWebMCPPolyfill()`; pages using v6 call `installWebMCP()` before
|
|
244
|
+
registering tools. Both initializer exports also work with custom Persona
|
|
245
|
+
polyfill loaders. Tool execution supports both JSON-string and object-input
|
|
246
|
+
contracts with one invocation, not a failed-call retry.
|
|
247
|
+
|
|
248
|
+
When no registry exists, Persona lazily installs v5. This preserves the previous
|
|
249
|
+
browser requirements and callback-result behavior. The demos use v6 explicitly;
|
|
250
|
+
that runtime requires HTTPS/localhost and Chrome/Firefox 126+ or Safari 18+.
|
|
251
|
+
|
|
252
|
+
Only the current document's tools are exposed, even when the registry also
|
|
253
|
+
discovers tools in related frames. The dispatch protocol addresses tools by
|
|
254
|
+
name and does not support frame-qualified calls.
|
|
255
|
+
|
|
256
|
+
Callback semantics belong to the installed runtime. In v6, callbacks receive
|
|
257
|
+
`(input, { signal })`; validate input, forward the signal to cancellable work,
|
|
258
|
+
and return a JSON-serializable value. Return an MCP result with `isError: true`
|
|
259
|
+
for an actionable error message: v6 replaces thrown callback errors with a
|
|
260
|
+
generic error and rejects `undefined` and other non-serializable results. v5's
|
|
261
|
+
existing result conversion remains unchanged. Registration cleanup uses an
|
|
262
|
+
AbortSignal in both versions.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as D,g as P}from"./chunk-NQLDCJAP.js";import{b as $,c as z}from"./chunk-Q735PSZL.js";import{a as h}from"./chunk-7NQ4ZTHF.js";import{a as r}from"./chunk-76IELU7F.js";var K=()=>{},R=t=>{K=t.webMcpToolTitle},O=t=>K(t);import{ChevronDown as ee,ChevronUp as te,ShieldAlert as oe,ShieldCheck as _,ShieldX as F}from"lucide";var H=t=>{let a=(t.startsWith(D)?t.slice(D.length):t).replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[_\-\s.]+/).filter(Boolean);if(a.length===0)return t;let o=a.join(" ").toLowerCase();return o.charAt(0).toUpperCase()+o.slice(1)},X=t=>t?.approval!==!1?t?.approval:void 0,j=(t,n,a)=>{let o=X(a)?.detailsDisplay??"collapsed";return n.get(t)??o==="expanded"},V=(t,n,a)=>{let o=X(a);t.setAttribute("aria-expanded",n?"true":"false");let e=t.querySelector("[data-approval-details-label]");e&&(e.textContent=n?o?.hideDetailsLabel??"Hide details":o?.showDetailsLabel??"Show details");let m=t.querySelector("[data-approval-details-chevron]");if(m){m.innerHTML="";let c=h(n?te:ee,14,"currentColor",2);c&&m.appendChild(c)}},G=(t,n,a,o=new Map)=>{let e=n.querySelector('button[data-bubble-type="approval"]'),m=n.querySelector("[data-approval-details]");if(!e||!m)return;let c=j(t,o,a);V(e,c,a),m.style.display=c?"":"none"};var Z=(t,n,a=new Map)=>{let o=t.approval,e=n?.approval!==!1?n?.approval:void 0,m=o?.status==="pending",c=r("div",["persona-approval-bubble","persona-w-full","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(c.id=`bubble-${t.id}`,c.setAttribute("data-message-id",t.id),c.style.backgroundColor=e?.backgroundColor??"var(--persona-approval-bg)",c.style.borderColor=e?.borderColor??"var(--persona-approval-border)",c.style.boxShadow=e?.shadow!==void 0?e.shadow.trim()===""?"none":e.shadow:"var(--persona-approval-shadow)",!o)return c;let x=r("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),g=r("div","persona-flex-shrink-0 persona-mt-0.5");g.setAttribute("data-approval-icon","true");let b=o.status==="denied"?F:o.status==="timeout"?oe:_,L=o.status==="approved"?"var(--persona-feedback-success, var(--persona-palette-colors-success-600))":o.status==="denied"?"var(--persona-feedback-error, var(--persona-palette-colors-error-600))":o.status==="timeout"?"var(--persona-feedback-warning, var(--persona-palette-colors-warning-600))":e?.titleColor??"currentColor",T=h(b,20,L,2);T&&g.appendChild(T);let v=r("div","persona-flex-1 persona-min-w-0"),f=r("div","persona-flex persona-items-center persona-gap-2"),y=r("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(e?.titleColor&&(y.style.color=e.titleColor),y.textContent=e?.title??"Approval Required",f.appendChild(y),!m){let i=r("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded-full persona-text-xs persona-font-medium");i.setAttribute("data-approval-status",o.status),o.status==="approved"?(i.style.backgroundColor="var(--persona-palette-colors-success-100)",i.style.color="var(--persona-palette-colors-success-700)",i.textContent="Approved"):o.status==="denied"?(i.style.backgroundColor="var(--persona-palette-colors-error-100)",i.style.color="var(--persona-palette-colors-error-700)",i.textContent="Denied"):o.status==="timeout"&&(i.style.backgroundColor="var(--persona-palette-colors-warning-100)",i.style.color="var(--persona-palette-colors-warning-700)",i.textContent="Timeout"),f.appendChild(i)}v.appendChild(f);let B=o.toolType==="webmcp"||o.toolName.startsWith(D)?O(o.toolName):void 0,C=e?.formatDescription?.({toolName:o.toolName,toolType:o.toolType,description:o.description,parameters:o.parameters,...B?{displayTitle:B}:{},...o.reason?{reason:o.reason}:{}}),W=!o.toolName,I=C||(W?o.description:`The assistant wants to use \u201C${B??H(o.toolName)}\u201D.`),w=r("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(w.setAttribute("data-approval-summary","true"),e?.descriptionColor&&(w.style.color=e.descriptionColor),w.textContent=I,v.appendChild(w),o.reason){let i=r("p","persona-text-sm persona-mt-1 persona-text-persona-muted");i.setAttribute("data-approval-reason","true"),e?.reasonColor?i.style.color=e.reasonColor:e?.descriptionColor&&(i.style.color=e.descriptionColor);let d=r("span","persona-font-medium");d.textContent=`${e?.reasonLabel??"Agent's stated reason:"} `,i.appendChild(d),i.appendChild(document.createTextNode(o.reason)),v.appendChild(i)}let M=e?.detailsDisplay??"collapsed",E=!!o.description&&!W,N=E||!!o.parameters;if(M!=="hidden"&&N){let i=j(t.id,a,n),d=r("button","persona-inline-flex persona-items-center persona-gap-1 persona-mt-1 persona-p-0 persona-border-none persona-bg-transparent persona-text-xs persona-font-medium persona-cursor-pointer persona-text-persona-muted");d.type="button",d.setAttribute("data-expand-header","true"),d.setAttribute("data-bubble-type","approval"),e?.descriptionColor&&(d.style.color=e.descriptionColor);let s=r("span");s.setAttribute("data-approval-details-label","true");let l=r("span","persona-inline-flex persona-items-center");l.setAttribute("data-approval-details-chevron","true"),d.append(s,l),V(d,i,n),v.appendChild(d);let p=r("div");if(p.setAttribute("data-approval-details","true"),p.style.display=i?"":"none",E){let u=r("p","persona-text-sm persona-mt-1 persona-text-persona-muted");e?.descriptionColor&&(u.style.color=e.descriptionColor),u.textContent=o.description,p.appendChild(u)}if(o.parameters){let u=r("pre","persona-mt-2 persona-text-xs persona-p-2 persona-rounded persona-overflow-x-auto persona-max-h-32 persona-bg-persona-container persona-text-persona-primary");e?.parameterBackgroundColor&&(u.style.backgroundColor=e.parameterBackgroundColor),e?.parameterTextColor&&(u.style.color=e.parameterTextColor),u.style.fontSize="0.75rem",u.style.lineHeight="1rem",u.textContent=P(o.parameters),p.appendChild(u)}v.appendChild(p)}if(m){let i=r("div","persona-flex persona-gap-2 persona-mt-2");i.setAttribute("data-approval-buttons","true");let d=r("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-border-none persona-cursor-pointer");d.type="button",d.style.backgroundColor=e?.approveButtonColor??"var(--persona-approval-approve-bg)",d.style.color=e?.approveButtonTextColor??"var(--persona-button-primary-fg)",d.setAttribute("data-approval-action","approve");let s=h(_,14,e?.approveButtonTextColor??"var(--persona-button-primary-fg)",2);s&&(s.style.marginRight="4px",d.appendChild(s));let l=document.createTextNode(e?.approveLabel??"Approve");d.appendChild(l);let p=r("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-cursor-pointer");p.type="button",p.style.backgroundColor=e?.denyButtonColor??"transparent",p.style.color=e?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",p.style.border=`1px solid ${e?.denyButtonTextColor?e.denyButtonTextColor:"var(--persona-palette-colors-error-200)"}`,p.setAttribute("data-approval-action","deny");let u=h(F,14,e?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",2);u&&(u.style.marginRight="4px",p.appendChild(u));let A=document.createTextNode(e?.denyLabel??"Deny");p.appendChild(A),i.append(d,p),v.appendChild(i)}return x.append(g,v),c.appendChild(x),c};import{Ban as ne,ChevronDown as J,ShieldCheck as re}from"lucide";var ae=()=>({keyHandlers:new Map,popovers:new Map,pendingOrder:[],latestPendingApprovalId:null}),Q=(t,n)=>{let a=t.keyHandlers.get(n);a&&(document.removeEventListener("keydown",a),t.keyHandlers.delete(n));let o=t.popovers.get(n);o&&(o.destroy(),t.popovers.delete(n))},k=(t,n)=>{Q(t,n);let a=t.pendingOrder.indexOf(n);a!==-1&&t.pendingOrder.splice(a,1),t.latestPendingApprovalId===n&&(t.latestPendingApprovalId=t.pendingOrder.length?t.pendingOrder[t.pendingOrder.length-1]:null)},se=t=>t?.approval!==!1?t?.approval:void 0,pe=(t,n,a)=>{let o=a?.detailsDisplay??"collapsed";return n.get(t)??o==="expanded"},q=t=>{let n=r("span","persona-approval-kbd");return n.textContent=t,n},le=(t,n)=>{let a=r("span","persona-approval-title");n?.titleColor&&(a.style.color=n.titleColor);let e=t.toolType==="webmcp"||t.toolName.startsWith(D)?O(t.toolName):void 0,m=n?.formatDescription?.({toolName:t.toolName,toolType:t.toolType,description:t.description??"",parameters:t.parameters,...e?{displayTitle:e}:{},...t.reason?{reason:t.reason}:{}});if(m)return a.textContent=m,a;let c=e??H(t.toolName),x=t.toolType&&t.toolType!=="webmcp"?t.toolType:null;a.append("The assistant wants to use ");let g=document.createElement("strong");if(g.textContent=c,a.appendChild(g),x){a.append(" from ");let b=document.createElement("strong");b.textContent=x,a.appendChild(b)}return a},ie=t=>{let n=r("div","persona-approval-resolved"),a=h(ne,15,"currentColor",2);a&&n.appendChild(a);let o=r("span","persona-approval-resolved-name");return o.textContent=t.toolName?H(t.toolName):"Tool",n.append(o,document.createTextNode(t.status==="timeout"?" timed out":" denied")),n},de=(t,n,a,o,e,m,c,x,g=!1)=>{let b=r("div","persona-approval-card persona-shadow-sm");b.id=`bubble-${a.id}`,b.setAttribute("data-message-id",a.id),b.setAttribute("data-bubble-type","approval"),e?.backgroundColor&&(b.style.background=e.backgroundColor),e?.borderColor&&(b.style.borderColor=e.borderColor),e?.shadow!==void 0&&(b.style.boxShadow=e.shadow.trim()===""?"none":e.shadow);let L=e?.detailsDisplay??"collapsed",T=!!o.description&&L!=="hidden",v=o.parameters!=null&&L!=="hidden"&&!g,f=T||v,y=f&&pe(a.id,n,e),U=e?.showDetailsLabel??"Show details",B=e?.hideDetailsLabel??"Hide details",C=r("button","persona-approval-head");C.type="button",f?(C.setAttribute("data-action","toggle-params"),C.setAttribute("aria-expanded",y?"true":"false"),C.setAttribute("aria-label",y?B:U)):C.setAttribute("data-static","true");let W=r("span","persona-approval-logo"),I=h(re,16,"currentColor",2);I&&W.appendChild(I),C.appendChild(W);let w=le(o,e);if(f){let s=r("span","persona-approval-toggle");s.setAttribute("aria-hidden","true");let l=h(J,14,"currentColor",2);l&&s.appendChild(l),w.append(" "),w.appendChild(s)}C.appendChild(w),b.appendChild(C);let M=r("div","persona-approval-body");if(f){let s=r("div","persona-approval-details");if(s.setAttribute("data-role","params"),s.hidden=!y,T){let l=r("p","persona-approval-desc");e?.descriptionColor&&(l.style.color=e.descriptionColor),l.textContent=o.description,s.appendChild(l)}if(v){let l=r("pre","persona-approval-params");e?.parameterBackgroundColor&&(l.style.background=e.parameterBackgroundColor),e?.parameterTextColor&&(l.style.color=e.parameterTextColor),l.textContent=P(o.parameters),s.appendChild(l)}M.appendChild(s)}if(g){let s=r("div","persona-approval-call");s.setAttribute("data-role","raw-call");let l=r("code","persona-approval-tool-name");if(l.textContent=o.toolName,s.appendChild(l),o.parameters!=null){let p=r("pre","persona-approval-params");e?.parameterBackgroundColor&&(p.style.background=e.parameterBackgroundColor),e?.parameterTextColor&&(p.style.color=e.parameterTextColor),p.textContent=P(o.parameters),s.appendChild(p)}M.appendChild(s)}if(o.reason){let s=r("p","persona-approval-reason");e?.reasonColor?s.style.color=e.reasonColor:e?.descriptionColor&&(s.style.color=e.descriptionColor);let l=r("span","persona-approval-reason-label");l.textContent=`${e?.reasonLabel??"Agent's stated reason:"} `,s.append(l,document.createTextNode(o.reason)),M.appendChild(s)}let E=r("div","persona-approval-actions"),N=null,i=s=>{e?.approveButtonColor&&(s.style.background=e.approveButtonColor),e?.approveButtonTextColor&&(s.style.color=e.approveButtonTextColor)},d=r("button","persona-approval-deny");if(d.type="button",d.setAttribute("data-action","deny"),e?.denyButtonColor&&(d.style.background=e.denyButtonColor),e?.denyButtonTextColor&&(d.style.color=e.denyButtonTextColor),d.append(e?.denyLabel??"Deny"),x){let s=r("div","persona-approval-split"),l=r("button","persona-approval-primary");l.type="button",l.setAttribute("data-action","always"),i(l),l.append(e?.approveLabel??"Always allow",q("\u23CE"));let p=r("button","persona-approval-caret");p.type="button",p.setAttribute("data-action","toggle-menu"),p.setAttribute("aria-label","More options"),i(p);let u=h(J,15,"currentColor",2);u&&p.appendChild(u),s.append(l,p),E.append(s,d),d.append(q("Esc"));let A=r("div","persona-approval-menu"),S=r("button","persona-approval-menu-item");S.type="button",S.append("Allow once",q("\u2318\u23CE")),A.appendChild(S),N=$({anchor:s,content:A,placement:"bottom-start",matchAnchorWidth:!0}),t.popovers.set(a.id,N),S.addEventListener("click",()=>{k(t,a.id),m()})}else{let s=r("button","persona-approval-primary persona-approval-primary--solo");s.type="button",s.setAttribute("data-action","allow"),i(s),s.append(e?.approveLabel??"Allow"),E.append(s,d)}return M.appendChild(E),b.appendChild(M),b.addEventListener("click",s=>{let l=s.target instanceof Element?s.target.closest("[data-action]"):null;if(!l)return;let p=l.getAttribute("data-action");if(p==="toggle-params"){let u=b.querySelector('[data-role="params"]');if(u){let A=u.hidden;u.hidden=!A,C.setAttribute("aria-expanded",A?"true":"false"),C.setAttribute("aria-label",A?B:U),n.set(a.id,A)}return}if(p==="toggle-menu"){N?.toggle();return}if(p==="always"){k(t,a.id),m({remember:!0});return}if(p==="allow"){k(t,a.id),m();return}if(p==="deny"){k(t,a.id),c();return}}),b},Y=(t=new Map)=>{let n=ae();return{plugin:{id:"persona-built-in-approval",renderApproval:({message:e,approve:m,deny:c,config:x})=>{let g=e?.approval;if(!g)return null;let b=se(x);if(g.status!=="pending"){if(k(n,e.id),g.status==="approved"){let f=document.createElement("div");return f.style.display="none",f}return ie(g)}Q(n,e.id);let L=!!x?.clientToken,T=b?.enableAlwaysAllow===!0,v=de(n,t,e,g,b,m,c,T,L);if(T){n.pendingOrder.includes(e.id)||n.pendingOrder.push(e.id),n.latestPendingApprovalId=n.pendingOrder[n.pendingOrder.length-1];let f=y=>{z(y)||e.id===n.latestPendingApprovalId&&(y.key!=="Escape"&&y.key!=="Enter"||(y.preventDefault(),y.stopImmediatePropagation(),k(n,e.id),y.key==="Escape"?c():y.metaKey||y.ctrlKey?m():m({remember:!0})))};n.keyHandlers.set(e.id,f),document.addEventListener("keydown",f)}return v}},teardown:()=>{for(let e of[...n.keyHandlers.keys(),...n.popovers.keys()])k(n,e);n.latestPendingApprovalId=null}}};export{Z as createApprovalBubble,Y as createBuiltInApprovalPlugin,H as humanizeToolName,R as initApprovalUi,G as updateApprovalDetailsUI};
|
|
1
|
+
import{a as D,g as P}from"./chunk-D4TDKCT5.js";import{b as $,c as z}from"./chunk-Q735PSZL.js";import{a as h}from"./chunk-7NQ4ZTHF.js";import{a as r}from"./chunk-76IELU7F.js";var K=()=>{},R=t=>{K=t.webMcpToolTitle},O=t=>K(t);import{ChevronDown as ee,ChevronUp as te,ShieldAlert as oe,ShieldCheck as _,ShieldX as F}from"lucide";var H=t=>{let a=(t.startsWith(D)?t.slice(D.length):t).replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[_\-\s.]+/).filter(Boolean);if(a.length===0)return t;let o=a.join(" ").toLowerCase();return o.charAt(0).toUpperCase()+o.slice(1)},X=t=>t?.approval!==!1?t?.approval:void 0,j=(t,n,a)=>{let o=X(a)?.detailsDisplay??"collapsed";return n.get(t)??o==="expanded"},V=(t,n,a)=>{let o=X(a);t.setAttribute("aria-expanded",n?"true":"false");let e=t.querySelector("[data-approval-details-label]");e&&(e.textContent=n?o?.hideDetailsLabel??"Hide details":o?.showDetailsLabel??"Show details");let m=t.querySelector("[data-approval-details-chevron]");if(m){m.innerHTML="";let c=h(n?te:ee,14,"currentColor",2);c&&m.appendChild(c)}},G=(t,n,a,o=new Map)=>{let e=n.querySelector('button[data-bubble-type="approval"]'),m=n.querySelector("[data-approval-details]");if(!e||!m)return;let c=j(t,o,a);V(e,c,a),m.style.display=c?"":"none"};var Z=(t,n,a=new Map)=>{let o=t.approval,e=n?.approval!==!1?n?.approval:void 0,m=o?.status==="pending",c=r("div",["persona-approval-bubble","persona-w-full","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(c.id=`bubble-${t.id}`,c.setAttribute("data-message-id",t.id),c.style.backgroundColor=e?.backgroundColor??"var(--persona-approval-bg)",c.style.borderColor=e?.borderColor??"var(--persona-approval-border)",c.style.boxShadow=e?.shadow!==void 0?e.shadow.trim()===""?"none":e.shadow:"var(--persona-approval-shadow)",!o)return c;let x=r("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),g=r("div","persona-flex-shrink-0 persona-mt-0.5");g.setAttribute("data-approval-icon","true");let b=o.status==="denied"?F:o.status==="timeout"?oe:_,L=o.status==="approved"?"var(--persona-feedback-success, var(--persona-palette-colors-success-600))":o.status==="denied"?"var(--persona-feedback-error, var(--persona-palette-colors-error-600))":o.status==="timeout"?"var(--persona-feedback-warning, var(--persona-palette-colors-warning-600))":e?.titleColor??"currentColor",T=h(b,20,L,2);T&&g.appendChild(T);let v=r("div","persona-flex-1 persona-min-w-0"),f=r("div","persona-flex persona-items-center persona-gap-2"),y=r("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(e?.titleColor&&(y.style.color=e.titleColor),y.textContent=e?.title??"Approval Required",f.appendChild(y),!m){let i=r("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded-full persona-text-xs persona-font-medium");i.setAttribute("data-approval-status",o.status),o.status==="approved"?(i.style.backgroundColor="var(--persona-palette-colors-success-100)",i.style.color="var(--persona-palette-colors-success-700)",i.textContent="Approved"):o.status==="denied"?(i.style.backgroundColor="var(--persona-palette-colors-error-100)",i.style.color="var(--persona-palette-colors-error-700)",i.textContent="Denied"):o.status==="timeout"&&(i.style.backgroundColor="var(--persona-palette-colors-warning-100)",i.style.color="var(--persona-palette-colors-warning-700)",i.textContent="Timeout"),f.appendChild(i)}v.appendChild(f);let B=o.toolType==="webmcp"||o.toolName.startsWith(D)?O(o.toolName):void 0,C=e?.formatDescription?.({toolName:o.toolName,toolType:o.toolType,description:o.description,parameters:o.parameters,...B?{displayTitle:B}:{},...o.reason?{reason:o.reason}:{}}),W=!o.toolName,I=C||(W?o.description:`The assistant wants to use \u201C${B??H(o.toolName)}\u201D.`),w=r("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(w.setAttribute("data-approval-summary","true"),e?.descriptionColor&&(w.style.color=e.descriptionColor),w.textContent=I,v.appendChild(w),o.reason){let i=r("p","persona-text-sm persona-mt-1 persona-text-persona-muted");i.setAttribute("data-approval-reason","true"),e?.reasonColor?i.style.color=e.reasonColor:e?.descriptionColor&&(i.style.color=e.descriptionColor);let d=r("span","persona-font-medium");d.textContent=`${e?.reasonLabel??"Agent's stated reason:"} `,i.appendChild(d),i.appendChild(document.createTextNode(o.reason)),v.appendChild(i)}let M=e?.detailsDisplay??"collapsed",E=!!o.description&&!W,N=E||!!o.parameters;if(M!=="hidden"&&N){let i=j(t.id,a,n),d=r("button","persona-inline-flex persona-items-center persona-gap-1 persona-mt-1 persona-p-0 persona-border-none persona-bg-transparent persona-text-xs persona-font-medium persona-cursor-pointer persona-text-persona-muted");d.type="button",d.setAttribute("data-expand-header","true"),d.setAttribute("data-bubble-type","approval"),e?.descriptionColor&&(d.style.color=e.descriptionColor);let s=r("span");s.setAttribute("data-approval-details-label","true");let l=r("span","persona-inline-flex persona-items-center");l.setAttribute("data-approval-details-chevron","true"),d.append(s,l),V(d,i,n),v.appendChild(d);let p=r("div");if(p.setAttribute("data-approval-details","true"),p.style.display=i?"":"none",E){let u=r("p","persona-text-sm persona-mt-1 persona-text-persona-muted");e?.descriptionColor&&(u.style.color=e.descriptionColor),u.textContent=o.description,p.appendChild(u)}if(o.parameters){let u=r("pre","persona-mt-2 persona-text-xs persona-p-2 persona-rounded persona-overflow-x-auto persona-max-h-32 persona-bg-persona-container persona-text-persona-primary");e?.parameterBackgroundColor&&(u.style.backgroundColor=e.parameterBackgroundColor),e?.parameterTextColor&&(u.style.color=e.parameterTextColor),u.style.fontSize="0.75rem",u.style.lineHeight="1rem",u.textContent=P(o.parameters),p.appendChild(u)}v.appendChild(p)}if(m){let i=r("div","persona-flex persona-gap-2 persona-mt-2");i.setAttribute("data-approval-buttons","true");let d=r("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-border-none persona-cursor-pointer");d.type="button",d.style.backgroundColor=e?.approveButtonColor??"var(--persona-approval-approve-bg)",d.style.color=e?.approveButtonTextColor??"var(--persona-button-primary-fg)",d.setAttribute("data-approval-action","approve");let s=h(_,14,e?.approveButtonTextColor??"var(--persona-button-primary-fg)",2);s&&(s.style.marginRight="4px",d.appendChild(s));let l=document.createTextNode(e?.approveLabel??"Approve");d.appendChild(l);let p=r("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-cursor-pointer");p.type="button",p.style.backgroundColor=e?.denyButtonColor??"transparent",p.style.color=e?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",p.style.border=`1px solid ${e?.denyButtonTextColor?e.denyButtonTextColor:"var(--persona-palette-colors-error-200)"}`,p.setAttribute("data-approval-action","deny");let u=h(F,14,e?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",2);u&&(u.style.marginRight="4px",p.appendChild(u));let A=document.createTextNode(e?.denyLabel??"Deny");p.appendChild(A),i.append(d,p),v.appendChild(i)}return x.append(g,v),c.appendChild(x),c};import{Ban as ne,ChevronDown as J,ShieldCheck as re}from"lucide";var ae=()=>({keyHandlers:new Map,popovers:new Map,pendingOrder:[],latestPendingApprovalId:null}),Q=(t,n)=>{let a=t.keyHandlers.get(n);a&&(document.removeEventListener("keydown",a),t.keyHandlers.delete(n));let o=t.popovers.get(n);o&&(o.destroy(),t.popovers.delete(n))},k=(t,n)=>{Q(t,n);let a=t.pendingOrder.indexOf(n);a!==-1&&t.pendingOrder.splice(a,1),t.latestPendingApprovalId===n&&(t.latestPendingApprovalId=t.pendingOrder.length?t.pendingOrder[t.pendingOrder.length-1]:null)},se=t=>t?.approval!==!1?t?.approval:void 0,pe=(t,n,a)=>{let o=a?.detailsDisplay??"collapsed";return n.get(t)??o==="expanded"},q=t=>{let n=r("span","persona-approval-kbd");return n.textContent=t,n},le=(t,n)=>{let a=r("span","persona-approval-title");n?.titleColor&&(a.style.color=n.titleColor);let e=t.toolType==="webmcp"||t.toolName.startsWith(D)?O(t.toolName):void 0,m=n?.formatDescription?.({toolName:t.toolName,toolType:t.toolType,description:t.description??"",parameters:t.parameters,...e?{displayTitle:e}:{},...t.reason?{reason:t.reason}:{}});if(m)return a.textContent=m,a;let c=e??H(t.toolName),x=t.toolType&&t.toolType!=="webmcp"?t.toolType:null;a.append("The assistant wants to use ");let g=document.createElement("strong");if(g.textContent=c,a.appendChild(g),x){a.append(" from ");let b=document.createElement("strong");b.textContent=x,a.appendChild(b)}return a},ie=t=>{let n=r("div","persona-approval-resolved"),a=h(ne,15,"currentColor",2);a&&n.appendChild(a);let o=r("span","persona-approval-resolved-name");return o.textContent=t.toolName?H(t.toolName):"Tool",n.append(o,document.createTextNode(t.status==="timeout"?" timed out":" denied")),n},de=(t,n,a,o,e,m,c,x,g=!1)=>{let b=r("div","persona-approval-card persona-shadow-sm");b.id=`bubble-${a.id}`,b.setAttribute("data-message-id",a.id),b.setAttribute("data-bubble-type","approval"),e?.backgroundColor&&(b.style.background=e.backgroundColor),e?.borderColor&&(b.style.borderColor=e.borderColor),e?.shadow!==void 0&&(b.style.boxShadow=e.shadow.trim()===""?"none":e.shadow);let L=e?.detailsDisplay??"collapsed",T=!!o.description&&L!=="hidden",v=o.parameters!=null&&L!=="hidden"&&!g,f=T||v,y=f&&pe(a.id,n,e),U=e?.showDetailsLabel??"Show details",B=e?.hideDetailsLabel??"Hide details",C=r("button","persona-approval-head");C.type="button",f?(C.setAttribute("data-action","toggle-params"),C.setAttribute("aria-expanded",y?"true":"false"),C.setAttribute("aria-label",y?B:U)):C.setAttribute("data-static","true");let W=r("span","persona-approval-logo"),I=h(re,16,"currentColor",2);I&&W.appendChild(I),C.appendChild(W);let w=le(o,e);if(f){let s=r("span","persona-approval-toggle");s.setAttribute("aria-hidden","true");let l=h(J,14,"currentColor",2);l&&s.appendChild(l),w.append(" "),w.appendChild(s)}C.appendChild(w),b.appendChild(C);let M=r("div","persona-approval-body");if(f){let s=r("div","persona-approval-details");if(s.setAttribute("data-role","params"),s.hidden=!y,T){let l=r("p","persona-approval-desc");e?.descriptionColor&&(l.style.color=e.descriptionColor),l.textContent=o.description,s.appendChild(l)}if(v){let l=r("pre","persona-approval-params");e?.parameterBackgroundColor&&(l.style.background=e.parameterBackgroundColor),e?.parameterTextColor&&(l.style.color=e.parameterTextColor),l.textContent=P(o.parameters),s.appendChild(l)}M.appendChild(s)}if(g){let s=r("div","persona-approval-call");s.setAttribute("data-role","raw-call");let l=r("code","persona-approval-tool-name");if(l.textContent=o.toolName,s.appendChild(l),o.parameters!=null){let p=r("pre","persona-approval-params");e?.parameterBackgroundColor&&(p.style.background=e.parameterBackgroundColor),e?.parameterTextColor&&(p.style.color=e.parameterTextColor),p.textContent=P(o.parameters),s.appendChild(p)}M.appendChild(s)}if(o.reason){let s=r("p","persona-approval-reason");e?.reasonColor?s.style.color=e.reasonColor:e?.descriptionColor&&(s.style.color=e.descriptionColor);let l=r("span","persona-approval-reason-label");l.textContent=`${e?.reasonLabel??"Agent's stated reason:"} `,s.append(l,document.createTextNode(o.reason)),M.appendChild(s)}let E=r("div","persona-approval-actions"),N=null,i=s=>{e?.approveButtonColor&&(s.style.background=e.approveButtonColor),e?.approveButtonTextColor&&(s.style.color=e.approveButtonTextColor)},d=r("button","persona-approval-deny");if(d.type="button",d.setAttribute("data-action","deny"),e?.denyButtonColor&&(d.style.background=e.denyButtonColor),e?.denyButtonTextColor&&(d.style.color=e.denyButtonTextColor),d.append(e?.denyLabel??"Deny"),x){let s=r("div","persona-approval-split"),l=r("button","persona-approval-primary");l.type="button",l.setAttribute("data-action","always"),i(l),l.append(e?.approveLabel??"Always allow",q("\u23CE"));let p=r("button","persona-approval-caret");p.type="button",p.setAttribute("data-action","toggle-menu"),p.setAttribute("aria-label","More options"),i(p);let u=h(J,15,"currentColor",2);u&&p.appendChild(u),s.append(l,p),E.append(s,d),d.append(q("Esc"));let A=r("div","persona-approval-menu"),S=r("button","persona-approval-menu-item");S.type="button",S.append("Allow once",q("\u2318\u23CE")),A.appendChild(S),N=$({anchor:s,content:A,placement:"bottom-start",matchAnchorWidth:!0}),t.popovers.set(a.id,N),S.addEventListener("click",()=>{k(t,a.id),m()})}else{let s=r("button","persona-approval-primary persona-approval-primary--solo");s.type="button",s.setAttribute("data-action","allow"),i(s),s.append(e?.approveLabel??"Allow"),E.append(s,d)}return M.appendChild(E),b.appendChild(M),b.addEventListener("click",s=>{let l=s.target instanceof Element?s.target.closest("[data-action]"):null;if(!l)return;let p=l.getAttribute("data-action");if(p==="toggle-params"){let u=b.querySelector('[data-role="params"]');if(u){let A=u.hidden;u.hidden=!A,C.setAttribute("aria-expanded",A?"true":"false"),C.setAttribute("aria-label",A?B:U),n.set(a.id,A)}return}if(p==="toggle-menu"){N?.toggle();return}if(p==="always"){k(t,a.id),m({remember:!0});return}if(p==="allow"){k(t,a.id),m();return}if(p==="deny"){k(t,a.id),c();return}}),b},Y=(t=new Map)=>{let n=ae();return{plugin:{id:"persona-built-in-approval",renderApproval:({message:e,approve:m,deny:c,config:x})=>{let g=e?.approval;if(!g)return null;let b=se(x);if(g.status!=="pending"){if(k(n,e.id),g.status==="approved"){let f=document.createElement("div");return f.style.display="none",f}return ie(g)}Q(n,e.id);let L=!!x?.clientToken,T=b?.enableAlwaysAllow===!0,v=de(n,t,e,g,b,m,c,T,L);if(T){n.pendingOrder.includes(e.id)||n.pendingOrder.push(e.id),n.latestPendingApprovalId=n.pendingOrder[n.pendingOrder.length-1];let f=y=>{z(y)||e.id===n.latestPendingApprovalId&&(y.key!=="Escape"&&y.key!=="Enter"||(y.preventDefault(),y.stopImmediatePropagation(),k(n,e.id),y.key==="Escape"?c():y.metaKey||y.ctrlKey?m():m({remember:!0})))};n.keyHandlers.set(e.id,f),document.addEventListener("keydown",f)}return v}},teardown:()=>{for(let e of[...n.keyHandlers.keys(),...n.popovers.keys()])k(n,e);n.latestPendingApprovalId=null}}};export{Z as createApprovalBubble,Y as createBuiltInApprovalPlugin,H as humanizeToolName,R as initApprovalUi,G as updateApprovalDetailsUI};
|
package/dist/approval-ui.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var ce=Object.create;var z=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var Ce=Object.getPrototypeOf,Se=Object.prototype.hasOwnProperty;var oe=(e,a)=>()=>(a||e((a={exports:{}}).exports,a),a.exports),ye=(e,a)=>{for(var o in a)z(e,o,{get:a[o],enumerable:!0})},fe=(e,a,o,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of he(a))!Se.call(e,r)&&r!==o&&z(e,r,{get:()=>a[r],enumerable:!(t=ge(a,r))||t.enumerable});return e};var
|
|
2
|
-
\r `.includes(e[t]);)t++};return c()},Pe=le;w.parse=Pe});var Oe={};ye(Oe,{createApprovalBubble:()=>te,createBuiltInApprovalPlugin:()=>ae,humanizeToolName:()=>E,initApprovalUi:()=>Z,updateApprovalDetailsUI:()=>ee});module.exports=be(Oe);var l=(e,a)=>{let o=document.createElement(e);return a&&(o.className=a),o};var $=Ae(se(),1);var W=e=>{if(e===null)return"null";if(e===void 0)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}};var de=()=>{},Z=e=>{de=e.webMcpToolTitle},J=e=>de(e);var Q=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M4.929 4.929 19.07 19.071"}]];var q=[["path",{d:"m6 9 6 6 6-6"}]];var Y=[["path",{d:"m18 15-6-6-6 6"}]];var j=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"M12 8v4"}],["path",{d:"M12 16h.01"}]];var U=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m9 12 2 2 4-4"}]];var G=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m14.5 9.5-5 5"}],["path",{d:"m9.5 9.5 5 5"}]];var R=(e,a=24,o="currentColor",t=2)=>{if(!Array.isArray(e))return null;let r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.setAttribute("width",String(a)),r.setAttribute("height",String(a)),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("fill","none"),r.setAttribute("stroke",o),r.setAttribute("stroke-width",String(t)),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round"),r.setAttribute("aria-hidden","true"),e.forEach(u=>{if(!Array.isArray(u)||u.length<2)return;let c=u[0],A=u[1];if(!A)return;let S=document.createElementNS("http://www.w3.org/2000/svg",c);Object.entries(A).forEach(([C,M])=>{C!=="stroke"&&S.setAttribute(C,String(M))}),r.appendChild(S)}),r};var I="webmcp:";var E=e=>{let o=(e.startsWith(I)?e.slice(I.length):e).replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[_\-\s.]+/).filter(Boolean);if(o.length===0)return e;let t=o.join(" ").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},ue=e=>e?.approval!==!1?e?.approval:void 0,ne=(e,a,o)=>{let t=ue(o)?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},pe=(e,a,o)=>{let t=ue(o);e.setAttribute("aria-expanded",a?"true":"false");let r=e.querySelector("[data-approval-details-label]");r&&(r.textContent=a?t?.hideDetailsLabel??"Hide details":t?.showDetailsLabel??"Show details");let u=e.querySelector("[data-approval-details-chevron]");if(u){u.innerHTML="";let c=R(a?Y:q,14,"currentColor",2);c&&u.appendChild(c)}},ee=(e,a,o,t=new Map)=>{let r=a.querySelector('button[data-bubble-type="approval"]'),u=a.querySelector("[data-approval-details]");if(!r||!u)return;let c=ne(e,t,o);pe(r,c,o),u.style.display=c?"":"none"};var te=(e,a,o=new Map)=>{let t=e.approval,r=a?.approval!==!1?a?.approval:void 0,u=t?.status==="pending",c=l("div",["persona-approval-bubble","persona-w-full","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(c.id=`bubble-${e.id}`,c.setAttribute("data-message-id",e.id),c.style.backgroundColor=r?.backgroundColor??"var(--persona-approval-bg)",c.style.borderColor=r?.borderColor??"var(--persona-approval-border)",c.style.boxShadow=r?.shadow!==void 0?r.shadow.trim()===""?"none":r.shadow:"var(--persona-approval-shadow)",!t)return c;let A=l("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),S=l("div","persona-flex-shrink-0 persona-mt-0.5");S.setAttribute("data-approval-icon","true");let C=t.status==="denied"?G:t.status==="timeout"?j:U,M=t.status==="approved"?"var(--persona-feedback-success, var(--persona-palette-colors-success-600))":t.status==="denied"?"var(--persona-feedback-error, var(--persona-palette-colors-error-600))":t.status==="timeout"?"var(--persona-feedback-warning, var(--persona-palette-colors-warning-600))":r?.titleColor??"currentColor",b=R(C,20,M,2);b&&S.appendChild(b);let s=l("div","persona-flex-1 persona-min-w-0"),n=l("div","persona-flex persona-items-center persona-gap-2"),g=l("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(r?.titleColor&&(g.style.color=r.titleColor),g.textContent=r?.title??"Approval Required",n.appendChild(g),!u){let p=l("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded-full persona-text-xs persona-font-medium");p.setAttribute("data-approval-status",t.status),t.status==="approved"?(p.style.backgroundColor="var(--persona-palette-colors-success-100)",p.style.color="var(--persona-palette-colors-success-700)",p.textContent="Approved"):t.status==="denied"?(p.style.backgroundColor="var(--persona-palette-colors-error-100)",p.style.color="var(--persona-palette-colors-error-700)",p.textContent="Denied"):t.status==="timeout"&&(p.style.backgroundColor="var(--persona-palette-colors-warning-100)",p.style.color="var(--persona-palette-colors-warning-700)",p.textContent="Timeout"),n.appendChild(p)}s.appendChild(n);let O=t.toolType==="webmcp"||t.toolName.startsWith(I)?J(t.toolName):void 0,m=r?.formatDescription?.({toolName:t.toolName,toolType:t.toolType,description:t.description,parameters:t.parameters,...O?{displayTitle:O}:{},...t.reason?{reason:t.reason}:{}}),k=!t.toolName,v=m||(k?t.description:`The assistant wants to use \u201C${O??E(t.toolName)}\u201D.`),P=l("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(P.setAttribute("data-approval-summary","true"),r?.descriptionColor&&(P.style.color=r.descriptionColor),P.textContent=v,s.appendChild(P),t.reason){let p=l("p","persona-text-sm persona-mt-1 persona-text-persona-muted");p.setAttribute("data-approval-reason","true"),r?.reasonColor?p.style.color=r.reasonColor:r?.descriptionColor&&(p.style.color=r.descriptionColor);let h=l("span","persona-font-medium");h.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,p.appendChild(h),p.appendChild(document.createTextNode(t.reason)),s.appendChild(p)}let L=r?.detailsDisplay??"collapsed",D=!!t.description&&!k,B=D||!!t.parameters;if(L!=="hidden"&&B){let p=ne(e.id,o,a),h=l("button","persona-inline-flex persona-items-center persona-gap-1 persona-mt-1 persona-p-0 persona-border-none persona-bg-transparent persona-text-xs persona-font-medium persona-cursor-pointer persona-text-persona-muted");h.type="button",h.setAttribute("data-expand-header","true"),h.setAttribute("data-bubble-type","approval"),r?.descriptionColor&&(h.style.color=r.descriptionColor);let d=l("span");d.setAttribute("data-approval-details-label","true");let x=l("span","persona-inline-flex persona-items-center");x.setAttribute("data-approval-details-chevron","true"),h.append(d,x),pe(h,p,a),s.appendChild(h);let i=l("div");if(i.setAttribute("data-approval-details","true"),i.style.display=p?"":"none",D){let y=l("p","persona-text-sm persona-mt-1 persona-text-persona-muted");r?.descriptionColor&&(y.style.color=r.descriptionColor),y.textContent=t.description,i.appendChild(y)}if(t.parameters){let y=l("pre","persona-mt-2 persona-text-xs persona-p-2 persona-rounded persona-overflow-x-auto persona-max-h-32 persona-bg-persona-container persona-text-persona-primary");r?.parameterBackgroundColor&&(y.style.backgroundColor=r.parameterBackgroundColor),r?.parameterTextColor&&(y.style.color=r.parameterTextColor),y.style.fontSize="0.75rem",y.style.lineHeight="1rem",y.textContent=W(t.parameters),i.appendChild(y)}s.appendChild(i)}if(u){let p=l("div","persona-flex persona-gap-2 persona-mt-2");p.setAttribute("data-approval-buttons","true");let h=l("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-border-none persona-cursor-pointer");h.type="button",h.style.backgroundColor=r?.approveButtonColor??"var(--persona-approval-approve-bg)",h.style.color=r?.approveButtonTextColor??"var(--persona-button-primary-fg)",h.setAttribute("data-approval-action","approve");let d=R(U,14,r?.approveButtonTextColor??"var(--persona-button-primary-fg)",2);d&&(d.style.marginRight="4px",h.appendChild(d));let x=document.createTextNode(r?.approveLabel??"Approve");h.appendChild(x);let i=l("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-cursor-pointer");i.type="button",i.style.backgroundColor=r?.denyButtonColor??"transparent",i.style.color=r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",i.style.border=`1px solid ${r?.denyButtonTextColor?r.denyButtonTextColor:"var(--persona-palette-colors-error-200)"}`,i.setAttribute("data-approval-action","deny");let y=R(G,14,r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",2);y&&(y.style.marginRight="4px",i.appendChild(y));let N=document.createTextNode(r?.denyLabel??"Deny");i.appendChild(N),p.append(h,i),s.appendChild(p)}return A.append(S,s),c.appendChild(A),c};function ke(e){let a=e.getRootNode?.();return a instanceof ShadowRoot?a:(e.ownerDocument??document).body}function ie(e){let{anchor:a,content:o,placement:t="bottom-start",offset:r=6,matchAnchorWidth:u=!1,horizontalOffset:c,verticalOffset:A,zIndex:S=2147483e3,onOpen:C,onDismiss:M}=e,b=e.container??ke(a),s=!1,n=null,g=()=>{if(!s)return;let m=a.getBoundingClientRect();o.style.position="fixed",u&&(o.style.minWidth=`${m.width}px`),c&&(o.style.maxWidth=`${m.width}px`);let k=o.getBoundingClientRect(),v=A?.()??null,P=v!=null?m.top+v:m.top,L=t==="top-start"||t==="top-end"?P-r-k.height:m.bottom+r,B=t==="bottom-end"||t==="top-end"?m.right-k.width:m.left,p=c?.()??null;if(p!=null){let h=Math.max(m.left,m.right-k.width);B=Math.min(Math.max(m.left+p,m.left),h)}o.style.top=`${L}px`,o.style.left=`${B}px`},F=()=>{s&&(s=!1,n&&(n(),n=null),o.remove())},O=()=>{if(s)return;s=!0,S!=null&&(o.style.zIndex=String(S)),b.appendChild(o),g();let m=(a.ownerDocument??document).defaultView??window,k=a.ownerDocument??document,v=()=>{if(!a.isConnected){F(),M?.("anchor-removed");return}g()},P=D=>{let B=typeof D.composedPath=="function"?D.composedPath():[];B.includes(o)||B.includes(a)||(F(),M?.("outside"))},L=m.setTimeout(()=>{k.addEventListener("pointerdown",P,!0)},0);m.addEventListener("scroll",v,!0),m.addEventListener("resize",v),n=()=>{m.clearTimeout(L),k.removeEventListener("pointerdown",P,!0),m.removeEventListener("scroll",v,!0),m.removeEventListener("resize",v)},C?.()};return{get isOpen(){return s},open:O,close:F,toggle:()=>s?F():O(),reposition:g,destroy:F}}function me(e){return(typeof e.composedPath=="function"?e.composedPath():[]).some(o=>o instanceof HTMLElement&&(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))}var ve=()=>({keyHandlers:new Map,popovers:new Map,pendingOrder:[],latestPendingApprovalId:null}),xe=(e,a)=>{let o=e.keyHandlers.get(a);o&&(document.removeEventListener("keydown",o),e.keyHandlers.delete(a));let t=e.popovers.get(a);t&&(t.destroy(),e.popovers.delete(a))},H=(e,a)=>{xe(e,a);let o=e.pendingOrder.indexOf(a);o!==-1&&e.pendingOrder.splice(o,1),e.latestPendingApprovalId===a&&(e.latestPendingApprovalId=e.pendingOrder.length?e.pendingOrder[e.pendingOrder.length-1]:null)},Le=e=>e?.approval!==!1?e?.approval:void 0,Be=(e,a,o)=>{let t=o?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},re=e=>{let a=l("span","persona-approval-kbd");return a.textContent=e,a},De=(e,a)=>{let o=l("span","persona-approval-title");a?.titleColor&&(o.style.color=a.titleColor);let r=e.toolType==="webmcp"||e.toolName.startsWith(I)?J(e.toolName):void 0,u=a?.formatDescription?.({toolName:e.toolName,toolType:e.toolType,description:e.description??"",parameters:e.parameters,...r?{displayTitle:r}:{},...e.reason?{reason:e.reason}:{}});if(u)return o.textContent=u,o;let c=r??E(e.toolName),A=e.toolType&&e.toolType!=="webmcp"?e.toolType:null;o.append("The assistant wants to use ");let S=document.createElement("strong");if(S.textContent=c,o.appendChild(S),A){o.append(" from ");let C=document.createElement("strong");C.textContent=A,o.appendChild(C)}return o},Re=e=>{let a=l("div","persona-approval-resolved"),o=R(Q,15,"currentColor",2);o&&a.appendChild(o);let t=l("span","persona-approval-resolved-name");return t.textContent=e.toolName?E(e.toolName):"Tool",a.append(t,document.createTextNode(e.status==="timeout"?" timed out":" denied")),a},Fe=(e,a,o,t,r,u,c,A,S=!1)=>{let C=l("div","persona-approval-card persona-shadow-sm");C.id=`bubble-${o.id}`,C.setAttribute("data-message-id",o.id),C.setAttribute("data-bubble-type","approval"),r?.backgroundColor&&(C.style.background=r.backgroundColor),r?.borderColor&&(C.style.borderColor=r.borderColor),r?.shadow!==void 0&&(C.style.boxShadow=r.shadow.trim()===""?"none":r.shadow);let M=r?.detailsDisplay??"collapsed",b=!!t.description&&M!=="hidden",s=t.parameters!=null&&M!=="hidden"&&!S,n=b||s,g=n&&Be(o.id,a,r),F=r?.showDetailsLabel??"Show details",O=r?.hideDetailsLabel??"Hide details",m=l("button","persona-approval-head");m.type="button",n?(m.setAttribute("data-action","toggle-params"),m.setAttribute("aria-expanded",g?"true":"false"),m.setAttribute("aria-label",g?O:F)):m.setAttribute("data-static","true");let k=l("span","persona-approval-logo"),v=R(U,16,"currentColor",2);v&&k.appendChild(v),m.appendChild(k);let P=De(t,r);if(n){let d=l("span","persona-approval-toggle");d.setAttribute("aria-hidden","true");let x=R(q,14,"currentColor",2);x&&d.appendChild(x),P.append(" "),P.appendChild(d)}m.appendChild(P),C.appendChild(m);let L=l("div","persona-approval-body");if(n){let d=l("div","persona-approval-details");if(d.setAttribute("data-role","params"),d.hidden=!g,b){let x=l("p","persona-approval-desc");r?.descriptionColor&&(x.style.color=r.descriptionColor),x.textContent=t.description,d.appendChild(x)}if(s){let x=l("pre","persona-approval-params");r?.parameterBackgroundColor&&(x.style.background=r.parameterBackgroundColor),r?.parameterTextColor&&(x.style.color=r.parameterTextColor),x.textContent=W(t.parameters),d.appendChild(x)}L.appendChild(d)}if(S){let d=l("div","persona-approval-call");d.setAttribute("data-role","raw-call");let x=l("code","persona-approval-tool-name");if(x.textContent=t.toolName,d.appendChild(x),t.parameters!=null){let i=l("pre","persona-approval-params");r?.parameterBackgroundColor&&(i.style.background=r.parameterBackgroundColor),r?.parameterTextColor&&(i.style.color=r.parameterTextColor),i.textContent=W(t.parameters),d.appendChild(i)}L.appendChild(d)}if(t.reason){let d=l("p","persona-approval-reason");r?.reasonColor?d.style.color=r.reasonColor:r?.descriptionColor&&(d.style.color=r.descriptionColor);let x=l("span","persona-approval-reason-label");x.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,d.append(x,document.createTextNode(t.reason)),L.appendChild(d)}let D=l("div","persona-approval-actions"),B=null,p=d=>{r?.approveButtonColor&&(d.style.background=r.approveButtonColor),r?.approveButtonTextColor&&(d.style.color=r.approveButtonTextColor)},h=l("button","persona-approval-deny");if(h.type="button",h.setAttribute("data-action","deny"),r?.denyButtonColor&&(h.style.background=r.denyButtonColor),r?.denyButtonTextColor&&(h.style.color=r.denyButtonTextColor),h.append(r?.denyLabel??"Deny"),A){let d=l("div","persona-approval-split"),x=l("button","persona-approval-primary");x.type="button",x.setAttribute("data-action","always"),p(x),x.append(r?.approveLabel??"Always allow",re("\u23CE"));let i=l("button","persona-approval-caret");i.type="button",i.setAttribute("data-action","toggle-menu"),i.setAttribute("aria-label","More options"),p(i);let y=R(q,15,"currentColor",2);y&&i.appendChild(y),d.append(x,i),D.append(d,h),h.append(re("Esc"));let N=l("div","persona-approval-menu"),V=l("button","persona-approval-menu-item");V.type="button",V.append("Allow once",re("\u2318\u23CE")),N.appendChild(V),B=ie({anchor:d,content:N,placement:"bottom-start",matchAnchorWidth:!0}),e.popovers.set(o.id,B),V.addEventListener("click",()=>{H(e,o.id),u()})}else{let d=l("button","persona-approval-primary persona-approval-primary--solo");d.type="button",d.setAttribute("data-action","allow"),p(d),d.append(r?.approveLabel??"Allow"),D.append(d,h)}return L.appendChild(D),C.appendChild(L),C.addEventListener("click",d=>{let x=d.target instanceof Element?d.target.closest("[data-action]"):null;if(!x)return;let i=x.getAttribute("data-action");if(i==="toggle-params"){let y=C.querySelector('[data-role="params"]');if(y){let N=y.hidden;y.hidden=!N,m.setAttribute("aria-expanded",N?"true":"false"),m.setAttribute("aria-label",N?O:F),a.set(o.id,N)}return}if(i==="toggle-menu"){B?.toggle();return}if(i==="always"){H(e,o.id),u({remember:!0});return}if(i==="allow"){H(e,o.id),u();return}if(i==="deny"){H(e,o.id),c();return}}),C},ae=(e=new Map)=>{let a=ve();return{plugin:{id:"persona-built-in-approval",renderApproval:({message:r,approve:u,deny:c,config:A})=>{let S=r?.approval;if(!S)return null;let C=Le(A);if(S.status!=="pending"){if(H(a,r.id),S.status==="approved"){let n=document.createElement("div");return n.style.display="none",n}return Re(S)}xe(a,r.id);let M=!!A?.clientToken,b=C?.enableAlwaysAllow===!0,s=Fe(a,e,r,S,C,u,c,b,M);if(b){a.pendingOrder.includes(r.id)||a.pendingOrder.push(r.id),a.latestPendingApprovalId=a.pendingOrder[a.pendingOrder.length-1];let n=g=>{me(g)||r.id===a.latestPendingApprovalId&&(g.key!=="Escape"&&g.key!=="Enter"||(g.preventDefault(),g.stopImmediatePropagation(),H(a,r.id),g.key==="Escape"?c():g.metaKey||g.ctrlKey?u():u({remember:!0})))};a.keyHandlers.set(r.id,n),document.addEventListener("keydown",n)}return s}},teardown:()=>{for(let r of[...a.keyHandlers.keys(),...a.popovers.keys()])H(a,r);a.latestPendingApprovalId=null}}};0&&(module.exports={createApprovalBubble,createBuiltInApprovalPlugin,humanizeToolName,initApprovalUi,updateApprovalDetailsUI});
|
|
1
|
+
"use strict";var ce=Object.create;var z=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var Ce=Object.getPrototypeOf,Se=Object.prototype.hasOwnProperty;var oe=(e,a)=>()=>(a||e((a={exports:{}}).exports,a),a.exports),ye=(e,a)=>{for(var o in a)z(e,o,{get:a[o],enumerable:!0})},fe=(e,a,o,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of he(a))!Se.call(e,r)&&r!==o&&z(e,r,{get:()=>a[r],enumerable:!(t=ge(a,r))||t.enumerable});return e};var be=(e,a,o)=>(o=e!=null?ce(Ce(e)):{},fe(a||!e||!e.__esModule?z(o,"default",{value:e,enumerable:!0}):o,e)),Ae=e=>fe(z({},"__esModule",{value:!0}),e);var K=oe(f=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0});f.Allow=f.ALL=f.COLLECTION=f.ATOM=f.SPECIAL=f.INF=f._INFINITY=f.INFINITY=f.NAN=f.BOOL=f.NULL=f.OBJ=f.ARR=f.NUM=f.STR=void 0;f.STR=1;f.NUM=2;f.ARR=4;f.OBJ=8;f.NULL=16;f.BOOL=32;f.NAN=64;f.INFINITY=128;f._INFINITY=256;f.INF=f.INFINITY|f._INFINITY;f.SPECIAL=f.NULL|f.BOOL|f.INF|f.NAN;f.ATOM=f.STR|f.NUM|f.SPECIAL;f.COLLECTION=f.ARR|f.OBJ;f.ALL=f.ATOM|f.COLLECTION;f.Allow={STR:f.STR,NUM:f.NUM,ARR:f.ARR,OBJ:f.OBJ,NULL:f.NULL,BOOL:f.BOOL,NAN:f.NAN,INFINITY:f.INFINITY,_INFINITY:f._INFINITY,INF:f.INF,SPECIAL:f.SPECIAL,ATOM:f.ATOM,COLLECTION:f.COLLECTION,ALL:f.ALL};f.default=f.Allow});var se=oe(w=>{"use strict";var we=w&&w.__createBinding||(Object.create?(function(e,a,o,t){t===void 0&&(t=o);var r=Object.getOwnPropertyDescriptor(a,o);(!r||("get"in r?!a.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return a[o]}}),Object.defineProperty(e,t,r)}):(function(e,a,o,t){t===void 0&&(t=o),e[t]=a[o]})),Te=w&&w.__exportStar||function(e,a){for(var o in e)o!=="default"&&!Object.prototype.hasOwnProperty.call(a,o)&&we(a,e,o)};Object.defineProperty(w,"__esModule",{value:!0});w.Allow=w.MalformedJSON=w.PartialJSON=w.parseJSON=w.parse=void 0;var T=K();Object.defineProperty(w,"Allow",{enumerable:!0,get:function(){return T.Allow}});Te(K(),w);var X=class extends Error{};w.PartialJSON=X;var _=class extends Error{};w.MalformedJSON=_;function le(e,a=T.Allow.ALL){if(typeof e!="string")throw new TypeError(`expecting str, got ${typeof e}`);if(!e.trim())throw new Error(`${e} is empty`);return Me(e.trim(),a)}w.parseJSON=le;var Me=(e,a)=>{let o=e.length,t=0,r=s=>{throw new X(`${s} at position ${t}`)},u=s=>{throw new _(`${s} at position ${t}`)},c=()=>(A(),t>=o&&r("Unexpected end of input"),e[t]==='"'?b():e[t]==="{"?S():e[t]==="["?C():e.substring(t,t+4)==="null"||T.Allow.NULL&a&&o-t<4&&"null".startsWith(e.substring(t))?(t+=4,null):e.substring(t,t+4)==="true"||T.Allow.BOOL&a&&o-t<4&&"true".startsWith(e.substring(t))?(t+=4,!0):e.substring(t,t+5)==="false"||T.Allow.BOOL&a&&o-t<5&&"false".startsWith(e.substring(t))?(t+=5,!1):e.substring(t,t+8)==="Infinity"||T.Allow.INFINITY&a&&o-t<8&&"Infinity".startsWith(e.substring(t))?(t+=8,1/0):e.substring(t,t+9)==="-Infinity"||T.Allow._INFINITY&a&&1<o-t&&o-t<9&&"-Infinity".startsWith(e.substring(t))?(t+=9,-1/0):e.substring(t,t+3)==="NaN"||T.Allow.NAN&a&&o-t<3&&"NaN".startsWith(e.substring(t))?(t+=3,NaN):M()),b=()=>{let s=t,n=!1;for(t++;t<o&&(e[t]!=='"'||n&&e[t-1]==="\\");)n=e[t]==="\\"?!n:!1,t++;if(e.charAt(t)=='"')try{return JSON.parse(e.substring(s,++t-Number(n)))}catch(g){u(String(g))}else if(T.Allow.STR&a)try{return JSON.parse(e.substring(s,t-Number(n))+'"')}catch{return JSON.parse(e.substring(s,e.lastIndexOf("\\"))+'"')}r("Unterminated string literal")},S=()=>{t++,A();let s={};try{for(;e[t]!=="}";){if(A(),t>=o&&T.Allow.OBJ&a)return s;let n=b();A(),t++;try{let g=c();s[n]=g}catch(g){if(T.Allow.OBJ&a)return s;throw g}A(),e[t]===","&&t++}}catch{if(T.Allow.OBJ&a)return s;r("Expected '}' at end of object")}return t++,s},C=()=>{t++;let s=[];try{for(;e[t]!=="]";)s.push(c()),A(),e[t]===","&&t++}catch{if(T.Allow.ARR&a)return s;r("Expected ']' at end of array")}return t++,s},M=()=>{if(t===0){e==="-"&&u("Not sure what '-' is");try{return JSON.parse(e)}catch(n){if(T.Allow.NUM&a)try{return JSON.parse(e.substring(0,e.lastIndexOf("e")))}catch{}u(String(n))}}let s=t;for(e[t]==="-"&&t++;e[t]&&",]}".indexOf(e[t])===-1;)t++;t==o&&!(T.Allow.NUM&a)&&r("Unterminated number literal");try{return JSON.parse(e.substring(s,t))}catch{e.substring(s,t)==="-"&&r("Not sure what '-' is");try{return JSON.parse(e.substring(s,e.lastIndexOf("e")))}catch(g){u(String(g))}}},A=()=>{for(;t<o&&`
|
|
2
|
+
\r `.includes(e[t]);)t++};return c()},Pe=le;w.parse=Pe});var Oe={};ye(Oe,{createApprovalBubble:()=>te,createBuiltInApprovalPlugin:()=>ae,humanizeToolName:()=>E,initApprovalUi:()=>Z,updateApprovalDetailsUI:()=>ee});module.exports=Ae(Oe);var l=(e,a)=>{let o=document.createElement(e);return a&&(o.className=a),o};var $=be(se(),1);var W=e=>{if(e===null)return"null";if(e===void 0)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}};var de=()=>{},Z=e=>{de=e.webMcpToolTitle},J=e=>de(e);var Q=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M4.929 4.929 19.07 19.071"}]];var q=[["path",{d:"m6 9 6 6 6-6"}]];var Y=[["path",{d:"m18 15-6-6-6 6"}]];var j=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"M12 8v4"}],["path",{d:"M12 16h.01"}]];var U=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m9 12 2 2 4-4"}]];var G=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m14.5 9.5-5 5"}],["path",{d:"m9.5 9.5 5 5"}]];var R=(e,a=24,o="currentColor",t=2)=>{if(!Array.isArray(e))return null;let r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.setAttribute("width",String(a)),r.setAttribute("height",String(a)),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("fill","none"),r.setAttribute("stroke",o),r.setAttribute("stroke-width",String(t)),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round"),r.setAttribute("aria-hidden","true"),e.forEach(u=>{if(!Array.isArray(u)||u.length<2)return;let c=u[0],b=u[1];if(!b)return;let S=document.createElementNS("http://www.w3.org/2000/svg",c);Object.entries(b).forEach(([C,M])=>{C!=="stroke"&&S.setAttribute(C,String(M))}),r.appendChild(S)}),r};var I="webmcp:";var E=e=>{let o=(e.startsWith(I)?e.slice(I.length):e).replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[_\-\s.]+/).filter(Boolean);if(o.length===0)return e;let t=o.join(" ").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},ue=e=>e?.approval!==!1?e?.approval:void 0,ne=(e,a,o)=>{let t=ue(o)?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},pe=(e,a,o)=>{let t=ue(o);e.setAttribute("aria-expanded",a?"true":"false");let r=e.querySelector("[data-approval-details-label]");r&&(r.textContent=a?t?.hideDetailsLabel??"Hide details":t?.showDetailsLabel??"Show details");let u=e.querySelector("[data-approval-details-chevron]");if(u){u.innerHTML="";let c=R(a?Y:q,14,"currentColor",2);c&&u.appendChild(c)}},ee=(e,a,o,t=new Map)=>{let r=a.querySelector('button[data-bubble-type="approval"]'),u=a.querySelector("[data-approval-details]");if(!r||!u)return;let c=ne(e,t,o);pe(r,c,o),u.style.display=c?"":"none"};var te=(e,a,o=new Map)=>{let t=e.approval,r=a?.approval!==!1?a?.approval:void 0,u=t?.status==="pending",c=l("div",["persona-approval-bubble","persona-w-full","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(c.id=`bubble-${e.id}`,c.setAttribute("data-message-id",e.id),c.style.backgroundColor=r?.backgroundColor??"var(--persona-approval-bg)",c.style.borderColor=r?.borderColor??"var(--persona-approval-border)",c.style.boxShadow=r?.shadow!==void 0?r.shadow.trim()===""?"none":r.shadow:"var(--persona-approval-shadow)",!t)return c;let b=l("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),S=l("div","persona-flex-shrink-0 persona-mt-0.5");S.setAttribute("data-approval-icon","true");let C=t.status==="denied"?G:t.status==="timeout"?j:U,M=t.status==="approved"?"var(--persona-feedback-success, var(--persona-palette-colors-success-600))":t.status==="denied"?"var(--persona-feedback-error, var(--persona-palette-colors-error-600))":t.status==="timeout"?"var(--persona-feedback-warning, var(--persona-palette-colors-warning-600))":r?.titleColor??"currentColor",A=R(C,20,M,2);A&&S.appendChild(A);let s=l("div","persona-flex-1 persona-min-w-0"),n=l("div","persona-flex persona-items-center persona-gap-2"),g=l("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(r?.titleColor&&(g.style.color=r.titleColor),g.textContent=r?.title??"Approval Required",n.appendChild(g),!u){let p=l("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded-full persona-text-xs persona-font-medium");p.setAttribute("data-approval-status",t.status),t.status==="approved"?(p.style.backgroundColor="var(--persona-palette-colors-success-100)",p.style.color="var(--persona-palette-colors-success-700)",p.textContent="Approved"):t.status==="denied"?(p.style.backgroundColor="var(--persona-palette-colors-error-100)",p.style.color="var(--persona-palette-colors-error-700)",p.textContent="Denied"):t.status==="timeout"&&(p.style.backgroundColor="var(--persona-palette-colors-warning-100)",p.style.color="var(--persona-palette-colors-warning-700)",p.textContent="Timeout"),n.appendChild(p)}s.appendChild(n);let O=t.toolType==="webmcp"||t.toolName.startsWith(I)?J(t.toolName):void 0,m=r?.formatDescription?.({toolName:t.toolName,toolType:t.toolType,description:t.description,parameters:t.parameters,...O?{displayTitle:O}:{},...t.reason?{reason:t.reason}:{}}),k=!t.toolName,v=m||(k?t.description:`The assistant wants to use \u201C${O??E(t.toolName)}\u201D.`),P=l("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(P.setAttribute("data-approval-summary","true"),r?.descriptionColor&&(P.style.color=r.descriptionColor),P.textContent=v,s.appendChild(P),t.reason){let p=l("p","persona-text-sm persona-mt-1 persona-text-persona-muted");p.setAttribute("data-approval-reason","true"),r?.reasonColor?p.style.color=r.reasonColor:r?.descriptionColor&&(p.style.color=r.descriptionColor);let h=l("span","persona-font-medium");h.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,p.appendChild(h),p.appendChild(document.createTextNode(t.reason)),s.appendChild(p)}let L=r?.detailsDisplay??"collapsed",D=!!t.description&&!k,B=D||!!t.parameters;if(L!=="hidden"&&B){let p=ne(e.id,o,a),h=l("button","persona-inline-flex persona-items-center persona-gap-1 persona-mt-1 persona-p-0 persona-border-none persona-bg-transparent persona-text-xs persona-font-medium persona-cursor-pointer persona-text-persona-muted");h.type="button",h.setAttribute("data-expand-header","true"),h.setAttribute("data-bubble-type","approval"),r?.descriptionColor&&(h.style.color=r.descriptionColor);let d=l("span");d.setAttribute("data-approval-details-label","true");let x=l("span","persona-inline-flex persona-items-center");x.setAttribute("data-approval-details-chevron","true"),h.append(d,x),pe(h,p,a),s.appendChild(h);let i=l("div");if(i.setAttribute("data-approval-details","true"),i.style.display=p?"":"none",D){let y=l("p","persona-text-sm persona-mt-1 persona-text-persona-muted");r?.descriptionColor&&(y.style.color=r.descriptionColor),y.textContent=t.description,i.appendChild(y)}if(t.parameters){let y=l("pre","persona-mt-2 persona-text-xs persona-p-2 persona-rounded persona-overflow-x-auto persona-max-h-32 persona-bg-persona-container persona-text-persona-primary");r?.parameterBackgroundColor&&(y.style.backgroundColor=r.parameterBackgroundColor),r?.parameterTextColor&&(y.style.color=r.parameterTextColor),y.style.fontSize="0.75rem",y.style.lineHeight="1rem",y.textContent=W(t.parameters),i.appendChild(y)}s.appendChild(i)}if(u){let p=l("div","persona-flex persona-gap-2 persona-mt-2");p.setAttribute("data-approval-buttons","true");let h=l("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-border-none persona-cursor-pointer");h.type="button",h.style.backgroundColor=r?.approveButtonColor??"var(--persona-approval-approve-bg)",h.style.color=r?.approveButtonTextColor??"var(--persona-button-primary-fg)",h.setAttribute("data-approval-action","approve");let d=R(U,14,r?.approveButtonTextColor??"var(--persona-button-primary-fg)",2);d&&(d.style.marginRight="4px",h.appendChild(d));let x=document.createTextNode(r?.approveLabel??"Approve");h.appendChild(x);let i=l("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-cursor-pointer");i.type="button",i.style.backgroundColor=r?.denyButtonColor??"transparent",i.style.color=r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",i.style.border=`1px solid ${r?.denyButtonTextColor?r.denyButtonTextColor:"var(--persona-palette-colors-error-200)"}`,i.setAttribute("data-approval-action","deny");let y=R(G,14,r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",2);y&&(y.style.marginRight="4px",i.appendChild(y));let N=document.createTextNode(r?.denyLabel??"Deny");i.appendChild(N),p.append(h,i),s.appendChild(p)}return b.append(S,s),c.appendChild(b),c};function ke(e){let a=e.getRootNode?.();return a instanceof ShadowRoot?a:(e.ownerDocument??document).body}function ie(e){let{anchor:a,content:o,placement:t="bottom-start",offset:r=6,matchAnchorWidth:u=!1,horizontalOffset:c,verticalOffset:b,zIndex:S=2147483e3,onOpen:C,onDismiss:M}=e,A=e.container??ke(a),s=!1,n=null,g=()=>{if(!s)return;let m=a.getBoundingClientRect();o.style.position="fixed",u&&(o.style.minWidth=`${m.width}px`),c&&(o.style.maxWidth=`${m.width}px`);let k=o.getBoundingClientRect(),v=b?.()??null,P=v!=null?m.top+v:m.top,L=t==="top-start"||t==="top-end"?P-r-k.height:m.bottom+r,B=t==="bottom-end"||t==="top-end"?m.right-k.width:m.left,p=c?.()??null;if(p!=null){let h=Math.max(m.left,m.right-k.width);B=Math.min(Math.max(m.left+p,m.left),h)}o.style.top=`${L}px`,o.style.left=`${B}px`},F=()=>{s&&(s=!1,n&&(n(),n=null),o.remove())},O=()=>{if(s)return;s=!0,S!=null&&(o.style.zIndex=String(S)),A.appendChild(o),g();let m=(a.ownerDocument??document).defaultView??window,k=a.ownerDocument??document,v=()=>{if(!a.isConnected){F(),M?.("anchor-removed");return}g()},P=D=>{let B=typeof D.composedPath=="function"?D.composedPath():[];B.includes(o)||B.includes(a)||(F(),M?.("outside"))},L=m.setTimeout(()=>{k.addEventListener("pointerdown",P,!0)},0);m.addEventListener("scroll",v,!0),m.addEventListener("resize",v),n=()=>{m.clearTimeout(L),k.removeEventListener("pointerdown",P,!0),m.removeEventListener("scroll",v,!0),m.removeEventListener("resize",v)},C?.()};return{get isOpen(){return s},open:O,close:F,toggle:()=>s?F():O(),reposition:g,destroy:F}}function me(e){return(typeof e.composedPath=="function"?e.composedPath():[]).some(o=>o instanceof HTMLElement&&(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))}var ve=()=>({keyHandlers:new Map,popovers:new Map,pendingOrder:[],latestPendingApprovalId:null}),xe=(e,a)=>{let o=e.keyHandlers.get(a);o&&(document.removeEventListener("keydown",o),e.keyHandlers.delete(a));let t=e.popovers.get(a);t&&(t.destroy(),e.popovers.delete(a))},H=(e,a)=>{xe(e,a);let o=e.pendingOrder.indexOf(a);o!==-1&&e.pendingOrder.splice(o,1),e.latestPendingApprovalId===a&&(e.latestPendingApprovalId=e.pendingOrder.length?e.pendingOrder[e.pendingOrder.length-1]:null)},Le=e=>e?.approval!==!1?e?.approval:void 0,Be=(e,a,o)=>{let t=o?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},re=e=>{let a=l("span","persona-approval-kbd");return a.textContent=e,a},De=(e,a)=>{let o=l("span","persona-approval-title");a?.titleColor&&(o.style.color=a.titleColor);let r=e.toolType==="webmcp"||e.toolName.startsWith(I)?J(e.toolName):void 0,u=a?.formatDescription?.({toolName:e.toolName,toolType:e.toolType,description:e.description??"",parameters:e.parameters,...r?{displayTitle:r}:{},...e.reason?{reason:e.reason}:{}});if(u)return o.textContent=u,o;let c=r??E(e.toolName),b=e.toolType&&e.toolType!=="webmcp"?e.toolType:null;o.append("The assistant wants to use ");let S=document.createElement("strong");if(S.textContent=c,o.appendChild(S),b){o.append(" from ");let C=document.createElement("strong");C.textContent=b,o.appendChild(C)}return o},Re=e=>{let a=l("div","persona-approval-resolved"),o=R(Q,15,"currentColor",2);o&&a.appendChild(o);let t=l("span","persona-approval-resolved-name");return t.textContent=e.toolName?E(e.toolName):"Tool",a.append(t,document.createTextNode(e.status==="timeout"?" timed out":" denied")),a},Fe=(e,a,o,t,r,u,c,b,S=!1)=>{let C=l("div","persona-approval-card persona-shadow-sm");C.id=`bubble-${o.id}`,C.setAttribute("data-message-id",o.id),C.setAttribute("data-bubble-type","approval"),r?.backgroundColor&&(C.style.background=r.backgroundColor),r?.borderColor&&(C.style.borderColor=r.borderColor),r?.shadow!==void 0&&(C.style.boxShadow=r.shadow.trim()===""?"none":r.shadow);let M=r?.detailsDisplay??"collapsed",A=!!t.description&&M!=="hidden",s=t.parameters!=null&&M!=="hidden"&&!S,n=A||s,g=n&&Be(o.id,a,r),F=r?.showDetailsLabel??"Show details",O=r?.hideDetailsLabel??"Hide details",m=l("button","persona-approval-head");m.type="button",n?(m.setAttribute("data-action","toggle-params"),m.setAttribute("aria-expanded",g?"true":"false"),m.setAttribute("aria-label",g?O:F)):m.setAttribute("data-static","true");let k=l("span","persona-approval-logo"),v=R(U,16,"currentColor",2);v&&k.appendChild(v),m.appendChild(k);let P=De(t,r);if(n){let d=l("span","persona-approval-toggle");d.setAttribute("aria-hidden","true");let x=R(q,14,"currentColor",2);x&&d.appendChild(x),P.append(" "),P.appendChild(d)}m.appendChild(P),C.appendChild(m);let L=l("div","persona-approval-body");if(n){let d=l("div","persona-approval-details");if(d.setAttribute("data-role","params"),d.hidden=!g,A){let x=l("p","persona-approval-desc");r?.descriptionColor&&(x.style.color=r.descriptionColor),x.textContent=t.description,d.appendChild(x)}if(s){let x=l("pre","persona-approval-params");r?.parameterBackgroundColor&&(x.style.background=r.parameterBackgroundColor),r?.parameterTextColor&&(x.style.color=r.parameterTextColor),x.textContent=W(t.parameters),d.appendChild(x)}L.appendChild(d)}if(S){let d=l("div","persona-approval-call");d.setAttribute("data-role","raw-call");let x=l("code","persona-approval-tool-name");if(x.textContent=t.toolName,d.appendChild(x),t.parameters!=null){let i=l("pre","persona-approval-params");r?.parameterBackgroundColor&&(i.style.background=r.parameterBackgroundColor),r?.parameterTextColor&&(i.style.color=r.parameterTextColor),i.textContent=W(t.parameters),d.appendChild(i)}L.appendChild(d)}if(t.reason){let d=l("p","persona-approval-reason");r?.reasonColor?d.style.color=r.reasonColor:r?.descriptionColor&&(d.style.color=r.descriptionColor);let x=l("span","persona-approval-reason-label");x.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,d.append(x,document.createTextNode(t.reason)),L.appendChild(d)}let D=l("div","persona-approval-actions"),B=null,p=d=>{r?.approveButtonColor&&(d.style.background=r.approveButtonColor),r?.approveButtonTextColor&&(d.style.color=r.approveButtonTextColor)},h=l("button","persona-approval-deny");if(h.type="button",h.setAttribute("data-action","deny"),r?.denyButtonColor&&(h.style.background=r.denyButtonColor),r?.denyButtonTextColor&&(h.style.color=r.denyButtonTextColor),h.append(r?.denyLabel??"Deny"),b){let d=l("div","persona-approval-split"),x=l("button","persona-approval-primary");x.type="button",x.setAttribute("data-action","always"),p(x),x.append(r?.approveLabel??"Always allow",re("\u23CE"));let i=l("button","persona-approval-caret");i.type="button",i.setAttribute("data-action","toggle-menu"),i.setAttribute("aria-label","More options"),p(i);let y=R(q,15,"currentColor",2);y&&i.appendChild(y),d.append(x,i),D.append(d,h),h.append(re("Esc"));let N=l("div","persona-approval-menu"),V=l("button","persona-approval-menu-item");V.type="button",V.append("Allow once",re("\u2318\u23CE")),N.appendChild(V),B=ie({anchor:d,content:N,placement:"bottom-start",matchAnchorWidth:!0}),e.popovers.set(o.id,B),V.addEventListener("click",()=>{H(e,o.id),u()})}else{let d=l("button","persona-approval-primary persona-approval-primary--solo");d.type="button",d.setAttribute("data-action","allow"),p(d),d.append(r?.approveLabel??"Allow"),D.append(d,h)}return L.appendChild(D),C.appendChild(L),C.addEventListener("click",d=>{let x=d.target instanceof Element?d.target.closest("[data-action]"):null;if(!x)return;let i=x.getAttribute("data-action");if(i==="toggle-params"){let y=C.querySelector('[data-role="params"]');if(y){let N=y.hidden;y.hidden=!N,m.setAttribute("aria-expanded",N?"true":"false"),m.setAttribute("aria-label",N?O:F),a.set(o.id,N)}return}if(i==="toggle-menu"){B?.toggle();return}if(i==="always"){H(e,o.id),u({remember:!0});return}if(i==="allow"){H(e,o.id),u();return}if(i==="deny"){H(e,o.id),c();return}}),C},ae=(e=new Map)=>{let a=ve();return{plugin:{id:"persona-built-in-approval",renderApproval:({message:r,approve:u,deny:c,config:b})=>{let S=r?.approval;if(!S)return null;let C=Le(b);if(S.status!=="pending"){if(H(a,r.id),S.status==="approved"){let n=document.createElement("div");return n.style.display="none",n}return Re(S)}xe(a,r.id);let M=!!b?.clientToken,A=C?.enableAlwaysAllow===!0,s=Fe(a,e,r,S,C,u,c,A,M);if(A){a.pendingOrder.includes(r.id)||a.pendingOrder.push(r.id),a.latestPendingApprovalId=a.pendingOrder[a.pendingOrder.length-1];let n=g=>{me(g)||r.id===a.latestPendingApprovalId&&(g.key!=="Escape"&&g.key!=="Enter"||(g.preventDefault(),g.stopImmediatePropagation(),H(a,r.id),g.key==="Escape"?c():g.metaKey||g.ctrlKey?u():u({remember:!0})))};a.keyHandlers.set(r.id,n),document.addEventListener("keydown",n)}return s}},teardown:()=>{for(let r of[...a.keyHandlers.keys(),...a.popovers.keys()])H(a,r);a.latestPendingApprovalId=null}}};0&&(module.exports={createApprovalBubble,createBuiltInApprovalPlugin,humanizeToolName,initApprovalUi,updateApprovalDetailsUI});
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
lucide/dist/esm/icons/ban.mjs:
|
package/dist/approval-ui.d.cts
CHANGED
|
@@ -3214,9 +3214,8 @@ type WebMcpConfirmInfo = {
|
|
|
3214
3214
|
};
|
|
3215
3215
|
/**
|
|
3216
3216
|
* Why the confirm was requested. Currently always `'gate'`: the default
|
|
3217
|
-
* confirm-by-default gate that fires before every `webmcp:*` call.
|
|
3218
|
-
*
|
|
3219
|
-
* internally, so Persona no longer surfaces a nested in-tool confirm.)
|
|
3217
|
+
* confirm-by-default gate that fires before every `webmcp:*` call. Tool
|
|
3218
|
+
* callbacks on v6 receive an AbortSignal, not a nested confirmation API.
|
|
3220
3219
|
*/
|
|
3221
3220
|
reason: 'gate';
|
|
3222
3221
|
};
|
|
@@ -9287,8 +9286,11 @@ type AgentWidgetConfig = {
|
|
|
9287
9286
|
/**
|
|
9288
9287
|
* WebMCP: consume page-registered tools (`document.modelContext.registerTool`).
|
|
9289
9288
|
* When `enabled`, the widget installs `@mcp-b/webmcp-polyfill`, snapshots the
|
|
9290
|
-
* registry on every dispatch, ships it as `clientTools[]`,
|
|
9291
|
-
* returned `webmcp:*`
|
|
9289
|
+
* current document's registry on every dispatch, ships it as `clientTools[]`,
|
|
9290
|
+
* and executes returned `webmcp:*` calls with confirm-by-default gating.
|
|
9291
|
+
* Supports host-installed v5 JSON-string and v6 object-input contracts.
|
|
9292
|
+
* The automatic fallback stays on v5 to preserve existing browser support
|
|
9293
|
+
* and callback-result behavior.
|
|
9292
9294
|
*
|
|
9293
9295
|
* Server-side policy on the chat surface is the source of truth: these
|
|
9294
9296
|
* fields layer on top.
|
package/dist/approval-ui.d.ts
CHANGED
|
@@ -3214,9 +3214,8 @@ type WebMcpConfirmInfo = {
|
|
|
3214
3214
|
};
|
|
3215
3215
|
/**
|
|
3216
3216
|
* Why the confirm was requested. Currently always `'gate'`: the default
|
|
3217
|
-
* confirm-by-default gate that fires before every `webmcp:*` call.
|
|
3218
|
-
*
|
|
3219
|
-
* internally, so Persona no longer surfaces a nested in-tool confirm.)
|
|
3217
|
+
* confirm-by-default gate that fires before every `webmcp:*` call. Tool
|
|
3218
|
+
* callbacks on v6 receive an AbortSignal, not a nested confirmation API.
|
|
3220
3219
|
*/
|
|
3221
3220
|
reason: 'gate';
|
|
3222
3221
|
};
|
|
@@ -9287,8 +9286,11 @@ type AgentWidgetConfig = {
|
|
|
9287
9286
|
/**
|
|
9288
9287
|
* WebMCP: consume page-registered tools (`document.modelContext.registerTool`).
|
|
9289
9288
|
* When `enabled`, the widget installs `@mcp-b/webmcp-polyfill`, snapshots the
|
|
9290
|
-
* registry on every dispatch, ships it as `clientTools[]`,
|
|
9291
|
-
* returned `webmcp:*`
|
|
9289
|
+
* current document's registry on every dispatch, ships it as `clientTools[]`,
|
|
9290
|
+
* and executes returned `webmcp:*` calls with confirm-by-default gating.
|
|
9291
|
+
* Supports host-installed v5 JSON-string and v6 object-input contracts.
|
|
9292
|
+
* The automatic fallback stays on v5 to preserve existing browser support
|
|
9293
|
+
* and callback-result behavior.
|
|
9292
9294
|
*
|
|
9293
9295
|
* Server-side policy on the chat surface is the source of truth: these
|
|
9294
9296
|
* fields layer on top.
|
package/dist/approval-ui.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var xe=Object.create;var j=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var ee=(e,a)=>()=>(a||e((a={exports:{}}).exports,a),a.exports);var Se=(e,a,o,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of ge(a))!Ce.call(e,r)&&r!==o&&j(e,r,{get:()=>a[r],enumerable:!(t=ce(a,r))||t.enumerable});return e};var ye=(e,a,o)=>(o=e!=null?xe(he(e)):{},Se(a||!e||!e.__esModule?j(o,"default",{value:e,enumerable:!0}):o,e));var J=ee(f=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0});f.Allow=f.ALL=f.COLLECTION=f.ATOM=f.SPECIAL=f.INF=f._INFINITY=f.INFINITY=f.NAN=f.BOOL=f.NULL=f.OBJ=f.ARR=f.NUM=f.STR=void 0;f.STR=1;f.NUM=2;f.ARR=4;f.OBJ=8;f.NULL=16;f.BOOL=32;f.NAN=64;f.INFINITY=128;f._INFINITY=256;f.INF=f.INFINITY|f._INFINITY;f.SPECIAL=f.NULL|f.BOOL|f.INF|f.NAN;f.ATOM=f.STR|f.NUM|f.SPECIAL;f.COLLECTION=f.ARR|f.OBJ;f.ALL=f.ATOM|f.COLLECTION;f.Allow={STR:f.STR,NUM:f.NUM,ARR:f.ARR,OBJ:f.OBJ,NULL:f.NULL,BOOL:f.BOOL,NAN:f.NAN,INFINITY:f.INFINITY,_INFINITY:f._INFINITY,INF:f.INF,SPECIAL:f.SPECIAL,ATOM:f.ATOM,COLLECTION:f.COLLECTION,ALL:f.ALL};f.default=f.Allow});var re=ee(w=>{"use strict";var
|
|
2
|
-
\r `.includes(e[t]);)t++};return c()},Te=te;w.parse=Te});var l=(e,a)=>{let o=document.createElement(e);return a&&(o.className=a),o};var K=ye(re(),1);var W=e=>{if(e===null)return"null";if(e===void 0)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}};var ae=()=>{},oe=e=>{ae=e.webMcpToolTitle},_=e=>ae(e);var $=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M4.929 4.929 19.07 19.071"}]];var H=[["path",{d:"m6 9 6 6 6-6"}]];var Z=[["path",{d:"m18 15-6-6-6 6"}]];var Q=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"M12 8v4"}],["path",{d:"M12 16h.01"}]];var q=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m9 12 2 2 4-4"}]];var G=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m14.5 9.5-5 5"}],["path",{d:"m9.5 9.5 5 5"}]];var R=(e,a=24,o="currentColor",t=2)=>{if(!Array.isArray(e))return null;let r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.setAttribute("width",String(a)),r.setAttribute("height",String(a)),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("fill","none"),r.setAttribute("stroke",o),r.setAttribute("stroke-width",String(t)),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round"),r.setAttribute("aria-hidden","true"),e.forEach(u=>{if(!Array.isArray(u)||u.length<2)return;let c=u[0],A=u[1];if(!A)return;let S=document.createElementNS("http://www.w3.org/2000/svg",c);Object.entries(A).forEach(([C,M])=>{C!=="stroke"&&S.setAttribute(C,String(M))}),r.appendChild(S)}),r};var U="webmcp:";var I=e=>{let o=(e.startsWith(U)?e.slice(U.length):e).replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[_\-\s.]+/).filter(Boolean);if(o.length===0)return e;let t=o.join(" ").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},fe=e=>e?.approval!==!1?e?.approval:void 0,le=(e,a,o)=>{let t=fe(o)?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},se=(e,a,o)=>{let t=fe(o);e.setAttribute("aria-expanded",a?"true":"false");let r=e.querySelector("[data-approval-details-label]");r&&(r.textContent=a?t?.hideDetailsLabel??"Hide details":t?.showDetailsLabel??"Show details");let u=e.querySelector("[data-approval-details-chevron]");if(u){u.innerHTML="";let c=R(a?Z:H,14,"currentColor",2);c&&u.appendChild(c)}},de=(e,a,o,t=new Map)=>{let r=a.querySelector('button[data-bubble-type="approval"]'),u=a.querySelector("[data-approval-details]");if(!r||!u)return;let c=le(e,t,o);se(r,c,o),u.style.display=c?"":"none"};var ue=(e,a,o=new Map)=>{let t=e.approval,r=a?.approval!==!1?a?.approval:void 0,u=t?.status==="pending",c=l("div",["persona-approval-bubble","persona-w-full","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(c.id=`bubble-${e.id}`,c.setAttribute("data-message-id",e.id),c.style.backgroundColor=r?.backgroundColor??"var(--persona-approval-bg)",c.style.borderColor=r?.borderColor??"var(--persona-approval-border)",c.style.boxShadow=r?.shadow!==void 0?r.shadow.trim()===""?"none":r.shadow:"var(--persona-approval-shadow)",!t)return c;let A=l("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),S=l("div","persona-flex-shrink-0 persona-mt-0.5");S.setAttribute("data-approval-icon","true");let C=t.status==="denied"?G:t.status==="timeout"?Q:q,M=t.status==="approved"?"var(--persona-feedback-success, var(--persona-palette-colors-success-600))":t.status==="denied"?"var(--persona-feedback-error, var(--persona-palette-colors-error-600))":t.status==="timeout"?"var(--persona-feedback-warning, var(--persona-palette-colors-warning-600))":r?.titleColor??"currentColor",b=R(C,20,M,2);b&&S.appendChild(b);let s=l("div","persona-flex-1 persona-min-w-0"),n=l("div","persona-flex persona-items-center persona-gap-2"),g=l("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(r?.titleColor&&(g.style.color=r.titleColor),g.textContent=r?.title??"Approval Required",n.appendChild(g),!u){let p=l("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded-full persona-text-xs persona-font-medium");p.setAttribute("data-approval-status",t.status),t.status==="approved"?(p.style.backgroundColor="var(--persona-palette-colors-success-100)",p.style.color="var(--persona-palette-colors-success-700)",p.textContent="Approved"):t.status==="denied"?(p.style.backgroundColor="var(--persona-palette-colors-error-100)",p.style.color="var(--persona-palette-colors-error-700)",p.textContent="Denied"):t.status==="timeout"&&(p.style.backgroundColor="var(--persona-palette-colors-warning-100)",p.style.color="var(--persona-palette-colors-warning-700)",p.textContent="Timeout"),n.appendChild(p)}s.appendChild(n);let O=t.toolType==="webmcp"||t.toolName.startsWith(U)?_(t.toolName):void 0,m=r?.formatDescription?.({toolName:t.toolName,toolType:t.toolType,description:t.description,parameters:t.parameters,...O?{displayTitle:O}:{},...t.reason?{reason:t.reason}:{}}),k=!t.toolName,v=m||(k?t.description:`The assistant wants to use \u201C${O??I(t.toolName)}\u201D.`),P=l("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(P.setAttribute("data-approval-summary","true"),r?.descriptionColor&&(P.style.color=r.descriptionColor),P.textContent=v,s.appendChild(P),t.reason){let p=l("p","persona-text-sm persona-mt-1 persona-text-persona-muted");p.setAttribute("data-approval-reason","true"),r?.reasonColor?p.style.color=r.reasonColor:r?.descriptionColor&&(p.style.color=r.descriptionColor);let h=l("span","persona-font-medium");h.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,p.appendChild(h),p.appendChild(document.createTextNode(t.reason)),s.appendChild(p)}let L=r?.detailsDisplay??"collapsed",D=!!t.description&&!k,B=D||!!t.parameters;if(L!=="hidden"&&B){let p=le(e.id,o,a),h=l("button","persona-inline-flex persona-items-center persona-gap-1 persona-mt-1 persona-p-0 persona-border-none persona-bg-transparent persona-text-xs persona-font-medium persona-cursor-pointer persona-text-persona-muted");h.type="button",h.setAttribute("data-expand-header","true"),h.setAttribute("data-bubble-type","approval"),r?.descriptionColor&&(h.style.color=r.descriptionColor);let d=l("span");d.setAttribute("data-approval-details-label","true");let x=l("span","persona-inline-flex persona-items-center");x.setAttribute("data-approval-details-chevron","true"),h.append(d,x),se(h,p,a),s.appendChild(h);let i=l("div");if(i.setAttribute("data-approval-details","true"),i.style.display=p?"":"none",D){let y=l("p","persona-text-sm persona-mt-1 persona-text-persona-muted");r?.descriptionColor&&(y.style.color=r.descriptionColor),y.textContent=t.description,i.appendChild(y)}if(t.parameters){let y=l("pre","persona-mt-2 persona-text-xs persona-p-2 persona-rounded persona-overflow-x-auto persona-max-h-32 persona-bg-persona-container persona-text-persona-primary");r?.parameterBackgroundColor&&(y.style.backgroundColor=r.parameterBackgroundColor),r?.parameterTextColor&&(y.style.color=r.parameterTextColor),y.style.fontSize="0.75rem",y.style.lineHeight="1rem",y.textContent=W(t.parameters),i.appendChild(y)}s.appendChild(i)}if(u){let p=l("div","persona-flex persona-gap-2 persona-mt-2");p.setAttribute("data-approval-buttons","true");let h=l("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-border-none persona-cursor-pointer");h.type="button",h.style.backgroundColor=r?.approveButtonColor??"var(--persona-approval-approve-bg)",h.style.color=r?.approveButtonTextColor??"var(--persona-button-primary-fg)",h.setAttribute("data-approval-action","approve");let d=R(q,14,r?.approveButtonTextColor??"var(--persona-button-primary-fg)",2);d&&(d.style.marginRight="4px",h.appendChild(d));let x=document.createTextNode(r?.approveLabel??"Approve");h.appendChild(x);let i=l("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-cursor-pointer");i.type="button",i.style.backgroundColor=r?.denyButtonColor??"transparent",i.style.color=r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",i.style.border=`1px solid ${r?.denyButtonTextColor?r.denyButtonTextColor:"var(--persona-palette-colors-error-200)"}`,i.setAttribute("data-approval-action","deny");let y=R(G,14,r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",2);y&&(y.style.marginRight="4px",i.appendChild(y));let N=document.createTextNode(r?.denyLabel??"Deny");i.appendChild(N),p.append(h,i),s.appendChild(p)}return A.append(S,s),c.appendChild(A),c};function Me(e){let a=e.getRootNode?.();return a instanceof ShadowRoot?a:(e.ownerDocument??document).body}function ne(e){let{anchor:a,content:o,placement:t="bottom-start",offset:r=6,matchAnchorWidth:u=!1,horizontalOffset:c,verticalOffset:A,zIndex:S=2147483e3,onOpen:C,onDismiss:M}=e,b=e.container??Me(a),s=!1,n=null,g=()=>{if(!s)return;let m=a.getBoundingClientRect();o.style.position="fixed",u&&(o.style.minWidth=`${m.width}px`),c&&(o.style.maxWidth=`${m.width}px`);let k=o.getBoundingClientRect(),v=A?.()??null,P=v!=null?m.top+v:m.top,L=t==="top-start"||t==="top-end"?P-r-k.height:m.bottom+r,B=t==="bottom-end"||t==="top-end"?m.right-k.width:m.left,p=c?.()??null;if(p!=null){let h=Math.max(m.left,m.right-k.width);B=Math.min(Math.max(m.left+p,m.left),h)}o.style.top=`${L}px`,o.style.left=`${B}px`},F=()=>{s&&(s=!1,n&&(n(),n=null),o.remove())},O=()=>{if(s)return;s=!0,S!=null&&(o.style.zIndex=String(S)),b.appendChild(o),g();let m=(a.ownerDocument??document).defaultView??window,k=a.ownerDocument??document,v=()=>{if(!a.isConnected){F(),M?.("anchor-removed");return}g()},P=D=>{let B=typeof D.composedPath=="function"?D.composedPath():[];B.includes(o)||B.includes(a)||(F(),M?.("outside"))},L=m.setTimeout(()=>{k.addEventListener("pointerdown",P,!0)},0);m.addEventListener("scroll",v,!0),m.addEventListener("resize",v),n=()=>{m.clearTimeout(L),k.removeEventListener("pointerdown",P,!0),m.removeEventListener("scroll",v,!0),m.removeEventListener("resize",v)},C?.()};return{get isOpen(){return s},open:O,close:F,toggle:()=>s?F():O(),reposition:g,destroy:F}}function pe(e){return(typeof e.composedPath=="function"?e.composedPath():[]).some(o=>o instanceof HTMLElement&&(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))}var Pe=()=>({keyHandlers:new Map,popovers:new Map,pendingOrder:[],latestPendingApprovalId:null}),ie=(e,a)=>{let o=e.keyHandlers.get(a);o&&(document.removeEventListener("keydown",o),e.keyHandlers.delete(a));let t=e.popovers.get(a);t&&(t.destroy(),e.popovers.delete(a))},E=(e,a)=>{ie(e,a);let o=e.pendingOrder.indexOf(a);o!==-1&&e.pendingOrder.splice(o,1),e.latestPendingApprovalId===a&&(e.latestPendingApprovalId=e.pendingOrder.length?e.pendingOrder[e.pendingOrder.length-1]:null)},ke=e=>e?.approval!==!1?e?.approval:void 0,ve=(e,a,o)=>{let t=o?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},Y=e=>{let a=l("span","persona-approval-kbd");return a.textContent=e,a},Le=(e,a)=>{let o=l("span","persona-approval-title");a?.titleColor&&(o.style.color=a.titleColor);let r=e.toolType==="webmcp"||e.toolName.startsWith(U)?_(e.toolName):void 0,u=a?.formatDescription?.({toolName:e.toolName,toolType:e.toolType,description:e.description??"",parameters:e.parameters,...r?{displayTitle:r}:{},...e.reason?{reason:e.reason}:{}});if(u)return o.textContent=u,o;let c=r??I(e.toolName),A=e.toolType&&e.toolType!=="webmcp"?e.toolType:null;o.append("The assistant wants to use ");let S=document.createElement("strong");if(S.textContent=c,o.appendChild(S),A){o.append(" from ");let C=document.createElement("strong");C.textContent=A,o.appendChild(C)}return o},Be=e=>{let a=l("div","persona-approval-resolved"),o=R($,15,"currentColor",2);o&&a.appendChild(o);let t=l("span","persona-approval-resolved-name");return t.textContent=e.toolName?I(e.toolName):"Tool",a.append(t,document.createTextNode(e.status==="timeout"?" timed out":" denied")),a},De=(e,a,o,t,r,u,c,A,S=!1)=>{let C=l("div","persona-approval-card persona-shadow-sm");C.id=`bubble-${o.id}`,C.setAttribute("data-message-id",o.id),C.setAttribute("data-bubble-type","approval"),r?.backgroundColor&&(C.style.background=r.backgroundColor),r?.borderColor&&(C.style.borderColor=r.borderColor),r?.shadow!==void 0&&(C.style.boxShadow=r.shadow.trim()===""?"none":r.shadow);let M=r?.detailsDisplay??"collapsed",b=!!t.description&&M!=="hidden",s=t.parameters!=null&&M!=="hidden"&&!S,n=b||s,g=n&&ve(o.id,a,r),F=r?.showDetailsLabel??"Show details",O=r?.hideDetailsLabel??"Hide details",m=l("button","persona-approval-head");m.type="button",n?(m.setAttribute("data-action","toggle-params"),m.setAttribute("aria-expanded",g?"true":"false"),m.setAttribute("aria-label",g?O:F)):m.setAttribute("data-static","true");let k=l("span","persona-approval-logo"),v=R(q,16,"currentColor",2);v&&k.appendChild(v),m.appendChild(k);let P=Le(t,r);if(n){let d=l("span","persona-approval-toggle");d.setAttribute("aria-hidden","true");let x=R(H,14,"currentColor",2);x&&d.appendChild(x),P.append(" "),P.appendChild(d)}m.appendChild(P),C.appendChild(m);let L=l("div","persona-approval-body");if(n){let d=l("div","persona-approval-details");if(d.setAttribute("data-role","params"),d.hidden=!g,b){let x=l("p","persona-approval-desc");r?.descriptionColor&&(x.style.color=r.descriptionColor),x.textContent=t.description,d.appendChild(x)}if(s){let x=l("pre","persona-approval-params");r?.parameterBackgroundColor&&(x.style.background=r.parameterBackgroundColor),r?.parameterTextColor&&(x.style.color=r.parameterTextColor),x.textContent=W(t.parameters),d.appendChild(x)}L.appendChild(d)}if(S){let d=l("div","persona-approval-call");d.setAttribute("data-role","raw-call");let x=l("code","persona-approval-tool-name");if(x.textContent=t.toolName,d.appendChild(x),t.parameters!=null){let i=l("pre","persona-approval-params");r?.parameterBackgroundColor&&(i.style.background=r.parameterBackgroundColor),r?.parameterTextColor&&(i.style.color=r.parameterTextColor),i.textContent=W(t.parameters),d.appendChild(i)}L.appendChild(d)}if(t.reason){let d=l("p","persona-approval-reason");r?.reasonColor?d.style.color=r.reasonColor:r?.descriptionColor&&(d.style.color=r.descriptionColor);let x=l("span","persona-approval-reason-label");x.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,d.append(x,document.createTextNode(t.reason)),L.appendChild(d)}let D=l("div","persona-approval-actions"),B=null,p=d=>{r?.approveButtonColor&&(d.style.background=r.approveButtonColor),r?.approveButtonTextColor&&(d.style.color=r.approveButtonTextColor)},h=l("button","persona-approval-deny");if(h.type="button",h.setAttribute("data-action","deny"),r?.denyButtonColor&&(h.style.background=r.denyButtonColor),r?.denyButtonTextColor&&(h.style.color=r.denyButtonTextColor),h.append(r?.denyLabel??"Deny"),A){let d=l("div","persona-approval-split"),x=l("button","persona-approval-primary");x.type="button",x.setAttribute("data-action","always"),p(x),x.append(r?.approveLabel??"Always allow",Y("\u23CE"));let i=l("button","persona-approval-caret");i.type="button",i.setAttribute("data-action","toggle-menu"),i.setAttribute("aria-label","More options"),p(i);let y=R(H,15,"currentColor",2);y&&i.appendChild(y),d.append(x,i),D.append(d,h),h.append(Y("Esc"));let N=l("div","persona-approval-menu"),V=l("button","persona-approval-menu-item");V.type="button",V.append("Allow once",Y("\u2318\u23CE")),N.appendChild(V),B=ne({anchor:d,content:N,placement:"bottom-start",matchAnchorWidth:!0}),e.popovers.set(o.id,B),V.addEventListener("click",()=>{E(e,o.id),u()})}else{let d=l("button","persona-approval-primary persona-approval-primary--solo");d.type="button",d.setAttribute("data-action","allow"),p(d),d.append(r?.approveLabel??"Allow"),D.append(d,h)}return L.appendChild(D),C.appendChild(L),C.addEventListener("click",d=>{let x=d.target instanceof Element?d.target.closest("[data-action]"):null;if(!x)return;let i=x.getAttribute("data-action");if(i==="toggle-params"){let y=C.querySelector('[data-role="params"]');if(y){let N=y.hidden;y.hidden=!N,m.setAttribute("aria-expanded",N?"true":"false"),m.setAttribute("aria-label",N?O:F),a.set(o.id,N)}return}if(i==="toggle-menu"){B?.toggle();return}if(i==="always"){E(e,o.id),u({remember:!0});return}if(i==="allow"){E(e,o.id),u();return}if(i==="deny"){E(e,o.id),c();return}}),C},me=(e=new Map)=>{let a=Pe();return{plugin:{id:"persona-built-in-approval",renderApproval:({message:r,approve:u,deny:c,config:A})=>{let S=r?.approval;if(!S)return null;let C=ke(A);if(S.status!=="pending"){if(E(a,r.id),S.status==="approved"){let n=document.createElement("div");return n.style.display="none",n}return Be(S)}ie(a,r.id);let M=!!A?.clientToken,b=C?.enableAlwaysAllow===!0,s=De(a,e,r,S,C,u,c,b,M);if(b){a.pendingOrder.includes(r.id)||a.pendingOrder.push(r.id),a.latestPendingApprovalId=a.pendingOrder[a.pendingOrder.length-1];let n=g=>{pe(g)||r.id===a.latestPendingApprovalId&&(g.key!=="Escape"&&g.key!=="Enter"||(g.preventDefault(),g.stopImmediatePropagation(),E(a,r.id),g.key==="Escape"?c():g.metaKey||g.ctrlKey?u():u({remember:!0})))};a.keyHandlers.set(r.id,n),document.addEventListener("keydown",n)}return s}},teardown:()=>{for(let r of[...a.keyHandlers.keys(),...a.popovers.keys()])E(a,r);a.latestPendingApprovalId=null}}};export{ue as createApprovalBubble,me as createBuiltInApprovalPlugin,I as humanizeToolName,oe as initApprovalUi,de as updateApprovalDetailsUI};
|
|
1
|
+
var xe=Object.create;var j=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var ee=(e,a)=>()=>(a||e((a={exports:{}}).exports,a),a.exports);var Se=(e,a,o,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of ge(a))!Ce.call(e,r)&&r!==o&&j(e,r,{get:()=>a[r],enumerable:!(t=ce(a,r))||t.enumerable});return e};var ye=(e,a,o)=>(o=e!=null?xe(he(e)):{},Se(a||!e||!e.__esModule?j(o,"default",{value:e,enumerable:!0}):o,e));var J=ee(f=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0});f.Allow=f.ALL=f.COLLECTION=f.ATOM=f.SPECIAL=f.INF=f._INFINITY=f.INFINITY=f.NAN=f.BOOL=f.NULL=f.OBJ=f.ARR=f.NUM=f.STR=void 0;f.STR=1;f.NUM=2;f.ARR=4;f.OBJ=8;f.NULL=16;f.BOOL=32;f.NAN=64;f.INFINITY=128;f._INFINITY=256;f.INF=f.INFINITY|f._INFINITY;f.SPECIAL=f.NULL|f.BOOL|f.INF|f.NAN;f.ATOM=f.STR|f.NUM|f.SPECIAL;f.COLLECTION=f.ARR|f.OBJ;f.ALL=f.ATOM|f.COLLECTION;f.Allow={STR:f.STR,NUM:f.NUM,ARR:f.ARR,OBJ:f.OBJ,NULL:f.NULL,BOOL:f.BOOL,NAN:f.NAN,INFINITY:f.INFINITY,_INFINITY:f._INFINITY,INF:f.INF,SPECIAL:f.SPECIAL,ATOM:f.ATOM,COLLECTION:f.COLLECTION,ALL:f.ALL};f.default=f.Allow});var re=ee(w=>{"use strict";var be=w&&w.__createBinding||(Object.create?(function(e,a,o,t){t===void 0&&(t=o);var r=Object.getOwnPropertyDescriptor(a,o);(!r||("get"in r?!a.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return a[o]}}),Object.defineProperty(e,t,r)}):(function(e,a,o,t){t===void 0&&(t=o),e[t]=a[o]})),Ae=w&&w.__exportStar||function(e,a){for(var o in e)o!=="default"&&!Object.prototype.hasOwnProperty.call(a,o)&&be(a,e,o)};Object.defineProperty(w,"__esModule",{value:!0});w.Allow=w.MalformedJSON=w.PartialJSON=w.parseJSON=w.parse=void 0;var T=J();Object.defineProperty(w,"Allow",{enumerable:!0,get:function(){return T.Allow}});Ae(J(),w);var z=class extends Error{};w.PartialJSON=z;var X=class extends Error{};w.MalformedJSON=X;function te(e,a=T.Allow.ALL){if(typeof e!="string")throw new TypeError(`expecting str, got ${typeof e}`);if(!e.trim())throw new Error(`${e} is empty`);return we(e.trim(),a)}w.parseJSON=te;var we=(e,a)=>{let o=e.length,t=0,r=s=>{throw new z(`${s} at position ${t}`)},u=s=>{throw new X(`${s} at position ${t}`)},c=()=>(A(),t>=o&&r("Unexpected end of input"),e[t]==='"'?b():e[t]==="{"?S():e[t]==="["?C():e.substring(t,t+4)==="null"||T.Allow.NULL&a&&o-t<4&&"null".startsWith(e.substring(t))?(t+=4,null):e.substring(t,t+4)==="true"||T.Allow.BOOL&a&&o-t<4&&"true".startsWith(e.substring(t))?(t+=4,!0):e.substring(t,t+5)==="false"||T.Allow.BOOL&a&&o-t<5&&"false".startsWith(e.substring(t))?(t+=5,!1):e.substring(t,t+8)==="Infinity"||T.Allow.INFINITY&a&&o-t<8&&"Infinity".startsWith(e.substring(t))?(t+=8,1/0):e.substring(t,t+9)==="-Infinity"||T.Allow._INFINITY&a&&1<o-t&&o-t<9&&"-Infinity".startsWith(e.substring(t))?(t+=9,-1/0):e.substring(t,t+3)==="NaN"||T.Allow.NAN&a&&o-t<3&&"NaN".startsWith(e.substring(t))?(t+=3,NaN):M()),b=()=>{let s=t,n=!1;for(t++;t<o&&(e[t]!=='"'||n&&e[t-1]==="\\");)n=e[t]==="\\"?!n:!1,t++;if(e.charAt(t)=='"')try{return JSON.parse(e.substring(s,++t-Number(n)))}catch(g){u(String(g))}else if(T.Allow.STR&a)try{return JSON.parse(e.substring(s,t-Number(n))+'"')}catch{return JSON.parse(e.substring(s,e.lastIndexOf("\\"))+'"')}r("Unterminated string literal")},S=()=>{t++,A();let s={};try{for(;e[t]!=="}";){if(A(),t>=o&&T.Allow.OBJ&a)return s;let n=b();A(),t++;try{let g=c();s[n]=g}catch(g){if(T.Allow.OBJ&a)return s;throw g}A(),e[t]===","&&t++}}catch{if(T.Allow.OBJ&a)return s;r("Expected '}' at end of object")}return t++,s},C=()=>{t++;let s=[];try{for(;e[t]!=="]";)s.push(c()),A(),e[t]===","&&t++}catch{if(T.Allow.ARR&a)return s;r("Expected ']' at end of array")}return t++,s},M=()=>{if(t===0){e==="-"&&u("Not sure what '-' is");try{return JSON.parse(e)}catch(n){if(T.Allow.NUM&a)try{return JSON.parse(e.substring(0,e.lastIndexOf("e")))}catch{}u(String(n))}}let s=t;for(e[t]==="-"&&t++;e[t]&&",]}".indexOf(e[t])===-1;)t++;t==o&&!(T.Allow.NUM&a)&&r("Unterminated number literal");try{return JSON.parse(e.substring(s,t))}catch{e.substring(s,t)==="-"&&r("Not sure what '-' is");try{return JSON.parse(e.substring(s,e.lastIndexOf("e")))}catch(g){u(String(g))}}},A=()=>{for(;t<o&&`
|
|
2
|
+
\r `.includes(e[t]);)t++};return c()},Te=te;w.parse=Te});var l=(e,a)=>{let o=document.createElement(e);return a&&(o.className=a),o};var K=ye(re(),1);var W=e=>{if(e===null)return"null";if(e===void 0)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}};var ae=()=>{},oe=e=>{ae=e.webMcpToolTitle},_=e=>ae(e);var $=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M4.929 4.929 19.07 19.071"}]];var H=[["path",{d:"m6 9 6 6 6-6"}]];var Z=[["path",{d:"m18 15-6-6-6 6"}]];var Q=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"M12 8v4"}],["path",{d:"M12 16h.01"}]];var q=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m9 12 2 2 4-4"}]];var G=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m14.5 9.5-5 5"}],["path",{d:"m9.5 9.5 5 5"}]];var R=(e,a=24,o="currentColor",t=2)=>{if(!Array.isArray(e))return null;let r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.setAttribute("width",String(a)),r.setAttribute("height",String(a)),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("fill","none"),r.setAttribute("stroke",o),r.setAttribute("stroke-width",String(t)),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round"),r.setAttribute("aria-hidden","true"),e.forEach(u=>{if(!Array.isArray(u)||u.length<2)return;let c=u[0],b=u[1];if(!b)return;let S=document.createElementNS("http://www.w3.org/2000/svg",c);Object.entries(b).forEach(([C,M])=>{C!=="stroke"&&S.setAttribute(C,String(M))}),r.appendChild(S)}),r};var U="webmcp:";var I=e=>{let o=(e.startsWith(U)?e.slice(U.length):e).replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[_\-\s.]+/).filter(Boolean);if(o.length===0)return e;let t=o.join(" ").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},fe=e=>e?.approval!==!1?e?.approval:void 0,le=(e,a,o)=>{let t=fe(o)?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},se=(e,a,o)=>{let t=fe(o);e.setAttribute("aria-expanded",a?"true":"false");let r=e.querySelector("[data-approval-details-label]");r&&(r.textContent=a?t?.hideDetailsLabel??"Hide details":t?.showDetailsLabel??"Show details");let u=e.querySelector("[data-approval-details-chevron]");if(u){u.innerHTML="";let c=R(a?Z:H,14,"currentColor",2);c&&u.appendChild(c)}},de=(e,a,o,t=new Map)=>{let r=a.querySelector('button[data-bubble-type="approval"]'),u=a.querySelector("[data-approval-details]");if(!r||!u)return;let c=le(e,t,o);se(r,c,o),u.style.display=c?"":"none"};var ue=(e,a,o=new Map)=>{let t=e.approval,r=a?.approval!==!1?a?.approval:void 0,u=t?.status==="pending",c=l("div",["persona-approval-bubble","persona-w-full","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(c.id=`bubble-${e.id}`,c.setAttribute("data-message-id",e.id),c.style.backgroundColor=r?.backgroundColor??"var(--persona-approval-bg)",c.style.borderColor=r?.borderColor??"var(--persona-approval-border)",c.style.boxShadow=r?.shadow!==void 0?r.shadow.trim()===""?"none":r.shadow:"var(--persona-approval-shadow)",!t)return c;let b=l("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),S=l("div","persona-flex-shrink-0 persona-mt-0.5");S.setAttribute("data-approval-icon","true");let C=t.status==="denied"?G:t.status==="timeout"?Q:q,M=t.status==="approved"?"var(--persona-feedback-success, var(--persona-palette-colors-success-600))":t.status==="denied"?"var(--persona-feedback-error, var(--persona-palette-colors-error-600))":t.status==="timeout"?"var(--persona-feedback-warning, var(--persona-palette-colors-warning-600))":r?.titleColor??"currentColor",A=R(C,20,M,2);A&&S.appendChild(A);let s=l("div","persona-flex-1 persona-min-w-0"),n=l("div","persona-flex persona-items-center persona-gap-2"),g=l("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(r?.titleColor&&(g.style.color=r.titleColor),g.textContent=r?.title??"Approval Required",n.appendChild(g),!u){let p=l("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded-full persona-text-xs persona-font-medium");p.setAttribute("data-approval-status",t.status),t.status==="approved"?(p.style.backgroundColor="var(--persona-palette-colors-success-100)",p.style.color="var(--persona-palette-colors-success-700)",p.textContent="Approved"):t.status==="denied"?(p.style.backgroundColor="var(--persona-palette-colors-error-100)",p.style.color="var(--persona-palette-colors-error-700)",p.textContent="Denied"):t.status==="timeout"&&(p.style.backgroundColor="var(--persona-palette-colors-warning-100)",p.style.color="var(--persona-palette-colors-warning-700)",p.textContent="Timeout"),n.appendChild(p)}s.appendChild(n);let O=t.toolType==="webmcp"||t.toolName.startsWith(U)?_(t.toolName):void 0,m=r?.formatDescription?.({toolName:t.toolName,toolType:t.toolType,description:t.description,parameters:t.parameters,...O?{displayTitle:O}:{},...t.reason?{reason:t.reason}:{}}),k=!t.toolName,v=m||(k?t.description:`The assistant wants to use \u201C${O??I(t.toolName)}\u201D.`),P=l("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(P.setAttribute("data-approval-summary","true"),r?.descriptionColor&&(P.style.color=r.descriptionColor),P.textContent=v,s.appendChild(P),t.reason){let p=l("p","persona-text-sm persona-mt-1 persona-text-persona-muted");p.setAttribute("data-approval-reason","true"),r?.reasonColor?p.style.color=r.reasonColor:r?.descriptionColor&&(p.style.color=r.descriptionColor);let h=l("span","persona-font-medium");h.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,p.appendChild(h),p.appendChild(document.createTextNode(t.reason)),s.appendChild(p)}let L=r?.detailsDisplay??"collapsed",D=!!t.description&&!k,B=D||!!t.parameters;if(L!=="hidden"&&B){let p=le(e.id,o,a),h=l("button","persona-inline-flex persona-items-center persona-gap-1 persona-mt-1 persona-p-0 persona-border-none persona-bg-transparent persona-text-xs persona-font-medium persona-cursor-pointer persona-text-persona-muted");h.type="button",h.setAttribute("data-expand-header","true"),h.setAttribute("data-bubble-type","approval"),r?.descriptionColor&&(h.style.color=r.descriptionColor);let d=l("span");d.setAttribute("data-approval-details-label","true");let x=l("span","persona-inline-flex persona-items-center");x.setAttribute("data-approval-details-chevron","true"),h.append(d,x),se(h,p,a),s.appendChild(h);let i=l("div");if(i.setAttribute("data-approval-details","true"),i.style.display=p?"":"none",D){let y=l("p","persona-text-sm persona-mt-1 persona-text-persona-muted");r?.descriptionColor&&(y.style.color=r.descriptionColor),y.textContent=t.description,i.appendChild(y)}if(t.parameters){let y=l("pre","persona-mt-2 persona-text-xs persona-p-2 persona-rounded persona-overflow-x-auto persona-max-h-32 persona-bg-persona-container persona-text-persona-primary");r?.parameterBackgroundColor&&(y.style.backgroundColor=r.parameterBackgroundColor),r?.parameterTextColor&&(y.style.color=r.parameterTextColor),y.style.fontSize="0.75rem",y.style.lineHeight="1rem",y.textContent=W(t.parameters),i.appendChild(y)}s.appendChild(i)}if(u){let p=l("div","persona-flex persona-gap-2 persona-mt-2");p.setAttribute("data-approval-buttons","true");let h=l("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-border-none persona-cursor-pointer");h.type="button",h.style.backgroundColor=r?.approveButtonColor??"var(--persona-approval-approve-bg)",h.style.color=r?.approveButtonTextColor??"var(--persona-button-primary-fg)",h.setAttribute("data-approval-action","approve");let d=R(q,14,r?.approveButtonTextColor??"var(--persona-button-primary-fg)",2);d&&(d.style.marginRight="4px",h.appendChild(d));let x=document.createTextNode(r?.approveLabel??"Approve");h.appendChild(x);let i=l("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-cursor-pointer");i.type="button",i.style.backgroundColor=r?.denyButtonColor??"transparent",i.style.color=r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",i.style.border=`1px solid ${r?.denyButtonTextColor?r.denyButtonTextColor:"var(--persona-palette-colors-error-200)"}`,i.setAttribute("data-approval-action","deny");let y=R(G,14,r?.denyButtonTextColor??"var(--persona-feedback-error, var(--persona-palette-colors-error-600))",2);y&&(y.style.marginRight="4px",i.appendChild(y));let N=document.createTextNode(r?.denyLabel??"Deny");i.appendChild(N),p.append(h,i),s.appendChild(p)}return b.append(S,s),c.appendChild(b),c};function Me(e){let a=e.getRootNode?.();return a instanceof ShadowRoot?a:(e.ownerDocument??document).body}function ne(e){let{anchor:a,content:o,placement:t="bottom-start",offset:r=6,matchAnchorWidth:u=!1,horizontalOffset:c,verticalOffset:b,zIndex:S=2147483e3,onOpen:C,onDismiss:M}=e,A=e.container??Me(a),s=!1,n=null,g=()=>{if(!s)return;let m=a.getBoundingClientRect();o.style.position="fixed",u&&(o.style.minWidth=`${m.width}px`),c&&(o.style.maxWidth=`${m.width}px`);let k=o.getBoundingClientRect(),v=b?.()??null,P=v!=null?m.top+v:m.top,L=t==="top-start"||t==="top-end"?P-r-k.height:m.bottom+r,B=t==="bottom-end"||t==="top-end"?m.right-k.width:m.left,p=c?.()??null;if(p!=null){let h=Math.max(m.left,m.right-k.width);B=Math.min(Math.max(m.left+p,m.left),h)}o.style.top=`${L}px`,o.style.left=`${B}px`},F=()=>{s&&(s=!1,n&&(n(),n=null),o.remove())},O=()=>{if(s)return;s=!0,S!=null&&(o.style.zIndex=String(S)),A.appendChild(o),g();let m=(a.ownerDocument??document).defaultView??window,k=a.ownerDocument??document,v=()=>{if(!a.isConnected){F(),M?.("anchor-removed");return}g()},P=D=>{let B=typeof D.composedPath=="function"?D.composedPath():[];B.includes(o)||B.includes(a)||(F(),M?.("outside"))},L=m.setTimeout(()=>{k.addEventListener("pointerdown",P,!0)},0);m.addEventListener("scroll",v,!0),m.addEventListener("resize",v),n=()=>{m.clearTimeout(L),k.removeEventListener("pointerdown",P,!0),m.removeEventListener("scroll",v,!0),m.removeEventListener("resize",v)},C?.()};return{get isOpen(){return s},open:O,close:F,toggle:()=>s?F():O(),reposition:g,destroy:F}}function pe(e){return(typeof e.composedPath=="function"?e.composedPath():[]).some(o=>o instanceof HTMLElement&&(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))}var Pe=()=>({keyHandlers:new Map,popovers:new Map,pendingOrder:[],latestPendingApprovalId:null}),ie=(e,a)=>{let o=e.keyHandlers.get(a);o&&(document.removeEventListener("keydown",o),e.keyHandlers.delete(a));let t=e.popovers.get(a);t&&(t.destroy(),e.popovers.delete(a))},E=(e,a)=>{ie(e,a);let o=e.pendingOrder.indexOf(a);o!==-1&&e.pendingOrder.splice(o,1),e.latestPendingApprovalId===a&&(e.latestPendingApprovalId=e.pendingOrder.length?e.pendingOrder[e.pendingOrder.length-1]:null)},ke=e=>e?.approval!==!1?e?.approval:void 0,ve=(e,a,o)=>{let t=o?.detailsDisplay??"collapsed";return a.get(e)??t==="expanded"},Y=e=>{let a=l("span","persona-approval-kbd");return a.textContent=e,a},Le=(e,a)=>{let o=l("span","persona-approval-title");a?.titleColor&&(o.style.color=a.titleColor);let r=e.toolType==="webmcp"||e.toolName.startsWith(U)?_(e.toolName):void 0,u=a?.formatDescription?.({toolName:e.toolName,toolType:e.toolType,description:e.description??"",parameters:e.parameters,...r?{displayTitle:r}:{},...e.reason?{reason:e.reason}:{}});if(u)return o.textContent=u,o;let c=r??I(e.toolName),b=e.toolType&&e.toolType!=="webmcp"?e.toolType:null;o.append("The assistant wants to use ");let S=document.createElement("strong");if(S.textContent=c,o.appendChild(S),b){o.append(" from ");let C=document.createElement("strong");C.textContent=b,o.appendChild(C)}return o},Be=e=>{let a=l("div","persona-approval-resolved"),o=R($,15,"currentColor",2);o&&a.appendChild(o);let t=l("span","persona-approval-resolved-name");return t.textContent=e.toolName?I(e.toolName):"Tool",a.append(t,document.createTextNode(e.status==="timeout"?" timed out":" denied")),a},De=(e,a,o,t,r,u,c,b,S=!1)=>{let C=l("div","persona-approval-card persona-shadow-sm");C.id=`bubble-${o.id}`,C.setAttribute("data-message-id",o.id),C.setAttribute("data-bubble-type","approval"),r?.backgroundColor&&(C.style.background=r.backgroundColor),r?.borderColor&&(C.style.borderColor=r.borderColor),r?.shadow!==void 0&&(C.style.boxShadow=r.shadow.trim()===""?"none":r.shadow);let M=r?.detailsDisplay??"collapsed",A=!!t.description&&M!=="hidden",s=t.parameters!=null&&M!=="hidden"&&!S,n=A||s,g=n&&ve(o.id,a,r),F=r?.showDetailsLabel??"Show details",O=r?.hideDetailsLabel??"Hide details",m=l("button","persona-approval-head");m.type="button",n?(m.setAttribute("data-action","toggle-params"),m.setAttribute("aria-expanded",g?"true":"false"),m.setAttribute("aria-label",g?O:F)):m.setAttribute("data-static","true");let k=l("span","persona-approval-logo"),v=R(q,16,"currentColor",2);v&&k.appendChild(v),m.appendChild(k);let P=Le(t,r);if(n){let d=l("span","persona-approval-toggle");d.setAttribute("aria-hidden","true");let x=R(H,14,"currentColor",2);x&&d.appendChild(x),P.append(" "),P.appendChild(d)}m.appendChild(P),C.appendChild(m);let L=l("div","persona-approval-body");if(n){let d=l("div","persona-approval-details");if(d.setAttribute("data-role","params"),d.hidden=!g,A){let x=l("p","persona-approval-desc");r?.descriptionColor&&(x.style.color=r.descriptionColor),x.textContent=t.description,d.appendChild(x)}if(s){let x=l("pre","persona-approval-params");r?.parameterBackgroundColor&&(x.style.background=r.parameterBackgroundColor),r?.parameterTextColor&&(x.style.color=r.parameterTextColor),x.textContent=W(t.parameters),d.appendChild(x)}L.appendChild(d)}if(S){let d=l("div","persona-approval-call");d.setAttribute("data-role","raw-call");let x=l("code","persona-approval-tool-name");if(x.textContent=t.toolName,d.appendChild(x),t.parameters!=null){let i=l("pre","persona-approval-params");r?.parameterBackgroundColor&&(i.style.background=r.parameterBackgroundColor),r?.parameterTextColor&&(i.style.color=r.parameterTextColor),i.textContent=W(t.parameters),d.appendChild(i)}L.appendChild(d)}if(t.reason){let d=l("p","persona-approval-reason");r?.reasonColor?d.style.color=r.reasonColor:r?.descriptionColor&&(d.style.color=r.descriptionColor);let x=l("span","persona-approval-reason-label");x.textContent=`${r?.reasonLabel??"Agent's stated reason:"} `,d.append(x,document.createTextNode(t.reason)),L.appendChild(d)}let D=l("div","persona-approval-actions"),B=null,p=d=>{r?.approveButtonColor&&(d.style.background=r.approveButtonColor),r?.approveButtonTextColor&&(d.style.color=r.approveButtonTextColor)},h=l("button","persona-approval-deny");if(h.type="button",h.setAttribute("data-action","deny"),r?.denyButtonColor&&(h.style.background=r.denyButtonColor),r?.denyButtonTextColor&&(h.style.color=r.denyButtonTextColor),h.append(r?.denyLabel??"Deny"),b){let d=l("div","persona-approval-split"),x=l("button","persona-approval-primary");x.type="button",x.setAttribute("data-action","always"),p(x),x.append(r?.approveLabel??"Always allow",Y("\u23CE"));let i=l("button","persona-approval-caret");i.type="button",i.setAttribute("data-action","toggle-menu"),i.setAttribute("aria-label","More options"),p(i);let y=R(H,15,"currentColor",2);y&&i.appendChild(y),d.append(x,i),D.append(d,h),h.append(Y("Esc"));let N=l("div","persona-approval-menu"),V=l("button","persona-approval-menu-item");V.type="button",V.append("Allow once",Y("\u2318\u23CE")),N.appendChild(V),B=ne({anchor:d,content:N,placement:"bottom-start",matchAnchorWidth:!0}),e.popovers.set(o.id,B),V.addEventListener("click",()=>{E(e,o.id),u()})}else{let d=l("button","persona-approval-primary persona-approval-primary--solo");d.type="button",d.setAttribute("data-action","allow"),p(d),d.append(r?.approveLabel??"Allow"),D.append(d,h)}return L.appendChild(D),C.appendChild(L),C.addEventListener("click",d=>{let x=d.target instanceof Element?d.target.closest("[data-action]"):null;if(!x)return;let i=x.getAttribute("data-action");if(i==="toggle-params"){let y=C.querySelector('[data-role="params"]');if(y){let N=y.hidden;y.hidden=!N,m.setAttribute("aria-expanded",N?"true":"false"),m.setAttribute("aria-label",N?O:F),a.set(o.id,N)}return}if(i==="toggle-menu"){B?.toggle();return}if(i==="always"){E(e,o.id),u({remember:!0});return}if(i==="allow"){E(e,o.id),u();return}if(i==="deny"){E(e,o.id),c();return}}),C},me=(e=new Map)=>{let a=Pe();return{plugin:{id:"persona-built-in-approval",renderApproval:({message:r,approve:u,deny:c,config:b})=>{let S=r?.approval;if(!S)return null;let C=ke(b);if(S.status!=="pending"){if(E(a,r.id),S.status==="approved"){let n=document.createElement("div");return n.style.display="none",n}return Be(S)}ie(a,r.id);let M=!!b?.clientToken,A=C?.enableAlwaysAllow===!0,s=De(a,e,r,S,C,u,c,A,M);if(A){a.pendingOrder.includes(r.id)||a.pendingOrder.push(r.id),a.latestPendingApprovalId=a.pendingOrder[a.pendingOrder.length-1];let n=g=>{pe(g)||r.id===a.latestPendingApprovalId&&(g.key!=="Escape"&&g.key!=="Enter"||(g.preventDefault(),g.stopImmediatePropagation(),E(a,r.id),g.key==="Escape"?c():g.metaKey||g.ctrlKey?u():u({remember:!0})))};a.keyHandlers.set(r.id,n),document.addEventListener("keydown",n)}return s}},teardown:()=>{for(let r of[...a.keyHandlers.keys(),...a.popovers.keys()])E(a,r);a.latestPendingApprovalId=null}}};export{ue as createApprovalBubble,me as createBuiltInApprovalPlugin,I as humanizeToolName,oe as initApprovalUi,de as updateApprovalDetailsUI};
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
lucide/dist/esm/icons/ban.mjs:
|
package/dist/artifacts-ui.d.cts
CHANGED
|
@@ -3216,9 +3216,8 @@ type WebMcpConfirmInfo = {
|
|
|
3216
3216
|
};
|
|
3217
3217
|
/**
|
|
3218
3218
|
* Why the confirm was requested. Currently always `'gate'`: the default
|
|
3219
|
-
* confirm-by-default gate that fires before every `webmcp:*` call.
|
|
3220
|
-
*
|
|
3221
|
-
* internally, so Persona no longer surfaces a nested in-tool confirm.)
|
|
3219
|
+
* confirm-by-default gate that fires before every `webmcp:*` call. Tool
|
|
3220
|
+
* callbacks on v6 receive an AbortSignal, not a nested confirmation API.
|
|
3222
3221
|
*/
|
|
3223
3222
|
reason: 'gate';
|
|
3224
3223
|
};
|
|
@@ -9289,8 +9288,11 @@ type AgentWidgetConfig = {
|
|
|
9289
9288
|
/**
|
|
9290
9289
|
* WebMCP: consume page-registered tools (`document.modelContext.registerTool`).
|
|
9291
9290
|
* When `enabled`, the widget installs `@mcp-b/webmcp-polyfill`, snapshots the
|
|
9292
|
-
* registry on every dispatch, ships it as `clientTools[]`,
|
|
9293
|
-
* returned `webmcp:*`
|
|
9291
|
+
* current document's registry on every dispatch, ships it as `clientTools[]`,
|
|
9292
|
+
* and executes returned `webmcp:*` calls with confirm-by-default gating.
|
|
9293
|
+
* Supports host-installed v5 JSON-string and v6 object-input contracts.
|
|
9294
|
+
* The automatic fallback stays on v5 to preserve existing browser support
|
|
9295
|
+
* and callback-result behavior.
|
|
9294
9296
|
*
|
|
9295
9297
|
* Server-side policy on the chat surface is the source of truth: these
|
|
9296
9298
|
* fields layer on top.
|
package/dist/artifacts-ui.d.ts
CHANGED
|
@@ -3216,9 +3216,8 @@ type WebMcpConfirmInfo = {
|
|
|
3216
3216
|
};
|
|
3217
3217
|
/**
|
|
3218
3218
|
* Why the confirm was requested. Currently always `'gate'`: the default
|
|
3219
|
-
* confirm-by-default gate that fires before every `webmcp:*` call.
|
|
3220
|
-
*
|
|
3221
|
-
* internally, so Persona no longer surfaces a nested in-tool confirm.)
|
|
3219
|
+
* confirm-by-default gate that fires before every `webmcp:*` call. Tool
|
|
3220
|
+
* callbacks on v6 receive an AbortSignal, not a nested confirmation API.
|
|
3222
3221
|
*/
|
|
3223
3222
|
reason: 'gate';
|
|
3224
3223
|
};
|
|
@@ -9289,8 +9288,11 @@ type AgentWidgetConfig = {
|
|
|
9289
9288
|
/**
|
|
9290
9289
|
* WebMCP: consume page-registered tools (`document.modelContext.registerTool`).
|
|
9291
9290
|
* When `enabled`, the widget installs `@mcp-b/webmcp-polyfill`, snapshots the
|
|
9292
|
-
* registry on every dispatch, ships it as `clientTools[]`,
|
|
9293
|
-
* returned `webmcp:*`
|
|
9291
|
+
* current document's registry on every dispatch, ships it as `clientTools[]`,
|
|
9292
|
+
* and executes returned `webmcp:*` calls with confirm-by-default gating.
|
|
9293
|
+
* Supports host-installed v5 JSON-string and v6 object-input contracts.
|
|
9294
|
+
* The automatic fallback stays on v5 to preserve existing browser support
|
|
9295
|
+
* and callback-result behavior.
|
|
9294
9296
|
*
|
|
9295
9297
|
* Server-side policy on the chat surface is the source of truth: these
|
|
9296
9298
|
* fields layer on top.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
var c="webmcp:",u=new Map,w=t=>{u.clear();for(let r of t){let e=r.title?.trim();e&&u.set(r.name,e)}},_=t=>u.get(h(t)),g=null;function D(t){if(t.length===0)return"0:empty";let r=t.map(e=>[e.name,e.description??"",e.parametersSchema?JSON.stringify(e.parametersSchema):"",e.origin??"",e.annotations?JSON.stringify(e.annotations):""].join("")).sort();return`${t.length}:${m(r.join(""))}`}function p(t,r){let e=3735928559^r,n=1103547991^r;for(let o=0;o<t.length;o++){let s=t.charCodeAt(o);e=Math.imul(e^s,2654435761),n=Math.imul(n^s,1597334677)}return e=Math.imul(e^e>>>16,2246822507),e^=Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507),n^=Math.imul(e^e>>>13,3266489909),4294967296*(2097151&n)+(e>>>0)}function m(t){let r=p(t,0).toString(36),e=p(t,2654435761).toString(36);return`${r}.${e}`}var h=t=>t.startsWith(c)?t.slice(c.length):t,E=t=>t.startsWith(c),k=()=>g?g():import("@mcp-b/webmcp-polyfill");import{parse as T,STR as M,OBJ as y}from"partial-json";var d=t=>t.replace(/\\n/g,`
|
|
2
|
-
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"),
|
|
2
|
+
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"),J=t=>{if(t===null)return"null";if(t===void 0)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t,null,2)}catch{return String(t)}},W=t=>{let r=t.completedAt??Date.now(),e=t.startedAt??r,o=(t.durationMs!==void 0?t.durationMs:Math.max(0,r-e))/1e3;return o<.1?"Thought for <0.1 seconds":`Thought for ${o>=10?Math.round(o).toString():o.toFixed(1).replace(/\.0$/,"")} seconds`},I=t=>t.status==="complete"?W(t):t.status==="pending"?"Waiting":"",b=15e3,P=1200,N=(t,r)=>{let e=r?.durationMs??b,n=r?.chars??P;return typeof t.durationMs=="number"?t.durationMs<e:(t.chunks??[]).join("").length<n},S=t=>{let e=(typeof t.duration=="number"?t.duration:typeof t.durationMs=="number"?t.durationMs:Math.max(0,(t.completedAt??Date.now())-(t.startedAt??t.completedAt??Date.now())))/1e3;return e<.1?"Used tool for <0.1 seconds":`Used tool for ${e>=10?Math.round(e).toString():e.toFixed(1).replace(/\.0$/,"")} seconds`};var O=t=>t.status==="complete"?S(t):"Using tool...",x=t=>{let r=t/1e3;return r<.1?"<0.1s":r>=10?`${Math.round(r)}s`:`${r.toFixed(1).replace(/\.0$/,"")}s`},A=t=>{let r=typeof t.duration=="number"?t.duration:typeof t.durationMs=="number"?t.durationMs:Math.max(0,(t.completedAt??Date.now())-(t.startedAt??t.completedAt??Date.now()));return x(r)},$=t=>{let r=t.durationMs!==void 0?t.durationMs:Math.max(0,(t.completedAt??Date.now())-(t.startedAt??t.completedAt??Date.now()));return x(r)},L=(t,r,e)=>{if(!r)return e;let n=t.name?.trim()||"tool",o=A(t);return r.replace(/\{toolName\}/g,n).replace(/\{duration\}/g,o)},H=(t,r)=>{let e=t.replace(/\{toolName\}/g,r),n=[],o=/\*\*(.+?)\*\*|\*(.+?)\*|~(.+?)~/g,s=0,i;for(;(i=o.exec(e))!==null;)i.index>s&&l(n,e.slice(s,i.index),[]),i[1]!==void 0?l(n,i[1],["bold"]):i[2]!==void 0?l(n,i[2],["italic"]):i[3]!==void 0&&l(n,i[3],["dim"]),s=i.index+i[0].length;return s<e.length&&l(n,e.slice(s),[]),n},l=(t,r,e)=>{let n=r.split("{duration}");for(let o=0;o<n.length;o++)n[o]&&t.push({text:n[o],styles:e}),o<n.length-1&&t.push({text:"{duration}",styles:e,isDuration:!0})},R=()=>{let t=null,r=0,e=n=>{let o=/"text"\s*:\s*"((?:[^"\\]|\\.|")*?)"/,s=n.match(o);if(s&&s[1])try{return s[1].replace(/\\n/g,`
|
|
3
3
|
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return s[1]}let i=/"text"\s*:\s*"((?:[^"\\]|\\.)*)/,a=n.match(i);if(a&&a[1])try{return a[1].replace(/\\n/g,`
|
|
4
|
-
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return a[1]}return null};return{getExtractedText:()=>t,processChunk:async n=>{if(n.length<=r)return t!==null?{text:t,raw:n}:null;let o=n.trim();if(!o.startsWith("{")&&!o.startsWith("["))return null;let s=e(n);return s!==null&&(t=s),r=n.length,t!==null?{text:t,raw:n}:null},close:async()=>{}}},
|
|
4
|
+
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return a[1]}return null};return{getExtractedText:()=>t,processChunk:async n=>{if(n.length<=r)return t!==null?{text:t,raw:n}:null;let o=n.trim();if(!o.startsWith("{")&&!o.startsWith("["))return null;let s=e(n);return s!==null&&(t=s),r=n.length,t!==null?{text:t,raw:n}:null},close:async()=>{}}},j=t=>{try{let r=JSON.parse(t);if(r&&typeof r=="object"&&typeof r.text=="string")return r.text}catch{return null}return null},U=()=>{let t={processChunk:r=>null,getExtractedText:()=>null};return t.__isPlainTextParser=!0,t},B=()=>{let t=R();return{processChunk:async r=>{let e=r.trim();return!e.startsWith("{")&&!e.startsWith("[")?null:t.processChunk(r)},getExtractedText:t.getExtractedText.bind(t),close:t.close?.bind(t)}},K=()=>{let t=null,r=0;return{getExtractedText:()=>t,processChunk:e=>{let n=e.trim();if(!n.startsWith("{")&&!n.startsWith("["))return null;if(e.length<=r)return t!==null||t===""?{text:t||"",raw:e}:null;try{let o=T(e,M|y);o&&typeof o=="object"&&(o.component&&typeof o.component=="string"?t=typeof o.text=="string"?d(o.text):"":o.type==="init"&&o.form?t="":typeof o.text=="string"&&(t=d(o.text)))}catch{}return r=e.length,t!==null?{text:t,raw:e}:null},close:()=>{}}};var X=()=>{let t=null;return{processChunk:r=>{if(!r.trim().startsWith("<"))return null;let n=r.match(/<text[^>]*>([\s\S]*?)<\/text>/);return n&&n[1]?(t=n[1],{text:t,raw:r}):null},getExtractedText:()=>t}};export{c as a,w as b,_ as c,D as d,E as e,k as f,J as g,I as h,N as i,O as j,x as k,A as l,$ as m,L as n,H as o,j as p,U as q,B as r,K as s,X as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t="4.28.1";var n=t;export{n as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as g}from"./chunk-
|
|
1
|
+
import{a as g}from"./chunk-FNXK3VTC.js";var H=32768,c=49152,p=t=>{let e=t??{},i=typeof e.targetId=="string"?e.targetId:null;return{id:typeof e.id=="string"?e.id:"",title:typeof e.title=="string"?e.title:"",targetId:i,preview:typeof e.preview=="string"?e.preview:null,messageCount:typeof e.messageCount=="number"?e.messageCount:0,createdAt:typeof e.createdAt=="string"?e.createdAt:"",updatedAt:typeof e.updatedAt=="string"?e.updatedAt:""}},v="The identity proof was not admitted; account history is unavailable",m="The identity proof was rejected",C="The request carried no visitor credential",w="The stored visitor belongs to a different signed-in user";function E(t,e,i){let r=new URLSearchParams;for(let[n,s]of Object.entries(i))s===void 0||s===""||r.set(n,String(s));let o=r.toString();return`${t.clientApiBase()}/v1/client/${e}${o?`?${o}`:""}`}function b(t,e){if(e)return e;let i=t.config.features?.history?.scope;return i||(t.config.getIdentityProof?"verified-user":"browser")}async function T(t,e,i){let r=t.config.getIdentityProof;if(!r)return i&&t.setHistoryIdentityStatus(t.browserOnlyStatus()),null;i&&t.setHistoryIdentityStatus({state:"verifying"});let o;try{o=await r()??null}catch{throw i&&t.setHistoryIdentityStatus({state:"identity_provider_failed"}),new t.HistoryClientError("identity_provider_failed","The identity proof provider failed")}if(o)return o;if(e.visitor?.endUserId!=null)throw i&&t.setHistoryIdentityStatus({state:"authentication_required",reason:"proof_unavailable_after_binding"}),new t.HistoryClientError("authentication_required","This browser is bound to a signed-in user and needs a fresh identity proof");return i&&t.setHistoryIdentityStatus({state:"browser_only",reason:"proof_unavailable_before_binding"}),null}async function P(t,e,i,r){if(e.visitor?.endUserId!=null)return e;let o=await t.reinitWithProof(i);if(!(o.visitor?.identityStatus==="admitted"&&o.visitor?.endUserId!=null))throw r&&t.setHistoryIdentityStatus({state:"configuration_error",reason:"proof_not_admitted"}),new t.HistoryClientError("proof_not_admitted",v);return o}async function _(t,e){let i=await e.json().catch(()=>({}));return typeof i.error=="string"?i.error:typeof i.message=="string"?i.message:""}async function A(t,e,i,r){let o=e.toLowerCase();if(o.includes("invalid_identity_proof"))throw r&&t.setHistoryIdentityStatus({state:"authentication_required",reason:"invalid_identity_proof"}),new t.HistoryClientError("invalid_identity_proof",m);if(o.includes("visitor token required"))throw new t.HistoryClientError("visitor_token_missing",C);if(o.includes("visitor_identity_mismatch")){if(!i)throw r&&t.setHistoryIdentityStatus({state:"authentication_required",reason:"proof_unavailable_after_binding"}),new t.HistoryClientError("visitor_identity_mismatch",w);return t.reinitWithProof(i)}if(o.includes("expired")||o.includes("not found"))return t.clearClientSession(),t.initSession();throw new t.HistoryClientError("unauthorized",e||"History request was not authorized")}async function h(t,e,i){let r=await _(t,e);if(e.status===404)return new t.HistoryClientError("not_found","Conversation not found");if(e.status===429){let o=Number.parseInt(e.headers.get("Retry-After")??"",10);return new t.HistoryClientError("rate_limited","Too many history requests",{...Number.isFinite(o)?{retryAfterSeconds:o}:{}})}if(e.status===503&&r.includes("identity_proof_not_admitted"))return i&&t.setHistoryIdentityStatus({state:"configuration_error",reason:"proof_not_admitted"}),new t.HistoryClientError("proof_not_admitted",v);if(e.status===401){let o=r.toLowerCase();return o.includes("invalid_identity_proof")?(i&&t.setHistoryIdentityStatus({state:"authentication_required",reason:"invalid_identity_proof"}),new t.HistoryClientError("invalid_identity_proof",m)):o.includes("visitor token required")?new t.HistoryClientError("visitor_token_missing",C):o.includes("visitor_identity_mismatch")?new t.HistoryClientError("visitor_identity_mismatch",w):new t.HistoryClientError("unauthorized",r||"History request was not authorized")}return new t.HistoryClientError("request_failed",r||`History request failed (${e.status})`)}function R(t,e,i,r){let o=e?.toLowerCase()??null;if(i){if(o==="admitted"){r&&t.setHistoryIdentityStatus({state:"verified"});return}throw r&&t.setHistoryIdentityStatus({state:"configuration_error",reason:"proof_not_admitted"}),o==="ignored"?new t.HistoryClientError("identity_contract_violation","Server reported an ignored identity proof on a success response"):new t.HistoryClientError("proof_not_admitted","The response did not acknowledge the identity proof this request sent")}if(o==="admitted")throw new t.HistoryClientError("identity_contract_violation","Server admitted an identity proof that was never sent");r&&t.setHistoryIdentityStatus(t.browserOnlyStatus())}async function y(t,e,i){f(t);let r=i.trackIdentity!==!1,o=await t.initSession(),n=null;b(t,i.scope)==="verified-user"&&(n=await T(t,o,r),n&&(o=await P(t,o,n,r)));let s=t.historyInternals.visitorStore,a=!1;for(;;){let u=s?.revision()??0,d=await t.readVisitorToken();if(!d&&!i.visitorTokenOptional)throw new t.HistoryClientError("visitor_token_missing","No visitor credential is stored for this browser");let l=await fetch(E(t,e,{...i.query,sessionId:o.sessionId}),{method:i.method,headers:{"X-Persona-Version":g,...d?{"X-Visitor-Token":d}:{},...n?{"X-Identity-Proof":n}:{},...i.body!==void 0?{"Content-Type":"application/json"}:{}},...i.body!==void 0?{body:JSON.stringify(i.body)}:{},...i.keepalive?{keepalive:!0}:{}});if(l.status===401&&!a){a=!0,o=await A(t,await _(t,l),n,r);continue}if(!l.ok)throw await h(t,l,r);let S=l.headers.get("X-History-Identity-Status"),I=await l.json().catch(()=>{});if(s&&s.revision()!==u)throw new t.HistoryClientError("credential_changed","The visitor credential changed while the request was in flight");return R(t,S,n!==null,r),I}}function f(t){if(!t.isClientTokenMode())throw new Error("Conversation history is only available in client token mode");if(!t.isHistoryCapable())throw new t.HistoryClientError("history_disabled","Visitor history is disabled for this surface")}async function O(t,e){let i=await y(t,"conversations",{method:"GET",query:{...e?.cursor?{cursor:e.cursor}:{},...e?.limit!==void 0?{limit:e.limit}:{},...e?.targetId?{targetId:e.targetId}:{}},...e?.scope?{scope:e.scope}:{}});return{data:(Array.isArray(i?.data)?i.data:[]).map(p),nextCursor:typeof i?.nextCursor=="string"?i.nextCursor:null}}async function x(t,e,i){let r=await y(t,`conversations/${encodeURIComponent(e)}`,{method:"GET",query:{...i?.messageCursor?{messageCursor:i.messageCursor}:{}},...i?.scope?{scope:i.scope}:{}});return{summary:p(r),messages:Array.isArray(r?.messages)?r.messages:[],nextMessageCursor:typeof r?.nextMessageCursor=="string"?r.nextMessageCursor:null,conversationRevision:typeof r?.conversationRevision=="string"?r.conversationRevision:null}}async function q(t,e,i){f(t);let r=0;for(let u of i){let d=u.displayContent.length;if(d>H)throw new t.HistoryClientError("payload_too_large",`displayContent exceeds the ${H} character limit`);r+=d}if(r>c)throw new t.HistoryClientError("payload_too_large",`Display projection batch exceeds the ${c} character limit`);await t.initSession();let o=t.historyInternals.visitorStore,n=o?.revision()??0,s=await y(t,`conversations/${encodeURIComponent(e)}/display-projections`,{method:"PATCH",body:{messages:i},scope:"browser",keepalive:r<=c,trackIdentity:!1}),a=typeof s?.conversationRevision=="string"?s.conversationRevision:null;return a&&t.clientSession?.conversationId===e&&(o?.revision()??0)===n&&t.historyInternals.setStoredConversationRevision?.(a),{conversationRevision:a}}async function D(t,e,i){let r=await y(t,`conversations/${encodeURIComponent(e)}`,{method:"DELETE",...i?.scope?{scope:i.scope}:{}});return{deleted:typeof r?.deleted=="number"?r.deleted:0}}async function M(t,e){let i=await y(t,"conversations",{method:"DELETE",query:{...e?.targetId!==void 0?{targetId:e.targetId}:{}},...e?.scope?{scope:e.scope}:{}});return{deleted:typeof i?.deleted=="number"?i.deleted:0}}async function N(t){f(t),t.setHistoryIdentityStatus({state:"resetting"});try{await y(t,"visitor/reset",{method:"POST",scope:"browser",visitorTokenOptional:!0})}finally{await t.historyInternals.visitorStore?.clear(),t.setHistoryIdentityStatus(t.derivedBrowserOnly())}return{reset:!0}}export{M as deleteAllConversations,D as deleteConversation,q as finalizeDisplayProjections,x as getConversation,h as historyErrorFor,O as listConversations,_ as readErrorCode,A as recoverFromUnauthorized,N as resetVisitor};
|