@cmach_socket/opencode-qq-bot 2.0.2 → 2.2.0
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 +1 -1
- package/package.json +20 -19
- package/src/cleanup.ts +2 -0
- package/src/config/initial.ts +20 -5
- package/src/config/live.ts +23 -2
- package/src/config/registry.ts +54 -0
- package/src/index.ts +178 -302
- package/src/instance.ts +181 -42
- package/src/naplink/client.ts +30 -3
- package/src/panel/api.ts +81 -0
- package/src/panel/documents.ts +17 -14
- package/src/panel/server.ts +4 -0
- package/src/panel/tools.ts +32 -0
- package/src/panel/user-md.ts +218 -0
- package/src/runtime/claim.ts +20 -3
- package/src/runtime/events.ts +74 -0
- package/src/runtime/local.ts +336 -0
- package/src/runtime/napcat-owner.ts +108 -0
- package/src/runtime/share.ts +105 -0
- package/src/safe-object.ts +5 -0
- package/src/session/manager.ts +243 -5
- package/src/user/store.ts +11 -1
- package/web/dist/assets/index-BkGFsghB.js +9 -0
- package/web/dist/assets/index-DxbYpvI7.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-C5lRsdbz.css +0 -1
- package/web/dist/assets/index-siSfDOnC.js +0 -8
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ opencode plugin add @cmach_socket/opencode-qq-bot
|
|
|
50
50
|
模板见 [`config.example.json`](config.example.json);全部字段、默认值与取值限制见
|
|
51
51
|
[docs/guide/configuration.md](docs/guide/configuration.md)。
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
文件不存在时插件首次启动会自己生成一份最小模板,填上 `ownerQQ`、`napcat.url` 与 `access.allow` 就能用。
|
|
54
54
|
|
|
55
55
|
## 文档
|
|
56
56
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmach_socket/opencode-qq-bot",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "OpenCode V2 plugin bridging a QQ group chat (NapCat via NapLink) to an OpenCode session.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"format": "prettier --write .",
|
|
35
35
|
"format:check": "prettier --check .",
|
|
36
36
|
"test": "vitest run",
|
|
37
|
+
"audit:prod": "bun audit --production --audit-level=high --ignore=GHSA-25mm-r35j-6hgm --ignore=GHSA-mhqm-9wj8-w7r4 --ignore=GHSA-jmj2-9c5q-vw73 --ignore=GHSA-hqgx-p3r3-2cfg --ignore=GHSA-gvrf-jx37-rjv5 --ignore=GHSA-6wwr-g865-f46r --ignore=GHSA-4pf9-5fpx-xmr6 --ignore=GHSA-3wwj-8j6r-q339 --ignore=GHSA-98v3-7xjr-fg83 --ignore=GHSA-wpwg-r92p-fjjh --ignore=GHSA-rgjp-p5j7-w36x --ignore=GHSA-qv2w-fc3h-pm27 --ignore=GHSA-mpg7-vg3p-wc3m --ignore=GHSA-ffhw-4r4q-5cwv --ignore=GHSA-7c32-79xj-j3jp --ignore=GHSA-72fp-85cc-g945",
|
|
37
38
|
"web:build": "bun run --cwd web build",
|
|
38
39
|
"web:dev": "bun run --cwd web dev",
|
|
39
40
|
"web:check": "bun run --cwd web check",
|
|
@@ -52,35 +53,35 @@
|
|
|
52
53
|
"license": "CC-BY-NC-SA-4.0",
|
|
53
54
|
"dependencies": {
|
|
54
55
|
"@bybrave/proper-lockfile2": "5.1.0",
|
|
55
|
-
"@hono/node-server": "2.1.
|
|
56
|
-
"@naplink/naplink": "1.
|
|
57
|
-
"@opencode/plugin": "2.
|
|
58
|
-
"@opencode/schema": "2.
|
|
56
|
+
"@hono/node-server": "2.1.11",
|
|
57
|
+
"@naplink/naplink": "1.3.0",
|
|
58
|
+
"@opencode/plugin": "2.4.3",
|
|
59
|
+
"@opencode/schema": "2.4.3",
|
|
59
60
|
"async-mutex": "0.5.0",
|
|
60
61
|
"chokidar": "6.0.0",
|
|
61
|
-
"flare-redact": "1.
|
|
62
|
-
"hono": "4.13.
|
|
62
|
+
"flare-redact": "1.13.1",
|
|
63
|
+
"hono": "4.13.23",
|
|
63
64
|
"ipaddr.js": "2.5.0",
|
|
64
|
-
"remove-markdown": "0.8.
|
|
65
|
-
"request-filtering-agent": "3.
|
|
65
|
+
"remove-markdown": "0.8.3",
|
|
66
|
+
"request-filtering-agent": "3.3.1",
|
|
66
67
|
"winston": "3.19.0",
|
|
67
68
|
"winston-daily-rotate-file": "5.0.0",
|
|
68
69
|
"write-file-atomic": "8.0.0",
|
|
69
70
|
"zod": "4.6.7"
|
|
70
71
|
},
|
|
71
72
|
"devDependencies": {
|
|
72
|
-
"@sveltejs/vite-plugin-svelte": "7.3.
|
|
73
|
-
"@testing-library/svelte": "5.2
|
|
74
|
-
"@types/bun": "1.4.
|
|
73
|
+
"@sveltejs/vite-plugin-svelte": "7.3.2",
|
|
74
|
+
"@testing-library/svelte": "5.4.2",
|
|
75
|
+
"@types/bun": "1.4.5",
|
|
75
76
|
"@types/write-file-atomic": "4.0.3",
|
|
76
|
-
"@vitest/coverage-v8": "5.1.
|
|
77
|
-
"eslint": "10.
|
|
78
|
-
"jsdom": "^31.0.
|
|
79
|
-
"prettier": "3.
|
|
80
|
-
"svelte": "5.
|
|
77
|
+
"@vitest/coverage-v8": "5.1.2",
|
|
78
|
+
"eslint": "10.16.0",
|
|
79
|
+
"jsdom": "^31.0.1",
|
|
80
|
+
"prettier": "3.10.1",
|
|
81
|
+
"svelte": "5.59.2",
|
|
81
82
|
"typescript": "6.0.3",
|
|
82
|
-
"typescript-eslint": "8.
|
|
83
|
-
"vitest": "5.1.
|
|
83
|
+
"typescript-eslint": "8.74.0",
|
|
84
|
+
"vitest": "5.1.2"
|
|
84
85
|
},
|
|
85
86
|
"overrides": {
|
|
86
87
|
"cross-spawn": "7.1.2"
|
package/src/cleanup.ts
CHANGED
package/src/config/initial.ts
CHANGED
|
@@ -4,18 +4,33 @@
|
|
|
4
4
|
* 配置文件是唯一来源:缺文件时先落一份默认配置,主人改掉需要的那几项即可,
|
|
5
5
|
* 不然插件只能拒绝启动。
|
|
6
6
|
*/
|
|
7
|
-
import { DEFAULT_CONFIG } from "./registry"
|
|
8
7
|
|
|
9
8
|
/** 新装时写进配置文件的 NapCat 地址:NapCat 默认监听的 WebSocket 端口。 */
|
|
10
9
|
export const INITIAL_NAPCAT_URL = "ws://127.0.0.1:3001"
|
|
11
10
|
|
|
11
|
+
/**
|
|
12
|
+
* 配置文件里始终保留的路径。
|
|
13
|
+
*
|
|
14
|
+
* 这几项是主人上手要填的:留在文件里,配置文件自己就说明了该改哪几处。
|
|
15
|
+
*/
|
|
16
|
+
export const TEMPLATE_PATHS: readonly string[] = [
|
|
17
|
+
"ownerQQ",
|
|
18
|
+
"napcat.url",
|
|
19
|
+
"access.allow.groups",
|
|
20
|
+
"access.allow.users",
|
|
21
|
+
]
|
|
22
|
+
|
|
12
23
|
/**
|
|
13
24
|
* 生成初始配置内容。
|
|
14
25
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
26
|
+
* 只写主人要填的几项,其余交给注册表里的默认值:
|
|
27
|
+
* 默认值以后调整,已经装好的机器也得跟着变。
|
|
28
|
+
* `ownerQQ` 写 `null` 表示「还没填」,解析时按未配置处理。
|
|
17
29
|
*/
|
|
18
30
|
export function initialConfig(): Record<string, unknown> {
|
|
19
|
-
|
|
20
|
-
|
|
31
|
+
return {
|
|
32
|
+
ownerQQ: null,
|
|
33
|
+
napcat: { url: INITIAL_NAPCAT_URL },
|
|
34
|
+
access: { allow: { groups: [], users: [] } },
|
|
35
|
+
}
|
|
21
36
|
}
|
package/src/config/live.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto"
|
|
2
2
|
import { applyHotFields, resolveConfig, type ConfigWarning, type QQBotConfig } from "../config"
|
|
3
3
|
import { CONFIG_FIELDS } from "../config/fields"
|
|
4
|
-
import { requiredFieldProblem } from "../config/registry"
|
|
5
|
-
import { initialConfig } from "./initial"
|
|
4
|
+
import { pruneDefaultEntries, requiredFieldProblem } from "../config/registry"
|
|
5
|
+
import { initialConfig, TEMPLATE_PATHS } from "./initial"
|
|
6
6
|
import type { Logger } from "../logger"
|
|
7
7
|
import { ConfigMissingError, type ConfigPatch, type ConfigStore } from "./store"
|
|
8
8
|
|
|
@@ -74,11 +74,32 @@ export class ConfigController {
|
|
|
74
74
|
*/
|
|
75
75
|
async load(): Promise<QQBotConfig> {
|
|
76
76
|
this.raw = await this.readOrCreate()
|
|
77
|
+
this.raw = await this.pruneDefaults(this.raw)
|
|
77
78
|
this.config = this.resolve(this.raw)
|
|
78
79
|
await this.ensureSecrets()
|
|
79
80
|
return this.config
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
/**
|
|
84
|
+
* 把配置文件里与默认值相同的项删掉并落盘。
|
|
85
|
+
*
|
|
86
|
+
* 配置文件只留主人改过的值:默认值以后调整,已经装好的机器也跟着变。
|
|
87
|
+
* 写不进去只告警:这一份配置照常用,只是默认值暂时传不过来。
|
|
88
|
+
*/
|
|
89
|
+
private async pruneDefaults(raw: Record<string, unknown>): Promise<Record<string, unknown>> {
|
|
90
|
+
const pruned = pruneDefaultEntries(raw, TEMPLATE_PATHS)
|
|
91
|
+
if (JSON.stringify(pruned) === JSON.stringify(raw)) return raw
|
|
92
|
+
try {
|
|
93
|
+
await this.options.store.write(pruned)
|
|
94
|
+
} catch (error) {
|
|
95
|
+
this.warn(
|
|
96
|
+
`配置文件精简失败,继续沿用原文件:${error instanceof Error ? error.message : String(error)}`,
|
|
97
|
+
)
|
|
98
|
+
return raw
|
|
99
|
+
}
|
|
100
|
+
return pruned
|
|
101
|
+
}
|
|
102
|
+
|
|
82
103
|
/**
|
|
83
104
|
* 读配置文件;文件不存在时先生成一份默认配置。
|
|
84
105
|
*
|
package/src/config/registry.ts
CHANGED
|
@@ -462,6 +462,60 @@ export function warnUnknownFileKeys(raw: Record<string, unknown>, warn: ConfigWa
|
|
|
462
462
|
walk(raw, "")
|
|
463
463
|
}
|
|
464
464
|
|
|
465
|
+
/**
|
|
466
|
+
* 删掉配置文件里与默认值相同的项。
|
|
467
|
+
*
|
|
468
|
+
* 配置文件只保留主人改过的值:默认值以后调整,已经装好的机器也跟着变。
|
|
469
|
+
* `keep` 里的路径原样留下,首次启动生成的模板就靠它们提示主人该填哪几项。
|
|
470
|
+
*/
|
|
471
|
+
export function pruneDefaultEntries(
|
|
472
|
+
raw: Record<string, unknown>,
|
|
473
|
+
keep: readonly string[] = [],
|
|
474
|
+
): Record<string, unknown> {
|
|
475
|
+
const kept = new Set(keep)
|
|
476
|
+
const result = structuredClone(raw) as Record<string, unknown>
|
|
477
|
+
for (const field of CONFIG_FIELDS) {
|
|
478
|
+
if (field.default === undefined) continue
|
|
479
|
+
if (kept.has(field.path)) continue
|
|
480
|
+
const value = getConfigValue(result, field.path)
|
|
481
|
+
if (value === undefined) continue
|
|
482
|
+
if (!sameValue(value, field.default)) continue
|
|
483
|
+
deletePath(result, field.path)
|
|
484
|
+
}
|
|
485
|
+
return result
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/** 值是否与默认值相同:数组逐项比较,其余按引用比。 */
|
|
489
|
+
function sameValue(left: unknown, right: unknown): boolean {
|
|
490
|
+
if (left === right) return true
|
|
491
|
+
if (!Array.isArray(left) || !Array.isArray(right)) return false
|
|
492
|
+
return left.length === right.length && left.every((item, index) => sameValue(item, right[index]))
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** 删掉一个路径,顺手清掉因此变空的上层对象。 */
|
|
496
|
+
function deletePath(target: Record<string, unknown>, path: string): void {
|
|
497
|
+
const segments = path.split(".")
|
|
498
|
+
const parents: Array<{ parent: Record<string, unknown>; key: string }> = []
|
|
499
|
+
let current = target
|
|
500
|
+
for (const segment of segments.slice(0, -1)) {
|
|
501
|
+
const child = current[segment]
|
|
502
|
+
if (!child || typeof child !== "object" || Array.isArray(child)) return
|
|
503
|
+
parents.push({ parent: current, key: segment })
|
|
504
|
+
current = child as Record<string, unknown>
|
|
505
|
+
}
|
|
506
|
+
const leaf = segments[segments.length - 1]
|
|
507
|
+
if (leaf === undefined) return
|
|
508
|
+
delete current[leaf]
|
|
509
|
+
for (let index = parents.length - 1; index >= 0; index -= 1) {
|
|
510
|
+
const entry = parents[index]
|
|
511
|
+
if (!entry) continue
|
|
512
|
+
const child = entry.parent[entry.key]
|
|
513
|
+
if (!child || typeof child !== "object" || Array.isArray(child)) break
|
|
514
|
+
if (Object.keys(child).length > 0) break
|
|
515
|
+
delete entry.parent[entry.key]
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
465
519
|
/** 注册表里声明为热更新的字段。 */
|
|
466
520
|
export const HOT_FIELDS: readonly ConfigField[] = CONFIG_FIELDS.filter((field) => field.hot)
|
|
467
521
|
|