refactor(packages): rename @snowluma/bridge → @snowluma/protocol

The package previously named "bridge" houses the protocol-byte layer
(OIDB cmds, msg-push decoders, highway uploaders, element-builder,
event bus). The name "bridge" suggested transport/lifecycle, which it
isn't — that role lives in core/hook and core/bridge/manager. Rename
to match what's actually inside.

This is a pure rename: zero logic changes, all 73 import sites updated
mechanically and TS-verified. core/onebot dependencies key updated.
ESLint override path adjusted for the moved oidb-services directory.

Rename detection threshold: git log --find-renames=20% recommended
when following history across this commit — content-replacement
(@snowluma/bridge → @snowluma/protocol) dropped per-file similarity
below git's default 50% on import-heavy files.
This commit is contained in:
DrSmoothl committed 2026-05-23 23:31:03 +08:00
1 parent 98296fcec5
commit c16064d7e3
238 files changed
+247 -284

No files matched your search

@@ -0,0 +1,100 @@
// 0x7ED_12 — fetch QQ "thumbs up" (赞) summary for self or another user.
//
// Self lookup needs the bot's own UID, hence the `identity` dependency.
// For other users we use `resolveUserUid` to translate the uin first.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x7edReq, Oidb0x7edResp } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export interface LikeInfo {
uid: string;
time: number;
favoriteInfo: {
total_count: number;
last_time: number;
today_count: number;
userInfos: never[];
};
voteInfo: {
total_count: number;
new_count: number;
new_nearby_count: number;
last_visit_time: number;
userInfos: never[];
};
}
export namespace GetLike {
export const command = 0x7ED;
export const subCommand = 12;
export interface Params {
/** Omit / 0 → query self. */
userId?: number;
start?: number;
limit?: number;
}
export type Deps = OidbSender & Pick<BridgeContext, 'identity' | 'resolveUserUid'>;
export const serialize = async (ctx: Deps, p: Params): Promise<Oidb0x7edReq> => {
const targetUid = p.userId
? await ctx.resolveUserUid(p.userId)
: await resolveSelf(ctx);
if (!targetUid) throw new Error('target uid not found');
return {
targetUid,
basic: 1,
vote: 1,
favorite: 1,
start: p.start ?? 0,
limit: p.limit ?? 10,
};
};
export const deserialize = (_ctx: Deps, body: Oidb0x7edResp): LikeInfo => {
const data = body.userLikeInfos?.[0];
if (!data) throw new Error('get profile like info empty');
return {
uid: data.uid ?? '',
time: Number(data.time ?? 0),
favoriteInfo: {
total_count: data.favoriteInfo?.totalCount || 0,
last_time: Number(data.favoriteInfo?.lastTime || 0),
today_count: data.favoriteInfo?.newCount || 0,
userInfos: [],
},
voteInfo: {
total_count: data.voteInfo?.totalCount || 0,
new_count: data.voteInfo?.newCount || 0,
new_nearby_count: 0,
last_visit_time: Number(data.voteInfo?.lastTime || 0),
userInfos: [],
},
};
};
export const encode = (env: OidbBase<Oidb0x7edReq>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0x7edReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<Oidb0x7edResp> =>
protobuf_decode<OidbBase<Oidb0x7edResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<LikeInfo> =>
invokeOidb(deps, GetLike, params);
}
async function resolveSelf(deps: Pick<BridgeContext, 'identity' | 'resolveUserUid'>): Promise<string> {
// Mirrors `apis/shared.ts::resolveSelfUid` — kept inline here so the
// namespace is self-contained against just the BridgeContext slice.
const cached = deps.identity.selfUid;
if (cached) return cached;
const selfUin = Number(deps.identity.uin);
if (!Number.isFinite(selfUin) || selfUin <= 0) {
throw new Error('self uid is unavailable');
}
return deps.resolveUserUid(selfUin);
}
@@ -0,0 +1,52 @@
// 0xE17_0 — fetch the unidirectional friend block list. Wire name is
// non-standard (`MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0`) — uses
// the `wireName` override to bypass the default
// `OidbSvcTrpcTcp.0xNNNN_N` scheme.
//
// Request and response carry a JSON-encoded string in a single
// protobuf field, so the namespace's `serialize` / `deserialize` do
// the JSON marshalling.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0xe17Req, Oidb0xe17Resp } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export namespace GetUnidirectionalFriendList {
export const command = 0xE17;
export const subCommand = 0;
/** Wire name override — this cmd lives outside the standard
* `OidbSvcTrpcTcp.0xNNNN_N` namespace. */
export const wireName = (): string => 'MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0';
export interface Params {}
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
export const serialize = (ctx: Deps, _p: Params): Oidb0xe17Req => {
const reqObj = {
uint64_uin: String(ctx.identity.uin),
uint64_top: 0,
uint32_req_num: 99,
bytes_cookies: '',
};
return { jsonBody: JSON.stringify(reqObj) };
};
export const deserialize = (_ctx: Deps, body: Oidb0xe17Resp): unknown[] => {
if (!body || !body.jsonBody) throw new Error('get unidirectional friend list empty');
const parsed = JSON.parse(body.jsonBody);
return parsed.rpt_block_list || [];
};
export const encode = (env: OidbBase<Oidb0xe17Req>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0xe17Req>>(env);
export const decode = (bytes: Uint8Array): OidbBase<Oidb0xe17Resp> =>
protobuf_decode<OidbBase<Oidb0xe17Resp>>(bytes);
export const invoke = (deps: Deps): Promise<unknown[]> =>
invokeOidb(deps, GetUnidirectionalFriendList, {});
}
@@ -0,0 +1,47 @@
// 0xCD4_1 — set typing / recording / etc. "input status" indicator
// shown to a peer in a 1:1 chat.
//
// Resolves the target uin → uid via the identity service before
// building the body. `chatType: 0` is the wire constant for friend
// chats (the only flavor SnowLuma currently supports here).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0xcd4Req, Oidb0xcd4Resp } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export namespace SetInputStatus {
export const command = 0xCD4;
export const subCommand = 1;
export interface Params {
userId: number;
eventType: number;
}
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
export const serialize = async (ctx: Deps, p: Params): Promise<Oidb0xcd4Req> => {
const targetUid = await ctx.resolveUserUid(p.userId);
if (!targetUid) throw new Error('target uid not found');
return {
reqBody: {
uid: targetUid,
chatType: 0,
eventType: p.eventType,
},
};
};
export const deserialize = (_ctx: Deps, _: Oidb0xcd4Resp): void => {};
export const encode = (env: OidbBase<Oidb0xcd4Req>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0xcd4Req>>(env);
export const decode = (bytes: Uint8Array): OidbBase<Oidb0xcd4Resp> =>
protobuf_decode<OidbBase<Oidb0xcd4Resp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetInputStatus, params);
}
@@ -0,0 +1,50 @@
// 0x112A_2 — write profile string/int field-value pairs.
//
// SnowLuma's facade currently exposes only nickname (field 20002) and
// personalNote (field 102) but the underlying wire supports arbitrary
// (fieldId, value) tuples. The `invoke` short-circuits when both
// inputs are undefined so the facade's historic no-op-on-no-input
// behaviour is preserved (no wasted SSO round-trip).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x112aResp, OidbSetProfile } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export namespace SetProfile {
export const command = 0x112A;
export const subCommand = 2;
export interface Params {
nickname?: string;
personalNote?: string;
}
/** Needs identity to read `uin` for the request body. */
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
export const serialize = (ctx: Deps, p: Params): OidbSetProfile => {
const stringProfiles: { fieldId: number; value: string }[] = [];
if (p.nickname !== undefined) stringProfiles.push({ fieldId: 20002, value: p.nickname });
if (p.personalNote !== undefined) stringProfiles.push({ fieldId: 102, value: p.personalNote });
return { uin: BigInt(ctx.identity.uin), stringProfiles };
};
export const deserialize = (_ctx: Deps, _: Oidb0x112aResp): void => {};
export const encode = (env: OidbBase<OidbSetProfile>): Uint8Array =>
protobuf_encode<OidbBase<OidbSetProfile>>(env);
export const decode = (bytes: Uint8Array): OidbBase<Oidb0x112aResp> =>
protobuf_decode<OidbBase<Oidb0x112aResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> => {
// No-op when there's nothing to write — preserves the facade's
// historic short-circuit (avoid a wasted SSO round-trip).
if (params.nickname === undefined && params.personalNote === undefined) {
return Promise.resolve();
}
return invokeOidb(deps, SetProfile, params);
};
}
@@ -0,0 +1,39 @@
// 0x112A_2 — set the self "long nick" / personal signature. Same cmd
// as SetProfile but a different request shape (uses the single
// `profile: { tag, value }` field instead of the repeated string
// profiles list). Kept separate because the wire body is structurally
// different — proton needs distinct types so the codec is correctly
// monomorphized per call site.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x112aReq, Oidb0x112aResp } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export namespace SetSelfLongNick {
export const command = 0x112A;
export const subCommand = 2;
export interface Params {
longNick: string;
}
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
export const serialize = (ctx: Deps, p: Params): Oidb0x112aReq => ({
uin: BigInt(ctx.identity.uin),
profile: { tag: 102, value: String(p.longNick) },
});
export const deserialize = (_ctx: Deps, _: Oidb0x112aResp): void => {};
export const encode = (env: OidbBase<Oidb0x112aReq>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0x112aReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<Oidb0x112aResp> =>
protobuf_decode<OidbBase<Oidb0x112aResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetSelfLongNick, params);
}