pcm-agents 0.3.0 → 0.3.2
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 +195 -0
- package/dist/cjs/index-BFPEnLbS.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-jlpx-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 +6560 -0
- package/dist/cjs/pcm-app-chat-modal_7.cjs.entry.js.map +1 -0
- package/dist/cjs/pcm-chat-modal.cjs.entry.js +17 -32
- package/dist/cjs/pcm-chat-modal.cjs.entry.js.map +1 -1
- package/dist/cjs/pcm-chat-modal.entry.cjs.js.map +1 -1
- package/dist/collection/collection-manifest.json +2 -0
- 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.css +2 -1
- package/dist/collection/components/pcm-app-chat-modal/pcm-app-chat-modal.js +137 -159
- package/dist/collection/components/pcm-app-chat-modal/pcm-app-chat-modal.js.map +1 -1
- package/dist/collection/components/pcm-chat-message/pcm-chat-message.css +66 -12
- package/dist/collection/components/pcm-chat-message/pcm-chat-message.js +106 -13
- package/dist/collection/components/pcm-chat-message/pcm-chat-message.js.map +1 -1
- package/dist/collection/components/pcm-chat-modal/pcm-chat-modal.js +39 -34
- package/dist/collection/components/pcm-chat-modal/pcm-chat-modal.js.map +1 -1
- package/dist/collection/components/pcm-hr-chat-modal/pcm-hr-chat-modal.js +76 -105
- 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.css +162 -0
- package/dist/collection/components/pcm-jlpx-modal/pcm-jlpx-modal.js +616 -0
- package/dist/collection/components/pcm-jlpx-modal/pcm-jlpx-modal.js.map +1 -0
- package/dist/collection/components/pcm-mnms-modal/pcm-mnms-modal.css +0 -79
- package/dist/collection/components/pcm-mnms-modal/pcm-mnms-modal.js +133 -81
- 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 +77 -101
- 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.css +273 -0
- package/dist/collection/components/pcm-zygh-modal/pcm-zygh-modal.js +613 -0
- package/dist/collection/components/pcm-zygh-modal/pcm-zygh-modal.js.map +1 -0
- package/dist/collection/global/global.css +324 -0
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/interfaces/chat.js.map +1 -1
- package/dist/collection/utils/utils.js +54 -113
- package/dist/collection/utils/utils.js.map +1 -1
- package/dist/components/index.js +1298 -11280
- package/dist/components/index.js.map +1 -1
- package/dist/components/my-component.js +2 -3
- package/dist/components/my-component.js.map +1 -1
- package/dist/components/{p-C4l_DOnx.js → p-BctfuDvG.js} +106 -147
- package/dist/components/p-BctfuDvG.js.map +1 -0
- package/dist/components/{p-D0s1Q-3O.js → p-LkDC0SN2.js} +343 -16
- package/dist/components/p-LkDC0SN2.js.map +1 -0
- package/dist/components/pcm-app-chat-modal.js +1 -1
- package/dist/components/pcm-chat-message.js +1 -1
- package/dist/components/pcm-chat-modal.js +19 -34
- package/dist/components/pcm-chat-modal.js.map +1 -1
- package/dist/components/pcm-hr-chat-modal.js +70 -100
- package/dist/components/pcm-hr-chat-modal.js.map +1 -1
- package/dist/components/pcm-jlpx-modal.d.ts +11 -0
- package/dist/components/pcm-jlpx-modal.js +339 -0
- package/dist/components/pcm-jlpx-modal.js.map +1 -0
- package/dist/components/pcm-mnms-modal.js +109 -57
- package/dist/components/pcm-mnms-modal.js.map +1 -1
- package/dist/components/pcm-video-chat-modal.js +74 -99
- package/dist/components/pcm-video-chat-modal.js.map +1 -1
- package/dist/components/pcm-zygh-modal.d.ts +11 -0
- package/dist/components/pcm-zygh-modal.js +330 -0
- package/dist/components/pcm-zygh-modal.js.map +1 -0
- package/dist/esm/index-nVjZGfA8.js +189 -0
- package/dist/esm/index-nVjZGfA8.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-jlpx-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 +6552 -0
- package/dist/esm/pcm-app-chat-modal_7.entry.js.map +1 -0
- package/dist/esm/pcm-chat-modal.entry.js +17 -32
- package/dist/esm/pcm-chat-modal.entry.js.map +1 -1
- package/dist/pcm-agents/index.esm.js +1 -1
- package/dist/pcm-agents/my-component.entry.esm.js.map +1 -1
- package/dist/pcm-agents/p-55417392.entry.js +2 -0
- package/dist/pcm-agents/p-55417392.entry.js.map +1 -0
- package/dist/pcm-agents/p-a698b59f.entry.js +2 -0
- package/dist/pcm-agents/p-a698b59f.entry.js.map +1 -0
- package/dist/pcm-agents/p-f3ca99b4.entry.js +2 -0
- package/dist/pcm-agents/p-f3ca99b4.entry.js.map +1 -0
- package/dist/pcm-agents/p-nVjZGfA8.js +2 -0
- package/dist/pcm-agents/p-nVjZGfA8.js.map +1 -0
- package/dist/pcm-agents/pcm-agents.esm.js +1 -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 +1 -0
- package/dist/pcm-agents/pcm-chat-modal.entry.esm.js.map +1 -1
- package/dist/types/components/pcm-app-chat-modal/pcm-app-chat-modal.d.ts +13 -8
- package/dist/types/components/pcm-chat-message/pcm-chat-message.d.ts +5 -0
- package/dist/types/components/pcm-chat-modal/pcm-chat-modal.d.ts +8 -8
- package/dist/types/components/pcm-hr-chat-modal/pcm-hr-chat-modal.d.ts +6 -12
- package/dist/types/components/pcm-jlpx-modal/pcm-jlpx-modal.d.ts +113 -0
- package/dist/types/components/pcm-mnms-modal/pcm-mnms-modal.d.ts +19 -20
- package/dist/types/components/pcm-video-chat-modal/pcm-video-chat-modal.d.ts +4 -4
- package/dist/types/components/pcm-zygh-modal/pcm-zygh-modal.d.ts +117 -0
- package/dist/types/components.d.ts +429 -80
- package/dist/types/interfaces/chat.d.ts +0 -4
- package/dist/types/utils/utils.d.ts +29 -83
- package/package.json +61 -60
- package/readme.md +307 -307
- package/dist/cjs/index-DfIUl99H.js +0 -11413
- package/dist/cjs/index-DfIUl99H.js.map +0 -1
- package/dist/cjs/pcm-app-chat-modal.pcm-chat-message.pcm-mnms-modal.entry.cjs.js.map +0 -1
- package/dist/cjs/pcm-app-chat-modal_3.cjs.entry.js +0 -3734
- package/dist/cjs/pcm-app-chat-modal_3.cjs.entry.js.map +0 -1
- package/dist/cjs/pcm-hr-chat-modal.cjs.entry.js +0 -1078
- package/dist/cjs/pcm-hr-chat-modal.cjs.entry.js.map +0 -1
- package/dist/cjs/pcm-hr-chat-modal.entry.cjs.js.map +0 -1
- package/dist/cjs/pcm-video-chat-modal.cjs.entry.js +0 -927
- package/dist/cjs/pcm-video-chat-modal.cjs.entry.js.map +0 -1
- package/dist/cjs/pcm-video-chat-modal.entry.cjs.js.map +0 -1
- package/dist/components/p-C4l_DOnx.js.map +0 -1
- package/dist/components/p-CgDy4pJp.js +0 -1244
- package/dist/components/p-CgDy4pJp.js.map +0 -1
- package/dist/components/p-D0s1Q-3O.js.map +0 -1
- package/dist/esm/index-B2EtEi7v.js +0 -11409
- package/dist/esm/index-B2EtEi7v.js.map +0 -1
- package/dist/esm/pcm-app-chat-modal.pcm-chat-message.pcm-mnms-modal.entry.js.map +0 -1
- package/dist/esm/pcm-app-chat-modal_3.entry.js +0 -3730
- package/dist/esm/pcm-app-chat-modal_3.entry.js.map +0 -1
- package/dist/esm/pcm-hr-chat-modal.entry.js +0 -1076
- package/dist/esm/pcm-hr-chat-modal.entry.js.map +0 -1
- package/dist/esm/pcm-video-chat-modal.entry.js +0 -925
- package/dist/esm/pcm-video-chat-modal.entry.js.map +0 -1
- package/dist/pcm-agents/p-0ddd5c47.entry.js +0 -2
- package/dist/pcm-agents/p-0ddd5c47.entry.js.map +0 -1
- package/dist/pcm-agents/p-5f624943.entry.js +0 -2
- package/dist/pcm-agents/p-5f624943.entry.js.map +0 -1
- package/dist/pcm-agents/p-6c07f155.entry.js +0 -2
- package/dist/pcm-agents/p-6c07f155.entry.js.map +0 -1
- package/dist/pcm-agents/p-9a1fb6ca.entry.js +0 -2
- package/dist/pcm-agents/p-9a1fb6ca.entry.js.map +0 -1
- package/dist/pcm-agents/p-B2EtEi7v.js +0 -146
- package/dist/pcm-agents/p-B2EtEi7v.js.map +0 -1
- package/dist/pcm-agents/p-e21bc169.entry.js +0 -2
- package/dist/pcm-agents/p-e21bc169.entry.js.map +0 -1
- package/dist/pcm-agents/pcm-app-chat-modal.pcm-chat-message.pcm-mnms-modal.entry.esm.js.map +0 -1
- package/dist/pcm-agents/pcm-hr-chat-modal.entry.esm.js.map +0 -1
- package/dist/pcm-agents/pcm-video-chat-modal.entry.esm.js.map +0 -1
|
@@ -1,925 +0,0 @@
|
|
|
1
|
-
import { r as registerInstance, c as createEvent, g as getElement, h } from './index-DaMwkrv5.js';
|
|
2
|
-
import { a as sendSSERequest, s as sendHttpRequest } from './index-B2EtEi7v.js';
|
|
3
|
-
|
|
4
|
-
const pcmVideoChatModalCss = ":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;display:flex;flex-direction:column;position:relative;margin:auto}.modal-container.fullscreen{width:100vw;max-width:none;height:100%;border-radius:0;margin:0;display:flex;flex-direction:column;height:100vh;max-height:100vh}.modal-container.fullscreen>div:not(.modal-header):not(.initial-upload){display:flex;flex-direction:column;flex:1;overflow:hidden;height:100%}.pc-layout{width:80%;max-width:800px;min-width:320px;min-height:400px}.mobile-layout{width:100%;height:100%;border-radius:0}@media screen and (max-width: 768px){.pc-layout{width:95%;}.modal-overlay{padding:0}.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.mobile-layout{width:100%;height:100vh;max-height:100vh;min-height:100vh;border-radius:0;margin:0;display:flex;flex-direction:column}}.video-preview.placeholder{display:flex;justify-content:center;align-items:center;background:#EAEAEA}.placeholder-status{color:#00000066}.waiting-message p{margin:0;font-size:16px;color:white;font-weight:500}.recording-container{width:100%;display:flex;flex-direction:column;align-items:center}.video-area{width:100%;display:flex;flex-direction:column;align-items:center}.stop-recording-button{width:100%;height:100%;font-size:16px;background:#f44336;border-radius:6px;color:white;border:none;cursor:pointer}.stop-recording-button:hover{background:#d32f2f}.play-audio-container{width:100%;height:100%;display:flex;justify-content:center;align-items:center}.modal-header{display:flex;justify-content:space-between;align-items:center;padding:4px 16px;height:50px;border-bottom:1px solid #e8e8e8;flex-shrink:0;}.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:20px;scroll-behavior:smooth;min-height:200px;background:url(https://pcm-resource-1312611446.cos.ap-guangzhou.myqcloud.com/web/sdk/chat_bg.png);background-size:100%}.fullscreen .chat-history{height:auto;flex:1 1 auto}.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}.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}.function-select{margin-top:2rem}.function-options{display:flex;flex-wrap:wrap;gap:1rem;justify-content:center;margin-top:1rem}.function-button{padding:0.5rem 1rem;border:1px solid #ddd;border-radius:4px;background:white;cursor:pointer;transition:all 0.3s ease}.function-button:hover{border-color:#1890ff;color:#1890ff}.function-button.selected{background:#1890ff;color:white;border-color:#1890ff}.recording-section{border-top:1px solid #eee;display:flex;flex-direction:column;align-items:center;padding:20px;border-radius:14px 14px 0 0;flex:0 0 auto}.recording-section .video-preview{width:100%;height:200px;max-width:400px;position:relative;margin-bottom:10px;border:1px solid #ddd;border-radius:12px;overflow:hidden}.recording-section video{width:100%;height:100%;object-fit:cover}.recording-status{position:absolute;top:10px;left:10px;background-color:rgba(0, 0, 0, 0.6);color:white;padding:4px 8px;border-radius:4px;display:flex;align-items:center;gap:5px;font-size:0.8rem;z-index:2}.recording-status .recording-dot{display:inline-block;width:10px;height:10px;background-color:red;border-radius:50%;margin-right:5px;animation:blink 1s infinite}.recording-status.warning{color:#ff4d4f;animation:blink 1s infinite}@keyframes blink{0%{opacity:1}50%{opacity:0.5}100%{opacity:1}}.recording-section .stop-recording-button{background-color:#f44336;color:white;border:none;cursor:pointer;font-weight:bold}.recording-section .stop-recording-button:hover{background-color:#d32f2f}.fullscreen{width:100vw;border-radius:0;height:100vh;display:flex;flex-direction:column;overflow-y:auto}.recording-controls{margin-top:10px;height:53px;width:100%;max-width:400px;display:flex;justify-content:center}.recording-controls .waiting-message{text-align:center;color:white;font-size:1rem;background-image:linear-gradient(100deg, #4A9FFF 0%, #1058FF 100%);border-radius:6px;box-shadow:0 2px 8px rgba(0, 0, 0, 0.15);width:95%;display:flex;justify-content:center;align-items:center;cursor:pointer}.recording-controls .waiting-message.loading{background:#faad14}.recording-controls .waiting-message p{margin:0;font-size:16px;color:white;font-weight:500}.recording-controls .stop-recording-button{background-color:#dc3545;color:white;border:none;cursor:pointer;font-size:1rem}.recording-controls .stop-recording-button:hover{background-color:#c82333}.recording-controls .stop-recording-button.disabled{background:#ccc;cursor:not-allowed}.recording-controls .stop-recording-button.disabled:hover{background:#ccc}.progress-container{display:flex;justify-content:space-between;align-items:center;width:100%;max-width:400px;margin-top:10px;padding:0 5px}.progress-bar-container{height:4px;background-color:#E5E5E5;border-radius:2px;overflow:hidden;margin-right:10px;width:75px}.progress-bar{height:100%;background-image:linear-gradient(111deg, #4A9FFF 0%, #1058FF 100%);border-radius:2px;transition:width 0.3s ease}.progress-text{font-size:14px;color:#666;white-space:nowrap}";
|
|
5
|
-
|
|
6
|
-
const VideoChatModal = class {
|
|
7
|
-
constructor(hostRef) {
|
|
8
|
-
registerInstance(this, hostRef);
|
|
9
|
-
this.modalClosed = createEvent(this, "modalClosed");
|
|
10
|
-
this.streamComplete = createEvent(this, "streamComplete");
|
|
11
|
-
this.interviewComplete = createEvent(this, "interviewComplete");
|
|
12
|
-
this.recordingError = createEvent(this, "recordingError");
|
|
13
|
-
this.recordingStatusChange = createEvent(this, "recordingStatusChange");
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* 模态框标题
|
|
17
|
-
*/
|
|
18
|
-
modalTitle = '在线客服';
|
|
19
|
-
/**
|
|
20
|
-
* API鉴权密钥
|
|
21
|
-
*/
|
|
22
|
-
apiKey = '';
|
|
23
|
-
/**
|
|
24
|
-
* 是否显示聊天模态框
|
|
25
|
-
*/
|
|
26
|
-
isOpen = false;
|
|
27
|
-
/**
|
|
28
|
-
* 聊天消息历史
|
|
29
|
-
*/
|
|
30
|
-
messages = [];
|
|
31
|
-
/**
|
|
32
|
-
* 当点击模态框关闭时触发
|
|
33
|
-
*/
|
|
34
|
-
modalClosed;
|
|
35
|
-
/**
|
|
36
|
-
* 应用图标URL
|
|
37
|
-
*/
|
|
38
|
-
icon;
|
|
39
|
-
/**
|
|
40
|
-
* 聊天框的页面层级
|
|
41
|
-
*/
|
|
42
|
-
zIndex = 1000;
|
|
43
|
-
/**
|
|
44
|
-
* 是否展示顶部标题栏
|
|
45
|
-
*/
|
|
46
|
-
isShowHeader = true;
|
|
47
|
-
/**
|
|
48
|
-
* 是否展示右上角的关闭按钮
|
|
49
|
-
*/
|
|
50
|
-
isNeedClose = true;
|
|
51
|
-
/**
|
|
52
|
-
* 会话ID
|
|
53
|
-
*/
|
|
54
|
-
conversationId;
|
|
55
|
-
/**
|
|
56
|
-
* 当前助手回复的消息
|
|
57
|
-
*/
|
|
58
|
-
currentAssistantMessage = '';
|
|
59
|
-
/**
|
|
60
|
-
* 是否正在加载回复
|
|
61
|
-
*/
|
|
62
|
-
isLoading = false;
|
|
63
|
-
/**
|
|
64
|
-
* 当前正在流式输出的消息
|
|
65
|
-
*/
|
|
66
|
-
currentStreamingMessage = null;
|
|
67
|
-
// 添加新的状态控制
|
|
68
|
-
shouldAutoScroll = true;
|
|
69
|
-
isLoadingHistory = false;
|
|
70
|
-
get hostElement() { return getElement(this); }
|
|
71
|
-
// 添加新的 Event
|
|
72
|
-
streamComplete;
|
|
73
|
-
/**
|
|
74
|
-
* 默认查询文本
|
|
75
|
-
*/
|
|
76
|
-
defaultQuery = '';
|
|
77
|
-
// 添加新的状态
|
|
78
|
-
showInitialUpload = true;
|
|
79
|
-
// 添加视频录制相关状态
|
|
80
|
-
isRecording = false;
|
|
81
|
-
recordingStream = null;
|
|
82
|
-
recordedBlob = null;
|
|
83
|
-
mediaRecorder = null;
|
|
84
|
-
recordingTimeLeft = 0;
|
|
85
|
-
showRecordingUI = false;
|
|
86
|
-
recordingTimer = null;
|
|
87
|
-
recordingStartTime = 0;
|
|
88
|
-
recordingMaxTime = 120; // 最大录制时间(秒)
|
|
89
|
-
waitingToRecord = false;
|
|
90
|
-
waitingTimer = null;
|
|
91
|
-
waitingTimeLeft = 10; // 等待时间(秒)
|
|
92
|
-
// 添加一个新的私有属性来存储视频元素的引用
|
|
93
|
-
videoRef = null;
|
|
94
|
-
/**
|
|
95
|
-
* 总题目数量
|
|
96
|
-
*/
|
|
97
|
-
totalQuestions = 2;
|
|
98
|
-
/**
|
|
99
|
-
* 当前题目序号
|
|
100
|
-
*/
|
|
101
|
-
currentQuestionNumber = 0;
|
|
102
|
-
/**
|
|
103
|
-
* 面试是否已完成
|
|
104
|
-
*/
|
|
105
|
-
isInterviewComplete = false;
|
|
106
|
-
/**
|
|
107
|
-
* 当面试完成时触发
|
|
108
|
-
*/
|
|
109
|
-
interviewComplete;
|
|
110
|
-
SCROLL_THRESHOLD = 30;
|
|
111
|
-
/**
|
|
112
|
-
* 视频录制最大时长(秒)
|
|
113
|
-
*/
|
|
114
|
-
maxRecordingTime = 120;
|
|
115
|
-
/**
|
|
116
|
-
* 录制倒计时提醒时间(秒)
|
|
117
|
-
* 当剩余时间小于此值时,显示倒计时警告
|
|
118
|
-
*/
|
|
119
|
-
countdownWarningTime = 30;
|
|
120
|
-
showCountdownWarning = false;
|
|
121
|
-
/**
|
|
122
|
-
* 是否以全屏模式打开
|
|
123
|
-
*/
|
|
124
|
-
fullscreen = false;
|
|
125
|
-
// 添加新的状态来跟踪视频上传
|
|
126
|
-
isUploadingVideo = false;
|
|
127
|
-
// 添加新的状态和属性
|
|
128
|
-
isPlayingAudio = false;
|
|
129
|
-
audioUrl = null;
|
|
130
|
-
audioElement = null;
|
|
131
|
-
/**
|
|
132
|
-
* 录制错误事件
|
|
133
|
-
*/
|
|
134
|
-
recordingError;
|
|
135
|
-
/**
|
|
136
|
-
* 录制状态变化事件
|
|
137
|
-
*/
|
|
138
|
-
recordingStatusChange;
|
|
139
|
-
/**
|
|
140
|
-
* 是否自动播放语音问题
|
|
141
|
-
*/
|
|
142
|
-
enableVoice = true;
|
|
143
|
-
/**
|
|
144
|
-
* 是否显示题干内容
|
|
145
|
-
* 1: 显示题干内容
|
|
146
|
-
* 0: 不显示题干内容
|
|
147
|
-
*/
|
|
148
|
-
displayContentStatus = "1";
|
|
149
|
-
/**
|
|
150
|
-
* 父组件传入的 简历id
|
|
151
|
-
*/
|
|
152
|
-
resumeId;
|
|
153
|
-
handleClose = () => {
|
|
154
|
-
this.stopRecording();
|
|
155
|
-
this.modalClosed.emit();
|
|
156
|
-
};
|
|
157
|
-
async sendMessageToAPI(message, videoUrl) {
|
|
158
|
-
this.isLoading = true;
|
|
159
|
-
let answer = '';
|
|
160
|
-
let llmText = '';
|
|
161
|
-
const now = new Date();
|
|
162
|
-
const time = `${now.getHours()}:${now.getMinutes().toString().padStart(2, '0')}`;
|
|
163
|
-
// 如果消息为空但有文件,使用默认文本
|
|
164
|
-
const queryText = message.trim();
|
|
165
|
-
// 检查是否是最后一题的"下一题"请求
|
|
166
|
-
const isLastQuestion = this.currentQuestionNumber >= this.totalQuestions;
|
|
167
|
-
// 创建新的消息对象
|
|
168
|
-
const newMessage = {
|
|
169
|
-
id: `temp-${Date.now()}`,
|
|
170
|
-
time: time,
|
|
171
|
-
query: queryText,
|
|
172
|
-
answer: '',
|
|
173
|
-
isStreaming: true,
|
|
174
|
-
conversation_id: this.conversationId,
|
|
175
|
-
inputs: {},
|
|
176
|
-
status: "normal",
|
|
177
|
-
error: null
|
|
178
|
-
};
|
|
179
|
-
// 设置当前流式消息
|
|
180
|
-
this.currentStreamingMessage = newMessage;
|
|
181
|
-
this.shouldAutoScroll = true;
|
|
182
|
-
// 滚动到底部
|
|
183
|
-
this.scrollToBottom();
|
|
184
|
-
// 如果是最后一题,直接显示结束消息并完成面试
|
|
185
|
-
if (isLastQuestion) {
|
|
186
|
-
this.messages = [...this.messages, newMessage];
|
|
187
|
-
this.currentStreamingMessage = null;
|
|
188
|
-
this.isLoading = false;
|
|
189
|
-
this.isInterviewComplete = true;
|
|
190
|
-
await this.completeInterview(queryText, videoUrl);
|
|
191
|
-
this.interviewComplete.emit({
|
|
192
|
-
conversation_id: this.conversationId,
|
|
193
|
-
total_questions: this.totalQuestions
|
|
194
|
-
});
|
|
195
|
-
this.currentQuestionNumber++;
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
// 准备请求数据
|
|
199
|
-
const requestData = {
|
|
200
|
-
response_mode: 'streaming',
|
|
201
|
-
conversation_id: this.conversationId,
|
|
202
|
-
query: queryText,
|
|
203
|
-
inputs: {
|
|
204
|
-
id: this.resumeId
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
// 如果有视频URL,添加到inputs中
|
|
208
|
-
if (videoUrl) {
|
|
209
|
-
requestData.inputs.video_url = videoUrl;
|
|
210
|
-
}
|
|
211
|
-
await sendSSERequest({
|
|
212
|
-
url: `https://pcm_api.ylzhaopin.com/external/v1/chat/chat-messages`,
|
|
213
|
-
method: 'POST',
|
|
214
|
-
headers: {
|
|
215
|
-
'authorization': 'Bearer ' + this.apiKey
|
|
216
|
-
},
|
|
217
|
-
data: requestData,
|
|
218
|
-
onMessage: (data) => {
|
|
219
|
-
console.log('收到Stream数据:', data);
|
|
220
|
-
if (data.conversation_id && !this.conversationId) {
|
|
221
|
-
this.conversationId = data.conversation_id;
|
|
222
|
-
this.updateUrlWithConversationId(data.conversation_id);
|
|
223
|
-
}
|
|
224
|
-
// 检查是否有 node_finished 事件和 LLMText
|
|
225
|
-
if (data.event === 'node_finished' && data.data.inputs && data.data.inputs.LLMText) {
|
|
226
|
-
llmText = data.data.inputs.LLMText;
|
|
227
|
-
console.log('获取到 LLMText:', llmText);
|
|
228
|
-
}
|
|
229
|
-
if (data.event === 'message') {
|
|
230
|
-
if (data.event === 'agent_message' || data.event === 'message') {
|
|
231
|
-
if (data.answer) {
|
|
232
|
-
answer += data.answer;
|
|
233
|
-
const updatedMessage = {
|
|
234
|
-
...this.currentStreamingMessage,
|
|
235
|
-
answer,
|
|
236
|
-
isStreaming: true
|
|
237
|
-
};
|
|
238
|
-
this.currentStreamingMessage = updatedMessage;
|
|
239
|
-
this.scrollToBottom();
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
if (data.event === "message_end") {
|
|
244
|
-
this.streamComplete.emit({
|
|
245
|
-
conversation_id: data.conversation_id || '',
|
|
246
|
-
event: data.event,
|
|
247
|
-
message_id: data.message_id,
|
|
248
|
-
id: data.id,
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
onError: (error) => {
|
|
253
|
-
console.error('发生错误:', error);
|
|
254
|
-
alert(error instanceof Error ? error.message : '消息发送失败,请稍后再试');
|
|
255
|
-
this.messages = [...this.messages, {
|
|
256
|
-
...newMessage,
|
|
257
|
-
answer: '抱歉,发生了错误,请稍后再试。',
|
|
258
|
-
error: error,
|
|
259
|
-
isStreaming: false
|
|
260
|
-
}];
|
|
261
|
-
this.currentStreamingMessage = null;
|
|
262
|
-
this.isLoading = false;
|
|
263
|
-
},
|
|
264
|
-
onComplete: async () => {
|
|
265
|
-
console.log('请求完成');
|
|
266
|
-
this.isLoading = false;
|
|
267
|
-
// 获取最新的AI回复内容
|
|
268
|
-
const latestAIMessage = this.currentStreamingMessage;
|
|
269
|
-
// 更新消息列表
|
|
270
|
-
this.messages = [...this.messages, this.currentStreamingMessage];
|
|
271
|
-
this.currentStreamingMessage = null;
|
|
272
|
-
// 增加题目计数
|
|
273
|
-
this.currentQuestionNumber++;
|
|
274
|
-
if (latestAIMessage && latestAIMessage.answer) {
|
|
275
|
-
// 优先使用 LLMText,如果没有则使用 answer
|
|
276
|
-
const textForSynthesis = llmText || latestAIMessage.answer;
|
|
277
|
-
if (textForSynthesis) {
|
|
278
|
-
// 合成语音
|
|
279
|
-
const audioUrl = await this.synthesizeAudio(textForSynthesis);
|
|
280
|
-
if (this.enableVoice) {
|
|
281
|
-
// 自动播放语音
|
|
282
|
-
await this.playAudio(audioUrl);
|
|
283
|
-
// 自动播放模式下,播放完成后立即开始等待录制
|
|
284
|
-
this.startWaitingToRecord();
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
// 只保存音频URL,不自动播放
|
|
288
|
-
this.audioUrl = audioUrl;
|
|
289
|
-
// 非自动播放模式下,不立即开始等待录制
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
// 监听滚动事件,用于控制聊天历史记录的自动滚动行为。
|
|
297
|
-
handleScroll = () => {
|
|
298
|
-
const chatHistory = this.hostElement.shadowRoot?.querySelector('.chat-history');
|
|
299
|
-
if (!chatHistory)
|
|
300
|
-
return;
|
|
301
|
-
const { scrollTop, scrollHeight, clientHeight } = chatHistory;
|
|
302
|
-
const distanceFromBottom = scrollHeight - scrollTop - clientHeight;
|
|
303
|
-
// 更新是否应该自动滚动的状态
|
|
304
|
-
this.shouldAutoScroll = distanceFromBottom <= this.SCROLL_THRESHOLD;
|
|
305
|
-
};
|
|
306
|
-
scrollToBottom() {
|
|
307
|
-
if (!this.shouldAutoScroll)
|
|
308
|
-
return;
|
|
309
|
-
const chatHistory = this.hostElement.shadowRoot?.querySelector('.chat-history');
|
|
310
|
-
if (chatHistory && this.isOpen) {
|
|
311
|
-
// 强制浏览器重新计算布局
|
|
312
|
-
chatHistory.scrollTop = chatHistory.scrollHeight;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
// 添加 componentDidRender 生命周期方法,用于在组件渲染后滚动到底部
|
|
316
|
-
componentDidRender() {
|
|
317
|
-
if (this.isLoadingHistory || (this.shouldAutoScroll && this.isOpen)) {
|
|
318
|
-
const chatHistory = this.hostElement.shadowRoot?.querySelector('.chat-history');
|
|
319
|
-
if (chatHistory) {
|
|
320
|
-
chatHistory.scrollTop = chatHistory.scrollHeight;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
updateUrlWithConversationId(conversationId) {
|
|
325
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
326
|
-
if (!urlParams.get('conversation_id')) {
|
|
327
|
-
const newUrl = new URL(window.location.href);
|
|
328
|
-
newUrl.searchParams.set('conversation_id', conversationId);
|
|
329
|
-
window.history.replaceState({}, '', newUrl);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
// 修改 loadHistoryMessages 方法
|
|
333
|
-
async loadHistoryMessages() {
|
|
334
|
-
if (!this.conversationId)
|
|
335
|
-
return;
|
|
336
|
-
this.isLoadingHistory = true;
|
|
337
|
-
console.log('加载历史消息...');
|
|
338
|
-
try {
|
|
339
|
-
await sendHttpRequest({
|
|
340
|
-
url: `https://pcm_api.ylzhaopin.com/external/v1/chat/messages`,
|
|
341
|
-
method: 'GET',
|
|
342
|
-
headers: {
|
|
343
|
-
'authorization': 'Bearer ' + this.apiKey
|
|
344
|
-
},
|
|
345
|
-
data: {
|
|
346
|
-
conversation_id: this.conversationId,
|
|
347
|
-
limit: 20
|
|
348
|
-
},
|
|
349
|
-
onMessage: (data) => {
|
|
350
|
-
if (data.data) {
|
|
351
|
-
const historyData = data.data || [];
|
|
352
|
-
const formattedMessages = historyData.map(msg => {
|
|
353
|
-
const time = new Date(msg.created_at * 1000);
|
|
354
|
-
const hours = time.getHours().toString().padStart(2, '0');
|
|
355
|
-
const minutes = time.getMinutes().toString().padStart(2, '0');
|
|
356
|
-
const timeStr = `${hours}:${minutes}`;
|
|
357
|
-
// 创建新的消息对象,不包含 inputs 字段
|
|
358
|
-
const { inputs, ...msgWithoutInputs } = msg;
|
|
359
|
-
return {
|
|
360
|
-
...msgWithoutInputs,
|
|
361
|
-
time: timeStr,
|
|
362
|
-
isStreaming: false,
|
|
363
|
-
status: msg.status === 'error' ? 'error' : 'normal'
|
|
364
|
-
};
|
|
365
|
-
});
|
|
366
|
-
this.messages = formattedMessages;
|
|
367
|
-
this.isLoadingHistory = false;
|
|
368
|
-
requestAnimationFrame(() => {
|
|
369
|
-
this.shouldAutoScroll = true;
|
|
370
|
-
this.scrollToBottom();
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
this.isLoadingHistory = false;
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
onError: (error) => {
|
|
378
|
-
console.error('加载历史消息失败:', error);
|
|
379
|
-
alert(error instanceof Error ? error.message : '加载历史消息失败,请刷新重试');
|
|
380
|
-
this.isLoadingHistory = false;
|
|
381
|
-
},
|
|
382
|
-
onComplete: () => {
|
|
383
|
-
this.isLoadingHistory = false;
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
catch (error) {
|
|
388
|
-
console.error('加载历史消息失败:', error);
|
|
389
|
-
alert(error instanceof Error ? error.message : '加载历史消息失败,请刷新重试');
|
|
390
|
-
this.isLoadingHistory = false;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
// 修改 isOpen 的 watch 方法
|
|
394
|
-
async handleIsOpenChange(newValue) {
|
|
395
|
-
if (newValue) {
|
|
396
|
-
if (this.conversationId) {
|
|
397
|
-
await this.loadHistoryMessages();
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
// 直接开始对话
|
|
401
|
-
this.sendMessageToAPI('请您开始提问');
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
// 开始等待录制
|
|
406
|
-
startWaitingToRecord() {
|
|
407
|
-
// 清除可能存在的计时器
|
|
408
|
-
if (this.waitingTimer) {
|
|
409
|
-
clearInterval(this.waitingTimer);
|
|
410
|
-
}
|
|
411
|
-
if (this.recordingTimer) {
|
|
412
|
-
clearInterval(this.recordingTimer);
|
|
413
|
-
}
|
|
414
|
-
this.waitingToRecord = true;
|
|
415
|
-
this.waitingTimeLeft = 10;
|
|
416
|
-
this.waitingTimer = setInterval(() => {
|
|
417
|
-
this.waitingTimeLeft--;
|
|
418
|
-
if (this.waitingTimeLeft <= 0) {
|
|
419
|
-
clearInterval(this.waitingTimer);
|
|
420
|
-
this.waitingTimer = null;
|
|
421
|
-
this.waitingToRecord = false;
|
|
422
|
-
this.startRecording();
|
|
423
|
-
}
|
|
424
|
-
}, 1000);
|
|
425
|
-
}
|
|
426
|
-
// 开始录制视频
|
|
427
|
-
async startRecording() {
|
|
428
|
-
try {
|
|
429
|
-
const stream = await navigator.mediaDevices.getUserMedia({
|
|
430
|
-
audio: true,
|
|
431
|
-
video: {
|
|
432
|
-
width: { ideal: 1280 },
|
|
433
|
-
height: { ideal: 720 },
|
|
434
|
-
frameRate: { ideal: 30 }
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
this.recordingStream = stream;
|
|
438
|
-
this.showRecordingUI = true;
|
|
439
|
-
this.showCountdownWarning = false;
|
|
440
|
-
// 重置视频引用
|
|
441
|
-
this.videoRef = null;
|
|
442
|
-
// 确保视频元素获取到流
|
|
443
|
-
this.setupVideoPreview(stream);
|
|
444
|
-
// 检测浏览器支持的MIME类型
|
|
445
|
-
const mimeType = this.getSupportedMimeType();
|
|
446
|
-
// 创建MediaRecorder实例
|
|
447
|
-
let mediaRecorder;
|
|
448
|
-
try {
|
|
449
|
-
mediaRecorder = new MediaRecorder(stream, {
|
|
450
|
-
mimeType: mimeType
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
catch (e) {
|
|
454
|
-
// 如果指定MIME类型失败,尝试使用默认设置
|
|
455
|
-
console.warn('指定的MIME类型不受支持,使用默认设置:', e);
|
|
456
|
-
try {
|
|
457
|
-
mediaRecorder = new MediaRecorder(stream);
|
|
458
|
-
}
|
|
459
|
-
catch (recorderError) {
|
|
460
|
-
// 通知父组件录制器创建失败
|
|
461
|
-
this.recordingError.emit({
|
|
462
|
-
type: 'recorder_creation_failed',
|
|
463
|
-
message: '无法创建媒体录制器,您的浏览器可能不支持此功能',
|
|
464
|
-
details: recorderError
|
|
465
|
-
});
|
|
466
|
-
this.showRecordingUI = false;
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
this.mediaRecorder = mediaRecorder;
|
|
471
|
-
const chunks = [];
|
|
472
|
-
mediaRecorder.ondataavailable = (event) => {
|
|
473
|
-
if (event.data.size > 0) {
|
|
474
|
-
chunks.push(event.data);
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
mediaRecorder.onerror = (event) => {
|
|
478
|
-
// 通知父组件录制过程中发生错误
|
|
479
|
-
this.recordingError.emit({
|
|
480
|
-
type: 'recording_error',
|
|
481
|
-
message: '录制过程中发生错误',
|
|
482
|
-
details: event
|
|
483
|
-
});
|
|
484
|
-
this.stopRecording();
|
|
485
|
-
};
|
|
486
|
-
mediaRecorder.onstop = () => {
|
|
487
|
-
try {
|
|
488
|
-
// 根据实际使用的MIME类型创建Blob
|
|
489
|
-
const blobType = mimeType || 'video/mp4';
|
|
490
|
-
const blob = new Blob(chunks, { type: blobType });
|
|
491
|
-
if (blob.size === 0) {
|
|
492
|
-
// 通知父组件录制的视频为空
|
|
493
|
-
this.recordingError.emit({
|
|
494
|
-
type: 'empty_recording',
|
|
495
|
-
message: '录制的视频为空'
|
|
496
|
-
});
|
|
497
|
-
this.showRecordingUI = false;
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
this.recordedBlob = blob;
|
|
501
|
-
// 通知父组件录制已完成
|
|
502
|
-
this.recordingStatusChange.emit({
|
|
503
|
-
status: 'stopped',
|
|
504
|
-
details: {
|
|
505
|
-
duration: Math.floor((Date.now() - this.recordingStartTime) / 1000),
|
|
506
|
-
size: blob.size,
|
|
507
|
-
type: blob.type
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
this.uploadRecordedVideo();
|
|
511
|
-
}
|
|
512
|
-
catch (error) {
|
|
513
|
-
// 通知父组件处理录制视频时出错
|
|
514
|
-
this.recordingError.emit({
|
|
515
|
-
type: 'processing_error',
|
|
516
|
-
message: '处理录制视频时出错',
|
|
517
|
-
details: error
|
|
518
|
-
});
|
|
519
|
-
this.showRecordingUI = false;
|
|
520
|
-
}
|
|
521
|
-
};
|
|
522
|
-
// 开始录制
|
|
523
|
-
try {
|
|
524
|
-
mediaRecorder.start();
|
|
525
|
-
this.isRecording = true;
|
|
526
|
-
this.recordingStartTime = Date.now();
|
|
527
|
-
this.recordingTimeLeft = this.maxRecordingTime;
|
|
528
|
-
// 通知父组件录制已开始
|
|
529
|
-
this.recordingStatusChange.emit({
|
|
530
|
-
status: 'started',
|
|
531
|
-
details: {
|
|
532
|
-
maxDuration: this.maxRecordingTime,
|
|
533
|
-
mimeType: mediaRecorder.mimeType
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
catch (startError) {
|
|
538
|
-
// 通知父组件开始录制失败
|
|
539
|
-
this.recordingError.emit({
|
|
540
|
-
type: 'start_failed',
|
|
541
|
-
message: '开始录制失败,请检查您的设备权限',
|
|
542
|
-
details: startError
|
|
543
|
-
});
|
|
544
|
-
this.showRecordingUI = false;
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
// 设置录制计时器
|
|
548
|
-
this.recordingTimer = setInterval(() => {
|
|
549
|
-
const elapsedTime = Math.floor((Date.now() - this.recordingStartTime) / 1000);
|
|
550
|
-
this.recordingTimeLeft = Math.max(0, this.maxRecordingTime - elapsedTime);
|
|
551
|
-
// 检查是否需要显示倒计时警告
|
|
552
|
-
if (this.recordingTimeLeft <= this.countdownWarningTime && !this.showCountdownWarning) {
|
|
553
|
-
this.showCountdownWarning = true;
|
|
554
|
-
}
|
|
555
|
-
// 时间到自动停止录制
|
|
556
|
-
if (this.recordingTimeLeft <= 0) {
|
|
557
|
-
this.stopRecording();
|
|
558
|
-
}
|
|
559
|
-
}, 1000);
|
|
560
|
-
}
|
|
561
|
-
catch (error) {
|
|
562
|
-
console.error('无法访问摄像头或麦克风:', error);
|
|
563
|
-
// 通知父组件无法访问媒体设备
|
|
564
|
-
this.recordingError.emit({
|
|
565
|
-
type: 'media_access_failed',
|
|
566
|
-
message: '无法访问摄像头或麦克风,请确保已授予权限',
|
|
567
|
-
details: error
|
|
568
|
-
});
|
|
569
|
-
this.showRecordingUI = false;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
// 添加新方法来设置视频预览
|
|
573
|
-
setupVideoPreview(stream) {
|
|
574
|
-
// 延迟执行以确保DOM已更新
|
|
575
|
-
setTimeout(() => {
|
|
576
|
-
const videoElement = this.hostElement.shadowRoot?.querySelector('video');
|
|
577
|
-
if (videoElement && stream) {
|
|
578
|
-
// 先尝试使用标准方法
|
|
579
|
-
try {
|
|
580
|
-
videoElement.srcObject = stream;
|
|
581
|
-
videoElement.play().catch(err => {
|
|
582
|
-
console.error('视频播放失败:', err);
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
catch (e) {
|
|
586
|
-
console.warn('设置srcObject失败,尝试替代方法:', e);
|
|
587
|
-
// 对于不支持srcObject的旧浏览器,使用URL.createObjectURL
|
|
588
|
-
try {
|
|
589
|
-
// 使用类型断言解决TypeScript错误
|
|
590
|
-
const objectUrl = URL.createObjectURL(stream);
|
|
591
|
-
videoElement.src = objectUrl;
|
|
592
|
-
// 确保在视频元素不再使用时释放URL
|
|
593
|
-
videoElement.onended = () => {
|
|
594
|
-
URL.revokeObjectURL(objectUrl);
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
catch (urlError) {
|
|
598
|
-
console.error('创建对象URL失败:', urlError);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
else {
|
|
603
|
-
console.warn('未找到视频元素或媒体流无效');
|
|
604
|
-
}
|
|
605
|
-
}, 100);
|
|
606
|
-
}
|
|
607
|
-
// 添加一个新方法来检测浏览器支持的MIME类型
|
|
608
|
-
getSupportedMimeType() {
|
|
609
|
-
// 按优先级排列的MIME类型列表
|
|
610
|
-
const mimeTypes = [
|
|
611
|
-
'video/webm;codecs=vp8,opus',
|
|
612
|
-
'video/webm;codecs=vp9,opus',
|
|
613
|
-
'video/webm',
|
|
614
|
-
'video/mp4',
|
|
615
|
-
'video/mp4;codecs=h264,aac',
|
|
616
|
-
'' // 空字符串表示使用浏览器默认值
|
|
617
|
-
];
|
|
618
|
-
// 检查MediaRecorder是否可用
|
|
619
|
-
if (!window.MediaRecorder) {
|
|
620
|
-
console.warn('MediaRecorder API不可用');
|
|
621
|
-
return '';
|
|
622
|
-
}
|
|
623
|
-
// 检查每种MIME类型是否受支持
|
|
624
|
-
for (const type of mimeTypes) {
|
|
625
|
-
if (!type)
|
|
626
|
-
return ''; // 如果是空字符串,直接返回
|
|
627
|
-
try {
|
|
628
|
-
if (MediaRecorder.isTypeSupported(type)) {
|
|
629
|
-
console.log('使用支持的MIME类型:', type);
|
|
630
|
-
return type;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
catch (e) {
|
|
634
|
-
console.warn(`检查MIME类型支持时出错 ${type}:`, e);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
// 如果没有找到支持的类型,返回空字符串
|
|
638
|
-
console.warn('没有找到支持的MIME类型,将使用浏览器默认值');
|
|
639
|
-
return '';
|
|
640
|
-
}
|
|
641
|
-
// 停止录制
|
|
642
|
-
stopRecording() {
|
|
643
|
-
if (this.mediaRecorder && this.isRecording) {
|
|
644
|
-
this.mediaRecorder.stop();
|
|
645
|
-
this.isRecording = false;
|
|
646
|
-
// 清理计时器
|
|
647
|
-
if (this.recordingTimer) {
|
|
648
|
-
clearInterval(this.recordingTimer);
|
|
649
|
-
this.recordingTimer = null;
|
|
650
|
-
}
|
|
651
|
-
// 停止并释放媒体流
|
|
652
|
-
if (this.recordingStream) {
|
|
653
|
-
this.recordingStream.getTracks().forEach(track => track.stop());
|
|
654
|
-
this.recordingStream = null;
|
|
655
|
-
}
|
|
656
|
-
// 清理视频引用
|
|
657
|
-
this.videoRef = null;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
// 上传录制的视频
|
|
661
|
-
async uploadRecordedVideo() {
|
|
662
|
-
if (!this.recordedBlob)
|
|
663
|
-
return;
|
|
664
|
-
try {
|
|
665
|
-
this.isUploadingVideo = true; // 开始上传时设置状态
|
|
666
|
-
this.showRecordingUI = false; // 隐藏视频预览
|
|
667
|
-
// 根据Blob类型确定文件扩展名
|
|
668
|
-
const fileExtension = this.recordedBlob.type.includes('webm') ? 'webm' : 'mp4';
|
|
669
|
-
const fileName = `answer.${fileExtension}`;
|
|
670
|
-
const formData = new FormData();
|
|
671
|
-
formData.append('file', this.recordedBlob, fileName);
|
|
672
|
-
const response = await fetch('https://pcm_api.ylzhaopin.com/external/v1/files/upload', {
|
|
673
|
-
method: 'POST',
|
|
674
|
-
headers: {
|
|
675
|
-
'authorization': 'Bearer ' + this.apiKey
|
|
676
|
-
},
|
|
677
|
-
body: formData
|
|
678
|
-
});
|
|
679
|
-
const result = await response.json();
|
|
680
|
-
console.log('视频上传结果:', result);
|
|
681
|
-
if (result && result.cos_key) {
|
|
682
|
-
// 调用音频转文字API
|
|
683
|
-
const transcriptionText = await this.convertAudioToText(result.cos_key);
|
|
684
|
-
// 发送转换后的文本和视频URL到下一个请求
|
|
685
|
-
await this.sendMessageToAPI(transcriptionText || "下一题", result.cos_key);
|
|
686
|
-
}
|
|
687
|
-
else {
|
|
688
|
-
throw new Error('视频上传失败');
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
catch (error) {
|
|
692
|
-
console.error('视频上传或处理错误:', error);
|
|
693
|
-
this.recordingError.emit({
|
|
694
|
-
type: 'upload_failed',
|
|
695
|
-
message: '视频上传或处理失败',
|
|
696
|
-
details: error
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
finally {
|
|
700
|
-
this.isUploadingVideo = false; // 上传完成后重置状态
|
|
701
|
-
this.showRecordingUI = false;
|
|
702
|
-
this.recordedBlob = null;
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
// 修改音频转文字方法
|
|
706
|
-
async convertAudioToText(cosKey) {
|
|
707
|
-
try {
|
|
708
|
-
// 创建一个Promise来处理响应
|
|
709
|
-
return new Promise((resolve, reject) => {
|
|
710
|
-
sendHttpRequest({
|
|
711
|
-
url: `https://pcm_api.ylzhaopin.com/external/v1/tts/audio_to_text`,
|
|
712
|
-
method: 'POST',
|
|
713
|
-
headers: {
|
|
714
|
-
'Content-Type': 'application/json',
|
|
715
|
-
'authorization': 'Bearer ' + this.apiKey
|
|
716
|
-
},
|
|
717
|
-
data: {
|
|
718
|
-
cos_key: cosKey
|
|
719
|
-
},
|
|
720
|
-
onMessage: (data) => {
|
|
721
|
-
// 检查返回结果中是否包含转换后的文本
|
|
722
|
-
if (data && data.text) {
|
|
723
|
-
console.log('转换后的文本:', data.text);
|
|
724
|
-
resolve(data.text);
|
|
725
|
-
}
|
|
726
|
-
else {
|
|
727
|
-
console.warn('音频转文字返回结果格式不正确');
|
|
728
|
-
resolve(null);
|
|
729
|
-
}
|
|
730
|
-
},
|
|
731
|
-
onError: (error) => {
|
|
732
|
-
console.error('音频转文字请求失败:', error);
|
|
733
|
-
reject(error);
|
|
734
|
-
}
|
|
735
|
-
});
|
|
736
|
-
});
|
|
737
|
-
}
|
|
738
|
-
catch (error) {
|
|
739
|
-
console.error('音频转文字错误:', error);
|
|
740
|
-
return null;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* 发送面试完成请求
|
|
745
|
-
*/
|
|
746
|
-
async completeInterview(queryText, videoUrl) {
|
|
747
|
-
if (!this.conversationId)
|
|
748
|
-
return;
|
|
749
|
-
const requestData = {
|
|
750
|
-
response_mode: 'streaming',
|
|
751
|
-
conversation_id: this.conversationId,
|
|
752
|
-
query: queryText,
|
|
753
|
-
inputs: {
|
|
754
|
-
id: this.resumeId
|
|
755
|
-
}
|
|
756
|
-
};
|
|
757
|
-
// 如果有视频URL,添加到inputs中
|
|
758
|
-
if (videoUrl) {
|
|
759
|
-
requestData.inputs.video_url = videoUrl;
|
|
760
|
-
}
|
|
761
|
-
// 不使用 await,直接发送请求
|
|
762
|
-
sendSSERequest({
|
|
763
|
-
url: `https://pcm_api.ylzhaopin.com/external/v1/chat/chat-messages`,
|
|
764
|
-
method: 'POST',
|
|
765
|
-
headers: {
|
|
766
|
-
'authorization': 'Bearer ' + this.apiKey
|
|
767
|
-
},
|
|
768
|
-
data: requestData,
|
|
769
|
-
}).catch(error => {
|
|
770
|
-
console.error('发送面试完成请求失败:', error);
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
// 添加TTS合成音频的方法
|
|
774
|
-
async synthesizeAudio(text) {
|
|
775
|
-
try {
|
|
776
|
-
const response = await fetch('https://pcm_api.ylzhaopin.com/external/v1/tts/synthesize_audio', {
|
|
777
|
-
method: 'POST',
|
|
778
|
-
headers: {
|
|
779
|
-
'Content-Type': 'application/json',
|
|
780
|
-
'authorization': 'Bearer ' + this.apiKey
|
|
781
|
-
},
|
|
782
|
-
body: JSON.stringify({ text })
|
|
783
|
-
});
|
|
784
|
-
if (!response.ok) {
|
|
785
|
-
throw new Error('语音合成失败');
|
|
786
|
-
}
|
|
787
|
-
// 获取音频数据并创建Blob URL
|
|
788
|
-
const audioBlob = await response.blob();
|
|
789
|
-
return URL.createObjectURL(audioBlob);
|
|
790
|
-
}
|
|
791
|
-
catch (error) {
|
|
792
|
-
console.error('语音合成错误:', error);
|
|
793
|
-
throw error;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
// 播放音频的方法
|
|
797
|
-
playAudio(audioUrl) {
|
|
798
|
-
return new Promise((resolve) => {
|
|
799
|
-
this.isPlayingAudio = true;
|
|
800
|
-
this.audioUrl = audioUrl;
|
|
801
|
-
// 创建音频元素
|
|
802
|
-
if (!this.audioElement) {
|
|
803
|
-
this.audioElement = new Audio();
|
|
804
|
-
}
|
|
805
|
-
this.audioElement.src = audioUrl;
|
|
806
|
-
this.audioElement.onended = () => {
|
|
807
|
-
this.isPlayingAudio = false;
|
|
808
|
-
this.audioUrl = null;
|
|
809
|
-
resolve();
|
|
810
|
-
};
|
|
811
|
-
this.audioElement.onerror = () => {
|
|
812
|
-
console.error('音频播放错误');
|
|
813
|
-
this.isPlayingAudio = false;
|
|
814
|
-
this.audioUrl = null;
|
|
815
|
-
resolve();
|
|
816
|
-
};
|
|
817
|
-
this.audioElement.play().catch(error => {
|
|
818
|
-
console.error('音频播放失败:', error);
|
|
819
|
-
this.isPlayingAudio = false;
|
|
820
|
-
this.audioUrl = null;
|
|
821
|
-
resolve();
|
|
822
|
-
});
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
|
-
// 修改 componentDidLoad 生命周期方法,确保组件卸载时释放资源
|
|
826
|
-
disconnectedCallback() {
|
|
827
|
-
// 释放音频资源
|
|
828
|
-
if (this.audioElement) {
|
|
829
|
-
this.audioElement.pause();
|
|
830
|
-
this.audioElement.src = '';
|
|
831
|
-
this.audioElement = null;
|
|
832
|
-
}
|
|
833
|
-
// 释放 Blob URL
|
|
834
|
-
if (this.audioUrl) {
|
|
835
|
-
URL.revokeObjectURL(this.audioUrl);
|
|
836
|
-
this.audioUrl = null;
|
|
837
|
-
}
|
|
838
|
-
// 清理其他计时器
|
|
839
|
-
if (this.waitingTimer) {
|
|
840
|
-
clearInterval(this.waitingTimer);
|
|
841
|
-
this.waitingTimer = null;
|
|
842
|
-
}
|
|
843
|
-
if (this.recordingTimer) {
|
|
844
|
-
clearInterval(this.recordingTimer);
|
|
845
|
-
this.recordingTimer = null;
|
|
846
|
-
}
|
|
847
|
-
// 停止录制
|
|
848
|
-
this.stopRecording();
|
|
849
|
-
}
|
|
850
|
-
// 修改手动播放音频的方法
|
|
851
|
-
handlePlayAudio = async () => {
|
|
852
|
-
if (this.audioUrl) {
|
|
853
|
-
await this.playAudio(this.audioUrl);
|
|
854
|
-
// 手动播放完成后开始等待录制
|
|
855
|
-
this.startWaitingToRecord();
|
|
856
|
-
}
|
|
857
|
-
};
|
|
858
|
-
render() {
|
|
859
|
-
if (!this.isOpen)
|
|
860
|
-
return null;
|
|
861
|
-
const modalStyle = {
|
|
862
|
-
zIndex: String(this.zIndex)
|
|
863
|
-
};
|
|
864
|
-
const containerClass = {
|
|
865
|
-
'modal-container': true,
|
|
866
|
-
'fullscreen': this.fullscreen
|
|
867
|
-
};
|
|
868
|
-
const overlayClass = {
|
|
869
|
-
'modal-overlay': true,
|
|
870
|
-
'fullscreen-overlay': this.fullscreen
|
|
871
|
-
};
|
|
872
|
-
const renderVideoPreview = () => (h("div", { class: "video-preview" }, h("video", { autoPlay: true, playsInline: true, muted: true, style: { transform: 'scaleX(-1)' }, ref: (el) => {
|
|
873
|
-
if (el && this.recordingStream && !this.videoRef) {
|
|
874
|
-
this.videoRef = el;
|
|
875
|
-
// 不在这里设置srcObject,而是使用setupVideoPreview方法
|
|
876
|
-
}
|
|
877
|
-
} }), h("div", { class: {
|
|
878
|
-
'recording-status': true,
|
|
879
|
-
'warning': this.showCountdownWarning
|
|
880
|
-
} }, h("span", { class: "recording-dot" }), h("span", null, "\u5F55\u5236\u4E2D ", Math.floor(this.recordingTimeLeft / 60), ":", (this.recordingTimeLeft % 60).toString().padStart(2, '0'), this.showCountdownWarning && ` (即将自动完成)`))));
|
|
881
|
-
// 渲染占位符状态信息
|
|
882
|
-
const renderPlaceholderStatus = () => {
|
|
883
|
-
// 正在播放音频
|
|
884
|
-
if (this.isPlayingAudio) {
|
|
885
|
-
return (h("div", { class: "placeholder-status" }, h("p", null, "\u6B63\u5728\u64AD\u653E\u95EE\u9898\uFF0C\u8BF7\u542C\u5B8C\u540E\u51C6\u5907\u56DE\u7B54...")));
|
|
886
|
-
}
|
|
887
|
-
// 正在上传视频
|
|
888
|
-
if (this.isUploadingVideo) {
|
|
889
|
-
return (h("div", { class: "placeholder-status" }, h("p", null, "\u6B63\u5728\u4E0A\u4F20\u89C6\u9891\uFF0C\u8BF7\u7A0D\u5019...")));
|
|
890
|
-
}
|
|
891
|
-
// 正在加载或等待AI回复
|
|
892
|
-
if (this.isLoading || this.currentStreamingMessage) {
|
|
893
|
-
return (h("div", { class: "placeholder-status" }, h("p", null, "\u8BF7\u7B49\u5F85\u9898\u76EE...")));
|
|
894
|
-
}
|
|
895
|
-
// 等待开始录制
|
|
896
|
-
if (this.waitingToRecord) {
|
|
897
|
-
return (h("div", { class: "placeholder-status" }, h("p", null, "\u8BF7\u51C6\u5907\u597D\uFF0C", this.waitingTimeLeft, "\u79D2\u540E\u5C06\u5F00\u59CB\u5F55\u5236\u60A8\u7684\u56DE\u7B54...")));
|
|
898
|
-
}
|
|
899
|
-
// 添加默认状态
|
|
900
|
-
return (h("div", { class: "placeholder-status default-status" }, h("p", null, "\u51C6\u5907\u4E2D...")));
|
|
901
|
-
};
|
|
902
|
-
return (h("div", { class: overlayClass, style: modalStyle }, h("div", { class: containerClass }, this.isShowHeader && (h("div", { class: "modal-header" }, h("div", { class: "header-left" }, this.icon && h("img", { src: this.icon, class: "header-icon", alt: "\u5E94\u7528\u56FE\u6807" }), h("div", null, this.modalTitle)), this.isNeedClose && (h("button", { class: "close-button", onClick: this.handleClose }, h("span", null, "\u00D7"))))), h("div", { style: { height: '100%' } }, h("div", { class: "chat-history", onScroll: this.handleScroll }, this.isLoadingHistory ? (h("div", { class: "loading-container" }, h("div", { class: "loading-spinner" }), h("p", null, "\u52A0\u8F7D\u5386\u53F2\u6D88\u606F\u4E2D..."))) : (h("div", null, this.messages.map((message) => (h("div", { id: `message_${message.id}`, key: message.id }, h("pcm-chat-message", { message: message, onMessageChange: (event) => {
|
|
903
|
-
const updatedMessages = this.messages.map(msg => msg.id === message.id ? { ...msg, ...event.detail } : msg);
|
|
904
|
-
this.messages = updatedMessages;
|
|
905
|
-
} })))), this.currentStreamingMessage && (h("div", { id: `message_${this.currentStreamingMessage.id}` }, h("pcm-chat-message", { message: this.currentStreamingMessage })))))), h("div", { class: "recording-section" }, h("div", { class: "recording-container" }, h("div", { class: "video-area" }, this.showRecordingUI ? (renderVideoPreview()) : (h("div", { class: "video-preview placeholder" }, renderPlaceholderStatus()))), h("div", { class: "progress-container" }, h("div", { class: "progress-bar-container" }, h("div", { class: "progress-bar", style: {
|
|
906
|
-
width: `${Math.max(0, this.currentQuestionNumber - 1) / this.totalQuestions * 100}%`
|
|
907
|
-
} })), h("div", { class: "progress-text" }, "\u5DF2\u5B8C\u6210", Math.max(0, this.currentQuestionNumber - 1), "/", this.totalQuestions)), h("div", { class: "recording-controls" }, this.showRecordingUI ? (h("button", { class: "stop-recording-button", onClick: () => this.stopRecording() }, "\u5B8C\u6210\u672C\u9898\u56DE\u7B54")) : (h("div", { class: "waiting-message" }, (() => {
|
|
908
|
-
// 显示播放按钮(当不自动播放且有音频URL时)
|
|
909
|
-
if (!this.enableVoice && this.audioUrl && !this.isPlayingAudio) {
|
|
910
|
-
return (h("div", { class: "play-audio-container", onClick: this.handlePlayAudio }, h("p", null, h("svg", { viewBox: "0 0 24 24", width: "24", height: "24", fill: "currentColor", style: { verticalAlign: 'middle', marginRight: '8px' } }, h("path", { d: "M8 5v14l11-7z" })), h("span", { style: { verticalAlign: 'middle' } }, "\u64AD\u653E\u9898\u76EE"))));
|
|
911
|
-
}
|
|
912
|
-
// 其他状态下显示禁用的"完成回答"按钮
|
|
913
|
-
return (h("button", { class: "stop-recording-button disabled", disabled: true }, "\u5B8C\u6210\u56DE\u7B54"));
|
|
914
|
-
})())))))))));
|
|
915
|
-
}
|
|
916
|
-
static get watchers() { return {
|
|
917
|
-
"isOpen": ["handleIsOpenChange"]
|
|
918
|
-
}; }
|
|
919
|
-
};
|
|
920
|
-
VideoChatModal.style = pcmVideoChatModalCss;
|
|
921
|
-
|
|
922
|
-
export { VideoChatModal as pcm_video_chat_modal };
|
|
923
|
-
//# sourceMappingURL=pcm-video-chat-modal.entry.js.map
|
|
924
|
-
|
|
925
|
-
//# sourceMappingURL=pcm-video-chat-modal.entry.js.map
|