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:MiniMaxAI/MiniMax-M2"
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    # Return --provider, --baseurl, and --model flags
44    echo --provider
45    echo openai
46    echo --baseurl
47    echo "https://api.synthetic.new/openai/v1"
48    echo --model
49    echo $_synu_llxprt_selected_model
50end
51
52function _synu_agent_llxprt_interactive --description "Interactive model selection using gum"
53    # Check for gum
54    if not command -q gum
55        echo "Error: gum is required for interactive mode. Install: https://github.com/charmbracelet/gum" >&2
56        return 1
57    end
58
59    # Fetch available models
60    set -l models_json (gum spin --spinner dot --title "Fetching models..." -- \
61        curl -s -H "Authorization: Bearer $SYNTHETIC_API_KEY" \
62        "https://api.synthetic.new/openai/v1/models")
63    or return 1
64
65    set -l model_names (echo $models_json | jq -r '.data[].name')
66    or return 1
67
68    # Select model
69    set -l model_name (printf "%s\n" $model_names | \
70        gum filter --limit 1 --header "Select model for llxprt" \
71        --placeholder "Filter models...")
72    or return 1
73
74    set -l model_id (echo $models_json | \
75        jq -r --arg name "$model_name" '.data[] | select(.name == $name) | .id')
76
77    if test -z "$model_id"
78        echo "Error: Could not find model ID" >&2
79        return 1
80    end
81
82    # Build flags
83    set -l flags --model=$model_id
84
85    # Offer to save as default
86    if gum confirm "Save as default for 'llxprt'?"
87        _synu_cache_set llxprt model $model_id
88    end
89
90    # Output flags for caller to use
91    echo $flags
92end