@weave-os/router 0.2.24 → 0.2.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -8
- package/cc-statusline.sh +2 -2
- package/install.sh +195 -122
- package/package.json +1 -2
- package/pi-router/src/pricing.generated.ts +3 -3
- package/uninstall.sh +204 -28
- package/opencode-weave/README.md +0 -159
- package/opencode-weave/package.json +0 -20
- package/opencode-weave/src/classifier-thread.ts +0 -145
- package/opencode-weave/src/directives.ts +0 -72
- package/opencode-weave/src/index.ts +0 -799
package/README.md
CHANGED
|
@@ -104,9 +104,11 @@ Four install targets:
|
|
|
104
104
|
block plus `model_provider = "weave"`. Fresh installs select `weave-auto`,
|
|
105
105
|
while reinstalling preserves an existing model choice. The provider preserves
|
|
106
106
|
the active ChatGPT OAuth login. No install pins `X-Weave-Router-Strategy`;
|
|
107
|
-
every endpoint keeps its router's configured default.
|
|
108
|
-
`/model` picker
|
|
109
|
-
|
|
107
|
+
every endpoint keeps its router's configured default. Switching models with
|
|
108
|
+
Codex's native `/model` picker mid-session forces the named model and its
|
|
109
|
+
selected reasoning effort; the model a session launches with stays a
|
|
110
|
+
baseline that routes automatically, and selecting **Weave Router** resumes
|
|
111
|
+
per-request routing. An existing `$fm`
|
|
110
112
|
session pin still applies in automatic mode until `$ufm` clears it. Re-run
|
|
111
113
|
`npx @weave-os/router --codex` and restart Codex to enable this on an older
|
|
112
114
|
install. `gpt-5.6-sol`, `gpt-5.6-terra`, `gpt-5.6-luna`, and `gpt-6-sol`
|
|
@@ -127,11 +129,13 @@ Four install targets:
|
|
|
127
129
|
- **opencode** (`--opencode`) — merges a Responses-format `provider.weave`
|
|
128
130
|
entry backed by `@ai-sdk/openai` into
|
|
129
131
|
`~/.config/opencode/opencode.json` (or `<repo>/opencode.json` with
|
|
130
|
-
`--scope project`).
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
`--scope project`). OpenCode major version 2 is required when the CLI is
|
|
133
|
+
installed and available on `PATH`. Installation activates `weave/auto` and
|
|
134
|
+
parks any prior default model so `off` and uninstall can restore it exactly.
|
|
135
|
+
The installer uses OpenCode's native Responses provider and session headers;
|
|
136
|
+
no plugin is installed. Re-install rewrites only the managed provider and
|
|
137
|
+
removes any stale v1 plugin registration/files while preserving unrelated
|
|
138
|
+
providers, MCP servers, agents, and plugins.
|
|
135
139
|
- **pi** (`--pi`) — registers the `weave` provider and installs this package as
|
|
136
140
|
a pi extension. Stock pi then gets the Loom startup header, Wooly's animated
|
|
137
141
|
mascot, the persistent actual-route display, cumulative session savings,
|
package/cc-statusline.sh
CHANGED
|
@@ -659,8 +659,8 @@ prices='{
|
|
|
659
659
|
"claude-sonnet-4-6": 0.1,
|
|
660
660
|
"claude-sonnet-5": 0.1,
|
|
661
661
|
"deepseek/deepseek-v4-flash": 0.2,
|
|
662
|
-
"deepseek/deepseek-v4-pro": 0.
|
|
663
|
-
"deepseek/deepseek-v4-pro-0813": 0.
|
|
662
|
+
"deepseek/deepseek-v4-pro": 0.0862,
|
|
663
|
+
"deepseek/deepseek-v4-pro-0813": 0.0862,
|
|
664
664
|
"deepseek/deepseek-v4.1-flash": 0.031818181818181815,
|
|
665
665
|
"gemini-2.0-flash": 0.25,
|
|
666
666
|
"gemini-2.0-flash-lite": 0.25,
|
package/install.sh
CHANGED
|
@@ -131,8 +131,7 @@ router_key_header="X-Weave-Router-Key"
|
|
|
131
131
|
# provider block into opencode.json. Each target carries its own
|
|
132
132
|
# credential-passthrough story in the router: Claude Code's logged-in
|
|
133
133
|
# Anthropic key flows through unchanged, Codex's ChatGPT credential flows
|
|
134
|
-
# through its native provider, and opencode uses the Responses API
|
|
135
|
-
# dedicated subscription headers. target_explicit tracks whether
|
|
134
|
+
# through its native provider, and opencode uses the Responses API. target_explicit tracks whether
|
|
136
135
|
# --claude / --codex / --opencode was passed so an interactive run can
|
|
137
136
|
# prompt for the choice.
|
|
138
137
|
target="claude"
|
|
@@ -362,6 +361,28 @@ require_cmd() {
|
|
|
362
361
|
fi
|
|
363
362
|
}
|
|
364
363
|
|
|
364
|
+
# check_opencode_major_version rejects OpenCode versions whose config schema or
|
|
365
|
+
# provider contract is incompatible with this installer. A missing executable
|
|
366
|
+
# is handled by the target-specific warning below so the installer can still
|
|
367
|
+
# prepare a config before OpenCode is installed.
|
|
368
|
+
check_opencode_major_version() {
|
|
369
|
+
local version version_line major
|
|
370
|
+
if ! version="$(opencode --version 2>/dev/null)"; then
|
|
371
|
+
err "Unable to determine the installed opencode version; 'opencode --version' failed. OpenCode major version 2 is required."
|
|
372
|
+
return 1
|
|
373
|
+
fi
|
|
374
|
+
version_line="$(printf '%s\n' "$version" | sed -n '1p' | tr -d '\r')"
|
|
375
|
+
major="$(printf '%s\n' "$version_line" | sed -nE 's/^[^0-9]*([0-9]+)(\..*)?$/\1/p')"
|
|
376
|
+
if [ -z "$major" ]; then
|
|
377
|
+
err "Unable to determine the installed opencode major version from '${version_line:-unknown}'. OpenCode major version 2 is required."
|
|
378
|
+
return 1
|
|
379
|
+
fi
|
|
380
|
+
if [ "$major" != "2" ]; then
|
|
381
|
+
err "OpenCode major version 2 is required; detected ${version_line:-unknown}."
|
|
382
|
+
return 1
|
|
383
|
+
fi
|
|
384
|
+
}
|
|
385
|
+
|
|
365
386
|
# Refuse to write through a symlink. Project scope reads the install path from
|
|
366
387
|
# the user's git repo; a malicious checkout could ship `.claude/settings.json`
|
|
367
388
|
# (or `.claude/` itself) as a symlink to e.g. `~/.ssh/authorized_keys`, and
|
|
@@ -999,26 +1020,14 @@ EOF
|
|
|
999
1020
|
chmod 600 "$config_file"
|
|
1000
1021
|
}
|
|
1001
1022
|
|
|
1002
|
-
# write_opencode_config merges the managed Weave provider
|
|
1003
|
-
# opencode.json
|
|
1023
|
+
# write_opencode_config merges the managed Weave provider into opencode's
|
|
1024
|
+
# opencode.json. Subscription enrollment is handled by the router's login
|
|
1025
|
+
# command, so opencode only needs this provider and its router key:
|
|
1004
1026
|
# - provider.weave : OpenAI/Responses-shaped (@ai-sdk/openai → /v1/responses).
|
|
1005
1027
|
# The single request provider. The router routes every
|
|
1006
|
-
# turn across
|
|
1007
|
-
#
|
|
1008
|
-
#
|
|
1009
|
-
# - provider.weave-claude : login-only storage for a Claude (Pro/Max) subscription
|
|
1010
|
-
# (no models, never serves requests). Written only when
|
|
1011
|
-
# the bundled plugin is present, since the Claude login
|
|
1012
|
-
# method lives in the plugin. The `weave` loader reads
|
|
1013
|
-
# this slot and attaches the Claude sub.
|
|
1014
|
-
# The plugin (src bundled at $script_dir/opencode-weave/src/index.ts) is dropped
|
|
1015
|
-
# into $opencode_dir/.weave/ and registered via opencode.json's `plugin` array
|
|
1016
|
-
# by absolute path — scope-independent (no reliance on an auto-load dir). It owns
|
|
1017
|
-
# both the ChatGPT (on `weave`) and Claude (on `weave-claude`) logins and attaches
|
|
1018
|
-
# whichever subscriptions are connected to every request via the router's
|
|
1019
|
-
# dedicated X-Weave-*-Subscription headers. Re-running rewrites the blocks
|
|
1020
|
-
# in-place via jq (and strips the legacy `weave-codex` provider); uninstall
|
|
1021
|
-
# strips them.
|
|
1028
|
+
# turn across the models the router can serve. The default.
|
|
1029
|
+
# Re-running rewrites the block in-place via jq, strips legacy provider blocks
|
|
1030
|
+
# and removes the obsolete v1 plugin registration and files.
|
|
1022
1031
|
#
|
|
1023
1032
|
# Usage: write_opencode_config <config_file_path> <base_url> <api_key> [user_email] [user_name]
|
|
1024
1033
|
write_opencode_config() {
|
|
@@ -1029,10 +1038,8 @@ write_opencode_config() {
|
|
|
1029
1038
|
local block_name="${5:-}"
|
|
1030
1039
|
|
|
1031
1040
|
# Build the headers object piecewise so empty email/name vanish from the
|
|
1032
|
-
# final JSON.
|
|
1033
|
-
#
|
|
1034
|
-
# would from Claude Code or Codex. The X-App tag lets router telemetry
|
|
1035
|
-
# attribute traffic to opencode specifically.
|
|
1041
|
+
# final JSON. The X-App tag lets router telemetry attribute traffic to
|
|
1042
|
+
# opencode specifically.
|
|
1036
1043
|
local headers_json
|
|
1037
1044
|
headers_json="$(jq -n \
|
|
1038
1045
|
--arg key "$block_key" \
|
|
@@ -1056,9 +1063,7 @@ write_opencode_config() {
|
|
|
1056
1063
|
# /v1/responses surface (the canonical inbound — the router translates to
|
|
1057
1064
|
# Anthropic/OSS as it routes, and ships verbatim to the Codex backend for GPT
|
|
1058
1065
|
# turns). apiKey is the router key as a parse-time placeholder; the router
|
|
1059
|
-
# authenticates off X-Weave-Router-Key (planted in headers)
|
|
1060
|
-
# loader attaches subscriptions via the dedicated X-Weave-*-Subscription
|
|
1061
|
-
# headers, so the apiKey value is never used upstream.
|
|
1066
|
+
# authenticates off X-Weave-Router-Key (planted in headers).
|
|
1062
1067
|
local block
|
|
1063
1068
|
block="$(jq -n \
|
|
1064
1069
|
--arg url "$block_url/v1" \
|
|
@@ -1066,7 +1071,7 @@ write_opencode_config() {
|
|
|
1066
1071
|
--argjson headers "$headers_json" '
|
|
1067
1072
|
{
|
|
1068
1073
|
npm: "@ai-sdk/openai",
|
|
1069
|
-
name: "Weave Router
|
|
1074
|
+
name: "Weave Router",
|
|
1070
1075
|
options: { apiKey: $key, baseURL: $url, headers: $headers },
|
|
1071
1076
|
models: {
|
|
1072
1077
|
auto: {
|
|
@@ -1080,55 +1085,6 @@ write_opencode_config() {
|
|
|
1080
1085
|
}
|
|
1081
1086
|
')"
|
|
1082
1087
|
|
|
1083
|
-
# Login-only storage provider for a Claude (Pro/Max) subscription. It serves
|
|
1084
|
-
# no requests (no models), so its npm/baseURL are inert — opencode just needs
|
|
1085
|
-
# it registered so the plugin's Claude login method has a home and `opencode
|
|
1086
|
-
# auth login` lists it. The `weave` loader reads this slot off disk and
|
|
1087
|
-
# attaches the Claude sub. Reuses the same router key + identity headers.
|
|
1088
|
-
local claude_block
|
|
1089
|
-
claude_block="$(jq -n \
|
|
1090
|
-
--arg url "$block_url/v1" \
|
|
1091
|
-
--arg key "$block_key" \
|
|
1092
|
-
--argjson headers "$headers_json" '
|
|
1093
|
-
{
|
|
1094
|
-
npm: "@ai-sdk/openai",
|
|
1095
|
-
name: "Weave Router — Claude plan",
|
|
1096
|
-
options: { apiKey: $key, baseURL: $url, headers: $headers },
|
|
1097
|
-
models: {}
|
|
1098
|
-
}
|
|
1099
|
-
')"
|
|
1100
|
-
|
|
1101
|
-
# Drop the Codex-subscription plugin next to the config and capture the
|
|
1102
|
-
# absolute path we'll register in opencode.json's `plugin` array (so it loads
|
|
1103
|
-
# regardless of scope). $config_file's dir is the already-created
|
|
1104
|
-
# opencode_dir, so the `cd … && pwd` canonicalization is safe — uninstall.sh
|
|
1105
|
-
# must canonicalize identically so the array entry matches on removal.
|
|
1106
|
-
#
|
|
1107
|
-
# Only register the path when the bundled source is actually present and
|
|
1108
|
-
# copied: registering a path with no file on disk makes opencode fail to load
|
|
1109
|
-
# a missing plugin. The plugin holds no secrets (router key lives in the
|
|
1110
|
-
# config; ChatGPT tokens live in opencode's own auth store), so 644 is fine.
|
|
1111
|
-
# Source is bundled alongside install.sh by the npm prepack
|
|
1112
|
-
# (scripts/copy-installer.js), same as commands/ + pi-router/.
|
|
1113
|
-
local plugin_dir plugin_spec plugin_src plugin_directives_src plugin_classifier_src plugin_arg=""
|
|
1114
|
-
plugin_dir="$(cd "$(dirname "$config_file")" && pwd)/.weave"
|
|
1115
|
-
plugin_spec="$plugin_dir/opencode-weave.ts"
|
|
1116
|
-
plugin_src="$script_dir/opencode-weave/src/index.ts"
|
|
1117
|
-
plugin_directives_src="$script_dir/opencode-weave/src/directives.ts"
|
|
1118
|
-
plugin_classifier_src="$script_dir/opencode-weave/src/classifier-thread.ts"
|
|
1119
|
-
if [ -f "$plugin_src" ] && [ -f "$plugin_directives_src" ] && [ -f "$plugin_classifier_src" ]; then
|
|
1120
|
-
mkdir -p "$plugin_dir"
|
|
1121
|
-
cp "$plugin_src" "$plugin_spec"
|
|
1122
|
-
chmod 644 "$plugin_spec"
|
|
1123
|
-
cp "$plugin_directives_src" "$plugin_dir/directives.ts"
|
|
1124
|
-
chmod 644 "$plugin_dir/directives.ts"
|
|
1125
|
-
cp "$plugin_classifier_src" "$plugin_dir/classifier-thread.ts"
|
|
1126
|
-
chmod 644 "$plugin_dir/classifier-thread.ts"
|
|
1127
|
-
plugin_arg="$plugin_spec"
|
|
1128
|
-
else
|
|
1129
|
-
warn "opencode subscription plugin source not found at $plugin_src — skipping the Claude login + subscription routing. (Use a packaged 'npx $npm_package_name' install.)"
|
|
1130
|
-
fi
|
|
1131
|
-
|
|
1132
1088
|
# Installing must actually activate the router. Preserve a prior direct model
|
|
1133
1089
|
# beside the config so off/uninstall can restore the user's exact choice.
|
|
1134
1090
|
local parked_file previous_model
|
|
@@ -1148,57 +1104,66 @@ write_opencode_config() {
|
|
|
1148
1104
|
esac
|
|
1149
1105
|
fi
|
|
1150
1106
|
|
|
1107
|
+
# Validate cleanup paths before the key-bearing config is written.
|
|
1108
|
+
local legacy_plugin_dir legacy_plugin_file legacy_plugin_files="opencode-weave.ts directives.ts classifier-thread.ts"
|
|
1109
|
+
legacy_plugin_dir="$(dirname "$config_file")/.weave"
|
|
1110
|
+
refuse_if_symlink "$legacy_plugin_dir"
|
|
1111
|
+
for legacy_plugin_file in $legacy_plugin_files; do
|
|
1112
|
+
refuse_if_symlink "$legacy_plugin_dir/$legacy_plugin_file"
|
|
1113
|
+
done
|
|
1114
|
+
|
|
1151
1115
|
# Merge into any existing opencode.json. We always overwrite provider.weave
|
|
1152
1116
|
# so re-install reflects the latest key/identity, but we leave the rest of the
|
|
1153
1117
|
# file (other providers, mcp, agent settings) untouched. The managed model is
|
|
1154
1118
|
# always weave/auto; a prior direct choice was parked above for exact restore.
|
|
1155
1119
|
#
|
|
1156
|
-
#
|
|
1157
|
-
#
|
|
1158
|
-
# Claude login method lives in the plugin, so registering the provider without
|
|
1159
|
-
# it (e.g. the `curl | sh` path, which carries no plugin source) would leave a
|
|
1160
|
-
# non-working login — instead we omit it (and strip any stale one). The legacy
|
|
1161
|
-
# `weave-codex` provider is always stripped: the single Responses `weave`
|
|
1162
|
-
# provider supersedes it.
|
|
1120
|
+
# Legacy subscription providers and the v1 plugin are removed during the
|
|
1121
|
+
# migration; unrelated providers and plugins remain untouched.
|
|
1163
1122
|
local merged
|
|
1164
1123
|
if [ -f "$config_file" ]; then
|
|
1165
1124
|
merged="$(jq \
|
|
1166
1125
|
--argjson block "$block" \
|
|
1167
|
-
|
|
1168
|
-
--arg plugin "$plugin_arg" \
|
|
1169
|
-
--arg pluginspec "$plugin_spec" '
|
|
1126
|
+
'
|
|
1170
1127
|
.provider = ((.provider // {}) | .weave = $block)
|
|
1171
1128
|
| (.provider |= del(."weave-codex"))
|
|
1172
|
-
| (
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
else . end)
|
|
1129
|
+
| (.provider |= del(."weave-claude"))
|
|
1130
|
+
| (if (.providers | type) == "object"
|
|
1131
|
+
then .providers |= del(.weave, ."weave-codex", ."weave-claude")
|
|
1132
|
+
else .
|
|
1133
|
+
end)
|
|
1134
|
+
| (if (.providers | type) == "object" and (.providers | length) == 0
|
|
1135
|
+
then del(.providers)
|
|
1136
|
+
else .
|
|
1181
1137
|
end)
|
|
1138
|
+
| (if (.plugin | type) == "array"
|
|
1139
|
+
then .plugin |= map(select((tostring | test("(^|/)opencode-weave\\.ts$")) | not))
|
|
1140
|
+
else .
|
|
1141
|
+
end)
|
|
1142
|
+
| (if (.plugin | type) == "array" and (.plugin | length) == 0 then del(.plugin) else . end)
|
|
1182
1143
|
| .model = "weave/auto"
|
|
1183
1144
|
| (.["$schema"] //= "https://opencode.ai/config.json")
|
|
1184
1145
|
' "$config_file")"
|
|
1185
1146
|
else
|
|
1186
1147
|
merged="$(jq -n \
|
|
1187
1148
|
--argjson block "$block" \
|
|
1188
|
-
|
|
1189
|
-
--arg plugin "$plugin_arg" '
|
|
1149
|
+
'
|
|
1190
1150
|
{
|
|
1191
1151
|
"$schema": "https://opencode.ai/config.json",
|
|
1192
1152
|
model: "weave/auto",
|
|
1193
1153
|
provider: { weave: $block }
|
|
1194
1154
|
}
|
|
1195
|
-
| (if $plugin != "" then .provider["weave-claude"] = $claude | .plugin = [$plugin] else . end)
|
|
1196
1155
|
')"
|
|
1197
1156
|
fi
|
|
1198
|
-
|
|
1199
|
-
# 0600
|
|
1200
|
-
#
|
|
1201
|
-
chmod 600 "$config_file"
|
|
1157
|
+
|
|
1158
|
+
# 0600 before the key lands: even at user scope, mode 644 would leak the key
|
|
1159
|
+
# to any local user on a shared box.
|
|
1160
|
+
[ ! -f "$config_file" ] || chmod 600 "$config_file"
|
|
1161
|
+
(umask 077 && printf '%s\n' "$merged" >"$config_file")
|
|
1162
|
+
|
|
1163
|
+
for legacy_plugin_file in $legacy_plugin_files; do
|
|
1164
|
+
[ ! -f "$legacy_plugin_dir/$legacy_plugin_file" ] || rm -f "$legacy_plugin_dir/$legacy_plugin_file"
|
|
1165
|
+
done
|
|
1166
|
+
rmdir "$legacy_plugin_dir" 2>/dev/null || true
|
|
1202
1167
|
}
|
|
1203
1168
|
|
|
1204
1169
|
# write_pi_models_config merges a managed `weave` provider into pi's
|
|
@@ -1853,7 +1818,8 @@ if [ "$target" = "claude" ] || [ "$target" = "opencode" ] || [ "$target" = "pi"
|
|
|
1853
1818
|
require_cmd jq "macOS: 'brew install jq' · Debian/Ubuntu: 'sudo apt install jq'"
|
|
1854
1819
|
fi
|
|
1855
1820
|
# curl is used by the install/update paths' health/validate probes and by every
|
|
1856
|
-
# `models` call
|
|
1821
|
+
# `models` call. The on/off toggles only ping the router best-effort after a
|
|
1822
|
+
# real state change (see report_client_event) and skip it when curl is absent.
|
|
1857
1823
|
if [ "$mode" = "install" ] || [ "$mode" = "update" ] || [ "$mode" = "models" ]; then
|
|
1858
1824
|
require_cmd curl "macOS/Linux: usually preinstalled — check your package manager"
|
|
1859
1825
|
fi
|
|
@@ -1878,8 +1844,10 @@ case "$target" in
|
|
|
1878
1844
|
;;
|
|
1879
1845
|
opencode)
|
|
1880
1846
|
if ! command -v opencode >/dev/null 2>&1; then
|
|
1881
|
-
warn "'opencode' not found on PATH. Install from https://opencode.ai (
|
|
1847
|
+
warn "'opencode' not found on PATH. Install OpenCode v2 from https://opencode.ai (Homebrew: 'brew install anomalyco/tap/opencode-v2'), then re-run this script."
|
|
1882
1848
|
warn "Continuing — opencode.json will be written and will take effect once opencode is installed."
|
|
1849
|
+
elif ! check_opencode_major_version; then
|
|
1850
|
+
exit 1
|
|
1883
1851
|
fi
|
|
1884
1852
|
;;
|
|
1885
1853
|
pi)
|
|
@@ -2555,6 +2523,60 @@ models_endpoint_is_trusted() {
|
|
|
2555
2523
|
return 1
|
|
2556
2524
|
}
|
|
2557
2525
|
|
|
2526
|
+
# report_client_event ACTION tells this install's router that a state-changing
|
|
2527
|
+
# off/on just succeeded, so the router can log and export a lifecycle event.
|
|
2528
|
+
# Strictly best-effort: the toggle has already been applied, users legitimately
|
|
2529
|
+
# turn routing off *because* the router is unreachable, and nothing here may
|
|
2530
|
+
# change the exit status. Everything -- resolution included -- runs in a
|
|
2531
|
+
# subshell with errexit off, so no failure escapes into the caller; the POST
|
|
2532
|
+
# itself is detached with a short timeout and its output discarded.
|
|
2533
|
+
#
|
|
2534
|
+
# Endpoint and key come from the installed config (never the hosted defaults),
|
|
2535
|
+
# via the same readers `models` uses, so a self-hosted install reports to its
|
|
2536
|
+
# own router. For Claude Code that means the parked sidecar while off, since
|
|
2537
|
+
# the live settings point at Anthropic then. An explicit --base-url wins over
|
|
2538
|
+
# the on-disk endpoint, as it does for `models`; otherwise the same trust gate
|
|
2539
|
+
# applies and a checkout-supplied endpoint never receives the key. The key
|
|
2540
|
+
# rides in a mode-600 header file, not argv.
|
|
2541
|
+
report_client_event() {
|
|
2542
|
+
local action="$1"
|
|
2543
|
+
(
|
|
2544
|
+
set +e
|
|
2545
|
+
endpoint="" key="" base_src="" key_src="" headers="" body="" harness=""
|
|
2546
|
+
command -v curl >/dev/null 2>&1 || exit 0
|
|
2547
|
+
if [ "$base_url_explicit" = "true" ]; then
|
|
2548
|
+
endpoint="${base_url%/}"
|
|
2549
|
+
else
|
|
2550
|
+
endpoint="$(resolve_installed_endpoint)"
|
|
2551
|
+
fi
|
|
2552
|
+
[ -n "$endpoint" ] || exit 0
|
|
2553
|
+
key="$(read_installed_key)"
|
|
2554
|
+
[ -n "$key" ] || exit 0
|
|
2555
|
+
if [ "$target" = "claude" ]; then
|
|
2556
|
+
base_src="$(resolve_installed_base_source "$endpoint")"
|
|
2557
|
+
key_src="$(resolve_installed_key_source)"
|
|
2558
|
+
else
|
|
2559
|
+
base_src="$(models_config_file_for_target)"
|
|
2560
|
+
key_src="$base_src"
|
|
2561
|
+
fi
|
|
2562
|
+
models_endpoint_is_trusted "$endpoint" "$base_src" "$key_src" || exit 0
|
|
2563
|
+
headers="$(mktemp)" || exit 0
|
|
2564
|
+
chmod 600 "$headers" || { rm -f "$headers"; exit 0; }
|
|
2565
|
+
printf '%s: %s\n' "$router_key_header" "$key" >"$headers" || { rm -f "$headers"; exit 0; }
|
|
2566
|
+
# The router keys harnesses the way minted keys do: Claude Code is claude_code.
|
|
2567
|
+
harness="$target"
|
|
2568
|
+
[ "$target" = "claude" ] && harness="claude_code"
|
|
2569
|
+
body="$(printf '{"action":"%s","harness":"%s"}' "$action" "$harness")"
|
|
2570
|
+
(
|
|
2571
|
+
trap 'rm -f "$headers"' EXIT
|
|
2572
|
+
curl -sS --max-time 2 -X POST -H 'Content-Type: application/json' \
|
|
2573
|
+
--header "@$headers" --data-binary "$body" -o /dev/null \
|
|
2574
|
+
"$endpoint/v1/client-events"
|
|
2575
|
+
) >/dev/null 2>&1 </dev/null &
|
|
2576
|
+
) >/dev/null 2>&1 || true
|
|
2577
|
+
return 0
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2558
2580
|
# gitignore_add appends an entry to the repo .gitignore in project scope so a
|
|
2559
2581
|
# parked sidecar (which may carry the router key header) never gets committed.
|
|
2560
2582
|
# No-op for user scope and --dir, matching how install handles its own ignores.
|
|
@@ -2722,6 +2744,7 @@ toggle_claude() {
|
|
|
2722
2744
|
printf '%s\n' "$merged" >"$settings_file"
|
|
2723
2745
|
fi
|
|
2724
2746
|
ok "Claude Code is ${C_BOLD}off${C_RESET} (direct to Anthropic). Restart Claude Code for it to take effect."
|
|
2747
|
+
report_client_event off
|
|
2725
2748
|
;;
|
|
2726
2749
|
on)
|
|
2727
2750
|
if [ "$parked_present" != "true" ]; then
|
|
@@ -2746,6 +2769,7 @@ toggle_claude() {
|
|
|
2746
2769
|
printf '%s\n' "$merged" >"$local_settings_file"
|
|
2747
2770
|
chmod 600 "$local_settings_file"
|
|
2748
2771
|
ok "Claude Code is ${C_BOLD}on${C_RESET} (routing through the Weave Router). Restart Claude Code for it to take effect."
|
|
2772
|
+
report_client_event on
|
|
2749
2773
|
else
|
|
2750
2774
|
warn "Claude Code is off and the parked router key is missing (its sidecar was deleted). Re-run the installer to restore the router key — leaving the current direct-to-Anthropic setup in place so requests don't fail auth."
|
|
2751
2775
|
fi
|
|
@@ -2786,6 +2810,7 @@ toggle_claude() {
|
|
|
2786
2810
|
apply_claude_context_window on "$active"
|
|
2787
2811
|
rm -f "$parked"
|
|
2788
2812
|
ok "Claude Code is ${C_BOLD}on${C_RESET} (routing through the Weave Router). Restart Claude Code for it to take effect."
|
|
2813
|
+
report_client_event on
|
|
2789
2814
|
;;
|
|
2790
2815
|
esac
|
|
2791
2816
|
}
|
|
@@ -2833,6 +2858,7 @@ toggle_codex() {
|
|
|
2833
2858
|
"$codex_status_file" --off >/dev/null 2>&1 || true
|
|
2834
2859
|
fi
|
|
2835
2860
|
ok "Codex is ${C_BOLD}off${C_RESET} (default provider). Takes effect on your next 'codex' run."
|
|
2861
|
+
report_client_event off
|
|
2836
2862
|
;;
|
|
2837
2863
|
on)
|
|
2838
2864
|
if [ "$state" = "absent" ]; then warn "No managed Weave block in $f. Run the installer to set up Codex."; return 0; fi
|
|
@@ -2877,6 +2903,7 @@ toggle_codex() {
|
|
|
2877
2903
|
"$codex_status_file" --on >/dev/null 2>&1 || true
|
|
2878
2904
|
fi
|
|
2879
2905
|
ok "Codex is ${C_BOLD}on${C_RESET} (routing through the Weave Router). Takes effect on your next 'codex' run."
|
|
2906
|
+
report_client_event on
|
|
2880
2907
|
;;
|
|
2881
2908
|
esac
|
|
2882
2909
|
}
|
|
@@ -2933,6 +2960,7 @@ toggle_opencode() {
|
|
|
2933
2960
|
else
|
|
2934
2961
|
ok "opencode is ${C_BOLD}off${C_RESET} — choose a direct model with /models. Takes effect on your next opencode run."
|
|
2935
2962
|
fi
|
|
2963
|
+
report_client_event off
|
|
2936
2964
|
;;
|
|
2937
2965
|
on)
|
|
2938
2966
|
if [ "$on" = "true" ]; then ok "opencode is already on — nothing to do."; return 0; fi
|
|
@@ -2958,6 +2986,7 @@ toggle_opencode() {
|
|
|
2958
2986
|
chmod 600 "$parked"
|
|
2959
2987
|
gitignore_add ".weave-parked.json"
|
|
2960
2988
|
ok "opencode is ${C_BOLD}on${C_RESET} (default model $router_model via the Weave Router). Takes effect on your next opencode run."
|
|
2989
|
+
report_client_event on
|
|
2961
2990
|
;;
|
|
2962
2991
|
esac
|
|
2963
2992
|
}
|
|
@@ -3591,6 +3620,27 @@ if [ "$mode" = "models" ] || [ "$mode" = "accounts" ] || [ "$mode" = "login" ] |
|
|
|
3591
3620
|
# Editing model selection needs the endpoint and key of one specific install,
|
|
3592
3621
|
# never the hosted defaults: a self-hosted user pointing at their own router
|
|
3593
3622
|
# would otherwise silently edit the hosted one's installation.
|
|
3623
|
+
# Login enrollment is client-independent. When no Claude/Codex endpoint is
|
|
3624
|
+
# configured, prefer the managed OpenCode config as the source for the
|
|
3625
|
+
# router endpoint; the provider operand still selects the account to enroll.
|
|
3626
|
+
if [ "$mode" = "login" ] && [ "$target" != "opencode" ] && [ "$base_url_explicit" != "true" ]; then
|
|
3627
|
+
login_target="$target"
|
|
3628
|
+
login_target_base="$(resolve_installed_endpoint)"
|
|
3629
|
+
if [ -z "$login_target_base" ]; then
|
|
3630
|
+
target="opencode"
|
|
3631
|
+
if [ -n "$install_dir" ]; then
|
|
3632
|
+
opencode_dir="$install_dir"
|
|
3633
|
+
elif [ "$scope" = "project" ]; then
|
|
3634
|
+
opencode_dir="$settings_base"
|
|
3635
|
+
else
|
|
3636
|
+
opencode_dir="${XDG_CONFIG_HOME:-$settings_base/.config}/opencode"
|
|
3637
|
+
fi
|
|
3638
|
+
opencode_config_file="$opencode_dir/opencode.json"
|
|
3639
|
+
if [ -z "$(resolve_installed_endpoint)" ]; then
|
|
3640
|
+
target="$login_target"
|
|
3641
|
+
fi
|
|
3642
|
+
fi
|
|
3643
|
+
fi
|
|
3594
3644
|
if [ "$base_url_explicit" != "true" ]; then
|
|
3595
3645
|
models_base="$(resolve_installed_endpoint)"
|
|
3596
3646
|
if [ -z "$models_base" ] && { [ "$mode" = "accounts" ] || [ "$mode" = "status" ]; } && [ "$target" = "claude" ]; then
|
|
@@ -3628,6 +3678,33 @@ if [ "$mode" = "models" ] || [ "$mode" = "accounts" ] || [ "$mode" = "login" ] |
|
|
|
3628
3678
|
models_key_source="$(models_config_file_for_target)"
|
|
3629
3679
|
fi
|
|
3630
3680
|
fi
|
|
3681
|
+
# Managed enrollment is client-independent. If an OpenCode-only install is
|
|
3682
|
+
# the first router config on the machine, login claude|codex still needs to
|
|
3683
|
+
# find its endpoint and key even though the provider operand initially makes
|
|
3684
|
+
# the lookup target Claude or Codex. Reuse the OpenCode key in that case, but
|
|
3685
|
+
# only when it pairs with the endpoint already resolved above: the endpoint
|
|
3686
|
+
# is either an explicit --base-url or the selected client's own install, and
|
|
3687
|
+
# a key from one router must never be sent to another.
|
|
3688
|
+
if [ "$mode" = "login" ] && [ "$target" != "opencode" ] && [ -z "$api_key" ]; then
|
|
3689
|
+
login_target="$target"
|
|
3690
|
+
target="opencode"
|
|
3691
|
+
if [ -n "$install_dir" ]; then
|
|
3692
|
+
opencode_dir="$install_dir"
|
|
3693
|
+
elif [ "$scope" = "project" ]; then
|
|
3694
|
+
opencode_dir="$settings_base"
|
|
3695
|
+
else
|
|
3696
|
+
opencode_dir="${XDG_CONFIG_HOME:-$settings_base/.config}/opencode"
|
|
3697
|
+
fi
|
|
3698
|
+
opencode_config_file="$opencode_dir/opencode.json"
|
|
3699
|
+
opencode_key="$(read_installed_key)"
|
|
3700
|
+
opencode_base="$(resolve_installed_endpoint)"
|
|
3701
|
+
if [ -n "$opencode_key" ] && { [ "$base_url_explicit" = "true" ] || [ "$(strip_trailing_slashes "$opencode_base")" = "$(strip_trailing_slashes "$base_url")" ]; }; then
|
|
3702
|
+
api_key="$opencode_key"
|
|
3703
|
+
models_key_source="$opencode_config_file"
|
|
3704
|
+
fi
|
|
3705
|
+
target="$login_target"
|
|
3706
|
+
fi
|
|
3707
|
+
|
|
3631
3708
|
if [ -z "$api_key" ]; then
|
|
3632
3709
|
err "No router key found for $target in this scope. Re-run 'npx $npm_package_name --$target', or export WEAVE_ROUTER_KEY."
|
|
3633
3710
|
exit 1
|
|
@@ -4993,24 +5070,22 @@ if [ "$target" = "opencode" ]; then
|
|
|
4993
5070
|
|
|
4994
5071
|
# Project scope: the per-teammate config carries the router key, so it
|
|
4995
5072
|
# stays out of git. Same reasoning as the Codex path — base URL is shared,
|
|
4996
|
-
# but the key is per-person
|
|
4997
|
-
# config references it by absolute path), so ignore it alongside.
|
|
5073
|
+
# but the key is per-person, so ignore the config alongside.
|
|
4998
5074
|
if [ "$scope" = "project" ] && [ -z "$install_dir" ] && [ -n "${git_root:-}" ]; then
|
|
4999
5075
|
gitignore="$git_root/.gitignore"
|
|
5000
5076
|
refuse_if_symlink "$gitignore"
|
|
5001
5077
|
for entry in \
|
|
5002
5078
|
"opencode.json" \
|
|
5003
|
-
".weave/" \
|
|
5004
5079
|
".weave-parked.json"
|
|
5005
5080
|
do
|
|
5006
5081
|
if [ ! -f "$gitignore" ] || ! grep -qxF "$entry" "$gitignore"; then
|
|
5007
5082
|
printf '%s\n' "$entry" >>"$gitignore"
|
|
5008
5083
|
fi
|
|
5009
5084
|
done
|
|
5010
|
-
ok "Updated $gitignore (ignored opencode.json
|
|
5085
|
+
ok "Updated $gitignore (ignored opencode.json)"
|
|
5011
5086
|
fi
|
|
5012
5087
|
|
|
5013
|
-
#
|
|
5088
|
+
# Native slash command files: opencode discovers commands in *.md files under
|
|
5014
5089
|
# ~/.config/opencode/commands/ (user scope) and .opencode/commands/ (project
|
|
5015
5090
|
# scope). Install command wrappers for /rf (±), /force-model, /unforce-model
|
|
5016
5091
|
# so typing /rf + in the TUI expands to /router-feedback + and reaches the
|
|
@@ -5031,15 +5106,13 @@ if [ "$target" = "opencode" ]; then
|
|
|
5031
5106
|
verify_install
|
|
5032
5107
|
|
|
5033
5108
|
announce_done "opencode"
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
# make these instructions misleading.
|
|
5040
|
-
if jq -e '(.provider // {}) | has("weave-claude")' "$opencode_config_file" >/dev/null 2>&1; then
|
|
5041
|
-
info "Optional: connect your AI plans so they pay for the matching turns. Run ${C_BOLD}opencode auth login${C_RESET} → ${C_BOLD}Weave Router — Codex plan${C_RESET} for ${C_BOLD}ChatGPT Pro/Plus${C_RESET} (GPT/Codex turns) and/or ${C_BOLD}Weave Router — Claude plan${C_RESET} for ${C_BOLD}Claude Pro/Max${C_RESET} (Claude turns). The router still routes every turn; your Weave key pays for the rest."
|
|
5109
|
+
enrollment_args=""
|
|
5110
|
+
if [ -n "$install_dir" ]; then
|
|
5111
|
+
enrollment_args=" --dir $(printf '%q' "$install_dir")"
|
|
5112
|
+
elif [ "$scope" = "project" ]; then
|
|
5113
|
+
enrollment_args=" --scope project"
|
|
5042
5114
|
fi
|
|
5115
|
+
info "To enroll managed subscriptions, run ${C_BOLD}npx $npm_package_name login claude${enrollment_args}${C_RESET} and/or ${C_BOLD}npx $npm_package_name login codex${enrollment_args}${C_RESET}."
|
|
5043
5116
|
if [ -n "$install_dir" ]; then
|
|
5044
5117
|
# --dir installs land outside opencode's discovery roots, so the caller
|
|
5045
5118
|
# has to point opencode at the file explicitly.
|
|
@@ -5769,8 +5842,8 @@ prices='{
|
|
|
5769
5842
|
"claude-sonnet-4-6": 0.1,
|
|
5770
5843
|
"claude-sonnet-5": 0.1,
|
|
5771
5844
|
"deepseek/deepseek-v4-flash": 0.2,
|
|
5772
|
-
"deepseek/deepseek-v4-pro": 0.
|
|
5773
|
-
"deepseek/deepseek-v4-pro-0813": 0.
|
|
5845
|
+
"deepseek/deepseek-v4-pro": 0.0862,
|
|
5846
|
+
"deepseek/deepseek-v4-pro-0813": 0.0862,
|
|
5774
5847
|
"deepseek/deepseek-v4.1-flash": 0.031818181818181815,
|
|
5775
5848
|
"gemini-2.0-flash": 0.25,
|
|
5776
5849
|
"gemini-2.0-flash-lite": 0.25,
|
|
@@ -6143,7 +6216,7 @@ write_claude_settings() {
|
|
|
6143
6216
|
jq -n --arg url "$base_url" --arg sl "$statusline_path_for_settings" --arg statusline_install "$statusline_install" '{
|
|
6144
6217
|
env: { ANTHROPIC_BASE_URL: $url, ENABLE_TOOL_SEARCH: "true" },
|
|
6145
6218
|
attribution: {
|
|
6146
|
-
commit: "Co-Authored-By: Weave Router <router@
|
|
6219
|
+
commit: "Co-Authored-By: Weave Router <router@weaveos.com>",
|
|
6147
6220
|
pr: "🤖 Generated with [Weave Router](https://router.workweave.ai)"
|
|
6148
6221
|
}
|
|
6149
6222
|
} + (if $statusline_install == "true" then {statusLine: { type: "command", command: $sl }} else {} end)' >"$tmp_patch"
|
|
@@ -6151,7 +6224,7 @@ write_claude_settings() {
|
|
|
6151
6224
|
jq -n --arg url "$base_url" --arg header "$custom_headers" --arg sl "$statusline_path_for_settings" --arg statusline_install "$statusline_install" '{
|
|
6152
6225
|
env: { ANTHROPIC_BASE_URL: $url, ANTHROPIC_CUSTOM_HEADERS: $header, ENABLE_TOOL_SEARCH: "true" },
|
|
6153
6226
|
attribution: {
|
|
6154
|
-
commit: "Co-Authored-By: Weave Router <router@
|
|
6227
|
+
commit: "Co-Authored-By: Weave Router <router@weaveos.com>",
|
|
6155
6228
|
pr: "🤖 Generated with [Weave Router](https://router.workweave.ai)"
|
|
6156
6229
|
}
|
|
6157
6230
|
} + (if $statusline_install == "true" then {statusLine: { type: "command", command: $sl }} else {} end)' >"$tmp_patch"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weave-os/router",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.26",
|
|
4
4
|
"description": "One-command installer that points Claude Code, Codex, opencode, or pi at the Weave Router. For pi it also ships the routing extension, loaded via pi.extensions.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"weave-router": "bin.js",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"commands/",
|
|
27
27
|
"codex-skills/",
|
|
28
28
|
"pi-router/",
|
|
29
|
-
"opencode-weave/",
|
|
30
29
|
"README.md",
|
|
31
30
|
"LICENSE",
|
|
32
31
|
"NOTICE"
|
|
@@ -7,7 +7,7 @@ export interface ModelPricing {
|
|
|
7
7
|
cacheReadMultiplier: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const PRICING_VERSION = "catalog-sha256:
|
|
10
|
+
export const PRICING_VERSION = "catalog-sha256:128e641ea3a4ffe9";
|
|
11
11
|
|
|
12
12
|
export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.freeze({
|
|
13
13
|
"claude-fable-5": { inputUsdPerMillion: 10, outputUsdPerMillion: 50, cacheReadMultiplier: 0.1 },
|
|
@@ -25,8 +25,8 @@ export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.free
|
|
|
25
25
|
"claude-sonnet-4-6": { inputUsdPerMillion: 3, outputUsdPerMillion: 15, cacheReadMultiplier: 0.1 },
|
|
26
26
|
"claude-sonnet-5": { inputUsdPerMillion: 3, outputUsdPerMillion: 15, cacheReadMultiplier: 0.1 },
|
|
27
27
|
"deepseek/deepseek-v4-flash": { inputUsdPerMillion: 0.1134, outputUsdPerMillion: 0.2791, cacheReadMultiplier: 0.2 },
|
|
28
|
-
"deepseek/deepseek-v4-pro": { inputUsdPerMillion: 1.74, outputUsdPerMillion: 3.48, cacheReadMultiplier: 0.
|
|
29
|
-
"deepseek/deepseek-v4-pro-0813": { inputUsdPerMillion: 1.74, outputUsdPerMillion: 3.48, cacheReadMultiplier: 0.
|
|
28
|
+
"deepseek/deepseek-v4-pro": { inputUsdPerMillion: 1.74, outputUsdPerMillion: 3.48, cacheReadMultiplier: 0.0862 },
|
|
29
|
+
"deepseek/deepseek-v4-pro-0813": { inputUsdPerMillion: 1.74, outputUsdPerMillion: 3.48, cacheReadMultiplier: 0.0862 },
|
|
30
30
|
"deepseek/deepseek-v4.1-flash": { inputUsdPerMillion: 0.22, outputUsdPerMillion: 0.66, cacheReadMultiplier: 0.031818181818181815 },
|
|
31
31
|
"gemini-2.0-flash": { inputUsdPerMillion: 0.1, outputUsdPerMillion: 0.4, cacheReadMultiplier: 0.25 },
|
|
32
32
|
"gemini-2.0-flash-lite": { inputUsdPerMillion: 0.075, outputUsdPerMillion: 0.3, cacheReadMultiplier: 0.25 },
|