UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 3.33 kB
import{t as createDeferredCore}from"./deferred-QsZCoVH-.mjs";import{a as captureAsyncWorkTracker,t as AsyncWorkScope}from"./async-work-scope-DBcxYU4O.mjs";import{r as classifySystemAgentApprovalText}from"./operator-approval-h7q9r6kO.mjs";import{a as resolveSystemAgentVerifiedInferenceRoute}from"./verified-inference-C2wCwCrh.mjs";import{c as extractEmbeddedAssistantText}from"./embedded-agent-utils-Bld7utNs.mjs";import{t as completeWithPreparedSimpleCompletionModel}from"./simple-completion-execution-dg9Ppwh3.mjs";import{t as acquireSimpleCompletionModelForAgent}from"./simple-completion-runtime-CMwlOKLc.mjs"; //!src/system-agent/approval-intent.ts const APPROVAL_INTENT_TIMEOUT_MS=1e4;const APPROVAL_INTENT_MAX_TOKENS=8;const APPROVAL_INTENT_SYSTEM_PROMPT=[`You classify one chat message from a user who was just asked to approve a pending configuration change.`,`Reply with exactly one word:`,`approve — the message clearly consents to applying the pending change now.`,`decline — the message clearly rejects or postpones the pending change.`,`other — anything else: questions, new requests, partial or conditional agreement, or unclear intent.`,`Only classify consent for the pending change itself. A message asking to change the proposal is not approval.`].join(` `);async function classifySystemAgentApprovalIntent(e){const t=classifySystemAgentApprovalText(e.message);if(t!==`other`)return t;try{const t=await resolveSystemAgentVerifiedInferenceRoute(e.verifiedInference);if(!t||t.runner!==`embedded`||t.agentHarnessRuntimeOverride!==`openclaw`)return`other`;const n=t.authProfileId?`${t.modelLabel}@${t.authProfileId}`:t.modelLabel;const r=createDeferredCore();captureAsyncWorkTracker()(async()=>{const i=await acquireSimpleCompletionModelForAgent({cfg:t.runConfig,agentId:t.agentId,agentDir:t.agentDir,modelRef:n,...t.authProfileId?{preferredProfile:t.authProfileId}:{},allowMissingApiKeyModes:[`aws-sdk`],bindAuthOwner:true});if(`error`in i){r.resolve(`other`);return}const a=new AsyncWorkScope;try{r.resolve(await a.track(async()=>{if((i.selection.runtimeProvider??i.selection.provider)!==t.provider||i.selection.modelId!==t.model||i.selection.agentDir!==t.agentDir||i.selection.profileId!==t.authProfileId||i.auth.profileId!==t.authProfileId||!e.verifiedInference.auth.authFingerprint||i.sourceAuthFingerprint!==e.verifiedInference.auth.authFingerprint)return`other`;const n=new AbortController;const r=setTimeout(()=>n.abort(),APPROVAL_INTENT_TIMEOUT_MS);try{const r=await completeWithPreparedSimpleCompletionModel({model:i.model,auth:i.auth,cfg:t.runConfig,context:{systemPrompt:APPROVAL_INTENT_SYSTEM_PROMPT,messages:[{role:`user`,content:[`Pending change: ${e.proposal??`a configuration change proposed in this conversation`}`,`User message: ${e.message}`].join(` `),timestamp:Date.now()}]},options:{maxTokens:APPROVAL_INTENT_MAX_TOKENS,signal:n.signal}});if(!await resolveSystemAgentVerifiedInferenceRoute(e.verifiedInference))return`other`;const a=extractEmbeddedAssistantText(r)?.trim().toLowerCase().split(/\s+/)[0];if(a===`approve`||a===`decline`)return a;return`other`}finally{clearTimeout(r)}}))}catch{r.resolve(`other`)}finally{await a.drain();await i[Symbol.asyncDispose]()}}).catch(()=>r.resolve(`other`));return await r.promise}catch{return`other`}}export{classifySystemAgentApprovalIntent};