codex/async-sqlite-node24
320
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
f65fe959bb |
fix(send-private): split c2c file segments out to sendC2cFileMessage (was shipping "[空消息]")
User report: `send_private_msg` with a `{type:'file', file_id}` segment
fired `[ElemBuilder] file send via elems[] is group-only; use bridge.
sendC2cFileMessage for c2c` and the message went out as "[空消息]".
Root cause: c2c files live on `RichText.notOnlineFile` (parallel to the
elems array, see proto/proton/message.ts), not inside `elems[]`. The
element-builder explicitly drops c2c `{type:'file'}` elements with a
warning. `sendPrivateMessage` was passing the file straight to
`bridge.sendPrivateMessage(userId, [fileElement])` which then ran
through `buildSendElems`, lost the file at the drop, and shipped a
0-element wire send — rendered as "[空消息]" by every receiver.
Fix: split at the OneBot layer in `sendPrivateMessage`. Pull file
elements out of the batch and dispatch each via
`bridge.sendC2cFileMessage`; route the rest through the regular
elems[] path. Matches NapCat's `dev/NapCatQQ/.../SendMsg.ts:404-415`
where FILE / VIDEO / ARK / PTT each get their own sendMsg call and
never mix with the regular elems[] batch.
- File-only message: only the c2c file API is called (single roundtrip)
- Mixed text + file: two sends, text first then file
- File without file_id: dropped with a warn (was silently shipping
empty messages)
- UID resolution failure: surfaced as throw instead of empty send
Also rewrote the element-builder fallback warn from "use
sendC2cFileMessage for c2c" (now stale advice) to "BUG: c2c file
reached element-builder — should be split out at the OneBot layer".
Tests: 4 new regression cases under
`tests/onebot/send-private-c2c-file.test.ts`. 646/646 pass.
|
||
|
|
cec38b4c1b |
fix(forward): piggyback every nested level onto the outermost long-msg upload (NapCat model)
Cross-referenced `dev/NapCatQQ/.../SendMsg.uploadForwardedNodesPacket`
(208-347): every layer of a nested forward attaches its own msgBody to
the *outer* long-msg upload under a uuid `actionCommand` slot. Receiver
walks the whole tree from one server fetch instead of resolving each
layer's res_id separately.
`dev/Lagrange.Core` (V2 branch on `linwenxuan04/v2`,
`MultiMsgUploadService.cs:23-31`) only writes a single MultiMsg action
— that's why NapCat-style receivers couldn't follow our previous
nested-forward sends past the first level.
Refactor:
1. `ForwardNodePayload` gets an optional `innerForward?:
ForwardNodePayload[]` field. `parseForwardNodes` no longer eagerly
uploads inner chains — it just attaches them here.
2. `uploadForwardNodes` now drives the whole recursion. The new
`uploadForwardNodesRecursive`:
- walks each node, recursively uploads any `innerForward` first
- replaces that node's `elements` with a real `{type:'forward'}`
preview pointing at the inner res_id
- piggybacks the inner level's `{uuid, msgBody}` + every deeper
level it surfaced into this level's `myInnerActions`
- encodes the long-msg payload as
`[{MultiMsg, ownMsgBody}, ...innerActions.map(uuid+msgBody)]`
- returns `{resId, msgBody, uuid, innerActions}` so an outer call
can keep climbing
Top-level public signature unchanged: `Promise<string>`.
3. New `deriveInnerSource` / `previewLinesFromNodes` /
`previewFromElements` helpers synthesise the ARK preview metadata
the inner bubble shows before the user taps to expand. They handle
text/image/record/video/file/forward/face element previews.
4. `parseForwardNodes`: when `content` is an all-node array, attach
the parsed inner chain to `node.innerForward` and let the upload
pipeline take over. `elements = []` placeholder is replaced by
`uploadForwardNodes` once it has the real res_id.
Tests:
- `actions/forward.test.ts`:
- `uploadForwardNodes recursively uploads nested innerForward chains
(NapCat piggyback model)` — asserts two SsoSendLongMsg roundtrips
(inner first, then outer) and the outer res_id propagates up
- `flat sends still take a single roundtrip` — backwards-compat
- `onebot/forward-nested.test.ts`: rewritten — mock now sees exactly
one `uploadForwardNodes` call with `innerForward` attached, instead
of two sequential calls; depth-limit + mixed-content tests
unchanged.
|
||
|
|
0b8dc1f7af |
fix(video): populate NTV2 fileInfo.time with the real duration (receiver was rendering 00:00)
The NTV2 upload request for video carried `time: 0` on the main mp4 sub-file, mirroring NapCat's transformer. But NapCat lives on top of the desktop QQ-NT client's IPC layer, which patches the duration into the resulting MsgInfo before the wire send — we don't have that layer, so the `time: 0` we passed in ended up baked into the `VideoFile. fileTime` field of every video the bot sent. Receivers then rendered every video bubble as "00:00". Cross-checked acidify's `RichMediaUpload.kt::buildVideoUploadInfoList` (2026-04 refactor) — they're a protocol-direct client too and write `time = payload.videoDuration` for exactly this reason. We already have `video.duration` from `loadVideo` (probed via ffprobe), so it's a one-liner. Width/height kept at 0 deliberately — acidify fills them, NapCat zeros them, and our earlier comment recorded "QQ NT server treats non-zero values here as schema mismatch on c2c sends". Out of scope for this fix; revisit if a c2c regression surfaces. Test asserts `fileInfo.time === 10` for the main sub-file (matches FINGERPRINT.duration) and stays 0 on the thumb. |
||
|
|
8f839f4f30 |
fix(group-file): correct GroupFileExtra wire shape — server was rejecting with result=79
Two off-by-one bugs in the group-file chat-post element that combined to make the QQ-NT server reject every group file send with result=79 (visible as "group file uploaded but chat post failed" in the logs): 1. Inner GroupFileInfo fields were shifted one tag left: - fileSha was field 5, should be field 6 - extInfo was field 6, should be field 7 - fileMd5 was field 7, should be field 8 Field 5 is actually a uint32 placeholder (`field5` in both NapCat and acidify). With the bug, our fileSha bytes were landing where the server expected a varint and the rest of the message got skipped as garbage. 2. Outer GroupFileExtra was missing the magic field1=6 + fileName slots that NapCat's encoder writes (`packet/message/element.ts:589`). Acidify's schema also models them as required even though it serialises with defaults. The current server build rejects sends without these slots populated. Cross-referenced: - NapCat `GroupFileExtraInfo` (component.ts:146-155) — matches our new field numbers exactly - acidify `GroupFileExtra.Inner.Info` (proto/message/extra/GroupFileExtra.kt) — same field numbers; their schema uses generic `field5`/`field7` names but the wire layout is identical Changes: - Proton + legacy schemas: shift inner fields, add outer field1/ fileName/display - `makeGroupFileElem`: write field1=6 + fileName on the outer wrapper - Regression test asserts each inner tag lands at 50/58/66 (not the old 42/50/58) and verifies the new outer field1 + fileName bytes are present |
||
|
|
04a905460b |
fix(file-upload): read upload host from rtpMediaPlatformUploadAddress (NT 2026 rollout)
The 2026 QQ-NT server has stopped populating *every* legacy host field (uploadIp / uploadDomain / uploadIpList / uploadHttpsDomain / uploadDns). The host now arrives in the new field 210 `rtpMediaPlatformUploadAddress` — a repeated `IPv4` message carrying `inIP`/`inPort` (LAN) and `outIP`/`outPort` (WAN). Coworker's debugging hint "host 好像是 fix64" was the 8-12-byte length-delimited IPv4 message looking like a fixed-width field on the wire. Cross-referenced acidify (https://github.com/LagrangeDev/acidify) — the only NT-protocol fork that's tracked this change (refactored in their 2026-04 protobuf rewrite). They read `inIP`+`inPort` exclusively because that's the address the highway PUT actually needs to reach (same DC as the OIDB endpoint). LagrangeGo / Lagrange.Core / NapCat still ship the old schema and would fail the same way against this server build. Changes: - Proton schema: add `IPv4` message (fields 1-5: outIP/outPort/inIP/ inPort/iPType, all int32 varint) + field 210 on the upload response - Consumer: prefer `rtpMediaPlatformUploadAddress[0].inIP`+`inPort` before falling back through the legacy host chain - New helper `int32ToIpv4Dotted` reverses acidify's `Int.toIpString()` (little-endian byte order, `>>>` for unsigned shift so high-bit IPs don't render as negative octets) - Diagnostic warn-log now dumps the rtp address array too - Regression test: 192.168.1.1 (LE-packed 0x0101A8C0 = 16885952) + inPort=8080 should reach highway PUT |
||
|
|
87ac6ffedb |
fix(file-upload): fall back through parallel host fields when uploadIp is empty
User report: `upload_private_file` was failing with "private file upload host is invalid" on a fresh upload (boolFileExist=false). The OIDB call succeeded but `uploadIp` (field 60) came back empty, and we treated that single field as the only source of truth. Cross-referenced LagrangeGo's `OidbSvcTrpcTcp0xE37_800.proto` + NapCat's `Oidb.0XE37_800.ts`: the server has six parallel host slots on this response (uploadIp / uploadDomain / uploadIpList[0] / uploadHttpsDomain / uploadDns / uploadLanip). LagrangeGo + Lagrange.Core only read field 60 and would hit the same dead-end — we walk the chain instead. Also log the full slot set when we genuinely can't find a host so future reports can name which field the server actually populated. Adds two regression tests: one proves the fallback to `uploadDomain` goes to highway successfully, one proves we still throw when every slot is empty. |
||
|
|
898898a507 |
feat(msg-push): handle three friend-related events we used to drop on the floor
Close three coverage gaps surfaced by the cross-Lagrange-family
audit (Lagrange V2 / LagrangeGo / acidify / lagrange-python):
- **0x210 subType 179 + 226 (NewFriend)** — mutual-accept friend
notice. 179 fires when bot sent a request and the other side
accepted; 226 fires for the opposite direction. Both decode
through the same wire shape. LagrangeGo handles the pair via a
`case 226: case 179:` fallthrough in `client/listener.go:248`.
We surface them as `kind: 'friend_add'`, which the existing
converter routes straight to OneBot `notice.friend_add` — bot
frameworks that wait for "auto-add a friend after they accept"
were previously stuck because nothing arrived.
- **0x210 subType 139 (self-recall)** — bot recalled its own
message sent to a friend. Same `FriendRecall` wire shape as 138
but the peer is on `toUid` instead of `fromUid` — acidify's
`parseFriendRecall:380` splits exactly this way. Without 139,
self-recalls disappeared and downstream `notice.friend_recall`
handlers thought the bot had never recalled anything.
- **PkgType 85 (bot self-joined a group)** — fires on the bot's
session once `set_group_add_request` is approved or an invite is
accepted, ported from lagrange-python's `server_push/msg.py:108`.
PkgType 33 (GroupMemberIncreaseNotice) only fires for *other*
members joining, so without 85 the bot never received its own
`notice.group_increase` until the first message arrived. We
decode `SelfJoinInGroup` and emit `kind: 'group_member_join'`
with `userUin = selfUin`; the existing converter picks
`sub_type: 'approve' | 'invite'` from the operator/user equality
so consumers see the standard OneBot shape.
While wiring 139, also fix a *pre-existing* prod bug spotted via
proton call-site analysis on the resulting bundle: `event-0x210.ts`
imported `FriendRecall` from both `proto/proton/notify` (as
`FriendRecallNotify`) *and* `events` (as the event interface).
Proton's import-resolver registers `importedTypeSources` keyed on
the *imported* name (last-write-wins), so the events.ts import
shadowed the proto one — `protobuf_decode<FriendRecall>(...)` lost
its codec, fell through to the runtime fallback throw, and was
silently swallowed by `MsgPushRegistry.decode`'s catch. Verified by
the substituted codec list in `dist/index.mjs`: pre-fix it had
`FriendRequest` / `GeneralGrayTipInfo` but no `FriendRecall`;
post-fix `FriendRecall` / `NewFriend` / `SelfJoinInGroup` are all
emitted as expected. Side-step the collision by importing the
proto types unaliased and re-deriving the colliding event type via
`Extract<QQEventVariant, { kind: 'friend_recall' }>`.
New proto interfaces in `proto/proton/notify.ts`:
- `NewFriend` + `NewFriendInfo` (uid/time/message/nickName fields,
fields 1-9; ported from
`LagrangeGo/.../notify.proto:25 NewFriend`)
- `SelfJoinInGroup` (groupUin / operatorUid + a few placeholder
fields; ported from
`lagrange-python/pb/status/group.py:170 PBSelfJoinInGroup`)
Regression coverage in `tests/msg-push-handler.test.ts`:
- subType 179/226 both produce identical friend_add events
- falls back to `routingHead.fromUin` when the new friend's uid
isn't in the local cache (matches LagrangeGo's
"emit-then-resolve" pattern)
- subType 138 keeps fromUid as the peer (other recalled their
own msg to us); subType 139 picks toUid (we recalled ours
sent to them)
- PkgType 85 emits group_member_join with userUin == selfUin,
operator resolved through identity when known
core: 635/635 tests pass (+7), typecheck clean. Production bundle
now contains substituted codecs for FriendRecall, NewFriend,
SelfJoinInGroup (cross-checked via `grep protobuf_decode_X` on
`dist/index.mjs`).
|
||
|
|
604dbc3f64 |
fix(msg-push): Event0x210 subType=38 is the troop-shortcut-bar push, not friend-related
Earlier this commit acknowledged subType 38 as a placeholder
"FriendGrayTipInfo" because none of the LagrangeDev-family projects
(Lagrange V2 / lagrange-python / LagrangeGo / acidify) have a
handler for it — they all just fall through with a generic
"unknown subType" debug log. The "best guess" gray-tip framing was
wrong.
A contributor traced it through the decompiled stock QQ Android
client to `com.tencent.imcore.message.ext.codec.decoder.msgType0x210
.SubType0x26` (tsuzcx/qq_apk @ afe46ef). The payload is
`submsgtype0x26.MsgBody` dispatching on `uint32_sub_cmd`:
- 0x1 → `UpdateAppUnreadNum`: a list of
`{group_code, app_id, unread_num}` keeping group-internal
"mini-app" badge counts (e.g. `appId=101846662` / `101896870`
for the troop shortcut bar) in sync.
- 0x3 → `UpdateDiscussAppInfo`: `{conf_uin, app_tip_notify.text}`
discussion-group app tips, routed through `getGAudioHandler()`.
- 0x4 → delegated to the troop online-push handler.
None of these have a meaningful OneBot mapping — they're
QQ-client-UI state pushes (badge counts, in-app tips), not
conversation events. Rename the enum entry to `GroupAppStatePush`
to reflect the actual semantics, cite the decompiled source
inline, and keep the silent-drop behaviour from the previous
attempt. Tests + decoder routing follow the rename.
628/628 tests pass (unchanged), typecheck clean.
|
||
|
|
ff5fc651d0 |
fix(tests): declare full vi.fn arg signatures so CI typecheck doesn't trip on tuple length
CI's `tsc --noEmit` was rejecting `forward-nested.test.ts` because the `vi.fn(async () => 'RES')` mocks for `bridge.uploadForwardNodes` only inferred zero or one arg from the lambda — so `uploadForwardNodes.mock.calls[0]` came out typed as `[]` or `[nodes: any[]]`, and indexing `[1]` / `[2]` for groupId / userId hit `Tuple type ... has no element at index 'N'`. Local `tsc --noEmit` happened to be looser about this in my version, which is why the bad assertions slipped past `e637647`. Declare the full 3-arg signature on every `uploadForwardNodes` mock — `(_nodes, _groupId?, _userId?)` — matching the real `Bridge.uploadForwardNodes` contract. `mock.calls[i]` now types as a 3-tuple, the index accesses check out, and the assertions stay unchanged. No production code touched, no test behaviour change. 626/626 still passing, typecheck clean. |
||
|
|
c758eb6569 |
fix(onebot): recursively parse nested forward chains (node-inside-node)
A custom forward node's `content` field can itself be a list of
`{type:'node'}` entries — that's the nested-forward case where one
forward bubble contains another. `parseForwardNodes` used to pass
the whole `content` straight into `parseMessage`, which routed
each inner `{type:'node'}` through `message-parser.ts:217 case
'node':` and turned them into opaque
`MessageElement{type:'node', resId: JSON.stringify(content)}`
placeholders. `element-builder.buildSendElems` then dropped those
at its default branch — so the outer forward shipped with either
zero elements (pure-nested → server rejects with "message is
empty") or text-only elements (mixed content → silently truncated
chat bubble). User-facing symptom: "嵌套转发解析后发不出去".
Add depth-aware recursion to `parseForwardNodes`, modelled on
NapCat's `SendMsg.uploadForwardedNodesPacket` (3-level cap):
- When a node's `content` is *all* `{type:'node'}` entries,
recurse: parse the inner chain into ForwardNodePayload[],
upload it via `bridge.uploadForwardNodes` to mint an
inner res_id, then embed a `{type:'forward', resId}` element
in the outer node. The receive-side rendering pipeline already
builds the ARK preview card for that element shape, so the
QQ client renders a tap-to-expand nested bubble.
- Mixed content (text + node siblings) deliberately stays on the
flat path — the meaning is ambiguous, and forcing a recursion
would silently drop the non-node siblings.
- Hard cap at depth 3; deeper attempts throw "depth exceeds 3".
Matches NapCat and prevents one slow inner upload from
aborting an unreasonably deep tree.
Threading: each forward send entry point passes its destination
into the parser (`{groupId}` from group-send, `{userId}` from
private-send) so the inner forward uploads against the same
res_id namespace.
Test coverage in `tests/onebot/forward-nested.test.ts`:
- group: inner uploads first, outer wraps inner res_id in a
forward element, both calls happen in order
- private: c2c path threads userId (not groupId) into the
inner uploadForwardNodes
- depth cap rejects 4-level nesting with /depth/
- flat (non-nested) content still uploads exactly once
- mixed content stays on the legacy parseMessage path
core: 626/626 tests pass (+5), typecheck clean, prod build clean.
|
||
|
|
10154cfbff |
fix(onebot): parse {type:'file', file_id:'…'} segments instead of dropping them
The companion to `e637647`. That commit fixed
`upload_group_file` / `upload_private_file` to publish the file as
a chat message atomically (matching napcat). This one fixes the
OTHER half of the same bug: when a bot framework does
send_msg([{type:'file', file_id:'<previously uploaded>'}])
— attaching an already-uploaded file as a message segment — the
parser used to fall through to its default warn-and-drop branch
(`message-parser.ts:340`). The dropped segment then either:
- became "message is empty" if it was the only segment, or
- silently disappeared if it shared the payload with text,
producing a chat bubble missing the file.
Adds a `case 'file':` that maps the OneBot segment shape to the
existing `MessageElement{type:'file', fileId, fileName, fileSize,
md5Hex, sha1Hex}` that `element-builder` already knows how to
emit as `TransElem(24)`. Accepts the common alias spellings
(`file_id`/`fileId`, `name`/`filename`/`fileName`,
`size`/`fileSize`, `md5`/`md5Hex`, `sha1`/`sha1Hex`).
Deliberately rejects `{file: '/path'}` form — kicking off an
upload from inside the synchronous parser would either swallow
errors or restructure the whole parseMessage signature, neither
worth it. Callers wanting upload-and-send should keep using
`upload_group_file` / `upload_private_file`, which now does both
atomically.
core: 621/621 tests pass (+3), typecheck clean.
|
||
|
|
e637647877 |
fix(bridge): publish uploaded files as chat messages (the "empty message" bug)
`upload_group_file` / `upload_private_file` used to do only the
upload half of the napcat-equivalent flow:
OIDB 0x6D6_0 alloc → highway PUT → return fileId
The fileId was real, the bytes were on QQ's CDN, the logs said
"uploaded" — but the chat showed nothing because no message was
ever sent referring to the upload. NapCat's `UploadGroupFile`
action (`dev/napcatQQ/.../UploadGroupFile.ts:54-58`) does the
upload AND immediately calls `MsgApi.sendMsg(peer, [fileElement])`
in the same action; that second step is what makes the file
visible in the chat.
Add the missing send step. Two paths because the wire shape
differs:
- **Group files** ride on `Elem.transElem` (type 24) in the
`RichText.elems` array. Add a `makeGroupFileElem()` helper +
`case 'file':` in `element-builder.buildSendElems`, then
`bridge.sendGroupMessage(groupId, [fileElement])` after a
successful upload. The TransElem wraps a `GroupFileExtra`
protobuf in `0x01 | BE16(len) | payload`, byte-symmetric with
the receive-side decoder at `rich-body-decoder.ts:171-185`.
- **C2C (private) files** live on `RichText.notOnlineFile`
(field 3 on RichText, parallel to `elems`), so they can't go
through `buildSendElems` at all. Add `Bridge.sendC2cFileMessage`
that builds the `SendMessageRequest` with `notOnlineFile`
directly and dispatches via `sendRawPacket`. The decoder side
that lifts these back to `{type:'file'}` segments has lived
at `rich-body-decoder.ts:425-433` the whole time.
Behavioural detail: both upload paths call the chat-publish step
*only* when `uploadFile=true` (the default). `uploadFile=false`
keeps the upload-only semantics for callers that just want a
fileId without dropping a message in the chat. If the chat post
fails for any reason (server rejection / network), the action
still returns the fileId with a warning log — the file is on QQ's
side, callers can re-publish if they want.
Regression coverage in `tests/actions/group-file.test.ts`:
- publishes the file as `{type:'file'}` via sendGroupMessage on
group upload
- skips the post when uploadFile=false
- returns success even when the chat post fails
- same trio for private upload going through sendC2cFileMessage
- and confirms private path does NOT route through the
`sendPrivateMessage` elems[] pipeline
core: 618/618 tests pass (+5), typecheck clean. Production build
contains 8 substituted call sites for the new GroupFileExtra +
SendMessageRequest paths under proton.
|
||
|
|
d821336943 |
fix(onebot): hot-reload HTTP server accessToken without re-binding
`HttpServerAdapter.startServer` baked `accessToken` into the
`createServer` callback's closure, then relied on
`bindingSignature` including the token to trigger a
`close()`+`open()` round-trip on every change. Two problems:
1. The three sibling adapters (`ws-server`, `http-post`,
`ws-client`) all read `this.config.accessToken` inline at the
point of use, so the HTTP-server's closure-capture pattern was
the odd one out.
2. `server.close()` is asynchronous; the immediately-following
`server.listen()` on the same port can race with the OS
releasing it. When it loses, the new listener fails with
EADDRINUSE (logged via `server.on('error', …)` but not bubbled
up), the old server is gone, and the operator's `reload` looks
successful while the endpoint is actually broken — which lines
up with the "token didn't hot-reload" reports.
Drop the closure capture: `handleRequest` reads
`this.config.path` and `this.config.accessToken` fresh per request
(`reload()` already replaces `this.config` in place via
`structuredClone(next)`). Remove `accessToken` from
`bindingSignature` so a token change no longer triggers a port
re-bind. `host`/`port`/`path` stay in the signature because Node's
`Server.listen()` binds the socket on those.
Four hot-reload tests pin the new contract: token swap, clearing
to empty, setting from empty, and "token-only change returns
`NetworkReloadType.Normal`" (no Reopened/Closed). All four hit a
single OS-assigned port and verify the port is unchanged after
reload — a re-bind would either land on a different port or fail.
core: 613/613 tests pass (+4), typecheck clean.
|
||
|
|
76b87f6b27 |
feat(proton): migrate group-album actions (PR #31) to proton codec
PR #31 landed 4 TRPC group-album actions on the legacy runtime schema encoder. Migrate them to the compile-time codec, matching the pattern established by the OIDB migration: TS interfaces in `proto/proton/oidb-action.ts` are monomorphized at build time and each `protoEncode/Decode` call site now calls `protobuf_encode<T>` / `protobuf_decode<T>` directly. - Add 33 proton interfaces for the new TRPC envelopes (GetMediaList, DoQunComment, DoQunLike, DeleteMedias, plus all nested types) — inline anonymous schemas in legacy lifted to named interfaces. - Migrate `actions/group-album.ts` to the proton API; drop the `(resp as any)` casts now that decoded responses are typed. - Add 4 wire-byte parity tests for the new envelopes; non-default field values throughout so byte equivalence holds (proto3 omission of defaults is the documented divergence). - Drop dead `GroupAvatarUploadExtSchema` from `proto/highway.ts` and unused `import * as console from "node:console"` in `web/group-album.ts` — leftovers from the original PR review. core: 609/609 tests pass, typecheck clean. |
||
|
|
5802812392 |
feat(proton): finish OIDB migration — runOidb on protobuf_encode<OidbBase<T>>
Closes the OIDB phase of the proton migration. Every consumer that
talked to the OIDB service through the old runtime
`makeOidbBaseSchema()` factory now goes through the compile-time
generic `OidbBase<T>` instead — proton monomorphizes the codec per
call-site instantiation.
@snowluma/proton — two analyzer fixes uncovered by the migration:
1. Skip queuing call-site type-args that reference an *enclosing
generic function's* type parameter for monomorphization. Before
this, a wrapper like
export function encodeOidbEnv<T>(env: OidbBase<T>): Uint8Array {
return protobuf_encode<OidbBase<T>>(env);
}
would cause the analyzer to mint a literal `OidbBase__T` registry
entry with `body.typeName = 'T'`, which the post-walk wire-type
guard then tripped on. The enclosing-scope type params are tracked
on a stack as the walker descends into FunctionDeclaration,
FunctionExpression, ArrowFunction, MethodDeclaration nodes; matching
call sites are skipped (the wrapper-binding path is still
responsible for materialising concrete codecs at downstream call
sites).
2. Register *explicitly* empty interfaces (`interface X {}`) as
zero-field proto messages. OIDB has a handful of these
('this call has no meaningful response body' placeholders —
Oidb0xeb7Resp, Oidb0xcd4Resp, Oidb0x112aResp, Oidb0x8a0Resp,
Oidb0xf16Resp, OidbClientKeyReq). Proto3 wire allows zero-field
messages, and downstream code does `protobuf_decode<OidbBase<X>>`
where X is one of these — the wire-type guard would otherwise trip
on the missing `X` registration. Interfaces that have members but
no pb-marked fields are still NOT registered.
@snowluma/core — the OIDB-layer refactor itself:
bridge-oidb.ts ditches the runtime ProtoSchema factory and exposes:
- makeOidbEnvelope<T>(oidbCmd, subCmd, body, isUid) pure helper
- encodeOidbEnv<T>(env) pass-through
- decodeOidbEnv<T>(bytes) pass-through
- runOidb(bridge, cmd, envelopeBytes) non-generic raw
`encodeOidbEnv` / `decodeOidbEnv` are pure pass-through generic
wrappers — proton wrapper-binds them and substitutes every call site
with the inlined `protobuf_encode_OidbBase__X` / `protobuf_decode_…`
function. `runOidb` is non-generic (proton leaves it alone) so it can
be mocked in tests. `makeOidbEnvelope` is plain TS — also mockable for
introspection.
56 `runOidb` call sites across 11 files migrated to the new API:
- bridge-contacts.ts, actions/extras.ts, actions/friend.ts,
actions/group-admin.ts, actions/group-file.ts,
actions/group-message.ts, actions/interaction.ts,
actions/misc.ts, actions/profile.ts, web-actions/cookies.ts,
highway/pipeline.ts
pipeline.ts also drops `makeOidbBaseSchema(NTV2UploadRichMediaReqSchema)`
and the residual `protoEncode({...}, EncodableMediaMsgInfoSchema)` —
both go through proton now.
Tests:
- 8 test files migrated from `vi.mocked(decodeOidbEnv).mockReturnValueOnce`
to `vi.mocked(runOidb).mockResolvedValueOnce(protobuf_encode<OidbBase<X>>({body: …}))`
— the proton substitution means the old mock layer is bypassed at
build time, so the only mockable point is the bytes layer at `runOidb`.
- 2 new parity tests pinning `OidbBase<T>` ↔ legacy
`makeOidbBaseSchema(InnerSchema)` byte equivalence.
Verification:
- @snowluma/proton: 95/95 tests pass, tsc --noEmit clean
- @snowluma/core: 605/605 tests pass (network-manager.test.ts
fails to load due to a missing darwin-arm64 native binary in this
environment — pre-existing), tsc --noEmit clean
|
||
|
|
c543ce9227 |
feat(proton): add proton/oidb.ts with generic OidbBase<T> envelope
Phase 1 of the OIDB migration: stages the proton-side type definitions
and pins their wire equivalence to the legacy makeOidbBaseSchema()
runtime factory. No call sites are switched yet — that lands in
phase 2 along with the proton/oidb-action.ts schema mirror and the
runOidb refactor.
The legacy bridge/proto/oidb.ts exports a `makeOidbBaseSchema(body)`
factory function that synthesizes the OidbSvcTrpcTcpBase envelope
ProtoSchema at runtime. Proton is compile-time, so the natural form
is the generic interface
OidbBase<T> { command, subCommand, errorCode, body: T, errorMsg,
properties, reserved }
which the plugin monomorphizes per-instantiation. This is exactly the
"generic template with generic-instantiated field" usage that this
package's earlier edge-case fixes #2 and #3 were designed to support,
and the new parity test pins that they actually work on the real
shape (a fully populated OidbSvcTrpcTcp0xFE5_2Response with nested
groupOwner/customInfo).
Also added:
- OidbProperty (for the envelope.properties repeated field)
- OidbBaseMeta — envelope-only view for fire-and-check OIDB calls
that just need to peek at errorCode without decoding the body
- All 8 concrete schemas from oidb.ts (FriendList, GroupList,
GroupMemberList, GroupRequest families)
Verification:
- 2 new parity tests
* OidbBase<OidbSvcTrpcTcp0xFE5_2Response> ↔ makeOidbBaseSchema
byte equivalence
* round-trip encode → decode preserves nested body
- 602+2 = 604 core tests pass (network-manager file still env-fails
on missing native binary)
- tsc --noEmit clean
|
||
|
|
7526622917 |
feat(proton): migrate highway.ts schemas + highway-client + group-file
Mirrors all 35 schemas in bridge/proto/highway.ts as proton interface
forms and switches the two non-OIDB-wrapped consumers
(highway/highway-client.ts and actions/group-file.ts) over to the new
compile-time API.
Migrated schemas (proton/highway.ts):
DataHighwayHead, SegHead, LoginSigHead, ReqDataHighwayHead,
RespDataHighwayHead, HighwayDomain, HighwayIPv4, HighwayNetwork,
HighwayHash, HighwayMsgInfoBody, NTV2RichMediaHighwayExt,
FileUploadUrl, FileUploadHost, FileUploadHostConfig,
FileUploadNameInfo, FileUploadClientInfo, FileUploadFileEntry,
FileUploadBusiInfo, FileUploadEntry, FileUploadExt,
EncodableMediaExtBizInfo, EncodableMediaMsgInfo, HttpConn,
HttpConn0x6FF501Request, ServerAddr, ServerInfo, HttpConnResponse,
HttpConn0x6FF501Response, NTV2FileType, NTV2FileInfo,
NTV2UploadInfo, NTV2ExtBizInfo, NTV2UploadReq, NTV2C2CUserInfo,
NTV2GroupInfo, NTV2UploadSceneInfo, NTV2CommonHead, NTV2ClientMeta,
NTV2UploadReqHead, NTV2UploadRichMediaReq, NTV2IPv4,
NTV2SubFileInfoResp, NTV2UploadRespMsgInfo, NTV2UploadRespBody,
NTV2UploadRespHead, NTV2UploadRichMediaResp
Consumer switches:
- highway/highway-client.ts: protobuf_encode/decode for HttpConn
session fetch, ReqDataHighwayHead frames, NTV2RichMediaHighwayExt
extend bytes, RespDataHighwayHead per-chunk responses
- actions/group-file.ts: protobuf_encode<FileUploadExt> for both
group + private file upload ext bytes
NOT migrated (depends on the OIDB factory pattern):
- highway/pipeline.ts — uses makeOidbBaseSchema(NTV2UploadRichMediaReqSchema)
to wrap the NTV2 upload in an OIDB envelope at runtime. Waits for
the oidb.ts migration to land a generic OidbBase<T> form.
Verification:
- 5 new parity tests for highway schemas (HttpConn0x6FF501 req+resp
with the high-numbered 0x501 tag, ReqDataHighwayHead with multiple
nested messages, NTV2RichMediaHighwayExt with repeated_bytes,
FileUploadExt with the 100/200/400/600/700 high-numbered tags)
- 602/602 core test suite passes — the existing image / ptt / video
upload tests implicitly validated wire format equivalence
- tsc --noEmit clean
|
||
|
|
ccc31a760c |
feat(proton): migrate action.ts schemas + bridge.ts + element-builder.ts
Mirrors all 11 schemas in bridge/proto/action.ts as proton interface
forms and switches the two consumers (element-builder.ts and the
send-message paths in bridge.ts) over to the new compile-time API.
Migrated schemas (proton/action.ts):
RoutingC2C, RoutingGroup, RoutingHead, SendContentHead,
MessageControl, SendRichText, SendMessageBody, SendMessageRequest,
SendMessageResponse, MentionExtraSend, MarkdownData
Consumer switches:
- element-builder.ts: protobuf_encode<MentionExtraSend> for @ mention
pbReserve payload; protobuf_encode<MarkdownData> for markdown elem
- bridge.ts: protobuf_encode<SendMessageRequest> +
protobuf_decode<SendMessageResponse> for both sendGroupMessage and
sendPrivateMessage
The `ProtoElem` type alias in element-builder.ts (Partial<ProtoDecoded<typeof
ElemSchema>>) stays as-is — it's a pure TS type used internally for
building elem objects and doesn't affect runtime behaviour. Replacing
it with the proton Elem type is a larger refactor that can come later
when there's a reason to.
Verification:
- 6 new parity tests for action schemas (RoutingHead c2c+grp,
SendMessageRequest full shape, SendMessageResponse, MentionExtraSend,
MarkdownData)
- 591/591 core test suite passes — the existing send-message and
element-builder tests implicitly validated wire format equivalence
- tsc --noEmit clean
|
||
|
|
9f32dbd60c |
feat(proton): migrate notify.ts schemas + all 6 msg-push consumers
Mirrors all 27 notify.ts schemas as proton interface forms and switches
the entire msg-push decoder family over to the new compile-time API.
Migrated schemas (proton/notify.ts):
OperatorField1, OperatorInfo, GroupChange, GroupAdminExtra,
GroupAdminBody, GroupAdmin, InvitationInner, InvitationInfo,
GroupInvitation, GroupInvite, GroupJoin, FriendRequestInfo,
FriendRequest, FriendRecallTipInfo, FriendRecallInfo, FriendRecall,
GroupMuteState, GroupMuteData, GroupMute, RecallMessage,
GroupRecallTipInfo, GroupRecall, TemplParam, GeneralGrayTipInfo,
EssenceMessage, NotifyMessageBody, GroupReactionDataInnerDataTarget,
GroupReactionDataContent, GroupReactionDataInnerData,
GroupReactionDataInner, GroupReactionData, GroupReactNotify
Consumer files switched to protobuf_decode<T>():
- msg-push/helpers.ts (decodeOperatorUid)
- msg-push/decoders/event-0x2dc.ts (5 call sites: GroupMute,
GroupRecall, GroupGreyTip, GroupEssence, GroupMsgEmojiLike)
- msg-push/decoders/event-0x210.ts (3 call sites: FriendRequest,
FriendRecall, FriendPoke)
- msg-push/decoders/group-admin.ts
- msg-push/decoders/group-member-change.ts (join + leave)
- msg-push/decoders/group-join-request.ts (join request + invitation
+ invite)
The notify.ts FriendRecall interface collides with events.ts's own
FriendRecall event type; the decoder imports it under the local alias
FriendRecallNotify to keep the existing event type intact.
Verification:
- 6 new parity tests pinning notify wire equivalence
- 591/591 core test suite passes (the existing decoder tests —
group-msg-emoji-like, group-admin, etc. — implicitly validated
wire format equivalence against real captured QQ payloads)
- tsc --noEmit clean
|
||
|
|
b7d8952163 |
feat(proton): full longmsg + element + message migration; forward.ts on new API
Completes the proton migration started in the previous PoC commit. All
schemas needed by actions/forward.ts are now mirrored as proton interface
forms, the legacy ProtoSchema constants stay in place for back-compat,
and forward.ts has been switched over to the new compile-time codecs.
Migrated schemas:
- element.ts (35 schemas: TextElem, FaceElem, OnlineImage, NotOnlineImage,
TransElem, MarketFace, CustomFace, RichMsg, GroupFileElem, ExtraInfo,
VideoFile, SrcMsg, LightAppElem, CommonElem, GeneralFlags, Elem,
MentionExtra, QFaceExtra, QSmallFaceExtra, FileType, FileInfo,
IndexNode, PicUrlExtInfo, PictureInfo, PicExtData, PicExtBizInfo,
VideoExtBizInfo, PttExtBizInfo, ExtBizInfo, C2cSource, TroopSource,
HashSum, MsgInfoBody, MsgInfo, GroupFileInfo, GroupFileExtraInner,
GroupFileExtra, Preserve, …)
- message.ts (PushMsg, PushMsgBody, ResponseHead, ContentHead, Ptt,
NotOnlineFile, RichText, MessageBody, FileExtra, …)
- longmsg.ts — the three remaining schemas (LongMsgContent / LongMsgAction
/ LongMsgResult) that depend on PushMsgBody
forward.ts now calls:
protobuf_encode<LongMsgResult>(...) // upload payload
protobuf_encode<SendLongMsgReq>(...)
protobuf_decode<SendLongMsgResp>(...)
protobuf_encode<RecvLongMsgReq>(...)
protobuf_decode<RecvLongMsgResp>(...)
protobuf_decode<LongMsgResult>(...) // download payload
protobuf_encode<PushMsg>(...) // re-wrap for parseMsgPush
The unused legacy schema constants are intentionally left in place — they
still back the existing forward.test.ts mock encoder and any other consumer
that hasn't been migrated yet. They will be removed in a follow-up once
every consumer is on the new API.
Verification:
- 18/18 parity tests pass (encode + decode equivalence for every
representative shape across element / message / longmsg)
- 585/585 core test suite passes (network-manager.test.ts fails to load
due to a missing native binary in this environment — pre-existing)
- tsc --noEmit clean
|
||
|
|
3d739c255a |
feat(proton): proof-of-concept migration — longmsg parity test
Migrates a self-contained subset of bridge/proto/longmsg.ts to the new
@snowluma/proton compile-time DSL form and verifies wire-format parity
against the legacy runtime ProtoSchema encoder. End-to-end proof that
the toolchain works in core's vitest pipeline.
What's covered:
- LongMsgUid / LongMsgSettings / SendLongMsgInfo / SendLongMsgReq /
SendLongMsgResp / SendLongMsgRespResult / RecvLongMsgInfo /
RecvLongMsgReq / RecvLongMsgResp / RecvLongMsgRespResult
- The three schemas that pull in PushMsgBody (LongMsgContent /
LongMsgAction / LongMsgResult) stay on the legacy API for now, since
migrating them requires also migrating message.ts and element.ts.
Toolchain changes:
- @snowluma/proton gets a tsup build step. The ./vite subpath now
points at the built dist/index.js so it is loadable as plain Node
ESM from vite.config.ts / vitest.config.ts (the source-only .ts
layout can't be consumed from outside the Vite transform pipeline).
The . (runtime) subpath stays at TS source — it's only ever
imported from user code, which IS Vite-transformed.
- prepare script ensures dist/ exists after pnpm install.
- @snowluma/core depends on @snowluma/proton (workspace:*) and adds
protobufVitePlugin() to its vitest config so test files get
transformed.
Documented divergence:
proton follows proto3 semantics: fields equal to their default value
(0 / false / "" / empty bytes) are NOT emitted on the wire. The legacy
runtime encoder always emits them. Both forms are round-trippable
through a conforming proto3 reader. The parity test pins this
behaviour explicitly.
8/8 parity tests pass.
|
||
|
|
f316073431 |
Merge pull request #43 from airline233/dev
feat(http-server): support parse content-type of urlencoded |
||
|
|
b99f5c0bf1 | fix(request-actions): match group add/invite flags by UID and add regression tests | ||
|
|
24056c3de0 |
feat(msg-push): decode group message emoji reactions (Event0x2DC subType=16)
QQ has been pushing Event0x2DC subType=16 every time someone tapped
an emoji on a message in a group, and we were dropping it silently
(only surfacing the PR5 [MsgPush.Unknown] debug line that prompted
this issue). Now we decode it into a first-class event and fan it
out to OneBot clients.
Wire details (cribbed from NapCat's GroupReactNotify transformer):
- body.msgContent has a 7-byte magic prefix; strip before decoding.
- GroupReactNotify { groupUin(4), field13(13), groupReactionData(44) }.
- field13 is a discriminator — same subType is reused for other
notify variants, only 35 means "emoji react". Other values now
fall through to MsgPush.Unknown so we still spot future variants.
- Inside groupReactionData (3-level nested data wrapper, ugh):
code emoji id (system face = numeric str, market = code)
count usually 1
operatorUid needs identity.findUinByUid to resolve to uin
type 1 = add, else = remove
target.seq msg_seq of the reacted-to message
New event kind `group_msg_emoji_like` flows through the standard
pipeline: bridge event → event-bus → converter → OneBot wire.
Converter emits the gocqhttp / NapCat extension shape:
notice_type: group_msg_emoji_like
sub_type: add | remove
group_id, user_id, operator_id, message_id, message_seq,
likes: [{ emoji_id, count }]
message_id is reconstructed via hashMessageIdInt32(msgSeq, groupId,
GROUP_MESSAGE_EVENT) so it matches whatever id the bot originally
handed out for the message being reacted to, even if it's no longer
in the message store.
formatEvent also gets a case so the [Event] log reads cleanly:
表情回应 [群名(123)] | [Alice(99999)] +[76] msgSeq=4242
7 new tests cover the happy path, type=2 (remove), field13!=35
(routed to MsgPush.Unknown), prefix-too-short edge, converter
shape both for add and remove, and the formatEvent string.
|
||
|
|
4c513c015d |
feat(logger): runtime log level toggle via WebUI
The console / subscriber level was captured at module load
(`const MIN_LEVEL = resolveMinLevel()`), so any change to
SNOWLUMA_LOG_LEVEL after Node started had no effect — restart was
the only way to flip levels, which makes "go to debug for 30s to
see what's happening" pretty painful.
logger.ts now keeps `currentLevel` mutable and exports
setLogLevel() / getLogLevel(). The env var still seeds it on
startup; nothing about the boot-time behavior changes. File
transport remains unaffected — it always sees debug-and-up.
WebUI gets two new endpoints, both behind the existing auth
middleware:
GET /api/logs/level → { level, levels }
POST /api/logs/level body → { level: 'debug' } updates it
Logs page picks up a "服务端级别" row of pills next to the
existing client-side filter pills, so an operator can flip the
console firehose on/off in one click without touching env vars
or restarting the bot. The label clarifies that file logging
stays at debug regardless.
|
||
|
|
4a49c55775 |
fix(hook): refresh pipe snapshot before verifying unload took
After native unload returns, the verification check
if (pipeWatcher.isPipeLive(pid)) { ... unload-failed message ... }
read PipeWatcher's cached snapshot, which is updated every 1500ms.
On Windows clicking "Unload" in WebUI almost always tripped this:
the native unload succeeded and the kernel pipe object was gone, but
the watcher's cached "live" state from the previous tick was still
fresh, so the session reported "DLL卸载失败:命名管道仍然存在" even
though the DLL was successfully unloaded. The user then sees the
status flip back to connecting and waits for a real (cached) refresh.
PipeWatcher already exposes tickNow() for exactly this situation —
the load path doesn't need it because injection's verification runs
async via onPipeUp, but unload verifies inline.
HookSessionDeps.pipeWatcher gains an optional `tickNow` and
unloadInternal awaits it before reading isPipeLive. Existing test
mocks that pass only `{ isPipeLive }` keep working (optional chain
is a no-op there). New regression test covers the production
scenario — stale-true cache flipped to false by tickNow.
|
||
|
|
257686eac6 |
feat(logger): identity-aware readable event rendering
Notice events (recall / join / leave / poke / admin / mute / essence
/ request / invite) and the received-message log now resolve group
IDs and user IDs against the Identity cache so output reads as
human names instead of raw QQ numbers.
Before:
[Event] 群撤回 12345 | 67890 被 99999 撤回
[Event] 群 12345 | NickName(67890): ID:42 你好 [图片]
After:
[Event] 群撤回 [SnowLuma群(12345)] | [Alice(67890)] 被 [Bob(99999)] 撤回
[Event] 群 [SnowLuma群(12345)] | [Alice(67890)]: ID:42 你好 [图片]
Reply segments now expand one level via messageStore.findEvent —
"[回复:42]" becomes "[回复 [Alice(100)]: 早安]" when the original
is still in the message store, falling back to the bare id when it
isn't.
New file utils/event-format.ts owns:
- formatGroup / formatUser identity-aware name resolution
- formatMessageSegments shared element preview (replaces
the inline switch in
logReceivedMessage)
- formatReply one-level reply chain expansion
- formatEvent notice-class event renderer
Every formatter wraps its lookup in try/catch and degrades to the
prior numeric form on cache miss / throw, so log formatting can
never crash the calling path. The QQ numeric ID is preserved
alongside the name so third-party parsers that scrape uids still
find them.
26 unit tests cover cache hit / miss, malformed input, throw
recovery, and per-event-kind rendering shapes.
|
||
|
|
7ec479bb88 |
feat(logger): protocol-layer observability for highway and msg-push
Highway upload path now emits per-type entry + shared pipeline ops: DEBUG [Highway.Image] uploading 234567 bytes md5=abc12345... → group 12345 DEBUG [Highway] image OIDB requires bytes, PUT 234567 bytes (sub=top) DEBUG [Highway] image PUT done in 1234ms -- or -- DEBUG [Highway] image fast-upload hit (server already had bytes) The three pipeline-side lines come from runNtv2Upload() and are shared across image/video/ptt; the per-type entry log lives in each *-upload.ts wrapper so the scope identifies the media kind. md5 is truncated to its first 8 hex chars for line width; PUT latency is reported in ms. MsgPush silent dispatch defaults are now visible at debug: DEBUG [MsgPush.Unknown] no decoder for PkgType=999 subType=0 DEBUG [MsgPush.Unknown] Event0x2DC unknown subType=42 DEBUG [MsgPush.Unknown] Event0x210 unknown subType=42 Captures protocol drift (new NT QQ subtypes) and "we forgot to register this PkgType" oversights, neither of which used to leave any trace in the log. All new lines are debug-level so console output (default info) stays unchanged; file transport sees them for post-mortem. |
||
|
|
1ba45e2659 |
feat(logger): observability for OneBot action dispatch
Every OneBot action call now emits a single debug line under [Bridge.Action]: DEBUG [Bridge.Action] send_group_msg group_id=12345 message=[len=3] On failure, dispatch logs a warn with the full stack instead of silently folding the error into the response. Unknown actions also get a debug entry so "the bot is ignoring me" is no longer invisible. Notes: - New summarizeParams() helper caps each value at 40 chars / line at 200 chars to keep arrays / nested payloads from blowing the line width. Lives in utils/log-summary.ts for reuse (highway will too). - ApiHandler now takes an optional uin and binds a child logger so per-account file routing works. OneBotInstance passes its parsed uin. - Control-char strip in logger/file-transport was exempting only ESC; also exempt TAB (0x09) and LF (0x0A) so stack traces stay multi-line in both console and file output. - vitest.config sets SNOWLUMA_LOG_LEVEL=debug so the ring buffer receives the new debug entries that tests assert on. |
||
|
|
93b9b03667 |
feat(logger): add .child({ uin }) API and per-UIN file fan-out
Logger now supports deriving a UIN-bound child:
const log = createLogger('Bridge');
this.log = log.child({ uin: this.uin });
The child stamps a fixed-width [UIN] slot into rendered lines so the
[Scope] column stays vertically aligned, and routes the same line to
a per-UIN sub-file:
logs/snowluma-YYYY-MM-DD.log (shared, all UINs)
logs/<uin>/snowluma-YYYY-MM-DD.log (per-account)
Both pathways share daily rollover, size cap, and retention.
LogEntry now carries uin so SSE subscribers (WebUI) can filter later.
Other meta keys passed to child() are preserved in opts.meta for
forward compat (requestId / traceId etc.) but not rendered yet.
Module-level callers are unchanged; no callsites migrated in this PR.
SNOWLUMA_LOG_PER_UIN=0 disables the per-account sub-file while
keeping the shared one.
|
||
|
|
51f46e15fd |
feat(logger): add file transport with daily rotation and size cap
Adds a hand-rolled FileTransport that fans out every log line (debug and up, regardless of console filter) to ./logs/snowluma-YYYY-MM-DD.log. When the current file exceeds the configurable size cap it rolls into snowluma-YYYY-MM-DD.1.log, and files older than the retention window are unlinked at startup and on each day rollover. Config (all env, no settings.json): - SNOWLUMA_LOG_FILE 0 to disable file output (default: on) - SNOWLUMA_LOG_DIR output directory (default: ./logs) - SNOWLUMA_LOG_MAX_MB per-file cap, MB (default: 50) - SNOWLUMA_LOG_RETAIN_DAYS retention window (default: 7) closeLogger() awaits the WriteStream's finish event; SIGINT and SIGTERM handlers now await it before process.exit so the buffer makes it to disk. vitest config sets SNOWLUMA_LOG_FILE=0 to keep the suite from polluting cwd; the new tests under tests/log-file-transport.test.ts flip it back on per-test against a tmpdir. |
||
|
|
b441647df4 | feat(http-server): support parse content-type of urlencoded | ||
|
|
ffe0c57abf |
feat(webui): add SNOWLUMA_WEBUI_TRUST_PROXY for reverse-proxy deploys
The previous commit tightened login rate-limiting to key off the real
TCP socket peer, which fixed the X-Forwarded-For bypass but had the
known caveat of collapsing every client into a single global bucket
when the WebUI runs behind nginx / Caddy / a SaaS CDN.
Give operators an explicit, audited way to opt back into per-client
keying without re-introducing the spoof:
* `SNOWLUMA_WEBUI_TRUST_PROXY` env var. Modes:
- unset / empty → keep socket peer (safe default, unchanged)
- "loopback" → trust X-Real-IP / X-Forwarded-For when the
immediate socket peer is 127.0.0.1 / ::1
(nginx + WebUI on the same host)
- "1" / "true" / → trust headers from any peer (only safe behind
"all" a SaaS proxy that strips client-set headers)
- comma-separated → trust headers only when the socket peer
IP list matches one of these (proxy on another box)
* When trusting headers we prefer X-Real-IP (single value the proxy
overwrites unconditionally) and fall back to the first hop of XFF.
We deliberately do NOT walk the full XFF chain — without a fully
trusted proxy chain the leftmost value is still spoofable; a
single-tier proxy is the only setup this app realistically sees.
* Boot log prints "login rate-limit keyed by: …" so operators can
verify the mode took effect, plus an extra WARN for "all" reminding
them it's only safe with header-stripping in front.
Logic lives in webui/client-ip.ts as a pure pickClientIp() that takes
a socket-IP resolver, so the trust-proxy matrix can be exercised
without standing up a server — see webui-client-ip.test.ts for the
11 new unit tests covering parse + dispatch + loopback / list / all /
none modes.
Smoke-tested with SNOWLUMA_WEBUI_TRUST_PROXY=loopback:
- 5× failed login w/ X-Forwarded-For: 1.1.1.1 → 401
- 6th attempt same XFF → 429 (locked, per-XFF)
- 6th attempt X-Forwarded-For: 2.2.2.2 → 401 (fresh bucket)
- X-Real-IP overrides XFF when both present
|
||
|
|
b40cee18cc |
fix(bridge): close two binary-size cap gaps flagged by review
Follow-up on the previous highway commit, addressing two real holes the Copilot review caught: * loadBinarySource HTTP path was buffering the entire response via `await resp.arrayBuffer()` BEFORE length-checking. A server that omits or understates `Content-Length` (chunked transfer, malicious upstream, proxy stripping headers) bypassed the cap entirely. Switch to a streaming reader: accumulate chunks, abort + reject as soon as the running total exceeds `maxBytes`. The Content-Length precheck still short-circuits the obvious case before we read a byte. * video-upload `stageVideoSource` has its own local-path fast-path that never went through `loadBinarySource`, so the 100 MB MAX_VIDEO_SIZE guard ran AFTER `fs.readFileSync` had already allocated the entire file. A 10 GiB local-file pointer would OOM the bot before the check fired. Add an `fs.statSync` precheck on the local branch, and pass `MAX_VIDEO_SIZE` explicitly when the source falls through to `loadBinarySource` so the HTTP / base64 cap matches the on-disk one. Update the DEFAULT_MAX_BINARY_SIZE comment to stop claiming video paths are bounded by it — they're bounded by the smaller MAX_VIDEO_SIZE, enforced inside video-upload. Adds five regression tests: - chunked streamed download (no Content-Length) over cap → throws - Content-Length over cap → throws before reading body - streamed download inside cap → returns full bytes - local file over cap (statSync precheck) → throws - base64 over cap → throws |
||
|
|
b3df633c87 |
fix(bridge): correctness pass on highway, hook, and identity service
* highway/utils detectImageFormat: JPEG SOF marker check now excludes 0xC4 (DHT), 0xC8 (JPG), and 0xCC (DAC). The old `(marker & 0xFC) === 0xC0` matched DHT et al. and then read Huffman table bytes as image dimensions, producing junk width/height for many real JPEGs. * loadBinarySource takes an optional maxBytes; defaults to 1 GiB to defend against an authenticated client triggering a multi-GB load into memory. Group/private file uploads pass FILE_UPLOAD_MAX_BYTES (4 GiB) because QQ's file protocol legitimately supports that size. HTTP fetches also pick up a 60s timeout and a Content-Length precheck. * highway-client.tcpConnect detaches its error/timeout listeners after a successful connect so subsequent upload IO errors don't reject an already-resolved promise. readHttpResponseBody uses local listener refs + a central detach(), eliminating MaxListenersExceededWarning during multi-chunk uploads. * hook/qq-hook-client.nextRequestId now wraps inside uint32 explicitly and skips id 0 / in-flight ids. The previous `nextRequestId++ >>> 0` loses precision past Number.MAX_SAFE_INTEGER (postfix increment evaluates before the shift) and could collide live request ids on very long-running processes. * identity-service.rememberUidUin removes stale partner entries before inserting a new (uid, uin) pair. The old code left orphan uidByUin / uinByUid entries after a uid/uin re-bind, so the two maps could disagree. |
||
|
|
2c80e1a267 |
refactor(onebot): make loadOneBotConfig read-only by default
GET on a load helper used to mint a fresh access_token and write it to
disk whenever the per-UIN file was missing or in legacy format. Reading
should not have side effects, and the WebUI's read-only GET handler in
particular was racing on concurrent requests and surprising operators
with materialized config files.
Introduce a `{ persistDefaults?: boolean }` option (default false). The
two boot-time call sites in `OneBotManager` (onSessionStarted, reloadConfig)
opt in explicitly; WebUI's GET path will rely on the new default once
that side of the patch lands.
Also stop reviving default 0.0.0.0 listeners when the operator has
explicitly emptied every adapter — only seed defaults on a true fresh
install (no per-uin and no global config on disk).
Drop the unused deepClone / deepMerge helpers; tryLoadJson now logs a
warning instead of silently swallowing JSON parse errors.
|
||
|
|
29f28d611f |
fix(send): use c2c businessType for private video / record
Private-chat video and voice sends were getting bounced by the QQ NT server with `PbSendMsg result=79`. Highway upload logs said success, but the final SendMsg the bot constructed used the group-scene tag inside the outgoing commonElem, and the c2c routing path doesn't recognise it. The convention — verified against the receive-side decoder at msg-push/rich-body-decoder.ts:261-330 which explicitly branches on the pairs — is: image : commonElem.businessType c2c=10 group=20 video : commonElem.businessType c2c=11 group=21 record : commonElem.businessType c2c=12 group=22 makeImageElem already honoured the split (`isGroup ? 20 : 10`). makeVideoElem and makePttElem hardcoded the group value for both scenes. Fix them to follow the same pattern. Also fix a symmetric asymmetry inside the highway upload itself: uploadVideoMsgInfo hardcoded `compatQmsgSceneType: 2` while uploadImageMsgInfo and uploadPttMsgInfo both use `isGroup ? 2 : 1`. Same root cause — group value leaking into the c2c path. Regression test (tests/element-builder.test.ts) pins all six businessType pairs by mocking the highway upload functions and inspecting the proto element the builder returns; would have caught the bug had it existed at the time element-builder.ts was written. |
||
|
|
97ad2e22bb |
feat(onebot): implement set_group_portrait via highway cmdId 3000
Port the Lagrange.Core protocol path for group avatar upload —
napcat's NTQQ GroupService.setHeader has no oidb wrapper, but
Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs
spells out the wire shape: same highway HTTP endpoint as personal
avatar, but with cmdId=3000 and a GroupAvatarExtra proto carried as
the `extend` blob (type=101, groupUin, field3={field1=1}, field5=3,
field6=1 — all four are protocol-prescribed constants).
Adds:
- GroupAvatarExtraSchema in proto/oidb-action.ts
- bridge.setGroupAvatar(groupId, source) wrapping the highway upload
- BridgeInterface.setGroupAvatar
- OneBot set_group_portrait action (was a stub returning
'not yet implemented'; accepts the same file-source variants as
set_qq_avatar)
5 new tests: 3 bridge-action (cmdId, extra-blob round-trip, empty-file
guard) + 2 OneBot (forwarding, param validation) — also tightens the
existing setAvatar test to assert the extend blob stays empty.
|
||
|
|
f7457e3e59 |
feat(onebot): add set_diy_online_status
DIY online status reuses the existing StatusService.SetStatus wire call. napcat hardcodes status=10 / extStatus=2000 and threads the faceId / wording / faceType through a customExt sub-message (field 4 of SetStatus, per napcat packet/transformer/proto/action/action.ts). Implementation: - Extend SetStatusReqSchema with optional customExt field. Encoder skips undefined fields so the existing set_online_status path stays byte-identical on the wire (verified by a new round-trip test). - New bridge.setDiyOnlineStatus(faceId, wording, faceType) wraps the same dispatchSetStatus helper as setOnlineStatus. - OneBot action set_diy_online_status accepts napcat-style payloads (face_id / face_type can be string or number; wording defaults to ''). 9 new tests across actions/profile and onebot/extended-actions. |
||
|
|
ee62f5aa0b |
feat(onebot): add napcat-parity actions (Tier 1 + Tier 2)
Wires 16 OneBot actions that napcat exposes but SnowLuma previously either lacked or stubbed: Tier 1 (pure glue over existing Bridge capabilities) - send_packet / .send_packet: real impl over Bridge.sendRawPacket - bot_exit, nc_get_packet_status, nc_get_rkey - get_group_ignored_notifies / get_group_ignore_add_request: project fetchGroupRequests(filtered=true) into napcat shapes (was empty stub) - delete_group_folder alias for delete_group_file_folder Tier 2 (new oidb proto + Bridge method) - set_/complete_/cancel_group_todo (oidb 0xF90_1/2/3) - nc_get_user_status (oidb 0xFE1_2 with napcat's status decode) - get_ai_characters / get_ai_record / send_group_ai_record (oidb 0x929D / 0x929B; AI voice reuses the existing fetchGroupPttUrlByNode) BridgeInterface now exposes sendRawPacket as the deliberate escape hatch for send_packet — every other surface method already wraps it. 46 new tests: 13 bridge-action (mocked runOidb dispatch checks) + 33 OneBot-action (ApiHandler.handle end-to-end). |
||
|
|
78d42029ba |
test(hook): guard against per-reconnect leak when QQ never logs in
50 onPipeUp/onPipeDown cycles → at most 1 live FakeClient, zero listeners on every torn-down client. E2E variant additionally asserts BridgeManager.onHookLogin / onPidDisconnected / onPacket are never called, so no Bridge / Identity / OneBotInstance is allocated. These prove no leak exists at this layer. Investigated after a Docker OOM report which turned out to be QQ Browser GC-thrashing while idle on the login screen (75-second LongTask entries from PID 61 in the report). |
||
|
|
6b236f70bf |
refactor(bridge): split MsgPush handler into per-PkgType decoders
The 885-line msg-push-handler.ts is replaced by bridge/msg-push/: 8 per-PkgType decoders plus MsgPushRegistry (single decoder per PkgType, catch + log on error), MsgPushContext (header decoded once at entry), and rich-body-decoder (one deep function hides ~400 lines of element conversion shared by all three message types). parseMsgPush(pkt, identity) signature preserved; existing tests pass with an import-path change only. |
||
|
|
29fa2696c8 |
test(onebot): exercise contact-actions through a fake BridgeInterface
First OneBot unit test that proves the BridgeInterface seam (PR4) delivers real testability. The fake bridge is a Proxy over a tiny override map — un-stubbed methods throw with a clear message, so each test only spells out the surface it actually exercises, and a missing stub never silently passes. Covers the five contact-actions read paths users hit most through the OneBot API: getLoginInfo / getFriendList / getGroupList / getGroupInfo / getGroupMemberList / getGroupMemberInfo / getStrangerInfo — 19 cases spanning happy path, network-fail fallback to identity cache, noCache=true forcing a refetch, and missing-data nulls. No SQLite, no native packet sender, no BridgeManager — just BridgeInterface. |
||
|
|
59cdfa98a2 |
refactor(oidb): replace 3 positional helpers with one named runOidb
bridge-oidb.ts used to expose three thin functions —
makeOidbRequest / sendOidbAndCheck / sendOidbAndDecode — and every
action file repeated the same five-step envelope assembly with long
positional argument lists. Collapse them into one `runOidb(bridge,
call)` taking an OidbCall object: cmd / oidbCmd / subCmd / request
{ schema, value, isUid? } / response? { schema }.
Behavioural contract is preserved:
- No `response`: verify success + gotResponse, peek envelope retCode
iff response data is present (fire-and-check semantics).
- With `response`: require responseData, decode through the base
schema, validate retCode, return the inner body typed as TResp.
Migration touches 51 call sites across 9 source files (bridge-contacts,
actions/{group-file, group-admin, profile, group-message, friend,
interaction, misc}, web-actions/cookies) plus 9 test files that used
to assert on positional `.mock.calls[0]![4]` indices and now read
through `.mock.calls[0]![1].request.value` / `.cmd` / `.oidbCmd`.
Net effect: callers now name what each piece is for, and adding
cross-cutting OIDB behaviour (retry / timeout / per-cmd logging) is a
single-site change inside runOidb instead of a sweep across 9 files.
|
||
|
|
ac10c663f1 |
refactor(identity): absorb QQInfo into IdentityService
QQInfo's in-memory state (self identity, friends, group rosters,
profile cache) and read methods (findFriend / findGroup /
findGroupMember / findUserProfile / nickname / uin / selfProfile) now
live directly on IdentityService. The QQInfo class is gone; its
interfaces stay in `qq-info.ts` as plain types shared across the
remember*/find* surface.
This eliminates a long-standing duplication: every observation used to
maintain both QQInfo's in-memory structures and IdentityService's
SQLite mirror in parallel, with the uidByUin/uinByUid Maps tracked
separately. With one Module owning all three layers, every remember*
hydrates one set of structures and `loadSnapshot` repopulates the
in-memory uid↔uin index from SQLite on startup — closing the cold-cache
gap that previously forced findUidByUin to fall through to a SQLite
query after every restart.
Knock-on changes:
- `Bridge` no longer holds a QQInfo; constructor takes an
`IdentityService`. The CmdParser signature on the cmd dispatch
table now passes `IdentityService` to parsers.
- `msg-push-handler.ts` drops its private `resolveUidToUin(qqInfo, …)`
helper that bypassed IdentityService's cascade — the parser hot
path now reads through `identity.findUinByUid(uid, groupId)` and
benefits from the O(1) `uinByUid` map even on freshly-loaded
sessions.
- `BridgeManager`'s session-started callback drops the QQInfo
parameter; OneBotInstance no longer carries a `qqInfo` field and
exposes a `nickname` getter for the WebUI listing.
- `contact-actions` and the per-theme bridge action files stop
importing QQInfo; they read everything via `bridge.identity.*`.
|
||
|
|
030336a25c |
refactor(identity): consolidate UID resolution behind IdentityService
Pull the cache→DB→network-fetch fallback cascade for UIN→UID translation into a single async `resolveUid` on IdentityService, and drop the duplicated `resolveUserUid` helper that used to live in bridge-oidb. Bridge injects itself as the IdentityFetcher post-construction so the network fallback runs through the same OIDB profile fetch the helper used. Each action module's `resolveUserUid(bridge, uin, groupId?)` call becomes `bridge.resolveUserUid(uin, groupId?)` — same signature on Bridge, but internally it now goes through `identity.resolveUid` so future changes (retry, coalescing, alternative resolvers) only need to land in one place. This is part 1 of the IdentityService deepening (RoadMap item 1). The QQInfo bypass in msg-push-handler and the broader QQInfo absorption land in the follow-up commit. |
||
|
|
9068ce3108 |
fix(core): skip Electron child processes during hook auto-load
With SNOWLUMA_HOOK_AUTOLOAD=1, the QQ window came up blank — no QR code, login stuck. Cause: the native enumerator (get_all_main_process_ids) returned the main QQ pid plus 2 zygote subprocesses because their cmdline contains "qq" and they transiently inherit wrapper.node via fork copy-on-write. Auto-load fired loadModuleManual for all three, spawning an in-process resolver thread inside each zygote. Renderer processes Electron later forked from those zygotes then inherited those resolver threads + the partially-initialised hook state, which breaks QQ's IPC and prevents the login UI from rendering. Add `shouldAutoLoadPid` which reads /proc/<pid>/cmdline and returns false when it contains `--type=` (Electron child process marker: zygote / renderer / gpu-process / utility). Manual loadProcess() is unaffected — operators picking PIDs from WebUI keep full control. SNOWLUMA_HOOK_AUTOLOAD_ALL=1 disables the filter as an escape hatch. Verified on tempserver: container restart with autoload=1 now shows the QR-code login screen as expected, and only the main qq pid gets the mojo.<pid>.*.sock pair (zygotes stay clean). |
||
|
|
fbb7504afe |
feat(core): auto-inject hook on QQ process discovery
Headless / Docker deployments previously needed a human to click "Load" in WebUI for every newly-discovered QQ process. Add an opt-in HookManager.autoLoadOnDiscovery flag wired up through two layers: - SNOWLUMA_HOOK_AUTOLOAD env var (highest priority) - hookAutoLoad in runtime.json (persistent fallback) When enabled, every 'process-discovered' event from PipeWatcher fires session.load() fire-and-forget; failures stay scoped to the session via existing error-state handling and don't break the watcher loop. Default stays off, so non-Docker installs see no behaviour change. |
||
|
|
dd02535a73 |
chore(core): flatten single-file dirs + drop dead writeFailed surface
Two small cleanups that came out of the round-2 architecture review and are sub-five-minutes each — bundled because each one is too small to justify its own commit. #5 — flatten single-file directories packages/core/src/bridge/builders/element-builder.ts -> packages/core/src/bridge/element-builder.ts packages/core/src/bridge/handlers/msg-push-handler.ts -> packages/core/src/bridge/msg-push-handler.ts Both dirs had exactly one file in them — a smell that says "planned a sibling that never landed". Moving up one level removes the wrapper directory. Touch list: - bridge.ts: 2 import paths - bridge/actions/forward.ts: 2 import paths - msg-push-handler.ts: internal ../X -> ./X for events, proto/element, proto/message (the dynamic-import-typeof references too) - element-builder.ts: internal ../X -> ./X for bridge, events, highway/* - 4 test files: import paths (2 regular, 2 vi.mock) #6 — drop IdentityService.hasWriteFailure identity-service.ts had a `private writeFailed = false` field set by the runWrite catch block and exposed via `get hasWriteFailure()`, but a full-repo grep showed zero callers of the getter. It was a public API stub for a feature that hadn't been wired (a webui health indicator, presumably). Removed: - the field - the getter - the assignment in runWrite's catch block (the error log on the next line is the actual observable behavior; nothing else reads the flag) If we want a "did any write fail this session" surface later, it's trivial to add back with an explicit consumer in mind. Behavior preserved end-to-end. No public API change outside the moved files. 369 tests pass (unchanged). 3 stability runs. |
||
|
|
069548918b |
refactor(core): split web-actions.ts into themed modules + barrel
web-actions.ts was a 330-line monolith with 14 exported functions
covering 4 distinct themes: cookie/credential primitives (the 8
functions every web call builds on), group honor leaderboards, group
essence (highlighted messages), and group notices. Same shape problem
the OIDB bridge-actions.ts split fixed three commits back, just smaller.
New layout under packages/core/src/bridge/web-actions/ :
cookies.ts (161 lines, 8 fns)
forceFetchClientKey / getPSkey / getCookies / getSKey /
getBknFromSKey / getCookiesStr / getCsrfToken / getCredentials
— the ptlogin2-jump + bkn-derivation primitives.
group-honor.ts (45 lines, 1 fn)
getGroupHonorInfo (talkative / performer / legend / emotion / ALL)
group-essence.ts (27 lines, 2 fns)
getGroupEssence (paged) + getGroupEssenceAll
group-notice.ts (118 lines, 3 fns)
sendGroupNotice (with optional image-from-URL-or-file upload),
getGroupNotice (OneBot shape flatten), deleteGroupNoticeByFid
index.ts (27 lines)
Barrel re-export. `bridge.ts` keeps its existing
`from './web-actions'` import — TS resolves the directory's
index.ts so no caller changes.
The lower-level web/* helpers (request-util, group-essence,
group-honor, group-notice) stay where they were — they're the
direct HTTP/cookie wrappers, distinct from these Bridge-level
orchestrators.
Behavior preserved end-to-end. Same ptlogin2 URL construction,
same fall-back-to-getPSkey-when-p_skey-missing path in getCookies,
same default keyIndex='19' / expireTime='1800', same djb2 bkn hash,
same NapCat-derived default 540x300 notice image dimensions, same
chinese error messages ('设置群公告失败', '获取公告失败').
Adds 35 happy-path tests across 4 new files in tests/web-actions/ :
cookies (13) forceFetchClientKey response shape + defaults,
getPSkey pskeyItems folding, getCookies ptlogin2
URL params, p_skey fallback path (both success
and throwing), getSKey success / no-clientKey /
no-skey throws, getBknFromSKey determinism +
range, getCookiesStr formatting, getCsrfToken
composition, getCredentials full + empty paths.
group-honor (7) TALKATIVE list vs empty list behaviour,
PERFORMER / LEGEND / EMOTION per-type dispatch,
ALL fetches all four types, groupId stringification.
group-essence (4) pageStart/pageLimit forwarding, defaults,
null-result fallback envelope, getAll delegation.
group-notice (11) text-only dispatch + defaults, options override,
http image fetch + upload + thread, fetch failure,
ec≠0 surfaces em, generic error fallback,
getGroupNotice feed flattening + pics mapping,
null-result throw, empty-feeds case,
deleteGroupNoticeByFid argument forwarding.
Tests use vi.mock on bridge-oidb / web/request-util / web/group-*
to isolate each theme from real HTTP, mirroring the pattern from
the bridge-actions split.
369 tests pass (was 334); 3 stability runs, same pre-existing
macOS-arm64 websocket addon failure, unrelated.
|