@pickaxeproject/react 6.0.1-1 → 6.0.1-3
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});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../hooks/pickaxe/usePickaxeContext.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../hooks/pickaxe/usePickaxeContext.js"),o=require("../Addons/Auth/hooks/useAuthContext.js"),i=require("../../../hooks/pickaxe/useDimensionContext.js"),r=require("../Addons/Document/hooks/useDocument.js"),a=require("../../../hooks/studio/useStyleFontSize.js"),l=require("./History/index.js"),c=require("./Input.js"),u=require("../../Icons/attach-vertical.svg.js"),d=require("../../../common/cn.js"),m=require("../../../common/api/pickaxe.js"),f=require("lucide-react"),x=require("uuid"),h=require("../../Icons/trash-2.svg.js"),p=require("../../Icons/pencil.svg.js"),v=require("../../../hooks/pickaxe/useResponseContext.js");const j=({text:e,icon:s,className:n,onClick:o,colors:i})=>t.jsx("div",Object.assign({onClick:o,className:d.default("relative flex items-center justify-center px-4 py-3 h-full shrink-0 transition-all duration-200 rounded-full",n),style:{backgroundColor:(null==i?void 0:i.secondary)||"transparent",color:(null==i?void 0:i.secondaryText)||"inherit"}},{children:t.jsxs("div",Object.assign({className:"flex items-center gap-2 z-20"},{children:[s&&t.jsx("img",{src:s,alt:"",className:"h-5 w-5 rounded-full object-cover"}),t.jsx("p",Object.assign({className:"text-sm font-medium truncate max-w-[150px]"},{children:e}))]}))})),g=({text:n,className:o,onRename:i,onDelete:r,colors:a})=>{const[l,c]=s.useState(!1),[u,m]=s.useState(!1),[x,v]=s.useState(n),[j,g]=s.useState(!1),b=s.useRef(null),y=s.useRef(null);s.useEffect((()=>{u||v(n)}),[n,u]),s.useEffect((()=>{const e=e=>{y.current&&!y.current.contains(e.target)&&c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)}),[]);const w=()=>e.__awaiter(void 0,void 0,void 0,(function*(){x.trim()&&(g(!0),yield i(x),g(!1),m(!1))})),k=()=>{v(n),m(!1)};return t.jsxs("div",Object.assign({ref:y,className:"relative z-40 h-full"},{children:[t.jsx("div",Object.assign({className:d.default("relative flex items-center justify-center px-4 py-3 h-full shrink-0 rounded-full overflow-visible transition-all duration-200 cursor-pointer group",o),style:{backgroundColor:(null==a?void 0:a.secondary)||"transparent",color:(null==a?void 0:a.secondaryText)||"inherit"},onClick:e=>{e.stopPropagation(),u||l?l&&c(!1):c(!0)}},{children:u?t.jsxs("div",Object.assign({className:"flex items-center gap-2 z-20 min-w-[140px]",onClick:e=>e.stopPropagation(),style:{color:(null==a?void 0:a.secondaryText)||"inherit"}},{children:[t.jsx("input",{autoFocus:!0,type:"text",value:x,onChange:e=>v(e.target.value),onKeyDown:e=>{"Enter"===e.key&&w(),"Escape"===e.key&&k()},className:"bg-transparent border-b border-current text-sm font-medium focus:outline-none w-full min-w-[80px]",style:{color:"inherit"}}),t.jsx("button",Object.assign({onClick:w,disabled:j,className:"p-1 rounded"},{children:t.jsx(f.Check,{className:"h-4 w-4"})})),t.jsx("button",Object.assign({onClick:k,disabled:j,className:"p-1 rounded"},{children:t.jsx(f.X,{className:"h-4 w-4"})}))]})):t.jsxs("div",Object.assign({className:"flex items-center gap-2 z-20 max-w-[200px]"},{children:[t.jsx("p",Object.assign({className:"text-sm font-medium truncate"},{children:n})),t.jsx(f.MoreHorizontal,{className:d.default("h-4 w-4 opacity-50 group-hover:opacity-100 transition-opacity")})]}))})),l&&t.jsxs("div",Object.assign({className:"absolute top-full right-0 mt-2 w-48 shadow-xl z-50 rounded-[16px] overflow-hidden animate-in fade-in zoom-in-95 duration-100",ref:b,style:{backgroundColor:(null==a?void 0:a.secondary)||"transparent",color:(null==a?void 0:a.secondaryText)||"inherit"}},{children:[t.jsxs("button",Object.assign({onClick:e=>{e.stopPropagation(),c(!1),m(!0)},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-colors"},{children:[t.jsx(p.default,{className:"h-4 w-4"}),t.jsx("span",Object.assign({className:"font-medium text-sm"},{children:"Rename chat"}))]})),t.jsxs("button",Object.assign({onClick:e=>{e.stopPropagation(),c(!1),r()},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-colors"},{children:[t.jsx(h.default,{className:"h-4 w-4"}),t.jsx("span",Object.assign({className:"font-medium text-sm"},{children:"Delete chat"}))]}))]}))]}))};exports.default=()=>{const{deploymentType:f,isNewChat:h,setIsNewChat:p,sessionId:b,setSessionId:y,pickaxeId:w,sender:k,colors:N,pickaxe:C,isEmbed:O}=n.usePickaxeContext(),{isSent:D}=o.useAuthContext(),{width:_,height:I,setDimension:S}=i.useDimensionContext(),{setDocuments:q,onFileUpload:E}=r.useDocument(),{isGenerating:P,messages:z}=v.useResponseContext(),F=a.useStyleFontSize(),[R,A]=s.useState(0),[T,H]=s.useState(!1),[L,M]=s.useState(!1),B=s.useRef(null),G=s.useRef(null),K=s.useRef(0),[U,X]=s.useState(null),[J,Q]=s.useState(!1),V="chat-input"===f&&h&&!D;s.useEffect((()=>()=>{q([])}),[]);const W=s.useCallback((()=>{if(!w||!k)return;const t=(s=0)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;try{const t=yield m.default.post("/get_pickaxe_conversation",{sessionId:b,userId:k});if(t.data&&t.data.success){const e=t.data.title;if(e&&"Conversation Title"!==e)return void Z(e)}else console.error("Failed to load conversation:",null===(e=t.data)||void 0===e?void 0:e.error)}catch(e){console.error("Error fetching conversation:",e)}s<20&&setTimeout((()=>t(s+1)),3e3)}));t()}),[w,k,b]);s.useEffect((()=>{P||h||!b||W()}),[P,h,b,W]),s.useEffect((()=>{if(!B.current)return;const e=new ResizeObserver((e=>{for(const t of e){const{width:e,height:s}=t.contentRect;S(parseInt(e.toFixed(0)),parseInt(s.toFixed(0)))}}));return e.observe(B.current),()=>{e.disconnect()}}),[B.current]);const[Y,Z]=s.useState("New Chat"),$=(null==C?void 0:C.formtitle)||"Pickaxe",ee=(null==C?void 0:C.coverphoto)||void 0,te=!V&&!O&&z.filter((e=>"user"===e.role)).length>0;return t.jsxs("div",Object.assign({ref:B,className:"relative flex h-full w-full flex-col items-center overflow-hidden",onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),K.current+=1,e.dataTransfer.items&&e.dataTransfer.items.length>0&&M(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),K.current-=1,0===K.current&&M(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation()},onDrop:t=>e.__awaiter(void 0,void 0,void 0,(function*(){t.preventDefault(),t.stopPropagation(),M(!1),K.current=0;const e=Array.from(t.dataTransfer.files||[]);e.length>0&&(p(!1),yield E(e))}))},{children:[L&&t.jsxs("div",Object.assign({className:"absolute inset-0 z-50 flex flex-col items-center justify-center rounded-lg bg-white/80 backdrop-blur-sm transition-all duration-300"},{children:[t.jsx("div",Object.assign({className:"flex h-24 w-24 items-center justify-center rounded-full bg-white shadow-lg animate-bounce text-black"},{children:t.jsx(u.default,{className:"h-10 w-10"})})),t.jsx("h3",Object.assign({className:d.default(F.h3,"mt-6 font-semibold text-c-primary text-black")},{children:"Drop files to upload"})),t.jsx("p",Object.assign({className:d.default(F.b2,"mt-2 opacity-60 text-black")},{children:"Add anything to the conversation"}))]})),V?t.jsx(c.default,{}):t.jsxs(t.Fragment,{children:[t.jsxs("div",Object.assign({className:d.default("flex flex-col w-full items-center h-full relative z-0",te?"pt-6":"")},{children:[te&&t.jsxs("div",Object.assign({className:"w-full max-w-3xl px-4 md:px-0 flex justify-start z-30 mb-4 animate-in fade-in slide-in-from-top-4 duration-500 gap-2"},{children:[t.jsx(j,{text:$,icon:ee,colors:N}),h||"New Chat"===Y?t.jsx(j,{text:Y,colors:N}):t.jsx(g,{text:Y,sessionId:b,colors:N,onRename:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(b)try{yield m.default.post("/edit_conversation_name",{sessionId:b,name:t,userId:k}),Z(t)}catch(e){console.error("Error renaming chat:",e),alert("Failed to rename chat.")}})),onDelete:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(b&&window.confirm("Are you sure you want to delete this conversation?"))try{yield m.default.post("/delete_pickaxe_conversation",{sessionId:b,userId:k}),p(!0),y(x.v4()),Z("New Chat")}catch(e){console.error("Error deleting chat:",e),alert("Failed to delete chat.")}}))})]})),t.jsx(l.default,{additionalScrollHeight:R,isForceHideInfo:I<=545||_<=350||T,isInputFocused:T,onSubmit:t=>e.__awaiter(void 0,void 0,void 0,(function*(){G.current&&G.current.onSubmit(t)})),smitheryAuthData:U,resubmitPrompt:()=>{X(null),Q(!0)}})]})),t.jsx(c.default,{ref:G,onFocus:()=>H(!0),onBlur:()=>H(!1),onInputHeightChange:A,initSmitheryAuthData:e=>X(e),resubmitPrompt:J})]})]}))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"../../../_virtual/_tslib.js";import{jsxs as t,jsx as o,Fragment as n}from"react/jsx-runtime";import{useState as s,useRef as
|
|
1
|
+
import{__awaiter as e}from"../../../_virtual/_tslib.js";import{jsxs as t,jsx as o,Fragment as n}from"react/jsx-runtime";import{useState as s,useRef as i,useEffect as r,useCallback as a}from"react";import{usePickaxeContext as l}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as c}from"../Addons/Auth/hooks/useAuthContext.js";import{useDimensionContext as d}from"../../../hooks/pickaxe/useDimensionContext.js";import{useDocument as m}from"../Addons/Document/hooks/useDocument.js";import{useStyleFontSize as u}from"../../../hooks/studio/useStyleFontSize.js";import p from"./History/index.js";import f from"./Input.js";import h from"../../Icons/attach-vertical.svg.js";import v from"../../../common/cn.js";import g from"../../../common/api/pickaxe.js";import{Check as x,X as b,MoreHorizontal as y}from"lucide-react";import{v4 as j}from"uuid";import w from"../../Icons/trash-2.svg.js";import N from"../../Icons/pencil.svg.js";import{useResponseContext as k}from"../../../hooks/pickaxe/useResponseContext.js";const O=({text:e,icon:n,className:s,onClick:i,colors:r})=>o("div",Object.assign({onClick:i,className:v("relative flex items-center justify-center px-4 py-3 h-full shrink-0 transition-all duration-200 rounded-full",s),style:{backgroundColor:(null==r?void 0:r.secondary)||"transparent",color:(null==r?void 0:r.secondaryText)||"inherit"}},{children:t("div",Object.assign({className:"flex items-center gap-2 z-20"},{children:[n&&o("img",{src:n,alt:"",className:"h-5 w-5 rounded-full object-cover"}),o("p",Object.assign({className:"text-sm font-medium truncate max-w-[150px]"},{children:e}))]}))})),C=({text:n,className:a,onRename:l,onDelete:c,colors:d})=>{const[m,u]=s(!1),[p,f]=s(!1),[h,g]=s(n),[j,k]=s(!1),O=i(null),C=i(null);r((()=>{p||g(n)}),[n,p]),r((()=>{const e=e=>{C.current&&!C.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)}),[]);const D=()=>e(void 0,void 0,void 0,(function*(){h.trim()&&(k(!0),yield l(h),k(!1),f(!1))})),I=()=>{g(n),f(!1)};return t("div",Object.assign({ref:C,className:"relative z-40 h-full"},{children:[o("div",Object.assign({className:v("relative flex items-center justify-center px-4 py-3 h-full shrink-0 rounded-full overflow-visible transition-all duration-200 cursor-pointer group",a),style:{backgroundColor:(null==d?void 0:d.secondary)||"transparent",color:(null==d?void 0:d.secondaryText)||"inherit"},onClick:e=>{e.stopPropagation(),p||m?m&&u(!1):u(!0)}},{children:t("div",p?Object.assign({className:"flex items-center gap-2 z-20 min-w-[140px]",onClick:e=>e.stopPropagation(),style:{color:(null==d?void 0:d.secondaryText)||"inherit"}},{children:[o("input",{autoFocus:!0,type:"text",value:h,onChange:e=>g(e.target.value),onKeyDown:e=>{"Enter"===e.key&&D(),"Escape"===e.key&&I()},className:"bg-transparent border-b border-current text-sm font-medium focus:outline-none w-full min-w-[80px]",style:{color:"inherit"}}),o("button",Object.assign({onClick:D,disabled:j,className:"p-1 rounded"},{children:o(x,{className:"h-4 w-4"})})),o("button",Object.assign({onClick:I,disabled:j,className:"p-1 rounded"},{children:o(b,{className:"h-4 w-4"})}))]}):Object.assign({className:"flex items-center gap-2 z-20 max-w-[200px]"},{children:[o("p",Object.assign({className:"text-sm font-medium truncate"},{children:n})),o(y,{className:v("h-4 w-4 opacity-50 group-hover:opacity-100 transition-opacity")})]}))})),m&&t("div",Object.assign({className:"absolute top-full right-0 mt-2 w-48 shadow-xl z-50 rounded-[16px] overflow-hidden animate-in fade-in zoom-in-95 duration-100",ref:O,style:{backgroundColor:(null==d?void 0:d.secondary)||"transparent",color:(null==d?void 0:d.secondaryText)||"inherit"}},{children:[t("button",Object.assign({onClick:e=>{e.stopPropagation(),u(!1),f(!0)},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-colors"},{children:[o(N,{className:"h-4 w-4"}),o("span",Object.assign({className:"font-medium text-sm"},{children:"Rename chat"}))]})),t("button",Object.assign({onClick:e=>{e.stopPropagation(),u(!1),c()},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-colors"},{children:[o(w,{className:"h-4 w-4"}),o("span",Object.assign({className:"font-medium text-sm"},{children:"Delete chat"}))]}))]}))]}))},D=()=>{const{deploymentType:x,isNewChat:b,setIsNewChat:y,sessionId:w,setSessionId:N,pickaxeId:D,sender:I,colors:P,pickaxe:z,isEmbed:F}=l(),{isSent:T}=c(),{width:A,height:E,setDimension:S}=d(),{setDocuments:_,onFileUpload:R}=m(),{isGenerating:H,messages:L}=k(),B=u(),[G,K]=s(0),[U,q]=s(!1),[J,M]=s(!1),Q=i(null),V=i(null),W=i(0),[X,Y]=s(null),[Z,$]=s(!1),ee="chat-input"===x&&b&&!T;r((()=>()=>{_([])}),[]);const te=a((()=>{if(!D||!I)return;const t=(o=0)=>e(void 0,void 0,void 0,(function*(){var e;try{const t=yield g.post("/get_pickaxe_conversation",{sessionId:w,userId:I});if(t.data&&t.data.success){const e=t.data.title;if(e&&"Conversation Title"!==e)return void ne(e)}else console.error("Failed to load conversation:",null===(e=t.data)||void 0===e?void 0:e.error)}catch(e){console.error("Error fetching conversation:",e)}o<20&&setTimeout((()=>t(o+1)),3e3)}));t()}),[D,I,w]);r((()=>{H||b||!w||te()}),[H,b,w,te]),r((()=>{if(!Q.current)return;const e=new ResizeObserver((e=>{for(const t of e){const{width:e,height:o}=t.contentRect;S(parseInt(e.toFixed(0)),parseInt(o.toFixed(0)))}}));return e.observe(Q.current),()=>{e.disconnect()}}),[Q.current]);const[oe,ne]=s("New Chat"),se=(null==z?void 0:z.formtitle)||"Pickaxe",ie=(null==z?void 0:z.coverphoto)||void 0,re=!ee&&!F&&L.filter((e=>"user"===e.role)).length>0;return t("div",Object.assign({ref:Q,className:"relative flex h-full w-full flex-col items-center overflow-hidden",onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),W.current+=1,e.dataTransfer.items&&e.dataTransfer.items.length>0&&M(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),W.current-=1,0===W.current&&M(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation()},onDrop:t=>e(void 0,void 0,void 0,(function*(){t.preventDefault(),t.stopPropagation(),M(!1),W.current=0;const e=Array.from(t.dataTransfer.files||[]);e.length>0&&(y(!1),yield R(e))}))},{children:[J&&t("div",Object.assign({className:"absolute inset-0 z-50 flex flex-col items-center justify-center rounded-lg bg-white/80 backdrop-blur-sm transition-all duration-300"},{children:[o("div",Object.assign({className:"flex h-24 w-24 items-center justify-center rounded-full bg-white shadow-lg animate-bounce text-black"},{children:o(h,{className:"h-10 w-10"})})),o("h3",Object.assign({className:v(B.h3,"mt-6 font-semibold text-c-primary text-black")},{children:"Drop files to upload"})),o("p",Object.assign({className:v(B.b2,"mt-2 opacity-60 text-black")},{children:"Add anything to the conversation"}))]})),ee?o(f,{}):t(n,{children:[t("div",Object.assign({className:v("flex flex-col w-full items-center h-full relative z-0",re?"pt-6":"")},{children:[re&&t("div",Object.assign({className:"w-full max-w-3xl px-4 md:px-0 flex justify-start z-30 mb-4 animate-in fade-in slide-in-from-top-4 duration-500 gap-2"},{children:[o(O,{text:se,icon:ie,colors:P}),b||"New Chat"===oe?o(O,{text:oe,colors:P}):o(C,{text:oe,sessionId:w,colors:P,onRename:t=>e(void 0,void 0,void 0,(function*(){if(w)try{yield g.post("/edit_conversation_name",{sessionId:w,name:t,userId:I}),ne(t)}catch(e){console.error("Error renaming chat:",e),alert("Failed to rename chat.")}})),onDelete:()=>e(void 0,void 0,void 0,(function*(){if(w&&window.confirm("Are you sure you want to delete this conversation?"))try{yield g.post("/delete_pickaxe_conversation",{sessionId:w,userId:I}),y(!0),N(j()),ne("New Chat")}catch(e){console.error("Error deleting chat:",e),alert("Failed to delete chat.")}}))})]})),o(p,{additionalScrollHeight:G,isForceHideInfo:E<=545||A<=350||U,isInputFocused:U,onSubmit:t=>e(void 0,void 0,void 0,(function*(){V.current&&V.current.onSubmit(t)})),smitheryAuthData:X,resubmitPrompt:()=>{Y(null),$(!0)}})]})),o(f,{ref:V,onFocus:()=>q(!0),onBlur:()=>q(!1),onInputHeightChange:K,initSmitheryAuthData:e=>Y(e),resubmitPrompt:Z})]})]}))};export{D as default};
|