mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat: add cli args
This commit is contained in:
@@ -73,6 +73,10 @@ export function query({
|
||||
abortController,
|
||||
debug: options.debug,
|
||||
stderr: options.stderr,
|
||||
maxSessionTurns: options.maxSessionTurns,
|
||||
coreTools: options.coreTools,
|
||||
excludeTools: options.excludeTools,
|
||||
authType: options.authType,
|
||||
});
|
||||
|
||||
// Build query options with abortController
|
||||
|
||||
@@ -166,6 +166,22 @@ export class ProcessTransport implements Transport {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.options.maxSessionTurns !== undefined) {
|
||||
args.push('--max-session-turns', String(this.options.maxSessionTurns));
|
||||
}
|
||||
|
||||
if (this.options.coreTools && this.options.coreTools.length > 0) {
|
||||
args.push('--core-tools', this.options.coreTools.join(','));
|
||||
}
|
||||
|
||||
if (this.options.excludeTools && this.options.excludeTools.length > 0) {
|
||||
args.push('--exclude-tools', this.options.excludeTools.join(','));
|
||||
}
|
||||
|
||||
if (this.options.authType) {
|
||||
args.push('--auth-type', this.options.authType);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ export type CreateQueryOptions = {
|
||||
/** Permission mode ('default' | 'plan' | 'auto-edit' | 'yolo') */
|
||||
permissionMode?: PermissionMode;
|
||||
/** Callback invoked before each tool execution */
|
||||
canUseTool?: PermissionCallback;
|
||||
canUseTool?: CanUseTool;
|
||||
|
||||
// Hook system
|
||||
/** Hook configuration for tool execution lifecycle */
|
||||
@@ -107,6 +107,14 @@ export type CreateQueryOptions = {
|
||||
debug?: boolean;
|
||||
/** Callback for stderr output */
|
||||
stderr?: (message: string) => void;
|
||||
/** Maximum number of session turns */
|
||||
maxSessionTurns?: number;
|
||||
/** Core tool paths */
|
||||
coreTools?: string[];
|
||||
/** Tools to exclude */
|
||||
excludeTools?: string[];
|
||||
/** Authentication type */
|
||||
authType?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -131,4 +139,49 @@ export type TransportOptions = {
|
||||
debug?: boolean;
|
||||
/** Callback for stderr output */
|
||||
stderr?: (message: string) => void;
|
||||
/** Maximum number of session turns */
|
||||
maxSessionTurns?: number;
|
||||
/** Core tool paths */
|
||||
coreTools?: string[];
|
||||
/** Tools to exclude */
|
||||
excludeTools?: string[];
|
||||
/** Authentication type */
|
||||
authType?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tool input type
|
||||
* TODO: align this type with actual tool inputs
|
||||
*/
|
||||
type ToolInput = Record<string, unknown>;
|
||||
|
||||
/**
|
||||
* Permission callback function
|
||||
* Called before each tool execution to determine if it should be allowed
|
||||
*
|
||||
* @param toolName - Name of the tool being executed
|
||||
* @param input - Input parameters for the tool
|
||||
* @param options - Options including abort signal
|
||||
* @returns Promise with permission result
|
||||
*/
|
||||
type CanUseTool = (
|
||||
toolName: string,
|
||||
input: ToolInput,
|
||||
options: {
|
||||
signal: AbortSignal;
|
||||
},
|
||||
) => Promise<PermissionResult>;
|
||||
|
||||
/**
|
||||
* Result of permission check
|
||||
*/
|
||||
type PermissionResult =
|
||||
| {
|
||||
behavior: 'allow';
|
||||
updatedInput: ToolInput;
|
||||
}
|
||||
| {
|
||||
behavior: 'deny';
|
||||
message: string;
|
||||
interrupt?: boolean;
|
||||
};
|
||||
|
||||
@@ -48,6 +48,10 @@ export const QueryOptionsSchema = z
|
||||
(message: string) => void
|
||||
>((val) => typeof val === 'function', { message: 'stderr must be a function' })
|
||||
.optional(),
|
||||
maxSessionTurns: z.number().optional(),
|
||||
coreTools: z.array(z.string()).optional(),
|
||||
excludeTools: z.array(z.string()).optional(),
|
||||
authType: z.enum(['openai', 'qwen-oauth']).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user