1.1.5 • Published 5 months ago

@bytexbyte/nxtlinq-ai-agent-sdk v1.1.5

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

Nxtlinq AI Agent SDK

A powerful SDK for building intelligent conversation applications with Nxtlinq AI Agent.

Features

  • 💬 Real-time chat interface with AI Agent
  • 🎯 Preset messages for quick interactions
  • 🛠️ Tool integration support
  • 🔄 Automatic retry mechanism for failed requests
  • 📱 Responsive and modern UI design
  • 🎨 Customizable styling
  • 🔌 Easy integration with React applications
  • 🔒 Secure authentication and API key management
  • 👛 MetaMask wallet integration
  • 🔐 AIT (AI Token) management
  • 🔑 Permission-based access control

Installation

npm install @bytexbyte/nxtlinq-ai-agent-sdk
# or
yarn add @bytexbyte/nxtlinq-ai-agent-sdk

Quick Start

import { ChatBot } from '@bytexbyte/nxtlinq-ai-agent-sdk';

function App() {
  const handleMessage = (message) => {
    console.log('Received new message:', message);
  };

  const handleToolUse = async (toolUse) => {
    console.log('Tool use:', toolUse);
    return {
      id: Date.now().toString(),
      content: 'Tool execution response',
      role: 'assistant',
      timestamp: new Date().toISOString()
    };
  };

  const presetMessages = [
    { text: 'Hello, how can you help me?' },
    { text: 'I want to add a new member' },
    { text: 'I want to view the analytics page' },
    { text: 'I want to change my name' }
  ];

  return (
    <ChatBot
      serviceId="your-service-id"
      apiKey="your-api-key"
      apiSecret="your-api-secret"
      onMessage={handleMessage}
      onToolUse={handleToolUse}
      presetMessages={presetMessages}
      onVerifyWallet={async (address) => {
        // Implement your wallet verification logic here
        return { token: 'verification-token' };
      }}
    />
  );
}

API Reference

NxtlinqAITSDK

MethodDescription
connectWallet()Connect to MetaMask wallet
verifyWallet(token: string, method: string)Verify wallet ownership
signInWithWallet()Sign in using wallet
generateAndRegisterAIT(permissions: string[])Generate and register a new AIT
getAIT()Get AIT information
getWalletInfo()Get wallet information

NxtlinqAIAgent

MethodDescription
setAIT(ait: AIT, signer?: ethers.Signer)Set AIT for the agent
generateAIT(options: GenerateAITOptions)Generate a new AIT
getAITInfo(serviceId: string, controller: string, signer?: ethers.Signer)Get AIT information
sendMessage(message: string, toolName?: string)Send a message to the agent

API Endpoints

AIT API

  • getAITByServiceIdAndController: Get AIT by service ID and controller
  • createAIT: Create a new AIT

Wallet API

  • verifyWallet: Verify wallet ownership
  • getWallet: Get wallet information

Metadata API

  • createMetadata: Create metadata for AIT

Auth API

  • getNonce: Get nonce for wallet sign-in
  • signIn: Sign in with wallet

Agent API

  • sendMessage: Send message to AI agent

ChatBot Component Props

PropTypeRequiredDescription
serviceIdstringYesYour Nxtlinq service ID
apiKeystringYesYour Nxtlinq API key
apiSecretstringYesYour Nxtlinq API secret
onMessage(message: Message) => voidNoCallback when a new message is received
onError(error: Error) => voidNoCallback when an error occurs
onToolUse(toolUse: ToolUse) => Promise<Message | void>NoCallback for handling tool usage
onVerifyWallet(address: string) => Promise<{ token: string }>YesCallback for wallet verification
presetMessagesPresetMessage[]NoArray of preset messages to display
placeholderstringNoInput placeholder text (default: "Type a message...")
classNamestringNoAdditional CSS class name
maxRetriesnumberNoMaximum number of retry attempts (default: 3)
retryDelaynumberNoDelay between retries in milliseconds (default: 1000)

Types

Message

interface Message {
  id: string;
  content: string;
  role: 'user' | 'assistant';
  timestamp: string;
  button?: boolean;
  error?: string;
}

PresetMessage

interface PresetMessage {
  text: string;
  autoSend?: boolean;
}

ToolUse

interface ToolUse {
  name: string;
  input: Record<string, any>;
}

AIT

interface AIT {
  aitId: string;
  controller: string;
  metadata: AITMetadata;
  metadataHash: string;
  metadataCid: string;
  signature: string;
}

interface AITMetadata {
  model: string;
  permissions: string[];
  issuedBy: string;
  serviceId?: string;
}

interface AITInfo {
  aitId: string;
  controller: string;
  metadata: AITMetadata;
  metadataHash: string;
  metadataCid: string;
  signature: string;
}

interface AITPermission {
  hasPermission: boolean;
  reason?: string;
  permissions?: string[];
}

interface GenerateAITOptions {
  hitAddress: string;
  signer: ethers.Signer;
  permissions: string[];
  serviceId: string;
}

interface WalletInfo {
  id: string;
  address: string;
  verified: boolean;
  method?: string;
}

interface MessageContext {
  aitId?: string;
  walletAddress?: string | null;
}

Features

Wallet Integration

  • MetaMask wallet connection
  • Wallet verification
  • Wallet-based authentication
  • AIT (AI Token) generation and management

Available Permissions

  • Set User Name
  • Navigate To Page
  • Add Member

Authentication Flow

  1. Connect MetaMask wallet
  2. Verify wallet ownership
  3. Sign in with wallet
  4. Generate and register AIT with required permissions
  5. Use AIT for authenticated operations

Error Handling

The SDK includes built-in error handling with:

  • Automatic retry mechanism for failed requests
  • Error callback for custom error handling
  • User-friendly error messages
  • Wallet connection error handling
  • Authentication error handling

Best Practices

  1. Implement proper wallet verification logic
  2. Handle AIT permissions appropriately
  3. Set appropriate timeout values
  4. Implement error retry mechanisms
  5. Use context management to maintain conversation coherence
  6. Handle wallet connection errors gracefully
  7. Implement proper error handling for authentication flow

License

Proprietary - All Rights Reserved

Copyright (c) 2025 ByteXByte. All rights reserved.

This software and associated documentation files (the "Software") are proprietary and confidential. The Software is protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties.

Unauthorized copying, distribution, modification, public display, or public performance of the Software is strictly prohibited. The Software may only be used in accordance with the terms of a valid license agreement with ByteXByte.

For licensing inquiries, please contact: Your Contact Information

1.1.5

5 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago