@compilr-dev/agents 0.3.9 → 0.3.11

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/index.d.ts CHANGED
@@ -31,7 +31,7 @@ export { PerplexityProvider, createPerplexityProvider } from './providers/index.
31
31
  export type { PerplexityProviderConfig } from './providers/index.js';
32
32
  export { OpenRouterProvider, createOpenRouterProvider } from './providers/index.js';
33
33
  export type { OpenRouterProviderConfig } from './providers/index.js';
34
- export type { Tool, ToolHandler, ToolRegistry, ToolInputSchema, ToolExecutionResult, ToolRegistryOptions, DefineToolOptions, ReadFileInput, WriteFileInput, BashInput, BashResult, FifoDetectionResult, GrepInput, GlobInput, EditInput, TodoWriteInput, TodoReadInput, TodoItem, TodoStatus, TodoContextCleanupOptions, TaskInput, TaskResult, AgentTypeConfig, TaskToolOptions, ContextMode, ThoroughnessLevel, SubAgentEventInfo, SuggestInput, SuggestToolOptions, } from './tools/index.js';
34
+ export type { Tool, ToolHandler, ToolRegistry, ToolInputSchema, ToolExecutionResult, ToolRegistryOptions, ToolFallbackHandler, DefineToolOptions, ReadFileInput, WriteFileInput, BashInput, BashResult, FifoDetectionResult, GrepInput, GlobInput, EditInput, TodoWriteInput, TodoReadInput, TodoItem, TodoStatus, TodoContextCleanupOptions, TaskInput, TaskResult, AgentTypeConfig, TaskToolOptions, ContextMode, ThoroughnessLevel, SubAgentEventInfo, SuggestInput, SuggestToolOptions, } from './tools/index.js';
35
35
  export { defineTool, createSuccessResult, createErrorResult, wrapToolExecute, DefaultToolRegistry, createToolRegistry, } from './tools/index.js';
36
36
  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, suggestTool, createSuggestTool, builtinTools, allBuiltinTools, TOOL_NAMES, TOOL_SETS, } from './tools/index.js';
37
37
  export { userMessage, assistantMessage, systemMessage, textBlock, toolUseBlock, toolResultBlock, getTextContent, getToolUses, getToolResults, hasToolUses, validateToolUseResultPairing, repairToolPairing, ensureMessageContent, normalizeMessages, } from './messages/index.js';
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * ToolRegistry - Manages available tools for an agent
3
3
  */
4
- import type { Tool, ToolDefinition, ToolRegistry as IToolRegistry, ToolExecutionResult, ToolExecutionContext } from './types.js';
4
+ import type { Tool, ToolDefinition, ToolRegistry as IToolRegistry, ToolExecutionResult, ToolExecutionContext, ToolFallbackHandler } from './types.js';
5
+ export type { ToolFallbackHandler } from './types.js';
5
6
  /**
6
7
  * Options for creating a DefaultToolRegistry
7
8
  */
@@ -15,6 +16,11 @@ export interface ToolRegistryOptions {
15
16
  * Per-tool timeout overrides (tool name -> timeout in ms)
16
17
  */
17
18
  toolTimeouts?: Record<string, number>;
19
+ /**
20
+ * Fallback handler for tools not found in the primary registry.
21
+ * Enables transparent routing to secondary registries (e.g., meta-tools).
22
+ */
23
+ fallbackHandler?: ToolFallbackHandler;
18
24
  }
19
25
  /**
20
26
  * Default implementation of ToolRegistry
@@ -23,7 +29,13 @@ export declare class DefaultToolRegistry implements IToolRegistry {
23
29
  private readonly tools;
24
30
  private readonly defaultTimeoutMs;
25
31
  private readonly toolTimeouts;
32
+ private fallbackHandler;
26
33
  constructor(options?: ToolRegistryOptions);
34
+ /**
35
+ * Set a fallback handler for tools not found in the primary registry.
36
+ * Enables transparent routing to secondary registries (e.g., meta-tools).
37
+ */
38
+ setFallbackHandler(handler: ToolFallbackHandler | null): void;
27
39
  /**
28
40
  * Register a tool
29
41
  */
@@ -13,9 +13,18 @@ export class DefaultToolRegistry {
13
13
  tools = new Map();
14
14
  defaultTimeoutMs;
15
15
  toolTimeouts;
16
+ fallbackHandler;
16
17
  constructor(options) {
17
18
  this.defaultTimeoutMs = options?.defaultTimeoutMs ?? DEFAULT_TOOL_TIMEOUT_MS;
18
19
  this.toolTimeouts = options?.toolTimeouts ?? {};
20
+ this.fallbackHandler = options?.fallbackHandler ?? null;
21
+ }
22
+ /**
23
+ * Set a fallback handler for tools not found in the primary registry.
24
+ * Enables transparent routing to secondary registries (e.g., meta-tools).
25
+ */
26
+ setFallbackHandler(handler) {
27
+ this.fallbackHandler = handler;
19
28
  }
20
29
  /**
21
30
  * Register a tool
@@ -81,6 +90,14 @@ export class DefaultToolRegistry {
81
90
  async execute(name, input, contextOrTimeout, timeoutMs) {
82
91
  const tool = this.tools.get(name);
83
92
  if (!tool) {
93
+ // Try fallback handler (e.g., meta-tools registry)
94
+ if (this.fallbackHandler) {
95
+ const context = typeof contextOrTimeout === 'object' ? contextOrTimeout : undefined;
96
+ const fallbackResult = await this.fallbackHandler(name, input, context);
97
+ if (fallbackResult !== null) {
98
+ return fallbackResult;
99
+ }
100
+ }
84
101
  return {
85
102
  success: false,
86
103
  error: `Tool not found: ${name}`,
@@ -79,6 +79,16 @@ export interface Tool<T = object> {
79
79
  */
80
80
  silent?: boolean;
81
81
  }
82
+ /**
83
+ * Fallback handler for tools not found in the primary registry.
84
+ * Used by meta-tools to transparently route calls to a secondary registry.
85
+ *
86
+ * @param name - Tool name that was not found
87
+ * @param input - Tool input parameters
88
+ * @param context - Optional execution context
89
+ * @returns Result if handled, or null to return the default "not found" error
90
+ */
91
+ export type ToolFallbackHandler = (name: string, input: Record<string, unknown>, context?: ToolExecutionContext) => Promise<ToolExecutionResult | null>;
82
92
  /**
83
93
  * Tool registry for managing available tools
84
94
  */
@@ -102,4 +112,9 @@ export interface ToolRegistry {
102
112
  * @param context - Optional execution context for streaming
103
113
  */
104
114
  execute(name: string, input: Record<string, unknown>, context?: ToolExecutionContext): Promise<ToolExecutionResult>;
115
+ /**
116
+ * Set a fallback handler for tools not found in the primary registry.
117
+ * Enables transparent routing to secondary registries (e.g., meta-tools).
118
+ */
119
+ setFallbackHandler(handler: ToolFallbackHandler | null): void;
105
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compilr-dev/agents",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "Lightweight multi-LLM agent library for building CLI AI assistants",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -52,7 +52,7 @@
52
52
  "node": ">=18.0.0"
53
53
  },
54
54
  "peerDependencies": {
55
- "@anthropic-ai/sdk": "^0.72.1",
55
+ "@anthropic-ai/sdk": ">=0.72.1",
56
56
  "@modelcontextprotocol/sdk": "^1.23.0"
57
57
  },
58
58
  "peerDependenciesMeta": {
@@ -64,17 +64,17 @@
64
64
  }
65
65
  },
66
66
  "devDependencies": {
67
- "@anthropic-ai/sdk": "^0.72.1",
67
+ "@anthropic-ai/sdk": "^0.74.0",
68
68
  "@eslint/js": "^9.39.1",
69
69
  "@modelcontextprotocol/sdk": "^1.23.0",
70
- "@types/node": "^24.10.1",
71
- "@vitest/coverage-v8": "^3.2.4",
70
+ "@types/node": "^25.2.3",
71
+ "@vitest/coverage-v8": "^4.0.18",
72
72
  "dotenv": "^17.2.3",
73
73
  "eslint": "^9.39.1",
74
74
  "prettier": "^3.7.1",
75
75
  "typescript": "^5.3.0",
76
76
  "typescript-eslint": "^8.48.0",
77
- "vitest": "^3.2.4"
77
+ "vitest": "^4.0.18"
78
78
  },
79
79
  "dependencies": {
80
80
  "@google/genai": "^1.38.0"