This commit is contained in:
闫旭隆
2026-01-09 11:22:42 +08:00
parent f4314c3ede
commit 202d1cb5ba
1066 changed files with 179639 additions and 7618 deletions

View File

@ -0,0 +1,60 @@
import type { Readable, Writable } from 'stream';
/**
* Represents a spawned process with stdin/stdout streams and lifecycle management.
* Implementers provide this interface to abstract the process spawning mechanism.
* ChildProcess already satisfies this interface.
*/
export interface SpawnedProcess {
/** Writable stream for sending data to the process stdin */
stdin: Writable;
/** Readable stream for receiving data from the process stdout */
stdout: Readable;
/** Whether the process has been killed */
readonly killed: boolean;
/** Exit code if the process has exited, null otherwise */
readonly exitCode: number | null;
/**
* Kill the process with the given signal
* @param signal - The signal to send (e.g., 'SIGTERM', 'SIGKILL')
*/
kill(signal: NodeJS.Signals): boolean;
/**
* Register a callback for when the process exits
* @param event - Must be 'exit'
* @param listener - Callback receiving exit code and signal
*/
on(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): void;
/**
* Register a callback for process errors
* @param event - Must be 'error'
* @param listener - Callback receiving the error
*/
on(event: 'error', listener: (error: Error) => void): void;
/**
* Register a one-time callback for when the process exits
*/
once(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): void;
once(event: 'error', listener: (error: Error) => void): void;
/**
* Remove an event listener
*/
off(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): void;
off(event: 'error', listener: (error: Error) => void): void;
}
/**
* Options passed to the spawn function.
*/
export interface SpawnOptions {
/** Command to execute */
command: string;
/** Arguments to pass to the command */
args: string[];
/** Working directory */
cwd?: string;
/** Environment variables */
env: {
[envVar: string]: string | undefined;
};
/** Abort signal for cancellation */
signal: AbortSignal;
}

View File

@ -0,0 +1,30 @@
import type { StdoutMessage } from '../entrypoints/sdkControlTypes.js';
/**
* Transport interface for Claude Code SDK communication
* Abstracts the communication layer to support both process and WebSocket transports
*/
export interface Transport {
/**
* Write data to the transport
* May be async for network-based transports
*/
write(data: string): void | Promise<void>;
/**
* Close the transport connection and clean up resources
* This also closes stdin if still open (eliminating need for endInput)
*/
close(): void;
/**
* Check if transport is ready for communication
*/
isReady(): boolean;
/**
* Read and parse messages from the transport
* Each transport handles its own protocol and error checking
*/
readMessages(): AsyncGenerator<StdoutMessage, void, unknown>;
/**
* End the input stream
*/
endInput(): void;
}