@e-llm-studio/instant-learning 0.0.226 → 0.0.227
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/cjs/features/IL-OTJ/ILOTJ.js +1 -1
- package/dist/cjs/features/IL-OTJ/_components/ChatComponents/ChatComponent.js +1 -1
- package/dist/cjs/features/IL-OTJ/_components/MessageRendering/MessageRendering.js +1 -1
- package/dist/cjs/features/IL-OTJ/_components/atoms/Textarea/Textarea.js +1 -1
- package/dist/cjs/features/IL-OTJ/_components/templates/TrafficManager/CreateRule.js +1 -1
- package/dist/cjs/features/IL-OTJ/helpers/utils.js +1 -1
- package/dist/features/IL-OTJ/ILOTJ.js +1 -1
- package/dist/features/IL-OTJ/_components/ChatComponents/ChatComponent.js +1 -1
- package/dist/features/IL-OTJ/_components/MessageRendering/MessageRendering.js +1 -1
- package/dist/features/IL-OTJ/_components/atoms/Textarea/Textarea.js +1 -1
- package/dist/features/IL-OTJ/_components/templates/TrafficManager/CreateRule.js +1 -1
- package/dist/features/IL-OTJ/helpers/utils.js +1 -1
- package/dist/types/src/features/IL-OTJ/ILOTJ.d.ts +5 -0
- package/dist/types/src/features/IL-OTJ/ILOTJ.d.ts.map +1 -1
- package/dist/types/src/features/IL-OTJ/ILOTJTest.d.ts.map +1 -1
- package/dist/types/src/features/IL-OTJ/_components/ChatComponents/ChatComponent.d.ts +5 -0
- package/dist/types/src/features/IL-OTJ/_components/ChatComponents/ChatComponent.d.ts.map +1 -1
- package/dist/types/src/features/IL-OTJ/_components/MessageRendering/MessageRendering.d.ts.map +1 -1
- package/dist/types/src/features/IL-OTJ/_components/atoms/Textarea/Textarea.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../node_modules/tslib/tslib.es6.mjs.js"),n=require("react/jsx-runtime"),t=require("../../../../node_modules/react-markdown/lib/react-markdown.js"),i=require("../../../../node_modules/rehype-raw/lib/index.js"),a=require("../../../../node_modules/remark-gfm/index.js"),r=require("react"),s=require("./ClickableChatComponents.js"),o=require("../MarkdownComponents/MarkdownElements.js"),c=require("../../helpers/utils.js"),l=require("./RuleVariantCard.js"),d=require("../MarkdownComponents/MarkdownSelect.js"),u=require("./ChatFeedback.js"),p=require("../../helpers/message-rendering-utils.js");exports.default=function(g){var m=g.index,f=g.content,v=g.role,h=g.messages,_=g.handleStream,S=g.scrollToBottom,b=g.isLastMessage,x=g.onSave,y=g.citations,k=g.setChatSize,w=g.chatSize,C=g.isStreamEnd,j=g.messageIsEnd,T=g.onViewComparison,R=g.onTypeResponseClick,E=g.onComparisonLinkClick,M=g.baseURL,A=g.onFeedbackSubmit,L=r.useState(f),B=L[0],N=L[1],I=r.useState([]),q=I[0],z=I[1],F=r.useState(!1),W=F[0],D=F[1],V=r.useState(!1),U=V[0],J=V[1],O=r.useState(!1),P=O[0],H=O[1],G=r.useState(null),K=G[0],$=G[1],Y=r.useState(null),Q=Y[0],X=Y[1],Z=r.useState([]),ee=Z[0],ne=Z[1],te=r.useState(!1),ie=te[0],ae=te[1],re=r.useState(!1),se=re[0],oe=re[1],ce=r.useState(new Set),le=ce[0],de=ce[1],ue=r.useState(new Set),pe=ue[0],ge=ue[1],me=r.useRef({handleStream:_,onSave:x,selectedTiers:q,tiersSubmitted:U,citations:y,openCardIds:le,openCitationIds:pe,chatSize:w,isLastMessage:b,scrollToBottom:S,isStreamEnd:C,selectedVariant:Q,messageIsEnd:j,isCommitted:P,clickedAction:K,gapSelections:ee,gapsSubmitted:se,onTypeResponseClick:R});me.current={handleStream:_,onSave:x,selectedTiers:q,tiersSubmitted:U,citations:y,openCardIds:le,openCitationIds:pe,chatSize:w,isLastMessage:b,scrollToBottom:S,isStreamEnd:C,selectedVariant:Q,messageIsEnd:j,isCommitted:P,clickedAction:K,gapSelections:ee,gapsSubmitted:se,onTypeResponseClick:R},r.useEffect(function(){X(null),H(!1),$(null),ae(!1),oe(!1),ne([])},[m]),r.useEffect(function(){if(j&&!P&&!Q){var e=je(B).match(/<variant-card[^>]*isselected=["']true["'][^>]*>/i);if(e){var n=e[0].match(/id=["']([^"']+)["']/),t=e[0].match(/variantname=["']([^"']+)["']/),i=e[0].match(/decisionstrength=["']([^"']+)["']/);n&&t&&X({id:n[1],variantName:t[1],decisionStrength:parseInt((null==i?void 0:i[1])||"0")})}}},[B,j,P,Q]);var fe=r.useCallback(function(e,n,t){var i=function(t){var i=new Set(t);return n?i.add(e):i.delete(e),i};"card"===t?de(function(e){return i(e)}):ge(function(e){return i(e)})},[]),ve=r.useCallback(function(e,n,t){void 0===n&&(n=!1);var i=me.current,a=i.handleStream;i.onSave;var r=e.trim();a&&(a(new KeyboardEvent("keydown",{key:"Enter"}),!1,r),n&&t&&(H(!0),$(t))),n||N(function(e){return e.replace(/<button([^>]*)class=["']clickable-button["']([^>]*)>([\s\S]*?)<\/button>/gi,function(e,n,t,i){var a=i.trim(),s='data-selected="'.concat(a===r,'"');return"<button".concat(n,'class="clickable-button" ').concat(s).concat(t,">").concat(i,"</button>")})})},[]),he=r.useCallback(function(e,n){ae(e),ne(n)},[]),_e=r.useCallback(function(){var e=me.current,n=e.handleStream,t=e.gapSelections.map(function(e){var n=Array.isArray(e.userSelection)?e.userSelection.join(", "):e.userSelection;return"".concat(e.name,": ").concat(n||"Skipped")}),i="Here are my choices for the critical gaps:\n".concat(t.join(","));n(new KeyboardEvent("keydown",{key:"Enter"}),!1,i),oe(!0)},[]),Se=r.useCallback(function(e,n){var t=me.current.citations;return t&&t.find(function(t){return t.customMetaData.citation_number&&"Cognitive Decisioning"!==t.customMetaData.citation_title&&t.customMetaData.source===n&&String(t.customMetaData.citation_number)===String(e)})||null},[]),be=r.useCallback(function(n,t){var i=me.current.scrollToBottom,a=Array.isArray(n)?n[0].trim():n.trim();D(!0),z(function(n){var i=e.__spreadArray([],n,!0);if(["both tiers","all tiers"].includes(a.toLowerCase()))i=t?["Both Tiers","Tier 1","Tier 2"]:[];else{t?i.includes(a)||i.push(a):i=i.filter(function(e){return e!==a});var r=i.includes("Tier 1"),s=i.includes("Tier 2");r&&s?i.includes("Both Tiers")||i.push("Both Tiers"):i=i.filter(function(e){return!["Both Tiers","All tiers"].includes(e)})}return i.filter(function(e,n){return i.indexOf(e)===n})}),null==i||i()},[]),xe=r.useCallback(function(e,n,t,i){me.current.isCommitted||n&&X({id:e,variantName:t,decisionStrength:i})},[]),ye=function(){if(!me.current.isCommitted){var e="Edit ".concat((null==Q?void 0:Q.variantName)||"Selected Behavior");ve(e,!0,"edit")}},ke=r.useCallback(function(){var e=me.current,n=e.handleStream,t=e.selectedTiers,i=t.join(" and ");t.some(function(e){return"both tiers"===e.toLowerCase()||"all tiers"===e.toLowerCase()})&&(i="Both Tiers"),n(new KeyboardEvent("keydown",{key:"Enter"}),!1,"".concat(i)),J(!0),D(!1),N(function(e){return e.replace(/<checkbox\s+class=["']clickable-box["'][^>]*>([\s\S]*?)<\/checkbox>/gi,function(e,n){var i=n.trim();return t.includes(i)?e:""})})},[]),we=r.useMemo(function(){return{p:function(t){t.node;var i=e.__rest(t,["node"]);return n.jsx("span",e.__assign({},i,{style:{maxWidth:"100%",wordWrap:"break-word",overflowWrap:"break-word",wordBreak:"break-word",whiteSpace:"normal",overflow:"hidden",display:"block",fontSize:"1rem",lineHeight:"1.625rem",marginBottom:"user"===v?"0":"0.4rem"}},{children:null==i?void 0:i.children}))},code:function(t){t.node;var i=e.__rest(t,["node"]);return n.jsx("span",e.__assign({},i,{style:{maxWidth:"100%",wordWrap:"break-word",overflowWrap:"break-word",wordBreak:"break-word",whiteSpace:"normal",overflow:"hidden",display:"inline-flex",fontSize:"1rem",lineHeight:"1.625rem"}},{children:null==i?void 0:i.children}))},ol:function(t){t.node;var i=e.__rest(t,["node"]);return n.jsx("ol",e.__assign({},i,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==i?void 0:i.children}))},ul:function(t){t.node;var i=e.__rest(t,["node"]);return n.jsx("ul",e.__assign({},i,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==i?void 0:i.children}))},rule:function(t){t.node;var i=e.__rest(t,["node"]);return n.jsx(s.RuleDisplay,{content:c.extractTextFromChildren(i.children)})},button:function(t){var i=t.node,a=t.className,r=e.__rest(t,["node","className"]),o=me.current,c=o.isLastMessage,l=o.handleStream,d=o.isStreamEnd;return n.jsx(s.ActionableButton,e.__assign({node:i,className:a||r.class,handleStream:l,onAction:ve,disabled:!c,isStreamEnd:d,isLastMessage:c,onTypeResponseClick:R,baseURL:M},r))},checkbox:function(t){var i=t.node,a=t.className,r=e.__rest(t,["node","className"]),o=me.current,c=o.selectedTiers,l=o.tiersSubmitted,d=o.isLastMessage;return n.jsx(s.ActionableCheckbox,e.__assign({node:i,className:a||r.class,selectedItems:c,onToggle:be,isSubmitted:l,disabled:!d},r))},a:function(t){var i=me.current,a=i.chatSize,r=i.openCitationIds;return n.jsx(o.MarkdownLinkRenderer,e.__assign({},t,{chatSize:a,openCitationIds:r,getCitationByNumber:Se,handleToggleState:fe,isStreamEnd:me.current.isStreamEnd}))},div:function(t){var i=me.current,a=i.openCardIds,r=i.citations,s=i.isLastMessage,c=i.isStreamEnd,l=i.gapsSubmitted,d=i.onTypeResponseClick;return n.jsx(o.MarkdownDivRenderer,e.__assign({},t,{openCardIds:a,citations:r,handleToggleState:fe,isStreamEnd:c,isLastMessage:s,handleStream:_,onGapValidation:he,isGapsSubmitted:l,onViewComparison:T,onComparisonLinkClick:E,onTypeResponseClick:d}))},span:function(t){var i,a,r;if((null===(i=t.className)||void 0===i?void 0:i.includes("cognitive-card-trigger"))||(null===(a=t.className)||void 0===a?void 0:a.includes("view-form-update-trigger"))||(null===(r=t.className)||void 0===r?void 0:r.includes("view-identified-fields-trigger"))){var s=me.current,c=s.openCardIds,l=s.citations,d=s.isLastMessage,u=s.isStreamEnd,p=!d||u;return n.jsx(o.MarkdownSpanRenderer,e.__assign({},t,{openCardIds:c,citations:l,handleToggleState:fe,onComparisonLinkClick:E,isStreamEnd:p}))}return n.jsx("span",e.__assign({},t))},"variant-card":function(t){t.node;var i=e.__rest(t,["node"]),a=i.variantname,r=i.decisionstrength,s=i.id,o=me.current,c=o.isCommitted,d=o.isLastMessage,u=o.selectedVariant;if(!j)return null;var p=(null==u?void 0:u.id)===s,g=parseInt(r||"0"),m=!c&&d;return n.jsx(l.RuleVariantCard,e.__assign({variantName:a,decisionStrength:g,isEditable:m,isSelected:p,onToggle:function(e){return xe(s,e,a,g)},onEdit:function(){return ye()}},{children:i.children}))},br:function(t){return n.jsx("p",e.__assign({style:{marginBottom:"0.75rem"}},t))}}},[ve,be,Se,fe,v,Q,P,j,he,xe]);r.useEffect(function(){U||(N(f),setTimeout(function(){null==S||S()},50))},[f,U,S]);var Ce=r.useRef(0);r.useEffect(function(){var e=le.size+pe.size;e>0&&0===Ce.current?null==k||k(50):0===e&&Ce.current>0&&(null==k||k(40)),Ce.current=e},[le,pe,k]);var je=function(e){if(!e)return"";for(var n=e,t=function(e){if("critical_gaps"===e.property){var t=e.data,i=(null==t?void 0:t.critical_gaps)||t,a={count:String(i.count||0),decisionStrength:i.critical_gaps_decision_strength||i.decisionStrength||"0",value:i.value||"",gaps:(i.gap_cards||i.gaps||[]).map(function(e,n){var t,i,a,r,s,o,c=p.extractReasoningFromText(e.gap_value||e.value),l=c.text,d=c.aiReasoning,u=e.ai_reasoning||e.aiReasoning||d,g=((null===(t=e.interaction)||void 0===t?void 0:t.options)||e.options||[]).map(function(e){var n,t=p.extractReasoningFromText(e.label||e.text),i=t.text,a=t.aiReasoning,r=e.ai_reasoning||e.aiReasoning||a,s=null!==(n=e.explanation)&&void 0!==n?n:null;if("string"==typeof s)try{s=s.startsWith("[")&&s.endsWith("]")?JSON.parse(s.replace(/"/g,'"')):s?[s]:null}catch(e){s=s?[s]:null}return{id:e.id,text:i,explanation:s,aiReasoning:p.buildAiReasoning(r)}});return{id:e.id||"gap-".concat(n),name:e.gap_name||e.name||"Gap",decisionStrength:e.gap_decision_strength||e.decisionStrength||"0",impact:e.impact||"Medium",value:l,aiReasoning:p.buildAiReasoning(u),inputType:"textfield"===(null===(i=e.interaction)||void 0===i?void 0:i.interaction_type)||"text"===e.inputType?"text":"radioselect"===(null===(a=e.interaction)||void 0===a?void 0:a.interaction_type)||"radio"===(null===(r=e.interaction)||void 0===r?void 0:r.interaction_type)||"radio"===e.inputType?"radio":"checkbox"===(null===(s=e.interaction)||void 0===s?void 0:s.interaction_type)||"checkbox"===e.inputType?"checkbox":"text",options:g,userSelection:"checkbox"===(null===(o=e.interaction)||void 0===o?void 0:o.interaction_type)||"checkbox"===e.inputType?[]:""}})},r=JSON.stringify(a).replace(/"/g,""");n=n.replace(e.rawMatch,'\n\n<div class="critical-gaps-trigger" data-payload="'.concat(r,'"></div>\n\n'))}else if("updated_fields"===e.property||"identified_fields"===e.property){var s=e.data,o={title:"Rule Title",description:"Description",rule_description:"Description",wta:"When to Apply",wnta:"When NOT to Apply",scope:"Tier Information",rule_type:"Rule Type"},c=["ai_reasoning","scheduling_config","is_user_accepted_risk"],l=[];Object.keys(s).forEach(function(e){if(!c.includes(e)&&s[e]){var n=o[e]||e.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()}),t=p.extractReasoningFromText(s[e]),i=t.text,a=t.aiReasoning;i&&l.push({label:"".concat(n,": ").concat(i),reasoning:a})}});var d={title:"updated_fields"===e.property?"View Updated Fields":"View Identified Fields",fields:l},u=(r=JSON.stringify(d).replace(/"/g,"""),"updated_fields"===e.property?"view-form-update-trigger":"view-identified-fields-trigger");n=n.replace(e.rawMatch,'<span class="'.concat(u,'" data-payload="').concat(r,'"></span>'))}else if("variant_card"===e.property){var g=e.data.variants.map(function(e){var n,t,i,a;return'<variant-card id="'.concat(e.id||"",'" variantname="').concat(e.variant_name||e.variantname||"",'" decisionstrength="').concat(null!==(t=null!==(n=e.decision_strength)&&void 0!==n?n:e.decisionstrength)&&void 0!==t?t:"0",'" iseditable="').concat(e.iseditable||"false",'" isselected="').concat(null!==(a=null!==(i=e.is_selected)&&void 0!==i?i:e.isselected)&&void 0!==a?a:"false",'">').concat(e.description||e.innerContent||"","</variant-card>")}).join("\n\n");n=n.replace(e.rawMatch,"\n\n".concat(g,"\n\n"))}else if("rule_validation_card"===e.property){var m=e.data,f=function(e){return String(null!=e?e:"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")};g=(Array.isArray(null==m?void 0:m.validated_rules)?m.validated_rules:[m]).map(function(e){var n=p.extractReasoningFromText(e.rule_description||e.ruleDescription||""),t=n.text,i=n.aiReasoning,a=p.extractReasoningFromText(e.rule_title||e.ruleTitle||""),r=a.text,s=a.aiReasoning,o=i||s,c="";return o&&(c="<ai_reasoning>\n <id>".concat(o.id||"","</id>\n <reason>").concat(o.reason||"","</reason>\n <gap>").concat(o.gap||"","</gap>\n <relevance_score>").concat(o.score||"","</relevance_score>\n </ai_reasoning>")),'<div class="rule-validation-card-trigger"\n data-type="'.concat(f(e.validation_type||e.validationType),'"\n data-decision-strength="').concat(f(e.decision_strength||e.decisionStrength),'"\n data-title="').concat(f(r),'"\n data-tier="').concat(f(e.tier),'"\n data-rule-id="').concat(f(e.rule_id||e.ruleId),'"\n data-description="').concat(f(t),'">\n ').concat(c,"\n </div>")}).join("\n\n");n=n.replace(e.rawMatch,"\n\n".concat(g,"\n\n"))}},i=0,a=p.parseJsonBlocks(n);i<a.length;i++){t(a[i])}n=(n=(n=n.replace(/\\"/g,'"').replace(/\\'/g,"'").replace(/\u00A0/g," ").replace(/\r\n/g,"\n")).replace(/```(?:\w+)?\n?([\s\S]*?)```/gi,"$1")).replace(/<br\s*\/?>/gi,"\n\n"),console.log("sanitized output2:",n),n=(n=(n=n.replace(/<(singleselect|multiselect|instantselect)>([\s\S]*?)<\/\1>/gi,function(e,n,t){var i="multi";return"singleselect"===n?i="single":"instantselect"===n&&(i="instant"),'\n\n<div class="markdown-select-trigger" data-type="'.concat(i,'">').concat(t,"</div>\n\n")})).replace(/<selectoption\s+([\s\S]*?)>([\s\S]*?)<\/selectoption>/gi,function(e,n,t){for(var i,a={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2/gi;null!==(i=r.exec(n));)a[i[1]]=i[3];return'<div class="select-option-item" data-id="'.concat(a.id||"",'" data-cd="').concat(a.cd||"false",'">').concat(t,"</div>")})).replace(/<!--<ai_reasoning>(?![\s\S]*?<\/ai_reasoning>-->)[\s\S]*$/gi,"");["ai_reasoning"].forEach(function(e){var t=new RegExp("\x3c!--\\s*(<".concat(e,">[\\s\\S]*?<\\/").concat(e,">)\\s*--\x3e"),"gi");n=n.replace(t,"$1")});var r=0;n=n.replace(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/gi,function(e,n){var t=n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,function(e,n,t){return'<a href="'.concat(t,'" data-shielded="true">').concat(n,"</a>")});return t=t.replace(/</g,"<").replace(/>/g,">"),r++,'<span class="cognitive-card-trigger" data-card-id="card-'.concat(r,'">').concat(t,"</span>")});var s=0;return n.replace(/(\[[^\]]+\]\()([^)]+)(\))/g,function(e,n,t,i){var a=t.replace(/\s/g,"%20");if(a.includes("citationNumber=")){s++;var r=a.includes("?")?"&":"?";return"".concat(n).concat(a).concat(r,"uiUniqueId=").concat(s).concat(i)}return"".concat(n).concat(a).concat(i)})},Te=r.useMemo(function(){return[i.default]},[]),Re=r.useMemo(function(){return[a.default]},[]),Ee=(null==Q?void 0:Q.variantName)||"Selected Behavior",Me=ee.some(function(e){return!(!e.userSelection||!e.options)&&(Array.isArray(e.userSelection)?e.userSelection:[e.userSelection]).some(function(n){var t=e.options.find(function(e){return e.text===n});return"typeYourAnswer"===(null==t?void 0:t.id)||"type your response"===n.trim().toLowerCase()})}),Ae=ie&&j&&(b||se)&&!Me,Le=r.useMemo(function(){return p.parseJsonBlocks(B).some(function(e){return"variant_card"===e.property})},[B]);return console.log("isVariantCard",Le),n.jsxs(n.Fragment,{children:[n.jsxs("div",e.__assign({style:{lineHeight:"1.625rem",fontSize:"1rem",marginTop:"0.5rem",marginBottom:"".concat("assistant"===v?"0.3rem":"0rem"),fontFamily:"Plus Jakarta Sans, sans-serif"}},{children:[n.jsx(t.ReactMarkdown,e.__assign({components:we,rehypePlugins:Te,remarkPlugins:Re},{children:je(B)}),m),j&&Le&&n.jsxs("div",e.__assign({style:{gap:"8px"}},{children:[n.jsxs(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:_,disabled:!b||!Q&&!P||P&&"add"!==K,isStreamEnd:C,onAction:function(){return ve("Add ".concat(Ee),!0,"add")},"data-selected":"add"===K?"true":P?"false":void 0,baseURL:M},{children:["Add ",Ee]})),n.jsxs(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:_,disabled:!b||!Q&&!P||P&&"edit"!==K,isStreamEnd:C,onAction:function(){return ve("Edit ".concat(Ee),!0,"edit")},"data-selected":"edit"===K?"true":P?"false":void 0,baseURL:M},{children:["Edit ",Ee]})),n.jsx(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:_,disabled:!b||P&&"skip"!==K,isStreamEnd:C,onAction:function(){return ve("Skip for now",!0,"skip")},"data-selected":"skip"===K?"true":P?"false":void 0,baseURL:M},{children:"Skip for now"}))]})),Ae&&n.jsx("div",e.__assign({style:{marginTop:"12px",display:"flex",justifyContent:"flex-start"}},{children:n.jsx(d.MarkdownSelect,{type:"instant",options:[{id:"proceed-gaps",label:"Proceed"}],selectedIds:se?["proceed-gaps"]:[],disabled:se,citations:[],onProceed:_e})}))]})),n.jsx("div",e.__assign({style:{display:"flex",maxWidth:"100%"}},{children:n.jsx("div",e.__assign({style:{width:"100%"}},{children:(null==q?void 0:q.length)>0&&W&&!U?n.jsxs("div",e.__assign({style:{marginTop:"10px"}},{children:[n.jsxs("span",{children:["It looks like you've chosen ",q&&0!==q.length?q.some(function(e){return"both tiers"===e.toLowerCase()||"all tiers"===e.toLowerCase()})?"Both Tiers":q.join(", "):"",". Would you like me to proceed?"]}),n.jsx("p",{children:n.jsx("button",e.__assign({style:{padding:"0.5rem 1rem",margin:"0.5rem 0",backgroundColor:"#2661eb",color:"white",border:"none",borderRadius:"8px",cursor:"pointer",fontSize:"0.75rem",fontWeight:"500",fontFamily:"Plus Jakarta Sans, sans-serif"},onClick:ke},{children:"Yes"}))})]})):null}))})),n.jsx(u.default,{isLastMessage:b,isStreamEnd:C,role:v,content:f,messages:h,index:m,onFeedbackSubmit:A})]})};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../node_modules/tslib/tslib.es6.mjs.js"),n=require("react/jsx-runtime"),t=require("../../../../node_modules/react-markdown/lib/react-markdown.js"),i=require("../../../../node_modules/rehype-raw/lib/index.js"),a=require("../../../../node_modules/remark-gfm/index.js"),r=require("react"),s=require("./ClickableChatComponents.js"),o=require("../MarkdownComponents/MarkdownElements.js"),c=require("../../helpers/utils.js"),l=require("./RuleVariantCard.js"),d=require("../MarkdownComponents/MarkdownSelect.js"),u=require("./ChatFeedback.js"),p=require("../../helpers/message-rendering-utils.js");exports.default=function(g){var m=g.index,f=g.content,v=g.role,h=g.messages,_=g.handleStream,S=g.scrollToBottom,b=g.isLastMessage,x=g.onSave,y=g.citations,k=g.setChatSize,w=g.chatSize,C=g.isStreamEnd,j=g.messageIsEnd,T=g.onViewComparison,R=g.onTypeResponseClick,E=g.onComparisonLinkClick,M=g.baseURL,A=g.onFeedbackSubmit,L=r.useState(f),B=L[0],N=L[1],I=r.useState([]),q=I[0],F=I[1],z=r.useState(!1),W=z[0],D=z[1],V=r.useState(!1),U=V[0],J=V[1],O=r.useState(!1),P=O[0],H=O[1],G=r.useState(null),K=G[0],$=G[1],Y=r.useState(null),Q=Y[0],X=Y[1],Z=r.useState([]),ee=Z[0],ne=Z[1],te=r.useState(!1),ie=te[0],ae=te[1],re=r.useState(!1),se=re[0],oe=re[1],ce=r.useState(new Set),le=ce[0],de=ce[1],ue=r.useState(new Set),pe=ue[0],ge=ue[1],me=r.useRef({handleStream:_,onSave:x,selectedTiers:q,tiersSubmitted:U,citations:y,openCardIds:le,openCitationIds:pe,chatSize:w,isLastMessage:b,scrollToBottom:S,isStreamEnd:C,selectedVariant:Q,messageIsEnd:j,isCommitted:P,clickedAction:K,gapSelections:ee,gapsSubmitted:se,onTypeResponseClick:R});me.current={handleStream:_,onSave:x,selectedTiers:q,tiersSubmitted:U,citations:y,openCardIds:le,openCitationIds:pe,chatSize:w,isLastMessage:b,scrollToBottom:S,isStreamEnd:C,selectedVariant:Q,messageIsEnd:j,isCommitted:P,clickedAction:K,gapSelections:ee,gapsSubmitted:se,onTypeResponseClick:R},r.useEffect(function(){X(null),H(!1),$(null),ae(!1),oe(!1),ne([])},[m]),r.useEffect(function(){if(j&&!P&&!Q){var e=je(B).match(/<variant-card[^>]*isselected=["']true["'][^>]*>/i);if(e){var n=e[0].match(/id=["']([^"']+)["']/),t=e[0].match(/variantname=["']([^"']+)["']/),i=e[0].match(/decisionstrength=["']([^"']+)["']/);n&&t&&X({id:n[1],variantName:t[1],decisionStrength:parseInt((null==i?void 0:i[1])||"0")})}}},[B,j,P,Q]);var fe=r.useCallback(function(e,n,t){var i=function(t){var i=new Set(t);return n?i.add(e):i.delete(e),i};"card"===t?de(function(e){return i(e)}):ge(function(e){return i(e)})},[]),ve=r.useCallback(function(e,n,t){void 0===n&&(n=!1);var i=me.current,a=i.handleStream;i.onSave;var r=e.trim();a&&(a(new KeyboardEvent("keydown",{key:"Enter"}),!1,r),n&&t&&(H(!0),$(t))),n||N(function(e){return e.replace(/<button([^>]*)class=["']clickable-button["']([^>]*)>([\s\S]*?)<\/button>/gi,function(e,n,t,i){var a=i.trim(),s='data-selected="'.concat(a===r,'"');return"<button".concat(n,'class="clickable-button" ').concat(s).concat(t,">").concat(i,"</button>")})})},[]),he=r.useCallback(function(e,n){ae(e),ne(n)},[]),_e=r.useCallback(function(){var e=me.current,n=e.handleStream,t=e.gapSelections.map(function(e){var n=Array.isArray(e.userSelection)?e.userSelection.join(", "):e.userSelection;return"".concat(e.name,": ").concat(n||"Skipped")}),i="Here are my choices for the critical gaps:\n".concat(t.join(","));n(new KeyboardEvent("keydown",{key:"Enter"}),!1,i),oe(!0)},[]),Se=r.useCallback(function(e,n){var t=me.current.citations;return t&&t.find(function(t){return t.customMetaData.citation_number&&"Cognitive Decisioning"!==t.customMetaData.citation_title&&t.customMetaData.source===n&&String(t.customMetaData.citation_number)===String(e)})||null},[]),be=r.useCallback(function(n,t){var i=me.current.scrollToBottom,a=Array.isArray(n)?n[0].trim():n.trim();D(!0),F(function(n){var i=e.__spreadArray([],n,!0);if(["both tiers","all tiers"].includes(a.toLowerCase()))i=t?["Both Tiers","Tier 1","Tier 2"]:[];else{t?i.includes(a)||i.push(a):i=i.filter(function(e){return e!==a});var r=i.includes("Tier 1"),s=i.includes("Tier 2");r&&s?i.includes("Both Tiers")||i.push("Both Tiers"):i=i.filter(function(e){return!["Both Tiers","All tiers"].includes(e)})}return i.filter(function(e,n){return i.indexOf(e)===n})}),null==i||i()},[]),xe=r.useCallback(function(e,n,t,i){me.current.isCommitted||n&&X({id:e,variantName:t,decisionStrength:i})},[]),ye=function(){if(!me.current.isCommitted){var e="Edit ".concat((null==Q?void 0:Q.variantName)||"Selected Behavior");ve(e,!0,"edit")}},ke=r.useCallback(function(){var e=me.current,n=e.handleStream,t=e.selectedTiers,i=t.join(" and ");t.some(function(e){return"both tiers"===e.toLowerCase()||"all tiers"===e.toLowerCase()})&&(i="Both Tiers"),n(new KeyboardEvent("keydown",{key:"Enter"}),!1,"".concat(i)),J(!0),D(!1),N(function(e){return e.replace(/<checkbox\s+class=["']clickable-box["'][^>]*>([\s\S]*?)<\/checkbox>/gi,function(e,n){var i=n.trim();return t.includes(i)?e:""})})},[]),we=r.useMemo(function(){return{p:function(t){t.node;var i=e.__rest(t,["node"]);return n.jsx("span",e.__assign({},i,{style:{maxWidth:"100%",wordWrap:"break-word",overflowWrap:"break-word",wordBreak:"break-word",whiteSpace:"normal",overflow:"hidden",display:"block",fontSize:"1rem",lineHeight:"1.625rem",marginBottom:"user"===v?"0":"0.4rem"}},{children:null==i?void 0:i.children}))},code:function(t){t.node;var i=e.__rest(t,["node"]);return n.jsx("span",e.__assign({},i,{style:{maxWidth:"100%",wordWrap:"break-word",overflowWrap:"break-word",wordBreak:"break-word",whiteSpace:"normal",overflow:"hidden",display:"inline-flex",fontSize:"1rem",lineHeight:"1.625rem"}},{children:null==i?void 0:i.children}))},ol:function(t){t.node;var i=e.__rest(t,["node"]);return n.jsx("ol",e.__assign({},i,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==i?void 0:i.children}))},ul:function(t){t.node;var i=e.__rest(t,["node"]);return n.jsx("ul",e.__assign({},i,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==i?void 0:i.children}))},rule:function(t){t.node;var i=e.__rest(t,["node"]);return n.jsx(s.RuleDisplay,{content:c.extractTextFromChildren(i.children)})},button:function(t){var i=t.node,a=t.className,r=e.__rest(t,["node","className"]),o=me.current,c=o.isLastMessage,l=o.handleStream,d=o.isStreamEnd;return n.jsx(s.ActionableButton,e.__assign({node:i,className:a||r.class,handleStream:l,onAction:ve,disabled:!c,isStreamEnd:d,isLastMessage:c,onTypeResponseClick:R,baseURL:M},r))},checkbox:function(t){var i=t.node,a=t.className,r=e.__rest(t,["node","className"]),o=me.current,c=o.selectedTiers,l=o.tiersSubmitted,d=o.isLastMessage;return n.jsx(s.ActionableCheckbox,e.__assign({node:i,className:a||r.class,selectedItems:c,onToggle:be,isSubmitted:l,disabled:!d},r))},a:function(t){var i=me.current,a=i.chatSize,r=i.openCitationIds;return n.jsx(o.MarkdownLinkRenderer,e.__assign({},t,{chatSize:a,openCitationIds:r,getCitationByNumber:Se,handleToggleState:fe,isStreamEnd:me.current.isStreamEnd}))},div:function(t){var i=me.current,a=i.openCardIds,r=i.citations,s=i.isLastMessage,c=i.isStreamEnd,l=i.gapsSubmitted,d=i.onTypeResponseClick;return n.jsx(o.MarkdownDivRenderer,e.__assign({},t,{openCardIds:a,citations:r,handleToggleState:fe,isStreamEnd:c,isLastMessage:s,handleStream:_,onGapValidation:he,isGapsSubmitted:l,onViewComparison:T,onComparisonLinkClick:E,onTypeResponseClick:d}))},span:function(t){var i,a,r;if((null===(i=t.className)||void 0===i?void 0:i.includes("cognitive-card-trigger"))||(null===(a=t.className)||void 0===a?void 0:a.includes("view-form-update-trigger"))||(null===(r=t.className)||void 0===r?void 0:r.includes("view-identified-fields-trigger"))){var s=me.current,c=s.openCardIds,l=s.citations,d=s.isLastMessage,u=s.isStreamEnd,p=!d||u;return n.jsx(o.MarkdownSpanRenderer,e.__assign({},t,{openCardIds:c,citations:l,handleToggleState:fe,onComparisonLinkClick:E,isStreamEnd:p}))}return n.jsx("span",e.__assign({},t))},"variant-card":function(t){t.node;var i=e.__rest(t,["node"]),a=i.variantname,r=i.decisionstrength,s=i.id,o=me.current,c=o.isCommitted,d=o.isLastMessage,u=o.selectedVariant;if(!j)return null;var p=(null==u?void 0:u.id)===s,g=parseInt(r||"0"),m=!c&&d;return n.jsx(l.RuleVariantCard,e.__assign({variantName:a,decisionStrength:g,isEditable:m,isSelected:p,onToggle:function(e){return xe(s,e,a,g)},onEdit:function(){return ye()}},{children:i.children}))},br:function(t){return n.jsx("p",e.__assign({style:{marginBottom:"0.75rem"}},t))}}},[ve,be,Se,fe,v,Q,P,j,he,xe]);r.useEffect(function(){U||(N(f),setTimeout(function(){null==S||S()},50))},[f,U,S]);var Ce=r.useRef(0);r.useEffect(function(){var e=le.size+pe.size;e>0&&0===Ce.current?null==k||k(50):0===e&&Ce.current>0&&(null==k||k(40)),Ce.current=e},[le,pe,k]);var je=function(e){if(!e)return"";for(var n=e,t=function(e){if("critical_gaps"===e.property){var t=e.data,i=(null==t?void 0:t.critical_gaps)||t,a={count:String(i.count||0),decisionStrength:i.critical_gaps_decision_strength||i.decisionStrength||"0",value:i.value||"",gaps:(i.gap_cards||i.gaps||[]).map(function(e,n){var t,i,a,r,s,o,c=p.extractReasoningFromText(e.gap_value||e.value),l=c.text,d=c.aiReasoning,u=e.ai_reasoning||e.aiReasoning||d,g=((null===(t=e.interaction)||void 0===t?void 0:t.options)||e.options||[]).map(function(e){var n,t=p.extractReasoningFromText(e.label||e.text),i=t.text,a=t.aiReasoning,r=e.ai_reasoning||e.aiReasoning||a,s=null!==(n=e.explanation)&&void 0!==n?n:null;if("string"==typeof s)try{s=s.startsWith("[")&&s.endsWith("]")?JSON.parse(s.replace(/"/g,'"')):s?[s]:null}catch(e){s=s?[s]:null}return{id:e.id,text:i,explanation:s,aiReasoning:p.buildAiReasoning(r)}});return{id:e.id||"gap-".concat(n),name:e.gap_name||e.name||"Gap",decisionStrength:e.gap_decision_strength||e.decisionStrength||"0",impact:e.impact||"Medium",value:l,aiReasoning:p.buildAiReasoning(u),inputType:"textfield"===(null===(i=e.interaction)||void 0===i?void 0:i.interaction_type)||"text"===e.inputType?"text":"radioselect"===(null===(a=e.interaction)||void 0===a?void 0:a.interaction_type)||"radio"===(null===(r=e.interaction)||void 0===r?void 0:r.interaction_type)||"radio"===e.inputType?"radio":"checkbox"===(null===(s=e.interaction)||void 0===s?void 0:s.interaction_type)||"checkbox"===e.inputType?"checkbox":"text",options:g,userSelection:"checkbox"===(null===(o=e.interaction)||void 0===o?void 0:o.interaction_type)||"checkbox"===e.inputType?[]:""}})},r=JSON.stringify(a).replace(/"/g,""");n=n.replace(e.rawMatch,'\n\n<div class="critical-gaps-trigger" data-payload="'.concat(r,'"></div>\n\n'))}else if("updated_fields"===e.property||"identified_fields"===e.property){var s=e.data,o={title:"Rule Title",description:"Description",rule_description:"Description",wta:"When to Apply",wnta:"When NOT to Apply",scope:"Tier Information",rule_type:"Rule Type"},c=["ai_reasoning","scheduling_config","is_user_accepted_risk"],l=[];Object.keys(s).forEach(function(e){if(!c.includes(e)&&s[e]){var n=o[e]||e.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()}),t=p.extractReasoningFromText(s[e]),i=t.text,a=t.aiReasoning;i&&l.push({label:"".concat(n,": ").concat(i),reasoning:a})}});var d={title:"updated_fields"===e.property?"View Updated Fields":"View Identified Fields",fields:l},u=(r=JSON.stringify(d).replace(/"/g,"""),"updated_fields"===e.property?"view-form-update-trigger":"view-identified-fields-trigger");n=n.replace(e.rawMatch,'<span class="'.concat(u,'" data-payload="').concat(r,'"></span>'))}else if("variant_card"===e.property){var g=e.data.variants.map(function(e){var n,t,i,a;return'<variant-card id="'.concat(e.id||"",'" variantname="').concat(e.variant_name||e.variantname||"",'" decisionstrength="').concat(null!==(t=null!==(n=e.decision_strength)&&void 0!==n?n:e.decisionstrength)&&void 0!==t?t:"0",'" iseditable="').concat(e.iseditable||"false",'" isselected="').concat(null!==(a=null!==(i=e.is_selected)&&void 0!==i?i:e.isselected)&&void 0!==a?a:"false",'">').concat(e.description||e.innerContent||"","</variant-card>")}).join("\n\n");n=n.replace(e.rawMatch,"\n\n".concat(g,"\n\n"))}else if("rule_validation_card"===e.property){var m=e.data,f=function(e){return String(null!=e?e:"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")};g=(Array.isArray(null==m?void 0:m.validated_rules)?m.validated_rules:[m]).map(function(e){var n=p.extractReasoningFromText(e.rule_description||e.ruleDescription||""),t=n.text,i=n.aiReasoning,a=p.extractReasoningFromText(e.rule_title||e.ruleTitle||""),r=a.text,s=a.aiReasoning,o=i||s,c="";return o&&(c="<ai_reasoning>\n <id>".concat(o.id||"","</id>\n <reason>").concat(o.reason||"","</reason>\n <gap>").concat(o.gap||"","</gap>\n <relevance_score>").concat(o.score||"","</relevance_score>\n </ai_reasoning>")),'<div class="rule-validation-card-trigger"\n data-type="'.concat(f(e.validation_type||e.validationType),'"\n data-decision-strength="').concat(f(e.decision_strength||e.decisionStrength),'"\n data-title="').concat(f(r),'"\n data-tier="').concat(f(e.tier),'"\n data-rule-id="').concat(f(e.rule_id||e.ruleId),'"\n data-description="').concat(f(t),'">\n ').concat(c,"\n </div>")}).join("\n\n");n=n.replace(e.rawMatch,"\n\n".concat(g,"\n\n"))}},i=0,a=p.parseJsonBlocks(n);i<a.length;i++){t(a[i])}n=(n=(n=(n=(n=(n=n.replace(/\\"/g,'"').replace(/\\'/g,"'").replace(/\u00A0/g," ").replace(/\r\n/g,"\n")).replace(/```(?:\w+)?\n?([\s\S]*?)```/gi,"$1")).replace(/<br\s*\/?>/gi,"\n\n")).replace(/<(singleselect|multiselect|instantselect)>([\s\S]*?)<\/\1>/gi,function(e,n,t){var i="multi";return"singleselect"===n?i="single":"instantselect"===n&&(i="instant"),'\n\n<div class="markdown-select-trigger" data-type="'.concat(i,'">').concat(t,"</div>\n\n")})).replace(/<selectoption\s+([\s\S]*?)>([\s\S]*?)<\/selectoption>/gi,function(e,n,t){for(var i,a={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2/gi;null!==(i=r.exec(n));)a[i[1]]=i[3];return'<div class="select-option-item" data-id="'.concat(a.id||"",'" data-cd="').concat(a.cd||"false",'">').concat(t,"</div>")})).replace(/<!--<ai_reasoning>(?![\s\S]*?<\/ai_reasoning>-->)[\s\S]*$/gi,"");["ai_reasoning"].forEach(function(e){var t=new RegExp("\x3c!--\\s*(<".concat(e,">[\\s\\S]*?<\\/").concat(e,">)\\s*--\x3e"),"gi");n=n.replace(t,"$1")});var r=0;n=n.replace(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/gi,function(e,n){var t=n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,function(e,n,t){return'<a href="'.concat(t,'" data-shielded="true">').concat(n,"</a>")});return t=t.replace(/</g,"<").replace(/>/g,">"),r++,'<span class="cognitive-card-trigger" data-card-id="card-'.concat(r,'">').concat(t,"</span>")});var s=0;return n.replace(/(\[[^\]]+\]\()([^)]+)(\))/g,function(e,n,t,i){var a=t.replace(/\s/g,"%20");if(a.includes("citationNumber=")){s++;var r=a.includes("?")?"&":"?";return"".concat(n).concat(a).concat(r,"uiUniqueId=").concat(s).concat(i)}return"".concat(n).concat(a).concat(i)})},Te=r.useMemo(function(){return[i.default]},[]),Re=r.useMemo(function(){return[a.default]},[]),Ee=(null==Q?void 0:Q.variantName)||"Selected Behavior",Me=ee.some(function(e){return!(!e.userSelection||!e.options)&&(Array.isArray(e.userSelection)?e.userSelection:[e.userSelection]).some(function(n){var t=e.options.find(function(e){return e.text===n});return"typeYourAnswer"===(null==t?void 0:t.id)||"type your response"===n.trim().toLowerCase()})}),Ae=ie&&j&&(b||se)&&!Me,Le=r.useMemo(function(){return p.parseJsonBlocks(B).some(function(e){return"variant_card"===e.property})},[B]);return n.jsxs(n.Fragment,{children:[n.jsxs("div",e.__assign({style:{lineHeight:"1.625rem",fontSize:"1rem",marginTop:"0.5rem",marginBottom:"".concat("assistant"===v?"0.3rem":"0rem"),fontFamily:"Plus Jakarta Sans, sans-serif"}},{children:[n.jsx(t.ReactMarkdown,e.__assign({components:we,rehypePlugins:Te,remarkPlugins:Re},{children:je(B)}),m),j&&Le&&n.jsxs("div",e.__assign({style:{gap:"8px"}},{children:[n.jsxs(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:_,disabled:!b||!Q&&!P||P&&"add"!==K,isStreamEnd:C,onAction:function(){return ve("Add ".concat(Ee),!0,"add")},"data-selected":"add"===K?"true":P?"false":void 0,baseURL:M},{children:["Add ",Ee]})),n.jsxs(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:_,disabled:!b||!Q&&!P||P&&"edit"!==K,isStreamEnd:C,onAction:function(){return ve("Edit ".concat(Ee),!0,"edit")},"data-selected":"edit"===K?"true":P?"false":void 0,baseURL:M},{children:["Edit ",Ee]})),n.jsx(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:_,disabled:!b||P&&"skip"!==K,isStreamEnd:C,onAction:function(){return ve("Skip for now",!0,"skip")},"data-selected":"skip"===K?"true":P?"false":void 0,baseURL:M},{children:"Skip for now"}))]})),Ae&&n.jsx("div",e.__assign({style:{marginTop:"12px",display:"flex",justifyContent:"flex-start"}},{children:n.jsx(d.MarkdownSelect,{type:"instant",options:[{id:"proceed-gaps",label:"Proceed"}],selectedIds:se?["proceed-gaps"]:[],disabled:se,citations:[],onProceed:_e})}))]})),n.jsx("div",e.__assign({style:{display:"flex",maxWidth:"100%"}},{children:n.jsx("div",e.__assign({style:{width:"100%"}},{children:(null==q?void 0:q.length)>0&&W&&!U?n.jsxs("div",e.__assign({style:{marginTop:"10px"}},{children:[n.jsxs("span",{children:["It looks like you've chosen ",q&&0!==q.length?q.some(function(e){return"both tiers"===e.toLowerCase()||"all tiers"===e.toLowerCase()})?"Both Tiers":q.join(", "):"",". Would you like me to proceed?"]}),n.jsx("p",{children:n.jsx("button",e.__assign({style:{padding:"0.5rem 1rem",margin:"0.5rem 0",backgroundColor:"#2661eb",color:"white",border:"none",borderRadius:"8px",cursor:"pointer",fontSize:"0.75rem",fontWeight:"500",fontFamily:"Plus Jakarta Sans, sans-serif"},onClick:ke},{children:"Yes"}))})]})):null}))})),n.jsx(u.default,{isLastMessage:b,isStreamEnd:C,role:v,content:f,messages:h,index:m,onFeedbackSubmit:A})]})};
|
|
2
2
|
//# sourceMappingURL=MessageRendering.js.map
|