@tylertech/forge-ai 0.10.0 → 0.11.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/custom-elements.json +4036 -2443
- package/dist/ai-chatbot/ai-chatbot-base.d.ts +92 -0
- package/dist/ai-chatbot/ai-chatbot-base.mjs +467 -0
- package/dist/ai-chatbot/ai-chatbot.d.ts +26 -75
- package/dist/ai-chatbot/ai-chatbot.mjs +51 -808
- package/dist/ai-chatbot/index.d.ts +3 -2
- package/dist/ai-chatbot/index.mjs +2 -0
- package/dist/ai-chatbot/message-state-controller.mjs +1 -1
- package/dist/ai-chatbot-launcher/ai-chatbot-launcher.d.ts +71 -0
- package/dist/ai-chatbot-launcher/ai-chatbot-launcher.mjs +288 -0
- package/dist/ai-chatbot-launcher/ai-chatbot-launcher.scss.mjs +4 -0
- package/dist/ai-chatbot-launcher/index.d.ts +1 -0
- package/dist/ai-chatbot-launcher/index.mjs +5 -0
- package/dist/ai-embedded-chat/ai-embedded-chat.mjs +1 -0
- package/dist/ai-empty-state/ai-empty-state.scss.mjs +1 -1
- package/dist/ai-message-thread/ai-message-thread.d.ts +2 -0
- package/dist/ai-message-thread/ai-message-thread.mjs +1 -1
- package/dist/ai-message-thread/ai-message-thread.scss.mjs +1 -1
- package/dist/ai-prompt/ai-prompt.scss.mjs +1 -1
- package/dist/core/chatbot-core-controller.d.ts +51 -0
- package/dist/core/chatbot-core-controller.mjs +400 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.mjs +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +5 -0
- package/dist/tools/ai-data-table/ai-data-table-definition.mjs +1 -0
- package/package.json +24 -24
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { unsafeCSS,
|
|
1
|
+
import { unsafeCSS, html, nothing } from "lit";
|
|
2
2
|
import { property, customElement } from "lit/decorators.js";
|
|
3
3
|
import { createRef, ref } from "lit/directives/ref.js";
|
|
4
4
|
import { when } from "lit/directives/when.js";
|
|
5
|
-
import {
|
|
6
|
-
import { FileUploadManager } from "./file-upload-manager.mjs";
|
|
7
|
-
import { MessageStateController } from "./message-state-controller.mjs";
|
|
8
|
-
import { generateId, downloadFile } from "./utils.mjs";
|
|
5
|
+
import { AiChatbotBase } from "./ai-chatbot-base.mjs";
|
|
9
6
|
import "../ai-attachment/ai-attachment.mjs";
|
|
10
7
|
import "../ai-chat-header/ai-chat-header.mjs";
|
|
11
8
|
import "../ai-chat-interface/ai-chat-interface.mjs";
|
|
@@ -32,168 +29,32 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
32
29
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
33
30
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
34
31
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
35
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
36
32
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
37
|
-
var
|
|
38
|
-
set _(value) {
|
|
39
|
-
__privateSet(obj, member, value);
|
|
40
|
-
},
|
|
41
|
-
get _() {
|
|
42
|
-
return __privateGet(obj, member, getter);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
var _chatInterfaceRef, _messageThreadRef, _promptRef, _headerRef, _messageStateController, _fileUploadManager, _toolsMap, _adapterSubscriptions, _executingToolHandlers, _AiChatbotComponent_instances, slashCommands_get, messageItems_get, isStreaming_get, isUploading_get, hasMessages_get, tools_get, setupAdapter_fn, handleMessageStart_fn, handleMessageDelta_fn, handleMessageEnd_fn, handleRunFinished_fn, tryCompleteResponse_fn, handleToolCallStart_fn, handleToolCallArgs_fn, handleToolCallEnd_fn, createToolResponse_fn, handleToolCall_fn, executeToolHandler_fn, handleError_fn, handleRunAborted_fn, handleStateChange_fn, handleToolCallResult_fn, sendToolResult_fn, sendUserMessage_fn, handleSend_fn, handleStop_fn, handleCancel_fn, handleCopy_fn, handleUserCopy_fn, handleUserResend_fn, handleUserEdit_fn, handleResend_fn, handleFeedback_fn, handleThumbsUp_fn, handleThumbsDown_fn, processFileUpload_fn, handleFileSelect_fn, createFileUploadCallbacks_fn, handleFileError_fn, handleAttachmentRemove_fn, handleSuggestionSelect_fn, handleVoiceInputResult_fn, handleHeaderExpand_fn, handleHeaderMinimize_fn, handleHeaderClear_fn, handleHeaderInfo_fn, handleAgentChange_fn, handleDebugToggle_fn, handleSlashCommand_fn, formatToolCallForExport_fn, handleExport_fn, sessionFilesTemplate_get, promptSlot_get, messageThread_get, dispatchEvent_fn, dispatchMessageEvent_fn, emitStateChange_fn;
|
|
33
|
+
var _chatInterfaceRef, _headerRef, _AiChatbotComponent_instances, handleHeaderExpand_fn, handleHeaderMinimize_fn, handleHeaderClear_fn, handleHeaderInfo_fn, sessionFilesTemplate_get, promptSlot_get, messageThread_get;
|
|
46
34
|
const AiChatbotComponentTagName = "forge-ai-chatbot";
|
|
47
|
-
let AiChatbotComponent = class extends
|
|
35
|
+
let AiChatbotComponent = class extends AiChatbotBase {
|
|
48
36
|
constructor() {
|
|
49
37
|
super(...arguments);
|
|
50
38
|
__privateAdd(this, _AiChatbotComponent_instances);
|
|
51
|
-
this.fileUpload = "off";
|
|
52
|
-
this.voiceInput = "on";
|
|
53
|
-
this.debugCommand = "on";
|
|
54
|
-
this.placeholder = "Ask a question...";
|
|
55
39
|
this.showExpandButton = false;
|
|
56
40
|
this.showMinimizeButton = false;
|
|
57
41
|
this.expanded = false;
|
|
58
42
|
this.minimizeIcon = "default";
|
|
59
|
-
this.enableReactions = false;
|
|
60
|
-
this.titleText = "AI Assistant";
|
|
61
|
-
this.headingLevel = 2;
|
|
62
|
-
this.debugMode = false;
|
|
63
|
-
this.disclaimerText = "AI can make mistakes. Always verify responses.";
|
|
64
|
-
this.agents = [];
|
|
65
43
|
__privateAdd(this, _chatInterfaceRef, createRef());
|
|
66
|
-
|
|
67
|
-
|
|
44
|
+
this._messageThreadRef = createRef();
|
|
45
|
+
this._promptRef = createRef();
|
|
68
46
|
__privateAdd(this, _headerRef, createRef());
|
|
69
|
-
__privateAdd(this, _messageStateController);
|
|
70
|
-
__privateAdd(this, _fileUploadManager);
|
|
71
|
-
__privateAdd(this, _toolsMap);
|
|
72
|
-
__privateAdd(this, _adapterSubscriptions);
|
|
73
|
-
__privateAdd(this, _executingToolHandlers, 0);
|
|
74
47
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
onThreadSettled: () => __privateMethod(this, _AiChatbotComponent_instances, emitStateChange_fn).call(this)
|
|
80
|
-
}));
|
|
81
|
-
__privateSet(this, _fileUploadManager, new FileUploadManager({
|
|
82
|
-
onError: (error) => {
|
|
83
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, {
|
|
84
|
-
type: "forge-ai-chatbot-error",
|
|
85
|
-
detail: { error }
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
onStateChange: () => {
|
|
89
|
-
this.requestUpdate();
|
|
90
|
-
}
|
|
91
|
-
}));
|
|
92
|
-
if (this.adapter) {
|
|
93
|
-
void __privateMethod(this, _AiChatbotComponent_instances, setupAdapter_fn).call(this);
|
|
48
|
+
_handleInfo() {
|
|
49
|
+
const header = __privateGet(this, _headerRef).value;
|
|
50
|
+
if (header?.showAgentInfo) {
|
|
51
|
+
header.showAgentInfo();
|
|
94
52
|
}
|
|
53
|
+
super._handleInfo();
|
|
95
54
|
}
|
|
96
|
-
disconnectedCallback() {
|
|
97
|
-
super.disconnectedCallback();
|
|
98
|
-
__privateGet(this, _adapterSubscriptions)?.unsubscribe();
|
|
99
|
-
this.adapter?.disconnect();
|
|
100
|
-
}
|
|
101
|
-
willUpdate(changedProperties) {
|
|
102
|
-
if (changedProperties.has("adapter") && this.adapter) {
|
|
103
|
-
__privateSet(this, _toolsMap, void 0);
|
|
104
|
-
__privateMethod(this, _AiChatbotComponent_instances, setupAdapter_fn).call(this);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Clears all messages from the chat history.
|
|
109
|
-
*/
|
|
110
|
-
clearMessages() {
|
|
111
|
-
__privateGet(this, _messageStateController).clearMessages();
|
|
112
|
-
__privateGet(this, _fileUploadManager).clear();
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Gets the current message history.
|
|
116
|
-
* @returns Array of chat messages
|
|
117
|
-
*/
|
|
118
|
-
getMessages() {
|
|
119
|
-
return __privateGet(this, _messageStateController).getMessages();
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Sets the message history. Useful for restoring conversation state.
|
|
123
|
-
* @param messages - Array of chat messages to set
|
|
124
|
-
*/
|
|
125
|
-
setMessages(messages) {
|
|
126
|
-
__privateGet(this, _messageStateController).setMessages(messages);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Gets the currently selected agent.
|
|
130
|
-
* @returns The selected agent or undefined if none selected
|
|
131
|
-
*/
|
|
132
|
-
getSelectedAgent() {
|
|
133
|
-
return this.agents.find((a) => a.id === this.selectedAgentId);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Programmatically sends a message as the user.
|
|
137
|
-
* @param content - The message content to send
|
|
138
|
-
* @param files - Optional file objects to attach
|
|
139
|
-
*/
|
|
140
55
|
async sendMessage(content, files) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
__privateGet(this, _promptRef).value?.closeSlashMenu();
|
|
146
|
-
if (files) {
|
|
147
|
-
const timestamp = Date.now();
|
|
148
|
-
for (const file of files) {
|
|
149
|
-
__privateMethod(this, _AiChatbotComponent_instances, processFileUpload_fn).call(this, file, timestamp);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
await __privateMethod(this, _AiChatbotComponent_instances, sendUserMessage_fn).call(this, {
|
|
153
|
-
content,
|
|
154
|
-
attachments: __privateGet(this, _fileUploadManager).pendingAttachments
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Aborts the current streaming response.
|
|
159
|
-
*/
|
|
160
|
-
abort() {
|
|
161
|
-
__privateMethod(this, _AiChatbotComponent_instances, handleStop_fn).call(this);
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Scrolls the chat interface to the bottom.
|
|
165
|
-
*/
|
|
166
|
-
async scrollToBottom({ behavior } = {}) {
|
|
167
|
-
await __privateGet(this, _messageThreadRef).value?.updateComplete;
|
|
168
|
-
await new Promise(requestAnimationFrame);
|
|
169
|
-
__privateGet(this, _messageThreadRef).value?.scrollToBottom({ behavior });
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Gets the complete serializable thread state including threadId and messages.
|
|
173
|
-
* @returns ThreadState object containing threadId, messages, and timestamp
|
|
174
|
-
*/
|
|
175
|
-
getThreadState() {
|
|
176
|
-
return {
|
|
177
|
-
threadId: this.adapter?.threadId,
|
|
178
|
-
messages: this.getMessages(),
|
|
179
|
-
timestamp: Date.now(),
|
|
180
|
-
selectedAgentId: this.selectedAgentId
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Restores thread state from a serialized ThreadState object.
|
|
185
|
-
* @param state - ThreadState object to restore
|
|
186
|
-
*/
|
|
187
|
-
async setThreadState(state) {
|
|
188
|
-
this.setMessages(state.messages);
|
|
189
|
-
if (state.threadId && this.adapter) {
|
|
190
|
-
this.adapter.threadId = state.threadId;
|
|
191
|
-
}
|
|
192
|
-
this.selectedAgentId = state.selectedAgentId;
|
|
193
|
-
await this.updateComplete;
|
|
194
|
-
const userMessages = state.messages.filter((msg) => msg.role === "user").map((msg) => msg.content);
|
|
195
|
-
__privateGet(this, _promptRef).value?.setHistory(userMessages);
|
|
196
|
-
this.scrollToBottom({ behavior: "instant" });
|
|
56
|
+
this._promptRef.value?.closeSlashMenu();
|
|
57
|
+
await super.sendMessage(content, files);
|
|
197
58
|
}
|
|
198
59
|
render() {
|
|
199
60
|
return html`
|
|
@@ -202,16 +63,16 @@ let AiChatbotComponent = class extends LitElement {
|
|
|
202
63
|
role="region"
|
|
203
64
|
aria-label="AI chatbot"
|
|
204
65
|
aria-live="polite"
|
|
205
|
-
aria-busy=${
|
|
66
|
+
aria-busy=${this._isStreaming}>
|
|
206
67
|
<forge-ai-chat-header
|
|
207
68
|
${ref(__privateGet(this, _headerRef))}
|
|
208
69
|
slot="header"
|
|
209
70
|
?show-expand-button=${this.showExpandButton}
|
|
210
71
|
?show-minimize-button=${this.showMinimizeButton}
|
|
211
72
|
?expanded=${this.expanded}
|
|
212
|
-
?disable-agent-selector=${
|
|
213
|
-
export-option=${
|
|
214
|
-
clear-option=${
|
|
73
|
+
?disable-agent-selector=${this._isStreaming}
|
|
74
|
+
export-option=${this._hasMessages ? "enabled" : "off"}
|
|
75
|
+
clear-option=${this._hasMessages ? "enabled" : "off"}
|
|
215
76
|
.minimizeIcon=${this.minimizeIcon}
|
|
216
77
|
.agentInfo=${this.agentInfo}
|
|
217
78
|
.headingLevel=${this.headingLevel}
|
|
@@ -221,9 +82,9 @@ let AiChatbotComponent = class extends LitElement {
|
|
|
221
82
|
@forge-ai-chat-header-expand=${__privateMethod(this, _AiChatbotComponent_instances, handleHeaderExpand_fn)}
|
|
222
83
|
@forge-ai-chat-header-minimize=${__privateMethod(this, _AiChatbotComponent_instances, handleHeaderMinimize_fn)}
|
|
223
84
|
@forge-ai-chat-header-clear=${__privateMethod(this, _AiChatbotComponent_instances, handleHeaderClear_fn)}
|
|
224
|
-
@forge-ai-chat-header-export=${
|
|
85
|
+
@forge-ai-chat-header-export=${this._handleExport}
|
|
225
86
|
@forge-ai-chat-header-info=${__privateMethod(this, _AiChatbotComponent_instances, handleHeaderInfo_fn)}
|
|
226
|
-
@forge-ai-chat-header-agent-change=${
|
|
87
|
+
@forge-ai-chat-header-agent-change=${this._handleAgentChange}>
|
|
227
88
|
<slot name="icon" slot="icon">
|
|
228
89
|
<forge-ai-icon></forge-ai-icon>
|
|
229
90
|
</slot>
|
|
@@ -235,600 +96,43 @@ let AiChatbotComponent = class extends LitElement {
|
|
|
235
96
|
}
|
|
236
97
|
};
|
|
237
98
|
_chatInterfaceRef = /* @__PURE__ */ new WeakMap();
|
|
238
|
-
_messageThreadRef = /* @__PURE__ */ new WeakMap();
|
|
239
|
-
_promptRef = /* @__PURE__ */ new WeakMap();
|
|
240
99
|
_headerRef = /* @__PURE__ */ new WeakMap();
|
|
241
|
-
_messageStateController = /* @__PURE__ */ new WeakMap();
|
|
242
|
-
_fileUploadManager = /* @__PURE__ */ new WeakMap();
|
|
243
|
-
_toolsMap = /* @__PURE__ */ new WeakMap();
|
|
244
|
-
_adapterSubscriptions = /* @__PURE__ */ new WeakMap();
|
|
245
|
-
_executingToolHandlers = /* @__PURE__ */ new WeakMap();
|
|
246
100
|
_AiChatbotComponent_instances = /* @__PURE__ */ new WeakSet();
|
|
247
|
-
slashCommands_get = function() {
|
|
248
|
-
const commands = [];
|
|
249
|
-
if (__privateGet(this, _AiChatbotComponent_instances, hasMessages_get)) {
|
|
250
|
-
commands.push({ id: "clear", name: "Clear", group: "Conversation" });
|
|
251
|
-
commands.push({ id: "export", name: "Export", group: "Conversation" });
|
|
252
|
-
}
|
|
253
|
-
commands.push({ id: "info", name: "Info", group: "Help" });
|
|
254
|
-
if (this.debugCommand === "on") {
|
|
255
|
-
commands.push({
|
|
256
|
-
id: "debug",
|
|
257
|
-
name: `${this.debugMode ? "Disable debug mode" : "Enable debug mode"}`,
|
|
258
|
-
group: "Help"
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
return commands;
|
|
262
|
-
};
|
|
263
|
-
messageItems_get = function() {
|
|
264
|
-
return __privateGet(this, _messageStateController)?.messageItems ?? [];
|
|
265
|
-
};
|
|
266
|
-
isStreaming_get = function() {
|
|
267
|
-
return (this.adapter?.isRunning ?? false) || __privateGet(this, _executingToolHandlers) > 0;
|
|
268
|
-
};
|
|
269
|
-
isUploading_get = function() {
|
|
270
|
-
return __privateGet(this, _fileUploadManager)?.isUploading ?? false;
|
|
271
|
-
};
|
|
272
|
-
hasMessages_get = function() {
|
|
273
|
-
return __privateGet(this, _AiChatbotComponent_instances, messageItems_get).length > 0;
|
|
274
|
-
};
|
|
275
|
-
tools_get = function() {
|
|
276
|
-
if (!__privateGet(this, _toolsMap)) {
|
|
277
|
-
__privateSet(this, _toolsMap, new Map(this.adapter?.getTools().map((t) => [t.name, t]) ?? []));
|
|
278
|
-
}
|
|
279
|
-
return __privateGet(this, _toolsMap);
|
|
280
|
-
};
|
|
281
|
-
setupAdapter_fn = async function() {
|
|
282
|
-
if (!this.adapter || this.adapter.isConnecting) {
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
await this.adapter.connect();
|
|
286
|
-
__privateGet(this, _adapterSubscriptions)?.unsubscribe();
|
|
287
|
-
__privateSet(this, _adapterSubscriptions, new SubscriptionManager());
|
|
288
|
-
__privateGet(this, _adapterSubscriptions).add(
|
|
289
|
-
this.adapter.onMessageStart(__privateMethod(this, _AiChatbotComponent_instances, handleMessageStart_fn).bind(this)),
|
|
290
|
-
this.adapter.onMessageDelta(__privateMethod(this, _AiChatbotComponent_instances, handleMessageDelta_fn).bind(this)),
|
|
291
|
-
this.adapter.onMessageEnd(__privateMethod(this, _AiChatbotComponent_instances, handleMessageEnd_fn).bind(this)),
|
|
292
|
-
this.adapter.onToolCallStart(__privateMethod(this, _AiChatbotComponent_instances, handleToolCallStart_fn).bind(this)),
|
|
293
|
-
this.adapter.onToolCallArgs(__privateMethod(this, _AiChatbotComponent_instances, handleToolCallArgs_fn).bind(this)),
|
|
294
|
-
this.adapter.onToolCallEnd(__privateMethod(this, _AiChatbotComponent_instances, handleToolCallEnd_fn).bind(this)),
|
|
295
|
-
this.adapter.onToolCall(__privateMethod(this, _AiChatbotComponent_instances, handleToolCall_fn).bind(this)),
|
|
296
|
-
this.adapter.onToolCallResult(__privateMethod(this, _AiChatbotComponent_instances, handleToolCallResult_fn).bind(this)),
|
|
297
|
-
this.adapter.onRunFinished(__privateMethod(this, _AiChatbotComponent_instances, handleRunFinished_fn).bind(this)),
|
|
298
|
-
this.adapter.onRunAborted(__privateMethod(this, _AiChatbotComponent_instances, handleRunAborted_fn).bind(this)),
|
|
299
|
-
this.adapter.onError(__privateMethod(this, _AiChatbotComponent_instances, handleError_fn).bind(this)),
|
|
300
|
-
this.adapter.onStateChange(__privateMethod(this, _AiChatbotComponent_instances, handleStateChange_fn).bind(this))
|
|
301
|
-
);
|
|
302
|
-
__privateSet(this, _toolsMap, void 0);
|
|
303
|
-
__privateGet(this, _messageStateController)?.updateConfig({ tools: __privateGet(this, _AiChatbotComponent_instances, tools_get) });
|
|
304
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, { type: "forge-ai-chatbot-connected" });
|
|
305
|
-
};
|
|
306
|
-
handleMessageStart_fn = function(event) {
|
|
307
|
-
__privateGet(this, _messageStateController).addTextToResponse(event.messageId, "", event);
|
|
308
|
-
};
|
|
309
|
-
handleMessageDelta_fn = function(event) {
|
|
310
|
-
__privateGet(this, _messageStateController).appendTextDelta(event.messageId, event.delta, event);
|
|
311
|
-
this.scrollToBottom();
|
|
312
|
-
};
|
|
313
|
-
handleMessageEnd_fn = function(event) {
|
|
314
|
-
__privateGet(this, _messageStateController).markTextComplete(event.messageId, event);
|
|
315
|
-
};
|
|
316
|
-
handleRunFinished_fn = function() {
|
|
317
|
-
__privateMethod(this, _AiChatbotComponent_instances, tryCompleteResponse_fn).call(this);
|
|
318
|
-
};
|
|
319
|
-
tryCompleteResponse_fn = function() {
|
|
320
|
-
if (__privateGet(this, _executingToolHandlers) > 0 || this.adapter?.isRunning) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
__privateGet(this, _messageStateController).tryFinalizeResponse();
|
|
324
|
-
const messages = this.getMessages();
|
|
325
|
-
const lastMessage = messages[messages.length - 1];
|
|
326
|
-
if (lastMessage?.role === "assistant" && lastMessage.status === "complete") {
|
|
327
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchMessageEvent_fn).call(this, "forge-ai-chatbot-message-received", lastMessage);
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
handleToolCallStart_fn = function(event) {
|
|
331
|
-
const toolCall = {
|
|
332
|
-
id: event.id,
|
|
333
|
-
messageId: event.messageId,
|
|
334
|
-
name: event.name,
|
|
335
|
-
args: {},
|
|
336
|
-
argsBuffer: "",
|
|
337
|
-
status: "parsing",
|
|
338
|
-
type: __privateGet(this, _AiChatbotComponent_instances, tools_get).has(event.name) ? "client" : "agent"
|
|
339
|
-
};
|
|
340
|
-
__privateGet(this, _messageStateController).addToolCallToResponse(toolCall, event);
|
|
341
|
-
};
|
|
342
|
-
handleToolCallArgs_fn = function(event) {
|
|
343
|
-
const updates = {
|
|
344
|
-
argsBuffer: event.argsBuffer,
|
|
345
|
-
args: event.partialArgs ?? {}
|
|
346
|
-
};
|
|
347
|
-
const rawEvent = { eventType: "tool-call-args", event };
|
|
348
|
-
__privateGet(this, _messageStateController).updateToolCallInResponse(event.id, updates, rawEvent);
|
|
349
|
-
this.scrollToBottom();
|
|
350
|
-
};
|
|
351
|
-
handleToolCallEnd_fn = function(event) {
|
|
352
|
-
const updates = {
|
|
353
|
-
args: event.args,
|
|
354
|
-
argsBuffer: void 0,
|
|
355
|
-
status: "executing"
|
|
356
|
-
};
|
|
357
|
-
const rawEvent = { eventType: "tool-call-end", event };
|
|
358
|
-
__privateGet(this, _messageStateController).updateToolCallInResponse(event.id, updates, rawEvent);
|
|
359
|
-
};
|
|
360
|
-
createToolResponse_fn = function(toolName, handlerReturn) {
|
|
361
|
-
if (typeof handlerReturn === "string") {
|
|
362
|
-
return handlerReturn;
|
|
363
|
-
}
|
|
364
|
-
if (handlerReturn && typeof handlerReturn === "object") {
|
|
365
|
-
return handlerReturn;
|
|
366
|
-
}
|
|
367
|
-
return `Tool '${toolName}' executed successfully`;
|
|
368
|
-
};
|
|
369
|
-
handleToolCall_fn = async function(event) {
|
|
370
|
-
let toolCall = __privateGet(this, _messageStateController).getToolCall(event.id);
|
|
371
|
-
if (toolCall) {
|
|
372
|
-
__privateGet(this, _messageStateController).updateToolCallInResponse(event.id, {
|
|
373
|
-
args: event.args,
|
|
374
|
-
status: "executing"
|
|
375
|
-
});
|
|
376
|
-
} else {
|
|
377
|
-
toolCall = {
|
|
378
|
-
id: event.id,
|
|
379
|
-
messageId: event.messageId,
|
|
380
|
-
name: event.name,
|
|
381
|
-
args: event.args,
|
|
382
|
-
status: "executing",
|
|
383
|
-
type: __privateGet(this, _AiChatbotComponent_instances, tools_get).has(event.name) ? "client" : "agent"
|
|
384
|
-
};
|
|
385
|
-
__privateGet(this, _messageStateController).addToolCallToResponse(toolCall);
|
|
386
|
-
}
|
|
387
|
-
if (toolCall?.type === "client") {
|
|
388
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, {
|
|
389
|
-
type: "forge-ai-chatbot-tool-call",
|
|
390
|
-
detail: {
|
|
391
|
-
toolCallId: event.id,
|
|
392
|
-
toolName: event.name,
|
|
393
|
-
arguments: event.args
|
|
394
|
-
}
|
|
395
|
-
});
|
|
396
|
-
const toolDef = __privateGet(this, _AiChatbotComponent_instances, tools_get).get(event.name);
|
|
397
|
-
if (toolDef?.handler) {
|
|
398
|
-
await Promise.resolve(__privateMethod(this, _AiChatbotComponent_instances, executeToolHandler_fn).call(this, event.id, event.name, toolDef.handler, event.args));
|
|
399
|
-
} else {
|
|
400
|
-
__privateMethod(this, _AiChatbotComponent_instances, sendToolResult_fn).call(this, event.id, __privateMethod(this, _AiChatbotComponent_instances, createToolResponse_fn).call(this, event.name));
|
|
401
|
-
}
|
|
402
|
-
} else {
|
|
403
|
-
__privateGet(this, _messageStateController).updateToolCallInResponse(event.id, { status: "complete" });
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
executeToolHandler_fn = async function(toolCallId, toolName, handler, args) {
|
|
407
|
-
__privateWrapper(this, _executingToolHandlers)._++;
|
|
408
|
-
this.requestUpdate();
|
|
409
|
-
try {
|
|
410
|
-
const context = {
|
|
411
|
-
args,
|
|
412
|
-
toolCallId,
|
|
413
|
-
toolName,
|
|
414
|
-
signal: void 0
|
|
415
|
-
};
|
|
416
|
-
const handlerReturn = await handler(context);
|
|
417
|
-
await __privateMethod(this, _AiChatbotComponent_instances, sendToolResult_fn).call(this, toolCallId, __privateMethod(this, _AiChatbotComponent_instances, createToolResponse_fn).call(this, toolName, handlerReturn));
|
|
418
|
-
} catch (error) {
|
|
419
|
-
console.error(`Tool handler error [${toolName}]:`, error);
|
|
420
|
-
__privateGet(this, _messageStateController).updateToolCallInResponse(toolCallId, {
|
|
421
|
-
status: "error",
|
|
422
|
-
result: { error: error.message }
|
|
423
|
-
});
|
|
424
|
-
const errorMessage = {
|
|
425
|
-
id: generateId(),
|
|
426
|
-
role: "assistant",
|
|
427
|
-
content: "An unexpected error occurred.",
|
|
428
|
-
timestamp: Date.now(),
|
|
429
|
-
status: "error"
|
|
430
|
-
};
|
|
431
|
-
__privateGet(this, _messageStateController).addMessage(errorMessage);
|
|
432
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, { type: "forge-ai-chatbot-error", detail: { error: error.message } });
|
|
433
|
-
} finally {
|
|
434
|
-
__privateWrapper(this, _executingToolHandlers)._--;
|
|
435
|
-
__privateMethod(this, _AiChatbotComponent_instances, tryCompleteResponse_fn).call(this);
|
|
436
|
-
this.requestUpdate();
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
handleError_fn = function(event) {
|
|
440
|
-
const errorMessage = {
|
|
441
|
-
id: generateId(),
|
|
442
|
-
role: "assistant",
|
|
443
|
-
content: event.message,
|
|
444
|
-
timestamp: Date.now(),
|
|
445
|
-
status: "error"
|
|
446
|
-
};
|
|
447
|
-
__privateGet(this, _messageStateController).addMessage(errorMessage);
|
|
448
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchMessageEvent_fn).call(this, "forge-ai-chatbot-message-received", errorMessage);
|
|
449
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, { type: "forge-ai-chatbot-error", detail: { error: event.message } });
|
|
450
|
-
};
|
|
451
|
-
handleRunAborted_fn = function() {
|
|
452
|
-
const abortMessage = {
|
|
453
|
-
id: generateId(),
|
|
454
|
-
role: "system",
|
|
455
|
-
content: "Run cancelled",
|
|
456
|
-
timestamp: Date.now(),
|
|
457
|
-
status: "complete",
|
|
458
|
-
clientOnly: true
|
|
459
|
-
};
|
|
460
|
-
__privateGet(this, _messageStateController).addMessage(abortMessage);
|
|
461
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchMessageEvent_fn).call(this, "forge-ai-chatbot-message-received", abortMessage);
|
|
462
|
-
};
|
|
463
|
-
handleStateChange_fn = function(_state) {
|
|
464
|
-
this.requestUpdate();
|
|
465
|
-
};
|
|
466
|
-
handleToolCallResult_fn = function(event) {
|
|
467
|
-
__privateGet(this, _messageStateController).completeToolCallInResponse(event.toolCallId, event.result, event);
|
|
468
|
-
};
|
|
469
|
-
sendToolResult_fn = async function(toolCallId, result) {
|
|
470
|
-
const toolCall = __privateGet(this, _messageStateController).getToolCall(toolCallId);
|
|
471
|
-
if (!toolCall || !this.adapter) {
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
__privateGet(this, _messageStateController).completeToolCallInResponse(toolCallId, result);
|
|
475
|
-
this.adapter.sendToolResult(toolCallId, result, this.getMessages());
|
|
476
|
-
};
|
|
477
|
-
sendUserMessage_fn = async function(config) {
|
|
478
|
-
if (!config.content.trim() || !this.adapter || __privateGet(this, _AiChatbotComponent_instances, isStreaming_get)) {
|
|
479
|
-
if (!this.adapter) {
|
|
480
|
-
console.warn("No adapter configured.");
|
|
481
|
-
}
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
if (!__privateGet(this, _fileUploadManager).canSend()) {
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
const userMessage = {
|
|
488
|
-
id: generateId(),
|
|
489
|
-
role: "user",
|
|
490
|
-
content: config.content,
|
|
491
|
-
timestamp: config.timestamp ?? Date.now(),
|
|
492
|
-
status: "pending"
|
|
493
|
-
};
|
|
494
|
-
__privateGet(this, _messageStateController).addMessage(userMessage);
|
|
495
|
-
try {
|
|
496
|
-
this.adapter.sendMessage(this.getMessages());
|
|
497
|
-
__privateGet(this, _messageStateController).updateMessageStatus(userMessage.id, "complete");
|
|
498
|
-
} catch (error) {
|
|
499
|
-
__privateGet(this, _messageStateController).updateMessageStatus(userMessage.id, "error");
|
|
500
|
-
const errorMessage = error instanceof Error ? error.message : "Failed to send message";
|
|
501
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, { type: "forge-ai-chatbot-error", detail: { error: errorMessage } });
|
|
502
|
-
} finally {
|
|
503
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchMessageEvent_fn).call(this, "forge-ai-chatbot-message-sent", userMessage.id);
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
handleSend_fn = async function(evt) {
|
|
507
|
-
const pendingAttachments = [...__privateGet(this, _fileUploadManager).pendingAttachments];
|
|
508
|
-
await __privateMethod(this, _AiChatbotComponent_instances, sendUserMessage_fn).call(this, {
|
|
509
|
-
content: evt.detail.value,
|
|
510
|
-
timestamp: evt.detail.date.getTime(),
|
|
511
|
-
attachments: pendingAttachments
|
|
512
|
-
});
|
|
513
|
-
};
|
|
514
|
-
handleStop_fn = function() {
|
|
515
|
-
if (this.adapter?.isRunning) {
|
|
516
|
-
this.adapter.abort();
|
|
517
|
-
}
|
|
518
|
-
this.requestUpdate();
|
|
519
|
-
};
|
|
520
|
-
handleCancel_fn = function() {
|
|
521
|
-
__privateMethod(this, _AiChatbotComponent_instances, handleStop_fn).call(this);
|
|
522
|
-
};
|
|
523
|
-
handleCopy_fn = async function(evt) {
|
|
524
|
-
const responseId = evt.detail.messageId;
|
|
525
|
-
const responseItem = __privateGet(this, _AiChatbotComponent_instances, messageItems_get).find((item) => item.type === "assistant" && item.data.id === responseId);
|
|
526
|
-
if (!responseItem || responseItem.type !== "assistant") {
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
const textContent = responseItem.data.children.filter(
|
|
530
|
-
(c) => c.type === "text"
|
|
531
|
-
).map((c) => c.content).join("\n\n");
|
|
532
|
-
try {
|
|
533
|
-
await navigator.clipboard.writeText(textContent);
|
|
534
|
-
} catch {
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
handleUserCopy_fn = async function(evt) {
|
|
538
|
-
const messageId = evt.detail.messageId;
|
|
539
|
-
const message = __privateGet(this, _messageStateController).getMessage(messageId);
|
|
540
|
-
if (!message || message.role !== "user") {
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
543
|
-
try {
|
|
544
|
-
await navigator.clipboard.writeText(message.content);
|
|
545
|
-
} catch {
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
handleUserResend_fn = function(evt) {
|
|
549
|
-
if (!this.adapter) {
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
|
-
const messageId = evt.detail.messageId;
|
|
553
|
-
const messageIndex = __privateGet(this, _AiChatbotComponent_instances, messageItems_get).findIndex((item) => item.type === "message" && item.data.id === messageId);
|
|
554
|
-
if (messageIndex === -1) {
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
const responseIndex = messageIndex + 1;
|
|
558
|
-
if (responseIndex < __privateGet(this, _AiChatbotComponent_instances, messageItems_get).length) {
|
|
559
|
-
__privateGet(this, _messageStateController).removeMessageItemsFrom(responseIndex);
|
|
560
|
-
}
|
|
561
|
-
this.adapter.sendMessage(this.getMessages());
|
|
562
|
-
};
|
|
563
|
-
handleUserEdit_fn = function(evt) {
|
|
564
|
-
if (!this.adapter) {
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
const { messageId, content } = evt.detail;
|
|
568
|
-
const messageIndex = __privateGet(this, _AiChatbotComponent_instances, messageItems_get).findIndex((item) => item.type === "message" && item.data.id === messageId);
|
|
569
|
-
if (messageIndex === -1) {
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
__privateGet(this, _messageStateController).updateMessageContent(messageId, content);
|
|
573
|
-
const responseIndex = messageIndex + 1;
|
|
574
|
-
if (responseIndex < __privateGet(this, _AiChatbotComponent_instances, messageItems_get).length) {
|
|
575
|
-
__privateGet(this, _messageStateController).removeMessageItemsFrom(responseIndex);
|
|
576
|
-
}
|
|
577
|
-
this.adapter.sendMessage(this.getMessages());
|
|
578
|
-
};
|
|
579
|
-
handleResend_fn = function(evt) {
|
|
580
|
-
if (!this.adapter) {
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
const responseId = evt.detail.messageId;
|
|
584
|
-
const responseIndex = __privateGet(this, _AiChatbotComponent_instances, messageItems_get).findIndex(
|
|
585
|
-
(item) => item.type === "assistant" && item.data.id === responseId
|
|
586
|
-
);
|
|
587
|
-
if (responseIndex === -1) {
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
__privateGet(this, _messageStateController).removeMessageItemsFrom(responseIndex);
|
|
591
|
-
this.adapter.sendMessage(this.getMessages());
|
|
592
|
-
};
|
|
593
|
-
handleFeedback_fn = function(evt, type) {
|
|
594
|
-
__privateGet(this, _messageStateController).setResponseFeedback(evt.detail.messageId, {
|
|
595
|
-
type,
|
|
596
|
-
reason: evt.detail.feedback
|
|
597
|
-
});
|
|
598
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, {
|
|
599
|
-
type: "forge-ai-chatbot-response-feedback",
|
|
600
|
-
detail: {
|
|
601
|
-
messageId: evt.detail.messageId,
|
|
602
|
-
type,
|
|
603
|
-
feedback: evt.detail.feedback
|
|
604
|
-
}
|
|
605
|
-
});
|
|
606
|
-
};
|
|
607
|
-
handleThumbsUp_fn = function(evt) {
|
|
608
|
-
__privateMethod(this, _AiChatbotComponent_instances, handleFeedback_fn).call(this, evt, "positive");
|
|
609
|
-
};
|
|
610
|
-
handleThumbsDown_fn = function(evt) {
|
|
611
|
-
__privateMethod(this, _AiChatbotComponent_instances, handleFeedback_fn).call(this, evt, "negative");
|
|
612
|
-
};
|
|
613
|
-
processFileUpload_fn = function(file, timestamp) {
|
|
614
|
-
const fileId = generateId();
|
|
615
|
-
__privateGet(this, _fileUploadManager).addAttachment(fileId, {
|
|
616
|
-
filename: file.name,
|
|
617
|
-
size: file.size,
|
|
618
|
-
mimeType: file.type,
|
|
619
|
-
timestamp
|
|
620
|
-
});
|
|
621
|
-
const callbacks = __privateMethod(this, _AiChatbotComponent_instances, createFileUploadCallbacks_fn).call(this, fileId);
|
|
622
|
-
this.adapter?.emitFileUpload(file, callbacks);
|
|
623
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, {
|
|
624
|
-
type: "forge-ai-chatbot-file-select",
|
|
625
|
-
detail: {
|
|
626
|
-
fileId,
|
|
627
|
-
file,
|
|
628
|
-
filename: file.name,
|
|
629
|
-
size: file.size,
|
|
630
|
-
mimeType: file.type,
|
|
631
|
-
timestamp,
|
|
632
|
-
...callbacks
|
|
633
|
-
}
|
|
634
|
-
});
|
|
635
|
-
};
|
|
636
|
-
handleFileSelect_fn = function(evt) {
|
|
637
|
-
const { file, timestamp } = evt.detail;
|
|
638
|
-
__privateMethod(this, _AiChatbotComponent_instances, processFileUpload_fn).call(this, file, timestamp);
|
|
639
|
-
};
|
|
640
|
-
createFileUploadCallbacks_fn = function(fileId) {
|
|
641
|
-
return {
|
|
642
|
-
updateProgress: (progress) => {
|
|
643
|
-
__privateGet(this, _fileUploadManager).updateProgress(fileId, progress);
|
|
644
|
-
},
|
|
645
|
-
markComplete: (uploadedFile) => {
|
|
646
|
-
__privateGet(this, _fileUploadManager).markComplete(fileId, uploadedFile);
|
|
647
|
-
},
|
|
648
|
-
markError: (error) => {
|
|
649
|
-
__privateGet(this, _fileUploadManager).markError(fileId, error);
|
|
650
|
-
},
|
|
651
|
-
onAbort: (callback) => {
|
|
652
|
-
__privateGet(this, _fileUploadManager).registerOnAbort(fileId, callback);
|
|
653
|
-
}
|
|
654
|
-
};
|
|
655
|
-
};
|
|
656
|
-
handleFileError_fn = function(evt) {
|
|
657
|
-
const errorMessage = {
|
|
658
|
-
id: generateId(),
|
|
659
|
-
role: "assistant",
|
|
660
|
-
content: evt.detail.message,
|
|
661
|
-
timestamp: Date.now(),
|
|
662
|
-
status: "error"
|
|
663
|
-
};
|
|
664
|
-
__privateGet(this, _messageStateController).addMessage(errorMessage);
|
|
665
|
-
};
|
|
666
|
-
handleAttachmentRemove_fn = function(evt) {
|
|
667
|
-
const { filename } = evt.detail;
|
|
668
|
-
const pendingAttachment = __privateGet(this, _fileUploadManager).pendingAttachments.find((a) => a.filename === filename);
|
|
669
|
-
if (pendingAttachment) {
|
|
670
|
-
__privateGet(this, _fileUploadManager).abort(pendingAttachment.id);
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
const completedAttachment = __privateGet(this, _fileUploadManager).completedAttachments.find((a) => a.filename === filename);
|
|
674
|
-
if (completedAttachment && completedAttachment.fileId) {
|
|
675
|
-
__privateGet(this, _fileUploadManager).removeCompletedAttachment(completedAttachment.id);
|
|
676
|
-
this.requestUpdate();
|
|
677
|
-
this.adapter?.emitFileRemove(completedAttachment.fileId, {
|
|
678
|
-
onSuccess: () => {
|
|
679
|
-
},
|
|
680
|
-
onError: (error) => {
|
|
681
|
-
console.error(`Failed to remove file ${filename}:`, error);
|
|
682
|
-
}
|
|
683
|
-
});
|
|
684
|
-
}
|
|
685
|
-
};
|
|
686
|
-
handleSuggestionSelect_fn = async function(evt) {
|
|
687
|
-
__privateGet(this, _promptRef).value?.addToHistory(evt.detail.text);
|
|
688
|
-
await this.sendMessage(evt.detail.text);
|
|
689
|
-
__privateGet(this, _promptRef).value?.focus();
|
|
690
|
-
};
|
|
691
|
-
handleVoiceInputResult_fn = function(evt) {
|
|
692
|
-
const { transcript } = evt.detail;
|
|
693
|
-
if (transcript && __privateGet(this, _promptRef).value) {
|
|
694
|
-
__privateGet(this, _promptRef).value.value = transcript;
|
|
695
|
-
}
|
|
696
|
-
};
|
|
697
101
|
handleHeaderExpand_fn = function() {
|
|
698
|
-
|
|
102
|
+
this._dispatchHostEvent({ type: "forge-ai-chatbot-expand" });
|
|
699
103
|
};
|
|
700
104
|
handleHeaderMinimize_fn = function() {
|
|
701
|
-
|
|
105
|
+
this._dispatchHostEvent({ type: "forge-ai-chatbot-minimize" });
|
|
702
106
|
};
|
|
703
107
|
handleHeaderClear_fn = function() {
|
|
704
|
-
|
|
705
|
-
if (!event.defaultPrevented) {
|
|
706
|
-
this.clearMessages();
|
|
707
|
-
}
|
|
108
|
+
this.clearMessages();
|
|
708
109
|
};
|
|
709
110
|
handleHeaderInfo_fn = function() {
|
|
710
|
-
|
|
711
|
-
if (header?.showAgentInfo) {
|
|
712
|
-
header.showAgentInfo();
|
|
713
|
-
}
|
|
714
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, { type: "forge-ai-chatbot-info" });
|
|
715
|
-
};
|
|
716
|
-
handleAgentChange_fn = function(event) {
|
|
717
|
-
const { agent, previousAgentId } = event.detail;
|
|
718
|
-
const changeEvt = __privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, {
|
|
719
|
-
type: "forge-ai-chatbot-agent-change",
|
|
720
|
-
detail: { agent, previousAgentId }
|
|
721
|
-
});
|
|
722
|
-
if (!changeEvt.defaultPrevented) {
|
|
723
|
-
this.selectedAgentId = agent?.id;
|
|
724
|
-
if (this.adapter) {
|
|
725
|
-
this.adapter.threadId = generateId();
|
|
726
|
-
}
|
|
727
|
-
if (__privateGet(this, _AiChatbotComponent_instances, hasMessages_get)) {
|
|
728
|
-
const agentName = agent?.name ?? this.titleText;
|
|
729
|
-
const systemMessage = {
|
|
730
|
-
id: generateId(),
|
|
731
|
-
role: "system",
|
|
732
|
-
content: `Switched to ${agentName}`,
|
|
733
|
-
timestamp: Date.now(),
|
|
734
|
-
status: "complete",
|
|
735
|
-
clientOnly: true
|
|
736
|
-
};
|
|
737
|
-
__privateGet(this, _messageStateController).addMessage(systemMessage);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
};
|
|
741
|
-
handleDebugToggle_fn = function() {
|
|
742
|
-
this.debugMode = !this.debugMode;
|
|
743
|
-
};
|
|
744
|
-
handleSlashCommand_fn = function(evt) {
|
|
745
|
-
const commandId = evt.detail.commandId;
|
|
746
|
-
switch (commandId) {
|
|
747
|
-
case "clear":
|
|
748
|
-
__privateMethod(this, _AiChatbotComponent_instances, handleHeaderClear_fn).call(this);
|
|
749
|
-
break;
|
|
750
|
-
case "export":
|
|
751
|
-
__privateMethod(this, _AiChatbotComponent_instances, handleExport_fn).call(this);
|
|
752
|
-
break;
|
|
753
|
-
case "info":
|
|
754
|
-
__privateMethod(this, _AiChatbotComponent_instances, handleHeaderInfo_fn).call(this);
|
|
755
|
-
break;
|
|
756
|
-
case "debug":
|
|
757
|
-
__privateMethod(this, _AiChatbotComponent_instances, handleDebugToggle_fn).call(this);
|
|
758
|
-
break;
|
|
759
|
-
}
|
|
760
|
-
};
|
|
761
|
-
formatToolCallForExport_fn = function(toolCall) {
|
|
762
|
-
const lines = [` Tool: ${toolCall.name}`, ` Args: ${JSON.stringify(toolCall.args)}`];
|
|
763
|
-
if (toolCall.status === "error") {
|
|
764
|
-
const errorMsg = typeof toolCall.result === "object" && toolCall.result !== null && "error" in toolCall.result ? toolCall.result.error : "Unknown error";
|
|
765
|
-
lines.push(` Error: ${errorMsg}`);
|
|
766
|
-
} else if (toolCall.result !== void 0) {
|
|
767
|
-
lines.push(` Result: ${JSON.stringify(toolCall.result)}`);
|
|
768
|
-
}
|
|
769
|
-
return lines.join("\n");
|
|
770
|
-
};
|
|
771
|
-
handleExport_fn = function() {
|
|
772
|
-
const messages = this.getMessages();
|
|
773
|
-
if (messages.length === 0) {
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
776
|
-
const chatText = messages.map((message) => {
|
|
777
|
-
const timestamp = new Date(message.timestamp).toLocaleString();
|
|
778
|
-
const role = message.role === "user" ? "You" : "Assistant";
|
|
779
|
-
let output = `[${timestamp}] ${role}:
|
|
780
|
-
${message.content}
|
|
781
|
-
`;
|
|
782
|
-
if (message.toolCalls?.length) {
|
|
783
|
-
output += "\n" + message.toolCalls.map((tc) => __privateMethod(this, _AiChatbotComponent_instances, formatToolCallForExport_fn).call(this, tc)).join("\n\n") + "\n";
|
|
784
|
-
}
|
|
785
|
-
return output;
|
|
786
|
-
}).join("\n");
|
|
787
|
-
const filename = `chat-history-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace(/:/g, "-")}.txt`;
|
|
788
|
-
downloadFile(chatText, filename, "text/plain");
|
|
111
|
+
this._handleInfo();
|
|
789
112
|
};
|
|
790
113
|
sessionFilesTemplate_get = function() {
|
|
791
|
-
const
|
|
792
|
-
|
|
793
|
-
const allFiles = [...uploading, ...completed];
|
|
794
|
-
if (allFiles.length === 0) {
|
|
114
|
+
const content = this._sessionFilesTemplate;
|
|
115
|
+
if (content === nothing) {
|
|
795
116
|
return nothing;
|
|
796
117
|
}
|
|
797
|
-
return html
|
|
798
|
-
<div class="session-files" slot="attachments">
|
|
799
|
-
<div class="session-files-header">Session Files (${allFiles.length})</div>
|
|
800
|
-
<div class="session-files-list">
|
|
801
|
-
${allFiles.map(
|
|
802
|
-
(attachment) => html`
|
|
803
|
-
<forge-ai-attachment
|
|
804
|
-
.filename=${attachment.filename}
|
|
805
|
-
.size=${attachment.size}
|
|
806
|
-
?uploading=${attachment.uploading ?? false}
|
|
807
|
-
removable
|
|
808
|
-
@forge-ai-attachment-remove=${__privateMethod(this, _AiChatbotComponent_instances, handleAttachmentRemove_fn)}>
|
|
809
|
-
</forge-ai-attachment>
|
|
810
|
-
`
|
|
811
|
-
)}
|
|
812
|
-
</div>
|
|
813
|
-
</div>
|
|
814
|
-
`;
|
|
118
|
+
return html`<div class="session-files" slot="attachments">${content}</div>`;
|
|
815
119
|
};
|
|
816
120
|
promptSlot_get = function() {
|
|
817
|
-
const isUploading =
|
|
121
|
+
const isUploading = this._isUploading;
|
|
818
122
|
return html`
|
|
819
123
|
<forge-ai-prompt
|
|
820
|
-
${ref(
|
|
124
|
+
${ref(this._promptRef)}
|
|
821
125
|
slot="prompt"
|
|
822
126
|
.placeholder=${this.placeholder}
|
|
823
|
-
.running=${
|
|
824
|
-
.slashCommands=${
|
|
127
|
+
.running=${this._isStreaming || isUploading}
|
|
128
|
+
.slashCommands=${this._slashCommands}
|
|
825
129
|
?disabled=${isUploading}
|
|
826
130
|
?debug-mode=${this.debugMode}
|
|
827
|
-
@forge-ai-prompt-send=${
|
|
828
|
-
@forge-ai-prompt-stop=${
|
|
829
|
-
@forge-ai-prompt-cancel=${
|
|
830
|
-
@forge-ai-prompt-debug-toggle=${
|
|
831
|
-
@forge-ai-prompt-command=${
|
|
131
|
+
@forge-ai-prompt-send=${this._handleSend}
|
|
132
|
+
@forge-ai-prompt-stop=${this._handleStop}
|
|
133
|
+
@forge-ai-prompt-cancel=${this._handleCancel}
|
|
134
|
+
@forge-ai-prompt-debug-toggle=${this._handleDebugToggle}
|
|
135
|
+
@forge-ai-prompt-command=${this._handleSlashCommand}>
|
|
832
136
|
${when(
|
|
833
137
|
this.fileUpload === "on",
|
|
834
138
|
() => html`
|
|
@@ -837,16 +141,16 @@ promptSlot_get = function() {
|
|
|
837
141
|
variant="icon-button"
|
|
838
142
|
multiple
|
|
839
143
|
?disabled=${isUploading}
|
|
840
|
-
.selectedFiles=${
|
|
841
|
-
@forge-ai-file-picker-change=${
|
|
842
|
-
@forge-ai-file-picker-error=${
|
|
144
|
+
.selectedFiles=${this._coreController?.pendingAttachments.map((a) => a.filename) ?? []}
|
|
145
|
+
@forge-ai-file-picker-change=${this._handleFileSelect}
|
|
146
|
+
@forge-ai-file-picker-error=${this._handleFileError}>
|
|
843
147
|
</forge-ai-file-picker>
|
|
844
148
|
`
|
|
845
149
|
)}
|
|
846
150
|
${when(
|
|
847
151
|
this.voiceInput === "on",
|
|
848
152
|
() => html`
|
|
849
|
-
<forge-ai-voice-input slot="actions-end" @forge-ai-voice-input-result=${
|
|
153
|
+
<forge-ai-voice-input slot="actions-end" @forge-ai-voice-input-result=${this._handleVoiceInputResult}>
|
|
850
154
|
</forge-ai-voice-input>
|
|
851
155
|
`
|
|
852
156
|
)}
|
|
@@ -856,69 +160,32 @@ promptSlot_get = function() {
|
|
|
856
160
|
messageThread_get = function() {
|
|
857
161
|
return html`
|
|
858
162
|
<forge-ai-message-thread
|
|
859
|
-
${ref(
|
|
860
|
-
.messageItems=${
|
|
861
|
-
.tools=${
|
|
163
|
+
${ref(this._messageThreadRef)}
|
|
164
|
+
.messageItems=${this._messageItems}
|
|
165
|
+
.tools=${this._tools}
|
|
862
166
|
?enable-reactions=${this.enableReactions}
|
|
863
|
-
?show-thinking=${
|
|
167
|
+
?show-thinking=${this._isStreaming}
|
|
864
168
|
?debug-mode=${this.debugMode}
|
|
865
|
-
@forge-ai-message-thread-copy=${
|
|
866
|
-
@forge-ai-message-thread-resend=${
|
|
867
|
-
@forge-ai-message-thread-thumbs-up=${
|
|
868
|
-
@forge-ai-message-thread-thumbs-down=${
|
|
869
|
-
@forge-ai-message-thread-user-copy=${
|
|
870
|
-
@forge-ai-message-thread-user-resend=${
|
|
871
|
-
@forge-ai-message-thread-user-edit=${
|
|
169
|
+
@forge-ai-message-thread-copy=${this._handleCopy}
|
|
170
|
+
@forge-ai-message-thread-resend=${this._handleResend}
|
|
171
|
+
@forge-ai-message-thread-thumbs-up=${this._handleThumbsUp}
|
|
172
|
+
@forge-ai-message-thread-thumbs-down=${this._handleThumbsDown}
|
|
173
|
+
@forge-ai-message-thread-user-copy=${this._handleUserCopy}
|
|
174
|
+
@forge-ai-message-thread-user-resend=${this._handleUserResend}
|
|
175
|
+
@forge-ai-message-thread-user-edit=${this._handleUserEdit}>
|
|
872
176
|
<slot name="empty-state-heading" slot="empty-state-heading"></slot>
|
|
873
177
|
<slot name="empty-state-message" slot="empty-state-message"></slot>
|
|
874
178
|
<div class="suggestions-container" slot="empty-state-actions">
|
|
875
179
|
<forge-ai-suggestions
|
|
876
180
|
variant="block"
|
|
877
181
|
.suggestions=${this.suggestions ?? []}
|
|
878
|
-
@forge-ai-suggestions-select=${
|
|
182
|
+
@forge-ai-suggestions-select=${this._handleSuggestionSelect}>
|
|
879
183
|
</forge-ai-suggestions>
|
|
880
184
|
</div>
|
|
881
185
|
</forge-ai-message-thread>
|
|
882
186
|
`;
|
|
883
187
|
};
|
|
884
|
-
dispatchEvent_fn = function(config) {
|
|
885
|
-
const event = new CustomEvent(config.type, {
|
|
886
|
-
detail: config.detail,
|
|
887
|
-
bubbles: true,
|
|
888
|
-
composed: true,
|
|
889
|
-
cancelable: config.cancelable ?? false
|
|
890
|
-
});
|
|
891
|
-
this.dispatchEvent(event);
|
|
892
|
-
return event;
|
|
893
|
-
};
|
|
894
|
-
dispatchMessageEvent_fn = function(type, messageOrId) {
|
|
895
|
-
const message = typeof messageOrId === "string" ? __privateGet(this, _messageStateController).getMessage(messageOrId) : messageOrId;
|
|
896
|
-
if (message) {
|
|
897
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, { type, detail: { message } });
|
|
898
|
-
}
|
|
899
|
-
};
|
|
900
|
-
emitStateChange_fn = function() {
|
|
901
|
-
__privateMethod(this, _AiChatbotComponent_instances, dispatchEvent_fn).call(this, { type: "forge-ai-chatbot-thread-state-change" });
|
|
902
|
-
};
|
|
903
188
|
AiChatbotComponent.styles = unsafeCSS(styles);
|
|
904
|
-
__decorateClass([
|
|
905
|
-
property({ attribute: false })
|
|
906
|
-
], AiChatbotComponent.prototype, "adapter", 2);
|
|
907
|
-
__decorateClass([
|
|
908
|
-
property({ attribute: "file-upload" })
|
|
909
|
-
], AiChatbotComponent.prototype, "fileUpload", 2);
|
|
910
|
-
__decorateClass([
|
|
911
|
-
property({ attribute: "voice-input" })
|
|
912
|
-
], AiChatbotComponent.prototype, "voiceInput", 2);
|
|
913
|
-
__decorateClass([
|
|
914
|
-
property({ attribute: "debug-command" })
|
|
915
|
-
], AiChatbotComponent.prototype, "debugCommand", 2);
|
|
916
|
-
__decorateClass([
|
|
917
|
-
property()
|
|
918
|
-
], AiChatbotComponent.prototype, "placeholder", 2);
|
|
919
|
-
__decorateClass([
|
|
920
|
-
property({ attribute: false })
|
|
921
|
-
], AiChatbotComponent.prototype, "suggestions", 2);
|
|
922
189
|
__decorateClass([
|
|
923
190
|
property({ type: Boolean, attribute: "show-expand-button" })
|
|
924
191
|
], AiChatbotComponent.prototype, "showExpandButton", 2);
|
|
@@ -931,30 +198,6 @@ __decorateClass([
|
|
|
931
198
|
__decorateClass([
|
|
932
199
|
property({ attribute: "minimize-icon" })
|
|
933
200
|
], AiChatbotComponent.prototype, "minimizeIcon", 2);
|
|
934
|
-
__decorateClass([
|
|
935
|
-
property({ type: Boolean, attribute: "enable-reactions" })
|
|
936
|
-
], AiChatbotComponent.prototype, "enableReactions", 2);
|
|
937
|
-
__decorateClass([
|
|
938
|
-
property({ type: Object, attribute: false })
|
|
939
|
-
], AiChatbotComponent.prototype, "agentInfo", 2);
|
|
940
|
-
__decorateClass([
|
|
941
|
-
property({ attribute: "title-text" })
|
|
942
|
-
], AiChatbotComponent.prototype, "titleText", 2);
|
|
943
|
-
__decorateClass([
|
|
944
|
-
property({ attribute: "heading-level", type: Number })
|
|
945
|
-
], AiChatbotComponent.prototype, "headingLevel", 2);
|
|
946
|
-
__decorateClass([
|
|
947
|
-
property({ type: Boolean, attribute: "debug-mode" })
|
|
948
|
-
], AiChatbotComponent.prototype, "debugMode", 2);
|
|
949
|
-
__decorateClass([
|
|
950
|
-
property({ attribute: "disclaimer-text" })
|
|
951
|
-
], AiChatbotComponent.prototype, "disclaimerText", 2);
|
|
952
|
-
__decorateClass([
|
|
953
|
-
property({ attribute: false })
|
|
954
|
-
], AiChatbotComponent.prototype, "agents", 2);
|
|
955
|
-
__decorateClass([
|
|
956
|
-
property({ attribute: "selected-agent-id" })
|
|
957
|
-
], AiChatbotComponent.prototype, "selectedAgentId", 2);
|
|
958
201
|
AiChatbotComponent = __decorateClass([
|
|
959
202
|
customElement(AiChatbotComponentTagName)
|
|
960
203
|
], AiChatbotComponent);
|