Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Feb 2, 2025
1 parent 5b40fc6 commit f0a3f2f
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 43 deletions.
17 changes: 9 additions & 8 deletions screenpipe-actions/ai-proxy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ async function handleWebSocketUpgrade(request: Request, env: Env): Promise<Respo
const deepgram = createClient(env.DEEPGRAM_API_KEY);
const deepgramSocket = deepgram.listen.live({}, url.toString());

deepgramSocket.on(LiveTranscriptionEvents.Open, (data) => {
deepgramSocket.on(LiveTranscriptionEvents.Open, () => {
server.send(
JSON.stringify({
type: 'message',
data: JSON.stringify(data),
type: 'connected',
message: 'WebSocket connection established',
})
);
});
Expand Down Expand Up @@ -323,6 +323,12 @@ export default Sentry.withSentry(
const url = new URL(request.url);
const path = url.pathname;

const upgradeHeader = request.headers.get('upgrade')?.toLowerCase();
if (path === '/v1/listen' && upgradeHeader === 'websocket') {
console.log('websocket request to /v1/listen detected, bypassing auth');
return await handleWebSocketUpgrade(request, env);
}

// Add auth check for protected routes
if (path !== '/test') {
const authHeader = request.headers.get('Authorization');
Expand Down Expand Up @@ -484,11 +490,6 @@ export default Sentry.withSentry(
}
}

if (path === '/v1/listen' && request.headers.get('Upgrade') === 'websocket') {
console.log('websocket request');
return await handleWebSocketUpgrade(request, env);
}

const response = new Response('not found', {
status: 404,
headers: {
Expand Down
2 changes: 2 additions & 0 deletions screenpipe-actions/ai-proxy/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ compatibility_date = "2024-10-11"
compatibility_flags = ["nodejs_compat"]
upload_source_maps = true

tail_consumers = [{service = "ai-proxy-tail"}]

# Workers Logs
# Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
# Configuration: https://developers.cloudflare.com/workers/observability/logs/workers-logs/#enable-workers-logs
Expand Down
24 changes: 11 additions & 13 deletions screenpipe-app-tauri/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions screenpipe-app-tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use tauri::{
};
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_autostart::ManagerExt;
use tauri_plugin_deep_link::DeepLinkExt;
use tauri_plugin_global_shortcut::ShortcutState;
use tauri_plugin_notification::NotificationExt;
#[allow(unused_imports)]
Expand Down Expand Up @@ -358,24 +357,10 @@ async fn get_pipe_port(pipe_id: &str) -> anyhow::Result<u16> {
.ok_or_else(|| anyhow::anyhow!("no port found for pipe {}", pipe_id))
}

async fn list_pipes() -> anyhow::Result<Value> {
let client = reqwest::Client::new();
let response = client
.get("http://localhost:3030/pipes/list")
.send()
.await?
.json::<Value>()
.await?;

Ok(response)
}


pub fn get_base_dir(
app: &tauri::AppHandle,
custom_path: Option<String>,
) -> anyhow::Result<PathBuf> {

let default_path = app.path().local_data_dir().unwrap().join("screenpipe");

let local_data_dir = custom_path.map(PathBuf::from).unwrap_or(default_path);
Expand Down
2 changes: 1 addition & 1 deletion screenpipe-app-tauri/src-tauri/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{get_base_dir, get_store, icons::AppIcon};
use crate::{get_base_dir, get_store};
use axum::body::Bytes;
use axum::response::sse::{Event, Sse};
use axum::response::IntoResponse;
Expand Down
19 changes: 13 additions & 6 deletions screenpipe-app-tauri/src-tauri/src/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ impl User {
.get("user.credits.created_at")
.and_then(|v| v.as_str().map(String::from)),
}),
cloud_subscribed: store
.get("user.cloud_subscribed")
.and_then(|v| v.as_bool()),
cloud_subscribed: store.get("user.cloud_subscribed").and_then(|v| v.as_bool()),
}
}
}
Expand Down Expand Up @@ -303,7 +301,7 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {
}
}

if deepgram_api_key != "default" {
if deepgram_api_key != "default" && deepgram_api_key != "" {
args.push("--deepgram-api-key");
let key = deepgram_api_key.as_str();
args.push(key);
Expand Down Expand Up @@ -396,14 +394,15 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {

// args.push("--debug");


if cfg!(windows) {
let mut c = app.shell().sidecar("screenpipe").unwrap();
if use_chinese_mirror {
c = c.env("HF_ENDPOINT", "https://hf-mirror.com");
}

// if a user with credits is provided, add the AI proxy env var api url for deepgram as env var https://ai-proxy.i-f9f.workers.dev/v1/listen
if user.cloud_subscribed.is_some() {
if user.cloud_subscribed.is_some() && (deepgram_api_key == "default" || deepgram_api_key == "") {
c = c.env(
"DEEPGRAM_API_URL",
"https://ai-proxy.i-f9f.workers.dev/v1/listen",
Expand All @@ -412,6 +411,8 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {
// Add token if screenpipe-cloud is selected and user has a token
if user.id.is_some() {
c = c.env("CUSTOM_DEEPGRAM_API_TOKEN", user.id.as_ref().unwrap());
args.push("--deepgram-api-key");
args.push(user.id.as_ref().unwrap());
}
}

Expand All @@ -436,7 +437,11 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {
}

// if a user with credits is provided, add the AI proxy env var api url for deepgram as env var https://ai-proxy.i-f9f.workers.dev/v1/listen
if user.cloud_subscribed.is_some() {
if user.cloud_subscribed.is_some() && (deepgram_api_key == "default" || deepgram_api_key == "") {
info!(
"Adding AI proxy env vars for deepgram: {:?}",
user.id.as_ref().unwrap()
);
c = c.env(
"DEEPGRAM_API_URL",
"https://ai-proxy.i-f9f.workers.dev/v1/listen",
Expand All @@ -445,6 +450,8 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {
// Add token if screenpipe-cloud is selected and user has a token
if user.id.is_some() {
c = c.env("CUSTOM_DEEPGRAM_API_TOKEN", user.id.as_ref().unwrap());
args.push("--deepgram-api-key");
args.push(user.id.as_ref().unwrap());
}
}

Expand Down
Binary file modified screenpipe-app-tauri/src-tauri/ui_monitor-aarch64-apple-darwin
Binary file not shown.
6 changes: 6 additions & 0 deletions screenpipe-audio/src/deepgram/realtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::sync::{atomic::AtomicBool, Arc};
use std::time::Duration;
use tokio::sync::broadcast::Receiver;
use tokio::sync::oneshot;
use tracing::info;

pub async fn stream_transcription_deepgram(
stream: Arc<AudioStream>,
Expand Down Expand Up @@ -67,6 +68,11 @@ pub async fn start_deepgram_stream(
}
});

info!(
"Starting deepgram stream with api key: {:?} and url: {:?}",
api_key, DEEPGRAM_WEBSOCKET_URL.as_str()
);

let deepgram = match DEEPGRAM_WEBSOCKET_URL.as_str().is_empty() {
true => deepgram::Deepgram::new(api_key)?,
false => {
Expand Down

0 comments on commit f0a3f2f

Please sign in to comment.