openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 9.99 kB
JavaScript
import{o as resolveGlobalSingleton}from"./global-singleton-DolL9xGt.mjs";import{t as AsyncContext}from"./async-context-D4i8WbBE.mjs";import{u as throwSqliteLifecycleErrors}from"./sqlite-lifecycle-errors-DMaudCZS.mjs";import{t as GATEWAY_OWNER_PROFILE_ID}from"./user-profile-constants-abCq1jKI.mjs";import{t as warnPluginSdkDeprecation}from"./sdk-deprecation-BDUCyBrU.mjs";
//!src/agents/harness/host-private-capabilities.ts
const replyQueueInputAdapters=/* @__PURE__ */ new WeakMap;const replyInputChannel=resolveGlobalSingleton(Symbol.for(`openclaw.replyInputChannel`),()=>Symbol(`replyInputChannel`));function bindReplyInputChannel(e,t){Object.assign(e,{[replyInputChannel]:t})}function readReplyInputChannel(e){const t=Reflect.get(e,replyInputChannel);return typeof t===`string`?t:void 0}const sharedGatewayOwnerSources=resolveGlobalSingleton(Symbol.for(`openclaw.sharedGatewayOwnerSources`),()=>/* @__PURE__ */ new WeakSet);function bindSharedGatewayOwnerRunAuthority(e){if(e.source)sharedGatewayOwnerSources.add(e.source)}function isSharedGatewayOwnerRunAuthority(e){return Boolean(e?.profileId===`gateway-owner`&&e.source&&sharedGatewayOwnerSources.has(e.source))}function bindReplyQueueInputAdapter(e,t){replyQueueInputAdapters.set(e,t);return e}function readReplyQueueInputAdapter(e){return(e&&replyQueueInputAdapters.get(e))??`legacy-question-category`}const questionDispatchCapabilities=/* @__PURE__ */ new WeakMap;function bindQuestionDispatchCapability(e,t,n){questionDispatchCapabilities.set(e,t);if(n)questionDispatchCapabilities.set(n,t)}function readQuestionDispatchCapability(e){return e?questionDispatchCapabilities.get(e):void 0}function bindQuestionDispatchGuard(e,t,n){const r=t?.prepareCurrent&&(async()=>{try{e();await t?.prepareCurrent?.();e()}catch(e){n(e)}});const guard=t=>{try{e();t();e()}catch(e){n(e)}};const i=readQuestionDispatchCapability(t?.assertCurrent);const a=i?.callerRead;const o=a?.assertLegacyCurrent;bindQuestionDispatchCapability(e,{assertCompatibilityCurrent:()=>guard(i?.assertCompatibilityCurrent??e),callerRead:a&&{reads:a.reads,prepareCurrent:r,assertLegacyCurrent:o&&(()=>guard(o)),assertPrepared:e=>guard(()=>a.assertPrepared(e)),retainCurrent:()=>{let e;try{e=a.retainCurrent()}catch(e){return n(e)}return{release:e.release,assertCurrent:()=>guard(e.assertCurrent)}}}},r);return r}function prepareQuestionGatewayDispatch(e,t=false){const n=readQuestionDispatchCapability(e?.assertCurrent);return{assertDispatchCurrent:t?e?.assertCurrent:n?.assertCompatibilityCurrent??e?.assertCurrent,prepareDispatchCurrent:e?.prepareCurrent}}const callerReadPreparers=/* @__PURE__ */ new WeakMap;const toolAuthorityReadScope=new AsyncContext(Symbol(`toolAuthorityReads`));const workerToolPreparations=/* @__PURE__ */ new WeakMap;function bindWorkerToolPreparation(e,t=[]){workerToolPreparations.set(e.prepareCurrent,{complete:t.every(e=>workerToolPreparations.get(e.prepareCurrent)?.complete===true)});return e}function isToolAuthorityReadCaptureActive(){return toolAuthorityReadScope.getStore()!==void 0}function recordPreparedToolAuthorityRead(e){toolAuthorityReadScope.getStore()?.reads.push(e)}async function capturePreparedToolAuthorityReads(e){const t=workerToolPreparations.get(e.prepareCurrent);const n={reads:[],complete:t?.complete??false};if(t)await toolAuthorityReadScope.run(n,e.prepareCurrent);else await e.prepareCurrent();e.assertCurrent();return{reads:n.reads,assertCompatibility:!n.complete||!n.reads.length?e.compatAssertCurrent:void 0}}function bindReplyToolAuthorityCallerRead(e,t){callerReadPreparers.set(e,t)}function captureReplyToolAuthorityCallerBinding(e,t,n,r,i){i();const a=e&&n?callerReadPreparers.get(e)?.(t,n,r,i):void 0;if(!a){const e=toolAuthorityReadScope.getStore();if(e)e.complete=false;return}a.assertCurrent();return{assertCurrent:()=>a.assertCurrent(),continuationKind:a.continuationKind,allowPendingUserInputAnswer:a.allowPendingUserInputAnswer,joinObservation:a.joinObservation,prepare:async()=>{a.assertCurrent();try{const e=await a.prepare();const t=toolAuthorityReadScope.getStore();if(t&&!e)t.complete=false;return e}finally{a.assertCurrent()}}}}async function prepareReplyToolAuthorityCallerRead(e,t,n,r,i){return captureReplyToolAuthorityCallerBinding(e,t,n,r,i)?.prepare()}function assertQuestionCompatibilityCurrent(e,t,n){e();t?.assertLegacyCurrent?.();const r=t?.retainCurrent();try{if(r)r.assertCurrent();else{warnPluginSdkDeprecation({family:`reply-tool-authority-sync-preparation`,method:`question dispatcher authority.assertCurrent synchronous preparation`,replacement:`await authority.assertCurrentAsync() before the final effect assertion`});n()}}finally{r?.release()}e()}async function prepareQuestionInputAuthority(e){const t=e.toolAuthorityPreparation;if(!t)return e;const assertActive=()=>{e.assertCurrent();t.assertCurrent()};assertActive();const n=await capturePreparedToolAuthorityReads(t);assertActive();const r=!n.assertCompatibility&&n.reads.length>0&&n.reads.every(e=>e.retainCurrent);const assertLegacyReads=()=>{for(const e of n.reads)e.assertLegacyCurrent()};const prepareCurrent=async()=>{assertActive();await t.prepareCurrent();if(!r)assertLegacyReads();assertActive()};const i=r?{reads:n.reads.flatMap(e=>e.reads),prepareCurrent,assertLegacyCurrent:assertLegacyReads,assertPrepared:e=>{assertActive();let t=0;for(const r of n.reads){r.assertPrepared(e.slice(t,t+r.reads.length));t+=r.reads.length}assertActive()},retainCurrent:()=>{const e=[];const release=()=>{const t=[];for(const n of e.toReversed())try{n.release()}catch(e){t.push(e)}throwSqliteLifecycleErrors(t,`Question authority reader release failed`)};try{for(const t of n.reads)e.push(t.retainCurrent());return{release,assertCurrent:()=>{assertActive();e.forEach(e=>e.assertCurrent());assertActive()}}}catch(e){release();throw e}}}:void 0;const assertCompatibilityCurrent=()=>assertQuestionCompatibilityCurrent(assertActive,i,()=>{t.compatAssertCurrent();assertLegacyReads()});const a=r?assertActive:()=>{assertActive();t.compatAssertCurrent();assertActive()};bindQuestionDispatchCapability(a,{assertCompatibilityCurrent,callerRead:i});return{kind:e.kind,assertCurrent:a,prepareCurrent}}async function prepareQuestionCallerAuthority(e,t,n){n();const r=await e.prepareCaller?.(t);n();const assertCompatibilityCurrent=()=>assertQuestionCompatibilityCurrent(n,r,()=>e.assertCaller(t));const i=r?n:assertCompatibilityCurrent;bindQuestionDispatchCapability(i,{assertCompatibilityCurrent,callerRead:r});return{kind:`source-bound`,assertCurrent:i,prepareCurrent:async()=>{n();if(r)await r.prepareCurrent();else e.assertCaller(t);n()}}}const questionAnswerScope=new AsyncContext(Symbol(`questionAnswerAuthority`));const questionAnswerCapabilities=/* @__PURE__ */ new WeakMap;function createAgentQuestionAnswerAuthority(e){return Object.freeze({sessionKey:e.sessionKey.trim(),requesterProfileId:e.requesterProfileId,assertActive:e.assertActive,admitTranscriptAnswer:e.admitTranscriptAnswer,prepareCaller:e.prepareCaller,assertCaller:t=>{e.assertActive();const n=e.project(t);e.assertActive();if(!e.fingerprint||n!==e.fingerprint)throw new Error(`question answer caller policy does not match its creator`)}})}function withAgentQuestionAnswerAuthority(e,t){return questionAnswerScope.run(e,t)}function registerAgentHarnessQuestionAnswerAuthority(e,t){questionAnswerCapabilities.set(e,t)}function resolveAgentQuestionAnswerAuthority(e){return e?questionAnswerCapabilities.get(e):questionAnswerScope.getStore()}function captureAgentQuestionAnswerAuthority(e){const t=questionAnswerScope.getStore();t?.assertActive();if(t&&t.sessionKey!==e.trim())throw new Error(`question creator authority belongs to another session`);return t}const retainedBeforeToolCallRunners=/* @__PURE__ */ new WeakMap;function retainBeforeToolCallForNativeHookRelay(e){return retainedBeforeToolCallRunners.get(e)?.()}function registerAgentHarnessBeforeToolCallRetention(e,t){retainedBeforeToolCallRunners.set(e,t)}const scheduledToolProjectionCapabilities=/* @__PURE__ */ new WeakMap;const ttsProvenanceTransferCapabilities=/* @__PURE__ */ new WeakMap;function registerAgentHarnessScheduledToolProjectionCapability(e){scheduledToolProjectionCapabilities.set(e.hostCapabilities,{ownerPluginId:e.ownerPluginId,create:e.create})}function resolveAgentHarnessScheduledToolProjectionCapability(e){const t=scheduledToolProjectionCapabilities.get(e.hostCapabilities);return t?.ownerPluginId===e.ownerPluginId?t.create:void 0}function registerAgentHarnessTtsProvenanceTransferCapability(e){ttsProvenanceTransferCapabilities.set(e.hostCapabilities,{ownerPluginId:e.ownerPluginId,transfer:e.transfer})}function resolveAgentHarnessTtsProvenanceTransferCapability(e){const t=ttsProvenanceTransferCapabilities.get(e.hostCapabilities);return t?.ownerPluginId===e.ownerPluginId?t.transfer:void 0}export{registerAgentHarnessScheduledToolProjectionCapability as C,resolveAgentQuestionAnswerAuthority as D,resolveAgentHarnessTtsProvenanceTransferCapability as E,retainBeforeToolCallForNativeHookRelay as O,registerAgentHarnessQuestionAnswerAuthority as S,resolveAgentHarnessScheduledToolProjectionCapability as T,readQuestionDispatchCapability as _,bindSharedGatewayOwnerRunAuthority as a,recordPreparedToolAuthorityRead as b,capturePreparedToolAuthorityReads as c,isSharedGatewayOwnerRunAuthority as d,isToolAuthorityReadCaptureActive as f,prepareReplyToolAuthorityCallerRead as g,prepareQuestionInputAuthority as h,bindReplyToolAuthorityCallerRead as i,withAgentQuestionAnswerAuthority as k,captureReplyToolAuthorityCallerBinding as l,prepareQuestionGatewayDispatch as m,bindReplyInputChannel as n,bindWorkerToolPreparation as o,prepareQuestionCallerAuthority as p,bindReplyQueueInputAdapter as r,captureAgentQuestionAnswerAuthority as s,bindQuestionDispatchGuard as t,createAgentQuestionAnswerAuthority as u,readReplyInputChannel as v,registerAgentHarnessTtsProvenanceTransferCapability as w,registerAgentHarnessBeforeToolCallRetention as x,readReplyQueueInputAdapter as y};