|
|
|
|
| import { Utils } from '../utils.js';
|
|
|
| export const StateManager = {
|
|
|
| sessionId: Utils.generateSessionId(),
|
|
|
|
|
| profile: {
|
| ageGroup: '',
|
| gender: '',
|
| roles: [],
|
| participantId: ''
|
| },
|
|
|
|
|
| consentGranted: false,
|
|
|
|
|
| currentLang: (() => {
|
| const browserLang = navigator.language.split('-')[0];
|
| const defaultLang = ['en', 'fr'].includes(browserLang) ? browserLang : 'en';
|
| return localStorage.getItem('preferredLang') || defaultLang;
|
| })(),
|
|
|
|
|
| modelChats: {
|
| "champ": {
|
| messages: [],
|
| conversation_id: Utils.generateConversationId()
|
| },
|
|
|
|
|
|
|
|
|
| "openai": {
|
| messages: [],
|
| conversation_id: Utils.generateConversationId()
|
| },
|
| "google-conservative": {
|
| messages: [],
|
| conversation_id: Utils.generateConversationId()
|
| },
|
| "google-creative": {
|
| messages: [],
|
| conversation_id: Utils.generateConversationId()
|
| }
|
| },
|
|
|
|
|
| sessionFiles: [],
|
|
|
|
|
| fontSize: 1,
|
|
|
| |
| |
| |
|
|
| updateProfile(profileData) {
|
| this.profile = { ...this.profile, ...profileData };
|
| },
|
|
|
| |
| |
| |
|
|
| setConsent(granted) {
|
| this.consentGranted = granted;
|
| },
|
|
|
| |
| |
| |
|
|
| setLanguage(lang) {
|
| this.currentLang = lang;
|
| localStorage.setItem('preferredLang', lang);
|
| },
|
|
|
| |
| |
| |
| |
|
|
| addMessage(modelType, message) {
|
| this.modelChats[modelType].messages.push(message);
|
| },
|
|
|
| |
| |
| |
| |
|
|
| getMessages(modelType) {
|
| return this.modelChats[modelType].messages;
|
| },
|
|
|
| |
| |
| |
| |
|
|
| getConversationId(modelType) {
|
| return this.modelChats[modelType].conversation_id;
|
| },
|
|
|
| |
| |
| |
|
|
| clearConversation(modelType) {
|
| this.modelChats[modelType].messages = [];
|
| this.modelChats[modelType].conversation_id = Utils.generateConversationId();
|
| },
|
|
|
| |
| |
| |
|
|
| addFile(file) {
|
| this.sessionFiles.push(file);
|
| },
|
|
|
| |
| |
| |
|
|
| removeFile(file) {
|
| this.sessionFiles = this.sessionFiles.filter(f => f !== file);
|
| },
|
|
|
| |
| |
| |
|
|
| getFiles() {
|
| return this.sessionFiles;
|
| },
|
|
|
| |
| |
| |
|
|
| setFontSize(size) {
|
| this.fontSize = size;
|
| },
|
|
|
| |
| |
| |
| |
|
|
| getTotalEmissions(modelType) {
|
| const chat = this.modelChats[modelType];
|
| if (!chat || !chat.messages) return 0;
|
|
|
| return chat.messages.reduce((total, message) => {
|
| return total + (message.gwpKgcoeq || 0);
|
| }, 0);
|
| },
|
|
|
| |
| |
| |
|
|
| getAllEmissions() {
|
| return Object.keys(this.modelChats).reduce((total, modelType) => {
|
| return total + this.getTotalEmissions(modelType);
|
| }, 0);
|
| },
|
|
|
| |
| |
| |
|
|
| getEmissionsBreakdown() {
|
| const breakdown = {};
|
| Object.keys(this.modelChats).forEach(modelType => {
|
| breakdown[modelType] = this.getTotalEmissions(modelType);
|
| });
|
| return breakdown;
|
| },
|
| }; |