-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_ccr.sh
More file actions
executable file
·351 lines (302 loc) · 8.7 KB
/
Copy pathsync_ccr.sh
File metadata and controls
executable file
·351 lines (302 loc) · 8.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/bin/bash
# Check for uv
if ! command -v uv &> /dev/null; then
echo "Error: 'uv' command not found. Please install uv to run this script."
exit 1
fi
HELPER="ccr_helper.py"
SCRIPT_DIR="$(dirname "$0")"
HELPER_PATH="$SCRIPT_DIR/$HELPER"
if [ ! -f "$HELPER_PATH" ]; then
echo "Error: $HELPER not found in $SCRIPT_DIR"
exit 1
fi
run_helper() {
uv run python "$HELPER_PATH" "$@"
}
apply_changes() {
echo "Applying changes..."
echo "Restarting CCR..."
ccr restart
if [ $? -eq 0 ]; then
echo "CCR restarted successfully."
else
echo "Failed to restart CCR."
fi
echo "Updating Claude Code settings..."
run_helper update_settings
}
select_model_interactive() {
echo "Fetching available models..."
models_output=$(run_helper list)
if [ -z "$models_output" ]; then
echo "No models found."
return 1
fi
echo "Available Models:"
i=1
declare -a p_names
declare -a m_names
while IFS=, read -r p m; do
if [ -z "$p" ] || [ -z "$m" ]; then continue; fi
echo "$i) $p / $m"
p_names[i]="$p"
m_names[i]="$m"
((i++))
done <<< "$models_output"
count=$((i-1))
if [ "$count" -eq 0 ]; then
echo "No valid models found."
return 1
fi
read -p "Select a model (1-$count): " selection
if [[ "$selection" =~ ^[0-9]+$ ]] && [ "$selection" -ge 1 ] && [ "$selection" -le "$count" ]; then
SELECTED_PROVIDER="${p_names[$selection]}"
SELECTED_MODEL="${m_names[$selection]}"
return 0
else
echo "Invalid selection."
return 1
fi
}
select_route_interactive() {
echo "Fetching available routes..."
routes_output=$(run_helper get_router_keys)
if [ -z "$routes_output" ]; then
echo "No routes found."
return 1
fi
echo "Available Routes:"
i=1
declare -a route_keys
# get_router_keys returns comma separated keys
IFS=',' read -r -a keys_array <<< "$routes_output"
for key in "${keys_array[@]}"; do
# Trim whitespace just in case
key=$(echo "$key" | xargs)
if [ -z "$key" ]; then continue; fi
echo "$i) $key"
route_keys[i]="$key"
((i++))
done
count=$((i-1))
if [ "$count" -eq 0 ]; then
echo "No valid routes found."
return 1
fi
read -p "Select a route to modify (1-$count): " selection
if [[ "$selection" =~ ^[0-9]+$ ]] && [ "$selection" -ge 1 ] && [ "$selection" -le "$count" ]; then
SELECTED_ROUTE="${route_keys[$selection]}"
return 0
else
echo "Invalid selection."
return 1
fi
}
select_provider_interactive() {
echo "Fetching available providers..."
providers_output=$(run_helper list_providers)
if [ -z "$providers_output" ]; then
echo "No providers found."
return 1
fi
echo "Available Providers:"
i=1
declare -a provider_names
while IFS= read -r provider; do
provider=$(echo "$provider" | xargs)
if [ -z "$provider" ]; then continue; fi
echo "$i) $provider"
provider_names[i]="$provider"
((i++))
done <<< "$providers_output"
count=$((i-1))
if [ "$count" -eq 0 ]; then
echo "No valid providers found."
return 1
fi
read -p "Select a provider (1-$count): " selection
if [[ "$selection" =~ ^[0-9]+$ ]] && [ "$selection" -ge 1 ] && [ "$selection" -le "$count" ]; then
SELECTED_PROVIDER="${provider_names[$selection]}"
return 0
else
echo "Invalid selection."
return 1
fi
}
select_preset_interactive() {
echo "Fetching available presets..."
presets_output=$(run_helper list_presets)
if [ -z "$presets_output" ]; then
echo "No presets found."
return 1
fi
echo "Available Presets:"
i=1
declare -a preset_names
while IFS='|' read -r name desc updated; do
# Trim whitespace
name=$(echo "$name" | xargs)
desc=$(echo "$desc" | xargs)
if [ -z "$name" ]; then continue; fi
echo "$i) $name - $desc"
preset_names[i]="$name"
((i++))
done <<< "$presets_output"
count=$((i-1))
if [ "$count" -eq 0 ]; then
echo "No valid presets found."
return 1
fi
read -p "Select a preset (1-$count): " selection
if [[ "$selection" =~ ^[0-9]+$ ]] && [ "$selection" -ge 1 ] && [ "$selection" -le "$count" ]; then
SELECTED_PRESET="${preset_names[$selection]}"
return 0
else
echo "Invalid selection."
return 1
fi
}
save_preset_interactive() {
read -p "Enter preset name: " preset_name
if [ -z "$preset_name" ]; then
echo "Error: Preset name cannot be empty."
return 1
fi
read -p "Enter preset description (optional): " preset_desc
if [ -n "$preset_desc" ]; then
run_helper save_preset "$preset_name" "$preset_desc"
else
run_helper save_preset "$preset_name"
fi
if [ $? -eq 0 ]; then
echo "✓ Preset saved successfully."
else
echo "✗ Failed to save preset."
return 1
fi
}
load_preset_interactive() {
if select_preset_interactive; then
run_helper load_preset "$SELECTED_PRESET"
if [ $? -eq 0 ]; then
echo "✓ Preset loaded successfully."
apply_changes
else
echo "✗ Failed to load preset."
return 1
fi
fi
}
delete_preset_interactive() {
if select_preset_interactive; then
read -p "Are you sure you want to delete preset '$SELECTED_PRESET'? (y/n): " confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
run_helper delete_preset "$SELECTED_PRESET"
if [ $? -eq 0 ]; then
echo "✓ Preset deleted successfully."
else
echo "✗ Failed to delete preset."
fi
else
echo "Deletion cancelled."
fi
fi
}
view_preset_interactive() {
if select_preset_interactive; then
run_helper show_preset "$SELECTED_PRESET"
fi
}
view_router_interactive() {
echo "Current Router Configuration:"
echo ""
run_helper show_router
echo ""
read -p "Press Enter to continue..."
}
while true; do
echo "----------------------------------------"
echo "CCR Model Manager"
echo "----------------------------------------"
echo "1. View Current Router Config"
echo "2. View Models"
echo "3. Add Model to Provider"
echo "4. Update Router (All Routes)"
echo "5. Update Router (Single Route)"
echo "6. Apply Changes & Exit (Update Configs & Restart)"
echo "----------------------------------------"
echo "Presets Management:"
echo "7. View Presets"
echo "8. Save Current Config as Preset"
echo "9. Load Preset"
echo "0. View Preset Details"
echo "----------------------------------------"
echo "d. Delete Preset"
echo "q. Quit (Without Applying)"
echo "----------------------------------------"
read -p "Select an option: " choice
case $choice in
1)
view_router_interactive
;;
2)
echo "Current Models:"
run_helper list
;;
3)
if select_provider_interactive; then
read -p "Enter New Model Name: " m_name
if [ -n "$m_name" ]; then
run_helper add_model "$SELECTED_PROVIDER" "$m_name"
else
echo "Invalid model name."
fi
fi
;;
4)
echo "Select the model to use for ALL routes:"
if select_model_interactive; then
run_helper update_router_all "$SELECTED_PROVIDER" "$SELECTED_MODEL"
apply_changes
fi
;;
5)
if select_route_interactive; then
echo "Select the model for route '$SELECTED_ROUTE':"
if select_model_interactive; then
run_helper update_router "$SELECTED_ROUTE" "$SELECTED_PROVIDER" "$SELECTED_MODEL"
apply_changes
fi
fi
;;
6)
apply_changes
break
;;
7)
echo "Available Presets:"
run_helper list_presets
;;
8)
save_preset_interactive
;;
9)
load_preset_interactive
;;
0)
view_preset_interactive
;;
d|D)
delete_preset_interactive
;;
q)
echo "Exiting..."
break
;;
*)
echo "Invalid option."
;;
esac
echo ""
done