Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(ai-proxy): query Vertex AI for models instead of hardcoding

Louis Beaumontc25bba3e8c3b
diff --git a/screenpipe-js/ai-proxy/src/providers/vertex.ts b/screenpipe-js/ai-proxy/src/providers/vertex.ts
index 44eb9e8ca..6b47fa26e 100644
--- a/screenpipe-js/ai-proxy/src/providers/vertex.ts
+++ b/screenpipe-js/ai-proxy/src/providers/vertex.ts
@@ -388,18 +388,45 @@ export class VertexAIProvider implements AIProvider {
}
/**
- * List available models - exact Vertex AI model IDs
+ * List available models by querying Vertex AI Model Garden
*/
async listModels(): Promise<{ id: string; name: string; provider: string }[]> {
+ try {
+ const accessToken = await this.getAccessToken();
+ // Query Vertex AI for Anthropic publisher models
+ const url = `https://${this.region}-aiplatform.googleapis.com/v1/publishers/anthropic/models`;
+ const response = await fetch(url, {
+ headers: {
+ Authorization: `Bearer ${accessToken}`,
+ },
+ });
+
+ if (!response.ok) {
+ console.error('Failed to list models from Vertex:', response.status);
+ // Fallback to known models if API fails
+ return this.getFallbackModels();
+ }
+
+ const data = await response.json();
+ const models = data.models || data.publisherModels || [];
+
+ return models.map((m: any) => ({
+ id: m.name?.split('/').pop() || m.modelId || m.id,
+ name: m.displayName || m.name || m.id,
+ provider: 'vertex',
+ }));
+ } catch (error) {
+ console.error('Error listing models:', error);
+ return this.getFallbackModels();
+ }
+ }
+
+ private getFallbackModels(): { id: string; name: string; provider: string }[] {
+ // Fallback only if API fails - these may be outdated
return [
- // Claude 4.x (latest)
- { id: 'claude-opus-4-5@20250915', name: 'Claude Opus 4.5', provider: 'vertex' },
{ id: 'claude-sonnet-4@20250514', name: 'Claude Sonnet 4', provider: 'vertex' },
{ id: 'claude-opus-4@20250514', name: 'Claude Opus 4', provider: 'vertex' },
- // Claude 3.x
- { id: 'claude-3-5-haiku@20241022', name: 'Claude 3.5 Haiku (fast)', provider: 'vertex' },
- { id: 'claude-3-7-sonnet@20250219', name: 'Claude 3.7 Sonnet', provider: 'vertex' },
- { id: 'claude-3-5-sonnet-v2@20241022', name: 'Claude 3.5 Sonnet v2', provider: 'vertex' },
+ { id: 'claude-3-5-haiku@20241022', name: 'Claude 3.5 Haiku', provider: 'vertex' },
];
}
}
@@ -506,45 +533,29 @@ export async function proxyToVertex(
}
}
-// Model aliases - map common/invalid names to valid Vertex AI model IDs
+// Model aliases - map common names to Vertex AI format
+// Only used for simple aliases, not format conversion
const MODEL_ALIASES: Record<string, string> = {
- // Haiku aliases
- 'claude-haiku-4-5': 'claude-3-5-haiku@20241022',
- 'claude-haiku-4-5-20251001': 'claude-3-5-haiku@20241022',
- 'claude-3-5-haiku': 'claude-3-5-haiku@20241022',
- 'claude-haiku': 'claude-3-5-haiku@20241022',
- // Sonnet aliases
- 'claude-sonnet-4': 'claude-sonnet-4@20250514',
- 'claude-sonnet-4-20250514': 'claude-sonnet-4@20250514',
- 'claude-4-sonnet': 'claude-sonnet-4@20250514',
+ // Simple aliases without dates -> latest version
+ 'claude-haiku': 'claude-haiku-4-5@20251001',
'claude-sonnet': 'claude-sonnet-4@20250514',
- // Opus aliases
- 'claude-opus-4': 'claude-opus-4@20250514',
- 'claude-opus-4-20250514': 'claude-opus-4@20250514',
- 'claude-4-opus': 'claude-opus-4@20250514',
- 'claude-opus-4-5': 'claude-opus-4-5@20250915',
- 'claude-opus-4-5-20250915': 'claude-opus-4-5@20250915',
'claude-opus': 'claude-opus-4@20250514',
};
-// Convert model ID format and apply aliases
+// Convert model ID format: claude-haiku-4-5-20251001 -> claude-haiku-4-5@20251001
export function mapModelToVertex(model: string): string {
- // Check for known aliases first
+ // Check for simple aliases (no date)
const lowerModel = model.toLowerCase();
if (MODEL_ALIASES[lowerModel]) {
return MODEL_ALIASES[lowerModel];
}
- // Match pattern: model-name-YYYYMMDD and convert last - to @
+ // Convert date suffix: model-YYYYMMDD -> model@YYYYMMDD
const match = model.match(/^(.+)-(\d{8})$/);
if (match) {
- const converted = `${match[1]}@${match[2]}`;
- // Check if converted form has an alias
- if (MODEL_ALIASES[converted.toLowerCase()]) {
- return MODEL_ALIASES[converted.toLowerCase()];
- }
- return converted;
+ return `${match[1]}@${match[2]}`;
}
+
return model;
}
diff --git a/screenpipe-vision/src/core.rs b/screenpipe-vision/src/core.rs
index b7cdb130b..888091bb0 100644
--- a/screenpipe-vision/src/core.rs
+++ b/screenpipe-vision/src/core.rs
@@ -14,6 +14,7 @@ use base64::{engine::general_purpose, Engine as _};
use chrono::{DateTime, Utc};
use image::codecs::jpeg::JpegEncoder;
use image::DynamicImage;
+use image::GenericImageView;
use screenpipe_core::Language;
use screenpipe_integrations::unstructured_ocr::perform_ocr_cloud;
use serde::Deserialize;
@@ -505,6 +506,67 @@ fn parse_json_output(json_output: &str) -> Vec<HashMap<String, String>> {
parsed_output
}
+/// Transform OCR coordinates from window-relative (normalized 0-1) to screen-relative (normalized 0-1).
+///
+/// OCR engines return coordinates normalized to the window image dimensions.
+/// This function transforms them to be normalized to the full screen dimensions,
+/// which is necessary because the video frames store the full screen capture.
+fn transform_ocr_coordinates_to_screen(
+ ocr_blocks: Vec<HashMap<String, String>>,
+ window_x: i32,
+ window_y: i32,
+ window_width: u32,
+ window_height: u32,
+ screen_width: u32,
+ screen_height: u32,
+) -> Vec<HashMap<String, String>> {
+ // Skip transformation if dimensions are invalid
+ if screen_width == 0 || screen_height == 0 || window_width == 0 || window_height == 0 {
+ return ocr_blocks;
+ }
+
+ let screen_w = screen_width as f64;
+ let screen_h = screen_height as f64;
+ let win_x = window_x as f64;
+ let win_y = window_y as f64;
+ let win_w = window_width as f64;
+ let win_h = window_height as f64;
+
+ ocr_blocks
+ .into_iter()
+ .map(|mut block| {
+ // Parse the normalized window coordinates (0-1 range)
+ if let (Some(left_str), Some(top_str), Some(width_str), Some(height_str)) = (
+ block.get("left").cloned(),
+ block.get("top").cloned(),
+ block.get("width").cloned(),
+ block.get("height").cloned(),
+ ) {
+ if let (Ok(left), Ok(top), Ok(width), Ok(height)) = (
+ left_str.parse::<f64>(),
+ top_str.parse::<f64>(),
+ width_str.parse::<f64>(),
+ height_str.parse::<f64>(),
+ ) {
+ // Transform from window-relative normalized coords to screen-relative normalized coords
+ // screen_coord = (window_offset + window_coord_normalized * window_size) / screen_size
+ let screen_left = (win_x + left * win_w) / screen_w;
+ let screen_top = (win_y + top * win_h) / screen_h;
+ let screen_width_normalized = (width * win_w) / screen_w;
+ let screen_height_normalized = (height * win_h) / screen_h;
+
+ // Update the block with screen-relative coordinates
+ block.insert("left".to_string(), screen_left.to_string());
+ block.insert("top".to_string(), screen_top.to_string());
+ block.insert("width".to_string(), screen_width_normalized.to_string());
+ block.insert("height".to_string(), screen_height_normalized.to_string());
+ }
+ }
+ block
+ })
+ .collect()
+}
+
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RealtimeVisionEvent {
Ocr(WindowOcr),