openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
133 lines (132 loc) • 4.95 kB
JavaScript
import { t as pruneMapToMaxSize } from "./map-size-BBr20tbc.mjs";
//#region src/agents/agent-tools.before-tool-call.state.ts
/** Detached execution facts; internal readers borrow the same snapshot. */
const adjustedParamsByToolCallId = /* @__PURE__ */ new Map();
const preExecutionBlockedToolCallIds = /* @__PURE__ */ new Set();
const structuredReplaySafeToolCallIds = /* @__PURE__ */ new Set();
const trackedToolCallIds = /* @__PURE__ */ new Map();
const batchAdmittedToolCallIds = /* @__PURE__ */ new Set();
function buildAdjustedParamsKey(e) {
if (e.runId && e.runId.trim()) return `${e.runId}:${e.toolCallId}`;
return e.toolCallId;
}
/** Detach before mutable execution; mutable hook/middleware inputs get their own copies. */
function recordAdjustedParamsForToolCall(e, t, n) {
if (!e) return;
let r;
try {
r = structuredClone(t);
} catch {
return;
}
adjustedParamsByToolCallId.set(buildAdjustedParamsKey({
runId: n,
toolCallId: e
}), r);
pruneMapToMaxSize(adjustedParamsByToolCallId, 1024);
}
/** Consume and remove hook-adjusted params for a completed tool call. */
function consumeAdjustedParamsForToolCall(e, t) {
const n = buildAdjustedParamsKey({
runId: t,
toolCallId: e
});
const r = adjustedParamsByToolCallId.get(n);
adjustedParamsByToolCallId.delete(n);
return r;
}
/** Borrow execution facts without consuming later outcome bookkeeping. */
function peekAdjustedParamsForToolCall(e, t) {
return adjustedParamsByToolCallId.get(buildAdjustedParamsKey({
runId: t,
toolCallId: e
}));
}
/** Consume whether policy prevented the target tool from starting. */
function consumePreExecutionBlockedToolCall(e, t) {
return preExecutionBlockedToolCallIds.delete(buildAdjustedParamsKey({
runId: t,
toolCallId: e
}));
}
/** Snapshot whether policy prevented execution without stealing cleanup from the tool owner. */
function peekPreExecutionBlockedToolCall(e, t) {
return preExecutionBlockedToolCallIds.has(buildAdjustedParamsKey({
runId: t,
toolCallId: e
}));
}
/** Record active wrapper ownership so a racing timeout can inspect the boundary. */
function recordToolExecutionTracked(e, t) {
const n = buildAdjustedParamsKey({
runId: t,
toolCallId: e
});
if (!trackedToolCallIds.has(n)) trackedToolCallIds.set(n, false);
}
function recordToolExecutionStarted(e, t) {
trackedToolCallIds.set(buildAdjustedParamsKey({
runId: t,
toolCallId: e
}), true);
}
/** Release execution-boundary evidence when the wrapped invocation settles. */
function clearTrackedToolExecution(e, t) {
trackedToolCallIds.delete(buildAdjustedParamsKey({
runId: t,
toolCallId: e
}));
}
/**
* Consume exact in-flight execution state. Undefined means the wrapper already
* settled or the producer does not participate in OpenClaw boundary tracking.
*/
function consumeTrackedToolExecutionStarted(e, t) {
const n = buildAdjustedParamsKey({
runId: t,
toolCallId: e
});
const r = trackedToolCallIds.get(n);
trackedToolCallIds.delete(n);
return r;
}
function recordStructuredReplaySafeToolCall(e, t) {
structuredReplaySafeToolCallIds.add(buildAdjustedParamsKey({
runId: t,
toolCallId: e
}));
}
function consumeStructuredReplaySafeToolCall(e, t) {
return structuredReplaySafeToolCallIds.delete(buildAdjustedParamsKey({
runId: t,
toolCallId: e
}));
}
/** Mark a call whose loop policy was already admitted with its whole assistant batch. */
function recordBatchAdmittedToolCall(e, t) {
batchAdmittedToolCallIds.add(buildAdjustedParamsKey({
runId: t,
toolCallId: e
}));
}
/** Consume whole-batch loop admission while leaving the remaining tool policies intact. */
function consumeBatchAdmittedToolCall(e, t) {
return batchAdmittedToolCallIds.delete(buildAdjustedParamsKey({
runId: t,
toolCallId: e
}));
}
/** Release exact batch-admission markers for prepared calls suppressed by steering. */
function releaseBatchAdmittedToolCalls(e, t) {
for (const n of e) batchAdmittedToolCallIds.delete(buildAdjustedParamsKey({
runId: t,
toolCallId: n
}));
}
/** Remove unused batch-admission markers when their embedded run ends. */
function clearBatchAdmittedToolCallsForRun(e) {
const t = `${e}:`;
for (const e of batchAdmittedToolCallIds) if (e.startsWith(t)) batchAdmittedToolCallIds.delete(e);
}
//#endregion
export { releaseBatchAdmittedToolCalls as _, consumeBatchAdmittedToolCall as a, consumeTrackedToolExecutionStarted as c, preExecutionBlockedToolCallIds as d, recordAdjustedParamsForToolCall as f, recordToolExecutionTracked as g, recordToolExecutionStarted as h, consumeAdjustedParamsForToolCall as i, peekAdjustedParamsForToolCall as l, recordStructuredReplaySafeToolCall as m, clearBatchAdmittedToolCallsForRun as n, consumePreExecutionBlockedToolCall as o, recordBatchAdmittedToolCall as p, clearTrackedToolExecution as r, consumeStructuredReplaySafeToolCall as s, buildAdjustedParamsKey as t, peekPreExecutionBlockedToolCall as u, structuredReplaySafeToolCallIds as v };