mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
refactor(vscode-ide-companion): clean up code and improve type safety
- Remove commented out error handling code in acpMessageHandler - Simplify session update handler by removing redundant comments - Clean up chat types interface definitions - Simplify null check in MessageRouter - Improve type safety in SettingsMessageHandler with ApprovalModeValue type
This commit is contained in:
@@ -233,21 +233,3 @@ export class AcpMessageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [
|
||||
// {
|
||||
// received: 'reject_once',
|
||||
// code: 'invalid_enum_value',
|
||||
// options: [
|
||||
// 'proceed_once',
|
||||
// 'proceed_always',
|
||||
// 'proceed_always_server',
|
||||
// 'proceed_always_tool',
|
||||
// 'modify_with_editor',
|
||||
// 'cancel',
|
||||
// ],
|
||||
// path: [],
|
||||
// message:
|
||||
// "Invalid enum value. Expected 'proceed_once' | 'proceed_always' | 'proceed_always_server' | 'proceed_always_tool' | 'modify_with_editor' | 'cancel', received 'reject_once'",
|
||||
// },
|
||||
// ];
|
||||
|
||||
@@ -47,30 +47,20 @@ export class QwenSessionUpdateHandler {
|
||||
|
||||
switch (update.sessionUpdate) {
|
||||
case 'user_message_chunk':
|
||||
// Handle user message chunk
|
||||
if (update.content?.text && this.callbacks.onStreamChunk) {
|
||||
this.callbacks.onStreamChunk(update.content.text);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'agent_message_chunk':
|
||||
// Handle assistant message chunk
|
||||
if (update.content?.text && this.callbacks.onStreamChunk) {
|
||||
this.callbacks.onStreamChunk(update.content.text);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'agent_thought_chunk':
|
||||
// Handle thought chunk - use special callback
|
||||
console.log(
|
||||
'[SessionUpdateHandler] 🧠 THOUGHT CHUNK:',
|
||||
update.content?.text,
|
||||
);
|
||||
if (update.content?.text) {
|
||||
if (this.callbacks.onThoughtChunk) {
|
||||
console.log(
|
||||
'[SessionUpdateHandler] 🧠 Calling onThoughtChunk callback',
|
||||
);
|
||||
this.callbacks.onThoughtChunk(update.content.text);
|
||||
} else if (this.callbacks.onStreamChunk) {
|
||||
// Fallback to regular stream processing
|
||||
@@ -103,7 +93,6 @@ export class QwenSessionUpdateHandler {
|
||||
}
|
||||
|
||||
case 'tool_call_update': {
|
||||
// Handle tool call status update
|
||||
if (this.callbacks.onToolCall && 'toolCallId' in update) {
|
||||
this.callbacks.onToolCall({
|
||||
toolCallId: update.toolCallId as string,
|
||||
@@ -123,7 +112,6 @@ export class QwenSessionUpdateHandler {
|
||||
}
|
||||
|
||||
case 'plan': {
|
||||
// Handle plan update
|
||||
if ('entries' in update) {
|
||||
const entries = update.entries as Array<{
|
||||
content: string;
|
||||
|
||||
@@ -11,60 +11,30 @@ export interface ChatMessage {
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plan Entry
|
||||
* Represents a single step in the AI's execution plan
|
||||
*/
|
||||
export interface PlanEntry {
|
||||
/** The detailed description of this plan step */
|
||||
content: string;
|
||||
/** The priority level of this plan step */
|
||||
priority?: 'high' | 'medium' | 'low';
|
||||
/** The current execution status of this plan step */
|
||||
status: 'pending' | 'in_progress' | 'completed';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool Call Update Data
|
||||
* Contains information about a tool call execution or update
|
||||
*/
|
||||
export interface ToolCallUpdateData {
|
||||
/** Unique identifier for this tool call */
|
||||
toolCallId: string;
|
||||
/** The type of tool being called (e.g., 'read', 'write', 'execute') */
|
||||
kind?: string;
|
||||
/** Human-readable title or description of the tool call */
|
||||
title?: string;
|
||||
/** Current execution status of the tool call */
|
||||
status?: string;
|
||||
/** Raw input parameters passed to the tool */
|
||||
rawInput?: unknown;
|
||||
/** Content or output data from the tool execution */
|
||||
content?: Array<Record<string, unknown>>;
|
||||
/** File locations associated with this tool call */
|
||||
locations?: Array<{ path: string; line?: number | null }>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback Functions Collection
|
||||
* Defines all possible callback functions for the Qwen Agent
|
||||
*/
|
||||
export interface QwenAgentCallbacks {
|
||||
/** Callback for receiving chat messages from the agent */
|
||||
onMessage?: (message: ChatMessage) => void;
|
||||
/** Callback for receiving streamed text chunks during generation */
|
||||
onStreamChunk?: (chunk: string) => void;
|
||||
/** Callback for receiving thought process chunks during generation */
|
||||
onThoughtChunk?: (chunk: string) => void;
|
||||
/** Callback for receiving tool call updates during execution */
|
||||
onToolCall?: (update: ToolCallUpdateData) => void;
|
||||
/** Callback for receiving execution plan updates */
|
||||
onPlan?: (entries: PlanEntry[]) => void;
|
||||
/** Callback for handling permission requests from the agent */
|
||||
onPermissionRequest?: (request: AcpPermissionRequest) => Promise<string>;
|
||||
/** Callback triggered when the agent reaches the end of a turn */
|
||||
onEndTurn?: () => void;
|
||||
/** Callback for receiving mode information after ACP initialization */
|
||||
onModeInfo?: (info: {
|
||||
currentModeId?: ApprovalModeValue;
|
||||
availableModes?: Array<{
|
||||
@@ -73,13 +43,9 @@ export interface QwenAgentCallbacks {
|
||||
description: string;
|
||||
}>;
|
||||
}) => void;
|
||||
/** Callback for receiving notifications when the mode changes */
|
||||
onModeChanged?: (modeId: ApprovalModeValue) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool call update type
|
||||
*/
|
||||
export interface ToolCallUpdate {
|
||||
type: 'tool_call' | 'tool_call_update';
|
||||
toolCallId: string;
|
||||
|
||||
@@ -150,13 +150,7 @@ export class MessageRouter {
|
||||
*/
|
||||
setLoginHandler(handler: () => Promise<void>): void {
|
||||
this.authHandler.setLoginHandler(handler);
|
||||
// Also set login handler for SessionMessageHandler
|
||||
if (
|
||||
this.sessionHandler &&
|
||||
typeof this.sessionHandler.setLoginHandler === 'function'
|
||||
) {
|
||||
this.sessionHandler.setLoginHandler(handler);
|
||||
}
|
||||
this.sessionHandler?.setLoginHandler?.(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { BaseMessageHandler } from './BaseMessageHandler.js';
|
||||
import type { ApprovalModeValue } from '../../types/acpTypes.js';
|
||||
|
||||
/**
|
||||
* Settings message handler
|
||||
@@ -31,7 +32,7 @@ export class SettingsMessageHandler extends BaseMessageHandler {
|
||||
case 'setApprovalMode':
|
||||
await this.handleSetApprovalMode(
|
||||
message.data as {
|
||||
modeId?: 'plan' | 'default' | 'auto-edit' | 'yolo';
|
||||
modeId?: ApprovalModeValue;
|
||||
},
|
||||
);
|
||||
break;
|
||||
@@ -83,23 +84,11 @@ export class SettingsMessageHandler extends BaseMessageHandler {
|
||||
* Set approval mode via agent (ACP session/set_mode)
|
||||
*/
|
||||
private async handleSetApprovalMode(data?: {
|
||||
modeId?: 'plan' | 'default' | 'auto-edit' | 'yolo';
|
||||
modeId?: ApprovalModeValue;
|
||||
}): Promise<void> {
|
||||
try {
|
||||
const modeId = (data?.modeId || 'default') as
|
||||
| 'plan'
|
||||
| 'default'
|
||||
| 'auto-edit'
|
||||
| 'yolo';
|
||||
await this.agentManager.setApprovalModeFromUi(
|
||||
modeId === 'plan'
|
||||
? 'plan'
|
||||
: modeId === 'auto-edit'
|
||||
? 'auto'
|
||||
: modeId === 'yolo'
|
||||
? 'yolo'
|
||||
: 'ask',
|
||||
);
|
||||
const modeId = data?.modeId || 'default';
|
||||
await this.agentManager.setApprovalModeFromUi(modeId);
|
||||
// No explicit response needed; WebView listens for modeChanged
|
||||
} catch (error) {
|
||||
console.error('[SettingsMessageHandler] Failed to set mode:', error);
|
||||
|
||||
Reference in New Issue
Block a user