@compilr-dev/agents 0.0.1

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 (160) hide show
  1. package/README.md +1277 -0
  2. package/dist/agent.d.ts +1272 -0
  3. package/dist/agent.js +1912 -0
  4. package/dist/anchors/builtin.d.ts +24 -0
  5. package/dist/anchors/builtin.js +61 -0
  6. package/dist/anchors/index.d.ts +6 -0
  7. package/dist/anchors/index.js +5 -0
  8. package/dist/anchors/manager.d.ts +115 -0
  9. package/dist/anchors/manager.js +412 -0
  10. package/dist/anchors/types.d.ts +168 -0
  11. package/dist/anchors/types.js +10 -0
  12. package/dist/context/index.d.ts +12 -0
  13. package/dist/context/index.js +10 -0
  14. package/dist/context/manager.d.ts +224 -0
  15. package/dist/context/manager.js +770 -0
  16. package/dist/context/types.d.ts +377 -0
  17. package/dist/context/types.js +7 -0
  18. package/dist/costs/index.d.ts +8 -0
  19. package/dist/costs/index.js +7 -0
  20. package/dist/costs/tracker.d.ts +121 -0
  21. package/dist/costs/tracker.js +295 -0
  22. package/dist/costs/types.d.ts +157 -0
  23. package/dist/costs/types.js +8 -0
  24. package/dist/errors.d.ts +178 -0
  25. package/dist/errors.js +249 -0
  26. package/dist/guardrails/builtin.d.ts +27 -0
  27. package/dist/guardrails/builtin.js +223 -0
  28. package/dist/guardrails/index.d.ts +6 -0
  29. package/dist/guardrails/index.js +5 -0
  30. package/dist/guardrails/manager.d.ts +117 -0
  31. package/dist/guardrails/manager.js +288 -0
  32. package/dist/guardrails/types.d.ts +159 -0
  33. package/dist/guardrails/types.js +7 -0
  34. package/dist/hooks/index.d.ts +31 -0
  35. package/dist/hooks/index.js +29 -0
  36. package/dist/hooks/manager.d.ts +147 -0
  37. package/dist/hooks/manager.js +600 -0
  38. package/dist/hooks/types.d.ts +368 -0
  39. package/dist/hooks/types.js +12 -0
  40. package/dist/index.d.ts +45 -0
  41. package/dist/index.js +73 -0
  42. package/dist/mcp/client.d.ts +93 -0
  43. package/dist/mcp/client.js +287 -0
  44. package/dist/mcp/errors.d.ts +60 -0
  45. package/dist/mcp/errors.js +78 -0
  46. package/dist/mcp/index.d.ts +43 -0
  47. package/dist/mcp/index.js +45 -0
  48. package/dist/mcp/manager.d.ts +120 -0
  49. package/dist/mcp/manager.js +276 -0
  50. package/dist/mcp/tools.d.ts +54 -0
  51. package/dist/mcp/tools.js +99 -0
  52. package/dist/mcp/types.d.ts +150 -0
  53. package/dist/mcp/types.js +40 -0
  54. package/dist/memory/index.d.ts +8 -0
  55. package/dist/memory/index.js +7 -0
  56. package/dist/memory/loader.d.ts +114 -0
  57. package/dist/memory/loader.js +463 -0
  58. package/dist/memory/types.d.ts +182 -0
  59. package/dist/memory/types.js +8 -0
  60. package/dist/messages/index.d.ts +82 -0
  61. package/dist/messages/index.js +155 -0
  62. package/dist/permissions/index.d.ts +5 -0
  63. package/dist/permissions/index.js +4 -0
  64. package/dist/permissions/manager.d.ts +125 -0
  65. package/dist/permissions/manager.js +379 -0
  66. package/dist/permissions/types.d.ts +162 -0
  67. package/dist/permissions/types.js +7 -0
  68. package/dist/providers/claude.d.ts +90 -0
  69. package/dist/providers/claude.js +348 -0
  70. package/dist/providers/index.d.ts +8 -0
  71. package/dist/providers/index.js +11 -0
  72. package/dist/providers/mock.d.ts +133 -0
  73. package/dist/providers/mock.js +204 -0
  74. package/dist/providers/types.d.ts +168 -0
  75. package/dist/providers/types.js +4 -0
  76. package/dist/rate-limit/index.d.ts +45 -0
  77. package/dist/rate-limit/index.js +47 -0
  78. package/dist/rate-limit/limiter.d.ts +104 -0
  79. package/dist/rate-limit/limiter.js +326 -0
  80. package/dist/rate-limit/provider-wrapper.d.ts +112 -0
  81. package/dist/rate-limit/provider-wrapper.js +201 -0
  82. package/dist/rate-limit/retry.d.ts +108 -0
  83. package/dist/rate-limit/retry.js +287 -0
  84. package/dist/rate-limit/types.d.ts +181 -0
  85. package/dist/rate-limit/types.js +22 -0
  86. package/dist/rehearsal/file-analyzer.d.ts +22 -0
  87. package/dist/rehearsal/file-analyzer.js +351 -0
  88. package/dist/rehearsal/git-analyzer.d.ts +22 -0
  89. package/dist/rehearsal/git-analyzer.js +472 -0
  90. package/dist/rehearsal/index.d.ts +35 -0
  91. package/dist/rehearsal/index.js +36 -0
  92. package/dist/rehearsal/manager.d.ts +100 -0
  93. package/dist/rehearsal/manager.js +290 -0
  94. package/dist/rehearsal/types.d.ts +235 -0
  95. package/dist/rehearsal/types.js +8 -0
  96. package/dist/skills/index.d.ts +160 -0
  97. package/dist/skills/index.js +282 -0
  98. package/dist/state/agent-state.d.ts +41 -0
  99. package/dist/state/agent-state.js +88 -0
  100. package/dist/state/checkpointer.d.ts +110 -0
  101. package/dist/state/checkpointer.js +362 -0
  102. package/dist/state/errors.d.ts +66 -0
  103. package/dist/state/errors.js +88 -0
  104. package/dist/state/index.d.ts +35 -0
  105. package/dist/state/index.js +37 -0
  106. package/dist/state/serializer.d.ts +55 -0
  107. package/dist/state/serializer.js +172 -0
  108. package/dist/state/types.d.ts +312 -0
  109. package/dist/state/types.js +14 -0
  110. package/dist/tools/builtin/bash-output.d.ts +61 -0
  111. package/dist/tools/builtin/bash-output.js +90 -0
  112. package/dist/tools/builtin/bash.d.ts +150 -0
  113. package/dist/tools/builtin/bash.js +354 -0
  114. package/dist/tools/builtin/edit.d.ts +50 -0
  115. package/dist/tools/builtin/edit.js +215 -0
  116. package/dist/tools/builtin/glob.d.ts +62 -0
  117. package/dist/tools/builtin/glob.js +244 -0
  118. package/dist/tools/builtin/grep.d.ts +74 -0
  119. package/dist/tools/builtin/grep.js +363 -0
  120. package/dist/tools/builtin/index.d.ts +44 -0
  121. package/dist/tools/builtin/index.js +69 -0
  122. package/dist/tools/builtin/kill-shell.d.ts +44 -0
  123. package/dist/tools/builtin/kill-shell.js +80 -0
  124. package/dist/tools/builtin/read-file.d.ts +57 -0
  125. package/dist/tools/builtin/read-file.js +184 -0
  126. package/dist/tools/builtin/shell-manager.d.ts +176 -0
  127. package/dist/tools/builtin/shell-manager.js +337 -0
  128. package/dist/tools/builtin/task.d.ts +202 -0
  129. package/dist/tools/builtin/task.js +350 -0
  130. package/dist/tools/builtin/todo.d.ts +207 -0
  131. package/dist/tools/builtin/todo.js +453 -0
  132. package/dist/tools/builtin/utils.d.ts +27 -0
  133. package/dist/tools/builtin/utils.js +70 -0
  134. package/dist/tools/builtin/web-fetch.d.ts +96 -0
  135. package/dist/tools/builtin/web-fetch.js +290 -0
  136. package/dist/tools/builtin/write-file.d.ts +54 -0
  137. package/dist/tools/builtin/write-file.js +147 -0
  138. package/dist/tools/define.d.ts +60 -0
  139. package/dist/tools/define.js +65 -0
  140. package/dist/tools/index.d.ts +10 -0
  141. package/dist/tools/index.js +37 -0
  142. package/dist/tools/registry.d.ts +79 -0
  143. package/dist/tools/registry.js +151 -0
  144. package/dist/tools/types.d.ts +59 -0
  145. package/dist/tools/types.js +4 -0
  146. package/dist/tracing/hooks.d.ts +58 -0
  147. package/dist/tracing/hooks.js +377 -0
  148. package/dist/tracing/index.d.ts +51 -0
  149. package/dist/tracing/index.js +55 -0
  150. package/dist/tracing/logging.d.ts +78 -0
  151. package/dist/tracing/logging.js +310 -0
  152. package/dist/tracing/manager.d.ts +160 -0
  153. package/dist/tracing/manager.js +468 -0
  154. package/dist/tracing/otel.d.ts +102 -0
  155. package/dist/tracing/otel.js +246 -0
  156. package/dist/tracing/types.d.ts +346 -0
  157. package/dist/tracing/types.js +38 -0
  158. package/dist/utils/index.d.ts +23 -0
  159. package/dist/utils/index.js +44 -0
  160. package/package.json +79 -0
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Helper for defining tools with type safety
3
+ */
4
+ import type { Tool, ToolExecutionResult, ToolInputSchema } from './types.js';
5
+ /**
6
+ * Options for defining a tool
7
+ */
8
+ export interface DefineToolOptions<T extends object> {
9
+ /**
10
+ * Unique name for the tool
11
+ */
12
+ name: string;
13
+ /**
14
+ * Description of what the tool does (shown to LLM)
15
+ */
16
+ description: string;
17
+ /**
18
+ * JSON Schema for the tool's input parameters
19
+ */
20
+ inputSchema: ToolInputSchema;
21
+ /**
22
+ * Function that executes the tool
23
+ */
24
+ execute: (input: T) => Promise<ToolExecutionResult>;
25
+ }
26
+ /**
27
+ * Define a tool with type-safe input handling
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const readFile = defineTool({
32
+ * name: 'read_file',
33
+ * description: 'Read the contents of a file',
34
+ * inputSchema: {
35
+ * type: 'object',
36
+ * properties: {
37
+ * path: { type: 'string', description: 'File path to read' },
38
+ * },
39
+ * required: ['path'],
40
+ * },
41
+ * execute: async ({ path }) => {
42
+ * const content = await fs.readFile(path, 'utf-8');
43
+ * return { success: true, result: content };
44
+ * },
45
+ * });
46
+ * ```
47
+ */
48
+ export declare function defineTool<T extends object>(options: DefineToolOptions<T>): Tool<T>;
49
+ /**
50
+ * Create a simple tool that returns success with a result
51
+ */
52
+ export declare function createSuccessResult(result: unknown): ToolExecutionResult;
53
+ /**
54
+ * Create an error result for a tool
55
+ */
56
+ export declare function createErrorResult(error: string | Error): ToolExecutionResult;
57
+ /**
58
+ * Wrap an async function to catch errors and return ToolExecutionResult
59
+ */
60
+ export declare function wrapToolExecute<T extends object>(fn: (input: T) => Promise<unknown>): (input: T) => Promise<ToolExecutionResult>;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Helper for defining tools with type safety
3
+ */
4
+ /**
5
+ * Define a tool with type-safe input handling
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const readFile = defineTool({
10
+ * name: 'read_file',
11
+ * description: 'Read the contents of a file',
12
+ * inputSchema: {
13
+ * type: 'object',
14
+ * properties: {
15
+ * path: { type: 'string', description: 'File path to read' },
16
+ * },
17
+ * required: ['path'],
18
+ * },
19
+ * execute: async ({ path }) => {
20
+ * const content = await fs.readFile(path, 'utf-8');
21
+ * return { success: true, result: content };
22
+ * },
23
+ * });
24
+ * ```
25
+ */
26
+ export function defineTool(options) {
27
+ const definition = {
28
+ name: options.name,
29
+ description: options.description,
30
+ inputSchema: options.inputSchema,
31
+ };
32
+ return {
33
+ definition,
34
+ execute: options.execute,
35
+ };
36
+ }
37
+ /**
38
+ * Create a simple tool that returns success with a result
39
+ */
40
+ export function createSuccessResult(result) {
41
+ return { success: true, result };
42
+ }
43
+ /**
44
+ * Create an error result for a tool
45
+ */
46
+ export function createErrorResult(error) {
47
+ return {
48
+ success: false,
49
+ error: error instanceof Error ? error.message : error,
50
+ };
51
+ }
52
+ /**
53
+ * Wrap an async function to catch errors and return ToolExecutionResult
54
+ */
55
+ export function wrapToolExecute(fn) {
56
+ return async (input) => {
57
+ try {
58
+ const result = await fn(input);
59
+ return createSuccessResult(result);
60
+ }
61
+ catch (error) {
62
+ return createErrorResult(error instanceof Error ? error : new Error(String(error)));
63
+ }
64
+ };
65
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Tools exports
3
+ */
4
+ export * from './types.js';
5
+ export { defineTool, createSuccessResult, createErrorResult, wrapToolExecute } from './define.js';
6
+ export type { DefineToolOptions } from './define.js';
7
+ export { DefaultToolRegistry, createToolRegistry } from './registry.js';
8
+ export type { ToolRegistryOptions } from './registry.js';
9
+ export { readFileTool, createReadFileTool, writeFileTool, createWriteFileTool, bashTool, createBashTool, execStream, detectFifoUsage, bashOutputTool, createBashOutputTool, killShellTool, createKillShellTool, ShellManager, getDefaultShellManager, setDefaultShellManager, grepTool, createGrepTool, globTool, createGlobTool, editTool, createEditTool, todoWriteTool, todoReadTool, createTodoTools, TodoStore, resetDefaultTodoStore, getDefaultTodoStore, createIsolatedTodoStore, cleanupTodoContextMessages, getTodoContextStats, webFetchTool, createWebFetchTool, createTaskTool, defaultAgentTypes, builtinTools, allBuiltinTools, } from './builtin/index.js';
10
+ export type { ReadFileInput, WriteFileInput, BashInput, BashResult, FifoDetectionResult, BashOutputInput, BashOutputResult, KillShellInput, KillShellResult, ShellStatus, BackgroundShell, ShellOutput, ShellManagerOptions, GrepInput, GlobInput, EditInput, TodoWriteInput, TodoReadInput, TodoItem, TodoStatus, TodoContextCleanupOptions, WebFetchInput, WebFetchResult, WebFetchOptions, TaskInput, TaskResult, AgentTypeConfig, TaskToolOptions, ContextMode, ThoroughnessLevel, SubAgentEventInfo, } from './builtin/index.js';
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Tools exports
3
+ */
4
+ // Core types
5
+ export * from './types.js';
6
+ // Tool definition helper
7
+ export { defineTool, createSuccessResult, createErrorResult, wrapToolExecute } from './define.js';
8
+ // Tool registry
9
+ export { DefaultToolRegistry, createToolRegistry } from './registry.js';
10
+ // Built-in tools
11
+ export {
12
+ // Read file
13
+ readFileTool, createReadFileTool,
14
+ // Write file
15
+ writeFileTool, createWriteFileTool,
16
+ // Bash
17
+ bashTool, createBashTool, execStream, detectFifoUsage,
18
+ // Bash output (background shell monitoring)
19
+ bashOutputTool, createBashOutputTool,
20
+ // Kill shell
21
+ killShellTool, createKillShellTool,
22
+ // Shell manager
23
+ ShellManager, getDefaultShellManager, setDefaultShellManager,
24
+ // Grep
25
+ grepTool, createGrepTool,
26
+ // Glob
27
+ globTool, createGlobTool,
28
+ // Edit
29
+ editTool, createEditTool,
30
+ // Todo
31
+ todoWriteTool, todoReadTool, createTodoTools, TodoStore, resetDefaultTodoStore, getDefaultTodoStore, createIsolatedTodoStore, cleanupTodoContextMessages, getTodoContextStats,
32
+ // WebFetch
33
+ webFetchTool, createWebFetchTool,
34
+ // Task (sub-agent spawning)
35
+ createTaskTool, defaultAgentTypes,
36
+ // Collections
37
+ builtinTools, allBuiltinTools, } from './builtin/index.js';
@@ -0,0 +1,79 @@
1
+ /**
2
+ * ToolRegistry - Manages available tools for an agent
3
+ */
4
+ import type { Tool, ToolDefinition, ToolRegistry as IToolRegistry, ToolExecutionResult } from './types.js';
5
+ /**
6
+ * Options for creating a DefaultToolRegistry
7
+ */
8
+ export interface ToolRegistryOptions {
9
+ /**
10
+ * Default timeout for tool execution in milliseconds.
11
+ * Default: 30000 (30 seconds). Set to 0 to disable timeout.
12
+ */
13
+ defaultTimeoutMs?: number;
14
+ /**
15
+ * Per-tool timeout overrides (tool name -> timeout in ms)
16
+ */
17
+ toolTimeouts?: Record<string, number>;
18
+ }
19
+ /**
20
+ * Default implementation of ToolRegistry
21
+ */
22
+ export declare class DefaultToolRegistry implements IToolRegistry {
23
+ private readonly tools;
24
+ private readonly defaultTimeoutMs;
25
+ private readonly toolTimeouts;
26
+ constructor(options?: ToolRegistryOptions);
27
+ /**
28
+ * Register a tool
29
+ */
30
+ register(tool: Tool): void;
31
+ /**
32
+ * Register multiple tools at once
33
+ */
34
+ registerAll(tools: Tool[]): void;
35
+ /**
36
+ * Unregister a tool by name
37
+ */
38
+ unregister(name: string): boolean;
39
+ /**
40
+ * Get a tool by name
41
+ */
42
+ get(name: string): Tool | undefined;
43
+ /**
44
+ * Check if a tool is registered
45
+ */
46
+ has(name: string): boolean;
47
+ /**
48
+ * Get all registered tool names
49
+ */
50
+ getNames(): string[];
51
+ /**
52
+ * Get all tool definitions (for sending to LLM)
53
+ */
54
+ getDefinitions(): ToolDefinition[];
55
+ /**
56
+ * Get the number of registered tools
57
+ */
58
+ get size(): number;
59
+ /**
60
+ * Execute a tool by name with given input
61
+ *
62
+ * @param name - Tool name
63
+ * @param input - Tool input parameters
64
+ * @param timeoutMs - Optional timeout override (uses default if not provided)
65
+ */
66
+ execute(name: string, input: Record<string, unknown>, timeoutMs?: number): Promise<ToolExecutionResult>;
67
+ /**
68
+ * Execute a tool with a timeout
69
+ */
70
+ private executeWithTimeout;
71
+ /**
72
+ * Clear all registered tools
73
+ */
74
+ clear(): void;
75
+ }
76
+ /**
77
+ * Create a new ToolRegistry with optional initial tools and options
78
+ */
79
+ export declare function createToolRegistry(tools?: Tool[], options?: ToolRegistryOptions): DefaultToolRegistry;
@@ -0,0 +1,151 @@
1
+ /**
2
+ * ToolRegistry - Manages available tools for an agent
3
+ */
4
+ import { ToolError, ToolTimeoutError } from '../errors.js';
5
+ /**
6
+ * Default tool execution timeout (30 seconds)
7
+ */
8
+ const DEFAULT_TOOL_TIMEOUT_MS = 30000;
9
+ /**
10
+ * Default implementation of ToolRegistry
11
+ */
12
+ export class DefaultToolRegistry {
13
+ tools = new Map();
14
+ defaultTimeoutMs;
15
+ toolTimeouts;
16
+ constructor(options) {
17
+ this.defaultTimeoutMs = options?.defaultTimeoutMs ?? DEFAULT_TOOL_TIMEOUT_MS;
18
+ this.toolTimeouts = options?.toolTimeouts ?? {};
19
+ }
20
+ /**
21
+ * Register a tool
22
+ */
23
+ register(tool) {
24
+ if (this.tools.has(tool.definition.name)) {
25
+ throw new ToolError(`Tool already registered: ${tool.definition.name}`, tool.definition.name);
26
+ }
27
+ this.tools.set(tool.definition.name, tool);
28
+ }
29
+ /**
30
+ * Register multiple tools at once
31
+ */
32
+ registerAll(tools) {
33
+ for (const tool of tools) {
34
+ this.register(tool);
35
+ }
36
+ }
37
+ /**
38
+ * Unregister a tool by name
39
+ */
40
+ unregister(name) {
41
+ return this.tools.delete(name);
42
+ }
43
+ /**
44
+ * Get a tool by name
45
+ */
46
+ get(name) {
47
+ return this.tools.get(name);
48
+ }
49
+ /**
50
+ * Check if a tool is registered
51
+ */
52
+ has(name) {
53
+ return this.tools.has(name);
54
+ }
55
+ /**
56
+ * Get all registered tool names
57
+ */
58
+ getNames() {
59
+ return Array.from(this.tools.keys());
60
+ }
61
+ /**
62
+ * Get all tool definitions (for sending to LLM)
63
+ */
64
+ getDefinitions() {
65
+ return Array.from(this.tools.values()).map((t) => t.definition);
66
+ }
67
+ /**
68
+ * Get the number of registered tools
69
+ */
70
+ get size() {
71
+ return this.tools.size;
72
+ }
73
+ /**
74
+ * Execute a tool by name with given input
75
+ *
76
+ * @param name - Tool name
77
+ * @param input - Tool input parameters
78
+ * @param timeoutMs - Optional timeout override (uses default if not provided)
79
+ */
80
+ async execute(name, input, timeoutMs) {
81
+ const tool = this.tools.get(name);
82
+ if (!tool) {
83
+ return {
84
+ success: false,
85
+ error: `Tool not found: ${name}`,
86
+ };
87
+ }
88
+ // Determine timeout: explicit param > per-tool config > default
89
+ const perToolTimeout = Object.hasOwn(this.toolTimeouts, name)
90
+ ? this.toolTimeouts[name]
91
+ : undefined;
92
+ const timeout = timeoutMs ?? perToolTimeout ?? this.defaultTimeoutMs;
93
+ // If timeout is 0 or negative, execute without timeout
94
+ if (timeout <= 0) {
95
+ try {
96
+ return await tool.execute(input);
97
+ }
98
+ catch (error) {
99
+ return {
100
+ success: false,
101
+ error: error instanceof Error ? error.message : String(error),
102
+ };
103
+ }
104
+ }
105
+ // Execute with timeout
106
+ try {
107
+ return await this.executeWithTimeout(tool, name, input, timeout);
108
+ }
109
+ catch (error) {
110
+ if (error instanceof ToolTimeoutError) {
111
+ return {
112
+ success: false,
113
+ error: error.message,
114
+ };
115
+ }
116
+ return {
117
+ success: false,
118
+ error: error instanceof Error ? error.message : String(error),
119
+ };
120
+ }
121
+ }
122
+ /**
123
+ * Execute a tool with a timeout
124
+ */
125
+ async executeWithTimeout(tool, name, input, timeoutMs) {
126
+ // Create a promise that rejects after the timeout
127
+ const timeoutPromise = new Promise((_, reject) => {
128
+ setTimeout(() => {
129
+ reject(new ToolTimeoutError(name, timeoutMs));
130
+ }, timeoutMs);
131
+ });
132
+ // Race the tool execution against the timeout
133
+ return Promise.race([tool.execute(input), timeoutPromise]);
134
+ }
135
+ /**
136
+ * Clear all registered tools
137
+ */
138
+ clear() {
139
+ this.tools.clear();
140
+ }
141
+ }
142
+ /**
143
+ * Create a new ToolRegistry with optional initial tools and options
144
+ */
145
+ export function createToolRegistry(tools, options) {
146
+ const registry = new DefaultToolRegistry(options);
147
+ if (tools) {
148
+ registry.registerAll(tools);
149
+ }
150
+ return registry;
151
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Core types for tools that AI agents can use
3
+ */
4
+ /**
5
+ * JSON Schema for tool input parameters
6
+ */
7
+ export interface ToolInputSchema {
8
+ type: 'object';
9
+ properties: Record<string, unknown>;
10
+ required?: string[];
11
+ }
12
+ /**
13
+ * Tool definition - describes a tool the AI can call
14
+ */
15
+ export interface ToolDefinition {
16
+ name: string;
17
+ description: string;
18
+ inputSchema: ToolInputSchema;
19
+ }
20
+ /**
21
+ * Result of executing a tool
22
+ */
23
+ export interface ToolExecutionResult {
24
+ success: boolean;
25
+ result?: unknown;
26
+ error?: string;
27
+ }
28
+ /**
29
+ * Tool handler function type
30
+ */
31
+ export type ToolHandler<T = object> = (input: T) => Promise<ToolExecutionResult>;
32
+ /**
33
+ * Tool implementation - combines definition with handler
34
+ */
35
+ export interface Tool<T = object> {
36
+ definition: ToolDefinition;
37
+ execute: ToolHandler<T>;
38
+ }
39
+ /**
40
+ * Tool registry for managing available tools
41
+ */
42
+ export interface ToolRegistry {
43
+ /**
44
+ * Register a tool
45
+ */
46
+ register(tool: Tool): void;
47
+ /**
48
+ * Get a tool by name
49
+ */
50
+ get(name: string): Tool | undefined;
51
+ /**
52
+ * Get all tool definitions (for sending to LLM)
53
+ */
54
+ getDefinitions(): ToolDefinition[];
55
+ /**
56
+ * Execute a tool by name with given input
57
+ */
58
+ execute(name: string, input: Record<string, unknown>): Promise<ToolExecutionResult>;
59
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Core types for tools that AI agents can use
3
+ */
4
+ export {};
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Built-in Tracing Hooks
3
+ *
4
+ * Pre-built hooks for common tracing patterns that integrate with the HooksManager.
5
+ * These hooks automatically create spans for LLM calls, tool executions, and iterations.
6
+ */
7
+ import type { HooksConfig } from '../hooks/types.js';
8
+ import type { TracingHooksConfig } from './types.js';
9
+ import { TracingManager } from './manager.js';
10
+ /**
11
+ * Create tracing hooks that automatically instrument agent execution
12
+ *
13
+ * @param manager - TracingManager instance
14
+ * @param config - Tracing hooks configuration
15
+ * @returns HooksConfig with tracing hooks
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const tracingManager = new TracingManager({ serviceName: 'my-agent' });
20
+ * const tracingHooks = createTracingHooks(tracingManager, {
21
+ * traceLLM: true,
22
+ * traceTools: true,
23
+ * traceIterations: true,
24
+ * });
25
+ *
26
+ * const agent = new Agent({
27
+ * provider,
28
+ * hooks: tracingHooks,
29
+ * });
30
+ * ```
31
+ */
32
+ export declare function createTracingHooks(manager: TracingManager, config?: TracingHooksConfig): HooksConfig;
33
+ /**
34
+ * Create a simple logging hook that logs all agent events
35
+ *
36
+ * @param logger - Logger function (default: console.log)
37
+ * @returns HooksConfig with logging hooks
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const loggingHooks = createLoggingHooks((msg) => myLogger.info(msg));
42
+ * const agent = new Agent({ provider, hooks: loggingHooks });
43
+ * ```
44
+ */
45
+ export declare function createLoggingHooks(logger?: (message: string, data?: Record<string, unknown>) => void): HooksConfig;
46
+ /**
47
+ * Merge multiple HooksConfig objects
48
+ *
49
+ * @param configs - HooksConfig objects to merge
50
+ * @returns Merged HooksConfig
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const hooks = mergeHooks(tracingHooks, loggingHooks, customHooks);
55
+ * const agent = new Agent({ provider, hooks });
56
+ * ```
57
+ */
58
+ export declare function mergeHooks(...configs: HooksConfig[]): HooksConfig;