feat: add support for the channel field to CLI parameters and configurations

This commit is contained in:
DragonnZhang
2025-12-12 00:57:33 +08:00
parent 58d3a9c253
commit 60a58ad8e5
8 changed files with 43 additions and 4 deletions

View File

@@ -138,6 +138,7 @@ export interface CliArgs {
coreTools: string[] | undefined; coreTools: string[] | undefined;
excludeTools: string[] | undefined; excludeTools: string[] | undefined;
authType: string | undefined; authType: string | undefined;
channel: string | undefined;
} }
function normalizeOutputFormat( function normalizeOutputFormat(
@@ -297,6 +298,11 @@ export async function parseArguments(settings: Settings): Promise<CliArgs> {
type: 'boolean', type: 'boolean',
description: 'Starts the agent in ACP mode', description: 'Starts the agent in ACP mode',
}) })
.option('channel', {
type: 'string',
choices: ['VSCode', 'ACP', 'SDK', 'CI'],
description: 'Channel identifier (VSCode, ACP, SDK, CI)',
})
.option('allowed-mcp-server-names', { .option('allowed-mcp-server-names', {
type: 'array', type: 'array',
string: true, string: true,
@@ -559,6 +565,12 @@ export async function parseArguments(settings: Settings): Promise<CliArgs> {
// The import format is now only controlled by settings.memoryImportFormat // The import format is now only controlled by settings.memoryImportFormat
// We no longer accept it as a CLI argument // We no longer accept it as a CLI argument
// Apply ACP fallback: if experimental-acp is present but no explicit --channel, treat as ACP
if (result['experimentalAcp'] && !result['channel']) {
(result as Record<string, unknown>)['channel'] = 'ACP';
}
return result as unknown as CliArgs; return result as unknown as CliArgs;
} }
@@ -983,6 +995,7 @@ export async function loadCliConfig(
output: { output: {
format: outputSettingsFormat, format: outputSettingsFormat,
}, },
channel: argv.channel,
}); });
} }

View File

@@ -485,6 +485,7 @@ describe('gemini.tsx main function kitty protocol', () => {
excludeTools: undefined, excludeTools: undefined,
authType: undefined, authType: undefined,
maxSessionTurns: undefined, maxSessionTurns: undefined,
channel: undefined,
}); });
await main(); await main();

View File

@@ -349,6 +349,7 @@ export interface ConfigParameters {
skipStartupContext?: boolean; skipStartupContext?: boolean;
sdkMode?: boolean; sdkMode?: boolean;
sessionSubagents?: SubagentConfig[]; sessionSubagents?: SubagentConfig[];
channel?: string;
} }
function normalizeConfigOutputFormat( function normalizeConfigOutputFormat(
@@ -485,6 +486,7 @@ export class Config {
private readonly enableToolOutputTruncation: boolean; private readonly enableToolOutputTruncation: boolean;
private readonly eventEmitter?: EventEmitter; private readonly eventEmitter?: EventEmitter;
private readonly useSmartEdit: boolean; private readonly useSmartEdit: boolean;
private readonly channel: string | undefined;
constructor(params: ConfigParameters) { constructor(params: ConfigParameters) {
this.sessionId = params.sessionId ?? randomUUID(); this.sessionId = params.sessionId ?? randomUUID();
@@ -598,6 +600,7 @@ export class Config {
this.enableToolOutputTruncation = params.enableToolOutputTruncation ?? true; this.enableToolOutputTruncation = params.enableToolOutputTruncation ?? true;
this.useSmartEdit = params.useSmartEdit ?? false; this.useSmartEdit = params.useSmartEdit ?? false;
this.extensionManagement = params.extensionManagement ?? true; this.extensionManagement = params.extensionManagement ?? true;
this.channel = params.channel;
this.storage = new Storage(this.targetDir); this.storage = new Storage(this.targetDir);
this.vlmSwitchMode = params.vlmSwitchMode; this.vlmSwitchMode = params.vlmSwitchMode;
this.inputFormat = params.inputFormat ?? InputFormat.TEXT; this.inputFormat = params.inputFormat ?? InputFormat.TEXT;
@@ -1144,6 +1147,10 @@ export class Config {
return this.cliVersion; return this.cliVersion;
} }
getChannel(): string | undefined {
return this.channel;
}
/** /**
* Get the current FileSystemService * Get the current FileSystemService
*/ */

View File

@@ -130,10 +130,13 @@ export class DashScopeOpenAICompatibleProvider
} }
buildMetadata(userPromptId: string): DashScopeRequestMetadata { buildMetadata(userPromptId: string): DashScopeRequestMetadata {
const channel = this.cliConfig.getChannel?.();
return { return {
metadata: { metadata: {
sessionId: this.cliConfig.getSessionId?.(), sessionId: this.cliConfig.getSessionId?.(),
promptId: userPromptId, promptId: userPromptId,
...(channel ? { channel } : {}),
}, },
}; };
} }

View File

@@ -28,5 +28,6 @@ export type DashScopeRequestMetadata = {
metadata: { metadata: {
sessionId?: string; sessionId?: string;
promptId: string; promptId: string;
channel?: string;
}; };
}; };

View File

@@ -249,6 +249,9 @@ export class QwenLogger {
authType === AuthType.USE_OPENAI authType === AuthType.USE_OPENAI
? this.config?.getContentGeneratorConfig().baseUrl || '' ? this.config?.getContentGeneratorConfig().baseUrl || ''
: '', : '',
...(this.config?.getChannel?.()
? { channel: this.config.getChannel() }
: {}),
}, },
_v: `qwen-code@${version}`, _v: `qwen-code@${version}`,
} as RumPayload; } as RumPayload;

View File

@@ -139,6 +139,7 @@ export class ProcessTransport implements Transport {
'stream-json', 'stream-json',
'--output-format', '--output-format',
'stream-json', 'stream-json',
'--channel=SDK',
]; ];
if (this.options.model) { if (this.options.model) {

View File

@@ -94,7 +94,12 @@ export class AcpConnection {
if (cliPath.startsWith('npx ')) { if (cliPath.startsWith('npx ')) {
const parts = cliPath.split(' '); const parts = cliPath.split(' ');
spawnCommand = isWindows ? 'npx.cmd' : 'npx'; spawnCommand = isWindows ? 'npx.cmd' : 'npx';
spawnArgs = [...parts.slice(1), '--experimental-acp', ...extraArgs]; spawnArgs = [
...parts.slice(1),
'--experimental-acp',
'--channel=VSCode',
...extraArgs,
];
} else { } else {
// For qwen CLI, ensure we use the correct Node.js version // For qwen CLI, ensure we use the correct Node.js version
// Handle various Node.js version managers (nvm, n, manual installations) // Handle various Node.js version managers (nvm, n, manual installations)
@@ -103,11 +108,16 @@ export class AcpConnection {
const nodePathResult = determineNodePathForCli(cliPath); const nodePathResult = determineNodePathForCli(cliPath);
if (nodePathResult.path) { if (nodePathResult.path) {
spawnCommand = nodePathResult.path; spawnCommand = nodePathResult.path;
spawnArgs = [cliPath, '--experimental-acp', ...extraArgs]; spawnArgs = [
cliPath,
'--experimental-acp',
'--channel=VSCode',
...extraArgs,
];
} else { } else {
// Fallback to direct execution // Fallback to direct execution
spawnCommand = cliPath; spawnCommand = cliPath;
spawnArgs = ['--experimental-acp', ...extraArgs]; spawnArgs = ['--experimental-acp', '--channel=VSCode', ...extraArgs];
// Log any error for debugging // Log any error for debugging
if (nodePathResult.error) { if (nodePathResult.error) {
@@ -118,7 +128,7 @@ export class AcpConnection {
} }
} else { } else {
spawnCommand = cliPath; spawnCommand = cliPath;
spawnArgs = ['--experimental-acp', ...extraArgs]; spawnArgs = ['--experimental-acp', '--channel=VSCode', ...extraArgs];
} }
} }