8* Hono JSX
9* HTMX (probably overcomplicates things; should remove)
10* @stevekrouse/openai, which is a light wrapper around @std/openai
1112I'm finding HTMX a bit overpowered for this, so I have two experimental forks without it:
emailSummaryHandlermain.tsx3 matches
2import { email } from "https://esm.town/v/std/email";
3import { extractValInfo } from "https://esm.town/v/stevekrouse/extractValInfo";
4import { OpenAI } from "npm:openai";
56function stripHtmlBackticks(html: string): string {
910export default async function(e: Email) {
11const openai = new OpenAI();
12console.log(`from: ${e.from} to: ${e.to} subject: ${e.subject}, cc: ${e.cc}, bcc: ${e.bcc}`);
1325}
2627const summary = await openai.chat.completions.create({
28messages: [
29{
researchAgentemailHandler2 matches
2import process from "node:process";
3import { marked } from "npm:marked";
4import { OpenAI } from "npm:openai";
56function pm(...lines: string[]): string {
16);
1718const client = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: "https://api.perplexity.ai" });
19const response = await client.chat.completions.create({
20model: "sonar",
vtProjectSearch2components.tsx2 matches
1215<a href="?q=function" className="example-link">function</a>
1216<a href="?q=discord" className="example-link">discord</a>
1217<a href="?q=openai" className="example-link">openai</a>
1218<a href="?q=react" className="example-link">react</a>
1219</div>
1360<a href="?q=function" className="example-link">function</a>
1361<a href="?q=discord" className="example-link">discord</a>
1362<a href="?q=openai" className="example-link">openai</a>
1363<a href="?q=react" className="example-link">react</a>
1364</div>
vtProjectSearchcomponents.tsx2 matches
1215<a href="?q=function" className="example-link">function</a>
1216<a href="?q=discord" className="example-link">discord</a>
1217<a href="?q=openai" className="example-link">openai</a>
1218<a href="?q=react" className="example-link">react</a>
1219</div>
1360<a href="?q=function" className="example-link">function</a>
1361<a href="?q=discord" className="example-link">discord</a>
1362<a href="?q=openai" className="example-link">openai</a>
1363<a href="?q=react" className="example-link">react</a>
1364</div>
vtProjectSearchcomponents.tsx2 matches
1215<a href="?q=function" className="example-link">function</a>
1216<a href="?q=discord" className="example-link">discord</a>
1217<a href="?q=openai" className="example-link">openai</a>
1218<a href="?q=react" className="example-link">react</a>
1219</div>
1360<a href="?q=function" className="example-link">function</a>
1361<a href="?q=discord" className="example-link">discord</a>
1362<a href="?q=openai" className="example-link">openai</a>
1363<a href="?q=react" className="example-link">react</a>
1364</div>
1// Combined Frontend (React/ChakraUI) and Backend (Hono/OpenAI) for Val Town
2// Funding Assistant Dashboard Prototype - v6 (Corrected AgencyInfo Prompt Logic)
3509export default async function server(request: Request): Promise<Response> {
510// Only import server-side dependencies here
511const { OpenAI } = await import("https://esm.town/v/std/openai");
512// const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite"); // DB optional
513const { Hono } = await import("npm:hono");
514515// --- OpenAI Client ---
516// Ensure API key is set as Val Town env var 'openai'
517let openai;
518try {
519openai = new OpenAI();
520} catch (e) {
521console.error("FATAL: Failed to initialize OpenAI client. Is the 'openai' environment variable set?", e);
522// Return a generic server error response if OpenAI cannot be initialized
523return new Response(JSON.stringify({ error: "Server configuration error. Unable to initialize OpenAI client." }), {
524status: 500,
525headers: { "Content-Type": "application/json" },
675];
676677// --- Call OpenAI ---
678console.log(`Calling OpenAI for agent: ${agentType}...`);
679const completion = await openai.chat.completions.create({
680messages: messages,
681model: "gpt-4o",
706707} catch (error) {
708// Catches errors in request handling, OpenAI API call itself, etc.
709console.error(`Critical error initiating agent ${agentType}:`, error);
710let errorMsg = `Server error initiating agent ${agentType}.`;
711// Check for specific OpenAI errors if needed for better diagnostics
712// if (error instanceof OpenAI.APIError) { errorMsg = `OpenAI API Error: ${error.status} ${error.message}`; }
713else if (error.message) {
714errorMsg = `${errorMsg} Details: ${error.message}`;
OpenTownietownie.mdc4 matches
54Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
5556### OpenAI
5758```ts
59import { OpenAI } from "https://esm.town/v/std/openai";
60const openai = new OpenAI();
61const completion = await openai.chat.completions.create({
62messages: [
63{ role: "user", content: "Say hello in a creative way" },
OpenTowniesystem_prompt.txt4 matches
49Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
5051### OpenAI
5253```ts
54import { OpenAI } from "https://esm.town/v/std/openai";
55const openai = new OpenAI();
56const completion = await openai.chat.completions.create({
57messages: [
58{ role: "user", content: "Say hello in a creative way" },
reactRouter7ExampleTODO.md1 match
1- [ ] Get OpenTownie or Gemini or Claude or OpenAI to synthesize the core of these patterns into a prompt we can use to make more ReactRouter apps, such as...
2- [ ] Convert this or into the basic react router guest book (and preserve this forum app in another project?)
3- [ ] To what extent can these patterns be packaged up into a Val Town Router project? Would be neat to get the version pinning thing all centralized, can this as-a-library be that centralized place?