@napuketto/adapter 0.19.0 → 0.21.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.
@@ -1,8 +1,9 @@
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";
6
+ import { MediaOutboundPolicy } from "@napuketto/media";
6
7
  /**
7
8
  * Milky 动作结果(retcode 为规范负数族;transport 原样组装信封)。
8
9
  *
@@ -69,6 +70,13 @@ declare class MessageSeqIndex {
69
70
  private evict;
70
71
  }
71
72
  declare const milkyConfigSchema: z.ZodObject<{
73
+ media: z.ZodOptional<z.ZodObject<{
74
+ localMediaRoots: z.ZodOptional<z.ZodArray<z.ZodString>>;
75
+ outboundPolicy: z.ZodOptional<z.ZodEnum<{
76
+ compat: "compat";
77
+ "public-only": "public-only";
78
+ }>>;
79
+ }, z.core.$strip>>;
72
80
  enabled: z.ZodDefault<z.ZodBoolean>;
73
81
  host: z.ZodDefault<z.ZodString>;
74
82
  port: z.ZodDefault<z.ZodNumber>;
@@ -104,6 +112,8 @@ declare function assembleMilkyTransports(opts: {
104
112
  }): MilkyTransportSet;
105
113
  /** MilkyApi 构造参数。 */
106
114
  interface MilkyApiOptions {
115
+ /** 相对 media.localMediaRoots 的可信基准目录,缺省为工作目录。 */
116
+ localMediaBaseDir?: string | undefined;
107
117
  msgApi: MsgApi;
108
118
  groupApi: GroupApi;
109
119
  friendApi: FriendApi;
@@ -137,6 +147,7 @@ interface MilkyApiOptions {
137
147
  }
138
148
  declare class MilkyApi {
139
149
  readonly mediaCache: MediaCache;
150
+ readonly getLocalMediaRoots?: (() => readonly string[]) | undefined;
140
151
  readonly msgApi: MsgApi;
141
152
  readonly groupApi: GroupApi;
142
153
  readonly friendApi: FriendApi;
@@ -158,11 +169,12 @@ declare class MilkyApi {
158
169
  readonly qqVersion: string;
159
170
  readonly implVersion: string;
160
171
  readonly mediaDir: string | undefined;
172
+ readonly getMediaOutboundPolicy?: (() => MediaOutboundPolicy | undefined) | undefined;
161
173
  /** 动作层可观测出口(缺省静默)。 */
162
174
  readonly logger: MilkyLoggerLike | undefined;
163
175
  /** message_seq ↔ msgId 双向映射(接收链路 record,动作侧反查)。 */
164
176
  readonly seqIndex: MessageSeqIndex;
165
- constructor(opts: MilkyApiOptions, seqIndex: MessageSeqIndex);
177
+ constructor(opts: MilkyApiOptions, seqIndex: MessageSeqIndex, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined, getLocalMediaRoots?: () => readonly string[] | undefined);
166
178
  /** uin → uid(私聊目标 / at 段发送转换 / 群管动作的 uid 入参)。 */
167
179
  uinToUid(uins: string[]): Promise<Map<string, string>>;
168
180
  /** uid → uin(事件路径 mention 转换)。 */
@@ -1,9 +1,10 @@
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";
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,11 +25,16 @@ 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;
29
+ localMediaRoots?: readonly string[] | undefined;
30
+ account?: string;
27
31
  /** 转码成功即转移输出文件及其父临时目录的所有权;发送消费结束后清理。 */
28
32
  onVideoTranscoded?: (path: string) => void;
29
33
  }
30
34
  /** SatoriApi 构造参数。 */
31
35
  interface SatoriApiOptions {
36
+ /** 相对 media.localMediaRoots 的可信基准目录,缺省为工作目录。 */
37
+ localMediaBaseDir?: string | undefined;
32
38
  msgApi: MsgApi;
33
39
  groupApi: GroupApi;
34
40
  groupNotifyApi: GroupNotifyApi;
@@ -41,6 +47,7 @@ interface SatoriApiOptions {
41
47
  };
42
48
  /** 媒体资源下载缓存目录(缺省 `os.tmpdir()/napuketto-satori-cache`)。 */
43
49
  cacheDir?: string | undefined;
50
+ mediaBaseDir?: string | undefined;
44
51
  /** 群/成员缓存(guild.member.get / user.get 读缓存用)。 */
45
52
  groupCache?: GroupCache | undefined;
46
53
  /** 媒体缓存清理失败的可观测出口。 */
@@ -49,6 +56,7 @@ interface SatoriApiOptions {
49
56
  /** Satori 动作统一依赖聚合。 */
50
57
  declare class SatoriApi {
51
58
  readonly mediaCache: MediaCache;
59
+ readonly getLocalMediaRoots?: (() => readonly string[]) | undefined;
52
60
  readonly msgApi: MsgApi;
53
61
  readonly groupApi: GroupApi;
54
62
  readonly groupNotifyApi: GroupNotifyApi;
@@ -60,13 +68,15 @@ declare class SatoriApi {
60
68
  };
61
69
  readonly selfUin: string;
62
70
  readonly cacheDir: string;
71
+ readonly publishLocalAsset?: ((path: string) => Promise<string | undefined>) | undefined;
63
72
  readonly groupCache: GroupCache | undefined;
64
73
  /**
65
74
  * 频道类型缓存:channel_id → isGroup(群聊频道 id 与私聊 uin 无法从数字
66
75
  * 规则区分,需从事件/查询回填——QQ 平台群号与用户 uin 同为数字)。
67
76
  */
68
77
  private readonly channelTypeCache;
69
- constructor(opts: SatoriApiOptions);
78
+ private readonly getMediaOutboundPolicy;
79
+ constructor(opts: SatoriApiOptions, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined, getLocalMediaRoots?: () => readonly string[] | undefined);
70
80
  /** 记录频道类型(消息事件翻译时回填:chatType GROUP → true)。 */
71
81
  setChannelType(channelId: string, isGroup: boolean): void;
72
82
  /**
@@ -106,6 +116,13 @@ type SatoriActionRegistry = ActionRegistry<SatoriActionHandler<unknown, unknown>
106
116
  /** 创建 Satori 动作注册表。 */
107
117
  declare function createSatoriActionRegistry(deps: SatoriActionDeps): SatoriActionRegistry;
108
118
  declare const satoriConfigSchema: z.ZodObject<{
119
+ media: z.ZodOptional<z.ZodObject<{
120
+ localMediaRoots: z.ZodOptional<z.ZodArray<z.ZodString>>;
121
+ outboundPolicy: z.ZodOptional<z.ZodEnum<{
122
+ compat: "compat";
123
+ "public-only": "public-only";
124
+ }>>;
125
+ }, z.core.$strip>>;
109
126
  token: z.ZodOptional<z.ZodString>;
110
127
  cacheDir: z.ZodOptional<z.ZodString>;
111
128
  httpServers: z.ZodDefault<z.ZodArray<z.ZodObject<{
@@ -333,6 +350,7 @@ interface SatoriTranslateDeps {
333
350
  selfUin: string;
334
351
  /** uid → uin(at 目标 / 用户 ID;缺省不转换)。 */
335
352
  uidToUin?: (uids: string[]) => Promise<Map<string, string>>;
353
+ publishLocalAsset?: ((path: string) => Promise<string | undefined>) | undefined;
336
354
  }
337
355
  /** 适配器构造参数。 */
338
356
  interface SatoriAdapterOptions extends SatoriApiOptions {
@@ -1,9 +1,10 @@
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";
6
6
  import { ZodType, z } from "zod";
7
+ import { MediaOutboundPolicy } from "@napuketto/media";
7
8
  /**
8
9
  * OneBot 11 类型定义(自研描述,参考公开协议规范)
9
10
  * 对应:接口签名是外部协议事实,可自研描述,不复制实现。
@@ -264,6 +265,8 @@ interface OneBotSystemOptions {
264
265
  }
265
266
  /** OneBotApi 构造参数。 */
266
267
  interface OneBotApiOptions {
268
+ /** 相对 media.localMediaRoots 的可信基准目录,缺省为工作目录。 */
269
+ localMediaBaseDir?: string | undefined;
267
270
  msgApi: MsgApi;
268
271
  groupApi: GroupApi;
269
272
  groupNotifyApi: GroupNotifyApi;
@@ -293,6 +296,8 @@ interface OneBotApiOptions {
293
296
  */
294
297
  declare class OneBotApi {
295
298
  readonly mediaCache: MediaCache;
299
+ readonly getLocalMediaRoots?: (() => readonly string[]) | undefined;
300
+ readonly getMediaOutboundPolicy?: (() => MediaOutboundPolicy | undefined) | undefined;
296
301
  /** kernel 消息 API(send_msg 等消息类动作用)。 */
297
302
  readonly msgApi: MsgApi;
298
303
  /** kernel 群 API。 */
@@ -338,7 +343,7 @@ declare class OneBotApi {
338
343
  readonly restart: (() => Promise<void>) | undefined;
339
344
  /** 降级分支可观测出口(缺省静默)。 */
340
345
  readonly logger?: AdapterLoggerLike | undefined;
341
- constructor(opts: OneBotApiOptions);
346
+ constructor(opts: OneBotApiOptions, getMediaOutboundPolicy?: () => MediaOutboundPolicy | undefined, getLocalMediaRoots?: () => readonly string[] | undefined);
342
347
  /**
343
348
  * uin→uid 转换(委托 groupApi;私聊目标/成员 user_id 用)。
344
349
  * 类字段箭头函数:动作会把本方法作为回调裸传(resolveUid 等),必须绑定实例,
@@ -439,6 +444,13 @@ declare function serializeCqParts(parts: Array<string | CqCode>): string;
439
444
  /** OB11 segment 数组 → CQ 码字符串(text 段转义拼接,特殊段编码)。 */
440
445
  declare function segmentsToCqMessage(segments: OB11MessageSegment[]): string;
441
446
  declare const ob11ConfigSchema: z.ZodObject<{
447
+ media: z.ZodOptional<z.ZodObject<{
448
+ localMediaRoots: z.ZodOptional<z.ZodArray<z.ZodString>>;
449
+ outboundPolicy: z.ZodOptional<z.ZodEnum<{
450
+ compat: "compat";
451
+ "public-only": "public-only";
452
+ }>>;
453
+ }, z.core.$strip>>;
442
454
  token: z.ZodOptional<z.ZodString>;
443
455
  heartbeatInterval: z.ZodDefault<z.ZodNumber>;
444
456
  reportSelfMessage: z.ZodDefault<z.ZodBoolean>;
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-PWs-cVWe.mjs";
21
- import { C as ob11ConfigSchema, S as OB11Config, o as NapukettoOneBot11Adapter, s as OneBot11AdapterOptions } from "./index-C-pAiIuG.mjs";
22
- import { R as SatoriConfig, d as NapukettoSatoriAdapter, f as SatoriAdapterOptions, z as satoriConfigSchema } from "./index-D93z0TYf.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-DTlPFEhN.mjs";
4
- import { t as NapukettoOneBot11Adapter, u as ob11ConfigSchema } from "./onebot11-Bq0f2Tky.mjs";
5
- import { m as satoriConfigSchema, t as NapukettoSatoriAdapter } from "./satori-VkOP24Vc.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-PWs-cVWe.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-DTlPFEhN.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,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 MediaCache, h as withMediaScope, i as hasGrayTip, m as protectMediaPath, n as findRevokeElement, o as sliceRaw, p as cacheMediaFile, r as firstUntranslatedGrayTip, t as collectGrayTipUids, u as fileUriToPath } from "./gray-tip-BL1rhwZK.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";
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, downloadUrl, inferExtension } from "@napuketto/media";
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 = {
@@ -321,29 +321,25 @@ 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
- * - http(s):// → @napuketto/media downloadUrl 落盘 cacheDir/milky/
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
- async function resolveMediaUri(uri, mediaDir) {
332
+ async function resolveMediaUri(uri, mediaDir, outboundPolicy) {
332
333
  if (mediaDir === void 0 || mediaDir === "") throw kernelError("远程媒体发送需要配置 [accounts.milky] cacheDir(下载缓存目录)", "INVALID_PARAM");
333
334
  if (uri.startsWith("base64://")) return await writeBase64(uri.slice(9), mediaDir);
334
335
  return await cacheMediaFile(mediaDir, inferExtension(null, uri), async (dest) => {
335
- await downloadUrl(uri, dest);
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) {
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);
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);
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;
@@ -555,14 +552,21 @@ var MilkyApi = class {
555
552
  qqVersion;
556
553
  implVersion;
557
554
  mediaDir;
555
+ getMediaOutboundPolicy;
558
556
  /** 动作层可观测出口(缺省静默)。 */
559
557
  logger;
560
558
  /** message_seq ↔ msgId 双向映射(接收链路 record,动作侧反查)。 */
561
559
  seqIndex;
562
- constructor(opts, seqIndex) {
560
+ constructor(opts, seqIndex, getMediaOutboundPolicy, getLocalMediaRoots) {
561
+ this.getMediaOutboundPolicy = getMediaOutboundPolicy;
562
+ this.getLocalMediaRoots = bindLocalMediaRoots(opts.localMediaBaseDir, getLocalMediaRoots);
563
563
  this.mediaCache = new MediaCache({
564
564
  root: opts.mediaDir,
565
- logger: opts.logger
565
+ logger: opts.logger,
566
+ owner: {
567
+ protocol: "milky",
568
+ account: opts.self.uin
569
+ }
566
570
  });
567
571
  this.msgApi = opts.msgApi;
568
572
  this.groupApi = opts.groupApi;
@@ -806,7 +810,7 @@ function createGroupManageActions(api) {
806
810
  image_uri: z.string().min(1)
807
811
  }),
808
812
  handle: async (payload) => {
809
- const imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir);
813
+ const imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir, api.getMediaOutboundPolicy?.(), api.getLocalMediaRoots?.());
810
814
  await api.groupApi.setGroupAvatar(String(payload.group_id), imagePath);
811
815
  return {};
812
816
  }
@@ -834,7 +838,7 @@ function createGroupManageActions(api) {
834
838
  handle: async (payload) => {
835
839
  const groupCode = String(payload.group_id);
836
840
  let imagePath;
837
- if (payload.image_uri !== void 0 && payload.image_uri !== null && payload.image_uri !== "") imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir);
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?.());
838
842
  await api.groupApi.publishGroupAnnouncement(groupCode, payload.content, imagePath);
839
843
  return {};
840
844
  }
@@ -1351,7 +1355,7 @@ function replySegment(data) {
1351
1355
  /** 媒体段(image/record/video,必填 uri: string)。 */
1352
1356
  function mediaSegment(type, data) {
1353
1357
  if (!hasStringProp(data, "uri")) return invalidSegment(type);
1354
- const path = resolveUriToPathPlaceholder(data["uri"]);
1358
+ const path = data["uri"];
1355
1359
  if (type === "record") return { element: {
1356
1360
  type: "voice",
1357
1361
  path
@@ -1410,16 +1414,6 @@ function outgoingSegmentToCanonical(seg) {
1410
1414
  if (isSimpleOutgoingType(seg.type)) return simpleOutgoingSegment(seg.type, data);
1411
1415
  return complexOutgoingSegment(seg.type, data);
1412
1416
  }
1413
- /**
1414
- * 媒体 URI → 本地路径(同步面:file:// / 裸路径直接给 canonical;base64:// 与
1415
- * http(s):// 需要异步落盘,由 send 核心在 canonical 上二次解析——此处先放原始
1416
- * URI 作占位,send 核心按元素类型调用 resolveMediaUri 替换)。
1417
- */
1418
- function resolveUriToPathPlaceholder(uri) {
1419
- if (uri.startsWith("file://")) return fileUriToPath(uri);
1420
- if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("base64://")) return uri;
1421
- return uri;
1422
- }
1423
1417
  // src/milky/helper/event/translate.ts
1424
1418
  /**
1425
1419
  * Milky 事件翻译(RawMessage → Milky 事件,纯函数)
@@ -1770,7 +1764,7 @@ function createMessageOpsActions(api) {
1770
1764
  file_name: z.string().min(1)
1771
1765
  }),
1772
1766
  handle: async (payload) => {
1773
- const path = await resolveUriToPath(payload.file_uri, api.mediaDir);
1767
+ const path = await resolveUriToPath(payload.file_uri, api.mediaDir, api.getMediaOutboundPolicy?.(), api.getLocalMediaRoots?.());
1774
1768
  const peer = await api.resolvePeer("friend", payload.user_id);
1775
1769
  return { file_id: (await api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
1776
1770
  }
@@ -1915,17 +1909,12 @@ async function resolveElement(el, uinToUid, api) {
1915
1909
  ...el,
1916
1910
  target: uinToUid?.get(el.target) ?? el.target
1917
1911
  };
1918
- if ((el.type === "image" || el.type === "voice" || el.type === "video") && isRemoteMediaUri(el)) return {
1912
+ if ("path" in el) return {
1919
1913
  ...el,
1920
- path: await resolveMediaUri(el.path, api.mediaDir)
1914
+ path: await resolveUriToPath(el.path, api.mediaDir, api.getMediaOutboundPolicy?.(), api.getLocalMediaRoots?.())
1921
1915
  };
1922
- if ("path" in el) await protectMediaPath(el.path);
1923
1916
  return el;
1924
1917
  }
1925
- /** 远程媒体元素(image/voice/video 且 path 为需落盘的 URI)。 */
1926
- function isRemoteMediaUri(el) {
1927
- return el.path.startsWith("http://") || el.path.startsWith("https://") || el.path.startsWith("base64://");
1928
- }
1929
1918
  // src/milky/action/profile.ts
1930
1919
  /**
1931
1920
  * Milky 资料类动作:get_user_profile / get_friend_info / set_avatar /
@@ -1976,7 +1965,7 @@ function createProfileActions(api) {
1976
1965
  name: "set_avatar",
1977
1966
  schema: z.object({ uri: z.string().min(1) }),
1978
1967
  handle: async (payload) => {
1979
- const path = await resolveMediaUri(payload.uri, api.mediaDir);
1968
+ const path = await resolveUriToPath(payload.uri, api.mediaDir, api.getMediaOutboundPolicy?.(), api.getLocalMediaRoots?.());
1980
1969
  await api.profileApi.setHeader(path);
1981
1970
  return {};
1982
1971
  }
@@ -2242,6 +2231,7 @@ function createMilkyActionRegistry(opts) {
2242
2231
  return registry;
2243
2232
  }
2244
2233
  const milkyConfigSchema = z.object({
2234
+ media: protocolMediaSchema.optional(),
2245
2235
  /** 启用开关(缺省 false:账号段存在但 enabled 未开 = 装配为空转)。 */
2246
2236
  enabled: z.boolean().default(false),
2247
2237
  /** HTTP 监听地址。 */
@@ -3315,7 +3305,7 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
3315
3305
  hooks
3316
3306
  });
3317
3307
  this.calibLogger = opts.logger;
3318
- this.api = new MilkyApi(opts, this.seqIndex);
3308
+ this.api = new MilkyApi(opts, this.seqIndex, () => config.get?.()?.media?.outboundPolicy, () => config.get?.()?.media?.localMediaRoots);
3319
3309
  const base = {
3320
3310
  api: this.api,
3321
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-C-pAiIuG.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-Bq0f2Tky.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";