impact-chatbot 3.1.0 → 3.1.1
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/index.esm.js
CHANGED
|
@@ -761,6 +761,30 @@ const uploadFile = async (payload) => {
|
|
|
761
761
|
return null;
|
|
762
762
|
}
|
|
763
763
|
};
|
|
764
|
+
/** Saves a skill for the signed-in user: its SKILL.md and the files it refers to, each keyed by its path in
|
|
765
|
+
* the skill's folder ({"SKILL.md": text, "references/x.md": text}). The agent checks it as its harness would
|
|
766
|
+
* serve it and answers {name, version, characters, files, missing_files, trigger, trigger_said, turn_on}; a
|
|
767
|
+
* skill it refuses is a 422 whose detail says why. Errors reach the caller, which shows them. */
|
|
768
|
+
const uploadSkill = async (files, baseUrl) => {
|
|
769
|
+
return axiosInstance({
|
|
770
|
+
url: `${baseUrl}/chatbot/agent/skills`,
|
|
771
|
+
method: 'POST',
|
|
772
|
+
data: { files },
|
|
773
|
+
});
|
|
774
|
+
};
|
|
775
|
+
/** Whether the agent takes skill uploads: its /info answer carries skills.upload beside the cards. Any
|
|
776
|
+
* failure, or an agent that does not say so, is false (no "Upload Skill" item). */
|
|
777
|
+
const fetchSkillUploadOn = async (baseUrl) => {
|
|
778
|
+
try {
|
|
779
|
+
const response = await fetchAgentsInfo(baseUrl);
|
|
780
|
+
const body = response?.data || {};
|
|
781
|
+
return body?.skills?.upload === true || body?.data?.skills?.upload === true;
|
|
782
|
+
}
|
|
783
|
+
catch (error) {
|
|
784
|
+
console.error('fetchSkillUploadOn error:', error);
|
|
785
|
+
return false;
|
|
786
|
+
}
|
|
787
|
+
};
|
|
764
788
|
const triggerRefresh = async (baseUrl) => {
|
|
765
789
|
try {
|
|
766
790
|
return httpRequest({
|
|
@@ -824,7 +848,7 @@ const getTableRecords = async (payload, baseUrl, tableName) => {
|
|
|
824
848
|
* user and answers {rows, total}. */
|
|
825
849
|
const postUiQuery = async (payload, baseUrl) => {
|
|
826
850
|
try {
|
|
827
|
-
return
|
|
851
|
+
return httpRequest({
|
|
828
852
|
url: `${baseUrl}/chatbot/agent/ui-query`,
|
|
829
853
|
method: 'POST',
|
|
830
854
|
data: payload,
|
|
@@ -14122,6 +14146,109 @@ function UploadModal(props) {
|
|
|
14122
14146
|
return (jsx(Modal, { onClose: handleModalClose, onPrimaryButtonClick: handleFileUpload, onSecondaryButtonClick: handleModalClose, open: isUploadModalOpen, size: "small", title: "Upload Document", primaryButtonLabel: "Upload", secondaryButtonLabel: "Cancel", primaryButtonProps: { disabled: isLoading }, secondaryButtonProps: { disabled: isLoading }, children: isLoading ? (jsx(Loader, { text: "Uploading file..." })) : (jsxs("div", { className: classes.uploadModalInnerSec, children: [jsx("input", { type: "file", ref: fileInputRef, onChange: handleFileSelect, accept: ".pdf", style: { display: "none" }, disabled: isLoading }), jsx(Button, { onClick: () => fileInputRef.current.click(), variant: "outlined", disabled: isLoading, children: "Select PDF File" }), selectedFile && (jsxs("p", { style: { marginTop: "10px" }, children: ["Selected File: ", selectedFile.name] }))] })) }));
|
|
14123
14147
|
}
|
|
14124
14148
|
|
|
14149
|
+
/** A skill is a folder: SKILL.md (its name and description, then its steps) and the files it refers to, such
|
|
14150
|
+
* as references/mcp-contracts.md. Picked files are read here as text, keyed by their path in that folder,
|
|
14151
|
+
* and saved for the signed-in user by the agent (POST {baseUrl}/chatbot/agent/skills). Unlike a paste into
|
|
14152
|
+
* the chat, an upload keeps the line breaks and the skill's other files. */
|
|
14153
|
+
const MAX_FILES = 50;
|
|
14154
|
+
const TEXT_EXTENSIONS = [".md", ".txt", ".json", ".yaml", ".yml", ".csv"];
|
|
14155
|
+
const isSkillFile = (path) => path === "SKILL.md" || path.endsWith("/SKILL.md");
|
|
14156
|
+
const isText = (name) => TEXT_EXTENSIONS.some((ext) => name.toLowerCase().endsWith(ext));
|
|
14157
|
+
/** What the agent answered; a 200 may be the object itself or wrapped as {data: {...}}. */
|
|
14158
|
+
const savedOf = (response) => response?.data?.data || response?.data || {};
|
|
14159
|
+
/** Why the agent did not save it: the 422's detail ("not saved: ..."), else the message or status. */
|
|
14160
|
+
const whyNot = (error) => {
|
|
14161
|
+
const body = error?.response?.data;
|
|
14162
|
+
const said = body?.detail || body?.message || body?.data?.detail;
|
|
14163
|
+
if (typeof said === "string" && said)
|
|
14164
|
+
return said;
|
|
14165
|
+
if (said)
|
|
14166
|
+
return JSON.stringify(said);
|
|
14167
|
+
return error?.response?.status ? `the agent answered ${error.response.status}` : String(error?.message || error);
|
|
14168
|
+
};
|
|
14169
|
+
function SkillUploadModal(props) {
|
|
14170
|
+
const { isOpen, setIsOpen, baseUrl, displaySnackMessages, onUseText } = props;
|
|
14171
|
+
const [picked, setPicked] = useState({});
|
|
14172
|
+
const [skipped, setSkipped] = useState(0);
|
|
14173
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
14174
|
+
const [saved, setSaved] = useState(null);
|
|
14175
|
+
const [error, setError] = useState("");
|
|
14176
|
+
const folderRef = useRef(null);
|
|
14177
|
+
const filesRef = useRef(null);
|
|
14178
|
+
const classes = useStyles$b();
|
|
14179
|
+
const reset = () => {
|
|
14180
|
+
setPicked({});
|
|
14181
|
+
setSkipped(0);
|
|
14182
|
+
setSaved(null);
|
|
14183
|
+
setError("");
|
|
14184
|
+
};
|
|
14185
|
+
const handleClose = () => {
|
|
14186
|
+
if (isSaving)
|
|
14187
|
+
return;
|
|
14188
|
+
setIsOpen(false);
|
|
14189
|
+
reset();
|
|
14190
|
+
};
|
|
14191
|
+
const take = async (list) => {
|
|
14192
|
+
if (!list)
|
|
14193
|
+
return;
|
|
14194
|
+
const next = { ...picked };
|
|
14195
|
+
let left = 0;
|
|
14196
|
+
for (const file of Array.from(list)) {
|
|
14197
|
+
const path = file.webkitRelativePath || file.name;
|
|
14198
|
+
if (!isText(file.name)) {
|
|
14199
|
+
left += 1; // a folder may hold images or .DS_Store: only text files are a skill's
|
|
14200
|
+
continue;
|
|
14201
|
+
}
|
|
14202
|
+
if (!(path in next) && Object.keys(next).length >= MAX_FILES) {
|
|
14203
|
+
displaySnackMessages(`A skill can have at most ${MAX_FILES} files`, "error");
|
|
14204
|
+
break;
|
|
14205
|
+
}
|
|
14206
|
+
next[path] = await file.text();
|
|
14207
|
+
}
|
|
14208
|
+
setPicked(next);
|
|
14209
|
+
setSkipped(skipped + left);
|
|
14210
|
+
setSaved(null);
|
|
14211
|
+
setError("");
|
|
14212
|
+
};
|
|
14213
|
+
const paths = Object.keys(picked);
|
|
14214
|
+
const hasSkill = paths.some(isSkillFile);
|
|
14215
|
+
const handleSave = async () => {
|
|
14216
|
+
if (!hasSkill) {
|
|
14217
|
+
displaySnackMessages("Pick the skill's SKILL.md (or its folder) first", "error");
|
|
14218
|
+
return;
|
|
14219
|
+
}
|
|
14220
|
+
try {
|
|
14221
|
+
setIsSaving(true);
|
|
14222
|
+
setError("");
|
|
14223
|
+
const response = await uploadSkill(picked, baseUrl);
|
|
14224
|
+
setSaved(savedOf(response));
|
|
14225
|
+
displaySnackMessages("Skill saved", "success");
|
|
14226
|
+
}
|
|
14227
|
+
catch (err) {
|
|
14228
|
+
console.error("uploadSkill error:", err);
|
|
14229
|
+
setError(whyNot(err));
|
|
14230
|
+
}
|
|
14231
|
+
finally {
|
|
14232
|
+
setIsSaving(false);
|
|
14233
|
+
}
|
|
14234
|
+
};
|
|
14235
|
+
const use = (text) => {
|
|
14236
|
+
onUseText?.(text);
|
|
14237
|
+
setIsOpen(false);
|
|
14238
|
+
reset();
|
|
14239
|
+
};
|
|
14240
|
+
const files = saved?.files || [];
|
|
14241
|
+
const missing = saved?.missing_files || [];
|
|
14242
|
+
const runText = saved?.name ? `Run skill ${saved.name} in Preview mode` : "";
|
|
14243
|
+
return (jsx(Modal, { onClose: handleClose, onPrimaryButtonClick: saved ? handleClose : handleSave, onSecondaryButtonClick: handleClose, open: isOpen, size: "small", title: "Upload Skill", primaryButtonLabel: saved ? "Done" : "Save the skill", secondaryButtonLabel: "Cancel", primaryButtonProps: { disabled: isSaving || (!saved && !hasSkill) }, secondaryButtonProps: { disabled: isSaving }, children: isSaving ? (jsx(Loader, { text: "Saving the skill..." })) : saved ? (jsxs("div", { style: { padding: "16px 20px", lineHeight: 1.5 }, children: [jsxs("p", { style: { margin: "0 0 8px" }, children: ["Saved ", jsx("b", { children: saved.name }), " (version ", saved.version, typeof saved.characters === "number" ? `, ${saved.characters.toLocaleString()} characters` : "", files.length ? `, with ${files.join(", ")}` : "", ")."] }), missing.length > 0 && (jsxs("p", { style: { margin: "0 0 8px" }, children: ["It refers to ", missing.join(", "), ", which was not uploaded."] })), saved.trigger && (jsxs("p", { style: { margin: "0 0 8px" }, children: ["It has a trigger: it ", saved.trigger_said, ". It is not on yet. To turn it on, send Iris:", " ", jsx("i", { children: saved.turn_on })] })), jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap", marginTop: "12px" }, children: [runText && (jsxs(Button, { variant: "outlined", onClick: () => use(runText), children: ["Put \"", runText, "\" in the chat"] })), saved.trigger && saved.turn_on && (jsxs(Button, { variant: "outlined", onClick: () => use(saved.turn_on), children: ["Put \"", saved.turn_on, "\" in the chat"] }))] })] })) : (jsxs("div", { className: classes.uploadModalInnerSec, style: { height: "auto", minHeight: "150px" }, children: [jsx("input", { type: "file", ref: folderRef, onChange: (e) => {
|
|
14244
|
+
take(e.target.files);
|
|
14245
|
+
e.target.value = "";
|
|
14246
|
+
}, style: { display: "none" }, multiple: true, ...{ webkitdirectory: "", directory: "" } }), jsx("input", { type: "file", ref: filesRef, onChange: (e) => {
|
|
14247
|
+
take(e.target.files);
|
|
14248
|
+
e.target.value = "";
|
|
14249
|
+
}, style: { display: "none" }, multiple: true, accept: TEXT_EXTENSIONS.join(",") }), jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap", justifyContent: "center" }, children: [jsx(Button, { variant: "outlined", onClick: () => folderRef.current?.click(), children: "Pick the skill's folder" }), jsx(Button, { variant: "outlined", onClick: () => filesRef.current?.click(), children: "Pick its files" })] }), paths.length > 0 ? (jsxs("div", { style: { marginTop: "12px", width: "100%" }, children: [jsx("ul", { style: { margin: 0, paddingLeft: "18px", maxHeight: "140px", overflowY: "auto" }, children: paths.map((path) => (jsx("li", { children: path }, path))) }), !hasSkill && jsx("p", { style: { margin: "8px 0 0" }, children: "No SKILL.md picked yet." }), skipped > 0 && (jsxs("p", { style: { margin: "8px 0 0" }, children: [skipped, " file", skipped === 1 ? " was" : "s were", " left out: a skill's files are text (", TEXT_EXTENSIONS.join(" "), ")."] }))] })) : (jsx("p", { style: { marginTop: "12px", textAlign: "center" }, children: "A skill is a SKILL.md and any files it refers to. Once saved, ask Iris to run it by name, now or on a schedule." })), error && jsxs("p", { style: { marginTop: "10px", color: "#b42318" }, children: ["Not saved: ", error.replace(/^not saved:\s*/i, "")] })] })) }));
|
|
14250
|
+
}
|
|
14251
|
+
|
|
14125
14252
|
const useStyles$2 = makeStyles(() => ({
|
|
14126
14253
|
input: {
|
|
14127
14254
|
width: "100%",
|
|
@@ -18005,6 +18132,9 @@ const SmartBot = (props) => {
|
|
|
18005
18132
|
useState(false);
|
|
18006
18133
|
useState(false);
|
|
18007
18134
|
const [conversation, setConversation] = useState({});
|
|
18135
|
+
// "Upload Skill": offered only when the agent's /info says skills.upload (asked once per base URL)
|
|
18136
|
+
const [skillUploadOn, setSkillUploadOn] = useState(false);
|
|
18137
|
+
const [isSkillUploadOpen, setIsSkillUploadOpen] = useState(false);
|
|
18008
18138
|
const { chatbotContext, currentAgentChatId, minimizedStreamData } = useSelector((state) => state.smartBotReducer);
|
|
18009
18139
|
const savedFilterDashboard = useSelector(selectors?.getSavedFilterDashboard ?? NULL_SELECTOR);
|
|
18010
18140
|
// Per-mode conversation ID tracking — prevents cross-mode contamination when
|
|
@@ -18563,6 +18693,29 @@ const SmartBot = (props) => {
|
|
|
18563
18693
|
useEffect(() => {
|
|
18564
18694
|
fetchCustomBotConfigurations();
|
|
18565
18695
|
}, [baseUrl]);
|
|
18696
|
+
useEffect(() => {
|
|
18697
|
+
let live = true;
|
|
18698
|
+
if (!baseUrl) {
|
|
18699
|
+
setSkillUploadOn(false);
|
|
18700
|
+
return;
|
|
18701
|
+
}
|
|
18702
|
+
fetchSkillUploadOn(baseUrl).then((on) => {
|
|
18703
|
+
if (live)
|
|
18704
|
+
setSkillUploadOn(on);
|
|
18705
|
+
});
|
|
18706
|
+
return () => {
|
|
18707
|
+
live = false;
|
|
18708
|
+
};
|
|
18709
|
+
}, [baseUrl]);
|
|
18710
|
+
// kept apart from utilityList: handleUploadAccess sets that list from its first value once its access
|
|
18711
|
+
// check returns, which would drop an item added meanwhile
|
|
18712
|
+
const skillUploadItem = {
|
|
18713
|
+
key: "Upload Skill",
|
|
18714
|
+
onClick: () => {
|
|
18715
|
+
setIsSkillUploadOpen(true);
|
|
18716
|
+
},
|
|
18717
|
+
icon: (jsx("div", { className: classes.memoryModalIconDiv, children: jsx(SvgUploadIcon, { style: { width: 20, height: 20 } }) })),
|
|
18718
|
+
};
|
|
18566
18719
|
// Sync showModal state with props.showModal OR props.invokeBot (backward compatibility)
|
|
18567
18720
|
// Host app passes showModal prop, but some integrations may use invokeBot
|
|
18568
18721
|
useEffect(() => {
|
|
@@ -19220,7 +19373,7 @@ const SmartBot = (props) => {
|
|
|
19220
19373
|
return (jsxs(Fragment, { children: [partialClose && (minimizedStreamData?.isStreaming || minimizedStreamData?.stepStatus === "step_form") && (jsx(MinimizedChatWidget, { onExpand: () => {
|
|
19221
19374
|
setShowModal(true);
|
|
19222
19375
|
setPartialClose(false);
|
|
19223
|
-
} })), jsxs("div", { ref: smartBotWrapperRef, className: `${classes.agentStyleOverride} ${partialClose || !(showModal || forceOpen) ? classes.hideBotStyle : ""} `, children: [jsx(RenameModal, { open: renameOpen, renameValue: renameValue, setRenameValue: setRenameValue, onConfirm: handleRenameConfirm, onCancel: handleRenameCancel }), jsx(DeleteConfirmModal, { open: deleteOpen, onConfirm: handleDeleteConfirm, onCancel: handleDeleteCancel }), jsx(MemoryModal, { isModalOpen: isModalOpen, setIsModalOpen: setIsModalOpen, displaySnackMessages: displaySnackMessages }), jsx(UploadModal, { isUploadModalOpen: isUploadModalOpen, setIsUploadModalOpen: setIsUploadModalOpen, displaySnackMessages: displaySnackMessages }), jsx(ChatBotComponent, { isFullWidth: forceOpen, userName: userName, showHistoryPanel: enableMultiChat, isConversationLoading: conversationLoading, customInputComponent: currentMode === "agent" && !showSavedFilters ? (jsx(ChatbotInput, { newChatScreen: newChatScreen, inputValue: userInput, setInputValue: setUserInput, isStopIcon: isStop, onSendIconClick: onSendIconClick, onStopIconClick: onStopIconClick, currentMode: currentMode, filterOptions: filterOptions,
|
|
19376
|
+
} })), jsxs("div", { ref: smartBotWrapperRef, className: `${classes.agentStyleOverride} ${partialClose || !(showModal || forceOpen) ? classes.hideBotStyle : ""} `, children: [jsx(RenameModal, { open: renameOpen, renameValue: renameValue, setRenameValue: setRenameValue, onConfirm: handleRenameConfirm, onCancel: handleRenameCancel }), jsx(DeleteConfirmModal, { open: deleteOpen, onConfirm: handleDeleteConfirm, onCancel: handleDeleteCancel }), jsx(MemoryModal, { isModalOpen: isModalOpen, setIsModalOpen: setIsModalOpen, displaySnackMessages: displaySnackMessages }), jsx(UploadModal, { isUploadModalOpen: isUploadModalOpen, setIsUploadModalOpen: setIsUploadModalOpen, displaySnackMessages: displaySnackMessages }), skillUploadOn && (jsx(SkillUploadModal, { isOpen: isSkillUploadOpen, setIsOpen: setIsSkillUploadOpen, baseUrl: baseUrl, displaySnackMessages: displaySnackMessages, onUseText: (text) => setUserInput(text) })), jsx(ChatBotComponent, { isFullWidth: forceOpen, userName: userName, showHistoryPanel: enableMultiChat, isConversationLoading: conversationLoading, customInputComponent: currentMode === "agent" && !showSavedFilters ? (jsx(ChatbotInput, { newChatScreen: newChatScreen, inputValue: userInput, setInputValue: setUserInput, isStopIcon: isStop, onSendIconClick: onSendIconClick, onStopIconClick: onStopIconClick, currentMode: currentMode, filterOptions: filterOptions,
|
|
19224
19377
|
// onSaveClick={saveCurrentChat}
|
|
19225
19378
|
savedFilterSets: savedFilterSets, selectedFilterSet: selectedFilterSet, onFilterSetSelect: (filterSet) => setSelectedFilterSet(filterSet), onClearFilterSet: () => setSelectedFilterSet(null), onTriggerRefresh: triggerRefreshAction, answerMode: answerMode, setAnswerMode: setAnswerMode })) : showSavedFilters ? jsx(Fragment, {}) : null, isChatBotOpen: showModal || forceOpen, historyPanelData: historyPanelData, onHistorySearchChange: (params) => { console.log("History Search Change", params); }, onHistorySelectConversation: (params) => {
|
|
19226
19379
|
const convId = params?.conversation_id;
|
|
@@ -19333,7 +19486,7 @@ const SmartBot = (props) => {
|
|
|
19333
19486
|
onSendIconClick: onSendIconClick, conversation: conversation, onModuleClick: (id, name, param) => {
|
|
19334
19487
|
// activeTab.current.activeTab = name.toLowerCase();
|
|
19335
19488
|
handleModuleSelect(name);
|
|
19336
|
-
}, moduleList: modules, tabList: tabList, utilityList: utilityList, isAssistantThinking: false, isCustomScreen: showChatPlaceholder ? showChatPlaceholder : showSavedFilters, customScreenJsx: showChatPlaceholder ?
|
|
19489
|
+
}, moduleList: modules, tabList: tabList, utilityList: skillUploadOn ? [...utilityList, skillUploadItem] : utilityList, isAssistantThinking: false, isCustomScreen: showChatPlaceholder ? showChatPlaceholder : showSavedFilters, customScreenJsx: showChatPlaceholder ?
|
|
19337
19490
|
jsx(ChatPlaceholder, { dateFormat: dateFormat, chatDataRef: chatDataRef, currentMode: currentMode, setShowChatPlaceholder: setShowChatPlaceholder, setLoader: setLoader, setCurrentAgentId: setCurrentAgentId, baseUrl: baseUrl, setBaseUrl: setBaseUrl, setCurrentSessionId: setCurrentSessionId, customChatConfig: customChatConfig, chatDataInfoRef: chatDataInfoRef, setChatDataState: setChatDataState, userInput: userInput, legacyAgentScreen: legacyAgentScreen, activeConversationId: activeConversationId, chatBodyRef: chatBodyRef, chatbotContext: chatbotContext, setInitValue: setInitValue, setSessionId: setSessionId, thinkingContent: thinkingContext?.thinkingContent, setThinkingContent: setThinkingContent, isThinking: isThinking, setIsThinking: setIsThinking, chatId: chatId, setChatId: setChatId, isStop: isStop, setIsStop: setIsStop, functionsRef: functionsRef, functionsState: functionsState, setFunctionsState: setFunctionsState, thinkingHeaderMessage: thinkingContext?.thinkingHeaderMessage, setThinkingHeaderMessage: setThinkingHeaderMessage, uniqueChatId: uniqueChatId, setUniqueChatId: setUniqueChatId, fieldNumber: fieldNumber, setFieldNumber: setFieldNumber, setAdditionalArgs: setAdditionalArgs, displayQuestions: displayQuestions, questions: questions, setActiveConversationId: setActiveConversationId, selectedFilterSet: selectedFilterSet, answerMode: answerMode })
|
|
19338
19491
|
:
|
|
19339
19492
|
components?.FilterComponent ? jsx(components.FilterComponent, { savedFilterSets: savedFilterSets, partialClose: partialClose, chatBotWidth: chatBotWidth, onSetFilterConfiguration: callbacks?.onSetFilterConfiguration }) : null, inputText: userInput, threadList: ["Home"], hideMenuArrow: true, newChatScreen: newChatScreen, isModuleListLoading: modulesLoading, suggestionBanner: {
|