Prime OpenCode catalog before container login and model validation
This commit is contained in:
+37
-7
@@ -102,21 +102,47 @@ class Setup:
|
||||
print("Keeping existing OpenCode provider setup in its Docker volume.")
|
||||
return
|
||||
print("Choose and authenticate your provider in the container's OpenCode login below.")
|
||||
self.compose("run", "--rm", "--no-deps", "--entrypoint", "opencode", "pipelines", "auth", "login")
|
||||
# Keep the catalog warm in the same service used by OpenCode's own
|
||||
# interactive connect UI, not just the later validation process.
|
||||
login = '''set -eu
|
||||
opencode api get /api/integration >/dev/null
|
||||
exec opencode auth login
|
||||
'''
|
||||
self.compose("run", "--rm", "--no-deps", "--entrypoint", "sh", "pipelines", "-c", login)
|
||||
if not connected():
|
||||
raise ValueError("Provider setup incomplete; rerun the installer to continue (credentials/volumes retained)")
|
||||
|
||||
def discover_models(self):
|
||||
# A one-off container starts a fresh OpenCode service. Its first model
|
||||
# read can race catalog initialization and return an empty successful
|
||||
# response. Prime discovery and retry in THAT SAME container/service;
|
||||
# starting another one-off container just repeats the cold-start race.
|
||||
discovery = '''set -eu
|
||||
opencode api get /api/integration >/dev/null
|
||||
for attempt in 1 2 3; do
|
||||
models=$(opencode models)
|
||||
if [ -n "$models" ]; then
|
||||
printf '%s\\n' "$models"
|
||||
exit 0
|
||||
fi
|
||||
if [ "$attempt" -lt 3 ]; then sleep 1; fi
|
||||
done
|
||||
'''
|
||||
result = self.compose("run", "--rm", "--no-deps", "-T", "--entrypoint", "sh", "pipelines", "-c", discovery, capture=True)
|
||||
return [line.strip() for line in result.stdout.splitlines()
|
||||
if re.fullmatch(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_./:-]+", line.strip())]
|
||||
|
||||
def validate_provider(self, args):
|
||||
result = self.compose("run", "--rm", "--no-deps", "-T", "--entrypoint", "opencode", "pipelines", "models", capture=True)
|
||||
models = [line.strip() for line in result.stdout.splitlines()
|
||||
if re.fullmatch(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_./:-]+", line.strip())]
|
||||
models = self.discover_models()
|
||||
ids = {account.get("id") for account in self.accounts if isinstance(account,dict) and account.get("connections")}
|
||||
available = [model for model in models if model.split("/",1)[0] in ids]
|
||||
saved = dict(line.split("=",1) for line in (self.directory/".env").read_text().splitlines() if "=" in line)
|
||||
model = args.model or saved.get("PIPELINES_DEFAULT_MODEL", "")
|
||||
if not model:
|
||||
if not available:
|
||||
raise ValueError("No models found for the connected provider. Reconnect with ./install.sh --relogin; no model was validated.")
|
||||
connected = ", ".join(sorted(str(id) for id in ids)) or "none"
|
||||
visible = ", ".join(sorted({model.split('/', 1)[0] for model in models})) or "none"
|
||||
raise ValueError(f"OpenCode catalog discovery found no models for connected providers [{connected}] (visible model providers: [{visible}]). Your saved key was not replaced; this is NOT proof it is invalid. Rerun ./install.sh; if it persists, share this message and the OpenCode version, not your key. No model was validated.")
|
||||
print("Choose the model to validate (one small tool-free test; provider charges may apply):")
|
||||
for i, item in enumerate(available[:25],1):
|
||||
print(f" {i}. {item}")
|
||||
@@ -125,8 +151,12 @@ class Setup:
|
||||
if model not in models:
|
||||
raise ValueError("Selected model is not available in this OpenCode configuration. Choose a listed model with --model PROVIDER/MODEL.")
|
||||
print(f"Validating {model} with one tool-free generation; the session is retained for debugging.")
|
||||
result = self.compose("run", "--rm", "--no-deps", "-T", "--entrypoint", "pipelines", "pipelines",
|
||||
"provider-check", "--model", model, "--yes", "--json", "--timeout", "90s", capture=True, check=False)
|
||||
validation = '''set -eu
|
||||
opencode api get /api/integration >/dev/null
|
||||
exec pipelines provider-check --model "$1" --yes --json --timeout 90s
|
||||
'''
|
||||
result = self.compose("run", "--rm", "--no-deps", "-T", "--entrypoint", "sh", "pipelines",
|
||||
"-c", validation, "pipelines-provider-check", model, capture=True, check=False)
|
||||
try:
|
||||
report = json.loads(result.stdout)
|
||||
except ValueError:
|
||||
|
||||
Reference in New Issue
Block a user