mirror of
https://github.com/moeru-ai/airi.git
synced 2026-07-09 15:58:27 +00:00
|
Some checks are pending
CI / Lint (push) Waiting to run
CI / Build Test (stage-tamagotchi) (push) Waiting to run
CI / Build Test (stage-tamagotchi-godot) (push) Waiting to run
CI / Build Test (stage-web) (push) Waiting to run
CI / Build Test (ui-loading-screens) (push) Waiting to run
CI / Build Test (ui-transitions) (push) Waiting to run
CI / Unit Test (push) Waiting to run
CI / Type Check (push) Waiting to run
CI / Check Provenance (push) Waiting to run
Cloudflare Pages (Auth UI) / Deploy - ui-server-auth (push) Waiting to run
Cloudflare Workers / Deploy - stage-web (push) Waiting to run
Update Nix pnpmDeps Hash / update (push) Waiting to run
|
||
|---|---|---|
| .. | ||
| src | ||
| test | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| tsdown.config.ts | ||
| vitest.config.ts | ||
@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.connectionStatusexposes the current lifecycle stateclient.isReadytells you whether the client has completed authentication + announceclient.send()returnsfalseinstead of silently dropping messages when the socket is unavailableclient.sendOrThrow()is available when you want strict delivery semanticsclient.onEvent()returns an unsubscribe function