data/services/tool_execution_service library

Classes

AbortController
Abort controller for cancellation.
AssistantMessage
Assistant message (simplified).
ContextModifier
A context modifier attached to a message update.
MessageUpdate
A message update yielded during tool execution.
PermissionDecisionReason
Reason for a permission decision.
PermissionResult
Permission result from hooks or rules.
PermissionRule
A permission rule with source info.
QueryTracking
Query tracking info.
StreamingToolExecutor
Executes tools as they stream in with concurrency control.
ToolBatch
Partition tool calls into batches where each batch is either:
ToolDefinition
A tool definition.
ToolMessage
A message returned from tool execution.
ToolResultBlock
A tool result block within a message.
ToolUseBlock
Tool use block from the API response.
ToolUseContext
Context passed to tool execution.

Enums

McpServerType
MCP server transport type.
PermissionBehavior
Permission decision result.
ToolStatus
Status of a tracked tool in the streaming executor.

Constants

cancelMessage → const String
Cancel message constant.
hookTimingDisplayThresholdMs → const int
Display threshold for hook timing summary.
rejectMessage → const String

Functions

classifyToolError(Object error) String
Classify a tool execution error into a telemetry-safe string.
createChildAbortController(AbortController parent) AbortController
Create a child abort controller that fires when the parent fires.
decisionReasonToOTelSource(PermissionDecisionReason? reason, PermissionBehavior behavior) String
Map a PermissionDecisionReason to the OTel source label.
findToolByName(List<ToolDefinition> tools, String name) ToolDefinition?
Find a tool by name in the tools list.
getMaxToolUseConcurrency() int
Max concurrent tool executions.
isMcpTool(String toolName) bool
Check if a tool name corresponds to an MCP tool.
partitionToolCalls(List<ToolUseBlock> toolUseMessages, ToolUseContext toolUseContext) List<ToolBatch>
Partition tool calls into batches for orchestration.
resolveHookPermissionDecision({required PermissionResult? hookPermissionResult, required ToolDefinition tool, required Map<String, dynamic> input, required ToolUseContext toolUseContext, required CanUseToolFn canUseTool, required AssistantMessage assistantMessage, required String toolUseID, Future<PermissionResult?> checkRuleBasedPermissions(ToolDefinition, Map<String, dynamic>, ToolUseContext)?}) Future<({PermissionResult decision, Map<String, dynamic> input})>
Resolve a PreToolUse hook's permission result into a final decision.
ruleSourceToOTelSource(String ruleSource, PermissionBehavior behavior) String
Map a rule's origin to OTel source vocabulary.
runTools(List<ToolUseBlock> toolUseMessages, List<AssistantMessage> assistantMessages, CanUseToolFn canUseTool, ToolUseContext toolUseContext) Stream<MessageUpdate>
Run tools — handles both serial and concurrent execution.
runToolUse(ToolUseBlock toolUse, AssistantMessage assistantMessage, CanUseToolFn canUseTool, ToolUseContext toolUseContext) Stream<MessageUpdate>
Run a single tool use block — checks permissions and executes the tool.
sanitizeToolNameForAnalytics(String toolName) String
Sanitize tool name for analytics (strips MCP prefix details).

Typedefs

CanUseToolFn = Future<PermissionResult> Function(ToolDefinition tool, Map<String, dynamic> input, ToolUseContext context, AssistantMessage assistantMessage, String toolUseID, [PermissionResult? forceDecision])
Type for the canUseTool callback.

Exceptions / Errors

AbortError
Abort error when tool execution is cancelled.
ShellError
Shell error for tool execution.