@napuketto/adapter 0.18.1 → 0.18.3
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/{buddy-req-CN7gzJpq.mjs → buddy-req-BeEl05O8.mjs} +27 -3
- package/dist/{buddy-req-CN7gzJpq.mjs.map → buddy-req-BeEl05O8.mjs.map} +1 -1
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +1 -1
- package/dist/{core-4PwF_pJB.mjs → core-5cq8w_zB.mjs} +36 -2
- package/dist/core-5cq8w_zB.mjs.map +1 -0
- package/dist/{index-DAsCCf9S.d.mts → index-BFvhy1hU.d.mts} +2 -2
- package/dist/{index-DAsCCf9S.d.mts.map → index-BFvhy1hU.d.mts.map} +1 -1
- package/dist/{index-lKqnKSwo.d.mts → index-BHS4Wz74.d.mts} +2 -2
- package/dist/{index-lKqnKSwo.d.mts.map → index-BHS4Wz74.d.mts.map} +1 -1
- package/dist/{index-D9Nwf0_4.d.mts → index-BZfGz6FA.d.mts} +26 -3
- package/dist/index-BZfGz6FA.d.mts.map +1 -0
- package/dist/{index-CiitTshy.d.mts → index-BlRIp4xi.d.mts} +2 -2
- package/dist/{index-CiitTshy.d.mts.map → index-BlRIp4xi.d.mts.map} +1 -1
- package/dist/{index-CKH8uaU-.d.mts → index-oinf9f75.d.mts} +2 -2
- package/dist/{index-CKH8uaU-.d.mts.map → index-oinf9f75.d.mts.map} +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +5 -5
- package/dist/kurobot/index.d.mts +1 -1
- package/dist/kurobot/index.mjs +1 -1
- package/dist/{kurobot-CG2qGU9G.mjs → kurobot-De610F3j.mjs} +3 -3
- package/dist/{kurobot-CG2qGU9G.mjs.map → kurobot-De610F3j.mjs.map} +1 -1
- package/dist/milky/index.d.mts +1 -1
- package/dist/milky/index.mjs +1 -1
- package/dist/{milky-DMmeotN9.mjs → milky-DvDcch01.mjs} +31 -70
- package/dist/milky-DvDcch01.mjs.map +1 -0
- package/dist/onebot11/index.d.mts +1 -1
- package/dist/onebot11/index.mjs +1 -1
- package/dist/{onebot11-CAf9fBoJ.mjs → onebot11-BL02tXe_.mjs} +30 -86
- package/dist/{onebot11-CAf9fBoJ.mjs.map → onebot11-BL02tXe_.mjs.map} +1 -1
- package/dist/{raw-message-Cs4vDKUU.mjs → raw-message-CXRlSiNk.mjs} +46 -12
- package/dist/raw-message-CXRlSiNk.mjs.map +1 -0
- package/dist/satori/index.d.mts +1 -1
- package/dist/satori/index.mjs +1 -1
- package/dist/{satori-D5lM6S3L.mjs → satori-CB-O6IN0.mjs} +5 -14
- package/dist/{satori-D5lM6S3L.mjs.map → satori-CB-O6IN0.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/core-4PwF_pJB.mjs.map +0 -1
- package/dist/index-D9Nwf0_4.d.mts.map +0 -1
- package/dist/milky-DMmeotN9.mjs.map +0 -1
- package/dist/raw-message-Cs4vDKUU.mjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as resolveProtocolConfig, i as BaseProtocolAdapter,
|
|
1
|
+
import { a as resolveProtocolConfig, c as matchTokenCredential, i as BaseProtocolAdapter, l as ActionRegistry, o as BEARER_PREFIX, s as createTokenAuthorize, u as runAction } from "./core-5cq8w_zB.mjs";
|
|
2
2
|
import { a as logEventFailure, i as hasGrayTip, n as findRevokeElement, o as sliceRaw, r as firstUntranslatedGrayTip, t as collectGrayTipUids, u as fileUriToPath } from "./gray-tip-DmZmdtjP.mjs";
|
|
3
|
-
import { a as firstNonEmptyString, c as MS_TO_SEC, d as
|
|
4
|
-
import { a 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-CXRlSiNk.mjs";
|
|
4
|
+
import { a as narrowEssenceGroupArg, c as nodeAt, d as textOf, f as varintAt, i as extractEssenceSetSysMsg, l as processSysMsgBlob, n as processInboundBuddyReqs, o as OBSERVED_UNNAMED_SYSMSG_KEYS, p as varintOf, r as EssenceListSync, s as narrowSysMsgBlobs, t as BuddyReqDedup, u as recognizeSysMsg } from "./buddy-req-BeEl05O8.mjs";
|
|
5
5
|
import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, errorMessage, hasNumberProp, hasStringProp, isRecord, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
6
6
|
import { HttpClient, HttpServer, createSseResponse, isWsOpen } from "@napuketto/network";
|
|
7
7
|
import { z } from "zod";
|
|
@@ -2256,8 +2256,6 @@ const milkyConfigSchema = z.object({
|
|
|
2256
2256
|
cacheDir: z.string().optional()
|
|
2257
2257
|
});
|
|
2258
2258
|
// src/milky/enrichment.ts
|
|
2259
|
-
/** 资料详情兜底的单批上限(好友申请批通常只有个位数,超限多为历史积压)。 */
|
|
2260
|
-
const MAX_PROFILE_LOOKUPS = 10;
|
|
2261
2259
|
/** Milky 收链路异步回填器。 */
|
|
2262
2260
|
var MilkyEnrichment = class {
|
|
2263
2261
|
api;
|
|
@@ -2265,42 +2263,24 @@ var MilkyEnrichment = class {
|
|
|
2265
2263
|
this.api = deps.api;
|
|
2266
2264
|
}
|
|
2267
2265
|
/**
|
|
2268
|
-
* uid 批量 → uin
|
|
2266
|
+
* uid 批量 → uin(空集返回 undefined 语义:调用方据此决定是否展开 `uidToUin`
|
|
2267
|
+
* 属性,空 Map 与「未查询」在事件载荷上不同)。
|
|
2269
2268
|
*
|
|
2270
2269
|
* `profileFallback` 时才做资料详情兜底(issue #122):好友申请的申请人通常不在
|
|
2271
2270
|
* 任何群里,群口径必然命中不了;而 grayTip 一类高频路径不做兜底——群口径整体失败
|
|
2272
|
-
* 时逐 uid 打 IPC
|
|
2271
|
+
* 时逐 uid 打 IPC 会把收链路拖垮。批量 / 兜底的 fail-soft 留痕在共享原语内完成。
|
|
2273
2272
|
*/
|
|
2274
2273
|
async resolveUidToUin(uids, options = {}) {
|
|
2275
2274
|
const unique = [...new Set(uids.filter((uid) => uid !== ""))];
|
|
2276
2275
|
if (unique.length === 0) return;
|
|
2277
|
-
|
|
2278
|
-
this.api.
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2276
|
+
return resolveUidToUinWithFallback(unique, {
|
|
2277
|
+
uidToUin: (batch) => this.api.uidToUin(batch),
|
|
2278
|
+
getUinByUid: (uid) => this.api.profileApi.getUinByUid(uid),
|
|
2279
|
+
logger: this.api.logger,
|
|
2280
|
+
scope: "milky",
|
|
2281
|
+
batchWarnMsg: "milky: uid→uin 批量转换失败,事件退用 uid",
|
|
2282
|
+
profileFallback: options.profileFallback === true
|
|
2283
2283
|
});
|
|
2284
|
-
if (options.profileFallback === true) await this.fillMissingUins(unique, map);
|
|
2285
|
-
return map;
|
|
2286
|
-
}
|
|
2287
|
-
/**
|
|
2288
|
-
* 群口径未命中的 uid 逐个走 `profileApi.getUinByUid` 兜底(原地补 map)。
|
|
2289
|
-
* fail-soft:单条失败 / 查不到保持未命中(翻译层退 0);条数设上限,防历史积压
|
|
2290
|
-
* 批次把逐条 IPC 打满。
|
|
2291
|
-
*/
|
|
2292
|
-
async fillMissingUins(uids, map) {
|
|
2293
|
-
const missing = uids.filter((uid) => !map.has(uid));
|
|
2294
|
-
for (const uid of missing.slice(0, MAX_PROFILE_LOOKUPS)) try {
|
|
2295
|
-
const uin = await this.api.profileApi.getUinByUid(uid);
|
|
2296
|
-
if (uin !== null) map.set(uid, uin);
|
|
2297
|
-
} catch (err) {
|
|
2298
|
-
this.api.logger?.debug({ error: errorMessage(err) }, "milky: uid→uin 资料兜底失败(该 uid 退 0)");
|
|
2299
|
-
}
|
|
2300
|
-
if (missing.length > MAX_PROFILE_LOOKUPS) this.api.logger?.debug({
|
|
2301
|
-
missing: missing.length,
|
|
2302
|
-
limit: MAX_PROFILE_LOOKUPS
|
|
2303
|
-
}, "milky: 待兜底 uid 超上限,其余保持未命中");
|
|
2304
2284
|
}
|
|
2305
2285
|
/** at uid → uin 批量转换(mention.user_id 用;失败 mention 段跳过)。 */
|
|
2306
2286
|
async fillMentionUids(elements, ctx) {
|
|
@@ -2994,20 +2974,13 @@ var MilkyInboundRequest = class {
|
|
|
2994
2974
|
this.broadcastBuddyReqs(arg).catch((err) => logEventFailure(this.deps.logger, "milky: friend request 翻译失败(整批丢弃)", err));
|
|
2995
2975
|
}
|
|
2996
2976
|
async broadcastBuddyReqs(arg) {
|
|
2997
|
-
|
|
2998
|
-
this.
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
return;
|
|
3005
|
-
}
|
|
3006
|
-
const fresh = filterBuddyReqs(reqs, this.baselineSec).filter((req) => this.dedup.claim(req));
|
|
3007
|
-
if (fresh.length < reqs.length) this.deps.logger?.debug({
|
|
3008
|
-
total: reqs.length,
|
|
3009
|
-
kept: fresh.length
|
|
3010
|
-
}, "milky: 好友申请过滤(历史积压 / 已读 / 已处理 / 重复)");
|
|
2977
|
+
const fresh = processInboundBuddyReqs(arg, {
|
|
2978
|
+
baselineSec: this.baselineSec,
|
|
2979
|
+
dedup: this.dedup,
|
|
2980
|
+
scope: "milky",
|
|
2981
|
+
formatRaw: sliceRaw,
|
|
2982
|
+
logger: this.deps.logger
|
|
2983
|
+
});
|
|
3011
2984
|
if (fresh.length === 0) return;
|
|
3012
2985
|
const ctx = await this.requestCtx(fresh.map((req) => req.friendUid));
|
|
3013
2986
|
for (const req of fresh) this.deps.broadcast(toFriendRequestEvent(req, ctx));
|
|
@@ -3167,8 +3140,6 @@ var MilkyInboundSysMsg = class {
|
|
|
3167
3140
|
const EVENT_PATH = "/event";
|
|
3168
3141
|
/** /api/ 前缀 + 动作名(小写字母开头,小写/数字/下划线)。 */
|
|
3169
3142
|
const API_PATH_RE = /^\/api\/([a-z][a-z0-9_]*)$/;
|
|
3170
|
-
/** Bearer 前缀。 */
|
|
3171
|
-
const BEARER_PREFIX = "Bearer ";
|
|
3172
3143
|
/**
|
|
3173
3144
|
* Milky 事件枢纽:SSE 客户端 + WS 客户端集合,send 即广播。
|
|
3174
3145
|
* 传输适配器面(open/close/send,EventBroadcaster 多态派发)——生命周期随
|
|
@@ -3196,7 +3167,7 @@ var MilkyEventHub = class {
|
|
|
3196
3167
|
reject(404, "event mode ws disabled");
|
|
3197
3168
|
return;
|
|
3198
3169
|
}
|
|
3199
|
-
if (config.token !== "" && !
|
|
3170
|
+
if (config.token !== "" && !matchTokenCredential(req, config.token, { allowQueryToken: true })) {
|
|
3200
3171
|
reject(401, "unauthorized");
|
|
3201
3172
|
return;
|
|
3202
3173
|
}
|
|
@@ -3230,7 +3201,15 @@ function assembleMilkyTransports(opts) {
|
|
|
3230
3201
|
const { config, broadcaster, registry, logger } = opts;
|
|
3231
3202
|
const hub = new MilkyEventHub();
|
|
3232
3203
|
const token = config.token;
|
|
3233
|
-
const authorize =
|
|
3204
|
+
const authorize = createTokenAuthorize(token, {
|
|
3205
|
+
allowQueryToken: true,
|
|
3206
|
+
onQueryParseError: (url, err) => {
|
|
3207
|
+
logger?.debug({
|
|
3208
|
+
url,
|
|
3209
|
+
error: errorMessage(err)
|
|
3210
|
+
}, "milky: 鉴权 URL 解析失败,按未授权拒绝");
|
|
3211
|
+
}
|
|
3212
|
+
});
|
|
3234
3213
|
const server = new HttpServer({
|
|
3235
3214
|
host: config.host,
|
|
3236
3215
|
port: config.port,
|
|
@@ -3311,24 +3290,6 @@ function handleMilkyHttpRequest(ctx, req, respond, registry, logger) {
|
|
|
3311
3290
|
});
|
|
3312
3291
|
});
|
|
3313
3292
|
}
|
|
3314
|
-
/** 鉴权钩子:Bearer 头或 access_token 查询参数(规范允许 SSE/WS 查询参数兜底)。 */
|
|
3315
|
-
function makeMilkyAuthorize(token, logger) {
|
|
3316
|
-
return (ctx) => tokenMatches(ctx, token, logger);
|
|
3317
|
-
}
|
|
3318
|
-
/** 请求凭据匹配(头优先,查询参数兜底;URL 解析失败 fail-closed 拒绝并 debug 留痕)。 */
|
|
3319
|
-
function tokenMatches(ctx, token, logger) {
|
|
3320
|
-
const auth = ctx.headers["authorization"] ?? ctx.headers["Authorization"];
|
|
3321
|
-
if (auth?.startsWith(BEARER_PREFIX)) return auth.slice(7) === token;
|
|
3322
|
-
try {
|
|
3323
|
-
return new URL(ctx.url, "http://localhost").searchParams.get("access_token") === token;
|
|
3324
|
-
} catch (err) {
|
|
3325
|
-
logger?.debug({
|
|
3326
|
-
url: ctx.url,
|
|
3327
|
-
error: errorMessage(err)
|
|
3328
|
-
}, "milky: 鉴权 URL 解析失败,按未授权拒绝");
|
|
3329
|
-
return false;
|
|
3330
|
-
}
|
|
3331
|
-
}
|
|
3332
3293
|
/** URL 路径部分(无 scheme 相对 url 容错)。 */
|
|
3333
3294
|
function pathnameOf(url) {
|
|
3334
3295
|
try {
|
|
@@ -3436,4 +3397,4 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
|
|
|
3436
3397
|
};
|
|
3437
3398
|
export { MilkyApi as a, createMilkyActionRegistry as i, assembleMilkyTransports as n, milkyErrorCodeMap as o, milkyConfigSchema as r, NapukettoMilkyAdapter as t };
|
|
3438
3399
|
|
|
3439
|
-
//# sourceMappingURL=milky-
|
|
3400
|
+
//# sourceMappingURL=milky-DvDcch01.mjs.map
|