@townco/agent 0.1.124 → 0.1.126

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@townco/agent",
3
- "version": "0.1.124",
3
+ "version": "0.1.126",
4
4
  "type": "module",
5
5
  "module": "index.ts",
6
6
  "files": [
@@ -83,12 +83,12 @@
83
83
  "@opentelemetry/sdk-trace-base": "^1.28.0",
84
84
  "@opentelemetry/sdk-trace-node": "^1.28.0",
85
85
  "@opentelemetry/semantic-conventions": "^1.28.0",
86
- "@townco/apiclient": "0.0.36",
87
- "@townco/core": "0.0.94",
88
- "@townco/gui-template": "0.1.113",
89
- "@townco/tsconfig": "0.1.113",
90
- "@townco/tui-template": "0.1.113",
91
- "@townco/ui": "0.1.116",
86
+ "@townco/apiclient": "0.0.38",
87
+ "@townco/core": "0.0.96",
88
+ "@townco/gui-template": "0.1.115",
89
+ "@townco/tsconfig": "0.1.115",
90
+ "@townco/tui-template": "0.1.115",
91
+ "@townco/ui": "0.1.118",
92
92
  "ai-tokenizer": "^1.0.6",
93
93
  "exa-js": "^2.0.0",
94
94
  "hono": "^4.10.4",
@@ -4,6 +4,14 @@ import type { AgentDefinition, McpConfigSchema } from "../definition";
4
4
 
5
5
  type McpConfig = z.infer<typeof McpConfigSchema>;
6
6
 
7
+ /** Config for a subagent to wire up via makeSubagentsTool */
8
+ export interface SubagentConfig {
9
+ agentName: string;
10
+ toolDescription: string;
11
+ displayName?: string;
12
+ path: string;
13
+ }
14
+
7
15
  export interface TemplateVars {
8
16
  name: string;
9
17
  model: string;
@@ -24,6 +32,7 @@ export interface TemplateVars {
24
32
  }
25
33
  >;
26
34
  mcps?: McpConfig[];
35
+ subagents?: SubagentConfig[];
27
36
  systemPrompt: string | null;
28
37
  hasWebSearch: boolean;
29
38
  hasGenerateImage: boolean;
@@ -83,6 +92,14 @@ export function getTemplateVars(
83
92
  result.mcps = definition.mcps;
84
93
  }
85
94
 
95
+ // Handle subagents if defined (using type assertion since AgentDefinition may not have subagents yet)
96
+ const defWithSubagents = definition as AgentDefinition & {
97
+ subagents?: SubagentConfig[];
98
+ };
99
+ if (defWithSubagents.subagents && defWithSubagents.subagents.length > 0) {
100
+ result.subagents = defWithSubagents.subagents;
101
+ }
102
+
86
103
  return result;
87
104
  }
88
105
 
@@ -123,41 +140,68 @@ export function generatePackageJson(vars: TemplateVars): string {
123
140
  }
124
141
 
125
142
  export async function generateIndexTs(vars: TemplateVars): Promise<string> {
126
- // Build agent definition with fields in a logical order
127
- const agentDef: Record<string, unknown> = {
128
- model: vars.model,
129
- };
143
+ const hasSubagents = vars.subagents && vars.subagents.length > 0;
130
144
 
145
+ let imports =
146
+ 'import type { AgentDefinition } from "@townco/agent/definition";';
147
+ if (hasSubagents) {
148
+ imports += '\nimport { makeSubagentsTool } from "@townco/agent/utils";';
149
+ }
150
+
151
+ // Build tools code - either plain JSON or with makeSubagentsTool call
152
+ const toolsCode: string = (() => {
153
+ if (!hasSubagents) {
154
+ return JSON.stringify(vars.tools);
155
+ }
156
+ // makeSubagentsTool expects 'description' not 'toolDescription'
157
+ const subagentConfigs =
158
+ vars.subagents?.map((s) => ({
159
+ agentName: s.agentName,
160
+ description: s.toolDescription,
161
+ ...(s.displayName && { displayName: s.displayName }),
162
+ path: s.path,
163
+ })) ?? [];
164
+ const subagentToolCall = `makeSubagentsTool(${JSON.stringify(subagentConfigs, null, 2)})`;
165
+ const toolItems = vars.tools.map((t) => JSON.stringify(t));
166
+ toolItems.push(subagentToolCall);
167
+ return `[${toolItems.join(", ")}]`;
168
+ })();
169
+
170
+ // Build optional fields
171
+ const optionalFields: string[] = [];
131
172
  if (vars.displayName) {
132
- agentDef.displayName = vars.displayName;
173
+ optionalFields.push(`displayName: ${JSON.stringify(vars.displayName)},`);
133
174
  }
134
175
  if (vars.description) {
135
- agentDef.description = vars.description;
176
+ optionalFields.push(`description: ${JSON.stringify(vars.description)},`);
136
177
  }
137
178
  if (vars.suggestedPrompts) {
138
- agentDef.suggestedPrompts = vars.suggestedPrompts;
179
+ optionalFields.push(
180
+ `suggestedPrompts: ${JSON.stringify(vars.suggestedPrompts)},`,
181
+ );
139
182
  }
140
-
141
- agentDef.systemPrompt = vars.systemPrompt;
142
- agentDef.tools = vars.tools;
143
-
144
183
  if (vars.mcps && vars.mcps.length > 0) {
145
- agentDef.mcps = vars.mcps;
184
+ optionalFields.push(`mcps: ${JSON.stringify(vars.mcps)},`);
146
185
  }
147
-
148
186
  if (vars.hooks) {
149
- agentDef.hooks = vars.hooks;
187
+ optionalFields.push(`hooks: ${JSON.stringify(vars.hooks)},`);
150
188
  }
151
189
 
152
- return prettier.format(
153
- `import type { AgentDefinition } from "@townco/agent/definition";
190
+ const optionalFieldsStr =
191
+ optionalFields.length > 0 ? `\n ${optionalFields.join("\n ")}` : "";
154
192
 
155
- const agent: AgentDefinition = ${JSON.stringify(agentDef)};
193
+ const code = `${imports}
194
+
195
+ const agent: AgentDefinition = {
196
+ model: ${JSON.stringify(vars.model)},${optionalFieldsStr}
197
+ systemPrompt: ${JSON.stringify(vars.systemPrompt)},
198
+ tools: ${toolsCode},
199
+ };
156
200
 
157
201
  export default agent;
158
- `,
159
- { parser: "typescript" },
160
- );
202
+ `;
203
+
204
+ return prettier.format(code, { parser: "typescript" });
161
205
  }
162
206
 
163
207
  export function generateBinTs(): string {