469 <textarea id="legal-task-query" name="legalTaskQuery" placeholder="E.g., 'Identify all clauses related to termination for cause.' or 'Summarize the key obligations of Party A.'">${escapedQuery}</textarea>
470
471 <label for="doc-url">Document URL (Optional - content will be fetched):</label>
472 <input type="text" id="doc-url" name="documentUrl" value="${escapedUrl}" placeholder="https://example.com/legal-document.html">
473
711Â Â Â Â Â Â inputSourceDescription = \`URL: \${urlValue}\`;
712Â Â Â Â Â Â formData.append('documentUrl', urlValue);
713Â Â Â Â Â Â addStatusMessage(\`Fetching and processing content from URL: \${urlValue}\`, 'progress');
714Â Â Â Â }
715Â Â Â Â formData.append('inputSourceDescription', inputSourceDescription);
717
718Â Â Â Â try {
719Â Â Â Â Â Â const response = await fetch(window.location.pathname + '?format=json', {
720Â Â Â Â Â Â Â Â method: 'POST',
721Â Â Â Â Â Â Â Â body: formData,
775 // Check if a "Starting analysis..." message exists and remove it or similar progress ones
776 const existingProgress = statusContainer.querySelector('.status-entry.progress');
777 if(existingProgress && (existingProgress.textContent.includes('Starting analysis...') || existingProgress.textContent.includes('Uploading and processing') || existingProgress.textContent.includes('Fetching and processing') || existingProgress.textContent.includes('Processing pasted text'))) {
778 // Don't clear all if server logs were already added
779 } else {
815 const { OpenAI } = await import("https://esm.town/v/std/openai");
816 const { z } = await import("npm:zod"); // For potential future robust input validation on server
817 const { fetch } = await import("https://esm.town/v/std/fetch");
818 const { PDFExtract, PDFExtractOptions } = await import("npm:pdf.js-extract");
819
939 documentText = input.documentText;
940 } else if (input.documentUrl) {
941 log.push({ agent: ingestionAgent, type: "step", message: `Fetching from URL: ${input.documentUrl}` });
942 try {
943 // Basic fetch, consider adding User-Agent, timeout, error handling, content-type checking
944 const response = await fetch(input.documentUrl, {
945 headers: { "Accept": "text/plain, text/html, application/pdf" },
946 }); // Accept PDF too
949 const contentType = response.headers.get("content-type") || "";
950 if (contentType.includes("application/pdf")) {
951 log.push({ agent: ingestionAgent, type: "info", message: "Fetched PDF from URL. Extracting text..." });
952 const pdfBuffer = await response.arrayBuffer();
953 documentText = await extractPdfTextNative(
962 } else { // Assume text-like
963 const text = await response.text();
964 if (!text || text.trim().length === 0) throw new Error("Fetched content is empty or not text.");
965 log.push({ agent: ingestionAgent, type: "info", message: `Fetched ~${text.length} characters from URL.` });
966 documentText = text;
967 }
968 } catch (error) {
969 const errorMessage = `Failed to fetch or process URL ${input.documentUrl}: ${error.message}`;
970 log.push({ agent: ingestionAgent, type: "error", message: errorMessage });
971 documentText = null;