koishi-plugin-cocoyyy-console 1.1.0-beta.3 → 1.1.0-beta.5
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.js
CHANGED
|
@@ -1530,7 +1530,6 @@ async function callOpenRouter(api_url, api_key, api_model = "gpt-4o-mini", messa
|
|
|
1530
1530
|
} else {
|
|
1531
1531
|
err = "OpenRouter 返回了未知格式,请检查日志";
|
|
1532
1532
|
}
|
|
1533
|
-
logger.error("[callOpenRouter Info]: " + responseText + ", err: " + err);
|
|
1534
1533
|
return { err, resp: responseText };
|
|
1535
1534
|
} catch (error) {
|
|
1536
1535
|
const err = error;
|
|
@@ -2078,21 +2077,18 @@ __name(registerKuroCommands, "registerKuroCommands");
|
|
|
2078
2077
|
|
|
2079
2078
|
// src/services/game_func/game_service.ts
|
|
2080
2079
|
var is_gaming = false;
|
|
2080
|
+
var is_thinking = false;
|
|
2081
2081
|
var chatHistory2 = [];
|
|
2082
2082
|
async function startSituationPuzzle(config) {
|
|
2083
2083
|
if (is_gaming)
|
|
2084
2084
|
return "海龟汤正在进行中,请先结束游戏";
|
|
2085
2085
|
chatHistory2 = [];
|
|
2086
|
-
const prompt_start =
|
|
2087
|
-
请生成一个海龟汤谜题,要求如下:
|
|
2088
|
-
1. 谜题是中文问句且内容简洁,包含一个看似矛盾或难以理解的情境
|
|
2089
|
-
2. 谜题长度不超过100字
|
|
2090
|
-
3. 谜题答案需要符合逻辑但出人意料
|
|
2091
|
-
`;
|
|
2086
|
+
const prompt_start = local_config2?.game?.situation_puzzle;
|
|
2092
2087
|
chatHistory2.push({ role: "system", content: [{ type: "text", text: prompt_start }] });
|
|
2093
2088
|
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2094
2089
|
if (err != null) {
|
|
2095
2090
|
logger.error("[startSituationPuzzle Error]: " + err);
|
|
2091
|
+
chatHistory2.pop();
|
|
2096
2092
|
return null;
|
|
2097
2093
|
}
|
|
2098
2094
|
chatHistory2.push({ role: "assistant", content: [{ type: "text", text: resp }] });
|
|
@@ -2102,12 +2098,16 @@ async function startSituationPuzzle(config) {
|
|
|
2102
2098
|
__name(startSituationPuzzle, "startSituationPuzzle");
|
|
2103
2099
|
async function questSituationPuzzle(content, config) {
|
|
2104
2100
|
chatHistory2.push({ role: "user", content: [{ type: "text", text: content }] });
|
|
2101
|
+
is_thinking = true;
|
|
2105
2102
|
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2106
|
-
|
|
2103
|
+
is_thinking = false;
|
|
2104
|
+
if (err != null) {
|
|
2107
2105
|
logger.error("[questSituationPuzzle Error]: " + err);
|
|
2106
|
+
chatHistory2.pop();
|
|
2108
2107
|
return null;
|
|
2109
2108
|
}
|
|
2110
2109
|
chatHistory2.push({ role: "assistant", content: [{ type: "text", text: resp }] });
|
|
2110
|
+
return resp;
|
|
2111
2111
|
}
|
|
2112
2112
|
__name(questSituationPuzzle, "questSituationPuzzle");
|
|
2113
2113
|
async function endSituationPuzzle(config) {
|
|
@@ -2116,6 +2116,7 @@ async function endSituationPuzzle(config) {
|
|
|
2116
2116
|
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2117
2117
|
if (err != null) {
|
|
2118
2118
|
logger.error("[endSituationPuzzle Error]: " + err);
|
|
2119
|
+
chatHistory2.pop();
|
|
2119
2120
|
return null;
|
|
2120
2121
|
}
|
|
2121
2122
|
return resp;
|
|
@@ -2135,12 +2136,12 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2135
2136
|
if (game_config?.config_path) {
|
|
2136
2137
|
local_config2 = loadYamlConfig(game_config.config_path);
|
|
2137
2138
|
if (local_config2) {
|
|
2138
|
-
logger.info("[loadYamlConfig Info]:
|
|
2139
|
+
logger.info("[loadYamlConfig Info]: Game 成功加载配置文件");
|
|
2139
2140
|
} else {
|
|
2140
|
-
logger.error("[loadYamlConfig Error]:
|
|
2141
|
+
logger.error("[loadYamlConfig Error]: Game 配置文件加载失败,将使用默认配置");
|
|
2141
2142
|
}
|
|
2142
2143
|
} else {
|
|
2143
|
-
logger.error("[loadYamlConfig Error]: 未配置
|
|
2144
|
+
logger.error("[loadYamlConfig Error]: 未配置 Game 配置文件路径");
|
|
2144
2145
|
}
|
|
2145
2146
|
ctx.command("gamelist", "查看所有游戏").action(async ({ session }) => {
|
|
2146
2147
|
return `[所有命令都需要@bot]
|
|
@@ -2178,9 +2179,9 @@ function registerGameMiddleware(ctx, ai_config) {
|
|
|
2178
2179
|
const { content, uid, userId } = session;
|
|
2179
2180
|
if (ctx.bots[uid]) return next();
|
|
2180
2181
|
if (!is_at_bot(session)) return next();
|
|
2182
|
+
if (is_thinking) return "正在思考,请耐心等待...";
|
|
2181
2183
|
const withoutTags = content.replace(/<[^>]+>/g, " ");
|
|
2182
2184
|
const text = withoutTags.replace(/\s+/g, " ").trim();
|
|
2183
|
-
logger.info("[game middleware Info]: " + text);
|
|
2184
2185
|
const resp = await questSituationPuzzle(text, ai_config);
|
|
2185
2186
|
return checkResp(resp);
|
|
2186
2187
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Context } from 'koishi';
|
|
2
2
|
import { GameConfig } from '../../utils/configs/game_config';
|
|
3
3
|
import { AiAPIConfig } from '../../utils/config';
|
|
4
|
+
declare let local_config: any;
|
|
4
5
|
declare function registerGameCommands(ctx: Context, game_config: GameConfig, ai_config: AiAPIConfig): void;
|
|
5
6
|
declare function registerGameMiddleware(ctx: Context, ai_config: AiAPIConfig): void;
|
|
6
|
-
export { registerGameCommands, registerGameMiddleware, };
|
|
7
|
+
export { local_config, registerGameCommands, registerGameMiddleware, };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AiAPIConfig } from "../../utils/config";
|
|
2
2
|
declare let is_gaming: boolean;
|
|
3
|
+
declare let is_thinking: boolean;
|
|
3
4
|
declare function startSituationPuzzle(config: AiAPIConfig): Promise<string>;
|
|
4
|
-
declare function questSituationPuzzle(content: string, config: AiAPIConfig): Promise<
|
|
5
|
+
declare function questSituationPuzzle(content: string, config: AiAPIConfig): Promise<string>;
|
|
5
6
|
declare function endSituationPuzzle(config: AiAPIConfig): Promise<string>;
|
|
6
|
-
export { is_gaming, startSituationPuzzle, questSituationPuzzle, endSituationPuzzle };
|
|
7
|
+
export { is_gaming, is_thinking, startSituationPuzzle, questSituationPuzzle, endSituationPuzzle };
|