qwen.fish

 1# SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
 2#
 3# SPDX-License-Identifier: Unlicense
 4
 5# Qwen Code agent definition for synu
 6# Provides model configuration for routing through Synthetic API
 7# Qwen Code only accepts configuration via environment variables
 8
 9# Source cache functions
10source (status dirname)/../_synu_cache.fish
11
12# Fallback default (used when no cache entry exists)
13set -g _synu_qwen_fallback_model "hf:MiniMaxAI/MiniMax-M2"
14
15function _synu_qwen_default --description "Get default model"
16    set -l cached (_synu_cache_get qwen model)
17    if test $status -eq 0
18        echo $cached
19    else
20        echo $_synu_qwen_fallback_model
21    end
22end
23
24function _synu_agent_qwen_flags --description "Return argparse-compatible flag specification"
25    echo "m/model="
26end
27
28function _synu_agent_qwen_env_vars --description "Return list of environment variables set by configure"
29    echo OPENAI_API_KEY
30    echo OPENAI_BASE_URL
31    echo OPENAI_MODEL
32end
33
34function _synu_agent_qwen_configure --description "Configure Qwen Code environment variables"
35    # Parse flags passed from main synu
36    argparse 'm/model=' -- $argv
37    or return 1
38
39    # Start with default (from cache or fallback)
40    set -l model (_synu_qwen_default)
41
42    # Apply override if provided
43    if set -q _flag_model
44        set model $_flag_model
45    end
46
47    # Export environment variables for Qwen Code
48    set -gx OPENAI_API_KEY $SYNTHETIC_API_KEY
49    set -gx OPENAI_BASE_URL "https://api.synthetic.new/openai/v1"
50    set -gx OPENAI_MODEL $model
51end
52
53function _synu_agent_qwen_interactive --description "Interactive model selection using gum"
54    # Check for gum
55    if not command -q gum
56        echo "Error: gum is required for interactive mode. Install: https://github.com/charmbracelet/gum" >&2
57        return 1
58    end
59
60    # Fetch available models
61    set -l models_json (gum spin --spinner dot --title "Fetching models..." -- \
62        curl -s -H "Authorization: Bearer $SYNTHETIC_API_KEY" \
63        "https://api.synthetic.new/openai/v1/models")
64    or return 1
65
66    set -l model_names (echo $models_json | jq -r '.data[].name')
67    or return 1
68
69    # Select model
70    set -l model_name (printf "%s\n" $model_names | \
71        gum filter --limit 1 --header "Select model for Qwen Code" \
72        --placeholder "Filter models...")
73    or return 1
74
75    set -l model_id (echo $models_json | \
76        jq -r --arg name "$model_name" '.data[] | select(.name == $name) | .id')
77
78    if test -z "$model_id"
79        echo "Error: Could not find model ID" >&2
80        return 1
81    end
82
83    # Build flags
84    set -l flags --model=$model_id
85
86    # Offer to save as default
87    if gum confirm "Save as default for 'qwen'?"
88        _synu_cache_set qwen model $model_id
89    end
90
91    # Output flags for caller to use
92    echo $flags
93end