@kodelyth/line 2026.5.42 → 2026.6.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.
Files changed (90) hide show
  1. package/klaw.plugin.json +329 -2
  2. package/package.json +18 -6
  3. package/api.ts +0 -11
  4. package/channel-plugin-api.ts +0 -1
  5. package/contract-api.ts +0 -5
  6. package/index.ts +0 -53
  7. package/runtime-api.ts +0 -179
  8. package/secret-contract-api.ts +0 -4
  9. package/setup-api.ts +0 -2
  10. package/setup-entry.ts +0 -9
  11. package/src/account-helpers.ts +0 -16
  12. package/src/accounts.test.ts +0 -288
  13. package/src/accounts.ts +0 -187
  14. package/src/actions.ts +0 -61
  15. package/src/auto-reply-delivery.test.ts +0 -253
  16. package/src/auto-reply-delivery.ts +0 -200
  17. package/src/bindings.ts +0 -65
  18. package/src/bot-access.ts +0 -30
  19. package/src/bot-handlers.test.ts +0 -1094
  20. package/src/bot-handlers.ts +0 -620
  21. package/src/bot-message-context.test.ts +0 -420
  22. package/src/bot-message-context.ts +0 -586
  23. package/src/bot.ts +0 -66
  24. package/src/card-command.ts +0 -347
  25. package/src/channel-access-token.ts +0 -14
  26. package/src/channel-api.ts +0 -17
  27. package/src/channel-setup-status.contract.test.ts +0 -70
  28. package/src/channel-shared.ts +0 -48
  29. package/src/channel.logout.test.ts +0 -145
  30. package/src/channel.runtime.ts +0 -3
  31. package/src/channel.sendPayload.test.ts +0 -659
  32. package/src/channel.setup.ts +0 -11
  33. package/src/channel.status.test.ts +0 -63
  34. package/src/channel.ts +0 -155
  35. package/src/config-adapter.ts +0 -29
  36. package/src/config-schema.test.ts +0 -53
  37. package/src/config-schema.ts +0 -81
  38. package/src/download.test.ts +0 -164
  39. package/src/download.ts +0 -34
  40. package/src/flex-templates/basic-cards.ts +0 -395
  41. package/src/flex-templates/common.ts +0 -20
  42. package/src/flex-templates/media-control-cards.ts +0 -555
  43. package/src/flex-templates/message.ts +0 -13
  44. package/src/flex-templates/schedule-cards.ts +0 -467
  45. package/src/flex-templates/types.ts +0 -22
  46. package/src/flex-templates.ts +0 -32
  47. package/src/gateway.ts +0 -129
  48. package/src/group-keys.test.ts +0 -123
  49. package/src/group-keys.ts +0 -65
  50. package/src/group-policy.ts +0 -22
  51. package/src/markdown-to-line.test.ts +0 -348
  52. package/src/markdown-to-line.ts +0 -416
  53. package/src/message-cards.test.ts +0 -204
  54. package/src/monitor-durable.test.ts +0 -57
  55. package/src/monitor-durable.ts +0 -37
  56. package/src/monitor.lifecycle.test.ts +0 -499
  57. package/src/monitor.runtime.ts +0 -1
  58. package/src/monitor.ts +0 -507
  59. package/src/outbound-media.test.ts +0 -194
  60. package/src/outbound-media.ts +0 -120
  61. package/src/outbound.runtime.ts +0 -12
  62. package/src/outbound.ts +0 -427
  63. package/src/probe.contract.test.ts +0 -9
  64. package/src/probe.runtime.ts +0 -1
  65. package/src/probe.ts +0 -34
  66. package/src/quick-reply-fallback.ts +0 -10
  67. package/src/reply-chunks.test.ts +0 -180
  68. package/src/reply-chunks.ts +0 -110
  69. package/src/reply-payload-transform.test.ts +0 -392
  70. package/src/reply-payload-transform.ts +0 -317
  71. package/src/rich-menu.test.ts +0 -315
  72. package/src/rich-menu.ts +0 -326
  73. package/src/runtime.ts +0 -32
  74. package/src/send-receipt.ts +0 -32
  75. package/src/send.test.ts +0 -453
  76. package/src/send.ts +0 -531
  77. package/src/setup-core.ts +0 -149
  78. package/src/setup-runtime-api.ts +0 -9
  79. package/src/setup-surface.test.ts +0 -481
  80. package/src/setup-surface.ts +0 -229
  81. package/src/signature.test.ts +0 -34
  82. package/src/signature.ts +0 -24
  83. package/src/status.ts +0 -37
  84. package/src/template-messages.ts +0 -333
  85. package/src/types.ts +0 -130
  86. package/src/webhook-node.test.ts +0 -598
  87. package/src/webhook-node.ts +0 -155
  88. package/src/webhook-utils.ts +0 -10
  89. package/src/webhook.ts +0 -135
  90. package/tsconfig.json +0 -16
@@ -1,420 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import type { webhook } from "@line/bot-sdk";
5
- import type { KlawConfig } from "klaw/plugin-sdk/config-contracts";
6
- import { getSessionBindingService } from "klaw/plugin-sdk/conversation-runtime";
7
- import { testing as sessionBindingTesting } from "klaw/plugin-sdk/conversation-runtime";
8
- import { createTestRegistry, setActivePluginRegistry } from "klaw/plugin-sdk/plugin-test-runtime";
9
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
10
- import { lineBindingsAdapter } from "./bindings.js";
11
- import { buildLineMessageContext, buildLinePostbackContext } from "./bot-message-context.js";
12
- import type { ResolvedLineAccount } from "./types.js";
13
-
14
- type MessageEvent = webhook.MessageEvent;
15
- type PostbackEvent = webhook.PostbackEvent;
16
-
17
- const lineBindingsPlugin = {
18
- id: "line",
19
- bindings: lineBindingsAdapter,
20
- conversationBindings: {
21
- defaultTopLevelPlacement: "current",
22
- supportsCurrentConversationBinding: true,
23
- },
24
- };
25
-
26
- describe("buildLineMessageContext", () => {
27
- let tmpDir: string;
28
- let storePath: string;
29
- let cfg: KlawConfig;
30
- const account: ResolvedLineAccount = {
31
- accountId: "default",
32
- enabled: true,
33
- channelAccessToken: "token",
34
- channelSecret: "secret",
35
- tokenSource: "config",
36
- config: {},
37
- };
38
-
39
- const createMessageEvent = (
40
- source: MessageEvent["source"],
41
- overrides?: Partial<MessageEvent>,
42
- ): MessageEvent =>
43
- ({
44
- type: "message",
45
- message: { id: "1", type: "text", text: "hello" },
46
- replyToken: "reply-token",
47
- timestamp: Date.now(),
48
- source,
49
- mode: "active",
50
- webhookEventId: "evt-1",
51
- deliveryContext: { isRedelivery: false },
52
- ...overrides,
53
- }) as MessageEvent;
54
-
55
- const createPostbackEvent = (
56
- source: PostbackEvent["source"],
57
- overrides?: Partial<PostbackEvent>,
58
- ): PostbackEvent =>
59
- ({
60
- type: "postback",
61
- postback: { data: "action=select" },
62
- replyToken: "reply-token",
63
- timestamp: Date.now(),
64
- source,
65
- mode: "active",
66
- webhookEventId: "evt-2",
67
- deliveryContext: { isRedelivery: false },
68
- ...overrides,
69
- }) as PostbackEvent;
70
-
71
- beforeEach(async () => {
72
- setActivePluginRegistry(
73
- createTestRegistry([
74
- {
75
- pluginId: lineBindingsPlugin.id,
76
- plugin: lineBindingsPlugin,
77
- source: "test",
78
- },
79
- ]),
80
- );
81
- sessionBindingTesting.resetSessionBindingAdaptersForTests();
82
- tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "klaw-line-context-"));
83
- storePath = path.join(tmpDir, "sessions.json");
84
- cfg = { session: { store: storePath } };
85
- });
86
-
87
- afterEach(async () => {
88
- sessionBindingTesting.resetSessionBindingAdaptersForTests();
89
- await fs.rm(tmpDir, {
90
- recursive: true,
91
- force: true,
92
- maxRetries: 3,
93
- retryDelay: 50,
94
- });
95
- });
96
-
97
- it("routes group message replies to the group id", async () => {
98
- const event = createMessageEvent({ type: "group", groupId: "group-1", userId: "user-1" });
99
-
100
- const context = await buildLineMessageContext({
101
- event,
102
- allMedia: [],
103
- cfg,
104
- account,
105
- commandAuthorized: true,
106
- });
107
-
108
- expect(context?.ctxPayload.OriginatingTo).toBe("line:group:group-1");
109
- expect(context?.ctxPayload.To).toBe("line:group:group-1");
110
- });
111
-
112
- it("routes group postback replies to the group id", async () => {
113
- const event = createPostbackEvent({ type: "group", groupId: "group-2", userId: "user-2" });
114
-
115
- const context = await buildLinePostbackContext({
116
- event,
117
- cfg,
118
- account,
119
- commandAuthorized: true,
120
- });
121
-
122
- expect(context?.ctxPayload.OriginatingTo).toBe("line:group:group-2");
123
- expect(context?.ctxPayload.To).toBe("line:group:group-2");
124
- });
125
-
126
- it("routes room postback replies to the room id", async () => {
127
- const event = createPostbackEvent({ type: "room", roomId: "room-1", userId: "user-3" });
128
-
129
- const context = await buildLinePostbackContext({
130
- event,
131
- cfg,
132
- account,
133
- commandAuthorized: true,
134
- });
135
-
136
- expect(context?.ctxPayload.OriginatingTo).toBe("line:room:room-1");
137
- expect(context?.ctxPayload.To).toBe("line:room:room-1");
138
- });
139
-
140
- it("resolves prefixed-only group config through the inbound message context", async () => {
141
- const event = createMessageEvent({ type: "group", groupId: "group-1", userId: "user-1" });
142
-
143
- const context = await buildLineMessageContext({
144
- event,
145
- allMedia: [],
146
- cfg,
147
- account: {
148
- ...account,
149
- config: {
150
- groups: {
151
- "group:group-1": {
152
- systemPrompt: "Use the prefixed group config",
153
- },
154
- },
155
- },
156
- },
157
- commandAuthorized: true,
158
- });
159
-
160
- expect(context?.ctxPayload.GroupSystemPrompt).toBe("Use the prefixed group config");
161
- });
162
-
163
- it("resolves prefixed-only room config through the inbound message context", async () => {
164
- const event = createMessageEvent({ type: "room", roomId: "room-1", userId: "user-1" });
165
-
166
- const context = await buildLineMessageContext({
167
- event,
168
- allMedia: [],
169
- cfg,
170
- account: {
171
- ...account,
172
- config: {
173
- groups: {
174
- "room:room-1": {
175
- systemPrompt: "Use the prefixed room config",
176
- },
177
- },
178
- },
179
- },
180
- commandAuthorized: true,
181
- });
182
-
183
- expect(context?.ctxPayload.GroupSystemPrompt).toBe("Use the prefixed room config");
184
- });
185
-
186
- it("keeps non-text message contexts fail-closed for command auth", async () => {
187
- const event = createMessageEvent(
188
- { type: "user", userId: "user-audio" },
189
- {
190
- message: { id: "audio-1", type: "audio", duration: 1000 } as MessageEvent["message"],
191
- },
192
- );
193
-
194
- const context = await buildLineMessageContext({
195
- event,
196
- allMedia: [],
197
- cfg,
198
- account,
199
- commandAuthorized: false,
200
- });
201
-
202
- expect(context?.ctxPayload.CommandAuthorized).toBe(false);
203
- });
204
-
205
- it("sets CommandAuthorized=true when authorized", async () => {
206
- const event = createMessageEvent({ type: "user", userId: "user-auth" });
207
-
208
- const context = await buildLineMessageContext({
209
- event,
210
- allMedia: [],
211
- cfg,
212
- account,
213
- commandAuthorized: true,
214
- });
215
-
216
- expect(context?.ctxPayload.CommandAuthorized).toBe(true);
217
- });
218
-
219
- it("sets CommandAuthorized=false when not authorized", async () => {
220
- const event = createMessageEvent({ type: "user", userId: "user-noauth" });
221
-
222
- const context = await buildLineMessageContext({
223
- event,
224
- allMedia: [],
225
- cfg,
226
- account,
227
- commandAuthorized: false,
228
- });
229
-
230
- expect(context?.ctxPayload.CommandAuthorized).toBe(false);
231
- });
232
-
233
- it("keeps per-channel-peer direct-message last-route writes on the isolated session", async () => {
234
- const event = createMessageEvent({ type: "user", userId: "user-1" });
235
- const directCfg: KlawConfig = {
236
- session: { store: storePath, dmScope: "per-channel-peer" },
237
- };
238
-
239
- const context = await buildLineMessageContext({
240
- event,
241
- allMedia: [],
242
- cfg: directCfg,
243
- account: {
244
- ...account,
245
- config: { allowFrom: ["user-1"] },
246
- },
247
- commandAuthorized: true,
248
- });
249
-
250
- expect(context?.route.sessionKey).toBe("agent:main:line:direct:user-1");
251
- const updateLastRoute = context?.turn.record.updateLastRoute;
252
- expect(updateLastRoute?.sessionKey).toBe(context?.route.sessionKey);
253
- expect(updateLastRoute?.sessionKey).not.toBe("agent:main:main");
254
- expect(updateLastRoute?.channel).toBe("line");
255
- expect(updateLastRoute?.to).toBe("user-1");
256
- expect(updateLastRoute?.mainDmOwnerPin).toBeUndefined();
257
- });
258
-
259
- it("sets CommandAuthorized on postback context", async () => {
260
- const event = createPostbackEvent({ type: "user", userId: "user-pb" });
261
-
262
- const context = await buildLinePostbackContext({
263
- event,
264
- cfg,
265
- account,
266
- commandAuthorized: true,
267
- });
268
-
269
- expect(context?.ctxPayload.CommandAuthorized).toBe(true);
270
- });
271
-
272
- it("group peer binding matches raw groupId without prefix (#21907)", async () => {
273
- const groupId = "Cc7e3bece1234567890abcdef"; // pragma: allowlist secret
274
- const bindingCfg: KlawConfig = {
275
- session: { store: storePath },
276
- agents: {
277
- list: [{ id: "main" }, { id: "line-group-agent" }],
278
- },
279
- bindings: [
280
- {
281
- agentId: "line-group-agent",
282
- match: { channel: "line", peer: { kind: "group", id: groupId } },
283
- },
284
- ],
285
- };
286
-
287
- const event = {
288
- type: "message",
289
- message: { id: "msg-1", type: "text", text: "hello" },
290
- replyToken: "reply-token",
291
- timestamp: Date.now(),
292
- source: { type: "group", groupId, userId: "user-1" },
293
- mode: "active",
294
- webhookEventId: "evt-1",
295
- deliveryContext: { isRedelivery: false },
296
- } as MessageEvent;
297
-
298
- const context = await buildLineMessageContext({
299
- event,
300
- allMedia: [],
301
- cfg: bindingCfg,
302
- account,
303
- commandAuthorized: true,
304
- });
305
- expect(context?.route.agentId).toBe("line-group-agent");
306
- expect(context?.route.matchedBy).toBe("binding.peer");
307
- });
308
-
309
- it("room peer binding matches raw roomId without prefix (#21907)", async () => {
310
- const roomId = "Rr1234567890abcdef";
311
- const bindingCfg: KlawConfig = {
312
- session: { store: storePath },
313
- agents: {
314
- list: [{ id: "main" }, { id: "line-room-agent" }],
315
- },
316
- bindings: [
317
- {
318
- agentId: "line-room-agent",
319
- match: { channel: "line", peer: { kind: "group", id: roomId } },
320
- },
321
- ],
322
- };
323
-
324
- const event = {
325
- type: "message",
326
- message: { id: "msg-2", type: "text", text: "hello" },
327
- replyToken: "reply-token",
328
- timestamp: Date.now(),
329
- source: { type: "room", roomId, userId: "user-2" },
330
- mode: "active",
331
- webhookEventId: "evt-2",
332
- deliveryContext: { isRedelivery: false },
333
- } as MessageEvent;
334
-
335
- const context = await buildLineMessageContext({
336
- event,
337
- allMedia: [],
338
- cfg: bindingCfg,
339
- account,
340
- commandAuthorized: true,
341
- });
342
- expect(context?.route.agentId).toBe("line-room-agent");
343
- expect(context?.route.matchedBy).toBe("binding.peer");
344
- });
345
-
346
- it("normalizes LINE ACP binding conversation ids through the plugin bindings surface", () => {
347
- const compiled = lineBindingsAdapter.compileConfiguredBinding({
348
- conversationId: "line:user:U1234567890abcdef1234567890abcdef",
349
- });
350
-
351
- expect(compiled).toEqual({
352
- conversationId: "U1234567890abcdef1234567890abcdef",
353
- });
354
- expect(
355
- lineBindingsAdapter.matchInboundConversation({
356
- compiledBinding: compiled!,
357
- conversationId: "U1234567890abcdef1234567890abcdef",
358
- }),
359
- ).toEqual({
360
- conversationId: "U1234567890abcdef1234567890abcdef",
361
- matchPriority: 2,
362
- });
363
- });
364
-
365
- it("normalizes canonical LINE targets through the plugin bindings surface", () => {
366
- const compiled = lineBindingsAdapter.compileConfiguredBinding({
367
- conversationId: "line:U1234567890abcdef1234567890abcdef",
368
- });
369
-
370
- expect(compiled).toEqual({
371
- conversationId: "U1234567890abcdef1234567890abcdef",
372
- });
373
- expect(
374
- lineBindingsAdapter.resolveCommandConversation({
375
- originatingTo: "line:U1234567890abcdef1234567890abcdef",
376
- }),
377
- ).toEqual({
378
- conversationId: "U1234567890abcdef1234567890abcdef",
379
- });
380
- expect(
381
- lineBindingsAdapter.matchInboundConversation({
382
- compiledBinding: compiled!,
383
- conversationId: "U1234567890abcdef1234567890abcdef",
384
- }),
385
- ).toEqual({
386
- conversationId: "U1234567890abcdef1234567890abcdef",
387
- matchPriority: 2,
388
- });
389
- });
390
-
391
- it("routes LINE conversations through active ACP session bindings", async () => {
392
- const userId = "U1234567890abcdef1234567890abcdef";
393
- await getSessionBindingService().bind({
394
- targetSessionKey: "agent:codex:acp:binding:line:default:test123",
395
- targetKind: "session",
396
- conversation: {
397
- channel: "line",
398
- accountId: "default",
399
- conversationId: userId,
400
- },
401
- placement: "current",
402
- metadata: {
403
- agentId: "codex",
404
- },
405
- });
406
-
407
- const event = createMessageEvent({ type: "user", userId });
408
- const context = await buildLineMessageContext({
409
- event,
410
- allMedia: [],
411
- cfg,
412
- account,
413
- commandAuthorized: true,
414
- });
415
-
416
- expect(context?.route.agentId).toBe("codex");
417
- expect(context?.route.sessionKey).toBe("agent:codex:acp:binding:line:default:test123");
418
- expect(context?.route.matchedBy).toBe("binding.channel");
419
- });
420
- });