crabcode 0.1.7__py3-none-any.whl → 0.1.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {crabcode-0.1.7.dist-info → crabcode-0.1.9.dist-info}/METADATA +1 -1
- {crabcode-0.1.7.dist-info → crabcode-0.1.9.dist-info}/RECORD +30 -21
- {crabcode-0.1.7.dist-info → crabcode-0.1.9.dist-info}/WHEEL +1 -1
- crabcode_cli/model_manager.py +139 -17
- crabcode_cli/repl.py +17 -6
- crabcode_core/_version.py +1 -1
- crabcode_core/api/anthropic_adapter.py +4 -3
- crabcode_core/api/azure_adapter.py +1 -1
- crabcode_core/api/base.py +2 -2
- crabcode_core/api/codex_adapter.py +2 -1
- crabcode_core/api/model_discovery.py +66 -5
- crabcode_core/api/model_info.py +10 -0
- crabcode_core/api/network.py +12 -5
- crabcode_core/api/openai_adapter.py +4 -1
- crabcode_core/config/model_catalog.py +81 -0
- crabcode_core/prompts/library.py +9 -3
- crabcode_core/prompts/presets/claude-code.json +41 -0
- crabcode_core/prompts/presets/codex.json +47 -0
- crabcode_core/prompts/presets/cursor.json +53 -0
- crabcode_core/prompts/presets/dsh.json +101 -0
- crabcode_core/prompts/presets/kimi-code.json +59 -0
- crabcode_core/prompts/presets/opencode.json +23 -0
- crabcode_core/prompts/presets/qoder.json +185 -0
- crabcode_core/prompts/presets/zcode.json +23 -0
- crabcode_core/prompts/presets.py +47 -0
- crabcode_core/prompts/profile.py +3 -0
- crabcode_core/prompts/system.py +13 -0
- crabcode_gateway/routes/config.py +27 -26
- crabcode_gateway/schemas.py +25 -0
- {crabcode-0.1.7.dist-info → crabcode-0.1.9.dist-info}/entry_points.txt +0 -0
|
@@ -3,15 +3,15 @@ crabcode_cli/__main__.py,sha256=ekwH_ayJ5YpefhbXSDj-IM9mS9YrCwWpoDIH92V6tjg,75
|
|
|
3
3
|
crabcode_cli/app.py,sha256=o7P9cQBTo7mY6OFDhaJVx39qdfj_Zqc2Qfku-z3eGSU,31579
|
|
4
4
|
crabcode_cli/banner.py,sha256=WlQPxVLLnzIE6xlP6gFbpCDYmDewzIwLtHKFLf9GC-I,1339
|
|
5
5
|
crabcode_cli/computer_use.py,sha256=F2ROhv4c7-j70N_-qPKRv69PkTIwkt2sWFC_qPEfpiQ,13973
|
|
6
|
-
crabcode_cli/model_manager.py,sha256=
|
|
6
|
+
crabcode_cli/model_manager.py,sha256=moii4RQJegZGMB5GgN9O3VQmMAspGLIKr1MJx6EO7f4,27268
|
|
7
7
|
crabcode_cli/model_picker.py,sha256=ghxsVySXy9WZVJLVb3ElTf9D2sWeT6lidcPWB0gX-_Y,8352
|
|
8
8
|
crabcode_cli/pipe.py,sha256=hIOqrkUNbm3jXXz7NRX-HlbbWb3uPlWZwO6UUpIhtvg,5431
|
|
9
|
-
crabcode_cli/repl.py,sha256=
|
|
9
|
+
crabcode_cli/repl.py,sha256=C8rzQC3RXbAjIanCZ8RKwgnvK_fyiZpcS6R0c45harg,193733
|
|
10
10
|
crabcode_cli/session_picker.py,sha256=Pett41MV4xcg6vDR4Rbq8C0bh40u-GVF_cjQldNQIoQ,10307
|
|
11
11
|
crabcode_cli/render/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
crabcode_cli/render/messages.py,sha256=n9OsbLIAU3FyO9gwGMMJld7zq-71N0caz9ecmE2kIjo,568
|
|
13
13
|
crabcode_core/__init__.py,sha256=ArpgEg5xC3iR4DRT0HBg7DwU3K-r1MnmDOHpIb1b0E4,142
|
|
14
|
-
crabcode_core/_version.py,sha256=
|
|
14
|
+
crabcode_core/_version.py,sha256=1Z8kzCsY4eqFoXtkIcJdwZMsVCRoZxIAfarpn7BQ__E,82
|
|
15
15
|
crabcode_core/_windows_process.py,sha256=PjRQqZfLSHdvexANQYHZDQNxyu2s1Yaxt1YNlawwNIU,2949
|
|
16
16
|
crabcode_core/agent_manager.py,sha256=Wu7kHfA5_zSTHYLemqOD85deblcwDdtvnZVE4rmq-Vc,71475
|
|
17
17
|
crabcode_core/command_line.py,sha256=MWbAF4QUDVdwGM8cKoHYnIgr8yOgqk3Y_0ndt9f-t6Y,544
|
|
@@ -32,17 +32,17 @@ crabcode_core/turn_details.py,sha256=Km_qHTGz2OhnrRFJP9kuO02AcX1q-uTmR010vIh4WBE
|
|
|
32
32
|
crabcode_core/usage.py,sha256=vNydrtitdH3Q690k-3x738LhKiJsXGcMw-ruOEL0csU,16307
|
|
33
33
|
crabcode_core/utf8_sanitize.py,sha256=RRTGgwA9jqK-HLR1WUSFwgG4xJn7ZukTDu7M6Oi3fHI,936
|
|
34
34
|
crabcode_core/api/__init__.py,sha256=IXs4hLgC4cT85TLdmS4KgtPKYDytadkwvrDyBshr5ag,674
|
|
35
|
-
crabcode_core/api/anthropic_adapter.py,sha256=
|
|
36
|
-
crabcode_core/api/azure_adapter.py,sha256=
|
|
37
|
-
crabcode_core/api/base.py,sha256=
|
|
38
|
-
crabcode_core/api/codex_adapter.py,sha256=
|
|
35
|
+
crabcode_core/api/anthropic_adapter.py,sha256=YusxU59dh_wm87xVTSv09T-Cx-Azz_wUK0zgjGs2VqI,26486
|
|
36
|
+
crabcode_core/api/azure_adapter.py,sha256=2wFAMlcrpTqySD9A5QxgR0Klig3MthJI_SUgBCmo2L8,2452
|
|
37
|
+
crabcode_core/api/base.py,sha256=lwVcfz6byMu4Yw0w-Yi5dxHlO2PHXPaiA5OlnvySmhk,8538
|
|
38
|
+
crabcode_core/api/codex_adapter.py,sha256=NKQuR-C-6HB96-4ixPCdrB4tsT1ehNYLqMJ5lzhkb2E,54813
|
|
39
39
|
crabcode_core/api/error_logging.py,sha256=2GMD8naR-Tk9Eki_i2GJQShAWGVvt6XZATs8SLXRR8Q,5326
|
|
40
40
|
crabcode_core/api/gemini_adapter.py,sha256=RVk3zlLPqDtzG8w5psu4aSoFyFLua5qQx3subqz-5DQ,1130
|
|
41
|
-
crabcode_core/api/model_discovery.py,sha256=
|
|
42
|
-
crabcode_core/api/model_info.py,sha256=
|
|
43
|
-
crabcode_core/api/network.py,sha256=
|
|
41
|
+
crabcode_core/api/model_discovery.py,sha256=Yow48Sa1ZAePIZOq1FfHJ8Yhn2iHAF8yzIJgZY_IkUA,10396
|
|
42
|
+
crabcode_core/api/model_info.py,sha256=SsZzWxhGyjxpQnwm8Iz5PGFwCfoePj_JbcsVeJif1Ds,8990
|
|
43
|
+
crabcode_core/api/network.py,sha256=PziTbJI8D6EvBvN4OVHqNwGLbdkRBIFq1oXLfcZM-lc,2798
|
|
44
44
|
crabcode_core/api/ollama_adapter.py,sha256=ZpTg11zOUGFE0J88qBXL7AvxDQU5PjWg2wWvm4uxUvY,1158
|
|
45
|
-
crabcode_core/api/openai_adapter.py,sha256=
|
|
45
|
+
crabcode_core/api/openai_adapter.py,sha256=Ea7W543mtgutmdKC7H5GbSIZg1X4bWvur3Ul759Zg_Y,12364
|
|
46
46
|
crabcode_core/api/registry.py,sha256=tCVRE74bMUn9ukCbGp3bDtSOYZ6_EmsNfdVnnkGN6k4,2413
|
|
47
47
|
crabcode_core/compact/__init__.py,sha256=9445RwiG5BI8b6mrXMcNkcPLs5NH3RSKFxDrXsgmmK8,395
|
|
48
48
|
crabcode_core/compact/compact.py,sha256=_5BjLhPJA7WkvQzBAor7d9QXF9Nluui7bZTtBNvPLpY,19580
|
|
@@ -50,7 +50,7 @@ crabcode_core/compact/context_tokens.py,sha256=ZOLoNFmwj_caf5_NIHDnoBM6ja0k0GLP1
|
|
|
50
50
|
crabcode_core/config/__init__.py,sha256=wbSnNVCqj673phu2pvIFz-f5HM5bLvH-FdD9b01HNRA,84
|
|
51
51
|
crabcode_core/config/claudemd.py,sha256=jl7HN7k-kJryOTGcJ7vEsP3_iw_TVKsq_Rx9VCMGKbA,2268
|
|
52
52
|
crabcode_core/config/manager.py,sha256=MqGYczrKUqFdl216ZVeEZ7-hseMA9QXM-lhr3eKaIb8,8497
|
|
53
|
-
crabcode_core/config/model_catalog.py,sha256=
|
|
53
|
+
crabcode_core/config/model_catalog.py,sha256=bv-yqG9USYFfnEynQiwSSSyjsH_WsPensMN_5pp0vg4,12015
|
|
54
54
|
crabcode_core/hooks/__init__.py,sha256=wfOnbLuJqtLezKYWYmBTAE9qG-eaG7wSfgx1-kS7N64,165
|
|
55
55
|
crabcode_core/hooks/manager.py,sha256=bVbe08EAGbY-pNxgkTFzonOEP4kE49Z8Ly9gIq-mv2U,10072
|
|
56
56
|
crabcode_core/lsp/__init__.py,sha256=np9EYVvOi94ZFxLWW_kD13AfwaIhN0Vcp8-pHaLDn6c,189
|
|
@@ -71,10 +71,19 @@ crabcode_core/plan/types.py,sha256=pPfcdu40sTbxr8uBNAEguZR1GzvSFYDIL40HL_bU_io,5
|
|
|
71
71
|
crabcode_core/prompts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
72
72
|
crabcode_core/prompts/blocks.py,sha256=pZZQ20oMNhy33osEwwwUtV3P0N3rtTZE4hRE8_rjvHY,438
|
|
73
73
|
crabcode_core/prompts/context.py,sha256=TBRVd0MzPKPTejgKIyBlzVJRkFguZnYZ2VX5Je_VJbg,8034
|
|
74
|
-
crabcode_core/prompts/library.py,sha256
|
|
75
|
-
crabcode_core/prompts/
|
|
76
|
-
crabcode_core/prompts/
|
|
74
|
+
crabcode_core/prompts/library.py,sha256=_DVzZgTm7mWkdJguEYJ1iIJqZf-C7h6kFcSSFaodFDQ,3422
|
|
75
|
+
crabcode_core/prompts/presets.py,sha256=CJPVgaMz2K6n2ZuQI7R9IbVUPzPqZ8jBgTU4zwQtvYw,1631
|
|
76
|
+
crabcode_core/prompts/profile.py,sha256=EOgLWQyuXR5X5lb5OXWct_i4JzcHCWIUa_r-Ma_cAyM,2796
|
|
77
|
+
crabcode_core/prompts/system.py,sha256=B_6LUi1N3fDThaTIj98X5LrwQPQB7H1al6kf1i46dH0,19211
|
|
77
78
|
crabcode_core/prompts/templates.py,sha256=aJ2NcYdi44PqQEZ76ddvvd3cOw94TvDviTZlCF4ZB7c,3656
|
|
79
|
+
crabcode_core/prompts/presets/claude-code.json,sha256=1ICGtf-e0I3W2uWkdsgSbEgrS3Tyx2WNuYQ44HsEFGo,13594
|
|
80
|
+
crabcode_core/prompts/presets/codex.json,sha256=xQk2rsVBJqZK5g0HsvD1Vb8e-c9mMIfe2E9p1AO_FUo,15138
|
|
81
|
+
crabcode_core/prompts/presets/cursor.json,sha256=tYl1fl69WBpky2gdmgoCWYXy4tkpZ3Yo78XzQEtAy48,16705
|
|
82
|
+
crabcode_core/prompts/presets/dsh.json,sha256=aQNRjaG9wsHaB1aqeSGzLYBF3JvbluJgUr2KSXUlDRk,7021
|
|
83
|
+
crabcode_core/prompts/presets/kimi-code.json,sha256=BOZKaMyDRiW2hs3s8iFc9FProM4fsKsvo3_QwMF3W3c,10797
|
|
84
|
+
crabcode_core/prompts/presets/opencode.json,sha256=1AZ-wdqyNtrbtnpwPsznh2Zh_0EHnr9qAbQo7f7Y3xA,9685
|
|
85
|
+
crabcode_core/prompts/presets/qoder.json,sha256=HAWUxbAwztjJFZ23WLbngmpMjNBNtcyBHcIJDNbnlN8,25664
|
|
86
|
+
crabcode_core/prompts/presets/zcode.json,sha256=pgmawAVlzMS-LBPXnWvdDQJp9iti1wDhjwRSI17Gbts,7224
|
|
78
87
|
crabcode_core/query/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
79
88
|
crabcode_core/query/computer_use_history.py,sha256=-dEi8KcsROBXBzYd0MchJ43aCND7ZVTV_JUY1jiaHVI,4245
|
|
80
89
|
crabcode_core/query/loop.py,sha256=CWX0bdDgfkKsF9KIzGW5qgTbOBguJtu1hNsyciFkxAI,100471
|
|
@@ -158,7 +167,7 @@ crabcode_gateway/event_bus.py,sha256=lWLCeoKkJ9fhDT_Kwc_esokDsbeRkPi5hsK87kPxRRY
|
|
|
158
167
|
crabcode_gateway/middleware.py,sha256=bn0pUJHWINc_28ZgZ6e7i-AarkqhfQZMaxbknAVU5UA,11293
|
|
159
168
|
crabcode_gateway/protocol.py,sha256=psXRNQjkfwliXZdETlo1qsGM0IcE_OIUarCLnSNuq6o,466
|
|
160
169
|
crabcode_gateway/safe_file.py,sha256=uOdkxWdZNQ5RJ2jJ9urnIRiF_2uAP8Dkj8wR08vbDaU,2108
|
|
161
|
-
crabcode_gateway/schemas.py,sha256=
|
|
170
|
+
crabcode_gateway/schemas.py,sha256=w7Z9yUTw_t2xwZWtIYHgcbyDiOKtRwEGqtPsazT69ug,57407
|
|
162
171
|
crabcode_gateway/server.py,sha256=ShCrO1Zw-Ed37HfUYihyOToJasGJjL7Kzy1BFA4CJ64,20408
|
|
163
172
|
crabcode_gateway/session_registry.py,sha256=HhvLvlGDx0EgmGwjk2zHCCtWURmNDZHHmpBjroX35fk,1214
|
|
164
173
|
crabcode_gateway/task_registry.py,sha256=Ij8USxQ13ockqhoZ286hn8jXckFeLglNSgwgcnQ5tX4,26461
|
|
@@ -177,7 +186,7 @@ crabcode_gateway/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
|
|
|
177
186
|
crabcode_gateway/routes/agent.py,sha256=ZI97BVRMPgwpv45IqWFoESO_Khr0uFfy6J-tDojNWOU,13955
|
|
178
187
|
crabcode_gateway/routes/auth.py,sha256=kIynPq7LUBlKwS--1Qp1hJHpLqebB5Unt1qAI8V_dUI,4945
|
|
179
188
|
crabcode_gateway/routes/computer_use.py,sha256=_NtMi3zciudhDRcha53fXL3jECp6Oj5cWWvWKD_JLAY,4622
|
|
180
|
-
crabcode_gateway/routes/config.py,sha256=
|
|
189
|
+
crabcode_gateway/routes/config.py,sha256=b1nXnJsvJlrrEEkQMGZFOOvCUZZGTTbsuPEa_lC1Pjo,71120
|
|
181
190
|
crabcode_gateway/routes/document.py,sha256=j01jt88A29GF6fHYcX2AparZAOPsUrwllec9YGtFswg,78665
|
|
182
191
|
crabcode_gateway/routes/event.py,sha256=WOr1WHJ-5nCcpCWIkpIos2aAl2ASJUyYKSaLZ5bCRS0,155226
|
|
183
192
|
crabcode_gateway/routes/git_review.py,sha256=-fbMOWo8JKnHCMsKew3i02lTE7Ohj9w6ocgFKCsYeio,10460
|
|
@@ -198,7 +207,7 @@ crabcode_search/embedder.py,sha256=NlNuOHS7t4JvaWXkNU-T_xxnkjRxFrr3l57dlB5IRkc,1
|
|
|
198
207
|
crabcode_search/indexer.py,sha256=bBL3OE6HMqdIRBCnI--XjaHl7_G3H4VO2d-RMKtjlkI,7745
|
|
199
208
|
crabcode_search/store.py,sha256=s1hsyRRGcAO_hdJli6M0C8rhkMW4tXj5ZVMPuCP3uhQ,8074
|
|
200
209
|
crabcode_search/tool.py,sha256=xJjAN3esvJIH3z7ILNQ1gQs5Ty5fu6u7CYX6P2WB_BY,10238
|
|
201
|
-
crabcode-0.1.
|
|
202
|
-
crabcode-0.1.
|
|
203
|
-
crabcode-0.1.
|
|
204
|
-
crabcode-0.1.
|
|
210
|
+
crabcode-0.1.9.dist-info/METADATA,sha256=1mKVqGqb0zYCvUoDu1c461rQATnHK3Bzbdjw4E2lanY,2799
|
|
211
|
+
crabcode-0.1.9.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
212
|
+
crabcode-0.1.9.dist-info/entry_points.txt,sha256=tpYKME-yDLFb2eqwryWJG-d-HW4dkvDbzwogRl2jays,52
|
|
213
|
+
crabcode-0.1.9.dist-info/RECORD,,
|
crabcode_cli/model_manager.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Guided terminal menus for adding and deleting
|
|
1
|
+
"""Guided terminal menus for adding, discovering and deleting models."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -16,17 +16,20 @@ from prompt_toolkit.layout import HSplit, Layout, VSplit, Window
|
|
|
16
16
|
from prompt_toolkit.layout.controls import BufferControl, FormattedTextControl
|
|
17
17
|
|
|
18
18
|
from crabcode_cli.session_picker import PICKER_STYLE, _plain
|
|
19
|
+
from crabcode_core.api.model_discovery import ModelDiscoveryError, discover_models
|
|
19
20
|
from crabcode_core.config.manager import ConfigManager
|
|
20
21
|
from crabcode_core.config.model_catalog import (
|
|
21
22
|
SETTINGS_SOURCE_LABELS,
|
|
22
23
|
WRITABLE_SETTINGS_SOURCES,
|
|
23
24
|
CatalogKind,
|
|
25
|
+
CatalogImportResult,
|
|
24
26
|
CatalogMutationResult,
|
|
25
27
|
ModelCatalogError,
|
|
26
28
|
WritableSettingsSource,
|
|
27
29
|
add_catalog_entry,
|
|
28
30
|
catalog_names,
|
|
29
31
|
delete_catalog_entry,
|
|
32
|
+
import_group_models,
|
|
30
33
|
list_catalog_definitions,
|
|
31
34
|
referencing_models,
|
|
32
35
|
settings_source_path,
|
|
@@ -36,6 +39,7 @@ from crabcode_core.events import CoreSession
|
|
|
36
39
|
|
|
37
40
|
|
|
38
41
|
ManagementAction = Literal["add", "delete"]
|
|
42
|
+
ManagementKind = Literal["model", "group", "discover"]
|
|
39
43
|
|
|
40
44
|
_SENSITIVE_CONFIG_KEYS = (
|
|
41
45
|
"api_key",
|
|
@@ -53,6 +57,7 @@ class MenuOption:
|
|
|
53
57
|
value: str
|
|
54
58
|
label: str
|
|
55
59
|
hint: str = ""
|
|
60
|
+
disabled: bool = False
|
|
56
61
|
|
|
57
62
|
|
|
58
63
|
class Prompter(Protocol):
|
|
@@ -65,6 +70,10 @@ class Prompter(Protocol):
|
|
|
65
70
|
initial: str | None = None,
|
|
66
71
|
) -> str | None: ...
|
|
67
72
|
|
|
73
|
+
async def multiselect(
|
|
74
|
+
self, message: str, options: Sequence[MenuOption],
|
|
75
|
+
) -> list[str] | None: ...
|
|
76
|
+
|
|
68
77
|
async def text(self, message: str, *, initial: str = "") -> str | None: ...
|
|
69
78
|
|
|
70
79
|
async def confirm(self, message: str, *, default: bool = False) -> bool | None: ...
|
|
@@ -85,12 +94,16 @@ class SearchableMenu:
|
|
|
85
94
|
*,
|
|
86
95
|
searchable: bool = True,
|
|
87
96
|
initial: str | None = None,
|
|
97
|
+
multiple: bool = False,
|
|
88
98
|
) -> None:
|
|
89
99
|
self.title = title
|
|
90
100
|
self.message = message
|
|
91
101
|
self.options = list(options)
|
|
92
102
|
self.searchable = searchable
|
|
93
103
|
self.initial = initial
|
|
104
|
+
self.multiple = multiple
|
|
105
|
+
self.checked: set[str] = set()
|
|
106
|
+
self.selection_error = ""
|
|
94
107
|
self.matches = self.options.copy()
|
|
95
108
|
self.selected = next(
|
|
96
109
|
(index for index, option in enumerate(self.matches) if option.value == initial),
|
|
@@ -118,9 +131,39 @@ class SearchableMenu:
|
|
|
118
131
|
|
|
119
132
|
@bindings.add("enter", eager=True)
|
|
120
133
|
def confirm(event: Any) -> None:
|
|
121
|
-
if self.
|
|
134
|
+
if self.multiple:
|
|
135
|
+
if self.checked:
|
|
136
|
+
event.app.exit(result=[option.value for option in self.options if option.value in self.checked])
|
|
137
|
+
elif self.matches:
|
|
122
138
|
event.app.exit(result=self.matches[self.selected].value)
|
|
123
139
|
|
|
140
|
+
if multiple:
|
|
141
|
+
@bindings.add("tab", eager=True)
|
|
142
|
+
@bindings.add(" ", eager=True)
|
|
143
|
+
def toggle(event: Any) -> None:
|
|
144
|
+
if self.matches:
|
|
145
|
+
option = self.matches[self.selected]
|
|
146
|
+
if option.disabled:
|
|
147
|
+
return
|
|
148
|
+
self.selection_error = ""
|
|
149
|
+
if option.value in self.checked:
|
|
150
|
+
self.checked.remove(option.value)
|
|
151
|
+
elif len(self.checked) < 1000:
|
|
152
|
+
self.checked.add(option.value)
|
|
153
|
+
else:
|
|
154
|
+
self.selection_error = "Select at most 1000 models per import."
|
|
155
|
+
|
|
156
|
+
@bindings.add("c-a", eager=True)
|
|
157
|
+
def toggle_visible(event: Any) -> None:
|
|
158
|
+
visible = {option.value for option in self.matches if not option.disabled}
|
|
159
|
+
self.selection_error = ""
|
|
160
|
+
if visible <= self.checked:
|
|
161
|
+
self.checked.difference_update(visible)
|
|
162
|
+
elif len(self.checked | visible) <= 1000:
|
|
163
|
+
self.checked.update(visible)
|
|
164
|
+
else:
|
|
165
|
+
self.selection_error = "Select at most 1000 models; narrow the search first."
|
|
166
|
+
|
|
124
167
|
@bindings.add("up")
|
|
125
168
|
@bindings.add("down")
|
|
126
169
|
@bindings.add("pageup")
|
|
@@ -172,11 +215,11 @@ class SearchableMenu:
|
|
|
172
215
|
self.list_window,
|
|
173
216
|
Window(FormattedTextControl(self._details), height=2, wrap_lines=True),
|
|
174
217
|
Window(char="─", height=1, style="class:hint"),
|
|
175
|
-
Window(FormattedTextControl(self._footer), height=2, wrap_lines=True),
|
|
218
|
+
Window(FormattedTextControl(self._footer), height=3 if multiple else 2, wrap_lines=True),
|
|
176
219
|
]
|
|
177
220
|
)
|
|
178
221
|
focused = self.search if searchable else self.list_control
|
|
179
|
-
self.app: Application[str | None] = Application(
|
|
222
|
+
self.app: Application[str | list[str] | None] = Application(
|
|
180
223
|
layout=Layout(HSplit(content), focused_element=focused),
|
|
181
224
|
key_bindings=bindings,
|
|
182
225
|
full_screen=True,
|
|
@@ -218,10 +261,13 @@ class SearchableMenu:
|
|
|
218
261
|
fragments: list[tuple[str, str]] = []
|
|
219
262
|
for index, option in enumerate(self.matches):
|
|
220
263
|
style = "class:selected" if index == self.selected else ""
|
|
264
|
+
marker = ""
|
|
265
|
+
if self.multiple:
|
|
266
|
+
marker = "[✓] " if option.disabled else "[x] " if option.value in self.checked else "[ ] "
|
|
221
267
|
fragments.extend(
|
|
222
268
|
[
|
|
223
269
|
(style, " ❯ " if index == self.selected else " "),
|
|
224
|
-
(style, _plain(option.label)),
|
|
270
|
+
(style, marker + _plain(option.label)),
|
|
225
271
|
("", "\n" if index < len(self.matches) - 1 else ""),
|
|
226
272
|
]
|
|
227
273
|
)
|
|
@@ -237,6 +283,12 @@ class SearchableMenu:
|
|
|
237
283
|
|
|
238
284
|
def _footer(self) -> list[tuple[str, str]]:
|
|
239
285
|
count = len(self.matches)
|
|
286
|
+
if self.multiple:
|
|
287
|
+
return [("class:hint",
|
|
288
|
+
" ↑↓ browse · Space/Tab toggle · Enter import · Esc cancel\n"
|
|
289
|
+
" Ctrl+A toggle results · Type to search · Ctrl+U clear\n"
|
|
290
|
+
f" {self.selection_error or f'{len(self.checked)} selected · {count} shown'}"
|
|
291
|
+
)]
|
|
240
292
|
search_help = " · Type to search" if self.searchable else ""
|
|
241
293
|
return [
|
|
242
294
|
(
|
|
@@ -246,7 +298,7 @@ class SearchableMenu:
|
|
|
246
298
|
)
|
|
247
299
|
]
|
|
248
300
|
|
|
249
|
-
async def run(self) -> str | None:
|
|
301
|
+
async def run(self) -> str | list[str] | None:
|
|
250
302
|
if not self.options:
|
|
251
303
|
return None
|
|
252
304
|
return await self.app.run_async()
|
|
@@ -264,13 +316,22 @@ class TerminalPrompter:
|
|
|
264
316
|
searchable: bool = True,
|
|
265
317
|
initial: str | None = None,
|
|
266
318
|
) -> str | None:
|
|
267
|
-
|
|
319
|
+
result = await SearchableMenu(
|
|
268
320
|
"Model management",
|
|
269
321
|
message,
|
|
270
322
|
options,
|
|
271
323
|
searchable=searchable,
|
|
272
324
|
initial=initial,
|
|
273
325
|
).run()
|
|
326
|
+
return cast(str | None, result)
|
|
327
|
+
|
|
328
|
+
async def multiselect(
|
|
329
|
+
self, message: str, options: Sequence[MenuOption],
|
|
330
|
+
) -> list[str] | None:
|
|
331
|
+
result = await SearchableMenu(
|
|
332
|
+
"Get models from group", message, options, multiple=True,
|
|
333
|
+
).run()
|
|
334
|
+
return cast(list[str] | None, result)
|
|
274
335
|
|
|
275
336
|
async def text(self, message: str, *, initial: str = "") -> str | None:
|
|
276
337
|
prompt: PromptSession[str] = PromptSession()
|
|
@@ -337,17 +398,21 @@ _FORMATS: tuple[MenuOption, ...] = tuple(
|
|
|
337
398
|
async def manage_model_catalog(
|
|
338
399
|
session: CoreSession,
|
|
339
400
|
action: ManagementAction,
|
|
340
|
-
kind:
|
|
401
|
+
kind: ManagementKind | None = None,
|
|
341
402
|
*,
|
|
342
403
|
prompter: Prompter | None = None,
|
|
343
|
-
) -> CatalogMutationResult | None:
|
|
344
|
-
"""Run the guided
|
|
404
|
+
) -> CatalogMutationResult | CatalogImportResult | None:
|
|
405
|
+
"""Run the guided management flow and refresh the current session catalog."""
|
|
345
406
|
active_prompter = prompter or TerminalPrompter()
|
|
346
407
|
try:
|
|
347
408
|
selected_kind = kind or await _choose_kind(action, active_prompter)
|
|
348
409
|
if selected_kind is None:
|
|
349
410
|
return None
|
|
350
|
-
if
|
|
411
|
+
if selected_kind == "discover":
|
|
412
|
+
if action != "add":
|
|
413
|
+
raise ModelCatalogError("Use /add discover to fetch models from a group.")
|
|
414
|
+
result = await _discover_group_models(session, active_prompter)
|
|
415
|
+
elif action == "add":
|
|
351
416
|
result = await _add_entry(session, selected_kind, active_prompter)
|
|
352
417
|
else:
|
|
353
418
|
result = await _delete_entry(session, selected_kind, active_prompter)
|
|
@@ -358,17 +423,74 @@ async def manage_model_catalog(
|
|
|
358
423
|
return None
|
|
359
424
|
|
|
360
425
|
|
|
361
|
-
async def _choose_kind(action: ManagementAction, prompter: Prompter) ->
|
|
426
|
+
async def _choose_kind(action: ManagementAction, prompter: Prompter) -> ManagementKind | None:
|
|
427
|
+
options = [
|
|
428
|
+
MenuOption("model", "Model", "A named model profile shown by /model"),
|
|
429
|
+
MenuOption("group", "Group", "Shared provider and API settings inherited by models"),
|
|
430
|
+
]
|
|
431
|
+
if action == "add":
|
|
432
|
+
options.append(MenuOption("discover", "Get models from group", "Fetch, search and import models using a saved group"))
|
|
362
433
|
value = await prompter.select(
|
|
363
434
|
"What do you want to add?" if action == "add" else "What do you want to delete?",
|
|
364
|
-
|
|
365
|
-
MenuOption("model", "Model", "A named model profile shown by /model"),
|
|
366
|
-
MenuOption("group", "Group", "Shared provider and API settings inherited by models"),
|
|
367
|
-
),
|
|
435
|
+
options,
|
|
368
436
|
searchable=False,
|
|
369
437
|
initial="model",
|
|
370
438
|
)
|
|
371
|
-
return cast(
|
|
439
|
+
return cast(ManagementKind | None, value)
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
async def _discover_group_models(
|
|
443
|
+
session: CoreSession, prompter: Prompter,
|
|
444
|
+
) -> CatalogImportResult | None:
|
|
445
|
+
settings = ConfigManager(cwd=session.cwd).load()
|
|
446
|
+
if not settings.groups:
|
|
447
|
+
raise ModelCatalogError("No configuration groups found. Create one with /add group first.")
|
|
448
|
+
name = await prompter.select(
|
|
449
|
+
"Select a group to fetch models from",
|
|
450
|
+
[MenuOption(name, name, _config_hint(group.model_dump(exclude_none=True)))
|
|
451
|
+
for name, group in settings.groups.items()],
|
|
452
|
+
)
|
|
453
|
+
if name is None:
|
|
454
|
+
return None
|
|
455
|
+
prompter.note("Fetching model list", f"Group: {_plain(name)} · timeout: 15 seconds")
|
|
456
|
+
try:
|
|
457
|
+
models = await discover_models(settings.groups[name], settings.env)
|
|
458
|
+
except ModelDiscoveryError as exc:
|
|
459
|
+
raise ModelCatalogError(str(exc)) from None
|
|
460
|
+
existing_ids = {config.model for config in settings.models.values() if config.group == name}
|
|
461
|
+
available = [model for model in models if model["id"] not in existing_ids]
|
|
462
|
+
if not available:
|
|
463
|
+
prompter.note("Model list", "All returned models are already in this group." if models else "The API returned no models.")
|
|
464
|
+
return None
|
|
465
|
+
options = []
|
|
466
|
+
for model in models:
|
|
467
|
+
existing = model["id"] in existing_ids
|
|
468
|
+
metadata = model.get("config", {})
|
|
469
|
+
hints = [model.get("name", "")]
|
|
470
|
+
hints.extend(f"{key}: {value}" for key, value in metadata.items())
|
|
471
|
+
options.append(MenuOption(
|
|
472
|
+
model["id"], model["id"] + (" · already added" if existing else ""),
|
|
473
|
+
" · ".join(hint for hint in hints if hint), disabled=existing,
|
|
474
|
+
))
|
|
475
|
+
selected = await prompter.multiselect(f"Group: {name} · select models to import", options)
|
|
476
|
+
if not selected:
|
|
477
|
+
return None
|
|
478
|
+
selected_ids = set(selected)
|
|
479
|
+
if not selected_ids <= {model["id"] for model in available}:
|
|
480
|
+
raise ModelCatalogError("Select only available models from the fetched list.")
|
|
481
|
+
source = await _choose_source(session.cwd, prompter)
|
|
482
|
+
preview = "\n".join(_plain(model_id) for model_id in selected[:20])
|
|
483
|
+
if len(selected) > 20:
|
|
484
|
+
preview += f"\n… and {len(selected) - 20} more"
|
|
485
|
+
prompter.note(
|
|
486
|
+
f'Import {len(selected)} models from "{_plain(name)}" into {SETTINGS_SOURCE_LABELS[source]}', preview,
|
|
487
|
+
)
|
|
488
|
+
if not await prompter.confirm("Import selected models?", default=True):
|
|
489
|
+
return None
|
|
490
|
+
return import_group_models(
|
|
491
|
+
session.cwd, source, name, selected,
|
|
492
|
+
{model["id"]: model["config"] for model in models if model["id"] in selected_ids and model.get("config")},
|
|
493
|
+
)
|
|
372
494
|
|
|
373
495
|
|
|
374
496
|
async def _choose_source(cwd: str, prompter: Prompter) -> WritableSettingsSource:
|
crabcode_cli/repl.py
CHANGED
|
@@ -209,7 +209,7 @@ _SLASH_COMMANDS: dict[str, list[str]] = {
|
|
|
209
209
|
"/ultra": ["true", "false"],
|
|
210
210
|
"/logs": ["-f", "--follow", "--clear", "--tail"],
|
|
211
211
|
"/model": [], # Dynamic: model names
|
|
212
|
-
"/add": ["model", "group"],
|
|
212
|
+
"/add": ["model", "group", "discover"],
|
|
213
213
|
"/del": ["model", "group"],
|
|
214
214
|
"/new": [],
|
|
215
215
|
"/compact": [],
|
|
@@ -394,7 +394,7 @@ class _CrabCodeCompleter(Completer):
|
|
|
394
394
|
"/ultra": "toggle/set ultra mode",
|
|
395
395
|
"/logs": "show background logs",
|
|
396
396
|
"/model": "show/switch model",
|
|
397
|
-
"/add": "add a model or group",
|
|
397
|
+
"/add": "add a model or group, or fetch models from a group",
|
|
398
398
|
"/del": "delete a model or group",
|
|
399
399
|
"/new": "start new session",
|
|
400
400
|
"/compact": "compact conversation",
|
|
@@ -2978,7 +2978,7 @@ async def _handle_command(
|
|
|
2978
2978
|
"[bold]/logs --clear <name>[/] — clear a background log\n"
|
|
2979
2979
|
"[bold]/model[/] — browse and switch configured models\n"
|
|
2980
2980
|
"[bold]/model <name>[/] — switch to a named model\n"
|
|
2981
|
-
"[bold]/add [model|group][/] — add a model
|
|
2981
|
+
"[bold]/add [model|group|discover][/] — add a model/group or fetch models from a group\n"
|
|
2982
2982
|
"[bold]/del [model|group][/] — delete a model profile or shared group\n"
|
|
2983
2983
|
"[bold]/new[/] — start a new session\n"
|
|
2984
2984
|
"[bold]/compact[/] — compact conversation\n"
|
|
@@ -3263,12 +3263,14 @@ async def _handle_command(
|
|
|
3263
3263
|
|
|
3264
3264
|
if cmd in {"/add", "/del"}:
|
|
3265
3265
|
kind_value = arg.casefold()
|
|
3266
|
-
if
|
|
3267
|
-
|
|
3266
|
+
allowed_kinds = {"", "model", "group", "discover"} if cmd == "/add" else {"", "model", "group"}
|
|
3267
|
+
if kind_value not in allowed_kinds:
|
|
3268
|
+
choices = "model|group|discover" if cmd == "/add" else "model|group"
|
|
3269
|
+
console.print(f"[dim]Usage: {cmd} [{choices}][/]")
|
|
3268
3270
|
return True
|
|
3269
3271
|
|
|
3270
3272
|
from crabcode_cli.model_manager import manage_model_catalog
|
|
3271
|
-
from crabcode_core.config.model_catalog import ModelCatalogError
|
|
3273
|
+
from crabcode_core.config.model_catalog import CatalogImportResult, ModelCatalogError
|
|
3272
3274
|
|
|
3273
3275
|
try:
|
|
3274
3276
|
result = await manage_model_catalog(
|
|
@@ -3285,6 +3287,15 @@ async def _handle_command(
|
|
|
3285
3287
|
console.print("[dim]Model configuration unchanged.[/]")
|
|
3286
3288
|
return True
|
|
3287
3289
|
|
|
3290
|
+
if isinstance(result, CatalogImportResult):
|
|
3291
|
+
message = Text("✓ ", style="green")
|
|
3292
|
+
message.append(f"Imported {len(result.names)} models", style="bold green")
|
|
3293
|
+
message.append(f" from {result.group}")
|
|
3294
|
+
message.append(f" · {result.path}", style="dim")
|
|
3295
|
+
console.print(message)
|
|
3296
|
+
console.print(Text(" Choose an imported model with /model", style="dim"))
|
|
3297
|
+
return True
|
|
3298
|
+
|
|
3288
3299
|
message = Text()
|
|
3289
3300
|
message.append("✓ ", style="green")
|
|
3290
3301
|
message.append("Added" if result.action == "add" else "Deleted", style="bold green")
|
crabcode_core/_version.py
CHANGED
|
@@ -123,6 +123,7 @@ def _tools_to_api(tools: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
|
123
123
|
class AnthropicAdapter(APIAdapter):
|
|
124
124
|
"""Adapter for Anthropic's Messages API (direct, first-party)."""
|
|
125
125
|
|
|
126
|
+
_sdk = anthropic
|
|
126
127
|
emits_response_item_events = True
|
|
127
128
|
|
|
128
129
|
def __init__(self, config: ApiConfig):
|
|
@@ -143,7 +144,7 @@ class AnthropicAdapter(APIAdapter):
|
|
|
143
144
|
kwargs["default_headers"] = config.http_headers
|
|
144
145
|
|
|
145
146
|
from crabcode_core.api.network import sdk_options
|
|
146
|
-
self.client = anthropic.AsyncAnthropic(**kwargs, **sdk_options(config))
|
|
147
|
+
self.client = anthropic.AsyncAnthropic(**kwargs, **sdk_options(config, self._sdk))
|
|
147
148
|
self._api_key = api_key
|
|
148
149
|
|
|
149
150
|
def _messages_url(self) -> str | None:
|
|
@@ -632,7 +633,7 @@ class BedrockAdapter(AnthropicAdapter):
|
|
|
632
633
|
def __init__(self, config: ApiConfig):
|
|
633
634
|
self.config = config
|
|
634
635
|
from crabcode_core.api.network import sdk_options
|
|
635
|
-
self.client = anthropic.AsyncAnthropicBedrock(**sdk_options(config))
|
|
636
|
+
self.client = anthropic.AsyncAnthropicBedrock(**sdk_options(config, self._sdk))
|
|
636
637
|
|
|
637
638
|
|
|
638
639
|
class VertexAdapter(AnthropicAdapter):
|
|
@@ -644,5 +645,5 @@ class VertexAdapter(AnthropicAdapter):
|
|
|
644
645
|
self.client = anthropic.AsyncAnthropicVertex(
|
|
645
646
|
region=os.environ.get("CLOUD_ML_REGION", "us-east5"),
|
|
646
647
|
project_id=os.environ.get("ANTHROPIC_VERTEX_PROJECT_ID"),
|
|
647
|
-
**sdk_options(config),
|
|
648
|
+
**sdk_options(config, self._sdk),
|
|
648
649
|
)
|
|
@@ -57,7 +57,7 @@ class AzureOpenAIAdapter(OpenAIAdapter):
|
|
|
57
57
|
kwargs["default_headers"] = config.http_headers
|
|
58
58
|
|
|
59
59
|
from crabcode_core.api.network import sdk_options
|
|
60
|
-
return openai.AsyncAzureOpenAI(**kwargs, **sdk_options(config))
|
|
60
|
+
return openai.AsyncAzureOpenAI(**kwargs, **sdk_options(config, self._sdk))
|
|
61
61
|
|
|
62
62
|
def _resolve_model(self, config: ModelConfig) -> str:
|
|
63
63
|
"""Azure uses deployment names instead of model names."""
|
crabcode_core/api/base.py
CHANGED
|
@@ -188,13 +188,13 @@ class APIAdapter(ABC):
|
|
|
188
188
|
async def reset_network_client(self) -> None:
|
|
189
189
|
"""Replace a failed SDK connection pool without changing its routing policy."""
|
|
190
190
|
import asyncio
|
|
191
|
-
from crabcode_core.api.network import
|
|
191
|
+
from crabcode_core.api.network import sdk_http_client
|
|
192
192
|
|
|
193
193
|
client = getattr(self, "client", None)
|
|
194
194
|
copy = getattr(client, "with_options", None)
|
|
195
195
|
if not callable(copy):
|
|
196
196
|
return
|
|
197
|
-
transport =
|
|
197
|
+
transport = sdk_http_client(self.config, getattr(self, "_sdk", None))
|
|
198
198
|
try:
|
|
199
199
|
replacement = copy(http_client=transport, max_retries=0)
|
|
200
200
|
except BaseException:
|
|
@@ -486,6 +486,7 @@ class CodexAdapter(APIAdapter):
|
|
|
486
486
|
def __init__(self, config: ApiConfig):
|
|
487
487
|
import openai
|
|
488
488
|
|
|
489
|
+
self._sdk = openai
|
|
489
490
|
self.config = config
|
|
490
491
|
api_key = None
|
|
491
492
|
oauth_account_id = None
|
|
@@ -524,7 +525,7 @@ class CodexAdapter(APIAdapter):
|
|
|
524
525
|
# differing built-in policy (which also retries 429) and apply the
|
|
525
526
|
# configured policy explicitly in _create_sdk_response_stream().
|
|
526
527
|
from crabcode_core.api.network import sdk_options
|
|
527
|
-
kwargs.update(sdk_options(config))
|
|
528
|
+
kwargs.update(sdk_options(config, self._sdk))
|
|
528
529
|
self.client = openai.AsyncOpenAI(**kwargs)
|
|
529
530
|
|
|
530
531
|
async def resolve_context_window(self) -> int:
|