Skip to main content

openclaw_node/
lib.rs

1//! # `OpenClaw` Node.js Bridge
2//!
3//! napi-rs bindings to expose Rust core functionality to Node.js.
4//!
5//! ## Features
6//!
7//! - **Configuration**: Load and validate `OpenClaw` config files
8//! - **Event Store**: Append-only event storage with CRDT projections
9//! - **Providers**: Anthropic Claude and `OpenAI` GPT API clients
10//! - **Auth**: Encrypted credential storage with safe API key handling
11//! - **Tools**: Tool registry for agent tool execution
12//! - **Validation**: Input validation and session key building
13//!
14//! ## Example
15//!
16//! ```javascript
17//! const {
18//!   loadDefaultConfig,
19//!   AnthropicProvider,
20//!   NodeApiKey,
21//!   CredentialStore,
22//!   ToolRegistry,
23//!   NodeEventStore,
24//! } = require('openclaw-node');
25//!
26//! // Load configuration
27//! const config = JSON.parse(loadDefaultConfig());
28//!
29//! // Create provider
30//! const provider = new AnthropicProvider(process.env.ANTHROPIC_API_KEY);
31//!
32//! // Create completion
33//! const response = await provider.complete({
34//!   model: 'claude-3-5-sonnet-20241022',
35//!   messages: [{ role: 'user', content: 'Hello!' }],
36//!   maxTokens: 1024,
37//! });
38//!
39//! console.log(response.content);
40//! ```
41
42#![warn(missing_docs)]
43
44// Error handling
45pub mod error;
46
47// Configuration
48mod config;
49pub use config::{load_config, load_default_config, validate_config};
50
51// Event storage
52mod events;
53pub use events::NodeEventStore;
54
55// Validation
56mod validation;
57pub use validation::{build_session_key, validate_message, validate_path};
58
59// AI Providers
60pub mod providers;
61pub use providers::{
62    AnthropicProvider, JsCompletionRequest, JsCompletionResponse, JsMessage, JsStreamChunk,
63    JsTokenUsage, JsTool, JsToolCall, OpenAIProvider,
64};
65
66// Authentication
67pub mod auth;
68pub use auth::{CredentialStore, NodeApiKey};
69
70// Agents
71pub mod agents;
72pub use agents::{JsToolDefinition, JsToolResult, ToolRegistry};