@kya-os/consent 0.1.13 → 0.1.14

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.
Files changed (126) hide show
  1. package/dist/bundle/inline.d.ts.map +1 -1
  2. package/dist/bundle/inline.js +2 -2
  3. package/dist/bundle/inline.js.map +1 -1
  4. package/dist/bundle/shell.d.ts +5 -0
  5. package/dist/bundle/shell.d.ts.map +1 -1
  6. package/dist/bundle/shell.js +3 -1
  7. package/dist/bundle/shell.js.map +1 -1
  8. package/dist/cjs/bundle/index.js +57 -0
  9. package/dist/cjs/bundle/index.js.map +1 -0
  10. package/dist/cjs/bundle/inline.js +22 -0
  11. package/dist/cjs/bundle/inline.js.map +1 -0
  12. package/dist/cjs/bundle/shell.js +291 -0
  13. package/dist/cjs/bundle/shell.js.map +1 -0
  14. package/dist/cjs/components/consent-button.js +180 -0
  15. package/dist/cjs/components/consent-button.js.map +1 -0
  16. package/dist/cjs/components/consent-checkbox.js +223 -0
  17. package/dist/cjs/components/consent-checkbox.js.map +1 -0
  18. package/dist/cjs/components/consent-input.js +335 -0
  19. package/dist/cjs/components/consent-input.js.map +1 -0
  20. package/dist/cjs/components/consent-oauth-button.js +392 -0
  21. package/dist/cjs/components/consent-oauth-button.js.map +1 -0
  22. package/dist/cjs/components/consent-otp-input.js +388 -0
  23. package/dist/cjs/components/consent-otp-input.js.map +1 -0
  24. package/dist/cjs/components/consent-permissions.js +433 -0
  25. package/dist/cjs/components/consent-permissions.js.map +1 -0
  26. package/dist/cjs/components/consent-shell.js +234 -0
  27. package/dist/cjs/components/consent-shell.js.map +1 -0
  28. package/dist/cjs/components/consent-terms.js +287 -0
  29. package/dist/cjs/components/consent-terms.js.map +1 -0
  30. package/dist/cjs/components/index.js +37 -0
  31. package/dist/cjs/components/index.js.map +1 -0
  32. package/dist/cjs/components/mcp-consent.js +1034 -0
  33. package/dist/cjs/components/mcp-consent.js.map +1 -0
  34. package/dist/cjs/constants/auth-modes.js +128 -0
  35. package/dist/cjs/constants/auth-modes.js.map +1 -0
  36. package/dist/cjs/constants/colors.js +40 -0
  37. package/dist/cjs/constants/colors.js.map +1 -0
  38. package/dist/cjs/constants/defaults.js +146 -0
  39. package/dist/cjs/constants/defaults.js.map +1 -0
  40. package/dist/cjs/constants/index.js +40 -0
  41. package/dist/cjs/constants/index.js.map +1 -0
  42. package/dist/cjs/index.js +49 -0
  43. package/dist/cjs/index.js.map +1 -0
  44. package/dist/cjs/package.json +1 -0
  45. package/dist/cjs/react/index.js +190 -0
  46. package/dist/cjs/react/index.js.map +1 -0
  47. package/dist/cjs/resolution/index.js +28 -0
  48. package/dist/cjs/resolution/index.js.map +1 -0
  49. package/dist/cjs/resolution/resolve-branding.js +159 -0
  50. package/dist/cjs/resolution/resolve-branding.js.map +1 -0
  51. package/dist/cjs/resolution/resolve-config.js +270 -0
  52. package/dist/cjs/resolution/resolve-config.js.map +1 -0
  53. package/dist/cjs/resolution/resolve-copy.js +136 -0
  54. package/dist/cjs/resolution/resolve-copy.js.map +1 -0
  55. package/dist/cjs/schemas/api.schemas.js +156 -0
  56. package/dist/cjs/schemas/api.schemas.js.map +1 -0
  57. package/dist/cjs/schemas/branding.schemas.js +57 -0
  58. package/dist/cjs/schemas/branding.schemas.js.map +1 -0
  59. package/dist/cjs/schemas/config.schemas.js +147 -0
  60. package/dist/cjs/schemas/config.schemas.js.map +1 -0
  61. package/dist/cjs/schemas/index.js +29 -0
  62. package/dist/cjs/schemas/index.js.map +1 -0
  63. package/dist/cjs/schemas/modes.schemas.js +107 -0
  64. package/dist/cjs/schemas/modes.schemas.js.map +1 -0
  65. package/dist/cjs/security/escape.js +206 -0
  66. package/dist/cjs/security/escape.js.map +1 -0
  67. package/dist/cjs/security/index.js +26 -0
  68. package/dist/cjs/security/index.js.map +1 -0
  69. package/dist/cjs/security/validators.js +210 -0
  70. package/dist/cjs/security/validators.js.map +1 -0
  71. package/dist/cjs/styles/css-variables.js +129 -0
  72. package/dist/cjs/styles/css-variables.js.map +1 -0
  73. package/dist/cjs/styles/index.js +28 -0
  74. package/dist/cjs/styles/index.js.map +1 -0
  75. package/dist/cjs/styles/stylesheet.js +204 -0
  76. package/dist/cjs/styles/stylesheet.js.map +1 -0
  77. package/dist/cjs/styles/tokens.js +183 -0
  78. package/dist/cjs/styles/tokens.js.map +1 -0
  79. package/dist/cjs/templates/base/base-template.js +282 -0
  80. package/dist/cjs/templates/base/base-template.js.map +1 -0
  81. package/dist/cjs/templates/base/components.js +295 -0
  82. package/dist/cjs/templates/base/components.js.map +1 -0
  83. package/dist/cjs/templates/base/index.js +26 -0
  84. package/dist/cjs/templates/base/index.js.map +1 -0
  85. package/dist/cjs/templates/index.js +34 -0
  86. package/dist/cjs/templates/index.js.map +1 -0
  87. package/dist/cjs/templates/modes/consent-only.template.js +74 -0
  88. package/dist/cjs/templates/modes/consent-only.template.js.map +1 -0
  89. package/dist/cjs/templates/modes/credentials.template.js +414 -0
  90. package/dist/cjs/templates/modes/credentials.template.js.map +1 -0
  91. package/dist/cjs/templates/modes/index.js +24 -0
  92. package/dist/cjs/templates/modes/index.js.map +1 -0
  93. package/dist/cjs/templates/modes/magic-link.template.js +196 -0
  94. package/dist/cjs/templates/modes/magic-link.template.js.map +1 -0
  95. package/dist/cjs/templates/modes/oauth.template.js +153 -0
  96. package/dist/cjs/templates/modes/oauth.template.js.map +1 -0
  97. package/dist/cjs/templates/modes/otp.template.js +316 -0
  98. package/dist/cjs/templates/modes/otp.template.js.map +1 -0
  99. package/dist/cjs/templates/modes/success.template.js +140 -0
  100. package/dist/cjs/templates/modes/success.template.js.map +1 -0
  101. package/dist/cjs/templates/registry.js +133 -0
  102. package/dist/cjs/templates/registry.js.map +1 -0
  103. package/dist/cjs/types/api.types.js +10 -0
  104. package/dist/cjs/types/api.types.js.map +1 -0
  105. package/dist/cjs/types/branding.types.js +10 -0
  106. package/dist/cjs/types/branding.types.js.map +1 -0
  107. package/dist/cjs/types/config.types.js +10 -0
  108. package/dist/cjs/types/config.types.js.map +1 -0
  109. package/dist/cjs/types/copy.types.js +10 -0
  110. package/dist/cjs/types/copy.types.js.map +1 -0
  111. package/dist/cjs/types/index.js +31 -0
  112. package/dist/cjs/types/index.js.map +1 -0
  113. package/dist/cjs/types/modes.types.js +140 -0
  114. package/dist/cjs/types/modes.types.js.map +1 -0
  115. package/dist/cjs/types/page.types.js +10 -0
  116. package/dist/cjs/types/page.types.js.map +1 -0
  117. package/dist/components/mcp-consent.d.ts +6 -0
  118. package/dist/components/mcp-consent.d.ts.map +1 -1
  119. package/dist/components/mcp-consent.js +14 -0
  120. package/dist/components/mcp-consent.js.map +1 -1
  121. package/dist/consent.js +7 -0
  122. package/dist/consent.min.js +2 -2
  123. package/dist/schemas/api.schemas.d.ts +116 -116
  124. package/dist/schemas/config.schemas.d.ts +116 -116
  125. package/dist/schemas/modes.schemas.d.ts +28 -28
  126. package/package.json +29 -15
@@ -1064,7 +1064,7 @@ var Xe=Object.defineProperty;var Ze=Object.getOwnPropertyDescriptor;var n=(i,t,e
1064
1064
  gap: 0.375rem;
1065
1065
  }
1066
1066
  }
1067
- `,n([l({type:Number})],A.prototype,"length",2),n([l({type:String})],A.prototype,"name",2),n([l({type:String})],A.prototype,"value",2),n([l({type:Boolean,reflect:!0})],A.prototype,"disabled",2),n([l({type:Boolean,reflect:!0})],A.prototype,"error",2),n([l({type:Boolean,attribute:"auto-focus"})],A.prototype,"autoFocus",2),n([l({type:String,attribute:"input-type"})],A.prototype,"inputType",2),n([w()],A.prototype,"digits",2),n([He("input")],A.prototype,"inputs",2),A=n([x("consent-otp-input")],A);var f={CONSENT_ONLY:"consent-only",CREDENTIALS:"credentials",OAUTH:"oauth",MAGIC_LINK:"magic-link",OTP:"otp",QR_CODE:"qr-code",PASSKEY:"passkey",IDV:"idv"},L={NONE:"none",PASSWORD:"password",OAUTH2:"oauth2",MAGIC_LINK:"magic_link",OTP:"otp"},vt={[f.CONSENT_ONLY]:L.NONE,[f.CREDENTIALS]:L.PASSWORD,[f.OAUTH]:L.OAUTH2,[f.MAGIC_LINK]:L.MAGIC_LINK,[f.OTP]:L.OTP,[f.QR_CODE]:L.NONE,[f.PASSKEY]:L.NONE,[f.IDV]:L.NONE};function Ve(i){return vt[i]??L.NONE}var Y={PRIMARY:"#2563EB",SECONDARY:"#DBEAFE",BACKGROUND:"#F9FAFB",TEXT_PRIMARY:"#111827",TEXT_SECONDARY:"#6B7280",TEXT_MUTED:"#9CA3AF",BORDER:"#E5E7EB",BORDER_DARK:"#D1D5DB",SUCCESS:"#16A34A",ERROR:"#DC2626",WARNING:"#F59E0B"};var fi={primaryColor:Y.PRIMARY,secondaryColor:Y.SECONDARY,logoUrl:void 0,companyName:void 0},E={title:"Permission request",description:"It looks like you would like to use [AI Agent] to access resources on your behalf.",expirationText:"This delegation will expire in",cancelButtonText:"Cancel",submitButtonText:"Allow access",permissionsHeader:"The agent is requesting the following permissions:",autoClose:!1,popupEnabled:!1,theme:"auto"},K={text:"Terms and Conditions",url:void 0,version:void 0,required:!0},D={title:"Access Granted",description:"The agent now has permission to act on your behalf.",showCredential:!0,redirectUrl:void 0,redirectDelay:void 0,continueButtonText:"Close"};var je=30;function yt(i){return i?/^#[0-9A-Fa-f]{6}$/.test(i):!1}function Ge(i,t){return yt(i)?i:t}function bt(i){if(!i)return!1;try{let t=new URL(i);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}function xt(i){if(bt(i))return i}function Ye(i){let t=i.replace(/^#/,""),e=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),s=parseInt(t.slice(4,6),16);return`${e}, ${r}, ${s}`}function wt(i){return{"--consent-primary":i.primaryColor,"--consent-secondary":i.secondaryColor,"--consent-primary-rgb":Ye(i.primaryColor),"--consent-secondary-rgb":Ye(i.secondaryColor)}}function Ke(i){let t=Ge(i?.primaryColor,Y.PRIMARY),e=Ge(i?.secondaryColor,Y.SECONDARY),r=xt(i?.logoUrl),s=i?.companyName?.trim()||void 0,o=wt({primaryColor:t,secondaryColor:e});return{primaryColor:t,secondaryColor:e,logoUrl:r,companyName:s,cssVars:o}}var $t="[AI Agent]";function We(i,t){return t?i.replace(new RegExp(Ct($t),"g"),t):i}function Ct(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Je(i,t){let e=i?.ui??{},r=i?.terms??{},s=i?.success??{},o=e.title??E.title,a=e.description??E.description,p=e.expirationText??E.expirationText,c=e.cancelButtonText??E.cancelButtonText,v=e.submitButtonText??E.submitButtonText,b=e.permissionsHeader??E.permissionsHeader,m=r.text??K.text,k=s.title??D.title,R=s.description??D.description,z=We(a,t),Qe=We(R,t);return{title:o,description:a,expirationText:p,cancelButtonText:c,submitButtonText:v,permissionsHeader:b,termsText:m,termsUrl:r.url,termsRequired:r.required??K.required,resolvedDescription:z,successTitle:k,successDescription:R,resolvedSuccessDescription:Qe,showCredential:s.showCredential??D.showCredential,continueButtonText:s.continueButtonText??D.continueButtonText}}function Et(i){return!i||i.length===0?[]:i.slice(0,10).filter(e=>!(!e.name||!e.label||!/^[a-zA-Z0-9_]+$/.test(e.name)||e.type==="select"&&(!e.options||e.options.length===0)))}function At(i){return i==null?je:i<1?1:i>365?365:Math.floor(i)}function $e(i){return i?.oauth?.providerId?f.OAUTH:i?.credentials?.usernameLabel||i?.credentials?.passwordLabel?f.CREDENTIALS:i?.magicLink?.enabled?f.MAGIC_LINK:i?.otp?.enabled?f.OTP:f.CONSENT_ONLY}function St(i){return{title:i?.title??E.title,description:i?.description??E.description,expirationText:i?.expirationText??E.expirationText,cancelButtonText:i?.cancelButtonText??E.cancelButtonText,submitButtonText:i?.submitButtonText??E.submitButtonText,permissionsHeader:i?.permissionsHeader??E.permissionsHeader,autoClose:i?.autoClose??E.autoClose,popupEnabled:i?.popupEnabled??E.popupEnabled,theme:i?.theme??E.theme}}function _t(i){return{text:i?.text??K.text,url:i?.url,version:i?.version,required:i?.required??K.required}}function Tt(i){return{title:i?.title??D.title,description:i?.description??D.description,showCredential:i?.showCredential??D.showCredential,redirectUrl:i?.redirectUrl,redirectDelay:i?.redirectDelay,continueButtonText:i?.continueButtonText??D.continueButtonText}}function Ce(i,t){let e=Ke(i?.branding),r=Je(i,t),s=St(i?.ui),o=_t(i?.terms),a=Tt(i?.success),p=Et(i?.customFields),c=At(i?.expirationDays),v=$e(i);return{branding:e,copy:r,ui:s,terms:o,success:a,customFields:p,expirationDays:c,authMode:v,credentials:i?.credentials,oauth:i?.oauth,magicLink:i?.magicLink,otp:i?.otp,qrCode:i?.qrCode,passkey:i?.passkey,idv:i?.idv}}var h=class extends g{constructor(){super(...arguments);this.tool="";this.scopes=[];this.agentDid="";this.sessionId="";this.projectId="";this.serverUrl="";this.agentName="";this.provider="";this.csrfToken="";this.credentialProviderType="";this.credentialProvider="";this.currentMode=f.CONSENT_ONLY;this.loading=!1;this.step="consent";this.termsAccepted=!1;this.formData={};this.resendCooldown=0;this.selectedScopes=[]}connectedCallback(){super.connectedCallback(),this.resolved=Ce(this.config,this.agentName),this.currentMode=this.mode??$e(this.config)??f.CONSENT_ONLY,this.selectedScopes=[...this.scopes]}disconnectedCallback(){super.disconnectedCallback(),this.resendCooldownInterval!==void 0&&(clearInterval(this.resendCooldownInterval),this.resendCooldownInterval=void 0)}updated(e){(e.has("config")||e.has("agentName"))&&(this.resolved=Ce(this.config,this.agentName)),e.has("mode")&&this.mode&&(this.currentMode=this.mode),e.has("scopes")&&(this.selectedScopes=[...this.scopes]),this.resolved&&(this.style.setProperty("--consent-primary",this.resolved.branding.primaryColor),this.style.setProperty("--consent-secondary",this.resolved.branding.secondaryColor))}getProviderType(){return this.currentMode===f.OAUTH&&this.oauthIdentity?.provider?this.oauthIdentity.provider:Ve(this.currentMode)}async handleApprove(e){if(e?.preventDefault(),!this.loading){if(!this.termsAccepted&&this.resolved?.terms.required){this.error="Please accept the terms to continue";return}if(this.scopes.length>0&&this.selectedScopes.length===0){this.error="Please select at least one permission";return}this.loading=!0,this.error=void 0;try{let r=new FormData;r.append("tool",this.tool),r.append("scopes",JSON.stringify(this.selectedScopes)),r.append("agent_did",this.agentDid),r.append("session_id",this.sessionId),r.append("project_id",this.projectId),r.append("auth_mode",this.currentMode),r.append("provider_type",this.getProviderType()),this.provider&&r.append("provider",this.provider),this.csrfToken&&r.append("csrf_token",this.csrfToken),r.append("termsAccepted",String(this.termsAccepted)),this.credentialProviderType&&r.append("credential_provider_type",this.credentialProviderType),this.credentialProvider&&r.append("credential_provider",this.credentialProvider),Object.entries(this.formData).forEach(([a,p])=>{r.append(a,p)});let s=await fetch(`${this.serverUrl}/consent/approve`,{method:"POST",body:r});if(!s.ok){let a=await s.json().catch(()=>({}));throw new Error(a.message||"Approval failed")}let o=await s.json();if(o.redirectUrl){this.dispatchEvent(new CustomEvent("mcp-consent:approve",{detail:{success:!0,redirectUrl:o.redirectUrl},bubbles:!0,composed:!0})),window.location.href=o.redirectUrl;return}this.step="success",this.dispatchEvent(new CustomEvent("mcp-consent:approve",{detail:{success:!0,delegationId:o.delegation_id},bubbles:!0,composed:!0}))}catch(r){this.error=r instanceof Error?r.message:"Unknown error",this.dispatchEvent(new CustomEvent("mcp-consent:error",{detail:{error:this.error},bubbles:!0,composed:!0}))}finally{this.loading=!1}}}handleDeny(){this.dispatchEvent(new CustomEvent("mcp-consent:deny",{bubbles:!0,composed:!0})),window.close()}handleTermsChange(e){this.termsAccepted=e.detail.checked}handleInputChange(e,r){this.formData={...this.formData,[e]:r}}handleResendOtp(){if(this.resendCooldown>0)return;let e=this.resolved?.otp?.resendCooldown??60;this.resendCooldown=e,this.resendCooldownInterval!==void 0&&clearInterval(this.resendCooldownInterval),this.resendCooldownInterval=setInterval(()=>{this.resendCooldown--,this.resendCooldown<=0&&(clearInterval(this.resendCooldownInterval),this.resendCooldownInterval=void 0)},1e3),this.dispatchEvent(new CustomEvent("mcp-consent:resend-otp",{bubbles:!0,composed:!0}))}renderAgentInfo(){let e=this.agentName||"this agent";return d`
1067
+ `,n([l({type:Number})],A.prototype,"length",2),n([l({type:String})],A.prototype,"name",2),n([l({type:String})],A.prototype,"value",2),n([l({type:Boolean,reflect:!0})],A.prototype,"disabled",2),n([l({type:Boolean,reflect:!0})],A.prototype,"error",2),n([l({type:Boolean,attribute:"auto-focus"})],A.prototype,"autoFocus",2),n([l({type:String,attribute:"input-type"})],A.prototype,"inputType",2),n([w()],A.prototype,"digits",2),n([He("input")],A.prototype,"inputs",2),A=n([x("consent-otp-input")],A);var f={CONSENT_ONLY:"consent-only",CREDENTIALS:"credentials",OAUTH:"oauth",MAGIC_LINK:"magic-link",OTP:"otp",QR_CODE:"qr-code",PASSKEY:"passkey",IDV:"idv"},L={NONE:"none",PASSWORD:"password",OAUTH2:"oauth2",MAGIC_LINK:"magic_link",OTP:"otp"},vt={[f.CONSENT_ONLY]:L.NONE,[f.CREDENTIALS]:L.PASSWORD,[f.OAUTH]:L.OAUTH2,[f.MAGIC_LINK]:L.MAGIC_LINK,[f.OTP]:L.OTP,[f.QR_CODE]:L.NONE,[f.PASSKEY]:L.NONE,[f.IDV]:L.NONE};function Ve(i){return vt[i]??L.NONE}var Y={PRIMARY:"#2563EB",SECONDARY:"#DBEAFE",BACKGROUND:"#F9FAFB",TEXT_PRIMARY:"#111827",TEXT_SECONDARY:"#6B7280",TEXT_MUTED:"#9CA3AF",BORDER:"#E5E7EB",BORDER_DARK:"#D1D5DB",SUCCESS:"#16A34A",ERROR:"#DC2626",WARNING:"#F59E0B"};var fi={primaryColor:Y.PRIMARY,secondaryColor:Y.SECONDARY,logoUrl:void 0,companyName:void 0},E={title:"Permission request",description:"It looks like you would like to use [AI Agent] to access resources on your behalf.",expirationText:"This delegation will expire in",cancelButtonText:"Cancel",submitButtonText:"Allow access",permissionsHeader:"The agent is requesting the following permissions:",autoClose:!1,popupEnabled:!1,theme:"auto"},K={text:"Terms and Conditions",url:void 0,version:void 0,required:!0},D={title:"Access Granted",description:"The agent now has permission to act on your behalf.",showCredential:!0,redirectUrl:void 0,redirectDelay:void 0,continueButtonText:"Close"};var je=30;function yt(i){return i?/^#[0-9A-Fa-f]{6}$/.test(i):!1}function Ge(i,t){return yt(i)?i:t}function bt(i){if(!i)return!1;try{let t=new URL(i);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}function xt(i){if(bt(i))return i}function Ye(i){let t=i.replace(/^#/,""),e=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),s=parseInt(t.slice(4,6),16);return`${e}, ${r}, ${s}`}function wt(i){return{"--consent-primary":i.primaryColor,"--consent-secondary":i.secondaryColor,"--consent-primary-rgb":Ye(i.primaryColor),"--consent-secondary-rgb":Ye(i.secondaryColor)}}function Ke(i){let t=Ge(i?.primaryColor,Y.PRIMARY),e=Ge(i?.secondaryColor,Y.SECONDARY),r=xt(i?.logoUrl),s=i?.companyName?.trim()||void 0,o=wt({primaryColor:t,secondaryColor:e});return{primaryColor:t,secondaryColor:e,logoUrl:r,companyName:s,cssVars:o}}var $t="[AI Agent]";function We(i,t){return t?i.replace(new RegExp(Ct($t),"g"),t):i}function Ct(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Je(i,t){let e=i?.ui??{},r=i?.terms??{},s=i?.success??{},o=e.title??E.title,a=e.description??E.description,p=e.expirationText??E.expirationText,c=e.cancelButtonText??E.cancelButtonText,v=e.submitButtonText??E.submitButtonText,b=e.permissionsHeader??E.permissionsHeader,m=r.text??K.text,k=s.title??D.title,R=s.description??D.description,z=We(a,t),Qe=We(R,t);return{title:o,description:a,expirationText:p,cancelButtonText:c,submitButtonText:v,permissionsHeader:b,termsText:m,termsUrl:r.url,termsRequired:r.required??K.required,resolvedDescription:z,successTitle:k,successDescription:R,resolvedSuccessDescription:Qe,showCredential:s.showCredential??D.showCredential,continueButtonText:s.continueButtonText??D.continueButtonText}}function Et(i){return!i||i.length===0?[]:i.slice(0,10).filter(e=>!(!e.name||!e.label||!/^[a-zA-Z0-9_]+$/.test(e.name)||e.type==="select"&&(!e.options||e.options.length===0)))}function At(i){return i==null?je:i<1?1:i>365?365:Math.floor(i)}function $e(i){return i?.oauth?.providerId?f.OAUTH:i?.credentials?.usernameLabel||i?.credentials?.passwordLabel?f.CREDENTIALS:i?.magicLink?.enabled?f.MAGIC_LINK:i?.otp?.enabled?f.OTP:f.CONSENT_ONLY}function St(i){return{title:i?.title??E.title,description:i?.description??E.description,expirationText:i?.expirationText??E.expirationText,cancelButtonText:i?.cancelButtonText??E.cancelButtonText,submitButtonText:i?.submitButtonText??E.submitButtonText,permissionsHeader:i?.permissionsHeader??E.permissionsHeader,autoClose:i?.autoClose??E.autoClose,popupEnabled:i?.popupEnabled??E.popupEnabled,theme:i?.theme??E.theme}}function _t(i){return{text:i?.text??K.text,url:i?.url,version:i?.version,required:i?.required??K.required}}function Tt(i){return{title:i?.title??D.title,description:i?.description??D.description,showCredential:i?.showCredential??D.showCredential,redirectUrl:i?.redirectUrl,redirectDelay:i?.redirectDelay,continueButtonText:i?.continueButtonText??D.continueButtonText}}function Ce(i,t){let e=Ke(i?.branding),r=Je(i,t),s=St(i?.ui),o=_t(i?.terms),a=Tt(i?.success),p=Et(i?.customFields),c=At(i?.expirationDays),v=$e(i);return{branding:e,copy:r,ui:s,terms:o,success:a,customFields:p,expirationDays:c,authMode:v,credentials:i?.credentials,oauth:i?.oauth,magicLink:i?.magicLink,otp:i?.otp,qrCode:i?.qrCode,passkey:i?.passkey,idv:i?.idv}}var h=class extends g{constructor(){super(...arguments);this.tool="";this.scopes=[];this.agentDid="";this.sessionId="";this.projectId="";this.serverUrl="";this.agentName="";this.provider="";this.csrfToken="";this.credentialProviderType="";this.credentialProvider="";this.userDid="";this.currentMode=f.CONSENT_ONLY;this.loading=!1;this.step="consent";this.termsAccepted=!1;this.formData={};this.resendCooldown=0;this.selectedScopes=[]}connectedCallback(){super.connectedCallback(),this.resolved=Ce(this.config,this.agentName),this.currentMode=this.mode??$e(this.config)??f.CONSENT_ONLY,this.selectedScopes=[...this.scopes]}disconnectedCallback(){super.disconnectedCallback(),this.resendCooldownInterval!==void 0&&(clearInterval(this.resendCooldownInterval),this.resendCooldownInterval=void 0)}updated(e){(e.has("config")||e.has("agentName"))&&(this.resolved=Ce(this.config,this.agentName)),e.has("mode")&&this.mode&&(this.currentMode=this.mode),e.has("scopes")&&(this.selectedScopes=[...this.scopes]),this.resolved&&(this.style.setProperty("--consent-primary",this.resolved.branding.primaryColor),this.style.setProperty("--consent-secondary",this.resolved.branding.secondaryColor))}getProviderType(){return this.currentMode===f.OAUTH&&this.oauthIdentity?.provider?this.oauthIdentity.provider:Ve(this.currentMode)}async handleApprove(e){if(e?.preventDefault(),!this.loading){if(!this.termsAccepted&&this.resolved?.terms.required){this.error="Please accept the terms to continue";return}if(this.scopes.length>0&&this.selectedScopes.length===0){this.error="Please select at least one permission";return}this.loading=!0,this.error=void 0;try{let r=new FormData;r.append("tool",this.tool),r.append("scopes",JSON.stringify(this.selectedScopes)),r.append("agent_did",this.agentDid),r.append("session_id",this.sessionId),r.append("project_id",this.projectId),r.append("auth_mode",this.currentMode),r.append("provider_type",this.getProviderType()),this.provider&&r.append("provider",this.provider),this.csrfToken&&r.append("csrf_token",this.csrfToken),r.append("termsAccepted",String(this.termsAccepted)),this.credentialProviderType&&r.append("credential_provider_type",this.credentialProviderType),this.credentialProvider&&r.append("credential_provider",this.credentialProvider),this.userDid&&r.append("user_did",this.userDid),Object.entries(this.formData).forEach(([a,p])=>{r.append(a,p)});let s=await fetch(`${this.serverUrl}/consent/approve`,{method:"POST",body:r});if(!s.ok){let a=await s.json().catch(()=>({}));throw new Error(a.message||"Approval failed")}let o=await s.json();if(o.redirectUrl){this.dispatchEvent(new CustomEvent("mcp-consent:approve",{detail:{success:!0,redirectUrl:o.redirectUrl},bubbles:!0,composed:!0})),window.location.href=o.redirectUrl;return}this.step="success",this.dispatchEvent(new CustomEvent("mcp-consent:approve",{detail:{success:!0,delegationId:o.delegation_id},bubbles:!0,composed:!0}))}catch(r){this.error=r instanceof Error?r.message:"Unknown error",this.dispatchEvent(new CustomEvent("mcp-consent:error",{detail:{error:this.error},bubbles:!0,composed:!0}))}finally{this.loading=!1}}}handleDeny(){this.dispatchEvent(new CustomEvent("mcp-consent:deny",{bubbles:!0,composed:!0})),window.close()}handleTermsChange(e){this.termsAccepted=e.detail.checked}handleInputChange(e,r){this.formData={...this.formData,[e]:r}}handleResendOtp(){if(this.resendCooldown>0)return;let e=this.resolved?.otp?.resendCooldown??60;this.resendCooldown=e,this.resendCooldownInterval!==void 0&&clearInterval(this.resendCooldownInterval),this.resendCooldownInterval=setInterval(()=>{this.resendCooldown--,this.resendCooldown<=0&&(clearInterval(this.resendCooldownInterval),this.resendCooldownInterval=void 0)},1e3),this.dispatchEvent(new CustomEvent("mcp-consent:resend-otp",{bubbles:!0,composed:!0}))}renderAgentInfo(){let e=this.agentName||"this agent";return d`
1068
1068
  <div class="agent-info">
1069
1069
  <div class="agent-icon">
1070
1070
  <svg
@@ -1518,7 +1518,7 @@ var Xe=Object.defineProperty;var Ze=Object.getOwnPropertyDescriptor;var n=(i,t,e
1518
1518
  color: #9ca3af;
1519
1519
  cursor: not-allowed;
1520
1520
  }
1521
- `,n([l({type:Object,converter:{fromAttribute:e=>{if(e)try{return JSON.parse(e)}catch{return}},toAttribute:e=>e?JSON.stringify(e):""}})],h.prototype,"config",2),n([l({type:String})],h.prototype,"mode",2),n([l({type:String})],h.prototype,"tool",2),n([l({type:Array,converter:{fromAttribute:e=>{if(!e)return[];try{return JSON.parse(e)}catch{return[]}},toAttribute:e=>JSON.stringify(e)}})],h.prototype,"scopes",2),n([l({type:String,attribute:"agent-did"})],h.prototype,"agentDid",2),n([l({type:String,attribute:"session-id"})],h.prototype,"sessionId",2),n([l({type:String,attribute:"project-id"})],h.prototype,"projectId",2),n([l({type:String,attribute:"server-url"})],h.prototype,"serverUrl",2),n([l({type:String,attribute:"agent-name"})],h.prototype,"agentName",2),n([l({type:String,attribute:"provider"})],h.prototype,"provider",2),n([l({type:String,attribute:"csrf-token"})],h.prototype,"csrfToken",2),n([l({type:String,attribute:"preview-step"})],h.prototype,"previewStep",2),n([l({type:String,attribute:"credential-provider-type"})],h.prototype,"credentialProviderType",2),n([l({type:String,attribute:"credential-provider"})],h.prototype,"credentialProvider",2),n([l({type:Object,attribute:"oauth-identity",converter:{fromAttribute:e=>{if(e)try{return JSON.parse(e)}catch{return}},toAttribute:e=>e?JSON.stringify(e):""}})],h.prototype,"oauthIdentity",2),n([w()],h.prototype,"resolved",2),n([w()],h.prototype,"currentMode",2),n([w()],h.prototype,"loading",2),n([w()],h.prototype,"error",2),n([w()],h.prototype,"step",2),n([w()],h.prototype,"termsAccepted",2),n([w()],h.prototype,"formData",2),n([w()],h.prototype,"resendCooldown",2),n([w()],h.prototype,"selectedScopes",2),h=n([x("mcp-consent")],h);export{_ as ConsentButton,T as ConsentCheckbox,C as ConsentInput,S as ConsentOAuthButton,A as ConsentOTPInput,P as ConsentPermissions,I as ConsentShell,$ as ConsentTerms,h as McpConsent};
1521
+ `,n([l({type:Object,converter:{fromAttribute:e=>{if(e)try{return JSON.parse(e)}catch{return}},toAttribute:e=>e?JSON.stringify(e):""}})],h.prototype,"config",2),n([l({type:String})],h.prototype,"mode",2),n([l({type:String})],h.prototype,"tool",2),n([l({type:Array,converter:{fromAttribute:e=>{if(!e)return[];try{return JSON.parse(e)}catch{return[]}},toAttribute:e=>JSON.stringify(e)}})],h.prototype,"scopes",2),n([l({type:String,attribute:"agent-did"})],h.prototype,"agentDid",2),n([l({type:String,attribute:"session-id"})],h.prototype,"sessionId",2),n([l({type:String,attribute:"project-id"})],h.prototype,"projectId",2),n([l({type:String,attribute:"server-url"})],h.prototype,"serverUrl",2),n([l({type:String,attribute:"agent-name"})],h.prototype,"agentName",2),n([l({type:String,attribute:"provider"})],h.prototype,"provider",2),n([l({type:String,attribute:"csrf-token"})],h.prototype,"csrfToken",2),n([l({type:String,attribute:"preview-step"})],h.prototype,"previewStep",2),n([l({type:String,attribute:"credential-provider-type"})],h.prototype,"credentialProviderType",2),n([l({type:String,attribute:"credential-provider"})],h.prototype,"credentialProvider",2),n([l({type:String,attribute:"user-did"})],h.prototype,"userDid",2),n([l({type:Object,attribute:"oauth-identity",converter:{fromAttribute:e=>{if(e)try{return JSON.parse(e)}catch{return}},toAttribute:e=>e?JSON.stringify(e):""}})],h.prototype,"oauthIdentity",2),n([w()],h.prototype,"resolved",2),n([w()],h.prototype,"currentMode",2),n([w()],h.prototype,"loading",2),n([w()],h.prototype,"error",2),n([w()],h.prototype,"step",2),n([w()],h.prototype,"termsAccepted",2),n([w()],h.prototype,"formData",2),n([w()],h.prototype,"resendCooldown",2),n([w()],h.prototype,"selectedScopes",2),h=n([x("mcp-consent")],h);export{_ as ConsentButton,T as ConsentCheckbox,C as ConsentInput,S as ConsentOAuthButton,A as ConsentOTPInput,P as ConsentPermissions,I as ConsentShell,$ as ConsentTerms,h as McpConsent};
1522
1522
  /*! Bundled license information:
1523
1523
 
1524
1524
  @lit/reactive-element/css-tag.js: