@defai.digital/ability-domain 13.2.2 → 13.2.4
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/loader.d.ts.map +1 -1
- package/dist/loader.js +55 -16
- package/dist/loader.js.map +1 -1
- package/package.json +2 -2
- package/src/loader.ts +59 -16
package/dist/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAYrE;;GAEG;AACH,qBAAa,uBAAwB,YAAW,aAAa;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IACvD,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,mBAAmB;IAOjC,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAOrD,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IA+C7B,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAO3C,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAK7B;;OAEG;YACW,QAAQ;IAwCtB;;OAEG;IACH,OAAO,CAAC,aAAa;IAoFrB;;OAEG;IACH,OAAO,CAAC,SAAS;CAMlB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,GAAG,aAAa,CAE9E"}
|
package/dist/loader.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Loads abilities from markdown files.
|
|
5
5
|
* Format: Each .md file is an ability with YAML frontmatter for metadata.
|
|
6
6
|
*/
|
|
7
|
-
import * as
|
|
7
|
+
import * as fsPromises from 'node:fs/promises';
|
|
8
8
|
import * as path from 'node:path';
|
|
9
9
|
import { validateAbility } from '@defai.digital/contracts';
|
|
10
10
|
// ============================================================================
|
|
@@ -36,17 +36,27 @@ export class FileSystemAbilityLoader {
|
|
|
36
36
|
async loadAll() {
|
|
37
37
|
this.cache.clear();
|
|
38
38
|
const dirPath = this.config.abilitiesDir;
|
|
39
|
-
if (!fs.existsSync(dirPath)) {
|
|
40
|
-
this.loaded = true;
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
const files = fs.readdirSync(dirPath);
|
|
44
39
|
const abilities = [];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
// Read directory with file types to filter out directories
|
|
41
|
+
// Handle missing/inaccessible directory gracefully
|
|
42
|
+
let entries;
|
|
43
|
+
try {
|
|
44
|
+
entries = await fsPromises.readdir(dirPath, { withFileTypes: true });
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
const code = err.code;
|
|
48
|
+
if (code === 'ENOENT' || code === 'EACCES' || code === 'ENOTDIR') {
|
|
49
|
+
this.loaded = true;
|
|
50
|
+
return [];
|
|
49
51
|
}
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
// Filter to only files with matching extensions
|
|
55
|
+
const files = entries
|
|
56
|
+
.filter((entry) => entry.isFile())
|
|
57
|
+
.map((entry) => entry.name)
|
|
58
|
+
.filter((name) => this.config.extensions.includes(path.extname(name).toLowerCase()));
|
|
59
|
+
for (const file of files) {
|
|
50
60
|
const filePath = path.join(dirPath, file);
|
|
51
61
|
const ability = await this.loadFile(filePath, file);
|
|
52
62
|
if (ability) {
|
|
@@ -76,7 +86,7 @@ export class FileSystemAbilityLoader {
|
|
|
76
86
|
*/
|
|
77
87
|
async loadFile(filePath, fileName) {
|
|
78
88
|
try {
|
|
79
|
-
const content =
|
|
89
|
+
const content = await fsPromises.readFile(filePath, 'utf-8');
|
|
80
90
|
const { metadata, body } = this.parseMarkdown(content);
|
|
81
91
|
// Generate ability ID from filename if not in metadata
|
|
82
92
|
const abilityId = typeof metadata.abilityId === 'string'
|
|
@@ -112,25 +122,50 @@ export class FileSystemAbilityLoader {
|
|
|
112
122
|
* Parse markdown with optional YAML frontmatter
|
|
113
123
|
*/
|
|
114
124
|
parseMarkdown(content) {
|
|
125
|
+
// Normalize Windows line endings to Unix for cross-platform compatibility
|
|
126
|
+
const normalizedContent = content.replace(/\r\n/g, '\n');
|
|
115
127
|
const frontmatterRegex = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/;
|
|
116
|
-
const match = frontmatterRegex.exec(
|
|
128
|
+
const match = frontmatterRegex.exec(normalizedContent);
|
|
117
129
|
if (!match) {
|
|
118
|
-
return { metadata: {}, body:
|
|
130
|
+
return { metadata: {}, body: normalizedContent };
|
|
119
131
|
}
|
|
120
132
|
const frontmatter = match[1] ?? '';
|
|
121
133
|
const body = match[2] ?? '';
|
|
122
134
|
// Simple YAML parser for frontmatter
|
|
123
135
|
const metadata = {};
|
|
124
136
|
const lines = frontmatter.split('\n');
|
|
125
|
-
|
|
137
|
+
let currentKey = null;
|
|
138
|
+
let currentArray = null;
|
|
139
|
+
for (let i = 0; i < lines.length; i++) {
|
|
140
|
+
const line = lines[i] ?? '';
|
|
141
|
+
// Check if this is a YAML array item (starts with " - " or "- ")
|
|
142
|
+
const arrayItemMatch = /^\s+-\s+(.*)$/.exec(line);
|
|
143
|
+
if (arrayItemMatch && currentKey !== null && currentArray !== null) {
|
|
144
|
+
const itemValue = arrayItemMatch[1]?.trim().replace(/^['"]|['"]$/g, '') ?? '';
|
|
145
|
+
currentArray.push(itemValue);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
// If we were building an array and hit a non-array line, save it
|
|
149
|
+
if (currentKey !== null && currentArray !== null) {
|
|
150
|
+
metadata[currentKey] = currentArray;
|
|
151
|
+
currentKey = null;
|
|
152
|
+
currentArray = null;
|
|
153
|
+
}
|
|
126
154
|
const colonIndex = line.indexOf(':');
|
|
127
155
|
if (colonIndex === -1)
|
|
128
156
|
continue;
|
|
129
157
|
const key = line.substring(0, colonIndex).trim();
|
|
130
158
|
let value = line.substring(colonIndex + 1).trim();
|
|
131
|
-
//
|
|
159
|
+
// Check if this starts a multi-line array
|
|
132
160
|
if (value === '') {
|
|
133
|
-
//
|
|
161
|
+
// Look ahead to see if next line is an array item
|
|
162
|
+
const nextLine = lines[i + 1];
|
|
163
|
+
if (nextLine !== undefined && /^\s+-\s+/.test(nextLine)) {
|
|
164
|
+
currentKey = key;
|
|
165
|
+
currentArray = [];
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
// Empty value, skip
|
|
134
169
|
continue;
|
|
135
170
|
}
|
|
136
171
|
// Parse booleans
|
|
@@ -150,6 +185,10 @@ export class FileSystemAbilityLoader {
|
|
|
150
185
|
}
|
|
151
186
|
metadata[key] = value;
|
|
152
187
|
}
|
|
188
|
+
// Don't forget to save any trailing array
|
|
189
|
+
if (currentKey !== null && currentArray !== null) {
|
|
190
|
+
metadata[currentKey] = currentArray;
|
|
191
|
+
}
|
|
153
192
|
return { metadata, body };
|
|
154
193
|
}
|
|
155
194
|
/**
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAG3D,+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AC,CAAC;AAC7C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defai.digital/ability-domain",
|
|
3
|
-
"version": "13.2.
|
|
3
|
+
"version": "13.2.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Ability management for AutomatosX agents",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@defai.digital/contracts": "13.2.
|
|
36
|
+
"@defai.digital/contracts": "13.2.4"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"typescript": "^5.7.2"
|
package/src/loader.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import * as fs from 'node:fs';
|
|
9
|
+
import * as fsPromises from 'node:fs/promises';
|
|
9
10
|
import * as path from 'node:path';
|
|
10
11
|
import type { Ability } from '@defai.digital/contracts';
|
|
11
12
|
import { validateAbility } from '@defai.digital/contracts';
|
|
@@ -47,21 +48,29 @@ export class FileSystemAbilityLoader implements AbilityLoader {
|
|
|
47
48
|
this.cache.clear();
|
|
48
49
|
|
|
49
50
|
const dirPath = this.config.abilitiesDir;
|
|
51
|
+
const abilities: Ability[] = [];
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
// Read directory with file types to filter out directories
|
|
54
|
+
// Handle missing/inaccessible directory gracefully
|
|
55
|
+
let entries: fs.Dirent[];
|
|
56
|
+
try {
|
|
57
|
+
entries = await fsPromises.readdir(dirPath, { withFileTypes: true });
|
|
58
|
+
} catch (err) {
|
|
59
|
+
const code = (err as NodeJS.ErrnoException).code;
|
|
60
|
+
if (code === 'ENOENT' || code === 'EACCES' || code === 'ENOTDIR') {
|
|
61
|
+
this.loaded = true;
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
54
65
|
}
|
|
55
66
|
|
|
56
|
-
|
|
57
|
-
const
|
|
67
|
+
// Filter to only files with matching extensions
|
|
68
|
+
const files = entries
|
|
69
|
+
.filter((entry) => entry.isFile())
|
|
70
|
+
.map((entry) => entry.name)
|
|
71
|
+
.filter((name) => this.config.extensions.includes(path.extname(name).toLowerCase()));
|
|
58
72
|
|
|
59
73
|
for (const file of files) {
|
|
60
|
-
const ext = path.extname(file).toLowerCase();
|
|
61
|
-
if (!this.config.extensions.includes(ext)) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
74
|
const filePath = path.join(dirPath, file);
|
|
66
75
|
const ability = await this.loadFile(filePath, file);
|
|
67
76
|
|
|
@@ -102,7 +111,7 @@ export class FileSystemAbilityLoader implements AbilityLoader {
|
|
|
102
111
|
fileName: string
|
|
103
112
|
): Promise<Ability | undefined> {
|
|
104
113
|
try {
|
|
105
|
-
const content =
|
|
114
|
+
const content = await fsPromises.readFile(filePath, 'utf-8');
|
|
106
115
|
const { metadata, body } = this.parseMarkdown(content);
|
|
107
116
|
|
|
108
117
|
// Generate ability ID from filename if not in metadata
|
|
@@ -144,11 +153,13 @@ export class FileSystemAbilityLoader implements AbilityLoader {
|
|
|
144
153
|
metadata: Record<string, unknown>;
|
|
145
154
|
body: string;
|
|
146
155
|
} {
|
|
156
|
+
// Normalize Windows line endings to Unix for cross-platform compatibility
|
|
157
|
+
const normalizedContent = content.replace(/\r\n/g, '\n');
|
|
147
158
|
const frontmatterRegex = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/;
|
|
148
|
-
const match = frontmatterRegex.exec(
|
|
159
|
+
const match = frontmatterRegex.exec(normalizedContent);
|
|
149
160
|
|
|
150
161
|
if (!match) {
|
|
151
|
-
return { metadata: {}, body:
|
|
162
|
+
return { metadata: {}, body: normalizedContent };
|
|
152
163
|
}
|
|
153
164
|
|
|
154
165
|
const frontmatter = match[1] ?? '';
|
|
@@ -158,16 +169,43 @@ export class FileSystemAbilityLoader implements AbilityLoader {
|
|
|
158
169
|
const metadata: Record<string, unknown> = {};
|
|
159
170
|
const lines = frontmatter.split('\n');
|
|
160
171
|
|
|
161
|
-
|
|
172
|
+
let currentKey: string | null = null;
|
|
173
|
+
let currentArray: string[] | null = null;
|
|
174
|
+
|
|
175
|
+
for (let i = 0; i < lines.length; i++) {
|
|
176
|
+
const line = lines[i] ?? '';
|
|
177
|
+
|
|
178
|
+
// Check if this is a YAML array item (starts with " - " or "- ")
|
|
179
|
+
const arrayItemMatch = /^\s+-\s+(.*)$/.exec(line);
|
|
180
|
+
if (arrayItemMatch && currentKey !== null && currentArray !== null) {
|
|
181
|
+
const itemValue = arrayItemMatch[1]?.trim().replace(/^['"]|['"]$/g, '') ?? '';
|
|
182
|
+
currentArray.push(itemValue);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// If we were building an array and hit a non-array line, save it
|
|
187
|
+
if (currentKey !== null && currentArray !== null) {
|
|
188
|
+
metadata[currentKey] = currentArray;
|
|
189
|
+
currentKey = null;
|
|
190
|
+
currentArray = null;
|
|
191
|
+
}
|
|
192
|
+
|
|
162
193
|
const colonIndex = line.indexOf(':');
|
|
163
194
|
if (colonIndex === -1) continue;
|
|
164
195
|
|
|
165
196
|
const key = line.substring(0, colonIndex).trim();
|
|
166
197
|
let value: unknown = line.substring(colonIndex + 1).trim();
|
|
167
198
|
|
|
168
|
-
//
|
|
199
|
+
// Check if this starts a multi-line array
|
|
169
200
|
if (value === '') {
|
|
170
|
-
//
|
|
201
|
+
// Look ahead to see if next line is an array item
|
|
202
|
+
const nextLine = lines[i + 1];
|
|
203
|
+
if (nextLine !== undefined && /^\s+-\s+/.test(nextLine)) {
|
|
204
|
+
currentKey = key;
|
|
205
|
+
currentArray = [];
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
// Empty value, skip
|
|
171
209
|
continue;
|
|
172
210
|
}
|
|
173
211
|
|
|
@@ -187,6 +225,11 @@ export class FileSystemAbilityLoader implements AbilityLoader {
|
|
|
187
225
|
metadata[key] = value;
|
|
188
226
|
}
|
|
189
227
|
|
|
228
|
+
// Don't forget to save any trailing array
|
|
229
|
+
if (currentKey !== null && currentArray !== null) {
|
|
230
|
+
metadata[currentKey] = currentArray;
|
|
231
|
+
}
|
|
232
|
+
|
|
190
233
|
return { metadata, body };
|
|
191
234
|
}
|
|
192
235
|
|