@townco/agent 0.1.88 → 0.1.101

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.
Files changed (32) hide show
  1. package/dist/acp-server/adapter.d.ts +49 -0
  2. package/dist/acp-server/adapter.js +693 -5
  3. package/dist/acp-server/http.d.ts +7 -0
  4. package/dist/acp-server/http.js +53 -6
  5. package/dist/definition/index.d.ts +29 -0
  6. package/dist/definition/index.js +24 -0
  7. package/dist/runner/agent-runner.d.ts +16 -1
  8. package/dist/runner/agent-runner.js +2 -1
  9. package/dist/runner/e2b-sandbox-manager.d.ts +18 -0
  10. package/dist/runner/e2b-sandbox-manager.js +99 -0
  11. package/dist/runner/hooks/executor.d.ts +3 -1
  12. package/dist/runner/hooks/executor.js +21 -1
  13. package/dist/runner/hooks/predefined/compaction-tool.js +67 -2
  14. package/dist/runner/hooks/types.d.ts +5 -0
  15. package/dist/runner/index.d.ts +11 -0
  16. package/dist/runner/langchain/index.d.ts +10 -0
  17. package/dist/runner/langchain/index.js +227 -7
  18. package/dist/runner/langchain/model-factory.js +28 -1
  19. package/dist/runner/langchain/tools/artifacts.js +6 -3
  20. package/dist/runner/langchain/tools/e2b.d.ts +54 -0
  21. package/dist/runner/langchain/tools/e2b.js +360 -0
  22. package/dist/runner/langchain/tools/filesystem.js +63 -0
  23. package/dist/runner/langchain/tools/subagent.d.ts +8 -0
  24. package/dist/runner/langchain/tools/subagent.js +76 -4
  25. package/dist/runner/langchain/tools/web_search.d.ts +36 -14
  26. package/dist/runner/langchain/tools/web_search.js +33 -2
  27. package/dist/runner/session-context.d.ts +20 -0
  28. package/dist/runner/session-context.js +54 -0
  29. package/dist/runner/tools.d.ts +2 -2
  30. package/dist/runner/tools.js +1 -0
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +8 -7
@@ -30,6 +30,17 @@ function getTownExaClient() {
30
30
  _townExaClient = new Exa(shedAuth.accessToken, `${shedAuth.shedUrl}/api/exa`);
31
31
  return _townExaClient;
32
32
  }
33
+ // Track citation counter for web search results
34
+ // This is reset at the start of each session via resetWebSearchCitationCounter()
35
+ let webSearchCitationCounter = 0;
36
+ /** Reset the web search citation counter (call at start of each session) */
37
+ export function resetWebSearchCitationCounter() {
38
+ webSearchCitationCounter = 0;
39
+ }
40
+ /** Get the current citation counter value */
41
+ export function getWebSearchCitationCounter() {
42
+ return webSearchCitationCounter;
43
+ }
33
44
  function makeWebSearchToolsInternal(getClient) {
34
45
  const webSearch = tool(async ({ query }) => {
35
46
  const client = getClient();
@@ -43,7 +54,25 @@ function makeWebSearchToolsInternal(getClient) {
43
54
  if (!result.results || result.results.length === 0) {
44
55
  return `No results found for query: ${query}`;
45
56
  }
46
- return result;
57
+ // Format results with citation numbers so the LLM can reference them
58
+ // The adapter will extract sources using the same numbering
59
+ const formattedResults = result.results.map((r) => {
60
+ webSearchCitationCounter++;
61
+ return {
62
+ citationId: webSearchCitationCounter,
63
+ url: r.url,
64
+ title: r.title,
65
+ text: r.text,
66
+ };
67
+ });
68
+ // Return both the formatted results (for LLM) and raw results (for adapter extraction)
69
+ return {
70
+ results: result.results, // Raw results for adapter source extraction
71
+ formattedForCitation: formattedResults.map((r) => ({
72
+ ...r,
73
+ citationInstruction: `Use [[${r.citationId}]] when citing this source`,
74
+ })),
75
+ };
47
76
  }, {
48
77
  name: "WebSearch",
49
78
  description: "\n- Allows you to search the web and use the results to inform responses\n" +
@@ -51,11 +80,13 @@ function makeWebSearchToolsInternal(getClient) {
51
80
  "- Returns search result information formatted as search result blocks\n" +
52
81
  "- Use this tool for accessing information beyond your knowledge cutoff\n" +
53
82
  "- Searches are performed automatically within a single API call\n" +
83
+ "- Results include citation IDs - use [[N]] format to cite sources in your response\n" +
54
84
  "\n" +
55
85
  "Usage notes:\n" +
56
86
  " - Domain filtering is supported to include or block specific websites\n" +
57
87
  " - Web search is only available in the US\n" +
58
- ' - Account for "Today\'s date" in <env>. For example, if <env> says "Today\'s date: 2025-07-01", and the user wants the latest docs, do not use 2024 in the search query. Use 2025.\n',
88
+ ' - Account for "Today\'s date" in <env>. For example, if <env> says "Today\'s date: 2025-07-01", and the user wants the latest docs, do not use 2024 in the search query. Use 2025.\n' +
89
+ " - IMPORTANT: When using information from search results, cite the source using [[N]] format where N is the citationId\n",
59
90
  schema: z.object({
60
91
  query: z.string().describe("The search query to use"),
61
92
  }),
@@ -10,6 +10,26 @@ export interface SessionContext {
10
10
  /** Artifacts directory: <agentDir>/.sessions/<sessionId>/artifacts */
11
11
  artifactsDir: string;
12
12
  }
13
+ /**
14
+ * Run a function with an abort signal available via AsyncLocalStorage.
15
+ * Tools can access the signal using getAbortSignal().
16
+ */
17
+ export declare function runWithAbortSignal<T>(signal: AbortSignal, fn: () => T): T;
18
+ /**
19
+ * Bind an async generator to an abort signal context so that every iteration
20
+ * runs with the abort signal available.
21
+ */
22
+ export declare function bindGeneratorToAbortSignal<T, R, N = unknown>(signal: AbortSignal, generator: AsyncGenerator<T, R, N>): AsyncGenerator<T, R, N>;
23
+ /**
24
+ * Get the current abort signal.
25
+ * Returns undefined if called outside of an abort signal context.
26
+ */
27
+ export declare function getAbortSignal(): AbortSignal | undefined;
28
+ /**
29
+ * Check if the current operation has been aborted.
30
+ * Returns false if no abort signal is available.
31
+ */
32
+ export declare function isAborted(): boolean;
13
33
  /**
14
34
  * Run a function with session context available via AsyncLocalStorage.
15
35
  * Tools can access the context using getSessionContext().
@@ -1,6 +1,60 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  import * as path from "node:path";
3
3
  const sessionStorage = new AsyncLocalStorage();
4
+ /**
5
+ * Abort signal context for cancellation support.
6
+ * Tools can access this to check if the current operation has been cancelled.
7
+ */
8
+ const abortSignalStorage = new AsyncLocalStorage();
9
+ /**
10
+ * Run a function with an abort signal available via AsyncLocalStorage.
11
+ * Tools can access the signal using getAbortSignal().
12
+ */
13
+ export function runWithAbortSignal(signal, fn) {
14
+ return abortSignalStorage.run(signal, fn);
15
+ }
16
+ /**
17
+ * Bind an async generator to an abort signal context so that every iteration
18
+ * runs with the abort signal available.
19
+ */
20
+ export function bindGeneratorToAbortSignal(signal, generator) {
21
+ const boundNext = (value) => abortSignalStorage.run(signal, () => generator.next(value));
22
+ const boundReturn = generator.return
23
+ ? (value) => abortSignalStorage.run(signal, () => generator.return?.(value))
24
+ : undefined;
25
+ const boundThrow = generator.throw
26
+ ? (e) => abortSignalStorage.run(signal, () => generator.throw?.(e))
27
+ : undefined;
28
+ const boundGenerator = {
29
+ next: boundNext,
30
+ return: boundReturn,
31
+ throw: boundThrow,
32
+ [Symbol.asyncIterator]() {
33
+ return this;
34
+ },
35
+ [Symbol.asyncDispose]: async () => {
36
+ if (Symbol.asyncDispose in generator) {
37
+ await generator[Symbol.asyncDispose]();
38
+ }
39
+ },
40
+ };
41
+ return boundGenerator;
42
+ }
43
+ /**
44
+ * Get the current abort signal.
45
+ * Returns undefined if called outside of an abort signal context.
46
+ */
47
+ export function getAbortSignal() {
48
+ return abortSignalStorage.getStore();
49
+ }
50
+ /**
51
+ * Check if the current operation has been aborted.
52
+ * Returns false if no abort signal is available.
53
+ */
54
+ export function isAborted() {
55
+ const signal = abortSignalStorage.getStore();
56
+ return signal?.aborted ?? false;
57
+ }
4
58
  /**
5
59
  * Run a function with session context available via AsyncLocalStorage.
6
60
  * Tools can access the context using getSessionContext().
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  /** Built-in tool types. */
3
- export declare const zBuiltInToolType: z.ZodUnion<readonly [z.ZodLiteral<"artifacts">, z.ZodLiteral<"todo_write">, z.ZodLiteral<"get_weather">, z.ZodLiteral<"web_search">, z.ZodLiteral<"town_web_search">, z.ZodLiteral<"filesystem">, z.ZodLiteral<"generate_image">, z.ZodLiteral<"town_generate_image">, z.ZodLiteral<"browser">, z.ZodLiteral<"document_extract">]>;
3
+ export declare const zBuiltInToolType: z.ZodUnion<readonly [z.ZodLiteral<"artifacts">, z.ZodLiteral<"todo_write">, z.ZodLiteral<"get_weather">, z.ZodLiteral<"web_search">, z.ZodLiteral<"town_web_search">, z.ZodLiteral<"filesystem">, z.ZodLiteral<"generate_image">, z.ZodLiteral<"town_generate_image">, z.ZodLiteral<"browser">, z.ZodLiteral<"document_extract">, z.ZodLiteral<"town_e2b">]>;
4
4
  /** Subagent configuration schema for Task tools. */
5
5
  export declare const zSubagentConfig: z.ZodObject<{
6
6
  agentName: z.ZodString;
@@ -23,7 +23,7 @@ declare const zDirectTool: z.ZodObject<{
23
23
  }, z.core.$strip>>>;
24
24
  }, z.core.$strip>;
25
25
  /** Tool type - can be a built-in tool string or custom tool object. */
26
- export declare const zToolType: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"artifacts">, z.ZodLiteral<"todo_write">, z.ZodLiteral<"get_weather">, z.ZodLiteral<"web_search">, z.ZodLiteral<"town_web_search">, z.ZodLiteral<"filesystem">, z.ZodLiteral<"generate_image">, z.ZodLiteral<"town_generate_image">, z.ZodLiteral<"browser">, z.ZodLiteral<"document_extract">]>, z.ZodObject<{
26
+ export declare const zToolType: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"artifacts">, z.ZodLiteral<"todo_write">, z.ZodLiteral<"get_weather">, z.ZodLiteral<"web_search">, z.ZodLiteral<"town_web_search">, z.ZodLiteral<"filesystem">, z.ZodLiteral<"generate_image">, z.ZodLiteral<"town_generate_image">, z.ZodLiteral<"browser">, z.ZodLiteral<"document_extract">, z.ZodLiteral<"town_e2b">]>, z.ZodObject<{
27
27
  type: z.ZodLiteral<"custom">;
28
28
  modulePath: z.ZodString;
29
29
  }, z.core.$strip>, z.ZodObject<{
@@ -11,6 +11,7 @@ export const zBuiltInToolType = z.union([
11
11
  z.literal("town_generate_image"),
12
12
  z.literal("browser"),
13
13
  z.literal("document_extract"),
14
+ z.literal("town_e2b"),
14
15
  ]);
15
16
  /** Custom tool schema (loaded from module path). */
16
17
  const zCustomTool = z.object({