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

@connexup/ai-api

v1.1.1

Published

SSE message streaming, REST session/agent/blob/file APIs, unified error handling, logging, and stream status management.

Readme

frontend ai api library

SSE message streaming, REST session/agent/blob/file APIs, unified error handling, logging, and stream status management.

Stream a message

import { AiLib, isSseTextChunkEvent, isSseTurnCompleteEvent } from '@connexup/ai-api';

const aiLib = new AiLib({
  baseUrl: 'https://api.example.com',
  apiKey: 'your-api-key',
  sessionId: 'session-id',
});

const unsubscribe = aiLib.subscribe({
  onMessage: (event) => {
    if (isSseTextChunkEvent(event)) {
      console.log('text chunk:', event.content, event.is_final_chunk);
    }
    if (isSseTurnCompleteEvent(event)) {
      console.log('turn complete:', event.output);
    }
  },
  onError: (error) => {
    console.error(error);
  },
});

aiLib.sendMessage({
  message: '列出项目中的所有文件',
});

unsubscribe();
aiLib.destroy();

Update the token at runtime:

aiLib.setApiKey('new-api-key');
aiLib.sendMessage({ message: 'hello', apiKey: 'one-off-key' }); // optional per-request override

REST API usage

import { SessionApi, APIException } from '@connexup/ai-api';

const sessionApi = new SessionApi({
  baseUrl: 'https://api.example.com',
  apiKey: 'your-api-key',
});

const { sessionId } = await sessionApi.createSession({
  agent_id: 'my-agent-123',
});

sessionApi.setApiKey('new-api-key');

try {
  await sessionApi.approveToolCall(sessionId, {
    call_id: 'call-1',
    decision: 'APPROVE',
  });
} catch (error) {
  if (error instanceof APIException) {
    console.log(error.statusCode, error.errorCode, error.message);
  }
}

const history = await sessionApi.getHistory(sessionId);
await sessionApi.closeSession(sessionId);

Error handling

| Exception | When | |-----------|------| | APIException | HTTP response received with non-success status, invalid JSON body, or SSE onopen failure with a readable response | | NetworkConnectionException | fetch() throws before a response is available (network down, CORS block, etc.) |

Helpers in api-request:

  • apiRequest() — JSON REST helper; throws APIException on HTTP errors
  • assertOkResponse() — validate a Response; throws APIException on failure
  • asAPIException() — normalize unknown errors (duck typing by name + statusCode)
  • createAPIExceptionFromResponse() — build APIException from Response + parsed body

Note: In cross-origin setups, the browser Network tab may show 401 while JavaScript only sees a failed fetch() (CORS). That case remains NetworkConnectionException until CORS is fixed or a same-origin proxy is used.

SessionApi methods

  • createSession
  • getHistory / getStatus
  • approveToolCall / cancelTurn / closeSession
  • loadTools / loadSkills / loadSubAgents
  • generateAgentDraft
  • listChatSessions / getChatSession / renameChatSession
  • batchDeleteChatSessions / deleteChatSession
  • setApiKey

SSE stream connection

  • Method: POST /api/sessions/messages/stream?agent-session-id={sessionId}
  • Body: { "message": "...", "variables": { ... }, "attachments": [ ... ] }
  • Headers: Accept: text/event-stream, Authorization: Bearer {apiKey} (optional)
  • Event type is read from JSON payload type, not from the SSE event: field.

SSE error events (type: "error") may include:

{
  "type": "error",
  "errorCode": "UNAUTHORIZED",
  "message": "invalid api key",
  "detail": "optional detail or JSON string"
}