
# shellcheck shell=dash


alias claude:provider:fetch:init='
local x_url=""
local x_apikey=""
local x_model=""
local x_fastmodel=""
local x_timeout=3000000
local x_nonessential_traffic=1
local x_effortlevel=auto
'

xrc:mod:lib     claude      other/ds    other/kimi    other/zhipu    other/sili    other/doubao    other/openrouter  other/mthreads  other/minimax  other/ali  other/baidu  other/tencent

___x_cmd_claude_other___use(){
    local provider="$1"
    local url="$2"
    local token="$3"
    local model="$4"
    local fast_model="$5"
    local nonessential_traffic="$6"
    local effortlevel="$7"
    shift 7

    local timeout="${API_TIMEOUT_MS:-"3000000"}"

    claude:debug --url "$url" --token "$token" --timeout "$timeout" --model "$model" --fast_model "$fast_model" --nonessential_traffic "$nonessential_traffic" "Use provider[$provider] to run claude-code"

    # ANTHROPIC_BASE_URL="${url}"                                        \
    # ANTHROPIC_AUTH_TOKEN="${token}"                                    \
    # API_TIMEOUT_MS="${timeout}"                                        \
    # ANTHROPIC_MODEL="${model}"                                         \
    # CLAUDE_CODE_SUBAGENT_MODEL="${fast_model}"                         \
    # ANTHROPIC_DEFAULT_OPUS_MODEL="${model}"                            \
    # ANTHROPIC_DEFAULT_SONNET_MODEL="${model}"                          \
    # ANTHROPIC_DEFAULT_HAIKU_MODEL="${fast_model}"                      \
    # CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="${nonessential_traffic}" \
    # CLAUDE_CODE_EFFORT_LEVEL="${effortlevel:-auto}"                    \
    #     ___x_cmd_claude___runmain "$@"

    local settings_json=""
    settings_json="$( ___x_cmd jq -n \
        --arg url "$url" \
        --arg token "$token" \
        --arg timeout "$timeout" \
        --arg model "$model" \
        --arg fastmodel "$fast_model" \
        --arg effortlevel "${effortlevel:-auto}" \
        --arg nonessential "${nonessential_traffic:-1}" \
        '{
            env: {
                ANTHROPIC_BASE_URL: $url,
                ANTHROPIC_AUTH_TOKEN: $token,
                API_TIMEOUT_MS: $timeout,
                CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: $nonessential,
                CLAUDE_CODE_EFFORT_LEVEL: $effortlevel,
                ANTHROPIC_MODEL: $model,
                ANTHROPIC_SMALL_FAST_MODEL: $fastmodel,
                ANTHROPIC_DEFAULT_SONNET_MODEL: $model,
                ANTHROPIC_DEFAULT_OPUS_MODEL: $model,
                ANTHROPIC_DEFAULT_HAIKU_MODEL: $fastmodel
            }
        }'
    )"

    ___x_cmd_claude___runmain --settings "$settings_json" "$@"
}
