Search
Code3,144
import { nanoid } from "https://esm.sh/nanoid@5.0.5";import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3";const TABLE_NAME = `memories`; try { // Get API key from environment const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); if (!apiKey) { console.error("Anthropic API key is not configured."); return null; } // Initialize Anthropic client const anthropic = new Anthropic({ apiKey }); // Format previous facts for the prompt console.log({ message }); const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", max_tokens: 1000,- **Automatic PR Analysis**: Responds to GitHub pull request webhooks instantly- **AI-Powered Reviews**: Uses Anthropic's Claude Haiku 4.5 for intelligent code analysis and typo detection- **Secure Integration**: Webhook signature verification for security- **Smart File Filtering**: Reviews code files and markdown files for typos, skips other documentation and config files - **Pull requests**: Read and write (required to post review comments)**Anthropic API Key**: Get your API key from [Anthropic Console](https://console.anthropic.com/)### 2. Configure Environment VariablesIn Val Town, set these environment variables:- `GITHUB_TOKEN`: Your GitHub personal access token- `ANTHROPIC_API_KEY`: Your Anthropic API key - `WEBHOOK_SECRET`: A random secret string (generate with: `openssl rand -hex 32`)- **Clear Descriptions**: Add good PR descriptions to help the AI understand context- **Test First**: Use the debug endpoints to verify your setup before going live- **Monitor Usage**: Keep an eye on your Anthropic API usage for cost management- **Apply Suggestions**: Use GitHub's "Apply suggestion" button for one-click fixes- **File Size**: Large files are truncated to 2000 characters for analysis- **File Types**: Reviews code files for quality/security and markdown files for typos/grammar- **Dependencies**: Requires internet access to GitHub and Anthropic APIs- **Rate Limits**: Subject to GitHub and Anthropic API rate limitsThese limitations help ensure fast, reliable reviews while managing API costs and complexity. files: FileChange[]): Promise<ReviewResult> { const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); if (!apiKey) { throw new Error("ANTHROPIC_API_KEY not configured"); } try { const response = await fetch("https://api.anthropic.com/v1/messages", { method: "POST", headers: { "Content-Type": "application/json", "x-api-key": apiKey, "anthropic-version": "2023-06-01", }, body: JSON.stringify({ // Main debug page const githubToken = Deno.env.get("GITHUB_TOKEN"); const anthropicKey = Deno.env.get("ANTHROPIC_API_KEY"); const webhookSecret = Deno.env.get("WEBHOOK_SECRET"); environment: { GITHUB_TOKEN: githubToken ? "✅ Set" : "❌ Missing", ANTHROPIC_API_KEY: anthropicKey ? "✅ Set" : "❌ Missing", WEBHOOK_SECRET: webhookSecret ? "✅ Set" : "❌ Missing" },async function testClaudeConnection(): Promise<Response> { const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); if (!apiKey) { return new Response(JSON.stringify({ success: false, error: "ANTHROPIC_API_KEY not configured" }), { status: 400, try { const response = await fetch("https://api.anthropic.com/v1/messages", { method: "POST", headers: { "Content-Type": "application/json", "x-api-key": apiKey, "anthropic-version": "2023-06-01", }, body: JSON.stringify({```GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxANTHROPIC_API_KEY=sk-ant-api03-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxWEBHOOK_SECRET=a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456```5. Generate token and copy the value### ANTHROPIC_API_KEY1. Go to https://console.anthropic.com/2. Sign up/login3. Go to API Keys section "Bash(find:*)", "Bash(git add:*)", "Bash(git commit -m \"$(cat <<''EOF''\nImplement critical fixes and cleanup legacy code\n\nCritical Improvements:\n- Add React Error Boundary for graceful error handling\n- Implement pagination (100 rows/page) to prevent browser freeze\n- Enable TypeScript strict mode (noImplicitAny, strict, lock)\n- Remove all ''any'' types, add SQLValue type for type safety\n- Add error type guards (isError, getErrorMessage)\n- Remove all production console.log statements\n- Fix Hono context typing with proper UserData types\n\nType Safety Enhancements:\n- Replace any[][] with SQLValue[][] throughout\n- Add type guards for safe error handling\n- Properly type all React hooks and components\n- Add ''override'' modifiers for class methods\n- Zero type errors with strict mode enabled\n\nPerformance & UX:\n- Paginated table with First/Previous/Next/Last controls\n- Shows \"X to Y of Z rows\" indicator\n- Only displays pagination when needed (>100 rows)\n- Better error propagation in download handlers\n\nCode Cleanup:\n- Remove 3 legacy directories (scripts/, sqliteExplorerApp/, sqliteExplorerApp_DEV/)\n- Delete 11 legacy files (HTMX scripts, duplicate CSS, old helpers)\n- Remove .DS_Store files\n- Clean up duplicate export helpers\n\nDocumentation:\n- Add comprehensive README.md with setup, API docs, architecture\n- Include installation, deployment, and troubleshooting guides\n- Document project structure and development workflow\n\nStats: -1046 lines of legacy code, +160 lines of improvements\nType checks: ✓ backend ✓ frontend ✓ shared\n\n🤖 Generated with [Claude Code](https://claude.com/claude-code)\n\nCo-Authored-By: Claude <noreply@anthropic.com>\nEOF\n)\")" ], "deny": [],${documentContent.substring(0, 5000)}`; const response = await fetch("https://api.anthropic.com/v1/messages", { method: "POST", headers: { "x-api-key": "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", "anthropic-version": "2023-06-01", }, body: JSON.stringify({import { Bot } from "https://deno.land/x/grammy@v1.35.0/mod.ts";import { DateTime } from "https://esm.sh/luxon@3.4.4";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3";import { backstory } from "../backstory.ts";import {} from "../memoryUtils.ts";async function generateBriefingContent(anthropic, memories, today, isSunday) { try { const weekdaysHelp = generateWeekDays(today); }; console.log("Sending prompt to Anthropic...", userMessage); const response = await anthropic.messages.create({ model: "claude-3-7-sonnet-latest", max_tokens: 30000,export async function sendDailyBriefing(chatId?: string, today?: DateTime) { // Get API keys from environment const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); const telegramToken = Deno.env.get("TELEGRAM_TOKEN"); if (!apiKey) { console.error("Anthropic API key is not configured."); return; } } // Initialize Anthropic client const anthropic = new Anthropic({ apiKey }); // Initialize Telegram bot // Generate briefing content const content = await generateBriefingContent( anthropic, memories, today,You'll need to set up some environment variables to make it run.- `ANTHROPIC_API_KEY` for LLM calls- You'll need to follow [these instructions](https://docs.val.town/integrations/telegram/) to make a telegram bot, and set `TELEGRAM_TOKEN`. You'll also need to get a `TELEGRAM_CHAT_ID` in order to have the bot remember chat contents.- For the Google Calendar integration you'll need `GOOGLE_CALENDAR_ACCOUNT_ID` and `GOOGLE_CALENDAR_CALENDAR_ID`. See [these instuctions](https://www.val.town/v/stevekrouse/pipedream) for details.import { DateTime } from "https://esm.sh/luxon@3.4.4";import Anthropic from "npm:@anthropic-ai/sdk@0.24.3";const RECIPIENTS = ["Geoffrey", "Maggie"] as const;async function analyzeHtmlContent( anthropic: Anthropic, htmlContent: string, imageSummaries: ImageSummary[]) { try { const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", max_tokens: 4196, console.log(e.text); // Get Anthropic API key from environment const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); if (!apiKey) { console.error("Anthropic API key is not configured for this val."); return; } // Initialize Anthropic client const anthropic = new Anthropic({ apiKey }); // Process each image attachment serially ); const response = await anthropic.messages.create({ model: "claude-3-5-sonnet-latest", max_tokens: 4196, // Analyze HTML content const htmlAnalysis = await analyzeHtmlContent( anthropic, e.html || "", summaries