@minjun0219/mdwire 0.1.10 → 0.1.11
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/README.md +20 -6
- package/bundler/mdwire.d.ts +42 -39
- package/bundler/mdwire_bg.js +51 -48
- package/bundler/mdwire_bg.wasm +0 -0
- package/js/events.d.ts +5 -5
- package/js/events.js +2 -2
- package/js/react.d.ts +10 -10
- package/js/react.js +15 -14
- package/node/mdwire.d.ts +42 -39
- package/node/mdwire.js +51 -48
- package/node/mdwire_bg.wasm +0 -0
- package/package.json +3 -3
package/node/mdwire.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @ts-self-types="./mdwire.d.ts" */
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* `renderWithReport
|
|
4
|
+
* The result of `renderWithReport`.
|
|
5
5
|
*/
|
|
6
6
|
class Rendered {
|
|
7
7
|
static __wrap(ptr) {
|
|
@@ -21,7 +21,7 @@ class Rendered {
|
|
|
21
21
|
wasm.__wbg_rendered_free(ptr, 0);
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* The parts. Just one if the text fit within the limit.
|
|
25
25
|
* @returns {string[]}
|
|
26
26
|
*/
|
|
27
27
|
get parts() {
|
|
@@ -38,7 +38,7 @@ class Rendered {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
41
|
+
* What normalization repaired.
|
|
42
42
|
* @returns {Repairs}
|
|
43
43
|
*/
|
|
44
44
|
get repairs() {
|
|
@@ -50,7 +50,7 @@ if (Symbol.dispose) Rendered.prototype[Symbol.dispose] = Rendered.prototype.free
|
|
|
50
50
|
exports.Rendered = Rendered;
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* Counts of what normalization repaired and what was changed to fit the channel.
|
|
54
54
|
*/
|
|
55
55
|
class Repairs {
|
|
56
56
|
static __wrap(ptr) {
|
|
@@ -70,7 +70,7 @@ class Repairs {
|
|
|
70
70
|
wasm.__wbg_repairs_free(ptr, 0);
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* Emphasis left open at the end of a block, closed for you.
|
|
74
74
|
* @returns {number}
|
|
75
75
|
*/
|
|
76
76
|
get closedEmphasis() {
|
|
@@ -78,7 +78,7 @@ class Repairs {
|
|
|
78
78
|
return ret >>> 0;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* Code fences left open at the end of the document, closed for you.
|
|
82
82
|
* @returns {number}
|
|
83
83
|
*/
|
|
84
84
|
get closedFence() {
|
|
@@ -86,7 +86,7 @@ class Repairs {
|
|
|
86
86
|
return ret >>> 0;
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
89
|
+
* Emphasis markers and `<url|text>` links rewritten in a different notation.
|
|
90
90
|
* @returns {number}
|
|
91
91
|
*/
|
|
92
92
|
get convertedMarker() {
|
|
@@ -94,7 +94,7 @@ class Repairs {
|
|
|
94
94
|
return ret >>> 0;
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
97
|
+
* Unmatched `**` markers that were dropped.
|
|
98
98
|
* @returns {number}
|
|
99
99
|
*/
|
|
100
100
|
get droppedMarker() {
|
|
@@ -102,7 +102,7 @@ class Repairs {
|
|
|
102
102
|
return ret >>> 0;
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
105
|
+
* Characters escaped because the channel would read them as syntax (GitHub's `\~`, `\<`, `\*`).
|
|
106
106
|
* @returns {number}
|
|
107
107
|
*/
|
|
108
108
|
get escapedChar() {
|
|
@@ -110,7 +110,7 @@ class Repairs {
|
|
|
110
110
|
return ret >>> 0;
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
|
-
*
|
|
113
|
+
* Unmatched backtick runs, turned back into literal text.
|
|
114
114
|
* @returns {number}
|
|
115
115
|
*/
|
|
116
116
|
get revertedCodeSpan() {
|
|
@@ -118,7 +118,7 @@ class Repairs {
|
|
|
118
118
|
return ret >>> 0;
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
121
|
+
* List bullets rewritten with a different symbol.
|
|
122
122
|
* @returns {number}
|
|
123
123
|
*/
|
|
124
124
|
get rewrittenBullet() {
|
|
@@ -126,7 +126,7 @@ class Repairs {
|
|
|
126
126
|
return ret >>> 0;
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
129
|
-
*
|
|
129
|
+
* Tables rewritten in a different shape from the source.
|
|
130
130
|
* @returns {number}
|
|
131
131
|
*/
|
|
132
132
|
get rewrittenTable() {
|
|
@@ -134,7 +134,7 @@ class Repairs {
|
|
|
134
134
|
return ret >>> 0;
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
|
-
*
|
|
137
|
+
* Raw HTML stripped from the source (tags, comments, and `<br>` turned into line breaks).
|
|
138
138
|
* @returns {number}
|
|
139
139
|
*/
|
|
140
140
|
get strippedHtml() {
|
|
@@ -142,7 +142,7 @@ class Repairs {
|
|
|
142
142
|
return ret >>> 0;
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
|
-
*
|
|
145
|
+
* Emphasis emitted differently because the channel would not read the marker in that position (GitHub's `<strong>`, Slack's U+2060).
|
|
146
146
|
* @returns {number}
|
|
147
147
|
*/
|
|
148
148
|
get tagEmphasis() {
|
|
@@ -150,70 +150,70 @@ class Repairs {
|
|
|
150
150
|
return ret >>> 0;
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
153
|
-
*
|
|
153
|
+
* Emphasis left open at the end of a block, closed for you.
|
|
154
154
|
* @param {number} arg0
|
|
155
155
|
*/
|
|
156
156
|
set closedEmphasis(arg0) {
|
|
157
157
|
wasm.__wbg_set_repairs_closedEmphasis(this.__wbg_ptr, arg0);
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
|
-
*
|
|
160
|
+
* Code fences left open at the end of the document, closed for you.
|
|
161
161
|
* @param {number} arg0
|
|
162
162
|
*/
|
|
163
163
|
set closedFence(arg0) {
|
|
164
164
|
wasm.__wbg_set_repairs_closedFence(this.__wbg_ptr, arg0);
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
|
-
*
|
|
167
|
+
* Emphasis markers and `<url|text>` links rewritten in a different notation.
|
|
168
168
|
* @param {number} arg0
|
|
169
169
|
*/
|
|
170
170
|
set convertedMarker(arg0) {
|
|
171
171
|
wasm.__wbg_set_repairs_convertedMarker(this.__wbg_ptr, arg0);
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
|
-
*
|
|
174
|
+
* Unmatched `**` markers that were dropped.
|
|
175
175
|
* @param {number} arg0
|
|
176
176
|
*/
|
|
177
177
|
set droppedMarker(arg0) {
|
|
178
178
|
wasm.__wbg_set_repairs_droppedMarker(this.__wbg_ptr, arg0);
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
|
-
*
|
|
181
|
+
* Characters escaped because the channel would read them as syntax (GitHub's `\~`, `\<`, `\*`).
|
|
182
182
|
* @param {number} arg0
|
|
183
183
|
*/
|
|
184
184
|
set escapedChar(arg0) {
|
|
185
185
|
wasm.__wbg_set_repairs_escapedChar(this.__wbg_ptr, arg0);
|
|
186
186
|
}
|
|
187
187
|
/**
|
|
188
|
-
*
|
|
188
|
+
* Unmatched backtick runs, turned back into literal text.
|
|
189
189
|
* @param {number} arg0
|
|
190
190
|
*/
|
|
191
191
|
set revertedCodeSpan(arg0) {
|
|
192
192
|
wasm.__wbg_set_repairs_revertedCodeSpan(this.__wbg_ptr, arg0);
|
|
193
193
|
}
|
|
194
194
|
/**
|
|
195
|
-
*
|
|
195
|
+
* List bullets rewritten with a different symbol.
|
|
196
196
|
* @param {number} arg0
|
|
197
197
|
*/
|
|
198
198
|
set rewrittenBullet(arg0) {
|
|
199
199
|
wasm.__wbg_set_repairs_rewrittenBullet(this.__wbg_ptr, arg0);
|
|
200
200
|
}
|
|
201
201
|
/**
|
|
202
|
-
*
|
|
202
|
+
* Tables rewritten in a different shape from the source.
|
|
203
203
|
* @param {number} arg0
|
|
204
204
|
*/
|
|
205
205
|
set rewrittenTable(arg0) {
|
|
206
206
|
wasm.__wbg_set_repairs_rewrittenTable(this.__wbg_ptr, arg0);
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
|
-
*
|
|
209
|
+
* Raw HTML stripped from the source (tags, comments, and `<br>` turned into line breaks).
|
|
210
210
|
* @param {number} arg0
|
|
211
211
|
*/
|
|
212
212
|
set strippedHtml(arg0) {
|
|
213
213
|
wasm.__wbg_set_repairs_strippedHtml(this.__wbg_ptr, arg0);
|
|
214
214
|
}
|
|
215
215
|
/**
|
|
216
|
-
*
|
|
216
|
+
* Emphasis emitted differently because the channel would not read the marker in that position (GitHub's `<strong>`, Slack's U+2060).
|
|
217
217
|
* @param {number} arg0
|
|
218
218
|
*/
|
|
219
219
|
set tagEmphasis(arg0) {
|
|
@@ -224,10 +224,11 @@ if (Symbol.dispose) Repairs.prototype[Symbol.dispose] = Repairs.prototype.free;
|
|
|
224
224
|
exports.Repairs = Repairs;
|
|
225
225
|
|
|
226
226
|
/**
|
|
227
|
-
*
|
|
227
|
+
* Streaming converter.
|
|
228
228
|
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
229
|
+
* Push a chunk and it returns only what is safe to emit now. Markup cut off at the
|
|
230
|
+
* chunk boundary stays inside. This is what you want when appending tokens to the
|
|
231
|
+
* screen as they arrive.
|
|
231
232
|
*/
|
|
232
233
|
class Streamer {
|
|
233
234
|
__destroy_into_raw() {
|
|
@@ -241,14 +242,15 @@ class Streamer {
|
|
|
241
242
|
wasm.__wbg_streamer_free(ptr, 0);
|
|
242
243
|
}
|
|
243
244
|
/**
|
|
244
|
-
*
|
|
245
|
+
* **To send what you have received so far as is, append this after it.**
|
|
245
246
|
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
247
|
+
* It does not touch the state, so streaming continues afterwards. Do not add it
|
|
248
|
+
* to the accumulated output itself; append it only right before sending. Use it
|
|
249
|
+
* when editing a message as tokens arrive.
|
|
248
250
|
*
|
|
249
251
|
* ```js
|
|
250
252
|
* acc += s.push(chunk);
|
|
251
|
-
* await edit(acc + s.closeOpen()); //
|
|
253
|
+
* await edit(acc + s.closeOpen()); // leave acc unchanged
|
|
252
254
|
* ```
|
|
253
255
|
* @returns {string}
|
|
254
256
|
*/
|
|
@@ -269,7 +271,7 @@ class Streamer {
|
|
|
269
271
|
}
|
|
270
272
|
}
|
|
271
273
|
/**
|
|
272
|
-
*
|
|
274
|
+
* Input has ended. Emits what is left and closes open markup.
|
|
273
275
|
* @returns {string}
|
|
274
276
|
*/
|
|
275
277
|
finish() {
|
|
@@ -312,15 +314,16 @@ class Streamer {
|
|
|
312
314
|
}
|
|
313
315
|
}
|
|
314
316
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
317
|
+
* **The tail that would follow the final output if input ended now.** It goes in the
|
|
318
|
+
* same place as `closeOpen`, but also draws what is being held back (open emphasis,
|
|
319
|
+
* table rows, code spans). This is the default when you redraw the whole message.
|
|
320
|
+
* It is a guess, so later chunks may change the shape. Check `revised()` after the end.
|
|
318
321
|
*
|
|
319
322
|
* ```js
|
|
320
323
|
* acc += s.push(chunk);
|
|
321
|
-
* await edit(acc + s.preview()); //
|
|
324
|
+
* await edit(acc + s.preview()); // call only when drawing (costs as much as the open block)
|
|
322
325
|
* acc += s.finish();
|
|
323
|
-
* if (s.revised()) await edit(acc); //
|
|
326
|
+
* if (s.revised()) await edit(acc); // skip if the last screen already is the final output
|
|
324
327
|
* ```
|
|
325
328
|
* @returns {string}
|
|
326
329
|
*/
|
|
@@ -363,7 +366,7 @@ class Streamer {
|
|
|
363
366
|
}
|
|
364
367
|
}
|
|
365
368
|
/**
|
|
366
|
-
*
|
|
369
|
+
* What normalization has repaired so far. After `finish`, this covers the whole document.
|
|
367
370
|
* @returns {Repairs}
|
|
368
371
|
*/
|
|
369
372
|
repairs() {
|
|
@@ -371,7 +374,7 @@ class Streamer {
|
|
|
371
374
|
return Repairs.__wrap(ret);
|
|
372
375
|
}
|
|
373
376
|
/**
|
|
374
|
-
*
|
|
377
|
+
* Whether the final output differs from the last `preview()`. Check it after `finish`.
|
|
375
378
|
* @returns {boolean}
|
|
376
379
|
*/
|
|
377
380
|
revised() {
|
|
@@ -383,7 +386,7 @@ if (Symbol.dispose) Streamer.prototype[Symbol.dispose] = Streamer.prototype.free
|
|
|
383
386
|
exports.Streamer = Streamer;
|
|
384
387
|
|
|
385
388
|
/**
|
|
386
|
-
*
|
|
389
|
+
* The channel's length limit (in characters). Exposed for callers that handle parts themselves.
|
|
387
390
|
* @param {string} channel
|
|
388
391
|
* @returns {number}
|
|
389
392
|
*/
|
|
@@ -407,7 +410,7 @@ function limit(channel) {
|
|
|
407
410
|
exports.limit = limit;
|
|
408
411
|
|
|
409
412
|
/**
|
|
410
|
-
*
|
|
413
|
+
* Converts a complete document. Returns an array of parts; it has more than one when the text exceeds the limit.
|
|
411
414
|
* @param {string} input
|
|
412
415
|
* @param {string} channel
|
|
413
416
|
* @param {RenderOptions | null} [options]
|
|
@@ -438,8 +441,8 @@ function render(input, channel, options) {
|
|
|
438
441
|
exports.render = render;
|
|
439
442
|
|
|
440
443
|
/**
|
|
441
|
-
* [`render`]
|
|
442
|
-
*
|
|
444
|
+
* Like [`render`], but also returns **what normalization repaired**. Use it to log
|
|
445
|
+
* how often the model breaks formatting.
|
|
443
446
|
* @param {string} input
|
|
444
447
|
* @param {string} channel
|
|
445
448
|
* @param {RenderOptions | null} [options]
|
|
@@ -483,30 +486,30 @@ function __wbg_get_imports() {
|
|
|
483
486
|
__wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
|
|
484
487
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
485
488
|
},
|
|
486
|
-
|
|
489
|
+
__wbg_html_89b49615556b2850: function(arg0) {
|
|
487
490
|
const ret = getObject(arg0).html;
|
|
488
491
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
489
492
|
},
|
|
490
|
-
|
|
493
|
+
__wbg_images_fc88426d1f55bdfc: function(arg0, arg1) {
|
|
491
494
|
const ret = getObject(arg1).images;
|
|
492
495
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
493
496
|
var len1 = WASM_VECTOR_LEN;
|
|
494
497
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
495
498
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
496
499
|
},
|
|
497
|
-
|
|
500
|
+
__wbg_limit_d1453e73fbf788db: function(arg0, arg1) {
|
|
498
501
|
const ret = getObject(arg1).limit;
|
|
499
502
|
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
500
503
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
501
504
|
},
|
|
502
|
-
|
|
505
|
+
__wbg_lineBreaks_8b98689e9716a2c8: function(arg0, arg1) {
|
|
503
506
|
const ret = getObject(arg1).lineBreaks;
|
|
504
507
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
505
508
|
var len1 = WASM_VECTOR_LEN;
|
|
506
509
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
507
510
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
508
511
|
},
|
|
509
|
-
|
|
512
|
+
__wbg_schemes_8e39175723a07726: function(arg0, arg1) {
|
|
510
513
|
const ret = getObject(arg1).schemes;
|
|
511
514
|
var ptr1 = isLikeNone(ret) ? 0 : passArrayJsValueToWasm0(ret, wasm.__wbindgen_export);
|
|
512
515
|
var len1 = WASM_VECTOR_LEN;
|
package/node/mdwire_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minjun0219/mdwire",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.11",
|
|
4
|
+
"description": "Send LLM-generated Markdown to Telegram, Slack, GitHub and Notion without it breaking: repaired, rendered for each channel and split within its limit, streaming included. Also safe HTML and React.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": { "type": "git", "url": "https://github.com/minjun0219/mdwire" },
|
|
7
7
|
"homepage": "https://mdwire.minjun.dev",
|
|
8
|
-
"keywords": ["markdown", "telegram", "slack", "github", "
|
|
8
|
+
"keywords": ["markdown", "llm", "ai", "agent", "chatbot", "telegram", "telegram-bot", "slack", "slack-bot", "github", "notion", "react", "streaming", "wasm"],
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "./node/mdwire.js",
|
|
11
11
|
"types": "./bundler/mdwire.d.ts",
|