📄 Source: switch_chat.php
<?php
session_name('INBOXZERO');
session_start();
header('Content-Type: application/json');
$input = json_decode(file_get_contents('php://input'), true);
$chatId = $input['chat_id'] ?? '';
if ($chatId && isset($_SESSION['chat_histories'][$chatId])) {
$_SESSION['current_conversation_id'] = $chatId;
$messages = [];
foreach ($_SESSION['chat_histories'][$chatId] as $entry) {
if (strpos($entry, 'User:') === 0) {
$messages[] = ['role' => 'user', 'content' => substr($entry, 6)];
} elseif (strpos($entry, 'Assistant:') === 0) {
$messages[] = ['role' => 'assistant', 'content' => substr($entry, 11)];
}
}
echo json_encode(['success' => true, 'messages' => $messages]);
} else {
echo json_encode(['error' => 'Chat not found']);
}
?>
← Back