@corva/chat-core

中文文档
0.1.19发布于 2026/11/11UNLICENSEDTypeScriptES Module近 30 天下载 4422

Platform-agnostic core of Corva Team Chat, shared by the web and mobile apps

原始使用文档
文档目录6 节
  1. Rules
  2. Setup
  3. Platform adapter
  4. Development
  5. Trying a local build in an app
  6. Publishing

@corva/chat-core

Platform-agnostic core of Corva Team Chat, shared by corva-web-frontend and corva-react-native-app.

It holds everything that is not UI: the Revolt/Stoat API and socket client, chat stores, and the $$CORVA:: message wire format. Each app renders its own UI on top of it.

Rules

  • No platform globals. The type environment is es2022 only, with no DOM or Node types. The only globals allowed are the timers, console and requestAnimationFrame declared in src/platform.d.ts and src/raf.d.ts. fetch, WebSocket, storage, notifications and app-state events are injected by the host app through adapters.
  • No React. Stores use zustand/vanilla; each app wraps them in its own hooks.
  • No UI dependencies (@corva/ui, MUI, React Native).

Runtime dependencies must also resolve through a main field: the mobile app runs Metro with package exports turned off, which is why uuid stays on v11 (v12+ ship only exports).

Hosts must provide a global crypto.getRandomValues for uuid: browsers have it, and the mobile app installs it with polyfillWebCrypto() from expo-standard-web-crypto in its root layout.

Lint and typecheck enforce these rules.

Setup

Call configureChat(host) once at app start, before touching any store, then ensureChatSession(corvaUser) to sign in:

import { configureChat, ensureChatSession } from '@corva/chat-core';

configureChat({
  apiUrl, // Revolt REST, e.g. https://stoat.corva.ai/api
  wsUrl, // Revolt events, e.g. wss://stoat.corva.ai/ws
  platform, // ChatPlatform, see below
  storage, // KeyValueStorage: localStorage on web
  corvaApi, // { get, post } against corva-api with the Corva JWT
  appState, // { isHidden, isInactive, subscribe, onTerminate? }
  dates, // { startOfTomorrowAt(hour, now) } in the user's timezone
  notifier, // optional { showIncomingMessage, onMessageSent, onLogout }
});

await ensureChatSession(corvaUser);
Host memberWebReact Native
storagelocalStorageMMKV, or a hydrated in-memory map
corvaApiapiCore / jsonApi (get repeats array keys)the app's ApiClient
appStatevisibilityState, hasFocus(), pagehideAppState (background counts hidden)
datesmoment with the user's timezone defaultdate-fns in the device timezone
notifierbrowser notification + sound, notification prompt, faviconpush/local notification, badge

Stores are zustand/vanilla stores (roomStore, messageStore, …). React apps wrap them:

import { useStore } from 'zustand';
import { roomStore } from '@corva/chat-core';

export const useRoomStore = <T>(selector: (state: ReturnType<typeof roomStore.getState>) => T) =>
  useStore(roomStore, selector);

Platform adapter

ChatPlatform (src/platform/types.ts) is the transport part of the host, also taken directly by createRevoltAPI and createRevoltSocket:

MemberWebReact Native
fetch(url, init) => fetch(url, init)same
createWebSocketurl => new WebSocket(url)same
createUploadBodyFormData with the FileFormData with { uri, name, type }
subscribeReconnectHintsonline + visibilitychangeNetInfo + AppState active

typecheck/browserPlatform.ts is a compile-only reference web adapter (platform and app state) that proves the browser APIs fit.

Development

nvm use
yarn install
yarn test        # vitest, node environment
yarn lint        # eslint + prettier
yarn typecheck
yarn build       # tsup → dist/ (ESM + .d.ts)

Trying a local build in an app

yarn build && npx yalc publish      # in this repo
npx yalc add @corva/chat-core       # in the consuming app

Publishing

npm version patch   # or minor / major
npm publish         # prepublishOnly runs lint, typecheck, tests, build and package checks
git push --follow-tags

Canary build for testing a branch in an app:

npm version 0.0.0-$(git rev-parse --short HEAD) --no-git-tag-version
npm publish --tag canary && git checkout package.json

版本与发布记录

@corva/chat-core 共发布 20 个版本,首次发布于 2026/09/24;过去 12 个月发布了 20 个版本。

版本发布日期距今
0.1.19latest2026/11/11今天
0.1.182026/11/101 天前
0.1.172026/11/101 天前
0.1.162026/11/091 天前
0.1.152026/11/091 天前
0.1.142026/10/2912 天前

关于 @corva/chat-core 的常见问题

@corva/chat-core 是什么?

Platform-agnostic core of Corva Team Chat, shared by the web and mobile apps

如何安装 @corva/chat-core?

在项目目录运行 npm install @corva/chat-core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zustand(^4.5.0 || ^5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@corva/chat-core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@corva/chat-core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@corva/chat-core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@corva/chat-core 可以商用吗?

@corva/chat-core 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@corva/chat-core 的下载量有多少?

根据 npm 官方下载统计,@corva/chat-core 在 2026/10/11 – 2026/11/09 这 30 天内被下载 4,422 次,日均约 147 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@corva/chat-core 还在维护吗?

最新版本 0.1.19 发布于 2026/11/11(今天);至今共发布 20 个版本,其中过去 12 个月发布了 20 个;首次发布于 2026/09/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。