function toJsonValue(e){return e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`?e:e instanceof Error?e.message:typeof e==`object`?e:String(e)}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};