@napuketto/adapter 0.20.0 → 0.21.1

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.
@@ -1,5 +1,5 @@
1
1
  import { m as ActionRegistry, s as BaseProtocolAdapter, t as ConfigBase$1 } from "./index-BO1TgLTT.mjs";
2
- import { t as MediaCache } from "./media-cache-C_0C9eCV.mjs";
2
+ import { t as MediaCache } from "./media-cache-BaTQ_l_b.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";
@@ -71,6 +71,7 @@ declare class MessageSeqIndex {
71
71
  }
72
72
  declare const milkyConfigSchema: z.ZodObject<{
73
73
  media: z.ZodOptional<z.ZodObject<{
74
+ localMediaRoots: z.ZodOptional<z.ZodArray<z.ZodString>>;
74
75
  outboundPolicy: z.ZodOptional<z.ZodEnum<{
75
76
  compat: "compat";
76
77
  "public-only": "public-only";
@@ -111,6 +112,8 @@ declare function assembleMilkyTransports(opts: {
111
112
  }): MilkyTransportSet;
112
113
  /** MilkyApi 构造参数。 */
113
114
  interface MilkyApiOptions {
115
+ /** 相对 media.localMediaRoots 的可信基准目录,缺省为工作目录。 */
116
+ localMediaBaseDir?: string | undefined;
114
117
  msgApi: MsgApi;
115
118
  groupApi: GroupApi;
116
119
  friendApi: FriendApi;
@@ -144,6 +147,7 @@ interface MilkyApiOptions {
144
147
  }
145
148
  declare class MilkyApi {
146
149
  readonly mediaCache: MediaCache;
150
+ readonly getLocalMediaRoots?: (() => readonly string[]) | undefined;
147
151
  readonly msgApi: MsgApi;
148
152
  readonly groupApi: GroupApi;
149
153
  readonly friendApi: FriendApi;
@@ -170,7 +174,7 @@ declare class MilkyApi {
170
174
  readonly logger: MilkyLoggerLike | undefined;
171
175
  /** message_seq ↔ msgId 双向映射(接收链路 record,动作侧反查)。 */
172
176
  readonly seqIndex: MessageSeqIndex;
173
- constructor(opts: MilkyApiOptions, seqIndex: MessageSeqIndex, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined);
177
+ constructor(opts: MilkyApiOptions, seqIndex: MessageSeqIndex, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined, getLocalMediaRoots?: () => readonly string[] | undefined);
174
178
  /** uin → uid(私聊目标 / at 段发送转换 / 群管动作的 uid 入参)。 */
175
179
  uinToUid(uins: string[]): Promise<Map<string, string>>;
176
180
  /** uid → uin(事件路径 mention 转换)。 */
@@ -1,5 +1,5 @@
1
1
  import { m as ActionRegistry, s as BaseProtocolAdapter, t as ConfigBase$1 } from "./index-BO1TgLTT.mjs";
2
- import { n as AdapterLoggerLike, t as MediaCache } from "./media-cache-C_0C9eCV.mjs";
2
+ import { n as AdapterLoggerLike, t as MediaCache } from "./media-cache-BaTQ_l_b.mjs";
3
3
  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";
@@ -26,11 +26,15 @@ interface SatoriToCanonicalDeps {
26
26
  /** 资源(img/audio/video/file)下载缓存目录。 */
27
27
  cacheDir: string;
28
28
  outboundPolicy?: MediaOutboundPolicy | undefined;
29
+ localMediaRoots?: readonly string[] | undefined;
30
+ account?: string;
29
31
  /** 转码成功即转移输出文件及其父临时目录的所有权;发送消费结束后清理。 */
30
32
  onVideoTranscoded?: (path: string) => void;
31
33
  }
32
34
  /** SatoriApi 构造参数。 */
33
35
  interface SatoriApiOptions {
36
+ /** 相对 media.localMediaRoots 的可信基准目录,缺省为工作目录。 */
37
+ localMediaBaseDir?: string | undefined;
34
38
  msgApi: MsgApi;
35
39
  groupApi: GroupApi;
36
40
  groupNotifyApi: GroupNotifyApi;
@@ -43,6 +47,7 @@ interface SatoriApiOptions {
43
47
  };
44
48
  /** 媒体资源下载缓存目录(缺省 `os.tmpdir()/napuketto-satori-cache`)。 */
45
49
  cacheDir?: string | undefined;
50
+ mediaBaseDir?: string | undefined;
46
51
  /** 群/成员缓存(guild.member.get / user.get 读缓存用)。 */
47
52
  groupCache?: GroupCache | undefined;
48
53
  /** 媒体缓存清理失败的可观测出口。 */
@@ -51,6 +56,7 @@ interface SatoriApiOptions {
51
56
  /** Satori 动作统一依赖聚合。 */
52
57
  declare class SatoriApi {
53
58
  readonly mediaCache: MediaCache;
59
+ readonly getLocalMediaRoots?: (() => readonly string[]) | undefined;
54
60
  readonly msgApi: MsgApi;
55
61
  readonly groupApi: GroupApi;
56
62
  readonly groupNotifyApi: GroupNotifyApi;
@@ -62,6 +68,7 @@ declare class SatoriApi {
62
68
  };
63
69
  readonly selfUin: string;
64
70
  readonly cacheDir: string;
71
+ readonly publishLocalAsset?: ((path: string) => Promise<string | undefined>) | undefined;
65
72
  readonly groupCache: GroupCache | undefined;
66
73
  /**
67
74
  * 频道类型缓存:channel_id → isGroup(群聊频道 id 与私聊 uin 无法从数字
@@ -69,7 +76,7 @@ declare class SatoriApi {
69
76
  */
70
77
  private readonly channelTypeCache;
71
78
  private readonly getMediaOutboundPolicy;
72
- constructor(opts: SatoriApiOptions, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined);
79
+ constructor(opts: SatoriApiOptions, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined, getLocalMediaRoots?: () => readonly string[] | undefined);
73
80
  /** 记录频道类型(消息事件翻译时回填:chatType GROUP → true)。 */
74
81
  setChannelType(channelId: string, isGroup: boolean): void;
75
82
  /**
@@ -110,6 +117,7 @@ type SatoriActionRegistry = ActionRegistry<SatoriActionHandler<unknown, unknown>
110
117
  declare function createSatoriActionRegistry(deps: SatoriActionDeps): SatoriActionRegistry;
111
118
  declare const satoriConfigSchema: z.ZodObject<{
112
119
  media: z.ZodOptional<z.ZodObject<{
120
+ localMediaRoots: z.ZodOptional<z.ZodArray<z.ZodString>>;
113
121
  outboundPolicy: z.ZodOptional<z.ZodEnum<{
114
122
  compat: "compat";
115
123
  "public-only": "public-only";
@@ -342,6 +350,7 @@ interface SatoriTranslateDeps {
342
350
  selfUin: string;
343
351
  /** uid → uin(at 目标 / 用户 ID;缺省不转换)。 */
344
352
  uidToUin?: (uids: string[]) => Promise<Map<string, string>>;
353
+ publishLocalAsset?: ((path: string) => Promise<string | undefined>) | undefined;
345
354
  }
346
355
  /** 适配器构造参数。 */
347
356
  interface SatoriAdapterOptions extends SatoriApiOptions {
@@ -1,5 +1,5 @@
1
1
  import { _ as ErrorCodeMap, m as ActionRegistry, s as BaseProtocolAdapter, t as ConfigBase$1 } from "./index-BO1TgLTT.mjs";
2
- import { n as AdapterLoggerLike, t as MediaCache } from "./media-cache-C_0C9eCV.mjs";
2
+ import { n as AdapterLoggerLike, t as MediaCache } from "./media-cache-BaTQ_l_b.mjs";
3
3
  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";
@@ -265,6 +265,8 @@ interface OneBotSystemOptions {
265
265
  }
266
266
  /** OneBotApi 构造参数。 */
267
267
  interface OneBotApiOptions {
268
+ /** 相对 media.localMediaRoots 的可信基准目录,缺省为工作目录。 */
269
+ localMediaBaseDir?: string | undefined;
268
270
  msgApi: MsgApi;
269
271
  groupApi: GroupApi;
270
272
  groupNotifyApi: GroupNotifyApi;
@@ -294,6 +296,7 @@ interface OneBotApiOptions {
294
296
  */
295
297
  declare class OneBotApi {
296
298
  readonly mediaCache: MediaCache;
299
+ readonly getLocalMediaRoots?: (() => readonly string[]) | undefined;
297
300
  readonly getMediaOutboundPolicy?: (() => MediaOutboundPolicy | undefined) | undefined;
298
301
  /** kernel 消息 API(send_msg 等消息类动作用)。 */
299
302
  readonly msgApi: MsgApi;
@@ -340,7 +343,7 @@ declare class OneBotApi {
340
343
  readonly restart: (() => Promise<void>) | undefined;
341
344
  /** 降级分支可观测出口(缺省静默)。 */
342
345
  readonly logger?: AdapterLoggerLike | undefined;
343
- constructor(opts: OneBotApiOptions, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined);
346
+ constructor(opts: OneBotApiOptions, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined, getLocalMediaRoots?: () => readonly string[] | undefined);
344
347
  /**
345
348
  * uin→uid 转换(委托 groupApi;私聊目标/成员 user_id 用)。
346
349
  * 类字段箭头函数:动作会把本方法作为回调裸传(resolveUid 等),必须绑定实例,
@@ -442,6 +445,7 @@ declare function serializeCqParts(parts: Array<string | CqCode>): string;
442
445
  declare function segmentsToCqMessage(segments: OB11MessageSegment[]): string;
443
446
  declare const ob11ConfigSchema: z.ZodObject<{
444
447
  media: z.ZodOptional<z.ZodObject<{
448
+ localMediaRoots: z.ZodOptional<z.ZodArray<z.ZodString>>;
445
449
  outboundPolicy: z.ZodOptional<z.ZodEnum<{
446
450
  compat: "compat";
447
451
  "public-only": "public-only";
package/dist/index.d.mts CHANGED
@@ -17,7 +17,16 @@
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-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
- 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 };
20
+ import { G as MilkyConfig, K as milkyConfigSchema, L as MilkyAdapterOptions, R as NapukettoMilkyAdapter } from "./index-Cwq1NPKE.mjs";
21
+ import { C as ob11ConfigSchema, S as OB11Config, o as NapukettoOneBot11Adapter, s as OneBot11AdapterOptions } from "./index-DsGLfZOl.mjs";
22
+ import { R as SatoriConfig, d as NapukettoSatoriAdapter, f as SatoriAdapterOptions, z as satoriConfigSchema } from "./index-DAoLsewN.mjs";
23
+ import { z } from "zod";
24
+ declare const protocolMediaSchema: z.ZodObject<{
25
+ localMediaRoots: z.ZodOptional<z.ZodArray<z.ZodString>>;
26
+ outboundPolicy: z.ZodOptional<z.ZodEnum<{
27
+ compat: "compat";
28
+ "public-only": "public-only";
29
+ }>>;
30
+ }, z.core.$strip>;
31
+ type ProtocolMediaConfig = z.infer<typeof protocolMediaSchema>;
32
+ 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 ProtocolMediaConfig, 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-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";
3
+ import { r as milkyConfigSchema, t as NapukettoMilkyAdapter } from "./milky-v3TqHlCp.mjs";
4
+ import { t as NapukettoOneBot11Adapter, u as ob11ConfigSchema } from "./onebot11-CZUzbgSG.mjs";
5
+ import { m as satoriConfigSchema, t as NapukettoSatoriAdapter } from "./satori-Cna8fauQ.mjs";
6
6
  export { ActionRegistry, BaseProtocolAdapter, ConfigBase, NapukettoKurobotAdapter, NapukettoMilkyAdapter, NapukettoOneBot11Adapter, NapukettoSatoriAdapter, ProtocolConfig, createServerSchema, kurobotConfigSchema, milkyConfigSchema, ob11ConfigSchema, runAction, satoriConfigSchema };
@@ -8,6 +8,10 @@ interface AdapterLoggerLike {
8
8
  type Lifetime = "temporary" | "reference";
9
9
  interface CacheOptions {
10
10
  root?: string | undefined;
11
+ owner?: {
12
+ protocol: string;
13
+ account: string;
14
+ };
11
15
  logger?: Pick<AdapterLoggerLike, "warn"> | undefined;
12
16
  ttlMs?: number;
13
17
  orphanTtlMs?: number;
@@ -17,6 +21,7 @@ interface CacheOptions {
17
21
  /** Private adapter cache. Only its marked, flat entries are candidates for deletion. */
18
22
  declare class MediaCache {
19
23
  private readonly roots;
24
+ private readonly cacheName;
20
25
  private timer;
21
26
  private starting;
22
27
  private generation;
@@ -32,15 +37,27 @@ declare class MediaCache {
32
37
  run<T>(task: () => Promise<T>): Promise<T>;
33
38
  private finish;
34
39
  /** Allocate before any download/write. Writer may return a renamed output in the same entry. */
35
- create(base: string, extension: string, writer: (path: string) => Promise<string> | Promise<void>, lifetime?: Lifetime): Promise<string>;
40
+ create(base: string, extension: string, writer: (path: string) => Promise<string> | Promise<void>, lifetime?: Lifetime, inputName?: string): Promise<string>;
41
+ private allocate;
42
+ private writeEntry;
36
43
  sweep(): Promise<void>;
37
44
  private checkRoot;
45
+ private checkDirectory;
46
+ private leaseReference;
47
+ private checkReference;
48
+ private ownsRoot;
49
+ static leasePath(path: string): Promise<string>;
50
+ static leaseInternal(base: string, account: string, entry: string, file: string): Promise<string>;
38
51
  private mark;
39
52
  private inspect;
40
53
  private summarize;
41
54
  private summarizeFile;
55
+ private summarizeDirectory;
56
+ private stagedOutput;
42
57
  private videoOutput;
43
58
  private collect;
59
+ private canCollect;
44
60
  private remove;
61
+ private removeContents;
45
62
  }
46
63
  export { AdapterLoggerLike as n, MediaCache as t };
@@ -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-Dsfxdjz5.mjs";
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-Cwq1NPKE.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 };
@@ -1 +1 @@
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
+ export { a as MilkyApi, t as NapukettoMilkyAdapter, n as assembleMilkyTransports, i as createMilkyActionRegistry, r as milkyConfigSchema, o as milkyErrorCodeMap } from "../milky-v3TqHlCp.mjs";
@@ -1,5 +1,5 @@
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 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";
2
+ import { _ as cacheMediaFile, a as logEventFailure, c as protocolMediaSchema, d as mediaDownloader, g as MediaCache, h as resolveLocalMedia, i as hasGrayTip, n as findRevokeElement, o as sliceRaw, p as bindLocalMediaRoots, r as firstUntranslatedGrayTip, t as collectGrayTipUids, y as withMediaScope } from "./gray-tip-D0SfHr7q.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";
@@ -321,11 +321,12 @@ function essenceToEntity(item, groupId) {
321
321
  * 发送媒体 URI 解析(Milky OutgoingSegment uri → 本地路径)
322
322
  *
323
323
  * 规范支持 file:// / http(s):// / base64:// 三种(image/record/video 共用):
324
- * - file:// → 平台路径(segments.ts 的同步面已处理)
324
+ * - file:// 和裸路径 → 核验授权后复制进动作缓存
325
325
  * - base64:// → 解码落盘 cacheDir/milky/,file-type 探测扩展名后改名
326
326
  * - http(s):// → 按媒体出站策略下载落盘 cacheDir/milky/
327
327
  * 未配置 mediaDir 时远程 URI 报错(不发静默空消息)。
328
328
  */
329
+ const HTTP_URL_RE = /^https?:\/\//i;
329
330
  const DETECTED_EXTENSION_RE = /^[a-zA-Z0-9]+$/;
330
331
  /** 解析远程媒体 URI 为本地绝对路径(base64:// / http(s)://;file:// 走同步面)。 */
331
332
  async function resolveMediaUri(uri, mediaDir, outboundPolicy) {
@@ -335,15 +336,10 @@ async function resolveMediaUri(uri, mediaDir, outboundPolicy) {
335
336
  await mediaDownloader(outboundPolicy)(uri, dest);
336
337
  });
337
338
  }
338
- /**
339
- * 动作参数 URI(image_uri / file_uri)→ 本地路径:file:// 同步展开(fileURLToPath
340
- * 失败裸剥离兜底,与 segments.ts 同步面同规则);http(s):// / base64:// 复用
341
- * resolveMediaUri 落盘;裸路径(go-cqhttp 惯例)原样。
342
- */
343
- async function resolveUriToPath(uri, mediaDir, outboundPolicy) {
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, outboundPolicy);
346
- return await protectMediaPath(uri);
339
+ /** 发送段与上传类动作共用相同的 URI 授权与下载规则。 */
340
+ async function resolveUriToPath(uri, mediaDir, outboundPolicy, localMediaRoots) {
341
+ if (HTTP_URL_RE.test(uri) || uri.startsWith("base64://")) return await resolveMediaUri(uri, mediaDir, outboundPolicy);
342
+ return await resolveLocalMedia(uri, localMediaRoots);
347
343
  }
348
344
  /** base64 载荷 → 落盘(先写 .bin,探测到扩展名再改名)。 */
349
345
  async function writeBase64(payload, mediaDir) {
@@ -471,7 +467,7 @@ function createGroupFileActions(api) {
471
467
  file_name: z.string().min(1)
472
468
  }),
473
469
  handle: async (payload) => {
474
- const path = await resolveUriToPath(payload.file_uri, api.mediaDir, api.getMediaOutboundPolicy?.());
470
+ const path = await resolveUriToPath(payload.file_uri, api.mediaDir, api.getMediaOutboundPolicy?.(), api.getLocalMediaRoots?.());
475
471
  const peer = {
476
472
  chatType: ChatType.GROUP,
477
473
  peerUid: String(payload.group_id)
@@ -538,6 +534,7 @@ function folderToEntity(info, groupId) {
538
534
  // src/milky/api.ts
539
535
  var MilkyApi = class {
540
536
  mediaCache;
537
+ getLocalMediaRoots;
541
538
  msgApi;
542
539
  groupApi;
543
540
  friendApi;
@@ -560,11 +557,16 @@ var MilkyApi = class {
560
557
  logger;
561
558
  /** message_seq ↔ msgId 双向映射(接收链路 record,动作侧反查)。 */
562
559
  seqIndex;
563
- constructor(opts, seqIndex, getMediaOutboundPolicy) {
560
+ constructor(opts, seqIndex, getMediaOutboundPolicy, getLocalMediaRoots) {
564
561
  this.getMediaOutboundPolicy = getMediaOutboundPolicy;
562
+ this.getLocalMediaRoots = bindLocalMediaRoots(opts.localMediaBaseDir, getLocalMediaRoots);
565
563
  this.mediaCache = new MediaCache({
566
564
  root: opts.mediaDir,
567
- logger: opts.logger
565
+ logger: opts.logger,
566
+ owner: {
567
+ protocol: "milky",
568
+ account: opts.self.uin
569
+ }
568
570
  });
569
571
  this.msgApi = opts.msgApi;
570
572
  this.groupApi = opts.groupApi;
@@ -808,7 +810,7 @@ function createGroupManageActions(api) {
808
810
  image_uri: z.string().min(1)
809
811
  }),
810
812
  handle: async (payload) => {
811
- const imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir, api.getMediaOutboundPolicy?.());
813
+ const imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir, api.getMediaOutboundPolicy?.(), api.getLocalMediaRoots?.());
812
814
  await api.groupApi.setGroupAvatar(String(payload.group_id), imagePath);
813
815
  return {};
814
816
  }
@@ -836,7 +838,7 @@ function createGroupManageActions(api) {
836
838
  handle: async (payload) => {
837
839
  const groupCode = String(payload.group_id);
838
840
  let imagePath;
839
- if (payload.image_uri !== void 0 && payload.image_uri !== null && payload.image_uri !== "") imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir, api.getMediaOutboundPolicy?.());
841
+ if (payload.image_uri !== void 0 && payload.image_uri !== null && payload.image_uri !== "") imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir, api.getMediaOutboundPolicy?.(), api.getLocalMediaRoots?.());
840
842
  await api.groupApi.publishGroupAnnouncement(groupCode, payload.content, imagePath);
841
843
  return {};
842
844
  }
@@ -1353,7 +1355,7 @@ function replySegment(data) {
1353
1355
  /** 媒体段(image/record/video,必填 uri: string)。 */
1354
1356
  function mediaSegment(type, data) {
1355
1357
  if (!hasStringProp(data, "uri")) return invalidSegment(type);
1356
- const path = resolveUriToPathPlaceholder(data["uri"]);
1358
+ const path = data["uri"];
1357
1359
  if (type === "record") return { element: {
1358
1360
  type: "voice",
1359
1361
  path
@@ -1412,16 +1414,6 @@ function outgoingSegmentToCanonical(seg) {
1412
1414
  if (isSimpleOutgoingType(seg.type)) return simpleOutgoingSegment(seg.type, data);
1413
1415
  return complexOutgoingSegment(seg.type, data);
1414
1416
  }
1415
- /**
1416
- * 媒体 URI → 本地路径(同步面:file:// / 裸路径直接给 canonical;base64:// 与
1417
- * http(s):// 需要异步落盘,由 send 核心在 canonical 上二次解析——此处先放原始
1418
- * URI 作占位,send 核心按元素类型调用 resolveMediaUri 替换)。
1419
- */
1420
- function resolveUriToPathPlaceholder(uri) {
1421
- if (uri.startsWith("file://")) return fileUriToPath(uri);
1422
- if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("base64://")) return uri;
1423
- return uri;
1424
- }
1425
1417
  // src/milky/helper/event/translate.ts
1426
1418
  /**
1427
1419
  * Milky 事件翻译(RawMessage → Milky 事件,纯函数)
@@ -1772,7 +1764,7 @@ function createMessageOpsActions(api) {
1772
1764
  file_name: z.string().min(1)
1773
1765
  }),
1774
1766
  handle: async (payload) => {
1775
- const path = await resolveUriToPath(payload.file_uri, api.mediaDir, api.getMediaOutboundPolicy?.());
1767
+ const path = await resolveUriToPath(payload.file_uri, api.mediaDir, api.getMediaOutboundPolicy?.(), api.getLocalMediaRoots?.());
1776
1768
  const peer = await api.resolvePeer("friend", payload.user_id);
1777
1769
  return { file_id: (await api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
1778
1770
  }
@@ -1917,17 +1909,12 @@ async function resolveElement(el, uinToUid, api) {
1917
1909
  ...el,
1918
1910
  target: uinToUid?.get(el.target) ?? el.target
1919
1911
  };
1920
- if ((el.type === "image" || el.type === "voice" || el.type === "video") && isRemoteMediaUri(el)) return {
1912
+ if ("path" in el) return {
1921
1913
  ...el,
1922
- path: await resolveMediaUri(el.path, api.mediaDir, api.getMediaOutboundPolicy?.())
1914
+ path: await resolveUriToPath(el.path, api.mediaDir, api.getMediaOutboundPolicy?.(), api.getLocalMediaRoots?.())
1923
1915
  };
1924
- if ("path" in el) await protectMediaPath(el.path);
1925
1916
  return el;
1926
1917
  }
1927
- /** 远程媒体元素(image/voice/video 且 path 为需落盘的 URI)。 */
1928
- function isRemoteMediaUri(el) {
1929
- return el.path.startsWith("http://") || el.path.startsWith("https://") || el.path.startsWith("base64://");
1930
- }
1931
1918
  // src/milky/action/profile.ts
1932
1919
  /**
1933
1920
  * Milky 资料类动作:get_user_profile / get_friend_info / set_avatar /
@@ -1978,7 +1965,7 @@ function createProfileActions(api) {
1978
1965
  name: "set_avatar",
1979
1966
  schema: z.object({ uri: z.string().min(1) }),
1980
1967
  handle: async (payload) => {
1981
- const path = await resolveMediaUri(payload.uri, api.mediaDir, api.getMediaOutboundPolicy?.());
1968
+ const path = await resolveUriToPath(payload.uri, api.mediaDir, api.getMediaOutboundPolicy?.(), api.getLocalMediaRoots?.());
1982
1969
  await api.profileApi.setHeader(path);
1983
1970
  return {};
1984
1971
  }
@@ -3318,7 +3305,7 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
3318
3305
  hooks
3319
3306
  });
3320
3307
  this.calibLogger = opts.logger;
3321
- this.api = new MilkyApi(opts, this.seqIndex, () => config.get?.()?.media?.outboundPolicy);
3308
+ this.api = new MilkyApi(opts, this.seqIndex, () => config.get?.()?.media?.outboundPolicy, () => config.get?.()?.media?.localMediaRoots);
3322
3309
  const base = {
3323
3310
  api: this.api,
3324
3311
  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-CufnIU9v.mjs";
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-DsGLfZOl.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 };
@@ -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-BW56Dqc6.mjs";
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-CZUzbgSG.mjs";