@napuketto/adapter 0.19.0 → 0.20.0
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/{gray-tip-BL1rhwZK.mjs → gray-tip-BtiJls6z.mjs} +13 -25
- package/dist/{index-D93z0TYf.d.mts → index-CX7UKc6W.d.mts} +10 -1
- package/dist/{index-C-pAiIuG.d.mts → index-CufnIU9v.d.mts} +9 -1
- package/dist/{index-PWs-cVWe.d.mts → index-Dsfxdjz5.d.mts} +9 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +3 -3
- package/dist/milky/index.d.mts +1 -1
- package/dist/milky/index.mjs +1 -1
- package/dist/{milky-DTlPFEhN.mjs → milky-79AYb8fV.mjs} +18 -15
- package/dist/onebot11/index.d.mts +1 -1
- package/dist/onebot11/index.mjs +1 -1
- package/dist/{onebot11-Bq0f2Tky.mjs → onebot11-BW56Dqc6.mjs} +22 -18
- package/dist/satori/index.d.mts +1 -1
- package/dist/satori/index.mjs +1 -1
- package/dist/{satori-VkOP24Vc.mjs → satori-Cetkw86t.mjs} +17 -15
- package/package.json +2 -2
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { errorMessage, kernelError } from "@napuketto/kernel";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
5
|
import { copyFile, lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, rmdir, stat, unlink, writeFile } from "node:fs/promises";
|
|
5
6
|
import { tmpdir } from "node:os";
|
|
6
7
|
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
7
|
-
import { downloadUrl, encodePcmToSilk, extractVideoFrame, getVideoInfo } from "@napuketto/media";
|
|
8
|
+
import { downloadPublicUrl, downloadUrl, encodePcmToSilk, extractVideoFrame, getVideoInfo } from "@napuketto/media";
|
|
8
9
|
import { fileURLToPath } from "node:url";
|
|
9
10
|
// src/internal/infra/media-cache.ts
|
|
10
11
|
const CACHE_DIR = ".napuketto-media-v1";
|
|
@@ -415,32 +416,17 @@ function fileUriToPath(uri) {
|
|
|
415
416
|
return FILE_URI_PREFIX_RE.test(uri) ? uri.replace(FILE_URI_PREFIX_RE, "") : uri;
|
|
416
417
|
}
|
|
417
418
|
}
|
|
418
|
-
/**
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
* - 父目录不存在时自动创建;
|
|
425
|
-
* - 失败统一包成 KernelError SEND_FAILED(`label` 供调用方定制前缀,如「头像下载失败」);
|
|
426
|
-
* - 返回落盘路径(便于调用方直接回传)。
|
|
427
|
-
*/
|
|
428
|
-
async function downloadBufferToFile(url, filePath, init, label = "下载失败") {
|
|
419
|
+
/** 协议动作默认走公网下载,兼容模式由受信任的装配方显式启用。 */
|
|
420
|
+
function mediaDownloader(policy) {
|
|
421
|
+
return policy === "compat" ? downloadUrl : downloadPublicUrl;
|
|
422
|
+
}
|
|
423
|
+
/** 转换有上传语义的下载失败,保留既有 SEND_FAILED 信封。 */
|
|
424
|
+
async function downloadProtocolMedia(url, filePath, options = {}) {
|
|
429
425
|
try {
|
|
430
|
-
|
|
431
|
-
await downloadUrl(url, filePath, headers === void 0 ? {} : { headers });
|
|
426
|
+
await mediaDownloader(options.outboundPolicy)(url, filePath, { headers: options.headers });
|
|
432
427
|
} catch (err) {
|
|
433
|
-
throw kernelError(`${
|
|
428
|
+
throw kernelError(`${options.errorLabel ?? "下载失败"}: ${errorMessage(err)}`, "SEND_FAILED", { cause: err });
|
|
434
429
|
}
|
|
435
|
-
return filePath;
|
|
436
|
-
}
|
|
437
|
-
/** RequestInit.headers(Headers / 元组数组 / 普通对象)→ 普通字符串对象。 */
|
|
438
|
-
function normalizeHeaders(headers) {
|
|
439
|
-
const out = {};
|
|
440
|
-
new Headers(headers).forEach((value, key) => {
|
|
441
|
-
out[key] = value;
|
|
442
|
-
});
|
|
443
|
-
return out;
|
|
444
430
|
}
|
|
445
431
|
/** 读文件头 8 字节(判断 silk 魔数)。 */
|
|
446
432
|
async function readFileHead(path) {
|
|
@@ -537,6 +523,8 @@ async function prepareVideoElements(elements) {
|
|
|
537
523
|
throw err;
|
|
538
524
|
}
|
|
539
525
|
}
|
|
526
|
+
// src/internal/infra/media-config.ts
|
|
527
|
+
const protocolMediaSchema = z.object({ outboundPolicy: z.enum(["public-only", "compat"]).optional() });
|
|
540
528
|
// src/internal/infra/log.ts
|
|
541
529
|
/**
|
|
542
530
|
* raw 日志截断与最小 logger 面(协议 adapter 校准日志共用,自
|
|
@@ -614,4 +602,4 @@ function firstUntranslatedGrayTip(msg) {
|
|
|
614
602
|
function findRevokeElement(msg) {
|
|
615
603
|
return msg.elements.find((el) => el.grayTipElement?.revokeElement != null)?.grayTipElement?.revokeElement ?? void 0;
|
|
616
604
|
}
|
|
617
|
-
export { logEventFailure as a,
|
|
605
|
+
export { withMediaScope as _, logEventFailure as a, protocolMediaSchema as c, fileUriToPath as d, mediaDownloader as f, protectMediaPath as g, cacheMediaFile as h, hasGrayTip as i, downloadProtocolMedia as l, MediaCache as m, findRevokeElement as n, sliceRaw as o, prepareVideoElements as p, firstUntranslatedGrayTip as r, truncRaw as s, collectGrayTipUids as t, ensureSilk as u };
|
|
@@ -4,6 +4,7 @@ import "./gray-tip-CcpfI1Og.mjs";
|
|
|
4
4
|
import { CanonicalElement, FriendApi, GroupApi, GroupCache, GroupNotifyApi, KernelErrorCode, MsgApi, MsgEventChannel, Peer, ProfileApi } from "@napuketto/kernel";
|
|
5
5
|
import { EventBroadcaster, TransportAdapter } from "@napuketto/network";
|
|
6
6
|
import { ZodType, z } from "zod";
|
|
7
|
+
import { MediaOutboundPolicy } from "@napuketto/media";
|
|
7
8
|
/** Satori 消息元素(与规范 satori-parse 形状一致;type="text" 为文本节点)。 */
|
|
8
9
|
interface SatoriElement {
|
|
9
10
|
type: string;
|
|
@@ -24,6 +25,7 @@ interface SatoriToCanonicalDeps {
|
|
|
24
25
|
uinToUid: (uins: string[]) => Promise<Map<string, string>>;
|
|
25
26
|
/** 资源(img/audio/video/file)下载缓存目录。 */
|
|
26
27
|
cacheDir: string;
|
|
28
|
+
outboundPolicy?: MediaOutboundPolicy | undefined;
|
|
27
29
|
/** 转码成功即转移输出文件及其父临时目录的所有权;发送消费结束后清理。 */
|
|
28
30
|
onVideoTranscoded?: (path: string) => void;
|
|
29
31
|
}
|
|
@@ -66,7 +68,8 @@ declare class SatoriApi {
|
|
|
66
68
|
* 规则区分,需从事件/查询回填——QQ 平台群号与用户 uin 同为数字)。
|
|
67
69
|
*/
|
|
68
70
|
private readonly channelTypeCache;
|
|
69
|
-
|
|
71
|
+
private readonly getMediaOutboundPolicy;
|
|
72
|
+
constructor(opts: SatoriApiOptions, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined);
|
|
70
73
|
/** 记录频道类型(消息事件翻译时回填:chatType GROUP → true)。 */
|
|
71
74
|
setChannelType(channelId: string, isGroup: boolean): void;
|
|
72
75
|
/**
|
|
@@ -106,6 +109,12 @@ type SatoriActionRegistry = ActionRegistry<SatoriActionHandler<unknown, unknown>
|
|
|
106
109
|
/** 创建 Satori 动作注册表。 */
|
|
107
110
|
declare function createSatoriActionRegistry(deps: SatoriActionDeps): SatoriActionRegistry;
|
|
108
111
|
declare const satoriConfigSchema: z.ZodObject<{
|
|
112
|
+
media: z.ZodOptional<z.ZodObject<{
|
|
113
|
+
outboundPolicy: z.ZodOptional<z.ZodEnum<{
|
|
114
|
+
compat: "compat";
|
|
115
|
+
"public-only": "public-only";
|
|
116
|
+
}>>;
|
|
117
|
+
}, z.core.$strip>>;
|
|
109
118
|
token: z.ZodOptional<z.ZodString>;
|
|
110
119
|
cacheDir: z.ZodOptional<z.ZodString>;
|
|
111
120
|
httpServers: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
@@ -4,6 +4,7 @@ import "./gray-tip-CcpfI1Og.mjs";
|
|
|
4
4
|
import { BuddyCacheEventChannel, BuddyEventChannel, CanonicalElement, FlashTransferApi, FriendApi, GroupApi, GroupCache, GroupEventChannel, GroupNotifyApi, MsgApi, MsgEventChannel, Peer, ProfileApi, ProfileLikeApi, RichMediaApi, TicketApi, WebApi } from "@napuketto/kernel";
|
|
5
5
|
import { EventBroadcaster, TransportAdapter } from "@napuketto/network";
|
|
6
6
|
import { ZodType, z } from "zod";
|
|
7
|
+
import { MediaOutboundPolicy } from "@napuketto/media";
|
|
7
8
|
/**
|
|
8
9
|
* OneBot 11 类型定义(自研描述,参考公开协议规范)
|
|
9
10
|
* 对应:接口签名是外部协议事实,可自研描述,不复制实现。
|
|
@@ -293,6 +294,7 @@ interface OneBotApiOptions {
|
|
|
293
294
|
*/
|
|
294
295
|
declare class OneBotApi {
|
|
295
296
|
readonly mediaCache: MediaCache;
|
|
297
|
+
readonly getMediaOutboundPolicy?: (() => MediaOutboundPolicy | undefined) | undefined;
|
|
296
298
|
/** kernel 消息 API(send_msg 等消息类动作用)。 */
|
|
297
299
|
readonly msgApi: MsgApi;
|
|
298
300
|
/** kernel 群 API。 */
|
|
@@ -338,7 +340,7 @@ declare class OneBotApi {
|
|
|
338
340
|
readonly restart: (() => Promise<void>) | undefined;
|
|
339
341
|
/** 降级分支可观测出口(缺省静默)。 */
|
|
340
342
|
readonly logger?: AdapterLoggerLike | undefined;
|
|
341
|
-
constructor(opts: OneBotApiOptions);
|
|
343
|
+
constructor(opts: OneBotApiOptions, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined);
|
|
342
344
|
/**
|
|
343
345
|
* uin→uid 转换(委托 groupApi;私聊目标/成员 user_id 用)。
|
|
344
346
|
* 类字段箭头函数:动作会把本方法作为回调裸传(resolveUid 等),必须绑定实例,
|
|
@@ -439,6 +441,12 @@ declare function serializeCqParts(parts: Array<string | CqCode>): string;
|
|
|
439
441
|
/** OB11 segment 数组 → CQ 码字符串(text 段转义拼接,特殊段编码)。 */
|
|
440
442
|
declare function segmentsToCqMessage(segments: OB11MessageSegment[]): string;
|
|
441
443
|
declare const ob11ConfigSchema: z.ZodObject<{
|
|
444
|
+
media: z.ZodOptional<z.ZodObject<{
|
|
445
|
+
outboundPolicy: z.ZodOptional<z.ZodEnum<{
|
|
446
|
+
compat: "compat";
|
|
447
|
+
"public-only": "public-only";
|
|
448
|
+
}>>;
|
|
449
|
+
}, z.core.$strip>>;
|
|
442
450
|
token: z.ZodOptional<z.ZodString>;
|
|
443
451
|
heartbeatInterval: z.ZodDefault<z.ZodNumber>;
|
|
444
452
|
reportSelfMessage: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -3,6 +3,7 @@ import { t as MediaCache } from "./media-cache-C_0C9eCV.mjs";
|
|
|
3
3
|
import { BuddyEventChannel, ChatType, FlashTransferApi, FriendApi, GroupApi, GroupCache, GroupEventChannel, GroupNotifyApi, KernelErrorCode, LoginEventChannel, MsgApi, MsgEventChannel, Peer, ProfileApi, ProfileLikeApi, RawMessage, RecentContactApi, RecentContactEventChannel, RichMediaApi, TicketApi, WebApi } from "@napuketto/kernel";
|
|
4
4
|
import { EventBroadcaster, TransportAdapter } from "@napuketto/network";
|
|
5
5
|
import { ZodType, z } from "zod";
|
|
6
|
+
import { MediaOutboundPolicy } from "@napuketto/media";
|
|
6
7
|
/**
|
|
7
8
|
* Milky 动作结果(retcode 为规范负数族;transport 原样组装信封)。
|
|
8
9
|
*
|
|
@@ -69,6 +70,12 @@ declare class MessageSeqIndex {
|
|
|
69
70
|
private evict;
|
|
70
71
|
}
|
|
71
72
|
declare const milkyConfigSchema: z.ZodObject<{
|
|
73
|
+
media: z.ZodOptional<z.ZodObject<{
|
|
74
|
+
outboundPolicy: z.ZodOptional<z.ZodEnum<{
|
|
75
|
+
compat: "compat";
|
|
76
|
+
"public-only": "public-only";
|
|
77
|
+
}>>;
|
|
78
|
+
}, z.core.$strip>>;
|
|
72
79
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
73
80
|
host: z.ZodDefault<z.ZodString>;
|
|
74
81
|
port: z.ZodDefault<z.ZodNumber>;
|
|
@@ -158,11 +165,12 @@ declare class MilkyApi {
|
|
|
158
165
|
readonly qqVersion: string;
|
|
159
166
|
readonly implVersion: string;
|
|
160
167
|
readonly mediaDir: string | undefined;
|
|
168
|
+
readonly getMediaOutboundPolicy?: (() => MediaOutboundPolicy | undefined) | undefined;
|
|
161
169
|
/** 动作层可观测出口(缺省静默)。 */
|
|
162
170
|
readonly logger: MilkyLoggerLike | undefined;
|
|
163
171
|
/** message_seq ↔ msgId 双向映射(接收链路 record,动作侧反查)。 */
|
|
164
172
|
readonly seqIndex: MessageSeqIndex;
|
|
165
|
-
constructor(opts: MilkyApiOptions, seqIndex: MessageSeqIndex);
|
|
173
|
+
constructor(opts: MilkyApiOptions, seqIndex: MessageSeqIndex, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined);
|
|
166
174
|
/** uin → uid(私聊目标 / at 段发送转换 / 群管动作的 uid 入参)。 */
|
|
167
175
|
uinToUid(uins: string[]): Promise<Map<string, string>>;
|
|
168
176
|
/** uid → uin(事件路径 mention 转换)。 */
|
package/dist/index.d.mts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { _ as ErrorCodeMap, a as ProtocolConfig, c as ProtocolHooks, g as ActionOutcome, h as ActionKernelSpec, i as ConfigSchema, m as ActionRegistry, n as ConfigFormat, o as createServerSchema, r as ConfigOptions, s as BaseProtocolAdapter, t as ConfigBase, v as runAction } from "./index-BO1TgLTT.mjs";
|
|
19
19
|
import { et as KurobotConfig, l as KurobotAdapterOptions, nt as kurobotConfigSchema, u as NapukettoKurobotAdapter } from "./index-tW3a05Du.mjs";
|
|
20
|
-
import { G as MilkyConfig, K as milkyConfigSchema, L as MilkyAdapterOptions, R as NapukettoMilkyAdapter } from "./index-
|
|
21
|
-
import { C as ob11ConfigSchema, S as OB11Config, o as NapukettoOneBot11Adapter, s as OneBot11AdapterOptions } from "./index-
|
|
22
|
-
import { R as SatoriConfig, d as NapukettoSatoriAdapter, f as SatoriAdapterOptions, z as satoriConfigSchema } from "./index-
|
|
20
|
+
import { G as MilkyConfig, K as milkyConfigSchema, L as MilkyAdapterOptions, R as NapukettoMilkyAdapter } from "./index-Dsfxdjz5.mjs";
|
|
21
|
+
import { C as ob11ConfigSchema, S as OB11Config, o as NapukettoOneBot11Adapter, s as OneBot11AdapterOptions } from "./index-CufnIU9v.mjs";
|
|
22
|
+
import { R as SatoriConfig, d as NapukettoSatoriAdapter, f as SatoriAdapterOptions, z as satoriConfigSchema } from "./index-CX7UKc6W.mjs";
|
|
23
23
|
export { type ActionKernelSpec, type ActionOutcome, ActionRegistry, BaseProtocolAdapter, ConfigBase, type ConfigFormat, type ConfigOptions, type ConfigSchema, type ErrorCodeMap, type KurobotAdapterOptions, type KurobotConfig, type MilkyAdapterOptions, type MilkyConfig, NapukettoKurobotAdapter, NapukettoMilkyAdapter, NapukettoOneBot11Adapter, NapukettoSatoriAdapter, type OB11Config, type OneBot11AdapterOptions, ProtocolConfig, type ProtocolHooks, type SatoriAdapterOptions, type SatoriConfig, createServerSchema, kurobotConfigSchema, milkyConfigSchema, ob11ConfigSchema, runAction, satoriConfigSchema };
|
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-8YrYipGI.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-79AYb8fV.mjs";
|
|
4
|
+
import { t as NapukettoOneBot11Adapter, u as ob11ConfigSchema } from "./onebot11-BW56Dqc6.mjs";
|
|
5
|
+
import { m as satoriConfigSchema, t as NapukettoSatoriAdapter } from "./satori-Cetkw86t.mjs";
|
|
6
6
|
export { ActionRegistry, BaseProtocolAdapter, ConfigBase, NapukettoKurobotAdapter, NapukettoMilkyAdapter, NapukettoOneBot11Adapter, NapukettoSatoriAdapter, ProtocolConfig, createServerSchema, kurobotConfigSchema, milkyConfigSchema, ob11ConfigSchema, runAction, satoriConfigSchema };
|
package/dist/milky/index.d.mts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* 对齐 ./onebot11 与 ./satori 的导出口径。装配方(loader assemble-protocols)
|
|
6
6
|
* 动态 import 本入口。
|
|
7
7
|
*/
|
|
8
|
-
import { A as MessageRecallData, B as MilkyApi, C as GroupMuteData, D as IncomingForwardedMessage, E as GroupWholeMuteData, F as PeerPinChangeData, G as MilkyConfig, H as MilkyLoggerLike, I as SendMessageOutput, J as milkyErrorCodeMap, K as milkyConfigSchema, L as MilkyAdapterOptions, M as MilkyEvent, N as OutgoingForwardedMessage, O as IncomingMessage, P as OutgoingSegment, R as NapukettoMilkyAdapter, S as GroupMessageReactionData, T as GroupNotificationEntity, U as MilkyTransportSet, V as MilkyApiOptions, W as assembleMilkyTransports, _ as GroupInvitedJoinRequestData, a as FriendRequestEntity, b as GroupMemberEntity, c as GetLoginInfoOutput, d as GroupEntity, f as GroupEssenceMessage, g as GroupInvitationData, h as GroupFolderEntity, i as FriendRequestData, j as MessageScene, k as IncomingSegment, l as GroupAnnouncementEntity, m as GroupFileUploadData, n as FriendCategoryEntity, o as GetCookiesOutput, p as GroupFileEntity, q as MilkyAction, r as FriendEntity, s as GetImplInfoOutput, t as BotOfflineData, u as GroupDisbandData, v as GroupJoinRequestData, w as GroupNameChangeData, x as GroupMemberIncreaseData, y as GroupMemberDecreaseData, z as createMilkyActionRegistry } from "../index-
|
|
8
|
+
import { A as MessageRecallData, B as MilkyApi, C as GroupMuteData, D as IncomingForwardedMessage, E as GroupWholeMuteData, F as PeerPinChangeData, G as MilkyConfig, H as MilkyLoggerLike, I as SendMessageOutput, J as milkyErrorCodeMap, K as milkyConfigSchema, L as MilkyAdapterOptions, M as MilkyEvent, N as OutgoingForwardedMessage, O as IncomingMessage, P as OutgoingSegment, R as NapukettoMilkyAdapter, S as GroupMessageReactionData, T as GroupNotificationEntity, U as MilkyTransportSet, V as MilkyApiOptions, W as assembleMilkyTransports, _ as GroupInvitedJoinRequestData, a as FriendRequestEntity, b as GroupMemberEntity, c as GetLoginInfoOutput, d as GroupEntity, f as GroupEssenceMessage, g as GroupInvitationData, h as GroupFolderEntity, i as FriendRequestData, j as MessageScene, k as IncomingSegment, l as GroupAnnouncementEntity, m as GroupFileUploadData, n as FriendCategoryEntity, o as GetCookiesOutput, p as GroupFileEntity, q as MilkyAction, r as FriendEntity, s as GetImplInfoOutput, t as BotOfflineData, u as GroupDisbandData, v as GroupJoinRequestData, w as GroupNameChangeData, x as GroupMemberIncreaseData, y as GroupMemberDecreaseData, z as createMilkyActionRegistry } from "../index-Dsfxdjz5.mjs";
|
|
9
9
|
export { type BotOfflineData, type FriendCategoryEntity, type FriendEntity, type FriendRequestData, type FriendRequestEntity, type GetCookiesOutput, type GetImplInfoOutput, type GetLoginInfoOutput, type GroupAnnouncementEntity, type GroupDisbandData, type GroupEntity, type GroupEssenceMessage, type GroupFileEntity, type GroupFileUploadData, type GroupFolderEntity, type GroupInvitationData, type GroupInvitedJoinRequestData, type GroupJoinRequestData, type GroupMemberDecreaseData, type GroupMemberEntity, type GroupMemberIncreaseData, type GroupMessageReactionData, type GroupMuteData, type GroupNameChangeData, type GroupNotificationEntity, type GroupWholeMuteData, type IncomingForwardedMessage, type MessageRecallData, type MessageScene, type MilkyAction, type MilkyAdapterOptions, MilkyApi, type MilkyApiOptions, type MilkyConfig, type MilkyEvent, type IncomingMessage as MilkyIncomingMessage, type IncomingSegment as MilkyIncomingSegment, type MilkyLoggerLike, type OutgoingSegment as MilkyOutgoingSegment, type MilkyTransportSet, NapukettoMilkyAdapter, type OutgoingForwardedMessage, type PeerPinChangeData, type SendMessageOutput, assembleMilkyTransports, createMilkyActionRegistry, milkyConfigSchema, milkyErrorCodeMap };
|
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-79AYb8fV.mjs";
|
|
@@ -1,12 +1,12 @@
|
|
|
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 { a as logEventFailure, f as
|
|
2
|
+
import { _ as withMediaScope, a as logEventFailure, c as protocolMediaSchema, d as fileUriToPath, f as mediaDownloader, g as protectMediaPath, h as cacheMediaFile, i as hasGrayTip, m as MediaCache, n as findRevokeElement, o as sliceRaw, r as firstUntranslatedGrayTip, t as collectGrayTipUids } from "./gray-tip-BtiJls6z.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-DU8YOhLV.mjs";
|
|
4
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-Cn1oRaLw.mjs";
|
|
5
5
|
import { ChatType, EssenceListSync, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, errorMessage, 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";
|
|
8
8
|
import { rename, writeFile } from "node:fs/promises";
|
|
9
|
-
import { detectFileType,
|
|
9
|
+
import { detectFileType, inferExtension } from "@napuketto/media";
|
|
10
10
|
// src/milky/action/base-action.ts
|
|
11
11
|
/** KernelErrorCode → Milky retcode 映射表(-400/-403 规范语义,其余取常见 HTTP 语义近似负数)。 */
|
|
12
12
|
const milkyErrorCodeMap = {
|
|
@@ -323,16 +323,16 @@ function essenceToEntity(item, groupId) {
|
|
|
323
323
|
* 规范支持 file:// / http(s):// / base64:// 三种(image/record/video 共用):
|
|
324
324
|
* - file:// → 平台路径(segments.ts 的同步面已处理)
|
|
325
325
|
* - base64:// → 解码落盘 cacheDir/milky/,file-type 探测扩展名后改名
|
|
326
|
-
* - http(s):// →
|
|
326
|
+
* - http(s):// → 按媒体出站策略下载落盘 cacheDir/milky/
|
|
327
327
|
* 未配置 mediaDir 时远程 URI 报错(不发静默空消息)。
|
|
328
328
|
*/
|
|
329
329
|
const DETECTED_EXTENSION_RE = /^[a-zA-Z0-9]+$/;
|
|
330
330
|
/** 解析远程媒体 URI 为本地绝对路径(base64:// / http(s)://;file:// 走同步面)。 */
|
|
331
|
-
async function resolveMediaUri(uri, mediaDir) {
|
|
331
|
+
async function resolveMediaUri(uri, mediaDir, outboundPolicy) {
|
|
332
332
|
if (mediaDir === void 0 || mediaDir === "") throw kernelError("远程媒体发送需要配置 [accounts.milky] cacheDir(下载缓存目录)", "INVALID_PARAM");
|
|
333
333
|
if (uri.startsWith("base64://")) return await writeBase64(uri.slice(9), mediaDir);
|
|
334
334
|
return await cacheMediaFile(mediaDir, inferExtension(null, uri), async (dest) => {
|
|
335
|
-
await
|
|
335
|
+
await mediaDownloader(outboundPolicy)(uri, dest);
|
|
336
336
|
});
|
|
337
337
|
}
|
|
338
338
|
/**
|
|
@@ -340,9 +340,9 @@ async function resolveMediaUri(uri, mediaDir) {
|
|
|
340
340
|
* 失败裸剥离兜底,与 segments.ts 同步面同规则);http(s):// / base64:// 复用
|
|
341
341
|
* resolveMediaUri 落盘;裸路径(go-cqhttp 惯例)原样。
|
|
342
342
|
*/
|
|
343
|
-
async function resolveUriToPath(uri, mediaDir) {
|
|
343
|
+
async function resolveUriToPath(uri, mediaDir, outboundPolicy) {
|
|
344
344
|
if (uri.startsWith("file://")) return await protectMediaPath(fileUriToPath(uri));
|
|
345
|
-
if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("base64://")) return await resolveMediaUri(uri, mediaDir);
|
|
345
|
+
if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("base64://")) return await resolveMediaUri(uri, mediaDir, outboundPolicy);
|
|
346
346
|
return await protectMediaPath(uri);
|
|
347
347
|
}
|
|
348
348
|
/** base64 载荷 → 落盘(先写 .bin,探测到扩展名再改名)。 */
|
|
@@ -471,7 +471,7 @@ function createGroupFileActions(api) {
|
|
|
471
471
|
file_name: z.string().min(1)
|
|
472
472
|
}),
|
|
473
473
|
handle: async (payload) => {
|
|
474
|
-
const path = await resolveUriToPath(payload.file_uri, api.mediaDir);
|
|
474
|
+
const path = await resolveUriToPath(payload.file_uri, api.mediaDir, api.getMediaOutboundPolicy?.());
|
|
475
475
|
const peer = {
|
|
476
476
|
chatType: ChatType.GROUP,
|
|
477
477
|
peerUid: String(payload.group_id)
|
|
@@ -555,11 +555,13 @@ var MilkyApi = class {
|
|
|
555
555
|
qqVersion;
|
|
556
556
|
implVersion;
|
|
557
557
|
mediaDir;
|
|
558
|
+
getMediaOutboundPolicy;
|
|
558
559
|
/** 动作层可观测出口(缺省静默)。 */
|
|
559
560
|
logger;
|
|
560
561
|
/** message_seq ↔ msgId 双向映射(接收链路 record,动作侧反查)。 */
|
|
561
562
|
seqIndex;
|
|
562
|
-
constructor(opts, seqIndex) {
|
|
563
|
+
constructor(opts, seqIndex, getMediaOutboundPolicy) {
|
|
564
|
+
this.getMediaOutboundPolicy = getMediaOutboundPolicy;
|
|
563
565
|
this.mediaCache = new MediaCache({
|
|
564
566
|
root: opts.mediaDir,
|
|
565
567
|
logger: opts.logger
|
|
@@ -806,7 +808,7 @@ function createGroupManageActions(api) {
|
|
|
806
808
|
image_uri: z.string().min(1)
|
|
807
809
|
}),
|
|
808
810
|
handle: async (payload) => {
|
|
809
|
-
const imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir);
|
|
811
|
+
const imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir, api.getMediaOutboundPolicy?.());
|
|
810
812
|
await api.groupApi.setGroupAvatar(String(payload.group_id), imagePath);
|
|
811
813
|
return {};
|
|
812
814
|
}
|
|
@@ -834,7 +836,7 @@ function createGroupManageActions(api) {
|
|
|
834
836
|
handle: async (payload) => {
|
|
835
837
|
const groupCode = String(payload.group_id);
|
|
836
838
|
let imagePath;
|
|
837
|
-
if (payload.image_uri !== void 0 && payload.image_uri !== null && payload.image_uri !== "") imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir);
|
|
839
|
+
if (payload.image_uri !== void 0 && payload.image_uri !== null && payload.image_uri !== "") imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir, api.getMediaOutboundPolicy?.());
|
|
838
840
|
await api.groupApi.publishGroupAnnouncement(groupCode, payload.content, imagePath);
|
|
839
841
|
return {};
|
|
840
842
|
}
|
|
@@ -1770,7 +1772,7 @@ function createMessageOpsActions(api) {
|
|
|
1770
1772
|
file_name: z.string().min(1)
|
|
1771
1773
|
}),
|
|
1772
1774
|
handle: async (payload) => {
|
|
1773
|
-
const path = await resolveUriToPath(payload.file_uri, api.mediaDir);
|
|
1775
|
+
const path = await resolveUriToPath(payload.file_uri, api.mediaDir, api.getMediaOutboundPolicy?.());
|
|
1774
1776
|
const peer = await api.resolvePeer("friend", payload.user_id);
|
|
1775
1777
|
return { file_id: (await api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
|
|
1776
1778
|
}
|
|
@@ -1917,7 +1919,7 @@ async function resolveElement(el, uinToUid, api) {
|
|
|
1917
1919
|
};
|
|
1918
1920
|
if ((el.type === "image" || el.type === "voice" || el.type === "video") && isRemoteMediaUri(el)) return {
|
|
1919
1921
|
...el,
|
|
1920
|
-
path: await resolveMediaUri(el.path, api.mediaDir)
|
|
1922
|
+
path: await resolveMediaUri(el.path, api.mediaDir, api.getMediaOutboundPolicy?.())
|
|
1921
1923
|
};
|
|
1922
1924
|
if ("path" in el) await protectMediaPath(el.path);
|
|
1923
1925
|
return el;
|
|
@@ -1976,7 +1978,7 @@ function createProfileActions(api) {
|
|
|
1976
1978
|
name: "set_avatar",
|
|
1977
1979
|
schema: z.object({ uri: z.string().min(1) }),
|
|
1978
1980
|
handle: async (payload) => {
|
|
1979
|
-
const path = await resolveMediaUri(payload.uri, api.mediaDir);
|
|
1981
|
+
const path = await resolveMediaUri(payload.uri, api.mediaDir, api.getMediaOutboundPolicy?.());
|
|
1980
1982
|
await api.profileApi.setHeader(path);
|
|
1981
1983
|
return {};
|
|
1982
1984
|
}
|
|
@@ -2242,6 +2244,7 @@ function createMilkyActionRegistry(opts) {
|
|
|
2242
2244
|
return registry;
|
|
2243
2245
|
}
|
|
2244
2246
|
const milkyConfigSchema = z.object({
|
|
2247
|
+
media: protocolMediaSchema.optional(),
|
|
2245
2248
|
/** 启用开关(缺省 false:账号段存在但 enabled 未开 = 装配为空转)。 */
|
|
2246
2249
|
enabled: z.boolean().default(false),
|
|
2247
2250
|
/** HTTP 监听地址。 */
|
|
@@ -3315,7 +3318,7 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
|
|
|
3315
3318
|
hooks
|
|
3316
3319
|
});
|
|
3317
3320
|
this.calibLogger = opts.logger;
|
|
3318
|
-
this.api = new MilkyApi(opts, this.seqIndex);
|
|
3321
|
+
this.api = new MilkyApi(opts, this.seqIndex, () => config.get?.()?.media?.outboundPolicy);
|
|
3319
3322
|
const base = {
|
|
3320
3323
|
api: this.api,
|
|
3321
3324
|
seqIndex: this.seqIndex,
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* OneBot 11 协议适配器(当前主战场)
|
|
3
3
|
* 公共面:类型 + 动作注册表 + 配置 schema + 翻译层(adapter.ts 于 打通 kernel 事件后接入)。
|
|
4
4
|
*/
|
|
5
|
-
import { $ as OB11MessageInfo, A as serializeCqParts, B as canonicalToCqMessage, C as ob11ConfigSchema, D as escapeCqParam, E as encodeCqCode, F as ob11ErrorCodeMap, G as CurrentTalkative, H as cqMessageToCanonical, I as OneBotApi, J as GroupInfo, K as FriendInfo, L as OneBotApiOptions, M as Ob11ActionDeps, N as createOb11ActionRegistry, O as escapeCqText, P as AtAllRemainInfo, Q as OB11Message, R as OneBotSystemOptions, S as OB11Config, T as CqCode, U as cqMessageToSegments, V as canonicalToSegments, W as segmentsToCanonical, X as HonorMember, Y as GroupMemberInfo, Z as LoginInfo, _ as OB11GroupMessageEvent, a as assembleOb11Transports, at as VersionInfo, b as OB11BaseEvent, c as OB11Event, d as OB11RequestEvent, et as OB11MessageSegment, f as OB11NoticeEvent, g as OB11Status, h as OB11MetaEvent, i as Ob11TransportSet, it as StrangerInfo, j as unescapeCqText, k as parseCqMessage, l as OB11FriendRequestEvent, m as OB11LifecycleMetaEvent, n as Ob11OutboundTransport, nt as Sender, o as NapukettoOneBot11Adapter, p as OB11HeartbeatMetaEvent, q as GroupHonorInfo, r as Ob11OutboundWsReconnect, rt as Sex, s as OneBot11AdapterOptions, t as AssembleOb11TransportsOptions, tt as OB11Return, u as OB11GroupRequestEvent, v as OB11MessageEvent, w as segmentsToCqMessage, x as OB11PostType, y as OB11PrivateMessageEvent, z as MessageUnique } from "../index-
|
|
5
|
+
import { $ as OB11MessageInfo, A as serializeCqParts, B as canonicalToCqMessage, C as ob11ConfigSchema, D as escapeCqParam, E as encodeCqCode, F as ob11ErrorCodeMap, G as CurrentTalkative, H as cqMessageToCanonical, I as OneBotApi, J as GroupInfo, K as FriendInfo, L as OneBotApiOptions, M as Ob11ActionDeps, N as createOb11ActionRegistry, O as escapeCqText, P as AtAllRemainInfo, Q as OB11Message, R as OneBotSystemOptions, S as OB11Config, T as CqCode, U as cqMessageToSegments, V as canonicalToSegments, W as segmentsToCanonical, X as HonorMember, Y as GroupMemberInfo, Z as LoginInfo, _ as OB11GroupMessageEvent, a as assembleOb11Transports, at as VersionInfo, b as OB11BaseEvent, c as OB11Event, d as OB11RequestEvent, et as OB11MessageSegment, f as OB11NoticeEvent, g as OB11Status, h as OB11MetaEvent, i as Ob11TransportSet, it as StrangerInfo, j as unescapeCqText, k as parseCqMessage, l as OB11FriendRequestEvent, m as OB11LifecycleMetaEvent, n as Ob11OutboundTransport, nt as Sender, o as NapukettoOneBot11Adapter, p as OB11HeartbeatMetaEvent, q as GroupHonorInfo, r as Ob11OutboundWsReconnect, rt as Sex, s as OneBot11AdapterOptions, t as AssembleOb11TransportsOptions, tt as OB11Return, u as OB11GroupRequestEvent, v as OB11MessageEvent, w as segmentsToCqMessage, x as OB11PostType, y as OB11PrivateMessageEvent, z as MessageUnique } from "../index-CufnIU9v.mjs";
|
|
6
6
|
export { type AssembleOb11TransportsOptions, type AtAllRemainInfo, type CqCode, type CurrentTalkative, type FriendInfo, type GroupHonorInfo, type GroupInfo, type GroupMemberInfo, type HonorMember, type LoginInfo, MessageUnique, NapukettoOneBot11Adapter, type OB11BaseEvent, type OB11Config, type OB11Event, type OB11FriendRequestEvent, type OB11GroupMessageEvent, type OB11GroupRequestEvent, type OB11HeartbeatMetaEvent, type OB11LifecycleMetaEvent, type OB11Message, type OB11MessageEvent, type OB11MessageInfo, type OB11MessageSegment, type OB11MetaEvent, type OB11NoticeEvent, type OB11PostType, type OB11PrivateMessageEvent, type OB11RequestEvent, type OB11Return, type OB11Status, type Ob11ActionDeps, type Ob11OutboundTransport, type Ob11OutboundWsReconnect, type Ob11TransportSet, type OneBot11AdapterOptions, OneBotApi, type OneBotApiOptions, type OneBotSystemOptions, type Sender, type Sex, type StrangerInfo, type VersionInfo, assembleOb11Transports, canonicalToCqMessage, canonicalToSegments, cqMessageToCanonical, cqMessageToSegments, createOb11ActionRegistry, encodeCqCode, escapeCqParam, escapeCqText, ob11ConfigSchema, ob11ErrorCodeMap, parseCqMessage, segmentsToCanonical, segmentsToCqMessage, serializeCqParts, unescapeCqText };
|
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-BW56Dqc6.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
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 { a as logEventFailure, c as
|
|
2
|
+
import { _ as withMediaScope, a as logEventFailure, c as protocolMediaSchema, d as fileUriToPath, f as mediaDownloader, g as protectMediaPath, h as cacheMediaFile, i as hasGrayTip, l as downloadProtocolMedia, m as MediaCache, o as sliceRaw, p as prepareVideoElements, r as firstUntranslatedGrayTip, s as truncRaw, t as collectGrayTipUids, u as ensureSilk } from "./gray-tip-BtiJls6z.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, r as subscribeRawMessages, s as startupBaselineSec, u as collectGroupNotifyUids } from "./raw-message-DU8YOhLV.mjs";
|
|
4
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-Cn1oRaLw.mjs";
|
|
5
5
|
import { ChatType, EssenceListSync, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, WebHonorType, errorMessage, hasStringProp, isRecord, kernelError, narrowEssenceGroupArg, toCanonicalElements } from "@napuketto/kernel";
|
|
@@ -7,7 +7,7 @@ import { HttpClient, HttpServer, WsClient, WsServer } from "@napuketto/network";
|
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { existsSync } from "node:fs";
|
|
9
9
|
import { join } from "node:path";
|
|
10
|
-
import {
|
|
10
|
+
import { inferExtension } from "@napuketto/media";
|
|
11
11
|
// src/onebot11/helper/message-unique.ts
|
|
12
12
|
/** OB11 message_id 上限(int32 max = 0x7FFF_FFFF)。 */
|
|
13
13
|
const INT32_MAX = 2147483647;
|
|
@@ -1422,6 +1422,7 @@ const wsReverseSchema = z.object({
|
|
|
1422
1422
|
heartbeatInterval: z.number().int().default(DEFAULT_WS_HEARTBEAT_MS)
|
|
1423
1423
|
});
|
|
1424
1424
|
const ob11ConfigSchema = z.object({
|
|
1425
|
+
media: protocolMediaSchema.optional(),
|
|
1425
1426
|
/** 鉴权 token(全局默认,实例未指定时继承)。 */
|
|
1426
1427
|
token: z.string().optional(),
|
|
1427
1428
|
/** 心跳 meta 事件间隔(毫秒),0 关闭心跳。 */
|
|
@@ -2121,7 +2122,7 @@ function createHistoryActions(api) {
|
|
|
2121
2122
|
* downloadRichMedia)。message_id 反查 → fetchMsgsByMsgId → 找 PIC/PTT 元素:
|
|
2122
2123
|
* - 本地文件解析:NT 相对路径(sourcePath/filePath)按 mediaBaseDir(QQ NT
|
|
2123
2124
|
* global 目录)解析为绝对路径,命中磁盘即返回 file
|
|
2124
|
-
* - 图片主动下载:本地未命中且有 picUrl →
|
|
2125
|
+
* - 图片主动下载:本地未命中且有 picUrl → 按媒体出站策略下载落
|
|
2125
2126
|
* cacheDir/media/,返回 file(绝对路径)+ url + file_size/file_name
|
|
2126
2127
|
* - 语音主动下载:本地未命中 → kernel MsgApi.downloadPtt(原生
|
|
2127
2128
|
* downloadRichMedia + 轮询元素回查)→ filePath 落盘后返回绝对路径;
|
|
@@ -2155,13 +2156,10 @@ async function downloadImageToCache(url, deps) {
|
|
|
2155
2156
|
if (cacheDir === void 0 || cacheDir === "") return null;
|
|
2156
2157
|
try {
|
|
2157
2158
|
return await cacheMediaFile(cacheDir, inferExtension(null, url), async (dest) => {
|
|
2158
|
-
await
|
|
2159
|
+
await mediaDownloader(deps.getMediaOutboundPolicy?.())(url, dest);
|
|
2159
2160
|
}, "reference");
|
|
2160
2161
|
} catch (err) {
|
|
2161
|
-
deps.logger?.warn({
|
|
2162
|
-
url,
|
|
2163
|
-
error: errorMessage(err)
|
|
2164
|
-
}, "ob11: 图片主动下载失败,get_image 退原始 url");
|
|
2162
|
+
deps.logger?.warn({ error: errorMessage(err) }, "ob11: 图片主动下载失败,get_image 退原始 url");
|
|
2165
2163
|
return null;
|
|
2166
2164
|
}
|
|
2167
2165
|
}
|
|
@@ -2528,10 +2526,14 @@ const setQQAvatarSchema = z.object({
|
|
|
2528
2526
|
/** 本地路径(URL 需先下载,由装配方 cacheDir 支持)。 */
|
|
2529
2527
|
file: z.string() });
|
|
2530
2528
|
/** URL 头像下载到缓存目录(cacheDir 缺省抛错)。 */
|
|
2531
|
-
async function downloadAvatarToCache(url,
|
|
2529
|
+
async function downloadAvatarToCache(url, api) {
|
|
2530
|
+
const { cacheDir } = api;
|
|
2532
2531
|
if (cacheDir === void 0 || cacheDir === "") throw kernelError("set_qq_avatar 处理 URL 需要缓存目录(装配方未注入)", "INVALID_STATE");
|
|
2533
2532
|
return await cacheMediaFile(cacheDir, inferExtension(null, url), async (path) => {
|
|
2534
|
-
await
|
|
2533
|
+
await downloadProtocolMedia(url, path, {
|
|
2534
|
+
outboundPolicy: api.getMediaOutboundPolicy?.(),
|
|
2535
|
+
errorLabel: "头像下载失败"
|
|
2536
|
+
});
|
|
2535
2537
|
});
|
|
2536
2538
|
}
|
|
2537
2539
|
/**
|
|
@@ -2605,7 +2607,7 @@ function createSystemAccountActions(api) {
|
|
|
2605
2607
|
schema: setQQAvatarSchema,
|
|
2606
2608
|
handle: async (payload) => {
|
|
2607
2609
|
let filePath = payload.file;
|
|
2608
|
-
if (URL_PREFIX.test(filePath)) filePath = await downloadAvatarToCache(filePath, api
|
|
2610
|
+
if (URL_PREFIX.test(filePath)) filePath = await downloadAvatarToCache(filePath, api);
|
|
2609
2611
|
if (!existsSync(filePath)) throw kernelError(`头像文件不存在: ${filePath}`, "NOT_FOUND");
|
|
2610
2612
|
await api.profileApi.setHeader(await protectMediaPath(filePath));
|
|
2611
2613
|
return null;
|
|
@@ -2617,8 +2619,7 @@ function createSystemAccountActions(api) {
|
|
|
2617
2619
|
/**
|
|
2618
2620
|
* 文件收发域动作
|
|
2619
2621
|
*
|
|
2620
|
-
* - download_file
|
|
2621
|
-
* { file }。文件名:download-<timestamp>-<basename>(headers 等扩展字段忽略)
|
|
2622
|
+
* - download_file:按媒体出站策略下载到 cacheDir 的独立缓存文件,返回 { file }。
|
|
2622
2623
|
* - upload_group_file / upload_private_file——**闪传通道**
|
|
2623
2624
|
*
|
|
2624
2625
|
* ⚠️ 语义降级(探测依据见 kernel design §15):
|
|
@@ -2674,10 +2675,11 @@ function createSystemFileActions(api) {
|
|
|
2674
2675
|
handle: async (payload) => {
|
|
2675
2676
|
const { cacheDir } = api;
|
|
2676
2677
|
if (cacheDir === void 0 || cacheDir === "") throw kernelError("download_file 未配置缓存目录(装配方未注入)", "INVALID_STATE");
|
|
2677
|
-
const init = {};
|
|
2678
|
-
if (payload.headers !== void 0) init.headers = payload.headers;
|
|
2679
2678
|
return { file: await cacheMediaFile(cacheDir, inferExtension(null, payload.url), async (path) => {
|
|
2680
|
-
await
|
|
2679
|
+
await downloadProtocolMedia(payload.url, path, {
|
|
2680
|
+
outboundPolicy: api.getMediaOutboundPolicy?.(),
|
|
2681
|
+
headers: payload.headers
|
|
2682
|
+
});
|
|
2681
2683
|
}, "reference") };
|
|
2682
2684
|
}
|
|
2683
2685
|
}),
|
|
@@ -2992,6 +2994,7 @@ function openOutboundWithRetry(transport, opts) {
|
|
|
2992
2994
|
*/
|
|
2993
2995
|
var OneBotApi = class {
|
|
2994
2996
|
mediaCache;
|
|
2997
|
+
getMediaOutboundPolicy;
|
|
2995
2998
|
/** kernel 消息 API(send_msg 等消息类动作用)。 */
|
|
2996
2999
|
msgApi;
|
|
2997
3000
|
/** kernel 群 API。 */
|
|
@@ -3034,7 +3037,8 @@ var OneBotApi = class {
|
|
|
3034
3037
|
restart;
|
|
3035
3038
|
/** 降级分支可观测出口(缺省静默)。 */
|
|
3036
3039
|
logger;
|
|
3037
|
-
constructor(opts) {
|
|
3040
|
+
constructor(opts, getMediaOutboundPolicy) {
|
|
3041
|
+
this.getMediaOutboundPolicy = getMediaOutboundPolicy;
|
|
3038
3042
|
this.mediaCache = new MediaCache({
|
|
3039
3043
|
root: opts.system?.cacheDir,
|
|
3040
3044
|
logger: opts.logger
|
|
@@ -3882,7 +3886,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
|
|
|
3882
3886
|
});
|
|
3883
3887
|
this.selfUin = opts.self.uin;
|
|
3884
3888
|
this.logger = opts.logger;
|
|
3885
|
-
this.oneBotApi = new OneBotApi(opts);
|
|
3889
|
+
this.oneBotApi = new OneBotApi(opts, () => config.get?.()?.media?.outboundPolicy);
|
|
3886
3890
|
this.pipeline = new Ob11EventPipeline({
|
|
3887
3891
|
selfUin: this.selfUin,
|
|
3888
3892
|
api: this.oneBotApi,
|
package/dist/satori/index.d.mts
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Satori 协议适配器
|
|
3
3
|
* 公共面:类型 + 动作注册表 + 配置 schema + 传输装配 + 适配器。
|
|
4
4
|
*/
|
|
5
|
-
import { A as Message, B as SatoriActionDeps, C as Emoji, D as GuildRole, E as GuildMember, F as Order, G as SatoriToCanonicalDeps, H as SatoriActionError, I as HTTP_STATUS, J as renderElements, K as SatoriElement, L as satoriHttpStatusMap, M as BidiList, N as Direction, O as Login, P as List, R as SatoriConfig, S as ChannelType, T as Guild, U as SatoriApi, V as createSatoriActionRegistry, W as SatoriApiOptions, _ as MetaBody, a as parseContentToCanonical, b as Signal, c as canonicalToSatoriElements, d as NapukettoSatoriAdapter, f as SatoriAdapterOptions, g as IdentifyBody, h as Event, i as toEventSignal, j as User, k as LoginStatus, l as SatoriEventContent, m as Button, n as SatoriTransportSet, o as satoriToCanonicalElements, p as Argv, q as parseElements, r as assembleSatoriTransports, s as CanonicalToSatoriDeps, t as AssembleSatoriTransportsOptions, u as SatoriEventDeps, v as Opcode, w as Friend, x as Channel, y as ReadyBody, z as satoriConfigSchema } from "../index-
|
|
5
|
+
import { A as Message, B as SatoriActionDeps, C as Emoji, D as GuildRole, E as GuildMember, F as Order, G as SatoriToCanonicalDeps, H as SatoriActionError, I as HTTP_STATUS, J as renderElements, K as SatoriElement, L as satoriHttpStatusMap, M as BidiList, N as Direction, O as Login, P as List, R as SatoriConfig, S as ChannelType, T as Guild, U as SatoriApi, V as createSatoriActionRegistry, W as SatoriApiOptions, _ as MetaBody, a as parseContentToCanonical, b as Signal, c as canonicalToSatoriElements, d as NapukettoSatoriAdapter, f as SatoriAdapterOptions, g as IdentifyBody, h as Event, i as toEventSignal, j as User, k as LoginStatus, l as SatoriEventContent, m as Button, n as SatoriTransportSet, o as satoriToCanonicalElements, p as Argv, q as parseElements, r as assembleSatoriTransports, s as CanonicalToSatoriDeps, t as AssembleSatoriTransportsOptions, u as SatoriEventDeps, v as Opcode, w as Friend, x as Channel, y as ReadyBody, z as satoriConfigSchema } from "../index-CX7UKc6W.mjs";
|
|
6
6
|
export { type Argv, type AssembleSatoriTransportsOptions, type BidiList, type Button, type CanonicalToSatoriDeps, type Channel, type ChannelType, type Direction, type Emoji, type Event, type Friend, type Guild, type GuildMember, type GuildRole, HTTP_STATUS, type IdentifyBody, type List, type Login, type LoginStatus, type Message, type MetaBody, NapukettoSatoriAdapter, type Opcode, type Order, type ReadyBody, type SatoriActionDeps, SatoriActionError, type SatoriAdapterOptions, SatoriApi, type SatoriApiOptions, type SatoriConfig, type SatoriElement, type SatoriEventContent, type SatoriEventDeps, type SatoriToCanonicalDeps, type SatoriTransportSet, type Signal, type User, assembleSatoriTransports, canonicalToSatoriElements, createSatoriActionRegistry, parseContentToCanonical, parseElements, renderElements, satoriConfigSchema, satoriHttpStatusMap, satoriToCanonicalElements, toEventSignal };
|
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-Cetkw86t.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
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 { a as logEventFailure, c as
|
|
2
|
+
import { _ as withMediaScope, a as logEventFailure, c as protocolMediaSchema, g as protectMediaPath, h as cacheMediaFile, l as downloadProtocolMedia, m as MediaCache, t as collectGrayTipUids, u as ensureSilk } from "./gray-tip-BtiJls6z.mjs";
|
|
3
3
|
import { c as MS_TO_SEC, h as toUinString, i as toUnixSeconds, r as subscribeRawMessages } from "./raw-message-DU8YOhLV.mjs";
|
|
4
4
|
import { ChatType, GrayTipSubType, NTGroupRequestOperateTypes, TipGroupElementType, isRecord, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
5
5
|
import { HttpServer, WsServer, isWsOpen, sendWsText } from "@napuketto/network";
|
|
@@ -22,6 +22,7 @@ const httpServerSchema = createServerSchema(DEFAULT_HTTP_PORT);
|
|
|
22
22
|
/** WS 事件服务实例(/v1/events 信令,第三方 SDK 连入)。 */
|
|
23
23
|
const wsServerSchema = createServerSchema(DEFAULT_WS_PORT);
|
|
24
24
|
const satoriConfigSchema = z.object({
|
|
25
|
+
media: protocolMediaSchema.optional(),
|
|
25
26
|
/** 鉴权 token(全局默认,实例未指定时继承)。 */
|
|
26
27
|
token: z.string().optional(),
|
|
27
28
|
/** 媒体资源(img/audio/video/file)下载缓存目录。 */
|
|
@@ -855,8 +856,7 @@ function createLoginActions(deps) {
|
|
|
855
856
|
* Satori 发方向资源处理(从 element-convert.ts 拆分,FTA 优化)
|
|
856
857
|
*
|
|
857
858
|
* - resolveAsset:internal: 路径 / http(s) 下载 / 本地路径原样
|
|
858
|
-
* -
|
|
859
|
-
* - 下载落盘统一走 shared/media.ts 的 downloadBufferToFile(异步 I/O 单一入口)
|
|
859
|
+
* - HTTP(S) 下载遵循当前协议配置的媒体出站策略。
|
|
860
860
|
*/
|
|
861
861
|
/** internal:{platform}/{user.id}/{path} → 本地路径(取 _tmp 之后的路径,回落 cacheDir)。 */
|
|
862
862
|
function resolveInternalPath(src) {
|
|
@@ -883,23 +883,22 @@ function assetFileName(src) {
|
|
|
883
883
|
* - http(s):// → 下载到 cacheDir
|
|
884
884
|
* - 其他 → 视为本地路径原样返回
|
|
885
885
|
*/
|
|
886
|
-
async function resolveAsset(src, cacheDir) {
|
|
886
|
+
async function resolveAsset(src, cacheDir, outboundPolicy) {
|
|
887
887
|
if (src.startsWith("internal:")) return await protectMediaPath(resolveInternalPath(src));
|
|
888
|
-
if (HTTP_URL_RE.test(src)) return
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
return await cacheMediaFile(cacheDir, inferExtension(null, url), async (path) => {
|
|
894
|
-
await downloadBufferToFile(url, path, void 0, "下载资源失败");
|
|
888
|
+
if (HTTP_URL_RE.test(src)) return await cacheMediaFile(cacheDir, inferExtension(null, src), async (path) => {
|
|
889
|
+
await downloadProtocolMedia(src, path, {
|
|
890
|
+
outboundPolicy,
|
|
891
|
+
errorLabel: "下载资源失败"
|
|
892
|
+
});
|
|
895
893
|
});
|
|
894
|
+
return await protectMediaPath(src);
|
|
896
895
|
}
|
|
897
896
|
// src/satori/helper/element/media-convert.ts
|
|
898
897
|
/** 解析元素媒体 src(空 → null 忽略),返回本地路径。 */
|
|
899
898
|
async function resolveMediaSrc(el, deps) {
|
|
900
899
|
const src = el.attrs?.["src"] ?? "";
|
|
901
900
|
if (src === "") return null;
|
|
902
|
-
return resolveAsset(src, deps.cacheDir);
|
|
901
|
+
return resolveAsset(src, deps.cacheDir, deps.outboundPolicy);
|
|
903
902
|
}
|
|
904
903
|
/** Satori img → canonical image。 */
|
|
905
904
|
async function imgToCanonical(el, deps) {
|
|
@@ -1337,7 +1336,9 @@ var SatoriApi = class {
|
|
|
1337
1336
|
* 规则区分,需从事件/查询回填——QQ 平台群号与用户 uin 同为数字)。
|
|
1338
1337
|
*/
|
|
1339
1338
|
channelTypeCache = /* @__PURE__ */ new Map();
|
|
1340
|
-
|
|
1339
|
+
getMediaOutboundPolicy;
|
|
1340
|
+
constructor(opts, getMediaOutboundPolicy) {
|
|
1341
|
+
this.getMediaOutboundPolicy = getMediaOutboundPolicy;
|
|
1341
1342
|
this.msgApi = opts.msgApi;
|
|
1342
1343
|
this.groupApi = opts.groupApi;
|
|
1343
1344
|
this.groupNotifyApi = opts.groupNotifyApi;
|
|
@@ -1396,7 +1397,8 @@ var SatoriApi = class {
|
|
|
1396
1397
|
toCanonicalDeps() {
|
|
1397
1398
|
return {
|
|
1398
1399
|
uinToUid: (uins) => this.groupApi.uinToUid(uins),
|
|
1399
|
-
cacheDir: this.cacheDir
|
|
1400
|
+
cacheDir: this.cacheDir,
|
|
1401
|
+
outboundPolicy: this.getMediaOutboundPolicy?.()
|
|
1400
1402
|
};
|
|
1401
1403
|
}
|
|
1402
1404
|
};
|
|
@@ -1784,7 +1786,7 @@ var NapukettoSatoriAdapter = class extends BaseProtocolAdapter {
|
|
|
1784
1786
|
}
|
|
1785
1787
|
});
|
|
1786
1788
|
this.msgChannel = opts.msgChannel;
|
|
1787
|
-
this.api = new SatoriApi(opts);
|
|
1789
|
+
this.api = new SatoriApi(opts, () => config.get?.()?.media?.outboundPolicy);
|
|
1788
1790
|
this.logger = opts.logger;
|
|
1789
1791
|
this.registry = createSatoriActionRegistry({ api: this.api });
|
|
1790
1792
|
}
|
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.
|
|
4
|
+
"version": "0.20.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Protocol adapters (OneBot11 / Satori / KuroBot / Milky) for NapukettoQQ",
|
|
7
7
|
"keywords": [
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"@napuketto/kernel": "^0.16.4",
|
|
87
|
-
"@napuketto/media": "^0.
|
|
87
|
+
"@napuketto/media": "^0.3.0",
|
|
88
88
|
"@napuketto/network": "^0.5.0",
|
|
89
89
|
"zod": "^4.6.7"
|
|
90
90
|
},
|