agentdev 0.1.6 → 0.1.8
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.
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/create.ts
|
|
4
|
+
import { mkdirSync, writeFileSync, existsSync as fsExistsSync } from "fs";
|
|
5
|
+
import { join, dirname } from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
async function createFeature(featureName2) {
|
|
9
|
+
const packageName = featureName2.startsWith("@agentdev/") ? featureName2 : `@agentdev/${featureName2}`;
|
|
10
|
+
const featureClass = toPascalCase(featureName2.replace("@agentdev/", ""));
|
|
11
|
+
const featureSlug = toKebabCase(featureName2.replace("@agentdev/", ""));
|
|
12
|
+
const targetDir = join(process.cwd(), featureSlug);
|
|
13
|
+
if (existsSync(targetDir)) {
|
|
14
|
+
throw new Error(`Directory already exists: ${targetDir}`);
|
|
15
|
+
}
|
|
16
|
+
console.log(`Creating AgentDev Feature: ${packageName}`);
|
|
17
|
+
console.log(`Target directory: ${targetDir}`);
|
|
18
|
+
mkdirSync(join(targetDir, "src"), { recursive: true });
|
|
19
|
+
mkdirSync(join(targetDir, "src", "templates"), { recursive: true });
|
|
20
|
+
mkdirSync(join(targetDir, "scripts"), { recursive: true });
|
|
21
|
+
generatePackageJson(targetDir, packageName, featureSlug);
|
|
22
|
+
generateTsConfig(targetDir);
|
|
23
|
+
generateCopyAssetsScript(targetDir);
|
|
24
|
+
generateMinimalFeatureClass(targetDir, featureClass);
|
|
25
|
+
generateMinimalReadme(targetDir, packageName, featureSlug);
|
|
26
|
+
console.log("\n\u2705 Feature package created successfully!");
|
|
27
|
+
console.log("\nNext steps:");
|
|
28
|
+
console.log(` cd ${featureSlug}`);
|
|
29
|
+
console.log(` npm install`);
|
|
30
|
+
console.log(` # Edit src/index.ts to implement your feature`);
|
|
31
|
+
console.log(` npm run build`);
|
|
32
|
+
}
|
|
33
|
+
function generatePackageJson(targetDir, packageName, featureSlug) {
|
|
34
|
+
const packageJson = {
|
|
35
|
+
name: packageName,
|
|
36
|
+
version: "0.1.0",
|
|
37
|
+
description: `${featureSlug} feature for AgentDev`,
|
|
38
|
+
type: "module",
|
|
39
|
+
main: "dist/index.js",
|
|
40
|
+
types: "dist/index.d.ts",
|
|
41
|
+
files: ["dist", "README.md"],
|
|
42
|
+
scripts: {
|
|
43
|
+
build: "tsup && npm run copy-assets",
|
|
44
|
+
dev: "tsup --watch",
|
|
45
|
+
"copy-assets": "node scripts/copy-assets.mjs",
|
|
46
|
+
prepublishOnly: "npm run build"
|
|
47
|
+
},
|
|
48
|
+
tsup: {
|
|
49
|
+
entry: ["src/index.ts", "src/templates/*.render.ts"],
|
|
50
|
+
format: "esm",
|
|
51
|
+
dts: true,
|
|
52
|
+
clean: true,
|
|
53
|
+
sourcemap: true
|
|
54
|
+
},
|
|
55
|
+
peerDependencies: {
|
|
56
|
+
agentdev: ">=0.1.0"
|
|
57
|
+
},
|
|
58
|
+
devDependencies: {
|
|
59
|
+
"@types/node": "^20.11.0",
|
|
60
|
+
tsup: "^8.3.5",
|
|
61
|
+
typescript: "^5.3.3",
|
|
62
|
+
agentdev: "latest"
|
|
63
|
+
},
|
|
64
|
+
keywords: ["agentdev", "feature", featureSlug],
|
|
65
|
+
license: "MIT"
|
|
66
|
+
};
|
|
67
|
+
writeFileSync(join(targetDir, "package.json"), JSON.stringify(packageJson, null, 2));
|
|
68
|
+
}
|
|
69
|
+
function generateTsConfig(targetDir) {
|
|
70
|
+
const tsConfig = {
|
|
71
|
+
compilerOptions: {
|
|
72
|
+
target: "ES2022",
|
|
73
|
+
module: "ES2022",
|
|
74
|
+
moduleResolution: "bundler",
|
|
75
|
+
outDir: "./dist",
|
|
76
|
+
rootDir: "./src",
|
|
77
|
+
declaration: true,
|
|
78
|
+
sourceMap: true,
|
|
79
|
+
strict: true,
|
|
80
|
+
esModuleInterop: true,
|
|
81
|
+
skipLibCheck: true,
|
|
82
|
+
forceConsistentCasingInFileNames: true,
|
|
83
|
+
resolveJsonModule: true,
|
|
84
|
+
allowSyntheticDefaultImports: true
|
|
85
|
+
},
|
|
86
|
+
include: ["src/**/*"],
|
|
87
|
+
exclude: ["node_modules", "dist"]
|
|
88
|
+
};
|
|
89
|
+
writeFileSync(join(targetDir, "tsconfig.json"), JSON.stringify(tsConfig, null, 2));
|
|
90
|
+
}
|
|
91
|
+
function generateMinimalFeatureClass(targetDir, featureClass) {
|
|
92
|
+
const className = toCamelCase(featureClass);
|
|
93
|
+
const content = `/**
|
|
94
|
+
* ${featureClass} Feature
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
import { fileURLToPath } from 'url';
|
|
98
|
+
import type {
|
|
99
|
+
AgentFeature,
|
|
100
|
+
FeatureInitContext,
|
|
101
|
+
PackageInfo,
|
|
102
|
+
} from 'agentdev';
|
|
103
|
+
import type { Tool } from 'agentdev';
|
|
104
|
+
import { getPackageInfoFromSource } from 'agentdev';
|
|
105
|
+
|
|
106
|
+
export interface ${featureClass}Config {
|
|
107
|
+
/** \u914D\u7F6E\u9009\u9879 */
|
|
108
|
+
enabled?: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export class ${featureClass} implements AgentFeature {
|
|
112
|
+
readonly name = '${className}';
|
|
113
|
+
readonly dependencies: string[] = [];
|
|
114
|
+
readonly source = fileURLToPath(import.meta.url).replace(/\\\\/g, '/');
|
|
115
|
+
readonly description = '${featureClass} feature';
|
|
116
|
+
|
|
117
|
+
private config: ${featureClass}Config;
|
|
118
|
+
private _packageInfo: PackageInfo | null = null;
|
|
119
|
+
|
|
120
|
+
constructor(config: ${featureClass}Config = {}) {
|
|
121
|
+
this.config = {
|
|
122
|
+
enabled: config.enabled ?? true,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* \u83B7\u53D6\u5305\u4FE1\u606F
|
|
128
|
+
*/
|
|
129
|
+
getPackageInfo(): PackageInfo | null {
|
|
130
|
+
if (!this._packageInfo) {
|
|
131
|
+
this._packageInfo = getPackageInfoFromSource(this.source);
|
|
132
|
+
}
|
|
133
|
+
return this._packageInfo;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* \u83B7\u53D6\u6A21\u677F\u540D\u79F0\u5217\u8868
|
|
138
|
+
*/
|
|
139
|
+
getTemplateNames(): string[] {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* \u83B7\u53D6\u5DE5\u5177\u5217\u8868
|
|
145
|
+
*/
|
|
146
|
+
getTools(): Tool[] {
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* \u5F02\u6B65\u83B7\u53D6\u5DE5\u5177\u5217\u8868
|
|
152
|
+
*/
|
|
153
|
+
async getAsyncTools(_ctx: FeatureInitContext): Promise<Tool[]> {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* \u521D\u59CB\u5316
|
|
159
|
+
*/
|
|
160
|
+
async onInitiate(_ctx: FeatureInitContext): Promise<void> {
|
|
161
|
+
// TODO: Feature \u521D\u59CB\u5316\u903B\u8F91
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* \u6E05\u7406\u8D44\u6E90
|
|
166
|
+
*/
|
|
167
|
+
async onDestroy(): Promise<void> {
|
|
168
|
+
// TODO: Feature \u6E05\u7406\u903B\u8F91
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
`;
|
|
172
|
+
writeFileSync(join(targetDir, "src", "index.ts"), content);
|
|
173
|
+
}
|
|
174
|
+
function generateMinimalReadme(targetDir, packageName, featureSlug) {
|
|
175
|
+
const content = `# ${packageName}
|
|
176
|
+
|
|
177
|
+
${featureSlug} feature for AgentDev.
|
|
178
|
+
|
|
179
|
+
## Installation
|
|
180
|
+
|
|
181
|
+
\`\`\`bash
|
|
182
|
+
npm install ${packageName}
|
|
183
|
+
\`\`\`
|
|
184
|
+
|
|
185
|
+
## Usage
|
|
186
|
+
|
|
187
|
+
\`\`\`typescript
|
|
188
|
+
import { Agent } from 'agentdev';
|
|
189
|
+
import { ${toPascalCase(featureSlug)} } from '${packageName}';
|
|
190
|
+
|
|
191
|
+
const agent = new Agent().use(new ${toPascalCase(featureSlug)}());
|
|
192
|
+
\`\`\`
|
|
193
|
+
|
|
194
|
+
## Development
|
|
195
|
+
|
|
196
|
+
\`\`\`bash
|
|
197
|
+
npm install
|
|
198
|
+
npm run build # \u6216 npm run dev \u76D1\u542C\u6A21\u5F0F
|
|
199
|
+
\`\`\`
|
|
200
|
+
|
|
201
|
+
## License
|
|
202
|
+
|
|
203
|
+
MIT
|
|
204
|
+
`;
|
|
205
|
+
writeFileSync(join(targetDir, "README.md"), content);
|
|
206
|
+
}
|
|
207
|
+
function generateCopyAssetsScript(targetDir) {
|
|
208
|
+
const content = `#!/usr/bin/env node
|
|
209
|
+
/**
|
|
210
|
+
* Copy non-TypeScript assets to dist directory
|
|
211
|
+
* This script automatically copies files like .py, .mp3, .json, etc.
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
import { copyFileSync, mkdirSync, readdirSync, statSync } from 'fs';
|
|
215
|
+
import { join, dirname, relative } from 'path';
|
|
216
|
+
import { fileURLToPath } from 'url';
|
|
217
|
+
|
|
218
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
219
|
+
const rootDir = join(__dirname, '..');
|
|
220
|
+
const srcDir = join(rootDir, 'src');
|
|
221
|
+
const distDir = join(rootDir, 'dist');
|
|
222
|
+
|
|
223
|
+
// Extensions to copy (non-TypeScript files)
|
|
224
|
+
const ASSET_EXTENSIONS = new Set([
|
|
225
|
+
'.mp3', '.wav', '.ogg', '.flac', // Audio
|
|
226
|
+
'.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', // Images
|
|
227
|
+
'.json', // Config files
|
|
228
|
+
'.py', '.sh', '.bash', '.zsh', // Scripts
|
|
229
|
+
'.txt', '.md', '.rst', // Docs
|
|
230
|
+
'.yml', '.yaml', '.toml', '.ini', // Config
|
|
231
|
+
'.sql', '.graphql', '.gql', // Data
|
|
232
|
+
'.html', '.css', '.scss', '.less', // Styles
|
|
233
|
+
'.wasm', '.bin', // Binary
|
|
234
|
+
]);
|
|
235
|
+
|
|
236
|
+
function isAssetFile(filename) {
|
|
237
|
+
const idx = filename.lastIndexOf('.');
|
|
238
|
+
return idx >= 0 && ASSET_EXTENSIONS.has(filename.slice(idx).toLowerCase());
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function copyDirectory(src, dest) {
|
|
242
|
+
const entries = readdirSync(src, { withFileTypes: true });
|
|
243
|
+
|
|
244
|
+
for (const entry of entries) {
|
|
245
|
+
const srcPath = join(src, entry.name);
|
|
246
|
+
const destPath = join(dest, entry.name);
|
|
247
|
+
|
|
248
|
+
if (entry.isDirectory()) {
|
|
249
|
+
copyDirectory(srcPath, destPath);
|
|
250
|
+
} else if (entry.isFile() && isAssetFile(entry.name)) {
|
|
251
|
+
mkdirSync(dirname(destPath), { recursive: true });
|
|
252
|
+
copyFileSync(srcPath, destPath);
|
|
253
|
+
console.log(\`Copied: \${relative(rootDir, srcPath)}\`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Copy assets from src to dist
|
|
259
|
+
copyDirectory(srcDir, distDir);
|
|
260
|
+
`;
|
|
261
|
+
writeFileSync(join(targetDir, "scripts", "copy-assets.mjs"), content);
|
|
262
|
+
}
|
|
263
|
+
function toPascalCase(str) {
|
|
264
|
+
return str.replace(/(?:^|-)([a-z])/g, (_, c) => c.toUpperCase());
|
|
265
|
+
}
|
|
266
|
+
function toCamelCase(str) {
|
|
267
|
+
return str.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
268
|
+
}
|
|
269
|
+
function toKebabCase(str) {
|
|
270
|
+
return str.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
|
|
271
|
+
}
|
|
272
|
+
function existsSync(path) {
|
|
273
|
+
try {
|
|
274
|
+
return !!fsExistsSync(path);
|
|
275
|
+
} catch {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/cli.ts
|
|
281
|
+
var args = process.argv.slice(2);
|
|
282
|
+
if (args.length === 0) {
|
|
283
|
+
console.error("Usage: create-agentdev-feature <feature-name>");
|
|
284
|
+
console.error("Example: create-agentdev-feature my-feature");
|
|
285
|
+
process.exit(1);
|
|
286
|
+
}
|
|
287
|
+
var featureName = args[0];
|
|
288
|
+
createFeature(featureName).catch((error) => {
|
|
289
|
+
console.error(`Error creating feature: ${error.message}`);
|
|
290
|
+
process.exit(1);
|
|
291
|
+
});
|
|
292
|
+
//# sourceMappingURL=cli.js.map
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdev",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "A lightweight, decoupled AI agent framework with built-in debugger",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
9
|
"agentdev-viewer": "dist/cli/viewer.cmd",
|
|
10
|
-
"agentdev-server": "dist/cli/server.cmd"
|
|
10
|
+
"agentdev-server": "dist/cli/server.cmd",
|
|
11
|
+
"agentdev-create-feature": "dist/create-feature-cli.cmd"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
14
|
"dist",
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
"build": "tsup && node scripts/generate-bin-cmds.mjs",
|
|
19
20
|
"dev": "tsup --watch",
|
|
20
21
|
"prepublishOnly": "npm run build",
|
|
21
|
-
"create-feature": "node
|
|
22
|
+
"create-feature": "node dist/create-feature-cli.js",
|
|
22
23
|
"copy-example": "node scripts/copy-example-feature.mjs",
|
|
23
24
|
"server": "node dist/cli/server.js"
|
|
24
25
|
},
|