@e-llm-studio/instant-learning 0.0.207 → 0.0.208
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.
|
@@ -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"),a=require("../../../../node_modules/rehype-raw/lib/index.js"),i=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");exports.default=function(u){var g=u.index,p=u.content,m=u.role;u.messages;var v=u.handleStream,f=u.scrollToBottom,S=u.isLastMessage,h=u.onSave,_=u.citations,x=u.setChatSize,b=u.chatSize,k=u.isStreamEnd,y=u.messageIsEnd,w=u.onViewComparison,C=u.onTypeResponseClick,j=u.onComparisonLinkClick,E=r.useState(p),T=E[0],M=E[1],R=r.useState([]),L=R[0],N=R[1],A=r.useState(!1),B=A[0],I=A[1],q=r.useState(!1),z=q[0],D=q[1],W=r.useState(!1),P=W[0],V=W[1],F=r.useState(null),J=F[0],O=F[1],$=r.useState(null),G=$[0],H=$[1],K=r.useState([]),U=K[0],Y=K[1],X=r.useState(!1),Q=X[0],Z=X[1],ee=r.useState(!1),ne=ee[0],te=ee[1],ae=r.useState(new Set),ie=ae[0],re=ae[1],se=r.useState(new Set),oe=se[0],ce=se[1],le=r.useRef({handleStream:v,onSave:h,selectedTiers:L,tiersSubmitted:z,citations:_,openCardIds:ie,openCitationIds:oe,chatSize:b,isLastMessage:S,scrollToBottom:f,isStreamEnd:k,selectedVariant:G,messageIsEnd:y,isCommitted:P,clickedAction:J,gapSelections:U,gapsSubmitted:ne,onTypeResponseClick:C});le.current={handleStream:v,onSave:h,selectedTiers:L,tiersSubmitted:z,citations:_,openCardIds:ie,openCitationIds:oe,chatSize:b,isLastMessage:S,scrollToBottom:f,isStreamEnd:k,selectedVariant:G,messageIsEnd:y,isCommitted:P,clickedAction:J,gapSelections:U,gapsSubmitted:ne,onTypeResponseClick:C},r.useEffect(function(){H(null),V(!1),O(null),Z(!1),te(!1),Y([])},[g]),r.useEffect(function(){if(y&&!P&&!G){var e=T.match(/<variant-card[^>]*isselected=["']true["'][^>]*>/i);if(e){var n=e[0].match(/id=["']([^"']+)["']/),t=e[0].match(/variantname=["']([^"']+)["']/),a=e[0].match(/decisionstrength=["']([^"']+)["']/);n&&t&&H({id:n[1],variantName:t[1],decisionStrength:parseInt((null==a?void 0:a[1])||"0")})}}},[T,y,P,G]);var de=r.useCallback(function(e,n,t){var a=function(t){var a=new Set(t);return n?a.add(e):a.delete(e),a};"card"===t?re(function(e){return a(e)}):ce(function(e){return a(e)})},[]),ue=r.useCallback(function(e,n,t){void 0===n&&(n=!1);var a=le.current,i=a.handleStream;a.onSave;var r=e.trim();i&&(i(new KeyboardEvent("keydown",{key:"Enter"}),!1,r),n&&t&&(V(!0),O(t))),n||M(function(e){return e.replace(/<button([^>]*)class=["']clickable-button["']([^>]*)>([\s\S]*?)<\/button>/gi,function(e,n,t,a){var i=a.trim(),s='data-selected="'.concat(i===r,'"');return"<button".concat(n,'class="clickable-button" ').concat(s).concat(t,">").concat(a,"</button>")})})},[]),ge=r.useCallback(function(e,n){Z(e),Y(n)},[]),pe=r.useCallback(function(){var e=le.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")}),a="Here are my choices for the critical gaps:\n".concat(t.join(","));n(new KeyboardEvent("keydown",{key:"Enter"}),!1,a),te(!0)},[]),me=r.useCallback(function(e,n){var t=le.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},[]),ve=r.useCallback(function(n,t){var a=le.current.scrollToBottom,i=Array.isArray(n)?n[0].trim():n.trim();I(!0),N(function(n){var a=e.__spreadArray([],n,!0);if(["both tiers","all tiers"].includes(i.toLowerCase()))a=t?["Both Tiers","Tier 1","Tier 2"]:[];else{t?a.includes(i)||a.push(i):a=a.filter(function(e){return e!==i});var r=a.includes("Tier 1"),s=a.includes("Tier 2");r&&s?a.includes("Both Tiers")||a.push("Both Tiers"):a=a.filter(function(e){return!["Both Tiers","All tiers"].includes(e)})}return a.filter(function(e,n){return a.indexOf(e)===n})}),null==a||a()},[]),fe=r.useCallback(function(e,n,t,a){le.current.isCommitted||n&&H({id:e,variantName:t,decisionStrength:a})},[]),Se=function(){if(!le.current.isCommitted){var e="Edit ".concat((null==G?void 0:G.variantName)||"Selected Behavior");ue(e,!0,"edit")}},he=r.useCallback(function(){var e=le.current,n=e.handleStream,t=e.selectedTiers,a=t.join(" and ");t.some(function(e){return"both tiers"===e.toLowerCase()||"all tiers"===e.toLowerCase()})&&(a="Both Tiers"),n(new KeyboardEvent("keydown",{key:"Enter"}),!1,"".concat(a)),D(!0),I(!1),M(function(e){return e.replace(/<checkbox\s+class=["']clickable-box["'][^>]*>([\s\S]*?)<\/checkbox>/gi,function(e,n){var a=n.trim();return t.includes(a)?e:""})})},[]),_e=r.useMemo(function(){return{p:function(t){t.node;var a=e.__rest(t,["node"]);return n.jsx("span",e.__assign({},a,{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"===m?"0":"0.4rem"}},{children:null==a?void 0:a.children}))},code:function(t){t.node;var a=e.__rest(t,["node"]);return n.jsx("span",e.__assign({},a,{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==a?void 0:a.children}))},ol:function(t){t.node;var a=e.__rest(t,["node"]);return n.jsx("ol",e.__assign({},a,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==a?void 0:a.children}))},ul:function(t){t.node;var a=e.__rest(t,["node"]);return n.jsx("ul",e.__assign({},a,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==a?void 0:a.children}))},rule:function(t){t.node;var a=e.__rest(t,["node"]);return n.jsx(s.RuleDisplay,{content:c.extractTextFromChildren(a.children)})},button:function(t){var a=t.node,i=t.className,r=e.__rest(t,["node","className"]),o=le.current,c=o.isLastMessage,l=o.handleStream,d=o.isStreamEnd;return n.jsx(s.ActionableButton,e.__assign({node:a,className:i||r.class,handleStream:l,onAction:ue,disabled:!c,isStreamEnd:d,isLastMessage:c,onTypeResponseClick:C},r))},checkbox:function(t){var a=t.node,i=t.className,r=e.__rest(t,["node","className"]),o=le.current,c=o.selectedTiers,l=o.tiersSubmitted,d=o.isLastMessage;return n.jsx(s.ActionableCheckbox,e.__assign({node:a,className:i||r.class,selectedItems:c,onToggle:ve,isSubmitted:l,disabled:!d},r))},a:function(t){var a=le.current,i=a.chatSize,r=a.openCitationIds;return n.jsx(o.MarkdownLinkRenderer,e.__assign({},t,{chatSize:i,openCitationIds:r,getCitationByNumber:me,handleToggleState:de,isStreamEnd:le.current.isStreamEnd}))},div:function(t){var a=le.current,i=a.openCardIds,r=a.citations,s=a.isLastMessage,c=a.isStreamEnd,l=a.gapsSubmitted,d=a.onTypeResponseClick;return n.jsx(o.MarkdownDivRenderer,e.__assign({},t,{openCardIds:i,citations:r,handleToggleState:de,isStreamEnd:c,isLastMessage:s,handleStream:v,onGapValidation:ge,isGapsSubmitted:l,onViewComparison:w,onComparisonLinkClick:j,onTypeResponseClick:d}))},span:function(t){var a,i,r;if((null===(a=t.className)||void 0===a?void 0:a.includes("cognitive-card-trigger"))||(null===(i=t.className)||void 0===i?void 0:i.includes("view-form-update-trigger"))||(null===(r=t.className)||void 0===r?void 0:r.includes("view-identified-fields-trigger"))){var s=le.current,c=s.openCardIds,l=s.citations,d=s.isLastMessage,u=s.isStreamEnd,g=!d||u;return n.jsx(o.MarkdownSpanRenderer,e.__assign({},t,{openCardIds:c,citations:l,handleToggleState:de,onComparisonLinkClick:j,isStreamEnd:g}))}return n.jsx("span",e.__assign({},t))},"variant-card":function(t){t.node;var a=e.__rest(t,["node"]),i=a.variantname,r=a.decisionstrength,s=a.id,o=le.current,c=o.isCommitted,d=o.isLastMessage,u=o.selectedVariant;if(!y)return null;var g=(null==u?void 0:u.id)===s,p=parseInt(r||"0"),m=!c&&d;return n.jsx(l.RuleVariantCard,e.__assign({variantName:i,decisionStrength:p,isEditable:m,isSelected:g,onToggle:function(e){return fe(s,e,i,p)},onEdit:function(){return Se()}},{children:a.children}))},br:function(t){return n.jsx("p",e.__assign({style:{marginBottom:"0.75rem"}},t))}}},[ue,ve,me,de,m,G,P,y,ge,fe]);r.useEffect(function(){z||(M(p),setTimeout(function(){null==f||f()},50))},[p,z,f]);var xe=r.useRef(0);r.useEffect(function(){var e=ie.size+oe.size;e>0&&0===xe.current?null==x||x(50):0===e&&xe.current>0&&(null==x||x(40)),xe.current=e},[ie,oe,x]);var be=r.useMemo(function(){return[a.default]},[]),ke=r.useMemo(function(){return[i.default]},[]),ye=(null==G?void 0:G.variantName)||"Selected Behavior",we=U.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()})}),Ce=Q&&y&&(S||ne)&&!we;return n.jsxs(n.Fragment,{children:[n.jsxs("div",e.__assign({style:{lineHeight:"1.625rem",fontSize:"1rem",marginTop:"0.5rem",marginBottom:"".concat("assistant"===m?"0.3rem":"0rem"),fontFamily:"Plus Jakarta Sans, sans-serif"}},{children:[n.jsx(t.ReactMarkdown,e.__assign({components:_e,rehypePlugins:be,remarkPlugins:ke},{children:function(n){if(!n)return"";var t=n.replace(/\\"/g,'"').replace(/\\'/g,"'");t=(t=(t=t.replace(/```(?:\w+)?\n?([\s\S]*?)```/gi,"$1")).replace(/<br\s*\/?>/gi,"\n\n")).replace(/(?:<!--\s*)?<critical_gaps\s+([\s\S]*?)>([\s\S]*?)<\/critical_gaps>\s*(?:-->)?/gi,function(n,t,a){try{for(var i={},r=/([a-z0-9_]+)\s*=\s*(["'])([\s\S]*?)\2/gi,s=void 0;null!==(s=r.exec(t));)i[s[1]]=s[3];for(var o=[],c=/<gap_card\s+([\s\S]*?)>([\s\S]*?)<\/gap_card>/gi,l=void 0,d=function(){for(var n=l[1],t=l[2],a={};null!==(s=r.exec(n));)a[s[1]]=s[3];var i=t.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),c=null;if(i){var d=i[1],u=function(e){var n;return(null===(n=d.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===n?void 0:n[1])||""};c={id:u("id"),reason:u("reason"),gap:u("gap"),score:u("relevance_score")}}var g=function(e){var n=e.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),t=e.match(/<explaination\s+value=(["'])([\s\S]*?)\1\s*><\/explaination>/i),a=null,i=null,r=e;if(n){var s=n[1],o=function(e){var n=s.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i"));return n?n[1].replace(/\\n/g,"\n").trim():""};a={id:o("id"),reason:o("reason"),gap:o("gap"),score:o("relevance_score")},r=e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/i,"").trim()}if(t){try{var c=t[2];i=JSON.parse(c.replace(/"/g,'"')),console.log("Parsed Explanation successfully:",i)}catch(e){console.error("Explanation parse error:",e,"Raw value:",t[2])}r=r.replace(/<explaination[\s\S]*?><\/explaination>/i,"")}return{text:r,aiReasoning:a,explanation:i}},p=[],m="text",v=/<(selectoption|radioselect)>/i.test(t),f=/<checkbox>/i.test(t),S=/<textfield>/i.test(t);if(v){m="radio";for(var h=void 0,_=/<selectoption([^>]*)>\s*([\s\S]*?)\s*<\/selectoption>/gi;null!==(h=_.exec(t));){var x=h[1],b=h[2],k=void 0;(C=x.match(/id=["']([^"']+)["']/i))&&(k=C[1]),p.push(e.__assign(e.__assign({},g(b)),{id:k}))}}else if(f){m="checkbox";for(var y=void 0,w=/<checkbox([^>]*)>\s*([\s\S]*?)\s*<\/checkbox>/gi;null!==(y=w.exec(t));){var C,j=y[1];b=y[2],k=void 0;(C=j.match(/id=["']([^"']+)["']/i))&&(k=C[1]),p.push(e.__assign(e.__assign({},g(b)),{id:k}))}}else S&&(m="text");"radio"!==m||0!==p.length||S||(m="text"),o.push({id:"gap-".concat(o.length),name:a.gap_name||"Gap",decisionStrength:a.gap_decision_strength,impact:a.impact,value:a.gap_value,aiReasoning:c,inputType:m,options:p,userSelection:"checkbox"===m?[]:""})};null!==(l=c.exec(a));)d();var u={count:i.count,decisionStrength:i.critical_gaps_decision_strength,value:i.value,gaps:o},g=JSON.stringify(u).replace(/"/g,""");return'\n\n<div class="critical-gaps-trigger" data-payload="'.concat(g,'"></div>\n\n')}catch(e){return console.error("Error parsing critical gaps XML",e),n}}),t=(t=t.replace(/<variant-card\s+([\s\S]*?)>([\s\S]*?)<\/variant-card>/gi,function(e,n,t){for(var a,i={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2(?=\s|>|$)/gi;null!==(a=r.exec(n));)i[a[1]]=a[3];return'\n\n<variant-card id="'.concat(i.id||"",'" variantname="').concat(i.variantname||"",'" decisionstrength="').concat(i.decisionstrength||"0",'" iseditable="').concat(i.iseditable||"false",'" isselected="').concat(i.isselected||"false",'">').concat(t,"</variant-card>\n\n")})).replace(/(?:<!--\s*)?<rule-validation-card\s+([\s\S]*?)(?:\/>|>([\s\S]*?)<\/rule-validation-card>)\s*(?:-->)?/gi,function(e,n,t){void 0===t&&(t="");for(var a,i={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2(?=\s|>|\/>|$)/gi;null!==(a=r.exec(n));)i[a[1]]=a[3];var s=function(e){return(i[e]||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")};return'\n\n<div class="rule-validation-card-trigger" \n data-type="'.concat(s("validationType"),'"\n data-decision-strength="').concat(s("decisionStrength"),'"\n data-title="').concat(s("ruleTitle"),'"\n data-tier="').concat(s("tier"),'"\n data-rule-id="').concat(s("ruleId"),'" \n data-description="').concat(s("ruleDescription"),'">').concat(t,"</div>\n\n")}),console.log("sanitized output2:",t),t=(t=(t=t.replace(/<(singleselect|multiselect|instantselect)>([\s\S]*?)<\/\1>/gi,function(e,n,t){var a="multi";return"singleselect"===n?a="single":"instantselect"===n&&(a="instant"),'\n\n<div class="markdown-select-trigger" data-type="'.concat(a,'">').concat(t,"</div>\n\n")})).replace(/<selectoption\s+([\s\S]*?)>([\s\S]*?)<\/selectoption>/gi,function(e,n,t){for(var a,i={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2/gi;null!==(a=r.exec(n));)i[a[1]]=a[3];return'<div class="select-option-item" data-id="'.concat(i.id||"",'" data-cd="').concat(i.cd||"false",'">').concat(t,"</div>")})).replace(/<view_form_update_card\s+title=["'](.*?)["']>([\s\S]*?)<\/view_form_update_card>/gi,function(e,n,t){for(var a,i=[],r=/<form_value\s+value=["']([\s\S]*?)["']>([\s\S]*?)<\/form_value>/gi,s=function(){var e=a[1],n=a[2],t=function(e){var t;return(null===(t=n.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===t?void 0:t[1])||""};i.push({label:e,reasoning:{id:t("id"),reason:t("reason"),gap:t("gap"),score:t("relevance_score")}})};null!==(a=r.exec(t));)s();var o={title:n||"Updated Fields",fields:i},c=JSON.stringify(o).replace(/"/g,""");return'<span class="view-form-update-trigger" data-payload="'.concat(c,'"></span>')}),t=t.replace(/<view_identified_fields\s+title=["'](.*?)["']>([\s\S]*?)<\/view_identified_fields>/gi,function(e,n,t){for(var a,i=[],r=/<form_value\s+value=["']([\s\S]*?)["']>([\s\S]*?)<\/form_value>/gi,s=function(){var e=a[1],n=a[2],t=function(e){var t;return(null===(t=n.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===t?void 0:t[1])||""};i.push({label:e,reasoning:{id:t("id"),reason:t("reason"),gap:t("gap"),score:t("relevance_score")}})};null!==(a=r.exec(t));)s();var o={title:n||"Identified Fields",fields:i},c=JSON.stringify(o).replace(/"/g,""");return'<span class="view-identified-fields-trigger" data-payload="'.concat(c,'"></span>')}),t=t.replace(/<!--<ai_reasoning>(?![\s\S]*?<\/ai_reasoning>-->)[\s\S]*$/gi,"");["ai_reasoning"].forEach(function(e){var n=new RegExp("\x3c!--\\s*(<".concat(e,">[\\s\\S]*?<\\/").concat(e,">)\\s*--\x3e"),"gi");t=t.replace(n,"$1")});var a=0;t=t.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,">"),a++,'<span class="cognitive-card-trigger" data-card-id="card-'.concat(a,'">').concat(t,"</span>")});var i=0;return t.replace(/(\[[^\]]+\]\()([^)]+)(\))/g,function(e,n,t,a){var r=t.replace(/\s/g,"%20");if(r.includes("citationNumber=")){i++;var s=r.includes("?")?"&":"?";return"".concat(n).concat(r).concat(s,"uiUniqueId=").concat(i).concat(a)}return"".concat(n).concat(r).concat(a)})}(T)}),g),y&&T.includes("<variant-card")&&n.jsxs("div",e.__assign({style:{gap:"8px"}},{children:[n.jsxs(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:v,disabled:!S||!G&&!P||P&&"add"!==J,isStreamEnd:k,onAction:function(){return ue("Add ".concat(ye),!0,"add")},"data-selected":"add"===J?"true":P?"false":void 0},{children:["Add ",ye]})),n.jsxs(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:v,disabled:!S||!G&&!P||P&&"edit"!==J,isStreamEnd:k,onAction:function(){return ue("Edit ".concat(ye),!0,"edit")},"data-selected":"edit"===J?"true":P?"false":void 0},{children:["Edit ",ye]})),n.jsx(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:v,disabled:!S||P&&"skip"!==J,isStreamEnd:k,onAction:function(){return ue("Skip for now",!0,"skip")},"data-selected":"skip"===J?"true":P?"false":void 0},{children:"Skip for now"}))]})),Ce&&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 to Fix Gaps"}],selectedIds:ne?["proceed-gaps"]:[],disabled:ne,citations:[],onProceed:pe})}))]})),n.jsx("div",e.__assign({style:{display:"flex",maxWidth:"100%"}},{children:n.jsx("div",e.__assign({style:{width:"100%"}},{children:(null==L?void 0:L.length)>0&&B&&!z?n.jsxs("div",e.__assign({style:{marginTop:"10px"}},{children:[n.jsxs("span",{children:["It looks like you've chosen ",L&&0!==L.length?L.some(function(e){return"both tiers"===e.toLowerCase()||"all tiers"===e.toLowerCase()})?"Both Tiers":L.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:he},{children:"Yes"}))})]})):null}))}))]})};
|
|
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"),a=require("../../../../node_modules/rehype-raw/lib/index.js"),i=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");exports.default=function(u){var g=u.index,p=u.content,m=u.role;u.messages;var v=u.handleStream,f=u.scrollToBottom,S=u.isLastMessage,h=u.onSave,_=u.citations,x=u.setChatSize,b=u.chatSize,k=u.isStreamEnd,y=u.messageIsEnd,w=u.onViewComparison,C=u.onTypeResponseClick,j=u.onComparisonLinkClick,E=r.useState(p),T=E[0],M=E[1],R=r.useState([]),L=R[0],N=R[1],A=r.useState(!1),B=A[0],I=A[1],q=r.useState(!1),z=q[0],D=q[1],W=r.useState(!1),P=W[0],V=W[1],F=r.useState(null),J=F[0],O=F[1],$=r.useState(null),G=$[0],H=$[1],K=r.useState([]),U=K[0],Y=K[1],X=r.useState(!1),Q=X[0],Z=X[1],ee=r.useState(!1),ne=ee[0],te=ee[1],ae=r.useState(new Set),ie=ae[0],re=ae[1],se=r.useState(new Set),oe=se[0],ce=se[1],le=r.useRef({handleStream:v,onSave:h,selectedTiers:L,tiersSubmitted:z,citations:_,openCardIds:ie,openCitationIds:oe,chatSize:b,isLastMessage:S,scrollToBottom:f,isStreamEnd:k,selectedVariant:G,messageIsEnd:y,isCommitted:P,clickedAction:J,gapSelections:U,gapsSubmitted:ne,onTypeResponseClick:C});le.current={handleStream:v,onSave:h,selectedTiers:L,tiersSubmitted:z,citations:_,openCardIds:ie,openCitationIds:oe,chatSize:b,isLastMessage:S,scrollToBottom:f,isStreamEnd:k,selectedVariant:G,messageIsEnd:y,isCommitted:P,clickedAction:J,gapSelections:U,gapsSubmitted:ne,onTypeResponseClick:C},r.useEffect(function(){H(null),V(!1),O(null),Z(!1),te(!1),Y([])},[g]),r.useEffect(function(){if(y&&!P&&!G){var e=T.match(/<variant-card[^>]*isselected=["']true["'][^>]*>/i);if(e){var n=e[0].match(/id=["']([^"']+)["']/),t=e[0].match(/variantname=["']([^"']+)["']/),a=e[0].match(/decisionstrength=["']([^"']+)["']/);n&&t&&H({id:n[1],variantName:t[1],decisionStrength:parseInt((null==a?void 0:a[1])||"0")})}}},[T,y,P,G]);var de=r.useCallback(function(e,n,t){var a=function(t){var a=new Set(t);return n?a.add(e):a.delete(e),a};"card"===t?re(function(e){return a(e)}):ce(function(e){return a(e)})},[]),ue=r.useCallback(function(e,n,t){void 0===n&&(n=!1);var a=le.current,i=a.handleStream;a.onSave;var r=e.trim();i&&(i(new KeyboardEvent("keydown",{key:"Enter"}),!1,r),n&&t&&(V(!0),O(t))),n||M(function(e){return e.replace(/<button([^>]*)class=["']clickable-button["']([^>]*)>([\s\S]*?)<\/button>/gi,function(e,n,t,a){var i=a.trim(),s='data-selected="'.concat(i===r,'"');return"<button".concat(n,'class="clickable-button" ').concat(s).concat(t,">").concat(a,"</button>")})})},[]),ge=r.useCallback(function(e,n){Z(e),Y(n)},[]),pe=r.useCallback(function(){var e=le.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")}),a="Here are my choices for the critical gaps:\n".concat(t.join(","));n(new KeyboardEvent("keydown",{key:"Enter"}),!1,a),te(!0)},[]),me=r.useCallback(function(e,n){var t=le.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},[]),ve=r.useCallback(function(n,t){var a=le.current.scrollToBottom,i=Array.isArray(n)?n[0].trim():n.trim();I(!0),N(function(n){var a=e.__spreadArray([],n,!0);if(["both tiers","all tiers"].includes(i.toLowerCase()))a=t?["Both Tiers","Tier 1","Tier 2"]:[];else{t?a.includes(i)||a.push(i):a=a.filter(function(e){return e!==i});var r=a.includes("Tier 1"),s=a.includes("Tier 2");r&&s?a.includes("Both Tiers")||a.push("Both Tiers"):a=a.filter(function(e){return!["Both Tiers","All tiers"].includes(e)})}return a.filter(function(e,n){return a.indexOf(e)===n})}),null==a||a()},[]),fe=r.useCallback(function(e,n,t,a){le.current.isCommitted||n&&H({id:e,variantName:t,decisionStrength:a})},[]),Se=function(){if(!le.current.isCommitted){var e="Edit ".concat((null==G?void 0:G.variantName)||"Selected Behavior");ue(e,!0,"edit")}},he=r.useCallback(function(){var e=le.current,n=e.handleStream,t=e.selectedTiers,a=t.join(" and ");t.some(function(e){return"both tiers"===e.toLowerCase()||"all tiers"===e.toLowerCase()})&&(a="Both Tiers"),n(new KeyboardEvent("keydown",{key:"Enter"}),!1,"".concat(a)),D(!0),I(!1),M(function(e){return e.replace(/<checkbox\s+class=["']clickable-box["'][^>]*>([\s\S]*?)<\/checkbox>/gi,function(e,n){var a=n.trim();return t.includes(a)?e:""})})},[]),_e=r.useMemo(function(){return{p:function(t){t.node;var a=e.__rest(t,["node"]);return n.jsx("span",e.__assign({},a,{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"===m?"0":"0.4rem"}},{children:null==a?void 0:a.children}))},code:function(t){t.node;var a=e.__rest(t,["node"]);return n.jsx("span",e.__assign({},a,{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==a?void 0:a.children}))},ol:function(t){t.node;var a=e.__rest(t,["node"]);return n.jsx("ol",e.__assign({},a,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==a?void 0:a.children}))},ul:function(t){t.node;var a=e.__rest(t,["node"]);return n.jsx("ul",e.__assign({},a,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==a?void 0:a.children}))},rule:function(t){t.node;var a=e.__rest(t,["node"]);return n.jsx(s.RuleDisplay,{content:c.extractTextFromChildren(a.children)})},button:function(t){var a=t.node,i=t.className,r=e.__rest(t,["node","className"]),o=le.current,c=o.isLastMessage,l=o.handleStream,d=o.isStreamEnd;return n.jsx(s.ActionableButton,e.__assign({node:a,className:i||r.class,handleStream:l,onAction:ue,disabled:!c,isStreamEnd:d,isLastMessage:c,onTypeResponseClick:C},r))},checkbox:function(t){var a=t.node,i=t.className,r=e.__rest(t,["node","className"]),o=le.current,c=o.selectedTiers,l=o.tiersSubmitted,d=o.isLastMessage;return n.jsx(s.ActionableCheckbox,e.__assign({node:a,className:i||r.class,selectedItems:c,onToggle:ve,isSubmitted:l,disabled:!d},r))},a:function(t){var a=le.current,i=a.chatSize,r=a.openCitationIds;return n.jsx(o.MarkdownLinkRenderer,e.__assign({},t,{chatSize:i,openCitationIds:r,getCitationByNumber:me,handleToggleState:de,isStreamEnd:le.current.isStreamEnd}))},div:function(t){var a=le.current,i=a.openCardIds,r=a.citations,s=a.isLastMessage,c=a.isStreamEnd,l=a.gapsSubmitted,d=a.onTypeResponseClick;return n.jsx(o.MarkdownDivRenderer,e.__assign({},t,{openCardIds:i,citations:r,handleToggleState:de,isStreamEnd:c,isLastMessage:s,handleStream:v,onGapValidation:ge,isGapsSubmitted:l,onViewComparison:w,onComparisonLinkClick:j,onTypeResponseClick:d}))},span:function(t){var a,i,r;if((null===(a=t.className)||void 0===a?void 0:a.includes("cognitive-card-trigger"))||(null===(i=t.className)||void 0===i?void 0:i.includes("view-form-update-trigger"))||(null===(r=t.className)||void 0===r?void 0:r.includes("view-identified-fields-trigger"))){var s=le.current,c=s.openCardIds,l=s.citations,d=s.isLastMessage,u=s.isStreamEnd,g=!d||u;return n.jsx(o.MarkdownSpanRenderer,e.__assign({},t,{openCardIds:c,citations:l,handleToggleState:de,onComparisonLinkClick:j,isStreamEnd:g}))}return n.jsx("span",e.__assign({},t))},"variant-card":function(t){t.node;var a=e.__rest(t,["node"]),i=a.variantname,r=a.decisionstrength,s=a.id,o=le.current,c=o.isCommitted,d=o.isLastMessage,u=o.selectedVariant;if(!y)return null;var g=(null==u?void 0:u.id)===s,p=parseInt(r||"0"),m=!c&&d;return n.jsx(l.RuleVariantCard,e.__assign({variantName:i,decisionStrength:p,isEditable:m,isSelected:g,onToggle:function(e){return fe(s,e,i,p)},onEdit:function(){return Se()}},{children:a.children}))},br:function(t){return n.jsx("p",e.__assign({style:{marginBottom:"0.75rem"}},t))}}},[ue,ve,me,de,m,G,P,y,ge,fe]);r.useEffect(function(){z||(M(p),setTimeout(function(){null==f||f()},50))},[p,z,f]);var xe=r.useRef(0);r.useEffect(function(){var e=ie.size+oe.size;e>0&&0===xe.current?null==x||x(50):0===e&&xe.current>0&&(null==x||x(40)),xe.current=e},[ie,oe,x]);var be=r.useMemo(function(){return[a.default]},[]),ke=r.useMemo(function(){return[i.default]},[]),ye=(null==G?void 0:G.variantName)||"Selected Behavior",we=U.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()})}),Ce=Q&&y&&(S||ne)&&!we;return n.jsxs(n.Fragment,{children:[n.jsxs("div",e.__assign({style:{lineHeight:"1.625rem",fontSize:"1rem",marginTop:"0.5rem",marginBottom:"".concat("assistant"===m?"0.3rem":"0rem"),fontFamily:"Plus Jakarta Sans, sans-serif"}},{children:[n.jsx(t.ReactMarkdown,e.__assign({components:_e,rehypePlugins:be,remarkPlugins:ke},{children:function(n){if(!n)return"";var t=n.replace(/\\"/g,'"').replace(/\\'/g,"'");t=(t=(t=t.replace(/```(?:\w+)?\n?([\s\S]*?)```/gi,"$1")).replace(/<br\s*\/?>/gi,"\n\n")).replace(/(?:<!--\s*)?<critical_gaps\s+([\s\S]*?)>([\s\S]*?)<\/critical_gaps>\s*(?:-->)?/gi,function(n,t,a){try{for(var i={},r=/([a-z0-9_]+)\s*=\s*(["'])([\s\S]*?)\2/gi,s=void 0;null!==(s=r.exec(t));)i[s[1]]=s[3];for(var o=[],c=/<gap_card\s+([\s\S]*?)>([\s\S]*?)<\/gap_card>/gi,l=void 0,d=function(){for(var n=l[1],t=l[2],a={};null!==(s=r.exec(n));)a[s[1]]=s[3];var i=t.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),c=null;if(i){var d=i[1],u=function(e){var n;return(null===(n=d.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===n?void 0:n[1])||""};c={id:u("id"),reason:u("reason"),gap:u("gap"),score:u("relevance_score")}}var g=function(e){var n=e.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),t=e.match(/<explaination\s+value=(["'])([\s\S]*?)\1\s*>[\s\S]*?<\/explaination>/i),a=null,i=null,r=e;if(n){var s=n[1],o=function(e){var n=s.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i"));return n?n[1].replace(/\\n/g,"\n").trim():""};a={id:o("id"),reason:o("reason"),gap:o("gap"),score:o("relevance_score")},r=e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/i,"").trim()}if(t){try{var c=t[2];i=JSON.parse(c.replace(/"/g,'"')),console.log("Parsed Explanation successfully:",i)}catch(e){console.error("Explanation parse error:",e,"Raw value:",t[2])}r=r.replace(/<explaination[\s\S]*?>[\s\S]*?<\/explaination>/i,"").trim()}return{text:r,aiReasoning:a,explanation:i}},p=[],m="text",v=/<(selectoption|radioselect)>/i.test(t),f=/<checkbox>/i.test(t),S=/<textfield>/i.test(t);if(v){m="radio";for(var h=void 0,_=/<selectoption([^>]*)>\s*([\s\S]*?)\s*<\/selectoption>/gi;null!==(h=_.exec(t));){var x=h[1],b=h[2],k=void 0;(C=x.match(/id=["']([^"']+)["']/i))&&(k=C[1]),p.push(e.__assign(e.__assign({},g(b)),{id:k}))}}else if(f){m="checkbox";for(var y=void 0,w=/<checkbox([^>]*)>\s*([\s\S]*?)\s*<\/checkbox>/gi;null!==(y=w.exec(t));){var C,j=y[1];b=y[2],k=void 0;(C=j.match(/id=["']([^"']+)["']/i))&&(k=C[1]),p.push(e.__assign(e.__assign({},g(b)),{id:k}))}}else S&&(m="text");"radio"!==m||0!==p.length||S||(m="text"),o.push({id:"gap-".concat(o.length),name:a.gap_name||"Gap",decisionStrength:a.gap_decision_strength,impact:a.impact,value:a.gap_value,aiReasoning:c,inputType:m,options:p,userSelection:"checkbox"===m?[]:""})};null!==(l=c.exec(a));)d();var u={count:i.count,decisionStrength:i.critical_gaps_decision_strength,value:i.value,gaps:o},g=JSON.stringify(u).replace(/"/g,""");return'\n\n<div class="critical-gaps-trigger" data-payload="'.concat(g,'"></div>\n\n')}catch(e){return console.error("Error parsing critical gaps XML",e),n}}),t=(t=t.replace(/<variant-card\s+([\s\S]*?)>([\s\S]*?)<\/variant-card>/gi,function(e,n,t){for(var a,i={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2(?=\s|>|$)/gi;null!==(a=r.exec(n));)i[a[1]]=a[3];return'\n\n<variant-card id="'.concat(i.id||"",'" variantname="').concat(i.variantname||"",'" decisionstrength="').concat(i.decisionstrength||"0",'" iseditable="').concat(i.iseditable||"false",'" isselected="').concat(i.isselected||"false",'">').concat(t,"</variant-card>\n\n")})).replace(/(?:<!--\s*)?<rule-validation-card\s+([\s\S]*?)(?:\/>|>([\s\S]*?)<\/rule-validation-card>)\s*(?:-->)?/gi,function(e,n,t){void 0===t&&(t="");for(var a,i={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2(?=\s|>|\/>|$)/gi;null!==(a=r.exec(n));)i[a[1]]=a[3];var s=function(e){return(i[e]||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")};return'\n\n<div class="rule-validation-card-trigger" \n data-type="'.concat(s("validationType"),'"\n data-decision-strength="').concat(s("decisionStrength"),'"\n data-title="').concat(s("ruleTitle"),'"\n data-tier="').concat(s("tier"),'"\n data-rule-id="').concat(s("ruleId"),'" \n data-description="').concat(s("ruleDescription"),'">').concat(t,"</div>\n\n")}),console.log("sanitized output2:",t),t=(t=(t=t.replace(/<(singleselect|multiselect|instantselect)>([\s\S]*?)<\/\1>/gi,function(e,n,t){var a="multi";return"singleselect"===n?a="single":"instantselect"===n&&(a="instant"),'\n\n<div class="markdown-select-trigger" data-type="'.concat(a,'">').concat(t,"</div>\n\n")})).replace(/<selectoption\s+([\s\S]*?)>([\s\S]*?)<\/selectoption>/gi,function(e,n,t){for(var a,i={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2/gi;null!==(a=r.exec(n));)i[a[1]]=a[3];return'<div class="select-option-item" data-id="'.concat(i.id||"",'" data-cd="').concat(i.cd||"false",'">').concat(t,"</div>")})).replace(/<view_form_update_card\s+title=["'](.*?)["']>([\s\S]*?)<\/view_form_update_card>/gi,function(e,n,t){for(var a,i=[],r=/<form_value\s+value=["']([\s\S]*?)["']>([\s\S]*?)<\/form_value>/gi,s=function(){var e=a[1],n=a[2],t=function(e){var t;return(null===(t=n.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===t?void 0:t[1])||""};i.push({label:e,reasoning:{id:t("id"),reason:t("reason"),gap:t("gap"),score:t("relevance_score")}})};null!==(a=r.exec(t));)s();var o={title:n||"Updated Fields",fields:i},c=JSON.stringify(o).replace(/"/g,""");return'<span class="view-form-update-trigger" data-payload="'.concat(c,'"></span>')}),t=t.replace(/<view_identified_fields\s+title=["'](.*?)["']>([\s\S]*?)<\/view_identified_fields>/gi,function(e,n,t){for(var a,i=[],r=/<form_value\s+value=["']([\s\S]*?)["']>([\s\S]*?)<\/form_value>/gi,s=function(){var e=a[1],n=a[2],t=function(e){var t;return(null===(t=n.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===t?void 0:t[1])||""};i.push({label:e,reasoning:{id:t("id"),reason:t("reason"),gap:t("gap"),score:t("relevance_score")}})};null!==(a=r.exec(t));)s();var o={title:n||"Identified Fields",fields:i},c=JSON.stringify(o).replace(/"/g,""");return'<span class="view-identified-fields-trigger" data-payload="'.concat(c,'"></span>')}),t=t.replace(/<!--<ai_reasoning>(?![\s\S]*?<\/ai_reasoning>-->)[\s\S]*$/gi,"");["ai_reasoning"].forEach(function(e){var n=new RegExp("\x3c!--\\s*(<".concat(e,">[\\s\\S]*?<\\/").concat(e,">)\\s*--\x3e"),"gi");t=t.replace(n,"$1")});var a=0;t=t.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,">"),a++,'<span class="cognitive-card-trigger" data-card-id="card-'.concat(a,'">').concat(t,"</span>")});var i=0;return t.replace(/(\[[^\]]+\]\()([^)]+)(\))/g,function(e,n,t,a){var r=t.replace(/\s/g,"%20");if(r.includes("citationNumber=")){i++;var s=r.includes("?")?"&":"?";return"".concat(n).concat(r).concat(s,"uiUniqueId=").concat(i).concat(a)}return"".concat(n).concat(r).concat(a)})}(T)}),g),y&&T.includes("<variant-card")&&n.jsxs("div",e.__assign({style:{gap:"8px"}},{children:[n.jsxs(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:v,disabled:!S||!G&&!P||P&&"add"!==J,isStreamEnd:k,onAction:function(){return ue("Add ".concat(ye),!0,"add")},"data-selected":"add"===J?"true":P?"false":void 0},{children:["Add ",ye]})),n.jsxs(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:v,disabled:!S||!G&&!P||P&&"edit"!==J,isStreamEnd:k,onAction:function(){return ue("Edit ".concat(ye),!0,"edit")},"data-selected":"edit"===J?"true":P?"false":void 0},{children:["Edit ",ye]})),n.jsx(s.ActionableButton,e.__assign({className:"clickable-button",handleStream:v,disabled:!S||P&&"skip"!==J,isStreamEnd:k,onAction:function(){return ue("Skip for now",!0,"skip")},"data-selected":"skip"===J?"true":P?"false":void 0},{children:"Skip for now"}))]})),Ce&&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 to Fix Gaps"}],selectedIds:ne?["proceed-gaps"]:[],disabled:ne,citations:[],onProceed:pe})}))]})),n.jsx("div",e.__assign({style:{display:"flex",maxWidth:"100%"}},{children:n.jsx("div",e.__assign({style:{width:"100%"}},{children:(null==L?void 0:L.length)>0&&B&&!z?n.jsxs("div",e.__assign({style:{marginTop:"10px"}},{children:[n.jsxs("span",{children:["It looks like you've chosen ",L&&0!==L.length?L.some(function(e){return"both tiers"===e.toLowerCase()||"all tiers"===e.toLowerCase()})?"Both Tiers":L.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:he},{children:"Yes"}))})]})):null}))}))]})};
|
|
2
2
|
//# sourceMappingURL=MessageRendering.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__spreadArray as e,__rest as n,__assign as t}from"../../../../node_modules/tslib/tslib.es6.mjs.js";import{jsx as i,jsxs as a,Fragment as r}from"react/jsx-runtime";import{ReactMarkdown as o}from"../../../../node_modules/react-markdown/lib/react-markdown.js";import s from"../../../../node_modules/rehype-raw/lib/index.js";import c from"../../../../node_modules/remark-gfm/index.js";import{useState as l,useRef as d,useEffect as u,useCallback as p,useMemo as m}from"react";import{RuleDisplay as g,ActionableButton as v,ActionableCheckbox as f}from"./ClickableChatComponents.js";import{MarkdownLinkRenderer as S,MarkdownDivRenderer as h,MarkdownSpanRenderer as b}from"../MarkdownComponents/MarkdownElements.js";import{extractTextFromChildren as y}from"../../helpers/utils.js";import{RuleVariantCard as k}from"./RuleVariantCard.js";import{MarkdownSelect as w}from"../MarkdownComponents/MarkdownSelect.js";var x=function(x){var _=x.index,C=x.content,E=x.role;x.messages;var T=x.handleStream,N=x.scrollToBottom,L=x.isLastMessage,I=x.onSave,M=x.citations,B=x.setChatSize,z=x.chatSize,j=x.isStreamEnd,A=x.messageIsEnd,R=x.onViewComparison,W=x.onTypeResponseClick,D=x.onComparisonLinkClick,P=l(C),V=P[0],q=P[1],J=l([]),F=J[0],O=J[1],$=l(!1),G=$[0],H=$[1],K=l(!1),U=K[0],Y=K[1],X=l(!1),Q=X[0],Z=X[1],ee=l(null),ne=ee[0],te=ee[1],ie=l(null),ae=ie[0],re=ie[1],oe=l([]),se=oe[0],ce=oe[1],le=l(!1),de=le[0],ue=le[1],pe=l(!1),me=pe[0],ge=pe[1],ve=l(new Set),fe=ve[0],Se=ve[1],he=l(new Set),be=he[0],ye=he[1],ke=d({handleStream:T,onSave:I,selectedTiers:F,tiersSubmitted:U,citations:M,openCardIds:fe,openCitationIds:be,chatSize:z,isLastMessage:L,scrollToBottom:N,isStreamEnd:j,selectedVariant:ae,messageIsEnd:A,isCommitted:Q,clickedAction:ne,gapSelections:se,gapsSubmitted:me,onTypeResponseClick:W});ke.current={handleStream:T,onSave:I,selectedTiers:F,tiersSubmitted:U,citations:M,openCardIds:fe,openCitationIds:be,chatSize:z,isLastMessage:L,scrollToBottom:N,isStreamEnd:j,selectedVariant:ae,messageIsEnd:A,isCommitted:Q,clickedAction:ne,gapSelections:se,gapsSubmitted:me,onTypeResponseClick:W},u(function(){re(null),Z(!1),te(null),ue(!1),ge(!1),ce([])},[_]),u(function(){if(A&&!Q&&!ae){var e=V.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&&re({id:n[1],variantName:t[1],decisionStrength:parseInt((null==i?void 0:i[1])||"0")})}}},[V,A,Q,ae]);var we=p(function(e,n,t){var i=function(t){var i=new Set(t);return n?i.add(e):i.delete(e),i};"card"===t?Se(function(e){return i(e)}):ye(function(e){return i(e)})},[]),xe=p(function(e,n,t){void 0===n&&(n=!1);var i=ke.current,a=i.handleStream;i.onSave;var r=e.trim();a&&(a(new KeyboardEvent("keydown",{key:"Enter"}),!1,r),n&&t&&(Z(!0),te(t))),n||q(function(e){return e.replace(/<button([^>]*)class=["']clickable-button["']([^>]*)>([\s\S]*?)<\/button>/gi,function(e,n,t,i){var a=i.trim(),o='data-selected="'.concat(a===r,'"');return"<button".concat(n,'class="clickable-button" ').concat(o).concat(t,">").concat(i,"</button>")})})},[]),_e=p(function(e,n){ue(e),ce(n)},[]),Ce=p(function(){var e=ke.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),ge(!0)},[]),Ee=p(function(e,n){var t=ke.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},[]),Te=p(function(n,t){var i=ke.current.scrollToBottom,a=Array.isArray(n)?n[0].trim():n.trim();H(!0),O(function(n){var i=e([],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"),o=i.includes("Tier 2");r&&o?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()},[]),Ne=p(function(e,n,t,i){ke.current.isCommitted||n&&re({id:e,variantName:t,decisionStrength:i})},[]),Le=function(){if(!ke.current.isCommitted){var e="Edit ".concat((null==ae?void 0:ae.variantName)||"Selected Behavior");xe(e,!0,"edit")}},Ie=p(function(){var e=ke.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)),Y(!0),H(!1),q(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:""})})},[]),Me=m(function(){return{p:function(e){e.node;var a=n(e,["node"]);return i("span",t({},a,{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"===E?"0":"0.4rem"}},{children:null==a?void 0:a.children}))},code:function(e){e.node;var a=n(e,["node"]);return i("span",t({},a,{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==a?void 0:a.children}))},ol:function(e){e.node;var a=n(e,["node"]);return i("ol",t({},a,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==a?void 0:a.children}))},ul:function(e){e.node;var a=n(e,["node"]);return i("ul",t({},a,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==a?void 0:a.children}))},rule:function(e){e.node;var t=n(e,["node"]);return i(g,{content:y(t.children)})},button:function(e){var a=e.node,r=e.className,o=n(e,["node","className"]),s=ke.current,c=s.isLastMessage,l=s.handleStream,d=s.isStreamEnd;return i(v,t({node:a,className:r||o.class,handleStream:l,onAction:xe,disabled:!c,isStreamEnd:d,isLastMessage:c,onTypeResponseClick:W},o))},checkbox:function(e){var a=e.node,r=e.className,o=n(e,["node","className"]),s=ke.current,c=s.selectedTiers,l=s.tiersSubmitted,d=s.isLastMessage;return i(f,t({node:a,className:r||o.class,selectedItems:c,onToggle:Te,isSubmitted:l,disabled:!d},o))},a:function(e){var n=ke.current,a=n.chatSize,r=n.openCitationIds;return i(S,t({},e,{chatSize:a,openCitationIds:r,getCitationByNumber:Ee,handleToggleState:we,isStreamEnd:ke.current.isStreamEnd}))},div:function(e){var n=ke.current,a=n.openCardIds,r=n.citations,o=n.isLastMessage,s=n.isStreamEnd,c=n.gapsSubmitted,l=n.onTypeResponseClick;return i(h,t({},e,{openCardIds:a,citations:r,handleToggleState:we,isStreamEnd:s,isLastMessage:o,handleStream:T,onGapValidation:_e,isGapsSubmitted:c,onViewComparison:R,onComparisonLinkClick:D,onTypeResponseClick:l}))},span:function(e){var n,a,r;if((null===(n=e.className)||void 0===n?void 0:n.includes("cognitive-card-trigger"))||(null===(a=e.className)||void 0===a?void 0:a.includes("view-form-update-trigger"))||(null===(r=e.className)||void 0===r?void 0:r.includes("view-identified-fields-trigger"))){var o=ke.current,s=o.openCardIds,c=o.citations,l=o.isLastMessage,d=o.isStreamEnd;return i(b,t({},e,{openCardIds:s,citations:c,handleToggleState:we,onComparisonLinkClick:D,isStreamEnd:!l||d}))}return i("span",t({},e))},"variant-card":function(e){e.node;var a=n(e,["node"]),r=a.variantname,o=a.decisionstrength,s=a.id,c=ke.current,l=c.isCommitted,d=c.isLastMessage,u=c.selectedVariant;if(!A)return null;var p=(null==u?void 0:u.id)===s,m=parseInt(o||"0");return i(k,t({variantName:r,decisionStrength:m,isEditable:!l&&d,isSelected:p,onToggle:function(e){return Ne(s,e,r,m)},onEdit:function(){return Le()}},{children:a.children}))},br:function(e){return i("p",t({style:{marginBottom:"0.75rem"}},e))}}},[xe,Te,Ee,we,E,ae,Q,A,_e,Ne]);u(function(){U||(q(C),setTimeout(function(){null==N||N()},50))},[C,U,N]);var Be=d(0);u(function(){var e=fe.size+be.size;e>0&&0===Be.current?null==B||B(50):0===e&&Be.current>0&&(null==B||B(40)),Be.current=e},[fe,be,B]);var ze=m(function(){return[s]},[]),je=m(function(){return[c]},[]),Ae=(null==ae?void 0:ae.variantName)||"Selected Behavior",Re=se.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()})}),We=de&&A&&(L||me)&&!Re;return a(r,{children:[a("div",t({style:{lineHeight:"1.625rem",fontSize:"1rem",marginTop:"0.5rem",marginBottom:"".concat("assistant"===E?"0.3rem":"0rem"),fontFamily:"Plus Jakarta Sans, sans-serif"}},{children:[i(o,t({components:Me,rehypePlugins:ze,remarkPlugins:je},{children:function(e){if(!e)return"";var n=e.replace(/\\"/g,'"').replace(/\\'/g,"'");n=(n=(n=n.replace(/```(?:\w+)?\n?([\s\S]*?)```/gi,"$1")).replace(/<br\s*\/?>/gi,"\n\n")).replace(/(?:<!--\s*)?<critical_gaps\s+([\s\S]*?)>([\s\S]*?)<\/critical_gaps>\s*(?:-->)?/gi,function(e,n,i){try{for(var a={},r=/([a-z0-9_]+)\s*=\s*(["'])([\s\S]*?)\2/gi,o=void 0;null!==(o=r.exec(n));)a[o[1]]=o[3];for(var s=[],c=/<gap_card\s+([\s\S]*?)>([\s\S]*?)<\/gap_card>/gi,l=void 0,d=function(){for(var e=l[1],n=l[2],i={};null!==(o=r.exec(e));)i[o[1]]=o[3];var a=n.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),c=null;if(a){var d=a[1],u=function(e){var n;return(null===(n=d.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===n?void 0:n[1])||""};c={id:u("id"),reason:u("reason"),gap:u("gap"),score:u("relevance_score")}}var p=function(e){var n=e.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),t=e.match(/<explaination\s+value=(["'])([\s\S]*?)\1\s*><\/explaination>/i),i=null,a=null,r=e;if(n){var o=n[1],s=function(e){var n=o.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i"));return n?n[1].replace(/\\n/g,"\n").trim():""};i={id:s("id"),reason:s("reason"),gap:s("gap"),score:s("relevance_score")},r=e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/i,"").trim()}if(t){try{var c=t[2];a=JSON.parse(c.replace(/"/g,'"')),console.log("Parsed Explanation successfully:",a)}catch(e){console.error("Explanation parse error:",e,"Raw value:",t[2])}r=r.replace(/<explaination[\s\S]*?><\/explaination>/i,"")}return{text:r,aiReasoning:i,explanation:a}},m=[],g="text",v=/<(selectoption|radioselect)>/i.test(n),f=/<checkbox>/i.test(n),S=/<textfield>/i.test(n);if(v){g="radio";for(var h=void 0,b=/<selectoption([^>]*)>\s*([\s\S]*?)\s*<\/selectoption>/gi;null!==(h=b.exec(n));){var y=h[1],k=h[2],w=void 0;(C=y.match(/id=["']([^"']+)["']/i))&&(w=C[1]),m.push(t(t({},p(k)),{id:w}))}}else if(f){g="checkbox";for(var x=void 0,_=/<checkbox([^>]*)>\s*([\s\S]*?)\s*<\/checkbox>/gi;null!==(x=_.exec(n));){var C,E=x[1];k=x[2],w=void 0;(C=E.match(/id=["']([^"']+)["']/i))&&(w=C[1]),m.push(t(t({},p(k)),{id:w}))}}else S&&(g="text");"radio"!==g||0!==m.length||S||(g="text"),s.push({id:"gap-".concat(s.length),name:i.gap_name||"Gap",decisionStrength:i.gap_decision_strength,impact:i.impact,value:i.gap_value,aiReasoning:c,inputType:g,options:m,userSelection:"checkbox"===g?[]:""})};null!==(l=c.exec(i));)d();var u={count:a.count,decisionStrength:a.critical_gaps_decision_strength,value:a.value,gaps:s},p=JSON.stringify(u).replace(/"/g,""");return'\n\n<div class="critical-gaps-trigger" data-payload="'.concat(p,'"></div>\n\n')}catch(n){return console.error("Error parsing critical gaps XML",n),e}}),n=(n=n.replace(/<variant-card\s+([\s\S]*?)>([\s\S]*?)<\/variant-card>/gi,function(e,n,t){for(var i,a={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2(?=\s|>|$)/gi;null!==(i=r.exec(n));)a[i[1]]=i[3];return'\n\n<variant-card id="'.concat(a.id||"",'" variantname="').concat(a.variantname||"",'" decisionstrength="').concat(a.decisionstrength||"0",'" iseditable="').concat(a.iseditable||"false",'" isselected="').concat(a.isselected||"false",'">').concat(t,"</variant-card>\n\n")})).replace(/(?:<!--\s*)?<rule-validation-card\s+([\s\S]*?)(?:\/>|>([\s\S]*?)<\/rule-validation-card>)\s*(?:-->)?/gi,function(e,n,t){void 0===t&&(t="");for(var i,a={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2(?=\s|>|\/>|$)/gi;null!==(i=r.exec(n));)a[i[1]]=i[3];var o=function(e){return(a[e]||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")};return'\n\n<div class="rule-validation-card-trigger" \n data-type="'.concat(o("validationType"),'"\n data-decision-strength="').concat(o("decisionStrength"),'"\n data-title="').concat(o("ruleTitle"),'"\n data-tier="').concat(o("tier"),'"\n data-rule-id="').concat(o("ruleId"),'" \n data-description="').concat(o("ruleDescription"),'">').concat(t,"</div>\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(/<view_form_update_card\s+title=["'](.*?)["']>([\s\S]*?)<\/view_form_update_card>/gi,function(e,n,t){for(var i,a=[],r=/<form_value\s+value=["']([\s\S]*?)["']>([\s\S]*?)<\/form_value>/gi,o=function(){var e=i[1],n=i[2],t=function(e){var t;return(null===(t=n.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===t?void 0:t[1])||""};a.push({label:e,reasoning:{id:t("id"),reason:t("reason"),gap:t("gap"),score:t("relevance_score")}})};null!==(i=r.exec(t));)o();var s={title:n||"Updated Fields",fields:a},c=JSON.stringify(s).replace(/"/g,""");return'<span class="view-form-update-trigger" data-payload="'.concat(c,'"></span>')}),n=n.replace(/<view_identified_fields\s+title=["'](.*?)["']>([\s\S]*?)<\/view_identified_fields>/gi,function(e,n,t){for(var i,a=[],r=/<form_value\s+value=["']([\s\S]*?)["']>([\s\S]*?)<\/form_value>/gi,o=function(){var e=i[1],n=i[2],t=function(e){var t;return(null===(t=n.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===t?void 0:t[1])||""};a.push({label:e,reasoning:{id:t("id"),reason:t("reason"),gap:t("gap"),score:t("relevance_score")}})};null!==(i=r.exec(t));)o();var s={title:n||"Identified Fields",fields:a},c=JSON.stringify(s).replace(/"/g,""");return'<span class="view-identified-fields-trigger" data-payload="'.concat(c,'"></span>')}),n=n.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 i=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,">"),i++,'<span class="cognitive-card-trigger" data-card-id="card-'.concat(i,'">').concat(t,"</span>")});var a=0;return n.replace(/(\[[^\]]+\]\()([^)]+)(\))/g,function(e,n,t,i){var r=t.replace(/\s/g,"%20");if(r.includes("citationNumber=")){a++;var o=r.includes("?")?"&":"?";return"".concat(n).concat(r).concat(o,"uiUniqueId=").concat(a).concat(i)}return"".concat(n).concat(r).concat(i)})}(V)}),_),A&&V.includes("<variant-card")&&a("div",t({style:{gap:"8px"}},{children:[a(v,t({className:"clickable-button",handleStream:T,disabled:!L||!ae&&!Q||Q&&"add"!==ne,isStreamEnd:j,onAction:function(){return xe("Add ".concat(Ae),!0,"add")},"data-selected":"add"===ne?"true":Q?"false":void 0},{children:["Add ",Ae]})),a(v,t({className:"clickable-button",handleStream:T,disabled:!L||!ae&&!Q||Q&&"edit"!==ne,isStreamEnd:j,onAction:function(){return xe("Edit ".concat(Ae),!0,"edit")},"data-selected":"edit"===ne?"true":Q?"false":void 0},{children:["Edit ",Ae]})),i(v,t({className:"clickable-button",handleStream:T,disabled:!L||Q&&"skip"!==ne,isStreamEnd:j,onAction:function(){return xe("Skip for now",!0,"skip")},"data-selected":"skip"===ne?"true":Q?"false":void 0},{children:"Skip for now"}))]})),We&&i("div",t({style:{marginTop:"12px",display:"flex",justifyContent:"flex-start"}},{children:i(w,{type:"instant",options:[{id:"proceed-gaps",label:"Proceed to Fix Gaps"}],selectedIds:me?["proceed-gaps"]:[],disabled:me,citations:[],onProceed:Ce})}))]})),i("div",t({style:{display:"flex",maxWidth:"100%"}},{children:i("div",t({style:{width:"100%"}},{children:(null==F?void 0:F.length)>0&&G&&!U?a("div",t({style:{marginTop:"10px"}},{children:[a("span",{children:["It looks like you've chosen ",F&&0!==F.length?F.some(function(e){return"both tiers"===e.toLowerCase()||"all tiers"===e.toLowerCase()})?"Both Tiers":F.join(", "):"",". Would you like me to proceed?"]}),i("p",{children:i("button",t({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:Ie},{children:"Yes"}))})]})):null}))}))]})};export{x as default};
|
|
1
|
+
import{__spreadArray as e,__rest as n,__assign as t}from"../../../../node_modules/tslib/tslib.es6.mjs.js";import{jsx as i,jsxs as a,Fragment as r}from"react/jsx-runtime";import{ReactMarkdown as o}from"../../../../node_modules/react-markdown/lib/react-markdown.js";import s from"../../../../node_modules/rehype-raw/lib/index.js";import c from"../../../../node_modules/remark-gfm/index.js";import{useState as l,useRef as d,useEffect as u,useCallback as p,useMemo as m}from"react";import{RuleDisplay as g,ActionableButton as v,ActionableCheckbox as f}from"./ClickableChatComponents.js";import{MarkdownLinkRenderer as S,MarkdownDivRenderer as h,MarkdownSpanRenderer as b}from"../MarkdownComponents/MarkdownElements.js";import{extractTextFromChildren as y}from"../../helpers/utils.js";import{RuleVariantCard as k}from"./RuleVariantCard.js";import{MarkdownSelect as w}from"../MarkdownComponents/MarkdownSelect.js";var x=function(x){var _=x.index,C=x.content,E=x.role;x.messages;var T=x.handleStream,N=x.scrollToBottom,L=x.isLastMessage,I=x.onSave,M=x.citations,B=x.setChatSize,z=x.chatSize,j=x.isStreamEnd,A=x.messageIsEnd,R=x.onViewComparison,W=x.onTypeResponseClick,D=x.onComparisonLinkClick,P=l(C),V=P[0],q=P[1],J=l([]),F=J[0],O=J[1],$=l(!1),G=$[0],H=$[1],K=l(!1),U=K[0],Y=K[1],X=l(!1),Q=X[0],Z=X[1],ee=l(null),ne=ee[0],te=ee[1],ie=l(null),ae=ie[0],re=ie[1],oe=l([]),se=oe[0],ce=oe[1],le=l(!1),de=le[0],ue=le[1],pe=l(!1),me=pe[0],ge=pe[1],ve=l(new Set),fe=ve[0],Se=ve[1],he=l(new Set),be=he[0],ye=he[1],ke=d({handleStream:T,onSave:I,selectedTiers:F,tiersSubmitted:U,citations:M,openCardIds:fe,openCitationIds:be,chatSize:z,isLastMessage:L,scrollToBottom:N,isStreamEnd:j,selectedVariant:ae,messageIsEnd:A,isCommitted:Q,clickedAction:ne,gapSelections:se,gapsSubmitted:me,onTypeResponseClick:W});ke.current={handleStream:T,onSave:I,selectedTiers:F,tiersSubmitted:U,citations:M,openCardIds:fe,openCitationIds:be,chatSize:z,isLastMessage:L,scrollToBottom:N,isStreamEnd:j,selectedVariant:ae,messageIsEnd:A,isCommitted:Q,clickedAction:ne,gapSelections:se,gapsSubmitted:me,onTypeResponseClick:W},u(function(){re(null),Z(!1),te(null),ue(!1),ge(!1),ce([])},[_]),u(function(){if(A&&!Q&&!ae){var e=V.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&&re({id:n[1],variantName:t[1],decisionStrength:parseInt((null==i?void 0:i[1])||"0")})}}},[V,A,Q,ae]);var we=p(function(e,n,t){var i=function(t){var i=new Set(t);return n?i.add(e):i.delete(e),i};"card"===t?Se(function(e){return i(e)}):ye(function(e){return i(e)})},[]),xe=p(function(e,n,t){void 0===n&&(n=!1);var i=ke.current,a=i.handleStream;i.onSave;var r=e.trim();a&&(a(new KeyboardEvent("keydown",{key:"Enter"}),!1,r),n&&t&&(Z(!0),te(t))),n||q(function(e){return e.replace(/<button([^>]*)class=["']clickable-button["']([^>]*)>([\s\S]*?)<\/button>/gi,function(e,n,t,i){var a=i.trim(),o='data-selected="'.concat(a===r,'"');return"<button".concat(n,'class="clickable-button" ').concat(o).concat(t,">").concat(i,"</button>")})})},[]),_e=p(function(e,n){ue(e),ce(n)},[]),Ce=p(function(){var e=ke.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),ge(!0)},[]),Ee=p(function(e,n){var t=ke.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},[]),Te=p(function(n,t){var i=ke.current.scrollToBottom,a=Array.isArray(n)?n[0].trim():n.trim();H(!0),O(function(n){var i=e([],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"),o=i.includes("Tier 2");r&&o?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()},[]),Ne=p(function(e,n,t,i){ke.current.isCommitted||n&&re({id:e,variantName:t,decisionStrength:i})},[]),Le=function(){if(!ke.current.isCommitted){var e="Edit ".concat((null==ae?void 0:ae.variantName)||"Selected Behavior");xe(e,!0,"edit")}},Ie=p(function(){var e=ke.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)),Y(!0),H(!1),q(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:""})})},[]),Me=m(function(){return{p:function(e){e.node;var a=n(e,["node"]);return i("span",t({},a,{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"===E?"0":"0.4rem"}},{children:null==a?void 0:a.children}))},code:function(e){e.node;var a=n(e,["node"]);return i("span",t({},a,{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==a?void 0:a.children}))},ol:function(e){e.node;var a=n(e,["node"]);return i("ol",t({},a,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==a?void 0:a.children}))},ul:function(e){e.node;var a=n(e,["node"]);return i("ul",t({},a,{style:{display:"flex",flexDirection:"column",gap:"1rem",listStyle:"decimal",paddingLeft:"2.5rem"}},{children:null==a?void 0:a.children}))},rule:function(e){e.node;var t=n(e,["node"]);return i(g,{content:y(t.children)})},button:function(e){var a=e.node,r=e.className,o=n(e,["node","className"]),s=ke.current,c=s.isLastMessage,l=s.handleStream,d=s.isStreamEnd;return i(v,t({node:a,className:r||o.class,handleStream:l,onAction:xe,disabled:!c,isStreamEnd:d,isLastMessage:c,onTypeResponseClick:W},o))},checkbox:function(e){var a=e.node,r=e.className,o=n(e,["node","className"]),s=ke.current,c=s.selectedTiers,l=s.tiersSubmitted,d=s.isLastMessage;return i(f,t({node:a,className:r||o.class,selectedItems:c,onToggle:Te,isSubmitted:l,disabled:!d},o))},a:function(e){var n=ke.current,a=n.chatSize,r=n.openCitationIds;return i(S,t({},e,{chatSize:a,openCitationIds:r,getCitationByNumber:Ee,handleToggleState:we,isStreamEnd:ke.current.isStreamEnd}))},div:function(e){var n=ke.current,a=n.openCardIds,r=n.citations,o=n.isLastMessage,s=n.isStreamEnd,c=n.gapsSubmitted,l=n.onTypeResponseClick;return i(h,t({},e,{openCardIds:a,citations:r,handleToggleState:we,isStreamEnd:s,isLastMessage:o,handleStream:T,onGapValidation:_e,isGapsSubmitted:c,onViewComparison:R,onComparisonLinkClick:D,onTypeResponseClick:l}))},span:function(e){var n,a,r;if((null===(n=e.className)||void 0===n?void 0:n.includes("cognitive-card-trigger"))||(null===(a=e.className)||void 0===a?void 0:a.includes("view-form-update-trigger"))||(null===(r=e.className)||void 0===r?void 0:r.includes("view-identified-fields-trigger"))){var o=ke.current,s=o.openCardIds,c=o.citations,l=o.isLastMessage,d=o.isStreamEnd;return i(b,t({},e,{openCardIds:s,citations:c,handleToggleState:we,onComparisonLinkClick:D,isStreamEnd:!l||d}))}return i("span",t({},e))},"variant-card":function(e){e.node;var a=n(e,["node"]),r=a.variantname,o=a.decisionstrength,s=a.id,c=ke.current,l=c.isCommitted,d=c.isLastMessage,u=c.selectedVariant;if(!A)return null;var p=(null==u?void 0:u.id)===s,m=parseInt(o||"0");return i(k,t({variantName:r,decisionStrength:m,isEditable:!l&&d,isSelected:p,onToggle:function(e){return Ne(s,e,r,m)},onEdit:function(){return Le()}},{children:a.children}))},br:function(e){return i("p",t({style:{marginBottom:"0.75rem"}},e))}}},[xe,Te,Ee,we,E,ae,Q,A,_e,Ne]);u(function(){U||(q(C),setTimeout(function(){null==N||N()},50))},[C,U,N]);var Be=d(0);u(function(){var e=fe.size+be.size;e>0&&0===Be.current?null==B||B(50):0===e&&Be.current>0&&(null==B||B(40)),Be.current=e},[fe,be,B]);var ze=m(function(){return[s]},[]),je=m(function(){return[c]},[]),Ae=(null==ae?void 0:ae.variantName)||"Selected Behavior",Re=se.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()})}),We=de&&A&&(L||me)&&!Re;return a(r,{children:[a("div",t({style:{lineHeight:"1.625rem",fontSize:"1rem",marginTop:"0.5rem",marginBottom:"".concat("assistant"===E?"0.3rem":"0rem"),fontFamily:"Plus Jakarta Sans, sans-serif"}},{children:[i(o,t({components:Me,rehypePlugins:ze,remarkPlugins:je},{children:function(e){if(!e)return"";var n=e.replace(/\\"/g,'"').replace(/\\'/g,"'");n=(n=(n=n.replace(/```(?:\w+)?\n?([\s\S]*?)```/gi,"$1")).replace(/<br\s*\/?>/gi,"\n\n")).replace(/(?:<!--\s*)?<critical_gaps\s+([\s\S]*?)>([\s\S]*?)<\/critical_gaps>\s*(?:-->)?/gi,function(e,n,i){try{for(var a={},r=/([a-z0-9_]+)\s*=\s*(["'])([\s\S]*?)\2/gi,o=void 0;null!==(o=r.exec(n));)a[o[1]]=o[3];for(var s=[],c=/<gap_card\s+([\s\S]*?)>([\s\S]*?)<\/gap_card>/gi,l=void 0,d=function(){for(var e=l[1],n=l[2],i={};null!==(o=r.exec(e));)i[o[1]]=o[3];var a=n.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),c=null;if(a){var d=a[1],u=function(e){var n;return(null===(n=d.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===n?void 0:n[1])||""};c={id:u("id"),reason:u("reason"),gap:u("gap"),score:u("relevance_score")}}var p=function(e){var n=e.match(/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/i),t=e.match(/<explaination\s+value=(["'])([\s\S]*?)\1\s*>[\s\S]*?<\/explaination>/i),i=null,a=null,r=e;if(n){var o=n[1],s=function(e){var n=o.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i"));return n?n[1].replace(/\\n/g,"\n").trim():""};i={id:s("id"),reason:s("reason"),gap:s("gap"),score:s("relevance_score")},r=e.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/i,"").trim()}if(t){try{var c=t[2];a=JSON.parse(c.replace(/"/g,'"')),console.log("Parsed Explanation successfully:",a)}catch(e){console.error("Explanation parse error:",e,"Raw value:",t[2])}r=r.replace(/<explaination[\s\S]*?>[\s\S]*?<\/explaination>/i,"").trim()}return{text:r,aiReasoning:i,explanation:a}},m=[],g="text",v=/<(selectoption|radioselect)>/i.test(n),f=/<checkbox>/i.test(n),S=/<textfield>/i.test(n);if(v){g="radio";for(var h=void 0,b=/<selectoption([^>]*)>\s*([\s\S]*?)\s*<\/selectoption>/gi;null!==(h=b.exec(n));){var y=h[1],k=h[2],w=void 0;(C=y.match(/id=["']([^"']+)["']/i))&&(w=C[1]),m.push(t(t({},p(k)),{id:w}))}}else if(f){g="checkbox";for(var x=void 0,_=/<checkbox([^>]*)>\s*([\s\S]*?)\s*<\/checkbox>/gi;null!==(x=_.exec(n));){var C,E=x[1];k=x[2],w=void 0;(C=E.match(/id=["']([^"']+)["']/i))&&(w=C[1]),m.push(t(t({},p(k)),{id:w}))}}else S&&(g="text");"radio"!==g||0!==m.length||S||(g="text"),s.push({id:"gap-".concat(s.length),name:i.gap_name||"Gap",decisionStrength:i.gap_decision_strength,impact:i.impact,value:i.gap_value,aiReasoning:c,inputType:g,options:m,userSelection:"checkbox"===g?[]:""})};null!==(l=c.exec(i));)d();var u={count:a.count,decisionStrength:a.critical_gaps_decision_strength,value:a.value,gaps:s},p=JSON.stringify(u).replace(/"/g,""");return'\n\n<div class="critical-gaps-trigger" data-payload="'.concat(p,'"></div>\n\n')}catch(n){return console.error("Error parsing critical gaps XML",n),e}}),n=(n=n.replace(/<variant-card\s+([\s\S]*?)>([\s\S]*?)<\/variant-card>/gi,function(e,n,t){for(var i,a={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2(?=\s|>|$)/gi;null!==(i=r.exec(n));)a[i[1]]=i[3];return'\n\n<variant-card id="'.concat(a.id||"",'" variantname="').concat(a.variantname||"",'" decisionstrength="').concat(a.decisionstrength||"0",'" iseditable="').concat(a.iseditable||"false",'" isselected="').concat(a.isselected||"false",'">').concat(t,"</variant-card>\n\n")})).replace(/(?:<!--\s*)?<rule-validation-card\s+([\s\S]*?)(?:\/>|>([\s\S]*?)<\/rule-validation-card>)\s*(?:-->)?/gi,function(e,n,t){void 0===t&&(t="");for(var i,a={},r=/([a-z0-9-]+)\s*=\s*(["'])([\s\S]*?)\2(?=\s|>|\/>|$)/gi;null!==(i=r.exec(n));)a[i[1]]=i[3];var o=function(e){return(a[e]||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")};return'\n\n<div class="rule-validation-card-trigger" \n data-type="'.concat(o("validationType"),'"\n data-decision-strength="').concat(o("decisionStrength"),'"\n data-title="').concat(o("ruleTitle"),'"\n data-tier="').concat(o("tier"),'"\n data-rule-id="').concat(o("ruleId"),'" \n data-description="').concat(o("ruleDescription"),'">').concat(t,"</div>\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(/<view_form_update_card\s+title=["'](.*?)["']>([\s\S]*?)<\/view_form_update_card>/gi,function(e,n,t){for(var i,a=[],r=/<form_value\s+value=["']([\s\S]*?)["']>([\s\S]*?)<\/form_value>/gi,o=function(){var e=i[1],n=i[2],t=function(e){var t;return(null===(t=n.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===t?void 0:t[1])||""};a.push({label:e,reasoning:{id:t("id"),reason:t("reason"),gap:t("gap"),score:t("relevance_score")}})};null!==(i=r.exec(t));)o();var s={title:n||"Updated Fields",fields:a},c=JSON.stringify(s).replace(/"/g,""");return'<span class="view-form-update-trigger" data-payload="'.concat(c,'"></span>')}),n=n.replace(/<view_identified_fields\s+title=["'](.*?)["']>([\s\S]*?)<\/view_identified_fields>/gi,function(e,n,t){for(var i,a=[],r=/<form_value\s+value=["']([\s\S]*?)["']>([\s\S]*?)<\/form_value>/gi,o=function(){var e=i[1],n=i[2],t=function(e){var t;return(null===(t=n.match(new RegExp("<".concat(e,">([\\s\\S]*?)<\\/").concat(e,">"),"i")))||void 0===t?void 0:t[1])||""};a.push({label:e,reasoning:{id:t("id"),reason:t("reason"),gap:t("gap"),score:t("relevance_score")}})};null!==(i=r.exec(t));)o();var s={title:n||"Identified Fields",fields:a},c=JSON.stringify(s).replace(/"/g,""");return'<span class="view-identified-fields-trigger" data-payload="'.concat(c,'"></span>')}),n=n.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 i=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,">"),i++,'<span class="cognitive-card-trigger" data-card-id="card-'.concat(i,'">').concat(t,"</span>")});var a=0;return n.replace(/(\[[^\]]+\]\()([^)]+)(\))/g,function(e,n,t,i){var r=t.replace(/\s/g,"%20");if(r.includes("citationNumber=")){a++;var o=r.includes("?")?"&":"?";return"".concat(n).concat(r).concat(o,"uiUniqueId=").concat(a).concat(i)}return"".concat(n).concat(r).concat(i)})}(V)}),_),A&&V.includes("<variant-card")&&a("div",t({style:{gap:"8px"}},{children:[a(v,t({className:"clickable-button",handleStream:T,disabled:!L||!ae&&!Q||Q&&"add"!==ne,isStreamEnd:j,onAction:function(){return xe("Add ".concat(Ae),!0,"add")},"data-selected":"add"===ne?"true":Q?"false":void 0},{children:["Add ",Ae]})),a(v,t({className:"clickable-button",handleStream:T,disabled:!L||!ae&&!Q||Q&&"edit"!==ne,isStreamEnd:j,onAction:function(){return xe("Edit ".concat(Ae),!0,"edit")},"data-selected":"edit"===ne?"true":Q?"false":void 0},{children:["Edit ",Ae]})),i(v,t({className:"clickable-button",handleStream:T,disabled:!L||Q&&"skip"!==ne,isStreamEnd:j,onAction:function(){return xe("Skip for now",!0,"skip")},"data-selected":"skip"===ne?"true":Q?"false":void 0},{children:"Skip for now"}))]})),We&&i("div",t({style:{marginTop:"12px",display:"flex",justifyContent:"flex-start"}},{children:i(w,{type:"instant",options:[{id:"proceed-gaps",label:"Proceed to Fix Gaps"}],selectedIds:me?["proceed-gaps"]:[],disabled:me,citations:[],onProceed:Ce})}))]})),i("div",t({style:{display:"flex",maxWidth:"100%"}},{children:i("div",t({style:{width:"100%"}},{children:(null==F?void 0:F.length)>0&&G&&!U?a("div",t({style:{marginTop:"10px"}},{children:[a("span",{children:["It looks like you've chosen ",F&&0!==F.length?F.some(function(e){return"both tiers"===e.toLowerCase()||"all tiers"===e.toLowerCase()})?"Both Tiers":F.join(", "):"",". Would you like me to proceed?"]}),i("p",{children:i("button",t({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:Ie},{children:"Yes"}))})]})):null}))}))]})};export{x as default};
|
|
2
2
|
//# sourceMappingURL=MessageRendering.js.map
|