openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
80 lines (79 loc) • 3.23 kB
JavaScript
import { i as createAbortError } from "./src-BPmQBLJp.mjs";
import "./abort-signal-D4Q6SEw7.mjs";
import { l as getPluginValueInstance } from "./plugin-instance-scope-oezVdCr2.mjs";
import { o as composeSessionSourceAssertion } from "./session-source-authority-TlTpfRVE.mjs";
import { g as resolveAdmittedRunActiveAssertion } from "./admitted-run-context-D3Jvk_f_.mjs";
import { f as resolveReplyExpectation } from "./reply-completion-CrT6uEHT.mjs";
//#region src/agents/cli-runner/execution-target.ts
function unsupportedIsolatedCompletionError(e) {
return Object.assign(/* @__PURE__ */ new Error(`CLI backend "${e}" does not support isolated completion; OpenClaw did not start the run.`), {
name: "IsolatedCompletionUnsupportedError",
code: "unsupported"
});
}
/** Keep all CLI transports bound to the same reply-operation identity and terminal contract. */
function attachCliReplyBackend(e, t, n) {
if (!e.replyOperation) return;
const r = {
kind: "cli",
runId: e.runId,
toolAuthorityFingerprint: e.toolAuthorityFingerprint,
terminalReplyExpectation: resolveReplyExpectation(e),
sourceReplyDeliveryMode: e.sourceReplyDeliveryMode,
taskSuggestionDeliveryMode: e.taskSuggestionDeliveryMode,
cancel: t,
...n,
get turnStatus() {
return n?.turnStatus;
}
};
e.replyOperation.attachBackend(r);
return () => e.replyOperation?.detachBackend(r);
}
/** Capture both the admitted run and any narrower caller-owned execution authority. */
function createCliRunCurrentAssertion(e, t = e.abortSignal) {
const n = e.assertCurrent;
const r = resolveAdmittedRunActiveAssertion(e.admittedRunContext, t);
return composeSessionSourceAssertion([n, composeSessionSourceAssertion([r], (e) => {
if (t?.aborted) throw createAbortError("CLI run aborted");
if (!r) throw new Error("CLI run authority is no longer active");
e();
})]);
}
/** Preparation and execution must agree on the owner of private prompt context. */
function resolveCliExecutionTarget(e) {
const t = e.params.sessionEntry;
if (e.backendId === "claude-cli" && t?.execHost === "node") {
const e = t.execNode?.trim();
if (!e) throw new Error("node-placed Claude CLI session is missing execNode");
return {
kind: "node",
placement: {
nodeId: e,
...t.execCwd?.trim() ? { cwd: t.execCwd.trim() } : {}
}
};
}
return e.execute && e.params.controlOperation !== "compact" ? {
kind: "plugin",
execute: e.execute
} : { kind: "process" };
}
/**
* A plugin hot reload retires the previous backend instance after a bounded call
* drain and then rejects its calls, which discarded turns that finished later.
* A retained consumer keeps every plugin call of one prepared turn (execution
* stream, lifecycle parser, text transforms, cleanup) admitted on that instance
* until the turn's cleanup releases it; the owner's physical cleanup waits for it.
*/
function retainCliPluginExecutionConsumer(e) {
const t = e ? getPluginValueInstance(e) : void 0;
if (!t) return;
try {
return t.retainConsumer();
} catch {
return;
}
}
//#endregion
export { unsupportedIsolatedCompletionError as a, retainCliPluginExecutionConsumer as i, createCliRunCurrentAssertion as n, resolveCliExecutionTarget as r, attachCliReplyBackend as t };