Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore(swift): add trailing newlines to embedded Swift source files

Steven Enamakel40cfb083e482
diff --git a/crates/openhuman-core/src/channels/controllers/ops/connect/disconnect.rs b/crates/openhuman-core/src/channels/controllers/ops/connect/disconnect.rs
new file mode 100644
index 0000000000..f69625c1a0
--- /dev/null
+++ b/crates/openhuman-core/src/channels/controllers/ops/connect/disconnect.rs
@@ -0,0 +1,115 @@
+//! Disconnecting a channel: removing stored credentials and clearing its
+//! runtime config, optionally along with its memory chunks.
+
+use serde_json::{json, Value};
+
+use crate::config::Config;
+use crate::rpc::RpcOutcome;
+use crate::security::credentials;
+
+use super::super::super::definitions::{find_channel_definition, ChannelAuthMode};
+use super::memory::clear_channel_memory;
+use super::shared::credential_provider;
+
+/// Disconnect a channel by removing stored credentials.
+pub async fn disconnect_channel(
+ config: &Config,
+ channel_id: &str,
+ auth_mode: ChannelAuthMode,
+ clear_memory: bool,
+) -> Result<RpcOutcome<Value>, String> {
+ // Verify channel exists.
+ find_channel_definition(channel_id).ok_or_else(|| format!("unknown channel: {channel_id}"))?;
+
+ let provider_key = credential_provider(channel_id, auth_mode);
+
+ // iMessage has no stored credentials (local-only); skip credential removal.
+ if !(channel_id == "imessage" && auth_mode == ChannelAuthMode::ManagedDm) {
+ credentials::ops::remove_provider_credentials(config, &provider_key, None)
+ .await
+ .map_err(|e| format!("failed to remove credentials: {e}"))?;
+ }
+
+ if channel_id == "telegram" && auth_mode == ChannelAuthMode::BotToken {
+ let mut persisted = config.clone();
+ if persisted.channels_config.telegram.take().is_some() {
+ persisted
+ .save()
+ .await
+ .map_err(|e| format!("failed to clear telegram config.toml: {e}"))?;
+ tracing::info!(
+ target: "openhuman::channels",
+ "[telegram] disconnect_channel: cleared channels_config.telegram"
+ );
+ }
+ } else if channel_id == "discord" && auth_mode == ChannelAuthMode::BotToken {
+ let mut persisted = config.clone();
+ if persisted.channels_config.discord.take().is_some() {
+ persisted
+ .save()
+ .await
+ .map_err(|e| format!("failed to clear discord config.toml: {e}"))?;
+ tracing::info!(
+ target: "openhuman::channels",
+ "[discord] disconnect_channel: cleared channels_config.discord"
+ );
+ }
+ } else if channel_id == "imessage" && auth_mode == ChannelAuthMode::ManagedDm {
+ let mut persisted = config.clone();
+ if persisted.channels_config.imessage.take().is_some() {
+ persisted
+ .save()
+ .await
+ .map_err(|e| format!("failed to clear imessage config.toml: {e}"))?;
+ tracing::info!(
+ target: "openhuman::channels",
+ "[imessage] disconnect_channel: cleared channels_config.imessage"
+ );
+ }
+ } else if channel_id == "yuanbao" && auth_mode == ChannelAuthMode::ApiKey {
+ let mut persisted = config.clone();
+ if persisted.channels_config.yuanbao.take().is_some() {
+ persisted
+ .save()
+ .await
+ .map_err(|e| format!("failed to clear yuanbao config.toml: {e}"))?;
+ tracing::info!(
+ target: "openhuman::channels",
+ "[yuanbao] disconnect_channel: cleared channels_config.yuanbao"
+ );
+ }
+ } else if channel_id == "email" && auth_mode == ChannelAuthMode::ApiKey {
+ let mut persisted = config.clone();
+ if persisted.channels_config.email.take().is_some() {
+ persisted
+ .save()
+ .await
+ .map_err(|e| format!("failed to clear email config.toml: {e}"))?;
+ tracing::info!(
+ target: "openhuman::channels",
+ "[email] disconnect_channel: cleared channels_config.email"
+ );
+ }
+ }
+
+ let memory_chunks_deleted = if clear_memory {
+ clear_channel_memory(config, channel_id)
+ .await
+ .map_err(|e| {
+ format!("channel disconnected, but failed to clear memory chunks: {e:#}")
+ })?
+ } else {
+ 0
+ };
+
+ Ok(RpcOutcome::single_log(
+ json!({
+ "channel": channel_id,
+ "auth_mode": auth_mode,
+ "disconnected": true,
+ "restart_required": true,
+ "memory_chunks_deleted": memory_chunks_deleted,
+ }),
+ format!("removed credentials for {}", provider_key),
+ ))
+}
diff --git a/crates/openhuman-core/src/desktop/accessibility/helper/swift_ax_actions.rs b/crates/openhuman-core/src/desktop/accessibility/helper/swift_ax_actions.rs
index a1d8ddeaf7..eae5e035b4 100644
--- a/crates/openhuman-core/src/desktop/accessibility/helper/swift_ax_actions.rs
+++ b/crates/openhuman-core/src/desktop/accessibility/helper/swift_ax_actions.rs
@@ -144,4 +144,5 @@ func axSetValue(appName: String, label: String, value: String, id: String?) -> [
return ["type": "ax_set_value", "id": id ?? "", "ok": false,
"error": "No text field matching '\(label)' found in '\(appName)'"]
}
+
"##;
diff --git a/crates/openhuman-core/src/desktop/accessibility/helper/swift_focus.rs b/crates/openhuman-core/src/desktop/accessibility/helper/swift_focus.rs
index f09278ed46..1c4506b92f 100644
--- a/crates/openhuman-core/src/desktop/accessibility/helper/swift_focus.rs
+++ b/crates/openhuman-core/src/desktop/accessibility/helper/swift_focus.rs
@@ -218,4 +218,5 @@ func queryFocusedElement(id: String?) -> [String: Any] {
return result
}
+
"##;
diff --git a/crates/openhuman-core/src/desktop/accessibility/helper/swift_paste.rs b/crates/openhuman-core/src/desktop/accessibility/helper/swift_paste.rs
index 0bcf950938..8e3b3a4284 100644
--- a/crates/openhuman-core/src/desktop/accessibility/helper/swift_paste.rs
+++ b/crates/openhuman-core/src/desktop/accessibility/helper/swift_paste.rs
@@ -40,4 +40,5 @@ func pasteText(id: String?, text: String) -> [String: Any] {
return result
}
+
"##;