@im-more/dsh-kook 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 +12 -0
  3. package/lib/index.js +2380 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/types/bot.d.ts +53 -0
  6. package/lib/types/bot.d.ts.map +1 -0
  7. package/lib/types/bot.js +138 -0
  8. package/lib/types/bot.js.map +1 -0
  9. package/lib/types/config.d.ts +46 -0
  10. package/lib/types/config.d.ts.map +1 -0
  11. package/lib/types/config.js +52 -0
  12. package/lib/types/config.js.map +1 -0
  13. package/lib/types/decode.d.ts +88 -0
  14. package/lib/types/decode.d.ts.map +1 -0
  15. package/lib/types/decode.js +564 -0
  16. package/lib/types/decode.js.map +1 -0
  17. package/lib/types/errors.d.ts +46 -0
  18. package/lib/types/errors.d.ts.map +1 -0
  19. package/lib/types/errors.js +159 -0
  20. package/lib/types/errors.js.map +1 -0
  21. package/lib/types/identity.d.ts +17 -0
  22. package/lib/types/identity.d.ts.map +1 -0
  23. package/lib/types/identity.js +24 -0
  24. package/lib/types/identity.js.map +1 -0
  25. package/lib/types/index.d.ts +15 -0
  26. package/lib/types/index.d.ts.map +1 -0
  27. package/lib/types/index.js +15 -0
  28. package/lib/types/index.js.map +1 -0
  29. package/lib/types/kmarkdown.d.ts +76 -0
  30. package/lib/types/kmarkdown.d.ts.map +1 -0
  31. package/lib/types/kmarkdown.js +201 -0
  32. package/lib/types/kmarkdown.js.map +1 -0
  33. package/lib/types/modes/kmarkdown.d.ts +17 -0
  34. package/lib/types/modes/kmarkdown.d.ts.map +1 -0
  35. package/lib/types/modes/kmarkdown.js +166 -0
  36. package/lib/types/modes/kmarkdown.js.map +1 -0
  37. package/lib/types/modes/shared.d.ts +192 -0
  38. package/lib/types/modes/shared.d.ts.map +1 -0
  39. package/lib/types/modes/shared.js +371 -0
  40. package/lib/types/modes/shared.js.map +1 -0
  41. package/lib/types/request.d.ts +53 -0
  42. package/lib/types/request.d.ts.map +1 -0
  43. package/lib/types/request.js +147 -0
  44. package/lib/types/request.js.map +1 -0
  45. package/lib/types/send.d.ts +57 -0
  46. package/lib/types/send.d.ts.map +1 -0
  47. package/lib/types/send.js +141 -0
  48. package/lib/types/send.js.map +1 -0
  49. package/lib/types/types.d.ts +807 -0
  50. package/lib/types/types.d.ts.map +1 -0
  51. package/lib/types/types.js +168 -0
  52. package/lib/types/types.js.map +1 -0
  53. package/lib/types/webhook.d.ts +35 -0
  54. package/lib/types/webhook.d.ts.map +1 -0
  55. package/lib/types/webhook.js +132 -0
  56. package/lib/types/webhook.js.map +1 -0
  57. package/lib/types/ws.d.ts +54 -0
  58. package/lib/types/ws.d.ts.map +1 -0
  59. package/lib/types/ws.js +358 -0
  60. package/lib/types/ws.js.map +1 -0
  61. package/package.json +61 -3
  62. package/src/bot.ts +217 -0
  63. package/src/config.ts +84 -0
  64. package/src/decode.ts +660 -0
  65. package/src/errors.ts +188 -0
  66. package/src/identity.ts +32 -0
  67. package/src/index.ts +80 -0
  68. package/src/kmarkdown.ts +246 -0
  69. package/src/modes/kmarkdown.ts +204 -0
  70. package/src/modes/shared.ts +498 -0
  71. package/src/request.ts +196 -0
  72. package/src/send.ts +216 -0
  73. package/src/types.ts +764 -0
  74. package/src/webhook.ts +170 -0
  75. package/src/ws.ts +431 -0
  76. package/README.md +0 -3
@@ -0,0 +1,159 @@
1
+ import { PlatformError } from '@deepseek-ai/cordis-plugin-im-core';
2
+ /** One failed KOOK call: an HTTP answer, a non-zero business code, or a Gateway refusal code. */
3
+ export class KookApiError extends Error {
4
+ status;
5
+ code;
6
+ retryAfterMs;
7
+ constructor(message, init = {}) {
8
+ super(message, init.cause === undefined ? undefined : { cause: init.cause });
9
+ this.name = 'KookApiError';
10
+ this.status = init.status;
11
+ this.code = init.code;
12
+ this.retryAfterMs = init.retryAfterMs;
13
+ }
14
+ }
15
+ /** The configured `selfId` and the account the bot token belongs to disagree. */
16
+ export class KookIdentityError extends Error {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = 'KookIdentityError';
20
+ }
21
+ }
22
+ /** HELLO codes that only a corrected configuration can fix (missing parameter, invalid/failed/expired token). */
23
+ const PERMANENT_HELLO_CODES = new Set([40100, 40101, 40102, 40103]);
24
+ /** RECONNECT codes that report a resume/session/sn refusal; v1 does not resume, so the connection is simply redialed. */
25
+ const RESUME_CODES = new Set([40106, 40107, 40108]);
26
+ /**
27
+ * Whether a HELLO answer means the configured token cannot work at all.
28
+ * @param code - `d.code` of the HELLO frame.
29
+ * @returns true for the four documented configuration refusals.
30
+ */
31
+ export function isPermanentHelloCode(code) {
32
+ return code !== undefined && PERMANENT_HELLO_CODES.has(code);
33
+ }
34
+ /**
35
+ * Whether a RECONNECT notice names a resume/session refusal.
36
+ * @param code - `d.code` of the RECONNECT frame.
37
+ * @returns true for the three documented resume refusals.
38
+ */
39
+ export function isResumeCode(code) {
40
+ return code !== undefined && RESUME_CODES.has(code);
41
+ }
42
+ /** Whether a caught value is the abort error of a cancelled request. */
43
+ function isAbortError(error) {
44
+ return ((error instanceof Error || error instanceof DOMException) &&
45
+ error.name === 'AbortError');
46
+ }
47
+ /**
48
+ * Map any KOOK failure onto the core platform taxonomy.
49
+ *
50
+ * A non-2xx answer and a non-zero business code are the platform refusing the call, so nothing was published; a
51
+ * transport failure or a 5xx answer leaves the outcome unknown. Business codes are not interpreted beyond the two
52
+ * documented Gateway ranges, because KOOK publishes no error-code reference (the linked page is gone).
53
+ *
54
+ * @param error - the caught failure.
55
+ * @returns the classified platform error.
56
+ */
57
+ export function classifyKookError(error) {
58
+ if (error instanceof PlatformError)
59
+ return error;
60
+ if (isAbortError(error)) {
61
+ return new PlatformError('fatal', error instanceof Error ? error.message : 'kook request aborted', { published: 'unknown', cause: error });
62
+ }
63
+ if (error instanceof KookApiError) {
64
+ const init = {
65
+ ...(error.code === undefined ? {} : { code: error.code }),
66
+ ...(error.retryAfterMs === undefined
67
+ ? {}
68
+ : { retryAfterMs: error.retryAfterMs }),
69
+ cause: error,
70
+ };
71
+ if (error.code !== undefined && error.status === undefined) {
72
+ // A Gateway refusal: the HELLO and RECONNECT code tables are the only documented ones.
73
+ if (isPermanentHelloCode(error.code)) {
74
+ return new PlatformError('permission', error.message, {
75
+ ...init,
76
+ published: 'no',
77
+ });
78
+ }
79
+ if (isResumeCode(error.code)) {
80
+ return new PlatformError('fatal', error.message, {
81
+ ...init,
82
+ published: 'no',
83
+ });
84
+ }
85
+ return new PlatformError('invalid', error.message, {
86
+ ...init,
87
+ published: 'no',
88
+ });
89
+ }
90
+ if (error.status === 429) {
91
+ return new PlatformError('rate-limit', error.message, {
92
+ ...init,
93
+ published: 'no',
94
+ });
95
+ }
96
+ if (error.code !== undefined) {
97
+ // An HTTP answer that also carries a business code: the status already says what happened.
98
+ if (error.status === 401 || error.status === 403) {
99
+ return new PlatformError('permission', error.message, {
100
+ ...init,
101
+ published: 'no',
102
+ });
103
+ }
104
+ if (error.status === 404) {
105
+ return new PlatformError('not-found', error.message, {
106
+ ...init,
107
+ published: 'no',
108
+ });
109
+ }
110
+ if (error.status !== undefined && error.status >= 500) {
111
+ return new PlatformError('retryable', error.message, {
112
+ ...init,
113
+ published: 'unknown',
114
+ });
115
+ }
116
+ return new PlatformError('invalid', error.message, {
117
+ ...init,
118
+ published: 'no',
119
+ });
120
+ }
121
+ if (error.status === 401 || error.status === 403) {
122
+ return new PlatformError('permission', error.message, {
123
+ ...init,
124
+ published: 'no',
125
+ });
126
+ }
127
+ if (error.status === 404) {
128
+ return new PlatformError('not-found', error.message, {
129
+ ...init,
130
+ published: 'no',
131
+ });
132
+ }
133
+ if (error.status !== undefined &&
134
+ error.status >= 400 &&
135
+ error.status < 500) {
136
+ return new PlatformError('invalid', error.message, {
137
+ ...init,
138
+ published: 'no',
139
+ });
140
+ }
141
+ if (error.status !== undefined && error.status >= 500) {
142
+ return new PlatformError('retryable', error.message, {
143
+ ...init,
144
+ published: 'unknown',
145
+ });
146
+ }
147
+ // No status at all: the request never completed, so the platform may have acted.
148
+ return new PlatformError('retryable', error.message, {
149
+ ...init,
150
+ published: 'unknown',
151
+ });
152
+ }
153
+ const message = error instanceof Error ? error.message : String(error);
154
+ return new PlatformError('retryable', `kook request failed: ${message}`, {
155
+ published: 'unknown',
156
+ cause: error,
157
+ });
158
+ }
159
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAalE,iGAAiG;AACjG,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,MAAM,CAAoB;IAC1B,IAAI,CAAoB;IACxB,YAAY,CAAoB;IAEzC,YAAY,OAAe,EAAE,OAAyB,EAAE;QACtD,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;QAC5E,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACrB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAA;IACvC,CAAC;CACF;AAED,iFAAiF;AACjF,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;CACF;AAED,iHAAiH;AACjH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;AA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CAAA;QACJ,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;YACtD,OAAO,IAAI,aAAa,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,EAAE;gBACnD,GAAG,IAAI;gBACP,SAAS,EAAE,SAAS;aACrB,CAAC,CAAA;QACJ,CAAC;QACD,iFAAiF;QACjF,OAAO,IAAI,aAAa,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,EAAE;YACnD,GAAG,IAAI;YACP,SAAS,EAAE,SAAS;SACrB,CAAC,CAAA;IACJ,CAAC;IAED,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,wBAAwB,OAAO,EAAE,EAAE;QACvE,SAAS,EAAE,SAAS;QACpB,KAAK,EAAE,KAAK;KACb,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { KookRequest } from './request.ts';
2
+ import type { Self } from './types.ts';
3
+ /**
4
+ * Verify that the bot token belongs to the configured bot.
5
+ *
6
+ * The token is an opaque platform-issued string, so the bot id cannot be derived from it; `selfId` is configured and
7
+ * checked here. The host keys `ctx.bots`, `sources.bot` and the intake dedupe key on `bot.id`, so a mismatch is a
8
+ * configuration error that reconnecting cannot fix.
9
+ *
10
+ * @param request - endpoints for this bot.
11
+ * @param selfId - the configured bot user id.
12
+ * @param signal - cancellation of the transport that asked.
13
+ * @returns the bot's own user record.
14
+ * @throws KookIdentityError when `/user/me` reports another account.
15
+ */
16
+ export declare function verifyIdentity(request: KookRequest, selfId: string, signal?: AbortSignal): Promise<Self>;
17
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC;;;;;;;;;;;;GAYG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CASf"}
@@ -0,0 +1,24 @@
1
+ import { KookIdentityError } from "./errors.js";
2
+ import { invoke } from "./request.js";
3
+ /**
4
+ * Verify that the bot token belongs to the configured bot.
5
+ *
6
+ * The token is an opaque platform-issued string, so the bot id cannot be derived from it; `selfId` is configured and
7
+ * checked here. The host keys `ctx.bots`, `sources.bot` and the intake dedupe key on `bot.id`, so a mismatch is a
8
+ * configuration error that reconnecting cannot fix.
9
+ *
10
+ * @param request - endpoints for this bot.
11
+ * @param selfId - the configured bot user id.
12
+ * @param signal - cancellation of the transport that asked.
13
+ * @returns the bot's own user record.
14
+ * @throws KookIdentityError when `/user/me` reports another account.
15
+ */
16
+ export async function verifyIdentity(request, selfId, signal) {
17
+ const user = await invoke(request, 'GET', '/user/me', undefined, signal);
18
+ const actual = user === undefined || user === null ? '' : String(user.id);
19
+ if (actual !== selfId) {
20
+ throw new KookIdentityError(`kook: selfId is configured as ${selfId} but the bot token belongs to ${actual === '' ? 'an unknown account' : actual}; fix selfId and restart`);
21
+ }
22
+ return user;
23
+ }
24
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAIrC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAoB,EACpB,MAAc,EACd,MAAoB;IAEpB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAO,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAA;IAC9E,MAAM,MAAM,GAAG,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACzE,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,MAAM,IAAI,iBAAiB,CACzB,iCAAiC,MAAM,iCAAiC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,MAAM,0BAA0B,CAChJ,CAAA;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,15 @@
1
+ export * as Kook from './types.ts';
2
+ export { KookBot, KookBot as default, type KookModes } from './bot.ts';
3
+ export { Config, configError, routePath, type KookConfig, type KookProtocol, } from './config.ts';
4
+ export { classifyKookError, isPermanentHelloCode, isResumeCode, KookApiError, KookIdentityError, type KookApiErrorInit, } from './errors.ts';
5
+ export { verifyIdentity } from './identity.ts';
6
+ export { escapeKMarkdown, parseKMarkdown, splitKMarkdown, unescapeKMarkdown, visibleLength, type KookMentionNames, type KookMentionRole, type KookMentionUser, } from './kmarkdown.ts';
7
+ export { chatOfMessage, decodeCard, decodeContent, decodeEvent, decodeInboundMessage, decodeMessage, parseTextMentions, referrerOf, userRefOf, type KookReferrer, } from './decode.ts';
8
+ export { createKmarkdownMode } from './modes/kmarkdown.ts';
9
+ export { assembleDraft, chunk, fileName, groupImages, KOOK_LIMITS, mediaNode, serializeDraft, textNode, textOf, themeOf, withMark, type KookButtonNode, type KookDraft, type KookImageDraft, type KookModeTypes, type KookModuleDraft, type KookNode, type KookPayload, type KookTheme, } from './modes/shared.ts';
10
+ export { createKookRequest, invoke, retryAfterOf, type KookEnvelope, type KookRequest, } from './request.ts';
11
+ export { deletePart, getMessage, isDirectChannel, members, sendPayload, } from './send.ts';
12
+ export { Internal } from './types.ts';
13
+ export { KookWebhook } from './webhook.ts';
14
+ export { KookWsTransport } from './ws.ts';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAA;AAElC,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAA;AACtE,OAAO,EACL,MAAM,EACN,WAAW,EACX,SAAS,EACT,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EACL,eAAe,EACf,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,aAAa,EACb,UAAU,EACV,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,KAAK,YAAY,GAClB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EACL,aAAa,EACb,KAAK,EACL,QAAQ,EACR,WAAW,EACX,WAAW,EACX,SAAS,EACT,cAAc,EACd,QAAQ,EACR,MAAM,EACN,OAAO,EACP,QAAQ,EACR,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,SAAS,GACf,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,iBAAiB,EACjB,MAAM,EACN,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,UAAU,EACV,UAAU,EACV,eAAe,EACf,OAAO,EACP,WAAW,GACZ,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,15 @@
1
+ export * as Kook from "./types.js";
2
+ export { KookBot, KookBot as default } from "./bot.js";
3
+ export { Config, configError, routePath, } from "./config.js";
4
+ export { classifyKookError, isPermanentHelloCode, isResumeCode, KookApiError, KookIdentityError, } from "./errors.js";
5
+ export { verifyIdentity } from "./identity.js";
6
+ export { escapeKMarkdown, parseKMarkdown, splitKMarkdown, unescapeKMarkdown, visibleLength, } from "./kmarkdown.js";
7
+ export { chatOfMessage, decodeCard, decodeContent, decodeEvent, decodeInboundMessage, decodeMessage, parseTextMentions, referrerOf, userRefOf, } from "./decode.js";
8
+ export { createKmarkdownMode } from "./modes/kmarkdown.js";
9
+ export { assembleDraft, chunk, fileName, groupImages, KOOK_LIMITS, mediaNode, serializeDraft, textNode, textOf, themeOf, withMark, } from "./modes/shared.js";
10
+ export { createKookRequest, invoke, retryAfterOf, } from "./request.js";
11
+ export { deletePart, getMessage, isDirectChannel, members, sendPayload, } from "./send.js";
12
+ export { Internal } from "./types.js";
13
+ export { KookWebhook } from "./webhook.js";
14
+ export { KookWsTransport } from "./ws.js";
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAA;AAElC,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAkB,MAAM,UAAU,CAAA;AACtE,OAAO,EACL,MAAM,EACN,WAAW,EACX,SAAS,GAGV,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACZ,YAAY,EACZ,iBAAiB,GAElB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EACL,eAAe,EACf,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,aAAa,GAId,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,aAAa,EACb,UAAU,EACV,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,SAAS,GAEV,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EACL,aAAa,EACb,KAAK,EACL,QAAQ,EACR,WAAW,EACX,WAAW,EACX,SAAS,EACT,cAAc,EACd,QAAQ,EACR,MAAM,EACN,OAAO,EACP,QAAQ,GAST,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,iBAAiB,EACjB,MAAM,EACN,YAAY,GAGb,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,UAAU,EACV,UAAU,EACV,eAAe,EACf,OAAO,EACP,WAAW,GACZ,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * KMarkdown text handling: the escaping the platform requires, the inbound `(met|chn|rol)` tokens, and the
3
+ * visible-length splitter the message budgets use.
4
+ *
5
+ * Escaping follows the upstream adapter exactly: a backslash goes in front of `\`, `*`, `` ` ``, `~`, `(` and `)`, so
6
+ * user text cannot open a control sequence or a formatting run. `[` and `]` stay unescaped because a lone one is
7
+ * harmless.
8
+ */
9
+ import type { Element } from '@deepseek-ai/cordis-plugin-im-core';
10
+ /** One mention name KOOK reports alongside a kmarkdown message. */
11
+ export interface KookMentionUser {
12
+ id: string;
13
+ username: string;
14
+ }
15
+ /** One role mention name KOOK reports alongside a kmarkdown message. */
16
+ export interface KookMentionRole {
17
+ role_id: number;
18
+ name: string;
19
+ }
20
+ /** Names that give kmarkdown mention tokens a readable label. */
21
+ export interface KookMentionNames {
22
+ users?: readonly KookMentionUser[];
23
+ roles?: readonly KookMentionRole[];
24
+ }
25
+ /**
26
+ * Escape user text for KMarkdown.
27
+ * @param text - plain text.
28
+ * @returns the text with the six metacharacters escaped.
29
+ */
30
+ export declare function escapeKMarkdown(text: string): string;
31
+ /**
32
+ * Undo KMarkdown escaping.
33
+ * @param text - escaped text.
34
+ * @returns the text with `\x` collapsed to `x`.
35
+ */
36
+ export declare function unescapeKMarkdown(text: string): string;
37
+ /**
38
+ * Parse the kmarkdown body of one message into content elements.
39
+ *
40
+ * Only the control sequences KOOK defines are interpreted; markdown syntax (`**bold**`, `> quote`, fences) stays in
41
+ * the text as the platform sent it, because rewriting the source would show the model something the user did not
42
+ * write.
43
+ *
44
+ * @param content - `d.content` of a kind-9 message.
45
+ * @param names - mention and role names of `extra.kmarkdown`.
46
+ * @returns the decoded content nodes, in source order.
47
+ */
48
+ export declare function parseKMarkdown(content: string, names?: KookMentionNames): Element[];
49
+ /**
50
+ * Visible characters of a kmarkdown body: control sequences and escape pairs count once, like a rendered mention.
51
+ * @param content - kmarkdown text.
52
+ * @returns the number of visible characters.
53
+ */
54
+ export declare function visibleLength(content: string): number;
55
+ /**
56
+ * Split a kmarkdown body into chunks of at most `limit` visible characters.
57
+ *
58
+ * The cut prefers the last line break of the window, then the last space, then a hard cut, and it never lands inside
59
+ * an escape pair or a control sequence. Concatenating the chunks returns the input exactly: splitting moves no
60
+ * character and adds no marker.
61
+ *
62
+ * @param content - kmarkdown text.
63
+ * @param limit - visible characters per chunk.
64
+ * @returns the chunks, in order.
65
+ */
66
+ export declare function splitKMarkdown(content: string, limit: number): string[];
67
+ /**
68
+ * Encode the inline kmarkdown of a subtree, for a control that only carries text (a card button).
69
+ * @param nodes - rendered text fragments.
70
+ * @returns the concatenated kmarkdown.
71
+ */
72
+ export declare function inlineKMarkdown(nodes: readonly {
73
+ type: 'text';
74
+ text: string;
75
+ }[]): string;
76
+ //# sourceMappingURL=kmarkdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kmarkdown.d.ts","sourceRoot":"","sources":["../../src/kmarkdown.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAA;AAEjE,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,wEAAwE;AACxE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb;AAED,iEAAiE;AACjE,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,SAAS,eAAe,EAAE,CAAA;IAClC,KAAK,CAAC,EAAE,SAAS,eAAe,EAAE,CAAA;CACnC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,gBAAqB,GAC3B,OAAO,EAAE,CAwDX;AA2CD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIrD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CA+CvE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,GAC/C,MAAM,CAER"}
@@ -0,0 +1,201 @@
1
+ /**
2
+ * KMarkdown text handling: the escaping the platform requires, the inbound `(met|chn|rol)` tokens, and the
3
+ * visible-length splitter the message budgets use.
4
+ *
5
+ * Escaping follows the upstream adapter exactly: a backslash goes in front of `\`, `*`, `` ` ``, `~`, `(` and `)`, so
6
+ * user text cannot open a control sequence or a formatting run. `[` and `]` stay unescaped because a lone one is
7
+ * harmless.
8
+ */
9
+ import { h } from '@deepseek-ai/cordis-plugin-im-core';
10
+ /**
11
+ * Escape user text for KMarkdown.
12
+ * @param text - plain text.
13
+ * @returns the text with the six metacharacters escaped.
14
+ */
15
+ export function escapeKMarkdown(text) {
16
+ return text.replace(/[\\*`~()]/g, '\\$&');
17
+ }
18
+ /**
19
+ * Undo KMarkdown escaping.
20
+ * @param text - escaped text.
21
+ * @returns the text with `\x` collapsed to `x`.
22
+ */
23
+ export function unescapeKMarkdown(text) {
24
+ return text.replace(/\\(.)/g, '$1');
25
+ }
26
+ /** Token of one kmarkdown control sequence, including the emoji form. */
27
+ const CONTROL = /^\((met|chn|rol)\)([\w-]+)\(\1\)/;
28
+ const EMOJI = /^\(emj\)([^()]*)\(emj\)\[([^\]]*)\]/;
29
+ /**
30
+ * Parse the kmarkdown body of one message into content elements.
31
+ *
32
+ * Only the control sequences KOOK defines are interpreted; markdown syntax (`**bold**`, `> quote`, fences) stays in
33
+ * the text as the platform sent it, because rewriting the source would show the model something the user did not
34
+ * write.
35
+ *
36
+ * @param content - `d.content` of a kind-9 message.
37
+ * @param names - mention and role names of `extra.kmarkdown`.
38
+ * @returns the decoded content nodes, in source order.
39
+ */
40
+ export function parseKMarkdown(content, names = {}) {
41
+ const users = names.users ?? [];
42
+ const roles = names.roles ?? [];
43
+ const elements = [];
44
+ let buffer = '';
45
+ let rest = content;
46
+ const flush = () => {
47
+ if (buffer === '')
48
+ return;
49
+ elements.push(h.text(buffer));
50
+ buffer = '';
51
+ };
52
+ while (rest !== '') {
53
+ if (rest.startsWith('\\') && rest.length > 1) {
54
+ buffer += rest[1];
55
+ rest = rest.slice(2);
56
+ continue;
57
+ }
58
+ const control = CONTROL.exec(rest);
59
+ if (control !== null) {
60
+ const whole = control.at(0) ?? '';
61
+ const kind = control.at(1) ?? '';
62
+ const id = control.at(2) ?? '';
63
+ rest = rest.slice(whole.length);
64
+ flush();
65
+ if (kind === 'met') {
66
+ if (id === 'all' || id === 'here') {
67
+ elements.push(h('at', { type: id }));
68
+ }
69
+ else {
70
+ const name = users.find((user) => user.id === id)?.username;
71
+ elements.push(h('at', {
72
+ type: 'user',
73
+ id,
74
+ ...(name === undefined ? {} : { name }),
75
+ }));
76
+ }
77
+ }
78
+ else if (kind === 'chn') {
79
+ elements.push(h('channel', { id }));
80
+ }
81
+ else {
82
+ const name = roles.find((role) => String(role.role_id) === id)?.name;
83
+ elements.push(h('at', {
84
+ type: 'role',
85
+ id,
86
+ ...(name === undefined ? {} : { name }),
87
+ }));
88
+ }
89
+ continue;
90
+ }
91
+ buffer += rest.charAt(0);
92
+ rest = rest.slice(1);
93
+ }
94
+ flush();
95
+ return elements;
96
+ }
97
+ /** Split a kmarkdown body into the pieces a cut may not break. */
98
+ function tokenize(content) {
99
+ const tokens = [];
100
+ let rest = content;
101
+ while (rest !== '') {
102
+ if (rest.startsWith('\\') && rest.length > 1) {
103
+ tokens.push({
104
+ raw: rest.slice(0, 2),
105
+ visible: 1,
106
+ newline: false,
107
+ space: false,
108
+ });
109
+ rest = rest.slice(2);
110
+ continue;
111
+ }
112
+ const control = CONTROL.exec(rest) ?? EMOJI.exec(rest);
113
+ if (control !== null) {
114
+ const whole = control.at(0) ?? '';
115
+ tokens.push({ raw: whole, visible: 1, newline: false, space: false });
116
+ rest = rest.slice(whole.length);
117
+ continue;
118
+ }
119
+ const codePoint = rest.codePointAt(0);
120
+ const raw = String.fromCodePoint(codePoint);
121
+ tokens.push({ raw, visible: 1, newline: raw === '\n', space: raw === ' ' });
122
+ rest = rest.slice(raw.length);
123
+ }
124
+ return tokens;
125
+ }
126
+ /**
127
+ * Visible characters of a kmarkdown body: control sequences and escape pairs count once, like a rendered mention.
128
+ * @param content - kmarkdown text.
129
+ * @returns the number of visible characters.
130
+ */
131
+ export function visibleLength(content) {
132
+ let length = 0;
133
+ for (const token of tokenize(content))
134
+ length += token.visible;
135
+ return length;
136
+ }
137
+ /**
138
+ * Split a kmarkdown body into chunks of at most `limit` visible characters.
139
+ *
140
+ * The cut prefers the last line break of the window, then the last space, then a hard cut, and it never lands inside
141
+ * an escape pair or a control sequence. Concatenating the chunks returns the input exactly: splitting moves no
142
+ * character and adds no marker.
143
+ *
144
+ * @param content - kmarkdown text.
145
+ * @param limit - visible characters per chunk.
146
+ * @returns the chunks, in order.
147
+ */
148
+ export function splitKMarkdown(content, limit) {
149
+ const tokens = tokenize(content);
150
+ if (tokens.reduce((sum, token) => sum + token.visible, 0) <= limit)
151
+ return [content];
152
+ const chunks = [];
153
+ let start = 0;
154
+ while (start < tokens.length) {
155
+ let end = start;
156
+ let visible = 0;
157
+ while (end < tokens.length && visible + tokens[end].visible <= limit) {
158
+ visible += tokens[end].visible;
159
+ end += 1;
160
+ }
161
+ if (end === tokens.length) {
162
+ chunks.push(tokens
163
+ .slice(start)
164
+ .map((token) => token.raw)
165
+ .join(''));
166
+ break;
167
+ }
168
+ let cut = end;
169
+ for (let index = end - 1; index >= start; index--) {
170
+ if (tokens[index].newline) {
171
+ cut = index + 1;
172
+ break;
173
+ }
174
+ }
175
+ if (cut === end) {
176
+ for (let index = end - 1; index >= start; index--) {
177
+ if (tokens[index].space) {
178
+ cut = index + 1;
179
+ break;
180
+ }
181
+ }
182
+ }
183
+ if (cut <= start)
184
+ cut = start + 1;
185
+ chunks.push(tokens
186
+ .slice(start, cut)
187
+ .map((token) => token.raw)
188
+ .join(''));
189
+ start = cut;
190
+ }
191
+ return chunks;
192
+ }
193
+ /**
194
+ * Encode the inline kmarkdown of a subtree, for a control that only carries text (a card button).
195
+ * @param nodes - rendered text fragments.
196
+ * @returns the concatenated kmarkdown.
197
+ */
198
+ export function inlineKMarkdown(nodes) {
199
+ return nodes.map((node) => node.text).join('');
200
+ }
201
+ //# sourceMappingURL=kmarkdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kmarkdown.js","sourceRoot":"","sources":["../../src/kmarkdown.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,oCAAoC,CAAA;AAqBtD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA;AAC3C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;AACrC,CAAC;AAED,yEAAyE;AACzE,MAAM,OAAO,GAAG,kCAAkC,CAAA;AAClD,MAAM,KAAK,GAAG,qCAAqC,CAAA;AAEnD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAe,EACf,QAA0B,EAAE;IAE5B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,EAAE,CAAA;IAC/B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,EAAE,CAAA;IAC/B,MAAM,QAAQ,GAAc,EAAE,CAAA;IAC9B,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAI,IAAI,GAAG,OAAO,CAAA;IAClB,MAAM,KAAK,GAAG,GAAS,EAAE;QACvB,IAA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EAAE,KAAK,IAAI,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;YAClD,IAAI,MAAM,CAAC,KAAK,CAAE,CAAC,OAAO,EAAE,CAAC;gBAC3B,GAAG,GAAG,KAAK,GAAG,CAAC,CAAA;gBACf,MAAK;YACP,CAAC;QACH,CAAC;QACD,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;YAChB,KAAK,IAAI,KAAK,GAAG,GAAG,GAAG,CAAC,EAAE,KAAK,IAAI,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;gBAClD,IAAI,MAAM,CAAC,KAAK,CAAE,CAAC,KAAK,EAAE,CAAC;oBACzB,GAAG,GAAG,KAAK,GAAG,CAAC,CAAA;oBACf,MAAK;gBACP,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,GAAG,IAAI,KAAK;YAAE,GAAG,GAAG,KAAK,GAAG,CAAC,CAAA;QACjC,MAAM,CAAC,IAAI,CACT,MAAM;aACH,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC;aACjB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC;aACzB,IAAI,CAAC,EAAE,CAAC,CACZ,CAAA;QACD,KAAK,GAAG,GAAG,CAAA;IACb,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAgD;IAEhD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAChD,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The single `kmarkdown` mode: KOOK message text with its KMarkdown markup, and a card when the content needs one.
3
+ *
4
+ * Native tags are the ones the upstream encoder renders (`text`, `p`, `br`, `b`, `i`, `u`, `s`, `spoiler`, `code`,
5
+ * `a`, `at`, `channel`, `emoji`) plus the block structure KMarkdown shows as text (headings, lists, quotes, fences, a
6
+ * divider) and the media and buttons that only a card module can carry. A `<button type="input">` is not declared: a
7
+ * click that sends a text as the reader has no card component, so the core fallback renders its label and command.
8
+ * Everything else takes the core fallback, which keeps its text — the platform has no second way to render it.
9
+ */
10
+ import type { Mode } from '@deepseek-ai/cordis-plugin-im-core';
11
+ import type { KookModeTypes } from './shared.ts';
12
+ /**
13
+ * Build the `kmarkdown` mode.
14
+ * @returns the only mode of this adapter.
15
+ */
16
+ export declare function createKmarkdownMode(): Mode<KookModeTypes>;
17
+ //# sourceMappingURL=kmarkdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kmarkdown.d.ts","sourceRoot":"","sources":["../../../src/modes/kmarkdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAiB,MAAM,oCAAoC,CAAA;AAiB7E,OAAO,KAAK,EAAkB,aAAa,EAAY,MAAM,aAAa,CAAA;AA2C1E;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,aAAa,CAAC,CAgIzD"}