@townco/agent 0.1.11 → 0.1.13
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/acp-server/adapter.d.ts +10 -14
- package/dist/acp-server/adapter.js +72 -73
- package/dist/acp-server/cli.d.ts +1 -3
- package/dist/acp-server/cli.js +5 -9
- package/dist/acp-server/http.d.ts +1 -3
- package/dist/acp-server/http.js +163 -173
- package/dist/bin.js +0 -0
- package/dist/definition/index.d.ts +4 -1
- package/dist/definition/index.js +8 -1
- package/dist/index.js +13 -12
- package/dist/runner/agent-runner.d.ts +4 -1
- package/dist/runner/agent-runner.js +4 -4
- package/dist/runner/index.d.ts +1 -3
- package/dist/runner/index.js +14 -18
- package/dist/runner/langchain/index.d.ts +8 -19
- package/dist/runner/langchain/index.js +55 -6
- package/dist/runner/langchain/tools/todo.d.ts +32 -48
- package/dist/runner/langchain/tools/todo.js +13 -16
- package/dist/runner/langchain/tools/web_search.d.ts +1 -1
- package/dist/runner/langchain/tools/web_search.js +18 -21
- package/dist/runner/tool-loader.d.ts +14 -0
- package/dist/runner/tool-loader.js +42 -0
- package/dist/runner/tools.d.ts +8 -7
- package/dist/runner/tools.js +12 -4
- package/dist/scaffold/bundle.d.ts +1 -1
- package/dist/scaffold/bundle.js +1 -1
- package/dist/scaffold/copy-gui.js +1 -1
- package/dist/scaffold/index.d.ts +8 -10
- package/dist/scaffold/index.js +82 -90
- package/dist/storage/index.js +24 -23
- package/dist/templates/index.d.ts +4 -1
- package/dist/templates/index.js +7 -3
- package/dist/test-script.js +11 -12
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/templates/index.ts +11 -4
- package/dist/definition/mcp.d.ts +0 -0
- package/dist/definition/mcp.js +0 -0
- package/dist/definition/tools/todo.d.ts +0 -49
- package/dist/definition/tools/todo.js +0 -80
- package/dist/definition/tools/web_search.d.ts +0 -4
- package/dist/definition/tools/web_search.js +0 -26
- package/dist/example.d.ts +0 -2
- package/dist/example.js +0 -19
package/dist/scaffold/index.js
CHANGED
|
@@ -2,105 +2,97 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { chmod, mkdir, writeFile } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { agentExists, ensureAgentsDir, getAgentPath } from "../storage";
|
|
5
|
-
import {
|
|
6
|
-
generateAgentJson,
|
|
7
|
-
generateBinTs,
|
|
8
|
-
generateEnvExample,
|
|
9
|
-
generateGitignore,
|
|
10
|
-
generateIndexTs,
|
|
11
|
-
generatePackageJson,
|
|
12
|
-
generateReadme,
|
|
13
|
-
generateTsConfig,
|
|
14
|
-
getTemplateVars,
|
|
15
|
-
} from "../templates";
|
|
5
|
+
import { generateAgentJson, generateBinTs, generateEnvExample, generateGitignore, generateIndexTs, generatePackageJson, generateReadme, generateTsConfig, getTemplateVars, } from "../templates";
|
|
16
6
|
import { bundleAgentDependencies } from "./bundle";
|
|
17
7
|
import { copyGuiApp } from "./copy-gui";
|
|
18
8
|
/**
|
|
19
9
|
* Scaffold a new agent package
|
|
20
10
|
*/
|
|
21
11
|
export async function scaffoldAgent(options) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
12
|
+
const { name, definition, overwrite = false, includeGui = true } = options;
|
|
13
|
+
try {
|
|
14
|
+
// Ensure base directory exists
|
|
15
|
+
await ensureAgentsDir();
|
|
16
|
+
// Check if agent already exists
|
|
17
|
+
const exists = await agentExists(name);
|
|
18
|
+
if (exists && !overwrite) {
|
|
19
|
+
return {
|
|
20
|
+
success: false,
|
|
21
|
+
path: getAgentPath(name),
|
|
22
|
+
error: `Agent "${name}" already exists. Use overwrite option to replace it.`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const agentPath = getAgentPath(name);
|
|
26
|
+
// Create the agent directory
|
|
27
|
+
await mkdir(agentPath, { recursive: true });
|
|
28
|
+
const vars = getTemplateVars(name, definition);
|
|
29
|
+
// Generate all template files
|
|
30
|
+
const files = [
|
|
31
|
+
{ path: "package.json", content: generatePackageJson(vars) },
|
|
32
|
+
{ path: "agent.json", content: generateAgentJson(vars) },
|
|
33
|
+
{ path: "index.ts", content: generateIndexTs() },
|
|
34
|
+
{ path: "bin.ts", content: generateBinTs(), executable: true },
|
|
35
|
+
{ path: "tsconfig.json", content: generateTsConfig() },
|
|
36
|
+
{ path: "README.md", content: generateReadme(vars) },
|
|
37
|
+
{ path: ".gitignore", content: generateGitignore() },
|
|
38
|
+
];
|
|
39
|
+
// Add .env.example if needed
|
|
40
|
+
const envExample = generateEnvExample(vars);
|
|
41
|
+
if (envExample) {
|
|
42
|
+
files.push({ path: ".env.example", content: envExample });
|
|
43
|
+
}
|
|
44
|
+
// Write all files
|
|
45
|
+
for (const file of files) {
|
|
46
|
+
const filePath = join(agentPath, file.path);
|
|
47
|
+
await writeFile(filePath, file.content, "utf-8");
|
|
48
|
+
// Make executable if needed
|
|
49
|
+
if (file.executable) {
|
|
50
|
+
await chmod(filePath, 0o755);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Bundle agent dependencies (copy lib files)
|
|
54
|
+
await bundleAgentDependencies(agentPath);
|
|
55
|
+
// Copy GUI app if requested
|
|
56
|
+
if (includeGui) {
|
|
57
|
+
await copyGuiApp(agentPath);
|
|
58
|
+
// Run bun install in the GUI directory
|
|
59
|
+
const guiPath = join(agentPath, "gui");
|
|
60
|
+
await runBunInstall(guiPath);
|
|
61
|
+
}
|
|
62
|
+
// Run bun install in agent root
|
|
63
|
+
await runBunInstall(agentPath);
|
|
64
|
+
return {
|
|
65
|
+
success: true,
|
|
66
|
+
path: agentPath,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
path: getAgentPath(name),
|
|
73
|
+
error: error instanceof Error ? error.message : String(error),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
85
76
|
}
|
|
86
77
|
/**
|
|
87
78
|
* Run bun install in the agent directory
|
|
88
79
|
*/
|
|
89
80
|
function runBunInstall(agentPath) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
const bunInstall = spawn("bun", ["install"], {
|
|
83
|
+
cwd: agentPath,
|
|
84
|
+
stdio: "ignore",
|
|
85
|
+
});
|
|
86
|
+
bunInstall.on("close", (code) => {
|
|
87
|
+
if (code === 0) {
|
|
88
|
+
resolve();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
reject(new Error(`bun install failed with code ${code}`));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
bunInstall.on("error", (error) => {
|
|
95
|
+
reject(error);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
106
98
|
}
|
package/dist/storage/index.js
CHANGED
|
@@ -1,57 +1,58 @@
|
|
|
1
1
|
import { mkdir, readdir, rm, stat } from "node:fs/promises";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
|
|
5
4
|
const AGENTS_DIR = join(homedir(), ".config", "town", "agents");
|
|
6
5
|
/**
|
|
7
6
|
* Get the base directory where all agents are stored
|
|
8
7
|
*/
|
|
9
8
|
export function getAgentsDir() {
|
|
10
|
-
|
|
9
|
+
return AGENTS_DIR;
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* Get the directory path for a specific agent
|
|
14
13
|
*/
|
|
15
14
|
export function getAgentPath(name) {
|
|
16
|
-
|
|
15
|
+
return join(AGENTS_DIR, name);
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
18
|
* Check if an agent exists
|
|
20
19
|
*/
|
|
21
20
|
export async function agentExists(name) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
try {
|
|
22
|
+
const agentPath = getAgentPath(name);
|
|
23
|
+
const stats = await stat(agentPath);
|
|
24
|
+
return stats.isDirectory();
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* List all created agents
|
|
32
32
|
*/
|
|
33
33
|
export async function listAgents() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
try {
|
|
35
|
+
await mkdir(AGENTS_DIR, { recursive: true });
|
|
36
|
+
const entries = await readdir(AGENTS_DIR, { withFileTypes: true });
|
|
37
|
+
return entries
|
|
38
|
+
.filter((entry) => entry.isDirectory())
|
|
39
|
+
.map((entry) => entry.name);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error("Error listing agents:", error);
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
47
|
* Delete an agent
|
|
47
48
|
*/
|
|
48
49
|
export async function deleteAgent(name) {
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
const agentPath = getAgentPath(name);
|
|
51
|
+
await rm(agentPath, { recursive: true, force: true });
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* Ensure the agents directory exists
|
|
54
55
|
*/
|
|
55
56
|
export async function ensureAgentsDir() {
|
|
56
|
-
|
|
57
|
+
await mkdir(AGENTS_DIR, { recursive: true });
|
|
57
58
|
}
|
|
@@ -2,7 +2,10 @@ import type { AgentDefinition } from "../definition";
|
|
|
2
2
|
export interface TemplateVars {
|
|
3
3
|
name: string;
|
|
4
4
|
model: string;
|
|
5
|
-
tools: string
|
|
5
|
+
tools: Array<string | {
|
|
6
|
+
type: "custom";
|
|
7
|
+
modulePath: string;
|
|
8
|
+
}>;
|
|
6
9
|
systemPrompt: string | null;
|
|
7
10
|
hasWebSearch: boolean;
|
|
8
11
|
}
|
package/dist/templates/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export function getTemplateVars(name, definition) {
|
|
|
5
5
|
model: definition.model,
|
|
6
6
|
tools,
|
|
7
7
|
systemPrompt: definition.systemPrompt,
|
|
8
|
-
hasWebSearch: tools.
|
|
8
|
+
hasWebSearch: tools.some((tool) => typeof tool === "string" && tool === "web_search"),
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
export function generatePackageJson(vars) {
|
|
@@ -23,7 +23,7 @@ export function generatePackageJson(vars) {
|
|
|
23
23
|
zod: "^4.1.12",
|
|
24
24
|
};
|
|
25
25
|
const pkg = {
|
|
26
|
-
name: `@
|
|
26
|
+
name: `@townco/agent-${vars.name}`,
|
|
27
27
|
version: "0.0.1",
|
|
28
28
|
type: "module",
|
|
29
29
|
module: "index.ts",
|
|
@@ -102,7 +102,11 @@ export function generateTsConfig() {
|
|
|
102
102
|
return JSON.stringify(config, null, 2);
|
|
103
103
|
}
|
|
104
104
|
export function generateReadme(vars) {
|
|
105
|
-
const toolsList = vars.tools.length > 0
|
|
105
|
+
const toolsList = vars.tools.length > 0
|
|
106
|
+
? vars.tools
|
|
107
|
+
.map((tool) => (typeof tool === "string" ? tool : tool.modulePath))
|
|
108
|
+
.join(", ")
|
|
109
|
+
: "None";
|
|
106
110
|
const envVars = vars.hasWebSearch
|
|
107
111
|
? "\n- `EXA_API_KEY`: Required for web_search tool"
|
|
108
112
|
: "";
|
package/dist/test-script.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { LangchainAgent } from "./runner/langchain";
|
|
2
|
-
|
|
3
2
|
const agent = new LangchainAgent({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
model: "claude-sonnet-4-5-20250929",
|
|
4
|
+
systemPrompt: "You are a helpful assistant.",
|
|
5
|
+
tools: ["todo_write"],
|
|
7
6
|
});
|
|
8
7
|
for await (const event of agent.invoke({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
prompt: [
|
|
9
|
+
{
|
|
10
|
+
type: "text",
|
|
11
|
+
text: "Whats the weather in Tokyo?",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
sessionId: "test-session",
|
|
16
15
|
})) {
|
|
17
|
-
|
|
16
|
+
console.log(event);
|
|
18
17
|
}
|