Skip to main content

Crate agentlink_sdk

Crate agentlink_sdk 

Source
Expand description

AgentLink SDK

A pure protocol implementation for AgentLink IM services. This crate provides HTTP and MQTT clients without any Tauri or SQLite dependencies.

§Example (使用邮箱登录)

use agentlink_sdk::{AgentLinkClient, ClientConfig};

async fn example() {
    let config = ClientConfig {
        api_url: "https://api.agentlink.im/api/v1".to_string(),
        mqtt_broker_url: "mqtts://mqtt.agentlink.im:8883".to_string(),
        token: None,
        user_id: None,
    };

    let client = AgentLinkClient::new(config);

    // Login
    let response = client.auth()
        .login_with_email_code("user@example.com", "123456")
        .await
        .unwrap();

    // Connect MQTT
    client.connect_mqtt(&response.token, &response.user.id)
        .await
        .unwrap();
}

§Example (使用 API Key,类似 OpenAI SDK)

use agentlink_sdk::{AgentLinkClient, EVENT_MESSAGE_RECEIVED};

// 方式 1: 从环境变量读取 API Key
// 环境变量: AGENTLINK_API_KEY=your-api-key
let client = AgentLinkClient::from_env().expect("Missing AGENTLINK_API_KEY");

// 方式 2: 直接传入 API Key
let client = AgentLinkClient::from_api_key("your-api-key");

// 连接 MQTT 并启动事件循环
client.connect_and_start().await.expect("Connection failed");

// 注册事件处理器
client.on(EVENT_MESSAGE_RECEIVED, |event| async move {
    println!("收到消息: {:?}", event);
}).await;

Re-exports§

pub use client::AgentLinkClient;
pub use client::ClientConfig;
pub use client::ENV_API_KEY;
pub use client::ENV_API_URL;
pub use client::DEFAULT_API_URL;
pub use client::API_PATH_PREFIX;
pub use error::SdkError;
pub use error::SdkResult;
pub use mqtt::client::MqttClient;
pub use mqtt::client::MqttConnectionState;
pub use mqtt::client::MqttEvent;
pub use services::auth_service::AuthService;
pub use services::conversation_service::ConversationService;
pub use services::friend_service::FriendService;
pub use services::message_service::MessageService;
pub use services::user_service::UserService;
pub use token_manager::TokenManager;
pub use events::*;

Modules§

client
AgentLink SDK Client
error
SDK Error Types
events
Typed Event System
http
HTTP Client Module
mqtt
MQTT Client Module
protocols
Protocol Types
services
Services Module
token_manager
Token Manager

Structs§

Conversation
会话
CreateConversationRequest
创建或获取会话请求
CreateConversationResponse
创建或获取会话响应
FriendRequest
好友请求
FriendRequestsResponse
好友请求列表响应
FriendsListResponse
好友列表响应
Friendship
好友关系
LoginRequest
邮件验证码登录请求
LoginResponse
登录响应
Message
消息
SendCodeRequest
发送验证码请求
SendCodeResponse
发送验证码响应
SendMessageRequest
发送消息请求 Protocol: mrd/services/send-message-spec.md
User
用户信息
UserLoginMethod
用户登录方式

Enums§

ServerEvent
服务端 MQTT 事件

Type Aliases§

AuthResponse
认证响应(兼容旧版本)