koishi-plugin-group-daily-analysis 0.0.1-alpha.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.
Files changed (46) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +83 -0
  3. package/lib/config.d.ts +68 -0
  4. package/lib/cron.d.ts +7 -0
  5. package/lib/index.cjs +4352 -0
  6. package/lib/index.d.ts +5 -0
  7. package/lib/index.mjs +4317 -0
  8. package/lib/onebot/cqcode.d.ts +13 -0
  9. package/lib/plugin.d.ts +3 -0
  10. package/lib/plugins/comic.d.ts +4 -0
  11. package/lib/plugins/command.d.ts +8 -0
  12. package/lib/plugins/prompt_variable.d.ts +3 -0
  13. package/lib/plugins/tool.d.ts +11 -0
  14. package/lib/service/analysis.d.ts +46 -0
  15. package/lib/service/api.d.ts +82 -0
  16. package/lib/service/image.d.ts +5 -0
  17. package/lib/service/llm.d.ts +42 -0
  18. package/lib/service/message.d.ts +54 -0
  19. package/lib/service/renderer.d.ts +22 -0
  20. package/lib/skins/anime.d.ts +18 -0
  21. package/lib/skins/art.d.ts +18 -0
  22. package/lib/skins/index.d.ts +49 -0
  23. package/lib/skins/md3.d.ts +18 -0
  24. package/lib/skins/newspaper.d.ts +18 -0
  25. package/lib/skins/scrapbook.d.ts +19 -0
  26. package/lib/skins/types.d.ts +68 -0
  27. package/lib/types.d.ts +169 -0
  28. package/lib/utils.d.ts +54 -0
  29. package/package.json +120 -0
  30. package/resources/anime/css/template_group.css +470 -0
  31. package/resources/anime/images/decoration_br.svg +19 -0
  32. package/resources/anime/images/decoration_tl.svg +24 -0
  33. package/resources/anime/template_group.html +108 -0
  34. package/resources/anime/template_user.html +99 -0
  35. package/resources/art/css/template_group.css +484 -0
  36. package/resources/art/template_group.html +77 -0
  37. package/resources/art/template_user.html +63 -0
  38. package/resources/md3/css/template_group.css +880 -0
  39. package/resources/md3/template_group.html +189 -0
  40. package/resources/md3/template_user.html +175 -0
  41. package/resources/newspaper/css/template_group.css +568 -0
  42. package/resources/newspaper/template_group.html +133 -0
  43. package/resources/newspaper/template_user.html +119 -0
  44. package/resources/scrapbook/css/style.css +1094 -0
  45. package/resources/scrapbook/template_group.html +115 -0
  46. package/resources/scrapbook/template_user.html +119 -0
package/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2025
2
+
3
+ dingyi <dingyi222666@foxmail.com>, lumia1998 <694807782@qq.com>
4
+
5
+ Permission is hereby granted, free of charge, to any
6
+ person obtaining a copy of this software and associated
7
+ documentation files (the "Software"), to deal in the
8
+ Software without restriction, including without
9
+ limitation the rights to use, copy, modify, merge,
10
+ publish, distribute, sublicense, and/or sell copies of
11
+ the Software, and to permit persons to whom the Software
12
+ is furnished to do so, subject to the following
13
+ conditions:
14
+
15
+ The above copyright notice and this permission notice
16
+ shall be included in all copies or substantial portions
17
+ of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
20
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
21
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
22
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
23
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
26
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
+ DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ <div align="center">
2
+
3
+ # koishi-plugin-group-daily-analysis
4
+
5
+ _Koishi 群聊分析插件_
6
+
7
+ ## [![npm](https://img.shields.io/npm/v/koishi-plugin-group-daily-analysis/alpha)](https://www.npmjs.com/package/koishi-plugin-group-daily-analysis) ![node version](https://img.shields.io/badge/node-%3E=18-green)
8
+
9
+ </div>
10
+
11
+ > 本版基于 [ChatLunaLab/chatluna-group-analysis](https://github.com/ChatLunaLab/chatluna-group-analysis) 改造;其源自 lumia1998 的群分析插件。保留原作者贡献与 AGPL-3.0 许可。
12
+ > `0.0.1-alpha.1` 为自定义 API 与群漫画的预发布版本。
13
+
14
+ 一个为 Koishi 设计的群聊分析插件,灵感来源于 `astrbot-qq-group-daily-analysis`,支持多维度统计和智能话题总结。
15
+
16
+ ## 截图
17
+
18
+ <img src="./screenshots/default.png" width="300" /> <img src="./screenshots/newspaper.png" width="300" /> <img src="./screenshots/anime.png" width="300" />
19
+
20
+ ## 特性
21
+
22
+ 1. **多维度统计** - 分析群聊的总消息数、参与人数、总字数、最活跃时段、发言排行榜等
23
+ 2. **智能话题总结** - 集成大语言模型(LLM),自动从聊天记录中总结出核心讨论话题
24
+ 3. **自然语言对话** - 基于 LLM 能力,用自然语言就可以从指定的时间,关注的话题等进行群分析(如 「群分析 过去三小时都聊了什么话题」)
25
+ 4. **图片报告** - 将分析结果渲染成美观的图片报告,直观易读(使用 Material Design 3 动态配色系统,支持明暗主题切换)
26
+ 5. **灵活触发** - 支持通过命令手动触发,也支持通过 CRON 表达式定时自动发送
27
+ 6. **高度可配置** - 支持群组白名单,自定义定时任务等配置选项
28
+ 7. **独立模型 API** - 支持 OpenAI Responses、Anthropic Messages、Google v1beta 和 OpenAI Chat Completions
29
+ 8. **群漫画** - 群消息 → 话题提取 → 自定义分镜提示词 → 生图 API,可附带角色三视图
30
+
31
+ ## 部署
32
+
33
+ 安装预发布版:`npm install koishi-plugin-group-daily-analysis@alpha`,在 Koishi 中启用 `group-analysis`。不要与 `chatluna-group-analysis` 同时启用,以免服务和命令重复注册。
34
+
35
+ **插件依赖 Puppeteer 和 ChatLuna,请确保已安装并配置了 koishi-plugin-puppeteer 和 koishi-plugin-chatluna 插件。**
36
+
37
+ 本分支的群分析、画像、查询解析和漫画分镜均直接调用下述自定义 API,不经过 ChatLuna 模型服务。ChatLuna 依赖仍用于原有工具和提示词变量注册:`group_message_fetch`、`group_user_persona` 保持不变。原有 Puppeteer 图片/PDF 报告不受漫画开关影响。
38
+
39
+ ### 从旧配置迁移
40
+
41
+ 在插件配置中填写 `llm.protocol`、`llm.baseUrl`、`llm.apiKey`,将 `model` 和可选的 `smallModel` 改成供应商的实际模型 ID,不再填写 ChatLuna 的平台/模型选择器值。两种模型共用同一个 LLM 接口配置。缺少 API 配置时不会回退 ChatLuna。
42
+
43
+ | `llm.protocol` | 请求接口 |
44
+ | --- | --- |
45
+ | `openai-responses` | `/v1/responses` |
46
+ | `anthropic-messages` | `/v1/messages` |
47
+ | `google-v1beta` | `/v1beta/models/{model}:generateContent` |
48
+ | `openai-chat` | `/v1/chat/completions` |
49
+
50
+ `baseUrl` 推荐填写 API 根地址或带版本的地址(例如 `https://your-provider.example/v1`)。也可填完整接口;Google 完整接口中的模型固定,不适合同时配置 `smallModel`。`llm.timeout` 默认 120 秒,`llm.maxOutputTokens` 默认 8192。Responses 和 Messages 不发送温度参数,以兼容限制温度的模型;其余文本协议使用 `temperature`。
51
+
52
+ ### 配置角色三视图漫画
53
+
54
+ 1. 启用 `comic.enabled`;单独填写 `comic.baseUrl`、`comic.apiKey` 和生图 `comic.model`。
55
+ 2. `comic.protocol` 选择 `google-v1beta` 或 `openai-images`。Google 模型须支持图片输入/输出;OpenAI 带参考图时使用 `/v1/images/edits`(multipart),不带时使用 `/v1/images/generations`。并非所有兼容代理都支持参考图,失败时不会静默丢弃参考图。
56
+ 3. 将 PNG/JPEG/WebP 三视图放在本机,填写 `comic.referenceImage`(绝对路径,或相对 Koishi 工作目录的路径,最大 20MB)。该路径仅由插件管理员配置,图片会上传给生图供应商;留空则无参考图。三视图不发送给文本模型。
57
+ 4. 编辑 `comic.prompt` 控制分镜。`{topics}` 替换为提取的话题,`{maxTopics}` 替换为漫画话题上限(默认 3)。默认要求英文画面描述、简短中文气泡和旁白,以及角色外观一致性。最终分镜全文连同三视图发送到生图 API。
58
+ 5. 在已启用分析的群发送 `群漫画` 或 `群漫画 2`。需要 Koishi 权限等级 3,天数为向前回溯的 1–7 个整 24 小时;受 `maxMessages`、`minMessages` 和现有消息过滤规则限制。
59
+
60
+ 漫画仅手动触发,不改变定时报告。每群同时只运行一个漫画任务,调用生图接口后默认冷却 10 分钟(`comic.cooldown`),失败也不自动重复付费生图。冷却状态仅在内存中,重载后重置。`comic.timeout` 默认 300 秒;OpenAI 使用 `comic.size`(默认 `1536x1024`,须按模型支持调整),Google 使用 16:9。
61
+
62
+ 生图响应支持 base64 图片,或公开 HTTPS 域名返回的图片 URL;URL 下载不跟随重定向,仅连接经校验的公网 IPv4。内网/仅 IPv6 下载地址不支持。输出图片最大 20MB,API JSON 响应最大 32MB。群聊消息会发给文本供应商,话题/分镜和参考图会发给生图供应商,请事先确认群成员知情。
63
+
64
+ ## 使用
65
+
66
+ ### 命令
67
+
68
+ - `群分析 <query: string>` - 分析群聊记录,可以用自然语言指定分析的时间,关键词,或者人物,话题。
69
+ - `群分析.启用` - 在发送的群中启用群聊分析
70
+ - `群分析.禁用` - 在发送的群中禁用群聊分析
71
+ - `群漫画 [days]` / `group-comic [days]` - 从最近若干天群话题生成漫画(默认 1 天)
72
+
73
+ ### 配置
74
+
75
+ - `allowedGroups` - 允许使用此插件的群号列表
76
+ - `cronSchedule` - 定时发送报告的 CRON 表达式
77
+ - `cronAnalysisDays` - 定时任务分析的天数
78
+ - `promptTopic` - 用于话题总结的 Prompt 模板
79
+
80
+ ## 感谢
81
+
82
+ - [lumia1998/koishi-plugin-group-analysis](https://github.com/lumia1998/koishi-plugin-group-analysis) Fork 的原始项目
83
+ - [SXP-Simon/astrbot-qq-group-daily-analysis](https://github.com/SXP-Simon/astrbot-qq-group-daily-analysis) AstrBot 的原始项目灵感来源,部分代码参考。
@@ -0,0 +1,68 @@
1
+ import { Schema } from 'koishi';
2
+ import { ApiConfig } from './service/api';
3
+ export interface GroupListener {
4
+ selfId: string;
5
+ channelId: string;
6
+ platform: string;
7
+ guildId?: string;
8
+ enabled: boolean;
9
+ }
10
+ export interface Config {
11
+ llm: ApiConfig;
12
+ comic: {
13
+ enabled: boolean;
14
+ protocol: 'openai-images' | 'google-v1beta';
15
+ baseUrl: string;
16
+ apiKey: string;
17
+ model: string;
18
+ referenceImage: string;
19
+ prompt: string;
20
+ timeout: number;
21
+ maxTopics: number;
22
+ cooldown: number;
23
+ size: string;
24
+ };
25
+ enableAllGroupsByDefault: boolean;
26
+ listenerGroups: GroupListener[];
27
+ wordsFilter: string[];
28
+ userFilter: string[];
29
+ personaUserFilter: string[];
30
+ model: string;
31
+ smallModel?: string;
32
+ alwaysPersistMessages: boolean;
33
+ retentionDays: number;
34
+ promptTopic: string;
35
+ promptUserTitles: string;
36
+ promptGoldenQuotes: string;
37
+ promptUserPersona: string;
38
+ promptQueryParser: string;
39
+ promptQueryChat: string;
40
+ outputFormat: 'image' | 'pdf' | 'text';
41
+ maxMessages: number;
42
+ temperature: number;
43
+ minMessages: number;
44
+ maxTopics: number;
45
+ maxUserTitles: number;
46
+ maxGoldenQuotes: number;
47
+ maxUsersInReport: number;
48
+ userTitleAnalysis: boolean;
49
+ groupAnalysisCacheMinutes: number;
50
+ cronSchedule: string;
51
+ autoAnalysisCooldown: number;
52
+ cronAnalysisDays: number;
53
+ useCalendarDayWindow: boolean;
54
+ personaAnalysisMessageInterval: number;
55
+ personaCacheLifetimeDays: number;
56
+ personaLookbackDays: number;
57
+ personaMaxMessages: number;
58
+ personaMinMessages: number;
59
+ registerTools: boolean;
60
+ theme: 'light' | 'dark' | 'auto';
61
+ skin: string;
62
+ debug?: boolean;
63
+ }
64
+ export declare const Config: Schema<Config>;
65
+ export declare const name = "group-analysis";
66
+ export declare const inject: {
67
+ required: string[];
68
+ };
package/lib/cron.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { Context } from 'koishi';
2
+ export declare function cron(ctx: Context, pattern: string, callback: () => void | Promise<void>, options?: CronOptions): () => void;
3
+ interface CronOptions {
4
+ cooldown?: number;
5
+ name?: string;
6
+ }
7
+ export {};