@townco/agent 0.1.38 → 0.1.40

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,5 +1,3 @@
1
1
  import type { AgentDefinition } from "../definition";
2
2
  import { type AgentRunner } from "../runner";
3
- export declare function makeStdioTransport(
4
- agent: AgentRunner | AgentDefinition,
5
- ): void;
3
+ export declare function makeStdioTransport(agent: AgentRunner | AgentDefinition): void;
@@ -3,13 +3,9 @@ import * as acp from "@agentclientprotocol/sdk";
3
3
  import { makeRunnerFromDefinition } from "../runner";
4
4
  import { AgentAcpAdapter } from "./adapter";
5
5
  export function makeStdioTransport(agent) {
6
- const agentRunner =
7
- "definition" in agent ? agent : makeRunnerFromDefinition(agent);
8
- const input = Writable.toWeb(process.stdout);
9
- const output = Readable.toWeb(process.stdin);
10
- const stream = acp.ndJsonStream(input, output);
11
- new acp.AgentSideConnection(
12
- (conn) => new AgentAcpAdapter(agentRunner, conn),
13
- stream,
14
- );
6
+ const agentRunner = "definition" in agent ? agent : makeRunnerFromDefinition(agent);
7
+ const input = Writable.toWeb(process.stdout);
8
+ const output = Readable.toWeb(process.stdin);
9
+ const stream = acp.ndJsonStream(input, output);
10
+ new acp.AgentSideConnection((conn) => new AgentAcpAdapter(agentRunner, conn), stream);
15
11
  }
package/dist/bin.js CHANGED
File without changes
package/dist/index.js CHANGED
@@ -22,8 +22,14 @@ const exampleAgent = {
22
22
  ],
23
23
  mcps: [],
24
24
  };
25
- // Parse transport type from command line argument
26
- const transport = process.argv[2] || "stdio";
25
+ // Parse transport type and flags from command line arguments
26
+ const args = process.argv.slice(2);
27
+ const transport = args.find((arg) => !arg.startsWith("--")) || "stdio";
28
+ const noSession = args.includes("--no-session");
29
+ // Set TOWN_NO_SESSION environment variable if flag is present
30
+ if (noSession) {
31
+ process.env.TOWN_NO_SESSION = "true";
32
+ }
27
33
  // Get agent directory and name for session storage
28
34
  const agentDir = process.cwd();
29
35
  const agentName = basename(agentDir);
@@ -35,6 +41,6 @@ else if (transport === "stdio") {
35
41
  }
36
42
  else {
37
43
  console.error(`Invalid transport: ${transport}`);
38
- console.error("Usage: bun run index.ts [stdio|http]");
44
+ console.error("Usage: bun run index.ts [stdio|http] [--no-session]");
39
45
  process.exit(1);
40
46
  }
@@ -1,6 +1,4 @@
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: (
5
- definition: AgentDefinition,
6
- ) => AgentRunner;
4
+ export declare const makeRunnerFromDefinition: (definition: AgentDefinition) => AgentRunner;
@@ -1,22 +1,18 @@
1
1
  import { zAgentRunnerParams } from "./agent-runner";
2
2
  import { LangchainAgent } from "./langchain";
3
3
  export const makeRunnerFromDefinition = (definition) => {
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
- }
4
+ const agentRunnerParams = zAgentRunnerParams.safeParse(definition);
5
+ if (!agentRunnerParams.success) {
6
+ throw new Error(`Invalid agent definition: ${agentRunnerParams.error.message}`);
7
+ }
8
+ switch (definition.harnessImplementation) {
9
+ case undefined:
10
+ case "langchain": {
11
+ return new LangchainAgent(agentRunnerParams.data);
12
+ }
13
+ default: {
14
+ const _exhaustiveCheck = definition.harnessImplementation;
15
+ throw new Error(`Unsupported harness implementation: ${definition.harnessImplementation}`);
16
+ }
17
+ }
22
18
  };
@@ -131,6 +131,9 @@ export class LangchainAgent {
131
131
  model,
132
132
  tools: finalTools,
133
133
  };
134
+ if (this.definition.systemPrompt) {
135
+ agentConfig.systemPrompt = this.definition.systemPrompt;
136
+ }
134
137
  // Inject system prompt with optional TodoWrite instructions
135
138
  const hasTodoWrite = builtInNames.includes("todo_write");
136
139
  if (hasTodoWrite) {
@@ -54,13 +54,27 @@ export function createModelFromString(modelString) {
54
54
  switch (provider) {
55
55
  case "google_vertexai":
56
56
  case "vertex":
57
- case "vertexai":
57
+ case "vertexai": {
58
+ if (process.env.VERTEX_CREDENTIALS == null) {
59
+ throw new Error("VERTEX_CREDENTIALS environment variable not set");
60
+ }
61
+ let parsedEnv;
62
+ try {
63
+ parsedEnv = JSON.parse(process.env.VERTEX_CREDENTIALS);
64
+ }
65
+ catch (e) {
66
+ throw new Error(`VERTEX_CREDENTIALS environment variable is not valid JSON ${e}`);
67
+ }
58
68
  return new ChatVertexAI({
59
69
  model: modelName,
60
70
  // Default to reasonable settings
61
71
  temperature: 0,
62
72
  location: "global",
73
+ authOptions: {
74
+ credentials: parsedEnv,
75
+ },
63
76
  });
77
+ }
64
78
  case "google_genai":
65
79
  case "gemini":
66
80
  return new ChatGoogleGenerativeAI({
@@ -179,6 +179,10 @@ async function querySubagent(agentPath, agentWorkingDirectory, query) {
179
179
  // Handle session updates from the agent
180
180
  const paramsExtended = params;
181
181
  const update = paramsExtended.update;
182
+ // Reset accumulated text when a tool call starts (marks a new message boundary)
183
+ if (update?.sessionUpdate === "tool_call") {
184
+ responseText = "";
185
+ }
182
186
  // Accumulate agent_message_chunk text content
183
187
  if (update?.sessionUpdate === "agent_message_chunk") {
184
188
  const content = update.content;