@pickaxeproject/react 6.11.0 → 6.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=e=>{var t;const r=(null!==(t=e.parts)&&void 0!==t?t:[]).filter((e=>!1!==e.isVisible)),n=r.filter((e=>"text"===e.type)).map((e=>{var t;return null!==(t=e.content)&&void 0!==t?t:""})).join(""),s=n.replace(/\s+/g," ").replace(/\s*([.,!?;:])\s*/g,"$1").trim();return s?JSON.stringify({role:e.role,text:s}):JSON.stringify({role:e.role,parts:r.map((e=>{var t;return{type:e.type,content:null!==(t=e.content)&&void 0!==t?t:""}}))})};exports.getUnpersistedMemoryMessages=(t,r)=>{if(!r.length||!t.length)return t;const n=r.map(e),s=new Set(r.filter((e=>"assistant"===e.role)).map(e));let l=0;return t.filter((t=>{const r=e(t),i=n.indexOf(r,l);return-1!==i?(l=i+1,!1):"assistant"!==t.role||!s.has(r)}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=t=>{if("string"==typeof t)return t;if(null==t)return"";try{return JSON.stringify(t)}catch(e){return String(t)}},e=e=>{if(!e||"object"!=typeof e)return null;const r=e;return"string"!=typeof r.type?null:{type:r.type,content:t(r.content),isVisible:!1!==r.isVisible}},r=(t,r)=>{let s=t;if("string"==typeof s)try{const t=JSON.parse(s);Array.isArray(t)&&(s=t)}catch(t){}if(Array.isArray(s))return s.map(e).filter((t=>null!==t));const n=e(s);if(n)return[n];const i="string"==typeof s?s:r;return"string"==typeof i&&i?[{type:"text",content:i,isVisible:!0}]:[]},s=t=>{const e=r(t.parts).filter((t=>!1!==t.isVisible)),s=e.filter((t=>"text"===t.type)).map((t=>{var e;return null!==(e=t.content)&&void 0!==e?e:""})).join(""),n=s.replace(/\s+/g," ").replace(/\s*([.,!?;:])\s*/g,"$1").trim();return n?JSON.stringify({role:t.role,text:n}):JSON.stringify({role:t.role,parts:e.map((t=>{var e;return{type:t.type,content:null!==(e=t.content)&&void 0!==e?e:""}}))})};exports.getUnpersistedMemoryMessages=(t,e)=>{if(!e.length||!t.length)return t;const r=e.map(s),n=new Set(e.filter((t=>"assistant"===t.role)).map(s));let i=0;return t.filter((t=>{const e=s(t),o=r.indexOf(e,i);return-1!==o?(i=o+1,!1):"assistant"!==t.role||!n.has(e)}))},exports.normalizeHistoryMessages=t=>Array.isArray(t)?t.flatMap((t=>{var e;if(!t||"object"!=typeof t)return[];const s=t;return"user"!==s.role&&"assistant"!==s.role?[]:[Object.assign(Object.assign({},s),{documentIds:Array.isArray(s.documentIds)?s.documentIds.filter((t=>"string"==typeof t)):[],parts:r(s.parts,null!==(e=s.content)&&void 0!==e?e:s.message)})]})):[],exports.normalizeMessageParts=r;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("./useScrollContext.js");exports.useScroll=({auto:t=!1,debug:o,smooth:n=!0})=>{const{scrollContainerRef:l,scrollTargetRef:c,hasScrolledRef:s,isLocked:u,isScrollSession:i,isScrollIncreasing:a,setIsLocked:d,setIsScrollSession:v,setIsScrolling:h,setIsScrollIncreasing:b}=r.useScrollContext(),f=e.useRef(null),g=e.useRef(null),m=e.useRef(!1),w=e.useRef(0),C=e.useCallback((()=>{null!==f.current&&(cancelAnimationFrame(f.current),f.current=null)}),[]),S=e.useCallback((e=>{g.current&&clearTimeout(g.current),g.current=setTimeout((()=>{m.current=!1,h(!1)}),"smooth"===e?400:0)}),[h]),T=e.useCallback(((e={})=>{var r;if(!e.force&&s.current)return;const t=null!==(r=e.behavior)&&void 0!==r?r:n?"smooth":"auto",u=l.current,i=c.current;if(u||i){if(m.current=!0,h(!0),u){const e=Math.max(0,u.scrollHeight-u.clientHeight);u.scrollTo({top:e,behavior:t})}else if(i){const e=i.getBoundingClientRect().bottom+window.scrollY,r=Math.max(0,e-window.innerHeight);window.scrollTo({top:r,behavior:t})}o&&console.log("[useScroll] scrolled to the active bottom"),S(t)}else o&&console.log("[useScroll] no scroll element detected")}),[o,S,s,l,c,h,n]),R=e.useCallback(((e={})=>{C(),f.current=requestAnimationFrame((()=>{f.current=null,T(e)}))}),[C,T]),p=e.useCallback(((e={})=>{var r;if(!e.force&&s.current)return;const t=c.current;if(!t)return void(o&&console.log("[useScroll] scroll target not detected"));const l=null!==(r=e.behavior)&&void 0!==r?r:n?"smooth":"auto",u=t.getBoundingClientRect().bottom+window.scrollY,i=Math.max(0,u-500);m.current=!0,h(!0),window.scrollTo({top:i,behavior:l}),o&&console.log("[useScroll] scrolled to the form response"),S(l)}),[o,S,s,c,h,n]),E=e.useCallback(((e={})=>{C(),f.current=requestAnimationFrame((()=>{f.current=null,p(e)}))}),[C,p]),k=e.useCallback((()=>{s.current=!1,d(!0),v(!0)}),[s,d,v]),L=e.useCallback((()=>{v(!1)}),[v]),H=e.useCallback(((e={})=>R(e)),[R]),x=e.useCallback(((e={})=>E(e)),[E]);return e.useEffect((()=>{if(!t||!i||!u)return;let e=l.current,r=c.current,o=null,n=[];const s=()=>{var t;if(!o)return;const n=e?e.scrollHeight:null!==(t=null==r?void 0:r.getBoundingClientRect().height)&&void 0!==t?t:0,l=n>w.current;w.current=n,b(l),l&&(e?R({behavior:"auto"}):E({behavior:"auto"}))},a=new ResizeObserver(s);function d(){o&&(n.forEach((e=>a.unobserve(e))),n=[o,...Array.from(o.children)],n.forEach((e=>a.observe(e))))}const v=new MutationObserver((()=>{d(),s()}));let h=null;const f=()=>{var t;e=l.current,r=c.current;const n=null!=e?e:r;return!(!n||n===o)&&(v.disconnect(),a.disconnect(),o=n,w.current=e?e.scrollHeight:null!==(t=null==r?void 0:r.getBoundingClientRect().height)&&void 0!==t?t:0,d(),v.observe(o,{childList:!0,subtree:!0}),e?R({behavior:"auto"}):E({behavior:"auto"}),!0)};return f()||(h=new MutationObserver((()=>{f()&&(null==h||h.disconnect())})),h.observe(document.body,{childList:!0,subtree:!0})),()=>{null==h||h.disconnect(),v.disconnect(),a.disconnect()}}),[t,u,i,R,E,l,c,b]),e.useEffect((()=>{u&&(s.current=!1)}),[s,u]),e.useEffect((()=>{const e=l.current,r=null!=e?e:window,t=()=>{if(m.current)return;const r=(()=>{if(e)return e.scrollHeight-e.scrollTop-e.clientHeight<=32;const r=c.current;return!r||r.getBoundingClientRect().bottom-window.innerHeight<=32})();s.current=!r,d(r)},o=()=>{m.current&&(m.current=!1,h(!1),g.current&&(clearTimeout(g.current),g.current=null),e?e.scrollTo({top:e.scrollTop,behavior:"auto"}):window.scrollTo({top:window.scrollY,behavior:"auto"}))};return r.addEventListener("scroll",t,{passive:!0}),r.addEventListener("wheel",o,{passive:!0}),r.addEventListener("touchmove",o,{passive:!0}),()=>{r.removeEventListener("scroll",t),r.removeEventListener("wheel",o),r.removeEventListener("touchmove",o)}}),[s,l,c,d,h]),e.useEffect((()=>()=>{C(),g.current&&clearTimeout(g.current)}),[C]),{scrollContainerRef:l,scrollTargetRef:c,isScrollIncreasing:a,scrollStartSession:k,scrollEndSession:L,scrollToBottom:H,scrollToTarget:x}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("./useScrollContext.js");exports.useScroll=({auto:t=!1,debug:o,smooth:n=!0})=>{const{scrollContainerRef:l,scrollTargetRef:c,hasScrolledRef:s,isLocked:u,isScrollIncreasing:i,setIsLocked:a,setIsScrollSession:d,setIsScrolling:h,setIsScrollIncreasing:v}=r.useScrollContext(),b=e.useRef(null),f=e.useRef(null),g=e.useRef(!1),m=e.useRef(0),w=e.useCallback((()=>{null!==b.current&&(cancelAnimationFrame(b.current),b.current=null)}),[]),C=e.useCallback((e=>{f.current&&clearTimeout(f.current),f.current=setTimeout((()=>{g.current=!1,h(!1)}),"smooth"===e?400:100)}),[h]),S=e.useCallback(((e={})=>{var r;if(!e.force&&s.current)return;const t=null!==(r=e.behavior)&&void 0!==r?r:n?"smooth":"auto",u=l.current,i=c.current;if(u||i){if(g.current=!0,h(!0),u){const e=Math.max(0,u.scrollHeight-u.clientHeight);u.scrollTo({top:e,behavior:t})}else if(i){const e=i.getBoundingClientRect().bottom+window.scrollY,r=Math.max(0,e-window.innerHeight);window.scrollTo({top:r,behavior:t})}o&&console.log("[useScroll] scrolled to the active bottom"),C(t)}else o&&console.log("[useScroll] no scroll element detected")}),[o,C,s,l,c,h,n]),T=e.useCallback(((e={})=>{w(),b.current=requestAnimationFrame((()=>{b.current=null,S(e)}))}),[w,S]),R=e.useCallback(((e={})=>{var r;if(!e.force&&s.current)return;const t=c.current;if(!t)return void(o&&console.log("[useScroll] scroll target not detected"));const l=null!==(r=e.behavior)&&void 0!==r?r:n?"smooth":"auto",u=t.getBoundingClientRect().bottom+window.scrollY,i=Math.max(0,u-500);g.current=!0,h(!0),window.scrollTo({top:i,behavior:l}),o&&console.log("[useScroll] scrolled to the form response"),C(l)}),[o,C,s,c,h,n]),p=e.useCallback(((e={})=>{w(),b.current=requestAnimationFrame((()=>{b.current=null,R(e)}))}),[w,R]),E=e.useCallback((()=>{s.current=!1,a(!0),d(!0)}),[s,a,d]),k=e.useCallback((()=>{d(!1)}),[d]),H=e.useCallback(((e={})=>T(e)),[T]),L=e.useCallback(((e={})=>p(e)),[p]);return e.useEffect((()=>{if(!t||!u)return;let e=l.current,r=c.current,o=null,n=[];const s=()=>{var t;if(!o)return;const n=e?Math.max(0,e.scrollHeight-e.clientHeight):null!==(t=null==r?void 0:r.getBoundingClientRect().height)&&void 0!==t?t:0,l=n>m.current;m.current=n,v(l),l&&(e?T({behavior:"auto"}):p({behavior:"auto"}))},i=new ResizeObserver(s);function a(){o&&(n.forEach((e=>i.unobserve(e))),n=[o,...Array.from(o.children)],n.forEach((e=>i.observe(e))))}const d=new MutationObserver((()=>{a(),s()}));let h=null;const b=()=>{var t;e=l.current,r=c.current;const n=null!=e?e:r;return!(!n||n===o)&&(d.disconnect(),i.disconnect(),o=n,m.current=e?Math.max(0,e.scrollHeight-e.clientHeight):null!==(t=null==r?void 0:r.getBoundingClientRect().height)&&void 0!==t?t:0,a(),d.observe(o,{childList:!0,subtree:!0}),e?T({behavior:"auto"}):p({behavior:"auto"}),!0)};return b()||(h=new MutationObserver((()=>{b()&&(null==h||h.disconnect())})),h.observe(document.body,{childList:!0,subtree:!0})),()=>{null==h||h.disconnect(),d.disconnect(),i.disconnect()}}),[t,u,T,p,l,c,v]),e.useEffect((()=>{u&&(s.current=!1)}),[s,u]),e.useEffect((()=>{const e=l.current,r=null!=e?e:window,t=()=>{if(g.current)return;const r=(()=>{if(e)return e.scrollHeight-e.scrollTop-e.clientHeight<=32;const r=c.current;return!r||r.getBoundingClientRect().bottom-window.innerHeight<=32})();s.current=!r,a(r)},o=()=>{g.current&&(g.current=!1,h(!1),f.current&&(clearTimeout(f.current),f.current=null),e?e.scrollTo({top:e.scrollTop,behavior:"auto"}):window.scrollTo({top:window.scrollY,behavior:"auto"}))};return r.addEventListener("scroll",t,{passive:!0}),r.addEventListener("wheel",o,{passive:!0}),r.addEventListener("touchmove",o,{passive:!0}),()=>{r.removeEventListener("scroll",t),r.removeEventListener("wheel",o),r.removeEventListener("touchmove",o)}}),[s,l,c,a,h]),e.useEffect((()=>()=>{w(),f.current&&clearTimeout(f.current)}),[w]),{scrollContainerRef:l,scrollTargetRef:c,isScrollIncreasing:i,scrollStartSession:E,scrollEndSession:k,scrollToBottom:H,scrollToTarget:L}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),r=require("react/jsx-runtime"),n=require("react"),t=require("./hooks/usePickaxeMarkdownContext.js"),s=require("./utils/custom-plugins.js"),i=require("react-markdown"),a=require("remark-gfm"),o=require("remark-math"),l=require("rehype-katex"),c=require("rehype-raw"),u=require("./Components/A/index.js"),d=require("./Components/A/FilePreview.js"),p=require("./Components/P/index.js"),h=require("./Components/Img/index.js"),f=require("./Components/Iframe/index.js"),m=require("./Components/Code/index.js"),x=require("./Components/Headings/index.js"),g=require("./Components/List/index.js"),j=require("./Components/Table/index.js"),b=require("./Components/Others/index.js"),w=require("./Components/Action/index.js"),k=require("./Components/Artifact/index.js"),q=require("./Components/Others/Think.js"),C=require("../../../../common/cn.js");function v(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var y=v(i),P=v(a),O=v(o),$=v(l),S=v(c);exports.PickaxeMarkdownRenderer=({className:i,style:a,children:o,value:l,maxLines:c,maxChars:v,multiLineBreaks:R,onExpandClick:A,filePreviewSeenRef:H,suppressedRichPreviewUrls:T})=>{const{colors:M,rtl:I,disableHtml:_,disableJs:N,disableCss:E}=t.usePickaxeMarkdownContext(),[F,L]=n.useState({width:0,height:0}),[U,B]=n.useState(null),z=n.useRef(null),J=n.useMemo((()=>{if(!l)return"";let e=l.trim();return e=e.replace(/<!--[\s\S]*?-->/g,""),e=e.replace(/\u200B/g,""),e=e.replace(/\\\((.*?)\\\)/g,"$$$ $1 $$$"),e=e.replace(/\\\[(.*?)\\\]/g,"$$$ $1 $$$"),e=e.replace(/<\/think>/g,"\n</think>"),R&&(e=e.replace(/```[\s\S]*?```|(\n(?=\n))/g,((e,r)=>r?"\n\n<br/>\n":e))),e||""}),[l,R]);n.useEffect((()=>{if(v)return void B(J.length>v?J.slice(0,v)+'<span class="pxe-expand-btn">...</span>':null);if(!c)return void B(null);if(!z.current||!J||U)return;const e=z.current,r=parseInt(window.getComputedStyle(e).lineHeight,10),n=c*r;if(!(F.height>n))return;const t=Math.floor(F.width/8),s=Math.floor(t*c);B(J.slice(0,s)+'<span class="pxe-expand-btn">...</span>')}),[J,c,v,F,U]);const W=n.useRef(new Set);H||(W.current=new Set);const D=null!=H?H:W,Q={h1:x.H1,h2:x.H2,h3:x.H3,h4:x.H4,h5:x.H5,p:e=>r.jsx(p.P,Object.assign({},e,{suppressedRichPreviewUrls:T})),a:e=>r.jsx(u.A,Object.assign({},e,{filePreviewSeenRef:D,suppressedRichPreviewUrls:T})),img:e=>{const n="string"==typeof e.src?e.src:"",t=d.getFilePreviewInfo(n);return t&&!d.shouldSuppressRichPreviewForUrl(t.url,T)?d.shouldRenderFilePreview(t,D)?r.jsx(d.default,{fileInfo:t,displayName:"string"==typeof e.alt?e.alt:void 0}):r.jsx("a",Object.assign({href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:M.accent}},{children:e.alt||t.fileName})):r.jsx(h.Img,Object.assign({},e))},iframe:f.Iframe,code:m.Code,ol:g.Ol,ul:g.Ul,li:g.Li,table:j.Table,th:j.Th,tr:j.Tr,td:j.Td,hr:b.Hr,br:b.Br,blockquote:b.Blockquote,span:n=>{var{children:t}=n,s=e.__rest(n,["children"]);return"pxe-expand-btn"===s.className?r.jsx("span",Object.assign({},s,{style:Object.assign({display:"inline",fontWeight:500,color:M.accent,marginLeft:".25rem",userSelect:"none"},A&&{cursor:"pointer"})},A&&{onClick:A},{children:t})):r.jsx("span",Object.assign({},s,{children:t}))},"action-caption":w.ActionCaption,"action-finished":w.ActionFinished,"action-error":w.ActionError,artifact:k.Artifact,"artifact-error":k.ArtifactError,think:q.Think};n.useEffect((()=>{if(!z.current)return;const e=new ResizeObserver((e=>{for(const r of e){const{width:e,height:n}=r.contentRect;L({width:e,height:n})}}));return e.observe(z.current),()=>{e.disconnect()}}),[]);const G=U||J;return r.jsxs("div",Object.assign({className:"pxe-markdown",ref:z,style:Object.assign({position:"relative",overflowWrap:"break-word",display:"grid",gridTemplateColumns:"repeat(1, minmax(0, 1fr))",gap:".625rem",width:"100%"},a)},I&&{dir:"rtl"},{children:[r.jsx(y.default,Object.assign({className:C.default("pxe-prose",i),components:Q,remarkPlugins:[P.default,[O.default,{singleDollarTextMath:!1}],s.remarkSmartQuotes],rehypePlugins:[s.rehypeCode,$.default,..._?[]:[S.default],[s.rehypeSanitize,{disableJs:N,disableCss:E}]]},{children:G})),o]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),r=require("react/jsx-runtime"),s=require("react"),n=require("./hooks/usePickaxeMarkdownContext.js"),i=require("./utils/custom-plugins.js"),t=require("react-markdown"),o=require("remark-gfm"),a=require("remark-math"),l=require("rehype-katex"),c=require("rehype-raw"),u=require("./Components/A/index.js"),d=require("./Components/A/FilePreview.js"),p=require("./Components/P/index.js"),f=require("./Components/Img/index.js"),h=require("./Components/Iframe/index.js"),m=require("./Components/Code/index.js"),x=require("./Components/Headings/index.js"),g=require("./Components/List/index.js"),j=require("./Components/Table/index.js"),w=require("./Components/Others/index.js"),v=require("./Components/Action/index.js"),b=require("./Components/Artifact/index.js"),k=require("./Components/Others/Think.js"),C=require("../../../../common/cn.js");function q(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var P=q(t),R=q(o),y=q(a),S=q(l),O=q(c);exports.PickaxeMarkdownRenderer=({className:t,style:o,children:a,value:l,maxLines:c,maxChars:q,multiLineBreaks:$,onExpandClick:A,filePreviewSeenRef:U,suppressedRichPreviewUrls:H})=>{const{colors:M,rtl:T,disableHtml:E,disableJs:I,disableCss:_}=n.usePickaxeMarkdownContext(),[N,F]=s.useState({width:0,height:0}),[L,B]=s.useState(null),z=s.useRef(null),J=s.useMemo((()=>{if(!l)return"";let e=l.trim();return e=e.replace(/<!--[\s\S]*?-->/g,""),e=e.replace(/\u200B/g,""),e=e.replace(/\\\((.*?)\\\)/g,"$$$ $1 $$$"),e=e.replace(/\\\[(.*?)\\\]/g,"$$$ $1 $$$"),e=e.replace(/<\/think>/g,"\n</think>"),$&&(e=e.replace(/```[\s\S]*?```|(\n(?=\n))/g,((e,r)=>r?"\n\n<br/>\n":e))),e||""}),[l,$]);s.useEffect((()=>{if(q)return void B(J.length>q?J.slice(0,q)+'<span class="pxe-expand-btn">...</span>':null);if(!c)return void B(null);if(!z.current||!J||L)return;const e=z.current,r=parseInt(window.getComputedStyle(e).lineHeight,10),s=c*r;if(!(N.height>s))return;const n=Math.floor(N.width/8),i=Math.floor(n*c);B(J.slice(0,i)+'<span class="pxe-expand-btn">...</span>')}),[J,c,q,N,L]);const W=s.useRef(new Set);U||(W.current=new Set);const D=null!=U?U:W,Q=s.useRef({colors:M,onExpandClick:A,filePreviewSeenRef:D,suppressedRichPreviewUrls:H});Q.current={colors:M,onExpandClick:A,filePreviewSeenRef:D,suppressedRichPreviewUrls:H};const G=s.useMemo((()=>({h1:x.H1,h2:x.H2,h3:x.H3,h4:x.H4,h5:x.H5,p:e=>r.jsx(p.P,Object.assign({},e,{suppressedRichPreviewUrls:Q.current.suppressedRichPreviewUrls})),a:e=>r.jsx(u.A,Object.assign({},e,{filePreviewSeenRef:Q.current.filePreviewSeenRef,suppressedRichPreviewUrls:Q.current.suppressedRichPreviewUrls})),img:e=>{const{colors:s,filePreviewSeenRef:n,suppressedRichPreviewUrls:i}=Q.current,t="string"==typeof e.src?e.src:"",o=d.getFilePreviewInfo(t);return o&&!d.shouldSuppressRichPreviewForUrl(o.url,i)?d.shouldRenderFilePreview(o,n)?r.jsx(d.default,{fileInfo:o,displayName:"string"==typeof e.alt?e.alt:void 0}):r.jsx("a",Object.assign({href:o.url,target:"_blank",rel:"noopener noreferrer",style:{color:s.accent}},{children:e.alt||o.fileName})):r.jsx(f.Img,Object.assign({},e))},iframe:h.Iframe,code:m.Code,ol:g.Ol,ul:g.Ul,li:g.Li,table:j.Table,th:j.Th,tr:j.Tr,td:j.Td,hr:w.Hr,br:w.Br,blockquote:w.Blockquote,span:s=>{var{children:n}=s,i=e.__rest(s,["children"]);const{colors:t,onExpandClick:o}=Q.current;return"pxe-expand-btn"===i.className?r.jsx("span",Object.assign({},i,{style:Object.assign({display:"inline",fontWeight:500,color:t.accent,marginLeft:".25rem",userSelect:"none"},o&&{cursor:"pointer"})},o&&{onClick:o},{children:n})):r.jsx("span",Object.assign({},i,{children:n}))},"action-caption":v.ActionCaption,"action-finished":v.ActionFinished,"action-error":v.ActionError,artifact:b.Artifact,"artifact-error":b.ArtifactError,think:k.Think})),[]);s.useEffect((()=>{if(!z.current)return;const e=new ResizeObserver((e=>{for(const r of e){const{width:e,height:s}=r.contentRect;F({width:e,height:s})}}));return e.observe(z.current),()=>{e.disconnect()}}),[]);const K=L||J;return r.jsxs("div",Object.assign({className:"pxe-markdown",ref:z,style:Object.assign({position:"relative",overflowWrap:"break-word",display:"grid",gridTemplateColumns:"repeat(1, minmax(0, 1fr))",gap:".625rem",width:"100%"},o)},T&&{dir:"rtl"},{children:[r.jsx(P.default,Object.assign({className:C.default("pxe-prose",t),components:G,remarkPlugins:[R.default,[y.default,{singleDollarTextMath:!1}],i.remarkSmartQuotes],rehypePlugins:[i.rehypeCode,S.default,...E?[]:[O.default],[i.rehypeSanitize,{disableJs:I,disableCss:_}]]},{children:K})),a]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),t=require("@tanstack/react-query"),s=require("./usePickaxeContext.js"),r=require("./useResponseContext.js"),i=require("../../common/api/pickaxe.js");const a=e=>e.filter(((t,s)=>"user"!==t.role||!(e=>"assistant"===(null==e?void 0:e.role)&&"scheduled_followup"===e.area)(e[s+1]))),n=(t,s)=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=yield i.pickaxeApi2.get(`/conversation?pickaxeId=${t}&sessionId=${s}`),r=e.data;if(200!==e.status)throw new Error("[_getChat] Failed to fetch chat conversation "+r);return r}));exports.useConversation=()=>{const{pickaxeId:i,sessionId:o,pickaxe:u}=s.usePickaxeContext(),{isGenerating:c,isSwitchedToChat:d}=r.useResponseContext(),l="string"==typeof(null==u?void 0:u.intromessage)&&0===u.intromessage.trim().length,v=!(!i||!o||d||c);return t.useQuery({queryKey:["form",i,"chat",o],queryFn:()=>e.__awaiter(void 0,void 0,void 0,(function*(){return n(i,o)})),select:e=>{const t=l?e.messages.filter((e=>"intromessage"!==e.area)):e.messages;return Object.assign(Object.assign({},e),{messages:a(t)})},enabled:!!i&&!!o&&!d,refetchInterval:!!v&&15e3,refetchIntervalInBackground:!1})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("@tanstack/react-query"),t=require("./usePickaxeContext.js"),r=require("./useResponseContext.js"),i=require("../../common/api/pickaxe.js"),o=require("../../common/chatMessages.js");const a=e=>e.filter(((s,t)=>"user"!==s.role||!(e=>"assistant"===(null==e?void 0:e.role)&&"scheduled_followup"===e.area)(e[t+1]))),n=(s,t)=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=yield i.pickaxeApi2.get(`/conversation?pickaxeId=${s}&sessionId=${t}`),r=e.data;if(200!==e.status)throw new Error("[_getChat] Failed to fetch chat conversation "+r);return r}));exports.useConversation=()=>{const{pickaxeId:i,sessionId:c,pickaxe:u}=t.usePickaxeContext(),{isGenerating:l,isSwitchedToChat:d}=r.useResponseContext(),v="string"==typeof(null==u?void 0:u.intromessage)&&0===u.intromessage.trim().length,g=!(!i||!c||d||l);return s.useQuery({queryKey:["form",i,"chat",c],queryFn:()=>e.__awaiter(void 0,void 0,void 0,(function*(){return n(i,c)})),select:e=>{const s=o.normalizeHistoryMessages(e.messages),t=v?s.filter((e=>"intromessage"!==e.area)):s;return Object.assign(Object.assign({},e),{messages:a(t)})},enabled:!!i&&!!c&&!d,refetchInterval:!!g&&15e3,refetchIntervalInBackground:!1})};
@@ -1,3 +1,5 @@
1
- import type { PickaxeHistoryMessage } from "../types/history";
1
+ import type { PickaxeHistoryMessage, PickaxeHistoryMessagePart } from "../types/history";
2
2
  import type { MemoryStoredChatMessage } from "../types/response";
3
+ export declare const normalizeMessageParts: (parts: unknown, fallbackContent?: unknown) => PickaxeHistoryMessagePart[];
4
+ export declare const normalizeHistoryMessages: (messages: unknown) => PickaxeHistoryMessage[];
3
5
  export declare const getUnpersistedMemoryMessages: (memoryMessages: MemoryStoredChatMessage[], persistedMessages: PickaxeHistoryMessage[]) => MemoryStoredChatMessage[];
@@ -1 +1 @@
1
- const t=t=>{var e;const r=(null!==(e=t.parts)&&void 0!==e?e:[]).filter((t=>!1!==t.isVisible)),n=r.filter((t=>"text"===t.type)).map((t=>{var e;return null!==(e=t.content)&&void 0!==e?e:""})).join(""),l=n.replace(/\s+/g," ").replace(/\s*([.,!?;:])\s*/g,"$1").trim();return l?JSON.stringify({role:t.role,text:l}):JSON.stringify({role:t.role,parts:r.map((t=>{var e;return{type:t.type,content:null!==(e=t.content)&&void 0!==e?e:""}}))})},e=(e,r)=>{if(!r.length||!e.length)return e;const n=r.map(t),l=new Set(r.filter((t=>"assistant"===t.role)).map(t));let i=0;return e.filter((e=>{const r=t(e),s=n.indexOf(r,i);return-1!==s?(i=s+1,!1):"assistant"!==e.role||!l.has(r)}))};export{e as getUnpersistedMemoryMessages};
1
+ const t=t=>{if("string"==typeof t)return t;if(null==t)return"";try{return JSON.stringify(t)}catch(r){return String(t)}},r=r=>{if(!r||"object"!=typeof r)return null;const e=r;return"string"!=typeof e.type?null:{type:e.type,content:t(e.content),isVisible:!1!==e.isVisible}},e=(t,e)=>{let n=t;if("string"==typeof n)try{const t=JSON.parse(n);Array.isArray(t)&&(n=t)}catch(t){}if(Array.isArray(n))return n.map(r).filter((t=>null!==t));const s=r(n);if(s)return[s];const i="string"==typeof n?n:e;return"string"==typeof i&&i?[{type:"text",content:i,isVisible:!0}]:[]},n=t=>Array.isArray(t)?t.flatMap((t=>{var r;if(!t||"object"!=typeof t)return[];const n=t;return"user"!==n.role&&"assistant"!==n.role?[]:[Object.assign(Object.assign({},n),{documentIds:Array.isArray(n.documentIds)?n.documentIds.filter((t=>"string"==typeof t)):[],parts:e(n.parts,null!==(r=n.content)&&void 0!==r?r:n.message)})]})):[],s=t=>{const r=e(t.parts).filter((t=>!1!==t.isVisible)),n=r.filter((t=>"text"===t.type)).map((t=>{var r;return null!==(r=t.content)&&void 0!==r?r:""})).join(""),s=n.replace(/\s+/g," ").replace(/\s*([.,!?;:])\s*/g,"$1").trim();return s?JSON.stringify({role:t.role,text:s}):JSON.stringify({role:t.role,parts:r.map((t=>{var r;return{type:t.type,content:null!==(r=t.content)&&void 0!==r?r:""}}))})},i=(t,r)=>{if(!r.length||!t.length)return t;const e=r.map(s),n=new Set(r.filter((t=>"assistant"===t.role)).map(s));let i=0;return t.filter((t=>{const r=s(t),o=e.indexOf(r,i);return-1!==o?(i=o+1,!1):"assistant"!==t.role||!n.has(r)}))};export{i as getUnpersistedMemoryMessages,n as normalizeHistoryMessages,e as normalizeMessageParts};
@@ -1 +1 @@
1
- import{useRef as e,useCallback as r,useEffect as t}from"react";import{useScrollContext as o}from"./useScrollContext.js";const n=({auto:n=!1,debug:l,smooth:c=!0})=>{const{scrollContainerRef:s,scrollTargetRef:i,hasScrolledRef:u,isLocked:a,isScrollSession:d,isScrollIncreasing:v,setIsLocked:h,setIsScrollSession:m,setIsScrolling:g,setIsScrollIncreasing:b}=o(),f=e(null),w=e(null),S=e(!1),T=e(0),p=r((()=>{null!==f.current&&(cancelAnimationFrame(f.current),f.current=null)}),[]),R=r((e=>{w.current&&clearTimeout(w.current),w.current=setTimeout((()=>{S.current=!1,g(!1)}),"smooth"===e?400:0)}),[g]),L=r(((e={})=>{var r;if(!e.force&&u.current)return;const t=null!==(r=e.behavior)&&void 0!==r?r:c?"smooth":"auto",o=s.current,n=i.current;if(o||n){if(S.current=!0,g(!0),o){const e=Math.max(0,o.scrollHeight-o.clientHeight);o.scrollTo({top:e,behavior:t})}else if(n){const e=n.getBoundingClientRect().bottom+window.scrollY,r=Math.max(0,e-window.innerHeight);window.scrollTo({top:r,behavior:t})}l&&console.log("[useScroll] scrolled to the active bottom"),R(t)}else l&&console.log("[useScroll] no scroll element detected")}),[l,R,u,s,i,g,c]),E=r(((e={})=>{p(),f.current=requestAnimationFrame((()=>{f.current=null,L(e)}))}),[p,L]),C=r(((e={})=>{var r;if(!e.force&&u.current)return;const t=i.current;if(!t)return void(l&&console.log("[useScroll] scroll target not detected"));const o=null!==(r=e.behavior)&&void 0!==r?r:c?"smooth":"auto",n=t.getBoundingClientRect().bottom+window.scrollY,s=Math.max(0,n-500);S.current=!0,g(!0),window.scrollTo({top:s,behavior:o}),l&&console.log("[useScroll] scrolled to the form response"),R(o)}),[l,R,u,i,g,c]),H=r(((e={})=>{p(),f.current=requestAnimationFrame((()=>{f.current=null,C(e)}))}),[p,C]),I=r((()=>{u.current=!1,h(!0),m(!0)}),[u,h,m]),B=r((()=>{m(!1)}),[m]),x=r(((e={})=>E(e)),[E]),M=r(((e={})=>H(e)),[H]);return t((()=>{if(!n||!d||!a)return;let e=s.current,r=i.current,t=null,o=[];const l=()=>{var o;if(!t)return;const n=e?e.scrollHeight:null!==(o=null==r?void 0:r.getBoundingClientRect().height)&&void 0!==o?o:0,l=n>T.current;T.current=n,b(l),l&&(e?E({behavior:"auto"}):H({behavior:"auto"}))},c=new ResizeObserver(l);function u(){t&&(o.forEach((e=>c.unobserve(e))),o=[t,...Array.from(t.children)],o.forEach((e=>c.observe(e))))}const v=new MutationObserver((()=>{u(),l()}));let h=null;const m=()=>{var o;e=s.current,r=i.current;const n=null!=e?e:r;return!(!n||n===t)&&(v.disconnect(),c.disconnect(),t=n,T.current=e?e.scrollHeight:null!==(o=null==r?void 0:r.getBoundingClientRect().height)&&void 0!==o?o:0,u(),v.observe(t,{childList:!0,subtree:!0}),e?E({behavior:"auto"}):H({behavior:"auto"}),!0)};return m()||(h=new MutationObserver((()=>{m()&&(null==h||h.disconnect())})),h.observe(document.body,{childList:!0,subtree:!0})),()=>{null==h||h.disconnect(),v.disconnect(),c.disconnect()}}),[n,a,d,E,H,s,i,b]),t((()=>{a&&(u.current=!1)}),[u,a]),t((()=>{const e=s.current,r=null!=e?e:window,t=()=>{if(S.current)return;const r=(()=>{if(e)return e.scrollHeight-e.scrollTop-e.clientHeight<=32;const r=i.current;return!r||r.getBoundingClientRect().bottom-window.innerHeight<=32})();u.current=!r,h(r)},o=()=>{S.current&&(S.current=!1,g(!1),w.current&&(clearTimeout(w.current),w.current=null),e?e.scrollTo({top:e.scrollTop,behavior:"auto"}):window.scrollTo({top:window.scrollY,behavior:"auto"}))};return r.addEventListener("scroll",t,{passive:!0}),r.addEventListener("wheel",o,{passive:!0}),r.addEventListener("touchmove",o,{passive:!0}),()=>{r.removeEventListener("scroll",t),r.removeEventListener("wheel",o),r.removeEventListener("touchmove",o)}}),[u,s,i,h,g]),t((()=>()=>{p(),w.current&&clearTimeout(w.current)}),[p]),{scrollContainerRef:s,scrollTargetRef:i,isScrollIncreasing:v,scrollStartSession:I,scrollEndSession:B,scrollToBottom:x,scrollToTarget:M}};export{n as useScroll};
1
+ import{useRef as e,useCallback as r,useEffect as t}from"react";import{useScrollContext as o}from"./useScrollContext.js";const n=({auto:n=!1,debug:l,smooth:c=!0})=>{const{scrollContainerRef:s,scrollTargetRef:i,hasScrolledRef:u,isLocked:a,isScrollIncreasing:d,setIsLocked:h,setIsScrollSession:v,setIsScrolling:m,setIsScrollIncreasing:g}=o(),b=e(null),f=e(null),w=e(!1),T=e(0),S=r((()=>{null!==b.current&&(cancelAnimationFrame(b.current),b.current=null)}),[]),p=r((e=>{f.current&&clearTimeout(f.current),f.current=setTimeout((()=>{w.current=!1,m(!1)}),"smooth"===e?400:100)}),[m]),R=r(((e={})=>{var r;if(!e.force&&u.current)return;const t=null!==(r=e.behavior)&&void 0!==r?r:c?"smooth":"auto",o=s.current,n=i.current;if(o||n){if(w.current=!0,m(!0),o){const e=Math.max(0,o.scrollHeight-o.clientHeight);o.scrollTo({top:e,behavior:t})}else if(n){const e=n.getBoundingClientRect().bottom+window.scrollY,r=Math.max(0,e-window.innerHeight);window.scrollTo({top:r,behavior:t})}l&&console.log("[useScroll] scrolled to the active bottom"),p(t)}else l&&console.log("[useScroll] no scroll element detected")}),[l,p,u,s,i,m,c]),H=r(((e={})=>{S(),b.current=requestAnimationFrame((()=>{b.current=null,R(e)}))}),[S,R]),L=r(((e={})=>{var r;if(!e.force&&u.current)return;const t=i.current;if(!t)return void(l&&console.log("[useScroll] scroll target not detected"));const o=null!==(r=e.behavior)&&void 0!==r?r:c?"smooth":"auto",n=t.getBoundingClientRect().bottom+window.scrollY,s=Math.max(0,n-500);w.current=!0,m(!0),window.scrollTo({top:s,behavior:o}),l&&console.log("[useScroll] scrolled to the form response"),p(o)}),[l,p,u,i,m,c]),E=r(((e={})=>{S(),b.current=requestAnimationFrame((()=>{b.current=null,L(e)}))}),[S,L]),C=r((()=>{u.current=!1,h(!0),v(!0)}),[u,h,v]),x=r((()=>{v(!1)}),[v]),I=r(((e={})=>H(e)),[H]),M=r(((e={})=>E(e)),[E]);return t((()=>{if(!n||!a)return;let e=s.current,r=i.current,t=null,o=[];const l=()=>{var o;if(!t)return;const n=e?Math.max(0,e.scrollHeight-e.clientHeight):null!==(o=null==r?void 0:r.getBoundingClientRect().height)&&void 0!==o?o:0,l=n>T.current;T.current=n,g(l),l&&(e?H({behavior:"auto"}):E({behavior:"auto"}))},c=new ResizeObserver(l);function u(){t&&(o.forEach((e=>c.unobserve(e))),o=[t,...Array.from(t.children)],o.forEach((e=>c.observe(e))))}const d=new MutationObserver((()=>{u(),l()}));let h=null;const v=()=>{var o;e=s.current,r=i.current;const n=null!=e?e:r;return!(!n||n===t)&&(d.disconnect(),c.disconnect(),t=n,T.current=e?Math.max(0,e.scrollHeight-e.clientHeight):null!==(o=null==r?void 0:r.getBoundingClientRect().height)&&void 0!==o?o:0,u(),d.observe(t,{childList:!0,subtree:!0}),e?H({behavior:"auto"}):E({behavior:"auto"}),!0)};return v()||(h=new MutationObserver((()=>{v()&&(null==h||h.disconnect())})),h.observe(document.body,{childList:!0,subtree:!0})),()=>{null==h||h.disconnect(),d.disconnect(),c.disconnect()}}),[n,a,H,E,s,i,g]),t((()=>{a&&(u.current=!1)}),[u,a]),t((()=>{const e=s.current,r=null!=e?e:window,t=()=>{if(w.current)return;const r=(()=>{if(e)return e.scrollHeight-e.scrollTop-e.clientHeight<=32;const r=i.current;return!r||r.getBoundingClientRect().bottom-window.innerHeight<=32})();u.current=!r,h(r)},o=()=>{w.current&&(w.current=!1,m(!1),f.current&&(clearTimeout(f.current),f.current=null),e?e.scrollTo({top:e.scrollTop,behavior:"auto"}):window.scrollTo({top:window.scrollY,behavior:"auto"}))};return r.addEventListener("scroll",t,{passive:!0}),r.addEventListener("wheel",o,{passive:!0}),r.addEventListener("touchmove",o,{passive:!0}),()=>{r.removeEventListener("scroll",t),r.removeEventListener("wheel",o),r.removeEventListener("touchmove",o)}}),[u,s,i,h,m]),t((()=>()=>{S(),f.current&&clearTimeout(f.current)}),[S]),{scrollContainerRef:s,scrollTargetRef:i,isScrollIncreasing:d,scrollStartSession:C,scrollEndSession:x,scrollToBottom:I,scrollToTarget:M}};export{n as useScroll};
@@ -1 +1 @@
1
- import{__rest as e}from"../../../../_virtual/_tslib.js";import{jsxs as r,jsx as t}from"react/jsx-runtime";import{useState as n,useRef as i,useMemo as o,useEffect as s}from"react";import{usePickaxeMarkdownContext as a}from"./hooks/usePickaxeMarkdownContext.js";import{remarkSmartQuotes as l,rehypeCode as m,rehypeSanitize as p}from"./utils/custom-plugins.js";import c from"react-markdown";import d from"remark-gfm";import f from"remark-math";import h from"rehype-katex";import u from"rehype-raw";import{A as g}from"./Components/A/index.js";import x,{getFilePreviewInfo as b,shouldSuppressRichPreviewForUrl as j,shouldRenderFilePreview as w}from"./Components/A/FilePreview.js";import{P as C}from"./Components/P/index.js";import{Img as k}from"./Components/Img/index.js";import{Iframe as v}from"./Components/Iframe/index.js";import{Code as $}from"./Components/Code/index.js";import{H1 as y,H2 as O,H3 as P,H4 as S,H5 as R}from"./Components/Headings/index.js";import{Ol as N,Ul as A,Li as I}from"./Components/List/index.js";import{Table as L,Th as M,Tr as T,Td as H}from"./Components/Table/index.js";import{Hr as U,Br as _,Blockquote as B}from"./Components/Others/index.js";import{ActionCaption as J,ActionFinished as W,ActionError as q}from"./Components/Action/index.js";import{Artifact as z,ArtifactError as D}from"./Components/Artifact/index.js";import{Think as E}from"./Components/Others/Think.js";import F from"../../../../common/cn.js";const G=({className:G,style:K,children:Q,value:V,maxLines:X,maxChars:Y,multiLineBreaks:Z,onExpandClick:ee,filePreviewSeenRef:re,suppressedRichPreviewUrls:te})=>{const{colors:ne,rtl:ie,disableHtml:oe,disableJs:se,disableCss:ae}=a(),[le,me]=n({width:0,height:0}),[pe,ce]=n(null),de=i(null),fe=o((()=>{if(!V)return"";let e=V.trim();return e=e.replace(/<!--[\s\S]*?-->/g,""),e=e.replace(/\u200B/g,""),e=e.replace(/\\\((.*?)\\\)/g,"$$$ $1 $$$"),e=e.replace(/\\\[(.*?)\\\]/g,"$$$ $1 $$$"),e=e.replace(/<\/think>/g,"\n</think>"),Z&&(e=e.replace(/```[\s\S]*?```|(\n(?=\n))/g,((e,r)=>r?"\n\n<br/>\n":e))),e||""}),[V,Z]);s((()=>{if(Y)return void ce(fe.length>Y?fe.slice(0,Y)+'<span class="pxe-expand-btn">...</span>':null);if(!X)return void ce(null);if(!de.current||!fe||pe)return;const e=de.current,r=parseInt(window.getComputedStyle(e).lineHeight,10),t=X*r;if(!(le.height>t))return;const n=Math.floor(le.width/8),i=Math.floor(n*X);ce(fe.slice(0,i)+'<span class="pxe-expand-btn">...</span>')}),[fe,X,Y,le,pe]);const he=i(new Set);re||(he.current=new Set);const ue=null!=re?re:he,ge={h1:y,h2:O,h3:P,h4:S,h5:R,p:e=>t(C,Object.assign({},e,{suppressedRichPreviewUrls:te})),a:e=>t(g,Object.assign({},e,{filePreviewSeenRef:ue,suppressedRichPreviewUrls:te})),img:e=>{const r="string"==typeof e.src?e.src:"",n=b(r);return n&&!j(n.url,te)?w(n,ue)?t(x,{fileInfo:n,displayName:"string"==typeof e.alt?e.alt:void 0}):t("a",Object.assign({href:n.url,target:"_blank",rel:"noopener noreferrer",style:{color:ne.accent}},{children:e.alt||n.fileName})):t(k,Object.assign({},e))},iframe:v,code:$,ol:N,ul:A,li:I,table:L,th:M,tr:T,td:H,hr:U,br:_,blockquote:B,span:r=>{var{children:n}=r,i=e(r,["children"]);return"pxe-expand-btn"===i.className?t("span",Object.assign({},i,{style:Object.assign({display:"inline",fontWeight:500,color:ne.accent,marginLeft:".25rem",userSelect:"none"},ee&&{cursor:"pointer"})},ee&&{onClick:ee},{children:n})):t("span",Object.assign({},i,{children:n}))},"action-caption":J,"action-finished":W,"action-error":q,artifact:z,"artifact-error":D,think:E};s((()=>{if(!de.current)return;const e=new ResizeObserver((e=>{for(const r of e){const{width:e,height:t}=r.contentRect;me({width:e,height:t})}}));return e.observe(de.current),()=>{e.disconnect()}}),[]);const xe=pe||fe;return r("div",Object.assign({className:"pxe-markdown",ref:de,style:Object.assign({position:"relative",overflowWrap:"break-word",display:"grid",gridTemplateColumns:"repeat(1, minmax(0, 1fr))",gap:".625rem",width:"100%"},K)},ie&&{dir:"rtl"},{children:[t(c,Object.assign({className:F("pxe-prose",G),components:ge,remarkPlugins:[d,[f,{singleDollarTextMath:!1}],l],rehypePlugins:[m,h,...oe?[]:[u],[p,{disableJs:se,disableCss:ae}]]},{children:xe})),Q]}))};export{G as PickaxeMarkdownRenderer};
1
+ import{__rest as e}from"../../../../_virtual/_tslib.js";import{jsx as r,jsxs as n}from"react/jsx-runtime";import{useState as t,useRef as s,useMemo as i,useEffect as o}from"react";import{usePickaxeMarkdownContext as l}from"./hooks/usePickaxeMarkdownContext.js";import{remarkSmartQuotes as a,rehypeCode as c,rehypeSanitize as p}from"./utils/custom-plugins.js";import m from"react-markdown";import d from"remark-gfm";import f from"remark-math";import h from"rehype-katex";import u from"rehype-raw";import{A as g}from"./Components/A/index.js";import x,{getFilePreviewInfo as w,shouldSuppressRichPreviewForUrl as b,shouldRenderFilePreview as j}from"./Components/A/FilePreview.js";import{P as v}from"./Components/P/index.js";import{Img as C}from"./Components/Img/index.js";import{Iframe as k}from"./Components/Iframe/index.js";import{Code as P}from"./Components/Code/index.js";import{H1 as R,H2 as $,H3 as y,H4 as O,H5 as S}from"./Components/Headings/index.js";import{Ol as U,Ul as N,Li as A}from"./Components/List/index.js";import{Table as E,Th as I,Tr as L,Td as M}from"./Components/Table/index.js";import{Hr as T,Br as H,Blockquote as _}from"./Components/Others/index.js";import{ActionCaption as B,ActionFinished as J,ActionError as W}from"./Components/Action/index.js";import{Artifact as q,ArtifactError as z}from"./Components/Artifact/index.js";import{Think as D}from"./Components/Others/Think.js";import F from"../../../../common/cn.js";const G=({className:G,style:K,children:Q,value:V,maxLines:X,maxChars:Y,multiLineBreaks:Z,onExpandClick:ee,filePreviewSeenRef:re,suppressedRichPreviewUrls:ne})=>{const{colors:te,rtl:se,disableHtml:ie,disableJs:oe,disableCss:le}=l(),[ae,ce]=t({width:0,height:0}),[pe,me]=t(null),de=s(null),fe=i((()=>{if(!V)return"";let e=V.trim();return e=e.replace(/<!--[\s\S]*?-->/g,""),e=e.replace(/\u200B/g,""),e=e.replace(/\\\((.*?)\\\)/g,"$$$ $1 $$$"),e=e.replace(/\\\[(.*?)\\\]/g,"$$$ $1 $$$"),e=e.replace(/<\/think>/g,"\n</think>"),Z&&(e=e.replace(/```[\s\S]*?```|(\n(?=\n))/g,((e,r)=>r?"\n\n<br/>\n":e))),e||""}),[V,Z]);o((()=>{if(Y)return void me(fe.length>Y?fe.slice(0,Y)+'<span class="pxe-expand-btn">...</span>':null);if(!X)return void me(null);if(!de.current||!fe||pe)return;const e=de.current,r=parseInt(window.getComputedStyle(e).lineHeight,10),n=X*r;if(!(ae.height>n))return;const t=Math.floor(ae.width/8),s=Math.floor(t*X);me(fe.slice(0,s)+'<span class="pxe-expand-btn">...</span>')}),[fe,X,Y,ae,pe]);const he=s(new Set);re||(he.current=new Set);const ue=null!=re?re:he,ge=s({colors:te,onExpandClick:ee,filePreviewSeenRef:ue,suppressedRichPreviewUrls:ne});ge.current={colors:te,onExpandClick:ee,filePreviewSeenRef:ue,suppressedRichPreviewUrls:ne};const xe=i((()=>({h1:R,h2:$,h3:y,h4:O,h5:S,p:e=>r(v,Object.assign({},e,{suppressedRichPreviewUrls:ge.current.suppressedRichPreviewUrls})),a:e=>r(g,Object.assign({},e,{filePreviewSeenRef:ge.current.filePreviewSeenRef,suppressedRichPreviewUrls:ge.current.suppressedRichPreviewUrls})),img:e=>{const{colors:n,filePreviewSeenRef:t,suppressedRichPreviewUrls:s}=ge.current,i="string"==typeof e.src?e.src:"",o=w(i);return o&&!b(o.url,s)?j(o,t)?r(x,{fileInfo:o,displayName:"string"==typeof e.alt?e.alt:void 0}):r("a",Object.assign({href:o.url,target:"_blank",rel:"noopener noreferrer",style:{color:n.accent}},{children:e.alt||o.fileName})):r(C,Object.assign({},e))},iframe:k,code:P,ol:U,ul:N,li:A,table:E,th:I,tr:L,td:M,hr:T,br:H,blockquote:_,span:n=>{var{children:t}=n,s=e(n,["children"]);const{colors:i,onExpandClick:o}=ge.current;return"pxe-expand-btn"===s.className?r("span",Object.assign({},s,{style:Object.assign({display:"inline",fontWeight:500,color:i.accent,marginLeft:".25rem",userSelect:"none"},o&&{cursor:"pointer"})},o&&{onClick:o},{children:t})):r("span",Object.assign({},s,{children:t}))},"action-caption":B,"action-finished":J,"action-error":W,artifact:q,"artifact-error":z,think:D})),[]);o((()=>{if(!de.current)return;const e=new ResizeObserver((e=>{for(const r of e){const{width:e,height:n}=r.contentRect;ce({width:e,height:n})}}));return e.observe(de.current),()=>{e.disconnect()}}),[]);const we=pe||fe;return n("div",Object.assign({className:"pxe-markdown",ref:de,style:Object.assign({position:"relative",overflowWrap:"break-word",display:"grid",gridTemplateColumns:"repeat(1, minmax(0, 1fr))",gap:".625rem",width:"100%"},K)},se&&{dir:"rtl"},{children:[r(m,Object.assign({className:F("pxe-prose",G),components:xe,remarkPlugins:[d,[f,{singleDollarTextMath:!1}],a],rehypePlugins:[c,h,...ie?[]:[u],[p,{disableJs:oe,disableCss:le}]]},{children:we})),Q]}))};export{G as PickaxeMarkdownRenderer};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../_virtual/_tslib.js";import{useQuery as t}from"@tanstack/react-query";import{usePickaxeContext as s}from"./usePickaxeContext.js";import{useResponseContext as o}from"./useResponseContext.js";import{pickaxeApi2 as r}from"../../common/api/pickaxe.js";const i=e=>e.filter(((t,s)=>"user"!==t.role||!(e=>"assistant"===(null==e?void 0:e.role)&&"scheduled_followup"===e.area)(e[s+1]))),n=()=>{const{pickaxeId:n,sessionId:a,pickaxe:c}=s(),{isGenerating:d,isSwitchedToChat:l}=o(),m="string"==typeof(null==c?void 0:c.intromessage)&&0===c.intromessage.trim().length;return t({queryKey:["form",n,"chat",a],queryFn:()=>e(void 0,void 0,void 0,(function*(){return t=n,s=a,e(void 0,void 0,void 0,(function*(){const e=yield r.get(`/conversation?pickaxeId=${t}&sessionId=${s}`),o=e.data;if(200!==e.status)throw new Error("[_getChat] Failed to fetch chat conversation "+o);return o}));var t,s})),select:e=>{const t=m?e.messages.filter((e=>"intromessage"!==e.area)):e.messages;return Object.assign(Object.assign({},e),{messages:i(t)})},enabled:!!n&&!!a&&!l,refetchInterval:!!!(!n||!a||l||d)&&15e3,refetchIntervalInBackground:!1})};export{n as useConversation};
1
+ import{__awaiter as e}from"../../_virtual/_tslib.js";import{useQuery as t}from"@tanstack/react-query";import{usePickaxeContext as o}from"./usePickaxeContext.js";import{useResponseContext as s}from"./useResponseContext.js";import{pickaxeApi2 as r}from"../../common/api/pickaxe.js";import{normalizeHistoryMessages as i}from"../../common/chatMessages.js";const n=e=>e.filter(((t,o)=>"user"!==t.role||!(e=>"assistant"===(null==e?void 0:e.role)&&"scheduled_followup"===e.area)(e[o+1]))),a=()=>{const{pickaxeId:a,sessionId:c,pickaxe:m}=o(),{isGenerating:d,isSwitchedToChat:l}=s(),u="string"==typeof(null==m?void 0:m.intromessage)&&0===m.intromessage.trim().length;return t({queryKey:["form",a,"chat",c],queryFn:()=>e(void 0,void 0,void 0,(function*(){return t=a,o=c,e(void 0,void 0,void 0,(function*(){const e=yield r.get(`/conversation?pickaxeId=${t}&sessionId=${o}`),s=e.data;if(200!==e.status)throw new Error("[_getChat] Failed to fetch chat conversation "+s);return s}));var t,o})),select:e=>{const t=i(e.messages),o=u?t.filter((e=>"intromessage"!==e.area)):t;return Object.assign(Object.assign({},e),{messages:n(o)})},enabled:!!a&&!!c&&!l,refetchInterval:!!!(!a||!c||l||d)&&15e3,refetchIntervalInBackground:!1})};export{a as useConversation};
@@ -1,3 +1,5 @@
1
- import type { PickaxeHistoryMessage } from "../types/history";
1
+ import type { PickaxeHistoryMessage, PickaxeHistoryMessagePart } from "../types/history";
2
2
  import type { MemoryStoredChatMessage } from "../types/response";
3
+ export declare const normalizeMessageParts: (parts: unknown, fallbackContent?: unknown) => PickaxeHistoryMessagePart[];
4
+ export declare const normalizeHistoryMessages: (messages: unknown) => PickaxeHistoryMessage[];
3
5
  export declare const getUnpersistedMemoryMessages: (memoryMessages: MemoryStoredChatMessage[], persistedMessages: PickaxeHistoryMessage[]) => MemoryStoredChatMessage[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "6.11.0",
3
+ "version": "6.11.2",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",