@opensumi/ide-ai-native 3.8.1-next-1741091353.0 → 3.8.1-next-1741092802.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/ai-core.contribution.d.ts +3 -0
- package/lib/browser/ai-core.contribution.d.ts.map +1 -1
- package/lib/browser/ai-core.contribution.js +45 -1
- package/lib/browser/ai-core.contribution.js.map +1 -1
- package/lib/browser/chat/chat-manager.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-manager.service.js +0 -4
- package/lib/browser/chat/chat-manager.service.js.map +1 -1
- package/lib/browser/chat/chat-proxy.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-proxy.service.js +8 -2
- package/lib/browser/chat/chat-proxy.service.js.map +1 -1
- package/lib/browser/chat/chat.view.d.ts.map +1 -1
- package/lib/browser/chat/chat.view.js +1 -7
- package/lib/browser/chat/chat.view.js.map +1 -1
- package/lib/browser/components/chat-history.module.less +0 -1
- package/lib/browser/mcp/base-apply.service.d.ts +7 -18
- package/lib/browser/mcp/base-apply.service.d.ts.map +1 -1
- package/lib/browser/mcp/base-apply.service.js +65 -185
- package/lib/browser/mcp/base-apply.service.js.map +1 -1
- package/lib/browser/mcp/tools/components/EditFile.d.ts.map +1 -1
- package/lib/browser/mcp/tools/components/EditFile.js +9 -15
- package/lib/browser/mcp/tools/components/EditFile.js.map +1 -1
- package/lib/browser/mcp/tools/components/index.module.less +0 -3
- package/lib/browser/mcp/tools/createNewFileWithText.d.ts +0 -1
- package/lib/browser/mcp/tools/createNewFileWithText.d.ts.map +1 -1
- package/lib/browser/mcp/tools/createNewFileWithText.js +11 -18
- package/lib/browser/mcp/tools/createNewFileWithText.js.map +1 -1
- package/lib/browser/mcp/tools/handlers/EditFile.js +1 -1
- package/lib/browser/mcp/tools/handlers/EditFile.js.map +1 -1
- package/lib/browser/model/msg-history-manager.d.ts +0 -1
- package/lib/browser/model/msg-history-manager.d.ts.map +1 -1
- package/lib/browser/model/msg-history-manager.js +0 -3
- package/lib/browser/model/msg-history-manager.js.map +1 -1
- package/lib/browser/preferences/schema.d.ts.map +1 -1
- package/lib/browser/preferences/schema.js +6 -1
- package/lib/browser/preferences/schema.js.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-manager.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-manager.js +8 -68
- package/lib/browser/widget/inline-diff/inline-diff-manager.js.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-previewer.d.ts +4 -10
- package/lib/browser/widget/inline-diff/inline-diff-previewer.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-previewer.js +3 -14
- package/lib/browser/widget/inline-diff/inline-diff-previewer.js.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-widget.module.less +4 -25
- package/lib/browser/widget/inline-diff/inline-diff.controller.d.ts +3 -3
- package/lib/browser/widget/inline-diff/inline-diff.controller.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff.controller.js +5 -10
- package/lib/browser/widget/inline-diff/inline-diff.controller.js.map +1 -1
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.d.ts +17 -46
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.d.ts.map +1 -1
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.js +53 -110
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.js.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.d.ts +0 -4
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.d.ts.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.js +1 -26
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.js.map +1 -1
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/model.d.ts +12 -0
- package/lib/common/model.d.ts.map +1 -0
- package/lib/common/model.js +83 -0
- package/lib/common/model.js.map +1 -0
- package/lib/common/types.d.ts +0 -1
- package/lib/common/types.d.ts.map +1 -1
- package/lib/node/anthropic/anthropic-language-model.d.ts +3 -1
- package/lib/node/anthropic/anthropic-language-model.d.ts.map +1 -1
- package/lib/node/anthropic/anthropic-language-model.js +6 -2
- package/lib/node/anthropic/anthropic-language-model.js.map +1 -1
- package/lib/node/base-language-model.d.ts +4 -1
- package/lib/node/base-language-model.d.ts.map +1 -1
- package/lib/node/base-language-model.js +6 -5
- package/lib/node/base-language-model.js.map +1 -1
- package/lib/node/deepseek/deepseek-language-model.d.ts +3 -1
- package/lib/node/deepseek/deepseek-language-model.d.ts.map +1 -1
- package/lib/node/deepseek/deepseek-language-model.js +6 -2
- package/lib/node/deepseek/deepseek-language-model.js.map +1 -1
- package/lib/node/openai/openai-language-model.d.ts +5 -4
- package/lib/node/openai/openai-language-model.d.ts.map +1 -1
- package/lib/node/openai/openai-language-model.js +8 -7
- package/lib/node/openai/openai-language-model.js.map +1 -1
- package/lib/node/openai-compatible/openai-compatible-language-model.d.ts +10 -0
- package/lib/node/openai-compatible/openai-compatible-language-model.d.ts.map +1 -0
- package/lib/node/openai-compatible/openai-compatible-language-model.js +32 -0
- package/lib/node/openai-compatible/openai-compatible-language-model.js.map +1 -0
- package/package.json +24 -23
- package/src/browser/ai-core.contribution.ts +57 -1
- package/src/browser/chat/chat-manager.service.ts +0 -6
- package/src/browser/chat/chat-proxy.service.ts +7 -2
- package/src/browser/chat/chat.view.tsx +2 -7
- package/src/browser/components/chat-history.module.less +0 -1
- package/src/browser/mcp/base-apply.service.ts +67 -222
- package/src/browser/mcp/tools/components/EditFile.tsx +9 -16
- package/src/browser/mcp/tools/components/index.module.less +0 -3
- package/src/browser/mcp/tools/createNewFileWithText.ts +12 -20
- package/src/browser/mcp/tools/handlers/EditFile.ts +1 -1
- package/src/browser/model/msg-history-manager.ts +0 -4
- package/src/browser/preferences/schema.ts +6 -1
- package/src/browser/widget/inline-diff/inline-diff-manager.tsx +21 -143
- package/src/browser/widget/inline-diff/inline-diff-previewer.ts +7 -25
- package/src/browser/widget/inline-diff/inline-diff-widget.module.less +4 -25
- package/src/browser/widget/inline-diff/inline-diff.controller.ts +8 -16
- package/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx +68 -139
- package/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx +1 -30
- package/src/common/index.ts +2 -0
- package/src/common/model.ts +90 -0
- package/src/common/types.ts +0 -1
- package/src/node/anthropic/anthropic-language-model.ts +7 -2
- package/src/node/base-language-model.ts +9 -9
- package/src/node/deepseek/deepseek-language-model.ts +7 -2
- package/src/node/openai/openai-language-model.ts +10 -9
- package/src/node/openai-compatible/openai-compatible-language-model.ts +30 -0
|
@@ -44,13 +44,10 @@ export enum EComputerMode {
|
|
|
44
44
|
|
|
45
45
|
const inlineStreamDiffComputer = new InlineStreamDiffComputer();
|
|
46
46
|
|
|
47
|
-
/**
|
|
48
|
-
* Abstract base class for inline streaming diff handlers
|
|
49
|
-
*/
|
|
50
47
|
@Injectable({ multiple: true })
|
|
51
|
-
export
|
|
48
|
+
export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPreviewerNode {
|
|
52
49
|
@Autowired(INJECTOR_TOKEN)
|
|
53
|
-
|
|
50
|
+
private readonly injector: Injector;
|
|
54
51
|
|
|
55
52
|
protected readonly _onDidEditChange = this.registerDispose(new Emitter<void>());
|
|
56
53
|
public readonly onDidEditChange: Event<void> = this._onDidEditChange.event;
|
|
@@ -60,14 +57,15 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
60
57
|
|
|
61
58
|
public previewerOptions: IDiffPreviewerOptions;
|
|
62
59
|
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
private originalModel: ITextModel;
|
|
61
|
+
private virtualModel: ITextModel;
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
private rawOriginalTextLines: string[];
|
|
64
|
+
private rawOriginalTextLinesTokens: LineTokens[] = [];
|
|
65
|
+
private undoRedoGroup: UndoRedoGroup = new UndoRedoGroup();
|
|
69
66
|
|
|
70
|
-
|
|
67
|
+
private readonly diffModel: ISettableObservable<IComputeDiffData | undefined> = observableValue(this, undefined);
|
|
68
|
+
private readonly finallyDiffModel: ISettableObservable<IComputeDiffData | undefined> = observableValue(
|
|
71
69
|
this,
|
|
72
70
|
undefined,
|
|
73
71
|
);
|
|
@@ -75,15 +73,14 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
75
73
|
public livePreviewDiffDecorationModel: LivePreviewDiffDecorationModel;
|
|
76
74
|
|
|
77
75
|
public get uri() {
|
|
78
|
-
return this.
|
|
76
|
+
return this.originalModel.uri;
|
|
79
77
|
}
|
|
80
78
|
|
|
81
|
-
constructor(
|
|
79
|
+
constructor(private readonly monacoEditor: ICodeEditor) {
|
|
82
80
|
super();
|
|
83
81
|
|
|
84
82
|
const modelService = StandaloneServices.get(IModelService);
|
|
85
|
-
|
|
86
|
-
const setModel = modelService.createModel(
|
|
83
|
+
this.virtualModel = modelService.createModel(
|
|
87
84
|
'',
|
|
88
85
|
null,
|
|
89
86
|
Uri.from({
|
|
@@ -92,8 +89,7 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
92
89
|
}),
|
|
93
90
|
true,
|
|
94
91
|
);
|
|
95
|
-
this.
|
|
96
|
-
this.virtualModel = setModel;
|
|
92
|
+
this.originalModel = this.monacoEditor.getModel()!;
|
|
97
93
|
|
|
98
94
|
this.livePreviewDiffDecorationModel = this.injector.get(LivePreviewDiffDecorationModel, [this.monacoEditor]);
|
|
99
95
|
this.addDispose(this.livePreviewDiffDecorationModel);
|
|
@@ -117,21 +113,45 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
117
113
|
});
|
|
118
114
|
}
|
|
119
115
|
|
|
120
|
-
|
|
116
|
+
initialize(selection: Selection): void {
|
|
117
|
+
const eol = this.originalModel.getEOL();
|
|
118
|
+
const startPosition = selection.getStartPosition();
|
|
119
|
+
const endPosition = selection.getEndPosition();
|
|
120
|
+
|
|
121
|
+
this.rawOriginalTextLines = this.originalModel
|
|
122
|
+
.getValueInRange(Range.fromPositions(startPosition, endPosition))
|
|
123
|
+
.split(eol);
|
|
124
|
+
|
|
125
|
+
this.rawOriginalTextLinesTokens = this.rawOriginalTextLines.map((_, index) => {
|
|
126
|
+
const lineNumber = startPosition.lineNumber + index;
|
|
127
|
+
this.originalModel.tokenization.forceTokenization(lineNumber);
|
|
128
|
+
const lineTokens = this.originalModel.tokenization.getLineTokens(lineNumber);
|
|
129
|
+
return lineTokens;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const zone = LineRange.fromRangeInclusive(
|
|
133
|
+
Range.fromPositions(
|
|
134
|
+
{ lineNumber: selection.startLineNumber, column: 1 },
|
|
135
|
+
{ lineNumber: selection.endLineNumber, column: Number.MAX_SAFE_INTEGER },
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
this.livePreviewDiffDecorationModel.initialize(zone);
|
|
140
|
+
}
|
|
121
141
|
|
|
122
142
|
getVirtualModelValue() {
|
|
123
143
|
return this.virtualModel.getValue();
|
|
124
144
|
}
|
|
125
145
|
|
|
126
146
|
getOriginModelValue() {
|
|
127
|
-
return this.
|
|
147
|
+
return this.rawOriginalTextLines.join('\n');
|
|
128
148
|
}
|
|
129
149
|
|
|
130
150
|
get onPartialEditWidgetListChange() {
|
|
131
151
|
return this.livePreviewDiffDecorationModel.onPartialEditWidgetListChange;
|
|
132
152
|
}
|
|
133
153
|
|
|
134
|
-
|
|
154
|
+
private computeDiff(
|
|
135
155
|
originalTextLines: string[],
|
|
136
156
|
newTextLines: string[],
|
|
137
157
|
computerMode: EComputerMode = EComputerMode.default,
|
|
@@ -265,12 +285,7 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
265
285
|
},
|
|
266
286
|
textLines: removedTextLines.map((text, index) => ({
|
|
267
287
|
text,
|
|
268
|
-
lineTokens:
|
|
269
|
-
this.rawOriginTextLinesTokens?.[removedLinesOriginalRange.startLineNumber - 1 + index] ||
|
|
270
|
-
LineTokens.createEmpty(text, {
|
|
271
|
-
encodeLanguageId: () => 0,
|
|
272
|
-
decodeLanguageId: () => 'plaintext',
|
|
273
|
-
}),
|
|
288
|
+
lineTokens: this.rawOriginalTextLinesTokens[removedLinesOriginalRange.startLineNumber - 1 + index],
|
|
274
289
|
})),
|
|
275
290
|
});
|
|
276
291
|
}
|
|
@@ -283,11 +298,6 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
283
298
|
});
|
|
284
299
|
}
|
|
285
300
|
|
|
286
|
-
/**
|
|
287
|
-
* Get the original model for diff operations
|
|
288
|
-
*/
|
|
289
|
-
protected abstract getOriginalModel(): ITextModel;
|
|
290
|
-
|
|
291
301
|
/**
|
|
292
302
|
* 令当前的 inline diff 在流式渲染过程当中使用 pushEditOperations 进行编辑的操作都放在同一组 undo/redo 堆栈里
|
|
293
303
|
* 一旦撤销到最顶层则关闭当前的 inline diff
|
|
@@ -300,24 +310,22 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
300
310
|
});
|
|
301
311
|
}
|
|
302
312
|
|
|
303
|
-
|
|
313
|
+
private renderDiffEdits(diffModel: IComputeDiffData): void {
|
|
304
314
|
const { activeLine, newFullRangeTextLines, pendingRange } = diffModel;
|
|
315
|
+
const eol = this.originalModel.getEOL();
|
|
305
316
|
const zone = this.getZone();
|
|
306
317
|
|
|
307
|
-
const originalModel = this.getOriginalModel();
|
|
308
|
-
const eol = originalModel.getEOL();
|
|
309
|
-
|
|
310
318
|
const validZone =
|
|
311
319
|
zone.startLineNumber < zone.endLineNumberExclusive
|
|
312
320
|
? new Range(
|
|
313
321
|
zone.startLineNumber,
|
|
314
322
|
1,
|
|
315
323
|
zone.endLineNumberExclusive - 1,
|
|
316
|
-
originalModel.getLineMaxColumn(zone.endLineNumberExclusive - 1),
|
|
324
|
+
this.originalModel.getLineMaxColumn(zone.endLineNumberExclusive - 1),
|
|
317
325
|
)
|
|
318
326
|
: new Range(zone.startLineNumber, 1, zone.startLineNumber, 1);
|
|
319
327
|
|
|
320
|
-
const newOriginalTextLines = originalModel.getValueInRange(validZone).split(eol);
|
|
328
|
+
const newOriginalTextLines = this.originalModel.getValueInRange(validZone).split(eol);
|
|
321
329
|
const diffComputation = linesDiffComputers.getDefault().computeDiff(newOriginalTextLines, newFullRangeTextLines, {
|
|
322
330
|
computeMoves: false,
|
|
323
331
|
maxComputationTimeMs: 200,
|
|
@@ -362,7 +370,7 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
362
370
|
validZone.startLineNumber + change.original.startLineNumber - 1,
|
|
363
371
|
1,
|
|
364
372
|
validZone.startLineNumber + change.original.endLineNumberExclusive - 2,
|
|
365
|
-
originalModel.getLineMaxColumn(validZone.startLineNumber + change.original.endLineNumberExclusive - 2),
|
|
373
|
+
this.originalModel.getLineMaxColumn(validZone.startLineNumber + change.original.endLineNumberExclusive - 2),
|
|
366
374
|
);
|
|
367
375
|
}
|
|
368
376
|
const edit = {
|
|
@@ -373,7 +381,7 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
373
381
|
realTimeChanges.push(edit);
|
|
374
382
|
}
|
|
375
383
|
}
|
|
376
|
-
originalModel.pushEditOperations(null, realTimeChanges, () => null, this.undoRedoGroup);
|
|
384
|
+
this.originalModel.pushEditOperations(null, realTimeChanges, () => null, this.undoRedoGroup);
|
|
377
385
|
|
|
378
386
|
/**
|
|
379
387
|
* 根据 newFullRangeTextLines 内容长度重新计算 zone,避免超过最大长度,进而影响未选中的代码区域
|
|
@@ -413,20 +421,17 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
413
421
|
this._onDidEditChange.fire();
|
|
414
422
|
}
|
|
415
423
|
|
|
416
|
-
public recompute(computerMode: EComputerMode,
|
|
417
|
-
if (
|
|
418
|
-
this.virtualModel.setValue(
|
|
424
|
+
public recompute(computerMode: EComputerMode, newContent?: string): IComputeDiffData {
|
|
425
|
+
if (newContent) {
|
|
426
|
+
this.virtualModel.setValue(newContent);
|
|
419
427
|
}
|
|
420
428
|
|
|
421
|
-
const
|
|
422
|
-
return this.
|
|
429
|
+
const newTextLines = this.virtualModel.getLinesContent();
|
|
430
|
+
return this.computeDiff(this.rawOriginalTextLines, newTextLines, computerMode);
|
|
423
431
|
}
|
|
424
432
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
protected abstract processDiffComputation(currentText: string[], computerMode?: EComputerMode): IComputeDiffData;
|
|
429
|
-
|
|
433
|
+
private currentEditLine = 0;
|
|
434
|
+
private isEditing = false;
|
|
430
435
|
public async rateRenderEditController(): Promise<void> {
|
|
431
436
|
if (this.isEditing === false) {
|
|
432
437
|
this.isEditing = true;
|
|
@@ -438,14 +443,19 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
438
443
|
|
|
439
444
|
const virtualTextLines = this.virtualModel.getLinesContent();
|
|
440
445
|
const currentText = virtualTextLines.slice(0, this.currentEditLine);
|
|
441
|
-
const currentDiffModel = this.
|
|
446
|
+
const currentDiffModel = this.computeDiff(this.rawOriginalTextLines, currentText);
|
|
447
|
+
transaction((tx) => {
|
|
448
|
+
this.diffModel.set(currentDiffModel, tx);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
this.onDiffFinishedEmitter.fire(currentDiffModel);
|
|
442
452
|
|
|
443
|
-
if (this.
|
|
453
|
+
if (this.originalModel.id === this.monacoEditor.getModel()?.id) {
|
|
444
454
|
this.renderDiffEdits(currentDiffModel);
|
|
445
455
|
}
|
|
446
456
|
|
|
447
457
|
this.currentEditLine += 1;
|
|
448
|
-
|
|
458
|
+
|
|
449
459
|
await sleep(FRAME_THREE);
|
|
450
460
|
}
|
|
451
461
|
|
|
@@ -459,7 +469,10 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
459
469
|
}
|
|
460
470
|
|
|
461
471
|
public addLinesToDiff(newText: string, computerMode: EComputerMode = EComputerMode.default): void {
|
|
462
|
-
this.recompute(computerMode, newText);
|
|
472
|
+
const diffModel = this.recompute(computerMode, newText);
|
|
473
|
+
transaction((tx) => {
|
|
474
|
+
this.diffModel.set(diffModel, tx);
|
|
475
|
+
});
|
|
463
476
|
}
|
|
464
477
|
|
|
465
478
|
public pushRateFinallyDiffStack(diffModel: IComputeDiffData): void {
|
|
@@ -475,17 +488,14 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
475
488
|
public finallyRender(diffModel: IComputeDiffData): void {
|
|
476
489
|
transaction((tx) => {
|
|
477
490
|
this.finallyDiffModel.set(diffModel, tx);
|
|
491
|
+
this.diffModel.set(diffModel, tx);
|
|
478
492
|
});
|
|
479
493
|
|
|
480
|
-
if (this.
|
|
494
|
+
if (this.originalModel.id !== this.monacoEditor.getModel()?.id) {
|
|
481
495
|
return;
|
|
482
496
|
}
|
|
483
497
|
|
|
484
498
|
this.onDiffFinishedEmitter.fire(diffModel);
|
|
485
|
-
|
|
486
|
-
if (this.livePreviewDiffDecorationModel.disposed) {
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
499
|
this.renderPartialEditWidgets(diffModel);
|
|
490
500
|
this.renderDiffEdits(diffModel);
|
|
491
501
|
this.pushStackElement();
|
|
@@ -527,84 +537,3 @@ export abstract class BaseInlineStreamDiffHandler extends Disposable implements
|
|
|
527
537
|
return this.livePreviewDiffDecorationModel.getTotalCodeInfo();
|
|
528
538
|
}
|
|
529
539
|
}
|
|
530
|
-
|
|
531
|
-
/**
|
|
532
|
-
* Regular inline stream diff handler (non-reverse mode)
|
|
533
|
-
*/
|
|
534
|
-
@Injectable({ multiple: true })
|
|
535
|
-
export class InlineStreamDiffHandler extends BaseInlineStreamDiffHandler {
|
|
536
|
-
initialize(selection: Selection): void {
|
|
537
|
-
const eol = this.savedModel.getEOL();
|
|
538
|
-
const startPosition = selection.getStartPosition();
|
|
539
|
-
const endPosition = selection.getEndPosition();
|
|
540
|
-
|
|
541
|
-
this.rawSavedTextLines = this.savedModel
|
|
542
|
-
.getValueInRange(Range.fromPositions(startPosition, endPosition))
|
|
543
|
-
.split(eol);
|
|
544
|
-
|
|
545
|
-
const zone = LineRange.fromRangeInclusive(
|
|
546
|
-
Range.fromPositions(
|
|
547
|
-
{ lineNumber: selection.startLineNumber, column: 1 },
|
|
548
|
-
{ lineNumber: selection.endLineNumber, column: Number.MAX_SAFE_INTEGER },
|
|
549
|
-
),
|
|
550
|
-
);
|
|
551
|
-
|
|
552
|
-
this.livePreviewDiffDecorationModel.initialize(zone);
|
|
553
|
-
this.rawOriginTextLinesTokens = this.rawSavedTextLines.map((_, index) => {
|
|
554
|
-
const lineNumber = startPosition.lineNumber + index;
|
|
555
|
-
this.savedModel.tokenization.forceTokenization(lineNumber);
|
|
556
|
-
const lineTokens = this.savedModel.tokenization.getLineTokens(lineNumber);
|
|
557
|
-
return lineTokens;
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
protected processDiffComputation(currentText: string[], computerMode?: EComputerMode): IComputeDiffData {
|
|
562
|
-
return this.computeDiff(this.rawSavedTextLines, currentText, computerMode);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
protected getOriginalModel(): ITextModel {
|
|
566
|
-
return this.savedModel;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Reverse inline stream diff handler
|
|
572
|
-
* In reverse mode, the roles of savedModel and virtualModel are swapped
|
|
573
|
-
*/
|
|
574
|
-
@Injectable({ multiple: true })
|
|
575
|
-
export class ReverseInlineStreamDiffHandler extends BaseInlineStreamDiffHandler {
|
|
576
|
-
recompute(computerMode: EComputerMode, content?: string): IComputeDiffData {
|
|
577
|
-
const result = super.recompute(computerMode, content);
|
|
578
|
-
this.rawOriginTextLinesTokens = this.virtualModel.getLinesContent().map((_, index) => {
|
|
579
|
-
const lineNumber = index + 1;
|
|
580
|
-
this.virtualModel.tokenization.forceTokenization(lineNumber);
|
|
581
|
-
const lineTokens = this.virtualModel.tokenization.getLineTokens(lineNumber);
|
|
582
|
-
return lineTokens;
|
|
583
|
-
});
|
|
584
|
-
return result;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
initialize(): void {
|
|
588
|
-
const eol = this.savedModel.getEOL();
|
|
589
|
-
|
|
590
|
-
// reverse 模式不支持 range
|
|
591
|
-
this.rawSavedTextLines = this.savedModel.getValue().split(eol);
|
|
592
|
-
|
|
593
|
-
// TODO: reverse 模式暂不支持 range
|
|
594
|
-
const zone = LineRange.fromRangeInclusive(
|
|
595
|
-
Range.fromPositions(
|
|
596
|
-
{ lineNumber: 1, column: 1 },
|
|
597
|
-
{ lineNumber: this.virtualModel.getLineCount(), column: Number.MAX_SAFE_INTEGER },
|
|
598
|
-
),
|
|
599
|
-
);
|
|
600
|
-
this.livePreviewDiffDecorationModel.initialize(zone);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
protected getOriginalModel(): ITextModel {
|
|
604
|
-
return this.virtualModel;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
protected processDiffComputation(currentText: string[], computerMode?: EComputerMode): IComputeDiffData {
|
|
608
|
-
return this.computeDiff(currentText, this.rawSavedTextLines, computerMode);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
@@ -7,13 +7,11 @@ import {
|
|
|
7
7
|
Emitter,
|
|
8
8
|
Event,
|
|
9
9
|
IAIReporter,
|
|
10
|
-
localize,
|
|
11
10
|
runWhenIdle,
|
|
12
11
|
} from '@opensumi/ide-core-common';
|
|
13
12
|
import { ISingleEditOperation } from '@opensumi/ide-editor';
|
|
14
13
|
import { ICodeEditor, IEditorDecorationsCollection, ITextModel, Position, Range } from '@opensumi/ide-monaco';
|
|
15
14
|
import { StandaloneServices } from '@opensumi/ide-monaco/lib/browser/monaco-api/services';
|
|
16
|
-
import { IMessageService } from '@opensumi/ide-overlay';
|
|
17
15
|
import { EditOperation } from '@opensumi/monaco-editor-core/esm/vs/editor/common/core/editOperation';
|
|
18
16
|
import { LineRange } from '@opensumi/monaco-editor-core/esm/vs/editor/common/core/lineRange';
|
|
19
17
|
import { ModelDecorationOptions } from '@opensumi/monaco-editor-core/esm/vs/editor/common/model/textModel';
|
|
@@ -69,9 +67,6 @@ export class LivePreviewDiffDecorationModel extends Disposable {
|
|
|
69
67
|
@Autowired(InlineDiffService)
|
|
70
68
|
private readonly inlineDiffService: InlineDiffService;
|
|
71
69
|
|
|
72
|
-
@Autowired(IMessageService)
|
|
73
|
-
private readonly messageService: IMessageService;
|
|
74
|
-
|
|
75
70
|
private activeLineDec: IEditorDecorationsCollection;
|
|
76
71
|
private pendingRangeDec: IEditorDecorationsCollection;
|
|
77
72
|
private aiNativeContextKey: AINativeContextKey;
|
|
@@ -92,10 +87,6 @@ export class LivePreviewDiffDecorationModel extends Disposable {
|
|
|
92
87
|
private removedZoneWidgets: RemovedZoneWidget[] = [];
|
|
93
88
|
private zone: LineRange;
|
|
94
89
|
|
|
95
|
-
public get partialEditWidgetCount() {
|
|
96
|
-
return this.partialEditWidgetList.length;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
90
|
constructor(private readonly monacoEditor: ICodeEditor) {
|
|
100
91
|
super();
|
|
101
92
|
this.model = this.monacoEditor.getModel()!;
|
|
@@ -625,7 +616,7 @@ export class LivePreviewDiffDecorationModel extends Disposable {
|
|
|
625
616
|
if (this.options.renderRemovedWidgetImmediately) {
|
|
626
617
|
run();
|
|
627
618
|
} else {
|
|
628
|
-
|
|
619
|
+
runWhenIdle(run);
|
|
629
620
|
}
|
|
630
621
|
}
|
|
631
622
|
|
|
@@ -690,26 +681,6 @@ export class LivePreviewDiffDecorationModel extends Disposable {
|
|
|
690
681
|
}
|
|
691
682
|
}
|
|
692
683
|
|
|
693
|
-
currentChangeIndex: number = 0;
|
|
694
|
-
|
|
695
|
-
revealSiblingChange(direction: 'up' | 'down') {
|
|
696
|
-
this.currentChangeIndex = this.currentChangeIndex + (direction === 'up' ? -1 : 1);
|
|
697
|
-
if (this.currentChangeIndex >= 0 && this.currentChangeIndex < this.partialEditWidgetList.length) {
|
|
698
|
-
const siblingChange = this.partialEditWidgetList[this.currentChangeIndex];
|
|
699
|
-
const pos = siblingChange.getPosition();
|
|
700
|
-
if (pos?.position) {
|
|
701
|
-
this.monacoEditor.revealLineInCenter(pos.position!.lineNumber);
|
|
702
|
-
return this.currentChangeIndex;
|
|
703
|
-
}
|
|
704
|
-
} else {
|
|
705
|
-
this.messageService.info(
|
|
706
|
-
direction === 'up'
|
|
707
|
-
? localize('aiNative.inlineDiff.noMoreChangesUp')
|
|
708
|
-
: localize('aiNative.inlineDiff.noMoreChangesDown'),
|
|
709
|
-
);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
|
|
713
684
|
setPreviewerOptions(options: IModelOptions) {
|
|
714
685
|
this.options = options;
|
|
715
686
|
}
|
package/src/common/index.ts
CHANGED
|
@@ -19,6 +19,8 @@ import { IPosition, ITextModel, InlineCompletionContext } from '@opensumi/ide-mo
|
|
|
19
19
|
import { MCPServerDescription } from './mcp-server-manager';
|
|
20
20
|
import { MCPTool } from './types';
|
|
21
21
|
|
|
22
|
+
export * from './model';
|
|
23
|
+
|
|
22
24
|
export const IAINativeService = Symbol('IAINativeService');
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export interface ModelInfo {
|
|
2
|
+
maxTokens?: number;
|
|
3
|
+
contextWindow?: number;
|
|
4
|
+
supportsImages?: boolean;
|
|
5
|
+
temperature?: number;
|
|
6
|
+
topP?: number;
|
|
7
|
+
topK?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const deepSeekModels = {
|
|
11
|
+
'deepseek-chat': {
|
|
12
|
+
maxTokens: 8_000,
|
|
13
|
+
contextWindow: 64_000,
|
|
14
|
+
supportsImages: false,
|
|
15
|
+
},
|
|
16
|
+
'deepseek-reasoner': {
|
|
17
|
+
maxTokens: 8_000,
|
|
18
|
+
contextWindow: 64_000,
|
|
19
|
+
supportsImages: false,
|
|
20
|
+
temperature: 0.7,
|
|
21
|
+
topP: 0.95,
|
|
22
|
+
},
|
|
23
|
+
} as Record<string, ModelInfo>;
|
|
24
|
+
|
|
25
|
+
export const anthropicModels = {
|
|
26
|
+
'claude-3-7-sonnet-20250219': {
|
|
27
|
+
maxTokens: 8192,
|
|
28
|
+
contextWindow: 200_000,
|
|
29
|
+
supportsImages: true,
|
|
30
|
+
},
|
|
31
|
+
'claude-3-5-sonnet-20241022': {
|
|
32
|
+
maxTokens: 8192,
|
|
33
|
+
contextWindow: 200_000,
|
|
34
|
+
supportsImages: true,
|
|
35
|
+
},
|
|
36
|
+
'claude-3-5-haiku-20241022': {
|
|
37
|
+
maxTokens: 8192,
|
|
38
|
+
contextWindow: 200_000,
|
|
39
|
+
supportsImages: false,
|
|
40
|
+
},
|
|
41
|
+
'claude-3-opus-20240229': {
|
|
42
|
+
maxTokens: 4096,
|
|
43
|
+
contextWindow: 200_000,
|
|
44
|
+
supportsImages: true,
|
|
45
|
+
},
|
|
46
|
+
'claude-3-haiku-20240307': {
|
|
47
|
+
maxTokens: 4096,
|
|
48
|
+
contextWindow: 200_000,
|
|
49
|
+
supportsImages: true,
|
|
50
|
+
},
|
|
51
|
+
} as Record<string, ModelInfo>; // as const assertion makes the object deeply readonly
|
|
52
|
+
|
|
53
|
+
export const openAiNativeModels = {
|
|
54
|
+
'o3-mini': {
|
|
55
|
+
maxTokens: 100_000,
|
|
56
|
+
contextWindow: 200_000,
|
|
57
|
+
supportsImages: false,
|
|
58
|
+
},
|
|
59
|
+
// don't support tool use yet
|
|
60
|
+
o1: {
|
|
61
|
+
maxTokens: 100_000,
|
|
62
|
+
contextWindow: 200_000,
|
|
63
|
+
supportsImages: true,
|
|
64
|
+
},
|
|
65
|
+
'o1-preview': {
|
|
66
|
+
maxTokens: 32_768,
|
|
67
|
+
contextWindow: 128_000,
|
|
68
|
+
supportsImages: true,
|
|
69
|
+
},
|
|
70
|
+
'o1-mini': {
|
|
71
|
+
maxTokens: 65_536,
|
|
72
|
+
contextWindow: 128_000,
|
|
73
|
+
supportsImages: true,
|
|
74
|
+
},
|
|
75
|
+
'gpt-4o': {
|
|
76
|
+
maxTokens: 4_096,
|
|
77
|
+
contextWindow: 128_000,
|
|
78
|
+
supportsImages: true,
|
|
79
|
+
},
|
|
80
|
+
'gpt-4o-mini': {
|
|
81
|
+
maxTokens: 16_384,
|
|
82
|
+
contextWindow: 128_000,
|
|
83
|
+
supportsImages: true,
|
|
84
|
+
},
|
|
85
|
+
'gpt-4.5-preview': {
|
|
86
|
+
maxTokens: 16_384,
|
|
87
|
+
contextWindow: 128_000,
|
|
88
|
+
supportsImages: true,
|
|
89
|
+
},
|
|
90
|
+
} as Record<string, ModelInfo>;
|
package/src/common/types.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Injectable } from '@opensumi/di';
|
|
|
4
4
|
import { IAIBackServiceOption } from '@opensumi/ide-core-common';
|
|
5
5
|
import { AINativeSettingSectionsId } from '@opensumi/ide-core-common/lib/settings/ai-native';
|
|
6
6
|
|
|
7
|
+
import { ModelInfo, anthropicModels } from '../../common/model';
|
|
7
8
|
import { BaseLanguageModel } from '../base-language-model';
|
|
8
9
|
|
|
9
10
|
export const AnthropicModelIdentifier = Symbol('AnthropicModelIdentifier');
|
|
@@ -19,7 +20,11 @@ export class AnthropicModel extends BaseLanguageModel {
|
|
|
19
20
|
return createAnthropic({ apiKey });
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
protected getModelIdentifier(provider: AnthropicProvider) {
|
|
23
|
-
return provider(
|
|
23
|
+
protected getModelIdentifier(provider: AnthropicProvider, modelId = 'claude-3-5-sonnet-20241022') {
|
|
24
|
+
return provider(modelId);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected getModelInfo(modelId: string): ModelInfo | undefined {
|
|
28
|
+
return anthropicModels[modelId];
|
|
24
29
|
}
|
|
25
30
|
}
|
|
@@ -5,6 +5,7 @@ import { ChatMessageRole, IAIBackServiceOption, IChatMessage } from '@opensumi/i
|
|
|
5
5
|
import { ChatReadableStream } from '@opensumi/ide-core-node';
|
|
6
6
|
import { CancellationToken } from '@opensumi/ide-utils';
|
|
7
7
|
|
|
8
|
+
import { ModelInfo } from '../common';
|
|
8
9
|
import {
|
|
9
10
|
IToolInvocationRegistryManager,
|
|
10
11
|
ToolInvocationRegistryManager,
|
|
@@ -13,6 +14,8 @@ import {
|
|
|
13
14
|
|
|
14
15
|
@Injectable()
|
|
15
16
|
export abstract class BaseLanguageModel {
|
|
17
|
+
static ModelOptions: Record<string, ModelInfo>;
|
|
18
|
+
|
|
16
19
|
@Autowired(ToolInvocationRegistryManager)
|
|
17
20
|
protected readonly toolInvocationRegistryManager: IToolInvocationRegistryManager;
|
|
18
21
|
|
|
@@ -56,9 +59,6 @@ export abstract class BaseLanguageModel {
|
|
|
56
59
|
chatReadableStream,
|
|
57
60
|
options.history || [],
|
|
58
61
|
options.modelId,
|
|
59
|
-
options.temperature,
|
|
60
|
-
options.topP,
|
|
61
|
-
options.topK,
|
|
62
62
|
options.providerOptions,
|
|
63
63
|
options.trimTexts,
|
|
64
64
|
options.system,
|
|
@@ -78,6 +78,8 @@ export abstract class BaseLanguageModel {
|
|
|
78
78
|
|
|
79
79
|
protected abstract getModelIdentifier(provider: any, modelId?: string): any;
|
|
80
80
|
|
|
81
|
+
protected abstract getModelInfo(modelId: string): ModelInfo | undefined;
|
|
82
|
+
|
|
81
83
|
protected async handleStreamingRequest(
|
|
82
84
|
provider: any,
|
|
83
85
|
request: string,
|
|
@@ -85,9 +87,6 @@ export abstract class BaseLanguageModel {
|
|
|
85
87
|
chatReadableStream: ChatReadableStream,
|
|
86
88
|
history: IChatMessage[] = [],
|
|
87
89
|
modelId?: string,
|
|
88
|
-
temperature?: number,
|
|
89
|
-
topP?: number,
|
|
90
|
-
topK?: number,
|
|
91
90
|
providerOptions?: Record<string, any>,
|
|
92
91
|
trimTexts?: [string, string],
|
|
93
92
|
systemPrompt?: string,
|
|
@@ -110,6 +109,7 @@ export abstract class BaseLanguageModel {
|
|
|
110
109
|
})),
|
|
111
110
|
{ role: 'user', content: request },
|
|
112
111
|
];
|
|
112
|
+
const modelInfo = modelId ? this.getModelInfo(modelId) : undefined;
|
|
113
113
|
const stream = streamText({
|
|
114
114
|
model: this.getModelIdentifier(provider, modelId),
|
|
115
115
|
tools: aiTools,
|
|
@@ -117,9 +117,9 @@ export abstract class BaseLanguageModel {
|
|
|
117
117
|
abortSignal: abortController.signal,
|
|
118
118
|
experimental_toolCallStreaming: true,
|
|
119
119
|
maxSteps: 12,
|
|
120
|
-
temperature,
|
|
121
|
-
topP: topP || 0.8,
|
|
122
|
-
topK: topK || 1,
|
|
120
|
+
temperature: modelInfo?.temperature || 0,
|
|
121
|
+
topP: modelInfo?.topP || 0.8,
|
|
122
|
+
topK: modelInfo?.topK || 1,
|
|
123
123
|
system: systemPrompt,
|
|
124
124
|
providerOptions,
|
|
125
125
|
});
|
|
@@ -4,6 +4,7 @@ import { Injectable } from '@opensumi/di';
|
|
|
4
4
|
import { IAIBackServiceOption } from '@opensumi/ide-core-common';
|
|
5
5
|
import { AINativeSettingSectionsId } from '@opensumi/ide-core-common/lib/settings/ai-native';
|
|
6
6
|
|
|
7
|
+
import { ModelInfo, deepSeekModels } from '../../common';
|
|
7
8
|
import { BaseLanguageModel } from '../base-language-model';
|
|
8
9
|
|
|
9
10
|
export const DeepSeekModelIdentifier = Symbol('DeepSeekModelIdentifier');
|
|
@@ -19,7 +20,11 @@ export class DeepSeekModel extends BaseLanguageModel {
|
|
|
19
20
|
return createDeepSeek({ apiKey });
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
protected getModelIdentifier(provider: DeepSeekProvider) {
|
|
23
|
-
return provider(
|
|
23
|
+
protected getModelIdentifier(provider: DeepSeekProvider, modelId = 'deepseek-chat') {
|
|
24
|
+
return provider(modelId);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected getModelInfo(modelId: string): ModelInfo | undefined {
|
|
28
|
+
return deepSeekModels[modelId];
|
|
24
29
|
}
|
|
25
30
|
}
|
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OpenAIProvider, createOpenAI } from '@ai-sdk/openai';
|
|
2
2
|
import { LanguageModelV1 } from 'ai';
|
|
3
3
|
|
|
4
4
|
import { Injectable } from '@opensumi/di';
|
|
5
5
|
import { AINativeSettingSectionsId, IAIBackServiceOption } from '@opensumi/ide-core-common';
|
|
6
6
|
|
|
7
|
+
import { ModelInfo, openAiNativeModels } from '../../common/model';
|
|
7
8
|
import { BaseLanguageModel } from '../base-language-model';
|
|
8
9
|
|
|
9
|
-
export const DeepSeekModelIdentifier = Symbol('DeepSeekModelIdentifier');
|
|
10
|
-
|
|
11
10
|
@Injectable()
|
|
12
11
|
export class OpenAIModel extends BaseLanguageModel {
|
|
13
|
-
protected initializeProvider(options: IAIBackServiceOption):
|
|
12
|
+
protected initializeProvider(options: IAIBackServiceOption): OpenAIProvider {
|
|
14
13
|
const apiKey = options.apiKey;
|
|
15
14
|
if (!apiKey) {
|
|
16
15
|
throw new Error(`Please provide OpenAI API Key in preferences (${AINativeSettingSectionsId.OpenaiApiKey})`);
|
|
17
16
|
}
|
|
18
|
-
return
|
|
17
|
+
return createOpenAI({
|
|
19
18
|
apiKey,
|
|
20
|
-
baseURL: options.baseURL || 'https://dashscope.aliyuncs.com/compatible-mode/v1',
|
|
21
|
-
name: 'openai',
|
|
22
19
|
});
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
protected getModelIdentifier(provider:
|
|
26
|
-
return provider(modelId
|
|
22
|
+
protected getModelIdentifier(provider: OpenAIProvider, modelId: string) {
|
|
23
|
+
return provider(modelId) as LanguageModelV1;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected getModelInfo(modelId: string): ModelInfo | undefined {
|
|
27
|
+
return openAiNativeModels[modelId];
|
|
27
28
|
}
|
|
28
29
|
}
|