refactor(bridge): extract protocol layer into @snowluma/bridge package
Phase 2 of the 4-package split (RoadMap #3). Moves ~35 files — events / event-bus / identity-service / packet-pipeline / element- builder / bridge-oidb / qq-info / msg-push/* / highway/* / web/* + the bridge-side formatters — out of `packages/core/src/bridge/` into the new `@snowluma/bridge` workspace package. Everything that translates QQ wire bytes ↔ typed events/elements now lives there. Why --- - `packages/core/src/bridge/` was actually two layers: a low-level "protocol decoder + I/O" set (msg-push, highway, packet-pipeline, identity, element-builder) AND the Api-class host (bridge.ts + apis/*). The Api layer can't move without the protocol layer moving first, but the two had grown into one directory. - Bridge-internal consumers (highway uploaders, OIDB envelope helper, element-builder, msg-push parsers) only ever needed `bridge.identity` + `bridge.sendRawPacket` + the upload-metadata cache. Splitting them out lets that minimal surface live in the bridge package as `BridgeContext` while the api-layer's extended context (with `apis: ApiHub`) stays in @snowluma/core. What stays in @snowluma/core (apis layer): - bridge.ts ── the god-class that composes the protocol building blocks + mounts apis - bridge-interface.ts ── public façade for OneBot consumers - manager.ts ── per-uin BridgeManager hub - apis/* ── the 13 typed Api classes - bridge-context.ts (NEW) ── extends @snowluma/bridge's slim BridgeContext with `apis: ApiHub` so the 13 Api classes keep their typed `this.ctx.apis.X.method()` access. Layout ------ Moved via `git mv` (history preserved): events / event-bus / identity-service / packet-pipeline / element-builder / bridge-oidb / qq-info / msg-push/* / highway/* / web/* → @snowluma/bridge/<sub> utils/event-format.ts → @snowluma/bridge/format.ts (the last one renamed because the destination directory only has bridge-related files; `format.ts` reads cleaner than `event-format`. Listed as a rename in git's `RM` output — content unchanged.) Layering fixes (functionality preserved, just type signatures) -------------------------------------------------------------- - `element-builder.SendContext.bridge` → typed as `BridgeContext` instead of `Bridge`. Reads only `bridge.identity` and the upload-cache (both on BridgeContext); the concrete `Bridge` instance still passes via free upcast. - `bridge-oidb.runOidb` signature widened from `Bridge` to `BridgeContext` — same reason. - `highway/{highway-client,pipeline,image-upload,ptt-upload, video-upload}.ts` — same. - `format.ts::formatReply` parameter typed as a new local `ReplyEventLookup` structural type (`{ findEvent(id): JsonObject | null }`) instead of `MessageStore` from @snowluma/onebot. The OneBot `MessageStore` is a structural superset; consumers pass it through unchanged. - JSON value types moved to a new `@snowluma/common/json` subpath (consumed by format.ts) — `onebot/types.ts` re-exports them so external `import { JsonValue } from '<…>/onebot/types'` paths keep working. - `UploadedFileMeta` interface moved from `core/src/bridge/bridge.ts` into `@snowluma/bridge/bridge-context.ts` — element-builder + the forward-builder both read the upload cache through BridgeContext, so the type has to live in @snowluma/bridge. `bridge.ts` keeps its re-export for back-compat. Changes ------- - New package `packages/bridge/` (package.json with per-file subpath exports mirroring legacy `core/src/bridge/<x>` layout 1:1, tsconfig.json, typecheck script). - 35 `.ts` files moved via `git mv` (3 files counted by git as RM — rename + modify because Bridge → BridgeContext type swap). - 150+ import sites rewritten across `packages/core/src` and `packages/core/tests`: `'../bridge/<x>'`, `'../../bridge/<x>'`, `'../src/bridge/<x>'`, `'@/bridge/web/<x>'`, and vitest `vi.mock(...)` literals all collapse to `@snowluma/bridge/<x>`. - `@snowluma/core` depends on `@snowluma/bridge` (workspace:*). - `@snowluma/bridge` depends on `@snowluma/common`, `@snowluma/proto-defs`, `@snowluma/proton`. - `packages/core/src/utils/` directory removed (empty). Verification ------------ - Full workspace `pnpm -r typecheck`: all 10 projects clean. - core test suite: 552 passed / 552 total (pre-existing websocket-darwin-arm64.node addon failure unchanged — same baseline as the previous refactor commits). - Vite build (with stubbed native binary): clean — 143 modules, 2.84 MB bundle / 224 KB gzip, identical envelope to the pre-split build. Phase 3 (next): OneBot + WebUI move into @snowluma/onebot. The runnable `index.ts` stays in @snowluma/core as the application entry, importing `OneBotManager` from `@snowluma/onebot`.
This commit is contained in:
107 files changed
+467
-229
No files matched your search
@@ -0,0 +1,127 @@
|
||||
{
|
||||
"name": "@snowluma/bridge",
|
||||
"version": "1.9.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "SnowLuma bridge — the protocol-layer between QQ wire bytes and typed events. Owns: identity service (uid↔uin cache with SQLite persistence), event bus, packet pipeline (incoming SSO packet → QQEventVariant), msg-push decoders, element-builder (MessageElement → wire elems[]), highway upload protocol (file/image/video/ptt), OIDB envelope helper, and the event/notice/request type vocabulary. Consumers (@snowluma/core, @snowluma/onebot) talk to this package through `BridgeContext` for runtime calls and the standalone classes (IdentityService, BridgeEventBus, IncomingPacketPipeline) for composition. Per-file subpath exports mirror the legacy `core/src/bridge/*` layout 1:1 so the previous `import { …} from '../bridge/<x>'` collapses to `import { … } from '@snowluma/bridge/<x>'`.",
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"default": "./src/index.ts"
|
||||
},
|
||||
"./events": {
|
||||
"types": "./src/events.ts",
|
||||
"default": "./src/events.ts"
|
||||
},
|
||||
"./event-bus": {
|
||||
"types": "./src/event-bus.ts",
|
||||
"default": "./src/event-bus.ts"
|
||||
},
|
||||
"./identity-service": {
|
||||
"types": "./src/identity-service.ts",
|
||||
"default": "./src/identity-service.ts"
|
||||
},
|
||||
"./packet-pipeline": {
|
||||
"types": "./src/packet-pipeline.ts",
|
||||
"default": "./src/packet-pipeline.ts"
|
||||
},
|
||||
"./element-builder": {
|
||||
"types": "./src/element-builder.ts",
|
||||
"default": "./src/element-builder.ts"
|
||||
},
|
||||
"./bridge-oidb": {
|
||||
"types": "./src/bridge-oidb.ts",
|
||||
"default": "./src/bridge-oidb.ts"
|
||||
},
|
||||
"./bridge-context": {
|
||||
"types": "./src/bridge-context.ts",
|
||||
"default": "./src/bridge-context.ts"
|
||||
},
|
||||
"./qq-info": {
|
||||
"types": "./src/qq-info.ts",
|
||||
"default": "./src/qq-info.ts"
|
||||
},
|
||||
"./format": {
|
||||
"types": "./src/format.ts",
|
||||
"default": "./src/format.ts"
|
||||
},
|
||||
"./msg-push": {
|
||||
"types": "./src/msg-push/index.ts",
|
||||
"default": "./src/msg-push/index.ts"
|
||||
},
|
||||
"./msg-push/registry": {
|
||||
"types": "./src/msg-push/registry.ts",
|
||||
"default": "./src/msg-push/registry.ts"
|
||||
},
|
||||
"./msg-push/context": {
|
||||
"types": "./src/msg-push/context.ts",
|
||||
"default": "./src/msg-push/context.ts"
|
||||
},
|
||||
"./msg-push/decoders/event-0x2dc": {
|
||||
"types": "./src/msg-push/decoders/event-0x2dc.ts",
|
||||
"default": "./src/msg-push/decoders/event-0x2dc.ts"
|
||||
},
|
||||
"./highway": {
|
||||
"types": "./src/highway/highway-client.ts",
|
||||
"default": "./src/highway/highway-client.ts"
|
||||
},
|
||||
"./highway/utils": {
|
||||
"types": "./src/highway/utils.ts",
|
||||
"default": "./src/highway/utils.ts"
|
||||
},
|
||||
"./highway/pipeline": {
|
||||
"types": "./src/highway/pipeline.ts",
|
||||
"default": "./src/highway/pipeline.ts"
|
||||
},
|
||||
"./highway/image-upload": {
|
||||
"types": "./src/highway/image-upload.ts",
|
||||
"default": "./src/highway/image-upload.ts"
|
||||
},
|
||||
"./highway/ptt-upload": {
|
||||
"types": "./src/highway/ptt-upload.ts",
|
||||
"default": "./src/highway/ptt-upload.ts"
|
||||
},
|
||||
"./highway/video-upload": {
|
||||
"types": "./src/highway/video-upload.ts",
|
||||
"default": "./src/highway/video-upload.ts"
|
||||
},
|
||||
"./highway/ffmpeg-addon": {
|
||||
"types": "./src/highway/ffmpeg-addon.ts",
|
||||
"default": "./src/highway/ffmpeg-addon.ts"
|
||||
},
|
||||
"./web/group-album": {
|
||||
"types": "./src/web/group-album.ts",
|
||||
"default": "./src/web/group-album.ts"
|
||||
},
|
||||
"./web/group-essence": {
|
||||
"types": "./src/web/group-essence.ts",
|
||||
"default": "./src/web/group-essence.ts"
|
||||
},
|
||||
"./web/group-honor": {
|
||||
"types": "./src/web/group-honor.ts",
|
||||
"default": "./src/web/group-honor.ts"
|
||||
},
|
||||
"./web/group-notice": {
|
||||
"types": "./src/web/group-notice.ts",
|
||||
"default": "./src/web/group-notice.ts"
|
||||
},
|
||||
"./web/request-util": {
|
||||
"types": "./src/web/request-util.ts",
|
||||
"default": "./src/web/request-util.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@snowluma/common": "workspace:*",
|
||||
"@snowluma/proto-defs": "workspace:*",
|
||||
"@snowluma/proton": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.12.2",
|
||||
"typescript": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// BridgeContext — the protocol-layer surface that anything inside
|
||||
// @snowluma/bridge (highway uploaders, OIDB envelope helper, element
|
||||
// builder, msg-push parsers) accepts when it needs `bridge.identity`
|
||||
// or `bridge.sendRawPacket` plus the upload-metadata cache.
|
||||
//
|
||||
// Deliberately apis-less: @snowluma/bridge knows nothing about the
|
||||
// `apis.<area>.method()` hub that lives in @snowluma/core, so the
|
||||
// type that bridge code accepts must NOT mention `ApiHub`. The api-
|
||||
// layer's own extended context (with `apis: ApiHub`) lives at
|
||||
// @snowluma/core's same-named file and `extends` this one — Api
|
||||
// classes import from THERE, bridge helpers import from HERE.
|
||||
//
|
||||
// The concrete `Bridge` class (in @snowluma/core) implements the
|
||||
// extended interface, which is a superset of this one. Passing a
|
||||
// `Bridge` where a slim `BridgeContext` is expected is a free upcast.
|
||||
|
||||
import type { IdentityService } from './identity-service';
|
||||
import type { BridgeEventBus } from './event-bus';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
/**
|
||||
* Metadata remembered after `upload_group_file` / `upload_private_file`
|
||||
* succeeds. Lets the OneBot send-message path reconstruct the full
|
||||
* payload when the caller only echoes the `file_id` back later. Lives
|
||||
* here (not on @snowluma/core's `bridge.ts`) so element-builder + the
|
||||
* forward-builder — both inside @snowluma/bridge — can read the cache
|
||||
* without circular-importing @snowluma/core.
|
||||
*/
|
||||
export interface UploadedFileMeta {
|
||||
fileId: string;
|
||||
scope: 'group' | 'private';
|
||||
/** Group id if scope='group', else `undefined`. */
|
||||
groupId?: number;
|
||||
/** Friend uin if scope='private', else `undefined`. */
|
||||
userId?: number;
|
||||
fileName: string;
|
||||
fileSize: number;
|
||||
fileMd5: Uint8Array;
|
||||
fileSha1: Uint8Array;
|
||||
/** Server-issued hash returned alongside the upload (private only). */
|
||||
fileHash?: string;
|
||||
/** Insert time — used to evict the oldest entry when the cache fills. */
|
||||
rememberedAt: number;
|
||||
}
|
||||
|
||||
export interface BridgeContext {
|
||||
// ── Per-instance state (one set per QQ account in a multi-account
|
||||
// runtime; `BridgeManager` allocates one `Bridge` per uin and
|
||||
// each Bridge owns its own identity/events/pipeline/apis). ──
|
||||
readonly identity: IdentityService;
|
||||
readonly events: BridgeEventBus;
|
||||
|
||||
// ── Raw I/O ──
|
||||
/** Escape hatch for arbitrary protocol calls (used by Api classes
|
||||
* and by the `send_packet` OneBot action). Every typed wrapper on an
|
||||
* Api class eventually routes through here. */
|
||||
sendRawPacket(serviceCmd: string, body: Uint8Array, timeoutMs?: number): Promise<SendPacketResult>;
|
||||
/** uin → uid lookup (cached in IdentityService). `groupId` is an
|
||||
* optional hint that lets the resolver fall back to a group-member
|
||||
* roster when the friend list doesn't have the uin. */
|
||||
resolveUserUid(uin: number, groupId?: number): Promise<string>;
|
||||
|
||||
// ── Send-side protocol helpers (Api classes that build a
|
||||
// `SendMessageRequest` need these monotonic generators to fill in
|
||||
// `clientSequence` and `random`). They were previously `private`
|
||||
// on Bridge — promoted to public so the new Api classes can call
|
||||
// them without `(bridge as any).nextXxx()`. ──
|
||||
nextMessageRandom(): number;
|
||||
nextClientSequence(): number;
|
||||
|
||||
// ── Uploaded-file metadata cache ──
|
||||
//
|
||||
// Bookkeeping shared between `GroupFileApi.upload*File` (writes the
|
||||
// tuple at upload time) and `MessageApi.sendPrivateMessage` (reads
|
||||
// it on later `send_msg` calls that carry only a file_id). Lives at
|
||||
// this layer rather than inside `GroupFileApi` because the message
|
||||
// send path is what queries the cache, and it shouldn't have to
|
||||
// reach into a different Api class for an infrastructure lookup.
|
||||
rememberUploadedFile(meta: UploadedFileMeta): void;
|
||||
recallUploadedFile(fileId: string): UploadedFileMeta | undefined;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import type { Bridge } from './bridge';
|
||||
import type { BridgeContext } from './bridge-context';
|
||||
import type { OidbBase, OidbBaseMeta } from '@snowluma/proto-defs/oidb';
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ export function makeOidbEnvelope<T>(
|
||||
* packet carried no payload).
|
||||
*/
|
||||
export async function runOidb(
|
||||
bridge: Bridge,
|
||||
bridge: BridgeContext,
|
||||
cmd: string,
|
||||
envelopeBytes: Uint8Array,
|
||||
timeoutMs?: number,
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { Bridge } from './bridge';
|
||||
import type { BridgeContext } from './bridge-context';
|
||||
import type { MessageElement } from './events';
|
||||
import { uploadImageMsgInfo } from './highway/image-upload';
|
||||
import { hexToBytes } from './highway/pipeline';
|
||||
@@ -14,7 +14,7 @@ import type { Elem, GroupFileExtra } from '@snowluma/proto-defs/element';
|
||||
type ProtoElem = Partial<Elem>;
|
||||
|
||||
export interface SendContext {
|
||||
bridge: Bridge;
|
||||
bridge: BridgeContext;
|
||||
groupId?: number;
|
||||
userUid?: string;
|
||||
/**
|
||||
File renamed without changes.
File renamed without changes.
@@ -1,7 +1,18 @@
|
||||
import type { QQEventVariant } from '../bridge/events';
|
||||
import type { IdentityService } from '../bridge/identity-service';
|
||||
import type { MessageStore } from '../onebot/message-store';
|
||||
import type { JsonObject, JsonValue } from '../onebot/types';
|
||||
import type { QQEventVariant } from './events';
|
||||
import type { IdentityService } from './identity-service';
|
||||
import type { JsonObject, JsonValue } from '@snowluma/common/json';
|
||||
|
||||
/**
|
||||
* Minimal shape of the OneBot-side `MessageStore` that `formatReply`
|
||||
* needs — just `findEvent(id)`. Defined inline (instead of importing
|
||||
* the full `MessageStore` class from @snowluma/onebot) so this
|
||||
* package doesn't depend on the OneBot layer above it. The OneBot
|
||||
* `MessageStore` is structurally a superset of this interface, so
|
||||
* callers pass it through with zero adaptation.
|
||||
*/
|
||||
export interface ReplyEventLookup {
|
||||
findEvent(messageId: number): JsonObject | null;
|
||||
}
|
||||
|
||||
const MAX_TEXT_PREVIEW = 50;
|
||||
const MAX_REPLY_BODY_PREVIEW = 30;
|
||||
@@ -110,7 +121,7 @@ function truncate(s: string, max: number): string {
|
||||
* to" questions.
|
||||
*/
|
||||
export function formatReply(
|
||||
messageStore: MessageStore,
|
||||
messageStore: ReplyEventLookup,
|
||||
identity: IdentityService,
|
||||
replyId: number,
|
||||
): string {
|
||||
File renamed without changes.
+3
-3
@@ -1,6 +1,6 @@
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import net from 'net';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type {
|
||||
HttpConn0x6FF501Request,
|
||||
HttpConn0x6FF501Response,
|
||||
@@ -27,7 +27,7 @@ function ipv4ToString(value: number): string {
|
||||
return `${value & 0xFF}.${(value >> 8) & 0xFF}.${(value >> 16) & 0xFF}.${(value >> 24) & 0xFF}`;
|
||||
}
|
||||
|
||||
export async function fetchHighwaySession(bridge: Bridge): Promise<HighwaySession> {
|
||||
export async function fetchHighwaySession(bridge: BridgeContext): Promise<HighwaySession> {
|
||||
const request = protobuf_encode<HttpConn0x6FF501Request>({
|
||||
httpConn: {
|
||||
field1: 0, field2: 0, field3: 16, field4: 1, field6: 3,
|
||||
@@ -218,7 +218,7 @@ async function httpPostFrame(
|
||||
}
|
||||
|
||||
export async function uploadHighwayHttp(
|
||||
bridge: Bridge, session: HighwaySession, commandId: number,
|
||||
bridge: BridgeContext, session: HighwaySession, commandId: number,
|
||||
bytes: Uint8Array, fileMd5: Uint8Array, extend: Uint8Array,
|
||||
): Promise<void> {
|
||||
const pathStr = `/cgi-bin/httpconn?htcmd=0x6FF0087&uin=${bridge.identity.uin}`;
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { MessageElement } from '../events';
|
||||
import { GROUP_IMAGE_CMD_ID, PRIVATE_IMAGE_CMD_ID } from './highway-client';
|
||||
import {
|
||||
@@ -12,7 +12,7 @@ import { computeHashes, detectImageFormat, loadBinarySource } from './utils';
|
||||
|
||||
const moduleLog = createLogger('Highway.Image');
|
||||
|
||||
function loggerFor(bridge: Bridge) {
|
||||
function loggerFor(bridge: BridgeContext) {
|
||||
const raw = bridge.identity?.uin;
|
||||
const uin = typeof raw === 'string' ? Number.parseInt(raw, 10) : 0;
|
||||
return Number.isFinite(uin) && uin > 0 ? moduleLog.child({ uin }) : moduleLog;
|
||||
@@ -103,7 +103,7 @@ async function loadImageFromSource(source: string, fileName: string, subType: nu
|
||||
* commonElem.
|
||||
*/
|
||||
export async function uploadImageMsgInfo(
|
||||
bridge: Bridge,
|
||||
bridge: BridgeContext,
|
||||
isGroup: boolean,
|
||||
targetIdOrUid: string | number,
|
||||
element: MessageElement,
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import crypto from 'crypto';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import { makeOidbEnvelope } from '../bridge-oidb';
|
||||
import type {
|
||||
EncodableMediaMsgInfo,
|
||||
@@ -50,7 +50,7 @@ export interface MediaSubFileUpload {
|
||||
}
|
||||
|
||||
export interface NtV2UploadParams {
|
||||
bridge: Bridge;
|
||||
bridge: BridgeContext;
|
||||
isGroup: boolean;
|
||||
/** Group uin when isGroup, otherwise the recipient's uid string. */
|
||||
targetIdOrUid: string | number;
|
||||
+3
-3
@@ -3,7 +3,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { MessageElement } from '../events';
|
||||
import { defaultPttTempDir, encodeSilk } from './ffmpeg-addon';
|
||||
import {
|
||||
@@ -16,7 +16,7 @@ import { computeHashes, loadBinarySource, resolveLocalFilePath } from './utils';
|
||||
|
||||
const moduleLog = createLogger('Highway.Ptt');
|
||||
|
||||
function loggerFor(bridge: Bridge) {
|
||||
function loggerFor(bridge: BridgeContext) {
|
||||
const raw = bridge.identity?.uin;
|
||||
const uin = typeof raw === 'string' ? Number.parseInt(raw, 10) : 0;
|
||||
return Number.isFinite(uin) && uin > 0 ? moduleLog.child({ uin }) : moduleLog;
|
||||
@@ -134,7 +134,7 @@ async function loadPtt(element: MessageElement, tempDir: string): Promise<PttPay
|
||||
* a `commonElem { serviceType: 48, businessType: 22 }`.
|
||||
*/
|
||||
export async function uploadPttMsgInfo(
|
||||
bridge: Bridge,
|
||||
bridge: BridgeContext,
|
||||
isGroup: boolean,
|
||||
targetIdOrUid: string | number,
|
||||
element: MessageElement,
|
||||
File renamed without changes.
+3
-3
@@ -3,7 +3,7 @@ import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { MessageElement } from '../events';
|
||||
import { getFFmpegAddon } from './ffmpeg-addon';
|
||||
import {
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
|
||||
const moduleLog = createLogger('Highway.Video');
|
||||
|
||||
function loggerFor(bridge: Bridge) {
|
||||
function loggerFor(bridge: BridgeContext) {
|
||||
const raw = bridge.identity?.uin;
|
||||
const uin = typeof raw === 'string' ? Number.parseInt(raw, 10) : 0;
|
||||
return Number.isFinite(uin) && uin > 0 ? moduleLog.child({ uin }) : moduleLog;
|
||||
@@ -421,7 +421,7 @@ async function loadVideo(element: MessageElement): Promise<VideoPayload> {
|
||||
* (with per-1MB-block sha1) and a thumb (read off `upload.subFileInfos[0]`).
|
||||
*/
|
||||
export async function uploadVideoMsgInfo(
|
||||
bridge: Bridge,
|
||||
bridge: BridgeContext,
|
||||
isGroup: boolean,
|
||||
targetIdOrUid: string | number,
|
||||
element: MessageElement,
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -1,5 +1,5 @@
|
||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
import { formatEvent } from '../utils/event-format';
|
||||
import { formatEvent } from './format';
|
||||
import { createLogger, type Logger } from '@snowluma/common/logger';
|
||||
import type { BridgeEventBus } from './event-bus';
|
||||
import type { QQEventVariant } from './events';
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"types": ["node"],
|
||||
"noEmit": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
@@ -19,6 +19,10 @@
|
||||
"types": "./src/hex.ts",
|
||||
"default": "./src/hex.ts"
|
||||
},
|
||||
"./json": {
|
||||
"types": "./src/json.ts",
|
||||
"default": "./src/json.ts"
|
||||
},
|
||||
"./log-file-transport": {
|
||||
"types": "./src/log-file-transport.ts",
|
||||
"default": "./src/log-file-transport.ts"
|
||||
@@ -40,6 +44,9 @@
|
||||
"default": "./src/runtime.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.12.2",
|
||||
"typescript": "catalog:"
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// Plain JSON value types — defined here (not in @snowluma/onebot/types
|
||||
// where they used to live) so @snowluma/bridge can talk about JSON-shaped
|
||||
// payloads without importing OneBot. The OneBot types module keeps the
|
||||
// names exported via re-export, so existing call sites that say
|
||||
// `import type { JsonValue } from '<…>/onebot/types'` continue to work
|
||||
// unchanged after Phase 3.
|
||||
//
|
||||
// Anything actually OneBot-specific (ApiResponse, OneBotRequest, …)
|
||||
// stays in @snowluma/onebot — only the plain JSON quartet moves here.
|
||||
|
||||
export type JsonPrimitive = string | number | boolean | null;
|
||||
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
||||
export interface JsonObject {
|
||||
[key: string]: JsonValue;
|
||||
}
|
||||
export type JsonArray = JsonValue[];
|
||||
@@ -14,6 +14,7 @@
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@snowluma/bridge": "workspace:*",
|
||||
"@snowluma/common": "workspace:*",
|
||||
"@snowluma/proto-defs": "workspace:*",
|
||||
"@snowluma/proton": "workspace:*",
|
||||
|
||||
@@ -33,7 +33,7 @@ import type {
|
||||
} from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { DownloadRKeyInfo } from '../bridge';
|
||||
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
|
||||
import { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type {
|
||||
FriendInfo,
|
||||
@@ -41,7 +41,7 @@ import type {
|
||||
GroupRequestInfo,
|
||||
QQGroupInfo,
|
||||
UserProfileInfo,
|
||||
} from '../qq-info';
|
||||
} from '@snowluma/bridge/qq-info';
|
||||
|
||||
// ─── Helpers (previously in bridge-contacts.ts) ───────────────────
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import type {
|
||||
import type { MediaIndexNode } from './shared';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
|
||||
import { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ import type { FileExtra, PushMsg, PushMsgBody } from '@snowluma/proto-defs/messa
|
||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { buildSendElems } from '../element-builder';
|
||||
import type { ForwardNodePayload, MessageElement } from '../events';
|
||||
import { parseMsgPush } from '../msg-push';
|
||||
import { buildSendElems } from '@snowluma/bridge/element-builder';
|
||||
import type { ForwardNodePayload, MessageElement } from '@snowluma/bridge/events';
|
||||
import { parseMsgPush } from '@snowluma/bridge/msg-push';
|
||||
import { resolveSelfUid, toInt } from './shared';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
@@ -13,7 +13,7 @@ import type {
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
|
||||
import { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import type {
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
|
||||
import { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import type {
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-album';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { getGroupAlbumList, uploadImageToGroupAlbum } from '../web/group-album';
|
||||
import { getGroupAlbumList, uploadImageToGroupAlbum } from '@snowluma/bridge/web/group-album';
|
||||
// `getCookies` is part of WebApi — go through the hub so we don't
|
||||
// duplicate the cookie acquisition flow.
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ import { toHexUpper } from '@snowluma/common/hex';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
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 { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
|
||||
import { fetchHighwaySession, uploadHighwayHttp } from '@snowluma/bridge/highway';
|
||||
import { computeHashes, computeMd5, FILE_UPLOAD_MAX_BYTES, loadBinarySource } from '@snowluma/bridge/highway/utils';
|
||||
import type { FileUploadExt } from '@snowluma/proto-defs/highway';
|
||||
import { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
|
||||
@@ -17,7 +17,7 @@ import type {
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
|
||||
import { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ import type {
|
||||
GroupRecallRequest,
|
||||
SsoReadedReportReq,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { MessageElement } from '../events';
|
||||
import { buildSendElems } from '../element-builder';
|
||||
import type { MessageElement } from '@snowluma/bridge/events';
|
||||
import { buildSendElems } from '@snowluma/bridge/element-builder';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
// `Bridge` is imported as a type only so we can narrow `ctx` back to
|
||||
// the concrete Bridge instance when passing it to `buildSendElems`
|
||||
|
||||
@@ -17,7 +17,7 @@ import type {
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
|
||||
import { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ import type {
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
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 { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
|
||||
import { fetchHighwaySession, uploadHighwayHttp } from '@snowluma/bridge/highway';
|
||||
import { computeHashes, loadBinarySource } from '@snowluma/bridge/highway/utils';
|
||||
import { resolveSelfUid } from './shared';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
@@ -14,16 +14,16 @@ import type {
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
|
||||
import { getGroupEssenceMsg, getGroupEssenceMsgAll } from '../web/group-essence';
|
||||
import { getHonorListWebAPI, WebHonorType } from '../web/group-honor';
|
||||
import { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
|
||||
import { getGroupEssenceMsg, getGroupEssenceMsgAll } from '@snowluma/bridge/web/group-essence';
|
||||
import { getHonorListWebAPI, WebHonorType } from '@snowluma/bridge/web/group-honor';
|
||||
import {
|
||||
deleteGroupNotice as deleteGroupNoticeHttp,
|
||||
getGroupNoticeWebAPI,
|
||||
setGroupNoticeWebAPI,
|
||||
uploadGroupNoticeImage,
|
||||
} from '../web/group-notice';
|
||||
import { RequestUtil } from '../web/request-util';
|
||||
} from '@snowluma/bridge/web/group-notice';
|
||||
import { RequestUtil } from '@snowluma/bridge/web/request-util';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
|
||||
@@ -1,67 +1,27 @@
|
||||
// BridgeContext — the surface that Api classes (and any external
|
||||
// consumer that doesn't need the full Bridge concrete class) see.
|
||||
// Api-layer extension of @snowluma/bridge's slim BridgeContext.
|
||||
//
|
||||
// Replaces the previous `BridgeInterface`, which had grown to ~170 lines
|
||||
// listing every Bridge method one-by-one and was a maintenance burden
|
||||
// (every new feature meant +1 signature here, +1 method on Bridge, +1
|
||||
// stub in `mockBridge`). The new design splits business methods OUT to
|
||||
// `apis.xxx.method()` — this interface now carries only the
|
||||
// "infrastructure" surface every Api class needs:
|
||||
// The slim interface in @snowluma/bridge has the protocol-layer
|
||||
// surface (identity / events / sendRawPacket / resolveUserUid / next*
|
||||
// sequence helpers / upload-metadata cache). This file extends it
|
||||
// with `apis: ApiHub` — the typed bag of Api classes that lives ONLY
|
||||
// in @snowluma/core, so the bridge package never sees it (avoiding
|
||||
// a bridge → core cycle).
|
||||
//
|
||||
// - state: identity / events / apis (per-instance)
|
||||
// - raw I/O: sendRawPacket, resolveUserUid
|
||||
// - protocol helpers: nextMessageRandom / nextClientSequence
|
||||
// - upload metadata cache: rememberUploadedFile / recallUploadedFile
|
||||
//
|
||||
// Anything beyond that lives in `apis.<area>.method()` — see
|
||||
// `bridge/apis/index.ts` for the ApiHub shape.
|
||||
//
|
||||
// The concrete `Bridge` class still `implements BridgeContext`, so
|
||||
// passing a `Bridge` where a `BridgeContext` is expected is a free
|
||||
// upcast. Test fakes go the other direction: build a small object that
|
||||
// only stubs the fields under test (instead of the previous 70+ method
|
||||
// `MockBridge` god-object) and pass it as `BridgeContext`.
|
||||
// The 13 Api classes (apis/<area>.ts) import `BridgeContext` from
|
||||
// here, which gives them `this.ctx.apis.message.sendGroup(...)` type-
|
||||
// safety alongside the protocol-layer fields. Highway uploaders,
|
||||
// element-builder, msg-push parsers (all in @snowluma/bridge) import
|
||||
// the slim version directly from `@snowluma/bridge/bridge-context`.
|
||||
|
||||
import type { IdentityService } from './identity-service';
|
||||
import type { BridgeEventBus } from './event-bus';
|
||||
import type { BridgeContext as BaseBridgeContext } from '@snowluma/bridge/bridge-context';
|
||||
import type { ApiHub } from './apis';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import type { UploadedFileMeta } from './bridge';
|
||||
|
||||
export interface BridgeContext {
|
||||
// ── Per-instance state (one set per QQ account in a multi-account
|
||||
// runtime; `BridgeManager` allocates one `Bridge` per uin and
|
||||
// each Bridge owns its own identity/events/pipeline/apis). ──
|
||||
readonly identity: IdentityService;
|
||||
readonly events: BridgeEventBus;
|
||||
export interface BridgeContext extends BaseBridgeContext {
|
||||
readonly apis: ApiHub;
|
||||
|
||||
// ── Raw I/O ──
|
||||
/** Escape hatch for arbitrary protocol calls (used by Api classes
|
||||
* and by the `send_packet` OneBot action). Every typed wrapper on an
|
||||
* Api class eventually routes through here. */
|
||||
sendRawPacket(serviceCmd: string, body: Uint8Array, timeoutMs?: number): Promise<SendPacketResult>;
|
||||
/** uin → uid lookup (cached in IdentityService). `groupId` is an
|
||||
* optional hint that lets the resolver fall back to a group-member
|
||||
* roster when the friend list doesn't have the uin. */
|
||||
resolveUserUid(uin: number, groupId?: number): Promise<string>;
|
||||
|
||||
// ── Send-side protocol helpers (Api classes that build a
|
||||
// `SendMessageRequest` need these monotonic generators to fill in
|
||||
// `clientSequence` and `random`). They were previously `private`
|
||||
// on Bridge — promoted to public so the new Api classes can call
|
||||
// them without `(bridge as any).nextXxx()`. ──
|
||||
nextMessageRandom(): number;
|
||||
nextClientSequence(): number;
|
||||
|
||||
// ── Uploaded-file metadata cache ──
|
||||
//
|
||||
// Bookkeeping shared between `GroupFileApi.upload*File` (writes the
|
||||
// tuple at upload time) and `MessageApi.sendPrivateMessage` (reads
|
||||
// it on later `send_msg` calls that carry only a file_id). Lives at
|
||||
// this layer rather than inside `GroupFileApi` because the message
|
||||
// send path is what queries the cache, and it shouldn't have to
|
||||
// reach into a different Api class for an infrastructure lookup.
|
||||
rememberUploadedFile(meta: UploadedFileMeta): void;
|
||||
recallUploadedFile(fileId: string): UploadedFileMeta | undefined;
|
||||
}
|
||||
|
||||
// Re-export `UploadedFileMeta` from the slim package so existing
|
||||
// `import type { UploadedFileMeta } from '<…>/bridge-context'` (or
|
||||
// from bridge.ts via re-export) keeps working without callers having
|
||||
// to learn the new package path.
|
||||
export type { UploadedFileMeta } from '@snowluma/bridge/bridge-context';
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { PacketSender, SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
import type { BridgeInterface } from './bridge-interface';
|
||||
import { IdentityService } from './identity-service';
|
||||
import { MSG_PUSH_CMD, parseMsgPush } from './msg-push';
|
||||
import { IncomingPacketPipeline, type CmdParser } from './packet-pipeline';
|
||||
import { IdentityService } from '@snowluma/bridge/identity-service';
|
||||
import { MSG_PUSH_CMD, parseMsgPush } from '@snowluma/bridge/msg-push';
|
||||
import { IncomingPacketPipeline, type CmdParser } from '@snowluma/bridge/packet-pipeline';
|
||||
// qq-info types are no longer used directly in this file — they live
|
||||
// inside the Api classes that own those fetches (apis/contacts.ts).
|
||||
import { type ApiHub, buildApiHub } from './apis';
|
||||
@@ -35,7 +35,7 @@ import type { GroupFilesResult } from './apis/group-file';
|
||||
// actions/profile.ts removed — moved to apis/profile.ts::ProfileApi.
|
||||
// `bridge-contacts.ts` removed — its 6 functions are now methods on
|
||||
// `apis.contacts` (see `apis/contacts.ts::ContactsApi`).
|
||||
import { BridgeEventBus } from './event-bus';
|
||||
import { BridgeEventBus } from '@snowluma/bridge/event-bus';
|
||||
// web-actions/* removed — moved to apis/web.ts::WebApi.
|
||||
export { AiVoiceChatType };
|
||||
export type { AiVoiceCategory, StrangerStatus };
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { PacketSender } from '@snowluma/common/packet-sender';
|
||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import { Bridge } from './bridge';
|
||||
import { IdentityService } from './identity-service';
|
||||
import { IdentityService } from '@snowluma/bridge/identity-service';
|
||||
|
||||
export type SessionStartedCallback = (uin: string, bridge: Bridge) => void;
|
||||
export type SessionClosedCallback = (uin: string) => void;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { ApiHandler, ApiActionContext } from '../api-handler';
|
||||
import { asNumber, asBoolean, asString } from '../api-handler';
|
||||
import { RETCODE, failedResponse, okResponse } from '../types';
|
||||
import { WebHonorType } from '@/bridge/web/group-honor';
|
||||
import { WebHonorType } from '@snowluma/bridge/web/group-honor';
|
||||
|
||||
export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('get_group_list', async (params) => {
|
||||
|
||||
@@ -17,7 +17,7 @@ import { register as registerRequest } from './actions/request';
|
||||
import { register as registerExtended } from './actions/extended';
|
||||
import { register as registerGroupAlbum } from './actions/group-album';
|
||||
|
||||
import { WebHonorType } from '@/bridge/web/group-honor';
|
||||
import { WebHonorType } from '@snowluma/bridge/web/group-honor';
|
||||
import { ClientKeyInfo } from '@/bridge/bridge';
|
||||
|
||||
export interface MessageSendResult {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { MessageElement, QQEventVariant } from '../../bridge/events';
|
||||
import type { MessageElement, QQEventVariant } from '@snowluma/bridge/events';
|
||||
import type { JsonObject } from '../types';
|
||||
import {
|
||||
convertFriendMessage,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { QQEventVariant } from '../../bridge/events';
|
||||
import type { QQEventVariant } from '@snowluma/bridge/events';
|
||||
import { GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT } from '../message-id';
|
||||
import type { JsonObject } from '../types';
|
||||
import type { ConverterContext } from './index';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { QQEventVariant } from '../../bridge/events';
|
||||
import type { QQEventVariant } from '@snowluma/bridge/events';
|
||||
import { GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT } from '../message-id';
|
||||
import type { JsonObject } from '../types';
|
||||
import type { ConverterContext } from './index';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { QQEventVariant } from '../../bridge/events';
|
||||
import type { QQEventVariant } from '@snowluma/bridge/events';
|
||||
import type { JsonObject } from '../types';
|
||||
import type { ConverterContext } from './index';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { MessageElement } from '../../bridge/events';
|
||||
import type { MessageElement } from '@snowluma/bridge/events';
|
||||
import type { JsonArray, JsonObject } from '../types';
|
||||
import type {
|
||||
ImageUrlResolver,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { QQEventVariant } from '../bridge/events';
|
||||
import type { QQEventVariant } from '@snowluma/bridge/events';
|
||||
import { convertEvent } from './event-converter';
|
||||
import type { OneBotInstanceContext } from './instance-context';
|
||||
import { GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT, hashMessageIdInt32 } from './message-id';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { WebHonorType } from '@/bridge/web/group-honor';
|
||||
import type { WebHonorType } from '@snowluma/bridge/web/group-honor';
|
||||
import type { Bridge } from '../bridge/bridge';
|
||||
import type { ApiActionContext } from './api-handler';
|
||||
import type { ConverterContext } from './event-converter';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { MessageElement } from '../bridge/events';
|
||||
import type { MessageElement } from '@snowluma/bridge/events';
|
||||
import type { DownloadRKeyInfo } from '../bridge/bridge';
|
||||
import type { BridgeInterface } from '../bridge/bridge-interface';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
type NetworkAdapterContext,
|
||||
} from './network';
|
||||
import { createLogger, type Logger } from '@snowluma/common/logger';
|
||||
import { formatGroup, formatMessageSegments, formatReply, formatUser } from '../utils/event-format';
|
||||
import { formatGroup, formatMessageSegments, formatReply, formatUser } from '@snowluma/bridge/format';
|
||||
|
||||
const moduleLog = createLogger('Event');
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// segment emitted by the event converter and writes a row into the
|
||||
// MediaStore so later `get_image` / `get_record` OneBot actions can
|
||||
|
||||
import type { MessageElement } from '../bridge/events';
|
||||
import type { MessageElement } from '@snowluma/bridge/events';
|
||||
import type { MediaStore } from './media-store';
|
||||
import type { JsonObject } from './types';
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import fs from 'fs';
|
||||
import { DatabaseSync, type StatementSync } from 'node:sqlite';
|
||||
import path from 'path';
|
||||
|
||||
import type { MessageElement } from '../bridge/events';
|
||||
import type { MessageElement } from '@snowluma/bridge/events';
|
||||
|
||||
export interface CachedImage {
|
||||
/** Primary `data.file` value as exposed in the OneBot segment. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { BridgeInterface } from '../bridge/bridge-interface';
|
||||
import type { MessageElement } from '../bridge/events';
|
||||
import type { MessageElement } from '@snowluma/bridge/events';
|
||||
import type { RKeyCache } from './instance-rkey';
|
||||
|
||||
export class MediaUrlResolver {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { MessageElement } from '../bridge/events';
|
||||
import type { MessageElement } from '@snowluma/bridge/events';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { JsonValue } from './types';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { BridgeInterface } from '../../bridge/bridge-interface';
|
||||
import type { IdentityService } from '../../bridge/identity-service';
|
||||
import type { IdentityService } from '@snowluma/bridge/identity-service';
|
||||
import type { OneBotInstanceContext } from '../instance-context';
|
||||
import type { JsonObject } from '../types';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { BridgeInterface } from '../../bridge/bridge-interface';
|
||||
import type { ForwardNodePayload, MessageElement } from '../../bridge/events';
|
||||
import type { ForwardNodePayload, MessageElement } from '@snowluma/bridge/events';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { MessageSendResult } from '../api-handler';
|
||||
import { elementsToOneBotSegments } from '../event-converter';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export type JsonPrimitive = string | number | boolean | null;
|
||||
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
||||
export interface JsonObject {
|
||||
[key: string]: JsonValue;
|
||||
}
|
||||
export type JsonArray = JsonValue[];
|
||||
// Plain JSON types now live in @snowluma/common/json so @snowluma/bridge
|
||||
// (event-format / receive parsers) can talk about JSON payloads without
|
||||
// importing OneBot. Re-exported here so the legacy import shape stays
|
||||
// supported — `import { JsonValue } from '<…>/onebot/types'` keeps working.
|
||||
export type { JsonPrimitive, JsonValue, JsonObject, JsonArray } from '@snowluma/common/json';
|
||||
import type { JsonValue, JsonObject } from '@snowluma/common/json';
|
||||
|
||||
export interface ApiResponse {
|
||||
status: 'ok' | 'failed';
|
||||
|
||||
@@ -14,9 +14,9 @@ import type {
|
||||
// the module object is a no-op — proton has already inlined the call.
|
||||
// We mock `runOidb` (non-generic) to return real proton-encoded bytes
|
||||
// that the production-side codec actually decodes.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -25,7 +25,7 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import { ExtrasApi, AiVoiceChatType } from '../../src/bridge/apis/extras';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', () => ({
|
||||
runOidb: vi.fn(async () => new Uint8Array()),
|
||||
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
|
||||
encodeOidbEnv: vi.fn(() => new Uint8Array()),
|
||||
@@ -40,7 +40,7 @@ vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
const { buildSendElemsMock } = vi.hoisted(() => ({
|
||||
buildSendElemsMock: vi.fn(async (_elements: unknown[], _ctx?: Record<string, unknown>) => []),
|
||||
}));
|
||||
vi.mock('../../src/bridge/element-builder', () => ({
|
||||
vi.mock('@snowluma/bridge/element-builder', () => ({
|
||||
buildSendElems: buildSendElemsMock,
|
||||
}));
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', () => ({
|
||||
runOidb: vi.fn(async () => new Uint8Array()),
|
||||
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
|
||||
encodeOidbEnv: vi.fn(() => new Uint8Array()),
|
||||
@@ -10,7 +10,7 @@ vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
// element-builder reaches into protoEncode with element-specific schemas
|
||||
// that we don't want to construct manually in tests; stub it to return
|
||||
// a benign placeholder.
|
||||
vi.mock('../../src/bridge/element-builder', () => ({
|
||||
vi.mock('@snowluma/bridge/element-builder', () => ({
|
||||
buildSendElems: vi.fn(async () => []),
|
||||
}));
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', () => ({
|
||||
runOidb: vi.fn(async () => new Uint8Array()),
|
||||
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
|
||||
encodeOidbEnv: vi.fn(() => new Uint8Array()),
|
||||
decodeOidbEnv: vi.fn(() => ({ body: {} })),
|
||||
}));
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import { FriendApi } from '../../src/bridge/apis/friend';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ import type { Oidb0x8a7Resp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
// is `runOidb` (non-generic, untouched by proton) returning real bytes
|
||||
// that the production-side codec then decodes. `makeOidbEnvelope` is a
|
||||
// pure TS helper, so its mock works for introspection.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -20,7 +20,7 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import { GroupAdminApi } from '../../src/bridge/apis/group-admin';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ import type {
|
||||
// the module object is a no-op — proton has already inlined the call.
|
||||
// We mock `runOidb` (non-generic, proton leaves it alone) to return real
|
||||
// proton-encoded bytes, which the production-side codec then decodes.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -28,12 +28,12 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('../../src/bridge/highway/highway-client', () => ({
|
||||
vi.mock('@snowluma/bridge/highway', () => ({
|
||||
fetchHighwaySession: vi.fn(async () => ({})),
|
||||
uploadHighwayHttp: vi.fn(async () => undefined),
|
||||
}));
|
||||
|
||||
vi.mock('../../src/bridge/highway/utils', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/utils', () => ({
|
||||
loadBinarySource: vi.fn(async (_src: string, fallback: string) => ({
|
||||
bytes: new Uint8Array([1, 2, 3]),
|
||||
fileName: `${fallback}.bin`,
|
||||
@@ -43,8 +43,8 @@ vi.mock('../../src/bridge/highway/utils', () => ({
|
||||
FILE_UPLOAD_MAX_BYTES: 4 * 1024 * 1024 * 1024,
|
||||
}));
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as highwayClient from '../../src/bridge/highway/highway-client';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import * as highwayClient from '@snowluma/bridge/highway';
|
||||
import { GroupFileApi } from '../../src/bridge/apis/group-file';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', () => ({
|
||||
runOidb: vi.fn(async () => new Uint8Array()),
|
||||
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
|
||||
encodeOidbEnv: vi.fn(() => new Uint8Array()),
|
||||
|
||||
@@ -10,9 +10,9 @@ import type { Oidb0x9083Resp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
// is `runOidb` (non-generic, untouched by proton) returning real bytes
|
||||
// that the production-side codec actually decodes. `makeOidbEnvelope` is
|
||||
// a pure TS helper, so its mock works for introspection.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -21,7 +21,7 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import { InteractionApi } from '../../src/bridge/apis/interaction';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ import type {
|
||||
// so mocking them on the module object is a no-op. We mock `runOidb`
|
||||
// (non-generic, untouched by proton) to return real proton-encoded bytes
|
||||
// that the production-side codec then actually decodes.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -22,7 +22,7 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import { MiscApi } from '../../src/bridge/apis/misc';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ import type {
|
||||
// the module object is a no-op — proton has already inlined the call.
|
||||
// We mock `runOidb` (non-generic) to return real proton-encoded bytes
|
||||
// that the production-side codec actually decodes.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -25,19 +25,19 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('../../src/bridge/highway/highway-client', () => ({
|
||||
vi.mock('@snowluma/bridge/highway', () => ({
|
||||
fetchHighwaySession: vi.fn(async () => ({})),
|
||||
uploadHighwayHttp: vi.fn(async () => undefined),
|
||||
}));
|
||||
|
||||
vi.mock('../../src/bridge/highway/utils', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/utils', () => ({
|
||||
loadBinarySource: vi.fn(async () => ({ bytes: new Uint8Array([1, 2, 3]), fileName: 'avatar.bin' })),
|
||||
computeHashes: vi.fn(() => ({ md5: new Uint8Array(16), sha1: new Uint8Array(20) })),
|
||||
computeMd5: vi.fn(() => new Uint8Array(16)),
|
||||
}));
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as highwayClient from '../../src/bridge/highway/highway-client';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import * as highwayClient from '@snowluma/bridge/highway';
|
||||
import { ProfileApi } from '../../src/bridge/apis/profile';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
@@ -161,7 +161,7 @@ describe('apis/profile', () => {
|
||||
|
||||
it('setGroupAvatar rejects an empty file before hitting highway', async () => {
|
||||
const bridge = mockBridge();
|
||||
const { loadBinarySource } = await import('../../src/bridge/highway/utils');
|
||||
const { loadBinarySource } = await import('@snowluma/bridge/highway/utils');
|
||||
vi.mocked(loadBinarySource).mockResolvedValueOnce({
|
||||
bytes: new Uint8Array(0), fileName: 'empty.png',
|
||||
} as any);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { BridgeEventBus } from '../src/bridge/event-bus';
|
||||
import type { FriendMessage, GroupMessage } from '../src/bridge/events';
|
||||
import { BridgeEventBus } from '@snowluma/bridge/event-bus';
|
||||
import type { FriendMessage, GroupMessage } from '@snowluma/bridge/events';
|
||||
|
||||
function makeFriendMessage(): FriendMessage {
|
||||
return {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { Bridge } from '../src/bridge/bridge';
|
||||
import { IdentityService } from '../src/bridge/identity-service';
|
||||
import type { GroupMemberInfo, QQGroupInfo } from '../src/bridge/qq-info';
|
||||
import type { GroupMemberJoin, QQEventVariant } from '../src/bridge/events';
|
||||
import { IdentityService } from '@snowluma/bridge/identity-service';
|
||||
import type { GroupMemberInfo, QQGroupInfo } from '@snowluma/bridge/qq-info';
|
||||
import type { GroupMemberJoin, QQEventVariant } from '@snowluma/bridge/events';
|
||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
|
||||
const SELF_UIN = '10001';
|
||||
|
||||
@@ -4,14 +4,14 @@ import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import type { SendMessageRequest, SendMessageResponse } from '@snowluma/proto-defs/action';
|
||||
import type { FileExtra } from '@snowluma/proto-defs/message';
|
||||
|
||||
vi.mock('../src/bridge/element-builder', () => ({
|
||||
vi.mock('@snowluma/bridge/element-builder', () => ({
|
||||
buildSendElems: vi.fn(async () => [{ text: { str: 'stub media elem' } }]),
|
||||
}));
|
||||
|
||||
describe('Bridge private media routing', () => {
|
||||
it('includes resolved uid in the final c2c send request for media messages', async () => {
|
||||
const { Bridge } = await import('../src/bridge/bridge');
|
||||
const { IdentityService } = await import('../src/bridge/identity-service');
|
||||
const { IdentityService } = await import('@snowluma/bridge/identity-service');
|
||||
|
||||
class TestBridge extends Bridge {
|
||||
capturedBody: Uint8Array | null = null;
|
||||
@@ -60,7 +60,7 @@ describe('Bridge private media routing', () => {
|
||||
// implementation wrote c2c routing + richText.notOnlineFile +
|
||||
// c2cCmd=11 — the QQ-NT server rejected every c2c file send.
|
||||
const { Bridge } = await import('../src/bridge/bridge');
|
||||
const { IdentityService } = await import('../src/bridge/identity-service');
|
||||
const { IdentityService } = await import('@snowluma/bridge/identity-service');
|
||||
|
||||
class TestBridge extends Bridge {
|
||||
capturedBody: Uint8Array | null = null;
|
||||
|
||||
@@ -16,17 +16,17 @@
|
||||
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
vi.mock('../src/bridge/highway/image-upload', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/image-upload', () => ({
|
||||
uploadImageMsgInfo: vi.fn(async () => new Uint8Array([7, 8, 9])),
|
||||
}));
|
||||
vi.mock('../src/bridge/highway/ptt-upload', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/ptt-upload', () => ({
|
||||
uploadPttMsgInfo: vi.fn(async () => new Uint8Array([4, 5, 6])),
|
||||
}));
|
||||
vi.mock('../src/bridge/highway/video-upload', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/video-upload', () => ({
|
||||
uploadVideoMsgInfo: vi.fn(async () => new Uint8Array([1, 2, 3])),
|
||||
}));
|
||||
|
||||
import { buildSendElems } from '../src/bridge/element-builder';
|
||||
import { buildSendElems } from '@snowluma/bridge/element-builder';
|
||||
|
||||
const fakeBridge = {} as any;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import type {
|
||||
MessageElement,
|
||||
QQEventVariant,
|
||||
TempMessage,
|
||||
} from '../src/bridge/events';
|
||||
} from '@snowluma/bridge/events';
|
||||
|
||||
const SELF_ID = 10001;
|
||||
const PEER_UIN = 22222;
|
||||
|
||||
@@ -12,8 +12,8 @@ import {
|
||||
formatMessageSegments,
|
||||
formatReply,
|
||||
formatUser,
|
||||
} from '../src/utils/event-format';
|
||||
import type { QQEventVariant } from '../src/bridge/events';
|
||||
} from '@snowluma/bridge/format';
|
||||
import type { QQEventVariant } from '@snowluma/bridge/events';
|
||||
|
||||
// ─── Test fakes (just the find* surface event-format uses) ───
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { BridgeEventBus } from '../src/bridge/event-bus';
|
||||
import { BridgeEventBus } from '@snowluma/bridge/event-bus';
|
||||
|
||||
// Wrap convertEvent in a vi.fn that delegates to the real impl by
|
||||
// default, so one test can override it to return null without making
|
||||
@@ -18,7 +18,7 @@ import type {
|
||||
GroupMemberJoin,
|
||||
TempMessage,
|
||||
QQEventVariant,
|
||||
} from '../src/bridge/events';
|
||||
} from '@snowluma/bridge/events';
|
||||
import type { JsonObject, MessageMeta } from '../src/onebot/types';
|
||||
|
||||
const SELF_UIN = '10001';
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
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';
|
||||
import type { GroupMsgEmojiLikeEvent, QQEventVariant } from '../src/bridge/events';
|
||||
import { decodeEvent0x2DC } from '@snowluma/bridge/msg-push/decoders/event-0x2dc';
|
||||
import type { MsgPushContext } from '@snowluma/bridge/msg-push/context';
|
||||
import { IdentityService } from '@snowluma/bridge/identity-service';
|
||||
import type { GroupMsgEmojiLikeEvent, QQEventVariant } from '@snowluma/bridge/events';
|
||||
import { convertGroupMsgEmojiLike } from '../src/onebot/event-converter/to-notice';
|
||||
import { GROUP_MESSAGE_EVENT, hashMessageIdInt32 } from '../src/onebot/message-id';
|
||||
import { formatEvent } from '../src/utils/event-format';
|
||||
import { formatEvent } from '@snowluma/bridge/format';
|
||||
import { subscribeLogs, type LogEntry } from '@snowluma/common/logger';
|
||||
|
||||
const SELF_UIN = '10001';
|
||||
|
||||
@@ -3,7 +3,7 @@ import os from 'os';
|
||||
import path from 'path';
|
||||
import { pathToFileURL } from 'url';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { loadBinarySource, resolveLocalFilePath } from '../src/bridge/highway/utils';
|
||||
import { loadBinarySource, resolveLocalFilePath } from '@snowluma/bridge/highway/utils';
|
||||
|
||||
describe('highway source paths', () => {
|
||||
it('normalizes file URLs with an extra leading slash on POSIX', () => {
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/highway/pipeline', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/pipeline', () => ({
|
||||
runNtv2Upload: vi.fn(async () => ({ msgInfo: { msgInfoBody: [], extBizInfo: {} } })),
|
||||
finalizeMediaMsgInfo: vi.fn(() => new Uint8Array([0xCA, 0xFE])),
|
||||
hexToBytes: vi.fn((hex: string) => new Uint8Array(hex.length / 2)),
|
||||
}));
|
||||
|
||||
vi.mock('../../src/bridge/highway/utils', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/utils', () => ({
|
||||
loadBinarySource: vi.fn(async () => ({ bytes: new Uint8Array([1, 2, 3]), fileName: 'src.jpg' })),
|
||||
computeHashes: vi.fn(() => ({
|
||||
md5: new Uint8Array(16),
|
||||
@@ -22,9 +22,9 @@ vi.mock('../../src/bridge/highway/utils', () => ({
|
||||
detectImageFormat: vi.fn(() => ({ format: 1000, width: 800, height: 600 })),
|
||||
}));
|
||||
|
||||
import * as pipeline from '../../src/bridge/highway/pipeline';
|
||||
import { uploadImageMsgInfo } from '../../src/bridge/highway/image-upload';
|
||||
import { GROUP_IMAGE_CMD_ID, PRIVATE_IMAGE_CMD_ID } from '../../src/bridge/highway/highway-client';
|
||||
import * as pipeline from '@snowluma/bridge/highway/pipeline';
|
||||
import { uploadImageMsgInfo } from '@snowluma/bridge/highway/image-upload';
|
||||
import { GROUP_IMAGE_CMD_ID, PRIVATE_IMAGE_CMD_ID } from '@snowluma/bridge/highway';
|
||||
|
||||
describe('image-upload', () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
|
||||
vi.mock('../../src/bridge/highway/highway-client', () => ({
|
||||
vi.mock('@snowluma/bridge/highway', () => ({
|
||||
fetchHighwaySession: vi.fn(async () => ({ sessionId: 'fake-session' })),
|
||||
uploadHighwayHttp: vi.fn(async () => undefined),
|
||||
buildHighwayExtend: vi.fn(() => new Uint8Array([0xAA, 0xBB])),
|
||||
@@ -16,14 +16,14 @@ vi.mock('../../src/bridge/highway/highway-client', () => ({
|
||||
GROUP_IMAGE_CMD_ID: 1004,
|
||||
}));
|
||||
|
||||
import * as highway from '../../src/bridge/highway/highway-client';
|
||||
import * as highway from '@snowluma/bridge/highway';
|
||||
import {
|
||||
finalizeMediaMsgInfo,
|
||||
hexToBytes,
|
||||
makeClientRandomId,
|
||||
runNtv2Upload,
|
||||
type MediaSubFileUpload,
|
||||
} from '../../src/bridge/highway/pipeline';
|
||||
} from '@snowluma/bridge/highway/pipeline';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { EncodableMediaMsgInfo, NTV2UploadRichMediaReq, NTV2UploadRichMediaResp } from '@snowluma/proto-defs/highway';
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/highway/pipeline', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/pipeline', () => ({
|
||||
runNtv2Upload: vi.fn(async () => ({ msgInfo: { msgInfoBody: [], extBizInfo: {} } })),
|
||||
finalizeMediaMsgInfo: vi.fn(() => new Uint8Array([0xAA, 0xBB])),
|
||||
hexToBytes: vi.fn((hex: string) => new Uint8Array(hex.length / 2)),
|
||||
}));
|
||||
|
||||
import * as pipeline from '../../src/bridge/highway/pipeline';
|
||||
import { uploadPttMsgInfo, GROUP_PTT_CMD_ID, PRIVATE_PTT_CMD_ID } from '../../src/bridge/highway/ptt-upload';
|
||||
import * as pipeline from '@snowluma/bridge/highway/pipeline';
|
||||
import { uploadPttMsgInfo, GROUP_PTT_CMD_ID, PRIVATE_PTT_CMD_ID } from '@snowluma/bridge/highway/ptt-upload';
|
||||
|
||||
const FINGERPRINT = {
|
||||
noByteFallback: true,
|
||||
|
||||
@@ -11,20 +11,20 @@
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/highway/pipeline', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/pipeline', () => ({
|
||||
runNtv2Upload: vi.fn(async () => ({ msgInfo: { msgInfoBody: [], extBizInfo: {} } })),
|
||||
finalizeMediaMsgInfo: vi.fn(() => new Uint8Array([0x12, 0x34])),
|
||||
hexToBytes: vi.fn((hex: string) => new Uint8Array(hex.length / 2)),
|
||||
}));
|
||||
|
||||
import * as pipeline from '../../src/bridge/highway/pipeline';
|
||||
import * as pipeline from '@snowluma/bridge/highway/pipeline';
|
||||
import {
|
||||
uploadVideoMsgInfo,
|
||||
GROUP_VIDEO_CMD_ID,
|
||||
GROUP_VIDEO_THUMB_CMD_ID,
|
||||
PRIVATE_VIDEO_CMD_ID,
|
||||
PRIVATE_VIDEO_THUMB_CMD_ID,
|
||||
} from '../../src/bridge/highway/video-upload';
|
||||
} from '@snowluma/bridge/highway/video-upload';
|
||||
|
||||
const FINGERPRINT = {
|
||||
noByteFallback: true,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { IdentityService } from '../src/bridge/identity-service';
|
||||
import type { GroupMemberInfo, QQGroupInfo, UserProfileInfo } from '../src/bridge/qq-info';
|
||||
import { IdentityService } from '@snowluma/bridge/identity-service';
|
||||
import type { GroupMemberInfo, QQGroupInfo, UserProfileInfo } from '@snowluma/bridge/qq-info';
|
||||
|
||||
const SELF_UIN = '10001';
|
||||
const GROUP_ID = 123456789;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { MediaIndexer } from '../src/onebot/media-indexer';
|
||||
import type { MessageElement } from '../src/bridge/events';
|
||||
import type { MessageElement } from '@snowluma/bridge/events';
|
||||
|
||||
function makeMediaStore() {
|
||||
return {
|
||||
|
||||
@@ -3,7 +3,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { MediaStore } from '../src/onebot/media-store';
|
||||
import { convertEvent, type ConverterContext } from '../src/onebot/event-converter';
|
||||
import type { GroupMessage, FriendMessage, MessageElement } from '../src/bridge/events';
|
||||
import type { GroupMessage, FriendMessage, MessageElement } from '@snowluma/bridge/events';
|
||||
|
||||
const SELF_ID = 10001;
|
||||
const PEER_UIN = 22222;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { MediaUrlResolver } from '../src/onebot/media-url-resolver';
|
||||
import type { MessageElement } from '../src/bridge/events';
|
||||
import type { MessageElement } from '@snowluma/bridge/events';
|
||||
|
||||
// Minimal stand-ins for the two collaborators. Each test wires whatever
|
||||
// subset of Bridge methods the element type exercises.
|
||||
|
||||
Loaded 100 of 107 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user