@im-more/dsh-matrix 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 +14 -0
- package/lib/index.js +2401 -0
- package/lib/index.js.map +1 -0
- package/lib/types/as.d.ts +33 -0
- package/lib/types/as.d.ts.map +1 -0
- package/lib/types/as.js +237 -0
- package/lib/types/as.js.map +1 -0
- package/lib/types/bot.d.ts +109 -0
- package/lib/types/bot.d.ts.map +1 -0
- package/lib/types/bot.js +234 -0
- package/lib/types/bot.js.map +1 -0
- package/lib/types/config.d.ts +59 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +67 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/decode.d.ts +56 -0
- package/lib/types/decode.d.ts.map +1 -0
- package/lib/types/decode.js +298 -0
- package/lib/types/decode.js.map +1 -0
- package/lib/types/errors.d.ts +45 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +120 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/html.d.ts +44 -0
- package/lib/types/html.d.ts.map +1 -0
- package/lib/types/html.js +286 -0
- package/lib/types/html.js.map +1 -0
- package/lib/types/identity.d.ts +20 -0
- package/lib/types/identity.d.ts.map +1 -0
- package/lib/types/identity.js +136 -0
- package/lib/types/identity.js.map +1 -0
- package/lib/types/index.d.ts +5 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +5 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/media.d.ts +54 -0
- package/lib/types/media.d.ts.map +1 -0
- package/lib/types/media.js +94 -0
- package/lib/types/media.js.map +1 -0
- package/lib/types/mentions.d.ts +58 -0
- package/lib/types/mentions.d.ts.map +1 -0
- package/lib/types/mentions.js +94 -0
- package/lib/types/mentions.js.map +1 -0
- package/lib/types/modes/html.d.ts +13 -0
- package/lib/types/modes/html.d.ts.map +1 -0
- package/lib/types/modes/html.js +242 -0
- package/lib/types/modes/html.js.map +1 -0
- package/lib/types/modes/shared.d.ts +164 -0
- package/lib/types/modes/shared.d.ts.map +1 -0
- package/lib/types/modes/shared.js +312 -0
- package/lib/types/modes/shared.js.map +1 -0
- package/lib/types/request.d.ts +82 -0
- package/lib/types/request.d.ts.map +1 -0
- package/lib/types/request.js +206 -0
- package/lib/types/request.js.map +1 -0
- package/lib/types/rooms.d.ts +83 -0
- package/lib/types/rooms.d.ts.map +1 -0
- package/lib/types/rooms.js +177 -0
- package/lib/types/rooms.js.map +1 -0
- package/lib/types/send.d.ts +76 -0
- package/lib/types/send.d.ts.map +1 -0
- package/lib/types/send.js +172 -0
- package/lib/types/send.js.map +1 -0
- package/lib/types/types.d.ts +418 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js +134 -0
- package/lib/types/types.js.map +1 -0
- package/package.json +65 -3
- package/src/as.ts +293 -0
- package/src/bot.ts +338 -0
- package/src/config.ts +100 -0
- package/src/decode.ts +392 -0
- package/src/errors.ts +149 -0
- package/src/html.ts +325 -0
- package/src/identity.ts +165 -0
- package/src/index.ts +14 -0
- package/src/media.ts +132 -0
- package/src/mentions.ts +134 -0
- package/src/modes/html.ts +346 -0
- package/src/modes/shared.ts +485 -0
- package/src/request.ts +295 -0
- package/src/rooms.ts +232 -0
- package/src/send.ts +275 -0
- package/src/types.ts +633 -0
- package/README.md +0 -3
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matrix failures and their mapping onto the core platform taxonomy.
|
|
3
|
+
*
|
|
4
|
+
* Matrix answers with one JSON envelope (`errcode`, `error`) and asks clients to decide from `errcode`, falling back
|
|
5
|
+
* to the HTTP status only for `M_UNKNOWN`. A refused write is atomic, so every 4xx means nothing was published;
|
|
6
|
+
* transport failures and 5xx answers leave the outcome unknown. The token-failure codes also mark the bot offline at
|
|
7
|
+
* the transport layer, because the AS-issued user token has no refresh path.
|
|
8
|
+
*/
|
|
9
|
+
import { PlatformError } from '@deepseek-ai/cordis-plugin-im-core';
|
|
10
|
+
/** One failed Matrix API call, with the fields `classify` reads. */
|
|
11
|
+
export class MatrixApiError extends Error {
|
|
12
|
+
method;
|
|
13
|
+
path;
|
|
14
|
+
status;
|
|
15
|
+
errcode;
|
|
16
|
+
error;
|
|
17
|
+
retryAfterMs;
|
|
18
|
+
constructor(message, init = {}) {
|
|
19
|
+
super(message, init.cause === undefined ? undefined : { cause: init.cause });
|
|
20
|
+
this.name = 'MatrixApiError';
|
|
21
|
+
this.method = init.method;
|
|
22
|
+
this.path = init.path;
|
|
23
|
+
this.status = init.status;
|
|
24
|
+
this.errcode = init.errcode;
|
|
25
|
+
this.error = init.error;
|
|
26
|
+
this.retryAfterMs = init.retryAfterMs;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Whether a failure means the user token is gone; the bot has to be re-logged in from scratch. */
|
|
30
|
+
export function isTokenFailure(error) {
|
|
31
|
+
if (error instanceof MatrixApiError) {
|
|
32
|
+
if (error.errcode === 'M_UNKNOWN_TOKEN' ||
|
|
33
|
+
error.errcode === 'M_MISSING_TOKEN')
|
|
34
|
+
return true;
|
|
35
|
+
return error.errcode === undefined && error.status === 401;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
/** The kind and publish state implied by one `errcode`. */
|
|
40
|
+
function byErrcode(errcode) {
|
|
41
|
+
switch (errcode) {
|
|
42
|
+
case 'M_LIMIT_EXCEEDED':
|
|
43
|
+
return { kind: 'rate-limit', published: 'no' };
|
|
44
|
+
case 'M_UNKNOWN_TOKEN':
|
|
45
|
+
case 'M_MISSING_TOKEN':
|
|
46
|
+
case 'M_FORBIDDEN':
|
|
47
|
+
case 'M_EXCLUSIVE':
|
|
48
|
+
case 'M_USER_DEACTIVATED':
|
|
49
|
+
case 'M_CONSENT_NOT_GIVEN':
|
|
50
|
+
return { kind: 'permission', published: 'no' };
|
|
51
|
+
case 'M_RESOURCE_LIMIT_EXCEEDED':
|
|
52
|
+
return { kind: 'retryable', published: 'no' };
|
|
53
|
+
case 'M_NOT_FOUND':
|
|
54
|
+
return { kind: 'not-found', published: 'no' };
|
|
55
|
+
case 'M_BAD_JSON':
|
|
56
|
+
case 'M_NOT_JSON':
|
|
57
|
+
case 'M_MISSING_PARAM':
|
|
58
|
+
case 'M_INVALID_PARAM':
|
|
59
|
+
return { kind: 'invalid', published: 'no' };
|
|
60
|
+
case 'M_TOO_LARGE':
|
|
61
|
+
return { kind: 'limit', published: 'no' };
|
|
62
|
+
default:
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The kind and publish state implied by a status when no `errcode` decides it. */
|
|
67
|
+
function byStatus(status) {
|
|
68
|
+
if (status === 429)
|
|
69
|
+
return { kind: 'rate-limit', published: 'no' };
|
|
70
|
+
if (status !== undefined && status >= 500)
|
|
71
|
+
return { kind: 'retryable', published: 'unknown' };
|
|
72
|
+
// A 2xx answer this client could not read may still have published the event; only a refusal is certainly unpublished.
|
|
73
|
+
if (status !== undefined && status >= 200 && status < 300)
|
|
74
|
+
return { kind: 'retryable', published: 'unknown' };
|
|
75
|
+
if (status !== undefined)
|
|
76
|
+
return { kind: 'invalid', published: 'no' };
|
|
77
|
+
return { kind: 'retryable', published: 'unknown' };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Map any failure onto the core platform taxonomy.
|
|
81
|
+
*
|
|
82
|
+
* @param error - the caught failure.
|
|
83
|
+
* @returns the classified platform error, with `retryAfterMs` when the platform named a delay.
|
|
84
|
+
*/
|
|
85
|
+
export function classifyMatrixError(error) {
|
|
86
|
+
if (error instanceof PlatformError)
|
|
87
|
+
return error;
|
|
88
|
+
if (error instanceof MatrixApiError) {
|
|
89
|
+
const { kind, published } = (error.errcode === undefined || error.errcode === 'M_UNKNOWN'
|
|
90
|
+
? undefined
|
|
91
|
+
: byErrcode(error.errcode)) ?? byStatus(error.status);
|
|
92
|
+
const code = error.errcode ?? error.status;
|
|
93
|
+
return new PlatformError(kind, error.message, {
|
|
94
|
+
...(code === undefined ? {} : { code }),
|
|
95
|
+
...(error.retryAfterMs === undefined
|
|
96
|
+
? {}
|
|
97
|
+
: { retryAfterMs: error.retryAfterMs }),
|
|
98
|
+
published,
|
|
99
|
+
cause: error,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
103
|
+
return new PlatformError('fatal', error.message, {
|
|
104
|
+
published: 'unknown',
|
|
105
|
+
cause: error,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
109
|
+
return new PlatformError('fatal', error.message, {
|
|
110
|
+
published: 'unknown',
|
|
111
|
+
cause: error,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
115
|
+
return new PlatformError('retryable', `matrix request failed: ${message}`, {
|
|
116
|
+
published: 'unknown',
|
|
117
|
+
cause: error,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAoBlE,oEAAoE;AACpE,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,MAAM,CAAoB;IAC1B,IAAI,CAAoB;IACxB,MAAM,CAAoB;IAC1B,OAAO,CAAoB;IAC3B,KAAK,CAAoB;IACzB,YAAY,CAAoB;IAEzC,YAAY,OAAe,EAAE,OAA2B,EAAE;QACxD,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAA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W,EAAE,0BAA0B,OAAO,EAAE,EAAE;QACzE,SAAS,EAAE,SAAS;QACpB,KAAK,EAAE,KAAK;KACb,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `formatted_body` decoding: Matrix's HTML subset becomes Satori elements.
|
|
3
|
+
*
|
|
4
|
+
* The traversal follows the upstream adapter (`html5parser` + a tag table) and keeps two one-line bug fixes from the
|
|
5
|
+
* migration: an unknown named character reference stays as written instead of duplicating the whole text node, and an
|
|
6
|
+
* image's `alt` is read from `alt` rather than from `src`. A Matrix rich reply carries a duplicated fallback block
|
|
7
|
+
* (`<mx-reply>`); the whole block is dropped, as the specification tells clients to strip it.
|
|
8
|
+
*/
|
|
9
|
+
import type { Element } from '@deepseek-ai/satori-element';
|
|
10
|
+
/** What the traversal needs from the bot: a way to turn `mxc://` into a fetchable `satori:` source. */
|
|
11
|
+
export interface HtmlDecodeOptions {
|
|
12
|
+
/** Turn an `mxc://` URI into the bot's authenticated internal source. */
|
|
13
|
+
mediaSource: (mxc: string) => string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Decode named, decimal and hexadecimal character references of one text run.
|
|
17
|
+
*
|
|
18
|
+
* A named reference outside {@link ENTITIES} is not an error: it stays as written. (Upstream returned the whole text
|
|
19
|
+
* node in that case, which duplicated everything around the unknown reference.)
|
|
20
|
+
*
|
|
21
|
+
* @param text - raw character data of one HTML text node.
|
|
22
|
+
* @returns the text with the known references decoded.
|
|
23
|
+
*/
|
|
24
|
+
export declare function decodeHE(text: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Convert one HTML string into elements.
|
|
27
|
+
*
|
|
28
|
+
* @param html - the `formatted_body` of an `m.room.message`.
|
|
29
|
+
* @param options - how to fetch media.
|
|
30
|
+
* @returns the elements of the body, in document order.
|
|
31
|
+
*/
|
|
32
|
+
export declare function htmlToElements(html: string, options: HtmlDecodeOptions): Element[];
|
|
33
|
+
/**
|
|
34
|
+
* Strip the rich-reply fallback of a plain `body`.
|
|
35
|
+
*
|
|
36
|
+
* A client that writes `format: org.matrix.custom.html` duplicates the quoted message inside `<mx-reply>`, and a plain
|
|
37
|
+
* body carries the same duplicate as leading `> ` lines. Only the leading block is removed, followed by the one blank
|
|
38
|
+
* line the fallback spec puts after it.
|
|
39
|
+
*
|
|
40
|
+
* @param body - the plain-text body of an `m.room.message`.
|
|
41
|
+
* @returns the body without a leading quote fallback.
|
|
42
|
+
*/
|
|
43
|
+
export declare function stripPlainFallback(body: string): string;
|
|
44
|
+
//# sourceMappingURL=html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/html.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAA;AAI1D,uGAAuG;AACvG,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;CACrC;AAkBD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiB7C;AA6CD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GACzB,OAAO,EAAE,CA4LX;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOvD"}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `formatted_body` decoding: Matrix's HTML subset becomes Satori elements.
|
|
3
|
+
*
|
|
4
|
+
* The traversal follows the upstream adapter (`html5parser` + a tag table) and keeps two one-line bug fixes from the
|
|
5
|
+
* migration: an unknown named character reference stays as written instead of duplicating the whole text node, and an
|
|
6
|
+
* image's `alt` is read from `alt` rather than from `src`. A Matrix rich reply carries a duplicated fallback block
|
|
7
|
+
* (`<mx-reply>`); the whole block is dropped, as the specification tells clients to strip it.
|
|
8
|
+
*/
|
|
9
|
+
import { h } from '@deepseek-ai/satori-element';
|
|
10
|
+
import { parse, SyntaxKind } from 'html5parser';
|
|
11
|
+
/** The named character references the traversal decodes (the upstream adapter's table). */
|
|
12
|
+
const ENTITIES = {
|
|
13
|
+
nbsp: ' ',
|
|
14
|
+
cent: '¢',
|
|
15
|
+
pound: '£',
|
|
16
|
+
yen: '¥',
|
|
17
|
+
euro: '€',
|
|
18
|
+
copy: '©',
|
|
19
|
+
reg: '®',
|
|
20
|
+
lt: '<',
|
|
21
|
+
gt: '>',
|
|
22
|
+
quot: '"',
|
|
23
|
+
amp: '&',
|
|
24
|
+
apos: "'",
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Decode named, decimal and hexadecimal character references of one text run.
|
|
28
|
+
*
|
|
29
|
+
* A named reference outside {@link ENTITIES} is not an error: it stays as written. (Upstream returned the whole text
|
|
30
|
+
* node in that case, which duplicated everything around the unknown reference.)
|
|
31
|
+
*
|
|
32
|
+
* @param text - raw character data of one HTML text node.
|
|
33
|
+
* @returns the text with the known references decoded.
|
|
34
|
+
*/
|
|
35
|
+
export function decodeHE(text) {
|
|
36
|
+
const regex = /&(([a-z0-9]+)|(#[0-9]{1,6})|(#x[0-9a-fA-F]{1,6}));/gi;
|
|
37
|
+
return text.replace(regex, (raw, _whole, name, dec, hex) => {
|
|
38
|
+
if (name)
|
|
39
|
+
return ENTITIES[name] ?? raw;
|
|
40
|
+
if (dec)
|
|
41
|
+
return String.fromCharCode(Number(dec.substring(1)));
|
|
42
|
+
if (hex)
|
|
43
|
+
return String.fromCharCode(parseInt(hex.substring(2), 16));
|
|
44
|
+
return raw;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** One attribute of a parsed tag, as written in the source. */
|
|
48
|
+
function attribute(node, name) {
|
|
49
|
+
return node.attributeMap?.[name]?.value?.value;
|
|
50
|
+
}
|
|
51
|
+
/** Whether the attribute is present (an HTML boolean attribute such as `checked`). */
|
|
52
|
+
function hasAttribute(node, name) {
|
|
53
|
+
return node.attributeMap?.[name] !== undefined;
|
|
54
|
+
}
|
|
55
|
+
/** A numeric attribute, or undefined when it is absent or not a number. */
|
|
56
|
+
function numericAttribute(node, name) {
|
|
57
|
+
const value = attribute(node, name);
|
|
58
|
+
if (value === undefined || value.trim() === '')
|
|
59
|
+
return undefined;
|
|
60
|
+
const parsed = Number(value);
|
|
61
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
62
|
+
}
|
|
63
|
+
/** Tags whose whole subtree is not part of the message body. */
|
|
64
|
+
const IGNORED = new Set([
|
|
65
|
+
'head',
|
|
66
|
+
'script',
|
|
67
|
+
'style',
|
|
68
|
+
'meta',
|
|
69
|
+
'title',
|
|
70
|
+
'template',
|
|
71
|
+
]);
|
|
72
|
+
/** The language of a `<pre><code class="language-x">` pair, when the client wrote one. */
|
|
73
|
+
function languageOf(body) {
|
|
74
|
+
for (const child of body) {
|
|
75
|
+
if (child.type !== SyntaxKind.Tag || child.name !== 'code')
|
|
76
|
+
continue;
|
|
77
|
+
const className = attribute(child, 'class');
|
|
78
|
+
if (className === undefined)
|
|
79
|
+
continue;
|
|
80
|
+
const match = /(?:^|\s)language-(\S+)/.exec(className);
|
|
81
|
+
if (match?.[1] !== undefined)
|
|
82
|
+
return match[1];
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
/** The label and destination of one `matrix.to` link, when it is one. */
|
|
87
|
+
const MATRIX_TO = 'https://matrix.to/#/';
|
|
88
|
+
/**
|
|
89
|
+
* Convert one HTML string into elements.
|
|
90
|
+
*
|
|
91
|
+
* @param html - the `formatted_body` of an `m.room.message`.
|
|
92
|
+
* @param options - how to fetch media.
|
|
93
|
+
* @returns the elements of the body, in document order.
|
|
94
|
+
*/
|
|
95
|
+
export function htmlToElements(html, options) {
|
|
96
|
+
const visit = (nodes) => {
|
|
97
|
+
const out = [];
|
|
98
|
+
for (const node of nodes) {
|
|
99
|
+
if (node.type === SyntaxKind.Text) {
|
|
100
|
+
const text = decodeHE(node.value);
|
|
101
|
+
if (text !== '')
|
|
102
|
+
out.push(h.text(text));
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const body = node.body ?? [];
|
|
106
|
+
switch (node.name) {
|
|
107
|
+
case 'mx-reply':
|
|
108
|
+
// The fallback repeats the replied-to message; Matrix clients strip it before rendering.
|
|
109
|
+
break;
|
|
110
|
+
case 'p':
|
|
111
|
+
out.push(h('p', ...visit(body)));
|
|
112
|
+
break;
|
|
113
|
+
case 'br':
|
|
114
|
+
out.push(h('br'));
|
|
115
|
+
break;
|
|
116
|
+
case 'hr':
|
|
117
|
+
out.push(h('hr'));
|
|
118
|
+
break;
|
|
119
|
+
case 'b':
|
|
120
|
+
case 'strong':
|
|
121
|
+
out.push(h('b', ...visit(body)));
|
|
122
|
+
break;
|
|
123
|
+
case 'i':
|
|
124
|
+
case 'em':
|
|
125
|
+
out.push(h('i', ...visit(body)));
|
|
126
|
+
break;
|
|
127
|
+
case 'u':
|
|
128
|
+
out.push(h('u', ...visit(body)));
|
|
129
|
+
break;
|
|
130
|
+
case 's':
|
|
131
|
+
case 'del':
|
|
132
|
+
case 'strike':
|
|
133
|
+
out.push(h('s', ...visit(body)));
|
|
134
|
+
break;
|
|
135
|
+
case 'code':
|
|
136
|
+
out.push(h('code', ...visit(body)));
|
|
137
|
+
break;
|
|
138
|
+
case 'pre': {
|
|
139
|
+
const language = languageOf(body);
|
|
140
|
+
out.push(h('pre', language === undefined ? {} : { lang: language }, ...visit(body)));
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case 'a': {
|
|
144
|
+
const href = attribute(node, 'href') ?? '#';
|
|
145
|
+
const children = visit(body);
|
|
146
|
+
const plain = href.startsWith(MATRIX_TO)
|
|
147
|
+
? href.slice(MATRIX_TO.length)
|
|
148
|
+
: undefined;
|
|
149
|
+
if (plain?.startsWith('@')) {
|
|
150
|
+
out.push(h('at', { type: 'user', id: plain }, ...children));
|
|
151
|
+
}
|
|
152
|
+
else if (plain?.startsWith('#') || plain?.startsWith('!')) {
|
|
153
|
+
out.push(h('channel', { id: plain }, ...children));
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
out.push(h('a', { href }, ...children));
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case 'img': {
|
|
161
|
+
const src = attribute(node, 'src');
|
|
162
|
+
const alt = attribute(node, 'alt');
|
|
163
|
+
const width = numericAttribute(node, 'width');
|
|
164
|
+
const height = numericAttribute(node, 'height');
|
|
165
|
+
if (src === undefined || src === '') {
|
|
166
|
+
// Upstream read `alt` into `src` by mistake; an image without a source keeps its description as text.
|
|
167
|
+
if (alt !== undefined && alt !== '')
|
|
168
|
+
out.push(h.text(alt));
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
const resolved = src.startsWith('mxc://')
|
|
172
|
+
? options.mediaSource(src)
|
|
173
|
+
: src;
|
|
174
|
+
out.push(h('img', {
|
|
175
|
+
src: resolved,
|
|
176
|
+
...(alt === undefined ? {} : { alt }),
|
|
177
|
+
...(width === undefined ? {} : { width }),
|
|
178
|
+
...(height === undefined ? {} : { height }),
|
|
179
|
+
}));
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case 'blockquote':
|
|
183
|
+
out.push(h('blockquote', ...visit(body)));
|
|
184
|
+
break;
|
|
185
|
+
case 'span': {
|
|
186
|
+
if (hasAttribute(node, 'data-mx-spoiler')) {
|
|
187
|
+
out.push(h('spoiler', ...visit(body)));
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
out.push(...visit(body));
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case 'ul':
|
|
195
|
+
out.push(h('ul', ...visit(body)));
|
|
196
|
+
break;
|
|
197
|
+
case 'ol': {
|
|
198
|
+
const start = numericAttribute(node, 'start');
|
|
199
|
+
out.push(h('ol', start === undefined ? {} : { start }, ...visit(body)));
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
case 'li': {
|
|
203
|
+
let checked;
|
|
204
|
+
const children = [];
|
|
205
|
+
for (const child of body) {
|
|
206
|
+
if (child.type === SyntaxKind.Tag &&
|
|
207
|
+
child.name === 'input' &&
|
|
208
|
+
attribute(child, 'type') === 'checkbox') {
|
|
209
|
+
checked = hasAttribute(child, 'checked');
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
children.push(child);
|
|
213
|
+
}
|
|
214
|
+
out.push(h('li', checked === undefined ? {} : { checked }, ...visit(children)));
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case 'table':
|
|
218
|
+
out.push(h('table', ...visit(body)));
|
|
219
|
+
break;
|
|
220
|
+
case 'tr':
|
|
221
|
+
out.push(h('tr', ...visit(body)));
|
|
222
|
+
break;
|
|
223
|
+
case 'th':
|
|
224
|
+
case 'td': {
|
|
225
|
+
const align = attribute(node, 'align');
|
|
226
|
+
const attrs = align === 'left' || align === 'center' || align === 'right'
|
|
227
|
+
? { align }
|
|
228
|
+
: {};
|
|
229
|
+
out.push(h(node.name, attrs, ...visit(body)));
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case 'details':
|
|
233
|
+
out.push(h('details', hasAttribute(node, 'open') ? { open: true } : {}, ...visit(body)));
|
|
234
|
+
break;
|
|
235
|
+
case 'summary':
|
|
236
|
+
out.push(h('summary', ...visit(body)));
|
|
237
|
+
break;
|
|
238
|
+
case 'h1':
|
|
239
|
+
case 'h2':
|
|
240
|
+
case 'h3':
|
|
241
|
+
case 'h4':
|
|
242
|
+
case 'h5':
|
|
243
|
+
case 'h6':
|
|
244
|
+
out.push(h(node.name, ...visit(body)));
|
|
245
|
+
break;
|
|
246
|
+
case 'sup':
|
|
247
|
+
case 'sub':
|
|
248
|
+
case 'font':
|
|
249
|
+
case 'div':
|
|
250
|
+
case 'caption':
|
|
251
|
+
case 'thead':
|
|
252
|
+
case 'tbody':
|
|
253
|
+
out.push(...visit(body));
|
|
254
|
+
break;
|
|
255
|
+
default:
|
|
256
|
+
if (IGNORED.has(node.name))
|
|
257
|
+
break;
|
|
258
|
+
out.push(...visit(body));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return out;
|
|
262
|
+
};
|
|
263
|
+
return visit(parse(html, { setAttributeMap: true }));
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Strip the rich-reply fallback of a plain `body`.
|
|
267
|
+
*
|
|
268
|
+
* A client that writes `format: org.matrix.custom.html` duplicates the quoted message inside `<mx-reply>`, and a plain
|
|
269
|
+
* body carries the same duplicate as leading `> ` lines. Only the leading block is removed, followed by the one blank
|
|
270
|
+
* line the fallback spec puts after it.
|
|
271
|
+
*
|
|
272
|
+
* @param body - the plain-text body of an `m.room.message`.
|
|
273
|
+
* @returns the body without a leading quote fallback.
|
|
274
|
+
*/
|
|
275
|
+
export function stripPlainFallback(body) {
|
|
276
|
+
const lines = body.split('\n');
|
|
277
|
+
let index = 0;
|
|
278
|
+
while (index < lines.length && lines[index].startsWith('> '))
|
|
279
|
+
index++;
|
|
280
|
+
if (index === 0)
|
|
281
|
+
return body;
|
|
282
|
+
if (lines[index] === '')
|
|
283
|
+
index++;
|
|
284
|
+
return lines.slice(index).join('\n');
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/html.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,6BAA6B,CAAA;AAE/C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAS/C,2FAA2F;AAC3F,MAAM,QAAQ,GAA2B;IACvC,IAAI,EAAE,GAAG;I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E,IAAI,EAAE,CAAC,CAAC,CAAA;AACtD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC9B,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,OAAO,KAAK,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,KAAK,EAAE,CAAA;IACtE,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAC5B,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,CAAA;IAChC,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application Service identity: register the virtual user with `m.login.application_service`, fall back to login when
|
|
3
|
+
* the homeserver reports `M_USER_IN_USE` (the normal case after the first start), check the answered `user_id`, read
|
|
4
|
+
* the profile and write the configured display name / avatar.
|
|
5
|
+
*
|
|
6
|
+
* The AS user has no password and no second login entry, so the returned user access token is the only credential the
|
|
7
|
+
* Client-Server calls carry.
|
|
8
|
+
*/
|
|
9
|
+
import type { MatrixBot } from './bot.ts';
|
|
10
|
+
import type { Config } from './config.ts';
|
|
11
|
+
/** The virtual user id of the configured localpart. */
|
|
12
|
+
export declare function matrixUserId(config: Config): string;
|
|
13
|
+
/**
|
|
14
|
+
* Establish the bot identity and store it on the adapter.
|
|
15
|
+
*
|
|
16
|
+
* @param bot - the adapter being connected.
|
|
17
|
+
* @throws MatrixApiError when the credentials, the namespace or the answered identity are wrong.
|
|
18
|
+
*/
|
|
19
|
+
export declare function establishIdentity(bot: MatrixBot): Promise<void>;
|
|
20
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAKzC,uDAAuD;AACvD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD;AAmFD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAuDrE"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application Service identity: register the virtual user with `m.login.application_service`, fall back to login when
|
|
3
|
+
* the homeserver reports `M_USER_IN_USE` (the normal case after the first start), check the answered `user_id`, read
|
|
4
|
+
* the profile and write the configured display name / avatar.
|
|
5
|
+
*
|
|
6
|
+
* The AS user has no password and no second login entry, so the returned user access token is the only credential the
|
|
7
|
+
* Client-Server calls carry.
|
|
8
|
+
*/
|
|
9
|
+
import { MatrixApiError } from "./errors.js";
|
|
10
|
+
import { internalMediaSource } from "./media.js";
|
|
11
|
+
/** The virtual user id of the configured localpart. */
|
|
12
|
+
export function matrixUserId(config) {
|
|
13
|
+
return `@${config.id}:${config.host}`;
|
|
14
|
+
}
|
|
15
|
+
/** The response of a failed convenience request, recovered structurally (`ctx.http.post` throws an `HttpError`). */
|
|
16
|
+
function responseOf(error) {
|
|
17
|
+
if (typeof error !== 'object' || error === null || !('response' in error))
|
|
18
|
+
return undefined;
|
|
19
|
+
const response = error.response;
|
|
20
|
+
return response instanceof Response ? response : undefined;
|
|
21
|
+
}
|
|
22
|
+
/** One JSON envelope of a failed answer. */
|
|
23
|
+
async function envelopeOf(response) {
|
|
24
|
+
try {
|
|
25
|
+
const parsed = await response.clone().json();
|
|
26
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
27
|
+
return {};
|
|
28
|
+
const value = parsed;
|
|
29
|
+
return {
|
|
30
|
+
...(typeof value.errcode === 'string' ? { errcode: value.errcode } : {}),
|
|
31
|
+
...(typeof value.error === 'string' ? { error: value.error } : {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Convert a convenience-request failure into the adapter's own error type. */
|
|
39
|
+
async function apiErrorOf(error, method) {
|
|
40
|
+
if (error instanceof MatrixApiError)
|
|
41
|
+
return error;
|
|
42
|
+
const failed = responseOf(error);
|
|
43
|
+
if (failed !== undefined) {
|
|
44
|
+
const body = await envelopeOf(failed);
|
|
45
|
+
return new MatrixApiError(`matrix ${method} answered ${failed.status}${body.errcode === undefined ? '' : `: ${body.errcode}`}${body.error === undefined ? '' : ` ${body.error}`}`, {
|
|
46
|
+
method,
|
|
47
|
+
status: failed.status,
|
|
48
|
+
...(body.errcode === undefined ? {} : { errcode: body.errcode }),
|
|
49
|
+
...(body.error === undefined ? {} : { error: body.error }),
|
|
50
|
+
cause: error,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return new MatrixApiError(`matrix ${method} request failed`, {
|
|
54
|
+
method,
|
|
55
|
+
cause: error,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Whether a failed registration means the virtual user already exists, so login is the right next step.
|
|
60
|
+
* @param error - the failure of `POST /register`.
|
|
61
|
+
* @returns true for a 400 `M_USER_IN_USE` (or a 400 without an envelope, which some homeservers send).
|
|
62
|
+
*/
|
|
63
|
+
async function isUserInUse(error) {
|
|
64
|
+
const failed = responseOf(error);
|
|
65
|
+
if (failed === undefined || failed.status !== 400)
|
|
66
|
+
return false;
|
|
67
|
+
const body = await envelopeOf(failed);
|
|
68
|
+
return body.errcode === undefined || body.errcode === 'M_USER_IN_USE';
|
|
69
|
+
}
|
|
70
|
+
/** Read the avatar bytes with the platform's own content type. */
|
|
71
|
+
async function downloadAvatar(ctx, url) {
|
|
72
|
+
// `get` with an identity decoder hands back the DOM response; a refused status rejects as the HTTP service's error.
|
|
73
|
+
const response = await ctx.http.get(url, { responseType: (raw) => raw });
|
|
74
|
+
const type = response.headers.get('content-type');
|
|
75
|
+
const data = new Uint8Array(await response.arrayBuffer());
|
|
76
|
+
return {
|
|
77
|
+
data,
|
|
78
|
+
mime: type === null || type === ''
|
|
79
|
+
? 'application/octet-stream'
|
|
80
|
+
: type.split(';')[0].trim(),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Establish the bot identity and store it on the adapter.
|
|
85
|
+
*
|
|
86
|
+
* @param bot - the adapter being connected.
|
|
87
|
+
* @throws MatrixApiError when the credentials, the namespace or the answered identity are wrong.
|
|
88
|
+
*/
|
|
89
|
+
export async function establishIdentity(bot) {
|
|
90
|
+
const config = bot.config;
|
|
91
|
+
const selfId = bot.selfId;
|
|
92
|
+
let user;
|
|
93
|
+
try {
|
|
94
|
+
user = await bot.internal.register(config.id, config.asToken);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (!(await isUserInUse(error)))
|
|
98
|
+
throw await apiErrorOf(error, '/client/v3/register');
|
|
99
|
+
try {
|
|
100
|
+
user = await bot.internal.login(config.id, config.asToken);
|
|
101
|
+
}
|
|
102
|
+
catch (loginError) {
|
|
103
|
+
throw await apiErrorOf(loginError, '/client/v3/login');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (user.user_id !== selfId) {
|
|
107
|
+
throw new MatrixApiError(`matrix: the homeserver answered user_id "${user.user_id ?? ''}" instead of "${selfId}"; check the registration's users namespaces`, { method: '/client/v3/register' });
|
|
108
|
+
}
|
|
109
|
+
if (user.access_token === undefined || user.access_token === '') {
|
|
110
|
+
throw new MatrixApiError('matrix: the homeserver answered no access_token; check as_token and the registration', {
|
|
111
|
+
method: '/client/v3/register',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
bot.request.setToken(user.access_token);
|
|
115
|
+
if (config.name !== undefined && config.name !== null && config.name !== '') {
|
|
116
|
+
await bot.internal.setDisplayName(selfId, config.name);
|
|
117
|
+
}
|
|
118
|
+
if (config.avatar !== undefined &&
|
|
119
|
+
config.avatar !== null &&
|
|
120
|
+
config.avatar !== '') {
|
|
121
|
+
const { data, mime } = await downloadAvatar(bot.ctx, config.avatar);
|
|
122
|
+
await bot.internal.setAvatar(selfId, Buffer.from(data), mime);
|
|
123
|
+
}
|
|
124
|
+
const profile = await bot.internal.getProfile(selfId);
|
|
125
|
+
bot.user = {
|
|
126
|
+
id: selfId,
|
|
127
|
+
name: profile.displayname ?? config.name ?? config.id,
|
|
128
|
+
...(profile.avatar_url === undefined || profile.avatar_url === ''
|
|
129
|
+
? {}
|
|
130
|
+
: {
|
|
131
|
+
avatar: internalMediaSource(bot, profile.avatar_url) ?? profile.avatar_url,
|
|
132
|
+
}),
|
|
133
|
+
isBot: true,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGhD,uDAAuD;AACvD,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,IAAI,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,EAAE,CAAA;AACvC,CAAC;AAED,oHAAoH;AACpH,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC;QACvE,OAAO,SAAS,CAAA;IAClB,MAAM,QAAQ,GA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,CAAC,UAAU,KAAK,EAAE;YAC/D,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC;gBACE,MAAM,EACJ,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,UAAU;aACrE,CAAC;QACN,KAAK,EAAE,IAAI;KACG,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MatrixBot, MatrixBot as default, type MatrixModes } from './bot.ts';
|
|
2
|
+
export { Config, configError, routePath, type Config as MatrixConfig, } from './config.ts';
|
|
3
|
+
export { classifyMatrixError, isTokenFailure, MatrixApiError, type MatrixApiErrorInit, } from './errors.ts';
|
|
4
|
+
export { MatrixClient, type MatrixRequestOptions } from './request.ts';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|