@kodelyth/line 2026.5.39 → 2026.5.42

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 (120) hide show
  1. package/api.ts +11 -0
  2. package/channel-plugin-api.ts +1 -0
  3. package/contract-api.ts +5 -0
  4. package/dist/accounts-CD4A1FE7.js +105 -0
  5. package/dist/api.js +11 -0
  6. package/dist/basic-cards-BISytiSa.js +307 -0
  7. package/dist/card-command-dQBX3fVN.js +240 -0
  8. package/dist/channel-DV5h44-j.js +649 -0
  9. package/dist/channel-plugin-api.js +2 -0
  10. package/dist/channel.runtime-Cc-v3szZ.js +4 -0
  11. package/dist/contract-api.js +2 -0
  12. package/dist/index.js +45 -0
  13. package/dist/markdown-to-line-CC3BU6CC.js +810 -0
  14. package/dist/monitor-Ci8Hg8ay.js +1485 -0
  15. package/dist/monitor.runtime-t6-QvlDB.js +2 -0
  16. package/dist/outbound.runtime-D1CxEvcL.js +2 -0
  17. package/dist/probe-BPSs_A_8.js +30 -0
  18. package/dist/probe.runtime-7u2o9QN5.js +2 -0
  19. package/dist/reply-payload-transform-CDuBzoT4.js +855 -0
  20. package/dist/runtime-api.js +291 -0
  21. package/dist/schedule-cards-D-yZMHDE.js +359 -0
  22. package/dist/secret-contract-api.js +5 -0
  23. package/dist/setup-api.js +2 -0
  24. package/dist/setup-entry.js +11 -0
  25. package/dist/setup-surface-CHfQ6Z4i.js +282 -0
  26. package/index.ts +53 -0
  27. package/klaw.plugin.json +2 -329
  28. package/package.json +4 -4
  29. package/runtime-api.ts +179 -0
  30. package/secret-contract-api.ts +4 -0
  31. package/setup-api.ts +2 -0
  32. package/setup-entry.ts +9 -0
  33. package/src/account-helpers.ts +16 -0
  34. package/src/accounts.test.ts +288 -0
  35. package/src/accounts.ts +187 -0
  36. package/src/actions.ts +61 -0
  37. package/src/auto-reply-delivery.test.ts +253 -0
  38. package/src/auto-reply-delivery.ts +200 -0
  39. package/src/bindings.ts +65 -0
  40. package/src/bot-access.ts +30 -0
  41. package/src/bot-handlers.test.ts +1094 -0
  42. package/src/bot-handlers.ts +620 -0
  43. package/src/bot-message-context.test.ts +420 -0
  44. package/src/bot-message-context.ts +586 -0
  45. package/src/bot.ts +66 -0
  46. package/src/card-command.ts +347 -0
  47. package/src/channel-access-token.ts +14 -0
  48. package/src/channel-api.ts +17 -0
  49. package/src/channel-setup-status.contract.test.ts +70 -0
  50. package/src/channel-shared.ts +48 -0
  51. package/src/channel.logout.test.ts +145 -0
  52. package/src/channel.runtime.ts +3 -0
  53. package/src/channel.sendPayload.test.ts +659 -0
  54. package/src/channel.setup.ts +11 -0
  55. package/src/channel.status.test.ts +63 -0
  56. package/src/channel.ts +155 -0
  57. package/src/config-adapter.ts +29 -0
  58. package/src/config-schema.test.ts +53 -0
  59. package/src/config-schema.ts +81 -0
  60. package/src/download.test.ts +164 -0
  61. package/src/download.ts +34 -0
  62. package/src/flex-templates/basic-cards.ts +395 -0
  63. package/src/flex-templates/common.ts +20 -0
  64. package/src/flex-templates/media-control-cards.ts +555 -0
  65. package/src/flex-templates/message.ts +13 -0
  66. package/src/flex-templates/schedule-cards.ts +467 -0
  67. package/src/flex-templates/types.ts +22 -0
  68. package/src/flex-templates.ts +32 -0
  69. package/src/gateway.ts +129 -0
  70. package/src/group-keys.test.ts +123 -0
  71. package/src/group-keys.ts +65 -0
  72. package/src/group-policy.ts +22 -0
  73. package/src/markdown-to-line.test.ts +348 -0
  74. package/src/markdown-to-line.ts +416 -0
  75. package/src/message-cards.test.ts +204 -0
  76. package/src/monitor-durable.test.ts +57 -0
  77. package/src/monitor-durable.ts +37 -0
  78. package/src/monitor.lifecycle.test.ts +499 -0
  79. package/src/monitor.runtime.ts +1 -0
  80. package/src/monitor.ts +507 -0
  81. package/src/outbound-media.test.ts +194 -0
  82. package/src/outbound-media.ts +120 -0
  83. package/src/outbound.runtime.ts +12 -0
  84. package/src/outbound.ts +427 -0
  85. package/src/probe.contract.test.ts +9 -0
  86. package/src/probe.runtime.ts +1 -0
  87. package/src/probe.ts +34 -0
  88. package/src/quick-reply-fallback.ts +10 -0
  89. package/src/reply-chunks.test.ts +180 -0
  90. package/src/reply-chunks.ts +110 -0
  91. package/src/reply-payload-transform.test.ts +392 -0
  92. package/src/reply-payload-transform.ts +317 -0
  93. package/src/rich-menu.test.ts +315 -0
  94. package/src/rich-menu.ts +326 -0
  95. package/src/runtime.ts +32 -0
  96. package/src/send-receipt.ts +32 -0
  97. package/src/send.test.ts +453 -0
  98. package/src/send.ts +531 -0
  99. package/src/setup-core.ts +149 -0
  100. package/src/setup-runtime-api.ts +9 -0
  101. package/src/setup-surface.test.ts +481 -0
  102. package/src/setup-surface.ts +229 -0
  103. package/src/signature.test.ts +34 -0
  104. package/src/signature.ts +24 -0
  105. package/src/status.ts +37 -0
  106. package/src/template-messages.ts +333 -0
  107. package/src/types.ts +130 -0
  108. package/src/webhook-node.test.ts +598 -0
  109. package/src/webhook-node.ts +155 -0
  110. package/src/webhook-utils.ts +10 -0
  111. package/src/webhook.ts +135 -0
  112. package/tsconfig.json +16 -0
  113. package/api.js +0 -7
  114. package/channel-plugin-api.js +0 -7
  115. package/contract-api.js +0 -7
  116. package/index.js +0 -7
  117. package/runtime-api.js +0 -7
  118. package/secret-contract-api.js +0 -7
  119. package/setup-api.js +0 -7
  120. package/setup-entry.js +0 -7
@@ -0,0 +1,855 @@
1
+ import { n as createEventCard, t as createAgendaCard } from "./schedule-cards-D-yZMHDE.js";
2
+ import { normalizeAccountId } from "klaw/plugin-sdk/account-id";
3
+ import { resolveAccountEntry } from "klaw/plugin-sdk/account-resolution";
4
+ import { buildChannelConfigSchema, requireOpenAllowFrom } from "klaw/plugin-sdk/channel-config-schema";
5
+ import { requireChannelOpenAllowFrom } from "klaw/plugin-sdk/extension-shared";
6
+ import { z } from "zod";
7
+ import { createPluginRuntimeStore } from "klaw/plugin-sdk/runtime-store";
8
+ import { createMessageReceiptFromOutboundResults } from "klaw/plugin-sdk/channel-message";
9
+ import { resolvePinnedHostnameWithPolicy } from "klaw/plugin-sdk/ssrf-runtime";
10
+ import { normalizeLowercaseStringOrEmpty } from "klaw/plugin-sdk/string-coerce-runtime";
11
+ //#region extensions/line/src/group-keys.ts
12
+ function resolveLineGroupLookupIds(groupId) {
13
+ const normalized = groupId?.trim();
14
+ if (!normalized) return [];
15
+ if (normalized.startsWith("group:") || normalized.startsWith("room:")) {
16
+ const rawId = normalized.split(":").slice(1).join(":");
17
+ return rawId ? [rawId, normalized] : [normalized];
18
+ }
19
+ return [
20
+ normalized,
21
+ `group:${normalized}`,
22
+ `room:${normalized}`
23
+ ];
24
+ }
25
+ function resolveLineGroupConfigEntry(groups, params) {
26
+ if (!groups) return;
27
+ for (const candidate of resolveLineGroupLookupIds(params.groupId)) {
28
+ const hit = groups[candidate];
29
+ if (hit) return hit;
30
+ }
31
+ for (const candidate of resolveLineGroupLookupIds(params.roomId)) {
32
+ const hit = groups[candidate];
33
+ if (hit) return hit;
34
+ }
35
+ return groups["*"];
36
+ }
37
+ function resolveLineGroupsConfig(cfg, accountId) {
38
+ const lineConfig = cfg.channels?.line;
39
+ if (!lineConfig) return;
40
+ const normalizedAccountId = normalizeAccountId(accountId);
41
+ return resolveAccountEntry(lineConfig.accounts, normalizedAccountId)?.groups ?? lineConfig.groups;
42
+ }
43
+ function resolveExactLineGroupConfigKey(params) {
44
+ const groups = resolveLineGroupsConfig(params.cfg, params.accountId);
45
+ if (!groups) return;
46
+ return resolveLineGroupLookupIds(params.groupId).find((candidate) => Object.hasOwn(groups, candidate));
47
+ }
48
+ //#endregion
49
+ //#region extensions/line/src/config-schema.ts
50
+ const DmPolicySchema = z.enum([
51
+ "open",
52
+ "allowlist",
53
+ "pairing",
54
+ "disabled"
55
+ ]);
56
+ const GroupPolicySchema = z.enum([
57
+ "open",
58
+ "allowlist",
59
+ "disabled"
60
+ ]);
61
+ const ThreadBindingsSchema = z.object({
62
+ enabled: z.boolean().optional(),
63
+ idleHours: z.number().optional(),
64
+ maxAgeHours: z.number().optional(),
65
+ spawnSessions: z.boolean().optional(),
66
+ defaultSpawnContext: z.enum(["isolated", "fork"]).optional(),
67
+ spawnSubagentSessions: z.boolean().optional(),
68
+ spawnAcpSessions: z.boolean().optional()
69
+ }).strict();
70
+ const LineCommonConfigSchemaBase = z.object({
71
+ enabled: z.boolean().optional(),
72
+ channelAccessToken: z.string().optional(),
73
+ channelSecret: z.string().optional(),
74
+ tokenFile: z.string().optional(),
75
+ secretFile: z.string().optional(),
76
+ name: z.string().optional(),
77
+ allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
78
+ groupAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
79
+ dmPolicy: DmPolicySchema.optional().default("pairing"),
80
+ groupPolicy: GroupPolicySchema.optional().default("allowlist"),
81
+ responsePrefix: z.string().optional(),
82
+ mediaMaxMb: z.number().optional(),
83
+ webhookPath: z.string().optional(),
84
+ threadBindings: ThreadBindingsSchema.optional()
85
+ });
86
+ const LineGroupConfigSchema = z.object({
87
+ enabled: z.boolean().optional(),
88
+ allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
89
+ requireMention: z.boolean().optional(),
90
+ systemPrompt: z.string().optional(),
91
+ skills: z.array(z.string()).optional()
92
+ }).strict();
93
+ const LineAccountConfigSchema = LineCommonConfigSchemaBase.extend({ groups: z.record(z.string(), LineGroupConfigSchema.optional()).optional() }).strict().superRefine((value, ctx) => {
94
+ requireChannelOpenAllowFrom({
95
+ channel: "line",
96
+ policy: value.dmPolicy,
97
+ allowFrom: value.allowFrom,
98
+ ctx,
99
+ requireOpenAllowFrom
100
+ });
101
+ });
102
+ const LineConfigSchema = LineCommonConfigSchemaBase.extend({
103
+ accounts: z.record(z.string(), LineAccountConfigSchema.optional()).optional(),
104
+ defaultAccount: z.string().optional(),
105
+ groups: z.record(z.string(), LineGroupConfigSchema.optional()).optional()
106
+ }).strict().superRefine((value, ctx) => {
107
+ requireChannelOpenAllowFrom({
108
+ channel: "line",
109
+ policy: value.dmPolicy,
110
+ allowFrom: value.allowFrom,
111
+ ctx,
112
+ requireOpenAllowFrom
113
+ });
114
+ });
115
+ const LineChannelConfigSchema = buildChannelConfigSchema(LineConfigSchema);
116
+ //#endregion
117
+ //#region extensions/line/src/runtime.ts
118
+ const { setRuntime: setLineRuntime, clearRuntime: clearLineRuntime, getRuntime: getLineRuntime } = createPluginRuntimeStore({
119
+ pluginId: "line",
120
+ errorMessage: "LINE runtime not initialized - plugin not registered"
121
+ });
122
+ //#endregion
123
+ //#region extensions/line/src/outbound-media.ts
124
+ const LINE_OUTBOUND_MEDIA_SSRF_POLICY = { allowPrivateNetwork: false };
125
+ async function validateLineMediaUrl(url) {
126
+ let parsed;
127
+ try {
128
+ parsed = new URL(url);
129
+ } catch {
130
+ throw new Error(`LINE outbound media URL must be a valid URL: ${url}`);
131
+ }
132
+ if (parsed.protocol !== "https:") throw new Error(`LINE outbound media URL must use HTTPS: ${url}`);
133
+ if (url.length > 2e3) throw new Error(`LINE outbound media URL must be 2000 chars or less (got ${url.length})`);
134
+ await resolvePinnedHostnameWithPolicy(parsed.hostname, { policy: LINE_OUTBOUND_MEDIA_SSRF_POLICY });
135
+ }
136
+ function isHttpsUrl(url) {
137
+ try {
138
+ return new URL(url).protocol === "https:";
139
+ } catch {
140
+ return false;
141
+ }
142
+ }
143
+ function detectLineMediaKindFromUrl(url) {
144
+ try {
145
+ const pathname = normalizeLowercaseStringOrEmpty(new URL(url).pathname);
146
+ if (/\.(png|jpe?g|gif|webp|bmp|heic|heif|avif)$/i.test(pathname)) return "image";
147
+ if (/\.(mp4|mov|m4v|webm)$/i.test(pathname)) return "video";
148
+ if (/\.(mp3|m4a|aac|wav|ogg|oga)$/i.test(pathname)) return "audio";
149
+ } catch {
150
+ return;
151
+ }
152
+ }
153
+ async function resolveLineOutboundMedia(mediaUrl, opts = {}) {
154
+ const trimmedUrl = mediaUrl.trim();
155
+ if (isHttpsUrl(trimmedUrl)) {
156
+ await validateLineMediaUrl(trimmedUrl);
157
+ const previewImageUrl = opts.previewImageUrl?.trim();
158
+ if (previewImageUrl) await validateLineMediaUrl(previewImageUrl);
159
+ return {
160
+ mediaUrl: trimmedUrl,
161
+ mediaKind: opts.mediaKind ?? (typeof opts.durationMs === "number" ? "audio" : void 0) ?? (opts.trackingId?.trim() ? "video" : void 0) ?? detectLineMediaKindFromUrl(trimmedUrl) ?? "image",
162
+ ...previewImageUrl ? { previewImageUrl } : {},
163
+ ...typeof opts.durationMs === "number" ? { durationMs: opts.durationMs } : {},
164
+ ...opts.trackingId ? { trackingId: opts.trackingId } : {}
165
+ };
166
+ }
167
+ try {
168
+ if (new URL(trimmedUrl).protocol !== "https:") throw new Error(`LINE outbound media URL must use HTTPS: ${trimmedUrl}`);
169
+ } catch (e) {
170
+ if (e instanceof Error && e.message.startsWith("LINE outbound")) throw e;
171
+ }
172
+ throw new Error("LINE outbound media currently requires a public HTTPS URL");
173
+ }
174
+ //#endregion
175
+ //#region extensions/line/src/quick-reply-fallback.ts
176
+ function buildLineQuickReplyFallbackText(labels) {
177
+ const normalized = (labels ?? []).map((label) => label.trim()).filter(Boolean).slice(0, 13);
178
+ if (normalized.length === 0) return "Choose an option.";
179
+ return `Options:\n${normalized.map((label) => `- ${label}`).join("\n")}`;
180
+ }
181
+ //#endregion
182
+ //#region extensions/line/src/send-receipt.ts
183
+ function createLineSendReceipt(params) {
184
+ const messageId = params.messageId.trim();
185
+ const chatId = params.chatId.trim();
186
+ return createMessageReceiptFromOutboundResults({
187
+ results: messageId ? [{
188
+ channel: "line",
189
+ messageId,
190
+ chatId,
191
+ conversationId: chatId,
192
+ meta: { messageCount: params.messageCount ?? 1 }
193
+ }] : [],
194
+ ...chatId ? { threadId: chatId } : {},
195
+ kind: params.kind ?? "unknown"
196
+ });
197
+ }
198
+ //#endregion
199
+ //#region extensions/line/src/flex-templates/media-control-cards.ts
200
+ /**
201
+ * Create a media player card for Sonos, Spotify, Apple Music, etc.
202
+ *
203
+ * Editorial design: Album art hero with gradient overlay for text,
204
+ * prominent now-playing indicator, refined playback controls.
205
+ */
206
+ function createMediaPlayerCard(params) {
207
+ const { title, subtitle, source, imageUrl, isPlaying, progress, controls, extraActions } = params;
208
+ const trackInfo = [{
209
+ type: "text",
210
+ text: title,
211
+ weight: "bold",
212
+ size: "xl",
213
+ color: "#111111",
214
+ wrap: true
215
+ }];
216
+ if (subtitle) trackInfo.push({
217
+ type: "text",
218
+ text: subtitle,
219
+ size: "md",
220
+ color: "#666666",
221
+ wrap: true,
222
+ margin: "sm"
223
+ });
224
+ const statusItems = [];
225
+ if (isPlaying !== void 0) statusItems.push({
226
+ type: "box",
227
+ layout: "horizontal",
228
+ contents: [{
229
+ type: "box",
230
+ layout: "vertical",
231
+ contents: [],
232
+ width: "8px",
233
+ height: "8px",
234
+ backgroundColor: isPlaying ? "#06C755" : "#CCCCCC",
235
+ cornerRadius: "4px"
236
+ }, {
237
+ type: "text",
238
+ text: isPlaying ? "Now Playing" : "Paused",
239
+ size: "xs",
240
+ color: isPlaying ? "#06C755" : "#888888",
241
+ weight: "bold",
242
+ margin: "sm"
243
+ }],
244
+ alignItems: "center"
245
+ });
246
+ if (source) statusItems.push({
247
+ type: "text",
248
+ text: source,
249
+ size: "xs",
250
+ color: "#AAAAAA",
251
+ margin: statusItems.length > 0 ? "lg" : void 0
252
+ });
253
+ if (progress) statusItems.push({
254
+ type: "text",
255
+ text: progress,
256
+ size: "xs",
257
+ color: "#888888",
258
+ align: "end",
259
+ flex: 1
260
+ });
261
+ const bodyContents = [{
262
+ type: "box",
263
+ layout: "vertical",
264
+ contents: trackInfo
265
+ }];
266
+ if (statusItems.length > 0) bodyContents.push({
267
+ type: "box",
268
+ layout: "horizontal",
269
+ contents: statusItems,
270
+ margin: "lg",
271
+ alignItems: "center"
272
+ });
273
+ const bubble = {
274
+ type: "bubble",
275
+ size: "mega",
276
+ body: {
277
+ type: "box",
278
+ layout: "vertical",
279
+ contents: bodyContents,
280
+ paddingAll: "xl",
281
+ backgroundColor: "#FFFFFF"
282
+ }
283
+ };
284
+ if (imageUrl) bubble.hero = {
285
+ type: "image",
286
+ url: imageUrl,
287
+ size: "full",
288
+ aspectRatio: "1:1",
289
+ aspectMode: "cover"
290
+ };
291
+ if (controls || extraActions?.length) {
292
+ const footerContents = [];
293
+ if (controls) {
294
+ const controlButtons = [];
295
+ if (controls.previous) controlButtons.push({
296
+ type: "button",
297
+ action: {
298
+ type: "postback",
299
+ label: "⏮",
300
+ data: controls.previous.data
301
+ },
302
+ style: "secondary",
303
+ flex: 1,
304
+ height: "sm"
305
+ });
306
+ if (controls.play) controlButtons.push({
307
+ type: "button",
308
+ action: {
309
+ type: "postback",
310
+ label: "▶",
311
+ data: controls.play.data
312
+ },
313
+ style: isPlaying ? "secondary" : "primary",
314
+ flex: 1,
315
+ height: "sm",
316
+ margin: controls.previous ? "md" : void 0
317
+ });
318
+ if (controls.pause) controlButtons.push({
319
+ type: "button",
320
+ action: {
321
+ type: "postback",
322
+ label: "⏸",
323
+ data: controls.pause.data
324
+ },
325
+ style: isPlaying ? "primary" : "secondary",
326
+ flex: 1,
327
+ height: "sm",
328
+ margin: controlButtons.length > 0 ? "md" : void 0
329
+ });
330
+ if (controls.next) controlButtons.push({
331
+ type: "button",
332
+ action: {
333
+ type: "postback",
334
+ label: "⏭",
335
+ data: controls.next.data
336
+ },
337
+ style: "secondary",
338
+ flex: 1,
339
+ height: "sm",
340
+ margin: controlButtons.length > 0 ? "md" : void 0
341
+ });
342
+ if (controlButtons.length > 0) footerContents.push({
343
+ type: "box",
344
+ layout: "horizontal",
345
+ contents: controlButtons
346
+ });
347
+ }
348
+ if (extraActions?.length) footerContents.push({
349
+ type: "box",
350
+ layout: "horizontal",
351
+ contents: extraActions.slice(0, 2).map((action, index) => ({
352
+ type: "button",
353
+ action: {
354
+ type: "postback",
355
+ label: action.label.slice(0, 15),
356
+ data: action.data
357
+ },
358
+ style: "secondary",
359
+ flex: 1,
360
+ height: "sm",
361
+ margin: index > 0 ? "md" : void 0
362
+ })),
363
+ margin: "md"
364
+ });
365
+ if (footerContents.length > 0) bubble.footer = {
366
+ type: "box",
367
+ layout: "vertical",
368
+ contents: footerContents,
369
+ paddingAll: "lg",
370
+ backgroundColor: "#FAFAFA"
371
+ };
372
+ }
373
+ return bubble;
374
+ }
375
+ /**
376
+ * Create an Apple TV remote card with a D-pad and control rows.
377
+ */
378
+ function createAppleTvRemoteCard(params) {
379
+ const { deviceName, status, actionData } = params;
380
+ const headerContents = [{
381
+ type: "text",
382
+ text: deviceName,
383
+ weight: "bold",
384
+ size: "xl",
385
+ color: "#111111",
386
+ wrap: true
387
+ }];
388
+ if (status) headerContents.push({
389
+ type: "text",
390
+ text: status,
391
+ size: "sm",
392
+ color: "#666666",
393
+ wrap: true,
394
+ margin: "sm"
395
+ });
396
+ const makeButton = (label, data, style = "secondary") => ({
397
+ type: "button",
398
+ action: {
399
+ type: "postback",
400
+ label,
401
+ data
402
+ },
403
+ style,
404
+ height: "sm",
405
+ flex: 1
406
+ });
407
+ const dpadRows = [
408
+ {
409
+ type: "box",
410
+ layout: "horizontal",
411
+ contents: [
412
+ { type: "filler" },
413
+ makeButton("↑", actionData.up),
414
+ { type: "filler" }
415
+ ]
416
+ },
417
+ {
418
+ type: "box",
419
+ layout: "horizontal",
420
+ contents: [
421
+ makeButton("←", actionData.left),
422
+ makeButton("OK", actionData.select, "primary"),
423
+ makeButton("→", actionData.right)
424
+ ],
425
+ margin: "md"
426
+ },
427
+ {
428
+ type: "box",
429
+ layout: "horizontal",
430
+ contents: [
431
+ { type: "filler" },
432
+ makeButton("↓", actionData.down),
433
+ { type: "filler" }
434
+ ],
435
+ margin: "md"
436
+ }
437
+ ];
438
+ const menuRow = {
439
+ type: "box",
440
+ layout: "horizontal",
441
+ contents: [makeButton("Menu", actionData.menu), makeButton("Home", actionData.home)],
442
+ margin: "lg"
443
+ };
444
+ const playbackRow = {
445
+ type: "box",
446
+ layout: "horizontal",
447
+ contents: [makeButton("Play", actionData.play), makeButton("Pause", actionData.pause)],
448
+ margin: "md"
449
+ };
450
+ const volumeRow = {
451
+ type: "box",
452
+ layout: "horizontal",
453
+ contents: [
454
+ makeButton("Vol +", actionData.volumeUp),
455
+ makeButton("Mute", actionData.mute),
456
+ makeButton("Vol -", actionData.volumeDown)
457
+ ],
458
+ margin: "md"
459
+ };
460
+ return {
461
+ type: "bubble",
462
+ size: "mega",
463
+ body: {
464
+ type: "box",
465
+ layout: "vertical",
466
+ contents: [
467
+ {
468
+ type: "box",
469
+ layout: "vertical",
470
+ contents: headerContents
471
+ },
472
+ {
473
+ type: "separator",
474
+ margin: "lg",
475
+ color: "#EEEEEE"
476
+ },
477
+ ...dpadRows,
478
+ menuRow,
479
+ playbackRow,
480
+ volumeRow
481
+ ],
482
+ paddingAll: "xl",
483
+ backgroundColor: "#FFFFFF"
484
+ }
485
+ };
486
+ }
487
+ /**
488
+ * Create a device control card for Apple TV, smart home devices, etc.
489
+ *
490
+ * Editorial design: Device-focused header with status indicator,
491
+ * clean control grid with clear visual hierarchy.
492
+ */
493
+ function createDeviceControlCard(params) {
494
+ const { deviceName, deviceType, status, isOnline, imageUrl, controls } = params;
495
+ const headerContents = [{
496
+ type: "box",
497
+ layout: "horizontal",
498
+ contents: [{
499
+ type: "box",
500
+ layout: "vertical",
501
+ contents: [],
502
+ width: "10px",
503
+ height: "10px",
504
+ backgroundColor: isOnline !== false ? "#06C755" : "#FF5555",
505
+ cornerRadius: "5px"
506
+ }, {
507
+ type: "text",
508
+ text: deviceName,
509
+ weight: "bold",
510
+ size: "xl",
511
+ color: "#111111",
512
+ wrap: true,
513
+ flex: 1,
514
+ margin: "md"
515
+ }],
516
+ alignItems: "center"
517
+ }];
518
+ if (deviceType) headerContents.push({
519
+ type: "text",
520
+ text: deviceType,
521
+ size: "sm",
522
+ color: "#888888",
523
+ margin: "sm"
524
+ });
525
+ if (status) headerContents.push({
526
+ type: "box",
527
+ layout: "vertical",
528
+ contents: [{
529
+ type: "text",
530
+ text: status,
531
+ size: "sm",
532
+ color: "#444444",
533
+ wrap: true
534
+ }],
535
+ margin: "lg",
536
+ paddingAll: "md",
537
+ backgroundColor: "#F8F9FA",
538
+ cornerRadius: "md"
539
+ });
540
+ const bubble = {
541
+ type: "bubble",
542
+ size: "mega",
543
+ body: {
544
+ type: "box",
545
+ layout: "vertical",
546
+ contents: headerContents,
547
+ paddingAll: "xl",
548
+ backgroundColor: "#FFFFFF"
549
+ }
550
+ };
551
+ if (imageUrl) bubble.hero = {
552
+ type: "image",
553
+ url: imageUrl,
554
+ size: "full",
555
+ aspectRatio: "16:9",
556
+ aspectMode: "cover"
557
+ };
558
+ if (controls.length > 0) {
559
+ const rows = [];
560
+ const limitedControls = controls.slice(0, 6);
561
+ for (let i = 0; i < limitedControls.length; i += 2) {
562
+ const rowButtons = [];
563
+ for (let j = i; j < Math.min(i + 2, limitedControls.length); j++) {
564
+ const ctrl = limitedControls[j];
565
+ const buttonLabel = ctrl.icon ? `${ctrl.icon} ${ctrl.label}` : ctrl.label;
566
+ rowButtons.push({
567
+ type: "button",
568
+ action: {
569
+ type: "postback",
570
+ label: buttonLabel.slice(0, 18),
571
+ data: ctrl.data
572
+ },
573
+ style: ctrl.style ?? "secondary",
574
+ flex: 1,
575
+ height: "sm",
576
+ margin: j > i ? "md" : void 0
577
+ });
578
+ }
579
+ if (rowButtons.length === 1) rowButtons.push({ type: "filler" });
580
+ rows.push({
581
+ type: "box",
582
+ layout: "horizontal",
583
+ contents: rowButtons,
584
+ margin: i > 0 ? "md" : void 0
585
+ });
586
+ }
587
+ bubble.footer = {
588
+ type: "box",
589
+ layout: "vertical",
590
+ contents: rows,
591
+ paddingAll: "lg",
592
+ backgroundColor: "#FAFAFA"
593
+ };
594
+ }
595
+ return bubble;
596
+ }
597
+ //#endregion
598
+ //#region extensions/line/src/reply-payload-transform.ts
599
+ /**
600
+ * Parse LINE-specific directives from text and extract them into ReplyPayload fields.
601
+ *
602
+ * Supported directives:
603
+ * - [[quick_replies: option1, option2, option3]]
604
+ * - [[location: title | address | latitude | longitude]]
605
+ * - [[confirm: question | yes_label | no_label]]
606
+ * - [[buttons: title | text | btn1:data1, btn2:data2]]
607
+ * - [[media_player: title | artist | source | imageUrl | playing/paused]]
608
+ * - [[event: title | date | time | location | description]]
609
+ * - [[agenda: title | event1_title:event1_time, event2_title:event2_time, ...]]
610
+ * - [[device: name | type | status | ctrl1:data1, ctrl2:data2]]
611
+ * - [[appletv_remote: name | status]]
612
+ */
613
+ function parseLineDirectives(payload) {
614
+ let text = payload.text;
615
+ if (!text) return payload;
616
+ const result = { ...payload };
617
+ const lineData = { ...result.channelData?.line };
618
+ const toSlug = (value) => normalizeLowercaseStringOrEmpty(value).replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "device";
619
+ const lineActionData = (action, extras) => {
620
+ const base = [`line.action=${encodeURIComponent(action)}`];
621
+ if (extras) for (const [key, value] of Object.entries(extras)) base.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
622
+ return base.join("&");
623
+ };
624
+ const quickRepliesMatch = text.match(/\[\[quick_replies:\s*([^\]]+)\]\]/i);
625
+ if (quickRepliesMatch) {
626
+ const options = quickRepliesMatch[1].split(",").map((s) => s.trim()).filter(Boolean);
627
+ if (options.length > 0) lineData.quickReplies = [...lineData.quickReplies || [], ...options];
628
+ text = text.replace(quickRepliesMatch[0], "").trim();
629
+ }
630
+ const locationMatch = text.match(/\[\[location:\s*([^\]]+)\]\]/i);
631
+ if (locationMatch && !lineData.location) {
632
+ const parts = locationMatch[1].split("|").map((s) => s.trim());
633
+ if (parts.length >= 4) {
634
+ const [title, address, latStr, lonStr] = parts;
635
+ const latitude = Number.parseFloat(latStr);
636
+ const longitude = Number.parseFloat(lonStr);
637
+ if (!Number.isNaN(latitude) && !Number.isNaN(longitude)) lineData.location = {
638
+ title: title || "Location",
639
+ address: address || "",
640
+ latitude,
641
+ longitude
642
+ };
643
+ }
644
+ text = text.replace(locationMatch[0], "").trim();
645
+ }
646
+ const confirmMatch = text.match(/\[\[confirm:\s*([^\]]+)\]\]/i);
647
+ if (confirmMatch && !lineData.templateMessage) {
648
+ const parts = confirmMatch[1].split("|").map((s) => s.trim());
649
+ if (parts.length >= 3) {
650
+ const [question, yesPart, noPart] = parts;
651
+ const [yesLabel, yesData] = yesPart.includes(":") ? yesPart.split(":").map((s) => s.trim()) : [yesPart, normalizeLowercaseStringOrEmpty(yesPart)];
652
+ const [noLabel, noData] = noPart.includes(":") ? noPart.split(":").map((s) => s.trim()) : [noPart, normalizeLowercaseStringOrEmpty(noPart)];
653
+ lineData.templateMessage = {
654
+ type: "confirm",
655
+ text: question,
656
+ confirmLabel: yesLabel,
657
+ confirmData: yesData,
658
+ cancelLabel: noLabel,
659
+ cancelData: noData,
660
+ altText: question
661
+ };
662
+ }
663
+ text = text.replace(confirmMatch[0], "").trim();
664
+ }
665
+ const buttonsMatch = text.match(/\[\[buttons:\s*([^\]]+)\]\]/i);
666
+ if (buttonsMatch && !lineData.templateMessage) {
667
+ const parts = buttonsMatch[1].split("|").map((s) => s.trim());
668
+ if (parts.length >= 3) {
669
+ const [title, bodyText, actionsStr] = parts;
670
+ const actions = actionsStr.split(",").map((actionStr) => {
671
+ const trimmed = actionStr.trim();
672
+ const colonIndex = (() => {
673
+ const index = trimmed.indexOf(":");
674
+ if (index === -1) return -1;
675
+ const lower = normalizeLowercaseStringOrEmpty(trimmed);
676
+ if (lower.startsWith("http://") || lower.startsWith("https://")) return -1;
677
+ return index;
678
+ })();
679
+ let label;
680
+ let data;
681
+ if (colonIndex === -1) {
682
+ label = trimmed;
683
+ data = trimmed;
684
+ } else {
685
+ label = trimmed.slice(0, colonIndex).trim();
686
+ data = trimmed.slice(colonIndex + 1).trim();
687
+ }
688
+ if (data.startsWith("http://") || data.startsWith("https://")) return {
689
+ type: "uri",
690
+ label,
691
+ uri: data
692
+ };
693
+ if (data.includes("=")) return {
694
+ type: "postback",
695
+ label,
696
+ data
697
+ };
698
+ return {
699
+ type: "message",
700
+ label,
701
+ data: data || label
702
+ };
703
+ });
704
+ if (actions.length > 0) lineData.templateMessage = {
705
+ type: "buttons",
706
+ title,
707
+ text: bodyText,
708
+ actions: actions.slice(0, 4),
709
+ altText: `${title}: ${bodyText}`
710
+ };
711
+ }
712
+ text = text.replace(buttonsMatch[0], "").trim();
713
+ }
714
+ const mediaPlayerMatch = text.match(/\[\[media_player:\s*([^\]]+)\]\]/i);
715
+ if (mediaPlayerMatch && !lineData.flexMessage) {
716
+ const parts = mediaPlayerMatch[1].split("|").map((s) => s.trim());
717
+ if (parts.length >= 1) {
718
+ const [title, artist, source, imageUrl, statusStr] = parts;
719
+ const isPlaying = normalizeLowercaseStringOrEmpty(statusStr) === "playing";
720
+ const validImageUrl = imageUrl?.startsWith("https://") ? imageUrl : void 0;
721
+ const deviceKey = toSlug(source || title || "media");
722
+ const card = createMediaPlayerCard({
723
+ title: title || "Unknown Track",
724
+ subtitle: artist || void 0,
725
+ source: source || void 0,
726
+ imageUrl: validImageUrl,
727
+ isPlaying: statusStr ? isPlaying : void 0,
728
+ controls: {
729
+ previous: { data: lineActionData("previous", { "line.device": deviceKey }) },
730
+ play: { data: lineActionData("play", { "line.device": deviceKey }) },
731
+ pause: { data: lineActionData("pause", { "line.device": deviceKey }) },
732
+ next: { data: lineActionData("next", { "line.device": deviceKey }) }
733
+ }
734
+ });
735
+ lineData.flexMessage = {
736
+ altText: `🎵 ${title}${artist ? ` - ${artist}` : ""}`,
737
+ contents: card
738
+ };
739
+ }
740
+ text = text.replace(mediaPlayerMatch[0], "").trim();
741
+ }
742
+ const eventMatch = text.match(/\[\[event:\s*([^\]]+)\]\]/i);
743
+ if (eventMatch && !lineData.flexMessage) {
744
+ const parts = eventMatch[1].split("|").map((s) => s.trim());
745
+ if (parts.length >= 2) {
746
+ const [title, date, time, location, description] = parts;
747
+ const card = createEventCard({
748
+ title: title || "Event",
749
+ date: date || "TBD",
750
+ time: time || void 0,
751
+ location: location || void 0,
752
+ description: description || void 0
753
+ });
754
+ lineData.flexMessage = {
755
+ altText: `📅 ${title} - ${date}${time ? ` ${time}` : ""}`,
756
+ contents: card
757
+ };
758
+ }
759
+ text = text.replace(eventMatch[0], "").trim();
760
+ }
761
+ const appleTvMatch = text.match(/\[\[appletv_remote:\s*([^\]]+)\]\]/i);
762
+ if (appleTvMatch && !lineData.flexMessage) {
763
+ const parts = appleTvMatch[1].split("|").map((s) => s.trim());
764
+ if (parts.length >= 1) {
765
+ const [deviceName, status] = parts;
766
+ const deviceKey = toSlug(deviceName || "apple_tv");
767
+ const card = createAppleTvRemoteCard({
768
+ deviceName: deviceName || "Apple TV",
769
+ status: status || void 0,
770
+ actionData: {
771
+ up: lineActionData("up", { "line.device": deviceKey }),
772
+ down: lineActionData("down", { "line.device": deviceKey }),
773
+ left: lineActionData("left", { "line.device": deviceKey }),
774
+ right: lineActionData("right", { "line.device": deviceKey }),
775
+ select: lineActionData("select", { "line.device": deviceKey }),
776
+ menu: lineActionData("menu", { "line.device": deviceKey }),
777
+ home: lineActionData("home", { "line.device": deviceKey }),
778
+ play: lineActionData("play", { "line.device": deviceKey }),
779
+ pause: lineActionData("pause", { "line.device": deviceKey }),
780
+ volumeUp: lineActionData("volume_up", { "line.device": deviceKey }),
781
+ volumeDown: lineActionData("volume_down", { "line.device": deviceKey }),
782
+ mute: lineActionData("mute", { "line.device": deviceKey })
783
+ }
784
+ });
785
+ lineData.flexMessage = {
786
+ altText: `📺 ${deviceName || "Apple TV"} Remote`,
787
+ contents: card
788
+ };
789
+ }
790
+ text = text.replace(appleTvMatch[0], "").trim();
791
+ }
792
+ const agendaMatch = text.match(/\[\[agenda:\s*([^\]]+)\]\]/i);
793
+ if (agendaMatch && !lineData.flexMessage) {
794
+ const parts = agendaMatch[1].split("|").map((s) => s.trim());
795
+ if (parts.length >= 2) {
796
+ const [title, eventsStr] = parts;
797
+ const events = eventsStr.split(",").map((eventStr) => {
798
+ const trimmed = eventStr.trim();
799
+ const colonIdx = trimmed.lastIndexOf(":");
800
+ if (colonIdx > 0) return {
801
+ title: trimmed.slice(0, colonIdx).trim(),
802
+ time: trimmed.slice(colonIdx + 1).trim()
803
+ };
804
+ return { title: trimmed };
805
+ });
806
+ const card = createAgendaCard({
807
+ title: title || "Agenda",
808
+ events
809
+ });
810
+ lineData.flexMessage = {
811
+ altText: `📋 ${title} (${events.length} events)`,
812
+ contents: card
813
+ };
814
+ }
815
+ text = text.replace(agendaMatch[0], "").trim();
816
+ }
817
+ const deviceMatch = text.match(/\[\[device:\s*([^\]]+)\]\]/i);
818
+ if (deviceMatch && !lineData.flexMessage) {
819
+ const parts = deviceMatch[1].split("|").map((s) => s.trim());
820
+ if (parts.length >= 1) {
821
+ const [deviceName, deviceType, status, controlsStr] = parts;
822
+ const deviceKey = toSlug(deviceName || "device");
823
+ const controls = controlsStr ? controlsStr.split(",").map((ctrlStr) => {
824
+ const [label, data] = ctrlStr.split(":").map((s) => s.trim());
825
+ return {
826
+ label,
827
+ data: lineActionData(data || normalizeLowercaseStringOrEmpty(label).replace(/\s+/g, "_"), { "line.device": deviceKey })
828
+ };
829
+ }) : [];
830
+ const card = createDeviceControlCard({
831
+ deviceName: deviceName || "Device",
832
+ deviceType: deviceType || void 0,
833
+ status: status || void 0,
834
+ controls
835
+ });
836
+ lineData.flexMessage = {
837
+ altText: `📱 ${deviceName}${status ? `: ${status}` : ""}`,
838
+ contents: card
839
+ };
840
+ }
841
+ text = text.replace(deviceMatch[0], "").trim();
842
+ }
843
+ text = text.replace(/\n{3,}/g, "\n\n").trim();
844
+ result.text = text || void 0;
845
+ if (Object.keys(lineData).length > 0) result.channelData = {
846
+ ...result.channelData,
847
+ line: lineData
848
+ };
849
+ return result;
850
+ }
851
+ function hasLineDirectives(text) {
852
+ return /\[\[(quick_replies|location|confirm|buttons|media_player|event|agenda|device|appletv_remote):/i.test(text);
853
+ }
854
+ //#endregion
855
+ export { resolveLineGroupsConfig as _, createMediaPlayerCard as a, resolveLineOutboundMedia as c, setLineRuntime as d, LineChannelConfigSchema as f, resolveLineGroupLookupIds as g, resolveLineGroupConfigEntry as h, createDeviceControlCard as i, validateLineMediaUrl as l, resolveExactLineGroupConfigKey as m, parseLineDirectives as n, createLineSendReceipt as o, LineConfigSchema as p, createAppleTvRemoteCard as r, buildLineQuickReplyFallbackText as s, hasLineDirectives as t, getLineRuntime as u };