@townco/agent 0.1.13 → 0.1.15

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.
@@ -1,58 +1,57 @@
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
+
4
5
  const AGENTS_DIR = join(homedir(), ".config", "town", "agents");
5
6
  /**
6
7
  * Get the base directory where all agents are stored
7
8
  */
8
9
  export function getAgentsDir() {
9
- return AGENTS_DIR;
10
+ return AGENTS_DIR;
10
11
  }
11
12
  /**
12
13
  * Get the directory path for a specific agent
13
14
  */
14
15
  export function getAgentPath(name) {
15
- return join(AGENTS_DIR, name);
16
+ return join(AGENTS_DIR, name);
16
17
  }
17
18
  /**
18
19
  * Check if an agent exists
19
20
  */
20
21
  export async function agentExists(name) {
21
- try {
22
- const agentPath = getAgentPath(name);
23
- const stats = await stat(agentPath);
24
- return stats.isDirectory();
25
- }
26
- catch {
27
- return false;
28
- }
22
+ try {
23
+ const agentPath = getAgentPath(name);
24
+ const stats = await stat(agentPath);
25
+ return stats.isDirectory();
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
- 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
- }
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
+ } catch (error) {
41
+ console.error("Error listing agents:", error);
42
+ return [];
43
+ }
45
44
  }
46
45
  /**
47
46
  * Delete an agent
48
47
  */
49
48
  export async function deleteAgent(name) {
50
- const agentPath = getAgentPath(name);
51
- await rm(agentPath, { recursive: true, force: true });
49
+ const agentPath = getAgentPath(name);
50
+ await rm(agentPath, { recursive: true, force: true });
52
51
  }
53
52
  /**
54
53
  * Ensure the agents directory exists
55
54
  */
56
55
  export async function ensureAgentsDir() {
57
- await mkdir(AGENTS_DIR, { recursive: true });
56
+ await mkdir(AGENTS_DIR, { recursive: true });
58
57
  }
@@ -9,8 +9,9 @@ export function getTemplateVars(name, definition) {
9
9
  };
10
10
  }
11
11
  export function generatePackageJson(vars) {
12
- // Include all dependencies since the bundled lib/runner includes all tool implementations
12
+ // Include @townco/agent as a dependency instead of bundling
13
13
  const dependencies = {
14
+ "@townco/agent": "^0.1.14",
14
15
  "@agentclientprotocol/sdk": "^0.5.1",
15
16
  "@langchain/anthropic": "^1.0.0",
16
17
  "@langchain/core": "^1.0.3",
@@ -43,8 +44,8 @@ export function generatePackageJson(vars) {
43
44
  export function generateIndexTs() {
44
45
  return `import { readFileSync } from "node:fs";
45
46
  import { join } from "node:path";
46
- import { makeHttpTransport, makeStdioTransport } from "./lib/acp-server/index.js";
47
- import type { AgentDefinition } from "./lib/definition/index.js";
47
+ import { makeHttpTransport, makeStdioTransport } from "@townco/agent/acp-server";
48
+ import type { AgentDefinition } from "@townco/agent/definition";
48
49
 
49
50
  // Load agent definition from JSON file
50
51
  const configPath = join(import.meta.dir, "agent.json");
@@ -1,17 +1,18 @@
1
1
  import { LangchainAgent } from "./runner/langchain";
2
+
2
3
  const agent = new LangchainAgent({
3
- model: "claude-sonnet-4-5-20250929",
4
- systemPrompt: "You are a helpful assistant.",
5
- tools: ["todo_write"],
4
+ model: "claude-sonnet-4-5-20250929",
5
+ systemPrompt: "You are a helpful assistant.",
6
+ tools: ["todo_write"],
6
7
  });
7
8
  for await (const event of agent.invoke({
8
- prompt: [
9
- {
10
- type: "text",
11
- text: "Whats the weather in Tokyo?",
12
- },
13
- ],
14
- sessionId: "test-session",
9
+ prompt: [
10
+ {
11
+ type: "text",
12
+ text: "Whats the weather in Tokyo?",
13
+ },
14
+ ],
15
+ sessionId: "test-session",
15
16
  })) {
16
- console.log(event);
17
+ console.log(event);
17
18
  }