impact-chatbot 2.4.1 → 2.4.2

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
@@ -248,6 +248,30 @@ const uploadFile = async (payload) => {
248
248
  return null;
249
249
  }
250
250
  };
251
+ /** Saves a skill for the signed-in user: its SKILL.md and the files it refers to, each keyed by its path in
252
+ * the skill's folder ({"SKILL.md": text, "references/x.md": text}). The agent checks it as its harness would
253
+ * serve it and answers {name, version, characters, files, missing_files, trigger, trigger_said, turn_on}; a
254
+ * skill it refuses is a 422 whose detail says why. Errors reach the caller, which shows them. */
255
+ const uploadSkill = async (files, baseUrl) => {
256
+ return axiosInstance({
257
+ url: `${baseUrl}/chatbot/agent/skills`,
258
+ method: 'POST',
259
+ data: { files },
260
+ });
261
+ };
262
+ /** Whether the agent takes skill uploads: its /info answer carries skills.upload beside the cards. Any
263
+ * failure, or an agent that does not say so, is false (no "Upload Skill" item). */
264
+ const fetchSkillUploadOn = async (baseUrl) => {
265
+ try {
266
+ const response = await fetchAgentsInfo(baseUrl);
267
+ const body = response?.data || {};
268
+ return body?.skills?.upload === true || body?.data?.skills?.upload === true;
269
+ }
270
+ catch (error) {
271
+ console.error('fetchSkillUploadOn error:', error);
272
+ return false;
273
+ }
274
+ };
251
275
  const triggerRefresh = async (baseUrl) => {
252
276
  try {
253
277
  return axiosInstance({
@@ -12839,6 +12863,109 @@ function UploadModal(props) {
12839
12863
  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] }))] })) }));
12840
12864
  }
12841
12865
 
12866
+ /** A skill is a folder: SKILL.md (its name and description, then its steps) and the files it refers to, such
12867
+ * as references/mcp-contracts.md. Picked files are read here as text, keyed by their path in that folder,
12868
+ * and saved for the signed-in user by the agent (POST {baseUrl}/chatbot/agent/skills). Unlike a paste into
12869
+ * the chat, an upload keeps the line breaks and the skill's other files. */
12870
+ const MAX_FILES = 50;
12871
+ const TEXT_EXTENSIONS = [".md", ".txt", ".json", ".yaml", ".yml", ".csv"];
12872
+ const isSkillFile = (path) => path === "SKILL.md" || path.endsWith("/SKILL.md");
12873
+ const isText = (name) => TEXT_EXTENSIONS.some((ext) => name.toLowerCase().endsWith(ext));
12874
+ /** What the agent answered; a 200 may be the object itself or wrapped as {data: {...}}. */
12875
+ const savedOf = (response) => response?.data?.data || response?.data || {};
12876
+ /** Why the agent did not save it: the 422's detail ("not saved: ..."), else the message or status. */
12877
+ const whyNot = (error) => {
12878
+ const body = error?.response?.data;
12879
+ const said = body?.detail || body?.message || body?.data?.detail;
12880
+ if (typeof said === "string" && said)
12881
+ return said;
12882
+ if (said)
12883
+ return JSON.stringify(said);
12884
+ return error?.response?.status ? `the agent answered ${error.response.status}` : String(error?.message || error);
12885
+ };
12886
+ function SkillUploadModal(props) {
12887
+ const { isOpen, setIsOpen, baseUrl, displaySnackMessages, onUseText } = props;
12888
+ const [picked, setPicked] = useState({});
12889
+ const [skipped, setSkipped] = useState(0);
12890
+ const [isSaving, setIsSaving] = useState(false);
12891
+ const [saved, setSaved] = useState(null);
12892
+ const [error, setError] = useState("");
12893
+ const folderRef = useRef(null);
12894
+ const filesRef = useRef(null);
12895
+ const classes = useStyles$b();
12896
+ const reset = () => {
12897
+ setPicked({});
12898
+ setSkipped(0);
12899
+ setSaved(null);
12900
+ setError("");
12901
+ };
12902
+ const handleClose = () => {
12903
+ if (isSaving)
12904
+ return;
12905
+ setIsOpen(false);
12906
+ reset();
12907
+ };
12908
+ const take = async (list) => {
12909
+ if (!list)
12910
+ return;
12911
+ const next = { ...picked };
12912
+ let left = 0;
12913
+ for (const file of Array.from(list)) {
12914
+ const path = file.webkitRelativePath || file.name;
12915
+ if (!isText(file.name)) {
12916
+ left += 1; // a folder may hold images or .DS_Store: only text files are a skill's
12917
+ continue;
12918
+ }
12919
+ if (!(path in next) && Object.keys(next).length >= MAX_FILES) {
12920
+ displaySnackMessages(`A skill can have at most ${MAX_FILES} files`, "error");
12921
+ break;
12922
+ }
12923
+ next[path] = await file.text();
12924
+ }
12925
+ setPicked(next);
12926
+ setSkipped(skipped + left);
12927
+ setSaved(null);
12928
+ setError("");
12929
+ };
12930
+ const paths = Object.keys(picked);
12931
+ const hasSkill = paths.some(isSkillFile);
12932
+ const handleSave = async () => {
12933
+ if (!hasSkill) {
12934
+ displaySnackMessages("Pick the skill's SKILL.md (or its folder) first", "error");
12935
+ return;
12936
+ }
12937
+ try {
12938
+ setIsSaving(true);
12939
+ setError("");
12940
+ const response = await uploadSkill(picked, baseUrl);
12941
+ setSaved(savedOf(response));
12942
+ displaySnackMessages("Skill saved", "success");
12943
+ }
12944
+ catch (err) {
12945
+ console.error("uploadSkill error:", err);
12946
+ setError(whyNot(err));
12947
+ }
12948
+ finally {
12949
+ setIsSaving(false);
12950
+ }
12951
+ };
12952
+ const use = (text) => {
12953
+ onUseText?.(text);
12954
+ setIsOpen(false);
12955
+ reset();
12956
+ };
12957
+ const files = saved?.files || [];
12958
+ const missing = saved?.missing_files || [];
12959
+ const runText = saved?.name ? `Run skill ${saved.name} in Preview mode` : "";
12960
+ 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) => {
12961
+ take(e.target.files);
12962
+ e.target.value = "";
12963
+ }, style: { display: "none" }, multiple: true, ...{ webkitdirectory: "", directory: "" } }), jsx("input", { type: "file", ref: filesRef, onChange: (e) => {
12964
+ take(e.target.files);
12965
+ e.target.value = "";
12966
+ }, 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, "")] })] })) }));
12967
+ }
12968
+
12842
12969
  const useStyles$2 = makeStyles(() => ({
12843
12970
  input: {
12844
12971
  width: "100%",
@@ -16622,6 +16749,9 @@ const SmartBot = (props) => {
16622
16749
  useState(false);
16623
16750
  useState(false);
16624
16751
  const [conversation, setConversation] = useState({});
16752
+ // "Upload Skill": offered only when the agent's /info says skills.upload (asked once per base URL)
16753
+ const [skillUploadOn, setSkillUploadOn] = useState(false);
16754
+ const [isSkillUploadOpen, setIsSkillUploadOpen] = useState(false);
16625
16755
  const { chatbotContext, currentAgentChatId, minimizedStreamData } = useSelector((state) => state.smartBotReducer);
16626
16756
  const savedFilterDashboard = useSelector((state) => state.filterReducer?.savedFilterDashboard);
16627
16757
  // Per-mode conversation ID tracking — prevents cross-mode contamination when
@@ -17181,6 +17311,29 @@ const SmartBot = (props) => {
17181
17311
  useEffect(() => {
17182
17312
  fetchCustomBotConfigurations();
17183
17313
  }, [baseUrl]);
17314
+ useEffect(() => {
17315
+ let live = true;
17316
+ if (!baseUrl) {
17317
+ setSkillUploadOn(false);
17318
+ return;
17319
+ }
17320
+ fetchSkillUploadOn(baseUrl).then((on) => {
17321
+ if (live)
17322
+ setSkillUploadOn(on);
17323
+ });
17324
+ return () => {
17325
+ live = false;
17326
+ };
17327
+ }, [baseUrl]);
17328
+ // kept apart from utilityList: handleUploadAccess sets that list from its first value once its access
17329
+ // check returns, which would drop an item added meanwhile
17330
+ const skillUploadItem = {
17331
+ key: "Upload Skill",
17332
+ onClick: () => {
17333
+ setIsSkillUploadOpen(true);
17334
+ },
17335
+ icon: (jsx("div", { className: classes.memoryModalIconDiv, children: jsx(SvgUploadIcon, { style: { width: 20, height: 20 } }) })),
17336
+ };
17184
17337
  // Sync showModal state with props.showModal OR props.invokeBot (backward compatibility)
17185
17338
  // Host app passes showModal prop, but some integrations may use invokeBot
17186
17339
  useEffect(() => {
@@ -17838,7 +17991,7 @@ const SmartBot = (props) => {
17838
17991
  return (jsxs(Fragment, { children: [partialClose && (minimizedStreamData?.isStreaming || minimizedStreamData?.stepStatus === "step_form") && (jsx(MinimizedChatWidget, { onExpand: () => {
17839
17992
  setShowModal(true);
17840
17993
  setPartialClose(false);
17841
- } })), 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,
17994
+ } })), 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,
17842
17995
  // onSaveClick={saveCurrentChat}
17843
17996
  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) => {
17844
17997
  const convId = params?.conversation_id;
@@ -17951,7 +18104,7 @@ const SmartBot = (props) => {
17951
18104
  onSendIconClick: onSendIconClick, conversation: conversation, onModuleClick: (id, name, param) => {
17952
18105
  // activeTab.current.activeTab = name.toLowerCase();
17953
18106
  handleModuleSelect(name);
17954
- }, moduleList: modules, tabList: tabList, utilityList: utilityList, isAssistantThinking: false, isCustomScreen: showChatPlaceholder ? showChatPlaceholder : showSavedFilters, customScreenJsx: showChatPlaceholder ?
18107
+ }, moduleList: modules, tabList: tabList, utilityList: skillUploadOn ? [...utilityList, skillUploadItem] : utilityList, isAssistantThinking: false, isCustomScreen: showChatPlaceholder ? showChatPlaceholder : showSavedFilters, customScreenJsx: showChatPlaceholder ?
17955
18108
  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 })
17956
18109
  :
17957
18110
  jsx(ChatbotSaveFilterComponent$1, { savedFilterSets: savedFilterSets, partialClose: partialClose, chatBotWidth: chatBotWidth }), inputText: userInput, threadList: ["Home"], hideMenuArrow: true, newChatScreen: newChatScreen, isModuleListLoading: modulesLoading, suggestionBanner: {