TownieuseCreateProject.tsx1 match
1import { useState, useEffect } from "react";
23const ENDPOINT = "/api/create-project";
45export function useCreateProject() {
TownieuseCreateBranch.tsx1 match
1import { useState, useEffect } from "react";
23const ENDPOINT = "/api/create-branch";
45export function useCreateBranch(projectId: string) {
TownieuseChatLogic.ts2 matches
17project,
18branchId,
19// anthropicApiKey,
20// bearerToken,
21selectedFiles,
39status,
40} = useChat({
41api: "/api/send-message",
42body: {
43project,
TownieuseBranches.tsx1 match
1import { useState, useEffect } from "react";
23const ENDPOINT = "/api/project-branches";
45export function useBranches (projectId: string) {
Townieusage-detail.ts2 matches
18finish_reason?: string;
19num_images?: number;
20our_api_token: boolean;
21}
22129</div>
130<div class="card-item">
131<strong>Our API:</strong> ${formatBoolean(usage.our_api_token)}
132</div>
133</div>
Towniesystem_prompt.txt9 matches
13- Generate code in TypeScript or TSX
14- Add appropriate TypeScript types and interfaces for all data structures
15- Prefer official SDKs or libraries than writing API calls directly
16- Ask the user to supply API or library documentation if you are at all unsure about it
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
23### 1. HTTP Trigger
2425- Create web APIs and endpoints
26- Handle HTTP requests and responses
27- Example structure:
158- **AI Image:** To inline generate an AI image use: `<img src="https://maxm-imggenurl.web.val.run/the-description-of-your-image" />`
159- **Storage:** DO NOT use the Deno KV module for storage
160- **Browser APIs:** DO NOT use the `alert()`, `prompt()`, or `confirm()` methods
161- **Weather Data:** Use open-meteo for weather data (doesn't require API keys) unless otherwise specified
162- **Error Debugging:** Add `<script src="https://esm.town/v/std/catch"></script>` to HTML to capture client-side errors
163- **Error Handling:** Only use try...catch when there's a clear local resolution; Avoid catches that merely log or return 500s. Let errors bubble up with full context
164- **Environment Variables:** Use `Deno.env.get('keyname')` when you need to, but generally prefer APIs that don't require keys
165- **Imports:** Use `https://esm.sh` for npm and Deno dependencies to ensure compatibility on server and browser
166- **Storage Strategy:** Only use backend storage if explicitly required; prefer simple static client-side sites
200### Backend (Hono) Best Practices
201202- Hono is the recommended API framework
203- Main entry point should be `backend/index.ts`
204- Do NOT use Hono serveStatic middleware
225});
226```
227- Create RESTful API routes for CRUD operations
228- Always include this snippet at the top-level Hono app to re-throwing errors to see full stack traces:
229```ts
262- For files in the project, use `readFile` helpers
2632645. **API Design:**
265- `fetch` handler is the entry point for HTTP vals
266- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
Towniestripe-webhook.ts2 matches
89const stripe = new Stripe(Deno.env.get(getEnvVarName("STRIPE_SECRET_KEY")) as string, {
10apiVersion: "2024-06-20",
11});
1251// const paymentIntent: Stripe.PaymentIntent = await stripe.paymentIntents.retrieve(session.client_reference_id);
5253const response = await fetch(`https://api.stripe.com/v1/payment_intents/${session.client_reference_id}`, {
54method: "GET",
55headers: {
TowniesoundEffects.ts4 matches
45/**
6* Plays a bell sound notification using the Web Audio API
7* @returns A Promise that resolves when the sound has started playing
8*/
13const AudioContext = window.AudioContext || (window as any).webkitAudioContext;
14if (!AudioContext) {
15console.warn("Web Audio API not supported in this browser");
16resolve();
17return;
6566/**
67* Plays a simple notification sound using the Web Audio API
68* This is a simpler, shorter bell sound
69* @returns A Promise that resolves when the sound has started playing
75const AudioContext = window.AudioContext || (window as any).webkitAudioContext;
76if (!AudioContext) {
77console.warn("Web Audio API not supported in this browser");
78resolve();
79return;
Towniesend-message.ts12 matches
48project,
49branchId,
50anthropicApiKey,
51selectedFiles,
52images,
5455// do we want to allow user-provided tokens still
56const apiKey = anthropicApiKey || Deno.env.get("ANTHROPIC_API_KEY");
57const our_api_token = apiKey === Deno.env.get("ANTHROPIC_API_KEY");
5859if (our_api_token) {
60if (await hasInsufficientCredits({ bearerToken })) {
61return Response.json({
7374const rowid = await startTrackingUsage({
75our_api_token,
76bearerToken, // will look up the userId from this
77branch_id: branchId,
8283// Initialize PostHog client
84const projectApiKey = Deno.env.get("POSTHOG_PROJECT_API_KEY");
8586let tracedModel;
8788if (projectApiKey) {
89const phClient = new PostHog(projectApiKey, {
90host: "https://us.i.posthog.com",
91});
98const traceId = `townie_${rowid}_${Date.now()}`;
99100const anthropic = createAnthropic({ apiKey });
101102// Wrap the Anthropic model with PostHog tracing
108townie_branch_id: branchId,
109townie_usage_id: rowid,
110townie_our_api_token: our_api_token,
111townie_num_images: images?.length || 0,
112townie_selected_files_count: selectedFiles?.length || 0,
121} else {
122// Fallback to regular Anthropic call if PostHog is not configured
123const anthropic = createAnthropic({ apiKey });
124tracedModel = anthropic(model);
125}
275});
276277if (our_api_token) {
278const stillHasCredits =
279!(await hasInsufficientCredits({ bearerToken })); // Check for at least 1 cent
Townieschema.tsx2 matches
20finish_reason?: string;
21num_images?: number;
22our_api_token: boolean;
23}
2445finish_reason TEXT,
46num_images INTEGER,
47our_api_token INTEGER NOT NULL,
48finish_timestamp INTEGER
49)`,