Files
vueapp/dist/assets/session.Cc2HEzjU.js
T
2026-06-09 17:00:23 +08:00

2 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{C as e,s as t}from"./index-CpNRQgjE.js";const n="/fastapi/api/v1";function s(){const t=e("clinical-thinking-access-token");if("string"!=typeof t||!t.trim())throw new Error("登录已过期,请重新登录");return t}function o(e="application/json"){return{"Content-Type":"application/json",Accept:e,Authorization:`Bearer ${s()}`,"X-Entry-Scene":"vue_frontend"}}async function a(e){const t=await e.text().catch((()=>""));if(!t)return`请求失败(${e.status}`;try{const e=JSON.parse(t),n=e.message||e.detail||e.error;if("string"==typeof n&&n.trim())return n}catch{}return t}function r(){const t=e("clinical-thinking-scenario");return t&&"object"==typeof t?t:null}function i(){var e,t;const n=null==(t=null==(e=r())?void 0:e.session)?void 0:t.session_id;if("number"==typeof n&&Number.isInteger(n)&&n>0)return n;throw new Error("未找到当前会话,请先生成模拟场景")}function c(e){const n=r();(null==n?void 0:n.session)&&t("clinical-thinking-scenario",{...n,session:{...n.session,status:e}})}async function f(e){var t;const n=await fetch("/fastapi/api/v1/sessions",{method:"POST",headers:o(),body:JSON.stringify(e)});if(!n.ok)throw new Error(await a(n));const s=await n.json();if("OK"!==s.code||!(null==(t=s.data)?void 0:t.session_id))throw new Error(s.message||"新建会话失败");return s.data}async function d(e){var t;const n=await fetch(`/fastapi/api/v1/sessions/${e}/complete-inquiry`,{method:"POST",headers:o()});if(!n.ok)throw new Error(await a(n));const s=await n.json();if("OK"!==s.code||!(null==(t=s.data)?void 0:t.session_id))throw new Error(s.message||"完成采集失败");return s.data}async function l(e,t,n,s){var r,i,c;const f=await fetch(`/fastapi/api/v1/sessions/${e}/chat/stream`,{method:"POST",headers:o("text/event-stream"),body:JSON.stringify({message:t}),signal:s});if(!f.ok||!f.body)throw new Error(await a(f));const d=f.body.getReader(),l=new TextDecoder;let u="",w=!1;for(;;){const{value:e,done:t}=await d.read();if(t)break;u+=l.decode(e,{stream:!0});const s=u.split("\n\n");u=s.pop()||"";for(const o of s){const e=null==(r=o.match(/^event:\s*(.+)$/m))?void 0:r[1],t=null==(i=o.match(/^data:\s*(.+)$/m))?void 0:i[1];if(!e||!t)continue;const s=JSON.parse(t);if("message_delta"===e){const e=s.delta;"string"==typeof e&&n.onDelta(e)}else if("message_done"===e)w=!0,null==(c=n.onDone)||c.call(n,s);else if("error"===e)throw new Error("string"==typeof s.message?s.message:"AI 流式回复异常")}}if(!w)throw new Error("AI 流式回复未正常结束,请重试")}async function u(e,t,n,s){var r,i,c;const f={last_user_message:t,scope:"current_conversation"},d=await fetch(`/fastapi/api/v1/sessions/${e}/hints/stream`,{method:"POST",headers:o("text/event-stream"),body:JSON.stringify(f),signal:s});if(!d.ok||!d.body)throw new Error(await a(d));const l=d.body.getReader(),u=new TextDecoder;let w="",h=!1;for(;;){const{value:e,done:t}=await l.read();if(t)break;w+=u.decode(e,{stream:!0});const s=w.split("\n\n");w=s.pop()||"";for(const o of s){const e=null==(r=o.match(/^event:\s*(.+)$/m))?void 0:r[1],t=null==(i=o.match(/^data:\s*(.+)$/m))?void 0:i[1];if(!e||!t)continue;const s=JSON.parse(t);if("hint_delta"===e){const e=s.delta;"string"==typeof e&&n.onDelta(e)}else if("hint_done"===e)h=!0,null==(c=n.onDone)||c.call(n,s);else if("error"===e)throw new Error("string"==typeof s.message?s.message:"练习提示生成失败,请稍后重试")}}if(!h)throw new Error("练习提示未正常结束,请重试")}export{n as F,o as a,r as b,f as c,d,u as e,i as f,a as r,l as s,c as u};