@elizaos/plugin-line 2.0.0-beta.1 → 2.0.3-beta.3

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 (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -3
  3. package/package.json +23 -6
  4. package/registry-entry.json +86 -0
  5. package/dist/accounts.d.ts +0 -152
  6. package/dist/accounts.d.ts.map +0 -1
  7. package/dist/accounts.js +0 -258
  8. package/dist/accounts.js.map +0 -1
  9. package/dist/actions/index.d.ts +0 -1
  10. package/dist/actions/index.d.ts.map +0 -1
  11. package/dist/actions/index.js +0 -3
  12. package/dist/actions/index.js.map +0 -1
  13. package/dist/connector-account-provider.d.ts +0 -16
  14. package/dist/connector-account-provider.d.ts.map +0 -1
  15. package/dist/connector-account-provider.js +0 -82
  16. package/dist/connector-account-provider.js.map +0 -1
  17. package/dist/index.d.ts +0 -18
  18. package/dist/index.d.ts.map +0 -1
  19. package/dist/index.js +0 -60
  20. package/dist/index.js.map +0 -1
  21. package/dist/messaging.d.ts +0 -142
  22. package/dist/messaging.d.ts.map +0 -1
  23. package/dist/messaging.js +0 -357
  24. package/dist/messaging.js.map +0 -1
  25. package/dist/providers/index.d.ts +0 -7
  26. package/dist/providers/index.d.ts.map +0 -1
  27. package/dist/providers/index.js +0 -8
  28. package/dist/providers/index.js.map +0 -1
  29. package/dist/service.d.ts +0 -110
  30. package/dist/service.d.ts.map +0 -1
  31. package/dist/service.js +0 -766
  32. package/dist/service.js.map +0 -1
  33. package/dist/types.d.ts +0 -279
  34. package/dist/types.d.ts.map +0 -1
  35. package/dist/types.js +0 -106
  36. package/dist/types.js.map +0 -1
  37. package/dist/workflow-credential-provider.d.ts +0 -21
  38. package/dist/workflow-credential-provider.d.ts.map +0 -1
  39. package/dist/workflow-credential-provider.js +0 -32
  40. package/dist/workflow-credential-provider.js.map +0 -1
@@ -1,82 +0,0 @@
1
- /**
2
- * LINE ConnectorAccountManager provider.
3
- *
4
- * Adapts the existing multi-account scaffolding in `accounts.ts` to the
5
- * `ConnectorAccountProvider` contract from
6
- * `@elizaos/core/connectors/account-manager`.
7
- *
8
- * Source of truth for accounts is character settings (`character.settings.line`)
9
- * plus env-var fallbacks (LINE_CHANNEL_ACCESS_TOKEN, LINE_CHANNEL_SECRET).
10
- * `listAccounts` enumerates all configured/enabled accounts; single-account
11
- * env-only deployments still surface as a `default` account.
12
- */
13
- import { DEFAULT_ACCOUNT_ID, listEnabledLineAccounts, normalizeAccountId, resolveLineAccount, } from "./accounts.js";
14
- export const LINE_PROVIDER_ID = "line";
15
- function purposeForAccount(_account) {
16
- return ["messaging"];
17
- }
18
- function accessGateForAccount(account) {
19
- const dmPolicy = account.config?.dmPolicy;
20
- if (dmPolicy === "pairing")
21
- return "pairing";
22
- if (dmPolicy === "disabled")
23
- return "disabled";
24
- return "open";
25
- }
26
- function roleForAccount(_account) {
27
- // LINE channel access tokens are bot tokens, not user-OAuth.
28
- return "AGENT";
29
- }
30
- function toConnectorAccount(account) {
31
- const now = Date.now();
32
- return {
33
- id: normalizeAccountId(account.accountId),
34
- provider: LINE_PROVIDER_ID,
35
- label: account.name ?? account.accountId,
36
- role: roleForAccount(account),
37
- purpose: purposeForAccount(account),
38
- accessGate: accessGateForAccount(account),
39
- status: account.enabled && account.configured ? "connected" : "disabled",
40
- createdAt: now,
41
- updatedAt: now,
42
- metadata: {
43
- tokenSource: account.tokenSource,
44
- dmPolicy: account.config?.dmPolicy ?? "open",
45
- groupPolicy: account.config?.groupPolicy ?? "allowlist",
46
- },
47
- };
48
- }
49
- export function createLineConnectorAccountProvider(runtime) {
50
- return {
51
- provider: LINE_PROVIDER_ID,
52
- label: "LINE",
53
- listAccounts: async (_manager) => {
54
- const enabled = listEnabledLineAccounts(runtime);
55
- if (enabled.length > 0) {
56
- return enabled.map(toConnectorAccount);
57
- }
58
- // Fall back to default account so single-account env-only deployments
59
- // still surface in the manager. Status reflects token configuration.
60
- const fallback = resolveLineAccount(runtime, DEFAULT_ACCOUNT_ID);
61
- return [toConnectorAccount(fallback)];
62
- },
63
- createAccount: async (input, _manager) => {
64
- return {
65
- ...input,
66
- provider: LINE_PROVIDER_ID,
67
- role: input.role ?? "AGENT",
68
- purpose: input.purpose ?? ["messaging"],
69
- accessGate: input.accessGate ?? "open",
70
- status: input.status ?? "pending",
71
- };
72
- },
73
- patchAccount: async (_accountId, patch, _manager) => {
74
- return { ...patch, provider: LINE_PROVIDER_ID };
75
- },
76
- deleteAccount: async (_accountId, _manager) => {
77
- // No-op at provider layer — runtime credentials live in character
78
- // settings; deletion of those is out of band.
79
- },
80
- };
81
- }
82
- //# sourceMappingURL=connector-account-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connector-account-provider.js","sourceRoot":"","sources":["../src/connector-account-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AASH,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAElB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AAEvB,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEvC,SAAS,iBAAiB,CAAC,QAA6B;IACtD,OAAO,CAAC,WAAW,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,oBAAoB,CAAC,OAA4B;IACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1C,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC7C,IAAI,QAAQ,KAAK,UAAU;QAAE,OAAO,UAAU,CAAC;IAC/C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,cAAc,CAAC,QAA6B;IACnD,6DAA6D;IAC7D,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,kBAAkB,CAAC,OAA4B;IACtD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,OAAO;QACL,EAAE,EAAE,kBAAkB,CAAC,OAAO,CA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I,EAAE,KAAK,CAAC,IAAI,IAAI,OAAO;gBAC3B,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,CAAC,WAAW,CAAC;gBACvC,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,MAAM;gBACtC,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,SAAS;aAClC,CAAC;QACJ,CAAC;QACD,YAAY,EAAE,KAAK,EACjB,UAAkB,EAClB,KAA4B,EAC5B,QAAiC,EACjC,EAAE;YACF,OAAO,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC;QAClD,CAAC;QACD,aAAa,EAAE,KAAK,EAAE,UAAkB,EAAE,QAAiC,EAAE,EAAE;YAC7E,kEAAkE;YAClE,8CAA8C;QAChD,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/index.d.ts DELETED
@@ -1,18 +0,0 @@
1
- /**
2
- * LINE Plugin for ElizaOS
3
- *
4
- * Provides LINE Messaging API integration for ElizaOS agents,
5
- * supporting text, flex messages, locations, and more.
6
- */
7
- import type { Plugin } from "@elizaos/core";
8
- import { LineService } from "./service.js";
9
- export { DEFAULT_ACCOUNT_ID, isLineMentionRequired, isLineUserAllowed, isMultiAccountEnabled, type LineAccountConfig, type LineGroupConfig, type LineMultiAccountConfig, type LineTokenResolution, type LineTokenSource, listEnabledLineAccounts, listLineAccountIds, normalizeAccountId, type ResolvedLineAccount, resolveDefaultLineAccountId, resolveLineAccount, resolveLineGroupConfig, resolveLineSecret, resolveLineToken, } from "./accounts.js";
10
- export { buildLineDeepLink, type ChunkLineTextOpts, type CodeBlock, chunkLineText, extractCodeBlocks, extractLinks, extractMarkdownTables, formatCodeBlockAsText, formatLineUser, formatTableAsText, getChatId, getChatType, hasMarkdownContent, isGroupChat, LINE_MAX_REPLY_MESSAGES, LINE_TEXT_CHUNK_LIMIT, type MarkdownLink, type MarkdownTable, markdownToLineChunks, type ProcessedLineMessage, processLineMessage, resolveLineSystemLocation, stripMarkdown, truncateText, } from "./messaging.js";
11
- export * from "./types.js";
12
- export { LineService };
13
- /**
14
- * LINE plugin for ElizaOS agents.
15
- */
16
- declare const linePlugin: Plugin;
17
- export default linePlugin;
18
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AAG3D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAI3C,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAClB,KAAK,mBAAmB,EACxB,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,uBAAuB,EACvB,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,oBAAoB,EACpB,KAAK,oBAAoB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,aAAa,EACb,YAAY,GACb,MAAM,gBAAgB,CAAC;AAExB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;GAEG;AACH,QAAA,MAAM,UAAU,EAAE,MAqDjB,CAAC;AAEF,eAAe,UAAU,CAAC"}
package/dist/index.js DELETED
@@ -1,60 +0,0 @@
1
- /**
2
- * LINE Plugin for ElizaOS
3
- *
4
- * Provides LINE Messaging API integration for ElizaOS agents,
5
- * supporting text, flex messages, locations, and more.
6
- */
7
- import { getConnectorAccountManager, logger } from "@elizaos/core";
8
- import { createLineConnectorAccountProvider } from "./connector-account-provider.js";
9
- import { LineService } from "./service.js";
10
- import { LineWorkflowCredentialProvider } from "./workflow-credential-provider.js";
11
- // Account management exports
12
- export { DEFAULT_ACCOUNT_ID, isLineMentionRequired, isLineUserAllowed, isMultiAccountEnabled, listEnabledLineAccounts, listLineAccountIds, normalizeAccountId, resolveDefaultLineAccountId, resolveLineAccount, resolveLineGroupConfig, resolveLineSecret, resolveLineToken, } from "./accounts.js";
13
- // Messaging utilities exports
14
- export { buildLineDeepLink, chunkLineText, extractCodeBlocks, extractLinks, extractMarkdownTables, formatCodeBlockAsText, formatLineUser, formatTableAsText, getChatId, getChatType, hasMarkdownContent, isGroupChat, LINE_MAX_REPLY_MESSAGES, LINE_TEXT_CHUNK_LIMIT, markdownToLineChunks, processLineMessage, resolveLineSystemLocation, stripMarkdown, truncateText, } from "./messaging.js";
15
- // Re-export types and service
16
- export * from "./types.js";
17
- export { LineService };
18
- /**
19
- * LINE plugin for ElizaOS agents.
20
- */
21
- const linePlugin = {
22
- name: "line",
23
- description: "LINE Messaging API plugin for ElizaOS agents",
24
- services: [LineService, LineWorkflowCredentialProvider],
25
- actions: [],
26
- providers: [],
27
- tests: [],
28
- init: async (config, runtime) => {
29
- logger.info("Initializing LINE plugin...");
30
- // Register the LINE provider with the ConnectorAccountManager so the HTTP
31
- // CRUD surface (packages/agent/src/api/connector-account-routes.ts) can
32
- // list, create, patch, and delete LINE accounts.
33
- try {
34
- const manager = getConnectorAccountManager(runtime);
35
- manager.registerProvider(createLineConnectorAccountProvider(runtime));
36
- }
37
- catch (err) {
38
- logger.warn({
39
- src: "plugin:line",
40
- err: err instanceof Error ? err.message : String(err),
41
- }, "Failed to register LINE provider with ConnectorAccountManager");
42
- }
43
- const hasAccessToken = Boolean(config.LINE_CHANNEL_ACCESS_TOKEN || process.env.LINE_CHANNEL_ACCESS_TOKEN);
44
- const hasSecret = Boolean(config.LINE_CHANNEL_SECRET || process.env.LINE_CHANNEL_SECRET);
45
- logger.info("LINE plugin configuration:");
46
- logger.info(` - Access token configured: ${hasAccessToken ? "Yes" : "No"}`);
47
- logger.info(` - Channel secret configured: ${hasSecret ? "Yes" : "No"}`);
48
- logger.info(` - DM policy: ${config.LINE_DM_POLICY || process.env.LINE_DM_POLICY || "pairing"}`);
49
- logger.info(` - Group policy: ${config.LINE_GROUP_POLICY || process.env.LINE_GROUP_POLICY || "allowlist"}`);
50
- if (!hasAccessToken) {
51
- logger.warn("LINE channel access token not configured. Set LINE_CHANNEL_ACCESS_TOKEN.");
52
- }
53
- if (!hasSecret) {
54
- logger.warn("LINE channel secret not configured. Set LINE_CHANNEL_SECRET.");
55
- }
56
- logger.info("LINE plugin initialized");
57
- },
58
- };
59
- export default linePlugin;
60
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,0BAA0B,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,kCAAkC,EAAE,MAAM,iCAAiC,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AAEnF,6BAA6B;AAC7B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EAMrB,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAElB,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,8BAA8B;AAC9B,OAAO,EACL,iBAAiB,EA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G,OAAO,CAAC,MAAM,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAEzF,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,gCAAgC,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7E,MAAM,CAAC,IAAI,CAAC,kCAAkC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1E,MAAM,CAAC,IAAI,CACT,kBAAkB,MAAM,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,SAAS,EAAE,CACrF,CAAC;QACF,MAAM,CAAC,IAAI,CACT,qBAAqB,MAAM,CAAC,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,WAAW,EAAE,CAChG,CAAC;QAEF,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,0EAA0E,CAAC,CAAC;QAC1F,CAAC;QAED,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAC;QAC9E,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACzC,CAAC;CACF,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -1,142 +0,0 @@
1
- /**
2
- * LINE text chunk limit (API supports 5000 characters per message)
3
- */
4
- export declare const LINE_TEXT_CHUNK_LIMIT = 5000;
5
- /**
6
- * LINE max messages per reply (API supports up to 5 messages in a reply)
7
- */
8
- export declare const LINE_MAX_REPLY_MESSAGES = 5;
9
- /**
10
- * Represents a markdown table extracted from text
11
- */
12
- export interface MarkdownTable {
13
- headers: string[];
14
- rows: string[][];
15
- }
16
- /**
17
- * Represents a code block extracted from text
18
- */
19
- export interface CodeBlock {
20
- language?: string;
21
- code: string;
22
- }
23
- /**
24
- * Represents a markdown link
25
- */
26
- export interface MarkdownLink {
27
- text: string;
28
- url: string;
29
- }
30
- /**
31
- * Result of processing text for LINE
32
- */
33
- export interface ProcessedLineMessage {
34
- text: string;
35
- tables: MarkdownTable[];
36
- codeBlocks: CodeBlock[];
37
- links: MarkdownLink[];
38
- }
39
- /**
40
- * Options for text chunking
41
- */
42
- export interface ChunkLineTextOpts {
43
- limit?: number;
44
- preserveCodeBlocks?: boolean;
45
- }
46
- /**
47
- * Extracts markdown tables from text
48
- */
49
- export declare function extractMarkdownTables(text: string): {
50
- tables: MarkdownTable[];
51
- textWithoutTables: string;
52
- };
53
- /**
54
- * Extracts code blocks from text
55
- */
56
- export declare function extractCodeBlocks(text: string): {
57
- codeBlocks: CodeBlock[];
58
- textWithoutCode: string;
59
- };
60
- /**
61
- * Extracts markdown links from text
62
- */
63
- export declare function extractLinks(text: string): {
64
- links: MarkdownLink[];
65
- textWithLinks: string;
66
- };
67
- /**
68
- * Strips markdown formatting from text
69
- */
70
- export declare function stripMarkdown(text: string): string;
71
- /**
72
- * Checks if text contains markdown that needs conversion
73
- */
74
- export declare function hasMarkdownContent(text: string): boolean;
75
- /**
76
- * Processes text for LINE output
77
- */
78
- export declare function processLineMessage(text: string): ProcessedLineMessage;
79
- /**
80
- * Chunks text for LINE messages
81
- */
82
- export declare function chunkLineText(text: string, opts?: ChunkLineTextOpts): string[];
83
- /**
84
- * Processes and chunks a markdown message for LINE
85
- */
86
- export declare function markdownToLineChunks(markdown: string, opts?: ChunkLineTextOpts): {
87
- textChunks: string[];
88
- tables: MarkdownTable[];
89
- codeBlocks: CodeBlock[];
90
- links: MarkdownLink[];
91
- };
92
- /**
93
- * Formats a table as plain text
94
- */
95
- export declare function formatTableAsText(table: MarkdownTable): string;
96
- /**
97
- * Formats a code block as plain text
98
- */
99
- export declare function formatCodeBlockAsText(block: CodeBlock): string;
100
- /**
101
- * Truncates text to a maximum length with ellipsis
102
- */
103
- export declare function truncateText(text: string, maxLength: number): string;
104
- /**
105
- * Formats a LINE user display name
106
- */
107
- export declare function formatLineUser(displayName: string, userId: string): string;
108
- /**
109
- * Builds a LINE deep link URL
110
- */
111
- export declare function buildLineDeepLink(_type: "user" | "group" | "room", id: string): string;
112
- /**
113
- * Resolves the system location string for logging
114
- */
115
- export declare function resolveLineSystemLocation(params: {
116
- chatType: "user" | "group" | "room";
117
- chatId: string;
118
- chatName?: string;
119
- }): string;
120
- /**
121
- * Checks if a chat is a group chat
122
- */
123
- export declare function isGroupChat(params: {
124
- groupId?: string;
125
- roomId?: string;
126
- }): boolean;
127
- /**
128
- * Gets the chat ID from context
129
- */
130
- export declare function getChatId(params: {
131
- userId: string;
132
- groupId?: string;
133
- roomId?: string;
134
- }): string;
135
- /**
136
- * Gets the chat type from context
137
- */
138
- export declare function getChatType(params: {
139
- groupId?: string;
140
- roomId?: string;
141
- }): "user" | "group" | "room";
142
- //# sourceMappingURL=messaging.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"messaging.d.ts","sourceRoot":"","sources":["../src/messaging.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,aAAa,EAAE,CAAC;I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characters per message)
3
- */
4
- export const LINE_TEXT_CHUNK_LIMIT = 5000;
5
- /**
6
- * LINE max messages per reply (API supports up to 5 messages in a reply)
7
- */
8
- export const LINE_MAX_REPLY_MESSAGES = 5;
9
- /**
10
- * Regex patterns for markdown detection
11
- */
12
- const MARKDOWN_TABLE_REGEX = /^\|(.+)\|[\r\n]+\|[-:\s|]+\|[\r\n]+((?:\|.+\|[\r\n]*)+)/gm;
13
- const MARKDOWN_CODE_BLOCK_REGEX = /```(\w*)\n([\s\S]*?)```/g;
14
- const MARKDOWN_LINK_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
15
- /**
16
- * Parses a single table row (pipe-separated values)
17
- */
18
- function parseTableRow(row) {
19
- return row
20
- .split("|")
21
- .map((cell) => cell.trim())
22
- .filter((cell, index, arr) => {
23
- // Filter out empty cells at start/end (from leading/trailing pipes)
24
- if (index === 0 && cell === "") {
25
- return false;
26
- }
27
- if (index === arr.length - 1 && cell === "") {
28
- return false;
29
- }
30
- return true;
31
- });
32
- }
33
- /**
34
- * Extracts markdown tables from text
35
- */
36
- export function extractMarkdownTables(text) {
37
- const tables = [];
38
- let textWithoutTables = text;
39
- // Reset regex state
40
- MARKDOWN_TABLE_REGEX.lastIndex = 0;
41
- let match;
42
- const matches = [];
43
- match = MARKDOWN_TABLE_REGEX.exec(text);
44
- while (match !== null) {
45
- const fullMatch = match[0];
46
- const headerLine = match[1];
47
- const bodyLines = match[2];
48
- const headers = parseTableRow(headerLine);
49
- const rows = bodyLines
50
- .trim()
51
- .split(/[\r\n]+/)
52
- .filter((line) => line.trim())
53
- .map(parseTableRow);
54
- if (headers.length > 0 && rows.length > 0) {
55
- matches.push({
56
- fullMatch,
57
- table: { headers, rows },
58
- });
59
- }
60
- match = MARKDOWN_TABLE_REGEX.exec(text);
61
- }
62
- // Remove tables from text in reverse order to preserve indices
63
- for (let i = matches.length - 1; i >= 0; i--) {
64
- const { fullMatch, table } = matches[i];
65
- tables.unshift(table);
66
- textWithoutTables = textWithoutTables.replace(fullMatch, "");
67
- }
68
- return { tables, textWithoutTables };
69
- }
70
- /**
71
- * Extracts code blocks from text
72
- */
73
- export function extractCodeBlocks(text) {
74
- const codeBlocks = [];
75
- let textWithoutCode = text;
76
- // Reset regex state
77
- MARKDOWN_CODE_BLOCK_REGEX.lastIndex = 0;
78
- let match;
79
- const matches = [];
80
- match = MARKDOWN_CODE_BLOCK_REGEX.exec(text);
81
- while (match !== null) {
82
- const fullMatch = match[0];
83
- const language = match[1] || undefined;
84
- const code = match[2];
85
- matches.push({
86
- fullMatch,
87
- block: { language, code: code.trim() },
88
- });
89
- match = MARKDOWN_CODE_BLOCK_REGEX.exec(text);
90
- }
91
- // Remove code blocks in reverse order
92
- for (let i = matches.length - 1; i >= 0; i--) {
93
- const { fullMatch, block } = matches[i];
94
- codeBlocks.unshift(block);
95
- textWithoutCode = textWithoutCode.replace(fullMatch, "");
96
- }
97
- return { codeBlocks, textWithoutCode };
98
- }
99
- /**
100
- * Extracts markdown links from text
101
- */
102
- export function extractLinks(text) {
103
- const links = [];
104
- // Reset regex state
105
- MARKDOWN_LINK_REGEX.lastIndex = 0;
106
- let match;
107
- match = MARKDOWN_LINK_REGEX.exec(text);
108
- while (match !== null) {
109
- links.push({
110
- text: match[1],
111
- url: match[2],
112
- });
113
- match = MARKDOWN_LINK_REGEX.exec(text);
114
- }
115
- // Replace markdown links with just the text (for plain text output)
116
- const textWithLinks = text.replace(MARKDOWN_LINK_REGEX, "$1");
117
- return { links, textWithLinks };
118
- }
119
- /**
120
- * Strips markdown formatting from text
121
- */
122
- export function stripMarkdown(text) {
123
- let result = text;
124
- // Remove bold: **text** or __text__
125
- result = result.replace(/\*\*(.+?)\*\*/g, "$1");
126
- result = result.replace(/__(.+?)__/g, "$1");
127
- // Remove italic: *text* or _text_ (but not already processed)
128
- result = result.replace(/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g, "$1");
129
- result = result.replace(/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g, "$1");
130
- // Remove strikethrough: ~~text~~
131
- result = result.replace(/~~(.+?)~~/g, "$1");
132
- // Remove headers: # Title, ## Title, etc.
133
- result = result.replace(/^#{1,6}\s+(.+)$/gm, "$1");
134
- // Remove blockquotes: > text
135
- result = result.replace(/^>\s?(.*)$/gm, "$1");
136
- // Remove horizontal rules: ---, ***, ___
137
- result = result.replace(/^[-*_]{3,}$/gm, "");
138
- // Remove inline code: `code`
139
- result = result.replace(/`([^`]+)`/g, "$1");
140
- // Clean up extra whitespace
141
- result = result.replace(/\n{3,}/g, "\n\n");
142
- result = result.trim();
143
- return result;
144
- }
145
- /**
146
- * Checks if text contains markdown that needs conversion
147
- */
148
- export function hasMarkdownContent(text) {
149
- // Check for tables
150
- MARKDOWN_TABLE_REGEX.lastIndex = 0;
151
- if (MARKDOWN_TABLE_REGEX.test(text)) {
152
- return true;
153
- }
154
- // Check for code blocks
155
- MARKDOWN_CODE_BLOCK_REGEX.lastIndex = 0;
156
- if (MARKDOWN_CODE_BLOCK_REGEX.test(text)) {
157
- return true;
158
- }
159
- // Check for other markdown patterns
160
- if (/\*\*[^*]+\*\*/.test(text)) {
161
- return true;
162
- }
163
- if (/~~[^~]+~~/.test(text)) {
164
- return true;
165
- }
166
- if (/^#{1,6}\s+/m.test(text)) {
167
- return true;
168
- }
169
- if (/^>\s+/m.test(text)) {
170
- return true;
171
- }
172
- return false;
173
- }
174
- /**
175
- * Processes text for LINE output
176
- */
177
- export function processLineMessage(text) {
178
- let processedText = text;
179
- // Extract tables
180
- const { tables, textWithoutTables } = extractMarkdownTables(processedText);
181
- processedText = textWithoutTables;
182
- // Extract code blocks
183
- const { codeBlocks, textWithoutCode } = extractCodeBlocks(processedText);
184
- processedText = textWithoutCode;
185
- // Handle links
186
- const { links, textWithLinks } = extractLinks(processedText);
187
- processedText = textWithLinks;
188
- // Strip remaining markdown formatting
189
- processedText = stripMarkdown(processedText);
190
- return {
191
- text: processedText,
192
- tables,
193
- codeBlocks,
194
- links,
195
- };
196
- }
197
- /**
198
- * Splits text at the last safe break point within the limit
199
- */
200
- function splitAtBreakPoint(text, limit) {
201
- if (text.length <= limit) {
202
- return { chunk: text, remainder: "" };
203
- }
204
- // Try to find a natural break point
205
- const searchArea = text.slice(0, limit);
206
- // Prefer double newlines (paragraph breaks)
207
- const doubleNewline = searchArea.lastIndexOf("\n\n");
208
- if (doubleNewline > limit * 0.5) {
209
- return {
210
- chunk: text.slice(0, doubleNewline).trimEnd(),
211
- remainder: text.slice(doubleNewline + 2).trimStart(),
212
- };
213
- }
214
- // Try single newlines
215
- const singleNewline = searchArea.lastIndexOf("\n");
216
- if (singleNewline > limit * 0.5) {
217
- return {
218
- chunk: text.slice(0, singleNewline).trimEnd(),
219
- remainder: text.slice(singleNewline + 1).trimStart(),
220
- };
221
- }
222
- // Try sentence boundaries
223
- const sentenceEnd = Math.max(searchArea.lastIndexOf(". "), searchArea.lastIndexOf("! "), searchArea.lastIndexOf("? "));
224
- if (sentenceEnd > limit * 0.5) {
225
- return {
226
- chunk: text.slice(0, sentenceEnd + 1).trimEnd(),
227
- remainder: text.slice(sentenceEnd + 2).trimStart(),
228
- };
229
- }
230
- // Try word boundaries
231
- const space = searchArea.lastIndexOf(" ");
232
- if (space > limit * 0.5) {
233
- return {
234
- chunk: text.slice(0, space).trimEnd(),
235
- remainder: text.slice(space + 1).trimStart(),
236
- };
237
- }
238
- // Hard break at limit
239
- return {
240
- chunk: text.slice(0, limit),
241
- remainder: text.slice(limit),
242
- };
243
- }
244
- /**
245
- * Chunks text for LINE messages
246
- */
247
- export function chunkLineText(text, opts = {}) {
248
- const limit = opts.limit ?? LINE_TEXT_CHUNK_LIMIT;
249
- if (!text?.trim()) {
250
- return [];
251
- }
252
- const normalizedText = text.trim();
253
- if (normalizedText.length <= limit) {
254
- return [normalizedText];
255
- }
256
- const chunks = [];
257
- let remaining = normalizedText;
258
- while (remaining.length > 0) {
259
- const { chunk, remainder } = splitAtBreakPoint(remaining, limit);
260
- if (chunk) {
261
- chunks.push(chunk);
262
- }
263
- remaining = remainder;
264
- }
265
- return chunks.filter((c) => c.length > 0);
266
- }
267
- /**
268
- * Processes and chunks a markdown message for LINE
269
- */
270
- export function markdownToLineChunks(markdown, opts = {}) {
271
- const processed = processLineMessage(markdown);
272
- const textChunks = chunkLineText(processed.text, opts);
273
- return {
274
- textChunks,
275
- tables: processed.tables,
276
- codeBlocks: processed.codeBlocks,
277
- links: processed.links,
278
- };
279
- }
280
- /**
281
- * Formats a table as plain text
282
- */
283
- export function formatTableAsText(table) {
284
- const lines = [];
285
- // Header
286
- lines.push(table.headers.join(" | "));
287
- lines.push("-".repeat(lines[0].length));
288
- // Rows
289
- for (const row of table.rows) {
290
- lines.push(row.join(" | "));
291
- }
292
- return lines.join("\n");
293
- }
294
- /**
295
- * Formats a code block as plain text
296
- */
297
- export function formatCodeBlockAsText(block) {
298
- const langLabel = block.language ? `[${block.language}]` : "[code]";
299
- return `${langLabel}\n${block.code}`;
300
- }
301
- /**
302
- * Truncates text to a maximum length with ellipsis
303
- */
304
- export function truncateText(text, maxLength) {
305
- if (text.length <= maxLength) {
306
- return text;
307
- }
308
- if (maxLength <= 3) {
309
- return "...".slice(0, maxLength);
310
- }
311
- return `${text.slice(0, maxLength - 3)}...`;
312
- }
313
- /**
314
- * Formats a LINE user display name
315
- */
316
- export function formatLineUser(displayName, userId) {
317
- return displayName || `User(${userId.slice(0, 8)}...)`;
318
- }
319
- /**
320
- * Builds a LINE deep link URL
321
- */
322
- export function buildLineDeepLink(_type, id) {
323
- return `line://ti/p/${id}`;
324
- }
325
- /**
326
- * Resolves the system location string for logging
327
- */
328
- export function resolveLineSystemLocation(params) {
329
- const { chatType, chatId, chatName } = params;
330
- const name = chatName || chatId.slice(0, 8);
331
- return `LINE ${chatType}:${name}`;
332
- }
333
- /**
334
- * Checks if a chat is a group chat
335
- */
336
- export function isGroupChat(params) {
337
- return Boolean(params.groupId || params.roomId);
338
- }
339
- /**
340
- * Gets the chat ID from context
341
- */
342
- export function getChatId(params) {
343
- return params.groupId || params.roomId || params.userId;
344
- }
345
- /**
346
- * Gets the chat type from context
347
- */
348
- export function getChatType(params) {
349
- if (params.groupId) {
350
- return "group";
351
- }
352
- if (params.roomId) {
353
- return "room";
354
- }
355
- return "user";
356
- }
357
- //# sourceMappingURL=messaging.js.map