mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
fix(vscode-ide-companion): improve type safety in webview components
修复 webview 组件的类型安全问题: - App.tsx: 规范化工具调用状态为联合类型 - InProgressToolCall.tsx: 安全处理非字符串类型的 title 属性 - InputForm.tsx: 修正 RefObject 泛型类型声明 - ReadToolCall.tsx: 添加空 children 避免 ToolCallContainer 警告
This commit is contained in:
@@ -24,7 +24,7 @@ import {
|
|||||||
import { useCompletionTrigger } from './hooks/useCompletionTrigger.js';
|
import { useCompletionTrigger } from './hooks/useCompletionTrigger.js';
|
||||||
import { SaveSessionDialog } from './components/SaveSessionDialog.js';
|
import { SaveSessionDialog } from './components/SaveSessionDialog.js';
|
||||||
import { InfoBanner } from './components/InfoBanner.js';
|
import { InfoBanner } from './components/InfoBanner.js';
|
||||||
import { ChatHeader } from './components/ui/ChatHeader.js';
|
import { ChatHeader } from './components/layouts/ChatHeader.js';
|
||||||
import {
|
import {
|
||||||
UserMessage,
|
UserMessage,
|
||||||
AssistantMessage,
|
AssistantMessage,
|
||||||
@@ -830,12 +830,22 @@ export const App: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalize status to our union type
|
||||||
|
const normalizedStatus = (
|
||||||
|
permToolCall.status === 'pending' ||
|
||||||
|
permToolCall.status === 'in_progress' ||
|
||||||
|
permToolCall.status === 'completed' ||
|
||||||
|
permToolCall.status === 'failed'
|
||||||
|
? permToolCall.status
|
||||||
|
: 'pending'
|
||||||
|
) as ToolCallUpdate['status'];
|
||||||
|
|
||||||
handleToolCallUpdate({
|
handleToolCallUpdate({
|
||||||
type: 'tool_call',
|
type: 'tool_call',
|
||||||
toolCallId: permToolCall.toolCallId,
|
toolCallId: permToolCall.toolCallId,
|
||||||
kind,
|
kind,
|
||||||
title: permToolCall.title,
|
title: permToolCall.title,
|
||||||
status: permToolCall.status || 'pending',
|
status: normalizedStatus,
|
||||||
content: permToolCall.content as Array<{
|
content: permToolCall.content as Array<{
|
||||||
type: 'content' | 'diff';
|
type: 'content' | 'diff';
|
||||||
content?: {
|
content?: {
|
||||||
|
|||||||
@@ -68,6 +68,12 @@ export const InProgressToolCall: React.FC<InProgressToolCallProps> = ({
|
|||||||
// Get status text
|
// Get status text
|
||||||
const statusText = getStatusText(status || 'in_progress');
|
const statusText = getStatusText(status || 'in_progress');
|
||||||
|
|
||||||
|
// Safely prepare a display value for title. Titles may sometimes arrive as
|
||||||
|
// non-string objects; ensure we render a string in that case.
|
||||||
|
const titleText = typeof title === 'string' ? title : undefined;
|
||||||
|
const titleDisplay: React.ReactNode =
|
||||||
|
typeof title === 'string' ? title : title ? JSON.stringify(title) : null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="in-progress-tool-call">
|
<div className="in-progress-tool-call">
|
||||||
<div className="in-progress-tool-call-header">
|
<div className="in-progress-tool-call-header">
|
||||||
@@ -79,8 +85,8 @@ export const InProgressToolCall: React.FC<InProgressToolCallProps> = ({
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{title && title !== kindLabel && (
|
{titleDisplay && (titleText ? titleText !== kindLabel : true) && (
|
||||||
<div className="in-progress-tool-call-title">{title}</div>
|
<div className="in-progress-tool-call-title">{titleDisplay}</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{locations && locations.length > 0 && (
|
{locations && locations.length > 0 && (
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ type EditMode = 'ask' | 'auto' | 'plan';
|
|||||||
|
|
||||||
interface InputFormProps {
|
interface InputFormProps {
|
||||||
inputText: string;
|
inputText: string;
|
||||||
inputFieldRef: React.RefObject<HTMLDivElement | null>;
|
// Note: RefObject<T> carries nullability in its `current` property, so the
|
||||||
|
// generic should be `HTMLDivElement` (not `HTMLDivElement | null`).
|
||||||
|
inputFieldRef: React.RefObject<HTMLDivElement>;
|
||||||
isStreaming: boolean;
|
isStreaming: boolean;
|
||||||
isComposing: boolean;
|
isComposing: boolean;
|
||||||
editMode: EditMode;
|
editMode: EditMode;
|
||||||
|
|||||||
@@ -48,7 +48,9 @@ export const ReadToolCall: React.FC<BaseToolCallProps> = ({ toolCall }) => {
|
|||||||
label={`Read ${fileName}`}
|
label={`Read ${fileName}`}
|
||||||
status="success"
|
status="success"
|
||||||
toolCallId={toolCallId}
|
toolCallId={toolCallId}
|
||||||
/>
|
>
|
||||||
|
{null}
|
||||||
|
</ToolCallContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user