@townco/agent 0.1.44 → 0.1.46
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 +1 -0
- package/dist/acp-server/adapter.js +130 -9
- package/dist/acp-server/cli.d.ts +3 -1
- package/dist/acp-server/session-storage.d.ts +21 -1
- package/dist/acp-server/session-storage.js +19 -1
- package/dist/bin.js +0 -0
- package/dist/definition/index.d.ts +19 -0
- package/dist/definition/index.js +11 -0
- package/dist/definition/mcp.js +0 -1
- 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/dev-agent/index.d.ts +2 -0
- package/dist/dev-agent/index.js +18 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.js +19 -0
- package/dist/index.js +13 -2
- package/dist/runner/agent-runner.d.ts +28 -2
- package/dist/runner/agent-runner.js +2 -1
- package/dist/runner/hooks/constants.d.ts +9 -0
- package/dist/runner/hooks/constants.js +19 -0
- package/dist/runner/hooks/executor.d.ts +23 -0
- package/dist/runner/hooks/executor.js +163 -0
- package/dist/runner/hooks/index.d.ts +5 -0
- package/dist/runner/hooks/index.js +5 -0
- package/dist/runner/hooks/loader.d.ts +5 -0
- package/dist/runner/hooks/loader.js +49 -0
- package/dist/runner/hooks/predefined/compaction-tool.d.ts +6 -0
- package/dist/runner/hooks/predefined/compaction-tool.js +42 -0
- package/dist/runner/hooks/registry.d.ts +14 -0
- package/dist/runner/hooks/registry.js +20 -0
- package/dist/runner/hooks/types.d.ts +144 -0
- package/dist/runner/hooks/types.js +33 -0
- package/dist/runner/index.d.ts +3 -1
- package/dist/runner/langchain/index.js +16 -10
- package/dist/runner/langchain/model-factory.js +3 -1
- package/dist/scaffold/claude-scaffold.js +8 -6
- package/dist/storage/index.js +3 -1
- package/dist/templates/index.d.ts +7 -0
- package/dist/templates/index.js +7 -2
- package/dist/test-script.js +3 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +14 -2
- package/package.json +5 -5
- package/templates/index.ts +14 -2
- package/dist/acp-server/test-acp-summarize.d.ts +0 -7
- package/dist/acp-server/test-acp-summarize.js +0 -127
- package/dist/acp-server/test-summarizer.d.ts +0 -7
- package/dist/acp-server/test-summarizer.js +0 -170
- package/dist/acp-server/tool-summarizer.d.ts +0 -125
- package/dist/acp-server/tool-summarizer.js +0 -182
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
* Anthropic API tool call format
|
|
4
|
-
*/
|
|
5
|
-
export const AnthropicToolCallSchema = z.object({
|
|
6
|
-
id: z.string(),
|
|
7
|
-
type: z.literal("tool_use"),
|
|
8
|
-
name: z.string(),
|
|
9
|
-
input: z.record(z.string(), z.unknown()),
|
|
10
|
-
});
|
|
11
|
-
/**
|
|
12
|
-
* Anthropic API content block format
|
|
13
|
-
*/
|
|
14
|
-
export const AnthropicContentBlockSchema = z.discriminatedUnion("type", [
|
|
15
|
-
z.object({
|
|
16
|
-
type: z.literal("text"),
|
|
17
|
-
text: z.string(),
|
|
18
|
-
}),
|
|
19
|
-
AnthropicToolCallSchema,
|
|
20
|
-
z.object({
|
|
21
|
-
type: z.literal("tool_result"),
|
|
22
|
-
tool_use_id: z.string(),
|
|
23
|
-
content: z.union([
|
|
24
|
-
z.string(),
|
|
25
|
-
z.array(z.object({
|
|
26
|
-
type: z.literal("text"),
|
|
27
|
-
text: z.string(),
|
|
28
|
-
})),
|
|
29
|
-
]),
|
|
30
|
-
is_error: z.boolean().optional(),
|
|
31
|
-
}),
|
|
32
|
-
]);
|
|
33
|
-
/**
|
|
34
|
-
* Anthropic API message format
|
|
35
|
-
*/
|
|
36
|
-
export const AnthropicMessageSchema = z.object({
|
|
37
|
-
role: z.enum(["user", "assistant"]),
|
|
38
|
-
content: z.union([z.string(), z.array(AnthropicContentBlockSchema)]),
|
|
39
|
-
});
|
|
40
|
-
/**
|
|
41
|
-
* Anthropic API request format
|
|
42
|
-
*/
|
|
43
|
-
export const AnthropicRequestSchema = z.object({
|
|
44
|
-
model: z.string().optional(),
|
|
45
|
-
messages: z.array(AnthropicMessageSchema),
|
|
46
|
-
max_tokens: z.number().optional(),
|
|
47
|
-
temperature: z.number().optional(),
|
|
48
|
-
tools: z.array(z.any()).optional(),
|
|
49
|
-
system: z.union([z.string(), z.array(z.any())]).optional(),
|
|
50
|
-
});
|
|
51
|
-
/**
|
|
52
|
-
* Extract tool calls from Anthropic API messages
|
|
53
|
-
*/
|
|
54
|
-
export function extractToolCalls(messages) {
|
|
55
|
-
const summaries = [];
|
|
56
|
-
const toolResultsMap = new Map();
|
|
57
|
-
// First pass: collect all tool results
|
|
58
|
-
for (const message of messages) {
|
|
59
|
-
if (typeof message.content === "string")
|
|
60
|
-
continue;
|
|
61
|
-
for (const block of message.content) {
|
|
62
|
-
if (block.type === "tool_result") {
|
|
63
|
-
const content = typeof block.content === "string"
|
|
64
|
-
? block.content
|
|
65
|
-
: block.content.map((c) => c.text).join("\n");
|
|
66
|
-
toolResultsMap.set(block.tool_use_id, {
|
|
67
|
-
content,
|
|
68
|
-
isError: block.is_error ?? false,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// Second pass: collect all tool calls and match with results
|
|
74
|
-
for (const message of messages) {
|
|
75
|
-
if (typeof message.content === "string")
|
|
76
|
-
continue;
|
|
77
|
-
for (const block of message.content) {
|
|
78
|
-
if (block.type === "tool_use") {
|
|
79
|
-
const result = toolResultsMap.get(block.id);
|
|
80
|
-
const summary = {
|
|
81
|
-
id: block.id,
|
|
82
|
-
name: block.name,
|
|
83
|
-
description: generateToolDescription(block.name, block.input),
|
|
84
|
-
input: block.input,
|
|
85
|
-
output: result?.content ?? undefined,
|
|
86
|
-
status: result
|
|
87
|
-
? result.isError
|
|
88
|
-
? "error"
|
|
89
|
-
: "completed"
|
|
90
|
-
: "pending",
|
|
91
|
-
error: result?.isError ? result.content : undefined,
|
|
92
|
-
};
|
|
93
|
-
summaries.push(summary);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return summaries;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Generate a human-readable description for a tool call
|
|
101
|
-
*/
|
|
102
|
-
function generateToolDescription(toolName, input) {
|
|
103
|
-
switch (toolName) {
|
|
104
|
-
case "read_file":
|
|
105
|
-
return `Reading file: ${input.target_file || "unknown"}`;
|
|
106
|
-
case "write":
|
|
107
|
-
return `Writing file: ${input.file_path || "unknown"}`;
|
|
108
|
-
case "search_replace":
|
|
109
|
-
return `Editing file: ${input.file_path || "unknown"}`;
|
|
110
|
-
case "grep":
|
|
111
|
-
return `Searching for: "${input.pattern || "unknown"}"`;
|
|
112
|
-
case "codebase_search":
|
|
113
|
-
return `Semantic search: "${input.query || "unknown"}"`;
|
|
114
|
-
case "run_terminal_cmd":
|
|
115
|
-
return `Running command: ${input.command || "unknown"}`;
|
|
116
|
-
case "list_dir":
|
|
117
|
-
return `Listing directory: ${input.target_directory || "unknown"}`;
|
|
118
|
-
case "glob_file_search":
|
|
119
|
-
return `Finding files: ${input.glob_pattern || "unknown"}`;
|
|
120
|
-
case "delete_file":
|
|
121
|
-
return `Deleting file: ${input.target_file || "unknown"}`;
|
|
122
|
-
case "todo_write":
|
|
123
|
-
return `Updating TODO list (${input.todos?.length || 0} items)`;
|
|
124
|
-
default:
|
|
125
|
-
return `${toolName}(${Object.keys(input).join(", ")})`;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Generate a summary of tool calls for the entire conversation
|
|
130
|
-
*/
|
|
131
|
-
export function summarizeToolCalls(request) {
|
|
132
|
-
const summaries = extractToolCalls(request.messages);
|
|
133
|
-
const byStatus = {
|
|
134
|
-
pending: 0,
|
|
135
|
-
completed: 0,
|
|
136
|
-
error: 0,
|
|
137
|
-
};
|
|
138
|
-
const byTool = {};
|
|
139
|
-
for (const summary of summaries) {
|
|
140
|
-
byStatus[summary.status] = (byStatus[summary.status] || 0) + 1;
|
|
141
|
-
byTool[summary.name] = (byTool[summary.name] || 0) + 1;
|
|
142
|
-
}
|
|
143
|
-
return {
|
|
144
|
-
total: summaries.length,
|
|
145
|
-
byStatus,
|
|
146
|
-
byTool,
|
|
147
|
-
summaries,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Generate a text summary of tool calls
|
|
152
|
-
*/
|
|
153
|
-
export function generateTextSummary(summaries, options) {
|
|
154
|
-
if (summaries.length === 0) {
|
|
155
|
-
return "No tool calls in this conversation.";
|
|
156
|
-
}
|
|
157
|
-
const { includeDetails = false, maxLength = 1000 } = options || {};
|
|
158
|
-
let text = `Found ${summaries.length} tool call(s):\n\n`;
|
|
159
|
-
for (const summary of summaries) {
|
|
160
|
-
const statusEmoji = summary.status === "completed"
|
|
161
|
-
? "✓"
|
|
162
|
-
: summary.status === "error"
|
|
163
|
-
? "✗"
|
|
164
|
-
: "⋯";
|
|
165
|
-
text += `${statusEmoji} ${summary.description}\n`;
|
|
166
|
-
if (includeDetails) {
|
|
167
|
-
if (summary.output) {
|
|
168
|
-
const outputPreview = summary.output.length > 100
|
|
169
|
-
? `${summary.output.slice(0, 100)}...`
|
|
170
|
-
: summary.output;
|
|
171
|
-
text += ` Output: ${outputPreview}\n`;
|
|
172
|
-
}
|
|
173
|
-
if (summary.error) {
|
|
174
|
-
text += ` Error: ${summary.error}\n`;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (text.length > maxLength) {
|
|
179
|
-
text = `${text.slice(0, maxLength)}...\n\n(truncated)`;
|
|
180
|
-
}
|
|
181
|
-
return text;
|
|
182
|
-
}
|