koishi-plugin-ai-puzzle 0.0.1
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/ai.d.ts +17 -0
- package/lib/game.d.ts +60 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +1761 -0
- package/lib/matcher.d.ts +16 -0
- package/lib/prompt.d.ts +38 -0
- package/lib/render.d.ts +17 -0
- package/lib/state.d.ts +33 -0
- package/lib/types.d.ts +97 -0
- package/package.json +39 -0
- package/readme.md +5 -0
- package/templates//346/270/270/346/210/217/347/214/234/350/260/234.yml +83 -0
package/lib/ai.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EndpointConfig, AIMessage } from './types';
|
|
2
|
+
export interface Logger {
|
|
3
|
+
debug: (...args: any[]) => void;
|
|
4
|
+
info: (...args: any[]) => void;
|
|
5
|
+
warn: (...args: any[]) => void;
|
|
6
|
+
error: (...args: any[]) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare class AIClient {
|
|
9
|
+
private logger?;
|
|
10
|
+
constructor(logger?: Logger);
|
|
11
|
+
generate(messages: AIMessage[], endpoints: EndpointConfig[]): Promise<string>;
|
|
12
|
+
/** 轮询模式:按顺序轮询,每个端点失败后重试一次,还失败则尝试下一个 */
|
|
13
|
+
private generateRoundRobin;
|
|
14
|
+
/** 故障转移模式:优先用第一个,失败后依次尝试其余端点 */
|
|
15
|
+
private generateFailover;
|
|
16
|
+
private callEndpoint;
|
|
17
|
+
}
|
package/lib/game.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Context, Session } from 'koishi';
|
|
2
|
+
import { ChannelStateManager } from './state';
|
|
3
|
+
import { PromptManager } from './prompt';
|
|
4
|
+
import { AIClient } from './ai';
|
|
5
|
+
import { AnswerMatcher } from './matcher';
|
|
6
|
+
import { ImageRenderer } from './render';
|
|
7
|
+
import { Config } from './types';
|
|
8
|
+
import type { Logger } from './ai';
|
|
9
|
+
export declare class GameOrchestrator {
|
|
10
|
+
private ctx;
|
|
11
|
+
private config;
|
|
12
|
+
private stateManager;
|
|
13
|
+
private promptManager;
|
|
14
|
+
private aiClient;
|
|
15
|
+
private matcher;
|
|
16
|
+
private renderer;
|
|
17
|
+
private logger;
|
|
18
|
+
constructor(ctx: Context, config: Config, stateManager: ChannelStateManager, promptManager: PromptManager, aiClient: AIClient, matcher: AnswerMatcher, renderer: ImageRenderer, logger?: Logger);
|
|
19
|
+
/** 开始游戏 */
|
|
20
|
+
startGame(session: Session, extensionRule?: string, userPuzzleCode?: string): Promise<string>;
|
|
21
|
+
/** 手动获取下一条线索 */
|
|
22
|
+
nextClue(session: Session): Promise<string>;
|
|
23
|
+
/** 处理猜测(开放模式中间件 / 限制模式 guess 命令) */
|
|
24
|
+
processGuess(session: Session, guessText: string): Promise<string | null>;
|
|
25
|
+
/** 停止游戏 */
|
|
26
|
+
stopGame(session: Session): Promise<string>;
|
|
27
|
+
/** 切换模板 */
|
|
28
|
+
switchTemplate(session: Session, keyword: string): string;
|
|
29
|
+
/** 切换模式(通用) */
|
|
30
|
+
switchMode(session: Session, modeUpdate: Partial<{
|
|
31
|
+
manualMode: boolean;
|
|
32
|
+
autoInterval: number;
|
|
33
|
+
autoExtraDelay: number;
|
|
34
|
+
openMode: boolean;
|
|
35
|
+
restrictPuzzle: number;
|
|
36
|
+
restrictClue: number;
|
|
37
|
+
preMode: boolean;
|
|
38
|
+
}>): string;
|
|
39
|
+
/** 列出模板:当前频道已选 + 可切换的模板 */
|
|
40
|
+
listTemplates(session: Session): string;
|
|
41
|
+
/** 添加用户出题(交互式) */
|
|
42
|
+
addUserPuzzle(session: Session, code: string): Promise<void>;
|
|
43
|
+
/** 删除用户出题 */
|
|
44
|
+
deleteUserPuzzle(session: Session, code: string): Promise<string>;
|
|
45
|
+
/** 预生成切换 */
|
|
46
|
+
togglePreMode(session: Session): string;
|
|
47
|
+
/** 检查超时并结束游戏(由定时器调用) */
|
|
48
|
+
checkAndEndTimeout(channelId: string): Promise<boolean>;
|
|
49
|
+
private startAIPuzzle;
|
|
50
|
+
private startUserPuzzle;
|
|
51
|
+
private beginPlaying;
|
|
52
|
+
private throwNextClue;
|
|
53
|
+
private endGame;
|
|
54
|
+
private scheduleAutoClue;
|
|
55
|
+
private preGenerate;
|
|
56
|
+
private promptWithCancel;
|
|
57
|
+
private buildFullTextResult;
|
|
58
|
+
private getHistory;
|
|
59
|
+
private updateHistory;
|
|
60
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "ai-puzzle";
|
|
3
|
+
export declare const inject: string[];
|
|
4
|
+
export interface Config {
|
|
5
|
+
endpoints: {
|
|
6
|
+
baseURL: string;
|
|
7
|
+
apiKey: string;
|
|
8
|
+
model: string;
|
|
9
|
+
}[];
|
|
10
|
+
templates: {
|
|
11
|
+
keyword: string;
|
|
12
|
+
clueLevels: number[];
|
|
13
|
+
fuzzyEnabled: boolean;
|
|
14
|
+
fuzzyThreshold: number;
|
|
15
|
+
globalHistory: boolean;
|
|
16
|
+
}[];
|
|
17
|
+
imageOutput: boolean;
|
|
18
|
+
/** 日志显示级别:debug=0 全部, info=1 一般, warn=2 警告, error=3 仅错误 */
|
|
19
|
+
logLevel: number;
|
|
20
|
+
}
|
|
21
|
+
export declare const Config: Schema<Config>;
|
|
22
|
+
export declare function apply(ctx: Context, config: Config): void;
|