@agentdomain/eliza-plugin 0.6.0 → 0.7.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/NOTICE +5 -0
- package/README.md +10 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +248 -319
- package/dist/text-parsing.d.ts +14 -0
- package/dist/text-parsing.js +226 -0
- package/package.json +7 -4
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CompactQuantity {
|
|
2
|
+
value: number;
|
|
3
|
+
suffix: 'k' | 'm';
|
|
4
|
+
}
|
|
5
|
+
export declare function readLabeledRemainder(text: string, labels: readonly string[], options?: {
|
|
6
|
+
requireSeparator?: boolean;
|
|
7
|
+
stopCharacter?: string;
|
|
8
|
+
stopLabels?: readonly string[];
|
|
9
|
+
}): string | undefined;
|
|
10
|
+
export declare function readLabeledEmailUsername(text: string, labels: readonly string[]): string | undefined;
|
|
11
|
+
export declare function extractEmailAddresses(text: string): string[];
|
|
12
|
+
export declare function readLabeledEmail(text: string, labels: readonly string[]): string | undefined;
|
|
13
|
+
export declare function extractFencedBlock(text: string, optionalLanguages: readonly string[]): string | undefined;
|
|
14
|
+
export declare function parseCompactQuantity(text: string): CompactQuantity | undefined;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
function isAsciiWhitespace(character) {
|
|
2
|
+
return character === ' ' || character === '\t' || character === '\r' || character === '\n';
|
|
3
|
+
}
|
|
4
|
+
function isAsciiDigit(character) {
|
|
5
|
+
return character !== undefined && character >= '0' && character <= '9';
|
|
6
|
+
}
|
|
7
|
+
function isAsciiLetter(character) {
|
|
8
|
+
return (character !== undefined &&
|
|
9
|
+
((character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z')));
|
|
10
|
+
}
|
|
11
|
+
function isAsciiAlphanumeric(character) {
|
|
12
|
+
return isAsciiDigit(character) || isAsciiLetter(character);
|
|
13
|
+
}
|
|
14
|
+
function isWordCharacter(character) {
|
|
15
|
+
return isAsciiAlphanumeric(character) || character === '_';
|
|
16
|
+
}
|
|
17
|
+
function isEmailLocalCharacter(character) {
|
|
18
|
+
return (isAsciiAlphanumeric(character) ||
|
|
19
|
+
character === '.' ||
|
|
20
|
+
character === '_' ||
|
|
21
|
+
character === '%' ||
|
|
22
|
+
character === '+' ||
|
|
23
|
+
character === '-');
|
|
24
|
+
}
|
|
25
|
+
function isEmailDomainCharacter(character) {
|
|
26
|
+
return isAsciiAlphanumeric(character) || character === '.' || character === '-';
|
|
27
|
+
}
|
|
28
|
+
function skipWhitespace(text, start) {
|
|
29
|
+
let cursor = start;
|
|
30
|
+
while (cursor < text.length && isAsciiWhitespace(text[cursor]))
|
|
31
|
+
cursor += 1;
|
|
32
|
+
return cursor;
|
|
33
|
+
}
|
|
34
|
+
function asciiCharactersEqual(left, right) {
|
|
35
|
+
if (left === right)
|
|
36
|
+
return true;
|
|
37
|
+
if (left === undefined || !isAsciiLetter(left) || !isAsciiLetter(right))
|
|
38
|
+
return false;
|
|
39
|
+
return (left.charCodeAt(0) | 32) === (right.charCodeAt(0) | 32);
|
|
40
|
+
}
|
|
41
|
+
function matchesAsciiCaseInsensitive(text, pattern, start) {
|
|
42
|
+
if (start + pattern.length > text.length)
|
|
43
|
+
return false;
|
|
44
|
+
for (let offset = 0; offset < pattern.length; offset += 1) {
|
|
45
|
+
if (!asciiCharactersEqual(text[start + offset], pattern[offset]))
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
function findLabeledValue(text, labels, requireSeparator, fromIndex = 0, requireWhitespaceBefore = false) {
|
|
51
|
+
let best = null;
|
|
52
|
+
for (const label of labels) {
|
|
53
|
+
let searchFrom = fromIndex;
|
|
54
|
+
while (searchFrom + label.length <= text.length) {
|
|
55
|
+
if (!matchesAsciiCaseInsensitive(text, label, searchFrom)) {
|
|
56
|
+
searchFrom += 1;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const labelStart = searchFrom;
|
|
60
|
+
const labelEnd = labelStart + label.length;
|
|
61
|
+
const hasStartBoundary = labelStart === 0 || !isWordCharacter(text[labelStart - 1]);
|
|
62
|
+
const hasEndBoundary = labelEnd === text.length || !isWordCharacter(text[labelEnd]);
|
|
63
|
+
const hasRequiredWhitespace = !requireWhitespaceBefore ||
|
|
64
|
+
labelStart === fromIndex ||
|
|
65
|
+
isAsciiWhitespace(text[labelStart - 1]);
|
|
66
|
+
if (hasStartBoundary && hasEndBoundary && hasRequiredWhitespace) {
|
|
67
|
+
let valueStart = skipWhitespace(text, labelEnd);
|
|
68
|
+
const hasSeparator = text[valueStart] === ':' || text[valueStart] === '=';
|
|
69
|
+
if (hasSeparator)
|
|
70
|
+
valueStart = skipWhitespace(text, valueStart + 1);
|
|
71
|
+
if (!requireSeparator || hasSeparator) {
|
|
72
|
+
if (best === null || labelStart < best.labelStart)
|
|
73
|
+
best = { labelStart, valueStart };
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
searchFrom += 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return best;
|
|
81
|
+
}
|
|
82
|
+
export function readLabeledRemainder(text, labels, options = {}) {
|
|
83
|
+
const match = findLabeledValue(text, labels, options.requireSeparator ?? true);
|
|
84
|
+
if (match === null)
|
|
85
|
+
return undefined;
|
|
86
|
+
let valueEnd = text.length;
|
|
87
|
+
if (options.stopCharacter) {
|
|
88
|
+
const stop = text.indexOf(options.stopCharacter, match.valueStart);
|
|
89
|
+
if (stop >= 0)
|
|
90
|
+
valueEnd = stop;
|
|
91
|
+
}
|
|
92
|
+
if (options.stopLabels?.length) {
|
|
93
|
+
const stop = findLabeledValue(text, options.stopLabels, true, match.valueStart, true);
|
|
94
|
+
if (stop !== null && stop.labelStart < valueEnd)
|
|
95
|
+
valueEnd = stop.labelStart;
|
|
96
|
+
}
|
|
97
|
+
const value = text.slice(match.valueStart, valueEnd).trim();
|
|
98
|
+
return value || undefined;
|
|
99
|
+
}
|
|
100
|
+
export function readLabeledEmailUsername(text, labels) {
|
|
101
|
+
const match = findLabeledValue(text, labels, false);
|
|
102
|
+
if (match === null || !isEmailLocalCharacter(text[match.valueStart]))
|
|
103
|
+
return undefined;
|
|
104
|
+
let end = match.valueStart;
|
|
105
|
+
while (end < text.length && isEmailLocalCharacter(text[end]))
|
|
106
|
+
end += 1;
|
|
107
|
+
return text.slice(match.valueStart, end);
|
|
108
|
+
}
|
|
109
|
+
function isValidDomain(domain) {
|
|
110
|
+
let labelStart = 0;
|
|
111
|
+
let dotCount = 0;
|
|
112
|
+
for (let index = 0; index <= domain.length; index += 1) {
|
|
113
|
+
if (index < domain.length && domain[index] !== '.') {
|
|
114
|
+
if (!isAsciiAlphanumeric(domain[index]) && domain[index] !== '-')
|
|
115
|
+
return false;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (index === labelStart ||
|
|
119
|
+
!isAsciiAlphanumeric(domain[labelStart]) ||
|
|
120
|
+
!isAsciiAlphanumeric(domain[index - 1])) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
if (index < domain.length) {
|
|
124
|
+
dotCount += 1;
|
|
125
|
+
labelStart = index + 1;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (dotCount < 1 || domain.length - labelStart < 2)
|
|
129
|
+
return false;
|
|
130
|
+
for (let index = labelStart; index < domain.length; index += 1) {
|
|
131
|
+
if (!isAsciiLetter(domain[index]))
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
function isValidEmailParts(local, domain) {
|
|
137
|
+
if (!local || local.startsWith('.') || local.endsWith('.') || local.includes('..') || !domain) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
return isValidDomain(domain);
|
|
141
|
+
}
|
|
142
|
+
function readEmailAt(text, start) {
|
|
143
|
+
if (!isEmailLocalCharacter(text[start]))
|
|
144
|
+
return { nextIndex: start + 1 };
|
|
145
|
+
let cursor = start;
|
|
146
|
+
while (cursor < text.length && isEmailLocalCharacter(text[cursor]))
|
|
147
|
+
cursor += 1;
|
|
148
|
+
const localEnd = cursor;
|
|
149
|
+
if (text[cursor] !== '@')
|
|
150
|
+
return { nextIndex: cursor };
|
|
151
|
+
cursor += 1;
|
|
152
|
+
const domainStart = cursor;
|
|
153
|
+
while (cursor < text.length && isEmailDomainCharacter(text[cursor]))
|
|
154
|
+
cursor += 1;
|
|
155
|
+
let addressEnd = cursor;
|
|
156
|
+
while (addressEnd > domainStart && text[addressEnd - 1] === '.')
|
|
157
|
+
addressEnd -= 1;
|
|
158
|
+
const local = text.slice(start, localEnd);
|
|
159
|
+
const domain = text.slice(domainStart, addressEnd);
|
|
160
|
+
return {
|
|
161
|
+
email: isValidEmailParts(local, domain) ? text.slice(start, addressEnd) : undefined,
|
|
162
|
+
nextIndex: Math.max(cursor, start + 1),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
export function extractEmailAddresses(text) {
|
|
166
|
+
const emails = [];
|
|
167
|
+
let cursor = 0;
|
|
168
|
+
while (cursor < text.length) {
|
|
169
|
+
if (!isEmailLocalCharacter(text[cursor])) {
|
|
170
|
+
cursor += 1;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const result = readEmailAt(text, cursor);
|
|
174
|
+
if (result.email)
|
|
175
|
+
emails.push(result.email);
|
|
176
|
+
cursor = result.nextIndex;
|
|
177
|
+
}
|
|
178
|
+
return emails;
|
|
179
|
+
}
|
|
180
|
+
export function readLabeledEmail(text, labels) {
|
|
181
|
+
const match = findLabeledValue(text, labels, true);
|
|
182
|
+
if (match === null)
|
|
183
|
+
return undefined;
|
|
184
|
+
return readEmailAt(text, match.valueStart).email;
|
|
185
|
+
}
|
|
186
|
+
export function extractFencedBlock(text, optionalLanguages) {
|
|
187
|
+
const openingFence = text.indexOf('```');
|
|
188
|
+
if (openingFence < 0)
|
|
189
|
+
return undefined;
|
|
190
|
+
let contentStart = openingFence + 3;
|
|
191
|
+
for (const language of optionalLanguages) {
|
|
192
|
+
if (matchesAsciiCaseInsensitive(text, language, contentStart)) {
|
|
193
|
+
contentStart += language.length;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
contentStart = skipWhitespace(text, contentStart);
|
|
198
|
+
const closingFence = text.indexOf('```', contentStart);
|
|
199
|
+
return closingFence < 0 ? undefined : text.slice(contentStart, closingFence);
|
|
200
|
+
}
|
|
201
|
+
export function parseCompactQuantity(text) {
|
|
202
|
+
let cursor = 0;
|
|
203
|
+
while (cursor < text.length) {
|
|
204
|
+
if (!isAsciiDigit(text[cursor])) {
|
|
205
|
+
cursor += 1;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const numberStart = cursor;
|
|
209
|
+
while (cursor < text.length && isAsciiDigit(text[cursor]))
|
|
210
|
+
cursor += 1;
|
|
211
|
+
if (text[cursor] === '.' && isAsciiDigit(text[cursor + 1])) {
|
|
212
|
+
cursor += 1;
|
|
213
|
+
while (cursor < text.length && isAsciiDigit(text[cursor]))
|
|
214
|
+
cursor += 1;
|
|
215
|
+
}
|
|
216
|
+
const numberEnd = cursor;
|
|
217
|
+
const suffixIndex = skipWhitespace(text, cursor);
|
|
218
|
+
const suffix = text[suffixIndex]?.toLowerCase();
|
|
219
|
+
if (suffix === 'k' || suffix === 'm') {
|
|
220
|
+
const value = Number(text.slice(numberStart, numberEnd));
|
|
221
|
+
if (Number.isFinite(value))
|
|
222
|
+
return { value, suffix };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentdomain/eliza-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "ElizaOS plugin for AgentDomain - give your Eliza agent a complete identity stack",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": "https://github.com/0xmdrakib/AgentDomain.git",
|
|
7
|
-
"homepage": "https://agentdomain.app
|
|
7
|
+
"homepage": "https://docs.agentdomain.app",
|
|
8
8
|
"bugs": "https://github.com/0xmdrakib/AgentDomain/issues",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "./dist/index.js",
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
20
|
"README.md",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"NOTICE",
|
|
21
23
|
"package.json"
|
|
22
24
|
],
|
|
23
25
|
"publishConfig": {
|
|
@@ -26,8 +28,8 @@
|
|
|
26
28
|
"dependencies": {
|
|
27
29
|
"viem": "^2.55.2",
|
|
28
30
|
"zod": "^3.24.1",
|
|
29
|
-
"@agentdomain/sdk": "^0.
|
|
30
|
-
"@agentdomain/shared": "^0.
|
|
31
|
+
"@agentdomain/sdk": "^0.7.0",
|
|
32
|
+
"@agentdomain/shared": "^0.7.0"
|
|
31
33
|
},
|
|
32
34
|
"peerDependencies": {
|
|
33
35
|
"@elizaos/core": "^1.0.0"
|
|
@@ -37,6 +39,7 @@
|
|
|
37
39
|
},
|
|
38
40
|
"scripts": {
|
|
39
41
|
"build": "tsc",
|
|
42
|
+
"test": "pnpm --filter @agentdomain/sdk build && pnpm run build && node --test test/*.test.mjs",
|
|
40
43
|
"typecheck": "tsc --noEmit",
|
|
41
44
|
"lint": "echo \"no lint\""
|
|
42
45
|
}
|