llxprt.fish

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