Skip to content

Commit 21b8468

Browse files
xxcddjosStorer
andauthored
Add support for kimi.moonshot.cn (#656)
* Add support for kimi.moonshot.cn * some improvements --------- Co-authored-by: josc146 <[email protected]>
1 parent c00b8ff commit 21b8468

File tree

7 files changed

+659
-1
lines changed

7 files changed

+659
-1
lines changed

src/background/index.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
chatgptApiModelKeys,
2424
chatgptWebModelKeys,
2525
claudeWebModelKeys,
26+
moonshotWebModelKeys,
2627
customApiModelKeys,
2728
defaultConfig,
2829
getUserConfig,
@@ -46,6 +47,7 @@ import { registerCommands } from './commands.mjs'
4647
import { generateAnswersWithBardWebApi } from '../services/apis/bard-web.mjs'
4748
import { generateAnswersWithClaudeWebApi } from '../services/apis/claude-web.mjs'
4849
import { generateAnswersWithMoonshotCompletionApi } from '../services/apis/moonshot-api.mjs'
50+
import { generateAnswersWithMoonshotWebApi } from '../services/apis/moonshot-web.mjs'
4951

5052
function setPortProxy(port, proxyTabId) {
5153
port.proxy = Browser.tabs.connect(proxyTabId)
@@ -161,6 +163,14 @@ async function executeApi(session, port, config) {
161163
config.moonshotApiKey,
162164
session.modelName,
163165
)
166+
} else if (moonshotWebModelKeys.includes(session.modelName)) {
167+
await generateAnswersWithMoonshotWebApi(
168+
port,
169+
session.question,
170+
session,
171+
config,
172+
session.modelName,
173+
)
164174
}
165175
}
166176

src/config/index.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const chatgptWebModelKeys = [
3131
export const bingWebModelKeys = ['bingFree4', 'bingFreeSydney']
3232
export const bardWebModelKeys = ['bardWebFree']
3333
export const claudeWebModelKeys = ['claude2WebFree']
34+
export const moonshotWebModelKeys = ['moonshotWebFree']
3435
export const gptApiModelKeys = ['gptApiInstruct', 'gptApiDavinci']
3536
export const chatgptApiModelKeys = [
3637
'chatgptApi35',
@@ -105,6 +106,8 @@ export const Models = {
105106
bingFree4: { value: '', desc: 'Bing (Web, GPT-4)' },
106107
bingFreeSydney: { value: '', desc: 'Bing (Web, GPT-4, Sydney)' },
107108

109+
moonshotWebFree: { value: '', desc: 'Kimi.Moonshot (Web, 100k)' },
110+
108111
bardWebFree: { value: '', desc: 'Gemini (Web)' },
109112

110113
chatglmTurbo: { value: 'chatglm_turbo', desc: 'ChatGLM (ChatGLM-Turbo)' },
@@ -230,6 +233,7 @@ export const defaultConfig = {
230233
'chatgptApi4_8k',
231234
'claude2WebFree',
232235
'bingFree4',
236+
'moonshotWebFree',
233237
'chatglmTurbo',
234238
'customModel',
235239
'azureOpenAi',
@@ -255,6 +259,8 @@ export const defaultConfig = {
255259
chatgptTabId: 0,
256260
chatgptArkoseReqUrl: '',
257261
chatgptArkoseReqForm: '',
262+
kimiMoonShotRefreshToken: '',
263+
kimiMoonShotAccessToken: '',
258264

259265
// unchangeable
260266

@@ -339,6 +345,11 @@ export function isUsingAzureOpenAi(configOrSession) {
339345
export function isUsingClaude2Api(configOrSession) {
340346
return claudeApiModelKeys.includes(configOrSession.modelName)
341347
}
348+
349+
export function isUsingMoonshotWeb(configOrSession) {
350+
return moonshotWebModelKeys.includes(configOrSession.modelName)
351+
}
352+
342353
export function isUsingGithubThirdPartyApi(configOrSession) {
343354
return githubThirdPartyApiModelKeys.includes(configOrSession.modelName)
344355
}

src/content-script/index.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
getPreferredLanguageKey,
1111
getUserConfig,
1212
setAccessToken,
13+
setUserConfig,
1314
} from '../config/index.mjs'
1415
import {
1516
createElementAtPosition,
@@ -289,7 +290,14 @@ async function prepareForStaticCard() {
289290
}
290291

291292
async function overwriteAccessToken() {
292-
if (location.hostname !== 'chat.openai.com') return
293+
if (location.hostname !== 'chat.openai.com') {
294+
if (location.hostname === 'kimi.moonshot.cn') {
295+
setUserConfig({
296+
kimiMoonShotRefreshToken: window.localStorage.refresh_token,
297+
})
298+
}
299+
return
300+
}
293301

294302
let data
295303
if (location.pathname === '/api/auth/session') {

src/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"https://*.poe.com/*",
1616
"https://*.google.com/*",
1717
"https://claude.ai/*",
18+
"https://*.moonshot.cn/*",
1819
"<all_urls>"
1920
],
2021
"permissions": [

src/manifest.v2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"https://*.poe.com/",
2323
"https://*.google.com/",
2424
"https://claude.ai/",
25+
"https://*.moonshot.cn/*",
2526
"<all_urls>"
2627
],
2728
"background": {

0 commit comments

Comments
 (0)