mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
feat(core): refactor shell execution to use node-pty (#6491)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
34
packages/core/src/utils/getPty.ts
Normal file
34
packages/core/src/utils/getPty.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
export type PtyImplementation = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
module: any;
|
||||
name: 'lydell-node-pty' | 'node-pty';
|
||||
} | null;
|
||||
|
||||
export interface PtyProcess {
|
||||
readonly pid: number;
|
||||
onData(callback: (data: string) => void): void;
|
||||
onExit(callback: (e: { exitCode: number; signal?: number }) => void): void;
|
||||
kill(signal?: string): void;
|
||||
}
|
||||
|
||||
export const getPty = async (): Promise<PtyImplementation> => {
|
||||
try {
|
||||
const lydell = '@lydell/node-pty';
|
||||
const module = await import(lydell);
|
||||
return { module, name: 'lydell-node-pty' };
|
||||
} catch (_e) {
|
||||
try {
|
||||
const nodePty = 'node-pty';
|
||||
const module = await import(nodePty);
|
||||
return { module, name: 'node-pty' };
|
||||
} catch (_e2) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user