@agent-smith/nodetask 0.1.0

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,3 @@
1
+ import type { TaskDef } from '@agent-smith/task';
2
+ declare function applyFilePlaceholders(def: TaskDef, baseDir?: string): TaskDef;
3
+ export { applyFilePlaceholders };
package/dist/files.js ADDED
@@ -0,0 +1,37 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ function _replaceFilePlaceholders(text, baseDir = "") {
4
+ const fileRegex = /\{file:(.*?)\}/g;
5
+ // The replace function is called for each match
6
+ const resultText = text.replace(fileRegex, (match, filePath) => {
7
+ if (!baseDir) {
8
+ if (!path.isAbsolute(filePath)) {
9
+ throw new Error(`Can not replace relative file placeholder ${filePath} without a baseDir set. Use absolute paths or set a baseDir in TaskConf`);
10
+ }
11
+ }
12
+ // Resolve the absolute path relative to the baseDir (or current working directory)
13
+ const fullPath = path.resolve(baseDir, filePath);
14
+ try {
15
+ const fileContent = fs.readFileSync(fullPath, 'utf8');
16
+ return fileContent;
17
+ }
18
+ catch (error) {
19
+ const msg = `Error reading file placeholder at ${fullPath}: ${error}`;
20
+ throw new Error(msg);
21
+ }
22
+ });
23
+ return resultText;
24
+ }
25
+ function applyFilePlaceholders(def, baseDir) {
26
+ def.prompt = _replaceFilePlaceholders(def.prompt, baseDir);
27
+ if (def.template) {
28
+ if (def.template?.system) {
29
+ def.template.system = _replaceFilePlaceholders(def.template.system, baseDir);
30
+ }
31
+ if (def.template?.afterSystem) {
32
+ def.template.afterSystem = _replaceFilePlaceholders(def.template.afterSystem, baseDir);
33
+ }
34
+ }
35
+ return def;
36
+ }
37
+ export { applyFilePlaceholders };
package/dist/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { NodeTask } from "./task.js";
2
+ export { NodeTask };
package/dist/main.js ADDED
@@ -0,0 +1,2 @@
1
+ import { NodeTask } from "./task.js";
2
+ export { NodeTask };
package/dist/task.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { Agent } from "@agent-smith/agent";
2
+ import { Task, TaskConf, TaskDef, TaskInput, TaskOutput } from "@agent-smith/task";
3
+ declare class NodeTask extends Task {
4
+ constructor(agent: Agent, def: TaskDef);
5
+ run(params: TaskInput, conf?: TaskConf): Promise<TaskOutput>;
6
+ }
7
+ export { NodeTask };
package/dist/task.js ADDED
@@ -0,0 +1,12 @@
1
+ import { Task } from "@agent-smith/task";
2
+ import { applyFilePlaceholders } from './files.js';
3
+ class NodeTask extends Task {
4
+ constructor(agent, def) {
5
+ super(agent, def);
6
+ }
7
+ async run(params, conf) {
8
+ this.def = applyFilePlaceholders(this.def, conf?.baseDir);
9
+ return super.run(params, conf);
10
+ }
11
+ }
12
+ export { NodeTask };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@agent-smith/nodetask",
3
+ "version": "0.1.0",
4
+ "description": "A toolkit to create human friendly agents: the nodejs tasks module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/synw/agent-smith.git"
8
+ },
9
+ "scripts": {
10
+ "buildrl": "rm -rf dist/* && rollup -c",
11
+ "build": "rm -rf dist/* && tsc",
12
+ "watch": "tsc -w",
13
+ "test": "jest --coverage",
14
+ "docs": "typedoc --entryPointStrategy expand"
15
+ },
16
+ "dependencies": {
17
+ "@agent-smith/agent": "^0.1.8",
18
+ "@agent-smith/task": "^0.2.1"
19
+ },
20
+ "devDependencies": {
21
+ "@locallm/api": "^0.7.3",
22
+ "openai": "6.15.0",
23
+ "@locallm/types": "^0.6.7",
24
+ "@rollup/plugin-node-resolve": "^16.0.3",
25
+ "@rollup/plugin-terser": "^0.4.4",
26
+ "@rollup/plugin-typescript": "^12.3.0",
27
+ "@types/node": "^25.0.3",
28
+ "markdown-it-replace-link": "^1.2.2",
29
+ "restmix": "^0.6.1",
30
+ "rollup": "^4.54.0",
31
+ "tslib": "^2.8.1",
32
+ "typedoc": "^0.28.15",
33
+ "typedoc-plugin-markdown": "^4.9.0",
34
+ "typedoc-plugin-rename-defaults": "^0.7.3",
35
+ "typescript": "^5.9.3"
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "module": "./dist/main.js",
41
+ "types": "./dist/main.d.ts",
42
+ "type": "module",
43
+ "exports": {
44
+ ".": {
45
+ "import": "./dist/main.js"
46
+ }
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "registry": "https://registry.npmjs.org/"
51
+ },
52
+ "license": "MIT"
53
+ }