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.
@@ -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
@@ -783,6 +783,30 @@ const uploadFile = async (payload) => {
783
783
  return null;
784
784
  }
785
785
  };
786
+ /** Saves a skill for the signed-in user: its SKILL.md and the files it refers to, each keyed by its path in
787
+ * the skill's folder ({"SKILL.md": text, "references/x.md": text}). The agent checks it as its harness would
788
+ * serve it and answers {name, version, characters, files, missing_files, trigger, trigger_said, turn_on}; a
789
+ * skill it refuses is a 422 whose detail says why. Errors reach the caller, which shows them. */
790
+ const uploadSkill = async (files, baseUrl) => {
791
+ return axiosInstance({
792
+ url: `${baseUrl}/chatbot/agent/skills`,
793
+ method: 'POST',
794
+ data: { files },
795
+ });
796
+ };
797
+ /** Whether the agent takes skill uploads: its /info answer carries skills.upload beside the cards. Any
798
+ * failure, or an agent that does not say so, is false (no "Upload Skill" item). */
799
+ const fetchSkillUploadOn = async (baseUrl) => {
800
+ try {
801
+ const response = await fetchAgentsInfo(baseUrl);
802
+ const body = response?.data || {};
803
+ return body?.skills?.upload === true || body?.data?.skills?.upload === true;
804
+ }
805
+ catch (error) {
806
+ console.error('fetchSkillUploadOn error:', error);
807
+ return false;
808
+ }
809
+ };
786
810
  const triggerRefresh = async (baseUrl) => {
787
811
  try {
788
812
  return httpRequest({
@@ -846,7 +870,7 @@ const getTableRecords = async (payload, baseUrl, tableName) => {
846
870
  * user and answers {rows, total}. */
847
871
  const postUiQuery = async (payload, baseUrl) => {
848
872
  try {
849
- return axiosInstance({
873
+ return httpRequest({
850
874
  url: `${baseUrl}/chatbot/agent/ui-query`,
851
875
  method: 'POST',
852
876
  data: payload,
@@ -14144,6 +14168,109 @@ function UploadModal(props) {
14144
14168
  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] }))] })) }));
14145
14169
  }
14146
14170
 
14171
+ /** A skill is a folder: SKILL.md (its name and description, then its steps) and the files it refers to, such
14172
+ * as references/mcp-contracts.md. Picked files are read here as text, keyed by their path in that folder,
14173
+ * and saved for the signed-in user by the agent (POST {baseUrl}/chatbot/agent/skills). Unlike a paste into
14174
+ * the chat, an upload keeps the line breaks and the skill's other files. */
14175
+ const MAX_FILES = 50;
14176
+ const TEXT_EXTENSIONS = [".md", ".txt", ".json", ".yaml", ".yml", ".csv"];
14177
+ const isSkillFile = (path) => path === "SKILL.md" || path.endsWith("/SKILL.md");
14178
+ const isText = (name) => TEXT_EXTENSIONS.some((ext) => name.toLowerCase().endsWith(ext));
14179
+ /** What the agent answered; a 200 may be the object itself or wrapped as {data: {...}}. */
14180
+ const savedOf = (response) => response?.data?.data || response?.data || {};
14181
+ /** Why the agent did not save it: the 422's detail ("not saved: ..."), else the message or status. */
14182
+ const whyNot = (error) => {
14183
+ const body = error?.response?.data;
14184
+ const said = body?.detail || body?.message || body?.data?.detail;
14185
+ if (typeof said === "string" && said)
14186
+ return said;
14187
+ if (said)
14188
+ return JSON.stringify(said);
14189
+ return error?.response?.status ? `the agent answered ${error.response.status}` : String(error?.message || error);
14190
+ };
14191
+ function SkillUploadModal(props) {
14192
+ const { isOpen, setIsOpen, baseUrl, displaySnackMessages, onUseText } = props;
14193
+ const [picked, setPicked] = React.useState({});
14194
+ const [skipped, setSkipped] = React.useState(0);
14195
+ const [isSaving, setIsSaving] = React.useState(false);
14196
+ const [saved, setSaved] = React.useState(null);
14197
+ const [error, setError] = React.useState("");
14198
+ const folderRef = React.useRef(null);
14199
+ const filesRef = React.useRef(null);
14200
+ const classes = useStyles$b();
14201
+ const reset = () => {
14202
+ setPicked({});
14203
+ setSkipped(0);
14204
+ setSaved(null);
14205
+ setError("");
14206
+ };
14207
+ const handleClose = () => {
14208
+ if (isSaving)
14209
+ return;
14210
+ setIsOpen(false);
14211
+ reset();
14212
+ };
14213
+ const take = async (list) => {
14214
+ if (!list)
14215
+ return;
14216
+ const next = { ...picked };
14217
+ let left = 0;
14218
+ for (const file of Array.from(list)) {
14219
+ const path = file.webkitRelativePath || file.name;
14220
+ if (!isText(file.name)) {
14221
+ left += 1; // a folder may hold images or .DS_Store: only text files are a skill's
14222
+ continue;
14223
+ }
14224
+ if (!(path in next) && Object.keys(next).length >= MAX_FILES) {
14225
+ displaySnackMessages(`A skill can have at most ${MAX_FILES} files`, "error");
14226
+ break;
14227
+ }
14228
+ next[path] = await file.text();
14229
+ }
14230
+ setPicked(next);
14231
+ setSkipped(skipped + left);
14232
+ setSaved(null);
14233
+ setError("");
14234
+ };
14235
+ const paths = Object.keys(picked);
14236
+ const hasSkill = paths.some(isSkillFile);
14237
+ const handleSave = async () => {
14238
+ if (!hasSkill) {
14239
+ displaySnackMessages("Pick the skill's SKILL.md (or its folder) first", "error");
14240
+ return;
14241
+ }
14242
+ try {
14243
+ setIsSaving(true);
14244
+ setError("");
14245
+ const response = await uploadSkill(picked, baseUrl);
14246
+ setSaved(savedOf(response));
14247
+ displaySnackMessages("Skill saved", "success");
14248
+ }
14249
+ catch (err) {
14250
+ console.error("uploadSkill error:", err);
14251
+ setError(whyNot(err));
14252
+ }
14253
+ finally {
14254
+ setIsSaving(false);
14255
+ }
14256
+ };
14257
+ const use = (text) => {
14258
+ onUseText?.(text);
14259
+ setIsOpen(false);
14260
+ reset();
14261
+ };
14262
+ const files = saved?.files || [];
14263
+ const missing = saved?.missing_files || [];
14264
+ const runText = saved?.name ? `Run skill ${saved.name} in Preview mode` : "";
14265
+ 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) => {
14266
+ take(e.target.files);
14267
+ e.target.value = "";
14268
+ }, style: { display: "none" }, multiple: true, ...{ webkitdirectory: "", directory: "" } }), jsxRuntime.jsx("input", { type: "file", ref: filesRef, onChange: (e) => {
14269
+ take(e.target.files);
14270
+ e.target.value = "";
14271
+ }, 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, "")] })] })) }));
14272
+ }
14273
+
14147
14274
  const useStyles$2 = styles.makeStyles(() => ({
14148
14275
  input: {
14149
14276
  width: "100%",
@@ -18027,6 +18154,9 @@ const SmartBot = (props) => {
18027
18154
  React.useState(false);
18028
18155
  React.useState(false);
18029
18156
  const [conversation, setConversation] = React.useState({});
18157
+ // "Upload Skill": offered only when the agent's /info says skills.upload (asked once per base URL)
18158
+ const [skillUploadOn, setSkillUploadOn] = React.useState(false);
18159
+ const [isSkillUploadOpen, setIsSkillUploadOpen] = React.useState(false);
18030
18160
  const { chatbotContext, currentAgentChatId, minimizedStreamData } = reactRedux.useSelector((state) => state.smartBotReducer);
18031
18161
  const savedFilterDashboard = reactRedux.useSelector(selectors?.getSavedFilterDashboard ?? NULL_SELECTOR);
18032
18162
  // Per-mode conversation ID tracking — prevents cross-mode contamination when
@@ -18585,6 +18715,29 @@ const SmartBot = (props) => {
18585
18715
  React.useEffect(() => {
18586
18716
  fetchCustomBotConfigurations();
18587
18717
  }, [baseUrl]);
18718
+ React.useEffect(() => {
18719
+ let live = true;
18720
+ if (!baseUrl) {
18721
+ setSkillUploadOn(false);
18722
+ return;
18723
+ }
18724
+ fetchSkillUploadOn(baseUrl).then((on) => {
18725
+ if (live)
18726
+ setSkillUploadOn(on);
18727
+ });
18728
+ return () => {
18729
+ live = false;
18730
+ };
18731
+ }, [baseUrl]);
18732
+ // kept apart from utilityList: handleUploadAccess sets that list from its first value once its access
18733
+ // check returns, which would drop an item added meanwhile
18734
+ const skillUploadItem = {
18735
+ key: "Upload Skill",
18736
+ onClick: () => {
18737
+ setIsSkillUploadOpen(true);
18738
+ },
18739
+ icon: (jsxRuntime.jsx("div", { className: classes.memoryModalIconDiv, children: jsxRuntime.jsx(SvgUploadIcon, { style: { width: 20, height: 20 } }) })),
18740
+ };
18588
18741
  // Sync showModal state with props.showModal OR props.invokeBot (backward compatibility)
18589
18742
  // Host app passes showModal prop, but some integrations may use invokeBot
18590
18743
  React.useEffect(() => {
@@ -19242,7 +19395,7 @@ const SmartBot = (props) => {
19242
19395
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [partialClose && (minimizedStreamData?.isStreaming || minimizedStreamData?.stepStatus === "step_form") && (jsxRuntime.jsx(MinimizedChatWidget, { onExpand: () => {
19243
19396
  setShowModal(true);
19244
19397
  setPartialClose(false);
19245
- } })), 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,
19398
+ } })), 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,
19246
19399
  // onSaveClick={saveCurrentChat}
19247
19400
  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) => {
19248
19401
  const convId = params?.conversation_id;
@@ -19355,7 +19508,7 @@ const SmartBot = (props) => {
19355
19508
  onSendIconClick: onSendIconClick, conversation: conversation, onModuleClick: (id, name, param) => {
19356
19509
  // activeTab.current.activeTab = name.toLowerCase();
19357
19510
  handleModuleSelect(name);
19358
- }, moduleList: modules, tabList: tabList, utilityList: utilityList, isAssistantThinking: false, isCustomScreen: showChatPlaceholder ? showChatPlaceholder : showSavedFilters, customScreenJsx: showChatPlaceholder ?
19511
+ }, moduleList: modules, tabList: tabList, utilityList: skillUploadOn ? [...utilityList, skillUploadItem] : utilityList, isAssistantThinking: false, isCustomScreen: showChatPlaceholder ? showChatPlaceholder : showSavedFilters, customScreenJsx: showChatPlaceholder ?
19359
19512
  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 })
19360
19513
  :
19361
19514
  components?.FilterComponent ? jsxRuntime.jsx(components.FilterComponent, { savedFilterSets: savedFilterSets, partialClose: partialClose, chatBotWidth: chatBotWidth, onSetFilterConfiguration: callbacks?.onSetFilterConfiguration }) : null, inputText: userInput, threadList: ["Home"], hideMenuArrow: true, newChatScreen: newChatScreen, isModuleListLoading: modulesLoading, suggestionBanner: {