koishi-plugin-cocoyyy-console 1.0.16-beta.1 → 1.0.16-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -0
- package/lib/index.js +95 -19
- package/lib/services/test_command.d.ts +2 -1
- package/lib/utils/ai_axios.d.ts +17 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -321,7 +321,7 @@ function getMenuList(command = null, functionConfig) {
|
|
|
321
321
|
return `[所有命令都需要@bot]
|
|
322
322
|
当前可用功能列表:
|
|
323
323
|
${menuList.map((item) => item.name + ": " + item.description).join("\n ")}
|
|
324
|
-
输入"help 功能名"查看特定功能的指令和使用示例。`;
|
|
324
|
+
输入"help [功能名]"查看特定功能的指令和使用示例。`;
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
327
|
__name(getMenuList, "getMenuList");
|
|
@@ -1351,20 +1351,95 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1351
1351
|
}
|
|
1352
1352
|
__name(registerRbqCommands, "registerRbqCommands");
|
|
1353
1353
|
|
|
1354
|
+
// src/utils/ai_axios.ts
|
|
1355
|
+
var import_axios = __toESM(require("axios"));
|
|
1356
|
+
async function callOpenRouter(apiKey, messages, model = "gpt-4o-mini") {
|
|
1357
|
+
try {
|
|
1358
|
+
const { data } = await import_axios.default.post(
|
|
1359
|
+
"https://openrouter.ai/api/v1/chat/completions",
|
|
1360
|
+
{
|
|
1361
|
+
model,
|
|
1362
|
+
messages
|
|
1363
|
+
},
|
|
1364
|
+
{
|
|
1365
|
+
headers: {
|
|
1366
|
+
Authorization: `Bearer ${apiKey}`,
|
|
1367
|
+
"Content-Type": "application/json"
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
);
|
|
1371
|
+
const choices = data?.choices ?? [];
|
|
1372
|
+
const reply = choices[0]?.message?.content;
|
|
1373
|
+
let responseText;
|
|
1374
|
+
if (typeof reply === "string") {
|
|
1375
|
+
responseText = reply.trim();
|
|
1376
|
+
} else if (Array.isArray(reply)) {
|
|
1377
|
+
responseText = reply.map((part) => part?.text ?? "").join("").trim();
|
|
1378
|
+
if (!responseText) {
|
|
1379
|
+
responseText = "OpenRouter 返回空内容";
|
|
1380
|
+
}
|
|
1381
|
+
} else {
|
|
1382
|
+
responseText = "OpenRouter 返回了未知格式,请检查日志";
|
|
1383
|
+
}
|
|
1384
|
+
return { err: null, resp: responseText };
|
|
1385
|
+
} catch (error) {
|
|
1386
|
+
const err = error;
|
|
1387
|
+
const status = err.response?.status;
|
|
1388
|
+
const detail = err.response?.data?.error || err.response?.data?.message || err.message;
|
|
1389
|
+
logger.error(error, "OpenRouter 请求失败");
|
|
1390
|
+
const errorMessage = `test error${status ? `(${status})` : ""}: ${detail}`;
|
|
1391
|
+
return { err: errorMessage, resp: null };
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
__name(callOpenRouter, "callOpenRouter");
|
|
1395
|
+
|
|
1354
1396
|
// src/services/test_command.ts
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1397
|
+
var CONSTANTS = {
|
|
1398
|
+
ESU: "前提条件"
|
|
1399
|
+
};
|
|
1400
|
+
var chatHistory = [];
|
|
1401
|
+
function registerTestCommands(ctx, config) {
|
|
1402
|
+
ctx.command("test1 <prompt:text>", "调用 OpenRouter 模型进行测试").action(async ({ session }, prompt) => {
|
|
1403
|
+
const apiKey = config?.test || process.env.OPENROUTER_API_KEY;
|
|
1404
|
+
if (!apiKey) return "未配置 OpenRouter API Key(config.test 或环境变量 OPENROUTER_API_KEY)";
|
|
1405
|
+
const content = prompt?.trim();
|
|
1406
|
+
if (!content) return "请输入要测试的内容";
|
|
1407
|
+
chatHistory.push({ role: "user", content });
|
|
1408
|
+
const messages = [
|
|
1409
|
+
{ role: "system", content: CONSTANTS.ESU },
|
|
1410
|
+
...chatHistory
|
|
1411
|
+
];
|
|
1412
|
+
const { err, resp } = await callOpenRouter(apiKey, messages);
|
|
1413
|
+
if (err) {
|
|
1414
|
+
return err;
|
|
1415
|
+
}
|
|
1416
|
+
if (!resp) {
|
|
1417
|
+
return "OpenRouter 返回空响应";
|
|
1418
|
+
}
|
|
1419
|
+
chatHistory.push({ role: "assistant", content: resp });
|
|
1420
|
+
return resp;
|
|
1421
|
+
});
|
|
1422
|
+
ctx.command("test <text>", "调用 OpenRouter 模型进行测试").action(async ({ session }, text) => {
|
|
1423
|
+
return text;
|
|
1424
|
+
});
|
|
1425
|
+
ctx.middleware((session, next) => {
|
|
1426
|
+
const { content, uid, userId } = session;
|
|
1427
|
+
const cid = session.cid;
|
|
1428
|
+
if (session.guildId != "829263238") return next();
|
|
1429
|
+
if (ctx.bots[uid]) return next();
|
|
1430
|
+
if (session.quote) {
|
|
1431
|
+
const quoteContent = session.quote.content;
|
|
1432
|
+
const quoteUserId = session.quote.user.id;
|
|
1433
|
+
logger.error(`quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
|
|
1434
|
+
} else {
|
|
1435
|
+
logger.error(`content: ${content} userId: ${userId}`);
|
|
1361
1436
|
}
|
|
1362
1437
|
});
|
|
1363
1438
|
}
|
|
1364
1439
|
__name(registerTestCommands, "registerTestCommands");
|
|
1365
1440
|
|
|
1366
1441
|
// src/services/kuro_func/kuro_service.ts
|
|
1367
|
-
var
|
|
1442
|
+
var import_axios2 = __toESM(require("axios"));
|
|
1368
1443
|
var import_qs = __toESM(require("qs"));
|
|
1369
1444
|
|
|
1370
1445
|
// src/models/kuro_user.ts
|
|
@@ -1473,7 +1548,7 @@ __name(createUpdateUser, "createUpdateUser");
|
|
|
1473
1548
|
|
|
1474
1549
|
// src/services/kuro_func/kuro_service.ts
|
|
1475
1550
|
var userTokenMap = /* @__PURE__ */ new Map();
|
|
1476
|
-
var
|
|
1551
|
+
var CONSTANTS2 = {
|
|
1477
1552
|
BASE_URL: "https://api.kurobbs.com",
|
|
1478
1553
|
LOGIN_URL: "/user/sdkLogin",
|
|
1479
1554
|
GAME_DATA_URL: "/gamer/role/list",
|
|
@@ -1497,11 +1572,11 @@ var CONSTANTS = {
|
|
|
1497
1572
|
"source": "ios"
|
|
1498
1573
|
}
|
|
1499
1574
|
};
|
|
1500
|
-
var wavesApi =
|
|
1575
|
+
var wavesApi = import_axios2.default.create();
|
|
1501
1576
|
wavesApi.interceptors.request.use(
|
|
1502
1577
|
async (config) => {
|
|
1503
1578
|
if (config.url.startsWith("/")) {
|
|
1504
|
-
config.url =
|
|
1579
|
+
config.url = CONSTANTS2.BASE_URL + config.url;
|
|
1505
1580
|
}
|
|
1506
1581
|
return config;
|
|
1507
1582
|
},
|
|
@@ -1555,7 +1630,7 @@ async function getToken(session, mobile, code) {
|
|
|
1555
1630
|
code
|
|
1556
1631
|
});
|
|
1557
1632
|
try {
|
|
1558
|
-
const user_response = await wavesApi.post(
|
|
1633
|
+
const user_response = await wavesApi.post(CONSTANTS2.LOGIN_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, devCode } });
|
|
1559
1634
|
if (user_response.data.code != 200) {
|
|
1560
1635
|
logger.error(`验证码登录失败: ${user_response.data.msg}`);
|
|
1561
1636
|
return { status: false, msg: user_response.data.msg };
|
|
@@ -1595,7 +1670,7 @@ async function getGameData(token) {
|
|
|
1595
1670
|
let data = import_qs.default.stringify({
|
|
1596
1671
|
"gameId": 3
|
|
1597
1672
|
});
|
|
1598
|
-
const response = await wavesApi.post(
|
|
1673
|
+
const response = await wavesApi.post(CONSTANTS2.GAME_DATA_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, "token": token } });
|
|
1599
1674
|
if (response.data.code === 200) {
|
|
1600
1675
|
return { status: true, data: response.data.data[0] };
|
|
1601
1676
|
} else {
|
|
@@ -1614,7 +1689,7 @@ async function isAvailable(serverId, roleId, token) {
|
|
|
1614
1689
|
"roleId": roleId
|
|
1615
1690
|
});
|
|
1616
1691
|
try {
|
|
1617
|
-
const response = await wavesApi.post(
|
|
1692
|
+
const response = await wavesApi.post(CONSTANTS2.TOKEN_REFRESH_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, "token": token } });
|
|
1618
1693
|
if (response.data.code === 220) {
|
|
1619
1694
|
logger.info(`${roleId} 获取可用性成功,账号已过期`);
|
|
1620
1695
|
return { status: false, msg: "账号已过期" };
|
|
@@ -1635,7 +1710,7 @@ async function refreshData(bat, serverId, roleId, token) {
|
|
|
1635
1710
|
"roleId": roleId
|
|
1636
1711
|
});
|
|
1637
1712
|
try {
|
|
1638
|
-
const response = await wavesApi.post(
|
|
1713
|
+
const response = await wavesApi.post(CONSTANTS2.REFRESH_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, "token": token, "b-at": bat } });
|
|
1639
1714
|
if (response.data.code === 10902 || response.data.code === 200) {
|
|
1640
1715
|
return { status: true, data: response.data.data };
|
|
1641
1716
|
} else {
|
|
@@ -1662,7 +1737,7 @@ async function signIn(qq_uid) {
|
|
|
1662
1737
|
"reqMonth": ((/* @__PURE__ */ new Date()).getMonth() + 1).toString().padStart(2, "0")
|
|
1663
1738
|
});
|
|
1664
1739
|
try {
|
|
1665
|
-
const response = await wavesApi.post(
|
|
1740
|
+
const response = await wavesApi.post(CONSTANTS2.SIGNIN_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, "token": userInfo.token, devcode: "", "b-at": userInfo.bat } });
|
|
1666
1741
|
if (response.data.code === 200) {
|
|
1667
1742
|
if (response.data.data === null) {
|
|
1668
1743
|
logger.info(`[signIn Info]: ${qq_uid} 签到失败,返回空数据`);
|
|
@@ -1691,7 +1766,7 @@ async function getRoleData(qq_uid) {
|
|
|
1691
1766
|
"roleId": userInfo.role_id
|
|
1692
1767
|
});
|
|
1693
1768
|
try {
|
|
1694
|
-
const response = await wavesApi.post(
|
|
1769
|
+
const response = await wavesApi.post(CONSTANTS2.ROLE_DATA_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, "token": userInfo.token, "b-at": userInfo.bat } });
|
|
1695
1770
|
if (response.data.code === 10902 || response.data.code === 200) {
|
|
1696
1771
|
response.data.data = JSON.parse(response.data.data);
|
|
1697
1772
|
if (response.data.data === null || !response.data.data.showToGuest) {
|
|
@@ -1779,7 +1854,8 @@ var Config = import_koishi9.Schema.object({
|
|
|
1779
1854
|
redis_config: RedisConfigSchema.description("Redis配置"),
|
|
1780
1855
|
mysql_config: MysqlConfigSchema.description("MySQL 数据库配置"),
|
|
1781
1856
|
tag_config: SaveConfigSchema.description("tag图片保存配置"),
|
|
1782
|
-
repeat_config: RepeatConfigSchema.description("复读配置")
|
|
1857
|
+
repeat_config: RepeatConfigSchema.description("复读配置"),
|
|
1858
|
+
test: import_koishi9.Schema.string().description("测试")
|
|
1783
1859
|
});
|
|
1784
1860
|
var logger = new import_koishi9.Logger(name);
|
|
1785
1861
|
var savePath = null;
|
|
@@ -1806,7 +1882,7 @@ async function apply(ctx, config) {
|
|
|
1806
1882
|
if (config.function_config)
|
|
1807
1883
|
registerKuroCommands(ctx, connected);
|
|
1808
1884
|
if (dev_mode)
|
|
1809
|
-
registerTestCommands(ctx);
|
|
1885
|
+
registerTestCommands(ctx, config);
|
|
1810
1886
|
}
|
|
1811
1887
|
__name(apply, "apply");
|
|
1812
1888
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface OpenRouterMessage {
|
|
2
|
+
role: 'system' | 'user' | 'assistant';
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
export interface OpenRouterResult {
|
|
6
|
+
err: string | null;
|
|
7
|
+
resp: string | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 调用 OpenRouter API 进行对话
|
|
11
|
+
* @param apiKey OpenRouter API Key
|
|
12
|
+
* @param messages 消息数组,包含系统消息和用户消息
|
|
13
|
+
* @param model 模型名称,默认为 gpt-4o-mini
|
|
14
|
+
* @returns 返回包含错误和响应的对象 { err: string | null, resp: string | null }
|
|
15
|
+
* err 不为 null 时表示出错,resp 不为 null 时表示成功
|
|
16
|
+
*/
|
|
17
|
+
export declare function callOpenRouter(apiKey: string, messages: OpenRouterMessage[], model?: string): Promise<OpenRouterResult>;
|