# shellcheck shell=dash

___x_cmd_hub_ai_convo(){
    local X_help_cmd='___x_cmd help -m hub ai convo'; help:arg-null:parse
    local op="$1";
    case "$op" in
        request|exec)
            shift; ___x_cmd_hub_ai_convo_"$op" "$@" ;;
        --get-apikey)
            shift; ___x_cmd_hub_service_verify_ ;;
        --get-model) ;;
        # model)
        #     shift; ___x_cmd_hub_ai_convo_model "$@" ;;
        *)  N=hub M="Not support such [subcmd=$op]" log:ret:64
    esac
}

___x_cmd_hub_ai_convo_request(){
    local X_help_cmd='___x_cmd help -m hub ai convo request'; help:arg:parse
    local header_flag=""
    case "$1" in
        -h|--help) ___x_cmd help -m hub ai convo request; return ;;
        --agent)   header_flag="X-Service-Agent: $2"; shift 2 ;;
    esac
    ___x_cmd chat --exec --provider hub "$@"
}

___x_cmd_hub_ai_convo_exec(){
    local endpoint="https://agent.x-cmd.com/api"

    ___X_CMD_OPENAI_CHAT_ACTUAL_URL_NOT_V1=1 \
    ___X_CMD_OPENAI_CHAT_ACTUAL_PROVIDER='hub'   \
    ___X_CMD_OPENAI_CHAT_ACTUAL_PROVIDER_NAME='X-CMD Hub AI'  \
    ___X_CMD_OPENAI_CHAT_ACTUAL_ENDPOINT="$endpoint"    \
    ___X_CMD_OPENAI_CHAT_ACTUAL_AUTHORIZATION_HEADER_NAME="X-Service-Authorization" \
    ___X_CMD_OPENAI_CHAT_ACTUAL_HEADER_FlAG="$header_flag" \
    ___x_cmd openai chat exec "$@"
}
