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

+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,