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

@siena-ai/live-chat-sdk

v0.4.0

Published

Siena Live Chat SDK — framework-agnostic core, platform clients, and an optional drop-in <SienaChat/> UI

Readme

@siena-ai/live-chat-sdk

Siena Live Chat for your own website or app. One package, five entry points:

| Import | What it is | Needs | | --- | --- | --- | | @siena-ai/live-chat-sdk | Framework-agnostic core: LiveChatClient, types, ports | nothing | | @siena-ai/live-chat-sdk/web | createBrowserClient, createBrowserClientFromCdn, loadSienaSdk | a browser | | @siena-ai/live-chat-sdk/react | useLiveChat(client) hook | react >= 18 | | @siena-ai/live-chat-sdk/native | createReactNativeClient (+ useLiveChat) | react-native | | @siena-ai/live-chat-sdk/ui | Drop-in <SienaChat/> and <SienaLauncher/> (React Native / react-native-web) | react-native, react-native-svg, react-native-markdown-display |

You need one value: your Live Chat app key (Siena dashboard, Live Chat settings). The API defaults to production (https://api.siena.cx). Realtime credentials are Siena's and are resolved for you.

Install

npm install @siena-ai/live-chat-sdk

pusher-js (realtime) is installed with it. React, React Native, react-native-svg and react-native-markdown-display are optional peers: install only what your entry point needs.

Web (headless)

import { createBrowserClient } from "@siena-ai/live-chat-sdk/web";

const client = createBrowserClient({ appKey: "YOUR_APP_KEY" });

client.on("message", () => render(client.getState().conversations));
client.on("error", (e) => console.warn(e));

await client.start({ hostname: location.hostname, currentPageUrl: location.href });
await client.sendMessage("Do you ship to Canada?");

Recommended: load the SDK from Siena's CDN

import { createBrowserClientFromCdn } from "@siena-ai/live-chat-sdk/web";

const client = await createBrowserClientFromCdn({ appKey: "YOUR_APP_KEY" });

createBrowserClientFromCdn loads https://chat.siena.cx/dist/sdk/v1/siena-sdk.js, so your site picks up SDK fixes without a redeploy. If the CDN fails or takes longer than 5 seconds it falls back to the copy bundled in this package, so the chat always starts. createBrowserClient (bundled only) stays the default.

Without a bundler, load the script yourself:

<script src="https://chat.siena.cx/dist/sdk/v1/siena-sdk.js"></script>
<script>
  const client = window.SienaLiveChatSDK.createBrowserClient({ appKey: "YOUR_APP_KEY" });
  client.start({ hostname: location.hostname, currentPageUrl: location.href });
</script>

loadSienaSdk({ url?, timeoutMs? }) injects that script and resolves window.SienaLiveChatSDK.

React

import { useEffect, useMemo } from "react";
import { createBrowserClient } from "@siena-ai/live-chat-sdk/web";
import { useLiveChat } from "@siena-ai/live-chat-sdk/react";

export function Chat() {
  const client = useMemo(() => createBrowserClient({ appKey: "YOUR_APP_KEY" }), []);
  useEffect(() => {
    client.start({ hostname: location.hostname, currentPageUrl: location.href });
    return () => client.stop();
  }, [client]);

  const chat = useLiveChat(client);
  return (
    <>
      {chat.messages.map((m) => <p key={m.uuid ?? m.client_idempotency_key}>{m.content}</p>)}
      <button onClick={() => chat.sendMessage("Hi")}>Send</button>
    </>
  );
}

useLiveChat returns state (messages, chatMode, widgetData, settingsReady, starters, csatData, isRoutedToTeam, isSessionClosed, connection, lastError, ...) and actions (sendMessage, loadMore, rateMessage, submitCsat, loadStarters, sendEmailFollowup, trackInteraction, setWidgetSettings, setIdentityToken, setCustomer, resetConversation, setCurrentPageUrl). The hook never starts or stops the client; you do.

React Native

npm install @siena-ai/live-chat-sdk @react-native-async-storage/async-storage
npx expo install @react-native-community/netinfo
# only for the drop-in UI (/ui):
npx expo install react-native-svg
npm install react-native-markdown-display punycode@^2 entities@^2

Why each one:

  • @react-native-community/netinfo: required by the React Native build of pusher-js.
  • @react-native-async-storage/async-storage: optional, but without it the conversation and the anonymous identity reset every time the app is killed.
  • punycode@^2 and entities@^2: react-native-markdown-display uses markdown-it@10, which imports the Node punycode module and entities/lib/maps/*.json (removed in entities@3). Hermes has neither, so install them in your app.
  • No crypto.getRandomValues polyfill is needed: the SDK falls back safely.
import { useEffect } from "react";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { createReactNativeClient } from "@siena-ai/live-chat-sdk/native";
import { SienaChat } from "@siena-ai/live-chat-sdk/ui";

const client = createReactNativeClient({ appKey: "YOUR_APP_KEY", storage: AsyncStorage });

export default function SupportScreen({ navigation }) {
  useEffect(() => {
    client.start({ hostname: "my-app", currentPageUrl: "app://support" });
    return () => client.stop();
  }, []);
  return <SienaChat client={client} variant="mobile" onClose={() => navigation.goBack()} />;
}

Do not wrap <SienaChat/> in a SafeAreaView; it handles its own insets.

Headless or <SienaChat/>?

  • Headless (LiveChatClient + useLiveChat): you render everything. Full control.
  • <SienaChat/> (/ui): a ready chat surface that follows your Siena branding (colors, persona, avatar, starters, CSAT, product cards, email capture). Props: client, appearance (brandColor, logoUrl, heading, placeholder, darkMode, availabilityText, fontFamily), variant ("full" | "panel" | "mobile"), onClose, onExpand, isExpanded, pickAttachments (return FileData[]; no picker is bundled), onAddToCart. <SienaLauncher theme onPress iconUrl? label?/> is a floating open button.
  • WebView / iframe: no SDK at all. Point a WebView or iframe at https://chat.siena.cx/dist/hosted.html?appKey=YOUR_APP_KEY.

Sessions

The client remembers the server session per app key (session uuid, expiry, integration, session token) in local storage (localStorage on web, AsyncStorage on React Native when you pass storage). The next start() resumes the same conversation. The anonymous visitor id is kept the same way.

client.resetConversation() forgets all of it (session, visitor id, customer, identity token, loaded messages) and starts a fresh anonymous chat. Call it when a customer signs out.

Signed-in customers

client.setCustomer({ email, firstName, lastName }) attaches account details to every following message. They are an unverified claim.

To prove who the customer is, sign an identity token on your server and pass it to the SDK. The token is an HS256 JWT with aud = your app key and sub = your customer id, signed with your Live Chat identity secret (Siena dashboard → Live Chat → Installation → Mobile app or custom UI (SDK) → Verified customers). Never ship the secret in an app.

// Node, on your server
import { SignJWT } from "jose";

const secret = new TextEncoder().encode(process.env.SIENA_IDENTITY_SECRET);

export function sienaIdentityToken(user: { id: string; email: string }) {
  return new SignJWT({ email: user.email })
    .setProtectedHeader({ alg: "HS256" })
    .setSubject(user.id)
    .setAudience(process.env.SIENA_APP_KEY!)
    .setIssuedAt()
    .setExpirationTime("1h")
    .sign(secret);
}
await client.start({ hostname, identityToken: await fetchTokenFromYourServer() });
// or later, after sign-in / token refresh:
client.setIdentityToken(newToken);
// on sign-out:
client.setIdentityToken(null);

The token rides on every request as x-siena-identity-token.

Errors

Listen once:

client.on("error", (e) => {
  // e: { message: string; type: "error"; code?: string; status?: number }
});

| code | Status | What the SDK does | What you do | | --- | --- | --- | --- | | sdk_upgrade_required | 426 | Stops the request | Upgrade @siena-ai/live-chat-sdk (or use the CDN loader) | | identity_token_invalid | 401 | Stops the request, no retry | Sign a fresh token, call setIdentityToken | | session_token_invalid | 401 | Drops the cached session token and retries once; this event fires only if the retry also fails | Usually nothing; resetConversation() if it persists | | rate_limited | 429 | For sends: waits Retry-After (max 30s) and retries once; this event fires if that fails too | Slow down |

Errors without code are network or server failures. A failed start() also rejects. sendMessage ignores text that is empty after trimming when no files are attached.

Versioning

Every API request from the SDK carries x-siena-sdk-version (this package's version), x-siena-sdk-platform (web or react-native) and x-siena-sdk-contract (1). File uploads to storage do not. When Siena raises the minimum supported version, older builds get sdk_upgrade_required (426). The CDN build (/sdk/v1/) is updated by Siena within major version 1, so createBrowserClientFromCdn users get fixes without upgrading.

API

LiveChatClient (from createBrowserClient / createBrowserClientFromCdn / createReactNativeClient):

| Member | Description | | --- | --- | | start({ hostname, currentPageUrl?, productData?, customer?, identityToken? }) | Load settings, resume or create the session, connect realtime, load history | | sendMessage(text, { files?, bypassBatching?, preGeneratedQuestionUuid? }?) | Send a message (immediately by default) | | loadMore() | Load older history | | rateMessage(id, rating) | Rate an agent message | | submitCsat(payload) | Submit CSAT feedback | | loadStarters(url, { productId?, variantId? }?) | Fetch conversation starters for a page | | sendEmailFollowup(email) | Lead capture | | trackInteraction(interaction) | Commerce analytics (product click, add to cart) | | uploadAttachment(file) | Upload one file without sending | | setWidgetSettings(partial) | Override merchant settings; merged over the server's | | setCustomer(customer \| null) | Account details on following messages | | setIdentityToken(jwt \| null) | Verified identity on following requests | | setCurrentPageUrl(url) | In-app navigation | | resetConversation() | Forget this device's conversation (sign-out) | | getState() | Current state snapshot | | on(event, handler) | message, session, agentMode, csat, starters, connection, error; returns unsubscribe | | stop() / destroy() | Disconnect (restartable) / tear down for good |

Config (ClientConfig): appKey (required), apiBaseUrl (default https://api.siena.cx), realtime (override only), locale, currency, tunables. React Native adds storage.

Lower-level building blocks (ApiClient, SessionManager, RealtimeCoordinator, MessageService, chatReducer, the port interfaces and the default adapters) are exported for custom platforms: build a Ports object and call new LiveChatClient(config, ports). Set config.platform yourself in that case so the SDK headers are sent.

License

MIT