koishi-plugin-chatluna-think-viewer 1.0.18 → 1.0.20
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/README.md +7 -3
- package/index.js +41 -39
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# koishi-plugin-chatluna-think-viewer
|
|
2
2
|
|
|
3
|
-
????/????? `chatluna-character` ??????? `<think>`
|
|
3
|
+
????/????? `chatluna-character` ??????? `<think>` ?????????????????/??????
|
|
4
4
|
|
|
5
5
|
## ??
|
|
6
6
|
- ?? `chatluna-character` ??????????????????????
|
|
7
7
|
- ??????????????????
|
|
8
|
-
-
|
|
8
|
+
- **????????/??**????? `<think>`?`<status>`?`<output>`?`<analysis>`?`<system>` ??? JSON ????????(think/json/yaml)????????????(recall)?????(block)?
|
|
9
9
|
|
|
10
10
|
## ??
|
|
11
11
|
```bash
|
|
@@ -27,9 +27,13 @@ plugins:
|
|
|
27
27
|
# ??????
|
|
28
28
|
guardEnabled: true
|
|
29
29
|
guardMode: recall # recall | block
|
|
30
|
+
guardDelay: 1 # ????????block ????
|
|
31
|
+
# ??????????????? think/status/output/analysis/system ????? JSON/????
|
|
30
32
|
guardForbiddenPatterns:
|
|
31
33
|
- '<think>[\s\S]*?<\/think>'
|
|
32
|
-
- '
|
|
34
|
+
- '<status>[\s\S]*?<\/status>'
|
|
35
|
+
- '<output>[\s\S]*?<\/output>'
|
|
36
|
+
- '```\s*think[\s\S]*?```'
|
|
33
37
|
```
|
|
34
38
|
|
|
35
39
|
## ??
|
package/index.js
CHANGED
|
@@ -18,27 +18,27 @@ const defaultForbidden = [
|
|
|
18
18
|
|
|
19
19
|
const Config = Schema.intersect([
|
|
20
20
|
Schema.object({
|
|
21
|
-
command: Schema.string().default('think').description('
|
|
22
|
-
keywords: Schema.array(Schema.string()).default(['
|
|
23
|
-
allowPrivate: Schema.boolean().default(false).description('
|
|
24
|
-
emptyMessage: Schema.string().default('
|
|
25
|
-
renderImage: Schema.boolean().default(false).description('
|
|
26
|
-
}).description('
|
|
21
|
+
command: Schema.string().default('think').description('\u67e5\u770b\u601d\u8003\u5185\u5bb9\u7684\u6307\u4ee4\u540d'),
|
|
22
|
+
keywords: Schema.array(Schema.string()).default(['\u67e5\u770b\u601d\u8003', '\u4e0a\u6b21\u601d\u8003']).description('\u53ef\u65e0\u524d\u7f00\u89e6\u53d1\u7684\u5173\u952e\u8bcd'),
|
|
23
|
+
allowPrivate: Schema.boolean().default(false).description('\u662f\u5426\u5141\u8bb8\u5728\u79c1\u804a\u4e2d\u4f7f\u7528'),
|
|
24
|
+
emptyMessage: Schema.string().default('\u6682\u65f6\u6ca1\u6709\u53ef\u7528\u7684\u601d\u8003\u8bb0\u5f55\u3002').description('\u6ca1\u6709\u8bb0\u5f55\u65f6\u7684\u63d0\u793a\u6587\u672c'),
|
|
25
|
+
renderImage: Schema.boolean().default(false).description('\u662f\u5426\u901a\u8fc7\u0020\u0043\u0068\u0061\u0074\u004c\u0075\u006e\u0061\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0072\u0065\u006e\u0064\u0065\u0072\u0065\u0072\u0020\u5c06\u601d\u8003\u6e32\u67d3\u4e3a\u56fe\u7247\uff0c\u5931\u8d25\u65f6\u56de\u9000\u6587\u672c'),
|
|
26
|
+
}).description('\u601d\u8003\u67e5\u770b\u914d\u7f6e'),
|
|
27
27
|
Schema.object({
|
|
28
|
-
guardEnabled: Schema.boolean().default(true).description('
|
|
29
|
-
guardMode: Schema.union(['recall', 'block']).default('recall').description('
|
|
30
|
-
guardDelay: Schema.number().default(1).min(0).max(60).description('
|
|
31
|
-
guardAllowPrivate: Schema.boolean().default(true).description('
|
|
32
|
-
guardGroups: Schema.array(Schema.string()).default([]).description('
|
|
28
|
+
guardEnabled: Schema.boolean().default(true).description('\u5f02\u5e38\u8f93\u51fa\u81ea\u52a8\u62e6\u622a\u5f00\u5173'),
|
|
29
|
+
guardMode: Schema.union(['recall', 'block']).default('recall').description('\u0072\u0065\u0063\u0061\u006c\u006c\u003d\u5148\u53d1\u9001\u540e\u64a4\u56de\uff0c\u0062\u006c\u006f\u0063\u006b\u003d\u76f4\u63a5\u963b\u6b62\u53d1\u9001'),
|
|
30
|
+
guardDelay: Schema.number().default(1).min(0).max(60).description('\u64a4\u56de\u5ef6\u8fdf\uff08\u79d2\uff09'),
|
|
31
|
+
guardAllowPrivate: Schema.boolean().default(true).description('\u662f\u5426\u5728\u79c1\u804a\u4e2d\u4e5f\u542f\u7528\u62e6\u622a'),
|
|
32
|
+
guardGroups: Schema.array(Schema.string()).default([]).description('\u53ea\u5728\u8fd9\u4e9b\u7fa4\u751f\u6548\uff0c\u7559\u7a7a\u8868\u793a\u5168\u90e8'),
|
|
33
33
|
guardForbiddenPatterns: Schema.array(Schema.string())
|
|
34
34
|
.default(defaultForbidden)
|
|
35
|
-
.description('
|
|
35
|
+
.description('\u547d\u4e2d\u5373\u89c6\u4e3a\u5f02\u5e38\u7684\u6a21\u5f0f\uff0c\u7528\u4e8e\u907f\u514d\u601d\u8003\u6cc4\u9732\u6216\u0020\u004a\u0053\u004f\u004e\u0020\u751f\u51fa'),
|
|
36
36
|
guardAllowedPatterns: Schema.array(Schema.string())
|
|
37
37
|
.default(['[\\s\\S]+'])
|
|
38
|
-
.description('
|
|
39
|
-
guardLog: Schema.boolean().default(true).description('
|
|
40
|
-
guardContentPreview: Schema.number().default(80).min(10).max(500).description('
|
|
41
|
-
}).description('
|
|
38
|
+
.description('\u53ef\u9009\u767d\u540d\u5355\uff0c\u81f3\u5c11\u5339\u914d\u4e00\u4e2a\u624d\u7b97\u6b63\u5e38'),
|
|
39
|
+
guardLog: Schema.boolean().default(true).description('\u662f\u5426\u5728\u65e5\u5fd7\u8bb0\u5f55\u5f02\u5e38\u539f\u56e0\u548c\u5185\u5bb9'),
|
|
40
|
+
guardContentPreview: Schema.number().default(80).min(10).max(500).description('\u65e5\u5fd7\u5185\u5bb9\u9884\u89c8\u957f\u5ea6'),
|
|
41
|
+
}).description('\u5f02\u5e38\u8f93\u51fa\u81ea\u52a8\u5904\u7406'),
|
|
42
42
|
]);
|
|
43
43
|
|
|
44
44
|
function extractText(content) {
|
|
@@ -60,7 +60,7 @@ function extractText(content) {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
function extractThink(text) {
|
|
63
|
-
//
|
|
63
|
+
// \u67d0\u4e9b\u6a21\u578b/\u4e2d\u95f4\u4ef6\u4f1a\u5728\u540c\u4e00\u6761\u6d88\u606f\u91cc\u591a\u6b21\u51fa\u73b0 <think>\uff0c\u53d6\u6700\u540e\u4e00\u6b21
|
|
64
64
|
let last = '';
|
|
65
65
|
const regex = /<think>([\s\S]*?)<\/think>/gi;
|
|
66
66
|
let m;
|
|
@@ -72,7 +72,7 @@ function extractThink(text) {
|
|
|
72
72
|
|
|
73
73
|
function formatThink(text) {
|
|
74
74
|
if (!text) return text;
|
|
75
|
-
//
|
|
75
|
+
// \u5c1d\u8bd5\u683c\u5f0f\u5316 JSON\uff0c\u5931\u8d25\u5219\u505a\u57fa\u7840\u53bb\u7a7a\u884c/\u7f29\u8fdb\u7f8e\u5316
|
|
76
76
|
try {
|
|
77
77
|
const parsed = JSON.parse(text);
|
|
78
78
|
return JSON.stringify(parsed, null, 2);
|
|
@@ -145,22 +145,24 @@ function getLatestRawThink(temp) {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
function compileRegex(list) {
|
|
148
|
-
return (list || [])
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
148
|
+
return (list || [])
|
|
149
|
+
.map((p) => {
|
|
150
|
+
try {
|
|
151
|
+
return new RegExp(p, 'i');
|
|
152
|
+
} catch (err) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
.filter(Boolean);
|
|
155
157
|
}
|
|
156
158
|
|
|
157
159
|
function detectAbnormal(text, forbidden, allowed) {
|
|
158
160
|
if (!text) return null;
|
|
159
161
|
for (const re of forbidden) {
|
|
160
|
-
if (re.test(text)) return
|
|
162
|
+
if (re.test(text)) return `\u547d\u4e2d\u7981\u6b62\u6a21\u5f0f: /${re.source}/`;
|
|
161
163
|
}
|
|
162
164
|
if (allowed.length && !allowed.some((re) => re.test(text))) {
|
|
163
|
-
return '
|
|
165
|
+
return '\u672a\u5339\u914d\u4efb\u4f55\u5141\u8bb8\u6a21\u5f0f';
|
|
164
166
|
}
|
|
165
167
|
return null;
|
|
166
168
|
}
|
|
@@ -227,10 +229,10 @@ function applyGuard(ctx, config) {
|
|
|
227
229
|
}
|
|
228
230
|
|
|
229
231
|
function apply(ctx, config) {
|
|
230
|
-
//
|
|
232
|
+
// \u601d\u8003\u67e5\u770b\u6307\u4ee4
|
|
231
233
|
const cmd = ctx
|
|
232
|
-
.command(`${config.command} [index:string]`, '
|
|
233
|
-
.usage('
|
|
234
|
+
.command(`${config.command} [index:string]`, '\u8bfb\u53d6\u4e0a\u4e00\u6761\u542b <think> \u7684\u5185\u5bb9\uff0c\u53ef\u6307\u5b9a\u5012\u6570\u7b2c N \u6761')
|
|
235
|
+
.usage('\u4e0d\u5e26\u53c2\u6570\u9ed8\u8ba4\u6700\u65b0\uff1b\u793a\u4f8b\uff1athink 2 \u67e5\u8be2\u5012\u6570\u7b2c 2 \u6761 AI \u56de\u590d\u7684\u601d\u8003');
|
|
234
236
|
|
|
235
237
|
for (const keyword of config.keywords || []) {
|
|
236
238
|
cmd.shortcut(keyword, { prefix: false });
|
|
@@ -238,23 +240,23 @@ function apply(ctx, config) {
|
|
|
238
240
|
|
|
239
241
|
cmd.action(async ({ session, args }, rawIndex) => {
|
|
240
242
|
if (!config.allowPrivate && !session.guildId) {
|
|
241
|
-
return '
|
|
243
|
+
return '\u4e0d\u652f\u6301\u5728\u79c1\u804a\u4e2d\u67e5\u8be2\u3002';
|
|
242
244
|
}
|
|
243
245
|
|
|
244
246
|
const service = ctx.chatluna_character;
|
|
245
|
-
if (!service) return 'chatluna-character
|
|
247
|
+
if (!service) return 'chatluna-character \u672a\u52a0\u8f7d\u3002';
|
|
246
248
|
|
|
247
249
|
const temp = await service.getTemp(session);
|
|
248
250
|
const targetIndex = parseIndex(rawIndex ?? args?.[0]);
|
|
249
251
|
|
|
250
|
-
// 1)
|
|
252
|
+
// 1) \u4f18\u5148\u8bfb\u53d6\u6700\u65b0\u4e00\u6b21\u539f\u59cb\u54cd\u5e94\uff08\u901a\u5e38\u4ecd\u542b <think>\uff09\uff0c\u4ec5\u5bf9\u7b2c 1 \u6761\u6709\u6548
|
|
251
253
|
const thinkFromRaw = targetIndex === 1 ? getLatestRawThink(temp) : '';
|
|
252
254
|
|
|
253
|
-
// 2)
|
|
255
|
+
// 2) \u5386\u53f2 completionMessages \u4e2d\u771f\u6b63\u5e26 <think> \u7684 AI \u6d88\u606f
|
|
254
256
|
const messages = temp?.completionMessages || [];
|
|
255
257
|
const thinkFromHistory = thinkFromRaw ? '' : getNthThink(messages, targetIndex);
|
|
256
258
|
|
|
257
|
-
// 3)
|
|
259
|
+
// 3) \u56de\u9000\uff1a\u7b2c N \u6761 AI \u6d88\u606f\u518d\u5c1d\u8bd5\u62bd\u53d6 <think>
|
|
258
260
|
const fallbackMsg = thinkFromRaw || thinkFromHistory ? null : getNthAiMessage(messages, targetIndex);
|
|
259
261
|
const think = thinkFromRaw || thinkFromHistory || extractThink(extractText(fallbackMsg?.content));
|
|
260
262
|
const formatted = formatThink(think);
|
|
@@ -262,7 +264,7 @@ function apply(ctx, config) {
|
|
|
262
264
|
|
|
263
265
|
if (config.renderImage && ctx.chatluna?.renderer) {
|
|
264
266
|
try {
|
|
265
|
-
const title = `###
|
|
267
|
+
const title = `### \u4e0a\u4e00\u6761\u601d\u8003\uff08\u5012\u6570\u7b2c ${targetIndex} \u6761\uff09`;
|
|
266
268
|
const markdown = `<div align="center">\n${title}\n</div>\n\n<div align="left">\n${formatted}\n</div>`;
|
|
267
269
|
const rendered = await ctx.chatluna.renderer.render(
|
|
268
270
|
{
|
|
@@ -276,10 +278,10 @@ function apply(ctx, config) {
|
|
|
276
278
|
}
|
|
277
279
|
}
|
|
278
280
|
|
|
279
|
-
return
|
|
281
|
+
return `\u4e0a\u4e00\u6761\u601d\u8003\uff08\u5012\u6570\u7b2c ${targetIndex} \u6761\uff09\n${formatted}`;
|
|
280
282
|
});
|
|
281
283
|
|
|
282
|
-
//
|
|
284
|
+
// \u5f02\u5e38\u8f93\u51fa\u81ea\u52a8\u5904\u7406
|
|
283
285
|
applyGuard(ctx, config);
|
|
284
286
|
}
|
|
285
287
|
|
|
@@ -288,4 +290,4 @@ module.exports = {
|
|
|
288
290
|
apply,
|
|
289
291
|
Config,
|
|
290
292
|
inject,
|
|
291
|
-
};
|
|
293
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-chatluna-think-viewer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"description": "View chatluna <think> blocks and auto recall abnormal formatted replies.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,3 +41,4 @@
|
|
|
41
41
|
"README.md"
|
|
42
42
|
]
|
|
43
43
|
}
|
|
44
|
+
|