UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1,173 lines (1,172 loc) • 46.7 kB
import { v as floorPositiveFiniteNumber } from "./number-coercion-D6u-4YD8.mjs"; import { n as containsAsciiControlCharacter } from "./string-normalization-DLmfYZXI.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { o as getAsyncWorkSignal } from "./async-work-scope-BXagjUap.mjs"; import { l as withPluginRuntimeGatewayRequestScope, o as getPluginRuntimeGatewayRequestScope } from "./gateway-request-scope-BvvDhs5D.mjs"; import { o as getGatewayContextResolver } from "./gateway-context-binding-BdXZoMU9.mjs"; import { c as isPathInside, m as readLocalFileFromRoots, x as resolveLocalPathFromRootsSync } from "./fs-safe-BbWvmdVn.mjs"; import { a as isSameOpenClawAgentDatabasePath } from "./openclaw-agent-db.paths-DJxv80ws.mjs"; import { S as resolveSessionAgentIdStrict } from "./agent-scope-config-DmXgFGKP.mjs"; import { b as getActiveDiagnosticTraceContext } from "./diagnostics-timeline-CSwiG24r.mjs"; import { n as captureOpenClawStateReadWorkerContext } from "./openclaw-state-worker-context-DAKL_dnZ.mjs"; import { n as createRuntimeConfigReader } from "./runtime-snapshot-WbwbY5b7.mjs"; import { t as DEFAULT_CONTEXT_TOKENS } from "./defaults-BWyoTPqn.mjs"; import "./agent-scope-BwB8YH6y.mjs"; import { u as emitAgentRunOutputTokens } from "./agent-events-BdfWYmot.mjs"; import { a as capturePluginLifecycleAuthority } from "./registry-lifecycle-CJjWnl-y.mjs"; import { l as getActivePluginRegistry } from "./runtime-ezCEpumg.mjs"; import { t as warnPluginSdkDeprecation } from "./sdk-deprecation-D5N9acnu.mjs"; import { a as getActiveSecretsRuntimeConfigSnapshot } from "./runtime-state-Dq_fFDZp.mjs"; import { n as getUserTurnTranscriptAdmissionOwner } from "./user-turn-transcript-admission-BdVewOwR.mjs"; import { l as getAdmittedRunDelegatedAuthority, p as readAdmittedRunOperatorAuthority, v as retainAdmittedRunBeforeToolCallRecovery } from "./admitted-run-context-D3Jvk_f_.mjs"; import { g as throwAgentRunRestartAbortReason } from "./run-termination-0Ig0-bk6.mjs"; import { i as captureExecRequestCustody } from "./exec-request-context-C8VKkMcB.mjs"; import { o as isToolExecutionAllowed } from "./tool-policy-shared-BHvBopvF.mjs"; import { d as withGatewayToolApprovalOwner, f as withGatewayToolCallerIdentity, o as getGatewayToolCallerIdentity, r as createAdmittedGatewayToolCallerIdentity } from "./gateway-caller-context-BNidAW8G.mjs"; import { v as createCronScheduledToolProjection } from "./agent-tool-metadata-nrQgRaqv.mjs"; import { i as readSessionEntryReadOnlyInWorker, l as withSessionEntryReadOnlyInWorker } from "./session-entry-read-runtime-1Fp1sybj.mjs"; import { r as resolveSqliteSessionKey } from "./session-accessor.sqlite-scope-helpers-5_tKUULP.mjs"; import { a as readCapturedSessionActorEntry, t as captureSessionActorStorageOwner } from "./session-actor-storage-binding-DMwpDsij.mjs"; import "./session-accessor.sqlite-scope-Cbj2BdoG.mjs"; import { _ as retainPreparedSessionEntryPredicate } from "./session-accessor.sqlite-entry-cache-publication-state-B4mkg2yK.mjs"; import { r as snapshotTranscriptTurnAdmission } from "./transcript-entry-anchor-D4uSx3rE.mjs"; import { p as readPersistedMediaFacts } from "./media-facts-B-0Dpo5L.mjs"; import { U as prepareUserTurnTranscriptAnnotation, d as rewritePreparedTranscriptMessageAtAnchor, m as persistCompactionBoundaryWithSessionEntryAsync } from "./session-accessor-CizTbDQj.mjs"; import { n as estimateTokens, t as IMAGE_BLOCK_TOKENS } from "./compaction-cut-point-CEj7MSFJ.mjs"; import { f as readModelPromptProjection, u as prepareModelPromptProjection } from "./session-transcript-rewrite-effects-BVKR4US3.mjs"; import { i as sessionMatchesExpectedTranscriptTurn } from "./session-transcript-turn-state-CviQGehX.mjs"; import { l as waitForSessionTranscriptProjection } from "./session-transcript-reconcile-CtdkqWN1.mjs"; import { t as SessionRowProjectionBinding } from "./session-row-projection-binding-TqlL_YAz.mjs"; import { g as withOwnedSessionTranscriptWrites, u as getOwnedSessionTranscriptWriterFence } from "./transcript-write-context-_7rz2F7z.mjs"; import { n as publishTranscriptUpdate } from "./session-accessor.sqlite-events-PQ5j_e7R.mjs"; import { r as resolveSessionTranscriptDatabasePath } from "./session-accessor.transcript-target-njOktg4F.mjs"; import { t as readActiveTranscriptEntryAnchor } from "./session-accessor.sqlite-transcript-admitted-read-DDDhDNR7.mjs"; import { C as resolveAgentQuestionAnswerAuthority, T as withAgentQuestionAnswerAuthority, _ as registerAgentHarnessBeforeToolCallRetention, b as registerAgentHarnessTtsProvenanceTransferCapability, y as registerAgentHarnessScheduledToolProjectionCapability } from "./host-private-capabilities-DDumj0c_.mjs"; import { f as runBeforeToolCallHook } from "./agent-tools.before-tool-call.wrapper-Dh3maIc2.mjs"; import { l as getPreparedModelRuntimePolicyConfigReader } from "./prepared-model-runtime-auth-DVZroiat.mjs"; import { c as prepareGitHubToolEnvironment } from "./github-tool-identity-41SK6r8O.mjs"; import { i as resolveMaxActiveTranscriptBytes, t as BOUNDED_CONTEXT_NOTICE } from "./transcript-byte-limit-SRI2OVpS.mjs"; import { n as resolveEffectiveToolFsWorkspaceOnly } from "./tool-fs-policy-dDd9W7xo.mjs"; import { i as normalizePathPrepend, n as findPathKey, t as applyPathPrepend } from "./path-prepend-HpofbiEN.mjs"; import { a as withInstallationTarget, n as getInstallationTarget, r as installationTargetEnv } from "./installation-target-context-C_xR1SHA.mjs"; import { t as callGatewayTool } from "./gateway-DL_Nxi-v.mjs"; import "./agent-tools.before-tool-call-CCkSq-k3.mjs"; import { t as log } from "./logger-DgCpB-Fs.mjs"; import { n as resolveExecToolConfig } from "./lazy-exec-tool-C-cI3niu.mjs"; import "./compaction-z9gtIF8y.mjs"; import { r as createCompactionRequestBudget } from "./request-budget-CDN2iAaH.mjs"; import { r as readSessionManagerContextAsync } from "./session-manager-incognito-BWxlXR5_.mjs"; import { a as prepareSkillLibrarySelection, i as loadSkillLibrarySelection } from "./selection-Bz10gm8A.mjs"; import { t as resolveSkillResourceCandidates } from "./resource-candidates-Bu5qK5ix.mjs"; import { s as prepareSystemRunMutableFileApproval } from "./system-run-approval-binding-B3btPgad.mjs"; import { n as createOpenClawCodingToolsInternalAsync, o as buildHarnessHostRequester } from "./agent-tools.async-b-kGzZ4n.mjs"; import { t as resolveToolLoopDetectionConfig } from "./tool-loop-detection-config-Dzb0KwUj.mjs"; import { t as buildAgentHookContextChannelFields } from "./hook-agent-context-sUFGgK45.mjs"; import { t as buildActiveNodeContextText } from "./active-node-context-Cw5OntFe.mjs"; import { o as transferCoreTtsToolResultProvenance, r as getCoreTtsToolResultMediaUrls } from "./tts-tool-result-provenance-DWw-9hLr.mjs"; import { i as bindHarnessNativeSpawnAuthority, n as bindHarnessHostSourceAuthority, r as bindHarnessModelExecution, s as retainHarnessSource } from "./host-source-authority-BR6Oinwf.mjs"; import { t as formatHarnessApprovalPresentation } from "./native-hook-relay-approval-presentation-D71fPg2_.mjs"; import { t as boundContextEngineAssembly } from "./bounded-context-yBBMHkX4.mjs"; import { t as MAX_SKILL_INSTRUCTION_BYTES } from "./installed-skill-catalog-CG4V1K2u.mjs"; import { n as createOpenClawCodingToolsInternal } from "./agent-tools-BMYUjZQ6.mjs"; import { t as captureSessionEntryCurrentCheckAsyncInternal } from "./session-entry-current-check-F4LSgnxb.mjs"; import { t as runBestEffortCallback } from "./embedded-agent-subscribe.callback-DQMmolWU.mjs"; import { n as requireCompactionWriterEntry } from "./compaction-successor-hCQ2tiCH.mjs"; import { t as attachCompactionAccountingRecorder } from "./compaction-accounting-bridge-BYYhZqhH.mjs"; import { i as resolveSandboxSkillRuntimeInputs } from "./sandbox-skills-B_GxuUqP.mjs"; import { t as prepareInstalledSkillCatalog } from "./installed-skill-runtime-0MS9fAu5.mjs"; import { i as captureRequiredWorkspaceToolFloor, o as prepareHostWorkspaceReadiness, r as bindHostContinuationRetryCount, s as cloneHostSnapshot, t as bindHostToolSurface } from "./host-bound-tool-DQpDDt09.mjs"; import { t as registerMcpToolApprovalBinding } from "./mcp-tool-approval-binding-BOf-khMN.mjs"; import { t as bindHarnessReplyMedia } from "./reply-media-BaghL9kd.mjs"; import path from "node:path"; import { isDeepStrictEqual } from "node:util"; //#region src/sessions/user-turn-transcript-annotation.ts /** Core-only binding performed by the harness host before invoking plugin code. */ function bindUserTurnTranscriptAnnotation(e) { const t = getUserTurnTranscriptAdmissionOwner(e.recorder); const n = t?.receipt(); const r = t?.message(); if (!t || !n || !r || t.blocked() || r.excludeFromContext === true) return; let i = snapshotTranscriptTurnAdmission(n); let a = structuredClone(r); const o = { ...e.target }; const s = getOwnedSessionTranscriptWriterFence({ sessionTarget: o }); if (o.sessionId !== i.sessionId || o.sessionKey !== i.sessionKey || o.agentId !== i.agentId || !isSameOpenClawAgentDatabasePath(resolveSessionTranscriptDatabasePath(o), i.storePath)) return; const assertLive = () => { e.assertCurrent(); const n = t.receipt(); const r = t.message(); const o = readModelPromptProjection(r); if (n && r && o !== void 0 && readModelPromptProjection(a) === void 0 && isDeepStrictEqual(n, { ...i, generation: n.generation }) && isDeepStrictEqual(r, prepareModelPromptProjection(a, o))) { i = snapshotTranscriptTurnAdmission(n); a = structuredClone(r); } if (e.abortSignal?.aborted || t.blocked() || !isDeepStrictEqual(t.receipt(), i) || !isDeepStrictEqual(t.message(), a) || a["__openclaw"]?.steerTargetRunId !== void 0) throw new Error("current user admission is no longer available for native annotation"); }; return async (n) => { const r = { mirrorIdentity: n.mirrorIdentity, upstreamUserText: n.upstreamUserText, mirrorOrigin: n.mirrorOrigin, mirrorSourceFingerprint: n.mirrorSourceFingerprint }; assertLive(); const c = await captureSessionEntryCurrentCheckAsyncInternal({ agentId: o.agentId, sessionKey: o.sessionKey, storePath: o.storePath, fields: [ "sessionId", "lifecycleRevision", "activeWriterRunId" ], errorMessage: "current user admission is no longer available for native annotation" }); try { const n = c.entry; if (!n || n.sessionId !== i.sessionId || n.activeWriterRunId !== void 0 && n.activeWriterRunId !== e.runId) throw new Error("current user admission is no longer available for native annotation"); const l = o.expectedLifecycleRevision ?? s?.expectedLifecycleRevision ?? n.lifecycleRevision ?? null; const u = o.expectedWriterRunId ?? s?.expectedWriterRunId; if (!sessionMatchesExpectedTranscriptTurn({ entry: n }, { expectedSessionId: i.sessionId, expectedLifecycleRevision: l, expectedWriterRunId: u }) || s?.expectedWriterRunId !== void 0 && n.activeWriterRunId !== s.expectedWriterRunId || s?.expectedLifecycleRevision !== void 0 && n.lifecycleRevision !== s.expectedLifecycleRevision) throw new Error("current user admission is no longer available for native annotation"); const assertNativeCurrent = () => { assertLive(); c.source(); const { logicalTurnId: e, role: t, ...n } = i; if (!isDeepStrictEqual(readActiveTranscriptEntryAnchor(i), n)) throw new Error("current user admission is no longer available for native annotation"); }; let d = false; const { logicalTurnId: f, role: p, ...m } = i; const h = await rewritePreparedTranscriptMessageAtAnchor(m, (t) => { assertLive(); if (!isDeepStrictEqual(t, a)) throw new Error("native prompt annotation cannot replace an edited admission"); const n = prepareUserTurnTranscriptAnnotation(a, r, e.runId); d = true; return isDeepStrictEqual(n, a) ? void 0 : n; }, { active: "exact", expectedEntry: { lifecycleRevision: l, activeWriterRunId: u ?? n.activeWriterRunId ?? null }, assertCurrent: assertLive, assertNativeCurrent }); if (!d) throw new Error("native prompt admission disappeared before annotation"); if (h) { i = { ...i, generation: h.generation }; a = structuredClone(h.message); t.refresh({ ...i }, h.message); await waitForSessionTranscriptProjection(i, e.abortSignal); } assertLive(); if (h) { await publishTranscriptUpdate(i, { message: h.message, messageId: i.entryId, messageSeq: i.activeMessagePosition + 1 }); assertLive(); } } finally { c.release(); } }; } //#endregion //#region src/agents/harness/host-delegation-policy.ts /** Capture the admitted reader before async tool preparation; explicit plugin configs stay scoped. */ function captureHostDelegationPolicy(e, t) { const n = e.config; const r = getPreparedModelRuntimePolicyConfigReader(e.preparedModelRuntime) ?? (n ? createRuntimeConfigReader(n) : void 0); return (e) => t() || !e.config || e.config === n ? r : createRuntimeConfigReader(e.config); } //#endregion //#region src/agents/harness/host-environment.ts const MAX_NATIVE_OPERATION_CWD_BYTES = 4096; function normalizeNativeOperationCwd(e, t) { if (typeof e !== "string") throw new Error("native operation cwd must be a string"); const n = e.trim(); if (!n) throw new Error("native operation cwd must not be empty"); if (Buffer.byteLength(n, "utf8") > MAX_NATIVE_OPERATION_CWD_BYTES) throw new Error(`native operation cwd must not exceed ${MAX_NATIVE_OPERATION_CWD_BYTES} bytes`); if (containsAsciiControlCharacter(n)) throw new Error("native operation cwd must not contain control characters"); return path.resolve(t ?? process.cwd(), n); } /** Capture non-secret environment facts once; the harness owns their placement. */ function prepareAgentHarnessEnvironment(e) { const t = resolveExecToolConfig({ cfg: e.config, agentId: e.sandboxAgentId ?? resolveSessionAgentIdStrict(e) }); const n = normalizePathPrepend(t.configuredPathPrepend).length > 0; const r = findPathKey(process.env); const i = n ? { [r]: process.env[r] ?? "" } : void 0; const a = n ? Object.freeze(normalizePathPrepend(t.pathPrepend)) : void 0; if (i && a) { applyPathPrepend(i, [...a]); Object.freeze(i); } const o = prepareGitHubToolEnvironment({ config: e.config ?? {}, sourceConfig: getActiveSecretsRuntimeConfigSnapshot()?.sourceConfig, agentId: resolveSessionAgentIdStrict(e) }); const s = installationTargetEnv(e.installationTarget); return Object.freeze({ ...o, ...s ? { localProcessEnv: s } : {}, ...i ? { localToolEnv: i, localToolPathPrepend: a } : {} }); } //#endregion //#region src/agents/harness/host-media.ts /** Bind media capabilities to the same captured attempt policy and host lifetime. */ function bindHarnessMedia(e) { const { attempt: t, config: n, assertActive: r } = e; const i = t.abortSignal; const a = t.workspaceDir; const o = t.timeoutMs; const s = { media: structuredClone(t.inputAttachmentMedia ?? t.media), userTurnTranscriptRecorder: t.userTurnTranscriptRecorder }; const resolveInputAttachmentMedia = async () => { r(); i?.throwIfAborted(); const e = s.userTurnTranscriptRecorder; const t = await e?.resolveMessage() ?? e?.message; r(); i?.throwIfAborted(); const n = structuredClone((t ? readPersistedMediaFacts(t) : void 0) ?? s.media ?? []); return Object.freeze(n.map((e) => Object.freeze(e))); }; const c = !t.sandbox?.enabled && !t.requireWorkspaceOnly && !t.modelRun && t.promptMode !== "none" && (!t.permissionMode || t.permissionMode === "full") && !resolveEffectiveToolFsWorkspaceOnly({ cfg: n, agentId: t.agentId }); let l = false; const u = a && o !== void 0 ? async (e) => { const assertCurrent = () => { r(); i?.throwIfAborted(); e.signal?.throwIfAborted(); e.assertCurrent(); }; assertCurrent(); if (!l || !c) return; const { prepareAgentWorkspaceAttachments: t } = await import("./workspace-access-DEg5wSt6.mjs"); assertCurrent(); const u = await t({ workspaceDir: a, localExecution: { config: n, readAllowed: l, maxChars: e.maxChars }, turn: { ...e.turn ?? s, config: n, timeoutMs: o, abortSignal: e.signal ?? i }, assertCurrent }); assertCurrent(); return u; } : void 0; let prepareContextMedia; if (t.workspaceDir && t.model) { const e = { config: n, workspaceDir: t.sandbox?.enabled ? t.sandbox.workspaceDir : t.workspaceDir, agentWorkspaceDir: t.workspaceDir, modelInput: t.model.input, agentId: t.agentId, sessionKey: t.sessionKey, sessionId: t.sessionId, channelId: t.messageChannel ?? t.messageProvider, accountId: t.agentAccountId, ...t.sandbox?.enabled && t.sandbox.fsBridge ? { sandbox: { root: t.sandbox.workspaceDir, bridge: t.sandbox.fsBridge } } : {} }; const assertCurrent = () => { r(); t.abortSignal?.throwIfAborted(); }; prepareContextMedia = async (t) => { assertCurrent(); const { prepareHarnessContextMedia: n } = await import("./context-media-runtime-BwYnt4sS.mjs"); assertCurrent(); const r = await n({ ...t, ...e, assertCurrent, signal: i }); assertCurrent(); return r; }; } const d = bindHarnessReplyMedia(e); const fitCurrentInput = async (e) => { r(); const { fitOversizedCurrentInput: t } = await import("./current-input-budget-X7iGUIhZ.mjs"); return await t(e); }; return { capabilities: { resolveInputAttachmentMedia, fitCurrentInput, ...prepareContextMedia ? { prepareContextMedia } : {}, ...u ? { prepareInputAttachments: u } : {}, ...d ? { prepareReplyMedia: d } : {} }, setInputAttachmentReadAllowed: (e) => { r(); l = e; } }; } //#endregion //#region src/agents/harness/host-seed.ts function combineSignals(e, t) { return e && t ? AbortSignal.any([e, t]) : e ?? t; } /** The admitted host owns summary persistence; native threads only consume the bounded view. */ function bindBoundedSeed(e, t, n, r, i) { const { config: a, workspaceDir: o, contextEngine: s } = e; const c = e.preparedSessionTarget?.target ?? e.sessionTarget; const { agentId: l, sessionId: u, sessionKey: d, storePath: f } = c ?? {}; const p = resolveMaxActiveTranscriptBytes(a); if (!c || !l || !u || !d || !f || !o || p === void 0 || s && s.info.id !== "legacy") return; const m = floorPositiveFiniteNumber(e.contextTokenBudget) || 2e5; const h = { ...c, agentId: l, sessionId: u, sessionKey: d, storePath: f }; const g = { ...e, sessionTarget: h, abortSignal: combineSignals(r, e.abortSignal) }; const _ = i?.capabilities.prepareContextMedia; const v = /* @__PURE__ */ new WeakMap(); const assertSource = () => { t(); g.abortSignal?.throwIfAborted(); g.preparedSessionTarget?.assertCurrent(); }; const prepare = async ({ assertCurrent: e, signal: t, tokenBudget: n }) => { const r = combineSignals(t, g.abortSignal); const assert = () => { r?.throwIfAborted(); assertSource(); e(); }; assert(); const i = g.userTurnTranscriptRecorder?.getAdmissionReceipt(); const s = floorPositiveFiniteNumber(n); const c = s && s < m ? s : m; const l = Math.min(p, c * 4); const u = i?.idempotencyKey ?? g.userTurnTranscriptRecorder?.message?.idempotencyKey; const isAdmittedUser = (e) => e.role === "user" && Boolean(u) && Reflect.get(e, "idempotencyKey") === u; const d = g.pluginRuntimeRefreshMessages; const f = d || g.continuation ? [...d ?? [], ...g.continuation?.messages ?? []] : void 0; let y = 0; let b = 0; let x = 0; let S = 0; const read = async () => { const e = await readSessionManagerContextAsync(h, (e, t, n) => { if (!n) throw new Error("Native seed read did not return its selection facts"); return { messages: Array.from(e), facts: n }; }, { signal: r, seed: { maxBytes: l, tokenBudget: c, admittedKey: u, beforeAdmittedUser: Boolean(f) } }); assert(); const { messages: t, facts: n } = e; x = n.retainedInputTokens; if (f) { const e = [...d && n.admittedUser && !f.some(isAdmittedUser) ? [n.admittedUser] : [], ...f]; y = e.length; return { messages: [...t, ...e], facts: n }; } return e; }; const select = async (e, t) => { b = t.omittedCount; const n = y ? e.slice(0, -y) : e; const r = y ? e.slice(-y) : []; const i = { messages: n, estimatedTokens: 0 }; if (!b && !_ && !y) return n; const a = /* @__PURE__ */ new Map(); if (_) for (const e of y ? [...i.messages, ...r] : i.messages) { if (e.role !== "user" && e.role !== "assistant") continue; const t = await _({ message: e, maxChars: c * 4 }); assert(); v.set(e, t); a.set(e, Buffer.byteLength(t.text ?? "", "utf8") + (t.text ? 2 : 0) + t.images.length * IMAGE_BLOCK_TOKENS * 4); } const o = r.reduce((e, t) => e + estimateTokens(t) + Math.ceil((a.get(t) ?? 0) / 4), 0); if (o > c) throw new Error("Active native continuation exceeds the history delivery allowance"); let s = c - o; let l = Math.min(p, s * 4); const boundHistory = () => boundContextEngineAssembly(i, l, s, a).messages; let u = boundHistory(); b = t.omittedCount + n.length - u.length; if (b) { const e = { role: "user", content: BOUNDED_CONTEXT_NOTICE, timestamp: 0 }; s -= estimateTokens(e); l = Math.min(p - Buffer.byteLength(JSON.stringify(e)) - 1, s * 4); if (l < 2) throw new Error("Native history allowance cannot fit its omission notice"); S = Math.floor(l / 4); const a = t.summary ?? n.findLast((e) => e.role === "compactionSummary"); const o = a ? Buffer.byteLength(JSON.stringify(a)) + 1 : 0; const c = a ? estimateTokens(a) : 0; const d = a && o + 2 <= l && c <= s ? [a] : []; l -= d.length ? o : 0; s -= d.length ? c : 0; if (d.length) i.messages = i.messages.filter((e) => e !== a); u = boundHistory(); b = t.omittedCount + n.length - u.length; return [ e, ...d, ...u, ...r ]; } return y ? [...u, ...r] : u; }; let C = await read(); let w = await select(C.messages, C.facts); if (a?.agents?.defaults?.compaction?.enabled !== false && (C.facts.omittedNonSummary || C.messages.slice(0, b - C.facts.omittedCount).some((e) => e.role !== "compactionSummary"))) { const e = await readSessionEntryReadOnlyInWorker({ ...h, readConsistency: "latest" }, assert); if (!e || e.sessionId !== h.sessionId) throw new Error("Session changed before preparing native thread history"); const t = { sessionId: h.sessionId, lifecycleRevision: h.expectedLifecycleRevision ?? e.lifecycleRevision, activeWriterRunId: h.expectedWriterRunId ?? e.activeWriterRunId }; requireCompactionWriterEntry(e, t); const n = { ...h, expectedLifecycleRevision: t.lifecycleRevision, expectedWriterRunId: t.activeWriterRunId, expectedOwner: t }; const a = {}; attachCompactionAccountingRecorder(a, { pendingRequestState: "unresolved", pendingUserEntryId: i?.entryId, requestBudget: createCompactionRequestBudget({ contextWindow: x + S, reserveTokens: 0 }) }); const { compactEmbeddedAgentSessionDirect: s } = await import("./compact-DIgIXwtI.mjs"); assert(); await withOwnedSessionTranscriptWrites({ sessionTarget: n, assertCommitAllowed: assert, withTranscriptWrite: async (e) => e() }, () => s({ ...g, sessionId: h.sessionId, sessionKey: h.sessionKey, sessionFile: h.sessionKey, sessionTarget: h, workspaceDir: o, model: g.modelId, senderId: g.senderId ?? void 0, senderName: g.senderName ?? void 0, senderUsername: g.senderUsername ?? void 0, senderE164: g.senderE164 ?? void 0, contextEngineRuntimeContext: a, trigger: "budget", abortSignal: r }, (e) => persistCompactionBoundaryWithSessionEntryAsync(n, { prepared: e, transcriptByteCompactionLatch: null }, assert))); assert(); C = await read(); w = await select(C.messages, C.facts); } assert(); if (b) { try { await g.onAgentEvent?.({ stream: "compaction", data: { phase: "context_bounded" } }); } catch (e) { log.warn(`bounded seed observer failed: ${formatErrorMessage(e)}`); } assert(); } return w; }; return { prepareBoundedSeed: (e) => n(() => prepare(e), e.signal), prepareContextMedia: _ && (async (e) => { assertSource(); const t = v.get(e.message) ?? await _(e); assertSource(); return t; }) }; } //#endregion //#region src/agents/harness/host-skills.ts /** Carry the admitted pin's prepared entries through awaited tool construction. */ async function prepareHostSkillLibraryResources(e, t) { const n = captureOpenClawStateReadWorkerContext(); return { entries: cloneHostSnapshot(await prepareSkillLibrarySelection(e, { env: n.environment }, t)), assertCurrent: t }; } /** Catalog identity is host-owned; readable paths follow the effective tool placement. */ function bindHostSkillCatalog(e) { return (t, n) => { e.assertCurrent(); if (!e.readable) return []; const r = e.sandbox?.enabled ? e.sandbox : t ?? e.sandbox; const i = resolveSandboxSkillRuntimeInputs({ sandbox: r, skillsAnchorWorkspace: e.workspaceDir, skillsSnapshot: e.snapshot }); const a = prepareInstalledSkillCatalog({ snapshot: i.skillsSnapshot, workspaceDir: i.skillsWorkspaceDir, sandbox: r, assertCurrent: e.assertCurrent }); if (!e.requiredRoot) return a; const o = n ?? e.requiredRoot; if (!isPathInside(e.requiredRoot, o)) throw new Error("Skill permission root escapes the captured required workspace."); return a.filter((e) => { if (!r?.enabled) return resolveLocalPathFromRootsSync({ filePath: e.source.filePath, roots: [o], requireFile: true }) !== null; const t = r.fsBridge?.resolvePath({ filePath: e.location, cwd: r.containerWorkdir }); return t?.hostPath !== void 0 && isPathInside(o, t.hostPath); }).map((t) => { const n = Object.assign({}, t); n.source = { filePath: t.source.filePath }; n.reader = async ({ location: n, signal: i }) => { e.assertCurrent(); i?.throwIfAborted(); const a = t.promptListed ? Number.MAX_SAFE_INTEGER : MAX_SKILL_INSTRUCTION_BYTES; let s; if (r?.enabled) { if (!r.fsBridge?.readFileWithSource) throw new Error("Sandbox skill reads require a source-aware filesystem bridge."); const e = await r.fsBridge.readFileWithSource({ filePath: n, cwd: r.containerWorkdir, signal: i, maxBytes: a }); if (e.workspaceRelativePath === void 0 || !isPathInside(o, path.resolve(r.workspaceDir, e.workspaceRelativePath))) throw new Error("Skill instructions escape the captured required workspace."); s = e.data; } else { const e = await readLocalFileFromRoots({ filePath: n, roots: [o], hardlinks: "reject", symlinks: "follow-within-root", maxBytes: a }); if (!e) throw new Error("Skill instructions escape the captured required workspace."); s = e.buffer; } e.assertCurrent(); i?.throwIfAborted(); return s.toString("utf8"); }; return n; }); }; } //#endregion //#region src/agents/harness/host-trajectory.ts function bindHarnessTrajectory(e, t) { const n = e.trajectoryRecorder; if (!n) return {}; const r = getAsyncWorkSignal(); const i = e.abortSignal; const a = e.admittedRunContext.operationalRunInstance; const assertCleanupActive = () => { t(); if (e.admittedRunContext.operationalRunInstance !== a || e.trajectoryRecorder !== n) throw new Error("agent harness trajectory cleanup is no longer active"); }; return { trajectory: Object.freeze({ recordEvent: (e, t) => { r?.throwIfAborted(); i?.throwIfAborted(); assertCleanupActive(); n.recordEvent(e, t); }, flush: async () => { assertCleanupActive(); await n.flush(); assertCleanupActive(); } }) }; } //#endregion //#region src/agents/harness/node-execution-authority.ts /** Full is admitted host authority, narrowed to one placement claim, never a request flag. */ async function createSessionNodeAuthorities(e, t, n, r, i) { const a = e.permissionMode === "full"; const o = getGatewayContextResolver(e.admittedRunContext); const s = o?.(); const c = e.sessionTarget; const l = getActivePluginRegistry(); const u = [l, getPluginRuntimeGatewayRequestScope()?.pluginRegistry ?? l].map((e) => { const n = e?.plugins.find((e) => e.id === t); return e && n ? capturePluginLifecycleAuthority(e, n, { scopedRuntime: e !== l }) : void 0; }); const d = getPluginRuntimeGatewayRequestScope()?.assertNodeExecutionCurrent; if (!s || !c?.storePath || !e.agentId || !e.sessionKey || !e.sessionId || !d) return {}; const f = { agentId: e.agentId, sessionKey: e.sessionKey, storePath: c.storePath }; const p = captureSessionActorStorageOwner(f, { assertCurrent: r, authorize() {} }); const readProjected = () => { const e = s.sessionRowProjectionOwner; return e instanceof SessionRowProjectionBinding ? e.readCommittedEntry({ agentId: f.agentId, storePath: f.storePath, key: f.sessionKey }) : void 0; }; const m = p ? void 0 : readProjected(); let h; let g; let _ = false; let v = false; if (!p && !m) try { await withSessionEntryReadOnlyInWorker(f, r, async (t, n) => { if (!t.ok) throw t.error; const r = t.value; _ = r?.sessionId === e.sessionId; v = r?.permissionMode === "full"; if (n.source) { const e = { databaseIdentity: `file:${n.source.databaseIdentity}`, sessionKey: resolveSqliteSessionKey(f.sessionKey, f.agentId), entry: r }; h = retainPreparedSessionEntryPredicate({ ...e, matches: (e, t) => e?.sessionId === t?.sessionId }); if (a) g = retainPreparedSessionEntryPredicate({ ...e, matches: (e, t) => e?.permissionMode === t?.permissionMode }); } }); } catch (e) { h?.release(); g?.release(); throw e; } const assertRequestCurrent = (a) => { r(); const c = p ? readCapturedSessionActorEntry(p, f.sessionKey) : m ? readProjected()?.entry : void 0; const y = p || m ? c !== void 0 && c.sessionId === e.sessionId && (a.source !== "session-full" || c.permissionMode === "full") : _ && h?.isCurrent() && (a.source !== "session-full" || v && g?.isCurrent()); if (i.aborted || getActivePluginRegistry() !== l || u.some((e) => !e?.()) || a.source === "session-full" && (e.permissionMode !== "full" || !n.has(a.command)) || o && o() !== s || a.pluginId !== t || !y || a.workspace.sessionKey !== e.sessionKey || a.workspace.sessionId !== e.sessionId) throw new Error("admitted node execution authority is no longer current"); d({ ...a, runId: e.runId, agentId: f.agentId }); }; const invokeWithSessionNodeAuthority = async (e, t) => { if (e.source === "session-full" && (!a || !n.has(e.command))) return; const assertCurrent = () => assertRequestCurrent(e); assertCurrent(); const r = await t(assertCurrent, i); assertCurrent(); return r; }; return { release: () => { h?.release(); g?.release(); }, invokeWithSessionNodeAuthority, nodePlacementGrantAuthority: { agentId: f.agentId, sessionKey: e.sessionKey, runId: e.runId, assertCurrent: (e) => assertRequestCurrent({ ...e, source: "human-approved" }) } }; } //#endregion //#region src/agents/harness/host-capability.ts /** Creates a closure-bound capability before plugin invocation. */ function createAgentHarnessHostCapabilities(e) { const t = e.attempt; const n = captureHostDelegationPolicy(t, () => Boolean(M)); const r = t.prepareContinuationRetryCount; const i = captureExecRequestCustody(t); const a = t.runtimePluginToolGrant ? Object.freeze({ pluginId: t.runtimePluginToolGrant.pluginId, toolNames: Object.freeze([...t.runtimePluginToolGrant.toolNames]) }) : void 0; const o = t.githubPublicationAvailable; const s = getAsyncWorkSignal(); const c = t.abortSignal; const l = getInstallationTarget(); const { sessionKey: u, onAgentEvent: d } = t; const f = new Set(e.requiredNodeCommands); const p = e.nativeModelPolicySupport === "exact"; const m = e.toolCalls === "deny"; const h = t.admittedRunContext.operationalRunInstance; const g = getAdmittedRunDelegatedAuthority(t.admittedRunContext); const _ = readAdmittedRunOperatorAuthority(t.admittedRunContext)?.profileId; if (!g) throw new Error("agent harness host capability requires active admitted run authority"); const { lifecycleGeneration: v } = g; const { runId: y } = g.operationalRunInstance; const b = /* @__PURE__ */ new WeakSet(); const x = new AbortController(); const bindAbortSignal = (e) => e ? AbortSignal.any([e, x.signal]) : x.signal; const S = getGatewayToolCallerIdentity(); const C = S?.operationalRunInstance === h ? S : void 0; let w = C?.personalToolParticipants; const inactiveError = (e) => { throwAgentRunRestartAbortReason(c?.aborted ? c.reason : s?.reason); return new Error(e); }; const T = getGatewayContextResolver(t.admittedRunContext); const E = bindHarnessHostSourceAuthority({ attempt: t, delegatedAuthority: g, sourceCaller: C, isActive: () => !x.signal.aborted, isGatewayCurrent: () => !T || D?.gatewayContextResolver?.() !== void 0, inactiveError }); const D = createAdmittedGatewayToolCallerIdentity({ admittedRunContext: t.admittedRunContext, receiptAuthority: E, approvalSignals: [x.signal, ...c ? [c] : []], agentId: t.agentId, sessionKey: t.sessionKey, turnSourceChannel: t.messageChannel ?? t.messageProvider, turnSourceTo: t.currentMessagingTarget ?? t.currentChannelId, turnSourceAccountId: t.agentAccountId, turnSourceThreadId: t.currentThreadTs }); const O = prepareHostWorkspaceReadiness(u, E); const observeCoreTtsToolResult = (e) => { if (typeof e === "object" && e !== null && getCoreTtsToolResultMediaUrls(e)) b.add(e); }; const k = buildHarnessHostRequester(t); const A = t.config ? cloneHostSnapshot(t.config) : void 0; const j = t.sandbox?.enabled === true; const M = captureRequiredWorkspaceToolFloor(t, e.pluginId, A); const N = M?.apply(); const P = bindHarnessMedia({ attempt: t, config: A, assertActive: E, signal: x.signal }); const F = t.userTurnTranscriptRecorder; const I = t.sessionTarget ? cloneHostSnapshot(t.sessionTarget) : void 0; const L = t.userTurnTranscriptRecorder && t.sessionTarget && t.agentId && t.sessionId && t.sessionKey && t.sessionTarget.storePath && !t.suppressNextUserMessagePersistence && t.trigger !== "memory" ? bindUserTurnTranscriptAnnotation({ recorder: t.userTurnTranscriptRecorder, target: { ...t.sessionTarget, agentId: t.agentId, sessionId: t.sessionId, sessionKey: t.sessionKey, storePath: t.sessionTarget.storePath }, runId: t.runId, config: A, abortSignal: bindAbortSignal(t.abortSignal), assertCurrent: () => { E(); if (t.userTurnTranscriptRecorder !== F || !isDeepStrictEqual(t.sessionTarget, I) || I?.agentId !== void 0 && I.agentId !== t.agentId || I?.sessionId !== void 0 && I.sessionId !== t.sessionId || I?.sessionKey !== void 0 && I.sessionKey !== t.sessionKey) throw new Error("native prompt annotation lost its source execution claim"); } }) : void 0; const R = t.skillsSnapshot ? cloneHostSnapshot(t.skillsSnapshot) : void 0; const z = bindHostSkillCatalog({ snapshot: R, workspaceDir: N?.workspaceDir ?? t.bootstrapWorkspaceDir ?? t.workspaceDir ?? t.cwd ?? process.cwd(), sandbox: M ? N?.sandbox : t.sandbox, requiredRoot: M?.root, readable: t.operation !== "settled-tool-finalization" && (!t.toolExecutionAllow || isToolExecutionAllowed(t.toolExecutionAllow, "read")), assertCurrent: E }); const B = prepareAgentHarnessEnvironment({ config: A, agentId: t.agentId, sessionKey: t.sessionKey, sandboxAgentId: t.sandboxAgentId, installationTarget: l }); const V = t.sandbox?.skillUsagePaths ? cloneHostSnapshot(t.sandbox.skillUsagePaths) : void 0; const H = Object.freeze({ ...t.agentId ? { agentId: t.agentId } : {}, ...A ? { config: A } : {}, ...t.cwd ? { cwd: t.cwd } : {}, ...t.workspaceDir ? { workspaceDir: t.workspaceDir } : {}, ...t.sessionKey ? { sessionKey: t.sessionKey } : {}, ...t.sessionId ? { sessionId: t.sessionId } : {}, runId: t.runId, ...buildAgentHookContextChannelFields(t), ...Object.keys(k).length > 0 ? { requester: Object.freeze(k) } : {}, ...getActiveDiagnosticTraceContext() ? { trace: getActiveDiagnosticTraceContext() } : {}, ...R ? { skillsSnapshot: R } : {}, ...V ? { skillUsagePaths: V } : {}, ...t.onToolOutcome ? { onToolOutcome: t.onToolOutcome } : {}, ...t.allocateToolOutcomeOrdinal ? { allocateToolOutcomeOrdinal: t.allocateToolOutcomeOrdinal } : {}, ...t.sandbox?.enabled && t.sandbox.workspaceAccess === "rw" && t.sandbox.fsBridge ? { sandbox: Object.freeze({ root: t.sandbox.workspaceDir, bridge: t.sandbox.fsBridge }) } : {}, loopDetection: cloneHostSnapshot(resolveToolLoopDetectionConfig({ cfg: A, agentId: t.agentId })), trigger: t.trigger, approvalReviewerDeviceId: t.approvalReviewerDeviceId, turnSourceChannel: t.messageChannel ?? t.messageProvider, turnSourceTo: t.currentMessagingTarget ?? t.currentChannelId, turnSourceAccountId: t.agentAccountId, turnSourceThreadId: t.currentThreadTs }); const withCaller = async (e, t) => await withGatewayToolCallerIdentity(D && t ? { ...D, approvalSignals: [...D.approvalSignals ?? [], t] } : D, e); const hookContextForOperation = (e) => { const t = e?.cwd !== void 0 ? normalizeNativeOperationCwd(e.cwd, H.cwd) : void 0; return t ? Object.freeze({ ...H, cwd: t }) : H; }; const runBeforeToolCallWithAssertion = async (e, { nativeOperation: t, approvalMode: n, ...r }) => { e(); if (m) return { blocked: true, kind: "veto", reason: "Tool calls are denied for this side question." }; if (O.beforeToolCall) await O.beforeToolCall(r, e); const i = n === "defer" ? "defer" : "request"; const a = hookContextForOperation(t); const o = await runBeforeToolCallHook({ ...r, approvalMode: i, ctx: a }); e(); return o; }; const runBeforeToolCall = async (e) => await withCaller(async () => await runBeforeToolCallWithAssertion(E, e), e.signal); registerAgentHarnessBeforeToolCallRetention(runBeforeToolCall, () => { const e = retainAdmittedRunBeforeToolCallRecovery(t.admittedRunContext); if (!e) return; const assertRecoveryActive = () => { if (t.abortSignal?.aborted || t.admittedRunContext.operationalRunInstance !== h || T && D?.gatewayContextResolver?.() === void 0) throw inactiveError("agent harness retained host policy is no longer active"); e.assertActive(); }; return { assertActive: assertRecoveryActive, release: e.release, runBeforeToolCall: async (e) => await runBeforeToolCallWithAssertion(assertRecoveryActive, e) }; }); const U = /* @__PURE__ */ new WeakMap(); const bindTools = (e, n, r) => bindHostToolSurface(e, { assertActive: E, observeResult: r, callerIdentity: D, hookContext: hookContextForOperation(n), abortSignal: bindAbortSignal(t.abortSignal), workspaceReadiness: O.readiness }); const W = p ? (e) => bindHarnessModelExecution(t.admittedRunContext, e, E) : void 0; const skillResourceSnapshot = (e) => !M && !j && !e?.sandbox?.enabled && e?.includeCoreTools !== false && e?.toolConstructionPlan?.includeBaseCodingTools !== false ? R : void 0; const toolConstructionInputs = (e, t, r, i = E, s = n(e)) => { i(); const c = { ...e, ...M?.apply(e) }; return { options: { ...c, readDelegationConfig: s, githubPublicationAvailable: o, exec: { ...c.exec, preparedRunEnvironment: B }, runtimePluginToolGrant: a, skillsSnapshot: e?.skillsSnapshot ?? R, installedSkills: z(c.sandbox, c.sessionPermissionPolicy?.root), skillUsagePaths: e?.skillUsagePaths ?? V, operationalRunInstance: h, pluginExecutionAuthority: D?.operatorAuthority, pluginExecutionSkillsSnapshot: R, assertInvocationCurrent: i, nativeHarnessExecution: !m ? r : void 0, unverifiedExecutionPolicy: true }, skillReadResources: resolveSkillResourceCandidates(skillResourceSnapshot(e), t) }; }; const bindCreatedTools = (e, t) => { const n = bindTools(e, t, observeCoreTtsToolResult); for (const e of n) if (e.name === "exec" || e.name === "process") U.set(e, { targetTool: e.name, execute: e.execute }); return n; }; const withToolConstructionScope = (e) => withAgentQuestionAnswerAuthority(resolveAgentQuestionAnswerAuthority(G), () => withInstallationTarget(l, e)); const G = Object.freeze({ kind: "agent-harness-host-capability", version: 1, assertActive: E, ...bindHostContinuationRetryCount(r, E), captureRequestCustody: () => { E(); return i; }, ...O.capability ? { workspaceReadiness: O.capability } : {}, get assertNativeSubagentSpawnAllowed() { return bindHarnessNativeSpawnAuthority(w, E); }, ...W ? { bindModelExecution: W } : {}, retainSourceAuthority: () => retainHarnessSource(t.admittedRunContext, E, p), reportOutputTokens: (e) => { E.assertScopeCurrent(); const t = emitAgentRunOutputTokens({ runId: y, lifecycleGeneration: v, sessionKey: u, outputTokens: e }); if (t && d) runBestEffortCallback({ label: "usage agent event", log, callback: () => d({ stream: "usage", data: t }) }); }, ...L ? { annotateCurrentUserTurn: L } : {}, ...P.capabilities, ...bindBoundedSeed(t, E, withCaller, x.signal, P), ...bindHarnessTrajectory(t, E.assertScopeCurrent), preparedEnvironment: () => { E.assertScopeCurrent(); return B; }, activeComputerContext: () => { E(); return buildActiveNodeContextText(_); }, bindToolSurface: (e, t) => bindTools(e, t, () => {}), /** @deprecated Await createToolSurfaceAsync for worker-backed tool construction. Supported through 2026-12-31. Removal in the first January 2027 stable release. */ createToolSurface: (e, t) => { warnPluginSdkDeprecation({ family: "agent-harness-host", method: "createToolSurface", replacement: "createToolSurfaceAsync", compatibility: "Synchronous tool construction retains its pinned skill resources." }); const n = toolConstructionInputs(e, loadSkillLibrarySelection(skillResourceSnapshot(e)?.librarySelections ?? []), t?.nativeLocalExecution); return bindCreatedTools(withToolConstructionScope(() => createOpenClawCodingToolsInternal(n.options, n.skillReadResources)), t); }, createToolSurfaceAsync: async (e, t) => { const r = n(e); const i = skillResourceSnapshot(e)?.librarySelections ?? []; const a = i.length ? await prepareHostSkillLibraryResources(i, E) : void 0; const o = toolConstructionInputs(e, a?.entries ?? [], t?.nativeLocalExecution, a?.assertCurrent, r); const s = await withToolConstructionScope(() => createOpenClawCodingToolsInternalAsync(o.options, o.skillReadResources, void 0, void 0, { assertCurrent: a?.assertCurrent ?? E, signal: bindAbortSignal(c) })); return bindCreatedTools(s, t); }, prepareMutableFileApproval: async (e) => { E(); const t = await prepareSystemRunMutableFileApproval(e); E(); if (!t.ok) return t; return Object.freeze({ ok: true, requiresOneShot: t.requiresOneShot, revalidate: async () => { E(); const e = await t.revalidate(); E(); return e; } }); }, runBeforeToolCall, requestApproval: async (n) => { E(); n.signal?.throwIfAborted(); const r = n.mcpTool && n.toolCallId && n.isMcpToolApprovalActive && t.agentId ? registerMcpToolApprovalBinding({ authority: g, agentId: t.agentId, toolCallId: n.toolCallId, ...n.mcpTool, isActive: () => { E(); return !n.signal?.aborted && n.isMcpToolApprovalActive(); } }) : void 0; try { const t = await withCaller(async () => await withGatewayToolApprovalOwner(e.pluginId, async () => await callGatewayTool("plugin.approval.request", { timeoutMs: n.transportTimeoutMs ?? n.timeoutMs }, { ...formatHarnessApprovalPresentation(n), ...n.detail !== void 0 ? { detail: n.detail } : {}, severity: n.severity, toolName: n.toolName, toolCallId: n.toolCallId, ...n.mcpTool ? { mcpTool: n.mcpTool } : {}, timeoutMs: n.timeoutMs, twoPhase: true, ...n.allowedDecisions ? { allowedDecisions: n.allowedDecisions } : {} }, { expectFinal: false, requireAgentRuntimeIdentity: true, signal: n.signal })), n.signal); E(); n.signal?.throwIfAborted(); return t; } finally { r?.(); } }, waitForApproval: async (t) => { E(); const n = await withCaller(async () => await withGatewayToolApprovalOwner(e.pluginId, async () => await callGatewayTool("plugin.approval.waitDecision", { timeoutMs: t.transportTimeoutMs ?? t.timeoutMs }, { id: t.approvalId }, { requireAgentRuntimeIdentity: true, signal: t.signal })), t.signal); E(); if (n?.id !== t.approvalId) return; return { decision: n.decision, terminalReason: n.terminalReason }; } }); registerAgentHarnessScheduledToolProjectionCapability({ hostCapabilities: G, ownerPluginId: e.pluginId, create: (e, t) => { E(); const n = U.get(e); if (!n || e.name !== n.targetTool || e.execute !== n.execute) throw new Error("scheduled tool projection source was not created by this host capability"); return createCronScheduledToolProjection(e, E, n.targetTool, t); } }); registerAgentHarnessTtsProvenanceTransferCapability({ hostCapabilities: G, ownerPluginId: e.pluginId, transfer: (e, t, n) => { E(); if (typeof e !== "object" || e === null || !b.has(e)) return t; return transferCoreTtsToolResultProvenance(e, t, n, h); } }); return { capabilities: G, setInputAttachmentReadAllowed: P.setInputAttachmentReadAllowed, runWithScope: async (n) => { const r = getGatewayToolCallerIdentity(); if (r?.operationalRunInstance === h) { w ??= r.personalToolParticipants; if (D && w) D.personalToolParticipants = w; } const { release: i, ...a } = await createSessionNodeAuthorities(t, e.pluginId, f, E, bindAbortSignal(t.abortSignal)); try { return await withPluginRuntimeGatewayRequestScope({ isWebchatConnect: () => false, ...getPluginRuntimeGatewayRequestScope(), ...a }, n); } finally { i?.(); } }, close: () => x.abort() }; } //#endregion export { createAgentHarnessHostCapabilities };