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

paltext-sdk

v1.0.0

Published

A JavaScript/TypeScript SDK for integrating with the PalText Agent API. This SDK allows businesses to easily add AI-powered chat functionality to their applications, with support for user authentication and custom business actions.

Readme

PalText SDK

A JavaScript/TypeScript SDK for integrating with the PalText Agent API. This SDK allows businesses to easily add AI-powered chat functionality to their applications, with support for user authentication and custom business actions.

Installation

npm install paltext-sdk

Or if you're using the SDK directly from the repository:

npm install file:../path/to/sdk-core

Features

  • AI-powered chat functionality
  • User authentication and session management
  • Business-specific actions execution
  • User profile management
  • Human-readable responses
  • Authentication requirement handling
  • Typed responses for TypeScript projects

Usage

Basic Usage

import PalTextSDK from 'paltext-sdk';

// Initialize the SDK with your API key
const sdk = new PalTextSDK('your-api-key');

// Initialize a session
const sessionId = await sdk.initSession('user123');

// Send a message
const response = await sdk.sendMessage('Hello, how can I help you?');

// Parse the response with human-readable format
const parsedResponse = sdk.parseAgentResponse(response.message);
console.log(parsedResponse.humanReadable);

With User Authentication

import PalTextSDK from 'paltext-sdk';

// Initialize the SDK with your API key
const sdk = new PalTextSDK('your-api-key');

// Initialize a session with authentication
const sessionId = await sdk.initSession('user123', 'auth-token-from-your-system');

// Get user profile
const userProfile = await sdk.getUserProfile();
console.log(`Hello, ${userProfile.name}`);

// Send a message (context is managed by the SDK)
const response = await sdk.sendMessage('Update my shipping address');

// Parse the response
const parsedResponse = sdk.parseAgentResponse(response.message);

// If the response contains an action, execute it
if (parsedResponse.action && parsedResponse.action !== 'none') {
  try {
    const actionResult = await sdk.executeAction(
      parsedResponse.action,
      parsedResponse.parameters
    );
    console.log('Action result:', actionResult);
  } catch (error) {
    // Check if the error is due to authentication requirements
    if (error.message.includes('sign up or log in')) {
      console.log('Authentication required for this action');
    } else {
      console.error('Error executing action:', error);
    }
  }
}

Handling Authentication Requirements

The SDK automatically checks if actions require authentication:

// Parse the response
const parsedResponse = sdk.parseAgentResponse(response.message);

// Check if the user is authenticated
if (!sdk.isAuthenticated()) {
  // If the action requires authentication, the humanReadable response will include a message
  if (parsedResponse.humanReadable.includes('need to sign up or log in')) {
    console.log('Please log in to perform this action');
    // Show login UI or redirect to login page
  }
}

Updating User Profile

// Update user profile (requires authentication)
const updatedProfile = await sdk.updateUserProfile({
  name: 'John Doe',
  preferences: {
    theme: 'dark',
    notifications: true
  }
});

API Reference

Constructor

new PalTextSDK(apiKey: string, options?: { baseUrl?: string })
  • apiKey: Your business API key
  • options.baseUrl: Optional custom API URL

Methods

initSession

async initSession(userId: string, authToken?: string): Promise<string>

Initializes a user session and returns a session ID.

setAuthToken

setAuthToken(authToken: string): void

Sets the authentication token for the current user.

isAuthenticated

isAuthenticated(): boolean

Returns true if the user has an authentication token.

getBusinessName

getBusinessName(): string

Returns the business name or "this business" if not available.

sendMessage

async sendMessage(message: string, context?: Partial<UserContext>): Promise<ChatResponse>

Sends a message to the chat agent and returns the response.

getUserProfile

async getUserProfile(): Promise<UserProfile>

Gets the user profile information.

getBusinessActions

getBusinessActions(): BusinessAction[]

Gets the list of available business actions.

executeAction

async executeAction(actionId: string, params: Record<string, any>): Promise<any>

Executes a business action with the given parameters. Throws an error if authentication is required but not provided.

updateUserProfile

async updateUserProfile(updates: Partial<UserProfile>): Promise<UserProfile>

Updates the user profile information. Requires authentication.

parseAgentResponse

parseAgentResponse(message: string): { 
  action: string; 
  text: string; 
  parameters?: Record<string, any>; 
  result?: any;
  humanReadable: string;
}

Parses a JSON response from the agent and adds a human-readable version of the response.

Types

UserContext

interface UserContext {
  userId: string;
  userName?: string;
  sessionId: string;
  authToken?: string;
  metadata?: Record<string, any>;
}

UserProfile

interface UserProfile {
  userId: string;
  name?: string;
  email?: string;
  preferences?: Record<string, any>;
  [key: string]: any;
}

BusinessAction

interface BusinessAction {
  id: string;
  name: string;
  description: string;
  endpoint: string;
  method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
  requiresAuth: boolean;
}

BusinessInfo

interface BusinessInfo {
  id: string;
  name: string;
  description?: string;
  logoUrl?: string;
}

ChatResponse

interface ChatResponse {
  message: string;
  actionResult?: ActionResult;
}

License

MIT