first commit

This commit is contained in:
2025-11-06 11:08:59 +01:00
commit 3c5117c2c3
85 changed files with 13275 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
module.exports = (sequelize, DataTypes) => {
const Conversation = sequelize.define('Conversation', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
user_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
},
title: {
type: DataTypes.STRING,
allowNull: false
},
status: {
type: DataTypes.ENUM('active', 'completed', 'archived'),
defaultValue: 'active'
},
context: {
type: DataTypes.JSONB,
defaultValue: {}
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {}
}
}, {
tableName: 'conversations',
indexes: [
{ fields: ['user_id'] },
{ fields: ['status'] },
{ fields: ['created_at'] }
]
});
return Conversation;
};
+73
View File
@@ -0,0 +1,73 @@
module.exports = (sequelize, DataTypes) => {
const Document = sequelize.define('Document', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
filename: {
type: DataTypes.STRING,
allowNull: false
},
original_filename: {
type: DataTypes.STRING,
allowNull: false
},
file_path: {
type: DataTypes.STRING,
allowNull: false
},
file_type: {
type: DataTypes.STRING,
allowNull: false
},
file_size: {
type: DataTypes.BIGINT,
allowNull: false
},
content: {
type: DataTypes.TEXT,
allowNull: true
},
extracted_text: {
type: DataTypes.TEXT,
allowNull: true
},
embeddings: {
type: DataTypes.JSONB,
allowNull: true
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {}
},
is_indexed: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
indexing_status: {
type: DataTypes.ENUM('pending', 'processing', 'completed', 'failed'),
defaultValue: 'pending'
},
tags: {
type: DataTypes.ARRAY(DataTypes.STRING),
defaultValue: []
},
category: {
type: DataTypes.STRING,
allowNull: true
}
}, {
tableName: 'documents',
indexes: [
{ fields: ['file_type'] },
{ fields: ['is_indexed'] },
{ fields: ['indexing_status'] },
{ fields: ['category'] },
{ fields: ['tags'] },
{ fields: ['created_at'] }
]
});
return Document;
};
+68
View File
@@ -0,0 +1,68 @@
module.exports = (sequelize, DataTypes) => {
const Feedback = sequelize.define('Feedback', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
user_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
},
message_id: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: 'messages',
key: 'id'
}
},
feedback_type: {
type: DataTypes.ENUM('positive', 'negative', 'correction', 'suggestion'),
allowNull: false
},
rating: {
type: DataTypes.INTEGER,
allowNull: true,
validate: {
min: 1,
max: 5
}
},
comment: {
type: DataTypes.TEXT,
allowNull: true
},
corrected_content: {
type: DataTypes.TEXT,
allowNull: true
},
is_processed: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
processing_notes: {
type: DataTypes.TEXT,
allowNull: true
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {}
}
}, {
tableName: 'feedback',
indexes: [
{ fields: ['user_id'] },
{ fields: ['message_id'] },
{ fields: ['feedback_type'] },
{ fields: ['is_processed'] },
{ fields: ['created_at'] }
]
});
return Feedback;
};
+60
View File
@@ -0,0 +1,60 @@
module.exports = (sequelize, DataTypes) => {
const Message = sequelize.define('Message', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
conversation_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'conversations',
key: 'id'
}
},
plan_id: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: 'plans',
key: 'id'
}
},
role: {
type: DataTypes.ENUM('user', 'assistant', 'system'),
allowNull: false
},
content: {
type: DataTypes.TEXT,
allowNull: false
},
message_type: {
type: DataTypes.ENUM('text', 'plan', 'execution', 'feedback'),
defaultValue: 'text'
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {}
},
tokens_used: {
type: DataTypes.INTEGER,
defaultValue: 0
},
processing_time: {
type: DataTypes.FLOAT,
defaultValue: 0
}
}, {
tableName: 'messages',
indexes: [
{ fields: ['conversation_id'] },
{ fields: ['plan_id'] },
{ fields: ['role'] },
{ fields: ['message_type'] },
{ fields: ['created_at'] }
]
});
return Message;
};
+72
View File
@@ -0,0 +1,72 @@
module.exports = (sequelize, DataTypes) => {
const ModelVersion = sequelize.define('ModelVersion', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
model_name: {
type: DataTypes.STRING,
allowNull: false
},
version: {
type: DataTypes.STRING,
allowNull: false
},
model_type: {
type: DataTypes.ENUM('MODEL1', 'QUERYMODEL'),
allowNull: false
},
base_model: {
type: DataTypes.STRING,
allowNull: false
},
fine_tuning_method: {
type: DataTypes.ENUM('SFT', 'DPO', 'PPO', 'LoRA', 'QLoRA'),
allowNull: true
},
training_data_count: {
type: DataTypes.INTEGER,
defaultValue: 0
},
performance_metrics: {
type: DataTypes.JSONB,
defaultValue: {}
},
is_active: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
deployment_status: {
type: DataTypes.ENUM('training', 'testing', 'deployed', 'deprecated'),
defaultValue: 'training'
},
model_path: {
type: DataTypes.STRING,
allowNull: true
},
hyperparameters: {
type: DataTypes.JSONB,
defaultValue: {}
},
training_log: {
type: DataTypes.JSONB,
defaultValue: {}
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {}
}
}, {
tableName: 'model_versions',
indexes: [
{ fields: ['model_name'] },
{ fields: ['model_type'] },
{ fields: ['is_active'] },
{ fields: ['deployment_status'] },
{ fields: ['created_at'] }
]
});
return ModelVersion;
};
+66
View File
@@ -0,0 +1,66 @@
module.exports = (sequelize, DataTypes) => {
const Plan = sequelize.define('Plan', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
conversation_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'conversations',
key: 'id'
}
},
title: {
type: DataTypes.STRING,
allowNull: false
},
description: {
type: DataTypes.TEXT,
allowNull: false
},
steps: {
type: DataTypes.JSONB,
allowNull: false
},
status: {
type: DataTypes.ENUM('draft', 'pending_approval', 'approved', 'rejected', 'executing', 'completed', 'failed'),
defaultValue: 'draft'
},
approval_feedback: {
type: DataTypes.TEXT,
allowNull: true
},
execution_result: {
type: DataTypes.JSONB,
defaultValue: {}
},
tools_required: {
type: DataTypes.ARRAY(DataTypes.STRING),
defaultValue: []
},
estimated_duration: {
type: DataTypes.INTEGER, // in minutes
allowNull: true
},
complexity_score: {
type: DataTypes.FLOAT,
defaultValue: 0
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {}
}
}, {
tableName: 'plans',
indexes: [
{ fields: ['conversation_id'] },
{ fields: ['status'] },
{ fields: ['created_at'] }
]
});
return Plan;
};
+73
View File
@@ -0,0 +1,73 @@
module.exports = (sequelize, DataTypes) => {
const ToolExecution = sequelize.define('ToolExecution', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
plan_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'plans',
key: 'id'
}
},
document_id: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: 'documents',
key: 'id'
}
},
tool_name: {
type: DataTypes.STRING,
allowNull: false
},
tool_type: {
type: DataTypes.ENUM('query_expander', 'extraction', 'report1', 'report2', 'web_search', 'encyclopedia_pdf'),
allowNull: false
},
input_parameters: {
type: DataTypes.JSONB,
allowNull: false
},
output_result: {
type: DataTypes.JSONB,
allowNull: true
},
status: {
type: DataTypes.ENUM('pending', 'running', 'completed', 'failed'),
defaultValue: 'pending'
},
execution_time: {
type: DataTypes.FLOAT,
allowNull: true
},
error_message: {
type: DataTypes.TEXT,
allowNull: true
},
tokens_used: {
type: DataTypes.INTEGER,
defaultValue: 0
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {}
}
}, {
tableName: 'tool_executions',
indexes: [
{ fields: ['plan_id'] },
{ fields: ['document_id'] },
{ fields: ['tool_name'] },
{ fields: ['tool_type'] },
{ fields: ['status'] },
{ fields: ['created_at'] }
]
});
return ToolExecution;
};
+64
View File
@@ -0,0 +1,64 @@
module.exports = (sequelize, DataTypes) => {
const TrainingData = sequelize.define('TrainingData', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
model_version_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'model_versions',
key: 'id'
}
},
data_type: {
type: DataTypes.ENUM('qa_pair', 'plan_pair', 'feedback', 'preference'),
allowNull: false
},
input_text: {
type: DataTypes.TEXT,
allowNull: false
},
output_text: {
type: DataTypes.TEXT,
allowNull: false
},
context: {
type: DataTypes.JSONB,
defaultValue: {}
},
quality_score: {
type: DataTypes.FLOAT,
allowNull: true
},
is_validated: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
validation_notes: {
type: DataTypes.TEXT,
allowNull: true
},
source: {
type: DataTypes.ENUM('expert', 'user', 'generated', 'feedback'),
allowNull: false
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {}
}
}, {
tableName: 'training_data',
indexes: [
{ fields: ['model_version_id'] },
{ fields: ['data_type'] },
{ fields: ['is_validated'] },
{ fields: ['source'] },
{ fields: ['quality_score'] }
]
});
return TrainingData;
};
+53
View File
@@ -0,0 +1,53 @@
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('User', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
isEmail: true
}
},
password_hash: {
type: DataTypes.STRING,
allowNull: false
},
first_name: {
type: DataTypes.STRING,
allowNull: false
},
last_name: {
type: DataTypes.STRING,
allowNull: false
},
role: {
type: DataTypes.ENUM('user', 'admin', 'expert'),
defaultValue: 'user'
},
is_active: {
type: DataTypes.BOOLEAN,
defaultValue: true
},
last_login: {
type: DataTypes.DATE
},
preferences: {
type: DataTypes.JSONB,
defaultValue: {}
}
}, {
tableName: 'users',
indexes: [
{ fields: ['email'] },
{ fields: ['role'] },
{ fields: ['is_active'] }
]
});
return User;
};
+69
View File
@@ -0,0 +1,69 @@
const { sequelize } = require('../config/database');
const { DataTypes } = require('sequelize');
// Import all models
const User = require('./User')(sequelize, DataTypes);
const Conversation = require('./Conversation')(sequelize, DataTypes);
const Message = require('./Message')(sequelize, DataTypes);
const Plan = require('./Plan')(sequelize, DataTypes);
const Feedback = require('./Feedback')(sequelize, DataTypes);
const Document = require('./Document')(sequelize, DataTypes);
const TrainingData = require('./TrainingData')(sequelize, DataTypes);
const ModelVersion = require('./ModelVersion')(sequelize, DataTypes);
const ToolExecution = require('./ToolExecution')(sequelize, DataTypes);
// Define associations
const defineAssociations = () => {
// User associations
User.hasMany(Conversation, { foreignKey: 'user_id' });
User.hasMany(Feedback, { foreignKey: 'user_id' });
// Conversation associations
Conversation.belongsTo(User, { foreignKey: 'user_id' });
Conversation.hasMany(Message, { foreignKey: 'conversation_id' });
Conversation.hasMany(Plan, { foreignKey: 'conversation_id' });
// Message associations
Message.belongsTo(Conversation, { foreignKey: 'conversation_id' });
Message.belongsTo(Plan, { foreignKey: 'plan_id' });
// Plan associations
Plan.belongsTo(Conversation, { foreignKey: 'conversation_id' });
Plan.hasMany(Message, { foreignKey: 'plan_id' });
Plan.hasMany(ToolExecution, { foreignKey: 'plan_id' });
// Feedback associations
Feedback.belongsTo(User, { foreignKey: 'user_id' });
Feedback.belongsTo(Message, { foreignKey: 'message_id' });
// Document associations
Document.hasMany(ToolExecution, { foreignKey: 'document_id' });
// TrainingData associations
TrainingData.belongsTo(ModelVersion, { foreignKey: 'model_version_id' });
// ModelVersion associations
ModelVersion.hasMany(TrainingData, { foreignKey: 'model_version_id' });
// ToolExecution associations
ToolExecution.belongsTo(Plan, { foreignKey: 'plan_id' });
ToolExecution.belongsTo(Document, { foreignKey: 'document_id' });
};
// Initialize associations
defineAssociations();
const models = {
User,
Conversation,
Message,
Plan,
Feedback,
Document,
TrainingData,
ModelVersion,
ToolExecution,
sequelize
};
module.exports = models;