@napuketto/adapter 0.4.1 → 0.5.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/kurobot/index.mjs +1 -1
- package/dist/milky/index.d.mts +187 -0
- package/dist/milky/index.d.mts.map +1 -0
- package/dist/milky/index.mjs +1240 -0
- package/dist/milky/index.mjs.map +1 -0
- package/dist/onebot11/index.d.mts +163 -143
- package/dist/onebot11/index.d.mts.map +1 -1
- package/dist/onebot11/index.mjs +68 -23
- package/dist/onebot11/index.mjs.map +1 -1
- package/dist/raw-message-D_ecJy4C.mjs +19 -0
- package/dist/raw-message-D_ecJy4C.mjs.map +1 -0
- package/dist/satori/index.mjs +1 -1
- package/package.json +10 -5
- package/dist/raw-message-6KdlG8kR.mjs +0 -13
- package/dist/raw-message-6KdlG8kR.mjs.map +0 -1
package/dist/kurobot/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as BaseProtocolAdapter } from "../core-DyXyDUcU.mjs";
|
|
2
|
-
import { t as forEachRawMessage } from "../raw-message-
|
|
2
|
+
import { t as forEachRawMessage } from "../raw-message-D_ecJy4C.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { ChatType, toCanonicalElements } from "@napuketto/kernel";
|
|
5
5
|
import { z } from "zod";
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { i as ProtocolConfig, n as BaseProtocolAdapter, s as ActionRegistry } from "../index-CDKj-jus.mjs";
|
|
2
|
+
import { ChatType, FriendApi, GroupApi, GroupCache, KernelErrorCode, MsgApi, MsgEventChannel, Peer, ProfileApi, RawMessage } from "@napuketto/kernel";
|
|
3
|
+
import { ZodType, z } from "zod";
|
|
4
|
+
import { EventBroadcaster, TransportAdapter } from "@napuketto/network";
|
|
5
|
+
//#region src/milky/helper/seq-index.d.ts
|
|
6
|
+
declare class MessageSeqIndex {
|
|
7
|
+
/** `${chatType}:${peerUid}:${seq}` → msgId。 */
|
|
8
|
+
private readonly seqToMsg;
|
|
9
|
+
/** msgId → seq 元信息。 */
|
|
10
|
+
private readonly msgToMeta;
|
|
11
|
+
/** 接收链路登记(一条消息双向写入;重复 msgId 覆盖)。 */
|
|
12
|
+
record(msg: RawMessage): void;
|
|
13
|
+
/** seq → msgId(反查;未登记返回 undefined)。 */
|
|
14
|
+
resolveMsgId(chatType: ChatType, peerUid: string, seq: number): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* 批量回填 reply 引用元信息(msgId → Milky reply 段 data 所需三元组)。
|
|
17
|
+
* 未命中的 id 不进表(翻译层按 0 兜底)。
|
|
18
|
+
*/
|
|
19
|
+
collectReplyMeta(msgIds: string[]): Map<string, {
|
|
20
|
+
messageSeq: number;
|
|
21
|
+
senderId: number;
|
|
22
|
+
time: number;
|
|
23
|
+
}>;
|
|
24
|
+
/** key 规则(chatType 数值 + peerUid + seq;peerUid 群聊=群号,C2C=uid)。 */
|
|
25
|
+
private key;
|
|
26
|
+
/** FIFO 淘汰到容量上限内。 */
|
|
27
|
+
private evict;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/milky/api.d.ts
|
|
31
|
+
/** MilkyApi 构造参数。 */
|
|
32
|
+
interface MilkyApiOptions {
|
|
33
|
+
msgApi: MsgApi;
|
|
34
|
+
groupApi: GroupApi;
|
|
35
|
+
friendApi: FriendApi;
|
|
36
|
+
profileApi: ProfileApi;
|
|
37
|
+
/** 登录身份(get_login_info / self_id 用)。 */
|
|
38
|
+
self: {
|
|
39
|
+
uin: string;
|
|
40
|
+
nickname: string;
|
|
41
|
+
};
|
|
42
|
+
/** 群/成员缓存(群实体回填 / get_group_list;未装配时动作直查 api)。 */
|
|
43
|
+
groupCache?: GroupCache;
|
|
44
|
+
/** QQ 客户端版本(get_impl_info.qq_protocol_version)。 */
|
|
45
|
+
qqVersion: string;
|
|
46
|
+
/** 协议端版本(get_impl_info.impl_version)。 */
|
|
47
|
+
implVersion: string;
|
|
48
|
+
/** 发送媒体 http(s)/base64 URI 下载缓存目录(缺省 = 远程媒体发送不可用)。 */
|
|
49
|
+
mediaDir?: string;
|
|
50
|
+
}
|
|
51
|
+
declare class MilkyApi {
|
|
52
|
+
readonly msgApi: MsgApi;
|
|
53
|
+
readonly groupApi: GroupApi;
|
|
54
|
+
readonly friendApi: FriendApi;
|
|
55
|
+
readonly profileApi: ProfileApi;
|
|
56
|
+
readonly self: {
|
|
57
|
+
uin: string;
|
|
58
|
+
nickname: string;
|
|
59
|
+
};
|
|
60
|
+
readonly groupCache: GroupCache | undefined;
|
|
61
|
+
readonly qqVersion: string;
|
|
62
|
+
readonly implVersion: string;
|
|
63
|
+
readonly mediaDir: string | undefined;
|
|
64
|
+
/** message_seq ↔ msgId 双向映射(接收链路 record,动作侧反查)。 */
|
|
65
|
+
readonly seqIndex: MessageSeqIndex;
|
|
66
|
+
constructor(opts: MilkyApiOptions, seqIndex: MessageSeqIndex);
|
|
67
|
+
/** uin → uid(私聊目标 / at 段发送转换)。 */
|
|
68
|
+
uinToUid(uins: string[]): Promise<Map<string, string>>;
|
|
69
|
+
/** uid → uin(事件路径 mention 转换)。 */
|
|
70
|
+
uidToUin(uids: string[]): Promise<Map<string, string>>;
|
|
71
|
+
/**
|
|
72
|
+
* message_scene + 数字 ID → NT Peer。
|
|
73
|
+
* group = 群号直作 peerUid;friend/temp = uin → uid(失败退 uin 原样,交 QQ 端判断)。
|
|
74
|
+
*/
|
|
75
|
+
resolvePeer(scene: "friend" | "group" | "temp", id: number): Promise<Peer>;
|
|
76
|
+
/**
|
|
77
|
+
* seq → msgId(索引优先,未登记扫描近段历史兜底)。
|
|
78
|
+
* 两层都未命中返回 undefined(调用方抛 NOT_FOUND)。
|
|
79
|
+
*/
|
|
80
|
+
resolveMsgIdBySeq(peer: Peer, seq: number, chatType: Peer["chatType"]): Promise<string | undefined>;
|
|
81
|
+
/** 发送结果回查:msgId → {message_seq, time}(sendMessage 只回 msgId)。 */
|
|
82
|
+
resolveSentOutput(peer: Peer, msgId: string): Promise<{
|
|
83
|
+
message_seq: number;
|
|
84
|
+
time: number;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/milky/action/error-map.d.ts
|
|
89
|
+
/** KernelErrorCode → Milky retcode 映射表(-400/-403 规范语义,其余自定负数)。 */
|
|
90
|
+
type MilkyErrorCodeMap = Record<KernelErrorCode, number>;
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/milky/action/base-action.d.ts
|
|
93
|
+
/** Milky 动作结果(retcode 为规范负数族;transport 原样组装信封)。 */
|
|
94
|
+
interface MilkyActionResult<T> {
|
|
95
|
+
status: "ok" | "failed";
|
|
96
|
+
retcode: number;
|
|
97
|
+
data: T | null;
|
|
98
|
+
message: string;
|
|
99
|
+
}
|
|
100
|
+
declare abstract class MilkyAction<TPayload, TReturn> {
|
|
101
|
+
abstract readonly name: string;
|
|
102
|
+
abstract readonly schema: ZodType<TPayload>;
|
|
103
|
+
protected abstract readonly errorCodeMap: MilkyErrorCodeMap;
|
|
104
|
+
protected abstract _handle(payload: TPayload): Promise<TReturn>;
|
|
105
|
+
/** 校验并执行(HTTP /api 入口;WS /event 不承载动作)。 */
|
|
106
|
+
handle(payload: unknown): Promise<MilkyActionResult<TReturn>>;
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/milky/action/index.d.ts
|
|
110
|
+
/** Milky 动作注册表(P0 9 动作)。 */
|
|
111
|
+
declare function createMilkyActionRegistry(opts: {
|
|
112
|
+
api: MilkyApi;
|
|
113
|
+
}): ActionRegistry<MilkyAction<unknown, unknown>>;
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/milky/config.d.ts
|
|
116
|
+
/** Milky 配置 schema。 */
|
|
117
|
+
declare const milkyConfigSchema: z.ZodObject<{
|
|
118
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
119
|
+
host: z.ZodDefault<z.ZodString>;
|
|
120
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
121
|
+
token: z.ZodDefault<z.ZodString>;
|
|
122
|
+
eventModes: z.ZodDefault<z.ZodArray<z.ZodEnum<{
|
|
123
|
+
sse: "sse";
|
|
124
|
+
ws: "ws";
|
|
125
|
+
}>>>;
|
|
126
|
+
webhooks: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
127
|
+
cacheDir: z.ZodOptional<z.ZodString>;
|
|
128
|
+
}, z.core.$strip>;
|
|
129
|
+
/** Milky 配置类型(由 schema 推导)。 */
|
|
130
|
+
type MilkyConfig = z.infer<typeof milkyConfigSchema>;
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/milky/transport.d.ts
|
|
133
|
+
/** 校准 logger 最小面(webhook 失败 / 配置异常提示;缺省静默)。 */
|
|
134
|
+
interface MilkyLoggerLike {
|
|
135
|
+
warn(obj: unknown, msg?: string): void;
|
|
136
|
+
info(obj: unknown, msg?: string): void;
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/milky/adapter.d.ts
|
|
140
|
+
/** 适配器构造参数(api 相关字段继承 MilkyApiOptions)。 */
|
|
141
|
+
interface MilkyAdapterOptions extends MilkyApiOptions {
|
|
142
|
+
config: ProtocolConfig<MilkyConfig>;
|
|
143
|
+
broadcaster: EventBroadcaster;
|
|
144
|
+
/** kernel 消息事件通道(收链路入口)。 */
|
|
145
|
+
msgChannel: MsgEventChannel;
|
|
146
|
+
/** 校准日志(webhook 失败 / 启停提示;IPC 模式传 loader pino 实例)。 */
|
|
147
|
+
logger?: MilkyLoggerLike;
|
|
148
|
+
}
|
|
149
|
+
declare class NapukettoMilkyAdapter extends BaseProtocolAdapter<MilkyConfig> {
|
|
150
|
+
readonly protocol = "milky";
|
|
151
|
+
private readonly msgChannel;
|
|
152
|
+
private readonly calibLogger;
|
|
153
|
+
private readonly api;
|
|
154
|
+
private readonly seqIndex;
|
|
155
|
+
/** 动作注册表(公共只读:装配方/测试枚举)。 */
|
|
156
|
+
readonly registry: ReturnType<typeof createMilkyActionRegistry>;
|
|
157
|
+
private unsubscribes;
|
|
158
|
+
private stopTransports;
|
|
159
|
+
constructor(opts: MilkyAdapterOptions);
|
|
160
|
+
/** 启动传输 + 订阅(enabled=false 空转:不订阅不起传输)。 */
|
|
161
|
+
private startTransports;
|
|
162
|
+
/** 热更新:停止重建(enabled 切换生效)。 */
|
|
163
|
+
private reloadTransports;
|
|
164
|
+
/** 停止:退订 + 关传输。 */
|
|
165
|
+
private stopAll;
|
|
166
|
+
/** 订阅 kernel 消息通道(幂等)。 */
|
|
167
|
+
private subscribe;
|
|
168
|
+
/** 退订(幂等)。 */
|
|
169
|
+
private unsubscribeAll;
|
|
170
|
+
/** 单条消息:seq 登记 → grayTip→recall / 普通→message_receive(自消息不上报)。 */
|
|
171
|
+
private handleIncoming;
|
|
172
|
+
/** message_receive 组装:at uid→uin + reply 回填 + 群实体回填(全部 fail-soft)。 */
|
|
173
|
+
private buildMessageReceiveEvent;
|
|
174
|
+
/** at uid → uin 批量转换(mention.user_id 用;失败 mention 段跳过)。 */
|
|
175
|
+
private fillMentionUids;
|
|
176
|
+
/** reply 引用元信息回填(seqIndex 命中即用;未命中不强查)。 */
|
|
177
|
+
private fillReplyMeta;
|
|
178
|
+
/** 群场景实体回填(GroupCache 缓存优先,失败最小实体兜底)。 */
|
|
179
|
+
private fillGroupEntities;
|
|
180
|
+
/** message_recall 组装(非撤回 grayTip 返回 null 静默)。 */
|
|
181
|
+
private buildRecallEvent;
|
|
182
|
+
/** 撤回操作者 uid → uin(未撤回/转换失败返回 undefined,operator_id 兜底 0)。 */
|
|
183
|
+
private resolveOperatorUin;
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
export { type MilkyAdapterOptions, type MilkyConfig, NapukettoMilkyAdapter, milkyConfigSchema };
|
|
187
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/milky/helper/seq-index.ts","../../src/milky/api.ts","../../src/milky/action/error-map.ts","../../src/milky/action/base-action.ts","../../src/milky/action/index.ts","../../src/milky/config.ts","../../src/milky/transport.ts","../../src/milky/adapter.ts"],"mappings":";;;;;cAsBa;;mBAEQ;;mBAEA;;EAGjB,OAAO,KAAK;;EAeZ,aAAa,UAAU,UAAU,iBAAiB;;;;;EAQlD,iBACI,mBACD;IAAc;IAAoB;IAAkB;;;UAgB/C;;UAKA;;;;;UCxDK;EACb,QAAQ;EACR,UAAU;EACV,WAAW;EACX,YAAY;;EAEZ;IAAQ;IAAa;;;EAErB,aAAa;;EAEb;;EAEA;;EAEA;;cAGS;WACA,QAAQ;WACR,UAAU;WACV,WAAW;WACX,YAAY;WACZ;IAAQ;IAAa;;WACrB,YAAY;WACZ;WACA;WACA;;WAEA,UAAU;EAEnB,YAAY,MAAM,iBAAiB,UAAU;;EAc7C,SAAS,iBAAiB,QAAQ;;EAKlC,SAAS,iBAAiB,QAAQ;;;;;EAQ5B,YAAY,oCAAoC,aAAa,QAAQ;;;;;EAqBrE,kBACF,MAAM,MACN,aACA,UAAU,mBACX;;EAeG,kBACF,MAAM,MACN,gBACD;IAAU;IAAqB;;;;;;KC9G1B,oBAAoB,OAAO;;;;UCItB,kBAAkB;EAC/B;EACA;EACA,MAAM;EACN;;uBAYkB,YAAY,UAAU;oBACtB;oBACA,QAAQ,QAAQ;8BACN,cAAc;qBAEvB,QAAQ,SAAS,WAAW,QAAQ;;EAGjD,OAAO,mBAAmB,QAAQ,kBAAkB;;;;;iBCf9C,0BAA0B;EACtC,KAAK;IACL,eAAe;;;;cCfN,mBAAiB,EAAA;;;;;;;;;;;GAe5B,EAAA,KAAA;;KAGU,cAAc,EAAE,aAAa;;;;UCQxB;EACb,KAAK,cAAc;EACnB,KAAK,cAAc;;;;;UCRN,4BAA4B;EACzC,QAAQ,eAAe;EACvB,aAAa;;EAEb,YAAY;;EAEZ,SAAS;;cAGA,8BAA8B,oBAAoB;WAClD;mBAEQ;mBACA;mBACA;mBACA;;WAER,UAAU,kBAAkB;UAC7B;UACA;EAER,YAAY,MAAM;;UAkBJ;;UAuBA;;UAMA;;UASN;;UAYA;;UAQM;;UAmBA;;UAUA;;UAkBN;;UAWM;;UAaA;;UASN"}
|