00:00 / 00:00

Rinnegan

Detector SDK

@laplace.live/rinnegan-sdk packages the detector behind LAPLACE Rinnegan as a standalone Apache-2.0-licensed library with zero runtime dependencies. It runs wherever modern JavaScript does: browsers, Bun, Node.js, and Workers (for example inside LAPLACE Chat).

Installation

bun add @laplace.live/rinnegan-sdk
bun add @laplace.live/chat-sdk   # optional peer: types the LaplaceEvents used below

Without @laplace.live/chat-sdk, keep skipLibCheck enabled in TypeScript because the signatures of toChatMessage and extractMessages reference it. Danmaku from other sources can be passed straight to detector.ingest() as a ChatMessage.

Judge Danmaku as They Arrive

Feed danmaku in chronological order to Detector; ingest() returns the sender's current assessment after each message:

import type { LaplaceEvent } from '@laplace.live/chat-sdk'
import { Detector, PATTERN_LABELS, toChatMessage, VERDICT_LABELS } from '@laplace.live/rinnegan-sdk'

const detector = new Detector()

function onEvent(event: LaplaceEvent) {
  if (event.type !== 'message') return
  const message = toChatMessage(event)
  // A string explains why the danmaku was skipped: 'anonymous', 'auto-danmaku', 'mirror', 'empty', or 'mock'
  if (typeof message === 'string') return
  const { assessment, changed } = detector.ingest(message)
  if (changed) {
    const { uname, verdict, score, pattern } = assessment
    console.log(`${uname}: ${VERDICT_LABELS[verdict]} ${score} · ${PATTERN_LABELS[pattern]}`)
  }
}
  • changed is true only when the verdict rose or a flagged user's score climbed by at least 5 points since the previous change, letting UIs update without flicker.
  • One Detector handles any number of rooms at once.
  • Memory and session lifetime: Detector keeps each user's messages for a sliding window (windowMs, 60 minutes by default) up to their latest 300 messages (maxRecordsPerUser), while each flagged user's peak assessment, episodes, and every viewer's 手动融入 tally persist for the whole session. Create a new Detector per stream to release them.
  • By default (manualHistory: true), every text danmaku counted by the 手动融入 tally is also kept in ManualBlend.history and in each flagged user's UserSummary.history from summaries(), tagged as a chant, a +1, or the viewer's own line. Because this grows with every message, pass manualHistory: false for long live sessions.

Rank an Archive

import { Detector, extractMessages } from '@laplace.live/rinnegan-sdk'

// `sheets`: the EventSheet[] inside a decompressed and parsed LAPLACE Chat archive
const { messages, skipped } = extractMessages(sheets, {
  since: Date.parse('2026-11-20T00:00:00+08:00'),
})
const detector = new Detector()
for (const message of messages) detector.ingest(message)

// Users who reached `suspect`, worst first, with their peak and flagged episodes
const flagged = detector.summaries()
// 手动融入: viewers who copy the room by hand; never `spam`, though some reach `suspect`
const copiers = detector.manualBlends()

Reading an Assessment

Each Assessment provides the following core fields (see Detection for signal definitions and thresholds):

  • verdict: spam (独轮车), suspect, or none. Repetition alone never reaches spam; automation proof (proof >= minAutomation) is also required.
  • score: 0 to 100, combining in-window repeats with evidence confidence.
  • pattern: loop, burst, template, blend (trend-following bots such as Chatterbox 自动融入), or flood.
  • evidence: automation signals found, each with a kind, a 0 to 1 weight, a Chinese detail, and an optional names list of other viewers' names quoted in detail so a UI can hide them.
  • clusters: the user's top repeated lines with raw message samples.

The SDK also exports the Chinese label maps used by the CLI: VERDICT_LABELS, PATTERN_LABELS, EVIDENCE_LABELS, SKIP_LABELS, GUARD_LABELS, and USER_TYPE_LABELS.

Text Helpers

The normalization and invisible-character helpers used inside the detector are exported for custom rendering or preprocessing:

  • canonicalize(text): folds dedup-bypass variants of a line into one canonical key.
  • findEvasionChars(text) / stripEvasionChars(text): find or strip invisible characters inserted by automation tools.
  • escapeInvisible(text): renders invisible characters visibly as ⟨U+00AD⟩ and similar tags.
  • invisibleRuns(text): splits a line into plain text and invisible-character runs for custom markup rendering.

DetectorOptions Reference

Pass any subset of DetectorOptions to new Detector(options) to override DEFAULT_DETECTOR_OPTIONS:

Prop

Type

Last updated on November 30, 2026

Tech otakus destroy the world