completion

This commit is contained in:
overcuriousity 2025-07-26 21:48:17 +02:00
parent d1b0998d9a
commit 3eb1b9d8d7
2 changed files with 23 additions and 20 deletions

View File

@ -154,6 +154,7 @@ const domainAgnosticSoftware = data['domain-agnostic-software'] || [];
</section> </section>
<script define:vars={{ tools, phases, domainAgnosticSoftware }}> <script define:vars={{ tools, phases, domainAgnosticSoftware }}>
console.log('[DEBUG] Script loaded, before DOMContentLoaded');
function sanitizeHTML(html) { function sanitizeHTML(html) {
const div = document.createElement('div'); const div = document.createElement('div');
div.textContent = html; div.textContent = html;
@ -167,6 +168,7 @@ function formatDuration(ms) {
} }
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
console.log('[DEBUG] DOMContentLoaded fired');
const aiInterface = document.getElementById('ai-interface'); const aiInterface = document.getElementById('ai-interface');
const aiInput = document.getElementById('ai-query-input'); const aiInput = document.getElementById('ai-query-input');
const aiSubmitBtn = document.getElementById('ai-submit-btn'); const aiSubmitBtn = document.getElementById('ai-submit-btn');
@ -177,6 +179,7 @@ document.addEventListener('DOMContentLoaded', () => {
const aiErrorMessage = document.getElementById('ai-error-message'); const aiErrorMessage = document.getElementById('ai-error-message');
const aiResults = document.getElementById('ai-results'); const aiResults = document.getElementById('ai-results');
const aiDescription = document.getElementById('ai-description'); const aiDescription = document.getElementById('ai-description');
console.log('[DEBUG] aiInput element found:', !!aiInput);
// Smart prompting elements // Smart prompting elements
const smartPromptingContainer = document.getElementById('smart-prompting-container'); const smartPromptingContainer = document.getElementById('smart-prompting-container');
@ -333,6 +336,7 @@ document.addEventListener('DOMContentLoaded', () => {
} }
async function triggerSmartPrompting() { async function triggerSmartPrompting() {
console.log('[DEBUG] triggerSmartPrompting function defined');
const inputText = aiInput.value.trim(); const inputText = aiInput.value.trim();
if (inputText.length < 50) { if (inputText.length < 50) {
@ -363,6 +367,7 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
const data = await response.json(); const data = await response.json();
console.log('[DEBUG AIQuery]Enhancement response:', data);
if (!response.ok) { if (!response.ok) {
if (response.status === 429) { if (response.status === 429) {
@ -373,8 +378,8 @@ document.addEventListener('DOMContentLoaded', () => {
return; return;
} }
if (data.success && data.suggestions && data.suggestions.length > 0) { if (data.success && data.questions && data.questions.length > 0) {
displaySuggestions(data.suggestions); displaySuggestions(data.questions);
} else { } else {
showPromptingStatus('hidden'); showPromptingStatus('hidden');
} }
@ -436,11 +441,9 @@ document.addEventListener('DOMContentLoaded', () => {
} }
}; };
aiInput.addEventListener('input', updateCharacterCount);
updateCharacterCount();
// Smart Prompting Input Handling // Smart Prompting Input Handling
aiInput.addEventListener('input', () => { aiInput.addEventListener('input', () => {
console.log('[DEBUG] Input event triggered, length:', aiInput.value.trim().length);
const inputLength = aiInput.value.trim().length; const inputLength = aiInput.value.trim().length;
// Clear existing timeout // Clear existing timeout
@ -452,31 +455,30 @@ document.addEventListener('DOMContentLoaded', () => {
} }
// Hide suggestions if input is too short // Hide suggestions if input is too short
if (inputLength < 50) { if (inputLength < 40) {
showPromptingStatus('hidden'); showPromptingStatus('hidden');
return; return;
} }
// Hide suggestions if they're currently visible (user is still typing) // Show analyzing state after 1 second
if (suggestionsVisible) {
showPromptingStatus('hidden');
}
// Show analyzing state after 1 second of typing (but only if long enough)
setTimeout(() => { setTimeout(() => {
if (aiInput.value.trim().length >= 50) { if (aiInput.value.trim().length >= 50) {
showPromptingStatus('analyzing'); showPromptingStatus('analyzing');
} }
}, 1000); }, 1000);
// Trigger AI enhancement after 4 seconds of no input // Trigger AI enhancement after 1.5 seconds
enhancementTimeout = setTimeout(() => { enhancementTimeout = setTimeout(() => {
if (aiInput.value.trim().length >= 50) { console.log('[DEBUG] Enhancement timeout fired, calling triggerSmartPrompting');
if (aiInput.value.trim().length >= 40) {
triggerSmartPrompting(); triggerSmartPrompting();
} }
}, 4000); }, 1500);
}); });
aiInput.addEventListener('input', updateCharacterCount);
updateCharacterCount();
// Dismiss suggestions handler // Dismiss suggestions handler
if (dismissSuggestions) { if (dismissSuggestions) {
dismissSuggestions.addEventListener('click', () => { dismissSuggestions.addEventListener('click', () => {

View File

@ -139,11 +139,12 @@ export const POST: APIRoute = async ({ request }) => {
let questions; let questions;
try { try {
// Clean up the response and parse JSON // Clean up the response and parse JSON
console.log('[DEBUG-ENHANCE]Raw AI content:', aiContent);
const cleanedContent = aiContent const cleanedContent = aiContent
.replace(/^```json\s*/i, '') .replace(/^```json\s*/i, '')
.replace(/\s*```\s*$/, '') .replace(/\s*```\s*$/, '')
.trim(); .trim();
console.log('[DEBUG-ENHANCE]Cleaned content:', cleanedContent);
questions = JSON.parse(cleanedContent); questions = JSON.parse(cleanedContent);
if (!Array.isArray(questions) || questions.length === 0) { if (!Array.isArray(questions) || questions.length === 0) {