Spaces:
Paused
Paused
File size: 1,425 Bytes
4edc3e5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | // utils.js - Utility functions
export const Utils = {
/**
* Get or create a unique machine ID stored in localStorage
* @returns {string} Machine ID
*/
getMachineId() {
let machineId = localStorage.getItem('MachineId');
if (!machineId) {
machineId = 'dev-' + crypto.randomUUID();
localStorage.setItem('MachineId', machineId);
}
return machineId;
},
/**
* Generate a unique session ID
* @returns {string} Session ID
*/
generateSessionId() {
return 'session-' + crypto.randomUUID();
},
/**
* Generate a unique conversation ID
* @returns {string} Conversation ID
*/
generateConversationId() {
return 'conversation-' + crypto.randomUUID();
},
/**
* Remove a file from a file input element
* @param {HTMLInputElement} fileInput - The file input element
* @param {File} fileToRemove - The file to remove
*/
removeFileFromInput(fileInput, fileToRemove) {
// File inputs are read-only. We have to update them
// by assigning a new value instead of filtering out
// directly files we do not want anymore.
const dt = new DataTransfer();
const { files } = fileInput;
for (let i = 0; i < files.length; i++) {
const file = files[i];
if (file !== fileToRemove) {
dt.items.add(file);
}
}
fileInput.files = dt.files;
}
}; |