Skip to content

Commit

Permalink
fix: update SkyWork urls
Browse files Browse the repository at this point in the history
fix #671
fix #616
  • Loading branch information
sunner committed Mar 16, 2024
1 parent d937e53 commit a1b3161
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ function createNewWindow(url, userAgent = "") {
// Get QianWen bot's XSRF-TOKEN
const token = await getCookie("XSRF-TOKEN");
mainWindow.webContents.send("QIANWEN-XSRF-TOKEN", token);
} else if (url.startsWith("https://neice.tiangong.cn/")) {
} else if (url.startsWith("https://chat.tiangong.cn/")) {
// Get the tokens of SkyWork
const inviteToken = await getLocalStorage("formNatureQueueWaitToken");
const token = await getLocalStorage("formNatureResearchToken");
const inviteToken = await getLocalStorage("aiChatQueueWaitToken");
const token = await getLocalStorage("aiChatResearchToken");
mainWindow.webContents.send("SKYWORK-TOKENS", { inviteToken, token });
} else if (url.startsWith("https://character.ai/")) {
const token = await getLocalStorage("char_token");
Expand Down
33 changes: 8 additions & 25 deletions src/bots/SkyWorkBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class SkyWorkBot extends Bot {
static _className = "SkyWorkBot"; // Class name of the bot
static _logoFilename = "skywork-logo.png"; // Place it in public/bots/
static _isDarkLogo = true; // The main color of logo is dark
static _loginUrl = "https://neice.tiangong.cn/";
static _loginUrl = "https://chat.tiangong.cn/";
static _lock = new AsyncLock(); // AsyncLock for prompt requests

currentPrompt = ""; // Used by createChatContext() only
Expand All @@ -35,28 +35,11 @@ export default class SkyWorkBot extends Bot {
let available = false;

try {
const { data } = await axios.post(
"https://neice.tiangong.cn/api/v1/user/inviteVerify",
{ data: {} },
this.getAuthHeaders(),
const { data } = await axios.get(
"https://api.tiangong.cn/usercenter/v1/passport/check",
{ headers: { "K-Client-Id": 200001 } },
);

if (data.code === 200) {
available = true;
} else if (data.code >= 60100) {
// Invite token expired, request a new one
const { data } = await axios.post(
"https://neice.tiangong.cn/api/v1/queue/waitAccess",
{ data: { token: "" } },
this.getAuthHeaders(),
);
if (data.code === 200 && data.resp_data?.busy_now === false) {
await store.commit("setSkyWork", {
inviteToken: data.resp_data?.invite_token,
});
available = true;
}
}
available = data.data?.is_login;
} catch (err) {
console.error("SkyWork login error:", err);
}
Expand Down Expand Up @@ -87,7 +70,7 @@ export default class SkyWorkBot extends Bot {
if (!messageId) {
await axios
.post(
"https://neice.tiangong.cn/api/v1/chat/chat",
"https://api-chat.tiangong.cn/api/v1/chat/chat",
{ data: { content: prompt, session_id: context.sessionId } },
this.getAuthHeaders(),
)
Expand All @@ -114,7 +97,7 @@ export default class SkyWorkBot extends Bot {
await new Promise((resolve) => setTimeout(resolve, 1000));
await axios
.post(
"https://neice.tiangong.cn/api/v1/chat/getMessage",
"https://api-chat.tiangong.cn/api/v1/chat/getMessage",
{ data: { message_id: messageId } },
this.getAuthHeaders(),
)
Expand Down Expand Up @@ -152,7 +135,7 @@ export default class SkyWorkBot extends Bot {
let context = null;
await axios
.post(
"https://neice.tiangong.cn/api/v1/session/newSession",
"https://api-chat.tiangong.cn/api/v1/session/newSession",
{ data: { content: this.currentPrompt } },
this.getAuthHeaders(),
)
Expand Down

0 comments on commit a1b3161

Please sign in to comment.