0412Xu commited on
Commit
3327444
·
verified ·
1 Parent(s): 54f7012

Upload 2 files

Browse files
Files changed (1) hide show
  1. src/routes/v1.js +15 -3
src/routes/v1.js CHANGED
@@ -1,5 +1,6 @@
1
  const express = require('express');
2
  const router = express.Router();
 
3
 
4
  const $root = require('../proto/message.js');
5
  const { v4: uuidv4, v5: uuidv5 } = require('uuid');
@@ -8,6 +9,7 @@ const keyManager = require('../utils/keyManager.js');
8
  const { spawn } = require('child_process');
9
  const path = require('path');
10
  const admin = require('../models/admin');
 
11
 
12
  // 存储刷新状态的变量
13
  let refreshStatus = {
@@ -280,7 +282,7 @@ router.get("/models", async (req, res) => {
280
  ?? process.env['x-cursor-checksum']
281
  ?? generateCursorChecksum(authToken.trim());
282
  //const cursorClientVersion = "0.45.11"
283
- const cursorClientVersion = "0.48.6";
284
 
285
  const availableModelsResponse = await fetch("https://api2.cursor.sh/aiserver.v1.AiService/AvailableModels", {
286
  method: 'POST',
@@ -292,6 +294,7 @@ router.get("/models", async (req, res) => {
292
  'user-agent': 'connect-es/1.6.1',
293
  'x-cursor-checksum': checksum,
294
  'x-cursor-client-version': cursorClientVersion,
 
295
  'x-cursor-timezone': 'Asia/Shanghai',
296
  'x-ghost-mode': 'true',
297
  'Host': 'api2.cursor.sh',
@@ -362,7 +365,7 @@ router.post('/chat/completions', async (req, res) => {
362
  const sessionid = uuidv5(authToken, uuidv5.DNS);
363
  const clientKey = generateHashed64Hex(authToken)
364
  //const cursorClientVersion = "0.45.11"
365
- const cursorClientVersion = "0.48.6";
366
  // Request the AvailableModels before StreamChat.
367
  const availableModelsResponse = await fetch("https://api2.cursor.sh/aiserver.v1.AiService/AvailableModels", {
368
  method: 'POST',
@@ -385,7 +388,14 @@ router.post('/chat/completions', async (req, res) => {
385
  })
386
 
387
  const cursorBody = generateCursorBody(messages, model);
388
- const response = await fetch('https://api2.cursor.sh/aiserver.v1.AiService/StreamChat', {
 
 
 
 
 
 
 
389
  method: 'POST',
390
  headers: {
391
  'authorization': `Bearer ${authToken}`,
@@ -398,6 +408,7 @@ router.post('/chat/completions', async (req, res) => {
398
  'x-client-key': clientKey,
399
  'x-cursor-checksum': checksum,
400
  'x-cursor-client-version': cursorClientVersion,
 
401
  'x-cursor-timezone': 'Asia/Shanghai',
402
  'x-ghost-mode': 'true',
403
  'x-request-id': uuidv4(),
@@ -405,6 +416,7 @@ router.post('/chat/completions', async (req, res) => {
405
  'Host': 'api2.cursor.sh',
406
  },
407
  body: cursorBody,
 
408
  timeout: {
409
  connect: 5000,
410
  read: 30000
 
1
  const express = require('express');
2
  const router = express.Router();
3
+ const { fetch, ProxyAgent, Agent } = require('undici');
4
 
5
  const $root = require('../proto/message.js');
6
  const { v4: uuidv4, v5: uuidv5 } = require('uuid');
 
9
  const { spawn } = require('child_process');
10
  const path = require('path');
11
  const admin = require('../models/admin');
12
+ const config = require('../config/config');
13
 
14
  // 存储刷新状态的变量
15
  let refreshStatus = {
 
282
  ?? process.env['x-cursor-checksum']
283
  ?? generateCursorChecksum(authToken.trim());
284
  //const cursorClientVersion = "0.45.11"
285
+ const cursorClientVersion = "0.48.7";
286
 
287
  const availableModelsResponse = await fetch("https://api2.cursor.sh/aiserver.v1.AiService/AvailableModels", {
288
  method: 'POST',
 
294
  'user-agent': 'connect-es/1.6.1',
295
  'x-cursor-checksum': checksum,
296
  'x-cursor-client-version': cursorClientVersion,
297
+ 'x-cursor-config-version': uuidv4(),
298
  'x-cursor-timezone': 'Asia/Shanghai',
299
  'x-ghost-mode': 'true',
300
  'Host': 'api2.cursor.sh',
 
365
  const sessionid = uuidv5(authToken, uuidv5.DNS);
366
  const clientKey = generateHashed64Hex(authToken)
367
  //const cursorClientVersion = "0.45.11"
368
+ const cursorClientVersion = "0.48.7";
369
  // Request the AvailableModels before StreamChat.
370
  const availableModelsResponse = await fetch("https://api2.cursor.sh/aiserver.v1.AiService/AvailableModels", {
371
  method: 'POST',
 
388
  })
389
 
390
  const cursorBody = generateCursorBody(messages, model);
391
+
392
+ // 添加代理支持
393
+ const dispatcher = config.proxy && config.proxy.enabled
394
+ ? new ProxyAgent(config.proxy.url, { allowH2: true })
395
+ : new Agent({ allowH2: true });
396
+
397
+ // 更新接口地址为 StreamUnifiedChatWithTools
398
+ const response = await fetch('https://api2.cursor.sh/aiserver.v1.ChatService/StreamUnifiedChatWithTools', {
399
  method: 'POST',
400
  headers: {
401
  'authorization': `Bearer ${authToken}`,
 
408
  'x-client-key': clientKey,
409
  'x-cursor-checksum': checksum,
410
  'x-cursor-client-version': cursorClientVersion,
411
+ 'x-cursor-config-version': uuidv4(),
412
  'x-cursor-timezone': 'Asia/Shanghai',
413
  'x-ghost-mode': 'true',
414
  'x-request-id': uuidv4(),
 
416
  'Host': 'api2.cursor.sh',
417
  },
418
  body: cursorBody,
419
+ dispatcher: dispatcher,
420
  timeout: {
421
  connect: 5000,
422
  read: 30000