UNPKG

pulse-ai-utils

Version:

Utility functions and helpers for AI-powered applications

129 lines 4.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeGeographicSearch = executeGeographicSearch; exports.streamGeographicSearch = streamGeographicSearch; const geo_search_service_1 = require("../services/geo-search-service"); const location_service_1 = require("../services/location-service"); const supabase_1 = require("../supabase"); /** * Execute geographic search with location-based content discovery */ async function executeGeographicSearch(params) { const startTime = Date.now(); const locationService = new location_service_1.LocationService(); try { // Determine location let lat; let lng; let locationSource; if (params.lat !== undefined && params.lng !== undefined) { lat = params.lat; lng = params.lng; locationSource = 'coordinates'; } else if (params.area) { const location = await locationService.getLocationFromArea(params.area); if (!location) { throw new Error(`Unknown area: ${params.area}`); } lat = location.lat; lng = location.lng; locationSource = 'area'; } else { // Default to Tampa lat = 27.9478; lng = -82.4584; locationSource = 'default'; } console.log(`[GeographicSearch] Using location: ${lat}, ${lng} (source: ${locationSource})`); // Initialize search service const geoSearchService = new geo_search_service_1.GeoSearchService({ firestoreDb: params.firestoreDb || null, supabaseClient: supabase_1.supabase, useSupabase: true, minResults: params.minResults || 20 }); // Perform search const searchOptions = { type: params.type || params.category, initialRadius: params.radius || 5, maxRadius: params.maxRadius || 50, minResults: params.minResults || 20, limit: params.limit || 50 }; const result = await geoSearchService.searchNearby(lat, lng, searchOptions); return { success: true, data: result.results, source: 'geographic', strategy: 'geo_search', location: { lat, lng, source: locationSource }, search: { radius_used: result.searchRadius, total_found: result.totalFound }, timing: { total_ms: Date.now() - startTime }, timestamp: new Date().toISOString() }; } catch (error) { console.error('[GeographicSearch] Error:', error); return { success: false, data: [], source: 'geographic', strategy: 'geo_search', location: { lat: 0, lng: 0, source: 'default' }, search: { radius_used: 0, total_found: 0 }, timing: { total_ms: Date.now() - startTime }, timestamp: new Date().toISOString() }; } } /** * Stream geographic search results */ async function* streamGeographicSearch(params) { yield { type: 'start', strategy: 'geo_search' }; const result = await executeGeographicSearch(params); if (result.success) { yield { type: 'metadata', location: result.location, search: result.search }; // Yield results one by one for (const item of result.data) { yield { type: 'data_item', item, distance: item.distance_miles, relevance: item.relevance_score }; } } else { yield { type: 'error', error: 'Geographic search failed' }; } yield { type: 'complete', timing: result.timing }; } //# sourceMappingURL=llm-geographic.js.map