@napuketto/adapter 0.24.4 → 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-CXj1VAP8.mjs → essence-By64qv90.mjs} +33 -53
- package/dist/index.mjs +3 -3
- package/dist/milky/index.mjs +1 -1
- package/dist/{milky-CNn-vyvI.mjs → milky-DbT3wxVC.mjs} +43 -98
- package/dist/onebot11/index.mjs +1 -1
- package/dist/{onebot11-DOOBXC3z.mjs → onebot11-DnDRoiMk.mjs} +13 -36
- package/dist/satori/index.mjs +1 -1
- package/dist/{satori-DewkytUw.mjs → satori-Cmu2QGGz.mjs} +73 -92
- package/package.json +2 -2
|
@@ -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
|
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
2
|
import { N as kurobotConfigSchema, t as NapukettoKurobotAdapter } from "./kurobot-xqbvEUYA.mjs";
|
|
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-
|
|
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/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
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
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-
|
|
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
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
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-
|
|
5
|
-
import { ChatType, EssenceListSync, GrayTipSubType, GroupApi, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, WebHonorType, errorMessage, findPendingGroupRequest, hasStringProp, isRecord, kernelError, narrowEssenceGroupArg, toCanonicalElements, toPendingGroupRequest } from "@napuketto/kernel";
|
|
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
|
*/
|
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";
|
|
@@ -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"
|