@theia/ai-chat 1.74.0 → 1.74.1

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.
@@ -15,7 +15,7 @@
15
15
  // *****************************************************************************
16
16
 
17
17
  import { expect } from 'chai';
18
- import { MutableChatResponseModel, ToolCallChatResponseContentImpl } from './chat-model';
18
+ import { MarkdownChatResponseContentImpl, MutableChatResponseModel, ToolCallChatResponseContentImpl } from './chat-model';
19
19
 
20
20
  describe('MutableChatResponseModel', () => {
21
21
  describe('content change propagation', () => {
@@ -35,6 +35,46 @@ describe('MutableChatResponseModel', () => {
35
35
  // lost on reload.
36
36
  expect(fireCount).to.equal(1);
37
37
  });
38
+
39
+ it('should not accumulate duplicate listeners when content is cleared and re-added', () => {
40
+ const response = new MutableChatResponseModel('req-1');
41
+ const toolCall = new ToolCallChatResponseContentImpl('tool-1', 'tool', '{}', false);
42
+ response.response.addContent(toolCall);
43
+
44
+ // Simulate AbstractStreamParsingChatAgent.addStreamResponse: for every streamed
45
+ // text token, the whole content is cleared and re-added, tool call included.
46
+ for (let i = 0; i < 10; i++) {
47
+ const contentBeforeMarker = response.response.content.slice(0, 1);
48
+ response.response.clearContent();
49
+ response.response.addContents(contentBeforeMarker);
50
+ response.response.addContents([new MarkdownChatResponseContentImpl(`token ${i}`)]);
51
+ }
52
+
53
+ let fireCount = 0;
54
+ response.onDidChange(() => { fireCount++; });
55
+
56
+ toolCall.updateResult('result');
57
+
58
+ // A single tool call change must fire exactly once, no matter how often the
59
+ // content array was rebuilt during streaming (see #17858).
60
+ expect(fireCount).to.equal(1);
61
+ });
62
+
63
+ it('should stop propagating changes of content that was cleared and not re-added', () => {
64
+ const response = new MutableChatResponseModel('req-1');
65
+ const toolCall = new ToolCallChatResponseContentImpl('tool-1', 'tool', '{}', false);
66
+ response.response.addContent(toolCall);
67
+ response.response.clearContent();
68
+
69
+ let fireCount = 0;
70
+ response.onDidChange(() => { fireCount++; });
71
+
72
+ toolCall.updateResult('result');
73
+
74
+ // Content that is no longer part of the response must not trigger response changes
75
+ // (and with that auto-save) anymore.
76
+ expect(fireCount).to.equal(0);
77
+ });
38
78
  });
39
79
 
40
80
  describe('setTokenUsage', () => {