completion
This commit is contained in:
parent
d1b0998d9a
commit
3eb1b9d8d7
@ -154,6 +154,7 @@ const domainAgnosticSoftware = data['domain-agnostic-software'] || [];
|
||||
</section>
|
||||
|
||||
<script define:vars={{ tools, phases, domainAgnosticSoftware }}>
|
||||
console.log('[DEBUG] Script loaded, before DOMContentLoaded');
|
||||
function sanitizeHTML(html) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = html;
|
||||
@ -167,6 +168,7 @@ function formatDuration(ms) {
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
console.log('[DEBUG] DOMContentLoaded fired');
|
||||
const aiInterface = document.getElementById('ai-interface');
|
||||
const aiInput = document.getElementById('ai-query-input');
|
||||
const aiSubmitBtn = document.getElementById('ai-submit-btn');
|
||||
@ -177,6 +179,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const aiErrorMessage = document.getElementById('ai-error-message');
|
||||
const aiResults = document.getElementById('ai-results');
|
||||
const aiDescription = document.getElementById('ai-description');
|
||||
console.log('[DEBUG] aiInput element found:', !!aiInput);
|
||||
|
||||
// Smart prompting elements
|
||||
const smartPromptingContainer = document.getElementById('smart-prompting-container');
|
||||
@ -333,6 +336,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
|
||||
async function triggerSmartPrompting() {
|
||||
console.log('[DEBUG] triggerSmartPrompting function defined');
|
||||
const inputText = aiInput.value.trim();
|
||||
|
||||
if (inputText.length < 50) {
|
||||
@ -363,6 +367,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
console.log('[DEBUG AIQuery]Enhancement response:', data);
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 429) {
|
||||
@ -373,8 +378,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.success && data.suggestions && data.suggestions.length > 0) {
|
||||
displaySuggestions(data.suggestions);
|
||||
if (data.success && data.questions && data.questions.length > 0) {
|
||||
displaySuggestions(data.questions);
|
||||
} else {
|
||||
showPromptingStatus('hidden');
|
||||
}
|
||||
@ -435,12 +440,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
counter.style.color = 'var(--color-text-secondary)';
|
||||
}
|
||||
};
|
||||
|
||||
aiInput.addEventListener('input', updateCharacterCount);
|
||||
updateCharacterCount();
|
||||
|
||||
// Smart Prompting Input Handling
|
||||
aiInput.addEventListener('input', () => {
|
||||
console.log('[DEBUG] Input event triggered, length:', aiInput.value.trim().length);
|
||||
const inputLength = aiInput.value.trim().length;
|
||||
|
||||
// Clear existing timeout
|
||||
@ -452,30 +455,29 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
|
||||
// Hide suggestions if input is too short
|
||||
if (inputLength < 50) {
|
||||
if (inputLength < 40) {
|
||||
showPromptingStatus('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide suggestions if they're currently visible (user is still typing)
|
||||
if (suggestionsVisible) {
|
||||
showPromptingStatus('hidden');
|
||||
}
|
||||
|
||||
// Show analyzing state after 1 second of typing (but only if long enough)
|
||||
// Show analyzing state after 1 second
|
||||
setTimeout(() => {
|
||||
if (aiInput.value.trim().length >= 50) {
|
||||
showPromptingStatus('analyzing');
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
// Trigger AI enhancement after 4 seconds of no input
|
||||
// Trigger AI enhancement after 1.5 seconds
|
||||
enhancementTimeout = setTimeout(() => {
|
||||
if (aiInput.value.trim().length >= 50) {
|
||||
triggerSmartPrompting();
|
||||
console.log('[DEBUG] Enhancement timeout fired, calling triggerSmartPrompting');
|
||||
if (aiInput.value.trim().length >= 40) {
|
||||
triggerSmartPrompting();
|
||||
}
|
||||
}, 4000);
|
||||
}, 1500);
|
||||
});
|
||||
|
||||
aiInput.addEventListener('input', updateCharacterCount);
|
||||
updateCharacterCount();
|
||||
|
||||
// Dismiss suggestions handler
|
||||
if (dismissSuggestions) {
|
||||
|
@ -138,13 +138,14 @@ export const POST: APIRoute = async ({ request }) => {
|
||||
|
||||
let questions;
|
||||
try {
|
||||
// Clean up the response and parse JSON
|
||||
const cleanedContent = aiContent
|
||||
// Clean up the response and parse JSON
|
||||
console.log('[DEBUG-ENHANCE]Raw AI content:', aiContent);
|
||||
const cleanedContent = aiContent
|
||||
.replace(/^```json\s*/i, '')
|
||||
.replace(/\s*```\s*$/, '')
|
||||
.trim();
|
||||
|
||||
questions = JSON.parse(cleanedContent);
|
||||
console.log('[DEBUG-ENHANCE]Cleaned content:', cleanedContent);
|
||||
questions = JSON.parse(cleanedContent);
|
||||
|
||||
if (!Array.isArray(questions) || questions.length === 0) {
|
||||
throw new Error('Invalid questions format');
|
||||
|
Loading…
x
Reference in New Issue
Block a user