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: custom provider presets broken in pipe execution (#2258)

Louis Beaumonte8f5f367432e
diff --git a/crates/screenpipe-core/src/agents/mod.rs b/crates/screenpipe-core/src/agents/mod.rs
index b7a7812db..b6e04132c 100644
--- a/crates/screenpipe-core/src/agents/mod.rs
+++ b/crates/screenpipe-core/src/agents/mod.rs
@@ -47,6 +47,8 @@ pub trait AgentExecutor: Send + Sync {
model: &str,
working_dir: &Path,
provider: Option<&str>,
+ provider_url: Option<&str>,
+ provider_api_key: Option<&str>,
pid_tx: Option<tokio::sync::oneshot::Sender<u32>>,
) -> Result<AgentOutput>;
diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rs
index 9cbb478e9..6bd73bf87 100644
--- a/crates/screenpipe-core/src/agents/pi.rs
+++ b/crates/screenpipe-core/src/agents/pi.rs
@@ -238,6 +238,7 @@ impl PiExecutor {
model: &str,
working_dir: &Path,
resolved_provider: &str,
+ provider_api_key: Option<&str>,
pid_tx: Option<tokio::sync::oneshot::Sender<u32>>,
) -> Result<AgentOutput> {
let mut cmd = build_async_command(pi_path);
@@ -250,6 +251,18 @@ impl PiExecutor {
cmd.env("SCREENPIPE_API_KEY", token);
}
+ // Pi resolves apiKey values in models.json as env var names.
+ // Set the actual key so the subprocess can find it.
+ if let Some(key) = provider_api_key {
+ if !key.is_empty() {
+ match resolved_provider {
+ "openai" | "openai-byok" => { cmd.env("OPENAI_API_KEY", key); }
+ "custom" => { cmd.env("CUSTOM_API_KEY", key); }
+ _ => {}
+ }
+ }
+ }
+
cmd.stdout(std::process::Stdio::piped());
cmd.stderr(std::process::Stdio::piped());
@@ -299,6 +312,8 @@ impl AgentExecutor for PiExecutor {
model: &str,
working_dir: &Path,
provider: Option<&str>,
+ provider_url: Option<&str>,
+ provider_api_key: Option<&str>,
pid_tx: Option<tokio::sync::oneshot::Sender<u32>>,
) -> Result<AgentOutput> {
Self::ensure_pi_config(
@@ -306,7 +321,7 @@ impl AgentExecutor for PiExecutor {
&self.api_url,
provider,
Some(model),
- None, // URL resolved from provider name defaults
+ provider_url,
)?;
Self::ensure_screenpipe_skill(working_dir)?;
Self::ensure_web_search_extension(working_dir)?;
@@ -331,6 +346,7 @@ impl AgentExecutor for PiExecutor {
model,
working_dir,
&resolved_provider,
+ provider_api_key,
pid_tx,
)
.await?;
@@ -350,7 +366,7 @@ impl AgentExecutor for PiExecutor {
&self.api_url,
provider,
Some(model),
- None,
+ provider_url,
)?;
return self
.spawn_pi(
@@ -359,6 +375,7 @@ impl AgentExecutor for PiExecutor {
model,
working_dir,
&resolved_provider,
+ provider_api_key,
None,
)
.await;
diff --git a/crates/screenpipe-core/src/pipes/mod.rs b/crates/screenpipe-core/src/pipes/mod.rs
index 8a776bbaa..1b1845042 100644
--- a/crates/screenpipe-core/src/pipes/mod.rs
+++ b/crates/screenpipe-core/src/pipes/mod.rs
@@ -198,6 +198,8 @@ struct ResolvedPreset {
provider: Option<String>,
/// Provider base URL (e.g. `http://localhost:11434/v1` for Ollama).
url: Option<String>,
+ /// API key for the provider (custom / openai BYOK).
+ api_key: Option<String>,
}
/// Read `~/.screenpipe/store.bin` and find the preset by id.
@@ -254,7 +256,7 @@ fn resolve_preset(pipes_dir: &Path, preset_id: &str) -> Option<ResolvedPreset> {
"pi" => Some("screenpipe"),
"native-ollama" => Some("ollama"),
"openai" => Some("openai"),
- "custom" => Some("openai"), // custom uses openai-compatible API
+ "custom" => Some("custom"), // custom uses openai-compatible API at a user-specified URL
_ => None,
})
.map(|s| s.to_string());
@@ -265,10 +267,17 @@ fn resolve_preset(pipes_dir: &Path, preset_id: &str) -> Option<ResolvedPreset> {
.filter(|s| !s.is_empty())
.map(|s| s.to_string());
+ let api_key = preset
+ .get("apiKey")
+ .and_then(|v| v.as_str())
+ .filter(|s| !s.is_empty())
+ .map(|s| s.to_string());
+
Some(ResolvedPreset {
model,
provider,
url,
+ api_key,
})
}
@@ -629,15 +638,15 @@ impl PipeManager {
}
// Resolve preset
- let (run_model, run_provider, run_provider_url) = if let Some(ref preset_id) = config.preset
- {
- match resolve_preset(&self.pipes_dir, preset_id) {
- Some(resolved) => (resolved.model, resolved.provider, resolved.url),
- None => (config.model.clone(), config.provider.clone(), None),
- }
- } else {
- (config.model.clone(), config.provider.clone(), None)
- };
+ let (run_model, run_provider, run_provider_url, run_api_key) =
+ if let Some(ref preset_id) = config.preset {
+ match resolve_preset(&self.pipes_dir, preset_id) {
+ Some(resolved) => (resolved.model, resolved.provider, resolved.url, resolved.api_key),
+ None => (config.model.clone(), config.provider.clone(), None, None),
+ }
+ } else {
+ (config.model.clone(), config.provider.clone(), None, None)
+ };
// Create DB execution row
let exec_id = if let Some(ref store) = self.store {
@@ -727,6 +736,8 @@ impl PipeManager {
&run_model,
&pipe_dir,
run_provider.as_deref(),
+ run_provider_url.as_deref(),
+ run_api_key.as_deref(),
Some(pid_tx),
),
)
@@ -914,7 +925,7 @@ impl PipeManager {
let pipe_dir = self.pipes_dir.join(name);
// Resolve preset → model/provider overrides
- let (run_model, run_provider, run_provider_url) = if let Some(ref preset_id) = config.preset
+ let (run_model, run_provider, run_provider_url, run_api_key) = if let Some(ref preset_id) = config.preset
{
match resolve_preset(&self.pipes_dir, preset_id) {
Some(resolved) => {
@@ -922,16 +933,16 @@ impl PipeManager {
"pipe '{}': using preset '{}' → model={}, provider={:?}",
name, preset_id, resolved.model, resolved.provider
);
- (resolved.model, resolved.provider, resolved.url)
+ (resolved.model, resolved.provider, resolved.url, resolved.api_key)
}
None => {
warn!("pipe '{}': preset '{}' not found in store.bin, falling back to pipe config",
name, preset_id);
- (config.model.clone(), config.provider.clone(), None)
+ (config.model.clone(), config.provider.clone(), None, None)
}
}
} else {
- (config.model.clone(), config.provider.clone(), None)
+ (config.model.clone(), config.provider.clone(), None, None)
};
// Create DB execution row
@@ -1013,6 +1024,8 @@ impl PipeManager {
&run_model,
&pipe_dir,
run_provider.as_deref(),
+ run_provider_url.as_deref(),
+ run_api_key.as_deref(),
Some(pid_tx),
),
)
@@ -1504,18 +1517,18 @@ impl PipeManager {
}
// Resolve preset → model/provider overrides (same as run_pipe)
- let (model, provider, provider_url) = if let Some(ref preset_id) = config.preset
+ let (model, provider, provider_url, api_key) = if let Some(ref preset_id) = config.preset
{
match resolve_preset(&pipes_dir, preset_id) {
Some(resolved) => {
info!("scheduler: pipe '{}' using preset '{}' → model={}, provider={:?}",
name, preset_id, resolved.model, resolved.provider);
- (resolved.model, resolved.provider, resolved.url)
+ (resolved.model, resolved.provider, resolved.url, resolved.api_key)
}
- None => (config.model.clone(), config.provider.clone(), None),
+ None => (config.model.clone(), config.provider.clone(), None, None),
}
} else {
- (config.model.clone(), config.provider.clone(), None)
+ (config.model.clone(), config.provider.clone(), None, None)
};
// Pre-configure pi with the pipe's provider
@@ -1608,6 +1621,8 @@ impl PipeManager {
&model,
&pipe_dir,
provider.as_deref(),
+ provider_url.as_deref(),
+ api_key.as_deref(),
Some(pid_tx),
),
)