live-reloadclient.ts2 matches
6*/
7async function registerLongPoll({ pageLoadedAt }: { pageLoadedAt: number }) {
8const { lastUpdatedAt, status } = await (await fetch("/__lastUpdatedAt")).json();
9if (lastUpdatedAt > pageLoadedAt) {
10window.location.href = `https://reload.val.run?${new URLSearchParams({ url: window.location.href })}`;
28return;
29}
30const resp = await fetch(targetURL);
31if (resp.ok) {
32window.location.href = targetURL;
live-reload-demomain.tsx1 match
1516// Enable live reloading
17export default liveReload(app.fetch, import.meta.url);
4import { NodeHtmlMarkdown, NodeHtmlMarkdownOptions } from "npm:node-html-markdown";
56const html = await fetch("https://github.com/trending").then(r => r.text());
78const { window: { document } } = new JSDOM(html);
2526try {
27const response = await fetch(window.location.href, {
28method: "POST",
29body: formData,
sqliteExplorerAppmain.tsx4 matches
1/** @jsxImportSource npm:hono/jsx **/
23import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
4import { iframeHandler } from "https://esm.town/v/nbbaier/iframeHandler";
5import { resetStyle } from "https://esm.town/v/nbbaier/resetStyle";
16import { verifyToken } from "https://esm.town/v/pomdtr/verifyToken";
17import { ResultSet, sqlite } from "https://esm.town/v/std/sqlite";
18import { reloadOnSaveFetchMiddleware } from "https://esm.town/v/stevekrouse/reloadOnSave";
19import { Hono } from "npm:hono";
20import type { FC } from "npm:hono/jsx";
175});
176177export const handler = app.fetch;
178export default iframeHandler(modifyFetchHandler(passwordAuth(handler, { verifyPassword: verifyToken })));
2// A more declarative and extensible multi-agent platform structure.
34import { fetch } from "https://esm.town/v/std/fetch"; // Assuming Val Town environment
56// --- Core Interfaces ---
296}
297298// Agent 2: Fetch External Data (modified for new signature)
299async function fetchAgent(
300input: AgentInput<{ url?: string }>, // Optionally allow URL via input
301context: AgentContext,
305const url = payload?.url || "https://jsonplaceholder.typicode.com/todos/1"; // Default URL
306307log('INFO', 'FetchAgent', `Start fetching data from ${url}`);
308try {
309const resp = await fetch(url);
310if (!resp.ok) {
311throw new Error(`Workspace failed: Server responded with status ${resp.status} ${resp.statusText}`);
313const data = await resp.json();
314315log('SUCCESS', 'FetchAgent', `Data fetched successfully`, { url, responseStatus: resp.status });
316return { mandateId, correlationId: taskId, payload: { data } };
317} catch (e: any) {
318log('ERROR', 'FetchAgent', `Workspaceing failed`, e);
319return { mandateId, correlationId: taskId, payload: { data: null }, error: e.message };
320}
325const analysisWorkflow: WorkflowDefinition = {
326id: "basicAnalysis",
327description: "Summarizes user text and fetches placeholder data.",
328steps: [
329{
335},
336{
337id: "step2_fetchData",
338agent: "fetcher",
339// No input mapping needed if the agent uses defaults or doesn't require specific input from workflow state
340input: {} // Explicitly empty
345outputMapping: { // Define the final output structure
346finalSummary: { source: "step1_summarize", field: "summary" },
347externalData: { source: "step2_fetchData", field: "data"},
348}
349};
358// Register agents
359agentRegistry.register("summarizer", summarizerAgent);
360agentRegistry.register("fetcher", fetchAgent);
361// Register more agents...
362// agentRegistry.register("sentimentAnalyzer", sentimentAgent);
410411try {
412const res = await fetch(window.location.pathname, {
413method: 'POST',
414headers: { 'Content-Type': 'application/json' },
430431} catch (err) {
432resultBox.textContent = 'Fetch Error: ' + err.message;
433resultBox.className = 'error';
434logBox.textContent = 'Failed to communicate with the backend.';
ca_highlightsmain.tsx2 matches
4// 1. if we've never queued for *today*, build queue via selectHighlights().
5// ‑ if no highlights, insert sentinel row into posted_tweets (tweet_id = "dummy‑YYYY‑MM‑DD").
6// 2. fetch any queued tweets scheduled within the next 15 min window and post them.
7// -----------------------------------------------------------------------------
8// env secrets:
74),
75);
76const res = await fetch(url, {
77method: "POST",
78headers: { "content-type": "application/json", ...authHeader },
hn_job_analyzerhnService.ts30 matches
1export async function fetchHiringPosts(postId?: number): Promise<any[]> {
2try {
3// If no post ID is provided, find the latest "Who is hiring" post
6}
7
8// Fetch the post data
9const post = await fetchItem(postId);
10
11// Fetch all comments
12const comments = await Promise.all(
13(post.kids || []).map(async (commentId: number) => {
14return await fetchItem(commentId);
15})
16);
19return comments.filter(comment => !comment.deleted && !comment.dead);
20} catch (error) {
21console.error('Error fetching hiring posts:', error);
22throw error;
23}
24}
2526export async function fetchWantToBeHiredPosts(postId?: number): Promise<any[]> {
27try {
28// If no post ID is provided, find the latest "Who wants to be hired" post
31}
32
33// Fetch the post data
34const post = await fetchItem(postId);
35
36// Fetch all comments
37const comments = await Promise.all(
38(post.kids || []).map(async (commentId: number) => {
39return await fetchItem(commentId);
40})
41);
44return comments.filter(comment => !comment.deleted && !comment.dead);
45} catch (error) {
46console.error('Error fetching want to be hired posts:', error);
47throw error;
48}
49}
5051export async function fetchFreelancerPosts(postId?: number): Promise<any[]> {
52try {
53// If no post ID is provided, find the latest "Freelancer? Seeking Freelancer?" post
56}
57
58// Fetch the post data
59const post = await fetchItem(postId);
60
61// Fetch all comments
62const comments = await Promise.all(
63(post.kids || []).map(async (commentId: number) => {
64return await fetchItem(commentId);
65})
66);
69return comments.filter(comment => !comment.deleted && !comment.dead);
70} catch (error) {
71console.error('Error fetching freelancer posts:', error);
72throw error;
73}
74}
7576// Helper function to fetch an item from the HN API
77async function fetchItem(id: number): Promise<any> {
78const response = await fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`);
79return await response.json();
80}
84try {
85// First, get the latest stories
86const response = await fetch('https://hacker-news.firebaseio.com/v0/askstories.json');
87const storyIds = await response.json();
88
89// Fetch the latest 50 stories to find the most recent "Who is hiring" post
90const stories = await Promise.all(
91storyIds.slice(0, 50).map(async (id: number) => {
92return await fetchItem(id);
93})
94);
116try {
117// First, get the latest stories
118const response = await fetch('https://hacker-news.firebaseio.com/v0/askstories.json');
119const storyIds = await response.json();
120
121// Fetch the latest 50 stories to find the most recent "Who wants to be hired" post
122const stories = await Promise.all(
123storyIds.slice(0, 50).map(async (id: number) => {
124return await fetchItem(id);
125})
126);
148try {
149// First, get the latest stories
150const response = await fetch('https://hacker-news.firebaseio.com/v0/askstories.json');
151const storyIds = await response.json();
152
153// Fetch the latest 50 stories to find the most recent "Freelancer? Seeking Freelancer?" post
154const stories = await Promise.all(
155storyIds.slice(0, 50).map(async (id: number) => {
156return await fetchItem(id);
157})
158);
discord-botapi-server.js3 matches
73res.json({ success: true, data: messages });
74} catch (error) {
75console.error('Error fetching messages:', error);
76res.status(500).json({ success: false, error: error.message });
77}
92res.json({ success: true, data: links });
93} catch (error) {
94console.error('Error fetching links:', error);
95res.status(500).json({ success: false, error: error.message });
96}
103res.json({ success: true, data: categories });
104} catch (error) {
105console.error('Error fetching categories:', error);
106res.status(500).json({ success: false, error: error.message });
107}
discord-botval-town-cron.js4 matches
1import { fetchAndStoreDMs } from './discord-client.js';
2import 'dotenv/config';
311*/
12export default async function cronHandler() {
13console.log('Starting scheduled Discord DM fetch...');
14try {
15await fetchAndStoreDMs();
16return { success: true, message: 'Successfully fetched and stored DMs' };
17} catch (error) {
18console.error('Error in cron job:', error);