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>
470471<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">
473711inputSourceDescription = \`URL: \${urlValue}\`;
712formData.append('documentUrl', urlValue);
713addStatusMessage(\`Fetching and processing content from URL: \${urlValue}\`, 'progress');
714}
715formData.append('inputSourceDescription', inputSourceDescription);
717718try {
719const response = await fetch(window.location.pathname + '?format=json', {
720method: 'POST',
721body: formData,
775// Check if a "Starting analysis..." message exists and remove it or similar progress ones
776const existingProgress = statusContainer.querySelector('.status-entry.progress');
777if(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 {
815const { OpenAI } = await import("https://esm.town/v/std/openai");
816const { z } = await import("npm:zod"); // For potential future robust input validation on server
817const { fetch } = await import("https://esm.town/v/std/fetch");
818const { PDFExtract, PDFExtractOptions } = await import("npm:pdf.js-extract");
819939documentText = input.documentText;
940} else if (input.documentUrl) {
941log.push({ agent: ingestionAgent, type: "step", message: `Fetching from URL: ${input.documentUrl}` });
942try {
943// Basic fetch, consider adding User-Agent, timeout, error handling, content-type checking
944const response = await fetch(input.documentUrl, {
945headers: { "Accept": "text/plain, text/html, application/pdf" },
946}); // Accept PDF too
949const contentType = response.headers.get("content-type") || "";
950if (contentType.includes("application/pdf")) {
951log.push({ agent: ingestionAgent, type: "info", message: "Fetched PDF from URL. Extracting text..." });
952const pdfBuffer = await response.arrayBuffer();
953documentText = await extractPdfTextNative(
962} else { // Assume text-like
963const text = await response.text();
964if (!text || text.trim().length === 0) throw new Error("Fetched content is empty or not text.");
965log.push({ agent: ingestionAgent, type: "info", message: `Fetched ~${text.length} characters from URL.` });
966documentText = text;
967}
968} catch (error) {
969const errorMessage = `Failed to fetch or process URL ${input.documentUrl}: ${error.message}`;
970log.push({ agent: ingestionAgent, type: "error", message: errorMessage });
971documentText = null;
204<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>
205206<label for="doc-url">Document URL (Optional - content will be fetched):</label>
207<input type="text" id="doc-url" name="documentUrl" value="${escapedUrl}" placeholder="https://example.com/legal-document.html">
208431inputSourceDescription = \`URL: \${urlValue}\`;
432formData.append('documentUrl', urlValue);
433addStatusMessage(\`Fetching and processing content from URL: \${urlValue}\`, 'progress');
434}
435formData.append('inputSourceDescription', inputSourceDescription);
438try {
439// The Val itself acts as the API endpoint
440const response = await fetch(window.location.pathname + '?format=json', {
441method: 'POST',
442// FormData sets Content-Type automatically
508const { OpenAI } = await import("https://esm.town/v/std/openai");
509const { z } = await import("npm:zod"); // For potential future robust input validation on server
510const { fetch } = await import("https://esm.town/v/std/fetch");
511const { PDFExtract, PDFExtractOptions } = await import("npm:pdf.js-extract");
512632documentText = input.documentText;
633} else if (input.documentUrl) {
634log.push({ agent: ingestionAgent, type: "step", message: `Fetching from URL: ${input.documentUrl}` });
635try {
636// Basic fetch, consider adding User-Agent, timeout, error handling, content-type checking
637const response = await fetch(input.documentUrl, {
638headers: { "Accept": "text/plain, text/html, application/pdf" },
639}); // Accept PDF too
642const contentType = response.headers.get("content-type") || "";
643if (contentType.includes("application/pdf")) {
644log.push({ agent: ingestionAgent, type: "info", message: "Fetched PDF from URL. Extracting text..." });
645const pdfBuffer = await response.arrayBuffer();
646documentText = await extractPdfTextNative(
655} else { // Assume text-like
656const text = await response.text();
657if (!text || text.trim().length === 0) throw new Error("Fetched content is empty or not text.");
658log.push({ agent: ingestionAgent, type: "info", message: `Fetched ~${text.length} characters from URL.` });
659documentText = text;
660}
661} catch (error) {
662const errorMessage = `Failed to fetch or process URL ${input.documentUrl}: ${error.message}`;
663log.push({ agent: ingestionAgent, type: "error", message: errorMessage });
664documentText = null;
blog2025-06-03-newsletter-25.md2 matches
174- [**pomdtr**](https://www.val.town/u/pomdtr) made [extract-feeds](https://www.val.town/x/pomdtr/extract-feeds) to extract RSS feeds from an HTML page.
175- [**curtcox**](https://www.val.town/u/curtcox) made [wwtdotcom](https://www.val.town/x/curtcox/wwtdotcom), a proxy for wwt.com that rewrites all links to stay within the proxy and injects a help widget on every page.
176- [**ashryanio**](https://www.val.town/u/ashryanio) made [halpk](https://www.val.town/x/ashryanio/halpk), which fetches the RSS feed from Astoria Tech's Subcurrent blog and displays a random blog post each time the page is loaded. He also made [subcurrentShuffle](https://www.val.town/x/ashryanio/subcurrentShuffle) with Townie in 15 minutes at that same meetup!
177- [**Cam Pak**](https://www.val.town/u/cameronpak) made [groq-api](https://www.val.town/x/cameronpak/groq-api), a simple API using the AI SDK and Groq.
178- [**mgmarlow**](https://www.val.town/u/mgmarlow) made [aposd-red-flags](https://www.val.town/x/mgmarlow/aposd-red-flags), a simple flashcard app to help learn about common software design red flags from the book A Philosophy of Software Design by John Ousterhout.
179- [**JJG**](https://www.val.town/u/jjg) made [blockbench-plugin](https://www.val.town/x/jjg/blockbench-plugin), which fetches JavaScript or TypeScript files from GitHub repositories or Gists and serves them with the proper content type headers.
180- [**Steve Krouse**](https://www.val.town/u/stevekrouse) made [luciaMagicLinkStarter](https://www.val.town/x/stevekrouse/luciaMagicLinkStarter) to roll-your-own auth & magic link login using Lucia.
181- [**Max**](https://www.val.town/u/maxm) made [sqlitelogs](https://www.val.town/x/maxm/sqlitelogs), a logging system that stores logs in SQLite with a web interface and search functionality.
31maxOutputTokens: 4000, // NEW FEATURE: Control AI output length
32pdfMaxFileSizeMB: 15, // REFACTOR: Centralized
33urlFetchTimeout: 10000, // NEW FEATURE: Timeout for URL fetching (milliseconds)
34disclaimerText:
35"This AI-generated analysis is for informational purposes only and does not constitute legal advice. Consult with a qualified legal professional for advice on specific legal matters. AI analysis may contain errors or omissions.",
40uploadingFile: (fileName) => `⬆️ Uploading file: ${fileName}...`,
41processingPDF: (fileName) => `📄 Processing PDF: ${fileName}...`,
42fetchingURL: (url) => `🌐 Fetching content from: ${url}...`,
43processingText: "✍️ Processing pasted text...",
44aiAnalysisInProgress: (model) => `🧠 Analyzing with ${model}, please wait...`,
272<select id="ai-model" name="aiModel">${modelOptions}</select>
273274<label for="doc-url">Document URL (Optional - content will be fetched):</label>
275<input type="text" id="doc-url" name="documentUrl" value="${escapedUrl}" placeholder="https://example.com/legal-document.html">
276552inputSourceDescription = \`Content from URL: \${urlValue}\`;
553formData.append('documentUrl', urlValue);
554addStatusMessage(CONFIG.statusMessages.fetchingURL(urlValue), 'progress', 'Client');
555}
556formData.append('inputSourceDescription', inputSourceDescription); // Client-side initial description
557558try {
559const response = await fetch(window.location.pathname + '?format=json', {
560method: 'POST',
561body: formData,
622const { OpenAI } = await import("https://esm.town/v/std/openai");
623// Zod is imported globally via import statement at the top of the script
624const { fetch } = await import("https://esm.town/v/std/fetch"); // Using std/fetch
625const { PDFExtract, PDFExtractOptions } = await import("npm:pdf.js-extract");
626800finalInputSourceDescription = `Pasted Text (Length: ${documentText.length} chars)`;
801} else if (input.documentUrl) {
802log.push({ agent: ingestionAgent, type: "step", message: CONFIG.statusMessages.fetchingURL(input.documentUrl) });
803try {
804const controller = new AbortController(); // NEW FEATURE: Fetch timeout
805const timeoutId = setTimeout(() => controller.abort(), CONFIG.urlFetchTimeout);
806807const response = await fetch(input.documentUrl, {
808headers: { "Accept": "text/plain, text/html, application/pdf" },
809signal: controller.signal,
820agent: ingestionAgent,
821type: "info",
822message: `Fetched PDF from URL '${input.documentUrl}'. Extracting text...`,
823});
824const pdfBuffer = await response.arrayBuffer();
834} else {
835const text = await response.text();
836if (!text || text.trim().length === 0) throw new Error("Fetched content is empty or not text-like.");
837log.push({
838agent: ingestionAgent,
839type: "info",
840message: `Fetched ~${text.length} characters from URL '${input.documentUrl}'.`,
841});
842documentText = text;
845}
846} catch (error) {
847const errorMsg = error.name === "AbortError" ? "Fetch timed out." : error.message;
848const errorMessage = `Failed to fetch or process URL ${input.documentUrl}: ${errorMsg}`;
849log.push({ agent: ingestionAgent, type: "error", message: errorMessage });
850documentText = null;
templateTwitterAlertmain.tsx1 match
19: Math.floor((Date.now() - 2 * 24 * 60 * 60 * 1000) / 1000);
2021// Fetch and log tweets
22const response = await socialDataSearch(`${query} since_time:${timeFrame}`);
23console.log("Response from socialDataSearch:", response);
untitled-4435main.tsx13 matches
604const triggerTelegramInteraction = async (chatId) => {
605try {
606const response = await fetch("/handle-telegram-interaction", {
607method: "POST",
608headers: { "Content-Type": "application/json" },
621};
622623const fetchUserBalance = async () => {
624let userId = null;
625let isTelegramEnv = false;
674if (userId) {
675try {
676const response = await fetch(`/get-balance?uid=${userId}`);
677if (!response.ok) {
678try {
699}
700} catch (error) {
701console.error("Failed to fetch or process balance:", error.toString());
702setBalance("Error");
703}
704} else {
705console.error("User ID could not be determined for balance fetching.");
706setBalance("--.--");
707}
731window.Telegram.WebApp.ready();
732}
733fetchUserBalance();
734} else if (isTelegramWebAppPresent) {
735console.log(
736"Telegram script present, but user data not immediately available or ready() pending. Setting timeout for balance fetch.",
737);
738if (window.Telegram.WebApp.ready) {
739window.Telegram.WebApp.ready();
740}
741scriptLoadTimeoutId = setTimeout(fetchUserBalance, 300);
742} else {
743console.log("Not in Telegram environment. Proceeding as web user for balance fetch.");
744fetchUserBalance();
745}
746}
882setShowSpinner(true);
883884const response = await fetch("/save-credentials", {
885method: "POST",
886headers: { "Content-Type": "application/json" },
1884const sendActualTelegramAPIMessage = async (botToken, chatId, text, parseMode = "Markdown") => {
1885try {
1886const response = await fetch(`https://api.telegram.org/bot${botToken}/sendMessage`, {
1887method: "POST",
1888headers: { "Content-Type": "application/json" },
2194if (confirm('Are you sure you want to unban this user?')) {
2195try {
2196const response = await fetch('/unban-telegram-user', {
2197method: 'POST',
2198headers: { 'Content-Type': 'application/json' },
Contextualindex.ts1 match
353});
354355export default app.fetch;
cerebras_coderindex.ts1 match
181182try {
183const response = await fetch("/", {
184method: "POST",
185body: JSON.stringify({
6const query = ?select=name,website,logo_url,description&plan=eq.premium&order=created_at.desc&limit=${limit};
7const endpoint = supabaseUrl + query;
8const response = await fetch(endpoint, {
9headers: {
10"Authorization":