npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

liteagent-sdk

v2.0.1

Published

TypeScript SDK for LiteAgent API

Readme

LiteAgent TypeScript SDK

English · 中文

A comprehensive TypeScript SDK for integrating with the LiteAgent API.

Features

  • 🌐 Cross-Platform Support: Works seamlessly in browsers, Node.js, and React Native
  • 🔄 Streaming Support: Real-time chat responses with streaming capabilities
  • 🛠️ Function Calling: Built-in support for agent function calling
  • 🔒 Type Safety: Fully typed API with TypeScript
  • 🧩 Modular Design: Adaptable architecture for different environments

Installation

Install the package using npm:

npm install liteagent-sdk

Or using yarn:

yarn add liteagent-sdk

Usage

Initializing the SDK

import { LiteAgentClient } from 'liteagent-sdk';

const client = new LiteAgentClient({
  apiKey: 'sk-your-api-key',
  baseUrl: 'https://your-liteagent-api-endpoint.com/liteAgent/v1',
  enableDebugLogs: true // Optional
});

Starting a Chat Session

// Initialize a session
const session = await client.initSession();
console.log(`Session created with ID: ${session.getSessionId()}`);

// Send a message with streaming response
await session.chat(
  [{ type: 'text', message: 'What is LiteAgent?' }], 
  true, // enable streaming
  {
    onMessage: (message) => {
      console.log('Full message:', message);
    },
    onChunk: (chunk) => {
      process.stdout.write(chunk.part || ''); // Print streaming text
    },
    onFunctionCall: async (funcCall) => {
      console.log('Function call received:', funcCall);
      
      // Send function call results back
      await session.sendFunctionCallResult(
        funcCall.content.id,
        { status: 'success', data: 'Function result' }
      );
    },
    onComplete: () => {
      console.log('\nStreaming completed');
    },
    onError: (error) => {
      console.error('Error in streaming:', error);
    }
  }
);

Restoring a Previous Session

If you have saved a session ID from a previous conversation, you can restore it to continue chatting:

// Save the session ID for later use
const sessionId = client.getSessionId();
localStorage.setItem('sessionId', sessionId);

// Later, restore the session
const savedSessionId = localStorage.getItem('sessionId');
if (savedSessionId) {
  client.restoreSession(savedSessionId);
  
  // Continue chatting
  await client.chat(
    [{ type: 'text', message: 'Continue our previous conversation' }],
    true
  );
}

Managing Sessions

// Get message history
const history = await client.getHistory();
console.log('Message history:', history);

// Stop a running task
await client.stop();

// Clear the session
await client.clear();

Sending Images

// Send a message with an image
await session.chat([
  { type: 'text', message: 'What's in this image?' },
  { type: 'imageUrl', message: 'https://example.com/image.jpg' }
], true);

// With a base64 image
import { imageToBase64 } from 'liteagent-sdk';

const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const base64Image = await imageToBase64(file);

await session.chat([
  { type: 'text', message: 'Describe this image' },
  { type: 'imageUrl', message: `data:image/jpeg;base64,${base64Image}` }
], true);

Browser Usage

For browser environments, the SDK is available as a UMD bundle:

<script src="https://unpkg.com/liteagent-sdk/dist/index.umd.js"></script>
<script>
  const client = new LiteAgent.LiteAgentClient({
    apiKey: 'sk-your-api-key',
    baseUrl: 'https://your-api-endpoint.com/liteAgent/v1'
  });
  
  // Use the SDK...
</script>

Error Handling

The SDK provides custom error classes for better error handling:

import { 
  LiteAgentError, 
  NetworkError, 
  AuthenticationError,
  ValidationError,
  TimeoutError 
} from 'liteagent-sdk';

try {
  await client.chat([{ type: 'text', message: 'Hello' }], true);
} catch (error) {
  if (error instanceof NetworkError) {
    console.error('Network issue:', error.message);
  } else if (error instanceof AuthenticationError) {
    console.error('Authentication failed:', error.message);
  } else if (error instanceof ValidationError) {
    console.error('Validation error:', error.message);
  } else if (error instanceof TimeoutError) {
    console.error('Request timed out:', error.message);
  } else {
    console.error('Unknown error:', error);
  }
}

License

MIT