Skip to content

Commit 40118d7

Browse files
jb55claude
andcommitted
config: make PNS relay URL configurable via DAVE_RELAY env var
Replace the hardcoded ws://relay.jb55.com/ constant with a configurable field that reads from the DAVE_RELAY environment variable at startup, falling back to the same default. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8ad2c98 commit 40118d7

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

crates/notedeck_dave/src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub struct DaveSettings {
8383
pub model: String,
8484
pub endpoint: Option<String>,
8585
pub api_key: Option<String>,
86+
pub pns_relay: Option<String>,
8687
}
8788

8889
impl Default for DaveSettings {
@@ -92,6 +93,7 @@ impl Default for DaveSettings {
9293
model: AiProvider::default().default_model().to_string(),
9394
endpoint: None,
9495
api_key: None,
96+
pns_relay: None,
9597
}
9698
}
9799
}
@@ -104,6 +106,7 @@ impl DaveSettings {
104106
model: provider.default_model().to_string(),
105107
endpoint: provider.default_endpoint().map(|s| s.to_string()),
106108
api_key: None,
109+
pns_relay: None,
107110
}
108111
}
109112

@@ -127,6 +130,7 @@ impl DaveSettings {
127130
.map(|s| s.to_string())
128131
.or_else(|| provider.default_endpoint().map(|s| s.to_string())),
129132
api_key,
133+
pns_relay: config.pns_relay.clone(),
130134
}
131135
}
132136
}
@@ -139,6 +143,7 @@ pub struct ModelConfig {
139143
model: String,
140144
api_key: Option<String>,
141145
pub anthropic_api_key: Option<String>,
146+
pub pns_relay: Option<String>,
142147
}
143148

144149
// short-term trial key for testing
@@ -215,6 +220,7 @@ impl Default for ModelConfig {
215220
model,
216221
api_key,
217222
anthropic_api_key,
223+
pns_relay: std::env::var("DAVE_RELAY").ok(),
218224
}
219225
}
220226
}
@@ -247,6 +253,7 @@ impl ModelConfig {
247253
model: "hhao/qwen2.5-coder-tools:latest".to_string(),
248254
api_key: None,
249255
anthropic_api_key: None,
256+
pns_relay: None,
250257
}
251258
}
252259

@@ -280,6 +287,7 @@ impl ModelConfig {
280287
model: settings.model.clone(),
281288
api_key,
282289
anthropic_api_key,
290+
pns_relay: settings.pns_relay.clone(),
283291
}
284292
}
285293

crates/notedeck_dave/src/lib.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ pub use ui::{
5858
};
5959
pub use vec3::Vec3;
6060

61-
/// Relay URL used for PNS event publishing and subscription.
62-
/// TODO: make this configurable in the UI
63-
const PNS_RELAY_URL: &str = "ws://relay.jb55.com/";
61+
/// Default relay URL used for PNS event publishing and subscription.
62+
const DEFAULT_PNS_RELAY: &str = "ws://relay.jb55.com/";
6463

6564
/// Extract a 32-byte secret key from a keypair.
6665
fn secret_key_bytes(keypair: KeypairUnowned<'_>) -> Option<[u8; 32]> {
@@ -143,6 +142,8 @@ pub struct Dave {
143142
pending_deletions: Vec<DeletedSessionInfo>,
144143
/// Local machine hostname, included in session state events.
145144
hostname: String,
145+
/// PNS relay URL (configurable via DAVE_RELAY env or settings UI).
146+
pns_relay_url: String,
146147
}
147148

148149
use update::PermissionPublish;
@@ -323,6 +324,10 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
323324
}
324325

325326
let settings = DaveSettings::from_model_config(&model_config);
327+
let pns_relay_url = model_config
328+
.pns_relay
329+
.clone()
330+
.unwrap_or_else(|| DEFAULT_PNS_RELAY.to_string());
326331

327332
let directory_picker = DirectoryPicker::new();
328333

@@ -375,6 +380,7 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
375380
pending_perm_responses: Vec::new(),
376381
pending_deletions: Vec::new(),
377382
hostname,
383+
pns_relay_url,
378384
}
379385
}
380386

@@ -386,6 +392,10 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
386392
/// Apply new settings. Note: Provider changes require app restart to take effect.
387393
pub fn apply_settings(&mut self, settings: DaveSettings) {
388394
self.model_config = ModelConfig::from_settings(&settings);
395+
self.pns_relay_url = settings
396+
.pns_relay
397+
.clone()
398+
.unwrap_or_else(|| DEFAULT_PNS_RELAY.to_string());
389399
self.settings = settings;
390400
}
391401

@@ -1950,9 +1960,10 @@ impl notedeck::App for Dave {
19501960
// Process relay events into ndb (needed when dave is the active app).
19511961
// Re-send PNS subscription when the relay (re)connects.
19521962
let pns_sub_id = self.pns_relay_sub.clone();
1963+
let pns_relay = self.pns_relay_url.clone();
19531964
try_process_events_core(ctx, ui.ctx(), |app_ctx, ev| {
19541965
if let enostr::RelayEvent::Opened = (&ev.event).into() {
1955-
if ev.relay == PNS_RELAY_URL {
1966+
if ev.relay == pns_relay {
19561967
if let Some(sub_id) = &pns_sub_id {
19571968
if let Some(sk) =
19581969
app_ctx.accounts.get_selected_account().keypair().secret_key
@@ -1963,7 +1974,7 @@ impl notedeck::App for Dave {
19631974
.authors([pns_keys.keypair.pubkey.bytes()])
19641975
.build();
19651976
let req = enostr::ClientMessage::req(sub_id.clone(), vec![pns_filter]);
1966-
app_ctx.pool.send_to(&req, PNS_RELAY_URL);
1977+
app_ctx.pool.send_to(&req, &pns_relay);
19671978
tracing::info!("re-subscribed for PNS events after relay reconnect");
19681979
}
19691980
}
@@ -2001,8 +2012,8 @@ impl notedeck::App for Dave {
20012012
// Ensure the PNS relay is in the pool
20022013
let egui_ctx = ui.ctx().clone();
20032014
let wakeup = move || egui_ctx.request_repaint();
2004-
if let Err(e) = ctx.pool.add_url(PNS_RELAY_URL.to_string(), wakeup) {
2005-
tracing::warn!("failed to add PNS relay {}: {:?}", PNS_RELAY_URL, e);
2015+
if let Err(e) = ctx.pool.add_url(self.pns_relay_url.clone(), wakeup) {
2016+
tracing::warn!("failed to add PNS relay {}: {:?}", self.pns_relay_url, e);
20062017
}
20072018

20082019
// Remote: subscribe on PNS relay for kind-1080 authored by our PNS pubkey
@@ -2012,9 +2023,9 @@ impl notedeck::App for Dave {
20122023
.build();
20132024
let sub_id = uuid::Uuid::new_v4().to_string();
20142025
let req = enostr::ClientMessage::req(sub_id.clone(), vec![pns_filter]);
2015-
ctx.pool.send_to(&req, PNS_RELAY_URL);
2026+
ctx.pool.send_to(&req, &self.pns_relay_url);
20162027
self.pns_relay_sub = Some(sub_id);
2017-
tracing::info!("subscribed for PNS events on {}", PNS_RELAY_URL);
2028+
tracing::info!("subscribed for PNS events on {}", self.pns_relay_url);
20182029

20192030
// Local: subscribe in ndb for kind-31988 session state events
20202031
let state_filter = nostrdb::Filter::new()
@@ -2210,7 +2221,7 @@ impl notedeck::App for Dave {
22102221
for event in all_events {
22112222
match session_events::wrap_pns(&event.note_json, &pns_keys) {
22122223
Ok(pns_json) => match enostr::ClientMessage::event_json(pns_json) {
2213-
Ok(msg) => ctx.pool.send_to(&msg, PNS_RELAY_URL),
2224+
Ok(msg) => ctx.pool.send_to(&msg, &self.pns_relay_url),
22142225
Err(e) => tracing::warn!("failed to build relay message: {:?}", e),
22152226
},
22162227
Err(e) => tracing::warn!("failed to PNS-wrap event: {}", e),

0 commit comments

Comments
 (0)