mioku-plugin-chat 2.6.0 → 2.7.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/configs/personalization.ts +1 -1
- package/context.ts +2 -0
- package/core/base.ts +1 -1
- package/core/chat-engine.ts +18 -7
- package/core/chat-turn.ts +26 -9
- package/core/media/image-analyzer.ts +63 -397
- package/core/prompt.ts +11 -20
- package/db.ts +8 -12
- package/handlers/idle-debug.ts +96 -97
- package/handlers/message.ts +35 -34
- package/handlers/poke.ts +102 -124
- package/humanize/emoji-agent.ts +208 -332
- package/humanize/index.ts +2 -3
- package/index.ts +32 -44
- package/manage/cooldown.ts +60 -100
- package/manage/idle-check.ts +163 -70
- package/manage/queue-processor.ts +73 -30
- package/manage/session-turn-scheduler.ts +130 -0
- package/package.json +1 -1
- package/runtime/chat-runtime.ts +14 -2
- package/types.ts +3 -19
- package/utils/config.ts +57 -0
- package/utils/group-config.ts +9 -0
- package/utils/message.ts +4 -7
- package/utils/queue.ts +5 -0
package/context.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { GroupStructuredHistoryManager } from "./manage/group-structured-hi
|
|
|
11
11
|
import type { CooldownManager } from "./manage/cooldown";
|
|
12
12
|
import type { IdleCheckManager } from "./manage/idle-check";
|
|
13
13
|
import type { QueueProcessor } from "./manage/queue-processor";
|
|
14
|
+
import type { SessionTurnScheduler } from "./manage/session-turn-scheduler";
|
|
14
15
|
import type {
|
|
15
16
|
RunRateLimitGuard,
|
|
16
17
|
GetGroupHistoryMessages,
|
|
@@ -58,6 +59,7 @@ export interface ChatPluginContext {
|
|
|
58
59
|
cooldownManager: CooldownManager;
|
|
59
60
|
idleCheckManager: IdleCheckManager;
|
|
60
61
|
queueProcessor: QueueProcessor;
|
|
62
|
+
sessionTurnScheduler: SessionTurnScheduler;
|
|
61
63
|
|
|
62
64
|
// Utility
|
|
63
65
|
runWithRateLimitGuard: RunRateLimitGuard;
|
package/core/base.ts
CHANGED
|
@@ -518,7 +518,7 @@ function expandOutgoingLines(text: string): string[] {
|
|
|
518
518
|
|
|
519
519
|
function normalizeActionLineBreaks(text: string): string {
|
|
520
520
|
return String(text || "").replace(
|
|
521
|
-
/\\\s*(?=(?:\[
|
|
521
|
+
/\\\s*(?=(?:\[\]|\[emotion:[^\]]+\]|\[audio:[^\]]+\]|\[reply:-?\d+\]))/gi,
|
|
522
522
|
"\n",
|
|
523
523
|
);
|
|
524
524
|
}
|
package/core/chat-engine.ts
CHANGED
|
@@ -180,8 +180,7 @@ export async function runChat(
|
|
|
180
180
|
segment: string,
|
|
181
181
|
unitIndex: number,
|
|
182
182
|
): Promise<void> => {
|
|
183
|
-
const text = cleanMarkers(segment)
|
|
184
|
-
.replace(/\[meme:[^\]]+\]/gi, "")
|
|
183
|
+
const text = removeStickerIntentLines(cleanMarkers(segment))
|
|
185
184
|
.replace(/\[emotion:[^\]]+\]/gi, "")
|
|
186
185
|
.replace(/\r/g, "")
|
|
187
186
|
.trim();
|
|
@@ -348,13 +347,18 @@ export async function runChat(
|
|
|
348
347
|
let emojiPath: string | null = null;
|
|
349
348
|
let finalText = cleanedText;
|
|
350
349
|
if (cleanedText.trim()) {
|
|
351
|
-
const
|
|
350
|
+
const stickerResult = await humanize.emojiAgent.processStickerResponse(
|
|
352
351
|
cleanedText,
|
|
353
|
-
|
|
352
|
+
{
|
|
353
|
+
sessionId: toolCtx.sessionId,
|
|
354
|
+
botNickname: promptCtx.botNickname,
|
|
355
|
+
chatHistory: history,
|
|
356
|
+
targetMessage,
|
|
357
|
+
},
|
|
354
358
|
);
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
359
|
+
finalText = stickerResult.cleanedText;
|
|
360
|
+
if (stickerResult.success && stickerResult.emojiPath) {
|
|
361
|
+
emojiPath = stickerResult.emojiPath;
|
|
358
362
|
}
|
|
359
363
|
}
|
|
360
364
|
|
|
@@ -723,6 +727,13 @@ function cleanMarkers(text: string): string {
|
|
|
723
727
|
return cleaned;
|
|
724
728
|
}
|
|
725
729
|
|
|
730
|
+
function removeStickerIntentLines(text: string): string {
|
|
731
|
+
return String(text || "")
|
|
732
|
+
.split(/\r?\n/)
|
|
733
|
+
.filter((line) => !/^\s*\[\]\s*$/.test(line))
|
|
734
|
+
.join("\n");
|
|
735
|
+
}
|
|
736
|
+
|
|
726
737
|
function stripThinkBlocks(text: string): string {
|
|
727
738
|
let source = String(text || "");
|
|
728
739
|
let output = "";
|
package/core/chat-turn.ts
CHANGED
|
@@ -124,7 +124,7 @@ function resolveRuntimeContext(
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
// Shared send/save/cooldown tail for both live and runtime turns.
|
|
127
|
-
async function
|
|
127
|
+
export async function finalizeChatTurn(
|
|
128
128
|
pluginCtx: ChatPluginContext,
|
|
129
129
|
args: {
|
|
130
130
|
event: any;
|
|
@@ -358,7 +358,7 @@ export async function processChat(
|
|
|
358
358
|
return;
|
|
359
359
|
}
|
|
360
360
|
|
|
361
|
-
await
|
|
361
|
+
await finalizeChatTurn(pluginCtx, {
|
|
362
362
|
event: e,
|
|
363
363
|
cfg,
|
|
364
364
|
result,
|
|
@@ -376,15 +376,32 @@ export async function processChat(
|
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
378
|
|
|
379
|
-
|
|
380
|
-
export async function executeChatRuntimeRequest(
|
|
381
|
-
options: ExecuteChatRuntimeRequestOptions,
|
|
382
|
-
pluginCtx: ChatPluginContext,
|
|
383
|
-
): Promise<{
|
|
379
|
+
type ChatRuntimeExecutionResult = {
|
|
384
380
|
messages: string[];
|
|
385
381
|
toolCalls: Array<{ name: string; arguments: any; result: any }>;
|
|
386
382
|
collectedInfo: null;
|
|
387
|
-
}
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
export async function executeChatRuntimeRequest(
|
|
386
|
+
options: ExecuteChatRuntimeRequestOptions,
|
|
387
|
+
pluginCtx: ChatPluginContext,
|
|
388
|
+
): Promise<ChatRuntimeExecutionResult> {
|
|
389
|
+
const runtimeCtx = resolveRuntimeContext(pluginCtx.ctx, options);
|
|
390
|
+
if (!runtimeCtx.isGroup) {
|
|
391
|
+
return executeChatRuntimeRequestNow(options, pluginCtx);
|
|
392
|
+
}
|
|
393
|
+
return pluginCtx.sessionTurnScheduler.run(
|
|
394
|
+
runtimeCtx.sessionId,
|
|
395
|
+
"chat-runtime",
|
|
396
|
+
() => executeChatRuntimeRequestNow(options, pluginCtx),
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Runtime turn — triggered by ChatRuntime.generateNotice / requestInformation.
|
|
401
|
+
async function executeChatRuntimeRequestNow(
|
|
402
|
+
options: ExecuteChatRuntimeRequestOptions,
|
|
403
|
+
pluginCtx: ChatPluginContext,
|
|
404
|
+
): Promise<ChatRuntimeExecutionResult> {
|
|
388
405
|
const cfg = options.config;
|
|
389
406
|
const runtimeCtx = resolveRuntimeContext(pluginCtx.ctx, options);
|
|
390
407
|
const {
|
|
@@ -516,7 +533,7 @@ export async function executeChatRuntimeRequest(
|
|
|
516
533
|
{ extraTools: options.extraTools },
|
|
517
534
|
);
|
|
518
535
|
|
|
519
|
-
await
|
|
536
|
+
await finalizeChatTurn(pluginCtx, {
|
|
520
537
|
event,
|
|
521
538
|
cfg,
|
|
522
539
|
result,
|