performance.mark("js-parse-end:62874-5fda33c755233af4.js"); "use strict";(globalThis.webpackChunk_github_ui_github_ui=globalThis.webpackChunk_github_ui_github_ui||[]).push([["62874"],{31143(e,t,s){s.d(t,{Z:()=>r});function r(e){let t,s=null;return{load:()=>(s||(s=e().then(e=>t=e)),s),read(){if(t)return t;throw this.load()}}}},51586(e,t,s){s.d(t,{BV:()=>i,My:()=>o,QM:()=>n,ZK:()=>d});var r=s(58209),a=s(78597);async function i(e,t,s){let r=await (0,a.DI)(t,{method:"POST",body:c(e),signal:s}),i=await r.json();if(!r.ok)throw new d("Error creating policy",i.errors);if(!i.asset_upload_url)throw Error("Unexpected error, missing asset upload URL");return i}async function n(e,t,s){let a=await fetch(t.upload_url,{method:"POST",body:c({...t.form,file:e}),signal:s,credentials:(0,r.kA)()?"include":"same-origin"});if(!a.ok)throw Error(await a.text())}async function o(e,t){let s=await (0,a.DI)(e.asset_upload_url,{method:"PUT",signal:t}),r=await s.json();if(!s.ok)throw new d("Error completing the upload",r.errors);return r}class d extends Error{errors;constructor(e,t){super(e),this.name="GenericServerError",this.errors=t}}function c(e){let t=new FormData;for(let[s,r]of Object.entries(e).filter(([,e])=>null!=e))t.append(s,r);return t}},36248(e,t,s){s.d(t,{M:()=>o,O:()=>d});var r=s(74848),a=s(16522),i=s(96540);let n=(0,i.createContext)(null);function o(e){let t,s,o,d=(0,a.c)(7),{selectedThreadId:c,children:l}=e,[h,u]=(0,i.useState)();d[0]===Symbol.for("react.memo_cache_sentinel")?(t=e=>{u(e)},d[0]=t):t=d[0];let p=t;d[1]!==h||d[2]!==c?(s={selectedCopilotSpaceId:h,setSelectedCopilotSpaceId:p,selectedThreadId:c},d[1]=h,d[2]=c,d[3]=s):s=d[3];let g=s;return d[4]!==l||d[5]!==g?(o=(0,r.jsx)(n,{value:g,children:l}),d[4]=l,d[5]=g,d[6]=o):o=d[6],o}function d(){let e=(0,i.use)(n);if(!e)throw Error("useCopilotSpaceSelection must be used within a CopilotSpaceSelectionProvider");return e}n.displayName="CopilotSpaceSelectionContext",o.displayName="CopilotSpaceSelectionProvider"},94642(e,t,s){s.d(t,{Hb:()=>o,qw:()=>d});var r=s(74848),a=s(16522),i=s(96540);let n=(0,i.createContext)([]);function o(e){let t,s=(0,a.c)(3),{plugins:i,children:o}=e;return s[0]!==o||s[1]!==i?(t=(0,r.jsx)(n,{value:i,children:o}),s[0]=o,s[1]=i,s[2]=t):t=s[2],t}function d(){return(0,i.use)(n)}n.displayName="PluginsContext",o.displayName="ImmersivePluginsProvider"},27677(e,t,s){function r(e,t){if(e?.components)return e.components.find(e=>e.routes.some(e=>e instanceof RegExp?e.test(t.pathname):e(t)))}function a(e,t){let{pathname:s}=e;if(!s)return;let r={pathname:s,search:e.search||"",hash:e.hash||""};return t.find(e=>{var t,s;return!!e.components&&e.components.length>0&&(t=e,s=r,!!t.components&&t.components.length>0&&t.components.some(e=>e.routes.some(e=>e instanceof RegExp?e.test(s.pathname):e(s))))})}s.d(t,{BW:()=>a,bG:()=>r})},10881(e,t,s){s.d(t,{Pk:()=>x,mo:()=>B,Mj:()=>b,pn:()=>F,bP:()=>U,A3:()=>H,IJ:()=>k});var r=s(74848),a=s(16522),i=s(13865),n=s(96540),o=s(4216),d=s(36248);let c=(0,s(35205).A)("sessionStorage");function l(e,t){return!!e&&"assistive"===t}let h="restored-chat-messages";function u(e,t){if("childMessages"!==e&&"parentMessage"!==e)return t}function p(){c.removeItem(h)}var g=s(11515),E=s(49481),m=s(66743),f=s(68626),T=s(49685),I=s(10506),R=s(34019);let _=(e,t)=>{let s=t=>{I.Jt.selectedThreadID=t;let s=t!==e.selectedThreadID,r=I.Jt.getModel(t)?.id,a=e.availableModels?.find(e=>e.id===r)??e.model;return{...e,model:a,selectedThreadID:t,threadSelectedAt:s?new Date:e.threadSelectedAt,currentView:"thread",showTopicPicker:!t&&e.showTopicPicker,currentReferences:s?[]:e.currentReferences,threadHasNewMessages:!s&&e.threadHasNewMessages,editingMessage:s?void 0:e.editingMessage,pendingFirstMessage:s?void 0:e.pendingFirstMessage}};switch(t.type){case"SLASH_COMMANDS_ERROR":return(0,m.BI)("copilot.slash_commands_error"),{...e,slashCommandLoading:{...e.slashCommandLoading,state:"error"}};case"SLASH_COMMANDS_LOADED":return(0,m.BI)("copilot.slash_commands_loaded"),{...e,slashCommandLoading:{...e.slashCommandLoading,state:"loaded"}};case"SLASH_COMMANDS_LOADING":return{...e,slashCommandLoading:{...e.slashCommandLoading,state:"loading"}};case"OPEN_COPILOT_CHAT":return(0,m.BI)("copilot.open_copilot_chat",{source:t.source}),{...e,chatIsOpen:!0,chatIsVisible:!0,entryPointId:t.id};case"CLOSE_COPILOT_CHAT":return(0,m.BI)("copilot.close_copilot_chat"),{...e,chatIsOpen:!1};case"HIDE_COPILOT_CHAT":return(0,m.BI)("copilot.hide_copilot_chat"),{...e,chatIsVisible:!1};case"THREAD_CREATED":{let r=new Map(e.threads);return(0,m.BI)("copilot.thread_created",{...A(t.thread),mode:e.mode,count:r.size+1,defaultToAgent:T.W.defaultToAgentInput,defaultToAgentControl:T.W.defaultToAgentControl,askModeDropdown:T.W.askModeDropdown}),r.set(t.thread.id,t.thread),{...t.preventThreadSelection?e:s(t.thread.id),threads:r,pendingFirstMessage:e.pendingFirstMessage}}case"THREAD_CONTINUED":{let r=new Map(e.threads);return(0,m.BI)("copilot.thread_continued",{...A(t.thread),mode:e.mode,count:r.size+1}),r.set(t.thread.id,t.thread),{...s(t.thread.id),threads:r}}case"THREAD_CONTINUED_FAILED":return(0,m.BI)("copilot.thread_continued_failed",{stateSelectedThreadID:e.selectedThreadID,sharedIdOnFetch:e.fetchSharedThreads?.shareId,mode:e.mode}),{...e};case"SUGGESTIONS_GENERATED":return{...e,suggestions:t.suggestions};case"CLEAR_SUGGESTIONS":if(e.suggestionsContext)return e;return{...e,suggestions:null};case"CLEAR_THREAD":return(0,m.BI)("copilot.clear_thread"),{...e,messages:[],currentReferences:[]};case"CLEAR_CURRENT_REFERENCES":{(0,m.BI)("copilot.clear_current_references");let s=t.keepTypes&&new Set(t.keepTypes),r=s?e.currentReferences.filter(e=>s.has(e.type)):[];return{...e,currentReferences:r}}case"CLEAR_IMPLICIT_REFERENCES":{if(0===e.implicitReferences.size)return e;let t=e.currentReferences.filter(t=>!e.implicitReferences.has(t)),s=t.length===e.currentReferences.length?e.currentReferences:t;return{...e,currentReferences:s,implicitReferences:new Set}}case"PROMOTE_IMPLICIT_REFERENCE":{if(!e.implicitReferences.has(t.reference))return e;let s=new Set(e.implicitReferences);return s.delete(t.reference),{...e,implicitReferences:s}}case"CLEAR_ALL_REFERENCES":return(0,m.BI)("copilot.clear_all_references"),{...e,currentReferences:[]};case"MESSAGES_UPDATED":if("error"===t.state&&((0,m.BI)("copilot.messages_updated",{count:t.messages?.length,loading:t.state}),t.notFound&&t.missingOrgIds&&t.missingOrgIds.length>0&&I.Jt.clearAuthToken()),!t.messages)return{...e,messagesLoading:{...e.messagesLoading,state:t.state,missingOrgIds:t.missingOrgIds,notFound:t.notFound}};{let s=[...t.messages],r=e.messages.length>0&&e.messages.some(e=>"root"!==e.id&&e.clientSide),a=null!=e.pendingFirstMessage||e.isWaitingOnCopilot||null!=e.streamingMessage;if(0===s.length&&null!=e.selectedThreadID&&(r||a))return{...e,messagesLoading:{...e.messagesLoading,state:t.state,missingOrgIds:t.missingOrgIds,notFound:t.notFound}};let i=e.defaultRecipient,n=e.allClientConfirmations;for(let r of("loaded"===t.state&&s.length>0&&(i=M(s[s.length-1],e),n=s.map(e=>e.clientConfirmations?.map(e=>JSON.stringify(Object.values(e.confirmation).sort()))).flat().filter(Boolean)),s))r.clientSide=!1;return{...e,defaultRecipient:i,allClientConfirmations:n,messages:(0,f.zh)(s),messagesLoading:{...e.messagesLoading,state:t.state,missingOrgIds:t.missingOrgIds,notFound:t.notFound},messagesRestored:!1}}case"WAITING_ON_COPILOT":return{...e,isWaitingOnCopilot:t.loading,threadHasNewMessages:!0};case"WAITING_ON_ATTACHMENT":return{...e,isWaitingOnAttachment:t.loading,attachmentProcessingType:t.loading&&t.attachmentType||null};case"SELECT_THREAD":{(0,m.BI)("copilot.select_thread",{threadID:t.thread?.id,mode:e.mode});let r={...s(t.thread?.id||null),currentTopic:t.clearTopic?void 0:e.currentTopic,topicLoading:t.clearTopic?{error:null,state:"loaded"}:e.topicLoading};return null===t.thread&&e.currentRepository&&(r.currentReferences=[(0,g.qS)(e.currentRepository)]),r}case"HANDLE_EVENT_START":return(0,m.BI)("copilot.handle_event_start"),{...e,chatIsOpen:!0,chatIsVisible:!0,entryPointId:t.id,currentReferences:t.references??e.currentReferences,suggestionsContext:t.suggestionsContext,suggestions:t.suggestionsContext?(0,g.mx)({type:t.suggestionsContext}):e.suggestions,showTopicPicker:!t.suggestionsContext&&e.showTopicPicker,customInstructions:t.customInstructions??e.customInstructions};case"THREADS_LOADING":return{...e,threadsLoading:{...e.threadsLoading,state:"loading"}};case"LATEST_THREAD_LOADED":{let s=new Map(e.threads);return s.set(t.latestThread.id,t.latestThread),{...e,threads:s}}case"THREADS_LOADED":{(0,m.BI)("copilot.threads_loaded",{count:t.threads.length,mode:e.mode});let s=e.selectedThreadID&&e.threads.get(e.selectedThreadID);return s&&Date.now()-new Date(s.createdAt).getTime()<6e4&&!t.threads.find(e=>e.id===s.id)&&t.threads.push(s),{...e,threadsLoading:{...e.threadsLoading,state:"loaded"},threads:new Map(t.threads.map(e=>[e.id,e]))}}case"THREADS_LOADING_ERROR":return(0,m.BI)("copilot.threads_loading_error",{error:t.message}),{...e,threadsLoading:{error:t.message,state:"error",status:t.status}};case"DELETE_THREAD_KEEP_SELECTION":{let r=new Map(e.threads);return(0,m.BI)("copilot.thread_deleted",{...A(t.thread),count:r.size-1}),r.delete(t.thread.id),{...s(null),threads:r,threadsLoading:{...e.threadsLoading,state:"loaded"},messages:[],messagesLoading:{state:"loaded",error:null},currentReferences:[],currentView:"list"}}case"DELETE_ALL_THREADS_KEEP_SELECTION":{let r=new Map(e.threads);for(let e of t.threads)(0,m.BI)("copilot.thread_deleted",{...A(e),count:r.size-1}),r.delete(e.id);return{...s(null),threads:r,threadsLoading:{...e.threadsLoading,state:"loaded"},messages:[],messagesLoading:{state:"loaded",error:null},currentReferences:[],currentView:"list"}}case"DELETE_THREAD":{let r=new Map(e.threads);if((0,m.BI)("copilot.thread_deleted",{...A(t.thread),count:r.size-1,mode:e.mode}),r.delete(t.thread.id),e.selectedThreadID===t.thread.id)return{...s(null),threads:r,threadsLoading:{...e.threadsLoading,state:"loaded"},messages:[],messagesLoading:{state:"loaded",error:null},currentReferences:[]};return{...e,threads:r}}case"DELETE_THREAD_ERROR":{(0,m.BI)("copilot.delete_thread_error",{...A(t.thread),error:t.error});let s=new Map(e.threads);return s.set(t.thread.id,t.thread),{...e,threadsLoading:{...e.threadsLoading,error:t.error},threads:s}}case"DELETE_ALL_THREADS_ERROR":{for(let e of t.threads)(0,m.BI)("copilot.delete_thread_error",{...A(e),error:t.error});let s=new Map(e.threads);for(let e of t.threads)s.set(e.id,e);return{...e,threadsLoading:{...e.threadsLoading,error:t.error},threads:s}}case"MESSAGE_ADDED":{(0,m.BI)("copilot.message_added",{...C(t.message),count:e.messages.length+1,repoHasCustomInstructions:!!t.repoHasCustomInstructions,usedRepoCustomInstructions:!!t.usedRepoCustomInstructions,customInstructionsOwners:t.customInstructionsOwners||""});let s=(0,f.HR)(e.messages,t.message);return{...e,messages:s,messagesLoading:{state:"loaded",error:null},pendingFirstMessage:void 0,threadHasNewMessages:!0,editingMessage:void 0}}case"MESSAGE_FEEDBACK":{let s=[...e.messages],r=s.findIndex(e=>e.id===t.message.id),a=s[r];if(!a)return(0,m.BI)("copilot.message_feedback_no_message_found",{...C(t.message)}),e;return s[r]={...a,feedback:t.feedback},{...e,messages:s}}case"MESSAGES_SET_SELECTED_MESSAGE":{let s=(0,f.ws)(e.messages,t.message);return(0,m.BI)("copilot.chat_subthread_changed",{removedReferences:e.currentReferences.length}),{...e,messages:s,threadHasNewMessages:!1,threadSelectedAt:new Date}}case"MESSAGES_UNSELECT_PREVIOUS_MESSAGE":{let s=(0,f.TC)(e.messages,t.message);return{...e,messages:s,threadHasNewMessages:!1}}case"THREAD_UPDATED":return{...e,threads:S(e,t.thread)};case"REFERENCES_LOADED":return(0,m.BI)("copilot.references_loaded",{count:t.references.length}),{...e,currentReferences:e.currentReferences.filter(e=>t.references.every(t=>(0,g.Vb)(t)!==(0,g.Vb)(e))).concat(t.references)};case"ADD_REFERENCE":{let s=[...e.currentReferences.filter(e=>!(0,g.x_)(e,t.reference)),t.reference],r=e.implicitReferences;if(s.length>e.currentReferences.length&&((0,m.BI)("copilot.add_reference",{...D(t.reference),source:t.source,count:e.currentReferences.length+1,implicit:!!t.implicit}),"repository"===t.reference.type&&I.Jt.setLastUsedRepository(t.reference)),t.reference&&("issue"===t.reference.type||"pull-request"===t.reference.type||"discussion"===t.reference.type)&&(0,E.i)(`Adding ${t.reference.type} ${t.reference.number} as a reference.`),t.implicit){let e=new Set(r);e.add(t.reference),r=e}return{...e,currentReferences:s,implicitReferences:r}}case"REMOVE_REFERENCES":{let s=t.references;s.length>0&&(0,m.BI)("copilot.remove_reference",{count:e.currentReferences.length-s.length}),s[0]&&("issue"===s[0].type||"pull-request"===s[0].type||"discussion"===s[0].type)&&(0,E.i)(`Removing ${s[0].type} ${s[0].number} as a reference.`);let r=I.Jt.getCurrentReferences(e.selectedThreadID);if(r){let t=r.filter(e=>!s.some(t=>(0,g.x_)(t,e)));I.Jt.setCurrentReferences(e.selectedThreadID,t)}return{...e,currentReferences:e.currentReferences.filter(e=>!s.includes(e)),implicitReferences:new Set([...e.implicitReferences].filter(e=>!s.includes(e)))}}case"REPLACE_REFERENCE":{let s=[],r=e.implicitReferences;for(let a of e.currentReferences)if((0,g.x_)(a,t.referenceToDelete)){if(s.push(t.referenceToInsert),r.has(a)){let e=new Set(r);e.delete(a),e.add(t.referenceToInsert),r=e}}else(0,g.x_)(a,t.referenceToInsert)||s.push(a);return(0,m.BI)("copilot.replace_reference",{removedReference:(0,g.Vb)(t.referenceToDelete),addedReference:(0,g.Vb)(t.referenceToInsert),count:s.length}),{...e,implicitReferences:r,currentReferences:s}}case"SHOW_TOPIC_PICKER":return{...e,showTopicPicker:t.show};case"CURRENT_TOPIC_UPDATED":return t.topic&&(0,m.BI)("copilot.current_topic_updated",{type:t.topic?"repository":"none",mode:e.mode}),{...e,currentTopic:t.topic,topicLoading:{...e.topicLoading,state:t.state}};case"MESSAGE_STREAMING_STARTED":return(0,m.BI)("copilot.message_streaming_started",{...C(t.message),model:e.model?.id,mode:e.mode}),{...e,isWaitingOnCopilot:!0,streamingMessage:t.message,messages:[...e.messages]};case"MESSAGE_STREAMING_TOKEN_ADDED":return{...e,streamingMessage:e.streamingMessage?{...e.streamingMessage,content:e.streamingMessage.content+t.token}:null};case"MESSAGE_STREAMING_FUNCTION_CALLED":if(e.streamingMessage){let s=e.streamingMessage.skillExecutions||[],r=-1,a=(r=t.callId&&T.W.enableToolCallLogs?s.findIndex(e=>e.callId===t.callId):s.findIndex(e=>"started"===e.status||"progress"===e.status))>=0?s[r]:null,i=s,n=e.streamingMessage.references||[];switch(t.status){case"started":i=[...s,{slug:t.name,status:t.status,arguments:t.arguments,errorMessage:t.errorMessage,references:[],callId:t.callId}];break;case"progress":if(a){let e={...a,status:t.status,statusMessage:t.statusMessage};i=[...s.slice(0,r),e,...s.slice(r+1)]}break;case"completed":if(a){i=[...s];let e=a.references;a.references?.length||(e=t.references,n=Array.from(new Set([...n,...t.references]))),i[r]={...a,status:t.status,references:e}}else(0,m.BI)("copilot.function_call_missing_callid",{referenceCount:t.references.length,tool:t.name,callId:t.callId??"missing"});break;case"error":a&&((i=[...s])[r]={...a,status:t.status,errorMessage:t.errorMessage})}return{...e,streamingMessage:{...e.streamingMessage,skillExecutions:i,references:n}}}return e;case"MESSAGE_STREAMING_COMPLETED":{let s,r=e.defaultRecipient,a=e.messages;if(e.streamingMessage){let i=e.streamingMessage.skillExecutions;e.streamingMessage.skillExecutions&&(i=e.streamingMessage.skillExecutions.map(e=>"started"===e.status||"progress"===e.status?{...e,status:"completed"}:e)),r=M(s={...e.streamingMessage,id:t.messageResponse.id,references:t.messageResponse.references,createdAt:t.messageResponse.createdAt,intent:t.messageResponse.intent,copilotAnnotations:t.messageResponse.copilotAnnotations,parentMessageID:t.messageResponse.parentMessageID,model:t.messageResponse.model,clientSide:!1,skillExecutions:i},e),(0,m.BI)("copilot.message_streaming_completed",{...C(s),...y(t.timings),model:e.model?.id,mode:e.mode,count:e.messages.length+1}),e.streamingMessage.requestID&&I.Jt.addRequestID(s.id,e.streamingMessage?.requestID),a=(0,f.Y$)(a,s),a=(0,f.HR)(a,s)}return{...e,defaultRecipient:r,isWaitingOnCopilot:!1,streamingMessage:null,messages:a}}case"MESSAGE_STREAMING_FAILED":return(0,m.BI)("copilot.message_streaming_failed",{...e.streamingMessage?C(e.streamingMessage):{},...y(t.timings),model:e.model?.id,mode:e.mode}),{...e,isWaitingOnCopilot:!1,streamingMessage:null};case"MESSAGE_STREAMING_STOPPED":{let s,r=(0,f.B)(e.messages).findLast(e=>"user"===e.role)?.id;e.streamingMessage?(s={...e.streamingMessage,interrupted:!0,parentMessageID:r},(0,m.BI)("copilot.message_streaming_stopped",{...C(s),...y(t.timings),model:e.model?.id,mode:e.mode,count:e.messages.length+1})):e.isWaitingOnCopilot&&(s={id:crypto.randomUUID(),role:"assistant",threadID:e.selectedThreadID??"",references:[],createdAt:new Date().toISOString(),interrupted:!0,clientSide:!0,parentMessageID:r});let a=e.messages;if(null!=s){let e=a.findLast(e=>"user"===e.role);void 0!==e&&(s.parentMessageID=e.id),a=(0,f.HR)(a,s)}return{...e,isWaitingOnCopilot:!1,streamingMessage:null,messages:a}}case"MESSAGES_CLEAR_LAST_ERROR":{let t=(0,f.B)(e.messages),s=e.messages,r=t[t.length-1],a=r?.error||r?.interrupted,i=s;return a&&(i=s.filter(e=>e.id!==r?.id)),{...e,streamingMessage:null,messages:[...i]}}case"SELECT_REFERENCE":return t.reference&&(0,m.BI)("copilot.select_reference",D(t.reference)),{...e,selectedReference:t.reference};case"MODELS_LOADING":return{...e,modelsLoading:{state:"loading",error:null}};case"MODELS_LOADING_ERROR":return{...e,modelsLoading:{state:"error",error:t.error}};case"MODELS_LOADED":{let s=t.models;return T.W.visionAllowedInClaude||(s=t.models.map(e=>{if(e.id.startsWith("claude")){let t={...e};return t.capabilities.supports.vision=!1,t}return e})),{...e,model:(s||[]).find(t=>t.id===e.model.id)||e.model,availableModels:s||[],modelsLoading:{state:"loaded",error:null}}}case"SELECT_MODEL":{if("immersive"!==e.mode&&!T.W.immersiveEmbedded)return e;let s=t.model?.capabilities?.supports?.vision?e.currentReferences:e.currentReferences.filter(e=>"image"!==e.type);return(0,m.BI)("copilot.select_model",{model:t.model?.name,mode:e.mode}),{...e,model:t.model,currentReferences:s}}case"VIEW_ALL_THREADS":return{...e,currentView:"list"};case"VIEW_CURRENT_THREAD":return{...e,currentView:"thread"};case"IMPLICIT_CONTEXT_UPDATED":if(!(0,g.yR)(t.context,e.context))return{...e,context:t.context};return e;case"SET_TOP_REPOSITORIES":return{...e,topRepositoriesCache:t.topics};case"SET_AGENTS":return{...e,agents:t.agents};case"SET_CUSTOM_COPILOT":{let s=e.customCopilots?.find(e=>(0,R.UG)(e,t.customCopilot)),r=s&&t.partial,a=s?e.customCopilots?.map(e=>(0,R.UG)(e,s)?r?{...e,...t.customCopilot}:t.customCopilot:e):[...e.customCopilots??[],t.customCopilot];return{...e,customCopilots:a}}case"SET_CUSTOM_COPILOTS":return{...e,customCopilots:t.customCopilots};case"REMOVE_CUSTOM_COPILOT":return{...e,customCopilots:e.customCopilots?.filter(e=>!(0,R.UG)(e,t.customCopilotId))};case"SET_DEEP_CODESEARCH":return{...e,skillOptions:{...e.skillOptions,deepCodeSearch:t.deepCodeSearch}};case"MESSAGE_STREAMING_CONFIRMATION":{let s={title:t.title,message:t.message,confirmation:t.confirmation};return{...e,streamingMessage:e.streamingMessage?{...e.streamingMessage,confirmations:e.streamingMessage.confirmations?[...e.streamingMessage.confirmations,s]:[s]}:null}}case"AGENT_ERROR":{let s=e.streamingMessage,r=t.error;return{...e,streamingMessage:s&&{...s,agentErrors:[...s.agentErrors??[],{type:r.type,code:r.code,message:r.message,identifier:r.identifier}]}}}case"ENTITLEMENT_UPDATED":return{...e,entitlement:t.entitlement??e.entitlement};case"TOGGLE_REPO_CUSTOM_INSTRUCTIONS":return(0,m.BI)("copilot.repo_custom_instructions_toggled",{isEnabling:!!t.value}),{...e,repoCustomInstructionsEnabled:t.value};case"DISMISS_EDITOR_UPSELL_BANNER":return{...e,isEditorUpsellBannerDismissed:!0};case"DISMISS_COPILOT_SPACES_MCP_BANNER":return{...e,showCopilotSpacesMcpBanner:!1};case"DISMISS_AMBIENT_ERROR":return{...e,ambientError:null};case"ADD_AMBIENT_ERROR":return{...e,ambientError:{message:t.message}};case"SET_PERSONAL_INSTRUCTIONS":return{...e,personalInstructions:t.personalInstructions};case"SHARED_THREAD_UPDATED":{let s=S(e,t.thread),r=s.get(t.thread.id);return r&&(0,m.BI)("copilot.shared_thread_update",A(r)),{...e,threads:s}}case"SHARED_THREADS_LOADING":return{...e,sharedThreadsLoading:{...e.sharedThreadsLoading,state:"loading"}};case"SHARED_THREADS_LOADED":return(0,m.BI)("copilot.shared_threads_loaded"),{...e,sharedThreadsLoading:{...e.sharedThreadsLoading,state:"loaded"}};case"SHARED_THREADS_LOADING_ERROR":return(0,m.BI)("copilot.shared_threads_loading_error",{error:t.message}),{...e,sharedThreadsLoading:{...e.sharedThreadsLoading,state:"error",error:t.message}};case"IMAGE_UPLOADED":return{...e,currentReferences:e.currentReferences.map(e=>"image"===e.type&&e.id===t.referenceId?{...e,imageUrl:t.dotcomAttachment.previewUrl}:e)};case"START_EDITING_MESSAGE":return(0,m.BI)("dotcom_chat.activate",{target:"USER_MESSAGE_ACTION_EDIT",mode:"immersive"}),{...e,editingMessage:t.messageId};case"CANCEL_EDITING_MESSAGE":return{...e,editingMessage:void 0};case"FETCH_SHARED_THREAD_MESSAGES":return{...e,fetchSharedThreads:{ok:t.ok,status:t.status,shareId:t.shareId,originalThreadId:t.originalThreadId}};case"SET_WRAP_CODE_LINES":return{...e,wrapCodeLines:t.value};case"CLEAR_SHARED_THREAD_CHANNEL":return{...e,sharedThreadChannel:null};case"CLEAR_DEFAULT_RECIPIENT":return{...e,defaultRecipient:void 0};case"SET_PENDING_FIRST_MESSAGE":return{...e,pendingFirstMessage:t.message};case"SET_SHOULD_REPLACE_HISTORY_ON_NAVIGATION":return{...e,shouldReplaceHistoryOnNavigation:t.value}}};function S(e,t){let s=new Map(e.threads),r=e.threads.get(t.id);if(!r)return s;let a={...r,...t};return s.set(t.id,a),s}function C(e){var t;if(!e)return(0,m.Ti)({});let s={id:e.id,role:e.role,createdAt:e.createdAt,threadID:e.threadID,referenceCount:e.references?.length??0};return e.intent&&(s.intent=e.intent),e.error&&(s.error=e.error),e.copilotAnnotations&&(s.copilotAnnotations=function(e){if(e)return{CodeVulnerability:e.CodeVulnerability?.map(e=>({details:{type:e?.details?.type}})),PublicCodeReference:e.PublicCodeReference?.map(e=>({details:{license:e?.details?.license,language:e?.details?.language}}))}}(e.copilotAnnotations)),e.skillExecutions&&(s.skillExecutions=(t=e.skillExecutions)?t.map(e=>({slug:e?.slug,status:e?.status,argumentCount:e?.arguments?.length??0,errorMessage:e?.errorMessage,references:e?.references?.length??0})):[]),e.interrupted&&(s.interrupted=!0),(0,m.Ti)(s)}function A(e){return e?(0,m.Ti)({id:e.id,createdAt:e.createdAt,updatedAt:e.updatedAt,currentReferenceCount:e.currentReferences?.length??0}):(0,m.Ti)({})}function D(e){return e?(0,m.Ti)({type:e.type}):(0,m.Ti)({})}function y(e){let t={totalTime:e.endTime-e.startTime};return void 0!==e.firstByte&&(t.ttfb=e.firstByte-e.startTime),void 0!==e.firstToken&&(t.ttft=e.firstToken-e.startTime),t}function M(e,t){let s=(0,g.Th)(e,t.currentUserLogin);if("agent"===s.type)return s.name}var w=s(23184),O=s(12104),L=s(54726);let v=(0,n.createContext)(null);v.displayName="CopilotChatDispatchContext";let N=new Set;function b(e){var t,s,i,E;let m,T,R,S,C,A,D,y,M,L,b,P,x,B,F=(0,a.c)(71),{children:H,topic:U,workerPath:k,threadId:W,refs:V,selectedReference:J,mode:j,ssoOrganizations:q,chatIsOpen:z,chatIsVisible:$,chatVisibleSettingPath:K,agents:Y,customCopilots:X,messages:Q,testReducerState:Z,realIp:ee,currentView:et,copilotChatPayload:es}=e,er=function(e,t){let s,r,i,o=(0,a.c)(4),d=l(e,t);if(o[0]===Symbol.for("react.memo_cache_sentinel")){let e=c.getItem(h);s=e?JSON.parse(e):void 0,o[0]=s}else s=o[0];let u=s;if(o[1]===Symbol.for("react.memo_cache_sentinel")?(r=[],o[1]=r):r=o[1],(0,n.useEffect)(p,r),d&&u?.expiry&&u.expiry>Date.now()&&u.threadId===e){let e;return o[2]===Symbol.for("react.memo_cache_sentinel")?(e={restoredMessages:u.restoredMessages,restoredThreadTitle:u.threadTitle},o[2]=e):e=o[2],e}return o[3]===Symbol.for("react.memo_cache_sentinel")?(i={},o[3]=i):i=o[3],i}(W,j),ea=er.restoredMessages,ei=er.restoredThreadTitle;if(ea){let e;F[0]!==ea?(e=(0,f.zh)(ea),F[0]=ea,F[1]=e):e=F[1],ea=e}F[2]!==U?(m=U?(0,g.qS)(U):void 0,F[2]=U,F[3]=m):m=F[3];let en=m;F[4]===Symbol.for("react.memo_cache_sentinel")?(T=(0,O.fZ)(null,null),F[4]=T):T=F[4];let eo=T;F[5]!==Y||F[6]!==z||F[7]!==$||F[8]!==K||F[9]!==es.agentsEnabled||F[10]!==es.agentsPath||F[11]!==es.apiURL||F[12]!==es.autoSubmit||F[13]!==es.currentUserLogin||F[14]!==es.customCopilotsEnabled||F[15]!==es.customCopilotsIndividualAccessEnabled||F[16]!==es.customInstructions||F[17]!==es.hasCEorCBAccess||F[18]!==es.optedInToPreviewFeatures||F[19]!==es.optedInToUserFeedback||F[20]!==es.personalInstructions||F[21]!==es.plan||F[22]!==es.renderBetaLabel||F[23]!==es.reviewLab||F[24]!==es.sharedThreadChannel||F[25]!==es.showCopilotSpacesMcpBanner||F[26]!==es.showDecoupledPRModeBanner||F[27]!==et||F[28]!==X||F[29]!==Q||F[30]!==j||F[31]!==V||F[32]!==ea||F[33]!==ei||F[34]!==J||F[35]!==q||F[36]!==Z||F[37]!==W||F[38]!==U||F[39]!==en||F[40]!==k?(R=Z||{threadSelectedAt:new Date,threadsLoading:{state:"pending",error:null},messagesLoading:{state:"pending",error:null},messagesRestored:!!ea,slashCommandLoading:{state:"pending",error:null},showTopicPicker:"immersive"!==j&&(!W||"assistive"===j)&&!U,topicLoading:{state:"pending",error:null},threads:new Map,restoredThreadTitle:ei,model:eo,availableModels:[eo],modelsLoading:{state:"pending",error:null},messages:Q??ea??[],streamingMessage:null,selectedThreadID:W,currentTopic:void 0,chatIsOpen:!!z,isWaitingOnCopilot:!1,isWaitingOnAttachment:!1,attachmentProcessingType:null,currentUserLogin:es.currentUserLogin,apiUrl:es.apiURL,currentReferences:en?[en,...V]:V,implicitReferences:N,findFileWorkerPath:k,currentView:et||"thread",selectedReference:J??null,mode:j,currentRepository:U,ssoOrganizations:q,context:void 0,customInstructions:es.customInstructions,chatIsVisible:$,chatVisibleSettingPath:K,renderBetaLabel:es.renderBetaLabel,topRepositoriesCache:void 0,agentsPath:es.agentsPath,customCopilotsEnabled:es.customCopilotsEnabled??!1,customCopilotsIndividualAccessEnabled:es.customCopilotsIndividualAccessEnabled??!0,optedInToPreviewFeatures:es.optedInToPreviewFeatures,optedInToUserFeedback:es.optedInToUserFeedback,agents:Y,customCopilots:X,reviewLab:es.reviewLab,repoCustomInstructionsEnabled:I.Jt.getRepoCustomInstructionsState(),ambientError:void 0,personalInstructions:es.personalInstructions??null,threadHasNewMessages:!1,sharedThreadsLoading:{state:"pending",error:null},skillOptions:{deepCodeSearch:!1},wrapCodeLines:I.Jt.getWrapCodeLines(),showCopilotSpacesMcpBanner:es.showCopilotSpacesMcpBanner??!1,sharedThreadChannel:es.sharedThreadChannel,autoSubmit:es.autoSubmit??!1,plan:es.plan,hasCEorCBAccess:es.hasCEorCBAccess,agentsEnabled:es.agentsEnabled,showDecoupledPRModeBanner:es.showDecoupledPRModeBanner},F[5]=Y,F[6]=z,F[7]=$,F[8]=K,F[9]=es.agentsEnabled,F[10]=es.agentsPath,F[11]=es.apiURL,F[12]=es.autoSubmit,F[13]=es.currentUserLogin,F[14]=es.customCopilotsEnabled,F[15]=es.customCopilotsIndividualAccessEnabled,F[16]=es.customInstructions,F[17]=es.hasCEorCBAccess,F[18]=es.optedInToPreviewFeatures,F[19]=es.optedInToUserFeedback,F[20]=es.personalInstructions,F[21]=es.plan,F[22]=es.renderBetaLabel,F[23]=es.reviewLab,F[24]=es.sharedThreadChannel,F[25]=es.showCopilotSpacesMcpBanner,F[26]=es.showDecoupledPRModeBanner,F[27]=et,F[28]=X,F[29]=Q,F[30]=j,F[31]=V,F[32]=ea,F[33]=ei,F[34]=J,F[35]=q,F[36]=Z,F[37]=W,F[38]=U,F[39]=en,F[40]=k,F[41]=R):R=F[41];let ed=R,[ec,el]=(0,n.useReducer)(_,ed);return t=ec.messages,s=ec.selectedThreadID,i=ec.threads,E=ec.mode,(x=(0,a.c)(9))[0]!==E||x[1]!==s?(L=l(s,E),x[0]=E,x[1]=s,x[2]=L):L=x[2],B=L,x[3]!==t||x[4]!==B||x[5]!==s||x[6]!==i?(b=()=>{if(!B)return;let e=()=>{if(!t?.length||!s)return;let e=i.get(s),r=e?.name,a={expiry:Date.now()+8e3,restoredMessages:t,threadId:s,threadTitle:r};c.setItem(h,JSON.stringify(a,u))};return window.addEventListener("turbo:before-fetch-response",e),window.addEventListener("beforeunload",e),window.addEventListener("popstate",e),()=>{window.removeEventListener("turbo:before-fetch-response",e),window.removeEventListener("beforeunload",e),window.removeEventListener("popstate",e)}},P=[t,B,s,i],x[3]=t,x[4]=B,x[5]=s,x[6]=i,x[7]=b,x[8]=P):(b=x[7],P=x[8]),(0,n.useEffect)(b,P),F[42]!==ec.chatIsOpen||F[43]!==ec.currentReferences||F[44]!==ec.currentRepository?.id||F[45]!==ec.selectedThreadID?(S=function(){if(!ec.chatIsOpen)return;let e=ec.currentReferences.filter(e=>"repository"!==e.type||e.id!==ec.currentRepository?.id);I.Jt.setCurrentReferences(ec.selectedThreadID,e)},F[42]=ec.chatIsOpen,F[43]=ec.currentReferences,F[44]=ec.currentRepository?.id,F[45]=ec.selectedThreadID,F[46]=S):S=F[46],F[47]!==ec.chatIsOpen||F[48]!==ec.currentReferences||F[49]!==ec.currentRepository||F[50]!==ec.selectedThreadID?(C=[ec.selectedThreadID,ec.currentReferences,ec.currentRepository,ec.chatIsOpen],F[47]=ec.chatIsOpen,F[48]=ec.currentReferences,F[49]=ec.currentRepository,F[50]=ec.selectedThreadID,F[51]=C):C=F[51],(0,n.useEffect)(S,C),F[52]!==H||F[53]!==ec.selectedThreadID?(A=(0,r.jsx)(d.M,{selectedThreadId:ec.selectedThreadID,children:H}),F[52]=H,F[53]=ec.selectedThreadID,F[54]=A):A=F[54],F[55]!==es.apiURL||F[56]!==es.apiVersion||F[57]!==es.hasCEorCBAccess||F[58]!==ee||F[59]!==q||F[60]!==ec||F[61]!==A?(D=(0,r.jsx)(v,{value:el,children:(0,r.jsx)(w.v,{apiURL:es.apiURL,apiVersion:es.apiVersion,state:ec,dispatch:el,ssoOrganizations:q,realIp:ee,hasCEorCBAccess:es.hasCEorCBAccess,children:A})}),F[55]=es.apiURL,F[56]=es.apiVersion,F[57]=es.hasCEorCBAccess,F[58]=ee,F[59]=q,F[60]=ec,F[61]=A,F[62]=D):D=F[62],F[63]!==ec||F[64]!==D?(y=(0,r.jsx)(G,{state:ec,children:D}),F[63]=ec,F[64]=D,F[65]=y):y=F[65],F[66]!==es.licenseType||F[67]!==es.plan||F[68]!==es.quotas||F[69]!==y?(M=(0,r.jsx)(o.$d,{initialLicenseType:es.licenseType,initialPlan:es.plan,initialQuotas:es.quotas,children:y}),F[66]=es.licenseType,F[67]=es.plan,F[68]=es.quotas,F[69]=y,F[70]=M):M=F[70],M}b.displayName="CopilotChatProvider";let P=(0,n.createContext)(null);function G(e){let t,s,o,d,c=(0,a.c)(14),{state:l,children:h}=e,[u,p]=(0,i.XG)(l);return c[0]!==p||c[1]!==l||c[2]!==u.current.value?(t=()=>{l!==u.current.value&&p(l)},c[0]=p,c[1]=l,c[2]=u.current.value,c[3]=t):t=c[3],c[4]!==p||c[5]!==l||c[6]!==u?(s=[l,u,p],c[4]=p,c[5]=l,c[6]=u,c[7]=s):s=c[7],(0,n.useLayoutEffect)(t,s),c[8]!==h||c[9]!==l?(o=(0,r.jsx)(P,{value:l,children:h}),c[8]=h,c[9]=l,c[10]=o):o=c[10],c[11]!==u||c[12]!==o?(d=(0,r.jsx)(L.sw,{value:u,children:o}),c[11]=u,c[12]=o,c[13]=d):d=c[13],d}function x(){let e=(0,n.use)(P);if(!e)throw Error("useChatState can only be used inside a CopilotChatProvider");return e}function B(){return(0,n.use)(P)??void 0}function F(e){let t=(0,L.rE)();if(!t||!t.current)throw Error("useChatStateLens can only be used inside a CopilotChatProvider");let s=(0,i.Sk)(t.current,e);return(0,i.HN)(s)}function H(e){let t,s=(0,a.c)(2);return s[0]!==e?(t=t=>t[e],s[0]=e,s[1]=t):t=s[1],F(t)}function U(...e){let t,s=(0,a.c)(2);return s[0]!==e?(t=t=>(function(e,t){let s={};for(let r of t)s[r]=e[r];return s})(t,e),s[0]=e,s[1]=t):t=s[1],F(t)}function k(){let e=(0,n.use)(v);if(!e)throw Error("useChatDispatch can only be used inside a CopilotChatProvider");return e}P.displayName="ChatStateContext",G.displayName="ChatStateProvider"},23184(e,t,s){s.d(t,{b:()=>E,v:()=>g});var r=s(74848),a=s(16522),i=s(70170),n=s(96540),o=s(4216),d=s(21341),c=s(94642),l=s(31383),h=s(49685),u=s(54726);let p=(0,n.createContext)(null);function g(e){let t,s,g,E,m,f=(0,a.c)(24),{apiURL:T,state:I,dispatch:R,ssoOrganizations:_,children:S,realIp:C,hasCEorCBAccess:A,apiVersion:D}=e,y=(0,u.tD)(),M=(0,c.qw)(),w=(0,d.jR)();f[0]!==T||f[1]!==D||f[2]!==R||f[3]!==y||f[4]!==A||f[5]!==M||f[6]!==C||f[7]!==_||f[8]!==w?(t=new l.e8(R,T,_,y,C,void 0,A,M,D,w),f[0]=T,f[1]=D,f[2]=R,f[3]=y,f[4]=A,f[5]=M,f[6]=C,f[7]=_,f[8]=w,f[9]=t):t=f[9];let O=t,{licenseType:L}=(0,o.xR)(),v=(0,n.useRef)(I.currentReferences.length);return f[10]!==I.currentReferences.length?(s=()=>{v.current=I.currentReferences.length},f[10]=I.currentReferences.length,f[11]=s):s=f[11],(0,n.useEffect)(s),f[12]!==O||f[13]!==I.chatIsOpen||f[14]!==I.mode?(g=()=>{let e=new AbortController,t=h.W.immersiveEmbedded&&"immersive"===I.mode,s=async e=>{let t=window.location.hash,s=window.location.pathname,r=window.location.hash?`${s}${t}`:s,a=r.slice(1).split("/");if(a.length<2)return;let i=a[0],n=a[1];i&&n&&await O.fetchImplicitContext(r,i,n,e)},r=e=>{s(e)},a=(0,i.s)(()=>r(!t),500);return I.chatIsOpen&&(r(!0),!function(){let{replaceState:t,pushState:s}=window.history;window.history.replaceState=function(...e){t.apply(window.history,e),O.clearSuggestions(),window.dispatchEvent(new Event("replaceState"))},window.history.pushState=function(...e){s.apply(window.history,e),O.clearSuggestions(),window.dispatchEvent(new Event("pushState"))},window.addEventListener("popstate",a,{signal:e.signal}),window.addEventListener("replaceState",a,{signal:e.signal}),window.addEventListener("pushState",a,{signal:e.signal})}()),()=>{e.abort()}},f[12]=O,f[13]=I.chatIsOpen,f[14]=I.mode,f[15]=g):g=f[15],f[16]!==L||f[17]!==O||f[18]!==I.chatIsOpen||f[19]!==I.mode?(E=[O,I.chatIsOpen,I.mode,L],f[16]=L,f[17]=O,f[18]=I.chatIsOpen,f[19]=I.mode,f[20]=E):E=f[20],(0,n.useEffect)(g,E),f[21]!==S||f[22]!==O?(m=(0,r.jsx)(p,{value:O,children:S}),f[21]=S,f[22]=O,f[23]=m):m=f[23],m}function E(){let e=(0,n.use)(p);if(!e)throw Error("useChatManager must be used within a CopilotChatManagerProvider");return e}p.displayName="CopilotChatManagerContext",g.displayName="CopilotChatManagerProvider"},54726(e,t,s){s.d(t,{rE:()=>c,sw:()=>o,tD:()=>d});var r=s(74848),a=s(16522),i=s(96540);let n=(0,i.createContext)(null);function o(e){let t,s=(0,a.c)(3),{children:i,value:o}=e;return s[0]!==i||s[1]!==o?(t=(0,r.jsx)(n,{value:o,children:i}),s[0]=i,s[1]=o,s[2]=t):t=s[2],t}function d(){let e=(0,i.use)(n);if(!e||!e.current)throw Error("useGetChatState can only be used inside a CopilotChatProvider");return(0,i.useCallback)(()=>e.current.value,[e])}function c(){return(0,i.use)(n)}n.displayName="ObservableChatStateContext",o.displayName="ObservableChatStateProvider"},85285(e,t,s){s.d(t,{Qs:()=>d,fv:()=>i,uN:()=>a,wJ:()=>o,wX:()=>n,wg:()=>r});let r="copilot-chat-textarea",a="copilot-chat-topic-search",i="copilot-chat-header-button",n="copilot-diff-header-button",o="copilot-chat-panel",d="copilot-chat-panel"},31383(e,t,s){s.d(t,{L9:()=>S,e8:()=>D});var r=s(74848),a=s(3696),i=s(66743),n=s(51189),o=s(95751),d=s(78597),c=s(27677),l=s(85285),h=s(11515),u=s(56649),p=s(51261),g=s(68626),E=s(20331),m=s(49685),f=s(10506),T=s(81830),I=s(12104),R=s(96978),_=s(11222);let S=99,C="Only one agent is allowed per thread, and their context can't be shared. If you want to interact with another agent, please start a new thread and @ mention the new agent.",A=null;class D{dispatch;traceDispatch;service;getChatState;hasCEorCBAccess;timings={startTime:0};streamer;messageAbortController;reloadingThreadPromise;fetchingThreadID=null;afterThreadReloadCallback;isFirstMessageInNewThread=!1;plugins;eventCustomInstructions;constructor(e,t,s,r,a,i,n,o,d,c){this.dispatch=e,this.traceDispatch=c,this.service=i??new p.k(t,s,a,d),this.getChatState=r,this.hasCEorCBAccess=!!n,this.plugins=o}async fetchRepoForInstructions(e){let t=await this.service.fetchRepo(e);return t.ok?(0,h.qS)(t.payload):null}async openChat(e,t,s,r,a,i){if(this.dispatch({type:"OPEN_COPILOT_CHAT",source:s}),"thread"===t&&await this.findOrStartNewThread(e,a,i),f.Jt.setCollapsedState(!1),L(this.getChatState().entryPointId??l.fv,!0),r){let e=new FormData;e.set("copilot_chat_visible","true"),(0,d.DI)(r,{method:"PUT",body:e})}}closeChat(){this.dispatch({type:"CLOSE_COPILOT_CHAT"}),f.Jt.setCollapsedState(!0),L(this.getChatState().entryPointId??l.fv,!1)}hideChat(e){if(this.dispatch({type:"HIDE_COPILOT_CHAT"}),this.closeChat(),e){let t=new FormData;t.set("copilot_chat_visible","false"),(0,d.DI)(e,{method:"PUT",body:t})}}toggleRepoCustomInstructions(e){this.dispatch({type:"TOGGLE_REPO_CUSTOM_INSTRUCTIONS",value:e}),f.Jt.setRepoCustomInstructionsState(e)}viewAllThreads(){this.dispatch({type:"VIEW_ALL_THREADS"})}viewCurrentThread(){this.dispatch({type:"VIEW_CURRENT_THREAD"})}maxMessagesReached(){return this.getChatState().messages.length>=3e3}setShouldReplaceHistoryOnNavigation(e){this.dispatch({type:"SET_SHOULD_REPLACE_HISTORY_ON_NAVIGATION",value:e})}emitFirstMessageRenderedIfNeeded(){if(!this.isFirstMessageInNewThread)return;this.isFirstMessageInNewThread=!1;let{mode:e,model:t}=this.getChatState();(0,i.BI)("dotcom_chat.first_message_rendered",{mode:e,model:t?.id}),(0,n.au)({name:"COPILOT_DOTCOM_CHAT_FIRST_MESSAGE_RENDERED",value:1,tags:{mode:e}})}markFirstMessageInNewThread(){this.isFirstMessageInNewThread=!0}async sendChatMessage({thread:e,content:t,references:s,topic:r,context:a,confirmations:o,customInstructions:d,model:c,customCopilotId:l,intent:u,parentMessageId:p,modeOverride:g,skillOptions:E,noSend:m,mediaContent:f}){let T=e;if(!T){let e=(0,h.Y6)({role:"user",content:t,mediaContent:[],references:s});this.dispatch({type:"SET_PENDING_FIRST_MESSAGE",message:e});try{T=await this.createThread({customCopilotId:l})}catch(s){let e="An unexpected error has occurred.";return s instanceof Error&&(e=s.message),this.handleSendMessageError(T,w(e),t,"ERROR_THREAD_CREATION",e),null}}f||=s.length?await Promise.all(s.filter(e=>"image"===e.type).map(async e=>{let{attachment:s}=e;if(!s.threadID){s.threadID=T?.id||null;try{await s.prefetch()}catch{let e="An error occurred uploading image attachments";this.handleSendMessageError(T,w(e),t,"ERROR_IMAGE_UPLOAD",e)}}let r=await s.url(),a=s.file;return{mediaType:a.type,name:a.name,url:r,chatAttachmentUrl:r,width:s.width,height:s.height}})):[];let I=s.filter(e=>"image"!==e.type);if(I=I.filter(e=>"figma"!==e.type||!e.authenticationRequired),null!=T&&this.clearEditedReferencesFromSessionStorage(T.id),!e){let{mode:e}=this.getChatState();(0,i.BI)("dotcom_chat.first_message_sent",{mode:e,model:c?.id}),(0,n.au)({name:"COPILOT_DOTCOM_CHAT_FIRST_MESSAGE_SENT",value:1,tags:{mode:e}}),this.isFirstMessageInNewThread=!0}return m?{thread:T,references:I,mediaContent:f}:(await this.sendNewMessage(T,t,f,I,u,r,a,o,d,c,l,p,g,E),null)}FindLastMessageID(){let e=(0,g.B)(this.getChatState().messages);return e[e.length-1]?.id||"root"}async retryLastUnsuccessfulChatMessage(e){let{currentTopic:t,context:s,customInstructions:r,model:a}=this.getChatState(),i=(0,g.B)(this.getChatState().messages).findLast(e=>"user"===e.role);if(!i?.content)return;let n=i.references?.length?i.references:e.currentReferences??[],o=i.mediaContent||[];this.dispatch({type:"MESSAGES_CLEAR_LAST_ERROR"}),this.unselectPreviousChildMessage(i);let d="";if(i.clientSide){let e=(0,g.B)(this.getChatState().messages).findLast(e=>!e.clientSide);d=e?"user"===e.role?e.parentMessageID||"root":e.id:"root"}else d=i.id;return this.sendMessage(e,i.content,o,n,i.intent,s,t,r,a,void 0,d)}async retryUserChatMessage(e,t,s){let r,{currentTopic:a,context:i,customInstructions:n,model:o}=this.getChatState();if(t.parentMessageID&&(r=this.getChatState().messages.findLast(e=>e.id===t.parentMessageID)),!r||!r.content)return;this.unselectPreviousChildMessage(r);let d=r.references||[],c=r.mediaContent||[];return this.sendMessage(e,r.content,c,d,t.intent,i,a,n,s||o,void 0,r.id)}async editUserChatMessage(e,t,s){if(!s)return;let{currentTopic:r,context:a,customInstructions:i,messages:n,model:o}=this.getChatState(),d=(0,g.CX)(n,t);if(!d)return;let c=d?.id||"",l=t.clientConfirmations??[],u=t.references||[],p=t.mediaContent||[],E=(0,h.Y6)({role:"user",content:s,mediaContent:p,references:u,thread:e,confirmationResponses:l,parentMessageID:c}),f=m.W.customInstructionsFileReferences?await (0,h.f2)(u,e=>this.fetchRepoForInstructions(e)):(0,h.lG)(u),T=m.W.customInstructionsFileReferences?await (0,h.B5)(u,e=>this.fetchRepoForInstructions(e)):(0,h.j$)(u);if(this.dispatch({type:"MESSAGE_ADDED",message:E,repoHasCustomInstructions:!!f,usedRepoCustomInstructions:!!(f&&this.repoInstructionsEnabled()),customInstructionsOwners:T}),this.reloadingThreadPromise&&(this.dispatch({type:"WAITING_ON_COPILOT",loading:!0}),this.afterThreadReloadCallback=()=>{this.dispatch({type:"MESSAGE_ADDED",message:E,repoHasCustomInstructions:!!f,usedRepoCustomInstructions:!!(f&&this.repoInstructionsEnabled()),customInstructionsOwners:T})},!await this.reloadingThreadPromise))return;let I=d;for(;I&&I.clientSide;)I=(0,g.CX)(n,I);return this.sendMessage(e,s,p,u,t.intent,a,r,i,o,void 0,I?.id||"")}handleFeedback(e,t){this.dispatch({type:"MESSAGE_FEEDBACK",message:e,feedback:t})}setSelectedMessage(e){this.clearEditedReferencesFromSessionStorage(e.threadID),this.dispatch({type:"MESSAGES_SET_SELECTED_MESSAGE",message:e})}unselectPreviousChildMessage(e){this.dispatch({type:"MESSAGES_UNSELECT_PREVIOUS_MESSAGE",message:e})}async stopStreaming(){this.streamer?(await this.streamer.stop(),this.streamer=void 0):this.messageAbortController?.abort(),this.emitFirstMessageRenderedIfNeeded(),this.dispatch({type:"MESSAGE_STREAMING_STOPPED",timings:this.completeTiming()})}async getSystemPrompt(){let{mode:e}=this.getChatState(),t=m.W.immersiveEmbedded?"immersive":e;return await this.systemPrompt(t)}async createThread(e){let t,{customCopilotId:s,preventThreadSelection:r=!1,scopeId:a,savedMessageSource:i="immersive"}=e||{},n=await this.service.createThread(s,a);if(n.ok)return t=n.payload,f.Jt.migrateNullThreadToNewThread(t.id,i),this.dispatch({type:"THREAD_CREATED",thread:t,preventThreadSelection:r}),t;throw Error(n.error)}async sendNewMessage(e,t,s,r,a,o,d,c,l,u,p,E,T,I){let{mode:R}=this.getChatState(),_=(0,h.Y6)({role:"user",content:t,mediaContent:s,references:r,thread:e,confirmationResponses:c?[c]:[],parentMessageID:E||this.FindLastMessageID(),skillOptions:I}),S=m.W.customInstructionsFileReferences?await (0,h.f2)(r,e=>this.fetchRepoForInstructions(e)):(0,h.lG)(r),C=m.W.customInstructionsFileReferences?await (0,h.B5)(r,e=>this.fetchRepoForInstructions(e)):(0,h.j$)(r);if(this.dispatch({type:"MESSAGE_ADDED",message:_,repoHasCustomInstructions:!!S,usedRepoCustomInstructions:!!(S&&this.repoInstructionsEnabled()),customInstructionsOwners:C}),!e){(0,i.BI)("dotcom_chat.first_message_sent",{mode:R,model:u?.id}),(0,n.au)({name:"COPILOT_DOTCOM_CHAT_FIRST_MESSAGE_SENT",value:1,tags:{mode:R}}),this.isFirstMessageInNewThread=!0;try{e=await this.createThread({customCopilotId:p})}catch(r){let s="An unexpected error has occurred.";r instanceof Error&&(s=r.message),this.handleSendMessageError(e,w(s),t,"ERROR_THREAD_CREATION",s);return}}this.dispatch({type:"THREAD_UPDATED",thread:{id:e.id,updatedAt:new Date().toISOString()}}),this.dispatch({type:"CLEAR_CURRENT_REFERENCES"}),u&&("assistive"!==R||m.W.immersiveEmbedded)&&f.Jt.setModel(e.id,u,!1);let A="";if(!E){let e=(0,g.B)(this.getChatState().messages),t=e[e.length-1];if(E=t?t.clientSide?e.findLast(e=>!e.clientSide&&"assistant"===e.role)?.id||"root":t.id:"root",this.reloadingThreadPromise&&(this.dispatch({type:"WAITING_ON_COPILOT",loading:!0}),this.afterThreadReloadCallback=e=>{0!==e.length&&(_.parentMessageID=A=e[e.length-1].id,this.dispatch({type:"MESSAGE_ADDED",message:_,repoHasCustomInstructions:!!S,usedRepoCustomInstructions:!!(S&&this.repoInstructionsEnabled()),customInstructionsOwners:C}))},!await this.reloadingThreadPromise))return}return this.sendMessage(e,t,s,r,a,d,o,l,u,c,A||E,T,I)}async sendMessage(e,t,s,r,n,o,d,c,l,p,g,f,T){n??=E.wh.conversation;let I=(0,h.Y6)({role:"assistant",content:"",mediaContent:[],thread:e,parentMessageID:g});I.messageIndex=-1,this.dispatch({type:"WAITING_ON_COPILOT",loading:!0});let R=r.length&&(1!==r.length||r[0]?.type!=="repository")?void 0:o;(0,i.BI)("copilot.implicit_context",{usedImplicitContext:!!R,type:R?.[0]?.type,count:R?.length}),!r.length&&d&&(r=[(0,h.qS)(d)]);let _=[];if(this.repoInstructionsEnabled()){let e=m.W.customInstructionsFileReferences?await (0,h.hm)(r,e=>this.fetchRepoForInstructions(e)):(0,h.NJ)(r);_.push(...e)}c?.type!=="Organization"||_.find(e=>"Organization"===e.type)||_.push(c);let S=c??this.eventCustomInstructions;S?.type==="Assistant"&&_.push(S);let C=_.find(e=>"Organization"===e.type);C&&r.push((0,h.lj)(C.owner));let A=_.map(e=>e.prompt),{mode:D}=this.getChatState();this.timings={startTime:Date.now()},this.streamer=void 0,this.messageAbortController=new AbortController;try{let i={threadID:e.id,messageID:I.id,content:t,mediaContent:s,intent:n,mode:f||D,references:r,context:R??[],confirmations:p?[p]:[],customInstructions:A,model:l?.id,customCopilotID:(0,a.O)(e),parentMessageID:g,signal:this.messageAbortController.signal,skillOptions:T},o=this.activePlugin?.overrideCreateMessageOptions?await this.activePlugin.overrideCreateMessageOptions(i):i,d=await this.service.createMessageStreaming(o);if(d.ok){let s=d.response.body?.getReader();if(!s)return void this.handleSendMessageError(e,w(h.DW),t,"ERROR_STREAM_READER",h.DW);I.requestID=d.response.headers.get("x-github-request-id")||void 0;let r=new u.X(s);this.streamer=r,this.dispatch({type:"MESSAGE_STREAMING_STARTED",message:I}),await this.handleStreamingMessage(e,r),await this.generateThreadName(e)}else{if(this.messageAbortController.signal.aborted)return void this.emitFirstMessageRenderedIfNeeded();this.handleSendMessageError(e,w(d.error),t,"ERROR_MESSAGE_STREAMING",d.error)}}finally{this.streamer=void 0,this.messageAbortController=void 0}}repoInstructionsEnabled(){return!!f.Jt.getRepoCustomInstructionsState()}async populateReferenceLanguage(e){let t=await this.service.fetchLanguageForFileReference(e);if(t.ok&&t.payload.language){let{languageName:s,languageId:r}=t.payload.language;this.replaceReference(e,{...e,languageName:s,languageId:r})}}clearEditedReferencesFromSessionStorage(e){(0,o.zB)(`edited-${e}-`)}addReference(e,t,s={}){this.dispatch({type:"ADD_REFERENCE",reference:e,source:t,implicit:!!s.implicit}),(0,h.SI)(e)&&(void 0===e.languageId||void 0===e.languageName)&&this.populateReferenceLanguage(e)}removeReference(e){e&&(v([e]),this.dispatch({type:"REMOVE_REFERENCES",references:[e]}))}removeReferences(e){v(e),this.dispatch({type:"REMOVE_REFERENCES",references:e})}clearCurrentReferences=e=>{e&&e.includes("image")||v(this.getChatState().currentReferences),this.dispatch({type:"CLEAR_CURRENT_REFERENCES",keepTypes:e})};clearAllReferences=()=>{v(this.getChatState().currentReferences),this.dispatch({type:"CLEAR_ALL_REFERENCES"})};clearImplicitReferences(){this.dispatch({type:"CLEAR_IMPLICIT_REFERENCES"})}promoteImplicitReference(e){this.dispatch({type:"PROMOTE_IMPLICIT_REFERENCE",reference:e})}replaceReference(e,t){this.dispatch({type:"REPLACE_REFERENCE",referenceToDelete:e,referenceToInsert:t})}setImageAttachmentUploaded(e,t){this.dispatch({type:"IMAGE_UPLOADED",referenceId:e,dotcomAttachment:t})}selectModel(e,t=!0,s=!0){this.dispatch({type:"SELECT_MODEL",model:e}),t&&f.Jt.setModel(this.getChatState().selectedThreadID,e,s)}get activePlugin(){return(0,c.BW)(location,this.plugins)}setCopilotSettings(e){f.Jt.settings=e}async selectThread(e,t){let{clearTopic:s,includeThreads:r=!0}=t??{};await this.fetchModels(),await this.stopStreaming(),this.dispatch({type:"CLEAR_SHARED_THREAD_CHANNEL"}),this.dispatch({type:"SELECT_THREAD",thread:e,clearTopic:s});let a=[];a.push(this.fetchMessages(e?.id||null)),r&&a.push(this.fetchThreads()),await Promise.all(a)}addMessage(e,t,s,r,a,i,n){let o=(0,h.Y6)({role:e,content:s,mediaContent:r,references:a,thread:t,confirmationResponses:i,clientSkillConfirmations:n,parentMessageID:this.FindLastMessageID()});this.dispatch({type:"MESSAGE_ADDED",message:o})}async renameThread(e,t){(await this.service.renameThread(e.id,t)).ok&&this.dispatch({type:"THREAD_UPDATED",thread:{id:e.id,name:t}})}async generateThreadName(e){if(!e.id||""===e.id.trim())return;let t=this.getChatState().messages;if(""!==e.name&&t.length>8)return;let s=await this.service.generateThreadName(e.id);s.ok&&this.dispatch({type:"THREAD_UPDATED",thread:{id:e.id,name:s.payload}})}dismissAmbientError(){this.dispatch({type:"DISMISS_AMBIENT_ERROR"})}addAmbientError(e){this.dispatch({type:"ADD_AMBIENT_ERROR",message:e});let{mode:t}=this.getChatState();(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_AMBIENT",mode:t,message:e})}async clearThread(e){(await this.service.clearThread(e.id)).ok&&this.dispatch({type:"CLEAR_THREAD",threadID:e.id})}async deleteThreadKeepSelection(e){this.dispatch({type:"DELETE_THREAD_KEEP_SELECTION",thread:e});let t=await this.service.deleteThread(e.id);t.ok||this.dispatch({type:"DELETE_THREAD_ERROR",thread:e,error:t.error})}async deleteAllThreadKeepSelection(e){this.dispatch({type:"DELETE_ALL_THREADS_KEEP_SELECTION",threads:e});let t=e.map(e=>e.id);for(let s=0;s!0){return Array.from(e.values()).filter(e=>t(e)&&!e.scopeID).sort((e,t)=>new Date(t.updatedAt).getTime()-new Date(e.updatedAt).getTime())}async sendMessageToNewThread(e,t,s,r,a,i="immersive"){if(""===t.trim()){let[e,r]=this.tryInferMessage(s);if(!e||!r)return;t=r}e&&(f.Jt.setSavedMessageFast(e,i,null),f.Jt.clearCurrentReferences(e)),await this.sendNewMessage(null,t,[],s,void 0,void 0,r,void 0,void 0,a)}resolvePromise=()=>{};startThreadReload(){this.reloadingThreadPromise=new Promise(e=>{this.resolvePromise=e})}cancelThreadReload(){this.resolvePromise(!1),this.resolvePromise=()=>{},this.reloadingThreadPromise=void 0,this.afterThreadReloadCallback=void 0,this.fetchingThreadID=null}async fetchMessages(e,t=!1,s=!1){let r=f.Jt.getCurrentReferences(e);if(!e)return this.threadDataLoaded(e,[],r||[]),()=>{};t||this.dispatch({type:"MESSAGES_UPDATED",state:"loading"});let a=this.getChatState().messages;this.fetchingThreadID=e;let i=async s=>{let n=await this.service.listMessages(e);if(t&&this.fetchingThreadID!==e)return!1;if(!n.ok)return this.setMessageUpdatedError(n.status,n.payload?.missingOrgIds),this.afterThreadReloadCallback=void 0,!1;if(s&&n.payload.messages.length===a.length)return i(!1);{let t=n.payload.thread;return this.threadDataLoaded(e,n.payload.messages,r||t.currentReferences||[]),this.afterThreadReloadCallback&&(this.afterThreadReloadCallback(n.payload.messages),this.afterThreadReloadCallback=void 0),!0}},n=await i(s);return()=>{this.resolvePromise(n),this.resolvePromise=()=>{},this.reloadingThreadPromise=void 0}}async fetchSharedThreadMessages(e){if(!e)return;this.dispatch({type:"MESSAGES_UPDATED",state:"loading"});let t=await this.service.listSharedThreadMessages(e);if(this.dispatch({type:"FETCH_SHARED_THREAD_MESSAGES",ok:t.ok,status:t.status,shareId:e,originalThreadId:t.ok?t.payload.thread.id:void 0}),t.ok){this.threadDataLoaded(e,t.payload.messages,[]),await this.fetchModels();let s=t.payload.messages?.at(-1)?.model,r=s&&this.getChatState().availableModels?.find(e=>e.id===s);r&&this.selectModel(r)}else this.setMessageUpdatedError(t.status,t.payload?.missingOrgIds)}setMessageUpdatedError(e,t){this.dispatch({type:"MESSAGES_UPDATED",state:"error",...404===e?{notFound:!0,missingOrgIds:t}:{}})}selectReference(e){this.dispatch({type:"SELECT_REFERENCE",reference:e})}setTopRepositoryTopics(e){this.dispatch({type:"SET_TOP_REPOSITORIES",topics:e})}async handleStreamingMessage(e,t){try{for await(let s of t.stream())this.processStreamingMessage(e,s)}catch(s){let t;if(this.isWrappedStreamingResponseError(s))t=this.getStreamingErrorMessage(s.error);else{t=w(h.DW);let{mode:e}=this.getChatState();(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_STREAMING_GENERIC",mode:e,message:"An unexpected error occurred during message streaming."})}this.handleSendMessageError(e,t);return}}isWrappedStreamingResponseError(e){return!!e&&"object"==typeof e&&"error"in e&&!!e.error&&"object"==typeof e.error&&"errorType"in e.error&&"string"==typeof e.error.errorType&&E.C6.includes(e.error.errorType)}processStreamingMessage(e,t){switch(this.timings.firstByte??=Date.now(),t.type){case"content":this.timings.firstToken??=Date.now(),this.emitFirstMessageRenderedIfNeeded(),this.dispatch({type:"MESSAGE_STREAMING_TOKEN_ADDED",token:t.body});break;case"functionCall":var s;s=t.name,E.xP.includes(s)&&this.dispatch({type:"MESSAGE_STREAMING_FUNCTION_CALLED",name:t.name,status:t.status,arguments:t.arguments,errorMessage:t.errorMessage,references:t.references,statusMessage:t.statusMessage,callId:t.callId});break;case"confirmation":this.dispatch({type:"MESSAGE_STREAMING_CONFIRMATION",title:t.title,message:t.message,confirmation:t.confirmation});break;case"threadTitle":this.dispatch({type:"THREAD_UPDATED",thread:{...e,name:t.title}});break;case"complete":t.references=(0,T.q)(t.references),this.dispatch({type:"MESSAGE_STREAMING_COMPLETED",messageResponse:t,timings:this.completeTiming()}),this.handleSendMessageSuccess(e);break;case"error":{let s=this.getStreamingErrorMessage(t);this.handleSendMessageError(e,s);break}case"debug":console.log("Prompt Body:",t.body);break;case"trace":{let s=this.getChatState().streamingMessage?.createdAt;try{if(!t.traceId){console.error("Received trace data without trace ID from backend, ignoring trace");break}let r=(0,R.r)(t.spans);if(r[0]){let a=s||t.traceId;this.traceDispatch?.({type:"SET_TRACE_INFO",traceInfo:{spanNode:r[0],messageId:a,threadId:e.id,actualTraceId:t.traceId}})}}catch(e){console.error("Failed to process trace info:",e)}break}case"agentError":this.dispatch({type:"AGENT_ERROR",error:{type:t.agentErrorType,code:t.code,message:t.message,identifier:t.identifier}})}}getStreamingErrorMessage(e){let{mode:t}=this.getChatState();switch(e.errorType){case"publicCode":{let e="https://docs.github.com/en/copilot/managing-copilot/managing-copilot-as-an-individual-subscriber/managing-copilot-policies-as-an-individual-subscriber",s=(0,r.jsxs)(r.Fragment,{children:["This response cannot be shown because it references public code, which is restricted by"," ",(0,r.jsx)("a",{href:e,children:"your Copilot settings"}),"."]});return this.hasCEorCBAccess&&(e="https://docs.github.com/en/enterprise-cloud@latest/copilot/managing-copilot/managing-github-copilot-in-your-organization/managing-policies-for-copilot-in-your-organization",s=(0,r.jsxs)(r.Fragment,{children:["This response cannot be shown because it references public code, which is restricted by"," ",(0,r.jsx)("a",{href:e,children:"your organization's Copilot settings"}),"."]})),(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_PUBLIC_CODE",mode:t,message:"This response cannot be shown because it references public code, which is restricted by your Copilot settings."}),{type:"publicCode",isError:!0,message:s,retryable:!0}}case"filtered":{let e=(0,r.jsxs)(r.Fragment,{children:["This response has been filtered because it violates ",(0,r.jsx)("a",{href:"https://docs.github.com/en/site-policy/github-terms/github-terms-for-additional-products-and-features#github-copilot",children:"GitHub's safety policies"}),"."]});return(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_FILTERED_RESPONSE",mode:t,message:"This response has been filtered because it violates GitHub's safety policies."}),{type:"filtered",isError:!0,message:e,retryable:!1}}case"contentTooLarge":return(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_CONTENT_TOO_LARGE",mode:t,message:h.nN["413"]||h.DW}),O(h.nN["413"]||h.DW);case"rateLimit":return(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_RATE_LIMIT",mode:t,message:h.nN["429"]||h.DW}),w(h.nN["429"]||h.DW);case"agentUnauthorized":{let s=JSON.parse(e.description),r=`You haven't authorized ${s.name} to access your account. You can do that by going here: ${window.location.origin}/login/oauth/authorize?client_id=${s.client_id}`;return(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_AGENT_UNAUTHORIZED",mode:t,message:r}),{type:"agentUnauthorized",isError:!0,message:r,details:s}}case"agentRequest":{let s=JSON.parse(e.description);return(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_AGENT_REQUEST",mode:t,message:s.message}),{type:"agentRequest",isError:!0,message:s.message,details:s}}case"multipleAgentsAttempt":return(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_MULTIPLE_AGENTS_ATTEMPT",mode:t,message:C}),w(C);case"networkError":return(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_NETWORK",mode:t,message:h.nN["408"]||h.DW}),w(h.nN["408"]||h.DW);case"quotaExceeded":return(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_QUOTA_EXCEEDED",mode:t,message:e.description||h.nN["402"]||h.DW}),O(e.description||h.nN["402"]||h.DW);case"billingNotConfigured":return(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_BILLING_NOT_CONFIGURED",mode:t,message:e.description||h.nN["402"]||h.DW}),{isError:!0,message:(0,r.jsxs)(r.Fragment,{children:["You have Copilot licenses from multiple organizations or enterprises. To use premium requests, please select a billing entity in your ",(0,r.jsx)("a",{href:h.rU,children:"Copilot billing settings"}),"."]}),type:"basic",retryable:!1};default:return(0,i.BI)("dotcom_chat.activate.error",{target:"ERROR_EXCEPTION",mode:t,message:h.FF[e.errorType]||h.DW}),w(h.FF[e.errorType]||h.DW)}}handleSendMessageSuccess(e){f.Jt.clearCurrentReferences(e.id),this.emitFirstMessageRenderedIfNeeded(),this.dispatch({type:"WAITING_ON_COPILOT",loading:!1})}handleSendMessageError(e,t,s,r,a=h.DW){this.emitFirstMessageRenderedIfNeeded(),e&&s&&f.Jt.setSavedUserMessageOnError(e.id,s);let n=(0,g.B)(this.getChatState().messages).findLast(e=>"user"===e.role)?.id||"root",o=(0,h.Y6)({role:"assistant",content:"",mediaContent:[],error:t,thread:e,parentMessageID:n});if(this.dispatch({type:"MESSAGE_ADDED",message:o}),this.dispatch({type:"WAITING_ON_COPILOT",loading:!1}),this.dispatch({type:"MESSAGE_STREAMING_FAILED",timings:this.completeTiming()}),r){let{mode:e}=this.getChatState();(0,i.BI)("dotcom_chat.activate.error",{target:r,mode:e,message:a})}}async fetchModels(){if(A){let{availableModels:e}=this.getChatState();(!e||A.length>e.length)&&this.dispatch({type:"MODELS_LOADED",models:A});return}this.dispatch({type:"MODELS_LOADING"});let e=await this.service.listModels();if(e.ok){let t=(0,I.eW)(e.payload);A=t,this.dispatch({type:"MODELS_LOADED",models:t});let s=f.Jt.getModel(this.getChatState().selectedThreadID)?.id,r=t.find(e=>e.id===s)||t.find(e=>e.is_chat_default);r&&this.dispatch({type:"SELECT_MODEL",model:r})}else this.dispatch({type:"MODELS_LOADING_ERROR",error:e.error})}fetchThreadsPromise=null;async fetchThreads(){if(!this.fetchThreadsPromise)try{return this.fetchThreadsPromise=this.fetchThreadsImpl(),await this.fetchThreadsPromise}finally{this.fetchThreadsPromise=null}return this.fetchThreadsPromise}async fetchThreadsImpl(){this.dispatch({type:"THREADS_LOADING"});let e=await this.service.fetchThreads();return e.ok?(setTimeout(()=>this.dispatch({type:"THREADS_LOADED",threads:e.payload}),100),e.payload):(setTimeout(()=>this.dispatch({type:"THREADS_LOADING_ERROR",message:e.error,status:e.status}),100),null)}async fetchSharedThreads(){this.dispatch({type:"SHARED_THREADS_LOADING"});let e=await this.service.fetchSharedThreads();return e.ok?(setTimeout(()=>this.dispatch({type:"SHARED_THREADS_LOADED"}),100),e.payload):(setTimeout(()=>this.dispatch({type:"SHARED_THREADS_LOADING_ERROR",message:e.error}),100),null)}async fetchLatestThread(e){let t=await this.service.fetchLatestThread(e);return t.ok?(t.payload&&this.dispatch({type:"LATEST_THREAD_LOADED",latestThread:t.payload}),t.payload):null}async continueSharedThread(e){if(!e)return this.dispatch({type:"THREAD_CONTINUED_FAILED"}),null;this.dispatch({type:"MESSAGES_UPDATED",state:"loading"});let t=await this.service.continueSharedThread(e);if(!t.ok)return null;{let{thread:e,messages:s}=t.payload;this.dispatch({type:"THREAD_CONTINUED",thread:e}),this.dispatch({type:"MESSAGES_UPDATED",state:"loaded",messages:s})}return t.payload}async unshareAllThreads(){let e=await this.service.unshareAllThreads();if(!e.ok)return this.dispatch({type:"ADD_AMBIENT_ERROR",message:e.error||"Failed to unshare all threads"}),e;for(let e of Array.from(this.getChatState().threads.values()))e.sharedAt&&this.dispatch({type:"THREAD_UPDATED",thread:{id:e.id,sharedAt:void 0,sharedID:void 0}});return e}async findOrStartNewThread(e,t,s){let r=null;if(e)r=e;else if(!s){let e=f.Jt.selectedThreadID||void 0;r=await this.fetchLatestThread(e)}if(r&&((0,h.F2)(r)||r.customCopilotID)&&(r=null),r&&t){let e=await this.service.listMessages(r.id);if(e.ok){let s=e.payload.messages,a=s?.length;a>=2&&!s[a-2]?.references?.find(e=>(0,h.x_)(e,t))&&(r=null)}}return await this.selectThread(r,{includeThreads:!1}),r}async systemPrompt(e){let t=await this.service.getSystemPrompt(e);return t.ok?t.payload.prompt:""}async fetchAgents(e){let t=await this.service.listAgents(e),s=[];return t.ok&&(s=t.payload,this.dispatch({type:"SET_AGENTS",agents:s})),s}async fetchCopilotSpace(e){let t=await this.service.fetchCopilotSpace(e),s={};return t.ok&&(s=t.payload),s}async fetchCurrentRepo(e){let t=await this.service.fetchRepo(e);if(t.ok)return this.dispatch({type:"ADD_REFERENCE",reference:(0,h.qS)(t.payload),source:"currentRepo"}),t.payload}async fetchImplicitContext(e,t,s,r=!0){let a=await this.service.fetchImplicitContext(e,t,s);if(a.ok){let e=a.payload?Array.isArray(a.payload)?a.payload:[a.payload]:void 0;this.dispatch({type:"IMPLICIT_CONTEXT_UPDATED",context:e});let i=this.getChatState();if(r&&"immersive"===i.mode&&e&&e.length>0){let r=m.W.immersiveEmbeddedImplicitReferences?e:e.filter(e=>e?.type==="repository");if(r.length>0){for(let e of(await Promise.all(r.map(async e=>{if(!e)return e;if("pull-request"===e.type||"issue"===e.type||"discussion"===e.type){let r="pull-request"===e.type?"pull_request":e.type,a=await this.service.fetchReferenceDetails(t,s,r,e.number);if(a.ok&&a.payload)return a.payload}return e}))))if(e){let t=this.getChatState(),s=t.currentReferences?.find(t=>(0,h.x_)(t,e));s?this.replaceReference(s,e):this.addReference(e,"implicit-context",{implicit:!0})}}}e&&e.length>0&&void 0!==e[0]&&this.generateSuggestions(e[0])}}clearCurrentTopic=()=>{this.dispatch({type:"CURRENT_TOPIC_UPDATED",topic:void 0,state:"loaded"})};showTopicPicker=(e=!0)=>{this.dispatch({type:"SHOW_TOPIC_PICKER",show:e})};startEditingMessage=e=>this.dispatch({type:"START_EDITING_MESSAGE",messageId:e});cancelEditingMessage=()=>this.dispatch({type:"CANCEL_EDITING_MESSAGE"});threadDataLoaded(e,t,s){this.dispatch({type:"MESSAGES_UPDATED",messages:t,state:"loaded"}),this.dispatch({type:"REFERENCES_LOADED",references:s})}dismissEditorUpsellBanner(){let e=new FormData;e.set("copilot_editor_upsell_banner_dismissed","true"),(0,d.DI)("/github-copilot/preferences",{method:"PUT",body:e}),this.dispatch({type:"DISMISS_EDITOR_UPSELL_BANNER"})}tryInferMessage(e){return e&&e.find(e=>"image"===e.type)?[!0,"Describe this image"]:[!1,void 0]}setWrapCodeLines(e){this.dispatch({type:"SET_WRAP_CODE_LINES",value:e}),f.Jt.setWrapCodeLines(e)}clearDefaultRecipient(){this.dispatch({type:"CLEAR_DEFAULT_RECIPIENT"})}completeTiming(){return{...this.timings,endTime:Date.now()}}getCustomCopilotKey(e){return e?`${e.owner}:${e.id}`:"default"}getThreadById(e){return e&&this.getChatState().threads.get(e)||null}}function y(e){var t;return M(e,[E.wh.explain,E.wh.suggest])||M(e,[E.wh.conversation])&&"content"in(t=e)&&"string"==typeof t.content}function M(e,t){return new Set(t).has(e.intent)}function w(e){return{isError:!0,message:e,type:"basic",retryable:!0}}function O(e,t){return{isError:!0,message:e,type:t||"basic",retryable:!1}}function L(e,t){let s=document.getElementById(e);s?.setAttribute("aria-expanded",t?"true":"false")}function v(e){for(let t of e)if("image"===t.type){let e=t.attachment;e instanceof _.N&&e.abortController.abort("Reference removed before upload completed")}}},56649(e,t,s){s.d(t,{X:()=>i});let r=/^data:\s+/;class a extends Error{error;constructor(e){super(e.description),this.error=e,this.name="CopilotStreamingError"}}class i{reader;constructor(e){this.reader=e}async *stream(){let e=new TextDecoder("utf-8"),t="";for(;;){let s,i;try{({value:s,done:i}=await this.reader.read())}catch{throw new a({type:"error",errorType:"networkError",description:"NETWORK_CONNECTION_INTERRUPTED"})}if(i)break;for(t+=e.decode(s);;){let e=t.indexOf("\n\n");if(-1===e)break;let s=t.slice(0,e).replace(r,"");if("[DONE]"===s)return;let a=JSON.parse(s);if(yield a,a?.type==="complete")return;t=t.slice(e+2)}}}async stop(){return this.reader.cancel()}}},68626(e,t,s){s.d(t,{B:()=>i,CX:()=>l,HR:()=>d,TC:()=>o,Y$:()=>c,ws:()=>n,zh:()=>a});var r=s(66743);function a(e,t=!0){let s=performance.now(),i=0,n={id:"root",role:"user",createdAt:"",threadID:"",references:null,childMessageIndexes:[],messageIndex:0,clientSide:!1};if(0===e.length)return e=[n],i=performance.now()-s,(0,r.BI)("copilot.timings",{function:"constructMessagesHierarchy",timeElapsed:i,messagesLength:e.length,selectMostRecentMessages:t}),e;"root"!==e[0].id&&(e=[n,...e],(0,r.BI)("copilot.legacy_thread_updated",{threadID:e[1].threadID,messagesLength:e.length,selectMostRecentMessages:t}));let o=e[1];if(!o)return e;[e,o]=h(e,1,"parentMessageID","root");let d=new Map,c=[];for(let[t,s]of e.entries()){if([e,s]=h(e,t,"messageIndex",t),c[t]=[],d.set(s.id,t),"root"===s.id)continue;s.parentMessageID||([e,s]=h(e,t,"parentMessageID",o.id),o=s);let r=d.get(s.parentMessageID);if(void 0!==r){[e,s]=h(e,t,"parentMessageIndex",r);let a=e[r];a&&(c[r].push(t),void 0===a.selectedChildIndex&&([e,a]=h(e,r,"selectedChildIndex",t)))}}for(let t=0;t({...e})),r=s[t.parentMessageIndex];return r&&(r.selectedChildIndex=t.messageIndex),s}function o(e,t){let s=e.map(e=>({...e})),r=s[t.messageIndex];return r&&void 0!==r.selectedChildIndex&&(r.selectedChildIndex=void 0),s}function d(e,t){let s=e.findIndex(e=>e.id===t?.parentMessageID);if(-1!==s){let r=e[s],a={...t};a.messageIndex=e.length,a.childMessageIndexes=[],a.parentMessageIndex=r.messageIndex;let i=r.childMessageIndexes?.slice()||[];i.includes(a.messageIndex)||i.push(a.messageIndex),r={...r,childMessageIndexes:i,selectedChildIndex:a.messageIndex},e=[...e,a].toSpliced(s,1,r)}return e}function c(e,t){if(null==e.find(e=>e.id===t?.parentMessageID)){let s=i(e),r=s[s.length-1];if(void 0!==r)if(r.clientSide&&"user"===r.role){let s=e.indexOf(r);[e,r]=h(e,s,"id",t.parentMessageID),[e,r]=h(e,s,"clientSide",!1)}else t.parentMessageID=r.id}return e}function l(e,t){return void 0!==t.parentMessageIndex?e[t.parentMessageIndex]:void 0}function h(e,t,s,r){let a=e[t];if(!a)throw Error(`Message at index ${t} does not exist.`);let i=a[s];if(i===r||Array.isArray(i)&&Array.isArray(r)&&i.length===r.length&&i.every((e,t)=>e===r[t]))return[e,a];let n={...a,[s]:r},o=[...e];return o[t]=n,[o,o[t]]}},11222(e,t,s){s.d(t,{N:()=>n});var r=s(51586),a=s(31143);async function i(e,t){return void 0!==t.width&&void 0!==t.height?{width:t.width,height:t.height}:e.type.startsWith("image/")?new Promise((s,r)=>{let a=new FileReader;a.onload=e=>{if(!e.target?.result||"string"!=typeof e.target.result)return void s({width:void 0,height:void 0});let a=new Image;a.onload=()=>{t.width=a.width,t.height=a.height,s({width:a.width,height:a.height})},a.onerror=()=>r(Error("Failed to load image for dimension extraction")),a.src=e.target.result},a.readAsDataURL(e)}):{width:void 0,height:void 0}}class n{file;width;height;#e;#t;abortController;key;threadID;isLoaded=!1;hasError=!1;constructor(e,t,s=null){this.file=t,this.abortController=new AbortController,this.#t=this.abortController.signal,this.key=e,this.#e=this.getDimensions(),this.threadID=s}#s=(0,a.Z)(async()=>{let e=await (0,r.BV)({name:this.file.name,size:String(this.file.size),content_type:this.file.type,thread_id:this.threadID},"/upload/policies/copilot-chat-attachments",this.#t);await (0,r.QM)(this.file,e,this.#t);let t=await (0,r.My)(e,this.#t),s=await this.#e;return this.width=s.width,this.height=s.height,this.isLoaded=!0,t});prefetch(){return this.#s.load()}get previewUrl(){return this.#s.read().href}async url(){return(await this.#s.load()).href}async getDimensions(){return i(this.file,this)}}},3696(e,t,s){s.d(t,{O:()=>r});function r(e){return e&&e.customCopilotID&&e.customCopilotOwner?{id:e.customCopilotID,owner:e.customCopilotOwner}:null}},95751(e,t,s){s.d(t,{Fo:()=>f,D6:()=>g,zB:()=>m,MV:()=>E});var r=s(16522),a=s(96540);let{cache:i,readStorage:n,writeStorage:o,resetStorage:d,subscribe:c,clearKeys:l,clearKeysByPrefix:h,getItemsByPrefix:u,clearAll:p}=(0,s(14762).y)("sessionStorage");function g(e){l(e)}function E(e){return u(e)}function m(e){h(e)}function f(e,t){let s,l,h,u,p,g,E,m=(0,r.c)(17),f=(0,a.useRef)(t);m[0]!==t?(s=()=>{f.current=t},m[0]=t,m[1]=s):s=m[1],(0,a.useEffect)(s),m[2]!==t||m[3]!==e?(l=()=>(i.has(e)||n(e,t),i.get(e)),m[2]=t,m[3]=e,m[4]=l):l=m[4];let T=l;m[5]!==t?(h=()=>t,m[5]=t,m[6]=h):h=m[6];let I=h;m[7]!==e?(u=t=>c(e,t),m[7]=e,m[8]=u):u=m[8];let R=u,_=(0,a.useSyncExternalStore)(R,T,I);m[9]!==e?(p=t=>{let s=i.has(e)?i.get(e):f.current,r="function"==typeof t?t(s):t;void 0===r?d(e,f.current):o(e,r)},m[9]=e,m[10]=p):p=m[10];let S=p;m[11]!==e?(g=()=>{d(e,f.current)},m[11]=e,m[12]=g):g=m[12];let C=g;return m[13]!==C||m[14]!==S||m[15]!==_?(E=[_,S,C],m[13]=C,m[14]=S,m[15]=_,m[16]=E):E=m[16],E}}}]); //# sourceMappingURL=62874-5fda33c755233af4-9fca3d516f15d90c.js.map