@townco/agent 0.1.22 → 0.1.23
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/cli.d.ts +1 -3
- package/dist/acp-server/cli.js +5 -9
- package/dist/acp-server/http.d.ts +1 -3
- package/dist/bin.js +0 -0
- package/dist/definition/index.d.ts +6 -0
- package/dist/definition/index.js +9 -0
- package/dist/index.js +11 -5
- package/dist/runner/agent-runner.d.ts +6 -0
- package/dist/runner/index.d.ts +1 -3
- package/dist/runner/index.js +14 -18
- package/dist/runner/langchain/index.js +10 -0
- package/dist/runner/langchain/tools/todo.d.ts +32 -48
- package/dist/runner/langchain/tools/web_search.d.ts +1 -1
- package/dist/runner/tools.d.ts +16 -0
- package/dist/runner/tools.js +10 -1
- package/dist/scaffold/copy-gui.js +7 -81
- package/dist/scaffold/copy-tui.js +1 -65
- package/dist/scaffold/index.d.ts +2 -0
- package/dist/scaffold/index.js +26 -31
- package/dist/scaffold/project-scaffold.d.ts +12 -0
- package/dist/scaffold/project-scaffold.js +314 -0
- package/dist/storage/index.d.ts +5 -0
- package/dist/storage/index.js +60 -24
- package/dist/templates/index.d.ts +7 -2
- package/dist/templates/index.js +13 -16
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/tool.d.ts +36 -0
- package/dist/utils/tool.js +33 -0
- package/index.ts +11 -7
- package/package.json +6 -5
- package/templates/index.ts +23 -18
- 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/dev-agent/index.d.ts +0 -2
- package/dist/dev-agent/index.js +0 -18
- package/dist/example.d.ts +0 -2
- package/dist/example.js +0 -19
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
/**
|
|
5
|
+
* Generate project package.json
|
|
6
|
+
*/
|
|
7
|
+
function generateProjectPackageJson() {
|
|
8
|
+
const pkg = {
|
|
9
|
+
name: "town-agents-project",
|
|
10
|
+
version: "0.1.0",
|
|
11
|
+
type: "module",
|
|
12
|
+
private: true,
|
|
13
|
+
scripts: {},
|
|
14
|
+
dependencies: {
|
|
15
|
+
"@agentclientprotocol/sdk": "^0.5.1",
|
|
16
|
+
"@optique/core": "^0.6.2",
|
|
17
|
+
"@optique/run": "^0.6.2",
|
|
18
|
+
"@radix-ui/react-dialog": "^1.1.15",
|
|
19
|
+
"@radix-ui/react-label": "^2.1.8",
|
|
20
|
+
"@radix-ui/react-select": "^2.2.6",
|
|
21
|
+
"@radix-ui/react-slot": "^1.2.4",
|
|
22
|
+
"@radix-ui/react-tabs": "^1.1.13",
|
|
23
|
+
"@townco/ui": "^0.1.0",
|
|
24
|
+
"@townco/agent": "^0.1.20",
|
|
25
|
+
"class-variance-authority": "^0.7.1",
|
|
26
|
+
clsx: "^2.1.1",
|
|
27
|
+
"ink-text-input": "^6.0.0",
|
|
28
|
+
ink: "^6.4.0",
|
|
29
|
+
"lucide-react": "^0.552.0",
|
|
30
|
+
"react-dom": "^19.2.0",
|
|
31
|
+
"react-markdown": "^10.1.0",
|
|
32
|
+
react: "^19.2.0",
|
|
33
|
+
"remark-gfm": "^4.0.1",
|
|
34
|
+
"tailwind-merge": "^3.3.1",
|
|
35
|
+
zod: "^4.1.12",
|
|
36
|
+
zustand: "^5.0.8",
|
|
37
|
+
},
|
|
38
|
+
devDependencies: {
|
|
39
|
+
"@tailwindcss/postcss": "^4.1.17",
|
|
40
|
+
"@types/react": "^19.2.2",
|
|
41
|
+
"@types/react-dom": "^19.2.2",
|
|
42
|
+
"@vitejs/plugin-react": "^5.1.0",
|
|
43
|
+
autoprefixer: "^10.4.21",
|
|
44
|
+
postcss: "^8.5.6",
|
|
45
|
+
tailwindcss: "^4.1.17",
|
|
46
|
+
typescript: "^5.9.3",
|
|
47
|
+
vite: "^7.2.1",
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
return JSON.stringify(pkg, null, 2);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Generate add-two-numbers tool
|
|
54
|
+
*/
|
|
55
|
+
function generateAddTwoNumbersTool() {
|
|
56
|
+
return `// biome-ignore lint/suspicious/noExplicitAny: .
|
|
57
|
+
export const schema = (z: any) =>
|
|
58
|
+
z.object({
|
|
59
|
+
a: z.number().describe("First number"),
|
|
60
|
+
b: z.number().describe("Second number"),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export const name = "add_two_numbers";
|
|
64
|
+
export const description = "Add two numbers together and return the result";
|
|
65
|
+
|
|
66
|
+
export default function addTwoNumbers(input: unknown) {
|
|
67
|
+
const { a, b } = input as { a: number; b: number };
|
|
68
|
+
return { result: a + b };
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Generate project tsconfig.json
|
|
74
|
+
*/
|
|
75
|
+
function generateProjectTsConfig() {
|
|
76
|
+
const config = {
|
|
77
|
+
compilerOptions: {
|
|
78
|
+
target: "ESNext",
|
|
79
|
+
module: "ESNext",
|
|
80
|
+
moduleResolution: "bundler",
|
|
81
|
+
lib: ["ESNext"],
|
|
82
|
+
outDir: "./dist",
|
|
83
|
+
strict: true,
|
|
84
|
+
esModuleInterop: true,
|
|
85
|
+
skipLibCheck: true,
|
|
86
|
+
forceConsistentCasingInFileNames: true,
|
|
87
|
+
resolveJsonModule: true,
|
|
88
|
+
allowSyntheticDefaultImports: true,
|
|
89
|
+
},
|
|
90
|
+
include: ["agents/**/*.ts", "tools/**/*.ts"],
|
|
91
|
+
exclude: ["node_modules", "dist"],
|
|
92
|
+
};
|
|
93
|
+
return JSON.stringify(config, null, 2);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Generate project README.md
|
|
97
|
+
*/
|
|
98
|
+
function generateProjectReadme() {
|
|
99
|
+
return `# Town Agents Project
|
|
100
|
+
|
|
101
|
+
A standalone project for developing Town agents with custom tools.
|
|
102
|
+
|
|
103
|
+
## Project Structure
|
|
104
|
+
|
|
105
|
+
\`\`\`
|
|
106
|
+
.
|
|
107
|
+
├── agents/ # Agent implementations (created with 'town create')
|
|
108
|
+
├── tools/ # Custom tools
|
|
109
|
+
│ └── add-two-numbers.ts # Example tool
|
|
110
|
+
├── package.json # Project dependencies
|
|
111
|
+
└── tsconfig.json # TypeScript configuration
|
|
112
|
+
\`\`\`
|
|
113
|
+
|
|
114
|
+
## Getting Started
|
|
115
|
+
|
|
116
|
+
1. Install dependencies (if not already done):
|
|
117
|
+
|
|
118
|
+
\`\`\`bash
|
|
119
|
+
bun install
|
|
120
|
+
\`\`\`
|
|
121
|
+
|
|
122
|
+
2. Create your first agent:
|
|
123
|
+
|
|
124
|
+
\`\`\`bash
|
|
125
|
+
town create
|
|
126
|
+
\`\`\`
|
|
127
|
+
|
|
128
|
+
This will launch an interactive wizard to create a new agent in the \`agents/\` directory.
|
|
129
|
+
The agent will include GUI and TUI interfaces for interaction.
|
|
130
|
+
|
|
131
|
+
## Creating Agents
|
|
132
|
+
|
|
133
|
+
Run \`town create\` inside your project directory to create new agents.
|
|
134
|
+
Each agent will be placed in \`agents/<agent-name>/\` with the following structure:
|
|
135
|
+
|
|
136
|
+
\`\`\`
|
|
137
|
+
agents/my-agent/
|
|
138
|
+
├── agent.json # Agent configuration
|
|
139
|
+
├── index.ts # Agent entry point
|
|
140
|
+
├── gui/ # Web-based GUI interface
|
|
141
|
+
└── tui/ # Terminal UI interface
|
|
142
|
+
\`\`\`
|
|
143
|
+
|
|
144
|
+
## Running Agents
|
|
145
|
+
|
|
146
|
+
Each agent can be run in different modes:
|
|
147
|
+
|
|
148
|
+
\`\`\`bash
|
|
149
|
+
# CLI mode (stdio)
|
|
150
|
+
bun agents/<agent-name>/index.ts stdio
|
|
151
|
+
|
|
152
|
+
# HTTP server mode
|
|
153
|
+
PORT=3100 bun agents/<agent-name>/index.ts http
|
|
154
|
+
\`\`\`
|
|
155
|
+
|
|
156
|
+
## Creating Custom Tools
|
|
157
|
+
|
|
158
|
+
Tools are defined in the \`tools/\` directory. Each tool exports:
|
|
159
|
+
|
|
160
|
+
- \`schema\`: A Zod schema factory function
|
|
161
|
+
- \`name\`: The tool name
|
|
162
|
+
- \`description\`: Tool description
|
|
163
|
+
- \`default\`: The tool implementation function
|
|
164
|
+
|
|
165
|
+
Example:
|
|
166
|
+
|
|
167
|
+
\`\`\`typescript
|
|
168
|
+
export const schema = (z: any) =>
|
|
169
|
+
z.object({
|
|
170
|
+
input: z.string(),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
export const name = "my_tool";
|
|
174
|
+
export const description = "My custom tool";
|
|
175
|
+
|
|
176
|
+
export default function myTool(input: unknown) {
|
|
177
|
+
// Implementation
|
|
178
|
+
return { result: "success" };
|
|
179
|
+
}
|
|
180
|
+
\`\`\`
|
|
181
|
+
|
|
182
|
+
To use a tool in an agent, import it in the agent's \`index.ts\`:
|
|
183
|
+
|
|
184
|
+
\`\`\`typescript
|
|
185
|
+
import myTool, { name, description, schema } from "../../tools/my-tool.js";
|
|
186
|
+
|
|
187
|
+
const agent: AgentDefinition = {
|
|
188
|
+
// ...
|
|
189
|
+
tools: [
|
|
190
|
+
{
|
|
191
|
+
type: "direct",
|
|
192
|
+
name,
|
|
193
|
+
description,
|
|
194
|
+
fn: myTool,
|
|
195
|
+
schema: schema(z),
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
};
|
|
199
|
+
\`\`\`
|
|
200
|
+
`;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Generate .gitignore
|
|
204
|
+
*/
|
|
205
|
+
function generateProjectGitignore() {
|
|
206
|
+
return `node_modules
|
|
207
|
+
dist
|
|
208
|
+
.env
|
|
209
|
+
*.log
|
|
210
|
+
`;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Run bun install
|
|
214
|
+
*/
|
|
215
|
+
function runBunInstall(projectPath) {
|
|
216
|
+
return new Promise((resolve, reject) => {
|
|
217
|
+
const bunInstall = spawn("bun", ["install"], {
|
|
218
|
+
cwd: projectPath,
|
|
219
|
+
stdio: "pipe",
|
|
220
|
+
});
|
|
221
|
+
let stdout = "";
|
|
222
|
+
let stderr = "";
|
|
223
|
+
// Capture stdout
|
|
224
|
+
bunInstall.stdout?.on("data", (data) => {
|
|
225
|
+
stdout += data.toString();
|
|
226
|
+
});
|
|
227
|
+
// Capture stderr
|
|
228
|
+
bunInstall.stderr?.on("data", (data) => {
|
|
229
|
+
stderr += data.toString();
|
|
230
|
+
});
|
|
231
|
+
bunInstall.on("close", (code) => {
|
|
232
|
+
if (code === 0) {
|
|
233
|
+
resolve();
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// Print captured output on failure
|
|
237
|
+
if (stdout) {
|
|
238
|
+
process.stdout.write(stdout);
|
|
239
|
+
}
|
|
240
|
+
if (stderr) {
|
|
241
|
+
process.stderr.write(stderr);
|
|
242
|
+
}
|
|
243
|
+
reject(new Error(`bun install failed with code ${code}`));
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
bunInstall.on("error", (error) => {
|
|
247
|
+
// Print captured output on error
|
|
248
|
+
if (stdout) {
|
|
249
|
+
process.stdout.write(stdout);
|
|
250
|
+
}
|
|
251
|
+
if (stderr) {
|
|
252
|
+
process.stderr.write(stderr);
|
|
253
|
+
}
|
|
254
|
+
reject(error);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Scaffold a new standalone project
|
|
260
|
+
*/
|
|
261
|
+
export async function scaffoldProject(options) {
|
|
262
|
+
const { path: projectPath } = options;
|
|
263
|
+
try {
|
|
264
|
+
// Create project root directory
|
|
265
|
+
await mkdir(projectPath, { recursive: true });
|
|
266
|
+
// Create agents directory (empty, to be populated by 'town create')
|
|
267
|
+
const agentsDir = join(projectPath, "agents");
|
|
268
|
+
await mkdir(agentsDir, { recursive: true });
|
|
269
|
+
// Create tools directory
|
|
270
|
+
const toolsDir = join(projectPath, "tools");
|
|
271
|
+
await mkdir(toolsDir, { recursive: true });
|
|
272
|
+
// Generate and write files
|
|
273
|
+
const files = [
|
|
274
|
+
{
|
|
275
|
+
path: "package.json",
|
|
276
|
+
content: generateProjectPackageJson(),
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
path: "tsconfig.json",
|
|
280
|
+
content: generateProjectTsConfig(),
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
path: ".gitignore",
|
|
284
|
+
content: generateProjectGitignore(),
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
path: "README.md",
|
|
288
|
+
content: generateProjectReadme(),
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
path: join("tools", "add-two-numbers.ts"),
|
|
292
|
+
content: generateAddTwoNumbersTool(),
|
|
293
|
+
},
|
|
294
|
+
];
|
|
295
|
+
// Write all files
|
|
296
|
+
for (const file of files) {
|
|
297
|
+
const filePath = join(projectPath, file.path);
|
|
298
|
+
await writeFile(filePath, file.content, "utf-8");
|
|
299
|
+
}
|
|
300
|
+
// Run bun install
|
|
301
|
+
await runBunInstall(projectPath);
|
|
302
|
+
return {
|
|
303
|
+
success: true,
|
|
304
|
+
path: projectPath,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
return {
|
|
309
|
+
success: false,
|
|
310
|
+
path: projectPath,
|
|
311
|
+
error: error instanceof Error ? error.message : String(error),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
}
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -22,3 +22,8 @@ export declare function deleteAgent(name: string): Promise<void>;
|
|
|
22
22
|
* Ensure the agents directory exists
|
|
23
23
|
*/
|
|
24
24
|
export declare function ensureAgentsDir(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Check if we're inside a Town project by looking for project markers
|
|
27
|
+
* Returns the project root path if found, null otherwise
|
|
28
|
+
*/
|
|
29
|
+
export declare function isInsideTownProject(startPath?: string): Promise<string | null>;
|
package/dist/storage/index.js
CHANGED
|
@@ -1,57 +1,93 @@
|
|
|
1
1
|
import { mkdir, readdir, rm, stat } from "node:fs/promises";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
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 });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if we're inside a Town project by looking for project markers
|
|
61
|
+
* Returns the project root path if found, null otherwise
|
|
62
|
+
*/
|
|
63
|
+
export async function isInsideTownProject(startPath = process.cwd()) {
|
|
64
|
+
let currentPath = startPath;
|
|
65
|
+
while (true) {
|
|
66
|
+
try {
|
|
67
|
+
// Check if this is a Town project by looking for:
|
|
68
|
+
// 1. agents/ directory exists
|
|
69
|
+
// (this is very naive right now)
|
|
70
|
+
const agentsDir = join(currentPath, "agents");
|
|
71
|
+
try {
|
|
72
|
+
const agentsDirStat = await stat(agentsDir);
|
|
73
|
+
if (agentsDirStat.isDirectory()) {
|
|
74
|
+
return currentPath;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// agents/ directory doesn't exist, continue searching
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// package.json doesn't exist or can't be read, continue searching
|
|
83
|
+
}
|
|
84
|
+
// Move up one directory
|
|
85
|
+
const parentPath = dirname(currentPath);
|
|
86
|
+
if (parentPath === currentPath) {
|
|
87
|
+
// Reached the filesystem root
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
currentPath = parentPath;
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
57
93
|
}
|
|
@@ -8,14 +8,19 @@ export interface TemplateVars {
|
|
|
8
8
|
} | {
|
|
9
9
|
type: "filesystem";
|
|
10
10
|
working_directory?: string | undefined;
|
|
11
|
+
} | {
|
|
12
|
+
type: "direct";
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
fn: any;
|
|
16
|
+
schema: unknown;
|
|
11
17
|
}>;
|
|
12
18
|
systemPrompt: string | null;
|
|
13
19
|
hasWebSearch: boolean;
|
|
14
20
|
}
|
|
15
21
|
export declare function getTemplateVars(name: string, definition: AgentDefinition): TemplateVars;
|
|
16
22
|
export declare function generatePackageJson(vars: TemplateVars): string;
|
|
17
|
-
export declare function generateIndexTs(): string
|
|
18
|
-
export declare function generateAgentJson(vars: TemplateVars): string;
|
|
23
|
+
export declare function generateIndexTs(vars: TemplateVars): Promise<string>;
|
|
19
24
|
export declare function generateBinTs(): string;
|
|
20
25
|
export declare function generateGitignore(): string;
|
|
21
26
|
export declare function generateTsConfig(): string;
|
package/dist/templates/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as prettier from "prettier";
|
|
1
2
|
export function getTemplateVars(name, definition) {
|
|
2
3
|
const tools = definition.tools ?? [];
|
|
3
4
|
return {
|
|
@@ -42,15 +43,17 @@ export function generatePackageJson(vars) {
|
|
|
42
43
|
};
|
|
43
44
|
return JSON.stringify(pkg, null, 2);
|
|
44
45
|
}
|
|
45
|
-
export function generateIndexTs() {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
export async function generateIndexTs(vars) {
|
|
47
|
+
const agentDef = {
|
|
48
|
+
model: vars.model,
|
|
49
|
+
systemPrompt: vars.systemPrompt,
|
|
50
|
+
tools: vars.tools,
|
|
51
|
+
};
|
|
52
|
+
return prettier.format(`import { makeHttpTransport, makeStdioTransport } from "@townco/agent/acp-server";
|
|
49
53
|
import type { AgentDefinition } from "@townco/agent/definition";
|
|
50
54
|
|
|
51
55
|
// Load agent definition from JSON file
|
|
52
|
-
const
|
|
53
|
-
const agent: AgentDefinition = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
56
|
+
const agent: AgentDefinition = ${JSON.stringify(agentDef)};
|
|
54
57
|
|
|
55
58
|
const transport = process.argv[2] || "stdio";
|
|
56
59
|
|
|
@@ -62,19 +65,11 @@ if (transport === "http") {
|
|
|
62
65
|
console.error(\`Invalid transport: \${transport}\`);
|
|
63
66
|
process.exit(1);
|
|
64
67
|
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
export function generateAgentJson(vars) {
|
|
68
|
-
const agentDef = {
|
|
69
|
-
model: vars.model,
|
|
70
|
-
systemPrompt: vars.systemPrompt,
|
|
71
|
-
tools: vars.tools,
|
|
72
|
-
};
|
|
73
|
-
return JSON.stringify(agentDef, null, 2);
|
|
68
|
+
`, { parser: "typescript" });
|
|
74
69
|
}
|
|
75
70
|
export function generateBinTs() {
|
|
76
71
|
return `#!/usr/bin/env bun
|
|
77
|
-
import "./index.
|
|
72
|
+
import "./index.ts";
|
|
78
73
|
`;
|
|
79
74
|
}
|
|
80
75
|
export function generateGitignore() {
|
|
@@ -113,6 +108,8 @@ export function generateReadme(vars) {
|
|
|
113
108
|
return tool.modulePath;
|
|
114
109
|
if (tool.type === "filesystem")
|
|
115
110
|
return `filesystem${tool.working_directory ? ` (${tool.working_directory})` : ""}`;
|
|
111
|
+
if (tool.type === "direct")
|
|
112
|
+
return tool.name;
|
|
116
113
|
return "";
|
|
117
114
|
})
|
|
118
115
|
.join(", ")
|