@chatbotkit/agent 1.28.0 → 1.29.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/README.md +67 -0
- package/dist/cjs/agent.cjs +37 -250
- package/dist/cjs/agent.d.ts +9 -53
- package/dist/cjs/execute.cjs +309 -0
- package/dist/cjs/execute.d.ts +56 -0
- package/dist/cjs/index.cjs +9 -4
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/skills.cjs +116 -0
- package/dist/cjs/skills.d.ts +18 -0
- package/dist/esm/agent.d.ts +9 -53
- package/dist/esm/agent.js +35 -248
- package/dist/esm/execute.d.ts +56 -0
- package/dist/esm/execute.js +305 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/skills.d.ts +18 -0
- package/dist/esm/skills.js +111 -0
- package/package.json +44 -2
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { readFile, readdir, stat, watch } from 'fs/promises';
|
|
2
|
+
import yaml from 'js-yaml';
|
|
3
|
+
import { join, resolve } from 'path';
|
|
4
|
+
function parseFrontMatter(content) {
|
|
5
|
+
const frontMatterRegex = /^---\s*\n([\s\S]*?)\n---/;
|
|
6
|
+
const match = content.match(frontMatterRegex);
|
|
7
|
+
if (!match) {
|
|
8
|
+
return {};
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const frontMatter = match[1];
|
|
12
|
+
const parsed = (yaml.load(frontMatter));
|
|
13
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
name: typeof parsed.name === 'string' ? parsed.name : undefined,
|
|
18
|
+
description: typeof parsed.description === 'string' ? parsed.description : undefined,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function loadSkillFromDirectory(skillDir) {
|
|
26
|
+
const skillFilePath = join(skillDir, 'SKILL.md');
|
|
27
|
+
try {
|
|
28
|
+
const content = await readFile(skillFilePath, 'utf-8');
|
|
29
|
+
const { name, description } = parseFrontMatter(content);
|
|
30
|
+
if (!name || !description) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
name,
|
|
35
|
+
description,
|
|
36
|
+
path: resolve(skillFilePath),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export async function loadSkills(directories, options = {}) {
|
|
44
|
+
const skills = ([]);
|
|
45
|
+
const watchControllers = ([]);
|
|
46
|
+
async function scanDirectory(baseDir) {
|
|
47
|
+
try {
|
|
48
|
+
const entries = await readdir(baseDir);
|
|
49
|
+
for (const entry of entries) {
|
|
50
|
+
const entryPath = join(baseDir, entry);
|
|
51
|
+
const entryStat = await stat(entryPath);
|
|
52
|
+
if (entryStat.isDirectory()) {
|
|
53
|
+
const skill = await loadSkillFromDirectory(entryPath);
|
|
54
|
+
if (skill) {
|
|
55
|
+
const existingIdx = skills.findIndex((s) => s.path === skill.path);
|
|
56
|
+
if (existingIdx !== -1) {
|
|
57
|
+
skills[existingIdx] = skill;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
skills.push(skill);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const dir of directories) {
|
|
70
|
+
await scanDirectory(dir);
|
|
71
|
+
}
|
|
72
|
+
if (options.watch) {
|
|
73
|
+
for (const dir of directories) {
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
watchControllers.push(controller);
|
|
76
|
+
(async () => {
|
|
77
|
+
try {
|
|
78
|
+
const watcher = watch(dir, {
|
|
79
|
+
recursive: true,
|
|
80
|
+
signal: controller.signal,
|
|
81
|
+
});
|
|
82
|
+
for await (const event of watcher) {
|
|
83
|
+
if (event.filename?.endsWith('SKILL.md')) {
|
|
84
|
+
await scanDirectory(dir);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
if (err instanceof Error &&
|
|
90
|
+
err.name !== 'AbortError' &&
|
|
91
|
+
!err.message.includes('AbortError')) {
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
})();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
skills,
|
|
99
|
+
close: () => {
|
|
100
|
+
for (const controller of watchControllers) {
|
|
101
|
+
controller.abort();
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export function createSkillsFeature(skills) {
|
|
107
|
+
return {
|
|
108
|
+
name: ('skills'),
|
|
109
|
+
options: { skills },
|
|
110
|
+
};
|
|
111
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatbotkit/agent",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.29.1",
|
|
4
4
|
"description": "ChatBotKit Agent implementation",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"engines": {
|
|
@@ -42,6 +42,26 @@
|
|
|
42
42
|
"default": "./dist/cjs/agent.cjs"
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
|
+
"./execute": {
|
|
46
|
+
"import": {
|
|
47
|
+
"types": "./dist/esm/execute.d.ts",
|
|
48
|
+
"default": "./dist/esm/execute.js"
|
|
49
|
+
},
|
|
50
|
+
"require": {
|
|
51
|
+
"types": "./dist/cjs/execute.d.ts",
|
|
52
|
+
"default": "./dist/cjs/execute.cjs"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"./execute.js": {
|
|
56
|
+
"import": {
|
|
57
|
+
"types": "./dist/esm/execute.d.ts",
|
|
58
|
+
"default": "./dist/esm/execute.js"
|
|
59
|
+
},
|
|
60
|
+
"require": {
|
|
61
|
+
"types": "./dist/cjs/execute.d.ts",
|
|
62
|
+
"default": "./dist/cjs/execute.cjs"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
45
65
|
".": {
|
|
46
66
|
"import": {
|
|
47
67
|
"types": "./dist/esm/index.d.ts",
|
|
@@ -72,6 +92,26 @@
|
|
|
72
92
|
"default": "./dist/cjs/index.cjs"
|
|
73
93
|
}
|
|
74
94
|
},
|
|
95
|
+
"./skills": {
|
|
96
|
+
"import": {
|
|
97
|
+
"types": "./dist/esm/skills.d.ts",
|
|
98
|
+
"default": "./dist/esm/skills.js"
|
|
99
|
+
},
|
|
100
|
+
"require": {
|
|
101
|
+
"types": "./dist/cjs/skills.d.ts",
|
|
102
|
+
"default": "./dist/cjs/skills.cjs"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"./skills.js": {
|
|
106
|
+
"import": {
|
|
107
|
+
"types": "./dist/esm/skills.d.ts",
|
|
108
|
+
"default": "./dist/esm/skills.js"
|
|
109
|
+
},
|
|
110
|
+
"require": {
|
|
111
|
+
"types": "./dist/cjs/skills.d.ts",
|
|
112
|
+
"default": "./dist/cjs/skills.cjs"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
75
115
|
"./tools": {
|
|
76
116
|
"import": {
|
|
77
117
|
"types": "./dist/esm/tools.d.ts",
|
|
@@ -96,12 +136,14 @@
|
|
|
96
136
|
},
|
|
97
137
|
"types": "./dist/cjs/index.d.ts",
|
|
98
138
|
"dependencies": {
|
|
139
|
+
"js-yaml": "^4.1.0",
|
|
99
140
|
"tslib": "^2.6.2",
|
|
100
141
|
"zod": "^3.25.76",
|
|
101
142
|
"zod-to-json-schema": "^3.24.6",
|
|
102
|
-
"@chatbotkit/sdk": "1.
|
|
143
|
+
"@chatbotkit/sdk": "1.29.0"
|
|
103
144
|
},
|
|
104
145
|
"devDependencies": {
|
|
146
|
+
"@types/js-yaml": "^4.0.9",
|
|
105
147
|
"npm-run-all": "^4.1.5",
|
|
106
148
|
"typedoc": "^0.28.14",
|
|
107
149
|
"typedoc-plugin-markdown": "^4.9.0",
|