mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
fix(cli): correctly handle tool invocation cancellation (#844)
This commit is contained in:
@@ -219,4 +219,22 @@ describe('Gemini Client (client.ts)', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addHistory', () => {
|
||||
it('should call chat.addHistory with the provided content', async () => {
|
||||
const mockChat = {
|
||||
addHistory: vi.fn(),
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
client['chat'] = Promise.resolve(mockChat as any);
|
||||
|
||||
const newContent = {
|
||||
role: 'user',
|
||||
parts: [{ text: 'New history item' }],
|
||||
};
|
||||
await client.addHistory(newContent);
|
||||
|
||||
expect(mockChat.addHistory).toHaveBeenCalledWith(newContent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,6 +58,11 @@ export class GeminiClient {
|
||||
this.chat = this.startChat();
|
||||
}
|
||||
|
||||
async addHistory(content: Content) {
|
||||
const chat = await this.chat;
|
||||
chat.addHistory(content);
|
||||
}
|
||||
|
||||
getChat(): Promise<GeminiChat> {
|
||||
return this.chat;
|
||||
}
|
||||
|
||||
@@ -352,4 +352,34 @@ describe('GeminiChat', () => {
|
||||
expect(history[1].parts).toEqual([{ text: 'Visible text' }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addHistory', () => {
|
||||
it('should add a new content item to the history', () => {
|
||||
const newContent: Content = {
|
||||
role: 'user',
|
||||
parts: [{ text: 'A new message' }],
|
||||
};
|
||||
chat.addHistory(newContent);
|
||||
const history = chat.getHistory();
|
||||
expect(history.length).toBe(1);
|
||||
expect(history[0]).toEqual(newContent);
|
||||
});
|
||||
|
||||
it('should add multiple items correctly', () => {
|
||||
const content1: Content = {
|
||||
role: 'user',
|
||||
parts: [{ text: 'Message 1' }],
|
||||
};
|
||||
const content2: Content = {
|
||||
role: 'model',
|
||||
parts: [{ text: 'Message 2' }],
|
||||
};
|
||||
chat.addHistory(content1);
|
||||
chat.addHistory(content2);
|
||||
const history = chat.getHistory();
|
||||
expect(history.length).toBe(2);
|
||||
expect(history[0]).toEqual(content1);
|
||||
expect(history[1]).toEqual(content2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -287,6 +287,15 @@ export class GeminiChat {
|
||||
return structuredClone(history);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new entry to the chat history.
|
||||
*
|
||||
* @param content - The content to add to the history.
|
||||
*/
|
||||
addHistory(content: Content): void {
|
||||
this.history.push(content);
|
||||
}
|
||||
|
||||
private async *processStreamResponse(
|
||||
streamResponse: AsyncGenerator<GenerateContentResponse>,
|
||||
inputContent: Content,
|
||||
|
||||
Reference in New Issue
Block a user