openclaw_node/
validation.rs1use napi_derive::napi;
4
5use openclaw_core::types::{AgentId, ChannelId, PeerId, PeerType, SessionKey};
6
7#[napi]
16#[must_use]
17pub fn validate_message(content: String, max_length: Option<u32>) -> String {
18 let max_len = max_length.unwrap_or(100_000) as usize;
19 match openclaw_core::validation::validate_message_content(&content, max_len) {
20 Ok(sanitized) => serde_json::json!({"valid": true, "sanitized": sanitized}).to_string(),
21 Err(e) => serde_json::json!({"valid": false, "error": e.to_string()}).to_string(),
22 }
23}
24
25#[napi]
34#[must_use]
35pub fn validate_path(path: String) -> String {
36 match openclaw_core::validation::validate_path(&path) {
37 Ok(()) => serde_json::json!({"valid": true}).to_string(),
38 Err(e) => serde_json::json!({"valid": false, "error": e.to_string()}).to_string(),
39 }
40}
41
42#[napi]
52#[must_use]
53pub fn build_session_key(
54 agent_id: String,
55 channel: String,
56 account_id: String,
57 peer_type: String,
58 peer_id: String,
59) -> String {
60 let pt = match peer_type.as_str() {
61 "dm" => PeerType::Dm,
62 "group" => PeerType::Group,
63 "channel" => PeerType::Channel,
64 "thread" => PeerType::Thread,
65 _ => PeerType::Dm,
66 };
67
68 SessionKey::build(
69 &AgentId::new(&agent_id),
70 &ChannelId::new(&channel),
71 &account_id,
72 pt,
73 &PeerId::new(&peer_id),
74 )
75 .as_ref()
76 .to_string()
77}