ee0af0cc06
Implements configurable tool filtering with four built-in profiles (minimal, messaging, coding, full), global and per-agent/per-provider allow/deny lists with glob pattern support, and defense-in-depth enforcement at both tool listing and execution time. New: src/tools/policy.ts (ToolPolicy engine), src/tools/policy.test.ts (37 tests) Modified: config schema, tool registry, tool executor, NativeAgent, AgentOrchestrator, daemon wiring, gateway tool handler, test mocks
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import type { GatewayRequest, OutboundMessage } from '../protocol.js';
|
|
import { makeResponse, makeError, ErrorCode } from '../protocol.js';
|
|
import type { ToolRegistry } from '../../tools/registry.js';
|
|
import type { ToolExecutor } from '../../tools/executor.js';
|
|
|
|
export interface ToolHandlerDeps {
|
|
toolRegistry: ToolRegistry;
|
|
toolExecutor: ToolExecutor;
|
|
}
|
|
|
|
export function createToolHandlers(deps: ToolHandlerDeps) {
|
|
return {
|
|
'tools.list': async (request: GatewayRequest): Promise<OutboundMessage> => {
|
|
// Use filteredList to respect tool policy (gateway context has no agent/provider)
|
|
const tools = deps.toolRegistry.filteredList().map(t => ({
|
|
name: t.name,
|
|
description: t.description,
|
|
inputSchema: t.inputSchema,
|
|
}));
|
|
return makeResponse(request.id, { tools });
|
|
},
|
|
|
|
'tools.invoke': async (request: GatewayRequest): Promise<OutboundMessage> => {
|
|
const params = request.params as { tool?: string; args?: Record<string, unknown> } | undefined;
|
|
if (!params?.tool) {
|
|
return makeError(request.id, ErrorCode.InvalidRequest, 'tool name is required');
|
|
}
|
|
|
|
const tool = deps.toolRegistry.get(params.tool);
|
|
if (!tool) {
|
|
return makeError(request.id, ErrorCode.ToolNotFound, `Tool not found: ${params.tool}`);
|
|
}
|
|
|
|
// Pass no context — gateway uses global policy only
|
|
const result = await deps.toolExecutor.execute(params.tool, params.args ?? {});
|
|
return makeResponse(request.id, result);
|
|
},
|
|
};
|
|
}
|