@topthink/chat 1.1.42 → 1.2.1

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.
@@ -0,0 +1 @@
1
+ import*as h from"react";var l,t,e;function v(){return v=Object.assign?Object.assign.bind():function(h){for(var l=1;l<arguments.length;l++){var t=arguments[l];for(var e in t)({}).hasOwnProperty.call(t,e)&&(h[e]=t[e])}return h},v.apply(null,arguments)}const c=c=>h.createElement("svg",v({xmlns:"http://www.w3.org/2000/svg",width:200,height:200,className:"html_svg__icon",viewBox:"0 0 1024 1024"},c),l||(l=h.createElement("path",{fill:"#8C8C8C",d:"m590.222 73.956 268.8 268.299v533.834c0 37.7-30.566 68.267-68.266 68.267H233.244c-37.7 0-68.266-30.567-68.266-68.267V142.222c0-37.7 30.566-68.266 68.266-68.266zM578.458 102.4H233.244a39.82 39.82 0 0 0-39.799 38.457l-.023 1.365V876.09a39.82 39.82 0 0 0 38.457 39.8l1.365.022h557.512a39.82 39.82 0 0 0 39.799-38.457l.023-1.365V354.054z"})),t||(t=h.createElement("path",{fill:"#8C8C8C",d:"M854.756 370.648H639.613c-45.528 0-82.551-36.431-83.507-81.738l-.017-1.792V73.956h28.444v213.162c0 29.895 23.82 54.232 53.516 55.063l1.564.023h215.143zM85.333 489.244h853.334q28.444 0 28.444 28.445v284.444q0 28.445-28.444 28.445H85.333q-28.444 0-28.444-28.445V517.69q0-28.445 28.444-28.445"})),e||(e=h.createElement("path",{fill:"#FFF",d:"M207.2 756.622v-78.336h62.726v78.336h45.568v-190.72h-45.568v72.704h-62.731v-72.704h-45.818v190.72zm235.014 0V604.046h51.712v-38.144H344.934v38.144h51.45v152.576zm122.112 0v-65.28c0-18.944-3.584-47.36-5.888-66.048h1.024l15.36 45.568 25.85 69.632h25.089l25.6-69.632 15.872-45.568h1.28c-2.56 18.688-6.144 47.104-6.144 66.048v65.28h41.728v-190.72h-49.664l-29.184 82.432c-3.584 11.008-6.656 23.04-10.49 34.56h-1.28c-3.585-11.52-6.657-23.552-10.497-34.56l-30.208-82.432h-49.413v190.72h40.96zm303.61 0v-38.4h-74.24v-152.32h-45.818v190.72z"})));var a="data:image/svg+xml,%3csvg t='1767873452096' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='1778' width='200' height='200'%3e%3cpath d='M590.222222 73.955556L859.022222 342.254933V876.088889c0 37.700267-30.5664 68.266667-68.266666 68.266667H233.244444c-37.700267 0-68.266667-30.5664-68.266666-68.266667V142.222222c0-37.700267 30.5664-68.266667 68.266666-68.266666h356.977778z m-11.764622 28.444444H233.244444a39.822222 39.822222 0 0 0-39.799466 38.456889L193.422222 142.222222v733.866667a39.822222 39.822222 0 0 0 38.456889 39.799467L233.244444 915.911111h557.511112a39.822222 39.822222 0 0 0 39.799466-38.456889L830.577778 876.088889V354.053689L578.4576 102.4z' fill='%238C8C8C' p-id='1779'%3e%3c/path%3e%3cpath d='M854.755556 370.648178h-215.1424c-45.528178 0-82.551467-36.431644-83.5072-81.737956l-0.017067-1.792V73.955556h28.444444v213.162666c0 29.895111 23.819378 54.232178 53.515378 55.062756l1.564445 0.022755h215.1424v28.444445z' fill='%238C8C8C' p-id='1780'%3e%3c/path%3e%3cpath d='M56.888889 489.244444m28.444444 0l853.333334 0q28.444444 0 28.444444 28.444445l0 284.444444q0 28.444444-28.444444 28.444445l-853.333334 0q-28.444444 0-28.444444-28.444445l0-284.444444q0-28.444444 28.444444-28.444445Z' fill='%238C8C8C' p-id='1781'%3e%3c/path%3e%3cpath d='M207.200711 756.622222v-78.336h62.725689V756.622222h45.568V565.902222h-45.568v72.704H207.195022v-72.704h-45.818311V756.622222zM442.2144 756.622222v-152.576h51.712v-38.144h-148.992v38.144h51.450311V756.622222zM564.3264 756.622222v-65.28c0-18.944-3.584-47.36-5.888-66.048h1.024l15.36 45.568 25.850311 69.632h25.088l25.6-69.632 15.872-45.568h1.28c-2.56 18.688-6.144 47.104-6.144 66.048V756.622222h41.728V565.902222h-49.664l-29.184 82.432c-3.584 11.008-6.656 23.04-10.490311 34.56h-1.28c-3.584-11.52-6.656-23.552-10.496-34.56l-30.208-82.432h-49.413689V756.622222h40.96zM867.936711 756.622222v-38.4h-74.24V565.902222h-45.818311V756.622222z' fill='white' p-id='1782'%3e%3c/path%3e%3c/svg%3e";export{c as ReactComponent,a as default};
package/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as n,css as i,formatSize as o,Tooltip as s,useAsync as a,isRequestError as l,Form as c,Toast as d,InfiniteScroller as h,Offcanvas as u,dayjs as m,RequestButton as p,useImmer as g,getAbsoluteUrl as b,Lightbox as f,Clipboard as v,isImageUrl as x,request as y}from"@topthink/components";import*as w from"react";import{createContext as k,useContext as E,useEffect as N,useState as j,useRef as $,useCallback as C,forwardRef as M,useMemo as q,useImperativeHandle as z,Fragment as S,memo as F}from"react";import R from"react-textarea-autosize";import*as A from"path";import I from"path";import{Spinner as D,Badge as L,CloseButton as P,OverlayTrigger as T,Popover as O}from"react-bootstrap";import B from"eventemitter3";import _ from"lodash/isEqual";import{toString as U}from"hast-util-to-string";import H from"react-markdown";import"katex/dist/katex.min.css";import J from"rehype-highlight";import K from"rehype-katex";import Q from"remark-breaks";import W from"remark-gfm";import X from"remark-math";import{codes as V,types as Y}from"micromark-util-symbol";import{markdownLineEnding as G}from"micromark-util-character";import{createPortal as Z}from"react-dom";import ee from"use-resize-observer";const te=function({ext:e}){const{result:r}=a(async e=>(await function(e){switch(e){case"../../images/file/docx.svg":return import("./docx-2LwnwWwv.js");case"../../images/file/jpg.svg":return import("./jpg-muicsKjX.js");case"../../images/file/md.svg":return import("./md-DRS7QmE8.js");case"../../images/file/pdf.svg":return import("./pdf-CWBi2u4Z.js");case"../../images/file/png.svg":return import("./png-DNwbFeJk.js");case"../../images/file/pptx.svg":return import("./pptx-Bv4V_F_3.js");case"../../images/file/txt.svg":return import("./txt-CsqmEKjF.js");case"../../images/file/xlsx.svg":return import("./xlsx-CmkshfKZ.js");default:return new Promise(function(t,r){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e)))})}}(`../../images/file/${e}.svg`)).default,[e]);return r?t("img",{width:30,height:30,src:r}):null};function re({className:r,name:n,size:i,loading:a,error:l,onRemove:c}){const d=I.extname(n).substring(1),h=e(se,{className:r,$error:!!l,children:[e(oe,{children:[t(te,{ext:d}),a&&t(D,{variant:"primary"})]}),e(ie,{children:[t("h4",{children:n}),t("p",{children:o(i,1)})]}),c&&t(ne,{onClick:e=>{e.preventDefault(),c()},children:t("i",{className:"bi bi-trash3"})})]});return l?t(s,{placement:"top",tooltip:l,children:h}):h}const ne=n.div`
1
+ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{styled as n,css as i,formatSize as o,Tooltip as s,useAsync as a,isRequestError as l,Form as c,Toast as d,InfiniteScroller as m,useDebounce as u,Offcanvas as h,ModalForm as p,RequestButton as g,Loader as f,useImmer as b,createGlobalStyle as v,getAbsoluteUrl as x,Lightbox as y,Clipboard as k,Button as w,isImageUrl as E,request as N}from"@topthink/components";import*as j from"react";import{createContext as $,useContext as C,useEffect as M,useState as S,useRef as q,useCallback as R,forwardRef as z,useMemo as I,useImperativeHandle as F,Fragment as A,memo as D}from"react";import*as L from"path";import T from"path";import{Spinner as P,Badge as O,Dropdown as _,FormControl as B,CloseButton as U,OverlayTrigger as H,Popover as J}from"react-bootstrap";import Q from"eventemitter3";import{Editor as W,Delta as X,SKILL_KEY as G,VARS_KEY as K,SEL_VALUE_KEY as V,SEL_KEY as Y,EditableInputPlugin as Z,SelectorInputPlugin as ee,SkillInputPlugin as te,BlockKit as re,Editable as ne,VARS_VALUE_KEY as ie}from"@block-kit/variable";import"@block-kit/variable/dist/style/index.css";import oe from"lodash/isEqual";import{toString as se}from"hast-util-to-string";import ae from"react-markdown";import"katex/dist/katex.min.css";import le from"rehype-highlight";import ce from"rehype-katex";import de from"remark-breaks";import me from"remark-gfm";import ue from"remark-math";import{codes as he,types as pe}from"micromark-util-symbol";import{markdownLineEnding as ge}from"micromark-util-character";import{createPortal as fe}from"react-dom";import be from"use-resize-observer";import{unified as ve}from"unified";import xe from"rehype-stringify";import ye from"remark-parse";import ke from"remark-rehype";function we(e,t){return e.name===t}const Ee=$(null);function Ne(e){const t=C(Ee);if(!t)throw new Error("useContext must be used within a Provider");const{setHandles:r}=t;return M(()=>{if(e)return r(e),()=>{r({})}},[e]),t}function je({children:t,...r}){const[n,i]=S({});return e(Ee.Provider,{value:{...r,handles:n,setHandles:i},children:t})}const $e=function({ext:t}){const{result:r}=a(async e=>{try{return(await function(e){switch(e){case"../../images/file/docx.svg":return import("./docx-2LwnwWwv.js");case"../../images/file/html.svg":return import("./html-BSKTzJZQ.js");case"../../images/file/jpg.svg":return import("./jpg-muicsKjX.js");case"../../images/file/md.svg":return import("./md-DRS7QmE8.js");case"../../images/file/mp3.svg":return import("./mp3-HhP1Gk4B.js");case"../../images/file/mp4.svg":return import("./mp4-CWxSyjdn.js");case"../../images/file/pdf.svg":return import("./pdf-CWBi2u4Z.js");case"../../images/file/png.svg":return import("./png-DNwbFeJk.js");case"../../images/file/pptx.svg":return import("./pptx-Bv4V_F_3.js");case"../../images/file/py.svg":return import("./py-D30pRTJN.js");case"../../images/file/txt.svg":return import("./txt-CsqmEKjF.js");case"../../images/file/unknown.svg":return import("./unknown-DW8znerP.js");case"../../images/file/xlsx.svg":return import("./xlsx-CmkshfKZ.js");default:return new Promise(function(t,r){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e)))})}}(`../../images/file/${e}.svg`)).default}catch{return(await import("./unknown-DW8znerP.js")).default}},[t]);return r?e("img",{width:30,height:30,src:r}):null},Ce=function({className:r,name:n,size:i=0,loading:a,error:l,onRemove:c,onClick:d}){const m=T.extname(n).substring(1),u=t(ze,{className:r,$error:!!l,onClick:d,children:[t(Re,{children:[e($e,{ext:m}),a&&e(P,{variant:"primary"})]}),t(qe,{children:[e("h4",{children:n}),i>0&&e("p",{children:o(i,1)})]}),c&&e(Se,{onClick:e=>{e.preventDefault(),c()},children:e("i",{className:"bi bi-trash3"})})]});return l?e(s,{placement:"top",tooltip:l,children:u}):u};function Me(t){const{renderFileItem:r}=Ne();return r?r({Component:Ce,props:t}):e(Ce,{...t})}const Se=n.div`
2
2
  width: 1.75rem;
3
3
  height: 1.75rem;
4
4
  align-items: center;
@@ -13,7 +13,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
13
13
  color: var(--bs-danger);
14
14
  background-color: var(--bs-danger-bg-subtle);
15
15
  }
16
- `,ie=n.div`
16
+ `,qe=n.div`
17
17
  flex: 1;
18
18
  overflow: hidden;
19
19
 
@@ -34,7 +34,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
34
34
  line-height: 20px;
35
35
  margin-bottom: 0;
36
36
  }
37
- `,oe=n.div`
37
+ `,Re=n.div`
38
38
  position: relative;
39
39
  width: 3rem;
40
40
  height: 3rem;
@@ -48,7 +48,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
48
48
  position: absolute;
49
49
  }
50
50
 
51
- `,se=n.div`
51
+ `,ze=n.div`
52
52
  display: flex;
53
53
  gap: .5rem;
54
54
  padding: .5rem;
@@ -56,6 +56,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
56
56
  border-radius: var(--bs-border-radius-lg);
57
57
  align-items: center;
58
58
  background: #FFF;
59
+ cursor: ${e=>e.onClick?"pointer":"default"};
59
60
 
60
61
  &:hover {
61
62
  border-color: var(--bs-primary);
@@ -64,7 +65,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
64
65
  ${e=>e.$error&&i`
65
66
  border-color: var(--bs-danger) !important;
66
67
  `}
67
- `,ae=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"],le=k(null);function ce(e){const t=E(le);if(!t)throw new Error("useContext must be used within a Provider");const{setHandles:r}=t;return N(()=>{if(e)return r(e),()=>{r({})}},[e]),t}function de({children:e,...r}){const[n,i]=j({});return t(le.Provider,{value:{...r,handles:n,setHandles:i},children:e})}function he(){const{setMessages:e,setSuggestions:t,setLoading:r,conversationId:n,setConversationId:i,request:o,handles:s}=ce(),a=$(null),c=$(!1),d=$(n);N(()=>{d.current=n},[n]);const{onSuccess:h,onComplete:u,onEvent:m}=s,p=C(t=>{if(t.data)if("[DONE]"!=t.data)try{const r=JSON.parse(t.data);r.conversation?(d.current=r.conversation,i(r.conversation)):r.suspend?c.current=!0:r.event?m?.(r.event):e(e=>{const t=e[e.length-1];if(r.chunks){if(t.chunks){const e=r.chunks.index;if(t.chunks[e]||(t.chunks[e]={content:"",reasoning:"",tools:[]}),r.chunks.error)t.chunks[e].error=r.chunks.error;else if(r.chunks.tools){t.chunks[e].tools||(t.chunks[e].tools=[]);const n=r.chunks.tools.index;delete r.chunks.tools.index,t.chunks[e].tools[n]&&"arguments"in r.chunks.tools?t.chunks[e].tools[n].arguments+=r.chunks.tools.arguments:t.chunks[e].tools[n]={...t.chunks[e].tools[n],...r.chunks.tools}}else if(r.chunks.reasoning)t.chunks[e].reasoning+=r.chunks.reasoning;else if(r.chunks.content)if("object"==typeof r.chunks.content){Array.isArray(t.chunks[e].content)||(t.chunks[e].content=[]);const n=r.chunks.content.index,i=r.chunks.content.value;"string"==typeof i?(t.chunks[e].content[n]||(t.chunks[e].content[n]=""),t.chunks[e].content[n]+=i):t.chunks[e].content[n]=i}else t.chunks[e].content+=r.chunks.content;else r.chunks.node&&(t.chunks[e].node={...t.chunks[e].node,...r.chunks.node})}}else r.stats?t.stats=r.stats:r.id&&(t.id=r.id)})}catch(e){console.error(e)}else e(e=>{e[e.length-1].loading=!1})},[s]),g=C(t=>{let r="未知错误";l(t)&&(r=401==t.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof t.errors?t.errors:Object.values(t.errors).join("\n")),e(e=>{const t=e[e.length-1];t.chunks&&(0===t.chunks.length?t.chunks=[{error:r}]:t.chunks[t.chunks.length-1].error=r),t.loading=!1})},[]);return{send:C(async(n,...i)=>{"string"==typeof n&&(n={query:n,...i});const{query:s,files:l=[],variables:m={},quote:b}=n;if(s||l.length>0){a.current&&a.current.abort(),c.current=!1,r(!0),t([]),e(e=>{e.push({query:s,quote:b,files:l,variables:m,chunks:[],loading:!0})});try{let e={method:"post",data:{query:s,quote:b,files:l,variables:m,conversation:d.current},onMessage:p};await o(e),c.current||h?.()}catch(e){g(e)}r(!1),u?.()}},[o,s]),resume:C(async t=>{try{a.current&&a.current.abort(),c.current=!1,r(!0),e(e=>{e[e.length-1].loading=!0});let n={url:"resume",method:"post",data:{conversation:d.current,chunk:t.chunk,payload:t.payload},onMessage:p};await o(n),c.current||h?.()}catch(e){g(e)}r(!1),u?.()},[o,s]),suggest:C(async()=>{a.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:d.current},signal:a.current.signal};const r=await o(e);t(r)}catch{}finally{a.current=null}},[o])}}function ue({variables:e,values:r,onSubmit:n,onChange:i,children:o}){const s={},a=[],l={};return e.forEach(e=>{s[e.key]={type:"string",title:e.label},"textarea"===e.type?l[e.key]={"ui:widget":"textarea"}:"select"===e.type&&e.options&&(s[e.key].enum=e.options,s[e.key].enumNames=e.options,e.options.length>0&&(s[e.key].default=e.options[0])),e.required&&a.push(e.key)}),t(c,{schema:{type:"object",properties:s,required:a},formData:r,omitExtraData:!0,uiSchema:l,submitText:"开始对话",onSubmit:n,onChange:i,children:o})}const me=n.button`
68
+ `,Ie=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"];function Fe(){const{setMessages:e,setSuggestions:t,setLoading:r,conversationId:n,setConversationId:i,request:o,handles:s,messages:a}=Ne(),c=q(null),d=q(!1),m=q(n),{onSuccess:u,onComplete:h,onEvent:p}=s,g=R(t=>{if(t.data)if("[DONE]"!=t.data)try{const r=JSON.parse(t.data);r.conversation?(m.current=r.conversation,i(r.conversation)):r.suspend?d.current=!0:r.event?p?.(r.event):e(e=>{const t=e[e.length-1];if(r.chunks){if(t.chunks){const e=r.chunks.index;if(t.chunks[e]||(t.chunks[e]={content:"",reasoning:"",tools:[]}),r.chunks.error)t.chunks[e].error=r.chunks.error;else if(r.chunks.tools){t.chunks[e].tools||(t.chunks[e].tools=[]);const n=r.chunks.tools.index;delete r.chunks.tools.index,t.chunks[e].tools[n]&&"arguments"in r.chunks.tools?t.chunks[e].tools[n].arguments+=r.chunks.tools.arguments:t.chunks[e].tools[n]={...t.chunks[e].tools[n],...r.chunks.tools}}else if(r.chunks.reasoning)t.chunks[e].reasoning+=r.chunks.reasoning;else if(r.chunks.content)if("object"==typeof r.chunks.content){Array.isArray(t.chunks[e].content)||(t.chunks[e].content=[]);const n=r.chunks.content.index,i=r.chunks.content.value;"string"==typeof i?(t.chunks[e].content[n]||(t.chunks[e].content[n]=""),t.chunks[e].content[n]+=i):t.chunks[e].content[n]=i}else t.chunks[e].content+=r.chunks.content;else r.chunks.node&&(t.chunks[e].node={...t.chunks[e].node,...r.chunks.node})}}else r.stats?t.stats=r.stats:r.id&&(t.id=r.id)})}catch(e){console.error(e)}else e(e=>{e[e.length-1].loading=!1})},[s]),f=R(t=>{let r="未知错误";l(t)&&(r=401==t.response?.status?"未授权或授权已过期,请刷新页面后重试":"string"==typeof t.errors?t.errors:Object.values(t.errors).join("\n")),e(e=>{const t=e[e.length-1];t.chunks&&(0===t.chunks.length?t.chunks=[{error:r}]:t.chunks[t.chunks.length-1].error=r),t.loading=!1})},[]),b=R(async()=>{try{c.current&&c.current.abort(),d.current=!1,r(!0),e(e=>{e[e.length-1].loading=!0,delete e[e.length-1].stats});let t={url:"message",method:"get",params:{conversation:m.current},onMessage:g};await o(t),d.current||u?.()}catch(e){f(e)}r(!1),h?.()},[]);M(()=>{m.current=n;const e=a[a.length-1];e&&0==e.chunks?.length&&!e.loading&&b()},[n]);const v=R(async(n,...i)=>{"string"==typeof n&&(n={query:n,...i});const{query:s,files:a=[],variables:l={},quote:p}=n;if(s||a.length>0){c.current&&c.current.abort(),d.current=!1,r(!0),t([]),e(e=>{e.push({query:s,quote:p,files:a,variables:l,chunks:[],loading:!0})});try{let e={method:"post",data:{query:s,quote:p,files:a,variables:l,conversation:m.current},onMessage:g};await o(e),d.current||u?.()}catch(e){f(e)}r(!1),h?.()}},[o,s]),x=R(async t=>{try{c.current&&c.current.abort(),d.current=!1,r(!0),e(e=>{e[e.length-1].loading=!0});let n={url:"resume",method:"post",data:{conversation:m.current,chunk:t.chunk,tool:t.tool,payload:t.payload},onMessage:g};await o(n),d.current||u?.()}catch(e){f(e)}r(!1),h?.()},[o,s]);return{send:v,resume:x,suggest:R(async()=>{c.current=new AbortController;try{let e={method:"post",url:"/suggestion",data:{conversation:m.current},signal:c.current.signal};const r=await o(e);t(r)}catch{}finally{c.current=null}},[o])}}function Ae({variables:t,values:r,onSubmit:n,onChange:i,children:o}){const s={},a=[],l={};return t.forEach(e=>{s[e.key]={type:"string",title:e.label},"textarea"===e.type?l[e.key]={"ui:widget":"textarea"}:"select"===e.type&&e.options&&(s[e.key].enum=e.options,s[e.key].enumNames=e.options,e.options.length>0&&(s[e.key].default=e.options[0])),e.required&&a.push(e.key)}),e(c,{schema:{type:"object",properties:s,required:a},formData:r,omitExtraData:!0,uiSchema:l,submitText:"开始对话",onSubmit:n,onChange:i,children:o})}const De=n.button`
68
69
  color: var(--bs-secondary);
69
70
  cursor: pointer;
70
71
  display: flex;
@@ -87,12 +88,12 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
87
88
  background-color: var(--bs-gray-200);
88
89
  }
89
90
 
90
- `;let pe=class{#e;#t;constructor(){this.#t=new B}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}start(){if(!this.#e){const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return void d.error("浏览器不支持语音识别");const t=new e;t.continuous=!0,t.lang=navigator.language,t.onresult=e=>{const t=Array.from(e.results).at(-1)?.item(0).transcript;t&&this.#t.emit("result",t)},t.onspeechend=()=>{this.#t.emit("recording",!1)},t.onerror=e=>{this.#t.emit("recording",!1),d.error(e.error)},this.#e=t}this.#t.emit("recording",!0),this.#e.start()}stop(){this.#e?.stop(),this.#t.emit("recording",!1)}},ge=class{#t;#r;#n;#i;constructor(e){this.#r=e,this.#t=new B}async start(){try{this.#n=await navigator.mediaDevices.getUserMedia({audio:!0}),this.#i=new AudioContext;const e=this.#i.createScriptProcessor(0,1,1);this.#i.createMediaStreamSource(this.#n).connect(e),e.connect(this.#i.destination);let t=[],r=0;const n=.01,i=1;e.onaudioprocess=e=>{const o=e.playbackTime,s=e.inputBuffer.getChannelData(0);let a=!0;for(let e=0;e<s.length;e++)if(Math.abs(s[e])>n){a=!1;break}if(a){const e=o-r;e>i&&(t.length>1&&(this.save(t),t=[]),e>10&&this.stop())}else t.push(new Float32Array(s)),r=o},this.#t.emit("recording",!0)}catch(e){d.error(e.message)}}convertBuffer(e){const t=new Float32Array(e),r=new Int16Array(e.length);for(let e=0;e<t.length;e++){const n=Math.max(-1,Math.min(1,t[e]));r[e]=n<0?32768*n:32767*n}return r}async encodeMP3(e){const{Mp3Encoder:t}=await import("@breezystack/lamejs"),r=new t(1,44100,128),n=[];for(const t of e){const e=this.convertBuffer(t),i=1152;let o=e.length;for(let t=0;o>=0;t+=i){const s=e.subarray(t,t+i),a=r.encodeBuffer(s);n.push(new Int8Array(a)),o-=i}}return n.push(r.flush()),new Blob(n,{type:"audio/mp3"})}async save(e){const t=await this.encodeMP3(e);try{this.#t.emit("transcribing",!0);const e=await this.#r(t);e&&this.#t.emit("result",e)}catch(e){}finally{this.#t.emit("transcribing",!1)}}stop(){this.#n&&(this.#n.getTracks().forEach(e=>e.stop()),this.#n=void 0),this.#i&&(this.#i.close(),this.#i=void 0),this.#t.emit("recording",!1)}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}};const be=M(({onResult:r,model:n="builtin"},i)=>{const{request:o}=ce(),a=q(()=>{if("builtin"!==n)return async e=>{const t=new FormData;t.append("file",e,"audio.mp3"),t.append("model",n);return(await o({url:"/transcriptions",method:"post",data:t})).text}},[n]),{start:l,stop:c,recording:d,transcribing:h}=function({onResult:e,loader:t}){const r=$(),[n,i]=j(!1),[o,s]=j(!1);return N(()=>()=>{r.current&&(r.current.stop(),r.current=void 0)},[]),{recording:n,transcribing:o,start:async()=>{r.current||(r.current=t?new ge(t):new pe,r.current.onRecording(i),r.current.onTranscribing(s),r.current.onResult(e)),r.current.start()},stop:()=>{r.current&&r.current.stop()}}}({onResult:r,loader:a});return z(i,()=>({start:l,stop:c}),[l,c]),t(s,{tooltip:d?"停止":"语音输入",placement:"top",children:e(me,{onMouseDown:e=>{e.preventDefault(),d?c():l()},children:[h&&t(fe,{animation:"border",variant:"primary",size:"sm"}),t("i",d?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})}),fe=n(D)`
91
+ `;let Le=class{#e;#t;constructor(){this.#t=new Q}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}start(){if(!this.#e){const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return void d.error("浏览器不支持语音识别");const t=new e;t.continuous=!0,t.lang=navigator.language,t.onresult=e=>{const t=Array.from(e.results).at(-1)?.item(0).transcript;t&&this.#t.emit("result",t)},t.onspeechend=()=>{this.#t.emit("recording",!1)},t.onerror=e=>{this.#t.emit("recording",!1),d.error(e.error)},this.#e=t}this.#t.emit("recording",!0),this.#e.start()}stop(){this.#e?.stop(),this.#t.emit("recording",!1)}},Te=class{#t;#r;#n;#i;constructor(e){this.#r=e,this.#t=new Q}async start(){try{this.#n=await navigator.mediaDevices.getUserMedia({audio:!0}),this.#i=new AudioContext;const e=this.#i.createScriptProcessor(0,1,1);this.#i.createMediaStreamSource(this.#n).connect(e),e.connect(this.#i.destination);let t=[],r=0;const n=.01,i=1;e.onaudioprocess=e=>{const o=e.playbackTime,s=e.inputBuffer.getChannelData(0);let a=!0;for(let e=0;e<s.length;e++)if(Math.abs(s[e])>n){a=!1;break}if(a){const e=o-r;e>i&&(t.length>1&&(this.save(t),t=[]),e>10&&this.stop())}else t.push(new Float32Array(s)),r=o},this.#t.emit("recording",!0)}catch(e){d.error(e.message)}}convertBuffer(e){const t=new Float32Array(e),r=new Int16Array(e.length);for(let e=0;e<t.length;e++){const n=Math.max(-1,Math.min(1,t[e]));r[e]=n<0?32768*n:32767*n}return r}async encodeMP3(e){const{Mp3Encoder:t}=await import("@breezystack/lamejs"),r=new t(1,44100,128),n=[];for(const t of e){const e=this.convertBuffer(t),i=1152;let o=e.length;for(let t=0;o>=0;t+=i){const s=e.subarray(t,t+i),a=r.encodeBuffer(s);n.push(new Int8Array(a)),o-=i}}return n.push(r.flush()),new Blob(n,{type:"audio/mp3"})}async save(e){const t=await this.encodeMP3(e);try{this.#t.emit("transcribing",!0);const e=await this.#r(t);e&&this.#t.emit("result",e)}catch(e){}finally{this.#t.emit("transcribing",!1)}}stop(){this.#n&&(this.#n.getTracks().forEach(e=>e.stop()),this.#n=void 0),this.#i&&(this.#i.close(),this.#i=void 0),this.#t.emit("recording",!1)}onResult(e){this.#t.on("result",e)}onRecording(e){this.#t.on("recording",e)}onTranscribing(e){this.#t.on("transcribing",e)}};const Pe=z(({onResult:r,model:n="builtin"},i)=>{const{request:o}=Ne(),a=I(()=>{if("builtin"!==n)return async e=>{const t=new FormData;t.append("file",e,"audio.mp3"),t.append("model",n);return(await o({url:"/transcriptions",method:"post",data:t})).text}},[n]),{start:l,stop:c,recording:d,transcribing:m}=function({onResult:e,loader:t}){const r=q(),[n,i]=S(!1),[o,s]=S(!1);return M(()=>()=>{r.current&&(r.current.stop(),r.current=void 0)},[]),{recording:n,transcribing:o,start:async()=>{r.current||(r.current=t?new Te(t):new Le,r.current.onRecording(i),r.current.onTranscribing(s),r.current.onResult(e)),r.current.start()},stop:()=>{r.current&&r.current.stop()}}}({onResult:r,loader:a});return F(i,()=>({start:l,stop:c}),[l,c]),e(s,{tooltip:d?"停止":"语音输入",placement:"top",children:t(De,{onMouseDown:e=>{e.preventDefault(),d?c():l()},children:[m&&e(Oe,{animation:"border",variant:"primary",size:"sm"}),e("i",d?{className:"bi bi-mic-fill text-danger"}:{className:"bi bi-mic"})]})})}),Oe=n(P)`
91
92
  position: absolute;
92
93
  --bs-spinner-width: .75rem;
93
94
  --bs-spinner-height: .75rem;
94
95
  --bs-spinner-border-width: 0.1em;
95
- `,ve=M(({className:e,children:r,size:n,tooltip:i,placement:o,onClick:a,onMouseDown:l},c)=>{const d=t(xe,{ref:c,className:e,onClick:a,onMouseDown:l,$size:n,children:r});return i?t(s,{tooltip:i,placement:o,children:d}):d}),xe=n.div`
96
+ `,_e=z(({className:t,children:r,size:n,tooltip:i,placement:o,onClick:a,onMouseDown:l},c)=>{const d=e(Be,{ref:c,className:t,onClick:a,onMouseDown:l,$size:n,children:r});return i?e(s,{tooltip:i,placement:o,children:d}):d}),Be=n.div`
96
97
  width: 2rem;
97
98
  height: 2rem;
98
99
  align-items: center;
@@ -116,100 +117,130 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
116
117
  &:hover {
117
118
  background-color: var(--bs-secondary-bg-subtle);
118
119
  }
119
- `;function ye(){const{request:n,reset:i,conversationId:o}=ce(),[a,l]=j(!1);return e(r,{children:[t(ve,{tooltip:"历史记录",placement:"top",onClick:()=>l(!0),children:t("i",{className:"bi bi-clock-history"})}),t(u,{show:a,onHide:()=>{l(!1)},placement:"end",header:"聊天历史记录",bodyAs:we,children:a&&t($e,{children:t(je,{useWindow:!1,source:e=>n({url:"/conversation",params:e}),render:({data:r,loading:a,setData:c})=>r.length||a?r.map((r,a)=>{const d=r.messages?.reduce((e,t)=>e+t.chunks.reduce((e,t)=>e+(t.content||""),""),"");return e(S,{children:[a>0&&t("hr",{className:"mx-2 my-2"}),e(Ne,{onClick:()=>{i(r),l(!1)},children:[e(Ee,{children:[o===r.id&&t(L,{bg:"secondary",children:"当前"}),t("span",{className:"fw-bold overflow-hidden text-truncate me-auto",children:r.title||"未命名对话"}),t("span",{className:"text-body text-opacity-50 flex-shrink-0 ms-5",children:m(r.update_time).fromNow()})]}),e(ke,{children:[t("span",{className:"overflow-hidden text-truncate me-auto",children:d||" "}),t("span",{className:"ms-3",children:o!==r.id&&t(s,{tooltip:"删除",children:t(p,{as:"a",confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${r.id}`,method:"DELETE"}),onSuccess:()=>{c(e=>{const t=e.findIndex(e=>e.id===r.id);-1!==t&&e.splice(t,1)})},children:t("i",{className:"bi bi-trash3"})})})})]})]})]},r.id)}):t("div",{className:"text-muted text-center py-5",children:"暂无对话记录"})})})})]})}const we=n.div`
120
+ `;function Ue(){const{request:n,reset:i,conversationId:o}=Ne(),[s,a]=S(!1),[l,c]=S(""),[d,m]=S(""),b=u(e=>{m(e)},500);return M(()=>{b(l)},[l]),t(r,{children:[e(_e,{tooltip:"历史记录",placement:"top",onClick:()=>a(!0),children:e("i",{className:"bi bi-clock-history"})}),e(h,{show:s,onHide:()=>{a(!1)},placement:"end",headerAs:Xe,header:t(r,{children:[e("span",{children:"聊天历史记录"}),e(Ge,{children:e(B,{type:"search",placeholder:"搜索聊天记录...",value:l,onChange:e=>c(e.target.value),autoFocus:!0})})]}),bodyAs:He,children:s&&e(We,{children:e(Qe,{useWindow:!1,source:e=>n({url:"/conversation",params:{...e,...d&&{keyword:d}}}),render:({data:s,loading:l,setData:c})=>s.length||l?t(r,{children:[s.map((s,l)=>t(A,{children:[l>0&&e("hr",{className:"mx-2 my-2"}),t(Je,{children:[o===s.id&&e(O,{bg:"secondary",children:"当前"}),e("span",{className:"overflow-hidden text-truncate flex-fill",onClick:()=>{i(s),a(!1)},children:s.title||"未命名对话"}),t(_,{align:"end",children:[e(_.Toggle,{size:"sm",className:"no-caret",as:_e,children:e("i",{className:"bi bi-three-dots-vertical"})}),t(_.Menu,{children:[e(p,{buttonProps:{as:_.Item},text:t(r,{children:[e("i",{className:"bi bi-pencil me-2"}),"重命名"]}),modalProps:{header:"编辑对话名称"},schema:{type:"object",properties:{title:{type:"string"}}},uiSchema:{title:{"ui:label":!1,"ui:autofocus":!0}},formData:{title:s.title},onRequest:e=>n({url:`/conversation/${s.id}`,method:"PUT",data:e}),onSuccess:(e,t)=>{c(e=>{const r=e.findIndex(e=>e.id===s.id);-1!==r&&Object.assign(e[r],t)})}}),t(g,{as:_.Item,confirm:"确定要删除吗?",onRequest:()=>n({url:`/conversation/${s.id}`,method:"DELETE"}),onSuccess:()=>{c(e=>{const t=e.findIndex(e=>e.id===s.id);-1!==t&&e.splice(t,1)})},children:[e("i",{className:"bi bi-trash3 me-2"}),"删除"]})]})]})]})]},s.id)),l&&e(f,{wrap:!0})]}):e("div",{className:"text-muted text-center py-5",children:d?"未找到匹配的聊天记录":"暂无对话记录"})},d)})})]})}const He=n.div`
120
121
  padding: 0;
121
122
  overflow: hidden;
122
- `,ke=n.div`
123
- color: var(--bs-gray-600);
124
- font-weight: 400;
125
- line-height: 22px;
126
- display: flex;
127
- align-items: center;
128
-
129
- & :last-child {
130
- display: none;
131
- }
132
- `,Ee=n.div`
133
- display: flex;
134
- align-items: center;
135
- gap: .25rem;
136
- `,Ne=n.div`
123
+ `,Je=n.div`
137
124
  gap: .5rem;
138
125
  display: flex;
139
- flex-direction: column;
140
126
  cursor: pointer;
141
127
  padding: .5rem;
128
+ align-items: center;
142
129
  border-radius: var(--bs-border-radius-lg);
143
130
 
131
+ & > .dropdown {
132
+ display: none;
133
+ }
134
+
144
135
  &:hover {
145
136
  background-color: var(--bs-gray-200);
146
137
 
147
-
148
- &:hover {
149
- ${ke} :last-child {
150
- display: initial;
151
- }
138
+ & > .dropdown {
139
+ display: block;
152
140
  }
153
141
  }
154
- `,je=n(h)`
142
+ `,Qe=n(m)`
155
143
  display: flex;
156
144
  flex-direction: column;
157
145
  padding: .5rem;
158
- `,$e=n.div`
146
+ `,We=n.div`
159
147
  height: 100%;
160
148
  overflow-y: auto;
161
- `;var Ce;function Me(){return Me=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Me.apply(null,arguments)}const qe=e=>w.createElement("svg",Me({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),Ce||(Ce=w.createElement("path",{fillRule:"evenodd",d:"M128 22C69.458 22 22 69.458 22 128v96c0 5.523 4.477 10 10 10h96c58.542 0 106-47.458 106-106S186.542 22 128 22m0 56c5.523 0 10 4.477 10 10v30h30c5.523 0 10 4.477 10 10s-4.477 10-10 10h-30v30c0 5.523-4.477 10-10 10s-10-4.477-10-10v-30H88c-5.523 0-10-4.477-10-10s4.477-10 10-10h30V88c0-5.523 4.477-10 10-10",clipRule:"evenodd","data-follow-fill":"#000"})));function ze(){const{reset:e}=ce();return t(ve,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:e,children:t(qe,{})})}function Se({children:r}){return e(Re,{children:[r,e(Fe,{children:[t(ye,{}),t(ze,{})]})]})}const Fe=n.div`
149
+ `,Xe=n.div`
150
+ display: flex;
151
+ align-items: center;
152
+ justify-content: space-between;
153
+ gap: 0.5rem;
154
+ flex: 1;
155
+ margin-right: .5rem;
156
+ `,Ge=n.div`
157
+ display: flex;
158
+ align-items: center;
159
+ gap: 0.5rem;
160
+ `;var Ke;function Ve(){return Ve=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Ve.apply(null,arguments)}const Ye=e=>j.createElement("svg",Ve({width:"1em",height:"1em",fill:"currentColor",viewBox:"0 0 256 256"},e),Ke||(Ke=j.createElement("path",{fillRule:"evenodd",d:"M128 22C69.458 22 22 69.458 22 128v96c0 5.523 4.477 10 10 10h96c58.542 0 106-47.458 106-106S186.542 22 128 22m0 56c5.523 0 10 4.477 10 10v30h30c5.523 0 10 4.477 10 10s-4.477 10-10 10h-30v30c0 5.523-4.477 10-10 10s-10-4.477-10-10v-30H88c-5.523 0-10-4.477-10-10s4.477-10 10-10h30V88c0-5.523 4.477-10 10-10",clipRule:"evenodd","data-follow-fill":"#000"})));function Ze(){const{reset:t}=Ne();return e(_e,{className:"text-primary",tooltip:"新会话",placement:"top",onClick:t,children:e(Ye,{})})}function et({children:r}){return t(rt,{children:[r,t(tt,{children:[e(Ue,{}),e(Ze,{})]})]})}const tt=n.div`
162
161
  display: flex;
163
162
  gap: .25rem;
164
163
  margin-left: auto;
165
- `,Re=n.div`
164
+ `,rt=n.div`
166
165
  margin-bottom: .5rem;
167
166
  display: flex;
168
167
  padding: 0 .125rem;
169
- `;var Ae=M(function({suggestion:r,fileTypes:n,speech:i,scrollRef:o,variables:a,minRows:c,toolbar:h,disabled:u,autoFocus:m,placeholder:p="请输入你的问题, Enter+Shift换行, Enter发送",onEvent:b},f){const v=$(null),x=$(null),y=$(null),[w,k]=j(""),[E,M]=j(""),[S,F]=g([]),[I,D]=j(!1),L=n&&n.length>0?n:ae,{send:T,resume:O,suggest:B}=he(),_=q(()=>({onSuccess(){r&&B()},onComplete(){requestAnimationFrame(()=>{v.current?.focus()})},onEvent:b}),[r,b]),{messages:U,loading:H,request:J}=ce(_),[K,Q]=j();N(()=>{const e=U.filter(e=>!!e.query);Q(e.at(-1)?.variables)},[U]),N(()=>{!n&&S.length>0&&F([])},[n]),N(()=>{const e=o.current;if(e&&T){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};a&&(t.variables={...K,...a.values}),T(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[a,K]);const W=C(({target:e})=>{if(e.files){const t=Array.from(e.files).filter(e=>!!L.includes(A.extname(e.name))&&(!(e.size>20971520)&&e)).slice(0,6-S.length);F(e=>{e.push(...t.map(e=>({file:e})))}),t.forEach(async e=>{try{const t=new FormData;t.set("file",e);const r=await J({method:"POST",url:"/upload",data:t});F(t=>{const n=t.find(t=>t.file===e);n&&(n.path=r.path)})}catch(t){const r=l(t)?t.message:"unknown error";F(t=>{const n=t.find(t=>t.file===e);n&&(n.error=r)})}})}e.value=""},[S,L]),X=S.flatMap(({file:e,path:t})=>t?[{name:e.name,size:e.size,path:t}]:[]),V=C(()=>{if(w||X.length>0){const e={query:w,files:X};a&&(e.variables={...K,...a.values}),E&&(e.quote=E),T(e),k(""),M(""),F([]),y.current?.stop(!0)}},[w,X,a,K,E]);if(z(f,()=>({setQuery:k,setQuote:M,send:T,resume:O,focus(){v.current?.focus()}})),a){const e=a.config.filter(e=>!(e.key in(a.values||{}))),r=(t,r=!1)=>!!t&&e.every(e=>{const n=!e.required||t?.[e.key];return!n&&r&&d.error("请完善必填信息"),n});if(e.length>0&&!r(K))return t(De,{children:t(Ie,{children:t(ue,{values:K,variables:e,onSubmit:({formData:e})=>{if(r(e,!0))return Q(e),!0}})})})}return e(_e,{children:[h&&t(Se,{children:h}),e(Be,{$focused:I&&!H,children:[S.length>0&&t(Pe,{children:S.map(({file:e,error:r,path:n},i)=>{const o=void 0===r&&void 0===n;return t(Le,{name:e.name,size:e.size,error:r,loading:o,onRemove:()=>{F(t=>{const r=t.findIndex(t=>t.file===e);-1!==r&&t.splice(r,1)})}},i)})}),!!E&&e(Oe,{children:[t("i",{className:"bi bi-quote"}),t("p",{children:E}),t(P,{onClick:()=>M("")})]}),e(Te,{children:[t(R,{disabled:H||u,ref:v,placeholder:p,minRows:c,maxRows:5,value:w,onChange:e=>k(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),V())},autoFocus:m,onFocus:()=>D(!0),onBlur:()=>D(!1)}),n&&t(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:e(me,{disabled:S.length>=6,onClick:()=>x.current?.click(),children:[t("input",{onChange:W,multiple:!0,accept:L.join(","),ref:x,type:"file",hidden:!0}),t("i",{className:"bi bi-file-earmark-arrow-up"})]})}),i&&t(be,{ref:y,model:i.model,onResult:e=>{v.current?.focus(),k(t=>t+e+" ")}}),t(me,{className:"text-primary",disabled:!w&&0===X.length,onClick:e=>{e.preventDefault(),V()},children:t("i",{className:"bi bi-send-fill"})})]})]})]})});const Ie=n.div`
168
+ `,nt=function(e){return e.ops.map(e=>e.attributes?.[ie]||e.attributes?.[V]||e.insert||"").join("")};var it=z(function({suggestion:r,fileTypes:n,speech:i,scrollRef:o,variables:a,minRows:c=1,maxRows:m=5,toolbar:u,disabled:h,autoFocus:p,placeholder:g="请输入你的问题, Enter+Shift换行, Enter发送",onEvent:f},v){const x=q(null),y=q(null),k=q(),[w,E]=S(""),[N,j]=S(""),[$,C]=b([]),[z,A]=S(!1),D=n&&n.length>0?n:Ie,{send:T,resume:P,suggest:O}=Fe(),_=I(()=>{const e=new W({schema:{[K]:{void:!0,inline:!0},[Y]:{void:!0,inline:!0},[G]:{void:!0,inline:!0}}});return e.event.on("focus_capture",()=>A(!0)),e.event.on("blur_capture",()=>A(!1)),e.event.on("keydown_capture",t=>{if("Escape"===t.key){const{ops:t}=e.state.toBlock();t.some(e=>"skill-key"in(e.attributes||{}))&&e.state.setContent(new X)}else"Enter"!==t.key||t.shiftKey||(t.preventDefault(),t.stopPropagation(),k.current?.())}),e.event.on("CONTENT_CHANGE",e=>{E(nt(e.current).trim())}),e},[]),B=I(()=>({onSuccess(){r&&O()},onComplete(){requestAnimationFrame(()=>{_.selection.focus()})},onEvent:f}),[r,f]),{messages:H,loading:J,request:Q,setInput:ne}=Ne(B),[ie,oe]=S();M(()=>{const e=H.filter(e=>!!e.query);oe(e.at(-1)?.variables)},[H]),M(()=>{!n&&$.length>0&&C([])},[n]),M(()=>{const e=o.current;if(e&&T){const t=e=>{if(e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash){e.preventDefault();const t={query:e.target.text};a&&(t.variables={...ie,...a.values}),T(t)}};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[a,ie]);const se=R(({target:e})=>{if(e.files){const t=Array.from(e.files).filter(e=>!!D.includes(L.extname(e.name))&&(!(e.size>20971520)&&e)).slice(0,6-$.length);C(e=>{e.push(...t.map(e=>({file:e})))}),t.forEach(async e=>{try{const t=new FormData;t.set("file",e);const r=await Q({method:"POST",url:"/upload",data:t});C(t=>{const n=t.find(t=>t.file===e);n&&(n.path=r.path)})}catch(t){const r=l(t)?t.message:"unknown error";C(t=>{const n=t.find(t=>t.file===e);n&&(n.error=r)})}})}e.value=""},[$,D]),ae=$.flatMap(({file:e,path:t})=>t?[{name:e.name,size:e.size,path:t}]:[]),le=R(()=>{if(w||ae.length>0){const e={query:w,files:ae};a&&(e.variables={...ie,...a.values}),N&&(e.quote=N),T(e),de(""),j(""),C([]),y.current?.stop(!0)}},[w,ae,a,ie,N]);M(()=>{k.current=le},[le]);const ce=R(e=>{const t={},r={},n=new X;let i=1,o=1,s=0;const a=/\(([^)]+)\)|\[([^\]]+)\]|\{([^}]+)\}/g;let l;for(;null!==(l=a.exec(e));){if(l.index>s){const t=e.substring(s,l.index);t&&n.insert(t)}if(l[1])n.insert(" ",{[G]:l[1].trim()});else if(l[2]){const e=`var-${i}`;t[e]=l[0],n.insert(" ",{[K]:e}),i++}else if(l[3]){const e=l[3].split("|").map(e=>e.trim()),t=`sel-${o}`;r[t]=e,n.insert(" ",{[Y]:t,[V]:e[0]}),o++}s=a.lastIndex}if(s<e.length){const t=e.substring(s);t&&n.insert(t)}return{delta:n,placeholders:t,selector:r}},[]),de=R(e=>{let t;t="string"==typeof e?e:e(nt(_.state.block.toDelta()));const{delta:r,placeholders:n,selector:i}=ce(t);_.plugin.register([new Z({placeholders:n}),new ee({selector:i}),new te]),_.state.setContent(r),requestAnimationFrame(()=>{_.selection.focus()})},[_,ce]),me=I(()=>({setQuery:de,setQuote:j,send:T,resume:P,editor:_,focus(){_.selection.focus()}}),[de,j,T,P,_]);if(M(()=>{ne(me)},[me]),F(v,()=>me,[me]),a){const t=a.config.filter(e=>!(e.key in(a.values||{}))),r=(e,r=!1)=>!!e&&t.every(t=>{const n=!t.required||e?.[t.key];return!n&&r&&d.error("请完善必填信息"),n});if(t.length>0&&!r(ie))return e(st,{children:e(ot,{children:e(Ae,{values:ie,variables:t,onSubmit:({formData:e})=>{if(r(e,!0))return oe(e),!0}})})})}return t(pt,{children:[e(lt,{}),u&&e(et,{children:u}),t(ht,{$focused:z&&!J,children:[$.length>0&&e(dt,{children:$.map(({file:t,error:r,path:n},i)=>{const o=void 0===r&&void 0===n;return e(at,{name:t.name,size:t.size,error:r,loading:o,onRemove:()=>{C(e=>{const r=e.findIndex(e=>e.file===t);-1!==r&&e.splice(r,1)})}},i)})}),!!N&&t(ut,{children:[e("i",{className:"bi bi-quote"}),e("p",{children:N}),e(U,{onClick:()=>j("")})]}),t(mt,{children:[e(re,{editor:_,readonly:J||h,children:e(ct,{className:"block-kit-editable",autoFocus:p,placeholder:g,$minRows:c,$maxRows:m})}),n&&e(s,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:t(De,{disabled:$.length>=6,onClick:()=>x.current?.click(),children:[e("input",{onChange:se,multiple:!0,accept:D.join(","),ref:x,type:"file",hidden:!0}),e("i",{className:"bi bi-file-earmark-arrow-up"})]})}),i&&e(Pe,{ref:y,model:i.model,onResult:e=>{de(t=>t+e+" ")}}),e(De,{className:"text-primary",disabled:!w&&0===ae.length,onClick:e=>{e.preventDefault(),le()},children:e("i",{className:"bi bi-send-fill"})})]})]})]})});const ot=n.div`
170
169
  border-radius: var(--bs-border-radius-lg);
171
170
  box-shadow: var(--bs-box-shadow-sm);
172
171
  margin: 1rem;
173
172
  padding: 1rem;
174
173
  width: 100%;
175
174
  max-width: 500px;
176
- `,De=n.div`
175
+ `,st=n.div`
177
176
  position: absolute;
178
177
  left: 0;
179
178
  right: 0;
180
179
  top: 0;
181
180
  bottom: 0;
182
- background: #FFF;
181
+ background: #fff;
183
182
  display: flex;
184
183
  justify-content: center;
185
184
  align-items: center;
186
- `,Le=n(re)`
187
- width: calc((100% - .75rem) / 2);
188
- `,Pe=n.div`
185
+ `,at=n(Me)`
186
+ width: calc((100% - 0.75rem) / 2);
187
+ `,lt=v`
188
+ .editable-selector-options {
189
+ border-radius: var(--bs-border-radius) !important;
190
+ border: none !important;
191
+ box-shadow: var(--bs-box-shadow-sm) !important;
192
+ padding: 0.25rem 0 !important;
193
+
194
+ & > div {
195
+ padding: 0.4rem 1rem !important;
196
+
197
+ &:hover {
198
+ background-color: var(--bs-tertiary-bg) !important;
199
+ }
200
+
201
+ &.editable-selector-option-selected {
202
+ color: var(--bs-primary) !important;
203
+ }
204
+ }
205
+ }
206
+ `,ct=n(ne)`
207
+ min-height: calc(${e=>1.5*e.$minRows}em + 1rem);
208
+ max-height: calc(${e=>1.5*e.$maxRows}em + 1rem);
209
+ overflow-y: auto;
210
+ margin: -0.5rem;
211
+ padding: 0.5rem;
212
+ flex: 1;
213
+
214
+ .editable-skill-container {
215
+ color: var(--bs-primary);
216
+ background: rgba(0, 102, 255, 0.06);
217
+
218
+ &:first-child {
219
+ margin-left: 0;
220
+ }
221
+ }
222
+
223
+ .editable-selector {
224
+ display: inline-flex;
225
+ }
226
+
227
+ .editable-vars > .block-kit-editable-text,
228
+ .editable-selector {
229
+ color: var(--bs-primary);
230
+ }
231
+ `,dt=n.div`
189
232
  display: flex;
190
233
  flex-wrap: wrap;
191
- padding: .75rem;
192
- gap: .75rem;
234
+ padding: 0.75rem;
235
+ gap: 0.75rem;
193
236
  border-bottom: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
194
- `,Te=n.div`
237
+ `,mt=n.div`
195
238
  display: flex;
196
- padding: .5rem .5rem .5rem 1rem;
197
- gap: .25rem;
239
+ padding: 0.5rem 0.5rem 0.5rem 0.75rem;
240
+ gap: 0.25rem;
198
241
  align-items: end;
199
-
200
- textarea {
201
- border: none;
202
- outline: none;
203
- flex: 1;
204
- resize: none;
205
- background: transparent;
206
-
207
- &::placeholder {
208
- color: rgba(54, 54, 54, .3);
209
- }
210
- }
211
- `,Oe=n.div`
212
- margin: .75rem .75rem 0 .75rem;
242
+ `,ut=n.div`
243
+ margin: 0.75rem 0.75rem 0 0.75rem;
213
244
  padding: 4px 8px;
214
245
  display: flex;
215
246
  align-items: center;
@@ -229,14 +260,14 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
229
260
  -webkit-box-orient: vertical;
230
261
  display: -webkit-box;
231
262
  }
232
- `,Be=n.div`
233
- background: #FFF;
263
+ `,ht=n.div`
264
+ background: #fff;
234
265
  border: var(--bs-border-width) var(--bs-border-style) ${e=>e.$focused?"var(--bs-primary)":"var(--bs-border-color)"};
235
266
  border-radius: var(--bs-border-radius-lg);
236
267
  box-shadow: 0.125rem 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
237
- `,_e=n.div`
268
+ `,pt=n.div`
238
269
  margin: 0 1rem 1rem;
239
- `;function Ue(e){return e.map(e=>({id:e.id,query:e.query,quote:e.quote||void 0,files:e.files||void 0,variables:e.variables,chunks:e.chunks.map(({content:e="",node:t,error:r,tools:n=[],reasoning:i})=>({content:e,reasoning:i,error:r,tools:n,node:t})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}}))}function He(e){if((e=e.filter(e=>!!e.trim())).length>3){const t=[...e];let r=e.length-3;for(;r--;){let e=Math.floor(Math.random()*t.length);t.splice(e,1)}e=t}return e}var Je,Ke,Qe;function We(){return We=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},We.apply(null,arguments)}const Xe=e=>w.createElement("svg",We({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),Je||(Je=w.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},w.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),w.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),Ke||(Ke=w.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},w.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),w.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),Qe||(Qe=w.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},w.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),w.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))));function Ve(e){if(!e)return"";if("string"==typeof e)return e;if("image"===e.type){return`![](${b(e.image)})`}return""}const Ye=function(e,t,r){function n(t){return t!==V.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(Y.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===V.rightSquareBracket?(e.exit(Y.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==V.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):G(n)||n===V.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==V.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},Ge=function(){const e=this.data();e.micromarkExtensions.push({text:{[V.leftSquareBracket]:{tokenize:Ye}}}),e.fromMarkdownExtensions.push({enter:{cite:function(e){this.enter({type:"cite",data:{hName:"cite",hChildren:[{type:"text",value:""}]}},e)},citeData:function(){this.buffer()}},exit:{cite:function(e){this.exit(e)},citeData:function(){const e=this.resume();this.stack[this.stack.length-1].data.hChildren[0].value=e}}})},Ze=f.Image,et={pre:({children:r,node:n})=>{const[i,o]=j(!1),s=q(()=>{const e=n.children[0];return"element"===(t=e).type&&"code"===t.tagName&&!!e.properties?.className?.includes("language-svg");var t},[n]);N(()=>{s&&o(s)},[s]);const a=q(()=>U(n),[n]);return e(st,{children:[e(ot,{children:[!i&&t(v,{tooltip:!1,as:it,content:a}),s&&i&&t(it,{onClick:()=>{const e=new Blob([a],{type:"image/svg+xml"}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download="image.svg",r.click(),URL.revokeObjectURL(t)},children:"下载"}),s&&t(it,{onClick:()=>o(!i),children:i?"源码":"预览"})]}),s&&i?t("div",{dangerouslySetInnerHTML:{__html:a}}):t("pre",{children:r})]})},a:({node:e,href:r,...n})=>{const i=r?.startsWith("http")?"_blank":"_self";return t("a",{...n,href:r,target:i})},img:({node:e,...r})=>t(Ze,{...r})},tt=[[X,{singleDollarTextMath:!1}],W,Q],rt=[K,[J,{detect:!1,ignoreMissing:!0}]],nt=F(({content:e,components:r,cite:n})=>{e=e.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const i=q(()=>{const e={...et,...r};return n&&(e.cite=n),e},[r,n]),o=q(()=>n?[...tt,Ge]:tt,[n]);return t(at,{remarkPlugins:o,rehypePlugins:rt,components:i,children:e})},_),it=n.div`
270
+ `;function gt(e){return e.map(e=>({id:e.id,query:e.query,quote:e.quote||void 0,files:e.files||void 0,variables:e.variables,chunks:e.chunks.map(({content:e="",node:t,error:r,tools:n=[],reasoning:i})=>({content:e,reasoning:i,error:r,tools:n,node:t})),annotation:e.annotation,stats:{usage:e.usage,latency:e.latency}}))}function ft(e){if((e=e.filter(e=>!!e.trim())).length>3){const t=[...e];let r=e.length-3;for(;r--;){let e=Math.floor(Math.random()*t.length);t.splice(e,1)}e=t}return e}var bt,vt,xt;function yt(){return yt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},yt.apply(null,arguments)}const kt=e=>j.createElement("svg",yt({xmlns:"http://www.w3.org/2000/svg",width:20,height:10,fill:"#fff",viewBox:"0 0 120 30"},e),bt||(bt=j.createElement("circle",{cx:15,cy:15,r:15,fill:"#3c60ff"},j.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),j.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))),vt||(vt=j.createElement("circle",{cx:60,cy:15,r:9,fill:"#3c60ff",fillOpacity:.3},j.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:9,repeatCount:"indefinite",to:9,values:"9;15;9"}),j.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"}))),xt||(xt=j.createElement("circle",{cx:105,cy:15,r:15,fill:"#3c60ff"},j.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:15,repeatCount:"indefinite",to:15,values:"15;9;15"}),j.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"}))));function wt(e){if(!e)return"";if("string"==typeof e)return e;if("image"===e.type){return`![](${x(e.image)})`}return""}const Et=function(e,t,r){function n(t){return t!==he.leftSquareBracket?(e.exit("citeMarker"),e.enter("citeData"),e.enter(pe.chunkString,{contentType:"string"}),i(t)):(e.consume(t),n)}function i(n){return n===he.rightSquareBracket?(e.exit(pe.chunkString),e.exit("citeData"),e.enter("citeMarker"),function(n){if(n!==he.rightSquareBracket)return r(n);return e.consume(n),e.exit("citeMarker"),e.exit("cite"),t(n)}(n)):ge(n)||n===he.eof||n>57||n<48?r(n):(e.consume(n),i)}return function(t){return t!==he.leftSquareBracket?r(t):(e.enter("cite"),e.enter("citeMarker"),n(t))}},Nt=function(){const e=this.data();e.micromarkExtensions.push({text:{[he.leftSquareBracket]:{tokenize:Et}}}),e.fromMarkdownExtensions.push({enter:{cite:function(e){this.enter({type:"cite",data:{hName:"cite",hChildren:[{type:"text",value:""}]}},e)},citeData:function(){this.buffer()}},exit:{cite:function(e){this.exit(e)},citeData:function(){const e=this.resume();this.stack[this.stack.length-1].data.hChildren[0].value=e}}})},jt=y.Image,$t={pre:({children:r,node:n})=>{if(!n)return null;const[i,o]=S(!1),s=I(()=>{const e=n.children[0];return"element"===(t=e).type&&"code"===t.tagName&&!!e.properties?.className?.includes("language-svg");var t},[n]);M(()=>{s&&o(s)},[s]);const a=I(()=>se(n),[n]);return t(zt,{children:[t(Rt,{children:[!i&&e(k,{tooltip:!1,as:qt,content:a}),s&&i&&e(qt,{onClick:()=>{const e=new Blob([a],{type:"image/svg+xml"}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download="image.svg",r.click(),URL.revokeObjectURL(t)},children:"下载"}),s&&e(qt,{onClick:()=>o(!i),children:i?"源码":"预览"})]}),s&&i?e("div",{dangerouslySetInnerHTML:{__html:a}}):e("pre",{children:r})]})},a:({node:t,href:r,...n})=>{const i=r?.startsWith("http")?"_blank":"_self";return e("a",{...n,href:r,target:i})},img:({node:t,...r})=>e(jt,{...r})},Ct=[[ue,{singleDollarTextMath:!1}],me,de],Mt=[ce,[le,{detect:!1,ignoreMissing:!0}]],St=D(z(({content:t,components:r,cite:n},i)=>{t=t.replace(/\\\(\s(.+?)\s\\\)/g,"$$$$ $1 $$$$");const o=I(()=>{const e={...$t,...r};return n&&(e.cite=n),e},[r,n]),s=I(()=>n?[...Ct,Nt]:Ct,[n]);return e(It,{ref:i,children:e(ae,{remarkPlugins:s,rehypePlugins:Mt,components:o,children:t})})}),oe),qt=n.div`
240
271
  cursor: pointer;
241
272
  padding: 2px 10px;
242
273
  background-color: #303030;
@@ -246,7 +277,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
246
277
  font-size: 12px;
247
278
  font-family: initial;
248
279
  user-select: none;
249
- `,ot=n.div`
280
+ `,Rt=n.div`
250
281
  position: absolute;
251
282
  right: 10px;
252
283
  top: 1em;
@@ -260,17 +291,17 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
260
291
  &:hover {
261
292
  opacity: 1;
262
293
  }
263
- `,st=n.div`
294
+ `,zt=n.div`
264
295
  position: relative;
265
296
 
266
297
  &:hover {
267
- ${ot} {
298
+ ${Rt} {
268
299
  pointer-events: all;
269
300
  transform: translateX(0px);
270
301
  opacity: 0.7;
271
302
  }
272
303
  }
273
- `,at=n(H)`
304
+ `,It=n.div`
274
305
  -ms-text-size-adjust: 100%;
275
306
  -webkit-text-size-adjust: 100%;
276
307
  line-height: 1.8;
@@ -540,7 +571,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
540
571
  .hljs-strong {
541
572
  font-weight: 700;
542
573
  }
543
- `;var lt=M(function({children:e,tooltip:r,onClick:n,disabled:i,...o},a){i&&(n=void 0);const l=t(ct,{ref:a,onClick:n,$disabled:i,...o,children:e});return r?t(s,{tooltip:r,placement:"top",children:l}):l});const ct=n.div`
574
+ `;var Ft=z(function({children:t,tooltip:r,onClick:n,disabled:i,...o},a){i&&(n=void 0);const l=e(At,{ref:a,onClick:n,$disabled:i,...o,children:t});return r?e(s,{tooltip:r,placement:"top",children:l}):l});const At=n.div`
544
575
  align-items: center;
545
576
  justify-content: center;
546
577
  border-radius: .375rem;
@@ -573,7 +604,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
573
604
  `}
574
605
 
575
606
  }
576
- `,dt=k(null);var ht=dt.Provider;const ut=f.Image;function mt({src:e,...r}){const{imageResolver:n}=ce();return n&&e&&(e=n(e)),t(pt,{children:t(ut,{src:e,...r})})}const pt=n.div`
607
+ `,Dt=$(null);var Lt=Dt.Provider;const Tt=y.Image;function Pt({src:t,...r}){const{imageResolver:n}=Ne();return n&&t&&(t=n(t)),e(Ot,{children:e(Tt,{src:t,...r})})}const Ot=n.div`
577
608
  margin-bottom: .5rem;
578
609
  margin-top: .5rem;
579
610
  border: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color);
@@ -598,7 +629,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
598
629
  max-height: 100%;
599
630
  max-width: 100%;
600
631
  }
601
- `,gt=k(null);function bt(){const e=E(gt);if(!e)throw new Error("useContext must be used within a Provider");return e}function ft({children:e,...r}){return t(gt.Provider,{value:r,children:e})}function vt({description:r,options:n}){const{resume:i,disabled:o,output:s}=bt(),[a,l]=j(s?.result),c=o||void 0!==a;return e(xt,{children:[r&&t(yt,{children:r}),n.map((e,r)=>t(wt,{$selected:a===e,$disabled:c,onClick:()=>(e=>{c||(l(e),i(e))})(e),children:e},r))]})}const xt=n.div`
632
+ `,_t=$(null);function Bt(){const e=C(_t);if(!e)throw new Error("useContext must be used within a Provider");return e}function Ut({children:t,...r}){return e(_t.Provider,{value:r,children:t})}function Ht({description:r,options:n}){const{resume:i,disabled:o,response:s}=Bt(),[a,l]=S(s?.result),c=o||void 0!==a;return t(Jt,{children:[r&&e(Qt,{children:r}),n.map((t,r)=>e(Wt,{$selected:a===t,$disabled:c,onClick:()=>(e=>{c||(l(e),i(e))})(t),children:t},r))]})}const Jt=n.div`
602
633
  display: flex;
603
634
  flex-direction: column;
604
635
  gap: 0.5rem;
@@ -611,10 +642,10 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
611
642
  &:last-child {
612
643
  margin-bottom: 0;
613
644
  }
614
- `,yt=n.div`
645
+ `,Qt=n.div`
615
646
  color: var(--bs-secondary);
616
647
  line-height: 1.5;
617
- `,wt=n.div`
648
+ `,Wt=n.div`
618
649
  padding: 0.375rem 0.75rem;
619
650
  background-color: ${e=>e.$selected?"rgba(var(--bs-primary-rgb), 0.1)":"#FFFFFF"};
620
651
  border: 1px solid ${e=>e.$selected?"rgba(var(--bs-primary-rgb), 0.3)":"var(--bs-border-color)"};
@@ -633,11 +664,20 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
633
664
  &:active {
634
665
  transform: ${e=>e.$disabled?"none":"scale(0.98)"};
635
666
  }
636
- `;function kt({description:r,fields:n}){const{resume:i,disabled:o,output:s}=bt(),[a,l]=j(void 0!==s),d=o||a,{schema:h,uiSchema:u}=q(()=>{const e={},t=[],r={};for(const i of n)e[i.name]={type:"number"===i.type?"number":"string",title:i.label},i.placeholder&&(r[i.name]={"ui:placeholder":i.placeholder}),"textarea"===i.type?r[i.name]={...r[i.name],"ui:widget":"textarea"}:"select"===i.type&&i.options?(e[i.name].enum=i.options,e[i.name].enumNames=i.options):"email"===i.type?e[i.name].format="email":"date"===i.type?e[i.name].format="date":"tel"===i.type&&(r[i.name]={...r[i.name],"ui:options":{inputType:"tel"}}),i.required&&t.push(i.name);return{schema:{type:"object",properties:e,required:t},uiSchema:r}},[n]);return e(Et,{children:[r&&t(Nt,{children:r}),t(c,{schema:h,uiSchema:u,formData:s,onSubmit:({formData:e})=>{d||(l(!0),i(e))},disabled:d,validate:!0,showErrorList:!1,submitText:a?"已提交":"提交",omitExtraData:!0})]})}const Et=n.div`
667
+ `;function Xt({description:r,fields:n}){const{resume:i,disabled:o,response:s}=Bt(),[a,l]=S(void 0!==s),d=o||a,{schema:m,uiSchema:u}=I(()=>{const e={},t=[],r={};for(const i of n)e[i.name]={type:"number"===i.type?"number":"string",title:i.label},i.placeholder&&(r[i.name]={"ui:placeholder":i.placeholder}),"textarea"===i.type?r[i.name]={...r[i.name],"ui:widget":"textarea"}:"select"!==i.type&&"radio"!==i.type||!i.options?"checkbox"===i.type&&i.options?(e[i.name].type="array",e[i.name].uniqueItems=!0,e[i.name].items={type:"string",enum:i.options},r[i.name]={...r[i.name],"ui:widget":"checkboxes","ui:enumNames":i.options,"ui:inline":!0}):"email"===i.type?e[i.name].format="email":"date"===i.type?e[i.name].format="date":"tel"===i.type&&(r[i.name]={...r[i.name],"ui:options":{inputType:"tel"}}):(r[i.name]={...r[i.name],"ui:widget":i.type},e[i.name].enum=i.options,e[i.name].enumNames=i.options),i.required&&t.push(i.name);return{schema:{type:"object",properties:e,required:t},uiSchema:r}},[n]);return t(Kt,{className:"rounded bg-white shadow-sm",children:[r&&e(Vt,{children:r}),e(c,{schema:m,uiSchema:u,formData:s,onSubmit:({formData:e})=>{d||(l(!0),i(e))},disabled:d,validate:!0,showErrorList:!1,submitText:a?"已提交":"提交",omitExtraData:!0,children:({submit:t})=>e(Gt,{children:t})})]})}const Gt=n.div`
668
+ display: flex;
669
+ justify-content: flex-end;
670
+ border-top: 1px solid var(--bs-border-color);
671
+ padding-top: .5rem;
672
+ button {
673
+ padding: .25rem;
674
+ }
675
+ `,Kt=n.div`
637
676
  display: flex;
638
677
  flex-direction: column;
639
678
  gap: 0.5rem;
640
- margin: 1rem 0;
679
+ margin: .5rem 0;
680
+ padding: .5rem;
641
681
 
642
682
  .g-3 {
643
683
  --bs-gutter-y: .5rem !important;
@@ -650,10 +690,36 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
650
690
  &:last-child {
651
691
  margin-bottom: 0;
652
692
  }
653
- `,Nt=n.div`
693
+ `,Vt=n.div`
654
694
  color: var(--bs-secondary);
655
695
  line-height: 1.5;
656
- `;function jt({suspend:e}){const{readonly:r}=ce(),{index:n,chunk:i,isLastMessage:o}=function(){const e=E(dt);if(!e)throw new Error("useContext must be used within a Provider");return e}(),{resume:s}=he(),a=C(e=>{s({chunk:n,payload:e})},[]);let l=null;switch(e.type){case"select":l=t(vt,{...e.select});break;case"form":l=t(kt,{...e.form})}return t(ft,{resume:a,disabled:r||!!i.error||!o,output:i.node?.output,children:l})}function $t({value:e,cite:n}){const i=e=>"string"==typeof e?t(nt,{content:e,cite:n}):"image"===e.type?t(mt,{src:e.image}):"suspend"===e.type?t(jt,{suspend:e.suspend}):null;return Array.isArray(e)?t(r,{children:e.map((e,r)=>t(S,{children:i(e)},r))}):i(e)}const Ct=F(({reasoning:r,loading:n})=>{const[i,o]=j(!1);return N(()=>{n||o(!1)},[n]),t(S,{children:t("div",{className:"mb-2",children:e("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n?t(D,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:n?"思考中":"已思考"}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:t("div",{className:"border rounded bg-light p-2",children:t(nt,{content:r})})})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[n?t(D,{animation:"border",variant:"primary",size:"sm"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:n?"思考中":"已思考"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})})});class Mt{#t;#o=[];#s=0;constructor(){this.#t=new B}speak(){for(this.#t.emit("playing",!0);this.#s<this.#o.length;){const e=this.#o[this.#s],t=new SpeechSynthesisUtterance(e),r=++this.#s;t.onend=()=>{r>=this.#o.length&&this.clear()},t.onerror=()=>{this.clear()},window.speechSynthesis.speak(t)}}clear(){this.#t.emit("playing",!1)}start(e,t=!1){this.#o=Array.isArray(e)?e:[e],t||(window.speechSynthesis.cancel(),this.#s=0),this.speak()}stop(){window.speechSynthesis.cancel(),this.clear()}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}const qt=new Map;class zt{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new B}createLoader(e){const t=new Promise(async t=>{try{const{type:r,data:n}=await this.#r(e),i=new Audio(`data:${r};base64,${n}`);this.#a.set(e,i),t(i)}catch{this.#a.delete(e),t(void 0)}});return this.#a.set(e,t),t}async loadAudioData(){this.#c=!0,this.#t.emit("speaking",!0);let e=0;for(;e<this.#o.length;){const t=this.#o[e];!this.#a.has(t)&&this.#c&&await this.createLoader(t),e++}this.#t.emit("speaking",!1),this.#c=!1}waitForAudioLoaded(e){const t=this.#a.get(e);return t instanceof Promise?t:Promise.resolve(t)}async playAudio(e=0){this.#l=!0;const t=await this.waitForAudioLoaded(this.#o[e]);this.#t.emit("playing",!0),t?(qt.set(this,t),t.onpause=async()=>{t.ended?(this.#s++,this.#s<this.#o.length?await this.playAudio(this.#s):this.clear()):this.clear()},await t.play()):this.clear()}clear(){this.#l=!1,this.#c=!1,this.#t.emit("playing",!1),this.#t.emit("speaking",!1),qt.delete(this)}start(e,t=!1){qt.forEach((e,t)=>{t!==this&&(e.pause(),e.currentTime=0)}),this.#o=Array.isArray(e)?e:[e],t||(this.#s=0),this.#c||this.loadAudioData(),this.#l||this.playAudio()}update(e){this.#o=Array.isArray(e)?e:[e]}stop(){const e=qt.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function St({text:e,loading:t,loader:r}){const n=$(),[i,o]=j(!1),[s,a]=j(!1),l=$(t),c=async(i=!1)=>{n.current||(n.current=r?new zt(r):new Mt,n.current.onSpeaking(o),n.current.onPlaying(a));let s="";"string"==typeof e?s=e:e.current&&(s=function(e){const t=e.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li:not(:has(p,h1, h2, h3, h4, h5, h6))");return Array.from(t).flatMap(e=>e.textContent?[e.textContent]:[])}(e.current),t&&s.pop()),s&&0!==s.length&&n.current.start(s,i)};return N(()=>{if(l.current&&"string"!=typeof e&&e.current){if(t){const t={childList:!0,subtree:!0},r=new MutationObserver(function(){c(!0)});return r.observe(e.current,t),c(),()=>{r.disconnect()}}c(!0)}},[t]),N(()=>()=>{n.current&&(n.current.stop(),n.current=void 0)},[]),{playing:s,speaking:i,start:c,stop:()=>{n.current&&n.current.stop()}}}function Ft({model:r="builtin",voice:n,loading:i,autoplay:o,contentRef:s,avatarRef:a}){const{request:l}=ce(),c=q(()=>{if("builtin"!==r)return async e=>(await l({url:"/speech",method:"post",data:{model:r,voice:n,input:e}})).audio},[r,n]),{playing:d,speaking:h,start:u,stop:m}=St({loader:c,text:s,loading:o&&i});let p=null;return a.current&&(h&&(p=Z(t(Rt,{children:t(D,{size:"sm",variant:"light"})}),a.current)),d&&(p=Z(t(Rt,{children:t(At,{className:"bi bi-volume-down-fill text-light"})}),a.current))),e(lt,{disabled:i&&!d,onClick:()=>{d?m():u()},children:[d?t(At,{className:"bi bi-volume-down-fill"}):h?t(D,{size:"sm",variant:"primary"}):t(At,{className:"bi bi-volume-down"}),p]})}const Rt=n.div`
696
+ `;function Yt({content:r}){const{resume:n,disabled:i,response:o}=Bt(),[s,a]=S(void 0!==o),l=i||s;return t(Zt,{className:"rounded bg-white shadow-sm",children:[r&&e(er,{children:e(St,{content:r})}),e(tr,{children:e(w,{disabled:l,onClick:()=>{l||(a(!0),n("已确认"))},children:s?"已确认":"确认"})})]})}const Zt=n.div`
697
+ display: flex;
698
+ flex-direction: column;
699
+ gap: .5rem;
700
+ margin: .5rem 0;
701
+ padding: 1rem;
702
+
703
+ &:first-child {
704
+ margin-top: 0;
705
+ }
706
+
707
+ &:last-child {
708
+ margin-bottom: 0;
709
+ }
710
+ `,er=n.div`
711
+ line-height: 1.6;
712
+ color: var(--bs-body-color);
713
+ `,tr=n.div`
714
+ display: flex;
715
+ justify-content: flex-end;
716
+ border-top: 1px solid var(--bs-border-color);
717
+ margin: 0 -1rem -.5rem -1rem;
718
+ padding: .5rem .5rem 0 .5rem;
719
+ button {
720
+ padding: .25rem 1.5rem;
721
+ }
722
+ `;function rr({suspend:t}){const{readonly:r}=Ne(),{chunkIndex:n,chunk:i,toolIndex:o,tool:s,isLastMessage:a}=function(){const e=C(Dt);if(!e)throw new Error("useContext must be used within a Provider");return e}(),{resume:l}=Fe(),c=R(e=>{l({chunk:n,tool:o,payload:e})},[]);let d=null;switch(t.type){case"select":d=e(Ht,{...t.select});break;case"form":d=e(Xt,{...t.form});break;case"confirm":d=e(Yt,{...t.confirm})}const m=s?.response||i.node?.output;return e(Ut,{resume:c,disabled:r||!!i.error||!a,response:"(Empty)"===m?void 0:m,children:d})}function nr({value:t,cite:n}){const i=t=>"string"==typeof t?e(St,{content:t,cite:n}):"image"===t.type?e(Pt,{src:t.image}):"suspend"===t.type?e(rr,{suspend:t.suspend}):null;return Array.isArray(t)?e(r,{children:t.map((t,r)=>e(A,{children:i(t)},r))}):i(t)}const ir=({reasoning:r,loading:n})=>{const[i,o]=S(!1);return M(()=>{n||o(!1)},[n]),e(A,{children:e("div",{className:"mb-2",children:t("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[n?e(P,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:e("div",{className:"border rounded bg-light p-2",children:e(St,{content:r})})})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[n?e(P,{animation:"border",variant:"primary",size:"sm"}):e("i",{className:"bi bi-check-circle-fill text-success"}),e("span",{className:"text-muted",children:n?"思考中":"已思考"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})})},or=D(t=>{const{renderReasoning:r}=Ne();return r?r({Component:ir,props:t}):e(ir,{...t})});class sr{#t;#o=[];#s=0;constructor(){this.#t=new Q}speak(){for(this.#t.emit("playing",!0);this.#s<this.#o.length;){const e=this.#o[this.#s],t=new SpeechSynthesisUtterance(e),r=++this.#s;t.onend=()=>{r>=this.#o.length&&this.clear()},t.onerror=()=>{this.clear()},window.speechSynthesis.speak(t)}}clear(){this.#t.emit("playing",!1)}start(e,t=!1){this.#o=Array.isArray(e)?e:[e],t||(window.speechSynthesis.cancel(),this.#s=0),this.speak()}stop(){window.speechSynthesis.cancel(),this.clear()}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}const ar=new Map;class lr{#r;#t;#o=[];#a=new Map;#l=!1;#s=0;#c=!1;constructor(e){this.#r=e,this.#t=new Q}createLoader(e){const t=new Promise(async t=>{try{const{type:r,data:n}=await this.#r(e),i=new Audio(`data:${r};base64,${n}`);this.#a.set(e,i),t(i)}catch{this.#a.delete(e),t(void 0)}});return this.#a.set(e,t),t}async loadAudioData(){this.#c=!0,this.#t.emit("speaking",!0);let e=0;for(;e<this.#o.length;){const t=this.#o[e];!this.#a.has(t)&&this.#c&&await this.createLoader(t),e++}this.#t.emit("speaking",!1),this.#c=!1}waitForAudioLoaded(e){const t=this.#a.get(e);return t instanceof Promise?t:Promise.resolve(t)}async playAudio(e=0){this.#l=!0;const t=await this.waitForAudioLoaded(this.#o[e]);this.#t.emit("playing",!0),t?(ar.set(this,t),t.onpause=async()=>{t.ended?(this.#s++,this.#s<this.#o.length?await this.playAudio(this.#s):this.clear()):this.clear()},await t.play()):this.clear()}clear(){this.#l=!1,this.#c=!1,this.#t.emit("playing",!1),this.#t.emit("speaking",!1),ar.delete(this)}start(e,t=!1){ar.forEach((e,t)=>{t!==this&&(e.pause(),e.currentTime=0)}),this.#o=Array.isArray(e)?e:[e],t||(this.#s=0),this.#c||this.loadAudioData(),this.#l||this.playAudio()}update(e){this.#o=Array.isArray(e)?e:[e]}stop(){const e=ar.get(this);e&&(e.pause(),e.currentTime=0)}onPlaying(e){this.#t.on("playing",e)}onSpeaking(e){this.#t.on("speaking",e)}}function cr({text:e,loading:t,loader:r}){const n=q(),[i,o]=S(!1),[s,a]=S(!1),l=q(t),c=async(i=!1)=>{n.current||(n.current=r?new lr(r):new sr,n.current.onSpeaking(o),n.current.onPlaying(a));let s="";"string"==typeof e?s=e:e.current&&(s=function(e){const t=e.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li:not(:has(p,h1, h2, h3, h4, h5, h6))");return Array.from(t).flatMap(e=>e.textContent?[e.textContent]:[])}(e.current),t&&s.pop()),s&&0!==s.length&&n.current.start(s,i)};return M(()=>{if(l.current&&"string"!=typeof e&&e.current){if(t){const t={childList:!0,subtree:!0},r=new MutationObserver(function(){c(!0)});return r.observe(e.current,t),c(),()=>{r.disconnect()}}c(!0)}},[t]),M(()=>()=>{n.current&&(n.current.stop(),n.current=void 0)},[]),{playing:s,speaking:i,start:c,stop:()=>{n.current&&n.current.stop()}}}function dr({model:r="builtin",voice:n,loading:i,autoplay:o,contentRef:s,avatarRef:a}){const{request:l}=Ne(),c=I(()=>{if("builtin"!==r)return async e=>(await l({url:"/speech",method:"post",data:{model:r,voice:n,input:e}})).audio},[r,n]),{playing:d,speaking:m,start:u,stop:h}=cr({loader:c,text:s,loading:o&&i});let p=null;return a.current&&(m&&(p=fe(e(mr,{children:e(P,{size:"sm",variant:"light"})}),a.current)),d&&(p=fe(e(mr,{children:e(ur,{className:"bi bi-volume-down-fill text-light"})}),a.current))),t(Ft,{disabled:i&&!d,onClick:()=>{d?h():u()},children:[d?e(ur,{className:"bi bi-volume-down-fill"}):m?e(P,{size:"sm",variant:"primary"}):e(ur,{className:"bi bi-volume-down"}),p]})}const mr=n.div`
657
723
  position: absolute;
658
724
  top: 0;
659
725
  left: 0;
@@ -663,20 +729,27 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
663
729
  align-items: center;
664
730
  justify-content: center;
665
731
  background-color: rgba(0, 0, 0, .3);
666
- `,At=n.i`
732
+ `,ur=n.i`
667
733
 
668
734
  &::before {
669
735
  transform: scale(1.4)
670
736
  }
671
- `;function It({tool:r,loading:n}){const[i,o]=j(!1),{logLevel:s="none"}=ce(),a="response"in r,l=!a&&!n;return e(S,{children:["stats"==s&&t("div",{className:"mb-2",children:e("div",{role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l?t("i",{className:"bi bi-dash-circle-fill text-muted"}):a?r.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(D,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:l?"已取消":a?"已使用":"正在使用"}),t("span",{children:r.title})]})}),"all"==s&&t("div",{className:"mb-2",children:e("div",i&&a?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[r.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}),t("span",{className:"text-muted",children:"已使用"}),t("span",{children:r.title}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"参数"})}),t("div",{className:"border-top p-2 overflow-hidden",children:r.arguments})]}),e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"响应"})}),t(Dt,{className:"border-top p-2 overflow-hidden",children:r.response||"None"})]})]})]}:{onClick:()=>o(a),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[l?t("i",{className:"bi bi-dash-circle-fill text-muted"}):a?r.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"}):t(D,{animation:"border",variant:"primary",size:"sm"}),t("span",{className:"text-muted",children:l?"已取消":a?"已使用":"正在使用"}),t("span",{children:r.title}),a&&t("i",{className:"bi bi-caret-down-fill text-muted"})]})}),r.content&&t($t,{value:r.content})]})}const Dt=n.div`
737
+ `;function hr({tool:r,loading:n}){const{logLevel:i="none",renderToolContent:o}=Ne(),s="response"in r,a=!s&&!n,{response:l,title:c,content:d,showStatus:m,defaultExpanded:u}=I(()=>{const n=(e=>{try{return JSON.parse(e.arguments)}catch(e){return null}})(r),i=e("span",{className:"text-truncate",children:r.title}),a=t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"参数"})}),e(gr,{className:"border-top p-2",children:r.arguments})]}),s&&t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"响应"})}),e(gr,{className:"border-top p-2",children:r.response||"None"})]})]}),l=r.content&&e(nr,{value:r.content});if(o){const e=o({tool:r,args:n});if(e)return{title:null===e.title?null:e.title??i,response:null===e.response?null:e.response??a,content:null===e.content?null:e.content??l,showStatus:e.showStatus??!0,defaultExpanded:e.defaultExpanded??!1}}return{title:i,response:a,content:l,showStatus:!0,defaultExpanded:!1}},[r,o]),[h,p]=S(u),g="all"==i&&null!==l;return t(A,{children:[c&&e("div",{className:"mb-2",children:t(pr,{className:"shadow-sm rounded bg-white fs-7",$open:h,children:[t("div",{onClick:()=>p(g&&!h),role:"button",className:"d-flex align-items-center flex-nowrap p-1 px-2 gap-2",children:[a?e("i",{className:"bi bi-dash-circle-fill text-muted"}):s?r.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"}):e(P,{animation:"border",variant:"primary",size:"sm"}),m&&e("span",{className:"text-muted",children:a?"已取消":s?"已使用":"正在使用"}),c,g&&e("i",h?{className:"bi bi-caret-up-fill text-muted"}:{className:"bi bi-caret-down-fill text-muted"})]}),h&&l]})}),d]})}const pr=n.div`
738
+ width: ${e=>e.$open?"auto":"fit-content"};
739
+ max-width: 100%;
740
+ overflow:hidden;
741
+ `,gr=n.div`
672
742
  white-space: pre-wrap;
673
- `;function Lt({node:r}){const[n,i]=j(!1),{nodeIconResolver:o}=ce(),s=!("latency"in r),a=s?t(D,{animation:"border",variant:"primary",size:"sm"}):r.error?t("i",{className:"bi bi-x-circle-fill text-danger"}):t("i",{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"shadow-sm rounded bg-white fs-7",children:[e(Tt,{onClick:()=>i(e=>!e),role:"button",className:"d-flex align-items-center p-1 px-2 gap-1",children:[t("i",{className:"bi bi-chevron-down text-muted"}),o?.(r.type),t(Ot,{className:"me-2 text-truncate",children:r.title}),t("span",{className:"me-auto"}),!s&&t("span",{className:"text-nowrap text-muted",children:Pt(r.latency)}),t("span",{children:a})]}),n&&e("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"输入"})}),t("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.input?JSON.stringify(r.input,null,4):"None"})]}),e("div",{className:"border rounded bg-light",children:[t("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:t("span",{className:"text-muted",children:"输出"})}),t("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.output?JSON.stringify(r.output,null,4):"None"})]})]})]})}const Pt=e=>e<1?`${(1e3*e).toFixed(3)} ms`:e>60?`${parseInt(Math.round(e/60).toString())} m ${(e%60).toFixed(3)} s`:`${e.toFixed(3)} s`,Tt=n.div`
743
+ overflow-y: auto;
744
+ overflow-x: hidden;
745
+ max-height: 150px;
746
+ `;function fr({node:r}){const[n,i]=S(!1),{nodeIconResolver:o}=Ne(),s=!("latency"in r),a=s?e(P,{animation:"border",variant:"primary",size:"sm"}):r.error?e("i",{className:"bi bi-x-circle-fill text-danger"}):e("i",{className:"bi bi-check-circle-fill text-success"});return t("div",{className:"shadow-sm rounded bg-white fs-7",children:[t(vr,{onClick:()=>i(e=>!e),role:"button",className:"d-flex align-items-center p-1 px-2 gap-1",children:[e("i",{className:"bi bi-chevron-down text-muted"}),o?.(r.type),e(xr,{className:"me-2 text-truncate",children:r.title}),e("span",{className:"me-auto"}),!s&&e("span",{className:"text-nowrap text-muted",children:br(r.latency)}),e("span",{children:a})]}),n&&t("div",{className:"border-top p-2 d-flex flex-column gap-2",children:[t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"输入"})}),e("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.input?JSON.stringify(r.input,null,4):"None"})]}),t("div",{className:"border rounded bg-light",children:[e("div",{className:"d-flex align-items-center p-1 px-2 fs-7 gap-2",children:e("span",{className:"text-muted",children:"输出"})}),e("div",{className:"border-top p-2 overflow-hidden text-pre-wrap",children:r.output?JSON.stringify(r.output,null,4):"None"})]})]})]})}const br=e=>e<1?`${(1e3*e).toFixed(3)} ms`:e>60?`${parseInt(Math.round(e/60).toString())} m ${(e%60).toFixed(3)} s`:`${e.toFixed(3)} s`,vr=n.div`
674
747
  svg {
675
748
  flex-shrink: 0;
676
749
  }
677
- `,Ot=n.span`
750
+ `,xr=n.span`
678
751
  display: inline-block;
679
- `;function Bt({nodes:r,loading:n}){const[i,o]=j(!1),s=r.some(e=>"error"in e),a=n?t(D,{animation:"border",variant:"primary",size:"sm"}):t("i",s?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return t("div",{className:"mb-2",children:e("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[e("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[a,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-up-fill text-muted"})]}),t("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:r.map((e,r)=>t(Lt,{node:e},r))})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[a,t("span",{children:"工作流"}),t("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const _t=F(({message:n,actions:i,setMessage:o,cite:s,speech:a,isLast:l})=>{const{query:c,quote:d,files:h=[],chunks:u,annotation:m,loading:p}=n,{user:g,bot:b,logLevel:f="none",messages:y}=ce(),w=q(()=>u?u.reduce(function(e,t){const r=Array.isArray(t.content)?t.content.reduce((e,t)=>{const r=Ve(t);return r?e+r+"\n":e},""):Ve(t.content);return e+r+"\n"+(t.tools||[]).reduce((e,t)=>{if(t.content){const r=Ve(t.content);if(r)return e+r+"\n"}return e},"")},""):"",[u]),k=$(null),E=$(null),N=$(null),j=q(()=>u?.flatMap(e=>e.node?[e.node]:[])||[],[u]),C=c||h.length>0;return e(r,{children:[C&&e(Zt,{$reverse:!0,children:[g&&t(Vt,{children:t("img",{src:g.avatar})}),t(Yt,{}),e(Gt,{ref:k,children:[c&&t(nt,{content:c}),d&&t(T,{trigger:"click",container:k,rootClose:!0,placement:"bottom",overlay:t(Ut,{body:!0,children:d}),children:t(Jt,{children:t(Ht,{children:d})})}),h.length>0&&h.map(({name:e,size:r,path:n},i)=>x(n)?t(mt,{src:`/uploads/${n}`},i):t(Qt,{children:t(re,{name:e,size:r})},i))]})]}),u&&e(Zt,{children:[b&&t(Vt,{ref:E,children:t("img",{src:b.avatar})}),t(Yt,{}),e(Gt,{children:[C&&!1!==i&&e(Wt,{children:[t(v,{placement:"top",content:w,as:lt,tooltip:!0}),a&&t(Ft,{loading:n.loading,avatarRef:E,contentRef:N,...a}),i?.({Component:lt,message:n,content:w,setMessage:o,messages:y})]}),t(Xt,{children:["stats","all"].includes(f)&&n.stats&&e(r,{children:[e("span",{children:["耗时 ",n.stats.latency/1e3," 秒"]}),e("span",{children:["花费 Token ",n.stats.usage]})]})}),e(Kt,{ref:N,$deleted:!!m,children:["all"===f&&j.length>0&&t(Bt,{loading:p,nodes:j}),u.map((r,n)=>e(ht,{value:{index:n,chunk:r,isLastMessage:l},children:[r.reasoning&&["stats","all"].includes(f)&&t(Ct,{reasoning:r.reasoning,loading:!r.content&&0===(r.tools||[]).length}),r.content&&t($t,{cite:s,value:r.content}),(r.tools||[]).map((e,r)=>t(It,{tool:e,loading:p},r)),r.error&&t(nt,{content:`[${r.error}]`})]},n))]}),m&&e("div",{children:[e("div",{className:"d-flex align-items-center",children:[t("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),t("hr",{className:"flex-fill"})]}),t(nt,{content:m.answer})]}),n.loading&&t(Xe,{})]})]})]})}),Ut=n(O)`
752
+ `;function yr({nodes:r,loading:n}){const[i,o]=S(!1),s=r.some(e=>"error"in e),a=n?e(P,{animation:"border",variant:"primary",size:"sm"}):e("i",s?{className:"bi bi-x-circle-fill text-danger"}:{className:"bi bi-check-circle-fill text-success"});return e("div",{className:"mb-2",children:t("div",i?{className:"shadow-sm rounded bg-white fs-7",children:[t("div",{onClick:()=>o(!1),role:"button",className:"d-flex align-items-center p-1 px-2 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-up-fill text-muted"})]}),e("div",{className:"border-top p-2 d-flex flex-column gap-1 bg-light bg-opacity-50",children:r.map((t,r)=>e(fr,{node:t},r))})]}:{onClick:()=>o(!0),role:"button",className:"d-inline-flex align-items-center shadow-sm rounded bg-white p-1 px-2 fs-7 gap-2",children:[a,e("span",{children:"工作流"}),e("i",{className:"bi bi-caret-down-fill text-muted"})]})})}const kr=D(({message:n,actions:i,setMessage:o,cite:s,speech:a,isLast:l})=>{const{query:c,quote:d,files:m=[],chunks:u,annotation:h,loading:p}=n,{user:g,bot:f,logLevel:b="none",messages:v}=Ne(),x=I(()=>u?u.reduce(function(e,t){const r=Array.isArray(t.content)?t.content.reduce((e,t)=>{const r=wt(t);return r?e+r+"\n":e},""):wt(t.content);return e+r+"\n"+(t.tools||[]).reduce((e,t)=>{if(t.content){const r=wt(t.content);if(r)return e+r+"\n"}return e},"")},""):"",[u]),y=q(null),w=q(null),N=q(null),j=I(()=>u?.flatMap(e=>e.node?[e.node]:[])||[],[u]),$=c||m.length>0;return t(r,{children:[$&&t(zr,{$reverse:!0,children:[g&&e(Sr,{children:e("img",{src:g.avatar})}),e(qr,{}),t(Rr,{ref:y,children:[c&&e(St,{content:c}),d&&e(H,{trigger:"click",container:y,rootClose:!0,placement:"bottom",overlay:e(wr,{body:!0,children:d}),children:e(Nr,{children:e(Er,{children:d})})}),m.length>0&&m.map(({name:t,size:r,path:n},i)=>E(n)?e(Pt,{src:`/uploads/${n}`},i):e($r,{children:e(Me,{name:t,url:`/uploads/${n}`,size:r})},i))]})]}),u&&t(zr,{children:[f&&e(Sr,{ref:w,children:e("img",{src:f.avatar})}),e(qr,{}),t(Rr,{children:[$&&!1!==i&&t(Cr,{children:[e(k,{placement:"top",content:x,as:Ft,tooltip:!0}),a&&e(dr,{loading:n.loading,avatarRef:w,contentRef:N,...a}),i?.({Component:Ft,message:n,content:x,setMessage:o,messages:v})]}),e(Mr,{children:["stats","all"].includes(b)&&n.stats&&t(r,{children:[t("span",{children:["耗时 ",n.stats.latency/1e3," 秒"]}),t("span",{children:["花费 Token ",n.stats.usage]})]})}),t(jr,{ref:N,$deleted:!!h,children:["all"===b&&j.length>0&&e(yr,{loading:p,nodes:j}),u.map((r,n)=>t(A,{children:[r.reasoning&&["stats","all"].includes(b)&&e(or,{reasoning:r.reasoning,loading:!r.content&&0===(r.tools||[]).length}),r.content&&e(Lt,{value:{chunkIndex:n,chunk:r,isLastMessage:l},children:e(nr,{cite:s,value:r.content})}),(r.tools||[]).map((t,i)=>e(Lt,{value:{chunkIndex:n,chunk:r,toolIndex:i,tool:t,isLastMessage:l},children:e(hr,{tool:t,loading:p})},i)),r.error&&e(St,{content:`[${r.error}]`})]},n))]}),h&&t("div",{children:[t("div",{className:"d-flex align-items-center",children:[e("span",{className:"fs-7 text-secondary me-2",children:"标注的答案"}),e("hr",{className:"flex-fill"})]}),e(St,{content:h.answer})]}),n.loading&&e(kt,{})]})]})]})}),wr=n(J)`
680
753
  max-width: calc(100% - .875rem * 2);
681
754
  width: calc(100% - .875rem * 2);
682
755
  font-size: 1rem;
@@ -685,25 +758,25 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
685
758
  .popover-body {
686
759
  padding: .5rem .75rem;
687
760
  }
688
- `,Ht=n.div`
761
+ `,Er=n.div`
689
762
  overflow: hidden;
690
763
  text-overflow: ellipsis;
691
764
  word-break: break-all;
692
765
  -webkit-line-clamp: 2;
693
766
  -webkit-box-orient: vertical;
694
767
  display: -webkit-box;
695
- `,Jt=n.div`
768
+ `,Nr=n.div`
696
769
  padding: .5rem .75rem;
697
770
  color: var(--bs-secondary);
698
771
  border-radius: var(--bs-border-radius-lg);
699
772
  background: #FFFFFF;
700
773
  cursor: pointer;
701
- `,Kt=n.div`
774
+ `,jr=n.div`
702
775
  ${e=>e.$deleted&&i`
703
776
  text-decoration-line: line-through;
704
777
  color: var(--bs-secondary);
705
778
  `}
706
- `,Qt=n.div`
779
+ `,$r=n.div`
707
780
  width: 100%;
708
781
  margin-bottom: .5rem;
709
782
  margin-top: .5rem;
@@ -715,7 +788,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
715
788
  &:last-child {
716
789
  margin-bottom: 0;
717
790
  }
718
- `,Wt=n.div`
791
+ `,Cr=n.div`
719
792
  position: absolute;
720
793
  top: -1.1rem;
721
794
  right: 0;
@@ -723,7 +796,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
723
796
  gap: .5rem;
724
797
  opacity: 0;
725
798
  z-index: 1;
726
- `,Xt=n.div`
799
+ `,Mr=n.div`
727
800
  position: absolute;
728
801
  bottom: -1.4rem;
729
802
  left: 0;
@@ -736,7 +809,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
736
809
  display: flex;
737
810
  opacity: 0;
738
811
  z-index: 1;
739
- `,Vt=n.div`
812
+ `,Sr=n.div`
740
813
  width: 35px;
741
814
  height: 35px;
742
815
  border-radius: 50%;
@@ -747,14 +820,14 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
747
820
  width: 100%;
748
821
  height: 100%;
749
822
  }
750
- `,Yt=n.div`
823
+ `,qr=n.div`
751
824
  width: 0;
752
825
  height: 0;
753
826
  content: "";
754
827
  border: 5px solid transparent;
755
828
  border-right-color: #f3f3f3;
756
829
  transform: translateY(10px);
757
- `,Gt=n.div`
830
+ `,Rr=n.div`
758
831
  padding: .875rem;
759
832
  background-color: rgb(243, 243, 243);
760
833
  border-radius: var(--bs-border-radius-lg);
@@ -762,31 +835,31 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
762
835
  position: relative;
763
836
 
764
837
  &:hover {
765
- ${Xt}, ${Wt} {
838
+ ${Mr}, ${Cr} {
766
839
  opacity: 1;
767
840
  }
768
841
  }
769
- `,Zt=n.div`
842
+ `,zr=n.div`
770
843
  display: flex;
771
844
  justify-content: flex-start;
772
845
  padding: 1rem 0 1rem 0;
773
846
  ${e=>e.$reverse&&i`
774
847
  flex-direction: row-reverse;
775
848
 
776
- ${Yt} {
849
+ ${qr} {
777
850
  border-left-color: rgba(var(--bs-primary-rgb), 0.1);
778
851
  border-right-color: transparent;
779
852
  }
780
853
 
781
- ${Gt} {
854
+ ${Rr} {
782
855
  background: rgba(var(--bs-primary-rgb), 0.1);
783
856
  }
784
857
  `};
785
- `;function er(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a,scrollRef:l}=r,{messages:c,setMessages:d,loading:h,suggestions:u,conversationId:m}=ce(),p=$(r.loaded),g=C(()=>{const e=l.current;e&&requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight})})},[]),b=$(null),{height:f}=ee({ref:b});N(()=>{(h||!p.current)&&c.length>0&&(h&&(p.current=!0),g())},[f,h,p,c]),N(()=>{u.length>0&&g()},[u]),N(()=>{p.current=r.loaded},[m]),N(()=>{const e=b.current;if(e){const t=()=>{p.current=!0};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[b]);const v=c.slice(-30);return e(tr,{ref:b,children:[0===v.length&&n,v.map((e,r)=>{const n={actions:i,cite:o,speech:s,message:e,setMessage:t=>{d(r=>{const n=r.findIndex(t=>t.id===e.id);-1!==n&&t(r[n])})},isLast:r===v.length-1};return a?a({Component:_t,props:n},r):t(_t,{...n},r)}),u.length>0&&t(rr,{children:u.map((e,r)=>t("a",{href:"#!question",children:e},r))})]})}const tr=n.div`
858
+ `;function Ir(r){const{placeholder:n,actions:i,cite:o,speech:s,renderItem:a,scrollRef:l}=r,{messages:c,setMessages:d,loading:m,suggestions:u,conversationId:h}=Ne(),p=q(r.loaded),g=R(()=>{const e=l.current;e&&requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight})})},[]),f=q(null),{height:b}=be({ref:f});M(()=>{(m||!p.current)&&c.length>0&&(m&&(p.current=!0),g())},[b,m,p,c]),M(()=>{u.length>0&&g()},[u]),M(()=>{p.current=r.loaded},[h]),M(()=>{const e=f.current;if(e){const t=()=>{p.current=!0};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}},[f]);const v=c.slice(-30);return t(Fr,{ref:f,children:[0===v.length&&n,v.map((t,r)=>{const n={actions:i,cite:o,speech:s,message:t,setMessage:e=>{d(r=>{const n=r.findIndex(e=>e.id===t.id);-1!==n&&e(r[n])})},isLast:r===v.length-1};return a?a({Component:kr,props:n},r):e(kr,{...n},r)}),u.length>0&&e(Ar,{children:u.map((t,r)=>e("a",{href:"#!question",children:t},r))})]})}const Fr=n.div`
786
859
  display: flex;
787
860
  flex-direction: column;
788
861
  flex: 1;
789
- `,rr=n.div`
862
+ `,Ar=n.div`
790
863
  display: flex;
791
864
  flex-direction: column;
792
865
  align-items: flex-start;
@@ -803,16 +876,16 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
803
876
  background: var(--bs-secondary-bg-subtle);
804
877
  }
805
878
  }
806
- `,nr=F(M(({className:r,bot:n,user:i,input:o,logLevel:s,imageResolver:a,nodeIconResolver:l,placeholder:c,actions:d,onboarding:h,conversation:u,cite:m,speech:p,renderItem:b,messages:v,request:x,transformMessages:w=Ue},k)=>{const E=C(e=>{const t=[];if(h&&!1!==h.enable){const e=He(h.questions||[]);t.push({chunks:[{content:[h.prologue,...e.map(e=>`[${e}](#!question)`)].join("\n"),tools:[]}],loading:h.loading})}return e?t.concat(w(e.messages||[])):v?t.concat(w(v)):t},[h]),[M,S]=j(u?.id),[F,R]=g([]);N(()=>{R(E(u))},[h]);const[A,I]=j(!1),D=$(null),[L,P]=j([]),T=C(e=>{A||(S(e?.id),R(E(e)),P([]))},[A,E]);return z(k,()=>({reset:T}),[T]),t(de,{request:q(()=>x?"string"==typeof x?y.create({baseURL:x}):x:y,[x]),bot:n,user:i,logLevel:s,imageResolver:a,nodeIconResolver:l,conversationId:M,setConversationId:S,messages:F,setMessages:R,suggestions:L,setSuggestions:P,loading:A,setLoading:I,reset:T,readonly:!o,children:t(or,{className:r,children:e(f,{children:[t(ir,{ref:D,children:t(er,{placeholder:c,cite:m,actions:d,loaded:!o,speech:p,renderItem:b,scrollRef:D})}),o&&t(Ae,{...o,scrollRef:D})]})})})}),_),ir=n.div`
879
+ `,Dr=D(z(({className:r,bot:n,user:i,input:o,logLevel:s,imageResolver:a,nodeIconResolver:l,placeholder:c,actions:d,onboarding:m,conversation:u,cite:h,speech:p,renderItem:g,renderFileItem:f,renderToolContent:v,renderReasoning:x,messages:k,request:w,onReset:E,transformMessages:j=gt},$)=>{const C=R(e=>{const t=[];if(m&&!1!==m.enable){const e=ft(m.questions||[]);t.push({chunks:[{content:[m.prologue,...e.map(e=>`[${e}](#!question)`)].join("\n"),tools:[]}],loading:m.loading})}return e?t.concat(j(e.messages||[])):k?t.concat(j(k)):t},[m]),[z,A]=S(u?.id),[D,L]=S(),[T,P]=b([]);M(()=>{P(C(u))},[m]);const[O,_]=S(!1),B=q(null),[U,H]=S([]),J=R(e=>{A(e?.id),P(C(e)),H([]),_(!1),E?.(e)},[O,C,E]);return F($,()=>({reset:J}),[J]),e(je,{request:I(()=>w?"string"==typeof w?N.create({baseURL:w}):w:N,[w]),bot:n,user:i,logLevel:s,imageResolver:a,nodeIconResolver:l,conversationId:z,setConversationId:A,input:D,setInput:L,messages:T,setMessages:P,suggestions:U,setSuggestions:H,loading:O,setLoading:_,renderFileItem:f,reset:J,readonly:!o,renderToolContent:v,renderReasoning:x,children:e(Tr,{className:r,children:t(y,{children:[e(Lr,{ref:B,children:e(Ir,{placeholder:c,cite:h,actions:d,loaded:!o,speech:p,renderItem:g,scrollRef:B})}),o&&e(it,{...o,scrollRef:B})]})})})}),oe),Lr=n.div`
807
880
  display: flex;
808
881
  flex-direction: column;
809
882
  flex: 1;
810
883
  overflow-y: auto;
811
884
  padding: 0 1rem;
812
885
  margin-bottom: .5rem;
813
- `,or=n.div`
886
+ `,Tr=n.div`
814
887
  display: flex;
815
888
  flex-direction: column;
816
889
  height: 100%;
817
890
  position: relative;
818
- `;export{ve as ActionButton,nt as Markdown,nr as MessageBox,ue as VariableForm,He as pickQuestions,St as useSynthesis};
891
+ `;async function Pr(e){const t=await ve().use(ye).use(de).use(me).use(ue).use(ke).use(xe).process(e);return String(t)}export{_e as ActionButton,Me as FileItem,St as Markdown,Dr as MessageBox,Ae as VariableForm,we as isToolMessage,Pr as md2html,ft as pickQuestions,Ne as useMessageContext,cr as useSynthesis};
@@ -0,0 +1 @@
1
+ import*as c from"react";var h,l,e;function t(){return t=Object.assign?Object.assign.bind():function(c){for(var h=1;h<arguments.length;h++){var l=arguments[h];for(var e in l)({}).hasOwnProperty.call(l,e)&&(c[e]=l[e])}return c},t.apply(null,arguments)}const a=a=>c.createElement("svg",t({xmlns:"http://www.w3.org/2000/svg",width:200,height:200,className:"mp3_svg__icon",viewBox:"0 0 1024 1024"},a),h||(h=c.createElement("path",{fill:"#B37FEB",d:"m590.222 73.956 268.8 268.299v533.834c0 37.7-30.566 68.267-68.266 68.267H233.244c-37.7 0-68.266-30.567-68.266-68.267V142.222c0-37.7 30.566-68.266 68.266-68.266zM578.458 102.4H233.244a39.82 39.82 0 0 0-39.799 38.457l-.023 1.365V876.09a39.82 39.82 0 0 0 38.457 39.8l1.365.022h557.512a39.82 39.82 0 0 0 39.799-38.457l.023-1.365V354.054z"})),l||(l=c.createElement("path",{fill:"#B37FEB",d:"M854.756 370.648H639.613c-45.528 0-82.551-36.431-83.507-81.738l-.017-1.792V73.956h28.444v213.162c0 29.895 23.82 54.232 53.516 55.063l1.564.023h215.143zM85.333 489.244h853.334q28.444 0 28.444 28.445v284.444q0 28.445-28.444 28.445H85.333q-28.444 0-28.444-28.445V517.69q0-28.445 28.444-28.445"})),e||(e=c.createElement("path",{fill:"#FFF",d:"M291.146 750.933v-65.28c0-18.944-3.584-47.36-5.888-66.048h1.024l15.36 45.568 25.85 69.632h25.088l25.6-69.632 15.872-45.568h1.286c-2.56 18.688-6.144 47.104-6.144 66.048v65.28h41.728v-190.72h-49.664l-29.184 82.432c-3.584 11.008-6.656 23.04-10.502 34.56h-1.274c-3.584-11.52-6.656-23.552-10.502-34.56l-30.208-82.432h-49.402v190.72zm250.624-190.72c41.722 0 76.288 15.104 76.288 62.208 0 45.312-34.816 65.28-75.264 65.28h-22.272v63.232h-45.83v-190.72zm-2.56 36.352h-18.688v55.04h19.968c22.272 0 33.024-10.496 33.024-29.184 0-19.2-12.288-25.856-34.304-25.856m160.768 157.952c37.888 0 70.394-19.456 70.394-54.272 0-23.808-15.61-38.912-36.608-45.056v-1.28c19.968-8.448 30.47-22.272 30.47-40.96 0-32.768-25.862-51.456-65.28-51.456-22.528 0-41.472 9.216-59.136 23.808l23.04 27.904c11.52-10.24 21.242-16.128 34.042-16.128 14.086 0 21.766 6.912 21.766 19.456 0 13.824-10.24 23.552-42.758 23.552v32.256c39.936 0 48.64 9.216 48.64 24.832 0 13.312-11.514 20.48-29.184 20.48-14.848 0-28.16-7.68-39.68-18.432l-20.992 28.672c13.824 16.128 35.078 26.624 65.286 26.624"})));var v="data:image/svg+xml,%3csvg t='1767873372939' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='1312' width='200' height='200'%3e%3cpath d='M590.222222 73.955556L859.022222 342.254933V876.088889c0 37.700267-30.5664 68.266667-68.266666 68.266667H233.244444c-37.700267 0-68.266667-30.5664-68.266666-68.266667V142.222222c0-37.700267 30.5664-68.266667 68.266666-68.266666h356.977778z m-11.764622 28.444444H233.244444a39.822222 39.822222 0 0 0-39.799466 38.456889L193.422222 142.222222v733.866667a39.822222 39.822222 0 0 0 38.456889 39.799467L233.244444 915.911111h557.511112a39.822222 39.822222 0 0 0 39.799466-38.456889L830.577778 876.088889V354.053689L578.4576 102.4z' fill='%23B37FEB' p-id='1313'%3e%3c/path%3e%3cpath d='M854.755556 370.648178h-215.1424c-45.528178 0-82.551467-36.431644-83.5072-81.737956l-0.017067-1.792V73.955556h28.444444v213.162666c0 29.895111 23.819378 54.232178 53.515378 55.062756l1.564445 0.022755h215.1424v28.444445z' fill='%23B37FEB' p-id='1314'%3e%3c/path%3e%3cpath d='M56.888889 489.244444m28.444444 0l853.333334 0q28.444444 0 28.444444 28.444445l0 284.444444q0 28.444444-28.444444 28.444445l-853.333334 0q-28.444444 0-28.444444-28.444445l0-284.444444q0-28.444444 28.444444-28.444445Z' fill='%23B37FEB' p-id='1315'%3e%3c/path%3e%3cpath d='M291.145956 750.933333v-65.28c0-18.944-3.584-47.36-5.888-66.048h1.024l15.36 45.568 25.850311 69.632h25.088l25.6-69.632 15.872-45.568h1.285689c-2.56 18.688-6.144 47.104-6.144 66.048V750.933333h41.728V560.213333h-49.664l-29.184 82.432c-3.584 11.008-6.656 23.04-10.501689 34.56h-1.274311c-3.584-11.52-6.656-23.552-10.501689-34.56l-30.208-82.432h-49.402311V750.933333h40.96zM541.769956 560.213333c41.722311 0 76.288 15.104 76.288 62.208 0 45.312-34.816 65.28-75.264 65.28h-22.272V750.933333h-45.829689V560.213333z m-2.56 36.352h-18.688v55.04h19.968c22.272 0 33.024-10.496 33.024-29.184 0-19.2-12.288-25.856-34.304-25.856zM699.977956 754.517333c37.888 0 70.394311-19.456 70.394311-54.272 0-23.808-15.610311-38.912-36.608-45.056v-1.28c19.968-8.448 30.469689-22.272 30.469689-40.96 0-32.768-25.861689-51.456-65.28-51.456-22.528 0-41.472 9.216-59.136 23.808l23.04 27.904c11.52-10.24 21.242311-16.128 34.042311-16.128 14.085689 0 21.765689 6.912 21.765689 19.456 0 13.824-10.24 23.552-42.757689 23.552v32.256c39.936 0 48.64 9.216 48.64 24.832 0 13.312-11.514311 20.48-29.184 20.48-14.848 0-28.16-7.68-39.68-18.432l-20.992 28.672c13.824 16.128 35.077689 26.624 65.285689 26.624z' fill='white' p-id='1316'%3e%3c/path%3e%3c/svg%3e";export{a as ReactComponent,v as default};
@@ -0,0 +1 @@
1
+ import*as h from"react";var l,c,e,t;function a(){return a=Object.assign?Object.assign.bind():function(h){for(var l=1;l<arguments.length;l++){var c=arguments[l];for(var e in c)({}).hasOwnProperty.call(c,e)&&(h[e]=c[e])}return h},a.apply(null,arguments)}const v=v=>h.createElement("svg",a({xmlns:"http://www.w3.org/2000/svg",width:200,height:200,className:"mp4_svg__icon",viewBox:"0 0 1024 1024"},v),l||(l=h.createElement("path",{fill:"#597EF7",d:"m590.222 73.956 268.8 268.299v533.834c0 37.7-30.566 68.267-68.266 68.267H233.244c-37.7 0-68.266-30.567-68.266-68.267V142.222c0-37.7 30.566-68.266 68.266-68.266zM578.458 102.4H233.244a39.82 39.82 0 0 0-39.799 38.457l-.023 1.365V876.09a39.82 39.82 0 0 0 38.457 39.8l1.365.022h557.512a39.82 39.82 0 0 0 39.799-38.457l.023-1.365V354.054z"})),c||(c=h.createElement("path",{fill:"#597EF7",d:"M854.756 370.648H639.613c-45.528 0-82.551-36.431-83.507-81.738l-.017-1.792V73.956h28.444v213.162c0 29.895 23.82 54.232 53.516 55.063l1.564.023h215.143zM85.333 489.244h853.334q28.444 0 28.444 28.445v284.444q0 28.445-28.444 28.445H85.333q-28.444 0-28.444-28.445V517.69q0-28.445 28.444-28.445"})),e||(e=h.createElement("path",{fill:"#FFF",d:"M291.146 756.622v-65.28c0-18.944-3.584-47.36-5.888-66.048h1.024l15.36 45.568 25.85 69.632h25.088l25.6-69.632 15.872-45.568h1.286c-2.56 18.688-6.144 47.104-6.144 66.048v65.28h41.728v-190.72h-49.664l-29.184 82.432c-3.584 11.008-6.656 23.04-10.502 34.56h-1.274c-3.584-11.52-6.656-23.552-10.502-34.56l-30.208-82.432h-49.402v190.72zm250.624-190.72c41.722 0 76.288 15.104 76.288 62.208 0 45.312-34.816 65.28-75.264 65.28h-22.272v63.232h-45.83v-190.72zm-2.56 36.352h-18.688v55.04h19.968c22.272 0 33.024-10.496 33.024-29.184 0-19.2-12.288-25.856-34.304-25.856m217.594 154.368v-43.264h20.992v-34.816h-20.992V570.766h-56.32l-66.298 110.848v31.744h80.128v43.264z"})),t||(t=h.createElement("path",{fill:"#FFF",d:"M714.314 678.542H677.7l21.766-37.376c5.37-11.008 10.49-21.504 15.36-32.256h1.024c-.512 12.032-1.536 30.464-1.536 42.496z"})));var i="data:image/svg+xml,%3csvg t='1767873401047' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='1465' width='200' height='200'%3e%3cpath d='M590.222222 73.955556L859.022222 342.254933V876.088889c0 37.700267-30.5664 68.266667-68.266666 68.266667H233.244444c-37.700267 0-68.266667-30.5664-68.266666-68.266667V142.222222c0-37.700267 30.5664-68.266667 68.266666-68.266666h356.977778z m-11.764622 28.444444H233.244444a39.822222 39.822222 0 0 0-39.799466 38.456889L193.422222 142.222222v733.866667a39.822222 39.822222 0 0 0 38.456889 39.799467L233.244444 915.911111h557.511112a39.822222 39.822222 0 0 0 39.799466-38.456889L830.577778 876.088889V354.053689L578.4576 102.4z' fill='%23597EF7' p-id='1466'%3e%3c/path%3e%3cpath d='M854.755556 370.648178h-215.1424c-45.528178 0-82.551467-36.431644-83.5072-81.737956l-0.017067-1.792V73.955556h28.444444v213.162666c0 29.895111 23.819378 54.232178 53.515378 55.062756l1.564445 0.022755h215.1424v28.444445z' fill='%23597EF7' p-id='1467'%3e%3c/path%3e%3cpath d='M56.888889 489.244444m28.444444 0l853.333334 0q28.444444 0 28.444444 28.444445l0 284.444444q0 28.444444-28.444444 28.444445l-853.333334 0q-28.444444 0-28.444444-28.444445l0-284.444444q0-28.444444 28.444444-28.444445Z' fill='%23597EF7' p-id='1468'%3e%3c/path%3e%3cpath d='M291.145956 756.622222v-65.28c0-18.944-3.584-47.36-5.888-66.048h1.024l15.36 45.568 25.850311 69.632h25.088l25.6-69.632 15.872-45.568h1.285689c-2.56 18.688-6.144 47.104-6.144 66.048V756.622222h41.728V565.902222h-49.664l-29.184 82.432c-3.584 11.008-6.656 23.04-10.501689 34.56h-1.274311c-3.584-11.52-6.656-23.552-10.501689-34.56l-30.208-82.432h-49.402311V756.622222h40.96zM541.769956 565.902222c41.722311 0 76.288 15.104 76.288 62.208 0 45.312-34.816 65.28-75.264 65.28h-22.272V756.622222h-45.829689V565.902222z m-2.56 36.352h-18.688v55.04h19.968c22.272 0 33.024-10.496 33.024-29.184 0-19.2-12.288-25.856-34.304-25.856zM756.804267 756.622222v-43.264h20.992v-34.816h-20.992V570.766222h-56.32l-66.298311 110.848v31.744h80.128V756.622222z' fill='white' p-id='1469'%3e%3c/path%3e%3cpath d='M714.313956 678.542222h-36.613689l21.765689-37.376c5.370311-11.008 10.490311-21.504 15.36-32.256h1.024c-0.512 12.032-1.536 30.464-1.536 42.496v27.136z' fill='white' p-id='1470'%3e%3c/path%3e%3c/svg%3e";export{v as ReactComponent,i as default};
@@ -0,0 +1 @@
1
+ import*as l from"react";var h,e,t;function c(){return c=Object.assign?Object.assign.bind():function(l){for(var h=1;h<arguments.length;h++){var e=arguments[h];for(var t in e)({}).hasOwnProperty.call(e,t)&&(l[t]=e[t])}return l},c.apply(null,arguments)}const a=a=>l.createElement("svg",c({xmlns:"http://www.w3.org/2000/svg",width:200,height:200,className:"py_svg__icon",viewBox:"0 0 1024 1024"},a),h||(h=l.createElement("path",{fill:"#FFA940",d:"m590.222 73.956 268.8 268.299v533.834c0 37.7-30.566 68.267-68.266 68.267H233.244c-37.7 0-68.266-30.567-68.266-68.267V142.222c0-37.7 30.566-68.266 68.266-68.266zM578.458 102.4H233.244a39.82 39.82 0 0 0-39.799 38.457l-.023 1.365V876.09a39.82 39.82 0 0 0 38.457 39.8l1.365.022h557.512a39.82 39.82 0 0 0 39.799-38.457l.023-1.365V354.054z"})),e||(e=l.createElement("path",{fill:"#FFA940",d:"M854.756 370.648H639.613c-45.528 0-82.551-36.431-83.507-81.738l-.017-1.792V73.956h28.444v213.162c0 29.895 23.82 54.232 53.516 55.063l1.564.023h215.143zM85.333 489.244h853.334q28.444 0 28.444 28.445v284.444q0 28.445-28.444 28.445H85.333q-28.444 0-28.444-28.445V517.69q0-28.445 28.444-28.445"})),t||(t=l.createElement("path",{fill:"#FFF",d:"M399.855 756.622V693.39h22.272c40.448 0 75.264-19.968 75.264-65.28 0-47.104-34.56-62.208-76.288-62.208H354.03v190.72zm19.968-99.328h-19.968v-55.04h18.688c22.016 0 34.304 6.656 34.304 25.856 0 18.688-10.752 29.184-33.024 29.184M608.5 756.622v-67.328l57.6-123.392h-47.872l-15.872 42.496c-5.376 14.336-10.502 27.648-15.872 42.496h-1.024c-5.376-14.848-10.24-28.16-15.36-42.496l-15.872-42.496h-48.64l57.344 123.392v67.328z"})));var i="data:image/svg+xml,%3csvg t='1767873272414' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='1469' width='200' height='200'%3e%3cpath d='M590.222222 73.955556L859.022222 342.254933V876.088889c0 37.700267-30.5664 68.266667-68.266666 68.266667H233.244444c-37.700267 0-68.266667-30.5664-68.266666-68.266667V142.222222c0-37.700267 30.5664-68.266667 68.266666-68.266666h356.977778z m-11.764622 28.444444H233.244444a39.822222 39.822222 0 0 0-39.799466 38.456889L193.422222 142.222222v733.866667a39.822222 39.822222 0 0 0 38.456889 39.799467L233.244444 915.911111h557.511112a39.822222 39.822222 0 0 0 39.799466-38.456889L830.577778 876.088889V354.053689L578.4576 102.4z' fill='%23FFA940' p-id='1470'%3e%3c/path%3e%3cpath d='M854.755556 370.648178h-215.1424c-45.528178 0-82.551467-36.431644-83.5072-81.737956l-0.017067-1.792V73.955556h28.444444v213.162666c0 29.895111 23.819378 54.232178 53.515378 55.062756l1.564445 0.022755h215.1424v28.444445z' fill='%23FFA940' p-id='1471'%3e%3c/path%3e%3cpath d='M56.888889 489.244444m28.444444 0l853.333334 0q28.444444 0 28.444444 28.444445l0 284.444444q0 28.444444-28.444444 28.444445l-853.333334 0q-28.444444 0-28.444444-28.444445l0-284.444444q0-28.444444 28.444444-28.444445Z' fill='%23FFA940' p-id='1472'%3e%3c/path%3e%3cpath d='M399.854933 756.622222v-63.232h22.272c40.448 0 75.264-19.968 75.264-65.28 0-47.104-34.56-62.208-76.288-62.208h-67.072V756.622222h45.824z m19.968-99.328h-19.968v-55.04h18.688c22.016 0 34.304 6.656 34.304 25.856 0 18.688-10.752 29.184-33.024 29.184zM608.500622 756.622222v-67.328l57.6-123.392h-47.872l-15.872 42.496c-5.376 14.336-10.501689 27.648-15.872 42.496h-1.024c-5.376-14.848-10.24-28.16-15.36-42.496l-15.872-42.496h-48.64l57.344 123.392V756.622222h45.568z' fill='white' p-id='1473'%3e%3c/path%3e%3c/svg%3e";export{a as ReactComponent,i as default};
@@ -0,0 +1 @@
1
+ import*as h from"react";var v,e,t;function a(){return a=Object.assign?Object.assign.bind():function(h){for(var v=1;v<arguments.length;v++){var e=arguments[v];for(var t in e)({}).hasOwnProperty.call(e,t)&&(h[t]=e[t])}return h},a.apply(null,arguments)}const l=l=>h.createElement("svg",a({xmlns:"http://www.w3.org/2000/svg",width:200,height:200,className:"unknown_svg__icon",viewBox:"0 0 1024 1024"},l),v||(v=h.createElement("path",{fill:"#FFCA28",d:"m590.222 73.956 268.8 268.299v533.834c0 37.7-30.566 68.267-68.266 68.267H233.244c-37.7 0-68.266-30.567-68.266-68.267V142.222c0-37.7 30.566-68.266 68.266-68.266zM578.458 102.4H233.244a39.82 39.82 0 0 0-39.799 38.457l-.023 1.365V876.09a39.82 39.82 0 0 0 38.457 39.8l1.365.022h557.512a39.82 39.82 0 0 0 39.799-38.457l.023-1.365V354.054z"})),e||(e=h.createElement("path",{fill:"#FFCA28",d:"M854.756 370.648H639.613c-45.528 0-82.551-36.431-83.507-81.738l-.017-1.792V73.956h28.444v213.162c0 29.895 23.82 54.232 53.516 55.063l1.564.023h215.143zM85.333 489.244h853.334q28.444 0 28.444 28.445v284.444q0 28.445-28.444 28.445H85.333q-28.444 0-28.444-28.445V517.69q0-28.445 28.444-28.445"})),t||(t=h.createElement("path",{fill:"#FFF",d:"M294.855 756.622v-72.704h65.024v-38.144h-65.024v-41.728h75.776v-38.144h-121.6v190.72zm154.624 0v-190.72h-45.824v190.72zm163.84 0v-38.4h-74.24v-152.32h-45.824v190.72zm156.672 0v-38.4h-77.824v-40.448h63.744v-38.4h-63.744v-35.328h75.008v-38.144H646.343v190.72z"})));var c="data:image/svg+xml,%3csvg t='1767873419093' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='1621' width='200' height='200'%3e%3cpath d='M590.222222 73.955556L859.022222 342.254933V876.088889c0 37.700267-30.5664 68.266667-68.266666 68.266667H233.244444c-37.700267 0-68.266667-30.5664-68.266666-68.266667V142.222222c0-37.700267 30.5664-68.266667 68.266666-68.266666h356.977778z m-11.764622 28.444444H233.244444a39.822222 39.822222 0 0 0-39.799466 38.456889L193.422222 142.222222v733.866667a39.822222 39.822222 0 0 0 38.456889 39.799467L233.244444 915.911111h557.511112a39.822222 39.822222 0 0 0 39.799466-38.456889L830.577778 876.088889V354.053689L578.4576 102.4z' fill='%23FFCA28' p-id='1622'%3e%3c/path%3e%3cpath d='M854.755556 370.648178h-215.1424c-45.528178 0-82.551467-36.431644-83.5072-81.737956l-0.017067-1.792V73.955556h28.444444v213.162666c0 29.895111 23.819378 54.232178 53.515378 55.062756l1.564445 0.022755h215.1424v28.444445z' fill='%23FFCA28' p-id='1623'%3e%3c/path%3e%3cpath d='M56.888889 489.244444m28.444444 0l853.333334 0q28.444444 0 28.444444 28.444445l0 284.444444q0 28.444444-28.444444 28.444445l-853.333334 0q-28.444444 0-28.444444-28.444445l0-284.444444q0-28.444444 28.444444-28.444445Z' fill='%23FFCA28' p-id='1624'%3e%3c/path%3e%3cpath d='M294.855111 756.622222v-72.704h65.024v-38.144H294.855111v-41.728h75.776v-38.144H249.031111V756.622222zM449.479111 756.622222V565.902222h-45.824V756.622222zM613.319111 756.622222v-38.4H539.079111V565.902222h-45.824V756.622222zM769.991111 756.622222v-38.4h-77.824v-40.448h63.744v-38.4H692.167111v-35.328h75.008v-38.144h-120.832V756.622222z' fill='white' p-id='1625'%3e%3c/path%3e%3c/svg%3e";export{l as ReactComponent,c as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topthink/chat",
3
- "version": "1.1.42",
3
+ "version": "1.2.1",
4
4
  "module": "es/index.js",
5
5
  "types": "types/index.d.ts",
6
6
  "files": [
@@ -10,25 +10,29 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@babel/runtime": "^7.11.2",
13
+ "@block-kit/core": "^1.0.22",
14
+ "@block-kit/variable": "^1.0.21",
13
15
  "@breezystack/lamejs": "^1.2.7",
14
- "@topthink/components": "1.1.25",
15
- "@types/hast": "^2.0.0",
16
+ "@topthink/components": "1.2.1",
17
+ "@types/hast": "^3.0.4",
16
18
  "@types/mdast": "^4.0.4",
17
19
  "eventemitter3": "^5.0.1",
18
- "hast-util-to-string": "^2.0.0",
19
- "katex": "^0.16.9",
20
- "mdast-util-from-markdown": "^2.0.1",
21
- "micromark-util-character": "^2.1.0",
22
- "micromark-util-symbol": "^2.0.0",
23
- "micromark-util-types": "^2.0.0",
24
- "react-markdown": "^8.0.7",
25
- "react-textarea-autosize": "^8.5.3",
26
- "rehype-highlight": "^6.0.0",
27
- "rehype-katex": "^6.0.3",
28
- "remark-breaks": "^3.0.2",
29
- "remark-gfm": "^3.0.1",
30
- "remark-math": "^5.1.1",
31
- "unified": "^10.0.0",
20
+ "hast-util-to-string": "^3.0.1",
21
+ "katex": "^0.16.28",
22
+ "mdast-util-from-markdown": "^2.0.2",
23
+ "micromark-util-character": "^2.1.1",
24
+ "micromark-util-symbol": "^2.0.1",
25
+ "micromark-util-types": "^2.0.2",
26
+ "react-markdown": "^10.1.0",
27
+ "rehype-highlight": "^7.0.2",
28
+ "rehype-katex": "^7.0.1",
29
+ "rehype-stringify": "^10.0.1",
30
+ "remark-breaks": "^4.0.0",
31
+ "remark-gfm": "^4.0.1",
32
+ "remark-math": "^6.0.0",
33
+ "remark-parse": "^11.0.0",
34
+ "remark-rehype": "^11.1.2",
35
+ "unified": "^11.0.5",
32
36
  "use-resize-observer": "^9.1.0"
33
37
  },
34
38
  "peerDependencies": {
@@ -60,7 +64,7 @@
60
64
  },
61
65
  "author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
62
66
  "license": "MIT",
63
- "gitHead": "1b2aed0bfff536822073eab1b44970fadc754bce",
67
+ "gitHead": "bf97bae04cbf072837f3dc02bf3223a71483026d",
64
68
  "scripts": {
65
69
  "prebuild": "rimraf es types",
66
70
  "build": "rollup -c --environment NODE_ENV:production",
@@ -5,5 +5,5 @@ interface Props {
5
5
  components?: Components;
6
6
  cite?: Components['cite'];
7
7
  }
8
- declare const Markdown: import("react").MemoExoticComponent<({ content, components: userComponents, cite }: Props) => import("react/jsx-runtime").JSX.Element>;
8
+ declare const Markdown: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<HTMLDivElement>>>;
9
9
  export default Markdown;
@@ -1,7 +1,9 @@
1
- import { Chunk } from '../../types';
1
+ import { Chunk, ToolMessage } from '../../types';
2
2
  interface ContextType {
3
- index: number;
3
+ chunkIndex: number;
4
4
  chunk: Chunk;
5
+ toolIndex?: number;
6
+ tool?: ToolMessage;
5
7
  isLastMessage: boolean;
6
8
  }
7
9
  declare const _default: import("react").Provider<ContextType | null>;
@@ -1,7 +1,9 @@
1
- import { Dispatch, PropsWithChildren, ReactNode, SetStateAction } from 'react';
2
- import { Conversation, LogLevel, Message } from '../../types';
1
+ import { ComponentType, Dispatch, PropsWithChildren, ReactElement, ReactNode, SetStateAction } from 'react';
2
+ import { Conversation, Input, LogLevel, Message, ToolMessage } from '../../types';
3
3
  import { Updater } from '@topthink/components/types/hooks/use-immer';
4
4
  import { RequestInstance } from '@topthink/components';
5
+ import { FileItemProps } from './file-item';
6
+ import { ReasoningProps } from './reasoning';
5
7
  interface Handles {
6
8
  onSuccess?: () => void;
7
9
  onComplete?: () => void;
@@ -10,6 +12,23 @@ interface Handles {
10
12
  data?: any;
11
13
  }) => void;
12
14
  }
15
+ export interface ToolRenderOptions {
16
+ /** 工具消息原始数据 */
17
+ tool: ToolMessage;
18
+ /** 解析后的参数对象 */
19
+ args: any;
20
+ }
21
+ export interface ToolRenderResult {
22
+ /** 工具的完整描述文本(包含标题和详细信息) */
23
+ title?: ReactNode;
24
+ /** 自定义的响应内容 UI,返回 null 则不显示内容区域 */
25
+ content?: ReactNode;
26
+ response?: ReactNode;
27
+ /** 是否显示状态文本(如"已使用"、"正在使用"等),默认为 true */
28
+ showStatus?: boolean;
29
+ /** 是否默认展开详情 */
30
+ defaultExpanded?: boolean;
31
+ }
13
32
  interface ContextType {
14
33
  bot?: {
15
34
  name: string;
@@ -25,6 +44,8 @@ interface ContextType {
25
44
  nodeIconResolver?: (type: string) => ReactNode;
26
45
  conversationId?: string;
27
46
  setConversationId: Dispatch<SetStateAction<string | undefined>>;
47
+ input?: Input;
48
+ setInput: Dispatch<SetStateAction<Input | undefined>>;
28
49
  messages: Message[];
29
50
  setMessages: Updater<Message[]>;
30
51
  suggestions: string[];
@@ -35,6 +56,16 @@ interface ContextType {
35
56
  readonly: boolean;
36
57
  handles: Handles;
37
58
  setHandles: Dispatch<SetStateAction<Handles>>;
59
+ renderFileItem?: (props: {
60
+ Component: ComponentType<FileItemProps>;
61
+ props: FileItemProps;
62
+ }) => ReactElement;
63
+ renderReasoning?: (props: {
64
+ Component: ComponentType<ReasoningProps>;
65
+ props: ReasoningProps;
66
+ }) => ReactElement;
67
+ /** 自定义工具渲染函数 */
68
+ renderToolContent?: (options: ToolRenderOptions) => ToolRenderResult | undefined;
38
69
  }
39
70
  export declare function useContext(handles?: Handles): ContextType;
40
71
  export declare function Provider({ children, ...props }: PropsWithChildren<Omit<ContextType, 'handles' | 'setHandles'>>): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +1,11 @@
1
- interface Props {
1
+ export interface FileItemProps {
2
2
  className?: string;
3
3
  name: string;
4
- size: number;
4
+ size?: number;
5
+ url?: string;
5
6
  loading?: boolean;
6
7
  error?: string;
7
8
  onRemove?: () => void;
9
+ onClick?: () => void;
8
10
  }
9
- export default function FileItem({ className, name, size, loading, error, onRemove }: Props): import("react/jsx-runtime").JSX.Element;
10
- export {};
11
+ export default function FileItem(props: FileItemProps): import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,11 @@
1
1
  import { RequestInstance } from '@topthink/components';
2
- import { MutableRefObject, ReactNode } from 'react';
2
+ import { ComponentType, MutableRefObject, ReactElement, ReactNode } from 'react';
3
3
  import { Conversation, ConversationMessage, Input, LogLevel, Message, MessageBoxType, Variable } from '../../types';
4
- import MessageItem, { MessageActions, MessageItemProps } from './message-item';
4
+ import { MessageActions, MessageItemProps } from './message-item';
5
+ import { ToolRenderOptions, ToolRenderResult } from './context';
5
6
  import { Components } from 'react-markdown';
7
+ import { FileItemProps } from './file-item';
8
+ import { ReasoningProps } from './reasoning';
6
9
  export interface MessageBoxProps {
7
10
  className?: string;
8
11
  bot?: {
@@ -55,10 +58,21 @@ export interface MessageBoxProps {
55
58
  actions?: MessageActions;
56
59
  cite?: Components['cite'];
57
60
  renderItem?: (props: {
58
- Component: typeof MessageItem;
61
+ Component: ComponentType<MessageItemProps>;
59
62
  props: MessageItemProps;
60
63
  }, index: number) => ReactNode;
64
+ renderFileItem?: (props: {
65
+ Component: ComponentType<FileItemProps>;
66
+ props: FileItemProps;
67
+ }) => ReactElement;
68
+ renderReasoning?: (props: {
69
+ Component: ComponentType<ReasoningProps>;
70
+ props: ReasoningProps;
71
+ }) => ReactElement;
72
+ /** 自定义工具渲染函数,用于定制工具调用的显示样式 */
73
+ renderToolContent?: (options: ToolRenderOptions) => ToolRenderResult | undefined;
61
74
  transformMessages?: (messages: any[]) => Message[];
75
+ onReset?: (conversation?: Conversation) => void;
62
76
  }
63
77
  declare const MessageBox: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<MessageBoxProps & import("react").RefAttributes<MessageBoxType>>>;
64
78
  export default MessageBox;
@@ -1,5 +1,6 @@
1
1
  import { MutableRefObject, ReactNode } from 'react';
2
2
  import { Input, Variable } from '../../../types';
3
+ import '@block-kit/variable/dist/style/index.css';
3
4
  interface Props {
4
5
  suggestion?: boolean;
5
6
  variables?: {
@@ -11,6 +12,7 @@ interface Props {
11
12
  model?: string;
12
13
  };
13
14
  minRows?: number;
15
+ maxRows?: number;
14
16
  scrollRef: MutableRefObject<HTMLDivElement | null>;
15
17
  toolbar?: ReactNode | true;
16
18
  disabled?: boolean;
@@ -1,6 +1,6 @@
1
- interface Props {
1
+ export interface ReasoningProps {
2
2
  reasoning: string;
3
3
  loading?: boolean;
4
4
  }
5
- declare const Reasoning: import("react").MemoExoticComponent<({ reasoning, loading }: Props) => import("react/jsx-runtime").JSX.Element>;
5
+ declare const Reasoning: import("react").MemoExoticComponent<(props: ReasoningProps) => import("react/jsx-runtime").JSX.Element>;
6
6
  export default Reasoning;
@@ -0,0 +1,5 @@
1
+ interface Props {
2
+ content: string;
3
+ }
4
+ export default function Confirm({ content }: Props): import("react/jsx-runtime").JSX.Element;
5
+ export {};
@@ -2,7 +2,7 @@ import { PropsWithChildren } from 'react';
2
2
  interface ContextType {
3
3
  resume: (payload: any) => void;
4
4
  disabled: boolean;
5
- output: any;
5
+ response: any;
6
6
  }
7
7
  export declare function useSuspend(): ContextType;
8
8
  export declare function Provider({ children, ...props }: PropsWithChildren<ContextType>): import("react/jsx-runtime").JSX.Element;
package/types/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  export * from './types';
2
2
  export { default as MessageBox, MessageBoxProps } from './components/message-box';
3
+ export { useContext as useMessageContext, ToolRenderOptions, ToolRenderResult } from './components/message-box/context';
3
4
  export { default as ActionButton } from './components/action-button';
4
5
  export { default as Markdown } from './components/markdown';
5
6
  export { default as VariableForm } from './components/variable-form';
7
+ export { default as FileItem } from './components/message-box/file-item';
6
8
  export { default as pickQuestions } from './utils/pick-questions';
7
9
  export { default as useSynthesis } from './speech/use-synthesis';
10
+ export { ContentChangeEvent } from '@block-kit/core';
11
+ export { default as md2html } from './utils/md2html';
package/types/types.d.ts CHANGED
@@ -1,7 +1,8 @@
1
+ import { Editor } from '@block-kit/variable';
1
2
  export interface FormField {
2
3
  name: string;
3
4
  label: string;
4
- type: 'text' | 'textarea' | 'number' | 'email' | 'tel' | 'date' | 'select';
5
+ type: 'text' | 'textarea' | 'number' | 'email' | 'tel' | 'date' | 'select' | 'radio' | 'checkbox';
5
6
  required: boolean;
6
7
  placeholder?: string;
7
8
  options?: string[];
@@ -18,6 +19,11 @@ export type SuspendType = {
18
19
  description: string;
19
20
  fields: FormField[];
20
21
  };
22
+ } | {
23
+ type: 'confirm';
24
+ confirm: {
25
+ content: string;
26
+ };
21
27
  };
22
28
  export type ContentType = string | {
23
29
  type: 'image';
@@ -28,15 +34,34 @@ export type ContentType = string | {
28
34
  } | {
29
35
  type: 'suspend';
30
36
  suspend: SuspendType;
37
+ } | {
38
+ type: string;
39
+ [key: string]: any;
31
40
  };
32
- export interface ToolMessage {
33
- name: string;
41
+ export interface ToolMessageConfig {
42
+ }
43
+ export interface BaseToolMessage<N extends string = string, C = ContentType> {
44
+ name: N;
45
+ title: string;
46
+ arguments: string;
47
+ response?: string;
48
+ error?: boolean;
49
+ content?: C;
50
+ }
51
+ export interface ConfiguredToolMessage<N extends string = string, C = ContentType> {
52
+ name: N;
34
53
  title: string;
35
54
  arguments: string;
36
55
  response?: string;
37
56
  error?: boolean;
38
- content?: ContentType;
57
+ content: C;
39
58
  }
59
+ type ConfiguredToolMessages = {
60
+ [K in keyof ToolMessageConfig]: ConfiguredToolMessage<K & string, ToolMessageConfig[K]>;
61
+ }[keyof ToolMessageConfig];
62
+ export type ToolMessage = [keyof ToolMessageConfig] extends [never] ? BaseToolMessage : ConfiguredToolMessages | BaseToolMessage;
63
+ export declare function isToolMessage<K extends keyof ToolMessageConfig>(tool: ToolMessage, name: K): tool is ConfiguredToolMessage<K & string, ToolMessageConfig[K]> & ToolMessage;
64
+ export declare function isToolMessage<N extends string>(tool: ToolMessage, name: N): tool is BaseToolMessage<N>;
40
65
  export type LogLevel = 'stats' | 'all' | 'none';
41
66
  export interface Node {
42
67
  title: string;
@@ -117,6 +142,7 @@ export interface SendParams {
117
142
  }
118
143
  export interface ResumeParams {
119
144
  chunk: number;
145
+ tool?: number;
120
146
  payload: any;
121
147
  }
122
148
  export interface Chat {
@@ -127,6 +153,7 @@ export interface MessageBoxType {
127
153
  reset(conversation?: Conversation): void;
128
154
  }
129
155
  export interface Input extends Chat {
156
+ editor: Editor;
130
157
  setQuery(query: string): void;
131
158
  setQuote(quote: string): void;
132
159
  focus(): void;
@@ -144,3 +171,4 @@ export interface Synthesis {
144
171
  onPlaying(onPlaying: (playing: boolean) => void): void;
145
172
  onSpeaking(onSpeaking: (speaking: boolean) => void): void;
146
173
  }
174
+ export {};
@@ -0,0 +1 @@
1
+ export default function md2html(markdown: string): Promise<string>;
@@ -10,9 +10,8 @@ declare module 'micromark-util-types' {
10
10
  }
11
11
  declare module 'unified' {
12
12
  interface Data {
13
- micromarkExtensions: NonNullable<FromMarkdownOptions['extensions']>;
14
- fromMarkdownExtensions: NonNullable<FromMarkdownOptions['mdastExtensions']>;
15
- [key: string]: unknown;
13
+ micromarkExtensions?: NonNullable<FromMarkdownOptions['extensions']>;
14
+ fromMarkdownExtensions?: NonNullable<FromMarkdownOptions['mdastExtensions']>;
16
15
  }
17
16
  interface FrozenProcessor {
18
17
  data(): Data;