@opensumi/ide-ai-native 2.26.9-rc-1695091570.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/LICENSE +21 -0
- package/lib/browser/ai-chat.contribution.d.ts +26 -0
- package/lib/browser/ai-chat.contribution.d.ts.map +1 -0
- package/lib/browser/ai-chat.contribution.js +227 -0
- package/lib/browser/ai-chat.contribution.js.map +1 -0
- package/lib/browser/ai-chat.module.less +174 -0
- package/lib/browser/ai-chat.service.d.ts +30 -0
- package/lib/browser/ai-chat.service.d.ts.map +1 -0
- package/lib/browser/ai-chat.service.js +134 -0
- package/lib/browser/ai-chat.service.js.map +1 -0
- package/lib/browser/ai-chat.view.d.ts +4 -0
- package/lib/browser/ai-chat.view.d.ts.map +1 -0
- package/lib/browser/ai-chat.view.js +305 -0
- package/lib/browser/ai-chat.view.js.map +1 -0
- package/lib/browser/ai-editor.contribution.d.ts +24 -0
- package/lib/browser/ai-editor.contribution.d.ts.map +1 -0
- package/lib/browser/ai-editor.contribution.js +419 -0
- package/lib/browser/ai-editor.contribution.js.map +1 -0
- package/lib/browser/ai-project/generate.service.d.ts +31 -0
- package/lib/browser/ai-project/generate.service.d.ts.map +1 -0
- package/lib/browser/ai-project/generate.service.js +453 -0
- package/lib/browser/ai-project/generate.service.js.map +1 -0
- package/lib/browser/ai-sumi/sumi.service.d.ts +11 -0
- package/lib/browser/ai-sumi/sumi.service.d.ts.map +1 -0
- package/lib/browser/ai-sumi/sumi.service.js +64 -0
- package/lib/browser/ai-sumi/sumi.service.js.map +1 -0
- package/lib/browser/code-widget/ai-code-document.provider.d.ts +10 -0
- package/lib/browser/code-widget/ai-code-document.provider.d.ts.map +1 -0
- package/lib/browser/code-widget/ai-code-document.provider.js +26 -0
- package/lib/browser/code-widget/ai-code-document.provider.js.map +1 -0
- package/lib/browser/code-widget/ai-code-widget.d.ts +20 -0
- package/lib/browser/code-widget/ai-code-widget.d.ts.map +1 -0
- package/lib/browser/code-widget/ai-code-widget.js +164 -0
- package/lib/browser/code-widget/ai-code-widget.js.map +1 -0
- package/lib/browser/components/AIImprove.d.ts +9 -0
- package/lib/browser/components/AIImprove.d.ts.map +1 -0
- package/lib/browser/components/AIImprove.js +34 -0
- package/lib/browser/components/AIImprove.js.map +1 -0
- package/lib/browser/components/AIInput.d.ts +5 -0
- package/lib/browser/components/AIInput.d.ts.map +1 -0
- package/lib/browser/components/AIInput.js +21 -0
- package/lib/browser/components/AIInput.js.map +1 -0
- package/lib/browser/components/ChatEditor.d.ts +5 -0
- package/lib/browser/components/ChatEditor.d.ts.map +1 -0
- package/lib/browser/components/ChatEditor.js +85 -0
- package/lib/browser/components/ChatEditor.js.map +1 -0
- package/lib/browser/components/ChatInput.d.ts +6 -0
- package/lib/browser/components/ChatInput.d.ts.map +1 -0
- package/lib/browser/components/ChatInput.js +127 -0
- package/lib/browser/components/ChatInput.js.map +1 -0
- package/lib/browser/components/ChatMoreActions.d.ts +5 -0
- package/lib/browser/components/ChatMoreActions.d.ts.map +1 -0
- package/lib/browser/components/ChatMoreActions.js +26 -0
- package/lib/browser/components/ChatMoreActions.js.map +1 -0
- package/lib/browser/components/Thinking.d.ts +3 -0
- package/lib/browser/components/Thinking.d.ts.map +1 -0
- package/lib/browser/components/Thinking.js +19 -0
- package/lib/browser/components/Thinking.js.map +1 -0
- package/lib/browser/components/components.module.less +259 -0
- package/lib/browser/components/lineVertical.d.ts +4 -0
- package/lib/browser/components/lineVertical.d.ts.map +1 -0
- package/lib/browser/components/lineVertical.js +22 -0
- package/lib/browser/components/lineVertical.js.map +1 -0
- package/lib/browser/content-widget/ai-content-widget.d.ts +38 -0
- package/lib/browser/content-widget/ai-content-widget.d.ts.map +1 -0
- package/lib/browser/content-widget/ai-content-widget.js +97 -0
- package/lib/browser/content-widget/ai-content-widget.js.map +1 -0
- package/lib/browser/content-widget/ai-inline-chat-panel.d.ts +6 -0
- package/lib/browser/content-widget/ai-inline-chat-panel.d.ts.map +1 -0
- package/lib/browser/content-widget/ai-inline-chat-panel.js +108 -0
- package/lib/browser/content-widget/ai-inline-chat-panel.js.map +1 -0
- package/lib/browser/content-widget/ai-inline-chat.module.less +74 -0
- package/lib/browser/content-widget/ai-inline-chat.service.d.ts +23 -0
- package/lib/browser/content-widget/ai-inline-chat.service.d.ts.map +1 -0
- package/lib/browser/content-widget/ai-inline-chat.service.js +47 -0
- package/lib/browser/content-widget/ai-inline-chat.service.js.map +1 -0
- package/lib/browser/diff-widget/ai-diff-document.provider.d.ts +10 -0
- package/lib/browser/diff-widget/ai-diff-document.provider.d.ts.map +1 -0
- package/lib/browser/diff-widget/ai-diff-document.provider.js +26 -0
- package/lib/browser/diff-widget/ai-diff-document.provider.js.map +1 -0
- package/lib/browser/diff-widget/ai-diff-widget.d.ts +20 -0
- package/lib/browser/diff-widget/ai-diff-widget.d.ts.map +1 -0
- package/lib/browser/diff-widget/ai-diff-widget.js +158 -0
- package/lib/browser/diff-widget/ai-diff-widget.js.map +1 -0
- package/lib/browser/index.d.ts +12 -0
- package/lib/browser/index.d.ts.map +1 -0
- package/lib/browser/index.js +84 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/inline-completions/constants.d.ts +62 -0
- package/lib/browser/inline-completions/constants.d.ts.map +1 -0
- package/lib/browser/inline-completions/constants.js +69 -0
- package/lib/browser/inline-completions/constants.js.map +1 -0
- package/lib/browser/inline-completions/provider.d.ts +27 -0
- package/lib/browser/inline-completions/provider.d.ts.map +1 -0
- package/lib/browser/inline-completions/provider.js +63 -0
- package/lib/browser/inline-completions/provider.js.map +1 -0
- package/lib/browser/override/ai-editor-tab.service.d.ts +6 -0
- package/lib/browser/override/ai-editor-tab.service.d.ts.map +1 -0
- package/lib/browser/override/ai-editor-tab.service.js +22 -0
- package/lib/browser/override/ai-editor-tab.service.js.map +1 -0
- package/lib/browser/override/ai-marker.service.d.ts +11 -0
- package/lib/browser/override/ai-marker.service.d.ts.map +1 -0
- package/lib/browser/override/ai-marker.service.js +55 -0
- package/lib/browser/override/ai-marker.service.js.map +1 -0
- package/lib/browser/override/global.styles.less +268 -0
- package/lib/browser/override/layout/layout-config.d.ts +6 -0
- package/lib/browser/override/layout/layout-config.d.ts.map +1 -0
- package/lib/browser/override/layout/layout-config.js +17 -0
- package/lib/browser/override/layout/layout-config.js.map +1 -0
- package/lib/browser/override/layout/layout.module.less +7 -0
- package/lib/browser/override/layout/main-slot-renderer.d.ts +4 -0
- package/lib/browser/override/layout/main-slot-renderer.d.ts.map +1 -0
- package/lib/browser/override/layout/main-slot-renderer.js +22 -0
- package/lib/browser/override/layout/main-slot-renderer.js.map +1 -0
- package/lib/browser/override/layout/menu-bar/menu-bar.contribution.d.ts +8 -0
- package/lib/browser/override/layout/menu-bar/menu-bar.contribution.d.ts.map +1 -0
- package/lib/browser/override/layout/menu-bar/menu-bar.contribution.js +32 -0
- package/lib/browser/override/layout/menu-bar/menu-bar.contribution.js.map +1 -0
- package/lib/browser/override/layout/menu-bar/menu-bar.module.less +41 -0
- package/lib/browser/override/layout/menu-bar/menu-bar.view.d.ts +3 -0
- package/lib/browser/override/layout/menu-bar/menu-bar.view.d.ts.map +1 -0
- package/lib/browser/override/layout/menu-bar/menu-bar.view.js +62 -0
- package/lib/browser/override/layout/menu-bar/menu-bar.view.js.map +1 -0
- package/lib/browser/override/layout/tabbar.view.d.ts +17 -0
- package/lib/browser/override/layout/tabbar.view.d.ts.map +1 -0
- package/lib/browser/override/layout/tabbar.view.js +38 -0
- package/lib/browser/override/layout/tabbar.view.js.map +1 -0
- package/lib/browser/override/override.module.less +32 -0
- package/lib/browser/override/theme/default-theme.d.ts +315 -0
- package/lib/browser/override/theme/default-theme.d.ts.map +1 -0
- package/lib/browser/override/theme/default-theme.js +821 -0
- package/lib/browser/override/theme/default-theme.js.map +1 -0
- package/lib/browser/run/run.service.d.ts +52 -0
- package/lib/browser/run/run.service.d.ts.map +1 -0
- package/lib/browser/run/run.service.js +176 -0
- package/lib/browser/run/run.service.js.map +1 -0
- package/lib/common/command.d.ts +17 -0
- package/lib/common/command.d.ts.map +1 -0
- package/lib/common/command.js +21 -0
- package/lib/common/command.js.map +1 -0
- package/lib/common/index.d.ts +37 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +22 -0
- package/lib/common/index.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/node/index.d.ts +10 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +32 -0
- package/lib/node/index.js.map +1 -0
- package/package.json +38 -0
- package/src/browser/ai-chat.contribution.ts +294 -0
- package/src/browser/ai-chat.module.less +174 -0
- package/src/browser/ai-chat.service.ts +152 -0
- package/src/browser/ai-chat.view.tsx +421 -0
- package/src/browser/ai-editor.contribution.ts +521 -0
- package/src/browser/ai-project/generate.service.ts +505 -0
- package/src/browser/ai-sumi/sumi.service.ts +65 -0
- package/src/browser/code-widget/ai-code-document.provider.ts +22 -0
- package/src/browser/code-widget/ai-code-widget.tsx +202 -0
- package/src/browser/components/AIImprove.tsx +45 -0
- package/src/browser/components/AIInput.tsx +30 -0
- package/src/browser/components/ChatEditor.tsx +129 -0
- package/src/browser/components/ChatInput.tsx +197 -0
- package/src/browser/components/ChatMoreActions.tsx +33 -0
- package/src/browser/components/Thinking.tsx +23 -0
- package/src/browser/components/components.module.less +259 -0
- package/src/browser/components/lineVertical.tsx +19 -0
- package/src/browser/content-widget/ai-content-widget.tsx +132 -0
- package/src/browser/content-widget/ai-inline-chat-panel.tsx +154 -0
- package/src/browser/content-widget/ai-inline-chat.module.less +74 -0
- package/src/browser/content-widget/ai-inline-chat.service.ts +46 -0
- package/src/browser/diff-widget/ai-diff-document.provider.ts +22 -0
- package/src/browser/diff-widget/ai-diff-widget.tsx +196 -0
- package/src/browser/index.ts +91 -0
- package/src/browser/inline-completions/constants.ts +108 -0
- package/src/browser/inline-completions/provider.ts +55 -0
- package/src/browser/override/ai-editor-tab.service.tsx +22 -0
- package/src/browser/override/ai-marker.service.tsx +55 -0
- package/src/browser/override/global.styles.less +268 -0
- package/src/browser/override/layout/layout-config.ts +21 -0
- package/src/browser/override/layout/layout.module.less +7 -0
- package/src/browser/override/layout/main-slot-renderer.tsx +62 -0
- package/src/browser/override/layout/menu-bar/menu-bar.contribution.tsx +28 -0
- package/src/browser/override/layout/menu-bar/menu-bar.module.less +41 -0
- package/src/browser/override/layout/menu-bar/menu-bar.view.tsx +92 -0
- package/src/browser/override/layout/tabbar.view.tsx +99 -0
- package/src/browser/override/override.module.less +32 -0
- package/src/browser/override/theme/default-theme.ts +818 -0
- package/src/browser/run/run.service.ts +183 -0
- package/src/common/command.ts +21 -0
- package/src/common/index.ts +39 -0
- package/src/index.ts +1 -0
- package/src/node/index.ts +24 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import React, { CSSProperties, useEffect, useRef } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
|
|
4
|
+
import { Injectable, Autowired } from '@opensumi/di';
|
|
5
|
+
import { AppConfig, URI, useInjectable } from '@opensumi/ide-core-browser';
|
|
6
|
+
import { ConfigProvider } from '@opensumi/ide-core-browser';
|
|
7
|
+
import { EditorCollectionService, IDiffEditor } from '@opensumi/ide-editor';
|
|
8
|
+
import { getSimpleEditorOptions } from '@opensumi/ide-editor';
|
|
9
|
+
import { IEditorDocumentModelService } from '@opensumi/ide-editor/lib/browser/index';
|
|
10
|
+
import { ICodeEditor } from '@opensumi/ide-monaco';
|
|
11
|
+
import { monaco } from '@opensumi/ide-monaco/lib/browser/monaco-api';
|
|
12
|
+
import { IDiffEditorOptions } from '@opensumi/ide-monaco/lib/browser/monaco-api/editor';
|
|
13
|
+
import { ZoneWidget } from '@opensumi/monaco-editor-core/esm/vs/editor/contrib/zoneWidget/browser/zoneWidget';
|
|
14
|
+
|
|
15
|
+
const diffEditorOptions: IDiffEditorOptions = {
|
|
16
|
+
scrollBeyondLastLine: false,
|
|
17
|
+
scrollbar: {
|
|
18
|
+
verticalScrollbarSize: 14,
|
|
19
|
+
horizontal: 'auto',
|
|
20
|
+
useShadows: true,
|
|
21
|
+
verticalHasArrows: false,
|
|
22
|
+
horizontalHasArrows: false,
|
|
23
|
+
alwaysConsumeMouseWheel: false,
|
|
24
|
+
},
|
|
25
|
+
fixedOverflowWidgets: true,
|
|
26
|
+
readOnly: true,
|
|
27
|
+
minimap: {
|
|
28
|
+
enabled: false,
|
|
29
|
+
},
|
|
30
|
+
enableSplitViewResizing: true,
|
|
31
|
+
renderOverviewRuler: true,
|
|
32
|
+
ignoreTrimWhitespace: false,
|
|
33
|
+
renderSideBySide: true,
|
|
34
|
+
lineNumbers: 'on',
|
|
35
|
+
glyphMargin: false,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const DiffContentProvider = React.memo(((props: { dto: { originValue; modifiedValue } | undefined; onMaxLincCount: (n) => void }) => {
|
|
39
|
+
const { dto, onMaxLincCount } = props;
|
|
40
|
+
const documentModelService: IEditorDocumentModelService = useInjectable(IEditorDocumentModelService);
|
|
41
|
+
const editorCollectionService: EditorCollectionService = useInjectable(EditorCollectionService);
|
|
42
|
+
const editorRef = useRef<HTMLDivElement>(null);
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!dto) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let diffEditor: IDiffEditor;
|
|
50
|
+
|
|
51
|
+
const random = Math.random() * 10;
|
|
52
|
+
const originUri = URI.parse(`AI://origin${random}`);
|
|
53
|
+
const actualUri = URI.parse(`AI://modified${random}`);
|
|
54
|
+
|
|
55
|
+
Promise.all([
|
|
56
|
+
documentModelService.createModelReference(originUri),
|
|
57
|
+
documentModelService.createModelReference(actualUri),
|
|
58
|
+
]).then((data) => {
|
|
59
|
+
const [original, modified] = data;
|
|
60
|
+
if (!original) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const { originValue, modifiedValue } = dto!;
|
|
65
|
+
|
|
66
|
+
diffEditor = editorCollectionService.createDiffEditor(editorRef.current!, {
|
|
67
|
+
...getSimpleEditorOptions(),
|
|
68
|
+
...diffEditorOptions,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const originalModel = original.instance.getMonacoModel();
|
|
72
|
+
const modifiedModel = modified.instance.getMonacoModel();
|
|
73
|
+
|
|
74
|
+
originalModel.setMode('java');
|
|
75
|
+
modifiedModel.setMode('java');
|
|
76
|
+
|
|
77
|
+
originalModel.setValue(originValue);
|
|
78
|
+
modifiedModel.setValue(modifiedValue);
|
|
79
|
+
|
|
80
|
+
diffEditor.compare(original, modified);
|
|
81
|
+
diffEditor.originalEditor.monacoEditor.setModel(originalModel);
|
|
82
|
+
diffEditor.modifiedEditor.monacoEditor.setModel(modifiedModel);
|
|
83
|
+
|
|
84
|
+
diffEditor.originalEditor.monacoEditor.updateOptions({ readOnly: true });
|
|
85
|
+
diffEditor.modifiedEditor.monacoEditor.updateOptions({ readOnly: true });
|
|
86
|
+
|
|
87
|
+
if (onMaxLincCount) {
|
|
88
|
+
const { originalEditor, modifiedEditor } = diffEditor;
|
|
89
|
+
|
|
90
|
+
const originContentHeight = originalEditor.monacoEditor.getContentHeight();
|
|
91
|
+
const originLineCount = originContentHeight / originalEditor.monacoEditor.getOption(monaco.editor.EditorOption.lineHeight);
|
|
92
|
+
|
|
93
|
+
const modifiedContentHeight = modifiedEditor.monacoEditor.getContentHeight();
|
|
94
|
+
const modifiedLineCount = modifiedContentHeight / modifiedEditor.monacoEditor.getOption(monaco.editor.EditorOption.lineHeight);
|
|
95
|
+
|
|
96
|
+
onMaxLincCount(Math.max(originLineCount, modifiedLineCount));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return () => {
|
|
101
|
+
if (diffEditor) {
|
|
102
|
+
diffEditor.dispose();
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}, [dto]);
|
|
106
|
+
|
|
107
|
+
return <div ref={editorRef} style={{ height: 'inherit', width:'100%', border:'1px solid #6666' }}></div>;
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
const styles: CSSProperties = {
|
|
111
|
+
height: '100%',
|
|
112
|
+
display: 'flex',
|
|
113
|
+
alignItems: 'center',
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
@Injectable({ multiple: true })
|
|
117
|
+
export class AiDiffWidget extends ZoneWidget {
|
|
118
|
+
@Autowired(AppConfig)
|
|
119
|
+
private configContext: AppConfig;
|
|
120
|
+
|
|
121
|
+
private recordLine: number;
|
|
122
|
+
|
|
123
|
+
private originValue: string;
|
|
124
|
+
private modifiedValue: string;
|
|
125
|
+
|
|
126
|
+
protected applyClass(): void {}
|
|
127
|
+
protected applyStyle(): void {}
|
|
128
|
+
|
|
129
|
+
protected _fillContainer(container: HTMLElement): void {
|
|
130
|
+
this.setCssClass('ai_diff-widget');
|
|
131
|
+
|
|
132
|
+
ReactDOM.render(
|
|
133
|
+
<ConfigProvider value={this.configContext}>
|
|
134
|
+
<div style={styles}>
|
|
135
|
+
<DiffContentProvider dto={{ originValue: this.originValue, modifiedValue: this.modifiedValue }} onMaxLincCount={(n) => {
|
|
136
|
+
if (n) {
|
|
137
|
+
this._relayout(n);
|
|
138
|
+
}
|
|
139
|
+
}}/>
|
|
140
|
+
</div>
|
|
141
|
+
</ConfigProvider>,
|
|
142
|
+
container,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
constructor(editor: ICodeEditor, originValue: string, modifiedValue: string) {
|
|
147
|
+
super(editor, {
|
|
148
|
+
showArrow: false,
|
|
149
|
+
showFrame: false,
|
|
150
|
+
arrowColor: undefined,
|
|
151
|
+
frameColor: undefined,
|
|
152
|
+
// 这里有个小坑,如果不开启这个配置,那么在调用 show 函数的时候会自动对焦并滚动到对应 range,导致在编辑 result 视图中代码时光标总是滚动在最后一个 widget 上
|
|
153
|
+
keepEditorSelection: true,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
this.originValue = originValue;
|
|
157
|
+
this.modifiedValue = modifiedValue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 覆写 revealLine 函数,使其在 show 的时候编辑器不会定位到对应位置
|
|
161
|
+
protected override revealLine(lineNumber: number, isLastLine: boolean): void {
|
|
162
|
+
// not implement
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public getRecordLine(): number {
|
|
166
|
+
return this.recordLine;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public setContainerStyle(style: { [key in string]: string }): void {
|
|
170
|
+
const keys = Object.keys(style);
|
|
171
|
+
for (const key of keys) {
|
|
172
|
+
if (Object.prototype.hasOwnProperty.call(this.container?.style, key)) {
|
|
173
|
+
this.container!.style[key] = style[key];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
public addClassName(type: string): this {
|
|
179
|
+
this.setCssClass(type);
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public showByLine(line: number, lineNumber = 20): void {
|
|
184
|
+
this.recordLine = line;
|
|
185
|
+
super.hide();
|
|
186
|
+
super.show(
|
|
187
|
+
{
|
|
188
|
+
startLineNumber: line,
|
|
189
|
+
startColumn: 0,
|
|
190
|
+
endLineNumber: line,
|
|
191
|
+
endColumn: Number.MAX_SAFE_INTEGER,
|
|
192
|
+
},
|
|
193
|
+
lineNumber,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Provider, Injectable, Injector } from '@opensumi/di';
|
|
2
|
+
import { BrowserModule } from '@opensumi/ide-core-browser';
|
|
3
|
+
import { AiChatContribution } from './ai-chat.contribution';
|
|
4
|
+
import { AiGPTBackSerivcePath, AiGPTBackSerivceToken } from '../common';
|
|
5
|
+
import { IMarkerService } from '@opensumi/ide-markers';
|
|
6
|
+
import { AiMarkerService } from './override/ai-marker.service';
|
|
7
|
+
import { LAYOUT_VIEW_SIZE } from '@opensumi/ide-core-browser/lib/layout/constants';
|
|
8
|
+
import { IEditorTabService } from '@opensumi/ide-editor/lib/browser';
|
|
9
|
+
import { AiEditorTabService } from './override/ai-editor-tab.service';
|
|
10
|
+
|
|
11
|
+
import { Color, IThemeData, IThemeStore } from '@opensumi/ide-theme';
|
|
12
|
+
import { ThemeData } from '@opensumi/ide-theme/lib/browser/theme-data';
|
|
13
|
+
import { ThemeStore } from '@opensumi/ide-theme/lib/browser/theme-store';
|
|
14
|
+
import { AiMenuBarContribution } from './override/layout/menu-bar/menu-bar.contribution';
|
|
15
|
+
import defaultTheme from './override/theme/default-theme';
|
|
16
|
+
|
|
17
|
+
import './override/global.styles.less';
|
|
18
|
+
|
|
19
|
+
@Injectable()
|
|
20
|
+
export class AiNativeModule extends BrowserModule {
|
|
21
|
+
providers: Provider[] = [
|
|
22
|
+
AiMenuBarContribution,
|
|
23
|
+
AiChatContribution
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
preferences = (injector: Injector) => {
|
|
27
|
+
injector.overrideProviders(
|
|
28
|
+
{
|
|
29
|
+
token: IMarkerService,
|
|
30
|
+
useClass: AiMarkerService,
|
|
31
|
+
override: true,
|
|
32
|
+
isDefault: true
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
token: IEditorTabService,
|
|
36
|
+
useClass: AiEditorTabService,
|
|
37
|
+
override: true,
|
|
38
|
+
isDefault: true
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
token: IThemeData,
|
|
42
|
+
useClass: class extends ThemeData {
|
|
43
|
+
override getDefaultTheme() {
|
|
44
|
+
return defaultTheme
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
override: true,
|
|
48
|
+
isDefault: true
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
// AI Native 模式下默认使用该主题
|
|
52
|
+
token: IThemeStore,
|
|
53
|
+
useClass: class extends ThemeStore {
|
|
54
|
+
override async getThemeData() {
|
|
55
|
+
const theme = this.loadDefaultTheme();
|
|
56
|
+
const colors = theme.colors;
|
|
57
|
+
if (colors) {
|
|
58
|
+
for (const colorId in colors) {
|
|
59
|
+
const colorHex = colors[colorId];
|
|
60
|
+
if (typeof colorHex === 'string') {
|
|
61
|
+
theme.colorMap[colorId] = Color.fromHex(colors[colorId]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return theme;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
override: true,
|
|
70
|
+
isDefault: true
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (!this.app.config.layoutViewSize) {
|
|
75
|
+
this.app.config.layoutViewSize = {
|
|
76
|
+
...LAYOUT_VIEW_SIZE,
|
|
77
|
+
MENUBAR_HEIGHT: 48,
|
|
78
|
+
EDITOR_TABS_HEIGHT: 36,
|
|
79
|
+
STATUSBAR_HEIGHT: 36,
|
|
80
|
+
ACCORDION_HEADER_SIZE_HEIGHT: 36,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
backServices = [
|
|
86
|
+
{
|
|
87
|
+
servicePath: AiGPTBackSerivcePath,
|
|
88
|
+
token: AiGPTBackSerivceToken,
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export const apiBaseUrl = 'http://localhost:3002';
|
|
2
|
+
const URL = 'https://caselike.alipay.com';
|
|
3
|
+
// 1.1基于GPT模型的代码补全(原COMMAND_GPT_CODEGEN)
|
|
4
|
+
export const codeFuseCommandGptCodegenUrl = URL + '/v1/function/commandGptCodegen';
|
|
5
|
+
// 1.2插件非流式功能(包含生成注释,生成代码等. 原:COMMAND_CHATCOMMAND)
|
|
6
|
+
export const codeFuseChatcommandUrl = URL + '/v1/function/chatcommand';
|
|
7
|
+
// 1.3对话(原 /v1/api/invokeWithStream接口)
|
|
8
|
+
export const codeFuseChatUrl = URL + '/v1/function/talkOnStream';
|
|
9
|
+
// 1.4评论对话消息(原MESSAGE_COMMENT)
|
|
10
|
+
export const codeFuseMessageCommentUrl = URL + '/v1/function/messageComment';
|
|
11
|
+
|
|
12
|
+
// 2.1查询用户信息(原:QUERY_USER)
|
|
13
|
+
export const codeFuseServiceUrl = URL + '/v1/user/queryUser';
|
|
14
|
+
// 2.2查询公钥(原:COMMAND_QUERYPUBKEY)
|
|
15
|
+
export const codeFuseQueryPubkeyUrl = URL + '/v1/common/queryPubkey';
|
|
16
|
+
// 2.3查询插件配置(原:COMMAND_QUERY_CONFIGDATA)
|
|
17
|
+
export const codeFuseQueryPluginConfigUrl = URL + '/v1/common/queryPluginConfig';
|
|
18
|
+
// 2.4申请权限(原:APPLY_PERMISSION)
|
|
19
|
+
export const codeFuseApplyPermissionUrl = URL + '/v1/common/applyPermission';
|
|
20
|
+
// 2.5提交插件埋点(原:/v1/api/submitReportEventTrack)
|
|
21
|
+
export const codeFuseTrackUrl = URL + 'v1/common/submitReportEventTrack';
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_API = 'https://marketplace.antfin-inc.com';
|
|
25
|
+
export const EXTENSION_ID = 'codeFuse.CodeFuse';
|
|
26
|
+
|
|
27
|
+
export const ACCOUNT_ID = 'bwdMKeo-xuSUNiHHaGtPl0mH ';
|
|
28
|
+
export const MASTER_KEY = 'IiBub2NWe0m7Va27heW0dY_f';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 接受补全事件
|
|
32
|
+
*/
|
|
33
|
+
export const COMMAND_ACCEPT = 'CF_COMMAND_ACCEPT';
|
|
34
|
+
|
|
35
|
+
interface CodeFuseConfigModel {
|
|
36
|
+
chatPromptMaxSize: number;
|
|
37
|
+
completionFileList: string[];
|
|
38
|
+
completionPromptMaxLineSize: number;
|
|
39
|
+
completionSuffixMaxLineSize: number;
|
|
40
|
+
intervalTime: number;
|
|
41
|
+
streamTimeOut: number;
|
|
42
|
+
timeOut: number;
|
|
43
|
+
completionRegular: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 插件配置信息
|
|
48
|
+
*/
|
|
49
|
+
export let codeFuseDefaultConfig: CodeFuseConfigModel = {
|
|
50
|
+
'chatPromptMaxSize': 4096,
|
|
51
|
+
'completionFileList': ['java', 'go', 'python', 'javascript', 'typescript'],
|
|
52
|
+
'completionPromptMaxLineSize': 1024,
|
|
53
|
+
'completionSuffixMaxLineSize': 500,
|
|
54
|
+
'intervalTime': 1800000,
|
|
55
|
+
'streamTimeOut': 40000,
|
|
56
|
+
'timeOut': 20000,
|
|
57
|
+
'completionRegular': '[\\)\\]\\}]',
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 更新配置
|
|
63
|
+
* @param newTsingyanConfig
|
|
64
|
+
*/
|
|
65
|
+
export function resetConfig(newTsingyanConfig: CodeFuseConfigModel) {
|
|
66
|
+
codeFuseDefaultConfig = newTsingyanConfig;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function isEmpty(value: any) {
|
|
70
|
+
if (value === null || value === undefined) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
if (typeof value === 'string' && value.trim() === '') {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (typeof value === 'object' && Object.keys(value).length === 0) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface IRawExtension extends IExtension {
|
|
86
|
+
isInstalled: boolean;
|
|
87
|
+
needUpdate: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 插件市场插件数据
|
|
92
|
+
*/
|
|
93
|
+
export interface IExtension {
|
|
94
|
+
extensionId: string;
|
|
95
|
+
name: string;
|
|
96
|
+
publisher: string;
|
|
97
|
+
displayName: string;
|
|
98
|
+
description: string;
|
|
99
|
+
icon: string;
|
|
100
|
+
version: string;
|
|
101
|
+
downloadCount: number;
|
|
102
|
+
originId: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface IExtensionManager {
|
|
106
|
+
install(extensionId: string, version: string): Promise<void>;
|
|
107
|
+
update(extensionId: string, version: string): Promise<void>;
|
|
108
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as constants from './constants';
|
|
2
|
+
/**
|
|
3
|
+
* prompt数据前处理
|
|
4
|
+
* 1: 去掉所有空行
|
|
5
|
+
* 2: 如果行数超过{@link constants.codeFuseDefaultConfig.completionPromptMaxLineSize},取最近的{@link constants.codeFuseDefaultConfig.completionPromptMaxLineSize}行
|
|
6
|
+
* @param prompt 代码上文
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export function prePromptHandler(prompt: string): string {
|
|
10
|
+
prompt = prompt.replace(/^s*[\n]/gm, '');
|
|
11
|
+
const arr = prompt.split('\n');
|
|
12
|
+
if (arr.length > constants.codeFuseDefaultConfig.completionPromptMaxLineSize) {
|
|
13
|
+
prompt = arr.slice(-constants.codeFuseDefaultConfig.completionPromptMaxLineSize).join('\n');
|
|
14
|
+
}
|
|
15
|
+
return prompt;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* suffix数据前处理
|
|
20
|
+
* 1: 去掉所有空行
|
|
21
|
+
* 2: 如果行数超过{@link constants.codeFuseDefaultConfig.completionPromptMaxLineSize},取最近的{@link constants.codeFuseDefaultConfig.completionPromptMaxLineSize}行
|
|
22
|
+
* @param prompt 代码上文
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export function preSuffixHandler(suffix: string): string {
|
|
26
|
+
suffix = suffix.replace(/^s*[\n]/gm, '');
|
|
27
|
+
const arr = suffix.split('\n');
|
|
28
|
+
if (arr.length > constants.codeFuseDefaultConfig.completionSuffixMaxLineSize) {
|
|
29
|
+
suffix = arr.slice(-constants.codeFuseDefaultConfig.completionSuffixMaxLineSize).join('\n');
|
|
30
|
+
}
|
|
31
|
+
return suffix;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class ReqStack {
|
|
35
|
+
queue: any[];
|
|
36
|
+
constructor() {
|
|
37
|
+
this.queue = [];
|
|
38
|
+
}
|
|
39
|
+
addReq(reqRequest: { sendRequest: any; cancelRequest: any }) {
|
|
40
|
+
this.queue.push(reqRequest);
|
|
41
|
+
}
|
|
42
|
+
runReq() {
|
|
43
|
+
if (this.queue.length === 0) {return;}
|
|
44
|
+
const fn = this.queue.pop();
|
|
45
|
+
return fn.sendRequest();
|
|
46
|
+
}
|
|
47
|
+
cancleRqe() {
|
|
48
|
+
if (this.queue.length === 0) {return;}
|
|
49
|
+
this.queue.forEach((item) => {
|
|
50
|
+
item.cancelRequest();
|
|
51
|
+
});
|
|
52
|
+
this.queue = [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { Injectable } from '@opensumi/di';
|
|
3
|
+
import { EditorTabService } from '@opensumi/ide-editor/lib/browser/editor.tab.service';
|
|
4
|
+
|
|
5
|
+
import cls from 'classnames';
|
|
6
|
+
import * as styles from './override.module.less';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export class AiEditorTabService extends EditorTabService {
|
|
10
|
+
override renderEditorTab(component: ReactNode, isCurrent: boolean): ReactNode {
|
|
11
|
+
return (
|
|
12
|
+
<div className={cls(
|
|
13
|
+
{
|
|
14
|
+
[styles.ai_editor_tab_block_container]: true,
|
|
15
|
+
[styles.active]: isCurrent
|
|
16
|
+
}
|
|
17
|
+
)}>
|
|
18
|
+
{component}
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { Injectable, Autowired } from '@opensumi/di';
|
|
3
|
+
import { MarkerService } from '@opensumi/ide-markers/lib/browser/markers-service';
|
|
4
|
+
import { MarkerGroupNode, MarkerNode } from '@opensumi/ide-markers/lib/browser/tree/tree-node.defined';
|
|
5
|
+
|
|
6
|
+
import cls from 'classnames';
|
|
7
|
+
|
|
8
|
+
import * as styles from './override.module.less';
|
|
9
|
+
import { Icon } from '@opensumi/ide-components';
|
|
10
|
+
import { getExternalIcon } from '@opensumi/ide-core-browser';
|
|
11
|
+
import { AiChatService } from '../ai-chat.service';
|
|
12
|
+
import { WorkbenchEditorServiceImpl } from '@opensumi/ide-editor/lib/browser/workbench-editor.service';
|
|
13
|
+
import { WorkbenchEditorService } from '@opensumi/ide-editor';
|
|
14
|
+
import { IFileServiceClient } from '@opensumi/ide-file-service';
|
|
15
|
+
|
|
16
|
+
@Injectable()
|
|
17
|
+
export class AiMarkerService extends MarkerService {
|
|
18
|
+
|
|
19
|
+
@Autowired(WorkbenchEditorService)
|
|
20
|
+
private readonly editorService: WorkbenchEditorServiceImpl;
|
|
21
|
+
|
|
22
|
+
@Autowired()
|
|
23
|
+
private aiChatService: AiChatService;
|
|
24
|
+
|
|
25
|
+
@Autowired(IFileServiceClient)
|
|
26
|
+
private readonly fileSystem: IFileServiceClient;
|
|
27
|
+
|
|
28
|
+
private async handleAiIcon(node: MarkerNode) {
|
|
29
|
+
try {
|
|
30
|
+
const resource = node.marker.resource;
|
|
31
|
+
const message = node.marker.message;
|
|
32
|
+
const { content } = await this.fileSystem.readFile(resource.toString());
|
|
33
|
+
|
|
34
|
+
const messageWithPrompt = `代码内容是 \`\`\`\n${content.toString()}\n\`\`\`。此时有个异常问题是 "${message}", 你需要解释这个异常问题并给出修复建议`;
|
|
35
|
+
|
|
36
|
+
this.aiChatService.launchChatMessage({
|
|
37
|
+
message: `/explain ${node.marker.message}`,
|
|
38
|
+
prompt: messageWithPrompt,
|
|
39
|
+
});
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw Error('read file error', error)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override renderMarkerNodeIcon(component: ReactNode, node: MarkerGroupNode | MarkerNode): ReactNode {
|
|
46
|
+
return (
|
|
47
|
+
<div className={cls(!(MarkerGroupNode.is(node)) && styles.ai_marker_node_icon_container)}>
|
|
48
|
+
{
|
|
49
|
+
!MarkerGroupNode.is(node) && <Icon tooltip='AI 智能问题诊断' onClick={() => this.handleAiIcon(node)} className={cls(getExternalIcon('lightbulb'), styles.ai_icon)} />
|
|
50
|
+
}
|
|
51
|
+
{component}
|
|
52
|
+
</div>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
}
|