mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
fix: update timeout settings and default logging level in SDK
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
* Implements AsyncIterator protocol for message consumption.
|
||||
*/
|
||||
|
||||
const DEFAULT_CAN_USE_TOOL_TIMEOUT = 30_000;
|
||||
const DEFAULT_CAN_USE_TOOL_TIMEOUT = 60_000;
|
||||
const DEFAULT_MCP_REQUEST_TIMEOUT = 60_000;
|
||||
const DEFAULT_CONTROL_REQUEST_TIMEOUT = 30_000;
|
||||
const DEFAULT_CONTROL_REQUEST_TIMEOUT = 60_000;
|
||||
const DEFAULT_STREAM_CLOSE_TIMEOUT = 60_000;
|
||||
|
||||
import { randomUUID } from 'node:crypto';
|
||||
@@ -434,8 +434,9 @@ export class Query implements AsyncIterable<SDKMessage> {
|
||||
try {
|
||||
const canUseToolTimeout =
|
||||
this.options.timeout?.canUseTool ?? DEFAULT_CAN_USE_TOOL_TIMEOUT;
|
||||
let timeoutId: NodeJS.Timeout | undefined;
|
||||
const timeoutPromise = new Promise<never>((_, reject) => {
|
||||
setTimeout(
|
||||
timeoutId = setTimeout(
|
||||
() => reject(new Error('Permission callback timeout')),
|
||||
canUseToolTimeout,
|
||||
);
|
||||
@@ -451,6 +452,10 @@ export class Query implements AsyncIterable<SDKMessage> {
|
||||
timeoutPromise,
|
||||
]);
|
||||
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
|
||||
if (result.behavior === 'allow') {
|
||||
return {
|
||||
behavior: 'allow',
|
||||
@@ -789,14 +794,20 @@ export class Query implements AsyncIterable<SDKMessage> {
|
||||
) {
|
||||
const streamCloseTimeout =
|
||||
this.options.timeout?.streamClose ?? DEFAULT_STREAM_CLOSE_TIMEOUT;
|
||||
await Promise.race([
|
||||
this.firstResultReceivedPromise,
|
||||
new Promise<void>((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, streamCloseTimeout);
|
||||
}),
|
||||
]);
|
||||
let timeoutId: NodeJS.Timeout | undefined;
|
||||
|
||||
const timeoutPromise = new Promise<void>((resolve) => {
|
||||
timeoutId = setTimeout(() => {
|
||||
logger.info('streamCloseTimeout resolved');
|
||||
resolve();
|
||||
}, streamCloseTimeout);
|
||||
});
|
||||
|
||||
await Promise.race([this.firstResultReceivedPromise, timeoutPromise]);
|
||||
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
}
|
||||
|
||||
this.endInput();
|
||||
|
||||
@@ -316,7 +316,7 @@ export interface QueryOptions {
|
||||
/**
|
||||
* Logging level for the SDK.
|
||||
* Controls the verbosity of log messages output by the SDK.
|
||||
* @default 'info'
|
||||
* @default 'error'
|
||||
*/
|
||||
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ const LOG_LEVEL_PRIORITY: Record<LogLevel, number> = {
|
||||
|
||||
export class SdkLogger {
|
||||
private static config: LoggerConfig = {};
|
||||
private static effectiveLevel: LogLevel = 'info';
|
||||
private static effectiveLevel: LogLevel = 'error';
|
||||
|
||||
static configure(config: LoggerConfig): void {
|
||||
this.config = config;
|
||||
@@ -47,7 +47,7 @@ export class SdkLogger {
|
||||
return 'debug';
|
||||
}
|
||||
|
||||
return 'info';
|
||||
return 'error';
|
||||
}
|
||||
|
||||
private static isValidLogLevel(level: string): boolean {
|
||||
|
||||
Reference in New Issue
Block a user