@opensumi/cli-engine 3.8.3-next-1742183446.0 → 3.8.3-next-1742194253.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.
- package/lib/browser/browser.js +2 -2
- package/package.json +10 -10
package/lib/browser/browser.js
CHANGED
|
@@ -31031,9 +31031,9 @@ ${A.slice(1).join(`
|
|
|
31031
31031
|
`).slice(d.startPosition.row);return`${f[0].slice(d.startPosition.column)}${f.length>1?`
|
|
31032
31032
|
${f.slice(1).join(`
|
|
31033
31033
|
`)}`:""}`}}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=[],a=[];if(E)for(let b=0;b<E?.childCount;b++){const y=E.child(b);if(y?.type==="import_statement")f.push(y);else if(y?.type==="type_annotation"){const A=y.child(1);A&&a.push(A.text)}else if(y?.type==="lexical_declaration"){const A=this.findTypeIdentifier(y);A&&a.push(A)}}for(const b of f)if(a.some(y=>b.text.includes(y))){let y=(h=b.child(3))===null||h===void 0?void 0:h.text;(y?.includes("'")||y?.includes('"'))&&(y=y.slice(1,-1)),y&&u.push(y)}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 a=E.child(f);if(a?.type==="export_statement"){const b=a.child(1);(b?.type==="interface_declaration"||b?.type==="type_alias_declaration")&&u.push(b.text)}else(a?.type==="interface_declaration"||a?.type==="type_alias_declaration")&&u.push(a.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=a=>{(a.type==="function_declaration"||a.type==="class_declaration"||a.type==="variable_declarator"||a.type==="statement_block"||a.type==="expression_statement")&&(a.hasError||a.isMissing||a.type==="ERROR")&&E++;for(let y=0;y<a.childCount;y++){const A=a.child(y);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 b=l.split(`
|
|
31034
|
-
`).slice(0,f.startPosition.row).reduce((y,A)=>y+A.length,0);return b+=f.startPosition.row,b+=f.startPosition.column,{codeBlock:f.text,range:{start:{line:f.startPosition.row,character:0},end:{line:f.endPosition.row,character:1/0}},offset:b,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),c=e(22486);let p=class{constructor(){this.pool=new Map}createParser(m){const _=c.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(c){return n.has(c)}}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),c=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,c.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 c{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=c},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),c=e(6858),p=e(70392);let v=class{async resolveResourceUri(){const _=await this.rendererRuntime.provideResourceUri(c.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)(c.RendererRuntime),n.__metadata("design:type",c.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)),c=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:w}=o.default.useContext(h.TabbarConfig),T=(0,c.useInjectable)(u.TabbarServiceFactory)(w);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}))},a=({className:w,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)(w,`${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=a;const b=({className:w,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)(w,`${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=b;const y=({className:w,components:T})=>o.default.createElement(_.DesignLeftTabRenderer,{className:w,components:T,tabbarView:A});t.AILeftTabRenderer=y;const A=()=>{const w=(0,c.useInjectable)(s.IMainLayoutService),T=(0,c.useInjectable)(u.TabbarServiceFactory)(c.SlotLocation.right),D=(0,c.useAutorun)(T.currentContainerId),I=o.default.useMemo(()=>w.getExtraMenu(),[w]),[O]=(0,c.useContextMenus)(I),M=(0,o.useCallback)(({renderContainers:R})=>{const P=T.visibleContainers.filter(k=>{var F;return!(!((F=k.options)===null||F===void 0)&&F.hideTab)});return o.default.createElement(o.default.Fragment,null,P.length>0&&o.default.createElement(p.HorizontalVertical,{margin:"8px auto 0px",width:"60%"}),P.map(k=>R(k,T,D)))},[D,T]);return o.default.createElement(g.LeftTabbarRenderer,{renderOtherVisibleContainers:M,isRenderExtraTopMenus:!1,renderExtraMenus:o.default.createElement("div",{className:E.default.extra_bottom_icon_container},O.length>=0?O.map(R=>o.default.createElement(p.EnhanceIconWithCtxMenu,{key:R.id,id:R.id,wrapperClassName:E.default.extra_bottom_icon,iconClass:R.icon,menuNodes:R.children,skew:{x:-8,y:-4}})):null)})},S=({className:w,components:T})=>{const D=(0,c.useInjectable)(u.TabbarServiceFactory)(c.SlotLocation.right),I=(0,c.useInjectable)(v.DesignLayoutConfig),O=(0,o.useCallback)(()=>{D.updateCurrentContainerId("")},[]),M=(0,o.useCallback)(P=>{const{component:k}=P,{options:F}=k;return o.default.createElement(l.ContainerView,{...P,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:O})))),renderContainerWrap:({children:L})=>o.default.createElement("div",{className:E.default.right_slot_container_wrap},o.default.createElement("div",{className:E.default.container},L))})},[]),R=(0,o.useMemo)(()=>I.useMergeRightWithLeftPanel?E.default.right_tab_renderer:"",[I]);return o.default.createElement(_.DesignRightTabRenderer,{components:T,className:R,tabbarView:()=>o.default.createElement(g.RightTabbarRenderer,{barSize:0,style:{width:0}}),tabpanelView:()=>o.default.createElement(l.BaseTabPanelView,{PanelView:M})})};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),c=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(c.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),c=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 c.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 a=this.chatInternalService.sessionModel.history.lastMessageId;if(!a)return;const b=this.getMessageCodeBlocks(a);b&&Object.values(b).forEach(y=>{this.cancelApply(y)})})),this.currentSessionId=this.chatInternalService.sessionModel.sessionId,this.addDispose(this.chatInternalService.onChangeSession(a=>{a!==this.currentSessionId&&(this.cancelAllApply(),this.currentSessionId=a)})),this.addDispose(this.chatInternalService.onRegenerateRequest(()=>{const a=this.chatInternalService.sessionModel.history.getMessages(),b=a[a.length-1].id,y=this.getMessageCodeBlocks(b);y&&Object.values(y).forEach(A=>{this.cancelApply(A)})})),this.addDispose(this.chatInternalService.onWillClearSession(a=>{this.cancelAllApply(a)}))}getMessageCodeBlocks(a,b){b=b||this.chatInternalService.sessionModel.sessionId;const y=this.chatInternalService.getSession(b);if(!y)throw new Error(`Session ${b} not found`);const A=y.history.getMessageAdditional(a);return A?.codeBlockMap}onEditorGroupClose(a){const b=s.path.relative(this.appConfig.workspaceDir,a.payload.resource.uri.path.toString());this.activePreviewerMap.get(b)&&this.activePreviewerMap.disposeKey(b),this.editorListenerMap.disposeKey(a.payload.resource.uri.toString())}async onEditorGroupOpen(a){var b;const y=s.path.relative(this.appConfig.workspaceDir,a.payload.resource.uri.path.toString());if(this.duringApply||this.activePreviewerMap.has(y)||!this.chatInternalService.sessionModel.history.getMessages().length)return;const A=((b=this.getUriCodeBlocks(a.payload.resource.uri))===null||b===void 0?void 0:b.filter(S=>S.status==="pending"))||[];if(A.length>0&&A[0].updatedCode){const S=a.payload.group.codeEditor.monacoEditor;await this.renderApplyResult(S,A[0],A[0].updatedCode)}}get currentPreviewer(){var a;const b=(a=this.editorService.currentEditor)===null||a===void 0?void 0:a.currentUri;if(b)return this.activePreviewerMap.get(s.path.relative(this.appConfig.workspaceDir,b.path.toString()))}getUriCodeBlocks(a){const b=this.getSessionCodeBlocks(),y=s.path.relative(this.appConfig.workspaceDir,a.path.toString());return b.filter(A=>A.relativePath===y).sort((A,S)=>S.version-A.version)}getPendingPaths(a){return this.getSessionCodeBlocks(a).filter(y=>y.status==="pending").map(y=>y.relativePath)}getSessionCodeBlocks(a){const b=a?this.chatInternalService.getSession(a):this.chatInternalService.sessionModel;if(!b)throw new Error(`Session ${a} not found`);const y=b.history.sessionAdditionals;return Array.from(y.values()).map(A=>A.codeBlockMap||{}).reduce((A,S)=>(Object.values(S).forEach(w=>{A.push(w)}),A),[])}getCodeBlock(a,b){if(b=b||this.chatInternalService.sessionModel.history.lastMessageId,!b)throw new Error("Message ID is required");const y=this.getMessageCodeBlocks(b);if(y)return y[a]}updateCodeBlock(a){const b=a.messageId,y=this.getMessageCodeBlocks(b);if(!y)throw new Error("Code block not found");y[a.toolCallId]=a,this.chatInternalService.sessionModel.history.setMessageAdditional(b,{codeBlockMap:y}),this.onCodeBlockUpdateEmitter.fire(a)}async registerCodeBlock(a,b,y,A){var S,w;const T=this.chatInternalService.sessionModel.history.lastMessageId,D=this.getUriCodeBlocks(s.URI.file(s.path.join(this.appConfig.workspaceDir,a))),I=await this.editorDocumentModelService.createModelReference(s.URI.file(s.path.join(this.appConfig.workspaceDir,a))),O={codeEdit:b,relativePath:a,status:"generating",iterationCount:1,version:1,createdAt:Date.now(),toolCallId:y,messageId:T,instructions:A,originalCode:I.instance.getText()};if(D?.length){O.version=D.length+1;for(const R of D)if(R.relativePath===a&&(!((w=(S=R.applyResult)===null||S===void 0?void 0:S.diagnosticInfos)===null||w===void 0)&&w.length))O.iterationCount++;else break}const M=this.getMessageCodeBlocks(T)||{};return M[y]=O,this.chatInternalService.sessionModel.history.setMessageAdditional(T,{codeBlockMap:M}),this.onCodeBlockUpdateEmitter.fire(O),O}async apply(a){try{if(this.duringApply=!0,a.iterationCount>3)throw new Error("Lint error max iteration count exceeded");const b=a.originalCode?await this.doApply(a):{result:a.codeEdit};if(!b.stream&&!b.result)throw new Error("No apply content provided");this.activePreviewerMap.has(a.relativePath)&&this.cancelApply(a,!0);const y=await this.editorService.open(s.URI.file(s.path.join(this.appConfig.workspaceDir,a.relativePath)));if(!y)throw new Error("Failed to open file");const A=await this.renderApplyResult(y.group.codeEditor.monacoEditor,a,b.result||b.stream,b.range);return a.updatedCode=A.updatedCode,a.status="pending",a.applyResult=A.result,this.updateCodeBlock(a),a}catch(b){throw a.status="failed",this.updateCodeBlock(a),b}finally{this.duringApply=!1}}async renderApplyResult(a,b,y,A){var S,w,T;const D=new s.Deferred,I=d.InlineDiffController.get(a);if(A=A||a.getModel().getFullModelRange(),typeof y=="string"){const O=y,M=a.getModel().getValue(),R=s.URI.file(s.path.join(this.appConfig.workspaceDir,b.relativePath)),P=this.editorDocumentModelService.getModelReference(R);(M!==O||P?.instance.dirty)&&((S=a.getModel())===null||S===void 0||S.pushEditOperations([],[g.EditOperation.replace(A,O)],()=>null),await this.editorService.save(R));const k=(w=this.getUriCodeBlocks(R))===null||w===void 0?void 0:w.filter(U=>U.status==="pending"),F=k?.[k.length-1];if(((T=F||b)===null||T===void 0?void 0:T.originalCode)===O)throw new Error("No changes applied");const L=I.createDiffPreviewer(a,_.Selection.fromRange(A,_.SelectionDirection.LTR),{disposeWhenEditorClosed:!0,renderRemovedWidgetImmediately:!0,reverse:!0});this.activePreviewerMap.set(b.relativePath,L),L.setValue(F?.originalCode||b.originalCode||`
|
|
31034
|
+
`).slice(0,f.startPosition.row).reduce((y,A)=>y+A.length,0);return b+=f.startPosition.row,b+=f.startPosition.column,{codeBlock:f.text,range:{start:{line:f.startPosition.row,character:0},end:{line:f.endPosition.row,character:1/0}},offset:b,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),c=e(22486);let p=class{constructor(){this.pool=new Map}createParser(m){const _=c.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(c){return n.has(c)}}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),c=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,c.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 c{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=c},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),c=e(6858),p=e(70392);let v=class{async resolveResourceUri(){const _=await this.rendererRuntime.provideResourceUri(c.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)(c.RendererRuntime),n.__metadata("design:type",c.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)),c=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:w}=o.default.useContext(h.TabbarConfig),T=(0,c.useInjectable)(u.TabbarServiceFactory)(w);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}))},a=({className:w,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)(w,`${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=a;const b=({className:w,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)(w,`${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=b;const y=({className:w,components:T})=>o.default.createElement(_.DesignLeftTabRenderer,{className:w,components:T,tabbarView:A});t.AILeftTabRenderer=y;const A=()=>{const w=(0,c.useInjectable)(s.IMainLayoutService),T=(0,c.useInjectable)(u.TabbarServiceFactory)(c.SlotLocation.right),D=(0,c.useAutorun)(T.currentContainerId),I=o.default.useMemo(()=>w.getExtraMenu(),[w]),[O]=(0,c.useContextMenus)(I),M=(0,o.useCallback)(({renderContainers:R})=>{const P=T.visibleContainers.filter(k=>{var F;return!(!((F=k.options)===null||F===void 0)&&F.hideTab)});return o.default.createElement(o.default.Fragment,null,P.length>0&&o.default.createElement(p.HorizontalVertical,{margin:"8px auto 0px",width:"60%"}),P.map(k=>R(k,T,D)))},[D,T]);return o.default.createElement(g.LeftTabbarRenderer,{renderOtherVisibleContainers:M,isRenderExtraTopMenus:!1,renderExtraMenus:o.default.createElement("div",{className:E.default.extra_bottom_icon_container},O.length>=0?O.map(R=>o.default.createElement(p.EnhanceIconWithCtxMenu,{key:R.id,id:R.id,wrapperClassName:E.default.extra_bottom_icon,iconClass:R.icon,menuNodes:R.children,skew:{x:-8,y:-4}})):null)})},S=({className:w,components:T})=>{const D=(0,c.useInjectable)(u.TabbarServiceFactory)(c.SlotLocation.right),I=(0,c.useInjectable)(v.DesignLayoutConfig),O=(0,o.useCallback)(()=>{D.updateCurrentContainerId("")},[]),M=(0,o.useCallback)(P=>{const{component:k}=P,{options:F}=k;return o.default.createElement(l.ContainerView,{...P,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:O})))),renderContainerWrap:({children:L})=>o.default.createElement("div",{className:E.default.right_slot_container_wrap},o.default.createElement("div",{className:E.default.container},L))})},[]),R=(0,o.useMemo)(()=>I.useMergeRightWithLeftPanel?E.default.right_tab_renderer:"",[I]);return o.default.createElement(_.DesignRightTabRenderer,{components:T,className:R,tabbarView:()=>o.default.createElement(g.RightTabbarRenderer,{barSize:0,style:{width:0}}),tabpanelView:()=>o.default.createElement(l.BaseTabPanelView,{PanelView:M})})};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),c=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(c.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),c=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 c.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 a=this.chatInternalService.sessionModel.history.lastMessageId;if(!a)return;const b=this.getMessageCodeBlocks(a);b&&Object.values(b).forEach(y=>{this.cancelApply(y)})})),this.currentSessionId=this.chatInternalService.sessionModel.sessionId,this.addDispose(this.chatInternalService.onChangeSession(a=>{a!==this.currentSessionId&&(this.cancelAllApply(),this.currentSessionId=a)})),this.addDispose(this.chatInternalService.onRegenerateRequest(()=>{const a=this.chatInternalService.sessionModel.history.getMessages(),b=a[a.length-1].id,y=this.getMessageCodeBlocks(b);y&&Object.values(y).forEach(A=>{this.cancelApply(A)})})),this.addDispose(this.chatInternalService.onWillClearSession(a=>{this.cancelAllApply(a)}))}getMessageCodeBlocks(a,b){b=b||this.chatInternalService.sessionModel.sessionId;const y=this.chatInternalService.getSession(b);if(!y)throw new Error(`Session ${b} not found`);const A=y.history.getMessageAdditional(a);return A?.codeBlockMap}onEditorGroupClose(a){const b=s.path.relative(this.appConfig.workspaceDir,a.payload.resource.uri.path.toString());this.activePreviewerMap.get(b)&&this.activePreviewerMap.disposeKey(b),this.editorListenerMap.disposeKey(a.payload.resource.uri.toString())}async onEditorGroupOpen(a){var b;const y=s.path.relative(this.appConfig.workspaceDir,a.payload.resource.uri.path.toString());if(this.duringApply||this.activePreviewerMap.has(y)||!this.chatInternalService.sessionModel.history.getMessages().length)return;const A=((b=this.getUriCodeBlocks(a.payload.resource.uri))===null||b===void 0?void 0:b.filter(S=>S.status==="pending"))||[];if(A.length>0&&A[0].updatedCode){const S=a.payload.group.codeEditor.monacoEditor;await this.renderApplyResult(S,A[0],A[0].updatedCode)}}get currentPreviewer(){var a;const b=(a=this.editorService.currentEditor)===null||a===void 0?void 0:a.currentUri;if(b)return this.activePreviewerMap.get(s.path.relative(this.appConfig.workspaceDir,b.path.toString()))}getUriCodeBlocks(a){const b=this.getSessionCodeBlocks(),y=s.path.relative(this.appConfig.workspaceDir,a.path.toString());return b.filter(A=>A.relativePath===y).sort((A,S)=>S.version-A.version)}getPendingPaths(a){return this.getSessionCodeBlocks(a).filter(y=>y.status==="pending").map(y=>y.relativePath)}getSessionCodeBlocks(a){const b=a?this.chatInternalService.getSession(a):this.chatInternalService.sessionModel;if(!b)throw new Error(`Session ${a} not found`);const y=b.history.sessionAdditionals;return Array.from(y.values()).map(A=>A.codeBlockMap||{}).reduce((A,S)=>(Object.values(S).forEach(w=>{A.push(w)}),A),[])}getCodeBlock(a,b){if(b=b||this.chatInternalService.sessionModel.history.lastMessageId,!b)throw new Error("Message ID is required");const y=this.getMessageCodeBlocks(b);if(y)return y[a]}updateCodeBlock(a){const b=a.messageId,y=this.getMessageCodeBlocks(b);if(!y)throw new Error("Code block not found");y[a.toolCallId]=a,this.chatInternalService.sessionModel.history.setMessageAdditional(b,{codeBlockMap:y}),this.onCodeBlockUpdateEmitter.fire(a)}async registerCodeBlock(a,b,y,A){var S,w;const T=this.chatInternalService.sessionModel.history.lastMessageId,D=this.getUriCodeBlocks(s.URI.file(s.path.join(this.appConfig.workspaceDir,a))),I=await this.editorDocumentModelService.createModelReference(s.URI.file(s.path.join(this.appConfig.workspaceDir,a))),O={codeEdit:b,relativePath:a,status:"generating",iterationCount:1,version:1,createdAt:Date.now(),toolCallId:y,messageId:T,instructions:A,originalCode:I.instance.getText()};if(D?.length){O.version=D.length+1;for(const R of D)if(R.relativePath===a&&(!((w=(S=R.applyResult)===null||S===void 0?void 0:S.diagnosticInfos)===null||w===void 0)&&w.length))O.iterationCount++;else break}const M=this.getMessageCodeBlocks(T)||{};return M[y]=O,this.chatInternalService.sessionModel.history.setMessageAdditional(T,{codeBlockMap:M}),this.onCodeBlockUpdateEmitter.fire(O),O}async apply(a){try{if(this.duringApply=!0,a.iterationCount>3)throw new Error("Lint error max iteration count exceeded");const b=a.originalCode?await this.doApply(a):{result:a.codeEdit};if(!b.stream&&!b.result)throw new Error("No apply content provided");this.activePreviewerMap.has(a.relativePath)&&(this.editorListenerMap.disposeKey(s.URI.file(s.path.join(this.appConfig.workspaceDir,a.relativePath)).toString()),this.activePreviewerMap.disposeKey(a.relativePath));const y=await this.editorService.open(s.URI.file(s.path.join(this.appConfig.workspaceDir,a.relativePath)));if(!y)throw new Error("Failed to open file");const A=await this.renderApplyResult(y.group.codeEditor.monacoEditor,a,b.result||b.stream,b.range);return a.updatedCode=A.updatedCode,a.status="pending",a.applyResult=A.result,this.updateCodeBlock(a),a}catch(b){throw a.status="failed",this.updateCodeBlock(a),b}finally{this.duringApply=!1}}async renderApplyResult(a,b,y,A){var S,w,T;const D=new s.Deferred,I=d.InlineDiffController.get(a);if(A=A||a.getModel().getFullModelRange(),typeof y=="string"){const O=y,M=a.getModel().getValue(),R=s.URI.file(s.path.join(this.appConfig.workspaceDir,b.relativePath)),P=this.editorDocumentModelService.getModelReference(R);(M!==O||P?.instance.dirty)&&((S=a.getModel())===null||S===void 0||S.pushEditOperations([],[g.EditOperation.replace(A,O)],()=>null),await this.editorService.save(R));const k=(w=this.getUriCodeBlocks(R))===null||w===void 0?void 0:w.filter(U=>U.status==="pending"),F=k?.[k.length-1];if(((T=F||b)===null||T===void 0?void 0:T.originalCode)===O)throw new Error("No changes applied");const L=I.createDiffPreviewer(a,_.Selection.fromRange(A,_.SelectionDirection.LTR),{disposeWhenEditorClosed:!0,renderRemovedWidgetImmediately:!0,reverse:!0});this.activePreviewerMap.set(b.relativePath,L),L.setValue(F?.originalCode||b.originalCode||`
|
|
31035
31035
|
`),this.eventBus.fire(new v.RegisterEditorSideComponentEvent),this.listenPartialEdit(a.getModel(),b).then(U=>{U&&(b.applyResult=U),this.updateCodeBlock(b),this.editorService.save(s.URI.file(s.path.join(this.appConfig.workspaceDir,b.relativePath)))});const{diff:B,rangesFromDiffHunk:j}=this.getDiffResult(b.originalCode,O,b.relativePath),W=this.getDiagnosticInfos(a.getModel().uri.toString(),j);D.resolve({result:{diff:B,diagnosticInfos:W},updatedCode:O})}else{const O=new u.InlineChatController;O.mountReadable(y);const M=I.showPreviewerByStream(a,{crossSelection:_.Selection.fromRange(A,_.SelectionDirection.LTR),chatResponse:O,previewerOptions:{disposeWhenEditorClosed:!0,renderRemovedWidgetImmediately:!1}});this.addDispose(O.onError(R=>{D.reject(R)})),this.addDispose(O.onAbort(()=>{D.reject(new Error("Apply aborted"))})),this.addDispose(M.getNode().onDiffFinished(async R=>{const P=R.newFullRangeTextLines.join(`
|
|
31036
|
-
`);if(b.originalCode===P){M.dispose(),D.reject(new Error("no changes applied"));return}M.dispose();try{const k=await this.renderApplyResult(a,b,P);D.resolve(k)}catch(k){D.reject(k)}})),this.activePreviewerMap.set(b.relativePath,M)}return D.promise}cancelApply(a,b){var y,A;(a.status==="generating"||a.status==="pending")&&(this.editorListenerMap.disposeKey(s.URI.file(s.path.join(this.appConfig.workspaceDir,a.relativePath)).toString()),this.activePreviewerMap.has(a.relativePath)&&((A=(y=this.activePreviewerMap.get(a.relativePath))===null||y===void 0?void 0:y.getNode())===null||A===void 0||A.livePreviewDiffDecorationModel.discardUnProcessed(),this.activePreviewerMap.disposeKey(a.relativePath)),
|
|
31036
|
+
`);if(b.originalCode===P){M.dispose(),D.reject(new Error("no changes applied"));return}M.dispose();try{const k=await this.renderApplyResult(a,b,P);D.resolve(k)}catch(k){D.reject(k)}})),this.activePreviewerMap.set(b.relativePath,M)}return D.promise}cancelApply(a,b){var y,A;(a.status==="generating"||a.status==="pending")&&(this.editorListenerMap.disposeKey(s.URI.file(s.path.join(this.appConfig.workspaceDir,a.relativePath)).toString()),this.activePreviewerMap.has(a.relativePath)&&((A=(y=this.activePreviewerMap.get(a.relativePath))===null||y===void 0?void 0:y.getNode())===null||A===void 0||A.livePreviewDiffDecorationModel.discardUnProcessed(),this.activePreviewerMap.disposeKey(a.relativePath)),a.status="cancelled",this.updateCodeBlock(a))}cancelAllApply(a){this.getSessionCodeBlocks(a).forEach(y=>{this.cancelApply(y)})}revealApplyPosition(a){var b;const y=(b=a.applyResult)===null||b===void 0?void 0:b.diff.split(`
|
|
31037
31037
|
`).find(T=>T.startsWith("@@"));let A=0,S=0;if(y){const[,,,T,D]=y.match(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);A=parseInt(T,10)-1,S=parseInt(D,10)-1}this.editorService.open(s.URI.file(s.path.join(this.appConfig.workspaceDir,a.relativePath)));const w=this.editorService.currentEditor;w&&w.setSelection(new _.Selection(A,0,S,0))}async processAll(a,b){var y;const A=b?(y=this.getUriCodeBlocks(b))===null||y===void 0?void 0:y.filter(D=>D.status==="pending"):this.getSessionCodeBlocks().filter(D=>D.status==="pending");if(!A?.length)throw new Error("No pending code block found");const S=b?[A[0].relativePath]:A.map(D=>D.relativePath).reduce((D,I)=>(D.includes(I)||D.push(I),D),[]),w=this.editorService.getAllOpenedUris(),T=S.filter(D=>!w.some(I=>I.codeUri.fsPath.endsWith(D))).map(D=>s.URI.file(s.path.join(this.appConfig.workspaceDir,D)));T.length&&await this.editorService.openUris(T),S.forEach(D=>{this.doProcess(a,D)}),A.forEach(D=>{D.status=a==="accept"?"success":"cancelled",this.updateCodeBlock(D)})}doProcess(a,b){var y,A;const S=(A=(y=this.activePreviewerMap.get(b))===null||y===void 0?void 0:y.getNode())===null||A===void 0?void 0:A.livePreviewDiffDecorationModel;if(!S)throw new Error("No active previewer found");a==="accept"?S.acceptUnProcessed():S.discardUnProcessed(),this.editorService.save(s.URI.file(s.path.join(this.appConfig.workspaceDir,b)))}listenPartialEdit(a,b){const y=new s.Deferred,A=a.uri.toString(),S=this.inlineDiffService.onPartialEdit(w=>{if(w.totalPartialEditCount===w.resolvedPartialEditCount&&w.uri.path===a.uri.path.toString()){if(w.acceptPartialEditCount>0){b.status="success";const T=a.getValue(),{diff:D,rangesFromDiffHunk:I}=this.getDiffResult(b.originalCode,T,b.relativePath),O=this.getDiagnosticInfos(a.uri.toString(),I);this.aiReporter.send({msgType:c.AIServiceType.Chat,actionType:c.ActionTypeEnum.Accept,actionSource:c.ActionSourceEnum.Chat,sessionId:this.chatInternalService.sessionModel.sessionId,isReceive:!0,isDrop:w.acceptPartialEditCount!==w.totalPartialEditCount,code:T,originCode:b.originalCode,message:JSON.stringify({diff:D,diagnosticInfos:O,instructions:b.instructions,codeEdit:b.codeEdit,partialEditCount:w.totalPartialEditCount,acceptPartialEditCount:w.acceptPartialEditCount,addedLinesCount:w.totalAddedLinesCount,deletedLinesCount:w.totalDeletedLinesCount})}),y.resolve({diff:D,diagnosticInfos:O})}else b.status="cancelled",y.resolve(),this.aiReporter.send({msgType:c.AIServiceType.Chat,actionType:c.ActionTypeEnum.Discard,actionSource:c.ActionSourceEnum.Chat,sessionId:this.chatInternalService.sessionModel.sessionId,isReceive:!1,isDrop:!0,originCode:b.originalCode,message:JSON.stringify({instructions:b.instructions,codeEdit:b.codeEdit})});this.editorListenerMap.disposeKey(A)}});return this.editorListenerMap.set(A,S),y.promise}getDiffResult(a,b,y){const A=(0,r.createPatch)(y,a,b).split(`
|
|
31038
31038
|
`).slice(4).join(`
|
|
31039
31039
|
`),S=A.split(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/cli-engine",
|
|
3
|
-
"version": "3.8.3-next-
|
|
3
|
+
"version": "3.8.3-next-1742194253.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-
|
|
30
|
-
"@opensumi/ide-core-common": "3.8.3-next-
|
|
31
|
-
"@opensumi/ide-core-node": "3.8.3-next-
|
|
32
|
-
"@opensumi/ide-express-file-server": "3.8.3-next-
|
|
33
|
-
"@opensumi/ide-extension": "3.8.3-next-
|
|
34
|
-
"@opensumi/ide-i18n": "3.8.3-next-
|
|
35
|
-
"@opensumi/ide-main-layout": "3.8.3-next-
|
|
36
|
-
"@opensumi/ide-startup": "3.8.3-next-
|
|
29
|
+
"@opensumi/ide-core-browser": "3.8.3-next-1742194253.0",
|
|
30
|
+
"@opensumi/ide-core-common": "3.8.3-next-1742194253.0",
|
|
31
|
+
"@opensumi/ide-core-node": "3.8.3-next-1742194253.0",
|
|
32
|
+
"@opensumi/ide-express-file-server": "3.8.3-next-1742194253.0",
|
|
33
|
+
"@opensumi/ide-extension": "3.8.3-next-1742194253.0",
|
|
34
|
+
"@opensumi/ide-i18n": "3.8.3-next-1742194253.0",
|
|
35
|
+
"@opensumi/ide-main-layout": "3.8.3-next-1742194253.0",
|
|
36
|
+
"@opensumi/ide-startup": "3.8.3-next-1742194253.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": "
|
|
75
|
+
"gitHead": "a8d790bc8a5c024acdc088b9d87c66c7f6870bfa"
|
|
76
76
|
}
|