@viswa-test/test-citation 0.0.260 → 0.0.261
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/CognitiveCompare/CitationAnchor.js +1 -1
- package/dist/cjs/features/CognitiveCompare/Guidelines/utils/helper.js +1 -1
- package/dist/cjs/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js +1 -1
- package/dist/cjs/features/CognitiveCompare/hooks/useCompareData.js +1 -1
- package/dist/features/CognitiveCompare/CitationAnchor.js +1 -1
- package/dist/features/CognitiveCompare/Guidelines/utils/helper.js +1 -1
- package/dist/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js +1 -1
- package/dist/features/CognitiveCompare/hooks/useCompareData.js +1 -1
- package/dist/types/src/CognitiveCompareTest.d.ts.map +1 -1
- package/dist/types/src/features/CognitiveCompare/CitationAnchor.d.ts.map +1 -1
- package/dist/types/src/features/CognitiveCompare/Guidelines/constants/guidelines.mockData.d.ts +1383 -10273
- package/dist/types/src/features/CognitiveCompare/Guidelines/constants/guidelines.mockData.d.ts.map +1 -1
- package/dist/types/src/features/CognitiveCompare/Guidelines/utils/helper.d.ts.map +1 -1
- package/dist/types/src/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.d.ts.map +1 -1
- package/dist/types/src/features/CognitiveCompare/hooks/useCompareData.d.ts.map +1 -1
- package/dist/types/src/features/CognitiveCompare/hooks/useCompareLayout.d.ts +1 -0
- package/dist/types/src/features/CognitiveCompare/hooks/useCompareLayout.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),i=require("react/jsx-runtime"),n=require("lucide-react"),t=require("react"),o=require("./ResizableSplitPane.js"),l=require("../PdfViewer/PdfViewer.js"),a=require("../../assests/svg/PdfViewerIcons.js"),r=require("react-markdown"),u=require("rehype-raw"),d=require("@mui/material"),s=require("./CognitiveCompareConfig.js");require("react-dom");var c=require("./CompareContext.js"),v=require("./Guidelines/utils/processGuidelinesMarkdown.js"),p=require("../GptWebCitation/GptWebCitation.js"),g=require("../GptWebCitation/types.js");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("./MoreFunctionsPopup.js"),require("./components/SubSectionAccordion.js"),require("./components/LHSSectionRow.js"),require("./components/RHSSectionRow.js");var x=h(r),m=h(u),f=function(e){var i,n,t;return(null===(t=null===(n=null===(i=(null==e?void 0:e.extraMetaData)||e)||void 0===i?void 0:i.aiReasoningCitation)||void 0===n?void 0:n.gpt_citation)||void 0===t?void 0:t[0])||null},_="https://dev-proposals-ai.techo.camp/utility/ca-workflow-composer-agent/get_citation",b="sai.siddhartha@techolution.com",y="672e32f7a0e8fe2e8e50bcba",C="TNV Sai Siddhartha",w="90vh",j="calc(".concat(w," - 120px)"),D=function(){var e;return"function"==typeof(null===(e=globalThis.crypto)||void 0===e?void 0:e.randomUUID)?globalThis.crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var i=Math.floor(16*Math.random());return("x"===e?i:i%4+8).toString(16)})},F=function(e,i){var n=function(e){var i;return(null==e?void 0:e.payloadCitationId)||(null===(i=null==e?void 0:e.extraMetaData)||void 0===i?void 0:i.payloadCitationId)||""}(e)||i||D();return function(e,i){e&&"object"==typeof e&&(e.payloadCitationId=i,e.extraMetaData&&"object"==typeof e.extraMetaData&&(e.extraMetaData.payloadCitationId=i))}(e,n),n},S=function(o){var l,a=o.metaData,r=o.isFullscreen,u=void 0!==r&&r,d=c.useCompareContext().gptWebCitationConfig,s=t.useMemo(function(){return function(e){return{endpoint:(null==e?void 0:e.endpoint)||_,userEmail:(null==e?void 0:e.userEmail)||b,userId:(null==e?void 0:e.userId)||y,userName:(null==e?void 0:e.userName)||C,headers:null==e?void 0:e.headers}}(d)},[d]),v=null==a?void 0:a.webGpt,h=t.useRef(null);h.current||(h.current=D());var x=t.useMemo(function(){return function(e,i,n){var t,o,l=f(e),a=(null==l?void 0:l.customMetaData)||{},r=(null==a?void 0:a.value)||{},u=(null==e?void 0:e.webSearchAnswer)||{},d=(null==e?void 0:e.extraMetaData)||e||{};return{userEmail:(null==e?void 0:e.userEmail)||(null==u?void 0:u.userEmail)||(null==i?void 0:i.userEmail)||"",userId:(null==e?void 0:e.userId)||(null==u?void 0:u.userId)||(null==i?void 0:i.userId)||"",userName:(null==e?void 0:e.userName)||(null==u?void 0:u.userName)||(null==i?void 0:i.userName)||"",citationId:F(e,n),citationUrl:(null==r?void 0:r.citationUrl)||(null==u?void 0:u.citationUrl)||"",content:(null==d?void 0:d.Reasoning)||(null==u?void 0:u.enhanced_content)||"",citationType:(null==r?void 0:r.citationType)||"web",citatioNumber:null!==(o=null!==(t=null==a?void 0:a.citation_number)&&void 0!==t?t:null==l?void 0:l.citation_number)&&void 0!==o?o:Number((null==e?void 0:e.reasoningId)||0)}}(v,s,h.current||void 0)},[v,s]),m=t.useMemo(function(){return f(v)},[v]),w=(null===(l=null==m?void 0:m.customMetaData)||void 0===l?void 0:l.value)||{},S=(null==v?void 0:v.extraMetaData)||v||{},P=t.useState(),M=P[0],T=P[1],k=t.useState("pending"),I=k[0],R=k[1],G=t.useState(!0),E=G[0],N=G[1];t.useEffect(function(){var i=!0;return e.__awaiter(void 0,void 0,void 0,function(){var n,t,o,l;return e.__generator(this,function(a){switch(a.label){case 0:if(!s.endpoint||!(null==x?void 0:x.citationUrl)||!(null==x?void 0:x.content))return R("error"),[2];R("pending"),a.label=1;case 1:return a.trys.push([1,4,,5]),[4,fetch(s.endpoint,{method:"POST",headers:e.__assign({"actor-id":x.userEmail,Accept:"application/json, text/plain, */*","Content-Type":"application/json"},s.headers||{}),body:JSON.stringify(x)})];case 2:if(!(n=a.sent()).ok)throw new Error("Failed to fetch GPT web citation (".concat(n.status,")"));return[4,n.json()];case 3:return t=a.sent(),o=(null==t?void 0:t.responseData)||(null==t?void 0:t.result)||(null==t?void 0:t.data)||t,i?(T(o),R("success"),[3,5]):[2];case 4:return l=a.sent(),i?(console.error("Failed to load GPT web citation",l),R("error"),[3,5]):[2];case 5:return[2]}})}),function(){i=!1}},[x,s]);var q=t.useMemo(function(){return{item:{confidence_score:Number((null==S?void 0:S.Confidence_score)||0),text:(null==w?void 0:w.paraphrase)||"Web citation reasoning",dataSource:(null==w?void 0:w.text)||(null==S?void 0:S.Reasoning)||"",paraphrase:(null==w?void 0:w.paraphrase)||""},headerTitle:"GPT Web Citation",index:Number((null==x?void 0:x.citatioNumber)||1)-1,iconsConfig:{ChevronDownIcon:n.ChevronDown,ChevronUpIcon:n.ChevronUp,MaximizeIcon:n.Maximize2,CloseIcon:n.X}}},[w,null==x?void 0:x.citatioNumber,S]),A=t.useMemo(function(){return e.__assign(e.__assign({},q),u?{bodyHeight:j}:{})},[q,u]);return i.jsx(p.default,{gptCitation:A,defaultCitationUrl:(null==x?void 0:x.citationUrl)||"",citationType:g.CitationType.GPT_WEB,webCitationData:M,webCitationStatus:I,showWebCitation:E,onToggleCitationView:function(){return N(function(e){return!e})},iconsConfig:{MaximizeIcon:n.Maximize2,ExternalLinkIcon:n.ExternalLink},isFixedHeight:!0})},P=function(n){var a,r,u,p,g,h,f,_=n.href,b=n.metaData,y=n.citationTitle,C=n.citationType,w=n.citationReason,j=n.isFullscreen,D=c.useCompareContext().guidelinesData,F=function(e){try{var i=new URL(e,window.location.origin);return{citationNumber:i.searchParams.get("citationNumber"),phraseToHighlight:i.searchParams.get("phrase_to_highlight")}}catch(e){return{citationNumber:null,phraseToHighlight:null}}}(_),P=F.citationNumber,M=F.phraseToHighlight,T=P&&(null===(a=null==b?void 0:b.citations)||void 0===a?void 0:a[P])||{},k=(null===(r=null==b?void 0:b.docData)||void 0===r?void 0:r.documents)||{},I=(null===(u=null==b?void 0:b.docData)||void 0===u?void 0:u.input_index_map)||{},R=Object.keys((null==b?void 0:b.citations)||{}).length>0||Object.keys((null==b?void 0:b.docData)||{}).length>0,G=null==I?void 0:I[0],E=null==I?void 0:I[1],N=G?k[G]:null,q=E?k[E]:null,A=G?T[G]:null,U=E?T[E]:null,W=t.useMemo(function(){var e,n,t,o;return A&&N?i.jsx(l.default,{defaultScale:"PageWidth",showFullScreenAction:!1,showHighlightsAction:!1,pdfName:null==N?void 0:N.title,pdfUrl:null==N?void 0:N.signed_url,highlightText:[null!==(e=null==A?void 0:A.highlighted_text)&&void 0!==e?e:""],highlightPages:{1:null===(n=null==A?void 0:A.custom_metadata)||void 0===n?void 0:n.pdf_start_page_number},jumpToPageValue:1,highlightCordinatePages:[],useCoordinates:!1,useRange:!0,rangeOfPages:[null===(t=null==A?void 0:A.custom_metadata)||void 0===t?void 0:t.pdf_start_page_number,null===(o=null==A?void 0:A.custom_metadata)||void 0===o?void 0:o.pdf_end_page_number]}):null},[null==N?void 0:N.title,null==N?void 0:N.signed_url,null==A?void 0:A.highlighted_text,null===(p=null==A?void 0:A.custom_metadata)||void 0===p?void 0:p.pdf_start_page_number,null===(g=null==A?void 0:A.custom_metadata)||void 0===g?void 0:g.pdf_end_page_number]),z=t.useMemo(function(){var e,n,t,o;return U&&q?i.jsx(l.default,{defaultScale:"PageWidth",showFullScreenAction:!1,showHighlightsAction:!1,pdfName:null==q?void 0:q.title,pdfUrl:null==q?void 0:q.signed_url,jumpToPageValue:1,highlightText:[null!==(e=null==U?void 0:U.highlighted_text)&&void 0!==e?e:""],highlightPages:{1:null===(n=null==U?void 0:U.custom_metadata)||void 0===n?void 0:n.pdf_start_page_number},highlightCordinatePages:[],useCoordinates:!1,useRange:!0,rangeOfPages:[null===(t=null==U?void 0:U.custom_metadata)||void 0===t?void 0:t.pdf_start_page_number,null===(o=null==U?void 0:U.custom_metadata)||void 0===o?void 0:o.pdf_end_page_number]}):null},[null==q?void 0:q.title,null==q?void 0:q.signed_url,null==U?void 0:U.highlighted_text,null===(h=null==U?void 0:U.custom_metadata)||void 0===h?void 0:h.pdf_start_page_number,null===(f=null==U?void 0:U.custom_metadata)||void 0===f?void 0:f.pdf_end_page_number]),H="dual_citation"===C,O=H&&!!(null==b?void 0:b.webGpt),B=t.useMemo(function(){if(!W)return null;var n=O?i.jsx(S,{metaData:b,isFullscreen:j}):"rulebook_citation"===C?i.jsx(i.Fragment,{children:i.jsx(d.Box,e.__assign({sx:e.__assign(e.__assign({padding:"0px 20px",backgroundColor:"#FFFFFF",borderRadius:"8px"},s.SHARED_MARKDOWN_STYLES),{overflow:"auto"})},{children:i.jsx(x.default,e.__assign({rehypePlugins:[m.default]},{children:v.processGuidelinesMarkdown({guidelinesData:D,targetHighlights:[M],labelColor:"#FEF08A"})}))}))}):z;return n?i.jsx(o.default,{leftComponent:W,rightComponent:n,isFullscreen:j}):W},[W,z,C,O,b,j]);return(null==b?void 0:b.webGpt)&&!R?i.jsx(S,{metaData:b,isFullscreen:j}):P?"rulebook_citation"===C?A?i.jsx("div",e.__assign({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:B})):i.jsx("div",e.__assign({style:{padding:"12px",fontSize:"13px",color:"#344054",lineHeight:1.5}},{children:w||"Rulebook citation selected."})):H?A||U?i.jsx("div",e.__assign({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:B})):(null==b?void 0:b.webGpt)?i.jsx(S,{metaData:b,isFullscreen:j}):i.jsx("div",{children:"Missing PDF Citation. Please try again later"}):["contract","clause"].includes(y)?A||U?i.jsx("div",e.__assign({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:B})):i.jsx("div",{children:"Missing PDF Citation. Please try again later"}):i.jsx("div",{children:"No Citation Found. Please try again later"}):null};exports.default=function(o){var l,r,u,s,c,v,p,g=o.href,h=o.children,x=o.citationType,m=o.citationReason,f=o.metaData,_=o.chevronUpComponent,b=void 0===_?null:_,y=o.chevronDownComponent,C=void 0===y?null:y,j=o.customStyle,D=void 0===j?{}:j,F=o.defaultState,S=void 0!==F&&F,M=o.onFullscreenChange,T=t.useState(S),k=T[0],I=T[1],R=t.useState(!1),G=R[0],E=R[1],N="string"==typeof h&&(null===(l=null==h?void 0:h.split("\n"))||void 0===l?void 0:l.length)>1?h.split("\n").join(" "):h;t.useEffect(function(){if(null==M||M(G),G)return function(){null==M||M(!1)}},[G,M]);var q="string"==typeof h?h:h[0],A=null!=b?b:function(e){var t,o;return i.jsx(n.ChevronUp,{size:null!==(t=null==e?void 0:e.fontSize)&&void 0!==t?t:16,color:null!==(o=null==e?void 0:e.color)&&void 0!==o?o:"rgb(214, 51, 132)"})}(null!==(r=null==D?void 0:D.arrow)&&void 0!==r?r:{}),U=null!=C?C:function(e){var t,o;return i.jsx(n.ChevronDown,{size:null!==(t=null==e?void 0:e.fontSize)&&void 0!==t?t:16,color:null!==(o=null==e?void 0:e.color)&&void 0!==o?o:"rgb(214, 51, 132)"})}(null!==(u=null==D?void 0:D.arrow)&&void 0!==u?u:{}),W=i.jsxs("div",e.__assign({style:{boxSizing:"border-box",border:G?"none":"1px solid #E4E7EC",borderRadius:G?0:"8px",overflow:"hidden",marginTop:G?0:"8px",display:"flex",flexDirection:"column",width:"100%",height:G?"100%":void 0,backgroundColor:"#FAFAFA"}},{children:[i.jsx("div",e.__assign({style:{display:"flex",justifyContent:"flex-end",padding:"6px 10px",borderBottom:"1px solid #E4E7EC",backgroundColor:"#FFFFFF",flexShrink:0}},{children:i.jsx("button",e.__assign({onClick:function(){E(function(e){return!e})},style:{background:"none",border:"none",cursor:"pointer",padding:"4px",borderRadius:"6px",color:"#475467",marginRight:"9px"}},{children:G?i.jsx(a.DefaultFullScreenCloseIcon,{}):i.jsx(a.DefaultFullScreenIcon,{})}))})),i.jsx("div",e.__assign({style:{flex:1,minHeight:0,height:"100%",overflow:"hidden"}},{children:i.jsx(P,{href:g,children:h,metaData:f,citationTitle:q,citationType:x,citationReason:m,isFullscreen:G})}))]}));return i.jsxs("span",e.__assign({style:e.__assign({display:"inline"},D.relativeWrapper||{})},{children:[i.jsx("div",e.__assign({style:e.__assign({display:"inline",marginTop:0},D.citationButtonWrapper||{})},{children:i.jsxs("button",e.__assign({type:"button",onClick:function(){return I(function(e){return!e})},style:e.__assign({display:(null==f?void 0:f.webGpt)?"inline":"inline-flex",alignItems:(null==f?void 0:f.webGpt)?void 0:"center",gap:(null==f?void 0:f.webGpt)?void 0:"3px",fontFamily:'"Inter", sans-serif',backgroundColor:"transparent",padding:0,margin:0,fontSize:"13px",borderRadius:9999,cursor:"pointer",fontWeight:(null==f?void 0:f.webGpt)?600:700,color:(null==f?void 0:f.webGpt)?"#6D28D9":"rgb(214, 51, 132)",border:"none",textDecoration:"none",wordBreak:"break-word",whiteSpace:"normal"},D.citationButton||{})},{children:[(null==f?void 0:f.webGpt)&&i.jsx(n.Globe,{size:null!==(c=null===(s=D.arrow)||void 0===s?void 0:s.fontSize)&&void 0!==c?c:"1em",color:null!==(p=null===(v=D.arrow)||void 0===v?void 0:v.color)&&void 0!==p?p:"#6D28D9",style:{display:"inline-block",width:"1em",height:"1em",marginRight:"3px",verticalAlign:"-0.125em",flexShrink:0}}),i.jsx("span",{children:N}),i.jsx("span",e.__assign({style:{display:"inline-flex",alignItems:"center",marginLeft:(null==f?void 0:f.webGpt)?"3px":void 0,verticalAlign:(null==f?void 0:f.webGpt)?"-0.125em":void 0}},{children:k?A:U}))]}))})),k&&(G?i.jsx(d.Dialog,e.__assign({open:G,onClose:function(){return E(!1)},maxWidth:!1,BackdropProps:{sx:{backgroundColor:"rgba(0, 0, 0, 0.6)",backdropFilter:"blur(4px)"}},PaperProps:{sx:{backgroundColor:"#FAFAFA",borderRadius:"16px",height:w,m:0,maxHeight:w,maxWidth:"95vw",overflow:"hidden",width:"95vw"}}},{children:W})):W)]}))};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),i=require("react/jsx-runtime"),n=require("lucide-react"),t=require("react"),o=require("./ResizableSplitPane.js"),l=require("../PdfViewer/PdfViewer.js"),a=require("../../assests/svg/PdfViewerIcons.js"),r=require("react-markdown"),u=require("rehype-raw"),d=require("@mui/material"),s=require("./CognitiveCompareConfig.js");require("react-dom");var c=require("./CompareContext.js"),v=require("./Guidelines/utils/processGuidelinesMarkdown.js"),p=require("../GptWebCitation/GptWebCitation.js"),g=require("../GptWebCitation/types.js");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("./MoreFunctionsPopup.js"),require("./components/SubSectionAccordion.js"),require("./components/LHSSectionRow.js"),require("./components/RHSSectionRow.js");var m=h(r),x=h(u),f=function(e){var i,n,t;return(null===(t=null===(n=null===(i=(null==e?void 0:e.extraMetaData)||e)||void 0===i?void 0:i.aiReasoningCitation)||void 0===n?void 0:n.gpt_citation)||void 0===t?void 0:t[0])||null},_="https://dev-proposals-ai.techo.camp/utility/ca-workflow-composer-agent/get_citation",b="sai.siddhartha@techolution.com",y="672e32f7a0e8fe2e8e50bcba",w="TNV Sai Siddhartha",C="90vh",j="calc(".concat(C," - 120px)"),D=function(){var e;return"function"==typeof(null===(e=globalThis.crypto)||void 0===e?void 0:e.randomUUID)?globalThis.crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var i=Math.floor(16*Math.random());return("x"===e?i:i%4+8).toString(16)})},F=function(e,i){var n=function(e){var i;return(null==e?void 0:e.payloadCitationId)||(null===(i=null==e?void 0:e.extraMetaData)||void 0===i?void 0:i.payloadCitationId)||""}(e)||i||D();return function(e,i){e&&"object"==typeof e&&(e.payloadCitationId=i,e.extraMetaData&&"object"==typeof e.extraMetaData&&(e.extraMetaData.payloadCitationId=i))}(e,n),n},S=function(o){var l,a=o.metaData,r=o.isFullscreen,u=void 0!==r&&r,d=c.useCompareContext().gptWebCitationConfig,s=t.useMemo(function(){return function(e){return{endpoint:(null==e?void 0:e.endpoint)||_,userEmail:(null==e?void 0:e.userEmail)||b,userId:(null==e?void 0:e.userId)||y,userName:(null==e?void 0:e.userName)||w,headers:null==e?void 0:e.headers}}(d)},[d]),v=null==a?void 0:a.webGpt,h=t.useRef(null);h.current||(h.current=D());var m=t.useMemo(function(){return function(e,i,n){var t,o,l=f(e),a=(null==l?void 0:l.customMetaData)||{},r=(null==a?void 0:a.value)||{},u=(null==e?void 0:e.webSearchAnswer)||{},d=(null==e?void 0:e.extraMetaData)||e||{};return{userEmail:(null==e?void 0:e.userEmail)||(null==u?void 0:u.userEmail)||(null==i?void 0:i.userEmail)||"",userId:(null==e?void 0:e.userId)||(null==u?void 0:u.userId)||(null==i?void 0:i.userId)||"",userName:(null==e?void 0:e.userName)||(null==u?void 0:u.userName)||(null==i?void 0:i.userName)||"",citationId:F(e,n),citationUrl:(null==r?void 0:r.citationUrl)||(null==u?void 0:u.citationUrl)||"",content:(null==d?void 0:d.Reasoning)||(null==u?void 0:u.enhanced_content)||"",citationType:(null==r?void 0:r.citationType)||"web",citatioNumber:null!==(o=null!==(t=null==a?void 0:a.citation_number)&&void 0!==t?t:null==l?void 0:l.citation_number)&&void 0!==o?o:Number((null==e?void 0:e.reasoningId)||0)}}(v,s,h.current||void 0)},[v,s]),x=t.useMemo(function(){return f(v)},[v]),C=(null===(l=null==x?void 0:x.customMetaData)||void 0===l?void 0:l.value)||{},S=(null==v?void 0:v.extraMetaData)||v||{},P=t.useState(),T=P[0],k=P[1],M=t.useState("pending"),N=M[0],I=M[1],R=t.useState(!0),G=R[0],U=R[1];t.useEffect(function(){var i=!0;return e.__awaiter(void 0,void 0,void 0,function(){var n,t,o,l;return e.__generator(this,function(a){switch(a.label){case 0:if(!s.endpoint||!(null==m?void 0:m.citationUrl)||!(null==m?void 0:m.content))return I("error"),[2];I("pending"),a.label=1;case 1:return a.trys.push([1,4,,5]),[4,fetch(s.endpoint,{method:"POST",headers:e.__assign({"actor-id":m.userEmail,Accept:"application/json, text/plain, */*","Content-Type":"application/json"},s.headers||{}),body:JSON.stringify(m)})];case 2:if(!(n=a.sent()).ok)throw new Error("Failed to fetch GPT web citation (".concat(n.status,")"));return[4,n.json()];case 3:return t=a.sent(),o=(null==t?void 0:t.responseData)||(null==t?void 0:t.result)||(null==t?void 0:t.data)||t,i?(k(o),I("success"),[3,5]):[2];case 4:return l=a.sent(),i?(console.error("Failed to load GPT web citation",l),I("error"),[3,5]):[2];case 5:return[2]}})}),function(){i=!1}},[m,s]);var E=t.useMemo(function(){return{item:{confidence_score:Number((null==S?void 0:S.Confidence_score)||0),text:(null==C?void 0:C.paraphrase)||"Web citation reasoning",dataSource:(null==C?void 0:C.text)||(null==S?void 0:S.Reasoning)||"",paraphrase:(null==C?void 0:C.paraphrase)||""},headerTitle:"GPT Web Citation",index:Number((null==m?void 0:m.citatioNumber)||1)-1,iconsConfig:{ChevronDownIcon:n.ChevronDown,ChevronUpIcon:n.ChevronUp,MaximizeIcon:n.Maximize2,CloseIcon:n.X}}},[C,null==m?void 0:m.citatioNumber,S]),q=t.useMemo(function(){return e.__assign(e.__assign({},E),u?{bodyHeight:j}:{})},[E,u]);return i.jsx(p.default,{gptCitation:q,defaultCitationUrl:(null==m?void 0:m.citationUrl)||"",citationType:g.CitationType.GPT_WEB,webCitationData:T,webCitationStatus:N,showWebCitation:G,onToggleCitationView:function(){return U(function(e){return!e})},iconsConfig:{MaximizeIcon:n.Maximize2,ExternalLinkIcon:n.ExternalLink},isFixedHeight:!0})},P=function(n){var a,r,u,p,g,h,f,_=n.href,b=n.metaData,y=n.citationTitle,w=n.citationType,C=n.citationReason,j=n.isFullscreen,D=c.useCompareContext().guidelinesData,F=function(e){try{var i=function(e){var i=e.match(/^(?:pdf_citation|deviation_summary)\$(\d+)/);if(i)try{var n=e.indexOf("?"),t=n>=0?e.slice(n):"";return{citationNumber:i[1],parsedUrl:new URL(t||"./",window.location.origin)}}catch(e){return{citationNumber:i[1],parsedUrl:null}}try{var o=new URL(e,window.location.origin);return{citationNumber:o.searchParams.get("citationNumber")||o.searchParams.get("citation_number"),parsedUrl:o}}catch(e){return{citationNumber:null,parsedUrl:null}}}(e),n=i.citationNumber,t=i.parsedUrl;return{citationNumber:n,phraseToHighlight:(null==t?void 0:t.searchParams.get("phrase_to_highlight"))||null,citationTypeFromHref:(null==t?void 0:t.searchParams.get("citation_type"))||null}}catch(e){return{citationNumber:null,phraseToHighlight:null,citationTypeFromHref:null}}}(_),P=F.citationNumber,T=F.phraseToHighlight,k=F.citationTypeFromHref,M=w||k||void 0,N="il_rulebook_citation"===M?"rulebook_citation":M,I=P&&(null===(a=null==b?void 0:b.citations)||void 0===a?void 0:a[P])||{},R=(null===(r=null==b?void 0:b.docData)||void 0===r?void 0:r.documents)||{},G=(null===(u=null==b?void 0:b.docData)||void 0===u?void 0:u.input_index_map)||{},U=Object.keys((null==b?void 0:b.citations)||{}).length>0||Object.keys((null==b?void 0:b.docData)||{}).length>0,E=null==G?void 0:G[0],q=null==G?void 0:G[1],A=E?R[E]:null,H=q?R[q]:null,W=E?I[E]:null,z=q?I[q]:null,O=t.useMemo(function(){var e,n,t,o;return W&&A?i.jsx(l.default,{defaultScale:"PageWidth",showFullScreenAction:!1,showHighlightsAction:!1,pdfName:null==A?void 0:A.title,pdfUrl:null==A?void 0:A.signed_url,highlightText:[null!==(e=null==W?void 0:W.highlighted_text)&&void 0!==e?e:""],highlightPages:{1:null===(n=null==W?void 0:W.custom_metadata)||void 0===n?void 0:n.pdf_start_page_number},jumpToPageValue:1,highlightCordinatePages:[],useCoordinates:!1,useRange:!0,rangeOfPages:[null===(t=null==W?void 0:W.custom_metadata)||void 0===t?void 0:t.pdf_start_page_number,null===(o=null==W?void 0:W.custom_metadata)||void 0===o?void 0:o.pdf_end_page_number]}):null},[null==A?void 0:A.title,null==A?void 0:A.signed_url,null==W?void 0:W.highlighted_text,null===(p=null==W?void 0:W.custom_metadata)||void 0===p?void 0:p.pdf_start_page_number,null===(g=null==W?void 0:W.custom_metadata)||void 0===g?void 0:g.pdf_end_page_number]),B=t.useMemo(function(){var e,n,t,o;return z&&H?i.jsx(l.default,{defaultScale:"PageWidth",showFullScreenAction:!1,showHighlightsAction:!1,pdfName:null==H?void 0:H.title,pdfUrl:null==H?void 0:H.signed_url,jumpToPageValue:1,highlightText:[null!==(e=null==z?void 0:z.highlighted_text)&&void 0!==e?e:""],highlightPages:{1:null===(n=null==z?void 0:z.custom_metadata)||void 0===n?void 0:n.pdf_start_page_number},highlightCordinatePages:[],useCoordinates:!1,useRange:!0,rangeOfPages:[null===(t=null==z?void 0:z.custom_metadata)||void 0===t?void 0:t.pdf_start_page_number,null===(o=null==z?void 0:z.custom_metadata)||void 0===o?void 0:o.pdf_end_page_number]}):null},[null==H?void 0:H.title,null==H?void 0:H.signed_url,null==z?void 0:z.highlighted_text,null===(h=null==z?void 0:z.custom_metadata)||void 0===h?void 0:h.pdf_start_page_number,null===(f=null==z?void 0:z.custom_metadata)||void 0===f?void 0:f.pdf_end_page_number]),L="dual_citation"===N,V=L&&!!(null==b?void 0:b.webGpt),J=t.useMemo(function(){if(!O)return null;var n=V?i.jsx(S,{metaData:b,isFullscreen:j}):"rulebook_citation"===N?i.jsx(i.Fragment,{children:i.jsx(d.Box,e.__assign({sx:e.__assign(e.__assign({padding:"0px 20px",backgroundColor:"#FFFFFF",borderRadius:"8px"},s.SHARED_MARKDOWN_STYLES),{overflow:"auto"})},{children:i.jsx(m.default,e.__assign({rehypePlugins:[x.default]},{children:v.processGuidelinesMarkdown({guidelinesData:D,targetHighlights:[T],labelColor:"#FEF08A"})}))}))}):B;return n?i.jsx(o.default,{leftComponent:O,rightComponent:n,isFullscreen:j}):O},[O,B,N,V,b,j,D,T]);return(null==b?void 0:b.webGpt)&&!U?i.jsx(S,{metaData:b,isFullscreen:j}):P?"rulebook_citation"===N?W?i.jsx("div",e.__assign({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:J})):i.jsx("div",e.__assign({style:{padding:"12px",fontSize:"13px",color:"#344054",lineHeight:1.5}},{children:C||"Rulebook citation selected."})):L?W||z?i.jsx("div",e.__assign({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:J})):(null==b?void 0:b.webGpt)?i.jsx(S,{metaData:b,isFullscreen:j}):i.jsx("div",{children:"Missing PDF Citation. Please try again later"}):["contract","clause"].includes(y)?W||z?i.jsx("div",e.__assign({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:J})):i.jsx("div",{children:"Missing PDF Citation. Please try again later"}):i.jsx("div",{children:"No Citation Found. Please try again later"}):null};exports.default=function(o){var l,r,u,s,c,v,p,g=o.href,h=o.children,m=o.citationType,x=o.citationReason,f=o.metaData,_=o.chevronUpComponent,b=void 0===_?null:_,y=o.chevronDownComponent,w=void 0===y?null:y,j=o.customStyle,D=void 0===j?{}:j,F=o.defaultState,S=void 0!==F&&F,T=o.onFullscreenChange,k=t.useState(S),M=k[0],N=k[1],I=t.useState(!1),R=I[0],G=I[1],U="string"==typeof h&&(null===(l=null==h?void 0:h.split("\n"))||void 0===l?void 0:l.length)>1?h.split("\n").join(" "):h;t.useEffect(function(){if(null==T||T(R),R)return function(){null==T||T(!1)}},[R,T]);var E="string"==typeof h?h:h[0],q=null!=b?b:function(e){var t,o;return i.jsx(n.ChevronUp,{size:null!==(t=null==e?void 0:e.fontSize)&&void 0!==t?t:16,color:null!==(o=null==e?void 0:e.color)&&void 0!==o?o:"rgb(214, 51, 132)"})}(null!==(r=null==D?void 0:D.arrow)&&void 0!==r?r:{}),A=null!=w?w:function(e){var t,o;return i.jsx(n.ChevronDown,{size:null!==(t=null==e?void 0:e.fontSize)&&void 0!==t?t:16,color:null!==(o=null==e?void 0:e.color)&&void 0!==o?o:"rgb(214, 51, 132)"})}(null!==(u=null==D?void 0:D.arrow)&&void 0!==u?u:{}),H=i.jsxs("div",e.__assign({style:{boxSizing:"border-box",border:R?"none":"1px solid #E4E7EC",borderRadius:R?0:"8px",overflow:"hidden",marginTop:R?0:"8px",display:"flex",flexDirection:"column",width:"100%",height:R?"100%":void 0,backgroundColor:"#FAFAFA"}},{children:[i.jsx("div",e.__assign({style:{display:"flex",justifyContent:"flex-end",padding:"6px 10px",borderBottom:"1px solid #E4E7EC",backgroundColor:"#FFFFFF",flexShrink:0}},{children:i.jsx("button",e.__assign({onClick:function(){G(function(e){return!e})},style:{background:"none",border:"none",cursor:"pointer",padding:"4px",borderRadius:"6px",color:"#475467",marginRight:"9px"}},{children:R?i.jsx(a.DefaultFullScreenCloseIcon,{}):i.jsx(a.DefaultFullScreenIcon,{})}))})),i.jsx("div",e.__assign({style:{flex:1,minHeight:0,height:"100%",overflow:"hidden"}},{children:i.jsx(P,{href:g,children:h,metaData:f,citationTitle:E,citationType:m,citationReason:x,isFullscreen:R})}))]}));return i.jsxs("span",e.__assign({style:e.__assign({display:"inline"},D.relativeWrapper||{})},{children:[i.jsx("div",e.__assign({style:e.__assign({display:"inline",marginTop:0},D.citationButtonWrapper||{})},{children:i.jsxs("button",e.__assign({type:"button",onClick:function(){return N(function(e){return!e})},style:e.__assign({display:(null==f?void 0:f.webGpt)?"inline":"inline-flex",alignItems:(null==f?void 0:f.webGpt)?void 0:"center",gap:(null==f?void 0:f.webGpt)?void 0:"3px",fontFamily:'"Inter", sans-serif',backgroundColor:"transparent",padding:0,margin:0,fontSize:"13px",borderRadius:9999,cursor:"pointer",fontWeight:(null==f?void 0:f.webGpt)?600:700,color:(null==f?void 0:f.webGpt)?"#6D28D9":"rgb(214, 51, 132)",border:"none",textDecoration:"none",wordBreak:"break-word",whiteSpace:"normal"},D.citationButton||{})},{children:[(null==f?void 0:f.webGpt)&&i.jsx(n.Globe,{size:null!==(c=null===(s=D.arrow)||void 0===s?void 0:s.fontSize)&&void 0!==c?c:"1em",color:null!==(p=null===(v=D.arrow)||void 0===v?void 0:v.color)&&void 0!==p?p:"#6D28D9",style:{display:"inline-block",width:"1em",height:"1em",marginRight:"3px",verticalAlign:"-0.125em",flexShrink:0}}),i.jsx("span",{children:U}),i.jsx("span",e.__assign({style:{display:"inline-flex",alignItems:"center",marginLeft:(null==f?void 0:f.webGpt)?"3px":void 0,verticalAlign:(null==f?void 0:f.webGpt)?"-0.125em":void 0}},{children:M?q:A}))]}))})),M&&(R?i.jsx(d.Dialog,e.__assign({open:R,onClose:function(){return G(!1)},maxWidth:!1,BackdropProps:{sx:{backgroundColor:"rgba(0, 0, 0, 0.6)",backdropFilter:"blur(4px)"}},PaperProps:{sx:{backgroundColor:"#FAFAFA",borderRadius:"16px",height:C,m:0,maxHeight:C,maxWidth:"95vw",overflow:"hidden",width:"95vw"}}},{children:H})):H)]}))};
|
|
2
2
|
//# sourceMappingURL=CitationAnchor.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(t){if("string"!=typeof t||""===t.trim())return null;try{var r="undefined"!=typeof window?window.location.origin:"http://localhost";return new URL(t,r)}catch(t){return null}},r=function(t,r){var e;if("string"!=typeof t||"string"!=typeof r||""===r.trim())return"";try{var n=t.match(new RegExp("\\b".concat(r,"\\s*=\\s*(['\"])(.*?)\\1"),"i"));return null!==(e=null==n?void 0:n[2])&&void 0!==e?e:""}catch(t){return""}},e=function(t){if("string"!=typeof t||""===t)return"";try{return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}catch(r){return t}},n=function(t,r,n){if("string"!=typeof t||""===t.trim())return t;if("string"!=typeof r||""===r.trim())return t;if(!n||"string"!=typeof n)return t;try{var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(t){if("string"!=typeof t||""===t.trim())return null;try{var r="undefined"!=typeof window?window.location.origin:"http://localhost";return new URL(t,r)}catch(t){return null}},r=function(t,r){var e;if("string"!=typeof t||"string"!=typeof r||""===r.trim())return"";try{var n=t.match(new RegExp("\\b".concat(r,"\\s*=\\s*(['\"])(.*?)\\1"),"i"));return null!==(e=null==n?void 0:n[2])&&void 0!==e?e:""}catch(t){return""}},e=function(t){if("string"!=typeof t||""===t)return"";try{return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}catch(r){return t}},n=function(t,r,n){if("string"!=typeof t||""===t.trim())return t;if("string"!=typeof r||""===r.trim())return t;if(!n||"string"!=typeof n)return t;try{var i=e(n),a=new RegExp("\\b".concat(r,"\\s*=\\s*(['\"])(.*?)\\1"),"i");return a.test(t)?t.replace(a,function(){return"".concat(r,'="').concat(i,'"')}):t.replace(/<a\b/i,function(){return"<a ".concat(r,'="').concat(i,'"')})}catch(r){return t}},i=function(r,e){if("string"!=typeof r||!r||"string"!=typeof e||!e)return"";try{var n=r.indexOf("?");if(n>=0){var i=r.slice(n+1).replace(/&/gi,"&"),a=i.indexOf("".concat(e,"="));if(a>=0){var c=a+e.length+1,o=i.slice(c).match(/&[A-Za-z_][A-Za-z0-9_]*=/),u=void 0!==(null==o?void 0:o.index)?c+o.index:i.length;return decodeURIComponent(i.slice(c,u).replace(/\+/g," "))}}var l=t(r.replace(/&/gi,"&"));return(null==l?void 0:l.searchParams.get(e))||""}catch(t){return""}};exports.mergeRulebookCitationsIntoMatchingLinks=function(a){if("string"!=typeof a||!a||!a.includes("citation_type"))return a;try{var c=a;return Array.from(a.matchAll(/<a\b([^>]*?)>([\s\S]*?)<\/a>/gi)).forEach(function(a){var o=a[0],u=a[1]||"",l=r(u,"href").replace(/&/gi,"&"),s=t(l),f=r(u,"type"),p=null==s?void 0:s.searchParams.get("citation_type");if("rulebook_citation"===f||"il_rulebook_citation"===p){f||(f=p||"rulebook_citation");var h=r(u,"reason"),g=(null==s?void 0:s.searchParams.get("citationNumber"))||(null==s?void 0:s.searchParams.get("citation_number"))||"",v=g.match(/^rb_(.+)$/),y=v?v[1]:g;if(y){var m={citation_type:p||"",phrase_to_highlight:i(l,"phrase_to_highlight")};if(m.citation_type||m.phrase_to_highlight){var d=!1,_=function(r){return function(r){if("string"!=typeof r||!r)return null;var e=r.match(/^(?:pdf_citation|deviation_summary)\$(\d+)/);if(e)return e[1];try{var n=t(r.replace(/&/gi,"&"));return(null==n?void 0:n.searchParams.get("citationNumber"))||(null==n?void 0:n.searchParams.get("citation_number"))||null}catch(t){return null}}(r)!==y?r:(d=!0,function(r,e){if("string"!=typeof r||""===r.trim())return r;if(!e||"object"!=typeof e)return r;try{var n=t(r);if(!n)return r;Object.entries(e).forEach(function(t){var r=t[0],e=t[1];e&&n.searchParams.set(r,e)});var i="".concat(n.pathname).concat(n.search).concat(n.hash);return r.startsWith("./")?".".concat(i):!r.startsWith("/")&&i.startsWith("/")?i.slice(1):i}catch(t){return r}}(r,m))};c=c.replace(/\[([^\]]+)\]\(([^)\n]+)\)/g,function(t,r,n){var i=_(n);return i===n?t:'<a type="'.concat(e(f),'" reason="').concat(e(h),'" href="').concat(e(i),'">').concat(r,"</a>")}),d||(c=c.replace(/<a\b([^>]*?)>/gi,function(e,i){var a,c=r(i,"type")||(null===(a=t(r(i,"href")))||void 0===a?void 0:a.searchParams.get("citation_type"));if("rulebook_citation"===c||"il_rulebook_citation"===c)return e;var o=r(i,"href"),u=_(o);if(u===o)return e;var l=e.replace(/\bhref\s*=\s*(['"])(.*?)\1/i,function(t,r){return"href=".concat(r).concat(u).concat(r)});return n(n(l,"type",f),"reason",h)})),c=c.split(o).join("")}else c=c.split(o).join("")}else c=c.split(o).join("")}}),c}catch(t){return a}};
|
|
2
2
|
//# sourceMappingURL=helper.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.processGuidelinesMarkdown=function(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.processGuidelinesMarkdown=function(t){var a,n,e=t.guidelinesData,o=t.targetHighlights,i=void 0===o?[]:o,r=t.labelColor,l=void 0===r?"#FEF08A":r,c="";if((null==e?void 0:e.learnings_data)&&Object.keys(e.learnings_data).length>0){var u=Object.keys(e.learnings_data)[0],d=e.learnings_data[u];(null==d?void 0:d.instruction_prompt)&&(c=d.instruction_prompt)}else{((null===(n=null===(a=null==e?void 0:e.data)||void 0===a?void 0:a.artifactData)||void 0===n?void 0:n.userStorySnapshot)||[]).forEach(function(t){var a;t.title&&(c+="### ".concat(t.title,"\n\n")),t.value&&(c+="".concat(t.value,"\n\n")),null===(a=t.sub_features)||void 0===a||a.forEach(function(t){t.title&&(c+="#### ".concat(t.title,"\n\n")),t.value&&(c+="".concat(t.value,"\n\n"))})})}return i.forEach(function(t,a){var n=t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),e=new RegExp("(".concat(n,")"),"g");c=c.replace(e,'<mark id="guideline-target-'.concat(a,'" style="background-color: ').concat(l,'; border-radius: 3px; padding: 2px;">$1</mark>'))}),c};
|
|
2
2
|
//# sourceMappingURL=processGuidelinesMarkdown.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("tslib"),e=require("react"),t=require("../CognitiveComparehelpers.js"),i=require("../utils/buildComparisonRows.js"),o={id:"",title:"",similarity:0,sections:[]};exports.useCognitiveTreeData=function(r,a,s,d,l,u){var v,c;void 0===l&&(l=!0);var f="string"==typeof s?s:JSON.stringify(s||{}),p=Boolean(u&&(null===(c=null===(v=u.data)||void 0===v?void 0:v.artifactData)||void 0===c?void 0:c.userStorySnapshot)),_=e.useMemo(function(){var e;if(!r||0===Object.keys(r).length)return{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:"Tree data is required"};var o=JSON.parse(f);try{var s=r.nodes||r,d=[],v=[],c=[],_=r.base_root_id,I=r.input_index_map||{0:"left",1:"right"},g=r[_]||s[_];if(!g||!1===g.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[],comparisonRows:[],parseError:null};var m=r.content_mapping||{},h=function(n){return r[n]||s[n]},y=function(e,i,o){if(!e||"object"!=typeof e)return e||null;if(e.deviations)return e;if(l)return e;var r=Object.keys(e).filter(function(n){return/^\d+$/.test(n)});if(!r.length)return e;var a=r.sort(function(n,e){return Number(n)-Number(e)}),s={},d={},u=null;return a.forEach(function(n){var r,a,l,v,c,f=e[n];if(f&&"object"==typeof f){u||(u=f);var p=!(null==f?void 0:f.status)||"pending"===f.status,_=function(n){var e,t=(null===(e=null==f?void 0:f.cognitive_decisioning)||void 0===e?void 0:e.citations)||(null==f?void 0:f.citations)||{};return Object.values(t).map(function(e){var t;return null===(t=null==e?void 0:e[n])||void 0===t?void 0:t.highlighted_text}).filter(function(n){return"string"==typeof n&&n.trim().length>0})},g=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];for(var i=0,o=n;i<o.length;i++){var r=o[i];if(Array.isArray(r)&&r.some(function(n){return!t.isMissingStr(n)}))return r}return[]},m=p?g((null===(a=null==f?void 0:f.deviation_highlights)||void 0===a?void 0:a[i])||(null===(l=null==f?void 0:f.deviation_highlights)||void 0===l?void 0:l[I[0]]),_(i),_(I[0])):[],h=p?g((null===(v=null==f?void 0:f.deviation_highlights)||void 0===v?void 0:v[o])||(null===(c=null==f?void 0:f.deviation_highlights)||void 0===c?void 0:c[I[1]]),_(o),_(I[1])):[];s[n]=((r={})[I[0]]=m[0]||"",r[I[1]]=h[0]||"",r.deviation_summary=(null==f?void 0:f.deviation_summary)||"",r.deviation_title=null==f?void 0:f.deviation_title,r.deviation_impact=null==f?void 0:f.deviation_impact,r.deviation_explanation=null==f?void 0:f.deviation_explanation,r.evaluation_outputs=null==f?void 0:f.evaluation_outputs,r.cognitive_decisioning=null==f?void 0:f.cognitive_decisioning,r.deviation_highlights=null==f?void 0:f.deviation_highlights,r),d[n]=f}}),n.__assign(n.__assign({},e),{deviation_title:(null==u?void 0:u.deviation_title)||(null==e?void 0:e.deviation_title),deviation_impact:(null==u?void 0:u.deviation_impact)||(null==e?void 0:e.deviation_impact),deviation_summary:(null==u?void 0:u.deviation_summary)||(null==e?void 0:e.deviation_summary),deviation_explanation:(null==u?void 0:u.deviation_explanation)||(null==e?void 0:e.deviation_explanation),evaluation_outputs:(null==u?void 0:u.evaluation_outputs)||(null==e?void 0:e.evaluation_outputs),cognitive_decisioning:(null==u?void 0:u.cognitive_decisioning)||(null==e?void 0:e.cognitive_decisioning),deviations:s,deviation_entries:d})},x=function(n){var e=new Map,t=function(n){n.forEach(function(n){var i;n.id&&e.set(n.id,n),(null===(i=n.subsections)||void 0===i?void 0:i.length)&&t(n.subsections)})};t(n);var i=function(n,t){for(var o,r=[],a=function(n){var a=n.ref_parent_section_node_id;if(a&&e.has(a)&&a!==(null==t?void 0:t.id)){var s=e.get(a);s.subsections||(s.subsections=[]),s.subsections.some(function(e){return e.id===n.id})||s.subsections.push(n)}else(null===(o=n.subsections)||void 0===o?void 0:o.length)&&(n.subsections=i(n.subsections,n)),r.push(n)},s=0,d=n;s<d.length;s++){a(d[s])}return r},o=i(n),r=function(n){n.forEach(function(n){n.subsections&&n.subsections.length>0&&(n.subsections.sort(function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:(n.selfIndex||0)-(e.selfIndex||0)}),r(n.subsections))})};return r(o),o},b=function(n){var e=n.comparison_inputs?Object.keys(n.comparison_inputs):[],t=I[0],i=I[1];return e.length>0&&(t=e.includes(I[0])?I[0]:e[0],i=e.includes(I[1])?I[1]:e.length>1?e[1]:e[0]),{nodeLeftId:t,nodeRightId:i}},R=function(e,i,o,r){var a=i.attributes||{},s=i.data||{},d=!1!==a.display_title,l=!1!==a.display_content,u=d?t.safeStringify(s.title||""):"",v=l?t.safeStringify(s.content||""):"",c=l?t.safeStringify(s.change_history||""):"",f=void 0!==a.display_index&&null!==a.display_index?Number(a.display_index):-1,p=function(n){return(null==n?void 0:n.entity_id)||(null==n?void 0:n.ref_parent_section_node_id)||(null==n?void 0:n.parent_entity_id)||null}(a),_=!(!u.trim()&&!v.trim());return n.__assign(n.__assign({id:"".concat(e,"::").concat(i.contentId),nodeId:e,contentId:i.contentId,parentContentId:p,title:u,content:v,change_history:c,displayTitle:d,displayContent:l,subsections:[]},_?r:{score:void 0,relation:"not_defined"}),{evaluationResult:o,evaluationResults:o?[o]:[],selfIndex:f,refIndexes:[],refContentIds:[],ref_parent_section_node_id:p})},C=function(e,t){e.refIndexes=Array.from(new Set(n.__spreadArray(n.__spreadArray([],e.refIndexes||[],!0),t.refIndexes||[],!0))),e.refContentIds=Array.from(new Set(n.__spreadArray(n.__spreadArray([],e.refContentIds||[],!0),t.refContentIds||[],!0)));var i=new Set((e.subsections||[]).map(function(n){return n.id||n.contentId||n.nodeId}));(t.subsections||[]).forEach(function(t){var o=t.id||t.contentId||t.nodeId;i.has(o)||(e.subsections=n.__spreadArray(n.__spreadArray([],e.subsections||[],!0),[t],!1),i.add(o))});var o=n.__spreadArray(n.__spreadArray([],e.evaluationResults||(e.evaluationResult?[e.evaluationResult]:[]),!0),t.evaluationResults||(t.evaluationResult?[t.evaluationResult]:[]),!0).filter(Boolean),r=new Set;return e.evaluationResults=o.filter(function(n){var e=(null==n?void 0:n.nodeId)||JSON.stringify(Object.keys((null==n?void 0:n.deviations)||n||{}));return!r.has(e)&&(r.add(e),!0)}),!e.evaluationResult&&t.evaluationResult&&(e.evaluationResult=t.evaluationResult),!e.cognitiveData&&t.cognitiveData&&(e.cognitiveData=t.cognitiveData),e},S=function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:n.selfIndex-e.selfIndex},E=function(e,i){var r,a=h(e);if(!a||!1===a.display_node)return[];if(p&&"1"===i)return[];var s=b(a),d=s.nodeLeftId,l=s.nodeRightId,u=t.getRationale(a),v=(null===(r=null==o?void 0:o[e])||void 0===r?void 0:r.evaluation_result)||a.evaluation_result||null,c=y(v,d,l),f=c&&"object"==typeof c?n.__assign(n.__assign({},c),{nodeId:e}):c,_=t.resolveComparisonInputItems(a,i,I,m).map(function(n){return R(e,n,f,u)});if(a.next){var g=Object.values(a.next).flatMap(function(n){return E(n,i)});_.forEach(function(n){var e=g.filter(function(e){return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId});n.subsections=e.length?e:g})}return _};if(a){var O=function(e,i){var r;void 0===i&&(i=0);var a=[],s=[];if(!e)return{refSections:a,baseSections:s};var d={},l={},u=-1,v=-1,c=function(a){var s=e[a],c=h(s);if(!c||!1===c.display_node)return"continue";var f=b(c),_=f.nodeLeftId,g=f.nodeRightId,x=t.getRationale(c),S=(null===(r=null==o?void 0:o[s])||void 0===r?void 0:r.evaluation_result)||c.evaluation_result||null,E=y(S,_,g),N=E&&"object"==typeof E?n.__assign(n.__assign({},E),{nodeId:s}):E,j=O(c.next,i+1),A=j.refSections,D=j.baseSections,w=t.resolveComparisonInputItems(c,"0",I,m).map(function(n){var e=R(s,n,N,x);return-1===e.selfIndex&&(e.selfIndex=v--),e}),M=[];if(!p){var P=t.resolveComparisonInputItems(c,"1",I,m);M=P.map(function(n){var e=R(s,n,N,x);return-1===e.selfIndex&&(e.selfIndex=u--),e})}w.forEach(function(n){M.forEach(function(e){var t,i,o,r,a,s,d,l;Number(e.selfIndex)>=0&&Number(n.selfIndex)>=0&&((null===(t=e.refIndexes)||void 0===t?void 0:t.includes(Number(n.selfIndex)))||null===(i=e.refIndexes)||void 0===i||i.push(Number(n.selfIndex)),(null===(o=n.refIndexes)||void 0===o?void 0:o.includes(Number(e.selfIndex)))||null===(r=n.refIndexes)||void 0===r||r.push(Number(e.selfIndex))),n.contentId&&!(null===(a=e.refContentIds)||void 0===a?void 0:a.includes(n.contentId))&&(null===(s=e.refContentIds)||void 0===s||s.push(n.contentId)),e.contentId&&!(null===(d=n.refContentIds)||void 0===d?void 0:d.includes(e.contentId))&&(null===(l=n.refContentIds)||void 0===l||l.push(e.contentId))})}),M.forEach(function(n){var e=A.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var t=0===i?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||s);d[t]=d[t]?C(d[t],n):n}),w.forEach(function(n){var e=D.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var t=0===i?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||s);l[t]=l[t]?C(l[t],n):n})};for(var f in e)c(f);return a=Object.values(d),s=Object.values(l),a.sort(S),s.sort(S),{refSections:a,baseSections:s}},N=O(g.next),j=N.refSections,A=N.baseSections;p||(v=x(j)),d=A}else g.next&&Object.values(g.next).forEach(function(n){var e=h(n);if(e&&!1!==e.display_node){var t=E(n,"0");if(p)d.push.apply(d,t);else{var o=x(E(n,"1"));c.push.apply(c,i.buildComparisonRows(n,t,o))}}}),p||(d=c.map(function(n){return n.left}),v=c.map(function(n){return n.right}));var D=t.getSideData(g,"0",I,m),w=t.getSideData(g,"1",I,m);return{activeProposed:{title:D.title||"Uploaded Contract",description:g.decision_scope_description||"",sections:d},activeVariants:[{id:"tree-variant-1",title:p?(null===(e=null==u?void 0:u.data)||void 0===e?void 0:e.artifactTitle)||"Rulebook Guidelines":w.title||"Reference Template",similarity:0,sections:v,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:g.decision_scope_description||""},fields:{}}}}],comparisonRows:c,parseError:null}}catch(n){return console.error("Data Transformation Error: ",n),{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:n instanceof Error?n.message:"Unknown Parsing Error"}}},[r,a,f,l,u]),I=_.activeProposed,g=_.activeVariants,m=_.comparisonRows,h=_.parseError,y=(null==g?void 0:g[0])||o,x=e.useMemo(function(){return(null==I?void 0:I.sections)||[]},[null==I?void 0:I.sections]),b=e.useMemo(function(){return y.sections||[]},[y.sections]),R=x.length>0||b.length>0,C=e.useMemo(function(){return d.fields.filter(function(n){var e=n.key;return(!R||"description"!==e)&&(t.hasValue(null==I?void 0:I[e])||t.hasValue(y[e]))})},[I,y,R,d.fields]),S=e.useMemo(function(){var n,e,i={},o={},s={},d=0,l=null===(n=null==r?void 0:r.input_index_map)||void 0===n?void 0:n[0],u=null===(e=null==r?void 0:r.input_index_map)||void 0===e?void 0:e[1],v=function(n,e){if(!a){var t="left"===e?x.indexOf(n):b.indexOf(n);return{rootKey:"".concat(e,":").concat(t),parentNum:t+1}}if("left"===e){var i=n.selfIndex,o=void 0!==i&&i>=0?i+1:x.indexOf(n)+1;return{rootKey:"left-root:".concat(n.id),parentNum:o}}var r=n.selfIndex,s=x.find(function(n){var e;return null===(e=n.refIndexes)||void 0===e?void 0:e.includes(r)});if(s){var d=s.selfIndex,l=void 0!==d&&d>=0?d+1:x.indexOf(s)+1;return{rootKey:"left-root:".concat(s.id),parentNum:l}}var u=void 0!==r&&r>=0?r+1:b.indexOf(n)+1;return{rootKey:"right-orphan-root:".concat(n.id),parentNum:u}},c=function(n,e){if(n&&e)return n.find(function(n){return n.id===e.id||n.nodeId&&n.nodeId===e.nodeId||n.contentId&&n.contentId===e.contentId})||void 0},f=function(n,e,r,a,v,p,_){if(e&&function(n,e,i){var r;((null===(r=null==n?void 0:n.evaluationResults)||void 0===r?void 0:r.length)?n.evaluationResults:(null==n?void 0:n.evaluationResult)?[n.evaluationResult]:[]).forEach(function(r){var a=(null==r?void 0:r.deviations)||{};Object.keys(a).sort().forEach(function(d){var v=a[d];if(v){var c=!t.isMissingStr(v[l]),f=!t.isMissingStr(v[u]);if(c||f){var p=(null==r?void 0:r.nodeId)||n.nodeId||n.id,_="".concat(p).concat(t.DEVIATION_BADGE_SEPARATOR).concat(d);void 0===o[_]&&(void 0===s[e]&&(s[e]=1),o[_]={index:s[e]++,rootKey:e,parentNum:i})}}})})}(e,a,v),e&&!p){var I=(null==_?void 0:_.id)||"fallback_parent_".concat(d++);i[I]||(i[I]=[]),i[I].push(e)}((null==e?void 0:e.subsections)||(null==n?void 0:n.subsections)||(null==r?void 0:r.subsections)||[]).forEach(function(t){var i=c(null==n?void 0:n.subsections,t),o=c(null==r?void 0:r.subsections,t);f(t,i,o,a,v,!1,e||_)})};x.forEach(function(n){var e,t=v(n,"left"),i=t.rootKey,o=t.parentNum,r=null;if(a){var s=null===(e=n.refIndexes)||void 0===e?void 0:e[0];r=b.find(function(n){return n.selfIndex===s})}else r=b[x.indexOf(n)];f(n,n,r,i,o,!0,n)}),p||b.forEach(function(n){var e=v(n,"right"),t=e.rootKey,i=e.parentNum;t.startsWith("right-orphan-root:")&&f(n,null,n,t,i,!0,n)});var _=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].index]})),I=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].parentNum]}));return{parentDeviationRecord:i,registry:_,deviationParentRegistry:I}},[x,b,a,r,p]),E=S.parentDeviationRecord,O=S.registry,N=S.deviationParentRegistry;return{isGuidelineMode:p,activeProposed:I,activeVariants:g,comparisonRows:m,existingRule:y,proposedSections:x,existingSections:b,visibleFields:C,parentDeviationRecord:E,deviationNumberRegistry:O,deviationParentRegistry:N,parseError:h}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("tslib"),e=require("react"),t=require("../CognitiveComparehelpers.js"),i=require("../utils/buildComparisonRows.js"),o={id:"",title:"",similarity:0,sections:[]};exports.useCognitiveTreeData=function(r,a,s,d,l,u){var v,c;void 0===l&&(l=!0);var f="string"==typeof s?s:JSON.stringify(s||{}),p=Boolean(u&&(u.learnings_data||(null===(c=null===(v=u.data)||void 0===v?void 0:v.artifactData)||void 0===c?void 0:c.userStorySnapshot))),_=e.useMemo(function(){if(!r||0===Object.keys(r).length)return{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:"Tree data is required"};var e=JSON.parse(f);try{var o=r.nodes||r,s=[],d=[],v=[],c=r.base_root_id,_=r.input_index_map||{0:"left",1:"right"},I=r[c]||o[c];if(!I||!1===I.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[],comparisonRows:[],parseError:null};var g=r.content_mapping||{},m=function(n){return r[n]||o[n]},h=function(e,i,o){if(!e||"object"!=typeof e)return e||null;if(e.deviations)return e;if(l)return e;var r=Object.keys(e).filter(function(n){return/^\d+$/.test(n)});if(!r.length)return e;var a=r.sort(function(n,e){return Number(n)-Number(e)}),s={},d={},u=null;return a.forEach(function(n){var r,a,l,v,c,f=e[n];if(f&&"object"==typeof f){u||(u=f);var p=!(null==f?void 0:f.status)||"pending"===f.status,I=function(n){var e,t=(null===(e=null==f?void 0:f.cognitive_decisioning)||void 0===e?void 0:e.citations)||(null==f?void 0:f.citations)||{};return Object.values(t).map(function(e){var t;return null===(t=null==e?void 0:e[n])||void 0===t?void 0:t.highlighted_text}).filter(function(n){return"string"==typeof n&&n.trim().length>0})},g=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];for(var i=0,o=n;i<o.length;i++){var r=o[i];if(Array.isArray(r)&&r.some(function(n){return!t.isMissingStr(n)}))return r}return[]},m=p?g((null===(a=null==f?void 0:f.deviation_highlights)||void 0===a?void 0:a[i])||(null===(l=null==f?void 0:f.deviation_highlights)||void 0===l?void 0:l[_[0]]),I(i),I(_[0])):[],h=p?g((null===(v=null==f?void 0:f.deviation_highlights)||void 0===v?void 0:v[o])||(null===(c=null==f?void 0:f.deviation_highlights)||void 0===c?void 0:c[_[1]]),I(o),I(_[1])):[];s[n]=((r={})[_[0]]=m[0]||"",r[_[1]]=h[0]||"",r.deviation_summary=(null==f?void 0:f.deviation_summary)||"",r.deviation_title=null==f?void 0:f.deviation_title,r.deviation_impact=null==f?void 0:f.deviation_impact,r.deviation_explanation=null==f?void 0:f.deviation_explanation,r.evaluation_outputs=null==f?void 0:f.evaluation_outputs,r.cognitive_decisioning=null==f?void 0:f.cognitive_decisioning,r.deviation_highlights=null==f?void 0:f.deviation_highlights,r),d[n]=f}}),n.__assign(n.__assign({},e),{deviation_title:(null==u?void 0:u.deviation_title)||(null==e?void 0:e.deviation_title),deviation_impact:(null==u?void 0:u.deviation_impact)||(null==e?void 0:e.deviation_impact),deviation_summary:(null==u?void 0:u.deviation_summary)||(null==e?void 0:e.deviation_summary),deviation_explanation:(null==u?void 0:u.deviation_explanation)||(null==e?void 0:e.deviation_explanation),evaluation_outputs:(null==u?void 0:u.evaluation_outputs)||(null==e?void 0:e.evaluation_outputs),cognitive_decisioning:(null==u?void 0:u.cognitive_decisioning)||(null==e?void 0:e.cognitive_decisioning),deviations:s,deviation_entries:d})},y=function(n){var e=new Map,t=function(n){n.forEach(function(n){var i;n.id&&e.set(n.id,n),(null===(i=n.subsections)||void 0===i?void 0:i.length)&&t(n.subsections)})};t(n);var i=function(n,t){for(var o,r=[],a=function(n){var a=n.ref_parent_section_node_id;if(a&&e.has(a)&&a!==(null==t?void 0:t.id)){var s=e.get(a);s.subsections||(s.subsections=[]),s.subsections.some(function(e){return e.id===n.id})||s.subsections.push(n)}else(null===(o=n.subsections)||void 0===o?void 0:o.length)&&(n.subsections=i(n.subsections,n)),r.push(n)},s=0,d=n;s<d.length;s++){a(d[s])}return r},o=i(n),r=function(n){n.forEach(function(n){n.subsections&&n.subsections.length>0&&(n.subsections.sort(function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:(n.selfIndex||0)-(e.selfIndex||0)}),r(n.subsections))})};return r(o),o},x=function(n){var e=n.comparison_inputs?Object.keys(n.comparison_inputs):[],t=_[0],i=_[1];return e.length>0&&(t=e.includes(_[0])?_[0]:e[0],i=e.includes(_[1])?_[1]:e.length>1?e[1]:e[0]),{nodeLeftId:t,nodeRightId:i}},b=function(e,i,o,r){var a=i.attributes||{},s=i.data||{},d=!1!==a.display_title,l=!1!==a.display_content,u=d?t.safeStringify(s.title||""):"",v=l?t.safeStringify(s.content||""):"",c=l?t.safeStringify(s.change_history||""):"",f=void 0!==a.display_index&&null!==a.display_index?Number(a.display_index):-1,p=function(n){return(null==n?void 0:n.entity_id)||(null==n?void 0:n.ref_parent_section_node_id)||(null==n?void 0:n.parent_entity_id)||null}(a),_=!(!u.trim()&&!v.trim());return n.__assign(n.__assign({id:"".concat(e,"::").concat(i.contentId),nodeId:e,contentId:i.contentId,parentContentId:p,title:u,content:v,change_history:c,displayTitle:d,displayContent:l,subsections:[]},_?r:{score:void 0,relation:"not_defined"}),{evaluationResult:o,evaluationResults:o?[o]:[],selfIndex:f,refIndexes:[],refContentIds:[],ref_parent_section_node_id:p})},R=function(e,t){e.refIndexes=Array.from(new Set(n.__spreadArray(n.__spreadArray([],e.refIndexes||[],!0),t.refIndexes||[],!0))),e.refContentIds=Array.from(new Set(n.__spreadArray(n.__spreadArray([],e.refContentIds||[],!0),t.refContentIds||[],!0)));var i=new Set((e.subsections||[]).map(function(n){return n.id||n.contentId||n.nodeId}));(t.subsections||[]).forEach(function(t){var o=t.id||t.contentId||t.nodeId;i.has(o)||(e.subsections=n.__spreadArray(n.__spreadArray([],e.subsections||[],!0),[t],!1),i.add(o))});var o=n.__spreadArray(n.__spreadArray([],e.evaluationResults||(e.evaluationResult?[e.evaluationResult]:[]),!0),t.evaluationResults||(t.evaluationResult?[t.evaluationResult]:[]),!0).filter(Boolean),r=new Set;return e.evaluationResults=o.filter(function(n){var e=(null==n?void 0:n.nodeId)||JSON.stringify(Object.keys((null==n?void 0:n.deviations)||n||{}));return!r.has(e)&&(r.add(e),!0)}),!e.evaluationResult&&t.evaluationResult&&(e.evaluationResult=t.evaluationResult),!e.cognitiveData&&t.cognitiveData&&(e.cognitiveData=t.cognitiveData),e},C=function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:n.selfIndex-e.selfIndex},S=function(i,o){var r,a=m(i);if(!a||!1===a.display_node)return[];if(p&&"1"===o)return[];var s=x(a),d=s.nodeLeftId,l=s.nodeRightId,u=t.getRationale(a),v=(null===(r=null==e?void 0:e[i])||void 0===r?void 0:r.evaluation_result)||a.evaluation_result||null,c=h(v,d,l),f=c&&"object"==typeof c?n.__assign(n.__assign({},c),{nodeId:i}):c,I=t.resolveComparisonInputItems(a,o,_,g).map(function(n){return b(i,n,f,u)});if(a.next){var y=Object.values(a.next).flatMap(function(n){return S(n,o)});I.forEach(function(n){var e=y.filter(function(e){return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId});n.subsections=e.length?e:y})}return I};if(a){var E=function(i,o){var r;void 0===o&&(o=0);var a=[],s=[];if(!i)return{refSections:a,baseSections:s};var d={},l={},u=-1,v=-1,c=function(a){var s=i[a],c=m(s);if(!c||!1===c.display_node)return"continue";var f=x(c),I=f.nodeLeftId,y=f.nodeRightId,C=t.getRationale(c),S=(null===(r=null==e?void 0:e[s])||void 0===r?void 0:r.evaluation_result)||c.evaluation_result||null,O=h(S,I,y),j=O&&"object"==typeof O?n.__assign(n.__assign({},O),{nodeId:s}):O,N=E(c.next,o+1),A=N.refSections,D=N.baseSections,w=t.resolveComparisonInputItems(c,"0",_,g).map(function(n){var e=b(s,n,j,C);return-1===e.selfIndex&&(e.selfIndex=v--),e}),k=[];if(!p){var M=t.resolveComparisonInputItems(c,"1",_,g);k=M.map(function(n){var e=b(s,n,j,C);return-1===e.selfIndex&&(e.selfIndex=u--),e})}w.forEach(function(n){k.forEach(function(e){var t,i,o,r,a,s,d,l;Number(e.selfIndex)>=0&&Number(n.selfIndex)>=0&&((null===(t=e.refIndexes)||void 0===t?void 0:t.includes(Number(n.selfIndex)))||null===(i=e.refIndexes)||void 0===i||i.push(Number(n.selfIndex)),(null===(o=n.refIndexes)||void 0===o?void 0:o.includes(Number(e.selfIndex)))||null===(r=n.refIndexes)||void 0===r||r.push(Number(e.selfIndex))),n.contentId&&!(null===(a=e.refContentIds)||void 0===a?void 0:a.includes(n.contentId))&&(null===(s=e.refContentIds)||void 0===s||s.push(n.contentId)),e.contentId&&!(null===(d=n.refContentIds)||void 0===d?void 0:d.includes(e.contentId))&&(null===(l=n.refContentIds)||void 0===l||l.push(e.contentId))})}),k.forEach(function(n){var e=A.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var t=0===o?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||s);d[t]=d[t]?R(d[t],n):n}),w.forEach(function(n){var e=D.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var t=0===o?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||s);l[t]=l[t]?R(l[t],n):n})};for(var f in i)c(f);return a=Object.values(d),s=Object.values(l),a.sort(C),s.sort(C),{refSections:a,baseSections:s}},O=E(I.next),j=O.refSections,N=O.baseSections;p||(d=y(j)),s=N}else I.next&&Object.values(I.next).forEach(function(n){var e=m(n);if(e&&!1!==e.display_node){var t=S(n,"0");if(p)s.push.apply(s,t);else{var o=y(S(n,"1"));v.push.apply(v,i.buildComparisonRows(n,t,o))}}}),p||(s=v.map(function(n){return n.left}),d=v.map(function(n){return n.right}));var A=t.getSideData(I,"0",_,g),D=t.getSideData(I,"1",_,g),w={title:A.title||"Uploaded Contract",description:I.decision_scope_description||"",sections:s},k={id:"tree-variant-1",title:p?function(){var n,e;if((null==u?void 0:u.learnings_data)&&Object.keys(u.learnings_data).length>0){var t=Object.keys(u.learnings_data)[0];return(null===(n=u.learnings_data[t])||void 0===n?void 0:n.title)||"Rulebook Guidelines"}return(null===(e=null==u?void 0:u.data)||void 0===e?void 0:e.artifactTitle)||"Rulebook Guidelines"}():D.title||"Reference Template",similarity:0,sections:d,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:I.decision_scope_description||""},fields:{}}}};return{activeProposed:w,activeVariants:[k],comparisonRows:v,parseError:null}}catch(n){return console.error("Data Transformation Error: ",n),{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:n instanceof Error?n.message:"Unknown Parsing Error"}}},[r,a,f,l,u]),I=_.activeProposed,g=_.activeVariants,m=_.comparisonRows,h=_.parseError,y=(null==g?void 0:g[0])||o,x=e.useMemo(function(){return(null==I?void 0:I.sections)||[]},[null==I?void 0:I.sections]),b=e.useMemo(function(){return y.sections||[]},[y.sections]),R=x.length>0||b.length>0,C=e.useMemo(function(){return d.fields.filter(function(n){var e=n.key;return(!R||"description"!==e)&&(t.hasValue(null==I?void 0:I[e])||t.hasValue(y[e]))})},[I,y,R,d.fields]),S=e.useMemo(function(){var n,e,i={},o={},s={},d=0,l=null===(n=null==r?void 0:r.input_index_map)||void 0===n?void 0:n[0],u=null===(e=null==r?void 0:r.input_index_map)||void 0===e?void 0:e[1],v=function(n,e){if(!a){var t="left"===e?x.indexOf(n):b.indexOf(n);return{rootKey:"".concat(e,":").concat(t),parentNum:t+1}}if("left"===e){var i=n.selfIndex,o=void 0!==i&&i>=0?i+1:x.indexOf(n)+1;return{rootKey:"left-root:".concat(n.id),parentNum:o}}var r=n.selfIndex,s=x.find(function(n){var e;return null===(e=n.refIndexes)||void 0===e?void 0:e.includes(r)});if(s){var d=s.selfIndex,l=void 0!==d&&d>=0?d+1:x.indexOf(s)+1;return{rootKey:"left-root:".concat(s.id),parentNum:l}}var u=void 0!==r&&r>=0?r+1:b.indexOf(n)+1;return{rootKey:"right-orphan-root:".concat(n.id),parentNum:u}},c=function(n,e){if(n&&e)return n.find(function(n){return n.id===e.id||n.nodeId&&n.nodeId===e.nodeId||n.contentId&&n.contentId===e.contentId})||void 0},f=function(n,e,r,a,v,p,_){if(e&&function(n,e,i){var r;((null===(r=null==n?void 0:n.evaluationResults)||void 0===r?void 0:r.length)?n.evaluationResults:(null==n?void 0:n.evaluationResult)?[n.evaluationResult]:[]).forEach(function(r){var a=(null==r?void 0:r.deviations)||{};Object.keys(a).sort().forEach(function(d){var v=a[d];if(v){var c=!t.isMissingStr(v[l]),f=!t.isMissingStr(v[u]);if(c||f){var p=(null==r?void 0:r.nodeId)||n.nodeId||n.id,_="".concat(p).concat(t.DEVIATION_BADGE_SEPARATOR).concat(d);void 0===o[_]&&(void 0===s[e]&&(s[e]=1),o[_]={index:s[e]++,rootKey:e,parentNum:i})}}})})}(e,a,v),e&&!p){var I=(null==_?void 0:_.id)||"fallback_parent_".concat(d++);i[I]||(i[I]=[]),i[I].push(e)}((null==e?void 0:e.subsections)||(null==n?void 0:n.subsections)||(null==r?void 0:r.subsections)||[]).forEach(function(t){var i=c(null==n?void 0:n.subsections,t),o=c(null==r?void 0:r.subsections,t);f(t,i,o,a,v,!1,e||_)})};x.forEach(function(n){var e,t=v(n,"left"),i=t.rootKey,o=t.parentNum,r=null;if(a){var s=null===(e=n.refIndexes)||void 0===e?void 0:e[0];r=b.find(function(n){return n.selfIndex===s})}else r=b[x.indexOf(n)];f(n,n,r,i,o,!0,n)}),p||b.forEach(function(n){var e=v(n,"right"),t=e.rootKey,i=e.parentNum;t.startsWith("right-orphan-root:")&&f(n,null,n,t,i,!0,n)});var _=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].index]})),I=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].parentNum]}));return{parentDeviationRecord:i,registry:_,deviationParentRegistry:I}},[x,b,a,r,p]),E=S.parentDeviationRecord,O=S.registry,j=S.deviationParentRegistry;return{isGuidelineMode:p,activeProposed:I,activeVariants:g,comparisonRows:m,existingRule:y,proposedSections:x,existingSections:b,visibleFields:C,parentDeviationRecord:E,deviationNumberRegistry:O,deviationParentRegistry:j,parseError:h}};
|
|
2
2
|
//# sourceMappingURL=useCompareData.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__assign as i,__awaiter as n,__generator as o}from"tslib";import{jsxs as t,jsx as e,Fragment as l}from"react/jsx-runtime";import{Globe as r,ChevronUp as a,ChevronDown as d,Maximize2 as u,X as c,ExternalLink as s}from"lucide-react";import{useState as v,useEffect as p,useMemo as h,useRef as m}from"react";import g from"./ResizableSplitPane.js";import f from"../PdfViewer/PdfViewer.js";import{DefaultFullScreenCloseIcon as x,DefaultFullScreenIcon as b}from"../../assests/svg/PdfViewerIcons.js";import _ from"react-markdown";import y from"rehype-raw";import{Dialog as w,Box as C}from"@mui/material";import{SHARED_MARKDOWN_STYLES as F}from"./CognitiveCompareConfig.js";import"react-dom";import{useCompareContext as D}from"./CompareContext.js";import{processGuidelinesMarkdown as P}from"./Guidelines/utils/processGuidelinesMarkdown.js";import S from"../GptWebCitation/GptWebCitation.js";import{CitationType as T}from"../GptWebCitation/types.js";import"./MoreFunctionsPopup.js";import"./components/SubSectionAccordion.js";import"./components/LHSSectionRow.js";import"./components/RHSSectionRow.js";var k=function(i){var n,o,t;return(null===(t=null===(o=null===(n=(null==i?void 0:i.extraMetaData)||i)||void 0===n?void 0:n.aiReasoningCitation)||void 0===o?void 0:o.gpt_citation)||void 0===t?void 0:t[0])||null},j="https://dev-proposals-ai.techo.camp/utility/ca-workflow-composer-agent/get_citation",I="sai.siddhartha@techolution.com",G="672e32f7a0e8fe2e8e50bcba",N="TNV Sai Siddhartha",R="90vh",E="calc(".concat(R," - 120px)"),M=function(){var i;return"function"==typeof(null===(i=globalThis.crypto)||void 0===i?void 0:i.randomUUID)?globalThis.crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(i){var n=Math.floor(16*Math.random());return("x"===i?n:n%4+8).toString(16)})},A=function(i,n){var o=function(i){var n;return(null==i?void 0:i.payloadCitationId)||(null===(n=null==i?void 0:i.extraMetaData)||void 0===n?void 0:n.payloadCitationId)||""}(i)||n||M();return function(i,n){i&&"object"==typeof i&&(i.payloadCitationId=n,i.extraMetaData&&"object"==typeof i.extraMetaData&&(i.extraMetaData.payloadCitationId=n))}(i,o),o},U=function(t){var l,r=t.metaData,g=t.isFullscreen,f=void 0!==g&&g,x=D().gptWebCitationConfig,b=h(function(){return function(i){return{endpoint:(null==i?void 0:i.endpoint)||j,userEmail:(null==i?void 0:i.userEmail)||I,userId:(null==i?void 0:i.userId)||G,userName:(null==i?void 0:i.userName)||N,headers:null==i?void 0:i.headers}}(x)},[x]),_=null==r?void 0:r.webGpt,y=m(null);y.current||(y.current=M());var w=h(function(){return function(i,n,o){var t,e,l=k(i),r=(null==l?void 0:l.customMetaData)||{},a=(null==r?void 0:r.value)||{},d=(null==i?void 0:i.webSearchAnswer)||{},u=(null==i?void 0:i.extraMetaData)||i||{};return{userEmail:(null==i?void 0:i.userEmail)||(null==d?void 0:d.userEmail)||(null==n?void 0:n.userEmail)||"",userId:(null==i?void 0:i.userId)||(null==d?void 0:d.userId)||(null==n?void 0:n.userId)||"",userName:(null==i?void 0:i.userName)||(null==d?void 0:d.userName)||(null==n?void 0:n.userName)||"",citationId:A(i,o),citationUrl:(null==a?void 0:a.citationUrl)||(null==d?void 0:d.citationUrl)||"",content:(null==u?void 0:u.Reasoning)||(null==d?void 0:d.enhanced_content)||"",citationType:(null==a?void 0:a.citationType)||"web",citatioNumber:null!==(e=null!==(t=null==r?void 0:r.citation_number)&&void 0!==t?t:null==l?void 0:l.citation_number)&&void 0!==e?e:Number((null==i?void 0:i.reasoningId)||0)}}(_,b,y.current||void 0)},[_,b]),C=h(function(){return k(_)},[_]),F=(null===(l=null==C?void 0:C.customMetaData)||void 0===l?void 0:l.value)||{},P=(null==_?void 0:_.extraMetaData)||_||{},R=v(),U=R[0],W=R[1],H=v("pending"),z=H[0],V=H[1],B=v(!0),O=B[0],L=B[1];p(function(){var t=!0;return n(void 0,void 0,void 0,function(){var n,e,l,r;return o(this,function(o){switch(o.label){case 0:if(!b.endpoint||!(null==w?void 0:w.citationUrl)||!(null==w?void 0:w.content))return V("error"),[2];V("pending"),o.label=1;case 1:return o.trys.push([1,4,,5]),[4,fetch(b.endpoint,{method:"POST",headers:i({"actor-id":w.userEmail,Accept:"application/json, text/plain, */*","Content-Type":"application/json"},b.headers||{}),body:JSON.stringify(w)})];case 2:if(!(n=o.sent()).ok)throw new Error("Failed to fetch GPT web citation (".concat(n.status,")"));return[4,n.json()];case 3:return e=o.sent(),l=(null==e?void 0:e.responseData)||(null==e?void 0:e.result)||(null==e?void 0:e.data)||e,t?(W(l),V("success"),[3,5]):[2];case 4:return r=o.sent(),t?(console.error("Failed to load GPT web citation",r),V("error"),[3,5]):[2];case 5:return[2]}})}),function(){t=!1}},[w,b]);var J=h(function(){return{item:{confidence_score:Number((null==P?void 0:P.Confidence_score)||0),text:(null==F?void 0:F.paraphrase)||"Web citation reasoning",dataSource:(null==F?void 0:F.text)||(null==P?void 0:P.Reasoning)||"",paraphrase:(null==F?void 0:F.paraphrase)||""},headerTitle:"GPT Web Citation",index:Number((null==w?void 0:w.citatioNumber)||1)-1,iconsConfig:{ChevronDownIcon:d,ChevronUpIcon:a,MaximizeIcon:u,CloseIcon:c}}},[F,null==w?void 0:w.citatioNumber,P]),q=h(function(){return i(i({},J),f?{bodyHeight:E}:{})},[J,f]);return e(S,{gptCitation:q,defaultCitationUrl:(null==w?void 0:w.citationUrl)||"",citationType:T.GPT_WEB,webCitationData:U,webCitationStatus:z,showWebCitation:O,onToggleCitationView:function(){return L(function(i){return!i})},iconsConfig:{MaximizeIcon:u,ExternalLinkIcon:s},isFixedHeight:!0})},W=function(n){var o,t,r,a,d,u,c,s=n.href,v=n.metaData,p=n.citationTitle,m=n.citationType,x=n.citationReason,b=n.isFullscreen,w=D().guidelinesData,S=function(i){try{var n=new URL(i,window.location.origin);return{citationNumber:n.searchParams.get("citationNumber"),phraseToHighlight:n.searchParams.get("phrase_to_highlight")}}catch(i){return{citationNumber:null,phraseToHighlight:null}}}(s),T=S.citationNumber,k=S.phraseToHighlight,j=T&&(null===(o=null==v?void 0:v.citations)||void 0===o?void 0:o[T])||{},I=(null===(t=null==v?void 0:v.docData)||void 0===t?void 0:t.documents)||{},G=(null===(r=null==v?void 0:v.docData)||void 0===r?void 0:r.input_index_map)||{},N=Object.keys((null==v?void 0:v.citations)||{}).length>0||Object.keys((null==v?void 0:v.docData)||{}).length>0,R=null==G?void 0:G[0],E=null==G?void 0:G[1],M=R?I[R]:null,A=E?I[E]:null,W=R?j[R]:null,H=E?j[E]:null,z=h(function(){var i,n,o,t;return W&&M?e(f,{defaultScale:"PageWidth",showFullScreenAction:!1,showHighlightsAction:!1,pdfName:null==M?void 0:M.title,pdfUrl:null==M?void 0:M.signed_url,highlightText:[null!==(i=null==W?void 0:W.highlighted_text)&&void 0!==i?i:""],highlightPages:{1:null===(n=null==W?void 0:W.custom_metadata)||void 0===n?void 0:n.pdf_start_page_number},jumpToPageValue:1,highlightCordinatePages:[],useCoordinates:!1,useRange:!0,rangeOfPages:[null===(o=null==W?void 0:W.custom_metadata)||void 0===o?void 0:o.pdf_start_page_number,null===(t=null==W?void 0:W.custom_metadata)||void 0===t?void 0:t.pdf_end_page_number]}):null},[null==M?void 0:M.title,null==M?void 0:M.signed_url,null==W?void 0:W.highlighted_text,null===(a=null==W?void 0:W.custom_metadata)||void 0===a?void 0:a.pdf_start_page_number,null===(d=null==W?void 0:W.custom_metadata)||void 0===d?void 0:d.pdf_end_page_number]),V=h(function(){var i,n,o,t;return H&&A?e(f,{defaultScale:"PageWidth",showFullScreenAction:!1,showHighlightsAction:!1,pdfName:null==A?void 0:A.title,pdfUrl:null==A?void 0:A.signed_url,jumpToPageValue:1,highlightText:[null!==(i=null==H?void 0:H.highlighted_text)&&void 0!==i?i:""],highlightPages:{1:null===(n=null==H?void 0:H.custom_metadata)||void 0===n?void 0:n.pdf_start_page_number},highlightCordinatePages:[],useCoordinates:!1,useRange:!0,rangeOfPages:[null===(o=null==H?void 0:H.custom_metadata)||void 0===o?void 0:o.pdf_start_page_number,null===(t=null==H?void 0:H.custom_metadata)||void 0===t?void 0:t.pdf_end_page_number]}):null},[null==A?void 0:A.title,null==A?void 0:A.signed_url,null==H?void 0:H.highlighted_text,null===(u=null==H?void 0:H.custom_metadata)||void 0===u?void 0:u.pdf_start_page_number,null===(c=null==H?void 0:H.custom_metadata)||void 0===c?void 0:c.pdf_end_page_number]),B="dual_citation"===m,O=B&&!!(null==v?void 0:v.webGpt),L=h(function(){if(!z)return null;var n=O?e(U,{metaData:v,isFullscreen:b}):"rulebook_citation"===m?e(l,{children:e(C,i({sx:i(i({padding:"0px 20px",backgroundColor:"#FFFFFF",borderRadius:"8px"},F),{overflow:"auto"})},{children:e(_,i({rehypePlugins:[y]},{children:P({guidelinesData:w,targetHighlights:[k],labelColor:"#FEF08A"})}))}))}):V;return n?e(g,{leftComponent:z,rightComponent:n,isFullscreen:b}):z},[z,V,m,O,v,b]);return(null==v?void 0:v.webGpt)&&!N?e(U,{metaData:v,isFullscreen:b}):T?"rulebook_citation"===m?e("div",W?i({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:L}):i({style:{padding:"12px",fontSize:"13px",color:"#344054",lineHeight:1.5}},{children:x||"Rulebook citation selected."})):B?W||H?e("div",i({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:L})):(null==v?void 0:v.webGpt)?e(U,{metaData:v,isFullscreen:b}):e("div",{children:"Missing PDF Citation. Please try again later"}):["contract","clause"].includes(p)?e("div",W||H?i({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:L}):{children:"Missing PDF Citation. Please try again later"}):e("div",{children:"No Citation Found. Please try again later"}):null},H=function(n){var o,l,u,c,s,h,m,g=n.href,f=n.children,_=n.citationType,y=n.citationReason,C=n.metaData,F=n.chevronUpComponent,D=void 0===F?null:F,P=n.chevronDownComponent,S=void 0===P?null:P,T=n.customStyle,k=void 0===T?{}:T,j=n.defaultState,I=void 0!==j&&j,G=n.onFullscreenChange,N=v(I),E=N[0],M=N[1],A=v(!1),U=A[0],H=A[1],z="string"==typeof f&&(null===(o=null==f?void 0:f.split("\n"))||void 0===o?void 0:o.length)>1?f.split("\n").join(" "):f;p(function(){if(null==G||G(U),U)return function(){null==G||G(!1)}},[U,G]);var V="string"==typeof f?f:f[0],B=null!=D?D:function(i){var n,o;return e(a,{size:null!==(n=null==i?void 0:i.fontSize)&&void 0!==n?n:16,color:null!==(o=null==i?void 0:i.color)&&void 0!==o?o:"rgb(214, 51, 132)"})}(null!==(l=null==k?void 0:k.arrow)&&void 0!==l?l:{}),O=null!=S?S:function(i){var n,o;return e(d,{size:null!==(n=null==i?void 0:i.fontSize)&&void 0!==n?n:16,color:null!==(o=null==i?void 0:i.color)&&void 0!==o?o:"rgb(214, 51, 132)"})}(null!==(u=null==k?void 0:k.arrow)&&void 0!==u?u:{}),L=t("div",i({style:{boxSizing:"border-box",border:U?"none":"1px solid #E4E7EC",borderRadius:U?0:"8px",overflow:"hidden",marginTop:U?0:"8px",display:"flex",flexDirection:"column",width:"100%",height:U?"100%":void 0,backgroundColor:"#FAFAFA"}},{children:[e("div",i({style:{display:"flex",justifyContent:"flex-end",padding:"6px 10px",borderBottom:"1px solid #E4E7EC",backgroundColor:"#FFFFFF",flexShrink:0}},{children:e("button",i({onClick:function(){H(function(i){return!i})},style:{background:"none",border:"none",cursor:"pointer",padding:"4px",borderRadius:"6px",color:"#475467",marginRight:"9px"}},{children:e(U?x:b,{})}))})),e("div",i({style:{flex:1,minHeight:0,height:"100%",overflow:"hidden"}},{children:e(W,{href:g,children:f,metaData:C,citationTitle:V,citationType:_,citationReason:y,isFullscreen:U})}))]}));return t("span",i({style:i({display:"inline"},k.relativeWrapper||{})},{children:[e("div",i({style:i({display:"inline",marginTop:0},k.citationButtonWrapper||{})},{children:t("button",i({type:"button",onClick:function(){return M(function(i){return!i})},style:i({display:(null==C?void 0:C.webGpt)?"inline":"inline-flex",alignItems:(null==C?void 0:C.webGpt)?void 0:"center",gap:(null==C?void 0:C.webGpt)?void 0:"3px",fontFamily:'"Inter", sans-serif',backgroundColor:"transparent",padding:0,margin:0,fontSize:"13px",borderRadius:9999,cursor:"pointer",fontWeight:(null==C?void 0:C.webGpt)?600:700,color:(null==C?void 0:C.webGpt)?"#6D28D9":"rgb(214, 51, 132)",border:"none",textDecoration:"none",wordBreak:"break-word",whiteSpace:"normal"},k.citationButton||{})},{children:[(null==C?void 0:C.webGpt)&&e(r,{size:null!==(s=null===(c=k.arrow)||void 0===c?void 0:c.fontSize)&&void 0!==s?s:"1em",color:null!==(m=null===(h=k.arrow)||void 0===h?void 0:h.color)&&void 0!==m?m:"#6D28D9",style:{display:"inline-block",width:"1em",height:"1em",marginRight:"3px",verticalAlign:"-0.125em",flexShrink:0}}),e("span",{children:z}),e("span",i({style:{display:"inline-flex",alignItems:"center",marginLeft:(null==C?void 0:C.webGpt)?"3px":void 0,verticalAlign:(null==C?void 0:C.webGpt)?"-0.125em":void 0}},{children:E?B:O}))]}))})),E&&(U?e(w,i({open:U,onClose:function(){return H(!1)},maxWidth:!1,BackdropProps:{sx:{backgroundColor:"rgba(0, 0, 0, 0.6)",backdropFilter:"blur(4px)"}},PaperProps:{sx:{backgroundColor:"#FAFAFA",borderRadius:"16px",height:R,m:0,maxHeight:R,maxWidth:"95vw",overflow:"hidden",width:"95vw"}}},{children:L})):L)]}))};export{H as default};
|
|
1
|
+
import{__assign as i,__awaiter as n,__generator as t}from"tslib";import{jsxs as o,jsx as e,Fragment as l}from"react/jsx-runtime";import{Globe as r,ChevronUp as a,ChevronDown as d,Maximize2 as u,X as c,ExternalLink as s}from"lucide-react";import{useState as v,useEffect as p,useMemo as m,useRef as h}from"react";import g from"./ResizableSplitPane.js";import f from"../PdfViewer/PdfViewer.js";import{DefaultFullScreenCloseIcon as b,DefaultFullScreenIcon as x}from"../../assests/svg/PdfViewerIcons.js";import _ from"react-markdown";import y from"rehype-raw";import{Dialog as w,Box as C}from"@mui/material";import{SHARED_MARKDOWN_STYLES as F}from"./CognitiveCompareConfig.js";import"react-dom";import{useCompareContext as D}from"./CompareContext.js";import{processGuidelinesMarkdown as P}from"./Guidelines/utils/processGuidelinesMarkdown.js";import T from"../GptWebCitation/GptWebCitation.js";import{CitationType as S}from"../GptWebCitation/types.js";import"./MoreFunctionsPopup.js";import"./components/SubSectionAccordion.js";import"./components/LHSSectionRow.js";import"./components/RHSSectionRow.js";var k=function(i){var n,t,o;return(null===(o=null===(t=null===(n=(null==i?void 0:i.extraMetaData)||i)||void 0===n?void 0:n.aiReasoningCitation)||void 0===t?void 0:t.gpt_citation)||void 0===o?void 0:o[0])||null},N="https://dev-proposals-ai.techo.camp/utility/ca-workflow-composer-agent/get_citation",j="sai.siddhartha@techolution.com",I="672e32f7a0e8fe2e8e50bcba",R="TNV Sai Siddhartha",G="90vh",U="calc(".concat(G," - 120px)"),E=function(){var i;return"function"==typeof(null===(i=globalThis.crypto)||void 0===i?void 0:i.randomUUID)?globalThis.crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(i){var n=Math.floor(16*Math.random());return("x"===i?n:n%4+8).toString(16)})},M=function(i,n){var t=function(i){var n;return(null==i?void 0:i.payloadCitationId)||(null===(n=null==i?void 0:i.extraMetaData)||void 0===n?void 0:n.payloadCitationId)||""}(i)||n||E();return function(i,n){i&&"object"==typeof i&&(i.payloadCitationId=n,i.extraMetaData&&"object"==typeof i.extraMetaData&&(i.extraMetaData.payloadCitationId=n))}(i,t),t},A=function(o){var l,r=o.metaData,g=o.isFullscreen,f=void 0!==g&&g,b=D().gptWebCitationConfig,x=m(function(){return function(i){return{endpoint:(null==i?void 0:i.endpoint)||N,userEmail:(null==i?void 0:i.userEmail)||j,userId:(null==i?void 0:i.userId)||I,userName:(null==i?void 0:i.userName)||R,headers:null==i?void 0:i.headers}}(b)},[b]),_=null==r?void 0:r.webGpt,y=h(null);y.current||(y.current=E());var w=m(function(){return function(i,n,t){var o,e,l=k(i),r=(null==l?void 0:l.customMetaData)||{},a=(null==r?void 0:r.value)||{},d=(null==i?void 0:i.webSearchAnswer)||{},u=(null==i?void 0:i.extraMetaData)||i||{};return{userEmail:(null==i?void 0:i.userEmail)||(null==d?void 0:d.userEmail)||(null==n?void 0:n.userEmail)||"",userId:(null==i?void 0:i.userId)||(null==d?void 0:d.userId)||(null==n?void 0:n.userId)||"",userName:(null==i?void 0:i.userName)||(null==d?void 0:d.userName)||(null==n?void 0:n.userName)||"",citationId:M(i,t),citationUrl:(null==a?void 0:a.citationUrl)||(null==d?void 0:d.citationUrl)||"",content:(null==u?void 0:u.Reasoning)||(null==d?void 0:d.enhanced_content)||"",citationType:(null==a?void 0:a.citationType)||"web",citatioNumber:null!==(e=null!==(o=null==r?void 0:r.citation_number)&&void 0!==o?o:null==l?void 0:l.citation_number)&&void 0!==e?e:Number((null==i?void 0:i.reasoningId)||0)}}(_,x,y.current||void 0)},[_,x]),C=m(function(){return k(_)},[_]),F=(null===(l=null==C?void 0:C.customMetaData)||void 0===l?void 0:l.value)||{},P=(null==_?void 0:_.extraMetaData)||_||{},G=v(),A=G[0],H=G[1],W=v("pending"),z=W[0],O=W[1],V=v(!0),B=V[0],L=V[1];p(function(){var o=!0;return n(void 0,void 0,void 0,function(){var n,e,l,r;return t(this,function(t){switch(t.label){case 0:if(!x.endpoint||!(null==w?void 0:w.citationUrl)||!(null==w?void 0:w.content))return O("error"),[2];O("pending"),t.label=1;case 1:return t.trys.push([1,4,,5]),[4,fetch(x.endpoint,{method:"POST",headers:i({"actor-id":w.userEmail,Accept:"application/json, text/plain, */*","Content-Type":"application/json"},x.headers||{}),body:JSON.stringify(w)})];case 2:if(!(n=t.sent()).ok)throw new Error("Failed to fetch GPT web citation (".concat(n.status,")"));return[4,n.json()];case 3:return e=t.sent(),l=(null==e?void 0:e.responseData)||(null==e?void 0:e.result)||(null==e?void 0:e.data)||e,o?(H(l),O("success"),[3,5]):[2];case 4:return r=t.sent(),o?(console.error("Failed to load GPT web citation",r),O("error"),[3,5]):[2];case 5:return[2]}})}),function(){o=!1}},[w,x]);var J=m(function(){return{item:{confidence_score:Number((null==P?void 0:P.Confidence_score)||0),text:(null==F?void 0:F.paraphrase)||"Web citation reasoning",dataSource:(null==F?void 0:F.text)||(null==P?void 0:P.Reasoning)||"",paraphrase:(null==F?void 0:F.paraphrase)||""},headerTitle:"GPT Web Citation",index:Number((null==w?void 0:w.citatioNumber)||1)-1,iconsConfig:{ChevronDownIcon:d,ChevronUpIcon:a,MaximizeIcon:u,CloseIcon:c}}},[F,null==w?void 0:w.citatioNumber,P]),$=m(function(){return i(i({},J),f?{bodyHeight:U}:{})},[J,f]);return e(T,{gptCitation:$,defaultCitationUrl:(null==w?void 0:w.citationUrl)||"",citationType:S.GPT_WEB,webCitationData:A,webCitationStatus:z,showWebCitation:B,onToggleCitationView:function(){return L(function(i){return!i})},iconsConfig:{MaximizeIcon:u,ExternalLinkIcon:s},isFixedHeight:!0})},H=function(n){var t,o,r,a,d,u,c,s=n.href,v=n.metaData,p=n.citationTitle,h=n.citationType,b=n.citationReason,x=n.isFullscreen,w=D().guidelinesData,T=function(i){try{var n=function(i){var n=i.match(/^(?:pdf_citation|deviation_summary)\$(\d+)/);if(n)try{var t=i.indexOf("?"),o=t>=0?i.slice(t):"";return{citationNumber:n[1],parsedUrl:new URL(o||"./",window.location.origin)}}catch(i){return{citationNumber:n[1],parsedUrl:null}}try{var e=new URL(i,window.location.origin);return{citationNumber:e.searchParams.get("citationNumber")||e.searchParams.get("citation_number"),parsedUrl:e}}catch(i){return{citationNumber:null,parsedUrl:null}}}(i),t=n.citationNumber,o=n.parsedUrl;return{citationNumber:t,phraseToHighlight:(null==o?void 0:o.searchParams.get("phrase_to_highlight"))||null,citationTypeFromHref:(null==o?void 0:o.searchParams.get("citation_type"))||null}}catch(i){return{citationNumber:null,phraseToHighlight:null,citationTypeFromHref:null}}}(s),S=T.citationNumber,k=T.phraseToHighlight,N=T.citationTypeFromHref,j=h||N||void 0,I="il_rulebook_citation"===j?"rulebook_citation":j,R=S&&(null===(t=null==v?void 0:v.citations)||void 0===t?void 0:t[S])||{},G=(null===(o=null==v?void 0:v.docData)||void 0===o?void 0:o.documents)||{},U=(null===(r=null==v?void 0:v.docData)||void 0===r?void 0:r.input_index_map)||{},E=Object.keys((null==v?void 0:v.citations)||{}).length>0||Object.keys((null==v?void 0:v.docData)||{}).length>0,M=null==U?void 0:U[0],H=null==U?void 0:U[1],W=M?G[M]:null,z=H?G[H]:null,O=M?R[M]:null,V=H?R[H]:null,B=m(function(){var i,n,t,o;return O&&W?e(f,{defaultScale:"PageWidth",showFullScreenAction:!1,showHighlightsAction:!1,pdfName:null==W?void 0:W.title,pdfUrl:null==W?void 0:W.signed_url,highlightText:[null!==(i=null==O?void 0:O.highlighted_text)&&void 0!==i?i:""],highlightPages:{1:null===(n=null==O?void 0:O.custom_metadata)||void 0===n?void 0:n.pdf_start_page_number},jumpToPageValue:1,highlightCordinatePages:[],useCoordinates:!1,useRange:!0,rangeOfPages:[null===(t=null==O?void 0:O.custom_metadata)||void 0===t?void 0:t.pdf_start_page_number,null===(o=null==O?void 0:O.custom_metadata)||void 0===o?void 0:o.pdf_end_page_number]}):null},[null==W?void 0:W.title,null==W?void 0:W.signed_url,null==O?void 0:O.highlighted_text,null===(a=null==O?void 0:O.custom_metadata)||void 0===a?void 0:a.pdf_start_page_number,null===(d=null==O?void 0:O.custom_metadata)||void 0===d?void 0:d.pdf_end_page_number]),L=m(function(){var i,n,t,o;return V&&z?e(f,{defaultScale:"PageWidth",showFullScreenAction:!1,showHighlightsAction:!1,pdfName:null==z?void 0:z.title,pdfUrl:null==z?void 0:z.signed_url,jumpToPageValue:1,highlightText:[null!==(i=null==V?void 0:V.highlighted_text)&&void 0!==i?i:""],highlightPages:{1:null===(n=null==V?void 0:V.custom_metadata)||void 0===n?void 0:n.pdf_start_page_number},highlightCordinatePages:[],useCoordinates:!1,useRange:!0,rangeOfPages:[null===(t=null==V?void 0:V.custom_metadata)||void 0===t?void 0:t.pdf_start_page_number,null===(o=null==V?void 0:V.custom_metadata)||void 0===o?void 0:o.pdf_end_page_number]}):null},[null==z?void 0:z.title,null==z?void 0:z.signed_url,null==V?void 0:V.highlighted_text,null===(u=null==V?void 0:V.custom_metadata)||void 0===u?void 0:u.pdf_start_page_number,null===(c=null==V?void 0:V.custom_metadata)||void 0===c?void 0:c.pdf_end_page_number]),J="dual_citation"===I,$=J&&!!(null==v?void 0:v.webGpt),q=m(function(){if(!B)return null;var n=$?e(A,{metaData:v,isFullscreen:x}):"rulebook_citation"===I?e(l,{children:e(C,i({sx:i(i({padding:"0px 20px",backgroundColor:"#FFFFFF",borderRadius:"8px"},F),{overflow:"auto"})},{children:e(_,i({rehypePlugins:[y]},{children:P({guidelinesData:w,targetHighlights:[k],labelColor:"#FEF08A"})}))}))}):L;return n?e(g,{leftComponent:B,rightComponent:n,isFullscreen:x}):B},[B,L,I,$,v,x,w,k]);return(null==v?void 0:v.webGpt)&&!E?e(A,{metaData:v,isFullscreen:x}):S?"rulebook_citation"===I?e("div",O?i({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:q}):i({style:{padding:"12px",fontSize:"13px",color:"#344054",lineHeight:1.5}},{children:b||"Rulebook citation selected."})):J?O||V?e("div",i({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:q})):(null==v?void 0:v.webGpt)?e(A,{metaData:v,isFullscreen:x}):e("div",{children:"Missing PDF Citation. Please try again later"}):["contract","clause"].includes(p)?e("div",O||V?i({style:{height:"100%",display:"flex",flexDirection:"column"}},{children:q}):{children:"Missing PDF Citation. Please try again later"}):e("div",{children:"No Citation Found. Please try again later"}):null},W=function(n){var t,l,u,c,s,m,h,g=n.href,f=n.children,_=n.citationType,y=n.citationReason,C=n.metaData,F=n.chevronUpComponent,D=void 0===F?null:F,P=n.chevronDownComponent,T=void 0===P?null:P,S=n.customStyle,k=void 0===S?{}:S,N=n.defaultState,j=void 0!==N&&N,I=n.onFullscreenChange,R=v(j),U=R[0],E=R[1],M=v(!1),A=M[0],W=M[1],z="string"==typeof f&&(null===(t=null==f?void 0:f.split("\n"))||void 0===t?void 0:t.length)>1?f.split("\n").join(" "):f;p(function(){if(null==I||I(A),A)return function(){null==I||I(!1)}},[A,I]);var O="string"==typeof f?f:f[0],V=null!=D?D:function(i){var n,t;return e(a,{size:null!==(n=null==i?void 0:i.fontSize)&&void 0!==n?n:16,color:null!==(t=null==i?void 0:i.color)&&void 0!==t?t:"rgb(214, 51, 132)"})}(null!==(l=null==k?void 0:k.arrow)&&void 0!==l?l:{}),B=null!=T?T:function(i){var n,t;return e(d,{size:null!==(n=null==i?void 0:i.fontSize)&&void 0!==n?n:16,color:null!==(t=null==i?void 0:i.color)&&void 0!==t?t:"rgb(214, 51, 132)"})}(null!==(u=null==k?void 0:k.arrow)&&void 0!==u?u:{}),L=o("div",i({style:{boxSizing:"border-box",border:A?"none":"1px solid #E4E7EC",borderRadius:A?0:"8px",overflow:"hidden",marginTop:A?0:"8px",display:"flex",flexDirection:"column",width:"100%",height:A?"100%":void 0,backgroundColor:"#FAFAFA"}},{children:[e("div",i({style:{display:"flex",justifyContent:"flex-end",padding:"6px 10px",borderBottom:"1px solid #E4E7EC",backgroundColor:"#FFFFFF",flexShrink:0}},{children:e("button",i({onClick:function(){W(function(i){return!i})},style:{background:"none",border:"none",cursor:"pointer",padding:"4px",borderRadius:"6px",color:"#475467",marginRight:"9px"}},{children:e(A?b:x,{})}))})),e("div",i({style:{flex:1,minHeight:0,height:"100%",overflow:"hidden"}},{children:e(H,{href:g,children:f,metaData:C,citationTitle:O,citationType:_,citationReason:y,isFullscreen:A})}))]}));return o("span",i({style:i({display:"inline"},k.relativeWrapper||{})},{children:[e("div",i({style:i({display:"inline",marginTop:0},k.citationButtonWrapper||{})},{children:o("button",i({type:"button",onClick:function(){return E(function(i){return!i})},style:i({display:(null==C?void 0:C.webGpt)?"inline":"inline-flex",alignItems:(null==C?void 0:C.webGpt)?void 0:"center",gap:(null==C?void 0:C.webGpt)?void 0:"3px",fontFamily:'"Inter", sans-serif',backgroundColor:"transparent",padding:0,margin:0,fontSize:"13px",borderRadius:9999,cursor:"pointer",fontWeight:(null==C?void 0:C.webGpt)?600:700,color:(null==C?void 0:C.webGpt)?"#6D28D9":"rgb(214, 51, 132)",border:"none",textDecoration:"none",wordBreak:"break-word",whiteSpace:"normal"},k.citationButton||{})},{children:[(null==C?void 0:C.webGpt)&&e(r,{size:null!==(s=null===(c=k.arrow)||void 0===c?void 0:c.fontSize)&&void 0!==s?s:"1em",color:null!==(h=null===(m=k.arrow)||void 0===m?void 0:m.color)&&void 0!==h?h:"#6D28D9",style:{display:"inline-block",width:"1em",height:"1em",marginRight:"3px",verticalAlign:"-0.125em",flexShrink:0}}),e("span",{children:z}),e("span",i({style:{display:"inline-flex",alignItems:"center",marginLeft:(null==C?void 0:C.webGpt)?"3px":void 0,verticalAlign:(null==C?void 0:C.webGpt)?"-0.125em":void 0}},{children:U?V:B}))]}))})),U&&(A?e(w,i({open:A,onClose:function(){return W(!1)},maxWidth:!1,BackdropProps:{sx:{backgroundColor:"rgba(0, 0, 0, 0.6)",backdropFilter:"blur(4px)"}},PaperProps:{sx:{backgroundColor:"#FAFAFA",borderRadius:"16px",height:G,m:0,maxHeight:G,maxWidth:"95vw",overflow:"hidden",width:"95vw"}}},{children:L})):L)]}))};export{W as default};
|
|
2
2
|
//# sourceMappingURL=CitationAnchor.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t=function(t){if("string"!=typeof t||""===t.trim())return null;try{var r="undefined"!=typeof window?window.location.origin:"http://localhost";return new URL(t,r)}catch(t){return null}},r=function(t,r){var
|
|
1
|
+
var t=function(t){if("string"!=typeof t||""===t.trim())return null;try{var r="undefined"!=typeof window?window.location.origin:"http://localhost";return new URL(t,r)}catch(t){return null}},r=function(t,r){var e;if("string"!=typeof t||"string"!=typeof r||""===r.trim())return"";try{var n=t.match(new RegExp("\\b".concat(r,"\\s*=\\s*(['\"])(.*?)\\1"),"i"));return null!==(e=null==n?void 0:n[2])&&void 0!==e?e:""}catch(t){return""}},e=function(t){if("string"!=typeof t||""===t)return"";try{return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}catch(r){return t}},n=function(t,r,n){if("string"!=typeof t||""===t.trim())return t;if("string"!=typeof r||""===r.trim())return t;if(!n||"string"!=typeof n)return t;try{var a=e(n),i=new RegExp("\\b".concat(r,"\\s*=\\s*(['\"])(.*?)\\1"),"i");return i.test(t)?t.replace(i,function(){return"".concat(r,'="').concat(a,'"')}):t.replace(/<a\b/i,function(){return"<a ".concat(r,'="').concat(a,'"')})}catch(r){return t}},a=function(r,e){if("string"!=typeof r||!r||"string"!=typeof e||!e)return"";try{var n=r.indexOf("?");if(n>=0){var a=r.slice(n+1).replace(/&/gi,"&"),i=a.indexOf("".concat(e,"="));if(i>=0){var c=i+e.length+1,o=a.slice(c).match(/&[A-Za-z_][A-Za-z0-9_]*=/),u=void 0!==(null==o?void 0:o.index)?c+o.index:a.length;return decodeURIComponent(a.slice(c,u).replace(/\+/g," "))}}var l=t(r.replace(/&/gi,"&"));return(null==l?void 0:l.searchParams.get(e))||""}catch(t){return""}},i=function(i){if("string"!=typeof i||!i||!i.includes("citation_type"))return i;try{var c=i;return Array.from(i.matchAll(/<a\b([^>]*?)>([\s\S]*?)<\/a>/gi)).forEach(function(i){var o=i[0],u=i[1]||"",l=r(u,"href").replace(/&/gi,"&"),s=t(l),f=r(u,"type"),p=null==s?void 0:s.searchParams.get("citation_type");if("rulebook_citation"===f||"il_rulebook_citation"===p){f||(f=p||"rulebook_citation");var h=r(u,"reason"),g=(null==s?void 0:s.searchParams.get("citationNumber"))||(null==s?void 0:s.searchParams.get("citation_number"))||"",v=g.match(/^rb_(.+)$/),y=v?v[1]:g;if(y){var m={citation_type:p||"",phrase_to_highlight:a(l,"phrase_to_highlight")};if(m.citation_type||m.phrase_to_highlight){var d=!1,_=function(r){return function(r){if("string"!=typeof r||!r)return null;var e=r.match(/^(?:pdf_citation|deviation_summary)\$(\d+)/);if(e)return e[1];try{var n=t(r.replace(/&/gi,"&"));return(null==n?void 0:n.searchParams.get("citationNumber"))||(null==n?void 0:n.searchParams.get("citation_number"))||null}catch(t){return null}}(r)!==y?r:(d=!0,function(r,e){if("string"!=typeof r||""===r.trim())return r;if(!e||"object"!=typeof e)return r;try{var n=t(r);if(!n)return r;Object.entries(e).forEach(function(t){var r=t[0],e=t[1];e&&n.searchParams.set(r,e)});var a="".concat(n.pathname).concat(n.search).concat(n.hash);return r.startsWith("./")?".".concat(a):!r.startsWith("/")&&a.startsWith("/")?a.slice(1):a}catch(t){return r}}(r,m))};c=c.replace(/\[([^\]]+)\]\(([^)\n]+)\)/g,function(t,r,n){var a=_(n);return a===n?t:'<a type="'.concat(e(f),'" reason="').concat(e(h),'" href="').concat(e(a),'">').concat(r,"</a>")}),d||(c=c.replace(/<a\b([^>]*?)>/gi,function(e,a){var i,c=r(a,"type")||(null===(i=t(r(a,"href")))||void 0===i?void 0:i.searchParams.get("citation_type"));if("rulebook_citation"===c||"il_rulebook_citation"===c)return e;var o=r(a,"href"),u=_(o);if(u===o)return e;var l=e.replace(/\bhref\s*=\s*(['"])(.*?)\1/i,function(t,r){return"href=".concat(r).concat(u).concat(r)});return n(n(l,"type",f),"reason",h)})),c=c.split(o).join("")}else c=c.split(o).join("")}else c=c.split(o).join("")}}),c}catch(t){return i}};export{i as mergeRulebookCitationsIntoMatchingLinks};
|
|
2
2
|
//# sourceMappingURL=helper.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var a=function(a){var t,
|
|
1
|
+
var a=function(a){var n,t,e=a.guidelinesData,i=a.targetHighlights,o=void 0===i?[]:i,l=a.labelColor,r=void 0===l?"#FEF08A":l,c="";if((null==e?void 0:e.learnings_data)&&Object.keys(e.learnings_data).length>0){var u=Object.keys(e.learnings_data)[0],d=e.learnings_data[u];(null==d?void 0:d.instruction_prompt)&&(c=d.instruction_prompt)}else{((null===(t=null===(n=null==e?void 0:e.data)||void 0===n?void 0:n.artifactData)||void 0===t?void 0:t.userStorySnapshot)||[]).forEach(function(a){var n;a.title&&(c+="### ".concat(a.title,"\n\n")),a.value&&(c+="".concat(a.value,"\n\n")),null===(n=a.sub_features)||void 0===n||n.forEach(function(a){a.title&&(c+="#### ".concat(a.title,"\n\n")),a.value&&(c+="".concat(a.value,"\n\n"))})})}return o.forEach(function(a,n){var t=a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),e=new RegExp("(".concat(t,")"),"g");c=c.replace(e,'<mark id="guideline-target-'.concat(n,'" style="background-color: ').concat(r,'; border-radius: 3px; padding: 2px;">$1</mark>'))}),c};export{a as processGuidelinesMarkdown};
|
|
2
2
|
//# sourceMappingURL=processGuidelinesMarkdown.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__assign as n,__spreadArray as e}from"tslib";import{useMemo as t}from"react";import{isMissingStr as i,safeStringify as o,getRationale as r,resolveComparisonInputItems as a,getSideData as d,hasValue as l,DEVIATION_BADGE_SEPARATOR as s}from"../CognitiveComparehelpers.js";import{buildComparisonRows as u}from"../utils/buildComparisonRows.js";var v={id:"",title:"",similarity:0,sections:[]},c=function(c,f,p,I,_,h){var m,g;void 0===_&&(_=!0);var x="string"==typeof p?p:JSON.stringify(p||{}),b=Boolean(h&&(null===(g=null===(m=h.data)||void 0===m?void 0:m.artifactData)||void 0===g?void 0:g.userStorySnapshot)),y=t(function(){var t;if(!c||0===Object.keys(c).length)return{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:"Tree data is required"};var l=JSON.parse(x);try{var s=c.nodes||c,v=[],p=[],I=[],m=c.base_root_id,g=c.input_index_map||{0:"left",1:"right"},y=c[m]||s[m];if(!y||!1===y.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[],comparisonRows:[],parseError:null};var R=c.content_mapping||{},C=function(n){return c[n]||s[n]},E=function(e,t,o){if(!e||"object"!=typeof e)return e||null;if(e.deviations)return e;if(_)return e;var r=Object.keys(e).filter(function(n){return/^\d+$/.test(n)});if(!r.length)return e;var a=r.sort(function(n,e){return Number(n)-Number(e)}),d={},l={},s=null;return a.forEach(function(n){var r,a,u,v,c,f=e[n];if(f&&"object"==typeof f){s||(s=f);var p=!(null==f?void 0:f.status)||"pending"===f.status,I=function(n){var e,t=(null===(e=null==f?void 0:f.cognitive_decisioning)||void 0===e?void 0:e.citations)||(null==f?void 0:f.citations)||{};return Object.values(t).map(function(e){var t;return null===(t=null==e?void 0:e[n])||void 0===t?void 0:t.highlighted_text}).filter(function(n){return"string"==typeof n&&n.trim().length>0})},_=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];for(var t=0,o=n;t<o.length;t++){var r=o[t];if(Array.isArray(r)&&r.some(function(n){return!i(n)}))return r}return[]},h=p?_((null===(a=null==f?void 0:f.deviation_highlights)||void 0===a?void 0:a[t])||(null===(u=null==f?void 0:f.deviation_highlights)||void 0===u?void 0:u[g[0]]),I(t),I(g[0])):[],m=p?_((null===(v=null==f?void 0:f.deviation_highlights)||void 0===v?void 0:v[o])||(null===(c=null==f?void 0:f.deviation_highlights)||void 0===c?void 0:c[g[1]]),I(o),I(g[1])):[];d[n]=((r={})[g[0]]=h[0]||"",r[g[1]]=m[0]||"",r.deviation_summary=(null==f?void 0:f.deviation_summary)||"",r.deviation_title=null==f?void 0:f.deviation_title,r.deviation_impact=null==f?void 0:f.deviation_impact,r.deviation_explanation=null==f?void 0:f.deviation_explanation,r.evaluation_outputs=null==f?void 0:f.evaluation_outputs,r.cognitive_decisioning=null==f?void 0:f.cognitive_decisioning,r.deviation_highlights=null==f?void 0:f.deviation_highlights,r),l[n]=f}}),n(n({},e),{deviation_title:(null==s?void 0:s.deviation_title)||(null==e?void 0:e.deviation_title),deviation_impact:(null==s?void 0:s.deviation_impact)||(null==e?void 0:e.deviation_impact),deviation_summary:(null==s?void 0:s.deviation_summary)||(null==e?void 0:e.deviation_summary),deviation_explanation:(null==s?void 0:s.deviation_explanation)||(null==e?void 0:e.deviation_explanation),evaluation_outputs:(null==s?void 0:s.evaluation_outputs)||(null==e?void 0:e.evaluation_outputs),cognitive_decisioning:(null==s?void 0:s.cognitive_decisioning)||(null==e?void 0:e.cognitive_decisioning),deviations:d,deviation_entries:l})},O=function(n){var e=new Map,t=function(n){n.forEach(function(n){var i;n.id&&e.set(n.id,n),(null===(i=n.subsections)||void 0===i?void 0:i.length)&&t(n.subsections)})};t(n);var i=function(n,t){for(var o,r=[],a=function(n){var a=n.ref_parent_section_node_id;if(a&&e.has(a)&&a!==(null==t?void 0:t.id)){var d=e.get(a);d.subsections||(d.subsections=[]),d.subsections.some(function(e){return e.id===n.id})||d.subsections.push(n)}else(null===(o=n.subsections)||void 0===o?void 0:o.length)&&(n.subsections=i(n.subsections,n)),r.push(n)},d=0,l=n;d<l.length;d++){a(l[d])}return r},o=i(n),r=function(n){n.forEach(function(n){n.subsections&&n.subsections.length>0&&(n.subsections.sort(function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:(n.selfIndex||0)-(e.selfIndex||0)}),r(n.subsections))})};return r(o),o},N=function(n){var e=n.comparison_inputs?Object.keys(n.comparison_inputs):[],t=g[0],i=g[1];return e.length>0&&(t=e.includes(g[0])?g[0]:e[0],i=e.includes(g[1])?g[1]:e.length>1?e[1]:e[0]),{nodeLeftId:t,nodeRightId:i}},S=function(e,t,i,r){var a=t.attributes||{},d=t.data||{},l=!1!==a.display_title,s=!1!==a.display_content,u=l?o(d.title||""):"",v=s?o(d.content||""):"",c=s?o(d.change_history||""):"",f=void 0!==a.display_index&&null!==a.display_index?Number(a.display_index):-1,p=function(n){return(null==n?void 0:n.entity_id)||(null==n?void 0:n.ref_parent_section_node_id)||(null==n?void 0:n.parent_entity_id)||null}(a),I=!(!u.trim()&&!v.trim());return n(n({id:"".concat(e,"::").concat(t.contentId),nodeId:e,contentId:t.contentId,parentContentId:p,title:u,content:v,change_history:c,displayTitle:l,displayContent:s,subsections:[]},I?r:{score:void 0,relation:"not_defined"}),{evaluationResult:i,evaluationResults:i?[i]:[],selfIndex:f,refIndexes:[],refContentIds:[],ref_parent_section_node_id:p})},j=function(n,t){n.refIndexes=Array.from(new Set(e(e([],n.refIndexes||[],!0),t.refIndexes||[],!0))),n.refContentIds=Array.from(new Set(e(e([],n.refContentIds||[],!0),t.refContentIds||[],!0)));var i=new Set((n.subsections||[]).map(function(n){return n.id||n.contentId||n.nodeId}));(t.subsections||[]).forEach(function(t){var o=t.id||t.contentId||t.nodeId;i.has(o)||(n.subsections=e(e([],n.subsections||[],!0),[t],!1),i.add(o))});var o=e(e([],n.evaluationResults||(n.evaluationResult?[n.evaluationResult]:[]),!0),t.evaluationResults||(t.evaluationResult?[t.evaluationResult]:[]),!0).filter(Boolean),r=new Set;return n.evaluationResults=o.filter(function(n){var e=(null==n?void 0:n.nodeId)||JSON.stringify(Object.keys((null==n?void 0:n.deviations)||n||{}));return!r.has(e)&&(r.add(e),!0)}),!n.evaluationResult&&t.evaluationResult&&(n.evaluationResult=t.evaluationResult),!n.cognitiveData&&t.cognitiveData&&(n.cognitiveData=t.cognitiveData),n},w=function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:n.selfIndex-e.selfIndex},D=function(e,t){var i,o=C(e);if(!o||!1===o.display_node)return[];if(b&&"1"===t)return[];var d=N(o),s=d.nodeLeftId,u=d.nodeRightId,v=r(o),c=(null===(i=null==l?void 0:l[e])||void 0===i?void 0:i.evaluation_result)||o.evaluation_result||null,f=E(c,s,u),p=f&&"object"==typeof f?n(n({},f),{nodeId:e}):f,I=a(o,t,g,R).map(function(n){return S(e,n,p,v)});if(o.next){var _=Object.values(o.next).flatMap(function(n){return D(n,t)});I.forEach(function(n){var e=_.filter(function(e){return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId});n.subsections=e.length?e:_})}return I};if(f){var P=function(e,t){var i;void 0===t&&(t=0);var o=[],d=[];if(!e)return{refSections:o,baseSections:d};var s={},u={},v=-1,c=-1,f=function(o){var d=e[o],f=C(d);if(!f||!1===f.display_node)return"continue";var p=N(f),I=p.nodeLeftId,_=p.nodeRightId,h=r(f),m=(null===(i=null==l?void 0:l[d])||void 0===i?void 0:i.evaluation_result)||f.evaluation_result||null,x=E(m,I,_),y=x&&"object"==typeof x?n(n({},x),{nodeId:d}):x,O=P(f.next,t+1),w=O.refSections,D=O.baseSections,k=a(f,"0",g,R).map(function(n){var e=S(d,n,y,h);return-1===e.selfIndex&&(e.selfIndex=c--),e}),K=[];if(!b){var V=a(f,"1",g,R);K=V.map(function(n){var e=S(d,n,y,h);return-1===e.selfIndex&&(e.selfIndex=v--),e})}k.forEach(function(n){K.forEach(function(e){var t,i,o,r,a,d,l,s;Number(e.selfIndex)>=0&&Number(n.selfIndex)>=0&&((null===(t=e.refIndexes)||void 0===t?void 0:t.includes(Number(n.selfIndex)))||null===(i=e.refIndexes)||void 0===i||i.push(Number(n.selfIndex)),(null===(o=n.refIndexes)||void 0===o?void 0:o.includes(Number(e.selfIndex)))||null===(r=n.refIndexes)||void 0===r||r.push(Number(e.selfIndex))),n.contentId&&!(null===(a=e.refContentIds)||void 0===a?void 0:a.includes(n.contentId))&&(null===(d=e.refContentIds)||void 0===d||d.push(n.contentId)),e.contentId&&!(null===(l=n.refContentIds)||void 0===l?void 0:l.includes(e.contentId))&&(null===(s=n.refContentIds)||void 0===s||s.push(e.contentId))})}),K.forEach(function(n){var e=w.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var i=0===t?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||d);s[i]=s[i]?j(s[i],n):n}),k.forEach(function(n){var e=D.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var i=0===t?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||d);u[i]=u[i]?j(u[i],n):n})};for(var p in e)f(p);return o=Object.values(s),d=Object.values(u),o.sort(w),d.sort(w),{refSections:o,baseSections:d}},k=P(y.next),K=k.refSections,V=k.baseSections;b||(p=O(K)),v=V}else y.next&&Object.values(y.next).forEach(function(n){var e=C(n);if(e&&!1!==e.display_node){var t=D(n,"0");if(b)v.push.apply(v,t);else{var i=O(D(n,"1"));I.push.apply(I,u(n,t,i))}}}),b||(v=I.map(function(n){return n.left}),p=I.map(function(n){return n.right}));var T=d(y,"0",g,R),A=d(y,"1",g,R);return{activeProposed:{title:T.title||"Uploaded Contract",description:y.decision_scope_description||"",sections:v},activeVariants:[{id:"tree-variant-1",title:b?(null===(t=null==h?void 0:h.data)||void 0===t?void 0:t.artifactTitle)||"Rulebook Guidelines":A.title||"Reference Template",similarity:0,sections:p,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:y.decision_scope_description||""},fields:{}}}}],comparisonRows:I,parseError:null}}catch(n){return console.error("Data Transformation Error: ",n),{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:n instanceof Error?n.message:"Unknown Parsing Error"}}},[c,f,x,_,h]),R=y.activeProposed,C=y.activeVariants,E=y.comparisonRows,O=y.parseError,N=(null==C?void 0:C[0])||v,S=t(function(){return(null==R?void 0:R.sections)||[]},[null==R?void 0:R.sections]),j=t(function(){return N.sections||[]},[N.sections]),w=S.length>0||j.length>0,D=t(function(){return I.fields.filter(function(n){var e=n.key;return(!w||"description"!==e)&&(l(null==R?void 0:R[e])||l(N[e]))})},[R,N,w,I.fields]),P=t(function(){var n,e,t={},o={},r={},a=0,d=null===(n=null==c?void 0:c.input_index_map)||void 0===n?void 0:n[0],l=null===(e=null==c?void 0:c.input_index_map)||void 0===e?void 0:e[1],u=function(n,e){if(!f){var t="left"===e?S.indexOf(n):j.indexOf(n);return{rootKey:"".concat(e,":").concat(t),parentNum:t+1}}if("left"===e){var i=n.selfIndex,o=void 0!==i&&i>=0?i+1:S.indexOf(n)+1;return{rootKey:"left-root:".concat(n.id),parentNum:o}}var r=n.selfIndex,a=S.find(function(n){var e;return null===(e=n.refIndexes)||void 0===e?void 0:e.includes(r)});if(a){var d=a.selfIndex,l=void 0!==d&&d>=0?d+1:S.indexOf(a)+1;return{rootKey:"left-root:".concat(a.id),parentNum:l}}var s=void 0!==r&&r>=0?r+1:j.indexOf(n)+1;return{rootKey:"right-orphan-root:".concat(n.id),parentNum:s}},v=function(n,e){if(n&&e)return n.find(function(n){return n.id===e.id||n.nodeId&&n.nodeId===e.nodeId||n.contentId&&n.contentId===e.contentId})||void 0},p=function(n,e,u,c,f,I,_){if(e&&function(n,e,t){var a;((null===(a=null==n?void 0:n.evaluationResults)||void 0===a?void 0:a.length)?n.evaluationResults:(null==n?void 0:n.evaluationResult)?[n.evaluationResult]:[]).forEach(function(a){var u=(null==a?void 0:a.deviations)||{};Object.keys(u).sort().forEach(function(v){var c=u[v];if(c){var f=!i(c[d]),p=!i(c[l]);if(f||p){var I=(null==a?void 0:a.nodeId)||n.nodeId||n.id,_="".concat(I).concat(s).concat(v);void 0===o[_]&&(void 0===r[e]&&(r[e]=1),o[_]={index:r[e]++,rootKey:e,parentNum:t})}}})})}(e,c,f),e&&!I){var h=(null==_?void 0:_.id)||"fallback_parent_".concat(a++);t[h]||(t[h]=[]),t[h].push(e)}((null==e?void 0:e.subsections)||(null==n?void 0:n.subsections)||(null==u?void 0:u.subsections)||[]).forEach(function(t){var i=v(null==n?void 0:n.subsections,t),o=v(null==u?void 0:u.subsections,t);p(t,i,o,c,f,!1,e||_)})};S.forEach(function(n){var e,t=u(n,"left"),i=t.rootKey,o=t.parentNum,r=null;if(f){var a=null===(e=n.refIndexes)||void 0===e?void 0:e[0];r=j.find(function(n){return n.selfIndex===a})}else r=j[S.indexOf(n)];p(n,n,r,i,o,!0,n)}),b||j.forEach(function(n){var e=u(n,"right"),t=e.rootKey,i=e.parentNum;t.startsWith("right-orphan-root:")&&p(n,null,n,t,i,!0,n)});var I=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].index]})),_=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].parentNum]}));return{parentDeviationRecord:t,registry:I,deviationParentRegistry:_}},[S,j,f,c,b]),k=P.parentDeviationRecord,K=P.registry,V=P.deviationParentRegistry;return{isGuidelineMode:b,activeProposed:R,activeVariants:C,comparisonRows:E,existingRule:N,proposedSections:S,existingSections:j,visibleFields:D,parentDeviationRecord:k,deviationNumberRegistry:K,deviationParentRegistry:V,parseError:O}};export{c as useCognitiveTreeData};
|
|
1
|
+
import{__assign as n,__spreadArray as e}from"tslib";import{useMemo as t}from"react";import{isMissingStr as i,safeStringify as o,getRationale as r,resolveComparisonInputItems as a,getSideData as d,hasValue as l,DEVIATION_BADGE_SEPARATOR as s}from"../CognitiveComparehelpers.js";import{buildComparisonRows as u}from"../utils/buildComparisonRows.js";var v={id:"",title:"",similarity:0,sections:[]},c=function(c,f,p,I,_,h){var g,m;void 0===_&&(_=!0);var x="string"==typeof p?p:JSON.stringify(p||{}),b=Boolean(h&&(h.learnings_data||(null===(m=null===(g=h.data)||void 0===g?void 0:g.artifactData)||void 0===m?void 0:m.userStorySnapshot))),y=t(function(){if(!c||0===Object.keys(c).length)return{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:"Tree data is required"};var t=JSON.parse(x);try{var l=c.nodes||c,s=[],v=[],p=[],I=c.base_root_id,g=c.input_index_map||{0:"left",1:"right"},m=c[I]||l[I];if(!m||!1===m.display_node)return{activeProposed:{title:"No Data",sections:[]},activeVariants:[],comparisonRows:[],parseError:null};var y=c.content_mapping||{},R=function(n){return c[n]||l[n]},C=function(e,t,o){if(!e||"object"!=typeof e)return e||null;if(e.deviations)return e;if(_)return e;var r=Object.keys(e).filter(function(n){return/^\d+$/.test(n)});if(!r.length)return e;var a=r.sort(function(n,e){return Number(n)-Number(e)}),d={},l={},s=null;return a.forEach(function(n){var r,a,u,v,c,f=e[n];if(f&&"object"==typeof f){s||(s=f);var p=!(null==f?void 0:f.status)||"pending"===f.status,I=function(n){var e,t=(null===(e=null==f?void 0:f.cognitive_decisioning)||void 0===e?void 0:e.citations)||(null==f?void 0:f.citations)||{};return Object.values(t).map(function(e){var t;return null===(t=null==e?void 0:e[n])||void 0===t?void 0:t.highlighted_text}).filter(function(n){return"string"==typeof n&&n.trim().length>0})},_=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];for(var t=0,o=n;t<o.length;t++){var r=o[t];if(Array.isArray(r)&&r.some(function(n){return!i(n)}))return r}return[]},h=p?_((null===(a=null==f?void 0:f.deviation_highlights)||void 0===a?void 0:a[t])||(null===(u=null==f?void 0:f.deviation_highlights)||void 0===u?void 0:u[g[0]]),I(t),I(g[0])):[],m=p?_((null===(v=null==f?void 0:f.deviation_highlights)||void 0===v?void 0:v[o])||(null===(c=null==f?void 0:f.deviation_highlights)||void 0===c?void 0:c[g[1]]),I(o),I(g[1])):[];d[n]=((r={})[g[0]]=h[0]||"",r[g[1]]=m[0]||"",r.deviation_summary=(null==f?void 0:f.deviation_summary)||"",r.deviation_title=null==f?void 0:f.deviation_title,r.deviation_impact=null==f?void 0:f.deviation_impact,r.deviation_explanation=null==f?void 0:f.deviation_explanation,r.evaluation_outputs=null==f?void 0:f.evaluation_outputs,r.cognitive_decisioning=null==f?void 0:f.cognitive_decisioning,r.deviation_highlights=null==f?void 0:f.deviation_highlights,r),l[n]=f}}),n(n({},e),{deviation_title:(null==s?void 0:s.deviation_title)||(null==e?void 0:e.deviation_title),deviation_impact:(null==s?void 0:s.deviation_impact)||(null==e?void 0:e.deviation_impact),deviation_summary:(null==s?void 0:s.deviation_summary)||(null==e?void 0:e.deviation_summary),deviation_explanation:(null==s?void 0:s.deviation_explanation)||(null==e?void 0:e.deviation_explanation),evaluation_outputs:(null==s?void 0:s.evaluation_outputs)||(null==e?void 0:e.evaluation_outputs),cognitive_decisioning:(null==s?void 0:s.cognitive_decisioning)||(null==e?void 0:e.cognitive_decisioning),deviations:d,deviation_entries:l})},E=function(n){var e=new Map,t=function(n){n.forEach(function(n){var i;n.id&&e.set(n.id,n),(null===(i=n.subsections)||void 0===i?void 0:i.length)&&t(n.subsections)})};t(n);var i=function(n,t){for(var o,r=[],a=function(n){var a=n.ref_parent_section_node_id;if(a&&e.has(a)&&a!==(null==t?void 0:t.id)){var d=e.get(a);d.subsections||(d.subsections=[]),d.subsections.some(function(e){return e.id===n.id})||d.subsections.push(n)}else(null===(o=n.subsections)||void 0===o?void 0:o.length)&&(n.subsections=i(n.subsections,n)),r.push(n)},d=0,l=n;d<l.length;d++){a(l[d])}return r},o=i(n),r=function(n){n.forEach(function(n){n.subsections&&n.subsections.length>0&&(n.subsections.sort(function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:(n.selfIndex||0)-(e.selfIndex||0)}),r(n.subsections))})};return r(o),o},O=function(n){var e=n.comparison_inputs?Object.keys(n.comparison_inputs):[],t=g[0],i=g[1];return e.length>0&&(t=e.includes(g[0])?g[0]:e[0],i=e.includes(g[1])?g[1]:e.length>1?e[1]:e[0]),{nodeLeftId:t,nodeRightId:i}},j=function(e,t,i,r){var a=t.attributes||{},d=t.data||{},l=!1!==a.display_title,s=!1!==a.display_content,u=l?o(d.title||""):"",v=s?o(d.content||""):"",c=s?o(d.change_history||""):"",f=void 0!==a.display_index&&null!==a.display_index?Number(a.display_index):-1,p=function(n){return(null==n?void 0:n.entity_id)||(null==n?void 0:n.ref_parent_section_node_id)||(null==n?void 0:n.parent_entity_id)||null}(a),I=!(!u.trim()&&!v.trim());return n(n({id:"".concat(e,"::").concat(t.contentId),nodeId:e,contentId:t.contentId,parentContentId:p,title:u,content:v,change_history:c,displayTitle:l,displayContent:s,subsections:[]},I?r:{score:void 0,relation:"not_defined"}),{evaluationResult:i,evaluationResults:i?[i]:[],selfIndex:f,refIndexes:[],refContentIds:[],ref_parent_section_node_id:p})},N=function(n,t){n.refIndexes=Array.from(new Set(e(e([],n.refIndexes||[],!0),t.refIndexes||[],!0))),n.refContentIds=Array.from(new Set(e(e([],n.refContentIds||[],!0),t.refContentIds||[],!0)));var i=new Set((n.subsections||[]).map(function(n){return n.id||n.contentId||n.nodeId}));(t.subsections||[]).forEach(function(t){var o=t.id||t.contentId||t.nodeId;i.has(o)||(n.subsections=e(e([],n.subsections||[],!0),[t],!1),i.add(o))});var o=e(e([],n.evaluationResults||(n.evaluationResult?[n.evaluationResult]:[]),!0),t.evaluationResults||(t.evaluationResult?[t.evaluationResult]:[]),!0).filter(Boolean),r=new Set;return n.evaluationResults=o.filter(function(n){var e=(null==n?void 0:n.nodeId)||JSON.stringify(Object.keys((null==n?void 0:n.deviations)||n||{}));return!r.has(e)&&(r.add(e),!0)}),!n.evaluationResult&&t.evaluationResult&&(n.evaluationResult=t.evaluationResult),!n.cognitiveData&&t.cognitiveData&&(n.cognitiveData=t.cognitiveData),n},S=function(n,e){return n.selfIndex<0&&e.selfIndex>=0?1:n.selfIndex>=0&&e.selfIndex<0?-1:n.selfIndex-e.selfIndex},w=function(e,i){var o,d=R(e);if(!d||!1===d.display_node)return[];if(b&&"1"===i)return[];var l=O(d),s=l.nodeLeftId,u=l.nodeRightId,v=r(d),c=(null===(o=null==t?void 0:t[e])||void 0===o?void 0:o.evaluation_result)||d.evaluation_result||null,f=C(c,s,u),p=f&&"object"==typeof f?n(n({},f),{nodeId:e}):f,I=a(d,i,g,y).map(function(n){return j(e,n,p,v)});if(d.next){var _=Object.values(d.next).flatMap(function(n){return w(n,i)});I.forEach(function(n){var e=_.filter(function(e){return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId});n.subsections=e.length?e:_})}return I};if(f){var k=function(e,i){var o;void 0===i&&(i=0);var d=[],l=[];if(!e)return{refSections:d,baseSections:l};var s={},u={},v=-1,c=-1,f=function(d){var l=e[d],f=R(l);if(!f||!1===f.display_node)return"continue";var p=O(f),I=p.nodeLeftId,_=p.nodeRightId,h=r(f),m=(null===(o=null==t?void 0:t[l])||void 0===o?void 0:o.evaluation_result)||f.evaluation_result||null,x=C(m,I,_),E=x&&"object"==typeof x?n(n({},x),{nodeId:l}):x,S=k(f.next,i+1),w=S.refSections,D=S.baseSections,P=a(f,"0",g,y).map(function(n){var e=j(l,n,E,h);return-1===e.selfIndex&&(e.selfIndex=c--),e}),K=[];if(!b){var V=a(f,"1",g,y);K=V.map(function(n){var e=j(l,n,E,h);return-1===e.selfIndex&&(e.selfIndex=v--),e})}P.forEach(function(n){K.forEach(function(e){var t,i,o,r,a,d,l,s;Number(e.selfIndex)>=0&&Number(n.selfIndex)>=0&&((null===(t=e.refIndexes)||void 0===t?void 0:t.includes(Number(n.selfIndex)))||null===(i=e.refIndexes)||void 0===i||i.push(Number(n.selfIndex)),(null===(o=n.refIndexes)||void 0===o?void 0:o.includes(Number(e.selfIndex)))||null===(r=n.refIndexes)||void 0===r||r.push(Number(e.selfIndex))),n.contentId&&!(null===(a=e.refContentIds)||void 0===a?void 0:a.includes(n.contentId))&&(null===(d=e.refContentIds)||void 0===d||d.push(n.contentId)),e.contentId&&!(null===(l=n.refContentIds)||void 0===l?void 0:l.includes(e.contentId))&&(null===(s=n.refContentIds)||void 0===s||s.push(e.contentId))})}),K.forEach(function(n){var e=w.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var t=0===i?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||l);s[t]=s[t]?N(s[t],n):n}),P.forEach(function(n){var e=D.filter(function(e){var t;return!e.parentContentId||e.parentContentId===n.contentId||e.parentContentId===n.parentContentId||(null===(t=n.refContentIds)||void 0===t?void 0:t.includes(e.parentContentId))});e.length>0&&(n.subsections=e);var t=0===i?String(n.selfIndex):"".concat(n.selfIndex,"_").concat(n.contentId||l);u[t]=u[t]?N(u[t],n):n})};for(var p in e)f(p);return d=Object.values(s),l=Object.values(u),d.sort(S),l.sort(S),{refSections:d,baseSections:l}},D=k(m.next),P=D.refSections,K=D.baseSections;b||(v=E(P)),s=K}else m.next&&Object.values(m.next).forEach(function(n){var e=R(n);if(e&&!1!==e.display_node){var t=w(n,"0");if(b)s.push.apply(s,t);else{var i=E(w(n,"1"));p.push.apply(p,u(n,t,i))}}}),b||(s=p.map(function(n){return n.left}),v=p.map(function(n){return n.right}));var V=d(m,"0",g,y),T=d(m,"1",g,y),A={title:V.title||"Uploaded Contract",description:m.decision_scope_description||"",sections:s},G={id:"tree-variant-1",title:b?function(){var n,e;if((null==h?void 0:h.learnings_data)&&Object.keys(h.learnings_data).length>0){var t=Object.keys(h.learnings_data)[0];return(null===(n=h.learnings_data[t])||void 0===n?void 0:n.title)||"Rulebook Guidelines"}return(null===(e=null==h?void 0:h.data)||void 0===e?void 0:e.artifactTitle)||"Rulebook Guidelines"}():T.title||"Reference Template",similarity:0,sections:v,analysis:{rule_difference_comparison:{summary:{overall_score:0,overall_summary:m.decision_scope_description||""},fields:{}}}};return{activeProposed:A,activeVariants:[G],comparisonRows:p,parseError:null}}catch(n){return console.error("Data Transformation Error: ",n),{activeProposed:{},activeVariants:[],comparisonRows:[],parseError:n instanceof Error?n.message:"Unknown Parsing Error"}}},[c,f,x,_,h]),R=y.activeProposed,C=y.activeVariants,E=y.comparisonRows,O=y.parseError,j=(null==C?void 0:C[0])||v,N=t(function(){return(null==R?void 0:R.sections)||[]},[null==R?void 0:R.sections]),S=t(function(){return j.sections||[]},[j.sections]),w=N.length>0||S.length>0,k=t(function(){return I.fields.filter(function(n){var e=n.key;return(!w||"description"!==e)&&(l(null==R?void 0:R[e])||l(j[e]))})},[R,j,w,I.fields]),D=t(function(){var n,e,t={},o={},r={},a=0,d=null===(n=null==c?void 0:c.input_index_map)||void 0===n?void 0:n[0],l=null===(e=null==c?void 0:c.input_index_map)||void 0===e?void 0:e[1],u=function(n,e){if(!f){var t="left"===e?N.indexOf(n):S.indexOf(n);return{rootKey:"".concat(e,":").concat(t),parentNum:t+1}}if("left"===e){var i=n.selfIndex,o=void 0!==i&&i>=0?i+1:N.indexOf(n)+1;return{rootKey:"left-root:".concat(n.id),parentNum:o}}var r=n.selfIndex,a=N.find(function(n){var e;return null===(e=n.refIndexes)||void 0===e?void 0:e.includes(r)});if(a){var d=a.selfIndex,l=void 0!==d&&d>=0?d+1:N.indexOf(a)+1;return{rootKey:"left-root:".concat(a.id),parentNum:l}}var s=void 0!==r&&r>=0?r+1:S.indexOf(n)+1;return{rootKey:"right-orphan-root:".concat(n.id),parentNum:s}},v=function(n,e){if(n&&e)return n.find(function(n){return n.id===e.id||n.nodeId&&n.nodeId===e.nodeId||n.contentId&&n.contentId===e.contentId})||void 0},p=function(n,e,u,c,f,I,_){if(e&&function(n,e,t){var a;((null===(a=null==n?void 0:n.evaluationResults)||void 0===a?void 0:a.length)?n.evaluationResults:(null==n?void 0:n.evaluationResult)?[n.evaluationResult]:[]).forEach(function(a){var u=(null==a?void 0:a.deviations)||{};Object.keys(u).sort().forEach(function(v){var c=u[v];if(c){var f=!i(c[d]),p=!i(c[l]);if(f||p){var I=(null==a?void 0:a.nodeId)||n.nodeId||n.id,_="".concat(I).concat(s).concat(v);void 0===o[_]&&(void 0===r[e]&&(r[e]=1),o[_]={index:r[e]++,rootKey:e,parentNum:t})}}})})}(e,c,f),e&&!I){var h=(null==_?void 0:_.id)||"fallback_parent_".concat(a++);t[h]||(t[h]=[]),t[h].push(e)}((null==e?void 0:e.subsections)||(null==n?void 0:n.subsections)||(null==u?void 0:u.subsections)||[]).forEach(function(t){var i=v(null==n?void 0:n.subsections,t),o=v(null==u?void 0:u.subsections,t);p(t,i,o,c,f,!1,e||_)})};N.forEach(function(n){var e,t=u(n,"left"),i=t.rootKey,o=t.parentNum,r=null;if(f){var a=null===(e=n.refIndexes)||void 0===e?void 0:e[0];r=S.find(function(n){return n.selfIndex===a})}else r=S[N.indexOf(n)];p(n,n,r,i,o,!0,n)}),b||S.forEach(function(n){var e=u(n,"right"),t=e.rootKey,i=e.parentNum;t.startsWith("right-orphan-root:")&&p(n,null,n,t,i,!0,n)});var I=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].index]})),_=Object.fromEntries(Object.entries(o).map(function(n){return[n[0],n[1].parentNum]}));return{parentDeviationRecord:t,registry:I,deviationParentRegistry:_}},[N,S,f,c,b]),P=D.parentDeviationRecord,K=D.registry,V=D.deviationParentRegistry;return{isGuidelineMode:b,activeProposed:R,activeVariants:C,comparisonRows:E,existingRule:j,proposedSections:N,existingSections:S,visibleFields:k,parentDeviationRecord:P,deviationNumberRegistry:K,deviationParentRegistry:V,parseError:O}};export{c as useCognitiveTreeData};
|
|
2
2
|
//# sourceMappingURL=useCompareData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CognitiveCompareTest.d.ts","sourceRoot":"","sources":["../../../src/CognitiveCompareTest.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CognitiveCompareTest.d.ts","sourceRoot":"","sources":["../../../src/CognitiveCompareTest.tsx"],"names":[],"mappings":"AAQA,QAAA,MAAM,oBAAoB,+CAkNzB,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CitationAnchor.d.ts","sourceRoot":"","sources":["../../../../../src/features/CognitiveCompare/CitationAnchor.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EACV,aAAa,EAKhB,MAAM,OAAO,CAAC;AAcf,UAAU,mBAAmB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,GAAG,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACrC,oBAAoB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvC,WAAW,CAAC,EAAE;QACV,qBAAqB,CAAC,EAAE,aAAa,CAAC;QACtC,KAAK,CAAC,EAAE,aAAa,CAAC;QACtB,cAAc,CAAC,EAAE,aAAa,CAAC;QAC/B,iBAAiB,CAAC,EAAE,aAAa,CAAC;QAClC,UAAU,CAAC,EAAE,aAAa,CAAC;QAC3B,QAAQ,CAAC,EAAE,aAAa,CAAC;QACzB,SAAS,CAAC,EAAE,aAAa,CAAC;QAC1B,eAAe,CAAC,EAAE,aAAa,CAAC;QAChC,eAAe,CAAC,EAAE,aAAa,CAAC;QAChC,mBAAmB,CAAC,EAAE,aAAa,CAAC;QACpC,eAAe,CAAC,EAAE,aAAa,CAAC;QAChC,oBAAoB,CAAC,EAAE,aAAa,CAAC;QACrC,eAAe,CAAC,EAAE,aAAa,CAAC;KACnC,CAAC;IACF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,kBAAkB,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,KAAK,IAAI,CAAC;CACxD;
|
|
1
|
+
{"version":3,"file":"CitationAnchor.d.ts","sourceRoot":"","sources":["../../../../../src/features/CognitiveCompare/CitationAnchor.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EACV,aAAa,EAKhB,MAAM,OAAO,CAAC;AAcf,UAAU,mBAAmB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,GAAG,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACrC,oBAAoB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvC,WAAW,CAAC,EAAE;QACV,qBAAqB,CAAC,EAAE,aAAa,CAAC;QACtC,KAAK,CAAC,EAAE,aAAa,CAAC;QACtB,cAAc,CAAC,EAAE,aAAa,CAAC;QAC/B,iBAAiB,CAAC,EAAE,aAAa,CAAC;QAClC,UAAU,CAAC,EAAE,aAAa,CAAC;QAC3B,QAAQ,CAAC,EAAE,aAAa,CAAC;QACzB,SAAS,CAAC,EAAE,aAAa,CAAC;QAC1B,eAAe,CAAC,EAAE,aAAa,CAAC;QAChC,eAAe,CAAC,EAAE,aAAa,CAAC;QAChC,mBAAmB,CAAC,EAAE,aAAa,CAAC;QACpC,eAAe,CAAC,EAAE,aAAa,CAAC;QAChC,oBAAoB,CAAC,EAAE,aAAa,CAAC;QACrC,eAAe,CAAC,EAAE,aAAa,CAAC;KACnC,CAAC;IACF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,kBAAkB,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,KAAK,IAAI,CAAC;CACxD;AAucD,QAAA,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAwNjD,CAAC;AAEF,eAAe,cAAc,CAAC"}
|