UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 1.62 kB
import{parseJsonValue}from"#shared/json.js";import{authorizationPendingAsJsonObject,isAuthorizationPendingModelOutput,isAuthorizationSignal}from"#harness/authorization.js";function toJsonValue(n){return isAuthorizationSignal(n)?parseJsonValue(authorizationPendingAsJsonObject({connections:n.challenges.map(e=>e.name)})):isAuthorizationPendingModelOutput(n)?parseJsonValue(authorizationPendingAsJsonObject(n)):n===null||typeof n==`string`||typeof n==`number`||typeof n==`boolean`?n:n instanceof Error?n.message:typeof n==`object`?n:String(n)}function createRuntimeToolResultFromValue(e){let t={callId:e.callId,kind:`tool-result`,output:toJsonValue(e.output),toolName:e.toolName};return e.isError===!0?{...t,isError:!0}:t}function createRuntimeToolResultFromStepResult(e){return createRuntimeToolResultFromValue({callId:e.toolCallId,output:e.output,toolName:e.toolName})}function createRuntimeToolResultFromMessagePart(e){return createRuntimeToolResultFromValue({callId:e.toolCallId,output:toolResultOutputToJsonValue(e.output),toolName:e.toolName,isError:isToolResultError(e.output)})}function toolResultOutputToJsonValue(e){switch(e.type){case`text`:case`error-text`:return e.value;case`json`:case`error-json`:return toJsonValue(e.value);case`execution-denied`:return{code:`TOOL_EXECUTION_DENIED`,message:e.reason??`Tool execution was denied.`};case`content`:return toJsonValue(e.value)}}function isToolResultError(e){return e.type===`error-json`||e.type===`error-text`||e.type===`execution-denied`}export{createRuntimeToolResultFromMessagePart,createRuntimeToolResultFromStepResult,createRuntimeToolResultFromValue};