@napuketto/adapter 0.24.3 → 0.24.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{essence-ChxJJipr.mjs → essence-By64qv90.mjs} +37 -57
- package/dist/{gray-tip-DlxDI1YV.mjs → gray-tip-jdpy-Jv3.mjs} +159 -159
- package/dist/index.mjs +4 -4
- package/dist/kurobot/index.mjs +1 -1
- package/dist/{kurobot-3nvb4oqh.mjs → kurobot-xqbvEUYA.mjs} +1 -1
- package/dist/milky/index.mjs +1 -1
- package/dist/{milky-BWLRoCdN.mjs → milky-DbT3wxVC.mjs} +45 -100
- package/dist/onebot11/index.mjs +1 -1
- package/dist/{onebot11-CQhxsoc_.mjs → onebot11-DnDRoiMk.mjs} +15 -38
- package/dist/{raw-message-B0kwCfKE.mjs → raw-message-D9-8kPiU.mjs} +3 -3
- package/dist/satori/index.mjs +1 -1
- package/dist/{satori-CgaSIlQs.mjs → satori-Cmu2QGGz.mjs} +75 -94
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as toUnixSeconds } from "./raw-message-
|
|
1
|
+
import { i as toUnixSeconds } from "./raw-message-D9-8kPiU.mjs";
|
|
2
2
|
import { isRecord } from "@napuketto/kernel";
|
|
3
|
-
// src/internal/
|
|
3
|
+
// src/internal/domain/buddy-req.ts
|
|
4
4
|
/**
|
|
5
5
|
* BuddyReq 防御收窄 + 可处理性过滤(OB11 / Milky 共用,issue #122)
|
|
6
6
|
*
|
|
@@ -131,7 +131,7 @@ function processInboundBuddyReqs(arg, opts) {
|
|
|
131
131
|
}, `${opts.scope}: 好友申请过滤(历史积压 / 已读 / 已处理 / 重复)`);
|
|
132
132
|
return fresh;
|
|
133
133
|
}
|
|
134
|
-
// src/internal/
|
|
134
|
+
// src/internal/domain/sysmsg.ts
|
|
135
135
|
/** 递归深度上限(防御:恶意/畸形字节防栈溢出)。 */
|
|
136
136
|
const MAX_DEPTH = 16;
|
|
137
137
|
/** 单层字段数上限。 */
|
|
@@ -178,46 +178,32 @@ function decodeTaggedField(data, start, depth) {
|
|
|
178
178
|
const [tagValue, afterTag] = tag;
|
|
179
179
|
const no = Number(tagValue >> 3n);
|
|
180
180
|
if (no === 0) return null;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
/** fixed 类 wire 的字节宽度(非 fixed → null)。 */
|
|
209
|
-
function fixedWireWidth(wireType) {
|
|
210
|
-
if (wireType === 1) return 8;
|
|
211
|
-
return wireType === 5 ? 4 : null;
|
|
212
|
-
}
|
|
213
|
-
/** 定长跳过(越界判失败)。 */
|
|
214
|
-
function skipFixedBytes(data, start, width) {
|
|
215
|
-
const next = start + width;
|
|
216
|
-
if (next > data.length) return null;
|
|
217
|
-
return {
|
|
218
|
-
field: void 0,
|
|
219
|
-
next
|
|
220
|
-
};
|
|
181
|
+
const wireType = Number(tagValue & 7n);
|
|
182
|
+
switch (wireType) {
|
|
183
|
+
case 0: {
|
|
184
|
+
const v = readVarint(data, afterTag);
|
|
185
|
+
if (v === null) return null;
|
|
186
|
+
return {
|
|
187
|
+
field: {
|
|
188
|
+
no,
|
|
189
|
+
kind: "varint",
|
|
190
|
+
value: v[0]
|
|
191
|
+
},
|
|
192
|
+
next: v[1]
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
case 2: return decodeLengthDelimited(data, afterTag, no, depth);
|
|
196
|
+
case 1:
|
|
197
|
+
case 5: {
|
|
198
|
+
const next = afterTag + (wireType === 1 ? 8 : 4);
|
|
199
|
+
if (next > data.length) return null;
|
|
200
|
+
return {
|
|
201
|
+
field: void 0,
|
|
202
|
+
next
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
default: return null;
|
|
206
|
+
}
|
|
221
207
|
}
|
|
222
208
|
/**
|
|
223
209
|
* 解码 protobuf wire-format 为递归字段树(不维护字段重复/顺序语义以外的信息)。
|
|
@@ -301,13 +287,12 @@ function textOf(node, no) {
|
|
|
301
287
|
const f = firstField(node, no);
|
|
302
288
|
return f?.kind === "bytes" ? decodeText(f.value) : null;
|
|
303
289
|
}
|
|
304
|
-
/**
|
|
290
|
+
/**
|
|
291
|
+
* 单个候选块 → Uint8Array(Int8Array / Uint8Array / number[] -128..255;其余 null)。
|
|
292
|
+
* 字节值必须是整数:浮点 & 0xff 会静默截断成别的字节。
|
|
293
|
+
*/
|
|
305
294
|
function toBlob(item) {
|
|
306
295
|
if (item instanceof Int8Array) return Uint8Array.from(item, (b) => b & 255);
|
|
307
|
-
return blobFromGeneric(item);
|
|
308
|
-
}
|
|
309
|
-
/** Uint8Array / 字节数组形态(Int8Array 已在上层处理)。 */
|
|
310
|
-
function blobFromGeneric(item) {
|
|
311
296
|
if (item instanceof Uint8Array) return new Uint8Array(item);
|
|
312
297
|
if (Array.isArray(item) && item.length > 0) return blobFromArray(item);
|
|
313
298
|
return null;
|
|
@@ -316,17 +301,12 @@ function blobFromGeneric(item) {
|
|
|
316
301
|
function blobFromArray(item) {
|
|
317
302
|
const out = new Uint8Array(item.length);
|
|
318
303
|
for (let i = 0; i < item.length; i += 1) {
|
|
319
|
-
const
|
|
320
|
-
if (
|
|
321
|
-
out[i] =
|
|
304
|
+
const b = item[i];
|
|
305
|
+
if (typeof b !== "number" || !Number.isInteger(b) || b < -128 || b > 255) return null;
|
|
306
|
+
out[i] = b & 255;
|
|
322
307
|
}
|
|
323
308
|
return out;
|
|
324
309
|
}
|
|
325
|
-
/** 带符号/无符号字节归一(非整数拒绝:浮点 & 0xff 会静默截断成别的字节)。 */
|
|
326
|
-
function signedToUnsigned(b) {
|
|
327
|
-
if (typeof b !== "number" || !Number.isInteger(b) || b < -128 || b > 255) return null;
|
|
328
|
-
return b & 255;
|
|
329
|
-
}
|
|
330
310
|
/**
|
|
331
311
|
* onRecvSysMsg 参数 → sysmsg 字节块列表(防御性收窄)。
|
|
332
312
|
* 接受批数组(实测形状)/ 单块裸数组 / TypedArray;零有效块返回 null
|
|
@@ -448,7 +428,7 @@ async function processSysMsgBlob(blob, opts) {
|
|
|
448
428
|
raw: toHex(blob).slice(0, 1024)
|
|
449
429
|
}, `${opts.scope}: onRecvSysMsg 校准数据(未识别,不广播)`);
|
|
450
430
|
}
|
|
451
|
-
// src/internal/
|
|
431
|
+
// src/internal/domain/essence.ts
|
|
452
432
|
/**
|
|
453
433
|
* 群精华协议层提取器(仅保留 sysmsg 732:1 protobuf 树字段提取)
|
|
454
434
|
*
|
|
@@ -558,163 +558,7 @@ async function cacheMediaFile(root, extension, writer, lifetime = "temporary", i
|
|
|
558
558
|
const leaseMediaReference = MediaCache.leasePath;
|
|
559
559
|
/** Only the current Satori account can consume its internal IDs. */
|
|
560
560
|
const leaseInternalMedia = MediaCache.leaseInternal;
|
|
561
|
-
// src/internal/
|
|
562
|
-
const MAX_FILE_BYTES = 536870912;
|
|
563
|
-
const WINDOWS = process.platform === "win32";
|
|
564
|
-
const DEVICE_RE = /^(?:con|prn|aux|nul|conin\$|conout\$|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)/i;
|
|
565
|
-
const DRIVE_PATH_RE = /^[a-z]:[\\/]/i;
|
|
566
|
-
const NETWORK_PATH_RE = /^[\\/]{2}/;
|
|
567
|
-
const PATH_SEPARATOR_RE = /[\\/]/;
|
|
568
|
-
const WINDOWS_INVALID_NAME_RE = /[<>:"|?*]|[ .]$/;
|
|
569
|
-
const FILE_SCHEME_RE = /^file:/i;
|
|
570
|
-
const FILE_URI_RE = /^file:\/\//i;
|
|
571
|
-
const EXTENSION_RE = /\.[a-z0-9]+$/i;
|
|
572
|
-
const URI_SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i;
|
|
573
|
-
function denied() {
|
|
574
|
-
return kernelError("本地媒体路径未授权或文件不可用", "INVALID_PARAM");
|
|
575
|
-
}
|
|
576
|
-
function validateWindowsPath(path) {
|
|
577
|
-
if (isAbsolute(path) && !DRIVE_PATH_RE.test(path)) throw denied();
|
|
578
|
-
const components = path.replace(DRIVE_PATH_RE, "").split(PATH_SEPARATOR_RE);
|
|
579
|
-
for (const part of components) {
|
|
580
|
-
if (part === "." || part === "..") continue;
|
|
581
|
-
if (WINDOWS_INVALID_NAME_RE.test(part) || DEVICE_RE.test(part)) throw denied();
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
function validatePath(path) {
|
|
585
|
-
if (path === "" || path.includes("\0") || NETWORK_PATH_RE.test(path)) throw denied();
|
|
586
|
-
if (URI_SCHEME_RE.test(path) && !(WINDOWS && DRIVE_PATH_RE.test(path))) throw denied();
|
|
587
|
-
if (WINDOWS) validateWindowsPath(path);
|
|
588
|
-
return path;
|
|
589
|
-
}
|
|
590
|
-
function decodeLocalPath(input) {
|
|
591
|
-
if (!FILE_SCHEME_RE.test(input)) return validatePath(input);
|
|
592
|
-
try {
|
|
593
|
-
if (!FILE_URI_RE.test(input)) throw denied();
|
|
594
|
-
const url = new URL(input);
|
|
595
|
-
if (url.search || url.hash || url.hostname !== "") throw denied();
|
|
596
|
-
return validatePath(fileURLToPath(url));
|
|
597
|
-
} catch {
|
|
598
|
-
throw denied();
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
/** Resolve configuration relative to the trusted host base, never to a request path. */
|
|
602
|
-
function bindLocalMediaRoots(base, configured) {
|
|
603
|
-
const anchor = resolve(base ?? ".");
|
|
604
|
-
return () => (configured?.() ?? []).map((root) => resolve(anchor, validatePath(root)));
|
|
605
|
-
}
|
|
606
|
-
function within(root, path) {
|
|
607
|
-
return path.startsWith(root.endsWith(sep) ? root : root + sep) && path !== root;
|
|
608
|
-
}
|
|
609
|
-
function unavailable(err) {
|
|
610
|
-
return err instanceof Error && "code" in err && [
|
|
611
|
-
"ENOENT",
|
|
612
|
-
"ENOTDIR",
|
|
613
|
-
"EACCES",
|
|
614
|
-
"EPERM",
|
|
615
|
-
"ELOOP"
|
|
616
|
-
].includes(String(err.code));
|
|
617
|
-
}
|
|
618
|
-
function sameFile(a, b) {
|
|
619
|
-
return a.isFile() && b.isFile() && a.dev === b.dev && a.ino === b.ino && a.ino !== 0n;
|
|
620
|
-
}
|
|
621
|
-
function withinInputRoot(root, path) {
|
|
622
|
-
return WINDOWS ? within(root.toLowerCase(), path.toLowerCase()) : within(root, path);
|
|
623
|
-
}
|
|
624
|
-
async function findCandidate(input, configuredRoot) {
|
|
625
|
-
try {
|
|
626
|
-
const root = validatePath(await realpath(configuredRoot));
|
|
627
|
-
const candidate = resolve(root, input);
|
|
628
|
-
if (!withinInputRoot(root, candidate) && !withinInputRoot(configuredRoot, candidate)) return void 0;
|
|
629
|
-
const path = validatePath(await realpath(candidate));
|
|
630
|
-
if (!within(root, path) || isMediaCachePath(path)) throw denied();
|
|
631
|
-
const before = await lstat(path, { bigint: true });
|
|
632
|
-
if (!before.isFile() || before.nlink !== 1n) throw denied();
|
|
633
|
-
return {
|
|
634
|
-
root,
|
|
635
|
-
path,
|
|
636
|
-
before
|
|
637
|
-
};
|
|
638
|
-
} catch (err) {
|
|
639
|
-
if (unavailable(err)) return void 0;
|
|
640
|
-
throw err;
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
async function selectCandidate(input, roots) {
|
|
644
|
-
const matches = /* @__PURE__ */ new Map();
|
|
645
|
-
for (const root of roots) {
|
|
646
|
-
const candidate = await findCandidate(input, resolve(root));
|
|
647
|
-
if (candidate !== void 0) matches.set(candidate.path, candidate);
|
|
648
|
-
}
|
|
649
|
-
if (matches.size !== 1) throw denied();
|
|
650
|
-
const [match] = matches.values();
|
|
651
|
-
if (match === void 0) throw denied();
|
|
652
|
-
return match;
|
|
653
|
-
}
|
|
654
|
-
async function verifyOpenFile(candidate, file) {
|
|
655
|
-
const { root, path, before } = candidate;
|
|
656
|
-
const opened = await file.stat({ bigint: true });
|
|
657
|
-
if (!sameFile(before, opened) || opened.nlink !== 1n || opened.size > MAX_FILE_BYTES) throw denied();
|
|
658
|
-
const actual = process.platform === "linux" ? await readlink(`/proc/self/fd/${file.fd}`) : await realpath(path);
|
|
659
|
-
if (actual !== path || !within(root, actual)) throw denied();
|
|
660
|
-
const after = await lstat(actual, { bigint: true });
|
|
661
|
-
if (!sameFile(after, opened) || after.nlink !== 1n) throw denied();
|
|
662
|
-
return Number(opened.size);
|
|
663
|
-
}
|
|
664
|
-
async function writeSnapshot(file, path, size) {
|
|
665
|
-
if (size === 0) {
|
|
666
|
-
await writeFile(path, "", {
|
|
667
|
-
flag: "wx",
|
|
668
|
-
mode: 384
|
|
669
|
-
});
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
const output = createWriteStream(path, {
|
|
673
|
-
flags: "wx",
|
|
674
|
-
mode: 384
|
|
675
|
-
});
|
|
676
|
-
await pipeline(file.createReadStream({
|
|
677
|
-
autoClose: false,
|
|
678
|
-
start: 0,
|
|
679
|
-
end: size - 1
|
|
680
|
-
}), output);
|
|
681
|
-
if (output.bytesWritten !== size) throw denied();
|
|
682
|
-
}
|
|
683
|
-
async function snapshot(candidate, cacheDir, lifetime) {
|
|
684
|
-
const linuxFlags = constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK;
|
|
685
|
-
const file = await open(candidate.path, WINDOWS ? "r" : linuxFlags);
|
|
686
|
-
try {
|
|
687
|
-
const size = await verifyOpenFile(candidate, file);
|
|
688
|
-
const name = basename(candidate.path);
|
|
689
|
-
return await cacheMediaFile(cacheDir, EXTENSION_RE.exec(name)?.[0] ?? ".bin", (path) => writeSnapshot(file, path, size), lifetime, lifetime === "temporary" ? name : void 0);
|
|
690
|
-
} finally {
|
|
691
|
-
await file.close();
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
/** The result is safe to hand to consumers that reopen a path, including native APIs. */
|
|
695
|
-
async function resolveLocalMedia(input, roots = []) {
|
|
696
|
-
const path = decodeLocalPath(input);
|
|
697
|
-
if (isMediaCachePath(path)) return await leaseMediaReference(path);
|
|
698
|
-
try {
|
|
699
|
-
return await snapshot(await selectCandidate(path, roots), MEDIA_TEMP_ROOT, "temporary");
|
|
700
|
-
} catch (err) {
|
|
701
|
-
if (unavailable(err)) throw denied();
|
|
702
|
-
throw err;
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
/** QQ sources come from a current-account message/API response, never from RPC path fields. */
|
|
706
|
-
async function exportQqMedia(source, qqRoot, cacheDir) {
|
|
707
|
-
if (!source || !qqRoot) return void 0;
|
|
708
|
-
try {
|
|
709
|
-
const candidate = await findCandidate(validatePath(source.replaceAll("\\", sep)), resolve(qqRoot));
|
|
710
|
-
if (candidate === void 0) return void 0;
|
|
711
|
-
return await snapshot(candidate, cacheDir || MEDIA_TEMP_ROOT, "reference");
|
|
712
|
-
} catch (err) {
|
|
713
|
-
if (unavailable(err) || err instanceof Error && "code" in err && err.code === "INVALID_PARAM") return;
|
|
714
|
-
throw err;
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
// src/internal/qq/media.ts
|
|
561
|
+
// src/internal/domain/media.ts
|
|
718
562
|
/**
|
|
719
563
|
* adapter core 媒体辅助:语音归一化 + 视频缩略图 + 图片元数据
|
|
720
564
|
* (media 严格解耦的协议层落点)
|
|
@@ -876,6 +720,162 @@ async function prepareVideoElements(elements) {
|
|
|
876
720
|
throw err;
|
|
877
721
|
}
|
|
878
722
|
}
|
|
723
|
+
// src/internal/infra/local-media.ts
|
|
724
|
+
const MAX_FILE_BYTES = 536870912;
|
|
725
|
+
const WINDOWS = process.platform === "win32";
|
|
726
|
+
const DEVICE_RE = /^(?:con|prn|aux|nul|conin\$|conout\$|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)/i;
|
|
727
|
+
const DRIVE_PATH_RE = /^[a-z]:[\\/]/i;
|
|
728
|
+
const NETWORK_PATH_RE = /^[\\/]{2}/;
|
|
729
|
+
const PATH_SEPARATOR_RE = /[\\/]/;
|
|
730
|
+
const WINDOWS_INVALID_NAME_RE = /[<>:"|?*]|[ .]$/;
|
|
731
|
+
const FILE_SCHEME_RE = /^file:/i;
|
|
732
|
+
const FILE_URI_RE = /^file:\/\//i;
|
|
733
|
+
const EXTENSION_RE = /\.[a-z0-9]+$/i;
|
|
734
|
+
const URI_SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i;
|
|
735
|
+
function denied() {
|
|
736
|
+
return kernelError("本地媒体路径未授权或文件不可用", "INVALID_PARAM");
|
|
737
|
+
}
|
|
738
|
+
function validateWindowsPath(path) {
|
|
739
|
+
if (isAbsolute(path) && !DRIVE_PATH_RE.test(path)) throw denied();
|
|
740
|
+
const components = path.replace(DRIVE_PATH_RE, "").split(PATH_SEPARATOR_RE);
|
|
741
|
+
for (const part of components) {
|
|
742
|
+
if (part === "." || part === "..") continue;
|
|
743
|
+
if (WINDOWS_INVALID_NAME_RE.test(part) || DEVICE_RE.test(part)) throw denied();
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
function validatePath(path) {
|
|
747
|
+
if (path === "" || path.includes("\0") || NETWORK_PATH_RE.test(path)) throw denied();
|
|
748
|
+
if (URI_SCHEME_RE.test(path) && !(WINDOWS && DRIVE_PATH_RE.test(path))) throw denied();
|
|
749
|
+
if (WINDOWS) validateWindowsPath(path);
|
|
750
|
+
return path;
|
|
751
|
+
}
|
|
752
|
+
function decodeLocalPath(input) {
|
|
753
|
+
if (!FILE_SCHEME_RE.test(input)) return validatePath(input);
|
|
754
|
+
try {
|
|
755
|
+
if (!FILE_URI_RE.test(input)) throw denied();
|
|
756
|
+
const url = new URL(input);
|
|
757
|
+
if (url.search || url.hash || url.hostname !== "") throw denied();
|
|
758
|
+
return validatePath(fileURLToPath(url));
|
|
759
|
+
} catch {
|
|
760
|
+
throw denied();
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
/** Resolve configuration relative to the trusted host base, never to a request path. */
|
|
764
|
+
function bindLocalMediaRoots(base, configured) {
|
|
765
|
+
const anchor = resolve(base ?? ".");
|
|
766
|
+
return () => (configured?.() ?? []).map((root) => resolve(anchor, validatePath(root)));
|
|
767
|
+
}
|
|
768
|
+
function within(root, path) {
|
|
769
|
+
return path.startsWith(root.endsWith(sep) ? root : root + sep) && path !== root;
|
|
770
|
+
}
|
|
771
|
+
function unavailable(err) {
|
|
772
|
+
return err instanceof Error && "code" in err && [
|
|
773
|
+
"ENOENT",
|
|
774
|
+
"ENOTDIR",
|
|
775
|
+
"EACCES",
|
|
776
|
+
"EPERM",
|
|
777
|
+
"ELOOP"
|
|
778
|
+
].includes(String(err.code));
|
|
779
|
+
}
|
|
780
|
+
function sameFile(a, b) {
|
|
781
|
+
return a.isFile() && b.isFile() && a.dev === b.dev && a.ino === b.ino && a.ino !== 0n;
|
|
782
|
+
}
|
|
783
|
+
function withinInputRoot(root, path) {
|
|
784
|
+
return WINDOWS ? within(root.toLowerCase(), path.toLowerCase()) : within(root, path);
|
|
785
|
+
}
|
|
786
|
+
async function findCandidate(input, configuredRoot) {
|
|
787
|
+
try {
|
|
788
|
+
const root = validatePath(await realpath(configuredRoot));
|
|
789
|
+
const candidate = resolve(root, input);
|
|
790
|
+
if (!withinInputRoot(root, candidate) && !withinInputRoot(configuredRoot, candidate)) return void 0;
|
|
791
|
+
const path = validatePath(await realpath(candidate));
|
|
792
|
+
if (!within(root, path) || isMediaCachePath(path)) throw denied();
|
|
793
|
+
const before = await lstat(path, { bigint: true });
|
|
794
|
+
if (!before.isFile() || before.nlink !== 1n) throw denied();
|
|
795
|
+
return {
|
|
796
|
+
root,
|
|
797
|
+
path,
|
|
798
|
+
before
|
|
799
|
+
};
|
|
800
|
+
} catch (err) {
|
|
801
|
+
if (unavailable(err)) return void 0;
|
|
802
|
+
throw err;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
async function selectCandidate(input, roots) {
|
|
806
|
+
const matches = /* @__PURE__ */ new Map();
|
|
807
|
+
for (const root of roots) {
|
|
808
|
+
const candidate = await findCandidate(input, resolve(root));
|
|
809
|
+
if (candidate !== void 0) matches.set(candidate.path, candidate);
|
|
810
|
+
}
|
|
811
|
+
if (matches.size !== 1) throw denied();
|
|
812
|
+
const [match] = matches.values();
|
|
813
|
+
if (match === void 0) throw denied();
|
|
814
|
+
return match;
|
|
815
|
+
}
|
|
816
|
+
async function verifyOpenFile(candidate, file) {
|
|
817
|
+
const { root, path, before } = candidate;
|
|
818
|
+
const opened = await file.stat({ bigint: true });
|
|
819
|
+
if (!sameFile(before, opened) || opened.nlink !== 1n || opened.size > MAX_FILE_BYTES) throw denied();
|
|
820
|
+
const actual = process.platform === "linux" ? await readlink(`/proc/self/fd/${file.fd}`) : await realpath(path);
|
|
821
|
+
if (actual !== path || !within(root, actual)) throw denied();
|
|
822
|
+
const after = await lstat(actual, { bigint: true });
|
|
823
|
+
if (!sameFile(after, opened) || after.nlink !== 1n) throw denied();
|
|
824
|
+
return Number(opened.size);
|
|
825
|
+
}
|
|
826
|
+
async function writeSnapshot(file, path, size) {
|
|
827
|
+
if (size === 0) {
|
|
828
|
+
await writeFile(path, "", {
|
|
829
|
+
flag: "wx",
|
|
830
|
+
mode: 384
|
|
831
|
+
});
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
const output = createWriteStream(path, {
|
|
835
|
+
flags: "wx",
|
|
836
|
+
mode: 384
|
|
837
|
+
});
|
|
838
|
+
await pipeline(file.createReadStream({
|
|
839
|
+
autoClose: false,
|
|
840
|
+
start: 0,
|
|
841
|
+
end: size - 1
|
|
842
|
+
}), output);
|
|
843
|
+
if (output.bytesWritten !== size) throw denied();
|
|
844
|
+
}
|
|
845
|
+
async function snapshot(candidate, cacheDir, lifetime) {
|
|
846
|
+
const linuxFlags = constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK;
|
|
847
|
+
const file = await open(candidate.path, WINDOWS ? "r" : linuxFlags);
|
|
848
|
+
try {
|
|
849
|
+
const size = await verifyOpenFile(candidate, file);
|
|
850
|
+
const name = basename(candidate.path);
|
|
851
|
+
return await cacheMediaFile(cacheDir, EXTENSION_RE.exec(name)?.[0] ?? ".bin", (path) => writeSnapshot(file, path, size), lifetime, lifetime === "temporary" ? name : void 0);
|
|
852
|
+
} finally {
|
|
853
|
+
await file.close();
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
/** The result is safe to hand to consumers that reopen a path, including native APIs. */
|
|
857
|
+
async function resolveLocalMedia(input, roots = []) {
|
|
858
|
+
const path = decodeLocalPath(input);
|
|
859
|
+
if (isMediaCachePath(path)) return await leaseMediaReference(path);
|
|
860
|
+
try {
|
|
861
|
+
return await snapshot(await selectCandidate(path, roots), MEDIA_TEMP_ROOT, "temporary");
|
|
862
|
+
} catch (err) {
|
|
863
|
+
if (unavailable(err)) throw denied();
|
|
864
|
+
throw err;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
/** QQ sources come from a current-account message/API response, never from RPC path fields. */
|
|
868
|
+
async function exportQqMedia(source, qqRoot, cacheDir) {
|
|
869
|
+
if (!source || !qqRoot) return void 0;
|
|
870
|
+
try {
|
|
871
|
+
const candidate = await findCandidate(validatePath(source.replaceAll("\\", sep)), resolve(qqRoot));
|
|
872
|
+
if (candidate === void 0) return void 0;
|
|
873
|
+
return await snapshot(candidate, cacheDir || MEDIA_TEMP_ROOT, "reference");
|
|
874
|
+
} catch (err) {
|
|
875
|
+
if (unavailable(err) || err instanceof Error && "code" in err && err.code === "INVALID_PARAM") return;
|
|
876
|
+
throw err;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
879
|
// src/internal/infra/media-config.ts
|
|
880
880
|
const protocolMediaSchema = z.object({
|
|
881
881
|
localMediaRoots: z.array(z.string().min(1)).optional(),
|
|
@@ -914,7 +914,7 @@ function sliceRaw(value, max = RAW_DEBUG_LIMIT) {
|
|
|
914
914
|
function logEventFailure(logger, msg, err) {
|
|
915
915
|
logger?.warn({ err: errorMessage(err) }, msg);
|
|
916
916
|
}
|
|
917
|
-
// src/internal/
|
|
917
|
+
// src/internal/domain/gray-tip.ts
|
|
918
918
|
/**
|
|
919
919
|
* 消息是否含 grayTip 元素(OB11 / Milky 收链路分流判据,收拢)。
|
|
920
920
|
* `!= null` 空值判定:Linux 原生宿主把未命中的变体字段显式置 null,
|
|
@@ -958,4 +958,4 @@ function firstUntranslatedGrayTip(msg) {
|
|
|
958
958
|
function findRevokeElement(msg) {
|
|
959
959
|
return msg.elements.find((el) => el.grayTipElement?.revokeElement != null)?.grayTipElement?.revokeElement ?? void 0;
|
|
960
960
|
}
|
|
961
|
-
export { MediaCache as _, logEventFailure as a, withMediaScope as b, protocolMediaSchema as c,
|
|
961
|
+
export { MediaCache as _, logEventFailure as a, withMediaScope as b, protocolMediaSchema as c, resolveLocalMedia as d, downloadProtocolMedia as f, prepareVideoElements as g, prepareImageElements as h, hasGrayTip as i, bindLocalMediaRoots as l, mediaDownloader as m, findRevokeElement as n, sliceRaw as o, ensureSilk as p, firstUntranslatedGrayTip as r, truncRaw as s, collectGrayTipUids as t, exportQqMedia as u, cacheMediaFile as v, leaseInternalMedia as y };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { f as ActionRegistry, n as ProtocolConfig, o as BaseProtocolAdapter, p as runAction, r as createServerSchema, t as ConfigBase } from "./framework-CA3087JP.mjs";
|
|
2
|
-
import { N as kurobotConfigSchema, t as NapukettoKurobotAdapter } from "./kurobot-
|
|
3
|
-
import { r as milkyConfigSchema, t as NapukettoMilkyAdapter } from "./milky-
|
|
4
|
-
import { t as NapukettoOneBot11Adapter, u as ob11ConfigSchema } from "./onebot11-
|
|
5
|
-
import { m as satoriConfigSchema, t as NapukettoSatoriAdapter } from "./satori-
|
|
2
|
+
import { N as kurobotConfigSchema, t as NapukettoKurobotAdapter } from "./kurobot-xqbvEUYA.mjs";
|
|
3
|
+
import { r as milkyConfigSchema, t as NapukettoMilkyAdapter } from "./milky-DbT3wxVC.mjs";
|
|
4
|
+
import { t as NapukettoOneBot11Adapter, u as ob11ConfigSchema } from "./onebot11-DnDRoiMk.mjs";
|
|
5
|
+
import { m as satoriConfigSchema, t as NapukettoSatoriAdapter } from "./satori-Cmu2QGGz.mjs";
|
|
6
6
|
export { ActionRegistry, BaseProtocolAdapter, ConfigBase, NapukettoKurobotAdapter, NapukettoMilkyAdapter, NapukettoOneBot11Adapter, NapukettoSatoriAdapter, ProtocolConfig, createServerSchema, kurobotConfigSchema, milkyConfigSchema, ob11ConfigSchema, runAction, satoriConfigSchema };
|
package/dist/kurobot/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { u as KurobotConnection, n as MAX_GROUP_TEXT_LENGTH, t as NapukettoKurobotAdapter, d as PROTOCOL_NAME, f as PROTOCOL_VERSION, p as WS_SUBPROTOCOL, m as bindingsUpdatedFrame, h as commandFrame, g as commandResultFrame, _ as deathFrame, r as degradeElements, i as degradeMessage, v as encodeFrame, y as gameChatFrame, b as helloAckFrame, x as helloFrame, S as isProtocolVersionCompatible, C as joinFrame, M as kurobotConfigDefaults, N as kurobotConfigSchema, w as leaveFrame, T as pingFrame, E as platformChatFrame, D as pongFrame, O as queryFrame, k as queryResultFrame, a as renderCommandResult, o as renderDeathText, s as renderTemplate, c as resolveSenderName, A as statusFrame, l as truncateForGroup, j as wireFrameSchema } from "../kurobot-
|
|
1
|
+
export { u as KurobotConnection, n as MAX_GROUP_TEXT_LENGTH, t as NapukettoKurobotAdapter, d as PROTOCOL_NAME, f as PROTOCOL_VERSION, p as WS_SUBPROTOCOL, m as bindingsUpdatedFrame, h as commandFrame, g as commandResultFrame, _ as deathFrame, r as degradeElements, i as degradeMessage, v as encodeFrame, y as gameChatFrame, b as helloAckFrame, x as helloFrame, S as isProtocolVersionCompatible, C as joinFrame, M as kurobotConfigDefaults, N as kurobotConfigSchema, w as leaveFrame, T as pingFrame, E as platformChatFrame, D as pongFrame, O as queryFrame, k as queryResultFrame, a as renderCommandResult, o as renderDeathText, s as renderTemplate, c as resolveSenderName, A as statusFrame, l as truncateForGroup, j as wireFrameSchema } from "../kurobot-xqbvEUYA.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { o as BaseProtocolAdapter, s as resolveProtocolConfig } from "./framework-CA3087JP.mjs";
|
|
2
|
-
import { r as subscribeRawMessages } from "./raw-message-
|
|
2
|
+
import { r as subscribeRawMessages } from "./raw-message-D9-8kPiU.mjs";
|
|
3
3
|
import { ChatType, errorMessage, getOwnProp, isRecord, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { z } from "zod";
|
package/dist/milky/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { a as MilkyApi, t as NapukettoMilkyAdapter, n as assembleMilkyTransports, i as createMilkyActionRegistry, r as milkyConfigSchema, o as milkyErrorCodeMap } from "../milky-
|
|
1
|
+
export { a as MilkyApi, t as NapukettoMilkyAdapter, n as assembleMilkyTransports, i as createMilkyActionRegistry, r as milkyConfigSchema, o as milkyErrorCodeMap } from "../milky-DbT3wxVC.mjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as BEARER_PREFIX, f as ActionRegistry, i as validateListenerToken, l as createTokenAuthorize, o as BaseProtocolAdapter, p as runAction, s as resolveProtocolConfig } from "./framework-CA3087JP.mjs";
|
|
2
|
-
import { _ as MediaCache, a as logEventFailure, b as withMediaScope, c as protocolMediaSchema, d as
|
|
3
|
-
import { a as firstNonEmptyString, c as MS_TO_SEC, d as numericUin, f as resolveUidToUinWithFallback, i as toUnixSeconds, l as NUMERIC_RE, m as toUin, o as stringOrUndefined, p as resolveUin, r as subscribeRawMessages, s as startupBaselineSec, t as forEachRawMessage } from "./raw-message-
|
|
4
|
-
import { a as processSysMsgBlob, c as varintAt, d as processInboundBuddyReqs, i as nodeAt, l as varintOf, n as OBSERVED_UNNAMED_SYSMSG_KEYS, o as recognizeSysMsg, r as narrowSysMsgBlobs, s as textOf, t as extractEssenceSetSysMsg, u as BuddyReqDedup } from "./essence-
|
|
2
|
+
import { _ as MediaCache, a as logEventFailure, b as withMediaScope, c as protocolMediaSchema, d as resolveLocalMedia, h as prepareImageElements, i as hasGrayTip, l as bindLocalMediaRoots, m as mediaDownloader, n as findRevokeElement, o as sliceRaw, r as firstUntranslatedGrayTip, t as collectGrayTipUids, v as cacheMediaFile } from "./gray-tip-jdpy-Jv3.mjs";
|
|
3
|
+
import { a as firstNonEmptyString, c as MS_TO_SEC, d as numericUin, f as resolveUidToUinWithFallback, i as toUnixSeconds, l as NUMERIC_RE, m as toUin, o as stringOrUndefined, p as resolveUin, r as subscribeRawMessages, s as startupBaselineSec, t as forEachRawMessage } from "./raw-message-D9-8kPiU.mjs";
|
|
4
|
+
import { a as processSysMsgBlob, c as varintAt, d as processInboundBuddyReqs, i as nodeAt, l as varintOf, n as OBSERVED_UNNAMED_SYSMSG_KEYS, o as recognizeSysMsg, r as narrowSysMsgBlobs, s as textOf, t as extractEssenceSetSysMsg, u as BuddyReqDedup } from "./essence-By64qv90.mjs";
|
|
5
5
|
import { ChatType, EssenceListSync, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, errorMessage, findPendingGroupRequest, hasNumberProp, hasStringProp, isRecord, kernelError, narrowEssenceGroupArg, toCanonicalElements } from "@napuketto/kernel";
|
|
6
6
|
import { HttpClient, HttpServer, createSseResponse, sendWsText } from "@napuketto/network";
|
|
7
7
|
import { z } from "zod";
|
|
@@ -1172,23 +1172,11 @@ function videoToIncoming(el) {
|
|
|
1172
1172
|
/**
|
|
1173
1173
|
* canonical → IncomingSegment 单元素分发(可辨识联合 switch)。
|
|
1174
1174
|
* 未映射类型(unknown / forward / 规范无对应)→ null(规范兼容性要求跳过)。
|
|
1175
|
-
*
|
|
1176
|
-
* 按「简单段 / 媒体与载荷段」拆两级:一级 switch 只分派,二级各管一类,
|
|
1177
|
-
* 单函数分支数保持低位(fallow 复杂度门禁)。
|
|
1178
1175
|
*/
|
|
1179
1176
|
function canonicalToIncomingSegment(el, ctx) {
|
|
1180
1177
|
switch (el.type) {
|
|
1181
1178
|
case "at": return atToIncoming(el, ctx);
|
|
1182
1179
|
case "reply": return replyToIncoming(el, ctx);
|
|
1183
|
-
case "text":
|
|
1184
|
-
case "face":
|
|
1185
|
-
case "file": return simpleIncoming(el);
|
|
1186
|
-
default: return mediaOrPayloadIncoming(el);
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
/** text / face / file 直映射。 */
|
|
1190
|
-
function simpleIncoming(el) {
|
|
1191
|
-
switch (el.type) {
|
|
1192
1180
|
case "text": return {
|
|
1193
1181
|
type: "text",
|
|
1194
1182
|
data: { text: el.text }
|
|
@@ -1201,11 +1189,6 @@ function simpleIncoming(el) {
|
|
|
1201
1189
|
}
|
|
1202
1190
|
};
|
|
1203
1191
|
case "file": return fileToIncoming(el);
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
/** 媒体段(image / voice / video)与载荷段(json / xml)映射;其余返回 null。 */
|
|
1207
|
-
function mediaOrPayloadIncoming(el) {
|
|
1208
|
-
switch (el.type) {
|
|
1209
1192
|
case "image": return imageToIncoming(el);
|
|
1210
1193
|
case "voice": return voiceToIncoming(el);
|
|
1211
1194
|
case "video": return videoToIncoming(el);
|
|
@@ -1332,53 +1315,10 @@ function outgoingSegmentsToCanonical(segments) {
|
|
|
1332
1315
|
replySeqs
|
|
1333
1316
|
};
|
|
1334
1317
|
}
|
|
1335
|
-
/** 段 data 收窄(非对象按空对象处理,字段守卫会立即拒绝)。 */
|
|
1336
|
-
function segmentData(seg) {
|
|
1337
|
-
return isRecord(seg.data) ? seg.data : {};
|
|
1338
|
-
}
|
|
1339
1318
|
/** 已知段缺必填字段 / 类型错误 → INVALID_PARAM。 */
|
|
1340
1319
|
function invalidSegment(type) {
|
|
1341
1320
|
throw kernelError(`Milky 消息段 ${type} 参数不合法`, "INVALID_PARAM");
|
|
1342
1321
|
}
|
|
1343
|
-
/** text 段(必填 text: string)。 */
|
|
1344
|
-
function textSegment(data) {
|
|
1345
|
-
if (!hasStringProp(data, "text")) return invalidSegment("text");
|
|
1346
|
-
return { element: {
|
|
1347
|
-
type: "text",
|
|
1348
|
-
text: data["text"]
|
|
1349
|
-
} };
|
|
1350
|
-
}
|
|
1351
|
-
/** mention 段(必填 user_id: number)。 */
|
|
1352
|
-
function mentionSegment(data) {
|
|
1353
|
-
if (!hasNumberProp(data, "user_id")) return invalidSegment("mention");
|
|
1354
|
-
const uin = String(data["user_id"]);
|
|
1355
|
-
return {
|
|
1356
|
-
element: {
|
|
1357
|
-
type: "at",
|
|
1358
|
-
target: uin
|
|
1359
|
-
},
|
|
1360
|
-
atUin: uin
|
|
1361
|
-
};
|
|
1362
|
-
}
|
|
1363
|
-
/** face 段(必填 face_id: string)。 */
|
|
1364
|
-
function faceSegment(data) {
|
|
1365
|
-
if (!hasStringProp(data, "face_id")) return invalidSegment("face");
|
|
1366
|
-
return { element: {
|
|
1367
|
-
type: "face",
|
|
1368
|
-
id: data["face_id"]
|
|
1369
|
-
} };
|
|
1370
|
-
}
|
|
1371
|
-
/** reply 段(必填 message_seq: number)。 */
|
|
1372
|
-
function replySegment(data) {
|
|
1373
|
-
if (!hasNumberProp(data, "message_seq")) return invalidSegment("reply");
|
|
1374
|
-
return {
|
|
1375
|
-
element: {
|
|
1376
|
-
type: "reply",
|
|
1377
|
-
messageId: String(data["message_seq"])
|
|
1378
|
-
},
|
|
1379
|
-
replySeq: data["message_seq"]
|
|
1380
|
-
};
|
|
1381
|
-
}
|
|
1382
1322
|
/** 媒体段(image/record/video,必填 uri: string)。 */
|
|
1383
1323
|
function mediaSegment(type, data) {
|
|
1384
1324
|
if (!hasStringProp(data, "uri")) return invalidSegment(type);
|
|
@@ -1392,55 +1332,60 @@ function mediaSegment(type, data) {
|
|
|
1392
1332
|
path
|
|
1393
1333
|
} };
|
|
1394
1334
|
}
|
|
1395
|
-
/**
|
|
1396
|
-
function
|
|
1397
|
-
const
|
|
1398
|
-
|
|
1399
|
-
type: "json",
|
|
1400
|
-
raw: typeof payload === "string" ? payload : ""
|
|
1401
|
-
} };
|
|
1402
|
-
}
|
|
1403
|
-
/** 简单段类型判定(字面量联合收窄)。 */
|
|
1404
|
-
function isSimpleOutgoingType(type) {
|
|
1405
|
-
switch (type) {
|
|
1335
|
+
/** 单段分派(可辨识联合 switch):已知类型逐项守卫,未知段跳过(规范兼容性要求)。 */
|
|
1336
|
+
function outgoingSegmentToCanonical(seg) {
|
|
1337
|
+
const data = isRecord(seg.data) ? seg.data : {};
|
|
1338
|
+
switch (seg.type) {
|
|
1406
1339
|
case "text":
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1340
|
+
if (!hasStringProp(data, "text")) return invalidSegment("text");
|
|
1341
|
+
return { element: {
|
|
1342
|
+
type: "text",
|
|
1343
|
+
text: data["text"]
|
|
1344
|
+
} };
|
|
1345
|
+
case "mention": {
|
|
1346
|
+
if (!hasNumberProp(data, "user_id")) return invalidSegment("mention");
|
|
1347
|
+
const uin = String(data["user_id"]);
|
|
1348
|
+
return {
|
|
1349
|
+
element: {
|
|
1350
|
+
type: "at",
|
|
1351
|
+
target: uin
|
|
1352
|
+
},
|
|
1353
|
+
atUin: uin
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1419
1356
|
case "mention_all": return { element: {
|
|
1420
1357
|
type: "at",
|
|
1421
1358
|
target: "all"
|
|
1422
1359
|
} };
|
|
1423
|
-
case "face":
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1360
|
+
case "face":
|
|
1361
|
+
if (!hasStringProp(data, "face_id")) return invalidSegment("face");
|
|
1362
|
+
return { element: {
|
|
1363
|
+
type: "face",
|
|
1364
|
+
id: data["face_id"]
|
|
1365
|
+
} };
|
|
1366
|
+
case "reply":
|
|
1367
|
+
if (!hasNumberProp(data, "message_seq")) return invalidSegment("reply");
|
|
1368
|
+
return {
|
|
1369
|
+
element: {
|
|
1370
|
+
type: "reply",
|
|
1371
|
+
messageId: String(data["message_seq"])
|
|
1372
|
+
},
|
|
1373
|
+
replySeq: data["message_seq"]
|
|
1374
|
+
};
|
|
1430
1375
|
case "image": return mediaSegment("image", data);
|
|
1431
1376
|
case "record": return mediaSegment("record", data);
|
|
1432
1377
|
case "video": return mediaSegment("video", data);
|
|
1433
|
-
case "light_app":
|
|
1378
|
+
case "light_app": {
|
|
1379
|
+
const payload = data["json_payload"];
|
|
1380
|
+
return { element: {
|
|
1381
|
+
type: "json",
|
|
1382
|
+
raw: typeof payload === "string" ? payload : ""
|
|
1383
|
+
} };
|
|
1384
|
+
}
|
|
1434
1385
|
case "forward": throw kernelError("forward 段不可与其他消息段混发或嵌套(顶层 forward 须单独发送)", "INVALID_PARAM");
|
|
1435
1386
|
default: return null;
|
|
1436
1387
|
}
|
|
1437
1388
|
}
|
|
1438
|
-
/** 单段分派入口(简单段 / 复杂段两级,避免单函数分支过多)。 */
|
|
1439
|
-
function outgoingSegmentToCanonical(seg) {
|
|
1440
|
-
const data = segmentData(seg);
|
|
1441
|
-
if (isSimpleOutgoingType(seg.type)) return simpleOutgoingSegment(seg.type, data);
|
|
1442
|
-
return complexOutgoingSegment(seg.type, data);
|
|
1443
|
-
}
|
|
1444
1389
|
// src/milky/helper/event/translate.ts
|
|
1445
1390
|
/**
|
|
1446
1391
|
* Milky 事件翻译(RawMessage → Milky 事件,纯函数)
|
package/dist/onebot11/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { y as MessageUnique, t as NapukettoOneBot11Adapter, r as OneBotApi, n as assembleOb11Transports, a as canonicalToCqMessage, o as canonicalToSegments, s as cqMessageToCanonical, c as cqMessageToSegments, i as createOb11ActionRegistry, f as encodeCqCode, p as escapeCqParam, m as escapeCqText, u as ob11ConfigSchema, v as ob11ErrorCodeMap, h as parseCqMessage, l as segmentsToCanonical, d as segmentsToCqMessage, g as serializeCqParts, _ as unescapeCqText } from "../onebot11-
|
|
1
|
+
export { y as MessageUnique, t as NapukettoOneBot11Adapter, r as OneBotApi, n as assembleOb11Transports, a as canonicalToCqMessage, o as canonicalToSegments, s as cqMessageToCanonical, c as cqMessageToSegments, i as createOb11ActionRegistry, f as encodeCqCode, p as escapeCqParam, m as escapeCqText, u as ob11ConfigSchema, v as ob11ErrorCodeMap, h as parseCqMessage, l as segmentsToCanonical, d as segmentsToCqMessage, g as serializeCqParts, _ as unescapeCqText } from "../onebot11-DnDRoiMk.mjs";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as validateServerTokens, c as BEARER_PREFIX, f as ActionRegistry, l as createTokenAuthorize, o as BaseProtocolAdapter, p as runAction, r as createServerSchema, s as resolveProtocolConfig } from "./framework-CA3087JP.mjs";
|
|
2
|
-
import { _ as MediaCache, a as logEventFailure, b as withMediaScope, c as protocolMediaSchema, d as
|
|
3
|
-
import { a as firstNonEmptyString, c as MS_TO_SEC, d as numericUin, f as resolveUidToUinWithFallback, i as toUnixSeconds, l as NUMERIC_RE, m as toUin, n as senderNickname, o as stringOrUndefined, p as resolveUin, r as subscribeRawMessages, s as startupBaselineSec, u as collectGroupNotifyUids } from "./raw-message-
|
|
4
|
-
import { a as processSysMsgBlob, d as processInboundBuddyReqs, n as OBSERVED_UNNAMED_SYSMSG_KEYS, o as recognizeSysMsg, r as narrowSysMsgBlobs, t as extractEssenceSetSysMsg, u as BuddyReqDedup } from "./essence-
|
|
5
|
-
import { ChatType, EssenceListSync, GrayTipSubType, GroupApi, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, WebHonorType, errorMessage, findPendingGroupRequest, hasStringProp, isRecord, kernelError, narrowEssenceGroupArg, toCanonicalElements, toPendingGroupRequest } from "@napuketto/kernel";
|
|
2
|
+
import { _ as MediaCache, a as logEventFailure, b as withMediaScope, c as protocolMediaSchema, d as resolveLocalMedia, f as downloadProtocolMedia, g as prepareVideoElements, h as prepareImageElements, i as hasGrayTip, l as bindLocalMediaRoots, m as mediaDownloader, o as sliceRaw, p as ensureSilk, r as firstUntranslatedGrayTip, s as truncRaw, t as collectGrayTipUids, u as exportQqMedia, v as cacheMediaFile } from "./gray-tip-jdpy-Jv3.mjs";
|
|
3
|
+
import { a as firstNonEmptyString, c as MS_TO_SEC, d as numericUin, f as resolveUidToUinWithFallback, i as toUnixSeconds, l as NUMERIC_RE, m as toUin, n as senderNickname, o as stringOrUndefined, p as resolveUin, r as subscribeRawMessages, s as startupBaselineSec, u as collectGroupNotifyUids } from "./raw-message-D9-8kPiU.mjs";
|
|
4
|
+
import { a as processSysMsgBlob, d as processInboundBuddyReqs, n as OBSERVED_UNNAMED_SYSMSG_KEYS, o as recognizeSysMsg, r as narrowSysMsgBlobs, t as extractEssenceSetSysMsg, u as BuddyReqDedup } from "./essence-By64qv90.mjs";
|
|
5
|
+
import { ChatType, EssenceListSync, GrayTipSubType, GroupApi, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, WebHonorType, errorMessage, findPendingGroupRequest, hasOptionalStringProp, hasStringProp, isRecord, kernelError, narrowEssenceGroupArg, toCanonicalElements, toPendingGroupRequest } from "@napuketto/kernel";
|
|
6
6
|
import { HttpClient, HttpServer, WsClient, WsServer } from "@napuketto/network";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { basename } from "node:path";
|
|
@@ -1132,33 +1132,23 @@ function rawToString(raw) {
|
|
|
1132
1132
|
function isStringOrNumber(val) {
|
|
1133
1133
|
return typeof val === "string" || typeof val === "number";
|
|
1134
1134
|
}
|
|
1135
|
-
/**
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1135
|
+
/**
|
|
1136
|
+
* OB11 消息段形状守卫:`type` 为 string,`data` 为对象,且**已知类型的必填字段**
|
|
1137
|
+
* 类型正确。未知 `type` 一律判非法(发送入口显式拒绝,不静默丢段)。
|
|
1138
|
+
*/
|
|
1139
|
+
function isOB11MessageSegment(val) {
|
|
1140
|
+
if (!isRecord(val) || !hasStringProp(val, "type")) return false;
|
|
1141
|
+
const data = val["data"];
|
|
1142
|
+
if (!isRecord(data)) return false;
|
|
1143
|
+
switch (val["type"]) {
|
|
1142
1144
|
case "text":
|
|
1143
1145
|
case "string": return hasStringProp(data, "text");
|
|
1144
|
-
case "at": return isStringOrNumber(data["qq"]) &&
|
|
1146
|
+
case "at": return isStringOrNumber(data["qq"]) && hasOptionalStringProp(data, "name");
|
|
1145
1147
|
case "face": return isStringOrNumber(data["id"]);
|
|
1146
|
-
default: return false;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
/** image / record / video / file 类型的 data 校验。 */
|
|
1150
|
-
function isMediaSegmentData(type, data) {
|
|
1151
|
-
switch (type) {
|
|
1152
1148
|
case "image":
|
|
1153
1149
|
case "record":
|
|
1154
|
-
case "video": return hasStringProp(data, "file") &&
|
|
1150
|
+
case "video": return hasStringProp(data, "file") && hasOptionalStringProp(data, "url");
|
|
1155
1151
|
case "file": return hasStringProp(data, "file");
|
|
1156
|
-
default: return false;
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
/** reply / forward / json / xml 类型的 data 校验。 */
|
|
1160
|
-
function isPayloadSegmentData(type, data) {
|
|
1161
|
-
switch (type) {
|
|
1162
1152
|
case "reply":
|
|
1163
1153
|
case "forward": return isStringOrNumber(data["id"]);
|
|
1164
1154
|
case "json":
|
|
@@ -1167,19 +1157,6 @@ function isPayloadSegmentData(type, data) {
|
|
|
1167
1157
|
}
|
|
1168
1158
|
}
|
|
1169
1159
|
/**
|
|
1170
|
-
* OB11 消息段形状守卫:`type` 为 string,`data` 为对象,且**已知类型的必填字段**
|
|
1171
|
-
* 类型正确。未知 `type` 一律判非法(发送入口显式拒绝,不静默丢段)。
|
|
1172
|
-
*
|
|
1173
|
-
* 按 data 校验形态拆成三组小函数(文本类 / 媒体类 / 载荷类),主函数只做短路组合。
|
|
1174
|
-
*/
|
|
1175
|
-
function isOB11MessageSegment(val) {
|
|
1176
|
-
if (!isRecord(val) || !hasStringProp(val, "type")) return false;
|
|
1177
|
-
const data = val["data"];
|
|
1178
|
-
if (!isRecord(data)) return false;
|
|
1179
|
-
const type = val["type"];
|
|
1180
|
-
return isTextLikeSegmentData(type, data) || isMediaSegmentData(type, data) || isPayloadSegmentData(type, data);
|
|
1181
|
-
}
|
|
1182
|
-
/**
|
|
1183
1160
|
* 校验并收窄入站 segment 数组(HTTP 动作载荷 → OB11MessageSegment[])。
|
|
1184
1161
|
* 任一项不合法即抛 INVALID_PARAM(ADR-009 外部边界统一错误语义)。
|
|
1185
1162
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { errorMessage, hasNumberProp, hasStringProp, isRecord } from "@napuketto/kernel";
|
|
2
|
-
// src/internal/
|
|
2
|
+
// src/internal/domain/uid-uin.ts
|
|
3
3
|
/** 毫秒 → 秒(Unix 时间戳换算)。 */
|
|
4
4
|
const MS_TO_SEC = 1e3;
|
|
5
5
|
/** uid → uin(映射命中取 uin,未命中退化 uid 数值,非数字返回 0)。 */
|
|
@@ -80,7 +80,7 @@ async function resolveUidToUinWithFallback(uids, deps) {
|
|
|
80
80
|
function startupBaselineSec(graceSec = 5) {
|
|
81
81
|
return Math.floor(Date.now() / MS_TO_SEC) - graceSec;
|
|
82
82
|
}
|
|
83
|
-
// src/internal/
|
|
83
|
+
// src/internal/domain/text.ts
|
|
84
84
|
/**
|
|
85
85
|
* 字符串取值小工具(跨协议共用)
|
|
86
86
|
*
|
|
@@ -99,7 +99,7 @@ function firstNonEmptyString(...values) {
|
|
|
99
99
|
function stringOrUndefined(value) {
|
|
100
100
|
return typeof value === "string" ? value : void 0;
|
|
101
101
|
}
|
|
102
|
-
// src/internal/
|
|
102
|
+
// src/internal/domain/raw-message.ts
|
|
103
103
|
/**
|
|
104
104
|
* 发送者显示名(跨平台字段名不同,Linux 原生 wrapper 实测):
|
|
105
105
|
* - Windows:`sendNickName` = 昵称,`sendMemberName` = 群名片(可空);
|
package/dist/satori/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { f as HTTP_STATUS, t as NapukettoSatoriAdapter, c as SatoriActionError, i as SatoriApi, n as assembleSatoriTransports, d as canonicalToSatoriElements, a as createSatoriActionRegistry, o as parseContentToCanonical, l as parseElements, u as renderElements, m as satoriConfigSchema, p as satoriHttpStatusMap, s as satoriToCanonicalElements, r as toEventSignal } from "../satori-
|
|
1
|
+
export { f as HTTP_STATUS, t as NapukettoSatoriAdapter, c as SatoriActionError, i as SatoriApi, n as assembleSatoriTransports, d as canonicalToSatoriElements, a as createSatoriActionRegistry, o as parseContentToCanonical, l as parseElements, u as renderElements, m as satoriConfigSchema, p as satoriHttpStatusMap, s as satoriToCanonicalElements, r as toEventSignal } from "../satori-Cmu2QGGz.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as validateServerTokens, d as tokenEquals, f as ActionRegistry, l as createTokenAuthorize, o as BaseProtocolAdapter, p as runAction, r as createServerSchema, s as resolveProtocolConfig } from "./framework-CA3087JP.mjs";
|
|
2
|
-
import { _ as MediaCache, a as logEventFailure, b as withMediaScope, c as protocolMediaSchema,
|
|
3
|
-
import { c as MS_TO_SEC, h as toUinString, i as toUnixSeconds, r as subscribeRawMessages } from "./raw-message-
|
|
2
|
+
import { _ as MediaCache, a as logEventFailure, b as withMediaScope, c as protocolMediaSchema, d as resolveLocalMedia, f as downloadProtocolMedia, h as prepareImageElements, l as bindLocalMediaRoots, p as ensureSilk, t as collectGrayTipUids, u as exportQqMedia, v as cacheMediaFile, y as leaseInternalMedia } from "./gray-tip-jdpy-Jv3.mjs";
|
|
3
|
+
import { c as MS_TO_SEC, h as toUinString, i as toUnixSeconds, r as subscribeRawMessages } from "./raw-message-D9-8kPiU.mjs";
|
|
4
4
|
import { ChatType, GrayTipSubType, NTGroupRequestOperateTypes, TipGroupElementType, errorMessage, findPendingGroupRequest, isRecord, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
5
5
|
import { HttpServer, WsServer, isWsOpen, sendWsText } from "@napuketto/network";
|
|
6
6
|
import { z } from "zod";
|
|
@@ -384,26 +384,30 @@ function readTag(source, pos) {
|
|
|
384
384
|
* - 未配对的标签视为文本内容的一部分
|
|
385
385
|
* - 文本内容前后包含换行符的连续空白会被忽略
|
|
386
386
|
*/
|
|
387
|
+
/** 文本转义映射(& < >)。 */
|
|
388
|
+
const TEXT_ESCAPES = {
|
|
389
|
+
"&": "&",
|
|
390
|
+
"<": "<",
|
|
391
|
+
">": ">"
|
|
392
|
+
};
|
|
387
393
|
/** 文本转义正则(& < >)。 */
|
|
388
394
|
const TEXT_ESCAPE_RE = /[&<>]/g;
|
|
389
395
|
/** 文本转义(& < >)。 */
|
|
390
396
|
function encodeText(input) {
|
|
391
|
-
return input.replace(TEXT_ESCAPE_RE, (ch) =>
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
+
return input.replace(TEXT_ESCAPE_RE, (ch) => TEXT_ESCAPES[ch] ?? ch);
|
|
398
|
+
}
|
|
399
|
+
/** 属性值转义映射(& " < >)。 */
|
|
400
|
+
const ATTR_ESCAPES = {
|
|
401
|
+
"&": "&",
|
|
402
|
+
"\"": """,
|
|
403
|
+
"<": "<",
|
|
404
|
+
">": ">"
|
|
405
|
+
};
|
|
397
406
|
/** 属性值转义正则(& " < >)。 */
|
|
398
407
|
const ATTR_ESCAPE_RE = /[&"<>]/g;
|
|
399
408
|
/** 属性值转义(& " < >)。 */
|
|
400
409
|
function encodeAttr(input) {
|
|
401
|
-
return input.replace(ATTR_ESCAPE_RE, (ch) =>
|
|
402
|
-
if (ch === "&") return "&";
|
|
403
|
-
if (ch === "\"") return """;
|
|
404
|
-
if (ch === "<") return "<";
|
|
405
|
-
return ">";
|
|
406
|
-
});
|
|
410
|
+
return input.replace(ATTR_ESCAPE_RE, (ch) => ATTR_ESCAPES[ch] ?? ch);
|
|
407
411
|
}
|
|
408
412
|
/** 行首连续空白。 */
|
|
409
413
|
const LEADING_WS_RE = /^\s+/;
|
|
@@ -423,114 +427,91 @@ function normalizeText(raw) {
|
|
|
423
427
|
if (trailing !== null && NEWLINE_RE.test(trailing[0])) out = out.slice(0, -trailing[0].length);
|
|
424
428
|
return out;
|
|
425
429
|
}
|
|
426
|
-
/**
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
/** 追加原始文本(解析间隙累积)。 */
|
|
452
|
-
appendRaw(raw) {
|
|
453
|
-
this.text += raw;
|
|
454
|
-
}
|
|
455
|
-
/** 起始/自闭合标签落位(压栈或仅挂载)。 */
|
|
456
|
-
openTag(name, attrs, selfClosing) {
|
|
457
|
-
const el = {
|
|
458
|
-
type: name,
|
|
459
|
-
attrs
|
|
460
|
-
};
|
|
461
|
-
this.mountPoint().push(el);
|
|
462
|
-
if (!selfClosing) this.stack.push(el);
|
|
463
|
-
}
|
|
464
|
-
/** 收尾:剩余文本落位(栈剩余未闭合元素:文本落在栈顶元素内,宽容)。 */
|
|
465
|
-
flush() {
|
|
466
|
-
this.pushText();
|
|
467
|
-
}
|
|
468
|
-
/** 注释:返回跳过后的位置;-1 = 未闭合终止解析(注释不渲染)。 */
|
|
469
|
-
skipComment(source, pos) {
|
|
470
|
-
const end = source.indexOf("-->", pos);
|
|
471
|
-
return end === -1 ? -1 : end + 3;
|
|
430
|
+
/** 当前挂载数组(栈顶元素 children 或根数组)。 */
|
|
431
|
+
function mountPoint(state) {
|
|
432
|
+
const top = state.stack[state.stack.length - 1];
|
|
433
|
+
if (top === void 0) return state.root;
|
|
434
|
+
top.children ??= [];
|
|
435
|
+
return top.children;
|
|
436
|
+
}
|
|
437
|
+
/** 归一化文本落位到当前挂载点。 */
|
|
438
|
+
function pushText(state) {
|
|
439
|
+
const normalized = normalizeText(state.text);
|
|
440
|
+
state.text = "";
|
|
441
|
+
if (normalized !== "") mountPoint(state).push({
|
|
442
|
+
type: "text",
|
|
443
|
+
text: normalized
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* 结束标签:匹配栈顶则闭合,否则按文本保留。
|
|
448
|
+
* @returns 下一个解析位置;-1 = 终止解析。
|
|
449
|
+
*/
|
|
450
|
+
function closeTag(state, source, lt, slashPos) {
|
|
451
|
+
const { name, end } = readTagName(source, slashPos + 1);
|
|
452
|
+
if (name === "") {
|
|
453
|
+
state.text += "<";
|
|
454
|
+
return lt + 1;
|
|
472
455
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
closeTag(source, lt, slashPos) {
|
|
478
|
-
const { name, end } = readTagName(source, slashPos + 1);
|
|
479
|
-
if (name === "") {
|
|
480
|
-
this.text += "<";
|
|
481
|
-
return lt + 1;
|
|
482
|
-
}
|
|
483
|
-
const gt = source.indexOf(">", end);
|
|
484
|
-
if (gt === -1) {
|
|
485
|
-
this.text += source.slice(lt);
|
|
486
|
-
return -1;
|
|
487
|
-
}
|
|
488
|
-
const top = this.stack[this.stack.length - 1];
|
|
489
|
-
if (top !== void 0 && top.type === name) {
|
|
490
|
-
this.pushText();
|
|
491
|
-
this.stack.pop();
|
|
492
|
-
} else this.text += source.slice(lt, gt + 1);
|
|
493
|
-
return gt + 1;
|
|
456
|
+
const gt = source.indexOf(">", end);
|
|
457
|
+
if (gt === -1) {
|
|
458
|
+
state.text += source.slice(lt);
|
|
459
|
+
return -1;
|
|
494
460
|
}
|
|
495
|
-
|
|
461
|
+
const top = state.stack[state.stack.length - 1];
|
|
462
|
+
if (top !== void 0 && top.type === name) {
|
|
463
|
+
pushText(state);
|
|
464
|
+
state.stack.pop();
|
|
465
|
+
} else state.text += source.slice(lt, gt + 1);
|
|
466
|
+
return gt + 1;
|
|
467
|
+
}
|
|
496
468
|
/**
|
|
497
469
|
* 解析 Satori 消息字符串 → 元素树。
|
|
498
470
|
* 容错:未配对标签/非法标签按文本保留;解析不抛错(消息内容宽容)。
|
|
499
471
|
*/
|
|
500
472
|
function parseElements(source) {
|
|
501
|
-
const
|
|
473
|
+
const state = {
|
|
474
|
+
root: [],
|
|
475
|
+
stack: [],
|
|
476
|
+
text: ""
|
|
477
|
+
};
|
|
502
478
|
let i = 0;
|
|
503
479
|
while (i < source.length) {
|
|
504
480
|
const lt = source.indexOf("<", i);
|
|
505
481
|
if (lt === -1) {
|
|
506
|
-
|
|
482
|
+
state.text += source.slice(i);
|
|
507
483
|
break;
|
|
508
484
|
}
|
|
509
|
-
|
|
485
|
+
state.text += source.slice(i, lt);
|
|
510
486
|
i = lt + 1;
|
|
511
487
|
if (source.startsWith("!--", i)) {
|
|
512
|
-
const
|
|
513
|
-
if (
|
|
514
|
-
i =
|
|
488
|
+
const end = source.indexOf("-->", i);
|
|
489
|
+
if (end === -1) break;
|
|
490
|
+
i = end + 3;
|
|
515
491
|
continue;
|
|
516
492
|
}
|
|
517
493
|
if (source.startsWith("/", i)) {
|
|
518
|
-
const next =
|
|
494
|
+
const next = closeTag(state, source, lt, i);
|
|
519
495
|
if (next === -1) break;
|
|
520
496
|
i = next;
|
|
521
497
|
continue;
|
|
522
498
|
}
|
|
523
499
|
const tag = readTag(source, i);
|
|
524
500
|
if (tag.name === "") {
|
|
525
|
-
|
|
501
|
+
state.text += "<";
|
|
526
502
|
continue;
|
|
527
503
|
}
|
|
528
|
-
|
|
529
|
-
|
|
504
|
+
pushText(state);
|
|
505
|
+
const el = {
|
|
506
|
+
type: tag.name,
|
|
507
|
+
attrs: tag.attrs
|
|
508
|
+
};
|
|
509
|
+
mountPoint(state).push(el);
|
|
510
|
+
if (!tag.selfClosing) state.stack.push(el);
|
|
530
511
|
i = tag.end;
|
|
531
512
|
}
|
|
532
|
-
|
|
533
|
-
return
|
|
513
|
+
pushText(state);
|
|
514
|
+
return state.root;
|
|
534
515
|
}
|
|
535
516
|
/** 元素树 → Satori 消息字符串。 */
|
|
536
517
|
function renderElements(elements) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@napuketto/adapter",
|
|
4
|
-
"version": "0.24.
|
|
4
|
+
"version": "0.24.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Protocol adapters (OneBot11 / Satori / KuroBot / Milky) for Napuketto",
|
|
7
7
|
"keywords": [
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"dev": "tsdown --watch"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@napuketto/kernel": "^0.19.
|
|
85
|
+
"@napuketto/kernel": "^0.19.5",
|
|
86
86
|
"@napuketto/media": "^0.4.1",
|
|
87
87
|
"@napuketto/network": "^0.5.1",
|
|
88
88
|
"zod": "^4.6.7"
|