openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.83 kB
JavaScript
import{_ as readQuestionDispatchCapability,h as prepareQuestionInputAuthority}from"./host-private-capabilities-B_SEzbNU.mjs";import{t as isEmbeddedMode}from"./embedded-mode-CWH0_8k1.mjs";
//!src/agents/harness/gateway-question-dispatch.ts
var QuestionDispatchRefusedError=class extends Error{constructor(...e){super(...e);this.name=`QuestionDispatchRefusedError`}};function refuseQuestionDispatch(e){throw new QuestionDispatchRefusedError(e instanceof Error?e.message:`question dispatch authority refused`,{cause:e})}async function prepareQuestionDispatchAuthority(e){try{const t=await prepareQuestionInputAuthority(e);await t.prepareCurrent?.();return t}catch(e){return refuseQuestionDispatch(e)}}var QuestionDispatchUnsupportedError=class extends QuestionDispatchRefusedError{};var PreparedQuestionAnswerRefusedError=class extends Error{constructor(e){super(e instanceof Error?e.message:`Prepared question input is no longer current`,{cause:e});this.name=`PreparedQuestionAnswerRefusedError`}};function buildAgentQuestionRequestQuestions(e){return e.map(({id:e,defaultAnswers:t,...n})=>({...n,questionId:e,options:[...n.options??[]],...t?{defaultAnswers:[...t]}:{}}))}function buildAgentQuestionAnswers(e){return{answers:Object.fromEntries(Object.entries(e.answers).map(([e,t])=>[e,t.answers]))}}var QuestionAnswerUnconfirmedError=class extends Error{constructor(e){super(`The question answer may have been accepted, but confirmation was lost. It was not sent again; check the conversation before retrying.`,{cause:e});this.name=`QuestionAnswerUnconfirmedError`}};async function withQuestionDispatchAuthority(e,t){const n=readQuestionDispatchCapability(e?.assertCurrent);const r=n?.callerRead;if(!r){(n?.assertCompatibilityCurrent??e?.assertCurrent)?.();return t()}const{withSessionEntriesFromStoresInWorker:i}=await import(`./session-entry-read-runtime-DneR6aFS.mjs`);const consumePrepared=n=>{r.assertPrepared(n);e?.assertCurrent();return{value:t()}};return(await i(r.reads,consumePrepared,{ordered:true})).value}function resolveAgentQuestionGatewayCall(e){if(e&&typeof e!==`function`&&e.version!==2)throw new Error(`unsupported question dispatcher version`);let t=null;return async(...n)=>{const[r,i,a,o]=n;if(e&&o?.dispatchAuthority?.kind===`run`){const e=o.dispatchAuthority;(readQuestionDispatchCapability(e.assertCurrent)?.assertCompatibilityCurrent??e.assertCurrent)()}if(typeof e===`function`){if(o?.dispatchAuthority?.kind===`source-bound`){o.dispatchAuthority.assertCurrent();throw new QuestionDispatchUnsupportedError(`source-bound question input requires the default or a version 2 dispatcher`)}return n.length===4&&(!o?.dispatchAuthority||o.signal)?e(r,i,a,o?.signal?{signal:o.signal}:void 0):e(r,i,a)}if(e)return e.call({method:r,options:i,params:a,signal:o?.signal,authority:o?.dispatchAuthority?.kind===`source-bound`?{kind:`source-bound`,assertCurrent:readQuestionDispatchCapability(o.dispatchAuthority.assertCurrent)?.assertCompatibilityCurrent??o.dispatchAuthority.assertCurrent,assertCurrentAsync:o.dispatchAuthority.prepareCurrent}:{kind:`unscoped`}});if(!t&&isEmbeddedMode()){const{getEmbeddedQuestionBroker:e}=await import(`./embedded-question-broker-CFbeAoME.mjs`);t=e()}if(t){await o?.dispatchAuthority?.prepareCurrent?.();o?.signal?.throwIfAborted();return withQuestionDispatchAuthority(o?.dispatchAuthority,()=>t.call(r,a,o))}const{callGatewayTool:s}=await import(`./gateway-question-dispatch.runtime--PJkmlH5.mjs`);return s(r,i,a,o)}}export{buildAgentQuestionAnswers as a,refuseQuestionDispatch as c,QuestionDispatchUnsupportedError as i,resolveAgentQuestionGatewayCall as l,QuestionAnswerUnconfirmedError as n,buildAgentQuestionRequestQuestions as o,QuestionDispatchRefusedError as r,prepareQuestionDispatchAuthority as s,PreparedQuestionAnswerRefusedError as t,withQuestionDispatchAuthority as u};