@linjz/opencode-qqbot 0.3.15 → 0.3.16
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 +42 -5
- package/bin/openqq.js +13 -0
- package/dist/notify-cli.js +28 -14
- package/dist/opencode-qqbot-plugin.js +934 -64
- package/dist/openqq-bot.js +3095 -677
- package/dist/openqq-cli.js +791 -0
- package/dist/openqq-watchdog.js +1063 -0
- package/package.json +8 -5
- package/src/bridge.ts +1310 -150
- package/src/cli/notify.ts +167 -158
- package/src/cli/openqq-main.ts +95 -0
- package/src/cli/service-main.ts +302 -0
- package/src/cli/watchdog-main.ts +77 -0
- package/src/commands.ts +644 -554
- package/src/config.ts +85 -0
- package/src/core/bot-control.ts +148 -0
- package/src/core/bot-launcher.ts +106 -13
- package/src/core/card-approval.ts +20 -9
- package/src/core/delivery.ts +145 -54
- package/src/core/discovery.ts +22 -4
- package/src/core/file-log.ts +35 -3
- package/src/core/form-bridge.ts +14 -5
- package/src/core/form-journal.ts +4 -4
- package/src/core/gateway-state.ts +3 -3
- package/src/core/inflight-journal.ts +214 -36
- package/src/core/instance-lock.ts +10 -2
- package/src/core/linkwatch.ts +3 -4
- package/src/core/markdown.ts +117 -0
- package/src/core/message-queue.ts +242 -91
- package/src/core/mirror.ts +222 -182
- package/src/core/notify-sink.ts +93 -96
- package/src/core/outbox.ts +10 -9
- package/src/core/permission.ts +627 -303
- package/src/core/question-form.ts +230 -0
- package/src/core/queue-view.ts +661 -0
- package/src/core/send-media.ts +32 -0
- package/src/core/storage.ts +34 -0
- package/src/core/watchdog.ts +513 -0
- package/src/core/zombie-reaper.ts +127 -0
- package/src/index.ts +140 -52
- package/src/opencode/client.ts +206 -27
- package/src/opencode/eventstream.ts +94 -12
- package/src/opencode/history.ts +4 -2
- package/src/opencode/mirror.ts +15 -2
- package/src/opencode/sessions.ts +135 -37
- package/src/plugin-entry.ts +120 -115
- package/src/qq/api.ts +165 -61
- package/src/qq/gateway.ts +79 -16
- package/src/qq/sender.ts +30 -18
- package/src/qq/types.ts +7 -0
package/src/core/outbox.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// @input: fs/path/os/crypto + ../qq/types(MessageContext)
|
|
1
|
+
// @input: fs/path/os/crypto + ../qq/types(MessageContext)
|
|
2
2
|
// @output: createOutbox 及 Outbox 公共类型、保留/退避常量、pruneOutboxEntries
|
|
3
3
|
// @pos: core - 独立持久化出站 Outbox(先落账后发送,至少一次恢复)
|
|
4
4
|
//
|
|
5
5
|
// 文件格式:{ "version": 1, "entries": OutboxEntry[] }。所有 mutation 都在
|
|
6
6
|
// <outbox>.lock 短文件锁内重新读盘,再经临时文件 + rename 原子替换。
|
|
7
7
|
// 网络 handler 不持文件锁;sending + leaseOwner/leaseUntil 防跨进程并发双发。
|
|
8
|
+
import { storageFile } from "./storage.js"
|
|
8
9
|
import {
|
|
9
10
|
closeSync,
|
|
10
11
|
existsSync,
|
|
@@ -16,8 +17,7 @@ import {
|
|
|
16
17
|
unlinkSync,
|
|
17
18
|
writeFileSync,
|
|
18
19
|
} from "node:fs"
|
|
19
|
-
import {
|
|
20
|
-
import { dirname, join } from "node:path"
|
|
20
|
+
import { dirname } from "node:path"
|
|
21
21
|
import { randomUUID } from "node:crypto"
|
|
22
22
|
import type { MessageContext } from "../qq/types.js"
|
|
23
23
|
|
|
@@ -106,7 +106,8 @@ export interface Outbox {
|
|
|
106
106
|
recover(options?: { ignoreLeases?: boolean; maxAttempts?: number }): Promise<OutboxRecoverResult>
|
|
107
107
|
/** 扫描 pending/failed;默认只处理 nextAttemptAt 已到期的项。 */
|
|
108
108
|
flush(options?: OutboxFlushOptions): Promise<OutboxEntry[]>
|
|
109
|
-
start
|
|
109
|
+
/** start 的 maxAttempts 会透传 recover/flush:失败达到该次数后保持 failed,不再无限重试。 */
|
|
110
|
+
start(options?: { recover?: boolean; maxAttempts?: number }): Promise<void>
|
|
110
111
|
/** 停止定时器,不等待正在发送的 handler;需要等待时调用 drain。 */
|
|
111
112
|
stop(): void
|
|
112
113
|
/** 等待当前及等待期间新启动的本实例发送全部结束。 */
|
|
@@ -207,7 +208,7 @@ export function pruneOutboxEntries(entries: OutboxEntry[], now = Date.now()): Ou
|
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
export function createOutbox(options: OutboxOptions = {}): Outbox {
|
|
210
|
-
const filePath = options.filePath ?? process.env.QQ_OUTBOX_FILE ??
|
|
211
|
+
const filePath = options.filePath ?? process.env.QQ_OUTBOX_FILE ?? storageFile("outbox.json")
|
|
211
212
|
const pollIntervalMs = nonNegative(options.pollIntervalMs, DEFAULT_POLL_INTERVAL_MS, "pollIntervalMs")
|
|
212
213
|
const retryBaseMs = nonNegative(options.retryBaseMs, OUTBOX_DEFAULT_RETRY_BASE_MS, "retryBaseMs")
|
|
213
214
|
const retryMaxMs = nonNegative(options.retryMaxMs, OUTBOX_DEFAULT_RETRY_MAX_MS, "retryMaxMs")
|
|
@@ -494,16 +495,16 @@ export function createOutbox(options: OutboxOptions = {}): Outbox {
|
|
|
494
495
|
dispatch,
|
|
495
496
|
recover,
|
|
496
497
|
flush,
|
|
497
|
-
async start(startOptions = {}) {
|
|
498
|
+
async start(startOptions: { recover?: boolean; maxAttempts?: number } = {}) {
|
|
498
499
|
stopped = false
|
|
499
|
-
if (startOptions.recover !== false) await recover()
|
|
500
|
+
if (startOptions.recover !== false) await recover({ maxAttempts: startOptions.maxAttempts })
|
|
500
501
|
if (pollIntervalMs === 0 || timer) return
|
|
501
502
|
timer = setInterval(() => {
|
|
502
503
|
if (stopped) return
|
|
503
|
-
void flush().catch(() => { /* 下轮继续;失败已持久化 */ })
|
|
504
|
+
void flush({ maxAttempts: startOptions.maxAttempts }).catch(() => { /* 下轮继续;失败已持久化 */ })
|
|
504
505
|
}, pollIntervalMs)
|
|
505
506
|
timer.unref?.()
|
|
506
|
-
void flush().catch(() => { /* 下轮继续 */ })
|
|
507
|
+
void flush({ maxAttempts: startOptions.maxAttempts }).catch(() => { /* 下轮继续 */ })
|
|
507
508
|
},
|
|
508
509
|
stop() {
|
|
509
510
|
stopped = true
|