Skip to content

Commit ce8da86

Browse files
authored
Merge pull request #27 from zhujian0805/main
fix droid
2 parents 9caf1ee + b561b0b commit ce8da86

File tree

5 files changed

+97
-170
lines changed

5 files changed

+97
-170
lines changed

code_assistant_manager/cli/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def list_config():
347347
"description": "Factory.ai Droid CLI",
348348
"paths": [
349349
home / ".factory" / "mcp.json",
350-
home / ".factory" / "config.json",
350+
home / ".factory" / "settings.json",
351351
],
352352
},
353353
"iflow": {
@@ -681,7 +681,7 @@ def load_app_config(app_name: str) -> tuple[dict, str]:
681681
],
682682
"droid": [
683683
Path.home() / ".factory" / "mcp.json",
684-
Path.home() / ".factory" / "config.json",
684+
Path.home() / ".factory" / "settings.json",
685685
],
686686
"iflow": [
687687
Path.home() / ".iflow" / "settings.json",

code_assistant_manager/tools.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ tools:
198198
injected: []
199199
filesystem:
200200
generated:
201-
- "~/.factory/config.json containing custom_models entries with base_url, api_key, provider, and max_tokens"
201+
- "~/.factory/settings.json containing custom_models entries with base_url, api_key, provider, and max_tokens"
202202

203203
iflow:
204204
enabled: true

code_assistant_manager/tools/droid.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,28 @@ def _process_endpoint(self, endpoint_name: str) -> Optional[List[str]]:
8080

8181
return entries
8282

83-
def _write_droid_config(self, selected_entries: List[str]) -> Path:
84-
"""Persist Droid config to ~/.factory/config.json."""
83+
def _write_droid_settings(self, selected_entries: List[str]) -> Path:
84+
"""Persist Droid custom models to ~/.factory/config.json."""
8585
config_dir = Path.home() / ".factory"
8686
config_file = config_dir / "config.json"
87-
config_dir.mkdir(exist_ok=True)
87+
config_dir.mkdir(parents=True, exist_ok=True)
88+
89+
# Preserve existing settings (plugins, etc) and only update custom_models.
90+
settings: dict = {}
91+
if config_file.exists():
92+
try:
93+
with open(config_file, "r", encoding="utf-8") as f:
94+
settings = json.load(f) or {}
95+
except Exception:
96+
settings = {}
8897

8998
json_models = self._build_models_json(selected_entries)
90-
with open(config_file, "w") as f:
91-
json.dump({"custom_models": json_models}, f, indent=2)
99+
100+
# Canonical location for Droid BYOK custom models.
101+
settings["custom_models"] = json_models
102+
103+
with open(config_file, "w", encoding="utf-8") as f:
104+
json.dump(settings, f, indent=2)
92105

93106
return config_file
94107

@@ -118,7 +131,7 @@ def run(self, args: List[str] = None) -> int:
118131
- Loads environment variables
119132
- Ensures required commands are available
120133
- Aggregates selected models from configured endpoints
121-
- Writes a config.json in ~/.factory and runs the `droid` CLI
134+
- Writes custom_models to ~/.factory/config.json and runs the `droid` CLI
122135
123136
Args:
124137
args: List of arguments to pass to the Droid CLI
@@ -165,9 +178,9 @@ def run(self, args: List[str] = None) -> int:
165178

166179
print(f"Total models selected: {len(selected_entries)}\n")
167180

168-
# Persist Droid config to ~/.factory/config.json
169-
config_file = self._write_droid_config(selected_entries)
170-
print(f"Droid config written to {config_file}\n")
181+
# Persist Droid custom models to ~/.factory/config.json
182+
settings_file = self._write_droid_settings(selected_entries)
183+
print(f"Droid settings written to {settings_file}\n")
171184

172185
# Clean proxy env vars for child process and set TLS env
173186
env = self._prepare_environment()
@@ -185,7 +198,7 @@ def _build_models_json(self, entries: List[str]) -> List[dict]:
185198
parts = entry.split("|")
186199
if len(parts) < 5:
187200
continue
188-
display, base_url, api_key, provider, max_tokens = parts[:5]
201+
display, base_url, api_key, _provider, max_tokens = parts[:5]
189202
model_id = display.split("[")[0].strip()
190203
try:
191204
max_tokens_val = int(max_tokens)
@@ -197,7 +210,7 @@ def _build_models_json(self, entries: List[str]) -> List[dict]:
197210
"model": model_id,
198211
"base_url": base_url,
199212
"api_key": api_key,
200-
"provider": provider,
213+
"provider": "generic-chat-completion-api",
201214
"max_tokens": max_tokens_val,
202215
}
203216
)

0 commit comments

Comments
 (0)