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