airi/packages/server-sdk
2026-05-07 19:36:33 +08:00
..
src style: many typescript v6 pending errors 2026-04-05 02:07:09 +08:00
test style: many typescript v6 pending errors 2026-04-05 02:07:09 +08:00
package.json release: v0.10.2 2026-05-07 19:36:33 +08:00
README.md refactor(server-*): refactor client, better state managment 2026-03-20 21:19:01 +08:00
tsconfig.json style: many typescript v6 pending errors 2026-04-05 02:07:09 +08:00
tsdown.config.ts chore: try to fix inlineOnly for tsdown 2026-02-26 18:20:09 +08:00
vitest.config.ts refactor(server-*): refactor client, better state managment 2026-03-20 21:19:01 +08:00

@proj-airi/server-sdk

The SDK for cliet-side code to connect to the server-side components.

Usage

ni @proj-airi/server-sdk -D # from @antfu/ni, can be installed via `npm i -g @antfu/ni`
pnpm i @proj-airi/server-sdk -D
yarn i @proj-airi/server-sdk -D
npm i @proj-airi/server-sdk -D
import { Client } from '@proj-airi/server-sdk'

const client = new Client({
  name: 'your airi plugin',
  autoConnect: false,
})

await client.connect()

client.onEvent('input:text', async (event) => {
  console.info(event.data.text)
})

connect() now resolves when the client is fully ready for use, not just when the websocket transport has opened. In practice that means:

  • the socket is open
  • authentication succeeded when a token is configured
  • the module has announced itself successfully

Useful runtime helpers:

  • client.connectionStatus exposes the current lifecycle state
  • client.isReady tells you whether the client has completed authentication + announce
  • client.send() returns false instead of silently dropping messages when the socket is unavailable
  • client.sendOrThrow() is available when you want strict delivery semantics
  • client.onEvent() returns an unsubscribe function

License

MIT