UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.52 kB
import{Guard}from"typebox/guard"; //!packages/llm-core/src/utils/diagnostics.ts const encoder=new TextEncoder;function isBoundedText(e,t){return typeof e===`string`&&e.length<=t&&e.trim().length>0&&encoder.encode(e).byteLength<=t}function readProviderRefusalReview(e){if(!Guard.IsObjectNotArray(e)||!isBoundedText(e.explanation,65536))return;const t=Guard.IsObjectNotArray(e.continuation)?e.continuation.message:void 0;return{explanation:e.explanation,...isBoundedText(t,1024)?{continuation:{message:t}}:{},...typeof e.errorType===`string`&&e.errorType.trim()?{errorType:e.errorType}:{}}}function isProviderRefusalAssistantError(e){return Boolean(e?.diagnostics?.some(e=>e.type===`provider_refusal`))}function appendAssistantMessageDiagnostic(e,t){e.diagnostics=[...e.diagnostics??[],t]}function recordSuppressedReasoning(e){if(!e.diagnostics?.some(e=>e.type===`reasoning_suppressed`))appendAssistantMessageDiagnostic(e,{type:`reasoning_suppressed`,timestamp:Date.now()});if(e.stopReason!==`stop`&&e.stopReason!==`length`||e.content.some(e=>e.type===`toolCall`||e.type===`text`&&e.text.trim()))return;return/* @__PURE__ */ new Error(`${e.provider}/${e.model} returned only reasoning while configured reasoning: false. Set reasoning: true for this model in models.providers.${e.provider}.models or choose a non-thinking model.`+(e.stopReason===`length`?` The output token limit was reached before an answer.`:``))}export{readProviderRefusalReview as n,recordSuppressedReasoning as r,isProviderRefusalAssistantError as t};