@hibira-io/chat-ui 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types.d.ts ADDED
@@ -0,0 +1,108 @@
1
+ /** A chat message as your backend returns it (PROTOCOL.md). */
2
+ export interface ChatMessage {
3
+ id?: string;
4
+ /** Position in the conversation, increasing by one per message. */
5
+ seq: number;
6
+ /** Who wrote it: "customer" for the person using the chat, anything else for your side. */
7
+ sender: string;
8
+ name?: string;
9
+ text: string;
10
+ created_at?: string;
11
+ metadata?: AgentMetadata & Record<string, unknown>;
12
+ }
13
+
14
+ /** Marks on an automatic reply. */
15
+ export interface AgentMetadata {
16
+ /** Written by your agent. */
17
+ assistant?: boolean;
18
+ /** The agent passed the conversation to a person. */
19
+ handoff?: boolean;
20
+ /** Follow-up questions the customer can send with one tap. */
21
+ suggestions?: string[];
22
+ }
23
+
24
+ export type AgentStep = 'reading' | 'account' | 'searching' | 'writing' | 'checking' | (string & {});
25
+
26
+ export interface ChatLabels {
27
+ placeholder: string;
28
+ send: string;
29
+ typing: string;
30
+ automatic: string;
31
+ handoff: string;
32
+ suggestions: string;
33
+ copy: string;
34
+ copied: string;
35
+ copyCode: string;
36
+ seen: string;
37
+ empty: string;
38
+ /** {n}: the most characters in one message. */
39
+ tooLong: string;
40
+ steps: Record<string, string>;
41
+ }
42
+
43
+ export type LabelOverrides = Partial<Omit<ChatLabels, 'steps'>> & { steps?: Record<string, string> };
44
+
45
+ export interface MarkdownOptions {
46
+ /** The page's origin, for same-site links and images (defaults to location.origin in a browser). */
47
+ origin?: string;
48
+ /** Other origins whose images show inline ("*" for any). Others become links. */
49
+ imageOrigins?: string[];
50
+ }
51
+
52
+ export type InlineNode =
53
+ | string
54
+ | { type: 'br' }
55
+ | { type: 'code'; text: string }
56
+ | { type: 'strong' | 'em' | 'del' | 'span'; children: InlineNode[] }
57
+ | { type: 'link'; href: string; children: InlineNode[] }
58
+ | { type: 'image'; src: string; alt: string }
59
+ | { type: 'imagelink'; href: string; alt: string };
60
+
61
+ export type Block =
62
+ | { type: 'p' | 'heading'; children: InlineNode[] }
63
+ | { type: 'code'; lang: string; text: string }
64
+ | { type: 'quote'; children: Block[] }
65
+ | { type: 'list'; ordered: boolean; start: number; items: Block[][] }
66
+ | { type: 'table'; align: ('left' | 'center' | 'right' | null)[]; head: InlineNode[][]; rows: InlineNode[][][] }
67
+ | { type: 'hr' };
68
+
69
+ export interface ConversationState {
70
+ messages: ChatMessage[];
71
+ loading: boolean;
72
+ error: unknown;
73
+ /** The other side is writing. */
74
+ typing: boolean;
75
+ /** What the agent is doing while it writes. */
76
+ step?: AgentStep;
77
+ /** Anything else load() returned besides messages. */
78
+ extra: Record<string, unknown>;
79
+ }
80
+
81
+ export interface ConversationOptions {
82
+ /** Reads the messages after seq `after` from your backend. */
83
+ load: (after: number, signal: AbortSignal) => Promise<{ messages: ChatMessage[] } & Record<string, unknown>>;
84
+ /** Sends the customer's message; return the stored message (or { message }). */
85
+ send?: (text: string) => Promise<ChatMessage | { message: ChatMessage } | unknown>;
86
+ /** A pusher-js instance pointed at your Hibira app. Without one it polls. */
87
+ pusher?: unknown;
88
+ /** The conversation's channel, e.g. "private-chat.c_123". */
89
+ channel?: string;
90
+ /** The sender value of the person using this page (default "customer"). */
91
+ me?: string;
92
+ pollMs?: number;
93
+ livePollMs?: number;
94
+ /** Hints other than message and typing. */
95
+ onEvent?: (event: string, data: Record<string, unknown>) => void;
96
+ }
97
+
98
+ export interface Conversation {
99
+ get(): ConversationState;
100
+ subscribe(fn: (state: ConversationState) => void): () => void;
101
+ /** Subscribes and starts reading; returns stop. */
102
+ start(): () => void;
103
+ stop(): void;
104
+ refresh(): Promise<void>;
105
+ added(message: ChatMessage): void;
106
+ send(text: string): Promise<unknown>;
107
+ hint(event: string, data?: Record<string, unknown>): void;
108
+ }