@openclaw/line 2026.11.12 → 2026.12.1-beta.2
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/dist/.setup/api-BFKOcDBj.mjs +3 -0
- package/dist/.setup/{api-CMPtJvIX.mjs → api-BHi0Jdse.mjs} +1 -1
- package/dist/.setup/{card-command-utjlRvb-.mjs → card-command-3YJcF1Sg.mjs} +2 -2
- package/dist/.setup/{channel-p6vbK7z1.mjs → channel-D8h0qJMW.mjs} +381 -18
- package/dist/.setup/channel.runtime-BBSUSMgH.mjs +4 -0
- package/dist/.setup/{monitor-D_RfCX20.mjs → monitor-B4Vqphj5.mjs} +7 -8
- package/dist/.setup/outbound.runtime-C41lKCRl.mjs +3 -0
- package/dist/.setup/{send-retry-D6J7bThI.mjs → schedule-cards-D2zI0jRv.mjs} +3 -352
- package/dist/.setup/send-Btj5Sv6v.mjs +664 -0
- package/dist/.setup/template-messages-5ZlXYNrb.mjs +198 -0
- package/dist/.source-module-urls/2c97352967966b7ab9f67f528eb25c098b6fe10ea0e4616ffae3851ed839d81e.json +1 -1
- package/dist/api.js +2 -2
- package/dist/channel-plugin-api.js +1 -1
- package/dist/index.js +1 -1
- package/dist/setup-entry.js +1 -1
- package/package.json +4 -4
- package/dist/.setup/api-B7qoCDpM.mjs +0 -3
- package/dist/.setup/channel.runtime-DlTsOqaQ.mjs +0 -4
- package/dist/.setup/outbound.runtime-BGlJ18sK.mjs +0 -3
- package/dist/.setup/send-H86JOXWw.mjs +0 -335
- package/dist/.setup/template-messages-B8c6X5DV.mjs +0 -464
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
import { C as uriAction, T as toFlexMessage, g as cardText, h as cardBox, u as createReceiptCard, w as fitsLineFlexBubble, x as postbackAction, y as messageAction } from "./send-retry-D6J7bThI.mjs";
|
|
2
|
-
import { markdownToIRWithMeta, stripMarkdown } from "openclaw/plugin-sdk/text-chunking";
|
|
3
|
-
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
4
|
-
// extensions/line/src/markdown-to-line.ts
|
|
5
|
-
const LINE_MARKDOWN_OPTIONS = {
|
|
6
|
-
assistantTranscriptRoleHeaders: true,
|
|
7
|
-
autolink: false,
|
|
8
|
-
blockquotePrefix: "",
|
|
9
|
-
headingStyle: "none",
|
|
10
|
-
horizontalRuleText: "",
|
|
11
|
-
linkify: false,
|
|
12
|
-
preserveSourceBlockSpacing: true
|
|
13
|
-
};
|
|
14
|
-
const TRANSCRIPT_ROLE_PREFIX = "[assistant-authored transcript] ";
|
|
15
|
-
const LINE_FLEX_CODE_CARD_MAX_CHARS = 2e3;
|
|
16
|
-
function parseLineMarkdown(text, tableMode = "block") {
|
|
17
|
-
return markdownToIRWithMeta(text, {
|
|
18
|
-
...LINE_MARKDOWN_OPTIONS,
|
|
19
|
-
tableMode
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
function rangesOverlap(left, right) {
|
|
23
|
-
return left.start < right.end && right.start < left.end;
|
|
24
|
-
}
|
|
25
|
-
/** A link shows its href after the label unless the label already is that address. */
|
|
26
|
-
function linkAddsHref(rawLabel, href) {
|
|
27
|
-
const label = rawLabel.trim();
|
|
28
|
-
return Boolean(href && label && label !== href && `mailto:${label}` !== href);
|
|
29
|
-
}
|
|
30
|
-
function projectPlainText(ir, omitted = [], additionalInsertions = [], onSegment) {
|
|
31
|
-
const insertions = [...additionalInsertions];
|
|
32
|
-
for (const link of ir.links) {
|
|
33
|
-
if (omitted.some((range) => rangesOverlap(range, link))) continue;
|
|
34
|
-
const href = link.href.trim();
|
|
35
|
-
if (linkAddsHref(ir.text.slice(link.start, link.end), href)) insertions.push({
|
|
36
|
-
position: link.end,
|
|
37
|
-
text: ` (${href})`
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
for (const annotation of ir.annotations ?? []) if (annotation.type === "assistant_transcript_role" && !omitted.some((range) => rangesOverlap(range, annotation))) insertions.push({
|
|
41
|
-
position: annotation.start,
|
|
42
|
-
text: TRANSCRIPT_ROLE_PREFIX
|
|
43
|
-
});
|
|
44
|
-
const inlineCodeSpans = ir.styles.filter((span) => span.style === "code" && !omitted.some((range) => rangesOverlap(range, span)));
|
|
45
|
-
for (const span of inlineCodeSpans) {
|
|
46
|
-
const code = ir.text.slice(span.start, span.end);
|
|
47
|
-
if (stripMarkdown(code, { assistantTranscriptRoleHeaders: true }).startsWith(TRANSCRIPT_ROLE_PREFIX)) insertions.push({
|
|
48
|
-
position: span.start,
|
|
49
|
-
text: TRANSCRIPT_ROLE_PREFIX
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
insertions.sort((left, right) => left.position - right.position);
|
|
53
|
-
const underlineTags = [...ir.text.matchAll(/<\/?u>/gi)].map((match) => ({
|
|
54
|
-
start: match.index,
|
|
55
|
-
end: match.index + match[0].length
|
|
56
|
-
})).filter((tag) => !inlineCodeSpans.some((span) => rangesOverlap(tag, span)) && !omitted.some((span) => rangesOverlap(tag, span)));
|
|
57
|
-
const removed = [...omitted, ...underlineTags].toSorted((left, right) => left.start - right.start);
|
|
58
|
-
let output = "";
|
|
59
|
-
let segmentStart = 0;
|
|
60
|
-
let cursor = 0;
|
|
61
|
-
let insertionIndex = 0;
|
|
62
|
-
const appendRange = (end) => {
|
|
63
|
-
while (insertionIndex < insertions.length) {
|
|
64
|
-
const insertion = insertions[insertionIndex];
|
|
65
|
-
if (!insertion || insertion.position > end) break;
|
|
66
|
-
if (insertion.position >= cursor) {
|
|
67
|
-
output += ir.text.slice(cursor, insertion.position);
|
|
68
|
-
if ("text" in insertion) output += insertion.text;
|
|
69
|
-
else if (onSegment) {
|
|
70
|
-
const precedingText = output.slice(segmentStart).trim();
|
|
71
|
-
if (precedingText) onSegment({
|
|
72
|
-
type: "text",
|
|
73
|
-
text: precedingText
|
|
74
|
-
});
|
|
75
|
-
onSegment({
|
|
76
|
-
type: "flex",
|
|
77
|
-
message: insertion.message
|
|
78
|
-
});
|
|
79
|
-
segmentStart = output.length;
|
|
80
|
-
}
|
|
81
|
-
cursor = insertion.position;
|
|
82
|
-
}
|
|
83
|
-
insertionIndex += 1;
|
|
84
|
-
}
|
|
85
|
-
output += ir.text.slice(cursor, end);
|
|
86
|
-
cursor = end;
|
|
87
|
-
};
|
|
88
|
-
for (const range of removed) {
|
|
89
|
-
appendRange(range.start);
|
|
90
|
-
cursor = Math.max(cursor, range.end);
|
|
91
|
-
while (insertionIndex < insertions.length && (insertions[insertionIndex]?.position ?? cursor) < cursor) insertionIndex += 1;
|
|
92
|
-
}
|
|
93
|
-
appendRange(ir.text.length);
|
|
94
|
-
if (onSegment) {
|
|
95
|
-
const trailingText = output.slice(segmentStart).trim();
|
|
96
|
-
if (trailingText) onSegment({
|
|
97
|
-
type: "text",
|
|
98
|
-
text: trailingText
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return output.trim();
|
|
102
|
-
}
|
|
103
|
-
function renderTableCell(cell) {
|
|
104
|
-
if (!cell.text.trim()) return {
|
|
105
|
-
text: "-",
|
|
106
|
-
hasMarkup: false
|
|
107
|
-
};
|
|
108
|
-
const codeSpans = cell.styles.filter((span) => span.style === "code");
|
|
109
|
-
const tags = [...cell.text.matchAll(/<\/?u>/gi)].map((match) => ({
|
|
110
|
-
start: match.index,
|
|
111
|
-
end: match.index + match[0].length,
|
|
112
|
-
closing: match[0][1] === "/"
|
|
113
|
-
})).filter((tag) => !codeSpans.some((span) => rangesOverlap(tag, span)));
|
|
114
|
-
const boundaries = /* @__PURE__ */ new Set([0, cell.text.length]);
|
|
115
|
-
for (const style of cell.styles) {
|
|
116
|
-
boundaries.add(style.start);
|
|
117
|
-
boundaries.add(style.end);
|
|
118
|
-
}
|
|
119
|
-
for (const link of cell.links) boundaries.add(link.end);
|
|
120
|
-
for (const tag of tags) {
|
|
121
|
-
boundaries.add(tag.start);
|
|
122
|
-
boundaries.add(tag.end);
|
|
123
|
-
}
|
|
124
|
-
const sortedBoundaries = [...boundaries].toSorted((left, right) => left - right);
|
|
125
|
-
const spans = [];
|
|
126
|
-
let underlineDepth = 0;
|
|
127
|
-
let hasMarkup = false;
|
|
128
|
-
const appendSpan = (span) => {
|
|
129
|
-
const previous = spans.at(-1);
|
|
130
|
-
if (previous && previous.weight === span.weight && previous.style === span.style && previous.decoration === span.decoration) previous.text = `${previous.text ?? ""}${span.text ?? ""}`;
|
|
131
|
-
else spans.push(span);
|
|
132
|
-
};
|
|
133
|
-
for (let index = 0; index < sortedBoundaries.length - 1; index += 1) {
|
|
134
|
-
const start = sortedBoundaries[index];
|
|
135
|
-
const end = sortedBoundaries[index + 1];
|
|
136
|
-
if (start === void 0 || end === void 0) continue;
|
|
137
|
-
const tag = tags.find((candidate) => candidate.start === start);
|
|
138
|
-
if (tag) {
|
|
139
|
-
underlineDepth += tag.closing ? -1 : 1;
|
|
140
|
-
hasMarkup = true;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
const text = cell.text.slice(start, end);
|
|
144
|
-
if (text) {
|
|
145
|
-
const active = new Set(cell.styles.filter((style) => style.start <= start && style.end >= end).map((style) => style.style));
|
|
146
|
-
const weight = active.has("bold") ? "bold" : void 0;
|
|
147
|
-
const style = active.has("italic") ? "italic" : void 0;
|
|
148
|
-
const decoration = active.has("strikethrough") ? "line-through" : underlineDepth > 0 ? "underline" : void 0;
|
|
149
|
-
hasMarkup ||= weight !== void 0 || style !== void 0 || decoration !== void 0;
|
|
150
|
-
appendSpan({
|
|
151
|
-
type: "span",
|
|
152
|
-
text,
|
|
153
|
-
weight,
|
|
154
|
-
style,
|
|
155
|
-
decoration
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
for (const link of cell.links.filter((candidate) => candidate.end === end)) {
|
|
159
|
-
const href = link.href.trim();
|
|
160
|
-
if (linkAddsHref(cell.text.slice(link.start, link.end), href)) {
|
|
161
|
-
appendSpan({
|
|
162
|
-
type: "span",
|
|
163
|
-
text: ` (${href})`
|
|
164
|
-
});
|
|
165
|
-
hasMarkup = true;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return {
|
|
170
|
-
text: spans.map((span) => span.text ?? "").join("").trim() || "-",
|
|
171
|
-
...hasMarkup ? { contents: spans } : {},
|
|
172
|
-
hasMarkup
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function convertTableToFlexBubble(table) {
|
|
176
|
-
const requiresPlainCells = table.rowCells.length > 10;
|
|
177
|
-
if (requiresPlainCells && (table.headers.length !== 2 || table.rowCells.length > 12)) return;
|
|
178
|
-
let hasInlineMarkup = false;
|
|
179
|
-
const renderCells = (cells) => {
|
|
180
|
-
const rendered = [];
|
|
181
|
-
for (const cell of cells) {
|
|
182
|
-
const prepared = renderTableCell(cell);
|
|
183
|
-
if (requiresPlainCells && prepared.hasMarkup) return;
|
|
184
|
-
hasInlineMarkup ||= prepared.hasMarkup;
|
|
185
|
-
rendered.push(prepared);
|
|
186
|
-
}
|
|
187
|
-
return rendered;
|
|
188
|
-
};
|
|
189
|
-
const headerCells = renderCells(table.headerCells);
|
|
190
|
-
if (!headerCells) return;
|
|
191
|
-
const rowCells = [];
|
|
192
|
-
for (const row of table.rowCells) {
|
|
193
|
-
const cells = renderCells(row);
|
|
194
|
-
if (!cells) return;
|
|
195
|
-
rowCells.push(cells);
|
|
196
|
-
}
|
|
197
|
-
if (table.headers.length === 2 && !hasInlineMarkup) return createReceiptCard({
|
|
198
|
-
title: headerCells.map((cell) => cell.text).join(" / "),
|
|
199
|
-
items: rowCells.map((row) => ({
|
|
200
|
-
name: row[0]?.text ?? "-",
|
|
201
|
-
value: row[1]?.text ?? "-"
|
|
202
|
-
}))
|
|
203
|
-
});
|
|
204
|
-
const renderRow = (cells, textStyle, rowStyle) => cardBox("horizontal", cells.map((cell) => cardText(cell.text, {
|
|
205
|
-
contents: cell.contents,
|
|
206
|
-
...textStyle,
|
|
207
|
-
size: "sm",
|
|
208
|
-
flex: 1,
|
|
209
|
-
wrap: true
|
|
210
|
-
})), rowStyle);
|
|
211
|
-
const headerRow = renderRow(headerCells, {
|
|
212
|
-
weight: "bold",
|
|
213
|
-
color: "#333333"
|
|
214
|
-
}, { paddingBottom: "sm" });
|
|
215
|
-
const dataRows = rowCells.map((row, rowIndex) => renderRow(table.headers.map((_, colIndex) => row[colIndex] ?? {
|
|
216
|
-
text: "-",
|
|
217
|
-
hasMarkup: false
|
|
218
|
-
}), { color: "#666666" }, { margin: rowIndex === 0 ? "md" : "sm" }));
|
|
219
|
-
return {
|
|
220
|
-
type: "bubble",
|
|
221
|
-
body: cardBox("vertical", [
|
|
222
|
-
headerRow,
|
|
223
|
-
{
|
|
224
|
-
type: "separator",
|
|
225
|
-
margin: "sm"
|
|
226
|
-
},
|
|
227
|
-
...dataRows
|
|
228
|
-
], { paddingAll: "lg" })
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
/** Parse once, route existing block surfaces to Flex, and project the remainder as plain text. */
|
|
232
|
-
function processLineMessage(text) {
|
|
233
|
-
const { ir, tables } = parseLineMarkdown(text);
|
|
234
|
-
const codeSpans = ir.styles.filter((span) => span.style === "code_block");
|
|
235
|
-
const plainTextInsertions = [];
|
|
236
|
-
for (const table of tables) {
|
|
237
|
-
const bubble = convertTableToFlexBubble(table);
|
|
238
|
-
if (!bubble || !fitsLineFlexBubble(bubble)) {
|
|
239
|
-
const markdownCell = (cell) => projectPlainText(cell).replace(/[\\|`*_[\]~<>&]/gu, "\\$&").replace(/\r?\n/gu, " ");
|
|
240
|
-
const markdownRow = (cells) => `| ${cells.map(markdownCell).join(" | ")} |`;
|
|
241
|
-
const markdown = [
|
|
242
|
-
markdownRow(table.headerCells),
|
|
243
|
-
`| ${table.headerCells.map(() => "---").join(" | ")} |`,
|
|
244
|
-
...table.rowCells.map(markdownRow)
|
|
245
|
-
].join("\n");
|
|
246
|
-
plainTextInsertions.push({
|
|
247
|
-
position: table.placeholderOffset,
|
|
248
|
-
text: `\n\n${projectPlainText(parseLineMarkdown(markdown, "bullets").ir)}\n\n`
|
|
249
|
-
});
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
const message = toFlexMessage("Table", bubble);
|
|
253
|
-
plainTextInsertions.push({
|
|
254
|
-
position: table.placeholderOffset,
|
|
255
|
-
message
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
for (const span of codeSpans) {
|
|
259
|
-
const block = {
|
|
260
|
-
...span.language ? { language: span.language } : {},
|
|
261
|
-
code: ir.text.slice(span.start, span.end).trimEnd()
|
|
262
|
-
};
|
|
263
|
-
if (!block.code.trim()) continue;
|
|
264
|
-
if (block.code.length > LINE_FLEX_CODE_CARD_MAX_CHARS) {
|
|
265
|
-
plainTextInsertions.push({
|
|
266
|
-
position: span.start,
|
|
267
|
-
text: `\n\n${block.code}\n\n`
|
|
268
|
-
});
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
const titleText = block.language ? `Code (${block.language})` : "Code";
|
|
272
|
-
plainTextInsertions.push({
|
|
273
|
-
position: span.start,
|
|
274
|
-
message: toFlexMessage("Code", {
|
|
275
|
-
type: "bubble",
|
|
276
|
-
body: cardBox("vertical", [cardText(titleText, {
|
|
277
|
-
weight: "bold",
|
|
278
|
-
size: "sm",
|
|
279
|
-
color: "#666666"
|
|
280
|
-
}), cardBox("vertical", [cardText(block.code, {
|
|
281
|
-
size: "xs",
|
|
282
|
-
color: "#333333",
|
|
283
|
-
wrap: true
|
|
284
|
-
})], {
|
|
285
|
-
backgroundColor: "#F5F5F5",
|
|
286
|
-
paddingAll: "md",
|
|
287
|
-
cornerRadius: "md",
|
|
288
|
-
margin: "sm"
|
|
289
|
-
})], { paddingAll: "lg" })
|
|
290
|
-
})
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
const segments = [];
|
|
294
|
-
projectPlainText(ir, codeSpans, plainTextInsertions, (segment) => segments.push(segment));
|
|
295
|
-
return segments;
|
|
296
|
-
}
|
|
297
|
-
// packages/normalization-core/src/utf16-slice.ts
|
|
298
|
-
function isHighSurrogate(codeUnit) {
|
|
299
|
-
return codeUnit >= 55296 && codeUnit <= 56319;
|
|
300
|
-
}
|
|
301
|
-
function isLowSurrogate(codeUnit) {
|
|
302
|
-
return codeUnit >= 56320 && codeUnit <= 57343;
|
|
303
|
-
}
|
|
304
|
-
/** Moves a chunk boundary away from the middle of a UTF-16 surrogate pair. */
|
|
305
|
-
function avoidTrailingHighSurrogateBreak(text, start, end) {
|
|
306
|
-
if (end <= start || end >= text.length || !isHighSurrogate(text.charCodeAt(end - 1)) || !isLowSurrogate(text.charCodeAt(end))) return end;
|
|
307
|
-
const adjusted = end - 1;
|
|
308
|
-
return adjusted > start ? adjusted : end + 1;
|
|
309
|
-
}
|
|
310
|
-
// packages/normalization-core/src/grapheme.ts
|
|
311
|
-
let graphemeSegmenter;
|
|
312
|
-
function getGraphemeSegmenter() {
|
|
313
|
-
graphemeSegmenter ??= new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
314
|
-
return graphemeSegmenter;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Chooses a whole-grapheme cut within the hard budget, honoring a usable preference.
|
|
318
|
-
* If no whole grapheme fits, allowPartial permits a surrogate-safe progress cut;
|
|
319
|
-
* a leading surrogate pair can exceed maxEnd by one code unit.
|
|
320
|
-
*/
|
|
321
|
-
function findGraphemeChunkEnd(text, start, maxEnd, preferredEnd = maxEnd, allowPartial = true) {
|
|
322
|
-
return graphemeChunkEndFinder(text, false)(start, maxEnd, preferredEnd, allowPartial);
|
|
323
|
-
}
|
|
324
|
-
function indexGraphemeBoundaries(text) {
|
|
325
|
-
const starts = new Uint32Array(Math.ceil(text.length / 32));
|
|
326
|
-
for (const { index } of getGraphemeSegmenter().segment(text)) {
|
|
327
|
-
const word = Math.floor(index / 32);
|
|
328
|
-
starts[word] = (starts[word] ?? 0) | 1 << index % 32;
|
|
329
|
-
}
|
|
330
|
-
const preceding = new Uint32Array(starts.length);
|
|
331
|
-
let last = 0;
|
|
332
|
-
for (const [word, bits] of starts.entries()) {
|
|
333
|
-
preceding[word] = last;
|
|
334
|
-
if (bits !== 0) last = word * 32 + 31 - Math.clz32(bits);
|
|
335
|
-
}
|
|
336
|
-
return (offset) => {
|
|
337
|
-
const word = Math.floor(offset / 32);
|
|
338
|
-
const throughOffset = 4294967295 >>> 31 - (offset & 31);
|
|
339
|
-
const bits = (starts[word] ?? 0) & throughOffset;
|
|
340
|
-
return bits === 0 ? preceding[word] ?? 0 : word * 32 + 31 - Math.clz32(bits);
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
function graphemeChunkEndFinder(text, reuse) {
|
|
344
|
-
let lastBoundary = 0;
|
|
345
|
-
let indexed;
|
|
346
|
-
return (start, maxEnd, preferredEnd = maxEnd, allowPartial = true) => {
|
|
347
|
-
const hardEnd = Math.min(maxEnd, text.length);
|
|
348
|
-
if (hardEnd <= start) return start;
|
|
349
|
-
const preferred = Number.isInteger(preferredEnd) && preferredEnd > start && preferredEnd <= hardEnd ? preferredEnd : hardEnd;
|
|
350
|
-
if (preferred === text.length) return preferred;
|
|
351
|
-
const before = text.charCodeAt(preferred - 1);
|
|
352
|
-
const after = text.charCodeAt(preferred);
|
|
353
|
-
if (Number.isInteger(preferred) && before <= 127 && after <= 127 && !(before === 13 && after === 10)) {
|
|
354
|
-
lastBoundary = preferred;
|
|
355
|
-
return preferred;
|
|
356
|
-
}
|
|
357
|
-
const from = start === 0 ? 0 : lastBoundary ?? 0;
|
|
358
|
-
if (reuse && start !== 0 && (lastBoundary === void 0 || from > start || start - from > hardEnd - start)) indexed ??= indexGraphemeBoundaries(text);
|
|
359
|
-
const segments = indexed ? void 0 : getGraphemeSegmenter().segment(text.slice(from, hardEnd + 2));
|
|
360
|
-
const boundaryAt = indexed ?? ((position) => from + (segments?.containing(position - from)?.index ?? position - from));
|
|
361
|
-
let end = boundaryAt(preferred);
|
|
362
|
-
if (end <= start && preferred < hardEnd) end = hardEnd === text.length ? hardEnd : boundaryAt(hardEnd);
|
|
363
|
-
if (end > start) {
|
|
364
|
-
lastBoundary = end;
|
|
365
|
-
return end;
|
|
366
|
-
}
|
|
367
|
-
if (allowPartial) {
|
|
368
|
-
lastBoundary = void 0;
|
|
369
|
-
return avoidTrailingHighSurrogateBreak(text, start, hardEnd);
|
|
370
|
-
}
|
|
371
|
-
return start;
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
// extensions/line/src/template-messages.ts
|
|
375
|
-
const COMPACT_TEMPLATE_TEXT_LIMIT = 60;
|
|
376
|
-
const TEMPLATE_ALT_TEXT_LIMIT = 1500;
|
|
377
|
-
function buildTemplatePayloadAction(action) {
|
|
378
|
-
if (action.type === "uri" && action.uri) return uriAction(action.label, action.uri);
|
|
379
|
-
if (action.type === "postback" && action.data) return postbackAction(action.label, action.data, action.label);
|
|
380
|
-
return messageAction(action.label, action.data ?? action.label);
|
|
381
|
-
}
|
|
382
|
-
function buildInferredTemplateAction(label, data) {
|
|
383
|
-
return data.startsWith("http") ? uriAction(label, data) : data.includes("=") ? postbackAction(label, data, label) : messageAction(label, data);
|
|
384
|
-
}
|
|
385
|
-
function resolveTemplateTextLimit(title, thumbnailImageUrl, textOnlyLimit) {
|
|
386
|
-
return title !== void 0 || thumbnailImageUrl !== void 0 ? COMPACT_TEMPLATE_TEXT_LIMIT : textOnlyLimit;
|
|
387
|
-
}
|
|
388
|
-
function truncateTemplateText(text, limit) {
|
|
389
|
-
const end = findGraphemeChunkEnd(text, 0, limit, limit, false);
|
|
390
|
-
return end > 0 ? text.slice(0, end) : truncateUtf16Safe(text, limit);
|
|
391
|
-
}
|
|
392
|
-
function resolveTemplateAltText(value, fallback) {
|
|
393
|
-
return truncateTemplateText(value ?? fallback, TEMPLATE_ALT_TEXT_LIMIT);
|
|
394
|
-
}
|
|
395
|
-
function buildTemplateMessageFromPayload(payload) {
|
|
396
|
-
switch (payload.type) {
|
|
397
|
-
case "confirm": return {
|
|
398
|
-
type: "template",
|
|
399
|
-
altText: resolveTemplateAltText(payload.altText, payload.text),
|
|
400
|
-
template: {
|
|
401
|
-
type: "confirm",
|
|
402
|
-
text: truncateTemplateText(payload.text, 240),
|
|
403
|
-
actions: [buildInferredTemplateAction(payload.confirmLabel, payload.confirmData), buildInferredTemplateAction(payload.cancelLabel, payload.cancelData)]
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
case "buttons": {
|
|
407
|
-
const title = payload.title || void 0;
|
|
408
|
-
const textLimit = resolveTemplateTextLimit(title, payload.thumbnailImageUrl, 160);
|
|
409
|
-
return {
|
|
410
|
-
type: "template",
|
|
411
|
-
altText: resolveTemplateAltText(payload.altText, title ? `${title}: ${payload.text}` : payload.text),
|
|
412
|
-
template: {
|
|
413
|
-
type: "buttons",
|
|
414
|
-
...title ? { title: truncateTemplateText(title, 40) } : {},
|
|
415
|
-
text: truncateTemplateText(payload.text, textLimit),
|
|
416
|
-
actions: payload.actions.slice(0, 4).map(buildTemplatePayloadAction),
|
|
417
|
-
thumbnailImageUrl: payload.thumbnailImageUrl,
|
|
418
|
-
imageAspectRatio: "rectangle",
|
|
419
|
-
imageSize: "cover",
|
|
420
|
-
imageBackgroundColor: void 0,
|
|
421
|
-
defaultAction: void 0
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
case "carousel": {
|
|
426
|
-
const visibleColumns = payload.columns.map((column) => {
|
|
427
|
-
const title = column.title || void 0;
|
|
428
|
-
const textLimit = resolveTemplateTextLimit(title, column.thumbnailImageUrl, 120);
|
|
429
|
-
return {
|
|
430
|
-
title: title === void 0 ? void 0 : truncateTemplateText(title, 40),
|
|
431
|
-
text: truncateTemplateText(column.text, textLimit),
|
|
432
|
-
actions: column.actions.map(buildTemplatePayloadAction).filter((action) => action.label !== void 0 && action.label !== "").slice(0, 3),
|
|
433
|
-
thumbnailImageUrl: column.thumbnailImageUrl,
|
|
434
|
-
imageBackgroundColor: void 0,
|
|
435
|
-
defaultAction: void 0
|
|
436
|
-
};
|
|
437
|
-
}).slice(0, 10);
|
|
438
|
-
const first = visibleColumns[0];
|
|
439
|
-
if (!first || visibleColumns.some((column) => column.text === "" || column.actions.length === 0 || column.title === void 0 !== (first.title === void 0) || column.actions.length !== first.actions.length)) {
|
|
440
|
-
const text = [...payload.altText ? [truncateTemplateText(payload.altText, TEMPLATE_ALT_TEXT_LIMIT)] : [], ...visibleColumns.map((column) => {
|
|
441
|
-
const body = column.title ? `${column.title}: ${column.text}` : column.text;
|
|
442
|
-
const labels = column.actions.map((action) => action.label).filter((label) => label !== void 0 && label !== "");
|
|
443
|
-
return labels.length > 0 ? `${body} (${labels.join(" / ")})` : body;
|
|
444
|
-
}).filter((line) => line !== "")].join("\n");
|
|
445
|
-
return text ? {
|
|
446
|
-
type: "text",
|
|
447
|
-
text
|
|
448
|
-
} : null;
|
|
449
|
-
}
|
|
450
|
-
return {
|
|
451
|
-
type: "template",
|
|
452
|
-
altText: resolveTemplateAltText(payload.altText, "View carousel"),
|
|
453
|
-
template: {
|
|
454
|
-
type: "carousel",
|
|
455
|
-
columns: visibleColumns,
|
|
456
|
-
imageAspectRatio: "rectangle",
|
|
457
|
-
imageSize: "cover"
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
default: return null;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
export { processLineMessage as n, buildTemplateMessageFromPayload as t };
|