@topthink/chat 1.1.40 → 1.1.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.js +1 -1
- package/package.json +2 -3
package/es/index.js
CHANGED
|
@@ -64,7 +64,7 @@ import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{styled as
|
|
|
64
64
|
${e=>e.$error&&i`
|
|
65
65
|
border-color: var(--bs-danger) !important;
|
|
66
66
|
`}
|
|
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})},[]),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`
|
|
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
68
|
color: var(--bs-secondary);
|
|
69
69
|
cursor: pointer;
|
|
70
70
|
display: flex;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topthink/chat",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.41",
|
|
4
4
|
"module": "es/index.js",
|
|
5
5
|
"types": "types/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/runtime": "^7.11.2",
|
|
13
13
|
"@breezystack/lamejs": "^1.2.7",
|
|
14
|
-
"@topthink/components": "^1.1.
|
|
14
|
+
"@topthink/components": "^1.1.24",
|
|
15
15
|
"@types/hast": "^2.0.0",
|
|
16
16
|
"@types/mdast": "^4.0.4",
|
|
17
17
|
"eventemitter3": "^5.0.1",
|
|
@@ -60,7 +60,6 @@
|
|
|
60
60
|
},
|
|
61
61
|
"author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
|
|
62
62
|
"license": "MIT",
|
|
63
|
-
"gitHead": "ec9772724e9636ed8cd78ba99ba7ee33f6383ce5",
|
|
64
63
|
"scripts": {
|
|
65
64
|
"prebuild": "rimraf es types",
|
|
66
65
|
"build": "rollup -c --environment NODE_ENV:production",
|