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:zai-org/GLM-4.6"
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    # Get current model for display
70    set -l current_id (_synu_qwen_default)
71    set -l current_name (echo $models_json | \
72        jq -r --arg id "$current_id" '.data[] | select(.id == $id) | .name // "unknown"')
73
74    # Select model
75    set -l model_name (printf "%s\n" $model_names | \
76        gum filter --limit 1 --header "Select model for Qwen Code (current: $current_id)" \
77        --placeholder "Filter models...")
78    or return 1
79
80    set -l model_id (echo $models_json | \
81        jq -r --arg name "$model_name" '.data[] | select(.name == $name) | .id')
82
83    if test -z "$model_id"
84        echo "Error: Could not find model ID" >&2
85        return 1
86    end
87
88    # Build flags
89    set -l flags --model=$model_id
90
91    # Offer to save as default
92    if gum confirm "Save as default for 'qwen'?"
93        _synu_cache_set qwen model $model_id
94    end
95
96    # Output flags for caller to use
97    printf '%s\n' $flags
98end