mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-24 23:21:30 +00:00
refactor: dedupe core config and runtime helpers
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { ChildProcessWithoutNullStreams, SpawnOptions } from "node:child_process";
|
||||
import { killProcessTree } from "../../kill-tree.js";
|
||||
import { spawnWithFallback } from "../../spawn-utils.js";
|
||||
import type { ManagedRunStdin } from "../types.js";
|
||||
import type { ManagedRunStdin, SpawnProcessAdapter } from "../types.js";
|
||||
import { toStringEnv } from "./env.js";
|
||||
|
||||
function resolveCommand(command: string): string {
|
||||
@@ -19,15 +19,7 @@ function resolveCommand(command: string): string {
|
||||
return command;
|
||||
}
|
||||
|
||||
export type ChildAdapter = {
|
||||
pid?: number;
|
||||
stdin?: ManagedRunStdin;
|
||||
onStdout: (listener: (chunk: string) => void) => void;
|
||||
onStderr: (listener: (chunk: string) => void) => void;
|
||||
wait: () => Promise<{ code: number | null; signal: NodeJS.Signals | null }>;
|
||||
kill: (signal?: NodeJS.Signals) => void;
|
||||
dispose: () => void;
|
||||
};
|
||||
export type ChildAdapter = SpawnProcessAdapter<NodeJS.Signals | null>;
|
||||
|
||||
export async function createChildAdapter(params: {
|
||||
argv: string[];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { killProcessTree } from "../../kill-tree.js";
|
||||
import type { ManagedRunStdin } from "../types.js";
|
||||
import type { ManagedRunStdin, SpawnProcessAdapter } from "../types.js";
|
||||
import { toStringEnv } from "./env.js";
|
||||
|
||||
const FORCE_KILL_WAIT_FALLBACK_MS = 4000;
|
||||
@@ -32,15 +32,7 @@ type PtyModule = {
|
||||
};
|
||||
};
|
||||
|
||||
export type PtyAdapter = {
|
||||
pid?: number;
|
||||
stdin?: ManagedRunStdin;
|
||||
onStdout: (listener: (chunk: string) => void) => void;
|
||||
onStderr: (listener: (chunk: string) => void) => void;
|
||||
wait: () => Promise<{ code: number | null; signal: NodeJS.Signals | number | null }>;
|
||||
kill: (signal?: NodeJS.Signals) => void;
|
||||
dispose: () => void;
|
||||
};
|
||||
export type PtyAdapter = SpawnProcessAdapter;
|
||||
|
||||
export async function createPtyAdapter(params: {
|
||||
shell: string;
|
||||
|
||||
@@ -54,6 +54,16 @@ export type ManagedRunStdin = {
|
||||
destroyed?: boolean;
|
||||
};
|
||||
|
||||
export type SpawnProcessAdapter<WaitSignal = NodeJS.Signals | number | null> = {
|
||||
pid?: number;
|
||||
stdin?: ManagedRunStdin;
|
||||
onStdout: (listener: (chunk: string) => void) => void;
|
||||
onStderr: (listener: (chunk: string) => void) => void;
|
||||
wait: () => Promise<{ code: number | null; signal: WaitSignal }>;
|
||||
kill: (signal?: NodeJS.Signals) => void;
|
||||
dispose: () => void;
|
||||
};
|
||||
|
||||
type SpawnBaseInput = {
|
||||
runId?: string;
|
||||
sessionId: string;
|
||||
|
||||
Reference in New Issue
Block a user