Compare commits

..

1 Commits

Author SHA1 Message Date
LaZzyMan
6004d8f7fe fix/auth-url-display 2026-01-13 19:41:32 +08:00
3 changed files with 10 additions and 69 deletions

View File

@@ -1826,7 +1826,7 @@ describe('runNonInteractive', () => {
);
});
it('should print tool description and output to console in text mode (non-Task tools)', async () => {
it('should print tool output to console in text mode (non-Task tools)', async () => {
// Test that tool output is printed to stdout in text mode
const toolCallEvent: ServerGeminiStreamEvent = {
type: GeminiEventType.ToolCallRequest,
@@ -1839,21 +1839,6 @@ describe('runNonInteractive', () => {
},
};
// Mock the tool registry to return a tool with displayName and build method
const mockTool = {
displayName: 'Shell',
build: (args: Record<string, unknown>) => {
// @ts-expect-error - accessing indexed property for test mock
const command: string = args.command || '';
return {
getDescription: () => String(command),
};
},
};
vi.mocked(mockToolRegistry.getTool).mockReturnValue(
mockTool as unknown as ReturnType<typeof mockToolRegistry.getTool>,
);
// Mock tool execution with outputUpdateHandler being called
mockCoreExecuteToolCall.mockImplementation(
async (_config, _request, _signal, options) => {
@@ -1916,15 +1901,8 @@ describe('runNonInteractive', () => {
);
// Verify tool output was written to stdout
// First call should be tool description
expect(processStdoutSpy).toHaveBeenCalledWith('Shell: npm outdated');
expect(processStdoutSpy).toHaveBeenCalledWith('\n');
// Then the actual tool output
expect(processStdoutSpy).toHaveBeenCalledWith('Package outdated');
expect(processStdoutSpy).toHaveBeenCalledWith('npm@1.0.0 -> npm@2.0.0');
// Final newline after tool execution
expect(processStdoutSpy).toHaveBeenCalledWith('\n');
// And the model's response
expect(processStdoutSpy).toHaveBeenCalledWith('Package outdated\n');
expect(processStdoutSpy).toHaveBeenCalledWith('npm@1.0.0 -> npm@2.0.0\n');
expect(processStdoutSpy).toHaveBeenCalledWith('Dependencies checked');
});
});

View File

@@ -351,51 +351,19 @@ export async function runNonInteractive(
const taskToolProgressHandler = taskToolProgress?.handler;
// Create output handler for non-Task tools in text mode (for console output)
const toolOutputLines: string[] = [];
const nonTaskOutputHandler =
!isTaskTool && !adapter
? (callId: string, outputChunk: ToolResultDisplay) => {
const toolRegistry = config.getToolRegistry();
const tool = toolRegistry.getTool(finalRequestInfo.name);
if (tool) {
try {
const invocation = tool.build(finalRequestInfo.args);
const description = invocation.getDescription();
toolOutputLines.push(
`${tool.displayName}: ${description}`,
);
toolOutputLines.push('\n');
} catch {
// If we can't build invocation, just show tool name
toolOutputLines.push(`${tool.displayName}`);
toolOutputLines.push('\n');
}
}
// Print tool output to console in text mode
if (typeof outputChunk === 'string') {
// Indent output lines to show they're part of the tool execution
const lines = outputChunk.split('\n');
for (let i = 0; i < lines.length; i++) {
if (i === lines.length - 1 && lines[i] === '') {
// Skip trailing empty line
continue;
}
toolOutputLines.push(lines[i]);
}
process.stdout.write(outputChunk);
} else if (
outputChunk &&
typeof outputChunk === 'object' &&
'ansiOutput' in outputChunk
) {
// Handle ANSI output - indent it similarly
const ansiStr = String(outputChunk.ansiOutput);
const lines = ansiStr.split('\n');
for (let i = 0; i < lines.length; i++) {
if (i === lines.length - 1 && lines[i] === '') {
continue;
}
toolOutputLines.push(lines[i]);
}
// Handle ANSI output - just print as string for now
process.stdout.write(String(outputChunk.ansiOutput));
}
}
: undefined;
@@ -418,11 +386,6 @@ export async function runNonInteractive(
: undefined,
);
if (toolOutputLines.length > 0) {
toolOutputLines.forEach((line) => process.stdout.write(line));
process.stdout.write('\n');
}
// Note: In JSON mode, subagent messages are automatically added to the main
// adapter's messages array and will be output together on emitResult()

View File

@@ -593,12 +593,12 @@ async function authWithQwenDeviceFlow(
qwenOAuth2Events.emit(QwenOAuth2Event.AuthUri, deviceAuth);
const showFallbackMessage = () => {
console.log('\n=== Qwen OAuth Device Authorization ===');
console.log(
process.stdout.write('\n=== Qwen OAuth Device Authorization ===');
process.stdout.write(
'Please visit the following URL in your browser to authorize:',
);
console.log(`\n${deviceAuth.verification_uri_complete}\n`);
console.log('Waiting for authorization to complete...\n');
process.stdout.write(`\n${deviceAuth.verification_uri_complete}\n`);
process.stdout.write('Waiting for authorization to complete...\n');
};
// Always show the fallback message in non-interactive environments to ensure