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
|
fi
|
||||||
echo "INFO ai: current profile $profile"
|
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)
|
harness=$(cn_ai_profile_field "$profile" harness)
|
||||||
provider=$(cn_ai_profile_field "$profile" provider)
|
provider=$(cn_ai_profile_field "$profile" provider)
|
||||||
command=$(cn_ai_harness_field "$harness" command)
|
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
|
if command -v "$command" > /dev/null 2>&1; then
|
||||||
echo "PASS ai: harness $harness installed ($command)"
|
echo "PASS ai: harness $harness installed ($command)"
|
||||||
else
|
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
|
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"
|
echo "PASS ai: $provider API Key stored"
|
||||||
else
|
else
|
||||||
echo "FAIL ai: $provider API Key 未存储 (omarchycn ai secret set $provider)"
|
echo "FAIL ai: $provider API Key 未存储 (omarchycn ai secret set $provider)"
|
||||||
|
|||||||
+10
-2
@@ -30,6 +30,15 @@ fi
|
|||||||
default_name="$harness-$provider"
|
default_name="$harness-$provider"
|
||||||
name=$(gum input --header "Profile 名称" --value "$default_name")
|
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
|
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"))")
|
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"
|
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-create "$name" "$harness" "$provider" "$model"
|
||||||
omarchy-cn-ai-profile-use "$name"
|
omarchy-cn-ai-profile-use "$name"
|
||||||
|
|
||||||
proto=$(cn_ai_harness_field "$harness" protocol)
|
if gum confirm "运行连接测试?"; then
|
||||||
if [[ $proto != "native" ]] && gum confirm "运行连接测试?"; then
|
|
||||||
omarchy-cn-ai-test "$name"
|
omarchy-cn-ai-test "$name"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+11
-6
@@ -18,6 +18,8 @@ harness=$(cn_ai_profile_field "$profile" harness)
|
|||||||
provider=$(cn_ai_profile_field "$profile" provider)
|
provider=$(cn_ai_profile_field "$profile" provider)
|
||||||
model=$(cn_ai_profile_field "$profile" model)
|
model=$(cn_ai_profile_field "$profile" model)
|
||||||
proto=$(cn_ai_harness_field "$harness" protocol)
|
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
|
failures=0
|
||||||
|
|
||||||
if [[ $proto == "native" ]]; then
|
if [[ $proto == "native" ]]; then
|
||||||
@@ -26,7 +28,7 @@ if [[ $proto == "native" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Endpoint override for mock-server tests
|
# 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"
|
echo "INFO ai-test: $profile ($harness x $provider x $model) -> $base"
|
||||||
|
|
||||||
if ! key=$(omarchy-cn-ai-secret get "$provider" 2>/dev/null); then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
body=$(mktemp)
|
||||||
|
trap 'rm -f "$body"' EXIT
|
||||||
|
|
||||||
case "$proto" in
|
case "$proto" in
|
||||||
anthropic)
|
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" \
|
-X POST "${base%/}/v1/messages" \
|
||||||
-H "x-api-key: $key" -H "authorization: Bearer $key" \
|
-H "x-api-key: $key" -H "authorization: Bearer $key" \
|
||||||
-H "anthropic-version: 2023-06-01" -H "content-type: application/json" \
|
-H "anthropic-version: 2023-06-01" -H "content-type: application/json" \
|
||||||
-d "{\"model\":\"$model\",\"max_tokens\":8,\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}]}" || true)
|
-d "{\"model\":\"$model\",\"max_tokens\":8,\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}]}" || true)
|
||||||
;;
|
;;
|
||||||
openai)
|
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" \
|
-X POST "${base%/}/chat/completions" \
|
||||||
-H "Authorization: Bearer $key" -H "content-type: application/json" \
|
-H "Authorization: Bearer $key" -H "content-type: application/json" \
|
||||||
-d "{\"model\":\"$model\",\"max_tokens\":8,\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}]}" || true)
|
-d "{\"model\":\"$model\",\"max_tokens\":8,\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}]}" || true)
|
||||||
@@ -65,7 +70,7 @@ case "$code" in
|
|||||||
;;
|
;;
|
||||||
404 | 400 | 422)
|
404 | 400 | 422)
|
||||||
echo "FAIL ai-test: 端点可达但请求被拒 (HTTP $code),可能是模型名问题"
|
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))
|
failures=$((failures + 1))
|
||||||
;;
|
;;
|
||||||
000)
|
000)
|
||||||
@@ -74,10 +79,10 @@ case "$code" in
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "FAIL ai-test: HTTP $code"
|
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))
|
failures=$((failures + 1))
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
rm -f /tmp/omarchycn-ai-test-body
|
rm -f $body
|
||||||
exit $((failures > 0 ? 1 : 0))
|
exit $((failures > 0 ? 1 : 0))
|
||||||
|
|||||||
Reference in New Issue
Block a user