@kodaris/krubble-app-components 1.0.61 → 1.0.63
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/chatbot.d.ts +158 -0
- package/dist/chatbot.d.ts.map +1 -0
- package/dist/chatbot.js +1320 -0
- package/dist/chatbot.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/krubble-app.bundled.js +1378 -50
- package/dist/krubble-app.bundled.js.map +1 -1
- package/dist/krubble-app.bundled.min.js +790 -71
- package/dist/krubble-app.bundled.min.js.map +1 -1
- package/dist/krubble-app.umd.js +1377 -49
- package/dist/krubble-app.umd.js.map +1 -1
- package/dist/krubble-app.umd.min.js +790 -71
- package/dist/krubble-app.umd.min.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Chat message interface
|
|
4
|
+
*/
|
|
5
|
+
export interface KRChatbotMessage {
|
|
6
|
+
role: 'user' | 'assistant';
|
|
7
|
+
content: string;
|
|
8
|
+
reasoning?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Frontend action dispatched by the AI via the SSE stream.
|
|
12
|
+
* The backend passes through tool calls from the AI model as ACTION events.
|
|
13
|
+
*
|
|
14
|
+
* Each action type has a specific `data` shape:
|
|
15
|
+
* - `RELOAD` — no data needed
|
|
16
|
+
* - `NAVIGATE` — `{ url: string }`
|
|
17
|
+
* - `UPDATE_HTML` — `{ selector: string, html: string }`
|
|
18
|
+
* - `OPEN_TAB` — `{ url: string }`
|
|
19
|
+
* - `SCROLL_TO` — `{ selector: string }`
|
|
20
|
+
*/
|
|
21
|
+
export interface KRChatbotAction {
|
|
22
|
+
action: 'RELOAD' | 'NAVIGATE' | 'UPDATE_HTML' | 'OPEN_TAB' | 'SCROLL_TO';
|
|
23
|
+
data?: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Callback function type for sending messages.
|
|
27
|
+
* Receives the user's message text and the current conversation history.
|
|
28
|
+
* Must return a Response with a streaming body (SSE format).
|
|
29
|
+
*/
|
|
30
|
+
export type KRChatbotSend = (params: {
|
|
31
|
+
message: string;
|
|
32
|
+
messages: KRChatbotMessage[];
|
|
33
|
+
}) => Promise<Response>;
|
|
34
|
+
/**
|
|
35
|
+
* AI chatbot component with SSE streaming and native browser action execution.
|
|
36
|
+
*
|
|
37
|
+
* Accepts a `send` callback that returns a streaming Response (SSE format).
|
|
38
|
+
* Parses the stream for text tokens, status updates, errors, and frontend actions.
|
|
39
|
+
* When an ACTION event arrives, dispatches a cancelable `action` custom event.
|
|
40
|
+
* If not prevented, executes the native browser action (reload, navigate, etc.).
|
|
41
|
+
*
|
|
42
|
+
* ## SSE Stream Format
|
|
43
|
+
* The component expects `data:` lines with JSON payloads containing a `type` field:
|
|
44
|
+
* - `STATUS` — `{ type: "STATUS", message: "Thinking..." }`
|
|
45
|
+
* - `RESPONSE_PART` — `{ type: "RESPONSE_PART", message: "token text" }`
|
|
46
|
+
* - `ACTION` — `{ type: "ACTION", action: "RELOAD" }` (see KRChatbotAction)
|
|
47
|
+
* - `ERROR` — `{ type: "ERROR", message: "Something went wrong" }`
|
|
48
|
+
* - `HEARTBEAT` — `{ type: "HEARTBEAT" }` (ignored)
|
|
49
|
+
*
|
|
50
|
+
* The final event should include `finished: true` to signal stream completion.
|
|
51
|
+
*
|
|
52
|
+
* ## Usage
|
|
53
|
+
* ```html
|
|
54
|
+
* <kr-chatbot
|
|
55
|
+
* title="AI Assistant"
|
|
56
|
+
* .send=${(params) => {
|
|
57
|
+
* return fetch('/api/ai/chat/stream', {
|
|
58
|
+
* method: 'POST',
|
|
59
|
+
* headers: { 'Content-Type': 'application/json', 'Accept': 'text/event-stream' },
|
|
60
|
+
* credentials: 'include',
|
|
61
|
+
* body: JSON.stringify({ userText: params.message })
|
|
62
|
+
* });
|
|
63
|
+
* }}
|
|
64
|
+
* ></kr-chatbot>
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @slot - Optional slot content displayed above the messages area
|
|
68
|
+
*
|
|
69
|
+
* @fires message-submit - When the user sends a message. Cancelable. Detail: `{ message: string }`
|
|
70
|
+
* @fires action - When the AI requests a frontend action. Cancelable. Detail: `{ action: KRChatbotAction }`
|
|
71
|
+
*/
|
|
72
|
+
export declare class KRChatbot extends LitElement {
|
|
73
|
+
static styles: import("lit").CSSResult;
|
|
74
|
+
private _reader;
|
|
75
|
+
private _decoder;
|
|
76
|
+
private _buffer;
|
|
77
|
+
private _userHasScrolledUp;
|
|
78
|
+
private _isDragging;
|
|
79
|
+
private _isResizing;
|
|
80
|
+
private _resizeDir;
|
|
81
|
+
private _dragStartX;
|
|
82
|
+
private _dragStartY;
|
|
83
|
+
private _dragStartLeft;
|
|
84
|
+
private _dragStartTop;
|
|
85
|
+
private _resizeStartW;
|
|
86
|
+
private _resizeStartH;
|
|
87
|
+
/**
|
|
88
|
+
* Callback function for sending messages. Receives the user's message and
|
|
89
|
+
* current conversation history. Must return a Response with a streaming SSE body.
|
|
90
|
+
*/
|
|
91
|
+
send: KRChatbotSend | null;
|
|
92
|
+
/**
|
|
93
|
+
* Callback function called when the user clears the conversation.
|
|
94
|
+
* Must return a Promise — messages are only cleared if it resolves.
|
|
95
|
+
*/
|
|
96
|
+
clear: (() => Promise<unknown>) | null;
|
|
97
|
+
/**
|
|
98
|
+
* Conversation messages. Can be set externally for initial messages.
|
|
99
|
+
* Updated internally as the conversation progresses.
|
|
100
|
+
*/
|
|
101
|
+
messages: KRChatbotMessage[];
|
|
102
|
+
/**
|
|
103
|
+
* Header title text.
|
|
104
|
+
*/
|
|
105
|
+
title: string;
|
|
106
|
+
/**
|
|
107
|
+
* Header subtitle text (shown below title with a green status dot).
|
|
108
|
+
*/
|
|
109
|
+
subtitle: string;
|
|
110
|
+
/**
|
|
111
|
+
* Input placeholder text.
|
|
112
|
+
*/
|
|
113
|
+
placeholder: string;
|
|
114
|
+
/**
|
|
115
|
+
* Whether the chat panel is open. Only relevant in floating mode.
|
|
116
|
+
*/
|
|
117
|
+
opened: boolean;
|
|
118
|
+
private _inputValue;
|
|
119
|
+
private _isStreaming;
|
|
120
|
+
private _statusText;
|
|
121
|
+
private _error;
|
|
122
|
+
private _panelEl;
|
|
123
|
+
private _messagesEl;
|
|
124
|
+
private _inputEl;
|
|
125
|
+
disconnectedCallback(): void;
|
|
126
|
+
updated(changed: Map<string, unknown>): void;
|
|
127
|
+
/**
|
|
128
|
+
* Stops the current stream without clearing the conversation.
|
|
129
|
+
*/
|
|
130
|
+
stop(): void;
|
|
131
|
+
private _handleHeaderMouseDown;
|
|
132
|
+
private _handleResizeMouseDown;
|
|
133
|
+
private _handleMouseMove;
|
|
134
|
+
private _handleMouseUp;
|
|
135
|
+
private _handleToggle;
|
|
136
|
+
private _handleInputChange;
|
|
137
|
+
private _handleKeyDown;
|
|
138
|
+
private _handleSubmit;
|
|
139
|
+
private _handleStop;
|
|
140
|
+
private _handleClear;
|
|
141
|
+
private _handleMessagesScroll;
|
|
142
|
+
private _handleErrorDismiss;
|
|
143
|
+
private _readStreamChunk;
|
|
144
|
+
private _handleStreamError;
|
|
145
|
+
/**
|
|
146
|
+
* Lightweight text formatting for assistant messages.
|
|
147
|
+
* Handles code blocks, inline code, bold, and line breaks.
|
|
148
|
+
* Escapes HTML entities first to prevent XSS.
|
|
149
|
+
*/
|
|
150
|
+
private _formatAssistantContent;
|
|
151
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
152
|
+
}
|
|
153
|
+
declare global {
|
|
154
|
+
interface HTMLElementTagNameMap {
|
|
155
|
+
'kr-chatbot': KRChatbot;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=chatbot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatbot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