<?php
// submit_artifact.php - Handle artifact submission to chat
session_start();
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo json_encode(['error' => 'Method not allowed']);
exit;
}
$input = file_get_contents('php://input');
$data = json_decode($input, true);
if (!$data) {
http_response_code(400);
echo json_encode(['error' => 'Invalid JSON']);
exit;
}
// Store the artifact submission data in session
$_SESSION['pending_artifact'] = [
'title' => $data['title'] ?? '',
'content' => $data['content'] ?? '',
'compactContent' => $data['compactContent'] ?? '',
'timestamp' => $data['timestamp'] ?? time()
];
// Force session write
session_write_close();
echo json_encode(['success' => true]);
?>