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

feat(ai-proxy): migrate to new cloudflare account with api.screenpi.pe

Louis Beaumont49d7bf3c3632
diff --git a/screenpipe-js/ai-proxy/src/index.ts b/screenpipe-js/ai-proxy/src/index.ts
index 90da633f2..9f2a025eb 100644
--- a/screenpipe-js/ai-proxy/src/index.ts
+++ b/screenpipe-js/ai-proxy/src/index.ts
@@ -1,4 +1,4 @@
-import * as Sentry from '@sentry/cloudflare';
+// import * as Sentry from '@sentry/cloudflare';
import { Env, RequestBody, AuthResult } from './types';
import { handleOptions, createSuccessResponse, createErrorResponse, addCorsHeaders } from './utils/cors';
import { validateAuth } from './utils/auth';
@@ -14,24 +14,17 @@ import { handleVertexProxy, handleVertexModels } from './handlers/vertex-proxy';
export { RateLimiter };
-export default Sentry.withSentry(
- (env) => ({
- dsn: 'https://55adeb65aab5b833e7bb21a98bf4735f@o4505591122886656.ingest.us.sentry.io/4510755394224128',
- tracesSampleRate: 0.1,
- sampleRate: 0.1,
- environment: env.NODE_ENV || 'development',
- enabled: (env.NODE_ENV || 'development') === 'production',
- }),
- {
- /**
- * This is the standard fetch handler for a Cloudflare Worker
- * @param request The HTTP request
- * @param env Environment variables
- * @param ctx Execution context
- * @returns HTTP response
- */
- // @ts-ignore
- async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
+// Temporarily disabled Sentry to debug production issues
+export default {
+ async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
+ const url = new URL(request.url);
+ const path = url.pathname;
+
+ // Early test endpoint - before any initialization
+ if (path === '/test') {
+ return new Response('ai proxy is working!', { status: 200 });
+ }
+
const langfuse = setupAnalytics(env);
try {
@@ -39,8 +32,6 @@ export default Sentry.withSentry(
return handleOptions(request);
}
- const url = new URL(request.url);
- const path = url.pathname;
console.log('path', path);
// Handle WebSocket upgrade for real-time transcription (no auth required)
@@ -50,11 +41,6 @@ export default Sentry.withSentry(
return await handleWebSocketUpgrade(request, env);
}
- // Test endpoint - no auth required
- if (path === '/test') {
- return createSuccessResponse('ai proxy is working!');
- }
-
// Authenticate and get tier info for all other endpoints
const authResult = await validateAuth(request, env);
console.log('auth result:', { tier: authResult.tier, deviceId: authResult.deviceId });
@@ -150,9 +136,8 @@ export default Sentry.withSentry(
} finally {
await langfuse.shutdownAsync();
}
- },
- } satisfies ExportedHandler<Env>
-);
+ },
+} satisfies ExportedHandler<Env>;
/*
terminal 1
diff --git a/screenpipe-js/ai-proxy/src/services/analytics.ts b/screenpipe-js/ai-proxy/src/services/analytics.ts
index 0ec4b67ec..dc62400c9 100644
--- a/screenpipe-js/ai-proxy/src/services/analytics.ts
+++ b/screenpipe-js/ai-proxy/src/services/analytics.ts
@@ -4,9 +4,27 @@ import { Env } from '../types';
/**
* Sets up and configures the analytics service
* @param env Environment variables
- * @returns Configured Langfuse instance
+ * @returns Configured Langfuse instance or no-op stub if credentials missing
*/
export function setupAnalytics(env: Env): Langfuse {
+ // Skip Langfuse if credentials are missing or placeholders
+ const placeholders = ['placeholder', 'dummy', ''];
+ if (!env.LANGFUSE_PUBLIC_KEY || !env.LANGFUSE_SECRET_KEY ||
+ placeholders.includes(env.LANGFUSE_PUBLIC_KEY) || placeholders.includes(env.LANGFUSE_SECRET_KEY)) {
+ console.log('Langfuse credentials missing, using stub');
+ // Return a no-op stub that matches the Langfuse interface
+ const stub = {
+ trace: () => ({ span: () => ({ end: () => {} }), generation: () => ({ end: () => {} }) }),
+ span: () => ({ end: () => {} }),
+ generation: () => ({ end: () => {} }),
+ debug: () => {},
+ on: () => {},
+ shutdownAsync: async () => {},
+ flushAsync: async () => {},
+ };
+ return stub as unknown as Langfuse;
+ }
+
const langfuse = new Langfuse({
publicKey: env.LANGFUSE_PUBLIC_KEY,
secretKey: env.LANGFUSE_SECRET_KEY,
@@ -19,4 +37,4 @@ export function setupAnalytics(env: Env): Langfuse {
});
return langfuse;
-}
\ No newline at end of file
+}
diff --git a/screenpipe-js/ai-proxy/wrangler.toml b/screenpipe-js/ai-proxy/wrangler.toml
index bb48e0353..327594b0a 100644
--- a/screenpipe-js/ai-proxy/wrangler.toml
+++ b/screenpipe-js/ai-proxy/wrangler.toml
@@ -2,11 +2,11 @@
name = "ai-proxy"
main = "src/index.ts"
compatibility_date = "2024-10-11"
+workers_dev = true
compatibility_flags = ["nodejs_compat"]
upload_source_maps = true
-# Custom domain - requires screenpi.pe to be on this Cloudflare account
-# After deploying, add DNS record: api.screenpi.pe -> CNAME to this worker
+# Custom domain
routes = [
{ pattern = "api.screenpi.pe/*", zone_name = "screenpi.pe" }
]
@@ -62,7 +62,7 @@ VERTEX_REGION = "us-east5"
[[d1_databases]]
binding = "DB"
database_name = "screenpipe-usage"
-database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
+database_id = "5496f4b2-03c9-496f-b8ca-675961c0622a"
# Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
@@ -136,6 +136,6 @@ bindings = [
]
[[migrations]]
-tag = "v1"
-new_classes = ["RateLimiter"]
+tag = "v2"
+new_sqlite_classes = ["RateLimiter"]