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
+70
View File
@@ -0,0 +1,70 @@
const { DataTypes } = require('sequelize');
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('users', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: 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',
allowNull: false
},
is_active: {
type: DataTypes.BOOLEAN,
defaultValue: true,
allowNull: false
},
last_login: {
type: DataTypes.DATE,
allowNull: true
},
preferences: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
// Create indexes
await queryInterface.addIndex('users', ['email']);
await queryInterface.addIndex('users', ['role']);
await queryInterface.addIndex('users', ['is_active']);
await queryInterface.addIndex('users', ['created_at']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('users');
}
};
@@ -0,0 +1,62 @@
const { DataTypes } = require('sequelize');
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('conversations', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
user_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'users',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE'
},
title: {
type: DataTypes.STRING,
allowNull: false
},
status: {
type: DataTypes.ENUM('active', 'completed', 'archived'),
defaultValue: 'active',
allowNull: false
},
context: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
// Create indexes
await queryInterface.addIndex('conversations', ['user_id']);
await queryInterface.addIndex('conversations', ['status']);
await queryInterface.addIndex('conversations', ['created_at']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('conversations');
}
};
+88
View File
@@ -0,0 +1,88 @@
const { DataTypes } = require('sequelize');
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('plans', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
conversation_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'conversations',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE'
},
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',
allowNull: false
},
approval_feedback: {
type: DataTypes.TEXT,
allowNull: true
},
execution_result: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
tools_required: {
type: DataTypes.ARRAY(DataTypes.STRING),
defaultValue: [],
allowNull: false
},
estimated_duration: {
type: DataTypes.INTEGER,
allowNull: true
},
complexity_score: {
type: DataTypes.FLOAT,
defaultValue: 0,
allowNull: false
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
// Create indexes
await queryInterface.addIndex('plans', ['conversation_id']);
await queryInterface.addIndex('plans', ['status']);
await queryInterface.addIndex('plans', ['created_at']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('plans');
}
};
+83
View File
@@ -0,0 +1,83 @@
const { DataTypes } = require('sequelize');
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('messages', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
conversation_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'conversations',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE'
},
plan_id: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: 'plans',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'SET NULL'
},
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',
allowNull: false
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
tokens_used: {
type: DataTypes.INTEGER,
defaultValue: 0,
allowNull: false
},
processing_time: {
type: DataTypes.FLOAT,
defaultValue: 0,
allowNull: false
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
// Create indexes
await queryInterface.addIndex('messages', ['conversation_id']);
await queryInterface.addIndex('messages', ['plan_id']);
await queryInterface.addIndex('messages', ['role']);
await queryInterface.addIndex('messages', ['message_type']);
await queryInterface.addIndex('messages', ['created_at']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('messages');
}
};
+92
View File
@@ -0,0 +1,92 @@
const { DataTypes } = require('sequelize');
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('documents', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
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: {},
allowNull: false
},
is_indexed: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false
},
indexing_status: {
type: DataTypes.ENUM('pending', 'processing', 'completed', 'failed'),
defaultValue: 'pending',
allowNull: false
},
tags: {
type: DataTypes.ARRAY(DataTypes.STRING),
defaultValue: [],
allowNull: false
},
category: {
type: DataTypes.STRING,
allowNull: true
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
// Create indexes
await queryInterface.addIndex('documents', ['file_type']);
await queryInterface.addIndex('documents', ['is_indexed']);
await queryInterface.addIndex('documents', ['indexing_status']);
await queryInterface.addIndex('documents', ['category']);
await queryInterface.addIndex('documents', ['tags']);
await queryInterface.addIndex('documents', ['created_at']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('documents');
}
};
+89
View File
@@ -0,0 +1,89 @@
const { DataTypes } = require('sequelize');
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('feedback', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
user_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'users',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE'
},
message_id: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: 'messages',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'SET NULL'
},
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,
allowNull: false
},
processing_notes: {
type: DataTypes.TEXT,
allowNull: true
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
// Create indexes
await queryInterface.addIndex('feedback', ['user_id']);
await queryInterface.addIndex('feedback', ['message_id']);
await queryInterface.addIndex('feedback', ['feedback_type']);
await queryInterface.addIndex('feedback', ['is_processed']);
await queryInterface.addIndex('feedback', ['created_at']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('feedback');
}
};
@@ -0,0 +1,94 @@
const { DataTypes } = require('sequelize');
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('model_versions', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
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,
allowNull: false
},
performance_metrics: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
is_active: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false
},
deployment_status: {
type: DataTypes.ENUM('training', 'testing', 'deployed', 'deprecated'),
defaultValue: 'training',
allowNull: false
},
model_path: {
type: DataTypes.STRING,
allowNull: true
},
hyperparameters: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
training_log: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
// Create indexes
await queryInterface.addIndex('model_versions', ['model_name']);
await queryInterface.addIndex('model_versions', ['model_type']);
await queryInterface.addIndex('model_versions', ['is_active']);
await queryInterface.addIndex('model_versions', ['deployment_status']);
await queryInterface.addIndex('model_versions', ['created_at']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('model_versions');
}
};
@@ -0,0 +1,85 @@
const { DataTypes } = require('sequelize');
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('training_data', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
model_version_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'model_versions',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE'
},
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: {},
allowNull: false
},
quality_score: {
type: DataTypes.FLOAT,
allowNull: true
},
is_validated: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false
},
validation_notes: {
type: DataTypes.TEXT,
allowNull: true
},
source: {
type: DataTypes.ENUM('expert', 'user', 'generated', 'feedback'),
allowNull: false
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
// Create indexes
await queryInterface.addIndex('training_data', ['model_version_id']);
await queryInterface.addIndex('training_data', ['data_type']);
await queryInterface.addIndex('training_data', ['is_validated']);
await queryInterface.addIndex('training_data', ['source']);
await queryInterface.addIndex('training_data', ['quality_score']);
await queryInterface.addIndex('training_data', ['created_at']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('training_data');
}
};
@@ -0,0 +1,95 @@
const { DataTypes } = require('sequelize');
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('tool_executions', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
plan_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'plans',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE'
},
document_id: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: 'documents',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'SET NULL'
},
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',
allowNull: false
},
execution_time: {
type: DataTypes.FLOAT,
allowNull: true
},
error_message: {
type: DataTypes.TEXT,
allowNull: true
},
tokens_used: {
type: DataTypes.INTEGER,
defaultValue: 0,
allowNull: false
},
metadata: {
type: DataTypes.JSONB,
defaultValue: {},
allowNull: false
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
// Create indexes
await queryInterface.addIndex('tool_executions', ['plan_id']);
await queryInterface.addIndex('tool_executions', ['document_id']);
await queryInterface.addIndex('tool_executions', ['tool_name']);
await queryInterface.addIndex('tool_executions', ['tool_type']);
await queryInterface.addIndex('tool_executions', ['status']);
await queryInterface.addIndex('tool_executions', ['created_at']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('tool_executions');
}
};