Files
omarchycn/bin/omarchy-cn-ai-default
T
ZacharyZhang-NYandClaude Fable 5 111b857cda Add local Ollama as an AI Hub provider for claude-code
Ollama v0.14+ speaks the Anthropic Messages API natively, so the
registry drives it with a fixed 'ollama' token and runtime-listed
models: static_token skips secret storage everywhere keys resolve,
models_dynamic defers model validation to the live /api/tags list,
and the setup wizard installs the right GPU variant and starts the
service before listing local models. Doctor stops treating the
endpoint port as part of the hostname.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019hLK3wsDuKVAC37GgDqg6H
2026-08-27 15:55:15 -04:00

83 lines
2.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# omarchy:summary=Map an AI profile onto Omarchy's default agent and hotkey
# omarchy:args=[profile]
# omarchy:examples=omarchycn ai default | omarchycn ai default work
set -euo pipefail
source "$OMARCHY_PATH/cn/lib/ai.sh"
profile="${1:-$(cn_ai_current_profile)}"
if [[ ! -f $CN_AI_PROFILE_DIR/$profile.toml ]]; then
echo "No such profile: $profile" >&2
exit 1
fi
harness=$(cn_ai_profile_field "$profile" harness)
provider=$(cn_ai_profile_field "$profile" provider)
model=$(cn_ai_profile_field "$profile" model)
# Only harnesses whose provider config persists in their own files can back
# the upstream hotkey; opencode is session-env only, natives self-auth
case "$harness" in
claude-code) agent="claude" ;;
codex) agent="codex" ;;
*)
echo "$harness 无法映射为上游默认 Agent;用 omarchycn ai launch $profile 启动" >&2
exit 1
;;
esac
command=$(cn_ai_harness_field "$harness" command)
if omarchy-cmd-missing "$command"; then
install=$(cn_ai_harness_field "$harness" install)
echo "Installing $harness: $install"
$install
fi
key=$(cn_ai_resolve_key "$provider")
case "$harness" in
claude-code)
# Persist provider env in Claude Code's own settings so the upstream
# Super+Shift+Ctrl+A -> omarchy-agent path launches fully configured
settings="$HOME/.claude/settings.json"
mkdir -p "${settings%/*}"
base=$(cn_ai_endpoint "$provider" anthropic)
# Dynamic-model providers have no fast alias: every tier maps to the model
fast=$(cn_ai_fast_model "$provider" 2>/dev/null || printf '%s' "$model")
current="{}"
if [[ -s $settings ]]; then
current=$(cat "$settings")
cp "$settings" "$settings.omarchycn-bak-$(date +%Y%m%d-%H%M%S)"
fi
# Key reaches jq via environment, never the argument list
rm -f "$settings.omarchycn-new"
(
umask 077
CN_AI_KEY="$key" jq --arg base "$base" --arg model "$model" --arg fast "$fast" \
'.env = (.env // {}) + {
ANTHROPIC_BASE_URL: $base,
ANTHROPIC_AUTH_TOKEN: env.CN_AI_KEY,
ANTHROPIC_API_KEY: env.CN_AI_KEY,
ANTHROPIC_MODEL: $model,
ANTHROPIC_DEFAULT_SONNET_MODEL: $model,
ANTHROPIC_DEFAULT_OPUS_MODEL: $model,
ANTHROPIC_DEFAULT_HAIKU_MODEL: $fast
}' <<<"$current" > "$settings.omarchycn-new"
)
mv "$settings.omarchycn-new" "$settings"
;;
codex)
cn_ai_render_codex_config "$provider" "$model" "$key"
;;
esac
agent_file="$HOME/.config/omarchy/defaults/agent"
mkdir -p "${agent_file%/*}"
printf '%s\n' "$agent" > "$agent_file"
echo "默认 Agent: $agent$profile: $provider x $model"
echo "快捷键 Super+Shift+Ctrl+A 或 'omarchy agent' 将以该配置启动"