AI wizard/test/doctor: native-auth handling, Responses API test, safe temp, stale profile
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp
This commit is contained in:
@@ -15,6 +15,11 @@ if [[ -z $profile ]]; then
|
||||
fi
|
||||
echo "INFO ai: current profile $profile"
|
||||
|
||||
if [[ ! -f $CN_AI_PROFILE_DIR/$profile.toml ]]; then
|
||||
echo "FAIL ai: 默认 Profile $profile 的文件不存在 (omarchycn ai profile list)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
harness=$(cn_ai_profile_field "$profile" harness)
|
||||
provider=$(cn_ai_profile_field "$profile" provider)
|
||||
command=$(cn_ai_harness_field "$harness" command)
|
||||
@@ -23,10 +28,17 @@ proto=$(cn_ai_harness_field "$harness" protocol)
|
||||
if command -v "$command" > /dev/null 2>&1; then
|
||||
echo "PASS ai: harness $harness installed ($command)"
|
||||
else
|
||||
echo "WARN ai: harness $harness 未安装,首次 launch 时自动安装"
|
||||
install=$(cn_ai_harness_field "$harness" install)
|
||||
if [[ $install == doc:* ]]; then
|
||||
echo "WARN ai: harness $harness 未安装,需手动安装: ${install#doc:}"
|
||||
else
|
||||
echo "WARN ai: harness $harness 未安装,首次 launch 时自动安装"
|
||||
fi
|
||||
fi
|
||||
|
||||
if omarchy-cn-ai-secret get "$provider" > /dev/null 2>&1; then
|
||||
if [[ $proto == "native" ]]; then
|
||||
echo "INFO ai: $harness 自管鉴权,跳过 OmarchyCN Key 检查"
|
||||
elif omarchy-cn-ai-secret get "$provider" > /dev/null 2>&1; then
|
||||
echo "PASS ai: $provider API Key stored"
|
||||
else
|
||||
echo "FAIL ai: $provider API Key 未存储 (omarchycn ai secret set $provider)"
|
||||
|
||||
+10
-2
@@ -30,6 +30,15 @@ fi
|
||||
default_name="$harness-$provider"
|
||||
name=$(gum input --header "Profile 名称" --value "$default_name")
|
||||
|
||||
proto=$(cn_ai_harness_field "$harness" protocol)
|
||||
if [[ $proto == "native" ]]; then
|
||||
omarchy-cn-ai-profile-create "$name" "$harness" "$provider" "$model"
|
||||
omarchy-cn-ai-profile-use "$name"
|
||||
echo "$harness 自管鉴权:首次启动时按其官方流程登录/配置"
|
||||
echo "完成。启动: omarchycn ai launch"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ! omarchy-cn-ai-secret get "$provider" > /dev/null 2>&1; then
|
||||
key=$(gum input --password --header "$provider API Key(获取: $(jq -r --arg p "$provider" '.providers[$p].key_url' "$CN_AI_PROVIDERS"))")
|
||||
printf '%s' "$key" | omarchy-cn-ai-secret set "$provider"
|
||||
@@ -38,8 +47,7 @@ fi
|
||||
omarchy-cn-ai-profile-create "$name" "$harness" "$provider" "$model"
|
||||
omarchy-cn-ai-profile-use "$name"
|
||||
|
||||
proto=$(cn_ai_harness_field "$harness" protocol)
|
||||
if [[ $proto != "native" ]] && gum confirm "运行连接测试?"; then
|
||||
if gum confirm "运行连接测试?"; then
|
||||
omarchy-cn-ai-test "$name"
|
||||
fi
|
||||
|
||||
|
||||
+11
-6
@@ -18,6 +18,8 @@ harness=$(cn_ai_profile_field "$profile" harness)
|
||||
provider=$(cn_ai_profile_field "$profile" provider)
|
||||
model=$(cn_ai_profile_field "$profile" model)
|
||||
proto=$(cn_ai_harness_field "$harness" protocol)
|
||||
# Codex speaks the Responses API (wire_api=responses), not chat/completions
|
||||
[[ $harness == "codex" ]] && proto="openai-responses"
|
||||
failures=0
|
||||
|
||||
if [[ $proto == "native" ]]; then
|
||||
@@ -26,7 +28,7 @@ if [[ $proto == "native" ]]; then
|
||||
fi
|
||||
|
||||
# Endpoint override for mock-server tests
|
||||
base="${OMARCHYCN_AI_TEST_BASE_URL:-$(cn_ai_endpoint "$provider" "$proto")}"
|
||||
base="${OMARCHYCN_AI_TEST_BASE_URL:-$(cn_ai_endpoint "$provider" "${proto%-responses}")}"
|
||||
echo "INFO ai-test: $profile ($harness x $provider x $model) -> $base"
|
||||
|
||||
if ! key=$(omarchy-cn-ai-secret get "$provider" 2>/dev/null); then
|
||||
@@ -34,16 +36,19 @@ if ! key=$(omarchy-cn-ai-secret get "$provider" 2>/dev/null); then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
body=$(mktemp)
|
||||
trap 'rm -f "$body"' EXIT
|
||||
|
||||
case "$proto" in
|
||||
anthropic)
|
||||
code=$(curl -sS -o /tmp/omarchycn-ai-test-body -w '%{http_code}' -m 30 --connect-timeout 8 \
|
||||
code=$(curl -sS -o "$body" -w '%{http_code}' -m 30 --connect-timeout 8 \
|
||||
-X POST "${base%/}/v1/messages" \
|
||||
-H "x-api-key: $key" -H "authorization: Bearer $key" \
|
||||
-H "anthropic-version: 2023-06-01" -H "content-type: application/json" \
|
||||
-d "{\"model\":\"$model\",\"max_tokens\":8,\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}]}" || true)
|
||||
;;
|
||||
openai)
|
||||
code=$(curl -sS -o /tmp/omarchycn-ai-test-body -w '%{http_code}' -m 30 --connect-timeout 8 \
|
||||
code=$(curl -sS -o "$body" -w '%{http_code}' -m 30 --connect-timeout 8 \
|
||||
-X POST "${base%/}/chat/completions" \
|
||||
-H "Authorization: Bearer $key" -H "content-type: application/json" \
|
||||
-d "{\"model\":\"$model\",\"max_tokens\":8,\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}]}" || true)
|
||||
@@ -65,7 +70,7 @@ case "$code" in
|
||||
;;
|
||||
404 | 400 | 422)
|
||||
echo "FAIL ai-test: 端点可达但请求被拒 (HTTP $code),可能是模型名问题"
|
||||
head -c 200 /tmp/omarchycn-ai-test-body 2>/dev/null && echo
|
||||
head -c 200 "$body" 2>/dev/null && echo
|
||||
failures=$((failures + 1))
|
||||
;;
|
||||
000)
|
||||
@@ -74,10 +79,10 @@ case "$code" in
|
||||
;;
|
||||
*)
|
||||
echo "FAIL ai-test: HTTP $code"
|
||||
head -c 200 /tmp/omarchycn-ai-test-body 2>/dev/null && echo
|
||||
head -c 200 "$body" 2>/dev/null && echo
|
||||
failures=$((failures + 1))
|
||||
;;
|
||||
esac
|
||||
|
||||
rm -f /tmp/omarchycn-ai-test-body
|
||||
rm -f $body
|
||||
exit $((failures > 0 ? 1 : 0))
|
||||
|
||||
Reference in New Issue
Block a user