-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscripts-zeroapi-doctor.sh
More file actions
executable file
·164 lines (145 loc) · 7.1 KB
/
scripts-zeroapi-doctor.sh
File metadata and controls
executable file
·164 lines (145 loc) · 7.1 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
#!/usr/bin/env bash
set -euo pipefail
OPENCLAW_DIR="${OPENCLAW_DIR:-${HOME}/.openclaw}"
ZEROAPI_CFG="$OPENCLAW_DIR/zeroapi-config.json"
OPENCLAW_CFG="$OPENCLAW_DIR/openclaw.json"
ZEROAPI_ADVISORY="$OPENCLAW_DIR/zeroapi-advisories.json"
ZEROAPI_MANAGED_STATE="$OPENCLAW_DIR/zeroapi-managed-install.json"
say() { printf '%s\n' "$*"; }
warn() { printf 'WARN: %s\n' "$*"; }
fail() { printf 'FAIL: %s\n' "$*"; exit 1; }
[ -f "$ZEROAPI_CFG" ] || fail "missing $ZEROAPI_CFG"
[ -f "$OPENCLAW_CFG" ] || fail "missing $OPENCLAW_CFG"
python3 - <<'PY'
import json, os, pathlib, sys
home = pathlib.Path(os.environ.get('OPENCLAW_DIR', str(pathlib.Path.home() / '.openclaw')))
zcfg = json.loads((home / 'zeroapi-config.json').read_text())
ocfg = json.loads((home / 'openclaw.json').read_text())
zero_default = zcfg.get('default_model')
routing_mode = zcfg.get('routing_mode') or 'balanced'
routing_modifier = zcfg.get('routing_modifier') or 'none'
runtime_default = ocfg.get('agents', {}).get('defaults', {}).get('model', {}).get('primary')
print(f'zeroapi.default_model={zero_default}')
print(f'zeroapi.routing_mode={routing_mode}')
print(f'zeroapi.routing_modifier={routing_modifier}')
print(f'openclaw.default_model={runtime_default}')
if zero_default != runtime_default:
print('WARN: default model mismatch between zeroapi-config.json and openclaw.json')
models = set(zcfg.get('models', {}).keys())
for category, rule in zcfg.get('routing_rules', {}).items():
primary = rule.get('primary')
if primary not in models:
print(f'WARN: routing_rules.{category}.primary missing from models: {primary}')
for fb in rule.get('fallbacks', []):
if fb not in models:
print(f'WARN: routing_rules.{category}.fallback missing from models: {fb}')
workspace_hints = zcfg.get('workspace_hints', {})
for agent, hint in workspace_hints.items():
if hint is not None and not isinstance(hint, list):
print(f'WARN: workspace_hints.{agent} should be list|null, got {type(hint).__name__}')
def read_model_ref(model):
if isinstance(model, str) and model.strip():
return model.strip()
if isinstance(model, dict):
primary = model.get('primary')
if isinstance(primary, str) and primary.strip():
return primary.strip()
return None
agents = ocfg.get('agents', {}).get('list', [])
if isinstance(agents, list):
for entry in agents:
if not isinstance(entry, dict):
continue
agent_id = entry.get('id')
model_ref = read_model_ref(entry.get('model'))
if not isinstance(agent_id, str) or not agent_id or not model_ref:
continue
if agent_id not in workspace_hints:
print(f'INFO: agent {agent_id} has explicit model {model_ref}; ZeroAPI will skip it implicitly unless workspace_hints.{agent_id} opts it in')
elif workspace_hints.get(agent_id) is None:
print(f'OK: agent {agent_id} explicit model protected by workspace_hints.{agent_id}=null')
profile = zcfg.get('subscription_profile')
inventory = zcfg.get('subscription_inventory')
enabled_profile = []
if isinstance(profile, dict):
global_profile = profile.get('global')
if isinstance(global_profile, dict) and global_profile:
for provider, selection in global_profile.items():
if isinstance(selection, dict) and selection.get('enabled') is True:
enabled_profile.append(provider)
print(f'subscription_profile.enabled={",".join(enabled_profile) if enabled_profile else "none"}')
else:
print('subscription_profile.enabled=none')
inventory_accounts = []
inventory_accounts_with_auth = []
if isinstance(inventory, dict):
accounts = inventory.get('accounts')
if isinstance(accounts, dict):
for account_id, account in accounts.items():
if not isinstance(account, dict):
continue
if account.get('enabled') is False:
continue
provider = account.get('provider')
if isinstance(provider, str) and provider:
inventory_accounts.append(f'{account_id}:{provider}')
auth_profile = account.get('authProfile')
if isinstance(auth_profile, str) and auth_profile.strip():
inventory_accounts_with_auth.append(f'{account_id}:{auth_profile.strip()}')
print(f'subscription_inventory.accounts={",".join(inventory_accounts) if inventory_accounts else "none"}')
if inventory_accounts_with_auth:
print(f'subscription_inventory.auth_profiles={",".join(inventory_accounts_with_auth)}')
print('NOTE: authProfile inventory steering works best on newer OpenClaw runtimes, but ZeroAPI also has a best-effort session-store fallback for older builds.')
if not enabled_profile and not inventory_accounts:
print('WARN: neither subscription_profile nor enabled subscription_inventory accounts are configured. Routing may silently filter out every provider.')
PY
if [ -f "$ZEROAPI_MANAGED_STATE" ]; then
say "--- zeroapi managed install ---"
python3 - <<'PY'
import json, os, pathlib
home = pathlib.Path(os.environ.get('OPENCLAW_DIR', str(pathlib.Path.home() / '.openclaw')))
state = json.loads((home / 'zeroapi-managed-install.json').read_text())
repo = state.get('repo', {})
updates = state.get('updates', {})
print(f"managed.installed_version={repo.get('installedVersion', 'unknown')}")
print(f"managed.repo_dir={repo.get('repoDir', 'unknown')}")
print(f"managed.skill_dir={repo.get('skillDir', 'unknown')}")
print(f"managed.last_status={updates.get('lastStatus', 'unknown')}")
print(f"managed.last_known_version={updates.get('lastKnownVersion', 'unknown')}")
print(f"managed.pending_version={updates.get('pendingVersion') or 'none'}")
print(f"managed.timer_enabled={updates.get('timerEnabled', False)}")
if updates.get('lastError'):
print(f"WARN: managed.last_error={updates['lastError']}")
PY
fi
if [ -f "$ZEROAPI_ADVISORY" ]; then
say "--- zeroapi advisory ---"
python3 - <<'PY'
import json, os, pathlib
home = pathlib.Path(os.environ.get('OPENCLAW_DIR', str(pathlib.Path.home() / '.openclaw')))
advisory = json.loads((home / 'zeroapi-advisories.json').read_text())
print(f"updated_at={advisory.get('updatedAt', 'unknown')}")
for line in advisory.get('summary', []):
print(f"WARN: {line}")
action = advisory.get('recommendedAction')
if action:
print(f"NEXT: {action}")
PY
fi
if [ -d "$OPENCLAW_DIR/extensions/zeroapi-router" ]; then
warn "manual extension directory detected at $OPENCLAW_DIR/extensions/zeroapi-router - this can shadow or duplicate plugin registry installs"
fi
if command -v openclaw >/dev/null 2>&1; then
say "--- openclaw plugins list ---"
if timeout 10s openclaw plugins list | grep zeroapi-router; then
:
else
warn "zeroapi-router not visible in plugin list or plugins list timed out - check openclaw.json installs + gateway logs"
fi
say "--- openclaw models status (summary) ---"
openclaw models status | sed -n '1,80p'
else
warn "openclaw CLI not available in PATH"
fi
say "--- runtime logs (last 20 ZeroAPI lines) ---"
grep -Rni "ZeroAPI Router\|default_mismatch\|skip:\|config_missing" /tmp/openclaw "$OPENCLAW_DIR/logs" 2>/dev/null | tail -n 20 || warn "no ZeroAPI log lines found"