|
@@ -1,7 +1,4 @@
|
|
import { create } from "zustand";
|
|
import { create } from "zustand";
|
|
-import { bluebookAiAgent } from "@/xiaolanbenlib/api/index";
|
|
|
|
-import request from "@/xiaolanbenlib/module/axios.js";
|
|
|
|
-
|
|
|
|
import {
|
|
import {
|
|
createAgent as _createAgent,
|
|
createAgent as _createAgent,
|
|
getAgents,
|
|
getAgents,
|
|
@@ -30,14 +27,16 @@ export interface AgentStoreState {
|
|
// 无需登录查看 agent 信息
|
|
// 无需登录查看 agent 信息
|
|
agentProfile: TAgentDetail | null;
|
|
agentProfile: TAgentDetail | null;
|
|
agentContactCard: TAgentContactCard | null;
|
|
agentContactCard: TAgentContactCard | null;
|
|
- agentProfileContactCard: TAgentContactCard | null;
|
|
|
|
agentCharacter: TEditAgentCharacter | null;
|
|
agentCharacter: TEditAgentCharacter | null;
|
|
- ents: {entName: string, entId: string|number}[]
|
|
|
|
|
|
+ ents: { entName: string; entId: string | number }[];
|
|
fetchAgents: () => Promise<TAgent[]>;
|
|
fetchAgents: () => Promise<TAgent[]>;
|
|
// 请求智能体数据登录状态
|
|
// 请求智能体数据登录状态
|
|
fetchAgent: (agentId: string) => Promise<TAgentDetail | null>;
|
|
fetchAgent: (agentId: string) => Promise<TAgentDetail | null>;
|
|
// 请求智能体数据非登录状态
|
|
// 请求智能体数据非登录状态
|
|
- fetchAgentProfile: (agentId: string, shareKey?: string) => Promise<TAgentDetail | null>;
|
|
|
|
|
|
+ fetchAgentProfile: (
|
|
|
|
+ agentId: string,
|
|
|
|
+ shareKey?: string
|
|
|
|
+ ) => Promise<TAgentDetail | null>;
|
|
createAgent: () => Promise<TAgentDetail | null>;
|
|
createAgent: () => Promise<TAgentDetail | null>;
|
|
clearProfileAgent: () => void;
|
|
clearProfileAgent: () => void;
|
|
setDefaultAgent: (agentId: string) => Promise<TAgentDetail | null>;
|
|
setDefaultAgent: (agentId: string) => Promise<TAgentDetail | null>;
|
|
@@ -45,16 +44,13 @@ export interface AgentStoreState {
|
|
agentId: string,
|
|
agentId: string,
|
|
data: TEditAgentCharacter
|
|
data: TEditAgentCharacter
|
|
) => Promise<boolean>;
|
|
) => Promise<boolean>;
|
|
- editAgentCard: (
|
|
|
|
- agentId: string,
|
|
|
|
- data: TAgentContactCard
|
|
|
|
- ) => Promise<boolean>;
|
|
|
|
|
|
+ editAgentCard: (agentId: string, data: TAgentContactCard) => Promise<boolean>;
|
|
editAgentWebsite: (
|
|
editAgentWebsite: (
|
|
agentId: string,
|
|
agentId: string,
|
|
data: TComponentItem[]
|
|
data: TComponentItem[]
|
|
) => Promise<boolean>;
|
|
) => Promise<boolean>;
|
|
- deleteAgent: (agentId: string) => Promise<void>
|
|
|
|
- resetData: () => void
|
|
|
|
|
|
+ deleteAgent: (agentId: string) => Promise<void>;
|
|
|
|
+ resetData: () => void;
|
|
}
|
|
}
|
|
|
|
|
|
export const useAgentStore = create<AgentStoreState>((set, get) => ({
|
|
export const useAgentStore = create<AgentStoreState>((set, get) => ({
|
|
@@ -63,27 +59,25 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
|
|
agentProfile: null,
|
|
agentProfile: null,
|
|
agentContactCard: null,
|
|
agentContactCard: null,
|
|
defaultAgent: null,
|
|
defaultAgent: null,
|
|
- agentProfileContactCard: null,
|
|
|
|
agentCharacter: null,
|
|
agentCharacter: null,
|
|
ents: [],
|
|
ents: [],
|
|
- resetData: ()=> {
|
|
|
|
|
|
+ resetData: () => {
|
|
set({
|
|
set({
|
|
agents: [],
|
|
agents: [],
|
|
agent: null,
|
|
agent: null,
|
|
agentProfile: null,
|
|
agentProfile: null,
|
|
agentContactCard: null,
|
|
agentContactCard: null,
|
|
defaultAgent: null,
|
|
defaultAgent: null,
|
|
- agentProfileContactCard: null,
|
|
|
|
agentCharacter: null,
|
|
agentCharacter: null,
|
|
ents: [],
|
|
ents: [],
|
|
- })
|
|
|
|
|
|
+ });
|
|
},
|
|
},
|
|
fetchAgents: async () => {
|
|
fetchAgents: async () => {
|
|
const response = await getAgents();
|
|
const response = await getAgents();
|
|
- const agentsData = response?.data
|
|
|
|
|
|
+ const agentsData = response?.data;
|
|
// const agentsData = response?.data?.filter(item => !item.isEnt)
|
|
// const agentsData = response?.data?.filter(item => !item.isEnt)
|
|
if (isSuccess(response.status) && agentsData.length) {
|
|
if (isSuccess(response.status) && agentsData.length) {
|
|
- const defaultAgent = agentsData.find( item => item.isDefault)
|
|
|
|
|
|
+ const defaultAgent = agentsData.find((item) => item.isDefault);
|
|
set({ agents: agentsData, defaultAgent });
|
|
set({ agents: agentsData, defaultAgent });
|
|
return agentsData;
|
|
return agentsData;
|
|
}
|
|
}
|
|
@@ -92,7 +86,7 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
|
|
},
|
|
},
|
|
fetchAgent: async (agentId: string) => {
|
|
fetchAgent: async (agentId: string) => {
|
|
const response = await _getMyAgent(agentId);
|
|
const response = await _getMyAgent(agentId);
|
|
- const result = isSuccess(response.status)
|
|
|
|
|
|
+ const result = isSuccess(response.status);
|
|
if (result && response.data) {
|
|
if (result && response.data) {
|
|
const agent = response.data;
|
|
const agent = response.data;
|
|
set({
|
|
set({
|
|
@@ -119,70 +113,53 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
|
|
}
|
|
}
|
|
set({
|
|
set({
|
|
agent: null,
|
|
agent: null,
|
|
- })
|
|
|
|
|
|
+ });
|
|
return null;
|
|
return null;
|
|
},
|
|
},
|
|
// 请求无需登录的 getAgent 接口
|
|
// 请求无需登录的 getAgent 接口
|
|
- fetchAgentProfile: async (agentId: string, shareKey?:string) => {
|
|
|
|
- if(shareKey){
|
|
|
|
- shareKey = decodeURIComponent(shareKey)
|
|
|
|
-
|
|
|
|
|
|
+ fetchAgentProfile: async (agentId: string, shareKey?: string) => {
|
|
|
|
+ if (shareKey) {
|
|
|
|
+ shareKey = decodeURIComponent(shareKey);
|
|
}
|
|
}
|
|
const response = await _getAgent(agentId, shareKey);
|
|
const response = await _getAgent(agentId, shareKey);
|
|
- const result = isSuccess(response.status)
|
|
|
|
- const agent = response.data
|
|
|
|
|
|
+ const result = isSuccess(response.status);
|
|
|
|
+ const agent = response.data;
|
|
if (result && agent) {
|
|
if (result && agent) {
|
|
- agent.components = (agent.components ?? []).filter(item => item.enabled)
|
|
|
|
|
|
+ agent.components = (agent.components ?? []).filter(
|
|
|
|
+ (item) => item.enabled
|
|
|
|
+ );
|
|
set({
|
|
set({
|
|
agentProfile: agent,
|
|
agentProfile: agent,
|
|
- agentProfileContactCard: {
|
|
|
|
- address: agent.address ?? "",
|
|
|
|
- email: agent.email ?? "",
|
|
|
|
- entName: agent.entName ?? "",
|
|
|
|
- mobile: agent.mobile ?? "",
|
|
|
|
- name: agent.name ?? "",
|
|
|
|
- position: agent.position ?? "",
|
|
|
|
- qrCodeUrl: agent.qrCodeUrl ?? "",
|
|
|
|
- },
|
|
|
|
});
|
|
});
|
|
return agent;
|
|
return agent;
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
},
|
|
},
|
|
- clearProfileAgent: ()=> {
|
|
|
|
|
|
+ clearProfileAgent: () => {
|
|
set({
|
|
set({
|
|
agentProfile: null,
|
|
agentProfile: null,
|
|
- agentProfileContactCard: {
|
|
|
|
- address: "",
|
|
|
|
- email: '',
|
|
|
|
- entName: '',
|
|
|
|
- mobile: '',
|
|
|
|
- name: '',
|
|
|
|
- position: '',
|
|
|
|
- qrCodeUrl: '',
|
|
|
|
- },
|
|
|
|
});
|
|
});
|
|
},
|
|
},
|
|
setDefaultAgent: async (agentId: string) => {
|
|
setDefaultAgent: async (agentId: string) => {
|
|
const response = await _setDefaultAgent(agentId);
|
|
const response = await _setDefaultAgent(agentId);
|
|
- const result = isSuccess(response.status)
|
|
|
|
- if(result){
|
|
|
|
- const agent = await get().fetchAgent(agentId)
|
|
|
|
|
|
+ const result = isSuccess(response.status);
|
|
|
|
+ if (result) {
|
|
|
|
+ const agent = await get().fetchAgent(agentId);
|
|
set({
|
|
set({
|
|
- defaultAgent: agent
|
|
|
|
- })
|
|
|
|
- return agent
|
|
|
|
|
|
+ defaultAgent: agent,
|
|
|
|
+ });
|
|
|
|
+ return agent;
|
|
}
|
|
}
|
|
- return null
|
|
|
|
|
|
+ return null;
|
|
},
|
|
},
|
|
// 创建并设置其为默认智能体
|
|
// 创建并设置其为默认智能体
|
|
createAgent: async () => {
|
|
createAgent: async () => {
|
|
const response = await _createAgent();
|
|
const response = await _createAgent();
|
|
- const agentDetail = response.data
|
|
|
|
|
|
+ const agentDetail = response.data;
|
|
if (agentDetail?.agentId) {
|
|
if (agentDetail?.agentId) {
|
|
// 创建新智能体,自动设置为默认智能体
|
|
// 创建新智能体,自动设置为默认智能体
|
|
- await get().setDefaultAgent(agentDetail.agentId)
|
|
|
|
-
|
|
|
|
|
|
+ await get().setDefaultAgent(agentDetail.agentId);
|
|
|
|
+
|
|
const a: TAgent = {
|
|
const a: TAgent = {
|
|
agentId: agentDetail.agentId ?? "",
|
|
agentId: agentDetail.agentId ?? "",
|
|
isDefault: true,
|
|
isDefault: true,
|
|
@@ -190,14 +167,11 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
|
|
isNewEnt: agentDetail.isNewEnt ?? false,
|
|
isNewEnt: agentDetail.isNewEnt ?? false,
|
|
name: agentDetail.name ?? "",
|
|
name: agentDetail.name ?? "",
|
|
enabledChatBg: false,
|
|
enabledChatBg: false,
|
|
- }
|
|
|
|
|
|
+ };
|
|
|
|
|
|
set((state) => {
|
|
set((state) => {
|
|
return {
|
|
return {
|
|
- agents: [
|
|
|
|
- ...state.agents,
|
|
|
|
- a,
|
|
|
|
- ],
|
|
|
|
|
|
+ agents: [...state.agents, a],
|
|
defaultAgent: a,
|
|
defaultAgent: a,
|
|
};
|
|
};
|
|
});
|
|
});
|
|
@@ -209,56 +183,58 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
|
|
editAgentCharacter: async (agentId: string, data: TEditAgentCharacter) => {
|
|
editAgentCharacter: async (agentId: string, data: TEditAgentCharacter) => {
|
|
const response = await _editAgentCharacter(agentId, data);
|
|
const response = await _editAgentCharacter(agentId, data);
|
|
console.log(response.data);
|
|
console.log(response.data);
|
|
- const result = isSuccess(response.status)
|
|
|
|
|
|
+ const result = isSuccess(response.status);
|
|
//@ts-ignore
|
|
//@ts-ignore
|
|
set((state) => {
|
|
set((state) => {
|
|
return {
|
|
return {
|
|
agent: {
|
|
agent: {
|
|
...state.agent,
|
|
...state.agent,
|
|
- voiceId: data.voiceId
|
|
|
|
|
|
+ voiceId: data.voiceId,
|
|
},
|
|
},
|
|
};
|
|
};
|
|
});
|
|
});
|
|
- return result
|
|
|
|
|
|
+ return result;
|
|
},
|
|
},
|
|
editAgentCard: async (agentId: string, data: TAgentContactCard) => {
|
|
editAgentCard: async (agentId: string, data: TAgentContactCard) => {
|
|
console.log(agentId, data);
|
|
console.log(agentId, data);
|
|
const response = await _editAgentCard(agentId, data);
|
|
const response = await _editAgentCard(agentId, data);
|
|
console.log(response);
|
|
console.log(response);
|
|
- const result = isSuccess(response.status)
|
|
|
|
-
|
|
|
|
- return result
|
|
|
|
|
|
+ const result = isSuccess(response.status);
|
|
|
|
+
|
|
|
|
+ return result;
|
|
},
|
|
},
|
|
editAgentWebsite: async (agentId: string, data: TComponentItem[]) => {
|
|
editAgentWebsite: async (agentId: string, data: TComponentItem[]) => {
|
|
console.log(agentId, data);
|
|
console.log(agentId, data);
|
|
- const response = await _editAgentWebsite(agentId, {components: data});
|
|
|
|
|
|
+ const response = await _editAgentWebsite(agentId, { components: data });
|
|
console.log(response);
|
|
console.log(response);
|
|
- const result = isSuccess(response.status)
|
|
|
|
-
|
|
|
|
- return result
|
|
|
|
|
|
+ const result = isSuccess(response.status);
|
|
|
|
+
|
|
|
|
+ return result;
|
|
},
|
|
},
|
|
- deleteAgent: async (agentId: string)=> {
|
|
|
|
- const response = await _deleteAgent(agentId)
|
|
|
|
- if(isSuccess(response.status)){
|
|
|
|
- const de = get().agents.filter((item: TAgent) => item.agentId !== agentId).reverse()[0]
|
|
|
|
- console.log(agentId, de, 'setDefault')
|
|
|
|
|
|
+ deleteAgent: async (agentId: string) => {
|
|
|
|
+ const response = await _deleteAgent(agentId);
|
|
|
|
+ if (isSuccess(response.status)) {
|
|
|
|
+ const de = get()
|
|
|
|
+ .agents.filter((item: TAgent) => item.agentId !== agentId)
|
|
|
|
+ .reverse()[0];
|
|
|
|
+ console.log(agentId, de, "setDefault");
|
|
// 默认设置自创的智能体
|
|
// 默认设置自创的智能体
|
|
- if(de){
|
|
|
|
- await get().setDefaultAgent(de.agentId)
|
|
|
|
|
|
+ if (de) {
|
|
|
|
+ await get().setDefaultAgent(de.agentId);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// 重新拉取智能体列表
|
|
// 重新拉取智能体列表
|
|
- const restAgents = await get().fetchAgents()
|
|
|
|
- if(restAgents.length <= 0){
|
|
|
|
- set({agent: null, defaultAgent: null})
|
|
|
|
- Taro.reLaunch({url: '/pages/index/index'})
|
|
|
|
|
|
+ const restAgents = await get().fetchAgents();
|
|
|
|
+ if (restAgents.length <= 0) {
|
|
|
|
+ set({ agent: null, defaultAgent: null });
|
|
|
|
+ Taro.reLaunch({ url: "/pages/index/index" });
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- const defaultAgent = restAgents.find((item)=> !!item.isDefault)
|
|
|
|
- if(defaultAgent){
|
|
|
|
- await get().fetchAgent(defaultAgent.agentId)
|
|
|
|
- }
|
|
|
|
|
|
+ const defaultAgent = restAgents.find((item) => !!item.isDefault);
|
|
|
|
+ if (defaultAgent) {
|
|
|
|
+ await get().fetchAgent(defaultAgent.agentId);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ },
|
|
}));
|
|
}));
|