@openclaw/line 2026.10.10-beta.5 → 2026.11.5-beta.1
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/{accounts-DOiM8-y3.mjs → accounts-Dm_NoU7R.mjs} +1 -2
- package/dist/.setup/{api-PmHlEZ7r.mjs → api-ByXjHPMe.mjs} +3 -4
- package/dist/.setup/api-DCMpIrda.mjs +3 -0
- package/dist/.setup/{card-command-BMLk4YKh.mjs → card-command-utjlRvb-.mjs} +27 -45
- package/dist/.setup/{channel-j3EnT95N.mjs → channel-D9i_xlsJ.mjs} +252 -359
- package/dist/.setup/channel.runtime-C-E2qsIu.mjs +4 -0
- package/dist/.setup/{monitor-DQ-v9pI6.mjs → monitor-BYGe2Y7S.mjs} +256 -358
- package/dist/.setup/{outbound.runtime-BJL2119X.mjs → outbound.runtime-AQvUJvJV.mjs} +2 -2
- package/dist/.setup/{runtime-V7yh9OeC.mjs → runtime-C9ldw-V4.mjs} +1 -2
- package/dist/.setup/{send-g4gFsc9W.mjs → send-H86JOXWw.mjs} +40 -109
- package/dist/.setup/{send-retry-Dzbkz5wG.mjs → send-retry-D6J7bThI.mjs} +187 -105
- package/dist/.setup/{setup-surface-CYd8oqzt.mjs → setup-surface-DvbBjHFi.mjs} +5 -9
- package/dist/.setup/{template-messages-COcdie6C.mjs → template-messages-KG1GwG0h.mjs} +36 -52
- package/dist/.setup/{webhook-spool-contract-msjTl60Q.mjs → webhook-spool-contract-COhQK5XQ.mjs} +1 -2
- 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/contract-api.js +1 -1
- package/dist/doctor-contract-api.js +3 -5
- package/dist/index.js +2 -3
- package/dist/runtime-api.js +1 -1
- package/dist/secret-contract-api.js +1 -2
- package/dist/setup-api.js +1 -1
- package/dist/setup-entry.js +2 -3
- package/node_modules/@line/bot-sdk/node_modules/@types/node/README.md +1 -1
- package/node_modules/@line/bot-sdk/node_modules/@types/node/package.json +2 -2
- package/node_modules/@line/bot-sdk/node_modules/@types/node/util.d.ts +7 -4
- package/node_modules/typebox/build/format/duration.d.mts +2 -2
- package/node_modules/typebox/build/format/duration.mjs +2 -2
- package/node_modules/typebox/build/format/idn_email.d.mts +1 -0
- package/node_modules/typebox/build/format/idn_email.mjs +1 -0
- package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -1
- package/node_modules/typebox/build/format/idn_hostname.mjs +1 -1
- package/node_modules/typebox/build/format/ipv4.d.mts +2 -2
- package/node_modules/typebox/build/format/ipv4.mjs +2 -2
- package/node_modules/typebox/build/format/ipv6.d.mts +1 -1
- package/node_modules/typebox/build/format/ipv6.mjs +1 -1
- package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
- package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
- package/node_modules/typebox/build/schema/build.mjs +1 -0
- package/node_modules/typebox/build/schema/engine/_unique.d.mts +4 -2
- package/node_modules/typebox/build/schema/engine/_unique.mjs +7 -3
- package/node_modules/typebox/build/schema/engine/additionalItems.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +0 -3
- package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +15 -17
- package/node_modules/typebox/build/schema/engine/contains.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/index.d.mts +1 -0
- package/node_modules/typebox/build/schema/engine/index.mjs +1 -0
- package/node_modules/typebox/build/schema/engine/items.mjs +7 -4
- package/node_modules/typebox/build/schema/engine/maxContains.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/minContains.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/oneOf.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/patternProperties.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +2 -2
- package/node_modules/typebox/build/system/hashing/hash.mjs +63 -34
- package/node_modules/typebox/build/system/locale/en_US.mjs +2 -1
- package/node_modules/typebox/build/system/memory/assign.d.mts +2 -8
- package/node_modules/typebox/build/system/memory/assign.mjs +13 -6
- package/node_modules/typebox/build/system/memory/clone.d.mts +4 -5
- package/node_modules/typebox/build/system/memory/clone.mjs +8 -96
- package/node_modules/typebox/build/system/memory/create.d.mts +1 -5
- package/node_modules/typebox/build/system/memory/create.mjs +18 -13
- package/node_modules/typebox/build/system/memory/deep.d.mts +2 -0
- package/node_modules/typebox/build/system/memory/deep.mjs +108 -0
- package/node_modules/typebox/build/system/memory/discard.d.mts +1 -1
- package/node_modules/typebox/build/system/memory/discard.mjs +9 -8
- package/node_modules/typebox/build/system/memory/finalize.d.mts +4 -0
- package/node_modules/typebox/build/system/memory/finalize.mjs +30 -0
- package/node_modules/typebox/build/system/memory/keys.d.mts +2 -0
- package/node_modules/typebox/build/system/memory/keys.mjs +8 -0
- package/node_modules/typebox/build/system/memory/update.d.mts +1 -4
- package/node_modules/typebox/build/system/memory/update.mjs +43 -16
- package/node_modules/typebox/build/type/engine/call/index.d.mts +1 -0
- package/node_modules/typebox/build/type/engine/call/index.mjs +1 -0
- package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +2 -24
- package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +2 -29
- package/node_modules/typebox/build/type/engine/evaluate/index.d.mts +1 -0
- package/node_modules/typebox/build/type/engine/evaluate/index.mjs +1 -0
- package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +5 -1
- package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +6 -1
- package/node_modules/typebox/build/type/engine/evaluate/property.d.mts +30 -0
- package/node_modules/typebox/build/type/engine/evaluate/property.mjs +29 -0
- package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +1 -3
- package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +1 -4
- package/node_modules/typebox/build/type/engine/object/from_intersect.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/object/from_intersect.mjs +2 -2
- package/node_modules/typebox/build/type/engine/object/from_union.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
- package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +1 -3
- package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +1 -4
- package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +1 -3
- package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +1 -4
- package/node_modules/typebox/build/type/engine/this/index.d.mts +1 -0
- package/node_modules/typebox/build/type/engine/this/index.mjs +1 -0
- package/node_modules/typebox/build/value/clone/clone.d.mts +4 -3
- package/node_modules/typebox/build/value/clone/clone.mjs +5 -7
- package/node_modules/typebox/build/value/repair/from_cyclic.d.mts +2 -0
- package/node_modules/typebox/build/value/repair/from_cyclic.mjs +6 -0
- package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +25 -14
- package/node_modules/typebox/package.json +1 -1
- package/node_modules/typebox/readme.md +1 -1
- package/node_modules/zod/package.json +1 -1
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
- package/node_modules/zod/src/v4/core/compile.ts +9 -0
- package/node_modules/zod/src/v4/core/schemas.ts +35 -1
- package/node_modules/zod/src/v4/core/util.ts +13 -0
- package/node_modules/zod/src/v4/core/versions.ts +1 -1
- package/node_modules/zod/v4/core/compile.cjs +8 -0
- package/node_modules/zod/v4/core/compile.js +8 -0
- package/node_modules/zod/v4/core/schemas.cjs +30 -0
- package/node_modules/zod/v4/core/schemas.d.cts +3 -1
- package/node_modules/zod/v4/core/schemas.d.ts +3 -1
- package/node_modules/zod/v4/core/schemas.js +30 -0
- package/node_modules/zod/v4/core/util.cjs +15 -0
- package/node_modules/zod/v4/core/util.d.cts +2 -0
- package/node_modules/zod/v4/core/util.d.ts +2 -0
- package/node_modules/zod/v4/core/util.js +14 -0
- package/node_modules/zod/v4/core/versions.cjs +1 -1
- package/node_modules/zod/v4/core/versions.js +1 -1
- package/package.json +6 -6
- package/dist/.setup/api-Bis3gHmg.mjs +0 -3
- package/dist/.setup/channel.runtime-in_KhKi8.mjs +0 -4
- package/dist/.setup/monitor.runtime-DtJPzQya.mjs +0 -1
- package/dist/.setup/probe.runtime-DaGwztSg.mjs +0 -1
- package/node_modules/typebox/build/system/memory/freeze.d.mts +0 -4
- package/node_modules/typebox/build/system/memory/freeze.mjs +0 -6
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
3
|
-
import { a as normalizeLineAllowEntry } from "./setup-surface-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { a as laneKeyFor, i as eventIdFor, n as LINE_WEBHOOK_SPOOL_INVALID_PAYLOAD_MESSAGE, r as LineWebhookPayloadError, t as LINE_WEBHOOK_SPOOL_INVALID_EVENT_REASON } from "./webhook-spool-contract-
|
|
7
|
-
import { a as getUserDisplayName, h as quotesLineBotMessage, i as getLineGroupName, l as pushMessageLine, m as showLoadingAnimation, n as createLocationMessage, o as getUserProfile, p as replyMessageLine, t as createFlexMessage, u as pushMessagesLine } from "./send-
|
|
8
|
-
import { n as processLineMessage, t as buildTemplateMessageFromPayload } from "./template-messages-
|
|
1
|
+
import { A as reportLineQuoteCarrierMissing, D as canCarryLineQuoteToken, E as applyLineQuoteToken, N as buildLineMediaMessage, O as readLineQuoteToken, j as resolveLineQuoteToken, k as recordLineQuoteToken, n as findLineHttpError, r as resolveLineNonDispatchRetryable, t as explainLineRefusal } from "./send-retry-D6J7bThI.mjs";
|
|
2
|
+
import { n as resolveDefaultLineAccountId, r as resolveLineAccount } from "./accounts-Dm_NoU7R.mjs";
|
|
3
|
+
import { a as normalizeLineAllowEntry } from "./setup-surface-DvbBjHFi.mjs";
|
|
4
|
+
import { a as parseLineQuestionPostbackData, c as resolveLineGroupConfigEntry, i as isLineQuestionPostbackData, n as createLineQuickReply, o as resolveLineQuestionPostback, r as prepareLineReplyPayload, s as buildLineQuickReplyFallbackText } from "./channel-D9i_xlsJ.mjs";
|
|
5
|
+
import { t as getLineRuntime } from "./runtime-C9ldw-V4.mjs";
|
|
6
|
+
import { a as laneKeyFor, i as eventIdFor, n as LINE_WEBHOOK_SPOOL_INVALID_PAYLOAD_MESSAGE, r as LineWebhookPayloadError, t as LINE_WEBHOOK_SPOOL_INVALID_EVENT_REASON } from "./webhook-spool-contract-COhQK5XQ.mjs";
|
|
7
|
+
import { a as getUserDisplayName, h as quotesLineBotMessage, i as getLineGroupName, l as pushMessageLine, m as showLoadingAnimation, n as createLocationMessage, o as getUserProfile, p as replyMessageLine, t as createFlexMessage, u as pushMessagesLine } from "./send-H86JOXWw.mjs";
|
|
8
|
+
import { n as processLineMessage, t as buildTemplateMessageFromPayload } from "./template-messages-KG1GwG0h.mjs";
|
|
9
9
|
import { createChannelPairingChallengeIssuer } from "openclaw/plugin-sdk/channel-pairing";
|
|
10
10
|
import { resolveChannelGroupsConfigPath } from "openclaw/plugin-sdk/channel-policy";
|
|
11
11
|
import { normalizeOptionalString, normalizeStringEntries, readNonEmptyStringPreservingWhitespace } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
@@ -16,7 +16,7 @@ import { buildChannelInboundEventContext, buildMentionRegexes, formatInboundEnve
|
|
|
16
16
|
import { collectErrorGraphCandidates, extractErrorCode, formatErrorMessage, readErrorName, toErrorObject } from "openclaw/plugin-sdk/error-runtime";
|
|
17
17
|
import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
|
|
18
18
|
import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking";
|
|
19
|
-
import { danger, logVerbose,
|
|
19
|
+
import { danger, logVerbose, waitForAbortSignal, warn } from "openclaw/plugin-sdk/runtime-env";
|
|
20
20
|
import { safeParseJson } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
21
21
|
import { classifyTransientNetworkErrorCode } from "openclaw/plugin-sdk/retry-runtime";
|
|
22
22
|
import { fetchWithRuntimeDispatcherOrMockedGlobal } from "openclaw/plugin-sdk/runtime-fetch";
|
|
@@ -43,8 +43,9 @@ import { MediaFetchError } from "openclaw/plugin-sdk/media-runtime";
|
|
|
43
43
|
import { saveMediaStream } from "openclaw/plugin-sdk/media-store";
|
|
44
44
|
import { raceWithTimeout } from "openclaw/plugin-sdk/time-runtime";
|
|
45
45
|
import { enqueueKeyedTask } from "openclaw/plugin-sdk/keyed-async-queue";
|
|
46
|
+
import { sendJsonWithoutCharset } from "openclaw/plugin-sdk/http-response-runtime";
|
|
46
47
|
import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
|
|
47
|
-
|
|
48
|
+
// extensions/line/src/auto-reply-delivery.ts
|
|
48
49
|
function toLineDeliveryError(error) {
|
|
49
50
|
return error instanceof Error ? error : new Error("LINE message send failed", { cause: error });
|
|
50
51
|
}
|
|
@@ -228,8 +229,7 @@ async function deliverLineAutoReply(params) {
|
|
|
228
229
|
visibleReplySent
|
|
229
230
|
};
|
|
230
231
|
}
|
|
231
|
-
|
|
232
|
-
//#region extensions/line/src/mentions.ts
|
|
232
|
+
// extensions/line/src/mentions.ts
|
|
233
233
|
function getLineMentionees(message) {
|
|
234
234
|
return message.type === "text" ? message.mention?.mentionees ?? [] : [];
|
|
235
235
|
}
|
|
@@ -266,8 +266,7 @@ function resolveLineMentionStrippedText(message) {
|
|
|
266
266
|
}
|
|
267
267
|
return `${stripped}${text.slice(cursor)}`.trim();
|
|
268
268
|
}
|
|
269
|
-
|
|
270
|
-
//#region extensions/line/src/bot-message-context.ts
|
|
269
|
+
// extensions/line/src/bot-message-context.ts
|
|
271
270
|
function getLineSourceInfo(source) {
|
|
272
271
|
if (!source) return {
|
|
273
272
|
userId: void 0,
|
|
@@ -348,10 +347,7 @@ async function resolveLineInboundRoute(params) {
|
|
|
348
347
|
});
|
|
349
348
|
const prepared = params.preparedRoute ?? await prepareLineInboundRoute(params);
|
|
350
349
|
const { peerId, runtimeRoute, configuredBinding, configuredBindingSessionKey } = prepared;
|
|
351
|
-
if (runtimeRoute.bindingRecord)
|
|
352
|
-
await getSessionBindingService().touchAsync(runtimeRoute.bindingRecord.bindingId, void 0, runtimeRoute.bindingRecord.conversation);
|
|
353
|
-
logVerbose(runtimeRoute.boundSessionKey ? `line: routed via bound conversation ${peerId} -> ${runtimeRoute.boundSessionKey}` : `line: plugin-bound conversation ${peerId}`);
|
|
354
|
-
}
|
|
350
|
+
if (runtimeRoute.bindingRecord) await getSessionBindingService().touchAsync(runtimeRoute.bindingRecord.bindingId, void 0, runtimeRoute.bindingRecord.conversation);
|
|
355
351
|
if (configuredBinding) {
|
|
356
352
|
const ensured = await ensureConfiguredBindingRouteReady({
|
|
357
353
|
cfg: params.cfg,
|
|
@@ -361,7 +357,6 @@ async function resolveLineInboundRoute(params) {
|
|
|
361
357
|
logVerbose(`line: configured ACP binding unavailable for ${peerId} -> ${configuredBindingSessionKey}: ${ensured.error}`);
|
|
362
358
|
throw new Error(`Configured ACP binding unavailable: ${ensured.error}`);
|
|
363
359
|
}
|
|
364
|
-
logVerbose(`line: using configured ACP binding for ${peerId} -> ${configuredBindingSessionKey}`);
|
|
365
360
|
}
|
|
366
361
|
return prepared;
|
|
367
362
|
}
|
|
@@ -404,6 +399,12 @@ function extractNativeMediaKind(message) {
|
|
|
404
399
|
}
|
|
405
400
|
}
|
|
406
401
|
async function finalizeLineInboundContext(params) {
|
|
402
|
+
const channelIngress = await params.resolveChannelIngress?.({
|
|
403
|
+
agentId: params.route.agentId,
|
|
404
|
+
sessionKey: params.route.sessionKey,
|
|
405
|
+
messageId: params.messageSid,
|
|
406
|
+
inboundEventKind: "user_request"
|
|
407
|
+
});
|
|
407
408
|
const senderId = params.source.userId ?? "unknown";
|
|
408
409
|
const clientOpts = {
|
|
409
410
|
cfg: params.cfg,
|
|
@@ -443,7 +444,7 @@ async function finalizeLineInboundContext(params) {
|
|
|
443
444
|
envelope: envelopeOptions
|
|
444
445
|
});
|
|
445
446
|
const ctxPayload = (params.buildContext ?? buildChannelInboundEventContext)({
|
|
446
|
-
channelIngress
|
|
447
|
+
channelIngress,
|
|
447
448
|
channel: "line",
|
|
448
449
|
accountId: params.route.accountId,
|
|
449
450
|
messageId: params.messageSid,
|
|
@@ -493,11 +494,6 @@ async function finalizeLineInboundContext(params) {
|
|
|
493
494
|
route: params.route,
|
|
494
495
|
sessionKey: params.route.sessionKey
|
|
495
496
|
});
|
|
496
|
-
if (shouldLogVerbose()) {
|
|
497
|
-
const mediaInfo = params.verboseLog.kind === "inbound" && (params.verboseLog.mediaCount ?? 0) > 1 ? ` mediaCount=${params.verboseLog.mediaCount}` : "";
|
|
498
|
-
const label = params.verboseLog.kind === "inbound" ? "line inbound" : "line postback";
|
|
499
|
-
logVerbose(`${label}: from=${ctxPayload.From} len=${body.length}${mediaInfo}`);
|
|
500
|
-
}
|
|
501
497
|
return {
|
|
502
498
|
ctxPayload,
|
|
503
499
|
event: params.event,
|
|
@@ -545,9 +541,11 @@ async function buildLineMessageContext(params) {
|
|
|
545
541
|
const messageId = message.id;
|
|
546
542
|
const rawBody = extractMessageText(message);
|
|
547
543
|
const nativeMediaKind = extractNativeMediaKind(message);
|
|
548
|
-
const mediaFacts = allMedia.length > 0 ? allMedia.map((
|
|
549
|
-
|
|
550
|
-
|
|
544
|
+
const mediaFacts = allMedia.length > 0 ? allMedia.map(({ path, contentType, fileName }) => ({
|
|
545
|
+
path,
|
|
546
|
+
contentType,
|
|
547
|
+
fileName,
|
|
548
|
+
kind: nativeMediaKind === "document" && contentType?.startsWith("image/") ? "image" : nativeMediaKind
|
|
551
549
|
})) : nativeMediaKind ? [{ kind: nativeMediaKind }] : [];
|
|
552
550
|
const shortfallNotice = params.missingParts ? `[line: ${params.missingParts === 1 ? "1 more image in this send was" : `${params.missingParts} more images in this send were`} not delivered]` : void 0;
|
|
553
551
|
const withShortfall = shortfallNotice ? formatInboundMediaUnavailableText({
|
|
@@ -584,19 +582,10 @@ async function buildLineMessageContext(params) {
|
|
|
584
582
|
mentions: params.mentions,
|
|
585
583
|
messageSid: messageId,
|
|
586
584
|
commandAuthorized,
|
|
587
|
-
|
|
588
|
-
agentId: route.agentId,
|
|
589
|
-
sessionKey: route.sessionKey,
|
|
590
|
-
messageId,
|
|
591
|
-
inboundEventKind: "user_request"
|
|
592
|
-
}),
|
|
585
|
+
resolveChannelIngress: params.resolveChannelIngress,
|
|
593
586
|
buildContext: params.buildContext,
|
|
594
587
|
media: mediaFacts,
|
|
595
588
|
locationContext,
|
|
596
|
-
verboseLog: {
|
|
597
|
-
kind: "inbound",
|
|
598
|
-
mediaCount: allMedia.length
|
|
599
|
-
},
|
|
600
589
|
inboundHistory
|
|
601
590
|
});
|
|
602
591
|
}
|
|
@@ -632,19 +621,12 @@ async function buildLinePostbackContext(params) {
|
|
|
632
621
|
agentBody,
|
|
633
622
|
messageSid,
|
|
634
623
|
commandAuthorized,
|
|
635
|
-
|
|
636
|
-
agentId: route.agentId,
|
|
637
|
-
sessionKey: route.sessionKey,
|
|
638
|
-
messageId: messageSid,
|
|
639
|
-
inboundEventKind: "user_request"
|
|
640
|
-
}),
|
|
624
|
+
resolveChannelIngress: params.resolveChannelIngress,
|
|
641
625
|
buildContext: params.buildContext,
|
|
642
|
-
media: []
|
|
643
|
-
verboseLog: { kind: "postback" }
|
|
626
|
+
media: []
|
|
644
627
|
});
|
|
645
628
|
}
|
|
646
|
-
|
|
647
|
-
//#region extensions/line/src/download.ts
|
|
629
|
+
// extensions/line/src/download.ts
|
|
648
630
|
const CONTENT_READY_MAX_ATTEMPTS = 6;
|
|
649
631
|
const CONTENT_READY_BASE_DELAY_MS = 500;
|
|
650
632
|
const CONTENT_READY_MAX_DELAY_MS = 4e3;
|
|
@@ -685,9 +667,7 @@ async function* lineResponseBodyChunks(response, messageId, signal, onComplete)
|
|
|
685
667
|
}
|
|
686
668
|
} finally {
|
|
687
669
|
if (!completed) await reader.cancel(signal.aborted ? signal.reason : void 0).catch(() => void 0);
|
|
688
|
-
|
|
689
|
-
reader.releaseLock();
|
|
690
|
-
} catch {}
|
|
670
|
+
reader.releaseLock();
|
|
691
671
|
}
|
|
692
672
|
}
|
|
693
673
|
async function fetchLineContentWhenReady(messageId, channelAccessToken, signal) {
|
|
@@ -738,18 +718,15 @@ async function downloadLineMedia(messageId, channelAccessToken, maxBytes = 10485
|
|
|
738
718
|
throw err;
|
|
739
719
|
}
|
|
740
720
|
options?.signal?.throwIfAborted();
|
|
741
|
-
logVerbose(`line: persisted media ${messageId} to ${saved.path} (${saved.size} bytes)`);
|
|
742
721
|
return {
|
|
743
722
|
path: saved.path,
|
|
744
|
-
contentType: saved.contentType
|
|
745
|
-
size: saved.size
|
|
723
|
+
contentType: saved.contentType
|
|
746
724
|
};
|
|
747
725
|
} finally {
|
|
748
726
|
clearTimeout(deadline);
|
|
749
727
|
}
|
|
750
728
|
}
|
|
751
|
-
|
|
752
|
-
//#region extensions/line/src/group-history.ts
|
|
729
|
+
// extensions/line/src/group-history.ts
|
|
753
730
|
const reservedEntries = /* @__PURE__ */ new WeakSet();
|
|
754
731
|
function reserveLineGroupHistory(historyMap, historyKey, limit) {
|
|
755
732
|
if (!historyMap || !historyKey || limit <= 0) return {
|
|
@@ -783,8 +760,7 @@ function reserveLineGroupHistory(historyMap, historyKey, limit) {
|
|
|
783
760
|
}
|
|
784
761
|
};
|
|
785
762
|
}
|
|
786
|
-
|
|
787
|
-
//#region extensions/line/src/bot-handlers.ts
|
|
763
|
+
// extensions/line/src/bot-handlers.ts
|
|
788
764
|
const LINE_DOWNLOADABLE_MESSAGE_TYPES = /* @__PURE__ */ new Set([
|
|
789
765
|
"image",
|
|
790
766
|
"video",
|
|
@@ -794,9 +770,6 @@ const LINE_DOWNLOADABLE_MESSAGE_TYPES = /* @__PURE__ */ new Set([
|
|
|
794
770
|
function isDownloadableLineMessageType(messageType) {
|
|
795
771
|
return LINE_DOWNLOADABLE_MESSAGE_TYPES.has(messageType);
|
|
796
772
|
}
|
|
797
|
-
function normalizeLineIngressEntry(value) {
|
|
798
|
-
return normalizeLineAllowEntry(value) || null;
|
|
799
|
-
}
|
|
800
773
|
/**
|
|
801
774
|
* Say one line back to a sender, preferring their reply token so the answer costs no
|
|
802
775
|
* push quota, and falling back to a push when no token is usable. A partial-delivery
|
|
@@ -895,7 +868,7 @@ async function resolveLineEventAdmission(event, context) {
|
|
|
895
868
|
accountId: account.accountId,
|
|
896
869
|
identity: {
|
|
897
870
|
key: "line-user-id",
|
|
898
|
-
normalize:
|
|
871
|
+
normalize: (value) => normalizeLineAllowEntry(value) || null,
|
|
899
872
|
sensitivity: "pii",
|
|
900
873
|
entryIdPrefix: "line-entry"
|
|
901
874
|
},
|
|
@@ -1024,191 +997,11 @@ function resolveEventRawText(event) {
|
|
|
1024
997
|
if (event.type === "postback") return event.postback?.data?.trim() ?? "";
|
|
1025
998
|
return "";
|
|
1026
999
|
}
|
|
1027
|
-
async function handleMessageEvent(event, context, setParts) {
|
|
1028
|
-
const { cfg, account, runtime, mediaMaxBytes, processMessage } = context;
|
|
1029
|
-
const message = event.message;
|
|
1030
|
-
const decision = await resolveLineEventAdmission(event, context);
|
|
1031
|
-
if (!decision) return;
|
|
1032
|
-
const { isGroup, groupId, roomId, userId } = getLineSourceInfo(event.source);
|
|
1033
|
-
if (isGroup && decision.access.activationAccess.shouldSkip) {
|
|
1034
|
-
const rawText = message.type === "text" ? readLineTextMessageBody(message) : "";
|
|
1035
|
-
const historyKey = groupId ?? roomId;
|
|
1036
|
-
const groupsConfigPath = resolveChannelGroupsConfigPath({
|
|
1037
|
-
cfg,
|
|
1038
|
-
channel: "line",
|
|
1039
|
-
accountId: account.accountId,
|
|
1040
|
-
groups: account.config.groups
|
|
1041
|
-
});
|
|
1042
|
-
logInboundDrop({
|
|
1043
|
-
log: runtime.log,
|
|
1044
|
-
channel: "line",
|
|
1045
|
-
reason: "no mention",
|
|
1046
|
-
target: historyKey,
|
|
1047
|
-
onceKey: JSON.stringify([account.accountId, historyKey]),
|
|
1048
|
-
hint: `Mention patterns can be derived from the agent identity name. Set ${groupsConfigPath}[${JSON.stringify(historyKey)}].requireMention=false to process messages without a mention. Preserve existing groups entries; when adding the first groups map, include "*": {} to keep other chats admitted.`
|
|
1049
|
-
});
|
|
1050
|
-
const senderId = userId ?? "unknown";
|
|
1051
|
-
if (historyKey && context.groupHistories) {
|
|
1052
|
-
const displayName = userId ? await getUserDisplayName(userId, {
|
|
1053
|
-
cfg,
|
|
1054
|
-
accountId: account.accountId,
|
|
1055
|
-
channelAccessToken: account.channelAccessToken,
|
|
1056
|
-
groupId,
|
|
1057
|
-
roomId
|
|
1058
|
-
}) : senderId;
|
|
1059
|
-
const sender = displayName === senderId ? senderId : `${displayName} (${senderId})`;
|
|
1060
|
-
createChannelHistoryWindow({ historyMap: context.groupHistories }).record({
|
|
1061
|
-
historyKey,
|
|
1062
|
-
limit: context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT,
|
|
1063
|
-
entry: {
|
|
1064
|
-
sender,
|
|
1065
|
-
body: rawText || `<${message.type}>`,
|
|
1066
|
-
timestamp: event.timestamp
|
|
1067
|
-
}
|
|
1068
|
-
});
|
|
1069
|
-
}
|
|
1070
|
-
return;
|
|
1071
|
-
}
|
|
1072
|
-
const groupHistoryKey = isGroup ? groupId ?? roomId : void 0;
|
|
1073
|
-
const historyReservation = reserveLineGroupHistory(context.groupHistories, groupHistoryKey, context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT);
|
|
1074
|
-
try {
|
|
1075
|
-
const allMedia = [];
|
|
1076
|
-
let mediaUnavailable = false;
|
|
1077
|
-
const abortSignal = context.turnAdoptionLifecycle?.abortSignal;
|
|
1078
|
-
for (const part of orderedLineSetMessages(message, setParts)) {
|
|
1079
|
-
if (!isDownloadableLineMessageType(part.type)) continue;
|
|
1080
|
-
try {
|
|
1081
|
-
const originalFilename = part.type === "file" ? normalizeOptionalString(part.fileName) : void 0;
|
|
1082
|
-
const media = await downloadLineMedia(part.id, account.channelAccessToken, mediaMaxBytes, {
|
|
1083
|
-
originalFilename,
|
|
1084
|
-
...abortSignal ? { signal: abortSignal } : {}
|
|
1085
|
-
});
|
|
1086
|
-
abortSignal?.throwIfAborted();
|
|
1087
|
-
allMedia.push({
|
|
1088
|
-
path: media.path,
|
|
1089
|
-
contentType: media.contentType,
|
|
1090
|
-
...originalFilename ? { fileName: originalFilename } : {}
|
|
1091
|
-
});
|
|
1092
|
-
} catch (err) {
|
|
1093
|
-
if (abortSignal?.aborted) throw abortSignal.reason;
|
|
1094
|
-
if (isRetryableLineInboundMediaError(err)) throw err;
|
|
1095
|
-
mediaUnavailable = true;
|
|
1096
|
-
const errMsg = String(err);
|
|
1097
|
-
if (errMsg.includes("exceeds") && errMsg.includes("limit")) logVerbose(`line: media exceeds size limit for message ${part.id}`);
|
|
1098
|
-
else runtime.error?.(danger(`line: failed to download media: ${errMsg}`));
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
const messageContext = await buildLineMessageContext({
|
|
1102
|
-
event: setParts.reduce((freshest, part) => part.timestamp > freshest.timestamp ? part : freshest, event),
|
|
1103
|
-
allMedia: [...allMedia],
|
|
1104
|
-
mediaUnavailable,
|
|
1105
|
-
...context.missingParts === void 0 ? {} : { missingParts: context.missingParts },
|
|
1106
|
-
cfg,
|
|
1107
|
-
account,
|
|
1108
|
-
preparedRoute: decision.preparedRoute,
|
|
1109
|
-
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1110
|
-
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1111
|
-
inboundHistory: historyReservation.inboundHistory,
|
|
1112
|
-
mentions: decision.mentions,
|
|
1113
|
-
buildContext: context.buildContext
|
|
1114
|
-
});
|
|
1115
|
-
if (!messageContext) logVerbose("line: skipping empty message");
|
|
1116
|
-
else {
|
|
1117
|
-
await processMessage(messageContext, {
|
|
1118
|
-
cfg: context.cfg,
|
|
1119
|
-
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1120
|
-
});
|
|
1121
|
-
historyReservation.commit();
|
|
1122
|
-
}
|
|
1123
|
-
} finally {
|
|
1124
|
-
historyReservation.release();
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
async function handleJoinEvent(event, context) {
|
|
1128
|
-
const { groupId, roomId, isGroup } = getLineSourceInfo(event.source);
|
|
1129
|
-
const conversationId = groupId ?? roomId;
|
|
1130
|
-
if (!isGroup || !conversationId) return;
|
|
1131
|
-
logVerbose(`line: bot joined ${groupId ? `group ${groupId}` : `room ${roomId}`}`);
|
|
1132
|
-
const { cfg, account } = context;
|
|
1133
|
-
const roomAllowed = Boolean(await resolveLineEventAdmission(event, context));
|
|
1134
|
-
await reportChannelRoomJoin({
|
|
1135
|
-
cfg,
|
|
1136
|
-
channel: "line",
|
|
1137
|
-
accountId: account.accountId,
|
|
1138
|
-
conversationId,
|
|
1139
|
-
deliverTo: conversationId,
|
|
1140
|
-
route: resolveAgentRoute({
|
|
1141
|
-
cfg,
|
|
1142
|
-
channel: "line",
|
|
1143
|
-
accountId: account.accountId,
|
|
1144
|
-
peer: {
|
|
1145
|
-
kind: "group",
|
|
1146
|
-
id: conversationId
|
|
1147
|
-
}
|
|
1148
|
-
}),
|
|
1149
|
-
roomAllowed,
|
|
1150
|
-
resolveRoomContext: async () => {
|
|
1151
|
-
const roomContext = { historyUnavailable: true };
|
|
1152
|
-
const title = groupId ? await getLineGroupName(groupId, {
|
|
1153
|
-
cfg,
|
|
1154
|
-
accountId: account.accountId,
|
|
1155
|
-
channelAccessToken: account.channelAccessToken
|
|
1156
|
-
}) : void 0;
|
|
1157
|
-
return title ? {
|
|
1158
|
-
...roomContext,
|
|
1159
|
-
title
|
|
1160
|
-
} : roomContext;
|
|
1161
|
-
}
|
|
1162
|
-
});
|
|
1163
|
-
}
|
|
1164
1000
|
/** What a tap that did not answer the question has to tell the person who tapped. */
|
|
1165
1001
|
function lineQuestionOutcomeNotice(status) {
|
|
1166
1002
|
if (status === "already-terminal") return "That question is no longer waiting for an answer.";
|
|
1167
1003
|
return "Could not record that answer. Reply with the option text instead.";
|
|
1168
1004
|
}
|
|
1169
|
-
async function handlePostbackEvent(event, context) {
|
|
1170
|
-
const data = event.postback.data;
|
|
1171
|
-
logVerbose(`line: received postback: ${data}`);
|
|
1172
|
-
const decision = await resolveLineEventAdmission(event, context);
|
|
1173
|
-
if (!decision) return;
|
|
1174
|
-
const question = parseLineQuestionPostbackData(data ?? "");
|
|
1175
|
-
if (question) {
|
|
1176
|
-
const { userId, groupId, roomId } = getLineSourceInfo(event.source);
|
|
1177
|
-
const authorize = async () => isLineEventAdmitted(await decision.resolveBoundAccess());
|
|
1178
|
-
const outcome = await resolveLineQuestionPostback({
|
|
1179
|
-
cfg: context.cfg,
|
|
1180
|
-
callback: question,
|
|
1181
|
-
accountId: context.account.accountId,
|
|
1182
|
-
...userId ? { senderId: userId } : {},
|
|
1183
|
-
authorize
|
|
1184
|
-
});
|
|
1185
|
-
const pushTarget = groupId ?? roomId ?? (userId ? `line:${userId}` : void 0);
|
|
1186
|
-
if (outcome.status === "answered" || outcome.status === "denied" || !pushTarget) return;
|
|
1187
|
-
await sendLineHandlerText({
|
|
1188
|
-
context,
|
|
1189
|
-
replyToken: event.replyToken,
|
|
1190
|
-
pushTarget,
|
|
1191
|
-
logLabel: "line: question answer notice failed",
|
|
1192
|
-
text: lineQuestionOutcomeNotice(outcome.status),
|
|
1193
|
-
authorize
|
|
1194
|
-
});
|
|
1195
|
-
return;
|
|
1196
|
-
}
|
|
1197
|
-
if (isLineQuestionPostbackData(data ?? "")) return;
|
|
1198
|
-
const postbackContext = await buildLinePostbackContext({
|
|
1199
|
-
event,
|
|
1200
|
-
cfg: context.cfg,
|
|
1201
|
-
account: context.account,
|
|
1202
|
-
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1203
|
-
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1204
|
-
buildContext: context.buildContext
|
|
1205
|
-
});
|
|
1206
|
-
if (!postbackContext) return;
|
|
1207
|
-
await context.processMessage(postbackContext, {
|
|
1208
|
-
cfg: context.cfg,
|
|
1209
|
-
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1210
|
-
});
|
|
1211
|
-
}
|
|
1212
1005
|
/** Media reads in the order the sender picked, whatever order LINE delivered. */
|
|
1213
1006
|
function orderedLineSetMessages(message, setParts) {
|
|
1214
1007
|
const messages = [message, ...setParts.map((partEvent) => partEvent.message)];
|
|
@@ -1225,26 +1018,195 @@ async function handleLineWebhookEvents(events, context) {
|
|
|
1225
1018
|
if (!event) return;
|
|
1226
1019
|
try {
|
|
1227
1020
|
switch (event.type) {
|
|
1228
|
-
case "message":
|
|
1229
|
-
|
|
1021
|
+
case "message": {
|
|
1022
|
+
const messageSetParts = setParts.filter((part) => part.type === "message");
|
|
1023
|
+
const { cfg, account, runtime, mediaMaxBytes, processMessage } = context;
|
|
1024
|
+
const message = event.message;
|
|
1025
|
+
const decision = await resolveLineEventAdmission(event, context);
|
|
1026
|
+
if (!decision) return;
|
|
1027
|
+
const { isGroup, groupId, roomId, userId } = getLineSourceInfo(event.source);
|
|
1028
|
+
if (isGroup && decision.access.activationAccess.shouldSkip) {
|
|
1029
|
+
const rawText = message.type === "text" ? readLineTextMessageBody(message) : "";
|
|
1030
|
+
const historyKey = groupId ?? roomId;
|
|
1031
|
+
const groupsConfigPath = resolveChannelGroupsConfigPath({
|
|
1032
|
+
cfg,
|
|
1033
|
+
channel: "line",
|
|
1034
|
+
accountId: account.accountId,
|
|
1035
|
+
groups: account.config.groups
|
|
1036
|
+
});
|
|
1037
|
+
logInboundDrop({
|
|
1038
|
+
log: runtime.log,
|
|
1039
|
+
channel: "line",
|
|
1040
|
+
reason: "no mention",
|
|
1041
|
+
target: historyKey,
|
|
1042
|
+
onceKey: JSON.stringify([account.accountId, historyKey]),
|
|
1043
|
+
hint: `Mention patterns can be derived from the agent identity name. Set ${groupsConfigPath}[${JSON.stringify(historyKey)}].requireMention=false to process messages without a mention. Preserve existing groups entries; when adding the first groups map, include "*": {} to keep other chats admitted.`
|
|
1044
|
+
});
|
|
1045
|
+
const senderId = userId ?? "unknown";
|
|
1046
|
+
if (historyKey && context.groupHistories) {
|
|
1047
|
+
const displayName = userId ? await getUserDisplayName(userId, {
|
|
1048
|
+
cfg,
|
|
1049
|
+
accountId: account.accountId,
|
|
1050
|
+
channelAccessToken: account.channelAccessToken,
|
|
1051
|
+
groupId,
|
|
1052
|
+
roomId
|
|
1053
|
+
}) : senderId;
|
|
1054
|
+
const sender = displayName === senderId ? senderId : `${displayName} (${senderId})`;
|
|
1055
|
+
createChannelHistoryWindow({ historyMap: context.groupHistories }).record({
|
|
1056
|
+
historyKey,
|
|
1057
|
+
limit: context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT,
|
|
1058
|
+
entry: {
|
|
1059
|
+
sender,
|
|
1060
|
+
body: rawText || `<${message.type}>`,
|
|
1061
|
+
timestamp: event.timestamp
|
|
1062
|
+
}
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
const groupHistoryKey = isGroup ? groupId ?? roomId : void 0;
|
|
1068
|
+
const historyReservation = reserveLineGroupHistory(context.groupHistories, groupHistoryKey, context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT);
|
|
1069
|
+
try {
|
|
1070
|
+
const allMedia = [];
|
|
1071
|
+
let mediaUnavailable = false;
|
|
1072
|
+
const abortSignal = context.turnAdoptionLifecycle?.abortSignal;
|
|
1073
|
+
for (const part of orderedLineSetMessages(message, messageSetParts)) {
|
|
1074
|
+
if (!isDownloadableLineMessageType(part.type)) continue;
|
|
1075
|
+
try {
|
|
1076
|
+
const originalFilename = part.type === "file" ? normalizeOptionalString(part.fileName) : void 0;
|
|
1077
|
+
const media = await downloadLineMedia(part.id, account.channelAccessToken, mediaMaxBytes, {
|
|
1078
|
+
originalFilename,
|
|
1079
|
+
...abortSignal ? { signal: abortSignal } : {}
|
|
1080
|
+
});
|
|
1081
|
+
abortSignal?.throwIfAborted();
|
|
1082
|
+
allMedia.push({
|
|
1083
|
+
path: media.path,
|
|
1084
|
+
contentType: media.contentType,
|
|
1085
|
+
...originalFilename ? { fileName: originalFilename } : {}
|
|
1086
|
+
});
|
|
1087
|
+
} catch (err) {
|
|
1088
|
+
if (abortSignal?.aborted) throw abortSignal.reason;
|
|
1089
|
+
if (isRetryableLineInboundMediaError(err)) throw err;
|
|
1090
|
+
mediaUnavailable = true;
|
|
1091
|
+
const errMsg = String(err);
|
|
1092
|
+
if (errMsg.includes("exceeds") && errMsg.includes("limit")) logVerbose(`line: media exceeds size limit for message ${part.id}`);
|
|
1093
|
+
else runtime.error?.(danger(`line: failed to download media: ${errMsg}`));
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
const messageContext = await buildLineMessageContext({
|
|
1097
|
+
event: messageSetParts.reduce((freshest, part) => part.timestamp > freshest.timestamp ? part : freshest, event),
|
|
1098
|
+
allMedia,
|
|
1099
|
+
mediaUnavailable,
|
|
1100
|
+
...context.missingParts === void 0 ? {} : { missingParts: context.missingParts },
|
|
1101
|
+
cfg,
|
|
1102
|
+
account,
|
|
1103
|
+
preparedRoute: decision.preparedRoute,
|
|
1104
|
+
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1105
|
+
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1106
|
+
inboundHistory: historyReservation.inboundHistory,
|
|
1107
|
+
mentions: decision.mentions,
|
|
1108
|
+
buildContext: context.buildContext
|
|
1109
|
+
});
|
|
1110
|
+
if (messageContext) {
|
|
1111
|
+
await processMessage(messageContext, {
|
|
1112
|
+
cfg: context.cfg,
|
|
1113
|
+
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1114
|
+
});
|
|
1115
|
+
historyReservation.commit();
|
|
1116
|
+
}
|
|
1117
|
+
} finally {
|
|
1118
|
+
historyReservation.release();
|
|
1119
|
+
}
|
|
1230
1120
|
break;
|
|
1121
|
+
}
|
|
1231
1122
|
case "follow":
|
|
1232
|
-
case "unfollow":
|
|
1233
|
-
|
|
1234
|
-
|
|
1123
|
+
case "unfollow": break;
|
|
1124
|
+
case "join": {
|
|
1125
|
+
const { groupId, roomId, isGroup } = getLineSourceInfo(event.source);
|
|
1126
|
+
const conversationId = groupId ?? roomId;
|
|
1127
|
+
if (!isGroup || !conversationId) return;
|
|
1128
|
+
logVerbose(`line: bot joined ${groupId ? `group ${groupId}` : `room ${roomId}`}`);
|
|
1129
|
+
const { cfg, account } = context;
|
|
1130
|
+
const roomAllowed = Boolean(await resolveLineEventAdmission(event, context));
|
|
1131
|
+
await reportChannelRoomJoin({
|
|
1132
|
+
cfg,
|
|
1133
|
+
channel: "line",
|
|
1134
|
+
accountId: account.accountId,
|
|
1135
|
+
conversationId,
|
|
1136
|
+
deliverTo: conversationId,
|
|
1137
|
+
route: resolveAgentRoute({
|
|
1138
|
+
cfg,
|
|
1139
|
+
channel: "line",
|
|
1140
|
+
accountId: account.accountId,
|
|
1141
|
+
peer: {
|
|
1142
|
+
kind: "group",
|
|
1143
|
+
id: conversationId
|
|
1144
|
+
}
|
|
1145
|
+
}),
|
|
1146
|
+
roomAllowed,
|
|
1147
|
+
resolveRoomContext: async () => {
|
|
1148
|
+
const roomContext = { historyUnavailable: true };
|
|
1149
|
+
const title = groupId ? await getLineGroupName(groupId, {
|
|
1150
|
+
cfg,
|
|
1151
|
+
accountId: account.accountId,
|
|
1152
|
+
channelAccessToken: account.channelAccessToken
|
|
1153
|
+
}) : void 0;
|
|
1154
|
+
return title ? {
|
|
1155
|
+
...roomContext,
|
|
1156
|
+
title
|
|
1157
|
+
} : roomContext;
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1235
1160
|
break;
|
|
1236
1161
|
}
|
|
1237
|
-
case "join":
|
|
1238
|
-
await handleJoinEvent(event, context);
|
|
1239
|
-
break;
|
|
1240
1162
|
case "leave": {
|
|
1241
1163
|
const { groupId, roomId } = getLineSourceInfo(event.source);
|
|
1242
1164
|
logVerbose(`line: bot left ${groupId ? `group ${groupId}` : `room ${roomId}`}`);
|
|
1243
1165
|
break;
|
|
1244
1166
|
}
|
|
1245
|
-
case "postback":
|
|
1246
|
-
|
|
1167
|
+
case "postback": {
|
|
1168
|
+
const data = event.postback.data;
|
|
1169
|
+
const decision = await resolveLineEventAdmission(event, context);
|
|
1170
|
+
if (!decision) return;
|
|
1171
|
+
const question = parseLineQuestionPostbackData(data ?? "");
|
|
1172
|
+
if (question) {
|
|
1173
|
+
const { userId, groupId, roomId } = getLineSourceInfo(event.source);
|
|
1174
|
+
const authorize = async () => isLineEventAdmitted(await decision.resolveBoundAccess());
|
|
1175
|
+
const outcome = await resolveLineQuestionPostback({
|
|
1176
|
+
cfg: context.cfg,
|
|
1177
|
+
callback: question,
|
|
1178
|
+
accountId: context.account.accountId,
|
|
1179
|
+
...userId ? { senderId: userId } : {},
|
|
1180
|
+
authorize
|
|
1181
|
+
});
|
|
1182
|
+
const pushTarget = groupId ?? roomId ?? (userId ? `line:${userId}` : void 0);
|
|
1183
|
+
if (outcome.status === "answered" || outcome.status === "denied" || !pushTarget) return;
|
|
1184
|
+
await sendLineHandlerText({
|
|
1185
|
+
context,
|
|
1186
|
+
replyToken: event.replyToken,
|
|
1187
|
+
pushTarget,
|
|
1188
|
+
logLabel: "line: question answer notice failed",
|
|
1189
|
+
text: lineQuestionOutcomeNotice(outcome.status),
|
|
1190
|
+
authorize
|
|
1191
|
+
});
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
if (isLineQuestionPostbackData(data ?? "")) return;
|
|
1195
|
+
const postbackContext = await buildLinePostbackContext({
|
|
1196
|
+
event,
|
|
1197
|
+
cfg: context.cfg,
|
|
1198
|
+
account: context.account,
|
|
1199
|
+
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1200
|
+
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1201
|
+
buildContext: context.buildContext
|
|
1202
|
+
});
|
|
1203
|
+
if (!postbackContext) return;
|
|
1204
|
+
await context.processMessage(postbackContext, {
|
|
1205
|
+
cfg: context.cfg,
|
|
1206
|
+
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1207
|
+
});
|
|
1247
1208
|
break;
|
|
1209
|
+
}
|
|
1248
1210
|
default: logVerbose(`line: unhandled event type: ${event.type}`);
|
|
1249
1211
|
}
|
|
1250
1212
|
} catch (err) {
|
|
@@ -1252,8 +1214,7 @@ async function handleLineWebhookEvents(events, context) {
|
|
|
1252
1214
|
throw toErrorObject(err, "Non-Error thrown");
|
|
1253
1215
|
}
|
|
1254
1216
|
}
|
|
1255
|
-
|
|
1256
|
-
//#region extensions/line/src/inbound-image-set.ts
|
|
1217
|
+
// extensions/line/src/inbound-image-set.ts
|
|
1257
1218
|
const IMAGE_SET_FLUSH_DELAY_MS = 4e3;
|
|
1258
1219
|
function orderedParts(pending) {
|
|
1259
1220
|
return [...pending.parts.values()].toSorted((left, right) => (left.index ?? Number.MAX_SAFE_INTEGER) - (right.index ?? Number.MAX_SAFE_INTEGER) || left.arrivedAt - right.arrivedAt);
|
|
@@ -1344,8 +1305,7 @@ function createLineImageSetIngressBuffer() {
|
|
|
1344
1305
|
isBusy: (laneKey) => laneChain.has(laneKey)
|
|
1345
1306
|
};
|
|
1346
1307
|
}
|
|
1347
|
-
|
|
1348
|
-
//#region extensions/line/src/webhook-spool.ts
|
|
1308
|
+
// extensions/line/src/webhook-spool.ts
|
|
1349
1309
|
const LINE_WEBHOOK_DRAIN_INTERVAL_MS = 500;
|
|
1350
1310
|
const LINE_WEBHOOK_MAX_CONCURRENT_DELIVERIES = 8;
|
|
1351
1311
|
const LINE_WEBHOOK_DRAIN_SCAN_LIMIT = 100;
|
|
@@ -1468,17 +1428,11 @@ function createLineWebhookSpool(options) {
|
|
|
1468
1428
|
}
|
|
1469
1429
|
const fannedIn = fanInChannelIngressLifecycles(turnLifecycles);
|
|
1470
1430
|
const boundLifecycle = bindIngressLifecycleToReplyOptions(fannedIn.lifecycle ?? lifecycle).turnAdoptionLifecycle;
|
|
1471
|
-
let handedOff = false;
|
|
1472
1431
|
const delivery = options.deliver(turnEvents, destination, {
|
|
1473
1432
|
...missingParts === void 0 ? {} : { missingParts },
|
|
1474
1433
|
turnAdoptionLifecycle: {
|
|
1475
1434
|
...boundLifecycle,
|
|
1476
|
-
onAdopted: async () => {
|
|
1477
|
-
handedOff = true;
|
|
1478
|
-
await boundLifecycle.onAdopted();
|
|
1479
|
-
},
|
|
1480
1435
|
onDeferred: () => {
|
|
1481
|
-
handedOff = true;
|
|
1482
1436
|
if (!acceptsDeferredClaims) {
|
|
1483
1437
|
Promise.resolve().then(() => boundLifecycle.onAbandoned()).catch((error) => {
|
|
1484
1438
|
options.runtime.error?.(danger(`line: failed to abandon a late webhook delivery: ${formatErrorMessage(error)}`));
|
|
@@ -1486,10 +1440,6 @@ function createLineWebhookSpool(options) {
|
|
|
1486
1440
|
return;
|
|
1487
1441
|
}
|
|
1488
1442
|
boundLifecycle.onDeferred();
|
|
1489
|
-
},
|
|
1490
|
-
onAbandoned: async () => {
|
|
1491
|
-
handedOff = true;
|
|
1492
|
-
await boundLifecycle.onAbandoned();
|
|
1493
1443
|
}
|
|
1494
1444
|
}
|
|
1495
1445
|
});
|
|
@@ -1498,20 +1448,13 @@ function createLineWebhookSpool(options) {
|
|
|
1498
1448
|
await delivery;
|
|
1499
1449
|
} catch (error) {
|
|
1500
1450
|
await fannedIn.abandon(error);
|
|
1501
|
-
handedOff = true;
|
|
1502
1451
|
throw error;
|
|
1503
1452
|
} finally {
|
|
1504
1453
|
activeDeliveries.delete(delivery);
|
|
1505
1454
|
releaseLane?.();
|
|
1506
1455
|
}
|
|
1507
|
-
if (
|
|
1508
|
-
|
|
1509
|
-
handedOff = true;
|
|
1510
|
-
}
|
|
1511
|
-
if (stopTask && !handedOff) {
|
|
1512
|
-
await fannedIn.abandon();
|
|
1513
|
-
return;
|
|
1514
|
-
}
|
|
1456
|
+
if (stopTask) await fannedIn.abandon();
|
|
1457
|
+
else await fannedIn.settle();
|
|
1515
1458
|
},
|
|
1516
1459
|
pollIntervalMs: LINE_WEBHOOK_DRAIN_INTERVAL_MS,
|
|
1517
1460
|
retention: {
|
|
@@ -1585,8 +1528,7 @@ function createLineWebhookSpool(options) {
|
|
|
1585
1528
|
}
|
|
1586
1529
|
};
|
|
1587
1530
|
}
|
|
1588
|
-
|
|
1589
|
-
//#region extensions/line/src/bot.ts
|
|
1531
|
+
// extensions/line/src/bot.ts
|
|
1590
1532
|
const DEFAULT_MEDIA_MAX_MB = 10;
|
|
1591
1533
|
function createLineBot(opts) {
|
|
1592
1534
|
const { runtime, config: startupConfig } = opts;
|
|
@@ -1603,14 +1545,14 @@ function createLineBot(opts) {
|
|
|
1603
1545
|
accountId: opts.accountId
|
|
1604
1546
|
});
|
|
1605
1547
|
const configuredMediaMaxMb = account.config.mediaMaxMb;
|
|
1606
|
-
const mediaMaxBytes = (
|
|
1548
|
+
const mediaMaxBytes = (configuredMediaMaxMb !== void 0 && configuredMediaMaxMb > 0 ? configuredMediaMaxMb : DEFAULT_MEDIA_MAX_MB) * 1024 * 1024;
|
|
1607
1549
|
const groupHistories = /* @__PURE__ */ new Map();
|
|
1608
1550
|
const spool = createLineWebhookSpool({
|
|
1609
1551
|
accountId: account.accountId,
|
|
1610
1552
|
runtime,
|
|
1611
1553
|
deliver: async (events, _destination, control) => {
|
|
1612
1554
|
const cfg = resolveTurnConfig();
|
|
1613
|
-
await handleLineWebhookEvents(
|
|
1555
|
+
await handleLineWebhookEvents(events, {
|
|
1614
1556
|
cfg,
|
|
1615
1557
|
account,
|
|
1616
1558
|
runtime,
|
|
@@ -1631,53 +1573,15 @@ function createLineBot(opts) {
|
|
|
1631
1573
|
stop: spool.stop
|
|
1632
1574
|
};
|
|
1633
1575
|
}
|
|
1634
|
-
|
|
1635
|
-
//#region extensions/line/src/monitor-durable.ts
|
|
1636
|
-
function resolveLineDurableReplyOptions(params) {
|
|
1637
|
-
if (params.infoKind !== "final") return false;
|
|
1638
|
-
if (params.replyToken && !params.replyTokenUsed) return false;
|
|
1639
|
-
const lineData = params.payload.channelData?.line;
|
|
1640
|
-
if (lineData && Object.keys(lineData).length > 0) return false;
|
|
1641
|
-
const reply = resolveSendableOutboundReplyParts(params.payload);
|
|
1642
|
-
if (reply.hasMedia || !reply.hasText) return false;
|
|
1643
|
-
return { to: params.to };
|
|
1644
|
-
}
|
|
1645
|
-
//#endregion
|
|
1646
|
-
//#region extensions/line/src/signature.ts
|
|
1576
|
+
// extensions/line/src/signature.ts
|
|
1647
1577
|
function validateLineSignature(body, signature, channelSecret) {
|
|
1648
1578
|
const hash = crypto.createHmac("SHA256", channelSecret).update(body).digest("base64");
|
|
1649
1579
|
return safeEqualSecret(signature, hash);
|
|
1650
1580
|
}
|
|
1651
|
-
|
|
1652
|
-
//#region extensions/line/src/webhook-node.ts
|
|
1581
|
+
// extensions/line/src/webhook-node.ts
|
|
1653
1582
|
const LINE_WEBHOOK_PREAUTH_MAX_BODY_BYTES = 65536;
|
|
1654
1583
|
const LINE_WEBHOOK_PREAUTH_BODY_TIMEOUT_MS = 5e3;
|
|
1655
|
-
async function readLineWebhookRequestBody(req, maxBytes, timeoutMs) {
|
|
1656
|
-
return await readRequestBodyWithLimit(req, {
|
|
1657
|
-
maxBytes,
|
|
1658
|
-
timeoutMs,
|
|
1659
|
-
destroyOnLimit: false
|
|
1660
|
-
});
|
|
1661
|
-
}
|
|
1662
|
-
/**
|
|
1663
|
-
* Answer a body-limit failure through the connection owner.
|
|
1664
|
-
*
|
|
1665
|
-
* The reader defers destruction for these two codes, so the connection is already fenced
|
|
1666
|
-
* and only the owner can still write: responding directly would race the teardown and LINE
|
|
1667
|
-
* would see a reset instead of the status.
|
|
1668
|
-
*/
|
|
1669
|
-
async function rejectLineWebhookRequest(req, res, error) {
|
|
1670
|
-
if (!isRequestBodyLimitError(error, "PAYLOAD_TOO_LARGE") && !isRequestBodyLimitError(error, "REQUEST_BODY_TIMEOUT")) return false;
|
|
1671
|
-
await sendHttpRequestRejection(req, res, error.statusCode, JSON.stringify({ error: requestBodyErrorToText(error.code) }), "application/json");
|
|
1672
|
-
return true;
|
|
1673
|
-
}
|
|
1674
|
-
function sendLineWebhookJson(res, statusCode, body) {
|
|
1675
|
-
res.statusCode = statusCode;
|
|
1676
|
-
res.setHeader("Content-Type", "application/json");
|
|
1677
|
-
res.end(JSON.stringify(body));
|
|
1678
|
-
}
|
|
1679
1584
|
function createLineNodeWebhookHandler(params) {
|
|
1680
|
-
const readBody = params.readBody ?? readLineWebhookRequestBody;
|
|
1681
1585
|
return async (req, res) => {
|
|
1682
1586
|
const targets = params.getTargets();
|
|
1683
1587
|
if (req.method !== "POST" && targets.length === 0) {
|
|
@@ -1698,7 +1602,7 @@ function createLineNodeWebhookHandler(params) {
|
|
|
1698
1602
|
}
|
|
1699
1603
|
if (req.method !== "POST") {
|
|
1700
1604
|
res.setHeader("Allow", "GET, HEAD, POST");
|
|
1701
|
-
|
|
1605
|
+
sendJsonWithoutCharset(res, 405, { error: "Method Not Allowed" });
|
|
1702
1606
|
return;
|
|
1703
1607
|
}
|
|
1704
1608
|
try {
|
|
@@ -1706,54 +1610,45 @@ function createLineNodeWebhookHandler(params) {
|
|
|
1706
1610
|
const signature = typeof signatureHeader === "string" ? signatureHeader.trim() : Array.isArray(signatureHeader) ? (signatureHeader[0] ?? "").trim() : "";
|
|
1707
1611
|
if (!signature) {
|
|
1708
1612
|
logVerbose("line: webhook missing X-Line-Signature header");
|
|
1709
|
-
|
|
1613
|
+
sendJsonWithoutCharset(res, 400, { error: "Missing X-Line-Signature header" });
|
|
1710
1614
|
return;
|
|
1711
1615
|
}
|
|
1712
|
-
const rawBody = await
|
|
1616
|
+
const rawBody = await readRequestBodyWithLimit(req, {
|
|
1617
|
+
maxBytes: LINE_WEBHOOK_PREAUTH_MAX_BODY_BYTES,
|
|
1618
|
+
timeoutMs: LINE_WEBHOOK_PREAUTH_BODY_TIMEOUT_MS,
|
|
1619
|
+
destroyOnLimit: false
|
|
1620
|
+
});
|
|
1713
1621
|
const match = resolveSingleWebhookTarget(targets, (target) => validateLineSignature(rawBody, signature, target.channelSecret));
|
|
1714
1622
|
if (match.kind === "none") {
|
|
1715
1623
|
logVerbose("line: webhook signature validation failed");
|
|
1716
|
-
|
|
1624
|
+
sendJsonWithoutCharset(res, 401, { error: "Invalid signature" });
|
|
1717
1625
|
return;
|
|
1718
1626
|
}
|
|
1719
1627
|
if (match.kind === "ambiguous") {
|
|
1720
1628
|
logVerbose("line: webhook signature matched multiple accounts");
|
|
1721
|
-
|
|
1629
|
+
sendJsonWithoutCharset(res, 401, { error: "Ambiguous webhook target" });
|
|
1722
1630
|
return;
|
|
1723
1631
|
}
|
|
1724
1632
|
const body = safeParseJson(rawBody);
|
|
1725
1633
|
if (!body) {
|
|
1726
|
-
|
|
1634
|
+
sendJsonWithoutCharset(res, 400, { error: "Invalid webhook payload" });
|
|
1727
1635
|
return;
|
|
1728
1636
|
}
|
|
1729
1637
|
if (body.events && body.events.length > 0) {
|
|
1730
|
-
logVerbose(`line: received ${body.events.length} webhook events`);
|
|
1731
1638
|
if (await match.target.bot.handleWebhook(body) === "durable") res.setHeader("x-openclaw-delivery-accepted", "durable");
|
|
1732
1639
|
}
|
|
1733
|
-
|
|
1640
|
+
sendJsonWithoutCharset(res, 200, { status: "ok" });
|
|
1734
1641
|
} catch (err) {
|
|
1735
|
-
if (
|
|
1642
|
+
if (isRequestBodyLimitError(err, "PAYLOAD_TOO_LARGE") || isRequestBodyLimitError(err, "REQUEST_BODY_TIMEOUT")) {
|
|
1643
|
+
await sendHttpRequestRejection(req, res, err.statusCode, JSON.stringify({ error: requestBodyErrorToText(err.code) }), "application/json");
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1736
1646
|
params.runtime.error?.(danger(`line webhook error: ${formatErrorMessage(err)}`));
|
|
1737
|
-
if (!res.headersSent)
|
|
1647
|
+
if (!res.headersSent) sendJsonWithoutCharset(res, 500, { error: "Internal server error" });
|
|
1738
1648
|
}
|
|
1739
1649
|
};
|
|
1740
1650
|
}
|
|
1741
|
-
|
|
1742
|
-
//#region extensions/line/src/webhook-utils.ts
|
|
1743
|
-
/** Route the gateway serves when an account configures no `webhookPath`. */
|
|
1744
|
-
const LINE_DEFAULT_WEBHOOK_PATH = "/line/webhook";
|
|
1745
|
-
/** The route this account's monitor serves, which is the one an operator has to register
|
|
1746
|
-
* with LINE. Every surface resolves it here so a warning cannot name a path the gateway
|
|
1747
|
-
* does not answer on. Route registration canonicalizes further, and matches requests the
|
|
1748
|
-
* same way, so a path resolved here always reaches the route the monitor registered. */
|
|
1749
|
-
function resolveLineWebhookPath(webhookPath) {
|
|
1750
|
-
return resolveWebhookPath({
|
|
1751
|
-
webhookPath,
|
|
1752
|
-
defaultPath: LINE_DEFAULT_WEBHOOK_PATH
|
|
1753
|
-
}) ?? LINE_DEFAULT_WEBHOOK_PATH;
|
|
1754
|
-
}
|
|
1755
|
-
//#endregion
|
|
1756
|
-
//#region extensions/line/src/monitor.ts
|
|
1651
|
+
// extensions/line/src/monitor.ts
|
|
1757
1652
|
const lineWebhookInFlightLimiter = createWebhookInFlightLimiter();
|
|
1758
1653
|
const lineWebhookTargets = /* @__PURE__ */ new Map();
|
|
1759
1654
|
async function monitorLineProvider(opts) {
|
|
@@ -1775,14 +1670,12 @@ async function monitorLineProvider(opts) {
|
|
|
1775
1670
|
const replyPipeline = userId ? { typing: {
|
|
1776
1671
|
start: () => showLoadingAnimation(userId, {
|
|
1777
1672
|
cfg: turnConfig,
|
|
1778
|
-
accountId: ctx.accountId
|
|
1779
|
-
loadingSeconds: 20
|
|
1673
|
+
accountId: ctx.accountId
|
|
1780
1674
|
}),
|
|
1781
1675
|
keepaliveIntervalMs: 18e3,
|
|
1782
1676
|
maxDurationMs: 0,
|
|
1783
1677
|
onStartError: () => {}
|
|
1784
1678
|
} } : {};
|
|
1785
|
-
logVerbose(`line: received message from ${ctxPayload.SenderName ?? ctx.userId ?? ctxPayload.From} (${ctxPayload.From})`);
|
|
1786
1679
|
let replyTokenUsed = false;
|
|
1787
1680
|
let turnAdopted = false;
|
|
1788
1681
|
const ingressLifecycle = deliveryControl.turnAdoptionLifecycle;
|
|
@@ -1832,13 +1725,15 @@ async function monitorLineProvider(opts) {
|
|
|
1832
1725
|
...replyOptions ? { replyOptions } : {},
|
|
1833
1726
|
delivery: {
|
|
1834
1727
|
preparePayload: (payload) => prepareLineReplyPayload(payload, ctxPayload.From),
|
|
1835
|
-
durable: (payload, info) =>
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1728
|
+
durable: (payload, info) => {
|
|
1729
|
+
if (info.kind !== "final") return false;
|
|
1730
|
+
if (replyToken && !replyTokenUsed) return false;
|
|
1731
|
+
const lineData = payload.channelData?.line;
|
|
1732
|
+
if (lineData && Object.keys(lineData).length > 0) return false;
|
|
1733
|
+
const reply = resolveSendableOutboundReplyParts(payload);
|
|
1734
|
+
if (reply.hasMedia || !reply.hasText) return false;
|
|
1735
|
+
return { to: ctxPayload.From };
|
|
1736
|
+
},
|
|
1842
1737
|
deliver: async (payload) => {
|
|
1843
1738
|
const deliveryResult = await deliverLineAutoReply({
|
|
1844
1739
|
payload,
|
|
@@ -1873,7 +1768,11 @@ async function monitorLineProvider(opts) {
|
|
|
1873
1768
|
}
|
|
1874
1769
|
}
|
|
1875
1770
|
});
|
|
1876
|
-
const
|
|
1771
|
+
const defaultPath = "/line/webhook";
|
|
1772
|
+
const normalizedPath = resolveWebhookPath({
|
|
1773
|
+
webhookPath,
|
|
1774
|
+
defaultPath
|
|
1775
|
+
}) ?? defaultPath;
|
|
1877
1776
|
const webhookRouteKey = canonicalizeWebhookRouteKey(normalizedPath);
|
|
1878
1777
|
const handleWebhook = createLineNodeWebhookHandler({
|
|
1879
1778
|
getTargets: () => lineWebhookTargets.get(webhookRouteKey) ?? [],
|
|
@@ -1949,5 +1848,4 @@ async function monitorLineProvider(opts) {
|
|
|
1949
1848
|
}
|
|
1950
1849
|
};
|
|
1951
1850
|
}
|
|
1952
|
-
|
|
1953
|
-
export { monitorLineProvider as t };
|
|
1851
|
+
export { monitorLineProvider };
|