@im-more/dsh-milky 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/cordis.patch.yml +11 -0
- package/lib/index.js +2311 -0
- package/lib/index.js.map +1 -0
- package/lib/types/bot.d.ts +127 -0
- package/lib/types/bot.d.ts.map +1 -0
- package/lib/types/bot.js +303 -0
- package/lib/types/bot.js.map +1 -0
- package/lib/types/config.d.ts +24 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +39 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/decode.d.ts +43 -0
- package/lib/types/decode.d.ts.map +1 -0
- package/lib/types/decode.js +277 -0
- package/lib/types/decode.js.map +1 -0
- package/lib/types/errors.d.ts +66 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +170 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/identity.d.ts +24 -0
- package/lib/types/identity.d.ts.map +1 -0
- package/lib/types/identity.js +33 -0
- package/lib/types/identity.js.map +1 -0
- package/lib/types/ids.d.ts +110 -0
- package/lib/types/ids.d.ts.map +1 -0
- package/lib/types/ids.js +166 -0
- package/lib/types/ids.js.map +1 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +9 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/internal.d.ts +2002 -0
- package/lib/types/internal.d.ts.map +1 -0
- package/lib/types/internal.js +408 -0
- package/lib/types/internal.js.map +1 -0
- package/lib/types/modes/text.d.ts +66 -0
- package/lib/types/modes/text.d.ts.map +1 -0
- package/lib/types/modes/text.js +275 -0
- package/lib/types/modes/text.js.map +1 -0
- package/lib/types/reads.d.ts +57 -0
- package/lib/types/reads.d.ts.map +1 -0
- package/lib/types/reads.js +219 -0
- package/lib/types/reads.js.map +1 -0
- package/lib/types/request.d.ts +55 -0
- package/lib/types/request.d.ts.map +1 -0
- package/lib/types/request.js +174 -0
- package/lib/types/request.js.map +1 -0
- package/lib/types/send.d.ts +34 -0
- package/lib/types/send.d.ts.map +1 -0
- package/lib/types/send.js +99 -0
- package/lib/types/send.js.map +1 -0
- package/lib/types/types/schema.d.ts +11726 -0
- package/lib/types/types/schema.d.ts.map +1 -0
- package/lib/types/types/schema.js +1422 -0
- package/lib/types/types/schema.js.map +1 -0
- package/lib/types/ws.d.ts +60 -0
- package/lib/types/ws.d.ts.map +1 -0
- package/lib/types/ws.js +335 -0
- package/lib/types/ws.js.map +1 -0
- package/package.json +62 -3
- package/src/bot.ts +431 -0
- package/src/config.ts +61 -0
- package/src/decode.ts +367 -0
- package/src/errors.ts +195 -0
- package/src/identity.ts +43 -0
- package/src/ids.ts +226 -0
- package/src/index.ts +44 -0
- package/src/internal.ts +657 -0
- package/src/modes/text.ts +368 -0
- package/src/reads.ts +315 -0
- package/src/request.ts +230 -0
- package/src/send.ts +175 -0
- package/src/types/schema.ts +1827 -0
- package/src/ws.ts +383 -0
- package/README.md +0 -3
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound decoding: one Milky event or message becomes a DSH session without any platform I/O.
|
|
3
|
+
*
|
|
4
|
+
* Media never carries bytes or a `temp_url` into the session: both expire, so a segment decodes to a `satori:` route
|
|
5
|
+
* of this bot (`/resources/:resourceId`, `/files/:scene/:peer/:fileId`) that the host fetches when it needs the bytes.
|
|
6
|
+
*/
|
|
7
|
+
import { h, normalize, } from '@deepseek-ai/cordis-plugin-im-core';
|
|
8
|
+
import { chatRefOf, fileSceneToken, messageIdOf, reactionEventId, recallEventId, } from "./ids.js";
|
|
9
|
+
/**
|
|
10
|
+
* Decode one event frame into a session.
|
|
11
|
+
*
|
|
12
|
+
* Only `message_receive`, `message_recall` and `group_message_reaction` have DSH consumers; every other event is left
|
|
13
|
+
* for the transport to log at debug level.
|
|
14
|
+
*
|
|
15
|
+
* @param bot - receiving bot (`selfId` decides `mentions.self`, the platform prefix names internal routes).
|
|
16
|
+
* @param event - one decoded protocol event.
|
|
17
|
+
* @returns the session, or `undefined` for an event this adapter does not surface.
|
|
18
|
+
*/
|
|
19
|
+
export function decodeFrame(bot, event) {
|
|
20
|
+
switch (event.event_type) {
|
|
21
|
+
case 'message_receive': {
|
|
22
|
+
const message = decodeMessage(bot, event.data);
|
|
23
|
+
return bot.session({
|
|
24
|
+
type: 'message',
|
|
25
|
+
id: message.id,
|
|
26
|
+
timestamp: message.time,
|
|
27
|
+
message,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
case 'message_recall': {
|
|
31
|
+
const { message_scene, peer_id, message_seq, operator_id } = event.data;
|
|
32
|
+
return bot.session({
|
|
33
|
+
type: 'message-deleted',
|
|
34
|
+
id: recallEventId(message_scene, peer_id, message_seq),
|
|
35
|
+
timestamp: event.time * 1000,
|
|
36
|
+
deleted: {
|
|
37
|
+
id: messageIdOf(message_scene, peer_id, message_seq),
|
|
38
|
+
chat: chatRefOf(message_scene, peer_id),
|
|
39
|
+
operator: { id: String(operator_id) },
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
case 'group_message_reaction': {
|
|
44
|
+
const { group_id, message_seq, user_id, reaction_type, face_id, is_add } = event.data;
|
|
45
|
+
return bot.session({
|
|
46
|
+
type: is_add ? 'reaction-added' : 'reaction-removed',
|
|
47
|
+
id: reactionEventId(group_id, message_seq, user_id, reaction_type, face_id, is_add),
|
|
48
|
+
timestamp: event.time * 1000,
|
|
49
|
+
reaction: {
|
|
50
|
+
message: {
|
|
51
|
+
id: messageIdOf('group', group_id, message_seq),
|
|
52
|
+
chat: chatRefOf('group', group_id),
|
|
53
|
+
},
|
|
54
|
+
// The same `<reaction_type>|<reaction_id>` spelling `createReaction` parses back.
|
|
55
|
+
emoji: `${reaction_type}|${face_id}`,
|
|
56
|
+
user: { id: String(user_id) },
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
default:
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Decode one received message.
|
|
66
|
+
*
|
|
67
|
+
* @param bot - receiving bot.
|
|
68
|
+
* @param input - `IncomingMessage` of the event (or of a `get_message` answer).
|
|
69
|
+
* @returns the inbound message; its content is never empty.
|
|
70
|
+
*/
|
|
71
|
+
export function decodeMessage(bot, input) {
|
|
72
|
+
const scene = input.message_scene;
|
|
73
|
+
const chat = chatOf(input);
|
|
74
|
+
const segments = input.segments;
|
|
75
|
+
const mentions = {
|
|
76
|
+
self: false,
|
|
77
|
+
all: false,
|
|
78
|
+
users: [],
|
|
79
|
+
};
|
|
80
|
+
const nodes = [];
|
|
81
|
+
let quote;
|
|
82
|
+
for (const segment of segments) {
|
|
83
|
+
if (segment.type === 'reply') {
|
|
84
|
+
quote = decodeQuote(bot, input, segment.data);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
nodes.push(...segmentNodes(bot, scene, input.peer_id, segment, mentions, 'element'));
|
|
88
|
+
}
|
|
89
|
+
const message = {
|
|
90
|
+
id: messageIdOf(scene, input.peer_id, input.message_seq),
|
|
91
|
+
chat,
|
|
92
|
+
sender: senderOf(input),
|
|
93
|
+
content: decodeContent(input, nodes),
|
|
94
|
+
mentions,
|
|
95
|
+
time: input.time * 1000,
|
|
96
|
+
referrer: referrerOf(input),
|
|
97
|
+
...(quote === undefined ? {} : { quote }),
|
|
98
|
+
};
|
|
99
|
+
return message;
|
|
100
|
+
}
|
|
101
|
+
/** The chat a message names (`group:…` / `private:…` / `temporary:…`), with its display name when the event has one. */
|
|
102
|
+
function chatOf(input) {
|
|
103
|
+
switch (input.message_scene) {
|
|
104
|
+
case 'group':
|
|
105
|
+
return chatRefOf('group', input.peer_id, input.group.group_name);
|
|
106
|
+
case 'friend':
|
|
107
|
+
return chatRefOf('friend', input.peer_id, input.friend.nickname);
|
|
108
|
+
case 'temp':
|
|
109
|
+
return chatRefOf('temp', input.peer_id);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** The sender, with the group card preferred over the account nickname and the group role when known. */
|
|
113
|
+
function senderOf(input) {
|
|
114
|
+
const id = String(input.sender_id);
|
|
115
|
+
switch (input.message_scene) {
|
|
116
|
+
case 'group': {
|
|
117
|
+
const member = input.group_member;
|
|
118
|
+
const name = member.card || member.nickname;
|
|
119
|
+
return { id, ...(name === '' ? {} : { name }), role: member.role };
|
|
120
|
+
}
|
|
121
|
+
case 'friend': {
|
|
122
|
+
const name = input.friend.nickname;
|
|
123
|
+
return { id, ...(name === '' ? {} : { name }) };
|
|
124
|
+
}
|
|
125
|
+
case 'temp':
|
|
126
|
+
return { id };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** The reply context: the quoted message is always in the same conversation as the reply. */
|
|
130
|
+
function referrerOf(input) {
|
|
131
|
+
return {
|
|
132
|
+
scene: input.message_scene,
|
|
133
|
+
peerId: input.peer_id,
|
|
134
|
+
messageSeq: input.message_seq,
|
|
135
|
+
senderId: input.sender_id,
|
|
136
|
+
time: input.time,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Normalize the decoded segments, falling back to the raw payload when nothing rendered.
|
|
141
|
+
*
|
|
142
|
+
* @param input - the message the segments belong to.
|
|
143
|
+
* @param nodes - nodes the segment decoder produced.
|
|
144
|
+
* @returns non-empty content.
|
|
145
|
+
*/
|
|
146
|
+
function decodeContent(input, nodes) {
|
|
147
|
+
const content = normalize(nodes);
|
|
148
|
+
if (content.children.length > 0)
|
|
149
|
+
return content;
|
|
150
|
+
// `content` is never empty: a message whose segments all decode to nothing (or that carries only an unsupported
|
|
151
|
+
// segment) keeps its raw payload so the host can still show that something arrived.
|
|
152
|
+
return normalize([
|
|
153
|
+
h('raw', { platform: 'milky', type: 'message', data: input }),
|
|
154
|
+
]);
|
|
155
|
+
}
|
|
156
|
+
/** One `reply` segment → the quoted message; its `segments` are used when the endpoint sent them (Milky ≥ 1.2). */
|
|
157
|
+
function decodeQuote(bot, input, data) {
|
|
158
|
+
const id = messageIdOf(input.message_scene, input.peer_id, data.message_seq);
|
|
159
|
+
const sender = {
|
|
160
|
+
id: String(data.sender_id),
|
|
161
|
+
...(data.sender_name === undefined ||
|
|
162
|
+
data.sender_name === null ||
|
|
163
|
+
data.sender_name === ''
|
|
164
|
+
? {}
|
|
165
|
+
: { name: data.sender_name }),
|
|
166
|
+
};
|
|
167
|
+
const segments = data.segments;
|
|
168
|
+
if (!Array.isArray(segments) || segments.length === 0)
|
|
169
|
+
return { id, sender };
|
|
170
|
+
const mentions = {
|
|
171
|
+
self: false,
|
|
172
|
+
all: false,
|
|
173
|
+
users: [],
|
|
174
|
+
};
|
|
175
|
+
const nodes = [];
|
|
176
|
+
for (const segment of segments) {
|
|
177
|
+
// A reply inside a quoted message would recurse without end; the quote of a quote is not part of its content.
|
|
178
|
+
if (segment.type === 'reply')
|
|
179
|
+
continue;
|
|
180
|
+
nodes.push(...segmentNodes(bot, input.message_scene, input.peer_id, segment, mentions, 'element'));
|
|
181
|
+
}
|
|
182
|
+
const content = normalize(nodes);
|
|
183
|
+
if (content.children.length === 0)
|
|
184
|
+
return { id, sender };
|
|
185
|
+
return { id, sender, content };
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Map one segment to elements.
|
|
189
|
+
*
|
|
190
|
+
* @param bot - receiving bot, used for internal media routes and `mentions.self`.
|
|
191
|
+
* @param scene - scene of the message the segment belongs to.
|
|
192
|
+
* @param peerId - peer of that message.
|
|
193
|
+
* @param segment - one incoming segment.
|
|
194
|
+
* @param mentions - accumulator of the message's mention facts.
|
|
195
|
+
* @param forwardStyle - how a merged forward segment renders.
|
|
196
|
+
* @returns the elements of the segment (possibly none).
|
|
197
|
+
*/
|
|
198
|
+
function segmentNodes(bot, scene, peerId, segment, mentions, forwardStyle) {
|
|
199
|
+
switch (segment.type) {
|
|
200
|
+
case 'text':
|
|
201
|
+
return [h('text', { content: segment.data.text })];
|
|
202
|
+
case 'mention': {
|
|
203
|
+
const id = String(segment.data.user_id);
|
|
204
|
+
const name = segment.data.name;
|
|
205
|
+
if (!mentions.users.some((user) => user.id === id)) {
|
|
206
|
+
mentions.users.push({ id, ...(name === '' ? {} : { name }) });
|
|
207
|
+
}
|
|
208
|
+
if (id === bot.selfId)
|
|
209
|
+
mentions.self = true;
|
|
210
|
+
return [h('at', { type: 'user', id, ...(name === '' ? {} : { name }) })];
|
|
211
|
+
}
|
|
212
|
+
case 'mention_all':
|
|
213
|
+
mentions.all = true;
|
|
214
|
+
return [h('at', { type: 'all' })];
|
|
215
|
+
case 'image':
|
|
216
|
+
return [
|
|
217
|
+
h('img', {
|
|
218
|
+
src: resourceRoute(bot, segment.data.resource_id),
|
|
219
|
+
width: segment.data.width,
|
|
220
|
+
height: segment.data.height,
|
|
221
|
+
}),
|
|
222
|
+
];
|
|
223
|
+
case 'record':
|
|
224
|
+
return [
|
|
225
|
+
h('audio', {
|
|
226
|
+
src: resourceRoute(bot, segment.data.resource_id),
|
|
227
|
+
duration: segment.data.duration,
|
|
228
|
+
}),
|
|
229
|
+
];
|
|
230
|
+
case 'video':
|
|
231
|
+
return [
|
|
232
|
+
h('video', {
|
|
233
|
+
src: resourceRoute(bot, segment.data.resource_id),
|
|
234
|
+
duration: segment.data.duration,
|
|
235
|
+
}),
|
|
236
|
+
];
|
|
237
|
+
case 'file':
|
|
238
|
+
return [fileElement(bot, scene, peerId, segment.data)];
|
|
239
|
+
case 'face':
|
|
240
|
+
return [h('emoji', { id: segment.data.face_id, name: '[表情]' })];
|
|
241
|
+
case 'market_face':
|
|
242
|
+
return segment.data.url === ''
|
|
243
|
+
? [h('text', { content: '[表情]' })]
|
|
244
|
+
: [h('img', { src: segment.data.url })];
|
|
245
|
+
case 'forward':
|
|
246
|
+
return forwardStyle === 'text'
|
|
247
|
+
? [h('text', { content: `[合并转发 #${segment.data.forward_id}]` })]
|
|
248
|
+
: [h('forward', { id: segment.data.forward_id })];
|
|
249
|
+
case 'light_app':
|
|
250
|
+
return [
|
|
251
|
+
h('raw', { platform: 'milky', type: 'light_app', data: segment.data }),
|
|
252
|
+
];
|
|
253
|
+
case 'xml':
|
|
254
|
+
return [h('raw', { platform: 'milky', type: 'xml', data: segment.data })];
|
|
255
|
+
case 'markdown':
|
|
256
|
+
return [h('text', { content: segment.data.content })];
|
|
257
|
+
default: {
|
|
258
|
+
// A segment type a newer endpoint added: the compatibility policy is to show text, never to drop the frame.
|
|
259
|
+
const unknown = segment;
|
|
260
|
+
const type = typeof unknown.type === 'string' ? unknown.type : 'unknown';
|
|
261
|
+
return [h('text', { content: `[不支持的${type}消息]` })];
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/** Internal route of one message resource (`resource_id` is stable; `temp_url` is not). */
|
|
266
|
+
function resourceRoute(bot, resourceId) {
|
|
267
|
+
return bot.getInternalUrl(`/resources/${encodeURIComponent(resourceId)}`);
|
|
268
|
+
}
|
|
269
|
+
/** An inbound file, routed through the `/files/:scene/:peer/:fileId` internal route (with its hash when private). */
|
|
270
|
+
function fileElement(bot, scene, peerId, data) {
|
|
271
|
+
const hash = data.file_hash;
|
|
272
|
+
return h('file', {
|
|
273
|
+
src: bot.getInternalUrl(`/files/${fileSceneToken(scene)}/${peerId}/${encodeURIComponent(data.file_id)}`, hash === undefined || hash === null || hash === '' ? undefined : { hash }),
|
|
274
|
+
name: data.file_name,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/decode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAIL,CAAC,EAED,SAAS,GAGV,MAAM,oCAAoC,CAAA;AAE3C,OAAO,EACL,SAAS,EACT,cAAc,EACd,WAAW,EAEX,eAAe,EACf,aAAa,GACd,MAAM,UAAU,CAAA;A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;AACH,CAAC;AAED,2FAA2F;AAC3F,SAAS,aAAa,CAAC,GAAa,EAAE,UAAkB;IACtD,OAAO,GAAG,CAAC,cAAc,CAAC,cAAc,kBAAkB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;AAC3E,CAAC;AAED,qHAAqH;AACrH,SAAS,WAAW,CAClB,GAAa,EACb,KAAiB,EACjB,MAAc,EACd,IAA6B;IAE7B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAA;IAC3B,OAAO,CAAC,CAAC,MAAM,EAAE;QACf,GAAG,EAAE,GAAG,CAAC,cAAc,CACrB,UAAU,cAAc,CAAC,KAAK,CAAC,IAAI,MAAM,IAAI,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,EAC/E,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAC1E;QACD,IAAI,EAAE,IAAI,CAAC,SAAS;KACrB,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Milky failures and their mapping onto the core platform taxonomy.
|
|
3
|
+
*
|
|
4
|
+
* `MilkyApiError` carries the facts the classification table of the design needs: the API name, the HTTP status, the
|
|
5
|
+
* protocol envelope status and retcode, and whether the call reached the protocol endpoint at all.
|
|
6
|
+
*/
|
|
7
|
+
import { PlatformError } from '@deepseek-ai/cordis-plugin-im-core';
|
|
8
|
+
/** A configuration value that can never work (bad `endpoint`, bad `selfId`). */
|
|
9
|
+
export declare class MilkyConfigError extends Error {
|
|
10
|
+
name: string;
|
|
11
|
+
/**
|
|
12
|
+
* @param message - what is wrong with the configuration.
|
|
13
|
+
* @param options - the caught cause, when any.
|
|
14
|
+
*/
|
|
15
|
+
constructor(message: string, options?: {
|
|
16
|
+
cause?: unknown;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The protocol endpoint is logged into a different account than the configured `selfId`.
|
|
21
|
+
*
|
|
22
|
+
* Runtime permanent: retrying cannot fix a misconfigured endpoint, and continuing would admit another account's events.
|
|
23
|
+
*/
|
|
24
|
+
export declare class MilkyIdentityError extends Error {
|
|
25
|
+
name: string;
|
|
26
|
+
/**
|
|
27
|
+
* @param message - which account was expected and which one answered.
|
|
28
|
+
*/
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
/** Fields of one failed Milky API call. */
|
|
32
|
+
export interface MilkyApiErrorInit {
|
|
33
|
+
/** API name (`send_group_message`). */
|
|
34
|
+
api: string;
|
|
35
|
+
/** HTTP status of the answer. */
|
|
36
|
+
httpStatus?: number;
|
|
37
|
+
/** Protocol envelope status, when the body carried a parsable one. */
|
|
38
|
+
status?: 'ok' | 'failed';
|
|
39
|
+
/** Protocol retcode (`-400`, `-403`, `-404`, …). */
|
|
40
|
+
retcode?: number;
|
|
41
|
+
cause?: unknown;
|
|
42
|
+
}
|
|
43
|
+
/** One failed Milky API call. */
|
|
44
|
+
export declare class MilkyApiError extends Error {
|
|
45
|
+
name: string;
|
|
46
|
+
readonly api: string;
|
|
47
|
+
readonly httpStatus: number | undefined;
|
|
48
|
+
readonly status: 'ok' | 'failed' | undefined;
|
|
49
|
+
readonly retcode: number | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* @param message - human-readable failure, already carrying the API name.
|
|
52
|
+
* @param init - what the call observed.
|
|
53
|
+
*/
|
|
54
|
+
constructor(message: string, init: MilkyApiErrorInit);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Map any failure onto the core platform taxonomy.
|
|
58
|
+
*
|
|
59
|
+
* HTTP 401 / 404 / 415 and every `status: 'failed'` answer are refusals of a request the endpoint understood, so
|
|
60
|
+
* nothing was published; a 5xx, a transport failure or a 2xx answer that cannot be parsed leaves the outcome unknown.
|
|
61
|
+
*
|
|
62
|
+
* @param error - the caught failure.
|
|
63
|
+
* @returns the classified platform error.
|
|
64
|
+
*/
|
|
65
|
+
export declare function classifyMilkyError(error: unknown): PlatformError;
|
|
66
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAElE,gFAAgF;AAChF,qBAAa,gBAAiB,SAAQ,KAAK;IAChC,IAAI,SAAqB;IAElC;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAM3D;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAClC,IAAI,SAAuB;IAEpC;;OAEG;gBACS,OAAO,EAAE,MAAM;CAG5B;AAED,2CAA2C;AAC3C,MAAM,WAAW,iBAAiB;IAChC,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAA;IACX,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,sEAAsE;IACtE,MAAM,CAAC,EAAE,IAAI,GAAG,QAAQ,CAAA;IACxB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,iCAAiC;AACjC,qBAAa,aAAc,SAAQ,KAAK;IAC7B,IAAI,SAAkB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IACvC,QAAQ,CAAC,MAAM,EAAE,IAAI,GAAG,QAAQ,GAAG,SAAS,CAAA;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAEpC;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB;CAOrD;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAsGhE"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Milky failures and their mapping onto the core platform taxonomy.
|
|
3
|
+
*
|
|
4
|
+
* `MilkyApiError` carries the facts the classification table of the design needs: the API name, the HTTP status, the
|
|
5
|
+
* protocol envelope status and retcode, and whether the call reached the protocol endpoint at all.
|
|
6
|
+
*/
|
|
7
|
+
import { PlatformError } from '@deepseek-ai/cordis-plugin-im-core';
|
|
8
|
+
/** A configuration value that can never work (bad `endpoint`, bad `selfId`). */
|
|
9
|
+
export class MilkyConfigError extends Error {
|
|
10
|
+
name = 'MilkyConfigError';
|
|
11
|
+
/**
|
|
12
|
+
* @param message - what is wrong with the configuration.
|
|
13
|
+
* @param options - the caught cause, when any.
|
|
14
|
+
*/
|
|
15
|
+
constructor(message, options) {
|
|
16
|
+
super(message, options?.cause === undefined ? undefined : { cause: options.cause });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The protocol endpoint is logged into a different account than the configured `selfId`.
|
|
21
|
+
*
|
|
22
|
+
* Runtime permanent: retrying cannot fix a misconfigured endpoint, and continuing would admit another account's events.
|
|
23
|
+
*/
|
|
24
|
+
export class MilkyIdentityError extends Error {
|
|
25
|
+
name = 'MilkyIdentityError';
|
|
26
|
+
/**
|
|
27
|
+
* @param message - which account was expected and which one answered.
|
|
28
|
+
*/
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super(message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** One failed Milky API call. */
|
|
34
|
+
export class MilkyApiError extends Error {
|
|
35
|
+
name = 'MilkyApiError';
|
|
36
|
+
api;
|
|
37
|
+
httpStatus;
|
|
38
|
+
status;
|
|
39
|
+
retcode;
|
|
40
|
+
/**
|
|
41
|
+
* @param message - human-readable failure, already carrying the API name.
|
|
42
|
+
* @param init - what the call observed.
|
|
43
|
+
*/
|
|
44
|
+
constructor(message, init) {
|
|
45
|
+
super(message, init.cause === undefined ? undefined : { cause: init.cause });
|
|
46
|
+
this.api = init.api;
|
|
47
|
+
this.httpStatus = init.httpStatus;
|
|
48
|
+
this.status = init.status;
|
|
49
|
+
this.retcode = init.retcode;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Map any failure onto the core platform taxonomy.
|
|
54
|
+
*
|
|
55
|
+
* HTTP 401 / 404 / 415 and every `status: 'failed'` answer are refusals of a request the endpoint understood, so
|
|
56
|
+
* nothing was published; a 5xx, a transport failure or a 2xx answer that cannot be parsed leaves the outcome unknown.
|
|
57
|
+
*
|
|
58
|
+
* @param error - the caught failure.
|
|
59
|
+
* @returns the classified platform error.
|
|
60
|
+
*/
|
|
61
|
+
export function classifyMilkyError(error) {
|
|
62
|
+
if (error instanceof PlatformError)
|
|
63
|
+
return error;
|
|
64
|
+
if (error instanceof MilkyApiError) {
|
|
65
|
+
const code = error.retcode ?? error.httpStatus;
|
|
66
|
+
const init = {
|
|
67
|
+
...(code === undefined ? {} : { code }),
|
|
68
|
+
cause: error,
|
|
69
|
+
};
|
|
70
|
+
const httpStatus = error.httpStatus;
|
|
71
|
+
if (httpStatus === undefined) {
|
|
72
|
+
// The call never reached the endpoint (dial failure, timeout, reset): whether it ran is unknowable.
|
|
73
|
+
return new PlatformError('retryable', error.message, {
|
|
74
|
+
...init,
|
|
75
|
+
published: 'unknown',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (httpStatus < 200 || httpStatus >= 300) {
|
|
79
|
+
if (httpStatus === 401)
|
|
80
|
+
return new PlatformError('permission', error.message, {
|
|
81
|
+
...init,
|
|
82
|
+
published: 'no',
|
|
83
|
+
});
|
|
84
|
+
if (httpStatus === 404)
|
|
85
|
+
return new PlatformError('fatal', error.message, {
|
|
86
|
+
...init,
|
|
87
|
+
published: 'no',
|
|
88
|
+
});
|
|
89
|
+
if (httpStatus === 415)
|
|
90
|
+
return new PlatformError('fatal', error.message, {
|
|
91
|
+
...init,
|
|
92
|
+
published: 'no',
|
|
93
|
+
});
|
|
94
|
+
if (httpStatus >= 500)
|
|
95
|
+
return new PlatformError('retryable', error.message, {
|
|
96
|
+
...init,
|
|
97
|
+
published: 'unknown',
|
|
98
|
+
});
|
|
99
|
+
if (httpStatus >= 400)
|
|
100
|
+
return new PlatformError('invalid', error.message, {
|
|
101
|
+
...init,
|
|
102
|
+
published: 'no',
|
|
103
|
+
});
|
|
104
|
+
// 1xx/3xx: the request did not reach the API the way it was meant to; whether it ran is unknowable.
|
|
105
|
+
return new PlatformError('retryable', error.message, {
|
|
106
|
+
...init,
|
|
107
|
+
published: 'unknown',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (error.status === 'failed') {
|
|
111
|
+
switch (error.retcode) {
|
|
112
|
+
case -400:
|
|
113
|
+
return new PlatformError('invalid', error.message, {
|
|
114
|
+
...init,
|
|
115
|
+
published: 'no',
|
|
116
|
+
});
|
|
117
|
+
case -403:
|
|
118
|
+
return new PlatformError('permission', error.message, {
|
|
119
|
+
...init,
|
|
120
|
+
published: 'no',
|
|
121
|
+
});
|
|
122
|
+
case -404:
|
|
123
|
+
return new PlatformError('not-found', error.message, {
|
|
124
|
+
...init,
|
|
125
|
+
published: 'no',
|
|
126
|
+
});
|
|
127
|
+
default:
|
|
128
|
+
// The specification fixes only -400 and -403; every other retcode is the endpoint's own refusal.
|
|
129
|
+
return new PlatformError('invalid', error.message, {
|
|
130
|
+
...init,
|
|
131
|
+
published: 'no',
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// A 2xx answer without a usable envelope: the endpoint processed the call, the receipt is incomplete.
|
|
136
|
+
return new PlatformError('invalid', error.message, {
|
|
137
|
+
...init,
|
|
138
|
+
published: 'unknown',
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (error instanceof MilkyConfigError) {
|
|
142
|
+
return new PlatformError('fatal', error.message, {
|
|
143
|
+
published: 'no',
|
|
144
|
+
cause: error,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (error instanceof MilkyIdentityError) {
|
|
148
|
+
return new PlatformError('permission', error.message, {
|
|
149
|
+
published: 'no',
|
|
150
|
+
cause: error,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (isAbortError(error)) {
|
|
154
|
+
return new PlatformError('fatal', error.message, {
|
|
155
|
+
published: 'unknown',
|
|
156
|
+
cause: error,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
160
|
+
return new PlatformError('retryable', `milky request failed: ${message}`, {
|
|
161
|
+
published: 'unknown',
|
|
162
|
+
cause: error,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/** Whether a caught value is an abort, including the `DOMException` an aborted signal produces. */
|
|
166
|
+
function isAbortError(error) {
|
|
167
|
+
return ((error instanceof Error || error instanceof DOMException) &&
|
|
168
|
+
error.name === 'AbortError');
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAElE,gFAAgF;AAChF,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,IAAI,GAAG,kBAAkB,CAAA;IAElC;;;OAGG;IACH,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CACH,OAAO,EACP,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CACpE,CAAA;IACH,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK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,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;YAC/C,SAAS,EAAE,SAAS;YACpB,KAAK,EAAE,KAAK;SACb,CAAC,CAAA;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACtE,OAAO,IAAI,aAAa,CAAC,WAAW,EAAE,yBAAyB,OAAO,EAAE,EAAE;QACxE,SAAS,EAAE,SAAS;QACpB,KAAK,EAAE,KAAK;KACb,CAAC,CAAA;AACJ,CAAC;AAED,mGAAmG;AACnG,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,CACL,CAAC,KAAK,YAAY,KAAK,IAAI,KAAK,YAAY,YAAY,CAAC;QACzD,KAAK,CAAC,IAAI,KAAK,YAAY,CAC5B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Bot identity: `get_login_info` must name the configured QQ account, and the endpoint version is reported, not trusted. */
|
|
2
|
+
import type { User } from '@deepseek-ai/cordis-plugin-im-core';
|
|
3
|
+
import type { GetImplInfoOutput, GetLoginInfoOutput } from './types/schema.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Verify a `get_login_info` answer against the configured account.
|
|
6
|
+
* @param selfId - configured QQ number.
|
|
7
|
+
* @param login - `get_login_info` result.
|
|
8
|
+
* @returns the bot's own user.
|
|
9
|
+
* @throws MilkyIdentityError when the endpoint is logged into another account.
|
|
10
|
+
*/
|
|
11
|
+
export declare function verifyIdentity(selfId: string, login: GetLoginInfoOutput): User;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the endpoint implements the Milky major version this adapter targets.
|
|
14
|
+
* @param version - `milky_version` of `get_impl_info`.
|
|
15
|
+
* @returns true for a `1.x` implementation.
|
|
16
|
+
*/
|
|
17
|
+
export declare function implementsMilky1(version: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Describe one `get_impl_info` answer for a warning about an unexpected version.
|
|
20
|
+
* @param info - `get_impl_info` result.
|
|
21
|
+
* @returns the diagnostic line.
|
|
22
|
+
*/
|
|
23
|
+
export declare function versionWarning(info: GetImplInfoOutput): string;
|
|
24
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAAA,6HAA6H;AAE7H,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAA;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE9E;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,kBAAkB,GACxB,IAAI,CAQN;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAE9D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Bot identity: `get_login_info` must name the configured QQ account, and the endpoint version is reported, not trusted. */
|
|
2
|
+
import { MilkyIdentityError } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Verify a `get_login_info` answer against the configured account.
|
|
5
|
+
* @param selfId - configured QQ number.
|
|
6
|
+
* @param login - `get_login_info` result.
|
|
7
|
+
* @returns the bot's own user.
|
|
8
|
+
* @throws MilkyIdentityError when the endpoint is logged into another account.
|
|
9
|
+
*/
|
|
10
|
+
export function verifyIdentity(selfId, login) {
|
|
11
|
+
const actual = String(login.uin);
|
|
12
|
+
if (actual !== selfId) {
|
|
13
|
+
throw new MilkyIdentityError(`milky: the endpoint is logged into account ${actual}, but this adapter is configured for ${selfId}`);
|
|
14
|
+
}
|
|
15
|
+
return { id: actual, name: login.nickname };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Whether the endpoint implements the Milky major version this adapter targets.
|
|
19
|
+
* @param version - `milky_version` of `get_impl_info`.
|
|
20
|
+
* @returns true for a `1.x` implementation.
|
|
21
|
+
*/
|
|
22
|
+
export function implementsMilky1(version) {
|
|
23
|
+
return /^1\./.test(version);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Describe one `get_impl_info` answer for a warning about an unexpected version.
|
|
27
|
+
* @param info - `get_impl_info` result.
|
|
28
|
+
* @returns the diagnostic line.
|
|
29
|
+
*/
|
|
30
|
+
export function versionWarning(info) {
|
|
31
|
+
return `milky: the endpoint implements Milky ${info.milky_version} (${info.impl_name} ${info.impl_version}); this adapter targets 1.x`;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAAA,6HAA6H;AAG7H,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGhD;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAc,EACd,KAAyB;IAEzB,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAChC,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,MAAM,IAAI,kBAAkB,CAC1B,8CAA8C,MAAM,wCAAwC,MAAM,EAAE,CACrG,CAAA;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAA;AAC7C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAC7B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAuB;IACpD,OAAO,wCAAwC,IAAI,CAAC,aAAa,KAAK,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,YAAY,6BAA6B,CAAA;AACxI,CAAC"}
|