163164try {
165const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}`;
166console.log("🔍 Sending title update request to:", url);
167179});
180181console.log("🔍 GitHub API response status:", response.status);
182183if (response.ok) {
189try {
190const error = await response.json();
191console.error("❌ GitHub API error:", JSON.stringify(error));
192errorMessage = error.message || errorMessage;
193} catch (e) {
194const errorText = await response.text();
195console.error("❌ GitHub API error text:", errorText);
196}
197return { success: false, message: errorMessage };
198}
199} catch (error) {
200console.error("❌ Exception during API call:", error);
201return { success: false, message: error.message };
202}
5// ❗❗❗ DO NOT USE YOUR TOKEN IN THE BROWSER FOR PRODUCTION. It should be kept and used server-side.
6const APP_TOKEN = process.env.APP_TOKEN;
7// We'll use this for authentication when making requests to the Calls API.
8const headers = {
9Authorization: `Bearer ${APP_TOKEN}`,
10};
11const API_BASE = `https://rtc.live.cloudflare.com/v1/apps/${APP_ID}`;
1213const echoMagic = crypto.randomUUID();
2122const channel1resp = await fetch(
23`${API_BASE}/sessions/${session1.sessionId}/datachannels/new`,
24{
25method: "POST",
4546const channel1SubscribeResp = await fetch(
47`${API_BASE}/sessions/${session2.sessionId}/datachannels/new`,
48{
49method: "POST",
136);
137const { sessionId, sessionDescription } = await fetch(
138`${API_BASE}/sessions/new`,
139{
140method: "POST",
blob_adminmain.tsx6 matches
1415// Public route without authentication
16app.get("/api/public/:id", async (c) => {
17const key = `__public/${c.req.param("id")}`;
18const { blob } = await import("https://esm.town/v/std/blob");
132};
133134app.get("/api/blobs", checkAuth, async (c) => {
135const prefix = c.req.query("prefix") || "";
136const limit = parseInt(c.req.query("limit") || "20", 10);
141});
142143app.get("/api/blob", checkAuth, async (c) => {
144const key = c.req.query("key");
145if (!key) return c.text("Missing key parameter", 400);
149});
150151app.put("/api/blob", checkAuth, async (c) => {
152const key = c.req.query("key");
153if (!key) return c.text("Missing key parameter", 400);
158});
159160app.delete("/api/blob", checkAuth, async (c) => {
161const key = c.req.query("key");
162if (!key) return c.text("Missing key parameter", 400);
166});
167168app.post("/api/blob", checkAuth, async (c) => {
169const { file, key } = await c.req.parseBody();
170if (!file || !key) return c.text("Missing file or key", 400);
blob_adminapp.tsx19 matches
70const menuRef = useRef(null);
71const isPublic = blob.key.startsWith("__public/");
72const publicUrl = isPublic ? `${window.location.origin}/api/public/${encodeURIComponent(blob.key.slice(9))}` : null;
7374useEffect(() => {
234setLoading(true);
235try {
236const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237const data = await response.json();
238setBlobs(data);
261setBlobContentLoading(true);
262try {
263const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264const content = await response.text();
265setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
275const handleSave = async () => {
276try {
277await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
278method: "PUT",
279body: editContent,
287const handleDelete = async (key) => {
288try {
289await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
290setBlobs(blobs.filter(b => b.key !== key));
291if (selectedBlob && selectedBlob.key === key) {
304const key = `${searchPrefix}${file.name}`;
305formData.append("key", encodeKey(key));
306await fetch("/api/blob", { method: "POST", body: formData });
307const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
308setBlobs([newBlob, ...blobs]);
326try {
327const fullKey = `${searchPrefix}${key}`;
328await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
329method: "PUT",
330body: "",
341const handleDownload = async (key) => {
342try {
343const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
344const blob = await response.blob();
345const url = window.URL.createObjectURL(blob);
360if (newKey && newKey !== oldKey) {
361try {
362const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
363const content = await response.blob();
364await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
365method: "PUT",
366body: content,
367});
368await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
369setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
370if (selectedBlob && selectedBlob.key === oldKey) {
380const newKey = `__public/${key}`;
381try {
382const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
383const content = await response.blob();
384await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
385method: "PUT",
386body: content,
387});
388await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
389setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
390if (selectedBlob && selectedBlob.key === key) {
399const newKey = key.slice(9); // Remove "__public/" prefix
400try {
401const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
402const content = await response.blob();
403await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
404method: "PUT",
405body: content,
406});
407await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
408setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
409if (selectedBlob && selectedBlob.key === key) {
554onClick={() =>
555copyToClipboard(
556`${window.location.origin}/api/public/${encodeURIComponent(selectedBlob.key.slice(9))}`,
557)}
558className="text-blue-400 hover:text-blue-300 text-sm"
577>
578<img
579src={`/api/blob?key=${encodeKey(selectedBlob.key)}`}
580alt="Blob content"
581className="max-w-full h-auto"
42</h2>
43<ol>
44<li>Login with your Val Town API token (with projects:read, projects:write, user:read permissions)</li>
45<li>Select a project to work on</li>
46<li>Chat with Claude about your code</li>
79</div>
80<h3>Cost Tracking</h3>
81<p>See estimated API usage costs for each interaction</p>
82</div>
83</section>
92<ul>
93<li>React frontend with TypeScript</li>
94<li>Hono API server backend</li>
95<li>Web Audio API for sound notifications</li>
96<li>AI SDK for Claude integration</li>
97</ul>
98<p>
99The application proxies requests to the Anthropic API and Val Town API, allowing Claude to view and edit your
100project files directly.
101</p>
TownieLoginRoute.tsx8 matches
8const { isAuthenticated, authenticate, error } = useAuth();
9const [tokenValue, setTokenValue] = useState("");
10const [apiKey, setApiKey] = useState("");
11// const [invalid, setInvalid] = useState(""); // TODO
1213const handleSubmit = (e) => {
14e.preventDefault();
15authenticate(tokenValue, apiKey);
16};
1736>
37<div>
38<label htmlFor="valtown-token" className="label">Val Town API Token</label>
39<div style={{ fontSize: "0.8em", color: "#666" }}>
40<p>
41<a href="https://www.val.town/settings/api/new" target="_blank" rel="noreferrer">
42Create a Val Town token here
43</a>
58</div>
59<div>
60<label htmlFor="anthropic-api-key" className="label">Anthropic API Key (optional)</label>
61<input
62type="password"
63id="anthropic-api-key"
64name="anthropic-key"
65value={apiKey}
66onChange={e => {
67setApiKey(e.target.value);
68}}
69/>
1/**
2* Sends a message to a Telegram chat via the Telegram Bot API
3* Requires a Telegram Bot token as an environment variable
4*/
10}
1112const telegramApiUrl = `https://api.telegram.org/bot${botToken}/sendMessage`;
1314const response = await fetch(telegramApiUrl, {
15method: 'POST',
16headers: {
25if (!response.ok) {
26const errorBody = await response.text();
27throw new Error(`Telegram API error: ${response.status} ${errorBody}`);
28}
29
Towniesend-message.ts6 matches
20}
2122const { messages, project, branchId, anthropicApiKey, selectedFiles, images } = await c.req.json();
23// console.log("Original messages:", JSON.stringify(messages, null, 2));
24// console.log("Images received:", JSON.stringify(images, null, 2));
2526const apiKey = anthropicApiKey || Deno.env.get("ANTHROPIC_API_KEY");
27const our_api_token = apiKey === Deno.env.get("ANTHROPIC_API_KEY");
2829if (our_api_token) {
30if (await overLimit(bearerToken)) {
31return Response.json("You have reached the limit of Townie in a 24 hour period.", { status: 403 });
3435const anthropic = createAnthropic({
36apiKey,
37});
38159onFinish: async (result: any) => {
160await trackUsage({
161our_api_token,
162bearerToken, // will look up the userId from this
163branch_id: branchId,
Townieusage-dashboard.ts3 matches
76SUM(num_images) as total_images
77FROM ${USAGE_TABLE}
78WHERE our_api_token = 1
79GROUP BY user_id, username
80ORDER BY total_price DESC
256<th>Finish</th>
257<th>Images</th>
258<th>Our API</th>
259</tr>
260</thead>
276<td>${row.finish_reason}</td>
277<td>${formatNumber(row.num_images)}</td>
278<td>${formatBoolean(row.our_api_token)}</td>
279</tr>
280`).join("")
Townieschema.tsx2 matches
17finish_reason: string;
18num_images: number;
19our_api_token: boolean;
20}
2137finish_reason TEXT,
38num_images INTEGER,
39our_api_token INTEGER NOT NULL
40)
41`);