- createChatClient: bearer auth, one refresh-and-retry on 401, 422 field errors
- useChat over useState: host bootstrap, open a channel, send
- ChatPage, ChatChannelList, ChatMessageList, ChatComposer
- runtime config chat.apiBase, public.chat.{apiBase,channelsApiBase,botsApiBase,hostApiBase}
161 lines
3.7 KiB
TypeScript
161 lines
3.7 KiB
TypeScript
// The JSON the chat layer reads: the host bootstrap (README, "Host bootstrap
|
|
// contract") and golem15.chat's MessageAPI, reactions and uploads. Ported
|
|
// from a Golem15 chat SPA's api/types.ts; the single group channel became a
|
|
// list of channels.
|
|
|
|
/** The composer limits: attachments per message, their total bytes and link cards per message. */
|
|
export interface ChatLimits {
|
|
max_files: number
|
|
max_bytes: number
|
|
max_embeds: number
|
|
}
|
|
|
|
/** One public channel of the community, with the caller's counts. */
|
|
export interface ChatChannel {
|
|
id: number
|
|
slug: string
|
|
name: string
|
|
/** The channel's backing golem15.chat conversation. */
|
|
conversation_id: number
|
|
/** The caller has not left it. */
|
|
joined: boolean
|
|
unread: number
|
|
mentions: number
|
|
}
|
|
|
|
export interface ChatLastMessage {
|
|
id: number
|
|
sender_id: number
|
|
content: string
|
|
created_at: string
|
|
}
|
|
|
|
/** One DM of the current user. */
|
|
export interface ChatConversationRow {
|
|
id: number
|
|
type: string
|
|
other_user_id: number
|
|
unread: number
|
|
last_message: ChatLastMessage | null
|
|
}
|
|
|
|
export interface ChatNonMember {
|
|
member: false
|
|
}
|
|
|
|
export interface ChatMemberBootstrap {
|
|
member: true
|
|
/** May delete other people's messages in channels. */
|
|
moderator: boolean
|
|
/** The chat context DMs are created in (POST /contexts/{type}/{id}/dm). */
|
|
context: { type: string; id: number }
|
|
channels: ChatChannel[]
|
|
conversations: ChatConversationRow[]
|
|
limits: ChatLimits
|
|
}
|
|
|
|
/** GET {hostApiBase}/chat: a non-member learns only that. */
|
|
export type ChatBootstrap = ChatNonMember | ChatMemberBootstrap
|
|
|
|
/** A community member (GET {hostApiBase}/chat/members); no e-mail address. */
|
|
export interface ChatMember {
|
|
id: number
|
|
name: string
|
|
surname: string
|
|
handle: string
|
|
is_bot: boolean
|
|
}
|
|
|
|
export interface ChatAttachment {
|
|
id: number
|
|
url: string
|
|
filename: string
|
|
size: number
|
|
mime_type: string
|
|
kind: string
|
|
width: number | null
|
|
height: number | null
|
|
}
|
|
|
|
export interface ChatReaction {
|
|
key: string
|
|
count: number
|
|
user_ids: number[]
|
|
}
|
|
|
|
/** The reaction routes' answer: the message's reactions after the change. */
|
|
export interface ChatReactionsAnswer {
|
|
message_id: number
|
|
reactions: ChatReaction[]
|
|
}
|
|
|
|
/** The reply sidecar of a thread root. */
|
|
export interface ChatThreadSummary {
|
|
root_id: number
|
|
reply_count: number
|
|
last_reply_at?: string
|
|
participant_ids: number[]
|
|
}
|
|
|
|
/** golem15.chat MessageAPI. sender_avatar is never rendered. */
|
|
export interface ChatMessage {
|
|
id: number
|
|
conversation_id: number
|
|
sender_id: number
|
|
sender_name: string
|
|
sender_avatar: string | null
|
|
content: string | null
|
|
type: string
|
|
attachments: ChatAttachment[]
|
|
created_at: string
|
|
created_at_human: string
|
|
edited_at: string | null
|
|
deleted_at: string | null
|
|
is_mine: boolean
|
|
root_id: number | null
|
|
thread_summary?: ChatThreadSummary | null
|
|
reactions?: ChatReaction[]
|
|
metadata?: Record<string, unknown>
|
|
}
|
|
|
|
export interface ChatSendBody {
|
|
content: string
|
|
attachment_ids?: number[]
|
|
metadata?: Record<string, unknown>
|
|
}
|
|
|
|
/** POST /attachments: the pending file. */
|
|
export interface ChatUploadAnswer {
|
|
id: number
|
|
filename: string
|
|
size: number
|
|
}
|
|
|
|
/** golem15.chat ConversationJSON (the conversation and DM answers). */
|
|
export interface ChatConversation {
|
|
id: number
|
|
type: string
|
|
name?: string | null
|
|
context_type?: string | null
|
|
context_id?: number | null
|
|
created_at?: string
|
|
}
|
|
|
|
/** PUT /threads/{rootId}/mute. */
|
|
export interface ChatThreadMute {
|
|
root_id: number
|
|
is_muted: boolean
|
|
}
|
|
|
|
/** One slash command of GET {botsApiBase}/commands. */
|
|
export interface ChatCommand {
|
|
trigger: string
|
|
description: string
|
|
}
|
|
|
|
/** POST {botsApiBase}/dispatch: ephemeral answers go to the sender only. */
|
|
export interface ChatDispatchAnswer {
|
|
mode: string
|
|
payload: unknown
|
|
}
|