"use strict";
(self["webpackChunkDr_Sai"] = self["webpackChunkDr_Sai"] || []).push([[577],{

/***/ 39614:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   CG: function() { return /* binding */ teamAPI; },
/* harmony export */   Ml: function() { return /* binding */ agentWorkerAPI; },
/* harmony export */   R2: function() { return /* binding */ authAPI; },
/* harmony export */   YP: function() { return /* binding */ settingsAPI; },
/* harmony export */   a7: function() { return /* binding */ planAPI; },
/* harmony export */   cM: function() { return /* binding */ agentAPI; },
/* harmony export */   hq: function() { return /* binding */ SessionAPI; },
/* harmony export */   jT: function() { return /* binding */ sessionAPI; },
/* harmony export */   jp: function() { return /* binding */ fileAPI; },
/* harmony export */   og: function() { return /* binding */ PlanAPI; }
/* harmony export */ });
/* unused harmony exports TeamAPI, SettingsAPI, Agent, AgentWorkerAPI, FileAPI, AuthAPI */
/* harmony import */ var _babel_runtime_helpers_esm_objectWithoutPropertiesLoose__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(98587);
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(70870);
const _excluded=["created_at"],_excluded2=["created_at"];let SessionAPI=/*#__PURE__*/function(){function SessionAPI(){}var _proto=SessionAPI.prototype;_proto.getBaseUrl=function getBaseUrl(){return (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .getServerUrl */ .Tt)();};_proto.getHeaders=function getHeaders(){return{"Content-Type":"application/json"};};_proto.listSessions=async function listSessions(userId){const response=await fetch(this.getBaseUrl()+"/sessions/?user_id="+userId,{headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch sessions");return data.data;};_proto.getSession=async function getSession(sessionId,userId){const response=await fetch(this.getBaseUrl()+"/sessions/"+sessionId+"?user_id="+userId,{headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch session");return data.data;};_proto.createSession=async function createSession(sessionData,userId){const session=Object.assign({},sessionData,{user_id:userId// Ensure user_id is included
// Note: created_at is handled by server_default=func.now() in backend
});const response=await fetch(this.getBaseUrl()+"/sessions/",{method:"POST",headers:this.getHeaders(),body:JSON.stringify(session)});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to create session");return data.data;};_proto.updateSession=async function updateSession(sessionId,sessionData,userId){// Exclude created_at when updating, as it should be preserved
const dataWithoutCreatedAt=(0,_babel_runtime_helpers_esm_objectWithoutPropertiesLoose__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A)(sessionData,_excluded);const session=Object.assign({},dataWithoutCreatedAt,{id:sessionId,user_id:userId// Ensure user_id is included
// Note: updated_at is handled by onupdate=func.now() in backend
});const response=await fetch(this.getBaseUrl()+"/sessions/"+sessionId+"?user_id="+userId,{method:"PUT",headers:this.getHeaders(),body:JSON.stringify(session)});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to update session");return data.data;}// session runs with messages
;_proto.getSessionRuns=async function getSessionRuns(sessionId,userId){const response=await fetch(this.getBaseUrl()+"/sessions/"+sessionId+"/runs?user_id="+userId,{headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch session runs");return data.data;// Returns { runs: RunMessage[] }
};_proto.updateSessionRuns=async function updateSessionRuns(runId,runData){const response=await fetch(this.getBaseUrl()+"/runs/"+runId,{method:"PUT",headers:this.getHeaders(),body:JSON.stringify(runData)});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to update Runs");return data.data;};_proto.deleteSession=async function deleteSession(sessionId,userId){const response=await fetch(this.getBaseUrl()+"/sessions/"+sessionId+"?user_id="+userId,{method:"DELETE",headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to delete session");}// Adding messages endpoint
;_proto.listSessionMessages=async function listSessionMessages(sessionId,userId){// Replace 'any' with proper message type
const response=await fetch(this.getBaseUrl()+"/sessions/"+sessionId+"/messages?user_id="+userId,{headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch messages");return data.data;};return SessionAPI;}();let TeamAPI=/*#__PURE__*/function(){function TeamAPI(){}var _proto2=TeamAPI.prototype;_proto2.getBaseUrl=function getBaseUrl(){return (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .getServerUrl */ .Tt)();};_proto2.getHeaders=function getHeaders(){return{"Content-Type":"application/json"};};_proto2.listTeams=async function listTeams(userId){const response=await fetch(this.getBaseUrl()+"/teams/?user_id="+userId,{headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch teams");return data.data;};_proto2.getTeam=async function getTeam(teamId,userId){const response=await fetch(this.getBaseUrl()+"/teams/"+teamId+"?user_id="+userId,{headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch team");return data.data;};_proto2.createTeam=async function createTeam(teamData,userId){const team=Object.assign({},teamData,{user_id:userId});const response=await fetch(this.getBaseUrl()+"/teams/",{method:"POST",headers:this.getHeaders(),body:JSON.stringify(team)});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to create team");return data.data;};_proto2.deleteTeam=async function deleteTeam(teamId,userId){const response=await fetch(this.getBaseUrl()+"/teams/"+teamId+"?user_id="+userId,{method:"DELETE",headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to delete team");}// Team-Agent Link Management
;_proto2.linkAgent=async function linkAgent(teamId,agentId){const response=await fetch(this.getBaseUrl()+"/teams/"+teamId+"/agents/"+agentId,{method:"POST",headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to link agent to team");};_proto2.linkAgentWithSequence=async function linkAgentWithSequence(teamId,agentId,sequenceId){const response=await fetch(this.getBaseUrl()+"/teams/"+teamId+"/agents/"+agentId+"/"+sequenceId,{method:"POST",headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to link agent to team with sequence");};_proto2.unlinkAgent=async function unlinkAgent(teamId,agentId){const response=await fetch(this.getBaseUrl()+"/teams/"+teamId+"/agents/"+agentId,{method:"DELETE",headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to unlink agent from team");};_proto2.getTeamAgents=async function getTeamAgents(teamId){const response=await fetch(this.getBaseUrl()+"/teams/"+teamId+"/agents",{headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch team agents");return data.data;};return TeamAPI;}();let PlanAPI=/*#__PURE__*/function(){function PlanAPI(){}var _proto3=PlanAPI.prototype;_proto3.getBaseUrl=function getBaseUrl(){return (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .getServerUrl */ .Tt)();};_proto3.getHeaders=function getHeaders(){return{"Content-Type":"application/json"};};_proto3.listPlans=async function listPlans(userId){const response=await fetch(this.getBaseUrl()+"/plans/?user_id="+userId,{headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch plans");return data.data;};_proto3.getPlan=async function getPlan(planId,userId){const response=await fetch(this.getBaseUrl()+"/plans/"+planId+"?user_id="+userId,{headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch plan");return data.data;};_proto3.createPlan=async function createPlan(planData,userId){const plan=Object.assign({},planData,{user_id:userId});const response=await fetch(this.getBaseUrl()+"/plans/",{method:"POST",headers:this.getHeaders(),body:JSON.stringify(plan)});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to create plan");return data.data;};_proto3.updatePlan=async function updatePlan(planId,planData,userId){if(!planData.task){console.error("Missing task in planData:",planData);}if(!planData.steps||!Array.isArray(planData.steps)){console.error("Missing or invalid steps in planData:",planData);}const dataWithoutCreatedAt=(0,_babel_runtime_helpers_esm_objectWithoutPropertiesLoose__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A)(planData,_excluded2);const plan=Object.assign({},dataWithoutCreatedAt,{id:planId,user_id:userId,updated_at:null// This will be replaced by the server with current time
});try{const response=await fetch(this.getBaseUrl()+"/plans/"+planId+"?user_id="+userId,{method:"PUT",headers:this.getHeaders(),body:JSON.stringify(plan)});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to update plan");return data.data;}catch(error){console.error("Error in updatePlan:",error);throw error;}};_proto3.deletePlan=async function deletePlan(planId,userId){try{const response=await fetch(this.getBaseUrl()+"/plans/"+planId+"?user_id="+userId,{method:"DELETE",headers:this.getHeaders()});if(!response.ok){throw new Error("Failed to delete plan. Server responded with status: "+response.status);}const data=await response.json();if(!data.status){throw new Error(data.message||"Failed to delete plan");}}catch(error){throw error;}};_proto3.learnPlan=async function learnPlan(sessionId,userId){try{const response=await fetch(this.getBaseUrl()+"/plans/learn_plan",{method:"POST",headers:this.getHeaders(),body:JSON.stringify({session_id:sessionId,user_id:userId})});if(!response.ok){// Log the complete error response
const errorText=await response.text();console.error("Full error response:",errorText);try{const errorData=JSON.parse(errorText);throw new Error(errorData.detail||response.statusText);}catch(e){throw new Error(response.status+" "+response.statusText+": "+errorText);}}return await response.json();}catch(error){console.error("Error learning plan:",error);throw error;}};return PlanAPI;}();let SettingsAPI=/*#__PURE__*/function(){function SettingsAPI(){}var _proto4=SettingsAPI.prototype;_proto4.getBaseUrl=function getBaseUrl(){return (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .getServerUrl */ .Tt)();};_proto4.getHeaders=function getHeaders(){return{"Content-Type":"application/json"};};_proto4.getSettings=async function getSettings(userId){const response=await fetch(this.getBaseUrl()+"/settings/?user_id="+userId,{headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch settings");return data.data.config||{};// Return just the config object
};_proto4.updateSettings=async function updateSettings(userId,config){const response=await fetch(this.getBaseUrl()+"/settings/",{method:"PUT",headers:this.getHeaders(),body:JSON.stringify({user_id:userId,config:config})});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to update settings");return data.data;};return SettingsAPI;}();let Agent=/*#__PURE__*/function(){function Agent(){}var _proto5=Agent.prototype;_proto5.getBaseUrl=function getBaseUrl(){return (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .getServerUrl */ .Tt)();};_proto5.getHeaders=function getHeaders(){return{"Content-Type":"application/json"};}// get main agent list
;_proto5.getAgentList=async function getAgentList(userId){// console.log("Fetching agent list for user:", userId);
// console.log("Using base URL:", this.getBaseUrl());
const response=await fetch(this.getBaseUrl()+"/agentmode/?user_id="+userId,{headers:{"Content-Type":"application/json"}});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch agents");// 后端返回的数据结构是 { agents_mode: [] }
// 需要提取 config.agent_modes 数组
const agentSettings=data.data;if(agentSettings&&agentSettings.agents_mode){return agentSettings.agents_mode;}// 如果数据结构不符合预期，返回空数组
console.warn("Unexpected agent list data structure:",agentSettings);return[];}// update main agent list
;_proto5.updateAgentList=async function updateAgentList(userId,id){const response=await fetch(this.getBaseUrl()+"/agentmode/?user_id="+userId+"&id="+id,{method:"PUT",headers:this.getHeaders()});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to update agents");// 后端返回的数据结构是 { agents_mode: [] }
// 需要提取 config.agent_modes 数组
const agentSettings=data.data;if(agentSettings&&agentSettings.agents_mode){return agentSettings.agents_mode;}// 如果数据结构不符合预期，返回空数组
console.warn("Unexpected agent list data structure:",agentSettings);return[];}// delete main agent list
;_proto5.deleteMainAgent=async function deleteMainAgent(userId,id){const response=await fetch(this.getBaseUrl()+"/agentmode/?user_id="+userId+"&id="+id,{method:"DELETE",headers:this.getHeaders()});}// save agent config
;_proto5.saveAgentConfig=async function saveAgentConfig(agentConfig){const response=await fetch(this.getBaseUrl()+"/agentmode/",{method:"POST",headers:this.getHeaders(),body:JSON.stringify(agentConfig)});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to save agent config");return data.data;}// get agent config by user_id and mode
;_proto5.getAgentConfig=async function getAgentConfig(userId,mode){const response=await fetch(this.getBaseUrl()+"/agentmode/config/?user_id="+userId+"&mode="+mode,{headers:{"Content-Type":"application/json"}});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch agent config");return data.data;};return Agent;}();let AgentWorkerAPI=/*#__PURE__*/function(){function AgentWorkerAPI(){}var _proto6=AgentWorkerAPI.prototype;_proto6.getBaseUrl=function getBaseUrl(){return (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .getServerUrl */ .Tt)();};_proto6.getHeaders=function getHeaders(apiKey){return{"Content-Type":"application/json","Authorization":"Bearer "+apiKey};};_proto6.getAgentList=async function getAgentList(userId,apiKey,is_refresh){if(is_refresh===void 0){is_refresh=false;}let url=this.getBaseUrl()+"/agentworker/ddf_agents?user_id="+encodeURIComponent(userId)+"&is_refresh="+is_refresh;const response=await fetch(url,{headers:this.getHeaders(apiKey)});const data=await response.json();// console.log("Agent worker list response:", data);
if(!data.status)throw new Error(data.message||"Failed to fetch agent workers");return data.data;};_proto6.testRemoteAgent=async function testRemoteAgent(userId,baseUrl,modelName,apiKey){const response=await fetch(this.getBaseUrl()+"/agentworker/remote_agent/test",{method:'POST',headers:{"Content-Type":"application/json"},body:JSON.stringify({user_id:userId,base_url:baseUrl,model_name:modelName,api_key:apiKey})});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to test remote agent connection");return data.data;};_proto6.saveRemoteAgent=async function saveRemoteAgent(userId,agentConfig){const response=await fetch(this.getBaseUrl()+"/agentworker/remote_agent/save",{method:'POST',headers:{"Content-Type":"application/json"},body:JSON.stringify({user_id:userId,agent_config:agentConfig})});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to save remote agent");return data;};_proto6.getUserRemoteAgents=async function getUserRemoteAgents(userId){const response=await fetch(this.getBaseUrl()+"/agentworker/remote_agent/list?user_id="+userId,{method:'GET',headers:{"Content-Type":"application/json"}});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to get user remote agents");return data.data;};_proto6.removeRemoteAgent=async function removeRemoteAgent(userId,id){const response=await fetch(this.getBaseUrl()+"/agentworker/remote_agent/remove",{method:'DELETE',headers:{"Content-Type":"application/json"},body:JSON.stringify({user_id:userId,id})});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to remove remote agent");return data;};_proto6.getUserAgents=async function getUserAgents(userId,apiKey,is_refresh){if(is_refresh===void 0){is_refresh=false;}const url=this.getBaseUrl()+"/agentworker/user_agents/list?user_id="+encodeURIComponent(userId)+"&is_refresh="+is_refresh;const response=await fetch(url,{headers:this.getHeaders(apiKey)});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch user agents");return data.data||[];}// 在 AgentWorkerAPI 类中添加这个方法
;_proto6.getUserAgentById=async function getUserAgentById(userId,agentId){const url=this.getBaseUrl()+"/agentworker/user_agents/"+encodeURIComponent(agentId)+"?user_id="+encodeURIComponent(userId);const response=await fetch(url,{headers:{"Content-Type":"application/json"}});const data=await response.json();if(!data.status){const error=new Error(data.message||"Failed to fetch agent");error.name="ApiStatusError";error.code=data.error_code;error.payload=data;throw error;}return data.data;};_proto6.updateUserAgent=async function updateUserAgent(userId,agentConfig){const response=await fetch(this.getBaseUrl()+"/agentworker/user_agent/save",{method:'PUT',headers:{"Content-Type":"application/json"},body:JSON.stringify({user_id:userId,agent_config:agentConfig})});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to update user agent");return data;};_proto6.getUserDefaultAgents=async function getUserDefaultAgents(userId){const url=this.getBaseUrl()+"/agentworker/user_default_agents/list?user_id="+encodeURIComponent(userId);const response=await fetch(url,{headers:{"Content-Type":"application/json"}});const data=await response.json();if(!data.status)throw new Error(data.message||"Failed to fetch user default agents");return data;};return AgentWorkerAPI;}();const agentWorkerAPI=new AgentWorkerAPI();const teamAPI=new TeamAPI();const sessionAPI=new SessionAPI();const planAPI=new PlanAPI();const settingsAPI=new SettingsAPI();const agentAPI=new Agent();let FileAPI=/*#__PURE__*/function(){function FileAPI(){}var _proto7=FileAPI.prototype;_proto7.getBaseUrl=function getBaseUrl(){return (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .getServerUrl */ .Tt)();};_proto7.getHeaders=function getHeaders(){return{// Don't set Content-Type for file uploads, let the browser set it with boundary
};};_proto7.saveFilesToServer=async function saveFilesToServer(userId,files,sessionId){const formData=new FormData();// Add user_id and session_id as query parameters
const url=this.getBaseUrl()+"/files/?user_id="+encodeURIComponent(userId)+"&session_id="+sessionId;// Add files to form data
files.forEach(file=>{formData.append("files",file);});const response=await fetch(url,{method:"POST",headers:this.getHeaders(),body:formData});if(!response.ok){let errorMessage="HTTP error! status: "+response.status;try{const errorData=await response.json();errorMessage=errorData.detail||errorData.message||errorMessage;}catch(e){// If response is not JSON, use status text
errorMessage=response.statusText||errorMessage;}throw new Error(errorMessage);}const data=await response.json();if(!data.status){throw new Error(data.message||data.detail||"Failed to upload files");}return data.data;};return FileAPI;}();let AuthAPI=/*#__PURE__*/function(){function AuthAPI(){}var _proto8=AuthAPI.prototype;_proto8.getBaseUrl=function getBaseUrl(){return (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .getServerUrl */ .Tt)();};_proto8.getHeaders=function getHeaders(){return{"Content-Type":"application/json"};};_proto8.register=async function register(userId,password){const params=new URLSearchParams({user_id:userId,password:password});const response=await fetch(this.getBaseUrl()+"/umtlocal/?"+params.toString(),{method:"POST",headers:this.getHeaders()});const data=await response.json();if(!data.status){throw new Error(data.message||"注册失败");}return data;};_proto8.login=async function login(userId,password){const params=new URLSearchParams({user_id:userId,password:password});const response=await fetch(this.getBaseUrl()+"/umtlocal/login?"+params.toString(),{method:"POST",headers:this.getHeaders()});const data=await response.json();if(!data.status){throw new Error(data.message||"登录失败");}return data;};return AuthAPI;}();const authAPI=new AuthAPI();const fileAPI=new FileAPI();

/***/ }),

/***/ 74749:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

__webpack_require__.r(__webpack_exports__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(96540);
/* harmony import */ var gatsby__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(64810);
/* harmony import */ var _hooks_provider__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(92744);
/* harmony import */ var _components_views_api__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(39614);
// 接收sso登录的回调，负责保存token和username到本地存储，并跳转到主页





const AuthPage = () => {
  const {
    setUser
  } = react__WEBPACK_IMPORTED_MODULE_0__.useContext(_hooks_provider__WEBPACK_IMPORTED_MODULE_2__/* .appContext */ .v);
  react__WEBPACK_IMPORTED_MODULE_0__.useEffect(() => {
    const params = new URLSearchParams(window.location.search);
    const token = params.get("token");
    const username = params.get("username");
    if (token && username) {
      localStorage.setItem("token", token);
      localStorage.setItem("username", username);
      localStorage.setItem("user_email", username); // 假设username就是email
      localStorage.setItem("user_name", username);

      // 清除之前的agent选择，确保新用户登录后使用默认agent
      localStorage.removeItem("drsai-mode-config");

      // 更新用户状态
      setUser({
        name: username,
        email: username,
        username: username
      });

      // 登录成功后立即初始化用户默认智能体列表（在所有接口之前）
      _components_views_api__WEBPACK_IMPORTED_MODULE_3__/* .agentWorkerAPI */ .Ml.getUserDefaultAgents(username).then(() => {
        // 初始化完成后跳转到主页
        (0,gatsby__WEBPACK_IMPORTED_MODULE_1__.navigate)("/");
      }).catch(error => {
        console.error("Failed to initialize user default agents:", error);
        // 即使失败也跳转到主页，避免阻塞用户
        (0,gatsby__WEBPACK_IMPORTED_MODULE_1__.navigate)("/");
      });
    } else {
      // 没有参数，跳转到登录
      (0,gatsby__WEBPACK_IMPORTED_MODULE_1__.navigate)("/sso-login");
    }
  }, []);
  return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__.createElement("div", null, "\u6B63\u5728\u767B\u5F55\uFF0C\u8BF7\u7A0D\u5019...");
};
/* harmony default export */ __webpack_exports__["default"] = (AuthPage);

/***/ })

}]);
//# sourceMappingURL=component---src-pages-auth-tsx-6b500fdceacbe958676e.js.map