@aikaara/chat-sdk 0.1.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/dist/cdn/aikaara-chat.iife.js +502 -0
- package/dist/headless-CjIUiswe.cjs +1 -0
- package/dist/headless-DzI-CcOZ.mjs +557 -0
- package/dist/headless.cjs +1 -0
- package/dist/headless.d.ts +243 -0
- package/dist/headless.mjs +11 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +354 -0
- package/dist/index.mjs +52 -0
- package/dist/ui.cjs +502 -0
- package/dist/ui.d.ts +182 -0
- package/dist/ui.mjs +994 -0
- package/package.json +41 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
export declare class ActionCableClient {
|
|
2
|
+
private ws;
|
|
3
|
+
private url;
|
|
4
|
+
private subscriptions;
|
|
5
|
+
private welcomePromise;
|
|
6
|
+
private pendingSubscriptions;
|
|
7
|
+
constructor(url: string);
|
|
8
|
+
connect(): Promise<void>;
|
|
9
|
+
disconnect(): void;
|
|
10
|
+
subscribe(identifier: Record<string, unknown>): ChannelSubscription;
|
|
11
|
+
subscribeAsync(identifier: Record<string, unknown>): Promise<ChannelSubscription>;
|
|
12
|
+
unsubscribe(identifierStr: string): void;
|
|
13
|
+
perform(identifierStr: string, action: string, data?: Record<string, unknown>): void;
|
|
14
|
+
get isConnected(): boolean;
|
|
15
|
+
private send;
|
|
16
|
+
private handleMessage;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export declare interface ActionCableMessage {
|
|
20
|
+
type?: 'welcome' | 'ping' | 'confirm_subscription' | 'reject_subscription' | 'disconnect';
|
|
21
|
+
identifier?: string;
|
|
22
|
+
message?: unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare interface AgentEvent {
|
|
26
|
+
type: AgentEventType;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export declare type AgentEventType = 'status' | 'error' | 'agent_start' | 'agent_end' | 'turn_start' | 'turn_end' | 'message_start' | 'message_update' | 'message_end' | 'tool_execution_start' | 'tool_execution_update' | 'tool_execution_end' | 'auto_retry_start' | 'auto_retry_end' | 'cancelled' | 'message_queued';
|
|
31
|
+
|
|
32
|
+
export declare class AikaaraChatClient extends EventEmitter<ChatEvents> {
|
|
33
|
+
private connection;
|
|
34
|
+
private api;
|
|
35
|
+
private messageStore;
|
|
36
|
+
private conversationManager;
|
|
37
|
+
private subscription;
|
|
38
|
+
private config;
|
|
39
|
+
constructor(config: ChatClientConfig);
|
|
40
|
+
connect(): Promise<void>;
|
|
41
|
+
sendMessage(content: string): Promise<void>;
|
|
42
|
+
sendUserEvent(eventKey: string, value?: object, source?: string): Promise<void>;
|
|
43
|
+
loadHistory(): Promise<Message[]>;
|
|
44
|
+
get messages(): Message[];
|
|
45
|
+
get conversationId(): string | null;
|
|
46
|
+
get isConnected(): boolean;
|
|
47
|
+
disconnect(): Promise<void>;
|
|
48
|
+
private handleBroadcast;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export declare class ApiClient {
|
|
52
|
+
private baseUrl;
|
|
53
|
+
private apiKey?;
|
|
54
|
+
private userToken;
|
|
55
|
+
constructor(baseUrl: string, userToken: string, apiKey?: string);
|
|
56
|
+
createConversation(params: {
|
|
57
|
+
systemPromptId?: number;
|
|
58
|
+
channel?: string;
|
|
59
|
+
title?: string;
|
|
60
|
+
}): Promise<CreateConversationResponse>;
|
|
61
|
+
getMessages(conversationId: string): Promise<Message[]>;
|
|
62
|
+
private mapMessage;
|
|
63
|
+
private request;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export declare class ChannelSubscription {
|
|
67
|
+
readonly identifier: string;
|
|
68
|
+
private callbacks;
|
|
69
|
+
private sendFn;
|
|
70
|
+
constructor(identifier: string, sendFn: (data: Record<string, unknown>) => void);
|
|
71
|
+
onReceived(callback: SubscriptionCallback): this;
|
|
72
|
+
onConnected(callback: () => void): this;
|
|
73
|
+
onDisconnected(callback: () => void): this;
|
|
74
|
+
onRejected(callback: () => void): this;
|
|
75
|
+
perform(action: string, data?: Record<string, unknown>): void;
|
|
76
|
+
/* Excluded from this release type: _notifyReceived */
|
|
77
|
+
/* Excluded from this release type: _notifyConnected */
|
|
78
|
+
/* Excluded from this release type: _notifyDisconnected */
|
|
79
|
+
/* Excluded from this release type: _notifyRejected */
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export declare interface ChatClientConfig extends ConnectionConfig {
|
|
83
|
+
apiKey?: string;
|
|
84
|
+
conversationId?: string;
|
|
85
|
+
systemPromptId?: number;
|
|
86
|
+
channel?: 'widget' | 'api';
|
|
87
|
+
onMessage?: (message: Message) => void;
|
|
88
|
+
onStatusChange?: (status: string) => void;
|
|
89
|
+
onError?: (error: Error) => void;
|
|
90
|
+
onStreamUpdate?: (delta: string, fullContent: string) => void;
|
|
91
|
+
onConnectionStateChange?: (state: ConnectionState) => void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export declare interface ChatEvents {
|
|
95
|
+
'connection:state': ConnectionState;
|
|
96
|
+
'message:received': Message;
|
|
97
|
+
'message:updated': Message;
|
|
98
|
+
'message:sent': Message;
|
|
99
|
+
'stream:start': {
|
|
100
|
+
messageId: string;
|
|
101
|
+
};
|
|
102
|
+
'stream:update': {
|
|
103
|
+
delta: string;
|
|
104
|
+
content: string;
|
|
105
|
+
};
|
|
106
|
+
'stream:end': {
|
|
107
|
+
messageId: string;
|
|
108
|
+
usage?: {
|
|
109
|
+
tokensInput: number;
|
|
110
|
+
tokensOutput: number;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
'typing:start': void;
|
|
114
|
+
'typing:stop': void;
|
|
115
|
+
'error': Error;
|
|
116
|
+
'status': string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export declare interface ConnectionConfig {
|
|
120
|
+
baseUrl: string;
|
|
121
|
+
userToken: string;
|
|
122
|
+
reconnect?: boolean;
|
|
123
|
+
maxReconnectAttempts?: number;
|
|
124
|
+
reconnectInterval?: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export declare class ConnectionManager extends EventEmitter<ChatEvents> {
|
|
128
|
+
private client;
|
|
129
|
+
private config;
|
|
130
|
+
private state;
|
|
131
|
+
private reconnectAttempt;
|
|
132
|
+
private reconnectTimer;
|
|
133
|
+
constructor(config: ConnectionConfig);
|
|
134
|
+
connect(): Promise<void>;
|
|
135
|
+
disconnect(): Promise<void>;
|
|
136
|
+
subscribeToConversation(conversationId: string | number): Promise<ChannelSubscription>;
|
|
137
|
+
sendMessage(conversationId: string | number, content: string): void;
|
|
138
|
+
sendUserEvent(conversationId: string | number, eventKey: string, value?: object, source?: string): void;
|
|
139
|
+
get connectionState(): ConnectionState;
|
|
140
|
+
private setState;
|
|
141
|
+
private scheduleReconnect;
|
|
142
|
+
private clearReconnectTimer;
|
|
143
|
+
private buildWsUrl;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export declare type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
|
|
147
|
+
|
|
148
|
+
export declare class ConversationManager {
|
|
149
|
+
private _conversationId;
|
|
150
|
+
private persist;
|
|
151
|
+
constructor(conversationId?: string, persist?: boolean);
|
|
152
|
+
get conversationId(): string | null;
|
|
153
|
+
set conversationId(id: string | null);
|
|
154
|
+
clear(): void;
|
|
155
|
+
private loadFromStorage;
|
|
156
|
+
private saveToStorage;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
declare interface CreateConversationResponse {
|
|
160
|
+
id: string;
|
|
161
|
+
status: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export declare class EventEmitter<Events extends Record<string, any>> {
|
|
165
|
+
private handlers;
|
|
166
|
+
on<K extends keyof Events & string>(event: K, handler: (data: Events[K]) => void): () => void;
|
|
167
|
+
off<K extends keyof Events & string>(event: K, handler: (data: Events[K]) => void): void;
|
|
168
|
+
emit<K extends keyof Events & string>(event: K, data: Events[K]): void;
|
|
169
|
+
removeAllListeners(): void;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export declare interface Message {
|
|
173
|
+
id: string;
|
|
174
|
+
conversationId: string;
|
|
175
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
176
|
+
content: string;
|
|
177
|
+
toolCalls?: ToolCall[];
|
|
178
|
+
toolCallResults?: ToolCallResult;
|
|
179
|
+
tokensInput?: number;
|
|
180
|
+
tokensOutput?: number;
|
|
181
|
+
metadata?: Record<string, unknown>;
|
|
182
|
+
createdAt: string;
|
|
183
|
+
status?: 'sending' | 'sent' | 'streaming' | 'complete' | 'error';
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export declare class MessageStore {
|
|
187
|
+
private _messages;
|
|
188
|
+
private optimisticCounter;
|
|
189
|
+
get messages(): Message[];
|
|
190
|
+
addOptimistic(role: 'user', content: string, conversationId: string): Message;
|
|
191
|
+
confirmOptimistic(tempId: string): void;
|
|
192
|
+
addStreamingMessage(conversationId: string): Message;
|
|
193
|
+
updateStreaming(content: string): void;
|
|
194
|
+
finalizeStreaming(usage?: {
|
|
195
|
+
tokensInput: number;
|
|
196
|
+
tokensOutput: number;
|
|
197
|
+
}): Message | undefined;
|
|
198
|
+
addMessage(message: Message): void;
|
|
199
|
+
setMessages(messages: Message[]): void;
|
|
200
|
+
clear(): void;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
declare type SubscriptionCallback = (data: unknown) => void;
|
|
204
|
+
|
|
205
|
+
export declare interface ToolCall {
|
|
206
|
+
id: string;
|
|
207
|
+
type: 'function';
|
|
208
|
+
function: {
|
|
209
|
+
name: string;
|
|
210
|
+
arguments: string;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export declare interface ToolCallResult {
|
|
215
|
+
tool_call_id: string;
|
|
216
|
+
content: string;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export declare interface WidgetConfig extends ChatClientConfig {
|
|
220
|
+
position?: 'bottom-right' | 'bottom-left';
|
|
221
|
+
offset?: {
|
|
222
|
+
x: number;
|
|
223
|
+
y: number;
|
|
224
|
+
};
|
|
225
|
+
width?: number;
|
|
226
|
+
height?: number;
|
|
227
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
228
|
+
primaryColor?: string;
|
|
229
|
+
fontFamily?: string;
|
|
230
|
+
borderRadius?: number;
|
|
231
|
+
title?: string;
|
|
232
|
+
subtitle?: string;
|
|
233
|
+
avatarUrl?: string;
|
|
234
|
+
welcomeMessage?: string;
|
|
235
|
+
placeholder?: string;
|
|
236
|
+
showTimestamps?: boolean;
|
|
237
|
+
persistConversation?: boolean;
|
|
238
|
+
showBubble?: boolean;
|
|
239
|
+
bubbleText?: string;
|
|
240
|
+
bubbleIcon?: string;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export { }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { A as n, a as t, b as s, C as i, c as o, d as r, E as C, M as l } from "./headless-DzI-CcOZ.mjs";
|
|
2
|
+
export {
|
|
3
|
+
n as ActionCableClient,
|
|
4
|
+
t as AikaaraChatClient,
|
|
5
|
+
s as ApiClient,
|
|
6
|
+
i as ChannelSubscription,
|
|
7
|
+
o as ConnectionManager,
|
|
8
|
+
r as ConversationManager,
|
|
9
|
+
C as EventEmitter,
|
|
10
|
+
l as MessageStore
|
|
11
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./headless-CjIUiswe.cjs"),a=require("./ui.cjs");function l(t){a.registerComponents();const r=document.createElement("aikaara-chat-widget"),n={baseUrl:"base-url",userToken:"user-token",apiKey:"api-key",title:"title",subtitle:"subtitle",theme:"theme",primaryColor:"primary-color",position:"position",width:"width",height:"height",placeholder:"placeholder",welcomeMessage:"welcome-message",avatarUrl:"avatar-url"};for(const[o,s]of Object.entries(n)){const i=t[o];i!=null&&r.setAttribute(s,String(i))}return r.configure(t),document.body.appendChild(r),r}function u(){const t=document.querySelector("aikaara-chat-widget");t&&t.remove()}exports.ActionCableClient=e.ActionCableClient;exports.AikaaraChatClient=e.AikaaraChatClient;exports.ApiClient=e.ApiClient;exports.ChannelSubscription=e.ChannelSubscription;exports.ConnectionManager=e.ConnectionManager;exports.ConversationManager=e.ConversationManager;exports.EventEmitter=e.EventEmitter;exports.MessageStore=e.MessageStore;exports.AikaaraChatBubble=a.AikaaraChatBubble;exports.AikaaraChatHeader=a.AikaaraChatHeader;exports.AikaaraChatInput=a.AikaaraChatInput;exports.AikaaraChatWidget=a.AikaaraChatWidget;exports.AikaaraErrorBanner=a.AikaaraErrorBanner;exports.AikaaraMessageBubble=a.AikaaraMessageBubble;exports.AikaaraMessageList=a.AikaaraMessageList;exports.AikaaraStreamingMessage=a.AikaaraStreamingMessage;exports.AikaaraTypingIndicator=a.AikaaraTypingIndicator;exports.registerComponents=a.registerComponents;exports.mount=l;exports.unmount=u;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
export declare class ActionCableClient {
|
|
2
|
+
private ws;
|
|
3
|
+
private url;
|
|
4
|
+
private subscriptions;
|
|
5
|
+
private welcomePromise;
|
|
6
|
+
private pendingSubscriptions;
|
|
7
|
+
constructor(url: string);
|
|
8
|
+
connect(): Promise<void>;
|
|
9
|
+
disconnect(): void;
|
|
10
|
+
subscribe(identifier: Record<string, unknown>): ChannelSubscription;
|
|
11
|
+
subscribeAsync(identifier: Record<string, unknown>): Promise<ChannelSubscription>;
|
|
12
|
+
unsubscribe(identifierStr: string): void;
|
|
13
|
+
perform(identifierStr: string, action: string, data?: Record<string, unknown>): void;
|
|
14
|
+
get isConnected(): boolean;
|
|
15
|
+
private send;
|
|
16
|
+
private handleMessage;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export declare interface ActionCableMessage {
|
|
20
|
+
type?: 'welcome' | 'ping' | 'confirm_subscription' | 'reject_subscription' | 'disconnect';
|
|
21
|
+
identifier?: string;
|
|
22
|
+
message?: unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare interface AgentEvent {
|
|
26
|
+
type: AgentEventType;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export declare type AgentEventType = 'status' | 'error' | 'agent_start' | 'agent_end' | 'turn_start' | 'turn_end' | 'message_start' | 'message_update' | 'message_end' | 'tool_execution_start' | 'tool_execution_update' | 'tool_execution_end' | 'auto_retry_start' | 'auto_retry_end' | 'cancelled' | 'message_queued';
|
|
31
|
+
|
|
32
|
+
export declare class AikaaraChatBubble extends HTMLElement {
|
|
33
|
+
private shadow;
|
|
34
|
+
constructor();
|
|
35
|
+
connectedCallback(): void;
|
|
36
|
+
private render;
|
|
37
|
+
setIcon(svgOrText: string): void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export declare class AikaaraChatClient extends EventEmitter<ChatEvents> {
|
|
41
|
+
private connection;
|
|
42
|
+
private api;
|
|
43
|
+
private messageStore;
|
|
44
|
+
private conversationManager;
|
|
45
|
+
private subscription;
|
|
46
|
+
private config;
|
|
47
|
+
constructor(config: ChatClientConfig);
|
|
48
|
+
connect(): Promise<void>;
|
|
49
|
+
sendMessage(content: string): Promise<void>;
|
|
50
|
+
sendUserEvent(eventKey: string, value?: object, source?: string): Promise<void>;
|
|
51
|
+
loadHistory(): Promise<Message[]>;
|
|
52
|
+
get messages(): Message[];
|
|
53
|
+
get conversationId(): string | null;
|
|
54
|
+
get isConnected(): boolean;
|
|
55
|
+
disconnect(): Promise<void>;
|
|
56
|
+
private handleBroadcast;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export declare class AikaaraChatHeader extends HTMLElement {
|
|
60
|
+
private shadow;
|
|
61
|
+
static get observedAttributes(): string[];
|
|
62
|
+
constructor();
|
|
63
|
+
connectedCallback(): void;
|
|
64
|
+
attributeChangedCallback(): void;
|
|
65
|
+
private render;
|
|
66
|
+
setStatus(status: string): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export declare class AikaaraChatInput extends HTMLElement {
|
|
70
|
+
private shadow;
|
|
71
|
+
private textarea;
|
|
72
|
+
private sendBtn;
|
|
73
|
+
private _disabled;
|
|
74
|
+
constructor();
|
|
75
|
+
connectedCallback(): void;
|
|
76
|
+
set disabled(val: boolean);
|
|
77
|
+
get disabled(): boolean;
|
|
78
|
+
focus(): void;
|
|
79
|
+
clear(): void;
|
|
80
|
+
private handleSend;
|
|
81
|
+
private autoGrow;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export declare class AikaaraChatWidget extends HTMLElement {
|
|
85
|
+
private shadow;
|
|
86
|
+
private controller;
|
|
87
|
+
private _config;
|
|
88
|
+
static get observedAttributes(): string[];
|
|
89
|
+
constructor();
|
|
90
|
+
connectedCallback(): void;
|
|
91
|
+
disconnectedCallback(): void;
|
|
92
|
+
attributeChangedCallback(_name: string, oldVal: string, newVal: string): void;
|
|
93
|
+
configure(config: Partial<WidgetConfig>): void;
|
|
94
|
+
private getConfig;
|
|
95
|
+
private render;
|
|
96
|
+
private initController;
|
|
97
|
+
private darkenColor;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export declare class AikaaraErrorBanner extends HTMLElement {
|
|
101
|
+
private shadow;
|
|
102
|
+
private container;
|
|
103
|
+
private dismissTimer;
|
|
104
|
+
constructor();
|
|
105
|
+
connectedCallback(): void;
|
|
106
|
+
show(message: string, autoDismissMs?: number): void;
|
|
107
|
+
hide(): void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export declare class AikaaraMessageBubble extends HTMLElement {
|
|
111
|
+
private shadow;
|
|
112
|
+
static get observedAttributes(): string[];
|
|
113
|
+
constructor();
|
|
114
|
+
connectedCallback(): void;
|
|
115
|
+
attributeChangedCallback(): void;
|
|
116
|
+
private render;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export declare class AikaaraMessageList extends HTMLElement {
|
|
120
|
+
private shadow;
|
|
121
|
+
private container;
|
|
122
|
+
private welcomeMessage;
|
|
123
|
+
private showTimestamps;
|
|
124
|
+
constructor();
|
|
125
|
+
connectedCallback(): void;
|
|
126
|
+
setWelcomeMessage(message: string): void;
|
|
127
|
+
setShowTimestamps(show: boolean): void;
|
|
128
|
+
renderMessages(messages: Message[]): void;
|
|
129
|
+
addMessage(message: Message): void;
|
|
130
|
+
updateStreamingContent(content: string): void;
|
|
131
|
+
finalizeStreaming(): void;
|
|
132
|
+
showTypingIndicator(): void;
|
|
133
|
+
removeTypingIndicator(): void;
|
|
134
|
+
private appendMessageElement;
|
|
135
|
+
private scrollToBottom;
|
|
136
|
+
private formatTime;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export declare class AikaaraStreamingMessage extends HTMLElement {
|
|
140
|
+
private shadow;
|
|
141
|
+
private bubble;
|
|
142
|
+
constructor();
|
|
143
|
+
connectedCallback(): void;
|
|
144
|
+
updateContent(content: string): void;
|
|
145
|
+
finalize(): void;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export declare class AikaaraTypingIndicator extends HTMLElement {
|
|
149
|
+
private shadow;
|
|
150
|
+
constructor();
|
|
151
|
+
connectedCallback(): void;
|
|
152
|
+
show(): void;
|
|
153
|
+
hide(): void;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export declare class ApiClient {
|
|
157
|
+
private baseUrl;
|
|
158
|
+
private apiKey?;
|
|
159
|
+
private userToken;
|
|
160
|
+
constructor(baseUrl: string, userToken: string, apiKey?: string);
|
|
161
|
+
createConversation(params: {
|
|
162
|
+
systemPromptId?: number;
|
|
163
|
+
channel?: string;
|
|
164
|
+
title?: string;
|
|
165
|
+
}): Promise<CreateConversationResponse>;
|
|
166
|
+
getMessages(conversationId: string): Promise<Message[]>;
|
|
167
|
+
private mapMessage;
|
|
168
|
+
private request;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export declare class ChannelSubscription {
|
|
172
|
+
readonly identifier: string;
|
|
173
|
+
private callbacks;
|
|
174
|
+
private sendFn;
|
|
175
|
+
constructor(identifier: string, sendFn: (data: Record<string, unknown>) => void);
|
|
176
|
+
onReceived(callback: SubscriptionCallback): this;
|
|
177
|
+
onConnected(callback: () => void): this;
|
|
178
|
+
onDisconnected(callback: () => void): this;
|
|
179
|
+
onRejected(callback: () => void): this;
|
|
180
|
+
perform(action: string, data?: Record<string, unknown>): void;
|
|
181
|
+
/* Excluded from this release type: _notifyReceived */
|
|
182
|
+
/* Excluded from this release type: _notifyConnected */
|
|
183
|
+
/* Excluded from this release type: _notifyDisconnected */
|
|
184
|
+
/* Excluded from this release type: _notifyRejected */
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export declare interface ChatClientConfig extends ConnectionConfig {
|
|
188
|
+
apiKey?: string;
|
|
189
|
+
conversationId?: string;
|
|
190
|
+
systemPromptId?: number;
|
|
191
|
+
channel?: 'widget' | 'api';
|
|
192
|
+
onMessage?: (message: Message) => void;
|
|
193
|
+
onStatusChange?: (status: string) => void;
|
|
194
|
+
onError?: (error: Error) => void;
|
|
195
|
+
onStreamUpdate?: (delta: string, fullContent: string) => void;
|
|
196
|
+
onConnectionStateChange?: (state: ConnectionState) => void;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export declare interface ChatEvents {
|
|
200
|
+
'connection:state': ConnectionState;
|
|
201
|
+
'message:received': Message;
|
|
202
|
+
'message:updated': Message;
|
|
203
|
+
'message:sent': Message;
|
|
204
|
+
'stream:start': {
|
|
205
|
+
messageId: string;
|
|
206
|
+
};
|
|
207
|
+
'stream:update': {
|
|
208
|
+
delta: string;
|
|
209
|
+
content: string;
|
|
210
|
+
};
|
|
211
|
+
'stream:end': {
|
|
212
|
+
messageId: string;
|
|
213
|
+
usage?: {
|
|
214
|
+
tokensInput: number;
|
|
215
|
+
tokensOutput: number;
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
'typing:start': void;
|
|
219
|
+
'typing:stop': void;
|
|
220
|
+
'error': Error;
|
|
221
|
+
'status': string;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export declare interface ConnectionConfig {
|
|
225
|
+
baseUrl: string;
|
|
226
|
+
userToken: string;
|
|
227
|
+
reconnect?: boolean;
|
|
228
|
+
maxReconnectAttempts?: number;
|
|
229
|
+
reconnectInterval?: number;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export declare class ConnectionManager extends EventEmitter<ChatEvents> {
|
|
233
|
+
private client;
|
|
234
|
+
private config;
|
|
235
|
+
private state;
|
|
236
|
+
private reconnectAttempt;
|
|
237
|
+
private reconnectTimer;
|
|
238
|
+
constructor(config: ConnectionConfig);
|
|
239
|
+
connect(): Promise<void>;
|
|
240
|
+
disconnect(): Promise<void>;
|
|
241
|
+
subscribeToConversation(conversationId: string | number): Promise<ChannelSubscription>;
|
|
242
|
+
sendMessage(conversationId: string | number, content: string): void;
|
|
243
|
+
sendUserEvent(conversationId: string | number, eventKey: string, value?: object, source?: string): void;
|
|
244
|
+
get connectionState(): ConnectionState;
|
|
245
|
+
private setState;
|
|
246
|
+
private scheduleReconnect;
|
|
247
|
+
private clearReconnectTimer;
|
|
248
|
+
private buildWsUrl;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export declare type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
|
|
252
|
+
|
|
253
|
+
export declare class ConversationManager {
|
|
254
|
+
private _conversationId;
|
|
255
|
+
private persist;
|
|
256
|
+
constructor(conversationId?: string, persist?: boolean);
|
|
257
|
+
get conversationId(): string | null;
|
|
258
|
+
set conversationId(id: string | null);
|
|
259
|
+
clear(): void;
|
|
260
|
+
private loadFromStorage;
|
|
261
|
+
private saveToStorage;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
declare interface CreateConversationResponse {
|
|
265
|
+
id: string;
|
|
266
|
+
status: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export declare class EventEmitter<Events extends Record<string, any>> {
|
|
270
|
+
private handlers;
|
|
271
|
+
on<K extends keyof Events & string>(event: K, handler: (data: Events[K]) => void): () => void;
|
|
272
|
+
off<K extends keyof Events & string>(event: K, handler: (data: Events[K]) => void): void;
|
|
273
|
+
emit<K extends keyof Events & string>(event: K, data: Events[K]): void;
|
|
274
|
+
removeAllListeners(): void;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export declare interface Message {
|
|
278
|
+
id: string;
|
|
279
|
+
conversationId: string;
|
|
280
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
281
|
+
content: string;
|
|
282
|
+
toolCalls?: ToolCall[];
|
|
283
|
+
toolCallResults?: ToolCallResult;
|
|
284
|
+
tokensInput?: number;
|
|
285
|
+
tokensOutput?: number;
|
|
286
|
+
metadata?: Record<string, unknown>;
|
|
287
|
+
createdAt: string;
|
|
288
|
+
status?: 'sending' | 'sent' | 'streaming' | 'complete' | 'error';
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export declare class MessageStore {
|
|
292
|
+
private _messages;
|
|
293
|
+
private optimisticCounter;
|
|
294
|
+
get messages(): Message[];
|
|
295
|
+
addOptimistic(role: 'user', content: string, conversationId: string): Message;
|
|
296
|
+
confirmOptimistic(tempId: string): void;
|
|
297
|
+
addStreamingMessage(conversationId: string): Message;
|
|
298
|
+
updateStreaming(content: string): void;
|
|
299
|
+
finalizeStreaming(usage?: {
|
|
300
|
+
tokensInput: number;
|
|
301
|
+
tokensOutput: number;
|
|
302
|
+
}): Message | undefined;
|
|
303
|
+
addMessage(message: Message): void;
|
|
304
|
+
setMessages(messages: Message[]): void;
|
|
305
|
+
clear(): void;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export declare function mount(config: WidgetConfig): AikaaraChatWidget;
|
|
309
|
+
|
|
310
|
+
export declare function registerComponents(): void;
|
|
311
|
+
|
|
312
|
+
declare type SubscriptionCallback = (data: unknown) => void;
|
|
313
|
+
|
|
314
|
+
export declare interface ToolCall {
|
|
315
|
+
id: string;
|
|
316
|
+
type: 'function';
|
|
317
|
+
function: {
|
|
318
|
+
name: string;
|
|
319
|
+
arguments: string;
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export declare interface ToolCallResult {
|
|
324
|
+
tool_call_id: string;
|
|
325
|
+
content: string;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export declare function unmount(): void;
|
|
329
|
+
|
|
330
|
+
export declare interface WidgetConfig extends ChatClientConfig {
|
|
331
|
+
position?: 'bottom-right' | 'bottom-left';
|
|
332
|
+
offset?: {
|
|
333
|
+
x: number;
|
|
334
|
+
y: number;
|
|
335
|
+
};
|
|
336
|
+
width?: number;
|
|
337
|
+
height?: number;
|
|
338
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
339
|
+
primaryColor?: string;
|
|
340
|
+
fontFamily?: string;
|
|
341
|
+
borderRadius?: number;
|
|
342
|
+
title?: string;
|
|
343
|
+
subtitle?: string;
|
|
344
|
+
avatarUrl?: string;
|
|
345
|
+
welcomeMessage?: string;
|
|
346
|
+
placeholder?: string;
|
|
347
|
+
showTimestamps?: boolean;
|
|
348
|
+
persistConversation?: boolean;
|
|
349
|
+
showBubble?: boolean;
|
|
350
|
+
bubbleText?: string;
|
|
351
|
+
bubbleIcon?: string;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export { }
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { A as p, a as d, b as g, C as h, c as k, d as C, E as b, M as A } from "./headless-DzI-CcOZ.mjs";
|
|
2
|
+
import { registerComponents as n } from "./ui.mjs";
|
|
3
|
+
import { AikaaraChatBubble as M, AikaaraChatHeader as w, AikaaraChatInput as y, AikaaraChatWidget as v, AikaaraErrorBanner as E, AikaaraMessageBubble as S, AikaaraMessageList as x, AikaaraStreamingMessage as B, AikaaraTypingIndicator as I } from "./ui.mjs";
|
|
4
|
+
function l(a) {
|
|
5
|
+
n();
|
|
6
|
+
const e = document.createElement("aikaara-chat-widget"), r = {
|
|
7
|
+
baseUrl: "base-url",
|
|
8
|
+
userToken: "user-token",
|
|
9
|
+
apiKey: "api-key",
|
|
10
|
+
title: "title",
|
|
11
|
+
subtitle: "subtitle",
|
|
12
|
+
theme: "theme",
|
|
13
|
+
primaryColor: "primary-color",
|
|
14
|
+
position: "position",
|
|
15
|
+
width: "width",
|
|
16
|
+
height: "height",
|
|
17
|
+
placeholder: "placeholder",
|
|
18
|
+
welcomeMessage: "welcome-message",
|
|
19
|
+
avatarUrl: "avatar-url"
|
|
20
|
+
};
|
|
21
|
+
for (const [i, o] of Object.entries(r)) {
|
|
22
|
+
const t = a[i];
|
|
23
|
+
t != null && e.setAttribute(o, String(t));
|
|
24
|
+
}
|
|
25
|
+
return e.configure(a), document.body.appendChild(e), e;
|
|
26
|
+
}
|
|
27
|
+
function c() {
|
|
28
|
+
const a = document.querySelector("aikaara-chat-widget");
|
|
29
|
+
a && a.remove();
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
p as ActionCableClient,
|
|
33
|
+
M as AikaaraChatBubble,
|
|
34
|
+
d as AikaaraChatClient,
|
|
35
|
+
w as AikaaraChatHeader,
|
|
36
|
+
y as AikaaraChatInput,
|
|
37
|
+
v as AikaaraChatWidget,
|
|
38
|
+
E as AikaaraErrorBanner,
|
|
39
|
+
S as AikaaraMessageBubble,
|
|
40
|
+
x as AikaaraMessageList,
|
|
41
|
+
B as AikaaraStreamingMessage,
|
|
42
|
+
I as AikaaraTypingIndicator,
|
|
43
|
+
g as ApiClient,
|
|
44
|
+
h as ChannelSubscription,
|
|
45
|
+
k as ConnectionManager,
|
|
46
|
+
C as ConversationManager,
|
|
47
|
+
b as EventEmitter,
|
|
48
|
+
A as MessageStore,
|
|
49
|
+
l as mount,
|
|
50
|
+
n as registerComponents,
|
|
51
|
+
c as unmount
|
|
52
|
+
};
|