fix: type errors

This commit is contained in:
mingholy.lmh
2025-09-15 14:11:31 +08:00
parent 1976837eda
commit acb93b1e1b
43 changed files with 367 additions and 342 deletions

View File

@@ -416,6 +416,7 @@ export class Task {
private createScheduler(): CoreToolScheduler {
const scheduler = new CoreToolScheduler({
/* @ts-expect-error */
outputUpdateHandler: this._schedulerOutputUpdate.bind(this),
onAllToolCallsComplete: this._schedulerAllToolCallsComplete.bind(this),
onToolCallsUpdate: this._schedulerToolCallsUpdate.bind(this),

View File

@@ -4,7 +4,11 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { CommandKind, SlashCommand, OpenDialogActionReturn } from './types.js';
import {
CommandKind,
type SlashCommand,
type OpenDialogActionReturn,
} from './types.js';
export const agentsCommand: SlashCommand = {
name: 'agents',

View File

@@ -7,12 +7,12 @@
import * as fsPromises from 'fs/promises';
import path from 'path';
import {
SlashCommand,
type SlashCommand,
CommandKind,
SlashCommandActionReturn,
type SlashCommandActionReturn,
} from './types.js';
import { getProjectSummaryPrompt } from '@qwen-code/qwen-code-core';
import { HistoryItemSummary } from '../types.js';
import type { HistoryItemSummary } from '../types.js';
export const summaryCommand: SlashCommand = {
name: 'summary',

View File

@@ -9,7 +9,7 @@ import React from 'react';
import { Colors } from '../colors.js';
import {
RadioButtonSelect,
RadioSelectItem,
type RadioSelectItem,
} from './shared/RadioButtonSelect.js';
import { useKeypress } from '../hooks/useKeypress.js';

View File

@@ -6,10 +6,10 @@
import { Box, Text } from 'ink';
import { Colors } from '../colors.js';
import { ProjectSummaryInfo } from '@qwen-code/qwen-code-core';
import { type ProjectSummaryInfo } from '@qwen-code/qwen-code-core';
import {
RadioButtonSelect,
RadioSelectItem,
type RadioSelectItem,
} from './shared/RadioButtonSelect.js';
import { useKeypress } from '../hooks/useKeypress.js';

View File

@@ -6,7 +6,7 @@
import React from 'react';
import { Box, Text } from 'ink';
import { SummaryProps } from '../../types.js';
import type { SummaryProps } from '../../types.js';
import Spinner from 'ink-spinner';
import { Colors } from '../../colors.js';

View File

@@ -294,4 +294,4 @@ export const ToolConfirmationMessage: React.FC<
</Box>
</Box>
);
};
};

View File

@@ -13,7 +13,7 @@ import { DescriptionInput } from './DescriptionInput.js';
import { ToolSelector } from './ToolSelector.js';
import { ColorSelector } from './ColorSelector.js';
import { CreationSummary } from './CreationSummary.js';
import { WizardStepProps } from '../types.js';
import { type WizardStepProps } from '../types.js';
import { WIZARD_STEPS } from '../constants.js';
import { getStepKind } from '../utils.js';
import { Config } from '@qwen-code/qwen-code-core';

View File

@@ -7,7 +7,7 @@
import { useState, useEffect } from 'react';
import { Box, Text } from 'ink';
import { RadioButtonSelect } from '../../shared/RadioButtonSelect.js';
import { ColorOption } from '../types.js';
import { type ColorOption } from '../types.js';
import { Colors } from '../../../colors.js';
import { COLOR_OPTIONS } from '../constants.js';

View File

@@ -6,8 +6,8 @@
import { useCallback, useState, useEffect } from 'react';
import { Box, Text, useInput } from 'ink';
import { WizardStepProps } from '../types.js';
import { SubagentManager, SubagentConfig } from '@qwen-code/qwen-code-core';
import { type WizardStepProps } from '../types.js';
import { SubagentManager, type SubagentConfig } from '@qwen-code/qwen-code-core';
import { theme } from '../../../semantic-colors.js';
import { shouldShowColor, getColorForDisplay } from '../utils.js';
import { useLaunchEditor } from '../../../hooks/useLaunchEditor.js';

View File

@@ -7,10 +7,10 @@
import { useCallback, useRef } from 'react';
import { Box, Text } from 'ink';
import Spinner from 'ink-spinner';
import { WizardStepProps, WizardAction } from '../types.js';
import type { WizardStepProps, WizardAction } from '../types.js';
import { sanitizeInput } from '../utils.js';
import { Config, subagentGenerator } from '@qwen-code/qwen-code-core';
import { useKeypress, Key } from '../../../hooks/useKeypress.js';
import { useKeypress, type Key } from '../../../hooks/useKeypress.js';
import { keyMatchers, Command } from '../../../keyMatchers.js';
import { theme } from '../../../semantic-colors.js';
import { Colors } from '../../../colors.js';

View File

@@ -6,7 +6,7 @@
import { Box } from 'ink';
import { RadioButtonSelect } from '../../shared/RadioButtonSelect.js';
import { WizardStepProps } from '../types.js';
import type { WizardStepProps } from '../types.js';
interface GenerationOption {
label: string;

View File

@@ -6,7 +6,7 @@
import { Box } from 'ink';
import { RadioButtonSelect } from '../../shared/RadioButtonSelect.js';
import { WizardStepProps } from '../types.js';
import type { WizardStepProps } from '../types.js';
interface LocationOption {
label: string;

View File

@@ -6,7 +6,7 @@
import { useCallback } from 'react';
import { Box, Text } from 'ink';
import { WizardStepProps } from '../types.js';
import type { WizardStepProps } from '../types.js';
import { Colors } from '../../../colors.js';
import { TextInput } from '../../shared/TextInput.js';

View File

@@ -7,7 +7,7 @@
import { useState, useMemo, useEffect } from 'react';
import { Box, Text } from 'ink';
import { RadioButtonSelect } from '../../shared/RadioButtonSelect.js';
import { ToolCategory } from '../types.js';
import type { ToolCategory } from '../types.js';
import { Kind, Config } from '@qwen-code/qwen-code-core';
import { Colors } from '../../../colors.js';

View File

@@ -8,7 +8,7 @@ import { useState } from 'react';
import { Box } from 'ink';
import { RadioButtonSelect } from '../../shared/RadioButtonSelect.js';
import { MANAGEMENT_STEPS } from '../types.js';
import { SubagentConfig } from '@qwen-code/qwen-code-core';
import { type SubagentConfig } from '@qwen-code/qwen-code-core';
interface ActionSelectionStepProps {
selectedAgent: SubagentConfig | null;

View File

@@ -5,8 +5,8 @@
*/
import { Box, Text } from 'ink';
import { SubagentConfig } from '@qwen-code/qwen-code-core';
import { StepNavigationProps } from '../types.js';
import { type SubagentConfig } from '@qwen-code/qwen-code-core';
import type { StepNavigationProps } from '../types.js';
import { theme } from '../../../semantic-colors.js';
import { useKeypress } from '../../../hooks/useKeypress.js';

View File

@@ -10,7 +10,7 @@ import { RadioButtonSelect } from '../../shared/RadioButtonSelect.js';
import { MANAGEMENT_STEPS } from '../types.js';
import { theme } from '../../../semantic-colors.js';
import { useLaunchEditor } from '../../../hooks/useLaunchEditor.js';
import { SubagentConfig } from '@qwen-code/qwen-code-core';
import { type SubagentConfig } from '@qwen-code/qwen-code-core';
interface EditOption {
id: string;

View File

@@ -9,7 +9,7 @@ import { Box, Text } from 'ink';
import { theme } from '../../../semantic-colors.js';
import { Colors } from '../../../colors.js';
import { useKeypress } from '../../../hooks/useKeypress.js';
import { SubagentConfig } from '@qwen-code/qwen-code-core';
import { type SubagentConfig } from '@qwen-code/qwen-code-core';
interface NavigationState {
currentBlock: 'project' | 'user' | 'builtin';

View File

@@ -7,7 +7,7 @@
import { Box, Text } from 'ink';
import { theme } from '../../../semantic-colors.js';
import { shouldShowColor, getColorForDisplay } from '../utils.js';
import { SubagentConfig } from '@qwen-code/qwen-code-core';
import { type SubagentConfig } from '@qwen-code/qwen-code-core';
interface AgentViewerStepProps {
selectedAgent: SubagentConfig | null;

View File

@@ -17,7 +17,7 @@ import { MANAGEMENT_STEPS } from '../types.js';
import { Colors } from '../../../colors.js';
import { theme } from '../../../semantic-colors.js';
import { getColorForDisplay, shouldShowColor } from '../utils.js';
import { Config, SubagentConfig } from '@qwen-code/qwen-code-core';
import { Config, type SubagentConfig } from '@qwen-code/qwen-code-core';
interface AgentsManagerDialogProps {
onClose: () => void;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { CreationWizardState, WizardAction } from './types.js';
import { type CreationWizardState, type WizardAction } from './types.js';
import { WIZARD_STEPS } from './constants.js';
import { getStepKind, getTotalSteps } from './utils.js';

View File

@@ -7,7 +7,7 @@
import React, { useMemo } from 'react';
import { Box, Text } from 'ink';
import { Colors } from '../../../colors.js';
import {
import type {
TaskResultDisplay,
SubagentStatsSummary,
} from '@qwen-code/qwen-code-core';

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { SubagentLevel, Config } from '@qwen-code/qwen-code-core';
import { type SubagentLevel, Config } from '@qwen-code/qwen-code-core';
/**
* State management for the subagent creation wizard.

View File

@@ -6,7 +6,7 @@
import { useCallback } from 'react';
import { useStdin } from 'ink';
import { EditorType } from '@qwen-code/qwen-code-core';
import type { EditorType } from '@qwen-code/qwen-code-core';
import { spawnSync } from 'child_process';
import { useSettings } from '../contexts/SettingsContext.js';
@@ -39,7 +39,7 @@ export function useLaunchEditor() {
const launchEditor = useCallback(
async (filePath: string): Promise<void> => {
const preferredEditor = settings.merged.preferredEditor as
const preferredEditor = settings.merged.general?.preferredEditor as
| EditorType
| undefined;
const editor = getEditorCommand(preferredEditor);
@@ -75,7 +75,7 @@ export function useLaunchEditor() {
if (wasRaw) setRawMode?.(true);
}
},
[settings.merged.preferredEditor, setRawMode, stdin],
[settings.merged.general?.preferredEditor, setRawMode, stdin],
);
return launchEditor;

View File

@@ -794,11 +794,11 @@ describe('CoreToolScheduler cancellation during executing with live output', ()
model: 'test-model',
authType: 'oauth-personal',
}),
getToolRegistry: () => mockToolRegistry,
} as unknown as Config;
const scheduler = new CoreToolScheduler({
config: mockConfig,
toolRegistry: mockToolRegistry,
onAllToolCallsComplete,
onToolCallsUpdate,
getPreferredEditor: () => 'vscode',

View File

@@ -19,7 +19,7 @@ import { isGitRepository } from '../utils/gitUtils.js';
import { MemoryTool, GEMINI_CONFIG_DIR } from '../tools/memoryTool.js';
import { TodoWriteTool } from '../tools/todoWrite.js';
import { TaskTool } from '../tools/task.js';
import { GenerateContentConfig } from '@google/genai';
import type { GenerateContentConfig } from '@google/genai';
export interface ModelTemplateMapping {
baseUrls?: string[];

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { SubagentConfig } from './types.js';
import type { SubagentConfig } from './types.js';
/**
* Registry of built-in subagents that are always available to all users.

View File

@@ -6,7 +6,7 @@
import { EventEmitter } from 'events';
import {
ToolCallConfirmationDetails,
type ToolCallConfirmationDetails,
ToolConfirmationOutcome,
} from '../tools/tools.js';

View File

@@ -9,7 +9,7 @@ import * as fs from 'fs/promises';
import * as path from 'path';
import * as os from 'os';
import { SubagentManager } from './subagent-manager.js';
import { SubagentConfig, SubagentError } from './types.js';
import { type SubagentConfig, SubagentError } from './types.js';
import { ToolRegistry } from '../tools/tool-registry.js';
import { Config } from '../config/config.js';
import { makeFakeConfig } from '../test-utils/config.js';

View File

@@ -13,19 +13,18 @@ import {
parse as parseYaml,
stringify as stringifyYaml,
} from '../utils/yaml-parser.js';
import {
import type {
SubagentConfig,
SubagentRuntimeConfig,
SubagentLevel,
ListSubagentsOptions,
CreateSubagentOptions,
SubagentError,
SubagentErrorCode,
PromptConfig,
ModelConfig,
RunConfig,
ToolConfig,
} from './types.js';
import { SubagentError, SubagentErrorCode } from './types.js';
import { SubagentValidator } from './validation.js';
import { SubAgentScope } from './subagent.js';
import { Config } from '../config/config.js';

View File

@@ -165,7 +165,7 @@ describe('subagent.ts', () => {
// Default mock for executeToolCall
vi.mocked(executeToolCall).mockResolvedValue({
callId: 'default-call',
responseParts: 'default response',
responseParts: [{ text: 'default response' }],
resultDisplay: 'Default tool result',
error: undefined,
errorType: undefined,

View File

@@ -6,11 +6,11 @@
import { reportError } from '../utils/errorReporting.js';
import { Config } from '../config/config.js';
import { ToolCallRequestInfo } from '../core/turn.js';
import { type ToolCallRequestInfo } from '../core/turn.js';
import {
CoreToolScheduler,
ToolCall,
WaitingToolCall,
type ToolCall,
type WaitingToolCall,
} from '../core/coreToolScheduler.js';
import type {
ToolConfirmationOutcome,
@@ -18,7 +18,7 @@ import type {
} from '../tools/tools.js';
import { createContentGenerator } from '../core/contentGenerator.js';
import { getEnvironmentContext } from '../utils/environmentContext.js';
import {
import type {
Content,
Part,
FunctionCall,
@@ -27,16 +27,14 @@ import {
GenerateContentResponseUsageMetadata,
} from '@google/genai';
import { GeminiChat } from '../core/geminiChat.js';
import {
SubagentTerminateMode,
import type {
PromptConfig,
ModelConfig,
RunConfig,
ToolConfig,
} from './types.js';
import {
SubAgentEventEmitter,
SubAgentEventType,
import { SubagentTerminateMode } from './types.js';
import type {
SubAgentFinishEvent,
SubAgentRoundEvent,
SubAgentStartEvent,
@@ -45,11 +43,12 @@ import {
SubAgentStreamTextEvent,
SubAgentErrorEvent,
} from './subagent-events.js';
import { SubAgentEventEmitter, SubAgentEventType } from './subagent-events.js';
import {
SubagentStatistics,
SubagentStatsSummary,
type SubagentStatsSummary,
} from './subagent-statistics.js';
import { SubagentHooks } from './subagent-hooks.js';
import type { SubagentHooks } from './subagent-hooks.js';
import { logSubagentExecution } from '../telemetry/loggers.js';
import { SubagentExecutionEvent } from '../telemetry/types.js';
import { TaskTool } from '../tools/task.js';
@@ -379,11 +378,20 @@ export class SubAgentScope {
let roundText = '';
let lastUsage: GenerateContentResponseUsageMetadata | undefined =
undefined;
for await (const resp of responseStream) {
for await (const streamEvent of responseStream) {
if (abortController.signal.aborted) {
this.terminateMode = SubagentTerminateMode.CANCELLED;
return;
}
// Handle retry events
if (streamEvent.type === 'retry') {
continue;
}
// Handle chunk events
if (streamEvent.type === 'chunk') {
const resp = streamEvent.value;
if (resp.functionCalls) functionCalls.push(...resp.functionCalls);
const content = resp.candidates?.[0]?.content;
const parts = content?.parts || [];
@@ -400,6 +408,7 @@ export class SubAgentScope {
}
if (resp.usageMetadata) lastUsage = resp.usageMetadata;
}
}
this.executionStats.rounds = turnCounter;
this.stats.setRounds(turnCounter);
@@ -546,7 +555,6 @@ export class SubAgentScope {
const responded = new Set<string>();
let resolveBatch: (() => void) | null = null;
const scheduler = new CoreToolScheduler({
toolRegistry: this.runtimeContext.getToolRegistry(),
outputUpdateHandler: undefined,
onAllToolCallsComplete: async (completedCalls) => {
for (const call of completedCalls) {

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { Content, FunctionDeclaration } from '@google/genai';
import type { Content, FunctionDeclaration } from '@google/genai';
/**
* Represents the storage level for a subagent configuration.

View File

@@ -6,7 +6,7 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { SubagentValidator } from './validation.js';
import { SubagentConfig, SubagentError } from './types.js';
import { type SubagentConfig, SubagentError } from './types.js';
describe('SubagentValidator', () => {
let validator: SubagentValidator;

View File

@@ -4,13 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
import {
SubagentConfig,
ValidationResult,
SubagentError,
SubagentErrorCode,
import { SubagentError, SubagentErrorCode } from './types.js';
import type {
ModelConfig,
RunConfig,
SubagentConfig,
ValidationResult,
} from './types.js';
/**

View File

@@ -5,12 +5,15 @@
*/
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { TaskTool, TaskParams } from './task.js';
import { TaskTool, type TaskParams } from './task.js';
import type { PartListUnion } from '@google/genai';
import type { ToolResultDisplay, TaskResultDisplay } from './tools.js';
import { Config } from '../config/config.js';
import { SubagentManager } from '../subagents/subagent-manager.js';
import { SubagentConfig, SubagentTerminateMode } from '../subagents/types.js';
import {
type SubagentConfig,
SubagentTerminateMode,
} from '../subagents/types.js';
import { SubAgentScope, ContextState } from '../subagents/subagent.js';
import { partToString } from '../utils/partUtils.js';

View File

@@ -4,10 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
import {
BaseDeclarativeTool,
BaseToolInvocation,
Kind,
import { BaseDeclarativeTool, BaseToolInvocation, Kind } from './tools.js';
import type {
ToolResult,
ToolResultDisplay,
TaskResultDisplay,
@@ -19,14 +17,19 @@ import type {
} from './tools.js';
import { Config } from '../config/config.js';
import { SubagentManager } from '../subagents/subagent-manager.js';
import { SubagentConfig, SubagentTerminateMode } from '../subagents/types.js';
import {
type SubagentConfig,
SubagentTerminateMode,
} from '../subagents/types.js';
import { ContextState } from '../subagents/subagent.js';
import {
SubAgentEventEmitter,
SubAgentEventType,
} from '../subagents/subagent-events.js';
import type {
SubAgentToolCallEvent,
SubAgentToolResultEvent,
SubAgentFinishEvent,
SubAgentEventType,
SubAgentErrorEvent,
SubAgentApprovalRequestEvent,
} from '../subagents/subagent-events.js';

View File

@@ -8,7 +8,7 @@ import type { FunctionDeclaration, PartListUnion } from '@google/genai';
import { ToolErrorType } from './tool-error.js';
import type { DiffUpdateResult } from '../ide/ideContext.js';
import { SchemaValidator } from '../utils/schemaValidator.js';
import { SubagentStatsSummary } from '../subagents/subagent-statistics.js';
import { type SubagentStatsSummary } from '../subagents/subagent-statistics.js';
/**
* Represents a validated and ready-to-execute tool call.

View File

@@ -4,14 +4,22 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, beforeEach, Mock, afterEach } from 'vitest';
import { Content, GoogleGenAI, Models } from '@google/genai';
import {
describe,
it,
expect,
vi,
beforeEach,
type Mock,
afterEach,
} from 'vitest';
import { type Content, GoogleGenAI, Models } from '@google/genai';
import { DEFAULT_QWEN_MODEL } from '../config/models.js';
import { GeminiClient } from '../core/client.js';
import { Config } from '../config/config.js';
import {
subagentGenerator,
SubagentGeneratedContent,
type SubagentGeneratedContent,
} from './subagentGenerator.js';
// Mock GeminiClient and Config constructor

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { Content } from '@google/genai';
import { type Content } from '@google/genai';
import { DEFAULT_QWEN_MODEL } from '../config/models.js';
import { GeminiClient } from '../core/client.js';