Townie-02queries.tsx5 matches
24user_id = ?
25AND timestamp > ?
26AND our_api_token = 1
27`,
28[userId, new Date().getTime() - 24 * 60 * 60 * 1000],
108branch_id,
109model,
110our_api_token,
111num_images,
112}: {
115branch_id: string;
116model: string;
117our_api_token: boolean;
118num_images: number;
119}) {
127branch_id,
128model,
129our_api_token,
130num_images
131) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
138branch_id,
139model,
140our_api_token ? 1 : 0,
141num_images,
142],
Townie-02Preview.tsx1 match
90value={customPath}
91onChange={handlePathChange}
92placeholder="Path (e.g., /api/data)"
93/>
94</div>
Townie-02LoginRoute.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/>
1import { basicAuthMiddleware } from "./auth.ts";
2import { handleApiRequest } from "./api/index.ts";
3import { getRequests } from "./api/requests.ts";
4import { getUserSummary } from "./api/user-summary.ts";
5import { getInferenceCalls } from "./api/inference-calls.ts";
6import { renderDashboard } from "./views/dashboard.ts";
7import { renderRequests } from "./views/requests.ts";
22const path = url.pathname;
2324// Handle API requests
25if (path.startsWith("/api/")) {
26return handleApiRequest(req);
27}
28
45/**
6* Handle API requests
7*/
8export async function handleApiRequest(req: Request): Promise<Response> {
9const url = new URL(req.url);
10const path = url.pathname.replace("/api/", "");
11
12try {
13// Route to the appropriate API handler
14if (path === "requests") {
15const usageId = url.searchParams.get("usage_id");
59}
60} catch (error) {
61console.error("API error:", error);
62return new Response(JSON.stringify({ error: error.message }), {
63status: 500,
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>
cerebras_coderREADME.md2 matches
671. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
1011# Todos
cerebras_codermain.tsx5 matches
212} catch (error) {
213Toastify({
214text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215position: "center",
216duration: 3000,
971};
972} else {
973const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
974const completion = await client.chat.completions.create({
975messages: [
1096<meta name="viewport" content="width=device-width, initial-scale=1.0">
1097<title>CerebrasCoder</title>
1098<link rel="preconnect" href="https://fonts.googleapis.com" />
1099<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1100<link
1101href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
1102rel="stylesheet"
1103/>
1112<meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
1113<meta property="og:type" content="website">
1114<meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1115
1116
ValTown-Package-Trackerindex.html2 matches
151async function loadDevices() {
152try {
153const response = await fetch('/api/devices');
154const devices = await response.json();
155
175try {
176const deviceId = deviceSelector.value;
177const url = deviceId ? `/api/locations?deviceId=${deviceId}` : '/api/locations';
178
179const response = await fetch(url);
ValTown-Package-Trackerindex.ts22 matches
4041// Debug endpoint to check system status
42app.get("/api/debug/status", async (c) => {
43try {
44// Check database connection
93app.get("/frontend/*", (c) => serveFile(c.req.path, import.meta.url));
9495// API endpoint to receive ChirpStack payloads
96app.post("/api/location", async (c) => {
97console.log("[INGEST] Received payload request");
98
186});
187188// API endpoint to get location history
189app.get("/api/locations", async (c) => {
190console.log("[API] Fetching location history");
191
192try {
193const deviceId = c.req.query("deviceId");
194if (deviceId) {
195console.log(`[API] Filtering locations by device ID: ${deviceId}`);
196} else {
197console.log("[API] Fetching all locations (no device filter)");
198}
199const { rows } = await getLocationHistory(deviceId);
203);
204console.log(
205`[API] Retrieved ${rows.length} total, ${filtered.length} in North America`
206);
207return c.json(filtered);
208209} catch (error) {
210console.error("[API] Error fetching location history:", error);
211return c.json({
212error: "Database error",
217});
218219// API endpoint to get a specific location
220app.get("/api/locations/:id", async (c) => {
221try {
222const idParam = c.req.param("id");
223console.log(`[API] Fetching location with ID: ${idParam}`);
224
225const id = parseInt(idParam);
226if (isNaN(id)) {
227console.error(`[API] Invalid location ID: ${idParam}`);
228return c.json({
229error: "Invalid parameter",
234const location = await getLocationById(id);
235if (!location) {
236console.log(`[API] Location not found with ID: ${id}`);
237return c.json({
238error: "Not found",
241}
242
243console.log(`[API] Successfully retrieved location with ID: ${id}`);
244return c.json(location);
245} catch (error) {
246console.error(`[API] Error fetching location:`, error);
247return c.json({
248error: "Database error",
253});
254255// API endpoint to get list of devices
256app.get("/api/devices", async (c) => {
257console.log("[API] Fetching device list");
258
259try {
260const devices = await getDevices();
261console.log(`[API] Successfully retrieved ${devices.rows.length} devices`);
262return c.json(devices.rows);
263} catch (error) {
264console.error("[API] Error fetching devices:", error);
265return c.json({
266error: "Database error",