pcm-agents 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/dist/cjs/{index-BFPEnLbS.js → index-RmBfqEV7.js} +4 -3
- package/dist/cjs/index-RmBfqEV7.js.map +1 -0
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/my-component.cjs.entry.js +2 -2
- package/dist/cjs/my-component.cjs.entry.js.map +1 -1
- package/dist/cjs/my-component.entry.cjs.js.map +1 -1
- package/dist/cjs/pcm-agents.cjs.js +1 -1
- package/dist/cjs/pcm-app-chat-modal.pcm-chat-message.pcm-hr-chat-modal.pcm-jlpp-modal.pcm-mnms-modal.pcm-video-chat-modal.pcm-zygh-modal.entry.cjs.js.map +1 -0
- package/dist/cjs/pcm-app-chat-modal_7.cjs.entry.js +56 -53
- package/dist/cjs/pcm-app-chat-modal_7.cjs.entry.js.map +1 -1
- package/dist/cjs/pcm-chat-modal.cjs.entry.js +1 -1
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/my-component/my-component.css +3 -3
- package/dist/collection/components/my-component/my-component.js +1 -1
- package/dist/collection/components/my-component/my-component.js.map +1 -1
- package/dist/collection/components/pcm-app-chat-modal/pcm-app-chat-modal.js +3 -4
- package/dist/collection/components/pcm-app-chat-modal/pcm-app-chat-modal.js.map +1 -1
- package/dist/collection/components/pcm-hr-chat-modal/pcm-hr-chat-modal.js +2 -2
- package/dist/collection/components/pcm-hr-chat-modal/pcm-hr-chat-modal.js.map +1 -1
- package/dist/collection/components/{pcm-jlpx-modal/pcm-jlpx-modal.js → pcm-jlpp-modal/pcm-jlpp-modal.js} +21 -21
- package/dist/collection/components/pcm-jlpp-modal/pcm-jlpp-modal.js.map +1 -0
- package/dist/collection/components/pcm-mnms-modal/pcm-mnms-modal.js +16 -16
- package/dist/collection/components/pcm-mnms-modal/pcm-mnms-modal.js.map +1 -1
- package/dist/collection/components/pcm-video-chat-modal/pcm-video-chat-modal.js +2 -2
- package/dist/collection/components/pcm-video-chat-modal/pcm-video-chat-modal.js.map +1 -1
- package/dist/collection/components/pcm-zygh-modal/pcm-zygh-modal.js +22 -18
- package/dist/collection/components/pcm-zygh-modal/pcm-zygh-modal.js.map +1 -1
- package/dist/collection/global/global.css +31 -0
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/utils/utils.js +2 -1
- package/dist/collection/utils/utils.js.map +1 -1
- package/dist/components/index.js +2 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/my-component.js +1 -1
- package/dist/components/my-component.js.map +1 -1
- package/dist/components/{p-BctfuDvG.js → p-BG-UIl44.js} +4 -5
- package/dist/components/p-BG-UIl44.js.map +1 -0
- package/dist/components/pcm-app-chat-modal.js +1 -1
- package/dist/components/pcm-hr-chat-modal.js +1 -1
- package/dist/components/pcm-hr-chat-modal.js.map +1 -1
- package/dist/components/{pcm-jlpx-modal.d.ts → pcm-jlpp-modal.d.ts} +4 -4
- package/dist/components/{pcm-jlpx-modal.js → pcm-jlpp-modal.js} +26 -26
- package/dist/components/pcm-jlpp-modal.js.map +1 -0
- package/dist/components/pcm-mnms-modal.js +15 -15
- package/dist/components/pcm-mnms-modal.js.map +1 -1
- package/dist/components/pcm-video-chat-modal.js +1 -1
- package/dist/components/pcm-video-chat-modal.js.map +1 -1
- package/dist/components/pcm-zygh-modal.js +19 -15
- package/dist/components/pcm-zygh-modal.js.map +1 -1
- package/dist/esm/{index-nVjZGfA8.js → index-CDtyzi83.js} +4 -3
- package/dist/esm/index-CDtyzi83.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/my-component.entry.js +2 -2
- package/dist/esm/my-component.entry.js.map +1 -1
- package/dist/esm/pcm-agents.js +1 -1
- package/dist/esm/pcm-app-chat-modal.pcm-chat-message.pcm-hr-chat-modal.pcm-jlpp-modal.pcm-mnms-modal.pcm-video-chat-modal.pcm-zygh-modal.entry.js.map +1 -0
- package/dist/esm/pcm-app-chat-modal_7.entry.js +56 -53
- package/dist/esm/pcm-app-chat-modal_7.entry.js.map +1 -1
- package/dist/esm/pcm-chat-modal.entry.js +1 -1
- package/dist/pcm-agents/app-globals-DQuL1Twl.js.map +1 -0
- package/dist/pcm-agents/index-Csq0E9fM.js.map +1 -0
- package/dist/pcm-agents/index.esm.js +1 -1
- package/dist/pcm-agents/index.esm.js.map +1 -1
- package/dist/pcm-agents/my-component.entry.esm.js.map +1 -1
- package/dist/pcm-agents/p-11c829b3.entry.js +2 -0
- package/dist/pcm-agents/p-11c829b3.entry.js.map +1 -0
- package/dist/pcm-agents/{p-f3ca99b4.entry.js → p-430f9a9f.entry.js} +2 -2
- package/dist/pcm-agents/p-CDtyzi83.js +2 -0
- package/dist/pcm-agents/p-CDtyzi83.js.map +1 -0
- package/dist/pcm-agents/p-e7221181.entry.js +2 -0
- package/dist/pcm-agents/p-e7221181.entry.js.map +1 -0
- package/dist/pcm-agents/pcm-agents.esm.js +1 -1
- package/dist/pcm-agents/pcm-agents.esm.js.map +1 -1
- package/dist/pcm-agents/pcm-app-chat-modal.pcm-chat-message.pcm-hr-chat-modal.pcm-jlpp-modal.pcm-mnms-modal.pcm-video-chat-modal.pcm-zygh-modal.entry.esm.js.map +1 -0
- package/dist/pcm-agents/utils-CfkrvVlp.js.map +1 -0
- package/dist/types/components/pcm-app-chat-modal/pcm-app-chat-modal.d.ts +1 -1
- package/dist/types/components/pcm-hr-chat-modal/pcm-hr-chat-modal.d.ts +1 -1
- package/dist/types/components/{pcm-jlpx-modal/pcm-jlpx-modal.d.ts → pcm-jlpp-modal/pcm-jlpp-modal.d.ts} +4 -4
- package/dist/types/components/pcm-mnms-modal/pcm-mnms-modal.d.ts +3 -3
- package/dist/types/components/pcm-video-chat-modal/pcm-video-chat-modal.d.ts +1 -1
- package/dist/types/components/pcm-zygh-modal/pcm-zygh-modal.d.ts +8 -4
- package/dist/types/components.d.ts +48 -48
- package/dist/types/utils/utils.d.ts +1 -1
- package/package.json +1 -1
- package/readme.md +307 -307
- package/dist/cjs/index-BFPEnLbS.js.map +0 -1
- package/dist/cjs/pcm-app-chat-modal.pcm-chat-message.pcm-hr-chat-modal.pcm-jlpx-modal.pcm-mnms-modal.pcm-video-chat-modal.pcm-zygh-modal.entry.cjs.js.map +0 -1
- package/dist/collection/components/pcm-jlpx-modal/pcm-jlpx-modal.js.map +0 -1
- package/dist/components/p-BctfuDvG.js.map +0 -1
- package/dist/components/pcm-jlpx-modal.js.map +0 -1
- package/dist/esm/index-nVjZGfA8.js.map +0 -1
- package/dist/esm/pcm-app-chat-modal.pcm-chat-message.pcm-hr-chat-modal.pcm-jlpx-modal.pcm-mnms-modal.pcm-video-chat-modal.pcm-zygh-modal.entry.js.map +0 -1
- package/dist/pcm-agents/p-55417392.entry.js +0 -2
- package/dist/pcm-agents/p-55417392.entry.js.map +0 -1
- package/dist/pcm-agents/p-a698b59f.entry.js +0 -2
- package/dist/pcm-agents/p-a698b59f.entry.js.map +0 -1
- package/dist/pcm-agents/p-nVjZGfA8.js +0 -2
- package/dist/pcm-agents/p-nVjZGfA8.js.map +0 -1
- package/dist/pcm-agents/pcm-app-chat-modal.pcm-chat-message.pcm-hr-chat-modal.pcm-jlpx-modal.pcm-mnms-modal.pcm-video-chat-modal.pcm-zygh-modal.entry.esm.js.map +0 -1
- /package/dist/collection/components/{pcm-jlpx-modal/pcm-jlpx-modal.css → pcm-jlpp-modal/pcm-jlpp-modal.css} +0 -0
- /package/dist/pcm-agents/{p-f3ca99b4.entry.js.map → p-430f9a9f.entry.js.map} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{f as format}from"./p-
|
|
1
|
+
export{f as format}from"./p-CDtyzi83.js";
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["src/index.ts"],"sourcesContent":["/**\n * @fileoverview entry point for your component library\n *\n * This is the entry point for your component library. Use this file to export utilities,\n * constants or data structure that accompany your components.\n *\n * DO NOT use this file to export your components. Instead, use the recommended approaches\n * to consume components of this package as outlined in the `README.md`.\n */\nexport { format } from './utils/utils';\nexport type * from './components.d.ts';\n"],"names":[],"mappings":";;AAAA;;;;;;;;AAQG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"my-component.entry.esm.js","sources":["src/components/my-component/my-component.css?tag=my-component&encapsulation=shadow","src/components/my-component/my-component.tsx"],"sourcesContent":[":host {\
|
|
1
|
+
{"version":3,"file":"my-component.entry.esm.js","sources":["src/components/my-component/my-component.css?tag=my-component&encapsulation=shadow","src/components/my-component/my-component.tsx"],"sourcesContent":[":host {\n display: block;\n}\n","import { Component, Prop, h } from '@stencil/core';\nimport { format } from '../../utils/utils';\n\n@Component({\n tag: 'my-component',\n styleUrl: 'my-component.css',\n shadow: true,\n})\nexport class MyComponent {\n /**\n * The first name\n */\n @Prop() first: string;\n\n /**\n * The middle name\n */\n @Prop() middle: string;\n\n /**\n * The last name\n */\n @Prop() last: string;\n\n private getText(): string {\n return format(this.first, this.middle, this.last);\n }\n\n render() {\n return <div>Hello, World! I'm {this.getText()}</div>;\n }\n}\n"],"names":[],"mappings":";;;AAAA,MAAM,cAAc,GAAG,sBAAsB;;MCQhC,WAAW,GAAA,MAAA;;;;AACtB;;AAEG;AACK,IAAA,KAAK;AAEb;;AAEG;AACK,IAAA,MAAM;AAEd;;AAEG;AACK,IAAA,IAAI;IAEJ,OAAO,GAAA;AACb,QAAA,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC;;IAGnD,MAAM,GAAA;AACJ,QAAA,OAAO,CAAA,CAAA,KAAA,EAAA,EAAA,GAAA,EAAA,0CAAA,EAAA,wBAAwB,IAAI,CAAC,OAAO,EAAE,CAAO;;;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as t,h as s}from"./p-DaMwkrv5.js";import{f as r}from"./p-CDtyzi83.js";const e=":host{display:block}";const o=class{constructor(s){t(this,s)}first;middle;last;getText(){return r(this.first,this.middle,this.last)}render(){return s("div",{key:"70654fc83039b5f659efe99cc990e9b86d20dbe0"},"Hello, World! I'm ",this.getText())}};o.style=e;export{o as my_component};
|
|
2
|
+
//# sourceMappingURL=p-11c829b3.entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["myComponentCss","MyComponent","first","middle","last","getText","format","this","render","h","key"],"sources":["src/components/my-component/my-component.css?tag=my-component&encapsulation=shadow","src/components/my-component/my-component.tsx"],"sourcesContent":[":host {\n display: block;\n}\n","import { Component, Prop, h } from '@stencil/core';\nimport { format } from '../../utils/utils';\n\n@Component({\n tag: 'my-component',\n styleUrl: 'my-component.css',\n shadow: true,\n})\nexport class MyComponent {\n /**\n * The first name\n */\n @Prop() first: string;\n\n /**\n * The middle name\n */\n @Prop() middle: string;\n\n /**\n * The last name\n */\n @Prop() last: string;\n\n private getText(): string {\n return format(this.first, this.middle, this.last);\n }\n\n render() {\n return <div>Hello, World! I'm {this.getText()}</div>;\n }\n}\n"],"mappings":"+EAAA,MAAMA,EAAiB,uB,MCQVC,EAAW,M,yBAIdC,MAKAC,OAKAC,KAEA,OAAAC,GACN,OAAOC,EAAOC,KAAKL,MAAOK,KAAKJ,OAAQI,KAAKH,K,CAG9C,MAAAI,GACE,OAAOC,EAAA,OAAAC,IAAA,iEAAwBH,KAAKF,U","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e,c as t,g as s,h as i}from"./p-DaMwkrv5.js";import{s as n,u as o,a}from"./p-nVjZGfA8.js";const r=":host{display:block}.modal-overlay{position:fixed;top:0;left:0;right:0;bottom:0;background-color:rgba(0, 0, 0, 0.5);display:flex;justify-content:center;align-items:center;overflow-y:auto;padding:20px;z-index:1000}.fullscreen-overlay{padding:0}.modal-container{background:white;border-radius:8px;width:100%;max-width:800px;height:80vh;min-height:600px;display:flex;flex-direction:column;position:relative;margin:auto}.modal-container.fullscreen{width:100vw;max-width:none;height:100vh;min-height:100vh;border-radius:0;margin:0}@media screen and (max-width: 768px){.modal-overlay{padding:0}.modal-container{width:95%;height:70vh;min-height:400px}.chat-history{min-height:200px;max-height:50vh}.modal-container.fullscreen{height:-webkit-fill-available;max-height:-webkit-fill-available;padding:env(safe-area-inset-top) 0 env(safe-area-inset-bottom)}.modal-container.fullscreen .chat-history{max-height:unset}.modal-container.fullscreen .modal-header{padding:0px 16px;padding-top:max(30px, env(safe-area-inset-top))}}.modal-header{display:flex;justify-content:space-between;align-items:center;padding:4px 16px;height:50px;border-bottom:1px solid #e8e8e8}.header-left{display:flex;align-items:center;gap:8px}.header-icon{width:24px;height:24px}.close-button{background:transparent;border:none;cursor:pointer;padding:8px;display:flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:4px}.close-button:hover{background-color:rgba(0, 0, 0, 0.04)}.close-button span{font-size:24px;line-height:1;color:#999}.close-button:hover span{color:#666}.chat-history{position:relative;flex:1;overflow-y:auto;padding:16px;scroll-behavior:smooth;min-height:400px;}@media screen and (max-width: 480px){.chat-history{min-height:200px;max-height:50vh}}.message-input{padding:16px;border-top:1px solid #eee;display:flex;gap:8px;align-items:center}.message-input input{flex:1;padding:8px 12px;border:1px solid #ddd;border-radius:4px;outline:none;transition:border-color 0.2s ease}.message-input input:focus{border-color:#bbb}.message{margin-bottom:16px;opacity:1;transition:opacity 0.3s ease}.message-content{max-width:70%;padding:8px 12px;border-radius:8px;word-break:break-word}.message-content p{margin:0;word-break:break-word}.user-message{display:flex;justify-content:flex-end}.agent-message{display:flex;justify-content:flex-start}.user-message .message-content{background-color:#007bff;color:white}.agent-message .message-content{background-color:#f1f1f1}.message-time{font-size:12px;color:#999;margin-top:4px;display:block}.send-button{background-color:#1890ff;color:white;border:none;border-radius:4px;padding:8px 16px;cursor:pointer;font-weight:500}.send-button:disabled{background-color:#ccc;cursor:not-allowed}.empty-state{display:flex;justify-content:center;align-items:center;height:100%;color:#999;text-align:center}.loading-container{position:absolute;top:0;left:0;right:0;bottom:0;display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:rgba(255, 255, 255, 0.98);z-index:1;opacity:1;transition:opacity 0.3s ease}.loading-container p{margin-top:16px;color:#666;font-size:14px}.loading-spinner{width:40px;height:40px;border:3px solid #f3f3f3;border-top:3px solid #1890ff;border-radius:50%;animation:spin 1s linear infinite}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}.messages-wrapper{width:100%;min-height:100%;display:flex;flex-direction:column;justify-content:flex-end}.messages-wrapper.has-overflow{justify-content:flex-start}.suggested-questions{display:flex;flex-direction:column;gap:8px;padding:16px}.suggested-question{display:flex;align-items:center;justify-content:space-between;padding:8px 12px;background-color:#f3f4f6;border-radius:4px;cursor:pointer;font-size:14px;color:#374151;transition:background-color 0.2s}.suggested-question:hover{background-color:#e5e7eb}.arrow-right{margin-left:8px}.loading-suggestions{display:flex;justify-content:center;padding:16px}.loading-spinner-small{width:20px;height:20px;border:2px solid #e5e7eb;border-top-color:#6b7280;border-radius:50%;animation:spin 1s linear infinite}.upload-button{background:transparent;border:none;cursor:pointer;padding:8px;display:flex;align-items:center;justify-content:center;color:#666;border-radius:4px;transition:background-color 0.2s}.upload-button:hover{background-color:rgba(0, 0, 0, 0.04)}.upload-button svg{width:20px;height:20px}.file-input{display:none}.selected-file{font-size:12px;color:#666;margin-left:8px;max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.input-wrapper{flex:1;display:flex;align-items:center;border:1px solid #ddd;border-radius:4px;padding:0 4px;background:white}.input-wrapper input{border:none;flex:1;padding:8px;outline:none}.input-wrapper:focus-within{border-color:#bbb}.file-preview{padding:8px 16px;border-top:1px solid #eee;background-color:#f9f9f9}.file-info{display:flex;align-items:center;justify-content:space-between;padding:8px;background:white;border:1px solid #e8e8e8;border-radius:4px}.file-name{font-size:13px;color:#333;margin-right:8px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:calc(100% - 30px)}.remove-file{background:transparent;border:none;color:#999;cursor:pointer;padding:4px 8px;font-size:16px;line-height:1;border-radius:4px;transition:all 0.2s}.remove-file:hover{background-color:#f0f0f0;color:#666}";const l=class{constructor(s){e(this,s);this.messageSent=t(this,"messageSent");this.modalClosed=t(this,"modalClosed");this.streamComplete=t(this,"streamComplete")}modalTitle="在线客服";apiKey="";isOpen=false;messages=[];currentMessage="";messageSent;modalClosed;icon;zIndex=1e3;isShowHeader=true;isNeedClose=true;botId;conversationId;currentAssistantMessage="";isLoading=false;currentStreamingMessage=null;shouldAutoScroll=true;SCROLL_THRESHOLD=30;isLoadingHistory=false;get hostElement(){return s(this)}streamComplete;suggestedQuestions=[];suggestedQuestionsLoading=false;stopSuggestedQuestionsRef={current:false};selectedFile=null;isUploading=false;uploadedFileInfo=[];defaultQuery="";fullscreen=false;handleClose=()=>{this.modalClosed.emit()};handleInputChange=e=>{const t=e.target;this.currentMessage=t.value};async getSuggestedQuestions(e){this.stopSuggestedQuestionsRef.current=false;this.suggestedQuestionsLoading=true;try{const t=await n({url:`/share/messages/${e}/suggested`});if(this.stopSuggestedQuestionsRef.current)return;if(t.success&&t.data){this.suggestedQuestions=t.data||[]}}catch(e){console.error("获取问题建议失败:",e)}finally{this.suggestedQuestionsLoading=false}}handleStopSuggestedQuestions=()=>{this.suggestedQuestions=[];this.stopSuggestedQuestionsRef.current=true};handleFileChange=async e=>{const t=e.target;if(t.files&&t.files.length>0){this.selectedFile=t.files[0];await this.uploadFile()}};async uploadFile(){if(!this.selectedFile)return;this.isUploading=true;try{const e=await o(this.selectedFile,{authorization:"Bearer "+this.apiKey});this.uploadedFileInfo.push(e)}catch(e){console.error("文件上传错误:",e);this.clearSelectedFile();alert("文件上传失败,请重试")}finally{this.isUploading=false}}handleUploadClick=()=>{const e=this.hostElement.shadowRoot?.querySelector(".file-input");e?.click()};clearSelectedFile=()=>{this.selectedFile=null;this.uploadedFileInfo=[];const e=this.hostElement.shadowRoot?.querySelector(".file-input");if(e){e.value=""}};async sendMessageToAPI(e){this.handleStopSuggestedQuestions();console.log("开始发送消息:",e);this.isLoading=true;let t="";const s=new Date;const i=`${s.getHours()}:${s.getMinutes().toString().padStart(2,"0")}`;const n=e.trim()||(this.uploadedFileInfo.length>0?"请分析这个文件":"");const o={id:`temp-${Date.now()}`,time:i,query:n,answer:"",isStreaming:true,conversation_id:this.conversationId,inputs:{},status:"normal",error:null};this.currentStreamingMessage=o;this.shouldAutoScroll=true;this.scrollToBottom();const r={response_mode:"streaming",conversation_id:this.conversationId,query:n,user:"1234567890"};if(this.uploadedFileInfo.length>0){const e=this.uploadedFileInfo.map((e=>e.cos_key)).join(",");r.inputs={...r.inputs,input:e}}await a({url:`/sdk/v1/chat/chat-messages`,method:"POST",data:r,onMessage:e=>{console.log("收到Stream数据:",e);if(e.conversation_id&&!this.conversationId){this.conversationId=e.conversation_id;this.updateUrlWithConversationId(e.conversation_id)}if(e.event==="message"){if(e.event==="agent_message"||e.event==="message"){if(e.answer){t+=e.answer;const s={...this.currentStreamingMessage,answer:t,isStreaming:true};this.currentStreamingMessage=s;this.scrollToBottom()}}}if(e.event==="message_end"){this.streamComplete.emit({conversation_id:e.conversation_id||"",event:e.event,message_id:e.message_id,id:e.id})}},onError:e=>{console.error("发生错误:",e);this.messages=[...this.messages,{...o,answer:"抱歉,发生了错误,请稍后再试。",error:e,isStreaming:false}];this.currentStreamingMessage=null;this.isLoading=false},onComplete:()=>{console.log("请求完成");this.isLoading=false;this.messages=[...this.messages,this.currentStreamingMessage];if(this.currentStreamingMessage){this.getSuggestedQuestions(this.currentStreamingMessage.conversation_id)}this.currentStreamingMessage=null}})}handleScroll=()=>{const e=this.hostElement.shadowRoot?.querySelector(".chat-history");if(!e)return;const{scrollTop:t,scrollHeight:s,clientHeight:i}=e;const n=s-t-i;this.shouldAutoScroll=n<=this.SCROLL_THRESHOLD};scrollToBottom(){if(!this.shouldAutoScroll)return;const e=this.hostElement.shadowRoot?.querySelector(".chat-history");console.log("chatHistory",e);if(e&&this.isOpen){e.scrollTop=e.scrollHeight}}componentDidRender(){if(this.isLoadingHistory||this.shouldAutoScroll&&this.isOpen){const e=this.hostElement.shadowRoot?.querySelector(".chat-history");if(e){e.scrollTop=e.scrollHeight}}}updateUrlWithConversationId(e){const t=new URLSearchParams(window.location.search);if(!t.get("conversation_id")){const t=new URL(window.location.href);t.searchParams.set("conversation_id",e);window.history.replaceState({},"",t)}}handleSendMessage=()=>{if(!this.currentMessage.trim()&&this.uploadedFileInfo.length===0||this.isLoading)return;this.messageSent.emit(this.currentMessage);this.sendMessageToAPI(this.currentMessage);this.currentMessage="";this.clearSelectedFile();const e=this.hostElement.shadowRoot?.querySelector("input");e?.focus()};handleKeyDown=e=>{if(e.key==="Enter"&&!e.shiftKey){e.preventDefault();this.handleSendMessage()}};async loadHistoryMessages(){if(!this.conversationId)return;this.isLoadingHistory=true;try{const e=await n({url:`/share/messages`,params:{conversation_id:this.conversationId,user:"1234567890",limit:20}});if(!e.success||!e.data){throw new Error("加载历史消息失败")}const t=e.data||[];this.currentStreamingMessage=null;this.messages=[];const s=t.map((e=>{const t=new Date(e.created_at*1e3);const s=`${t.getHours()}:${t.getMinutes().toString().padStart(2,"0")}`;return{...e,time:s,isStreaming:false,status:e.status==="error"?"error":"normal"}}));this.messages=s;requestAnimationFrame((()=>{this.shouldAutoScroll=true;this.scrollToBottom()}))}catch(e){console.error("加载历史消息失败:",e)}finally{this.isLoadingHistory=false}}async handleIsOpenChange(e){if(e&&this.conversationId){await this.loadHistoryMessages()}}handleDefaultQueryChange(e){if(e&&!this.currentMessage){this.currentMessage=e}}componentWillLoad(){if(this.defaultQuery){this.currentMessage=this.defaultQuery}}render(){if(!this.isOpen)return null;const e={zIndex:String(this.zIndex)};const t={"modal-container":true,fullscreen:this.fullscreen};const s={"modal-overlay":true,"fullscreen-overlay":this.fullscreen};return i("div",{class:s,style:e},i("div",{class:t},this.isShowHeader&&i("div",{class:"modal-header"},i("div",{class:"header-left"},this.icon&&i("img",{src:this.icon,class:"header-icon",alt:"应用图标"}),i("h3",null,this.modalTitle)),this.isNeedClose&&i("button",{class:"close-button",onClick:this.handleClose},i("span",null,"×"))),i("div",{class:"chat-history",onScroll:this.handleScroll},this.isLoadingHistory?i("div",{class:"loading-container"},i("div",{class:"loading-spinner"}),i("p",null,"加载历史消息中...")):i(i.Fragment,null,this.messages.map((e=>i("div",{id:`message_${e.id}`,key:e.id},i("pcm-chat-message",{message:e,onMessageChange:t=>{const s=this.messages.map((s=>s.id===e.id?{...s,...t.detail}:s));this.messages=s}})))),this.currentStreamingMessage&&i("div",{id:`message_${this.currentStreamingMessage.id}`},i("pcm-chat-message",{message:this.currentStreamingMessage})),this.messages.length===0&&!this.currentStreamingMessage&&i("div",{class:"empty-state"},i("p",null,"请输入消息"))),this.suggestedQuestionsLoading?i("div",{class:"loading-suggestions"},i("div",{class:"loading-spinner-small"})):this.suggestedQuestions.length>0&&i("div",{class:"suggested-questions"},this.suggestedQuestions.map(((e,t)=>i("div",{key:t,class:"suggested-question",onClick:()=>{this.currentMessage=e;this.handleSendMessage()}},e,i("span",{class:"arrow-right"},"→")))))),this.selectedFile&&i("div",{class:"file-preview"},i("div",{class:"file-info"},i("span",{class:"file-name",title:this.selectedFile.name},this.selectedFile.name,this.isUploading&&i("span",{class:"uploading-indicator"}," (上传中...)"),this.uploadedFileInfo.length>0&&i("span",{class:"upload-success"}," (已上传)")),i("button",{class:"remove-file",onClick:this.clearSelectedFile},"×"))),i("div",{class:"message-input"},i("input",{type:"file",class:"file-input",onChange:this.handleFileChange,accept:"image/*,.pdf,.doc,.docx,.txt"}),i("button",{class:"upload-button",onClick:this.handleUploadClick,title:"上传文件",disabled:this.isUploading},i("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor"},i("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m0-16l-4 4m4-4l4 4"}))),i("div",{class:"input-wrapper"},i("input",{type:"text",placeholder:"请输入消息...",value:this.currentMessage,onInput:this.handleInputChange,onKeyDown:this.handleKeyDown,disabled:this.isLoading})),i("button",{class:"send-button",onClick:()=>this.handleSendMessage(),disabled:!this.currentMessage.trim()&&this.uploadedFileInfo.length===0||this.isLoading||this.isUploading},this.isLoading?"发送中...":"发送"))))}static get watchers(){return{isOpen:["handleIsOpenChange"],defaultQuery:["handleDefaultQueryChange"]}}};l.style=r;export{l as pcm_chat_modal};
|
|
2
|
-
//# sourceMappingURL=p-
|
|
1
|
+
import{r as e,c as t,g as s,h as i}from"./p-DaMwkrv5.js";import{s as n,u as o,a}from"./p-CDtyzi83.js";const r=":host{display:block}.modal-overlay{position:fixed;top:0;left:0;right:0;bottom:0;background-color:rgba(0, 0, 0, 0.5);display:flex;justify-content:center;align-items:center;overflow-y:auto;padding:20px;z-index:1000}.fullscreen-overlay{padding:0}.modal-container{background:white;border-radius:8px;width:100%;max-width:800px;height:80vh;min-height:600px;display:flex;flex-direction:column;position:relative;margin:auto}.modal-container.fullscreen{width:100vw;max-width:none;height:100vh;min-height:100vh;border-radius:0;margin:0}@media screen and (max-width: 768px){.modal-overlay{padding:0}.modal-container{width:95%;height:70vh;min-height:400px}.chat-history{min-height:200px;max-height:50vh}.modal-container.fullscreen{height:-webkit-fill-available;max-height:-webkit-fill-available;padding:env(safe-area-inset-top) 0 env(safe-area-inset-bottom)}.modal-container.fullscreen .chat-history{max-height:unset}.modal-container.fullscreen .modal-header{padding:0px 16px;padding-top:max(30px, env(safe-area-inset-top))}}.modal-header{display:flex;justify-content:space-between;align-items:center;padding:4px 16px;height:50px;border-bottom:1px solid #e8e8e8}.header-left{display:flex;align-items:center;gap:8px}.header-icon{width:24px;height:24px}.close-button{background:transparent;border:none;cursor:pointer;padding:8px;display:flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:4px}.close-button:hover{background-color:rgba(0, 0, 0, 0.04)}.close-button span{font-size:24px;line-height:1;color:#999}.close-button:hover span{color:#666}.chat-history{position:relative;flex:1;overflow-y:auto;padding:16px;scroll-behavior:smooth;min-height:400px;}@media screen and (max-width: 480px){.chat-history{min-height:200px;max-height:50vh}}.message-input{padding:16px;border-top:1px solid #eee;display:flex;gap:8px;align-items:center}.message-input input{flex:1;padding:8px 12px;border:1px solid #ddd;border-radius:4px;outline:none;transition:border-color 0.2s ease}.message-input input:focus{border-color:#bbb}.message{margin-bottom:16px;opacity:1;transition:opacity 0.3s ease}.message-content{max-width:70%;padding:8px 12px;border-radius:8px;word-break:break-word}.message-content p{margin:0;word-break:break-word}.user-message{display:flex;justify-content:flex-end}.agent-message{display:flex;justify-content:flex-start}.user-message .message-content{background-color:#007bff;color:white}.agent-message .message-content{background-color:#f1f1f1}.message-time{font-size:12px;color:#999;margin-top:4px;display:block}.send-button{background-color:#1890ff;color:white;border:none;border-radius:4px;padding:8px 16px;cursor:pointer;font-weight:500}.send-button:disabled{background-color:#ccc;cursor:not-allowed}.empty-state{display:flex;justify-content:center;align-items:center;height:100%;color:#999;text-align:center}.loading-container{position:absolute;top:0;left:0;right:0;bottom:0;display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:rgba(255, 255, 255, 0.98);z-index:1;opacity:1;transition:opacity 0.3s ease}.loading-container p{margin-top:16px;color:#666;font-size:14px}.loading-spinner{width:40px;height:40px;border:3px solid #f3f3f3;border-top:3px solid #1890ff;border-radius:50%;animation:spin 1s linear infinite}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}.messages-wrapper{width:100%;min-height:100%;display:flex;flex-direction:column;justify-content:flex-end}.messages-wrapper.has-overflow{justify-content:flex-start}.suggested-questions{display:flex;flex-direction:column;gap:8px;padding:16px}.suggested-question{display:flex;align-items:center;justify-content:space-between;padding:8px 12px;background-color:#f3f4f6;border-radius:4px;cursor:pointer;font-size:14px;color:#374151;transition:background-color 0.2s}.suggested-question:hover{background-color:#e5e7eb}.arrow-right{margin-left:8px}.loading-suggestions{display:flex;justify-content:center;padding:16px}.loading-spinner-small{width:20px;height:20px;border:2px solid #e5e7eb;border-top-color:#6b7280;border-radius:50%;animation:spin 1s linear infinite}.upload-button{background:transparent;border:none;cursor:pointer;padding:8px;display:flex;align-items:center;justify-content:center;color:#666;border-radius:4px;transition:background-color 0.2s}.upload-button:hover{background-color:rgba(0, 0, 0, 0.04)}.upload-button svg{width:20px;height:20px}.file-input{display:none}.selected-file{font-size:12px;color:#666;margin-left:8px;max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.input-wrapper{flex:1;display:flex;align-items:center;border:1px solid #ddd;border-radius:4px;padding:0 4px;background:white}.input-wrapper input{border:none;flex:1;padding:8px;outline:none}.input-wrapper:focus-within{border-color:#bbb}.file-preview{padding:8px 16px;border-top:1px solid #eee;background-color:#f9f9f9}.file-info{display:flex;align-items:center;justify-content:space-between;padding:8px;background:white;border:1px solid #e8e8e8;border-radius:4px}.file-name{font-size:13px;color:#333;margin-right:8px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:calc(100% - 30px)}.remove-file{background:transparent;border:none;color:#999;cursor:pointer;padding:4px 8px;font-size:16px;line-height:1;border-radius:4px;transition:all 0.2s}.remove-file:hover{background-color:#f0f0f0;color:#666}";const l=class{constructor(s){e(this,s);this.messageSent=t(this,"messageSent");this.modalClosed=t(this,"modalClosed");this.streamComplete=t(this,"streamComplete")}modalTitle="在线客服";apiKey="";isOpen=false;messages=[];currentMessage="";messageSent;modalClosed;icon;zIndex=1e3;isShowHeader=true;isNeedClose=true;botId;conversationId;currentAssistantMessage="";isLoading=false;currentStreamingMessage=null;shouldAutoScroll=true;SCROLL_THRESHOLD=30;isLoadingHistory=false;get hostElement(){return s(this)}streamComplete;suggestedQuestions=[];suggestedQuestionsLoading=false;stopSuggestedQuestionsRef={current:false};selectedFile=null;isUploading=false;uploadedFileInfo=[];defaultQuery="";fullscreen=false;handleClose=()=>{this.modalClosed.emit()};handleInputChange=e=>{const t=e.target;this.currentMessage=t.value};async getSuggestedQuestions(e){this.stopSuggestedQuestionsRef.current=false;this.suggestedQuestionsLoading=true;try{const t=await n({url:`/share/messages/${e}/suggested`});if(this.stopSuggestedQuestionsRef.current)return;if(t.success&&t.data){this.suggestedQuestions=t.data||[]}}catch(e){console.error("获取问题建议失败:",e)}finally{this.suggestedQuestionsLoading=false}}handleStopSuggestedQuestions=()=>{this.suggestedQuestions=[];this.stopSuggestedQuestionsRef.current=true};handleFileChange=async e=>{const t=e.target;if(t.files&&t.files.length>0){this.selectedFile=t.files[0];await this.uploadFile()}};async uploadFile(){if(!this.selectedFile)return;this.isUploading=true;try{const e=await o(this.selectedFile,{authorization:"Bearer "+this.apiKey});this.uploadedFileInfo.push(e)}catch(e){console.error("文件上传错误:",e);this.clearSelectedFile();alert("文件上传失败,请重试")}finally{this.isUploading=false}}handleUploadClick=()=>{const e=this.hostElement.shadowRoot?.querySelector(".file-input");e?.click()};clearSelectedFile=()=>{this.selectedFile=null;this.uploadedFileInfo=[];const e=this.hostElement.shadowRoot?.querySelector(".file-input");if(e){e.value=""}};async sendMessageToAPI(e){this.handleStopSuggestedQuestions();console.log("开始发送消息:",e);this.isLoading=true;let t="";const s=new Date;const i=`${s.getHours()}:${s.getMinutes().toString().padStart(2,"0")}`;const n=e.trim()||(this.uploadedFileInfo.length>0?"请分析这个文件":"");const o={id:`temp-${Date.now()}`,time:i,query:n,answer:"",isStreaming:true,conversation_id:this.conversationId,inputs:{},status:"normal",error:null};this.currentStreamingMessage=o;this.shouldAutoScroll=true;this.scrollToBottom();const r={response_mode:"streaming",conversation_id:this.conversationId,query:n,user:"1234567890"};if(this.uploadedFileInfo.length>0){const e=this.uploadedFileInfo.map((e=>e.cos_key)).join(",");r.inputs={...r.inputs,input:e}}await a({url:`/sdk/v1/chat/chat-messages`,method:"POST",data:r,onMessage:e=>{console.log("收到Stream数据:",e);if(e.conversation_id&&!this.conversationId){this.conversationId=e.conversation_id;this.updateUrlWithConversationId(e.conversation_id)}if(e.event==="message"){if(e.event==="agent_message"||e.event==="message"){if(e.answer){t+=e.answer;const s={...this.currentStreamingMessage,answer:t,isStreaming:true};this.currentStreamingMessage=s;this.scrollToBottom()}}}if(e.event==="message_end"){this.streamComplete.emit({conversation_id:e.conversation_id||"",event:e.event,message_id:e.message_id,id:e.id})}},onError:e=>{console.error("发生错误:",e);this.messages=[...this.messages,{...o,answer:"抱歉,发生了错误,请稍后再试。",error:e,isStreaming:false}];this.currentStreamingMessage=null;this.isLoading=false},onComplete:()=>{console.log("请求完成");this.isLoading=false;this.messages=[...this.messages,this.currentStreamingMessage];if(this.currentStreamingMessage){this.getSuggestedQuestions(this.currentStreamingMessage.conversation_id)}this.currentStreamingMessage=null}})}handleScroll=()=>{const e=this.hostElement.shadowRoot?.querySelector(".chat-history");if(!e)return;const{scrollTop:t,scrollHeight:s,clientHeight:i}=e;const n=s-t-i;this.shouldAutoScroll=n<=this.SCROLL_THRESHOLD};scrollToBottom(){if(!this.shouldAutoScroll)return;const e=this.hostElement.shadowRoot?.querySelector(".chat-history");console.log("chatHistory",e);if(e&&this.isOpen){e.scrollTop=e.scrollHeight}}componentDidRender(){if(this.isLoadingHistory||this.shouldAutoScroll&&this.isOpen){const e=this.hostElement.shadowRoot?.querySelector(".chat-history");if(e){e.scrollTop=e.scrollHeight}}}updateUrlWithConversationId(e){const t=new URLSearchParams(window.location.search);if(!t.get("conversation_id")){const t=new URL(window.location.href);t.searchParams.set("conversation_id",e);window.history.replaceState({},"",t)}}handleSendMessage=()=>{if(!this.currentMessage.trim()&&this.uploadedFileInfo.length===0||this.isLoading)return;this.messageSent.emit(this.currentMessage);this.sendMessageToAPI(this.currentMessage);this.currentMessage="";this.clearSelectedFile();const e=this.hostElement.shadowRoot?.querySelector("input");e?.focus()};handleKeyDown=e=>{if(e.key==="Enter"&&!e.shiftKey){e.preventDefault();this.handleSendMessage()}};async loadHistoryMessages(){if(!this.conversationId)return;this.isLoadingHistory=true;try{const e=await n({url:`/share/messages`,params:{conversation_id:this.conversationId,user:"1234567890",limit:20}});if(!e.success||!e.data){throw new Error("加载历史消息失败")}const t=e.data||[];this.currentStreamingMessage=null;this.messages=[];const s=t.map((e=>{const t=new Date(e.created_at*1e3);const s=`${t.getHours()}:${t.getMinutes().toString().padStart(2,"0")}`;return{...e,time:s,isStreaming:false,status:e.status==="error"?"error":"normal"}}));this.messages=s;requestAnimationFrame((()=>{this.shouldAutoScroll=true;this.scrollToBottom()}))}catch(e){console.error("加载历史消息失败:",e)}finally{this.isLoadingHistory=false}}async handleIsOpenChange(e){if(e&&this.conversationId){await this.loadHistoryMessages()}}handleDefaultQueryChange(e){if(e&&!this.currentMessage){this.currentMessage=e}}componentWillLoad(){if(this.defaultQuery){this.currentMessage=this.defaultQuery}}render(){if(!this.isOpen)return null;const e={zIndex:String(this.zIndex)};const t={"modal-container":true,fullscreen:this.fullscreen};const s={"modal-overlay":true,"fullscreen-overlay":this.fullscreen};return i("div",{class:s,style:e},i("div",{class:t},this.isShowHeader&&i("div",{class:"modal-header"},i("div",{class:"header-left"},this.icon&&i("img",{src:this.icon,class:"header-icon",alt:"应用图标"}),i("h3",null,this.modalTitle)),this.isNeedClose&&i("button",{class:"close-button",onClick:this.handleClose},i("span",null,"×"))),i("div",{class:"chat-history",onScroll:this.handleScroll},this.isLoadingHistory?i("div",{class:"loading-container"},i("div",{class:"loading-spinner"}),i("p",null,"加载历史消息中...")):i(i.Fragment,null,this.messages.map((e=>i("div",{id:`message_${e.id}`,key:e.id},i("pcm-chat-message",{message:e,onMessageChange:t=>{const s=this.messages.map((s=>s.id===e.id?{...s,...t.detail}:s));this.messages=s}})))),this.currentStreamingMessage&&i("div",{id:`message_${this.currentStreamingMessage.id}`},i("pcm-chat-message",{message:this.currentStreamingMessage})),this.messages.length===0&&!this.currentStreamingMessage&&i("div",{class:"empty-state"},i("p",null,"请输入消息"))),this.suggestedQuestionsLoading?i("div",{class:"loading-suggestions"},i("div",{class:"loading-spinner-small"})):this.suggestedQuestions.length>0&&i("div",{class:"suggested-questions"},this.suggestedQuestions.map(((e,t)=>i("div",{key:t,class:"suggested-question",onClick:()=>{this.currentMessage=e;this.handleSendMessage()}},e,i("span",{class:"arrow-right"},"→")))))),this.selectedFile&&i("div",{class:"file-preview"},i("div",{class:"file-info"},i("span",{class:"file-name",title:this.selectedFile.name},this.selectedFile.name,this.isUploading&&i("span",{class:"uploading-indicator"}," (上传中...)"),this.uploadedFileInfo.length>0&&i("span",{class:"upload-success"}," (已上传)")),i("button",{class:"remove-file",onClick:this.clearSelectedFile},"×"))),i("div",{class:"message-input"},i("input",{type:"file",class:"file-input",onChange:this.handleFileChange,accept:"image/*,.pdf,.doc,.docx,.txt"}),i("button",{class:"upload-button",onClick:this.handleUploadClick,title:"上传文件",disabled:this.isUploading},i("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor"},i("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m0-16l-4 4m4-4l4 4"}))),i("div",{class:"input-wrapper"},i("input",{type:"text",placeholder:"请输入消息...",value:this.currentMessage,onInput:this.handleInputChange,onKeyDown:this.handleKeyDown,disabled:this.isLoading})),i("button",{class:"send-button",onClick:()=>this.handleSendMessage(),disabled:!this.currentMessage.trim()&&this.uploadedFileInfo.length===0||this.isLoading||this.isUploading},this.isLoading?"发送中...":"发送"))))}static get watchers(){return{isOpen:["handleIsOpenChange"],defaultQuery:["handleDefaultQueryChange"]}}};l.style=r;export{l as pcm_chat_modal};
|
|
2
|
+
//# sourceMappingURL=p-430f9a9f.entry.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e="https://www.pincaimao.com/agents/api";function t(e,t,s){return(e||"")+(t?` ${t}`:"")+(s?` ${s}`:"")}const s=async t=>{const{url:s,method:o,headers:a={},data:n,onMessage:r,onError:c,onComplete:i}=t;try{const t=`${e}${s}`;const c=await fetch(t,{method:o,headers:{Accept:"text/event-stream","Content-Type":"application/json",...a},body:n?JSON.stringify(n):undefined});if(!c.ok){throw new Error(`HTTP error! status: ${c.status}`)}const f=c.body?.getReader();if(!f)throw new Error("No reader available");const l=new TextDecoder;let u="";while(true){const{value:e,done:t}=await f.read();if(t)break;u+=l.decode(e,{stream:true});const s=u.split("\n");u=s.pop()||"";for(const e of s){if(e.startsWith("data:")){try{const t=e.substring(5).trim();if(!t)continue;const s=JSON.parse(t);r?.(s)}catch(t){console.error("解析 SSE 数据错误:",t,"原始数据:",e)}}}}i?.()}catch(e){console.error("SSE 请求错误:",e);c?.(e)}};const o=async t=>{const{url:s,method:o="GET",headers:a={},params:n={},data:r,formData:c,onMessage:i}=t;try{const t=new URLSearchParams;Object.entries(n).forEach((([e,s])=>{if(s!==undefined&&s!==null){t.append(e,String(s))}}));let f=`${e}${s}${t.toString()?`?${t.toString()}`:""}`;const l={method:o,headers:c?{...a}:{"Content-Type":"application/json",...a}};if(c){l.body=c}else if(o!=="GET"&&o!=="HEAD"&&r){l.body=JSON.stringify(r)}if(o==="GET"&&r){const e=new URLSearchParams;Object.entries(r).forEach((([t,s])=>{if(s!==undefined&&s!==null){e.append(t,String(s))}}));f+=(t.toString()?"&":"?")+e.toString()}const u=await fetch(f,l);const d=await u.json();if(i){i(d)}if(!u.ok){console.error(`HTTP错误: ${u.status} ${u.statusText}`);return{success:false,message:d.message||`HTTP错误: ${u.status}`,error:d}}if(d.code!==0){console.error(`API错误: ${d.message}`);return{success:false,message:d.message,error:d}}return{success:true,data:d.data}}catch(e){console.error("HTTP请求错误:",e);if(t.onError){t.onError(e)}return{success:false,error:e,message:e instanceof Error?e.message:"未知错误"}}finally{if(t.onComplete){t.onComplete()}}};const a=async(e,t)=>{const s=new FormData;s.append("file",e);try{const e=await o({url:"/sdk/v1/files/upload",method:"POST",headers:{...t},formData:s});if(!e.success||!e.data){throw new Error(e.message||"文件上传失败")}return e.data}catch(e){console.error("文件上传错误:",e);throw e}};export{e as A,s as a,t as f,o as s,a as u};
|
|
2
|
+
//# sourceMappingURL=p-CDtyzi83.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"p-CDtyzi83.js","sources":["src/utils/utils.ts"],"sourcesContent":["/**\n * API域名配置\n */\n// export const API_DOMAIN = 'http://192.168.17.194:8000';\n// export const API_DOMAIN = 'https://tagents.ylzhaopin.com/agents/api';\nexport const API_DOMAIN = 'https://www.pincaimao.com/agents/api';\n\n\nexport function format(first?: string, middle?: string, last?: string): string {\n return (first || '') + (middle ? ` ${middle}` : '') + (last ? ` ${last}` : '');\n}\n\n// 添加类型定义\nexport interface UserInputMessageType {\n message: string;\n [key: string]: any;\n}\n\nexport interface WorkFlowNode {\n message_id?: string;\n conversation_id?: string;\n created_at?: string;\n event?: string;\n answer?: string;\n data?: {\n outputs?: {\n answer?: string;\n };\n status?: string;\n error?: any;\n };\n}\n\nexport interface MessageRound extends UserInputMessageType {\n id?: string;\n conversation_id?: string;\n created_at?: string;\n answer?: string;\n status?: string;\n error?: any;\n}\n\n/**\n * 将工作流节点转换为消息轮次\n * @param message_event 消息事件类型\n * @param inputMessage 用户输入消息\n * @param streamNode 工作流节点\n * @returns 消息轮次\n */\nexport const convertWorkflowStreamNodeToMessageRound = (\n message_event: string,\n inputMessage: UserInputMessageType,\n streamNode: WorkFlowNode,\n): MessageRound => {\n const messageRound: MessageRound = {\n ...inputMessage,\n };\n if (message_event === 'workflow_finished') messageRound.answer = streamNode.data?.outputs?.answer;\n if (message_event === 'agent_message' || message_event === 'message') messageRound.answer = streamNode?.answer;\n messageRound.id = streamNode.message_id;\n messageRound.conversation_id = streamNode.conversation_id;\n messageRound.created_at = streamNode.created_at;\n messageRound.status = streamNode.data?.status;\n messageRound.error = streamNode.data?.error;\n return messageRound;\n};\n\n/**\n * SSE 流式请求配置接口\n */\nexport interface SSERequestConfig {\n url: string;\n method: string;\n headers?: Record<string, string>;\n data?: any;\n onMessage?: (data: any) => void;\n onError?: (error: any) => void;\n onComplete?: () => void;\n}\n\n/**\n * 发送 SSE 流式请求\n * @param config 请求配置\n * @returns Promise<void>\n */\nexport const sendSSERequest = async (config: SSERequestConfig): Promise<void> => {\n const { url, method, headers = {}, data, onMessage, onError, onComplete } = config;\n \n try {\n // 使用 API_DOMAIN 拼接完整的请求URL\n const requestUrl = `${API_DOMAIN}${url}`;\n \n const response = await fetch(requestUrl, {\n method,\n headers: {\n 'Accept': 'text/event-stream',\n 'Content-Type': 'application/json',\n ...headers\n },\n body: data ? JSON.stringify(data) : undefined\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const reader = response.body?.getReader();\n if (!reader) throw new Error('No reader available');\n \n const decoder = new TextDecoder();\n let buffer = '';\n\n while (true) {\n const { value, done } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n\n // 处理缓冲区中的完整消息\n const lines = buffer.split('\\n');\n buffer = lines.pop() || ''; // 保留最后一个不完整的行\n\n for (const line of lines) {\n if (line.startsWith('data:')) {\n try {\n const jsonStr = line.substring(5).trim();\n if (!jsonStr) continue;\n \n const data = JSON.parse(jsonStr);\n onMessage?.(data);\n } catch (e) {\n console.error('解析 SSE 数据错误:', e, '原始数据:', line);\n }\n }\n }\n }\n \n onComplete?.();\n } catch (error) {\n console.error('SSE 请求错误:', error);\n onError?.(error);\n }\n};\n\n/**\n * HTTP请求配置接口\n */\nexport interface HttpRequestConfig {\n url: string;\n method?: string;\n headers?: Record<string, string>;\n params?: Record<string, any>;\n data?: any;\n formData?: FormData; // 添加FormData支持\n onMessage?: (data: any) => void;\n onError?: (error: any) => void;\n onComplete?: () => void;\n}\n\n/**\n * 统一的API响应接口\n */\nexport interface ApiResponse<T = any> {\n code: number;\n message: string;\n data?: T;\n}\n\n/**\n * HTTP响应接口\n */\nexport interface HttpResponse<T = any> {\n success: boolean;\n data?: T;\n error?: any;\n message?: string;\n}\n\n/**\n * 发送HTTP请求\n * @param config 请求配置\n * @returns Promise<HttpResponse>\n */\nexport const sendHttpRequest = async <T = any>(config: HttpRequestConfig): Promise<HttpResponse<T>> => {\n const { url, method = 'GET', headers = {}, params = {}, data, formData, onMessage } = config;\n \n try {\n // 构建URL和查询参数\n const queryParams = new URLSearchParams();\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n queryParams.append(key, String(value));\n }\n });\n \n // 使用 API_DOMAIN 拼接完整的请求URL\n let requestUrl = `${API_DOMAIN}${url}${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;\n \n // 创建请求配置对象\n const requestConfig: RequestInit = {\n method,\n headers: formData ? { ...headers } : {\n 'Content-Type': 'application/json',\n ...headers\n }\n };\n\n // 处理请求体\n if (formData) {\n // 如果提供了FormData,直接使用\n requestConfig.body = formData;\n } else if (method !== 'GET' && method !== 'HEAD' && data) {\n // 否则,如果是非GET/HEAD请求且有data,将其JSON序列化\n requestConfig.body = JSON.stringify(data);\n }\n\n // 如果是 GET 方法且有 data,将其作为查询参数添加到 URL\n if (method === 'GET' && data) {\n const dataParams = new URLSearchParams();\n Object.entries(data).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n dataParams.append(key, String(value));\n }\n });\n requestUrl += (queryParams.toString() ? '&' : '?') + dataParams.toString();\n }\n\n const response = await fetch(requestUrl, requestConfig);\n const responseData: ApiResponse<T> = await response.json();\n \n // 调用 onMessage 回调\n if (onMessage) {\n onMessage(responseData);\n }\n \n // 检查响应状态\n if (!response.ok) {\n console.error(`HTTP错误: ${response.status} ${response.statusText}`);\n return {\n success: false,\n message: responseData.message || `HTTP错误: ${response.status}`,\n error: responseData\n };\n }\n \n // 检查业务状态码\n if (responseData.code !== 0) {\n console.error(`API错误: ${responseData.message}`);\n return {\n success: false,\n message: responseData.message,\n error: responseData\n };\n }\n \n // 直接返回data\n return {\n success: true,\n data: responseData.data\n };\n } catch (error) {\n console.error('HTTP请求错误:', error);\n if (config.onError) {\n config.onError(error);\n }\n return {\n success: false,\n error,\n message: error instanceof Error ? error.message : '未知错误'\n };\n } finally {\n if (config.onComplete) {\n config.onComplete();\n }\n }\n};\n\n\n\n/**\n * 文件上传响应数据接口\n */\nexport interface FileUploadResponse {\n /** 文件在对象存储中的唯一标识符 */\n cos_key: string;\n /** 文件名称 */\n file_name: string;\n /** 文件大小(带单位的字符串,如 \"1.5MB\") */\n file_size: string;\n /** 文件的预签名URL */\n presigned_url: string;\n /** 文件扩展名 */\n ext: string;\n}\n\n/**\n * 通过后端API上传文件\n * @param file 要上传的文件\n * @param headers 可选的请求头\n * @returns Promise 包含上传结果\n */\nexport const uploadFileToBackend = async (\n file: File,\n headers?: Record<string, string>\n): Promise<FileUploadResponse> => {\n const formData = new FormData();\n formData.append('file', file);\n \n try {\n const response = await sendHttpRequest<{cos_key: string, file_name: string, file_size: string,presigned_url: string, ext: string}>({\n url: '/sdk/v1/files/upload',\n method: 'POST',\n headers: {\n ...headers\n },\n formData\n });\n \n if (!response.success || !response.data) {\n throw new Error(response.message || '文件上传失败');\n }\n \n return response.data;\n } catch (error) {\n console.error('文件上传错误:', error);\n throw error;\n }\n};\n"],"names":[],"mappings":"AAAA;;AAEG;AACH;AACA;AACO,MAAM,UAAU,GAAG;SAGV,MAAM,CAAC,KAAc,EAAE,MAAe,EAAE,IAAa,EAAA;AACnE,IAAA,OAAO,CAAC,KAAK,IAAI,EAAE,KAAK,MAAM,GAAG,CAAI,CAAA,EAAA,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,GAAG,CAAI,CAAA,EAAA,IAAI,EAAE,GAAG,EAAE,CAAC;AAChF;AAsEA;;;;AAIG;MACU,cAAc,GAAG,OAAO,MAAwB,KAAmB;AAC9E,IAAA,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM;AAElF,IAAA,IAAI;;AAEF,QAAA,MAAM,UAAU,GAAG,CAAA,EAA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