@topthink/chat 1.1.6 → 1.1.8
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/es/index.js
CHANGED
|
@@ -647,7 +647,7 @@ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{Lightbox
|
|
|
647
647
|
margin-bottom: .5rem;
|
|
648
648
|
display: flex;
|
|
649
649
|
padding: 0 .125rem;
|
|
650
|
-
`;var vt=q((function(r,n){let{suggestion:i,fileTypes:o,speech:a,scrollRef:s,variables:c,minRows:d,toolbar:u,disabled:p,autoFocus:g}=r;const
|
|
650
|
+
`;var vt=q((function(r,n){let{suggestion:i,fileTypes:o,speech:a,scrollRef:s,variables:c,minRows:d,toolbar:u,disabled:p,autoFocus:g,placeholder:f="请输入你的问题, Enter+Shift换行, Enter发送"}=r;const b=E(null),x=E(null),y=E(null),[w,k]=C(""),[j,N]=C(""),[M,q]=v([]),[A,F]=C(!1),R=o&&o.length>0?o:Je,{messages:D,loading:I,request:T}=de(),{send:P}=function(e){let{suggestion:t,onSuccess:r}=e;const{setMessages:n,setSuggestions:i,setLoading:o,conversationId:a,setConversationId:s,request:l}=de(),c=E(null),d=$((async()=>{c.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:a},signal:c.current.signal};const t=await l(e);i(t)}catch{}finally{c.current=null}}),[a,l]),u=$((async function(e){if("string"==typeof e){for(var u=arguments.length,m=new Array(u>1?u-1:0),p=1;p<u;p++)m[p-1]=arguments[p];e={query:e,...m}}const{query:g,files:f=[],variables:b={},quote:v}=e;if(g||f.length>0){c.current&&c.current.abort(),o(!0),i([]),n((e=>{e.push({query:g,quote:v,files:f,variables:b,chunks:[],loading:!0})}));try{let e={method:"post",data:{query:g,quote:v,files:f,variables:b,conversation:a},onMessage:e=>{if(e.data)if("[DONE]"!=e.data)try{const t=JSON.parse(e.data);t.conversation?s(t.conversation):n((e=>{const r=e[e.length-1];if(r.chunks)if(t.chunks){const e=t.chunks.index;if(r.chunks[e]||(r.chunks[e]={content:"",tools:[]}),t.chunks.error)r.chunks[e].error=t.chunks.error;else if(t.chunks.tools){const n=t.chunks.tools.index;"response"in t.chunks.tools?(r.chunks[e].tools[n].response=t.chunks.tools.response,r.chunks[e].tools[n].error=t.chunks.tools.error,r.chunks[e].tools[n].content=t.chunks.tools.content):r.chunks[e].tools[n]={name:t.chunks.tools.name,title:t.chunks.tools.title,arguments:t.chunks.tools.arguments}}else t.chunks.content&&(r.chunks[e].content+=t.chunks.content)}else t.stats&&(r.stats=t.stats)}))}catch(e){console.error(e)}else n((e=>{e[e.length-1].loading=!1}))}};await l(e),t&&d()}catch(e){let t="未知错误";h(e)&&(t=401==e.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof e.errors?e.errors:Object.values(e.errors).join("\n")),n((e=>{const r=e[e.length-1];r.chunks&&(0===r.chunks.length?r.chunks=[{content:`[${t}]`,tools:[]}]:r.chunks[r.chunks.length-1].content=`[${t}]`),r.loading=!1}))}o(!1),r?.()}}),[a,l]);return{send:u}}({suggestion:i,onSuccess(){requestAnimationFrame((()=>{b.current?.focus()}))}}),[L,B]=C();z((()=>{const e=D.filter((e=>!!e.query));B(e.at(-1)?.variables)}),[D]),z((()=>{!o&&M.length>0&&q([])}),[o]),z((()=>{const e=s.current;if(e&&P){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};c&&(t.variables={...L,...c.values}),P(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[c,L]);const O=$((e=>{let{target:t}=e;if(t.files){const e=Array.from(t.files).filter((e=>!!R.includes(W.extname(e.name))&&(!(e.size>20971520)&&e))).slice(0,6-M.length);q((t=>{t.push(...e.map((e=>({file:e}))))})),e.forEach((async e=>{try{const t=new FormData;t.set("file",e);const r=await T({method:"POST",url:"/upload",data:t});q((t=>{const n=t.find((t=>t.file===e));n&&(n.path=r.path)}))}catch(t){const r=h(t)?t.message:"unknown error";q((t=>{const n=t.find((t=>t.file===e));n&&(n.error=r)}))}}))}t.value=""}),[M,R]),_=M.flatMap((e=>{let{file:t,path:r}=e;return r?[{name:t.name,size:t.size,path:r}]:[]})),U=$((()=>{if(w||_.length>0){const e={query:w,files:_};c&&(e.variables={...L,...c.values}),j&&(e.quote=j),P(e),k(""),N(""),q([]),y.current?.stop(!0)}}),[w,_,c,L,j]);if(S(n,(()=>({setQuery:k,setQuote:N,send:P,focus(){b.current?.focus()}}))),c){const t=c.config.filter((e=>!(e.key in(c.values||{})))),r=function(e){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!!e&&t.every((t=>{const n=!t.required||e?.[t.key];return!n&&r&&m.error("请完善必填信息"),n}))};if(t.length>0&&!r(L))return e(yt,{children:e(xt,{children:e(Ve,{values:L,variables:t,onSubmit:e=>{let{formData:t}=e;if(r(t,!0))return B(t),!0}})})})}return t(Ct,{children:[u&&e(gt,{children:u}),t(Nt,{$focused:A&&!I,children:[M.length>0&&e(kt,{children:M.map(((t,r)=>{let{file:n,error:i,path:o}=t;const a=void 0===i&&void 0===o;return e(wt,{name:n.name,size:n.size,error:i,loading:a,onRemove:()=>{q((e=>{const t=e.findIndex((e=>e.file===n));-1!==t&&e.splice(t,1)}))}},r)}))}),!!j&&t(jt,{children:[e("i",{className:"bi bi-quote"}),e("p",{children:j}),e(Q,{onClick:()=>N("")})]}),t(Et,{children:[e(Y,{disabled:I||p,ref:b,placeholder:f,minRows:d,maxRows:5,value:w,onChange:e=>k(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),U())},autoFocus:g,onFocus:()=>F(!0),onBlur:()=>F(!1)}),o&&e(l,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:t(Ye,{disabled:M.length>=6,onClick:()=>x.current?.click(),children:[e("input",{onChange:O,multiple:!0,accept:R.join(","),ref:x,type:"file",hidden:!0}),e("i",{className:"bi bi-file-earmark-arrow-up"})]})}),a&&e(et,{ref:y,model:a.model,onResult:e=>{b.current?.focus(),k((t=>t+e+" "))}}),e(Ye,{className:"text-primary",disabled:!w&&0===_.length,onClick:e=>{e.preventDefault(),U()},children:e("i",{className:"bi bi-send-fill"})})]})]})]})}));const xt=i.div`
|
|
651
651
|
border-radius: var(--bs-border-radius-lg);
|
|
652
652
|
box-shadow: var(--bs-box-shadow-sm);
|
|
653
653
|
margin: 1rem;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topthink/chat",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prebuild": "rimraf es types",
|
|
6
6
|
"build": "rollup -c --environment NODE_ENV:production",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
},
|
|
66
66
|
"author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
|
|
67
67
|
"license": "MIT",
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "173b3ed17255994bfc2e9cbabf93b7323ebe9c18"
|
|
69
69
|
}
|
|
@@ -14,6 +14,7 @@ interface Props {
|
|
|
14
14
|
scrollRef: MutableRefObject<HTMLDivElement | null>;
|
|
15
15
|
toolbar?: ReactNode | true;
|
|
16
16
|
disabled?: boolean;
|
|
17
|
+
placeholder?: string;
|
|
17
18
|
autoFocus?: boolean;
|
|
18
19
|
}
|
|
19
20
|
declare const _default: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<Input>>;
|