mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
- Increase message logging truncation limit from 500 to 1500 characters - Fix permission option mapping logic for reject_once/cancel options - Add TODO comments for diff accept/cancel responses during permission requests Resolves issues with permission handling and improves debugging capabilities.
110 lines
3.1 KiB
TypeScript
110 lines
3.1 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Qwen Team
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Tool call component factory - routes to specialized components by kind
|
|
*/
|
|
|
|
import type React from 'react';
|
|
import type { BaseToolCallProps } from './shared/types.js';
|
|
import { shouldShowToolCall } from './shared/utils.js';
|
|
import { GenericToolCall } from './GenericToolCall.js';
|
|
import { ReadToolCall } from './Read/ReadToolCall.js';
|
|
import { WriteToolCall } from './Write/WriteToolCall.js';
|
|
import { EditToolCall } from './Edit/EditToolCall.js';
|
|
import { ExecuteToolCall as BashExecuteToolCall } from './Bash/Bash.js';
|
|
import { ExecuteToolCall } from './Execute/Execute.js';
|
|
import { UpdatedPlanToolCall } from './UpdatedPlan/UpdatedPlanToolCall.js';
|
|
import { ExecuteNodeToolCall } from './ExecuteNode/ExecuteNodeToolCall.js';
|
|
import { SearchToolCall } from './Search/SearchToolCall.js';
|
|
import { ThinkToolCall } from './Think/ThinkToolCall.js';
|
|
|
|
/**
|
|
* Factory function that returns the appropriate tool call component based on kind
|
|
*/
|
|
export const getToolCallComponent = (
|
|
kind: string,
|
|
toolCall?: import('./shared/types.js').ToolCallData,
|
|
): React.FC<BaseToolCallProps> => {
|
|
const normalizedKind = kind.toLowerCase();
|
|
|
|
// Route to specialized components
|
|
switch (normalizedKind) {
|
|
case 'read':
|
|
return ReadToolCall;
|
|
|
|
case 'write':
|
|
return WriteToolCall;
|
|
|
|
case 'edit':
|
|
return EditToolCall;
|
|
|
|
case 'execute':
|
|
// Check if this is a node/npm version check command
|
|
if (toolCall) {
|
|
const commandText =
|
|
typeof toolCall.rawInput === 'string'
|
|
? toolCall.rawInput
|
|
: typeof toolCall.rawInput === 'object' &&
|
|
toolCall.rawInput !== null
|
|
? (toolCall.rawInput as { command?: string }).command || ''
|
|
: '';
|
|
|
|
// TODO:
|
|
if (
|
|
commandText.includes('node --version') ||
|
|
commandText.includes('npm --version')
|
|
) {
|
|
return ExecuteNodeToolCall;
|
|
}
|
|
}
|
|
return ExecuteToolCall;
|
|
|
|
case 'bash':
|
|
case 'command':
|
|
return BashExecuteToolCall;
|
|
|
|
case 'updated_plan':
|
|
case 'updatedplan':
|
|
case 'todo_write':
|
|
case 'update_todos':
|
|
case 'todowrite':
|
|
return UpdatedPlanToolCall;
|
|
// return TodoWriteToolCall;
|
|
|
|
case 'search':
|
|
case 'grep':
|
|
case 'glob':
|
|
case 'find':
|
|
return SearchToolCall;
|
|
|
|
case 'think':
|
|
case 'thinking':
|
|
return ThinkToolCall;
|
|
|
|
default:
|
|
// Fallback to generic component
|
|
return GenericToolCall;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Main tool call component that routes to specialized implementations
|
|
*/
|
|
export const ToolCallRouter: React.FC<BaseToolCallProps> = ({ toolCall }) => {
|
|
// Check if we should show this tool call (hide internal ones)
|
|
if (!shouldShowToolCall(toolCall.kind)) {
|
|
return null;
|
|
}
|
|
|
|
// Get the appropriate component for this kind
|
|
const Component = getToolCallComponent(toolCall.kind, toolCall);
|
|
|
|
// Render the specialized component
|
|
return <Component toolCall={toolCall} />;
|
|
};
|
|
|
|
// Re-export types for convenience
|
|
export type { BaseToolCallProps, ToolCallData } from './shared/types.js';
|