mioku-plugin-chat 2.8.2 → 2.8.3

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/core/base.ts CHANGED
@@ -2,6 +2,7 @@ import type { MiokiContext } from "mioki";
2
2
  import { logger } from "mioki";
3
3
  import type { SkillPermissionRole } from "mioku";
4
4
  import type { AIInstance, AIService } from "mioku";
5
+ import type { ScreenshotService } from "mioku";
5
6
  import type {
6
7
  ChatConfig,
7
8
  ChatMessage,
@@ -12,7 +13,7 @@ import type { ChatDatabase } from "../db";
12
13
  import type { HumanizeEngine } from "../humanize";
13
14
  import { parseLineMarkers, splitByReplyMarkers } from "../utils/queue";
14
15
  import { getGroupHistory } from "../utils";
15
- import type { ScreenshotService } from "mioku";
16
+ import { getService, Services } from "mioku";
16
17
  import { synthesizeAudioBase64 } from "./media/audio";
17
18
  import {
18
19
  extractStandaloneMarkdownBlock,
@@ -157,9 +158,7 @@ export async function sendAIResponse(
157
158
  }
158
159
 
159
160
  if (markdownContent) {
160
- const screenshotService = ctx.services?.screenshot as
161
- | ScreenshotService
162
- | undefined;
161
+ const screenshotService = getService(ctx, Services.Screenshot);
163
162
  const imagePath = await buildMarkdownImage(
164
163
  ctx,
165
164
  markdownContent,
@@ -305,9 +304,7 @@ export async function sendMessage(
305
304
  const hasAt = atUsers.length > 0;
306
305
 
307
306
  if (markdownContent) {
308
- const screenshotService = ctx.services?.screenshot as
309
- | ScreenshotService
310
- | undefined;
307
+ const screenshotService = getService(ctx, Services.Screenshot);
311
308
  const imagePath = await buildMarkdownImage(
312
309
  ctx,
313
310
  markdownContent,
@@ -1,4 +1,5 @@
1
1
  import type { AISkill, SkillPermissionRole } from "mioku";
2
+ import { normalizeSkillPermissionRole } from "mioku";
2
3
  import type { ChatConfig } from "../types";
3
4
 
4
5
  function normalizeSkillName(name: unknown): string {
@@ -33,24 +34,9 @@ const SKILL_PERMISSION_RANK: Record<SkillPermissionRole, number> = {
33
34
  member: 0,
34
35
  admin: 1,
35
36
  owner: 2,
37
+ master: 2,
36
38
  };
37
39
 
38
- export function normalizeSkillPermissionRole(
39
- role: unknown,
40
- ): SkillPermissionRole {
41
- const normalized = String(role || "")
42
- .trim()
43
- .toLowerCase();
44
- if (
45
- normalized === "member" ||
46
- normalized === "admin" ||
47
- normalized === "owner"
48
- ) {
49
- return normalized;
50
- }
51
- return "member";
52
- }
53
-
54
40
  export function getSkillRequiredPermissionRole(
55
41
  skill: AISkill | undefined,
56
42
  ): SkillPermissionRole {
@@ -80,8 +80,8 @@ export function getForwardId(seg: {
80
80
  return String(seg?.id || seg?.data?.id || "");
81
81
  }
82
82
 
83
- export function getCardData(seg: { data?: unknown }): string | null {
84
- const data = seg?.data;
83
+ export function getCardData(seg: unknown): string | null {
84
+ const data = (seg as { data?: unknown } | null | undefined)?.data;
85
85
  if (!data) return null;
86
86
  return typeof data === "string" ? data : JSON.stringify(data);
87
87
  }
@@ -1,4 +1,8 @@
1
1
  import type { ChatPluginContext, ChatHandlerState } from "../context";
2
+ import type {
3
+ GroupMessageEvent,
4
+ PrivateMessageEvent,
5
+ } from "napcat-sdk";
2
6
  import {
3
7
  isGroupAllowed,
4
8
  shouldTrigger,
@@ -32,7 +36,7 @@ export function createMessageHandler(
32
36
  const { ctx } = pluginCtx;
33
37
  const { getConfig, matchMessageCommands, runtimeState } = state;
34
38
 
35
- return async (e: any) => {
39
+ return async (e: GroupMessageEvent | PrivateMessageEvent) => {
36
40
  const isGroup = e.message_type === "group";
37
41
  const groupId: number | undefined = isGroup ? e.group_id : undefined;
38
42
  const cfg = await getConfig(groupId);
package/handlers/poke.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ChatPluginContext, ChatHandlerState } from "../context";
2
2
  import type { TargetMessage } from "../types";
3
+ import type { GroupPokeNoticeEvent } from "napcat-sdk";
3
4
  import { getBotRole, isGroupAllowed } from "../utils";
4
5
  import { buildStructuredUserInputFromTarget } from "../manage/group-structured-history";
5
6
  import { finalizeChatTurn } from "../core/chat-turn";
@@ -12,7 +13,7 @@ export function createPokeHandler(
12
13
  const { ctx } = pluginCtx;
13
14
  const { getConfig, runtimeState, pokeCooldowns } = state;
14
15
 
15
- return async (e: any) => {
16
+ return async (e: GroupPokeNoticeEvent) => {
16
17
  if (e.target_id !== e.self_id) return;
17
18
  const groupId = e.group_id;
18
19
  const cfg = groupId ? await getConfig(groupId) : await getConfig();
@@ -36,7 +37,7 @@ export function createPokeHandler(
36
37
  "group",
37
38
  groupId,
38
39
  );
39
- const userId = e.user_id || e.operator_id;
40
+ const userId = e.user_id;
40
41
  const botRole = await getBotRole(groupId, ctx, e.self_id);
41
42
  const botNickname =
42
43
  cfg.nicknames[0] || ctx.pickBot(e.self_id).nickname || "Bot";
package/index.ts CHANGED
@@ -1,7 +1,10 @@
1
- import { definePlugin } from "mioki";
2
- import type { MiokiContext } from "mioki";
3
- import type { AIInstance, AIModelRole, AIService, ConfigService, ScreenshotService } from "mioku";
4
- import { getPluginRuntimeState } from "mioku";
1
+ import { definePlugin, type MiokiContext } from "mioki";
2
+ import type { AIInstance, AIModelRole, AIService } from "mioku";
3
+ import {
4
+ getPluginRuntimeState,
5
+ getService,
6
+ Services,
7
+ } from "mioku";
5
8
  import type { ChatConfig, ChatMessage, ChatGroupsFile, TargetMessage } from "./types";
6
9
  import { initDatabase } from "./db";
7
10
  import { SessionManager } from "./manage/session";
@@ -115,9 +118,9 @@ export default definePlugin({
115
118
  async setup(ctx: MiokiContext) {
116
119
  ctx.logger.info("聊天插件正在初始化...");
117
120
 
118
- const aiService = ctx.services?.ai as AIService | undefined;
119
- const configService = ctx.services?.config as ConfigService | undefined;
120
- const screenshotService = ctx.services?.screenshot as ScreenshotService | undefined;
121
+ const aiService = getService(ctx, Services.AI);
122
+ const configService = getService(ctx, Services.Config);
123
+ const screenshotService = getService(ctx, Services.Screenshot);
121
124
  let warnedMarkdownScreenshotUnavailable = false;
122
125
 
123
126
  if (configService) {
@@ -447,7 +450,7 @@ export default definePlugin({
447
450
  aiService.registerChatRuntime(runtime);
448
451
 
449
452
  ctx.handle("message", createMessageHandler(pluginCtx, handlerState));
450
- ctx.handle("notice.group.poke" as any, createPokeHandler(pluginCtx, handlerState));
453
+ ctx.handle("notice.group.poke", createPokeHandler(pluginCtx, handlerState));
451
454
 
452
455
  ctx.logger.info(
453
456
  `聊天插件加载成功 (main=${roleModels.main || "?"}, work=${roleModels.working || "?"}, vision=${roleModels.vision || "?"})`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mioku-plugin-chat",
3
- "version": "2.8.2",
3
+ "version": "2.8.3",
4
4
  "description": "AI 智能聊天插件",
5
5
  "main": "index.ts",
6
6
  "type": "module",
@@ -44,6 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "openai": "^4.0.0",
47
+ "puppeteer": "^23.0.0",
47
48
  "sharp": "^0.34.5"
48
49
  },
49
50
  "devDependencies": {