Skip to content

@lastshotlabs/slingshot-chat

npm install @lastshotlabs/slingshot-chat

Create the chat package using the definePackage authoring path.

Mounts all 10 chat entities — each entity module uses wiring: { mode: 'manual', buildAdapter } so the package factory can capture the resolved adapter into a closure-owned ChatAdapterRefs bag for adapter-dependent middleware, custom-op handlers, and event subscribers.

Cross-package contracts:

  • Requires slingshot-permissions for PermissionsState.
  • Requires slingshot-notifications for NotificationsBuilderFactoryCap.
  • Publishes ChatInteractionsPeerCap for consumers (notably slingshot-interactions).

WebSocket self-wiring: the package self-registers its incoming event handlers onto SlingshotContext.wsEndpoints[mountPath] during setupPost. No caller-side wiring is required.

Background schedulers: during setupPost the package starts two 30-second intervals — one for due reminders, one for scheduled message delivery. Both are cleared in teardown().

Optional integrations (duck-typed):

  • slingshot-push — when present, registers chat push formatters.
  • slingshot-embeds — when present, unfurls URLs in new messages and writes the resolved embeds back via attachEmbeds.

Encryption: when config.encryption.provider === 'aes-gcm', encrypted rooms (rooms with encrypted: true) store messages as ciphertext and decrypt them on read. The room id is bound into the cipher as authenticated data so ciphertext cannot be replayed across rooms.

function createChatPackage(rawConfig: ChatPluginConfig): SlingshotPackageDefinition

Source: packages/slingshot-chat/src/plugin.ts

Source: packages/slingshot-chat/src/public.ts

Plugin state key for slingshot-chat.

Single-sourced constant — no magic string 'slingshot-chat' anywhere in cross-package contracts (cold-start invariant #7).

Source: packages/slingshot-chat/src/state.ts

Read-only adapter surface for chat entities.

Cross-package consumers (SSR loaders, search indexers, application-defined plugins) resolve adapters with:

import { ChatEntities } from '@lastshotlabs/slingshot-chat';
import { requireEntityAdapter } from '@lastshotlabs/slingshot-core';
const rooms = requireEntityAdapter(carrier, ChatEntities.Room);
const room = await rooms.getById('room-123');

The exposed methods are the canonical lookup paths used elsewhere in this package’s HTTP routes; readonly([...]) enforces the slice at runtime.

Mutation paths (create/update/delete) are intentionally excluded — those go through the HTTP routes, server actions, or the entity event bus so the full middleware chain (banCheck, encryption, blockGuard, …) runs.

Source: packages/slingshot-chat/src/public.ts

Source: packages/slingshot-chat/src/public.ts

Source: packages/slingshot-chat/src/public.ts

Thrown when a repository backend operation has not been implemented yet. Replace with actual implementation — do not catch and ignore.

Source: packages/slingshot-chat/src/factories/errors.ts

A user block relationship.

Source: packages/slingshot-chat/src/types.ts

Entity adapter for Block — CRUD + block operations.

Source: packages/slingshot-chat/src/types.ts

AES-GCM encryption config for encrypted rooms.

The key must be a base64-encoded raw AES key (16, 24, or 32 bytes). The room ID is bound into the cipher as authenticated data so ciphertext cannot be replayed across rooms.

Source: packages/slingshot-chat/src/types.ts

Cross-package peer surface used by slingshot-interactions (and other component-aware consumers) to resolve chat-owned message trees and apply component updates returned by interaction dispatchers.

Source: packages/slingshot-chat/src/public.ts

Payload sent to clients on chat.message.deleted.

Source: packages/slingshot-chat/src/types.ts

Narrow mutation seam for application-owned room moderation policy.

Source: packages/slingshot-chat/src/public.ts

Disable message-body encryption.

This is the default when ChatPluginConfig.encryption is omitted.

Source: packages/slingshot-chat/src/types.ts

Permission roles configuration for chat operations.

Each field accepts an array of role strings allowed to perform the operation. If omitted, no role restriction is applied.

Source: packages/slingshot-chat/src/types.ts

Payload for the chat.ping keepalive WS event.

Source: packages/slingshot-chat/src/types.ts

Configuration for createChatPackage().

Source: packages/slingshot-chat/src/types.ts

Payload broadcast on chat.read (server → clients).

Source: packages/slingshot-chat/src/types.ts

Payload for the chat.read incoming WS event (client → server).

Source: packages/slingshot-chat/src/types.ts

Payload for the chat.typing incoming WS event (client → server).

Source: packages/slingshot-chat/src/types.ts

Input for creating a RoomMember.

Source: packages/slingshot-chat/src/types.ts

Input for creating a Message.

Source: packages/slingshot-chat/src/types.ts

Input for creating a Room.

Source: packages/slingshot-chat/src/types.ts

A user’s favorited room.

Source: packages/slingshot-chat/src/types.ts

Entity adapter for FavoriteRoom — CRUD + favorites operations.

Source: packages/slingshot-chat/src/types.ts

A chat message.

Source: packages/slingshot-chat/src/types.ts

Entity adapter for Message — CRUD + message-specific operations.

Source: packages/slingshot-chat/src/types.ts

An emoji reaction on a message.

Source: packages/slingshot-chat/src/types.ts

Entity adapter for MessageReaction — CRUD + reaction operations.

Source: packages/slingshot-chat/src/types.ts

A pinned message in a room.

Source: packages/slingshot-chat/src/types.ts

Entity adapter for Pin — CRUD + pin operations.

Source: packages/slingshot-chat/src/types.ts

Payload for the chat.message.reaction WS event sent to clients.

Forwarded from both chat:message.reaction.added and chat:message.reaction.removed bus events. The added flag distinguishes the two.

Source: packages/slingshot-chat/src/types.ts

A read receipt.

Source: packages/slingshot-chat/src/types.ts

Entity adapter for ReadReceipt — CRUD + receipt operations.

Source: packages/slingshot-chat/src/types.ts

Payload emitted on the chat:read.created bus event when a read receipt is recorded.

Emitted by the chat.read WebSocket handler after upserting a receipt row. The WS forward config picks this up and broadcasts chat.read to room members.

Source: packages/slingshot-chat/src/types.ts

A user reminder.

Source: packages/slingshot-chat/src/types.ts

Entity adapter for Reminder — CRUD + reminder operations.

Source: packages/slingshot-chat/src/types.ts

A room invite link.

Source: packages/slingshot-chat/src/types.ts

Entity adapter for RoomInvite — CRUD + invite operations.

Source: packages/slingshot-chat/src/types.ts

A room membership record.

Source: packages/slingshot-chat/src/types.ts

Entity adapter for RoomMember — CRUD + membership operations.

Source: packages/slingshot-chat/src/types.ts

Input for updating a RoomMember (mutable fields only).

Source: packages/slingshot-chat/src/types.ts

Input for updating a Message (mutable fields only).

Source: packages/slingshot-chat/src/types.ts

Input for updating a Room.

Source: packages/slingshot-chat/src/types.ts

Key bundle stored per user. v1: stub shape. v2: populated by full Signal key upload flow.

Source: packages/slingshot-chat/src/encryption/stub.ts

Input type for RoomMemberAdapter.create(). Structural alias of CreateMemberInput.

Source: packages/slingshot-chat/src/types.ts

JSON-safe encryption config for createChatPackage().

Source: packages/slingshot-chat/src/types.ts

Payload sent to clients on chat.message.updated.

Source: packages/slingshot-chat/src/types.ts

Member role within a room.

Source: packages/slingshot-chat/src/types.ts

Message content type.

Source: packages/slingshot-chat/src/types.ts

Notification preference for a room membership.

Source: packages/slingshot-chat/src/types.ts

Room topology type.

Source: packages/slingshot-chat/src/types.ts