@kodaris/krubble-app-components 1.0.67 → 1.0.69

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 CHANGED
@@ -7,21 +7,6 @@ export interface KRChatbotMessage {
7
7
  content: string;
8
8
  reasoning?: string;
9
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
10
  /**
26
11
  * Callback function type for sending messages.
27
12
  * Receives the user's message text and the current conversation history.
@@ -32,18 +17,17 @@ export type KRChatbotSend = (params: {
32
17
  messages: KRChatbotMessage[];
33
18
  }) => Promise<Response>;
34
19
  /**
35
- * AI chatbot component with SSE streaming and native browser action execution.
20
+ * AI chatbot component with SSE streaming.
36
21
  *
37
22
  * 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.).
23
+ * Parses the stream for text tokens, status updates, and errors.
24
+ * Dispatches a `stream-event` custom event for every SSE message so consumers can react.
41
25
  *
42
26
  * ## SSE Stream Format
43
27
  * The component expects `data:` lines with JSON payloads containing a `type` field:
44
28
  * - `STATUS` — `{ type: "STATUS", message: "Thinking..." }`
45
29
  * - `RESPONSE_PART` — `{ type: "RESPONSE_PART", message: "token text" }`
46
- * - `ACTION` — `{ type: "ACTION", action: "RELOAD" }` (see KRChatbotAction)
30
+ * - `TOOL_RESULT` — `{ type: "TOOL_RESULT", message: "tool_name", data: {...} }`
47
31
  * - `ERROR` — `{ type: "ERROR", message: "Something went wrong" }`
48
32
  * - `HEARTBEAT` — `{ type: "HEARTBEAT" }` (ignored)
49
33
  *
@@ -67,7 +51,7 @@ export type KRChatbotSend = (params: {
67
51
  * @slot - Optional slot content displayed above the messages area
68
52
  *
69
53
  * @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 }`
54
+ * @fires stream-event - Dispatched for every SSE message received. Detail contains the parsed event data.
71
55
  */
72
56
  export declare class KRChatbot extends LitElement {
73
57
  static styles: import("lit").CSSResult;
@@ -77,6 +61,7 @@ export declare class KRChatbot extends LitElement {
77
61
  private _userHasScrolledUp;
78
62
  private _isDragging;
79
63
  private _isResizing;
64
+ private _overlay;
80
65
  private _resizeDir;
81
66
  private _dragStartX;
82
67
  private _dragStartY;
@@ -94,6 +79,11 @@ export declare class KRChatbot extends LitElement {
94
79
  * Must return a Promise — messages are only cleared if it resolves.
95
80
  */
96
81
  clear: (() => Promise<unknown>) | null;
82
+ /**
83
+ * Callback function called on init to load existing conversation messages.
84
+ * Must return a Promise that resolves with an array of KRChatbotMessage.
85
+ */
86
+ load: (() => Promise<KRChatbotMessage[]>) | null;
97
87
  /**
98
88
  * Conversation messages. Can be set externally for initial messages.
99
89
  * Updated internally as the conversation progresses.
@@ -122,17 +112,42 @@ export declare class KRChatbot extends LitElement {
122
112
  private _panelEl;
123
113
  private _messagesEl;
124
114
  private _inputEl;
115
+ connectedCallback(): void;
125
116
  disconnectedCallback(): void;
126
117
  updated(changed: Map<string, unknown>): void;
127
118
  /**
128
119
  * Stops the current stream without clearing the conversation.
129
120
  */
130
121
  stop(): void;
122
+ /**
123
+ * Shows a full-viewport transparent overlay during drag/resize operations.
124
+ *
125
+ * This overlay solves a critical rendering issue when the chatbot is used inside
126
+ * a page that contains iframes (e.g., the AI editor shell where the page content
127
+ * is rendered in an iframe and the chatbot floats on top).
128
+ *
129
+ * Without the overlay, modifying the iframe's `pointer-events` style during drag
130
+ * (to prevent it from swallowing mousemove events) causes Chrome to recalculate
131
+ * compositing layers. This layer recalculation blocks the browser from repainting
132
+ * the chatbot panel's style changes (width/height/position) even though they are
133
+ * correctly applied to the DOM. The result is that the panel appears frozen while
134
+ * the user drags, despite the inline styles updating on every mousemove.
135
+ *
136
+ * The overlay approach avoids this entirely: instead of touching the iframe's styles,
137
+ * we place a transparent div (z-index 9999) above the iframe but below the chatbot
138
+ * (z-index 10000). This div intercepts all mouse events that would otherwise hit the
139
+ * iframe, without triggering any compositing layer changes on the iframe itself.
140
+ */
141
+ private _showOverlay;
142
+ private _hideOverlay;
131
143
  private _handleHeaderMouseDown;
132
144
  private _handleResizeMouseDown;
133
145
  private _handleMouseMove;
134
146
  private _handleMouseUp;
135
147
  private _handleToggle;
148
+ private _saveState;
149
+ private _restoreState;
150
+ private _applyStoredLayout;
136
151
  private _handleInputChange;
137
152
  private _handleKeyDown;
138
153
  private _handleSubmit;
@@ -142,12 +157,6 @@ export declare class KRChatbot extends LitElement {
142
157
  private _handleErrorDismiss;
143
158
  private _readStreamChunk;
144
159
  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
160
  render(): import("lit-html").TemplateResult<1>;
152
161
  }
153
162
  declare global {
@@ -1 +1 @@
1
- {"version":3,"file":"chatbot.d.ts","sourceRoot":"","sources":["../src/chatbot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,MAAM,KAAK,CAAC;AAKrD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EA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