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.
@@ -0,0 +1,2 @@
1
+ declare function SkillUploadModal(props: any): import("react/jsx-runtime").JSX.Element;
2
+ export default SkillUploadModal;
package/dist/index.cjs.js CHANGED
@@ -270,6 +270,30 @@ const uploadFile = async (payload) => {
270
270
  return null;
271
271
  }
272
272
  };
273
+ /** Saves a skill for the signed-in user: its SKILL.md and the files it refers to, each keyed by its path in
274
+ * the skill's folder ({"SKILL.md": text, "references/x.md": text}). The agent checks it as its harness would
275
+ * serve it and answers {name, version, characters, files, missing_files, trigger, trigger_said, turn_on}; a
276
+ * skill it refuses is a 422 whose detail says why. Errors reach the caller, which shows them. */
277
+ const uploadSkill = async (files, baseUrl) => {
278
+ return axiosInstance({
279
+ url: `${baseUrl}/chatbot/agent/skills`,
280
+ method: 'POST',
281
+ data: { files },
282
+ });
283
+ };
284
+ /** Whether the agent takes skill uploads: its /info answer carries skills.upload beside the cards. Any
285
+ * failure, or an agent that does not say so, is false (no "Upload Skill" item). */
286
+ const fetchSkillUploadOn = async (baseUrl) => {
287
+ try {
288
+ const response = await fetchAgentsInfo(baseUrl);
289
+ const body = response?.data || {};
290
+ return body?.skills?.upload === true || body?.data?.skills?.upload === true;
291
+ }
292
+ catch (error) {
293
+ console.error('fetchSkillUploadOn error:', error);
294
+ return false;
295
+ }
296
+ };
273
297
  const triggerRefresh = async (baseUrl) => {
274
298
  try {
275
299
  return axiosInstance({
@@ -12861,6 +12885,109 @@ function UploadModal(props) {
12861
12885
  return (jsxRuntime.jsx(impactUiV3.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 ? (jsxRuntime.jsx(impactUiV3.Loader, { text: "Uploading file..." })) : (jsxRuntime.jsxs("div", { className: classes.uploadModalInnerSec, children: [jsxRuntime.jsx("input", { type: "file", ref: fileInputRef, onChange: handleFileSelect, accept: ".pdf", style: { display: "none" }, disabled: isLoading }), jsxRuntime.jsx(impactUiV3.Button, { onClick: () => fileInputRef.current.click(), variant: "outlined", disabled: isLoading, children: "Select PDF File" }), selectedFile && (jsxRuntime.jsxs("p", { style: { marginTop: "10px" }, children: ["Selected File: ", selectedFile.name] }))] })) }));
12862
12886
  }
12863
12887
 
12888
+ /** A skill is a folder: SKILL.md (its name and description, then its steps) and the files it refers to, such
12889
+ * as references/mcp-contracts.md. Picked files are read here as text, keyed by their path in that folder,
12890
+ * and saved for the signed-in user by the agent (POST {baseUrl}/chatbot/agent/skills). Unlike a paste into
12891
+ * the chat, an upload keeps the line breaks and the skill's other files. */
12892
+ const MAX_FILES = 50;
12893
+ const TEXT_EXTENSIONS = [".md", ".txt", ".json", ".yaml", ".yml", ".csv"];
12894
+ const isSkillFile = (path) => path === "SKILL.md" || path.endsWith("/SKILL.md");
12895
+ const isText = (name) => TEXT_EXTENSIONS.some((ext) => name.toLowerCase().endsWith(ext));
12896
+ /** What the agent answered; a 200 may be the object itself or wrapped as {data: {...}}. */
12897
+ const savedOf = (response) => response?.data?.data || response?.data || {};
12898
+ /** Why the agent did not save it: the 422's detail ("not saved: ..."), else the message or status. */
12899
+ const whyNot = (error) => {
12900
+ const body = error?.response?.data;
12901
+ const said = body?.detail || body?.message || body?.data?.detail;
12902
+ if (typeof said === "string" && said)
12903
+ return said;
12904
+ if (said)
12905
+ return JSON.stringify(said);
12906
+ return error?.response?.status ? `the agent answered ${error.response.status}` : String(error?.message || error);
12907
+ };
12908
+ function SkillUploadModal(props) {
12909
+ const { isOpen, setIsOpen, baseUrl, displaySnackMessages, onUseText } = props;
12910
+ const [picked, setPicked] = React.useState({});
12911
+ const [skipped, setSkipped] = React.useState(0);
12912
+ const [isSaving, setIsSaving] = React.useState(false);
12913
+ const [saved, setSaved] = React.useState(null);
12914
+ const [error, setError] = React.useState("");
12915
+ const folderRef = React.useRef(null);
12916
+ const filesRef = React.useRef(null);
12917
+ const classes = useStyles$b();
12918
+ const reset = () => {
12919
+ setPicked({});
12920
+ setSkipped(0);
12921
+ setSaved(null);
12922
+ setError("");
12923
+ };
12924
+ const handleClose = () => {
12925
+ if (isSaving)
12926
+ return;
12927
+ setIsOpen(false);
12928
+ reset();
12929
+ };
12930
+ const take = async (list) => {
12931
+ if (!list)
12932
+ return;
12933
+ const next = { ...picked };
12934
+ let left = 0;
12935
+ for (const file of Array.from(list)) {
12936
+ const path = file.webkitRelativePath || file.name;
12937
+ if (!isText(file.name)) {
12938
+ left += 1; // a folder may hold images or .DS_Store: only text files are a skill's
12939
+ continue;
12940
+ }
12941
+ if (!(path in next) && Object.keys(next).length >= MAX_FILES) {
12942
+ displaySnackMessages(`A skill can have at most ${MAX_FILES} files`, "error");
12943
+ break;
12944
+ }
12945
+ next[path] = await file.text();
12946
+ }
12947
+ setPicked(next);
12948
+ setSkipped(skipped + left);
12949
+ setSaved(null);
12950
+ setError("");
12951
+ };
12952
+ const paths = Object.keys(picked);
12953
+ const hasSkill = paths.some(isSkillFile);
12954
+ const handleSave = async () => {
12955
+ if (!hasSkill) {
12956
+ displaySnackMessages("Pick the skill's SKILL.md (or its folder) first", "error");
12957
+ return;
12958
+ }
12959
+ try {
12960
+ setIsSaving(true);
12961
+ setError("");
12962
+ const response = await uploadSkill(picked, baseUrl);
12963
+ setSaved(savedOf(response));
12964
+ displaySnackMessages("Skill saved", "success");
12965
+ }
12966
+ catch (err) {
12967
+ console.error("uploadSkill error:", err);
12968
+ setError(whyNot(err));
12969
+ }
12970
+ finally {
12971
+ setIsSaving(false);
12972
+ }
12973
+ };
12974
+ const use = (text) => {
12975
+ onUseText?.(text);
12976
+ setIsOpen(false);
12977
+ reset();
12978
+ };
12979
+ const files = saved?.files || [];
12980
+ const missing = saved?.missing_files || [];
12981
+ const runText = saved?.name ? `Run skill ${saved.name} in Preview mode` : "";
12982
+ return (jsxRuntime.jsx(impactUiV3.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 ? (jsxRuntime.jsx(impactUiV3.Loader, { text: "Saving the skill..." })) : saved ? (jsxRuntime.jsxs("div", { style: { padding: "16px 20px", lineHeight: 1.5 }, children: [jsxRuntime.jsxs("p", { style: { margin: "0 0 8px" }, children: ["Saved ", jsxRuntime.jsx("b", { children: saved.name }), " (version ", saved.version, typeof saved.characters === "number" ? `, ${saved.characters.toLocaleString()} characters` : "", files.length ? `, with ${files.join(", ")}` : "", ")."] }), missing.length > 0 && (jsxRuntime.jsxs("p", { style: { margin: "0 0 8px" }, children: ["It refers to ", missing.join(", "), ", which was not uploaded."] })), saved.trigger && (jsxRuntime.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:", " ", jsxRuntime.jsx("i", { children: saved.turn_on })] })), jsxRuntime.jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap", marginTop: "12px" }, children: [runText && (jsxRuntime.jsxs(impactUiV3.Button, { variant: "outlined", onClick: () => use(runText), children: ["Put \"", runText, "\" in the chat"] })), saved.trigger && saved.turn_on && (jsxRuntime.jsxs(impactUiV3.Button, { variant: "outlined", onClick: () => use(saved.turn_on), children: ["Put \"", saved.turn_on, "\" in the chat"] }))] })] })) : (jsxRuntime.jsxs("div", { className: classes.uploadModalInnerSec, style: { height: "auto", minHeight: "150px" }, children: [jsxRuntime.jsx("input", { type: "file", ref: folderRef, onChange: (e) => {
12983
+ take(e.target.files);
12984
+ e.target.value = "";
12985
+ }, style: { display: "none" }, multiple: true, ...{ webkitdirectory: "", directory: "" } }), jsxRuntime.jsx("input", { type: "file", ref: filesRef, onChange: (e) => {
12986
+ take(e.target.files);
12987
+ e.target.value = "";
12988
+ }, style: { display: "none" }, multiple: true, accept: TEXT_EXTENSIONS.join(",") }), jsxRuntime.jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap", justifyContent: "center" }, children: [jsxRuntime.jsx(impactUiV3.Button, { variant: "outlined", onClick: () => folderRef.current?.click(), children: "Pick the skill's folder" }), jsxRuntime.jsx(impactUiV3.Button, { variant: "outlined", onClick: () => filesRef.current?.click(), children: "Pick its files" })] }), paths.length > 0 ? (jsxRuntime.jsxs("div", { style: { marginTop: "12px", width: "100%" }, children: [jsxRuntime.jsx("ul", { style: { margin: 0, paddingLeft: "18px", maxHeight: "140px", overflowY: "auto" }, children: paths.map((path) => (jsxRuntime.jsx("li", { children: path }, path))) }), !hasSkill && jsxRuntime.jsx("p", { style: { margin: "8px 0 0" }, children: "No SKILL.md picked yet." }), skipped > 0 && (jsxRuntime.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(" "), ")."] }))] })) : (jsxRuntime.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 && jsxRuntime.jsxs("p", { style: { marginTop: "10px", color: "#b42318" }, children: ["Not saved: ", error.replace(/^not saved:\s*/i, "")] })] })) }));
12989
+ }
12990
+
12864
12991
  const useStyles$2 = styles.makeStyles(() => ({
12865
12992
  input: {
12866
12993
  width: "100%",
@@ -16644,6 +16771,9 @@ const SmartBot = (props) => {
16644
16771
  React.useState(false);
16645
16772
  React.useState(false);
16646
16773
  const [conversation, setConversation] = React.useState({});
16774
+ // "Upload Skill": offered only when the agent's /info says skills.upload (asked once per base URL)
16775
+ const [skillUploadOn, setSkillUploadOn] = React.useState(false);
16776
+ const [isSkillUploadOpen, setIsSkillUploadOpen] = React.useState(false);
16647
16777
  const { chatbotContext, currentAgentChatId, minimizedStreamData } = reactRedux.useSelector((state) => state.smartBotReducer);
16648
16778
  const savedFilterDashboard = reactRedux.useSelector((state) => state.filterReducer?.savedFilterDashboard);
16649
16779
  // Per-mode conversation ID tracking — prevents cross-mode contamination when
@@ -17203,6 +17333,29 @@ const SmartBot = (props) => {
17203
17333
  React.useEffect(() => {
17204
17334
  fetchCustomBotConfigurations();
17205
17335
  }, [baseUrl]);
17336
+ React.useEffect(() => {
17337
+ let live = true;
17338
+ if (!baseUrl) {
17339
+ setSkillUploadOn(false);
17340
+ return;
17341
+ }
17342
+ fetchSkillUploadOn(baseUrl).then((on) => {
17343
+ if (live)
17344
+ setSkillUploadOn(on);
17345
+ });
17346
+ return () => {
17347
+ live = false;
17348
+ };
17349
+ }, [baseUrl]);
17350
+ // kept apart from utilityList: handleUploadAccess sets that list from its first value once its access
17351
+ // check returns, which would drop an item added meanwhile
17352
+ const skillUploadItem = {
17353
+ key: "Upload Skill",
17354
+ onClick: () => {
17355
+ setIsSkillUploadOpen(true);
17356
+ },
17357
+ icon: (jsxRuntime.jsx("div", { className: classes.memoryModalIconDiv, children: jsxRuntime.jsx(SvgUploadIcon, { style: { width: 20, height: 20 } }) })),
17358
+ };
17206
17359
  // Sync showModal state with props.showModal OR props.invokeBot (backward compatibility)
17207
17360
  // Host app passes showModal prop, but some integrations may use invokeBot
17208
17361
  React.useEffect(() => {
@@ -17860,7 +18013,7 @@ const SmartBot = (props) => {
17860
18013
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [partialClose && (minimizedStreamData?.isStreaming || minimizedStreamData?.stepStatus === "step_form") && (jsxRuntime.jsx(MinimizedChatWidget, { onExpand: () => {
17861
18014
  setShowModal(true);
17862
18015
  setPartialClose(false);
17863
- } })), jsxRuntime.jsxs("div", { ref: smartBotWrapperRef, className: `${classes.agentStyleOverride} ${partialClose || !(showModal || forceOpen) ? classes.hideBotStyle : ""} `, children: [jsxRuntime.jsx(RenameModal, { open: renameOpen, renameValue: renameValue, setRenameValue: setRenameValue, onConfirm: handleRenameConfirm, onCancel: handleRenameCancel }), jsxRuntime.jsx(DeleteConfirmModal, { open: deleteOpen, onConfirm: handleDeleteConfirm, onCancel: handleDeleteCancel }), jsxRuntime.jsx(MemoryModal, { isModalOpen: isModalOpen, setIsModalOpen: setIsModalOpen, displaySnackMessages: displaySnackMessages }), jsxRuntime.jsx(UploadModal, { isUploadModalOpen: isUploadModalOpen, setIsUploadModalOpen: setIsUploadModalOpen, displaySnackMessages: displaySnackMessages }), jsxRuntime.jsx(impactUiV3.ChatBotComponent, { isFullWidth: forceOpen, userName: userName, showHistoryPanel: enableMultiChat, isConversationLoading: conversationLoading, customInputComponent: currentMode === "agent" && !showSavedFilters ? (jsxRuntime.jsx(ChatbotInput, { newChatScreen: newChatScreen, inputValue: userInput, setInputValue: setUserInput, isStopIcon: isStop, onSendIconClick: onSendIconClick, onStopIconClick: onStopIconClick, currentMode: currentMode, filterOptions: filterOptions,
18016
+ } })), jsxRuntime.jsxs("div", { ref: smartBotWrapperRef, className: `${classes.agentStyleOverride} ${partialClose || !(showModal || forceOpen) ? classes.hideBotStyle : ""} `, children: [jsxRuntime.jsx(RenameModal, { open: renameOpen, renameValue: renameValue, setRenameValue: setRenameValue, onConfirm: handleRenameConfirm, onCancel: handleRenameCancel }), jsxRuntime.jsx(DeleteConfirmModal, { open: deleteOpen, onConfirm: handleDeleteConfirm, onCancel: handleDeleteCancel }), jsxRuntime.jsx(MemoryModal, { isModalOpen: isModalOpen, setIsModalOpen: setIsModalOpen, displaySnackMessages: displaySnackMessages }), jsxRuntime.jsx(UploadModal, { isUploadModalOpen: isUploadModalOpen, setIsUploadModalOpen: setIsUploadModalOpen, displaySnackMessages: displaySnackMessages }), skillUploadOn && (jsxRuntime.jsx(SkillUploadModal, { isOpen: isSkillUploadOpen, setIsOpen: setIsSkillUploadOpen, baseUrl: baseUrl, displaySnackMessages: displaySnackMessages, onUseText: (text) => setUserInput(text) })), jsxRuntime.jsx(impactUiV3.ChatBotComponent, { isFullWidth: forceOpen, userName: userName, showHistoryPanel: enableMultiChat, isConversationLoading: conversationLoading, customInputComponent: currentMode === "agent" && !showSavedFilters ? (jsxRuntime.jsx(ChatbotInput, { newChatScreen: newChatScreen, inputValue: userInput, setInputValue: setUserInput, isStopIcon: isStop, onSendIconClick: onSendIconClick, onStopIconClick: onStopIconClick, currentMode: currentMode, filterOptions: filterOptions,
17864
18017
  // onSaveClick={saveCurrentChat}
17865
18018
  savedFilterSets: savedFilterSets, selectedFilterSet: selectedFilterSet, onFilterSetSelect: (filterSet) => setSelectedFilterSet(filterSet), onClearFilterSet: () => setSelectedFilterSet(null), onTriggerRefresh: triggerRefreshAction, answerMode: answerMode, setAnswerMode: setAnswerMode })) : showSavedFilters ? jsxRuntime.jsx(jsxRuntime.Fragment, {}) : null, isChatBotOpen: showModal || forceOpen, historyPanelData: historyPanelData, onHistorySearchChange: (params) => { console.log("History Search Change", params); }, onHistorySelectConversation: (params) => {
17866
18019
  const convId = params?.conversation_id;
@@ -17973,7 +18126,7 @@ const SmartBot = (props) => {
17973
18126
  onSendIconClick: onSendIconClick, conversation: conversation, onModuleClick: (id, name, param) => {
17974
18127
  // activeTab.current.activeTab = name.toLowerCase();
17975
18128
  handleModuleSelect(name);
17976
- }, moduleList: modules, tabList: tabList, utilityList: utilityList, isAssistantThinking: false, isCustomScreen: showChatPlaceholder ? showChatPlaceholder : showSavedFilters, customScreenJsx: showChatPlaceholder ?
18129
+ }, moduleList: modules, tabList: tabList, utilityList: skillUploadOn ? [...utilityList, skillUploadItem] : utilityList, isAssistantThinking: false, isCustomScreen: showChatPlaceholder ? showChatPlaceholder : showSavedFilters, customScreenJsx: showChatPlaceholder ?
17977
18130
  jsxRuntime.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 })
17978
18131
  :
17979
18132
  jsxRuntime.jsx(ChatbotSaveFilterComponent$1, { savedFilterSets: savedFilterSets, partialClose: partialClose, chatBotWidth: chatBotWidth }), inputText: userInput, threadList: ["Home"], hideMenuArrow: true, newChatScreen: newChatScreen, isModuleListLoading: modulesLoading, suggestionBanner: {