add(coding-agent): add defineTool helper closes #2746

This commit is contained in:
Mario Zechner
2026-04-01 23:07:14 +02:00
parent 746f770b10
commit e2f29b0523
7 changed files with 50 additions and 26 deletions

View File

@@ -154,6 +154,7 @@ export type {
} from "./types.js";
// Type guards
export {
defineTool,
isBashToolResult,
isEditToolResult,
isFindToolResult,

View File

@@ -404,6 +404,21 @@ export interface ToolDefinition<TParams extends TSchema = TSchema, TDetails = un
) => Component;
}
type AnyToolDefinition = ToolDefinition<any, any, any>;
/**
* Preserve parameter inference for standalone tool definitions.
*
* Use this when assigning a tool to a variable or passing it through arrays such
* as `customTools`, where contextual typing would otherwise widen params to
* `unknown`.
*/
export function defineTool<TParams extends TSchema, TDetails = unknown, TState = any>(
tool: ToolDefinition<TParams, TDetails, TState>,
): ToolDefinition<TParams, TDetails, TState> & AnyToolDefinition {
return tool;
}
// ============================================================================
// Resource Events
// ============================================================================

View File

@@ -28,6 +28,7 @@ export {
type AgentToolUpdateCallback,
type BeforeAgentStartEvent,
type ContextEvent,
defineTool,
discoverAndLoadExtensions,
type ExecOptions,
type ExecResult,

View File

@@ -125,6 +125,7 @@ export type {
} from "./core/extensions/index.js";
export {
createExtensionRuntime,
defineTool,
discoverAndLoadExtensions,
ExtensionRunner,
isBashToolResult,