aimemoryindex.html2 matches
67// Debug helper
68const debug = {
69log: function(message, data) {
70const debugElement = document.getElementById('debug');
71const timestamp = new Date().toISOString().split('T')[1].split('.')[0];
78debugElement.appendChild(logEntry);
79},
80clear: function() {
81document.getElementById('debug').innerHTML = '';
82}
1011// Initialize the database table
12async function initializeDatabase() {
13await sqlite.execute(`
14CREATE TABLE IF NOT EXISTS ${MEMORY_TABLE} (
2223// Save a new memory snippet
24async function saveMemory(content: string, tags: string = "") {
25await sqlite.execute(
26`INSERT INTO ${MEMORY_TABLE} (content, tags) VALUES (?, ?)`,
3132// Search for relevant memories based on a query
33async function searchMemories(query: string): Promise<Array<{ id: number; content: string; tags: string; created_at: string }>> {
34// Simple search implementation - could be improved with embeddings or more sophisticated search
35const results = await sqlite.execute(
4243// Get all memories from the database
44async function getAllMemories(): Promise<Array<{ id: number; content: string; tags: string; created_at: string }>> {
45const results = await sqlite.execute(
46`SELECT * FROM ${MEMORY_TABLE} ORDER BY created_at DESC`
5152// Fallback response generator when OpenAI is not available
53function generateFallbackResponse(query: string, memories: Array<{ content: string; tags?: string }> = []) {
54if (memories.length === 0) {
55return `I don't have any memories stored yet. You can teach me by saving some information.`;
7273// Generate a response using OpenAI, incorporating memories if available
74async function generateResponse(query: string, memories: Array<{ content: string; tags?: string }> = []) {
75try {
76// Format all memories as context
114115// Process the incoming request
116async function processRequest(req: Request) {
117// Initialize database on each request (only creates if not exists)
118await initializeDatabase();
183184// HTTP handler
185export default async function(req: Request) {
186// Handle OPTIONS for CORS
187if (req.method === "OPTIONS") {
HTOCHeader.tsx1 match
2import React from "https://esm.sh/react@18.2.0";
34export default function Header() {
5return (
6<header className="bg-indigo-600 text-white shadow-md">
13}
1415export default function App({ initialData }: AppProps) {
16const [properties, setProperties] = useState<Property[]>(initialData.properties);
17const [loading, setLoading] = useState(false);
67- `types.ts` - TypeScript interfaces used throughout the application
8- `utils.ts` - Utility functions for formatting and data manipulation
910## Usage
1// Format price as currency
2export function formatPrice(price: number): string {
3return new Intl.NumberFormat('en-US', {
4style: 'currency',
910// Format number with commas
11export function formatNumber(num: number): string {
12return new Intl.NumberFormat('en-US').format(num);
13}
1415// Format bathrooms (handle .5 for half baths)
16export function formatBathrooms(bathrooms: number): string {
17return bathrooms % 1 === 0 ? bathrooms.toString() : bathrooms.toFixed(1);
18}
21}
2223// Utility functions that work in both browser and Deno
24export function formatDate(dateString: string): string {
25if (!dateString) return '';
26const date = new Date(dateString);
32}
3334export function formatTime(dateString: string): string {
35if (!dateString) return '';
36const date = new Date(dateString);
4243// Validation utilities
44export function validateEmail(email: string): boolean {
45const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
46return re.test(email);
47}
4849export function validateJobPosting(job: Partial<JobPosting>): { valid: boolean; error?: string } {
50if (!job.title || job.title.trim() === '') {
51return { valid: false, error: 'Job title is required' };
1function app() {
2return {
3// State
218},
219220// Utility functions
221formatDate(dateString) {
222if (!dateString) return '';
1# Database Layer
23This directory contains the database schema and query functions for the House Hunter application.
45## Files
67- `migrations.ts` - Contains the database schema definitions and initial data seeding
8- `queries.ts` - Contains functions for querying the database
910## Schema
31## Usage
3233The database is automatically initialized when the application starts. The `runMigrations` function creates the necessary tables and seeds initial data if needed.
HTOCqueries.ts4 matches
3233// Get all properties with optional filtering
34export async function getProperties(filters: PropertyFilters = {}): Promise<Property[]> {
35let query = `SELECT * FROM ${PROPERTIES_TABLE} WHERE 1=1`;
36const params: any[] = [];
8586// Get a single property by ID
87export async function getPropertyById(id: number): Promise<Property | null> {
88const result = await sqlite.execute(
89`SELECT * FROM ${PROPERTIES_TABLE} WHERE id = ?`,
99100// Get cities for dropdown
101export async function getCities(): Promise<string[]> {
102const result = await sqlite.execute(
103`SELECT DISTINCT city FROM ${PROPERTIES_TABLE} ORDER BY city ASC`
108109// Get states for dropdown
110export async function getStates(): Promise<string[]> {
111const result = await sqlite.execute(
112`SELECT DISTINCT state FROM ${PROPERTIES_TABLE} ORDER BY state ASC`