@elizaos/plugin-line 2.0.3-beta.6 → 2.0.3-beta.7
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/accounts.d.ts +152 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +258 -0
- package/dist/accounts.js.map +1 -0
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +3 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/connector-account-provider.d.ts +16 -0
- package/dist/connector-account-provider.d.ts.map +1 -0
- package/dist/connector-account-provider.js +82 -0
- package/dist/connector-account-provider.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/messaging.d.ts +142 -0
- package/dist/messaging.d.ts.map +1 -0
- package/dist/messaging.js +357 -0
- package/dist/messaging.js.map +1 -0
- package/dist/providers/index.d.ts +7 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +8 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/service.d.ts +110 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +861 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +279 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +106 -0
- package/dist/types.js.map +1 -0
- package/dist/workflow-credential-provider.d.ts +21 -0
- package/dist/workflow-credential-provider.d.ts.map +1 -0
- package/dist/workflow-credential-provider.js +38 -0
- package/dist/workflow-credential-provider.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,142 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,EAA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CACjB,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAQ5B"}
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LINE text chunk limit (API supports 5000 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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messaging.js","sourceRoot":"","sources":["../src/messaging.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAE1C;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AA4CzC;;GAEG;AACH,MAAM,oBAAoB,GAAG,2DAA2D,CAAC;AACzF,MAAM,yBAAyB,GAAG,0BAA0B,CAAC;AAC7D,MAAM,mBAAmB,GA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C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,MAA6C;IACvE,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAA6D;IACrF,OAAO,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,MAG3B;IACC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LINE service implementation for ElizaOS.
|
|
3
|
+
*/
|
|
4
|
+
import type { Content, IAgentRuntime } from "@elizaos/core";
|
|
5
|
+
import { Service } from "@elizaos/core";
|
|
6
|
+
import { type MiddlewareConfig, middleware, type webhook } from "@line/bot-sdk";
|
|
7
|
+
type WebhookEvent = webhook.Event;
|
|
8
|
+
import { type ILineService, type LineFlexMessage, type LineGroup, type LineLocationMessage, type LineMessageSendOptions, type LineSendResult, type LineSettings, type LineTemplateMessage, type LineUser } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* LINE messaging service for ElizaOS agents.
|
|
11
|
+
*/
|
|
12
|
+
export declare class LineService extends Service implements ILineService {
|
|
13
|
+
static serviceType: string;
|
|
14
|
+
capabilityDescription: string;
|
|
15
|
+
private settings;
|
|
16
|
+
private client;
|
|
17
|
+
private connected;
|
|
18
|
+
constructor(runtime?: IAgentRuntime);
|
|
19
|
+
/**
|
|
20
|
+
* Start the LINE service.
|
|
21
|
+
*/
|
|
22
|
+
static start(runtime: IAgentRuntime): Promise<Service>;
|
|
23
|
+
static registerSendHandlers(runtime: IAgentRuntime, service: LineService): void;
|
|
24
|
+
/**
|
|
25
|
+
* Initialize the service.
|
|
26
|
+
*/
|
|
27
|
+
private initialize;
|
|
28
|
+
/**
|
|
29
|
+
* Stop the LINE service.
|
|
30
|
+
*/
|
|
31
|
+
stop(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Check if the service is connected.
|
|
34
|
+
*/
|
|
35
|
+
isConnected(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Get bot info.
|
|
38
|
+
*/
|
|
39
|
+
getBotInfo(): Promise<LineUser | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Send a text message.
|
|
42
|
+
*/
|
|
43
|
+
sendMessage(to: string, text: string, options?: LineMessageSendOptions): Promise<LineSendResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Send multiple messages.
|
|
46
|
+
*/
|
|
47
|
+
sendMessages(to: string, messages: Array<{
|
|
48
|
+
type: string;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}>): Promise<LineSendResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Send a flex message.
|
|
53
|
+
*/
|
|
54
|
+
sendFlexMessage(to: string, flex: LineFlexMessage): Promise<LineSendResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Send a template message.
|
|
57
|
+
*/
|
|
58
|
+
sendTemplateMessage(to: string, template: LineTemplateMessage): Promise<LineSendResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Send a location message.
|
|
61
|
+
*/
|
|
62
|
+
sendLocationMessage(to: string, location: LineLocationMessage): Promise<LineSendResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Reply to a message using reply token.
|
|
65
|
+
*/
|
|
66
|
+
replyMessage(replyToken: string, messages: Array<{
|
|
67
|
+
type: string;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
}>): Promise<LineSendResult>;
|
|
70
|
+
/**
|
|
71
|
+
* Get user profile.
|
|
72
|
+
*/
|
|
73
|
+
getUserProfile(userId: string): Promise<LineUser | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Get group info.
|
|
76
|
+
*/
|
|
77
|
+
getGroupInfo(groupId: string): Promise<LineGroup | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Leave a group or room.
|
|
80
|
+
*/
|
|
81
|
+
leaveChat(chatId: string, chatType: "group" | "room"): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Get the middleware config for webhook verification.
|
|
84
|
+
*/
|
|
85
|
+
getMiddlewareConfig(): MiddlewareConfig;
|
|
86
|
+
/**
|
|
87
|
+
* Create Express middleware for webhook handling.
|
|
88
|
+
*/
|
|
89
|
+
createMiddleware(): ReturnType<typeof middleware>;
|
|
90
|
+
/**
|
|
91
|
+
* Handle webhook events.
|
|
92
|
+
*/
|
|
93
|
+
handleWebhookEvents(events: WebhookEvent[]): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Get current settings.
|
|
96
|
+
*/
|
|
97
|
+
getSettings(): LineSettings | null;
|
|
98
|
+
sendDirectMessage(target: string, content: Content): Promise<void>;
|
|
99
|
+
sendRoomMessage(target: string, content: Content): Promise<void>;
|
|
100
|
+
private handleSendMessage;
|
|
101
|
+
private sendConnectorContent;
|
|
102
|
+
private listConnectorRooms;
|
|
103
|
+
private loadSettings;
|
|
104
|
+
private validateSettings;
|
|
105
|
+
private pushMessages;
|
|
106
|
+
private handleWebhookEvent;
|
|
107
|
+
private handleMessageEvent;
|
|
108
|
+
}
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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