feat(mcp): 引入 MCP 单工具网关模式 (hose_cli) 与并发流调度并发布 v0.4.0
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled
This commit is contained in:
1 parent
4f510efc1b
commit
9e20caf4a3
9 files changed
+468
-38
No files matched your search
+46
-1
@@ -15,7 +15,52 @@ import { handleOpenApiCommand } from "./commands/openapi.js";
|
||||
import { handleBillCommand } from "./commands/bill.js";
|
||||
import type { CliResult, CliRunOptions } from "./types.js";
|
||||
|
||||
export async function runCli(
|
||||
let runQueue = Promise.resolve<any>(undefined);
|
||||
|
||||
export function runCli(
|
||||
rawArgs: string[],
|
||||
options: CliRunOptions = {}
|
||||
): Promise<CliResult> {
|
||||
const run = runQueue.then(() => runCliOnce(rawArgs, options));
|
||||
runQueue = run.then(
|
||||
() => undefined,
|
||||
() => undefined
|
||||
);
|
||||
return run;
|
||||
}
|
||||
|
||||
async function runCliOnce(
|
||||
rawArgs: string[],
|
||||
options: CliRunOptions = {}
|
||||
): Promise<CliResult> {
|
||||
const stdoutChunks: string[] = [];
|
||||
const stderrChunks: string[] = [];
|
||||
const originalLog = console.log;
|
||||
const originalError = console.error;
|
||||
|
||||
console.log = (...values: unknown[]) => {
|
||||
stdoutChunks.push(values.map((v) => (typeof v === "string" ? v : String(v))).join(" "));
|
||||
};
|
||||
console.error = (...values: unknown[]) => {
|
||||
stderrChunks.push(values.map((v) => (typeof v === "string" ? v : String(v))).join(" "));
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await dispatchCli(rawArgs, options);
|
||||
const extraStdout = stdoutChunks.length ? `${stdoutChunks.join("\n")}\n` : "";
|
||||
const extraStderr = stderrChunks.length ? `${stderrChunks.join("\n")}\n` : "";
|
||||
return {
|
||||
stdout: extraStdout + (result.stdout || ""),
|
||||
stderr: extraStderr + (result.stderr || ""),
|
||||
exitCode: result.exitCode,
|
||||
};
|
||||
} finally {
|
||||
console.log = originalLog;
|
||||
console.error = originalError;
|
||||
}
|
||||
}
|
||||
|
||||
async function dispatchCli(
|
||||
rawArgs: string[],
|
||||
options: CliRunOptions = {}
|
||||
): Promise<CliResult> {
|
||||
|
||||
Reference in new issue
Block a user