Search
Code3,144
import { createAnthropic } from "npm:@ai-sdk/anthropic@latest";import { generateObject } from "npm:ai@latest";import { z } from "npm:zod@latest";});const anthropic = createAnthropic({ apiKey: Deno.env.get("ANTHROPIC_API_KEY"),}); const { object, usage } = await generateObject({ model: anthropic("claude-haiku-4-5-20251001"), messages: [ { role: "user", content: prompt }, image: "imageData", providerOptions: { anthropic: { cacheControl: { type: "ephemeral" } }, }, }, }, "imports": { "@ai-sdk/anthropic": "npm:@ai-sdk/anthropic@^2.0.45", "@biomejs/biome": "npm:@biomejs/biome@^2.3.5", "ai": "npm:ai@^5.0.100", const body = await req.json(); // Call Anthropic API const response = await fetch("https://api.anthropic.com/v1/messages", { method: "POST", headers: { "Content-Type": "application/json", "x-api-key": Deno.env.get("ANTHROPIC_API_KEY"), "anthropic-version": "2023-06-01", }, body: JSON.stringify(body), "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": [],import Anthropic from "https://esm.sh/@anthropic-ai/sdk@0.24.3";import { Hono } from "https://esm.sh/hono@4.4.2";import { serveFile,} from "https://esm.town/v/std/utils@85-main/index.ts";import { createAnthropic } from "npm:@ai-sdk/anthropic";import { generateObject } from "npm:ai";import { z } from "npm:zod"; } const anthropic = createAnthropic({ apiKey: Deno.env.get("ANTHROPIC_API_KEY"), }); const { object: foodItemsObject } = await generateObject({ model: anthropic("claude-haiku-4-5-20251001"), messages: [ { }, "imports": { "@ai-sdk/anthropic": "npm:@ai-sdk/anthropic@^2.0.45", "@biomejs/biome": "npm:@biomejs/biome@^2.3.5", "ai": "npm:ai@^5.0.100",// example.tsimport { createAnthropic } from "npm:@ai-sdk/anthropic";import { generateObject } from "npm:ai";import { z } from "npm:zod";});const anthropic = createAnthropic({ apiKey: Deno.env.get("ANTHROPIC_API_KEY"),}); const { object: sonnetObject, usage: sonnetUsage } = await generateObject({ model: anthropic("claude-sonnet-4-5-20250929"), messages, maxOutputTokens: 1024, const { object: haikuObject, usage: haikuUsage } = await generateObject({ model: anthropic("claude-haiku-4-5-20251001"), messages, maxOutputTokens: 1024,// Paste this into Val Townimport { Anthropic } from "npm:@anthropic-ai/sdk";const userState = new Map();}async function identifyProduct(url, anthropic) { const response = await anthropic.messages.create({ model: "claude-sonnet-4-20250514", max_tokens: 200,}async function generateResponse(product, mode, context, anthropic) { const prompt = mode === "sell" ? `VOICE: You're their friend who happens to have impeccable taste. Emma Chamberlain clarity + Taylor Swift emotional intelligence + Alex Cooper directness. You text like a real person — not a bot.CRITICAL: 40-60 words MAX. This is a text. Be natural.`; const response = await anthropic.messages.create({ model: "claude-sonnet-4-20250514", max_tokens: 250, message, conversationHistory, anthropic,) { const response = await anthropic.messages.create({ model: "claude-sonnet-4-20250514", max_tokens: 150, try { const ANTHROPIC_API_KEY = "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"; const anthropic = new Anthropic({ apiKey: ANTHROPIC_API_KEY }); const formData = await req.formData(); `that's your ${FREE_MESSAGE_LIMIT} freebies used up 🔒 unlimited coming soon, promise`; } else { const product = await identifyProduct(urlToUse, anthropic); // Pass their message as context so response can reference it reply = await generateResponse(product, mode, body, anthropic); user.usageCount++; user.pendingUrl = null; body, user.conversationHistory, anthropic, ); } // Case 3: Mode but no URL → need a link body, user.conversationHistory, anthropic, ); }export default async function (req: Request): Promise<Response> { const ANTHROPIC_API_KEY = Deno.env.get("ANTHROPIC_API_KEY"); // Enable CORS try { const response = await fetch("https://api.anthropic.com/v1/messages", { method: "POST", headers: { "Content-Type": "application/json", "x-api-key": ANTHROPIC_API_KEY, "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,