@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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/cordis.patch.yml +11 -0
  3. package/lib/index.js +2311 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/types/bot.d.ts +127 -0
  6. package/lib/types/bot.d.ts.map +1 -0
  7. package/lib/types/bot.js +303 -0
  8. package/lib/types/bot.js.map +1 -0
  9. package/lib/types/config.d.ts +24 -0
  10. package/lib/types/config.d.ts.map +1 -0
  11. package/lib/types/config.js +39 -0
  12. package/lib/types/config.js.map +1 -0
  13. package/lib/types/decode.d.ts +43 -0
  14. package/lib/types/decode.d.ts.map +1 -0
  15. package/lib/types/decode.js +277 -0
  16. package/lib/types/decode.js.map +1 -0
  17. package/lib/types/errors.d.ts +66 -0
  18. package/lib/types/errors.d.ts.map +1 -0
  19. package/lib/types/errors.js +170 -0
  20. package/lib/types/errors.js.map +1 -0
  21. package/lib/types/identity.d.ts +24 -0
  22. package/lib/types/identity.d.ts.map +1 -0
  23. package/lib/types/identity.js +33 -0
  24. package/lib/types/identity.js.map +1 -0
  25. package/lib/types/ids.d.ts +110 -0
  26. package/lib/types/ids.d.ts.map +1 -0
  27. package/lib/types/ids.js +166 -0
  28. package/lib/types/ids.js.map +1 -0
  29. package/lib/types/index.d.ts +10 -0
  30. package/lib/types/index.d.ts.map +1 -0
  31. package/lib/types/index.js +9 -0
  32. package/lib/types/index.js.map +1 -0
  33. package/lib/types/internal.d.ts +2002 -0
  34. package/lib/types/internal.d.ts.map +1 -0
  35. package/lib/types/internal.js +408 -0
  36. package/lib/types/internal.js.map +1 -0
  37. package/lib/types/modes/text.d.ts +66 -0
  38. package/lib/types/modes/text.d.ts.map +1 -0
  39. package/lib/types/modes/text.js +275 -0
  40. package/lib/types/modes/text.js.map +1 -0
  41. package/lib/types/reads.d.ts +57 -0
  42. package/lib/types/reads.d.ts.map +1 -0
  43. package/lib/types/reads.js +219 -0
  44. package/lib/types/reads.js.map +1 -0
  45. package/lib/types/request.d.ts +55 -0
  46. package/lib/types/request.d.ts.map +1 -0
  47. package/lib/types/request.js +174 -0
  48. package/lib/types/request.js.map +1 -0
  49. package/lib/types/send.d.ts +34 -0
  50. package/lib/types/send.d.ts.map +1 -0
  51. package/lib/types/send.js +99 -0
  52. package/lib/types/send.js.map +1 -0
  53. package/lib/types/types/schema.d.ts +11726 -0
  54. package/lib/types/types/schema.d.ts.map +1 -0
  55. package/lib/types/types/schema.js +1422 -0
  56. package/lib/types/types/schema.js.map +1 -0
  57. package/lib/types/ws.d.ts +60 -0
  58. package/lib/types/ws.d.ts.map +1 -0
  59. package/lib/types/ws.js +335 -0
  60. package/lib/types/ws.js.map +1 -0
  61. package/package.json +62 -3
  62. package/src/bot.ts +431 -0
  63. package/src/config.ts +61 -0
  64. package/src/decode.ts +367 -0
  65. package/src/errors.ts +195 -0
  66. package/src/identity.ts +43 -0
  67. package/src/ids.ts +226 -0
  68. package/src/index.ts +44 -0
  69. package/src/internal.ts +657 -0
  70. package/src/modes/text.ts +368 -0
  71. package/src/reads.ts +315 -0
  72. package/src/request.ts +230 -0
  73. package/src/send.ts +175 -0
  74. package/src/types/schema.ts +1827 -0
  75. package/src/ws.ts +383 -0
  76. package/README.md +0 -3
@@ -0,0 +1,275 @@
1
+ /**
2
+ * The one `text` mode: a Milky message is a JSON array of segments, so there is no markup dialect to choose between.
3
+ *
4
+ * The mode collects the segments of one logical message. Text, mentions and media ride one `send_*_message` request;
5
+ * a `<file>` cannot be a segment (Milky's `OutgoingSegment` has no file type) and becomes its own draft, uploaded to
6
+ * the QQ file area by `sendPayload`.
7
+ */
8
+ import { defineMode, ElementRegistry, PlatformError, } from '@deepseek-ai/cordis-plugin-im-core';
9
+ import { decodeChatId, decodeFilePartId, decodeMessageId, idNamesChat, } from "../ids.js";
10
+ /** Register `text`, `p` and `br` (the mandatory base tags) plus every element Milky can render natively. */
11
+ function buildRegistry() {
12
+ return (new ElementRegistry()
13
+ .register('text', (el) => ({ type: 'text', text: el.attrs.content }))
14
+ .register('p', (el, ctx) => [
15
+ ...ctx.render(el.children),
16
+ { type: 'text', text: '\n' },
17
+ ])
18
+ .register('br', () => ({ type: 'text', text: '\n' }))
19
+ // `at[type=user]` must stay native: the `im` system prompt asks the model to notify people with `<at user_id>`,
20
+ // and a fallback would silently turn every mention into plain text. A non-numeric id names another platform's
21
+ // user and can only be shown, not notified.
22
+ .register('at', (el) => {
23
+ // The vocabulary makes `type` required, but content in the wild (and the shared corpus) omits it for a user.
24
+ const type = el.attrs.type ?? 'user';
25
+ const { id, name } = el.attrs;
26
+ if (type === 'all')
27
+ return { type: 'mention_all' };
28
+ if (type === 'user' && id !== undefined && /^\d+$/.test(id))
29
+ return { type: 'mention', userId: id };
30
+ return { type: 'text', text: `@${name ?? id ?? type}` };
31
+ },
32
+ // `here` and `role` are not declared: Milky has no segment for them and core's fallback renders text.
33
+ { variants: ['user', 'all'] })
34
+ .register('img', (el, ctx) => ({
35
+ type: 'media',
36
+ kind: 'image',
37
+ ref: ctx.resource('image', el.attrs.src, {
38
+ ...(el.attrs.width === undefined ? {} : { width: el.attrs.width }),
39
+ ...(el.attrs.height === undefined
40
+ ? {}
41
+ : { height: el.attrs.height }),
42
+ }),
43
+ }), { variants: ['inline'] })
44
+ .register('audio', (el, ctx) => ({
45
+ type: 'media',
46
+ kind: 'record',
47
+ ref: ctx.resource('audio', el.attrs.src, {
48
+ ...(el.attrs.duration === undefined
49
+ ? {}
50
+ : { duration: el.attrs.duration }),
51
+ ...(el.attrs.name === undefined ? {} : { name: el.attrs.name }),
52
+ }),
53
+ }))
54
+ .register('video', (el, ctx) => ({
55
+ type: 'media',
56
+ kind: 'video',
57
+ ref: ctx.resource('video', el.attrs.src, {
58
+ ...(el.attrs.duration === undefined
59
+ ? {}
60
+ : { duration: el.attrs.duration }),
61
+ ...(el.attrs.name === undefined ? {} : { name: el.attrs.name }),
62
+ }),
63
+ }))
64
+ // A file cannot be a segment; the handler still produces its own draft, so `assemble` sees the node.
65
+ .register('file', (el, ctx) => ({
66
+ type: 'file',
67
+ ref: ctx.resource('file', el.attrs.src, {
68
+ ...(el.attrs.name === undefined ? {} : { name: el.attrs.name }),
69
+ }),
70
+ }))
71
+ // A Milky text segment has no hyperlink: keep the label and append the target the way the upstream adapter did.
72
+ .fallback('a', (el) => [...el.children, `(${el.attrs.href})`]));
73
+ }
74
+ /** Strip leading and trailing newlines of the message text (a `p` always ends with one) and drop empty text nodes. */
75
+ function trimMessage(draft) {
76
+ const first = draft.segments[0];
77
+ if (first?.type === 'text')
78
+ first.text = first.text.replace(/^\n+/, '');
79
+ const last = draft.segments[draft.segments.length - 1];
80
+ if (last?.type === 'text')
81
+ last.text = last.text.replace(/\n+$/, '');
82
+ for (let index = draft.segments.length - 1; index >= 0; index--) {
83
+ const node = draft.segments[index];
84
+ if (node.type === 'text' && node.text === '')
85
+ draft.segments.splice(index, 1);
86
+ }
87
+ }
88
+ /**
89
+ * Build the `text` mode.
90
+ * @returns the mode (registered under `text`).
91
+ */
92
+ export function createMilkyTextMode() {
93
+ return defineMode()({
94
+ id: 'text',
95
+ elements: buildRegistry(),
96
+ limits: {
97
+ // One logical message uses at most one segment message; each `<file>` goes to the file area instead.
98
+ 'limit.message.parts': 1,
99
+ },
100
+ assemble: (nodes, envelope, ctx) => {
101
+ const drafts = [];
102
+ // A holder keeps the lazy draft visible across the closure without control-flow narrowing the variable.
103
+ const state = {};
104
+ const messageDraft = () => {
105
+ if (state.message === undefined) {
106
+ const draft = { kind: 'message', segments: [] };
107
+ state.message = draft;
108
+ drafts.push(draft);
109
+ }
110
+ return state.message;
111
+ };
112
+ for (const node of nodes) {
113
+ if (node.type === 'file') {
114
+ drafts.push({
115
+ kind: 'file',
116
+ ref: node.ref,
117
+ name: node.ref.meta.name ?? 'file',
118
+ });
119
+ continue;
120
+ }
121
+ const draft = messageDraft();
122
+ if (node.type === 'text') {
123
+ const last = draft.segments[draft.segments.length - 1];
124
+ if (last?.type === 'text')
125
+ last.text += node.text;
126
+ else
127
+ draft.segments.push({ ...node });
128
+ }
129
+ else {
130
+ draft.segments.push(node);
131
+ }
132
+ }
133
+ const message = state.message;
134
+ if (message !== undefined) {
135
+ trimMessage(message);
136
+ }
137
+ attachQuote(state.message, envelope.quote, ctx);
138
+ // No segments at all: return the empty draft so `check` rejects it before any request.
139
+ if (drafts.length === 0)
140
+ drafts.push({ kind: 'message', segments: [] });
141
+ return drafts;
142
+ },
143
+ serialize: (prepared, ctx) => serializeDraft(prepared, ctx),
144
+ check: (draft) => {
145
+ if (draft.kind === 'file')
146
+ return [];
147
+ if (draft.segments.length > 0)
148
+ return [];
149
+ return [
150
+ {
151
+ kind: 'size',
152
+ key: 'limit.elements',
153
+ limit: 1,
154
+ actual: 0,
155
+ message: 'milky: empty message',
156
+ },
157
+ ];
158
+ },
159
+ });
160
+ }
161
+ /**
162
+ * Decide what happens to an envelope `<quote id>`.
163
+ *
164
+ * A quote that parses as a Milky message id or a file part id is kept for {@link serializeDraft}, which owns the
165
+ * chat-membership check and its precise refusal (a quote of another conversation, or a file part that has no
166
+ * sequence, must not be sent here). A quote that is neither cannot have been published by this adapter, so the reply
167
+ * is dropped and reported — the content still sends, and a `strict` send rejects the report.
168
+ *
169
+ * @param message - the segment draft that would carry the reply, if the content produced one.
170
+ * @param quote - the quoted platform message id.
171
+ * @param ctx - render context (target chat and report).
172
+ */
173
+ function attachQuote(message, quote, ctx) {
174
+ if (quote === undefined)
175
+ return;
176
+ if (message === undefined) {
177
+ // A reply can only ride a segment message, and this content produced none.
178
+ ctx.report.dropped.push({ what: 'quote', reason: 'milky-file-only' });
179
+ return;
180
+ }
181
+ if (decodeMessageId(quote) === undefined &&
182
+ decodeFilePartId(quote) === undefined) {
183
+ ctx.report.dropped.push({
184
+ what: 'quote',
185
+ reason: 'milky-quote-unparseable',
186
+ });
187
+ return;
188
+ }
189
+ message.replyTo = quote;
190
+ }
191
+ /** Resolved URI of one resource; a draft reaching serialize unprepared is an adapter bug. */
192
+ function resolvedKey(prepared, ref) {
193
+ const resolved = prepared.resolved.get(ref);
194
+ if (resolved === undefined) {
195
+ throw new PlatformError('invalid', `milky: ${ref.kind} "${ref.src}" was not prepared before serialize`, {
196
+ published: 'no',
197
+ });
198
+ }
199
+ return resolved.key;
200
+ }
201
+ /** Sequence of the quoted message, which must belong to the chat the payload goes to. */
202
+ function replySeqOf(replyTo, chatId) {
203
+ if (decodeFilePartId(replyTo) !== undefined) {
204
+ throw new PlatformError('invalid', `milky: "${replyTo}" is a file part id, not a message, and cannot be quoted`, { published: 'no' });
205
+ }
206
+ const decoded = decodeMessageId(replyTo);
207
+ const chat = decodeChatId(chatId);
208
+ if (decoded === undefined ||
209
+ !idNamesChat(decoded.scene, decoded.peerId, chat)) {
210
+ throw new PlatformError('invalid', `milky: quoted message "${replyTo}" is not a message of chat "${chatId}" and cannot be answered here`, { published: 'no' });
211
+ }
212
+ return decoded.messageSeq;
213
+ }
214
+ /** One node → its outgoing segment; media take their prepared URI. */
215
+ function segmentOf(prepared, node) {
216
+ switch (node.type) {
217
+ case 'text':
218
+ return { type: 'text', data: { text: node.text } };
219
+ case 'mention':
220
+ return { type: 'mention', data: { user_id: Number(node.userId) } };
221
+ case 'mention_all':
222
+ return { type: 'mention_all', data: {} };
223
+ case 'media': {
224
+ const uri = resolvedKey(prepared, node.ref);
225
+ switch (node.kind) {
226
+ case 'image':
227
+ return { type: 'image', data: { uri, sub_type: 'normal' } };
228
+ case 'record':
229
+ return { type: 'record', data: { uri } };
230
+ case 'video':
231
+ return { type: 'video', data: { uri } };
232
+ }
233
+ }
234
+ case 'file':
235
+ // A file node never reaches `segmentOf`: `assemble` gives it a draft of its own.
236
+ throw new PlatformError('invalid', 'milky: a file cannot ride a message segment', { published: 'no' });
237
+ }
238
+ }
239
+ /** Name an uploaded file: the element's `name`, else the fetched name recorded by `upload`, else `file`. */
240
+ function fileNameOf(prepared, ref) {
241
+ const name = ref.meta.name;
242
+ if (name !== undefined && name !== '')
243
+ return name;
244
+ const extra = prepared.resolved.get(ref)?.extra;
245
+ if (extra && typeof extra === 'object' && 'name' in extra) {
246
+ const fetched = extra.name;
247
+ if (typeof fetched === 'string' && fetched !== '')
248
+ return fetched;
249
+ }
250
+ return 'file';
251
+ }
252
+ /** Serialize one prepared draft into the exact request body. */
253
+ function serializeDraft(prepared, ctx) {
254
+ const { draft } = prepared;
255
+ const chatId = ctx.target.chat.id;
256
+ if (draft.kind === 'file') {
257
+ return {
258
+ kind: 'file',
259
+ chatId,
260
+ uri: resolvedKey(prepared, draft.ref),
261
+ name: fileNameOf(prepared, draft.ref),
262
+ };
263
+ }
264
+ const segments = [];
265
+ if (draft.replyTo !== undefined) {
266
+ segments.push({
267
+ type: 'reply',
268
+ data: { message_seq: replySeqOf(draft.replyTo, chatId) },
269
+ });
270
+ }
271
+ for (const node of draft.segments)
272
+ segments.push(segmentOf(prepared, node));
273
+ return { kind: 'message', chatId, segments };
274
+ }
275
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/modes/text.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,UAAU,EACV,eAAe,EAIf,aAAa,GAKd,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,WAAW,GACZ,MAAM,WAAW,CAAA;AA4ClB,4GAA4G;AAC5G,SAAS,aAAa;IACpB,OAAO,CACL,IAAI,eAAe,EAAkB;SAClC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;SACpE,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,CA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AA;QAClD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,EAAE;YAAE,OAAO,OAAO,CAAA;IACnE,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,gEAAgE;AAChE,SAAS,cAAc,CACrB,QAA8B,EAC9B,GAAqB;IAErB,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAA;IAC1B,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAA;IACjC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC1B,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,MAAM;YACN,GAAG,EAAE,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC;YACrC,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC;SACtC,CAAA;IACH,CAAC;IACD,MAAM,QAAQ,GAAsB,EAAE,CAAA;IACtC,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,EAAE,WAAW,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;SACzD,CAAC,CAAA;IACJ,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,QAAQ;QAAE,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAA;IAC3E,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;AAC9C,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The read surface: members, one message by id (with merged forwards expanded) and group reactions.
3
+ *
4
+ * These are the only platform reads the adapter performs on request; inbound decoding itself does none.
5
+ */
6
+ import { type ChatRef, type InboundMessage, type MembersPage, type MessageRef } from '@deepseek-ai/cordis-plugin-im-core';
7
+ import type { MilkyBot } from './bot.ts';
8
+ import type { Internal } from './internal.ts';
9
+ /**
10
+ * One page of the people a chat lists as its members.
11
+ *
12
+ * Milky's member API has no paging parameters, so the cursor is the adapter's own index into the full list; a private
13
+ * chat lists its single peer.
14
+ *
15
+ * @param internal - platform API client.
16
+ * @param chat - chat to list.
17
+ * @param cursor - `next` of the previous page.
18
+ * @param limit - page-size hint from the host.
19
+ * @returns one page.
20
+ * @throws PlatformError `invalid` for a chat id this adapter did not write or a cursor that is not an index.
21
+ */
22
+ export declare function members(internal: Internal, chat: ChatRef, cursor?: string, limit?: number): Promise<MembersPage>;
23
+ /**
24
+ * Read one message by id.
25
+ *
26
+ * @param bot - bot whose platform prefix names internal media routes.
27
+ * @param chat - the chat the caller asked about; the id must belong to it.
28
+ * @param id - platform message id (`g|f|t:<peer>:<seq>`).
29
+ * @returns the message, with merged-forward entries expanded.
30
+ * @throws PlatformError `invalid` for an id of another chat or a file part id (those carry no `message_seq`).
31
+ */
32
+ export declare function getMessage(bot: MilkyBot, chat: ChatRef, id: string): Promise<InboundMessage>;
33
+ /**
34
+ * Parse the adapter's `<reaction_type>|<reaction_id>` reaction encoding; a bare value is a QQ face id.
35
+ * @param emoji - reaction the host asked for.
36
+ * @returns the protocol reaction type and id.
37
+ * @throws PlatformError `invalid` for an unknown reaction type prefix.
38
+ */
39
+ export declare function parseReaction(emoji: string): {
40
+ type: 'face' | 'emoji';
41
+ id: string;
42
+ };
43
+ /**
44
+ * Add one group reaction.
45
+ * @param internal - platform API client.
46
+ * @param message - the reacted message.
47
+ * @param emoji - `<reaction_type>|<reaction_id>`, or a bare face id.
48
+ */
49
+ export declare function createReaction(internal: Internal, message: MessageRef, emoji: string): Promise<void>;
50
+ /**
51
+ * Remove one group reaction.
52
+ * @param internal - platform API client.
53
+ * @param message - the reacted message.
54
+ * @param emoji - `<reaction_type>|<reaction_id>`, or a bare face id.
55
+ */
56
+ export declare function deleteReaction(internal: Internal, message: MessageRef, emoji: string): Promise<void>;
57
+ //# sourceMappingURL=reads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../../src/reads.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,OAAO,EAEZ,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EAIhB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAGxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAG7C;;;;;;;;;;;;GAYG;AACH,wBAAsB,OAAO,CAC3B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,OAAO,EACb,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,CAuCtB;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,OAAO,EACb,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,cAAc,CAAC,CAiCzB;AA0HD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG;IAC5C,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IACtB,EAAE,EAAE,MAAM,CAAA;CACX,CAYA;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAUf"}
@@ -0,0 +1,219 @@
1
+ /**
2
+ * The read surface: members, one message by id (with merged forwards expanded) and group reactions.
3
+ *
4
+ * These are the only platform reads the adapter performs on request; inbound decoding itself does none.
5
+ */
6
+ import { PlatformError, h, } from '@deepseek-ai/cordis-plugin-im-core';
7
+ import { decodeMessage } from "./decode.js";
8
+ import { decodeChatId, decodeMessageId, idNamesChat } from "./ids.js";
9
+ /**
10
+ * One page of the people a chat lists as its members.
11
+ *
12
+ * Milky's member API has no paging parameters, so the cursor is the adapter's own index into the full list; a private
13
+ * chat lists its single peer.
14
+ *
15
+ * @param internal - platform API client.
16
+ * @param chat - chat to list.
17
+ * @param cursor - `next` of the previous page.
18
+ * @param limit - page-size hint from the host.
19
+ * @returns one page.
20
+ * @throws PlatformError `invalid` for a chat id this adapter did not write or a cursor that is not an index.
21
+ */
22
+ export async function members(internal, chat, cursor, limit) {
23
+ const decoded = decodeChatId(chat.id);
24
+ if (decoded === undefined) {
25
+ throw new PlatformError('invalid', `milky: "${chat.id}" is not a milky chat id`);
26
+ }
27
+ const offset = cursor === undefined ? 0 : Number(cursor);
28
+ if (!Number.isSafeInteger(offset) || offset < 0) {
29
+ throw new PlatformError('invalid', `milky: "${cursor}" is not a member-list cursor of chat "${chat.id}"`);
30
+ }
31
+ if (decoded.scene !== 'group') {
32
+ // A private (or temporary) conversation has exactly one counterpart.
33
+ if (offset > 0)
34
+ return { data: [] };
35
+ const profile = await internal.getUserProfile(decoded.peerId);
36
+ const name = profile?.nickname;
37
+ return {
38
+ data: [
39
+ {
40
+ id: String(decoded.peerId),
41
+ ...(name === undefined || name === '' ? {} : { name }),
42
+ },
43
+ ],
44
+ };
45
+ }
46
+ const result = await internal.getGroupMemberList(decoded.peerId);
47
+ const list = Array.isArray(result?.members) ? result.members : [];
48
+ const size = limit === undefined || limit <= 0 ? list.length : limit;
49
+ const data = list.slice(offset, offset + size).map((member) => ({
50
+ id: String(member.user_id),
51
+ name: member.card || member.nickname,
52
+ role: member.role,
53
+ }));
54
+ const next = offset + size < list.length ? String(offset + size) : undefined;
55
+ return { data, ...(next === undefined ? {} : { next }) };
56
+ }
57
+ /**
58
+ * Read one message by id.
59
+ *
60
+ * @param bot - bot whose platform prefix names internal media routes.
61
+ * @param chat - the chat the caller asked about; the id must belong to it.
62
+ * @param id - platform message id (`g|f|t:<peer>:<seq>`).
63
+ * @returns the message, with merged-forward entries expanded.
64
+ * @throws PlatformError `invalid` for an id of another chat or a file part id (those carry no `message_seq`).
65
+ */
66
+ export async function getMessage(bot, chat, id) {
67
+ const decoded = decodeMessageId(id);
68
+ const target = decodeChatId(chat.id);
69
+ if (decoded === undefined ||
70
+ !idNamesChat(decoded.scene, decoded.peerId, target)) {
71
+ throw new PlatformError('invalid', `milky: "${id}" is not a message of chat "${chat.id}" and cannot be read there`);
72
+ }
73
+ const result = await bot.internal.getMessage(decoded.scene, decoded.peerId, decoded.messageSeq);
74
+ const input = result?.message;
75
+ if (input === undefined || input === null) {
76
+ throw new PlatformError('invalid', `milky: get_message answered without a message for "${id}"`);
77
+ }
78
+ const message = decodeMessage(bot, input);
79
+ if (message.chat.id !== chat.id) {
80
+ throw new PlatformError('invalid', `milky: "${id}" belongs to chat "${message.chat.id}", not "${chat.id}"`);
81
+ }
82
+ await expandForward(bot, message);
83
+ return message;
84
+ }
85
+ /**
86
+ * Fill the entries of a root merged-forward placeholder.
87
+ *
88
+ * A `<forward>` from decoding carries only its id; only a platform read knows the entries, so the host asks for the
89
+ * expansion when it needs the content (`im_read`). Entries become one text line each; a nested forward stays a
90
+ * `[合并转发 #id]` placeholder so one read cannot fan out without bound.
91
+ *
92
+ * @param bot - platform API client of the reading bot.
93
+ * @param message - the message whose forward placeholder to expand.
94
+ */
95
+ async function expandForward(bot, message) {
96
+ const forward = message.content.children.find((el) => el.type === 'forward' && el.children.length === 0);
97
+ if (forward === undefined)
98
+ return;
99
+ const result = await bot.internal.getForwardedMessages(forward.attrs.id);
100
+ const entries = Array.isArray(result?.messages) ? result.messages : [];
101
+ const children = [];
102
+ entries.forEach((entry, index) => {
103
+ if (index > 0)
104
+ children.push(h('br'));
105
+ const text = forwardedText(entry.segments);
106
+ children.push(h('text', { content: `${entry.sender_name}: ${text}` }));
107
+ });
108
+ forward.children = children;
109
+ }
110
+ /**
111
+ * Inline text of one forwarded entry: blocks flattened into one line, media and nested forwards as placeholders.
112
+ * @param segments - segments of the forwarded message.
113
+ * @returns its text, without line breaks.
114
+ */
115
+ function forwardedText(segments) {
116
+ const parts = [];
117
+ for (const segment of segments) {
118
+ switch (segment.type) {
119
+ case 'text':
120
+ parts.push(segment.data.text);
121
+ break;
122
+ case 'mention':
123
+ parts.push(`@${segment.data.name}`);
124
+ break;
125
+ case 'mention_all':
126
+ parts.push('@全体');
127
+ break;
128
+ case 'face':
129
+ case 'market_face':
130
+ parts.push('[表情]');
131
+ break;
132
+ case 'image':
133
+ parts.push('[图片]');
134
+ break;
135
+ case 'record':
136
+ parts.push('[语音]');
137
+ break;
138
+ case 'video':
139
+ parts.push('[视频]');
140
+ break;
141
+ case 'file':
142
+ parts.push(`[文件${segment.data.file_name === '' ? '' : `: ${segment.data.file_name}`}]`);
143
+ break;
144
+ case 'forward':
145
+ parts.push(`[合并转发 #${segment.data.forward_id}]`);
146
+ break;
147
+ case 'light_app':
148
+ parts.push(`[小程序${segment.data.app_name === '' ? '' : `: ${segment.data.app_name}`}]`);
149
+ break;
150
+ case 'xml':
151
+ parts.push('[XML 消息]');
152
+ break;
153
+ case 'markdown':
154
+ parts.push(segment.data.content);
155
+ break;
156
+ case 'reply':
157
+ break;
158
+ default: {
159
+ const unknown = segment;
160
+ const type = typeof unknown.type === 'string' ? unknown.type : 'unknown';
161
+ parts.push(`[不支持的${type}消息]`);
162
+ }
163
+ }
164
+ }
165
+ return parts.join('').replace(/\s+/g, ' ').trim();
166
+ }
167
+ /** The group and sequence one reaction targets, refusing anything that is not a group message of this chat. */
168
+ function reactionTarget(message) {
169
+ const decoded = decodeMessageId(message.id);
170
+ const chat = decodeChatId(message.chat.id);
171
+ if (message.chat.type !== 'group' || chat?.scene !== 'group') {
172
+ throw new PlatformError('invalid', 'milky: reactions are only available in group chats', { published: 'no' });
173
+ }
174
+ if (decoded === undefined ||
175
+ decoded.scene !== 'group' ||
176
+ !idNamesChat(decoded.scene, decoded.peerId, chat)) {
177
+ throw new PlatformError('invalid', `milky: "${message.id}" is not a message of group "${message.chat.id}"`, { published: 'no' });
178
+ }
179
+ return { groupId: chat.peerId, messageSeq: decoded.messageSeq };
180
+ }
181
+ /**
182
+ * Parse the adapter's `<reaction_type>|<reaction_id>` reaction encoding; a bare value is a QQ face id.
183
+ * @param emoji - reaction the host asked for.
184
+ * @returns the protocol reaction type and id.
185
+ * @throws PlatformError `invalid` for an unknown reaction type prefix.
186
+ */
187
+ export function parseReaction(emoji) {
188
+ const index = emoji.indexOf('|');
189
+ if (index < 0)
190
+ return { type: 'face', id: emoji };
191
+ const type = emoji.slice(0, index);
192
+ if (type !== 'face' && type !== 'emoji') {
193
+ throw new PlatformError('invalid', `milky: "${emoji}" does not name a reaction type (expected face|<id> or emoji|<id>)`, { published: 'no' });
194
+ }
195
+ return { type, id: emoji.slice(index + 1) };
196
+ }
197
+ /**
198
+ * Add one group reaction.
199
+ * @param internal - platform API client.
200
+ * @param message - the reacted message.
201
+ * @param emoji - `<reaction_type>|<reaction_id>`, or a bare face id.
202
+ */
203
+ export async function createReaction(internal, message, emoji) {
204
+ const { groupId, messageSeq } = reactionTarget(message);
205
+ const reaction = parseReaction(emoji);
206
+ await internal.sendGroupMessageReaction(groupId, messageSeq, reaction.id, reaction.type, true);
207
+ }
208
+ /**
209
+ * Remove one group reaction.
210
+ * @param internal - platform API client.
211
+ * @param message - the reacted message.
212
+ * @param emoji - `<reaction_type>|<reaction_id>`, or a bare face id.
213
+ */
214
+ export async function deleteReaction(internal, message, emoji) {
215
+ const { groupId, messageSeq } = reactionTarget(message);
216
+ const reaction = parseReaction(emoji);
217
+ await internal.sendGroupMessageReaction(groupId, messageSeq, reaction.id, reaction.type, false);
218
+ }
219
+ //# sourceMappingURL=reads.js.map
@@ -0,0 +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A;IACrC,MAAM,QAAQ,CAAC,wBAAwB,CACrC,OAAO,EACP,UAAU,EACV,QAAQ,CAAC,EAAE,EACX,QAAQ,CAAC,IAAI,EACb,KAAK,CACN,CAAA;AACH,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Milky wire transport: `POST <origin>/api/<name>` with the protocol's JSON envelope and a bearer token.
3
+ *
4
+ * The HTTP and WebSocket addresses are derived from the `origin` of `endpoint` only: the protocol endpoint serves
5
+ * `/api` and `/event` next to each other at its root, so a path, query or hash of the configured URL is ignored (the
6
+ * same rule the upstream adapter applies).
7
+ */
8
+ import type { Context } from '@deepseek-ai/cordis';
9
+ /** What every API call and the event socket share. */
10
+ export interface MilkyRequest {
11
+ readonly ctx: Context;
12
+ /** `access_token` of the protocol endpoint; an empty string sends no `Authorization` header. */
13
+ readonly token: string;
14
+ /** Scheme, host and port of `endpoint`; the protocol endpoint's root. */
15
+ readonly origin: string;
16
+ }
17
+ /**
18
+ * Normalize the configured endpoint: drop trailing slashes, keep everything else for {@link milkyOrigin} to judge.
19
+ * @param endpoint - `config.endpoint` as given.
20
+ * @returns the endpoint without a trailing slash.
21
+ */
22
+ export declare function normalizeEndpoint(endpoint: string): string;
23
+ /**
24
+ * Origin (scheme + host + port) of the protocol endpoint.
25
+ * @param endpoint - normalized endpoint.
26
+ * @returns the origin both the API and the event socket are built from.
27
+ * @throws MilkyConfigError when the endpoint is not a URL or does not use `http:` / `https:`.
28
+ */
29
+ export declare function milkyOrigin(endpoint: string): string;
30
+ /**
31
+ * Build the shared request endpoints of one bot.
32
+ * @param ctx - context whose isolated `http` service performs the calls.
33
+ * @param token - configured access token.
34
+ * @param origin - origin of the protocol endpoint.
35
+ * @returns the request endpoints.
36
+ */
37
+ export declare function createMilkyRequest(ctx: Context, token: string, origin: string): MilkyRequest;
38
+ /**
39
+ * Event socket address of one request endpoint.
40
+ * @param request - request endpoints of the bot.
41
+ * @returns `ws(s)://<origin>/event`.
42
+ */
43
+ export declare function eventUrl(request: MilkyRequest): string;
44
+ /**
45
+ * Call one Milky API method through the shared envelope and error path.
46
+ *
47
+ * @param request - request endpoints of the bot.
48
+ * @param api - API name (`send_group_message`).
49
+ * @param payload - JSON request body; `{}` for the parameterless APIs.
50
+ * @param signal - cancellation of the caller.
51
+ * @returns the `data` field of a `status: 'ok'` answer.
52
+ * @throws MilkyApiError for every non-ok answer, including an unparsable one.
53
+ */
54
+ export declare function invoke<T>(request: MilkyRequest, api: string, payload?: object, signal?: AbortSignal): Promise<T>;
55
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAIlD,sDAAsD;AACtD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;IACrB,gGAAgG;IAChG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,yEAAyE;IACzE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAUD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAgBpD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,YAAY,CAEd;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAKtD;AAED;;;;;;;;;GASG;AACH,wBAAsB,MAAM,CAAC,CAAC,EAC5B,OAAO,EAAE,YAAY,EACrB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,MAAW,EACpB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CA8EZ"}