11* @returns Array of previous fun facts
12*/
13async function getPreviousFunFacts() {
14try {
15const result = await sqlite.execute(
32* @param dates Array of date strings in ISO format
33*/
34async function deleteExistingFunFacts(dates) {
35try {
36for (const date of dates) {
51* @param factText The fun fact text
52*/
53async function insertFunFact(date, factText) {
54try {
55await sqlite.execute(
75* @returns Array of generated fun facts
76*/
77async function generateFunFacts(previousFacts) {
78try {
79// Get API key from environment
197* @returns Array of parsed facts
198*/
199function parseFallbackFacts(responseText, expectedDates) {
200// Try to extract facts using regex
201const factPattern = /(\d{4}-\d{2}-\d{2})["']?[,:]?\s*["']?(.*?)["']?[,}]/gs;
260261/**
262* Main function to generate and store fun facts for the next 7 days
263*/
264export async function generateAndStoreFunFacts() {
265try {
266// Get previous fun facts
301* Intended to be used as a Val Town cron job
302*/
303export default async function() {
304console.log("Running fun facts generation cron job...");
305return await generateAndStoreFunFacts();
middleranger-stevens.cursorrules15 matches
8### 1. Script Vals
910- Basic JavaScript/TypeScript functions
11- Can be imported by other vals
12- Example structure:
1314```typescript
15export function myFunction() {
16// Your code here
17}
2526```typescript
27export default async function (req: Request) {
28return new Response("Hello World");
29}
3738```typescript
39export default async function () {
40// Scheduled task code
41}
4950```typescript
51export default async function (email: Email) {
52// Process email
53}
5758- Ask clarifying questions when requirements are ambiguous
59- Provide complete, functional solutions rather than skeleton implementations
60- Test your logic against edge cases before presenting the final solution
61- Ensure all code follows Val Town's specific platform requirements
70- **Never bake in secrets into the code** - always use environment variables
71- Include comments explaining complex logic (avoid commenting obvious operations)
72- Follow modern ES6+ conventions and functional programming practices if possible
7374## Val Town Standard Libraries
7576Val Town provides several hosted services and utility functions.
7778### Blob Storage
124```
125126## Val Town Utility Functions
127128Val Town provides several utility functions to help with common project tasks.
129130### Importing Utilities
176{
177name: "should add numbers correctly",
178function: () => {
179expect(1 + 1).toBe(2);
180},
210โ โโโ database/
211โ โ โโโ migrations.ts # Schema definitions
212โ โ โโโ queries.ts # DB query functions
213โ โ โโโ README.md
214โ โโโ index.ts # Main entry point
226โโโ shared/
227โโโ README.md
228โโโ utils.ts # Shared types and functions
229```
230232- Hono is the recommended API framework (similar to Express, Flask, or Sinatra)
233- Main entry point should be `backend/index.ts`
234- **Static asset serving:** Use the utility functions to read and serve project files:
235```ts
236// Use the serveFile utility to handle content types automatically
273- Run migrations on startup or comment out for performance
274- Change table names when modifying schemas rather than altering
275- Export clear query functions with proper TypeScript typing
276- Follow the queries and migrations pattern from the example
277
1import { sendDailyBriefing } from "./sendDailyBrief.ts";
23export async function cronDailyBrief() {
4try {
5const chatId = Deno.env.get("TELEGRAM_CHAT_ID");
middleranger-stevensApp.tsx2 matches
62};
6364export function App() {
65const [memories, setMemories] = useState<Memory[]>([]);
66const [loading, setLoading] = useState(true);
139const data = await response.json();
140141// Change the sorting function to show memories in chronological order
142const sortedMemories = [...data].sort((a, b) => {
143const dateA = a.createdDate || 0;
ChatmcpPrompts.ts7 matches
16* @returns Promise<MCPPromptsResult>
17*/
18export async function fetchMCPPrompts(clientPool: MCPClientPool): Promise<MCPPromptsResult> {
19try {
20return await clientPool.fetchPrompts();
35* @returns Promise<MCPPromptsResult>
36*/
37export async function fetchMCPPromptsWithCache(
38clientPool: MCPClientPool,
39cacheKey: string = "mcp_prompts_cache",
100* @param cacheKey - Cache key to clear
101*/
102export function clearMCPPromptsCache(cacheKey: string = "mcp_prompts_cache"): void {
103localStorage.removeItem(cacheKey);
104}
105106/**
107* Legacy function for backward compatibility - uses direct fetch
108* @deprecated Use fetchMCPPrompts with clientPool instead
109*/
110export async function fetchMCPPromptsDirect(servers: MCPServerConfig[]): Promise<MCPPromptsResult> {
111try {
112if (!servers || !Array.isArray(servers)) {
161162/**
163* Legacy function - fetch prompts from a single MCP server using direct fetch
164* @deprecated Use client pool instead
165*/
166async function fetchPromptsFromServerDirect(server: MCPServerConfig): Promise<MCPPrompt[]> {
167if (!server.enabled || !server.url) {
168return [];
ChatmcpTools.ts7 matches
16* @returns Promise<MCPToolsResult>
17*/
18export async function fetchMCPTools(clientPool: MCPClientPool): Promise<MCPToolsResult> {
19try {
20return await clientPool.fetchTools();
35* @returns Promise<MCPToolsResult>
36*/
37export async function fetchMCPToolsWithCache(
38clientPool: MCPClientPool,
39cacheKey: string = "mcp_tools_cache",
100* @param cacheKey - Cache key to clear
101*/
102export function clearMCPToolsCache(cacheKey: string = "mcp_tools_cache"): void {
103localStorage.removeItem(cacheKey);
104}
105106/**
107* Legacy function for backward compatibility - uses direct fetch
108* @deprecated Use fetchMCPTools with clientPool instead
109*/
110export async function fetchMCPToolsDirect(servers: MCPServerConfig[]): Promise<MCPToolsResult> {
111try {
112if (!servers || !Array.isArray(servers)) {
148149/**
150* Legacy function - fetch tools from a single MCP server using direct fetch
151* @deprecated Use client pool instead
152*/
153async function fetchToolsFromServerDirect(server: MCPServerConfig): Promise<MCPTool[]> {
154if (!server.enabled || !server.url) {
155return [];
ChatuseMCPClients.tsx3 matches
15* Hook to manage MCP client instances based on server configurations
16*/
17export default function useMCPClients(serverConfigs: MCPServerConfig[]) {
18const [clientStates, setClientStates] = useState<Map<string, MCPClientState>>(new Map());
19101}, [serverConfigs]);
102103// Helper function to connect a client
104const connectClient = useCallback(async (id: string, client: MCPClient, initialState: MCPClientState) => {
105try {
166}, [connectedClients, serverConfigs]);
167168// Get connected clients (legacy function for backward compatibility)
169const getConnectedClients = useCallback((): MCPClient[] => {
170return connectedClients;
ChatResourceViewer-README.md4 matches
12- **๐ฑ Fullscreen Mode** - Toggle fullscreen for better viewing of large files
13- **๐ Smart Caching** - Caches fetched content for 5 minutes to improve performance
14- **๐ Retry Mechanism** - Automatic retry functionality when resource fetching fails
15- **๐ Metadata Display** - Shows file type, content type, and source server information
16- **๐ฏ Adaptive Rendering** - Chooses optimal rendering mode based on file type and hints
231## Implementation Notes
232233- ResourceViewer is integrated into the Message component's `renderAnthropicBlocks()` function
234- Detection happens in the `mcp_tool_result` case after NextSteps and before HTML detection
235- CodeMirror extensions are loaded dynamically based on file type
242- **Stable Reference Management** - MCP clients array is memoized in the parent hook to prevent reload loops
243- **Simplified Dependency Chains** - Reduced nested useCallback dependencies to minimize effect re-executions
244- **Optimized useEffect Dependencies** - Removed function dependencies that caused infinite reload loops
245246## Dependencies
254- **Binary File Support** - Display images, PDFs, etc.
255- **Diff Viewer** - Compare file versions
256- **Search/Find** - In-file search functionality
257- **Download Support** - Save resources locally
258- **Collaborative Editing** - Real-time editing capabilities
capsidemailsmain.js3 matches
198const errorText = document.getElementById('errorText');
199200function showSuccess(message) {
201successText.textContent = message;
202successMessage.classList.remove('hidden');
204}
205206function showError(message) {
207errorText.textContent = message;
208errorMessage.classList.remove('hidden');
210}
211212function hideMessages() {
213successMessage.classList.add('hidden');
214errorMessage.classList.add('hidden');
capsidemailsemail.js2 matches
5// =============================================================================
67// Email handler function for Val.Town
8export async function emailHandler(email) {
9const rawContent = email.html || email.text || "No content";
10const cleanedContent = await cleanEmailContent(rawContent);