refactor(proto-defs): extract wire-protobuf definitions into standalone package

Move `packages/core/src/bridge/proto/proton/*.ts` (13 files, ~3.3k
LOC) into a new `@snowluma/proto-defs` workspace package. The proton
spike landed in the previous commit means bare-specifier imports
(`@snowluma/proto-defs/oidb`, `…/message`, …) now resolve correctly
through proton's vite plugin, so call-site replacement still fires.

Why
---
- Lets downstream consumers share the same wire
  definitions without copy-pasting them — multiple workspace packages
  can now depend on `@snowluma/proto-defs` directly.
- Trims `@snowluma/core`'s surface: the bridge no longer owns the
  protocol schema, only its consumers.
- Sets up future #5 (`message-parsing perf`) and #6 (`Api-on-ctx
  refactor`) — both want a thinner core.

Layout
------
Per-file subpath exports (mirrors the legacy `proto/proton/<sub>`
shape 1:1). The barrel `index.ts` intentionally skips `highway` and
`oidb-actions/media` because the two files share six NTV2-prefixed
type names — `export *` would silently drop one side. Subpath imports
are unambiguous, which is also why every call site in core uses them.

Changes
-------
- New package `packages/proto-defs/` (package.json, tsconfig.json,
  src/index.ts).
- 13 `.ts` files moved via `git mv` to preserve history.
- 44 import sites across 26 source files + 15 tests rewritten via sed
  from `./[…/]proto/proton/<sub>` → `@snowluma/proto-defs/<sub>`.
- `@snowluma/core` depends on `@snowluma/proto-defs` (workspace:*).

Verification
------------
- proto-defs typecheck: clean
- core typecheck: clean
- core test suite: 587 passed (same baseline as before the refactor;
  one failure is the pre-existing websocket native addon, unrelated)
- proton test suite: 99 passed (8 files including the new
  cross-package.test.ts from the spike)
- Full workspace `pnpm -r typecheck`: all 8 projects clean

Note: proton's `dist/index.js` MUST be rebuilt for the vite plugin to
pick up the bare-specifier resolution. The previous commit's source
change is only effective after `pnpm -F @snowluma/proton build`.
This commit is contained in:
DrSmoothl committed 2026-05-20 21:31:30 +08:00
1 parent 994633eafa
commit 6c7e56d5a1
59 files changed
+212 -75

No files matched your search

+1
View File
@@ -14,6 +14,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@snowluma/proto-defs": "workspace:*",
"@snowluma/proton": "workspace:*",
"@snowluma/websocket": "workspace:*"
},
+3 -3
View File
@@ -1,18 +1,18 @@
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
import { OidbBase } from '../proto/proton/oidb';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbGroupTodo,
OidbStrangerStatusReq,
OidbStrangerStatusResp,
} from '../proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
import type {
OidbAiVoiceListReq,
OidbAiVoiceListResp,
OidbAiVoiceReq,
OidbAiVoiceResp,
} from '../proto/proton/oidb-actions/media';
} from '@snowluma/proto-defs/oidb-actions/media';
import type { MediaIndexNode } from './shared';
// ─────────────── Group todo (0xF90) ───────────────
+2 -2
View File
@@ -12,8 +12,8 @@ import type {
RecvLongMsgResp,
SendLongMsgReq,
SendLongMsgResp,
} from '../proto/proton/longmsg';
import type { FileExtra, PushMsg, PushMsgBody } from '../proto/proton/message';
} from '@snowluma/proto-defs/longmsg';
import type { FileExtra, PushMsg, PushMsgBody } from '@snowluma/proto-defs/message';
import { resolveSelfUid, toInt } from './shared';
// Module-scoped cache, keyed by res_id. Survives only for the lifetime
+2 -2
View File
@@ -1,12 +1,12 @@
import { protobuf_encode } from '@snowluma/proton';
import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
import { OidbBase } from '../proto/proton/oidb';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbDeleteFriend,
OidbFriendRequestAction,
OidbSetFriendRemark,
} from '../proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
export async function setFriendAddRequest(bridge: Bridge, uidOrFlag: string, approve: boolean): Promise<void> {
let targetUid = uidOrFlag;
@@ -1,7 +1,7 @@
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
import { OidbBase } from '../proto/proton/oidb';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
Oidb0x89a_0AddOption,
Oidb0x89a_0Search,
@@ -18,7 +18,7 @@ import type {
OidbRenameMember,
OidbSetAdmin,
OidbSpecialTitle,
} from '../proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
// ─────────────── mute / un-mute ───────────────
@@ -9,7 +9,7 @@ import type {
DoQunLikeResponse,
GetMediaListRequest,
GetMediaListResponse,
} from '../proto/proton/oidb-actions/group-album';
} from '@snowluma/proto-defs/oidb-actions/group-album';
export interface GroupAlbumMediaResult {
mediaList: any[];
@@ -5,8 +5,8 @@ import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
import { fetchHighwaySession, uploadHighwayHttp } from '../highway/highway-client';
import { computeHashes, computeMd5, FILE_UPLOAD_MAX_BYTES, loadBinarySource } from '../highway/utils';
import type { FileUploadExt } from '../proto/proton/highway';
import { OidbBase } from '../proto/proton/oidb';
import type { FileUploadExt } from '@snowluma/proto-defs/highway';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbGroupFileCountViewReq,
OidbGroupFileCountViewResp,
@@ -17,7 +17,7 @@ import type {
OidbGroupFileViewReq,
OidbGroupFileViewResp,
OidbGroupSendFileReq,
} from '../proto/proton/oidb-actions/group-file';
} from '@snowluma/proto-defs/oidb-actions/group-file';
import type {
NTV2RichMediaReq,
NTV2RichMediaResp,
@@ -25,7 +25,7 @@ import type {
OidbPrivateFileDownloadResp,
OidbPrivateFileUploadReq,
OidbPrivateFileUploadResp,
} from '../proto/proton/oidb-actions/media';
} from '@snowluma/proto-defs/oidb-actions/media';
import { ensureRetCodeZero, resolveSelfUid, toInt, type MediaIndexNode } from './shared';
const log = createLogger('GroupFile');
@@ -1,8 +1,8 @@
import { protobuf_encode } from '@snowluma/proton';
import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
import { OidbBase } from '../proto/proton/oidb';
import type { C2CRecallRequest, GroupRecallRequest, OidbEssence, SsoReadedReportReq } from '../proto/proton/oidb-actions/base';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import type { C2CRecallRequest, GroupRecallRequest, OidbEssence, SsoReadedReportReq } from '@snowluma/proto-defs/oidb-actions/base';
export async function recallGroupMessage(bridge: Bridge, groupId: number, sequence: number): Promise<void> {
const request = protobuf_encode<GroupRecallRequest>({
@@ -1,14 +1,14 @@
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
import { OidbBase } from '../proto/proton/oidb';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
Oidb0x9083Req,
Oidb0x9083Resp,
OidbGroupReaction,
OidbLike,
OidbPoke,
} from '../proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
export async function sendPoke(bridge: Bridge, isGroup: boolean, peerUin: number, targetUin?: number): Promise<void> {
const env = makeOidbEnvelope<OidbPoke>(0xED3, 1, {
+2 -2
View File
@@ -1,7 +1,7 @@
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
import { OidbBase } from '../proto/proton/oidb';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
MiniAppShareReq,
MiniAppShareResp,
@@ -11,7 +11,7 @@ import type {
Oidb0x990Resp,
Oidb0xeb7Req,
Oidb0xeb7Resp,
} from '../proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
export async function translateEn2Zh(
bridge: Bridge,
+2 -2
View File
@@ -3,7 +3,7 @@ import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
import { fetchHighwaySession, uploadHighwayHttp } from '../highway/highway-client';
import { computeHashes, loadBinarySource } from '../highway/utils';
import { OidbBase } from '../proto/proton/oidb';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FaceroamOpReq,
FaceroamOpResp,
@@ -19,7 +19,7 @@ import type {
OidbSetProfile,
SetStatusReq,
SetStatusResp,
} from '../proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
import { resolveSelfUid } from './shared';
// ─────────────── status / profile setters ───────────────
+3 -3
View File
@@ -7,7 +7,7 @@ import type {
OidbSvcTrpcTcp0xFD4_1Response,
OidbSvcTrpcTcp0xFE5_2Response,
OidbSvcTrpcTcp0xFE7_3Response,
} from './proto/proton/oidb';
} from '@snowluma/proto-defs/oidb';
import type {
AvatarInfo,
OidbFriendListRequest,
@@ -16,11 +16,11 @@ import type {
OidbGroupRequestList,
OidbUserInfoRequest,
OidbUserInfoResponse,
} from './proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
import type {
NTV2RichMediaReq,
NTV2RichMediaResp,
} from './proto/proton/oidb-actions/media';
} from '@snowluma/proto-defs/oidb-actions/media';
import type { FriendInfo, GroupMemberInfo, GroupRequestInfo, QQGroupInfo, UserProfileInfo } from './qq-info';
// ---------------------------------------------------------------------------
+1 -1
View File
@@ -1,6 +1,6 @@
import { protobuf_decode } from '@snowluma/proton';
import type { Bridge } from './bridge';
import type { OidbBase, OidbBaseMeta } from './proto/proton/oidb';
import type { OidbBase, OidbBaseMeta } from '@snowluma/proto-defs/oidb';
/**
* Build the OidbBase<T>-shaped TS value. Pure helper, no protobuf
+2 -2
View File
@@ -10,8 +10,8 @@ import { IncomingPacketPipeline, type CmdParser } from './packet-pipeline';
import type {
SendMessageRequest,
SendMessageResponse,
} from './proto/proton/action';
import type { FileExtra } from './proto/proton/message';
} from '@snowluma/proto-defs/action';
import type { FileExtra } from '@snowluma/proto-defs/message';
import type { FriendInfo, GroupMemberInfo, GroupRequestInfo, QQGroupInfo, UserProfileInfo } from './qq-info';
// Delegated modules
+2 -2
View File
@@ -8,8 +8,8 @@ import { uploadVideoMsgInfo } from './highway/video-upload';
import type {
MarkdownData,
MentionExtraSend,
} from './proto/proton/action';
import type { Elem, GroupFileExtra } from './proto/proton/element';
} from '@snowluma/proto-defs/action';
import type { Elem, GroupFileExtra } from '@snowluma/proto-defs/element';
type ProtoElem = Partial<Elem>;
@@ -7,7 +7,7 @@ import type {
NTV2RichMediaHighwayExt,
ReqDataHighwayHead,
RespDataHighwayHead,
} from '../proto/proton/highway';
} from '@snowluma/proto-defs/highway';
import { computeMd5, packHighwayFrame, unpackHighwayFrame } from './utils';
const HIGHWAY_APP_ID = 1600001604;
+2 -2
View File
@@ -7,8 +7,8 @@ import type {
EncodableMediaMsgInfo,
NTV2UploadRichMediaReq,
NTV2UploadRichMediaResp,
} from '../proto/proton/highway';
import { OidbBase } from '../proto/proton/oidb';
} from '@snowluma/proto-defs/highway';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import { buildHighwayExtend, fetchHighwaySession, uploadHighwayHttp } from './highway-client';
const moduleLog = createLogger('Highway');
+1 -1
View File
@@ -1,7 +1,7 @@
import { protobuf_decode } from '@snowluma/proton';
import type { PacketInfo } from '../../protocol/types';
import type { IdentityService } from '../identity-service';
import type { ContentHead, MessageBody, PushMsg, ResponseHead } from '../proto/proton/message';
import type { ContentHead, MessageBody, PushMsg, ResponseHead } from '@snowluma/proto-defs/message';
export type PushMsgBody = MessageBody;
export type PushMsgResponseHead = ResponseHead;
@@ -11,7 +11,7 @@ import type {
FriendRequest,
GeneralGrayTipInfo,
NewFriend,
} from '../../proto/proton/notify';
} from '@snowluma/proto-defs/notify';
import type { MsgPushContext } from '../context';
import { Event0x210SubType } from '../enums';
import {
@@ -12,7 +12,7 @@ import type {
GroupMute,
GroupReactNotify,
NotifyMessageBody,
} from '../../proto/proton/notify';
} from '@snowluma/proto-defs/notify';
import type { MsgPushContext } from '../context';
import { Event0x2DCSubType } from '../enums';
import {
@@ -1,6 +1,6 @@
import { protobuf_decode } from '@snowluma/proton';
import type { GroupAdminEvent } from '../../events';
import type { GroupAdmin } from '../../proto/proton/notify';
import type { GroupAdmin } from '@snowluma/proto-defs/notify';
import { resolveUidToUin } from '../helpers';
import type { MsgPushDecoder } from '../registry';
@@ -3,7 +3,7 @@ import type { GroupInviteEvent } from '../../events';
import type {
GroupInvitation, GroupInvite,
GroupJoin,
} from '../../proto/proton/notify';
} from '@snowluma/proto-defs/notify';
import { resolveUidToUin } from '../helpers';
import type { MsgPushDecoder } from '../registry';
@@ -1,6 +1,6 @@
import { protobuf_decode } from '@snowluma/proton';
import type { GroupMemberJoin, GroupMemberLeave } from '../../events';
import type { GroupChange, SelfJoinInGroup } from '../../proto/proton/notify';
import type { GroupChange, SelfJoinInGroup } from '@snowluma/proto-defs/notify';
import { decodeOperatorUid, resolveUidToUin } from '../helpers';
import type { MsgPushDecoder } from '../registry';
+1 -1
View File
@@ -1,7 +1,7 @@
import { protobuf_decode } from '@snowluma/proton';
import { inflateSync } from 'zlib';
import type { IdentityService } from '../identity-service';
import type { OperatorInfo } from '../proto/proton/notify';
import type { OperatorInfo } from '@snowluma/proto-defs/notify';
export function makeImageUrl(origUrl: string): string {
if (!origUrl) return '';
@@ -9,8 +9,8 @@ import type {
NotOnlineImage,
QFaceExtra,
QSmallFaceExtra,
} from '../proto/proton/element';
import type { FileExtra, MessageBody, RichText } from '../proto/proton/message';
} from '@snowluma/proto-defs/element';
import type { FileExtra, MessageBody, RichText } from '@snowluma/proto-defs/message';
import { decompressData, makeImageUrl } from './helpers';
type ElemDecoded = Elem;
@@ -1,13 +1,13 @@
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
import { OidbBase } from '../proto/proton/oidb';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbClientKeyReq,
OidbClientKeyResp,
OidbGetPskeyReq,
OidbGetPskeyResp,
} from '../proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
import { RequestUtil } from '../web/request-util';
export async function forceFetchClientKey(bridge: Bridge) {
@@ -138,7 +138,7 @@ export async function sendPrivateMessage(
// C2C `{type:'file'}` segments can't ride on the elems[] pipeline —
// c2c files live on `RichText.notOnlineFile`, parallel to elems
// (see `proto/proton/message.ts:notOnlineFile`). The element-builder
// (see `@snowluma/proto-defs/message:notOnlineFile`). The element-builder
// explicitly drops them with a warn ("file send via elems[] is
// group-only"), so a private message that bundled a file alongside
// anything else used to either ship as "[空消息]" (only-file case,
+3 -3
View File
@@ -1,13 +1,13 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbStrangerStatusResp,
} from '../../src/bridge/proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
import type {
OidbAiVoiceListResp,
OidbAiVoiceResp,
} from '../../src/bridge/proto/proton/oidb-actions/media';
} from '@snowluma/proto-defs/oidb-actions/media';
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
// that the plugin substitutes at the call site with the inlined codec, so
@@ -45,7 +45,7 @@ vi.mock('../../src/bridge/element-builder', () => ({
}));
import { protobuf_encode } from '@snowluma/proton';
import type { SendLongMsgResp } from '../../src/bridge/proto/proton/longmsg';
import type { SendLongMsgResp } from '@snowluma/proto-defs/longmsg';
import * as forward from '../../src/bridge/actions/forward';
import { mockBridge } from './_helpers';
+1 -1
View File
@@ -15,7 +15,7 @@ vi.mock('../../src/bridge/element-builder', () => ({
}));
import { protobuf_encode } from '@snowluma/proton';
import type { SendLongMsgResp } from '../../src/bridge/proto/proton/longmsg';
import type { SendLongMsgResp } from '@snowluma/proto-defs/longmsg';
import * as forward from '../../src/bridge/actions/forward';
import { mockBridge } from './_helpers';
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
import type { Oidb0x8a7Resp } from '../../src/bridge/proto/proton/oidb-actions/base';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x8a7Resp } from '@snowluma/proto-defs/oidb-actions/base';
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
// that the plugin substitutes at the call site with the inlined codec, so
@@ -1,16 +1,16 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbGroupFileCountViewResp,
OidbGroupFileResp,
OidbGroupFileViewResp,
OidbGroupFileFolderResp,
} from '../../src/bridge/proto/proton/oidb-actions/group-file';
} from '@snowluma/proto-defs/oidb-actions/group-file';
import type {
OidbPrivateFileUploadResp,
NTV2RichMediaResp,
} from '../../src/bridge/proto/proton/oidb-actions/media';
} from '@snowluma/proto-defs/oidb-actions/media';
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
// (substituted at the call site with the inlined codec). Mocking them on
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
import type { Oidb0x9083Resp } from '../../src/bridge/proto/proton/oidb-actions/base';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x9083Resp } from '@snowluma/proto-defs/oidb-actions/base';
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
// that the plugin substitutes at the call site for the inlined codec.
+2 -2
View File
@@ -1,10 +1,10 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
Oidb0x990Resp,
Oidb0x112eResp,
} from '../../src/bridge/proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
// — the plugin substitutes them at the call site with the inlined codec,
+2 -2
View File
@@ -1,13 +1,13 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
GroupAvatarExtra,
Oidb0x7edResp,
Oidb0xe17Resp,
SetStatusReq,
SetStatusResp,
} from '../../src/bridge/proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
// (substituted at the call site with the inlined codec). Mocking them on
@@ -1,8 +1,8 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { SendPacketResult } from '../src/protocol/packet-sender';
import type { SendMessageRequest, SendMessageResponse } from '../src/bridge/proto/proton/action';
import type { FileExtra } from '../src/bridge/proto/proton/message';
import type { SendMessageRequest, SendMessageResponse } from '@snowluma/proto-defs/action';
import type { FileExtra } from '@snowluma/proto-defs/message';
vi.mock('../src/bridge/element-builder', () => ({
buildSendElems: vi.fn(async () => [{ text: { str: 'stub media elem' } }]),
@@ -7,7 +7,7 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { GroupReactNotify } from '../src/bridge/proto/proton/notify';
import type { GroupReactNotify } from '@snowluma/proto-defs/notify';
import { decodeEvent0x2DC } from '../src/bridge/msg-push/decoders/event-0x2dc';
import type { MsgPushContext } from '../src/bridge/msg-push/context';
import { IdentityService } from '../src/bridge/identity-service';
+2 -2
View File
@@ -24,8 +24,8 @@ import {
runNtv2Upload,
type MediaSubFileUpload,
} from '../../src/bridge/highway/pipeline';
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
import type { EncodableMediaMsgInfo, NTV2UploadRichMediaReq, NTV2UploadRichMediaResp } from '../../src/bridge/proto/proton/highway';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { EncodableMediaMsgInfo, NTV2UploadRichMediaReq, NTV2UploadRichMediaResp } from '@snowluma/proto-defs/highway';
interface FakeUploadResponse {
upload?: {
+3 -3
View File
@@ -5,9 +5,9 @@ import { describe, it, expect, vi } from 'vitest';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { parseMessage } from '../src/onebot/message-parser';
import { buildSendElems } from '../src/bridge/element-builder';
import type { MentionExtraSend } from '../src/bridge/proto/proton/action';
import type { OidbBase } from '../src/bridge/proto/proton/oidb';
import type { NTV2UploadRichMediaResp } from '../src/bridge/proto/proton/highway';
import type { MentionExtraSend } from '@snowluma/proto-defs/action';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { NTV2UploadRichMediaResp } from '@snowluma/proto-defs/highway';
describe('parseMessage', () => {
describe('plain text', () => {
+2 -2
View File
@@ -14,8 +14,8 @@ import type { GroupMemberInfo, QQGroupInfo } from '../src/bridge/qq-info';
// inline-extract the kind.
import type {
GroupChange, NewFriend, FriendRecall, OperatorInfo, SelfJoinInGroup,
} from '../src/bridge/proto/proton/notify';
import type { PushMsg } from '../src/bridge/proto/proton/message';
} from '@snowluma/proto-defs/notify';
import type { PushMsg } from '@snowluma/proto-defs/message';
import type {
GroupMemberJoin, FriendAddEvent, QQEventVariant,
} from '../src/bridge/events';
@@ -25,8 +25,8 @@ import {
runNtv2Upload,
type MediaSubFileUpload,
} from '../src/bridge/highway/pipeline';
import type { OidbBase } from '../src/bridge/proto/proton/oidb';
import type { NTV2UploadRichMediaResp } from '../src/bridge/proto/proton/highway';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { NTV2UploadRichMediaResp } from '@snowluma/proto-defs/highway';
import { MsgPushRegistry } from '../src/bridge/msg-push/registry';
import type { MsgPushContext } from '../src/bridge/msg-push/context';
import { decodeEvent0x2DC } from '../src/bridge/msg-push/decoders/event-0x2dc';
@@ -1,10 +1,10 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbClientKeyResp,
OidbGetPskeyResp,
} from '../../src/bridge/proto/proton/oidb-actions/base';
} from '@snowluma/proto-defs/oidb-actions/base';
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
// — the plugin substitutes them at the call site with the inlined codec,
+73
View File
@@ -0,0 +1,73 @@
{
"name": "@snowluma/proto-defs",
"version": "1.9.0",
"private": true,
"type": "module",
"description": "SnowLuma QQ/Lagrange wire-protobuf type definitions. Pure TypeScript interfaces with proton's `pb<N, T>` marker types — `@snowluma/proton`'s vite plugin compiles them into zero-runtime encoder/decoder functions at the call sites in `@snowluma/core` (and any downstream consumer). Exposed as per-file subpaths (`@snowluma/proto-defs/oidb`, `@snowluma/proto-defs/message`, …) so the import-site shape mirrors the legacy `bridge/proto/proton/*` layout and avoids name collisions across files (notably `highway.ts` and `oidb-actions/media.ts` share NTV2-prefixed names).",
"main": "./src/index.ts",
"types": "./src/index.ts",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./src/index.ts"
},
"./action": {
"types": "./src/action.ts",
"default": "./src/action.ts"
},
"./element": {
"types": "./src/element.ts",
"default": "./src/element.ts"
},
"./highway": {
"types": "./src/highway.ts",
"default": "./src/highway.ts"
},
"./longmsg": {
"types": "./src/longmsg.ts",
"default": "./src/longmsg.ts"
},
"./message": {
"types": "./src/message.ts",
"default": "./src/message.ts"
},
"./notify": {
"types": "./src/notify.ts",
"default": "./src/notify.ts"
},
"./oidb": {
"types": "./src/oidb.ts",
"default": "./src/oidb.ts"
},
"./oidb-action": {
"types": "./src/oidb-action.ts",
"default": "./src/oidb-action.ts"
},
"./oidb-actions/base": {
"types": "./src/oidb-actions/base.ts",
"default": "./src/oidb-actions/base.ts"
},
"./oidb-actions/group-album": {
"types": "./src/oidb-actions/group-album.ts",
"default": "./src/oidb-actions/group-album.ts"
},
"./oidb-actions/group-file": {
"types": "./src/oidb-actions/group-file.ts",
"default": "./src/oidb-actions/group-file.ts"
},
"./oidb-actions/media": {
"types": "./src/oidb-actions/media.ts",
"default": "./src/oidb-actions/media.ts"
}
},
"scripts": {
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@snowluma/proton": "workspace:*"
},
"devDependencies": {
"@types/node": "^24.12.2",
"typescript": "catalog:"
}
}
+34
View File
@@ -0,0 +1,34 @@
// SnowLuma wire-protobuf type definitions.
//
// This barrel exists so `@snowluma/proto-defs` can be resolved by a
// plain `import {} from '@snowluma/proto-defs'` (consumers that don't
// know which sub-namespace they want, or just want to see what's
// available). The package itself is otherwise consumed via the
// per-file subpath exports declared in package.json — that's the
// recommended import shape because it mirrors the legacy
// `bridge/proto/proton/<sub>` paths 1:1 and avoids name collisions.
//
// ─── Collision note ───
//
// `highway.ts` and `oidb-actions/media.ts` each define their own
// `NTV2*` types (NTV2CommonHead, NTV2ClientMeta, NTV2C2CUserInfo,
// NTV2FileInfo, NTV2FileType, NTV2GroupInfo). The two definitions
// are NOT compatible — they describe different wire shapes for
// different protocol surfaces and happen to share the same name in
// the upstream Lagrange schema. `export *` silently drops one side
// when names collide, so a consumer that grabs an `NTV2CommonHead`
// off the barrel might end up with the wrong one. Prefer the subpath
// imports below for any NTV2-named type.
export type * from './action.js';
export type * from './element.js';
// NOTE: `highway.ts` intentionally NOT re-exported here — see note above.
export type * from './longmsg.js';
export type * from './message.js';
export type * from './notify.js';
export type * from './oidb.js';
export type * from './oidb-action.js';
export type * from './oidb-actions/base.js';
export type * from './oidb-actions/group-album.js';
export type * from './oidb-actions/group-file.js';
// NOTE: `oidb-actions/media.ts` intentionally NOT re-exported — see note above.
+13
View File
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node"],
"noEmit": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
]
}
+16
View File
@@ -50,6 +50,9 @@ importers:
packages/core:
dependencies:
'@snowluma/proto-defs':
specifier: workspace:*
version: link:../proto-defs
'@snowluma/proton':
specifier: workspace:*
version: link:../proton
@@ -88,6 +91,19 @@ importers:
specifier: ^4.1.4
version: 4.1.4(@types/[email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]))
packages/proto-defs:
dependencies:
'@snowluma/proton':
specifier: workspace:*
version: link:../proton
devDependencies:
'@types/node':
specifier: ^24.12.2
version: 24.12.2
typescript:
specifier: 'catalog:'
version: 6.0.2
packages/proton:
dependencies:
typescript: