@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.
- package/dist/acp-server/adapter.d.ts +14 -10
- package/dist/acp-server/adapter.js +73 -72
- package/dist/acp-server/cli.d.ts +3 -1
- package/dist/acp-server/cli.js +9 -5
- package/dist/acp-server/http.d.ts +3 -1
- package/dist/acp-server/http.js +173 -163
- package/dist/bin.js +0 -0
- package/dist/definition/mcp.d.ts +0 -0
- package/dist/definition/mcp.js +0 -0
- package/dist/definition/tools/todo.d.ts +49 -0
- package/dist/definition/tools/todo.js +80 -0
- package/dist/definition/tools/web_search.d.ts +4 -0
- package/dist/definition/tools/web_search.js +26 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.js +19 -0
- package/dist/index.js +12 -13
- package/dist/runner/agent-runner.js +4 -4
- package/dist/runner/index.d.ts +3 -1
- package/dist/runner/index.js +18 -14
- package/dist/runner/langchain/tools/todo.d.ts +48 -32
- package/dist/runner/langchain/tools/todo.js +16 -13
- package/dist/runner/langchain/tools/web_search.d.ts +1 -1
- package/dist/runner/langchain/tools/web_search.js +21 -18
- package/dist/scaffold/copy-gui.d.ts +1 -1
- package/dist/scaffold/copy-gui.js +22 -113
- package/dist/scaffold/index.d.ts +10 -8
- package/dist/scaffold/index.js +1 -4
- package/dist/storage/index.js +23 -24
- package/dist/templates/index.js +4 -3
- package/dist/test-script.js +12 -11
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -2
- package/templates/index.ts +4 -3
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { tool } from "langchain";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export const todoItemSchema = z.object({
|
|
4
|
+
content: z.string().min(1),
|
|
5
|
+
status: z.enum(["pending", "in_progress", "completed"]),
|
|
6
|
+
activeForm: z.string().min(1),
|
|
7
|
+
});
|
|
8
|
+
export const todoWrite = tool(
|
|
9
|
+
({ todos }) => {
|
|
10
|
+
// Simple implementation that confirms the todos were written
|
|
11
|
+
return `Successfully updated todo list with ${todos.length} items`;
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "todo_write",
|
|
15
|
+
description: `Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
|
|
16
|
+
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
17
|
+
|
|
18
|
+
## When to Use This Tool
|
|
19
|
+
Use this tool proactively in these scenarios:
|
|
20
|
+
|
|
21
|
+
1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
|
|
22
|
+
2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
|
|
23
|
+
3. User explicitly requests todo list - When the user directly asks you to use the todo list
|
|
24
|
+
4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
|
|
25
|
+
5. After receiving new instructions - Immediately capture user requirements as todos
|
|
26
|
+
6. When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
|
|
27
|
+
7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
|
|
28
|
+
|
|
29
|
+
## When NOT to Use This Tool
|
|
30
|
+
|
|
31
|
+
Skip using this tool when:
|
|
32
|
+
1. There is only a single, straightforward task
|
|
33
|
+
2. The task is trivial and tracking it provides no organizational benefit
|
|
34
|
+
3. The task can be completed in less than 3 trivial steps
|
|
35
|
+
4. The task is purely conversational or informational
|
|
36
|
+
|
|
37
|
+
NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
|
|
38
|
+
|
|
39
|
+
## Task States and Management
|
|
40
|
+
|
|
41
|
+
1. **Task States**: Use these states to track progress:
|
|
42
|
+
- pending: Task not yet started
|
|
43
|
+
- in_progress: Currently working on (limit to ONE task at a time)
|
|
44
|
+
- completed: Task finished successfully
|
|
45
|
+
|
|
46
|
+
**IMPORTANT**: Task descriptions must have two forms:
|
|
47
|
+
- content: The imperative form describing what needs to be done (e.g., "Run tests", "Build the project")
|
|
48
|
+
- activeForm: The present continuous form shown during execution (e.g., "Running tests", "Building the project")
|
|
49
|
+
|
|
50
|
+
2. **Task Management**:
|
|
51
|
+
- Update task status in real-time as you work
|
|
52
|
+
- Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
|
|
53
|
+
- Exactly ONE task must be in_progress at any time (not less, not more)
|
|
54
|
+
- Complete current tasks before starting new ones
|
|
55
|
+
- Remove tasks that are no longer relevant from the list entirely
|
|
56
|
+
|
|
57
|
+
3. **Task Completion Requirements**:
|
|
58
|
+
- ONLY mark a task as completed when you have FULLY accomplished it
|
|
59
|
+
- If you encounter errors, blockers, or cannot finish, keep the task as in_progress
|
|
60
|
+
- When blocked, create a new task describing what needs to be resolved
|
|
61
|
+
- Never mark a task as completed if:
|
|
62
|
+
- Tests are failing
|
|
63
|
+
- Implementation is partial
|
|
64
|
+
- You encountered unresolved errors
|
|
65
|
+
- You couldn't find necessary files or dependencies
|
|
66
|
+
|
|
67
|
+
4. **Task Breakdown**:
|
|
68
|
+
- Create specific, actionable items
|
|
69
|
+
- Break complex tasks into smaller, manageable steps
|
|
70
|
+
- Use clear, descriptive task names
|
|
71
|
+
- Always provide both forms:
|
|
72
|
+
- content: "Fix authentication bug"
|
|
73
|
+
- activeForm: "Fixing authentication bug"
|
|
74
|
+
|
|
75
|
+
When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.`,
|
|
76
|
+
schema: z.object({
|
|
77
|
+
todos: z.array(todoItemSchema),
|
|
78
|
+
}),
|
|
79
|
+
},
|
|
80
|
+
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ExaSearchResults } from "@langchain/exa";
|
|
2
|
+
import Exa from "exa-js";
|
|
3
|
+
|
|
4
|
+
let _webSearchInstance = null;
|
|
5
|
+
export function makeWebSearchTool() {
|
|
6
|
+
if (_webSearchInstance) {
|
|
7
|
+
return _webSearchInstance;
|
|
8
|
+
}
|
|
9
|
+
const apiKey = process.env.EXA_API_KEY;
|
|
10
|
+
if (!apiKey) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"EXA_API_KEY environment variable is required to use the web_search tool. " +
|
|
13
|
+
"Please set it to your Exa API key from https://exa.ai",
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const client = new Exa(apiKey);
|
|
17
|
+
_webSearchInstance = new ExaSearchResults({
|
|
18
|
+
client,
|
|
19
|
+
searchArgs: {
|
|
20
|
+
numResults: 5,
|
|
21
|
+
type: "auto",
|
|
22
|
+
text: true,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
return _webSearchInstance;
|
|
26
|
+
}
|
package/dist/example.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { makeHttpTransport, makeStdioTransport } from "./acp-server/index.js";
|
|
3
|
+
|
|
4
|
+
const exampleAgent = {
|
|
5
|
+
model: "claude-sonnet-4-5-20250929",
|
|
6
|
+
systemPrompt: "You are a helpful assistant.",
|
|
7
|
+
tools: ["todo_write", "get_weather", "web_search"],
|
|
8
|
+
};
|
|
9
|
+
// Parse transport type from command line argument
|
|
10
|
+
const transport = process.argv[2] || "stdio";
|
|
11
|
+
if (transport === "http") {
|
|
12
|
+
makeHttpTransport(exampleAgent);
|
|
13
|
+
} else if (transport === "stdio") {
|
|
14
|
+
makeStdioTransport(exampleAgent);
|
|
15
|
+
} else {
|
|
16
|
+
console.error(`Invalid transport: ${transport}`);
|
|
17
|
+
console.error("Usage: bun run example.ts [stdio|http]");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { makeHttpTransport, makeStdioTransport } from "./acp-server";
|
|
2
|
+
|
|
2
3
|
const exampleAgent = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
model: "claude-sonnet-4-5-20250929",
|
|
5
|
+
systemPrompt: "You are a helpful assistant.",
|
|
6
|
+
tools: ["todo_write", "get_weather", "web_search"],
|
|
7
|
+
mcps: [],
|
|
7
8
|
};
|
|
8
9
|
// Parse transport type from command line argument
|
|
9
10
|
const transport = process.argv[2] || "stdio";
|
|
10
11
|
if (transport === "http") {
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
console.error("Usage: bun run index.ts [stdio|http]");
|
|
19
|
-
process.exit(1);
|
|
12
|
+
makeHttpTransport(exampleAgent);
|
|
13
|
+
} else if (transport === "stdio") {
|
|
14
|
+
makeStdioTransport(exampleAgent);
|
|
15
|
+
} else {
|
|
16
|
+
console.error(`Invalid transport: ${transport}`);
|
|
17
|
+
console.error("Usage: bun run index.ts [stdio|http]");
|
|
18
|
+
process.exit(1);
|
|
20
19
|
}
|
|
@@ -2,8 +2,8 @@ import { z } from "zod";
|
|
|
2
2
|
import { McpConfigSchema } from "../definition";
|
|
3
3
|
import { zToolType } from "./tools";
|
|
4
4
|
export const zAgentRunnerParams = z.object({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
systemPrompt: z.string().nullable(),
|
|
6
|
+
model: z.string(),
|
|
7
|
+
tools: z.array(zToolType).optional(),
|
|
8
|
+
mcps: z.array(McpConfigSchema).optional(),
|
|
9
9
|
});
|
package/dist/runner/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { AgentDefinition } from "../definition";
|
|
2
2
|
import { type AgentRunner } from "./agent-runner";
|
|
3
3
|
export type { AgentRunner };
|
|
4
|
-
export declare const makeRunnerFromDefinition: (
|
|
4
|
+
export declare const makeRunnerFromDefinition: (
|
|
5
|
+
definition: AgentDefinition,
|
|
6
|
+
) => AgentRunner;
|
package/dist/runner/index.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { zAgentRunnerParams } from "./agent-runner";
|
|
2
2
|
import { LangchainAgent } from "./langchain";
|
|
3
3
|
export const makeRunnerFromDefinition = (definition) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
const agentRunnerParams = zAgentRunnerParams.safeParse(definition);
|
|
5
|
+
if (!agentRunnerParams.success) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
`Invalid agent definition: ${agentRunnerParams.error.message}`,
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
switch (definition.harnessImplementation) {
|
|
11
|
+
case undefined:
|
|
12
|
+
case "langchain": {
|
|
13
|
+
return new LangchainAgent(agentRunnerParams.data);
|
|
14
|
+
}
|
|
15
|
+
default: {
|
|
16
|
+
const _exhaustiveCheck = definition.harnessImplementation;
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Unsupported harness implementation: ${definition.harnessImplementation}`,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
18
22
|
};
|
|
@@ -1,33 +1,49 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export declare const todoItemSchema: z.ZodObject<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
2
|
+
export declare const todoItemSchema: z.ZodObject<
|
|
3
|
+
{
|
|
4
|
+
content: z.ZodString;
|
|
5
|
+
status: z.ZodEnum<{
|
|
6
|
+
pending: "pending";
|
|
7
|
+
in_progress: "in_progress";
|
|
8
|
+
completed: "completed";
|
|
9
|
+
}>;
|
|
10
|
+
activeForm: z.ZodString;
|
|
11
|
+
},
|
|
12
|
+
z.core.$strip
|
|
13
|
+
>;
|
|
14
|
+
export declare const todoWrite: import("langchain").DynamicStructuredTool<
|
|
15
|
+
z.ZodObject<
|
|
16
|
+
{
|
|
17
|
+
todos: z.ZodArray<
|
|
18
|
+
z.ZodObject<
|
|
19
|
+
{
|
|
20
|
+
content: z.ZodString;
|
|
21
|
+
status: z.ZodEnum<{
|
|
22
|
+
pending: "pending";
|
|
23
|
+
in_progress: "in_progress";
|
|
24
|
+
completed: "completed";
|
|
25
|
+
}>;
|
|
26
|
+
activeForm: z.ZodString;
|
|
27
|
+
},
|
|
28
|
+
z.core.$strip
|
|
29
|
+
>
|
|
30
|
+
>;
|
|
31
|
+
},
|
|
32
|
+
z.core.$strip
|
|
33
|
+
>,
|
|
34
|
+
{
|
|
35
|
+
todos: {
|
|
36
|
+
content: string;
|
|
37
|
+
status: "pending" | "in_progress" | "completed";
|
|
38
|
+
activeForm: string;
|
|
39
|
+
}[];
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
todos: {
|
|
43
|
+
content: string;
|
|
44
|
+
status: "pending" | "in_progress" | "completed";
|
|
45
|
+
activeForm: string;
|
|
46
|
+
}[];
|
|
47
|
+
},
|
|
48
|
+
string
|
|
49
|
+
>;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { tool } from "langchain";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
export const todoItemSchema = z.object({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
content: z.string().min(1),
|
|
5
|
+
status: z.enum(["pending", "in_progress", "completed"]),
|
|
6
|
+
activeForm: z.string().min(1),
|
|
7
7
|
});
|
|
8
|
-
export const todoWrite = tool(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export const todoWrite = tool(
|
|
9
|
+
({ todos }) => {
|
|
10
|
+
// Simple implementation that confirms the todos were written
|
|
11
|
+
return `Successfully updated todo list with ${todos.length} items`;
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "todo_write",
|
|
15
|
+
description: `Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
|
|
14
16
|
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
15
17
|
|
|
16
18
|
## When to Use This Tool
|
|
@@ -71,7 +73,8 @@ NOTE that you should not use this tool if there is only one trivial task to do.
|
|
|
71
73
|
- activeForm: "Fixing authentication bug"
|
|
72
74
|
|
|
73
75
|
When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.`,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
76
|
+
schema: z.object({
|
|
77
|
+
todos: z.array(todoItemSchema),
|
|
78
|
+
}),
|
|
79
|
+
},
|
|
80
|
+
);
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import { ExaSearchResults } from "@langchain/exa";
|
|
2
2
|
import Exa from "exa-js";
|
|
3
|
+
|
|
3
4
|
let _webSearchInstance = null;
|
|
4
5
|
export function makeWebSearchTool() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
if (_webSearchInstance) {
|
|
7
|
+
return _webSearchInstance;
|
|
8
|
+
}
|
|
9
|
+
const apiKey = process.env.EXA_API_KEY;
|
|
10
|
+
if (!apiKey) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"EXA_API_KEY environment variable is required to use the web_search tool. " +
|
|
13
|
+
"Please set it to your Exa API key from https://exa.ai",
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const client = new Exa(apiKey);
|
|
17
|
+
_webSearchInstance = new ExaSearchResults({
|
|
18
|
+
client,
|
|
19
|
+
searchArgs: {
|
|
20
|
+
numResults: 5,
|
|
21
|
+
type: "auto",
|
|
22
|
+
text: true,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
return _webSearchInstance;
|
|
23
26
|
}
|
|
@@ -1,42 +1,38 @@
|
|
|
1
1
|
import { cp, mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import { dirname, join } from "node:path";
|
|
3
|
-
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
4
5
|
/**
|
|
5
|
-
* Get the
|
|
6
|
+
* Get the GUI template from @townco/gui-template npm package
|
|
6
7
|
*/
|
|
7
8
|
function getGuiSourceDir() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function getUiSourceDir() {
|
|
16
|
-
const currentFile = fileURLToPath(import.meta.url);
|
|
17
|
-
// scaffold/copy-gui.ts -> scaffold -> packages/agent -> packages -> ui
|
|
18
|
-
return join(dirname(currentFile), "..", "..", "ui");
|
|
9
|
+
try {
|
|
10
|
+
const packagePath = require.resolve("@townco/gui-template/package.json");
|
|
11
|
+
return dirname(packagePath);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
throw new Error("Could not find @townco/gui-template. Please ensure it is installed.");
|
|
15
|
+
}
|
|
19
16
|
}
|
|
20
17
|
/**
|
|
21
|
-
* Copy GUI app to the agent directory
|
|
18
|
+
* Copy GUI app to the agent directory from @townco/gui-template
|
|
22
19
|
*/
|
|
23
20
|
export async function copyGuiApp(agentPath) {
|
|
24
|
-
const sourceDir = getGuiSourceDir();
|
|
25
21
|
const guiDir = join(agentPath, "gui");
|
|
26
22
|
// Create gui directory
|
|
27
23
|
await mkdir(guiDir, { recursive: true });
|
|
28
|
-
//
|
|
29
|
-
const
|
|
24
|
+
// Get GUI source from @townco/gui-template npm package
|
|
25
|
+
const sourceDir = getGuiSourceDir();
|
|
26
|
+
const itemsToCopy = [
|
|
27
|
+
"src",
|
|
28
|
+
"index.html",
|
|
29
|
+
"postcss.config.js",
|
|
30
|
+
"vite.config.ts",
|
|
31
|
+
];
|
|
30
32
|
for (const item of itemsToCopy) {
|
|
31
33
|
const sourcePath = join(sourceDir, item);
|
|
32
34
|
const targetPath = join(guiDir, item);
|
|
33
|
-
|
|
34
|
-
await cp(sourcePath, targetPath, { recursive: true });
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
// Item might not exist, that's okay
|
|
38
|
-
console.warn(`Warning: Could not copy ${item}:`, error);
|
|
39
|
-
}
|
|
35
|
+
await cp(sourcePath, targetPath, { recursive: true });
|
|
40
36
|
}
|
|
41
37
|
// Create a standalone tsconfig.json for the GUI (can't extend from workspace tsconfig)
|
|
42
38
|
const guiTsConfig = {
|
|
@@ -74,65 +70,8 @@ export async function copyGuiApp(agentPath) {
|
|
|
74
70
|
exclude: ["node_modules", "dist"],
|
|
75
71
|
};
|
|
76
72
|
await writeFile(join(guiDir, "tsconfig.json"), JSON.stringify(guiTsConfig, null, 2));
|
|
77
|
-
// Create a custom vite.config.ts with path aliases
|
|
78
|
-
const viteConfig = `import { defineConfig } from "vite";
|
|
79
|
-
import react from "@vitejs/plugin-react";
|
|
80
|
-
import { resolve } from "path";
|
|
81
|
-
|
|
82
|
-
export default defineConfig({
|
|
83
|
-
plugins: [react()],
|
|
84
|
-
resolve: {
|
|
85
|
-
alias: {
|
|
86
|
-
"@townco/ui": resolve(__dirname, "./ui/src"),
|
|
87
|
-
// Exclude Node.js-only modules from browser bundle
|
|
88
|
-
"node:child_process": resolve(__dirname, "./polyfills/child_process.js"),
|
|
89
|
-
"node:stream": resolve(__dirname, "./polyfills/stream.js"),
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
optimizeDeps: {
|
|
93
|
-
exclude: ["node:child_process", "node:stream"],
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
`;
|
|
97
|
-
await writeFile(join(guiDir, "vite.config.ts"), viteConfig);
|
|
98
|
-
// Create polyfills directory with stub modules for Node.js-only imports
|
|
99
|
-
const polyfillsDir = join(guiDir, "polyfills");
|
|
100
|
-
await mkdir(polyfillsDir, { recursive: true });
|
|
101
|
-
// Provide stub exports for child_process module
|
|
102
|
-
const childProcessPolyfill = `// Polyfill for node:child_process (browser-incompatible)
|
|
103
|
-
export const spawn = () => {
|
|
104
|
-
throw new Error('child_process.spawn is not available in the browser');
|
|
105
|
-
};
|
|
106
|
-
export class ChildProcess {}
|
|
107
|
-
export default { spawn, ChildProcess };
|
|
108
|
-
`;
|
|
109
|
-
await writeFile(join(polyfillsDir, "child_process.js"), childProcessPolyfill);
|
|
110
|
-
// Provide stub exports for stream module
|
|
111
|
-
const streamPolyfill = `// Polyfill for node:stream (browser-incompatible)
|
|
112
|
-
export class Readable {
|
|
113
|
-
constructor() {
|
|
114
|
-
throw new Error('stream.Readable is not available in the browser');
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
export class Writable {
|
|
118
|
-
constructor() {
|
|
119
|
-
throw new Error('stream.Writable is not available in the browser');
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
export class Duplex {
|
|
123
|
-
constructor() {
|
|
124
|
-
throw new Error('stream.Duplex is not available in the browser');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
export class Transform {
|
|
128
|
-
constructor() {
|
|
129
|
-
throw new Error('stream.Transform is not available in the browser');
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
export default { Readable, Writable, Duplex, Transform };
|
|
133
|
-
`;
|
|
134
|
-
await writeFile(join(polyfillsDir, "stream.js"), streamPolyfill);
|
|
135
73
|
// Generate a custom package.json for the GUI
|
|
74
|
+
// Use @townco/ui as a dependency instead of copying files
|
|
136
75
|
const packageJson = {
|
|
137
76
|
name: "agent-gui",
|
|
138
77
|
version: "0.0.1",
|
|
@@ -144,6 +83,7 @@ export default { Readable, Writable, Duplex, Transform };
|
|
|
144
83
|
preview: "vite preview",
|
|
145
84
|
},
|
|
146
85
|
dependencies: {
|
|
86
|
+
"@townco/ui": "^0.1.0",
|
|
147
87
|
"@agentclientprotocol/sdk": "^0.5.1",
|
|
148
88
|
"@radix-ui/react-dialog": "^1.1.15",
|
|
149
89
|
"@radix-ui/react-label": "^2.1.8",
|
|
@@ -174,35 +114,4 @@ export default { Readable, Writable, Duplex, Transform };
|
|
|
174
114
|
},
|
|
175
115
|
};
|
|
176
116
|
await writeFile(join(guiDir, "package.json"), JSON.stringify(packageJson, null, 2));
|
|
177
|
-
// Copy UI package components and styles
|
|
178
|
-
const uiSourceDir = getUiSourceDir();
|
|
179
|
-
const uiTargetDir = join(guiDir, "ui");
|
|
180
|
-
await mkdir(uiTargetDir, { recursive: true });
|
|
181
|
-
// Copy the entire UI src directory (which includes styles)
|
|
182
|
-
const sourcePath = join(uiSourceDir, "src");
|
|
183
|
-
const targetPath = join(uiTargetDir, "src");
|
|
184
|
-
try {
|
|
185
|
-
await cp(sourcePath, targetPath, { recursive: true });
|
|
186
|
-
}
|
|
187
|
-
catch (error) {
|
|
188
|
-
console.warn(`Warning: Could not copy UI src:`, error);
|
|
189
|
-
}
|
|
190
|
-
// Create a tsconfig for the ui directory
|
|
191
|
-
const uiTsConfig = {
|
|
192
|
-
compilerOptions: {
|
|
193
|
-
target: "ESNext",
|
|
194
|
-
module: "ESNext",
|
|
195
|
-
jsx: "react-jsx",
|
|
196
|
-
moduleResolution: "bundler",
|
|
197
|
-
lib: ["ESNext", "DOM", "DOM.Iterable"],
|
|
198
|
-
strict: true,
|
|
199
|
-
esModuleInterop: true,
|
|
200
|
-
skipLibCheck: true,
|
|
201
|
-
forceConsistentCasingInFileNames: true,
|
|
202
|
-
resolveJsonModule: true,
|
|
203
|
-
allowSyntheticDefaultImports: true,
|
|
204
|
-
},
|
|
205
|
-
include: ["**/*.ts", "**/*.tsx"],
|
|
206
|
-
};
|
|
207
|
-
await writeFile(join(uiTargetDir, "tsconfig.json"), JSON.stringify(uiTsConfig, null, 2));
|
|
208
117
|
}
|
package/dist/scaffold/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type { AgentDefinition } from "../definition";
|
|
2
2
|
export interface ScaffoldOptions {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
name: string;
|
|
4
|
+
definition: AgentDefinition;
|
|
5
|
+
overwrite?: boolean;
|
|
6
|
+
includeGui?: boolean;
|
|
7
7
|
}
|
|
8
8
|
export interface ScaffoldResult {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
success: boolean;
|
|
10
|
+
path: string;
|
|
11
|
+
error?: string;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Scaffold a new agent package
|
|
15
15
|
*/
|
|
16
|
-
export declare function scaffoldAgent(
|
|
16
|
+
export declare function scaffoldAgent(
|
|
17
|
+
options: ScaffoldOptions,
|
|
18
|
+
): Promise<ScaffoldResult>;
|
package/dist/scaffold/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { chmod, mkdir, writeFile } from "node:fs/promises";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { agentExists, ensureAgentsDir, getAgentPath } from "../storage";
|
|
5
5
|
import { generateAgentJson, generateBinTs, generateEnvExample, generateGitignore, generateIndexTs, generatePackageJson, generateReadme, generateTsConfig, getTemplateVars, } from "../templates";
|
|
6
|
-
import { bundleAgentDependencies } from "./bundle";
|
|
7
6
|
import { copyGuiApp } from "./copy-gui";
|
|
8
7
|
/**
|
|
9
8
|
* Scaffold a new agent package
|
|
@@ -50,8 +49,6 @@ export async function scaffoldAgent(options) {
|
|
|
50
49
|
await chmod(filePath, 0o755);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
|
-
// Bundle agent dependencies (copy lib files)
|
|
54
|
-
await bundleAgentDependencies(agentPath);
|
|
55
52
|
// Copy GUI app if requested
|
|
56
53
|
if (includeGui) {
|
|
57
54
|
await copyGuiApp(agentPath);
|
|
@@ -59,7 +56,7 @@ export async function scaffoldAgent(options) {
|
|
|
59
56
|
const guiPath = join(agentPath, "gui");
|
|
60
57
|
await runBunInstall(guiPath);
|
|
61
58
|
}
|
|
62
|
-
// Run bun install in agent root
|
|
59
|
+
// Run bun install in agent root to fetch dependencies from npm
|
|
63
60
|
await runBunInstall(agentPath);
|
|
64
61
|
return {
|
|
65
62
|
success: true,
|