ecokind-moderation-sdk
v1.1.2
Published
EcoKind - A privacy-first moderation SDK powered by decentralized LLMs on the Internet Computer. Making the internet safer, one message at a time.
Maintainers
Readme
EcoKind Moderation SDK
https://www.npmjs.com/package/ecokind-moderation-sdk
EcoKind is a privacy-first content moderation SDK powered by decentralized LLMs on the Internet Computer. This package enables real-time toxic message detection with built-in AI tools, ensuring safer communication across digital platforms.
⚠️ Note: Only authorized users with a valid project key can access and utilize the SDK's moderation features.
🔑 You can request an authorization key from https://ecokind.xyz.
Features
- Real-time content moderation - Instant analysis of messages as they're sent
- Privacy-preserving AI - Powered by decentralized LLMs on the Internet Computer
- Easy integration - Simple API for existing messaging systems
- Toxicity detection - Advanced harassment detection with severity levels
- Message improvement - AI-powered suggestions for better communication
- Secure authorization - Project key validation required for all features
- Developer-friendly - Full JSDoc and TypeScript support
Installation
npm install ecokind-moderation-sdkQuick Start
const EcoKindClient = require('ecokind-moderation-sdk');
async function main() {
const client = new EcoKindClient();
await client.initialize();
// Set the authorized project key
await client.authorize('myproject', 'myproject-abc123');
const message = 'You are so dumb!';
const level = await client.harassmentLevel(message);
console.log('Harassment Level:', level);
const improved = await client.suggestImprovedMessage(message);
console.log('Suggested Improvement:', improved);
}
main().catch(console.error);API Reference
Constructor
const client = new EcoKindClient(canisterId, options);Parameters:
canisterId(optional): The canister ID. Defaults to your deployed canisteroptions(optional): Configuration optionshost: IC network host (default: 'https://icp0.io')isLocal: Set to true for local development (default: false)
Methods
initialize()
Initializes the connection to the Internet Computer canister.
await client.initialize();authorize(project, key)
Authorizes the SDK usage for a given project. Required before using any core feature.
await client.authorize('myproject', 'myproject-abc123');Returns: Boolean - true if authorization is successful
sendMessage(sender, receiver, content)
Sends a message with automatic harassment detection. Authorization required.
const success = await client.sendMessage('user1', 'user2', 'Hello!');Returns: Boolean - true if message was sent successfully
receiveMessages(userPrincipal)
Retrieves all messages for a specific user. Authorization required.
const messages = await client.receiveMessages('user1');Returns: Array<Message> - Array of message objects
editMessage(address, index, newContent)
Edits a message at the specified index (only by the original sender). Authorization required.
const edited = await client.editMessage('user1', 0, 'Updated message');Returns: Boolean - true if edit was successful
deleteUserMessages(address)
Deletes all messages sent by a specific user. Authorization required.
const deleted = await client.deleteUserMessages('user1');Returns: Boolean - true if deletion was successful
clearMessages()
Clears all messages from the system. Authorization required.
const cleared = await client.clearMessages();Returns: Boolean - true if clearing was successful
harassmentLevel(content)
Analyzes the harassment level of a message. Authorization required.
const level = await client.harassmentLevel('This is a test message');
// Returns: 'Low', 'Moderate', or 'High'Returns: String - Harassment level classification
suggestImprovedMessage(content)
Gets an AI-improved version of a message. Authorization required.
const improved = await client.suggestImprovedMessage('ur dumb');
// Returns: A more polite version of the messageReturns: String - Improved message content
validateKey(project, input)
Validates a project key format.
const isValid = await client.validateKey('myproject', 'myproject-abc123');Returns: Boolean - true if key format is valid
Message Object Structure
{
sender: "user1-address",
receiver: "user2-address",
content: "Hello there!",
timestamp: 1640995200000
}Error Handling
All methods throw errors that should be caught, especially if the user is not authorized.
try {
const success = await client.sendMessage('user1', 'user2', 'Hello!');
} catch (error) {
console.error('Failed to send message:', error);
}Local Development
For local development with a local Internet Computer replica:
const client = new EcoKindClient('your-local-canister-id', {
host: 'http://localhost:8000',
isLocal: true
});Don't forget to use your local project's key for authorization:
await client.authorize('localproject', 'localproject-xyz456');Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support and questions:
- Open an issue on GitHub
- Check the Internet Computer documentation
- Visit the DFINITY community forums
Built with ❤️ on the Internet Computer
