@arcgis/coding-components
Version:
Contains components for editing code in different languages. The currently supported languages are html, css, json, TypeScript, JavaScript, and Arcade.
6 lines • 33.7 kB
JavaScript
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
v4.33.14 */
import{a as T}from"./YIHM5PLZ.js";import b from"./7TCVJENI.js";import{a as V,b as D}from"./ZWG62OP5.js";import{a as B}from"./KBSNSGW6.js";import"./FXJMBYDM.js";import a from"./AJJYACDZ.js";import"./WODQNPAA.js";import{i as L,j}from"./ESHR3OJV.js";import"./FBTENGUV.js";import{A as w,C as H,a as P,b as o,c as q,d as C,p as _,q as F,r as O,y as z}from"./MOODF6RJ.js";import{h as N}from"./SWSGV34B.js";import"./GMVUIEZO.js";import"./HAP7XW5O.js";export default $arcgis.t(([ae,G,oe,ce,{a:Q},S])=>{var k=class extends O{constructor(e){if(super(e),this.it=C,e.type!==_.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===C||e==null)return this._t=void 0,this.it=e;if(e===q)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;let t=[e];return t.raw=t,this._t={_$litType$:this.constructor.resultType,strings:t,values:[]}}};k.directiveName="unsafeHTML",k.resultType=1;var x=F(k);var re=P`:host(:not([closed])){--calcite-block-border-color: var(--calcite-color-transparent);flex:1 0 auto;border-inline-start:var(--arcgis-coding-components-border);box-sizing:border-box;max-width:var(--arcgis-coding-components-side-panel-max-w);width:var(--arcgis-coding-components-side-panel-w);.submission-actions-wrapper{display:flex;flex-direction:column;width:100%;gap:.75rem}.submission-actions{display:flex;flex-direction:row;gap:.5rem;justify-content:space-between}.gaps{display:flex;gap:.25rem}.align-inline-end{margin-inline-start:auto}.action .error-display{display:flex;flex-direction:row;gap:.5rem;justify-content:space-between}.context-popover p{padding:0 .5rem;font-size:var(--calcite-font-size-sm)}.prompt-list calcite-list-item{margin-block-end:.5rem;border-radius:var(--calcite-corner-radius-round);--calcite-color-border-3: transparent;overflow:hidden}.feedback-content{padding:1rem;display:flex;flex-direction:column;gap:.75rem;max-height:30vh;overflow-y:auto}.feedback-sheet{--calcite-sheet-height: auto;--calcite-sheet-max-height: 100%;--calcite-sheet-min-height: auto}calcite-chip[slot=header-actions-end]{align-self:center;margin-inline-end:.5rem}calcite-list-item:focus calcite-button{position:relative;top:-2px}.prompt-list calcite-list-item:last-of-type{margin-block-end:0}calcite-list{--calcite-color-foreground-1: transparent;background-color:transparent}calcite-list-item{--calcite-color-foreground-1: white}calcite-flow-item calcite-shell{background:transparent}calcite-block{width:100%;max-width:100%;align-self:flex-end;background-color:transparent;margin-block:0}calcite-sheet{--calcite-sheet-scrim-background: rgba(200, 200, 200, .5)}.type-suggestion{--calcite-color-foreground-1: var(--calcite-color-foreground-current);--calcite-color-text-3: var(--calcite-color-text-2);--calcite-icon-color: var(--calcite-color-brand)}.type-history{--calcite-icon-color: var(--calcite-color-text-2)}.type-response{--calcite-icon-color: var(--calcite-color-brand);--calcite-font-family: monospace}.block-response{align-self:flex-start;margin-block-end:4rem;border-block-end:0;--calcite-block-text-color: var(--calcite-color-brand)}calcite-list-item calcite-button{margin-inline-end:.25rem}.type-docs{--calcite-color-foreground-1: var(--calcite-color-foreground-3);--calcite-icon-color: var(--calcite-color-text-1)}.type-error{--calcite-icon-color: var(--calcite-color-status-danger);--calcite-font-family: monospace;border:1px solid var(--calcite-color-status-danger)}#thumbs-up{margin-inline-start:auto;--calcite-icon-color: var(--calcite-color-border-input)}#thumbs-down{--calcite-icon-color: var(--calcite-color-border-input)}calcite-flow-item calcite-shell calcite-notice{margin-block:1rem}.no-space-block,.no-space-block[open]{margin:0}calcite-block[open]:last-of-type{border-block-end:0}.text-area-wrapper{display:flex;border-radius:var(--calcite-corner-radius-round);margin:.75rem;overflow:hidden;--calcite-color-border-input: transparent;position:sticky;box-shadow:var(--calcite-shadow-sm);flex:none}calcite-text-area{height:auto;min-height:5.75rem;overflow:hidden;border-radius:var(--calcite-corner-radius-round) var(--calcite-corner-radius-round) 0 0;--calcite-font-weight-normal: 500;font-weight:500;line-height:1.2}calcite-tooltip{--calcite-tooltip-z-index: 1000}.standalone-list{margin:1rem;width:calc(100% - 2rem)}.result-disclaimer{display:block;width:24rem;max-width:90%;margin:1rem auto;text-align:center;line-height:1.125rem;font-size:.875rem;font-style:italic}calcite-flow{height:100%}calcite-popover calcite-list{--calcite-list-background-color: transparent;--calcite-input-border-color: transparent}calcite-popover calcite-list calcite-filter{--calcite-spacing-sm: 0}.break-spaces{white-space:break-spaces}.feedback-button-container{margin-inline-start:auto;gap:0}.info-heading{font-size:var(--calcite-font-size-1);color:var(--calcite-color-text-1)}.unstyled-h3{margin:unset;font-size:var(--calcite-font-size-md)}.unstyled-shell{position:unset;inset:unset;display:unset;block-size:unset;inline-size:unset}.suggestion-button{font-weight:var(--calcite-font-weight-medium)}.info-block{max-width:450px}#result-block{calcite-card-group{--calcite-card-group-gap: 1.25rem}calcite-card{--calcite-card-corner-radius: var(--calcite-corner-radius-round);--calcite-card-background-color: white;--calcite-card-border-color: transparent;width:100%}.positioned-code-content{display:flex;flex-direction:row;gap:.5rem;padding:.5rem}calcite-card [slot=title] calcite-chip{margin-block-start:.25rem}.code-response-wrapper{position:relative;background:var(--calcite-color-foreground-2);border-radius:var(--calcite-corner-radius-round);margin-top:-1.5rem}.prior-prompt{display:flex;flex-direction:row;padding:0;overflow-y:hidden;overflow-x:auto;margin:.25rem 0 .75rem;align-items:center;max-width:100%;span{overflow-x:auto;overflow-y:hidden}}.copy-feedback{display:none}.copy-prompt-button{align-self:flex-start;margin-inline-start:auto}.response-secondary-action-button[data-copied]+.copy-feedback,.copy-prompt-button[data-copied]+.copy-feedback{display:block;span{padding:.75rem 1rem;font-size:var(--calcite-font-size--2);line-height:1.375;color:var(--calcite-color-text--2);font-weight:var(--calcite-font-weight-medium)}}.copy-prompt-button[data-copied]~.copy-tooltip,.response-secondary-action-button[data-copied]~.copy-tooltip{display:none}code{white-space:pre;font-size:12px;margin:0;overflow-x:auto;font-family:Fira Mono,Consolas,Menlo,monospace;display:block;max-height:12rem;position:relative;padding:.5rem}.code-collapse{margin-inline-start:auto}.response-secondary-action-button{margin-left:.5rem}.add-to-editor-button{--calcite-internal-button-border-color: unset}}.collapsible-code{padding:.5rem}.collapsible-code summary{cursor:pointer;font-weight:500;color:var(--calcite-color-brand);outline:none;padding:.25rem 0}.collapsible-code[open] summary{color:var(--calcite-color-text-2)}.collapsible-error{padding:.5rem}.collapsible-error summary{cursor:pointer;font-weight:500;color:var(--calcite-color-status-danger);outline:none;padding:.25rem 0}.collapsible-error[open] summary{color:var(--calcite-color-text-2)}.response-error-container{padding:.5rem;background:color-mix(in srgb,var(--calcite-color-status-warning) 10%,transparent);border-radius:var(--calcite-corner-radius-round);margin:1rem 0;font-size:var(--calcite-font-size--2);--calcite-input-message-icon-color: var(--calcite-color-status-warning)}.response-error-chip{--calcite-internal-chip-background-color: var(--calcite-color-status-warning);--calcite-chip-icon-color: var(--calcite-color-foreground-1);--calcite-chip-border-color: var(--calcite-color-transparent)}.feedback-actions{gap:unset}}:host([closed]){display:none}`,v=class extends Error{constructor({message:e,code:t,subCode:s,details:n,source:r}){super(e),this.name="ArcadeAssistantError",this.code=t,this.subCode=s,this.details=n,this.source=r}};function J(i){if(!i)return;let e=i.indexOf('{"error":');if(e!==-1)try{let t=i.slice(e),s=JSON.parse(t);if(s&&typeof s=="object"&&s.error)return s.error}catch{return}}async function ne(i){let{baseUrl:e,skillId:t,message:s,authToken:n,previousConversationId:r,context:d}=i,p=t?`${e}/skills/${t}/chat`:`${e}/chat`,c=[],h={message:s,context:d};r&&(h.conversation_id=r);let a;try{a=await G(p,{method:"post",headers:{"Content-Type":"application/json",token:n},body:JSON.stringify(h),responseType:"json"})}catch(b){let f=b,A=f.details?.rawResponse||f.message||String(b),y=J(A);throw y?new v(y):b}let l=a.data;c.push(l);let u=l.conversationId,ee=l.inquiryId,R=l.sequenceNumber;async function te(){let b=0,f=25;for(;b<f;){await new Promise($=>setTimeout($,1e3));let A=le(u,R,ee),y;try{y=await G(p,{method:"post",headers:{"Content-Type":"application/json",token:n},body:JSON.stringify(A),responseType:"json"})}catch($){let M=$,se=M.details?.rawResponse||M.message||String($),U=J(se);throw U?new v(U):$}let g=y.data;if(g.context&&g.context.kind==="ArcgisErrorAsContext"&&g.context.error)throw new v({message:g.context.error.message||"ArcGIS Assistant error",code:g.context.error.code,subCode:g.context.error.subCode,details:g.context.error.details,source:"polling-response"});if(c.push(g),R=g.sequenceNumber,b++,!g.hasMore)break}if(b===f)throw new v({message:"Request timed out",code:"TIMEOUT",source:"polling"})}let ie=2*60*1e3;return await Promise.race([te(),new Promise((b,f)=>setTimeout(()=>f(new v({message:"Request timed out",code:"TIMEOUT",source:"hard-timeout"})),ie))]),c}function le(i,e,t){return{conversationId:i,inquiryId:t,ackSequenceNumber:e}}function de(i){return i.message.match(/Error in prompt shield/u)?"I'm having trouble with this request. Try again by rephrasing the question.":i.code==="TIMEOUT"?"I'm having trouble with this request. Try again by re-asking the same question or rephrasing it.":i.message}var pe=i=>{let e=i.value.length,t=72,s=180,n=i.offsetWidth,r=Math.max(1,Math.floor(n/8)),d=Math.ceil(e/r),p=t+(d-2)*24;i.style.setProperty("--calcite-text-area-min-height",`${Math.min(p,s)}px`)};function ue({messages:i}){return o`<calcite-chip slot=header-actions-end scale=s appearance=outline-fill .label=${i.beta??"Beta"}>${i.beta??"Beta"}</calcite-chip>`}function me({popoverContent:i}){return o`<calcite-action icon=information slot=header-actions-end id=legal-disclaimer text></calcite-action><calcite-popover reference-element=legal-disclaimer overlay-positioning=fixed label=legal-disclaimer placement=bottom auto-close>${i}</calcite-popover>`}function Z({errorMessage:i,slot:e}){return o`<div class="error-display"><calcite-input-message id=error-message status=invalid icon=exclamation-mark-triangle scale=m slot=${e??w}>${i}</calcite-input-message></div>`}function he({active:i,setActive:e,messages:t}){return o`<calcite-alert slot=alerts .open=${i} placement=bottom kind=success icon=check-circle-f auto-close @calciteAlertClose=${()=>e(!1)} .label=${t.expressionapplied??"Expression applied"}><div slot=message>${t.expressionapplied??"Expression applied to editor."}</div></calcite-alert>`}function ge({context:i,messages:e}){return i?o`<div class="gaps">${i.profileName&&o`<calcite-popover auto-close placement=top .label=${e.profilecontextlabel.replace("{profileName}",i.profileName)} reference-element=profile-context-button class="context-popover"><p>${e.profilecontextlabel.replace("{profileName}",i.profileName)}</p></calcite-popover><calcite-button round kind=neutral icon-start=map-information id=profile-context-button></calcite-button>`||""}${i.layerName&&o`<calcite-popover auto-close placement=top .label=${e.layercontextlabel.replace("{layerName}",i.layerName)} reference-element=layer-context-button class="context-popover"><p>${e.layercontextlabel.replace("{layerName}",i.layerName)}</p></calcite-popover><calcite-button round kind=neutral icon-start=layers id=layer-context-button></calcite-button>`||""}</div>`:null}function be({isDisabled:i,isReadOnly:e,setQuestion:t,setIsViewingResult:s,textAreaRef:n,question:r,errorMessage:d,setErrorMessage:p,submitQuestion:c,messages:h,mode:a,context:l}){return o`<div class="text-area-wrapper"><calcite-text-area resize=vertical .readOnly=${i||e} class="styled-text-area" .placeholder=${h.askaquestion??`Specify the calculation or logic you need in an Arcade expression. (e.g., 'Return "Yes" if value > 10')`} .value=${r} @calciteTextAreaInput=${u=>{pe(u.target),t(u.target.value)}} ${D(n)}><div class="submission-actions-wrapper" slot=footer-start>${d&&Z({errorMessage:d,slot:"footer-start"})||""}<div class="submission-actions">${ge({context:l,messages:h})}<div class="align-inline-end gaps"><calcite-button round kind=neutral .hidden=${a!=="refine"} icon-start=arrow-left icon-flip-rtl=both appearance=solid .disabled=${i} @click=${async()=>{s(!1),t("")}}>${h.startover??"Start Over"}</calcite-button><calcite-button round icon-end=effects appearance=solid .loading=${i} .disabled=${i} @click=${async()=>{p(r?"":h.enteraprompt??"Please enter a prompt"),await c()}}>${a==="prompt"?h.ask??"Generate":h.refine??"Refine"}</calcite-button></div></div></div></calcite-text-area></div>`}var fe="https://www.esri.com/en-us/privacy/privacy-statements/privacy-statement",ve="https://www.esri.com/en-us/privacy/privacy-statements/privacy-supplement";function ye({setOpen:i,messages:e,feedback:t,setFeedback:s,onSubmit:n}){return t.active?o`<calcite-sheet class="feedback-sheet" .label=${e.feedback??"Feedback"} slot=sheets display-mode=float position=block-end .open=${t.active} @calciteSheetClose=${()=>i(!1)}><calcite-panel .heading=${e.providefeedback??"Provide feedback"} .description=${e.experiencehelps??"Your experience helps guide future improvements"}><div class="feedback-content"><calcite-label>${e.experiencehelpful??"Was the assistant helpful?"}<calcite-segmented-control scale=l><calcite-segmented-control-item icon-start=thumbs-up .checked=${t.value==="good"} @click=${()=>s({...t,value:"good"})}></calcite-segmented-control-item><calcite-segmented-control-item icon-start=thumbs-down .checked=${t.value==="bad"} @click=${()=>s({...t,value:"bad"})}></calcite-segmented-control-item></calcite-segmented-control></calcite-label><calcite-label>${e.describeexperience??"Describe your experience"}<calcite-text-area resize=vertical .value=${t.text} @calciteTextAreaInput=${r=>s({...t,text:r.target.value})}></calcite-text-area></calcite-label><calcite-label layout=inline scale=s><calcite-checkbox scale=l .checked=${t.termsAccepted} @calciteCheckboxChange=${r=>{s({...t,termsAccepted:r.target.checked})}}></calcite-checkbox><span>${x(e.agreement?.replace("{EsriPrivacyStatement}",`<calcite-link href=${fe} target="_blank">${e.esriprivacystatement??"Esri Privacy Statement"}</calcite-link>`).replace("{Supplement}",`<calcite-link href=${ve} target="_blank">${e.supplement??"Supplement"}</calcite-link>`))}</span></calcite-label></div><calcite-button slot=footer width=full @click=${n} .disabled=${!t.termsAccepted||t.submitting} .loading=${t.submitting}>${e.submitfeedback??"Submit Feedback"}</calcite-button></calcite-panel></calcite-sheet>`:null}function Y({assistantsEnabled:i,messages:e,slot:t,assistantHelpUrl:s,helpTopicUrl:n}){return o`<calcite-block .label=${e.assistantinformation??"Assistant information"} slot=${t??w} expanded class="info-block"><calcite-chip .label=${e.new??"new"} kind=brand>${e.new}</calcite-chip><h1 class="info-heading">${e.introducing}</h1><p>${e.capabilities}</p>${i?o`<p>${e.keepinmind??"Keep in mind the following:"}<ul><li>${e.beconsise??"Be concise, but also clear in your request"}</li><li>${e.avoidambiguity??"Avoid ambiguity and vagueness"}</li><li>${e.moredetails??"you do not need to use exact field names in your instructions, but more detail is generally better"}</li></ul>${x((e.seedocumentation??"Please see the {documentation} for more information, including limitations and additional resources.").replace("{documentation}",`<calcite-link href=${n} target="_blank">${e.documentation??"documentation"}</calcite-link>`))}</p>`:o`<p>${x(e.useofassistant?.replace("{aiassistants}",`<strong>${e.aiassistants??"Ai Assistants"}</strong>`))}<calcite-link .href=${s} target=_blank icon-end=launch-2>${e.opensettings??"Open Settings"}</calcite-link></p>`}</calcite-block>`}function $e({messages:i,onProceed:e,onExit:t,helpTopicUrl:s}){return o`<calcite-dialog close-disabled placement=top .heading=${i.welcome} slot=dialogs open width-scale=m id=welcome-dialog><h3 class="unstyled-h3">${i.beforeyougetstarted}</h3><ul><li>${i.maybeincorrect}</li><li>${x(i.pleasereadhelp.replace("{helpTopic}",`<calcite-link href=${s} target="_blank">${i.helptopic}</calcite-link>`))}</li></ul><calcite-button id=welcome-proceed slot=footer-end @click=${e}>${i.proceed}</calcite-button><calcite-button id=welcome-decline slot=footer-start @click=${t} kind=neutral>${i.exit}</calcite-button></calcite-dialog>`}function ke({messages:i,suggestions:e,onSuggestionClick:t}){return o`<calcite-block .heading=${i.promptsuggestions} expanded collapsible id=suggestion-block><calcite-chip-group class="suggestions" .label=${i.promptsuggestions??"Prompt Suggestions"}>${T(e,s=>s,s=>o`<calcite-button round appearance=outline-fill kind=neutral .label=${i.promptsuggestion} class="suggestion-button" @click=${()=>t?.(s)}>${s}</calcite-button>`)}</calcite-chip-group></calcite-block>`}function W({hidden:i=!1,expanded:e=!1,messages:t,cards:s,heading:n,collapsible:r=!1,showEffectsIcon:d=!1,onCopyCode:p,standalone:c}){let h=t.addtoeditor??"Add to editor";return o`<calcite-block .hidden=${i} id=result-block .heading=${n??t.besteffort??"Here is the assistant's best effort"} .expanded=${e} .collapsible=${r}>${d&&o`<calcite-chip .label=${t.assistantresponses} slot=content-start icon=effects scale=m class="suggestion-chips"></calcite-chip>`||""}<calcite-card-group .label=${t.assistantresponses}>${T(s,a=>a.conversationId,a=>o`<calcite-card><div slot=heading><div class="prior-prompt"><span>${a.priorPrompt}</span><calcite-action icon=duplicate scale=s slot=actions-end class="copy-prompt-button" text .id=${`copy-prompt-${a.conversationId}-${c?"standalone":"list"}`} @click=${l=>{let u=l.currentTarget;navigator.clipboard.writeText(a.priorPrompt).then(()=>{u.setAttribute("data-copied","true"),setTimeout(()=>u.removeAttribute("data-copied"),1500)})}}></calcite-action><calcite-popover .referenceElement=${`copy-prompt-${a.conversationId}-${c?"standalone":"list"}`} placement=top-start class="copy-feedback" .label=${t.copiedsuccessfully??"copied successfully"} open trigger-disabled><span>${t.copiedsuccessfully??"copied successfully"}</span></calcite-popover><calcite-tooltip .referenceElement=${`copy-prompt-${a.conversationId}-${c?"standalone":"list"}`} placement=top-start class="copy-tooltip">${t.copyprompttoclipboard}</calcite-tooltip></div>${a.message&&c&&o`<div class="response-error-container">${Z({errorMessage:a.message})}</div>`||""}</div><div><div class="code-response-wrapper"><div class="positioned-code-content"><calcite-chip-group .label=${t.responsecontext??"Response Context"} scale=s>${a.message&&!c&&o`<calcite-tooltip .referenceElement=${`response-chip-${a.conversationId}-error`} placement=top-start overlay-positioning=fixed>${a.message}</calcite-tooltip><calcite-chip .id=${`response-chip-${a.conversationId}-error`} .label=${t.error??"Error"} scale=s appearance=outline icon=exclamation-mark-triangle-f class="response-error-chip"></calcite-chip>`||""}${a.chips?.map(l=>{let u=N();return o`${l.tooltip&&o`<calcite-tooltip .referenceElement=${`response-chip-${l.conversationId}-${u}`} placement=top-start overlay-positioning=fixed>${l.tooltip}</calcite-tooltip>`||""}<calcite-chip .label=${l.label} .scale=${l.scale??"s"} .appearance=${l.appearance??"outline"} .icon=${l.icon} .id=${`response-chip-${l.conversationId}-${u}`}>${l.label}</calcite-chip>`})}</calcite-chip-group></div><details class="collapsible-code" open><summary>Code response</summary><code>${a.code}</code></details></div></div><div slot=footer-start class="feedback-actions"><calcite-button primary-text=${h??w} class="add-to-editor-button" @click=${()=>a.onAddToEditor("add")} overlay-positioning=fixed scale=s icon-start=plus round>${t.addtoeditor??"Add to editor"}</calcite-button><calcite-button round icon-start=file-code kind=neutral scale=s @click=${()=>a.onAddToEditor("replace")} class="response-secondary-action-button" .id=${`replace-${a.conversationId}-${c?"standalone":"list"}`}></calcite-button><calcite-tooltip .referenceElement=${`replace-${a.conversationId}-${c?"standalone":"list"}`} placement=top-start><span>${t.replaceineditor??"Replace all code in editor"}</span></calcite-tooltip><calcite-button round icon-start=copy-to-clipboard kind=neutral scale=s @click=${l=>{let u=l.currentTarget;p(a.code).then(()=>{u.setAttribute("data-copied","true"),setTimeout(()=>u.removeAttribute("data-copied"),1500)})}} class="response-secondary-action-button" .id=${`copy-response-${a.conversationId}-${c?"standalone":"list"}`}></calcite-button><calcite-popover .referenceElement=${`copy-response-${a.conversationId}-${c?"standalone":"list"}`} placement=top-start class="copy-feedback" .label=${t.copiedsuccessfully??"copied successfully"} open trigger-disabled><span>${t.copiedsuccessfully??"copied successfully"}</span></calcite-popover><calcite-tooltip .referenceElement=${`copy-response-${a.conversationId}-${c?"standalone":"list"}`} placement=top-start class="copy-tooltip">${t.copytoclipboard}</calcite-tooltip></div><div slot=footer-end class="feedback-actions"><calcite-action .text=${t.thumbsup} scale=s icon=thumbs-up @click=${a.onThumbsUp} .id=${`thumbs-up-${a.conversationId}-${c?"standalone":"list"}`}></calcite-action><calcite-tooltip .referenceElement=${`thumbs-up-${a.conversationId}-${c?"standalone":"list"}`} placement=top-start><span>${t.helpful??"Helpful"}</span></calcite-tooltip><calcite-action .text=${t.thumbsdown} scale=s icon=thumbs-down @click=${a.onThumbsDown} .id=${`thumbs-down-${a.conversationId}-${c?"standalone":"list"}`}></calcite-action><calcite-tooltip .referenceElement=${`thumbs-down-${a.conversationId}-${c?"standalone":"list"}`} placement=top-start><span>${t.unhelpful??"Unhelpful"}</span></calcite-tooltip></div></calcite-card>`)}</calcite-card-group></calcite-block>`}var m={welcome:"Welcome to the new assistant experience",beforeyougetstarted:"Before you get started be aware:",maybeincorrect:"AI generated code may occasionally be incorrect or biased. Review carefully.",pleasereadhelp:"Read the Arcade Assistant (beta) {helpTopic} to get started and learn details on security, privacy and limitations.",proceed:"Proceed",exit:"Exit",promptsuggestions:"Prompt suggestions",promptsuggestion:"Prompt suggestion",assistantresponses:"Assistant responses",collapse:"Collapse",thumbsup:"Thumbs up",thumbsdown:"Thumbs down",refine:"Refine",startover:"Start over",helptopic:"help topic",agreement:"I agree to the {EsriPrivacyStatement} (and {Supplement}).",esriprivacystatement:"Esri Privacy Statement",supplement:"Supplement",disclaimerpt2:"AI-generated content may be inaccurate. Review before using.",replaceineditor:"Replace all code in editor",keepinmind:"Keep in mind the following:",beconsise:"Be concise, but also clear in your request",avoidambiguity:"Avoid ambiguity and vagueness",documentation:"documentation",useexamples:"Use examples to clarify your request",moredetails:"You do not need to use exact field names in your instructions, but more detail is generally better",seedocumentation:"Please see the {documentation} for more information, including limitations and additional resources.",assistantinformation:"Assistant information",profilecontextlabel:"Profile context: {profileName}",layercontextlabel:"Layer context: {layerName}",numlayers:"{numLayers} {layerOrLayers}",numlayersplural:"layers",numlayerssingular:"layer",responsecontext:"Response context",error:"Error",copytoclipboard:"Copy code to clipboard",copyprompttoclipboard:"Copy prompt to clipboard",copiedsuccessfully:"Copied successfully",helpful:"Helpful",unhelpful:"Unhelpful"},xe="arcade_generation",we="ArcadeCodeRequest",I="visualization",Ae="ArcadeAssistant",Ce=["your_comments","user_evaluation","question","answer","useragent","_source","version","context","extras"],K=[],X=!0,E=class extends z{constructor(){super(...arguments),this.textAreaRef=V(),this.messages=B(),this._feedbackService=void 0,this.handleFeedbackButton=(e,t)=>{this.feedback={active:!0,value:e,item:t,termsAccepted:!1,text:"",submitting:!1}},this.handleFeedbackSheetClose=()=>{this.feedback={active:!1}},this.handleFeedbackSubmit=async()=>{if(!this.feedback.active)return;this.feedback={...this.feedback,submitting:!0};let e=await this.ensureFeedbackService();if(!e){this.handleFeedbackSheetClose();return}let t=this.getModel(),s=t?await this.getProfileAndMetadata(t.uri):void 0,n={user_evaluation:this.feedback.value,your_comments:this.feedback.text||void 0,question:this.feedback.item?.question??"",answer:encodeURIComponent(this.feedback.item?.formattedScript??""),useragent:navigator.userAgent,_source:Ae,version:this.appVersion??"",context:s?JSON.stringify(s):"",extras:s?.profileName??"",conversation_id:this.feedback.item?.conversationId??"",privacy_statement:this.feedback.termsAccepted?"I_agree":""};try{await e.applyEdits({addFeatures:[new ce({attributes:n})]})}catch(r){console.error("Error submitting feedback:",r)}this.handleFeedbackSheetClose()},this.handleClose=e=>{this.closed=!0,this.closePanel?.(e)},this.setQuestion=e=>{this.question=e},this.onSuggestionClick=e=>{this.textAreaRef.value&&(this.textAreaRef.value.value=e,this.textAreaRef.value.setFocus(),this.setQuestion(e))},this.isViewingResult=!1,this.confirmationActive=!1,this.isSubmitting=!1,this.errorMessage=void 0,this.question="",this.history=[],this.feedback={active:!1},this.splashActive=!0,this.context=void 0,this.historyCards=[],this.helpBase="",this.assistantsEnabled=!1,this.closed=!1}static{this.properties={isViewingResult:16,confirmationActive:16,isSubmitting:16,errorMessage:16,question:16,history:16,feedback:16,splashActive:16,context:16,historyCards:16,closePanel:0,insertText:0,helpBase:1,assistantsEnabled:5,layer:[1,{type:Object}],portalUrl:1,serviceUrl:1,closed:7,editorRef:0,feedbackServiceUrl:1,appVersion:1}}static{this.styles=re}get disclaimerComment(){return`// ${this.messages.disclaimercomment}
// ${m.disclaimerpt2}`}get assistantHelpUrl(){return`${this.helpBase??"https://doc.arcgis.com/en/arcgis-online/"}administer/configure-assistants.htm`}get assistantOverviewDocUrl(){return`${this.helpBase??"https://doc.arcgis.com/en/arcgis-online/"}create-maps/understand-arcade-assistant.htm`}get usingTheAssitantDocUrl(){return`${this.helpBase??"https://doc.arcgis.com/en/arcgis-online/"}create-maps/use-arcade-assistant.htm`}async destroy(){}load(){let e=async()=>{let t=this.getModel();if(!t){this.context=void 0;return}let s=await this.getProfileAndMetadata(t.uri);this.context=s};e().catch(t=>{console.error("Error setting initial context in Arcade Assistant:",t)}),this.manager.onLifecycle(()=>({remove:S.onModelContextDidChange(async()=>{e().catch(t=>{console.error("Error setting context in Arcade Assistant:",t)})}).dispose}))}willUpdate(e){e.has("history")&&(this.historyCards=this.getHistoryCards())}connectedCallback(){super.connectedCallback(),this.history=K,this.splashActive=X}disconnectedCallback(){super.disconnectedCallback(),K=this.history,X=this.splashActive,this.copySuccessTimer&&(clearTimeout(this.copySuccessTimer),this.copySuccessTimer=void 0)}getHistoryCards(){return this.history.reduce((e,t)=>(!t.script||(e.push({priorPrompt:t.question,code:t.formattedScript||t.error||"",chips:[{label:t.profile??I,icon:"map-information",appearance:"outline",scale:"s",conversationId:t.conversationId??"",tooltip:m.profilecontextlabel.replace("{profileName}",t.profile??I)},...t.layerName?[{label:m.numlayers.replace("{numLayers}","1").replace("{layerOrLayers}",m.numlayerssingular),icon:"layer",appearance:"outline",scale:"s",conversationId:t.conversationId??"",tooltip:m.layercontextlabel.replace("{layerName}",t.layerName??"No layer")}]:[]],onAddToEditor:s=>{L(this.editorRef.editorInstance,t.formattedScript??"",s,this.disclaimerComment)},onThumbsUp:()=>this.handleFeedbackButton("good",t),onThumbsDown:()=>this.handleFeedbackButton("bad",t),conversationId:t.conversationId??"",message:t.message}),this.isViewingResult),e),[])}setFeedbackState(e){this.feedback=e}async ensureFeedbackService(){if(this._feedbackService)return this._feedbackService;if(!this.feedbackServiceUrl)return;let e=new oe({url:this.feedbackServiceUrl});await e.load();let t=Ce.filter(s=>!e.fields.some(n=>n.name===s));if(t.length>0){console.error(`Missing the following fields in feedback service: ${t.join(", ")}. Feedback will not be logged.`);return}return this._feedbackService=e,e}getModel(){return this.editorRef.editorInstance?.getModel()}async submitQuestion(){if(this.question){this.isSubmitting=!0;try{let e=await this.getToken(),t=this.getModel();if(!t)return;let{profileName:s,metadata:n,layerName:r}=await this.getProfileAndMetadata(t.uri),d=(await ne({baseUrl:this.serviceUrl,skillId:xe,message:this.question,authToken:e,context:{kind:we,context:{profile_name:s,metadata:n}}})).find(p=>p.context?.kind==="ArcadeCodeResponse");if(!d)return;d.context?.kind==="ArcadeCodeResponse"&&(this.history=[{script:d?.context?.arcadeCode?.code,formattedScript:j(d?.context?.arcadeCode?.code??""),error:void 0,question:this.question,profile:s,conversationId:d.conversationId,layerName:r??void 0,...d.message?{message:d.message}:{}},...this.history],this.isViewingResult=!0,this.errorMessage=void 0)}catch(e){e instanceof Error&&e.name==="ArcadeAssistantError"?this.errorMessage=de(e)||this.messages.erroroccurred||"An error occurred.":this.errorMessage=this.messages.erroroccurred||"An error occurred.",console.error("Error in Arcade Assistant:",e)}finally{this.isSubmitting=!1}}}async getToken(){let{token:e}=await ae.getCredential(this.portalUrl);return e}async getProfileAndMetadata(e){let t=I,s=S.getEditorProfileForModel(e);s?.loaded||await s?.loadSource();let n=this.editorRef.profile;n&&"id"in n&&(t=n.id);let r=s?.definition?.variables?.find(c=>c.type==="feature"),d=[],p;return r?.definition&&"fields"in r.definition&&(d=r.definition.fields.map(c=>({name:c.name,type:c.type,alias:c.alias})),Q(r?.definition)&&(p=r.definition.title)),{profileName:t,metadata:d,layerName:p}}onCopyCode(e){let t=e?`${this.disclaimerComment}
${e}`:"";return navigator.clipboard.writeText(t)}render(){return this.closed?null:this.assistantsEnabled?o`<calcite-flow><calcite-flow-item closable .heading=${this.messages.arcadeassistant??"Arcade assistant"} @calciteFlowItemClose=${this.handleClose}>${this.splashActive&&o`<calcite-scrim></calcite-scrim>`||""}${ue({messages:this.messages})}${me({popoverContent:Y({assistantsEnabled:this.assistantsEnabled,messages:{...this.messages,...m},assistantHelpUrl:this.assistantHelpUrl,helpTopicUrl:this.usingTheAssitantDocUrl})})}<calcite-shell class="unstyled-shell">${this.splashActive&&$e({messages:{...m,...this.messages},onProceed:()=>{this.splashActive=!1},helpTopicUrl:this.assistantOverviewDocUrl,onExit:e=>this.closePanel&&this.closePanel(e)})||""}${he({active:this.confirmationActive,setActive:e=>this.confirmationActive=e,messages:this.messages})}${be({isDisabled:this.isSubmitting,isReadOnly:!1,setQuestion:this.setQuestion,setIsViewingResult:e=>this.isViewingResult=e,mode:this.isViewingResult?"refine":"prompt",textAreaRef:this.textAreaRef,question:this.question,errorMessage:this.errorMessage,setErrorMessage:e=>this.errorMessage=e,submitQuestion:this.submitQuestion.bind(this),messages:{...m,...this.messages},context:this.context})}<calcite-block-group label="interactive blocks">${!this.isViewingResult&&!this.isSubmitting&&ke({messages:{...this.messages,...m},suggestions:["Round value to one decimal place",'Return "Yes" if value > 10'],onSuggestionClick:this.onSuggestionClick})||""}<calcite-block .hidden=${!this.isSubmitting} .heading=${this.messages.generatingresponse??"Generating response..."}></calcite-block>${W({expanded:this.isViewingResult,messages:{...this.messages,...m},collapsible:!0,showEffectsIcon:!0,cards:this.historyCards.length?[this.historyCards[0]]:[],heading:this.messages.besteffort??"Here's the assistant's best effort",hidden:this.isSubmitting||!this.isViewingResult,onCopyCode:this.onCopyCode.bind(this),standalone:!0})}${W({expanded:!this.isViewingResult,messages:{...this.messages,...m},collapsible:!0,cards:this.isViewingResult?this.historyCards.slice(1):this.historyCards,heading:this.messages.recentprompts??"Recent prompts",hidden:this.isSubmitting||this.history.length===0,onCopyCode:this.onCopyCode.bind(this)})}</calcite-block-group>${this.feedback.active?ye({setOpen:this.handleFeedbackSheetClose,messages:{...this.messages,...m},onSubmit:this.handleFeedbackSubmit,feedback:this.feedback,setFeedback:this.setFeedbackState.bind(this)}):null}</calcite-shell></calcite-flow-item></calcite-flow>`:o`<calcite-flow><calcite-flow-item .selected=${!this.isViewingResult} closable .heading=${this.messages.arcadeassistant??"Arcade assistant"} @calciteFlowItemClose=${this.handleClose}>${Y({slot:"content-top",messages:{...this.messages,...m},assistantsEnabled:this.assistantsEnabled,assistantHelpUrl:this.assistantHelpUrl,helpTopicUrl:this.usingTheAssitantDocUrl})}</calcite-flow-item></calcite-flow>`}};H("arcgis-arcade-coding-assistant",E);return E},"identity/IdentityManager","request","layers/FeatureLayer","Graphic",a,b)