0.1.0 • Published 10 months ago

@guardian-ai/sdk v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

🛡️ Guardian AI SDK

npm version TypeScript License: MIT PRs Welcome

🤖 Autonomous AI-powered security analysis for your repositories and smart contracts 🔒

🚀 Installation⚡ Quick Start✨ Features📚 Documentation💡 Examples🤝 Contributing

⚡ Quick Start

📦 Installation

# Using npm
npm install @guardian-ai/sdk

# Using yarn
yarn add @guardian-ai/sdk

# Using pnpm
pnpm add @guardian-ai/sdk

🎯 Basic Usage

import { GuardianAI } from '@guardian-ai/sdk';

// Initialize the Guardian AI
const guardian = new GuardianAI({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

// Analyze a repository
const analysis = await guardian.analyzeRepository('https://github.com/user/repo');
console.log(analysis);

⚛️ React Integration

import { useGuardianAI } from '@guardian-ai/sdk';

function SecurityAnalyzer() {
  const guardian = useGuardianAI({
    apiKey: process.env.ANTHROPIC_API_KEY,
  });

  const handleAnalysis = async () => {
    const result = await guardian.analyzeRepository('https://github.com/user/repo');
    console.log(result);
  };

  return <button onClick={handleAnalysis}>Analyze Repository</button>;
}

🌟 Features

  • 🔍 Deep Security Analysis

    • 🎯 Comprehensive repository scanning
    • ⚠️ Vulnerability detection and classification
    • 📦 Dependency security audit
  • 🔐 Smart Contract Security

    • 🤖 Automated vulnerability detection
    • ✅ Best practices validation
    • ⚡ Gas optimization suggestions
  • 💻 Developer Experience

    • 📘 TypeScript support
    • ⚛️ React hooks for easy integration
    • 📚 Comprehensive documentation
    • 🔄 Modern ESM and CommonJS support

📚 Documentation

🛡️ GuardianAI Class

The main class for interacting with the Guardian AI SDK.

⚙️ Constructor Options

interface SecurityAnalysisOptions {
  apiKey: string;        // Your Anthropic API key
  model?: string;        // AI model to use (default: 'claude-3-haiku-20240307')
  maxTokens?: number;    // Maximum tokens for analysis (default: 4096)
}

🔧 Methods

MethodDescriptionParametersReturn Type
analyzeRepositoryPerforms security analysis on a GitHub repositoryrepoUrl: stringPromise<SecurityAnalysisResult>

📝 Types

interface SecurityThreat {
  level: 'high' | 'medium' | 'low';
  description: string;
  impact: string;
  remediation: string;
}

interface SecurityAnalysisResult {
  score: number;              // Overall security score (0-100)
  threats: SecurityThreat[];  // List of identified threats
  recommendations: string[];  // Security recommendations
}

💡 Examples

🔍 Basic Security Analysis

const guardian = new GuardianAI({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

// Analyze a specific repository
const analysis = await guardian.analyzeRepository(
  'https://github.com/example/defi-protocol'
);

// Handle the results
console.log(`Security Score: ${analysis.score}`);
analysis.threats.forEach(threat => {
  console.log(`${threat.level.toUpperCase()}: ${threat.description}`);
});

⚛️ React Component with Loading State

function SecurityScanner() {
  const [loading, setLoading] = useState(false);
  const [results, setResults] = useState(null);
  const guardian = useGuardianAI({
    apiKey: process.env.ANTHROPIC_API_KEY,
  });

  const handleScan = async (repoUrl) => {
    try {
      setLoading(true);
      const analysis = await guardian.analyzeRepository(repoUrl);
      setResults(analysis);
    } catch (error) {
      console.error('Analysis failed:', error);
    } finally {
      setLoading(false);
    }
  };

  return (
    <div>
      {loading ? (
        <div>Analyzing repository...</div>
      ) : results ? (
        <div>
          <h2>Security Score: {results.score}</h2>
          {/* Display other results */}
        </div>
      ) : null}
    </div>
  );
}

🤝 Contributing

We welcome contributions! Please feel free to submit a Pull Request. 🎉

  1. 🍴 Fork the repository
  2. 🌿 Create your feature branch (git checkout -b feature/amazing-feature)
  3. ✍️ Commit your changes (git commit -m 'Add some amazing feature')
  4. 🚀 Push to the branch (git push origin feature/amazing-feature)
  5. 🎯 Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.