mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
Add promptContent parameter to ConversationContent class
This change adds a new promptContent parameter to the ConversationContent constructor and updates all related code including serialization, deserialization, and tests to support this new field.
This commit is contained in:
parent
679a94d173
commit
e551155230
4 changed files with 47 additions and 11 deletions
|
|
@ -35,6 +35,7 @@ export class ConversationFileSystemService {
|
|||
.map(content => ({
|
||||
role: content.role,
|
||||
content: content.content,
|
||||
promptContent: content.promptContent,
|
||||
functionCall: content.functionCall,
|
||||
timestamp: content.timestamp.toISOString(),
|
||||
isFunctionCall: content.isFunctionCall,
|
||||
|
|
@ -86,7 +87,7 @@ export class ConversationFileSystemService {
|
|||
conversation.updated = new Date(data.updated);
|
||||
conversation.contents = data.contents.map(content => {
|
||||
return new ConversationContent(
|
||||
content.role, content.content, content.functionCall, new Date(content.timestamp), content.isFunctionCall, content.isFunctionCallResponse, content.toolId);
|
||||
content.role, content.content, content.promptContent, content.functionCall, new Date(content.timestamp), content.isFunctionCall, content.isFunctionCallResponse, content.toolId);
|
||||
});
|
||||
conversations.push(conversation);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { Conversation } from '../../Conversations/Conversation';
|
||||
import { ConversationContent } from '../../Conversations/ConversationContent';
|
||||
|
||||
|
|
@ -62,6 +62,7 @@ describe('Conversation', () => {
|
|||
{
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -190,6 +191,7 @@ describe('Conversation', () => {
|
|||
{
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -312,7 +314,7 @@ describe('Conversation', () => {
|
|||
|
||||
it('should overwrite existing function call', () => {
|
||||
const conversation = new Conversation();
|
||||
const content = new ConversationContent('assistant', '', 'oldFunction', new Date(), true);
|
||||
const content = new ConversationContent('assistant', '', '', 'oldFunction', new Date(), true);
|
||||
conversation.contents.push(content);
|
||||
|
||||
conversation.setMostRecentFunctionCall('newFunction');
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ describe('ConversationContent', () => {
|
|||
const content = new ConversationContent(
|
||||
'user',
|
||||
'Hello',
|
||||
'promptContent',
|
||||
'functionCall',
|
||||
timestamp,
|
||||
true,
|
||||
|
|
@ -17,6 +18,7 @@ describe('ConversationContent', () => {
|
|||
|
||||
expect(content.role).toBe('user');
|
||||
expect(content.content).toBe('Hello');
|
||||
expect(content.promptContent).toBe('promptContent');
|
||||
expect(content.functionCall).toBe('functionCall');
|
||||
expect(content.timestamp).toBe(timestamp);
|
||||
expect(content.isFunctionCall).toBe(true);
|
||||
|
|
@ -29,6 +31,7 @@ describe('ConversationContent', () => {
|
|||
|
||||
expect(content.role).toBe('assistant');
|
||||
expect(content.content).toBe('');
|
||||
expect(content.promptContent).toBe('');
|
||||
expect(content.functionCall).toBe('');
|
||||
expect(content.timestamp).toBeInstanceOf(Date);
|
||||
expect(content.isFunctionCall).toBe(false);
|
||||
|
|
@ -46,10 +49,11 @@ describe('ConversationContent', () => {
|
|||
});
|
||||
|
||||
it('should accept partial optional parameters', () => {
|
||||
const content = new ConversationContent('user', 'Hello', 'someFunction');
|
||||
const content = new ConversationContent('user', 'Hello', '', 'someFunction');
|
||||
|
||||
expect(content.role).toBe('user');
|
||||
expect(content.content).toBe('Hello');
|
||||
expect(content.promptContent).toBe('');
|
||||
expect(content.functionCall).toBe('someFunction');
|
||||
expect(content.timestamp).toBeInstanceOf(Date);
|
||||
expect(content.isFunctionCall).toBe(false);
|
||||
|
|
@ -76,6 +80,7 @@ describe('ConversationContent', () => {
|
|||
const content = new ConversationContent(
|
||||
'assistant',
|
||||
'',
|
||||
'',
|
||||
'readFile',
|
||||
new Date(),
|
||||
true,
|
||||
|
|
@ -95,6 +100,7 @@ describe('ConversationContent', () => {
|
|||
'user',
|
||||
'File contents here',
|
||||
'',
|
||||
'',
|
||||
new Date(),
|
||||
false,
|
||||
true,
|
||||
|
|
@ -114,6 +120,7 @@ describe('ConversationContent', () => {
|
|||
const validData = {
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -127,6 +134,7 @@ describe('ConversationContent', () => {
|
|||
const validData = {
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
promptContent: '',
|
||||
functionCall: 'readFile',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: true,
|
||||
|
|
@ -151,6 +159,7 @@ describe('ConversationContent', () => {
|
|||
it('should return false when role is missing', () => {
|
||||
const invalidData = {
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -164,6 +173,7 @@ describe('ConversationContent', () => {
|
|||
const invalidData = {
|
||||
role: 123,
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -176,6 +186,7 @@ describe('ConversationContent', () => {
|
|||
it('should return false when content is missing', () => {
|
||||
const invalidData = {
|
||||
role: 'user',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -189,6 +200,7 @@ describe('ConversationContent', () => {
|
|||
const invalidData = {
|
||||
role: 'user',
|
||||
content: 123,
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -202,6 +214,7 @@ describe('ConversationContent', () => {
|
|||
const invalidData = {
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
isFunctionCallResponse: false
|
||||
|
|
@ -214,6 +227,7 @@ describe('ConversationContent', () => {
|
|||
const invalidData = {
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: null,
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -227,6 +241,7 @@ describe('ConversationContent', () => {
|
|||
const invalidData = {
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
isFunctionCall: false,
|
||||
isFunctionCallResponse: false
|
||||
|
|
@ -239,6 +254,7 @@ describe('ConversationContent', () => {
|
|||
const invalidData = {
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: new Date(),
|
||||
isFunctionCall: false,
|
||||
|
|
@ -252,6 +268,7 @@ describe('ConversationContent', () => {
|
|||
const invalidData = {
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCallResponse: false
|
||||
|
|
@ -264,6 +281,7 @@ describe('ConversationContent', () => {
|
|||
const invalidData = {
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: 'false',
|
||||
|
|
@ -277,6 +295,7 @@ describe('ConversationContent', () => {
|
|||
const invalidData = {
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false
|
||||
|
|
@ -289,6 +308,7 @@ describe('ConversationContent', () => {
|
|||
const invalidData = {
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -302,6 +322,7 @@ describe('ConversationContent', () => {
|
|||
const validData = {
|
||||
role: 'user',
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T00:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -315,6 +336,7 @@ describe('ConversationContent', () => {
|
|||
const validData = {
|
||||
role: '',
|
||||
content: '',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -407,7 +429,7 @@ describe('ConversationContent', () => {
|
|||
});
|
||||
|
||||
it('should handle both function call and response flags true', () => {
|
||||
const content = new ConversationContent('user', 'test', 'func', new Date(), true, true);
|
||||
const content = new ConversationContent('user', 'test', '', 'func', new Date(), true, true);
|
||||
|
||||
expect(content.isFunctionCall).toBe(true);
|
||||
expect(content.isFunctionCallResponse).toBe(true);
|
||||
|
|
@ -415,14 +437,14 @@ describe('ConversationContent', () => {
|
|||
|
||||
it('should handle very old timestamps', () => {
|
||||
const oldDate = new Date('1970-01-01T00:00:00.000Z');
|
||||
const content = new ConversationContent('user', 'Hello', '', oldDate);
|
||||
const content = new ConversationContent('user', 'Hello', '', '', oldDate);
|
||||
|
||||
expect(content.timestamp).toBe(oldDate);
|
||||
});
|
||||
|
||||
it('should handle future timestamps', () => {
|
||||
const futureDate = new Date('2099-12-31T23:59:59.999Z');
|
||||
const content = new ConversationContent('user', 'Hello', '', futureDate);
|
||||
const content = new ConversationContent('user', 'Hello', '', '', futureDate);
|
||||
|
||||
expect(content.timestamp).toBe(futureDate);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
conversation.updated = new Date('2024-01-01T10:30:00Z');
|
||||
|
||||
conversation.contents.push(
|
||||
new ConversationContent(Role.User, 'Hello', undefined, new Date('2024-01-01T10:00:00Z')),
|
||||
new ConversationContent(Role.Assistant, 'Hi there!', undefined, new Date('2024-01-01T10:01:00Z'))
|
||||
new ConversationContent(Role.User, 'Hello', '', '', new Date('2024-01-01T10:00:00Z')),
|
||||
new ConversationContent(Role.Assistant, 'Hi there!', '', '', new Date('2024-01-01T10:01:00Z'))
|
||||
);
|
||||
|
||||
return conversation;
|
||||
|
|
@ -139,7 +139,7 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
it('should filter out aborted request messages', async () => {
|
||||
const conversation = createTestConversation('Test Filter');
|
||||
conversation.contents.push(
|
||||
new ConversationContent(Role.Assistant, Copy.ApiRequestAborted, undefined, new Date())
|
||||
new ConversationContent(Role.Assistant, Copy.ApiRequestAborted, '', '', new Date())
|
||||
);
|
||||
|
||||
await service.saveConversation(conversation);
|
||||
|
|
@ -190,6 +190,7 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
new ConversationContent(
|
||||
Role.Assistant,
|
||||
'Function call',
|
||||
'',
|
||||
JSON.stringify(functionCall),
|
||||
new Date('2024-01-01T10:02:00Z'),
|
||||
true,
|
||||
|
|
@ -206,6 +207,7 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
expect(functionCallContent).toEqual({
|
||||
role: Role.Assistant,
|
||||
content: 'Function call',
|
||||
promptContent: '',
|
||||
functionCall: JSON.stringify(functionCall),
|
||||
timestamp: '2024-01-01T10:02:00.000Z',
|
||||
isFunctionCall: true,
|
||||
|
|
@ -221,7 +223,8 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
new ConversationContent(
|
||||
Role.User,
|
||||
'Function response',
|
||||
undefined,
|
||||
'',
|
||||
'',
|
||||
new Date('2024-01-01T10:03:00Z'),
|
||||
false,
|
||||
true,
|
||||
|
|
@ -365,6 +368,7 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
{
|
||||
role: Role.User,
|
||||
content: 'Message 1',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T10:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -380,6 +384,7 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
{
|
||||
role: Role.User,
|
||||
content: 'Message 2',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-02T10:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -412,6 +417,7 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
{
|
||||
role: Role.User,
|
||||
content: 'Hello',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T10:00:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -420,6 +426,7 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
{
|
||||
role: Role.Assistant,
|
||||
content: 'Hi!',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T10:01:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -485,6 +492,7 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
{
|
||||
role: Role.Assistant,
|
||||
content: 'Calling function',
|
||||
promptContent: '',
|
||||
functionCall: JSON.stringify({ name: 'test_func', arguments: {} }),
|
||||
timestamp: '2024-01-01T10:00:00.000Z',
|
||||
isFunctionCall: true,
|
||||
|
|
@ -494,6 +502,7 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
{
|
||||
role: Role.User,
|
||||
content: 'Function result',
|
||||
promptContent: '',
|
||||
functionCall: '',
|
||||
timestamp: '2024-01-01T10:01:00.000Z',
|
||||
isFunctionCall: false,
|
||||
|
|
@ -627,6 +636,7 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
new ConversationContent(
|
||||
Role.Assistant,
|
||||
'Function',
|
||||
'',
|
||||
JSON.stringify({ name: 'test', arguments: { arg: 'val' } }),
|
||||
new Date('2024-01-01T10:05:00Z'),
|
||||
true,
|
||||
|
|
@ -637,6 +647,7 @@ describe('ConversationFileSystemService - Integration Tests', () => {
|
|||
Role.User,
|
||||
'Response',
|
||||
'',
|
||||
'',
|
||||
new Date('2024-01-01T10:06:00Z'),
|
||||
false,
|
||||
true,
|
||||
|
|
|
|||
Loading…
Reference in a new issue