@townco/agent 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.
- package/README.md +15 -0
- package/dist/acp-server/adapter.d.ts +15 -0
- package/dist/acp-server/adapter.js +76 -0
- package/dist/acp-server/cli.d.ts +3 -0
- package/dist/acp-server/cli.js +11 -0
- package/dist/acp-server/http.d.ts +3 -0
- package/dist/acp-server/http.js +178 -0
- package/dist/acp-server/index.d.ts +2 -0
- package/dist/acp-server/index.js +2 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +3 -0
- package/dist/definition/index.d.ts +30 -0
- package/dist/definition/index.js +33 -0
- package/dist/definition/mcp.d.ts +0 -0
- package/dist/definition/mcp.js +1 -0
- package/dist/definition/tools/todo.d.ts +33 -0
- package/dist/definition/tools/todo.js +77 -0
- package/dist/definition/tools/web_search.d.ts +4 -0
- package/dist/definition/tools/web_search.js +23 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.js +20 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -0
- package/dist/runner/agent-runner.d.ts +24 -0
- package/dist/runner/agent-runner.js +9 -0
- package/dist/runner/index.d.ts +4 -0
- package/dist/runner/index.js +18 -0
- package/dist/runner/langchain/index.d.ts +15 -0
- package/dist/runner/langchain/index.js +227 -0
- package/dist/runner/langchain/tools/todo.d.ts +33 -0
- package/dist/runner/langchain/tools/todo.js +77 -0
- package/dist/runner/langchain/tools/web_search.d.ts +4 -0
- package/dist/runner/langchain/tools/web_search.js +23 -0
- package/dist/runner/tools.d.ts +3 -0
- package/dist/runner/tools.js +6 -0
- package/dist/scaffold/bundle.d.ts +4 -0
- package/dist/scaffold/bundle.js +28 -0
- package/dist/scaffold/copy-gui.d.ts +4 -0
- package/dist/scaffold/copy-gui.js +210 -0
- package/dist/scaffold/index.d.ts +16 -0
- package/dist/scaffold/index.js +98 -0
- package/dist/storage/index.d.ts +24 -0
- package/dist/storage/index.js +58 -0
- package/dist/templates/index.d.ts +17 -0
- package/dist/templates/index.js +173 -0
- package/dist/test-script.d.ts +1 -0
- package/dist/test-script.js +17 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +72 -0
- package/templates/index.ts +203 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import type { AgentDefinition } from "../definition";
|
|
2
|
+
|
|
3
|
+
export interface TemplateVars {
|
|
4
|
+
name: string;
|
|
5
|
+
model: string;
|
|
6
|
+
tools: string[];
|
|
7
|
+
systemPrompt: string | null;
|
|
8
|
+
hasWebSearch: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getTemplateVars(
|
|
12
|
+
name: string,
|
|
13
|
+
definition: AgentDefinition,
|
|
14
|
+
): TemplateVars {
|
|
15
|
+
const tools = definition.tools || [];
|
|
16
|
+
return {
|
|
17
|
+
name,
|
|
18
|
+
model: definition.model,
|
|
19
|
+
tools,
|
|
20
|
+
systemPrompt: definition.systemPrompt,
|
|
21
|
+
hasWebSearch: tools.includes("web_search"),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function generatePackageJson(
|
|
26
|
+
vars: TemplateVars,
|
|
27
|
+
useLocalDeps = true,
|
|
28
|
+
): string {
|
|
29
|
+
// For local development, use link: protocol to reference monorepo packages
|
|
30
|
+
// After npm publish, users will use the published versions
|
|
31
|
+
const dependencies: Record<string, string> = useLocalDeps
|
|
32
|
+
? {
|
|
33
|
+
"@townco/agent": "link:../../../../agent_hub/packages/agent",
|
|
34
|
+
"@townco/ui": "link:../../../../agent_hub/packages/ui",
|
|
35
|
+
}
|
|
36
|
+
: {
|
|
37
|
+
"@townco/agent": "^0.1.0",
|
|
38
|
+
"@townco/ui": "^0.1.0",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const pkg = {
|
|
42
|
+
name: `@townco/agent-${vars.name}`,
|
|
43
|
+
version: "0.0.1",
|
|
44
|
+
type: "module",
|
|
45
|
+
module: "index.ts",
|
|
46
|
+
bin: {
|
|
47
|
+
[`town-agent-${vars.name}`]: "./bin.ts",
|
|
48
|
+
},
|
|
49
|
+
scripts: {
|
|
50
|
+
build: "tsc",
|
|
51
|
+
check: "tsc --noEmit",
|
|
52
|
+
start: "bun index.ts stdio",
|
|
53
|
+
"start-http": "PORT=3100 bun index.ts http",
|
|
54
|
+
},
|
|
55
|
+
dependencies,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return JSON.stringify(pkg, null, 2);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function generateIndexTs(): string {
|
|
62
|
+
return `import { readFileSync } from "node:fs";
|
|
63
|
+
import { join } from "node:path";
|
|
64
|
+
import { makeHttpTransport, makeStdioTransport } from "@townco/agent/acp-server";
|
|
65
|
+
import type { AgentDefinition } from "@townco/agent/definition";
|
|
66
|
+
|
|
67
|
+
// Load agent definition from JSON file
|
|
68
|
+
const configPath = join(import.meta.dir, "agent.json");
|
|
69
|
+
const agent: AgentDefinition = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
70
|
+
|
|
71
|
+
const transport = process.argv[2] || "stdio";
|
|
72
|
+
|
|
73
|
+
if (transport === "http") {
|
|
74
|
+
makeHttpTransport(agent);
|
|
75
|
+
} else if (transport === "stdio") {
|
|
76
|
+
makeStdioTransport(agent);
|
|
77
|
+
} else {
|
|
78
|
+
console.error(\`Invalid transport: \${transport}\`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function generateAgentJson(vars: TemplateVars): string {
|
|
85
|
+
const agentDef = {
|
|
86
|
+
model: vars.model,
|
|
87
|
+
systemPrompt: vars.systemPrompt,
|
|
88
|
+
tools: vars.tools,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return JSON.stringify(agentDef, null, 2);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function generateBinTs(): string {
|
|
95
|
+
return `#!/usr/bin/env bun
|
|
96
|
+
import "./index.js";
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function generateGitignore(): string {
|
|
101
|
+
return `node_modules
|
|
102
|
+
dist
|
|
103
|
+
.env
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function generateTsConfig(): string {
|
|
108
|
+
const config = {
|
|
109
|
+
compilerOptions: {
|
|
110
|
+
target: "ESNext",
|
|
111
|
+
module: "ESNext",
|
|
112
|
+
moduleResolution: "bundler",
|
|
113
|
+
lib: ["ESNext"],
|
|
114
|
+
outDir: "./dist",
|
|
115
|
+
strict: true,
|
|
116
|
+
esModuleInterop: true,
|
|
117
|
+
skipLibCheck: true,
|
|
118
|
+
forceConsistentCasingInFileNames: true,
|
|
119
|
+
resolveJsonModule: true,
|
|
120
|
+
allowSyntheticDefaultImports: true,
|
|
121
|
+
},
|
|
122
|
+
include: ["**/*.ts"],
|
|
123
|
+
exclude: ["node_modules", "dist"],
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return JSON.stringify(config, null, 2);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function generateReadme(vars: TemplateVars): string {
|
|
130
|
+
const toolsList = vars.tools.length > 0 ? vars.tools.join(", ") : "None";
|
|
131
|
+
const envVars = vars.hasWebSearch
|
|
132
|
+
? "\n- `EXA_API_KEY`: Required for web_search tool"
|
|
133
|
+
: "";
|
|
134
|
+
|
|
135
|
+
return `# ${vars.name}
|
|
136
|
+
|
|
137
|
+
Agent created with \`town create\`.
|
|
138
|
+
|
|
139
|
+
## Configuration
|
|
140
|
+
|
|
141
|
+
- **Model**: ${vars.model}
|
|
142
|
+
- **Tools**: ${toolsList}
|
|
143
|
+
- **System Prompt**: ${vars.systemPrompt ? "Yes" : "No"}
|
|
144
|
+
|
|
145
|
+
## Setup
|
|
146
|
+
${envVars ? `\n### Environment Variables\n${envVars}\n` : ""}
|
|
147
|
+
Install dependencies:
|
|
148
|
+
|
|
149
|
+
\`\`\`bash
|
|
150
|
+
bun install
|
|
151
|
+
\`\`\`
|
|
152
|
+
|
|
153
|
+
## Usage
|
|
154
|
+
|
|
155
|
+
### CLI Mode (stdio)
|
|
156
|
+
|
|
157
|
+
\`\`\`bash
|
|
158
|
+
bun start
|
|
159
|
+
\`\`\`
|
|
160
|
+
|
|
161
|
+
Or using the executable:
|
|
162
|
+
|
|
163
|
+
\`\`\`bash
|
|
164
|
+
town-agent-${vars.name}
|
|
165
|
+
\`\`\`
|
|
166
|
+
|
|
167
|
+
### Server Mode (HTTP)
|
|
168
|
+
|
|
169
|
+
\`\`\`bash
|
|
170
|
+
bun run start-http
|
|
171
|
+
\`\`\`
|
|
172
|
+
|
|
173
|
+
The server will start on port 3100 with the following endpoints:
|
|
174
|
+
|
|
175
|
+
- \`/health\`: Health check
|
|
176
|
+
- \`/rpc\`: Request-response messages
|
|
177
|
+
- \`/events\`: SSE stream for real-time updates
|
|
178
|
+
|
|
179
|
+
## Development
|
|
180
|
+
|
|
181
|
+
Type check:
|
|
182
|
+
|
|
183
|
+
\`\`\`bash
|
|
184
|
+
bun run check
|
|
185
|
+
\`\`\`
|
|
186
|
+
|
|
187
|
+
Build:
|
|
188
|
+
|
|
189
|
+
\`\`\`bash
|
|
190
|
+
bun run build
|
|
191
|
+
\`\`\`
|
|
192
|
+
`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function generateEnvExample(vars: TemplateVars): string | null {
|
|
196
|
+
if (!vars.hasWebSearch) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return `# Required for web_search tool
|
|
201
|
+
EXA_API_KEY=your_exa_api_key_here
|
|
202
|
+
`;
|
|
203
|
+
}
|