@opensumi/ide-ai-native 3.7.1-next-1738917599.0 → 3.7.1-next-1738979076.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.
Files changed (26) hide show
  1. package/lib/browser/layout/layout.module.less +9 -9
  2. package/lib/browser/layout/tabbar.view.d.ts.map +1 -1
  3. package/lib/browser/layout/tabbar.view.js +5 -6
  4. package/lib/browser/layout/tabbar.view.js.map +1 -1
  5. package/lib/browser/widget/inline-chat/inline-content-widget.d.ts.map +1 -1
  6. package/lib/browser/widget/inline-chat/inline-content-widget.js +5 -0
  7. package/lib/browser/widget/inline-chat/inline-content-widget.js.map +1 -1
  8. package/lib/browser/widget/inline-input/inline-input-widget.d.ts +3 -5
  9. package/lib/browser/widget/inline-input/inline-input-widget.d.ts.map +1 -1
  10. package/lib/browser/widget/inline-input/inline-input-widget.js +10 -14
  11. package/lib/browser/widget/inline-input/inline-input-widget.js.map +1 -1
  12. package/lib/browser/widget/inline-input/inline-input.controller.d.ts +0 -3
  13. package/lib/browser/widget/inline-input/inline-input.controller.d.ts.map +1 -1
  14. package/lib/browser/widget/inline-input/inline-input.controller.js +36 -80
  15. package/lib/browser/widget/inline-input/inline-input.controller.js.map +1 -1
  16. package/lib/browser/widget/inline-input/model.d.ts +1 -19
  17. package/lib/browser/widget/inline-input/model.d.ts.map +1 -1
  18. package/lib/browser/widget/inline-input/model.js +1 -39
  19. package/lib/browser/widget/inline-input/model.js.map +1 -1
  20. package/package.json +21 -21
  21. package/src/browser/layout/layout.module.less +9 -9
  22. package/src/browser/layout/tabbar.view.tsx +10 -8
  23. package/src/browser/widget/inline-chat/inline-content-widget.tsx +7 -0
  24. package/src/browser/widget/inline-input/inline-input-widget.tsx +5 -14
  25. package/src/browser/widget/inline-input/inline-input.controller.ts +42 -110
  26. package/src/browser/widget/inline-input/model.ts +1 -41
@@ -15,13 +15,6 @@ import {
15
15
  import { EditorGroupCloseEvent } from '@opensumi/ide-editor/lib/browser';
16
16
  import * as monaco from '@opensumi/ide-monaco';
17
17
  import { ICodeEditor } from '@opensumi/ide-monaco';
18
- import {
19
- IObservable,
20
- ISettableObservable,
21
- autorun,
22
- observableFromEvent,
23
- observableValue,
24
- } from '@opensumi/ide-monaco/lib/common/observable';
25
18
  import { MessageService } from '@opensumi/ide-overlay/lib/browser/message.service';
26
19
  import { EditOperation } from '@opensumi/monaco-editor-core/esm/vs/editor/common/core/editOperation';
27
20
  import { LineRange } from '@opensumi/monaco-editor-core/esm/vs/editor/common/core/lineRange';
@@ -35,10 +28,10 @@ import { EInlineChatStatus, EResultKind } from '../inline-chat/inline-chat.servi
35
28
  import { InlineDiffController } from '../inline-diff';
36
29
  import { InlineInputPreviewDecorationID } from '../internal.type';
37
30
 
38
- import { InlineInputWidget } from './inline-input-widget';
31
+ import { InlineInputChatWidget } from './inline-input-widget';
39
32
  import styles from './inline-input.module.less';
40
33
  import { InlineInputService } from './inline-input.service';
41
- import { InlineInputWidgetStoreInEmptyLine, InlineInputWidgetStoreInSelection } from './model';
34
+
42
35
  @Injectable()
43
36
  export class InlineInputController extends BaseAIMonacoEditorController {
44
37
  public static readonly ID = 'editor.contrib.ai.inline.input';
@@ -67,25 +60,11 @@ export class InlineInputController extends BaseAIMonacoEditorController {
67
60
  private inputDisposable: Disposable;
68
61
  private aiNativeContextKey: AINativeContextKey;
69
62
 
70
- private inputValue: ISettableObservable<string>;
71
- private modelChangeObs: IObservable<monaco.editor.ITextModel, unknown>;
72
- private inlineInputWidgetStore = new Map<
73
- string,
74
- InlineInputWidgetStoreInEmptyLine | InlineInputWidgetStoreInSelection | null
75
- >();
76
-
77
63
  mount(): IDisposable {
78
64
  this.inputDisposable = new Disposable();
79
65
  this.aiNativeContextKey = this.injector.get(AINativeContextKey, [this.monacoEditor.contextKeyService]);
80
66
  this.inlineDiffController = InlineDiffController.get(this.monacoEditor)!;
81
67
 
82
- this.inputValue = observableValue(this, '');
83
- this.modelChangeObs = observableFromEvent<monaco.editor.ITextModel>(
84
- this,
85
- this.monacoEditor.onDidChangeModel,
86
- () => this.monacoEditor.getModel()!,
87
- );
88
-
89
68
  this.featureDisposable.addDispose(
90
69
  /**
91
70
  * 如果在流式过程中,直接关闭了当前文件,则需要销毁 diff previewer 并隐藏 input,恢复原始代码
@@ -112,7 +91,10 @@ export class InlineInputController extends BaseAIMonacoEditorController {
112
91
  );
113
92
 
114
93
  this.featureDisposable.addDispose(
115
- this.inlineInputService.onHidden(() => {
94
+ Event.any<any>(
95
+ this.inlineInputService.onHidden,
96
+ this.monacoEditor.onWillChangeModel,
97
+ )(() => {
116
98
  this.hideInput();
117
99
  }),
118
100
  );
@@ -137,27 +119,6 @@ export class InlineInputController extends BaseAIMonacoEditorController {
137
119
  }),
138
120
  );
139
121
 
140
- this.featureDisposable.addDispose(
141
- autorun((reader) => {
142
- const model = this.modelChangeObs.read(reader);
143
- if (!model) {
144
- return;
145
- }
146
-
147
- const storeData = this.inlineInputWidgetStore.get(model.id);
148
- if (!storeData) {
149
- this.hideInput();
150
- return;
151
- }
152
-
153
- if (storeData instanceof InlineInputWidgetStoreInEmptyLine) {
154
- this.showInputInEmptyLine(storeData.getPosition(), this.monacoEditor, storeData.getValue());
155
- } else if (storeData instanceof InlineInputWidgetStoreInSelection) {
156
- this.showInputInSelection(storeData.getSelection(), this.monacoEditor, storeData.getValue());
157
- }
158
- }),
159
- );
160
-
161
122
  this.featureDisposable.addDispose(this.inputDisposable);
162
123
 
163
124
  return this.featureDisposable;
@@ -169,7 +130,6 @@ export class InlineInputController extends BaseAIMonacoEditorController {
169
130
  }
170
131
 
171
132
  private hideInput() {
172
- this.inlineInputWidgetStore.delete(this.monacoEditor.getModel()!.id);
173
133
  this.inputDisposable.dispose();
174
134
  }
175
135
 
@@ -185,16 +145,15 @@ export class InlineInputController extends BaseAIMonacoEditorController {
185
145
  return;
186
146
  }
187
147
 
188
- this.inputValue.set(defaultValue || '', undefined);
189
- this.inlineInputWidgetStore.set(model.id, new InlineInputWidgetStoreInEmptyLine(position, defaultValue));
190
-
191
148
  if (this.inputDisposable) {
192
149
  this.inputDisposable.dispose();
193
150
  this.inputDisposable = new Disposable();
194
151
  }
195
152
 
196
153
  const collection = monacoEditor.createDecorationsCollection();
197
- const inlineInputWidget = this.injector.get(InlineInputWidget, [monacoEditor, this.inputValue.get()]);
154
+ const inlineInputChatWidget = this.injector.get(InlineInputChatWidget, [monacoEditor, defaultValue]);
155
+
156
+ let inputValue = defaultValue;
198
157
 
199
158
  // 仅在空行情况下增加装饰逻辑
200
159
  collection.append([
@@ -213,12 +172,12 @@ export class InlineInputController extends BaseAIMonacoEditorController {
213
172
  let preLineRange: LineRange;
214
173
  if (decorationRange) {
215
174
  preLineRange = LineRange.fromRange(decorationRange);
216
- inlineInputWidget.show({ position: decorationRange.getStartPosition() });
175
+ inlineInputChatWidget.show({ position: decorationRange.getStartPosition() });
217
176
  this.aiNativeContextKey.inlineInputWidgetIsVisible.set(true);
218
177
  }
219
178
 
220
179
  this.inputDisposable.addDispose(
221
- inlineInputWidget.onDispose(() => {
180
+ inlineInputChatWidget.onDispose(() => {
222
181
  this.cancelToken();
223
182
  collection.clear();
224
183
  this.aiNativeContextKey.inlineInputWidgetIsVisible.set(false);
@@ -226,18 +185,7 @@ export class InlineInputController extends BaseAIMonacoEditorController {
226
185
  );
227
186
 
228
187
  this.inputDisposable.addDispose(
229
- inlineInputWidget.onValueChange((value) => {
230
- this.inputValue.set(value, undefined);
231
-
232
- const storeData = this.inlineInputWidgetStore.get(model.id);
233
- if (storeData instanceof InlineInputWidgetStoreInEmptyLine) {
234
- storeData.setValue(value);
235
- }
236
- }),
237
- );
238
-
239
- this.inputDisposable.addDispose(
240
- inlineInputWidget.onResultClick(async (kind: EResultKind) => {
188
+ inlineInputChatWidget.onResultClick(async (kind: EResultKind) => {
241
189
  const clear = () => {
242
190
  const curPosi = collection.getRange(0)!;
243
191
 
@@ -262,7 +210,7 @@ export class InlineInputController extends BaseAIMonacoEditorController {
262
210
  */
263
211
  const curPosi = collection.getRange(0)!;
264
212
  const curPosition = curPosi.getStartPosition();
265
- this.showInputInEmptyLine(curPosition, monacoEditor, this.inputValue.get());
213
+ this.showInputInEmptyLine(curPosition, monacoEditor, inputValue);
266
214
  });
267
215
  break;
268
216
 
@@ -285,18 +233,18 @@ export class InlineInputController extends BaseAIMonacoEditorController {
285
233
  const range = collection.getRange(0)!;
286
234
  const curLineRange = LineRange.fromRange(range);
287
235
  if (!preLineRange.equals(curLineRange)) {
288
- inlineInputWidget.setOptions({
236
+ inlineInputChatWidget.setOptions({
289
237
  position: range.getStartPosition(),
290
238
  });
291
239
 
292
- inlineInputWidget.layoutContentWidget();
240
+ inlineInputChatWidget.layoutContentWidget();
293
241
  }
294
242
  preLineRange = curLineRange;
295
243
  }),
296
244
  );
297
245
 
298
246
  this.inputDisposable.addDispose(
299
- inlineInputWidget.onClose(() => {
247
+ inlineInputChatWidget.onClose(() => {
300
248
  const isStreaming = this.aiNativeContextKey.inlineInputWidgetIsStreaming.get();
301
249
  if (isStreaming) {
302
250
  this.cancelToken();
@@ -307,7 +255,8 @@ export class InlineInputController extends BaseAIMonacoEditorController {
307
255
  );
308
256
 
309
257
  this.inputDisposable.addDispose(
310
- inlineInputWidget.onSend(async (value) => {
258
+ inlineInputChatWidget.onInteractiveInputValue(async (value) => {
259
+ inputValue = value;
311
260
  monacoEditor.focus();
312
261
 
313
262
  const handler = this.inlineInputService.getInteractiveInputHandler();
@@ -317,13 +266,13 @@ export class InlineInputController extends BaseAIMonacoEditorController {
317
266
  return;
318
267
  }
319
268
 
320
- inlineInputWidget.launchChatStatus(EInlineChatStatus.THINKING);
269
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.THINKING);
321
270
 
322
271
  const strategy = await this.inlineInputService.getInteractiveInputStrategyHandler()(monacoEditor, value);
323
272
 
324
273
  if (strategy === ERunStrategy.EXECUTE && handler.execute) {
325
274
  handler.execute(monacoEditor, value, this.token);
326
- inlineInputWidget.launchChatStatus(EInlineChatStatus.DONE);
275
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.DONE);
327
276
  this.hideInput();
328
277
  return;
329
278
  }
@@ -332,7 +281,7 @@ export class InlineInputController extends BaseAIMonacoEditorController {
332
281
  const previewResponse = await handler.providePreviewStrategy(monacoEditor, value, this.token);
333
282
 
334
283
  if (CancelResponse.is(previewResponse)) {
335
- inlineInputWidget.launchChatStatus(EInlineChatStatus.READY);
284
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.READY);
336
285
  this.hideInput();
337
286
  return;
338
287
  }
@@ -365,17 +314,17 @@ export class InlineInputController extends BaseAIMonacoEditorController {
365
314
  }),
366
315
  controller.onError((error) => {
367
316
  this.aiNativeContextKey.inlineInputWidgetIsStreaming.set(false);
368
- inlineInputWidget.launchChatStatus(EInlineChatStatus.ERROR);
317
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.ERROR);
369
318
  }),
370
319
  controller.onAbort(() => {
371
320
  this.aiNativeContextKey.inlineInputWidgetIsStreaming.set(false);
372
321
  model.pushStackElement();
373
- inlineInputWidget.launchChatStatus(EInlineChatStatus.DONE);
322
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.DONE);
374
323
  }),
375
324
  controller.onEnd(() => {
376
325
  this.aiNativeContextKey.inlineInputWidgetIsStreaming.set(false);
377
326
  model.pushStackElement();
378
- inlineInputWidget.launchChatStatus(EInlineChatStatus.DONE);
327
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.DONE);
379
328
  }),
380
329
  ]);
381
330
 
@@ -385,7 +334,7 @@ export class InlineInputController extends BaseAIMonacoEditorController {
385
334
  }),
386
335
  );
387
336
 
388
- this.inputDisposable.addDispose(inlineInputWidget);
337
+ this.inputDisposable.addDispose(inlineInputChatWidget);
389
338
  }
390
339
 
391
340
  private async showInputInSelection(selection: monaco.Selection, monacoEditor: ICodeEditor, defaultValue?: string) {
@@ -394,14 +343,6 @@ export class InlineInputController extends BaseAIMonacoEditorController {
394
343
  this.inputDisposable = new Disposable();
395
344
  }
396
345
 
397
- const model = monacoEditor.getModel();
398
- if (!model) {
399
- return;
400
- }
401
-
402
- this.inputValue.set(defaultValue || '', undefined);
403
- this.inlineInputWidgetStore.set(model.id, new InlineInputWidgetStoreInSelection(selection, defaultValue));
404
-
405
346
  const decorationsCollection = monacoEditor.createDecorationsCollection();
406
347
  decorationsCollection.set([
407
348
  {
@@ -420,14 +361,15 @@ export class InlineInputController extends BaseAIMonacoEditorController {
420
361
  },
421
362
  ]);
422
363
 
423
- const inlineInputWidget = this.injector.get(InlineInputWidget, [monacoEditor, this.inputValue.get()]);
424
- inlineInputWidget.show({ selection });
364
+ const inlineInputChatWidget = this.injector.get(InlineInputChatWidget, [monacoEditor, defaultValue]);
365
+ inlineInputChatWidget.show({ selection });
425
366
 
426
367
  this.aiNativeContextKey.inlineInputWidgetIsVisible.set(true);
427
368
  this.inlineDiffController.destroyPreviewer(monacoEditor.getModel()?.uri.toString());
369
+ let inputValue = defaultValue;
428
370
 
429
371
  this.inputDisposable.addDispose(
430
- inlineInputWidget.onDispose(() => {
372
+ inlineInputChatWidget.onDispose(() => {
431
373
  this.cancelToken();
432
374
  decorationsCollection.clear();
433
375
  this.aiNativeContextKey.inlineInputWidgetIsVisible.set(false);
@@ -435,18 +377,7 @@ export class InlineInputController extends BaseAIMonacoEditorController {
435
377
  );
436
378
 
437
379
  this.inputDisposable.addDispose(
438
- inlineInputWidget.onValueChange((value) => {
439
- this.inputValue.set(value, undefined);
440
-
441
- const storeData = this.inlineInputWidgetStore.get(model.id);
442
- if (storeData instanceof InlineInputWidgetStoreInSelection) {
443
- storeData.setValue(value);
444
- }
445
- }),
446
- );
447
-
448
- this.inputDisposable.addDispose(
449
- inlineInputWidget.onClose(() => {
380
+ inlineInputChatWidget.onClose(() => {
450
381
  const isStreaming = this.aiNativeContextKey.inlineInputWidgetIsStreaming.get();
451
382
  if (isStreaming) {
452
383
  this.cancelToken();
@@ -457,7 +388,8 @@ export class InlineInputController extends BaseAIMonacoEditorController {
457
388
  );
458
389
 
459
390
  this.inputDisposable.addDispose(
460
- inlineInputWidget.onSend(async (value) => {
391
+ inlineInputChatWidget.onInteractiveInputValue(async (value) => {
392
+ inputValue = value;
461
393
  monacoEditor.focus();
462
394
  decorationsCollection.clear();
463
395
 
@@ -467,7 +399,7 @@ export class InlineInputController extends BaseAIMonacoEditorController {
467
399
  return;
468
400
  }
469
401
 
470
- inlineInputWidget.launchChatStatus(EInlineChatStatus.THINKING);
402
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.THINKING);
471
403
 
472
404
  const strategy = await this.inlineInputService.getInteractiveInputStrategyHandler()(monacoEditor, value);
473
405
 
@@ -479,7 +411,7 @@ export class InlineInputController extends BaseAIMonacoEditorController {
479
411
  const previewResponse = await handler.providePreviewStrategy(monacoEditor, value, this.token);
480
412
 
481
413
  if (CancelResponse.is(previewResponse)) {
482
- inlineInputWidget.launchChatStatus(EInlineChatStatus.READY);
414
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.READY);
483
415
  this.hideInput();
484
416
  return;
485
417
  }
@@ -495,15 +427,15 @@ export class InlineInputController extends BaseAIMonacoEditorController {
495
427
  }),
496
428
  chatResponse.onError((error) => {
497
429
  this.aiNativeContextKey.inlineInputWidgetIsStreaming.set(false);
498
- inlineInputWidget.launchChatStatus(EInlineChatStatus.ERROR);
430
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.ERROR);
499
431
  }),
500
432
  chatResponse.onAbort(() => {
501
433
  this.aiNativeContextKey.inlineInputWidgetIsStreaming.set(false);
502
- inlineInputWidget.launchChatStatus(EInlineChatStatus.DONE);
434
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.DONE);
503
435
  }),
504
436
  chatResponse.onEnd(() => {
505
437
  this.aiNativeContextKey.inlineInputWidgetIsStreaming.set(false);
506
- inlineInputWidget.launchChatStatus(EInlineChatStatus.DONE);
438
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.DONE);
507
439
  }),
508
440
  ]);
509
441
 
@@ -513,28 +445,28 @@ export class InlineInputController extends BaseAIMonacoEditorController {
513
445
  crossSelection,
514
446
  chatResponse,
515
447
  });
516
- diffPreviewer.mount(inlineInputWidget);
448
+ diffPreviewer.mount(inlineInputChatWidget);
517
449
  }
518
450
  } else {
519
- inlineInputWidget.launchChatStatus(EInlineChatStatus.READY);
451
+ inlineInputChatWidget.launchChatStatus(EInlineChatStatus.READY);
520
452
  this.hideInput();
521
453
  }
522
454
  }),
523
455
  );
524
456
 
525
457
  this.inputDisposable.addDispose(
526
- inlineInputWidget.onResultClick((kind: EResultKind) => {
458
+ inlineInputChatWidget.onResultClick((kind: EResultKind) => {
527
459
  this.inlineDiffController.handleAction(kind);
528
460
  this.hideInput();
529
461
 
530
462
  if (kind === EResultKind.REGENERATE) {
531
463
  requestAnimationFrame(() => {
532
- this.showInputInSelection(selection, monacoEditor, this.inputValue.get());
464
+ this.showInputInSelection(selection, monacoEditor, inputValue);
533
465
  });
534
466
  }
535
467
  }),
536
468
  );
537
469
 
538
- this.inputDisposable.addDispose(inlineInputWidget);
470
+ this.inputDisposable.addDispose(inlineInputChatWidget);
539
471
  }
540
472
  }
@@ -1,6 +1,6 @@
1
1
  import { InteractiveInput } from '@opensumi/ide-core-browser/lib/components/ai-native';
2
2
  import { MaybePromise, uuid } from '@opensumi/ide-core-common';
3
- import { ICodeEditor, IPosition, Selection } from '@opensumi/ide-monaco';
3
+ import { ICodeEditor } from '@opensumi/ide-monaco';
4
4
 
5
5
  import { ERunStrategy, IInteractiveInputHandler } from '../../types';
6
6
 
@@ -32,43 +32,3 @@ export class InteractiveInputModel {
32
32
  this._handler = undefined;
33
33
  }
34
34
  }
35
-
36
- export class InlineInputWidgetStoreInEmptyLine {
37
- constructor(private position: IPosition, private value?: string) {}
38
-
39
- public getPosition(): IPosition {
40
- return this.position;
41
- }
42
-
43
- public setPosition(position: IPosition): void {
44
- this.position = position;
45
- }
46
-
47
- public getValue(): string | undefined {
48
- return this.value;
49
- }
50
-
51
- public setValue(value: string): void {
52
- this.value = value;
53
- }
54
- }
55
-
56
- export class InlineInputWidgetStoreInSelection {
57
- constructor(private selection: Selection, private value?: string) {}
58
-
59
- public getSelection(): Selection {
60
- return this.selection;
61
- }
62
-
63
- public setSelection(selection: Selection): void {
64
- this.selection = selection;
65
- }
66
-
67
- public getValue(): string | undefined {
68
- return this.value;
69
- }
70
-
71
- public setValue(value: string): void {
72
- this.value = value;
73
- }
74
- }