@opensumi/cli-engine 3.8.3-next-1747210131.0 → 3.8.3-next-1747225210.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31564,7 +31564,7 @@ Use the appropriate tools to fulfill the USER\u2019s request, ensuring all requi
31564
31564
  <user_info>
31565
31565
  The user's OS is ${(0,p.getOperatingSystemName)()}. The absolute path of the user's workspace is ${this.appConfig.workspaceDir}.
31566
31566
  </user_info>`},invoke:async(f,c,y,b)=>{this.chatDeferred=new p.Deferred;const{message:A,command:S}=f;let D=A;if(S){const w=this.chatFeatureRegistry.getSlashCommandHandler(S);if(w&&w.providerPrompt){const I=this.monacoCommandRegistry.getActiveCodeEditor();D=await w.providerPrompt(A,I)}}const T=await this.aiBackService.requestStream(D,{requestId:f.requestId,sessionId:f.sessionId,history:y,images:f.images,...this.getRequestOptions()},b);return(0,s.listenReadable)(T,{onData:w=>{c(w)},onEnd:()=>{this.chatDeferred.resolve()},onError:w=>{this.messageService.error(w.message),this.aiReporter.end(f.sessionId+"_"+f.requestId,{message:w.message,success:!1,command:S})}}),await this.chatDeferred.promise,{}},provideSlashCommands:async f=>this.chatFeatureRegistry.getAllSlashCommand().map(c=>({...c,name:c.name,description:c.description||""})),provideChatWelcomeMessage:async f=>{}})),queueMicrotask(()=>{this.chatAgentService.updateAgent(n.AGENT_ID,{})})}};t.ChatProxyService=d,d.AGENT_ID="Default_Chat_Agent",r.__decorate([(0,o.Autowired)(g.IChatAgentService),r.__metadata("design:type",Object)],d.prototype,"chatAgentService",void 0),r.__decorate([(0,o.Autowired)(p.AIBackSerivcePath),r.__metadata("design:type",Object)],d.prototype,"aiBackService",void 0),r.__decorate([(0,o.Autowired)(p.ChatFeatureRegistryToken),r.__metadata("design:type",u.ChatFeatureRegistry)],d.prototype,"chatFeatureRegistry",void 0),r.__decorate([(0,o.Autowired)(m.MonacoCommandRegistry),r.__metadata("design:type",m.MonacoCommandRegistry)],d.prototype,"monacoCommandRegistry",void 0),r.__decorate([(0,o.Autowired)(p.ChatServiceToken),r.__metadata("design:type",h.ChatService)],d.prototype,"aiChatService",void 0),r.__decorate([(0,o.Autowired)(p.IAIReporter),r.__metadata("design:type",Object)],d.prototype,"aiReporter",void 0),r.__decorate([(0,o.Autowired)(p.ChatAgentViewServiceToken),r.__metadata("design:type",Object)],d.prototype,"chatAgentViewService",void 0),r.__decorate([(0,o.Autowired)(a.PreferenceService),r.__metadata("design:type",Object)],d.prototype,"preferenceService",void 0),r.__decorate([(0,o.Autowired)(p.IApplicationService),r.__metadata("design:type",Object)],d.prototype,"applicationService",void 0),r.__decorate([(0,o.Autowired)(_.IMessageService),r.__metadata("design:type",Object)],d.prototype,"messageService",void 0),r.__decorate([(0,o.Autowired)(a.AppConfig),r.__metadata("design:type",Object)],d.prototype,"appConfig",void 0),t.ChatProxyService=d=n=r.__decorate([(0,o.Injectable)()],d)},29770:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ChatService=void 0;const n=e(85608),r=e(76003),o=e(43718),a=e(63067),p=e(19413),v=e(59347);let m=class extends o.Disposable{constructor(){super(),this._onChatMessageLaunch=new o.Emitter,this.onChatMessageLaunch=this._onChatMessageLaunch.event,this._onChatReplyMessageLaunch=new o.Emitter,this.onChatReplyMessageLaunch=this._onChatReplyMessageLaunch.event,this._onChatMessageListLaunch=new o.Emitter,this.onChatMessageListLaunch=this._onChatMessageListLaunch.event,this._onScrollToBottom=new o.Emitter,this.onScrollToBottom=this._onScrollToBottom.event}showChatView(){this.mainLayoutService.toggleSlot(p.AI_CHAT_VIEW_ID,!0)}sendMessage(s){this.showChatView(),this._onChatMessageLaunch.fire(s)}clearHistoryMessages(){var s;(s=this.chatInternalService.sessionModel)===null||s===void 0||s.history.clearMessages()}sendReplyMessage(s){typeof s=="string"?this._onChatReplyMessageLaunch.fire({kind:"content",content:s}):this._onChatReplyMessageLaunch.fire(s)}sendMessageList(s){this._onChatMessageListLaunch.fire(s)}scrollToBottom(){this._onScrollToBottom.fire()}};t.ChatService=m,n.__decorate([(0,r.Autowired)(p.IChatInternalService),n.__metadata("design:type",v.ChatInternalService)],m.prototype,"chatInternalService",void 0),n.__decorate([(0,r.Autowired)(a.IMainLayoutService),n.__metadata("design:type",Object)],m.prototype,"mainLayoutService",void 0),t.ChatService=m=n.__decorate([(0,r.Injectable)(),n.__metadata("design:paramtypes",[])],m)},11735:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ChatFeatureRegistry=void 0;const n=e(85608),r=e(76003),o=e(43718),a=e(19413),p=e(42033),v=e(51081);let m=class extends o.Disposable{constructor(){super(...arguments),this.logger=(0,o.getDebugLogger)(),this.slashCommandsMap=new Map,this.slashCommandsHandlerMap=new Map,this._onDidWelcomeMessageChange=new o.Emitter,this.onDidWelcomeMessageChange=this._onDidWelcomeMessageChange.event}registerImageUploadProvider(s){this.imageUploadProvider=s}getImageUploadProvider(){return this.imageUploadProvider}dispose(){super.dispose(),this.slashCommandsMap.clear(),this.slashCommandsHandlerMap.clear()}registerWelcome(s,g){this.chatWelcomeMessageModel=new p.ChatWelcomeMessageModel(s,g),this._onDidWelcomeMessageChange.fire()}registerSlashCommand(s,g){const{name:l}=s;if(this.slashCommandsMap.has(l)){this.logger.warn(`ChatFeatureRegistry: commands name ${l} already exists`);return}this.slashCommandsMap.set(l,new p.ChatSlashCommandItemModel(s,l,v.ChatProxyService.AGENT_ID)),this.slashCommandsHandlerMap.set(l,g)}getSlashCommandHandler(s){return this.slashCommandsHandlerMap.get(s)}getSlashCommand(s){return this.slashCommandsMap.get(s)}getSlashCommandHandlerBySlashName(s){const g=this.getAllSlashCommand().find(l=>l.nameWithSlash===s);if(g)return this.getSlashCommandHandler(g.name)}getSlashCommandBySlashName(s){const g=this.getAllSlashCommand().find(l=>l.nameWithSlash===s);if(g)return this.getSlashCommand(g.name)}getAllSlashCommand(){return Array.from(this.slashCommandsMap.values())}getAllShortcutSlashCommand(){return this.getAllSlashCommand().filter(s=>s.isShortcut===!0)}parseSlashCommand(s){if(s.startsWith(a.SLASH_SYMBOL)){const g=this.getAllSlashCommand();for(const l of g){const{nameWithSlash:h}=l;if(s.startsWith(h))return{value:s.slice(h.length),nameWithSlash:h}}}return{value:s,nameWithSlash:""}}};t.ChatFeatureRegistry=m,t.ChatFeatureRegistry=m=n.__decorate([(0,r.Injectable)()],m)},59347:(x,t,e)=>{"use strict";var n;Object.defineProperty(t,"__esModule",{value:!0}),t.ChatInternalService=void 0;const r=e(85608),o=e(76003),a=e(41869),p=e(43718),v=e(19413),m=e(61282);let _=class extends p.Disposable{constructor(){super(...arguments),this._onChangeRequestId=new p.Emitter,this.onChangeRequestId=this._onChangeRequestId.event,this._onChangeSession=new p.Emitter,this.onChangeSession=this._onChangeSession.event,this._onCancelRequest=new p.Emitter,this.onCancelRequest=this._onCancelRequest.event,this._onWillClearSession=new p.Emitter,this.onWillClearSession=this._onWillClearSession.event,this._onRegenerateRequest=new p.Emitter,this.onRegenerateRequest=this._onRegenerateRequest.event,n.set(this,void 0)}get latestRequestId(){return this._latestRequestId}get sessionModel(){return r.__classPrivateFieldGet(this,n,"f")}init(){this.chatManagerService.onStorageInit(()=>{const g=this.chatManagerService.getSessions();g.length>0?this.activateSession(g[g.length-1].sessionId):this.createSessionModel()})}setLatestRequestId(g){this._latestRequestId=g,this._onChangeRequestId.fire(g)}createRequest(g,l,h,u){return this.chatManagerService.createRequest(r.__classPrivateFieldGet(this,n,"f").sessionId,g,l,u,h)}sendRequest(g,l=!1){const h=this.chatManagerService.sendRequest(r.__classPrivateFieldGet(this,n,"f").sessionId,g,l);return l&&this._onRegenerateRequest.fire(),h}cancelRequest(){this.chatManagerService.cancelRequest(r.__classPrivateFieldGet(this,n,"f").sessionId),this._onCancelRequest.fire()}createSessionModel(){r.__classPrivateFieldSet(this,n,this.chatManagerService.startSession(),"f"),this._onChangeSession.fire(r.__classPrivateFieldGet(this,n,"f").sessionId)}clearSessionModel(g){g=g||r.__classPrivateFieldGet(this,n,"f").sessionId,this._onWillClearSession.fire(g),this.chatManagerService.clearSession(g),g===r.__classPrivateFieldGet(this,n,"f").sessionId&&r.__classPrivateFieldSet(this,n,this.chatManagerService.startSession(),"f"),this._onChangeSession.fire(r.__classPrivateFieldGet(this,n,"f").sessionId)}getSessions(){return this.chatManagerService.getSessions()}getSession(g){return this.chatManagerService.getSession(g)}activateSession(g){const l=this.chatManagerService.getSession(g);if(!l)throw new Error(`There is no session with session id ${g}`);r.__classPrivateFieldSet(this,n,l,"f"),this._onChangeSession.fire(r.__classPrivateFieldGet(this,n,"f").sessionId)}dispose(){var g;(g=r.__classPrivateFieldGet(this,n,"f"))===null||g===void 0||g.dispose(),super.dispose()}};t.ChatInternalService=_,n=new WeakMap,r.__decorate([(0,o.Autowired)(p.AIBackSerivcePath),r.__metadata("design:type",Object)],_.prototype,"aiBackService",void 0),r.__decorate([(0,o.Autowired)(a.PreferenceService),r.__metadata("design:type",Object)],_.prototype,"preferenceService",void 0),r.__decorate([(0,o.Autowired)(v.IChatManagerService),r.__metadata("design:type",m.ChatManagerService)],_.prototype,"chatManagerService",void 0),t.ChatInternalService=_=r.__decorate([(0,o.Injectable)()],_)},70394:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ChatRenderRegistry=void 0;const n=e(85608),r=e(76003),o=e(43718);let a=class extends o.Disposable{registerWelcomeRender(v){this.chatWelcomeRender=v}registerAIRoleRender(v){this.chatAIRoleRender=v}registerUserRoleRender(v){this.chatUserRoleRender=v}registerThinkingRender(v){this.chatThinkingRender=v}registerInputRender(v){this.chatInputRender=v}registerThinkingResultRender(v){this.chatThinkingResultRender=v}registerChatViewHeaderRender(v){this.chatViewHeaderRender=v}};t.ChatRenderRegistry=a,t.ChatRenderRegistry=a=n.__decorate([(0,r.Injectable)()],a)},76154:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AIChatView=void 0,t.DefaultChatViewHeader=U;const n=e(85608),r=n.__importStar(e(14041)),o=e(68392),a=e(41869),p=e(81878),v=e(89195),m=e(43718),_=e(54414),s=e(63067),g=e(72665);e(41937);const l=e(51500),h=e(19413),u=e(46044),d=e(98864),E=e(87785),f=e(25834),c=n.__importDefault(e(90103)),y=e(57987),b=e(56474),A=e(49601),S=e(15016),D=e(29039),T=e(78048),w=e(86556),I=e(73974),R=e(77633),P=e(42033),O=e(51081),M=n.__importDefault(e(77256)),k="chat_scroll",F=100,L=W=>W.map(j=>{var Q;const G=((Q=j.applyResult)===null||Q===void 0?void 0:Q.diff.split(`
31567
- `).reduce(([Z,$],V)=>(V.startsWith("-")?Z+=1:V.startsWith("+")&&($+=1),[Z,$]),[0,0]))||[0,0];return{path:j.relativePath,additions:G[1],deletions:G[0],status:j.status}}).reduce((j,Q)=>{const G=j.find(Z=>Z.path===Q.path);return G?(G.additions+=Q.additions,G.deletions+=Q.deletions,G.status=Q.status):j.push(Q),j},[]),B=()=>{const W=(0,a.useInjectable)(h.IChatInternalService),j=(0,a.useInjectable)(m.ChatServiceToken),Q=(0,a.useInjectable)(m.IAIReporter),G=(0,a.useInjectable)(h.IChatAgentService),Z=(0,a.useInjectable)(m.ChatFeatureRegistryToken),$=(0,a.useInjectable)(m.ChatRenderRegistryToken),V=(0,a.useInjectable)(R.TokenMCPServerRegistry),H=(0,a.useInjectable)(a.AINativeConfigService),K=(0,a.useInjectable)(u.LLMContextServiceToken),Y=(0,a.useInjectable)(s.IMainLayoutService),X=W.sessionModel.history,oe=r.useRef(null),ie=r.useRef(!0),he=r.useRef(null),me=(0,a.useInjectable)(_.WorkbenchEditorService),q=(0,a.useInjectable)(a.AppConfig),Ee=(0,a.useInjectable)(I.BaseApplyService),ue=(0,a.useInjectable)(a.LabelService),te=(0,a.useInjectable)(l.IWorkspaceService),fe=(0,a.useInjectable)(m.CommandService),[Ie,Me]=r.useState([]),[Be,Pe]=r.useState(W.sessionModel.modelId),[we,_e]=r.useState(L(Ee.getSessionCodeBlocks())),[Ne,Te]=r.useReducer((Oe,Le)=>{switch(Le.type){case"add":return[...Oe,...Le.payload||[]];case"clear":return[];case"init":return Array.isArray(Le.payload)?Le.payload:[];default:return Oe}},[]),[We,pe]=r.useState(!1),[re,ge]=r.useState(""),[De,Ae]=r.useState(""),[Ue,Ye]=r.useState(""),[Ke,mt]=r.useState(null);r.useEffect(()=>{Pe(W.sessionModel.modelId)},[We,W.sessionModel]),r.useEffect(()=>{const Oe=new m.Disposable,Le=()=>{const ze=L(Ee.getSessionCodeBlocks());_e(ze)};return Oe.addDispose(W.onChangeSession(Le)),Oe.addDispose(Ee.onCodeBlockUpdate(Le)),()=>Oe.dispose()},[]),r.useEffect(()=>{const Oe=Z.getAllShortcutSlashCommand(),Le=G.onDidChangeAgents(()=>{const ze=G.getCommands().filter(St=>St.isShortcut).map(St=>new P.ChatSlashCommandItemModel({icon:"",name:`${St.name} `,description:St.description,isShortcut:St.isShortcut},St.name,St.agentId));Me(Oe.concat(ze))});return Me(Oe),()=>Le.dispose()},[Z,G]),(0,a.useUpdateOnEvent)(W.onChangeSession);const _t=r.useMemo(()=>$.chatInputRender?$.chatInputRender:H.capabilities.supportsMCP?A.ChatMentionInput:y.ChatInput,[$.chatInputRender]),Mt=r.useMemo(()=>(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:"",text:r.createElement(w.WelcomeMessage,null)}),[]),ct=r.useCallback(Oe=>{Oe.deltaY<0?ie.current=!1:ie.current=!0},[ie]);r.useEffect(()=>{if(oe.current)return oe.current.addEventListener("wheel",ct),()=>{var Oe;(Oe=oe.current)===null||Oe===void 0||Oe.removeEventListener("wheel",ct)}},[ie]);const wt=r.useCallback(()=>{if(oe&&oe.current&&ie.current){const Oe=oe.current.lastElementChild;Oe&&Oe.scrollIntoView({behavior:"smooth",block:"end"}),oe.current.scrollHeight>oe.current.clientHeight&&oe.current.classList.add(k)}},[oe,ie]),st=r.useCallback(Oe=>{Te(Oe),requestAnimationFrame(()=>{wt()})},[Te,wt]);r.useEffect(()=>{st({type:"init",payload:[Mt]})},[]),r.useEffect(()=>{const Oe=new m.Disposable;return Oe.addDispose(j.onScrollToBottom(()=>{requestAnimationFrame(()=>{})})),Oe.addDispose(j.onChatMessageLaunch(async Le=>{var ze;if(Le.immediate!==!1){if(We)return;await ci(Le.message,Le.images,Le.agentId,Le.command)}else Le.agentId&&ge(Le.agentId),Le.command&&Ye(Le.command),(ze=he?.current)===null||ze===void 0||ze.setInputValue(Le.message)})),Oe.addDispose(j.onChatReplyMessageLaunch(Le=>{if(Le.kind==="content"){const ze=Q.start(m.AIServiceType.CustomReply,{message:Le.content,sessionId:W.sessionModel.sessionId});X.addAssistantMessage({content:Le.content,relationId:ze}),jt({chunk:Le.content,relationId:ze})}else{const ze=Q.start(m.AIServiceType.CustomReply,{message:"component#"+Le.component,sessionId:W.sessionModel.sessionId});X.addAssistantMessage({componentId:Le.component,componentValue:Le.value,content:"",relationId:ze}),_n({chunk:Le,relationId:ze})}})),Oe.addDispose(j.onChatMessageListLaunch(Le=>{const ze=[];Le.forEach(St=>{const{role:$t}=St,On=Q.start(m.AIServiceType.Chat,{message:"",sessionId:W.sessionModel.sessionId});if($t==="assistant"){const Bn=St;ze.push((0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:On,text:r.createElement(S.ChatNotify,{requestId:On,chunk:Bn})},M.default.chat_notify))}if($t==="user"){const{message:Bn}=St,ui=O.ChatProxyService.AGENT_ID,li=$.chatUserRoleRender,Ni=ui===O.ChatProxyService.AGENT_ID?"":ui;ze.push((0,T.createMessageByUser)({id:(0,m.uuid)(6),relationId:On,text:li?r.createElement(li,{content:Bn,agentId:Ni}):r.createElement(f.CodeBlockWrapperInput,{relationId:On,text:Bn,agentId:Ni,command:Ue,labelService:ue,workspaceService:te,commandService:fe})},M.default.chat_message_code))}}),st({type:"add",payload:ze}),setTimeout(wt,0)})),()=>Oe.dispose()},[j,$.chatAIRoleRender,X]),r.useEffect(()=>{const Oe=new m.Disposable;return Oe.addDispose(G.onDidSendMessage(Le=>{const ze=Le,St=Q.start(m.AIServiceType.Agent,{message:""}),$t=(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:St,text:r.createElement(S.ChatNotify,{requestId:W.latestRequestId,chunk:ze})},M.default.chat_notify);st({type:"add",payload:[$t]})})),Oe.addDispose(G.onDidChangeAgents(async()=>{const Le=G.getDefaultAgentId();Ae(Le??"")})),()=>Oe.dispose()},[G,X,W]);const rt=r.useCallback(async Oe=>{const{userMessage:Le,relationId:ze,requestId:St,render:$t,startTime:On,command:Bn,agentId:ui}=Oe;X.addAssistantMessage({type:"component",content:""});const li=(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:ze,className:M.default.chat_with_more_actions,text:r.createElement(D.SlashCustomRender,{userMessage:Le,startTime:On,relationId:ze,requestId:St,renderContent:$t,command:Bn,agentId:ui})});st({type:"add",payload:[li]})},[oe,X]),lt=r.useCallback(async Oe=>{const Le=$.chatUserRoleRender,{message:ze,images:St,agentId:$t,relationId:On,command:Bn}=Oe,ui=$t===O.ChatProxyService.AGENT_ID?"":$t,li=(0,T.createMessageByUser)({id:(0,m.uuid)(6),relationId:On,text:Le?r.createElement(Le,{content:ze,images:St,agentId:ui,command:Bn}):r.createElement(f.CodeBlockWrapperInput,{labelService:ue,relationId:On,text:ze,images:St,agentId:ui,command:Bn,workspaceService:te,commandService:fe})},M.default.chat_message_code);st({type:"add",payload:[li]})},[$,$.chatUserRoleRender,X,wt]),At=r.useCallback(async Oe=>{const{message:Le,agentId:ze,request:St,relationId:$t,command:On,startTime:Bn,msgId:ui}=Oe,li=ze===O.ChatProxyService.AGENT_ID?"":ze;if(ze===O.ChatProxyService.AGENT_ID&&On){const Rn=Z.getSlashCommandHandler(On);if(Rn&&Rn.providerRender)return pe(!1),rt({userMessage:Le,render:Rn.providerRender,relationId:$t,requestId:St.requestId,startTime:Bn,agentId:ze,command:On})}const Ni=(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:$t,className:M.default.chat_with_more_actions,text:r.createElement(S.ChatReply,{relationId:$t,request:St,startTime:Bn,agentId:li,command:On,onDidChange:()=>{wt()},history:X,onDone:()=>{pe(!1)},onRegenerate:()=>{St&&W.sendRequest(St,!0)},msgId:ui})});st({type:"add",payload:[Ni]})},[$,X,wt]),jt=r.useCallback(Oe=>{const{chunk:Le,relationId:ze}=Oe;let St=r.createElement(b.ChatMarkdown,{markdown:Le,fillInIncompleteTokens:!0,agentId:re,command:Ue});if($.chatAIRoleRender){const On=$.chatAIRoleRender;St=r.createElement(On,{content:Le})}const $t=(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:ze,text:St,className:M.default.chat_with_more_actions});st({type:"add",payload:[$t]})},[$,X,wt]),_n=r.useCallback(Oe=>{const{chunk:Le,relationId:ze}=Oe,St=(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:ze,text:r.createElement(S.ChatNotify,{requestId:ze,chunk:Le})},M.default.chat_notify);st({type:"add",payload:[St]})},[$,X,wt]),In=r.useCallback(async Oe=>{const{message:Le,images:ze,agentId:St,command:$t,reportExtra:On}=Oe,{actionType:Bn,actionSource:ui}=On||{},li=W.createRequest(Le,St,ze,$t);if(!li)return;pe(!0),W.setLatestRequestId(li.requestId);const Ni=Date.now(),Rn=O.ChatProxyService.AGENT_ID===St?m.AIServiceType.Chat:m.AIServiceType.Agent,Cn=Q.start($t||Rn,{agentId:St,userMessage:Le,actionType:Bn,actionSource:ui,sessionId:W.sessionModel.sessionId},600*1e3);X.addUserMessage({content:Le.replaceAll(u.LLM_CONTEXT_KEY_REGEX,""),images:ze||[],agentId:St,agentCommand:$t,relationId:Cn}),await lt({relationId:Cn,message:Le,images:ze,command:$t,agentId:St}),W.sendRequest(li);const $n=X.addAssistantMessage({content:"",relationId:Cn,requestId:li.requestId,replyStartTime:Ni});V.activeMessageInfo={messageId:$n,sessionId:W.sessionModel.sessionId},await At({startTime:Ni,relationId:Cn,message:Le,agentId:St,command:$t,request:li,msgId:$n})},[$,$.chatUserRoleRender,X,wt,We]),ci=r.useCallback(async(Oe,Le,ze,St)=>{var $t,On,Bn;const ui={actionSource:m.ActionSourceEnum.Chat,actionType:m.ActionTypeEnum.Send};ze=ze||O.ChatProxyService.AGENT_ID;let li=Oe;const Ni=/\{\{@file:(.*?)\}\}/g,Rn=Oe.match(Ni);let Cn=!1;if(Rn)for(const un of Rn){const Vn=un.replace(/\{\{@file:(.*?)\}\}/,"$1");Vn&&!Cn&&(Cn=!0,K.cleanFileContext());const Xt=new m.URI(Vn),Qe=(($t=await te.asRelativePath(Xt))===null||$t===void 0?void 0:$t.path)||Xt.displayName;li=li.replace(un,`\`${u.LLM_CONTEXT_KEY.AttachedFile}${Qe}\``)}const $n=/\{\{@folder:(.*?)\}\}/g,Si=li.match($n);if(Si)for(const un of Si){const Vn=un.replace(/\{\{@folder:(.*?)\}\}/,"$1"),Xt=new m.URI(Vn),Qe=((On=await te.asRelativePath(Xt))===null||On===void 0?void 0:On.path)||Xt.displayName;li=li.replace(un,`\`${u.LLM_CONTEXT_KEY.AttachedFolder}${Qe}\``)}const Ui=/\{\{@code:(.*?)\}\}/g,bi=li.match(Ui);if(bi)for(const un of bi){const Vn=un.replace(/\{\{@code:(.*?)\}\}/,"$1"),[Xt,Qe]=Vn.split(":");let vt=[0,0];if(Qe){const[nn,Gt]=Qe.slice(1).split("-");vt=[parseInt(nn,10),parseInt(Gt,10)]}const pt=new m.URI(Xt),gt=((Bn=await te.asRelativePath(pt))===null||Bn===void 0?void 0:Bn.path)||pt.displayName;li=li.replace(un,`\`${u.LLM_CONTEXT_KEY.AttachedFile}${gt}:L${vt[0]}-${vt[1]}\``)}return In({message:li,images:Le,agentId:ze,command:St,reportExtra:ui})},[In]),xn=r.useCallback(()=>{W.clearSessionModel(),j.clearHistoryMessages(),dn()},[Ne]),dn=r.useCallback(()=>{var Oe;(Oe=oe?.current)===null||Oe===void 0||Oe.classList.remove(k),st({type:"init",payload:[Mt]})},[Ne]),jn=Oe=>{We||(mt(Oe.nameWithSlash),ge(Oe.agentId),Ye(Oe.command))},sn=r.useCallback(()=>{Y.toggleSlot(h.AI_CHAT_VIEW_ID)},[Y]),at=$.chatViewHeaderRender||U,$e=r.useCallback(async Oe=>{for(const Le of X.getMessages()){if(Oe.isCancellationRequested)return;if(Le.role===1)await lt({relationId:Le.relationId,message:Le.content,agentId:Le.agentId,command:Le.agentCommand,images:Le.images});else if(Le.role===2&&Le.requestId){const ze=W.sessionModel.getRequest(Le.requestId);ze&&!ze.response.isComplete&&pe(!0),await At({msgId:Le.id,relationId:Le.relationId,message:Le.content,agentId:Le.agentId,command:Le.agentCommand,startTime:Le.replyStartTime,request:ze})}else Le.role===2&&Le.content?await jt({relationId:Le.relationId,chunk:Le.content}):Le.role===2&&Le.componentId&&await _n({relationId:Le.relationId,chunk:{kind:"component",component:Le.componentId,value:Le.componentValue}})}},[At]);return r.useEffect(()=>{dn();const Oe=new m.CancellationTokenSource;return pe(!1),$e(Oe.token),()=>{Oe.cancel()}},[W.sessionModel]),r.createElement("div",{id:M.default.ai_chat_view},r.createElement("div",{className:M.default.header_container},r.createElement(at,{handleClear:xn,handleCloseChatView:sn})),r.createElement("div",{className:M.default.body_container},r.createElement("div",{className:M.default.left_bar,id:"ai_chat_left_container"},r.createElement("div",{className:M.default.chat_container,ref:oe},r.createElement(o.MessageList,{className:M.default.message_list,lockable:!0,toBottomHeight:"100%",dataSource:Ne})),W.sessionModel.slicedMessageCount?r.createElement("div",{className:M.default.chat_tips_text},r.createElement("div",{className:M.default.chat_tips_container},(0,m.formatLocalize)("aiNative.chat.ai.assistant.limit.message",W.sessionModel.slicedMessageCount))):null,r.createElement("div",{className:M.default.chat_input_wrap},r.createElement("div",{className:M.default.header_operate},r.createElement("div",{className:M.default.header_operate_left},Ie.map(Oe=>r.createElement(p.Popover,{id:`ai-chat-shortcut-${Oe.name}`,key:`ai-chat-shortcut-${Oe.name}`,title:Oe.tooltip||Oe.name},r.createElement("div",{className:M.default.tag,onClick:()=>jn(Oe)},Oe.name))))),we.length>0&&r.createElement(E.FileListDisplay,{files:we,hideActions:We,onFileClick:Oe=>{me.open(m.URI.file(m.path.join(q.workspaceDir,Oe)))},onRejectAll:()=>{Ee.processAll("reject")},onAcceptAll:()=>{Ee.processAll("accept")}}),r.createElement(_t,{onSend:ci,disabled:We,enableOptions:!0,theme:Ke,setTheme:mt,agentId:re,setAgentId:ge,defaultAgentId:De,command:Ue,setCommand:Ye,contextService:K,ref:he,disableModelSelector:Be!==void 0||We,sessionModelId:Be})))))};t.AIChatView=B;function U({handleClear:W,handleCloseChatView:j}){const Q=(0,a.useInjectable)(h.IChatInternalService),G=(0,a.useInjectable)(g.IMessageService),[Z,$]=r.useState([]),[V,H]=r.useState(""),K=r.useCallback(()=>{if(Q.sessionModel.history.getMessages().length>0)try{Q.createSessionModel()}catch(oe){G.error(oe.message)}},[Q]),Y=r.useCallback(oe=>{Q.activateSession(oe.id)},[Q]),X=r.useCallback(oe=>{Q.clearSessionModel(oe.id)},[Q]);return r.useEffect(()=>{const oe=()=>{const q=Q.sessionModel.history.getMessages().findLast(Ee=>Ee.role===1);H(q?(0,d.cleanAttachedTextWrapper)(q.content).slice(0,F):""),$(Q.getSessions().map(Ee=>{const te=Ee.history.getMessages(),fe=te.length>0?(0,d.cleanAttachedTextWrapper)(te[0].content).slice(0,F):"",Ie=te.length>0&&te[te.length-1].replyStartTime||0;return{id:Ee.sessionId,title:fe,updatedAt:Ie,loading:!1}}))};oe();const ie=new m.DisposableCollection,he=new Set;return ie.push(Q.onChangeSession(me=>{oe(),!he.has(me)&&(he.add(me),ie.push(Q.sessionModel.history.onMessageChange(()=>{oe()})))})),ie.push(Q.sessionModel.history.onMessageChange(()=>{oe()})),()=>{ie.dispose()}},[Q]),r.createElement("div",{className:M.default.header},r.createElement(c.default,{className:M.default.chat_history,currentId:Q.sessionModel.sessionId,title:V||(0,m.localize)("aiNative.chat.ai.assistant.name"),historyList:Z,onNewChat:K,onHistoryItemSelect:Y,onHistoryItemDelete:X,onHistoryItemChange:()=>{}}),r.createElement(p.Popover,{overlayClassName:M.default.popover_icon,id:"ai-chat-header-clear",title:(0,m.localize)("aiNative.operate.clear.title")},r.createElement(v.EnhanceIcon,{wrapperClassName:M.default.action_btn,className:(0,a.getIcon)("clear"),onClick:W,tabIndex:0,role:"button",ariaLabel:(0,m.localize)("aiNative.operate.clear.title")})),r.createElement(p.Popover,{overlayClassName:M.default.popover_icon,id:"ai-chat-header-close",position:p.PopoverPosition.left,title:(0,m.localize)("aiNative.operate.close.title")},r.createElement(v.EnhanceIcon,{wrapperClassName:M.default.action_btn,className:(0,a.getIcon)("window-close"),onClick:j,tabIndex:0,role:"button",ariaLabel:(0,m.localize)("aiNative.operate.close.title")})))}},21967:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ApplyStatus=void 0;const n=e(85608),r=n.__importDefault(e(14041)),o=e(97267),a=n.__importDefault(e(6960)),p=({status:v,error:m})=>{const _=()=>{switch(v){case"generating":return r.default.createElement(o.Loading,null);case"pending":return r.default.createElement(o.Popover,{title:"Pending",id:"edit-file-tool-status-pending"},r.default.createElement(o.Icon,{iconClass:"codicon codicon-circle-large"}));case"success":return r.default.createElement(o.Popover,{title:"Success",id:"edit-file-tool-status-success"},r.default.createElement(o.Icon,{iconClass:"codicon codicon-pass"}));case"failed":return r.default.createElement(o.Popover,{title:`Failed (${m||"Unknown error"})`,id:"edit-file-tool-status-failed"},r.default.createElement(o.Icon,{iconClass:"codicon codicon-error"}));case"cancelled":return r.default.createElement(o.Popover,{title:"Cancelled",id:"edit-file-tool-status-cancelled"},r.default.createElement(o.Icon,{iconClass:"codicon codicon-circle-slash",style:{color:"var(--input-placeholderForeground)"}}));default:return null}};return r.default.createElement("span",{className:a.default.status},_())};t.ApplyStatus=p},87785:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FileListDisplay=void 0;const n=e(85608),r=n.__importStar(e(14041)),o=e(97267),a=e(41869),p=e(54414),v=e(42995),m=e(21967),_=n.__importDefault(e(80919)),s=g=>{const{files:l,onFileClick:h,onRejectAll:u,onAcceptAll:d,hideActions:E}=g,[f,c]=(0,r.useState)(!0),y=(0,a.useInjectable)(p.WorkbenchEditorService),b=(0,a.useInjectable)(a.LabelService),A=(0,r.useMemo)(()=>l.map(R=>{const P=a.URI.parse(R.path),O=b.getIcon(P);return r.default.createElement("span",{className:O})}),[l]),S=l.length,D=l.reduce((R,P)=>({additions:R.additions+P.additions,deletions:R.deletions+P.deletions}),{additions:0,deletions:0}),T=()=>{c(!f)},w=R=>R?r.default.createElement("span",{className:_.default.viewChanges,onClick:P=>{P.stopPropagation(),y.open(a.URI.from({scheme:v.ChatMultiDiffResolver.CHAT_EDITING_MULTI_DIFF_SOURCE_RESOLVER_SCHEME,path:"chat-editing-multi-diff-source"}),{label:(0,a.localize)("aiNative.chat.view-changes")})}},r.default.createElement(o.Icon,{icon:"unorderedlist",size:"small"}),(0,a.localize)("aiNative.chat.view-changes")):null,I=(R,P)=>{const O=[];return R>0&&O.push(r.default.createElement("span",{key:"add",className:_.default.additions},"+",R)),P>0&&(O.length>0&&O.push(" "),O.push(r.default.createElement("span",{key:"del",className:_.default.deletions},"-",P))),O.length===0&&O.push(r.default.createElement("span",{key:"no-change",className:_.default.noChange},"No changes")),O};return r.default.createElement("div",{className:_.default.container},r.default.createElement("div",{className:_.default.header},r.default.createElement("span",{className:_.default.title},r.default.createElement("button",{className:_.default.toggleButton,onClick:T},f?r.default.createElement(o.Icon,{icon:"down"}):r.default.createElement(o.Icon,{icon:"right"})," Changed Files(",S,")"),I(D.additions,D.deletions),!E&&w(l.length)),!E&&l.some(R=>R.status==="pending")&&r.default.createElement("div",{className:_.default.actions},r.default.createElement(o.Button,{type:"link",size:"small",onClick:R=>{R.stopPropagation(),u()}},"Reject"),r.default.createElement(o.Button,{size:"small",onClick:R=>{R.stopPropagation(),d()}},"Accept"))),r.default.createElement("ul",{className:`${_.default.fileList} ${f?"":_.default.collapsed}`},l.map((R,P)=>r.default.createElement("li",{key:P,className:_.default.fileItem,onClick:()=>h(R.path)},r.default.createElement("span",{className:_.default.fileIcon},A[P]||"\u{1F4C4}"),r.default.createElement("div",{className:_.default.fileInfo},r.default.createElement("div",{className:_.default.filePath},R.path),r.default.createElement("div",{className:_.default.fileStats},I(R.additions,R.deletions)),r.default.createElement(m.ApplyStatus,{status:R.status}))))))};t.FileListDisplay=s},25834:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CodeBlockWrapperInput=t.CodeBlockWrapper=t.CodeEditorWithHighlight=void 0;const n=e(85608),r=n.__importDefault(e(56005)),o=n.__importDefault(e(97331)),a=n.__importStar(e(14041)),p=n.__importDefault(e(10580)),v=e(46541),m=e(41869),_=e(81878),s=e(89195),g=e(43718),l=e(71624),h=e(9447),u=e(52416),d=n.__importDefault(e(6960)),E=e(83933),f=e(44692);e(38191);const c=S=>{const{input:D,language:T,relationId:w,agentId:I,command:R,hideInsert:P}=S,O=a.default.useRef(null),M=(0,m.useInjectable)(h.MonacoCommandRegistry),k=(0,m.useInjectable)(m.IClipboardService),F=(0,m.useInjectable)(u.IThemeService),L=(0,m.useInjectable)(g.IAIReporter),[B,U]=(0,a.useState)(!1),W=(0,a.useMemo)(()=>(0,m.uuid)(12),[O,O.current]);(0,a.useEffect)(()=>{const Z=H=>{H.type==="dark"||H.type==="hcDark"?e.e(622).then(e.bind(e,51622)):(H.type==="light"||H.type==="hcLight")&&e.e(412).then(e.bind(e,50412))},$=F.onThemeChange(H=>{Z(H)}),V=F.getCurrentThemeSync();return Z(V),()=>$.dispose()},[]);const j=(0,a.useRef)((0,o.default)(()=>{var Z;if(O.current){const $=O.current,V=(Z=$?.el)===null||Z===void 0?void 0:Z.querySelector("code"),H=V?.children;if(H){const K=H[H.length-1];K&&(K.scrollIntoViewIfNeeded?K.scrollIntoViewIfNeeded():K.scrollIntoView(!1))}}},150,{leading:!0,trailing:!0})).current;(0,a.useEffect)(()=>(j(),()=>{j.cancel()}),[D,j]);const Q=(0,a.useCallback)(async()=>{U(!0),await k.writeText(D),L.end(w,{copy:!0,code:D,language:T,agentId:I,command:R,actionSource:g.ActionSourceEnum.Chat,actionType:g.ActionTypeEnum.ChatCopyCode}),(0,g.runWhenIdle)(()=>{U(!1)},1e3)},[k,D,w]),G=(0,a.useCallback)(()=>{const Z=M.getActiveCodeEditor();if(Z){const $=Z.getSelection();$&&((0,l.insertSnippetWithMonacoEditor)(Z,D,[$],{undoStopBefore:!1,undoStopAfter:!1}),L.end(w,{insert:!0,code:D,language:T,agentId:I,command:R,actionSource:g.ActionSourceEnum.Chat,actionType:g.ActionTypeEnum.ChatInsertCode}))}},[M]);return a.default.createElement("div",{className:d.default.monaco_wrapper},a.default.createElement("div",{className:d.default.action_toolbar},!P&&a.default.createElement(_.Popover,{id:`ai-chat-inser-${W}`,title:(0,g.localize)("aiNative.chat.code.insert")},a.default.createElement(s.EnhanceIcon,{className:(0,m.getIcon)("insert"),onClick:()=>G(),tabIndex:0,role:"button",ariaLabel:(0,g.localize)("aiNative.chat.code.insert")})),a.default.createElement(_.Popover,{id:`ai-chat-copy-${W}`,title:(0,g.localize)(B?"aiNative.chat.code.copy.success":"aiNative.chat.code.copy")},a.default.createElement(s.EnhanceIcon,{className:(0,m.getIcon)("copy"),onClick:()=>Q(),tabIndex:0,role:"button",ariaLabel:(0,g.localize)("aiNative.chat.code.copy")}))),a.default.createElement(p.default,{language:T,ref:O,className:d.default.highlight_editor},D))};t.CodeEditorWithHighlight=c;const y=({content:S="",relationId:D,renderText:T,agentId:w="",command:I="",labelService:R,commandService:P,workspaceService:O})=>{const M=/`([^`]+)`/g,k=/```([^]+?)```/g,F=/```([^]+)?/g,L=/<attached_file>(.*)/g,B=/<attached_folder>(.*)/g,U=(0,a.useCallback)(async(G,Z)=>{const $=await O?.roots;let V;if($)for(const H of $){V=new g.URI(H.uri).resolve(G);try{await P?.executeCommand(m.FILE_COMMANDS.REVEAL_IN_EXPLORER.id,V),Z===f.MentionType.FILE&&await P?.executeCommand(m.EDITOR_COMMANDS.OPEN_RESOURCE.id,V);break}catch{continue}}},[P,O]),W=(G,Z=!1,$)=>a.default.createElement("span",{className:d.default.attachment,key:$,onClick:()=>U(G,Z?f.MentionType.FOLDER:f.MentionType.FILE)},a.default.createElement(_.Icon,{iconClass:Z?(0,m.getIcon)("folder"):R?.getIcon(new g.URI(G||"file"))}),a.default.createElement("span",{className:d.default.attachment_text},G)),j=G=>{const Z=G.split(`
31567
+ `).reduce(([Z,$],V)=>(V.startsWith("-")?Z+=1:V.startsWith("+")&&($+=1),[Z,$]),[0,0]))||[0,0];return{path:j.relativePath,additions:G[1],deletions:G[0],status:j.status}}).reduce((j,Q)=>{const G=j.find(Z=>Z.path===Q.path);return G?(G.additions+=Q.additions,G.deletions+=Q.deletions,G.status=Q.status):j.push(Q),j},[]),B=()=>{const W=(0,a.useInjectable)(h.IChatInternalService),j=(0,a.useInjectable)(m.ChatServiceToken),Q=(0,a.useInjectable)(m.IAIReporter),G=(0,a.useInjectable)(h.IChatAgentService),Z=(0,a.useInjectable)(m.ChatFeatureRegistryToken),$=(0,a.useInjectable)(m.ChatRenderRegistryToken),V=(0,a.useInjectable)(R.TokenMCPServerRegistry),H=(0,a.useInjectable)(a.AINativeConfigService),K=(0,a.useInjectable)(u.LLMContextServiceToken),Y=(0,a.useInjectable)(s.IMainLayoutService),X=W.sessionModel.history,oe=r.useRef(null),ie=r.useRef(!0),he=r.useRef(null),me=(0,a.useInjectable)(_.WorkbenchEditorService),q=(0,a.useInjectable)(a.AppConfig),Ee=(0,a.useInjectable)(I.BaseApplyService),ue=(0,a.useInjectable)(a.LabelService),te=(0,a.useInjectable)(l.IWorkspaceService),fe=(0,a.useInjectable)(m.CommandService),[Ie,Me]=r.useState([]),[Be,Pe]=r.useState(W.sessionModel.modelId),[we,_e]=r.useState(L(Ee.getSessionCodeBlocks())),[Ne,Te]=r.useReducer((Oe,Le)=>{switch(Le.type){case"add":return[...Oe,...Le.payload||[]];case"clear":return[];case"init":return Array.isArray(Le.payload)?Le.payload:[];default:return Oe}},[]),[We,pe]=r.useState(!1),[re,ge]=r.useState(""),[De,Ae]=r.useState(""),[Ue,Ye]=r.useState(""),[Ke,mt]=r.useState(null);r.useEffect(()=>{Pe(W.sessionModel.modelId)},[We,W.sessionModel]),r.useEffect(()=>{const Oe=new m.Disposable,Le=()=>{const ze=L(Ee.getSessionCodeBlocks());_e(ze)};return Oe.addDispose(W.onChangeSession(Le)),Oe.addDispose(Ee.onCodeBlockUpdate(Le)),()=>Oe.dispose()},[]),r.useEffect(()=>{const Oe=Z.getAllShortcutSlashCommand(),Le=G.onDidChangeAgents(()=>{const ze=G.getCommands().filter(St=>St.isShortcut).map(St=>new P.ChatSlashCommandItemModel({icon:"",name:`${St.name} `,description:St.description,isShortcut:St.isShortcut},St.name,St.agentId));Me(Oe.concat(ze))});return Me(Oe),()=>Le.dispose()},[Z,G]),(0,a.useUpdateOnEvent)(W.onChangeSession);const _t=r.useMemo(()=>$.chatInputRender?$.chatInputRender:H.capabilities.supportsMCP?A.ChatMentionInput:y.ChatInput,[$.chatInputRender]),Mt=r.useMemo(()=>(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:"",text:r.createElement(w.WelcomeMessage,null)}),[]),ct=r.useCallback(Oe=>{Oe.deltaY<0?ie.current=!1:ie.current=!0},[ie]);r.useEffect(()=>{if(oe.current)return oe.current.addEventListener("wheel",ct),()=>{var Oe;(Oe=oe.current)===null||Oe===void 0||Oe.removeEventListener("wheel",ct)}},[ie]);const wt=r.useCallback(()=>{if(oe&&oe.current&&ie.current){const Oe=oe.current.lastElementChild;Oe&&Oe.scrollIntoView({behavior:"smooth",block:"end"}),oe.current.scrollHeight>oe.current.clientHeight&&oe.current.classList.add(k)}},[oe,ie]),st=r.useCallback(Oe=>{Te(Oe),requestAnimationFrame(()=>{wt()})},[Te,wt]);r.useEffect(()=>{st({type:"init",payload:[Mt]})},[]),r.useEffect(()=>{const Oe=new m.Disposable;return Oe.addDispose(j.onScrollToBottom(()=>{requestAnimationFrame(()=>{})})),Oe.addDispose(j.onChatMessageLaunch(async Le=>{var ze;if(Le.immediate!==!1){if(We)return;await ci(Le.message,Le.images,Le.agentId,Le.command)}else Le.agentId&&ge(Le.agentId),Le.command&&Ye(Le.command),(ze=he?.current)===null||ze===void 0||ze.setInputValue(Le.message)})),Oe.addDispose(j.onChatReplyMessageLaunch(Le=>{if(Le.kind==="content"){const ze=Q.start(m.AIServiceType.CustomReply,{message:Le.content,sessionId:W.sessionModel.sessionId});X.addAssistantMessage({content:Le.content,relationId:ze}),jt({chunk:Le.content,relationId:ze})}else{const ze=Q.start(m.AIServiceType.CustomReply,{message:"component#"+Le.component,sessionId:W.sessionModel.sessionId});X.addAssistantMessage({componentId:Le.component,componentValue:Le.value,content:"",relationId:ze}),_n({chunk:Le,relationId:ze})}})),Oe.addDispose(j.onChatMessageListLaunch(Le=>{const ze=[];Le.forEach(St=>{const{role:$t}=St,On=Q.start(m.AIServiceType.Chat,{message:"",sessionId:W.sessionModel.sessionId});if($t==="assistant"){const Bn=St;ze.push((0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:On,text:r.createElement(S.ChatNotify,{requestId:On,chunk:Bn})},M.default.chat_notify))}if($t==="user"){const{message:Bn}=St,ui=O.ChatProxyService.AGENT_ID,li=$.chatUserRoleRender,Ni=ui===O.ChatProxyService.AGENT_ID?"":ui;ze.push((0,T.createMessageByUser)({id:(0,m.uuid)(6),relationId:On,text:li?r.createElement(li,{content:Bn,agentId:Ni}):r.createElement(f.CodeBlockWrapperInput,{relationId:On,text:Bn,agentId:Ni,command:Ue,labelService:ue,workspaceService:te,commandService:fe})},M.default.chat_message_code))}}),st({type:"add",payload:ze}),setTimeout(wt,0)})),()=>Oe.dispose()},[j,$.chatAIRoleRender,X]),r.useEffect(()=>{const Oe=new m.Disposable;return Oe.addDispose(G.onDidSendMessage(Le=>{const ze=Le,St=Q.start(m.AIServiceType.Agent,{message:""}),$t=(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:St,text:r.createElement(S.ChatNotify,{requestId:W.latestRequestId,chunk:ze})},M.default.chat_notify);st({type:"add",payload:[$t]})})),Oe.addDispose(G.onDidChangeAgents(async()=>{const Le=G.getDefaultAgentId();Ae(Le??"")})),()=>Oe.dispose()},[G,X,W]);const rt=r.useCallback(async Oe=>{const{userMessage:Le,relationId:ze,requestId:St,render:$t,startTime:On,command:Bn,agentId:ui}=Oe;X.addAssistantMessage({type:"component",content:""});const li=(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:ze,className:M.default.chat_with_more_actions,text:r.createElement(D.SlashCustomRender,{userMessage:Le,startTime:On,relationId:ze,requestId:St,renderContent:$t,command:Bn,agentId:ui})});st({type:"add",payload:[li]})},[oe,X]),lt=r.useCallback(async Oe=>{const Le=$.chatUserRoleRender,{message:ze,images:St,agentId:$t,relationId:On,command:Bn}=Oe,ui=$t===O.ChatProxyService.AGENT_ID?"":$t,li=(0,T.createMessageByUser)({id:(0,m.uuid)(6),relationId:On,text:Le?r.createElement(Le,{content:ze,images:St,agentId:ui,command:Bn}):r.createElement(f.CodeBlockWrapperInput,{labelService:ue,relationId:On,text:ze,images:St,agentId:ui,command:Bn,workspaceService:te,commandService:fe})},M.default.chat_message_code);st({type:"add",payload:[li]})},[$,$.chatUserRoleRender,X,wt]),At=r.useCallback(async Oe=>{const{message:Le,agentId:ze,request:St,relationId:$t,command:On,startTime:Bn,msgId:ui}=Oe,li=ze===O.ChatProxyService.AGENT_ID?"":ze;if(ze===O.ChatProxyService.AGENT_ID&&On){const Rn=Z.getSlashCommandHandler(On);if(Rn&&Rn.providerRender)return pe(!1),rt({userMessage:Le,render:Rn.providerRender,relationId:$t,requestId:St.requestId,startTime:Bn,agentId:ze,command:On})}const Ni=(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:$t,className:M.default.chat_with_more_actions,text:r.createElement(S.ChatReply,{relationId:$t,request:St,startTime:Bn,agentId:li,command:On,onDidChange:()=>{wt()},history:X,onDone:()=>{pe(!1)},onRegenerate:()=>{St&&W.sendRequest(St,!0)},msgId:ui})});st({type:"add",payload:[Ni]})},[$,X,wt]),jt=r.useCallback(Oe=>{const{chunk:Le,relationId:ze}=Oe;let St=r.createElement(b.ChatMarkdown,{markdown:Le,fillInIncompleteTokens:!0,agentId:re,command:Ue});if($.chatAIRoleRender){const On=$.chatAIRoleRender;St=r.createElement(On,{content:Le})}const $t=(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:ze,text:St,className:M.default.chat_with_more_actions});st({type:"add",payload:[$t]})},[$,X,wt]),_n=r.useCallback(Oe=>{const{chunk:Le,relationId:ze}=Oe,St=(0,T.createMessageByAI)({id:(0,m.uuid)(6),relationId:ze,text:r.createElement(S.ChatNotify,{requestId:ze,chunk:Le})},M.default.chat_notify);st({type:"add",payload:[St]})},[$,X,wt]),In=r.useCallback(async Oe=>{const{message:Le,images:ze,agentId:St,command:$t,reportExtra:On}=Oe,{actionType:Bn,actionSource:ui}=On||{},li=W.createRequest(Le,St,ze,$t);if(!li)return;pe(!0),W.setLatestRequestId(li.requestId);const Ni=Date.now(),Rn=O.ChatProxyService.AGENT_ID===St?m.AIServiceType.Chat:m.AIServiceType.Agent,Cn=Q.start($t||Rn,{agentId:St,userMessage:Le,actionType:Bn,actionSource:ui,sessionId:W.sessionModel.sessionId},600*1e3);X.addUserMessage({content:Le.replaceAll(u.LLM_CONTEXT_KEY_REGEX,""),images:ze||[],agentId:St,agentCommand:$t,relationId:Cn}),await lt({relationId:Cn,message:Le,images:ze,command:$t,agentId:St}),W.sendRequest(li);const $n=X.addAssistantMessage({content:"",relationId:Cn,requestId:li.requestId,replyStartTime:Ni});V.activeMessageInfo={messageId:$n,sessionId:W.sessionModel.sessionId},await At({startTime:Ni,relationId:Cn,message:Le,agentId:St,command:$t,request:li,msgId:$n})},[$,$.chatUserRoleRender,X,wt,We]),ci=r.useCallback(async(Oe,Le,ze,St)=>{var $t,On,Bn;const ui={actionSource:m.ActionSourceEnum.Chat,actionType:m.ActionTypeEnum.Send};ze=ze||O.ChatProxyService.AGENT_ID;let li=Oe;const Ni=/\{\{@file:(.*?)\}\}/g,Rn=Oe.match(Ni);let Cn=!1;if(Rn)for(const un of Rn){const Vn=un.replace(/\{\{@file:(.*?)\}\}/,"$1");Vn&&!Cn&&(Cn=!0,K.cleanFileContext());const Xt=new m.URI(Vn),Qe=(($t=await te.asRelativePath(Xt))===null||$t===void 0?void 0:$t.path)||Xt.displayName;li=li.replace(un,`\`${u.LLM_CONTEXT_KEY.AttachedFile}${Qe}\``)}const $n=/\{\{@folder:(.*?)\}\}/g,Si=li.match($n);if(Si)for(const un of Si){const Vn=un.replace(/\{\{@folder:(.*?)\}\}/,"$1"),Xt=new m.URI(Vn),Qe=((On=await te.asRelativePath(Xt))===null||On===void 0?void 0:On.path)||Xt.displayName;li=li.replace(un,`\`${u.LLM_CONTEXT_KEY.AttachedFolder}${Qe}\``)}const Ui=/\{\{@code:(.*?)\}\}/g,bi=li.match(Ui);if(bi)for(const un of bi){const Vn=un.replace(/\{\{@code:(.*?)\}\}/,"$1"),[Xt,Qe]=Vn.split(":");let vt=[0,0];if(Qe){const[nn,Gt]=Qe.slice(1).split("-");vt=[parseInt(nn,10),parseInt(Gt,10)]}const pt=new m.URI(Xt),gt=((Bn=await te.asRelativePath(pt))===null||Bn===void 0?void 0:Bn.path)||pt.displayName;li=li.replace(un,`\`${u.LLM_CONTEXT_KEY.AttachedFile}${gt}:L${vt[0]}-${vt[1]}\``)}return In({message:li,images:Le,agentId:ze,command:St,reportExtra:ui})},[In]),xn=r.useCallback(()=>{W.clearSessionModel(),j.clearHistoryMessages(),dn()},[Ne]),dn=r.useCallback(()=>{var Oe;(Oe=oe?.current)===null||Oe===void 0||Oe.classList.remove(k),st({type:"init",payload:[Mt]})},[Ne]),jn=Oe=>{We||(mt(Oe.nameWithSlash),ge(Oe.agentId),Ye(Oe.command))},sn=r.useCallback(()=>{Y.toggleSlot(h.AI_CHAT_VIEW_ID)},[Y]),at=$.chatViewHeaderRender||U,$e=r.useCallback(async Oe=>{for(const Le of X.getMessages()){if(Oe.isCancellationRequested)return;if(Le.role===1)await lt({relationId:Le.relationId,message:Le.content,agentId:Le.agentId,command:Le.agentCommand,images:Le.images});else if(Le.role===2&&Le.requestId){const ze=W.sessionModel.getRequest(Le.requestId);ze&&!ze.response.isComplete&&pe(!0),await At({msgId:Le.id,relationId:Le.relationId,message:Le.content,agentId:Le.agentId,command:Le.agentCommand,startTime:Le.replyStartTime,request:ze})}else Le.role===2&&Le.content?await jt({relationId:Le.relationId,chunk:Le.content}):Le.role===2&&Le.componentId&&await _n({relationId:Le.relationId,chunk:{kind:"component",component:Le.componentId,value:Le.componentValue}})}},[At]);return r.useEffect(()=>{dn();const Oe=new m.CancellationTokenSource;return pe(!1),$e(Oe.token),()=>{Oe.cancel()}},[W.sessionModel]),r.createElement("div",{id:M.default.ai_chat_view},r.createElement("div",{className:M.default.header_container},r.createElement(at,{handleClear:xn,handleCloseChatView:sn})),r.createElement("div",{className:M.default.body_container},r.createElement("div",{className:M.default.left_bar,id:"ai_chat_left_container"},r.createElement("div",{className:M.default.chat_container,ref:oe},r.createElement(o.MessageList,{className:M.default.message_list,lockable:!0,toBottomHeight:"100%",dataSource:Ne})),W.sessionModel.slicedMessageCount?r.createElement("div",{className:M.default.chat_tips_text},r.createElement("div",{className:M.default.chat_tips_container},(0,m.formatLocalize)("aiNative.chat.ai.assistant.limit.message",W.sessionModel.slicedMessageCount))):null,r.createElement("div",{className:M.default.chat_input_wrap},r.createElement("div",{className:M.default.header_operate},r.createElement("div",{className:M.default.header_operate_left},Ie.map(Oe=>r.createElement(p.Popover,{id:`ai-chat-shortcut-${Oe.name}`,key:`ai-chat-shortcut-${Oe.name}`,title:Oe.tooltip||Oe.name},r.createElement("div",{className:M.default.tag,onClick:()=>jn(Oe)},Oe.name))))),we.length>0&&r.createElement(E.FileListDisplay,{files:we,hideActions:We,onFileClick:Oe=>{me.open(m.URI.file(m.path.join(q.workspaceDir,Oe)))},onRejectAll:()=>{Ee.processAll("reject")},onAcceptAll:()=>{Ee.processAll("accept")}}),r.createElement(_t,{onSend:ci,disabled:We,enableOptions:!0,theme:Ke,setTheme:mt,agentId:re,setAgentId:ge,defaultAgentId:De,command:Ue,setCommand:Ye,contextService:K,ref:he,disableModelSelector:Be!==void 0||We,sessionModelId:Be})))))};t.AIChatView=B;function U({handleClear:W,handleCloseChatView:j}){const Q=(0,a.useInjectable)(h.IChatInternalService),G=(0,a.useInjectable)(g.IMessageService),[Z,$]=r.useState([]),[V,H]=r.useState(""),K=r.useCallback(()=>{if(Q.sessionModel.history.getMessages().length>0)try{Q.createSessionModel()}catch(oe){G.error(oe.message)}},[Q]),Y=r.useCallback(oe=>{Q.activateSession(oe.id)},[Q]),X=r.useCallback(oe=>{Q.clearSessionModel(oe.id)},[Q]);return r.useEffect(()=>{const oe=()=>{const q=Q.sessionModel.history.getMessages().findLast(Ee=>Ee.role===1);H(q?(0,d.cleanAttachedTextWrapper)(q.content).slice(0,F):""),$(Q.getSessions().map(Ee=>{const te=Ee.history.getMessages(),fe=te.length>0?(0,d.cleanAttachedTextWrapper)(te[0].content).slice(0,F):"",Ie=te.length>0&&te[te.length-1].replyStartTime||0;return{id:Ee.sessionId,title:fe,updatedAt:Ie,loading:!1}}))};oe();const ie=new m.DisposableCollection,he=new Set;return ie.push(Q.onChangeSession(me=>{oe(),!he.has(me)&&(he.add(me),ie.push(Q.sessionModel.history.onMessageChange(()=>{oe()})))})),ie.push(Q.sessionModel.history.onMessageChange(()=>{oe()})),()=>{ie.dispose()}},[Q]),r.createElement("div",{className:M.default.header},r.createElement(c.default,{className:M.default.chat_history,currentId:Q.sessionModel.sessionId,title:V||(0,m.localize)("aiNative.chat.ai.assistant.name"),historyList:Z,onNewChat:K,onHistoryItemSelect:Y,onHistoryItemDelete:X,onHistoryItemChange:()=>{}}),r.createElement(p.Popover,{overlayClassName:M.default.popover_icon,id:"ai-chat-header-clear",title:(0,m.localize)("aiNative.operate.clear.title")},r.createElement(v.EnhanceIcon,{wrapperClassName:M.default.action_btn,className:(0,a.getIcon)("clear"),onClick:W,tabIndex:0,role:"button",ariaLabel:(0,m.localize)("aiNative.operate.clear.title")})),r.createElement(p.Popover,{overlayClassName:M.default.popover_icon,id:"ai-chat-header-close",position:p.PopoverPosition.left,title:(0,m.localize)("aiNative.operate.close.title")},r.createElement(v.EnhanceIcon,{wrapperClassName:M.default.action_btn,className:(0,a.getIcon)("window-close"),onClick:j,tabIndex:0,role:"button",ariaLabel:(0,m.localize)("aiNative.operate.close.title")})))}},21967:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ApplyStatus=void 0;const n=e(85608),r=n.__importDefault(e(14041)),o=e(97267),a=n.__importDefault(e(6960)),p=({status:v,error:m})=>{const _=()=>{switch(v){case"generating":return r.default.createElement(o.Loading,null);case"pending":return r.default.createElement(o.Popover,{title:"Pending",id:"edit-file-tool-status-pending"},r.default.createElement(o.Icon,{iconClass:"codicon codicon-circle-large"}));case"success":return r.default.createElement(o.Popover,{title:"Success",id:"edit-file-tool-status-success"},r.default.createElement(o.Icon,{iconClass:"codicon codicon-pass"}));case"failed":return r.default.createElement(o.Popover,{title:`(${m||"Unknown error"})`,id:"edit-file-tool-status-failed"},r.default.createElement(o.Icon,{iconClass:"codicon codicon-error"}));case"cancelled":return r.default.createElement(o.Popover,{title:"Cancelled",id:"edit-file-tool-status-cancelled"},r.default.createElement(o.Icon,{iconClass:"codicon codicon-circle-slash",style:{color:"var(--input-placeholderForeground)"}}));default:return null}};return r.default.createElement("span",{className:a.default.status},_())};t.ApplyStatus=p},87785:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FileListDisplay=void 0;const n=e(85608),r=n.__importStar(e(14041)),o=e(97267),a=e(41869),p=e(54414),v=e(42995),m=e(21967),_=n.__importDefault(e(80919)),s=g=>{const{files:l,onFileClick:h,onRejectAll:u,onAcceptAll:d,hideActions:E}=g,[f,c]=(0,r.useState)(!0),y=(0,a.useInjectable)(p.WorkbenchEditorService),b=(0,a.useInjectable)(a.LabelService),A=(0,r.useMemo)(()=>l.map(R=>{const P=a.URI.parse(R.path),O=b.getIcon(P);return r.default.createElement("span",{className:O})}),[l]),S=l.length,D=l.reduce((R,P)=>({additions:R.additions+P.additions,deletions:R.deletions+P.deletions}),{additions:0,deletions:0}),T=()=>{c(!f)},w=R=>R?r.default.createElement("span",{className:_.default.viewChanges,onClick:P=>{P.stopPropagation(),y.open(a.URI.from({scheme:v.ChatMultiDiffResolver.CHAT_EDITING_MULTI_DIFF_SOURCE_RESOLVER_SCHEME,path:"chat-editing-multi-diff-source"}),{label:(0,a.localize)("aiNative.chat.view-changes")})}},r.default.createElement(o.Icon,{icon:"unorderedlist",size:"small"}),(0,a.localize)("aiNative.chat.view-changes")):null,I=(R,P)=>{const O=[];return R>0&&O.push(r.default.createElement("span",{key:"add",className:_.default.additions},"+",R)),P>0&&(O.length>0&&O.push(" "),O.push(r.default.createElement("span",{key:"del",className:_.default.deletions},"-",P))),O.length===0&&O.push(r.default.createElement("span",{key:"no-change",className:_.default.noChange},"No changes")),O};return r.default.createElement("div",{className:_.default.container},r.default.createElement("div",{className:_.default.header},r.default.createElement("span",{className:_.default.title},r.default.createElement("button",{className:_.default.toggleButton,onClick:T},f?r.default.createElement(o.Icon,{icon:"down"}):r.default.createElement(o.Icon,{icon:"right"})," Changed Files(",S,")"),I(D.additions,D.deletions),!E&&w(l.length)),!E&&l.some(R=>R.status==="pending")&&r.default.createElement("div",{className:_.default.actions},r.default.createElement(o.Button,{type:"link",size:"small",onClick:R=>{R.stopPropagation(),u()}},"Reject"),r.default.createElement(o.Button,{size:"small",onClick:R=>{R.stopPropagation(),d()}},"Accept"))),r.default.createElement("ul",{className:`${_.default.fileList} ${f?"":_.default.collapsed}`},l.map((R,P)=>r.default.createElement("li",{key:P,className:_.default.fileItem,onClick:()=>h(R.path)},r.default.createElement("span",{className:_.default.fileIcon},A[P]||"\u{1F4C4}"),r.default.createElement("div",{className:_.default.fileInfo},r.default.createElement("div",{className:_.default.filePath},R.path),r.default.createElement("div",{className:_.default.fileStats},I(R.additions,R.deletions)),r.default.createElement(m.ApplyStatus,{status:R.status}))))))};t.FileListDisplay=s},25834:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CodeBlockWrapperInput=t.CodeBlockWrapper=t.CodeEditorWithHighlight=void 0;const n=e(85608),r=n.__importDefault(e(56005)),o=n.__importDefault(e(97331)),a=n.__importStar(e(14041)),p=n.__importDefault(e(10580)),v=e(46541),m=e(41869),_=e(81878),s=e(89195),g=e(43718),l=e(71624),h=e(9447),u=e(52416),d=n.__importDefault(e(6960)),E=e(83933),f=e(44692);e(38191);const c=S=>{const{input:D,language:T,relationId:w,agentId:I,command:R,hideInsert:P}=S,O=a.default.useRef(null),M=(0,m.useInjectable)(h.MonacoCommandRegistry),k=(0,m.useInjectable)(m.IClipboardService),F=(0,m.useInjectable)(u.IThemeService),L=(0,m.useInjectable)(g.IAIReporter),[B,U]=(0,a.useState)(!1),W=(0,a.useMemo)(()=>(0,m.uuid)(12),[O,O.current]);(0,a.useEffect)(()=>{const Z=H=>{H.type==="dark"||H.type==="hcDark"?e.e(622).then(e.bind(e,51622)):(H.type==="light"||H.type==="hcLight")&&e.e(412).then(e.bind(e,50412))},$=F.onThemeChange(H=>{Z(H)}),V=F.getCurrentThemeSync();return Z(V),()=>$.dispose()},[]);const j=(0,a.useRef)((0,o.default)(()=>{var Z;if(O.current){const $=O.current,V=(Z=$?.el)===null||Z===void 0?void 0:Z.querySelector("code"),H=V?.children;if(H){const K=H[H.length-1];K&&(K.scrollIntoViewIfNeeded?K.scrollIntoViewIfNeeded():K.scrollIntoView(!1))}}},150,{leading:!0,trailing:!0})).current;(0,a.useEffect)(()=>(j(),()=>{j.cancel()}),[D,j]);const Q=(0,a.useCallback)(async()=>{U(!0),await k.writeText(D),L.end(w,{copy:!0,code:D,language:T,agentId:I,command:R,actionSource:g.ActionSourceEnum.Chat,actionType:g.ActionTypeEnum.ChatCopyCode}),(0,g.runWhenIdle)(()=>{U(!1)},1e3)},[k,D,w]),G=(0,a.useCallback)(()=>{const Z=M.getActiveCodeEditor();if(Z){const $=Z.getSelection();$&&((0,l.insertSnippetWithMonacoEditor)(Z,D,[$],{undoStopBefore:!1,undoStopAfter:!1}),L.end(w,{insert:!0,code:D,language:T,agentId:I,command:R,actionSource:g.ActionSourceEnum.Chat,actionType:g.ActionTypeEnum.ChatInsertCode}))}},[M]);return a.default.createElement("div",{className:d.default.monaco_wrapper},a.default.createElement("div",{className:d.default.action_toolbar},!P&&a.default.createElement(_.Popover,{id:`ai-chat-inser-${W}`,title:(0,g.localize)("aiNative.chat.code.insert")},a.default.createElement(s.EnhanceIcon,{className:(0,m.getIcon)("insert"),onClick:()=>G(),tabIndex:0,role:"button",ariaLabel:(0,g.localize)("aiNative.chat.code.insert")})),a.default.createElement(_.Popover,{id:`ai-chat-copy-${W}`,title:(0,g.localize)(B?"aiNative.chat.code.copy.success":"aiNative.chat.code.copy")},a.default.createElement(s.EnhanceIcon,{className:(0,m.getIcon)("copy"),onClick:()=>Q(),tabIndex:0,role:"button",ariaLabel:(0,g.localize)("aiNative.chat.code.copy")}))),a.default.createElement(p.default,{language:T,ref:O,className:d.default.highlight_editor},D))};t.CodeEditorWithHighlight=c;const y=({content:S="",relationId:D,renderText:T,agentId:w="",command:I="",labelService:R,commandService:P,workspaceService:O})=>{const M=/`([^`]+)`/g,k=/```([^]+?)```/g,F=/```([^]+)?/g,L=/<attached_file>(.*)/g,B=/<attached_folder>(.*)/g,U=(0,a.useCallback)(async(G,Z)=>{const $=await O?.roots;let V;if($)for(const H of $){V=new g.URI(H.uri).resolve(G);try{await P?.executeCommand(m.FILE_COMMANDS.REVEAL_IN_EXPLORER.id,V),Z===f.MentionType.FILE&&await P?.executeCommand(m.EDITOR_COMMANDS.OPEN_RESOURCE.id,V);break}catch{continue}}},[P,O]),W=(G,Z=!1,$)=>a.default.createElement("span",{className:d.default.attachment,key:$,onClick:()=>U(G,Z?f.MentionType.FOLDER:f.MentionType.FILE)},a.default.createElement(_.Icon,{iconClass:Z?(0,m.getIcon)("folder"):R?.getIcon(new g.URI(G||"file"))}),a.default.createElement("span",{className:d.default.attachment_text},G)),j=G=>{const Z=G.split(`
31568
31568
  `)[0].trim().toLowerCase(),$=E.highLightLanguageSupport.find(V=>V===Z)||"plaintext";return G=G.replace(/.*?\n/,""),G=G.trim(),a.default.createElement("div",{className:d.default.code_block},a.default.createElement("div",{className:d.default.code_language},(0,r.default)($)),a.default.createElement(t.CodeEditorWithHighlight,{input:G,language:Z,relationId:D,agentId:w,command:I}))},Q=(0,a.useMemo)(()=>{const G=S.split(k),Z=[];return G.map(($,V)=>{V%2===0?$.split(M).map((H,K)=>{if(K%2===0){if(H.includes("```")){const Y=H.split(F).filter(Boolean);if(Y.length===2){Z.push(Y[0]),Z.push(j(Y[1]));return}}T?Z.push(T(H)):Z.push(H)}else{const Y=H,X=[...H.matchAll(L)],oe=[...H.matchAll(B)];if(X.length||oe.length){let ie=0;const he=[],me=(q,Ee)=>{q.forEach((ue,te)=>{if(ue.index!==void 0){const fe=Y.slice(ie,ue.index);fe&&he.push(a.default.createElement("span",{key:`${K}-${te}-${Ee?"folder":"file"}`},fe)),he.push(W(ue[1],Ee,`${K}-tag-${te}-${Ee?"folder":"file"}`)),ie=ue.index+ue[0].length}})};me(X,!1),me(oe,!0),he.push(Y.slice(ie)),Z.push(...he)}else Z.push(a.default.createElement("span",{className:d.default.code_inline,key:K},H))}}):Z.push(j($))}),Z},[S,T]);return a.default.createElement(a.default.Fragment,null,Q)},b=({text:S,renderText:D,relationId:T,agentId:w,labelService:I,commandService:R,workspaceService:P})=>a.default.createElement("div",{className:d.default.ai_chat_code_wrapper},a.default.createElement("div",{className:d.default.render_text},a.default.createElement(y,{content:S,labelService:I,renderText:D,relationId:T,agentId:w,commandService:R,workspaceService:P})));t.CodeBlockWrapper=b;const A=({text:S,images:D,relationId:T,agentId:w,command:I,labelService:R,workspaceService:P,commandService:O})=>{const M=(0,m.useInjectable)(g.ChatFeatureRegistryToken),[k,F]=(0,a.useState)(""),[L,B]=(0,a.useState)(S);return a.default.useEffect(()=>{const{value:U,nameWithSlash:W}=M.parseSlashCommand(S);if(W){F(W),B(U);return}else B(S)},[S,M]),a.default.createElement("div",{className:d.default.ai_chat_code_wrapper},D?.map(U=>a.default.createElement("div",{className:d.default.image_wrapper},a.default.createElement(v.Image,{src:U}))),a.default.createElement("div",{className:d.default.render_text},k&&a.default.createElement("div",{className:d.default.tag_wrapper},a.default.createElement("span",{className:d.default.tag},k)),w&&a.default.createElement("div",{className:d.default.tag,style:{marginRight:4}},"@",w),I&&a.default.createElement("div",{className:d.default.tag},"/ ",I),a.default.createElement(y,{content:L,labelService:R,relationId:T,agentId:w,command:I,workspaceService:P,commandService:O})))};t.CodeBlockWrapperInput=A},90103:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=e(85608),r=n.__importDefault(e(53373)),o=n.__importStar(e(14041)),a=e(97267),p=e(41869),v=e(89195),m=n.__importDefault(e(35553)),_=100,s=(0,o.memo)(({title:g,historyList:l,currentId:h,onNewChat:u,onHistoryItemSelect:d,onHistoryItemChange:E,onHistoryItemDelete:f,className:c})=>{const[y,b]=(0,o.useState)(null),[A,S]=(0,o.useState)(""),D=(0,o.useRef)(null),T=(0,o.useCallback)(W=>{S(W.target.value)},[A]),w=(0,o.useCallback)(W=>{d(W),S("")},[d,A]),I=(0,o.useCallback)(W=>{b({[W.id]:!0})},[y]),R=(0,o.useCallback)((W,j)=>{b({[W.id]:!1}),E(W,j)},[E,y]),P=(0,o.useCallback)(W=>{b({[W.id]:!1})},[y]),O=(0,o.useCallback)(()=>{u()},[u]);(0,o.useEffect)(()=>{var W;y&&((W=D.current)===null||W===void 0||W.focus({cursor:"end"}))},[y]);const M=(0,o.useCallback)(W=>{f(W)},[f]),k=(0,o.useCallback)(W=>{if(W<60*60*1e3){const Q=Math.floor(W/6e4);return Q===0?"Just now":`${Q}m ago`}else{if(W<24*60*60*1e3)return`${Math.floor(W/36e5)}h ago`;if(W<7*24*60*60*1e3)return`${Math.floor(W/864e5)}d ago`;if(W<30*24*60*60*1e3)return`${Math.floor(W/6048e5)}w ago`;if(W<365*24*60*60*1e3)return`${Math.floor(W/2592e6)}mo ago`}return`${Math.floor(W/(365*24*60*60*1e3))}y ago`},[]),F=(0,o.useCallback)(W=>{const j=new Date,Q=[];return W.forEach(G=>{const Z=new Date(G.updatedAt),$=j.getTime()-Z.getTime(),V=k($),H=Q.find(K=>K.key===V);H?H.items.push(G):Q.push({key:V,items:[G]})}),Q},[k]),L=(0,o.useCallback)(W=>o.default.createElement("div",{key:W.id,className:(0,r.default)(m.default.chat_history_item,W.id===h?m.default.chat_history_item_selected:""),onClick:()=>w(W)},o.default.createElement("div",{className:m.default.chat_history_item_content},W.loading?o.default.createElement(a.Loading,null):o.default.createElement(a.Icon,{icon:"message",style:{width:"16px",height:"16px",marginRight:4}}),y?.[W.id]?o.default.createElement(a.Input,{className:m.default.chat_history_item_title,defaultValue:W.title,ref:D,onPressEnter:j=>{R(W,j.target.value)},onBlur:()=>P(W)}):o.default.createElement("span",{id:`chat-history-item-title-${W.id}`,className:m.default.chat_history_item_title},W.title)),o.default.createElement("div",{className:m.default.chat_history_item_actions},o.default.createElement(v.EnhanceIcon,{className:(0,r.default)(m.default.chat_history_item_actions_delete,(0,a.getIcon)("delete")),onClick:j=>{j.preventDefault(),j.stopPropagation(),M(W)},ariaLabel:(0,p.localize)("aiNative.operate.chatHistory.delete")}))),[y,w,R,P,I,M,h,D]),B=(0,o.useCallback)(()=>{const W=l.slice(0,_).filter(Q=>Q.title&&Q.title.includes(A)),j=F(W);return o.default.createElement("div",null,o.default.createElement(a.Input,{placeholder:(0,p.localize)("aiNative.operate.chatHistory.searchPlaceholder"),className:m.default.chat_history_search,value:A,onChange:T}),o.default.createElement("div",{className:m.default.chat_history_list},j.map(Q=>o.default.createElement("div",{key:Q.key,style:{padding:"4px"}},o.default.createElement("div",{className:m.default.chat_history_time},Q.key),Q.items.map(L)))))},[l,A,F,T,L]),U=(0,o.useCallback)(W=>W.parentElement,[]);return o.default.createElement("div",{className:(0,r.default)(m.default.chat_history_header,c)},o.default.createElement("div",{className:m.default.chat_history_header_title},o.default.createElement("span",null,g)),o.default.createElement("div",{className:m.default.chat_history_header_actions},o.default.createElement(a.Popover,{id:"chat-history-header-actions-history",content:B(),trigger:a.PopoverTriggerType.click,position:a.PopoverPosition.bottomRight,title:(0,p.localize)("aiNative.operate.chatHistory.title"),getPopupContainer:U},o.default.createElement("div",{className:m.default.chat_history_header_actions_history,title:(0,p.localize)("aiNative.operate.chatHistory.title")},o.default.createElement(v.EnhanceIcon,{className:(0,r.default)(m.default.chat_history_header_actions_history,"codicon codicon-history")}))),o.default.createElement(a.Popover,{id:"ai-chat-header-new",position:a.PopoverPosition.top,title:(0,p.localize)("aiNative.operate.newChat.title")},o.default.createElement(v.EnhanceIcon,{className:(0,r.default)(m.default.chat_history_header_actions_new,(0,a.getIcon)("plus")),onClick:O}))))});t.default=s},57987:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ChatInput=void 0;const n=e(85608),r=n.__importDefault(e(53373)),o=n.__importStar(e(14041)),a=e(41869),p=e(81878),v=e(89195),m=e(83913),_=e(43718),s=e(92323),g=e(9447),l=e(72665),h=e(19413),u=e(42033),d=e(51081),E=e(27397),f=e(30703),c=n.__importDefault(e(6960)),y=8,b=68,A=({icon:w,name:I,description:R,agentId:P,command:O,selectedAgentId:M})=>{const k=(0,o.useMemo)(()=>!M&&P&&P!==d.ChatProxyService.AGENT_ID&&O?o.default.createElement("span",{className:c.default.agent_label},"@",P):null,[]);return o.default.createElement("div",{className:c.default.block},w&&o.default.createElement(v.EnhanceIcon,{className:w}),I&&o.default.createElement("span",{className:c.default.name},I),R&&o.default.createElement("span",{className:c.default.text},R),k)},S=({onClick:w,bottom:I,trigger:R,agentId:P})=>{const O=(0,a.useInjectable)(h.IChatAgentService),M=(0,a.useInjectable)(_.ChatAgentViewServiceToken),k=(0,o.useMemo)(()=>R===h.AT_SIGN_SYMBOL?M.getRenderAgents().map(L=>new u.ChatSlashCommandItemModel({icon:"",name:`${h.AT_SIGN_SYMBOL}${L.id} `,description:L.metadata.description},"",L.id)):O.getCommands().map(L=>new u.ChatSlashCommandItemModel({icon:"",name:`${h.SLASH_SYMBOL} ${L.name} `,description:L.description},L.name,L.agentId)).filter(L=>!P||L.agentId===P),[R,O]),F=(0,o.useCallback)((L,B,U)=>{w&&w(L||"",B,U)},[w]);return k.length===0?null:o.default.createElement("div",{className:c.default.instruction_options_container,style:{bottom:I+"px"}},o.default.createElement("div",{className:c.default.options},o.default.createElement("ul",null,k.map(({icon:L,name:B,nameWithSlash:U,description:W,agentId:j,command:Q})=>o.default.createElement("li",{key:`${j||""}-${B}`,onMouseDown:()=>F(U,j,Q)},o.default.createElement(A,{icon:L,name:B,description:W,agentId:j,command:Q,selectedAgentId:P}))))))},D=({themeBlock:w})=>o.default.createElement("div",{className:c.default.theme_container},o.default.createElement("div",{className:c.default.theme_block},w)),T=({agentId:w,command:I})=>o.default.createElement("div",{className:c.default.theme_container},w!==d.ChatProxyService.AGENT_ID&&o.default.createElement("div",{className:c.default.theme_block,style:{marginRight:4}},"@",w),I&&o.default.createElement("div",{className:c.default.theme_block},h.SLASH_SYMBOL," ",I));t.ChatInput=o.default.forwardRef((w,I)=>{const{onSend:R,onValueChange:P,enableOptions:O=!1,disabled:M=!1,defaultHeight:k=32,autoFocus:F,setTheme:L,theme:B,setAgentId:U,agentId:W,defaultAgentId:j,setCommand:Q,command:G,sendBtnClassName:Z}=w,$=W||j,V=(0,o.useRef)(null),H=(0,o.useRef)(null),[K,Y]=(0,o.useState)(w.value||""),[X,oe]=(0,o.useState)(!1),[ie,he]=(0,o.useState)(k),[me,q]=(0,o.useState)(!1),[Ee,ue]=(0,o.useState)(!1),[te,fe]=(0,o.useState)(!1),[Ie,Me]=(0,o.useState)((0,_.localize)("aiNative.chat.input.placeholder.default")),Be=(0,a.useInjectable)(h.IChatInternalService),Pe=(0,a.useInjectable)(l.IDialogService),we=(0,a.useInjectable)(a.AINativeConfigService),_e=(0,a.useInjectable)(h.TokenMCPServerProxyService),Ne=(0,a.useInjectable)(g.MonacoCommandRegistry),Te=(0,a.useInjectable)(h.IChatAgentService),We=(0,a.useInjectable)(_.ChatFeatureRegistryToken),pe=(0,a.useInjectable)(s.CommandService),re=(0,a.useLatest)($),ge=o.default.useCallback(()=>{pe.executeCommand(E.MCPConfigCommands.OPEN_MCP_CONFIG.id)},[pe]),De=o.default.useCallback(async()=>{const rt=await _e.getAllMCPTools();Pe.open({message:o.default.createElement(f.MCPToolsDialog,{tools:rt}),type:_.MessageType.Empty,buttons:[(0,_.localize)("dialog.file.close")]})},[_e,Pe]);(0,o.useImperativeHandle)(I,()=>({setInputValue:rt=>{Y(rt),(0,_.runWhenIdle)(()=>{var lt;(lt=V.current)===null||lt===void 0||lt.focus()},120)}})),(0,o.useEffect)(()=>{w.value!==K&&Y(w.value||"")},[w.value]),(0,o.useEffect)(()=>{var rt;(rt=V.current)===null||rt===void 0||rt.focus();const lt=(0,_.localize)("aiNative.chat.input.placeholder.default"),At=We.getSlashCommandHandler(G);if(At&&At.providerInputPlaceholder){const jt=Ne.getActiveCodeEditor(),_n=At.providerInputPlaceholder(K,jt);Me(_n||lt)}else Me(lt)},[We,G]),(0,o.useEffect)(()=>{Ke(B||"",$,G)},[B,$,G]),(0,o.useEffect)(()=>{var rt;V&&F&&((rt=V.current)===null||rt===void 0||rt.focus())},[V,F,w.value]),(0,o.useEffect)(()=>{if(O&&((K===h.SLASH_SYMBOL||K===h.AT_SIGN_SYMBOL&&Te.getAgents().length>0)&&!te?oe(!0):oe(!1)),K.startsWith(h.SLASH_SYMBOL)){const{value:rt,nameWithSlash:lt}=We.parseSlashCommand(K);if(lt){const At=We.getSlashCommandBySlashName(lt);Y(rt),L(lt),At&&(U(At.agentId),Q(At.command));return}}if(Te.getAgents().length){const rt=Te.parseMessage(K,re.current);(rt.agentId||rt.command)&&(L(""),Y(rt.message),rt.agentId&&U(rt.agentId),rt.command&&Q(rt.command))}},[V,K,O,We]),(0,o.useEffect)(()=>{K||(he(k),ue(!1),fe(!1))},[K]);const Ae=(0,o.useCallback)(rt=>{Y(rt),P&&P(rt)},[]),Ue=(0,o.useCallback)(()=>{Be.cancelRequest()},[]),Ye=(0,o.useCallback)(async()=>{if(M)return;const rt=(lt=K)=>{R(lt,[],$,G),Y(""),L(""),U(""),Q("")};if(G){const lt=We.getSlashCommandHandler(G);if(lt&&lt.execute){const At=Ne.getActiveCodeEditor();await lt.execute(K,jt=>rt(jt),At);return}}rt()},[R,K,$,G,We]),Ke=(0,o.useCallback)((rt,lt,At)=>{if(lt){if(oe(!1),L(""),U(lt),Q(At||""),V?.current){const jt=V.current.value;(jt===h.AT_SIGN_SYMBOL||At&&jt===h.SLASH_SYMBOL)&&Y(""),(0,_.runWhenIdle)(()=>V.current.focus())}}else if(rt){oe(!1),U(""),Q("");const jt=We.getSlashCommandBySlashName(rt);if(L(jt?jt.nameWithSlash:""),V&&V.current){const _n=V.current.value;_n.length===1&&_n.startsWith(h.SLASH_SYMBOL)&&Y(""),(0,_.runWhenIdle)(()=>V.current.focus())}}},[V,We]),mt=(0,o.useMemo)(()=>{const rt=y+ie;return te&&oe(!1),rt},[ie]),_t=rt=>{var lt,At;if(rt.key==="Backspace"&&((lt=V.current)===null||lt===void 0?void 0:lt.selectionEnd)===0&&((At=V.current)===null||At===void 0?void 0:At.selectionStart)===0){if(L(""),$===d.ChatProxyService.AGENT_ID){Q(""),U("");return}$&&(G?Q(""):U(""))}},Mt=(0,o.useCallback)(rt=>{he(rt),rt>b?ue(!0):ue(!1)},[]),ct=(0,o.useCallback)(()=>{q(!1),oe(!1)},[V]),wt=(0,o.useCallback)(()=>{q(!0)},[V]),st=(0,o.useCallback)(()=>{const rt=te;if(fe(!rt),rt)he(k),ue(!1);else{const At=document.querySelector("#ai_chat_left_container").clientHeight-68-(B?32:0)-16;he(At)}},[te]);return o.default.createElement("div",{className:(0,r.default)(c.default.chat_input_container,me?c.default.active:null)},X&&o.default.createElement("div",{ref:H},o.default.createElement(S,{onClick:Ke,bottom:mt,trigger:K,agentId:$})),B&&o.default.createElement(D,{themeBlock:B}),$&&o.default.createElement(T,{agentId:$,command:G}),Ee&&o.default.createElement("div",{className:c.default.expand_icon,onClick:()=>st()},o.default.createElement(p.Popover,{id:"ai_chat_input_expand",title:(0,_.localize)(te?"aiNative.chat.expand.unfullscreen":"aiNative.chat.expand.fullescreen")},o.default.createElement(p.Icon,{className:(0,r.default)(te?(0,p.getIcon)("unfullscreen"):(0,p.getIcon)("fullescreen"))}))),o.default.createElement(m.InteractiveInput,{ref:V,placeholder:Ie,value:K,onKeyDown:_t,onBlur:ct,onFocus:wt,onValueChange:Ae,disabled:M,className:c.default.input_wrapper,onSend:Ye,onStop:Ue,sendBtnClassName:Z,onHeightChange:Mt,height:ie,popoverPosition:p.PopoverPosition.left}),o.default.createElement("div",{className:c.default.chat_input_footer},we.capabilities.supportsMCP&&o.default.createElement("div",{className:c.default.mcp_desc},o.default.createElement(p.Popover,{overlayClassName:c.default.popover_icon,id:"ai-chat-header-mcp-server",position:p.PopoverPosition.left,title:"MCP Server"},o.default.createElement(v.EnhanceIcon,{wrapperClassName:c.default.action_btn,className:"codicon codicon-radio-tower",onClick:ge,tabIndex:0,role:"button",ariaLabel:"MCP Server"})),o.default.createElement(p.Popover,{overlayClassName:c.default.popover_icon,id:"ai-chat-header-tools",position:p.PopoverPosition.left,title:(0,_.localize)("aiNative.operate.tools.title")},o.default.createElement(v.EnhanceIcon,{wrapperClassName:c.default.action_btn,className:(0,p.getIcon)("menubar-tool"),onClick:De,tabIndex:0,role:"button",ariaLabel:(0,_.localize)("aiNative.operate.tools.title")})))))})},56474:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ChatMarkdown=void 0,t.postProcessCodeBlockLanguageId=l,t.fillInIncompleteTokens=h;const n=e(85608),r=n.__importDefault(e(53373)),o=n.__importStar(e(14041)),a=e(13719),p=e(84605),v=e(41869),m=e(90684),_=e(25834),s=n.__importDefault(e(6960)),g=I=>{const R=(0,o.useRef)(null),P=(0,v.useInjectable)(v.AppConfig),[O,M]=(0,o.useState)(),[k,F]=(0,o.useState)();return(0,o.useEffect)(()=>{var L;if(!R.current)return;const U=typeof I.markdown=="string"?new m.MarkdownString(I.markdown):I.markdown,W=new a.MarkdownReactRenderer;W.code=(V,H)=>{const K=l(H);return o.default.createElement("div",{className:s.default.code},o.default.createElement(v.ConfigProvider,{value:P},o.default.createElement("div",{className:s.default.code_block},o.default.createElement("div",{className:(0,r.default)(s.default.code_language,"language-badge")},K),o.default.createElement(_.CodeEditorWithHighlight,{input:V,language:K,relationId:I.relationId||"",agentId:I.agentId,command:I.command,hideInsert:I.hideInsert}))))},W.codespan=V=>o.default.createElement("code",{className:s.default.code_inline},V);const j=new a.MarkdownReactParser({renderer:W}),Q={...p.marked.defaults,...I.markedOptions,renderer:j,smartypants:!1};let G=(L=U.value)!==null&&L!==void 0?L:"";G.length>1e5&&(G=`${G.slice(0,1e5)}\u2026`);let Z,$;if(I.fillInIncompleteTokens){const V=p.marked.lexer(G,Q),H=h(V);Z=p.marked.parser(H,Q),$=H}else{const V=p.marked.lexer(G,Q);Z=p.marked.parser(V,Q),$=V}F($),M(j)},[I.markdown]),o.default.createElement("div",{className:(0,r.default)(s.default.markdown_container,I.className),ref:R,tabIndex:0},k&&O&&O.parse(k))};t.ChatMarkdown=g;function l(I){if(!I)return"";const R=I.split(/[\s+|:|,|\{|\?]/,1);return R.length?R[0]:I}function h(I){let R,P;for(R=0;R<I.length;R++){const O=I[R];if(O.type==="paragraph"&&O.raw.match(/(\n|^)```/)){P=u(I.slice(R));break}if(O.type==="paragraph"&&O.raw.match(/(\n|^)\|/)){P=D(I.slice(R));break}if(O.type==="paragraph"&&R===I.length-1){const M=w(O);if(M){P=[M];break}}}if(P){const O=[...I.slice(0,R),...P];return O.links=I.links,O}return I}function u(I){const R=T(I);return p.marked.lexer(R+"\n```")}function d(I){return S(I,"`")}function E(I){return S(I,"*")}function f(I){return S(I,"_")}function c(I){return S(I,")")}function y(I){return S(I,"](about:blank)")}function b(I){return S(I,"**")}function A(I){return S(I,"__")}function S(I,R){const P=T(Array.isArray(I)?I:[I]);return p.marked.lexer(P+R)[0]}function D(I){const R=T(I),P=R.split(`
31569
31569
  `);let O=0,M=!1;for(let k=0;k<P.length;k++){const F=P[k].trim();if(typeof O>"u"&&F.match(/^\s*\|/)){const L=F.match(/(\|[^\|]+)(?=\||$)/g);L&&(O=L.length)}else if(typeof O=="number")if(F.match(/^\s*\|/)&&k===P.length-1)M=!0;else return}if(O>0){const k=M?P.slice(0,-1).join(`
31570
31570
  `):R,F=!!k.match(/\|\s*$/),L=k+(F?"":"|")+`
@@ -31655,7 +31655,7 @@ ${A.slice(1).join(`
31655
31655
  `).slice(d.startPosition.row);return`${f[0].slice(d.startPosition.column)}${f.length>1?`
31656
31656
  ${f.slice(1).join(`
31657
31657
  `)}`:""}`}}return l.text}findTypeIdentifier(l){let h=l;for(;h;){if(h.type==="type_identifier")return h.text;const u=h.child(1);if(!u)break;h=u}return""}async extractImportPaths(l){var h;const u=[],d=await this.parser.parse(l),E=d?.rootNode,f=[],c=[];if(E)for(let y=0;y<E?.childCount;y++){const b=E.child(y);if(b?.type==="import_statement")f.push(b);else if(b?.type==="type_annotation"){const A=b.child(1);A&&c.push(A.text)}else if(b?.type==="lexical_declaration"){const A=this.findTypeIdentifier(b);A&&c.push(A)}}for(const y of f)if(c.some(b=>y.text.includes(b))){let b=(h=y.child(3))===null||h===void 0?void 0:h.text;(b?.includes("'")||b?.includes('"'))&&(b=b.slice(1,-1)),b&&u.push(b)}return u}async extractInterfaceOrTypeCode(l){var h;const u=[];if(this.language==="typescript"){await this.parserLoaded.promise;const d=(h=this.parser)===null||h===void 0?void 0:h.parse(l),E=d?.rootNode;if(E)for(let f=0;f<E?.childCount;f++){const c=E.child(f);if(c?.type==="export_statement"){const y=c.child(1);(y?.type==="interface_declaration"||y?.type==="type_alias_declaration")&&u.push(y.text)}else(c?.type==="interface_declaration"||c?.type==="type_alias_declaration")&&u.push(c.text)}}return u}async findSyntaxErrorCount(l){var h;await this.parserLoaded.promise;const u=(h=this.parser)===null||h===void 0?void 0:h.parse(l),d=u?.rootNode;if(!d)return 0;let E=0;const f=c=>{(c.type==="function_declaration"||c.type==="class_declaration"||c.type==="variable_declarator"||c.type==="statement_block"||c.type==="expression_statement")&&(c.hasError||c.isMissing||c.type==="ERROR")&&E++;for(let b=0;b<c.childCount;b++){const A=c.child(b);A&&f(A)}};return f(d),E}async findNearestCodeBlockWithPosition(l,h){const u=await this.parser.parse(l);if(u){const{rootNode:d}=u,E=d.namedDescendantForIndex(h),f=this.findContainingCodeBlockWithPosition(E,h);if(!f)return null;let y=l.split(`
31658
- `).slice(0,f.startPosition.row).reduce((b,A)=>b+A.length,0);return y+=f.startPosition.row,y+=f.startPosition.column,{codeBlock:f.text,range:{start:{line:f.startPosition.row,character:0},end:{line:f.endPosition.row,character:1/0}},offset:y,type:f.startPosition.row===f.endPosition.row?p.NearestCodeBlockType.Line:p.NearestCodeBlockType.Block}}return null}dispose(){this.parser.delete(),this.lruCache.clear()}};t.LanguageParser=s,n.__decorate([(0,o.Autowired)(_.WasmModuleManager),n.__metadata("design:type",_.WasmModuleManager)],s.prototype,"wasmModuleManager",void 0),n.__decorate([(0,o.Autowired)(m.TreeSitterLanguageFacts),n.__metadata("design:type",m.TreeSitterLanguageFacts)],s.prototype,"languageFacts",void 0),t.LanguageParser=s=n.__decorate([(0,o.Injectable)({multiple:!0}),n.__metadata("design:paramtypes",[String])],s)},85679:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.LanguageParserService=void 0;const n=e(85608),r=e(76003),o=e(3073),a=e(22486);let p=class{constructor(){this.pool=new Map}createParser(m){const _=a.parserNameMap[m];if(_)return this.pool.has(_)||this.pool.set(_,this.injector.get(o.LanguageParser,[_])),this.pool.get(_)}dispose(){this.pool.forEach(m=>m.dispose()),this.pool.clear()}};t.LanguageParserService=p,n.__decorate([(0,r.Autowired)(r.INJECTOR_TOKEN),n.__metadata("design:type",r.Injector)],p.prototype,"injector",void 0),t.LanguageParserService=p=n.__decorate([(0,r.Injectable)()],p)},53374:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.toMonacoRange=e;function e(n){return{startLineNumber:n.startPosition.row+1,startColumn:n.startPosition.column+1,endLineNumber:n.endPosition.row+1,endColumn:n.endPosition.column+1}}},19584:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.GolangLanguageFacts=void 0;const e=["function_declaration","method_declaration","block","if_statement","else_statement","switch_statement","case_clause","for_statement","range_clause","type_switch_statement","type_case_clause","comm_clause","select_statement","go_statement","defer_statement"],n=new Set(e);class r{constructor(){this.name="go",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return n}isCodeBlock(a){return n.has(a)}}t.GolangLanguageFacts=r},22486:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TreeSitterLanguageFacts=t.knownLanguageFacts=void 0;const n=e(85608);n.__exportStar(e(17973),t);const r=e(76003),o=e(19584),a=e(44606),p=e(82381),v=e(41486),m=e(98588),_=e(96436),s=e(2349),g=e(78542),l=new Set;t.knownLanguageFacts=[o.GolangLanguageFacts,a.JavaLanguageFacts,p.JavaScriptLanguageFacts,v.JavaScriptReactLanguageFacts,m.PythonLanguageFacts,_.RustLanguageFacts,s.TypeScriptLanguageFacts,g.TypeScriptReactLanguageFacts];let h=class{constructor(){this.langs=new Map,t.knownLanguageFacts.forEach(d=>{const E=new d;this.langs.set(E.name,E)})}isCodeBlock(d,E){const f=this.langs.get(d);return f&&f.isCodeBlock?f.isCodeBlock(E):!1}isFunctionCodeBlock(d,E){const f=this.langs.get(d);return f&&f.isFunctionCodeBlocks?f.isFunctionCodeBlocks(E):!1}provideFunctionInfo(d,E){const f=this.langs.get(d);return f&&f.provideFunctionInfo?f.provideFunctionInfo(E):null}getCodeBlockTypes(d){const E=this.langs.get(d);return E?E.provideCodeBlocks():l}};t.TreeSitterLanguageFacts=h,t.TreeSitterLanguageFacts=h=n.__decorate([(0,r.Injectable)(),n.__metadata("design:paramtypes",[])],h)},44606:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.JavaLanguageFacts=void 0;const e=["compilation_unit","class_declaration","interface_declaration","enum_declaration","method_declaration","constructor_declaration","block","static_initializer","instance_initializer","if_statement","switch_statement","while_statement","do_statement","for_statement","enhanced_for_statement","try_statement","catch_clause","finally_clause"],n=new Set(["method_declaration","constructor_declaration"]),r=new Set(e);class o{constructor(){this.name="java",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return r}isCodeBlock(p){return r.has(p)}isFunctionCodeBlocks(p){return n.has(p)}}t.JavaLanguageFacts=o},82381:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.JavaScriptLanguageFacts=t.functionBlockCodeTypes=t.javascriptBlockCodeTypes=void 0;const n=e(53374);t.javascriptBlockCodeTypes=["function","function_declaration","function_expression","arrow_function","class_declaration","method_definition","if_statement","switch_case","while_statement","do_statement","for_statement","for_in_statement","try_statement","catch_clause","block","export_statement","lexical_declaration"],t.functionBlockCodeTypes=["function","function_declaration","function_expression","arrow_function","method_definition"];const r=new Set(t.functionBlockCodeTypes),o=new Set(t.javascriptBlockCodeTypes);class a{constructor(){this.name="javascript",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return o}isCodeBlock(v){return o.has(v)}isFunctionCodeBlocks(v){return r.has(v)}provideFunctionInfo(v){var m,_,s;switch(v.type){case"function_declaration":case"function_expression":return{infoCategory:"function",type:v.type,name:((m=v.firstNamedChild)===null||m===void 0?void 0:m.text)||"",signatures:v.children.filter(g=>g.type==="parameter").map(g=>{var l;return((l=g.firstChild)===null||l===void 0?void 0:l.text)||""}),range:(0,n.toMonacoRange)(v)};case"arrow_function":{const g=v.parent;return g&&g.type==="variable_declarator"&&g.parent&&(g.parent.type==="lexical_declaration"||g.parent.type==="export_statement"||g.parent.type==="variable_declaration")?{infoCategory:"function",type:v.type,name:((_=g.firstChild)===null||_===void 0?void 0:_.text)||"",signatures:v.children.filter(l=>l.type==="parameter").map(l=>{var h;return((h=l.firstChild)===null||h===void 0?void 0:h.text)||""}),range:(0,n.toMonacoRange)(g.parent)}:null}case"method_definition":return{infoCategory:"function",type:v.type,name:((s=v.firstNamedChild)===null||s===void 0?void 0:s.text)||"",signatures:v.children.filter(g=>g.type==="parameter").map(g=>{var l;return((l=g.firstChild)===null||l===void 0?void 0:l.text)||""}),range:(0,n.toMonacoRange)(v)}}return null}}t.JavaScriptLanguageFacts=a},41486:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.JavaScriptReactLanguageFacts=t.javascriptreactBlockCodeTypes=void 0;const n=e(82381);t.javascriptreactBlockCodeTypes=[...n.javascriptBlockCodeTypes,"jsx_element","jsx_self_closing_element","jsx_expression","jsx_fragment"];const r=new Set(t.javascriptreactBlockCodeTypes);class o{constructor(){this.name="jsx",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return r}isCodeBlock(p){return r.has(p)}}t.JavaScriptReactLanguageFacts=o},98588:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PythonLanguageFacts=t.pythonBlockCodeTypes=void 0,t.pythonBlockCodeTypes=["function_definition","class_definition","compound_statement","if_statement","elif_clause","else_clause","for_statement","while_statement","try_statement","except_clause","with_statement","decorated_definition"];const e=new Set(t.pythonBlockCodeTypes);class n{constructor(){this.name="python",this.listCommentStyle="# ",this.blockCommentStyle={start:"'''",end:"'''",linePrefix:""}}provideCodeBlocks(){return e}isCodeBlock(o){return e.has(o)}}t.PythonLanguageFacts=n},96436:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.RustLanguageFacts=t.rustBlockCodeTypes=void 0,t.rustBlockCodeTypes=["function_item","impl_item","trait_item","block","if_expression","match_expression","while_expression","loop_expression","for_expression","closure_expression","struct_item","enum_item","union_item","mod_item"];const e=new Set(t.rustBlockCodeTypes);class n{constructor(){this.name="rust",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return e}isCodeBlock(o){return e.has(o)}}t.RustLanguageFacts=n},17973:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parserIdentifierMap=t.parserNameMap=void 0;const r=e(85608).__importDefault(e(19891)),o={typescript:"typescript",typescriptreact:"tsx",javascript:"javascript",javascriptreact:"jsx",rust:"rust",python:"python",java:"java",go:"go"};t.parserNameMap=o,t.parserIdentifierMap=(0,r.default)(t.parserNameMap)},2349:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TypeScriptLanguageFacts=t.typescriptBlockTypes=void 0,t.typescriptBlockTypes=["function","function_declaration","function_expression","arrow_function","class_declaration","interface_declaration","method_definition","method_signature","enum_declaration","type_alias_declaration","lexical_declaration","if_statement","switch_case","while_statement","do_statement","for_statement","for_in_statement","for_of_statement","try_statement","catch_clause","block","module","public_field_definition","private_field_definition","export_statement"];const e=new Set(t.typescriptBlockTypes);class n{constructor(){this.name="typescript",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return e}isCodeBlock(o){return e.has(o)}}t.TypeScriptLanguageFacts=n},78542:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TypeScriptReactLanguageFacts=t.typescriptreactBlockTypes=void 0;const n=e(2349);t.typescriptreactBlockTypes=[...n.typescriptBlockTypes,"jsx_element","jsx_self_closing_element","jsx_expression","jsx_fragment"];const r=new Set(t.typescriptreactBlockTypes);class o{constructor(){this.name="tsx",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return r}isCodeBlock(p){return r.has(p)}}t.TypeScriptReactLanguageFacts=o},67045:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WasmModuleManager=void 0;const n=e(85608),r=n.__importDefault(e(13833)),o=e(76003),a=e(6858),p=e(70392);let v=class{async resolveResourceUri(){const _=await this.rendererRuntime.provideResourceUri(a.EKnownResources.TreeSitterWasmDirectory);this.resolvedResourceUriDeferred.resolve(_)}constructor(){this.resolvedResourceUriDeferred=new p.Deferred,this.cachedRuntime=new Map,this.parserInitialized=!1,this.resolveResourceUri()}async initParser(){const _=await this.resolvedResourceUriDeferred.promise;let s;return _.endsWith("/")?s=`${_}tree-sitter.wasm`:s=`${_}/tree-sitter.wasm`,this.parserInitialized||(await r.default.init({locateFile:()=>s}),this.parserInitialized=!0),new r.default}async loadLanguage(_){if(!this.cachedRuntime.has(_)){const s=new p.Deferred;this.cachedRuntime.set(_,s);const g=await this.resolvedResourceUriDeferred.promise;let l;g.endsWith("/")?l=`${g}tree-sitter-${_}.wasm`:l=`${g}/tree-sitter-${_}.wasm`,fetch(l).then(h=>h.arrayBuffer()).then(h=>{s.resolve(h)})}return this.cachedRuntime.get(_).promise}};t.WasmModuleManager=v,n.__decorate([(0,o.Autowired)(a.RendererRuntime),n.__metadata("design:type",a.RendererRuntime)],v.prototype,"rendererRuntime",void 0),t.WasmModuleManager=v=n.__decorate([(0,o.Injectable)(),n.__metadata("design:paramtypes",[])],v)},4972:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AIRightTabRenderer=t.AILeftTabRenderer=t.AIChatTabRendererWithTab=t.AIChatTabRenderer=void 0;const n=e(85608),r=n.__importDefault(e(53373)),o=n.__importStar(e(14041)),a=e(41869),p=e(89195),v=e(1149),m=e(43718),_=e(11090),s=e(63067),g=e(46245),l=e(66368),h=e(19951),u=e(752),d=e(19413),E=n.__importDefault(e(87708)),f=()=>{const{side:D}=o.default.useContext(h.TabbarConfig),T=(0,a.useInjectable)(u.TabbarServiceFactory)(D);return(0,o.useEffect)(()=>{T.setIsLatter(!0)},[T]),o.default.createElement("div",{style:{width:0}},o.default.createElement(g.TabbarViewBase,{tabSize:0,MoreTabView:g.IconElipses,TabView:g.IconTabView,barSize:0,panelBorderSize:1}))},c=({className:D,components:T})=>o.default.createElement(h.TabRendererBase,{side:d.AI_CHAT_VIEW_ID,direction:"left-to-right",id:E.default.ai_chat_panel,className:(0,r.default)(D,`${d.AI_CHAT_VIEW_ID}-slot`),components:T,TabbarView:()=>o.default.createElement(f,null),TabpanelView:()=>o.default.createElement(l.BaseTabPanelView,{PanelView:l.ContainerView,PanelViewProps:{className:E.default.ai_chat_view_container}})});t.AIChatTabRenderer=c;const y=({className:D,components:T})=>o.default.createElement(h.TabRendererBase,{side:d.AI_CHAT_VIEW_ID,direction:"right-to-left",id:E.default.ai_chat_panel,className:(0,r.default)(D,`${d.AI_CHAT_VIEW_ID}-slot`,"design_right_slot"),components:T,TabbarView:()=>o.default.createElement(g.ChatTabbarRenderer2,null),TabpanelView:()=>o.default.createElement(l.BaseTabPanelView,{PanelView:l.ContainerView,PanelViewProps:{className:E.default.ai_chat_view_container}})});t.AIChatTabRendererWithTab=y;const b=({className:D,components:T})=>o.default.createElement(_.DesignLeftTabRenderer,{className:D,components:T,tabbarView:A});t.AILeftTabRenderer=b;const A=()=>{const D=(0,a.useInjectable)(s.IMainLayoutService),T=(0,a.useInjectable)(u.TabbarServiceFactory)(a.SlotLocation.right),w=(0,a.useAutorun)(T.currentContainerId),I=o.default.useMemo(()=>D.getExtraMenu(),[D]),[R]=(0,a.useContextMenus)(I),P=(0,o.useCallback)(({renderContainers:O})=>{const M=T.visibleContainers.filter(k=>{var F;return!(!((F=k.options)===null||F===void 0)&&F.hideTab)});return o.default.createElement(o.default.Fragment,null,M.length>0&&o.default.createElement(p.HorizontalVertical,{margin:"8px auto 0px",width:"60%"}),M.map(k=>O(k,T,w)))},[w,T]);return o.default.createElement(g.LeftTabbarRenderer,{renderOtherVisibleContainers:P,isRenderExtraTopMenus:!1,renderExtraMenus:o.default.createElement("div",{className:E.default.extra_bottom_icon_container},R.length>=0?R.map(O=>o.default.createElement(p.EnhanceIconWithCtxMenu,{key:O.id,id:O.id,wrapperClassName:E.default.extra_bottom_icon,iconClass:O.icon,menuNodes:O.children,skew:{x:-8,y:-4}})):null)})},S=({className:D,components:T})=>{const w=(0,a.useInjectable)(u.TabbarServiceFactory)(a.SlotLocation.right),I=(0,a.useInjectable)(v.DesignLayoutConfig),R=(0,o.useCallback)(()=>{w.updateCurrentContainerId("")},[]),P=(0,o.useCallback)(M=>{const{component:k}=M,{options:F}=k;return o.default.createElement(l.ContainerView,{...M,customTitleBar:o.default.createElement("div",{className:E.default.header},o.default.createElement("span",{className:E.default.title},F&&F.title),o.default.createElement("div",{className:E.default.side},o.default.createElement(p.EnhancePopover,{id:"ai_right_panel_header_close",title:(0,m.localize)("editor.title.context.close")},o.default.createElement(p.EnhanceIcon,{icon:"close",onClick:R})))),renderContainerWrap:({children:L})=>o.default.createElement("div",{className:E.default.right_slot_container_wrap},o.default.createElement("div",{className:E.default.container},L))})},[]),O=(0,o.useMemo)(()=>I.useMergeRightWithLeftPanel?E.default.right_tab_renderer:"",[I]);return o.default.createElement(_.DesignRightTabRenderer,{components:T,className:O,tabbarView:()=>o.default.createElement(g.RightTabbarRenderer,{barSize:0,style:{width:0}}),tabpanelView:()=>o.default.createElement(l.BaseTabPanelView,{PanelView:P})})};t.AIRightTabRenderer=S},82983:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AIChatLogoAvatar=void 0;const n=e(85608),r=n.__importDefault(e(14041)),o=e(41869),a=e(89195),p=e(63067),v=e(19413),m=n.__importDefault(e(88473)),_=()=>{const s=(0,o.useInjectable)(p.IMainLayoutService),g=r.default.useCallback(()=>{s.toggleSlot(v.AI_CHAT_VIEW_ID)},[s]);return r.default.createElement("div",{className:m.default.ai_switch,onClick:g},r.default.createElement(a.AILogoAvatar,{iconClassName:m.default.avatar_icon_large}))};t.AIChatLogoAvatar=_},73974:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.BaseApplyService=void 0;const n=e(85608),r=e(41429),o=e(76003),a=e(41869),p=e(54414),v=e(57517),m=e(55126),_=e(20868),s=e(70392),g=e(2261),l=e(19413),h=e(59347),u=e(40111),d=e(15989);class E extends a.WithEventBus{constructor(){super(),this.onCodeBlockUpdateEmitter=new s.Emitter,this.onCodeBlockUpdate=this.onCodeBlockUpdateEmitter.event,this.activePreviewerMap=this.registerDispose(new s.DisposableMap),this.editorListenerMap=this.registerDispose(new s.DisposableMap),this.addDispose(this.chatInternalService.onCancelRequest(()=>{const c=this.chatInternalService.sessionModel.history.lastMessageId;if(!c)return;const y=this.getMessageCodeBlocks(c);y&&Object.values(y).forEach(b=>{this.cancelApply(b)})})),this.currentSessionId=this.chatInternalService.sessionModel.sessionId,this.addDispose(this.chatInternalService.onChangeSession(c=>{c!==this.currentSessionId&&(this.cancelAllApply(),this.currentSessionId=c)})),this.addDispose(this.chatInternalService.onRegenerateRequest(()=>{const c=this.chatInternalService.sessionModel.history.getMessages(),y=c[c.length-1].id,b=this.getMessageCodeBlocks(y);b&&Object.values(b).forEach(A=>{this.cancelApply(A)})})),this.addDispose(this.chatInternalService.onWillClearSession(c=>{this.cancelAllApply(c)}))}getMessageCodeBlocks(c,y){y=y||this.chatInternalService.sessionModel.sessionId;const b=this.chatInternalService.getSession(y);if(!b)throw new Error(`Session ${y} not found`);const A=b.history.getMessageAdditional(c);return A?.codeBlockMap}onEditorGroupClose(c){const y=s.path.relative(this.appConfig.workspaceDir,c.payload.resource.uri.path.toString());this.activePreviewerMap.get(y)&&this.activePreviewerMap.disposeKey(y),this.editorListenerMap.disposeKey(c.payload.resource.uri.toString())}async onEditorGroupOpen(c){var y;const b=s.path.relative(this.appConfig.workspaceDir,c.payload.resource.uri.path.toString());if(this.duringApply||this.activePreviewerMap.has(b)||!this.chatInternalService.sessionModel.history.getMessages().length)return;const A=((y=this.getUriCodeBlocks(c.payload.resource.uri))===null||y===void 0?void 0:y.filter(S=>S.status==="pending"))||[];if(A.length>0&&A[0].updatedCode){const S=c.payload.group.codeEditor.monacoEditor;await this.renderApplyResult(S,A[0],A[0].updatedCode)}}get currentPreviewer(){var c;const y=(c=this.editorService.currentEditor)===null||c===void 0?void 0:c.currentUri;if(y)return this.activePreviewerMap.get(s.path.relative(this.appConfig.workspaceDir,y.path.toString()))}getUriCodeBlocks(c){const y=this.getSessionCodeBlocks(),b=s.path.relative(this.appConfig.workspaceDir,c.path.toString());return y.filter(A=>A.relativePath===b).sort((A,S)=>S.version-A.version)}getPendingPaths(c){return this.getSessionCodeBlocks(c).filter(b=>b.status==="pending").map(b=>b.relativePath)}getSessionCodeBlocks(c){const y=c?this.chatInternalService.getSession(c):this.chatInternalService.sessionModel;if(!y)throw new Error(`Session ${c} not found`);const b=y.history.sessionAdditionals;return Array.from(b.values()).map(A=>A.codeBlockMap||{}).reduce((A,S)=>(Object.values(S).forEach(D=>{A.push(D)}),A),[])}getCodeBlock(c,y){if(y=y||this.chatInternalService.sessionModel.history.lastMessageId,!y)throw new Error("Message ID is required");const b=this.getMessageCodeBlocks(y);if(b)return b[c]}updateCodeBlock(c){const y=c.messageId,b=this.getMessageCodeBlocks(y);if(!b)throw new Error("Code block not found");b[c.toolCallId]=c,this.chatInternalService.sessionModel.history.setMessageAdditional(y,{codeBlockMap:b}),this.onCodeBlockUpdateEmitter.fire(c)}async registerCodeBlock(c,y,b,A){var S,D;const T=this.chatInternalService.sessionModel.history.lastMessageId,w=this.getUriCodeBlocks(s.URI.file(s.path.join(this.appConfig.workspaceDir,c))),I=await this.editorDocumentModelService.createModelReference(s.URI.file(s.path.join(this.appConfig.workspaceDir,c))),R={codeEdit:y,relativePath:c,status:"generating",iterationCount:1,version:1,createdAt:Date.now(),toolCallId:b,messageId:T,instructions:A,originalCode:I.instance.getText()};if(w?.length){R.version=w.length+1;for(const O of w)if(O.relativePath===c&&(!((D=(S=O.applyResult)===null||S===void 0?void 0:S.diagnosticInfos)===null||D===void 0)&&D.length))R.iterationCount++;else break}const P=this.getMessageCodeBlocks(T)||{};return P[b]=R,this.chatInternalService.sessionModel.history.setMessageAdditional(T,{codeBlockMap:P}),this.onCodeBlockUpdateEmitter.fire(R),R}async apply(c){try{if(this.duringApply=!0,c.iterationCount>3)throw new Error("Lint error max iteration count exceeded");const y=c.originalCode?await this.doApply(c):{result:c.codeEdit};if(!y.stream&&!y.result)throw new Error("No apply content provided");this.activePreviewerMap.has(c.relativePath)&&(this.editorListenerMap.disposeKey(s.URI.file(s.path.join(this.appConfig.workspaceDir,c.relativePath)).toString()),this.activePreviewerMap.disposeKey(c.relativePath));const b=await this.editorService.open(s.URI.file(s.path.join(this.appConfig.workspaceDir,c.relativePath)));if(!b)throw new Error("Failed to open file");const A=await this.renderApplyResult(b.group.codeEditor.monacoEditor,c,y.result||y.stream,y.range);return c.updatedCode=A.updatedCode,c.status="pending",c.applyResult=A.result,this.updateCodeBlock(c),c}catch(y){throw c.status="failed",this.updateCodeBlock(c),y}finally{this.duringApply=!1}}async renderApplyResult(c,y,b,A){var S,D,T;const w=new s.Deferred,I=d.InlineDiffController.get(c);if(A=A||c.getModel().getFullModelRange(),typeof b=="string"){const R=b,P=c.getModel().getValue(),O=s.URI.file(s.path.join(this.appConfig.workspaceDir,y.relativePath)),M=this.editorDocumentModelService.getModelReference(O);(P!==R||M?.instance.dirty)&&((S=c.getModel())===null||S===void 0||S.pushEditOperations([],[g.EditOperation.replace(A,R)],()=>null),await this.editorService.save(O));const k=(D=this.getUriCodeBlocks(O))===null||D===void 0?void 0:D.filter(j=>j.status==="pending"),F=k?.[k.length-1];if(((T=F||y)===null||T===void 0?void 0:T.originalCode)===R)throw new Error("No changes applied");const L=I.createDiffPreviewer(c,_.Selection.fromRange(A,_.SelectionDirection.LTR),{disposeWhenEditorClosed:!0,renderRemovedWidgetImmediately:!0,reverse:!0});this.activePreviewerMap.set(y.relativePath,L),L.setValue(F?.originalCode||y.originalCode||`
31658
+ `).slice(0,f.startPosition.row).reduce((b,A)=>b+A.length,0);return y+=f.startPosition.row,y+=f.startPosition.column,{codeBlock:f.text,range:{start:{line:f.startPosition.row,character:0},end:{line:f.endPosition.row,character:1/0}},offset:y,type:f.startPosition.row===f.endPosition.row?p.NearestCodeBlockType.Line:p.NearestCodeBlockType.Block}}return null}dispose(){this.parser.delete(),this.lruCache.clear()}};t.LanguageParser=s,n.__decorate([(0,o.Autowired)(_.WasmModuleManager),n.__metadata("design:type",_.WasmModuleManager)],s.prototype,"wasmModuleManager",void 0),n.__decorate([(0,o.Autowired)(m.TreeSitterLanguageFacts),n.__metadata("design:type",m.TreeSitterLanguageFacts)],s.prototype,"languageFacts",void 0),t.LanguageParser=s=n.__decorate([(0,o.Injectable)({multiple:!0}),n.__metadata("design:paramtypes",[String])],s)},85679:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.LanguageParserService=void 0;const n=e(85608),r=e(76003),o=e(3073),a=e(22486);let p=class{constructor(){this.pool=new Map}createParser(m){const _=a.parserNameMap[m];if(_)return this.pool.has(_)||this.pool.set(_,this.injector.get(o.LanguageParser,[_])),this.pool.get(_)}dispose(){this.pool.forEach(m=>m.dispose()),this.pool.clear()}};t.LanguageParserService=p,n.__decorate([(0,r.Autowired)(r.INJECTOR_TOKEN),n.__metadata("design:type",r.Injector)],p.prototype,"injector",void 0),t.LanguageParserService=p=n.__decorate([(0,r.Injectable)()],p)},53374:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.toMonacoRange=e;function e(n){return{startLineNumber:n.startPosition.row+1,startColumn:n.startPosition.column+1,endLineNumber:n.endPosition.row+1,endColumn:n.endPosition.column+1}}},19584:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.GolangLanguageFacts=void 0;const e=["function_declaration","method_declaration","block","if_statement","else_statement","switch_statement","case_clause","for_statement","range_clause","type_switch_statement","type_case_clause","comm_clause","select_statement","go_statement","defer_statement"],n=new Set(e);class r{constructor(){this.name="go",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return n}isCodeBlock(a){return n.has(a)}}t.GolangLanguageFacts=r},22486:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TreeSitterLanguageFacts=t.knownLanguageFacts=void 0;const n=e(85608);n.__exportStar(e(17973),t);const r=e(76003),o=e(19584),a=e(44606),p=e(82381),v=e(41486),m=e(98588),_=e(96436),s=e(2349),g=e(78542),l=new Set;t.knownLanguageFacts=[o.GolangLanguageFacts,a.JavaLanguageFacts,p.JavaScriptLanguageFacts,v.JavaScriptReactLanguageFacts,m.PythonLanguageFacts,_.RustLanguageFacts,s.TypeScriptLanguageFacts,g.TypeScriptReactLanguageFacts];let h=class{constructor(){this.langs=new Map,t.knownLanguageFacts.forEach(d=>{const E=new d;this.langs.set(E.name,E)})}isCodeBlock(d,E){const f=this.langs.get(d);return f&&f.isCodeBlock?f.isCodeBlock(E):!1}isFunctionCodeBlock(d,E){const f=this.langs.get(d);return f&&f.isFunctionCodeBlocks?f.isFunctionCodeBlocks(E):!1}provideFunctionInfo(d,E){const f=this.langs.get(d);return f&&f.provideFunctionInfo?f.provideFunctionInfo(E):null}getCodeBlockTypes(d){const E=this.langs.get(d);return E?E.provideCodeBlocks():l}};t.TreeSitterLanguageFacts=h,t.TreeSitterLanguageFacts=h=n.__decorate([(0,r.Injectable)(),n.__metadata("design:paramtypes",[])],h)},44606:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.JavaLanguageFacts=void 0;const e=["compilation_unit","class_declaration","interface_declaration","enum_declaration","method_declaration","constructor_declaration","block","static_initializer","instance_initializer","if_statement","switch_statement","while_statement","do_statement","for_statement","enhanced_for_statement","try_statement","catch_clause","finally_clause"],n=new Set(["method_declaration","constructor_declaration"]),r=new Set(e);class o{constructor(){this.name="java",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return r}isCodeBlock(p){return r.has(p)}isFunctionCodeBlocks(p){return n.has(p)}}t.JavaLanguageFacts=o},82381:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.JavaScriptLanguageFacts=t.functionBlockCodeTypes=t.javascriptBlockCodeTypes=void 0;const n=e(53374);t.javascriptBlockCodeTypes=["function","function_declaration","function_expression","arrow_function","class_declaration","method_definition","if_statement","switch_case","while_statement","do_statement","for_statement","for_in_statement","try_statement","catch_clause","block","export_statement","lexical_declaration"],t.functionBlockCodeTypes=["function","function_declaration","function_expression","arrow_function","method_definition"];const r=new Set(t.functionBlockCodeTypes),o=new Set(t.javascriptBlockCodeTypes);class a{constructor(){this.name="javascript",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return o}isCodeBlock(v){return o.has(v)}isFunctionCodeBlocks(v){return r.has(v)}provideFunctionInfo(v){var m,_,s;switch(v.type){case"function_declaration":case"function_expression":return{infoCategory:"function",type:v.type,name:((m=v.firstNamedChild)===null||m===void 0?void 0:m.text)||"",signatures:v.children.filter(g=>g.type==="parameter").map(g=>{var l;return((l=g.firstChild)===null||l===void 0?void 0:l.text)||""}),range:(0,n.toMonacoRange)(v)};case"arrow_function":{const g=v.parent;return g&&g.type==="variable_declarator"&&g.parent&&(g.parent.type==="lexical_declaration"||g.parent.type==="export_statement"||g.parent.type==="variable_declaration")?{infoCategory:"function",type:v.type,name:((_=g.firstChild)===null||_===void 0?void 0:_.text)||"",signatures:v.children.filter(l=>l.type==="parameter").map(l=>{var h;return((h=l.firstChild)===null||h===void 0?void 0:h.text)||""}),range:(0,n.toMonacoRange)(g.parent)}:null}case"method_definition":return{infoCategory:"function",type:v.type,name:((s=v.firstNamedChild)===null||s===void 0?void 0:s.text)||"",signatures:v.children.filter(g=>g.type==="parameter").map(g=>{var l;return((l=g.firstChild)===null||l===void 0?void 0:l.text)||""}),range:(0,n.toMonacoRange)(v)}}return null}}t.JavaScriptLanguageFacts=a},41486:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.JavaScriptReactLanguageFacts=t.javascriptreactBlockCodeTypes=void 0;const n=e(82381);t.javascriptreactBlockCodeTypes=[...n.javascriptBlockCodeTypes,"jsx_element","jsx_self_closing_element","jsx_expression","jsx_fragment"];const r=new Set(t.javascriptreactBlockCodeTypes);class o{constructor(){this.name="jsx",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return r}isCodeBlock(p){return r.has(p)}}t.JavaScriptReactLanguageFacts=o},98588:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PythonLanguageFacts=t.pythonBlockCodeTypes=void 0,t.pythonBlockCodeTypes=["function_definition","class_definition","compound_statement","if_statement","elif_clause","else_clause","for_statement","while_statement","try_statement","except_clause","with_statement","decorated_definition"];const e=new Set(t.pythonBlockCodeTypes);class n{constructor(){this.name="python",this.listCommentStyle="# ",this.blockCommentStyle={start:"'''",end:"'''",linePrefix:""}}provideCodeBlocks(){return e}isCodeBlock(o){return e.has(o)}}t.PythonLanguageFacts=n},96436:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.RustLanguageFacts=t.rustBlockCodeTypes=void 0,t.rustBlockCodeTypes=["function_item","impl_item","trait_item","block","if_expression","match_expression","while_expression","loop_expression","for_expression","closure_expression","struct_item","enum_item","union_item","mod_item"];const e=new Set(t.rustBlockCodeTypes);class n{constructor(){this.name="rust",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return e}isCodeBlock(o){return e.has(o)}}t.RustLanguageFacts=n},17973:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parserIdentifierMap=t.parserNameMap=void 0;const r=e(85608).__importDefault(e(19891)),o={typescript:"typescript",typescriptreact:"tsx",javascript:"javascript",javascriptreact:"jsx",rust:"rust",python:"python",java:"java",go:"go"};t.parserNameMap=o,t.parserIdentifierMap=(0,r.default)(t.parserNameMap)},2349:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TypeScriptLanguageFacts=t.typescriptBlockTypes=void 0,t.typescriptBlockTypes=["function","function_declaration","function_expression","arrow_function","class_declaration","interface_declaration","method_definition","method_signature","enum_declaration","type_alias_declaration","lexical_declaration","if_statement","switch_case","while_statement","do_statement","for_statement","for_in_statement","for_of_statement","try_statement","catch_clause","block","module","public_field_definition","private_field_definition","export_statement"];const e=new Set(t.typescriptBlockTypes);class n{constructor(){this.name="typescript",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return e}isCodeBlock(o){return e.has(o)}}t.TypeScriptLanguageFacts=n},78542:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TypeScriptReactLanguageFacts=t.typescriptreactBlockTypes=void 0;const n=e(2349);t.typescriptreactBlockTypes=[...n.typescriptBlockTypes,"jsx_element","jsx_self_closing_element","jsx_expression","jsx_fragment"];const r=new Set(t.typescriptreactBlockTypes);class o{constructor(){this.name="tsx",this.listCommentStyle="// ",this.blockCommentStyle={start:"/**",end:" */",linePrefix:" * "}}provideCodeBlocks(){return r}isCodeBlock(p){return r.has(p)}}t.TypeScriptReactLanguageFacts=o},67045:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WasmModuleManager=void 0;const n=e(85608),r=n.__importDefault(e(13833)),o=e(76003),a=e(6858),p=e(70392);let v=class{async resolveResourceUri(){const _=await this.rendererRuntime.provideResourceUri(a.EKnownResources.TreeSitterWasmDirectory);this.resolvedResourceUriDeferred.resolve(_)}constructor(){this.resolvedResourceUriDeferred=new p.Deferred,this.cachedRuntime=new Map,this.parserInitialized=!1,this.resolveResourceUri()}async initParser(){const _=await this.resolvedResourceUriDeferred.promise;let s;return _.endsWith("/")?s=`${_}tree-sitter.wasm`:s=`${_}/tree-sitter.wasm`,this.parserInitialized||(await r.default.init({locateFile:()=>s}),this.parserInitialized=!0),new r.default}async loadLanguage(_){if(!this.cachedRuntime.has(_)){const s=new p.Deferred;this.cachedRuntime.set(_,s);const g=await this.resolvedResourceUriDeferred.promise;let l;g.endsWith("/")?l=`${g}tree-sitter-${_}.wasm`:l=`${g}/tree-sitter-${_}.wasm`,fetch(l).then(h=>h.arrayBuffer()).then(h=>{s.resolve(h)})}return this.cachedRuntime.get(_).promise}};t.WasmModuleManager=v,n.__decorate([(0,o.Autowired)(a.RendererRuntime),n.__metadata("design:type",a.RendererRuntime)],v.prototype,"rendererRuntime",void 0),t.WasmModuleManager=v=n.__decorate([(0,o.Injectable)(),n.__metadata("design:paramtypes",[])],v)},4972:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AIRightTabRenderer=t.AILeftTabRenderer=t.AIChatTabRendererWithTab=t.AIChatTabRenderer=void 0;const n=e(85608),r=n.__importDefault(e(53373)),o=n.__importStar(e(14041)),a=e(41869),p=e(89195),v=e(1149),m=e(43718),_=e(11090),s=e(63067),g=e(46245),l=e(66368),h=e(19951),u=e(752),d=e(19413),E=n.__importDefault(e(87708)),f=()=>{const{side:D}=o.default.useContext(h.TabbarConfig),T=(0,a.useInjectable)(u.TabbarServiceFactory)(D);return(0,o.useEffect)(()=>{T.setIsLatter(!0)},[T]),o.default.createElement("div",{style:{width:0}},o.default.createElement(g.TabbarViewBase,{tabSize:0,MoreTabView:g.IconElipses,TabView:g.IconTabView,barSize:0,panelBorderSize:1}))},c=({className:D,components:T})=>o.default.createElement(h.TabRendererBase,{side:d.AI_CHAT_VIEW_ID,direction:"left-to-right",id:E.default.ai_chat_panel,className:(0,r.default)(D,`${d.AI_CHAT_VIEW_ID}-slot`),components:T,TabbarView:()=>o.default.createElement(f,null),TabpanelView:()=>o.default.createElement(l.BaseTabPanelView,{PanelView:l.ContainerView,PanelViewProps:{className:E.default.ai_chat_view_container}})});t.AIChatTabRenderer=c;const y=({className:D,components:T})=>o.default.createElement(h.TabRendererBase,{side:d.AI_CHAT_VIEW_ID,direction:"right-to-left",id:E.default.ai_chat_panel,className:(0,r.default)(D,`${d.AI_CHAT_VIEW_ID}-slot`,"design_right_slot"),components:T,TabbarView:()=>o.default.createElement(g.ChatTabbarRenderer2,null),TabpanelView:()=>o.default.createElement(l.BaseTabPanelView,{PanelView:l.ContainerView,PanelViewProps:{className:E.default.ai_chat_view_container}})});t.AIChatTabRendererWithTab=y;const b=({className:D,components:T})=>o.default.createElement(_.DesignLeftTabRenderer,{className:D,components:T,tabbarView:A});t.AILeftTabRenderer=b;const A=()=>{const D=(0,a.useInjectable)(s.IMainLayoutService),T=(0,a.useInjectable)(u.TabbarServiceFactory)(a.SlotLocation.right),w=(0,a.useAutorun)(T.currentContainerId),I=o.default.useMemo(()=>D.getExtraMenu(),[D]),[R]=(0,a.useContextMenus)(I),P=(0,o.useCallback)(({renderContainers:O})=>{const M=T.visibleContainers.filter(k=>{var F;return!(!((F=k.options)===null||F===void 0)&&F.hideTab)});return o.default.createElement(o.default.Fragment,null,M.length>0&&o.default.createElement(p.HorizontalVertical,{margin:"8px auto 0px",width:"60%"}),M.map(k=>O(k,T,w)))},[w,T]);return o.default.createElement(g.LeftTabbarRenderer,{renderOtherVisibleContainers:P,isRenderExtraTopMenus:!1,renderExtraMenus:o.default.createElement("div",{className:E.default.extra_bottom_icon_container},R.length>=0?R.map(O=>o.default.createElement(p.EnhanceIconWithCtxMenu,{key:O.id,id:O.id,wrapperClassName:E.default.extra_bottom_icon,iconClass:O.icon,menuNodes:O.children,skew:{x:-8,y:-4}})):null)})},S=({className:D,components:T})=>{const w=(0,a.useInjectable)(u.TabbarServiceFactory)(a.SlotLocation.right),I=(0,a.useInjectable)(v.DesignLayoutConfig),R=(0,o.useCallback)(()=>{w.updateCurrentContainerId("")},[]),P=(0,o.useCallback)(M=>{const{component:k}=M,{options:F}=k;return o.default.createElement(l.ContainerView,{...M,customTitleBar:o.default.createElement("div",{className:E.default.header},o.default.createElement("span",{className:E.default.title},F&&F.title),o.default.createElement("div",{className:E.default.side},o.default.createElement(p.EnhancePopover,{id:"ai_right_panel_header_close",title:(0,m.localize)("editor.title.context.close")},o.default.createElement(p.EnhanceIcon,{icon:"close",onClick:R})))),renderContainerWrap:({children:L})=>o.default.createElement("div",{className:E.default.right_slot_container_wrap},o.default.createElement("div",{className:E.default.container},L))})},[]),O=(0,o.useMemo)(()=>I.useMergeRightWithLeftPanel?E.default.right_tab_renderer:"",[I]);return o.default.createElement(_.DesignRightTabRenderer,{components:T,className:O,tabbarView:()=>o.default.createElement(g.RightTabbarRenderer,{barSize:0,style:{width:0}}),tabpanelView:()=>o.default.createElement(l.BaseTabPanelView,{PanelView:P})})};t.AIRightTabRenderer=S},82983:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AIChatLogoAvatar=void 0;const n=e(85608),r=n.__importDefault(e(14041)),o=e(41869),a=e(89195),p=e(63067),v=e(19413),m=n.__importDefault(e(88473)),_=()=>{const s=(0,o.useInjectable)(p.IMainLayoutService),g=r.default.useCallback(()=>{s.toggleSlot(v.AI_CHAT_VIEW_ID)},[s]);return r.default.createElement("div",{className:m.default.ai_switch,onClick:g},r.default.createElement(a.AILogoAvatar,{iconClassName:m.default.avatar_icon_large}))};t.AIChatLogoAvatar=_},73974:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.BaseApplyService=void 0;const n=e(85608),r=e(41429),o=e(76003),a=e(41869),p=e(54414),v=e(57517),m=e(55126),_=e(20868),s=e(70392),g=e(2261),l=e(19413),h=e(59347),u=e(40111),d=e(15989);class E extends a.WithEventBus{constructor(){super(),this.onCodeBlockUpdateEmitter=new s.Emitter,this.onCodeBlockUpdate=this.onCodeBlockUpdateEmitter.event,this.activePreviewerMap=this.registerDispose(new s.DisposableMap),this.editorListenerMap=this.registerDispose(new s.DisposableMap),this.addDispose(this.chatInternalService.onCancelRequest(()=>{const c=this.chatInternalService.sessionModel.history.lastMessageId;if(!c)return;const y=this.getMessageCodeBlocks(c);y&&Object.values(y).forEach(b=>{this.cancelApply(b)})})),this.currentSessionId=this.chatInternalService.sessionModel.sessionId,this.addDispose(this.chatInternalService.onChangeSession(c=>{c!==this.currentSessionId&&(this.cancelAllApply(),this.currentSessionId=c)})),this.addDispose(this.chatInternalService.onRegenerateRequest(()=>{const c=this.chatInternalService.sessionModel.history.getMessages(),y=c[c.length-1].id,b=this.getMessageCodeBlocks(y);b&&Object.values(b).forEach(A=>{this.cancelApply(A)})})),this.addDispose(this.chatInternalService.onWillClearSession(c=>{this.cancelAllApply(c)}))}getMessageCodeBlocks(c,y){y=y||this.chatInternalService.sessionModel.sessionId;const b=this.chatInternalService.getSession(y);if(!b)throw new Error(`Session ${y} not found`);const A=b.history.getMessageAdditional(c);return A?.codeBlockMap}onEditorGroupClose(c){const y=s.path.relative(this.appConfig.workspaceDir,c.payload.resource.uri.path.toString());this.activePreviewerMap.get(y)&&this.activePreviewerMap.disposeKey(y),this.editorListenerMap.disposeKey(c.payload.resource.uri.toString())}async onEditorGroupOpen(c){var y;const b=s.path.relative(this.appConfig.workspaceDir,c.payload.resource.uri.path.toString());if(this.duringApply||this.activePreviewerMap.has(b)||!this.chatInternalService.sessionModel.history.getMessages().length)return;const A=((y=this.getUriCodeBlocks(c.payload.resource.uri))===null||y===void 0?void 0:y.filter(S=>S.status==="pending"))||[];if(A.length>0&&A[0].updatedCode){const S=c.payload.group.codeEditor.monacoEditor;await this.renderApplyResult(S,A[0],A[0].updatedCode)}}get currentPreviewer(){var c;const y=(c=this.editorService.currentEditor)===null||c===void 0?void 0:c.currentUri;if(y)return this.activePreviewerMap.get(s.path.relative(this.appConfig.workspaceDir,y.path.toString()))}getUriCodeBlocks(c){const y=this.getSessionCodeBlocks(),b=s.path.relative(this.appConfig.workspaceDir,c.path.toString());return y.filter(A=>A.relativePath===b).sort((A,S)=>S.version-A.version)}getPendingPaths(c){return this.getSessionCodeBlocks(c).filter(b=>b.status==="pending").map(b=>b.relativePath)}getSessionCodeBlocks(c){const y=c?this.chatInternalService.getSession(c):this.chatInternalService.sessionModel;if(!y)throw new Error(`Session ${c} not found`);const b=y.history.sessionAdditionals;return Array.from(b.values()).map(A=>A.codeBlockMap||{}).reduce((A,S)=>(Object.values(S).forEach(D=>{A.push(D)}),A),[])}getCodeBlock(c,y){if(y=y||this.chatInternalService.sessionModel.history.lastMessageId,!y)throw new Error("Message ID is required");const b=this.getMessageCodeBlocks(y);if(b)return b[c]}updateCodeBlock(c){const y=c.messageId,b=this.getMessageCodeBlocks(y);if(!b)throw new Error("Code block not found");b[c.toolCallId]=c,this.chatInternalService.sessionModel.history.setMessageAdditional(y,{codeBlockMap:b}),this.onCodeBlockUpdateEmitter.fire(c)}async registerCodeBlock(c,y,b,A){var S,D;const T=this.chatInternalService.sessionModel.history.lastMessageId,w=this.getUriCodeBlocks(s.URI.file(s.path.join(this.appConfig.workspaceDir,c))),I=await this.editorDocumentModelService.createModelReference(s.URI.file(s.path.join(this.appConfig.workspaceDir,c))),R={codeEdit:y,relativePath:c,status:"generating",iterationCount:1,version:1,createdAt:Date.now(),toolCallId:b,messageId:T,instructions:A,originalCode:I.instance.getText()};if(w?.length){R.version=w.length+1;for(const O of w)if(O.relativePath===c&&(!((D=(S=O.applyResult)===null||S===void 0?void 0:S.diagnosticInfos)===null||D===void 0)&&D.length))R.iterationCount++;else break}const P=this.getMessageCodeBlocks(T)||{};return P[b]=R,this.chatInternalService.sessionModel.history.setMessageAdditional(T,{codeBlockMap:P}),this.onCodeBlockUpdateEmitter.fire(R),R}async apply(c){try{if(this.duringApply=!0,c.iterationCount>3)throw new Error("Lint error max iteration count exceeded");const y=c.originalCode?await this.doApply(c):{result:c.codeEdit};if(!y.stream&&!y.result)return c.status="cancelled",this.updateCodeBlock(c),c;this.activePreviewerMap.has(c.relativePath)&&(this.editorListenerMap.disposeKey(s.URI.file(s.path.join(this.appConfig.workspaceDir,c.relativePath)).toString()),this.activePreviewerMap.disposeKey(c.relativePath));const b=await this.editorService.open(s.URI.file(s.path.join(this.appConfig.workspaceDir,c.relativePath)));if(!b)throw new Error("Failed to open file");const A=await this.renderApplyResult(b.group.codeEditor.monacoEditor,c,y.result||y.stream,y.range);return c.updatedCode=A.updatedCode,c.status="pending",c.applyResult=A.result,this.updateCodeBlock(c),c}catch(y){throw c.status="failed",this.updateCodeBlock(c),y}finally{this.duringApply=!1}}async renderApplyResult(c,y,b,A){var S,D,T;const w=new s.Deferred,I=d.InlineDiffController.get(c);if(A=A||c.getModel().getFullModelRange(),typeof b=="string"){const R=b,P=c.getModel().getValue(),O=s.URI.file(s.path.join(this.appConfig.workspaceDir,y.relativePath)),M=this.editorDocumentModelService.getModelReference(O);(P!==R||M?.instance.dirty)&&((S=c.getModel())===null||S===void 0||S.pushEditOperations([],[g.EditOperation.replace(A,R)],()=>null),await this.editorService.save(O));const k=(D=this.getUriCodeBlocks(O))===null||D===void 0?void 0:D.filter(j=>j.status==="pending"),F=k?.[k.length-1];if(((T=F||y)===null||T===void 0?void 0:T.originalCode)===R)throw new Error("No changes applied");const L=I.createDiffPreviewer(c,_.Selection.fromRange(A,_.SelectionDirection.LTR),{disposeWhenEditorClosed:!0,renderRemovedWidgetImmediately:!0,reverse:!0});this.activePreviewerMap.set(y.relativePath,L),L.setValue(F?.originalCode||y.originalCode||`
31659
31659
  `),this.eventBus.fire(new v.RegisterEditorSideComponentEvent),this.listenPartialEdit(c.getModel(),y).then(j=>{j&&(y.applyResult=j),this.updateCodeBlock(y),this.editorService.save(s.URI.file(s.path.join(this.appConfig.workspaceDir,y.relativePath)))});const{diff:B,rangesFromDiffHunk:U}=this.getDiffResult(y.originalCode,R,y.relativePath),W=this.getDiagnosticInfos(c.getModel().uri.toString(),U);w.resolve({result:{diff:B,diagnosticInfos:W},updatedCode:R})}else{const R=new u.InlineChatController;R.mountReadable(b);const P=I.showPreviewerByStream(c,{crossSelection:_.Selection.fromRange(A,_.SelectionDirection.LTR),chatResponse:R,previewerOptions:{disposeWhenEditorClosed:!0,renderRemovedWidgetImmediately:!1}});this.addDispose(R.onError(O=>{w.reject(O)})),this.addDispose(R.onAbort(()=>{w.reject(new Error("Apply aborted"))})),this.addDispose(P.getNode().onDiffFinished(async O=>{const M=O.newFullRangeTextLines.join(`
31660
31660
  `);if(y.originalCode===M){P.dispose(),w.reject(new Error("no changes applied"));return}P.dispose();try{const k=await this.renderApplyResult(c,y,M);w.resolve(k)}catch(k){w.reject(k)}})),this.activePreviewerMap.set(y.relativePath,P)}return w.promise}cancelApply(c,y){var b,A;(c.status==="generating"||c.status==="pending")&&(this.editorListenerMap.disposeKey(s.URI.file(s.path.join(this.appConfig.workspaceDir,c.relativePath)).toString()),this.activePreviewerMap.has(c.relativePath)&&((A=(b=this.activePreviewerMap.get(c.relativePath))===null||b===void 0?void 0:b.getNode())===null||A===void 0||A.livePreviewDiffDecorationModel.discardUnProcessed(),this.activePreviewerMap.disposeKey(c.relativePath)),c.status="cancelled",this.updateCodeBlock(c))}cancelAllApply(c){this.getSessionCodeBlocks(c).forEach(b=>{this.cancelApply(b)})}revealApplyPosition(c){var y;const b=(y=c.applyResult)===null||y===void 0?void 0:y.diff.split(`
31661
31661
  `).find(T=>T.startsWith("@@"));let A=0,S=0;if(b){const[,,,T,w]=b.match(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);A=parseInt(T,10)-1,S=parseInt(w,10)-1}this.editorService.open(s.URI.file(s.path.join(this.appConfig.workspaceDir,c.relativePath)));const D=this.editorService.currentEditor;D&&D.setSelection(new _.Selection(A,0,S,0))}async processAll(c,y){var b;const A=y?(b=this.getUriCodeBlocks(y))===null||b===void 0?void 0:b.filter(w=>w.status==="pending"):this.getSessionCodeBlocks().filter(w=>w.status==="pending");if(!A?.length)throw new Error("No pending code block found");const S=y?[A[0].relativePath]:A.map(w=>w.relativePath).reduce((w,I)=>(w.includes(I)||w.push(I),w),[]),D=this.editorService.getAllOpenedUris(),T=S.filter(w=>!D.some(I=>I.codeUri.fsPath.endsWith(w))).map(w=>s.URI.file(s.path.join(this.appConfig.workspaceDir,w)));T.length&&await this.editorService.openUris(T),S.forEach(w=>{this.doProcess(c,w)}),A.forEach(w=>{w.status=c==="accept"?"success":"cancelled",this.updateCodeBlock(w)})}doProcess(c,y){var b,A;const S=(A=(b=this.activePreviewerMap.get(y))===null||b===void 0?void 0:b.getNode())===null||A===void 0?void 0:A.livePreviewDiffDecorationModel;if(!S)throw new Error("No active previewer found");c==="accept"?S.acceptUnProcessed():S.discardUnProcessed(),this.editorService.save(s.URI.file(s.path.join(this.appConfig.workspaceDir,y)))}listenPartialEdit(c,y){const b=new s.Deferred,A=c.uri.toString(),S=this.inlineDiffService.onPartialEdit(D=>{if(D.totalPartialEditCount===D.resolvedPartialEditCount&&D.uri.path===c.uri.path.toString()){if(D.acceptPartialEditCount>0){y.status="success";const T=c.getValue(),{diff:w,rangesFromDiffHunk:I}=this.getDiffResult(y.originalCode,T,y.relativePath),R=this.getDiagnosticInfos(c.uri.toString(),I);this.aiReporter.send({msgType:a.AIServiceType.Chat,actionType:a.ActionTypeEnum.Accept,actionSource:a.ActionSourceEnum.Chat,sessionId:this.chatInternalService.sessionModel.sessionId,isReceive:!0,isDrop:D.acceptPartialEditCount!==D.totalPartialEditCount,code:T,originCode:y.originalCode,message:JSON.stringify({diff:w,diagnosticInfos:R,instructions:y.instructions,codeEdit:y.codeEdit,partialEditCount:D.totalPartialEditCount,acceptPartialEditCount:D.acceptPartialEditCount,addedLinesCount:D.totalAddedLinesCount,deletedLinesCount:D.totalDeletedLinesCount})}),b.resolve({diff:w,diagnosticInfos:R})}else y.status="cancelled",b.resolve(),this.aiReporter.send({msgType:a.AIServiceType.Chat,actionType:a.ActionTypeEnum.Discard,actionSource:a.ActionSourceEnum.Chat,sessionId:this.chatInternalService.sessionModel.sessionId,isReceive:!1,isDrop:!0,originCode:y.originalCode,message:JSON.stringify({instructions:y.instructions,codeEdit:y.codeEdit})});this.editorListenerMap.disposeKey(A)}});return this.editorListenerMap.set(A,S),b.promise}getDiffResult(c,y,b){const A=(0,r.createPatch)(b,c,y).split(`
@@ -31664,11 +31664,11 @@ ${f.slice(1).join(`
31664
31664
  `).map(D=>{if(D.startsWith("@@")){const[,,,T,w]=D.match(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);return new _.Range(parseInt(T,10),0,parseInt(T,10)+parseInt(w,10)-1,0)}return null}).filter(D=>D!==null);return{diff:A,rangesFromDiffHunk:S}}getDiagnosticInfos(c,y){return this.markerService.getManager().getMarkers({resource:c}).filter(A=>A.severity>=a.MarkerSeverity.Warning&&y.some(S=>S.containsPosition(new _.Position(A.startLineNumber,A.startColumn))))}}t.BaseApplyService=E,E.CHAT_EDITING_SOURCE_RESOLVER_SCHEME="chat-editing-source",n.__decorate([(0,o.Autowired)(l.IChatInternalService),n.__metadata("design:type",h.ChatInternalService)],E.prototype,"chatInternalService",void 0),n.__decorate([(0,o.Autowired)(a.AppConfig),n.__metadata("design:type",Object)],E.prototype,"appConfig",void 0),n.__decorate([(0,o.Autowired)(p.WorkbenchEditorService),n.__metadata("design:type",p.WorkbenchEditorService)],E.prototype,"editorService",void 0),n.__decorate([(0,o.Autowired)(l.InlineDiffServiceToken),n.__metadata("design:type",Object)],E.prototype,"inlineDiffService",void 0),n.__decorate([(0,o.Autowired)(m.IMarkerService),n.__metadata("design:type",Object)],E.prototype,"markerService",void 0),n.__decorate([(0,o.Autowired)(v.IEditorDocumentModelService),n.__metadata("design:type",Object)],E.prototype,"editorDocumentModelService",void 0),n.__decorate([(0,o.Autowired)(a.IAIReporter),n.__metadata("design:type",Object)],E.prototype,"aiReporter",void 0),n.__decorate([(0,a.OnEvent)(v.EditorGroupCloseEvent),n.__metadata("design:type",Function),n.__metadata("design:paramtypes",[v.EditorGroupCloseEvent]),n.__metadata("design:returntype",void 0)],E.prototype,"onEditorGroupClose",null),n.__decorate([(0,a.OnEvent)(v.EditorGroupOpenEvent),n.__metadata("design:type",Function),n.__metadata("design:paramtypes",[v.EditorGroupOpenEvent]),n.__metadata("design:returntype",Promise)],E.prototype,"onEditorGroupOpen",null)},75279:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPConfigView=void 0;const n=e(85608),r=n.__importDefault(e(53373)),o=n.__importStar(e(14041)),a=e(97267),p=e(41869),v=e(43718),m=e(19413),_=n.__importDefault(e(76599)),s=e(51750),g=()=>{const l=(0,p.useInjectable)(v.MCPConfigServiceToken),[h,u]=o.default.useState([]),[d,E]=o.default.useState(!1),[f,c]=o.default.useState(),[y,b]=o.default.useState(),[A,S]=o.default.useState(l.isInitialized),D=(0,o.useCallback)(async()=>{const M=await l.getServers();u(M)},[l]);o.default.useEffect(()=>{D();const M=l.onMCPServersChange(k=>{k&&S(!0),D()});return()=>{M.dispose()}},[D]);const T=(0,o.useCallback)(async(M,k)=>{try{b(M),await l.controlServer(M,k),await D(),b(void 0)}catch{b(void 0)}},[l,D]),w=(0,o.useCallback)(()=>{c(void 0),E(!0)},[]),I=(0,o.useCallback)(async M=>{const k=await l.getServerConfigByName(M.name);k&&(c(k),E(!0))},[l]),R=(0,o.useCallback)(async M=>{await l.deleteServer(M),await D()},[l,D]),P=(0,o.useCallback)(async(M,k)=>{E(!1),await l.saveServer(M,k),M?.enabled&&(b(k.name),await l.controlServer(k.name,!0),b(void 0)),await D()},[l,D]),O=(0,o.useCallback)(async M=>{b(M.name),await l.syncServer(M.name),await D(),b(void 0)},[l,D]);return o.default.createElement("div",{className:_.default.container},o.default.createElement("div",{className:_.default.header},o.default.createElement("div",null,o.default.createElement("h2",{className:_.default.title},"MCP Servers"),o.default.createElement("p",{className:_.default.description},(0,v.localize)("ai.native.mcp.manage.connections"))),o.default.createElement("button",{className:_.default.actionButton,onClick:w},o.default.createElement(a.Icon,{icon:"plus",className:_.default.actionButtonIcon}),(0,v.localize)("ai.native.mcp.addMCPServer.title"))),o.default.createElement("div",{className:_.default.serversList},h.map(M=>o.default.createElement("div",{key:M.name,className:_.default.serverItem},o.default.createElement("div",{className:_.default.serverHeader},o.default.createElement("div",{className:_.default.serverTitleRow},o.default.createElement("h3",{className:_.default.serverName},M.name,o.default.createElement("span",{className:(0,r.default)(_.default.serverStatusIcon,M.isStarted?_.default.active:_.default.inactive)}))),o.default.createElement("div",{className:_.default.serverActions},o.default.createElement(a.Popover,{id:"mcp-server-action-popover",trigger:a.PopoverTriggerType.hover,content:M.isStarted?(0,v.localize)("ai.native.mcp.disable.title"):(0,v.localize)("ai.native.mcp.enable.title")},o.default.createElement(a.Button,{type:"default",className:(0,r.default)(_.default.serverActionButton,M.isStarted&&_.default.active),onClick:()=>T(M.name,!M.isStarted)},o.default.createElement("i",{className:`codicon ${y===M.name||!A&&M.name!==m.BUILTIN_MCP_SERVER_NAME&&!M.isStarted?"codicon-loading kt-icon-loading":M.isStarted?"codicon-check":"codicon-circle"}`}),o.default.createElement("span",null,(0,v.localize)(M.isStarted?"ai.native.mcp.enabled":"ai.native.mcp.disabled")))),M.name!==m.BUILTIN_MCP_SERVER_NAME&&o.default.createElement(a.Button,{type:"icon",iconClass:"codicon codicon-edit",className:_.default.iconButton,title:(0,v.localize)("ai.native.mcp.tool.action.edit"),onClick:()=>I(M)}),M.name!==m.BUILTIN_MCP_SERVER_NAME&&o.default.createElement(a.Button,{type:"icon",iconClass:"codicon codicon-sync",className:_.default.iconButton,title:(0,v.localize)("ai.native.mcp.tool.action.sync"),onClick:()=>O(M)}),M.name!==m.BUILTIN_MCP_SERVER_NAME&&o.default.createElement(a.Button,{type:"icon",iconClass:"codicon codicon-trash",className:_.default.iconButton,title:(0,v.localize)("ai.native.mcp.tool.action.delete"),onClick:()=>R(M.name)}))),o.default.createElement("div",{className:_.default.serverDetail},M.type&&o.default.createElement("div",{className:_.default.detailRow},o.default.createElement("span",{className:_.default.detailLabel},"Type:"),o.default.createElement(a.Badge,{className:(0,r.default)(_.default.serverType,_.default.typeTag)},l.getReadableServerType(M.type)))),M.tools&&M.tools.length>0&&o.default.createElement("div",{className:_.default.serverDetail},o.default.createElement("div",{className:_.default.detailRow},o.default.createElement("span",{className:_.default.detailLabel},"Tools:"),o.default.createElement("span",{className:_.default.detailContent},M.tools.map((k,F)=>o.default.createElement(a.Badge,{key:F,className:_.default.toolTag,title:k.description},k.name))))),M.command&&o.default.createElement("div",{className:_.default.serverDetail},o.default.createElement("div",{className:_.default.detailRow},o.default.createElement("span",{className:_.default.detailLabel},"Command:"),o.default.createElement("span",{className:_.default.detailContent},M.command))),M.url&&o.default.createElement("div",{className:_.default.serverDetail},o.default.createElement("div",{className:_.default.detailRow},o.default.createElement("span",{className:_.default.detailLabel},"Server Link:"),o.default.createElement("span",{className:(0,r.default)(_.default.detailContent,_.default.link)},M.url)))))),o.default.createElement(s.MCPServerForm,{visible:d,initialData:f,servers:h,onSave:M=>P(f,M),onCancel:()=>E(!1)}))};t.MCPConfigView=g},51750:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPServerForm=void 0;const n=e(85608),r=n.__importDefault(e(53373)),o=n.__importStar(e(14041)),a=e(97267),p=e(48412),v=e(53017),m=e(41869),_=e(43718),s=e(72665),g=e(69820),l=n.__importDefault(e(83761)),h=({visible:u,initialData:d,onSave:E,onCancel:f,servers:c})=>{const[y,b]=(0,o.useState)(()=>({name:"",command:"",args:[],env:{},type:g.MCP_SERVER_TYPE.STDIO,...d})),A=(0,m.useInjectable)(s.IMessageService),[S,D]=(0,o.useState)(()=>{var B;return((B=d?.args)===null||B===void 0?void 0:B.join(" "))||""}),[T,w]=(0,o.useState)(()=>d?.env?Object.entries(d.env).map(([B,U])=>`${B}=${U}`).join(`
31665
31665
  `):"");(0,o.useEffect)(()=>{var B;b({name:"",command:"",args:[],env:{},type:g.MCP_SERVER_TYPE.STDIO,...d}),D(((B=d?.args)===null||B===void 0?void 0:B.join(" "))||""),w(d?.env?Object.entries(d.env).map(([U,W])=>`${U}=${W}`).join(`
31666
31666
  `):"")},[d]);const I=(0,o.useCallback)(B=>{var U,W;if(B.name.trim()==="")return A.error((0,_.localize)("ai.native.mcp.name.isRequired")),!1;if(!d&&c.some(Q=>Q.name.toLocaleLowerCase()===B.name.toLocaleLowerCase()))return A.error((0,_.formatLocalize)("ai.native.mcp.serverNameExists",B.name)),!1;if(B.type===g.MCP_SERVER_TYPE.SSE){const Q=((U=B.url)===null||U===void 0?void 0:U.trim())!=="";return Q||A.error((0,_.localize)("ai.native.mcp.url.isRequired")),Q}const j=((W=B.command)===null||W===void 0?void 0:W.trim())!=="";return j||A.error((0,_.localize)("ai.native.mcp.command.isRequired")),j},[c,d]),R=(0,o.useCallback)(B=>{var U;if(B.preventDefault(),!I(y))return;const j={...y};if(y.type===g.MCP_SERVER_TYPE.SSE)j.url=(U=j.url)===null||U===void 0?void 0:U.trim();else{const Q=S.split(" ").filter(Boolean),G=T.split(`
31667
- `).filter(Boolean).reduce((Z,$)=>{const[V,H]=$.split("=");return V&&H&&(Z[V.trim()]=H.trim()),Z},{});j.args=Q,j.env=G}b({...y,name:"",command:"",url:"",args:[],env:{}}),E(j)},[y,S,T,E,I]),P=(0,o.useCallback)(B=>{b({...y,command:B.target.value})},[y,S]),O=(0,o.useCallback)(B=>{D(B.target.value)},[S]),M=(0,o.useCallback)(B=>{w(B.target.value)},[T]),k=(0,o.useCallback)(B=>{b({...y,url:B.target.value})},[y]),F=(0,o.useCallback)(B=>{b({...y,type:B,command:"",args:[],env:{},url:""})},[y]),L=(0,o.useCallback)(()=>y?.type===g.MCP_SERVER_TYPE.STDIO?o.default.createElement(o.default.Fragment,null,o.default.createElement("div",{className:l.default.formItem},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.command")),o.default.createElement("input",{type:"text",value:y.command,onChange:P,placeholder:(0,_.localize)("ai.native.mcp.command.placeHolder"),required:!0})),o.default.createElement("div",{className:l.default.formItem},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.args")),o.default.createElement("textarea",{value:S,onChange:O,placeholder:(0,_.localize)("ai.native.mcp.args.placeHolder"),rows:3})),o.default.createElement("div",{className:l.default.formItem},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.env")),o.default.createElement("textarea",{value:T,onChange:M,placeholder:(0,_.localize)("ai.native.mcp.env.placeHolder"),rows:3}))):o.default.createElement(o.default.Fragment,null,o.default.createElement("div",{className:l.default.formItem},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.url")),o.default.createElement("textarea",{value:y.url,onChange:k,placeholder:(0,_.localize)("ai.native.mcp.url.placeHolder"),rows:3}))),[y,S,T]);return o.default.createElement(v.Modal,{title:d?(0,_.localize)("ai.native.mcp.editMCPServer.title"):(0,_.localize)("ai.native.mcp.addMCPServer.title"),visible:u,onCancel:f,centered:!0,width:600,footer:null,style:{background:"var(--editor-background)"}},o.default.createElement("form",{className:l.default.form,onSubmit:B=>B.preventDefault()},o.default.createElement("div",{className:l.default.formRow},o.default.createElement("div",{className:(0,r.default)(l.default.formItem,l.default.formItemName)},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.name")),o.default.createElement("input",{type:"text",value:y.name,onChange:B=>b({...y,name:B.target.value}),placeholder:(0,_.localize)("ai.native.mcp.name.placeHolder"),required:!0})),o.default.createElement("div",{className:(0,r.default)(l.default.formItem,l.default.formItemType)},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.type")),o.default.createElement(a.Select,{size:"large",value:y.type,options:[{label:(0,_.localize)("ai.native.mcp.stdio"),value:g.MCP_SERVER_TYPE.STDIO},{label:(0,_.localize)("ai.native.mcp.sse"),value:g.MCP_SERVER_TYPE.SSE}],className:l.default.formItemSelect,onChange:F}))),L(),o.default.createElement("div",{className:l.default.formActions},o.default.createElement(p.Button,{onClick:f,type:"primary",className:l.default.secondaryButton},(0,_.localize)("ai.native.mcp.buttonCancel")),o.default.createElement(p.Button,{onClick:R,type:"primary"},d?(0,_.localize)("ai.native.mcp.buttonUpdate"):(0,_.localize)("ai.native.mcp.buttonSave")))))};t.MCPServerForm=h},27397:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPConfigCommandContribution=t.MCPConfigCommands=void 0;const n=e(85608),r=e(76003),o=e(41869),a=e(43718),p=e(54414),v=e(5297),m=e(33108);var _;(function(g){g.OPEN_MCP_CONFIG={id:"mcp.openConfig",label:"Open MCP Configuration"},g.OPEN_MCP_CONFIG_FILE={id:"mcp.openConfigFile",label:"Open MCP Configuration (JSON)"}})(_||(t.MCPConfigCommands=_={}));let s=class{registerCommands(l){l.registerCommand(_.OPEN_MCP_CONFIG,{execute:()=>{const h=new o.URI().withScheme(v.MCP_CONFIG_COMPONENTS_SCHEME_ID);this.editorService.open(h,{preview:!1,focus:!0})}}),l.registerCommand(_.OPEN_MCP_CONFIG_FILE,{execute:()=>{this.mcpConfigService.openConfigFile()}})}};t.MCPConfigCommandContribution=s,n.__decorate([(0,r.Autowired)(p.WorkbenchEditorService),n.__metadata("design:type",p.WorkbenchEditorService)],s.prototype,"editorService",void 0),n.__decorate([(0,r.Autowired)(a.MCPConfigServiceToken),n.__metadata("design:type",m.MCPConfigService)],s.prototype,"mcpConfigService",void 0),t.MCPConfigCommandContribution=s=n.__decorate([(0,a.Domain)(o.CommandContribution)],s)},5297:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPConfigContribution=t.MCP_CONFIG_COMPONENTS_SCHEME_ID=void 0;const n=e(85608),r=e(76003),o=e(97267),a=e(93899),p=e(39496),v=e(26542),m=e(43718),_=e(82196),s=e(7443),g=e(10560),l=e(75279),h=e(27397),u="opensumi-mcp-config-viewer";t.MCP_CONFIG_COMPONENTS_SCHEME_ID="mcp-config";let d=class{registerEditorComponent(f){f.registerEditorComponent({uid:u,scheme:t.MCP_CONFIG_COMPONENTS_SCHEME_ID,component:l.MCPConfigView,renderMode:_.EditorComponentRenderMode.ONE_PER_WORKBENCH}),f.registerEditorComponentResolver(t.MCP_CONFIG_COMPONENTS_SCHEME_ID,(c,y)=>{y.push({type:"component",componentId:u})})}registerResource(f){f.registerResourceProvider({scheme:t.MCP_CONFIG_COMPONENTS_SCHEME_ID,provideResource:async c=>{const{configType:y}=c.getParsedQuery();return{uri:c,name:(0,m.localize)("ai.native.mcp.config.title"),icon:(0,o.getIcon)("mcp"),metadata:{configType:y}}}})}registerMenus(f){f.registerMenuItem(p.MenuId.EditorTitle,{command:h.MCPConfigCommands.OPEN_MCP_CONFIG_FILE.id,iconClass:(0,o.getIcon)("open"),group:"navigation",order:4,when:`resourceScheme == ${t.MCP_CONFIG_COMPONENTS_SCHEME_ID}`}),f.registerMenuItem(p.MenuId.EditorTitle,{command:h.MCPConfigCommands.OPEN_MCP_CONFIG.id,iconClass:(0,o.getIcon)("open"),group:"navigation",order:4,when:"resourceFilename =~ /mcp.json/"})}};t.MCPConfigContribution=d,n.__decorate([(0,r.Autowired)(g.IWorkspaceService),n.__metadata("design:type",Object)],d.prototype,"workspaceService",void 0),n.__decorate([(0,r.Autowired)(s.IconService),n.__metadata("design:type",s.IconService)],d.prototype,"iconService",void 0),n.__decorate([(0,r.Autowired)(),n.__metadata("design:type",v.LabelService)],d.prototype,"labelService",void 0),t.MCPConfigContribution=d=n.__decorate([(0,m.Domain)(_.BrowserEditorContribution,a.MenuContribution)],d)},33108:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPConfigService=void 0;const n=e(85608),r=e(76003),o=e(41869),a=e(78132),p=e(43718),v=e(54414),m=e(72665),_=e(19413),s=e(64811),g=e(69820),l=e(45331);let h=class extends p.Disposable{constructor(){super(),this.whenReadyDeferred=new p.Deferred,this._isInitialized=!1,this.mcpServersChangeEventEmitter=new p.Emitter,this.init(),this.disposables.push(this.mcpServerProxyService.onChangeMCPServers(()=>{this.fireMCPServersChange()})),this.disposables.push(this.preferenceService.onSpecificPreferenceChange("mcp",()=>{this.fireMCPServersChange()}))}async init(){this.chatStorage=await this.storageProvider(p.STORAGE_NAMESPACE.CHAT),this.whenReadyDeferred.resolve()}get whenReady(){return this.whenReadyDeferred.promise}get isInitialized(){return this._isInitialized}get onMCPServersChange(){return this.mcpServersChangeEventEmitter.event}fireMCPServersChange(d=!1){d&&(this._isInitialized=!0),this.mcpServersChangeEventEmitter.fire(d)}async getServers(){const{value:d,scope:E}=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0);if(E===p.PreferenceScope.Default){const S=(await this.mcpServerProxyService.$getServers()).find(D=>D.name===_.BUILTIN_MCP_SERVER_NAME);return S?[S]:[]}const f=Object.keys(d.mcpServers).map(A=>{const S=d.mcpServers[A];return S.url?{name:A,type:g.MCP_SERVER_TYPE.SSE,url:S.url}:{name:A,type:g.MCP_SERVER_TYPE.STDIO,command:S.command,args:S.args,env:S.env}}),c=await this.mcpServerProxyService.$getServers(),y=c.find(A=>A.name===_.BUILTIN_MCP_SERVER_NAME),b=f?.map(A=>{const S=c.find(D=>D.name===A.name);return S||this.sumiMCPServerBackendProxy.$addOrUpdateServer(A),{...A,isStarted:S?.isStarted||!1,tools:S?.tools||[]}});return y&&b.unshift(y),b}async controlServer(d,E){try{E?await this.mcpServerProxyService.$startServer(d):await this.mcpServerProxyService.$stopServer(d);const f=this.chatStorage.get(s.MCPServersEnabledKey,[_.BUILTIN_MCP_SERVER_NAME]),c=new Set(f);E?c.add(d):c.delete(d),this.chatStorage.set(s.MCPServersEnabledKey,Array.from(c))}catch(f){const c=f.message||f;throw this.logger.error(`Failed to ${E?"start":"stop"} server ${d}:`,c),this.messageService.error(c),f}}async saveServer(d,E){await this.whenReady;const{value:f}=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0),c=f.mcpServers;let y;E.type===g.MCP_SERVER_TYPE.SSE?y={url:E.url}:y={command:E.command,args:E.args,env:E.env},d?.name&&delete c[d.name],c[E.name]=y,await this.preferenceService.set("mcp",{mcpServers:c}),d?.enabled&&this.sumiMCPServerBackendProxy.$removeServer(d.name),this.sumiMCPServerBackendProxy.$addOrUpdateServer(E)}async deleteServer(d){const{value:E}=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0),f=E.mcpServers;f[d]&&(delete f[d],await this.sumiMCPServerBackendProxy.$removeServer(d),await this.preferenceService.set("mcp",{mcpServers:f}))}async syncServer(d){try{await this.sumiMCPServerBackendProxy.$syncServer(d)}catch(E){this.logger.error(`Failed to sync server ${d}:`,E),this.messageService.error(E.message||E)}}async getServerConfigByName(d){const{value:E}=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0);await this.whenReady;const f=this.chatStorage.get(s.MCPServersEnabledKey,[_.BUILTIN_MCP_SERVER_NAME]),c=E.mcpServers[d];if(c)return c.url?{name:d,type:g.MCP_SERVER_TYPE.SSE,url:c.url,enabled:f.includes(d)}:{name:d,type:g.MCP_SERVER_TYPE.STDIO,command:c.command,args:c.args,env:c.env,enabled:f.includes(d)}}getReadableServerType(d){switch(d){case g.MCP_SERVER_TYPE.STDIO:return(0,p.localize)("ai.native.mcp.type.stdio");case g.MCP_SERVER_TYPE.SSE:return(0,p.localize)("ai.native.mcp.type.sse");case g.MCP_SERVER_TYPE.BUILTIN:return(0,p.localize)("ai.native.mcp.type.builtin");default:return d}}async openConfigFile(){let d=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0);d.scope===p.PreferenceScope.Default&&(await this.preferenceService.set("mcp",{mcpServers:{}},p.PreferenceScope.Workspace),d=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0));const E=d.configUri;E&&this.workbenchEditorService.open(E,{preview:!1})}};t.MCPConfigService=h,n.__decorate([(0,r.Autowired)(_.SumiMCPServerProxyServicePath),n.__metadata("design:type",Object)],h.prototype,"sumiMCPServerBackendProxy",void 0),n.__decorate([(0,r.Autowired)(l.MCPServerProxyService),n.__metadata("design:type",l.MCPServerProxyService)],h.prototype,"mcpServerProxyService",void 0),n.__decorate([(0,r.Autowired)(a.PreferenceService),n.__metadata("design:type",Object)],h.prototype,"preferenceService",void 0),n.__decorate([(0,r.Autowired)(m.IMessageService),n.__metadata("design:type",Object)],h.prototype,"messageService",void 0),n.__decorate([(0,r.Autowired)(p.StorageProvider),n.__metadata("design:type",Function)],h.prototype,"storageProvider",void 0),n.__decorate([(0,r.Autowired)(v.WorkbenchEditorService),n.__metadata("design:type",v.WorkbenchEditorService)],h.prototype,"workbenchEditorService",void 0),n.__decorate([(0,r.Autowired)(o.ILogger),n.__metadata("design:type",Object)],h.prototype,"logger",void 0),t.MCPConfigService=h=n.__decorate([(0,r.Injectable)(),n.__metadata("design:paramtypes",[])],h)},33368:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPFolderPreferenceProvider=void 0;const n=e(85608),r=e(76003),o=e(91825);let a=class extends o.FolderFilePreferenceProvider{parse(v){const m=super.parse(v);if(m!==void 0)return{mcp:{...m}}}getPath(v){if(v==="mcp")return[];if(v.startsWith("mcp."))return[v.substr(4)]}};t.MCPFolderPreferenceProvider=a,t.MCPFolderPreferenceProvider=a=n.__decorate([(0,r.Injectable)()],a)},55003:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPPreferencesContribution=t.MCPResourceProvider=void 0;const n=e(85608),r=e(76003),o=e(41869),a=e(57517),p=e(924);let v=class{provideResource(s){return{supportsRevive:!0,name:(0,o.localize)("menu-bar.title.debug"),icon:(0,o.getIcon)("debug"),uri:s}}provideResourceSubname(){return null}async shouldCloseResource(){return!0}};t.MCPResourceProvider=v,t.MCPResourceProvider=v=n.__decorate([(0,r.Injectable)()],v);let m=class{constructor(){this.schema=p.MCPPreferencesSchema,this.name="mcp"}registerResource(s){s.registerResourceProvider(this.prefResourceProvider)}registerSchema(s){s.registerSchema(p.MCPSchemaUri,p.MCPSchema,["mcp.json"])}};t.MCPPreferencesContribution=m,n.__decorate([(0,r.Autowired)(v),n.__metadata("design:type",v)],m.prototype,"prefResourceProvider",void 0),t.MCPPreferencesContribution=m=n.__decorate([(0,o.Domain)(o.PreferenceContribution,o.PreferenceConfiguration,a.BrowserEditorContribution,o.JsonSchemaContribution)],m)},924:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPSchema=t.MCPPreferencesSchema=t.MCPSchemaUri=void 0,t.MCPSchemaUri="vscode://schemas/mcp/user",t.MCPPreferencesSchema={type:"object",scope:"resource",properties:{mcp:{$ref:t.MCPSchemaUri,description:"MCP configuration for Workspace.",defaultValue:{mcpServers:{}}}}},t.MCPSchema={$id:t.MCPSchemaUri,type:"object",title:"MCP",required:[],default:{mcpServers:{}},properties:{mcpServers:{type:"object",description:"List of MCP Servers. Add new servers or edit existing ones by using IntelliSense.",additionalProperties:{type:"object",properties:{command:{type:"string",description:"The command to start the MCP server."},args:{type:"array",description:"The arguments for the command to start the MCP server.",items:{type:"string"}},env:{type:"object",description:"The environment variables for the command to start the MCP server.",additionalProperties:{type:"string"}},url:{type:"string",description:"The SSE URL for the MCP server."}},oneOf:[{required:["command"]},{required:["url"]}]}}}}},45331:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPServerProxyService=void 0;const n=e(85608),r=e(48085),o=e(76003),a=e(41869),p=e(43718),v=e(19413),m=e(77633);let _=class{constructor(){this._onChangeMCPServers=new p.Emitter,this.onChangeMCPServers=this._onChangeMCPServers.event}$callMCPTool(g,l){return this.mcpServerRegistry.callMCPTool(g,l)}async $getBuiltinMCPTools(){const g=await this.mcpServerRegistry.getMCPTools().map(l=>({name:l.name,description:l.description,inputSchema:(0,r.zodToJsonSchema)(l.inputSchema),providerName:v.BUILTIN_MCP_SERVER_NAME}));return this.logger.log("SUMI MCP tools",g),g}async $updateMCPServers(){this._onChangeMCPServers.fire("update")}async getAllMCPTools(){return this.sumiMCPServerProxyService.$getAllMCPTools()}async $getServers(){return this.sumiMCPServerProxyService.$getServers()}async $startServer(g){await this.sumiMCPServerProxyService.$startServer(g)}async $stopServer(g){await this.sumiMCPServerProxyService.$stopServer(g)}};t.MCPServerProxyService=_,n.__decorate([(0,o.Autowired)(m.TokenMCPServerRegistry),n.__metadata("design:type",Object)],_.prototype,"mcpServerRegistry",void 0),n.__decorate([(0,o.Autowired)(a.ILogger),n.__metadata("design:type",Object)],_.prototype,"logger",void 0),n.__decorate([(0,o.Autowired)(v.SumiMCPServerProxyServicePath),n.__metadata("design:type",Object)],_.prototype,"sumiMCPServerProxyService",void 0),t.MCPServerProxyService=_=n.__decorate([(0,o.Injectable)()],_)},79502:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPServerRegistry=void 0;const n=e(85608),r=e(76003),o=e(43718),a=e(19413),p=e(98864);class v{constructor(s){this.logger=s}appendLine(s){this.logger.log(s)}}let m=class{constructor(){this.tools=[],this.toolComponents={}}get logger(){return new v(this.baseLogger)}set activeMessageInfo(s){this._activeMessageInfo=s}getMCPTool(s,g=a.BUILTIN_MCP_SERVER_NAME){return this.tools.find(l=>(0,p.getToolName)(l.name,g)===s)}registerMCPTool(s){this.tools.push(s)}registerToolComponent(s,g,l=a.BUILTIN_MCP_SERVER_NAME){this.toolComponents[(0,p.getToolName)(s,l)]=g}getToolComponent(s){return this.toolComponents[s]}getMCPTools(){return this.tools.sort((s,g)=>{var l,h;return((l=s.order)!==null&&l!==void 0?l:1/0)-((h=g.order)!==null&&h!==void 0?h:1/0)})}async callMCPTool(s,g){try{const l=this.tools.find(d=>d.name===s);if(!l)throw new Error(`MCP tool ${s} not found`);const h=g.toolCallId;g=l.inputSchema.parse(g);const u=await l.handler({...g,toolCallId:h},this.logger);return this.reportToolCall(s,g,u,h),u}catch(l){return console.error("callMCPTool error:",l),this.reportToolCall(s,g,l,g.toolCallId),{content:[{type:"text",text:`The tool ${s} failed to execute. Error: ${l}`}],isError:!0}}}reportToolCall(s,g,l,h){if(!this.tools.find(d=>d.name===s))throw new Error(`MCP tool ${s} not found`);this.aiReporter.send({msgType:o.AIServiceType.ToolCall,message:JSON.stringify({args:g,name:s,result:l}),messageId:this._activeMessageInfo.messageId,sessionId:this._activeMessageInfo.sessionId,relationId:h})}};t.MCPServerRegistry=m,n.__decorate([(0,r.Autowired)(o.ILogger),n.__metadata("design:type",Object)],m.prototype,"baseLogger",void 0),n.__decorate([(0,r.Autowired)(o.IAIReporter),n.__metadata("design:type",Object)],m.prototype,"aiReporter",void 0),t.MCPServerRegistry=m=n.__decorate([(0,r.Injectable)()],m)},30703:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPToolsDialog=void 0;const n=e(85608),r=n.__importStar(e(14041)),o=n.__importDefault(e(49783)),a=({tools:p})=>r.createElement("div",{className:o.default.mcp_tools_dialog},r.createElement("div",{className:o.default.dialog_title},"MCP Tools"),r.createElement("div",{className:o.default.tools_list},p.map(v=>r.createElement("div",{key:v.name,className:o.default.tool_item},r.createElement("div",{className:o.default.tool_name},v.name),r.createElement("div",{className:o.default.tool_description},v.description),v.providerName&&r.createElement("div",{className:o.default.tool_provider},"Provider: ",v.providerName)))));t.MCPToolsDialog=a},58260:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.EditFileToolComponent=void 0;const n=e(85608),r=n.__importDefault(e(53373)),o=n.__importStar(e(14041)),a=e(97267),p=e(41869),v=e(54414),m=e(14162),_=e(87822),s=e(16781),g=e(21967),l=e(56474),h=e(73974),u=n.__importDefault(e(51601)),d=E=>{var f,c,y;const{args:b,messageId:A,toolCallId:S}=E,[D,T]=(0,o.useState)("code"),w=(0,p.useInjectable)(p.LabelService),I=(0,p.useInjectable)(p.AppConfig),R=(0,p.useInjectable)(h.BaseApplyService),P=(0,p.useInjectable)(v.WorkbenchEditorService),{target_file:O="",code_edit:M,instructions:k}=b||{},F=p.path.join(I.workspaceDir,O),[L,B]=(0,o.useState)(R.getCodeBlock(S,A)),U=(0,o.useMemo)(()=>O?`file-icon ${w.getIcon(p.URI.file(F))}`:void 0,[O,F]),W=(0,o.useMemo)(()=>{if(!O)return;const Q=s.StandaloneServices.get(_.IModelService),G=s.StandaloneServices.get(m.ILanguageService);return(0,p.detectModeId)(Q,G,p.Uri.file(F))},[O,F]);(0,o.useEffect)(()=>{const Q=R.onCodeBlockUpdate(G=>{G.toolCallId===S&&B({...G})});return()=>{Q.dispose()}},[]);const j=Q=>{Q.stopPropagation(),T(D==="code"?"diff":"code")};return!b||!L?null:[k&&o.default.createElement("p",{key:"edit-file-tool-instructions"},k),o.default.createElement("div",{className:u.default["edit-file-tool"],key:"edit-file-tool"},o.default.createElement("div",{className:(0,r.default)(u.default["edit-file-tool-header"],{clickable:L.status==="pending"||L.status==="success"}),onClick:()=>{L.status==="pending"?P.open(p.URI.file(F)):L.status==="success"&&R.revealApplyPosition(L)}},o.default.createElement("div",{className:u.default.left},U&&o.default.createElement("span",{className:U}),o.default.createElement("span",{className:u.default["edit-file-tool-file-name"]},O),L.iterationCount>1&&o.default.createElement("span",{className:u.default["edit-file-tool-iteration-count"]},L.iterationCount,"/3"),o.default.createElement(g.ApplyStatus,{status:L.status,error:E.result})),o.default.createElement("div",{className:u.default.right},o.default.createElement(a.Popover,{title:"Show Code",id:"edit-file-tool-show-code"},o.default.createElement(a.Icon,{iconClass:"codicon codicon-file-code",onClick:j})),((f=L.applyResult)===null||f===void 0?void 0:f.diff)&&o.default.createElement(a.Popover,{title:"Show Diff",id:"edit-file-tool-show-diff"},o.default.createElement(a.Icon,{iconClass:"codicon codicon-diff-multiple",onClick:j})))),o.default.createElement(l.ChatMarkdown,{markdown:D==="code"?`\`\`\`${W||""}
31667
+ `).filter(Boolean).reduce((Z,$)=>{const[V,H]=$.split("=");return V&&H&&(Z[V.trim()]=H.trim()),Z},{});j.args=Q,j.env=G}b({...y,name:"",command:"",url:"",args:[],env:{}}),E(j)},[y,S,T,E,I]),P=(0,o.useCallback)(B=>{b({...y,command:B.target.value})},[y,S]),O=(0,o.useCallback)(B=>{D(B.target.value)},[S]),M=(0,o.useCallback)(B=>{w(B.target.value)},[T]),k=(0,o.useCallback)(B=>{b({...y,url:B.target.value})},[y]),F=(0,o.useCallback)(B=>{b({...y,type:B,command:"",args:[],env:{},url:""})},[y]),L=(0,o.useCallback)(()=>y?.type===g.MCP_SERVER_TYPE.STDIO?o.default.createElement(o.default.Fragment,null,o.default.createElement("div",{className:l.default.formItem},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.command")),o.default.createElement("input",{type:"text",value:y.command,onChange:P,placeholder:(0,_.localize)("ai.native.mcp.command.placeHolder"),required:!0})),o.default.createElement("div",{className:l.default.formItem},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.args")),o.default.createElement("textarea",{value:S,onChange:O,placeholder:(0,_.localize)("ai.native.mcp.args.placeHolder"),rows:3})),o.default.createElement("div",{className:l.default.formItem},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.env")),o.default.createElement("textarea",{value:T,onChange:M,placeholder:(0,_.localize)("ai.native.mcp.env.placeHolder"),rows:3}))):o.default.createElement(o.default.Fragment,null,o.default.createElement("div",{className:l.default.formItem},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.url")),o.default.createElement("textarea",{value:y.url,onChange:k,placeholder:(0,_.localize)("ai.native.mcp.url.placeHolder"),rows:3}))),[y,S,T]);return o.default.createElement(v.Modal,{title:d?(0,_.localize)("ai.native.mcp.editMCPServer.title"):(0,_.localize)("ai.native.mcp.addMCPServer.title"),visible:u,onCancel:f,centered:!0,width:600,footer:null,style:{background:"var(--editor-background)"}},o.default.createElement("form",{className:l.default.form,onSubmit:B=>B.preventDefault()},o.default.createElement("div",{className:l.default.formRow},o.default.createElement("div",{className:(0,r.default)(l.default.formItem,l.default.formItemName)},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.name")),o.default.createElement("input",{type:"text",value:y.name,onChange:B=>b({...y,name:B.target.value}),placeholder:(0,_.localize)("ai.native.mcp.name.placeHolder"),required:!0})),o.default.createElement("div",{className:(0,r.default)(l.default.formItem,l.default.formItemType)},o.default.createElement("label",null,(0,_.localize)("ai.native.mcp.type")),o.default.createElement(a.Select,{size:"large",value:y.type,options:[{label:(0,_.localize)("ai.native.mcp.stdio"),value:g.MCP_SERVER_TYPE.STDIO},{label:(0,_.localize)("ai.native.mcp.sse"),value:g.MCP_SERVER_TYPE.SSE}],className:l.default.formItemSelect,onChange:F}))),L(),o.default.createElement("div",{className:l.default.formActions},o.default.createElement(p.Button,{onClick:f,type:"primary",className:l.default.secondaryButton},(0,_.localize)("ai.native.mcp.buttonCancel")),o.default.createElement(p.Button,{onClick:R,type:"primary"},d?(0,_.localize)("ai.native.mcp.buttonUpdate"):(0,_.localize)("ai.native.mcp.buttonSave")))))};t.MCPServerForm=h},27397:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPConfigCommandContribution=t.MCPConfigCommands=void 0;const n=e(85608),r=e(76003),o=e(41869),a=e(43718),p=e(54414),v=e(5297),m=e(33108);var _;(function(g){g.OPEN_MCP_CONFIG={id:"mcp.openConfig",label:"Open MCP Configuration"},g.OPEN_MCP_CONFIG_FILE={id:"mcp.openConfigFile",label:"Open MCP Configuration (JSON)"}})(_||(t.MCPConfigCommands=_={}));let s=class{registerCommands(l){l.registerCommand(_.OPEN_MCP_CONFIG,{execute:()=>{const h=new o.URI().withScheme(v.MCP_CONFIG_COMPONENTS_SCHEME_ID);this.editorService.open(h,{preview:!1,focus:!0})}}),l.registerCommand(_.OPEN_MCP_CONFIG_FILE,{execute:()=>{this.mcpConfigService.openConfigFile()}})}};t.MCPConfigCommandContribution=s,n.__decorate([(0,r.Autowired)(p.WorkbenchEditorService),n.__metadata("design:type",p.WorkbenchEditorService)],s.prototype,"editorService",void 0),n.__decorate([(0,r.Autowired)(a.MCPConfigServiceToken),n.__metadata("design:type",m.MCPConfigService)],s.prototype,"mcpConfigService",void 0),t.MCPConfigCommandContribution=s=n.__decorate([(0,a.Domain)(o.CommandContribution)],s)},5297:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPConfigContribution=t.MCP_CONFIG_COMPONENTS_SCHEME_ID=void 0;const n=e(85608),r=e(76003),o=e(97267),a=e(93899),p=e(39496),v=e(26542),m=e(43718),_=e(82196),s=e(7443),g=e(10560),l=e(75279),h=e(27397),u="opensumi-mcp-config-viewer";t.MCP_CONFIG_COMPONENTS_SCHEME_ID="mcp-config";let d=class{registerEditorComponent(f){f.registerEditorComponent({uid:u,scheme:t.MCP_CONFIG_COMPONENTS_SCHEME_ID,component:l.MCPConfigView,renderMode:_.EditorComponentRenderMode.ONE_PER_WORKBENCH}),f.registerEditorComponentResolver(t.MCP_CONFIG_COMPONENTS_SCHEME_ID,(c,y)=>{y.push({type:"component",componentId:u})})}registerResource(f){f.registerResourceProvider({scheme:t.MCP_CONFIG_COMPONENTS_SCHEME_ID,provideResource:async c=>{const{configType:y}=c.getParsedQuery();return{uri:c,name:(0,m.localize)("ai.native.mcp.config.title"),icon:(0,o.getIcon)("mcp"),metadata:{configType:y}}}})}registerMenus(f){f.registerMenuItem(p.MenuId.EditorTitle,{command:h.MCPConfigCommands.OPEN_MCP_CONFIG_FILE.id,iconClass:(0,o.getIcon)("open"),group:"navigation",order:4,when:`resourceScheme == ${t.MCP_CONFIG_COMPONENTS_SCHEME_ID}`}),f.registerMenuItem(p.MenuId.EditorTitle,{command:h.MCPConfigCommands.OPEN_MCP_CONFIG.id,iconClass:(0,o.getIcon)("open"),group:"navigation",order:4,when:"resourceFilename =~ /mcp.json/"})}};t.MCPConfigContribution=d,n.__decorate([(0,r.Autowired)(g.IWorkspaceService),n.__metadata("design:type",Object)],d.prototype,"workspaceService",void 0),n.__decorate([(0,r.Autowired)(s.IconService),n.__metadata("design:type",s.IconService)],d.prototype,"iconService",void 0),n.__decorate([(0,r.Autowired)(),n.__metadata("design:type",v.LabelService)],d.prototype,"labelService",void 0),t.MCPConfigContribution=d=n.__decorate([(0,m.Domain)(_.BrowserEditorContribution,a.MenuContribution)],d)},33108:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPConfigService=void 0;const n=e(85608),r=e(76003),o=e(41869),a=e(78132),p=e(43718),v=e(54414),m=e(72665),_=e(19413),s=e(64811),g=e(69820),l=e(45331);let h=class extends p.Disposable{constructor(){super(),this.whenReadyDeferred=new p.Deferred,this._isInitialized=!1,this.mcpServersChangeEventEmitter=new p.Emitter,this.init(),this.disposables.push(this.mcpServerProxyService.onChangeMCPServers(()=>{this.fireMCPServersChange()})),this.disposables.push(this.preferenceService.onSpecificPreferenceChange("mcp",()=>{this.fireMCPServersChange()}))}async init(){this.chatStorage=await this.storageProvider(p.STORAGE_NAMESPACE.CHAT),this.whenReadyDeferred.resolve()}get whenReady(){return this.whenReadyDeferred.promise}get isInitialized(){return this._isInitialized}get onMCPServersChange(){return this.mcpServersChangeEventEmitter.event}fireMCPServersChange(d=!1){d&&(this._isInitialized=!0),this.mcpServersChangeEventEmitter.fire(d)}async getServers(){const{value:d,scope:E}=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0);if(E===p.PreferenceScope.Default){const S=(await this.mcpServerProxyService.$getServers()).find(D=>D.name===_.BUILTIN_MCP_SERVER_NAME);return S?[S]:[]}const f=Object.keys(d.mcpServers).map(A=>{const S=d.mcpServers[A];return S.url?{name:A,type:g.MCP_SERVER_TYPE.SSE,url:S.url}:{name:A,type:g.MCP_SERVER_TYPE.STDIO,command:S.command,args:S.args,env:S.env}}),c=await this.mcpServerProxyService.$getServers(),y=c.find(A=>A.name===_.BUILTIN_MCP_SERVER_NAME),b=f?.map(A=>{const S=c.find(D=>D.name===A.name);return S||this.sumiMCPServerBackendProxy.$addOrUpdateServer(A),{...A,isStarted:S?.isStarted||!1,tools:S?.tools||[]}});return y&&b.unshift(y),b}async controlServer(d,E){try{E?await this.mcpServerProxyService.$startServer(d):await this.mcpServerProxyService.$stopServer(d);const f=this.chatStorage.get(s.MCPServersEnabledKey,[_.BUILTIN_MCP_SERVER_NAME]),c=new Set(f);E?c.add(d):c.delete(d),this.chatStorage.set(s.MCPServersEnabledKey,Array.from(c))}catch(f){const c=f.message||f;throw this.logger.error(`Failed to ${E?"start":"stop"} server ${d}:`,c),this.messageService.error(c),f}}async saveServer(d,E){await this.whenReady;const{value:f}=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0),c=f.mcpServers;let y;E.type===g.MCP_SERVER_TYPE.SSE?y={url:E.url}:y={command:E.command,args:E.args,env:E.env},d?.name&&delete c[d.name],c[E.name]=y,await this.preferenceService.set("mcp",{mcpServers:c}),d?.enabled&&this.sumiMCPServerBackendProxy.$removeServer(d.name),this.sumiMCPServerBackendProxy.$addOrUpdateServer(E)}async deleteServer(d){const{value:E}=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0),f=E.mcpServers;f[d]&&(delete f[d],await this.sumiMCPServerBackendProxy.$removeServer(d),await this.preferenceService.set("mcp",{mcpServers:f}))}async syncServer(d){try{await this.sumiMCPServerBackendProxy.$syncServer(d)}catch(E){this.logger.error(`Failed to sync server ${d}:`,E),this.messageService.error(E.message||E)}}async getServerConfigByName(d){const{value:E}=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0);await this.whenReady;const f=this.chatStorage.get(s.MCPServersEnabledKey,[_.BUILTIN_MCP_SERVER_NAME]),c=E.mcpServers[d];if(c)return c.url?{name:d,type:g.MCP_SERVER_TYPE.SSE,url:c.url,enabled:f.includes(d)}:{name:d,type:g.MCP_SERVER_TYPE.STDIO,command:c.command,args:c.args,env:c.env,enabled:f.includes(d)}}getReadableServerType(d){switch(d){case g.MCP_SERVER_TYPE.STDIO:return(0,p.localize)("ai.native.mcp.type.stdio");case g.MCP_SERVER_TYPE.SSE:return(0,p.localize)("ai.native.mcp.type.sse");case g.MCP_SERVER_TYPE.BUILTIN:return(0,p.localize)("ai.native.mcp.type.builtin");default:return d}}async openConfigFile(){let d=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0);d.scope===p.PreferenceScope.Default&&(await this.preferenceService.set("mcp",{mcpServers:{}},p.PreferenceScope.Workspace),d=this.preferenceService.resolve("mcp",{mcpServers:{}},void 0));const E=d.configUri;E&&this.workbenchEditorService.open(E,{preview:!1})}};t.MCPConfigService=h,n.__decorate([(0,r.Autowired)(_.SumiMCPServerProxyServicePath),n.__metadata("design:type",Object)],h.prototype,"sumiMCPServerBackendProxy",void 0),n.__decorate([(0,r.Autowired)(l.MCPServerProxyService),n.__metadata("design:type",l.MCPServerProxyService)],h.prototype,"mcpServerProxyService",void 0),n.__decorate([(0,r.Autowired)(a.PreferenceService),n.__metadata("design:type",Object)],h.prototype,"preferenceService",void 0),n.__decorate([(0,r.Autowired)(m.IMessageService),n.__metadata("design:type",Object)],h.prototype,"messageService",void 0),n.__decorate([(0,r.Autowired)(p.StorageProvider),n.__metadata("design:type",Function)],h.prototype,"storageProvider",void 0),n.__decorate([(0,r.Autowired)(v.WorkbenchEditorService),n.__metadata("design:type",v.WorkbenchEditorService)],h.prototype,"workbenchEditorService",void 0),n.__decorate([(0,r.Autowired)(o.ILogger),n.__metadata("design:type",Object)],h.prototype,"logger",void 0),t.MCPConfigService=h=n.__decorate([(0,r.Injectable)(),n.__metadata("design:paramtypes",[])],h)},33368:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPFolderPreferenceProvider=void 0;const n=e(85608),r=e(76003),o=e(91825);let a=class extends o.FolderFilePreferenceProvider{parse(v){const m=super.parse(v);if(m!==void 0)return{mcp:{...m}}}getPath(v){if(v==="mcp")return[];if(v.startsWith("mcp."))return[v.substr(4)]}};t.MCPFolderPreferenceProvider=a,t.MCPFolderPreferenceProvider=a=n.__decorate([(0,r.Injectable)()],a)},55003:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPPreferencesContribution=t.MCPResourceProvider=void 0;const n=e(85608),r=e(76003),o=e(41869),a=e(57517),p=e(924);let v=class{provideResource(s){return{supportsRevive:!0,name:(0,o.localize)("menu-bar.title.debug"),icon:(0,o.getIcon)("debug"),uri:s}}provideResourceSubname(){return null}async shouldCloseResource(){return!0}};t.MCPResourceProvider=v,t.MCPResourceProvider=v=n.__decorate([(0,r.Injectable)()],v);let m=class{constructor(){this.schema=p.MCPPreferencesSchema,this.name="mcp"}registerResource(s){s.registerResourceProvider(this.prefResourceProvider)}registerSchema(s){s.registerSchema(p.MCPSchemaUri,p.MCPSchema,["mcp.json"])}};t.MCPPreferencesContribution=m,n.__decorate([(0,r.Autowired)(v),n.__metadata("design:type",v)],m.prototype,"prefResourceProvider",void 0),t.MCPPreferencesContribution=m=n.__decorate([(0,o.Domain)(o.PreferenceContribution,o.PreferenceConfiguration,a.BrowserEditorContribution,o.JsonSchemaContribution)],m)},924:(x,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPSchema=t.MCPPreferencesSchema=t.MCPSchemaUri=void 0,t.MCPSchemaUri="vscode://schemas/mcp/user",t.MCPPreferencesSchema={type:"object",scope:"resource",properties:{mcp:{$ref:t.MCPSchemaUri,description:"MCP configuration for Workspace.",defaultValue:{mcpServers:{}}}}},t.MCPSchema={$id:t.MCPSchemaUri,type:"object",title:"MCP",required:[],default:{mcpServers:{}},properties:{mcpServers:{type:"object",description:"List of MCP Servers. Add new servers or edit existing ones by using IntelliSense.",additionalProperties:{type:"object",properties:{command:{type:"string",description:"The command to start the MCP server."},args:{type:"array",description:"The arguments for the command to start the MCP server.",items:{type:"string"}},env:{type:"object",description:"The environment variables for the command to start the MCP server.",additionalProperties:{type:"string"}},url:{type:"string",description:"The SSE URL for the MCP server."}},oneOf:[{required:["command"]},{required:["url"]}]}}}}},45331:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPServerProxyService=void 0;const n=e(85608),r=e(48085),o=e(76003),a=e(41869),p=e(43718),v=e(19413),m=e(77633);let _=class{constructor(){this._onChangeMCPServers=new p.Emitter,this.onChangeMCPServers=this._onChangeMCPServers.event}$callMCPTool(g,l){return this.mcpServerRegistry.callMCPTool(g,l)}async $getBuiltinMCPTools(){const g=await this.mcpServerRegistry.getMCPTools().map(l=>({name:l.name,description:l.description,inputSchema:(0,r.zodToJsonSchema)(l.inputSchema),providerName:v.BUILTIN_MCP_SERVER_NAME}));return this.logger.log("SUMI MCP tools",g),g}async $updateMCPServers(){this._onChangeMCPServers.fire("update")}async getAllMCPTools(){return this.sumiMCPServerProxyService.$getAllMCPTools()}async $getServers(){return this.sumiMCPServerProxyService.$getServers()}async $startServer(g){await this.sumiMCPServerProxyService.$startServer(g)}async $stopServer(g){await this.sumiMCPServerProxyService.$stopServer(g)}};t.MCPServerProxyService=_,n.__decorate([(0,o.Autowired)(m.TokenMCPServerRegistry),n.__metadata("design:type",Object)],_.prototype,"mcpServerRegistry",void 0),n.__decorate([(0,o.Autowired)(a.ILogger),n.__metadata("design:type",Object)],_.prototype,"logger",void 0),n.__decorate([(0,o.Autowired)(v.SumiMCPServerProxyServicePath),n.__metadata("design:type",Object)],_.prototype,"sumiMCPServerProxyService",void 0),t.MCPServerProxyService=_=n.__decorate([(0,o.Injectable)()],_)},79502:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPServerRegistry=void 0;const n=e(85608),r=e(76003),o=e(43718),a=e(19413),p=e(98864);class v{constructor(s){this.logger=s}appendLine(s){this.logger.log(s)}}let m=class{constructor(){this.tools=[],this.toolComponents={}}get logger(){return new v(this.baseLogger)}set activeMessageInfo(s){this._activeMessageInfo=s}getMCPTool(s,g=a.BUILTIN_MCP_SERVER_NAME){return this.tools.find(l=>(0,p.getToolName)(l.name,g)===s)}registerMCPTool(s){this.tools.push(s)}registerToolComponent(s,g,l=a.BUILTIN_MCP_SERVER_NAME){this.toolComponents[(0,p.getToolName)(s,l)]=g}getToolComponent(s){return this.toolComponents[s]}getMCPTools(){return this.tools.sort((s,g)=>{var l,h;return((l=s.order)!==null&&l!==void 0?l:1/0)-((h=g.order)!==null&&h!==void 0?h:1/0)})}async callMCPTool(s,g){try{const l=this.tools.find(d=>d.name===s);if(!l)throw new Error(`MCP tool ${s} not found`);const h=g.toolCallId;g=l.inputSchema.parse(g);const u=await l.handler({...g,toolCallId:h},this.logger);return this.reportToolCall(s,g,u,h),u}catch(l){return console.error("callMCPTool error:",l),this.reportToolCall(s,g,l,g.toolCallId),{content:[{type:"text",text:`The tool ${s} failed to execute. Error: ${l}`}],isError:!0}}}reportToolCall(s,g,l,h){if(!this.tools.find(d=>d.name===s))throw new Error(`MCP tool ${s} not found`);this.aiReporter.send({msgType:o.AIServiceType.ToolCall,message:JSON.stringify({args:g,name:s,result:l}),messageId:this._activeMessageInfo.messageId,sessionId:this._activeMessageInfo.sessionId,relationId:h})}};t.MCPServerRegistry=m,n.__decorate([(0,r.Autowired)(o.ILogger),n.__metadata("design:type",Object)],m.prototype,"baseLogger",void 0),n.__decorate([(0,r.Autowired)(o.IAIReporter),n.__metadata("design:type",Object)],m.prototype,"aiReporter",void 0),t.MCPServerRegistry=m=n.__decorate([(0,r.Injectable)()],m)},30703:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MCPToolsDialog=void 0;const n=e(85608),r=n.__importStar(e(14041)),o=n.__importDefault(e(49783)),a=({tools:p})=>r.createElement("div",{className:o.default.mcp_tools_dialog},r.createElement("div",{className:o.default.dialog_title},"MCP Tools"),r.createElement("div",{className:o.default.tools_list},p.map(v=>r.createElement("div",{key:v.name,className:o.default.tool_item},r.createElement("div",{className:o.default.tool_name},v.name),r.createElement("div",{className:o.default.tool_description},v.description),v.providerName&&r.createElement("div",{className:o.default.tool_provider},"Provider: ",v.providerName)))));t.MCPToolsDialog=a},58260:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.EditFileToolComponent=void 0;const n=e(85608),r=n.__importDefault(e(53373)),o=n.__importStar(e(14041)),a=e(97267),p=e(41869),v=e(54414),m=e(14162),_=e(87822),s=e(16781),g=e(21967),l=e(56474),h=e(73974),u=n.__importDefault(e(51601)),d=E=>{var f,c,y;const{args:b,messageId:A,toolCallId:S}=E,[D,T]=(0,o.useState)("code"),w=(0,p.useInjectable)(p.LabelService),I=(0,p.useInjectable)(p.AppConfig),R=(0,p.useInjectable)(h.BaseApplyService),P=(0,p.useInjectable)(v.WorkbenchEditorService),{target_file:O="",code_edit:M,instructions:k}=b||{},F=p.path.join(I.workspaceDir,O),[L,B]=(0,o.useState)(R.getCodeBlock(S,A)),U=(0,o.useMemo)(()=>O?`file-icon ${w.getIcon(p.URI.file(F))}`:void 0,[O,F]),W=(0,o.useMemo)(()=>{if(!O)return;const G=s.StandaloneServices.get(_.IModelService),Z=s.StandaloneServices.get(m.ILanguageService);return(0,p.detectModeId)(G,Z,p.Uri.file(F))},[O,F]),j=(0,o.useMemo)(()=>{var G,Z;if(L?.status==="failed")try{return(Z=(G=JSON.parse(E.result||"{}").content)===null||G===void 0?void 0:G[0])===null||Z===void 0?void 0:Z.text}catch{return""}},[E.result,L]);(0,o.useEffect)(()=>{const G=R.onCodeBlockUpdate(Z=>{Z.toolCallId===S&&B({...Z})});return()=>{G.dispose()}},[]);const Q=G=>{G.stopPropagation(),T(D==="code"?"diff":"code")};return!b||!L?null:[k&&o.default.createElement("p",{key:"edit-file-tool-instructions"},k),o.default.createElement("div",{className:u.default["edit-file-tool"],key:"edit-file-tool"},o.default.createElement("div",{className:(0,r.default)(u.default["edit-file-tool-header"],{clickable:L.status==="pending"||L.status==="success"}),onClick:()=>{L.status==="pending"?P.open(p.URI.file(F)):L.status==="success"&&R.revealApplyPosition(L)}},o.default.createElement("div",{className:u.default.left},U&&o.default.createElement("span",{className:U}),o.default.createElement("span",{className:u.default["edit-file-tool-file-name"]},O),L.iterationCount>1&&o.default.createElement("span",{className:u.default["edit-file-tool-iteration-count"]},L.iterationCount,"/3"),o.default.createElement(g.ApplyStatus,{status:L.status,error:j})),o.default.createElement("div",{className:u.default.right},o.default.createElement(a.Popover,{title:"Show Code",id:"edit-file-tool-show-code"},o.default.createElement(a.Icon,{iconClass:"codicon codicon-file-code",onClick:Q})),((f=L.applyResult)===null||f===void 0?void 0:f.diff)&&o.default.createElement(a.Popover,{title:"Show Diff",id:"edit-file-tool-show-diff"},o.default.createElement(a.Icon,{iconClass:"codicon codicon-diff-multiple",onClick:Q})))),o.default.createElement(l.ChatMarkdown,{markdown:D==="code"?`\`\`\`${W||""}
31668
31668
  ${M}
31669
31669
  \`\`\``:`\`\`\`diff
31670
31670
  ${(c=L.applyResult)===null||c===void 0?void 0:c.diff}
31671
- \`\`\``,hideInsert:!0})),L.applyResult&&L.applyResult.diagnosticInfos.length>0&&o.default.createElement("div",{className:u.default["edit-file-tool-diagnostic-errors"],key:"edit-file-tool-diagnostic-errors"},o.default.createElement("div",{className:u.default.title},"Found Lints:"),(y=L.applyResult)===null||y===void 0?void 0:y.diagnosticInfos.map(Q=>o.default.createElement("div",{key:Q.message,className:(0,r.default)({[u.default.error]:Q.severity===p.MarkerSeverity.Error,[u.default.warning]:Q.severity===p.MarkerSeverity.Warning})},o.default.createElement(a.Icon,{className:`codicon codicon-${Q.severity===p.MarkerSeverity.Error?"error":"warning"}`}),Q.message.split(`
31671
+ \`\`\``,hideInsert:!0})),L.applyResult&&L.applyResult.diagnosticInfos.length>0&&o.default.createElement("div",{className:u.default["edit-file-tool-diagnostic-errors"],key:"edit-file-tool-diagnostic-errors"},o.default.createElement("div",{className:u.default.title},"Found Lints:"),(y=L.applyResult)===null||y===void 0?void 0:y.diagnosticInfos.map(G=>o.default.createElement("div",{key:G.message,className:(0,r.default)({[u.default.error]:G.severity===p.MarkerSeverity.Error,[u.default.warning]:G.severity===p.MarkerSeverity.Warning})},o.default.createElement(a.Icon,{className:`codicon codicon-${G.severity===p.MarkerSeverity.Error?"error":"warning"}`}),G.message.split(`
31672
31672
  `)[0])))]};t.EditFileToolComponent=d},95292:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ListDirToolComponent=t.GrepSearchToolComponent=t.FileSearchToolComponent=void 0;const n=e(85608),r=n.__importStar(e(14041)),o=e(80564),a=e(41869),p=e(54414),v=e(51500),m=e(19413),_=n.__importDefault(e(51601)),s=({args:u,toolCallId:d,messageId:E})=>r.default.createElement(h,{args:u,toolCallId:d,messageId:E,toolName:"fileSearch",headerText:`Searched files "${u.query}"`});t.FileSearchToolComponent=s;const g=({args:u,toolCallId:d,messageId:E})=>r.default.createElement(h,{args:u,toolCallId:d,messageId:E,toolName:"grepSearch",headerText:`Grepped codebase "${u.query}"`});t.GrepSearchToolComponent=g;const l=({args:u,toolCallId:d,messageId:E})=>r.default.createElement(h,{args:u,toolCallId:d,messageId:E,toolName:"listDir",headerText:`Listed directory "${u.relative_workspace_path}"`});t.ListDirToolComponent=l;const h=({args:u,toolCallId:d,toolName:E,messageId:f,headerText:c})=>{const[y,b]=(0,r.useState)(!1),A=(0,a.useInjectable)(a.LabelService),S=(0,a.useInjectable)(p.WorkbenchEditorService),D=(0,a.useInjectable)(v.IWorkspaceService),T=(0,a.useInjectable)(a.CommandService),w=(0,r.useMemo)(()=>{var k,F;return a.URI.parse((F=(k=D.tryGetRoots())===null||k===void 0?void 0:k[0])===null||F===void 0?void 0:F.uri)},[]),I=(0,a.useInjectable)(m.IChatInternalService),[R,P]=(0,r.useState)([]);(0,r.useEffect)(()=>{const k=I.sessionModel.history.onMessageAdditionalChange(F=>{F[d]&&P(F[d].files||[])});return()=>{k.dispose()}},[]);const O=async k=>{if(!k.isDirectory)S.open(a.URI.parse(k.uri));else{const F=a.URI.parse(k.uri);T.executeCommand("filetree.location",F)}},M=(0,r.useMemo)(()=>R.map(k=>{const F=a.URI.parse(k.uri);return{iconClass:A.getIcon(F,{isDirectory:k.isDirectory}),name:F.path.base,path:a.path.relative(w.codeUri.fsPath,F.path.dir.toString()),uri:k.uri,isDirectory:k.isDirectory}}),[R]);return r.default.createElement("div",{className:_.default.container},r.default.createElement("div",{className:_.default.header,onClick:()=>b(!y)},r.default.createElement("span",{style:{transform:`rotate(${y?"90deg":"0deg"})`,display:"flex"}},r.default.createElement(o.Icon,{iconClass:"codicon codicon-chevron-right"})),r.default.createElement("span",null,c," \xB7 ",R.length," files")),y&&r.default.createElement("ul",{className:_.default.fileList},M.map((k,F)=>r.default.createElement("li",{key:F,className:_.default.fileItem,onClick:()=>O({uri:k.uri,isDirectory:k.isDirectory})},r.default.createElement("span",{className:k.iconClass}),r.default.createElement("span",{style:{flex:1}},k.name),r.default.createElement("span",{className:_.default.filePath},k.path)))))}},24706:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TerminalToolComponent=void 0;const n=e(85608),r=n.__importStar(e(14041)),o=e(41869),a=e(81878),p=e(52141),v=e(89897),m=e(43718),_=e(71990),s=e(83854),g=e(22559),l=e(62471),h=n.__importDefault(e(51601));function u(f){const c={};try{const y=JSON.parse(f);return y.isError&&(c.isError=y.isError),y.content&&(c.text=y.content.map(b=>b.text).join(`
31673
31673
  `)),c}catch{return null}}const d={[s.ETerminalAutoExecutionPolicy.always]:"ai.native.terminal.autorun.always",[s.ETerminalAutoExecutionPolicy.auto]:"ai.native.terminal.autorun.auto",[s.ETerminalAutoExecutionPolicy.off]:"ai.native.terminal.autorun.off"};function E(f){return(0,m.localize)(d[f])}t.TerminalToolComponent=(0,r.memo)(f=>{const{args:c,toolCallId:y}=f,b=(0,o.useInjectable)(g.RunCommandHandler),A=(0,o.useInjectable)(o.PreferenceService),S=(0,o.useInjectable)(m.CommandService),[D,T]=(0,r.useState)(!1),w=A.get(_.AINativeSettingSectionsId.TerminalAutoRun),I=(0,r.useMemo)(()=>{var M;return!!(w===s.ETerminalAutoExecutionPolicy.off||w===s.ETerminalAutoExecutionPolicy.auto&&(!((M=f.args)===null||M===void 0)&&M.require_user_approval))},[f.args]);(0,r.useEffect)(()=>{f.state==="result"?T(!1):I||T(!0)},[f]);const R=(0,r.useCallback)(()=>{S.executeCommand("workbench.action.openSettings","ai.native.terminal.autorun")},[]),P=(0,r.useCallback)(M=>{y&&(b.handleApproval(y,M),T(!0))},[]),O=(0,r.useMemo)(()=>f.result?u(f.result):null,[f]);return r.default.createElement("div",{className:h.default.run_cmd_tool},r.default.createElement("div",null,r.default.createElement("div",{className:h.default.command_title},r.default.createElement(a.Icon,{icon:"terminal"}),r.default.createElement("span",null,I?(0,m.localize)("ai.native.mcp.terminal.allow-question"):(0,m.localize)("ai.native.mcp.terminal.command"))),r.default.createElement("p",{className:h.default.command_content},r.default.createElement("code",null,"$ ",c?.command)),r.default.createElement("p",{className:h.default.comand_description},c?.explanation),f.state==="complete"&&I&&c&&!D&&r.default.createElement("div",{className:h.default.cmmand_footer},r.default.createElement(a.Button,{type:"link",size:"small",onClick:()=>P(!0)},(0,m.localize)("ai.native.mcp.terminal.allow")),r.default.createElement(a.Button,{type:"link",size:"small",onClick:()=>P(!1)},(0,m.localize)("ai.native.mcp.terminal.deny"))),f.state==="result"&&O&&r.default.createElement(r.default.Fragment,null,r.default.createElement("div",{className:h.default.command_content},r.default.createElement(a.Icon,{icon:"output"}),r.default.createElement("code",{dangerouslySetInnerHTML:{__html:(0,l.computeAnsiLogString)(O.text||"")}})),r.default.createElement("div",{className:h.default.auto_execution_policy},r.default.createElement("span",{className:h.default.auto_execution_policy_label},E(w||s.ETerminalAutoExecutionPolicy.auto)),r.default.createElement(p.EnhancePopover,{id:"policy-config-popover",title:(0,m.localize)("ai.native.terminal.autorun.command")},r.default.createElement(a.Icon,{size:"small",iconClass:"codicon codicon-settings-gear",onClick:R}))))),D&&r.default.createElement("div",{className:h.default.running},r.default.createElement(v.Loading,null),r.default.createElement("span",null,(0,m.localize)("ai.native.terminal.autorun.running"))))})},62471:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.computeAnsiLogString=p;const n=e(85608),r=n.__importDefault(e(30002)),o=n.__importDefault(e(39718)),a=new r.default;function p(v,m=!0,_=!1){const s=v.split(`
31674
31674
  `);let g=m?(0,o.default)(s):s;return _&&(g=g.map(h=>h.replace("\r","")).filter(h=>!!h)),g.map(h=>a.ansi_to_html(h)).join(`
@@ -31699,7 +31699,7 @@ ${u.applyResult.diagnosticInfos.map(d=>`Line ${d.startLineNumber}: ${d.message.s
31699
31699
  `)[0]}`).join(`
31700
31700
  `)}
31701
31701
 
31702
- Please fix the linter errors if it is clear how to (or you can easily figure out how to). Do not make uneducated guesses. And do not loop more than 3 times on fixing linter errors on the same file.`:""}`:"User cancelled the edit."}]}}};t.EditFileTool=s,n.__decorate([(0,o.Autowired)(m.EditFileHandler),n.__metadata("design:type",m.EditFileHandler)],s.prototype,"editFileHandler",void 0),t.EditFileTool=s=n.__decorate([(0,a.Domain)(p.MCPServerContribution)],s)},80173:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FileSearchTool=void 0;const n=e(85608),r=e(75995),o=e(76003),a=e(79240),p=e(43718),v=e(87863),m=e(84660),_=e(51500),s=e(19413),g=e(59347),l=e(77633),h=e(95292),u=r.z.object({query:r.z.string().describe("Fuzzy filename to search for"),explanation:r.z.string().describe("One sentence explanation as to why this tool is being used, and how it contributes to the goal.")}),d=10;let E=class{registerMCPServer(c){c.registerMCPTool(this.getToolDefinition()),c.registerToolComponent("file_search",h.FileSearchToolComponent)}getToolDefinition(){return{name:"file_search",label:"Search Files",order:6,description:"Fast file search based on fuzzy matching against file path. Use if you know part of the file path but don't know where it's located exactly. Response will be capped to 10 results. Make your query more specific if need to filter results further.",inputSchema:u,handler:this.handler.bind(this)}}async handler(c,y){if(!c.query)throw new Error("No fileSearch parameters provided. Need to give a query.");const b=this.workspaceService.tryGetRoots();if(!b||b.length===0)throw new Error("Cannot determine project directory");const A=this.normalizeQuery(c.query),S=await this.fileSearchService.find(A,{rootUris:[new p.URI(b[0].uri).codeUri.fsPath],excludePatterns:Object.keys(v.defaultFilesWatcherExcludes),limit:100,useGitIgnore:!0,noIgnoreParent:!0,fuzzyMatch:!0}),D=S.slice(0,d).map(w=>({uri:p.URI.parse(w).codeUri.fsPath,isDirectory:!1})),T=this.chatInternalService.sessionModel.history.getMessages();return this.chatInternalService.sessionModel.history.setMessageAdditional(T[T.length-1].id,{[c.toolCallId]:{files:D}}),y.appendLine(`Found ${D.length} files matching "${c.query}"`),{content:[{type:"text",text:`${D.map(w=>w.uri).join(`
31702
+ Please fix the linter errors if it is clear how to (or you can easily figure out how to). Do not make uneducated guesses. And do not loop more than 3 times on fixing linter errors on the same file.`:"The apply model made no changes to the file."}`:"User cancelled the edit."}]}}};t.EditFileTool=s,n.__decorate([(0,o.Autowired)(m.EditFileHandler),n.__metadata("design:type",m.EditFileHandler)],s.prototype,"editFileHandler",void 0),t.EditFileTool=s=n.__decorate([(0,a.Domain)(p.MCPServerContribution)],s)},80173:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FileSearchTool=void 0;const n=e(85608),r=e(75995),o=e(76003),a=e(79240),p=e(43718),v=e(87863),m=e(84660),_=e(51500),s=e(19413),g=e(59347),l=e(77633),h=e(95292),u=r.z.object({query:r.z.string().describe("Fuzzy filename to search for"),explanation:r.z.string().describe("One sentence explanation as to why this tool is being used, and how it contributes to the goal.")}),d=10;let E=class{registerMCPServer(c){c.registerMCPTool(this.getToolDefinition()),c.registerToolComponent("file_search",h.FileSearchToolComponent)}getToolDefinition(){return{name:"file_search",label:"Search Files",order:6,description:"Fast file search based on fuzzy matching against file path. Use if you know part of the file path but don't know where it's located exactly. Response will be capped to 10 results. Make your query more specific if need to filter results further.",inputSchema:u,handler:this.handler.bind(this)}}async handler(c,y){if(!c.query)throw new Error("No fileSearch parameters provided. Need to give a query.");const b=this.workspaceService.tryGetRoots();if(!b||b.length===0)throw new Error("Cannot determine project directory");const A=this.normalizeQuery(c.query),S=await this.fileSearchService.find(A,{rootUris:[new p.URI(b[0].uri).codeUri.fsPath],excludePatterns:Object.keys(v.defaultFilesWatcherExcludes),limit:100,useGitIgnore:!0,noIgnoreParent:!0,fuzzyMatch:!0}),D=S.slice(0,d).map(w=>({uri:p.URI.parse(w).codeUri.fsPath,isDirectory:!1})),T=this.chatInternalService.sessionModel.history.getMessages();return this.chatInternalService.sessionModel.history.setMessageAdditional(T[T.length-1].id,{[c.toolCallId]:{files:D}}),y.appendLine(`Found ${D.length} files matching "${c.query}"`),{content:[{type:"text",text:`${D.map(w=>w.uri).join(`
31703
31703
  `)}
31704
31704
  ${S.length>d?`
31705
31705
  Found ${S.length} files matching "${c.query}", only return the first ${d} results`:""}`}]}}normalizeQuery(c){const y=c.trim().replace(/\s/g,"");return(0,a.getValidateInput)(y)}};t.FileSearchTool=E,n.__decorate([(0,o.Autowired)(_.IWorkspaceService),n.__metadata("design:type",Object)],E.prototype,"workspaceService",void 0),n.__decorate([(0,o.Autowired)(m.FileSearchServicePath),n.__metadata("design:type",Object)],E.prototype,"fileSearchService",void 0),n.__decorate([(0,o.Autowired)(s.IChatInternalService),n.__metadata("design:type",g.ChatInternalService)],E.prototype,"chatInternalService",void 0),t.FileSearchTool=E=n.__decorate([(0,p.Domain)(l.MCPServerContribution)],E)},30645:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.GetDiagnosticsByPathTool=void 0;const n=e(85608),r=n.__importStar(e(64756)),o=e(75995),a=e(76003),p=e(43718),v=e(51500),m=e(26592),_=e(34835),s=e(77633),g=o.z.object({filePathInProject:o.z.string().describe("The relative path to the file to get diagnostics for")});let l=class{registerMCPServer(u){u.registerMCPTool(this.getToolDefinition())}getToolDefinition(){return{name:"get_diagnostics_by_path",label:"Get Diagnostics By Path",order:9,description:`Retrieves diagnostic information (errors, warnings, etc.) from a specific file in the project. Use this tool to get information about problems in any project file. IMPORTANT: This tool should be called after any code generation or modification operations to verify and fix potential issues. Requires a filePathInProject parameter specifying the target file path relative to project root. Returns a JSON-formatted list of diagnostics, where each entry contains: - path: The file path where the diagnostic was found - line: The line number (1-based) of the diagnostic - severity: The severity level ("error", "warning", "information", or "hint") - message: The diagnostic message Returns an empty list ([]) if no diagnostics are found or the file doesn't exist. Best Practice: Always check diagnostics after code generation to ensure code quality and fix any issues immediately. Use this tool in combination with get_open_in_editor_file_diagnostics to verify all affected files after code changes. Diagnostic Severity Handling Guidelines: - "error": Must be fixed immediately as they indicate critical issues that will prevent code from working correctly. - "warning": For user code, preserve unless the warning indicates a clear improvement opportunity. For generated code, optimize to remove warnings. - "information"/"hint": For user code, preserve as they might reflect intentional patterns. For generated code, optimize if it improves code quality without changing functionality.`,inputSchema:g,handler:this.handler.bind(this)}}async handler(u,d){try{const E=this.workspaceService.tryGetRoots();if(!E||E.length===0)return d.appendLine("Error: Cannot determine project directory"),{content:[{type:"text",text:"[]"}],isError:!0};const f=p.URI.parse(E[0].uri),c=r.join(f.codeUri.fsPath,u.filePathInProject),y=m.URI.file(c),b=r.relative(f.codeUri.fsPath,c);if(b.startsWith("..")||r.isAbsolute(b))return d.appendLine("Error: File is outside of project scope"),{content:[{type:"text",text:"[]"}],isError:!0};const S=this.markerService.read({resource:y}).map(T=>({path:u.filePathInProject,line:T.startLineNumber,severity:this.getSeverityString(T.severity),message:T.message})),D=JSON.stringify(S,null,2);return d.appendLine(`Found ${S.length} diagnostics in ${u.filePathInProject}`),{content:[{type:"text",text:D}]}}catch(E){return d.appendLine(`Error getting diagnostics: ${E}`),{content:[{type:"text",text:"[]"}],isError:!0}}}getSeverityString(u){switch(u){case _.MarkerSeverity.Error:return"error";case _.MarkerSeverity.Warning:return"warning";case _.MarkerSeverity.Info:return"information";case _.MarkerSeverity.Hint:return"hint";default:return"unknown"}}};t.GetDiagnosticsByPathTool=l,n.__decorate([(0,a.Autowired)(v.IWorkspaceService),n.__metadata("design:type",Object)],l.prototype,"workspaceService",void 0),n.__decorate([(0,a.Autowired)(_.IMarkerService),n.__metadata("design:type",Object)],l.prototype,"markerService",void 0),t.GetDiagnosticsByPathTool=l=n.__decorate([(0,p.Domain)(s.MCPServerContribution)],l)},82078:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.GetOpenEditorFileDiagnosticsTool=void 0;const n=e(85608),r=n.__importStar(e(64756)),o=e(75995),a=e(76003),p=e(43718),v=e(54414),m=e(51500),_=e(26592),s=e(34835),g=e(77633),l=o.z.object({});let h=class{registerMCPServer(d){d.registerMCPTool(this.getToolDefinition())}getToolDefinition(){return{name:"get_open_in_editor_file_diagnostics",label:"Get Current Editor Diagnostics",order:8,description:'Retrieves diagnostic information (errors, warnings, etc.) from the currently active file in VS Code editor. Use this tool to get information about problems in your current file. IMPORTANT: This tool should be called after any code generation or modification operations to verify and fix potential issues. Returns a JSON-formatted list of diagnostics, where each entry contains: - path: The file path where the diagnostic was found - line: The line number (1-based) of the diagnostic - severity: The severity level ("error", "warning", "information", or "hint") - message: The diagnostic message Returns an empty list ([]) if no diagnostics are found or no file is open. Best Practice: Always check diagnostics after code generation to ensure code quality and fix any issues immediately. Diagnostic Severity Handling Guidelines: - "error": Must be fixed immediately as they indicate critical issues that will prevent code from working correctly. - "warning": For user code, preserve unless the warning indicates a clear improvement opportunity. For generated code, optimize to remove warnings. - "information"/"hint": For user code, preserve as they might reflect intentional patterns. For generated code, optimize if it improves code quality without changing functionality.',inputSchema:l,handler:this.handler.bind(this)}}async handler(d,E){try{const f=this.editorService.currentEditor;if(!f||!f.currentUri)return E.appendLine("Error: No active text editor found"),{content:[{type:"text",text:"[]"}],isError:!0};const c=this.workspaceService.tryGetRoots();if(!c||c.length===0)return E.appendLine("Error: Cannot determine project directory"),{content:[{type:"text",text:"[]"}],isError:!0};const y=_.URI.parse(f.currentUri.toString()),b=this.markerService.read({resource:y}),A=p.URI.parse(c[0].uri),S=r.relative(A.codeUri.fsPath,f.currentUri.codeUri.fsPath),D=b.map(w=>({path:S,line:w.startLineNumber,severity:this.getSeverityString(w.severity),message:w.message})),T=JSON.stringify(D,null,2);return E.appendLine(`Found ${D.length} diagnostics in current file`),{content:[{type:"text",text:T}]}}catch(f){return E.appendLine(`Error getting diagnostics: ${f}`),{content:[{type:"text",text:"[]"}],isError:!0}}}getSeverityString(d){switch(d){case s.MarkerSeverity.Error:return"error";case s.MarkerSeverity.Warning:return"warning";case s.MarkerSeverity.Info:return"information";case s.MarkerSeverity.Hint:return"hint";default:return"unknown"}}};t.GetOpenEditorFileDiagnosticsTool=h,n.__decorate([(0,a.Autowired)(v.WorkbenchEditorService),n.__metadata("design:type",v.WorkbenchEditorService)],h.prototype,"editorService",void 0),n.__decorate([(0,a.Autowired)(m.IWorkspaceService),n.__metadata("design:type",Object)],h.prototype,"workspaceService",void 0),n.__decorate([(0,a.Autowired)(s.IMarkerService),n.__metadata("design:type",Object)],h.prototype,"markerService",void 0),t.GetOpenEditorFileDiagnosticsTool=h=n.__decorate([(0,p.Domain)(g.MCPServerContribution)],h)},39855:(x,t,e)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.GrepSearchTool=void 0;const n=e(85608),r=e(75995),o=e(76003),a=e(43718),p=e(13439),v=e(51495),m=e(51500),_=e(19413),s=e(59347),g=e(77633),l=e(95292),h=r.z.object({query:r.z.string().describe("The regex pattern to search for"),case_sensitive:r.z.boolean().optional().describe("Whether the search should be case sensitive"),include_pattern:r.z.string().optional().describe('Glob pattern for files to include (e.g. "*.ts" for TypeScript files)'),exclude_pattern:r.z.string().optional().describe("Glob pattern for files to exclude"),explanation:r.z.string().optional().describe("One sentence explanation as to why this tool is being used, and how it contributes to the goal.")}),u=50;let d=class{registerMCPServer(f){f.registerMCPTool(this.getToolDefinition()),f.registerToolComponent("grep_search",l.GrepSearchToolComponent)}getToolDefinition(){return{name:"grep_search",label:"Search Contents",order:4,description:`Fast text-based regex search that finds exact pattern matches within files or directories, utilizing the ripgrep command for efficient searching.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opensumi/cli-engine",
3
- "version": "3.8.3-next-1747210131.0",
3
+ "version": "3.8.3-next-1747225210.0",
4
4
  "description": "Integration engine runtime for opensumi-cli and opensumi extension",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -26,14 +26,14 @@
26
26
  "dependencies": {
27
27
  "@koa/cors": "^5.0.0",
28
28
  "@opensumi/di": "^1.8.0",
29
- "@opensumi/ide-core-browser": "3.8.3-next-1747210131.0",
30
- "@opensumi/ide-core-common": "3.8.3-next-1747210131.0",
31
- "@opensumi/ide-core-node": "3.8.3-next-1747210131.0",
32
- "@opensumi/ide-express-file-server": "3.8.3-next-1747210131.0",
33
- "@opensumi/ide-extension": "3.8.3-next-1747210131.0",
34
- "@opensumi/ide-i18n": "3.8.3-next-1747210131.0",
35
- "@opensumi/ide-main-layout": "3.8.3-next-1747210131.0",
36
- "@opensumi/ide-startup": "3.8.3-next-1747210131.0",
29
+ "@opensumi/ide-core-browser": "3.8.3-next-1747225210.0",
30
+ "@opensumi/ide-core-common": "3.8.3-next-1747225210.0",
31
+ "@opensumi/ide-core-node": "3.8.3-next-1747225210.0",
32
+ "@opensumi/ide-express-file-server": "3.8.3-next-1747225210.0",
33
+ "@opensumi/ide-extension": "3.8.3-next-1747225210.0",
34
+ "@opensumi/ide-i18n": "3.8.3-next-1747225210.0",
35
+ "@opensumi/ide-main-layout": "3.8.3-next-1747225210.0",
36
+ "@opensumi/ide-startup": "3.8.3-next-1747225210.0",
37
37
  "chalk": "^4.1.2",
38
38
  "ejs": "^3.1.7",
39
39
  "ip": "^1.1.8",
@@ -72,5 +72,5 @@
72
72
  "webpack": "^5.90.0",
73
73
  "webpack-cli": "^5.1.4"
74
74
  },
75
- "gitHead": "45887cd2ac43a549560070e5125430833be57c98"
75
+ "gitHead": "2b710f598b75e5c1d5b9b954c2463fb5a4226258"
76
76
  }